Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do we make a non_conservative + parabolic equation #2232

Closed
yolhan83 opened this issue Jan 14, 2025 · 4 comments
Closed

How do we make a non_conservative + parabolic equation #2232

yolhan83 opened this issue Jan 14, 2025 · 4 comments

Comments

@yolhan83
Copy link

yolhan83 commented Jan 14, 2025

Hello, I need to make a equation of the form

$$\partial_t u + u \partial_x u - \varepsilon \partial_x^2 u = 0,$$

I tried the non-conservative + parabolic and fall into the issue #1671, so i thought we could access the LDG gradient inside the source term but does not seem possible either. Also I have no idea what flux splitting mean here. What's the correct way of doing it ?
related : yolhan83/BloodFlowTrixi.jl#2 and the model : https://yolhan83.github.io/BloodFlowTrixi.jl/dev/math/
Thank you.

@MarcoArtiano
Copy link

MarcoArtiano commented Jan 14, 2025

The way Trixi handles non-conservative terms is via an equivalent formulation to Flux-Differencing, i.e. you need to define a surface_flux and volume_flux for the non conservative term. I'm not sure if there is a general way to define a surface and volume non conservative fluxes. Usually they are derived by employing either an EC condition or a well balanced condition. One paper that describes a similar (equivalent) semidiscretization is https://arxiv.org/pdf/2203.06062.

Moreover, a slight modification of the [Adding a non-conservative equation](https://trixi-framework.github.io/Trixi.jl/stable/tutorials/adding_nonconservative_equation/#adding_nonconservative_equation) leads to the following working example for non-conservative + parabolic equations:

Example
module NonconservativeLinearAdvection

using Trixi
using Trixi: AbstractEquations, get_node_vars
import Trixi: varnames, default_analysis_integrals, flux, max_abs_speed_naive,
            have_nonconservative_terms

struct NonconservativeLinearAdvectionEquation <: AbstractEquations{1, # spatial dimension
                                                                 1} # one variables (u,)
end

function varnames(::typeof(cons2cons), ::NonconservativeLinearAdvectionEquation)
  ("scalar")
end

default_analysis_integrals(::NonconservativeLinearAdvectionEquation) = ()

flux(u, orientation, equation::NonconservativeLinearAdvectionEquation) = zero(u)


function max_abs_speed_naive(u_ll, u_rr, orientation::Integer,
                           ::NonconservativeLinearAdvectionEquation)

  return max(abs(u_ll[1]), abs(u_rr[1]))
end

have_nonconservative_terms(::NonconservativeLinearAdvectionEquation) = Trixi.True()


function flux_nonconservative(u_ll, u_rr, orientation,
                            equations::NonconservativeLinearAdvectionEquation)

  return SVector((u_ll[1] + u_rr[1])*0.5f0 * (u_rr[1] - u_ll[1]))
end

end


import .NonconservativeLinearAdvection
using Trixi
using OrdinaryDiffEq

equations = NonconservativeLinearAdvection.NonconservativeLinearAdvectionEquation()
diffusivity() = 0.1
equations_parabolic = LaplaceDiffusion1D(diffusivity(), equations)

function initial_condition_sine(x, t,
                              equation::NonconservativeLinearAdvection.NonconservativeLinearAdvectionEquation)
  x0 = -2 * atan(sqrt(3) * tan(sqrt(3) / 2 * t - atan(tan(x[1] / 2) / sqrt(3))))
  scalar = sin(x0)
  SVector(scalar)
end


mesh = TreeMesh(-Float64(π), Float64(π), 
              initial_refinement_level = 4, n_cells_max = 10^4)

volume_flux = (flux_central, NonconservativeLinearAdvection.flux_nonconservative)
surface_flux = (flux_central, NonconservativeLinearAdvection.flux_nonconservative)
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
             volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
boundary_conditions = boundary_condition_periodic
boundary_conditions_parabolic = boundary_condition_periodic


semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
                                           initial_condition_sine,
                                           solver;
                                           boundary_conditions = (boundary_conditions,
                                                                  boundary_conditions_parabolic))

tspan = (0.0, 8.0)
ode = semidiscretize(semi, tspan);

summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi, interval = 50)
callbacks = CallbackSet(summary_callback, analysis_callback);

sol = solve(ode, Tsit5(), abstol = 1.0e-6, reltol = 1.0e-6,
          save_everystep = false);

I'm not sure if this is the best option (I would probably try some split form $$\partial_x u^2/2 - u/2 \partial_x u$$), but it might be a good starting point to understand non-conservative semidiscretization in Trixi.

ps: I should have changed the name from NonconservativeLinearAdvectionEquation to NonconservativeBurgersEquation

@yolhan83
Copy link
Author

yolhan83 commented Jan 14, 2025

Oh ok so it should work then, I may have some bugs thank you. I wonder why Trixi does not allow for gradients in source-term when parabolic terms are used since they are calculated anyway.
edit : working fine indeed it was a bug

@ranocha
Copy link
Member

ranocha commented Jan 15, 2025

I wonder why Trixi does not allow for gradients in source-term when parabolic terms are used since they are calculated anyway.

Non-conservative terms have to be handled differently than classical pointwise source terms. Moreover, it would make the implementation more complex since we focus on first-order systems (hyperbolic problems), so we would have to duplicate code when parabolic terms are present.

@ranocha
Copy link
Member

ranocha commented Jan 15, 2025

Feel free to close this issue when your problem has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants