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 
13 registerADMooseObject("NavierStokesApp", INSADMaterial);
14 
17  ADMaterial,
18  params.addClassDescription("This is the material class used to compute some of the strong "
19  "residuals for the INS equations.");
20  params.addRequiredCoupledVar("velocity", "The velocity");
21  params.addRequiredCoupledVar("pressure", "The pressure");
22  params.addParam<MaterialPropertyName>("mu_name", "mu", "The name of the dynamic viscosity");
23  params.addParam<MaterialPropertyName>("rho_name", "rho", "The name of the density");
24  params.addParam<bool>("transient_term",
25  true,
26  "Whether there should be a transient term in the momentum residuals.");
27  params.addParam<bool>("integrate_p_by_parts",
28  true,
29  "Whether to integrate the pressure by parts");
30  params.addParam<bool>("include_viscous_term_in_strong_form",
31  false,
32  "Whether to include the strong form of the viscous term in the momentum "
33  "equation strong residual. The method is more consistent if set to true, "
34  "but it incurs quite a bit more computational expense");
35  params.addParam<RealVectorValue>("gravity", "Direction of the gravity vector");
36  params.addParam<FunctionName>("function_x", 0, "The x-velocity mms forcing function.");
37  params.addParam<FunctionName>("function_y", 0, "The y-velocity mms forcing function.");
38  params.addParam<FunctionName>("function_z", 0, "The z-velocity mms forcing function."););
39 
40 template <ComputeStage compute_stage>
41 INSADMaterial<compute_stage>::INSADMaterial(const InputParameters & parameters)
42  : ADMaterial<compute_stage>(parameters),
43  _velocity(adCoupledVectorValue("velocity")),
44  _grad_velocity(adCoupledVectorGradient("velocity")),
45  _grad_p(adCoupledGradient("pressure")),
46  _mu(getADMaterialProperty<Real>("mu_name")),
47  _rho(getADMaterialProperty<Real>("rho_name")),
48  _transient_term(getParam<bool>("transient_term")),
49  _velocity_dot(_transient_term ? &adCoupledVectorDot("velocity") : nullptr),
50  _integrate_p_by_parts(getParam<bool>("integrate_p_by_parts")),
51  _include_viscous_term_in_strong_form(getParam<bool>("include_viscous_term_in_strong_form")),
52  _mass_strong_residual(declareADProperty<Real>("mass_strong_residual")),
53  _convective_strong_residual(declareADProperty<RealVectorValue>("convective_strong_residual")),
54  _td_strong_residual(declareADProperty<RealVectorValue>("td_strong_residual")),
55  _gravity_strong_residual(declareADProperty<RealVectorValue>("gravity_strong_residual")),
56  _mms_function_strong_residual(declareProperty<RealVectorValue>("mms_function_strong_residual")),
57  _momentum_strong_residual(declareADProperty<RealVectorValue>("momentum_strong_residual")),
58  _x_vel_fn(getFunction("function_x")),
59  _y_vel_fn(getFunction("function_y")),
60  _z_vel_fn(getFunction("function_z"))
61 {
62  if (parameters.isParamSetByUser("gravity"))
63  {
64  _gravity_set = true;
65  _gravity = getParam<RealVectorValue>("gravity");
66  }
67  else
68  _gravity_set = false;
69  if (getParam<bool>("include_viscous_term_in_strong_form"))
70  mooseError("Sorry no TypeNTensor operations are currently implemented, so we cannot add the "
71  "strong form contribution of the viscous term. Note that for linear elements, this "
72  "introduces no error, and in general for bi-linear elements, the error is small");
73 }
74 
75 template <ComputeStage compute_stage>
76 void
78 {
79  _mass_strong_residual[_qp] = -_grad_velocity[_qp].tr();
80  _convective_strong_residual[_qp] = _rho[_qp] * _grad_velocity[_qp] * _velocity[_qp];
81  _td_strong_residual[_qp] =
82  _transient_term ? _rho[_qp] * (*_velocity_dot)[_qp] : ADRealVectorValue(0);
83  _gravity_strong_residual[_qp] = _gravity_set ? -_rho[_qp] * _gravity : ADRealVectorValue(0);
84  _mms_function_strong_residual[_qp] = -RealVectorValue(_x_vel_fn.value(_t, _q_point[_qp]),
85  _y_vel_fn.value(_t, _q_point[_qp]),
86  _z_vel_fn.value(_t, _q_point[_qp]));
87  _momentum_strong_residual[_qp] =
88  _gravity_strong_residual[_qp] + _mms_function_strong_residual[_qp] +
89  _convective_strong_residual[_qp] + _td_strong_residual[_qp] + _grad_p[_qp];
90 }
INSADMaterial::computeQpProperties
virtual void computeQpProperties() override
Definition: INSADMaterial.C:77
INSADMaterial::_gravity_set
bool _gravity_set
Whether the user set a gravity vector. If none is set, we assume there is no gravity term in the simu...
Definition: INSADMaterial.h:65
INSADMaterial::INSADMaterial
INSADMaterial(const InputParameters &parameters)
Definition: INSADMaterial.C:41
defineADValidParams
defineADValidParams(INSADMaterial, ADMaterial, params.addClassDescription("This is the material class used to compute some of the strong " "residuals for the INS equations.");params.addRequiredCoupledVar("velocity", "The velocity");params.addRequiredCoupledVar("pressure", "The pressure");params.addParam< MaterialPropertyName >("mu_name", "mu", "The name of the dynamic viscosity");params.addParam< MaterialPropertyName >("rho_name", "rho", "The name of the density");params.addParam< bool >("transient_term", true, "Whether there should be a transient term in the momentum residuals.");params.addParam< bool >("integrate_p_by_parts", true, "Whether to integrate the pressure by parts");params.addParam< bool >("include_viscous_term_in_strong_form", false, "Whether to include the strong form of the viscous term in the momentum " "equation strong residual. The method is more consistent if set to true, " "but it incurs quite a bit more computational expense");params.addParam< RealVectorValue >("gravity", "Direction of the gravity vector");params.addParam< FunctionName >("function_x", 0, "The x-velocity mms forcing function.");params.addParam< FunctionName >("function_y", 0, "The y-velocity mms forcing function.");params.addParam< FunctionName >("function_z", 0, "The z-velocity mms forcing function.");)
INSADMaterial.h
registerADMooseObject
registerADMooseObject("NavierStokesApp", INSADMaterial)
INSADMaterial
Definition: INSADMaterial.h:22
INSADMaterial::_gravity
RealVectorValue _gravity
The gravity vector; should be in units of acceleration.
Definition: INSADMaterial.h:68