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");
30 params.
addParam<MaterialPropertyName>(
"source_matprop",
"Source term in the diffusion problem");
39 _use_ad(getParam<bool>(
"use_automatic_differentiation"))
48 unsigned int num_diffusion_terms = 1;
50 num_diffusion_terms = getParam<std::vector<MaterialPropertyName>>(
"diffusivity_matprop").size();
52 num_diffusion_terms = getParam<std::vector<MooseFunctorName>>(
"diffusivity_functor").size();
54 for (
const auto i_diff_block_group : make_range(num_diffusion_terms))
57 std::string kernel_type;
59 kernel_type =
_use_ad ?
"ADMatDiffusion" :
"MatDiffusion";
63 getParam<std::vector<MooseFunctorName>>(
"diffusivity_functor")[i_diff_block_group];
65 kernel_type =
"FunctionDiffusion";
68 "No diffusion kernel implemented for the diffusivity type of ",
72 kernel_type =
_use_ad ?
"ADDiffusion" :
"Diffusion";
74 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
77 getParam<std::vector<std::vector<SubdomainName>>>(
78 "diffusivity_blocks")[i_diff_block_group]);
85 params.
set<MaterialPropertyName>(
"diffusivity") =
86 getParam<std::vector<MaterialPropertyName>>(
"diffusivity_matprop")[i_diff_block_group];
88 params.
set<FunctionName>(
"function") =
89 getParam<std::vector<MooseFunctorName>>(
"diffusivity_functor")[i_diff_block_group];
91 const auto kernel_name =
93 ((num_diffusion_terms > 1) ?
"_" + std::to_string(i_diff_block_group) :
"");
101 std::string kernel_type;
103 isParamValid(
"source_functor") ? getParam<MooseFunctorName>(
"source_functor") :
"";
105 source = getParam<MaterialPropertyName>(
"source_matprop");
108 getProblem().hasPostprocessorValueByName(source))
109 kernel_type =
_use_ad ?
"ADBodyForce" :
"BodyForce";
111 kernel_type =
_use_ad ?
"ADCoupledForce" :
"CoupledForce";
113 kernel_type =
"FunctorKernel";
114 else if (
getProblem().getMaterialPropertyRegistry().hasProperty(source))
115 kernel_type =
_use_ad ?
"ADMatBodyForce" :
"MatBodyForce";
118 "No kernel defined for a source term in CG for the type of '",
123 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
127 const auto coef = getParam<Real>(
"source_coef");
129 params.set<Real>(
"value") = MooseUtils::convert<Real>(source) * coef;
132 params.set<Real>(
"value") = coef;
133 params.set<FunctionName>(
"function") = source;
137 params.set<Real>(
"value") = coef;
138 params.set<PostprocessorName>(
"postprocessor") = source;
142 params.set<MooseFunctorName>(
"functor") = source;
143 params.set<
bool>(
"functor_on_rhs") =
true;
146 "Setting a coefficient is not implemented with a source functor. Use an "
147 "intermediate (parsed) functor material to define a new functors which "
148 "multiplies the functor by the coefficient");
152 params.set<MaterialPropertyName>(
"material_property") = source;
156 "Setting a coefficient is not implemented with a material property source. Use an "
157 "intermediate (parsed) material to define a new functors which "
158 "multiplies the property by the coefficient");
162 params.set<Real>(
"coef") = coef;
163 params.set<std::vector<VariableName>>(
"v") = {source};
172 const std::string kernel_type =
_use_ad ?
"ADTimeDerivative" :
"TimeDerivative";
174 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
185 const auto & boundary_fluxes = getParam<std::vector<MooseFunctorName>>(
"boundary_fluxes");
188 const auto & bc_flux = boundary_fluxes[i];
192 std::string bc_type =
"";
194 bc_type =
_use_ad ?
"ADNeumannBC" :
"NeumannBC";
196 bc_type =
"CoupledVarNeumannBC";
198 bc_type =
_use_ad ?
"ADFunctionNeumannBC" :
"FunctionNeumannBC";
199 else if (
getProblem().hasPostprocessorValueByName(bc_flux))
200 bc_type =
"PostprocessorNeumannBC";
202 bc_type =
"FunctorNeumannBC";
206 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
211 params.
set<Real>(
"value") = MooseUtils::convert<Real>(bc_flux);
213 params.
set<std::vector<VariableName>>(
"v") = {bc_flux};
215 params.
set<FunctionName>(
"function") = bc_flux;
217 params.
set<PostprocessorName>(
"postprocessor") = bc_flux;
219 params.
set<MooseFunctorName>(
"functor") = bc_flux;
227 const auto & boundary_values = getParam<std::vector<MooseFunctorName>>(
"boundary_values");
230 const auto & bc_value = boundary_values[i];
232 std::string bc_type =
"";
234 bc_type =
_use_ad ?
"ADDirichletBC" :
"DirichletBC";
236 bc_type =
_use_ad ?
"ADMatchedValueBC" :
"MatchedValueBC";
238 bc_type =
_use_ad ?
"ADFunctionDirichletBC" :
"FunctionDirichletBC";
239 else if (
getProblem().hasPostprocessorValueByName(bc_value))
240 bc_type =
"PostprocessorDirichletBC";
242 bc_type =
"FunctorDirichletBC";
245 params.
set<NonlinearVariableName>(
"variable") =
_var_name;
250 params.
set<Real>(
"value") = MooseUtils::convert<Real>(bc_value);
252 params.
set<std::vector<VariableName>>(
"v") = {bc_value};
254 params.
set<FunctionName>(
"function") = bc_value;
256 params.
set<PostprocessorName>(
"postprocessor") = bc_value;
258 params.
set<MooseFunctorName>(
"functor") = bc_value;
276 const std::string variable_type =
"MooseVariable";
278 params.
set<
MooseEnum>(
"order") = getParam<MooseEnum>(
"variable_order");
288 const auto bc_type_fixed =
"FunctorDirichletBC";
290 const auto bc_type_flux =
"FunctorNeumannBC";
295 for (
const auto & bc_pair : comp_pair.second)
297 params_fixed.
set<NonlinearVariableName>(
"variable") =
_var_name;
298 params_flux.
set<NonlinearVariableName>(
"variable") =
_var_name;
300 const auto bc_type = bc_pair.second.second;
301 const auto functor_name = bc_pair.second.first;
302 params_fixed.
set<MooseFunctorName>(
"functor") = functor_name;
303 params_flux.
set<MooseFunctorName>(
"functor") = functor_name;
305 const auto surface_name = bc_pair.first.second;
306 params_fixed.
set<std::vector<BoundaryName>>(
"boundary") = {surface_name};
307 params_flux.
set<std::vector<BoundaryName>>(
"boundary") = {surface_name};
312 "_fixed_value_" + surface_name,
317 "_flux_" + surface_name,
320 mooseError(
"Boundary condition type not implemented");
registerDiffusionPhysicsBaseTasks("MooseApp", DiffusionCG)
registerMooseAction("MooseApp", DiffusionCG, "add_kernel")
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Creates all the objects needed to solve a diffusion equation with a continuous Galerkin finite elemen...
virtual void addFEBCs() override
virtual void addBoundaryConditionsFromComponents() override
static InputParameters validParams()
DiffusionCG(const InputParameters ¶meters)
virtual void addSolverVariables() override
The default implementation of these routines will do nothing as we do not expect all Physics to be de...
const bool _use_ad
Whether to use automatic differentiation or not.
virtual void addFEKernels() override
Base class to host all common parameters and attributes of Physics actions to solve the diffusion equ...
const std::vector< BoundaryName > & _neumann_boundaries
Boundaries on which a Neumann boundary condition is applied.
const VariableName & _var_name
Name of the diffused variable.
static InputParameters validParams()
const std::vector< BoundaryName > & _dirichlet_boundaries
Boundaries on which a Dirichlet boundary condition is applied.
const MaterialPropertyRegistry & getMaterialPropertyRegistry() const
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶ms)
Canonical method for adding a non-linear variable.
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
virtual void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters ¶meters)
virtual void addKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
bool hasProperty(const std::string &name) const
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 ...
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.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
static InputParameters validParams()
Base class to help creating an entire physics.
virtual FEProblemBase & getProblem()
Get the problem for this physics Useful to add objects to the simulation.
Factory & getFactory()
Get the factory for this physics The factory lets you get the parameters for objects.
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.
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.
void reportPotentiallyMissedParameters(const std::vector< std::string > ¶m_names, const std::string &object_type, const std::string &object_name="") const
When this is called, we are knowingly not using the value of these parameters.
std::string prefix() const
Use prefix() to disambiguate names.
const SolverSystemName & getSolverSystem(unsigned int variable_index) const
Get the solver system for this variable index.
bool shouldCreateVariable(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_aux)
Returns whether this Physics should create the variable.
std::vector< SubdomainName > _blocks
Keep track of the subdomains the Physics is defined on.
Interface class to help components interact with Physics.
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.
bool hasFunctor(const std::string &name, const THREAD_ID tid) const
checks whether we have a functor corresponding to name on the thread id tid
bool parsesToReal(const std::string &input, Real *parsed_real)