muMECH  1.0
selfBalanceAlgorithm.cpp
Go to the documentation of this file.
1 //********************************************************************************************************
2 // code: ### ### ##### #### ## ##
3 // ## ## ######## ## ## ## ## ##
4 // ## ## ## ## ## ### ## ######
5 // ## ## ## ## ## ## ## ## ##
6 // ##### ## ## ##### #### ## ##
7 // ##
8 //
9 // name: selfBalanceAlgorithm.cpp
10 // author(s): Jan Novak
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 #include <string.h>
28 #include "macros.h"
29 #include "esuf.h"
30 #include "esei.h"
31 #include "eshelbySoluLambda.h"
32 #include "transformTensors.h"
33 #include "selfBalanceAlgorithm.h"
34 #include "matrixOperations.h"
35 #include "elementaryFunctions.h"
36 #include "problem.h"
37 
38 
39 namespace mumech {
40 
41 
42 //********************************************************************************************************
43 // PUBLIC FUNCTIONS
44 //********************************************************************************************************
45 
54 {
55  for( int i = 0; i < n; i++ ){
56  CopyVector( inclRec[i]->globEigStrainTotal, ( auxVect + i * 6 ), 6 );
57  }
58 
59  return ;
60 }//end of function: copyGlobTotalEigStrainsToAuxVector( )
61 
62 
69 {
70  if (problem->SBA_type == SBAT_STANDA) {
71  ;
72  }
73  else if (problem->SBA_type == SBAT_ORIGINAL) {
74  // test whether all inclusions are 3D
75  InclusionRecord3D **inclRec = new InclusionRecord3D*[problem->noIncl];
76  for (int i=0; i<problem->noIncl; i++) {
77  inclRec[i] = dynamic_cast<InclusionRecord3D*>(problem->inclusions[i]);
78  if (inclRec[i] == NULL) _errorr("");
79  }
80 
81  // info print
82  if (problem->verbose > 0) printf( "Transformation strain update in progress, please wait ... \n" );
83 
84  Point *point = NULL;
85  double * auxStrains = NULL;
86  double norm;
87  int step, i, j;
88 
89  // auxiliary 'Point' memory allocation
90  point = new Point[problem->noIncl];
91  for( i = 0; i < problem->noIncl; i++ ){
92  point[i].set_nlc(problem, 1);
93  CopyVector( inclRec[i]->origin, point[i].x, 3 );
94  }
95 
96  // auxiliary memory allocation to save the total global eigenstrains of previous 'balance' step
97  auxStrains = new double[problem->noIncl * 6];
98  long noActIncls, indx;
99 
100  // Self-balance iterative algorithm.
101  step = 0;
102  do {
103  // maximum number of interations reached - non convergence
104  if (step >= problem->get_SBA_maxiters()) _errorr("convergence not reached");
105  // required number of interations reached - break
106  if (step >= problem->get_SBA_reqiters()) break;
107  step++;
108 
109  //update of auxGlobEigenstrain
110  selfBalanceAlgorithm::copyGlobTotalEigStrainsToAuxVector( inclRec, auxStrains, problem->noIncl );
111 
113  for (i = 0; i < problem->noIncl; i++)
114  CleanVector(inclRec[i]->locEigStrainTot, 6);
115 
116  for (i = 0; i < problem->noIncl; i++) {
117  // number of active inclusions
118  if (problem->SBA_optimized == false) noActIncls = problem->noIncl;
119  else noActIncls = inclRec[i]->noActingIncls;
120 
121  for (j=0; j<noActIncls; j++) {
122  if (problem->SBA_optimized == false) indx = j;
123  else indx = inclRec[i]->actingIncls[j];
124 
125  if (indx != i) {
126  inclRec[i]->esuf->giveEshelbyStrainOfOnePoint( &point[indx]);
127  inclRec[indx]->SBA_updateGlobAndLocStrains(point+indx);
128  }
129 
130  }
131  }
132 
133  for (i=0; i<problem->noIncl; i++)
134  inclRec[i]->addtot();
135 
136  //quadratic norm calculation
137  norm = selfBalanceAlgorithm::giveQuadNormMultEigstrain( inclRec, auxStrains, problem->noIncl );
138 
139  //
140  if (problem->verbose > 0)
141  printf( "self-balance norm[%d] = %.6e\n", ( step ), norm );
142 
143  } while( norm > _SELF_BALANCE_NORM_LIMIT_ );
144 
145  if (problem->verbose > 0)
146  printf( "steps: %d\n", step );
147 
148  // Final local eigenstrains update
150 
151  // DEBUG PRINT
152  if (problem && problem->give_verbose() > 2) {
153  //Total global transformation strain printing
154  //selfBalanceAlgorithm::printTotEigenStrains( inclRec, problem->noIncl, "Updated transformation strains:\n" );
155  }
156 
157  //auxiliary memory de-allocation
158  delete [] point;
159  delete [] auxStrains;
160 
161  delete [] inclRec;
162  }
163  else if (problem->SBA_type== SBAT_VOID) {
164  ;
165  }
166  else _errorr("Unknown SBAmode");
167 
168  return ;
169 }//end of function: totalEigStrainInInclCentroidsUpdate( )
170 
171 
172 //********************************************************************************************************
173 // PROTECTED FUNCTIONS
174 //********************************************************************************************************
175 //
176 
177 
178 // //********************************************************************************************************
179 // // description: Function copies strain perturbatios in inclusion origins into an auxiliary vector
180 // // last edit: 02. 03. 2010
181 // // -------------------------------------------------------------------------------------------------------
182 // // @point - point data record, defined in: types.h
183 // // @auxVect - auxiliary vector
184 // // @n - total number of inclusions
185 // //********************************************************************************************************
186 // void selfBalanceAlgorithm::copyPertStrainsToAuxVect( Point * point, double * auxVect, int n )
187 // {
188 // for( int i = 0; i < n; i++ ){
189 // CopyVector( point[i].strain[0], ( auxVect + i * 6 ), 6 );
190 // }
191 //
192 // return ;
193 // }//end of function: copyPertStrainsToAuxVect( )
194 
202 double selfBalanceAlgorithm :: giveQuadNormMultEigstrain (InclusionRecord3D **inclRec, double * oldStrain, int n)
203 {
204  double norm = 0.;
205 
206  // calculation of quadratic norm of eigenstrains in global coordinates
207  while (n--)
208  norm += give_quadNormTwoVectors ( oldStrain + n * 6, inclRec[n]->globEigStrainTotal, 6);
209 
210  return norm;
211 }
212 
213 //********************************************************************************************************
214 // description: Function updates total local eigenstrains from their total global counterparts
215 // last edit: 02. 03. 2010
216 // -------------------------------------------------------------------------------------------------------
217 // @inclRec - inclusion record (data structure of given inclusions: types.h)
218 // @n - total number of inclusions
219 //********************************************************************************************************
221 {
222  for (int i=0; i<n; i++)
223  inclRec[i]->rotateStrain_G2L(inclRec[i]->globEigStrainTotal, inclRec[i]->locEigStrain);
224 }
225 
226 //********************************************************************************************************
227 // description: Function prints resulting total transformation strains in inclusion centroids
228 // last edit: 02. 03. 2010
229 // -------------------------------------------------------------------------------------------------------
230 // @inclRec - inclusion record (data structure of given inclusions: types.h)
231 // @n - total number of inclusions
232 //********************************************************************************************************
233 void selfBalanceAlgorithm::printTotEigenStrains( InclusionRecord3D **inclRec, int n, const char * notice )
234 {
235  char auxName[200];
236 
237  printf( "%s", notice );
238 
239  for( int i = 0; i < n; i++ ){
240  sprintf( auxName, "Inclusion %d:\n", ( i + 1 ) );
241  printVectorRowForm( inclRec[i]->globEigStrainTotal, 6, ( const char * ) auxName );
242  //CleanString( auxName, 200 );
243  }
244 }//end of function: printTotEigenStrains( )
245 
246 
247 } // end of namespace mumech
248 
249 /*end of file*/
Class eshelbySoluUniformField.
int get_SBA_maxiters(void)
Definition: problem.h:491
static double giveQuadNormMultEigstrain(InclusionRecord3D **inclRec, double *oldStrain, int n)
Function gives the quadratic norm of multiple eigenstrain vectors calculated from total global eigens...
double give_quadNormTwoVectors(const double *v1, const double *v2, int n)
Function returns the quadratic norm of two vectors of length &#39;n&#39;.
int get_SBA_reqiters(void)
Definition: problem.h:493
#define _SELF_BALANCE_NORM_LIMIT_
Definition: types.h:54
void giveEshelbyStrainOfOnePoint(Point *point)
Function gives the &#39;Eshelby&#39; STRAIN field in an arbitrary EXTERNAL point.
Definition: esuf.cpp:134
Problem description.
Definition: problem.h:154
void set_nlc(const Problem *p, int nlc)
Definition: matrix.cpp:313
Original Honza Novak&#39;s balancing.
Definition: types.h:90
static void copyGlobTotalEigStrainsToAuxVector(InclusionRecord3D **inclRec, double *auxVect, int n)
Function copies total global eigenstrains from InclRecord to an auxiliary vector: auxVect = &#39;n x 6&#39; ...
eshelbySoluUniformField * esuf
Definition: inclusion.h:285
static void totalEigStrainInInclCentroidsUpdate(Problem *p)
Function gives the total transformation strain field in inclusion centroids regarding the presence of...
Namespace MatrixOperations.
int verbose
0 - no printing, 1 - basic printing, 3 - debug printing
Definition: problem.h:206
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;.
void SBA_updateGlobAndLocStrains(Point *point)
Function modifies/updates the actuall local and global eigenstrains in inclusion centroids due to the...
Definition: inclusion.cpp:1461
void printVectorRowForm(double *vect, int n, const char *notice)
Function prints the vector of double values as row.
Class eshelbySoluEllipticIntegrals.
The header file of usefull macros.
3D inclusion record.
Definition: inclusion.h:278
Collection of the functions of basic manipulations, some of them can be used instead of their counter...
bool SBA_optimized
SBA optimized (FULL/_OPTIMIZED_)
Definition: problem.h:192
SBAtype SBA_type
type of Self balancing algorithm (SBA)
Definition: problem.h:191
Single Point data structure - contribution from Single inclusion.
Definition: matrix.h:133
int give_verbose(void) const
Give verbose level.
Definition: problem.h:499
Inclusion ** inclusions
inclusion records - 1d array of pointers to InclusionRecord
Definition: problem.h:189
#define _errorr(_1)
Definition: gelib.h:160
static void localEigStrainUpdateTotal(mumech::InclusionRecord3D **inclRec, int n)
int noActingIncls
Number of acting inclusions.
Definition: inclusion.h:111
static void printTotEigenStrains(InclusionRecord3D **inclRec, int n, const char *notice)
The set of the functions returning the Eshelby solution of multiple inclusion task using the self-bal...
New Standa&#39;s b.
Definition: types.h:91
int noIncl
number of inclusions
Definition: problem.h:188
int * actingIncls
Set of inclusions which act to the "this" one.
Definition: inclusion.h:112
void CleanVector(double *a, long n)
Functin cleans a &#39;double&#39; vector, initialize each value being 0-zero.
No balancing.
Definition: types.h:89
Class Problem.
Namespace TransformTensors.