NeoPZ
TPZAnalyticSolution.h
Go to the documentation of this file.
1 
2 #ifndef TPZANALYTICSOLUTION
3 #define TPZANALYTICSOLUTION
4 
5 #include "pzvec.h"
6 #include "tpzautopointer.h"
7 #include "pzcmesh.h"
8 #include "pzfunction.h"
9 
10 #include <string>
11 
12 
13 // typedef void (ExactFunc)(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu);
14 
16 {
17 
19  int fSignConvention = 1;
20 
21  TPZAnalyticSolution() : fSignConvention(1){
22 
23  }
24 
26 
28 
29  class TForce : public TPZFunction<STATE>
30  {
32 
33  public:
34  TForce(const TPZAnalyticSolution *root) : fAnalytic(root)
35  {
36  }
37 
38  virtual ~TForce()
39  {
40 
41  }
43  virtual void Execute(const TPZVec<REAL> &x, TPZVec<STATE> &f){
44  fAnalytic->Force(x,f);
45  for(auto &it:f) it *= fAnalytic->fSignConvention;
46  }
48  virtual void Execute(const TPZVec<REAL> &x, TPZVec<STATE> &f, TPZFMatrix<STATE> &nada){
49  fAnalytic->Force(x,f);
50  for(auto &it:f) it *= fAnalytic->fSignConvention;
51  }
52 
55  virtual int PolynomialOrder() const {
56  return 5;
57  }
58 
59  };
60 
61  class Tensor : public TPZFunction<STATE>
62  {
64 
65  public:
66  Tensor(TPZAnalyticSolution *root) : fAnalytic(root)
67  {
68 
69  }
70 
71  virtual ~Tensor()
72  {
73 
74  }
81  virtual void Execute(const TPZVec<REAL> &x, TPZVec<STATE> &f, TPZFMatrix<STATE> &df)
82  {
83  fAnalytic->Sigma(x,df);
84  TPZFNMatrix<9,STATE> dsol(df);
85  fAnalytic->Solution(x, f, dsol);
86  }
89  virtual int PolynomialOrder() const
90  {
91  return 5;
92  }
93 
94  };
95 
96  class TExactState : public TPZFunction<STATE>
97  {
99 
100  public:
101  TExactState(const TPZAnalyticSolution *root) : fAnalytic(root)
102  {
103 
104  }
105  virtual ~TExactState()
106  {
107 
108  }
115  virtual void Execute(const TPZVec<REAL> &x, TPZVec<STATE> &f, TPZFMatrix<STATE> &df)
116  {
117  fAnalytic->Solution(x,f,df);
118  }
125  virtual void Execute(const TPZVec<REAL> &x, TPZVec<STATE> &f)
126  {
127  TPZFNMatrix<9,STATE> df(3,3);
128  fAnalytic->Solution(x,f,df);
129  }
132  virtual int PolynomialOrder() const
133  {
134  return 5;
135  }
136 
137  };
138 
140  {
141  return new TForce(this);
142  };
143 
145  {
146  return new TExactState(this);
147  };
148 
149  std::function<void (const TPZVec<REAL> &loc, TPZVec<STATE> &result, TPZFMatrix<STATE> &deriv)> ExactSolution() const
150  {
151  return [this](const TPZVec<REAL> &loc, TPZVec<STATE> &result, TPZFMatrix<STATE> &deriv)
152  {
153  this->Solution(loc,result,deriv);
154  };
155  }
156 
158  {
159  return new Tensor(this);
160  }
161 
163  {
164 
165  }
166 
167  virtual void Force(const TPZVec<REAL> &x, TPZVec<STATE> &force) const = 0;
168 
169  virtual void Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const = 0;
170 
171  virtual void Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &tensor) const = 0;
172 };
173 
174 #ifdef _AUTODIFF
175 
176 struct TElasticity2DAnalytic : public TPZAnalyticSolution
177 {
178  enum EDefState {ENone, EDispx, EDispy, ERot, EStretchx, EUniAxialx, EStretchy, EShear, EBend, ELoadedBeam, Etest1, Etest2, EThiago, EPoly,
179  ESquareRootUpper, ESquareRootLower, ESquareRoot
180  };
181 
182  EDefState fProblemType = EDispx;
183 
186  int fPlaneStress = 1;
187 
188  static REAL gE;
189 
190  static REAL gPoisson;
191 
192  static int gOscilatoryElasticity;
193 
194  virtual void Force(const TPZVec<REAL> &x, TPZVec<STATE> &force) const
195  {
196  TPZManVector<STATE,3> xstate(3),locforce(2);
197  for(int i=0; i<3; i++) xstate[i]=x[i];
198  DivSigma(x, locforce);
199  force[0] = -locforce[0];
200  force[1] = -locforce[1];
201  }
202 
203  virtual void GradU(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const;
204 
205 
206  virtual ~TElasticity2DAnalytic()
207  {
208 
209  }
210  TElasticity2DAnalytic() : TPZAnalyticSolution(), fProblemType(ENone), fPlaneStress(1)
211  {
212 
213  }
214 
215  TElasticity2DAnalytic(const TElasticity2DAnalytic &cp);
216 
217  TElasticity2DAnalytic &operator=(const TElasticity2DAnalytic &copy);
218 
219  static TPZAutoPointer<TPZFunction<STATE> > ConstitutiveLawFunction()
220  {
222  TPZDummyFunction<STATE> *dummy = new TPZDummyFunction<STATE>(TElasticity2DAnalytic::ElasticDummy,4);
223  //dummy->SetPolynomialOrder(4);
224  result = TPZAutoPointer<TPZFunction<STATE> >(dummy);
225  return result;
226  }
227 
228  void Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &sigma) const;
229 
230  void Sigma(const TPZVec<Fad<STATE> > &x, TPZFMatrix<Fad<STATE> > &sigma) const;
231 
232  template<class TVar>
233  void DivSigma(const TPZVec<REAL> &x, TPZVec<TVar> &divsigma) const;
234 
235  template<typename TVar1, typename TVar2>
236  void uxy(const TPZVec<TVar1> &x, TPZVec<TVar2> &disp) const;
237 
238  template<typename TVar1, typename TVar2>
239  void graduxy(const TPZVec<TVar1> &x, TPZFMatrix<TVar2> &grad) const {
240  TPZManVector<Fad<TVar1>,3> xfad(x.size());
241  for(int i=0; i<2; i++)
242  {
243  Fad<TVar1> temp = Fad<TVar1>(2,i,x[i]);
244  xfad[i] = temp;
245 
246  }
247  xfad[2] = x[2];
248  TPZManVector<Fad<TVar2>,3> result(2);
249  uxy(xfad,result);
250  grad.Resize(2,2);
251  for (int i=0; i<2; i++) {
252  for (int j=0; j<2; j++)
253  {
254  grad(j,i) = result[i].d(j);
255  }
256  }
257  }
258 
259  template<typename TVar>
260  static void Elastic(const TPZVec<TVar> &x, TVar &Elast, TVar &nu);
261 
262  static void ElasticDummy(const TPZVec<REAL> &x, TPZVec<STATE> &result, TPZFMatrix<STATE> &deriv);
263 
264  virtual void Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const;
265 
266 };
267 
268 struct TElasticity3DAnalytic : public TPZAnalyticSolution
269 {
270  enum EDefState {ENone, EDispx, EDispy, ERot, EStretchx, EUniAxialx, EStretchy, EShear, EBend, ELoadedBeam, Etest1,Etest2, ETestShearMoment, ESphere };
271 
272  EDefState fProblemType = ENone;
273 
274  REAL fE = 1.;
275 
276  REAL fPoisson = 0.3;
277 
278  virtual void Force(const TPZVec<REAL> &x, TPZVec<STATE> &force) const
279  {
280  TPZManVector<STATE,3> locforce(3);
281  DivSigma(x, locforce);
282  force[0] = -locforce[0];
283  force[1] = -locforce[1];
284  force[2] = -locforce[2];
285  }
286 
287  virtual void Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const;
288 
289  TElasticity3DAnalytic() : TPZAnalyticSolution(), fProblemType(ENone)
290  {
291 
292  }
293 
294  virtual ~TElasticity3DAnalytic()
295  {
296 
297  }
298 
299  TElasticity3DAnalytic (const TElasticity3DAnalytic &cp);
300 
301  TElasticity3DAnalytic &operator=(const TElasticity3DAnalytic &copy);
302 
303  template<class TVar>
304  void Sigma(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const;
305 
306  virtual void Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &tensor) const;
307 
308  template<class TVar>
309  void DivSigma(const TPZVec<REAL> &x, TPZVec<TVar> &divsigma) const;
310 
311  template<class TVar>
312  void uxy(const TPZVec<TVar> &x, TPZVec<TVar> &disp) const;
313 
314  template<class TVar>
315  void graduxy(const TPZVec<TVar> &x, TPZFMatrix<TVar> &grad) const;
316 
317  template<class TVar>
318  void Elastic(const TPZVec<TVar> &x, TVar &Elast, TVar &nu) const;
319 
320  static void ElasticDummy(const TPZVec<REAL> &x, TPZVec<STATE> &result, TPZFMatrix<STATE> &deriv);
321 
322 };
323 
324 
325 struct TLaplaceExample1 : public TPZAnalyticSolution
326 {
327 
328  enum EExactSol {ENone, EConst, EX, ESinSin, ECosCos, EArcTan, EArcTanSingular,ESinDist, E10SinSin,E2SinSin, ESinSinDirNonHom,ESinMark,ESteklovNonConst,EGalvisNonConst,EBoundaryLayer,EBubble,ESinCosCircle, EHarmonic};
329 
330  int fDimension = 2;
331 
332  EExactSol fExact = EArcTan;
333 
334  TPZManVector<REAL,3> fCenter;
335 
336  TPZFNMatrix<9,REAL> fTensorPerm;
337 
338  TPZFNMatrix<9,REAL> fInvPerm;
339 
340  TLaplaceExample1() : fCenter(3,0.), TPZAnalyticSolution()
341  {
342  fTensorPerm = fInvPerm = {{1,0,0},{0,1,0},{0,0,1}};
343  }
344 
345  TLaplaceExample1(TPZFNMatrix<9,REAL> K, TPZFNMatrix<9,REAL> invK): fCenter(3,0.), TPZAnalyticSolution()
346  {
347  fTensorPerm = K;
348  fInvPerm =invK;
349  }
350 
351  void setPermeabilyTensor(TPZFNMatrix<9,REAL> K, TPZFNMatrix<9,REAL> invK);
352 
353  virtual ~TLaplaceExample1()
354  {
355  fExact = ENone;
356  fDimension = -1;
357  }
358 
359  TLaplaceExample1(const TLaplaceExample1 &cp);
360 
361  TLaplaceExample1 &operator=(const TLaplaceExample1 &copy);
362 
363  virtual void Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const;
364 
365 
366  template<class TVar>
367  void uxy(const TPZVec<TVar> &x, TPZVec<TVar> &disp) const;
368 
369  template<class TVar>
370  void graduxy(const TPZVec<TVar> &x, TPZVec<TVar> &grad) const;
371 
372  template<class TVar>
373  static void Permeability(const TPZVec<TVar> &x, TVar &Elast);
374 
375  static void PermeabilityDummy(const TPZVec<REAL> &x, TPZVec<STATE> &result, TPZFMatrix<STATE> &deriv);
376 
377  template<class TVar>
378  void SigmaLoc(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const;
379 
380  template<class TVar>
381  void DivSigma(const TPZVec<REAL> &x, TVar &divsigma) const;
382 
383 
384  virtual void Force(const TPZVec<REAL> &x, TPZVec<STATE> &force) const
385  {
386  STATE locforce;
387  DivSigma(x, locforce);
388  force[0] = locforce;
389  }
390 
391  virtual void Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &tensor) const
392  {
393  TPZManVector<STATE,3> xco(3);
394  for (int i=0; i<3; i++) {
395  xco[i] = x[i];
396  }
397  SigmaLoc<STATE>(xco,tensor);
398  }
399 
400 };
401 
402 class TLaplaceExampleTimeDependent : public TPZAnalyticSolution
403 {
404 
405 public:
406 
407  enum MProblemType {ENone, ELinear, ESin, ECos};
408 
409  MProblemType fProblemType = ESin;
410 
411  REAL fTime = 0.; // time
412 
413  REAL fDelt = 0.1; // timestep
414 
415  REAL fK = 1.; // permeability
416 
417  virtual ~TLaplaceExampleTimeDependent()
418  {
419 
420  }
421 
422  void Solution(const TPZVec<REAL> &x, TPZVec<STATE> &u, TPZFMatrix<STATE> &gradu) const;
423 
424 
425  template<class TVar>
426  void uxy(const TPZVec<TVar> &x, TPZVec<TVar> &disp) const;
427 
428  template<class TVar>
429  void graduxy(const TPZVec<TVar> &x, TPZVec<TVar> &grad) const;
430 
431  template<class TVar>
432  void Permeability(const TPZVec<TVar> &x, TVar &Elast) const;
433 
434 
435  template<class TVar>
436  void Sigma(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const;
437 
438  virtual void Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &sigma) const;
439 
440  template<class TVar>
441  void DivSigma(const TPZVec<REAL> &x, TVar &divsigma) const;
442 
443  virtual void Force(const TPZVec<REAL> &x, TPZVec<STATE> &force) const
444  {
445  REAL locforce = 0;
446  force[0] = locforce;
447  }
448 
449 };
450 
451 struct TStokesAnalytic : public TPZAnalyticSolution
452 {
453 
454  enum MProblemType {EStokes, ENavierStokes, EOseen, ENavierStokesCDG, EOseenCDG, EBrinkman};
455 
456  enum EExactSol {ENone, ECavity, EKovasznay, EKovasznayCDG, ESinCos, EPconst, EObstacles, EOneCurve ,EStokesLimit, EDarcyLimit};
457 
458  int fDimension = 2;
459 
460  MProblemType fProblemType = EStokes;
461 
462  EExactSol fExactSol = ESinCos;
463 
464  REAL fvisco = 1.; //Viscosity
465 
466  REAL Pi = M_PI;
467 
468  REAL Re = 1./fvisco; //Reynolds number
469 
470  REAL lambda = Re/2.- sqrt(Re*Re/4.+4.*Pi*Pi); // Parameter for Navier-Stokes solution
471 
472  REAL falphaBrinkman = 1.;
473 
474  TPZManVector<REAL,3> fCenter;
475 
476  TStokesAnalytic() : fCenter(3,0.), TPZAnalyticSolution()
477  {
478 
479  }
480 
481  virtual ~TStokesAnalytic()
482  {
483 
484  }
485 
486  virtual void Solution(const TPZVec<REAL> &x, TPZVec<STATE> &sol, TPZFMatrix<STATE> &dsol) const;
487 
488  template<class TVar>
489  void uxy(const TPZVec<TVar> &x, TPZVec<TVar> &flux) const;
490 
491  template<class TVar>
492  void pressure(const TPZVec<TVar> &x, TVar &p) const;
493 
494  template<class TVar>
495  void graduxy(const TPZVec<TVar> &x, TPZFMatrix<TVar> &grad) const;
496 
497  template<class TVar>
498  void Duxy(const TPZVec<TVar> &x, TPZFMatrix<TVar> &Du) const;
499 
500  template<class TVar>
501  void Sigma(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const;
502 
503  virtual void Sigma(const TPZVec<REAL> &x, TPZFMatrix<STATE> &sigma) const;
504 
505  template<class TVar>
506  void SigmaLoc(const TPZVec<TVar> &x, TPZFMatrix<TVar> &sigma) const;
507 
508  template<class TVar>
509  void DivSigma(const TPZVec<REAL> &x, TPZVec<TVar> &divsigma) const;
510 
511  virtual void Force(const TPZVec<REAL> &x, TPZVec<STATE> &force) const;
512 
513 
514 };
515 
516 #endif
517 
518 #endif
Definition: pzreal.h:105
int fSignConvention
integer to correct for the sign convention of the forcing term
TPZAutoPointer< TPZFunction< STATE > > ForcingFunction() const
TExactState(const TPZAnalyticSolution *root)
Definition: pzreal.h:105
TPZAutoPointer< TPZFunction< STATE > > TensorFunction()
Templated vector implementation.
virtual void Execute(const TPZVec< REAL > &x, TPZVec< STATE > &f, TPZFMatrix< STATE > &df)
Performs function computation.
std::function< void(const TPZVec< REAL > &loc, TPZVec< STATE > &result, TPZFMatrix< STATE > &deriv)> ExactSolution() const
Definition: fad.h:54
virtual void Execute(const TPZVec< REAL > &x, TPZVec< STATE > &f)
Performs function computation.
Implements a function. Utility.
Definition: pzfunction.h:19
virtual void Execute(const TPZVec< REAL > &x, TPZVec< STATE > &f, TPZFMatrix< STATE > &df)
Performs function computation.
REAL const Pi
Definition: main.cpp:91
TPZAutoPointer< TPZFunction< STATE > > Exact() const
virtual void Execute(const TPZVec< REAL > &x, TPZVec< STATE > &f, TPZFMatrix< STATE > &nada)
Simpler version of Execute method which does not compute function derivatives.
TPZAnalyticSolution & operator=(const TPZAnalyticSolution &copy)
virtual void Sigma(const TPZVec< REAL > &x, TPZFMatrix< STATE > &tensor) const =0
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
f
Definition: test.py:287
const TPZAnalyticSolution * fAnalytic
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
TPZAnalyticSolution * fAnalytic
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
virtual void Force(const TPZVec< REAL > &x, TPZVec< STATE > &force) const =0
Contains declaration of TPZCompMesh class which is a repository for computational elements...
virtual int PolynomialOrder() const
Polynomial order of this function.
const TPZAnalyticSolution * fAnalytic
Tensor(TPZAnalyticSolution *root)
virtual int PolynomialOrder() const
Polynomial order of this function.
virtual void Execute(const TPZVec< REAL > &x, TPZVec< STATE > &f)
Simpler version of Execute method which does not compute function derivatives.
virtual void Solution(const TPZVec< REAL > &x, TPZVec< STATE > &u, TPZFMatrix< STATE > &gradu) const =0
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
virtual int PolynomialOrder() const
Polynomial order of this function.
This class implements a reference counter mechanism to administer a dynamically allocated object...
TForce(const TPZAnalyticSolution *root)