Changeset 24036
- Timestamp:
- 06/24/19 02:21:51 (6 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/cores/movingfront_core.cpp
r23652 r24036 88 88 delete analysis; 89 89 90 /*Kill ice berg to avoid free body motion*/ 91 if(VerboseSolution()) _printf0_(" looking for icebergs to kill\n"); 92 KillIcebergsx(femmodel); 93 90 94 /*Reset levelset if needed*/ 91 95 if(reinit_frequency && (step%reinit_frequency==0)){ -
issm/trunk-jpl/src/c/modules/KillIcebergsx/KillIcebergsx.cpp
r24034 r24036 7 7 #include "../../toolkits/toolkits.h" 8 8 9 #include "../InputUpdateFromVectorx/InputUpdateFromVectorx.h" 10 9 11 void KillIcebergsx(FemModel* femmodel){ 10 12 11 13 /*Intermediaries*/ 12 IssmDouble* local_mask = NULL; 13 const int MAXVERTICES = 6; 14 bool found1; 15 int sidlist[MAXVERTICES]; 16 int lidlist[MAXVERTICES]; 14 int lid; 17 15 18 /*retrieve vertex info*/ 19 int nbv_global = femmodel->vertices->NumberOfVertices(); 20 int nbv_local = femmodel->vertices->NumberOfVerticesLocal(); 21 if(nbv_global==0) return; 22 Vector<IssmDouble>* vec_connected_to_land=new Vector<IssmDouble>(nbv_local,nbv_global); 16 /*retrieve vertex info and prepare element flag to speed up process*/ 17 int nbv_local = femmodel->vertices->Size(); 18 IssmDouble *local_mask = xNewZeroInit<IssmDouble>(nbv_local); 19 bool *element_flag = xNewZeroInit<bool>(femmodel->elements->Size()); 23 20 24 /*Prepare element flag to speed up process*/ 25 bool* element_flag = xNewZeroInit<bool>(femmodel->elements->Size()); 26 27 /*Fill vector with 1 once for all*/ 28 IssmDouble eflags[MAXVERTICES]; 29 for(int i=0;i<MAXVERTICES;i++) eflags[i] = 1.; 30 31 /*Step 1, go through all elements and put 1 in vec_connected_to_land if the element is grounded*/ 21 /*Step 1, go through all elements and put 1 in local_mask if the element is grounded*/ 32 22 for(int i=0;i<femmodel->elements->Size();i++){ 33 23 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i)); 34 35 24 if(!element->IsIceInElement()){ 36 25 /*Nothing to do, just flag element to speed up the computation*/ … … 39 28 else{ 40 29 if(element->IsGrounded()){ 41 int numvertices = element->GetNumberOfVertices(); 42 if(numvertices>MAXVERTICES) _error_("need to increase MAXVERTICES"); 43 element->GetVerticesSidList(&sidlist[0]); 44 vec_connected_to_land->SetValues(numvertices,&sidlist[0],&eflags[0],ADD_VAL); 30 int numvertices = element->GetNumberOfVertices(); 31 for(int v=0;v<numvertices;v++) local_mask[element->vertices[v]->Lid()] = 1.; 45 32 } 46 33 } 47 34 } 48 vec_connected_to_land->Assemble();49 35 50 /*Now we have 2 loops, one across cpus, and one for each cpus: we are going to propagate the mask if an element 51 * is connected to a positive mask already. 52 * We then communicate to the other partitions. We stop when the mask stops changing*/ 36 /*Now we have 2 loops, one across cpus, and one for each cpus: we are going 37 * to propagate the mask if an element is connected to a positive mask 38 * already. We then communicate to the other partitions. We stop when the 39 * mask stops changing*/ 53 40 bool keepsyncing = true; 54 41 while(keepsyncing){ 55 42 56 43 /*Get local mask from parallel vector*/ 57 if(local_mask) xDelete<IssmDouble>(local_mask); 58 femmodel->GetLocalVectorWithClonesVertices(&local_mask,vec_connected_to_land); 44 femmodel->SyncLocalVectorWithClonesVertices(local_mask); 59 45 60 46 /*Local iterations on partition*/ 61 bool keepgoing = true;47 bool keepgoing = true; 62 48 int didsomething = 0; 63 int iter = 1;49 int iter = 1; 64 50 while(keepgoing){ 65 _printf0_(" -- Kill icebergs: iteration "<<iter<<"\n");51 _printf0_(" -- Kill icebergs: local iteration "<<iter<<"\n"); 66 52 67 53 keepgoing = false; … … 72 58 if(!element_flag[i]){ 73 59 int numvertices = element->GetNumberOfVertices(); 74 element->GetVerticesLidList(&lidlist[0]);75 60 bool found1 = false; 76 61 for(int j=0;j<numvertices;j++){ 77 if(local_mask[lidlist[j]]>0.){ 62 lid = element->vertices[j]->Lid(); 63 if(local_mask[lid]>0.){ 78 64 found1 = true; 79 65 break; … … 83 69 element_flag[i] = true; 84 70 for(int j=0;j<numvertices;j++){ 85 if(local_mask[lidlist[j]]==0.){ 86 local_mask[lidlist[j]]=1.; 71 lid = element->vertices[j]->Lid(); 72 if(local_mask[lid]==0.){ 73 local_mask[lid]=1.; 87 74 keepgoing = true; 88 75 didsomething = 1; … … 96 83 97 84 /*Check how many iterations all cpus did*/ 98 int didsomething_max; 99 ISSM_MPI_Reduce(&didsomething,&didsomething_max,1,ISSM_MPI_INT,ISSM_MPI_MAX,0,IssmComm::GetComm()); 100 ISSM_MPI_Bcast(&didsomething_max,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 101 if(didsomething_max==0){ 85 int iter_max; 86 ISSM_MPI_Reduce(&iter,&iter_max,1,ISSM_MPI_INT,ISSM_MPI_MAX,0,IssmComm::GetComm()); 87 ISSM_MPI_Bcast(&iter_max,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 88 if(iter_max==2){ 89 /*If iter is only 2, nothing else was changed in the while loop above (iter is initialized as 1 and then ++)*/ 102 90 keepsyncing = false; 103 }104 else{105 for(int i=0;i<femmodel->elements->Size();i++){106 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));107 108 if(element->IsIceInElement()){109 int numvertices = element->GetNumberOfVertices();110 element->GetVerticesSidList(&sidlist[0]);111 element->GetVerticesLidList(&lidlist[0]);112 for(int j=0;j<numvertices;j++) eflags[j] = local_mask[lidlist[j]];113 vec_connected_to_land->SetValues(numvertices,&sidlist[0],&eflags[0],ADD_VAL);114 }115 }116 vec_connected_to_land->Assemble();117 91 } 118 92 } 119 93 94 InputUpdateFromVectorx(femmodel,local_mask,PressureEnum,VertexLIdEnum); 120 95 /*Cleanup*/ 121 96 xDelete<bool>(element_flag); 122 delete vec_connected_to_land;123 97 124 98 /*OK, now deactivate iceberg and count the number of deactivated vertices*/ … … 128 102 if(element->IsIceInElement()){ 129 103 int numvertices = element->GetNumberOfVertices(); 130 element->GetVerticesLidList(&lidlist[0]);131 104 bool deactivate = false; 132 105 for(int j=0;j<numvertices;j++){ 133 if(local_mask[lidlist[j]]==0.){ 106 lid = element->vertices[j]->Lid(); 107 if(local_mask[lid]==0.){ 134 108 deactivate = true; 135 109 break;
Note:
See TracChangeset
for help on using the changeset viewer.