8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
23 #include <pz_config.h>
28 #include <TPZRefPatternTools.h>
29 #include <TPZRefPatternDataBase.h>
30 #include <TPZRefPattern.h>
32 #include <tpzchangeel.h>
33 #include <TPZGeoElement.h>
34 #include <pzreftriangle.h>
35 #include <pzgeotriangle.h>
36 #include <tpzgeoelrefpattern.h>
37 #include <pzgraphmesh.h>
38 #include <TPZVTKGeoMesh.h>
41 using namespace pzgeom;
47 this->fathermesh = NULL;
48 this->previousmesh = NULL;
49 this->refinement_type = -1;
53 this->groundingline_distance = -1;
54 this->icefront_distance = -1;
55 this->thicknesserror_threshold = -1;
56 this->deviatoricerror_threshold = -1;
57 this->deviatoricerror_maximum = -1;
58 this->thicknesserror_maximum = -1;
59 this->sid2index.clear();
60 this->index2sid.clear();
61 this->specialelementsindex.clear();
64 this->elementslist = NULL;
65 this->numberofvertices = -1;
66 this->numberofelements = -1;
79 this->fathermesh =
new TPZGeoMesh(*cp.
fathermesh);
91 this->sid2index.clear();
92 this->sid2index.resize(cp.
sid2index.size());
94 this->index2sid.clear();
95 this->index2sid.resize(cp.
index2sid.size());
97 this->specialelementsindex.clear();
106 if(writemesh) this->WriteMesh();
114 if(this->fathermesh)
delete this->fathermesh;
115 if(this->previousmesh)
delete this->previousmesh;
116 if(this->x) xDelete<IssmDouble>(this->x);
117 if(this->y) xDelete<IssmDouble>(this->y);
118 if(this->elementslist) xDelete<int>(this->elementslist);
119 this->refinement_type = -1;
120 this->level_max = -1;
121 this->gradation = -1;
123 this->groundingline_distance = -1;
124 this->icefront_distance = -1;
125 this->thicknesserror_threshold = -1;
126 this->deviatoricerror_threshold = -1;
127 this->deviatoricerror_maximum = -1;
128 this->thicknesserror_maximum = -1;
129 this->numberofvertices = -1;
130 this->numberofelements = -1;
131 this->sid2index.clear();
132 this->index2sid.clear();
133 this->specialelementsindex.clear();
141 if(this->elementslist) xDelete<int>(this->elementslist);
142 if(this->x) xDelete<IssmDouble>(this->x);
143 if(this->y) xDelete<IssmDouble>(this->y);
145 this->elementslist = *elementslist_in;
148 this->numberofvertices = *numberofvertices_in;
149 this->numberofelements = *numberofelements_in;
154 *elementslist_out = this->elementslist;
157 *numberofvertices_out= this->numberofvertices;
158 *numberofelements_out= this->numberofelements;
164 if(!this->fathermesh || !this->previousmesh)
_error_(
"Impossible to execute refinement: fathermesh or previousmesh is NULL!\n");
165 if(this->refinement_type!=0 && this->refinement_type!=1)
_error_(
"Impossible to execute refinement: refinement type is not defined!\n");
168 if(this->deviatoricerror_threshold>0 && !deviatoricerror)
_error_(
"deviatoricerror is NULL!\n");
169 if(this->thicknesserror_threshold>0 && !thicknesserror)
_error_(
"thicknesserror is NULL!\n");
170 if(this->groundingline_distance>0 && !gl_distance)
_error_(
"gl_distance is NULL!\n");
171 if(this->icefront_distance>0 && !if_distance)
_error_(
"if_distance is NULL!\n");
173 if(this->deviatoricerror_threshold>0 && this->deviatoricerror_groupthreshold<DBL_EPSILON)
_error_(
"group threshold is too small!");
174 if(this->thicknesserror_threshold>0 && this->thicknesserror_groupthreshold<DBL_EPSILON)
_error_(
"group threshold is too small!");
180 this->RefineMeshOneLevel(verbose,gl_distance,if_distance,deviatoricerror,thicknesserror);
183 this->GetMesh(this->previousmesh,pdatalist,pxylist,pelementslist);
186 this->CheckMesh(pdatalist,pxylist,pelementslist);
197 int numberofcriteria =-1;
198 int nconformelements = this->sid2index.size();
199 double gl_distance_h =-1;
200 double gl_distance_hmax = this->groundingline_distance;
201 double if_distance_h =-1;
202 double if_distance_hmax = this->icefront_distance;
203 double gl_groupdistance =-1;
204 double if_groupdistance =-1;
205 double d_maxerror =-1;
206 double t_maxerror =-1;
207 double deviatoric_grouperror =-1;
208 double thickness_grouperror =-1;
209 TPZGeoMesh* gmesh = NULL;
210 TPZVec<REAL> qsi(2,0.),cp(3,0.);
211 TPZVec<TPZGeoEl*> sons;
212 std::vector<int> index;
216 if(this->deviatoricerror_threshold>0) numberofcriteria++;
217 if(this->thicknesserror_threshold>0) numberofcriteria++;
218 if(this->groundingline_distance>0) numberofcriteria++;
219 if(this->icefront_distance>0) numberofcriteria++;
223 if(this->deviatoricerror_threshold>0 && this->deviatoricerror_maximum<DBL_EPSILON){
224 for(
int i=0;i<nconformelements;i++) this->deviatoricerror_maximum=
max(this->deviatoricerror_maximum,deviatoricerror[i]);
226 if(this->thicknesserror_threshold>0 && this->thicknesserror_maximum<DBL_EPSILON){
227 for(
int i=0;i<nconformelements;i++) this->thicknesserror_maximum=
max(this->thicknesserror_maximum,thicknesserror[i]);
232 gmesh=this->previousmesh;
233 for(
int i=0;i<this->specialelementsindex.size();i++){
234 if(this->specialelementsindex[i]==-1)
_error_(
"index is -1!\n");
235 if(!gmesh->Element(this->specialelementsindex[i]))
_error_(
"element is null!\n");
236 if(!gmesh->Element(this->specialelementsindex[i])->Father())
_error_(
"father is null!\n");
237 if(gmesh->Element(this->specialelementsindex[i])->HasSubElement())
_error_(
"special element has sub elements!\n");
239 gmesh->Element(this->specialelementsindex[i])->Father()->GetHigherSubElements(sons);
241 gl_distance_h = gl_distance_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(this->specialelementsindex[i])->Level());
242 if_distance_h = if_distance_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(this->specialelementsindex[i])->Level());
243 d_maxerror = this->deviatoricerror_threshold*this->deviatoricerror_maximum;
244 t_maxerror = this->thicknesserror_threshold*this->thicknesserror_maximum;
246 gl_groupdistance=INFINITY;if_groupdistance=INFINITY;deviatoric_grouperror=0;thickness_grouperror=0;
247 for(
int s=0;s<sons.size();s++){
248 sid=this->index2sid[sons[s]->Index()];
250 if(this->groundingline_distance>0) gl_groupdistance=
std::min(gl_groupdistance,gl_distance[sid]);
251 if(this->icefront_distance>0) if_groupdistance=
std::min(if_groupdistance,if_distance[sid]);
252 if(this->deviatoricerror_threshold>0) deviatoric_grouperror+=deviatoricerror[sid];
253 if(this->thicknesserror_threshold>0) thickness_grouperror+=thicknesserror[sid];
256 if(this->groundingline_distance>0 && gl_groupdistance<gl_distance_h+DBL_EPSILON) criteria++;
257 if(this->icefront_distance>0 && if_groupdistance<if_distance_h+DBL_EPSILON) criteria++;
258 if(this->deviatoricerror_threshold>0 && deviatoric_grouperror>d_maxerror-DBL_EPSILON) criteria++;
259 if(this->thicknesserror_threshold>0 && thickness_grouperror>t_maxerror-DBL_EPSILON) criteria++;
261 if(criteria) index.push_back(gmesh->Element(this->specialelementsindex[i])->FatherIndex());
266 if(this->refinement_type==1) this->DeleteSpecialElements(verbose,gmesh);
267 else this->specialelementsindex.clear();
271 if(this->refinement_type==0){
272 delete this->previousmesh;
273 gmesh=this->fathermesh;
278 if(verbose)
_printf_(
"\tunrefinement process...\n");
282 nelem=gmesh->NElements();
283 for(
int i=0;i<nelem;i++){
284 if(!gmesh->Element(i))
continue;
285 if(gmesh->Element(i)->MaterialId()!=this->GetElemMaterialID())
continue;
286 if(gmesh->Element(i)->HasSubElement())
continue;
287 if(gmesh->Element(i)->Level()==0)
continue;
288 if(!gmesh->Element(i)->Father())
_error_(
"father is NULL!\n");
290 gl_distance_h = this->lag*gl_distance_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(i)->Level());
291 if_distance_h = this->lag*if_distance_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(i)->Level());
292 d_maxerror = this->deviatoricerror_groupthreshold*this->deviatoricerror_maximum;
293 t_maxerror = this->thicknesserror_groupthreshold*this->thicknesserror_maximum;
296 gmesh->Element(i)->Father()->GetHigherSubElements(sons);
297 if(sons.size()!=4)
continue;
299 gl_groupdistance=INFINITY;if_groupdistance=INFINITY;deviatoric_grouperror=0;thickness_grouperror=0;
300 for(
int s=0;s<sons.size();s++){
301 sid=this->index2sid[sons[s]->Index()];
303 if(sid<0){gl_groupdistance=INFINITY;if_groupdistance=INFINITY;deviatoric_grouperror=INFINITY;thickness_grouperror=INFINITY;
continue;}
305 if(this->groundingline_distance>0) gl_groupdistance=
std::min(gl_groupdistance,gl_distance[sid]);
306 if(this->icefront_distance>0) if_groupdistance=
std::min(if_groupdistance,if_distance[sid]);
307 if(this->deviatoricerror_threshold>0) deviatoric_grouperror+=deviatoricerror[sid];
308 if(this->thicknesserror_threshold>0) thickness_grouperror+=thicknesserror[sid];
312 if(this->groundingline_distance>0 && gl_groupdistance>gl_distance_h-DBL_EPSILON) criteria++;
313 if(this->icefront_distance>0 && if_groupdistance>if_distance_h-DBL_EPSILON) criteria++;
314 if(this->deviatoricerror_threshold>0 && deviatoric_grouperror<d_maxerror+DBL_EPSILON) criteria++;
315 if(this->thicknesserror_threshold>0 && thickness_grouperror<t_maxerror+DBL_EPSILON) criteria++;
317 if(criteria==numberofcriteria){
318 gmesh->Element(i)->Father()->ResetSubElements(); count++;
319 for(
int s=0;s<sons.size();s++){this->index2sid[sons[s]->Index()]=-1;gmesh->DeleteElement(sons[s],sons[s]->Index());}
322 if(verbose)
_printf_(
""<<count<<
"\n");
328 if(verbose)
_printf_(
"\trefinement process (level max = "<<this->level_max<<
")\n");
331 nelem=gmesh->NElements();
332 for(
int i=0;i<nelem;i++){
333 if(!gmesh->Element(i))
continue;
334 if(gmesh->Element(i)->MaterialId()!=this->GetElemMaterialID())
continue;
335 if(gmesh->Element(i)->HasSubElement())
continue;
336 if(gmesh->Element(i)->Level()==this->level_max)
continue;
338 sid=this->index2sid[gmesh->Element(i)->Index()];
341 gl_distance_h = gl_distance_hmax*std::pow(this->gradation,this->level_max-(gmesh->Element(i)->Level()+1));
342 if_distance_h = if_distance_hmax*std::pow(this->gradation,this->level_max-(gmesh->Element(i)->Level()+1));
343 d_maxerror = this->deviatoricerror_threshold*this->deviatoricerror_maximum;
344 t_maxerror = this->thicknesserror_threshold*this->thicknesserror_maximum;
347 if(this->groundingline_distance>0 && gl_distance[sid]<gl_distance_h+DBL_EPSILON) criteria++;
348 if(this->icefront_distance>0 && if_distance[sid]<if_distance_h+DBL_EPSILON) criteria++;
349 if(this->deviatoricerror_threshold>0 && deviatoricerror[sid]>d_maxerror-DBL_EPSILON) criteria++;
350 if(this->thicknesserror_threshold>0 && thicknesserror[sid]>t_maxerror-DBL_EPSILON) criteria++;
352 if(criteria)index.push_back(i);
355 for(
int i=0;i<index.size();i++){
356 if(!gmesh->Element(index[i])) DebugStop();
357 if(!gmesh->Element(index[i])->HasSubElement()){gmesh->Element(index[i])->Divide(sons);count++;}
359 if(verbose)
_printf_(
""<<count<<
"\n");
365 this->RefineMeshWithSmoothing(verbose,gmesh);
366 if(this->refinement_type==0) this->previousmesh=this->CreateRefPatternMesh(gmesh);
367 gmesh=this->previousmesh;
368 this->RefineMeshToAvoidHangingNodes(verbose,gmesh);
379 if(!geoel)
_error_(
"geoel is NULL!\n");
385 TPZVec<TPZGeoEl*> sons;
388 for(
int j=3;j<6;j++){
389 if(!gmesh->Element(geoel->NeighbourIndex(j))->HasSubElement())
continue;
391 gmesh->Element(geoel->NeighbourIndex(j))->GetHigherSubElements(sons);
392 if(sons.size()) type++;
393 if(sons.size()>4) type++;
411 TPZVec<TPZGeoEl*> sons;
414 if(verbose)
_printf_(
"\tsmoothing process (level max = "<<this->level_max<<
")\n");
421 nelem=gmesh->NElements();
422 for(
int i=0;i<nelem;i++){
423 if(!gmesh->Element(i))
continue;
424 if(gmesh->Element(i)->MaterialId()!=this->GetElemMaterialID())
continue;
425 if(gmesh->Element(i)->HasSubElement())
continue;
426 if(gmesh->Element(i)->Level()==this->level_max)
continue;
428 type=this->VerifyRefinementType(gmesh->Element(i),gmesh);
431 for(
int j=3;j<6;j++){
432 if(gmesh->Element(gmesh->Element(i)->NeighbourIndex(j))->HasSubElement())
continue;
433 if(gmesh->Element(i)->NeighbourIndex(j)==i) typecount++;
434 if(this->VerifyRefinementType(gmesh->Element(gmesh->Element(i)->NeighbourIndex(j)),gmesh)==1) typecount++;
435 if(typecount>1 && type==1) type=2;
436 else if(typecount>2 && type==0) type=2;
442 if(type==2){gmesh->Element(i)->Divide(sons); count++;}
445 if(count==0)
_printf_(
""<<count<<
"\n");
456 if(verbose)
_printf_(
"\trefining to avoid hanging nodes (total: ");
463 nelem=gmesh->NElements();
465 for(
int i=0;i<nelem;i++){
467 TPZGeoEl * geoel=gmesh->Element(i);
469 if(geoel->HasSubElement())
continue;
470 if(geoel->MaterialId() != this->GetElemMaterialID())
continue;
472 TPZAutoPointer<TPZRefPattern> refp=TPZRefPatternTools::PerfectMatchRefPattern(geoel);
475 TPZVec<TPZGeoEl *> sons;
476 geoel->SetRefPattern(refp);
480 for(
int j=0;j<sons.size();j++) this->specialelementsindex.push_back(sons[j]->Index());
484 if(count==0)
_printf_(
""<<count<<
")\n");
496 if(verbose)
_printf_(
"\tdelete "<<this->specialelementsindex.size()<<
" special elements (total: ");
497 for(
int i=0;i<this->specialelementsindex.size();i++){
498 if(this->specialelementsindex[i]==-1)
continue;
499 if(!gmesh->Element(this->specialelementsindex[i]))
continue;
500 if(gmesh->Element(this->specialelementsindex[i])->Father()) gmesh->Element(this->specialelementsindex[i])->Father()->ResetSubElements();
501 gmesh->DeleteElement(gmesh->Element(this->specialelementsindex[i]),this->specialelementsindex[i]);
502 this->index2sid[this->specialelementsindex[i]]=-1;
505 if(verbose)
_printf_(
""<<count<<
")\n");
507 this->specialelementsindex.clear();
522 int nconformelements,nconformvertices;
523 int ntotalvertices = gmesh->NNodes();
524 int* newelements = NULL;
526 double* newmeshXY = NULL;
527 TPZGeoEl* geoel = NULL;
528 long* vertex_index2sid = xNew<long>(ntotalvertices);
529 this->index2sid.clear(); this->index2sid.resize(gmesh->NElements());
530 this->sid2index.clear();
533 for(
int i=0;i<gmesh->NNodes();i++) vertex_index2sid[i]=-1;
536 for(
int i=0;i<gmesh->NElements();i++) this->index2sid[i]=-1;
540 for(
int i=0;i<gmesh->NElements();i++){
541 geoel=gmesh->ElementVec()[i];
543 if(geoel->HasSubElement())
continue;
544 if(geoel->MaterialId() != this->GetElemMaterialID())
continue;
545 this->sid2index.push_back(geoel->Index());
546 this->index2sid[geoel->Index()]=this->sid2index.size()-1;
547 for(
int j=0;j<this->GetNumberOfNodes();j++){
548 nodeindex=geoel->NodeIndex(j);
549 if(nodeindex<0)
_error_(
"nodeindex is <0\n");
550 if(vertex_index2sid[nodeindex]==-1){
551 vertex_index2sid[nodeindex]=sid;
558 nconformelements = (int)this->sid2index.size();
559 nconformvertices = (int)sid;
560 newelements = xNew<int>(nconformelements*this->GetNumberOfNodes());
561 newmeshXY = xNew<double>(nconformvertices*2);
562 newdata = xNew<int>(2);
563 newdata[0] = nconformvertices;
564 newdata[1] = nconformelements;
566 for(
int i=0;i<ntotalvertices;i++){
567 sid=vertex_index2sid[i];
568 if(sid==-1)
continue;
569 TPZVec<REAL> coords(3,0.);
570 gmesh->NodeVec()[i].GetCoordinates(coords);
571 newmeshXY[2*sid] = coords[0];
572 newmeshXY[2*sid+1] = coords[1];
575 for(
int i=0;i<this->sid2index.size();i++){
576 for(
int j=0;j<this->GetNumberOfNodes();j++) {
577 geoel = gmesh->ElementVec()[this->sid2index[i]];
578 sid = vertex_index2sid[geoel->NodeIndex(j)];
579 newelements[i*this->GetNumberOfNodes()+j]=(int)sid+1;
584 double detJ,xa,xb,xc,ya,yb,yc;
587 a=newelements[i*this->GetNumberOfNodes()+0]-1;
588 b=newelements[i*this->GetNumberOfNodes()+1]-1;
589 c=newelements[i*this->GetNumberOfNodes()+2]-1;
591 xa=newmeshXY[2*a]; ya=newmeshXY[2*a+1];
592 xb=newmeshXY[2*b]; yb=newmeshXY[2*b+1];
593 xc=newmeshXY[2*c]; yc=newmeshXY[2*c+1];
595 detJ=(xb-xa)*(yc-ya)-(xc-xa)*(yb-ya);
599 newelements[i*this->GetNumberOfNodes()+0]=b+1;
600 newelements[i*this->GetNumberOfNodes()+1]=a+1;
607 *pelements = newelements;
610 xDelete<long>(vertex_index2sid);
618 if(this->numberofvertices<=0)
_error_(
"Impossible to create initial mesh: nvertices is <= 0!\n");
619 if(this->numberofelements<=0)
_error_(
"Impossible to create initial mesh: nelements is <= 0!\n");
620 if(this->refinement_type!=0 && this->refinement_type!=1)
_error_(
"Impossible to create initial mesh: refinement type is not defined!\n");
623 if(!this->x || !this->y || !this->elementslist)
_error_(
"Mesh data structure is NULL!\n");
624 if(this->fathermesh || this->previousmesh)
_error_(
"Initial mesh already exists!\n");
626 this->fathermesh =
new TPZGeoMesh();
627 this->fathermesh->NodeVec().Resize(this->numberofvertices);
630 for(
int i=0;i<this->numberofvertices;i++){
632 TPZManVector<REAL,3> coord(3,0.);
633 coord[0]= this->x[i];
634 coord[1]= this->y[i];
637 this->fathermesh->NodeVec()[i].SetCoord(coord);
638 this->fathermesh->NodeVec()[i].SetNodeId(i);
643 const int mat = this->GetElemMaterialID();
644 TPZManVector<int64_t> elem(this->GetNumberOfNodes(),0);
645 this->index2sid.clear(); this->index2sid.resize(this->numberofelements);
646 this->sid2index.clear();
648 for(
int i=0;i<this->numberofelements;i++){
649 for(
int j=0;j<this->GetNumberOfNodes();j++) elem[j]=this->elementslist[i*this->GetNumberOfNodes()+j]-1;
650 switch(this->GetNumberOfNodes()){
651 case 3: this->fathermesh->CreateGeoElement(ETriangle,elem,mat,index,this->refinement_type);
break;
652 default:
_error_(
"mesh not supported yet");
655 this->fathermesh->ElementVec()[index]->SetId(i);
657 this->sid2index.push_back((
int)index);
658 this->index2sid[(int)index]=this->sid2index.size()-1;
661 this->fathermesh->BuildConnectivity();
663 if(this->refinement_type==1) this->previousmesh=
new TPZGeoMesh(*this->fathermesh);
664 else this->previousmesh=this->CreateRefPatternMesh(this->fathermesh);
669 TPZGeoMesh *newgmesh =
new TPZGeoMesh();
672 int nnodes = gmesh->NNodes();
673 int nelem = gmesh->NElements();
674 int mat = this->GetElemMaterialID();;
679 newgmesh->NodeVec().Resize(nnodes);
680 for(
int i=0;i<nnodes;i++) newgmesh->NodeVec()[i] = gmesh->NodeVec()[i];
683 for(
int i=0;i<nelem;i++){
684 TPZGeoEl * geoel = gmesh->Element(i);
687 index=newgmesh->ElementVec().AllocateNewElement();
688 newgmesh->ElementVec()[index] = NULL;
692 TPZManVector<int64_t> elem(3,0);
693 for(
int j=0;j<3;j++) elem[j] = geoel->NodeIndex(j);
695 newgmesh->CreateGeoElement(ETriangle,elem,mat,index,reftype);
696 newgmesh->ElementVec()[index]->SetId(geoel->Id());
698 TPZGeoElRefPattern<TPZGeoTriangle>* newgeoel =
dynamic_cast<TPZGeoElRefPattern<TPZGeoTriangle>*
>(newgmesh->ElementVec()[index]);
701 const int nsides = TPZGeoTriangle::NSides;
702 TPZVec< std::vector<TPZGeoElSide> > neighbourhood(nsides);
703 TPZVec<long> NodesSequence(0);
704 for(
int s = 0; s < nsides; s++){
705 neighbourhood[s].resize(0);
706 TPZGeoElSide mySide(geoel,s);
707 TPZGeoElSide neighS = mySide.Neighbour();
708 if(mySide.Dimension() == 0){
709 long oldSz = NodesSequence.NElements();
710 NodesSequence.resize(oldSz+1);
711 NodesSequence[oldSz] = geoel->NodeIndex(s);
713 while(mySide != neighS){
714 neighbourhood[s].push_back(neighS);
715 neighS = neighS.Neighbour();
720 for(
int s = 0; s < nsides; s++){
721 TPZGeoEl * tempEl = newgeoel;
722 TPZGeoElSide tempSide(newgeoel,s);
724 for(
unsigned long n = 0; n < neighbourhood[s].size(); n++){
725 TPZGeoElSide neighS = neighbourhood[s][n];
726 tempEl->SetNeighbour(byside, neighS);
727 tempEl = neighS.Element();
728 byside = neighS.Side();
730 tempEl->SetNeighbour(byside, tempSide);
733 long fatherindex = geoel->FatherIndex();
734 if(fatherindex>-1) newgeoel->SetFather(fatherindex);
736 if(!geoel->HasSubElement())
continue;
738 int nsons = geoel->NSubElements();
740 TPZAutoPointer<TPZRefPattern> ref = gRefDBase.GetUniformRefPattern(ETriangle);
741 newgeoel->SetRefPattern(ref);
743 for(
int j=0;j<nsons;j++){
744 TPZGeoEl* son = geoel->SubElement(j);
748 newgeoel->SetSubElement(j,son);
753 newgmesh->BuildConnectivity();
761 if(!pdata)
_error_(
"Impossible to continue: pdata is NULL!\n");
762 if(**pdata<=0)
_error_(
"Impossible to continue: nvertices <=0!\n");
763 if(*(*pdata+1)<=0)
_error_(
"Impossible to continue: nelements <=0!\n");
764 if(!pxy)
_error_(
"Impossible to continue: pxy is NULL!\n");
765 if(!pelements)
_error_(
"Impossible to continue: pelements is NULL!\n");
771 long nelements = gmesh->NElements();
773 std::stringstream node, connectivity, type, material;
776 file <<
"# vtk DataFile Version 3.0" << std::endl;
777 file <<
"TPZGeoMesh VTK Visualization" << std::endl;
778 file <<
"ASCII" << std::endl << std::endl;
779 file <<
"DATASET UNSTRUCTURED_GRID" << std::endl;
782 long actualNode = -1, size = 0, nVALIDelements = 0;
783 for(
long el = 0; el < nelements; el++){
784 gel = gmesh->ElementVec()[el];
789 if(gel->HasSubElement())
793 MElementType elt = gel->Type();
794 int elNnodes = MElementType_NNodes(elt);
796 size += (1+elNnodes);
797 connectivity << elNnodes;
799 for(
int t = 0; t < elNnodes; t++)
801 for(
int c = 0; c < 3; c++)
803 double coord = gmesh->NodeVec()[gel->NodeIndex(t)].Coord(c);
804 node << coord <<
" ";
809 connectivity <<
" " << actualNode;
811 connectivity << std::endl;
813 int elType = this->GetVTK_ElType(gel);
814 type << elType << std::endl;
818 material << gel->MaterialId() << std::endl;
822 material << gel->Index() << std::endl;
829 file << actualNode <<
" float" << std::endl << node.str();
831 file <<
"CELLS " << nVALIDelements <<
" ";
833 file << size << std::endl;
834 file << connectivity.str() << std::endl;
836 file <<
"CELL_TYPES " << nVALIDelements << std::endl;
837 file << type.str() << std::endl;
839 file <<
"CELL_DATA" <<
" " << nVALIDelements << std::endl;
840 file <<
"FIELD FieldData 1" << std::endl;
843 file <<
"material 1 " << nVALIDelements <<
" int" << std::endl;
847 file <<
"ElementIndex 1 " << nVALIDelements <<
" int" << std::endl;
849 file << material.str();
855 MElementType pzElType = gel->Type();
875 case (EQuadrilateral):
902 std::cout <<
"Element type not found on " << __PRETTY_FUNCTION__ << std::endl;
909 std::cout <<
"Element type not found on " << __PRETTY_FUNCTION__ << std::endl;
910 std::cout <<
"MIGHT BE CURVED ELEMENT (quadratic or quarter point)" << std::endl;
919 std::string fathermeshfile =
"/home/santos/issm_fathermesh.txt";
920 std::string previousmeshfile =
"/home/santos/issm_previousmesh.txt";
921 std::string amrfile =
"/home/santos/issm_amr.txt";
922 std::ifstream amrifstream(amrfile.c_str());
925 TPZPersistenceManager::OpenRead(fathermeshfile);
926 this->fathermesh =
dynamic_cast<TPZGeoMesh *
>(TPZPersistenceManager::ReadFromFile());
927 TPZPersistenceManager::CloseRead();
929 TPZPersistenceManager::OpenRead(previousmeshfile);
930 this->previousmesh =
dynamic_cast<TPZGeoMesh *
>(TPZPersistenceManager::ReadFromFile());
931 TPZPersistenceManager::CloseRead();
933 if(!amrifstream.is_open())
_error_(
"amr ifstream is not open!");
934 amrifstream.seekg(0);
936 this->sid2index.clear();
937 this->index2sid.clear();
938 this->specialelementsindex.clear();
941 for(
int i=0;i<size;i++){
943 this->sid2index.push_back(value);
947 for(
int i=0;i<size;i++){
949 this->index2sid.push_back(value);
953 for(
int i=0;i<size;i++){
955 this->specialelementsindex.push_back(value);
961 std::string fathermeshfile =
"/home/santos/issm_fathermesh.txt";
962 std::string previousmeshfile =
"/home/santos/issm_previousmesh.txt";
963 std::string amrfile =
"/home/santos/issm_amr.txt";
964 std::ofstream amrofstream(amrfile.c_str());
966 if(this->fathermesh){
967 TPZPersistenceManager::OpenWrite(fathermeshfile);
968 TPZPersistenceManager::WriteToFile(this->fathermesh);
969 TPZPersistenceManager::CloseWrite();
972 if(this->previousmesh){
973 TPZPersistenceManager::OpenWrite(previousmeshfile);
974 TPZPersistenceManager::WriteToFile(this->previousmesh);
975 TPZPersistenceManager::CloseWrite();
978 if(this->sid2index.size()>0){
979 amrofstream << this->sid2index.size() << std::endl;
980 for(
int i=0;i<this->sid2index.size();i++) {
981 amrofstream << this->sid2index[i] << std::endl;
985 if(this->index2sid.size()>0){
986 amrofstream << this->index2sid.size() << std::endl;
987 for(
int i=0;i<this->index2sid.size();i++) {
988 amrofstream << this->index2sid[i] << std::endl;
992 if(this->specialelementsindex.size()){
993 amrofstream << this->specialelementsindex.size() << std::endl;
994 for(
int i=0;i<this->specialelementsindex.size();i++) {
995 amrofstream << this->specialelementsindex[i] << std::endl;