Ignore:
Timestamp:
11/02/15 11:46:25 (8 years ago)
Author:
mhnguyen
Message:

Implementing the reading of attributes of an axis from a file

+) 3d grid can be read directly from a file
+) Clean some redundant codes
+) Add new attribute declaration that allows to output only desired attributes

Test
+) On Curie
+) test_remap passes and result is correct

File:
1 edited

Legend:

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

    r772 r775  
    339339   void CDomain::fillInRectilinearLonLat() 
    340340   { 
    341      if (!lonvalue_2d.isEmpty()) lonvalue_2d.free(); 
    342      if (!latvalue_2d.isEmpty()) latvalue_1d.free(); 
    343      lonvalue_1d.resize(ni); 
    344      latvalue_1d.resize(nj); 
    345  
    346      double lonRange = lon_end - lon_start; 
    347      double latRange = lat_end - lat_start; 
    348  
    349      double lonStep = (1 == ni_glo.getValue()) ? lonRange : lonRange/double(ni_glo.getValue()-1); 
    350      double latStep = (1 == nj_glo.getValue()) ? latRange : latRange/double(nj_glo.getValue()-1); 
    351  
    352      // Assign lon value 
    353      for (int i = 0; i < ni; ++i) 
    354      { 
    355        if (0 == (ibegin + i)) 
     341     if (!lonvalue_rectilinear_read_from_file.isEmpty()) 
     342     { 
     343       lonvalue_1d.resize(ni); 
     344       for (int idx = 0; idx < ni; ++idx) 
     345         lonvalue_1d(idx) = lonvalue_rectilinear_read_from_file(idx+ibegin); 
     346       lon_start.setValue(lonvalue_rectilinear_read_from_file(0)); 
     347       lon_end.setValue(lonvalue_rectilinear_read_from_file(ni_glo-1)); 
     348     } 
     349     else 
     350     { 
     351       if (!lonvalue_2d.isEmpty()) lonvalue_2d.free(); 
     352       lonvalue_1d.resize(ni); 
     353       double lonRange = lon_end - lon_start; 
     354       double lonStep = (1 == ni_glo.getValue()) ? lonRange : lonRange/double(ni_glo.getValue()-1); 
     355 
     356        // Assign lon value 
     357       for (int i = 0; i < ni; ++i) 
    356358       { 
    357          lonvalue_1d(i) = lon_start; 
     359         if (0 == (ibegin + i)) 
     360         { 
     361           lonvalue_1d(i) = lon_start; 
     362         } 
     363         else if (ni_glo == (ibegin + i + 1)) 
     364         { 
     365           lonvalue_1d(i) = lon_end; 
     366         } 
     367         else 
     368         { 
     369           lonvalue_1d(i) = (ibegin + i) * lonStep  + lon_start; 
     370         } 
    358371       } 
    359        else if (ni_glo == (ibegin + i + 1)) 
     372     } 
     373 
     374 
     375     if (!latvalue_rectilinear_read_from_file.isEmpty()) 
     376     { 
     377       latvalue_1d.resize(nj); 
     378       for (int idx = 0; idx < nj; ++idx) 
     379         latvalue_1d(idx) = latvalue_rectilinear_read_from_file(idx+jbegin); 
     380       lat_start.setValue(latvalue_rectilinear_read_from_file(0)); 
     381       lat_end.setValue(latvalue_rectilinear_read_from_file(nj_glo-1)); 
     382     } 
     383     else 
     384     { 
     385       if (!latvalue_2d.isEmpty()) latvalue_1d.free(); 
     386       latvalue_1d.resize(nj); 
     387 
     388       double latRange = lat_end - lat_start; 
     389       double latStep = (1 == nj_glo.getValue()) ? latRange : latRange/double(nj_glo.getValue()-1); 
     390 
     391       for (int j = 0; j < nj; ++j) 
    360392       { 
    361          lonvalue_1d(i) = lon_end; 
    362        } 
    363        else 
    364        { 
    365          lonvalue_1d(i) = (ibegin + i) * lonStep  + lon_start; 
    366        } 
    367      } 
    368  
    369      for (int j = 0; j < nj; ++j) 
    370      { 
    371        if (0 == (jbegin + j)) 
    372        { 
    373           latvalue_1d(j) = lat_start; 
    374        } 
    375        else if (nj_glo == (jbegin + j + 1)) 
    376        { 
    377           latvalue_1d(j) = lat_end; 
    378        } 
    379        else 
    380        { 
    381          latvalue_1d(j) =  (jbegin + j) * latStep + lat_start; 
     393         if (0 == (jbegin + j)) 
     394         { 
     395            latvalue_1d(j) = lat_start; 
     396         } 
     397         else if (nj_glo == (jbegin + j + 1)) 
     398         { 
     399            latvalue_1d(j) = lat_end; 
     400         } 
     401         else 
     402         { 
     403           latvalue_1d(j) =  (jbegin + j) * latStep + lat_start; 
     404         } 
    382405       } 
    383406     } 
     
    389412     int i,j,k; 
    390413     const int nvertexValue = 4; 
    391  
    392      double boundsLonRange = bounds_lon_end - bounds_lon_start; 
    393      double boundsLatRange = bounds_lat_end - bounds_lat_start; 
    394  
    395414     boundsLon.resize(nvertexValue,ni*nj); 
     415 
     416     if (!lonvalue_rectilinear_read_from_file.isEmpty()) 
     417     { 
     418       double lonStepStart = lonvalue_rectilinear_read_from_file(1)-lonvalue_rectilinear_read_from_file(0); 
     419       bounds_lon_start.setValue(lonvalue_rectilinear_read_from_file(0) - lonStepStart/2); 
     420       double lonStepEnd = (lonvalue_rectilinear_read_from_file(ni_glo-1)-lonvalue_rectilinear_read_from_file(ni_glo-2)); 
     421       bounds_lon_end.setValue(lonvalue_rectilinear_read_from_file(ni_glo-1) + lonStepEnd/2); 
     422       double errorBoundsLon = std::abs(360-std::abs(bounds_lon_end-bounds_lon_start)); 
     423       if (errorBoundsLon > NumTraits<double>::epsilon()) bounds_lon_end.setValue(bounds_lon_start+360); 
     424       for(j=0;j<nj;++j) 
     425         for(i=0;i<ni;++i) 
     426         { 
     427           k=j*ni+i; 
     428           boundsLon(0,k) = boundsLon(1,k) = (0 == (ibegin + i)) ? bounds_lon_start 
     429                                                                 : (lonvalue_rectilinear_read_from_file(ibegin + i)+lonvalue_rectilinear_read_from_file(ibegin + i-1))/2; 
     430           boundsLon(2,k) = boundsLon(3,k) = ((ibegin + i + 1) == ni_glo) ? bounds_lon_end 
     431                                                                          : (lonvalue_rectilinear_read_from_file(ibegin + i + 1)+lonvalue_rectilinear_read_from_file(ibegin + i))/2; 
     432         } 
     433     } 
     434     else 
     435     { 
     436       double boundsLonRange = bounds_lon_end - bounds_lon_start; 
     437       double lonStep = boundsLonRange/double(ni_glo.getValue()); 
     438       for(j=0;j<nj;++j) 
     439         for(i=0;i<ni;++i) 
     440         { 
     441           k=j*ni+i; 
     442           boundsLon(0,k) = boundsLon(1,k) = (0 != (ibegin + i)) ? (ibegin + i) * lonStep + bounds_lon_start 
     443                                                                 : bounds_lon_start; 
     444           boundsLon(2,k) = boundsLon(3,k) = ((ibegin + i + 1) != ni_glo) ? (ibegin + i +1) * lonStep + bounds_lon_start 
     445                                                                          : bounds_lon_end; 
     446         } 
     447     } 
     448 
    396449     boundsLat.resize(nvertexValue,nj*ni); 
    397  
    398      double lonStep = boundsLonRange/double(ni_glo.getValue()); 
    399      double latStep = boundsLatRange/double(nj_glo.getValue()); 
    400  
    401      for(j=0;j<nj;++j) 
    402        for(i=0;i<ni;++i) 
    403        { 
    404          k=j*ni+i; 
    405          boundsLon(0,k) = boundsLon(1,k) = (0 != (ibegin + i)) ? (ibegin + i) * lonStep + bounds_lon_start 
    406                                                                : bounds_lon_start; 
    407          boundsLon(2,k) = boundsLon(3,k) = ((ibegin + i + 1) != ni_glo) ? (ibegin + i +1) * lonStep + bounds_lon_start 
    408                                                                         : bounds_lon_end; 
    409        } 
    410  
    411      double bounds_lat_start_pole = bounds_lat_start; 
    412      double bounds_lat_end_pole   = bounds_lat_end; 
    413      if (isNorthPole) bounds_lat_start_pole = lat_start; 
    414      if (isSouthPole) bounds_lat_end_pole   = lat_end; 
    415  
    416      for(j=0;j<nj;++j) 
    417        for(i=0;i<ni;++i) 
    418        { 
    419          k=j*ni+i; 
    420          boundsLat(1,k) = boundsLat(2,k) = (0 != (jbegin + j)) ? (jbegin + j) * latStep + bounds_lat_start 
    421                                                                : bounds_lat_start_pole; 
    422          boundsLat(0,k) = boundsLat(3,k) = ((jbegin + j +1) != nj_glo) ? (jbegin + j +1) * latStep + bounds_lat_start 
    423                                                                : bounds_lat_end_pole; 
    424        } 
    425    } 
    426  
    427    /*! 
    428      Temporary function to verify whether a rectilinear domain is created automatically. 
    429    The domain is distributed into number of parts which are equal to number of clients (intracomm) 
    430    */ 
    431    void CDomain::checkGenerate() 
    432    { 
    433      TransMapTypes trans = this->getAllTransformations(); 
    434      TransMapTypes::const_iterator it = trans.begin(), ite = trans.end(); 
    435      int transOrder = 0; 
    436      for (; it != ite; ++it, ++transOrder) 
    437      { 
    438        ETranformationType transType = it->first; 
    439        if ((TRANS_GENERATE_RECTILINEAR_DOMAIN == transType) && (0 == transOrder)) 
    440        { 
    441          CContext* context = CContext::getCurrent(); 
    442          CContextClient* client = context->client; 
    443          int nbClient; 
    444          MPI_Comm_size(client->intraComm,&nbClient); 
    445          it->second->checkValid(this); 
    446          this->redistribute(nbClient); 
    447          break; 
    448        } 
    449      } 
    450    } 
    451  
     450     if (!latvalue_rectilinear_read_from_file.isEmpty()) 
     451     { 
     452       double latStepStart = latvalue_rectilinear_read_from_file(1)-latvalue_rectilinear_read_from_file(0); 
     453       bounds_lat_start.setValue(latvalue_rectilinear_read_from_file(0) - latStepStart/2); 
     454       double latStepEnd = (latvalue_rectilinear_read_from_file(nj_glo-1)-latvalue_rectilinear_read_from_file(nj_glo-2)); 
     455       bounds_lat_end.setValue(latvalue_rectilinear_read_from_file(nj_glo-1) + latStepEnd/2); 
     456       double bounds_lat_start_pole = bounds_lat_start; 
     457       double bounds_lat_end_pole   = bounds_lat_end; 
     458       if (isNorthPole) bounds_lat_start_pole = lat_start; 
     459       if (isSouthPole) bounds_lat_end_pole   = lat_end; 
     460 
     461       for(j=0;j<nj;++j) 
     462         for(i=0;i<ni;++i) 
     463         { 
     464           k=j*ni+i; 
     465           boundsLat(1,k) = boundsLat(2,k) = (0 == (jbegin + j)) ? bounds_lat_start_pole 
     466                                                                 : (latvalue_rectilinear_read_from_file(jbegin + j)+latvalue_rectilinear_read_from_file(jbegin + j-1))/2; 
     467           boundsLat(0,k) = boundsLat(3,k) = ((jbegin + j +1) == nj_glo) ? bounds_lat_end_pole 
     468                                                                 : (latvalue_rectilinear_read_from_file(jbegin + j + 1)+latvalue_rectilinear_read_from_file(jbegin + j))/2; 
     469         } 
     470     } 
     471     else 
     472     { 
     473       double boundsLatRange = bounds_lat_end - bounds_lat_start; 
     474       double latStep = boundsLatRange/double(nj_glo.getValue()); 
     475       double bounds_lat_start_pole = bounds_lat_start; 
     476       double bounds_lat_end_pole   = bounds_lat_end; 
     477       if (isNorthPole) bounds_lat_start_pole = lat_start; 
     478       if (isSouthPole) bounds_lat_end_pole   = lat_end; 
     479 
     480       for(j=0;j<nj;++j) 
     481         for(i=0;i<ni;++i) 
     482         { 
     483           k=j*ni+i; 
     484           boundsLat(1,k) = boundsLat(2,k) = (0 != (jbegin + j)) ? (jbegin + j) * latStep + bounds_lat_start 
     485                                                                 : bounds_lat_start_pole; 
     486           boundsLat(0,k) = boundsLat(3,k) = ((jbegin + j +1) != nj_glo) ? (jbegin + j +1) * latStep + bounds_lat_start 
     487                                                                 : bounds_lat_end_pole; 
     488         } 
     489     } 
     490 
     491   } 
    452492 
    453493   void CDomain::checkDomain(void) 
     
    10291069     CContext* context=CContext::getCurrent(); 
    10301070 
    1031       this->checkGenerate(); 
    10321071      this->checkDomain(); 
    10331072      this->checkBounds(); 
Note: See TracChangeset for help on using the changeset viewer.