Changeset 21503 for issm/trunk-jpl/src/c/classes/AdaptiveMeshRefinement.cpp
- Timestamp:
- 01/30/17 16:54:51 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/AdaptiveMeshRefinement.cpp
r21484 r21503 50 50 if(this->fathermesh) delete this->fathermesh; 51 51 if(this->previousmesh) delete this->previousmesh; 52 52 this->hmax=-1; 53 this->elementswidth=-1; 53 54 } 54 55 /*}}}*/ … … 127 128 /*Mesh refinement methods*/ 128 129 #include "TPZVTKGeoMesh.h" //itapopo 129 void AdaptiveMeshRefinement::ExecuteRefinement(int &type_process,double *vx, double *vy, double *masklevelset, long &nvertices, long &nelements, long &nsegments, double** x, double** y, double** z, long*** elements, long*** segments){/*{{{*/130 131 // ITAPOPO_assert_(this->fathermesh);132 // ITAPOPO_assert_(this->previousmesh);130 void AdaptiveMeshRefinement::ExecuteRefinement(int &type_process,double *vx, double *vy, double *masklevelset, int &nvertices, int &nelements, int &nsegments, double** x, double** y, double** z, int*** elements, int*** segments){/*{{{*/ 131 132 //itapopo _assert_(this->fathermesh); 133 //itapopo _assert_(this->previousmesh); 133 134 134 135 /*Calculate the position of the grounding line using previous mesh*/ 135 136 std::vector<TPZVec<REAL> > GLvec; 136 137 this->CalcGroundingLinePosition(masklevelset, GLvec); 137 138 139 //std::ofstream file1("/Users/santos/Desktop/mesh0.vtk"); 140 //TPZVTKGeoMesh::PrintGMeshVTK(this->previousmesh,file1 ); 138 139 std::ofstream file1("/ronne_1/home/santos/mesh0.vtk"); 140 TPZVTKGeoMesh::PrintGMeshVTK(this->previousmesh,file1 ); 141 141 142 142 /*run refinement or unrefinement process*/ … … 149 149 150 150 this->RefinementProcess(newmesh,GLvec); 151 152 //std::ofstream file2("/Users/santos/Desktop/mesh1.vtk");153 //TPZVTKGeoMesh::PrintGMeshVTK(this->previousmesh,file2 );151 152 std::ofstream file2("/ronne_1/home/santos/mesh1.vtk"); 153 TPZVTKGeoMesh::PrintGMeshVTK(this->previousmesh,file2 ); 154 154 155 155 /*Set new mesh pointer. Previous mesh just have uniform elements*/ … … 162 162 TPZGeoMesh *nohangingnodesmesh = new TPZGeoMesh(*newmesh); 163 163 164 165 //std::ofstream file3("/Users/santos/Desktop/mesh2.vtk"); 166 //TPZVTKGeoMesh::PrintGMeshVTK(newmesh,file3); 164 std::ofstream file3("/ronne_1/home/santos/mesh2.vtk"); 165 TPZVTKGeoMesh::PrintGMeshVTK(newmesh,file3); 167 166 168 167 this->RefineMeshToAvoidHangingNodes(nohangingnodesmesh); 169 168 170 171 //std::ofstream file4("/Users/santos/Desktop/mesh3.vtk"); 172 //TPZVTKGeoMesh::PrintGMeshVTK(nohangingnodesmesh,file4); 173 169 std::ofstream file4("/ronne_1/home/santos/mesh3.vtk"); 170 TPZVTKGeoMesh::PrintGMeshVTK(nohangingnodesmesh,file4); 174 171 175 172 /*Get new geometric mesh in ISSM data structure*/ 176 173 this->GetMesh(nohangingnodesmesh,nvertices,nelements,nsegments,x,y,z,elements,segments); 177 174 178 175 /*Verify the new geometry*/ 179 this->CheckMesh(nvertices,nelements,nsegments,this->elementswidth, (*x),(*y),(*z),(*elements),(*segments));180 176 this->CheckMesh(nvertices,nelements,nsegments,this->elementswidth,x,y,z,elements,segments); 177 181 178 delete nohangingnodesmesh; 182 183 179 } 184 180 /*}}}*/ … … 189 185 190 186 /*Set elements to be refined using some criteria*/ 191 std::vector< long> ElemVec; //elements without children187 std::vector<int> ElemVec; //elements without children 192 188 this->SetElementsToRefine(gmesh,GLvec,hlevel,ElemVec); 193 189 … … 198 194 } 199 195 /*}}}*/ 200 void AdaptiveMeshRefinement::RefineMesh(TPZGeoMesh *gmesh, std::vector< long> &ElemVec){/*{{{*/196 void AdaptiveMeshRefinement::RefineMesh(TPZGeoMesh *gmesh, std::vector<int> &ElemVec){/*{{{*/ 201 197 202 198 /*Refine elements in ElemVec: uniform pattern refinement*/ 203 for( longi = 0; i < ElemVec.size(); i++){199 for(int i = 0; i < ElemVec.size(); i++){ 204 200 205 201 /*Get geometric element and verify if it has already been refined*/ 206 longindex = ElemVec[i];202 int index = ElemVec[i]; 207 203 TPZGeoEl * geoel = gmesh->Element(index); 208 204 if(geoel->HasSubElement()) DebugStop(); //itapopo _assert_(!geoel->HasSubElement()); … … 211 207 /*Divide geoel*/ 212 208 TPZVec<TPZGeoEl *> Sons; 213 209 geoel->Divide(Sons); 214 210 215 211 /*If a 1D segment is neighbor, it must be divided too*/ … … 236 232 237 233 /*Refine elements to avoid hanging nodes: non-uniform refinement*/ 238 const longNElem = gmesh->NElements();239 for( longi = 0; i < NElem; i++){234 const int NElem = gmesh->NElements(); 235 for(int i = 0; i < NElem; i++){ 240 236 241 237 /*Get geometric element and verify if it has already been refined. Geoel may not have been previously refined*/ … … 253 249 } 254 250 255 251 } 256 252 257 253 gmesh->BuildConnectivity(); … … 259 255 } 260 256 /*}}}*/ 261 void AdaptiveMeshRefinement::GetMesh(TPZGeoMesh *gmesh, long &nvertices, long &nelements, long &nsegments, double** meshX, double** meshY, double** meshZ, long*** elements, long*** segments){/*{{{*/257 void AdaptiveMeshRefinement::GetMesh(TPZGeoMesh *gmesh, int &nvertices, int &nelements, int &nsegments, double** meshX, double** meshY, double** meshZ, int*** elements, int*** segments){/*{{{*/ 262 258 263 259 /* vertices */ 264 longntotalvertices = gmesh->NNodes();//total260 int ntotalvertices = gmesh->NNodes();//total 265 261 266 262 /* mesh coords */ … … 269 265 double *newmeshZ = new double[ntotalvertices]; 270 266 271 272 for( longi = 0; i < ntotalvertices; i++ ){267 /* getting mesh coords */ 268 for(int i = 0; i < ntotalvertices; i++ ){ 273 269 TPZVec<REAL> coords(3,0.); 274 270 gmesh->NodeVec()[i].GetCoordinates(coords); … … 280 276 /* elements */ 281 277 std::vector<TPZGeoEl*> GeoVec; GeoVec.clear(); 282 for(long i = 0; i < gmesh->NElements(); i++){ 283 278 for(int i = 0; i < gmesh->NElements(); i++){ 284 279 if( gmesh->ElementVec()[i]->HasSubElement() ) continue; 285 280 if( gmesh->ElementVec()[i]->MaterialId() != this->GetElemMaterialID() ) continue; 286 281 GeoVec.push_back( gmesh->ElementVec()[i]); 287 288 } 289 290 long ntotalelements = GeoVec.size(); 291 long ** newelements = new long*[ntotalelements]; 282 } 283 284 int ntotalelements = (int)GeoVec.size(); 285 int ** newelements = new int*[ntotalelements]; 292 286 293 287 if ( !(this->elementswidth == 3) && !(this->elementswidth == 4) && !(this->elementswidth == 6) ) DebugStop(); 294 288 295 for(long i = 0; i < GeoVec.size(); i++){ 296 297 newelements[i] = new long[this->elementswidth]; 298 for(int j = 0; j < this->elementswidth; j++) newelements[i][j] = GeoVec[i]->NodeIndex(j); 289 for(int i = 0; i < GeoVec.size(); i++){ 290 newelements[i] = new int[this->elementswidth]; 291 for(int j = 0; j < this->elementswidth; j++) newelements[i][j] = (int)GeoVec[i]->NodeIndex(j); 299 292 } 300 293 301 294 /* segments */ 302 295 std::vector<TPZGeoEl*> SegVec; SegVec.clear(); 303 for(long i = 0; i < gmesh->NElements(); i++){ 304 296 for(int i = 0; i < gmesh->NElements(); i++){ 305 297 if( gmesh->ElementVec()[i]->HasSubElement() ) continue; 306 298 if( gmesh->ElementVec()[i]->MaterialId() != this->GetBoundaryMaterialID() ) continue; 307 299 SegVec.push_back( gmesh->ElementVec()[i]); 308 309 } 310 311 long ntotalsegments = SegVec.size(); 312 long ** newsegments = new long*[ntotalsegments]; 313 314 for(long i = 0; i < SegVec.size(); i++){ 315 316 newsegments[i] = new long[3]; 300 } 301 302 int ntotalsegments = (int)SegVec.size(); 303 int ** newsegments = new int*[ntotalsegments]; 304 305 for(int i = 0; i < SegVec.size(); i++){ 306 307 newsegments[i] = new int[3]; 317 308 for(int j = 0; j < 2; j++) newsegments[i][j] = SegVec[i]->NodeIndex(j); 318 309 319 longneighborindex = SegVec[i]->Neighbour(2).Element()->Index();320 longneighbourid = -1;321 322 for( longj = 0; j < GeoVec.size(); j++){310 int neighborindex = SegVec[i]->Neighbour(2).Element()->Index(); 311 int neighbourid = -1; 312 313 for(int j = 0; j < GeoVec.size(); j++){ 323 314 if( GeoVec[j]->Index() == neighborindex || GeoVec[j]->FatherIndex() == neighborindex){ 324 315 neighbourid = j; … … 347 338 /* Find grounding line using elments center point */ 348 339 GLvec.clear(); 349 for( longi=0;i<this->previousmesh->NElements();i++){340 for(int i=0;i<this->previousmesh->NElements();i++){ 350 341 351 342 if(this->previousmesh->Element(i)->MaterialId()!=this->GetElemMaterialID()) continue; … … 353 344 354 345 //itapopo apenas malha 2D triangular! 355 longvertex0 = this->previousmesh->Element(i)->NodeIndex(0);356 longvertex1 = this->previousmesh->Element(i)->NodeIndex(1);357 longvertex2 = this->previousmesh->Element(i)->NodeIndex(2);346 int vertex0 = this->previousmesh->Element(i)->NodeIndex(0); 347 int vertex1 = this->previousmesh->Element(i)->NodeIndex(1); 348 int vertex2 = this->previousmesh->Element(i)->NodeIndex(2); 358 349 359 350 double mls0 = masklevelset[vertex0]; … … 384 375 } 385 376 /*}}}*/ 386 void AdaptiveMeshRefinement::SetElementsToRefine(TPZGeoMesh *gmesh,std::vector<TPZVec<REAL> > &GLvec,int &hlevel,std::vector< long> &ElemVec){/*{{{*/377 void AdaptiveMeshRefinement::SetElementsToRefine(TPZGeoMesh *gmesh,std::vector<TPZVec<REAL> > &GLvec,int &hlevel,std::vector<int> &ElemVec){/*{{{*/ 387 378 388 379 if(!gmesh) DebugStop(); //itapopo verificar se usará _assert_ … … 398 389 } 399 390 /*}}}*/ 400 void AdaptiveMeshRefinement::TagAllElements(TPZGeoMesh *gmesh,std::vector< long> &ElemVec){/*{{{*/391 void AdaptiveMeshRefinement::TagAllElements(TPZGeoMesh *gmesh,std::vector<int> &ElemVec){/*{{{*/ 401 392 402 393 /* Uniform refinement. This refines the entire mesh */ 403 longnelements = gmesh->NElements();404 for( longi=0;i<nelements;i++){394 int nelements = gmesh->NElements(); 395 for(int i=0;i<nelements;i++){ 405 396 if(gmesh->Element(i)->MaterialId()!=this->GetElemMaterialID()) continue; 406 397 if(gmesh->Element(i)->HasSubElement()) continue; … … 409 400 } 410 401 /*}}}*/ 411 void AdaptiveMeshRefinement::TagElementsNearGroundingLine(TPZGeoMesh *gmesh,std::vector<TPZVec<REAL> > &GLvec,int &hlevel,std::vector< long> &ElemVec){/*{{{*/402 void AdaptiveMeshRefinement::TagElementsNearGroundingLine(TPZGeoMesh *gmesh,std::vector<TPZVec<REAL> > &GLvec,int &hlevel,std::vector<int> &ElemVec){/*{{{*/ 412 403 413 404 /* Tag elements near grounding line */ … … 416 407 double MaxDistance = MaxRegion / std::exp(alpha*(hlevel-1)); 417 408 418 for( longi=0;i<gmesh->NElements();i++){409 for(int i=0;i<gmesh->NElements();i++){ 419 410 420 411 if(gmesh->Element(i)->MaterialId()!=this->GetElemMaterialID()) continue; … … 430 421 REAL distance = MaxDistance; 431 422 432 for ( longj = 0; j < GLvec.size(); j++) {423 for (int j = 0; j < GLvec.size(); j++) { 433 424 434 425 REAL value = ( GLvec[j][0] - centerPoint[0] ) * ( GLvec[j][0] - centerPoint[0] ); // (x2-x1)^2 … … 446 437 } 447 438 /*}}}*/ 448 void AdaptiveMeshRefinement::CreateInitialMesh( long &nvertices, long &nelements, long &nsegments, int &width, double* x, double* y, double* z, long** elements, long** segments){/*{{{*/439 void AdaptiveMeshRefinement::CreateInitialMesh(int &nvertices, int &nelements, int &nsegments, int &width, double* x, double* y, double* z, int** elements, int** segments){/*{{{*/ 449 440 450 441 // itapopo _assert_(nvertices>0); 451 442 // itapoo _assert_(nelements>0); 452 443 this->SetElementWidth(width); 453 444 454 445 /*Verify and creating initial mesh*/ 455 446 //itapopo if(this->fathermesh) _error_("Initial mesh already exists!"); 456 447 457 448 this->fathermesh = new TPZGeoMesh(); 458 449 this->fathermesh->NodeVec().Resize( nvertices ); 459 450 460 451 /*Set the vertices (geometric nodes in NeoPZ context)*/ 461 for( longi=0;i<nvertices;i++){452 for(int i=0;i<nvertices;i++){ 462 453 463 454 /*x,y,z coords*/ … … 469 460 /*Insert in the mesh*/ 470 461 this->fathermesh->NodeVec()[i].SetCoord(coord); 471 this->fathermesh->NodeVec()[i].SetNodeId(i);462 this->fathermesh->NodeVec()[i].SetNodeId(i); 472 463 } 473 464 … … 477 468 TPZManVector<long> elem(this->elementswidth,0); 478 469 479 for( longiel=0;iel<nelements;iel++){470 for(int iel=0;iel<nelements;iel++){ 480 471 481 472 for(int jel=0;jel<this->elementswidth;jel++) elem[jel]=elements[iel][jel]; … … 499 490 TPZManVector<long> boundary(2,0.); 500 491 501 for( longiel=nelements;iel<nelements+nsegments;iel++){492 for(int iel=nelements;iel<nelements+nsegments;iel++){ 502 493 503 494 boundary[0] = segments[iel-nelements][0]; … … 526 517 } 527 518 /*}}}*/ 528 void AdaptiveMeshRefinement::CheckMesh( long &nvertices, long &nelements, long &nsegments,int &width, double* x, double* y, double* z, long** elements, long** segments){/*{{{*/519 void AdaptiveMeshRefinement::CheckMesh(int &nvertices, int &nelements, int &nsegments,int &width, double** x, double** y, double** z, int*** elements, int*** segments){/*{{{*/ 529 520 530 521 /*Basic verification*/ … … 536 527 537 528 /*Verify if there are orphan nodes*/ 538 std::set<long> elemvertices; 539 elemvertices.clear(); 540 541 for(long i = 0; i < nelements; i++){ 542 for(long j = 0; j < width; j++) { 543 elemvertices.insert(elements[i][j]); 544 } 545 } 529 std::set<int> elemvertices; 530 elemvertices.clear(); 531 for(int i = 0; i < nelements; i++){ 532 for(int j = 0; j < width; j++) { 533 elemvertices.insert((*elements)[i][j]); 534 } 535 } 546 536 547 537 if( elemvertices.size() != nvertices ) DebugStop();//itapopo verificar se irá usar o _assert_ 548 538 549 539 //Verify if there are inf or NaN in coords 550 for(long i = 0; i < nvertices; i++) if(isnan(x[i]) || isinf(x[i])) DebugStop(); 551 for(long i = 0; i < nvertices; i++) if(isnan(y[i]) || isinf(y[i])) DebugStop(); 552 for(long i = 0; i < nvertices; i++) if(isnan(z[i]) || isinf(z[i])) DebugStop(); 553 for(long i = 0; i < nvertices; i++){ 554 for(long j = 0; j < width; j++){ 555 if( isnan(elements[i][j]) || isinf(elements[i][j]) ) DebugStop(); 556 } 557 } 558 559 } 560 /*}}}*/ 540 for(int i = 0; i < nvertices; i++) if(isnan((*x)[i]) || isinf((*x)[i])) DebugStop(); 541 for(int i = 0; i < nvertices; i++) if(isnan((*y)[i]) || isinf((*y)[i])) DebugStop(); 542 for(int i = 0; i < nvertices; i++) if(isnan((*z)[i]) || isinf((*z)[i])) DebugStop(); 543 544 for(int i = 0; i < nelements; i++){ 545 for(int j = 0; j < width; j++){ 546 if( isnan((*elements)[i][j]) || isinf((*elements)[i][j]) ) DebugStop(); 547 } 548 } 549 550 } 551 /*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.