https://mooseframework.inl.gov
Loading...
Searching...
No Matches
DiffusionFV.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "DiffusionFV.h"
11#include "MooseUtils.h"
12
13// Register the actions for the objects actually used
14registerMooseAction("MooseApp", DiffusionFV, "add_fv_kernel");
15registerMooseAction("MooseApp", DiffusionFV, "add_fv_bc");
16registerMooseAction("MooseApp", DiffusionFV, "add_variable");
18
21{
23 params.addClassDescription("Add diffusion physics discretized with cell-centered finite volume");
24 // No kernel implemented in the framework for a material property diffusivity
25 params.suppressParameter<std::vector<MaterialPropertyName>>("diffusivity_matprop");
26 params.addRequiredParam<std::vector<MooseFunctorName>>("diffusivity_functor",
27 "Functor specifying the diffusivity");
28
29 params.addParam<unsigned short>(
30 "ghost_layers", 2, "Number of ghosting layers for distributed memory parallel calculations");
31 params.addParamNamesToGroup("ghost_layers", "Advanced");
32 return params;
33}
34
36 : PhysicsBase(parameters), PhysicsComponentInterface(parameters), DiffusionPhysicsBase(parameters)
37{
38}
39
40void
45
46void
48{
49 // Diffusion term(s)
50 unsigned int num_diffusion_terms = 1;
51 if (isParamValid("diffusivity_functor"))
52 num_diffusion_terms = getParam<std::vector<MooseFunctorName>>("diffusivity_functor").size();
53
54 for (const auto i_diff_block_group : make_range(num_diffusion_terms))
55 {
56 const std::string kernel_type = "FVDiffusion";
57 InputParameters params = getFactory().getValidParams(kernel_type);
58 if (isParamValid("diffusivity_blocks"))
59 assignBlocks(params,
60 getParam<std::vector<std::vector<SubdomainName>>>(
61 "diffusivity_blocks")[i_diff_block_group]);
62 else
63 assignBlocks(params, _blocks);
64 params.set<NonlinearVariableName>("variable") = _var_name;
65 params.set<MooseFunctorName>("coeff") =
66 getParam<std::vector<MooseFunctorName>>("diffusivity_functor")[i_diff_block_group];
67 getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_diffusion", params);
68 }
69 // Source term
70 if (isParamValid("source_functor"))
71 {
72 // Select the kernel type based on the user parameters
73 std::string kernel_type;
74
75 const auto & source = getParam<MooseFunctorName>("source_functor");
76 if (MooseUtils::parsesToReal(source) || getProblem().hasFunction(source) ||
77 getProblem().hasPostprocessorValueByName(source))
78 kernel_type = "FVBodyForce";
79 else if (getProblem().hasVariable(source))
80 kernel_type = "FVCoupledForce";
81 else
82 paramError("source_functor",
83 "No kernel defined for a source term in FV for the type used for '",
84 source,
85 "'");
86
87 InputParameters params = getFactory().getValidParams(kernel_type);
88 params.set<NonlinearVariableName>("variable") = _var_name;
89 assignBlocks(params, _blocks);
90
91 // Transfer the source and coefficient parameter from the Physics to the kernel
92 const auto coef = getParam<Real>("source_coef");
93 if (MooseUtils::parsesToReal(source))
94 params.set<Real>("value") = MooseUtils::convert<Real>(source) * coef;
95 else if (getProblem().hasFunction(source))
96 {
97 params.set<Real>("value") = coef;
98 params.set<FunctionName>("function") = source;
99 }
100 else if (getProblem().hasPostprocessorValueByName(source))
101 {
102 params.set<Real>("value") = coef;
103 params.set<PostprocessorName>("postprocessor") = source;
104 }
105 else
106 {
107 params.set<Real>("coef") = coef;
108 params.set<MooseFunctorName>("v") = {source};
109 }
110
111 getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_source", params);
112 }
113 // Time derivative
115 {
116 const std::string kernel_type = "FVTimeKernel";
117 InputParameters params = getFactory().getValidParams(kernel_type);
118 params.set<NonlinearVariableName>("variable") = _var_name;
119 assignBlocks(params, _blocks);
120 getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_time", params);
121 }
122}
123
124void
126{
127 if (isParamValid("neumann_boundaries"))
128 {
129 const auto & boundary_fluxes = getParam<std::vector<MooseFunctorName>>("boundary_fluxes");
130 for (const auto i : index_range(_neumann_boundaries))
131 {
132 const auto & bc_flux = boundary_fluxes[i];
133 // Select the boundary type based on the user parameters and what we know to be most efficient
134 std::string bc_type = "";
135 if (MooseUtils::parsesToReal(bc_flux))
136 bc_type = "FVNeumannBC";
137 else if (getProblem().hasFunction(bc_flux))
138 bc_type = "FVFunctionNeumannBC";
139 else
140 bc_type = "FVFunctorNeumannBC";
141
142 InputParameters params = getFactory().getValidParams(bc_type);
143 params.set<NonlinearVariableName>("variable") = _var_name;
144 params.set<std::vector<BoundaryName>>("boundary") = {_neumann_boundaries[i]};
145
146 // Set the boundary condition parameter for the specific boundary condition type used
147 if (MooseUtils::parsesToReal(bc_flux))
148 params.set<Real>("value") = MooseUtils::convert<Real>(bc_flux);
149 else if (getProblem().hasFunction(bc_flux))
150 params.set<FunctionName>("function") = bc_flux;
151 else
152 params.set<MooseFunctorName>("functor") = bc_flux;
153
155 bc_type, prefix() + _var_name + "_neumann_bc_" + _neumann_boundaries[i], params);
156 }
157 }
158
159 if (isParamValid("dirichlet_boundaries"))
160 {
161 const auto & boundary_values = getParam<std::vector<MooseFunctorName>>("boundary_values");
162 for (const auto i : index_range(_dirichlet_boundaries))
163 {
164 const auto & bc_value = boundary_values[i];
165 // Select the boundary type based on the user parameters and what we know to be most efficient
166 std::string bc_type = "";
167 if (MooseUtils::parsesToReal(bc_value))
168 bc_type = "FVDirichletBC";
169 else if (getProblem().hasFunction(bc_value))
170 bc_type = "FVFunctionDirichletBC";
171 else
172 bc_type = "FVADFunctorDirichletBC";
173
174 InputParameters params = getFactory().getValidParams(bc_type);
175 params.set<NonlinearVariableName>("variable") = _var_name;
176 params.set<std::vector<BoundaryName>>("boundary") = {_dirichlet_boundaries[i]};
177
178 // Set the boundary condition parameter for the specific boundary condition type used
179 if (MooseUtils::parsesToReal(bc_value))
180 params.set<Real>("value") = MooseUtils::convert<Real>(bc_value);
181 else if (getProblem().hasFunction(bc_value))
182 params.set<FunctionName>("function") = bc_value;
183 else
184 params.set<MooseFunctorName>("functor") = bc_value;
185
187 bc_type, prefix() + _var_name + "_dirichlet_bc_" + _dirichlet_boundaries[i], params);
188 }
189 }
190}
191
192void
194{
196 {
197 reportPotentiallyMissedParameters({"system_names"}, "MooseVariableFVReal");
198 return;
199 }
200
201 const std::string variable_type = "MooseVariableFVReal";
202 InputParameters params = getFactory().getValidParams(variable_type);
203 assignBlocks(params, _blocks);
204 params.set<SolverSystemName>("solver_sys") = getSolverSystem(_var_name);
205 getProblem().addVariable(variable_type, _var_name, params);
206}
207
210{
211 const auto necessary_layers =
212 std::max(getParam<unsigned short>("ghost_layers"), (unsigned short)2);
213
214 // Just an object that has a ghost_layers parameter
215 const std::string kernel_type = "FVDiffusion";
216 InputParameters params = getFactory().getValidParams(kernel_type);
217 params.template set<unsigned short>("ghost_layers") = necessary_layers;
218
219 return params;
220}
registerMooseAction("MooseApp", DiffusionFV, "add_fv_kernel")
registerDiffusionPhysicsBaseTasks("MooseApp", DiffusionFV)
Creates all the objects needed to solve a diffusion equation with a cell-centered finite volume discr...
Definition DiffusionFV.h:19
virtual void initializePhysicsAdditional() override
Additional initialization work that should happen very early, as soon as the problem is created.
Definition DiffusionFV.C:41
virtual void addFVKernels() override
Definition DiffusionFV.C:47
virtual void addSolverVariables() override
The default implementation of these routines will do nothing as we do not expect all Physics to be de...
static InputParameters validParams()
Definition DiffusionFV.C:20
virtual InputParameters getAdditionalRMParams() const override
Provide additional parameters for the relationship managers.
DiffusionFV(const InputParameters &parameters)
Definition DiffusionFV.C:35
virtual void addFVBCs() 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.
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
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 needFV() override
marks this problem as including/needing finite volume functionality.
virtual void addFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
virtual void addFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
Base class to help creating an entire physics.
Definition PhysicsBase.h:31
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 &params, 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 > &param_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.
bool parsesToReal(const std::string &input, Real *parsed_real)
Definition MooseUtils.C:152