www.mooseframework.org
ExternalForceDensityMaterial.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 #include "Function.h"
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<Material>();
15  params.addClassDescription("Providing external applied force density to grains");
16  params.addParam<FunctionName>("force_x", 0.0, "The forcing function in x direction.");
17  params.addParam<FunctionName>("force_y", 0.0, "The forcing function in y direction.");
18  params.addParam<FunctionName>("force_z", 0.0, "The forcing function in z direction.");
19  params.addRequiredCoupledVarWithAutoBuild(
20  "etas", "var_name_base", "op_num", "Array of coupled order parameters");
21  params.addCoupledVar("c", "Concentration field");
22  params.addParam<Real>("k", 1.0, "stiffness constant multiplier");
23  return params;
24 }
25 
27  : DerivativeMaterialInterface<Material>(parameters),
28  _force_x(getFunction("force_x")),
29  _force_y(getFunction("force_y")),
30  _force_z(getFunction("force_z")),
31  _c(coupledValue("c")),
32  _c_name(getVar("c", 0)->name()),
33  _k(getParam<Real>("k")),
34  _op_num(coupledComponents(
35  "etas")), // determine number of grains from the number of names passed in.
36  _vals(_op_num), // Size variable arrays
37  _vals_name(_op_num),
38  _dF(declareProperty<std::vector<RealGradient>>("force_density_ext")),
39  _dFdc(declarePropertyDerivative<std::vector<RealGradient>>("force_density_ext", _c_name)),
40  _dFdeta(_op_num)
41 {
42  // Loop through grains and load coupled variables into the arrays
43  for (unsigned int i = 0; i < _op_num; ++i)
44  {
45  _vals[i] = &coupledValue("etas", i);
46  _vals_name[i] = getVar("etas", i)->name();
47  _dFdeta[i] =
48  &declarePropertyDerivative<std::vector<RealGradient>>("force_density_ext", _vals_name[i]);
49  }
50 }
51 
52 void
54 {
55  _dF[_qp].resize(_op_num);
56  _dFdc[_qp].resize(_op_num);
57 
58  for (unsigned int i = 0; i < _op_num; ++i)
59  {
60  _dF[_qp][i](0) = _k * _c[_qp] * _force_x.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
61  _dF[_qp][i](1) = _k * _c[_qp] * _force_y.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
62  _dF[_qp][i](2) = _k * _c[_qp] * _force_z.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
63 
64  _dFdc[_qp][i](0) = _k * _force_x.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
65  _dFdc[_qp][i](1) = _k * _force_y.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
66  _dFdc[_qp][i](2) = _k * _force_z.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
67  }
68 
69  for (unsigned int i = 0; i < _op_num; ++i)
70  {
71  (*_dFdeta[i])[_qp].resize(_op_num);
72  for (unsigned int j = 0; j < _op_num; ++j)
73  {
74  (*_dFdeta[i])[_qp][j](0) = _k * _c[_qp] * _force_x.value(_t, _q_point[_qp]);
75  (*_dFdeta[i])[_qp][j](1) = _k * _c[_qp] * _force_y.value(_t, _q_point[_qp]);
76  (*_dFdeta[i])[_qp][j](2) = _k * _c[_qp] * _force_z.value(_t, _q_point[_qp]);
77  }
78  }
79 }
MaterialProperty< std::vector< RealGradient > > & _dFdc
first order derivative of force density material w.r.t c
std::vector< VariableName > _vals_name
InputParameters validParams< ExternalForceDensityMaterial >()
ExternalForceDensityMaterial(const InputParameters &parameters)
const VariableValue & _c
concentration field considered to be the density of particles
const Real _k
stiffness constant
std::vector< MaterialProperty< std::vector< RealGradient > > * > _dFdeta
MaterialProperty< std::vector< RealGradient > > & _dF
force density material
std::vector< const VariableValue * > _vals