NeoPZ
TPZAnalyticSolution.cpp
Go to the documentation of this file.
1 
2 #include "TPZAnalyticSolution.h"
3 
4 #include "pzgmesh.h"
5 //#include "TPZGenGrid2D.h"
6 #include "pzgeoel.h"
7 #include "TPZRefPatternTools.h"
8 #include "pzcheckgeom.h"
9 #include "TPZVTKGeoMesh.h"
10 
11 #include "pzanalysis.h"
12 #include "pzstepsolver.h"
13 
14 #include "TPZMaterial.h"
16 
17 #include "TPZSSpStructMatrix.h"
18 
19 #ifndef USING_MKL
20 #include "pzskylstrmatrix.h"
21 #endif
22 
23 
24 #include "pzlog.h"
25 
26 #ifdef _AUTODIFF
27 #include "fadType.h"
28 
29 
30 #ifndef STATE_COMPLEX
32 {
33  int sz = x.size();
34  STATE xval,yval;
35  xval = x.val();
36  yval = y.val();
37  STATE angle = atan2(yval,xval);
38  Fad<STATE> result(sz,angle);
39  STATE r = x.val()*x.val()+y.val()*y.val();
40  for (int i=0; i<sz; i++) {
41  result.fastAccessDx(i) = (-y.val()*x.fastAccessDx(i) + x.val()*y.fastAccessDx(i))/r;
42  }
43  return result;
44 }
45 #else
47 {
48  int sz = x.size();
49  double xval,yval,xvalimag,yvalimag;
50  xval = x.val().real();
51  yval = y.val().real();
52  xvalimag = x.val().imag();
53  yvalimag = y.val().imag();
54  if(abs(xvalimag) > 1.e-12 || abs(yvalimag)> 1.e-12)
55  {
56  DebugStop();
57  }
58  REAL angle = atan2(yval,xval);
59  Fad<STATE> result(sz,angle);
60  double r = xval*xval+yval*yval;
61  for (int i=0; i<sz; i++) {
62  result.fastAccessDx(i) = (-y.val()*x.fastAccessDx(i) + x.val()*y.fastAccessDx(i))/r;
63  }
64  return result;
65 }
66 #endif
67 
68 static FADFADSTATE FADatan2(FADFADSTATE y, FADFADSTATE x)
69 {
70  int sz = x.size();
71  FADFADSTATE result(sz,atan2(y.val(),x.val()));
72  Fad<STATE> r = x.val()*x.val()+y.val()*y.val();
73  for (int i=0; i<sz; i++) {
74  result.fastAccessDx(i) = (-y.val()*x.fastAccessDx(i) + x.val()*y.fastAccessDx(i))/r;
75  }
76  return result;
77 }
78 
79 static FADFADSTATE FADsin(FADFADSTATE x)
80 {
81 
82  Fad<STATE> sinaval = sin(x.val());
83  Fad<STATE> cosaval = cos(x.val());
84  int sz = x.size();
85  FADFADSTATE sina(sz,sinaval);
86  for (int i=0; i<sz; i++) {
87  sina.fastAccessDx(i) = cosaval*x.dx(i);
88  }
89  return sina;
90 }
91 
92 static FADFADSTATE FADcos(FADFADSTATE x)
93 {
94  Fad<STATE> sinaval = sin(x.val());
95  Fad<STATE> cosaval = cos(x.val());
96  int sz = x.size();
97  FADFADSTATE cosa(sz,cosaval);
98  for (int i=0; i<sz; i++) {
99  cosa.fastAccessDx(i) = -sinaval*x.dx(i);
100  }
101  return cosa;
102 }
103 
104 static FADFADSTATE FADexp(FADFADSTATE x)
105 {
106  Fad<STATE> expaval = exp(x.val());
107  int sz = x.size();
108  FADFADSTATE expa(sz,expaval);
109  for (int i=0; i<sz; i++) {
110  expa.fastAccessDx(i) = expaval*x.dx(i);
111  }
112  return expa;
113 }
114 
115 static FADFADSTATE FADsqrt(FADFADSTATE x)
116 {
117  Fad<STATE> fadres = sqrt(x.val());
118  int sz = x.size();
119  FADFADSTATE resa(sz,fadres);
120  for (int i=0; i<sz; i++) {
121  resa.fastAccessDx(i) = REAL(0.5)/fadres*x.dx(i);
122  }
123  return resa;
124 }
125 
126 static FADFADSTATE FADatan(FADFADSTATE x)
127 {
128  Fad<STATE> fadres = atan(x.val());
129  int sz = x.size();
130  FADFADSTATE resa(sz,fadres);
131  for (int i=0; i<sz; i++) {
132  resa.fastAccessDx(i) = 1./(1.+x.val()*x.val())*x.dx(i);
133  }
134  return resa;
135 }
136 
137 static FADFADSTATE FADcosh(FADFADSTATE x)
138 {
139  Fad<STATE> coshval = cosh(x.val());
140  Fad<STATE> sinhval = sinh(x.val());
141  int sz = x.size();
142  FADFADSTATE resa(sz,coshval);
143  for (int i=0; i<sz; i++) {
144  resa.fastAccessDx(i) = sinhval*x.dx(i);
145  }
146  return resa;
147 }
148 
149 static FADFADSTATE FADsinh(FADFADSTATE x)
150 {
151  Fad<STATE> coshval = cosh(x.val());
152  Fad<STATE> sinhval = sinh(x.val());
153  int sz = x.size();
154  FADFADSTATE resa(sz,sinhval);
155  for (int i=0; i<sz; i++) {
156  resa.fastAccessDx(i) = coshval*x.dx(i);
157  }
158  return resa;
159 }
160 
161 static const REAL FI = 1.;
162 static const REAL a = 0.5;
163 static const REAL b = 0.5;
164 
165 TPZAnalyticSolution::TPZAnalyticSolution(const TPZAnalyticSolution &cp) :fSignConvention(cp.fSignConvention) {
166  std::cout << "TPZAnalyticSolution::TPZAnalyticSolution(const TPZAnalyticSolution &cp): One should not invoke this copy constructor";
167  DebugStop();
168 }
169 
171  std::cout << "TPZAnalyticSolution & TPZAnalyticSolution::operator=(const TPZAnalyticSolution &copy): One should not invoke this copy constructor";
172  DebugStop();
173  fSignConvention = copy.fSignConvention;
174  return *this;
175 }
176 
177 REAL TElasticity2DAnalytic::gE = 1.;
178 
179 REAL TElasticity2DAnalytic::gPoisson = 0.3;
180 
181 int TElasticity2DAnalytic::gOscilatoryElasticity = 0;
182 
183 TElasticity2DAnalytic::TElasticity2DAnalytic(const TElasticity2DAnalytic &cp) : TPZAnalyticSolution(cp),fProblemType(cp.fProblemType) {
184  std::cout << "TElasticity2DAnalytic::TElasticity2DAnalytic(const TElasticity2DAnalytic &cp): One should not invoke this copy constructor";
185  DebugStop();
186 }
187 
188 TElasticity2DAnalytic & TElasticity2DAnalytic::operator=(const TElasticity2DAnalytic &copy){
189  fProblemType = copy.fProblemType;
190  gE = copy.gE;
191  gPoisson = copy.gPoisson;
192  return *this;
193 }
194 
195 template<>
196 void TElasticity2DAnalytic::uxy(const TPZVec<FADFADSTATE > &x, TPZVec<FADFADSTATE > &disp) const
197 {
198  typedef FADFADSTATE TVar;
199  if(fProblemType == Etest1)
200  {
201  FADFADSTATE tmp = (FADFADSTATE)(1./27.)*x[0]*x[0]*x[1]*x[1];
202  disp[0] = tmp*FADcos((FADFADSTATE)(6.*M_PI)*x[0])*FADsin((FADFADSTATE)(7.*M_PI)*x[1]);
203  disp[1] = (FADFADSTATE)(0.2)*FADexp(x[1])*FADsin((FADFADSTATE)(4.*M_PI)*x[0]);
204 
205  }
206  else if(fProblemType == Etest2)
207  {
208  disp[0] = x[0]*0.;
209  disp[1] = x[0]*0.;
210  disp[0] = ((1.-x[0]*x[0])*(1.+x[1]*x[1]*x[1]*x[1]));
211  disp[1] = ((1.-x[1]*x[1])*(1.+x[0]*x[0]*x[0]*x[0]));
212  }
213 
214  else if(fProblemType ==ERot)//rotation
215  {
216  disp[0] = x[0]*0.;
217  disp[1] = x[0]*0.;
218  disp[0] =(FADFADSTATE)-x[1];
219  disp[1] =(FADFADSTATE) x[0];
220 
221  }
222 
223  else if(fProblemType == EShear)//pure shear
224  {
225  disp[0] = x[0]*0.;
226  disp[1] = x[0]*0.;
227  disp[0] += (FADFADSTATE) x[1];
228  disp[1] += (FADFADSTATE) 0. ;
229  }
230  else if(fProblemType == EStretchx)//strech x
231  {
232  disp[0] = x[0]*0.;
233  disp[1] = x[0]*0.;
234  disp[0] += (FADFADSTATE) x[0];
235  disp[1] += (FADFADSTATE) 0.;
236  }
237  else if(fProblemType == EUniAxialx)
238  {
239  if (fPlaneStress == 0) {
240  disp[0] = x[0]*(1.-gPoisson*gPoisson)/gE;
241  disp[1] = -x[1]*(1.+gPoisson)*gPoisson/gE;
242  }
243  else
244  {
245  disp[0] = x[0]/gE;
246  disp[1] = -x[1]*gPoisson/gE;
247  }
248  }
249  else if(fProblemType ==EStretchy)//strech y
250  {
251  disp[0] = x[0]*0.;
252  disp[1] = x[0]*0.;
253  disp[0] += (FADFADSTATE) 0.;
254  disp[1] += (FADFADSTATE) x[1];
255  }
256  else if(fProblemType==EDispx)
257  {
258  disp[0] = x[0]*0.;
259  disp[1] = x[0]*0.;
260  disp[0] += 1.;
261  disp[0] += 0.;
262  }
263  else if(fProblemType==EDispy)
264  {
265  disp[0] = x[0]*0.;
266  disp[1] = x[0]*0.;
267  disp[0] += (FADFADSTATE) 0.;
268  disp[0] += (FADFADSTATE) 1.;
269  }
270  else if (fProblemType == EThiago){
271  disp[0] = FADcos(M_PI * x[0]) * FADsin(2 * M_PI * x[1]);
272  disp[1] = FADcos(M_PI * x[1]) * FADsin(M_PI * x[0]);
273  } else if(fProblemType == EPoly){
274  disp[0] = 0. * x[0]; //*x[0]*x[1];
275  disp[1] = x[1] * x[0]; //(x[1]-1.)*(x[1]-x[0])*(x[0]+4.*x[1]);
276  } else if(fProblemType==EBend)
277  {
278  typedef TVar FADFADSTATE;
279  TVar poiss = gPoisson;
280  TVar elast = gE;
281  if(fPlaneStress == 0)
282  {
283  poiss = poiss/(1.-poiss);
284  elast /= (1-gPoisson*gPoisson);
285  }
286  disp[0] = 5.*x[0]*x[1]/elast;
287  disp[1] = (-poiss*5.*x[1]*x[1]/2.-5.*x[0]*x[0]/2.)/elast;
288 
289  }
290  else if(fProblemType == ELoadedBeam)
291  {
292  TVar Est,nust,G;
293  REAL MI = 5, h = 1.;
294  G = gE/(2.*(1.+gPoisson));
295  if (fPlaneStress == 0) {
296  Est = gE/((1.-gPoisson*gPoisson));
297  nust = gPoisson/(1-gPoisson);
298 // Est = (1.+2.*gPoisson)/((1+gPoisson)*(1.+gPoisson))*fE;
299 // nust = gPoisson/(1.+gPoisson);
300  }
301  else
302  {
303  Est = gE;
304  nust = gPoisson;
305  }
306  disp[0] = MI*h*h*x[1]/(2.*G)+ MI*x[0]*x[0]*x[1]/(2.*Est)-MI *x[1]*x[1]*x[1]/(6.*G)+MI*nust*x[1]*x[1]*x[1]/(6.*Est);
307  disp[1] = -MI*x[0]*x[0]*x[0]/(6.*Est)-MI*nust*x[0]*x[1]*x[1]/(2.*Est);
308  }
309  else if(fProblemType == ESquareRoot)
310  {
311  TVar Est,nust,G, kappa;
312  TVar theta = FADatan2(x[1],x[0]);
313  TVar r = FADsqrt(x[0]*x[0]+x[1]*x[1]);
314  G = gE/(2.*(1.+gPoisson));
315  if (fPlaneStress == 0) {
316  // Est = (1.+2.*gPoisson)/((1+gPoisson)*(1.+gPoisson))*fE;
317  // nust = gPoisson/(1.+gPoisson);
318  Est = gE/((1.-gPoisson*gPoisson));
319  nust = gPoisson/(1.-gPoisson);
320  kappa = 3.-4.*gPoisson;
321  }
322  else
323  {
324  Est = gE;
325  nust = gPoisson;
326  kappa = (3.-gPoisson)/(1.+gPoisson);
327  }
328  TVar costh = FADcos(theta/2.);
329  TVar sinth = FADsin(theta/2.);
330  disp[0] = 1./(2.*G)*FADsqrt(r/(2.*M_PI))*costh*(kappa-1.+2.*sinth*sinth);
331  disp[1] = 1./(2.*G)*FADsqrt(r/(2.*M_PI))*sinth*(kappa+1.-2.*costh*costh);
332  }
333  else if(fProblemType == ESquareRootLower)
334  {
335  TVar Est,nust,G, kappa;
336  TVar theta = FADatan2(x[1],x[0]);
337  if (shapeFAD::val(theta) > 0.) {
338  theta -= (2.*M_PI);
339  }
340  TVar r = FADsqrt(x[0]*x[0]+x[1]*x[1]);
341  G = gE/(2.*(1.+gPoisson));
342  if (fPlaneStress == 0) {
343  // Est = (1.+2.*gPoisson)/((1+gPoisson)*(1.+gPoisson))*fE;
344  // nust = gPoisson/(1.+gPoisson);
345  Est = gE/((1.-gPoisson*gPoisson));
346  nust = gPoisson/(1.-gPoisson);
347  kappa = 3.-4.*gPoisson;
348  }
349  else
350  {
351  Est = gE;
352  nust = gPoisson;
353  kappa = (3.-gPoisson)/(1.+gPoisson);
354  }
355  TVar costh = FADcos(theta/2.);
356  TVar sinth = FADsin(theta/2.);
357  disp[0] = 1./(2.*G)*FADsqrt(r/(2.*M_PI))*costh*(kappa-1.+2.*sinth*sinth);
358  disp[1] = 1./(2.*G)*FADsqrt(r/(2.*M_PI))*sinth*(kappa+1.-2.*costh*costh);
359  }
360  else if(fProblemType == ESquareRootUpper)
361  {
362  TVar Est,nust,G, kappa;
363  TVar theta = FADatan2(x[1],x[0]);
364  if (shapeFAD::val(theta) < 0.) {
365  theta += (2.*M_PI);
366  }
367  TVar r = FADsqrt(x[0]*x[0]+x[1]*x[1]);
368  G = gE/(2.*(1.+gPoisson));
369  if (fPlaneStress == 0) {
370  // Est = (1.+2.*gPoisson)/((1+gPoisson)*(1.+gPoisson))*fE;
371  // nust = gPoisson/(1.+gPoisson);
372  Est = gE/((1.-gPoisson*gPoisson));
373  nust = gPoisson/(1.-gPoisson);
374  kappa = 3.-4.*gPoisson;
375  }
376  else
377  {
378  Est = gE;
379  nust = gPoisson;
380  kappa = (3.-gPoisson)/(1.+gPoisson);
381  }
382  TVar costh = FADcos(theta/2.);
383  TVar sinth = FADsin(theta/2.);
384  disp[0] = 1./(2.*G)*FADsqrt(r/(2.*M_PI))*costh*(kappa-1.+2.*sinth*sinth);
385  disp[1] = 1./(2.*G)*FADsqrt(r/(2.*M_PI))*sinth*(kappa+1.-2.*costh*costh);
386  }
387  else
388  {
389  DebugStop();
390  }
391 }
392 
393 template<typename TVar1, typename TVar2>
394 void TElasticity2DAnalytic::uxy(const TPZVec<TVar1> &x, TPZVec<TVar2> &disp) const {
395 
396  if (fProblemType == Etest1) {
397  disp[0] = TVar2(1. / 27.) * x[0] * x[0] * x[1] * x[1] * cos(TVar2(6. * M_PI) * x[0]) * sin(TVar2(7. * M_PI) * x[1]);
398  disp[1] = TVar2(0.2) * exp(x[1]) * sin(TVar2(4. * M_PI) * x[0]);
399  } else if (fProblemType == Etest2) {
400  disp[0] = x[0]*0.;
401  disp[1] = x[0]*0.;
402  disp[0] = ((TVar2(1) - x[0] * x[0])*(1. + x[1] * x[1] * x[1] * x[1]));
403  disp[1] = ((TVar2(1) - x[1] * x[1])*(1. + x[0] * x[0] * x[0] * x[0]));
404  }
405  else if (fProblemType == ERot)//rotation
406  {
407  disp[0] = (TVar2) - x[1];
408  disp[1] = (TVar2) x[0];
409  }
410  else if (fProblemType == EShear)//pure shear
411  {
412  disp[0] = x[0]*0.;
413  disp[1] = x[0]*0.;
414  disp[0] += (TVar2) x[1];
415  disp[1] += (TVar2) 0.;
416  } else if (fProblemType == EStretchx)//strech x
417  {
418  disp[0] = x[0]*0.;
419  disp[1] = x[0]*0.;
420  disp[0] += (TVar2) x[0];
421  disp[1] += (TVar2) 0.;
422  } else if (fProblemType == EUniAxialx) {
423  if (fPlaneStress == 0) {
424  disp[0] = x[0]*(1. - gPoisson * gPoisson) / gE;
425  disp[1] = -x[1]*(1. + gPoisson) * gPoisson / gE;
426  } else {
427  disp[0] = x[0] / gE;
428  disp[1] = -x[1] * gPoisson / gE;
429  }
430  } else if (fProblemType == EStretchy)//strech y
431  {
432  disp[0] = x[0]*0.;
433  disp[1] = x[0]*0.;
434  disp[0] += (TVar2) 0.;
435  disp[1] += (TVar2) x[1];
436  } else if (fProblemType == EDispx) {
437  disp[0] = x[0]*0.;
438  disp[1] = x[0]*0.;
439  disp[0] += 1.;
440  disp[0] += 0.;
441  } else if (fProblemType == EDispy) {
442  disp[0] = x[0]*0.;
443  disp[1] = x[0]*0.;
444  disp[0] += (TVar2) 0.;
445  disp[0] += (TVar2) 1.;
446  } else if (fProblemType == EThiago){
447  disp[0] = x[0]*0.;
448  disp[1] = x[0]*0.;
449  //disp[0] = ((1-x[0]*x[0])*(1+x[1]*x[1]*x[1]*x[1]));
450  //disp[1] = ((1-x[1]*x[1])*(1+x[0]*x[0]*x[0]*x[0]));
451  disp[0] = (TVar2) cos(M_PI * x[0])*(TVar2) sin(2 * M_PI * x[1]);
452  disp[1] = (TVar2) cos(M_PI * x[1])*(TVar2) sin(M_PI * x[0]);
453  } else if(fProblemType == EPoly){
454  disp[0] = 0. * x[0]; //*x[0]*x[1];
455  disp[1] = x[1] * x[0]; //(x[1]-1.)*(x[1]-x[0])*(x[0]+4.*x[1]);
456  } else if (fProblemType == EBend) {
457  TVar2 poiss = gPoisson;
458  TVar2 elast = gE;
459  if (fPlaneStress == 0) {
460  poiss = poiss / (1. - poiss);
461  elast /= (1 - gPoisson * gPoisson);
462  }
463  disp[0] = 5. * x[0] * x[1] / elast;
464  disp[1] = (-poiss * 5. * x[1] * x[1] / 2. - 5. * x[0] * x[0] / 2.) / elast;
465  } else if (fProblemType == ELoadedBeam) {
466  TVar2 Est, nust, G;
467  REAL MI = 5, h = 1.;
468  G = gE / (2. * (1. + gPoisson));
469  if (fPlaneStress == 0) {
470  // Est = (1.+2.*gPoisson)/((1+gPoisson)*(1.+gPoisson))*gE;
471  // nust = gPoisson/(1.+gPoisson);
472  Est = gE / ((1. - gPoisson * gPoisson));
473  nust = gPoisson / (1 - gPoisson);
474  } else {
475  Est = gE;
476  nust = gPoisson;
477  }
478  disp[0] = MI * h * h * x[1] / (2. * G) + MI * x[0] * x[0] * x[1] / (2. * Est) - MI * x[1] * x[1] * x[1] / (6. * G) + MI * nust * x[1] * x[1] * x[1] / (6. * Est);
479  disp[1] = -MI * x[0] * x[0] * x[0] / (6. * Est) - MI * nust * x[0] * x[1] * x[1] / (2. * Est);
480  } else if (fProblemType == ESquareRoot) {
481 #ifdef STATE_COMPLEX
482  DebugStop();
483 #else
484  TVar2 Est, nust, G, kappa;
485  TVar2 theta = atan2(x[1], x[0]);
486  TVar2 r = sqrt(x[0] * x[0] + x[1] * x[1]);
487  G = gE / (2. * (1. + gPoisson));
488  if (fPlaneStress == 0) {
489  // Est = (1.+2.*gPoisson)/((1+gPoisson)*(1.+gPoisson))*gE;
490  // nust = gPoisson/(1.+gPoisson);
491  Est = gE / ((1. - gPoisson * gPoisson));
492  nust = gPoisson / (1 - gPoisson);
493  kappa = 3. - 4. * gPoisson;
494  } else {
495  Est = gE;
496  nust = gPoisson;
497  kappa = (3. - gPoisson) / (1 + gPoisson);
498  }
499  TVar2 costh = cos(theta / 2.);
500  TVar2 sinth = sin(theta / 2.);
501  disp[0] = 1 / (2. * G) * sqrt(r / (2. * M_PI)) * costh * (kappa - 1. + 2. * sinth * sinth);
502  disp[1] = 1 / (2. * G) * sqrt(r / (2. * M_PI)) * sinth * (kappa + 1. - 2. * costh * costh);
503  // std::cout << "SQ x " << x << " theta " << theta << " disp " << disp << std::endl;
504 #endif
505  } else if (fProblemType == ESquareRootLower) {
506 #ifdef STATE_COMPLEX
507  DebugStop();
508 #else
509  TVar2 Est, nust, G, kappa;
510  TVar2 theta = atan2(x[1], x[0]);
511  if (shapeFAD::val(theta) > 0.) {
512  theta -= (2. * M_PI);
513  }
514  TVar2 r = sqrt(x[0] * x[0] + x[1] * x[1]);
515  G = gE / (2. * (1. + gPoisson));
516  if (fPlaneStress == 0) {
517  // Est = (1.+2.*gPoisson)/((1+gPoisson)*(1.+gPoisson))*gE;
518  // nust = gPoisson/(1.+gPoisson);
519  Est = gE / ((1. - gPoisson * gPoisson));
520  nust = gPoisson / (1 - gPoisson);
521  kappa = 3. - 4. * gPoisson;
522  } else {
523  Est = gE;
524  nust = gPoisson;
525  kappa = (3. - gPoisson) / (1 + gPoisson);
526  }
527  TVar2 costh = cos(theta / 2.);
528  TVar2 sinth = sin(theta / 2.);
529  disp[0] = 1 / (2. * G) * sqrt(r / (2. * M_PI)) * costh * (kappa - 1. + 2. * sinth * sinth);
530  disp[1] = 1 / (2. * G) * sqrt(r / (2. * M_PI)) * sinth * (kappa + 1. - 2. * costh * costh);
531  // std::cout << "SQL x " << x << " theta " << theta << " disp " << disp << std::endl;
532 #endif
533  } else if (fProblemType == ESquareRootUpper) {
534 #ifdef STATE_COMPLEX
535  DebugStop();
536 #else
537  TVar2 Est, nust, G, kappa;
538  TVar2 theta = atan2(x[1], x[0]);
539  if (shapeFAD::val(theta) < 0.) {
540  theta += (2. * M_PI);
541  }
542  TVar2 r = sqrt(x[0] * x[0] + x[1] * x[1]);
543  G = gE / (2. * (1. + gPoisson));
544  if (fPlaneStress == 0) {
545  // Est = (1.+2.*gPoisson)/((1+gPoisson)*(1.+gPoisson))*gE;
546  // nust = gPoisson/(1.+gPoisson);
547  Est = gE / ((1. - gPoisson * gPoisson));
548  nust = gPoisson / (1 - gPoisson);
549  kappa = 3. - 4. * gPoisson;
550  } else {
551  Est = gE;
552  nust = gPoisson;
553  kappa = (3. - gPoisson) / (1 + gPoisson);
554  }
555  TVar2 costh = cos(theta / 2.);
556  TVar2 sinth = sin(theta / 2.);
557  disp[0] = 1 / (2. * G) * sqrt(r / (2. * M_PI)) * costh * (kappa - 1. + 2. * sinth * sinth);
558  disp[1] = 1 / (2. * G) * sqrt(r / (2. * M_PI)) * sinth * (kappa + 1. - 2. * costh * costh);
559  // std::cout << "SQU x " << x << " theta " << theta << " disp " << disp << std::endl;
560 #endif
561  } else {
562  DebugStop();
563  }
564 }
565 
566 template
567 void TElasticity2DAnalytic::uxy<REAL,REAL>(const TPZVec<REAL> &x, TPZVec<REAL> &disp) const;
568 
569 #if (REAL != STATE)
570 
571 template
572 void TElasticity2DAnalytic::uxy<REAL,STATE>(const TPZVec<REAL> &x, TPZVec<STATE> &disp) const;
573 
574 template
575 void TElasticity2DAnalytic::uxy<STATE,STATE>(const TPZVec<STATE> &x, TPZVec<STATE> &disp) const;
576 
577 #endif
578 
579 template<class TVar>
580 void TElasticity2DAnalytic::Elastic(const TPZVec<TVar> &x, TVar &Elast, TVar &nu)
581 {
582  if(gOscilatoryElasticity != 0)
583  {
584  Elast = (TVar(100.) * (TVar(1.) + TVar(0.3) * sin(TVar(10 * M_PI) * (x[0] - TVar(0.5))) * cos(TVar(10. * M_PI) * x[1])));
585  }
586  else
587  {
588  Elast = gE;
589  }
590  nu = TVar(gPoisson);
591 }
592 
593 //template<>
594 //void TElasticity2DAnalytic::Elastic(const TPZVec<double> &x, double &Elast, double &nu)
595 //{
596 // Elast = 1000.;
597 // Elast = (100. * (1. + 0.3 * sin(10 * M_PI * (x[0] - 0.5)) * cos(10. * M_PI * x[1])));
598 // Elast = 1.;
599 // nu = 0.;
600 //}
601 
602 void TElasticity2DAnalytic::ElasticDummy(const TPZVec<REAL> &x, TPZVec<STATE> &result, TPZFMatrix<STATE> &deriv)
603 {
604  //TPZManVector<STATE> xstate(x.size());
605  TPZManVector<STATE> xstate(x.size());
606  for (int i=0; i<xstate.size(); i++) {
607  xstate[i] = x[i];
608  }
609 
610  STATE E = 1,nu = 0.3;
611  Elastic(xstate,E,nu);
612  result[0] = E;
613  result[1] = nu;
614 }
615 
616 
617 template<>
618 void TElasticity2DAnalytic::graduxy(const TPZVec<Fad<STATE> > &x, TPZFMatrix<Fad<STATE> > &grad) const
619 {
620  TPZManVector<Fad<Fad<STATE> >,3> xfad(x.size());
621  for(int i=0; i<3; i++)
622  {
623  Fad<Fad<STATE> > temp = Fad<Fad<STATE> >(3,Fad<STATE>(3,0.));
624 // Fad<STATE> temp = Fad<STATE>(2,i,x[i]);
625  temp.val()= x[i];
626  Fad<STATE> temp3(3,0.);
627  for(int j=0; j<3; j++)
628  {
629  temp.fastAccessDx(j) = temp3;
630  }
631  Fad<STATE> temp2(3,1.);
632  temp.fastAccessDx(i) = temp2;
633 // Fad<STATE> temp = Fad<STATE>(2,i,x[i]);
634  xfad[i] = temp;
635 // xfad[i] = temp;
636  }
637  TPZManVector<Fad<Fad<STATE> >,3> result(2);
638  uxy(xfad,result);
639  grad.Resize(2,2);
640  for (int i=0; i<2; i++) {
641  for (int j=0; j<2; j++)
642  {
643  grad(j,i) = result[i].d(j);
644  }
645  }
646 }
647 
648 template
649 void TElasticity2DAnalytic::graduxy<REAL,REAL>(const TPZVec<REAL> &x, TPZFMatrix<REAL> &grad) const;
650 
651 #if (REAL != STATE)
652 
653 template
654 void TElasticity2DAnalytic::graduxy<REAL,STATE>(const TPZVec<REAL> &x, TPZFMatrix<STATE> &grad) const;
655 
656 template
657 void TElasticity2DAnalytic::graduxy<STATE,STATE>(const TPZVec<STATE> &x, TPZFMatrix<STATE> &grad) const;
658 
659 #endif
660 
661 void TElasticity2DAnalytic::Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const {
662  TPZManVector<STATE> xst(3);
663  for(int i=0; i<3; i++) xst[i] = x[i];
664  uxy(xst,u);
665  graduxy(xst,gradu);
666 }
667 
668 void TElasticity2DAnalytic::GradU(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const
669 {
670  TPZManVector<Fad<STATE>,3> xfad(x.size());
671  for(int i=0; i<2; i++)
672  {
673  Fad<STATE> temp = Fad<STATE>(2,i,x[i]);
674  xfad[i] = temp;
675  }
676  xfad[2] = x[2];
677  TPZManVector<Fad<STATE>,3> result(2);
678  uxy(xfad,result);
679  gradu.Redim(2,2);
680  u[0] = result[0].val();
681  u[1] = result[1].val();
682  for (int i=0; i<2; i++) {
683  for (int j=0; j<2; j++)
684  {
685  gradu(i,j) = result[j].d(i);
686  }
687  }
688 
689 }
690 
691 void TElasticity2DAnalytic::Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &sigma) const
692 {
694  REAL E, nu;
695  sigma.Resize(2,2);
696  Elastic(x, E, nu);
697  graduxy(x,grad);
698  //uxy(x,u);
699  if (fPlaneStress == 0)
700  {
701  STATE Fac = E/((STATE)1.+nu)/((STATE(1.)-STATE(2.)*nu));
702  sigma(0,0) = Fac*((STATE(1.)-nu)*grad(0,0)+nu*grad(1,1));
703  sigma(1,1) = Fac*((STATE(1.)-nu)*grad(1,1)+nu*grad(0,0));
704  sigma(0,1) = E/(STATE(2.)*(STATE(1.)+nu))*(grad(0,1)+grad(1,0));
705  sigma(1,0) = sigma(0,1);
706  }
707  else
708  {
709  STATE Fac = E/((STATE)1.-nu*nu);
710  sigma(0,0) = Fac*(grad(0,0)+nu*grad(1,1));
711  sigma(1,1) = Fac*(grad(1,1)+nu*grad(0,0));
712  sigma(0,1) = E/(STATE(2.)*(STATE(1.)+nu))*(grad(0,1)+grad(1,0));
713  sigma(1,0) = sigma(0,1);
714  }
715 }
716 
717 void TElasticity2DAnalytic::Sigma(const TPZVec<Fad<STATE> > &x, TPZFMatrix<Fad<STATE> > &sigma) const {
719  sigma.Resize(2,2);
720  Fad<STATE> E, nu;
721  Elastic(x, E, nu);
722  graduxy(x,grad);
723  if (fPlaneStress == 0)
724  {
725  Fad<STATE> Fac = E/(Fad<STATE>(1.)+nu)/((Fad<STATE>(1.)-Fad<STATE>(2.)*nu));
726  sigma(0,0) = Fac*((Fad<STATE>(1.)-nu)*grad(0,0)+nu*grad(1,1));
727  sigma(1,1) = Fac*((Fad<STATE>(1.)-nu)*grad(1,1)+nu*grad(0,0));
728  sigma(0,1) = E/(Fad<STATE>(2.)*(Fad<STATE>(1.)+nu))*(grad(0,1)+grad(1,0));
729  sigma(1,0) = sigma(0,1);
730  }
731  else
732  {
733  typedef Fad<STATE> TVar;
734  TVar Fac = E/((TVar)1.-nu*nu);
735  sigma(0,0) = Fac*(grad(0,0)+nu*grad(1,1));
736  sigma(1,1) = Fac*(grad(1,1)+nu*grad(0,0));
737  sigma(0,1) = E/(TVar(2.)*(TVar(1.)+nu))*(grad(0,1)+grad(1,0));
738  sigma(1,0) = sigma(0,1);
739 
740  }
741 }
742 
743 template<class TVar>
744 //void TElasticity2DAnalytic::DivSigma(const TPZVec<TVar> &x, TPZVec<TVar> &divsigma) const
745 void TElasticity2DAnalytic::DivSigma(const TPZVec<REAL> &x, TPZVec<TVar> &divsigma) const
746 {
747  TPZManVector<Fad<TVar>,3> xfad(x.size());
748  for(int i=0; i<2; i++)
749  {
750  xfad[i] = Fad<TVar>(2,i,x[i]);
751  }
752  TPZFNMatrix<4, Fad<TVar> > sigma(2,2);
753  Sigma(xfad,sigma);
754  divsigma[0] = sigma(0,0).dx(0)+sigma(0,1).dx(1);
755  divsigma[1] = sigma(1,0).dx(0)+sigma(1,1).dx(1);
756 }
757 
758 
759 
760 template
761 void TElasticity2DAnalytic::DivSigma(const TPZVec<REAL> &x, TPZVec<STATE> &divsigma) const;
762 
763 
764 TElasticity3DAnalytic::TElasticity3DAnalytic(const TElasticity3DAnalytic &cp) : TPZAnalyticSolution(cp),fProblemType(cp.fProblemType),fE(cp.fE),fPoisson(cp.fPoisson) {
765  std::cout << "TElasticity3DAnalytic::TElasticity3DAnalytic(const TElasticity3DAnalytic &cp): One should not invoke this copy constructor";
766  DebugStop();
767 }
768 
769 TElasticity3DAnalytic & TElasticity3DAnalytic::operator=(const TElasticity3DAnalytic &copy){
770  fProblemType = copy.fProblemType;
771  fE = copy.fE;
772  fPoisson = copy.fPoisson;
773  return *this;
774 }
775 
776 template<class TVar>
777 void TElasticity3DAnalytic::uxy(const TPZVec<TVar> &x, TPZVec<TVar> &disp) const
778 {
779 
780  if(fProblemType == Etest1)
781  {
782  disp[0] = TVar(1./27.)*x[0]*x[0]*x[1]*x[1]*cos(TVar(6.*M_PI)*x[0])*sin(TVar(7.*M_PI)*x[1]);
783  disp[1] = TVar(0.2)*exp(x[1])*sin(TVar(4.*M_PI)*x[0]);
784  disp[2] = x[0]*TVar(0.);
785  }
786  else if(fProblemType == Etest2)
787  {
788  disp[0] = x[0]*0.;
789  disp[1] = x[0]*0.;
790  disp[0] = ((1.-x[0]*x[0])*(1.+x[1]*x[1]*x[1]*x[1]));
791  disp[1] = ((1.-x[1]*x[1])*(1.+x[0]*x[0]*x[0]*x[0]));
792  disp[2] = x[0]*TVar(0.);
793  }
794 
795  else if(fProblemType ==ERot)//rotation
796  {
797  disp[0] = x[0]*0.;
798  disp[1] = x[0]*0.;
799  disp[0] = (TVar)-x[1];
800  disp[1] = (TVar)x[0];
801  disp[2] = x[0]*TVar(0.);
802  }
803 
804  else if(fProblemType == EShear)//pure shear
805  {
806  disp[0] = x[0]*0.;
807  disp[1] = x[0]*0.;
808  disp[0] += (TVar) x[1];
809  disp[1] += (TVar) 0. ;
810  disp[2] = x[0]*TVar(0.);
811  }
812  else if(fProblemType == EStretchx)//strech x
813  {
814  disp[0] = x[0]*0.;
815  disp[1] = x[0]*0.;
816  disp[0] += (TVar) x[0];
817  disp[1] += (TVar) 0.;
818  disp[2] = x[0]*TVar(0.);
819  }
820  else if(fProblemType == EUniAxialx)//strech x
821  {
822  disp[0] += (TVar) x[0]/fE;
823  disp[1] += (TVar) -x[1]*fPoisson/fE;
824  disp[2] = -x[2]*fPoisson/fE;
825  }
826  else if(fProblemType ==EStretchy)//strech y
827  {
828  disp[0] = x[0]*0.;
829  disp[1] = x[0]*0.;
830  disp[0] += (TVar) 0.;
831  disp[1] += (TVar) x[1];
832  disp[2] = x[0]*TVar(0.);
833  }
834  else if(fProblemType==EDispx)
835  {
836  disp[0] = x[0]*0.;
837  disp[1] = x[0]*0.;
838  disp[0] += 1.;
839  disp[0] += 0.;
840  disp[2] = x[0]*TVar(0.);
841  }
842  else if(fProblemType==EDispy)
843  {
844  disp[0] = x[0]*0.;
845  disp[1] = x[0]*0.;
846  disp[0] += (TVar) 0.;
847  disp[0] += (TVar) 1.;
848  disp[2] = x[0]*TVar(0.);
849  }
850  else if(fProblemType==EBend)
851  {
852  TVar poiss = fPoisson;
853  TVar elast = fE;
854  disp[0] = 5.*x[0]*x[1]/elast;
855  disp[1] = (-poiss*5.*x[1]*x[1]/2.-5.*x[0]*x[0]/2.)/elast;
856  disp[2] = x[0]*0.;
857  }
858  else if(fProblemType == ELoadedBeam)
859  {
860  TVar Est = fE,nust = fPoisson,G;
861  REAL MI = 5, h = 1.;
862  G = fE/(2.*(1.+fPoisson));
863  // returning the solution of plane strain
864  Est = fE/((1.-fPoisson*fPoisson));
865  nust = fPoisson/(1-fPoisson);
866  int offset = 2;
867  int i0 = offset;
868  int i1 = (offset+1)%3;
869  int i2 = (offset+2)%3;
870 
871  disp[i0] = MI*h*h*x[i1]/(2.*G)+MI * x[i0]*x[i0]*x[i1]/(2.*Est)-MI *x[i1]*x[i1]*x[i1]/(6.*G)+MI*nust*x[i1]*x[i1]*x[i1]/(6.*Est);
872  disp[i1] = -MI*x[i0]*x[i0]*x[i0]/(6.*Est)-MI*nust*x[i0]*x[i1]*x[i1]/(2.*Est);
873  disp[i2] = x[i2]*0.;
874  }
875  else if(fProblemType == ETestShearMoment)
876  {
877  disp[0] = -((TVar) FI/fE*fPoisson) *x[0]*x[1]*x[2];
878  disp[1] = ((TVar) FI/fE) *((TVar)(fPoisson/2.)*(x[0]*x[0]-x[1]*x[1])*x[2]-((TVar)(1./6.)*x[2]*x[2]*x[2]));
879  TVar disp2A = FI/fE*(1./2.* x[1]*(fPoisson*x[0]*x[0]+x[2]*x[2])+1./6.*fPoisson*x[1]*x[1]*x[1]+(1.+fPoisson)*(b*b*x[1]-1./3.*x[1]*x[1]*x[1])-1./3.*a*a*fPoisson*x[1]);
880  TVar series = (TVar) 0.;
881  TVar minusone = (TVar) -1;
882  for (int i=1; i<5; i++) {
883  series += (minusone/TVar(i*i*i)*cos(i*M_PI*x[0]/a)*sinh(i*M_PI*x[1]/a)/cosh(i*M_PI*b/a));
884  minusone *= (TVar) -1.;
885  }
886  series *= (-4.*a*a*a*fPoisson/(M_PI*M_PI*M_PI));
887  disp[2] = disp2A+series;
888  }
889  else if(fProblemType == ESphere)
890  {
891  TPZManVector<TVar,3> xc(x);
892  TVar radius2 = xc[0]*xc[0]+xc[1]*xc[1]+xc[2]*xc[2];
893  TVar radius = sqrt(radius2);
894  TVar acube = 10.*10.*10.;
895  TVar bcube = 50.*50.*50.;
896  TVar pi = 6.;
897  TVar ur = pi*acube/(2.*fE*(bcube-acube)*radius2)*(2.*(1.-2.*fPoisson)*radius2*radius+(1.+fPoisson)*bcube);
898  TVar cosphi = xc[2]/radius;
899  TVar xyradius = sqrt(xc[0]*xc[0]+xc[1]*xc[1]);
900  TVar sinphi = xyradius/radius;
901  TVar costheta = xc[0]/xyradius;
902  TVar sintheta = xc[1]/xyradius;
903  disp[2] = ur*cosphi;
904  disp[0] = ur*sinphi*costheta;
905  disp[1] = ur*sinphi*sintheta;
906  }
907  else{
908  DebugStop();
909  }
910 }
911 
912 
913 template<>
914 void TElasticity3DAnalytic::uxy(const TPZVec<FADFADSTATE > &x, TPZVec<FADFADSTATE > &disp) const
915 {
916  typedef FADFADSTATE TVar;
917  if(fProblemType == Etest1)
918  {
919  FADFADSTATE tmp = (FADFADSTATE)(1./27.)*x[0]*x[0]*x[1]*x[1];
920  disp[0] = tmp*FADcos((FADFADSTATE)(6.*M_PI)*x[0])*FADsin((FADFADSTATE)(7.*M_PI)*x[1]);
921  disp[1] = (FADFADSTATE)(0.2)*FADexp(x[1])*FADsin((FADFADSTATE)(4.*M_PI)*x[0]);
922  disp[2] = x[0]*TVar(0.);
923 
924  }
925  else if(fProblemType == Etest2)
926  {
927  disp[0] = x[0]*0.;
928  disp[1] = x[0]*0.;
929  disp[0] = ((1.-x[0]*x[0])*(1.+x[1]*x[1]*x[1]*x[1]));
930  disp[1] = ((1.-x[1]*x[1])*(1.+x[0]*x[0]*x[0]*x[0]));
931  disp[2] = x[0]*TVar(0.);
932  }
933 
934  else if(fProblemType ==ERot)//rotation
935  {
936  disp[0] = x[0]*0.;
937  disp[1] = x[0]*0.;
938  disp[0] =(FADFADSTATE)-x[1];
939  disp[1] =(FADFADSTATE) x[0];
940  disp[2] = x[0]*TVar(0.);
941 
942  }
943 
944  else if(fProblemType == EShear)//pure shear
945  {
946  disp[0] = x[0]*0.;
947  disp[1] = x[0]*0.;
948  disp[0] += (FADFADSTATE) x[1];
949  disp[1] += (FADFADSTATE) 0. ;
950  disp[2] = x[0]*TVar(0.);
951  }
952  else if(fProblemType == EStretchx)//strech x
953  {
954  disp[0] = x[0]*0.;
955  disp[1] = x[0]*0.;
956  disp[0] += (FADFADSTATE) x[0];
957  disp[1] += (FADFADSTATE) 0.;
958  disp[2] = x[0]*TVar(0.);
959  }
960  else if(fProblemType == EUniAxialx)//strech x
961  {
962  disp[0] += (TVar) x[0]/fE;
963  disp[1] += (TVar) -x[1]*fPoisson/fE;
964  disp[2] = -x[2]*fPoisson/fE;
965  }
966  else if(fProblemType ==EStretchy)//strech y
967  {
968  disp[0] = x[0]*0.;
969  disp[1] = x[0]*0.;
970  disp[0] += (FADFADSTATE) 0.;
971  disp[1] += (FADFADSTATE) x[1];
972  disp[2] = x[0]*TVar(0.);
973  }
974  else if(fProblemType==EDispx)
975  {
976  disp[0] = x[0]*0.;
977  disp[1] = x[0]*0.;
978  disp[0] += 1.;
979  disp[0] += 0.;
980  disp[2] = x[0]*TVar(0.);
981  }
982  else if(fProblemType==EDispy)
983  {
984  disp[0] = x[0]*0.;
985  disp[1] = x[0]*0.;
986  disp[0] += (FADFADSTATE) 0.;
987  disp[0] += (FADFADSTATE) 1.;
988  disp[2] = x[0]*TVar(0.);
989  }
990  else if(fProblemType==EBend)
991  {
992  TVar poiss = fPoisson;
993  TVar elast = fE;
994  disp[0] = 5.*x[0]*x[1]/elast;
995  disp[1] = (-poiss*5.*x[1]*x[1]/2.-5.*x[0]*x[0]/2.)/elast;
996  disp[2] = x[0]*0.;
997  }
998  else if(fProblemType == ELoadedBeam)
999  {
1000  TVar Est = fE,nust = fPoisson,G;
1001  REAL MI = 5, h = 1.;
1002  G = fE/(2.*(1.+fPoisson));
1003  // returning the solution of plane strain
1004  Est = fE/((1.-fPoisson*fPoisson));
1005  nust = fPoisson/(1.-fPoisson);
1006  int offset = 2;
1007  int i0 = offset;
1008  int i1 = (offset+1)%3;
1009  int i2 = (offset+2)%3;
1010 
1011  disp[i0] = MI*h*h*x[i1]/(2.*G)+MI * x[i0]*x[i0]*x[i1]/(2.*Est)-MI *x[i1]*x[i1]*x[i1]/(6.*G)+MI*nust*x[i1]*x[i1]*x[i1]/(6.*Est);
1012  disp[i1] = -MI*x[i0]*x[i0]*x[i0]/(6.*Est)-MI*nust*x[i0]*x[i1]*x[i1]/(2.*Est);
1013  disp[i2] = x[i2]*0.;
1014  }
1015  else if(fProblemType == ETestShearMoment)
1016  {
1017  disp[0] = -((TVar) FI/fE*fPoisson) *x[0]*x[1]*x[2];
1018  disp[1] = ((TVar) FI/fE) *((TVar)(fPoisson/2.)*(x[0]*x[0]-x[1]*x[1])*x[2]-((TVar)(1./6.)*x[2]*x[2]*x[2]));
1019  TVar disp2A = FI/fE*(1./2.* x[1]*(fPoisson*x[0]*x[0]+x[2]*x[2])+1./6.*fPoisson*x[1]*x[1]*x[1]+(1.+fPoisson)*(b*b*x[1]-1./3.*x[1]*x[1]*x[1])-1./3.*a*a*fPoisson*x[1]);
1020  TVar series = (TVar) 0.;
1021  TVar minusone = (TVar) -1;
1022  for (int i=1; i<5; i++) {
1023  TVar ivar(i);
1024  series += (minusone/(TVar)(i*i*i)*FADcos(ivar*M_PI*x[0]/a)*FADsinh(ivar*M_PI*x[1]/a)/FADcosh(ivar*M_PI*b/a));
1025  minusone *= (TVar) -1.;
1026  }
1027  series *= (-4.*a*a*a*fPoisson/(M_PI*M_PI*M_PI));
1028  disp[2] = disp2A+series;
1029  }
1030  else if(fProblemType == ESphere)
1031  {
1032  TPZManVector<TVar,3> xc(x);
1033  TVar radius2 = xc[0]*xc[0]+xc[1]*xc[1]+xc[2]*xc[2];
1034  TVar radius = FADsqrt(radius2);
1035  TVar acube = 10.*10.*10.;
1036  TVar bcube = 50.*50.*50.;
1037  TVar pi = 6.;
1038  TVar ur = pi*acube/(2.*fE*(bcube-acube)*radius2)*(2.*(1.-2.*fPoisson)*radius2*radius+(1.+fPoisson)*bcube);
1039  TVar cosphi = xc[2]/radius;
1040  TVar xyradius = FADsqrt(xc[0]*xc[0]+xc[1]*xc[1]);
1041  TVar sinphi = xyradius/radius;
1042  TVar costheta = xc[0]/xyradius;
1043  TVar sintheta = xc[1]/xyradius;
1044  disp[2] = ur*cosphi;
1045  disp[0] = ur*sinphi*costheta;
1046  disp[1] = ur*sinphi*sintheta;
1047  }
1048  else{
1049  DebugStop();
1050  }
1051 }
1052 
1053 
1054 template<class TVar>
1055 void TElasticity3DAnalytic::Elastic(const TPZVec<TVar> &x, TVar &Elast, TVar &nu) const
1056 {
1057  // Elast = (TVar(100.) * (TVar(1.) + TVar(0.3) * sin(TVar(10 * M_PI) * (x[0] - TVar(0.5))) * cos(TVar(10. * M_PI) * x[1])));
1058  Elast = TVar(fE);
1059  nu = TVar(fPoisson);
1060 }
1061 
1062 //template<>
1063 //void TElasticity3DAnalytic::Elastic(const TPZVec<double> &x, double &Elast, double &nu)
1064 //{
1065 // Elast = 1000.;
1066 // Elast = (100. * (1. + 0.3 * sin(10 * M_PI * (x[0] - 0.5)) * cos(10. * M_PI * x[1])));
1067 // Elast = 1.;
1068 // nu = 0.;
1069 //}
1070 
1071 void TElasticity3DAnalytic::ElasticDummy(const TPZVec<REAL> &x, TPZVec<STATE> &result, TPZFMatrix<STATE> &deriv)
1072 {
1073  TPZManVector<STATE> xstate(x.size());
1074  for (int i=0; i<xstate.size(); i++) {
1075  xstate[i] = x[i];
1076  }
1077  STATE E = 1.,nu = 0.3;
1078  DebugStop();
1079 // Elastic(xstate,E,nu);
1080  result[0] = E;
1081  result[1] = nu;
1082 }
1083 
1084 
1085 template<class TVar>
1086 void TElasticity3DAnalytic::graduxy(const TPZVec<TVar> &x, TPZFMatrix<TVar> &grad) const
1087 {
1088  int sz = x.size();
1089 #ifdef PZDEBUG
1090  if(sz != 3)
1091  {
1092  DebugStop();
1093  }
1094 #endif
1095  TPZManVector<Fad<TVar>,3> xfad(sz);
1096  for(int i=0; i<sz; i++)
1097  {
1098  Fad<TVar> temp = Fad<TVar>(sz,i,x[i]);
1099  xfad[i] = temp;
1100 
1101  }
1102  TPZManVector<Fad<TVar>,3> result(3);
1103  uxy(xfad,result);
1104  grad.Resize(sz,sz);
1105  for (int i=0; i<sz; i++) {
1106  for (int j=0; j<sz; j++)
1107  {
1108  grad(j,i) = result[i].d(j);
1109  }
1110  }
1111 
1112 }
1113 
1114 void TElasticity3DAnalytic::Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const
1115 {
1116  int sz = x.size();
1117  TPZManVector<Fad<STATE>,3> xfad(sz);
1118  for(int i=0; i<sz; i++)
1119  {
1120  Fad<STATE> temp = Fad<STATE>(sz,i,x[i]);
1121  xfad[i] = temp;
1122  }
1123  TPZManVector<Fad<STATE>,3> result(3);
1124  uxy(xfad,result);
1125  gradu.Redim(sz,sz);
1126  for (int i=0; i<sz; i++) {
1127  u[i] = result[i].val();
1128  for (int j=0; j<sz; j++)
1129  {
1130  gradu(i,j) = result[j].d(i);
1131  }
1132  }
1133 
1134 }
1135 
1136 /*
1137 template<>
1138 void TElasticity3DAnalytic::graduxy(const TPZVec<Fad<STATE> > &x, TPZFMatrix<Fad<STATE> > &grad)
1139 {
1140  TPZManVector<Fad<Fad<STATE> >,3> xfad(x.size());
1141  for(int i=0; i<3; i++)
1142  {
1143  Fad<Fad<STATE> > temp = Fad<Fad<STATE> >(3,Fad<STATE>(3,0.));
1144  // Fad<STATE> temp = Fad<STATE>(2,i,x[i]);
1145  temp.val()= x[i];
1146  Fad<STATE> temp3(3,0.);
1147  for(int j=0; j<3; j++)
1148  {
1149  temp.fastAccessDx(j) = temp3;
1150  }
1151  Fad<STATE> temp2(3,1.);
1152  temp.fastAccessDx(i) = temp2;
1153  // Fad<STATE> temp = Fad<STATE>(2,i,x[i]);
1154  xfad[i] = temp;
1155  // xfad[i] = temp;
1156  }
1157  TPZManVector<Fad<Fad<STATE> >,3> result(2);
1158  uxy(xfad,result);
1159  grad.Resize(2,2);
1160  for (int i=0; i<2; i++) {
1161  for (int j=0; j<2; j++)
1162  {
1163  grad(i,j) = result[i].d(j);
1164  }
1165  }
1166 }
1167  */
1168 
1169 template<class TVar>
1170 void TElasticity3DAnalytic::Sigma(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const
1171 {
1172  TPZFNMatrix<9,TVar> grad;
1173  TVar E, nu;
1174  Elastic(x, E, nu);
1175  TVar Fac = E/((TVar)1.+nu)/((TVar(1.)-TVar(2.)*nu));
1176  graduxy(x,grad);
1177  //uxy(x,u);
1178  sigma.Resize(3,3);
1179  sigma(0,0) = Fac*((TVar(1.)-nu)*grad(0,0)+nu*grad(1,1)+nu*grad(2,2));
1180  sigma(1,1) = Fac*((TVar(1.)-nu)*grad(1,1)+nu*grad(0,0)+nu*grad(2,2));
1181  sigma(2,2) = Fac*((TVar(1.)-nu)*grad(2,2)+nu*grad(0,0)+nu*grad(1,1));
1182  sigma(0,1) = E/(TVar(2.)*(TVar(1.)+nu))*(grad(0,1)+grad(1,0));
1183  sigma(1,0) = sigma(0,1);
1184  sigma(0,2) = E/(TVar(2.)*(TVar(1.)+nu))*(grad(0,2)+grad(2,0));
1185  sigma(2,0) = sigma(0,2);
1186  sigma(1,2) = E/(TVar(2.)*(TVar(1.)+nu))*(grad(1,2)+grad(2,1));
1187  sigma(2,1) = sigma(1,2);
1188 }
1189 
1190 void TElasticity3DAnalytic::Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &tensor) const
1191 {
1192  TPZManVector<STATE,3> xloc(3,0.);
1193  for (int i=0; i<3; i++) {
1194  xloc[i] = x[i];
1195  }
1196  Sigma<STATE>(xloc,tensor);
1197 }
1198 
1199 /*
1200 template<>
1201 void TElasticity3DAnalytic::Sigma(const TPZVec<Fad<STATE> > &x, TPZFMatrix<Fad<STATE> > &sigma)
1202 {
1203  TPZFNMatrix<4,Fad<STATE> > grad;
1204  Fad<STATE> E, nu;
1205  Elastic(x, E, nu);
1206  Fad<STATE> Fac = E/(Fad<STATE>(1.)+nu)/((Fad<STATE>(1.)-Fad<STATE>(2.)*nu));
1207  graduxy(x,grad);
1208  sigma.Resize(2,2);
1209  sigma(0,0) = Fac*((Fad<STATE>(1.)-nu)*grad(0,0)+nu*grad(1,1));
1210  sigma(1,1) = Fac*((Fad<STATE>(1.)-nu)*grad(1,1)+nu*grad(0,0));
1211  sigma(0,1) = E/(Fad<STATE>(2.)*(Fad<STATE>(1.)+nu))*(grad(0,1)+grad(1,0));
1212  sigma(1,0) = sigma(0,1);
1213 
1214 }
1215 */
1216 template
1217 void TElasticity3DAnalytic::Sigma<REAL>(const TPZVec<REAL> &x, TPZFMatrix<REAL> &divsigma) const;
1218 
1219 template<class TVar>
1220 void TElasticity3DAnalytic::DivSigma(const TPZVec<REAL> &x, TPZVec<TVar> &divsigma) const
1221 {
1222  int sz = x.size();
1223  TPZManVector<Fad<TVar>,3> xfad(sz);
1224  for(int i=0; i<sz; i++)
1225  {
1226  xfad[i] = Fad<TVar>(sz,i,x[i]);
1227  }
1228  TPZFNMatrix<9, Fad<TVar> > sigma(3,3);
1229  Sigma(xfad,sigma);
1230  for (int i=0; i<3; i++) {
1231  divsigma[i] = sigma(i,0).dx(0)+sigma(i,1).dx(1)+sigma(i,2).dx(2);
1232  }
1233 }
1234 
1235 
1236 
1237 template
1238 void TElasticity3DAnalytic::DivSigma<STATE>(const TPZVec<REAL> &x, TPZVec<STATE> &divsigma) const;
1239 template
1240 void TElasticity3DAnalytic::Sigma<Fad<STATE> >(const TPZVec<Fad<STATE> > &x, TPZFMatrix<Fad<STATE> > &sigma) const;
1241 
1242 TLaplaceExample1::TLaplaceExample1(const TLaplaceExample1 &cp) : TPZAnalyticSolution(cp),fExact(cp.fExact) {
1243  std::cout << "TLaplaceExample1::TLaplaceExample1(const TLaplaceExample1 &cp): One should not invoke this copy constructor";
1244  DebugStop();
1245 }
1246 
1247 TLaplaceExample1 & TLaplaceExample1::operator=(const TLaplaceExample1 &copy){
1248  fExact = copy.fExact;
1249  return *this;
1250 }
1251 
1252 template<class TVar>
1253 void TLaplaceExample1::uxy(const TPZVec<TVar> &x, TPZVec<TVar> &disp) const
1254 {
1255  TPZManVector<TVar,3> xloc(x);
1256  for (int i = 0; i<xloc.size(); i++) {
1257  xloc[i] -= fCenter[i];
1258  }
1259  TVar r2 = 0.;
1260  for (int i=0; i<fDimension; i++) {
1261  r2 += xloc[i]*xloc[i];
1262  }
1263  TVar r = sqrt(r2);
1264  disp[0] = xloc[0]*(TVar)(0.);
1265 
1266  REAL xval[2] = {shapeFAD::val(x[0]),shapeFAD::val(x[1])};
1267 
1268  switch (fExact) {
1269  case EConst:
1270  disp[0] += 1.;
1271  break;
1272  case EX:
1273  disp[0] += xloc[0];
1274  break;
1275  case ESinSin:
1276  {
1277  disp[0] += (TVar)(1.);
1278  for(int i=0; i<fDimension; i++) disp[0] *= sin((TVar)M_PI*xloc[i]);
1279  }
1280  break;
1281  case E10SinSin:
1282  {
1283  disp[0] += (TVar)(1.);
1284  for(int i=0; i<fDimension; i++) disp[0] *= sin((TVar)M_PI*xloc[i]*10.);
1285  }
1286  break;
1287 
1288  case E2SinSin:
1289  {
1290  disp[0] += (TVar)(1.);
1291  for(int i=0; i<fDimension; i++) disp[0] *= sin((TVar)M_PI*xloc[i]*2.);
1292  }
1293  break;
1294  case ESinDist:
1295  {
1296  disp[0] += (TVar)(1.);
1297  for(int i=0; i<fDimension; i++) disp[0] *= sin((TVar)M_PI*xloc[i]*1.1);
1298  }
1299  break;
1300  case ECosCos:
1301  {
1302  disp[0] += (TVar)(1.);
1303  for(int i=0; i<fDimension; i++) disp[0] *= cos((TVar)M_PI*2.*xloc[i]);
1304  }
1305  break;
1306  case EArcTan://(1+0.3sin(10Pi x))*(1+0.5cos(10Pi r)*arctan(100*(r-0.5))
1307  {
1308  TVar atanco = (r-(TVar)0.5)*100.;
1309  TVar freq = 10.;
1310  TVar mult = (TVar(1)+TVar(0.3)*sin(TVar(M_PI)*xloc[0]*freq))*(TVar(1)+TVar(0.5)*cos(TVar(M_PI)*r*freq));
1311  disp[0] = atan(atanco)*mult;
1312  }
1313  break;
1314  case EArcTanSingular://5*(0.5*pi + arctang(20(0.25 - r^2))))
1315  {
1316  REAL B = 5.;
1317  if(fDimension==1)
1318  B *= 0.25;
1319  else if(fDimension==3)
1320  B *= 4;
1321  // Argument value (arc) to compute ArcTangent( arc )
1322  TVar RCircle = 0.5;
1323  TVar Force = 20.;
1324  TVar arc = Force*(RCircle*RCircle-r2);
1325  TVar Prod = 1.;
1326  for (int i=0; i<fDimension; i++) {
1327  Prod *= x[i]*(1.-x[i]);
1328  }
1329  TVar temp = 0.5*M_PI + atan(arc);
1330  disp[0] = B*temp;
1331  }
1332  break;
1333 
1334  //----
1335  case ESinMark://(r^(2/3)-r^2)sin(20/3) para homogeneo dirichlet e r^(2/3)sin(20/3) para f=0
1336  {
1337 
1338  TVar theta = atan2(xloc[1], xloc[0]);//theta=arctan(y/x)
1339  auto thetaval = shapeFAD::val(theta);
1340  if (thetaval < (0.)) theta += 2. * M_PI;
1341 
1342  // Verification to avoid numerical errors when x > 0 and y = 0
1343  if (xval[0] > 0 && xval[1] < 1e-15 && xval[1] > -1.e-15) {
1344  disp[0] = 0.;
1345  }
1346  else {
1347  TVar factor = pow(r,TVar (2.)/TVar (3.));//pow(r,TVar (2.)/TVar (3.))-pow(r,TVar (2.));//
1348  disp[0] = factor * (sin((TVar) (2.) * theta / TVar(3.)));
1349  }
1350 
1351 
1352  }
1353  break;
1354 
1355  //--
1356 
1357  case ESinSinDirNonHom: //sin(2 pi x)sin(2pi y)+1/(x+y+1)
1358  {
1359 
1360  disp[0]=(sin((TVar)M_PI*2.*xloc[0]))*sin((TVar)M_PI*2.*xloc[1])+(TVar)1./(xloc[0]+xloc[1]+(TVar)(1.));
1361 
1362  }
1363 
1364  break;
1365 
1366  case ESteklovNonConst://Steklov function for eigenvalue lambda=0.53544094560246 and permeability Omega1=Omega=3, Omega2=Omega4=5
1367  {
1368  TVar coefs[] = {1., 0.44721359549995787, 2.3333333333333326,
1369  -0.7453559924999296, 0.5555555555555556,
1370  -0.9441175904999111, -0.48148148148148173,
1371  -2.4017026424997736};
1372  TVar lambda = 0.53544094560246;
1373  TVar t = atan2(xloc[1], xloc[0]);
1374  REAL tval = shapeFAD::val(t);
1375  if(tval < (0.)) t += 2.*M_PI;
1376 
1377  if((xval[0] >=(0.)) && (xval[1] >=(0.))){
1378  // std::cout<<"1o. Q "<<xloc<< " r " << r << " th " << t << std::endl;
1379 
1380  disp[0]=pow(r, lambda)*(TVar(coefs[0])*cos(lambda *t) + TVar(coefs[1])*sin(lambda*t) );
1381  // std::cout<<"valor da funcao no 1o. Q "<<disp[0]<<std::endl;
1382  // disp[0]=pow(r, lambda)*(cos(lambda *t)+TVar(-1.)*TVar(0.1)*sin(lambda*t));
1383 
1384  }
1385 
1386  if(( xval[0] <= (0.)) && (xval[1] >=(0.))){
1387  // std::cout<<"2o. Q "<<xloc<< " r " << r << " th " << t << std::endl;
1388 
1389  disp[0]= pow(r, lambda)*(TVar(coefs[2])*cos(lambda*t) + TVar(coefs[3])*sin(lambda* t));
1390 
1391  // std::cout<<"valor da funcao no 2o. Q "<<disp[0]<<std::endl;
1392  }
1393 
1394  if((xval[0] <(0.)) && ( xval[1] <= (0.))){
1395  // std::cout<<"3o. Q "<<xloc<< " r " << r << " th " << t << std::endl;
1396  disp[0]= pow(r, lambda)*(TVar(coefs[4] )*cos(lambda*t) + TVar(coefs[5])*sin(lambda* t));
1397  //disp[0]= pow(r, lambda)*(TVar(-1.)*TVar(0.882757 )*cos(lambda*t) + TVar(-1.)*TVar(0.480355)*sin(lambda* t));
1398  // std::cout<<"valor da funcao no 3o. Q "<<disp[0]<<std::endl;
1399  }
1400  if(( xval[0] >= (0.)) && ( xval[1] < (0.))){
1401  // std::cout<<"4o. Q "<<xloc<< " r " << r << " th " << t << std::endl;
1402 
1403  disp[0]= pow(r, lambda)*(TVar(coefs[6])*cos(lambda*t) + TVar(coefs[7])*sin(lambda* t));
1404 
1405  // std::cout<<"valor da funcao no 4o. Q "<<disp[0]<<std::endl;
1406 
1407  }
1408 
1409 
1410  }
1411  break;
1412 
1413  case EGalvisNonConst:
1414  {
1415 
1416  TVar k1 = 2;
1417  TVar k2 = 5;
1418 
1419 
1420  if((xval[0] <= (0.)) && (xval[1] <= (0.))){
1421 
1422  TVar u1 = sin(M_PI*(xloc[0]+TVar(1.))/(k1+1.));
1423  TVar u2 = TVar(4.)*(xloc[1]+TVar(1.))*(k2-xloc[1])/((k2+TVar(1.))*(k2+TVar(1.)));
1424 
1425  disp[0]=u1*u2;
1426  // std::cout<<"3o. Q "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1427 
1428  }
1429 
1430  if(( xval[0] > (0.)) && (xval[1] < (0.))){
1431 
1432 
1433  TVar u1 = sin(M_PI*(k1*xloc[0]+TVar(1.))/(k1 + TVar(1.)));
1434  TVar u2 = TVar(4.)*(xloc[1]+TVar(1.))*(k2-xloc[1])/((k2+TVar(1.))*(k2+TVar(1.)));
1435 
1436  disp[0]=u1*u2;
1437  // std::cout<<"4o. Q "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1438 
1439  }
1440 
1441  if((xval[0] < (0.)) && ( xval[1] >= (0.))){
1442 
1443  TVar u1 = sin(M_PI*(xloc[0]+TVar(1.))/(k1+TVar(1.)));
1444  TVar u2 = TVar(4.)*(k2*xloc[1]+TVar(1.))*(k2-k2*xloc[1])/((k2+TVar(1.))*(k2+TVar(1.)));
1445 
1446  disp[0]=u1*u2;
1447  // std::cout<<"2o. Q "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1448 
1449  }
1450  if(( xval[0] >= (0.)) && ( xval[1] >= (0.))){
1451 
1452 
1453  TVar u1 = sin(M_PI*(k1*xloc[0]+TVar(1.))/(k1+TVar(1.)));
1454  TVar u2 = TVar(4.)*(k2*xloc[1]+TVar(1.))*(k2-k2*xloc[1])/((k2+TVar(1.))*(k2+TVar(1.)));
1455 
1456  disp[0]=u1*u2;
1457  // std::cout<<"1o. Q "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1458 
1459 
1460  }
1461 
1462 
1463  }
1464  break;
1465 
1466  case EBoundaryLayer:{
1467  TVar term1 = xloc[0]*xloc[1]*(1.-xloc[0])*(1.-xloc[1]);
1468  TVar term2 = exp(TVar(10.)*xloc[0])*exp(TVar(10.)*xloc[1]);
1469  TVar factor = TVar(537930);
1470 
1471  disp[0] = (term1*term2)/factor;
1472 
1473  // std::cout<<"Pto "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1474 
1475 
1476  }
1477  break;
1478 
1479  case EBubble:{
1480 
1481  disp[0] = xloc[0]*xloc[1]*xloc[2]*(TVar(1.)-xloc[0])*(TVar(1.)-xloc[1])*(TVar(1.)-xloc[2]);
1482  // std::cout<<"pto "<<xloc <<" f(x) "<<disp<<std::endl;
1483  }
1484  break;
1485  case ESinCosCircle:{
1486 
1487  TVar coef = pow(r, TVar(4.));
1488  TVar theta=atan2(xloc[1],xloc[0]);
1489  disp[0] = coef*sin(TVar(2.)*theta)*cos(TVar(2.)*theta);
1490 
1491 
1492  }
1493  break;
1494  case EHarmonic:
1495  disp[0] = exp(M_PI*x[0])*sin(M_PI*x[1]);
1496  break;
1497 
1498  default:
1499  disp[0] = 0.;
1500  break;
1501  }
1502 }
1503 
1504 template<>
1505 void TLaplaceExample1::uxy(const TPZVec<FADFADSTATE > &x, TPZVec<FADFADSTATE > &disp) const
1506 {
1507 #ifdef PZDEBUG
1508 
1509  if(fDimension == -1){
1510  DebugStop();
1511  }
1512 
1513 #endif
1514 
1515  typedef FADFADSTATE TVar;
1516  TPZManVector<TVar,3> xloc(x);
1517  for (int i = 0; i<xloc.size(); i++) {
1518  xloc[i] -= fCenter[i];
1519  }
1520  TVar r2 = 0.;
1521  for (int i=0; i<fDimension; i++) {
1522  r2 += xloc[i]*xloc[i];
1523  }
1524  TVar r = FADsqrt(r2);
1525  disp[0] = (TVar)(0.)*xloc[0];
1526  switch (fExact) {
1527  case EConst:
1528  disp[0] += 1.;
1529  break;
1530  case EX:
1531  disp[0] += xloc[0];
1532  break;
1533  case ESinSin:
1534  {
1535  disp[0] += (TVar)(1.);
1536  for(int i=0; i<fDimension; i++) disp[0] *= FADsin((TVar)M_PI*xloc[i]);
1537  }
1538  break;
1539  case E10SinSin:
1540  {
1541  disp[0] += (TVar)(1.);
1542  for(int i=0; i<fDimension; i++) disp[0] *= FADsin((TVar)M_PI*xloc[i]*10.);
1543  }
1544  break;
1545  case E2SinSin:
1546  {
1547  disp[0] += (TVar)(1.);
1548  for(int i=0; i<fDimension; i++) disp[0] *= FADsin((TVar)M_PI*xloc[i]*2.);
1549  }
1550  break;
1551 
1552 
1553  case ESinDist:
1554  {
1555  disp[0] += (TVar)(1.);
1556  for(int i=0; i<fDimension; i++) disp[0] *= FADsin((TVar)M_PI*xloc[i]*1.1);
1557  }
1558  break;
1559  case ECosCos:
1560  {
1561  disp[0] += (TVar)(1.);
1562  for(int i=0; i<fDimension; i++) disp[0] *= FADcos((TVar)M_PI*2.*xloc[i]);
1563  }
1564  break;
1565  case EArcTan:
1566  {
1567  TVar atanco = (r-(TVar)0.5)*100.;
1568  TVar freq = 10.;
1569  TVar mult = (TVar(1)+TVar(0.3)*FADsin(TVar(M_PI)*xloc[0]*freq))*(TVar(1)+TVar(0.5)*FADcos(TVar(M_PI)*r*freq));
1570  disp[0] = FADatan(atanco)*mult;
1571  }
1572  break;
1573  case EArcTanSingular:
1574  {
1575  REAL B = 5.;
1576  if(fDimension==1)
1577  B *= 0.25;
1578  else if(fDimension==3)
1579  B *= 4;
1580  // Argument value (arc) to compute ArcTangent( arc )
1581  TVar RCircle = 0.5;
1582  TVar Force = 20.;
1583  TVar arc = Force*(RCircle*RCircle-r2);
1584  TVar Prod = 1.;
1585  for (int i=0; i<fDimension; i++) {
1586  Prod *= x[i]*(1.-x[i]);
1587  }
1588  TVar temp = 0.5*M_PI + FADatan(arc);
1589  disp[0] = B*temp;
1590  }
1591  break;
1592  case ESinSinDirNonHom: //sin(2pi x)sin(2pi y)+1/(x+y+1)
1593  {
1594 
1595  disp[0]=(FADsin((TVar)M_PI*2.*xloc[0]))*FADsin((TVar)M_PI*2.*xloc[1])+(TVar)1./(xloc[0]+xloc[1]+(TVar)(1.));
1596 
1597  }
1598 
1599  break;
1600  case ESinMark://(r^(2/3)-r^2)sin(20/3) para f=0 usar r^(2/3)sin(20/3)
1601  {
1602 
1603  TVar theta=FADatan2(xloc[1],xloc[0]);//theta=atan(y/x)
1604 #ifdef STATE_COMPLEX
1605  if( theta.val().val().real() < 0.) theta += 2.*M_PI;
1606 #else
1607  if( theta < TVar(0.)) theta += 2.*M_PI;
1608 #endif
1609 
1610  // Verification to avoid numerical errors when x > 0 and y = 0
1611 #ifdef STATE_COMPLEX
1612  if ((xloc[0].val().val().real() > 0.) && (xloc[1].val().val().real() < (1e-15)) && (xloc[1].val().val().real() > (-1e-15))) {
1613  disp[0] = TVar(0.);
1614  }
1615 #else
1616  if ((xloc[0] > TVar(0.)) && (xloc[1] < TVar (1e-15)) && (xloc[1] > TVar(-1e-15))) {
1617  disp[0] = TVar(0.);
1618  }
1619 #endif
1620  else{
1621 
1622  TVar factor = pow(r,TVar (2.)/TVar (3.));//pow(r,TVar (2.)/TVar (3.))-pow(r,TVar (2.));
1623  disp[0] = factor*(FADsin((TVar)(2.)*theta/TVar(3.)));
1624  }
1625 
1626  }
1627  break;
1628  case ESteklovNonConst://Steklov function for eigenvalue lambda=0.126902 and permeability Omega1=Omega=3=100, Omega2=Omega4=1
1629  {
1630 
1631  TVar coefs[] = {1., 0.44721359549995787, 2.3333333333333326,
1632  -0.7453559924999296, 0.5555555555555556,
1633  -0.9441175904999111, -0.48148148148148173,
1634  -2.4017026424997736};
1635  TVar lambda = 0.53544094560246;
1636 #ifdef STATE_COMPLEX
1637  double xr = xloc[0].val().val().real();
1638  double yr = xloc[1].val().val().real();
1639 #else
1640  double xr = xloc[0].val().val();
1641  double yr = xloc[1].val().val();
1642 #endif
1643  TVar t = FADatan2(xloc[1], xloc[0]);
1644  double tval = atan2(yr,xr);
1645  if(tval < (0.)) t += TVar(2.*M_PI);
1646 
1647  if((xr >= (0.)) && (yr >= (0.))){
1648  // std::cout<<"1o. Q"<<xloc<<std::endl;
1649 
1650  disp[0]=pow(r, lambda)*(TVar(coefs[0])*FADcos(lambda *t) + TVar(coefs[1])*FADsin(lambda*t));
1651  // std::cout<<"valor da funcao no 1o. Q "<<disp[0]<<std::endl;
1652  // disp[0]=pow(r, lambda)*(cos(lambda *t)+TVar(-1.)*TVar(0.1)*sin(lambda*t));
1653 
1654  }
1655 
1656  if(( xr < (0)) && (yr >(0.))){
1657  // std::cout<<"2o. Q"<<xloc<<std::endl;
1658 
1659  disp[0]= pow(r, lambda)*(TVar(coefs[2])*FADcos(lambda*t) + TVar(coefs[3])*FADsin(lambda* t));
1660  //disp[0]= pow(r, lambda)*(TVar(2.9604)*cos(lambda*t) +TVar(-1.)* TVar(9.60396)*sin(lambda* t));
1661  //std::cout<<"valor da funcao no 2o. Q "<<disp[0]<<std::endl;
1662  }
1663 
1664  if((xr < (0.)) && ( yr <= (0.))){
1665  // std::cout<<"3o. Q"<<xloc<<std::endl;
1666  disp[0]= pow(r, lambda)*(TVar(coefs[4] )*FADcos(lambda*t) + TVar(coefs[5])*FADsin(lambda* t));
1667  //disp[0]= pow(r, lambda)*(TVar(-1.)*TVar(0.882757 )*cos(lambda*t) + TVar(-1.)*TVar(0.480355)*sin(lambda* t));
1668  // std::cout<<"valor da funcao no 3o. Q "<<disp[0]<<std::endl;
1669  }
1670  if(( xr >= (0.)) && ( yr < 0.)){
1671  // std::cout<<"4o. Q"<<xloc<<std::endl;
1672 
1673  disp[0]= pow(r, lambda)*(TVar(coefs[6])*FADcos(lambda*t) + TVar(coefs[7])*FADsin(lambda* t));
1674  //disp[0]= pow(r, lambda)*(TVar(-1.)*TVar(6.45646)*cos(lambda*t) + TVar(7.70156 )*sin(lambda* t));
1675  // std::cout<<"valor da funcao no 4o. Q "<<disp[0]<<std::endl;
1676 
1677  }
1678 
1679 
1680 
1681  }
1682  break;
1683 
1684  case EGalvisNonConst:
1685  {
1686 
1687  TVar k1 = 2;
1688  TVar k2 = 5;
1689 #ifdef STATE_COMPLEX
1690  double xr = xloc[0].val().val().real();
1691  double yr = xloc[1].val().val().real();
1692 #else
1693  double xr = xloc[0].val().val();
1694  double yr = xloc[1].val().val();
1695 #endif
1696 
1697 
1698  if((xr <= (0.)) && (yr <= (0.))){
1699 
1700  TVar u1 = FADsin(M_PI*(xloc[0]+TVar(1.))/(k1+1.));
1701  TVar u2 = TVar(4.)*(xloc[1]+TVar(1.))*(k2-xloc[1])/((k2+TVar(1.))*(k2+TVar(1.)));
1702 
1703  disp[0]=u1*u2;
1704  // std::cout<<"3o. Q "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1705 
1706  }
1707 
1708  if(( xr > (0.)) && (yr < (0.))){
1709 
1710 
1711  TVar u1 = FADsin(M_PI*(k1*xloc[0]+TVar(1.))/(k1 + TVar(1.)));
1712  TVar u2 = TVar(4.)*(xloc[1]+TVar(1.))*(k2-xloc[1])/((k2+TVar(1.))*(k2+TVar(1.)));
1713 
1714  disp[0]=u1*u2;
1715  // std::cout<<"4o. Q "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1716 
1717  }
1718 
1719  if((xr < (0.)) && ( yr >= (0.))){
1720 
1721  TVar u1 = FADsin(M_PI*(xloc[0]+TVar(1.))/(k1+TVar(1.)));
1722  TVar u2 = TVar(4.)*(k2*xloc[1]+TVar(1.))*(k2-k2*xloc[1])/((k2+TVar(1.))*(k2+TVar(1.)));
1723 
1724  disp[0]=u1*u2;
1725  // std::cout<<"2o. Q "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1726 
1727  }
1728  if(( xr >= (0.)) && ( yr >= (0.))){
1729 
1730 
1731  TVar u1 = FADsin(M_PI*(k1*xloc[0]+TVar(1.))/(k1+TVar(1.)));
1732  TVar u2 = TVar(4.)*(k2*xloc[1]+TVar(1.))*(k2-k2*xloc[1])/((k2+TVar(1.))*(k2+TVar(1.)));
1733 
1734  disp[0]=u1*u2;
1735  //std::cout<<"1o. Q "<<xloc<<" valor da funcao "<<disp[0]<<std::endl;
1736 
1737 
1738  }
1739  }
1740  break;
1741 
1742  case EBoundaryLayer:{
1743  TVar term1 = xloc[0]*xloc[1]*(1.-xloc[0])*(1.-xloc[1]);
1744  TVar term2 = FADexp(TVar(10.)*xloc[0])*FADexp(TVar(10.)*xloc[1]);
1745  TVar factor = TVar(537930);
1746 
1747  disp[0] = (term1*term2)/factor;
1748 
1749 
1750  }
1751  break;
1752 
1753  case EBubble:{
1754 
1755  disp[0] = xloc[0]*xloc[1]*xloc[2]*(TVar(1.)-xloc[0])*(TVar(1.)-xloc[1])*(TVar(1.)-xloc[2]);
1756  // std::cout<<"pto "<<xloc <<" f(x) "<<disp<<std::endl;
1757 
1758  }
1759  break;
1760 
1761  case ESinCosCircle:{
1762 
1763  TVar coef = pow(r, TVar(4.));
1764  TVar theta=FADatan2(xloc[1],xloc[0]);
1765  disp[0] = coef*FADsin(TVar(2.)*theta)*FADcos(TVar(2.)*theta);
1766 
1767 
1768  }
1769  break;
1770 
1771  case EHarmonic:
1772  disp[0] = FADexp(M_PI*x[0])*FADsin(M_PI*x[1]);
1773  break;
1774 
1775  default:
1776  disp[0] = xloc[0]*0.;
1777  break;
1778  }
1779 
1780 }
1781 
1782 void TLaplaceExample1::setPermeabilyTensor(TPZFNMatrix<9,REAL> K, TPZFNMatrix<9,REAL> invK)
1783 {
1784  fTensorPerm = K;
1785  fInvPerm = invK;
1786 }
1787 
1788 template<class TVar>
1789 void TLaplaceExample1::Permeability(const TPZVec<TVar> &x, TVar &Perm)
1790 {
1791  Perm = (TVar)(1.);
1792 }
1793 
1794 void TLaplaceExample1::PermeabilityDummy(const TPZVec<REAL> &x, TPZVec<STATE> &result, TPZFMatrix<STATE> &deriv)
1795 {
1796  TPZManVector<STATE,3> xloc(x.size());
1797  for (unsigned int i = 0; i<xloc.size(); ++i) {
1798  xloc[i] = x[i];
1799  }
1800  STATE Perm;
1801  Permeability(xloc, Perm);
1802  deriv.Zero();
1803  deriv(0,0) = Perm;
1804  deriv(1,1) = Perm;
1805  deriv(2,2) = Perm;
1806  deriv(3,0) = 1./Perm;
1807  deriv(4,1) = 1./Perm;
1808  deriv(5,2) = 1./Perm;
1809 }
1810 
1811 template<class TVar>
1812 void TLaplaceExample1::graduxy(const TPZVec<TVar> &x, TPZVec<TVar> &grad) const
1813 {
1814  TPZManVector<Fad<TVar>,3> xfad(x.size());
1815  for(int i=0; i<3; i++)
1816  {
1817  Fad<TVar> temp = Fad<TVar>(3,i,x[i]);
1818  xfad[i] = temp;
1819  }
1820  TPZManVector<Fad<TVar>,3> result(1);
1821  uxy(xfad,result);
1822  grad.resize(3);
1823  for (int i=0; i<3; i++)
1824  {
1825  grad[i] = result[0].d(i);
1826  }
1827 }
1828 
1829 template<>
1830 void TLaplaceExample1::graduxy<Fad<STATE>>(const TPZVec<Fad<STATE>> &x, TPZVec<Fad<STATE>> &grad) const
1831 {
1832  typedef Fad<STATE> TVar;
1833  TPZManVector<Fad<TVar>,3> xfad(x.size());
1834  for(int i=0; i<3; i++)
1835  {
1836  Fad<TVar> temp = Fad<TVar>(3,i,x[i]);
1837  xfad[i] = temp;
1838  }
1839  TPZManVector<Fad<TVar>,3> result(1);
1840  uxy(xfad,result);
1841  grad.resize(3);
1842  for (int i=0; i<3; i++)
1843  {
1844  grad[i] = result[0].d(i);
1845  }
1846 }
1847 
1848 void TLaplaceExample1::Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const
1849 {
1850  TPZManVector<Fad<STATE>,3> xfad(x.size());
1851  for(int i=0; i<3; i++)
1852  {
1853  Fad<STATE> temp = Fad<STATE>(3,i,x[i]);
1854  xfad[i] = temp;
1855  }
1856  TPZManVector<Fad<STATE>,3> result(1);
1857  uxy(xfad,result);
1858  gradu.Redim(3,1);
1859 
1860 
1861  u[0] = result[0].val();
1862  for (int i=0; i<3; i++) {
1863  for (int j=0; j<1; j++)
1864  {
1865  gradu(i,j) = result[j].d(i);
1866  }
1867  }
1868 
1869 
1870 }
1871 
1872 template<class TVar>
1873 void TLaplaceExample1::SigmaLoc(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const
1874 {
1875  TPZManVector<TVar,3> grad;
1876  graduxy(x,grad);
1877  sigma.Resize(3,1);
1878 
1879  //Sigma_i = 1
1880  for(int rowIndex =0; rowIndex < 3 ; rowIndex++) sigma(rowIndex) =0;
1881 
1882  //Sigma = -K*grad[u]
1883  TVar Perm;
1884  for(int rowIndex =0; rowIndex < 3 ; rowIndex++) for(int colIndex=0; colIndex < 3; colIndex++)
1885  {
1886  Perm = (TVar) fTensorPerm.GetVal(rowIndex,colIndex);
1887  sigma(rowIndex) -= Perm*grad[colIndex];
1888  }
1889 }
1890 
1891 template<class TVar>
1892 void TLaplaceExample1::DivSigma(const TPZVec<REAL> &x, TVar &divsigma) const
1893 {
1894  TPZManVector<Fad<TVar>,3> xfad(x.size());
1895  for(int i=0; i<3; i++)
1896  {
1897  xfad[i] = Fad<TVar>(3,i,x[i]);
1898  }
1899  TPZFNMatrix<3,Fad<TVar> > sigma(3,1);
1900  SigmaLoc(xfad,sigma);
1901  divsigma = sigma(0).dx(0)+sigma(1).dx(1)+sigma(2).dx(2);
1902 
1903 }
1904 
1905 template
1906 void TLaplaceExample1::SigmaLoc(const TPZVec<STATE> &x, TPZFMatrix<STATE> &sigma) const;
1907 
1908 template
1909 void TLaplaceExample1::DivSigma<STATE>(const TPZVec<REAL> &x, STATE &divsigma) const;
1910 
1911 template
1912 void TLaplaceExample1::graduxy<Fad<STATE>>(const TPZVec<Fad<STATE>> &x, TPZVec<Fad<STATE>> &grad) const;
1913 
1914 template
1915 void TLaplaceExample1::graduxy<STATE>(const TPZVec<STATE> &x, TPZVec<STATE> &grad) const;
1916 
1917 
1918 
1919 //ExactFunc *Exact();
1920 
1921 
1922 template<class TVar>
1923 void TLaplaceExampleTimeDependent::uxy(const TPZVec<TVar> &x, TPZVec<TVar> &disp) const
1924 {
1925  switch(fProblemType)
1926  {
1927  case ELinear:
1928  disp[0] = x[0];
1929  break;
1930  case ESin:
1931  disp[0] = sin(M_PI*x[0])*sin(M_PI*x[1])*exp(-2.*M_PI*M_PI*fTime);
1932  break;
1933  case ECos:
1934  disp[0] = cos(M_PI_2*x[0])*cos(M_PI_2*x[1])*exp(-M_PI*M_PI_2*fTime);
1935  break;
1936  default:
1937  DebugStop();
1938  }
1939 }
1940 
1941 template<>
1942 void TLaplaceExampleTimeDependent::uxy(const TPZVec<FADFADSTATE > &x, TPZVec<FADFADSTATE > &disp) const
1943 {
1944  switch(fProblemType)
1945  {
1946  case ELinear:
1947  disp[0] = x[0];
1948  break;
1949  case ESin:
1950  disp[0] = FADsin(M_PI*x[0])*FADsin(M_PI*x[1])*FADexp(-2.*M_PI*M_PI*fTime);
1951  break;
1952  case ECos:
1953  disp[0] = FADcos(M_PI_2*x[0])*FADcos(M_PI_2*x[1])*FADexp(-M_PI*M_PI_2*fTime);
1954  break;
1955  default:
1956  DebugStop();
1957  }
1958 
1959 }
1960 
1961 template<class TVar>
1962 void TLaplaceExampleTimeDependent::Permeability(const TPZVec<TVar> &x, TVar &Perm) const
1963 {
1964  Perm = (TVar)(fK);
1965 }
1966 
1967 
1968 template<class TVar>
1969 void TLaplaceExampleTimeDependent::graduxy(const TPZVec<TVar> &x, TPZVec<TVar> &grad) const
1970 {
1971  TPZManVector<Fad<TVar>,3> xfad(x.size());
1972  for(int i=0; i<2; i++)
1973  {
1974  Fad<TVar> temp = Fad<TVar>(2,i,x[i]);
1975  xfad[i] = temp;
1976  }
1977  xfad[2] = x[2];
1978  TPZManVector<Fad<TVar>,3> result(1);
1979  uxy(xfad,result);
1980  grad.resize(2);
1981  for (int i=0; i<2; i++)
1982  {
1983  grad[i] = result[0].d(i);
1984  }
1985 }
1986 
1987 void TLaplaceExampleTimeDependent::Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const
1988 {
1989  TPZManVector<Fad<STATE>,3> xfad(x.size());
1990  for(int i=0; i<2; i++)
1991  {
1992  Fad<STATE> temp = Fad<STATE>(2,i,x[i]);
1993  xfad[i] = temp;
1994  }
1995  xfad[2] = x[2];
1996  TPZManVector<Fad<STATE>,3> result(2);
1997  uxy(xfad,result);
1998  gradu.Redim(2,1);
1999  u[0] = result[0].val();
2000  for (int i=0; i<2; i++) {
2001  for (int j=0; j<1; j++)
2002  {
2003  gradu(i,j) = result[j].d(i);
2004  }
2005  }
2006 
2007 }
2008 
2009 template<class TVar>
2010 void TLaplaceExampleTimeDependent::Sigma(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const
2011 {
2012  TPZManVector<TVar,3> grad;
2013  TVar Perm;
2014  Permeability(x, Perm);
2015  graduxy(x,grad);
2016  sigma.Resize(2,1);
2017  sigma(0) = -Perm*grad[0];
2018  sigma(1) = -Perm*grad[1];
2019 
2020 }
2021 
2022 
2023 void TLaplaceExampleTimeDependent::Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &sigma) const
2024 {
2025  typedef STATE TVar;
2026  TPZManVector<TVar,3> grad, xst(3);
2027  for(int i=0; i<3; i++) xst[i] = x[i];
2028  TVar Perm;
2029  Permeability(xst, Perm);
2030  graduxy(xst,grad);
2031  sigma.Resize(2,1);
2032  sigma(0) = -Perm*grad[0];
2033  sigma(1) = -Perm*grad[1];
2034 
2035 }
2036 
2037 template<class TVar>
2038 void TLaplaceExampleTimeDependent::DivSigma(const TPZVec<REAL> &x, TVar &divsigma) const
2039 {
2040  TPZManVector<Fad<TVar>,3> xfad(x.size());
2041  for(int i=0; i<2; i++)
2042  {
2043  xfad[i] = Fad<TVar>(2,i,x[i]);
2044  }
2045  TPZFNMatrix<3, Fad<TVar> > sigma(2,1);
2046  Sigma(xfad,sigma);
2047  divsigma = sigma(0).dx(0)+sigma(1).dx(1);
2048 
2049 }
2050 
2051 
2052 template
2053 void TLaplaceExampleTimeDependent::DivSigma(const TPZVec<REAL> &x, STATE &divsigma) const;
2054 
2055 
2056 template<class TVar>
2057 void TStokesAnalytic::uxy(const TPZVec<TVar> &x, TPZVec<TVar> &flux) const
2058 {
2059  TVar x1 = x[0];
2060  TVar x2 = x[1];
2061 
2062  switch(fExactSol)
2063  {
2064  case ESinCos:
2065  flux[0] = -1.*sin(x1)*sin(x2);
2066  flux[1] = -1.*cos(x1)*cos(x2);
2067  break;
2068  case EKovasznay:
2069  case EKovasznayCDG:
2070  flux[0] = 1. - exp(lambda*x1)*cos(2.*Pi*x2);
2071  flux[1] = (lambda/(2.*Pi))*exp(lambda*x1)*sin(2.*Pi*x2);
2072  break;
2073  case EPconst:
2074  flux[0] = x1;
2075  flux[1] = -x2;
2076  break;
2077  default:
2078  DebugStop();
2079  }
2080 }
2081 
2082 
2083 template<>
2084 void TStokesAnalytic::uxy(const TPZVec<FADFADSTATE > &x, TPZVec<FADFADSTATE > &flux) const
2085 {
2086  FADFADSTATE x1 = x[0];
2087  FADFADSTATE x2 = x[1];
2088 
2089  switch(fExactSol)
2090  {
2091  case ESinCos:
2092  flux[0] = -1.*FADsin(x1)*FADsin(x2);
2093  flux[1] = -1.*FADcos(x1)*FADcos(x2);
2094  break;
2095  case EKovasznay:
2096  case EKovasznayCDG:
2097  flux[0] = 1. - FADexp(lambda*x1)*FADcos(2.*Pi*x2);
2098  flux[1] = (lambda/(2.*Pi))*FADexp(lambda*x1)*FADsin(2.*Pi*x2);
2099  break;
2100  case EPconst:
2101  flux[0] = x1;
2102  flux[1] = -x2;
2103  break;
2104  default:
2105  DebugStop();
2106  }
2107 
2108 }
2109 
2110 template<class TVar>
2111 void TStokesAnalytic::pressure(const TPZVec<TVar> &x, TVar &p) const
2112 {
2113  TVar x1 = x[0];
2114  TVar x2 = x[1];
2115  TPZVec<TVar> flux(2,0.);
2116 
2117  switch(fExactSol)
2118  {
2119  case ESinCos:
2120  p = cos(x1)*sin(x2);
2121  break;
2122  case EKovasznay:
2123  p = -(1./2.)*exp(2.*lambda*x1);
2124  break;
2125  case EKovasznayCDG:
2126  flux[0] = 1. - exp(lambda*x1)*cos(2.*Pi*x2);
2127  flux[1] = (lambda/(2.*Pi))*exp(lambda*x1)*sin(2.*Pi*x2);
2128  p = -(1./2.)*exp(2.*lambda*x1);
2129  p += (1./2.)*(flux[0]*flux[0]+flux[1]*flux[1]);
2130  break;
2131  case EPconst:
2132  p = 0;
2133  break;
2134  default:
2135  DebugStop();
2136  }
2137 }
2138 
2139 template<>
2140 void TStokesAnalytic::pressure(const TPZVec<FADFADSTATE > &x, FADFADSTATE &p) const
2141 {
2142  FADFADSTATE x1 = x[0];
2143  FADFADSTATE x2 = x[1];
2144  TPZVec<FADFADSTATE > flux(2,0.);
2145 
2146  switch(fExactSol)
2147  {
2148  case ESinCos:
2149  p = FADcos(x1)*FADsin(x2);
2150  break;
2151  case EKovasznay:
2152  p = -(1./2.)*FADexp(2.*lambda*x1);
2153  break;
2154  case EKovasznayCDG:
2155  flux[0] = 1. - FADexp(lambda*x1)*FADcos(2.*Pi*x2);
2156  flux[1] = (lambda/(2.*Pi))*FADexp(lambda*x1)*FADsin(2.*Pi*x2);
2157  p = -(1./2.)*FADexp(2.*lambda*x1);
2158  p += (1./2.)*(flux[0]*flux[0]+flux[1]*flux[1]);
2159  break;
2160  case EPconst:
2161  p = 0;
2162  break;
2163  default:
2164  DebugStop();
2165  }
2166 
2167 }
2168 
2169 template<class TVar>
2170 void TStokesAnalytic::graduxy(const TPZVec<TVar> &x, TPZFMatrix<TVar> &gradu) const
2171 {
2172  TPZManVector<Fad<TVar>,3> xfad(x.size());
2173  for(int i=0; i<2; i++)
2174  {
2175  Fad<TVar> temp = Fad<TVar>(2,i,x[i]);
2176  xfad[i] = temp;
2177  }
2178  xfad[2] = x[2];
2179  TPZManVector<Fad<TVar>,3> result(2);
2180  uxy(xfad,result);
2181  gradu.Redim(3,3);
2182  for (int i=0; i<2; i++) {
2183  for (int j=0; j<2; j++)
2184  {
2185  gradu(i,j) = result[i].d(j);
2186  }
2187  }
2188 }
2189 
2190 template<class TVar>
2191 void TStokesAnalytic::Duxy(const TPZVec<TVar> &x, TPZFMatrix<TVar> &Du) const
2192 {
2193  TPZFMatrix<TVar> grad(3,3,0.), gradT(3,3,0.);
2194  graduxy(x,grad);
2195  grad.Transpose(&gradT);
2196  for(int i=0; i<3; i++)
2197  {
2198  for(int j=0; j<3; j++)
2199  {
2200  Du(i,j) = 0.5*(grad(i,j)+gradT(i,j));
2201  }
2202  }
2203 }
2204 
2205 
2206 template<class TVar>
2207 void TStokesAnalytic::SigmaLoc(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const
2208 {
2209  TPZFMatrix<TVar> Du, pIdentity(sigma.Rows(),sigma.Cols());
2210  TVar p=0.;
2211  Duxy(x,Du);
2212 
2213  for(int i=0; i<Du.Rows(); i++)
2214  {
2215  for(int j=0; j<Du.Cols(); j++)
2216  {
2217  Du(i,j) *= 2.*fvisco;
2218  }
2219  }
2220  pressure(x, p);
2221  for (int i=0; i< pIdentity.Rows(); i++) {
2222  pIdentity(i,i) = p;
2223  }
2224  sigma = Du-pIdentity;
2225 }
2226 
2227 template<class TVar>
2228 void TStokesAnalytic::Sigma(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const
2229 {
2230  TPZFMatrix<TVar> Du(sigma.Rows(),sigma.Cols()), pIdentity(sigma.Rows(),sigma.Cols());
2231  TVar p=0.;
2232  Duxy(x,Du);
2233  for(int i=0; i<Du.Rows(); i++)
2234  {
2235  for(int j=0; j<Du.Cols(); j++)
2236  {
2237  Du(i,j) *= 2.*fvisco;
2238  }
2239  }
2240  pressure(x, p);
2241  for (int i=0; i< pIdentity.Rows(); i++) {
2242  pIdentity(i,i) = p;
2243  }
2244 
2245  for(int i=0; i<sigma.Rows(); i++)
2246  {
2247  for(int j=0; j<sigma.Cols(); j++)
2248  {
2249  sigma(i,j) = Du(i,j)-pIdentity(i,j);
2250  }
2251  }
2252 
2253 }
2254 
2255 
2256 void TStokesAnalytic::Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &sigma) const
2257 {
2258  typedef STATE TVar;
2259  TPZFMatrix<TVar> Du, pIdentity(sigma.Rows(),sigma.Cols());
2260  TVar p=0.;
2261  TPZManVector<STATE,3> xstate(3);
2262  for(int i=0; i<3; i++) xstate[i] = x[i];
2263  Duxy(xstate,Du);
2264  for(int i=0; i<Du.Rows(); i++)
2265  {
2266  for(int j=0; j<Du.Cols(); j++)
2267  {
2268  Du(i,j) *= 2.*fvisco;
2269  }
2270  }
2271  pressure(xstate, p);
2272  for (int i=0; i< pIdentity.Rows(); i++) {
2273  pIdentity(i,i) = p;
2274  }
2275  sigma = Du-pIdentity;
2276 
2277 }
2278 
2279 
2280 
2281 
2282 template
2283 void TStokesAnalytic::SigmaLoc(const TPZVec<STATE> &x, TPZFMatrix<STATE> &sigma) const;
2284 
2285 
2286 template<class TVar>
2287 void TStokesAnalytic::DivSigma(const TPZVec<REAL> &x, TPZVec<TVar> &divsigma) const
2288 {
2289  int sz = x.size();
2290  TPZManVector<Fad<TVar>,3> xfad(sz);
2291  for(int i=0; i<sz; i++)
2292  {
2293  xfad[i] = Fad<TVar>(sz,i,x[i]);
2294  }
2295  TPZFNMatrix<9, Fad<TVar> > sigma(3,3);
2296  Sigma(xfad,sigma);
2297  for (int i=0; i<3; i++) {
2298  divsigma[i] = sigma(i,0).dx(0)+sigma(i,1).dx(1)+sigma(i,2).dx(2);
2299  }
2300 }
2301 
2302 template
2303 void TStokesAnalytic::DivSigma(const TPZVec<REAL> &x, TPZVec<STATE> &divsigma) const;
2304 
2305 void TStokesAnalytic::Force(const TPZVec<REAL> &x, TPZVec<STATE> &force) const
2306 {
2307 
2308  TPZManVector<STATE,3> locforce(3,0.),beta(3,0.),gradU_beta(3,0.),gradUt_beta(3,0.),xst(3);
2309  TPZFMatrix<STATE> grad(3,3,0.);
2310  for(int i=0; i<3; i++) xst[i] = x[i];
2311  DivSigma(x, locforce);
2312 
2313  switch(fProblemType)
2314  {
2315  case EStokes:
2316  force[0] = -locforce[0];
2317  force[1] = -locforce[1];
2318  force[2] = -locforce[2];
2319  break;
2320 
2321  case ENavierStokes:
2322  case EOseen:
2323 
2324  graduxy(xst,grad);
2325  uxy(xst,beta);
2326 
2327  for (int e=0; e<3; e++) {
2328  for (int f=0; f<3; f++) {
2329  gradU_beta[e] += grad(e,f)*beta[f];
2330  }
2331  }
2332 
2333  force[0] = -locforce[0]+gradU_beta[0];
2334  force[1] = -locforce[1]+gradU_beta[1];
2335  force[2] = -locforce[2]+gradU_beta[2];
2336  break;
2337 
2338  case ENavierStokesCDG:
2339  case EOseenCDG:
2340 
2341  graduxy(xst,grad);
2342  uxy(xst,beta);
2343 
2344  for (int e=0; e<3; e++) {
2345  for (int f=0; f<3; f++) {
2346  gradU_beta[e] += grad(e,f)*beta[f];
2347  }
2348  }
2349 
2350  for (int e=0; e<3; e++) {
2351  for (int f=0; f<3; f++) {
2352  gradUt_beta[e] += grad(f,e)*beta[f];
2353  }
2354  }
2355 
2356  force[0] = -locforce[0]+gradU_beta[0]-gradUt_beta[0];
2357  force[1] = -locforce[1]+gradU_beta[1]-gradUt_beta[1];
2358  force[2] = -locforce[2]+gradU_beta[2]-gradUt_beta[2];
2359  break;
2360 
2361  default:
2362  DebugStop();
2363  }
2364 
2365 
2366 
2367 }
2368 
2369 void TStokesAnalytic::Solution(const TPZVec<REAL> &x, TPZVec<STATE> &sol, TPZFMatrix<STATE> &gradsol) const
2370 {
2371 // TPZManVector<STATE> xst(3);
2372 // for(int i=0; i<3; i++) xst[i] = x[i];
2373 // uxy(xst,u);
2374 // graduxy(xst,gradu);
2375 
2376  TPZManVector<Fad<STATE>,3> xfad(x.size());
2377  for(int i=0; i<3; i++)
2378  {
2379  Fad<STATE> temp = Fad<STATE>(3,i,x[i]);
2380  xfad[i] = temp;
2381  }
2382  TPZManVector<Fad<STATE>,3> u_result(3);
2383  uxy(xfad,u_result);
2384  gradsol.Redim(3,3);
2385  sol.resize(4);
2386  for (int i = 0; i < 3; i++) {
2387  sol[i] = u_result[i].val();
2388  }
2389  for(int i=0; i<fDimension; i++) {
2390  for (int j=0; j<fDimension; j++)
2391  {
2392  gradsol(i,j) = u_result[j].d(i);
2393  }
2394  }
2395  Fad<STATE> p_result = 0.;
2396  pressure(xfad, p_result);
2397  sol[3] = p_result.val();
2398 
2399 }
2400 
2401 #endif
Definition: pzreal.h:105
int fSignConvention
integer to correct for the sign convention of the forcing term
TPZFlopCounter atan2(const TPZFlopCounter &val1, const TPZFlopCounter &val2)
Returns the arc tangent in radians and increments the counter of the Arc Tangent. ATAN2 returns the ...
Definition: pzreal.h:544
Definition: pzreal.h:105
Contains TPZAnalysis class which implements the sequence of actions to perform a finite element analy...
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.
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
REAL val() const
Definition: pzreal.h:280
virtual void resize(const int64_t newsize)
Definition: pzvec.h:213
int size() const
Definition: fad.h:127
Contains declaration of TPZCheckGeom class which performs a series of consistency tests on geometric ...
T & fastAccessDx(int i)
Definition: fad.h:117
Definition: fad.h:54
clarg::argBool h("-h", "help message", false)
TinyFad< 8, T > abs(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:846
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
AutoPointerMutexArrayInit tmp
Contains the TPZSymetricSpStructMatrix class which implements sparse structural matrices.
REAL const Pi
Definition: main.cpp:91
TPZAnalyticSolution & operator=(const TPZAnalyticSolution &copy)
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
sin
Definition: fadfunc.h:63
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
f
Definition: test.py:287
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ cosh
Definition: tfadfunc.h:90
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
Contains the TPZSkylineStructMatrix class which implements SkyLine Structural Matrices.
Contains the declaration of the TPZBuildmultiphysicsMesh class.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
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
const T & val() const
Definition: fad.h:112
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
static REAL angle
Angle in radians to test.
Definition: pzsubcmesh.cpp:53
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
Definition: pzreal.h:487
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sinh
Definition: tfadfunc.h:95
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ atan
Definition: tfadfunc.h:85
Contains TPZStepSolver class which defines step solvers class.
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ exp
Definition: tfadfunc.h:125
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
Contains the TPZVTKGeoMesh class which implements the graphical mesh to VTK environment to geometric ...
const Vector< T > & dx() const
Definition: fad.h:110
TPZFlopCounter cos(const TPZFlopCounter &orig)
Returns the cosine in radians and increments the counter of the Cosine.
Definition: pzreal.h:514
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
Definition: pzfmatrix.h:566
Contains the TPZRefPatternTools class which defines tools of pattern.
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716