https://mooseframework.inl.gov
WCNSFVScalarTransportPhysicsBase.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 "WCNSFVFlowPhysics.h"
13 #include "NSFVBase.h"
14 #include "NS.h"
15 
18 {
21  params.addClassDescription(
22  "Define the Navier Stokes weakly-compressible scalar field transport equation(s)");
23 
25 
26  // TODO Remove the parameter once NavierStokesFV syntax has been removed
27  params.addParam<bool>(
28  "add_scalar_equation",
29  "Whether to add the scalar transport equation. This parameter is not necessary if "
30  "using the Physics syntax");
31 
32  // These parameters are not shared because the NSFVPhysics use functors
33  params.addParam<std::vector<std::vector<MooseFunctorName>>>(
34  "passive_scalar_inlet_function",
35  std::vector<std::vector<MooseFunctorName>>(),
36  "Functors for inlet boundaries in the passive scalar equations.");
37 
38  // New functor boundary conditions
39  params.deprecateParam(
40  "passive_scalar_inlet_function", "passive_scalar_inlet_functors", "01/01/2025");
41 
42  // No need for the duplication
43  params.addParam<std::vector<MooseFunctorName>>("passive_scalar_source", "Passive scalar sources");
44 
45  // Spatial finite volume discretization scheme
47  "passive_scalar_advection_interpolation");
48  params.transferParam<bool>(NSFVBase::validParams(), "passive_scalar_two_term_bc_expansion");
49 
50  // Nonlinear equation solver scaling
51  params.addRangeCheckedParam<std::vector<Real>>(
52  "passive_scalar_scaling",
53  "passive_scalar_scaling > 0.0",
54  "The scaling factor for the passive scalar field variables.");
55 
56  // Parameter groups
57  params.addParamNamesToGroup("passive_scalar_names initial_scalar_variables", "Variable");
58  params.addParamNamesToGroup("passive_scalar_advection_interpolation passive_scalar_scaling "
59  "passive_scalar_two_term_bc_expansion",
60  "Numerical scheme");
61  params.addParamNamesToGroup("passive_scalar_inlet_types passive_scalar_inlet_functors",
62  "Inlet boundary");
63 
64  return params;
65 }
66 
68  const InputParameters & parameters)
69  : NavierStokesPhysicsBase(parameters),
71  _passive_scalar_names(getParam<std::vector<NonlinearVariableName>>("passive_scalar_names")),
72  _has_scalar_equation(isParamValid("add_scalar_equation") ? getParam<bool>("add_scalar_equation")
73  : !usingNavierStokesFVSyntax()),
74  _passive_scalar_inlet_types(getParam<MultiMooseEnum>("passive_scalar_inlet_types")),
75  _passive_scalar_inlet_functors(
76  getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_inlet_functors")),
77  _passive_scalar_sources(getParam<std::vector<MooseFunctorName>>("passive_scalar_source")),
78  _passive_scalar_coupled_sources(
79  getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_coupled_source")),
80  _passive_scalar_sources_coef(
81  getParam<std::vector<std::vector<Real>>>("passive_scalar_coupled_source_coeff"))
82 {
84  for (const auto & scalar_name : _passive_scalar_names)
85  saveSolverVariableName(scalar_name);
86 
87  // For compatibility with Modules/NavierStokesFV syntax
89  return;
90 
91  // These parameters must be passed for every passive scalar at a time
92  checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
93  "passive_scalar_names", "passive_scalar_diffusivity", true);
94  checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
95  "passive_scalar_names", "passive_scalar_coupled_source", true);
96  checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
97  "passive_scalar_names", "passive_scalar_source", true);
98  checkVectorParamsSameLengthIfSet<NonlinearVariableName, Real>(
99  "passive_scalar_names", "passive_scalar_scaling", true);
100  checkVectorParamsSameLengthIfSet<NonlinearVariableName, FunctionName>(
101  "passive_scalar_names", "initial_scalar_variables", true);
102  checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
103  "passive_scalar_names", "passive_scalar_inlet_functors", true);
105  checkTwoDVectorParamMultiMooseEnumSameLength<MooseFunctorName>(
106  "passive_scalar_inlet_functors", "passive_scalar_inlet_types", false);
107 
108  if (_passive_scalar_sources_coef.size())
109  checkTwoDVectorParamsSameLength<MooseFunctorName, Real>("passive_scalar_coupled_source",
110  "passive_scalar_coupled_source_coeff");
111 }
112 
113 void
115 {
116  // For compatibility with Modules/NavierStokesFV syntax
118  return;
119 
120  if (isTransient())
122 
127 }
128 
129 void
131 {
132  // For compatibility with Modules/NavierStokesFV syntax
134  return;
135 
137  // There is typically no wall flux of passive scalars, similarly we rarely know
138  // their concentrations at the outlet at the beginning of the simulation
139  // TODO: we will know the outlet values in case of flow reversal. Implement scalar outlet
140  addScalarWallBC();
142 }
143 
144 void
146 {
147  // For compatibility with Modules/NavierStokesFV syntax
149  return;
150  if (!_define_variables && parameters().isParamSetByUser("initial_scalar_variables"))
151  paramError("initial_scalar_variables",
152  "Scalar variables are defined externally of NavierStokesFV, so should their inital "
153  "conditions");
154  // do not set initial conditions if we load from file
155  if (getParam<bool>("initialize_variables_from_mesh_file"))
156  return;
157  // do not set initial conditions if we are not defining variables
158  if (!_define_variables)
159  return;
160 
161  InputParameters params = getFactory().getValidParams("FunctionIC");
162  assignBlocks(params, _blocks);
163 
164  // There are no default initial conditions for passive scalar variables, we however
165  // must obey the user-defined initial conditions, even if we are restarting
166  if (parameters().isParamSetByUser("initial_scalar_variables"))
167  {
168  for (unsigned int name_i = 0; name_i < _passive_scalar_names.size(); ++name_i)
169  {
170  params.set<VariableName>("variable") = _passive_scalar_names[name_i];
171  params.set<FunctionName>("function") =
172  getParam<std::vector<FunctionName>>("initial_scalar_variables")[name_i];
173 
174  getProblem().addInitialCondition("FunctionIC", _passive_scalar_names[name_i] + "_ic", params);
175  }
176  }
177 }
178 
179 unsigned short
181 {
182  unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
183  necessary_layers =
185  if (getParam<MooseEnum>("passive_scalar_advection_interpolation") == "skewness-corrected")
186  necessary_layers = std::max(necessary_layers, (unsigned short)3);
187 
188  return necessary_layers;
189 }
static InputParameters validParams()
Definition: NSFVBase.C:368
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of algebraic ghosting layers needed.
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
Factory & getFactory()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual void addScalarAdvectionKernels()=0
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
std::vector< NonlinearVariableName > _passive_scalar_names
Names of the passive scalar variables.
std::vector< SubdomainName > _blocks
static InputParameters commonScalarFieldAdvectionParams()
Definition: NSFVBase.C:278
virtual void addInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
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...
virtual FEProblemBase & getProblem()
virtual unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of ghosting layers needed.
static InputParameters validParams()
std::vector< std::vector< Real > > _passive_scalar_sources_coef
Coefficients multiplying for the passive scalar sources. Inner indexing is scalar variable index...
void deprecateParam(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
const T & getParam(const std::string &name) const
std::vector< std::vector< MooseFunctorName > > _passive_scalar_coupled_sources
Functors for the passive scalar (coupled) sources. Inner indexing is scalar variable index...
void paramError(const std::string &param, Args... args) const
Helper class to interact with a flow and turbulence physics for a Physics that solves an advection pr...
WCNSFVScalarTransportPhysicsBase(const InputParameters &parameters)
void transferParam(const InputParameters &source_param, const std::string &name, const std::string &new_name="", const std::string &new_description="")
bool _define_variables
Whether to define variables if they do not exist.
bool isParamSetByUser(const std::string &nm) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< MooseFunctorName > _passive_scalar_sources
Functors for the passive scalar sources. Indexing is scalar variable index.
void addClassDescription(const std::string &doc_string)
virtual void addScalarSourceKernels()=0
Equivalent of NSFVAction addScalarCoupledSourceKernels.
const InputParameters & parameters() const
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
Base class to hold common parameters and utilities between all the weakly compressible Navier Stokes-...
virtual void addScalarDiffusionKernels()=0
const bool _has_scalar_equation
A boolean to help compatibility with the old Modules/NavierStokesFV syntax or to deliberately skip ad...
virtual void addScalarTimeKernels()=0
Functions adding kernels for the incompressible / weakly-compressible scalar transport equation...
virtual void addScalarInletBC()=0
Functions adding boundary conditions for the scalar conservation equations.
void saveSolverVariableName(const VariableName &var_name)
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
bool isTransient() const
virtual void addScalarOutletBC()=0
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)