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_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
105 checkTwoDVectorParamsSameLength<MooseFunctorName, Real>("passive_scalar_coupled_source",
106 "passive_scalar_coupled_source_coeff");
107
108 addRequiredPhysicsTask("get_turbulence_physics");
109 addRequiredPhysicsTask("add_variables_physics");
110 addRequiredPhysicsTask("add_ics_physics");
111 addRequiredPhysicsTask("add_fv_kernel");
112 addRequiredPhysicsTask("add_fv_bc");
113}
114
115void
117{
118 // Turbulence physics would not be initialized before this task
119 if (_current_task == "get_turbulence_physics")
120 {
123 }
124}
125
126void
128{
129 // For compatibility with Modules/NavierStokesFV syntax
131 return;
132
133 if (isTransient())
135
140}
141
142void
144{
145 // For compatibility with Modules/NavierStokesFV syntax
147 return;
148
150 // There is typically no wall flux of passive scalars, similarly we rarely know
151 // their concentrations at the outlet at the beginning of the simulation
152 // TODO: we will know the outlet values in case of flow reversal. Implement scalar outlet
155}
156
157void
159{
160 // For compatibility with Modules/NavierStokesFV syntax
162 return;
163 if (!_define_variables && parameters().isParamSetByUser("initial_scalar_variables"))
164 paramError("initial_scalar_variables",
165 "Scalar variables are defined externally of NavierStokesFV, so should their inital "
166 "conditions");
167 // do not set initial conditions if we load from file
168 if (getParam<bool>("initialize_variables_from_mesh_file"))
169 return;
170 // do not set initial conditions if we are not defining variables
172 return;
173
174 InputParameters params = getFactory().getValidParams("FunctionIC");
175 assignBlocks(params, _blocks);
176
177 // There are no default initial conditions for passive scalar variables, we however
178 // must obey the user-defined initial conditions, even if we are restarting
179 if (parameters().isParamSetByUser("initial_scalar_variables"))
180 {
181 for (unsigned int name_i = 0; name_i < _passive_scalar_names.size(); ++name_i)
182 {
183 params.set<VariableName>("variable") = _passive_scalar_names[name_i];
184 params.set<FunctionName>("function") =
185 getParam<std::vector<FunctionName>>("initial_scalar_variables")[name_i];
186
187 getProblem().addInitialCondition("FunctionIC", _passive_scalar_names[name_i] + "_ic", params);
188 }
189 }
190}
191
192unsigned short
194{
195 unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
196 necessary_layers =
198 if (getParam<MooseEnum>("passive_scalar_advection_interpolation") == "skewness-corrected")
199 necessary_layers = std::max(necessary_layers, (unsigned short)3);
200
201 return necessary_layers;
202}
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 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:371
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< 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.
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. Inner indexing is scalar variable index.
virtual void addScalarDiffusionKernels()=0
virtual void addScalarSourceKernels()=0
Equivalent of NSFVAction addScalarCoupledSourceKernels.
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.