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