www.mooseframework.org
StressDivergenceTensorsTruss.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 /****************************************************************/
7 
9 
10 // MOOSE includes
11 #include "Assembly.h"
12 #include "Material.h"
13 #include "MooseVariable.h"
14 #include "SystemBase.h"
15 
16 template <>
17 InputParameters
19 {
20  InputParameters params = validParams<Kernel>();
21  params.addClassDescription("Kernel for truss element");
22  params.addRequiredParam<unsigned int>("component",
23  "An integer corresponding to the direction "
24  "the variable this kernel acts in. (0 for x, "
25  "1 for y, 2 for z)");
26  params.addCoupledVar("displacements",
27  "The string of displacements suitable for the problem statement");
28  params.addCoupledVar("temperature", "The temperature");
29  params.addCoupledVar("area", "Cross-sectional area of truss element");
30  params.addParam<std::string>("base_name", "Material property base name");
31  params.set<bool>("use_displaced_mesh") = true;
32  return params;
33 }
34 
36  : Kernel(parameters),
37  _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
38  _axial_stress(getMaterialPropertyByName<Real>(_base_name + "axial_stress")),
39  _e_over_l(getMaterialPropertyByName<Real>(_base_name + "e_over_l")),
40  _component(getParam<unsigned int>("component")),
41  _ndisp(coupledComponents("displacements")),
42  _temp_coupled(isCoupled("temperature")),
43  _temp_var(_temp_coupled ? coupled("temperature") : 0),
44  _area(coupledValue("area")),
45  _orientation(NULL)
46 {
47  for (unsigned int i = 0; i < _ndisp; ++i)
48  _disp_var.push_back(coupled("displacements", i));
49 }
50 
51 void
53 {
54  _orientation = &_subproblem.assembly(_tid).getFE(FEType(), 1)->get_dxyzdxi();
55 }
56 
57 void
59 {
60  DenseVector<Number> & re = _assembly.residualBlock(_var.number());
61  mooseAssert(re.size() == 2, "Truss element has and only has two nodes.");
62  _local_re.resize(re.size());
63  _local_re.zero();
64 
65  RealGradient orientation((*_orientation)[0]);
66  orientation /= orientation.norm();
67 
68  VectorValue<Real> force_local = _axial_stress[0] * _area[0] * orientation;
69 
70  _local_re(0) = -force_local(_component);
71  _local_re(1) = -_local_re(0);
72 
73  re += _local_re;
74 
75  if (_has_save_in)
76  {
77  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
78  for (unsigned int i = 0; i < _save_in.size(); ++i)
79  _save_in[i]->sys().solution().add_vector(_local_re, _save_in[i]->dofIndices());
80  }
81 }
82 
83 Real
84 StressDivergenceTensorsTruss::computeStiffness(unsigned int i, unsigned int j)
85 {
86  RealGradient orientation((*_orientation)[0]);
87  orientation /= orientation.norm();
88 
89  return orientation(i) * orientation(j) * _e_over_l[0] * _area[0];
90 }
91 
92 void
94 {
95  DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), _var.number());
96  _local_ke.resize(ke.m(), ke.n());
97  _local_ke.zero();
98 
99  for (unsigned int i = 0; i < _test.size(); ++i)
100  for (unsigned int j = 0; j < _phi.size(); ++j)
101  _local_ke(i, j) += (i == j ? 1 : -1) * computeStiffness(_component, _component);
102 
103  ke += _local_ke;
104 
105  if (_has_diag_save_in)
106  {
107  unsigned int rows = ke.m();
108  DenseVector<Number> diag(rows);
109  for (unsigned int i = 0; i < rows; ++i)
110  diag(i) = _local_ke(i, i);
111 
112  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
113  for (unsigned int i = 0; i < _diag_save_in.size(); ++i)
114  _diag_save_in[i]->sys().solution().add_vector(diag, _diag_save_in[i]->dofIndices());
115  }
116 }
117 
118 void
120 {
121  if (jvar == _var.number())
122  computeJacobian();
123  else
124  {
125  unsigned int coupled_component = 0;
126  bool disp_coupled = false;
127 
128  for (unsigned int i = 0; i < _ndisp; ++i)
129  if (jvar == _disp_var[i])
130  {
131  coupled_component = i;
132  disp_coupled = true;
133  break;
134  }
135 
136  DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar);
137 
138  if (disp_coupled)
139  for (unsigned int i = 0; i < _test.size(); ++i)
140  for (unsigned int j = 0; j < _phi.size(); ++j)
141  ke(i, j) += (i == j ? 1 : -1) * computeStiffness(_component, coupled_component);
142  else if (false) // Need some code here for coupling with temperature
143  {
144  }
145  }
146 }
StressDivergenceTensorsTruss(const InputParameters &parameters)
virtual Real computeStiffness(unsigned int i, unsigned int j)
const std::vector< RealGradient > * _orientation
virtual void computeOffDiagJacobian(unsigned int jvar)
std::vector< unsigned int > _disp_var
const MaterialProperty< Real > & _axial_stress
const MaterialProperty< Real > & _e_over_l
InputParameters validParams< StressDivergenceTensorsTruss >()