Changeset 23584


Ignore:
Timestamp:
12/30/18 19:42:32 (6 years ago)
Author:
Mathieu Morlighem
Message:

CHG: fixing vertex pairing and splitting CreateElementsVerticesAndMaterials.cpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateNodes.cpp

    r23576 r23584  
    99#include "./ModelProcessorx.h"
    1010
     11#define MAXCONNECTIVITY 5
     12
     13bool IsNodeInRank(int* nodes_ranks,int* nodes_proc_count,int nid,int rank){/*{{{*/
     14
     15        /*See if node is already in partition*/
     16        for(int k=0;k<nodes_proc_count[nid];k++){
     17                if(nodes_ranks[MAXCONNECTIVITY*nid+k] == rank) return true;
     18        }
     19
     20        return false;
     21}/*}}}*/
     22int  NodeMasterRank(int* nodes_ranks,int nid){/*{{{*/
     23        return nodes_ranks[MAXCONNECTIVITY*nid+0];
     24}/*}}}*/
     25void AddNodeToRank(int* nodes_ranks,int* nodes_proc_count,int nid,int rank){/*{{{*/
     26
     27        /*See if node is already in partition, return if this is the case*/
     28        if(IsNodeInRank(nodes_ranks,nodes_proc_count,nid,rank)) return;
     29
     30        /*This rank has not been marked for this node just yet so go ahead and add it*/
     31        nodes_ranks[MAXCONNECTIVITY*nid+nodes_proc_count[nid]] = rank;
     32        nodes_proc_count[nid]++;
     33}/*}}}*/
     34
    1135void CreateNodes(Nodes* nodes, IoModel* iomodel,int analysis,int finite_element,int approximation,int* approximations){
    1236
    1337        /*Intermediaries*/
    1438        int        numnodes;
    15         const int  MAXCONNECTIVITY = 5;
    1639        int        element_numnodes;
    1740        int        element_node_ids[40] = {0};
     
    2245        int*     epart = iomodel->epart;
    2346
    24 
    2547        /*Determine how many nodes we have in total*/
    26         /*Define nodes sids for each element*/
     48        /*{{{*/
    2749        if(iomodel->meshelementtype==TriaEnum){
    2850                switch(finite_element){
     
    125147                _error_("mesh elements "<< EnumToStringx(iomodel->meshelementtype) <<" not supported yet");
    126148        }
     149        /*}}}*/
    127150
    128151        /*create matrix that keeps track of all ranks that have node i, and initialize as -1 (Common to all CPUs)*/
     
    132155        /*For all nodes, count how many cpus have node i (initialize with 0)*/
    133156        int* nodes_proc_count = xNewZeroInit<int>(numnodes);
    134 
    135         /*Create vector of size total numnodes, initialized with -1, that will keep track of local ids*/
    136         int* nodes_lids  = xNew<int>(numnodes);
    137         for(int i=0;i<numnodes;i++) nodes_lids[i] = -1;
    138157
    139158        /*Create vector of approximation per node (used for FS: vel or pressure)*/
     
    147166
    148167        /*Go through all elements and mark all vertices for all partitions*/
    149         int  lid = 0;
     168        /*{{{*/
    150169        for(int i=0;i<iomodel->numberofelements;i++){
    151170
     
    478497                }
    479498
     499                /*Add rank epart[i] for all nodes belonging to this element*/
    480500                for(int j=0;j<element_numnodes;j++){
    481501                        int nid = element_node_ids[j]; _assert_(nid<numnodes);
    482 
    483                         /*See if it has already been marked*/
    484                         bool found = false;
    485                         for(int k=0;k<nodes_proc_count[nid];k++){
    486                                 if(nodes_ranks[MAXCONNECTIVITY*nid+k] == epart[i]){
    487                                         found = true;
    488                                         break;
    489                                 }
    490                         }
    491 
    492                         /*On go below if this vertex has not been seen yet in this partition*/
    493                         if(!found){
    494                                 /*This rank has not been marked for this vertex just yet so go ahead and mark it*/
    495                                 nodes_ranks[MAXCONNECTIVITY*nid+nodes_proc_count[nid]] = epart[i];
    496                                 nodes_proc_count[nid]++;
    497 
    498                                 /*Keep track of local ids!*/
    499                                 if(epart[i]==my_rank){
    500                                         nodes_lids[nid] = lid;
    501                                         lid++;
    502                                 }
    503 
    504                                 /*Make sure we don't go too far in the table*/
    505                                 if(nodes_proc_count[nid]>MAXCONNECTIVITY) _error_("need to increase MAXCONNECTIVITY (this is hard coded, contact ISSM developer)");
    506                         }
    507                 }
    508         }
    509         if(finite_element==P1DGEnum){/* Special case for DG...{{{*/
     502                        AddNodeToRank(nodes_ranks,nodes_proc_count,nid,epart[i]);
     503                }
     504        }
     505        /*}}}*/
     506        if(finite_element==P1DGEnum){/*Special case for DG...{{{*/
    510507                int node_list[4];
    511508                if(!iomodel->domaintype==Domain2DhorizontalEnum) _error_("not implemented yet");
     
    533530                                        for(int j=0;j<4;j++){
    534531                                                int  nid = node_list[j];
    535                                                 bool found = false;
    536                                                 for(int k=0;k<nodes_proc_count[nid];k++){
    537                                                         if(nodes_ranks[MAXCONNECTIVITY*nid+k] == epart[e1]){
    538                                                                 found = true;
    539                                                                 break;
    540                                                         }
    541                                                 }
    542                                                 if(!found){
    543                                                         nodes_ranks[MAXCONNECTIVITY*nid+nodes_proc_count[nid]] = epart[e1];
    544                                                         nodes_proc_count[nid]++;
    545                                                         if(epart[e1]==my_rank){
    546                                                                 nodes_lids[nid] = lid;
    547                                                                 lid++;
    548                                                         }
    549                                                         if(nodes_proc_count[nid]>MAXCONNECTIVITY) _error_("need to increase MAXCONNECTIVITY (this is hard coded, contact ISSM developer)");
    550                                                 }
    551                                         }
    552                                         for(int j=0;j<4;j++){
    553                                                 int  nid = node_list[j];
    554                                                 bool found = false;
    555                                                 for(int k=0;k<nodes_proc_count[nid];k++){
    556                                                         if(nodes_ranks[MAXCONNECTIVITY*nid+k] == epart[e2]){
    557                                                                 found = true;
    558                                                                 break;
    559                                                         }
    560                                                 }
    561                                                 if(!found){
    562                                                         nodes_ranks[MAXCONNECTIVITY*nid+nodes_proc_count[nid]] = epart[e2];
    563                                                         nodes_proc_count[nid]++;
    564                                                         if(epart[e2]==my_rank){
    565                                                                 nodes_lids[nid] = lid;
    566                                                                 lid++;
    567                                                         }
    568                                                         if(nodes_proc_count[nid]>MAXCONNECTIVITY) _error_("need to increase MAXCONNECTIVITY (this is hard coded, contact ISSM developer)");
    569                                                 }
     532                                                AddNodeToRank(nodes_ranks,nodes_proc_count,nid,epart[e1]);
     533                                                AddNodeToRank(nodes_ranks,nodes_proc_count,nid,epart[e2]);
    570534                                        }
    571535                                }
     
    573537                }
    574538        }/*}}}*/
    575         //if(my_rank==0) printarray(nodes_ranks,numnodes,MAXCONNECTIVITY);
     539        /*Vertex pairing for stressbalance{{{*/
     540        if(analysis==StressbalanceAnalysisEnum || analysis==StressbalanceVerticalAnalysisEnum){
     541                int *vertex_pairing = NULL;
     542                int  numvertex_pairing;
     543                iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,"md.stressbalance.vertex_pairing");
     544                _assert_(numvertex_pairing==0 || finite_element==P1Enum);
     545                for(int i=0;i<numvertex_pairing;i++){
     546                        int nid1 = vertex_pairing[2*i+0]-1;
     547                        int nid2 = vertex_pairing[2*i+1]-1;
     548                        for(int j=0;j<nodes_proc_count[nid1];j++) AddNodeToRank(nodes_ranks,nodes_proc_count,nid2,nodes_ranks[MAXCONNECTIVITY*nid1+j]);
     549                        for(int j=0;j<nodes_proc_count[nid2];j++) AddNodeToRank(nodes_ranks,nodes_proc_count,nid1,nodes_ranks[MAXCONNECTIVITY*nid2+j]);
     550                }
     551                xDelete<int>(vertex_pairing);
     552        }
     553        /*}}}*/
     554
     555        /*Create vector of size total numnodes, initialized with -1, that will keep track of local ids*/
     556        int  lid = 0;
     557        int* nodes_lids  = xNew<int>(numnodes);
     558        for(int i=0;i<numnodes;i++){
     559                if(IsNodeInRank(nodes_ranks,nodes_proc_count,i,my_rank)){
     560                        nodes_lids[i] = lid++;
     561                }
     562                else{
     563                        nodes_lids[i] = -1;
     564                }
     565        }
    576566
    577567        /*Now, Count how many clones we have with other partitions*/
     
    687677        nodes->common_recv_ids=common_recv_ids;
    688678}
     679
Note: See TracChangeset for help on using the changeset viewer.