www.mooseframework.org
INSADMaterial.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
18 registerMooseObject("NavierStokesApp", INSADMaterial);
19 
22 {
24  params.addClassDescription("This is the material class used to compute some of the strong "
25  "residuals for the INS equations.");
26  params.addRequiredCoupledVar("velocity", "The velocity");
27  params.addRequiredCoupledVar(NS::pressure, "The pressure");
28  params.addParam<MaterialPropertyName>("mu_name", "mu", "The name of the dynamic viscosity");
29  params.addParam<MaterialPropertyName>("rho_name", "rho", "The name of the density");
30  return params;
31 }
32 
34  : Material(parameters),
35  _velocity(adCoupledVectorValue("velocity")),
36  _grad_velocity(adCoupledVectorGradient("velocity")),
37  _grad_p(adCoupledGradient(NS::pressure)),
38  _mu(getADMaterialProperty<Real>("mu_name")),
39  _rho(getADMaterialProperty<Real>("rho_name")),
40  _velocity_dot(nullptr),
41  _mass_strong_residual(declareADProperty<Real>("mass_strong_residual")),
42  _advective_strong_residual(declareADProperty<RealVectorValue>("advective_strong_residual")),
43  // We have to declare the below strong residuals for integrity check purposes even though we may
44  // not compute them. This may incur some unnecessary cost for a non-sparse derivative container
45  // since when the properties are resized the entire non-sparse derivative containers will be
46  // initialized to zero
47  _td_strong_residual(declareADProperty<RealVectorValue>("td_strong_residual")),
48  _gravity_strong_residual(declareADProperty<RealVectorValue>("gravity_strong_residual")),
49  _boussinesq_strong_residual(declareADProperty<RealVectorValue>("boussinesq_strong_residual")),
50  _coupled_force_strong_residual(
51  declareADProperty<RealVectorValue>("coupled_force_strong_residual")),
52  _mesh_velocity(declareADProperty<RealVectorValue>("mesh_velocity")),
53  _relative_velocity(declareADProperty<RealVectorValue>("relative_velocity")),
54  _advected_mesh_strong_residual(
55  declareADProperty<RealVectorValue>("advected_mesh_strong_residual")),
56  // _mms_function_strong_residual(declareProperty<RealVectorValue>("mms_function_strong_residual")),
57  _use_displaced_mesh(getParam<bool>("use_displaced_mesh")),
58  _ad_q_point(_bnd ? _assembly.adQPointsFace() : _assembly.adQPoints()),
59  _rz_radial_coord(_mesh.getAxisymmetricRadialCoord()),
60  _rz_axial_coord(_rz_radial_coord == 0 ? 1 : 0)
61 {
62  if (!_fe_problem.hasUserObject("ins_ad_object_tracker"))
63  {
65  tracker_params.addPrivateParam("_moose_app", &_app);
66 
67  _fe_problem.addUserObject("INSADObjectTracker", "ins_ad_object_tracker", tracker_params);
68  }
69 
70  // Bypass the UserObjectInterface method because it requires a UserObjectName param which we
71  // don't need
72  _object_tracker = &_fe_problem.getUserObject<INSADObjectTracker>("ins_ad_object_tracker");
73  const_cast<INSADObjectTracker *>(_object_tracker)->addBlockIDs(this->blockIDs());
74 }
75 
76 void
78 {
80 
81  for (const auto sub_id : this->blockIDs())
82  if ((_object_tracker->get<bool>("has_boussinesq", sub_id)))
83  {
84  _boussinesq_alphas[sub_id] = &getPossiblyConstantGenericMaterialPropertyByName<Real, true>(
85  _object_tracker->get<MaterialPropertyName>("alpha", sub_id), _material_data, 0);
86  _ref_temps[sub_id] = &getPossiblyConstantGenericMaterialPropertyByName<Real, false>(
87  _object_tracker->get<MaterialPropertyName>("ref_temp", sub_id), _material_data, 0);
88  }
89 }
90 
91 void
93 {
94  if ((_has_transient = _object_tracker->get<bool>("has_transient", _current_subdomain_id)))
95  _velocity_dot = &adCoupledVectorDot("velocity");
96  else
97  _velocity_dot = nullptr;
98 
99  if (auto alpha_it = _boussinesq_alphas.find(_current_subdomain_id);
100  alpha_it != _boussinesq_alphas.end())
101  {
102  _has_boussinesq = true;
103  _boussinesq_alpha = alpha_it->second;
104  auto & temp_var = _subproblem.getStandardVariable(
105  _tid, _object_tracker->get<std::string>("temperature", _current_subdomain_id));
106  addMooseVariableDependency(&temp_var);
107  _temperature = &temp_var.adSln();
108  _ref_temp = libmesh_map_find(_ref_temps, _current_subdomain_id);
109  }
110  else
111  {
112  _has_boussinesq = false;
113  _boussinesq_alpha = nullptr;
114  _temperature = nullptr;
115  _ref_temp = nullptr;
116  }
117 
118  _has_gravity = _object_tracker->get<bool>("has_gravity", _current_subdomain_id);
121  else
122  _gravity_vector = 0;
123 
124  // Setup data for Arbitrary Lagrangian Eulerian (ALE) simulations in which the simulation domain
125  // is displacing. We will need to subtract the mesh velocity from the velocity solution in order
126  // to get the correct material velocity for the momentum convection term.
127  if ((_has_advected_mesh = _object_tracker->get<bool>("has_advected_mesh", _current_subdomain_id)))
128  {
129  auto & disp_x = _subproblem.getStandardVariable(
130  _tid, _object_tracker->get<VariableName>("disp_x", _current_subdomain_id));
132  _disp_x_dot = &disp_x.adUDot();
133  _disp_x_sys_num = disp_x.sys().number();
134  _disp_x_num = (disp_x.kind() == Moose::VarKindType::VAR_NONLINEAR) &&
136  ? disp_x.number()
139  {
140  auto & disp_y = _subproblem.getStandardVariable(
141  _tid, _object_tracker->get<VariableName>("disp_y", _current_subdomain_id));
143  _disp_y_dot = &disp_y.adUDot();
144  _disp_y_sys_num = disp_y.sys().number();
145  _disp_y_num =
146  disp_y.kind() == (Moose::VarKindType::VAR_NONLINEAR &&
148  ? disp_y.number()
150  }
151  else
152  {
153  _disp_y_dot = nullptr;
156  }
158  {
159  auto & disp_z = _subproblem.getStandardVariable(
160  _tid, _object_tracker->get<VariableName>("disp_z", _current_subdomain_id));
162  _disp_z_dot = &disp_z.adUDot();
163  _disp_z_sys_num = disp_z.sys().number();
164  _disp_z_num =
165  disp_z.kind() == (Moose::VarKindType::VAR_NONLINEAR &&
167  ? disp_z.number()
169  }
170  else
171  {
172  _disp_z_dot = nullptr;
175  }
176  }
177  else
178  _disp_x_dot = _disp_y_dot = _disp_z_dot = nullptr;
179 
180  _viscous_form = static_cast<NS::ViscousForm>(
182 
183  if ((_has_coupled_force = _object_tracker->get<bool>("has_coupled_force", _current_subdomain_id)))
184  {
185  _coupled_force_var.clear();
187  if (_object_tracker->isTrackerParamValid("coupled_force_var", _current_subdomain_id))
188  {
189  const auto & var_names = _object_tracker->get<std::vector<VariableName>>(
190  "coupled_force_var", _current_subdomain_id);
191  for (const auto & var_name : var_names)
192  _coupled_force_var.push_back(&_subproblem.getVectorVariable(_tid, var_name).adSln());
193  }
194 
195  if (_object_tracker->isTrackerParamValid("coupled_force_vector_function",
197  {
198  const auto & func_names = _object_tracker->get<std::vector<FunctionName>>(
199  "coupled_force_vector_function", _current_subdomain_id);
200  for (const auto & func_name : func_names)
202  }
203  }
204 }
205 
206 void
208 {
211  // Subtract u_r / r
215 
217  if (_has_transient)
218  _td_strong_residual[_qp] = _rho[_qp] * (*_velocity_dot)[_qp];
219  if (_has_gravity)
221  if (_has_boussinesq)
222  _boussinesq_strong_residual[_qp] = (*_boussinesq_alpha)[_qp] * _gravity_vector * _rho[_qp] *
223  ((*_temperature)[_qp] - (*_ref_temp)[_qp]);
225 
226  if (_has_advected_mesh)
227  {
228  _mesh_velocity[_qp](0) = (*_disp_x_dot)[_qp];
229  if (_disp_y_dot)
230  _mesh_velocity[_qp](1) = (*_disp_y_dot)[_qp];
231  if (_disp_z_dot)
232  _mesh_velocity[_qp](2) = (*_disp_z_dot)[_qp];
235  }
236 
237  if (_has_coupled_force)
238  {
240  mooseAssert(!(_coupled_force_var.empty() && _coupled_force_vector_function.empty()),
241  "Either the coupled force var or the coupled force vector function must be "
242  "non-empty in 'INSADMaterial'");
243  for (const auto * var : _coupled_force_var)
244  {
245  mooseAssert(var, "null coupled variable in INSADMaterial");
247  }
248  for (const auto * fn : _coupled_force_vector_function)
249  {
250  mooseAssert(fn, "null coupled function in INSADMaterial");
251  _coupled_force_strong_residual[_qp] -= fn->vectorValue(_t, _q_point[_qp]);
252  }
253  }
254 
255  // // Future Addition
256  // _mms_function_strong_residual[_qp] = -RealVectorValue(_x_vel_fn.value(_t, _q_point[_qp]),
257  // _y_vel_fn.value(_t, _q_point[_qp]),
258  // _z_vel_fn.value(_t, _q_point[_qp]));
259 }
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)
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:77
virtual void subdomainSetup() override
Definition: INSADMaterial.C:92
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:21
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
const bool _use_displaced_mesh
Whether we are on the displaced mesh.
Definition: INSADMaterial.h:80
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:33
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