www.mooseframework.org
Density.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 "Density.h"
11 
12 registerMooseObject("MiscApp", Density);
13 registerMooseObject("MiscApp", ADDensity);
14 
15 template <bool is_ad>
18 {
20 
21  params.addCoupledVar(
22  "displacements",
23  "The displacements appropriate for the simulation geometry and coordinate system");
24 
25  params.addParam<std::string>("base_name",
26  "Optional parameter that allows the user to define "
27  "multiple material systems on the same block, "
28  "e.g. for multiple phases");
29  params.addRequiredParam<Real>("density", "Density");
30  params.addClassDescription("Creates density material property");
31 
32  return params;
33 }
34 
35 template <bool is_ad>
37  : Material(parameters),
38  _is_coupled(isCoupled("displacements")),
39  _coord_system(getBlockCoordSystem()),
40  _disp_r(_is_coupled ? this->template coupledGenericValue<is_ad>("displacements", 0)
41  : genericZeroValue<is_ad>()),
42  _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
43  _initial_density(getParam<Real>("density")),
44  _grad_disp(_is_coupled ? this->template coupledGenericGradients<is_ad>("displacements")
45  : std::vector<const GenericVariableGradient<is_ad> *>()),
46  _density(declareGenericProperty<Real, is_ad>(_base_name + "density"))
47 {
48  if (getParam<bool>("use_displaced_mesh"))
49  paramError("use_displaced_mesh",
50  "Density needs to act on an undisplaced mesh. Use of a displaced mesh leads to "
51  "incorrect gradient values");
52 
53  // get coupled gradients
54  const unsigned int ndisp = coupledComponents("displacements");
55 
56  if (ndisp == 0 && _fe_problem.getDisplacedProblem())
57  paramError(
58  "displacements",
59  "The system uses a displaced problem but 'displacements' are not provided in Density.");
60 
61  // fill remaining components with zero
62  _grad_disp.resize(3, &genericZeroGradient<is_ad>());
63 }
64 
65 template <bool is_ad>
66 void
68 {
69  _density[_qp] = _initial_density;
70 }
71 
72 template <bool is_ad>
73 void
75 {
76  GenericReal<is_ad> density = _initial_density;
77 
78  // TODO: We should deprecate the !_is_coupled case and have the
79  // user use a GenericConstantMaterial
80  if (_is_coupled)
81  {
82  // rho * V = rho0 * V0
83  // rho = rho0 * V0 / V
84  // rho = rho0 / det(F)
85  // rho = rho0 / det(grad(u) + 1)
86 
87  const auto Axx = (*_grad_disp[0])[_qp](0) + 1.0;
88  const auto & Axy = (*_grad_disp[0])[_qp](1);
89  const auto & Axz = (*_grad_disp[0])[_qp](2);
90  const auto & Ayx = (*_grad_disp[1])[_qp](0);
91  auto Ayy = (*_grad_disp[1])[_qp](1) + 1.0;
92  const auto & Ayz = (*_grad_disp[1])[_qp](2);
93  const auto & Azx = (*_grad_disp[2])[_qp](0);
94  const auto & Azy = (*_grad_disp[2])[_qp](1);
95  auto Azz = (*_grad_disp[2])[_qp](2) + 1.0;
96 
97  switch (_coord_system)
98  {
99  case Moose::COORD_XYZ:
100  Azz = (*_grad_disp[2])[_qp](2) + 1.0;
101  break;
102 
103  case Moose::COORD_RZ:
104  if (_q_point[_qp](0) != 0.0)
105  Azz = _disp_r[_qp] / _q_point[_qp](0) + 1.0;
106  break;
107 
109  if (_q_point[_qp](0) != 0.0)
110  Ayy = Azz = _disp_r[_qp] / _q_point[_qp](0) + 1.0;
111  break;
112  }
113 
114  const auto detF = Axx * Ayy * Azz + Axy * Ayz * Azx + Axz * Ayx * Azy - Azx * Ayy * Axz -
115  Azy * Ayz * Axx - Azz * Ayx * Axy;
116  density /= detF;
117  }
118 
119  _density[_qp] = density;
120 }
121 
122 template class DensityTempl<false>;
123 template class DensityTempl<true>;
Compute density, which may changed based on a deforming mesh.
Definition: Density.h:18
FEProblemBase & _fe_problem
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
Definition: Density.C:17
static const std::string density
Definition: NS.h:33
DensityTempl(const InputParameters &params)
Definition: Density.C:36
COORD_RSPHERICAL
std::vector< const GenericVariableGradient< is_ad > * > _grad_disp
Definition: Density.h:37
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
registerMooseObject("MiscApp", Density)
void addCoupledVar(const std::string &name, const std::string &doc_string)
virtual void initQpStatefulProperties() override
Definition: Density.C:67
virtual void computeQpProperties() override
Definition: Density.C:74
unsigned int coupledComponents(const std::string &var_name) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
void addClassDescription(const std::string &doc_string)
typename Moose::GenericType< Real, is_ad > GenericReal
typename Moose::GenericType< VariableGradient, is_ad > GenericVariableGradient