https://mooseframework.inl.gov
Loading...
Searching...
No Matches
INSADMomentumViscous.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
11#include "Assembly.h"
12#include "SystemBase.h"
13#include "INSADObjectTracker.h"
14
15#include "metaphysicl/raw_type.h"
16
18
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
72void
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 {
84 const RealTensorValue value = raw_value(qpViscousTerm()) * _JxW[_qp] * _coord[_qp];
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
108void
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 {
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
156ADReal
158{
159 mooseError("computeQpResidual is not used in the INSADMomentumViscous class");
160}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("NavierStokesApp", INSADMomentumViscous)
const MooseArray< ADPoint > & _ad_q_point
const ADTemplateVariableValue< T > & _u
const ADTemplateVariableTestValue< T > & _test
const ADTemplateVariableTestGradient< T > & _grad_test
static InputParameters validParams()
std::vector< ADReal > _residuals
MooseVariableFE< T > & _var
const OutputTools< T >::VariableTestGradient & _regular_grad_test
const MooseArray< ADReal > & _ad_JxW
virtual const std::vector< dof_id_type > & dofIndices() const
const ADTemplateVariableGradient< T > & _grad_u
const MooseArray< ADReal > & _ad_coord
virtual const std::set< SubdomainID > & blockIDs() const
T & getUserObject(const std::string &name, unsigned int tid=0) const
This class computes the momentum equation residual and Jacobian contributions for the viscous term of...
ADReal computeQpResidual() override
INSADMomentumViscous(const InputParameters &parameters)
ADRealVectorValue qpAdditionalRZTerm()
Computes an additional contribution to the viscous term present of RZ coordinate systems (assumes axi...
ADRealTensorValue qpViscousTerm()
Computes the cartesian coordinate system viscous term.
const unsigned int _rz_radial_coord
The radial coordinate index for RZ coordinate systems.
void computeResidual() override
void computeResidualsForJacobian() override
static InputParameters validParams()
const ADMaterialProperty< Real > & _mu
const Moose::CoordinateSystemType & _coord_sys
const MooseEnum _form
Either traction or laplace.
Object for tracking what kernels have been added to an INSAD simulation.
void set(const std::string &name, const T &value, SubdomainID sub_id)
Set the internal parameter name to 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)
std::vector< MooseVariableFEBase * > _save_in
const bool _use_displaced_mesh
const MooseArray< Real > & _coord
unsigned int _qp
const MooseArray< Real > & _JxW
unsigned int _i
const QBase *const & _qrule
void mooseError(Args &&... args) const
unsigned int number() const
virtual const OutputTools< T >::VariableValue & value()
Assembly & _assembly
FEProblemBase & _fe_problem
void accumulateTaggedLocalResidual()
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
DenseVector< Number > _local_re
libMesh::CompareTypes< T, T2 >::supertype dotProduct(const W< T > &a, const W2< T2 > &b)
auto raw_value(const Eigen::Map< T > &in)