muMECH  1.0
matrix.cpp
Go to the documentation of this file.
1 //********************************************************************************************************
2 // code: ### ### ##### #### ## ##
3 // ## ## ######## ## ## ## ## ##
4 // ## ## ## ## ## ### ## ######
5 // ## ## ## ## ## ## ## ## ##
6 // ##### ## ## ##### #### ## ##
7 // ##
8 //
9 // name: matrix_record.cpp
10 // author(s): Jan Novak
11 // last edit: 04. 02. 2010
12 // language: C, C++
13 // license: This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published by
15 // the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 //********************************************************************************************************
27 
28 //included libraries
29 #include <stdio.h>
30 #include "matrix.h"
31 #include "stiffness.h"
32 #include "esuf.h"
33 #include "matrixOperations.h"
34 #include "problem.h"
35 #include "librw.h"
36 
37 
38 namespace mumech {
39 
40 
43 {
44  P = p;
45  ym = pr = -1.0;
46  origin = NULL;
47  nRS = 0;
48  Remote_strain = NULL;
49 
51 
52  C = new double[P->give_ISO_C_RANGE()];
53 }
54 
57 {
58  delete [] origin;
63 
64  if (C) delete [] C;
65 }
66 
69 {
70  if (nRS) _errorr("nlc set already");
71  nRS = n;
72  if (nRS < 1 || nRS > 99) _errorr("Number of load cases should be > 0 and <100");
73 }
74 
76 void MatrixRecord :: set_E_nu (double e, double n)
77 {
79  _errorr("You can not set matrix recor when data already converted to equivalent problem.");
80 
81  if (this->ym >= 0.0) _errorr("Matrix record: E is already set");
82  if (this->pr >= 0.0) _errorr("Matrix record: nu is already set");
83 
84  ym = e;
85  pr = n;
86 
87  // evaluation of stifness matrix
88  Stiffness::giveReducedIsoStiffMatrix (this->C, this->ym, this->pr, P->is_twodim());
89 }
90 
91 void MatrixRecord :: set_origin (double x, double y) { P->check_dim(2); origin = new double[2]; origin[0] = x; origin[1] = y; }
92 void MatrixRecord :: set_origin (double x, double y, double z) { P->check_dim(3); origin = new double[3]; origin[0] = x; origin[1] = y; origin[2] = z; }
93 
96 {
99 }
100 
102 void MatrixRecord :: set_Remote_strain_for_lc (int lc, const double r1[])
103 {
104  if (this->nRS == 0) _errorr("Number of remote strains was not set.");
105  if (this->nRS <= lc) _errorr("Remote strain ID is greather then the set number of remote strains");
106  if (Remote_strain == NULL) this->allocate_nlc_fields ();
108 
109  this->convert_RS_ROWtoFEEP (lc);
110 }
113 {
114  if (Remote_strain == NULL) this->allocate_nlc_fields ();
115 
116  int l = P->give_TENS_RANGE();
117 
118  for (int i=0; i<P->give_nLC(); i++) {
119  if (FP_scan_array (stream, l, Remote_strain[i]) != true)
120  return false;
121 
122  this->convert_RS_ROWtoFEEP (i);
123  }
124 
125  return true;
126 }
128 bool MatrixRecord :: scan_Remote_strains (const char *stream)
129 {
130  if (Remote_strain == NULL) this->allocate_nlc_fields ();
131 
132  int l = P->give_TENS_RANGE();
133 
134  for (int i=0; i<P->give_nLC(); i++) {
135  if (SP_scan_array (stream, l, Remote_strain[i]) != true)
136  return false;
137 
138  this->convert_RS_ROWtoFEEP (i);
139  }
140 
141  return true;
142 }
143 
146 {
147  if (Remote_strain) {
148  if (this->remote_strain_is_unit() == false)
149  _errorr("Already given Remote strain is not equal to \"unit set\".");
150 
151  }
152  else {
153  // Unit remote strain se pouziva pro homogenizaci RegGrid, a musi byt proto na vsech pozicich 1.0.
154  // Ikdyz tam dam 0.5, tak se stejne nic nedeje, pac to tam stejne nasobim inverzi strainu,
155  // takze vlastne muze byt unit strain libovolnej, ale jen diky tomu nasobeni.
156  double smyk = 1.0;
157 
158  this->set_nlc(P->give_VM_TENS_RANGE());
159  this->allocate_nlc_fields();
160 
162 
163  if (P->twodim) {
164  Remote_strain[0][0] = 1.0;
165  Remote_strain[1][1] = 1.0;
166  Remote_strain[2][2] = smyk;
167  }
168  else {
169  Remote_strain[0][0] = 1.0;
170  Remote_strain[1][1] = 1.0;
171  Remote_strain[2][2] = 1.0;
172  Remote_strain[4][4] = smyk;
173  Remote_strain[5][5] = smyk;
174  Remote_strain[3][3] = smyk;
175  }
176  }
177 }
178 
181 {
182  if (this->nRS != P->give_VM_TENS_RANGE()) return false;
183 
184  double smyk = 1.0; // same as upper
185 
186  double s = GiveSumMembersArray2D ((const double **)Remote_strain, nRS, P->give_TENS_RANGE());
187  if (s != (P->twodim ? 2+smyk : 3+3*smyk)) return false;
188 
189  if (P->twodim) {
190  if (Remote_strain[0][0] != 1.0 ||
191  Remote_strain[1][1] != 1.0 ||
192  Remote_strain[2][2] != smyk ) return false;
193  }
194  else {
195  if (Remote_strain[0][0] != 1.0 ||
196  Remote_strain[1][1] != 1.0 ||
197  Remote_strain[2][2] != 1.0 ||
198  Remote_strain[3][3] != smyk ||
199  Remote_strain[4][4] != smyk ||
200  Remote_strain[5][5] != smyk ) return false;
201  }
202  return true;
203 }
204 
206 void MatrixRecord :: giveReducedStiffMatrix (double *answer) const
207 {
208  CopyVector(this->C, answer, P->give_ISO_C_RANGE());
209 }
211 void MatrixRecord :: giveFullStiffMatrix (double *answer) const
212 {
215 }
216 
217 
220 {
223 }
224 
226 const double* MatrixRecord :: give_globHomog_Displc (int lc, const double *coords)
227 {
229 
230  return globHomog_displc[lc];
231 }
233 void MatrixRecord :: give_globHomog_Displc (double *displ, int lc, const double *coords)
234 {
235  CopyVector(this->give_globHomog_Displc(lc, coords), displ, P->give_VECT_RANGE());
236 }
237 
240 {
241  return Remote_strain[lc];
242 }
244 void MatrixRecord :: give_globHomog_Strain (double *strain, int lc)
245 {
246  CopyVector(this->give_globHomog_Strain(lc), strain, P->give_VM_TENS_RANGE());
247 }
248 
251 {
252  if (globHomog_stress == NULL) {
253  globHomog_stress = new double*[P->give_nLC()];
254  memset (globHomog_stress, 0, P->give_nLC() * sizeof(double*));
255  }
256 
257  if (globHomog_stress[lc] == NULL) {
258  globHomog_stress[lc] = new double[P->give_VM_TENS_RANGE()];
259 
262  }
263 
264  return globHomog_stress[lc];
265 }
267 void MatrixRecord :: give_globHomog_Stress (double *stress, int lc)
268 {
269  CopyVector(this->give_globHomog_Stress(lc), stress, P->give_VM_TENS_RANGE());
270 }
271 
272 
273 
274 
275 
276 
277 
279 void MatrixRecord :: printYourself (const char *notice)
280 {
281  if (notice) printf( "%s", notice );
282  printf( "Young's modulus: %e\n", ym );
283  printf( "Poisson's ratio: %e\n", pr );
284  //eshSolu.printIsoTensor( C, "Infinite medium stifness matrix:\n", _STANDARD_SYNTAX_ );
285 
286  return ;
287 } // end of function: printMtrxRecord( )
288 
289 
290 // ********************************************************************************************************
291 // ************************** POINT *******************************************************************
292 // ********************************************************************************************************
293 
296 {
297  //position = PPF_VOID;
298  //this->set_nlc(p, nlc);
299 
300  displacement = strain = stress = NULL;
301 }
302 
305 {
306  DeleteArray2D (displacement, nlc);
307  DeleteArray2D (strain, nlc);
308  DeleteArray2D (stress, nlc);
309 }
310 
311 
313 void Point :: set_nlc (const Problem *p, int nlc)
314 {
315  Point::nlc = nlc;
316 
317  AllocateArray2D (displacement, nlc, p->give_VECT_RANGE());
318  AllocateArray2D (strain, nlc, p->give_VM_TENS_RANGE());
319  AllocateArray2D (stress, nlc, p->give_VM_TENS_RANGE());
320 }
321 
322 
323 
324 } // end of namespace mumech
325 
326 /*end of file*/
Class eshelbySoluUniformField.
int give_VM_TENS_RANGE(void) const
Gives range of a second order tensor in Voigt-Mandel notation.
Definition: problem.h:98
void convert_RS_ROWtoFEEP(int lc)
Definition: matrix.cpp:95
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...
int give_dimension(void) const
Definition: problem.h:86
const double * give_globHomog_Stress(int lc)
Definition: matrix.cpp:250
virtual int give_nLC(void) const
Give number of load cases, e.i. number of load cases, i.e. number of Remote_strain fields...
Definition: problem.h:334
const double * give_globHomog_Strain(int lc)
Definition: matrix.cpp:239
void convert3Dtensor_9ROWto6FEEP_notation(double *t)
double * C
isotropic stiffness matrix of the infinite medium (infinite matrix), saved in reduced form...
Definition: matrix.h:66
void convert2Dtensor_4ROWto3FEEP_notation(double *t)
Problem description.
Definition: problem.h:154
double ** globHomog_strain
Global homogeneous strain fields.
Definition: matrix.h:62
void set_nlc(const Problem *p, int nlc)
Definition: matrix.cpp:313
void set_unit_remote_strain(void)
Sets a set of unit remote strain.
Definition: matrix.cpp:145
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...
Namespace MatrixOperations.
bool twodim
2 dimension problem; 3d is default; twodim == true - 2d, twodim == false - 3d
Definition: problem.h:66
Input / output function.
void giveReducedIsoStiffMatrix(double *C, double E, double nu, bool twodim)
Function gives the reduced isotropic stiffness matrix of a homogeneous material.
Definition: stiffness.cpp:35
void printYourself(const char *notice=NULL)
Function prints the MatrixRecord.
Definition: matrix.cpp:279
int give_VECT_RANGE(void) const
Gives vector range, same as dimension.
Definition: problem.h:92
void CopyVector(const double *src, double *dest, long n)
Function copy given number of components from vector, &#39;a&#39; to vector &#39;b&#39;.
Point()
Constructor.
Definition: matrix.cpp:295
virtual bool is_converted_to_equivalent(void) const
Give type of ...
Definition: problem.h:483
bool SP_scan_array(const char *&src, int n, ArgType *a)
... array of numbers
Definition: librw.h:253
bool remote_strain_is_unit(void) const
Check the remote strain is unit.
Definition: matrix.cpp:180
void giveTVproduct_6is6x6to12and6(double *result, const double *T, const double *vect)
Function gives product of tensor and vector - &#39;result = T * vect&#39;.
void giveReducedStiffMatrix(double *answer) const
Definition: matrix.cpp:206
Namespace Stiffness.
bool FP_scan_array(FILE *stream, int n, int *dest)
scan/copy array of numbers from src to dest, src pointer is shifted over the field ...
Definition: librw.cpp:313
const Problem * P
Definition: matrix.h:52
void CleanArray2d(double **a, long rows, long columns)
Function cleans an 2d &#39;double&#39; array, initialize each value being 0-zero.
int give_ISO_C_RANGE(void) const
Gives range of ...
Definition: problem.h:100
double ym
Young&#39;s modulus of the matrix.
Definition: matrix.h:54
int give_TENS_RANGE(void) const
Gives tensor range, same as dimension^2. Theoretical range of a second order tensor.
Definition: problem.h:96
double pr
Poissons ratio of the matrix.
Definition: matrix.h:55
void check_dim(int i) const
Definition: problem.h:496
Class MatrixRecord.
const double * give_globHomog_Displc(int lc, const double *coords)
Definition: matrix.cpp:226
MatrixRecord(const Problem *p)
Constructor.
Definition: matrix.cpp:42
void giveIsoTensAndVectorProduct(const double *tens, const double *vec, double *result, int dim)
Function gives the product of the isotropic tensor of seccond order with a vector.
#define _errorr(_1)
Definition: gelib.h:160
double ** globHomog_stress
Global homogeneous stress fields.
Definition: matrix.h:63
int is_twodim(void) const
Definition: problem.h:487
void giveTVproduct_3is3x3to5and3(double *result, const double *T, const double *vect)
Function gives product of tensor and vector - &#39;result = T * vect&#39;.
double GiveSumMembersArray2D(const double **a, long d1, long d2)
Function returns sum of all member of array &#39;a&#39;.
void DeleteArray2D(bool **array, long d1)
Function deletes a 2D &#39;bool&#39; array of dimension d1 x ??, allocated by new.
double * origin
coordinates of the origin of infinite medium (origin of global coordinate system) ...
Definition: matrix.h:56
void set_Remote_strain_for_lc(int lc, const double r1[])
r1 se zadava v theoretical row notation prislusne delky, 4 nebo 9
Definition: matrix.cpp:102
virtual ~MatrixRecord()
Destructor.
Definition: matrix.cpp:56
double ** Remote_strain
Remote strain fields == homogeneous strain tensor, stored in TVRN_THEORETICAL_FEEP notation...
Definition: matrix.h:58
double ** AllocateArray2D(long d1, long d2)
Operations with 2d, 3d, 4d arrays of various sizes.
bool scan_Remote_strains(FILE *stream)
Definition: matrix.cpp:112
void set_nlc(int n)
Definition: matrix.cpp:68
void set_E_nu(double e, double n)
Definition: matrix.cpp:76
void allocate_nlc_fields(void)
Allocate fields depending to number of load cases.
Definition: matrix.cpp:219
int nRS
Number of remote strains.
Definition: matrix.h:57
double ** globHomog_displc
Global homogeneous displacement fields.
Definition: matrix.h:61
virtual ~Point()
Destructor.
Definition: matrix.cpp:304
Class Problem.
void giveFullStiffMatrix(double *answer) const
Definition: matrix.cpp:211
void set_origin(double x, double y)
Definition: matrix.cpp:91
void e(int i)