www.mooseframework.org
INSADMomentumViscous.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 "INSADMomentumViscous.h"
11 #include "Assembly.h"
12 #include "SystemBase.h"
13 #include "INSADObjectTracker.h"
14 
15 #include "metaphysicl/raw_type.h"
16 
18 
19 registerMooseObject("NavierStokesApp", INSADMomentumViscous);
20 
23 {
25  params.addClassDescription("Adds the viscous term to the INS momentum equation");
26  params.addParam<MaterialPropertyName>(
27  "mu_name", "mu", "The name of the viscosity material property");
28  MooseEnum viscous_form("traction laplace", "laplace");
29  params.addParam<MooseEnum>("viscous_form",
30  viscous_form,
31  "The form of the viscous term. Options are 'traction' or 'laplace'");
32  return params;
33 }
34 
36  : ADVectorKernel(parameters),
37  _mu(getADMaterialProperty<Real>("mu_name")),
38  _coord_sys(_assembly.coordSystem()),
39  _form(getParam<MooseEnum>("viscous_form")),
40  _rz_radial_coord(_mesh.getAxisymmetricRadialCoord())
41 {
42  auto & obj_tracker = const_cast<INSADObjectTracker &>(
43  _fe_problem.getUserObject<INSADObjectTracker>("ins_ad_object_tracker"));
44  for (const auto block_id : blockIDs())
45  obj_tracker.set("viscous_form", _form, block_id);
46 }
47 
50 {
51  if (_form == "laplace")
52  return _mu[_qp] * _grad_u[_qp];
53  else
54  return _mu[_qp] * (_grad_u[_qp] + _grad_u[_qp].transpose());
55 }
56 
59 {
61  auto & extra_term = ret(_rz_radial_coord);
62 
63  // Add the u_r / r^2 term. There is an extra factor of 2 for the traction form
64  const auto & r = _ad_q_point[_qp](_rz_radial_coord);
65  extra_term = _mu[_qp] * _u[_qp](_rz_radial_coord) / (r * r);
66  if (_form == "traction")
67  extra_term *= 2.;
68 
69  return ret;
70 }
71 
72 void
74 {
75  // When computing the residual we use the regular version of all quantities, e.g. JxW, coord,
76  // test, grad_test, because we do not need to track the derivatives
77 
79 
80  const unsigned int n_test = _grad_test.size();
81 
82  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
83  {
85  for (_i = 0; _i < n_test; _i++) // target for auto vectorization
87 
88  // If we're in RZ, then we need to add an additional term
90  {
91  const RealVectorValue rz_value = raw_value(qpAdditionalRZTerm()) * _JxW[_qp] * _coord[_qp];
92 
93  for (_i = 0; _i < n_test; _i++) // target for auto vectorization
94  _local_re(_i) += rz_value * _test[_i][_qp];
95  }
96  }
97 
99 
100  if (_has_save_in)
101  {
102  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
103  for (unsigned int i = 0; i < _save_in.size(); i++)
104  _save_in[i]->sys().solution().add_vector(_local_re, _save_in[i]->dofIndices());
105  }
106 }
107 
108 void
110 {
111  mooseAssert(_test.size() == _grad_test.size(),
112  "How are the there are different number of test and grad_test objects?");
113  const auto n_test = _test.size();
114 
115  if (_residuals.size() != n_test)
116  _residuals.resize(n_test, 0);
117  for (auto & r : _residuals)
118  r = 0;
119 
121  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
122  {
123  // This will also compute the derivative with respect to all dofs
125  for (_i = 0; _i < _grad_test.size(); _i++)
127 
128  // If we're in RZ, then we need to add an additional term
130  {
131  const ADRealVectorValue rz_value = qpAdditionalRZTerm() * _ad_JxW[_qp] * _ad_coord[_qp];
132 
133  for (_i = 0; _i < n_test; _i++)
134  _residuals[_i] += rz_value * _test[_i][_qp];
135  }
136  }
137  else
138  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
139  {
140  // Compute scalar quanitities up front to reduce DualNumber operations
142  for (_i = 0; _i < _grad_test.size(); _i++)
144 
145  // If we're in RZ, then we need to add an additional term
147  {
148  // Compute scalar quanitities up front to reduce DualNumber operations
149  const ADRealVectorValue rz_value = _JxW[_qp] * _coord[_qp] * qpAdditionalRZTerm();
150  for (_i = 0; _i < n_test; _i++)
151  _residuals[_i] += rz_value * _test[_i][_qp];
152  }
153  }
154 }
155 
156 ADReal
158 {
159  mooseError("computeQpResidual is not used in the INSADMomentumViscous class");
160 }
const ADTemplateVariableTestGradient< T > & _grad_test
void accumulateTaggedLocalResidual()
T & getUserObject(const std::string &name, unsigned int tid=0) const
std::vector< MooseVariableFEBase *> _save_in
const MooseArray< Real > & _JxW
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int number() const
void set(const std::string &name, const T &value, SubdomainID sub_id)
Set the internal parameter name to value.
virtual const std::vector< dof_id_type > & dofIndices() const
This class computes the momentum equation residual and Jacobian contributions for the viscous term of...
const ADMaterialProperty< Real > & _mu
auto raw_value(const Eigen::Map< T > &in)
const ADTemplateVariableValue< T > & _u
const Moose::CoordinateSystemType & _coord_sys
virtual const std::set< SubdomainID > & blockIDs() const
const ADTemplateVariableTestValue< T > & _test
const unsigned int _rz_radial_coord
The radial coordinate index for RZ coordinate systems.
TensorValue< Real > RealTensorValue
std::vector< ADReal > _residuals
registerMooseObject("NavierStokesApp", INSADMomentumViscous)
libMesh::CompareTypes< T, T2 >::supertype dotProduct(const W< T > &a, const W2< T2 > &b)
const QBase *const & _qrule
FEProblemBase & _fe_problem
ADRealVectorValue qpAdditionalRZTerm()
Computes an additional contribution to the viscous term present of RZ coordinate systems (assumes axi...
const OutputTools< T >::VariableTestGradient & _regular_grad_test
const MooseArray< ADPoint > & _ad_q_point
unsigned int _i
virtual const OutputTools< T >::VariableValue & value()
const MooseArray< ADReal > & _ad_JxW
static InputParameters validParams()
void computeResidualsForJacobian() override
const MooseArray< Real > & _coord
Assembly & _assembly
const bool _use_displaced_mesh
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const ADTemplateVariableGradient< T > & _grad_u
INSADMomentumViscous(const InputParameters &parameters)
DenseVector< Number > _local_re
const MooseEnum _form
Either traction or laplace.
ADRealTensorValue qpViscousTerm()
Computes the cartesian coordinate system viscous term.
void mooseError(Args &&... args) const
MooseVariableFE< T > & _var
void addClassDescription(const std::string &doc_string)
ADReal computeQpResidual() override
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
static InputParameters validParams()
Object for tracking what kernels have been added to an INSAD simulation.
void computeResidual() override
const MooseArray< ADReal > & _ad_coord
unsigned int _qp