https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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_coupled_sources_coef(
77 getParam<std::vector<std::vector<Real>>>("passive_scalar_coupled_source_coeff")),
78 _passive_scalar_coupled_sources_blocks(
79 getParam<std::vector<std::vector<std::vector<SubdomainName>>>>(
80 "passive_scalar_coupled_source_blocks"))
81{
83 for (const auto & scalar_name : _passive_scalar_names)
84 saveSolverVariableName(scalar_name);
85
86 // For compatibility with Modules/NavierStokesFV syntax
88 return;
89
90 // These parameters must be passed for every passive scalar at a time
91 checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
92 "passive_scalar_names", "passive_scalar_diffusivity", true);
93 checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
94 "passive_scalar_names", "passive_scalar_coupled_source", true);
95 checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
96 "passive_scalar_names", "passive_scalar_source", true);
97 checkVectorParamsSameLengthIfSet<NonlinearVariableName, Real>(
98 "passive_scalar_names", "passive_scalar_scaling", true);
99 checkVectorParamsSameLengthIfSet<NonlinearVariableName, FunctionName>(
100 "passive_scalar_names", "initial_scalar_variables", true);
101 checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
102 "passive_scalar_names", "passive_scalar_inlet_functors", true);
104 checkTwoDVectorParamMultiMooseEnumSameLength<MooseFunctorName>(
105 "passive_scalar_inlet_functors", "passive_scalar_inlet_types", false);
106
108 checkTwoDVectorParamsSameLength<MooseFunctorName, Real>("passive_scalar_coupled_source",
109 "passive_scalar_coupled_source_coeff");
111 checkTwoDVectorParamsSameLength<MooseFunctorName, std::vector<SubdomainName>>(
112 "passive_scalar_coupled_source", "passive_scalar_coupled_source_blocks");
113
114 addRequiredPhysicsTask("get_turbulence_physics");
115 addRequiredPhysicsTask("add_variables_physics");
116 addRequiredPhysicsTask("add_ics_physics");
117 addRequiredPhysicsTask("add_fv_kernel");
118 addRequiredPhysicsTask("add_fv_bc");
119}
120
121void
123{
124 // Turbulence physics would not be initialized before this task
125 if (_current_task == "get_turbulence_physics")
126 {
129 }
130}
131
132void
134{
135 // For compatibility with Modules/NavierStokesFV syntax
137 return;
138
139 if (isTransient())
141
146}
147
148void
150{
151 // For compatibility with Modules/NavierStokesFV syntax
153 return;
154
156 // There is typically no wall flux of passive scalars, similarly we rarely know
157 // their concentrations at the outlet at the beginning of the simulation
158 // TODO: we will know the outlet values in case of flow reversal. Implement scalar outlet
161}
162
163void
165{
166 // For compatibility with Modules/NavierStokesFV syntax
168 return;
169 if (!_define_variables && parameters().isParamSetByUser("initial_scalar_variables"))
170 paramError("initial_scalar_variables",
171 "Scalar variables are defined externally of NavierStokesFV, so should their inital "
172 "conditions");
173 // do not set initial conditions if we load from file
174 if (getParam<bool>("initialize_variables_from_mesh_file"))
175 return;
176 // do not set initial conditions if we are not defining variables
178 return;
179
180 InputParameters params = getFactory().getValidParams("FunctionIC");
181 assignBlocks(params, _blocks);
182
183 // There are no default initial conditions for passive scalar variables, we however
184 // must obey the user-defined initial conditions, even if we are restarting
185 if (parameters().isParamSetByUser("initial_scalar_variables"))
186 {
187 for (unsigned int name_i = 0; name_i < _passive_scalar_names.size(); ++name_i)
188 {
189 params.set<VariableName>("variable") = _passive_scalar_names[name_i];
190 params.set<FunctionName>("function") =
191 getParam<std::vector<FunctionName>>("initial_scalar_variables")[name_i];
192
193 getProblem().addInitialCondition("FunctionIC", _passive_scalar_names[name_i] + "_ic", params);
194 }
195 }
196}
197
198unsigned short
200{
201 unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
202 necessary_layers =
204 if (getParam<MooseEnum>("passive_scalar_advection_interpolation") == "skewness-corrected")
205 necessary_layers = std::max(necessary_layers, (unsigned short)3);
206
207 return necessary_layers;
208}
const std::string & _current_task
virtual void addInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
void checkTwoDVectorParamsSameLength(const std::string &param1, const std::string &param2) 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 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 addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const InputParameters & parameters() const
void paramError(const std::string &param, Args... args) const
bool isParamSetByUser(const std::string &name) const
const T & getParam(const std::string &name) const
static InputParameters commonScalarFieldAdvectionParams()
Definition NSFVBase.C:284
static InputParameters validParams()
Definition NSFVBase.C:378
Base class to hold common parameters and utilities between all the weakly compressible Navier Stokes-...
static InputParameters validParams()
bool _define_variables
Whether to define variables if they do not exist.
virtual FEProblemBase & getProblem()
Factory & getFactory()
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
void saveSolverVariableName(const VariableName &var_name)
bool isTransient() const
std::vector< SubdomainName > _blocks
void addRequiredPhysicsTask(const std::string &task)
Helper class to interact with a flow and turbulence physics for a Physics that solves an advection pr...
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
const WCNSFVTurbulencePhysicsBase * _turbulence_physics
Turbulence.
const WCNSFVTurbulencePhysicsBase * getCoupledTurbulencePhysics() const
bool _has_turbulence_model
Because of the Modules/navierStokesFV syntax, a turbulence physics often exists without a model we sa...
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of algebraic ghosting layers needed.
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.
virtual unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of ghosting layers needed.
std::vector< std::vector< MooseFunctorName > > _passive_scalar_coupled_sources
Functors for the passive scalar (coupled) sources. Outer indexing is scalar variable index.
virtual void addScalarDiffusionKernels()=0
virtual void addScalarSourceKernels()=0
Equivalent of NSFVAction addScalarCoupledSourceKernels.
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 addScalarInletBC()=0
Functions adding boundary conditions for the scalar conservation equations.
std::vector< NonlinearVariableName > _passive_scalar_names
Names of the passive scalar variables.
virtual void addScalarTimeKernels()=0
Functions adding kernels for the incompressible / weakly-compressible scalar transport equation.
WCNSFVScalarTransportPhysicsBase(const InputParameters &parameters)
virtual void addScalarAdvectionKernels()=0
virtual void addScalarOutletBC()=0
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...
bool hasTurbulenceModel() const
Whether a turbulence model is in use.