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 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<Material>();
19 
20  params.addCoupledVar("disp_r", "The r displacement");
21  params.addCoupledVar("disp_x", "The x displacement");
22  params.addCoupledVar("disp_y", "The y displacement");
23  params.addCoupledVar("disp_z", "The z displacement");
24 
25  params.addCoupledVar(
26  "displacements",
27  "The displacements appropriate for the simulation geometry and coordinate system");
28 
29  params.addParam<std::string>("base_name",
30  "Optional parameter that allows the user to define "
31  "multiple material systems on the same block, "
32  "e.g. for multiple phases");
33  params.addRequiredParam<Real>("density", "Density");
34  params.addClassDescription("Creates density material property");
35 
36  return params;
37 }
38 
39 Density::Density(const InputParameters & parameters)
40  : Material(parameters),
41  _is_coupled(true),
42  _disp_r(isCoupled("displacements") ? coupledValue("displacements", 0)
43  : (isCoupled("disp_r") ? coupledValue("disp_r") : _zero)),
44  _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
45  _orig_density(getParam<Real>("density")),
46  _density(declareProperty<Real>(_base_name + "density"))
47 {
48  // new parameter scheme
49  if (isCoupled("displacements"))
50  {
51  // get coordinate system
52  _coord_system = getBlockCoordSystem();
53 
54  // get coupled gradients
55  const unsigned int ndisp = coupledComponents("displacements");
56  _grad_disp.resize(ndisp);
57  for (unsigned int i = 0; i < ndisp; ++i)
58  _grad_disp[i] = &coupledGradient("displacements", i);
59 
60  // fill remaining components with zero
61  _grad_disp.resize(3, &_grad_zero);
62  }
63 
64  // old deprecated parameters
65  else if (isCoupled("disp_x") || isCoupled("disp_r"))
66  {
67  // guess(!) coordinate system
68  if (isCoupled("disp_r"))
69  {
70  if (isCoupled("disp_z"))
71  _coord_system = Moose::COORD_RZ;
72  else
73  _coord_system = Moose::COORD_RSPHERICAL;
74  }
75  else
76  _coord_system = Moose::COORD_XYZ;
77 
78  // couple gradients
79  _grad_disp = {
80  isCoupled("disp_x") ? &coupledGradient("disp_x")
81  : (isCoupled("disp_r") ? &coupledGradient("disp_r") : &_grad_zero),
82  isCoupled("disp_y") ? &coupledGradient("disp_y")
83  : (isCoupled("disp_z") ? &coupledGradient("disp_z") : &_grad_zero),
84  _coord_system != Moose::COORD_RZ && isCoupled("disp_z") ? &coupledGradient("disp_z")
85  : &_grad_zero};
86  }
87 
88  // no coupling
89  else
90  {
91  _is_coupled = false;
92  // TODO: We should deprecate this case and have the user use a GenericConstantMaterial for this
93  }
94 }
95 
96 void
98 {
99  _density[_qp] = _orig_density;
100 }
101 
102 void
104 {
105  Real density = _orig_density;
106  if (_is_coupled)
107  {
108  // rho * V = rho0 * V0
109  // rho = rho0 * V0 / V
110  // rho = rho0 / det(F)
111  // rho = rho0 / det(grad(u) + 1)
112 
113  const Real Axx = (*_grad_disp[0])[_qp](0) + 1.0;
114  const Real Axy = (*_grad_disp[0])[_qp](1);
115  const Real Axz = (*_grad_disp[0])[_qp](2);
116  const Real Ayx = (*_grad_disp[1])[_qp](0);
117  Real Ayy = (*_grad_disp[1])[_qp](1) + 1.0;
118  const Real Ayz = (*_grad_disp[1])[_qp](2);
119  const Real Azx = (*_grad_disp[2])[_qp](0);
120  const Real Azy = (*_grad_disp[2])[_qp](1);
121  Real Azz = (*_grad_disp[2])[_qp](2) + 1.0;
122 
123  switch (_coord_system)
124  {
125  case Moose::COORD_XYZ:
126  Azz = (*_grad_disp[2])[_qp](2) + 1.0;
127  break;
128 
129  case Moose::COORD_RZ:
130  if (_q_point[_qp](0) != 0.0)
131  Azz = _disp_r[_qp] / _q_point[_qp](0) + 1.0;
132  break;
133 
134  case Moose::COORD_RSPHERICAL:
135  if (_q_point[_qp](0) != 0.0)
136  Ayy = Azz = _disp_r[_qp] / _q_point[_qp](0) + 1.0;
137  break;
138  }
139 
140  const Real detF = Axx * Ayy * Azz + Axy * Ayz * Azx + Axz * Ayx * Azy - Azx * Ayy * Axz -
141  Azy * Ayz * Axx - Azz * Ayx * Axy;
142  density /= detF;
143  }
144 
145  _density[_qp] = density;
146 }
Density::initQpStatefulProperties
virtual void initQpStatefulProperties() override
Definition: Density.C:97
Density::_is_coupled
bool _is_coupled
Definition: Density.h:26
Density::_coord_system
Moose::CoordinateSystemType _coord_system
Definition: Density.h:27
Density::_orig_density
const Real _orig_density
Definition: Density.h:32
validParams< Density >
InputParameters validParams< Density >()
Definition: Density.C:16
registerMooseObject
registerMooseObject("MiscApp", Density)
NS::density
const std::string density
Definition: NS.h:16
Density::Density
Density(const InputParameters &params)
Definition: Density.C:39
Density::_disp_r
const VariableValue & _disp_r
Definition: Density.h:29
Density.h
Density::_density
MaterialProperty< Real > & _density
Definition: Density.h:33
Density::_grad_disp
std::vector< const VariableGradient * > _grad_disp
Definition: Density.h:28
Density::computeQpProperties
virtual void computeQpProperties() override
Definition: Density.C:103
Density
Compute density, which may changed based on a deforming mesh.
Definition: Density.h:17