https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WCNSFVScalarTransportPhysics.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 "NSFVBase.h"
13#include "NS.h"
14
17
20{
22 params.addClassDescription("Define the Navier Stokes weakly-compressible scalar field transport "
23 "equation(s) using the nonlinear finite volume discretization");
24 params.transferParam<MooseEnum>(NSFVBase::validParams(), "passive_scalar_face_interpolation");
25 params.addParamNamesToGroup("passive_scalar_face_interpolation", "Numerical scheme");
26 return params;
27}
28
33
34void
36{
37 // For compatibility with Modules/NavierStokesFV syntax
39 return;
40
41 auto params = getFactory().getValidParams("INSFVScalarFieldVariable");
42 assignBlocks(params, _blocks);
43 params.set<MooseEnum>("face_interp_method") =
44 getParam<MooseEnum>("passive_scalar_face_interpolation");
45 params.set<bool>("two_term_boundary_expansion") =
46 getParam<bool>("passive_scalar_two_term_bc_expansion");
47
48 for (const auto name_i : index_range(_passive_scalar_names))
49 {
50 // Dont add if the user already defined the variable
51 if (!shouldCreateVariable(_passive_scalar_names[name_i], _blocks, /*error if aux*/ true))
52 {
53 reportPotentiallyMissedParameters({"system_names", "passive_scalar_scaling"},
54 "INSFVScalarFieldVariable");
55 continue;
56 }
57
58 params.set<SolverSystemName>("solver_sys") = getSolverSystem(name_i);
59 if (isParamValid("passive_scalar_scaling"))
60 params.set<std::vector<Real>>("scaling") = {
61 getParam<std::vector<Real>>("passive_scalar_scaling")[name_i]};
62
63 getProblem().addVariable("INSFVScalarFieldVariable", _passive_scalar_names[name_i], params);
64 }
65}
66
67void
69{
70 for (const auto & vname : _passive_scalar_names)
71 {
72 const std::string kernel_type = "FVFunctorTimeKernel";
73 InputParameters params = getFactory().getValidParams(kernel_type);
74 assignBlocks(params, _blocks);
75 params.set<NonlinearVariableName>("variable") = vname;
76
77 if (shouldCreateTimeDerivative(vname, _blocks, /* error if already defined */ false))
78 getProblem().addFVKernel(kernel_type, prefix() + "ins_" + vname + "_time", params);
79 }
80}
81
82void
84{
85 const std::string kernel_type =
86 _porous_medium_treatment ? "PINSFVScalarFieldAdvection" : "INSFVScalarFieldAdvection";
87 InputParameters params = getFactory().getValidParams(kernel_type);
88
89 assignBlocks(params, _blocks);
90 params.set<MooseEnum>("velocity_interp_method") = _velocity_interpolation;
91 params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
92 params.set<MooseEnum>("advected_interp_method") =
93 getParam<MooseEnum>("passive_scalar_advection_interpolation");
96 params.set<MooseFunctorName>(NS::porosity) =
98
99 for (const auto & vname : _passive_scalar_names)
100 {
101 params.set<NonlinearVariableName>("variable") = vname;
102 getProblem().addFVKernel(kernel_type, prefix() + "ins_" + vname + "_advection", params);
103 }
104}
105
106void
108{
109 // Direct specification of diffusion term
110 const auto passive_scalar_diffusivities =
111 getParam<std::vector<MooseFunctorName>>("passive_scalar_diffusivity");
112
113 if (passive_scalar_diffusivities.size())
114 {
115 const std::string kernel_type = "FVDiffusion";
116 InputParameters params = getFactory().getValidParams(kernel_type);
117 assignBlocks(params, _blocks);
118 for (const auto name_i : index_range(_passive_scalar_names))
119 {
120 params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
121 params.set<MooseFunctorName>("coeff") = passive_scalar_diffusivities[name_i];
123 kernel_type, prefix() + "ins_" + _passive_scalar_names[name_i] + "_diffusion", params);
124 }
125 }
126}
127
128void
130{
131 const std::string kernel_type = "FVCoupledForce";
132 InputParameters params = getFactory().getValidParams(kernel_type);
133 assignBlocks(params, _blocks);
134
135 for (const auto scalar_i : index_range(_passive_scalar_names))
136 {
137 params.set<NonlinearVariableName>("variable") = _passive_scalar_names[scalar_i];
138 if (_passive_scalar_sources.size())
139 {
140 // Added for backward compatibility with former Modules/NavierStokesFV syntax
141 params.set<MooseFunctorName>("v") = _passive_scalar_sources[scalar_i];
143 kernel_type, prefix() + "ins_" + _passive_scalar_names[scalar_i] + "_source", params);
144 }
145
146 // Sufficient for all intents and purposes
148 for (const auto i : index_range(_passive_scalar_coupled_sources[scalar_i]))
149 {
150 params.set<MooseFunctorName>("v") = _passive_scalar_coupled_sources[scalar_i][i];
152 params.set<Real>("coef") = _passive_scalar_sources_coef[scalar_i][i];
153 getProblem().addFVKernel(kernel_type,
154 prefix() + "ins_" + _passive_scalar_names[scalar_i] +
155 "_coupled_source_" + std::to_string(i),
156 params);
157 }
158 }
159}
160
161void
163{
164 const auto & inlet_boundaries = _flow_equations_physics->getInletBoundaries();
165 if (inlet_boundaries.empty())
166 return;
167
168 // Boundary checks
169 // TODO: once we have vectors of MooseEnum, we could use the same templated check for types and
170 // functors
171 if (inlet_boundaries.size() * _passive_scalar_names.size() != _passive_scalar_inlet_types.size())
173 "passive_scalar_inlet_types",
174 "The number of scalar inlet types (" + std::to_string(_passive_scalar_inlet_types.size()) +
175 ") is not equal to the number of inlet boundaries (" +
176 std::to_string(inlet_boundaries.size()) + ") times the number of passive scalars (" +
177 std::to_string(_passive_scalar_names.size()) + ")");
179 paramError("passive_scalar_inlet_functors",
180 "The number of groups of inlet functors (" +
181 std::to_string(_passive_scalar_inlet_functors.size()) +
182 ") is not equal to the number of passive scalars (" +
183 std::to_string(_passive_scalar_names.size()) + ")");
184
185 for (const auto name_i : index_range(_passive_scalar_names))
186 {
187 if (inlet_boundaries.size() != _passive_scalar_inlet_functors[name_i].size())
188 paramError("passive_scalar_inlet_functors",
189 "The number of inlet boundary functors for scalar '" +
190 _passive_scalar_names[name_i] +
191 "' does not match the number of inlet boundaries (" +
192 std::to_string(_passive_scalar_inlet_functors[name_i].size()) + ")");
193
194 unsigned int flux_bc_counter = 0;
195 unsigned int num_inlets = inlet_boundaries.size();
196 for (unsigned int bc_ind = 0; bc_ind < num_inlets; ++bc_ind)
197 {
198 if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "fixed-value")
199 {
200 const std::string bc_type = "FVADFunctorDirichletBC";
201 InputParameters params = getFactory().getValidParams(bc_type);
202 params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
203 params.set<MooseFunctorName>("functor") = _passive_scalar_inlet_functors[name_i][bc_ind];
204 params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
205
207 bc_type, _passive_scalar_names[name_i] + "_" + inlet_boundaries[bc_ind], params);
208 }
209 else if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-mass" ||
210 _passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-velocity")
211 {
212 const auto flux_inlet_directions = _flow_equations_physics->getFluxInletDirections();
213 const auto flux_inlet_pps = _flow_equations_physics->getFluxInletPPs();
214
215 const std::string bc_type = "WCNSFVScalarFluxBC";
216 InputParameters params = getFactory().getValidParams(bc_type);
217 params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
218 params.set<MooseFunctorName>("passive_scalar") = _passive_scalar_names[name_i];
219 if (flux_inlet_directions.size())
220 params.set<Point>("direction") = flux_inlet_directions[flux_bc_counter];
221 if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-mass")
222 {
223 params.set<PostprocessorName>("mdot_pp") = flux_inlet_pps[flux_bc_counter];
224 params.set<PostprocessorName>("area_pp") = "area_pp_" + inlet_boundaries[bc_ind];
225 }
226 else
227 params.set<PostprocessorName>("velocity_pp") = flux_inlet_pps[flux_bc_counter];
228
229 params.set<MooseFunctorName>(NS::density) = _density_name;
230 params.set<PostprocessorName>("scalar_value_pp") =
231 _passive_scalar_inlet_functors[name_i][bc_ind];
232 params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
233
234 params.set<MooseFunctorName>(NS::velocity_x) = _velocity_names[0];
235 if (dimension() > 1)
236 params.set<MooseFunctorName>(NS::velocity_y) = _velocity_names[1];
237 if (dimension() > 2)
238 params.set<MooseFunctorName>(NS::velocity_z) = _velocity_names[2];
239
240 getProblem().addFVBC(bc_type,
241 prefix() + _passive_scalar_names[name_i] + "_" +
242 inlet_boundaries[bc_ind],
243 params);
244 flux_bc_counter += 1;
245 }
246 }
247 }
248}
249
250void
252{
253 // Advection outlet is naturally handled by the advection flux kernel
254 return;
255}
registerNavierStokesPhysicsBaseTasks("NavierStokesApp", WCNSFVScalarTransportPhysics)
registerWCNSFVScalarTransportBaseTasks("NavierStokesApp", WCNSFVScalarTransportPhysics)
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
virtual void addFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
virtual void addFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void transferParam(const InputParameters &source_param, const std::string &name, const std::string &new_name="", const std::string &new_description="")
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
bool isParamValid(const std::string &name) const
unsigned int size() const
static InputParameters validParams()
Definition NSFVBase.C:371
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
unsigned int dimension() 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
const SolverSystemName & getSolverSystem(unsigned int variable_index) const
bool shouldCreateVariable(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_aux)
std::vector< SubdomainName > _blocks
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
const std::vector< std::string > _velocity_names
Velocity names.
const bool _porous_medium_treatment
Switch to show if porous medium treatment is requested or not.
const MooseEnum _velocity_interpolation
The velocity / momentum face interpolation method for advecting other quantities.
const MooseFunctorName _density_name
Name of the density material property.
const UserObjectName & rhieChowUOName() const
Return the name of the Rhie Chow user object.
const std::vector< BoundaryName > & getInletBoundaries() const
Get the inlet boundaries.
MooseFunctorName getPorosityFunctorName(const bool smoothed) const
const std::vector< PostprocessorName > & getFluxInletPPs() const
Get the inlet flux postprocessor if using a flux inlet.
const std::vector< Point > & getFluxInletDirections() const
Get the inlet direction if using a flux inlet.
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< std::vector< Real > > _passive_scalar_sources_coef
Coefficients multiplying for the passive scalar sources. Inner indexing is scalar variable index.
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. Inner indexing is scalar variable index.
MultiMooseEnum _passive_scalar_inlet_types
Passive scalar inlet boundary types.
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 nonlin...
WCNSFVScalarTransportPhysics(const InputParameters &parameters)
virtual void addScalarSourceKernels() override
Equivalent of NSFVAction addScalarCoupledSourceKernels.
virtual void addScalarDiffusionKernels() override
virtual void addScalarAdvectionKernels() override
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.
static const std::string density
Definition NS.h:34
static const std::string velocity_y
Definition NS.h:48
static const std::string velocity_z
Definition NS.h:49
static const std::string porosity
Definition NS.h:108
static const std::string velocity_x
Definition NS.h:47