24 "Discretizes a diffusion equation with the continuous Galerkin finite element method");
26 "use_automatic_differentiation",
28 "Whether to use automatic differentiation for all the terms in the equation");
38 _use_ad(getParam<bool>(
"use_automatic_differentiation"))
48 std::string kernel_type;
50 kernel_type =
_use_ad ?
"ADMatDiffusion" :
"MatDiffusion";
53 const auto & d = getParam<MooseFunctorName>(
"diffusivity_functor");
55 kernel_type =
"FunctionDiffusion";
58 "No diffusion kernel implemented for the diffusivity type of ",
62 kernel_type =
_use_ad ?
"ADDiffusion" :
"Diffusion";
64 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
70 params.
set<MaterialPropertyName>(
"diffusivity") =
71 getParam<MaterialPropertyName>(
"diffusivity_matprop");
73 params.
set<FunctionName>(
"function") = getParam<MooseFunctorName>(
"diffusivity_functor");
82 std::string kernel_type;
83 const auto & source = getParam<MooseFunctorName>(
"source_functor");
86 kernel_type =
_use_ad ?
"ADBodyForce" :
"BodyForce";
88 kernel_type =
_use_ad ?
"ADCoupledForce" :
"CoupledForce";
91 "No kernel defined for a source term in CG for the type of '",
96 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
100 const auto coef = getParam<Real>(
"source_coef");
102 params.
set<
Real>(
"value") = MooseUtils::convert<Real>(source) * coef;
105 params.
set<
Real>(
"value") = coef;
106 params.
set<FunctionName>(
"function") = source;
110 params.
set<
Real>(
"value") = coef;
111 params.
set<PostprocessorName>(
"postprocessor") = source;
115 params.
set<
Real>(
"coef") = coef;
116 params.
set<std::vector<VariableName>>(
"v") = {source};
125 const std::string kernel_type =
_use_ad ?
"ADTimeDerivative" :
"TimeDerivative";
127 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
138 const auto & boundary_fluxes = getParam<std::vector<MooseFunctorName>>(
"boundary_fluxes");
141 const auto & bc_flux = boundary_fluxes[i];
145 std::string bc_type =
"";
147 bc_type =
_use_ad ?
"ADNeumannBC" :
"NeumannBC";
149 bc_type =
"CoupledVarNeumannBC";
151 bc_type =
_use_ad ?
"ADFunctionNeumannBC" :
"FunctionNeumannBC";
153 bc_type =
"PostprocessorNeumannBC";
155 bc_type =
"FunctorNeumannBC";
159 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
164 params.
set<
Real>(
"value") = MooseUtils::convert<Real>(bc_flux);
166 params.
set<std::vector<VariableName>>(
"v") = {bc_flux};
168 params.
set<FunctionName>(
"function") = bc_flux;
170 params.
set<PostprocessorName>(
"postprocessor") = bc_flux;
172 params.
set<MooseFunctorName>(
"functor") = bc_flux;
180 const auto & boundary_values = getParam<std::vector<MooseFunctorName>>(
"boundary_values");
183 const auto & bc_value = boundary_values[i];
185 std::string bc_type =
"";
187 bc_type =
_use_ad ?
"ADDirichletBC" :
"DirichletBC";
189 bc_type =
_use_ad ?
"ADMatchedValueBC" :
"MatchedValueBC";
191 bc_type =
_use_ad ?
"ADFunctionDirichletBC" :
"FunctionDirichletBC";
193 bc_type =
"PostprocessorDirichletBC";
195 bc_type =
"FunctorDirichletBC";
198 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
203 params.
set<
Real>(
"value") = MooseUtils::convert<Real>(bc_value);
205 params.
set<std::vector<VariableName>>(
"v") = {bc_value};
207 params.
set<FunctionName>(
"function") = bc_value;
209 params.
set<PostprocessorName>(
"postprocessor") = bc_value;
211 params.
set<MooseFunctorName>(
"functor") = bc_value;
229 const std::string variable_type =
"MooseVariable";
231 params.
set<
MooseEnum>(
"order") = getParam<MooseEnum>(
"variable_order");
241 const auto bc_type_fixed =
"FunctorDirichletBC";
243 const auto bc_type_flux =
"FunctorNeumannBC";
248 for (
const auto & bc_pair : comp_pair.second)
250 params_fixed.
set<NonlinearVariableName>(
"variable") =
_var_name;
251 params_flux.
set<NonlinearVariableName>(
"variable") =
_var_name;
253 const auto bc_type = bc_pair.second.second;
254 const auto functor_name = bc_pair.second.first;
255 params_fixed.
set<MooseFunctorName>(
"functor") = functor_name;
256 params_flux.
set<MooseFunctorName>(
"functor") = functor_name;
258 const auto surface_name = bc_pair.first.second;
259 params_fixed.
set<std::vector<BoundaryName>>(
"boundary") = {surface_name};
260 params_flux.
set<std::vector<BoundaryName>>(
"boundary") = {surface_name};
262 if (bc_type == ComponentBoundaryConditionInterface::BoundaryConditionType::FIXED_VALUE)
265 "_fixed_value_" + surface_name,
267 else if (bc_type == ComponentBoundaryConditionInterface::BoundaryConditionType::FLUX)
270 "_flux_" + surface_name,
273 mooseError(
"Boundary condition type not implemented");
static InputParameters validParams()
std::string prefix() const
Use prefix() to disambiguate names.
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
bool parsesToReal(const std::string &input)
Check if the input string can be parsed into a Real.
const bool _use_ad
Whether to use automatic differentiation or not.
void assignBlocks(InputParameters ¶ms, const std::vector< SubdomainName > &blocks) const
Set the blocks parameter to the input parameters of an object this Physics will create.
bool shouldCreateVariable(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_aux)
Returns whether this Physics should create the variable.
static InputParameters validParams()
Factory & getFactory()
Get the factory for this physics The factory lets you get the parameters for objects.
virtual void addBoundaryConditionsFromComponents() override
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
const std::vector< BoundaryName > & _neumann_boundaries
Boundaries on which a Neumann boundary condition is applied.
Base class to help creating an entire physics.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
static InputParameters validParams()
bool shouldCreateTimeDerivative(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_already_defined) const
Returns whether this Physics should create the variable.
virtual void addKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
const VariableName & _var_name
Name of the diffused variable.
std::vector< SubdomainName > _blocks
Keep track of the subdomains the Physics is defined on.
std::map< std::string, std::map< std::pair< VariableName, BoundaryName >, std::pair< MooseFunctorName, ComponentBoundaryConditionInterface::BoundaryConditionType > > > _components_boundary_conditions
Map of components to variables and boundary conditions.
DiffusionCG(const InputParameters ¶meters)
virtual void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters ¶meters)
virtual FEProblemBase & getProblem()
Get the problem for this physics Useful to add objects to the simulation.
virtual void addFEBCs() override
const SolverSystemName & getSolverSystem(unsigned int variable_index) const
Get the solver system for this variable index.
Interface class to help components interact with Physics.
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
const std::vector< BoundaryName > & _dirichlet_boundaries
Boundaries on which a Dirichlet boundary condition is applied.
Creates all the objects needed to solve a diffusion equation with a continuous Galerkin finite elemen...
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶ms)
Canonical method for adding a non-linear variable.
virtual void addSolverVariables() override
The default implementation of these routines will do nothing as we do not expect all Physics to be de...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerDiffusionPhysicsBaseTasks("MooseApp", DiffusionCG)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
void reportPotentiallyMissedParameters(const std::vector< std::string > ¶m_names, const std::string &object_type) const
When this is called, we are knowingly not using the value of these parameters.
virtual void addFEKernels() override
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
auto index_range(const T &sizable)
Base class to host all common parameters and attributes of Physics actions to solve the diffusion equ...
registerMooseAction("MooseApp", DiffusionCG, "add_kernel")