Ignore:
Timestamp:
01/29/14 11:49:29 (10 years ago)
Author:
ymipsl
Message:

Add functionnalities for reduced gaussian grid support.

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/domain.cpp

    r456 r467  
    7777   //---------------------------------------------------------------- 
    7878 
    79    void CDomain::checkGlobalDomain(void) 
     79   void CDomain::checkDomain(void) 
    8080   { 
    8181      if (!type.isEmpty() && type==type_attr::unstructured) 
     
    9393         if (!ibegin.isEmpty()) jbegin=ibegin ; 
    9494         if (!iend.isEmpty()) jend=iend ; 
     95         if (!i_index.isEmpty()) 
     96         { 
     97          j_index.resize(1,nj) ; 
     98          for(int i=0;i<ni;i++) j_index(0,i)=i_index(i,0) ; 
     99          i_index.resize(1,nj) ; 
     100          for(int j=0;j<nj;j++) i_index(0,j)=0 ; 
     101         } 
     102 
     103         if (!mask.isEmpty()) 
     104         { 
     105          CArray<int,2> mask_tmp(nj,1) ; 
     106          mask_tmp = mask ; 
     107          mask.resize(1,nj) ; 
     108          for(int j=0;j<nj;j++) mask(0,j)=mask_tmp(j,0) ; 
     109         } 
    95110         ni=1 ; 
    96111         ibegin=1 ; 
    97112         iend=1 ; 
     113          
    98114      } 
    99115      else if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) || 
     
    105121               << " check the \'ni_glo\' et \'nj_glo\' values !")  
    106122      } 
     123      checkLocalIDomain() ; 
     124      checkLocalJDomain() ; 
     125       
     126     if (i_index.isEmpty()) 
     127     { 
     128       i_index.resize(ni,nj) ; 
     129       for(int j=0;j<nj;j++) 
     130         for(int i=0;i<ni;i++) i_index(i,j)=i ;    
     131     } 
     132      
     133     if (j_index.isEmpty()) 
     134     { 
     135        j_index.resize(ni,nj) ; 
     136        for(int j=0;j<nj;j++) 
     137         for(int i=0;i<ni;i++) j_index(i,j)=j ;    
     138     } 
     139  
    107140   } 
    108141 
     
    214247      if (!mask.isEmpty()) 
    215248      { 
    216          unsigned int niu = ni.getValue(), nju = nj.getValue(); 
    217          if ((mask.extent(0) != niu) || 
    218              (mask.extent(1) != nju)) 
     249         if ((mask.extent(0) != ni) || 
     250             (mask.extent(1) != nj)) 
    219251            ERROR("CDomain::checkAttributes(void)", 
    220252                  <<"the mask has not the same size than the local domain"<<endl 
    221                    <<"Local size is "<<niu<<"x"<<nju<<endl 
     253                   <<"Local size is "<<ni<<"x"<<nj<<endl 
    222254                  <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1));                  
    223          for (int i = 0; i < ni.getValue(); i++) 
    224          { 
    225             for (int j = 0; j < nj.getValue(); j++) 
     255         for (int i = 0; i < ni; i++) 
     256         { 
     257            for (int j = 0; j < nj; j++) 
    226258            { 
    227259               if (i < ibegin_mask && i > iend_mask && 
     
    423455        for (int j = 0; j < zoom_nj_client; j++) 
    424456        { 
    425 //          lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client -1) + (j + zoom_jbegin_client -1)*ni );  
    426 //          latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client -1)+(j + zoom_jbegin_client -1)*ni ); 
    427457          lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni );  
    428458          latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client - jbegin)*ni ); 
     
    431461            for(int n=0;n<nvertex;n++)  
    432462            { 
    433 //              bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client -1) + (j + zoom_jbegin_client -1)*ni );  
    434 //              bounds_lat(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client -1)+(j + zoom_jbegin_client -1)*ni ); 
    435463              bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni );  
    436464              bounds_lat(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client -jbegin)*ni ); 
     
    489517      zoom_nj_client=zoom_jend_client-zoom_jbegin_client+1 ; 
    490518      if (zoom_nj_client<0) zoom_nj_client=0 ; 
    491        
    492       cout << zoom_ibegin<<"  "<<zoom_ni <<"  "<< zoom_jbegin<<"  "<<zoom_nj<<endl ; 
    493       cout << zoom_ibegin_client<<"  "<<zoom_ni_client <<"  "<< zoom_jbegin_client<<"  "<<zoom_nj_client<<endl ; 
    494       cout << ibegin_client<<"  "<<iend_client <<"  "<< jbegin_client<<"  "<<jend_client<<endl ; 
    495 /*     
    496       { 
    497          int zoom_iend = zoom_ibegin + zoom_ni - 1; 
    498          int zoom_jend = zoom_jbegin + zoom_nj - 1; 
    499           
    500          if ( zoom_ibegin > iend || zoom_iend < ibegin ) 
    501          { 
    502             zoom_ni_loc = 0 ; 
    503             zoom_ibegin_loc = zoom_ibegin ; 
    504          } 
    505          else 
    506          { 
    507             int zoom_ibegin_loc_ = (zoom_ibegin > ibegin) ? zoom_ibegin : ibegin ; 
    508             int zoom_iend_loc_  = (zoom_iend < iend) ? zoom_iend : iend ; 
    509             int zoom_ni_loc_ = zoom_iend_loc_ - zoom_ibegin_loc_ + 1; 
    510              
    511             zoom_ni_loc = zoom_ni_loc_; 
    512             zoom_ibegin_loc = zoom_ibegin_loc_-ibegin.getValue()+1; 
    513          } 
    514           
    515          if ( zoom_jbegin > jend || zoom_jend < jbegin ) 
    516          { 
    517             zoom_nj_loc = 0 ; 
    518             zoom_jbegin_loc = zoom_jbegin ; 
    519          } 
    520          else 
    521          { 
    522             int zoom_jbegin_loc_ = ( zoom_jbegin > jbegin ) ? zoom_jbegin : jbegin ; 
    523             int zoom_jend_loc_  = (zoom_jend < jend) ? zoom_jend : jend ; 
    524             int zoom_nj_loc_ = zoom_jend_loc_ - zoom_jbegin_loc_ + 1; 
    525              
    526             zoom_nj_loc = zoom_nj_loc_; 
    527             zoom_jbegin_loc = zoom_jbegin_loc_-jbegin.getValue()+1; 
    528          } 
    529       } 
    530 */ 
     519 
    531520   } 
    532521    
     
    552541      CContext* context=CContext::getCurrent() ; 
    553542 
    554       this->checkGlobalDomain(); 
    555       this->checkLocalIDomain(); 
    556       this->checkLocalJDomain(); 
    557        
     543      this->checkDomain(); 
    558544      this->checkZoom(); 
    559545      this->checkBounds(); 
     
    617603     else client->sendEvent(event) ; 
    618604  } 
    619    
     605 
    620606  void CDomain::computeConnectedServer(void) 
    621607  { 
    622     int ib,ie,in; 
    623     int jb,je,jn ; 
    624      
    625     int ni_srv=ni_glo.getValue() ; 
    626     int ibegin_srv=1 ; 
    627     int iend_srv=ni_glo.getValue() ; 
    628       
    629     int nj_serv,jbegin_srv, jend_srv ; 
    630     int zoom_ibegin_srv,zoom_iend_srv,zoom_ni_srv ; 
    631     int zoom_jbegin_srv,zoom_jend_srv,zoom_nj_srv ; 
    632      
    633     ibegin_client=ibegin.getValue() ; iend_client=iend.getValue() ; ni_client=ni.getValue() ; 
    634     jbegin_client=jbegin.getValue() ; jend_client=jend.getValue() ; nj_client=nj.getValue() ; 
     608    int i,j,i_ind,j_ind ; 
     609     
     610    ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 
     611    jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 
    635612      
    636613    CContext* context = CContext::getCurrent() ; 
     
    638615    int nbServer=client->serverSize ; 
    639616 
    640 /*     
    641     // compute client zoom indices 
    642     int zoom_iend=zoom_ibegin.getValue()+zoom_ni.getValue()-1 ; 
    643     zoom_ibegin_client = ibegin_client > zoom_ibegin.getValue() ? ibegin_client : zoom_ibegin.getValue() ; 
    644     zoom_iend_client = iend_client < zoom_iend ? iend_client : zoom_iend ; 
    645     zoom_ni_client=zoom_iend_client-zoom_ibegin_client+1 ; 
    646     if (zoom_ni_client<0) zoom_ni_client=0 ; 
    647  
    648     int zoom_jend=zoom_jbegin.getValue()+zoom_nj.getValue()-1 ; 
    649     zoom_jbegin_client = jbegin_client > zoom_jbegin.getValue() ? jbegin_client : zoom_jbegin.getValue() ; 
    650     zoom_jend_client = jend_client < zoom_jend ? jend_client : zoom_jend ; 
    651     zoom_nj_client=zoom_jend_client-zoom_jbegin_client+1 ; 
    652     if (zoom_nj_client<0) zoom_nj_client=0 ; 
    653 */  
    654617    // find how much client are connected to a server 
    655618    int zoom_iend=zoom_ibegin+zoom_ni-1 ; 
    656619    int zoom_jend=zoom_jbegin+zoom_nj-1 ; 
    657620     
    658     jend_srv=0 ; 
    659     for(int ns=0;ns<nbServer;ns++) 
    660     { 
    661       jbegin_srv=jend_srv+1 ; 
    662       nj_srv=nj_glo.getValue()/nbServer ; 
    663       if (ns<nj_glo.getValue()%nbServer) nj_srv++ ; 
    664       jend_srv=jbegin_srv+nj_srv-1 ; 
    665        
    666       ib = ibegin_client>ibegin_srv ? ibegin_client : ibegin_srv ; 
    667       ie=  iend_client< iend_srv? iend_client : iend_srv ; 
    668       in=ie-ib+1 ;  
    669       if (in<0) in=0 ; 
    670        
    671       jb= jbegin_client>jbegin_srv ? jbegin_client : jbegin_srv ; 
    672       je= jend_client<jend_srv ? jend_client : jend_srv ; 
    673       jn=je-jb+1 ; 
    674       if (jn<0) jn=0 ; 
     621    int blockSize=nj_glo/nbServer ; 
     622    int ns=nj_glo%nbServer ; 
     623    int pos=ns*(blockSize+1) ; 
     624    int serverNum ; 
     625     
     626    mapConnectedServer.resize(ni,nj) ; 
     627    vector<int> nbData(nbServer,0) ; 
     628    vector<int> indServer(nbServer,-1) ; 
     629    vector<bool> IsConnected(nbServer,false) ; 
     630     
     631    for(j=0;j<nj;j++) 
     632      for(i=0;i<ni;i++) 
     633      { 
     634        i_ind=ibegin+i_index(i,j)-1 ; 
     635        j_ind=jbegin+j_index(i,j)-1 ; 
    675636         
    676       if (in>0 && jn>0) 
    677       { 
    678         zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; 
    679         zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 
    680         zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 
    681         if (zoom_ni_srv<0) zoom_ni_srv=0 ; 
    682        
    683         zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ; 
    684         zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 
    685         zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 
    686         if (zoom_nj_srv<0) zoom_nj_srv=0 ; 
    687   
    688         if (zoom_ni_srv>0 && zoom_nj_srv>0 && zoom_ni_client>0 && zoom_nj_client>0) 
     637        if (j_ind<pos) serverNum=j_ind/(blockSize+1) ; 
     638        else serverNum=ns+(j_ind-pos)/blockSize ; 
     639        IsConnected[serverNum]=true ; 
     640                 
     641        if (i_ind >= zoom_ibegin-1 && i_ind <= zoom_iend-1 && j_ind >= zoom_jbegin-1 && j_ind <= zoom_jend-1) 
    689642        { 
    690           ib = zoom_ibegin_client>zoom_ibegin_srv ? zoom_ibegin_client : zoom_ibegin_srv ; 
    691           ie=zoom_iend_client<zoom_iend_srv?zoom_iend_client:zoom_iend_srv ; 
    692           in=ie-ib+1 ; 
    693           if (in<0) in=0 ; 
    694          
    695           jb=zoom_jbegin_client>zoom_jbegin_srv?zoom_jbegin_client:zoom_jbegin_srv ; 
    696           je=zoom_jend_client<zoom_jend_srv?zoom_jend_client:zoom_jend_srv ; 
    697           jn=je-jb+1 ; 
    698           if (jn<0) jn=0 ; 
     643          mapConnectedServer(i,j)=serverNum ; 
     644          nbData[serverNum]++ ; 
    699645        } 
    700         else 
     646        else mapConnectedServer(i,j)=-1 ; 
     647      } 
     648 
     649 
     650    for(serverNum=0 ; serverNum<nbServer ; serverNum++)  
     651      if (IsConnected[serverNum]) 
     652      { 
     653        ns=connectedServer.size() ; 
     654        indServer[serverNum]=ns; 
     655        connectedServer.push_back(serverNum) ; 
     656        nbDataSrv.push_back(nbData[serverNum]) ; 
     657      } 
     658      
     659     i_indSrv.resize(connectedServer.size()) ; 
     660     j_indSrv.resize(connectedServer.size()) ; 
     661 
     662     for(j=0;j<nj;j++) 
     663      for(i=0;i<ni;i++)  
     664      { 
     665        if (mapConnectedServer(i,j)>=0) 
    701666        { 
    702           ib=1 ; ie=0 ; in=0 ; 
    703           jb=1 ; je=0 ; jn=0 ; 
     667          ns=indServer[mapConnectedServer(i,j)] ; 
     668          mapConnectedServer(i,j)= ns ; 
     669          i_indSrv[ns].push_back(i+ibegin-1) ; 
     670          j_indSrv[ns].push_back(j+jbegin-1) ; 
    704671        } 
    705          
    706 //          if (in>0 && jn>0)  
    707 //          {  
    708             connectedServer.push_back(ns) ; 
    709             ib_srv.push_back(ib) ; 
    710             ie_srv.push_back(ie) ; 
    711             in_srv.push_back(in) ; 
    712             jb_srv.push_back(jb) ; 
    713             je_srv.push_back(je) ; 
    714             jn_srv.push_back(jn) ; 
    715 //           } 
    716          
    717       } 
    718     } 
     672      } 
     673           
    719674    int nbConnectedServer=connectedServer.size() ; 
     675 
    720676    int* recvCount=new int[client->clientSize] ; 
    721677    int* displ=new int[client->clientSize] ; 
     
    744700    delete [] recvBuff ; 
    745701  } 
    746    
     702 
     703 
    747704  void CDomain::sendLonLat(void) 
    748705  { 
     706    int ns,n,i,j,ind,nv ; 
    749707    CContext* context = CContext::getCurrent() ; 
    750708    CContextClient* client=context->client ; 
     
    752710    CEventClient event(getType(),EVENT_ID_LON_LAT) ; 
    753711     
    754     int ib,ie,in ; 
    755     int jb,je,jn ; 
    756    
    757712    list<shared_ptr<CMessage> > list_msg ;     
    758713    list< CArray<int,1>* > list_indi,list_indj ; 
     
    762717    for(int ns=0;ns<connectedServer.size();ns++) 
    763718    { 
    764       ib=ib_srv[ns] ; ie=ie_srv[ns] ; in=in_srv[ns] ; 
    765       jb=jb_srv[ns] ; je=je_srv[ns] ; jn=jn_srv[ns] ; 
    766        
    767       CArray<int,1> indi(in*jn) ; 
    768       CArray<int,1> indj(in*jn) ; 
    769       CArray<double,1> lon(in*jn) ; 
    770       CArray<double,1> lat(in*jn) ; 
    771       CArray<double,2> boundslon(nvertex,in*jn) ; 
    772       CArray<double,2> boundslat(nvertex,in*jn) ; 
    773  
    774            
    775       int ind_client,ind_loc ; 
    776        
    777       for(int j=jb;j<=je;j++) 
    778         for(int i=ib;i<=ie;i++) 
     719      int nbData = nbDataSrv[ns] ; 
     720      CArray<int,1> indi(nbData) ; 
     721      CArray<int,1> indj(nbData) ; 
     722      CArray<double,1> lon(nbData) ; 
     723      CArray<double,1> lat(nbData) ; 
     724      CArray<double,2> boundslon(nvertex,nbData) ; 
     725      CArray<double,2> boundslat(nvertex,nbData) ; 
     726       
     727      for(n=0;n<nbData;n++)  
     728      { 
     729        i=i_indSrv[ns][n] ; 
     730        j=j_indSrv[ns][n] ; 
     731        ind=(i-(zoom_ibegin_client-1))+(j-(zoom_jbegin_client-1))*zoom_ni_client ; 
     732         
     733        lon(n)=lonvalue(ind) ; 
     734        lat(n)=latvalue(ind) ; 
     735        if (hasBounds) 
    779736        { 
    780           ind_client=(i-zoom_ibegin_client)+(j-zoom_jbegin_client)*zoom_ni_client ; 
    781           ind_loc=(i-ib)+(j-jb)*in ; 
    782           lon(ind_loc)=lonvalue(ind_client) ; 
    783           lat(ind_loc)=latvalue(ind_client) ; 
    784           if (hasBounds) 
     737          for(nv=0;nv<nvertex;nv++) 
    785738          { 
    786             for(int n=0;n<nvertex;n++) 
    787             { 
    788               boundslon(n,ind_loc)=bounds_lon(n,ind_client); 
    789               boundslat(n,ind_loc)=bounds_lat(n,ind_client); 
    790             } 
     739            boundslon(nv,n)=bounds_lon(nv,ind); 
     740            boundslat(nv,n)=bounds_lat(nv,ind); 
    791741          } 
    792           indi(ind_loc)=i ; 
    793           indj(ind_loc)=j ; 
    794742        } 
    795        
     743        indi(n)=ibegin+i_index(i-ibegin+1,j-jbegin+1)-1  ; 
     744        indj(n)=jbegin+j_index(i-ibegin+1,j-jbegin+1)-1  ; 
     745      } 
     746     
    796747      list_indi.push_back(new CArray<int,1>(indi.copy())) ; 
    797748      list_indj.push_back(new CArray<int,1>(indj.copy())) ; 
     
    818769    for(list<CArray<double,1>* >::iterator it=list_lat.begin();it!=list_lat.end();it++)   delete *it; 
    819770    if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslon.begin();it!=list_boundslon.end();it++)   delete *it; 
    820     if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++)   delete *it; 
     771    if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++)   delete *it;     
    821772     
    822773  } 
     774   
    823775   
    824776  bool CDomain::dispatchEvent(CEventServer& event) 
     
    860812 
    861813     buffer>>ni_srv>>ibegin_srv>>iend_srv>>nj_srv>>jbegin_srv>>jend_srv; 
     814      
    862815     
    863816    zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; 
     
    874827      zoom_jbegin_srv=1 ; zoom_jend_srv=0 ; zoom_nj_srv=0 ; 
    875828    } 
    876      
    877829    lonvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 
    878830    lonvalue_srv = 0. ; 
     
    908860    CArray<double,2> boundslon ; 
    909861    CArray<double,2> boundslat ; 
    910  
     862     
    911863    int type_int ; 
    912864    buffer>>type_int>>isCurvilinear>>indi>>indj>>lon>>lat ; 
     
    915867 
    916868    int i,j,ind_srv ; 
    917  
    918869    for(int ind=0;ind<indi.numElements();ind++) 
    919870    { 
    920871      i=indi(ind) ; j=indj(ind) ; 
    921       ind_srv=(i-zoom_ibegin_srv)+(j-zoom_jbegin_srv)*zoom_ni_srv ; 
     872      ind_srv=(i-(zoom_ibegin_srv-1))+(j-(zoom_jbegin_srv-1))*zoom_ni_srv ; 
    922873      lonvalue_srv(ind_srv)=lon(ind) ; 
    923874      latvalue_srv(ind_srv)=lat(ind) ; 
    924875      if (hasBounds)  
    925876      { 
    926         for(int n=0;n<nvertex;n++)  
     877        for(int nv=0;nv<nvertex;nv++)  
    927878        { 
    928           bounds_lon_srv(n,ind_srv)=boundslon(n,ind) ; 
    929           bounds_lat_srv(n,ind_srv)=boundslat(n,ind) ; 
     879          bounds_lon_srv(nv,ind_srv)=boundslon(nv,ind) ; 
     880          bounds_lat_srv(nv,ind_srv)=boundslat(nv,ind) ; 
    930881        } 
    931882      } 
Note: See TracChangeset for help on using the changeset viewer.