Changeset 24036


Ignore:
Timestamp:
06/24/19 02:21:51 (6 years ago)
Author:
Mathieu Morlighem
Message:

CHG: first implementation of kill berg, seems to be workingmodules/KillIcebergsx/KillIcebergsx.cpp

Location:
issm/trunk-jpl/src/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/cores/movingfront_core.cpp

    r23652 r24036  
    8888        delete analysis;
    8989
     90        /*Kill ice berg to avoid free body motion*/
     91        if(VerboseSolution()) _printf0_("   looking for icebergs to kill\n");
     92        KillIcebergsx(femmodel);
     93
    9094        /*Reset levelset if needed*/
    9195        if(reinit_frequency && (step%reinit_frequency==0)){
  • issm/trunk-jpl/src/c/modules/KillIcebergsx/KillIcebergsx.cpp

    r24034 r24036  
    77#include "../../toolkits/toolkits.h"
    88
     9#include "../InputUpdateFromVectorx/InputUpdateFromVectorx.h"
     10
    911void KillIcebergsx(FemModel* femmodel){
    1012
    1113        /*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;
    1715
    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());
    2320
    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*/
    3222        for(int i=0;i<femmodel->elements->Size();i++){
    3323                Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
    34 
    3524                if(!element->IsIceInElement()){
    3625                        /*Nothing to do, just flag element to speed up the computation*/
     
    3928                else{
    4029                        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.;
    4532                        }
    4633                }
    4734        }
    48         vec_connected_to_land->Assemble();
    4935
    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*/
    5340        bool keepsyncing = true;
    5441        while(keepsyncing){
    5542
    5643                /*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);
    5945
    6046                /*Local iterations on partition*/
    61                 bool keepgoing = true;
     47                bool keepgoing    = true;
    6248                int  didsomething = 0;
    63                 int  iter      = 1;
     49                int  iter         = 1;
    6450                while(keepgoing){
    65                         _printf0_("   -- Kill icebergs: iteration "<<iter<<"\n");
     51                        _printf0_("   -- Kill icebergs: local iteration "<<iter<<"\n");
    6652
    6753                        keepgoing    = false;
     
    7258                                if(!element_flag[i]){
    7359                                        int numvertices = element->GetNumberOfVertices();
    74                                         element->GetVerticesLidList(&lidlist[0]);
    7560                                        bool found1 = false;
    7661                                        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.){
    7864                                                        found1 = true;
    7965                                                        break;
     
    8369                                                element_flag[i] = true;
    8470                                                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.;
    8774                                                                keepgoing = true;
    8875                                                                didsomething = 1;
     
    9683
    9784                /*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 ++)*/
    10290                        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();
    11791                }
    11892        }
    11993
     94        InputUpdateFromVectorx(femmodel,local_mask,PressureEnum,VertexLIdEnum);
    12095        /*Cleanup*/
    12196        xDelete<bool>(element_flag);
    122         delete vec_connected_to_land;
    12397
    12498        /*OK, now deactivate iceberg and count the number of deactivated vertices*/
     
    128102                if(element->IsIceInElement()){
    129103                        int  numvertices = element->GetNumberOfVertices();
    130                         element->GetVerticesLidList(&lidlist[0]);
    131104                        bool deactivate = false;
    132105                        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.){
    134108                                        deactivate = true;
    135109                                        break;
Note: See TracChangeset for help on using the changeset viewer.