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<MaterialPropertyName>("diffusivity_matprop");
26 params.addRequiredParam<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
50 {
51 const std::string kernel_type = "FVDiffusion";
52 InputParameters params = getFactory().getValidParams(kernel_type);
53 assignBlocks(params, _blocks);
54 params.set<NonlinearVariableName>("variable") = _var_name;
55 params.set<MooseFunctorName>("coeff") = getParam<MooseFunctorName>("diffusivity_functor");
56 getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_diffusion", params);
57 }
58 // Source term
59 if (isParamValid("source_functor"))
60 {
61 // Select the kernel type based on the user parameters
62 std::string kernel_type;
63
64 const auto & source = getParam<MooseFunctorName>("source_functor");
65 if (MooseUtils::parsesToReal(source) || getProblem().hasFunction(source) ||
66 getProblem().hasPostprocessorValueByName(source))
67 kernel_type = "FVBodyForce";
68 else if (getProblem().hasVariable(source))
69 kernel_type = "FVCoupledForce";
70 else
71 paramError("source_functor",
72 "No kernel defined for a source term in FV for the type used for '",
73 source,
74 "'");
75
76 InputParameters params = getFactory().getValidParams(kernel_type);
77 params.set<NonlinearVariableName>("variable") = _var_name;
78 assignBlocks(params, _blocks);
79
80 // Transfer the source and coefficient parameter from the Physics to the kernel
81 const auto coef = getParam<Real>("source_coef");
82 if (MooseUtils::parsesToReal(source))
83 params.set<Real>("value") = MooseUtils::convert<Real>(source) * coef;
84 else if (getProblem().hasFunction(source))
85 {
86 params.set<Real>("value") = coef;
87 params.set<FunctionName>("function") = source;
88 }
89 else if (getProblem().hasPostprocessorValueByName(source))
90 {
91 params.set<Real>("value") = coef;
92 params.set<PostprocessorName>("postprocessor") = source;
93 }
94 else
95 {
96 params.set<Real>("coef") = coef;
97 params.set<MooseFunctorName>("v") = {source};
98 }
99
100 getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_source", params);
101 }
102 // Time derivative
104 {
105 const std::string kernel_type = "FVTimeKernel";
106 InputParameters params = getFactory().getValidParams(kernel_type);
107 params.set<NonlinearVariableName>("variable") = _var_name;
108 assignBlocks(params, _blocks);
109 getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_time", params);
110 }
111}
112
113void
115{
116 if (isParamValid("neumann_boundaries"))
117 {
118 const auto & boundary_fluxes = getParam<std::vector<MooseFunctorName>>("boundary_fluxes");
119 for (const auto i : index_range(_neumann_boundaries))
120 {
121 const auto & bc_flux = boundary_fluxes[i];
122 // Select the boundary type based on the user parameters and what we know to be most efficient
123 std::string bc_type = "";
124 if (MooseUtils::parsesToReal(bc_flux))
125 bc_type = "FVNeumannBC";
126 else if (getProblem().hasFunction(bc_flux))
127 bc_type = "FVFunctionNeumannBC";
128 else
129 bc_type = "FVFunctorNeumannBC";
130
131 InputParameters params = getFactory().getValidParams(bc_type);
132 params.set<NonlinearVariableName>("variable") = _var_name;
133 params.set<std::vector<BoundaryName>>("boundary") = {_neumann_boundaries[i]};
134
135 // Set the boundary condition parameter for the specific boundary condition type used
136 if (MooseUtils::parsesToReal(bc_flux))
137 params.set<Real>("value") = MooseUtils::convert<Real>(bc_flux);
138 else if (getProblem().hasFunction(bc_flux))
139 params.set<FunctionName>("function") = bc_flux;
140 else
141 params.set<MooseFunctorName>("functor") = bc_flux;
142
144 bc_type, prefix() + _var_name + "_neumann_bc_" + _neumann_boundaries[i], params);
145 }
146 }
147
148 if (isParamValid("dirichlet_boundaries"))
149 {
150 const auto & boundary_values = getParam<std::vector<MooseFunctorName>>("boundary_values");
151 for (const auto i : index_range(_dirichlet_boundaries))
152 {
153 const auto & bc_value = boundary_values[i];
154 // Select the boundary type based on the user parameters and what we know to be most efficient
155 std::string bc_type = "";
156 if (MooseUtils::parsesToReal(bc_value))
157 bc_type = "FVDirichletBC";
158 else if (getProblem().hasFunction(bc_value))
159 bc_type = "FVFunctionDirichletBC";
160 else
161 bc_type = "FVADFunctorDirichletBC";
162
163 InputParameters params = getFactory().getValidParams(bc_type);
164 params.set<NonlinearVariableName>("variable") = _var_name;
165 params.set<std::vector<BoundaryName>>("boundary") = {_dirichlet_boundaries[i]};
166
167 // Set the boundary condition parameter for the specific boundary condition type used
168 if (MooseUtils::parsesToReal(bc_value))
169 params.set<Real>("value") = MooseUtils::convert<Real>(bc_value);
170 else if (getProblem().hasFunction(bc_value))
171 params.set<FunctionName>("function") = bc_value;
172 else
173 params.set<MooseFunctorName>("functor") = bc_value;
174
176 bc_type, prefix() + _var_name + "_dirichlet_bc_" + _dirichlet_boundaries[i], params);
177 }
178 }
179}
180
181void
183{
185 {
186 reportPotentiallyMissedParameters({"system_names"}, "MooseVariableFVReal");
187 return;
188 }
189
190 const std::string variable_type = "MooseVariableFVReal";
191 InputParameters params = getFactory().getValidParams(variable_type);
192 assignBlocks(params, _blocks);
193 params.set<SolverSystemName>("solver_sys") = getSolverSystem(_var_name);
194 getProblem().addVariable(variable_type, _var_name, params);
195}
196
199{
200 const auto necessary_layers =
201 std::max(getParam<unsigned short>("ghost_layers"), (unsigned short)2);
202
203 // Just an object that has a ghost_layers parameter
204 const std::string kernel_type = "FVDiffusion";
205 InputParameters params = getFactory().getValidParams(kernel_type);
206 params.template set<unsigned short>("ghost_layers") = necessary_layers;
207
208 return params;
209}
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
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:100