www.mooseframework.org
StressDivergenceTensorsTruss.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 
11 
12 // MOOSE includes
13 #include "Assembly.h"
14 #include "Material.h"
15 #include "MooseVariable.h"
16 #include "SystemBase.h"
17 
19 
22 {
24  params.addClassDescription("Kernel for truss element");
25  params.addRequiredParam<unsigned int>("component",
26  "An integer corresponding to the direction "
27  "the variable this kernel acts in. (0 for x, "
28  "1 for y, 2 for z)");
29  params.addCoupledVar("displacements",
30  "The string of displacements suitable for the problem statement");
31  params.addCoupledVar("temperature", "The temperature");
32  params.addCoupledVar("area", "Cross-sectional area of truss element");
33  params.addParam<std::string>("base_name", "Material property base name");
34  params.set<bool>("use_displaced_mesh") = true;
35  return params;
36 }
37 
39  : Kernel(parameters),
40  _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
41  _axial_stress(getMaterialPropertyByName<Real>(_base_name + "axial_stress")),
42  _e_over_l(getMaterialPropertyByName<Real>(_base_name + "e_over_l")),
43  _component(getParam<unsigned int>("component")),
44  _ndisp(coupledComponents("displacements")),
45  _temp_coupled(isCoupled("temperature")),
46  _temp_var(_temp_coupled ? coupled("temperature") : 0),
47  _area(coupledValue("area")),
48  _orientation(NULL)
49 {
50  for (unsigned int i = 0; i < _ndisp; ++i)
51  _disp_var.push_back(coupled("displacements", i));
52 }
53 
54 void
56 {
57  _orientation = &_subproblem.assembly(_tid, _sys.number()).getFE(FEType(), 1)->get_dxyzdxi();
58 }
59 
60 void
62 {
64 
65  mooseAssert(_local_re.size() == 2, "Truss element has and only has two nodes.");
66 
68  orientation /= orientation.norm();
69 
70  VectorValue<Real> force_local = _axial_stress[0] * _area[0] * orientation;
71 
72  _local_re(0) = -force_local(_component);
73  _local_re(1) = -_local_re(0);
74 
76 
77  if (_has_save_in)
78  {
79  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
80  for (unsigned int i = 0; i < _save_in.size(); ++i)
81  _save_in[i]->sys().solution().add_vector(_local_re, _save_in[i]->dofIndices());
82  }
83 }
84 
85 Real
87 {
89  orientation /= orientation.norm();
90 
91  return orientation(i) * orientation(j) * _e_over_l[0] * _area[0];
92 }
93 
94 void
96 {
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 
104 
105  if (_has_diag_save_in)
106  {
107  unsigned int rows = _local_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_num == _var.number())
122  computeJacobian();
123  else
124  {
125  const auto & jvar = getVariable(jvar_num);
126 
127  // This (undisplaced) jvar could potentially yield the wrong phi size if this object is acting
128  // on the displaced mesh
129  auto phi_size = jvar.dofIndices().size();
130 
131  unsigned int coupled_component = 0;
132  bool disp_coupled = false;
133 
134  for (unsigned int i = 0; i < _ndisp; ++i)
135  if (jvar_num == _disp_var[i])
136  {
137  coupled_component = i;
138  disp_coupled = true;
139  break;
140  }
141 
142  if (disp_coupled)
143  {
144  prepareMatrixTag(_assembly, _var.number(), jvar_num);
145 
146  for (unsigned int i = 0; i < _test.size(); ++i)
147  for (unsigned int j = 0; j < phi_size; ++j)
148  _local_ke(i, j) += (i == j ? 1 : -1) * computeStiffness(_component, coupled_component);
149 
151  }
152  else if (false) // Need some code here for coupling with temperature
153  {
154  }
155  }
156 }
const unsigned int _ndisp
Number of displacement variables.
registerMooseObject("SolidMechanicsApp", StressDivergenceTensorsTruss)
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
static InputParameters validParams()
void accumulateTaggedLocalResidual()
MooseVariable & _var
std::vector< MooseVariableFEBase *> _save_in
StressDivergenceTensorsTruss(const InputParameters &parameters)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int number() const
T & set(const std::string &name, bool quiet_mode=false)
unsigned int m() const
virtual Real computeStiffness(unsigned int i, unsigned int j)
THREAD_ID _tid
bool _has_diag_save_in
DenseMatrix< Number > _local_ke
const unsigned int _component
An integer corresponding to the direction this kernel acts in.
const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
SystemBase & _sys
const VariableTestValue & _test
virtual void computeOffDiagJacobian(unsigned int jvar) override
const std::vector< RealGradient > * _orientation
std::vector< MooseVariableFEBase *> _diag_save_in
SubProblem & _subproblem
bool _has_save_in
unsigned int number() const
void accumulateTaggedLocalMatrix()
Assembly & _assembly
void addCoupledVar(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num)=0
DenseVector< Number > _local_re
std::vector< unsigned int > _disp_var
Variable numbers of coupled displacement variables.
const MaterialProperty< Real > & _axial_stress
virtual unsigned int size() const override final
void addClassDescription(const std::string &doc_string)
const MaterialProperty< Real > & _e_over_l
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
void prepareMatrixTag(Assembly &assembly, unsigned int ivar, unsigned int jvar)
const VariablePhiValue & _phi
bool orientation(std::array< Point, N > &arr)
void ErrorVector unsigned int