NeoPZ
pzanalysiserror.cpp
Go to the documentation of this file.
1 
6 #include "pzanalysiserror.h"
7 #include <stdlib.h> // for exit
8 #include <cmath> // for log, pow, sqrt, fabs
9 #include <iostream> // for cout
10 #include "pzadmchunk.h" // for TPZAdmChunkVector
11 #include "pzblock.h" // for TPZBlock
12 #include "TPZChunkVector.h" // for TPZChunkVector
13 #include "pzcmesh.h" // for TPZCompMesh
14 #include "pzconnect.h" // for TPZConnect
15 #include "pzerror.h" // for PZError
16 #include "pzgeoel.h" // for TPZGeoEl
17 #include "pzgeoelside.h" // for TPZGeoElSide
18 #include "pzgmesh.h" // for TPZGeoMesh
19 #include "pzgnode.h" // for TPZGeoNode
20 #include "pzintel.h" // for TPZInterpolatedElement
21 #include "TPZMaterial.h" // for TPZMaterial
22 #include "pzmatrix.h" // for TPZFMatrix, TPZMatrix, DecomposeType::E...
23 #include "pzskylstrmatrix.h" // for TPZSkylineStructMatrix
24 #include "pzsolve.h" // for TPZMatrixSolver<>::MSolver, TPZSolver
25 #include "pzstepsolver.h" // for TPZStepSolver
26 #include "pzvec.h" // for TPZVec
27 #include <functional>
28 
29 using namespace std;
30 
31 TPZAnalysisError::TPZAnalysisError(TPZCompMesh *mesh,std::ostream &out) : TPZAnalysis(mesh,true,out),fElIndexes(0),fElErrors(0),
32 fSingular(),fTotalError(0.),fAdmissibleError(0.0),fEtaAdmissible(0.05),fNIterations(4) {}
33 
34 void TPZAnalysisError::SetAdaptivityParameters(REAL EtaAdmissible, int64_t NIterations) {
35  fEtaAdmissible = EtaAdmissible;
36  fNIterations = NIterations;
37 }
39 std::ofstream arq("Param.dat");
40 void TPZAnalysisError::hp_Adaptive_Mesh_Design(std::ostream &out,REAL &CurrentEtaAdmissible) {
41  int64_t iter = 0;//iteracao atual
42  cout << "\n\nIteration 1\n";
43  out << "\n Iteration 1\n";
44  Run(out);//solucao malha inicial
45  TPZManVector<REAL,3> errors(3);
46  errors.Fill(0.0);
47  TPZVec<REAL> flux(0);
48  bool store_error = false;
49  fNIterations--;
50  while(iter++ < fNIterations) {
51  arq << "\n iter = " << iter << endl;
52  CurrentEtaAdmissible = pow(fEtaAdmissible,sqrt((REAL)(iter*1./(fNIterations*1.))));//error admissivel corrigido
53  // Print data
54  PlotLocal(iter,CurrentEtaAdmissible,out);
55  //if more norms than 3 are available, the pzvec is resized in the material error method
56  Mesh()->EvaluateError(fExact,store_error, errors);
57  if (errors.NElements() < 3) {
58  PZError << endl << "TPZAnalysisError::hp_Adaptive_Mesh_Design - At least 3 norms are expected." << endl;
59  exit (-1);
60  }
61  out << " - Error Energy Norm : " << errors[0] << endl;
62  out << " - FE Sol Energy Norm : " << errors[1] << endl;
63  out << " - Ex Sol Energy Norm : " << errors[2] << endl;
64 
65  for(int ier = 3; ier < errors.NElements(); ier++)
66  out << "Other norms : " << errors[ier] << endl;
67 
68  out << " - Eta Admissible : " << CurrentEtaAdmissible << endl;
69  // out << " - Eta Reached : " << true_error/exactnorm << endl;
70  out << " - Eta Reached : " << errors[0]/errors[2] << endl;
71  //Code isn't place to chat
72  //#warning Philippe, nao entendo nada!!!!! //<!>
73  //#warning De fato Thiago, voce tem razao
74 
75  out << " - Number of D.O.F. : " << fCompMesh->NEquations() << endl;
76  out.flush();
77  HPAdapt(CurrentEtaAdmissible,out);//processa os restantes elementos ; (nadmerror)
81  SetStructuralMatrix(skystr);
83  sol.ShareMatrix(Solver());
84 
85  sol.SetDirect(ECholesky);//ECholesky
86  SetSolver(sol);
87  cout << "\n\nIteration " << (iter+1) << endl;
88  out << "\n Iteration " << (iter+1) << endl;
89  Run(out);
90  }
91  //Code isn't place to chat
92  //#warning Philippe, nao parece igual acima ?? //<!>
93  //#warning Olhar aqui //<!>
94  errors.Resize(3);
95  errors.Fill(0.0);
96 
97  PlotLocal(iter,CurrentEtaAdmissible,out);
98  Mesh()->EvaluateError(fExact,store_error, errors);
99 
100  if (errors.NElements() < 3) {
101  PZError << endl << "TPZAnalysisError::hp_Adaptive_Mesh_Design - At least 3 norms are expected." << endl;
102  exit (-1);
103  }
104 
105  out << " - Error Energy Norm : " << errors[0] << endl;
106  out << " - FE Sol Energy Norm : " << errors[1] << endl;
107  out << " - Ex Sol Energy Norm : " << errors[2] << endl;
108 
109  for(int ier = 3; ier < errors.NElements(); ier++)
110  out << "Other norms : " << errors[ier] << endl;
111 
112  out << " - Eta Admissible : " << CurrentEtaAdmissible << endl;
113  // out << " - Eta Reached : " << true_error/exactnorm << endl; <!>
114  out << " - Eta Reached : " << errors[0]/errors[2] << endl;
115  out << " - Number of D.O.F. : " << fCompMesh->NEquations() << endl;
116  out.flush();
117 }
118 
119 void TPZAnalysisError::PlotLocal(int64_t iter, REAL CurrentEtaAdmissible, std::ostream &out) {
120  bool store_error = false;
121  EvaluateError(CurrentEtaAdmissible,store_error, out);
122  TPZManVector<std::string> solution(1);
123  solution[0] = "Solution";
124  TPZVec<std::string> vecnames(0);
125  {
126  std::stringstream plotfile;
127  plotfile << "plot";
128  plotfile << '0' << iter;
129  plotfile << '\0';
130  plotfile << ".plt";
131  DefineGraphMesh(2, solution, vecnames, plotfile.str());
132  }
133  PostProcess(0);
134  solution.Resize(2);
135  solution[0] = "POrder";
136  solution[1] = "Error";
137  {
138  std::stringstream plotfile;
139  plotfile << "plop";
140  plotfile << '0' << iter;
141  plotfile << '\0';
142  plotfile << ".plt";
143  DefineGraphMesh(2, solution, vecnames, plotfile.str());
144  }
145  PostProcess(3);
146 }
147 
149  //point deve ser interior a algum elemento da malha
150 }
151 //SingularElements(..)
152 void TPZAnalysisError::ZoomInSingularity(REAL csi, TPZCompElSide elside, REAL singularity_strength) {
153 
154  REAL hn = 1./pow(csi,1./singularity_strength);
155  REAL Q=2.;
156  REAL NcReal = log( 1.+(1./hn - 1.)*(Q - 1.) )/log(Q);
157  int Nc = 0;
158  while(REAL(Nc) < (NcReal+0.5)) Nc++;
159  int minporder = 2;
160 
161  TPZStack<TPZCompElSide> ElToRefine;
162  TPZStack<int> POrder;
163  TPZStack<TPZGeoElSide> subelements;
164  TPZStack<int64_t> csubindex;
165  ElToRefine.Push(elside);
166  POrder.Push(Nc);
167  while(ElToRefine.NElements()) {
169  TPZCompElSide curelside = ElToRefine.Pop();
170  int curporder = POrder.Pop();
171  if(!curelside.Exists()) continue;
172  int64_t cindex = curelside.Element()->Index();
173  if(cindex < 0) continue;
174 
176  TPZCompEl *cel = curelside.Element();
177  TPZInterpolatedElement *cintel = 0;
178  cintel = dynamic_cast<TPZInterpolatedElement *> (cel);
180  if(!cintel) continue;
182  if(curporder == minporder) {
183  cintel->PRefine(Nc);
184  fSingular.Push(curelside);
185  } else {
186  cintel->PRefine(curporder);
187  cintel->Divide(cindex,csubindex,1);
189  }
190  TPZGeoElSide gelside = curelside.Reference();
191  if(!gelside.Exists()) continue;
192  gelside.GetSubElements2(subelements);
193  int64_t ns = subelements.NElements();
194  curporder--;
195  int64_t is;
196  for(is=0; is<ns; is++) {
197  TPZGeoElSide sub = subelements[is];
198  TPZCompElSide csub = sub.Reference();
199  if(csub.Exists()) {
200  ElToRefine.Push(csub);
201  POrder.Push(curporder);
202  }
203  }
204  }
206 
207  /*
208  REAL H1_error,L2_error,estimate;
209  TPZBlock *flux=0;
210  int64_t nel = fElIndexes.NElements();
211  for(int64_t elloc=0;elloc<nel;elloc++) {
212  int64_t el = fElIndexes[elloc];
213  estimate = fElErrors[elloc];
214  REAL csi = estimate / fAdmissibleError;
215  REAL h = h_Parameter(intellist[el]);
216  REAL hn = h/pow(csi,1./.9);
217  REAL Nc = log( 1.+(h/hn - 1.)*(Q - 1.) )/log(Q);
218  if(hn > 1.3*h) hn = 2.0*h*hn / (h + hn);
219  REAL hsub = h;//100.0;//pode ser = h ; Cedric
220  TPZCompEl *locel = intellist[el];
221  //obter um subelemento que contem o ponto singular e tem tamanho <= hn
222  TPZAdmChunkVector<TPZCompEl *> sublist;
223  while(hsub > hn) {
224  TPZVec<int64_t> indexsubs;
225  int64_t index = locel->Index();
226  locel->Divide(index,indexsubs,1);
227  int64_t nsub = indexsubs.NElements();
228  TPZAdmChunkVector<TPZCompEl *> listsub(0);
229  for(int64_t k=0;k<nsub;k++) {
230  index = listsub.AllocateNewElement();
231  listsub[index] = Mesh()->ElementVec()[indexsubs[k]];
232  }
233  //existe um unico filho que contem o ponto singular
234  SingularElement(point,listsub,sublist);
235  hsub = h_Parameter(sublist[0]);
236  }
237  TPZInterpolatedElement *intel = (TPZInterpolatedElement *) locel;
238  intel->PRefine(Nc+1);
239  indexlist.Push(intel->Index());
240  //os elemento viz devem ter ordens menores a cel quanto mais longe de point
241  TPZInterpolatedElement *neighkeep,*neigh;
242  //feito s�para o caso 1d , extender para o caso geral
243  int dim = intel->Dimension();
244  if(dim != 1) {
245  cout << "TPZAnalysisError::Step3 not dimension implemented , dimension = " << intellist[el]->Dimension() << endl;
246  return ;//exit(1);
247  }
248  for(int side=0;side<2;side++) {
249  int ly = 1;
250  TPZGeoElSide neighside = intel->Reference()->Neighbour(side);
251  TPZGeoElSide neighsidekeep = neighside;
252  TPZCompElSide neighsidecomp(0,0);
253  TPZStack<TPZCompElSide> elvec(0);
254  TPZCompElSide thisside(intel,side);
255  if(!neighsidekeep.Exists()) thisside.HigherLevelElementList(elvec,1,1);
256  if(!neighsidekeep.Exists() && elvec.NElements() == 0) {
257  neighsidekeep = thisside.LowerLevelElementList(1).Reference();
258  } else if(elvec.NElements() != 0) {
259  neighsidekeep = elvec[0].Reference();
260  }
261  while(ly < (Nc+1) && neighsidekeep.Exists() && neighsidekeep.Element()->Reference()->Material()->Id() > -1) {
262  neigh = (TPZInterpolatedElement *) neighsidekeep.Element()->Reference();
263  if(neigh) {
264  neigh->PRefine(ly);
265  int otherside = (neighsidekeep.Side()+1)%2;
266  neighsidekeep.SetSide(otherside);
267  indexlist.Push(neighsidekeep.Reference().Element()->Index());
268  }
269  neighside = neighsidekeep.Neighbour();
270  while(!neighside.Exists()) {
271  neighsidecomp = neighsidekeep.Reference();
272  neighsidecomp.HigherLevelElementList(elvec,1,1);
273  if(elvec.NElements()) {
274  neighside = elvec[0].Reference();
275  break;
276  }
277  neighside = neighsidecomp.LowerLevelElementList(1).Reference();
278  if(!neighside.Exists()) break;
279  }
280  neighsidekeep = neighside;
281  ly++;
282  }
283  }
284  }//for
285  Mesh()->InitializeBlock();
286  */
287 }
288 
289 //void DivideRecursive(TPZCompEl *locel,int index,TPZVec<int> indexsubs,int hn);
290 void TPZAnalysisError::HPAdapt(REAL CurrentEtaAdmissible, std::ostream &out) {
291 
292  arq << "CurrentEtaAdmissible " << CurrentEtaAdmissible << endl;
293 
295  bool store_error = false;
296  EvaluateError(CurrentEtaAdmissible,store_error, out);
297  TPZVec<TPZCompElSide> SingLocal(fSingular);
298  fSingular.Resize(0);
299 
300  int64_t nel = fElIndexes.NElements();
301  for(int64_t ielloc=0;ielloc<nel;ielloc++) {
302  int64_t iel = fElIndexes[ielloc];
303  // if the element has already been treated (e.g. singularity) skip the process
304  if(iel == -1) continue;
305  TPZInterpolatedElement *elem = (TPZInterpolatedElement *) listel[iel];
306  if(!elem || elem->Material()->Id() < 0) {
307  PZError << "TPZAnalysisError::HPAdapt boundary element with error?\n";
308  PZError.flush();
309  continue;
310  }
311  REAL csi = fElErrors[ielloc] / fAdmissibleError;
312  // Verificar se o element atual e um elemento singular
313  int64_t ising, nsing = SingLocal.NElements();
314  for(ising=0; ising<nsing; ising++) {
315  if(elem == SingLocal[ising].Element()) {
316  ZoomInSingularity(csi,SingLocal[ising]);
317  break;
318  }
319  }
320  // Go to the end of the loop if the element was handled by the singularity
321  if(ising < nsing) continue;
322  //calculo da ordem pn do elemento atual
323  int nsides = elem->Reference()->NSides();
324  REAL pFo = double(elem->EffectiveSideOrder(nsides-1));//quadrilatero
325 
326  // Newton's Method -> compute pNew
327  REAL pFn = pFo, res = 10.0, phi, del, dph, tol = 0.001;
328  int64_t MaxIter = 100; int64_t iter=0;
329  while (iter < MaxIter && res > tol) {
330  phi = pFo+log(csi)-pFo*log(pFn/pFo);
331  dph = pFn/(pFo+pFn);
332  del = dph*(phi-pFn);
333  if (del+pFn <= 0.0) // caiu fora do intervalo!
334  del = 0.5 - pFn;
335  res = fabs(del);
336  pFn = del+pFn;
337  iter++;
338  } // end of Newton's Method
339 
340  if (iter == MaxIter)
341  PZError << "\n - Newton's Method Failed at Element = " << elem->Reference()->Id() << endl;
342  if(pFn < 1.) pFn = 1.;
343  REAL factor = pow(csi,-1.0/pFn)*(pow(pFn/pFo,pFo/pFn));
344 
345  if(factor <= 0.75)
346  factor = 0.5; // refine h
347  else factor = 1.0; // don't refine h
348 
349  // Newton's Method -> compute once again pNew
350  pFn = pFo; iter = 0; res = 10.0;
351  while (iter < MaxIter && res > tol) {
352  phi = -pFn*log(factor)-log(csi)+pFo*log(pFn/pFo);
353  dph = pFn/(pFo-pFn*log(factor));
354  del = -dph*phi;
355  if (del+pFn <= 0.0) // caiu fora do intervalo!
356  del = 0.5 - pFn;
357  res = fabs(del);
358  pFn = del+pFn;
359  iter++;
360  } // end of Newton's Method
361 
362  if (iter == MaxIter)
363  PZError << "\n - Newton's Method Failed at Element = " << elem->Reference()->Id() << endl;
364  if(pFn < 1.) pFn = 1.;
365  int pNew = 0;//(int) floor(pFn + 0.5); // get the integer
366  while(REAL(pNew) < (pFn+0.5)) pNew++;
367  TPZVec<REAL> x(3),cs(2,0.);
368  elem->Reference()->X(cs,x);
369 
370  elem->PRefine(pNew);
371  TPZCompEl *locel = elem;
372  //Divide elements
373  if(factor == 0.5 ) {
374  TPZVec<int64_t> indexsubs;
375  int64_t index = locel->Index();
376  elem->Divide(index,indexsubs,1);
377  }
378  }
379 }
380 
381 
383 
384  REAL h = 0.,cicjdist;
385  TPZGeoEl *gel = cel->Reference();
386  int nconn = gel->NCornerNodes();
387  for(int conni=0;conni<nconn;conni++) {
388  for(int connj=conni;connj<nconn;connj++) {
389  cicjdist = 0.;
390  for(int coordi=0;coordi<3;coordi++) {
391  REAL coor1 = gel->NodePtr(conni)->Coord(coordi);
392  REAL coor2 = gel->NodePtr(connj)->Coord(coordi);
393  cicjdist += pow( coor1 - coor2, (REAL)2.0);
394  }
395  cicjdist = sqrt(cicjdist);
396  if(h < cicjdist) h = cicjdist;
397  }
398  }
399  return h;
400 }
401 
404 
406 
407  val[0] = 0.*point[0];
408  deriv(0,0) = 0.;
409  deriv(1,0) = 0.;
410 }
411 
413 
414  TPZGeoMesh *gmesh = fCompMesh->Reference();
415  TPZAdmChunkVector<TPZGeoNode> &listnodes = gmesh->NodeVec();
416  int64_t nnodes = gmesh->NNodes();
417  TPZAdmChunkVector<TPZGeoNode> nodes(listnodes);
418  TPZVec<int64_t> nodeindex(0);
419  int64_t keepindex;
420  int64_t in;
421  TPZGeoNode *nodei = 0;
422  for(in=0;in<nnodes;in++) {
423  nodei = &nodes[in];
424  REAL xi;
425  if(nodei) xi = nodei->Coord(0);
426  else continue;
427  keepindex = in;
428  for(int64_t jn=in;jn<nnodes;jn++) {
429  TPZGeoNode *nodej = &nodes[jn];
430  REAL xj;
431  if(nodej) xj = nodej->Coord(0); else continue;
432  if(xj < xi) {
433  keepindex = jn;
434  xi = xj;
435  }
436  }
437  if(keepindex!=in) {
438  TPZGeoNode commut = nodes[in];
439  nodes[in] = nodes[keepindex];
440  nodes[keepindex] = commut;
441  }
442  }
443  ofstream mesh("Malha.dat");
444  ofstream graph("Graphic.nb");
445  mesh << "\nDistribuicao de nos\n\n";
446  int64_t i;
447  for(i=0;i<nnodes;i++) {
448  nodei = &nodes[i];
449  if(nodei) mesh << nodei->Coord(0) << endl;
450  }
451  //2a parte
452  TPZVec<int64_t> locnodid(nnodes,0);
453  TPZVec<TPZGeoEl *> gelptr(nnodes);
454  int64_t nel = gmesh->NElements();
455  int64_t count = 0;
456  for(in=0;in<nnodes;in++) {
457  nodei = &nodes[in];
458  if(!nodei) continue;
459  for(int64_t iel=0;iel<nel;iel++) {
460  TPZGeoEl *gel = gmesh->ElementVec()[iel];
461  if(!gel || !gel->Reference() || gel->MaterialId() < 0) continue;
462  //int numnodes = gel->NNodes();
463  int ic=0;//for(int ic=0;ic<numnodes;ic++)
464  if(in==nnodes-1) ic = 1;
465  if(nodei->Id() == gel->NodePtr(ic)->Id()) {
466  gelptr[count] = gel;
467  locnodid[count++] = ic;
468  break;
469  }
470  }
471  }
472  TPZVec<int64_t> connects(nnodes);
473  int64_t iel;
474  for(iel=0;iel<nnodes;iel++) {
475  //if(!gelptr[iel] || !(gelptr[iel]->Reference())) continue;
476  connects[iel] = gelptr[iel]->Reference()->ConnectIndex(locnodid[iel]);
477  }
478  TPZVec<STATE> sol(nnodes);
479  for(i=0; i<nnodes; i++) {
480  TPZConnect *df = &fCompMesh->ConnectVec()[connects[i]];
481  if(!df) {
482  cout << "\nError in structure of dates\n";
483  mesh << "\nError in structure of dates\n";
484  return;//exit(-1);
485  }
486  int64_t seqnum = df->SequenceNumber();
487  int64_t pos = fCompMesh->Block().Position(seqnum);
488  sol[i] = fCompMesh->Solution()(pos,0);
489  }
490  mesh << "\nSolucao nodal\n\n";
491  for(i=0;i<nnodes;i++) {
492  mesh << sol[i] << endl;
493  }
494  // expanding solution
495  int64_t numsols = 5*(nnodes-1)+1; // 5 values by element: 3 interpolated (interior) + 2 over corners
496  TPZVec<STATE> expand_sol(numsols);
497  TPZVec<REAL> expand_nodes(numsols);
498  TPZVec<REAL> qsi(1);
499  int64_t exp_iel = -1;
500  for(iel=0;iel<nnodes-1;iel++) {
501  TPZManVector<STATE> locsol(1);
502  exp_iel++;
503  expand_sol[exp_iel] = sol[iel];
504  qsi[0] = -1.;
505  expand_nodes[exp_iel] = nodes[iel].Coord(0);
506  REAL h = h_Parameter(gelptr[iel]->Reference());
507  for(int i=1;i<5;i++) {
508  exp_iel++;
509  expand_nodes[exp_iel] = i*h/5. + nodes[iel].Coord(0);
510  qsi[0] += .4;
511  gelptr[iel]->Reference()->Solution(qsi,0,locsol);
512  expand_sol[exp_iel] = locsol[0];
513  }
514  }
515  expand_nodes[numsols-1] = nodes[nnodes-1].Coord(0);
516  expand_sol[numsols-1] = sol[nnodes-1];
517  // Mathematica output format
518  graph << "list = {" << endl;
519  for(int64_t isol=0;isol<numsols;isol++) {
520  if(isol > 0) graph << ",";
521  STATE expandsol = expand_sol[isol];
522  if(fabs(expandsol) < 1.e-10) expandsol = 0.;
523  graph << "{" << expand_nodes[isol] << "," << expandsol << "}";
524  if( !((isol+1)%5) ) graph << endl;
525  }
526  graph << "\n};\n";
527  graph << "ListPlot[list, PlotJoined->True, PlotRange->All];" << endl;
528 }
529 void TPZAnalysisError::EvaluateError(REAL CurrentEtaAdmissible, bool store_error, std::ostream &out) {
530  //Code isn�t place to chat
531  //#warning Philippe, tambem nao entendo aqui //<!>
532 
533  TPZManVector<REAL,3> elerror(3);
534  elerror.Fill(0.);
535  TPZManVector<REAL,3> errorSum(3);
536  errorSum.Fill(0.0);
537 
538  TPZBlock<REAL> *flux = 0;
539  int64_t elcounter=0;
540  int64_t numel = Mesh()->ElementVec().NElements();
541  fElErrors.Resize(numel);
542  fElIndexes.Resize(numel);
543  Mesh()->ElementSolution().Redim(numel,1);
544  // Sum of the errors over all computational elements
545  int64_t el;
546  for(el=0;el< numel;el++) {
547  TPZCompEl *elptr = Mesh()->ElementVec()[el];
548  if(elptr && !(elptr->Material()->Id() < 0)) {
549  elptr->EvaluateError(fExact,elerror, flux);
550  int nerrors = elerror.NElements();
551  errorSum.Resize(nerrors, 0.);
552  for(int ii = 0; ii < nerrors; ii++)
553  errorSum[ii] += elerror[ii]*elerror[ii];
554 
555  fElErrors[elcounter] = elerror[0];
556  (Mesh()->ElementSolution())(el,0) = elerror[0];
557  fElIndexes[elcounter++] = el;
558  } else {
559  (Mesh()->ElementSolution())(el,0) = 0.;
560  }
561  }
562  fElErrors.Resize(elcounter);
563  fElIndexes.Resize(elcounter);
564  fTotalError = sqrt(errorSum[0]);
565 // void NullFunction(TPZVec<REAL> &point,TPZVec<STATE>&val,TPZFMatrix<STATE> &deriv);
566 
567  std::function<void(const TPZVec<REAL> &,TPZVec<STATE>&,TPZFMatrix<STATE> &)> func(NullFunction);
568  Mesh()->EvaluateError(func,store_error, elerror);
569  fAdmissibleError = CurrentEtaAdmissible*sqrt(elerror[0]*elerror[0] + fTotalError*fTotalError) / sqrt(1.*elcounter);
570 }
571 
573  int64_t nelem = singel.NElements();
574  TPZStack<TPZGeoElSide> gelstack;
575  TPZStack<TPZCompElSide> celstack;
576  int64_t iel;
577  for(iel=0; iel<nelem; iel++) {
578  TPZCompElSide celside = singel[iel];
579  TPZGeoElSide gelside;
580  gelside = celside.Reference();
581  if(!gelside.Exists()) continue;
582  gelstack.Resize(0);
583  cout << "This part needs to be fixed\n";
584  // gelside.Element()->LowerDimensionSides(gelside.Side(),gelstack);
585  while(gelstack.NElements()) {
586  TPZGeoElSide gelsideloc;
587  gelsideloc = gelstack.Pop();
588  gelsideloc.EqualLevelCompElementList(celstack,1,0);
589  while(celstack.NElements()) {
590  TPZCompElSide celsideloc = celstack.Pop();
591  if(! celsideloc.Exists()) continue;
592  int64_t nelsing = singel.NElements();
593  int64_t smel;
594  for(smel=0; smel<nelsing; smel++) if(singel[smel].Element() == celsideloc.Element()) break;
595  if(smel != nelsing) singel.Push(celsideloc);
596  }
597  }
598  }
599 }
TPZFMatrix< STATE > & ElementSolution()
Access method for the element solution vectors.
Definition: pzcmesh.h:225
TPZGeoMesh * Reference() const
Returns a pointer to the geometrical mesh associated.
Definition: pzcmesh.h:209
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 AdjustBoundaryElements()
Will refine the elements associated with a boundary condition till there are no elements constrained ...
Definition: pzcmesh.cpp:1423
const int64_t numel
Number of elements to test.
Definition: pzsubcmesh.cpp:47
int Position(const int block_diagonal) const
Returns the position of first element block dependent on matrix diagonal.
Definition: pzblock.h:177
Implements computational element and a side. Computational Element.
Definition: pzcompel.h:632
Represents a set of shape functions associated with a computational element/side. Computational Eleme...
Definition: pzconnect.h:30
TPZManVector< REAL > fElErrors
Vector with error values by elements.
TPZGeoNode * NodePtr(int i) const
Returns a pointer to the ith node of the element.
Definition: pzgeoel.cpp:2566
Contains declaration of TPZGeoElSide class which represents an element and its side, and TPZGeoElSideIndex class which represents an TPZGeoElSide index.
void ShareMatrix(TPZMatrixSolver< TVar > &other)
Shares the current matrix with another object of same type.
Definition: pzsolve.cpp:57
void SetStructuralMatrix(TPZAutoPointer< TPZStructMatrix > strmatrix)
Set structural matrix as auto pointer for analysis.
Definition: pzanalysis.cpp:82
void OptimizeBandwidth()
Sets the computer connection block number from the graphical connections block number otimization...
Definition: pzanalysis.cpp:195
int MaterialId() const
Returns the material index of the element.
Definition: pzgeoel.h:250
virtual void EvaluateError(std::function< void(const TPZVec< REAL > &loc, TPZVec< STATE > &val, TPZFMatrix< STATE > &deriv)> func, TPZVec< REAL > &errors, bool store_error)
Performs an error estimate on the elemen.
Definition: pzcompel.cpp:415
Contains declaration of TPZGeoNode class which defines a geometrical node.
REAL Coord(int i) const
Returns i-th coordinate of the current node.
Definition: pzgnode.h:99
int64_t NEquations()
This computes the number of equations associated with non-restrained nodes.
Definition: pzcmesh.cpp:721
TPZStack< TPZCompElSide > fSingular
TPZGeoElSide Reference() const
Reference to the geometric element.
Definition: pzcompel.cpp:748
Templated vector implementation.
Defines step solvers class. Solver.
Definition: pzmganalysis.h:17
void SetSolver(TPZMatrixSolver< STATE > &solver)
Set solver matrix.
TPZCompMesh * fCompMesh
Computational mesh.
Definition: pzanalysis.h:44
Defines PZError.
virtual int NCornerNodes() const =0
Returns the number of corner nodes of the element.
TPZCompMesh * Mesh() const
Returns the pointer to the computational mesh.
Definition: pzanalysis.h:180
void NullFunction(const TPZVec< REAL > &point, TPZVec< STATE > &val, TPZFMatrix< STATE > &deriv)
Function to zeroes data.
int64_t NElements() const
Number of elements of the mesh.
Definition: pzgmesh.h:129
void GetSubElements2(TPZStack< TPZGeoElSide > &subelements)
build the list of element/side pairs which compose the current set of points
Declarates the TPZBlock<REAL>class which implements block matrices.
Utility class which represents an element with its side. The Geometric approximation classes Geometry...
Definition: pzgeoelside.h:83
clarg::argBool h("-h", "help message", false)
virtual void DefineGraphMesh(int dimension, const TPZVec< std::string > &scalnames, const TPZVec< std::string > &vecnames, const std::string &plotfile)
Define GrapMesh as V3D, DX, MV or VTK depending on extension of the file.
Definition: pzanalysis.cpp:952
int64_t NElements() const
Access method to query the number of elements of the vector.
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
Implements a chunk vector with free store administration. Utility.
Definition: TPZStream.h:39
void MathematicaPlot()
Plot to the aproximated solution of the FEM with Mathematica package.
virtual int NSides() const =0
Returns the number of connectivities of the element.
std::function< void(const TPZVec< REAL > &loc, TPZVec< STATE > &result, TPZFMatrix< STATE > &deriv)> fExact
Pointer to Exact solution function, it is necessary to calculating errors.
Definition: pzanalysis.h:99
void EqualLevelCompElementList(TPZStack< TPZCompElSide > &elsidevec, int onlyinterpolated, int removeduplicates)
Returns all connected computational elements which have equal level to the current element...
TPZMatrixSolver< STATE > & Solver()
Get the solver matrix.
Definition: pzanalysis.h:367
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
void EvaluateError(REAL CurrentEtaAdmissible, bool store_error, std::ostream &out)
Compute the list of errors of all elements and also the admissible error for any element in the grid...
Contains TPZAnalysisError class which implements analysis procedures with hp adaptivity.
Implements SkyLine Structural Matrices. Structural Matrix.
virtual TPZMaterial * Material() const
Identify the material object associated with the element.
Definition: pzcompel.cpp:959
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
int64_t SequenceNumber() const
Returns the Sequence number of the connect object.
Definition: pzconnect.h:158
static const double tol
Definition: pzgeoprism.cpp:23
void GetSingularElements(TPZStack< TPZCompElSide > &listel)
Search the element whith contain this point.
Implements the sequence of actions to perform a finite element analysis. Analysis.
Definition: pzanalysis.h:32
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
TPZAnalysisError(TPZCompMesh *mesh, std::ostream &out)
Object constructors.
void SetAdaptivityParameters(REAL EtaAdmissible, int64_t NIterations)
Set the parameters which will govern the adaptive process.
void Divide(int64_t index, TPZVec< int64_t > &sub, int interpolatesolution=0) override
Implement the refinement of an interpolated element.
Definition: pzintel.cpp:1396
int64_t NNodes() const
Number of nodes of the mesh.
Definition: pzgmesh.h:126
Contains declaration of TPZConnect class which represents a set of shape functions associated with a ...
Contains the TPZSkylineStructMatrix class which implements SkyLine Structural Matrices.
TPZManVector< int64_t > fElIndexes
Indexes of the elements vector.
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
TPZCompEl * Reference() const
Return a pointer to the element referenced by the geometric element.
Definition: pzgeoel.h:750
void ExpandConnected(TPZStack< TPZCompElSide > &singel)
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
string res
Definition: test.py:151
const TPZBlock< STATE > & Block() const
Access the block structure of the solution vector.
Definition: pzcmesh.h:213
int Exists() const
Verifies if the object is non null (initialized)
Definition: pzcompel.h:697
TPZAdmChunkVector< TPZConnect > & ConnectVec()
Return a reference to the connect pointers vector.
Definition: pzcmesh.h:198
int64_t Index() const
Returns element index of the mesh fELementVec list.
Definition: pzcompel.h:821
Contains declaration of TPZCompMesh class which is a repository for computational elements...
virtual void PostProcess(int resolution)
Draw solution over mesh for all dimensions.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
virtual void Run(std::ostream &out=std::cout)
Calls the appropriate sequence of methods to build a solution or a time stepping sequence.
Definition: pzanalysis.cpp:920
Contains TPZMatrix<TVar>class, root matrix class.
REAL h_Parameter(TPZCompEl *cel)
Calculate the h parameter of the element.
virtual int EffectiveSideOrder(int side) const =0
Returns the actual interpolation order of the polynomial along the side.
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
Definition: pzreal.h:487
std::ofstream arq("Param.dat")
Output file with number of iteration made.
T Pop()
Retrieve an object from the stack.
Definition: pzstack.h:87
TPZCompEl * Element() const
Gives a pointer to the reference computational element.
Definition: pzcompel.h:675
int64_t Id() const
Returns the Id of the element.
Definition: pzgeoel.h:223
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ log
Definition: tfadfunc.h:130
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Definition: pzcompel.cpp:1137
Implements a geometric node in the pz environment. Geometry.
Definition: pzgnode.h:31
virtual void X(TPZVec< REAL > &qsi, TPZVec< REAL > &result) const =0
Return the coordinate in real space of the point coordinate in the master element space...
TPZCompElSide Reference() const
Returns a pointer to the elementside referenced by the geometric elementside.
Free store vector implementation in chunks.
Implements block matrices. Matrix utility.
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
void ZoomInSingularity(REAL csi, TPZCompElSide elside, REAL singularity_order=0.9)
Calculate pn and hn parameters for the elements neighbours to the element with contain the singular p...
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
void HPAdapt(REAL CurrentEtaAdmissible, std::ostream &out)
Run one iteration of HP adaptivity.
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
Contains TPZSolver class which defines a abstract class of solvers which will be used by matrix class...
void PRefine(int order) override
Changes the interpolation order of a side. Updates all constraints and block sizes ...
Definition: pzintel.cpp:1592
Contains declaration of TPZInterpolatedElement class which implements computational element of the in...
int Id() const
Definition: TPZMaterial.h:170
void EvaluateError(std::function< void(const TPZVec< REAL > &loc, TPZVec< STATE > &val, TPZFMatrix< STATE > &deriv)> fp, bool store_error, TPZVec< REAL > &errorSum)
Evaluates the error given the two vectors of the analised parameters.
Definition: pzcmesh.cpp:1395
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
void hp_Adaptive_Mesh_Design(std::ostream &out, REAL &EtaAdmissible)
Run the algorithm of the fast hp adaptive finite element mesh design.
Contains TPZStepSolver class which defines step solvers class.
int Exists() const
Definition: pzgeoelside.h:175
int Id() const
Returns the identity of the current node.
Definition: pzgnode.h:68
int64_t fNIterations
Number of iterations.
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
void SetDirect(const DecomposeType decomp)
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
TPZFMatrix< STATE > & Solution()
Access the solution vector.
Definition: pzcmesh.h:219
Implements computational element based on an interpolation space. Computational Element.
Definition: pzintel.h:27
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
TPZAdmChunkVector< TPZGeoEl * > & ElementVec()
Methods for handling pzlists.
Definition: pzgmesh.h:138
void PlotLocal(int64_t iter, REAL CurrentEtaAdmissible, std::ostream &out)
Postprocess the intermediate solutions.