muMECH  1.0
homogenization.cpp
Go to the documentation of this file.
1 //********************************************************************************************************
2 // code: ### ### ##### #### ## ##
3 // ## ## ######## ## ## ## ## ##
4 // ## ## ## ## ## ### ## ######
5 // ## ## ## ## ## ## ## ## ##
6 // ##### ## ## ##### #### ## ##
7 // ##
8 //
9 // name: homogenization.cpp
10 // author(s): Jan Vorel, Ladislav Svoboda
11 // language: C, C++
12 // license: This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 //********************************************************************************************************
26 
27 // toto je kvuli WIN32_LEAN_AND_MEAN
28 #include "types.h"
29 
30 #include "homogenization.h"
31 #include "problem.h"
32 #include "mesh.h"
33 #include "mnode.h"
34 #include "melement.h"
35 #include "elementaryFunctions.h"
36 #include "matrixOperations.h"
37 
38 
39 namespace mumech {
40 
41 
44 {
45  id = i;
46  P = p; if (p == NULL) _errorr("Problem not defined");
47  volume = -1;
48  inside = new bool[p->noIncl];
49  for (long i=0; i<p->noIncl; i++) inside[i] = true;
50 }
51 
52 
55 {
56  P = NULL; // do not deleta, this is only pointer to problem allocated upper
57  delete [] inside;
58 }
59 
60 
61 void
62 Homogenization :: set_boundingBox (double x1, double y1, double x2, double y2)
63 {
64  P->check_dim(2);
65  bb1[0] = x1; bb1[1] = y1; bb1[2] = 0.0;
66  bb2[0] = x2; bb2[1] = y2; bb2[2] = 0.0;
67 }
68 void
69 Homogenization :: set_boundingBox (double x1, double y1, double z1, double x2, double y2, double z2)
70 {
71  P->check_dim(3);
72  bb1[0] = x1; bb1[1] = y1; bb1[2] = z1;
73  bb2[0] = x2; bb2[1] = y2; bb2[2] = z2;
74 }
75 void
76 Homogenization :: set_boundingBox (const double *p1, const double *p2)
77 {
78  bb1[0] = p1[0]; bb1[1] = p1[1]; bb1[2] = p1[2];
79  bb2[0] = p2[0]; bb2[1] = p2[1]; bb2[2] = p2[2];
80 }
81 
82 void
84 {
85  for (int i=0; i<P->noIncl; i++)
87 }
88 
89 
90 // Functions to approach Problem Properties
91 int
93 {
94  return P->noIncl;
95 }
96 
98 {
99  if( P->give_twodim() ) return PT_2D;
100  else return PT_3D;
101 }
102 
103 int
105 {
106  return P->give_VM_TENS_RANGE();
107 }
108 
109 int
111 {
112  return P->give_ISO_C_RANGE();
113 }
114 
115 int
117 {
118  return P->give_VM_TENS_RANGE();
119 }
120 
121 double
123 {
124  if (volume < 0) {
125  if (P->give_twodim()) ((Homogenization*)this)->volume = (bb2[0]-bb1[0])*(bb2[1]-bb1[1]);
126  else ((Homogenization*)this)->volume = (bb2[0]-bb1[0])*(bb2[1]-bb1[1])*(bb2[2]-bb1[2]);
127  }
128 
129  return volume;
130 }
131 
132 
133 
134 
135 // Functions to approach Inclusion Properties
137 void
138 Homogenization :: giveFullEshelbyMatrixOfInclusion(double** answer, const long inclusionNumber )
139 {
140  P->give_inclusion(inclusionNumber)->give_EshelbyMatrixFull(answer);
141 }
142 
144 void
145 Homogenization :: giveReducedEshelbyMatrixOfInclusion(double* answer, const long inclusionNumber )
146 {
147  P->give_inclusion(inclusionNumber)->give_EshelbyMatrixReduced(answer);
148 }
149 
151 void
152 Homogenization :: giveFullStiffnessMatrixOfInclusion( double* answer, const long inclusionNumber )
153 {
154  P->give_inclusion(inclusionNumber)->give_StiffnessMatrixFull(answer);
155 }
156 
158 void
159 Homogenization :: giveReducedStiffnessMatrixOfInclusion( double* answer, const long inclusionNumber )
160 {
161  P->give_inclusion(inclusionNumber)->give_StiffnessMatrixReduced(answer);
162 }
163 
164 double
166 {
167  Inclusion *incl = this->P->give_inclusion(inclusionNumber);
168  return incl->give_volume() / this->giveTotalVolume();
169 }
170 
171 double
173 {
174  double tf = 0.0;
175  for (long i=0; i<P->noIncl; i++)
176  if (inside[i])
177  tf += P->inclusions[i]->give_volume();
178 
179  return tf / this->giveTotalVolume();
180 }
181 
184 void
185 Homogenization :: giveTransformationMatrixStressStrainG2L (double* answer, const long inclusionNumber)
186 {
187  P->give_inclusion(inclusionNumber)->give_TeMatrix_G2L(answer);
188 }
189 
190 void
191 Homogenization :: giveTransformationMatrixStressStrainL2G( double* answer, const long inclusionNumber )
192 {
193  P->give_inclusion(inclusionNumber)->give_TeMatrix_L2G(answer);
194 }
195 
196 void
197 Homogenization :: giveFullMatrixInGCSFromReducedMatrixInLCS(double* answer, double* ALoc, const long inclusionNumber )
198 {
199  // answer = full matrix stored row by row
200  // ALoc = full matrix in local coordinate system
201 
202  if( answer == NULL ) {
203  _errorr( "Field for answer must be allocated" );
204  }
205 
206  int mSize = this->giveSizeOfFullMatrix();
207  double *dumM = new double[mSize*mSize];
208 
210  giveFullMatrixInGCSFromFullMatrixInLCS(answer, dumM, inclusionNumber);
211 
212  delete [] dumM;
213 }
214 
215 void
216 Homogenization :: giveFullMatrixInGCSFromFullMatrixInLCS(double* answer, double* ALoc, const long inclusionNumber )
217 {
218  // answer = full matrix stored row by row
219  // ALoc = full matrix in local coordinate system
220 
221  if( answer == NULL ) {
222  _errorr( "Field for answer must be allocated" );
223  }
224 
225  int mSize = this->giveSizeOfFullMatrix();
226  double *dumM = new double[mSize*mSize];
227  double *dumT = new double[mSize*mSize];
228 
229  giveTransformationMatrixStressStrainL2G(dumT, inclusionNumber);
230 
231  giveMatrixMatrixProduct(dumT, ALoc, dumM, mSize);
232 
233  giveTransformationMatrixStressStrainG2L(dumT, inclusionNumber);
234 
235  giveMatrixMatrixProduct(dumM, dumT, answer, mSize);
236 
237  delete [] dumM;
238  delete [] dumT;
239 }
240 
241 void
242 Homogenization :: giveFullMatrixInLCSFromFullMatrixInGCS(double* answer, double* AGlob, const long inclusionNumber )
243 {
244  // answer = full matrix stored row by row
245  // AGlob = full matrix in global coordinate system
246 
247  if( answer == NULL ) {
248  _errorr( "Field for answer must be allocated" );
249  }
250 
251  int mSize = this->giveSizeOfFullMatrix();
252  double *dumM = new double[mSize*mSize];
253  double *dumT = new double[mSize*mSize];
254 
255  giveTransformationMatrixStressStrainG2L(dumT, inclusionNumber);
256 
257  giveMatrixMatrixProduct(dumT, AGlob, dumM, mSize);
258 
259  giveTransformationMatrixStressStrainL2G(dumT, inclusionNumber);
260 
261  giveMatrixMatrixProduct(dumM, dumT, answer, mSize);
262 
263  delete [] dumM;
264  delete [] dumT;
265 }
266 
267 
268 // General Functions
269 void
270 Homogenization :: giveInverseOfReducedMatrix( double* answer, const double* rM, ProblemType pT )
271 {
272  // rM = reduced matrix
273  if( answer == NULL ) {
274  _errorr( "Field for answer must be allocated" );
275  }
276 
277  switch (pT) {
278  case PT_2D: giveInverseMatrix3x3to5 (answer, rM); break;
279  case PT_3D: giveInverseMatrix6x6to12(answer, rM); break;
280  default:
281  _errorr( "Unsupported problem type" );
282  }
283 }
284 
285 void
287 {
288  if( answer == NULL ) _errorr( "Field for answer must be allocated" );
289 
290  switch( pT ) {
293  default: _errorr( "Unsupported problem type" );
294  }
295 }
296 
297 void
299 {
300  if( answer == NULL ) _errorr( "Field for answer must be allocated" );
301 
302  switch( pT ) {
303  case PT_2D: MatrixOperations::giveUnitSMatrixFull_2d (answer); break;
304  case PT_3D: MatrixOperations::giveUnitSMatrixFull_3d (answer); break;
305  default: _errorr( "Unsupported problem type" );
306  }
307 }
308 
309 void
310 Homogenization :: giveProductOfReducedMatrices( double* answer, double* A, double* B, ProblemType pT )
311 {
312  // answer = A*B;
313  if( answer == NULL ) {
314  _errorr( "Field for answer must be allocated" );
315  }
316 
318 
319  switch( pT )
320  {
321  case PT_2D: {
322  answer[0] = A[0]*B[0] + A[1]*B[2];
323  answer[1] = A[0]*B[1] + A[1]*B[3];
324  answer[2] = A[2]*B[0] + A[3]*B[2];
325  answer[3] = A[2]*B[1] + A[3]*B[3];
326  answer[4] = A[4]*B[4];
327 
328  break;
329  }
330  case PT_3D: {
331  answer[0] = A[0]*B[0] + A[1]*B[3] + A[2]*B[6];
332  answer[1] = A[0]*B[1] + A[1]*B[4] + A[2]*B[7];
333  answer[2] = A[0]*B[2] + A[1]*B[5] + A[2]*B[8];
334  answer[3] = A[3]*B[0] + A[4]*B[3] + A[5]*B[6];
335  answer[4] = A[3]*B[1] + A[4]*B[4] + A[5]*B[7];
336  answer[5] = A[3]*B[2] + A[4]*B[5] + A[5]*B[8];
337  answer[6] = A[6]*B[0] + A[7]*B[3] + A[8]*B[6];
338  answer[7] = A[6]*B[1] + A[7]*B[4] + A[8]*B[7];
339  answer[8] = A[6]*B[2] + A[7]*B[5] + A[8]*B[8];
340  answer[9] = A[9]*B[9];
341  answer[10] = A[10]*B[10];
342  answer[11] = A[11]*B[11];
343 
344  break;
345  }
346  default:
347  _errorr( "Unsupported problem type" );
348  }
349 }
350 
352 void
354 {
355 #ifdef DEBUG
356  if( answer == NULL ) _errorr( "Field for answer must be allocated" );
357 #endif
358 
360 
361  switch( pT )
362  {
363  case PT_2D: {
365  break;
366  }
367  case PT_3D: {
369  break;
370  }
371  default:
372  _errorr( "Unsupported problem type" );
373  }
374 }
375 
376 void
377 Homogenization :: giveProductOfRegularMatrixReducedMatrix( double* answer, double* A, double* redB , int n, ProblemType pT )
378 {
379  // answer = A[n,k]*B[k,l];
380  if( answer == NULL ) {
381  _errorr( "Field for answer must be allocated" );
382  } else if( giveSizeOfFullMatrix() != n ) {
383  _errorr( "Matrix mismatch" );
384  }
385 
386  double *dumB = new double[n*n];
387 
388  giveFullMatrixFromReducedMatrix(dumB, redB, pT);
389 
390  giveMatrixMatrixProduct(A, dumB, answer, n);
391 
392  delete [] dumB;
393 }
394 
395 void
396 Homogenization :: giveProductOfReducedMatrixRegularMatrix( double* answer, double* redA, double* B, ProblemType pT, int n )
397 {
398  // answer = A[n,k]*B[k,l];
399  if( answer == NULL ) {
400  _errorr( "Field for answer must be allocated" );
401  } else if( giveSizeOfFullMatrix() != n ) {
402  _errorr( "Matrix mismatch" );
403  }
404 
405  double *dumA = new double[n*n];
406 
407  giveFullMatrixFromReducedMatrix(dumA, redA, pT);
408 
409  giveMatrixMatrixProduct(dumA, B, answer, n);
410 
411  delete [] dumA;
412 }
413 
414 } // end of namespace mumech
415 
416 /*end of file*/
int give_VM_TENS_RANGE(void) const
Gives range of a second order tensor in Voigt-Mandel notation.
Definition: problem.h:98
double volume
Total volume of the proble/bounding box.
void giveFullEshelbyMatrixOfInclusion(double **answer, const long inclusionNumber)
void copy2DeshelbyTensor_reduced2full(const double *a, double **b)
Function copies and converts 2D eshelby/stiffness tensor saved in reduced row-wise vector &#39;a&#39; to full...
file of various types and symbolic constant definitions
void giveUnitSMatrixFull_2d(double *m)
Function sets reduced 2d SMatrix to unit matrix.
void giveReducedUnitMatrix(double *answer, ProblemType pT)
Problem * P
Problem description.
bool * inside
Flag - inclusion inside of the bounding box.
Class InclusionRecord contains and handles all inclusion data.
Definition: inclusion.h:60
Problem description.
Definition: problem.h:154
double give_volume(void)
Definition: inclusion.cpp:416
void copy3DeshelbyTensor_reduced2full(const double *a, double **b)
Function copies and converts 3D eshelby/stiffness tensor saved in reduced row-wise vector &#39;a&#39; to full...
int giveNumberOfInclusions() const
void find_inclusions_in_BB(void)
Namespace MatrixOperations.
void give_StiffnessMatrixFull(double *answer) const
Copy stiffness tensor into full matrix answer.
Definition: inclusion.cpp:799
Class of function for homogenization of stress fields.
double bb1[3]
Coordinates of lower corner of the bounding box.
Class Mesh.
Inclusion * give_inclusion(long i) const
debug, for one function in tools
Definition: problem.h:402
void giveTransformationMatrixStressStrainL2G(double *answer, const long inclusionNumber)
double giveTotalVolume() const
void give_EshelbyMatrixFull(double **answer) const
Copy Eshelby tensor into full matrix answer.
Definition: inclusion.cpp:778
void giveInverseMatrix6x6to12(double *answer, const double *m)
Function computes inverse of the eshelby-like 3x3 matrix &#39;m&#39; saved in reduced 6x6to12 form...
void giveInverseMatrix3x3to5(double *answer, const double *m)
Function computes inverse of the eshelby-like 3x3 matrix &#39;m&#39; saved in reduced 3x3to5 form...
ProblemType giveProblemType() const
void giveProductOfReducedMatrixRegularMatrix(double *answer, double *redA, double *B, ProblemType pT, int n)
Function returning full matrix stored row by row in vector array.
void giveUnitSMatrixReduced_3d(double *m)
Function sets reduced 3d SMatrix to unit matrix.
Class mElement, mesh element.
virtual ~Homogenization()
Destructor.
void giveTransformationMatrixStressStrainG2L(double *answer, const long inclusionNumber)
answer = full transformation matrix global->local stored row by row
void giveFullStiffnessMatrixOfInclusion(double *answer, const long inclusionNumber)
void giveFullMatrixInGCSFromReducedMatrixInLCS(double *answer, double *ALoc, const long inclusionNumber)
void giveProductOfReducedMatrices(double *answer, double *A, double *B, ProblemType pT)
void giveFullMatrixInLCSFromFullMatrixInGCS(double *answer, double *AGlob, const long inclusionNumber)
void set_boundingBox(double x1, double y1, double x2, double y2)
Collection of the functions of basic manipulations, some of them can be used instead of their counter...
void giveFullUnitMatrix(double *answer, ProblemType pT)
int give_ISO_C_RANGE(void) const
Gives range of ...
Definition: problem.h:100
void giveReducedEshelbyMatrixOfInclusion(double *answer, const long inclusionNumber)
void giveFullMatrixFromReducedMatrix(double *answer, const double *A, ProblemType pT)
Function returning full matrix stored row by row in vector array.
bool is_inside_of_BB(const double *bb1, const double *bb2) const
check the receiver is inside of the bounding box defined by lower left bb1 and upper right bb2 corner...
Definition: inclusion.cpp:218
double giveTotalVolumeFractionOfInclusions(void) const
void giveFullMatrixInGCSFromFullMatrixInLCS(double *answer, double *ALoc, const long inclusionNumber)
Inclusion ** inclusions
inclusion records - 1d array of pointers to InclusionRecord
Definition: problem.h:189
void check_dim(int i) const
Definition: problem.h:496
void give_TeMatrix_G2L(double *answer) const
Copy Te (G2L strain transformation matrix) tensor into full matrix answer.
Definition: inclusion.cpp:820
Class Homogenization.
void giveMatrixMatrixProduct(const double *mtrx1, const double *mtrx2, double *resMtrx, long n)
Function gives the product of two regular matrices.
#define _errorr(_1)
Definition: gelib.h:160
Class mNode, mesh node.
int give_twodim(void) const
Definition: problem.h:84
void give_TeMatrix_L2G(double *answer) const
Copy TeInv (L2G strain transformation matrix) tensor into full matrix answer.
Definition: inclusion.cpp:829
double giveVolumeFractionOfInclusion(const long inclusionNumber)
void giveReducedStiffnessMatrixOfInclusion(double *answer, const long inclusionNumber)
void giveUnitSMatrixReduced_2d(double *m)
Function sets reduced 2d SMatrix to unit matrix.
void giveProductOfRegularMatrixReducedMatrix(double *answer, double *A, double *redB, int n, ProblemType pT)
Function returning full matrix stored row by row in vector array.
void give_EshelbyMatrixReduced(double *answer) const
Copy Eshelby tensor into reduced vector answer.
Definition: inclusion.cpp:789
void giveUnitSMatrixFull_3d(double *m)
Function sets reduced 3d SMatrix to unit matrix.
double bb2[3]
Coordinates of upper corner of the bounding box.
int noIncl
number of inclusions
Definition: problem.h:188
void CleanVector(double *a, long n)
Functin cleans a &#39;double&#39; vector, initialize each value being 0-zero.
Class Problem.
Homogenization(long i, Problem *p)
Constructor.
void give_StiffnessMatrixReduced(double *answer) const
Copy stiffness tensor into reduced vector answer.
Definition: inclusion.cpp:810
void giveInverseOfReducedMatrix(double *answer, const double *rM, ProblemType pT)