www.mooseframework.org
SymmElasticityTensor.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 "SymmElasticityTensor.h"
11 #include <vector>
12 
13 template <>
14 void
15 dataStore(std::ostream & stream, SymmElasticityTensor & set, void * context)
16 {
17  dataStore(stream, set._constant, context);
18  dataStore(stream, set._values_computed, context);
19  dataStore(stream, set._val, context);
20 }
21 
22 template <>
23 void
24 dataLoad(std::istream & stream, SymmElasticityTensor & set, void * context)
25 {
26  dataLoad(stream, set._constant, context);
27  dataLoad(stream, set._values_computed, context);
28  dataLoad(stream, set._val, context);
29 }
30 
32  : _constant(constant), _values_computed(false)
33 {
34  for (unsigned i(0); i < 21; ++i)
35  {
36  _val[i] = 0;
37  }
38 }
39 
40 void
42 {
43  if (!_constant || !_values_computed)
44  {
45  calculateEntries(qp);
46  _values_computed = true;
47  }
48 }
49 
50 void
52 {
53 }
54 
55 void
57 {
58  const Real xx = x.xx();
59  const Real yy = x.yy();
60  const Real zz = x.zz();
61  const Real xy = x.xy();
62  const Real yz = x.yz();
63  const Real zx = x.zx();
64 
65  b.xx() =
66  _val[0] * xx + _val[1] * yy + _val[2] * zz + 2 * (_val[3] * xy + _val[4] * yz + _val[5] * zx);
67  b.yy() = _val[1] * xx + _val[6] * yy + _val[7] * zz +
68  2 * (_val[8] * xy + _val[9] * yz + _val[10] * zx);
69  b.zz() = _val[2] * xx + _val[7] * yy + _val[11] * zz +
70  2 * (_val[12] * xy + _val[13] * yz + _val[14] * zx);
71  b.xy() = _val[3] * xx + _val[8] * yy + _val[12] * zz +
72  2 * (_val[15] * xy + _val[16] * yz + _val[17] * zx);
73  b.yz() = _val[4] * xx + _val[9] * yy + _val[13] * zz +
74  2 * (_val[16] * xy + _val[18] * yz + _val[19] * zx);
75  b.zx() = _val[5] * xx + _val[10] * yy + _val[14] * zz +
76  2 * (_val[17] * xy + _val[19] * yz + _val[20] * zx);
77 }
78 
80 {
81  SymmTensor b;
82  multiply(x, b);
83  return b;
84 }
85 
86 Real
87 SymmElasticityTensor::stiffness(const unsigned int i,
88  const unsigned int j,
89  const RealGradient & test,
90  const RealGradient & phi) const
91 {
92  RealGradient b;
93  if (0 == i && 0 == j)
94  {
95  b(0) = _val[0] * phi(0) + _val[3] * phi(1) + _val[5] * phi(2);
96  b(1) = _val[3] * phi(0) + _val[15] * phi(1) + _val[17] * phi(2);
97  b(2) = _val[5] * phi(0) + _val[17] * phi(1) + _val[20] * phi(2);
98  }
99  else if (1 == i && 1 == j)
100  {
101  b(0) = _val[15] * phi(0) + _val[8] * phi(1) + _val[16] * phi(2);
102  b(1) = _val[8] * phi(0) + _val[6] * phi(1) + _val[9] * phi(2);
103  b(2) = _val[16] * phi(0) + _val[9] * phi(1) + _val[18] * phi(2);
104  }
105  else if (2 == i && 2 == j)
106  {
107  b(0) = _val[20] * phi(0) + _val[19] * phi(1) + _val[14] * phi(2);
108  b(1) = _val[19] * phi(0) + _val[18] * phi(1) + _val[13] * phi(2);
109  b(2) = _val[14] * phi(0) + _val[13] * phi(1) + _val[11] * phi(2);
110  }
111  else if (0 == i && 1 == j)
112  {
113  b(0) = _val[3] * phi(0) + _val[1] * phi(1) + _val[4] * phi(2);
114  b(1) = _val[15] * phi(0) + _val[8] * phi(1) + _val[16] * phi(2);
115  b(2) = _val[17] * phi(0) + _val[10] * phi(1) + _val[19] * phi(2);
116  }
117  else if (1 == i && 0 == j)
118  {
119  b(0) = _val[3] * phi(0) + _val[15] * phi(1) + _val[17] * phi(2);
120  b(1) = _val[1] * phi(0) + _val[8] * phi(1) + _val[10] * phi(2);
121  b(2) = _val[4] * phi(0) + _val[16] * phi(1) + _val[19] * phi(2);
122  }
123  else if (1 == i && 2 == j)
124  {
125  b(0) = _val[17] * phi(0) + _val[16] * phi(1) + _val[12] * phi(2);
126  b(1) = _val[10] * phi(0) + _val[9] * phi(1) + _val[7] * phi(2);
127  b(2) = _val[19] * phi(0) + _val[18] * phi(1) + _val[13] * phi(2);
128  }
129  else if (2 == i && 1 == j)
130  {
131  b(0) = _val[17] * phi(0) + _val[10] * phi(1) + _val[19] * phi(2);
132  b(1) = _val[16] * phi(0) + _val[9] * phi(1) + _val[18] * phi(2);
133  b(2) = _val[12] * phi(0) + _val[7] * phi(1) + _val[13] * phi(2);
134  }
135  else if (0 == i && 2 == j)
136  {
137  b(0) = _val[5] * phi(0) + _val[4] * phi(1) + _val[2] * phi(2);
138  b(1) = _val[17] * phi(0) + _val[16] * phi(1) + _val[12] * phi(2);
139  b(2) = _val[20] * phi(0) + _val[19] * phi(1) + _val[14] * phi(2);
140  }
141  else if (2 == i && 0 == j)
142  {
143  b(0) = _val[5] * phi(0) + _val[17] * phi(1) + _val[20] * phi(2);
144  b(1) = _val[4] * phi(0) + _val[16] * phi(1) + _val[19] * phi(2);
145  b(2) = _val[2] * phi(0) + _val[12] * phi(1) + _val[14] * phi(2);
146  }
147  else
148  {
149  std::stringstream s;
150  s << "Wrong index in stiffness calculation: ";
151  s << i << " " << j;
152  mooseError(s.str());
153  }
154  return test * b;
155 }
156 
157 void
158 SymmElasticityTensor::convertFrom9x9(const ColumnMajorMatrix & input)
159 {
160  if (input.numEntries() != 81)
161  {
162  mooseError("Cannot convert from ColumnMajorMatrix (wrong size)");
163  }
164 
165  _val[0] = input(0, 0);
166  _val[1] = input(0, 4);
167  _val[2] = input(0, 8);
168  _val[3] = input(0, 1);
169  _val[4] = input(0, 5);
170  _val[5] = input(0, 2);
171 
172  _val[6] = input(4, 4);
173  _val[7] = input(4, 8);
174  _val[8] = input(4, 3);
175  _val[9] = input(4, 5);
176  _val[10] = input(4, 6);
177 
178  _val[11] = input(8, 8);
179  _val[12] = input(8, 3);
180  _val[13] = input(8, 5);
181  _val[14] = input(8, 6);
182 
183  _val[15] = input(1, 1);
184  _val[16] = input(1, 5);
185  _val[17] = input(1, 2);
186 
187  _val[18] = input(5, 5);
188  _val[19] = input(5, 6);
189 
190  _val[20] = input(2, 2);
191 }
192 
193 void
194 SymmElasticityTensor::convertFrom6x6(const ColumnMajorMatrix & input)
195 {
196  if (input.numEntries() != 36)
197  {
198  mooseError("Cannot convert from ColumnMajorMatrix (wrong size)");
199  }
200 
201  _val[0] = input(0, 0);
202  _val[1] = input(0, 1);
203  _val[2] = input(0, 2);
204  _val[3] = input(0, 3);
205  _val[4] = input(0, 4);
206  _val[5] = input(0, 5);
207 
208  _val[6] = input(1, 1);
209  _val[7] = input(1, 2);
210  _val[8] = input(1, 3);
211  _val[9] = input(1, 4);
212  _val[10] = input(1, 5);
213 
214  _val[11] = input(2, 2);
215  _val[12] = input(2, 3);
216  _val[13] = input(2, 4);
217  _val[14] = input(2, 5);
218 
219  _val[15] = input(3, 3);
220  _val[16] = input(3, 4);
221  _val[17] = input(3, 5);
222 
223  _val[18] = input(4, 4);
224  _val[19] = input(4, 5);
225 
226  _val[20] = input(5, 5);
227 }
228 
229 ColumnMajorMatrix
231 {
232  ColumnMajorMatrix cmm(6, 6);
233  unsigned count(0);
234  for (unsigned i(0); i < 6; ++i)
235  {
236  for (unsigned j(i); j < 6; ++j)
237  {
238  cmm(i, j) = cmm(j, i) = _val[count++];
239  }
240  }
241  return cmm;
242 }
243 
244 ColumnMajorMatrix
246 {
247  ColumnMajorMatrix cmm(9, 9);
248  cmm(0, 0) = _val[0];
249  cmm(0, 1) = cmm(1, 0) = _val[3];
250  cmm(0, 2) = cmm(2, 0) = _val[5];
251  cmm(0, 3) = cmm(3, 0) = _val[3];
252  cmm(0, 4) = cmm(4, 0) = _val[1];
253  cmm(0, 5) = cmm(5, 0) = _val[4];
254  cmm(0, 6) = cmm(6, 0) = _val[5];
255  cmm(0, 7) = cmm(7, 0) = _val[4];
256  cmm(0, 8) = cmm(8, 0) = _val[2];
257 
258  cmm(1, 1) = _val[15];
259  cmm(1, 2) = cmm(2, 1) = _val[17];
260  cmm(1, 3) = cmm(3, 1) = _val[15];
261  cmm(1, 4) = cmm(4, 1) = _val[8];
262  cmm(1, 5) = cmm(5, 1) = _val[16];
263  cmm(1, 6) = cmm(6, 1) = _val[17];
264  cmm(1, 7) = cmm(7, 1) = _val[16];
265  cmm(1, 8) = cmm(8, 1) = _val[12];
266 
267  cmm(2, 2) = _val[20];
268  cmm(2, 3) = cmm(3, 2) = _val[17];
269  cmm(2, 4) = cmm(4, 2) = _val[10];
270  cmm(2, 5) = cmm(5, 2) = _val[19];
271  cmm(2, 6) = cmm(6, 2) = _val[20];
272  cmm(2, 7) = cmm(7, 2) = _val[19];
273  cmm(2, 8) = cmm(8, 2) = _val[14];
274 
275  cmm(3, 3) = _val[15];
276  cmm(3, 4) = cmm(4, 3) = _val[8];
277  cmm(3, 5) = cmm(5, 3) = _val[16];
278  cmm(3, 6) = cmm(6, 3) = _val[17];
279  cmm(3, 7) = cmm(7, 3) = _val[16];
280  cmm(3, 8) = cmm(8, 3) = _val[12];
281 
282  cmm(4, 4) = _val[6];
283  cmm(4, 5) = cmm(5, 4) = _val[9];
284  cmm(4, 6) = cmm(6, 4) = _val[10];
285  cmm(4, 7) = cmm(7, 4) = _val[9];
286  cmm(4, 8) = cmm(8, 4) = _val[7];
287 
288  cmm(5, 5) = _val[18];
289  cmm(5, 6) = cmm(6, 5) = _val[19];
290  cmm(5, 7) = cmm(7, 5) = _val[18];
291  cmm(5, 8) = cmm(8, 5) = _val[13];
292 
293  cmm(6, 6) = _val[20];
294  cmm(6, 7) = cmm(7, 6) = _val[19];
295  cmm(6, 8) = cmm(8, 6) = _val[14];
296 
297  cmm(7, 7) = _val[18];
298  cmm(7, 8) = cmm(8, 7) = _val[13];
299 
300  cmm(8, 8) = _val[11];
301 
302  return cmm;
303 }
304 
305 std::ostream &
306 operator<<(std::ostream & stream, const SymmElasticityTensor & obj)
307 {
308  stream << "SymmElasticityTensor:\n"
309  << std::setprecision(6) << std::setw(13) << obj._val[0] << "\t" << std::setw(13)
310  << obj._val[1] << "\t" << std::setw(13) << obj._val[2] << "\t" << std::setw(13)
311  << obj._val[3] << "\t" << std::setw(13) << obj._val[4] << "\t" << std::setw(13)
312  << obj._val[5] << "\n"
313  << "\t\t" << std::setw(13) << obj._val[6] << "\t" << std::setw(13) << obj._val[7] << "\t"
314  << std::setw(13) << obj._val[8] << "\t" << std::setw(13) << obj._val[9] << "\t"
315  << std::setw(13) << obj._val[10] << "\n"
316  << "\t\t\t\t" << std::setw(13) << obj._val[11] << "\t" << std::setw(13) << obj._val[12]
317  << "\t" << std::setw(13) << obj._val[13] << "\t" << std::setw(13) << obj._val[14] << "\n"
318  << "\t\t\t\t\t\t" << std::setw(13) << obj._val[15] << "\t" << std::setw(13) << obj._val[16]
319  << "\t" << std::setw(13) << obj._val[17] << "\t"
320  << "\n"
321  << "\t\t\t\t\t\t\t\t" << std::setw(13) << obj._val[18] << "\t" << std::setw(13)
322  << obj._val[19] << "\n"
323  << "\t\t\t\t\t\t\t\t\t\t" << std::setw(13) << obj._val[20] << std::endl;
324  return stream;
325 }
326 
328 SymmElasticityTensor::calculateDerivative(unsigned int /*qp*/, unsigned int /*i*/)
329 {
330  return SymmElasticityTensor();
331 }
332 
334 {
335  SymmElasticityTensor fred(*this);
336  fred *= x;
337  return fred;
338 }
339 
340 void
341 SymmElasticityTensor::form9x9Rotation(const ColumnMajorMatrix & R_3x3,
342  ColumnMajorMatrix & R_9x9) const
343 {
344  for (int i = 0; i < 3; ++i)
345  {
346  for (int j = 0; j < 3; ++j)
347  {
348  for (int k = 0; k < 3; ++k)
349  {
350  for (int l = 0; l < 3; ++l)
351  {
352  R_9x9(((i * 3) + k), ((j * 3) + l)) = R_3x3(i, j) * R_3x3(k, l);
353  }
354  }
355  }
356  }
357 }
358 
359 void
361 {
362  convertFrom9x9((R * columnMajorMatrix9x9()) * R.transpose());
363 }
364 
365 void
367 {
368  convertFrom9x9(R.transpose() * (columnMajorMatrix9x9() * R));
369 }
370 
371 void
372 SymmElasticityTensor::adjustForCracking(const RealVectorValue & /*crack_flags*/)
373 {
374  mooseError("adjustForCracking method not defined");
375 }
376 
377 void
378 SymmElasticityTensor::adjustForCrackingWithShearRetention(const RealVectorValue & /*crack_flags*/)
379 {
380  mooseError("adjustForCrackingWithShearRetention method not defined");
381 }
382 
383 void
384 SymmElasticityTensor::fillFromInputVector(std::vector<Real> input, bool all)
385 {
386  if ((all == true && input.size() != 21) || (all == false && input.size() != 9))
387  mooseError("Please check the number of entries in the stiffness input vector.");
388 
389  if (all == true)
390  {
391  for (int i = 0; i < 21; i++)
392  _val[i] = input[i];
393  }
394  else
395  {
396  _val[0] = input[0]; // C1111
397  _val[1] = input[1]; // C1122
398  _val[2] = input[2]; // C1133
399  _val[6] = input[3]; // C2222
400  _val[7] = input[4]; // C2233
401  _val[11] = input[5]; // C3333
402  _val[15] = input[6]; // C2323
403  _val[18] = input[7]; // C1313
404  _val[20] = input[8]; // C1212
405  }
406 }
407 
408 Real
410 {
411  return _val[i];
412 }
413 
414 Real
416 {
417  // summation of Cij for i and j ranging from 0 to 2 - used in the volumetric locking correction
418  return _val[0] + 2 * (_val[1] + _val[2] + _val[7]) + _val[6] + _val[11];
419 }
420 
423 {
424  // used for volumetric locking correction
425  RealGradient a(3);
426  a(0) = _val[0] + _val[1] + _val[2]; // C00 + C01 + C02
427  a(1) = _val[1] + _val[6] + _val[7]; // C10 + C11 + C12
428  a(2) = _val[2] + _val[7] + _val[11]; // C20 + C21 + C22
429  return a;
430 }
SymmElasticityTensor.h
SymmTensor::xx
Real xx() const
Definition: SymmTensor.h:131
SymmElasticityTensor::calculate
void calculate(unsigned int qp)
Public function that will be called whenever the values for this matrix need to be filled in.
Definition: SymmElasticityTensor.C:41
SymmElasticityTensor::rotateFromLocalToGlobal
void rotateFromLocalToGlobal(const ColumnMajorMatrix &R)
Definition: SymmElasticityTensor.C:360
SymmTensor::zx
Real zx() const
Definition: SymmTensor.h:136
SymmElasticityTensor::convertFrom9x9
void convertFrom9x9(const ColumnMajorMatrix &cmm)
Definition: SymmElasticityTensor.C:158
SymmElasticityTensor::sum_3x3
Real sum_3x3() const
Definition: SymmElasticityTensor.C:415
SymmElasticityTensor::valueAtIndex
Real valueAtIndex(int i) const
Definition: SymmElasticityTensor.C:409
SymmElasticityTensor::multiply
virtual void multiply(const SymmTensor &x, SymmTensor &b) const
Definition: SymmElasticityTensor.C:56
SymmTensor::zz
Real zz() const
Definition: SymmTensor.h:133
SymmElasticityTensor::rotateFromGlobalToLocal
void rotateFromGlobalToLocal(const ColumnMajorMatrix &R)
Definition: SymmElasticityTensor.C:366
operator<<
std::ostream & operator<<(std::ostream &stream, const SymmElasticityTensor &obj)
Definition: SymmElasticityTensor.C:306
libMesh::RealGradient
VectorValue< Real > RealGradient
Definition: GrainForceAndTorqueInterface.h:17
SymmElasticityTensor::_values_computed
bool _values_computed
Whether or not the values have been computed once.
Definition: SymmElasticityTensor.h:178
SymmElasticityTensor::adjustForCracking
virtual void adjustForCracking(const RealVectorValue &crack_flags)
Definition: SymmElasticityTensor.C:372
SymmElasticityTensor::form9x9Rotation
void form9x9Rotation(const ColumnMajorMatrix &R_3x3, ColumnMajorMatrix &R_9x9) const
Definition: SymmElasticityTensor.C:341
SymmElasticityTensor::stiffness
virtual Real stiffness(const unsigned int i, const unsigned int j, const RealGradient &test, const RealGradient &phi) const
Definition: SymmElasticityTensor.C:87
SymmElasticityTensor::adjustForCrackingWithShearRetention
virtual void adjustForCrackingWithShearRetention(const RealVectorValue &crack_flags)
Definition: SymmElasticityTensor.C:378
SymmTensor::xy
Real xy() const
Definition: SymmTensor.h:134
SymmElasticityTensor::convertFrom6x6
void convertFrom6x6(const ColumnMajorMatrix &cmm)
Definition: SymmElasticityTensor.C:194
SymmElasticityTensor
This class defines a basic set of capabilities any elasticity tensor should have.
Definition: SymmElasticityTensor.h:55
SymmElasticityTensor::SymmElasticityTensor
SymmElasticityTensor(const bool constant=false)
Default constructor...
Definition: SymmElasticityTensor.C:31
SymmTensor::yz
Real yz() const
Definition: SymmTensor.h:135
dataLoad
void dataLoad(std::istream &stream, SymmElasticityTensor &set, void *context)
Definition: SymmElasticityTensor.C:24
SymmElasticityTensor::_constant
bool _constant
Whether or not the matrix is constant for all of time and space.
Definition: SymmElasticityTensor.h:173
SymmTensor
Definition: SymmTensor.h:21
dataStore
void dataStore(std::ostream &stream, SymmElasticityTensor &set, void *context)
Definition: SymmElasticityTensor.C:15
SymmElasticityTensor::calculateDerivative
virtual SymmElasticityTensor calculateDerivative(unsigned int qp, unsigned int i)
Definition: SymmElasticityTensor.C:328
SymmElasticityTensor::calculateEntries
virtual void calculateEntries(unsigned int qp)
Virtual (must be overriden by derived class).
Definition: SymmElasticityTensor.C:51
SymmElasticityTensor::columnMajorMatrix6x6
ColumnMajorMatrix columnMajorMatrix6x6() const
Definition: SymmElasticityTensor.C:230
SymmTensor::yy
Real yy() const
Definition: SymmTensor.h:132
SymmElasticityTensor::_val
Real _val[21]
Definition: SymmElasticityTensor.h:188
SymmElasticityTensor::fillFromInputVector
void fillFromInputVector(std::vector< Real > input, bool all)
Definition: SymmElasticityTensor.C:384
SymmElasticityTensor::sum_3x1
RealGradient sum_3x1() const
Definition: SymmElasticityTensor.C:422
SymmElasticityTensor::operator*
SymmTensor operator*(const SymmTensor &x) const
Definition: SymmElasticityTensor.C:79
SymmElasticityTensor::columnMajorMatrix9x9
ColumnMajorMatrix columnMajorMatrix9x9() const
Definition: SymmElasticityTensor.C:245