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 
21 
22 InputParameters
24 {
25  InputParameters params = Kernel::validParams();
26  params.addClassDescription("Kernel for truss element");
27  params.addRequiredParam<unsigned int>("component",
28  "An integer corresponding to the direction "
29  "the variable this kernel acts in. (0 for x, "
30  "1 for y, 2 for z)");
31  params.addCoupledVar("displacements",
32  "The string of displacements suitable for the problem statement");
33  params.addCoupledVar("temperature", "The temperature");
34  params.addCoupledVar("area", "Cross-sectional area of truss element");
35  params.addParam<std::string>("base_name", "Material property base name");
36  params.set<bool>("use_displaced_mesh") = true;
37  return params;
38 }
39 
41  : Kernel(parameters),
42  _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
43  _axial_stress(getMaterialPropertyByName<Real>(_base_name + "axial_stress")),
44  _e_over_l(getMaterialPropertyByName<Real>(_base_name + "e_over_l")),
45  _component(getParam<unsigned int>("component")),
46  _ndisp(coupledComponents("displacements")),
47  _temp_coupled(isCoupled("temperature")),
48  _temp_var(_temp_coupled ? coupled("temperature") : 0),
49  _area(coupledValue("area")),
50  _orientation(NULL)
51 {
52  for (unsigned int i = 0; i < _ndisp; ++i)
53  _disp_var.push_back(coupled("displacements", i));
54 }
55 
56 void
58 {
59  _orientation = &_subproblem.assembly(_tid).getFE(FEType(), 1)->get_dxyzdxi();
60 }
61 
62 void
64 {
65  prepareVectorTag(_assembly, _var.number());
66 
67  mooseAssert(_local_re.size() == 2, "Truss element has and only has two nodes.");
68 
69  RealGradient orientation((*_orientation)[0]);
70  orientation /= orientation.norm();
71 
72  VectorValue<Real> force_local = _axial_stress[0] * _area[0] * orientation;
73 
74  _local_re(0) = -force_local(_component);
75  _local_re(1) = -_local_re(0);
76 
77  accumulateTaggedLocalResidual();
78 
79  if (_has_save_in)
80  {
81  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
82  for (unsigned int i = 0; i < _save_in.size(); ++i)
83  _save_in[i]->sys().solution().add_vector(_local_re, _save_in[i]->dofIndices());
84  }
85 }
86 
87 Real
88 StressDivergenceTensorsTruss::computeStiffness(unsigned int i, unsigned int j)
89 {
90  RealGradient orientation((*_orientation)[0]);
91  orientation /= orientation.norm();
92 
93  return orientation(i) * orientation(j) * _e_over_l[0] * _area[0];
94 }
95 
96 void
98 {
99  prepareMatrixTag(_assembly, _var.number(), _var.number());
100 
101  for (unsigned int i = 0; i < _test.size(); ++i)
102  for (unsigned int j = 0; j < _phi.size(); ++j)
103  _local_ke(i, j) += (i == j ? 1 : -1) * computeStiffness(_component, _component);
104 
105  accumulateTaggedLocalMatrix();
106 
107  if (_has_diag_save_in)
108  {
109  unsigned int rows = _local_ke.m();
110  DenseVector<Number> diag(rows);
111  for (unsigned int i = 0; i < rows; ++i)
112  diag(i) = _local_ke(i, i);
113 
114  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
115  for (unsigned int i = 0; i < _diag_save_in.size(); ++i)
116  _diag_save_in[i]->sys().solution().add_vector(diag, _diag_save_in[i]->dofIndices());
117  }
118 }
119 
120 void
122 {
123  size_t jvar_num = jvar.number();
124  if (jvar_num == _var.number())
125  computeJacobian();
126  else
127  {
128  // This (undisplaced) jvar could potentially yield the wrong phi size if this object is acting
129  // on the displaced mesh
130  auto phi_size = _sys.getVariable(_tid, jvar.number()).dofIndices().size();
131 
132  unsigned int coupled_component = 0;
133  bool disp_coupled = false;
134 
135  for (unsigned int i = 0; i < _ndisp; ++i)
136  if (jvar_num == _disp_var[i])
137  {
138  coupled_component = i;
139  disp_coupled = true;
140  break;
141  }
142 
143  if (disp_coupled)
144  {
145  prepareMatrixTag(_assembly, _var.number(), jvar_num);
146 
147  for (unsigned int i = 0; i < _test.size(); ++i)
148  for (unsigned int j = 0; j < phi_size; ++j)
149  _local_ke(i, j) += (i == j ? 1 : -1) * computeStiffness(_component, coupled_component);
150 
151  accumulateTaggedLocalMatrix();
152  }
153  else if (false) // Need some code here for coupling with temperature
154  {
155  }
156  }
157 }
StressDivergenceTensorsTruss::computeStiffness
virtual Real computeStiffness(unsigned int i, unsigned int j)
Definition: StressDivergenceTensorsTruss.C:88
StressDivergenceTensorsTruss
Definition: StressDivergenceTensorsTruss.h:20
libMesh::RealGradient
VectorValue< Real > RealGradient
Definition: GrainForceAndTorqueInterface.h:17
StressDivergenceTensorsTruss::computeResidual
virtual void computeResidual() override
Definition: StressDivergenceTensorsTruss.C:63
StressDivergenceTensorsTruss::validParams
static InputParameters validParams()
Definition: StressDivergenceTensorsTruss.C:23
StressDivergenceTensorsTruss::initialSetup
virtual void initialSetup() override
Definition: StressDivergenceTensorsTruss.C:57
StressDivergenceTensorsTruss.h
StressDivergenceTensorsTruss::_component
const unsigned int _component
Definition: StressDivergenceTensorsTruss.h:42
StressDivergenceTensorsTruss::computeOffDiagJacobian
virtual void computeOffDiagJacobian(MooseVariableFEBase &jvar) override
Definition: StressDivergenceTensorsTruss.C:121
StressDivergenceTensorsTruss::computeJacobian
virtual void computeJacobian() override
Definition: StressDivergenceTensorsTruss.C:97
StressDivergenceTensorsTruss::_disp_var
std::vector< unsigned int > _disp_var
Definition: StressDivergenceTensorsTruss.h:47
registerMooseObject
registerMooseObject("TensorMechanicsApp", StressDivergenceTensorsTruss)
StressDivergenceTensorsTruss::_ndisp
const unsigned int _ndisp
Definition: StressDivergenceTensorsTruss.h:43
validParams
InputParameters validParams()
StressDivergenceTensorsTruss::_e_over_l
const MaterialProperty< Real > & _e_over_l
Definition: StressDivergenceTensorsTruss.h:39
StressDivergenceTensorsTruss::_axial_stress
const MaterialProperty< Real > & _axial_stress
Definition: StressDivergenceTensorsTruss.h:38
defineLegacyParams
defineLegacyParams(StressDivergenceTensorsTruss)
StressDivergenceTensorsTruss::_orientation
const std::vector< RealGradient > * _orientation
Definition: StressDivergenceTensorsTruss.h:50
StressDivergenceTensorsTruss::_area
const VariableValue & _area
Definition: StressDivergenceTensorsTruss.h:49
StressDivergenceTensorsTruss::StressDivergenceTensorsTruss
StressDivergenceTensorsTruss(const InputParameters &parameters)
Definition: StressDivergenceTensorsTruss.C:40