NeoPZ
TPZPlasticStep.cpp
Go to the documentation of this file.
1 
5 #include "TPZPlasticStep.h"
6 #include "TPZElasticResponse.h"
8 #include "TPZThermoForceA.h"
9 #include "TPZYCVonMises.h"
10 #include "TPZYCTresca.h"
11 #include "tpzyctrescaregularized.h"
12 #include "TPZYCLadeKim.h"
13 #include "TPZLadeKimThermoForceA.h"
14 #include "TPZYCSandlerDimaggio.h"
15 #include "TPZYCSandlerDimaggioL.h"
16 #include "TPZYCSandlerDimaggioL2.h"
17 #include "TPZSandlerDimaggio.h"
20 #include "pzfmatrix.h"
21 #include "pzstepsolver.h"
22 #include "pzvec_extras.h"
23 #include "TPZPlasticState.h"
24 #include "TPZYCDruckerPrager.h"
25 #include "TPZYCRankine.h"
26 
27 
29 
30 using namespace std;
31 
32 #include "tfad.h"
33 #include "pzlog.h"
34 
35 #ifdef LOG4CXX
36 static LoggerPtr pointloadconfig(Logger::getLogger("plasticity.loadconfig"));
37 static LoggerPtr plasticIntegrLogger(Logger::getLogger("plasticity.plasticIntegr"));
38 #endif
39 
40 #ifdef LOG4CXX
41 static LoggerPtr logger(Logger::getLogger("pz.PLASTIC_STEP.main"));
42 static LoggerPtr loggerx(Logger::getLogger("pz.PLASTIC_STEP.main"));
43 static LoggerPtr loggerPlasticResidual(Logger::getLogger("PLASTIC_RESIDUAL"));
44 static LoggerPtr loggerDEP1(Logger::getLogger("pz.PLASTIC_STEP.DEP1"));
45 static LoggerPtr loggerDEP2(Logger::getLogger("pz.PLASTIC_STEP.DEP2"));
46 #endif
47 
48 template <class YC_t, class TF_t, class ER_t>
50  return fPlasticMem.NElements() - 2;
51 }
52 
53 template <class YC_t, class TF_t, class ER_t>
55  fN = state;
56 
57 #ifdef LOG4CXX_PLASTICITY
58  {
59  std::stringstream sout1, sout2;
60  sout1 << ">>> SetState_Internal ***";
61  sout2 << "\nfN.m_eps_p << " << fN.m_eps_p << "\nfN.m_hardening << " << fN.m_hardening;
62  LOGPZ_DEBUG(logger, sout1.str().c_str());
63  LOGPZ_DEBUG(logger, sout2.str().c_str());
64  }
65 #endif
66 }
67 
68 template <class YC_t, class TF_t, class ER_t>
70  return fN;
71 }
72 
73 template <class YC_t, class TF_t, class ER_t>
75  const TPZPlasticState<REAL> & state) {
76  int multipl = SignCorrection();
77  fN = state;
78  fN.m_eps_p *= multipl;
79  fN.m_eps_t *= multipl;
80 
81 #ifdef LOG4CXX_PLASTICITY
82  {
83  std::stringstream sout1, sout2;
84  sout1 << ">>> SetUp ***";
85  sout2 << "\nfN.m_eps_p << " << fN.m_eps_p << "\nfN.m_hardening << " << fN.m_hardening;
86  LOGPZ_DEBUG(logger, sout1.str().c_str());
87  LOGPZ_DEBUG(logger, sout2.str().c_str());
88  }
89 #endif
90 }
91 
92 template <class YC_t, class TF_t, class ER_t>
94  int multipl = SignCorrection();
96  N.m_eps_p *= multipl;
97  N.m_eps_t *= multipl;
98 
99  return N;
100 }
101 
102 template <class YC_t, class TF_t, class ER_t>
104  const TPZTensor<REAL> & epsTotal) {
105  fN.m_eps_t = epsTotal;
106 
107 #ifdef LOG4CXX_PLASTICITY
108  {
109  std::stringstream sout1, sout2;
110  sout1 << ">>> SetUp ***";
111  LOGPZ_DEBUG(logger, sout1.str().c_str());
112  }
113 #endif
114 }
115 
116 template <class YC_t, class TF_t, class ER_t>
118  TPZTensor<REAL> epsTotal_Internal(epsTotal);
119  epsTotal_Internal *= SignCorrection();
120  ApplyStrain_Internal(epsTotal_Internal);
121 }
122 
123 template <class YC_t, class TF_t, class ER_t>
125 
126  bool require_tangent_Q = true;
127  if (!tangent) {
128  require_tangent_Q = false;
129  }
130 
131 #ifdef PZDEBUG
132  // Check for required dimensions of tangent
133  if (!(tangent->Rows() == 6 && tangent->Cols() == 6)) {
134  std::cerr << "Unable to compute the tangent operator. Required tangent array dimensions are 6x6." << std::endl;
135  DebugStop();
136  }
137 #endif
138 
139  if (require_tangent_Q) {
140  DebugStop(); // implemented this functionality.
141  }
142 
143  int multipl = SignCorrection();
144  TPZTensor<REAL> epsTotal_Internal(epsTotal);
145  epsTotal_Internal *= multipl;
146  ApplyStrainComputeSigma_Internal(epsTotal_Internal, sigma);
147  sigma *= multipl;
148 }
149 
150 template <class YC_t, class TF_t, class ER_t>
152  int multipl = SignCorrection();
153  TPZTensor<REAL> epsTotal_Internal(epsTotal);
154  epsTotal_Internal *= multipl;
155  ApplyStrainComputeDep_Internal(epsTotal_Internal, sigma, Dep);
156  sigma *= multipl;
157 }
158 
159 template <class YC_t, class TF_t, class ER_t>
161  TPZTensor<REAL> sigma_Internal(sigma);
162  sigma_Internal *= SignCorrection();
163  ApplyLoad_Internal(sigma_Internal, epsTotal);
164  epsTotal *= SignCorrection();
165 }
166 
167 template <class YC_t, class TF_t, class ER_t>
169  TPZTensor<REAL> epsTotal_Internal(epsTotal);
170  epsTotal_Internal *= SignCorrection();
171 
172  Phi_Internal(epsTotal_Internal, phi);
173 
174  return;
175 }
176 
177 template <class YC_t, class TF_t, class ER_t>
179  fInterfaceTensionSign = (s >= 0) ? 1 : -1;
180 }
181 
182 template <class YC_t, class TF_t, class ER_t>
184  return fMaterialTensionSign * fInterfaceTensionSign;
185 }
186 
187 template <class YC_t, class TF_t, class ER_t>
188 template<class T>
190  TPZTensor<T> & sigma_T,
191  T & A_T)const {
192  // variable representing the stress and elastic deformation
193  TPZTensor<T> epsE_T(state_T.EpsT());
194  // subtract the value of the current plastic deformation
195  epsE_T.Add(state_T.EpsP(), T(-1.));
196  // compute the stress of the elastic response
197  fER.ComputeStress(epsE_T, sigma_T);
198  // compute the value of the thermo dynamical force for the given damage variable
199  A_T = fTFA.Compute(state_T.VolHardening());
200 }
201 
202 template <class YC_t, class TF_t, class ER_t>
204 #ifdef LOG4CXX_PLASTICITY
205  {
206  std::stringstream sout1, sout2;
207  sout1 << ">>> IsStrainElastic ***";
208  sout2 << "\nstate.EpsT() << " << state.EpsT();
209  LOGPZ_DEBUG(logger, sout1.str().c_str());
210  LOGPZ_DEBUG(logger, sout2.str().c_str());
211  }
212 #endif
213 
214  TPZTensor<REAL> sigma;
215  REAL A;
216 
217  ComputePlasticVars<REAL>(state, sigma, A);
218 
219  // compute the value of the yield functions
220  TPZManVector<REAL, 10> phi(YC_t::NYield);
221 
222  fYC.Compute(sigma, A, phi, 0);
223  // verify if any yield function indicates plastification
224  int i;
225  for (i = 0; i < YC_t::NYield; i++) {
226  if (phi[i] > 0.) break;
227  }
228 
229 
230  // if we are in the elastic range
231  if (i == YC_t::NYield) {
232 #ifdef LOG4CXX_PLASTICITY
233  {
234  std::stringstream sout;
235  sout << "*** IsStrainElastic *** Strain yet in the elastic range - no damage variable needs update.\nExiting method ApplyStrain."
236  << "\n Phi = ";
237  for (int j = 0; j < YC_t::NYield; j++)sout << phi[j] << " ";
238  LOGPZ_DEBUG(logger, sout.str().c_str());
239  }
240 #endif
241  return true;
242  }
243 #ifdef LOG4CXX_PLASTICITY
244  {
245  std::stringstream sout;
246  sout << "*** IsStrainElastic *** Strain exceeds the elastic range - damage variables need update"
247  << "\n Phi = ";
248  for (int j = 0; j < YC_t::NYield; j++)sout << phi[j] << " ";
249  LOGPZ_DEBUG(logger, sout.str().c_str());
250  }
251 #endif
252  return false;
253 
254 }
255 
256 template <class YC_t, class TF_t, class ER_t>
258 
259 #ifdef LOG4CXX
260  {
261  std::stringstream sout;
262  sout << ">>> ApplyStrain_Internal *** Imposed epsTotal << " << epsTotal;
263  LOGPZ_DEBUG(logger, sout.str().c_str());
264  }
265 #endif
266 #ifdef LOG4CXX_PLASTICITY
267  {
268  std::stringstream sout;
269  sout << ">>> ApplyStrain_Internal *** Imposed epsTotal << " << epsTotal;
270  LOGPZ_DEBUG(logger, sout.str().c_str());
271  }
272 #endif
273 
274  //ProcessStrainNoSubIncrement(epsTotal);
275  ProcessStrain(epsTotal);
276 
277  int n = fPlasticMem.NElements();
278 
279  // load the integrated values as the current state
280  TPZPlasticStep<YC_t, TF_t, ER_t>::SetState_Internal(fPlasticMem[n - 1].m_elastoplastic_state);
281 
282 #ifdef LOG4CXX_PLASTICITY
283  {
284  std::stringstream sout;
285  sout << "*** ProcessStrain *** Exiting Method.";
286  LOGPZ_DEBUG(logger, sout.str().c_str());
287  }
288 #endif
289 
290 }
291 
292 template <class YC_t, class TF_t, class ER_t>
294 
295 #ifdef LOG4CXX_PLASTICITY
296  {
297  std::stringstream sout1;
298  sout1 << ">>> ProcessStrainNoSubIncrement ***";
299  LOGPZ_DEBUG(logger, sout1.str().c_str());
300  }
301 #endif
302 
303  REAL yieldMultipl = 0;
304 
305  fPlasticMem.Resize(0);
306  PushPlasticMem(fN,
307  0. /*k*/,
308  0. /*lambda*/,
309  TPZManVector<REAL, YC_t::NYield>(YC_t::NYield, 0)/*delGamma*/,
310  TPZManVector<int, YC_t::NYield>(YC_t::NYield, 0)/*validEqs*/,
311  0 /*forceYield*/);
312 
313  TPZPlasticState<REAL> stateAtYield(fN), Np1(fN); // Np1 state with fN guesses
314  Np1.m_eps_t = epsTotal;
315 
316  bool elastic = true;
317 
318  if (ep == EForceElastic) {
319 #ifdef LOG4CXX_PLASTICITY
320  {
321  std::stringstream sout1;
322  sout1 << ">>> ProcessStrainNoSubIncrement *** behaviour imposed to be Elastic";
323  LOGPZ_DEBUG(logger, sout1.str().c_str());
324  }
325 #endif
326  elastic = true;
327  }
328 
329  if (ep == EForcePlastic) {
330 #ifdef LOG4CXX_PLASTICITY
331  {
332  std::stringstream sout1;
333  sout1 << ">>> ProcessStrainNoSubIncrement *** behaviour imposed to be Plastic";
334  LOGPZ_DEBUG(logger, sout1.str().c_str());
335  }
336 #endif
337  elastic = false;
338  }
339 
340  if (ep == EAuto) elastic = IsStrainElastic(Np1);
341 
342  if (elastic) {
343  PushPlasticMem(Np1,
344  1. /*k*/,
345  0. /*lambda unused - elastic state*/,
346  TPZManVector<REAL, YC_t::NYield>(YC_t::NYield, 0)/*delGamma*/,
347  TPZManVector<int, YC_t::NYield>(YC_t::NYield, 0)/*validEqs*/,
348  0 /*forceYield*/);
349  return;
350  }
351 
352  // Plastic Integration needed
353 
354  yieldMultipl = FindPointAtYield(Np1.EpsT(), stateAtYield);
355 
356  PushPlasticMem(stateAtYield,
357  yieldMultipl /*k*/,
358  0. /*lambda unused - elastic state*/,
359  TPZManVector<REAL, YC_t::NYield>(YC_t::NYield, 0)/*delGamma*/,
360  TPZManVector<int, YC_t::NYield>(YC_t::NYield, 0)/*validEqs*/,
361  0 /*forceYield*/);
362 
363  REAL multipl = 0.99;
364  TPZTensor<REAL> DeltaEpsP_guess = Np1.m_eps_t;
365  DeltaEpsP_guess.Add(stateAtYield.m_eps_t, -1.);
366  Np1.m_eps_p.Add(DeltaEpsP_guess, multipl);
367 
368 
369  //PlasticIntegrate(stateAtYield, Np1, fIntegrTol);
370  int succeeded;
371 
372  TPZManVector<REAL, YC_t::NYield> delGamma(YC_t::NYield, 0.);
373  TPZManVector<int, YC_t::NYield> validEqs(YC_t::NYield, 0);
374 
375  REAL normEpsPErr = 0.;
376  // int counter = 0;
377  REAL lambda = 0.;
378 
379  succeeded = PlasticLoop(stateAtYield, Np1, delGamma, normEpsPErr, lambda, validEqs);
380 
381  if (normEpsPErr < fIntegrTol && succeeded) {
382  PushPlasticMem(Np1, 1., lambda, delGamma, validEqs, fYC.GetForceYield());
383  return;
384  }
385 
386  TPZTensor<REAL> deltaEpsTotal(Np1.EpsT());
387  deltaEpsTotal.Add(stateAtYield.EpsT(), -1.);
388  TPZFMatrix<REAL> residual_mat(6, 1);
389 
390  REAL resnorm = 0.;
391  do {
392 
393 
394 
395  Np1.m_eps_t.Add(deltaEpsTotal, 1.);
396  succeeded = PlasticLoop(stateAtYield, Np1, delGamma, normEpsPErr, lambda, validEqs);
397 
398  TPZTensor<REAL> res(Np1.m_eps_t), epstyield(stateAtYield.m_eps_t);
399  int k;
400  for (k = 0; k < 6; k++)residual_mat(k, 0) = res.fData[k] - epstyield.fData[k];
401  for (k = 0; k < 6; k++)resnorm += pow(residual_mat(k, 0), 2.);
402  resnorm = sqrt(resnorm);
403 
404 
405  } while (resnorm > 1.e-3 && succeeded);
406 
407  // succeeded = PlasticLoop(stateAtYield, Np1, delGamma, normEpsPErr, lambda, validEqs);
408  PushPlasticMem(Np1, 1., lambda, delGamma, validEqs, fYC.GetForceYield());
409 
410  cout << "\n ProcessStrainNoSubIncrement ";
411  cout << "\n fIntegrTol = " << fIntegrTol;
412  cout << "\n lambda = " << lambda;
413  cout << "\n delGamma = " << delGamma;
414  cout << "\n fIntegrTol = " << fIntegrTol;
415 
416 }
417 
418 template <class YC_t, class TF_t, class ER_t>
420 
421 #ifdef LOG4CXX_PLASTICITY
422  {
423  std::stringstream sout1;
424  sout1 << ">>> ProcessStrain ***";
425  LOGPZ_DEBUG(logger, sout1.str().c_str());
426  }
427 #endif
428 
429  REAL yieldMultipl = 0;
430 
431  fPlasticMem.Resize(0);
432  PushPlasticMem(fN,
433  0. /*k*/,
434  0. /*lambda*/,
435  TPZManVector<REAL, YC_t::NYield>(YC_t::NYield, 0)/*delGamma*/,
436  TPZManVector<int, YC_t::NYield>(YC_t::NYield, 0)/*validEqs*/,
437  0 /*forceYield*/);
438 
439  TPZPlasticState<REAL> stateAtYield(fN),
440  Np1(fN); // Np1 state with fN guesses
441  Np1.m_eps_t = epsTotal;
442 
443  bool elastic = true;
444 
445  if (ep == EForceElastic) {
446 #ifdef LOG4CXX_PLASTICITY
447  {
448  std::stringstream sout1;
449  sout1 << ">>> ProcessStrain *** behaviour imposed to be Elastic";
450  LOGPZ_DEBUG(logger, sout1.str().c_str());
451  }
452 #endif
453  elastic = true;
454  }
455 
456  if (ep == EForcePlastic) {
457 #ifdef LOG4CXX_PLASTICITY
458  {
459  std::stringstream sout1;
460  sout1 << ">>> ProcessStrain *** behaviour imposed to be Plastic";
461  LOGPZ_DEBUG(logger, sout1.str().c_str());
462  }
463 #endif
464  elastic = false;
465  }
466 
467  if (ep == EAuto) {
468  bool result = IsStrainElastic(Np1);
469  elastic = (result == 1);
470  }
471 
472  if (elastic) {
473  PushPlasticMem(Np1,
474  1. /*k*/,
475  0. /*lambda unused - elastic state*/,
476  TPZManVector<REAL, YC_t::NYield>(YC_t::NYield, 0)/*delGamma*/,
477  TPZManVector<int, YC_t::NYield>(YC_t::NYield, 0)/*validEqs*/,
478  0 /*forceYield*/);
479  return;
480  }
481 
482  // Plastic Integration needed
483 
484  yieldMultipl = FindPointAtYield(Np1.EpsT(), stateAtYield);
485 
486  PushPlasticMem(stateAtYield,
487  yieldMultipl /*k*/,
488  0. /*lambda unused - elastic state*/,
489  TPZManVector<REAL, YC_t::NYield>(YC_t::NYield, 0)/*delGamma*/,
490  TPZManVector<int, YC_t::NYield>(YC_t::NYield, 0)/*validEqs*/,
491  0 /*forceYield*/);
492 
493  REAL multipl = 0.99;
494  TPZTensor<REAL> DeltaEpsP_guess = Np1.m_eps_t;
495  DeltaEpsP_guess.Add(stateAtYield.m_eps_t, -1.);
496  Np1.m_eps_p.Add(DeltaEpsP_guess, multipl);
497 
498  PlasticIntegrate(stateAtYield, Np1, fIntegrTol);
499 
500 
501 
502 }
503 
504 template <class YC_t, class TF_t, class ER_t>
506  TPZTensor<REAL> &sigma,
507  TPZFMatrix<REAL> &Dep) {
508 
509 #ifdef LOG4CXX
510  {
511  std::stringstream sout;
512  sout << ">>> ApplyStrainComputeDep_Internal *** Imposed epsTotal << " << epsTotal;
513  LOGPZ_DEBUG(logger, sout.str().c_str());
514  }
515 #endif
516 #ifdef LOG4CXX_PLASTICITY
517  {
518  std::stringstream sout;
519  sout << ">>> ApplyStrainComputeDep_Internal *** Imposed epsTotal << " << epsTotal;
520  LOGPZ_DEBUG(logger, sout.str().c_str());
521  }
522 #endif
523 
524  ApplyStrain_Internal(epsTotal);
525 
526 #ifdef LOG4CXX_PLASTICITY
527  {
528  std::stringstream sout;
529  sout << "*** ApplyStrainComputeDep *** \n Calling ComputeDep";
530  LOGPZ_DEBUG(logger, sout.str().c_str());
531  }
532 #endif
533 
534  ComputeDep(sigma, Dep);
535  /*
536  TPZTensor<STATE> sigma2;
537  TPZFNMatrix<36,STATE> Dep2(6,6);
538  ComputeDep2(sigma2, Dep2);
539 #ifdef LOG4CXX
540  {
541  std::stringstream sout1;
542  sout1 << "Imposed epsTotal << " << epsTotal
543  << "\nResulted in Sigma = " << sigma << "\nDep = \n" << Dep << std::endl;
544 
545  LOGPZ_DEBUG(loggerDEP1,sout1.str());
546  }
547 #endif
548 #ifdef LOG4CXX
549  {
550  std::stringstream sout1;
551  sout1 << "Imposed epsTotal << " << epsTotal
552  << "\nResulted in Sigma = " << sigma2 << "\nDep = \n" << Dep2 << std::endl;
553 
554  LOGPZ_DEBUG(loggerDEP2,sout1.str());
555  }
556 #endif
557  */
558 }
559 
560 /*
561 template <class YC_t, class TF_t, class ER_t>
562 void TPZPlasticStep<YC_t, TF_t, ER_t>::ComputeDep2(TPZTensor<REAL> & sigma, TPZFMatrix<REAL> &Dep)
563 {
564 
565  const int nyield = YC_t::NYield;
566  const int nVarsResidual = 7+nyield;
567  const int nVarsTensor = 6;
568 
569  int i,j;
570 
571  typedef TFad<nVarsTensor, REAL> TFAD;
572  typedef TFad<nVarsResidual, TFAD> TFAD_FAD;
573 
574  REAL normEpsPErr, resnorm;
575 
576  EStatus status;
577 
578  TPZPlasticState<TFAD_FAD> Nk_FADFAD,
579  Nkp1_FADFAD;
580 
581  TPZPlasticState<REAL > Nk, Nkp1;
582 
583  TPZManVector<TFAD_FAD, nyield> delGamma_FADFAD(nyield);
584  TPZManVector<REAL, nyield> delGamma(nyield);
585  TPZManVector<TFAD_FAD, nVarsResidual> epsRes_FADFAD(nVarsResidual);
586  TPZManVector<REAL, nVarsResidual> epsRes(nVarsResidual);
587  TPZDiffMatrix< TFAD > tangent_FAD(nVarsResidual,nVarsResidual),
588  residual_FAD(nVarsResidual,1),
589  Sol_FAD(nVarsResidual,1);
590 
591  TPZPlasticState<TFAD> Nk_FAD;
592  TPZTensor<TFAD> sigma_FAD;
593  TFAD A_FAD;
594 
595  TPZTensor<REAL> diffPlasticStrain;
596 
597  int n = fPlasticMem.NElements();
598 
599  if(n < 2)
600  {
601 #ifdef LOG4CXX
602  if(plasticIntegrLogger->isDebugEnabled())
603  {
604  std::stringstream sout;
605  sout << ">>> ComputeDep *** Insufficient Plastic Mem Entries: " << n << ".";
606  LOGPZ_ERROR(plasticIntegrLogger,sout.str().c_str());
607  }
608 #endif
609 #ifdef LOG4CXX_PLASTICITY
610  {
611  std::stringstream sout;
612  sout << ">>> ComputeDep *** Insufficient Plastic Mem Entries: " << n << ".";
613  LOGPZ_ERROR(logger,sout.str().c_str());
614  }
615 #endif
616  return;
617  }
618 #ifdef LOG4CXX_PLASTICITY
619  {
620  std::stringstream sout;
621  sout << ">>> ComputeDep *** Plastic Mem Entries: " << n << ".";
622  if( n == 2 ) sout << "\nTwo entries indicate pure elastic step";
623  LOGPZ_DEBUG(logger,sout.str().c_str());
624  }
625 #endif
626 
627  if(n==2)
628  {// pure elastic step - no plastic loop necessary
629  fPlasticMem[1].m_elastoplastic_state.CopyTo(Nk_FAD);
630  for(i = 0; i < nVarsTensor; i++)Nk_FAD.m_eps_t.fData[i].diff(i,nVarsTensor);
631 
632  }else
633  {// plastification occurs
634 
635  // plastic Loop analogue with derivative evaluation
636 
637  // Initializing last available elastic step
638  fPlasticMem[1].m_elastoplastic_state.CopyTo(Nk_FADFAD);
639  for(j = 0; j < nVarsTensor; j++)Nk_FADFAD.m_eps_t.fData[j].val().fastAccessDx(j) = fPlasticMem[1].fK;
640 
641  TPZManVector<STATE,10> pivots(nVarsResidual,0.);
642 
643  REAL disturbFactor = sqrt(fResTol); // imposing an initial guess very close to the real
644  // solution in order to ensure residual drop and convergence.
645  // This is very important to accumulate good FAD derivatives
646 
647  for(i = 2; i < n; i++)
648  {
649  InitializePlasticFAD(fPlasticMem[i].m_elastoplastic_state,
650  fPlasticMem[i].fDelGamma,
651  Nkp1_FADFAD,
652  delGamma_FADFAD,
653  nVarsResidual);
654  fYC.SetForceYield(fPlasticMem[i].fForceYield); // imposing the same assumptions made in the plasticLoop
655 
656  Nkp1_FADFAD.m_hardening.val().val() -=
657  ( fPlasticMem[i].m_elastoplastic_state.m_hardening - fPlasticMem[i-1].m_elastoplastic_state.m_hardening )
658  * disturbFactor;
659 
660  for(j = 0; j < nyield; j++)delGamma_FADFAD[j].val().val() *= (1.0 - disturbFactor);
661 
662  for(j = 0; j < nVarsTensor; j++)
663  {
664  Nkp1_FADFAD.m_eps_p.fData[j].val().val() -=
665  ( fPlasticMem[i].m_elastoplastic_state.m_eps_p.fData[j] - fPlasticMem[i-1].m_elastoplastic_state.m_eps_p.fData[j] )
666  * disturbFactor;
667  Nkp1_FADFAD.m_eps_t.fData[j].val().diff(j, nVarsTensor);
668  Nkp1_FADFAD.m_eps_t.fData[j].val().fastAccessDx(j) = fPlasticMem[i].fK; // setting the derivatives of EpsT with respect to deltaEpsT
669  }
670 
671 #ifdef LOG4CXX_PLASTICITY
672  {
673  std::stringstream sout;
674  sout << "*** ComputeDep *** Before Matrix Invertion: Plastic step number " << i-1 << " of " << n-1
675  << "\n*Nk_FADFAD=\n" << setw(10) << Nk_FADFAD
676  << "\n*Nkp1_FADFAD=\n" << setw(10) << Nkp1_FADFAD
677  << "\n*delGamma_FADFAD=\n" << setw(10) << delGamma_FADFAD;
678  LOGPZ_DEBUG(logger,sout.str().c_str());
679  }
680 #endif
681 
682  int NewtonCounter = 0;
683 
684  do{//(resnorm > fResTol && NewtonCounter < fMaxNewton)
685 
686  PlasticResidual<TFAD_FAD, TFAD_FAD>(Nk_FADFAD, Nkp1_FADFAD,
687  delGamma_FADFAD, epsRes_FADFAD,
688  normEpsPErr);
689 
690 
691 // PlasticResidualRK<TFAD_FAD, TFAD_FAD>(Nk_FADFAD, Nkp1_FADFAD,
692 // delGamma_FADFAD, epsRes_FADFAD,
693 // normEpsPErr);
694 
695  tangent_FAD.Reset(); // resets the LU Decomposition flag
696 
697  int precond = 1;
698  int resetInvalidEqs = 1;
699  ExtractTangent(epsRes_FADFAD, residual_FAD,
700  resnorm, tangent_FAD, // TPZFMatrix for T1=fad<real> type
701  fPlasticMem[i].fValidEqs, pivots,
702  precond, resetInvalidEqs);
703 #ifdef LOG4CXX
704  TPZDiffMatrix< TFAD > tangentcopy(tangent_FAD);
705 #endif
706  status = tangent_FAD.Decompose_LU();
707  if(status == EZeroPivot)
708  {
709  std::stringstream sout;
710  sout << "*** ComputeDep *** ### Decompose_LU error! - ZeroPivot ### No inversion will be performed";
711 #ifdef LOG4CXX
712  sout << "\nMatrix before decomposition\n";
713  sout << tangentcopy;
714  LOGPZ_ERROR(plasticIntegrLogger,sout.str().c_str());
715 #endif
716 #ifdef LOG4CXX_PLASTICITY
717  LOGPZ_ERROR(logger,sout.str().c_str());
718 #endif
719  cout << endl << sout.str().c_str();
720  }
721 
722  Sol_FAD = residual_FAD;
723  status = tangent_FAD.Substitution(&Sol_FAD);
724  if(status != EOk)
725  {
726  std::stringstream sout;
727  if(status == EIncompDim)sout << "*** ComputeDep *** ### LU Substitution error! - IncompatibleDimensions ### No inversion will be performed";
728  if(status == EZeroPivot)sout << "*** ComputeDep *** ### LU Substitution error! - ZeroPivot ### No inversion will be performed";
729 #ifdef LOG4CXX
730  LOGPZ_ERROR(plasticIntegrLogger,sout.str().c_str());
731 #endif
732 #ifdef LOG4CXX_PLASTICITY
733  LOGPZ_ERROR(logger,sout.str().c_str());
734 #endif
735  cout << endl << sout.str().c_str();
736  }
737 
738 
739 // REAL lambda = UpdatePlasticVars(Nk_FADFAD, Nkp1_FADFAD,
740 // delGamma_FADFAD, epsRes_FADFAD,
741 // Sol_FAD, fPlasticMem[i].fValidEqs,
742 // 0); //Do not update variables internally
743 
744 
745  REAL lambda = 1.; // forcing unity because the guess is very close to the solution
746 
747 
748 #ifdef LOG4CXX_PLASTICITY
749  {
750  std::stringstream sout;
751  sout << "*** ComputeDep *** After " << NewtonCounter
752  << "-th Matrix Invertion: Plastic step number " << i-1 << " of " << n-1
753  << "\nSol_FAD=\n " << setw(10) << Sol_FAD
754  << "\nepsRes_FADFAD=\n " << setw(10) << epsRes_FADFAD
755  << "\nNkp1_FADFAD=\n" << setw(10) << Nkp1_FADFAD
756  << "\ndelGamma_FADFAD=\n" << delGamma_FADFAD
757  << "\nfLambda = " << setw(10) << lambda;
758  LOGPZ_DEBUG(logger,sout.str().c_str());
759  }
760 #endif
761 
762  for(j=0; j<nVarsTensor; j++) Nkp1_FADFAD.m_eps_p.fData[j].val() -= lambda*Sol_FAD(j);
763  Nkp1_FADFAD.m_hardening.val() -= lambda*Sol_FAD(j++);
764  for(j=0; j<YC_t::NYield; j++) delGamma_FADFAD[j].val() -= lambda*Sol_FAD(j+7);
765 
766  for(j=0;j<nVarsTensor;j++)
767  {
768  Nk .m_eps_p.fData[j] = Nk_FADFAD .m_eps_p.fData[j].val().val();
769  Nk .m_eps_t.fData[j] = Nk_FADFAD .m_eps_t.fData[j].val().val();
770  Nkp1.m_eps_p.fData[j] = Nkp1_FADFAD.m_eps_p.fData[j].val().val();
771  Nkp1.m_eps_t.fData[j] = Nkp1_FADFAD.m_eps_t.fData[j].val().val();
772  }
773  Nk .m_hardening = Nk_FADFAD. m_hardening.val().val();
774  Nkp1.m_hardening = Nkp1_FADFAD.m_hardening.val().val();
775  for(j=0; j<YC_t::NYield; j++) delGamma[j] = delGamma_FADFAD[j].val().val();
776 
777  PlasticResidual<REAL, REAL>(Nk, Nkp1, delGamma, epsRes, normEpsPErr);
778  //PlasticResidual<TFAD_FAD, TFAD_FAD>(Nk_FADFAD, Nkp1_FADFAD, delGamma_FADFAD, epsRes_FADFAD, normEpsPErr);
779 
780  // updating the residual
781  for(j=0; j < nyield; j++)
782  if(fPlasticMem[i].fValidEqs[j] == 0)epsRes[j + 7] = 0.;
783  resnorm = 0.;
784  for(j=0; j < nVarsResidual; j++)
785  resnorm += pow(epsRes[j] , 2.);
786  resnorm = sqrt(resnorm);
787 
788  NewtonCounter++;
789  }while((resnorm > fResTol && NewtonCounter < fMaxNewton) || NewtonCounter < 2);
790 
791  for(j = 0; j < 6; j++)diffPlasticStrain.fData[j] = Nkp1_FADFAD.m_eps_p.fData[j].val().val()
792  - fPlasticMem[i].m_elastoplastic_state.m_eps_p.fData[j];
793 
794 #ifdef LOG4CXX
795  {
796  std::stringstream sout;
797  sout << "*** ComputeDep *** substep " << i-1 << " of " << n-2
798  << " solved with " << NewtonCounter << " iterations and residual = " << resnorm;
799  if(resnorm > fResTol)
800  {
801  sout << "\n#### Truncated Newton ####. Results are unpredictable";
802  sout << "\nDifferences in the plastic strain:" << diffPlasticStrain;
803  sout << "\nDifferences in alpha:" << Nkp1_FADFAD.m_hardening.val().val() - fPlasticMem[i].m_elastoplastic_state.m_hardening;
804  sout << "\nAlpha = " << fPlasticMem[i].m_elastoplastic_state.m_hardening;
805  LOGPZ_WARN(plasticIntegrLogger,sout.str().c_str());
806  }else
807  {
808  LOGPZ_DEBUG(plasticIntegrLogger,sout.str().c_str());
809  }
810  }
811 #endif
812 
813 #ifdef LOG4CXX_PLASTICITY
814  {
815  std::stringstream sout;
816  sout << "*** ComputeDep *** substep " << i-1 << " of " << n-2
817  << " solved with " << NewtonCounter << " iterations and residual = " << resnorm;
818  if(resnorm > fResTol)
819  {
820  sout << "\n#### Truncated Newton ####. Results are unpredictable";
821  sout << "\nDifferences in the plastic strain:" << diffPlasticStrain;
822  sout << "\nDifferences in alpha:" << Nkp1_FADFAD.m_hardening.val().val() - fPlasticMem[i].m_elastoplastic_state.m_hardening;
823  sout << "\nAlpha = " << fPlasticMem[i].m_elastoplastic_state.m_hardening;
824  LOGPZ_WARN(logger,sout.str().c_str());
825  }else
826  {
827  LOGPZ_DEBUG(logger,sout.str().c_str());
828  }
829  }
830 #endif
831 
832  // substep marching
833  for(j = 0; j < nVarsTensor; j++)
834  {
835  Nk_FADFAD.m_eps_t.fData[j].val() = Nkp1_FADFAD.m_eps_t.fData[j].val(); // ignoring first derivatives
836  Nk_FADFAD.m_eps_p.fData[j].val() = Nkp1_FADFAD.m_eps_p.fData[j].val(); // ignoring first derivatives
837  }
838  Nk_FADFAD.m_hardening.val() = Nkp1_FADFAD.m_hardening.val();// ignoring first derivatives
839  }
840 
841  // decreasing derivative order
842  for(i = 0; i < nVarsTensor; i++)
843  {
844  Nk_FAD.m_eps_t.fData[i] = Nk_FADFAD.m_eps_t.fData[i].val();
845  Nk_FAD.m_eps_p.fData[i] = Nk_FADFAD.m_eps_p.fData[i].val();
846  }
847  Nk_FAD.m_hardening = Nk_FADFAD.m_hardening.val();
848 
849  }// end of plasticLoop analogue
850 
851  //at this point, all the residual variables should contain their real derivatives to detaEpsT
852  // in the case the loading is either elastic or elastoplastic.
853  ComputePlasticVars(Nk_FAD, sigma_FAD, A_FAD);
854 
855  for(i = 0; i < nVarsTensor; i++)for(j = 0; j < nVarsTensor; j++)Dep(i,j) = sigma_FAD.fData[i].dx(j);
856 
857 #ifdef LOG4CXX_PLASTICITY
858  {
859  std::stringstream sout;
860  sout << "*** ComputeDep *** \nsigma_FAD= \n" << sigma_FAD
861  << "\nDep =\n" << Dep;
862  LOGPZ_DEBUG(logger,sout.str().c_str());
863  }
864 #endif
865 
866  sigma_FAD.CopyTo(sigma);
867 
868 }
869  */
870 
871 template <class YC_t, class TF_t, class ER_t>
873 
874  const int nyield = YC_t::NYield;
875  const int nVarsResidual = 7 + nyield;
876  const int nVarsTensor = 6;
877 
878  int j;
879 
880  typedef TFad<nVarsTensor, REAL> TFAD;
881  typedef TFad<nVarsResidual, REAL> TFAD_RES;
882 
883  REAL normResidual, normResidual2, resnorm;
884 
885  EStatus status;
886 
887  TPZPlasticState<TFAD_RES> Nk_FADRES, Nkp1_FADRES;
888 
889  TPZPlasticState<REAL > Nk, Nkp1;
890 
891  TPZManVector<TFAD_RES, nyield> delGamma_FADRES(nyield);
892  TPZManVector<REAL, nyield> delGamma(nyield);
893 
894  TPZManVector<TFAD, nyield> delGamma_FAD(nyield);
895 
896  TPZManVector<TFAD_RES, nVarsResidual> Residual_FADRES(nVarsResidual);
897  TPZManVector<TFAD, nVarsResidual> Residual_FAD(nVarsResidual);
898  TPZManVector<REAL, nVarsResidual> epsRes(nVarsResidual);
899  TPZDiffMatrix< REAL > tangent(nVarsResidual, nVarsResidual), residual_RES(nVarsResidual, 1), Sol_RES(nVarsResidual, 1);
900  TPZDiffMatrix<STATE> tangentFAD(nVarsResidual, 6), residualFAD_STATE(nVarsResidual, 1);
901 
902  TPZPlasticState<TFAD> Nk_FAD, Nkp1_FAD;
903  TPZTensor<TFAD> sigma_FAD;
904  TFAD A_FAD;
905 
906  TPZTensor<REAL> diffPlasticStrain;
907 
908  int n = fPlasticMem.NElements();
909 
910  if (n < 2) {
911 #ifdef LOG4CXX
912  if (logger->isDebugEnabled()) {
913  std::stringstream sout;
914  sout << ">>> ComputeDep2 *** Insufficient Plastic Mem Entries: " << n << ".";
915  LOGPZ_ERROR(plasticIntegrLogger, sout.str().c_str());
916  }
917 #endif
918 #ifdef LOG4CXX
919  {
920  std::stringstream sout;
921  sout << ">>> ComputeDep2 *** Insufficient Plastic Mem Entries: " << n << ".";
922  LOGPZ_ERROR(logger, sout.str().c_str());
923  }
924 #endif
925  return;
926  }
927 #ifdef LOG4CXX
928  {
929  std::stringstream sout;
930  sout << ">>> ComputeDep2 *** Plastic Mem Entries: " << n << ".";
931  if (n == 2) sout << "\nTwo entries indicate pure elastic step";
932  LOGPZ_DEBUG(logger, sout.str())
933  }
934 #endif
935 
936  if (n == 2) {// pure elastic step - no plastic loop necessary
937  fPlasticMem[1].m_elastoplastic_state.CopyTo(Nkp1_FAD);
938  for (int i = 0; i < nVarsTensor; i++)Nkp1_FAD.m_eps_t.fData[i].fastAccessDx(i) = 1.;
939 
940  } else {// plastification occurs
941 
942  // plastic Loop analogue with derivative evaluation
943 
944  // Initializing last available elastic step
945  fPlasticMem[1].m_elastoplastic_state.CopyTo(Nk_FADRES);
946  fPlasticMem[1].m_elastoplastic_state.CopyTo(Nkp1_FAD);
947  // for(j = 0; j < nVarsTensor; j++)Nk_FADFAD.m_eps_t.fData[j].val().fastAccessDx(j) = fPlasticMem[1].fK;
948 
949  // solution in order to ensure residual drop and convergence.
950  // This is very important to accumulate good FAD derivatives
951  TPZManVector<STATE, 10> pivots(nVarsResidual, 0.);
952 
953 
954  for (int plasticstep = 2; plasticstep < n; plasticstep++) {
955  InitializePlasticFAD(fPlasticMem[plasticstep].m_elastoplastic_state,
956  fPlasticMem[plasticstep].fDelGamma,
957  Nkp1_FADRES,
958  delGamma_FADRES,
959  nVarsResidual);
960  fYC.SetForceYield(fPlasticMem[plasticstep].fForceYield); // imposing the same assumptions made in the plasticLoop
961  Nk_FAD = Nkp1_FAD;
962  fPlasticMem[plasticstep].m_elastoplastic_state.CopyTo(Nkp1_FAD);
963  for (int j = 0; j < 6; j++) {
964  Nkp1_FAD.m_eps_t[j].fastAccessDx(j) = fPlasticMem[plasticstep].fK;
965  }
966  for (int i = 0; i < YC_t::NYield; i++) {
967  delGamma_FAD[i] = fPlasticMem[plasticstep].fDelGamma[i];
968  }
969 
970 
971 
972 #ifdef LOG4CXX
973  {
974  std::stringstream sout;
975  sout << "*** ComputeDep2 *** Before Matrix Invertion: Plastic step number " << plasticstep - 1 << " of " << n - 1
976  << "\n*Nk_FADFAD = " << setw(10) << Nk_FADRES
977  << "\n*Nkp1_FADFAD = " << setw(10) << Nkp1_FADRES
978  << "\n*delGamma_FADFAD = " << setw(10) << delGamma_FADRES
979  << "\nNk_FAD= " << Nk_FAD
980  << "\nNkp1_FAD = " << Nkp1_FAD
981  << "\ndelGamma_FAD = " << delGamma_FAD;
982 
983  LOGPZ_DEBUG(logger, sout.str())
984  }
985 #endif
986 
987  PlasticResidual<TFAD_RES, TFAD_RES>(Nk_FADRES, Nkp1_FADRES,
988  delGamma_FADRES, Residual_FADRES,
989  normResidual);
990  PlasticResidual<TFAD, TFAD>(Nk_FAD, Nkp1_FAD, delGamma_FAD, Residual_FAD, normResidual2);
991 
992 
993  tangent.Reset(); // resets the LU Decomposition flag
994 
995  int precond = 0;
996  int precondtangent = 1;
997  int resetInvalidEqs = 1;
998  ExtractTangent(Residual_FADRES, residual_RES,
999  resnorm, tangent, // TPZFMatrix for T1=fad<real> type
1000  fPlasticMem[plasticstep].fValidEqs, pivots,
1001  precondtangent, resetInvalidEqs);
1002 
1003  ExtractTangent(Residual_FAD, residualFAD_STATE, resnorm, tangentFAD, fPlasticMem[plasticstep].fValidEqs, pivots, precond, resetInvalidEqs);
1004 
1005  for (int i = 0; i < tangentFAD.Rows(); i++) {
1006  for (int j = 0; j < tangentFAD.Cols(); j++) {
1007  tangentFAD(i, j) /= pivots[i];
1008  }
1009  }
1010 #ifdef LOG4CXX
1011  TPZDiffMatrix< REAL > tangentcopy(tangent);
1012 #endif
1013  status = tangent.Decompose_LU();
1014  if (status == EZeroPivot) {
1015  std::stringstream sout;
1016  sout << "*** ComputeDep2 *** ### Decompose_LU error! - ZeroPivot ### No inversion will be performed";
1017 #ifdef LOG4CXX
1018  sout << "\nMatrix before decomposition\n";
1019  sout << tangentcopy;
1020  LOGPZ_ERROR(plasticIntegrLogger, sout.str().c_str());
1021 #endif
1022 #ifdef LOG4CXX_PLASTICITY
1023  LOGPZ_ERROR(logger, sout.str().c_str());
1024 #endif
1025  cout << endl << sout.str().c_str();
1026  }
1027 
1028  Sol_RES = tangentFAD;
1029  status = tangent.Substitution(&Sol_RES);
1030  if (status != EOk) {
1031  std::stringstream sout;
1032  if (status == EIncompDim)sout << "*** ComputeDep2 *** ### LU Substitution error! - IncompatibleDimensions ### No inversion will be performed";
1033  if (status == EZeroPivot)sout << "*** ComputeDep2 *** ### LU Substitution error! - ZeroPivot ### No inversion will be performed";
1034 #ifdef LOG4CXX
1035  LOGPZ_ERROR(plasticIntegrLogger, sout.str().c_str());
1036 #endif
1037 #ifdef LOG4CXX
1038  LOGPZ_ERROR(logger, sout.str());
1039 #endif
1040  cout << endl << sout.str().c_str();
1041  }
1042 
1043 
1044 
1045 #ifdef LOG4CXX
1046  {
1047  std::stringstream sout;
1048  sout << "*** ComputeDep2 *** Plastic step number " << plasticstep - 1 << " of " << n - 1
1049  << "\nSol_FAD = " << setw(10) << Sol_RES
1050  << "\nResidual_FADRES = " << setw(10) << Residual_FADRES
1051  << "\ntangentFAD = " << tangentFAD;
1052 
1053  LOGPZ_DEBUG(logger, sout.str().c_str());
1054  }
1055 #endif
1056 
1057  for (j = 0; j < nVarsTensor; j++) for (int k = 0; k < 6; k++) Nkp1_FAD.m_eps_p.fData[j].fastAccessDx(k) = -Sol_RES(j, k);
1058  for (int k = 0; k < 6; k++) Nkp1_FAD.m_hardening.fastAccessDx(k) = -Sol_RES(j, k);
1059  j++;
1060  for (int k = 0; k < 6; k++) for (j = 0; j < YC_t::NYield; j++) delGamma_FAD[j].fastAccessDx(k) = -Sol_RES(j + 7, k);
1061 
1062 
1063 #ifdef LOG4CXX
1064  {
1065  std::stringstream sout;
1066  sout << "*** ComputeDep2 *** substep " << plasticstep - 1 << " of " << n - 2
1067  << " solved with residual = " << resnorm;
1068  }
1069 #endif
1070 
1071  }
1072  } // end of condition on number of plastic steps
1073 
1074  //at this point, all the residual variables should contain their real derivatives to detaEpsT
1075  // in the case the loading is either elastic or elastoplastic.
1076  ComputePlasticVars(Nkp1_FAD, sigma_FAD, A_FAD);
1077 
1078  for (int i = 0; i < nVarsTensor; i++) for (j = 0; j < nVarsTensor; j++)Dep(i, j) = sigma_FAD.fData[i].dx(j);
1079 
1080 #ifdef LOG4CXX
1081  {
1082  std::stringstream sout;
1083  sout << "*** ComputeDep2 *** \nsigma_FAD= \n" << sigma_FAD
1084  << "\nDep =\n" << Dep;
1085  LOGPZ_DEBUG(logger, sout.str());
1086  }
1087 #endif
1088 
1089  sigma_FAD.CopyTo(sigma);
1090 
1091 }
1092 
1093 //template <class YC_t, class TF_t, class ER_t>
1094 //REAL TPZPlasticStep<YC_t, TF_t, ER_t>::FindPointAtYield(
1095 // const TPZTensor<REAL> &epsTotalNp1,
1096 // TPZPlasticState<REAL> &stateAtYield)const
1097 //{
1098 //
1099 //#ifdef LOG4CXX_PLASTICITY
1100 //
1101 // int plasticIntegrOutput;
1102 //
1103 // {
1104 // std::stringstream sout;
1105 // sout << ">>> FindPointAtYield ***";
1106 // LOGPZ_DEBUG(logger,sout.str().c_str());
1107 // }
1108 //#endif
1109 //
1110 // const int nVars = 1;
1111 // typedef TFad<nVars, REAL> TFAD_One;
1112 // TPZTensor<REAL> deltaEps;
1113 // TPZTensor<TFAD_One> deltaEps_FAD, sigma_FAD;
1114 // TFAD_One A_FAD, multipl_FAD;
1115 // TPZManVector<TFAD_One,10> phi_FAD(YC_t::NYield);
1116 // REAL multiplN, minMultipl = 1.;
1117 // TPZPlasticState<TFAD_One> stateAtYield_FAD;
1118 //
1119 // stateAtYield.CopyTo(stateAtYield_FAD);
1120 //
1121 //
1122 // // delta epsilon contains epstotal_N+1 - epsTotal_N
1123 // epsTotalNp1.CopyTo(deltaEps);
1124 // deltaEps.Add(fN.EpsT(), -1.);
1125 // deltaEps.CopyTo(deltaEps_FAD);
1126 //
1127 // int i, nyield = YC_t::NYield;
1128 // for(i = 0; i < nyield; i++)
1129 // { // searching for the multiplier for each yield surface
1130 //
1131 // multiplN = 0.; // the plastic multiplier is likely to be zero
1132 // // because of possible previous plastifications,
1133 // // although a null value may lead to no derivative
1134 // // or numerical instabilities when deltaEpsT=0
1135 // int count = 0;
1136 // do
1137 // {
1138 // if(count > 0)
1139 // {
1140 // REAL derX = phi_FAD[i].dx(0);
1141 // if(fabs(derX)<1.e-8) derX += 1.e-8;
1142 // multiplN -= phi_FAD[i].val() / derX; // avoiding division by zero
1143 // if(multiplN > 1.0)
1144 // {
1145 //#ifdef LOG4CXX_PLASTICITY
1146 // {
1147 // std::stringstream sout;
1148 // sout << "*** FindPointAtYield *** multiplication factor = " << multiplN << " set to 1.0";
1149 // sout << "\nPlastification is known to occur within this load step and the guess for the nest Newton's step is clipped to multipl=1";
1150 // LOGPZ_DEBUG(logger,sout.str().c_str());
1151 // }
1152 //#endif
1153 // multiplN = 1.0; // The step is known as plastic in advance
1154 // // (IsStrainElastic previously called)
1155 // // The check above avoids the multiplicator to be too large when the
1156 // // first derivative evaluation is very low. In very nonlinear models
1157 // // and specially in those where the stiffness matrix is very low at the
1158 // // null stress state this could happen and, if this statement weren't here,
1159 // // this newton loop could be extremely slow to converge since the
1160 // // initial guesses would be too far from the correct answer.
1161 // }
1162 //
1163 // if(multiplN < -1.0)
1164 // {
1165 //#ifdef LOG4CXX_PLASTICITY
1166 // {
1167 // std::stringstream sout;
1168 // sout << "*** FindPointAtYield *** multiplication factor = " << multiplN << " set to 1.0";
1169 // sout << "\nPlastification is known to occur within this load step. Forcing restart with initial guess biased towards the highest range attempting to help the code reach physically meaningful results";
1170 // LOGPZ_DEBUG(logger,sout.str().c_str());
1171 // }
1172 //#endif
1173 // multiplN = 1.0; // This check attempts to ensure that the
1174 // // solution of this plastification step does not explode backwards to the
1175 // // desired loading path. This may happen when the yield function is too
1176 // // nonlinear and may present a second solution in the negative range of
1177 // // the desired loading path. By setting the initial guess equal to 1.0
1178 // // (that means the whole loading path is plastic - true only in perfect
1179 // // plastic materials) the code attempts to bias the solver towards the
1180 // // physical meaningful solution.
1181 // }
1182 // }
1183 // count++;
1184 //
1185 // multipl_FAD = multiplN;
1186 // multipl_FAD.diff(0,nVars);
1187 // fN.EpsT().CopyTo(stateAtYield_FAD.m_eps_t);
1188 // stateAtYield_FAD.m_eps_t.Add(deltaEps_FAD, multipl_FAD);
1189 //
1190 // // this method computes sigma, A(alpha) substracting E_p from epstotal
1191 // ComputePlasticVars(stateAtYield_FAD,
1192 // sigma_FAD,
1193 // A_FAD);
1194 //
1195 // // compute the value of the yield functions
1196 // fYC.Compute(sigma_FAD, A_FAD, phi_FAD, 0);
1197 //
1198 //
1199 // }while(fabs (phi_FAD[i].val()) > fResTol && count < fMaxNewton);
1200 //
1201 //#ifdef LOG4CXX
1202 // {
1203 // if(count >= fMaxNewton )
1204 // {
1205 // std::stringstream sout;
1206 // sout << "*** FindPointAtYield *** multiplication factor= ";
1207 // sout << multiplN << " such that yield of function ";
1208 // sout << i << " = " << phi_FAD[i].val() << "; ";
1209 // sout << "\n#### Truncated Newton after "
1210 // << fMaxNewton << " steps with phi[" << i << "] = "
1211 // << TPZExtractVal::val(phi_FAD[i]) << "####. Results are unpredictable";
1212 // LOGPZ_WARN(plasticIntegrLogger,sout.str().c_str());
1213 // //plasticIntegrOutput = 1;
1214 // }
1215 // }
1216 //#endif
1217 //#ifdef LOG4CXX_PLASTICITY
1218 // {
1219 // std::stringstream sout;
1220 // sout << "*** FindPointAtYield *** multiplication factor= ";
1221 // sout << multiplN << " such that yield of function ";
1222 // sout << i << " = " << phi_FAD[i].val();
1223 // if(count >= fMaxNewton )
1224 // {
1225 // sout << "\n#### Truncated Newton after "
1226 // << fMaxNewton << " steps with phi[" << i << "] = "
1227 // << TPZExtractVal::val(phi_FAD[i])
1228 // << "####. It appears in such load path the plastic yield solution was found in the opposite direction."
1229 // << "\nPlease check the other(s) yield function(s) to guarantee at least one of them is plastifying within the proposed load path.";
1230 // LOGPZ_WARN(logger,sout.str().c_str());
1231 // LOGPZ_WARN(plasticIntegrLogger,sout.str().c_str());
1232 //
1233 // }else{
1234 // LOGPZ_DEBUG(logger,sout.str().c_str());
1235 // }
1236 // }
1237 //#endif
1238 //
1239 // if(multiplN < minMultipl)minMultipl = multiplN;
1240 // }
1241 //
1242 // if(minMultipl < - fResTol)
1243 // {
1244 //#ifdef LOG4CXX
1245 // {
1246 // std::stringstream sout;
1247 // sout << "*** FindPointAtYield *** Ignoring deltaStrainMultiplier = " << minMultipl
1248 // << " and setting it to zero.\n\t###### WARN: EpsTotalN isn't elastic!! ######";
1249 // LOGPZ_WARN(plasticIntegrLogger,sout.str().c_str());
1250 // }
1251 //#endif
1252 //#ifdef LOG4CXX_PLASTICITY
1253 // {
1254 // std::stringstream sout;
1255 // sout << "*** FindPointAtYield *** Ignoring deltaStrainMultiplier = " << minMultipl
1256 // << " and setting it to zero.\n\t###### WARN: EpsTotalN isn't elastic!! ######";
1257 // LOGPZ_WARN(logger,sout.str().c_str());
1258 // }
1259 //#endif
1260 // }
1261 //
1262 //
1263 // if(minMultipl < 0.)minMultipl = 0.; //avoiding rounding errors
1264 //
1265 // stateAtYield = fN;
1266 // stateAtYield.m_eps_t.Add(deltaEps, minMultipl);
1267 //
1268 //#ifdef LOG4CXX_PLASTICITY
1269 // {
1270 // std::stringstream sout;
1271 // sout << "<<< FindPointAtYield *** Exiting Method with deltaStrainMultiplier = " << minMultipl;
1272 // LOGPZ_DEBUG(logger,sout.str().c_str());
1273 // if(plasticIntegrOutput)LOGPZ_DEBUG(plasticIntegrLogger,sout.str().c_str());
1274 // }
1275 //#endif
1276 //
1277 // return minMultipl;
1278 //}
1279 
1280 template <class YC_t, class TF_t, class ER_t>
1282  const TPZTensor<REAL> &epsTotalNp1,
1283  TPZPlasticState<REAL> &stateAtYield)const {
1284 
1285 #ifdef LOG4CXX_PLASTICITY
1286 
1287  int plasticIntegrOutput;
1288 
1289  {
1290  std::stringstream sout;
1291  sout << ">>> FindPointAtYield ***";
1292  LOGPZ_DEBUG(logger, sout.str().c_str());
1293  }
1294 #endif
1295 
1296  const int nVars = 1;
1297  typedef TFad<nVars, REAL> TFAD_One;
1298  TPZTensor<REAL> deltaEps;
1299  TFAD_One A_FAD, multipl_FAD;
1300  TPZManVector<TFAD_One, 10> phi_FAD(YC_t::NYield);
1301 
1302 
1303  // this will be the result of the method (it is always a number between 0 and 1)
1304  REAL multiplN, minMultipl = 1.;
1305 
1306  TPZPlasticState<TFAD_One> stateAtYield_FAD;
1307 
1308  stateAtYield.CopyTo(stateAtYield_FAD);
1309 
1310  TPZTensor<STATE> sigma;
1311  STATE A;
1312  TPZManVector<STATE> phi(YC_t::NYield);
1313 
1314  // this method computes sigma, A(alpha) substracting E_p from epstotal
1315  ComputePlasticVars(stateAtYield, sigma, A);
1316  // compute the value of the yield functions
1317  fYC.Compute(sigma, A, phi, 0);
1318 
1319 
1320  // delta epsilon contains epstotal_N+1 - epsTotal_N
1321  epsTotalNp1.CopyTo(deltaEps);
1322  deltaEps.Add(fN.EpsT(), -1.);
1323 
1324  int i, nyield = YC_t::NYield;
1325 
1326 
1327  for (i = 0; i < nyield; i++) { // searching for the multiplier for each yield surface
1328 
1329  multiplN = 1.; // the plastic multiplier is likely to be zero
1330  // because of possible previous plastifications,
1331  // although a null value may lead to no derivative
1332  // or numerical instabilities when deltaEpsT=0
1333 
1334  TPZTensor<TFAD_One> deltaEps_FAD, sigma_FAD;
1335  deltaEps.CopyTo(deltaEps_FAD);
1336 
1337  // this will set the derivative in the value of stateatyield
1338  TFAD_One mult(multiplN, 0);
1339  deltaEps_FAD *= mult;
1340  stateAtYield.CopyTo(stateAtYield_FAD);
1341  stateAtYield_FAD.m_eps_t += deltaEps_FAD;
1342 
1343  // stateAtYield is at the next point
1344 
1345  // this method computes sigma, A(alpha) substracting E_p from epstotal
1346  ComputePlasticVars(stateAtYield_FAD, sigma_FAD, A_FAD);
1347  // compute the value of the yield functions
1348  fYC.Compute(sigma_FAD, A_FAD, phi_FAD, 0);
1349 
1350 #ifdef LOG4CXX
1351  if (logger->isDebugEnabled()) {
1352  std::stringstream sout;
1353  sout << "State at yield " << stateAtYield_FAD << std::endl;
1354  sout << "Sigma " << sigma_FAD << std::endl;
1355  sout << "phi " << phi_FAD << std::endl;
1356  LOGPZ_DEBUG(logger, sout.str())
1357  }
1358 #endif
1359 
1360  // the next value will be elastic. The multiplier cannot be diminished
1361  // if the value is less or equal to zero the multiplier is one
1362  if (phi_FAD[i].val() < fResTol) {
1363  continue;
1364  }
1365 
1366  // if the point was already on the plastic surface, the multiplier is zero
1367  if (phi[i] > -fResTol) {
1368  minMultipl = 0.;
1369  // nothing else to do, the multiplier can t be smaller
1370  return minMultipl;
1371  }
1372 
1373  // we have to find a scalar value which brings the point on the surface
1374  while (fabs(phi_FAD[i].val()) > fResTol) {
1375 
1376  REAL phi_prev = phi_FAD[i].val();
1377  deltaEps.CopyTo(deltaEps_FAD);
1378 
1379  // this will set the derivative in the value of stateatyield
1380  TFAD_One mult(multiplN, 0);
1381  deltaEps_FAD *= mult;
1382  stateAtYield.CopyTo(stateAtYield_FAD);
1383  stateAtYield_FAD.m_eps_t += deltaEps_FAD;
1384 
1385  // this method computes sigma, A(alpha) substracting E_p from epstotal
1386  ComputePlasticVars(stateAtYield_FAD, sigma_FAD, A_FAD);
1387  // compute the value of the yield functions
1388  fYC.Compute(sigma_FAD, A_FAD, phi_FAD, 0);
1389 
1390 #ifdef LOG4CXX
1391  if (logger->isDebugEnabled()) {
1392  std::stringstream sout;
1393  sout << "State at yield " << stateAtYield_FAD << std::endl;
1394  sout << "Sigma " << sigma_FAD << std::endl;
1395  sout << "phi " << phi_FAD << std::endl;
1396  LOGPZ_DEBUG(logger, sout.str())
1397  }
1398 #endif
1399  if (fabs(phi_FAD[i].val()) > fabs(phi_prev)) {
1400  DebugStop();
1401  }
1402 
1403  REAL derX = phi_FAD[i].dx(0);
1404  if (fabs(derX) < 1.e-8) derX += 1.e-8;
1405  REAL delmult = -phi_FAD[i].val() / derX; // avoiding division by zero
1406  if (multiplN == 1.0 && delmult > 0.) {
1407  // there is nothing to search further for this yield surface
1408  break; // The step is known as plastic in advance
1409  }
1410  multiplN += delmult;
1411  if (multiplN > 1.) multiplN = 1.;
1412  }
1413 
1414 #ifdef LOG4CXX_PLASTICITY
1415  {
1416  std::stringstream sout;
1417  sout << "*** FindPointAtYield *** multiplication factor= ";
1418  sout << multiplN << " such that yield of function ";
1419  sout << i << " = " << phi_FAD[i].val();
1420  if (count >= fMaxNewton) {
1421  sout << "\n#### Truncated Newton after "
1422  << fMaxNewton << " steps with phi[" << i << "] = "
1423  << TPZExtractVal::val(phi_FAD[i])
1424  << "####. It appears in such load path the plastic yield solution was found in the opposite direction."
1425  << "\nPlease check the other(s) yield function(s) to guarantee at least one of them is plastifying within the proposed load path.";
1426  LOGPZ_WARN(logger, sout.str().c_str());
1427  LOGPZ_WARN(plasticIntegrLogger, sout.str().c_str());
1428 
1429  } else {
1430  LOGPZ_DEBUG(logger, sout.str().c_str());
1431  }
1432  }
1433 #endif
1434 
1435  if (multiplN < minMultipl)minMultipl = multiplN;
1436  }
1437 
1438  if (minMultipl < fResTol) {
1439  minMultipl = 0.;
1440 #ifdef LOG4CXX
1441  {
1442  std::stringstream sout;
1443  sout << "*** FindPointAtYield *** Ignoring deltaStrainMultiplier = " << minMultipl
1444  << " and setting it to zero.\n\t###### WARN: EpsTotalN isn't elastic!! ######";
1445  LOGPZ_WARN(plasticIntegrLogger, sout.str().c_str());
1446  }
1447 #endif
1448 #ifdef LOG4CXX_PLASTICITY
1449  {
1450  std::stringstream sout;
1451  sout << "*** FindPointAtYield *** Ignoring deltaStrainMultiplier = " << minMultipl
1452  << " and setting it to zero.\n\t###### WARN: EpsTotalN isn't elastic!! ######";
1453  LOGPZ_WARN(logger, sout.str().c_str());
1454  }
1455 #endif
1456  }
1457 
1458 
1459  stateAtYield = fN;
1460  stateAtYield.m_eps_t.Add(deltaEps, minMultipl);
1461 
1462 #ifdef LOG4CXX_PLASTICITY
1463  {
1464  std::stringstream sout;
1465  sout << "<<< FindPointAtYield *** Exiting Method with deltaStrainMultiplier = " << minMultipl;
1466  LOGPZ_DEBUG(logger, sout.str().c_str());
1467  if (plasticIntegrOutput)LOGPZ_DEBUG(plasticIntegrLogger, sout.str().c_str());
1468  }
1469 #endif
1470 
1471  return minMultipl;
1472 }
1473 
1483 template <class YC_t, class TF_t, class ER_t>
1485  const TPZPlasticState<REAL> &N,
1486  TPZPlasticState<REAL> &Np1,
1487  TPZVec<REAL> &delGamma,
1488  TPZVec<int> &valideqs
1489  ) {
1490 
1491 }
1492 
1493 template <class YC_t, class TF_t, class ER_t>
1495  const TPZPlasticState<REAL> &NN,
1496  TPZPlasticState<REAL> &Np1,
1497  TPZVec<REAL> &delGamma,
1498  REAL &normEpsPErr,
1499  REAL &lambda,
1500  TPZVec<int> & validEqs) {
1501 
1502  // 6 variables for tensor and others: alpha and deltaGamma
1503  const int nVars = 7 + YC_t::NYield;
1504  int i;
1505  const REAL Tol = fResTol;
1506 
1507 #ifdef LOG4CXX
1508  if (pointloadconfig->isDebugEnabled()) {
1509  std::stringstream sout;
1510  sout << "alpha = " << NN.m_hardening << std::endl;
1511  TPZFNMatrix<6, REAL> Ep(NN.m_eps_p), EpsT(Np1.m_eps_t);
1512  TPZTensor<REAL> sigmaT, deformElast;
1513  Ep.Print("Ep = ", sout, EMathematicaInput);
1514  EpsT.Print("Etotal = ", sout, EMathematicaInput);
1515  deformElast = Np1.m_eps_t;
1516  deformElast.Add(NN.m_eps_p, -1.);
1517  fER.ComputeStress(deformElast, sigmaT);
1518  TPZFNMatrix<6, REAL> sigma(sigmaT);
1519  sigma.Print("sigmaTrial = ", sout, EMathematicaInput);
1520  LOGPZ_DEBUG(pointloadconfig, sout.str())
1521  }
1522 #endif
1523  InitialGuess(NN, Np1, delGamma, validEqs);
1524 #ifdef LOG4CXX
1525  {
1526  std::stringstream sout; //1, sout2;
1527  sout << " >>> PlasticLoop ***\n";
1528  sout << "Np1 = " << Np1
1529  << "\ndelGamma = " << delGamma
1530  << "\nlambda = " << lambda
1531  << "\nValid eqs = " << validEqs;
1532  //LOGPZ_DEBUG(logger,sout.str().c_str());
1533  LOGPZ_DEBUG(logger, sout.str());
1534  }
1535 #endif
1536 
1537  typedef TFad<nVars, REAL> TFAD;
1538 
1539  TPZPlasticState<TFAD> Np1_FAD;
1540  TPZTensor<TFAD> sigmaNp1_FAD;
1541  TPZManVector<TFAD, nVars> epsRes_FAD(nVars), delGamma_FAD(YC_t::NYield);
1542  TFAD phiRes_FAD;
1543  // ResVal to hold the residual vector
1544  // Sol will contain the values of the unknown values
1545  TPZFNMatrix<nVars> ResVal(nVars, 1, 0.), Sol(nVars, 1, 0.);
1546  TPZFNMatrix<nVars * nVars> tangent(nVars, nVars, 0.); // Jacobian matrix
1547  REAL resnorm = 0.;
1548 
1549  TPZManVector<STATE, nVars> pivots(nVars);
1550 
1551 
1552  int countReset = 0;
1553  for (int i = 0; i < validEqs.size(); i++) {
1554  if (validEqs[i] != 0) {
1555  countReset = 1;
1556  }
1557  }
1558  int countNewton = 0;
1559  int switchvalid = 0;
1560 
1561  do {//while(RemoveInvalidEqs(epsRes_FAD));
1562  switchvalid++;
1563  // verifying if it is necessary to impose post-peak material behavior
1564  TPZTensor<REAL> sigmaGuess;
1565  REAL AGuess;
1566  ComputePlasticVars<REAL>(Np1, sigmaGuess, AGuess);
1567  fYC.SetYieldStatusMode(sigmaGuess, AGuess);
1568 
1569  InitializePlasticFAD(Np1, delGamma, Np1_FAD, delGamma_FAD);
1570 #ifdef LOG4CXX
1571  {
1572  std::stringstream sout;
1573  sout << "Before plastic residual\n";
1574  sout << "Np1_FAD\n" << Np1_FAD << std::endl;
1575  sout << "delGamma_FAD " << delGamma_FAD << std::endl;
1576  LOGPZ_DEBUG(logger, sout.str())
1577  }
1578 #endif
1579 
1580  PlasticResidual<REAL, TFAD>(NN, Np1_FAD, delGamma_FAD, epsRes_FAD, normEpsPErr);
1581 
1582 #ifdef LOG4CXX
1583  {
1584  std::stringstream sout;
1585  sout << "After Plastic residual\nepsRes_FAD = \n" << epsRes_FAD << std::endl;
1586  sout << "delGamma_FAD " << delGamma_FAD << std::endl;
1587  LOGPZ_DEBUG(logger, sout.str())
1588  }
1589 #endif
1590 
1591  if (countReset == 0)InitializeValidEqs(epsRes_FAD, validEqs);
1592 
1593 #ifdef LOG4CXX_PLASTICITY
1594  {
1595  std::stringstream sout;
1596  sout << "*** PlasticLoop *** PlasticLoop main loop with "
1597  << countReset << "-th valid equation set: {"
1598  << validEqs << "}.";
1599  LOGPZ_DEBUG(logger, sout.str().c_str());
1600  }
1601 #endif
1602 
1603 
1604  // REAL LineSearch(const TPZFMatrix &Wn, TPZFMatrix DeltaW, TPZFMatrix &NextW, REAL tol, int niter);
1605 
1606  ExtractTangent(epsRes_FAD, ResVal, resnorm, tangent, validEqs, pivots, 1/*precond*/, 1/*ResetUnvalidEqs*/);
1607 #ifdef LOG4CXX
1608  {
1609  std::stringstream sout;
1610  tangent.Print("A = ", sout, EMathematicaInput);
1611  LOGPZ_DEBUG(logger, sout.str())
1612  }
1613 #endif
1614  countNewton = 0;
1615 
1616  do {
1617 
1618  countNewton++;
1619 
1620  TPZFNMatrix<nVars * nVars> *matc = new TPZFNMatrix<nVars * nVars>(nVars, nVars);
1621  *matc = tangent;
1622  TPZStepSolver<REAL> st(matc);
1623  st.SetDirect(ELU);
1624 
1625  // cout << " RESVAL " <<endl;
1626  // cout << ResVal << endl;
1627 
1628 
1629  // ofstream fileout("rigidez.nb");
1630  // tangent.Print("Rigidez = ", fileout, EMathematicaInput);
1631  // ofstream fileout2("ResVal.nb");
1632  // ResVal.Print("ResVal = ", fileout2, EMathematicaInput);
1633  // cout << tangent << endl;
1634  // cout << ResVal << endl;
1635 
1636 
1637  // invert the tangent matrix and put the correction in the Sol variable
1638  st.Solve(ResVal, Sol, 0);
1639 
1640  // update the independent variables (their partial derivatives remain unchanged)
1641  lambda = UpdatePlasticVars(NN, Np1_FAD, delGamma_FAD, epsRes_FAD, Sol, validEqs);
1642 
1643 
1644  if (countNewton > 8) {
1645  std::cout << "countNewton = " << countNewton << " resnorm " << resnorm << " tolerance " << fResTol << "\n";
1646  }
1647  // recompute the residual
1648  PlasticResidual<REAL, TFAD>(NN, Np1_FAD, delGamma_FAD, epsRes_FAD, normEpsPErr);
1649 
1650 #ifdef LOG4CXX
1651  {
1652  std::stringstream sout;
1653  sout << "Plastic residual " << epsRes_FAD << std::endl;
1654  sout << "delGamma_FAD " << delGamma_FAD << std::endl;
1655  LOGPZ_DEBUG(logger, sout.str())
1656  }
1657 #endif
1658  // extract the values of the residual vector
1659  ExtractTangent(epsRes_FAD, ResVal, resnorm, tangent, validEqs, pivots, 1, 1);
1660 
1661 #ifdef LOG4CXX_PLASTICITY
1662  {
1663  std::stringstream sout1, sout2;
1664  sout1 << "*** PlasticLoop *** Newton's " << countNewton
1665  << "-th iteration with residual norm = " << resnorm;
1666  //sout1 << "\nTangent Matrix:\n" << tangent
1667  // << "\nResidual:\n" << ResVal;
1668  // LOGPZ_DEBUG(logger,sout1.str().c_str());
1669  }
1670 #endif
1671 
1672  } while (resnorm > Tol && countNewton < fMaxNewton);
1673 
1674 #ifdef LOG4CXX
1675  {
1676 
1677  std::stringstream sout;
1678  sout << "*** PlasticLoop *** Exiting Newton's scheme after " << countNewton
1679  << " steps and with residual norm = " << resnorm;
1680  if (resnorm > Tol) {
1681  sout << "\n###### Max Newton steps achieved - Truncating Newton ######";
1682  LOGPZ_WARN(plasticIntegrLogger, sout.str().c_str());
1683  } else {
1684  LOGPZ_DEBUG(plasticIntegrLogger, sout.str().c_str());
1685  }
1686  }
1687 #endif
1688 #ifdef LOG4CXX_PLASTICITY
1689  {
1690  std::stringstream sout1, sout2;
1691  sout1 << "*** PlasticLoop *** Exiting Newton's scheme after " << countNewton
1692  << " steps and with residual norm = " << resnorm;
1693  LOGPZ_DEBUG(logger, sout1.str().c_str());
1694  if (resnorm > Tol) {
1695  sout2 << "\n###### Max Newton steps achieved - Truncating Newton ######";
1696  LOGPZ_WARN(logger, sout2.str().c_str());
1697  }
1698  }
1699 #endif
1700 
1701  countReset++;
1702 
1703  } while (switchvalid < 3 && RemoveInvalidEqs(delGamma_FAD, epsRes_FAD, validEqs));
1704 
1706 
1707  // updating output variables
1708  //for(i=0; i<6; i++) Np1.m_eps_p.fData[i] = Np1_FAD.EpsP().fData[i].val();
1709  //Np1.m_hardening = Np1_FAD.VolHardening().val();
1710 #ifdef PZDEBUG
1711  if (switchvalid == 3) {
1712  std::cout << __FUNCTION__ << " should stop switchvalid\n";
1713  }
1714 #endif
1715  Np1_FAD.CopyTo(Np1);
1716 
1717  for (i = 0; i < YC_t::NYield; i++)
1718  delGamma[i] = delGamma_FAD[i].val();
1719 
1720 
1721 
1722  // for(int i=0;i<6;i++)
1723  // {
1724  //
1725  // fOutfile << "{ {" << Np1.m_eps_t.XX() << "," << Np1.m_eps_t.XY() << "," << Np1.m_eps_t.XZ()
1726  // <<"},{"<<Np1.m_eps_t.XY()<<","<<Np1.m_eps_t.YY()<<","<<Np1.m_eps_t.YZ()
1727  // <<"},{"<<Np1.m_eps_t.XZ()<<","<<Np1.m_eps_t.YZ() << ","<<Np1.m_eps_t.ZZ()<<"} } ";
1728  // }
1729 
1730 
1731 
1732 #ifdef LOG4CXX
1733 
1734  {
1735  std::stringstream sout1, sout2;
1736  sout1 << "<<< PlasticLoop *** Exiting Method";
1737  sout2 << "\nNp1 << " << Np1
1738  << "\ndelGamma = " << delGamma
1739  << "\nValidEqs = {" << validEqs << "}";
1740  LOGPZ_DEBUG(loggerx, sout1.str().c_str());
1741  LOGPZ_DEBUG(loggerx, sout2.str().c_str());
1742  }
1743 
1744 #endif
1745 #ifdef LOG4CXX
1746  if (pointloadconfig->isDebugEnabled()) {
1747  std::stringstream sout;
1748  sout << "alphanp1 = " << Np1.m_hardening << std::endl;
1749  TPZFNMatrix<6, REAL> Ep(Np1.m_eps_p);
1750  Ep.Print("Epnp1 = ", sout, EMathematicaInput);
1751  sout << "delGamma = {" << delGamma << "};\n";
1752  LOGPZ_DEBUG(pointloadconfig, sout.str())
1753  }
1754 #endif
1755 
1756  return resnorm <= Tol;
1757 }
1758 
1759 template <class YC_t, class TF_t, class ER_t>
1761  const TPZPlasticState<REAL> &N,
1762  TPZPlasticState<REAL> &Np1,
1763  const REAL &TolEpsPErr) {
1764  int succeeded;
1765 
1766  TPZManVector<REAL, YC_t::NYield> delGamma(YC_t::NYield, 0.);
1767  TPZManVector<int, YC_t::NYield> validEqs(YC_t::NYield, 0);
1768 
1769  REAL normEpsPErr = 0.;
1770  int counter = 0;
1771  REAL lambda = 0.;
1772 
1773  succeeded = PlasticLoop(N, Np1, delGamma, normEpsPErr, lambda, validEqs);
1774 
1775  if (normEpsPErr < TolEpsPErr && succeeded) {
1776 
1777  PushPlasticMem(Np1, 1., lambda, delGamma, validEqs, fYC.GetForceYield());
1778 
1779  return 1;
1780  }
1781 
1782  int discarded = 1;
1783 
1784  // Substepping state variables
1785  TPZPlasticState<REAL> Nk(N),
1786  Nkp1;
1787 
1788  TPZTensor<REAL> deltaEpsTotal(Np1.EpsT());
1789  deltaEpsTotal.Add(N.EpsT(), -1.);
1790 
1791  REAL k = 0., q = 1., kp1 = 0., multipl;
1792 
1793  ofstream outfile("integrate.txt");
1794  ofstream outfile2("integrate2.txt");
1795 
1796  while (k < 1.) {
1797 
1798 
1799  multipl = 0.95 * pow(TolEpsPErr / normEpsPErr, 0.5);
1800 
1801  if (multipl < 0.1) multipl = 0.1;
1802  if (multipl > 10.) multipl = 10.;
1803 
1804  if (!succeeded)multipl = 0.5;
1805 
1806  q *= multipl;
1807 
1808  if (q < fMinStepSize)q = fMinStepSize;
1809 
1810  kp1 = min((REAL) 1.0, k + q);
1811  q = kp1 - k; // needed when k+q exceeds 1
1812  Nkp1.m_eps_t = N.EpsT();
1813  Nkp1.m_eps_t.Add(deltaEpsTotal, kp1);
1814  Nkp1.m_hardening = Nk.VolHardening();
1815  Nkp1.m_eps_p = Nk.EpsP();
1816  for (int i = 0; i < YC_t::NYield; i++)delGamma[i] = 0.;
1817 
1818 #ifdef LOG4CXX
1819  {
1820  std::stringstream sout;
1821  sout << "Nkp1 = " << Nkp1 << endl;
1822  sout << "Nk = " << Nk << endl;
1823  sout << "k = " << k << endl;
1824  sout << "normEpsPErr = " << normEpsPErr << endl;
1825  sout << "delGamma = " << delGamma << endl;
1826  sout << "lambda = " << lambda << endl;
1827  LOGPZ_DEBUG(loggerx, sout.str())
1828  }
1829 #endif
1830 
1831 
1832  succeeded = PlasticLoop(Nk, Nkp1, delGamma, normEpsPErr, lambda, validEqs);
1833 
1834 
1835  if ((normEpsPErr < TolEpsPErr && succeeded) || kp1 - k < fMinStepSize * 1.001) // 1.001 because of rounding errors
1836  {
1837 
1838  PushPlasticMem(Nkp1, kp1, lambda, delGamma, validEqs, fYC.GetForceYield());
1839  counter++;
1840 
1841  // the k-th integration step respects the estimated tolerance
1842  // proceeding with time evolution...
1843  Nk = Nkp1;
1844  k = kp1;
1845 
1846  outfile << "\n" << counter << " " << k;
1847  } else {
1848  discarded++;
1849  }// otherwise the answer isn't accepted and the next q will be
1850  // recomputed in order to lie within the desired tolerance.
1851  // If the method works fine this situation should rarely happen.
1852  REAL razaoerros = normEpsPErr / TolEpsPErr;
1853  outfile2 << "\n" << counter << " " << razaoerros;
1854 
1855  }
1856 
1857  return counter;
1858 }
1859 
1860 template <class YC_t, class TF_t, class ER_t>
1861 template <class T>
1863 #ifdef LOG4CXX_PLASTICITY
1864  {
1865  int i, n = res_T.NElements();
1866  std::stringstream sout;
1867  sout << ">>> InitializeValidEqs *** Res = ";
1868  for (i = 0; i < n; i++)sout << TPZExtractVal::val(res_T[i]) << " ";
1869  LOGPZ_DEBUG(logger, sout.str().c_str());
1870  }
1871 #endif
1872  const int nyield = YC_t::NYield;
1873  validEqs.Resize(nyield);
1874  int i, count = 0;
1875  for (i = 0; i < nyield; i++) {
1876  validEqs[i] = 0;
1877  if (TPZExtractVal::val(res_T[i + 7]) > 0.) {
1878  validEqs[i] = 1;
1879  count++;
1880  }
1881  }
1882 
1883  if (nyield == 1) // if there exists only one eqn it must be active
1884  {
1885  validEqs[0] = 1;
1886  count++;
1887  }
1888 
1889  return count;
1890 }
1891 
1892 template <class YC_t, class TF_t, class ER_t>
1893 template <class T>
1895  const int nyield = YC_t::NYield;
1896  validEqs.Resize(nyield);
1897 
1898  if (nyield == 1)return 0; // remove Invalid Eqs should not invalidate the unique equation
1899 
1900  int i, count = 0;
1901 
1902 #ifdef LOG4CXX_PLASTICITY
1903  {
1904  int i;
1905  std::stringstream sout;
1906  sout << ">>> RemoveInvalidEqs *** delGamma = ";
1907  for (i = 0; i < nyield; i++)sout << TPZExtractVal::val(delGamma_T[i]) << " ";
1908  sout << " phi = ";
1909  for (i = 0; i < nyield; i++)sout << TPZExtractVal::val(res_T[i + 7]) << " ";
1910  LOGPZ_DEBUG(logger, sout.str().c_str());
1911  }
1912 #endif
1913 
1914  int BoolDelGamma,
1915  BoolValidEq,
1916  BoolRes;
1917 
1918  for (i = 0; i < nyield; i++) {
1919  BoolDelGamma = TPZExtractVal::val(delGamma_T[i]) > 0.; // deltaGamma is valid
1920  BoolValidEq = validEqs[i]; // equation is already in use
1921  BoolRes = TPZExtractVal::val(res_T[i + 7]) > fResTol; // equation indicates plastification
1922 
1923  switch (BoolRes) {
1924  case (true):
1925  // the lines below unfortunately led to instabilities in the integration process
1926  //validEqs[i] = 1; // if the equation indicates plastification then it is necessary to involve it in the process
1927  // the equation was not computed and the plasticity function is positive
1928  if (!BoolValidEq) {
1929  // validEqs[i] = 1;
1930  // count++;
1931  }
1932  break;
1933  case (false):
1934  // if the equation does not indicate plastification but is
1935  // already involved in the plastification process and
1936  // has a valid deltaGamma then keep it in the integration process - do nothing
1937 
1938  // if it is involved in the plastification process but has an
1939  // invalid deltagamma - invalidate it
1940  if (BoolValidEq && !BoolDelGamma) {
1941  validEqs[i] = 0;
1942  count++;
1943  }
1944 
1945  // if it isn't invoved in the plastification process - delgamma is meaningless and no
1946  // testing should be performed.
1947  break;
1948  }
1949  }
1950 
1951  return count;
1952 }
1953 
1954 template <class YC_t, class TF_t, class ER_t>
1955 template<class T1, class T_VECTOR, class T_MATRIX>//T1:input residual fad type (FAD FAD or FAD), T_MATRIX: output matrix &vector of type (FAD or REAL, respectvly)
1957  const TPZVec<T1> & epsRes_FAD,
1958  T_VECTOR & ResVal, //TPZFMatrix for the T1=fad<real> type
1959  REAL & resnorm, // REAL
1960  T_MATRIX & tangent, // TPZFMatrix for T1=fad<real> type
1961  TPZVec<int> & validEqs,
1962  TPZVec<REAL> &pivots,
1963  const int precond,
1964  const int resetInvalidEqs) {
1965 
1966  const int nyield = YC_t::NYield;
1967  const int nVars = 7 + nyield; // 6 stresses + alpha + 2 delGamma
1968  int i, j;
1969  int ncols = epsRes_FAD[0].size();
1970 
1971  // extract the partial derivatives to form the tangent matrix
1972  for (i = 0; i < nVars; i++) {
1973  for (j = 0; j < ncols; j++) {
1974  tangent(i, j) = epsRes_FAD[i].dx(j);
1975  }
1976  ResVal(i, 0) = epsRes_FAD[i].val();
1977  }
1978 
1979  // cout << "epsRes_FAD[i] "<<endl;
1980  // cout << epsRes_FAD <<endl;
1981  //
1982  // cout << "ResVal"<<endl;
1983  // cout << ResVal<<endl;
1984  //
1985  // cout << " TANGENTE " <<endl;
1986  // cout << tangent <<endl;
1987 
1988  // reseting the equations related to the invalid yield surfaces
1989  if (resetInvalidEqs) {
1990  for (i = 0; i < nyield; i++) {
1991  if (validEqs[i] == 0) {
1992  for (j = 0; j < ncols; j++) {
1993  tangent(i + 7, j) = 0.;
1994  }
1995  if (i + 7 < ncols) {
1996  tangent(i + 7, i + 7) = 1.;
1997  }
1998 
1999  ResVal(i + 7, 0) = 0.;
2000  }
2001  }
2002  }
2003 
2004  // updating residual norm
2005  // before preconditioning such that it keeps its physical meaning
2006  //cout << "ResVal"<<endl;
2007  // cout << ResVal<<endl;
2008  resnorm = 0.;
2009  for (i = 0; i < nVars; i++) {
2010  resnorm += pow(TPZExtractVal::val(ResVal(i, 0)), 2.);
2011  }
2012  resnorm = sqrt(resnorm);
2013 
2014  if (precond && nVars != ncols) {
2015  DebugStop();
2016  }
2017  //cout << "resnorm"<<endl;
2018  // cout << resnorm<<endl;
2019  // preconditioning the matrix/residual system
2020  if (precond) {
2021  for (i = 0; i < 7; i++) {
2022  REAL pivot = 0., elem;
2023  j = i;
2024  elem = TPZExtractVal::val(tangent(i, j));
2025  if (fabs(pivot) < fabs(elem))pivot = elem;
2026  pivots[i] = pivot;
2027  //pivot = fabs(TPZExtractVal::val(pivot) ) < fabs(TPZExtractVal::val(tangent(i,j) ) ) ? tangent(i,j) : pivot;
2028 
2029  for (j = 0; j < nVars; j++)
2030  tangent(i, j) = tangent(i, j) / pivot;
2031  ResVal(i, 0) = ResVal(i, 0) / pivot;
2032  }
2033 
2034  for (; i < nVars; i++) {
2035  REAL pivot = 0., elem;
2036  for (j = 0; j < nVars; j++) {
2037  elem = TPZExtractVal::val(tangent(i, j));
2038  if (fabs(pivot) < fabs(elem))pivot = elem;
2039  //pivot = fabs(TPZExtractVal::val(pivot) ) < fabs(TPZExtractVal::val(tangent(i,j) ) ) ? tangent(i,j) : pivot;
2040  }
2041  pivots[i] = pivot;
2042  for (j = 0; j < nVars; j++) {
2043  tangent(i, j) = tangent(i, j) / pivot;
2044  }
2045  ResVal(i, 0) = ResVal(i, 0) / pivot;
2046  }
2047  }
2048 #ifdef LOG4CXX_PLASTICITY
2049  {
2050  std::stringstream sout;
2051  sout << ">>> ExtractTangent *** Residual norm = " << resnorm
2052  << "; precond = " << precond
2053  << "; resetInvalidEqs = " << resetInvalidEqs
2054  << "; validEqs = {" << validEqs << "}";
2055  LOGPZ_DEBUG(logger, sout.str().c_str());
2056  }
2057 #endif
2058 }
2059 
2060 template <class YC_t, class TF_t, class ER_t>
2061 template <class T1, class T2>
2063  const TPZPlasticState<T1> &N_T1,
2064  TPZPlasticState<T2> &Np1_T2,
2065  const TPZVec<T2> &delGamma_T2,
2066  TPZVec<T2> &res_T2,
2067  REAL &normEpsPErr,
2068  int silent)const {
2069 
2070  // a= 0 ->implicito
2071  // a= 0.5 -> ponto medio - segunda ordem
2072  const REAL a = 0.;
2073 
2074  // This function will be either called with template parameter T being REAL or FAD type
2075  // nyield indicates the number of yield functions
2076  const int nyield = YC_t::NYield;
2077 
2078  // variable to hold the value of the stress, elastic strain and residual corresponding to the plastic strain
2079  TPZTensor<T2> sigmaNp1_T2, epsResMidPt_T2;
2080  TPZTensor<T1> sigmaN_T1;
2081  // variable containing the error or deviation between solutions from Modified and
2082  // explicit Euler schemes
2083  TPZTensor<REAL> epsPErr;
2084 
2085  // vector holding the tensors of the N directions (usually derivative of the yield functions)
2086  TPZManVector<TPZTensor<T2>, nyield> NdirNp1_T2(nyield), NdirMidPt_T2(nyield);
2087  TPZManVector<TPZTensor<T1>, nyield> NdirN_T1(nyield);
2088 
2089  // vector holding the residual of the yield function equations
2090  TPZManVector<T2, nyield> phiRes_T2(nyield), HNp1_T2(nyield), HMidPt_T2(nyield);
2091  TPZManVector<T1, nyield> HN_T1(nyield);
2092 
2093  // residual of the equation corresponding to the damage variable
2094  T2 alphaRes_T2, ANp1_T2;
2095  T1 AN_T1;
2096 
2097  ComputePlasticVars<T1>(N_T1, sigmaN_T1, AN_T1);
2098  ComputePlasticVars<T2>(Np1_T2, sigmaNp1_T2, ANp1_T2);
2099 
2100  // Compute the values of the N directions (which will update the plastic strain)
2101  fYC.N(sigmaN_T1, AN_T1, NdirN_T1, 0);
2102  fYC.N(sigmaNp1_T2, ANp1_T2, NdirNp1_T2, 1);
2103 
2104  int i, j;
2105  for (i = 0; i < nyield; i++){
2106  for (j = 0; j < 6; j++){
2107  NdirMidPt_T2[i].fData[j] = ((NdirNp1_T2[i].fData[j]) * T2(1. - a)
2108  + (NdirN_T1[i].fData[j]) * T1(a));
2109  }
2110  }
2111 
2112  // Compute the value of H
2113  fYC.H(sigmaN_T1, AN_T1, HN_T1, 0);
2114  fYC.H(sigmaNp1_T2, ANp1_T2, HNp1_T2, 1);
2115 
2116  for (i = 0; i < nyield; i++) {
2117  HMidPt_T2[i] = (HNp1_T2[i] * T2(1. - a) + T2(HN_T1[i] * T1(a)));
2118  }
2119 
2120  //EpsRes = EpsilonPNp1 - m_eps_p - deltagamma * Ndir; // 6 eqs
2121  //for
2122  for (i = 0; i < nyield; i++) {
2123  NdirMidPt_T2[i].Multiply(delGamma_T2[i], T2(1.));
2124  epsResMidPt_T2.Add(NdirMidPt_T2[i], T2(-1.));
2125 
2126  NdirN_T1[i].Multiply(T1(TPZExtractVal::val(delGamma_T2[i])), T1(1.));
2127  for (j = 0; j < 6; j++) {
2128  epsPErr.fData[j] += TPZExtractVal::val(NdirN_T1[i]. fData[j])
2129  - TPZExtractVal::val(NdirMidPt_T2[i].fData[j]);
2130  }
2131  }
2132  epsResMidPt_T2.Add(N_T1.EpsP(), T1(-1.));
2133  epsResMidPt_T2.Add(Np1_T2.EpsP(), T1(1.));
2134 
2135 
2136 
2137 #ifdef LOG4CXX
2138  {
2139  std::stringstream sout;
2140  //sout << "\n NdirNp1_T2 = "<< NdirNp1_T2 <<endl;
2141  //sout << "\n NdirN_T1 = "<< NdirN_T1 <<endl;
2142  //LOGPZ_DEBUG(loggerx,sout.str().c_str());
2143  }
2144 #endif
2145 
2146  // Explicit scheme relative error: estimated by the difference between the
2147  // first and second order schemes results.
2148  normEpsPErr = epsPErr.Norm();
2149  // The second order scheme error is estimated based on the explicit Euler
2150  // scheme. Its relative error measure coincides with the Explicit Scheme
2151  // error estimation.
2152 
2153  // alphaRes = alpha(n+1)-alpha(n)-Sum delGamma * H
2154  alphaRes_T2 = Np1_T2.VolHardening() - N_T1.VolHardening();
2155 
2156  T2 multiplier;
2157 
2158  fYC.AlphaMultiplier(Np1_T2.VolHardening(), multiplier);
2159  alphaRes_T2 *= multiplier;
2160  for (i = 0; i < nyield; i++) {
2161  alphaRes_T2 -= delGamma_T2[i] * HMidPt_T2[i]; // 1 eq
2162  }
2163  // STATE multval = TPZExtractVal::val(multiplier);
2164  // multval = sqrt(fabs(multval));
2165  // alphaRes_T2 /= (T2)multval;
2166 
2167  // compute the values of the yield functions
2168  fYC.Compute(sigmaNp1_T2, ANp1_T2, phiRes_T2, 1); // nyield eq
2169 
2170  // transfer the values of the residuals to the residual vector
2171  // depending on the type T, the residual and its partial derivatives will have been computed
2172  for (i = 0; i < 6; i++) {
2173  res_T2[i] = epsResMidPt_T2.fData[i];
2174  }
2175  res_T2[i++] = alphaRes_T2;
2176  for (j = 0; j < nyield; j++) {
2177  res_T2[i++] = phiRes_T2[j];
2178  }
2179 
2180 }
2181 
2182 template <class YC_t, class TF_t, class ER_t>
2183 template <class T1, class T2>
2185  const TPZPlasticState<T1> &N_T1,
2186  TPZPlasticState<T2> &Np1_T2,
2187  const TPZVec<T2> &delGamma_T2,
2188  TPZVec<T2> &res_T2,
2189  REAL &normEpsPErr,
2190  int silent)const {
2191 
2192  // This function will be either called with template parameter T being REAL or FAD type
2193  // nyield indicates the number of yield functions
2194  const int nyield = YC_t::NYield;
2195 
2196  // variable to hold the value of the stress, elastic strain and residual corresponding to the plastic strain
2197  TPZTensor<T2> sigmaNp1_T2, epsResMidPt_T2;
2198  TPZTensor<T1> sigmaN_T1;
2199  // variable containing the error or deviation between solutions from Modified and
2200  // explicit Euler schemes
2201  TPZTensor<REAL> epsPErr;
2202 
2203  // vector holding the tensors of the N directions (usually derivative of the yield functions)
2204  TPZManVector<TPZTensor<T2>, nyield> NdirNp1_T2(nyield), NdirMidPt_T2(nyield), K1N_T2(nyield), K2N_T2(nyield), K3N_T2(nyield), K4N_T2(nyield), KTOTALN_T2(nyield);
2205  TPZManVector<TPZTensor<T1>, nyield> NdirN_T1(nyield), NdirN_T1COPY(nyield);
2206 
2207  // vector holding the residual of the yield function equations
2208  TPZManVector<T2, nyield> phiRes_T2(nyield), HNp1_T2(nyield), HMidPt_T2(nyield), K1H_T2(nyield), K2H_T2(nyield), K3H_T2(nyield), K4H_T2(nyield), KTOTALH_T2(nyield);
2209  TPZManVector<T1, nyield> HN_T1(nyield);
2210 
2211  // residual of the equation corresponding to the damage variable
2212  T2 alphaRes_T2, ANp1_T2;
2213  T1 AN_T1;
2214 
2215  ComputePlasticVars<T1>(N_T1, sigmaN_T1, AN_T1);
2216  ComputePlasticVars<T2>(Np1_T2, sigmaNp1_T2, ANp1_T2);
2217 
2218  // Compute the values of the N directions (which will update the plastic strain)
2219  fYC.N(sigmaN_T1, AN_T1, NdirN_T1, 0);
2220  fYC.N(sigmaNp1_T2, ANp1_T2, NdirNp1_T2, 1);
2221 
2222  //k1 = epspN ,k2 = epspN +(N1/2)*k1, k3 = epspN+(N1/2)*k2, k3 = epspN+N1*k3
2223  int i, j;
2224  for (i = 0; i < nyield; i++) {
2225  for (j = 0; j < 6; j++) {
2226  K1N_T2[i].fData[j] = N_T1.m_eps_p.fData[j];
2227  K2N_T2[i].fData[j] = N_T1.m_eps_p.fData[j] + (NdirN_T1[i].fData[j]/*+NdirN_T2[i].fData[j]*/) * T2(0.5) * K1N_T2[i].fData[j];
2228  K3N_T2[i].fData[j] = N_T1.m_eps_p.fData[j] + (NdirN_T1[i].fData[j]/*+NdirN_T2[i].fData[j]*/) * T2(0.5) * K2N_T2[i].fData[j];
2229  K4N_T2[i].fData[j] = N_T1.m_eps_p.fData[j] + (NdirN_T1[i].fData[j]/*+NdirN_T2[i].fData[j]*/) * K3N_T2[i].fData[j];
2230  KTOTALN_T2[i].fData[j] = K1N_T2[i].fData[j] + T2(2.) * K2N_T2[i].fData[j] + T2(2.) * K3N_T2[i].fData[j] + K4N_T2[i].fData[j];
2231 
2232  NdirN_T1COPY[i].fData[j] = NdirN_T1[i].fData[j];
2233 
2234  }
2235 
2236 
2237  }
2238 
2239 
2240  // Compute the value of H
2241  fYC.H(sigmaN_T1, AN_T1, HN_T1, 0);
2242  fYC.H(sigmaNp1_T2, ANp1_T2, HNp1_T2, 1);
2243 
2244  for (i = 0; i < nyield; i++) {
2245  K1H_T2[i] = N_T1.m_hardening;
2246  K2H_T2[i] = N_T1.m_hardening + HN_T1[i] * T2(0.5) * K1H_T2[i];
2247  K3H_T2[i] = N_T1.m_hardening + HN_T1[i] * T2(0.5) * K2H_T2[i];
2248  K4H_T2[i] = N_T1.m_hardening + HN_T1[i] * K3H_T2[i];
2249  KTOTALH_T2[i] = K1H_T2[i]+(T2(2.) * K2H_T2[i])+(T2(2.) * K3H_T2[i]) + K2H_T2[i];
2250 
2251  }
2252 
2253 
2254 
2255  //EpsRes = EpsilonPNp1 - m_eps_p - ((deltagamma * Ndir)/6)*(k1+2k2+2k3+k4); // 6 eqs
2256  for (i = 0; i < nyield; i++) {
2257  //deltagamma * Ndir
2258  NdirN_T1COPY[i].Multiply(delGamma_T2[i], T2(1. / 6.));
2259  NdirN_T1COPY[i].Multiply(K1H_T2[i], T2(1.));
2260  epsResMidPt_T2.Add(NdirN_T1COPY[i], T2(-1.));
2261 
2262  NdirN_T1[i].Multiply(T1(TPZExtractVal::val(delGamma_T2[i])), T1(1.));
2263  for (j = 0; j < 6; j++)epsPErr.fData[j] += TPZExtractVal::val(NdirN_T1[i]. fData[j])
2264  - TPZExtractVal::val(NdirN_T1COPY[i].fData[j]);
2265  }
2266  //????
2267  epsResMidPt_T2.Add(N_T1.EpsP(), T1(-1.));
2268  epsResMidPt_T2.Add(Np1_T2.EpsP(), T1(1.));
2269 
2270  // Explicit scheme relative error: estimated by the difference between the
2271  // first and second order schemes results.
2272  normEpsPErr = epsPErr.Norm();
2273  // The second order scheme error is estimated based on the explicit Euler
2274  // scheme. Its relative error measure coincides with the Explicit Scheme
2275  // error estimation.
2276 
2277  // alphaRes = alpha(n+1)-alpha(n)-Sum delGamma * H
2278  alphaRes_T2 = Np1_T2.VolHardening() - N_T1.VolHardening();
2279  for (i = 0; i < nyield; i++) {
2280  alphaRes_T2 -= delGamma_T2[i] * HN_T1[i] * T2(1. / 6.) * KTOTALH_T2[i]; // 1 eq
2281  }
2282 
2283  // compute the values of the yield functions
2284  fYC.Compute(sigmaNp1_T2, ANp1_T2, phiRes_T2, 1); // nyield eq
2285 
2286  // transfer the values of the residuals to the residual vector
2287  // depending on the type T, the residual and its partial derivatives will have been computed
2288  for (i = 0; i < 6; i++) {
2289  res_T2[i] = epsResMidPt_T2.fData[i];
2290  }
2291  res_T2[i++] = alphaRes_T2;
2292  for (j = 0; j < nyield; j++) {
2293  res_T2[i++] = phiRes_T2[j];
2294  }
2295 
2296 
2297 #ifdef LOG4CXX
2298  if (plasticIntegrLogger->isDebugEnabled()) {
2299  std::stringstream sout;
2300  /* sout << "\n res_T2 = " << res_T2 <<endl;
2301  sout << "\n K1N_T2 = " << K1N_T2 <<endl;
2302  sout << "\n K2N_T2 = " << K2N_T2 <<endl;
2303  sout << "\n K3N_T2 = " << K3N_T2 << endl;
2304  sout << "\n K4N_T2 = " << K4N_T2 << endl;
2305  sout << "\n K1H_T2 = " << K1H_T2 <<endl;
2306  sout << "\n K2H_T2 = " << K2H_T2 <<endl;
2307  sout << "\n K3H_T2 = " << K3H_T2 << endl;
2308  sout << "\n K4H_T2 = " << K4H_T2 << endl;
2309  */
2310  sout << "\n epsResMidPt_T2 = " << epsResMidPt_T2 << endl;
2311  sout << "\n alphaRes_T2 = " << alphaRes_T2 << endl;
2312  sout << "\n NdirN_T1 = " << NdirN_T1 << endl;
2313  LOGPZ_DEBUG(plasticIntegrLogger, sout.str().c_str());
2314  }
2315 #endif
2316 
2317 
2318 }
2319 
2320 template <class YC_t, class TF_t, class ER_t>
2321 template<class T1, class T2, class TVECTOR>
2323  const TPZPlasticState<T1> &N_T1,
2324  TPZPlasticState<T2> &Np1_T2,
2325  TPZVec<T2> &delGamma_T2,
2326  TPZVec<T2> &res_T2,
2327  TVECTOR & Sol_TVECTOR,
2328  TPZVec<int> & validEqs,
2329  int updateVars)const {
2330  const int nyield = YC_t::NYield;
2331  const int nVars = 7 + nyield;
2332  TPZManVector<REAL, nyield> delGamma(nyield);
2333  REAL sqrNormResN = 0, sqrNormResNp1, normEpsPErr;
2335  TPZPlasticState<REAL> Np1, N;
2336  int i, j;
2337 
2338  Np1_T2.CopyTo(Np1);
2339  N_T1.CopyTo(N);
2340 
2341  for (i = 0; i < 6; i++) Np1.m_eps_p.fData[i] -= TPZExtractVal::val(Sol_TVECTOR(i));
2342  Np1.m_hardening -= TPZExtractVal::val(Sol_TVECTOR(i++));
2343  for (j = 0; j < nyield; j++)delGamma[j] = TPZExtractVal::val(delGamma_T2[j]) - TPZExtractVal::val(Sol_TVECTOR(i++));
2344 
2345  PlasticResidual<REAL, REAL>(N, Np1, delGamma, res, normEpsPErr, 1 /*silent*/);
2346  // PlasticResidualRK<REAL, REAL>(N, Np1, delGamma, res, normEpsPErr, 1 /*silent*/);
2347 
2348  sqrNormResNp1 = pow(sdot(res, res), 0.5);
2349 
2350  const REAL k = 2.;
2351  REAL lambda = 1.; // ensuring that the lambda value will be ONE at the first step
2352 
2353  do {
2354  sqrNormResN = sqrNormResNp1;
2355 
2356  lambda /= k;
2357 
2358  Np1_T2.CopyTo(Np1);
2359  for (i = 0; i < 6; i++) Np1.m_eps_p.fData[i] -= lambda * TPZExtractVal::val(Sol_TVECTOR(i));
2360  Np1.m_hardening -= lambda * TPZExtractVal::val(Sol_TVECTOR(i++));
2361  for (j = 0; j < nyield; j++)delGamma[j] = TPZExtractVal::val(delGamma_T2[j]) - lambda * TPZExtractVal::val(Sol_TVECTOR(i++));
2362 
2363  PlasticResidual<REAL, REAL>(N, Np1, delGamma, res, normEpsPErr, 1 /*silent*/);
2364  // PlasticResidualRK<REAL, REAL>(N, Np1, delGamma, res, normEpsPErr, 1 /*silent*/);
2365 
2366  // resetting invalid equations
2367  for (i = 0; i < nyield; i++)
2368  if (validEqs[i] == 0)
2369  res[i + 7] = 0.;
2370 
2371  sqrNormResNp1 = pow(sdot(res, res), 0.5);
2372 
2373  } while (sqrNormResNp1 < sqrNormResN && lambda >= fMinLambda); // ensuring that the step will be larger than fMinLambda
2374  // to avoid wandering within local minima.
2375 
2376  lambda *= k;
2377 
2378  if (lambda < 1.) {
2379 #ifdef LOG4CXX_PLASTICITY
2380  {
2381  std::stringstream sout;
2382  sout << "*** UpdatePlasticVars *** Line Search indicates lambda = " << lambda << " to ensure residual drop.";
2383  LOGPZ_DEBUG(logger, sout.str().c_str());
2384  }
2385 #endif
2386  }
2387 
2388  if (!updateVars) return lambda;
2389 
2390  for (i = 0; i < 6; i++) Np1_T2.m_eps_p.fData[i] -= T2(lambda * Sol_TVECTOR(i));
2391  Np1_T2.m_hardening -= T2(lambda * Sol_TVECTOR(i++));
2392  for (j = 0; j < YC_t::NYield; j++) delGamma_T2[j] -= T2(lambda * Sol_TVECTOR(i++));
2393 
2394  return lambda;
2395 
2396 }
2397 
2398 template <class YC_t, class TF_t, class ER_t>
2399 template<class T>
2401  const TPZPlasticState<REAL> &state,
2402  const TPZVec<REAL> &delGamma,
2403  TPZPlasticState<T> &state_T,
2404  TPZVec<T> &delGamma_T,
2405  const int nVars)const {
2406  int i;
2407  int nVarsPlastic = 7 + YC_t::NYield;
2408 
2409  // copying values
2410  state.CopyTo(state_T); // also initializing derivatives to null
2411  for (i = 0; i < YC_t::NYield; i++)delGamma_T[i] = delGamma[i];
2412 
2413  // Initialize the partial derivative values
2414  // the first 6 independent variables are the values of the plastic strains
2415  for (i = 0; i < 6; i++) state_T.m_eps_p.fData[i].diff(i, nVars);
2416  // the damage variable is the seventh variable
2417 
2418  state_T.m_hardening.diff(6, nVars);
2419  // the remaining variables are the yield function multipliers
2420  for (i = 7; i < nVarsPlastic; i++) delGamma_T[i - 7].diff(i, nVars);
2421 
2422 }
2423 
2424 template <class YC_t, class TF_t, class ER_t>
2426  const int nVars = 6;
2427  REAL resnorm;
2428  int i, k = 0;
2429  TPZFNMatrix<nVars * nVars> Dep_mat(nVars, nVars);
2430  TPZFNMatrix<nVars> residual_mat(nVars, 1),
2431  sol_mat(nVars, 1);
2432 
2433  TPZTensor<REAL> epsTotal(fN.m_eps_t), EEpsilon;
2434 
2435 #ifdef LOG4CXX
2436  if (plasticIntegrLogger->isDebugEnabled()) {
2437  std::stringstream sout;
2438  sout << ">>> ProcessLoad *** Evaluating Sigma to compute the resultant stress for the guess strain - Preparing starting tangent matrix for Newton's scheme";
2439  sout << "\n sigma << " << sigma;
2440  LOGPZ_DEBUG(plasticIntegrLogger, sout.str().c_str());
2441  }
2442 #endif
2443 #ifdef LOG4CXX_PLASTICITY
2444  {
2445  std::stringstream sout1, sout2;
2446  sout1 << ">>> ProcessLoad *** Evaluating Sigma to compute the resultant stress for the guess strain - Preparing starting tangent matrix for Newton's scheme";
2447  sout2 << "\n sigma << " << sigma;
2448  LOGPZ_DEBUG(logger, sout1.str().c_str());
2449  LOGPZ_DEBUG(logger, sout2.str().c_str());
2450  }
2451 #endif
2452 
2453  //cout << "\nstarting ProcessStrain/ComputeDep";
2454  //cout.flush();
2456  /*
2457  TPZYCSandlerDimaggio *yc = (TPZYCSandlerDimaggio *)(&fYC);
2458  TPZYCSandlerDimaggioL *ycl = dynamic_cast<TPZYCSandlerDimaggioL *>(yc);
2459  TPZManVector<REAL> epsx(50),sigx(50),dsig(50),epsv(50),L(50),DepsVdL(50);
2460 
2461  for(int i=0; i<50; i++)
2462  {
2463  epsTotal.XX() = -0.025*i/50.;
2464  epsTotal.YY() = -0.025*i/50.;
2465  epsTotal.ZZ() = -0.025*i/50.;
2466  ProcessStrain(epsTotal, EAuto);
2467  ComputeDep(EEpsilon, Dep_mat);
2468  ApplyStrain(epsTotal);
2469  REAL diagdep = 0;
2470  for (int j=0; j< 6; j++) {
2471  diagdep += Dep_mat(j,0);
2472  }
2473  epsx[i] = epsTotal[0];
2474  sigx[i] = EEpsilon[0];
2475  dsig[i] = diagdep;
2476  if (ycl) {
2477  int n = this->fPlasticMem.size();
2478  L[i] = this->fPlasticMem[n-1].m_elastoplastic_state.m_hardening;
2479  yc->EpspFromL(L[i], epsv[i]);
2480  yc->DEpspDL(L[i], DepsVdL[i]);
2481  }
2482  else {
2483  REAL X;
2484  int n = this->fPlasticMem.size();
2485  epsv[i] = this->fPlasticMem[n-1].m_elastoplastic_state.m_hardening;
2486  yc->ComputeX(epsv[i], X);
2487  yc->SolveL(X, L[i]);
2488  yc->DEpspDL(L[i], DepsVdL[i]);
2489  }
2490  {
2491  std::stringstream sout;
2492  sout << "Sigma " << EEpsilon << std::endl;
2493  sout << "espTotal " << epsTotal << std::endl;
2494  sout << "D Sigma_x/Deps" << diagdep;
2495  Dep_mat.Print("depmat",sout);
2496  LOGPZ_DEBUG(logger, sout.str())
2497  }
2498  }
2499  {
2500  std::stringstream sout;
2501  sout << "eps = { "<< epsx << "};\n";
2502  sout << "sig = { "<< sigx << "};\n";
2503  sout << "dsigdeps = { " << dsig << " };\n";
2504  sout << "epsv = { " << epsv << " };\n";
2505  sout << "L = { " << L << " };\n";
2506  sout << "depsvdl = { " << DepsVdL << " };\n";
2507  LOGPZ_DEBUG(logger, sout.str())
2508  }
2509  epsTotal = TPZTensor<REAL>();
2510  */
2512  // evaluating the plastic integration, stress tensor and jacobian
2513  //ProcessStrainNoSubIncrement(epsTotal,EAuto);
2514  ProcessStrain(epsTotal, EAuto);
2515  ComputeDep(EEpsilon, Dep_mat);
2516 
2517  //cout << "\nended ProcessStrain/ComputeDep";
2518  //cout.flush();
2519 
2520  resnorm = 0.;
2521  for (i = 0; i < nVars; i++)residual_mat(i, 0) = EEpsilon.fData[i] - sigma.fData[i];
2522  for (i = 0; i < nVars; i++)resnorm += pow(residual_mat(i, 0), 2.);
2523  resnorm = sqrt(resnorm);
2524 
2525  while (resnorm > fResTol && k < fMaxNewton) {
2526  k++;
2527 
2528  TPZFNMatrix<nVars * nVars> *matc = new TPZFNMatrix<nVars * nVars>(nVars, nVars);
2529  *matc = Dep_mat;
2530 
2531 #ifdef LOG4CXX
2532 
2533  if (logger->isDebugEnabled()) {
2534  std::stringstream sout;
2535  Dep_mat.Print("Derivative", sout);
2536  sout << "EEpsilon " << EEpsilon << std::endl;
2537  LOGPZ_DEBUG(logger, sout.str())
2538  }
2539 #endif
2540 
2541  // cout << "\nNewton Method Step " << k << "\nDep=" << Dep_mat << endl << residual_mat;
2542  // cout.flush();
2543 
2544  TPZStepSolver<REAL> st(matc);
2545  st.SetDirect(ELU);
2546 
2547 
2548  // invert the tangent matrix and put the correction in the Sol variable
2549  st.Solve(residual_mat, sol_mat, 0);
2550 
2551  //cout << "\n solve ended:" << sol_mat;
2552  //cout.flush();
2553 
2554  TPZTensor<REAL> epsTotalPrev(epsTotal);
2555  REAL scalefactor = 1.;
2556  REAL resnormprev = resnorm;
2557 
2558  do {
2559  for (i = 0; i < nVars; i++)epsTotal.fData[i] = epsTotalPrev.fData[i] - scalefactor * sol_mat(i, 0);
2560 
2561 #ifdef LOG4CXX
2562 
2563  if (logger->isDebugEnabled()) {
2564  std::stringstream sout;
2565  sout << "Next epsTotal " << epsTotal << std::endl;
2566  LOGPZ_DEBUG(logger, sout.str())
2567  }
2568 #endif
2569  //cout << "\nstarting ProcessStrain/ComputeDep";
2570  //cout.flush();
2571 
2572  // evaluating the plastic integration, stress tensor and jacobian
2573  // ProcessStrainNoSubIncrement(epsTotal,ep);
2574  ProcessStrain(epsTotal, /*o original e ep e nao EAuto */ ep);
2575  ComputeDep(EEpsilon, Dep_mat);
2576 
2577  //cout << "\nended ProcessStrain/ComputeDep";
2578  //cout.flush();
2579 
2580  resnorm = 0.;
2581  for (i = 0; i < nVars; i++)residual_mat(i, 0) = EEpsilon.fData[i] - sigma.fData[i];
2582  for (i = 0; i < nVars; i++)resnorm += pow(residual_mat(i, 0), 2.);
2583  resnorm = sqrt(resnorm);
2584 
2585  scalefactor *= 0.5;
2586  } while (resnorm > resnormprev);
2587  //cout << "\nresidual = " << resnorm;
2588 
2589 #ifdef LOG4CXX
2590  if (plasticIntegrLogger->isDebugEnabled()) {
2591  std::stringstream sout;
2592  sout << "*** ProcessLoad *** " << k << "-th iteration of Newton's scheme with residual = " << resnorm;
2593  LOGPZ_DEBUG(plasticIntegrLogger, sout.str().c_str());
2594  }
2595 #endif
2596 #ifdef LOG4CXX_PLASTICITY
2597  {
2598  std::stringstream sout;
2599  sout << "*** ProcessLoad *** " << k << "-th iteration of Newton's scheme with residual = " << resnorm;
2600  LOGPZ_DEBUG(logger, sout.str().c_str());
2601  }
2602 #endif
2603 
2604  if (k > fMaxNewton)cout << "\n*** ProcessLoad step " << k << " with res= " << resnorm;
2605  }
2606 
2607 #ifdef LOG4CXX_PLASTICITY
2608  {
2609  std::stringstream sout;
2610 
2611  if (k > fMaxNewton) {
2612  sout << "<<< ProcessLoad *** Exiting Method with residual = " << resnorm
2613  << " after " << k << " steps.";
2614  sout << "\n#### Truncated Newton ####. Results are unpredictable";
2615  LOGPZ_WARN(logger, sout.str().c_str());
2616  LOGPZ_WARN(plasticIntegrLogger, sout.str().c_str());
2617  } else {
2618  sout << "<<< ProcessLoad *** Exiting Method with residual = " << resnorm;
2619  LOGPZ_DEBUG(logger, sout.str().c_str());
2620  LOGPZ_DEBUG(plasticIntegrLogger, sout.str().c_str());
2621  }
2622  }
2623 #endif
2624 
2625 }
2626 
2630 template <class YC_t, class TF_t, class ER_t>
2632  TPZTensor<REAL> sigma;
2633  REAL A;
2634 
2635  TPZPlasticState<REAL> state(fN);
2636  state.m_eps_t = epsTotal;
2637 
2638  ComputePlasticVars<REAL>(state, sigma, A);
2639 
2640  fYC.Compute(sigma, A, phi, 0);
2641 
2642  return;
2643 }
2644 
2645 template <class YC_t, class TF_t, class ER_t>
2646 template <int N>
2648  const TPZPlasticState<REAL> & state,
2649  const REAL & k,
2650  const REAL & lambda,
2651  const TPZManVector<REAL, N> & delGamma,
2652  const TPZVec<int> & validEqs,
2653  const int forceYield) {
2654  TPZPlasticIntegrMem<REAL, YC_t::NYield> Mem(state, k, lambda, delGamma, validEqs, forceYield);
2655  fPlasticMem.Push(Mem);
2656 
2657 }
2658 
2659 template <class YC_t, class TF_t, class ER_t>
2661 
2662 #ifdef LOG4CXX
2663  if (plasticIntegrLogger->isDebugEnabled()) {
2664  std::stringstream sout;
2665  sout << ">>> ApplyLoad_Internal ***"
2666  << " Imposed sigma << " << sigma;
2667  LOGPZ_DEBUG(plasticIntegrLogger, sout.str().c_str());
2668  }
2669 #endif
2670 
2671 #ifdef LOG4CXX
2672  if (pointloadconfig->isDebugEnabled()) {
2673  std::stringstream sout;
2674  sout << ">>> ApplyLoad_Internal ***"
2675  << " Imposed sigma << " << sigma;
2676  LOGPZ_DEBUG(pointloadconfig, sout.str().c_str());
2677  }
2678 #endif
2679 
2680 #ifdef LOG4CXX_PLASTICITY
2681  {
2682  std::stringstream sout;
2683  sout << ">>> ApplyLoad_Internal ***"
2684  << " Imposed sigma << " << sigma;
2685  LOGPZ_DEBUG(logger, sout.str().c_str());
2686  }
2687 #endif
2688  /*
2689  ProcessLoad(sigma, EAuto);
2690 
2691  int n = fPlasticMem.NElements();
2692  */
2693 
2694 #ifdef LOG4CXX_PLASTICITY
2695  {
2696  std::stringstream sout;
2697  sout << ">>> ApplyLoad_Internal ***"
2698  << " Forcing Elastic behaviour";
2699  LOGPZ_DEBUG(logger, sout.str().c_str());
2700  }
2701 #endif
2702 
2703  ProcessLoad(sigma, EForceElastic);
2704  int n = fPlasticMem.NElements();
2705 
2706  if (!IsStrainElastic(fPlasticMem[n - 1].m_elastoplastic_state)) {
2707 #ifdef LOG4CXX_PLASTICITY
2708  {
2709  std::stringstream sout;
2710  sout << ">>> ApplyLoad_Internal ***"
2711  << " Forcing Plastic behaviour - Elastic attempt led to a final plastic state";
2712  LOGPZ_DEBUG(logger, sout.str().c_str());
2713  }
2714 #endif
2715  ProcessLoad(sigma, EForcePlastic);
2716  n = fPlasticMem.NElements();
2717  }
2718 
2719  TPZPlasticStep<YC_t, TF_t, ER_t>::SetState_Internal(fPlasticMem[n - 1].m_elastoplastic_state);
2720 
2721  epsTotal = fN.m_eps_t;
2722 
2723 #ifdef LOG4CXX_PLASTICITY
2724  {
2725  std::stringstream sout1, sout2;
2726  sout1 << "<<< ApplyLoad_Internal ***";
2727  sout2 << "\nOutput epsTotal << " << epsTotal;
2728  LOGPZ_DEBUG(logger, sout1.str().c_str());
2729  LOGPZ_DEBUG(logger, sout2.str().c_str());
2730  }
2731 #endif
2732 
2733 }
2734 
2735 template <class YC_t, class TF_t, class ER_t>
2737  int i, j, n = fPlasticMem.NElements();
2738 
2739  if (n <= 2) return 0;
2740 
2741  plastifLen.Fill(0.);
2742  REAL plasticLen = 0., deltaK;
2743 
2744  for (i = 2; i < n; i++) {
2745  deltaK = fPlasticMem[i].fK - fPlasticMem[i - 1].fK;
2746  for (j = 0; j < YC_t::NYield; j++)if (fPlasticMem[i].fValidEqs[j])plastifLen[j] += deltaK;
2747  plasticLen += deltaK;
2748  }
2749 
2750  return plasticLen;
2751 }
2752 
2753 template<class YC_t, class TF_t, class ER_t>
2754 void TPZPlasticStep<YC_t, TF_t, ER_t>::Write(TPZStream& buf, int withclassid) const {
2755  fYC.Write(buf, withclassid);
2756  fTFA.Write(buf, withclassid);
2757  fER.Write(buf, withclassid);
2758  buf.Write(&fResTol);
2759  buf.Write(&fIntegrTol);
2760  buf.Write(&fMaxNewton);
2761  buf.Write(&fMinLambda);
2762  buf.Write(&fMinStepSize);
2763  fN.Write(buf, withclassid);
2764  if (fPlasticMem.NElements() > 0) {
2765  DebugStop();
2766  }
2767  buf.Write(&fMaterialTensionSign);
2768  buf.Write(&fInterfaceTensionSign);
2769 }
2770 
2771 template<class YC_t, class TF_t, class ER_t>
2773  fYC.Read(buf, context);
2774  fTFA.Read(buf, context);
2775  fER.Read(buf, context);
2776  buf.Read(&fResTol);
2777  buf.Read(&fIntegrTol);
2778  buf.Read(&fMaxNewton);
2779  buf.Read(&fMinLambda);
2780  buf.Read(&fMinStepSize);
2781  fN.Read(buf, context);
2782  if (fPlasticMem.NElements() > 0) {
2783  DebugStop();
2784  }
2785  buf.Read(&fMaterialTensionSign);
2786  buf.Read(&fInterfaceTensionSign);
2787 }
2788 
2790 
2791 template <class YC_t, class TF_t, class ER_t>
2793  fER = ER;
2794 }
2795 
2796 template<>
2798  DebugStop();
2799 }
2800 
2801 template <class YC_t, class TF_t, class ER_t>
2803  return fER;
2804 }
2805 
2806 template<>
2808  DebugStop();
2809  //Must return something
2810  TPZElasticResponse ret;
2811  return ret;
2812 }
2813 
2814 
2815 
2816 template <class YC_t, class TF_t, class ER_t>
2818 
2819 
2824 
2826 
2829 
2830 #include "TPZYCMohrCoulomb.h"
2831 #include "TPZYCWillamWarnke.h"
2832 #include "TPZYCModifiedMohrCoulomb.h"
2833 //#include "TPZYCDruckerPragerBase.h"
2834 
2838 //template class TPZPlasticStep<TPZYCDruckerPragerBase< TPZYCMohrCoulomb >, TPZThermoForceA, TPZElasticResponse>;
2839 
2841 PlasticResidual<REAL, REAL>(TPZPlasticState<REAL> const &,
2842  TPZPlasticState<REAL> &,
2843  TPZVec<REAL> const&,
2844  TPZVec<REAL> &,
2845  REAL &, int) const;
2846 
2848 PlasticResidual<REAL, TFad<14, REAL> >(TPZPlasticState<REAL> const &,
2850  TPZVec<TFad<14, REAL> > const &,
2851  TPZVec<TFad<14, REAL> > &,
2852  REAL &, int) const;
2853 
2854 
2855 //template void TPZPlasticStep<TPZYCLadeKim, TPZLadeKimThermoForceA, TPZLadeNelsonElasticResponse>::
2856 //PlasticResidualRK<REAL, REAL>(TPZPlasticState<REAL> const &,
2857 // TPZPlasticState<REAL> &,
2858 // TPZVec<REAL> const&,
2859 // TPZVec<REAL> &,
2860 // REAL &, int)const;
2861 //
2862 //template void TPZPlasticStep<TPZYCLadeKim, TPZLadeKimThermoForceA, TPZLadeNelsonElasticResponse>::
2863 //PlasticResidualRK<REAL, TFad<14,REAL> >(TPZPlasticState<REAL> const &,
2864 // TPZPlasticState< TFad<14,REAL> > &,
2865 // TPZVec<TFad<14,REAL> > const &,
2866 // TPZVec<TFad<14,REAL> > &,
2867 // REAL &, int)const;
2868 
2878 template <>
2880  const TPZPlasticState<REAL> &N,
2881  TPZPlasticState<REAL> &Np1,
2882  TPZVec<REAL> &delGamma,
2883  TPZVec<int> &validEqs
2884  ) {
2885  TPZTensor<REAL> EpN = N.m_eps_p;
2886  TPZTensor<REAL> ETotal = Np1.m_eps_t;
2887  TPZTensor<REAL> ETrial = ETotal;
2888  TPZTensor<REAL> sigmaTrial;
2889  ETrial.Add(EpN, -1.);
2890  fER.ComputeStress(ETrial, sigmaTrial);
2891  TPZTensor<REAL> sigproj;
2892  fYC.InitialGuess(fER, N.m_hardening, sigmaTrial, Np1.m_hardening, delGamma, sigproj);
2893  TPZTensor<REAL> sigPlast(sigmaTrial);
2894  sigPlast.Add(sigproj, -1.);
2895  fER.ComputeStrain(sigPlast, Np1.m_eps_p);
2896  Np1.m_eps_p.Add(N.m_eps_p, 1.);
2897  validEqs.Fill(0);
2898  for (int i = 0; i < 2; i++) {
2899  if (delGamma[i] > 0.) {
2900  validEqs[i] = 1;
2901  }
2902  }
2903 #ifdef LOG4CXX
2904  {
2905  std::stringstream sout;
2906  sout << "epsp next " << Np1.m_hardening << std::endl;
2907  sout << "delGamma " << delGamma << std::endl;
2908  sout << "validEqs " << validEqs << std::endl;
2909  TPZManVector<REAL, 2> Residual(2);
2910  fYC.Compute(sigmaTrial, N.m_hardening, Residual, 1);
2911  sout << "residual before projection" << Residual << std::endl;
2912  fYC.Compute(sigproj, Np1.m_hardening, Residual, 1);
2913  sout << "residual after projection" << Residual << std::endl;
2914  LOGPZ_DEBUG(loggerSM, sout.str())
2915  }
2916 #endif
2917 }
2918 
2919 template <>
2921  const TPZPlasticState<REAL> &N,
2922  TPZPlasticState<REAL> &Np1,
2923  TPZVec<REAL> &delGamma,
2924  TPZVec<int> &validEqs
2925  ) {
2926  TPZTensor<REAL> EpN = N.m_eps_p;
2927  TPZTensor<REAL> ETotal = Np1.m_eps_t;
2928  TPZTensor<REAL> ETrial = ETotal;
2929  TPZTensor<REAL> sigmaTrial;
2930  ETrial.Add(EpN, -1.);
2931  fER.ComputeStress(ETrial, sigmaTrial);
2932  TPZTensor<REAL> sigproj;
2933  fYC.InitialGuess(fER, N.m_hardening, sigmaTrial, Np1.m_hardening, delGamma, sigproj);
2934  TPZTensor<REAL> sigPlast(sigmaTrial);
2935  sigPlast.Add(sigproj, -1.);
2936  fER.ComputeStrain(sigPlast, Np1.m_eps_p);
2937  Np1.m_eps_p.Add(N.m_eps_p, 1.);
2938  validEqs.Fill(0);
2939  for (int i = 0; i < 2; i++) {
2940  if (delGamma[i] > 0.) {
2941  validEqs[i] = 1;
2942  }
2943  }
2944 #ifdef LOG4CXX
2945  {
2946  std::stringstream sout;
2947  sout << "epsp next " << Np1.m_hardening << std::endl;
2948  sout << "delGamma " << delGamma << std::endl;
2949  sout << "validEqs " << validEqs << std::endl;
2950  TPZManVector<REAL, 2> Residual(2);
2951  fYC.Compute(sigmaTrial, N.m_hardening, Residual, 1);
2952  sout << "residual before projection" << Residual << std::endl;
2953  fYC.Compute(sigproj, Np1.m_hardening, Residual, 1);
2954  sout << "residual after projection" << Residual << std::endl;
2955  LOGPZ_DEBUG(loggerSM, sout.str())
2956  }
2957 #endif
2958 }
2959 
2960 template <>
2962  const TPZPlasticState<REAL> &N,
2963  TPZPlasticState<REAL> &Np1,
2964  TPZVec<REAL> &delGamma,
2965  TPZVec<int> &validEqs
2966  ) {
2967  TPZTensor<REAL> EpN = N.m_eps_p;
2968  TPZTensor<REAL> ETotal = Np1.m_eps_t;
2969  TPZTensor<REAL> ETrial = ETotal;
2970  TPZTensor<REAL> sigmaTrial;
2971  ETrial.Add(EpN, -1.);
2972  fER.ComputeStress(ETrial, sigmaTrial);
2973  TPZTensor<REAL> sigproj;
2974  fYC.InitialGuess(fER, N.m_hardening, sigmaTrial, Np1.m_hardening, delGamma, sigproj);
2975  TPZTensor<REAL> sigPlast(sigmaTrial);
2976  sigPlast.Add(sigproj, -1.);
2977  fER.ComputeStrain(sigPlast, Np1.m_eps_p);
2978  Np1.m_eps_p.Add(N.m_eps_p, 1.);
2979  validEqs.Fill(0);
2980  for (int i = 0; i < 2; i++) {
2981  if (delGamma[i] > 0.) {
2982  validEqs[i] = 1;
2983  }
2984  }
2985 #ifdef LOG4CXX
2986  {
2987  std::stringstream sout;
2988  sout << "epsp next " << Np1.m_hardening << std::endl;
2989  sout << "delGamma " << delGamma << std::endl;
2990  sout << "validEqs " << validEqs << std::endl;
2991  TPZManVector<REAL, 2> Residual(2);
2992  fYC.Compute(sigmaTrial, N.m_hardening, Residual, 1);
2993  sout << "residual before projection" << Residual << std::endl;
2994  fYC.Compute(sigproj, Np1.m_hardening, Residual, 1);
2995  sout << "residual after projection" << Residual << std::endl;
2996  LOGPZ_DEBUG(loggerSM, sout.str())
2997  }
2998 #endif
2999 }
3000 
3001 
3002 
3004 
3006 
3008 
3009 
3011 
3012 template void TPZPlasticStep<TPZYCSandlerDimaggioL, TPZSandlerDimaggioThermoForceA, TPZElasticResponse>::ComputePlasticVars<REAL>(TPZPlasticState<REAL> const&, TPZTensor<REAL>&, REAL&) const;
3013 
3014 template void TPZPlasticStep<TPZYCSandlerDimaggioL2, TPZSandlerDimaggioThermoForceA, TPZElasticResponse>::ComputePlasticVars<REAL>(TPZPlasticState<REAL> const&, TPZTensor<REAL>&, REAL&) const;
Classe que efetua avanco de um passo de plastificacao utilizando o metodo de Newton.
virtual void Phi_Internal(const TPZTensor< REAL > &epsTotal, TPZVec< REAL > &phi) const
Return the value of the yield functions for the given strain Internal Method.
virtual void SetUp(const TPZTensor< REAL > &epsTotal)
Overwrite the current total strain only.
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 ApplyLoad_Internal(const TPZTensor< REAL > &sigma, TPZTensor< REAL > &epsTotal)
Attempts to compute an epsTotal value in order to reach an imposed stress state sigma. This methid should be used only for test purposes because it isn&#39;t fully robust. Some materials, specially those perfectly plastic and with softening, may fail when applying the Newton Method on ProcessLoad. Internal Method.
T Norm() const
Definition: TPZTensor.h:854
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.
TPZTensor< T > m_eps_t
Tensors representing the total and plastic strain states.
virtual void ProcessStrainNoSubIncrement(const TPZTensor< REAL > &epsTotal, const EElastoPlastic ep=EAuto)
Imposes the specified strain tensor and performs plastic integration when necessary. This function DO NOT calls PlasticIntegrate.
TPZManVector< T, 6 > fData
Definition: TPZTensor.h:652
T m_hardening
Plastic volumetric hardeing variable.
Defines step solvers class. Solver.
Definition: pzmganalysis.h:17
void InitializePlasticFAD(const TPZPlasticState< REAL > &state, const TPZVec< REAL > &delGamma, TPZPlasticState< T > &state_T, TPZVec< T > &delGamma_T, const int nVars=7+YC_t::NYield) const
This method copies the REAL variables into FAD variables and intializes the derivatives The nVars var...
void ApplyStrain_Internal(const TPZTensor< REAL > &epsTotal)
Imposes the specified strain tensor, evaluating the plastic integration if necessary. Internal Method.
double sdot(TPZVec< T1 > &x, TPZVec< T1 > &y)
Performs a sdot operation: dot <- Transpose[x] * y.
Definition: pzvec_extras.h:98
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
#define LOGPZ_WARN(A, B)
Define log for warnings.
Definition: pzlog.h:91
int RemoveInvalidEqs(TPZVec< T > &delGamma_T, TPZVec< T > &res_T, TPZVec< int > &validEqs)
After a complete plasticLoop, plsatic surface equations related to negative plastic multipliers are d...
void ExtractTangent(const TPZVec< T1 > &epsRes_FAD, T_VECTOR &ResVal, REAL &resnorm, T_MATRIX &tangent, TPZVec< int > &validEqs, TPZVec< REAL > &pivots, const int precond=1, const int resetInvalidEqs=1)
Extracts the tangent matrix and residual vector from the FAD variables and according to the precondit...
virtual REAL IntegrationOverview(TPZVec< REAL > &plastifLen)
Similar to IntegrationSteps, it returns the plastic parcel of the last loading. 1.0 means that the whole step was plastic, 0.0 means the whole step was elastic.
bool IsStrainElastic(const TPZPlasticState< REAL > &state) const
Verifies if the proposed epsTotalNp1 is still in the elastic range.
EStatus Substitution(TPZDiffMatrix< T > *B) const
Definition: pzdiffmatrix.h:406
void CopyTo(TPZPlasticState< T1 > &target) const
int InitializeValidEqs(TPZVec< T > &res_T, TPZVec< int > &validEqs)
Initializes the fValidEqs booleans indication whether to consider the plastic surfaces.
int SignCorrection() const
Indicates whether or not to correct Stress/Strain sign.
void Read(TPZStream &buf, void *context) override
read objects from the stream
void ApplyStrainComputeDep_Internal(const TPZTensor< REAL > &epsTotal, TPZTensor< REAL > &sigma, TPZFMatrix< REAL > &Dep)
Imposes the specified strain tensor and returns the corresp. stress state and tangent stiffness matri...
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
virtual void ApplyStrain(const TPZTensor< REAL > &epsTotal) override
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
void InitialGuess(const TPZPlasticState< REAL > &N, TPZPlasticState< REAL > &Np1, TPZVec< REAL > &delGamma, TPZVec< int > &validEqs)
Proposes an update to the plastic variables and estimates the relative error comitted in this update...
EStatus
Definition: pzdiffmatrix.h:17
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
TPZPlasticIntegrMem< REAL, 4 > teste
Definition: tfad.h:64
Definition: pzmatrix.h:52
int PlasticLoop(const TPZPlasticState< REAL > &N, TPZPlasticState< REAL > &Np1, TPZVec< REAL > &delGamma, REAL &normEpsPErr, REAL &lambda, TPZVec< int > &validEqs)
Proposes an update to the plastic variables and estimates the relative error comitted in this update...
virtual void Phi(const TPZTensor< REAL > &epsTotal, TPZVec< REAL > &phi) const override
Return the value of the yield functions for the given strain.
REAL FindPointAtYield(const TPZTensor< REAL > &epsTotalNp1, TPZPlasticState< REAL > &stateAtYield) const
Finds the strain point in the linear path from epsTotalN and towards epsTotalNp1 that matches the yie...
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
void PlasticResidualRK(const TPZPlasticState< T1 > &N_T1, TPZPlasticState< T2 > &Np1_T2, const TPZVec< T2 > &delGamma_T2, TPZVec< T2 > &res_T2, REAL &normEpsPErr, int silent=0) const
Evaluates the residual vector for the plasticity problem RK.
REAL UpdatePlasticVars(const TPZPlasticState< T1 > &N_T1, TPZPlasticState< T2 > &Np1_T2, TPZVec< T2 > &delGamma_T2, TPZVec< T2 > &res_T2, TVECTOR &Sol_TVECTOR, TPZVec< int > &validEqs, int updateVars=1) const
Updates the N+1 plastic state variables based on the solution of a Newton&#39;s scheme. A very simple line search is performed in order to attempt to guarantee residual drop.
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
void SetTensionSign(int s)
string res
Definition: test.py:151
virtual TPZPlasticState< REAL > GetState() const override
Retrieve the plastic state variables.
virtual void ProcessStrain(const TPZTensor< REAL > &epsTotal, const EElastoPlastic ep=EAuto)
Imposes the specified strain tensor and performs plastic integration when necessary. This function creates a new plastic integration history epserimenting the proposed epsTotal. It does not update the current plastic state.
void PushPlasticMem(const TPZPlasticState< REAL > &state, const REAL &k, const REAL &lambda, const TPZManVector< REAL, N > &delGamma, const TPZVec< int > &validEqs, const int forceYield)
Stores the whole content of a plastic integration step in order to allow its further reevaluation...
expr_ expr_ fastAccessDx(i) *cos(expr_.val())) FAD_FUNC_MACRO(TFadFuncTan
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
Definition: pzlog.h:93
static REAL val(const int number)
Definition: pzextractval.h:21
TPZTensor< T > m_eps_p
void PlasticResidual(const TPZPlasticState< T1 > &N_T1, TPZPlasticState< T2 > &Np1_T2, const TPZVec< T2 > &delGamma_T2, TPZVec< T2 > &res_T2, REAL &normEpsPErr, int silent=0) const
void Solve(const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual=0) override
Solves the system of linear equations.
void Print(std::ostream &out) const
Definition: TPZTensor.h:1847
virtual void ApplyLoad(const TPZTensor< REAL > &sigma, TPZTensor< REAL > &epsTotal) override
EElastoPlastic
virtual void SetElasticResponse(TPZElasticResponse &ER) override
modify the elastic response. Needs to be reimplemented for each instantiation
virtual TPZElasticResponse GetElasticResponse() const override
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
Definition: pzreal.h:487
virtual void ApplyStrainComputeDep(const TPZTensor< REAL > &epsTotal, TPZTensor< REAL > &sigma, TPZFMatrix< REAL > &Dep) override
const T & VolHardening() const
const TPZTensor< T > & EpsT() const
Matrix class to hold the flux derivatives A B C and diffusive matrix coefficients. Matrix.
Definition: pzdiffmatrix.h:27
void ComputePlasticVars(const TPZPlasticState< T > &state_T, TPZTensor< T > &sigma_T, T &A_T) const
Evaluates the sigma stress tensor and the thermoForceA for use in several pieces of this code...
const TPZTensor< T > & EpsP() const
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
Contains TPZStepSolver class which defines step solvers class.
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
virtual void ApplyStrainComputeSigma(const TPZTensor< REAL > &epsTotal, TPZTensor< REAL > &sigma, TPZFMatrix< REAL > *tangent=NULL) override
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
void SetDirect(const DecomposeType decomp)
virtual TPZPlasticState< REAL > GetState_Internal() const
Retrieves the plastic state variables - makes no interface sign checks.
Extra utilities for TPZVec. Implementations of the saxpy, sscal, sdot, intercept, max and min functio...
virtual void ComputeDep(TPZTensor< REAL > &sigma, TPZFMatrix< REAL > &Dep)
Evaluates the constitutive matrix (DSigma/DEpsT) based on the data from the plastic integration histo...
virtual void SetState(const TPZPlasticState< REAL > &state) override
Update the damage values.
int PlasticIntegrate(const TPZPlasticState< REAL > &N, TPZPlasticState< REAL > &Np1, const REAL &TolEpsPErr)
Proposes an update to the plastic variables respecting an integration with error control. Neither internal variable are used nor changed. In the Np1 variables, EpsT is imposed [input] and the Alpha and EpsP are evaluated.
virtual void SetState_Internal(const TPZPlasticState< REAL > &state)
Updates the damage values - makes no interface sign checks.
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
virtual void ProcessLoad(const TPZTensor< REAL > &sigma, const EElastoPlastic ep=EAuto)
Imposes the specified stress tensor and performs plastic integration when necessary. This function evaluates a newton&#39;s method on ProcessStrain until the stress state matches. It does not update the current plastic state.
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
virtual int IntegrationSteps() const override
Return the number of plastic steps in the last load step. Zero indicates elastic loading.