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_functors",
35  std::vector<std::vector<MooseFunctorName>>(),
36  "Functors for inlet boundaries in the passive scalar equations.");
37 
38  // No need for the duplication
39  params.addParam<std::vector<MooseFunctorName>>("passive_scalar_source", "Passive scalar sources");
40 
41  // Spatial finite volume discretization scheme
43  "passive_scalar_advection_interpolation");
44  params.transferParam<bool>(NSFVBase::validParams(), "passive_scalar_two_term_bc_expansion");
45 
46  // Nonlinear equation solver scaling
47  params.addRangeCheckedParam<std::vector<Real>>(
48  "passive_scalar_scaling",
49  "passive_scalar_scaling > 0.0",
50  "The scaling factor for the passive scalar field variables.");
51 
52  // Parameter groups
53  params.addParamNamesToGroup("passive_scalar_names initial_scalar_variables", "Variable");
54  params.addParamNamesToGroup("passive_scalar_advection_interpolation passive_scalar_scaling "
55  "passive_scalar_two_term_bc_expansion",
56  "Numerical scheme");
57  params.addParamNamesToGroup("passive_scalar_inlet_types passive_scalar_inlet_functors",
58  "Inlet boundary");
59 
60  return params;
61 }
62 
64  const InputParameters & parameters)
65  : NavierStokesPhysicsBase(parameters),
67  _passive_scalar_names(getParam<std::vector<NonlinearVariableName>>("passive_scalar_names")),
68  _has_scalar_equation(isParamValid("add_scalar_equation") ? getParam<bool>("add_scalar_equation")
69  : !usingNavierStokesFVSyntax()),
70  _passive_scalar_inlet_types(getParam<MultiMooseEnum>("passive_scalar_inlet_types")),
71  _passive_scalar_inlet_functors(
72  getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_inlet_functors")),
73  _passive_scalar_sources(getParam<std::vector<MooseFunctorName>>("passive_scalar_source")),
74  _passive_scalar_coupled_sources(
75  getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_coupled_source")),
76  _passive_scalar_sources_coef(
77  getParam<std::vector<std::vector<Real>>>("passive_scalar_coupled_source_coeff"))
78 {
80  for (const auto & scalar_name : _passive_scalar_names)
81  saveSolverVariableName(scalar_name);
82 
83  // For compatibility with Modules/NavierStokesFV syntax
85  return;
86 
87  // These parameters must be passed for every passive scalar at a time
88  checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
89  "passive_scalar_names", "passive_scalar_diffusivity", true);
90  checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
91  "passive_scalar_names", "passive_scalar_coupled_source", true);
92  checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
93  "passive_scalar_names", "passive_scalar_source", true);
94  checkVectorParamsSameLengthIfSet<NonlinearVariableName, Real>(
95  "passive_scalar_names", "passive_scalar_scaling", true);
96  checkVectorParamsSameLengthIfSet<NonlinearVariableName, FunctionName>(
97  "passive_scalar_names", "initial_scalar_variables", true);
98  checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
99  "passive_scalar_names", "passive_scalar_inlet_functors", true);
101  checkTwoDVectorParamMultiMooseEnumSameLength<MooseFunctorName>(
102  "passive_scalar_inlet_functors", "passive_scalar_inlet_types", false);
103 
104  if (_passive_scalar_sources_coef.size())
105  checkTwoDVectorParamsSameLength<MooseFunctorName, Real>("passive_scalar_coupled_source",
106  "passive_scalar_coupled_source_coeff");
107 }
108 
109 void
111 {
112  // For compatibility with Modules/NavierStokesFV syntax
114  return;
115 
116  if (isTransient())
118 
123 }
124 
125 void
127 {
128  // For compatibility with Modules/NavierStokesFV syntax
130  return;
131 
133  // There is typically no wall flux of passive scalars, similarly we rarely know
134  // their concentrations at the outlet at the beginning of the simulation
135  // TODO: we will know the outlet values in case of flow reversal. Implement scalar outlet
136  addScalarWallBC();
138 }
139 
140 void
142 {
143  // For compatibility with Modules/NavierStokesFV syntax
145  return;
146  if (!_define_variables && parameters().isParamSetByUser("initial_scalar_variables"))
147  paramError("initial_scalar_variables",
148  "Scalar variables are defined externally of NavierStokesFV, so should their inital "
149  "conditions");
150  // do not set initial conditions if we load from file
151  if (getParam<bool>("initialize_variables_from_mesh_file"))
152  return;
153  // do not set initial conditions if we are not defining variables
154  if (!_define_variables)
155  return;
156 
157  InputParameters params = getFactory().getValidParams("FunctionIC");
158  assignBlocks(params, _blocks);
159 
160  // There are no default initial conditions for passive scalar variables, we however
161  // must obey the user-defined initial conditions, even if we are restarting
162  if (parameters().isParamSetByUser("initial_scalar_variables"))
163  {
164  for (unsigned int name_i = 0; name_i < _passive_scalar_names.size(); ++name_i)
165  {
166  params.set<VariableName>("variable") = _passive_scalar_names[name_i];
167  params.set<FunctionName>("function") =
168  getParam<std::vector<FunctionName>>("initial_scalar_variables")[name_i];
169 
170  getProblem().addInitialCondition("FunctionIC", _passive_scalar_names[name_i] + "_ic", params);
171  }
172  }
173 }
174 
175 unsigned short
177 {
178  unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
179  necessary_layers =
181  if (getParam<MooseEnum>("passive_scalar_advection_interpolation") == "skewness-corrected")
182  necessary_layers = std::max(necessary_layers, (unsigned short)3);
183 
184  return necessary_layers;
185 }
static InputParameters validParams()
Definition: NSFVBase.C:371
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 paramError(const std::string &param, Args... args) const
const T & getParam(const std::string &name) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual void addScalarAdvectionKernels()=0
const InputParameters & parameters() const
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:284
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...
std::vector< std::vector< MooseFunctorName > > _passive_scalar_coupled_sources
Functors for the passive scalar (coupled) sources. Inner indexing is scalar variable index...
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.
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.
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.
bool isParamSetByUser(const std::string &name) const
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)