NeoPZ
TPZLadeNelsonElasticResponse.h
Go to the documentation of this file.
1 
5 #ifndef TPZLADENELSONELASTICRESPONSE_H
6 #define TPZLADENELSONELASTICRESPONSE_H
7 
8 #include "TPZTensor.h"
9 #include "pzreal.h"
10 #include "pzfmatrix.h"
11 #include "pzstepsolver.h"
12 #include "pzvec_extras.h"
13 #include "pzdiffmatrix.h"
14 
15 
16 #ifndef CHECKCONV
17 #define CHECKCONV
18 #include "checkconv.h"
19 #endif
20 
21 using namespace std;
22 
23 #include "tfad.h"
24 #include "fadType.h"
25 #include "pzlog.h"
26 
27 #ifdef LOG4CXX_PLASTICITY
28 static LoggerPtr loggerPlasticity(Logger::getLogger("plasticity.plasticstep"));
29 #endif
30 
35 
36 public:
37 
38  int ClassId() const override;
39 
40  TPZLadeNelsonElasticResponse() : fLambda(0.), fM(0.), fPoisson(0.), fPa(0.)
41  { }
42 
44  {
45  fLambda = source.fLambda;
46  fM = source.fM;
47  fPoisson = source.fPoisson;
48  fPa = source.fPa;
49  }
50 
52  {
53  fLambda = source.fLambda;
54  fM = source.fM;
55  fPoisson = source.fPoisson;
56  fPa = source.fPa;
57  return *this;
58  }
59 
60  void Write(TPZStream &buf, int withclassid) const override{
61  buf.Write(&fLambda);
62  buf.Write(&fM);
63  buf.Write(&fPoisson);
64  buf.Write(&fPa);
65  }
66 
67  void Read(TPZStream& buf, void* context) override {
68  buf.Read(&fLambda);
69  buf.Read(&fM);
70  buf.Read(&fPoisson);
71  buf.Read(&fPa);
72  }
73 
74  const char * Name() const
75  {
76  return "TPZLadeNelsonElasticResponse";
77  }
78 
79  void Print(std::ostream & out) const
80  {
81  out << "\n" << this->Name();
82  out << "\n fLambda = " << fLambda;
83  out << "\n fM = " << fM;
84  out << "\n fPoisson = " << fPoisson;
85  out << "\n fPa = " << fPa;
86  }
87 
88 
96  void SetUp(REAL Lambda, REAL M, REAL poisson, REAL pa)
97  {
98  fM = M;
99  fLambda = Lambda;
100  fPoisson = poisson;
101  fPa = pa;
102  }
103 
109  template <class T>
110  void ComputeStress(const TPZTensor<T> & epsilon_T, TPZTensor<T> & sigma_T) const;
111 
118  void ComputeStress(const TPZTensor<REAL> & epsilon, TPZTensor<REAL> & sigma) const;
119 
120 protected:
121 
128  template <class T>
129  void SolveSigma(const TPZTensor<T> & epsilon_T, TPZTensor<T> & sigma_T) const;
130 
131  template <class T, class TBASE>
132  void ComputeYoung(const TPZTensor<T> & sigma, T & Young) const;
133 
134  template <class T, class TBASE>
135  void ApplyElasticTensor(const T & Young, const TPZTensor<T> & Epsilon, TPZTensor<T> & sigma) const;
136 
137  template <class T, class VECTOR, class MATRIX>
138  inline void ExtractTangent(const TPZTensor<T> & Res_T, VECTOR & ResVal, REAL & resnorm, MATRIX & tangent) const;
139 
140 public:
141 
142  REAL fLambda;
143  REAL fM;
144  REAL fPoisson;
145  REAL fPa;
146 
147 public:
149 
153  int NumCases()
154  {
155  return 2;
156  }
157 
163  {
164  #ifdef LOG4CXX_PLASTICITY
165  LoggerPtr logger(Logger::getLogger("plasticity.erladenelson"));
166  #endif
167  int i;
168  for(i=0; i<6; i++) gRefDeform[i] = state(i,0);
169  #ifdef LOG4CXX_PLASTICITY
170  std::stringstream sout;
171  sout << "State " << state;
172  LOGPZ_DEBUG(logger,sout.str().c_str());
173  #endif
174  }
175 
176  void ComputeTangent(TPZFMatrix<REAL> &tangent, TPZVec<REAL> &, int icase)
177  {
178  #ifdef LOG4CXX_PLASTICITY
179  LoggerPtr logger(Logger::getLogger("plasticity.erladenelson"));
180  #endif
181 
182  const int nVars = 6;
183  typedef TFad<nVars,REAL> TFAD;
184 
185  int i, j;
186  TPZTensor<TFAD> epsilon_FAD, sigma_FAD;
187  TFAD young_FAD;
188 
189  switch(icase)
190  {
191  case 1:
192  //ComputeYoung
193  gRefDeform.CopyTo(sigma_FAD);
194  for(i=0;i<nVars;i++)
195  sigma_FAD[i] . diff(i,nVars);
196  tangent.Redim(1,nVars);
197  ComputeYoung<TFAD, REAL>(sigma_FAD, young_FAD);
198  for(i=0; i<nVars; i++)
199  tangent(0,i) = young_FAD.dx(i);
200  break;
201 
202  case 0:
203  gRefDeform.CopyTo(epsilon_FAD);
204  for(i=0;i<nVars;i++)
205  epsilon_FAD[i] . diff(i,nVars);
206  epsilon_FAD.Multiply(-2.,1.);// multiplying by -2 to analise the effect of previous evaluated functions
207  ComputeStress(epsilon_FAD, sigma_FAD);
208  tangent.Redim(nVars,nVars);
209  for(i=0; i<nVars; i++)
210  for(j=0; j<nVars; j++)
211  tangent(i,j) = sigma_FAD[i].dx(j);
212  break;
213  }
214  #ifdef LOG4CXX_PLASTICITY
215  std::stringstream sout;
216  sout << "Matriz tangent " << tangent;
217  LOGPZ_DEBUG(logger,sout.str().c_str());
218  #endif
219  }
220 
221  void Residual(TPZFMatrix<REAL> &res,int icase)
222  {
223  #ifdef LOG4CXX_PLASTICITY
224  LoggerPtr logger(Logger::getLogger("plasticity.erladenelson"));
225  #endif
226  int i;
227  const int nVars = 6;
228  TPZTensor< REAL > epsilon, sigma;
229  REAL young;
230  switch(icase)
231  {
232  case 1:
233  //ComputeYoung
234  gRefDeform.CopyTo(sigma);
235  res.Redim(1,1);
236  ComputeYoung<REAL , REAL>(sigma, young);
237  res(0,0) = young;
238  break;
239 
240  case 0:
241  //
242  gRefDeform.CopyTo(epsilon);
243  epsilon.Multiply(-2.,1.); // multiplying by -2 to analise the effect of previous evaluated functions
244  ComputeStress(epsilon, sigma);
245  res.Redim(nVars,1);
246  for(i=0; i<nVars; i++)
247  res(i,0) = sigma[i];
248  break;
249  }
250 #ifdef LOG4CXX_PLASTICITY
251  std::stringstream sout;
252  sout << "Residual vector " << res;
253  LOGPZ_DEBUG(logger,sout.str().c_str());
254 #endif
255  }
256 
257 static void CheckConv()
258 {
259  const int nVars = 6;
260 
261  // Creating the LadeNelsonElasticResponse obejct
262  TPZLadeNelsonElasticResponse ERLadeNelson;
263  // setup with data from Sacramento River Sand
264  // Lade, Poul V., Kim, Moon K. Single Hardening Constitutive Model
265  // for soil, Rock and Concrete. Int. J. Solids Structures, vol32
266  // No14 pp 1963-1978,1995
267  ERLadeNelson.SetUp(0.28 /*Lambda*/, 900. /*M*/, 0.2 /*poisson*/, 14.7);
268  TPZFNMatrix<nVars> Epsilon(nVars,1), Range(nVars,1);
269  Epsilon(_XX_,0) = 0.17*0.10;
270  Epsilon(_YY_,0) = 0.13*0.10;
271  Epsilon(_ZZ_,0) = 0.11*0.10;
272  Epsilon(_XY_,0) = 0.7 *0.10;
273  Epsilon(_XZ_,0) = 0.5 *0.10;
274  Epsilon(_YZ_,0) = 0.3 *0.10;
275 
276  Range = Epsilon * (1./19.);
277  TPZVec< REAL > Coefs(1,1.);
278  CheckConvergence(ERLadeNelson, Epsilon, Range, Coefs);
279 }
280 
281 
283 
284 
285 };
286 
287 
288 template <class T>
290  SolveSigma(const TPZTensor<T> & epsilon_T, TPZTensor<T> & sigma_T) const
291 {
292  const int nVars = 6;
293  typedef TFad< nVars, T > TFAD_SIX;
294 
295  TFAD_SIX Young_FAD(T (0.));
296 
297  TPZTensor< TFAD_SIX > sigma_FAD(Young_FAD), // initializing with zero values
298  EEpsilon_FAD(Young_FAD),// Explicit initialization is
299  Res_FAD(Young_FAD),// necessary because 3rd derivatives
300  epsilon_FAD(Young_FAD);// may arise in the code
301 
302  TPZDiffMatrix<T> DResDSigma_T(nVars,nVars), Res_T(nVars,1), Sol_T(nVars, 1);
303 
304  int i;
305  REAL residual, refResidual = 0.;
306  EStatus status;
307 
308  for(i = 0 ; i < nVars; i++)
309  {
310  epsilon_FAD.fData[i].val() = epsilon_T.fData[i];
311  sigma_FAD .fData[i].val() = sigma_T .fData[i];
312  sigma_FAD .fData[i].diff(i,nVars);
313  //refResidual += pow(TPZExtractVal::val(sigma_T.fData[i]),2.);
314  }
315  //refResidual = max(sqrt(refResidual),1.e-6); // avoiding division by zero
316 
317  ComputeYoung<TFAD_SIX, T>(sigma_FAD, Young_FAD);
318  ApplyElasticTensor<TFAD_SIX, T>(Young_FAD, epsilon_FAD, EEpsilon_FAD);
319  //for(i = 0; i < nVars; i++)
320  Res_FAD = sigma_FAD;
321  Res_FAD.Add(EEpsilon_FAD, T(-1.));
322  ExtractTangent(Res_FAD, Res_T, residual, DResDSigma_T);
323 
324  do{
325  Sol_T = Res_T;
326  status = DResDSigma_T.Decompose_LU();
327  status = DResDSigma_T.Substitution(& Sol_T);
328 
329  for(i = 0; i < nVars; i++)sigma_FAD.fData[i].val() -= Sol_T(i,0);
330 
331  ComputeYoung<TFAD_SIX,T>(sigma_FAD, Young_FAD);
332  ApplyElasticTensor<TFAD_SIX,T>(Young_FAD, epsilon_FAD, EEpsilon_FAD);
333 
334  refResidual = 0.;
335  for(i = 0; i < nVars; i++)refResidual += pow(TPZExtractVal::val(EEpsilon_FAD.fData[i]),2.);
336  refResidual = sqrt(refResidual);
337 
338  Res_FAD = sigma_FAD;
339  Res_FAD.Add(EEpsilon_FAD, T(-1.));
340 
341  ExtractTangent(Res_FAD, Res_T, residual, DResDSigma_T);
342  }while(residual > 1.e-6 || residual/refResidual > 1.e-12);
343  //residual > 1.e-6 ensures that the residual will be small
344  // and residual/refResidual > 1.e-12 ensures that the residual is 9 orders
345  // of magnitude smaller than the stress state when it converges.
346 
347  for(i = 0; i < nVars; i++ )
348  sigma_T.fData[i] = sigma_FAD.fData[i].val();
349 }
350 
352  ComputeStress(const TPZTensor<REAL> & epsilon, TPZTensor<REAL> & sigma) const
353 {
354  REAL YoungGuess = 1.e10;
355 
356  ApplyElasticTensor<REAL, REAL>(YoungGuess, epsilon, sigma); // sigma initial guess coherent with the Young guess
357 
358  SolveSigma(epsilon, sigma); // sigma implicitly carries the young initial guess
359  // since the Young(sigma) will lead to the YoungGuess proposed value.
360 
361  return;
362 }
363 
364 template <class T>
366  ComputeStress(const TPZTensor<T> & epsilon_T, TPZTensor<T> & sigma_T) const
367 {
368  TPZTensor<REAL> epsilon, sigma;
369 
370  epsilon_T.CopyTo(epsilon);
371 
372  ComputeStress(epsilon, sigma); // Solving for the correct sigma
373 
374  sigma.CopyTo(sigma_T);
375 
376  SolveSigma(epsilon_T, sigma_T); // solving again using last solution
377  //as initial guess in order only to evaluate the derivatives
378 
379  return;
380 }
381 
382 template <class T, class TBASE>
384  ComputeYoung(const TPZTensor<T> & sigma, T & Young) const
385 {
386  REAL R = 6. * (1. + fPoisson) / (1. - 2. * fPoisson);
387  T I1 = sigma.I1();
388  T J2 = sigma.J2();
389  REAL pa2 = fPa * fPa;
390  //T Base = I1 * I1 / pa2 + J2 / pa2 * R;
391  T Base = (I1 * I1 + J2 * TBASE(R) ) / TBASE(pa2);
392  if((fLambda < 1E-12) )
393  {
394  Young = TBASE( fM * fPa);
395  return;
396  }
397  REAL BaseParameter = 1.E-12;
398  if((fabs(TPZExtractVal::val(Base)) < BaseParameter) )
399  {
400  // In the case the the averged stresses leads to less than
401  // Base * fPa the Elastic modulus is assumed constant and
402  // equal to the one at averaged stress = Base * fPa.
403  // This tricky change is necessary because the Young
404  // modulus increases with increasing stress state and the
405  // values for very small stress states near zero, leading
406  // to numerical instability (very large stress forecasts
407  // in the Newton scheme at TPZPlasticStep::Sigma.
408  Base = TBASE(BaseParameter);
409 #ifdef LOG4CXX_PLASTICITY
410  {
411  std::stringstream sout;
412  sout << "*** ComputeYoung *** Too small Elastic Modulus - Constraining it.";
413  LOGPZ_INFO(loggerPlasticity,sout.str().c_str());
414  }
415 #endif
416  }
417 
418  //Young = T( fM * fPa ) * pow( Base, fLambda );
419  Young = TBASE( fM * fPa ) * exp( TBASE(fLambda) * log( Base ) );
420 }
421 
422 template <class T, class TBASE>
424  ApplyElasticTensor(const T & Young, const TPZTensor<T> & Epsilon, TPZTensor<T> & sigma) const
425 {
426  // Evaluating the Lamè coefficients
427  TBASE TBase;
428  T Lambda = Young * TBASE(fPoisson/((1.+fPoisson)*(1.-2.*fPoisson)));
429  T Mu = Young / TBASE(2.*(1.+fPoisson));
430  T trace = Epsilon.I1();
431  sigma.Identity_T(TBase);
432  sigma.Multiply(trace,Lambda);
433  sigma.Add(Epsilon,Mu * TBASE(2.));
434 }
435 
436 template <class T, class VECTOR, class MATRIX>
438  ExtractTangent(const TPZTensor<T> & Res_T, VECTOR & ResVal, REAL & resnorm, MATRIX & tangent) const
439 {
440  const int nVars = 6;
441  int i,j;
442 // typedef TFad<nVars, REAL> TFAD;
443  // extract the values of the residual vector
444 
445  resnorm = 0.;
446 
447  for(i=0; i<nVars; i++)
448  {
449  ResVal(i,0) = Res_T.fData[i].val();
450  resnorm += pow(TPZExtractVal::val(ResVal(i,0)) , 2.);
451  }
452 
453  resnorm = sqrt(resnorm);
454 
455  // extract the partial derivatives to fill the tangent matrix
456  tangent.Reset();
457 
458  for(i=0; i<nVars; i++)
459  for(j=0; j<nVars; j++)
460  tangent(i,j) = Res_T.fData[i].dx(j);
461 
462 }
463 
464 #endif //TPZLADEKIMELASTICRESPONSE_H
465 
#define _XZ_
Definition: TPZTensor.h:29
void CheckConvergence(TConv &obj, TPZFMatrix< STATE > &state, TPZFMatrix< STATE > &range, TPZVec< REAL > &coefs)
Implements a general procedure to check whether the class TConv implements a consistente tangent matr...
Definition: checkconv.h:23
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
Definition: tfadfunc.h:140
void CopyTo(TPZTensor< T1 > &target) const
Definition: TPZTensor.h:819
void Add(const TPZTensor< T1 > &tensor, const T2 &constant)
Definition: TPZTensor.h:757
void Multiply(const T1 &multipl, const T2 &constant)
Definition: TPZTensor.h:766
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
Contains TPZDiffMatrix class which to hold the flux derivatives A B C and diffusive matrix coefficien...
void SetUp(REAL Lambda, REAL M, REAL poisson, REAL pa)
void ComputeStress(const TPZTensor< T > &epsilon_T, TPZTensor< T > &sigma_T) const
TPZManVector< T, 6 > fData
Definition: TPZTensor.h:652
void ExtractTangent(const TPZTensor< T > &Res_T, VECTOR &ResVal, REAL &resnorm, MATRIX &tangent) const
T I1() const
Definition: TPZTensor.h:903
void Residual(TPZFMatrix< REAL > &res, int icase)
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
TPZLadeNelsonElasticResponse(const TPZLadeNelsonElasticResponse &source)
void ComputeTangent(TPZFMatrix< REAL > &tangent, TPZVec< REAL > &, int icase)
TPZLadeNelsonElasticResponse & operator=(const TPZLadeNelsonElasticResponse &source)
#define LOGPZ_INFO(A, B)
Define log for informations.
Definition: pzlog.h:89
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define _XX_
Definition: TPZTensor.h:27
EStatus
Definition: pzdiffmatrix.h:17
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
Definition: tfad.h:64
#define _YZ_
Definition: TPZTensor.h:31
#define _XY_
Definition: TPZTensor.h:28
void ComputeYoung(const TPZTensor< T > &sigma, T &Young) const
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
string res
Definition: test.py:151
T J2() const
Definition: TPZTensor.h:927
void Read(TPZStream &buf, void *context) override
read objects from the stream
static REAL val(const int number)
Definition: pzextractval.h:21
#define _YY_
Definition: TPZTensor.h:30
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
#define _ZZ_
Definition: TPZTensor.h:32
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
Definition: pzreal.h:487
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ log
Definition: tfadfunc.h:130
void LoadState(TPZFMatrix< REAL > &state)
Matrix class to hold the flux derivatives A B C and diffusive matrix coefficients. Matrix.
Definition: pzdiffmatrix.h:27
Contains TPZStepSolver class which defines step solvers class.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ exp
Definition: tfadfunc.h:125
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
void Print(std::ostream &out) const
Extra utilities for TPZVec. Implementations of the saxpy, sscal, sdot, intercept, max and min functio...
Contains the implementation of the CheckConvergence function.
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
Definition: TPZSavable.h:67
void ApplyElasticTensor(const T &Young, const TPZTensor< T > &Epsilon, TPZTensor< T > &sigma) const
void SolveSigma(const TPZTensor< T > &epsilon_T, TPZTensor< T > &sigma_T) const
EStatus Decompose_LU()
Definition: pzdiffmatrix.h:382
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
void Identity_T(TBASE &)
Definition: TPZTensor.h:694