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 params.set<MooseEnum>("face_interp_method") =
43 getParam<MooseEnum>("passive_scalar_face_interpolation");
44 params.set<bool>("two_term_boundary_expansion") =
45 getParam<bool>("passive_scalar_two_term_bc_expansion");
46
47 for (const auto name_i : index_range(_passive_scalar_names))
48 {
49 // Dont add if the user already defined the variable
50 if (!shouldCreateVariable(_passive_scalar_names[name_i], _blocks, /*error if aux*/ true))
51 {
52 reportPotentiallyMissedParameters({"system_names", "passive_scalar_scaling"},
53 "INSFVScalarFieldVariable");
54 continue;
55 }
56
57 if (isParamValid("passive_scalar_scaling"))
58 params.set<std::vector<Real>>("scaling") = {
59 getParam<std::vector<Real>>("passive_scalar_scaling")[name_i]};
60
61 addSharedSolverVariable("INSFVScalarFieldVariable", _passive_scalar_names[name_i], params);
62 }
63}
64
65void
67{
68 for (const auto & vname : _passive_scalar_names)
69 {
70 const std::string kernel_type = "FVFunctorTimeKernel";
71 InputParameters params = getFactory().getValidParams(kernel_type);
72 assignBlocks(params, _blocks);
73 params.set<NonlinearVariableName>("variable") = vname;
74
75 if (shouldCreateTimeDerivative(vname, _blocks, /* error if already defined */ false))
76 getProblem().addFVKernel(kernel_type, prefix() + "ins_" + vname + "_time", params);
77 }
78}
79
80void
82{
83 const std::string kernel_type =
84 _porous_medium_treatment ? "PINSFVScalarFieldAdvection" : "INSFVScalarFieldAdvection";
85 InputParameters params = getFactory().getValidParams(kernel_type);
86
87 assignBlocks(params, _blocks);
88 params.set<MooseEnum>("velocity_interp_method") = _velocity_interpolation;
89 params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
90 params.set<MooseEnum>("advected_interp_method") =
91 getParam<MooseEnum>("passive_scalar_advection_interpolation");
94 params.set<MooseFunctorName>(NS::porosity) =
96
97 for (const auto & vname : _passive_scalar_names)
98 {
99 params.set<NonlinearVariableName>("variable") = vname;
100 getProblem().addFVKernel(kernel_type, prefix() + "ins_" + vname + "_advection", params);
101 }
102}
103
104void
106{
107 // Direct specification of diffusion term
108 const auto passive_scalar_diffusivities =
109 getParam<std::vector<MooseFunctorName>>("passive_scalar_diffusivity");
110
111 if (passive_scalar_diffusivities.size())
112 {
113 const std::string kernel_type = "FVDiffusion";
114 InputParameters params = getFactory().getValidParams(kernel_type);
115 assignBlocks(params, _blocks);
116 for (const auto name_i : index_range(_passive_scalar_names))
117 {
118 params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
119 params.set<MooseFunctorName>("coeff") = passive_scalar_diffusivities[name_i];
121 kernel_type, prefix() + "ins_" + _passive_scalar_names[name_i] + "_diffusion", params);
122 }
123 }
124}
125
126void
128{
129 const std::string kernel_type = "FVCoupledForce";
130 InputParameters params = getFactory().getValidParams(kernel_type);
131 assignBlocks(params, _blocks);
132
133 for (const auto scalar_i : index_range(_passive_scalar_names))
134 {
135 params.set<NonlinearVariableName>("variable") = _passive_scalar_names[scalar_i];
136 if (_passive_scalar_sources.size())
137 {
138 // Added for backward compatibility with former Modules/NavierStokesFV syntax
139 params.set<MooseFunctorName>("v") = _passive_scalar_sources[scalar_i];
141 kernel_type, prefix() + "ins_" + _passive_scalar_names[scalar_i] + "_source", params);
142 }
143
144 // Sufficient for all intents and purposes
146 for (const auto i : index_range(_passive_scalar_coupled_sources[scalar_i]))
147 {
148 params.set<MooseFunctorName>("v") = _passive_scalar_coupled_sources[scalar_i][i];
150 params.set<Real>("coef") = _passive_scalar_coupled_sources_coef[scalar_i][i];
152 params.set<std::vector<SubdomainName>>("block") =
154 getProblem().addFVKernel(kernel_type,
155 prefix() + "ins_" + _passive_scalar_names[scalar_i] +
156 "_coupled_source_" + std::to_string(i),
157 params);
158 }
159 }
160}
161
162void
164{
165 const auto & inlet_boundaries = _flow_equations_physics->getInletBoundaries();
166 if (inlet_boundaries.empty())
167 return;
168
169 // Boundary checks
170 // TODO: once we have vectors of MooseEnum, we could use the same templated check for types and
171 // functors
172 if (inlet_boundaries.size() * _passive_scalar_names.size() != _passive_scalar_inlet_types.size())
174 "passive_scalar_inlet_types",
175 "The number of scalar inlet types (" + std::to_string(_passive_scalar_inlet_types.size()) +
176 ") is not equal to the number of inlet boundaries (" +
177 std::to_string(inlet_boundaries.size()) + ") times the number of passive scalars (" +
178 std::to_string(_passive_scalar_names.size()) + ")");
180 paramError("passive_scalar_inlet_functors",
181 "The number of groups of inlet functors (" +
182 std::to_string(_passive_scalar_inlet_functors.size()) +
183 ") is not equal to the number of passive scalars (" +
184 std::to_string(_passive_scalar_names.size()) + ")");
185
186 for (const auto name_i : index_range(_passive_scalar_names))
187 {
188 if (inlet_boundaries.size() != _passive_scalar_inlet_functors[name_i].size())
189 paramError("passive_scalar_inlet_functors",
190 "The number of inlet boundary functors for scalar '" +
191 _passive_scalar_names[name_i] +
192 "' does not match the number of inlet boundaries (" +
193 std::to_string(_passive_scalar_inlet_functors[name_i].size()) + ")");
194
195 unsigned int flux_bc_counter = 0;
196 unsigned int num_inlets = inlet_boundaries.size();
197 for (unsigned int bc_ind = 0; bc_ind < num_inlets; ++bc_ind)
198 {
199 if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "fixed-value")
200 {
201 const std::string bc_type = "FVADFunctorDirichletBC";
202 InputParameters params = getFactory().getValidParams(bc_type);
203 params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
204 params.set<MooseFunctorName>("functor") = _passive_scalar_inlet_functors[name_i][bc_ind];
205 params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
206
208 bc_type, _passive_scalar_names[name_i] + "_" + inlet_boundaries[bc_ind], params);
209 }
210 else if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-mass" ||
211 _passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-velocity")
212 {
213 const auto flux_inlet_directions = _flow_equations_physics->getFluxInletDirections();
214 const auto flux_inlet_pps = _flow_equations_physics->getFluxInletPPs();
215
216 const std::string bc_type = "WCNSFVScalarFluxBC";
217 InputParameters params = getFactory().getValidParams(bc_type);
218 params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
219 params.set<MooseFunctorName>("passive_scalar") = _passive_scalar_names[name_i];
220 if (flux_inlet_directions.size())
221 params.set<Point>("direction") = flux_inlet_directions[flux_bc_counter];
222 if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-mass")
223 {
224 params.set<PostprocessorName>("mdot_pp") = flux_inlet_pps[flux_bc_counter];
225 params.set<PostprocessorName>("area_pp") = "area_pp_" + inlet_boundaries[bc_ind];
226 }
227 else
228 params.set<PostprocessorName>("velocity_pp") = flux_inlet_pps[flux_bc_counter];
229
230 params.set<MooseFunctorName>(NS::density) = _density_name;
231 params.set<PostprocessorName>("scalar_value_pp") =
232 _passive_scalar_inlet_functors[name_i][bc_ind];
233 params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
234
235 params.set<MooseFunctorName>(NS::velocity_x) = _velocity_names[0];
236 if (dimension() > 1)
237 params.set<MooseFunctorName>(NS::velocity_y) = _velocity_names[1];
238 if (dimension() > 2)
239 params.set<MooseFunctorName>(NS::velocity_z) = _velocity_names[2];
240
241 getProblem().addFVBC(bc_type,
242 prefix() + _passive_scalar_names[name_i] + "_" +
243 inlet_boundaries[bc_ind],
244 params);
245 flux_bc_counter += 1;
246 }
247 }
248 }
249}
250
251void
253{
254 // Advection outlet is naturally handled by the advection flux kernel
255 return;
256}
registerNavierStokesPhysicsBaseTasks("NavierStokesApp", WCNSFVScalarTransportPhysics)
registerWCNSFVScalarTransportBaseTasks("NavierStokesApp", WCNSFVScalarTransportPhysics)
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:378
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
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
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< 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 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