https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
INSADTauMaterialTempl< T > Class Template Reference

#include <INSADTauMaterial.h>

Inheritance diagram for INSADTauMaterialTempl< T >:
[legend]

Public Member Functions

 INSADTauMaterialTempl (const InputParameters &parameters)
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

virtual void computeProperties () override
 
virtual void computeQpProperties () override
 
void computeHMax ()
 Compute the maximum dimension of the current element.
 
void computeViscousStrongResidual ()
 Compute the viscous strong residual.
 
void viscousTermRZ ()
 Compute the strong form corresponding to RZ pieces of the viscous term.
 
bool doVelocityDerivatives () const
 Whether to seed with respect to velocity derivatives.
 

Protected Attributes

const Real _alpha
 
ADMaterialProperty< Real > & _tau
 
ADMaterialProperty< RealVectorValue > & _viscous_strong_residual
 Strong residual corresponding to the momentum viscous term.
 
ADMaterialProperty< RealVectorValue > & _momentum_strong_residual
 The strong residual of the momentum equation.
 
ADReal _hmax
 
const VectorMooseVariable *const _velocity_var
 The velocity variable.
 
const FEBase *const & _scalar_lagrange_fe
 A scalar Lagrange FE data member to compute the velocity second derivatives since they're currently not supported for vector FE types.
 
std::vector< ADRealTensorValue > _d2u
 Containers to hold the matrix of second spatial derivatives of velocity.
 
std::vector< ADRealTensorValue > _d2v
 
std::vector< ADRealTensorValue > _d2w
 
const unsigned int _vel_number
 The velocity variable number.
 
const unsigned int _vel_sys_number
 The velocity system number.
 
ADReal _speed
 The speed of the medium.
 

Detailed Description

template<typename T>
class INSADTauMaterialTempl< T >

Definition at line 32 of file INSADTauMaterial.h.

Constructor & Destructor Documentation

◆ INSADTauMaterialTempl()

template<typename T >
INSADTauMaterialTempl< T >::INSADTauMaterialTempl ( const InputParameters &  parameters)

Definition at line 152 of file INSADTauMaterial.h.

153 : T(parameters),
154 _alpha(this->template getParam<Real>("alpha")),
155 _tau(this->template declareADProperty<Real>("tau")),
157 this->template declareADProperty<RealVectorValue>("viscous_strong_residual")),
159 this->template declareADProperty<RealVectorValue>("momentum_strong_residual")),
160 _velocity_var(getVectorVar("velocity", 0)),
161 _scalar_lagrange_fe(_assembly.getFE(FEType(_velocity_var->feType().order, LAGRANGE)
162 .set_p_refinement(_velocity_var->feType().p_refinement),
163 _mesh.dimension())),
166{
167 _scalar_lagrange_fe->get_d2phi();
168}
const double T
ADMaterialProperty< RealVectorValue > & _viscous_strong_residual
Strong residual corresponding to the momentum viscous term.
const FEBase *const & _scalar_lagrange_fe
A scalar Lagrange FE data member to compute the velocity second derivatives since they're currently n...
const VectorMooseVariable *const _velocity_var
The velocity variable.
const unsigned int _vel_sys_number
The velocity system number.
ADMaterialProperty< Real > & _tau
ADMaterialProperty< RealVectorValue > & _momentum_strong_residual
The strong residual of the momentum equation.
const unsigned int _vel_number
The velocity variable number.
const libMesh::FEType & feType() const
SystemBase & sys()
unsigned int number() const
unsigned int number() const
OrderWrapper order

Member Function Documentation

◆ computeHMax()

template<typename T >
void INSADTauMaterialTempl< T >::computeHMax ( )
protected

Compute the maximum dimension of the current element.

Definition at line 180 of file INSADTauMaterial.h.

181{
182 if (_disp_x_num == libMesh::invalid_uint || !ADReal::do_derivatives)
183 {
184 _hmax = _current_elem->hmax();
185 return;
186 }
187
188 _hmax = 0;
189 std::array<unsigned int, 3> disps = {_disp_x_num, _disp_y_num, _disp_z_num};
190 std::array<unsigned int, 3> disp_sys_nums = {_disp_x_sys_num, _disp_y_sys_num, _disp_z_sys_num};
191
192 for (unsigned int n_outer = 0; n_outer < _current_elem->n_vertices(); n_outer++)
193 for (unsigned int n_inner = n_outer + 1; n_inner < _current_elem->n_vertices(); n_inner++)
194 {
195 VectorValue<ADReal> diff = (_current_elem->point(n_outer) - _current_elem->point(n_inner));
196 for (const auto i : index_range(disps))
197 {
198 const auto disp_num = disps[i];
199 if (disp_num == libMesh::invalid_uint)
200 continue;
201 const auto sys_num = disp_sys_nums[i];
202
203 // Here we insert derivatives of the difference in nodal positions with respect to the
204 // displacement degrees of freedom. From above, diff = outer_node_position -
205 // inner_node_position
206 diff(i).derivatives().insert(
207 _current_elem->node_ref(n_outer).dof_number(sys_num, disp_num, 0)) = 1.;
208 diff(i).derivatives().insert(
209 _current_elem->node_ref(n_inner).dof_number(sys_num, disp_num, 0)) = -1.;
210 }
211
212 _hmax = std::max(_hmax, diff.norm_sq());
213 }
214
215 using std::sqrt;
216 _hmax = sqrt(_hmax);
217}
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
auto index_range(const T &sizable)
const unsigned int invalid_uint

◆ computeProperties()

template<typename T >
void INSADTauMaterialTempl< T >::computeProperties ( )
overrideprotectedvirtual

Definition at line 221 of file INSADTauMaterial.h.

222{
223 computeHMax();
225
226 T::computeProperties();
227}
void computeViscousStrongResidual()
Compute the viscous strong residual.
void computeHMax()
Compute the maximum dimension of the current element.

◆ computeQpProperties()

template<typename T >
void INSADTauMaterialTempl< T >::computeQpProperties ( )
overrideprotectedvirtual

Reimplemented in INSADStabilized3Eqn.

Definition at line 345 of file INSADTauMaterial.h.

346{
347 T::computeQpProperties();
348
349 using std::sqrt;
350
351 const auto nu = _mu[_qp] / _rho[_qp];
352 const auto transient_part = _has_transient ? 4. / (_dt * _dt) : 0.;
353 _speed = NS::computeSpeed<ADReal>(_relative_velocity[_qp]);
354 _tau[_qp] = _alpha / sqrt(transient_part + (2. * _speed / _hmax) * (2. * _speed / _hmax) +
355 9. * (4. * nu / (_hmax * _hmax)) * (4. * nu / (_hmax * _hmax)));
356
358 _advective_strong_residual[_qp] + _viscous_strong_residual[_qp] + _grad_p[_qp];
359
360 if (_has_transient)
361 _momentum_strong_residual[_qp] += _td_strong_residual[_qp];
362
363 if (_has_gravity)
364 _momentum_strong_residual[_qp] += _gravity_strong_residual[_qp];
365
366 if (_has_boussinesq)
367 _momentum_strong_residual[_qp] += _boussinesq_strong_residual[_qp];
368
369 if (_has_advected_mesh)
370 _momentum_strong_residual[_qp] += _advected_mesh_strong_residual[_qp];
371
372 if (_has_coupled_force)
373 _momentum_strong_residual[_qp] += _coupled_force_strong_residual[_qp];
374
375 // // Future addition
376 // if (_object_tracker->hasMMS())
377 // _momentum_strong_residual[_qp] += _mms_function_strong_residual[_qp];
378}
ADReal _speed
The speed of the medium.
template ADReal computeSpeed< ADReal >(const libMesh::VectorValue< ADReal > &velocity)

Referenced by INSADStabilized3Eqn::computeQpProperties().

◆ computeViscousStrongResidual()

template<typename T >
void INSADTauMaterialTempl< T >::computeViscousStrongResidual ( )
protected

Compute the viscous strong residual.

Definition at line 231 of file INSADTauMaterial.h.

232{
233 auto resize_and_zero = [this](auto & d2vel)
234 {
235 d2vel.resize(_qrule->n_points());
236 for (auto & d2qp : d2vel)
237 d2qp = 0;
238 };
239 resize_and_zero(_d2u);
240 resize_and_zero(_d2v);
241 resize_and_zero(_d2w);
242
243 auto get_d2 = [this](const auto i) -> std::vector<ADRealTensorValue> &
244 {
245 switch (i)
246 {
247 case 0:
248 return _d2u;
249 case 1:
250 return _d2v;
251 case 2:
252 return _d2w;
253 default:
254 mooseError("invalid value of 'i'");
255 }
256 };
257
258 // libMesh does not yet have the capability for computing second order spatial derivatives of
259 // vector bases. Lacking that capability, we can compute the second order spatial derivatives "by
260 // hand" using the scalar field version of the vector basis, e.g. LAGRANGE instead of
261 // LAGRANGE_VEC. Adding this implementation allows us to be fully consistent with results from a
262 // scalar velocity field component implementation of Navier-Stokes
263 const auto & vel_dof_indices = _velocity_var->dofIndices();
264 for (const auto i : index_range(vel_dof_indices))
265 {
266 // This may not work if the element and spatial dimensions are different
267 mooseAssert(_current_elem->dim() == _mesh.dimension(),
268 "Below logic only applicable if element and mesh dimension are the same");
269 const auto dimensional_component = i % _mesh.dimension();
270 auto & d2vel = get_d2(dimensional_component);
271 const auto dof_index = vel_dof_indices[i];
272 ADReal dof_value = (*_velocity_var->sys().currentSolution())(dof_index);
274 dof_value.derivatives().insert(dof_index) = 1;
275 const auto scalar_i_component = i / _mesh.dimension();
276 for (const auto qp : make_range(_qrule->n_points()))
277 d2vel[qp] += dof_value * _scalar_lagrange_fe->get_d2phi()[scalar_i_component][qp];
278 }
279
280 // Now that we have the second order spatial derivatives of velocity, we can compute the strong
281 // form of the viscous residual for use in our stabilization calculations
282 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
283 {
284 _viscous_strong_residual[_qp](0) = -_mu[_qp] * _d2u[_qp].tr();
286 _mesh.dimension() >= 2 ? -_mu[_qp] * _d2v[_qp].tr() : ADReal(0);
288 _mesh.dimension() == 3 ? -_mu[_qp] * _d2w[_qp].tr() : ADReal(0);
289 if (_viscous_form == NS::ViscousForm::Traction)
290 {
291 _viscous_strong_residual[_qp] -= _mu[_qp] * _d2u[_qp].row(0);
292 if (_mesh.dimension() >= 2)
293 _viscous_strong_residual[_qp] -= _mu[_qp] * _d2v[_qp].row(1);
294 if (_mesh.dimension() == 3)
295 _viscous_strong_residual[_qp] -= _mu[_qp] * _d2w[_qp].row(2);
296 }
297 if (_coord_sys == Moose::COORD_RZ)
299 }
300}
DualNumber< Real, DNDerivativeType, true > ADReal
void mooseError(Args &&... args)
std::vector< ADRealTensorValue > _d2u
Containers to hold the matrix of second spatial derivatives of velocity.
void viscousTermRZ()
Compute the strong form corresponding to RZ pieces of the viscous term.
std::vector< ADRealTensorValue > _d2v
bool doVelocityDerivatives() const
Whether to seed with respect to velocity derivatives.
std::vector< ADRealTensorValue > _d2w
const std::vector< dof_id_type > & dofIndices() const final
virtual const NumericVector< Number > *const & currentSolution() const=0
IntRange< T > make_range(T beg, T end)

◆ doVelocityDerivatives()

template<typename T >
bool INSADTauMaterialTempl< T >::doVelocityDerivatives ( ) const
protected

Whether to seed with respect to velocity derivatives.

Definition at line 172 of file INSADTauMaterial.h.

173{
174 return ADReal::do_derivatives &&
175 (_vel_sys_number == _fe_problem.currentNonlinearSystem().number());
176}

◆ validParams()

template<typename T >
InputParameters INSADTauMaterialTempl< T >::validParams ( )
static

Definition at line 142 of file INSADTauMaterial.h.

143{
144 InputParameters params = T::validParams();
145 params.addClassDescription(
146 "This is the material class used to compute the stabilization parameter tau.");
147 params.addParam<Real>("alpha", 1., "Multiplicative factor on the stabilization parameter tau.");
148 return params;
149}
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)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Referenced by INSADStabilized3Eqn::validParams().

◆ viscousTermRZ()

template<typename T >
void INSADTauMaterialTempl< T >::viscousTermRZ ( )
protected

Compute the strong form corresponding to RZ pieces of the viscous term.

Definition at line 304 of file INSADTauMaterial.h.

305{
306 // To understand the code immediately below, visit
307 // https://en.wikipedia.org/wiki/Del_in_cylindrical_and_spherical_coordinates.
308 // The u_r / r^2 term comes from the vector Laplacian. The -du_i/dr * 1/r term comes from
309 // the scalar Laplacian. The scalar Laplacian in axisymmetric cylindrical coordinates is
310 // equivalent to the Cartesian Laplacian plus a 1/r * du_i/dr term. And of course we are
311 // applying a minus sign here because the strong form is -\nabala^2 * \vec{u}
312 //
313 // Another note: libMesh implements grad(v) as dvi/dxj or more obviously:
314 //
315 // grad(v) = (vx_x vx_y)
316 // (vy_x vy_y)
317 //
318 // so, the gradient of the velocity with respect to the radial coordinate will correspond to a
319 // *column* slice
320
321 const auto & r = _ad_q_point[_qp](_rz_radial_coord);
322
323 {
324 // Do the "Laplace" form. This will be present in *both* Laplace and Traction forms
325 ADRealVectorValue rz_term;
326 for (const auto i : make_range((unsigned int)2))
327 rz_term(i) = -_mu[_qp] * _grad_velocity[_qp](i, _rz_radial_coord) / r;
328 rz_term(_rz_radial_coord) += _mu[_qp] * _velocity[_qp](_rz_radial_coord) / (r * r);
329 _viscous_strong_residual[_qp] += rz_term;
330 }
331 if (_viscous_form == NS::ViscousForm::Traction)
332 {
333 ADRealVectorValue rz_term;
334 for (const auto i : make_range((unsigned int)2))
335 // This is the transpose of the above
336 rz_term(i) = -_mu[_qp] * _grad_velocity[_qp](_rz_radial_coord, i) / r;
337 // This is the same as above (since the transpose of the diagonal is the diagonal)
338 rz_term(_rz_radial_coord) += _mu[_qp] * _velocity[_qp](_rz_radial_coord) / (r * r);
339 _viscous_strong_residual[_qp] += rz_term;
340 }
341}
void ErrorVector unsigned int

Member Data Documentation

◆ _alpha

template<typename T >
const Real INSADTauMaterialTempl< T >::_alpha
protected

Definition at line 63 of file INSADTauMaterial.h.

◆ _d2u

template<typename T >
std::vector<ADRealTensorValue> INSADTauMaterialTempl< T >::_d2u
protected

Containers to hold the matrix of second spatial derivatives of velocity.

Definition at line 83 of file INSADTauMaterial.h.

◆ _d2v

template<typename T >
std::vector<ADRealTensorValue> INSADTauMaterialTempl< T >::_d2v
protected

Definition at line 84 of file INSADTauMaterial.h.

◆ _d2w

template<typename T >
std::vector<ADRealTensorValue> INSADTauMaterialTempl< T >::_d2w
protected

Definition at line 85 of file INSADTauMaterial.h.

◆ _hmax

template<typename T >
ADReal INSADTauMaterialTempl< T >::_hmax
protected

Definition at line 73 of file INSADTauMaterial.h.

◆ _momentum_strong_residual

template<typename T >
ADMaterialProperty<RealVectorValue>& INSADTauMaterialTempl< T >::_momentum_strong_residual
protected

The strong residual of the momentum equation.

Definition at line 71 of file INSADTauMaterial.h.

◆ _scalar_lagrange_fe

template<typename T >
const FEBase* const& INSADTauMaterialTempl< T >::_scalar_lagrange_fe
protected

A scalar Lagrange FE data member to compute the velocity second derivatives since they're currently not supported for vector FE types.

Definition at line 80 of file INSADTauMaterial.h.

Referenced by INSADTauMaterialTempl< T >::INSADTauMaterialTempl().

◆ _speed

template<typename T >
ADReal INSADTauMaterialTempl< T >::_speed
protected

The speed of the medium.

This is the norm of the relative velocity, e.g. the velocity minus the mesh velocity, at the current _qp

Definition at line 95 of file INSADTauMaterial.h.

◆ _tau

template<typename T >
ADMaterialProperty<Real>& INSADTauMaterialTempl< T >::_tau
protected

Definition at line 64 of file INSADTauMaterial.h.

◆ _vel_number

template<typename T >
const unsigned int INSADTauMaterialTempl< T >::_vel_number
protected

The velocity variable number.

Definition at line 88 of file INSADTauMaterial.h.

◆ _vel_sys_number

template<typename T >
const unsigned int INSADTauMaterialTempl< T >::_vel_sys_number
protected

The velocity system number.

Definition at line 91 of file INSADTauMaterial.h.

◆ _velocity_var

template<typename T >
const VectorMooseVariable* const INSADTauMaterialTempl< T >::_velocity_var
protected

The velocity variable.

Definition at line 76 of file INSADTauMaterial.h.

◆ _viscous_strong_residual

template<typename T >
ADMaterialProperty<RealVectorValue>& INSADTauMaterialTempl< T >::_viscous_strong_residual
protected

Strong residual corresponding to the momentum viscous term.

This is only used by stabilization kernels

Definition at line 68 of file INSADTauMaterial.h.


The documentation for this class was generated from the following file: