-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add Physics base class and a heat conduction example #25977
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
Merged
Merged
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
7f69c40
Add a PhysicsName type that will be used to pass Physics to other obj…
GiudGiud 7ae640f
Add a base class for defining Physics
GiudGiud cd63837
Add some base routines for restarting variables in a Physics
GiudGiud abac2b1
Add documentation to Physics
GiudGiud b7be95d
Add a system number to the Physics
GiudGiud d37fed9
Add 1st utility to check parameters
GiudGiud f169229
Add another set of utilities to check parameters:
GiudGiud de3f42a
Add a base class for heat conduction equation
GiudGiud 7ee1a4f
Add a derived class for CGFE heat conduction
GiudGiud a35feb0
Add documentation for the finite element heat conduction physics
GiudGiud 97caf50
Add a test for the heat conduction physics
GiudGiud 5548d3e
Duplicate physics source page as a syntax page
GiudGiud 8a796f2
Add a base class for solving the diffusion equation
GiudGiud 43c3f2b
Add a derived physics class to solve diffusion with CG
GiudGiud 7af5c30
Add a derived physics class to solve diffusion with FV
GiudGiud 8a9c1ee
Add tests for diffusion example physics
GiudGiud 5a53817
Allow for a parameter rename when transferring a parameter
GiudGiud ef05443
Set some default preconditioning options for solving diffusion
GiudGiud a867ff9
Add documentation to example diffusion physics, refs #25642
GiudGiud 8853c20
Fix documentation:
GiudGiud 6cd3bdb
Use preconditioning by default for diffusion
GiudGiud f58c075
More catering to that unit test that enforces MOOSE does not add new …
GiudGiud 70297ec
Change moose server unit test so it no longer enforces the list of sy…
GiudGiud 1ce6048
Use a macro to propagate base classes tasks to derived ones
GiudGiud a04095b
Keep track of required tasks in the Physics objects
GiudGiud 372e593
Add preconditioning to heat conduction physics too
GiudGiud e15e093
Address Alex review
GiudGiud 6c31c20
Update to new syntax based on discussions with Daniel, Kyle, Peter an…
GiudGiud 8fa9f21
Address Josh review
GiudGiud 478340e
Add a new insertion point for physics adding new tasks
GiudGiud bd7ff03
Add proper syntax pages for everything but the last level syntax
GiudGiud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # DiffusionCG | ||
|
|
||
| !syntax description /Physics/DiffusionCG/DiffusionCG | ||
|
|
||
| See the [DiffusionPhysicsBase.md] documentation for the diffusion equation solved. | ||
|
|
||
| ## Continuous Galerkin Discretization | ||
|
|
||
| The volumetric discretization of the time derivative uses the [TimeDerivative.md] kernel. | ||
| The diffusion term $\nabla \cdot D \nabla u(\vec{x})$ is integrated by parts and represented using: | ||
| - a [Diffusion.md] kernel if no diffusion coefficient is passed | ||
joshuahansel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - a [MatDiffusion.md] kernel if a diffusion coefficient is passed, usually as a [material property](syntax/Materials/index.md) | ||
|
|
||
|
|
||
| The source term $f$ is added using: | ||
| - a [BodyForce.md] if the source is a constant, a [Postprocessor](syntax/Postprocessors/index.md) or a [Function](syntax/Functions/index.md) | ||
| - a [MatCoupledForce.md] if the force is specified using a material property | ||
| - a [CoupledForce.md] if the source is another type of [functor](syntax/Functors/index.md) | ||
|
|
||
|
|
||
| The Dirichlet boundary conditions are created using: | ||
| - a [DirichletBC.md] if the boundary value is set to a number | ||
| - a [FunctionDirichletBC.md] if set to a [Function](syntax/Functions/index.md) | ||
| - a [PostprocessorDirichletBC.md] if set to a [Postprocessor](syntax/Postprocessors/index.md) | ||
| - a [FunctorDirichletBC.md] for any other kind of [functor](syntax/Functors/index.md) for the boundary value | ||
|
|
||
|
|
||
| The Neumann boundary conditions are created using: | ||
| - a [NeumannBC.md] if the flux is set to a number | ||
| - a [FunctionNeumannBC.md] if set to a [Function](syntax/Functions/index.md) | ||
| - a [PostprocessorNeumannBC.md] if set to a [Postprocessor](syntax/Postprocessors/index.md) | ||
| - a [FunctorNeumannBC.md] for any other kind of [functor](syntax/Functors/index.md) for the flux value | ||
|
|
||
|
|
||
| !alert note | ||
| We could use a [Functor](syntax/Functors/index.md) object to cover every need, but the specialized objects | ||
| are a few percent faster, depending on the case. | ||
|
|
||
| !alert note | ||
| The user may switch between using / not using automatic differentiation for the kernel and boundary | ||
| conditions using the [!param](/Physics/DiffusionCG/automatic_differentiation). This parameter is only | ||
| obeyed if the AD/non-AD object exists for the requested diffusivity / source / boundary value functor etc. | ||
|
|
||
|
|
||
| !syntax parameters /Physics/DiffusionCG/DiffusionCG | ||
|
|
||
| !syntax inputs /Physics/DiffusionCG/DiffusionCG | ||
|
|
||
| !syntax children /Physics/DiffusionCG/DiffusionCG | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # DiffusionFV | ||
|
|
||
| !syntax description /Physics/DiffusionFV/DiffusionFV | ||
|
|
||
| See the [DiffusionPhysicsBase.md] documentation for the diffusion equation solved. | ||
|
|
||
| ## Finite Volume Discretization | ||
|
|
||
| The volumetric discretization of the time derivative uses the [FVTimeKernel.md] kernel. | ||
| The diffusion term $\nabla \cdot D \nabla u(\vec{x})$ is integrated by parts and represented using a [FVDiffusion.md] kernel. | ||
| The source term $f$ is added using: | ||
|
|
||
| - a [FVBodyForce.md] if the source is a constant, a [Postprocessor](syntax/Postprocessors/index.md) or a [Function](syntax/Functions/index.md) | ||
| - a [FVCoupledForce.md] if the source is another type of [functor](syntax/Functors/index.md) | ||
|
|
||
|
|
||
| The Dirichlet boundary conditions are created using: | ||
| - a [FVDirichletBC.md] if the boundary value is set to a number | ||
| - a [FVFunctionDirichletBC.md] if set to a [Function](syntax/Functions/index.md) | ||
| - a [FVFunctorDirichletBC.md] for any other kind of [functor](syntax/Functors/index.md) for the boundary value | ||
|
|
||
|
|
||
| The Neumann boundary conditions are created using: | ||
| - a [FVNeumannBC.md] if the flux is set to a number | ||
| - a [FVFunctionNeumannBC.md] if set to a [Function](syntax/Functions/index.md) | ||
| - a [FVFunctorNeumannBC.md] for any other kind of [functor](syntax/Functors/index.md) for the flux value | ||
|
|
||
|
|
||
| !alert note | ||
| We could use a [Functor](syntax/Functors/index.md) object to cover every need, but the specialized objects | ||
| are a few percent faster, depending on the case. | ||
|
|
||
| !syntax parameters /Physics/DiffusionFV/DiffusionFV | ||
|
|
||
| !syntax inputs /Physics/DiffusionFV/DiffusionFV | ||
|
|
||
| !syntax children /Physics/DiffusionFV/DiffusionFV |
26 changes: 26 additions & 0 deletions
26
framework/doc/content/source/physics/DiffusionPhysicsBase.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # DiffusionPhysicsBase | ||
|
|
||
| This is a base class for the derived [Physics](syntax/Physics/index.md) actions setting up objects | ||
| to solve the diffusion equation with a particular discretization. | ||
|
|
||
| The diffusion equation solved is: | ||
|
|
||
| !equation | ||
| \dfrac{\partial u}{\partial t} - \nabla \cdot D \nabla u(\vec{x}) - f(\vec{x}) = 0 | ||
|
|
||
| with Dirichlet boundary conditions: | ||
|
|
||
| !equation | ||
| u(\vec{x}) = g | ||
|
|
||
| and / or Neumann boundary conditions: | ||
|
|
||
| !equation | ||
| D\dfrac{\partial u}{\partial n} = h | ||
|
|
||
| over the boundaries specified by the [!param](/Physics/DiffusionFV/dirichlet_boundaries) and | ||
| [!param](/Physics/DiffusionFV/neumann_boundaries) parameters respectively. | ||
|
|
||
| The values set at the Dirichlet boundary conditions, $g$, and Neumann boundary conditions, $h$, | ||
| are set by the [!param](/Physics/DiffusionFV/boundary_values) and | ||
| [!param](/Physics/DiffusionFV/boundary_fluxes) respectively. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../source/physics/DiffusionCG.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../source/physics/DiffusionFV.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Physics system | ||
|
|
||
| The `Physics` system is meant to standardize the process of adding an equation and its discretization | ||
| to a simulation. It is based on the [Action system](source/actions/Action.md), with additional APIs | ||
| defined to support the definition of an equation. | ||
lindsayad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Interaction with Components | ||
|
|
||
| The interaction with Components is one of the main goals of the Physics system. Stay tuned for future developments. | ||
|
|
||
| ## Implementing your own Physics | ||
|
|
||
| If you have *not* created the kernels, boundary conditions, and so on, the `Physics` system is not a good place | ||
| to start. You must start with a working implementation of your equations before attempting to create a `Physics` object. | ||
|
|
||
| If you do have a working set of kernels, boundary conditions, and other MOOSE objects, that let you solve an equation in MOOSE, you should consider the following before implementing a `Physics`: | ||
|
|
||
| - is user-friendliness a priority for the expansion of my work? | ||
| - is the current workflow unsatisfactory in that regard? | ||
| - would creating objects programmatically reduce the potential for user-error while allowing sufficient flexibility? | ||
|
|
||
| If the answer is yes to all three, then you may start implementing a `Physics` object for your equation. | ||
| The simple concepts behind the simulation setup in a `Physics` is that the `add<various MOOSE object>` routines | ||
| are all called on the `Physics` and they are all called at the same time in the setup as with a regular input file. | ||
|
|
||
| So for example, to make a `DiffusionPhysics` create a finite element diffusion kernel, one can override `addFEKernels` like this: | ||
|
|
||
| ``` | ||
| void | ||
| DiffusionPhysics::addFEKernels() | ||
| { | ||
| { | ||
| const std::string kernel_type = "ADDiffusion"; | ||
| InputParameters params = getFactory().getValidParams(kernel_type); | ||
| params.set<NonlinearVariableName>("variable") = _temperature_name; // we saved the name of the variable as a class attribute | ||
| getProblem().addKernel(kernel_type, name() + "_diffusion", params); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Notice how we use the `PhysicsBase::getFactory()` routine to get access to the `Factory` that will get the parameters we | ||
| need to fill, and the `PhysicsBase::getProblem()` to get access to the `Problem` which stores the objects created. | ||
|
|
||
| If you already have an `Action` defined for your physics, converting it to a `Physics` should be fairly straightforward. The principal advantages of doing so are: | ||
|
|
||
| - benefit from new APIs implemented in the `Physics` system | ||
| - future ability to leverage the `Components` system to define a complex system | ||
|
|
||
GiudGiud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ### Advice on implementation | ||
|
|
||
| #### Add a lot of checks | ||
|
|
||
| Do as much parameter checking as you can. The `PhysicsBase` class defines utilities such as the ones below | ||
| that let you check that the user inputs to your physics are correct. | ||
|
|
||
| ``` | ||
| void checkParamsBothSetOrNotSet(const std::string & param1, const std::string & param2) const; | ||
| template <typename T, typename S> | ||
| void checkVectorParamsSameLength(const std::string & param1, const std::string & param2) const; | ||
| template <typename T> | ||
| void checkVectorParamsNoOverlap(const std::vector<std::string> & param_vec) const; | ||
| ``` | ||
|
|
||
| #### Separate the definition of the equation from its discretization | ||
|
|
||
| The Physics base class you will create will hold the parameters that are shared between all the | ||
| discretized versions of it. | ||
|
|
||
| Physics and spatial discretizations are as separated as we could make them, but they are still very much intertwined. So | ||
| when you are adding a parameter you need to think about: | ||
|
|
||
| - is this more tied to the strong form of the equation? If so then it likely belongs in a `XYZPhysicsBase` base class | ||
| - is this more tied to the discretization of the equation? If so then it likely belong in the derived, user-instantiated, | ||
| `XYZPhysics` class. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //* This file is part of the MOOSE framework | ||
| //* https://www.mooseframework.org | ||
| //* | ||
| //* All rights reserved, see COPYRIGHT for full restrictions | ||
| //* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
| //* | ||
| //* Licensed under LGPL 2.1, please see LICENSE for details | ||
| //* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "DiffusionPhysicsBase.h" | ||
|
|
||
| /** | ||
| * Creates all the objects needed to solve a diffusion equation with a continuous Galerkin finite | ||
| * element discretization | ||
| */ | ||
| class DiffusionCG : public DiffusionPhysicsBase | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| DiffusionCG(const InputParameters & parameters); | ||
|
|
||
| private: | ||
| virtual void addNonlinearVariables() override; | ||
| virtual void addFEKernels() override; | ||
| virtual void addFEBCs() override; | ||
|
|
||
| /// Whether to use automatic differentiation or not | ||
| const bool _use_ad; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //* This file is part of the MOOSE framework | ||
| //* https://www.mooseframework.org | ||
| //* | ||
| //* All rights reserved, see COPYRIGHT for full restrictions | ||
| //* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
| //* | ||
| //* Licensed under LGPL 2.1, please see LICENSE for details | ||
| //* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "DiffusionPhysicsBase.h" | ||
|
|
||
| /** | ||
| * Creates all the objects needed to solve a diffusion equation with a cell-centered finite | ||
| * volume discretization | ||
| */ | ||
| class DiffusionFV : public DiffusionPhysicsBase | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| DiffusionFV(const InputParameters & parameters); | ||
|
|
||
| private: | ||
| virtual void addNonlinearVariables() override; | ||
| virtual void addFVKernels() override; | ||
| virtual void addFVBCs() override; | ||
| virtual InputParameters getAdditionalRMParams() const override; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //* This file is part of the MOOSE framework | ||
| //* https://www.mooseframework.org | ||
| //* | ||
| //* All rights reserved, see COPYRIGHT for full restrictions | ||
| //* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
| //* | ||
| //* Licensed under LGPL 2.1, please see LICENSE for details | ||
| //* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "PhysicsBase.h" | ||
|
|
||
| #define registerDiffusionPhysicsBaseTasks(app_name, derived_name) \ | ||
| registerPhysicsBaseTasks(app_name, derived_name); \ | ||
| registerMooseAction(app_name, derived_name, "add_preconditioning") | ||
|
|
||
| /** | ||
| * Base class to host all common parameters and attributes of Physics actions to solve the diffusion | ||
| * equation | ||
| */ | ||
| class DiffusionPhysicsBase : public PhysicsBase | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| DiffusionPhysicsBase(const InputParameters & parameters); | ||
|
|
||
| protected: | ||
| /// Name of the diffused variable | ||
| const VariableName & _var_name; | ||
| /// Boundaries on which a Neumann boundary condition is applied | ||
| const std::vector<BoundaryName> & _neumann_boundaries; | ||
| /// Boundaries on which a Dirichlet boundary condition is applied | ||
| const std::vector<BoundaryName> & _dirichlet_boundaries; | ||
|
|
||
| private: | ||
| /// Add default preconditioning options | ||
| void addPreconditioning() override; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.