https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WCNSLinearFVScalarTransportPhysics.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
12#include "NSFVUtils.h"
13#include "NS.h"
14
17registerMooseAction("NavierStokesApp",
19 "add_interpolation_method_physics");
20
23{
25 params.addClassDescription("Define the Navier Stokes weakly-compressible scalar field transport "
26 "equation(s) using the linear finite volume discretization");
27 params.set<MooseEnum>("passive_scalar_advection_interpolation") =
29 params.addParam<InterpolationMethodName>(
30 "passive_scalar_advection_interpolation_method_name",
31 "Name of an externally defined FVInterpolationMethod to use for passive scalar advection. "
32 "When provided, this overrides 'passive_scalar_advection_interpolation'.");
33 params.addParam<bool>("use_nonorthogonal_correction",
34 true,
35 "If the nonorthogonal correction should be used when computing the normal "
36 "gradient, notably in the diffusion term.");
37
38 // Not supported
39 params.suppressParameter<MooseEnum>("preconditioning");
40
41 params.addParamNamesToGroup("passive_scalar_advection_interpolation_method_name",
42 "Numerical scheme");
43
44 return params;
45}
46
53
54MooseFunctorName
56{
57 // The scalars are concentrations per unit fluid volume, so storage, diffusion and sources act on
58 // the fluid fraction of the volume. Advection uses the superficial face flux unscaled.
61 _flow_equations_physics->getPorosityFunctorName(/*smoothed=*/false), functor)
62 : functor;
63}
64
65void
67{
68 if (!_has_scalar_equation || isParamValid("passive_scalar_advection_interpolation_method_name"))
69 return;
70
71 addFVAdvectedInterpolationMethod(getParam<MooseEnum>("passive_scalar_advection_interpolation"));
72}
73
74void
76{
77 // For compatibility with Modules/NavierStokesFV syntax
79 return;
80
81 auto params = getFactory().getValidParams("MooseLinearVariableFVReal");
82
83 for (const auto name_i : index_range(_passive_scalar_names))
84 {
85 // Dont add if the user already defined the variable
86 if (!shouldCreateVariable(_passive_scalar_names[name_i], _blocks, /*error if aux*/ true))
87 {
88 reportPotentiallyMissedParameters({"system_names", "passive_scalar_scaling"},
89 "MooseLinearVariableFVReal");
90 continue;
91 }
92
93 if (isParamValid("passive_scalar_scaling"))
94 params.set<std::vector<Real>>("scaling") = {
95 getParam<std::vector<Real>>("passive_scalar_scaling")[name_i]};
96
97 addSharedSolverVariable("MooseLinearVariableFVReal", _passive_scalar_names[name_i], params);
98 }
99}
100
101void
103{
104 std::string kernel_type = "LinearFVTimeDerivative";
105 InputParameters params = getFactory().getValidParams(kernel_type);
106 assignBlocks(params, _blocks);
108 params.set<MooseFunctorName>("factor") = fluidFractionScaled("1");
109
110 for (const auto & vname : _passive_scalar_names)
111 {
112 params.set<LinearVariableName>("variable") = vname;
113 if (shouldCreateTimeDerivative(vname, _blocks, /*error if already defined */ false))
114 getProblem().addLinearFVKernel(kernel_type, prefix() + "ins_" + vname + "_time", params);
115 }
116}
117
118void
120{
121 const auto method_name =
122 isParamValid("passive_scalar_advection_interpolation_method_name")
123 ? getParam<InterpolationMethodName>("passive_scalar_advection_interpolation_method_name")
124 : InterpolationMethodName(
125 std::string(getParam<MooseEnum>("passive_scalar_advection_interpolation")));
126
127 const std::string kernel_type = "LinearFVScalarAdvection";
128 InputParameters params = getFactory().getValidParams(kernel_type);
129
130 assignBlocks(params, _blocks);
131 params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
132 params.set<InterpolationMethodName>("advected_interp_method_name") = method_name;
133 setSlipVelocityParams(params);
134
135 for (const auto & vname : _passive_scalar_names)
136 {
137 params.set<LinearVariableName>("variable") = vname;
138 getProblem().addLinearFVKernel(kernel_type, prefix() + "ins_" + vname + "_advection", params);
139 }
140}
141
142void
144{
145 // Direct specification of diffusion term
146 const auto passive_scalar_diffusivities =
147 getParam<std::vector<MooseFunctorName>>("passive_scalar_diffusivity");
148
149 if (passive_scalar_diffusivities.size())
150 {
151 const std::string kernel_type = "LinearFVDiffusion";
152 InputParameters params = getFactory().getValidParams(kernel_type);
153 assignBlocks(params, _blocks);
154 params.set<bool>("use_nonorthogonal_correction") =
155 getParam<bool>("use_nonorthogonal_correction");
156 for (const auto name_i : index_range(_passive_scalar_names))
157 {
158 params.set<LinearVariableName>("variable") = _passive_scalar_names[name_i];
159 params.set<MooseFunctorName>("diffusion_coeff") = fluidFractionScaled(
160 passive_scalar_diffusivities[name_i] + (_has_turbulence_model ? "_plus_mut/Sc_t" : ""));
162 kernel_type, prefix() + "ins_" + _passive_scalar_names[name_i] + "_diffusion", params);
163 }
164 }
165}
166
167void
169{
170 const std::string kernel_type = "LinearFVSource";
171 InputParameters params = getFactory().getValidParams(kernel_type);
172 assignBlocks(params, _blocks);
173 const auto source_scaling = fluidFractionScaled("1");
174
175 for (const auto scalar_i : index_range(_passive_scalar_names))
176 {
177 params.set<LinearVariableName>("variable") = _passive_scalar_names[scalar_i];
178
179 if (_passive_scalar_sources.size())
180 {
181 // Added for backward compatibility with former Modules/NavierStokesFV syntax
182 params.set<MooseFunctorName>("source_density") = _passive_scalar_sources[scalar_i];
183 params.set<MooseFunctorName>("scaling_factor") = source_scaling;
185 kernel_type, prefix() + "ins_" + _passive_scalar_names[scalar_i] + "_source", params);
186 }
187
189 for (const auto i : index_range(_passive_scalar_coupled_sources[scalar_i]))
190 {
191 params.set<MooseFunctorName>("source_density") =
193 params.set<MooseFunctorName>("scaling_factor") =
197 : source_scaling;
199 params.set<std::vector<SubdomainName>>("block") =
201
202 getProblem().addLinearFVKernel(kernel_type,
203 prefix() + "ins_" + _passive_scalar_names[scalar_i] +
204 "_coupled_source_" + std::to_string(i),
205 params);
206 }
207 }
208}
209
210void
212{
213 const auto & inlet_boundaries = _flow_equations_physics->getInletBoundaries();
214 if (inlet_boundaries.empty())
215 return;
216
217 // Boundary checks
218 // TODO: once we have vectors of MooseEnum, we could use the same templated check for types and
219 // functors
220 if (inlet_boundaries.size() * _passive_scalar_names.size() != _passive_scalar_inlet_types.size())
222 "passive_scalar_inlet_types",
223 "The number of scalar inlet types (" + std::to_string(_passive_scalar_inlet_types.size()) +
224 ") is not equal to the number of inlet boundaries (" +
225 std::to_string(inlet_boundaries.size()) + ") times the number of passive scalars (" +
226 std::to_string(_passive_scalar_names.size()) + ")");
228 paramError("passive_scalar_inlet_functors",
229 "The number of groups of inlet functors (" +
230 std::to_string(_passive_scalar_inlet_functors.size()) +
231 ") is not equal to the number of passive scalars (" +
232 std::to_string(_passive_scalar_names.size()) + ")");
233
234 for (const auto name_i : index_range(_passive_scalar_names))
235 {
236 if (inlet_boundaries.size() != _passive_scalar_inlet_functors[name_i].size())
237 paramError("passive_scalar_inlet_functors",
238 "The number of inlet boundary functors for scalar '" +
239 _passive_scalar_names[name_i] +
240 "' does not match the number of inlet boundaries (" +
241 std::to_string(_passive_scalar_inlet_functors[name_i].size()) + ")");
242
243 unsigned int num_inlets = inlet_boundaries.size();
244 for (unsigned int bc_ind = 0; bc_ind < num_inlets; ++bc_ind)
245 {
246 if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "fixed-value")
247 {
248 const std::string bc_type = "LinearFVAdvectionDiffusionFunctorDirichletBC";
249 InputParameters params = getFactory().getValidParams(bc_type);
250 params.set<LinearVariableName>("variable") = _passive_scalar_names[name_i];
251 params.set<MooseFunctorName>("functor") = _passive_scalar_inlet_functors[name_i][bc_ind];
252 params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
253
255 bc_type, _passive_scalar_names[name_i] + "_" + inlet_boundaries[bc_ind], params);
256 }
257 else if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-mass" ||
258 _passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-velocity")
259 {
260 mooseError("Flux boundary conditions not supported at this time using the linear finite "
261 "volume discretization");
262 }
263 }
264 }
265}
266
267unsigned short
272
273void
275{
276 const auto & outlet_boundaries = _flow_equations_physics->getOutletBoundaries();
277 if (outlet_boundaries.empty())
278 return;
279
280 for (const auto & outlet_bdy : outlet_boundaries)
281 {
282 const std::string bc_type = "LinearFVAdvectionDiffusionOutflowBC";
283 InputParameters params = getFactory().getValidParams(bc_type);
284 params.set<std::vector<BoundaryName>>("boundary") = {outlet_bdy};
285 params.set<bool>("use_two_term_expansion") =
286 getParam<bool>("passive_scalar_two_term_bc_expansion");
287
288 for (const auto name_i : index_range(_passive_scalar_names))
289 {
290 params.set<LinearVariableName>("variable") = _passive_scalar_names[name_i];
291 getProblem().addLinearFVBC(bc_type, _passive_scalar_names[name_i] + "_" + outlet_bdy, params);
292 }
293 }
294}
registerMooseAction("NavierStokesApp", WCNSLinearFVScalarTransportPhysics, "add_interpolation_method_physics")
registerNavierStokesPhysicsBaseTasks("NavierStokesApp", WCNSLinearFVScalarTransportPhysics)
registerWCNSFVScalarTransportBaseTasks("NavierStokesApp", WCNSLinearFVScalarTransportPhysics)
virtual void addLinearFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addLinearFVBC(const std::string &fv_bc_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)
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) const
unsigned int size() const
void addFVAdvectedInterpolationMethod(const MooseEnum &interpolation_method)
Add the FVInterpolationMethod object for an advected interpolation method if absent.
MooseFunctorName addPorosityScaledFunctor(const MooseFunctorName &porosity, const MooseFunctorName &functor)
Add, if absent, a non-AD functor material defining the product of a porosity and another functor on t...
virtual FEProblemBase & getProblem()
Factory & getFactory()
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
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type, const std::string &object_name="") const
std::string prefix() const
void addSharedSolverVariable(const std::string &var_type, const VariableName &var_name, InputParameters params)
bool shouldCreateVariable(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_aux)
std::vector< SubdomainName > _blocks
void addRequiredPhysicsTask(const std::string &task)
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
bool _has_turbulence_model
Because of the Modules/navierStokesFV syntax, a turbulence physics often exists without a model we sa...
const bool _porous_medium_treatment
Switch to show if porous medium treatment is requested or not.
const UserObjectName & rhieChowUOName() const
Return the name of the Rhie Chow user object.
const std::vector< BoundaryName > & getOutletBoundaries() const
Get the outlet boundaries.
const std::vector< BoundaryName > & getInletBoundaries() const
Get the inlet boundaries.
MooseFunctorName getPorosityFunctorName(const bool smoothed) const
Creates all the objects needed to solve the Navier Stokes scalar transport equations.
const bool _has_scalar_equation
A boolean to help compatibility with the old Modules/NavierStokesFV syntax or to deliberately skip ad...
std::vector< MooseFunctorName > _passive_scalar_sources
Functors for the passive scalar sources. Indexing is scalar variable index.
std::vector< std::vector< MooseFunctorName > > _passive_scalar_coupled_sources
Functors for the passive scalar (coupled) sources. Outer indexing is scalar variable index.
MultiMooseEnum _passive_scalar_inlet_types
Passive scalar inlet boundary types.
std::vector< std::vector< std::vector< SubdomainName > > > _passive_scalar_coupled_sources_blocks
Subdomains for the sources. Outer indexing is scalar index, intermediate is source index,...
std::vector< std::vector< Real > > _passive_scalar_coupled_sources_coef
Coefficients for multiplying for the passive scalar sources. Outer indexing is scalar variable index.
virtual void setSlipVelocityParams(InputParameters &) const
std::vector< NonlinearVariableName > _passive_scalar_names
Names of the passive scalar variables.
std::vector< std::vector< MooseFunctorName > > _passive_scalar_inlet_functors
Functors describing the inlet boundary values. See passive_scalar_inlet_types for what the functors a...
Creates all the objects needed to solve the Navier Stokes scalar transport equations using the linear...
virtual unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of ghosting layers needed.
virtual void addScalarTimeKernels() override
Functions adding kernels for the incompressible / weakly-compressible scalar transport equation If th...
virtual void addScalarInletBC() override
Functions adding boundary conditions for the incompressible simulation.
MooseFunctorName fluidFractionScaled(const MooseFunctorName &functor)
Return the functor scaled by the porosity for porous flow, the functor itself otherwise.
WCNSLinearFVScalarTransportPhysics(const InputParameters &parameters)
virtual void addScalarSourceKernels() override
Equivalent of NSFVAction addScalarCoupledSourceKernels.
std::string stringify(const T &t)
MooseEnum fvAdvectedInterpolationMethods()
Enum of the advected interpolation methods supported by FVInterpolationMethod objects.
Definition NSFVUtils.C:61