https://mooseframework.inl.gov
Loading...
Searching...
No Matches
INSADMaterial.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
10#include "INSADMaterial.h"
11#include "Function.h"
12#include "Assembly.h"
13#include "INSADObjectTracker.h"
14#include "FEProblemBase.h"
15#include "NonlinearSystemBase.h"
16#include "NS.h"
17#include "NavierStokesMethods.h"
18
20
23{
25 params.addClassDescription("This is the material class used to compute some of the strong "
26 "residuals for the INS equations.");
27 params.addRequiredCoupledVar("velocity", "The velocity");
28 params.addRequiredCoupledVar(NS::pressure, "The pressure");
29 params.addParam<MaterialPropertyName>("mu_name", "mu", "The name of the dynamic viscosity");
30 params.addParam<MaterialPropertyName>("rho_name", "rho", "The name of the density");
31 return params;
32}
33
35 : Material(parameters),
36 _velocity(adCoupledVectorValue("velocity")),
37 _grad_velocity(adCoupledVectorGradient("velocity")),
38 _grad_p(adCoupledGradient(NS::pressure)),
39 _mu(getADMaterialProperty<Real>("mu_name")),
40 _rho(getADMaterialProperty<Real>("rho_name")),
41 _velocity_dot(nullptr),
42 _mass_strong_residual(declareADProperty<Real>("mass_strong_residual")),
43 _advective_strong_residual(declareADProperty<RealVectorValue>("advective_strong_residual")),
44 // We have to declare the below strong residuals for integrity check purposes even though we may
45 // not compute them. This may incur some unnecessary cost for a non-sparse derivative container
46 // since when the properties are resized the entire non-sparse derivative containers will be
47 // initialized to zero
48 _td_strong_residual(declareADProperty<RealVectorValue>("td_strong_residual")),
49 _gravity_strong_residual(declareADProperty<RealVectorValue>("gravity_strong_residual")),
50 _boussinesq_strong_residual(declareADProperty<RealVectorValue>("boussinesq_strong_residual")),
51 _coupled_force_strong_residual(
52 declareADProperty<RealVectorValue>("coupled_force_strong_residual")),
53 _mesh_velocity(declareADProperty<RealVectorValue>("mesh_velocity")),
54 _relative_velocity(declareADProperty<RealVectorValue>("relative_velocity")),
55 _advected_mesh_strong_residual(
56 declareADProperty<RealVectorValue>("advected_mesh_strong_residual")),
57 // _mms_function_strong_residual(declareProperty<RealVectorValue>("mms_function_strong_residual")),
58 _use_displaced_mesh(getParam<bool>("use_displaced_mesh")),
59 _ad_q_point(_bnd ? _assembly.adQPointsFace() : _assembly.adQPoints()),
60 _rz_radial_coord(_mesh.getAxisymmetricRadialCoord()),
61 _rz_axial_coord(_rz_radial_coord == 0 ? 1 : 0)
62{
63 if (!_fe_problem.hasUserObject("ins_ad_object_tracker"))
64 {
67
68 _fe_problem.addUserObject("INSADObjectTracker", "ins_ad_object_tracker", tracker_params);
69 }
70
71 // Bypass the UserObjectInterface method because it requires a UserObjectName param which we
72 // don't need
74 const_cast<INSADObjectTracker *>(_object_tracker)->addBlockIDs(this->blockIDs());
75}
76
77void
79{
81
82 for (const auto sub_id : this->blockIDs())
83 if ((_object_tracker->get<bool>("has_boussinesq", sub_id)))
84 {
85 _boussinesq_alphas[sub_id] = &getPossiblyConstantGenericMaterialPropertyByName<Real, true>(
86 _object_tracker->get<MaterialPropertyName>("alpha", sub_id), _material_data, 0);
87 _ref_temps[sub_id] = &getPossiblyConstantGenericMaterialPropertyByName<Real, false>(
88 _object_tracker->get<MaterialPropertyName>("ref_temp", sub_id), _material_data, 0);
89 }
90}
91
92void
94{
95 if ((_has_transient = _object_tracker->get<bool>("has_transient", _current_subdomain_id)))
96 _velocity_dot = &adCoupledVectorDot("velocity");
97 else
98 _velocity_dot = nullptr;
99
100 if (auto alpha_it = _boussinesq_alphas.find(_current_subdomain_id);
101 alpha_it != _boussinesq_alphas.end())
102 {
103 _has_boussinesq = true;
104 _boussinesq_alpha = alpha_it->second;
105 auto & temp_var = _subproblem.getStandardVariable(
106 _tid, _object_tracker->get<std::string>("temperature", _current_subdomain_id));
108 _temperature = &temp_var.adSln();
109 _ref_temp = libmesh_map_find(_ref_temps, _current_subdomain_id);
110 }
111 else
112 {
113 _has_boussinesq = false;
114 _boussinesq_alpha = nullptr;
115 _temperature = nullptr;
116 _ref_temp = nullptr;
117 }
118
119 _has_gravity = _object_tracker->get<bool>("has_gravity", _current_subdomain_id);
121 _gravity_vector = _object_tracker->get<RealVectorValue>("gravity", _current_subdomain_id);
122 else
123 _gravity_vector = 0;
124
125 // Setup data for Arbitrary Lagrangian Eulerian (ALE) simulations in which the simulation domain
126 // is displacing. We will need to subtract the mesh velocity from the velocity solution in order
127 // to get the correct material velocity for the momentum convection term.
128 if ((_has_advected_mesh = _object_tracker->get<bool>("has_advected_mesh", _current_subdomain_id)))
129 {
130 auto & disp_x = _subproblem.getStandardVariable(
131 _tid, _object_tracker->get<VariableName>("disp_x", _current_subdomain_id));
133 _disp_x_dot = &disp_x.adUDot();
134 _disp_x_sys_num = disp_x.sys().number();
135 _disp_x_num = (disp_x.kind() == Moose::VarKindType::VAR_SOLVER) &&
137 ? disp_x.number()
140 {
141 auto & disp_y = _subproblem.getStandardVariable(
142 _tid, _object_tracker->get<VariableName>("disp_y", _current_subdomain_id));
144 _disp_y_dot = &disp_y.adUDot();
145 _disp_y_sys_num = disp_y.sys().number();
147 disp_y.kind() == (Moose::VarKindType::VAR_SOLVER &&
149 ? disp_y.number()
151 }
152 else
153 {
154 _disp_y_dot = nullptr;
157 }
159 {
160 auto & disp_z = _subproblem.getStandardVariable(
161 _tid, _object_tracker->get<VariableName>("disp_z", _current_subdomain_id));
163 _disp_z_dot = &disp_z.adUDot();
164 _disp_z_sys_num = disp_z.sys().number();
166 disp_z.kind() == (Moose::VarKindType::VAR_SOLVER &&
168 ? disp_z.number()
170 }
171 else
172 {
173 _disp_z_dot = nullptr;
176 }
177 }
178 else
179 _disp_x_dot = _disp_y_dot = _disp_z_dot = nullptr;
180
181 _viscous_form = static_cast<NS::ViscousForm>(
183
184 if ((_has_coupled_force = _object_tracker->get<bool>("has_coupled_force", _current_subdomain_id)))
185 {
186 _coupled_force_var.clear();
189 {
190 const auto & var_names = _object_tracker->get<std::vector<VariableName>>(
191 "coupled_force_var", _current_subdomain_id);
192 for (const auto & var_name : var_names)
194 }
195
196 if (_object_tracker->isTrackerParamValid("coupled_force_vector_function",
198 {
199 const auto & func_names = _object_tracker->get<std::vector<FunctionName>>(
200 "coupled_force_vector_function", _current_subdomain_id);
201 for (const auto & func_name : func_names)
203 }
204 }
205}
206
207void
209{
212
214 if (_has_transient)
215 _td_strong_residual[_qp] = _rho[_qp] * (*_velocity_dot)[_qp];
216 if (_has_gravity)
218 if (_has_boussinesq)
219 _boussinesq_strong_residual[_qp] = (*_boussinesq_alpha)[_qp] * _gravity_vector * _rho[_qp] *
220 ((*_temperature)[_qp] - (*_ref_temp)[_qp]);
222
224 {
226 if (_disp_y_dot)
228 if (_disp_z_dot)
232 }
233
235 {
237 mooseAssert(!(_coupled_force_var.empty() && _coupled_force_vector_function.empty()),
238 "Either the coupled force var or the coupled force vector function must be "
239 "non-empty in 'INSADMaterial'");
240 for (const auto * var : _coupled_force_var)
241 {
242 mooseAssert(var, "null coupled variable in INSADMaterial");
244 }
245 for (const auto * fn : _coupled_force_vector_function)
246 {
247 mooseAssert(fn, "null coupled function in INSADMaterial");
248 _coupled_force_strong_residual[_qp] -= fn->vectorValue(_t, _q_point[_qp]);
249 }
250 }
251
252 // // Future Addition
253 // _mms_function_strong_residual[_qp] = -RealVectorValue(_x_vel_fn.value(_t, _q_point[_qp]),
254 // _y_vel_fn.value(_t, _q_point[_qp]),
255 // _z_vel_fn.value(_t, _q_point[_qp]));
256}
registerMooseObject("NavierStokesApp", INSADMaterial)
void ErrorVector unsigned int
virtual const std::set< SubdomainID > & blockIDs() const
const ADVectorVariableValue & adCoupledVectorDot(const std::string &var_name, unsigned int comp=0) const
T & getUserObject(const std::string &name, unsigned int tid=0) const
virtual std::vector< std::shared_ptr< UserObject > > addUserObject(const std::string &user_object_name, const std::string &name, InputParameters &parameters)
bool hasUserObject(const std::string &name) const
NonlinearSystemBase & currentNonlinearSystem()
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
std::unordered_map< SubdomainID, const MaterialProperty< Real > * > _ref_temps
The reference temperature.
ADMaterialProperty< RealVectorValue > & _advective_strong_residual
Strong residual corresponding to the momentum advective term.
const ADVariableValue * _disp_z_dot
The time derivative with respect to z-displacement.
const INSADObjectTracker * _object_tracker
A user object that consumes information from INSAD residual objects and feeds it into this material.
RealVectorValue _gravity_vector
The gravity vector.
INSADMaterial(const InputParameters &parameters)
std::vector< const ADVectorVariableValue * > _coupled_force_var
optionally copuled vector var(s)
const ADVariableValue * _disp_y_dot
The time derivative with respect to y-displacement.
ADMaterialProperty< RealVectorValue > & _td_strong_residual
Strong residual corresponding to the momentum transient term.
std::unordered_map< SubdomainID, const ADMaterialProperty< Real > * > _boussinesq_alphas
The Boussinesq coefficient.
unsigned int _disp_x_sys_num
unsigned int _disp_y_num
bool _has_boussinesq
Whether natural convection forces via the Boussinesq approximation are added to the momentum equation...
virtual void resolveOptionalProperties() override
const ADVariableValue * _disp_x_dot
The time derivative with respect to x-displacement.
virtual void computeQpProperties() override
bool _has_transient
Whether the momentum equations are transient.
ADMaterialProperty< RealVectorValue > & _mesh_velocity
The mesh velocity.
unsigned int _disp_x_num
ADMaterialProperty< RealVectorValue > & _coupled_force_strong_residual
Strong residual corresponding to coupled force term.
ADMaterialProperty< RealVectorValue > & _boussinesq_strong_residual
Strong residual corresponding to the momentum boussinesq term.
static InputParameters validParams()
ADMaterialProperty< RealVectorValue > & _gravity_strong_residual
Strong residual corresponding to the momentum gravity term.
virtual void subdomainSetup() override
unsigned int _disp_y_sys_num
ADMaterialProperty< RealVectorValue > & _relative_velocity
The relative velocity, e.g. velocity - mesh_velocity.
unsigned int _disp_z_sys_num
ADMaterialProperty< Real > & _mass_strong_residual
The strong residual of the mass continuity equation.
bool _has_gravity
Whether there is a gravity force in the momentum equation.
bool _has_advected_mesh
Whether we have mesh convection.
ADMaterialProperty< RealVectorValue > & _advected_mesh_strong_residual
Strong residual corresponding to advected mesh term.
const MaterialProperty< Real > * _ref_temp
std::vector< const Function * > _coupled_force_vector_function
optional vector function(s)
const MooseArray< ADPoint > & _ad_q_point
The quadrature points with potential partial derivatives with respect to displacement degrees of free...
const ADVectorVariableValue * _velocity_dot
Time derivative of the velocity, e.g. the acceleration.
const unsigned int _rz_radial_coord
The radial coordinate index for RZ coordinate systems.
const ADVectorVariableGradient & _grad_velocity
gradient of velocity
NS::ViscousForm _viscous_form
The viscous form of the equations. This is either "laplace" or "traction".
const ADVariableValue * _temperature
The temperature.
bool _has_coupled_force
Whether there is a force from a coupled vector variable or vector function.
const ADMaterialProperty< Real > & _rho
density
unsigned int _disp_z_num
const ADMaterialProperty< Real > * _boussinesq_alpha
const ADVectorVariableValue & _velocity
velocity
Object for tracking what kernels have been added to an INSAD simulation.
bool isTrackerParamValid(const std::string &name, SubdomainID sub_id) const
static InputParameters validParams()
const T & get(const std::string &name, SubdomainID sub_id) const
Get the internal parameter name.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addPrivateParam(const std::string &name, const T &value)
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)
const Moose::CoordinateSystemType & _coord_sys
THREAD_ID _tid
unsigned int _qp
SubProblem & _subproblem
FEProblemBase & _fe_problem
MaterialData & _material_data
static InputParameters validParams()
virtual void resolveOptionalProperties() override
const SubdomainID & _current_subdomain_id
const MooseArray< Point > & _q_point
static const std::string app_param
MooseApp & _app
void addMooseVariableDependency(MooseVariableFieldBase *var)
const ADTemplateVariableValue< OutputType > & adSln() const override
virtual MooseVariable & getStandardVariable(const THREAD_ID tid, const std::string &var_name)=0
virtual VectorMooseVariable & getVectorVariable(const THREAD_ID tid, const std::string &var_name)=0
unsigned int number() const
Real & _t
ViscousForm
Definition NSEnums.h:21
T divergence(const TensorValue< T > &gradient, const VectorType &value, const PointType &point, const Moose::CoordinateSystemType &coord_sys, const unsigned int rz_radial_coord)
Compute the divergence of a vector given its matrix of derivatives.
static const std::string pressure
Definition NS.h:57
const unsigned int invalid_uint