https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PNSLinearFVSolidHeatTransferPhysics.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
11
13registerMooseAction("NavierStokesApp", PNSLinearFVSolidHeatTransferPhysics, "add_variable");
15registerMooseAction("NavierStokesApp", PNSLinearFVSolidHeatTransferPhysics, "add_linear_fv_kernel");
16registerMooseAction("NavierStokesApp", PNSLinearFVSolidHeatTransferPhysics, "add_linear_fv_bc");
17registerMooseAction("NavierStokesApp", PNSLinearFVSolidHeatTransferPhysics, "add_material");
18registerMooseAction("NavierStokesApp", PNSLinearFVSolidHeatTransferPhysics, "add_preconditioning");
19
22{
24 params.addClassDescription("Define the Navier Stokes porous media solid energy equation with "
25 "the linear finite volume discretization");
26
27 params.addParam<bool>(
28 "use_nonorthogonal_correction",
29 true,
30 "Whether to use a non-orthogonal correction. This can potentially slow down convergence, "
31 "but reduces numerical dispersion on non-orthogonal meshes. Can be safely turned off on "
32 "orthogonal meshes.");
33 params.addParamNamesToGroup("use_nonorthogonal_correction", "Numerical scheme");
34 params.set<std::vector<SolverSystemName>>("system_names") = {"solid_energy_system"};
35
36 // The linear finite volume variable has no face interpolation or two-term boundary options
37 params.suppressParameter<MooseEnum>("solid_temperature_face_interpolation");
38 params.suppressParameter<bool>("solid_temperature_two_term_bc_expansion");
39 params.suppressParameter<Real>("temperature_scaling");
40 // The linear solvers do not use the nonlinear enthalpy material, which requires AD
41 params.set<bool>("use_external_enthalpy_material") = true;
42 params.suppressParameter<bool>("use_external_enthalpy_material");
43 params.suppressParameter<MooseEnum>("preconditioning");
44 // The solid heat source is specified with 'external_heat_source'
45 params.suppressParameter<MooseFunctorName>("heat_source_functor");
46
47 return params;
48}
49
51 const InputParameters & parameters)
53 _non_orthogonal_correction(getParam<bool>("use_nonorthogonal_correction"))
54{
55}
56
57void
59{
60 // Dont add if the user already defined the variable
62 /*error_if_aux=*/true))
64 getProblem().getVariable(0, _solid_temperature_name).blocks());
65 else
66 {
67 const std::string var_type = "MooseLinearVariableFVReal";
68 auto params = getFactory().getValidParams(var_type);
70 }
71}
72
73void
75{
76 // Linear finite volume variables are initialized by finite volume initial conditions
77 if (getParam<bool>("initialize_variables_from_mesh_file"))
78 return;
80 _blocks,
81 /*whether IC is a default*/ !isParamSetByUser("initial_temperature"),
82 /*error if already an IC*/ isParamSetByUser("initial_temperature")))
83 {
84 InputParameters params = getFactory().getValidParams("FVFunctionIC");
85 assignBlocks(params, _blocks);
86 params.set<VariableName>("variable") = _solid_temperature_name;
87 params.set<FunctionName>("function") = getParam<FunctionName>("initial_temperature");
89 "FVFunctionIC", prefix() + _solid_temperature_name + "_ic", params);
90 }
91}
92
93MooseFunctorName
95{
96 const MooseFunctorName name = prefix() + "solid_fraction";
97 if (getProblem().hasFunctor(name, /*thread_id=*/0))
98 return name;
99
100 const std::string object_type = "ParsedFunctorMaterial";
101 InputParameters params = getFactory().getValidParams(object_type);
102 assignBlocks(params, _blocks);
104 params.set<std::string>("expression") = "1 - " + _porosity_name;
105 else
106 {
107 params.set<std::string>("expression") = "1 - eps";
108 params.set<std::vector<std::string>>("functor_names") = {_porosity_name};
109 params.set<std::vector<std::string>>("functor_symbols") = {"eps"};
110 }
111 params.set<std::string>("property_name") = name;
112 getProblem().addMaterial(object_type, name + "_material", params);
113 return name;
114}
115
116void
118{
120
121 // Time derivative: (1 - eps) rho_s cp_s dT_s/dt
122 if (isTransient() &&
123 shouldCreateTimeDerivative(_solid_temperature_name, _blocks, /*error if defined*/ false))
124 {
125 const std::string kernel_type = "LinearFVTimeDerivative";
126 InputParameters params = getFactory().getValidParams(kernel_type);
127 assignBlocks(params, _blocks);
128 params.set<LinearVariableName>("variable") = _solid_temperature_name;
129
130 const std::string object_type = "ParsedFunctorMaterial";
131 InputParameters mat_params = getFactory().getValidParams(object_type);
132 assignBlocks(mat_params, _blocks);
133 const auto solid_fraction = addSolidFractionFunctor();
134 std::vector<std::string> names = {solid_fraction};
135 std::vector<std::string> symbols = {"f0"};
136 std::vector<std::string> factors = {"f0"};
137 for (const auto & functor : {_density_name, _specific_heat_name})
138 if (MooseUtils::parsesToReal(functor))
139 factors.push_back(functor);
140 else
141 {
142 names.push_back(functor);
143 symbols.push_back("f" + std::to_string(symbols.size()));
144 factors.push_back(symbols.back());
145 }
146 mat_params.set<std::string>("expression") = MooseUtils::stringJoin(factors, " * ");
147 mat_params.set<std::vector<std::string>>("functor_names") = names;
148 mat_params.set<std::vector<std::string>>("functor_symbols") = symbols;
149 const auto capacity_name = prefix() + "solid_heat_capacity";
150 mat_params.set<std::string>("property_name") = capacity_name;
151 getProblem().addMaterial(object_type, capacity_name + "_material", mat_params);
152
153 params.set<MooseFunctorName>("factor") = capacity_name;
154 // The solid is stationary, so (1 - eps) rho_s is constant in time and the stored energy changes
155 // as (1 - eps) rho_s dh_s/dt = (1 - eps) rho_s cp_s dT_s/dt. The specific heat must stay
156 // outside the derivative: d(cp_s T_s)/dt is not dh_s/dt when cp_s depends on the temperature.
157 params.set<bool>("conservative_form") = false;
158 getProblem().addLinearFVKernel(kernel_type, prefix() + "solid_energy_time", params);
159 }
160
161 // Conduction. The solid thermal conductivity is an effective conductivity, either a scalar or
162 // the diagonal of an anisotropic conductivity tensor
163 {
164 const bool vector_conductivity = processThermalConductivity();
165 const std::string kernel_type =
166 vector_conductivity ? "LinearFVAnisotropicDiffusion" : "LinearFVDiffusion";
167 InputParameters params = getFactory().getValidParams(kernel_type);
168 params.set<LinearVariableName>("variable") = _solid_temperature_name;
169 params.set<bool>("use_nonorthogonal_correction") = _non_orthogonal_correction;
170 std::vector<SubdomainName> conduction_blocks;
171 for (const auto & block_group : _thermal_conductivity_blocks)
172 conduction_blocks.insert(conduction_blocks.end(), block_group.begin(), block_group.end());
173 assignBlocks(params, _thermal_conductivity_blocks.size() ? conduction_blocks : _blocks);
174 // Multiple conductivities are combined by the material of the base class
175 params.set<MooseFunctorName>(vector_conductivity ? "diffusion_tensor" : "diffusion_coeff") =
176 _thermal_conductivity_blocks.size() > 1 ? prefix() + "combined_thermal_conductivity"
178 getProblem().addLinearFVKernel(kernel_type, prefix() + "solid_energy_diffusion", params);
179 }
180
181 // Volumetric heat exchange with the fluid
182 if (_ambient_convection_alpha.size())
183 {
185 const std::string kernel_type = "LinearFVVolumetricHeatTransfer";
186 InputParameters params = getFactory().getValidParams(kernel_type);
187 params.set<LinearVariableName>("variable") = _solid_temperature_name;
188 params.set<VariableName>(NS::T_solid) = _solid_temperature_name;
189 params.set<bool>("is_solid") = true;
190 const auto num_convection_blocks = _ambient_convection_blocks.size();
191 for (const auto block_i : make_range(num_convection_blocks ? num_convection_blocks : 1))
192 {
193 if (num_convection_blocks)
194 params.set<std::vector<SubdomainName>>("block") = _ambient_convection_blocks[block_i];
195 else
196 assignBlocks(params, _blocks);
197 params.set<MooseFunctorName>("h_solid_fluid") = _ambient_convection_alpha[block_i];
198 params.set<VariableName>(NS::T_fluid) =
201 kernel_type, prefix() + "ambient_convection_" + std::to_string(block_i), params);
202 }
203 }
204
205 // External heat source, a density per unit total volume
206 if (isParamValid("external_heat_source"))
207 {
208 const std::string kernel_type = "LinearFVSource";
209 InputParameters params = getFactory().getValidParams(kernel_type);
210 params.set<LinearVariableName>("variable") = _solid_temperature_name;
211 const auto & source_blocks =
212 getParam<std::vector<SubdomainName>>("external_heat_source_blocks");
213 assignBlocks(params, source_blocks.size() ? source_blocks : _blocks);
214 params.set<MooseFunctorName>("source_density") =
215 getParam<MooseFunctorName>("external_heat_source");
216 params.set<MooseFunctorName>("scaling_factor") =
217 std::to_string(getParam<Real>("external_heat_source_coeff"));
218 getProblem().addLinearFVKernel(kernel_type, prefix() + "external_heat_source", params);
219 }
220}
221
222void
224{
225 // Faces without a boundary condition are insulated
226 const auto add_bcs = [this](const std::string & bc_type,
227 const std::string & boundaries_param,
228 const std::string & functors_param,
229 const std::string & conductivity_param_name)
230 {
231 const auto & boundaries = getParam<std::vector<BoundaryName>>(boundaries_param);
232 const auto & functors = getParam<std::vector<MooseFunctorName>>(functors_param);
233 InputParameters params = getFactory().getValidParams(bc_type);
234 params.set<LinearVariableName>("variable") = _solid_temperature_name;
235 for (const auto i : index_range(boundaries))
236 {
237 params.set<std::vector<BoundaryName>>("boundary") = {boundaries[i]};
238 params.set<MooseFunctorName>("functor") = functors[i];
239 // The heat flux conditions recover the boundary temperature with the conductivity
240 if (!conductivity_param_name.empty())
241 params.set<MooseFunctorName>(conductivity_param_name) =
242 _thermal_conductivity_blocks.size() > 1 ? prefix() + "combined_thermal_conductivity"
245 bc_type, prefix() + _solid_temperature_name + "_" + boundaries[i], params);
246 }
247 };
248
249 add_bcs("LinearFVAdvectionDiffusionFunctorDirichletBC",
250 "fixed_temperature_boundaries",
251 "boundary_temperatures",
252 "");
253 if (getParam<std::vector<BoundaryName>>("heat_flux_boundaries").size())
254 {
255 const bool vector_conductivity = processThermalConductivity();
256 add_bcs(vector_conductivity ? "LinearFVAnisotropicDiffusionFunctorNeumannBC"
257 : "LinearFVAdvectionDiffusionFunctorNeumannBC",
258 "heat_flux_boundaries",
259 "boundary_heat_fluxes",
260 vector_conductivity ? "diffusion_tensor" : "diffusion_coeff");
261 }
262}
registerPhysicsBaseTasks("NavierStokesApp", PNSLinearFVSolidHeatTransferPhysics)
registerMooseAction("NavierStokesApp", PNSLinearFVSolidHeatTransferPhysics, "add_variable")
const std::string name
Definition Setup.h:21
virtual void addLinearFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
virtual void addLinearFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
virtual void addFVInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
void suppressParameter(const std::string &name)
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
bool isParamSetByUser(const std::string &name) const
const T & getParam(const std::string &name) const
bool isParamValid(const std::string &name) const
Creates all the objects needed to solve the porous media solid energy equation.
const MooseFunctorName _porosity_name
Name of the porosity functor (usually material property)
std::vector< MooseFunctorName > _thermal_conductivity_name
Name of the thermal conductivity functor for each block-group.
std::vector< MooseFunctorName > _ambient_temperature
Name of the solid domain temperature for each block-group.
std::vector< std::vector< SubdomainName > > _ambient_convection_blocks
Vector of subdomain groups where we want to have different ambient convection.
bool processThermalConductivity()
Process thermal conductivity (multiple functor input options are available).
std::vector< std::vector< SubdomainName > > _thermal_conductivity_blocks
Vector of subdomain groups where we want to have different thermal conduction.
const NonlinearVariableName _solid_temperature_name
Solid temperature name.
const MooseFunctorName _specific_heat_name
Name of the specific heat functor (usually material property)
std::vector< MooseFunctorName > _ambient_convection_alpha
Name of the ambient convection heat transfer coefficients for each block-group.
const MooseFunctorName _density_name
Name of the density functor (usually material property)
void checkAmbientConvectionParameters() const
Check the number of ambient convection heat transfer coefficients against the blocks.
void checkFluidAndSolidHeatTransferPhysicsParameters() const
Battery of additional checks on parameters.
Creates all the objects needed to solve the porous media solid energy equation with the linear finite...
MooseFunctorName addSolidFractionFunctor()
Return the solid fraction of the volume, (1 - porosity), as a functor name.
PNSLinearFVSolidHeatTransferPhysics(const InputParameters &parameters)
const bool _non_orthogonal_correction
Whether to use the correction term for non-orthogonality in the conduction term.
virtual FEProblemBase & getProblem()
Factory & getFactory()
bool shouldCreateIC(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool ic_is_default_ic, const bool error_if_already_defined) const
bool checkBlockRestrictionIdentical(const std::string &object_name, const std::vector< SubdomainName > &blocks, const bool error_if_not_identical=true) const
bool shouldCreateTimeDerivative(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_already_defined) const
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
std::string prefix() const
bool variableExists(const VariableName &var_name, bool error_if_aux) const
void addSharedSolverVariable(const std::string &var_type, const VariableName &var_name, InputParameters params)
bool isTransient() const
std::vector< SubdomainName > _blocks
const std::vector< SubdomainName > & blocks() const
bool parsesToReal(const std::string &input, Real *parsed_real)
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator=" ")
static const std::string T_fluid
Definition NS.h:110
static const std::string T_solid
Definition NS.h:111