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

Adding a tutorial on adding new parabolic terms #1209

Merged
merged 10 commits into from
Aug 27, 2022

Conversation

jlchan
Copy link
Contributor

@jlchan jlchan commented Aug 25, 2022

This includes a description of the operators Gradient and Divergence used for dispatch in the boundary conditions.

@jlchan jlchan requested a review from ranocha August 25, 2022 21:14
@jlchan
Copy link
Contributor Author

jlchan commented Aug 25, 2022

@ranocha this is now ready to review (should have no more commits). I built the docs preview on my laptop and it looks good.

@sloede this includes some documentation of the Gradient and Divergence boundary conditions (#1147). I remember you were asking about documentation of these BCs previously.

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! I have one question below.

docs/literate/src/files/adding_new_parabolic_terms.jl Outdated Show resolved Hide resolved
Comment on lines 126 to 135
u_left = 1.0
u_bottom = 2.0

boundary_conditions_hyperbolic = (; x_neg = BoundaryConditionDirichlet((x, t, equations) -> SVector(u_left)),
y_neg = BoundaryConditionDirichlet((x, t, equations) -> SVector(u_bottom)),
y_pos = boundary_condition_do_nothing,
x_pos = boundary_condition_do_nothing)

boundary_conditions_parabolic = (; x_neg = BoundaryConditionConstantDirichlet(u_left),
y_neg = BoundaryConditionConstantDirichlet(u_bottom),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If users copy this directly to their code, they will run into type instabilities with non-constant globals. What about adding const qualifiers to u_left and u_bottom or copying their values directly into the corresponding lines?
It doesn't really matter for this demonstration of the behavior, but it would probably be nice to follow best practices in the tutorials in general (when it's not too complex).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - removed u_left, u_bottom.

Is the type instability due to the use of u_left in the anonymous function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - it picks up a global variable from there and the global variable is neither typed nor const

Copy link
Member

@sloede sloede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for doing this! I just left a few minor suggestions which may or may not be applied; either way this PR can be merged afterwards.

docs/literate/src/files/adding_new_parabolic_terms.jl Outdated Show resolved Hide resolved
docs/literate/src/files/adding_new_parabolic_terms.jl Outdated Show resolved Hide resolved
docs/literate/src/files/adding_new_parabolic_terms.jl Outdated Show resolved Hide resolved
Copy link
Member

@andrewwinters5000 andrewwinters5000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this @jlchan ! It looks quite nice. I just added two minor suggestions.

docs/literate/src/files/adding_new_parabolic_terms.jl Outdated Show resolved Hide resolved
docs/literate/src/files/adding_new_parabolic_terms.jl Outdated Show resolved Hide resolved
@jlchan
Copy link
Contributor Author

jlchan commented Aug 26, 2022

Thanks for the reviews @ranocha, @sloede, @andrewwinters5000! I've addressed the comments now

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jlchan jlchan merged commit f79183c into trixi-framework:dev Aug 27, 2022
ranocha added a commit that referenced this pull request Oct 11, 2022
* Parabolic terms for DGMulti (#1136)

* minor formatting

* adding multi-term semidiscretization

* fixing bug and adding test

* changing name

* changing name, importing SplitODEFunction

* fixing test by adding norm

* trying another test fix

* adding norm back

* adjusting tol

* try to fix test again

* syntax error

* removing norm frm test

* adding cache to parabolic terms (enable reuse of inviscid cache)

* generalize dgmulti iterators

* fix typo

* generalizing reset_du! for dgmulti

* WIP gradient and divergence computations

* fix name

* more generalization

* divergence + remove repeated code

* adding cache

* remove test

* update diffusion test

* update diffusion rhs

* moving routines around

* fix multiple includes

* removing time dependence for now from viscous rhs

* export ScalarDiffusion2D

* fix test

* working periodic advection RHS

* cleanup and comments

* making periodic advection-diffusion example

* trim whitespace

* adding t back in to parabolic rhs


add t back in

* refactoring boundary condition code

* update elixir with BCs

* change default DGMulti interface flux behavior

same as in #1139

* cleanup

* renaming variables

* BC prepping

* cleanup of elixir

* more name fixing

* Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* adding Neumann BCs

* switching to weak form


weak form


more weak form


weak form

* fixing cache variable names

* simplified parabolic boundary flux treatement

* updated elixir with different types of BCs

* Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* Update src/equations/equations.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* rhs! -> rhs_parabolic!

* move Gradient/Divergence types

* add "no boundary condition" BC

* rename ScalarDiffusion -> LaplaceDiffusion


r


r

* rhs -> rhs_parabolic! again

* comments

* moving tests around

* scalarDiffusion -> LaplaceDiffusion

* tuple-based constructor

* updating examples

* add ScalarPlotData2D docstring (#1145)

Co-authored-by: Jesse Chan <[email protected]>

* Apply suggestions from code review

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>

* renaming for consistency

parabolic_equations -> equations_parabolic
no_boundary_condition -> boundary_condition_do_nothing

* move Neumann BCs into equations.jl

* renaming, e.g., ParabolicEquations -> EquationsParabolic, etc

* rename test module

* generalize LaplaceDiffusion2D to any number of variables

* removing saveat times and standardizing `tol` names

* parabolic_cache -> cache_parabolic


cache

* renaming `create_cache` -> `create_cache_parabolic`

avoids conflicts when using dg::DGMultiFluxDiff

* Update examples/dgmulti_2d/elixir_advection_diffusion.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* Update src/equations/equations.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* parabolic_boundary_conditions -> boundary_conditions_parabolic

similarly for hyperbolic
d

* Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* add equations as field to LaplaceDiffusion2D

* moving Neumann BCs into equations.jl and adding default BC behavior

* running parabolic tests, adding integration test

* adding parabolic tests to ci

* missing comma

* Update src/equations/laplace_diffusion_2d.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* fix test

* fix test typo

* fix tests (for real this time)

* improve test coverage

Co-authored-by: Jesse Chan <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* Additional work on parabolic terms  (#1148)

* make "do nothing BC" a struct, move it to basic_types

* add varnames for LaplaceDiffusion

* add forgotten @threaded

* update comment

* Revert "add forgotten @threaded"

This reverts commit 1564501.

* add @threaded (without enumerate)

* remove periodic advection diffusion elixir (redundant)

* adding test

* one more test

* Update src/basic_types.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

Co-authored-by: Jesse Chan <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>

* Reorganization of boundary conditions (#1152)

* moving "default" boundary conditions back into equations file

* add periodic advection_diffusion back in

* updating test

* update test

* Apply suggestions from code review

Co-authored-by: Jesse Chan <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>

* Adding parabolic solver option (#1153)

* adding parabolic solver types

* incorporating parabolic solver types into dg_parabolic penalties

* specializing parabolic solver options in LaplaceDiffusion2D

* moving things around to fix CI

* dropped arg in test

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>

* renaming files and ViscousFlux solvers


renaming files


rename


rename

* Added TODO note for penalty term

* ViscousFlux___ -> ViscousFormulation___

* move function def around

Co-authored-by: Jesse Chan <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>

* rearrange include order

* Add support for hyperbolic-parabolic systems to TreeMesh2D (#1156)

* Add prototype for advection-diffusion elixir for TreeMesh2D

* Initial implementation of `calc_gradient!` for TreeMesh{2}

* First complete implementation of the parabolic rhs operator for TreeMesh

* Make it work

* Add first elixir that works

* Clean up elixir

* first draft of container for Navier-Stokes constants and fluxes

* remove unneeded temperature computation

* draft of elixir with possible boundary condition structure

* added manufactured solution and source term

* fix typo in function name for MMS

* update variable names for consistency. improve comments

* fix dumb typos in new equation system name

* actually export new equations

* add comment near variable_mapping declaration.

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>

* parabolic equations now exported separately

* change name to CompressibleNavierStokesEquations2D

* export NS with proper name

* explicitly require compressible Euler in the type parameter

* name kinematic viscosity nu for consistency with Lattice-Boltzmann

* add promotion in constructor

* make Reynolds, Prandtl, Mach, and kappa keyword arguments

* update constructor call in elixir

* reduce computation by exploiting stress tensor symmetry

* fix unpacking of flux

* modifying parabolic cache creation

in cache, we assume we take the gradient of all hyperbolic variables. since the number of parabolic variables can differ from the number of hyperbolic variables, we pass in the hyperbolic equations to `create_cache_parabolic` now

* comments

* comments

* formatting and renaming equations to equations_hyperbolic


formatting comments

* fix unpacking of gradients in flux

* adding CNS BCs

* adding lid-driven cavity elixir

* adding variable transform, editing cons2prim for CNS

* add prim2cons for NS (inconsistent right now)

* add draft of DGMulti Navier Stokes convergence elixir

* converging solution using elixir for TreeMesh with BCs

* fixing DGMulti advection diffusion elixir convergence

* naming equations as parabolic/hyperbolic

* generalizing transform_variables

* add TODO


more todos

* additional checks on get_unsigned_normal

* adding isothermal BC

* commenting out unused CNS functions for now

* fix call to transform_variables

* comments and cleanup

* changing default solver and Re for cavity

* adding more advection diffusion tests

* label tests

* add gradient_variables field to SemidiscretizationHyperbolicParabolic

* Revert "add gradient_variables field to SemidiscretizationHyperbolicParabolic"

This reverts commit 063b602.

* allowing for specialization in transform_variables

adding a function `gradient_variable_transformation` which should get specialized if the gradient variables are not conservative variables

* formatting and comments

* reverting elixir

* comments

* standardizing time tol

* minor fix to CNS boundary flux for convenience

make it so that the density state is computed correctly, even though it's not used

* formatting + comments

* using primitive variables in viscous flux instead of conservative

* minor formatting

* add CNS tests

* fix test

* testing if scoping issues fix TreeMesh tests

* decreasing timestep tol for TreeMesh parabolic test

* enabling periodic BCs for TreeMesh + more tests

* fix density BC flux (unused, but could be useful)

* adding non-working TreeMesh elixirs

* adding AD checks

* standardizing parameters in convergence elixirs

* minor cleanup

* revert DGMulti CNS elixir setup back to the one used in tests

* adding TreeMesh CNS convergence test

* removing redundant elixir

* add more tests

* add more test

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>

* set version to v0.4.43

* set development version to v0.4.44-pre

* add YouTube links to JuliaCon presentations (#1192)

* add YouTube links to JuliaCon presentations

* Apply suggestions from code review

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* improved readability of equation docstrings in compressible Euler files

* Navier-Stokes in 2D on DGMulti and TreeMesh (#1165)

* first draft of container for Navier-Stokes constants and fluxes

* remove unneeded temperature computation

* draft of elixir with possible boundary condition structure

* added manufactured solution and source term

* fix typo in function name for MMS

* update variable names for consistency. improve comments

* fix dumb typos in new equation system name

* actually export new equations

* add comment near variable_mapping declaration.

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>

* parabolic equations now exported separately

* change name to CompressibleNavierStokesEquations2D

* export NS with proper name

* explicitly require compressible Euler in the type parameter

* name kinematic viscosity nu for consistency with Lattice-Boltzmann

* add promotion in constructor

* make Reynolds, Prandtl, Mach, and kappa keyword arguments

* update constructor call in elixir

* reduce computation by exploiting stress tensor symmetry

* fix unpacking of flux

* modifying parabolic cache creation

in cache, we assume we take the gradient of all hyperbolic variables. since the number of parabolic variables can differ from the number of hyperbolic variables, we pass in the hyperbolic equations to `create_cache_parabolic` now

* comments

* comments

* formatting and renaming equations to equations_hyperbolic


formatting comments

* fix unpacking of gradients in flux

* adding CNS BCs

* adding lid-driven cavity elixir

* adding variable transform, editing cons2prim for CNS

* add prim2cons for NS (inconsistent right now)

* add draft of DGMulti Navier Stokes convergence elixir

* converging solution using elixir for TreeMesh with BCs

* fixing DGMulti advection diffusion elixir convergence

* naming equations as parabolic/hyperbolic

* generalizing transform_variables

* add TODO


more todos

* additional checks on get_unsigned_normal

* adding isothermal BC

* commenting out unused CNS functions for now

* fix call to transform_variables

* comments and cleanup

* changing default solver and Re for cavity

* adding more advection diffusion tests

* label tests

* add gradient_variables field to SemidiscretizationHyperbolicParabolic

* Revert "add gradient_variables field to SemidiscretizationHyperbolicParabolic"

This reverts commit 063b602.

* allowing for specialization in transform_variables

adding a function `gradient_variable_transformation` which should get specialized if the gradient variables are not conservative variables

* formatting and comments

* reverting elixir

* comments

* standardizing time tol

* minor fix to CNS boundary flux for convenience

make it so that the density state is computed correctly, even though it's not used

* formatting + comments

* using primitive variables in viscous flux instead of conservative

* minor formatting

* add CNS tests

* fix test

* testing if scoping issues fix TreeMesh tests

* decreasing timestep tol for TreeMesh parabolic test

* enabling periodic BCs for TreeMesh + more tests

* fix density BC flux (unused, but could be useful)

* adding non-working TreeMesh elixirs

* adding AD checks

* standardizing parameters in convergence elixirs

* minor cleanup

* revert DGMulti CNS elixir setup back to the one used in tests

* adding TreeMesh CNS convergence test

* removing redundant elixir

* add more tests

* add more test

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>

* add docstrings

Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Jesse Chan <[email protected]>

* add docstring for CNS equations

* removing some addressed TODOs

* adjust definition of the kappa constant

* avoid overwriting u_grad with viscous_flux results

* remove old TODOs

* clarify TODOs for later

* removing let statements

* rearrange main docstring. Fix typos in math environment causing it to not parse

* update TODO notes

* Apply suggestions from code review

Co-authored-by: Andrew Winters <[email protected]>

* update TODO notes

* Apply suggestions from code review

Co-authored-by: Andrew Winters <[email protected]>

* update TODO notes

* changing diffusivity names

Auto stash before merge of "parabolic-treemesh" and "origin/parabolic-treemesh"

* Reynolds/Prandtl number name changes for consistency

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Michael Schlottke-Lakemper <[email protected]>
Co-authored-by: Andrew Winters <[email protected]>

* fixing bug introduced by GH code review

* moving manufactured solution into the CNS equations file

* fix allocation issue

* get_diffusivity -> diffusivity

* removing cruft code, adding comment on messy prim2cons routine

* moving manufactured solution back into elixirs

* Update examples/dgmulti_2d/elixir_advection_diffusion_nonperiodic.jl

* TODO -> Todo, and .6 -> 0.6


d

* Update src/solvers/dgsem_tree/dg_2d_parabolic.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* adding note to Adiabatic/Isothermal BCs

* replacing CompressibleNavierStokesEquations with ...Diffusion

* Update src/solvers/dgsem_tree/dg_2d_parabolic.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Update src/solvers/dgsem_tree/dg_2d_parabolic.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* documenting Jacobian sign flip

* remove extra arg to `gradient_variable_transformation`

* Update src/solvers/dgsem_tree/dg_2d_parabolic.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* change warning to error

* fix bug introduced by search/replace

* dg_parabolic -> parabolic_scheme

* BoundaryConditionViscousWall -> BoundaryConditionNavierStokesWall

* u_grad -> gradients

* fix test

* renaming

* update comment

* converting to signature `flux(u, gradients, orientation, equations)`

* using prolong2interfaces/boundaries

* unpacking `gradients` and `flux_viscous`

* using calc_surface_integral!

* adding @muladd

* Apply suggestions from code review

* update comments

* Rename grad_u -> gradients

* Update src/equations/compressible_navier_stokes_2d.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* Rename remaining grad_u/u_grad -> gradients

* Refactor into prolong2interfaces!

* Refactor calc_volume_integral!

* Refactor calc_interface_flux

* Refactor prolong2boundaries!

* Refactor calc_divergence!

* Formatting consistency

* Remove dispatch on volume integral type

* Add comment on why surface_integral is passed to prolong2interfaces!

* Explicitly use weak form volume integral to allow easy overriding in test

* Add flux differencing test for CNS test

* Remove erroneous P4estMesh{2} dispatch

* Remove non-cons terms from parabolic solver

Co-authored-by: Andrew Winters <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Jesse Chan <[email protected]>
Co-authored-by: Jesse Chan <[email protected]>

* Add commentary on reuse of interfaces/boundaries data structures (#1199)

* Add comments on storing flux values in `u`

* Rearrange function names for consistency

* Update src/solvers/dgsem_tree/dg_2d_parabolic.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Update src/solvers/dgsem_tree/dg_2d_parabolic.jl

Co-authored-by: Andrew Winters <[email protected]>

Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Andrew Winters <[email protected]>

* Adding parabolic term description to NEWS.md (#1207)

* Add Literate docs for advection-diffusion (#1208)

* adding literate docs for advection-diffusion

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>

* rename "adding parabolic terms" -> "parabolic terms"

Co-authored-by: Hendrik Ranocha <[email protected]>

* Adding a tutorial on adding new parabolic terms (#1209)

* Viscous terms from entropy gradients (#1202)

* first draft of entropy stable gradients

* update TODOs

* added elixir with discontinuous solution for ES testing

* forgot one TODO marker

* adding GradientVariables**** type parameter

* fix bug (missing type param in constructor)

* add elixir with periodic CNS manufactured solution

* fix gradient conversion

* fix entropy variables w/BCs

* updating elixirs with `gradient_variables=GradientVariablesPrimitive()`

* Update src/equations/compressible_navier_stokes_2d.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* removing unused routines

* removing specialized entropy2cons and cons2entropy routines

* adding more tests

* removing unused elixirs

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>

* adding docs/warning for gradient variable type

* extracting w_inner[4] into a more clearly named variable

Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Jesse Chan <[email protected]>
Co-authored-by: Jesse Chan <[email protected]>
Co-authored-by: Michael Schlottke-Lakemper <[email protected]>
Co-authored-by: Jesse Chan <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>

* adding some minor documentation (#1214)

* fix parabolic PID (#1224)

* fix parabolic PID

* activate analysis_callback in Navier-Stokes convergence test

* fix typo

* Rescale compressible Navier-Stokes (#1230)

* remove the nondimensionalization and update the docstring for CNS

* update TreeMesh elixirs and test values

* update the elixirs and test values for DGMulti

* fix unbalanced parentheses

* file renaming for consistency

* update file names in the parabolic test script

* remove the gas constant as a parameter and update comments

* rename viscosity to dynamic_viscosity

* add comment about units in the docstring

* Update src/equations/compressible_navier_stokes_2d.jl

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* unify notation to call the viscosity mu

* fix undefined variable

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

* improve type stability of semidiscretize for parabolic semi (#1231)

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Michael Schlottke-Lakemper <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Andrew Winters <[email protected]>
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

Successfully merging this pull request may close these issues.

4 participants