https://mooseframework.inl.gov
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 
19 registerMooseObject("NavierStokesApp", INSADMaterial);
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  {
66  tracker_params.addPrivateParam("_moose_app", &_app);
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
73  _object_tracker = &_fe_problem.getUserObject<INSADObjectTracker>("ins_ad_object_tracker");
74  const_cast<INSADObjectTracker *>(_object_tracker)->addBlockIDs(this->blockIDs());
75 }
76 
77 void
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 
92 void
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));
107  addMooseVariableDependency(&temp_var);
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);
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();
146  _disp_y_num =
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();
165  _disp_z_num =
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();
188  if (_object_tracker->isTrackerParamValid("coupled_force_var", _current_subdomain_id))
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)
193  _coupled_force_var.push_back(&_subproblem.getVectorVariable(_tid, var_name).adSln());
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 
207 void
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 
223  if (_has_advected_mesh)
224  {
225  _mesh_velocity[_qp](0) = (*_disp_x_dot)[_qp];
226  if (_disp_y_dot)
227  _mesh_velocity[_qp](1) = (*_disp_y_dot)[_qp];
228  if (_disp_z_dot)
229  _mesh_velocity[_qp](2) = (*_disp_z_dot)[_qp];
232  }
233 
234  if (_has_coupled_force)
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 }
const MooseArray< Point > & _q_point
const ADVectorVariableGradient & _grad_velocity
gradient of velocity
Definition: INSADMaterial.h:34
ADMaterialProperty< RealVectorValue > & _gravity_strong_residual
Strong residual corresponding to the momentum gravity term.
Definition: INSADMaterial.h:58
const ADMaterialProperty< Real > * _boussinesq_alpha
FEProblemBase & _fe_problem
RealVectorValue _gravity_vector
The gravity vector.
virtual VectorMooseVariable & getVectorVariable(const THREAD_ID tid, const std::string &var_name)=0
T & getUserObject(const std::string &name, unsigned int tid=0) const
const unsigned int invalid_uint
ADMaterialProperty< RealVectorValue > & _advected_mesh_strong_residual
Strong residual corresponding to advected mesh term.
Definition: INSADMaterial.h:73
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
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.
void addPrivateParam(const std::string &name, const T &value)
ADMaterialProperty< RealVectorValue > & _coupled_force_strong_residual
Strong residual corresponding to coupled force term.
Definition: INSADMaterial.h:64
NS::ViscousForm _viscous_form
The viscous form of the equations. This is either "laplace" or "traction".
static InputParameters validParams()
std::vector< const Function * > _coupled_force_vector_function
optional vector function(s)
SubProblem & _subproblem
const Moose::CoordinateSystemType & _coord_sys
virtual void resolveOptionalProperties() override
Definition: INSADMaterial.C:78
virtual void subdomainSetup() override
Definition: INSADMaterial.C:93
unsigned int _disp_x_num
const MaterialProperty< Real > * _ref_temp
const INSADObjectTracker * _object_tracker
A user object that consumes information from INSAD residual objects and feeds it into this material...
Definition: INSADMaterial.h:94
ViscousForm
Definition: NSEnums.h:20
virtual const std::set< SubdomainID > & blockIDs() const
bool hasUserObject(const std::string &name) const
unsigned int _disp_z_sys_num
ADMaterialProperty< RealVectorValue > & _td_strong_residual
Strong residual corresponding to the momentum transient term.
Definition: INSADMaterial.h:55
bool _has_gravity
Whether there is a gravity force in the momentum equation.
MaterialData & _material_data
const ADVariableValue * _disp_x_dot
The time derivative with respect to x-displacement.
static InputParameters validParams()
Definition: INSADMaterial.C:22
ADMaterialProperty< RealVectorValue > & _relative_velocity
The relative velocity, e.g. velocity - mesh_velocity.
Definition: INSADMaterial.h:70
const MooseArray< ADPoint > & _ad_q_point
The quadrature points with potential partial derivatives with respect to displacement degrees of free...
Definition: INSADMaterial.h:84
ADMaterialProperty< RealVectorValue > & _advective_strong_residual
Strong residual corresponding to the momentum advective term.
Definition: INSADMaterial.h:52
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
unsigned int _qp
unsigned int _disp_y_sys_num
registerMooseObject("NavierStokesApp", INSADMaterial)
static InputParameters validParams()
const T & get(const std::string &name, SubdomainID sub_id) const
Get the internal parameter name.
const ADVariableValue * _disp_z_dot
The time derivative with respect to z-displacement.
THREAD_ID _tid
NonlinearSystemBase & currentNonlinearSystem()
Real & _t
const ADTemplateVariableValue< OutputType > & adSln() const override
virtual MooseVariable & getStandardVariable(const THREAD_ID tid, const std::string &var_name)=0
bool isTrackerParamValid(const std::string &name, SubdomainID sub_id) const
const ADVariableValue * _disp_y_dot
The time derivative with respect to y-displacement.
unsigned int number() const
std::unordered_map< SubdomainID, const MaterialProperty< Real > * > _ref_temps
The reference temperature.
const ADVectorVariableValue & adCoupledVectorDot(const std::string &var_name, unsigned int comp=0) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
virtual void computeQpProperties() override
const ADVectorVariableValue & _velocity
velocity
Definition: INSADMaterial.h:31
const ADVectorVariableValue * _velocity_dot
Time derivative of the velocity, e.g. the acceleration.
Definition: INSADMaterial.h:46
bool _has_transient
Whether the momentum equations are transient.
Definition: INSADMaterial.h:97
ADMaterialProperty< RealVectorValue > & _boussinesq_strong_residual
Strong residual corresponding to the momentum boussinesq term.
Definition: INSADMaterial.h:61
void addMooseVariableDependency(MooseVariableFieldBase *var)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
MooseApp & _app
const ADVariableValue * _temperature
The temperature.
unsigned int _disp_x_sys_num
virtual std::vector< std::shared_ptr< UserObject > > addUserObject(const std::string &user_object_name, const std::string &name, InputParameters &parameters)
static const std::string pressure
Definition: NS.h:56
std::vector< const ADVectorVariableValue * > _coupled_force_var
optionally copuled vector var(s)
unsigned int _disp_y_num
bool _has_coupled_force
Whether there is a force from a coupled vector variable or vector function.
bool _has_boussinesq
Whether natural convection forces via the Boussinesq approximation are added to the momentum equation...
std::unordered_map< SubdomainID, const ADMaterialProperty< Real > * > _boussinesq_alphas
The Boussinesq coefficient.
void addClassDescription(const std::string &doc_string)
unsigned int _disp_z_num
bool _has_advected_mesh
Whether we have mesh convection.
const SubdomainID & _current_subdomain_id
virtual void resolveOptionalProperties() override
const ADMaterialProperty< Real > & _rho
density
Definition: INSADMaterial.h:43
const unsigned int _rz_radial_coord
The radial coordinate index for RZ coordinate systems.
Definition: INSADMaterial.h:87
INSADMaterial(const InputParameters &parameters)
Definition: INSADMaterial.C:34
Object for tracking what kernels have been added to an INSAD simulation.
void ErrorVector unsigned int
ADMaterialProperty< RealVectorValue > & _mesh_velocity
The mesh velocity.
Definition: INSADMaterial.h:67
ADMaterialProperty< Real > & _mass_strong_residual
The strong residual of the mass continuity equation.
Definition: INSADMaterial.h:49