Changeset 783 for XIOS/trunk


Ignore:
Timestamp:
11/12/15 16:33:08 (8 years ago)
Author:
mhnguyen
Message:

Adding attribute reading of unstructured grid

+) Fix a minor bug relating to unstructured grid detection
+) Add attribute reading for unstructured domain

Test
+) On Curie
+) test_remap passes

Location:
XIOS/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/inputs/REMAP/iodef.xml

    r782 r783  
    88   <field_definition level="1" > 
    99     <field id="src_field" operation="instant" domain_ref="src_domain"/> 
    10 <!--     <field id="dst_field" operation="instant" field_ref="src_field" domain_ref="dst_domain"/>--> 
     10     <field id="dst_field" operation="instant" field_ref="src_field" domain_ref="dst_domain"/> 
    1111     <field id="tmp_field" operation="instant" domain_ref="src_domain_regular_tmp"/> 
    1212     <field id="tmp_field_1" operation="instant" grid_ref="src_grid_curvilinear" /> 
     13     <field id="tmp_field_2" operation="instant" domain_ref="domain_src_unstructured" /> 
    1314     <field id="dst_field_regular" operation="instant" field_ref="tmp_field" domain_ref="dst_domain_regular" read_access="true"/> 
    14      <field id="dst_field_regular_pole" operation="instant" field_ref="src_field" domain_ref="dst_domain_regular_pole" read_access="true"/> 
     15     <field id="dst_field_regular_pole" operation="instant" field_ref="src_field" domain_ref="dst_domain_regular_pole"/> 
    1516   </field_definition> 
    1617 
     
    3233<!--        <field field_ref="tmp_field_1" operation="instant"/>--> 
    3334     </file> 
     35     <file id="output_dst_unstructured" name="output_dst_unstructured" type="one_file"> 
     36        <field field_ref="tmp_field_2" operation="instant"/> 
     37     </file> 
    3438 
    3539     <file id="output_src_regular" name="output_src_regular" mode="read" type="multiple_file"> 
     
    4145 
    4246     <file id="output_src_curvilinear" name="output_src_curvilinear" mode="read" type="one_file"> 
    43 <!--        <field id="src_field_curvilinear" name="field_A" domain_ref="src_domain_curvilinear" axis_ref="src_axis_curvilinear" operation="instant"/>--> 
    4447        <field id="src_field_curvilinear" name="field_A" grid_ref="src_grid_curvilinear" operation="instant"/> 
    4548     </file> 
    46      <file id="output_surface_curvi" name="output_surface_curvi" mode="read" type="one_file"> 
    47         <field id="field_surface_curvi" name="field_A" domain_ref="domain_surface_curvi" axis_ref="axis_surface_curvi" operation="instant"/> 
     49     <file id="output_unstructured" name="output_unstructured" mode="read" type="one_file"> 
     50        <field id="field_src_unstructred" name="field" domain_ref="domain_src_unstructured" operation="instant"/> 
    4851     </file> 
    4952   </file_definition> 
     
    5962   <domain_definition> 
    6063     <domain id="src_domain" /> 
    61      <domain id="dst_domain" domain_src="src_domain_regular"> 
     64     <domain id="dst_domain" domain_src="src_domain"> 
    6265       <interpolate_domain/> 
    6366     </domain> 
     
    6669       <interpolate_domain/> 
    6770     </domain> 
    68 <!--     <domain id="dst_domain_regular" domain_src="src_domain_regular" ni_glo="90" nj_glo="45" type="rectilinear">--> 
    6971     <domain id="dst_domain_regular" domain_src="src_domain_regular_tmp" ni_glo="90" nj_glo="45" type="rectilinear"> 
    7072       <generate_rectilinear_domain /> 
     
    8082       <generate_rectilinear_domain /> 
    8183     </domain> 
    82      <domain id="domain_surface_curvi" type="curvilinear"> 
     84     <domain id="domain_src_unstructured" type="unstructured"> 
    8385       <generate_rectilinear_domain /> 
    8486     </domain> 
  • XIOS/trunk/src/io/inetcdf4.cpp

    r782 r783  
    551551          return false; 
    552552      } 
    553       else return false; 
    554553    } 
    555554 
  • XIOS/trunk/src/io/nc4_data_input.cpp

    r782 r783  
    143143    // Verify the compatibility of dimension of declared grid and real grid in file 
    144144    int realGridDim = 1; 
     145    bool isUnstructuredGrid = SuperClassWriter::isUnstructured(fieldId); 
    145146    std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId); 
    146147    realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size(); 
     148    if (isUnstructuredGrid) ++realGridDim; 
    147149 
    148150    if (gridDim != realGridDim) 
     
    154156    if (SuperClassWriter::isTemporal(fieldId)) dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName()); 
    155157    int mapSize = dimSizeMap.size() - 1; 
     158    std::list<std::pair<StdString, StdSize> > listDimSize; 
     159    for (std::map<StdString, StdSize>::const_iterator itMap = dimSizeMap.begin(); itMap != dimSizeMap.end(); ++itMap) 
     160      listDimSize.push_front(*itMap); 
    156161 
    157162    // Now process domain and axis 
     
    169174        { 
    170175           it = readValueDomains_.insert(domainP[idxDomain]->getId()); 
    171            if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], dimSizeMap, mapSize - 1 - elementPosition, fieldId); 
     176           if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId); 
    172177        } 
    173178        else 
    174179        { 
    175180          it = readMetaDataDomains_.insert(domainP[idxDomain]->getId()); 
    176           if (it.second) readDomainAttributesFromFile(domainP[idxDomain], dimSizeMap, mapSize - 1 - elementPosition, fieldId); 
     181          if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId); 
    177182        } 
    178183        ++idxDomain; 
    179         elementPosition += 2; 
     184        if (isUnstructuredGrid) ++elementPosition; 
     185        else elementPosition += 2; 
    180186      } 
    181187      else 
     
    184190        { 
    185191          it = readValueAxis_.insert(axisP[idxAxis]->getId()); 
    186           if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], dimSizeMap, mapSize - elementPosition, fieldId); 
     192          if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId); 
    187193        } 
    188194        else 
    189195        { 
    190196          it = readMetaDataAxis_.insert(axisP[idxAxis]->getId()); 
    191           if (it.second) readAxisAttributesFromFile(axisP[idxAxis], dimSizeMap, mapSize - elementPosition, fieldId); 
     197          if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId); 
    192198        } 
    193199        ++idxAxis; 
     
    204210    \param [in] fieldId id (or name) associated with the grid 
    205211  */ 
    206   void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::map<StdString, StdSize>& dimSizeMap, 
     212  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    207213                                                       int elementPosition, const StdString& fieldId) 
    208214  { 
    209215    // There are some optional attributes of a domain to retrieve from file    // + lon lat? 
    210     std::map<StdString, StdSize>::const_iterator itMapNj = dimSizeMap.begin(), itMapNi, 
    211                                                  iteMap  = dimSizeMap.end(); 
    212  
    213     for (int i = 0; i < elementPosition; ++i, ++itMapNj) {} 
    214     itMapNi = itMapNj; ++itMapNi; 
     216    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj, 
     217                                                              iteMap  = dimSizeMap.end(); 
     218 
     219    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {} 
     220    itMapNj = itMapNi; ++itMapNj; 
    215221 
    216222    if (this->isRectilinear(fieldId)) 
     
    225231      readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true); 
    226232      domain->fillInRectilinearLonLat(); 
     233    } 
     234    else if (this->isUnstructured(fieldId)) 
     235    { 
     236      int ni = domain->ni; 
     237      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0); 
     238      nBeginLatLon[0] = domain->ibegin.getValue(); 
     239      nSizeLatLon[0]  = ni; 
     240 
     241      StdString latName = this->getLatCoordName(fieldId); 
     242      domain->latvalue_1d.resize(ni); 
     243      readFieldVariableValue(domain->latvalue_1d, latName, nBeginLatLon, nSizeLatLon); 
     244      StdString lonName = this->getLonCoordName(fieldId); 
     245      domain->lonvalue_1d.resize(ni); 
     246      readFieldVariableValue(domain->lonvalue_1d, lonName, nBeginLatLon, nSizeLatLon); 
     247 
     248      StdString boundsLatName = this->getBoundsId(latName); 
     249      if (0 == boundsLatName.compare("")) 
     250         ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
     251              << "Field '" << fieldId << std::endl 
     252              << "Trying to read attributes from unstructured grid." 
     253              << "Latitude variable " << latName << " does not have bounds."); 
     254      StdString boundsLonName = this->getBoundsId(lonName); 
     255      if (0 == boundsLonName.compare("")) 
     256         ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
     257              << "Field '" << fieldId << std::endl 
     258              << "Trying to read attributes from unstructured grid." 
     259              << "Longitude variable " << lonName << " does not have bounds."); 
     260 
     261      int nbVertex = this->getNbVertex(fieldId); 
     262      domain->nvertex.setValue(nbVertex); 
     263      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2); 
     264      nBeginBndsLatLon[0] = domain->ibegin.getValue(); nSizeBndsLatLon[0] = ni; 
     265      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex; 
     266 
     267      domain->bounds_lat_1d.resize(nbVertex,ni); 
     268      readFieldVariableValue(domain->bounds_lat_1d, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
     269      domain->bounds_lon_1d.resize(nbVertex,ni); 
     270      readFieldVariableValue(domain->bounds_lon_1d, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
    227271    } 
    228272    else if (this->isCurvilinear(fieldId)) 
     
    254298              << "Longitude variable " << lonName << " does not have bounds."); 
    255299 
    256       domain->nvertex.setValue(4); 
     300      int nbVertex = this->getNbVertex(fieldId); 
     301      domain->nvertex.setValue(nbVertex); 
    257302      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3); 
    258303      nBeginBndsLatLon[0] = domain->jbegin.getValue(); nSizeBndsLatLon[0] = nj; 
    259304      nBeginBndsLatLon[1] = domain->ibegin.getValue(); nSizeBndsLatLon[1] = ni; 
    260       nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = 4; 
    261  
    262       domain->bounds_lat_2d.resize(4,ni,nj); 
     305      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex; 
     306 
     307      domain->bounds_lat_2d.resize(nbVertex,ni,nj); 
    263308      readFieldVariableValue(domain->bounds_lat_2d, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
    264       domain->bounds_lon_2d.resize(4,ni,nj); 
     309      domain->bounds_lon_2d.resize(nbVertex,ni,nj); 
    265310      readFieldVariableValue(domain->bounds_lon_2d, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
    266     } 
    267     else if (this->isUnstructured(fieldId)) 
    268     { 
    269  
    270311    } 
    271312  } 
     
    278319    \param [in] fieldId id (or name) associated with the grid 
    279320  */ 
    280   void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::map<StdString, StdSize>& dimSizeMap, 
     321  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    281322                                                   int elementPosition, const StdString& fieldId) 
    282323  { 
    283324    // There are some mandatory attributes of a domain to retrieve from file 
    284325    // + ni_glo, nj_glo 
    285     std::map<StdString, StdSize>::const_iterator itMapNj = dimSizeMap.begin(), itMapNi, 
    286                                                  iteMap  = dimSizeMap.end(); 
    287     for (int i = 0; i < elementPosition; ++i, ++itMapNj) {} 
    288     itMapNi = itMapNj; ++itMapNi; 
     326    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj, 
     327                                                              iteMap  = dimSizeMap.end(); 
     328    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {} 
     329    itMapNj = itMapNi; ++itMapNj; 
    289330 
    290331    if (this->isRectilinear(fieldId) || this->isCurvilinear(fieldId)) 
    291332    { 
    292333      domain->nj_glo.setValue(itMapNj->second); 
    293       domain->ni_glo.setValue((itMapNi)->second); 
     334      domain->ni_glo.setValue(itMapNi->second); 
    294335    } 
    295336    else if (this->isUnstructured(fieldId)) 
    296337    { 
    297  
     338      domain->nj_glo.setValue(1); 
     339      domain->ni_glo.setValue(itMapNi->second); 
    298340    } 
    299341  } 
     
    306348    \param [in] fieldId id (or name) associated with the grid 
    307349  */ 
    308   void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::map<StdString, StdSize>& dimSizeMap, 
     350  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    309351                                                 int elementPosition, const StdString& fieldId) 
    310352  { 
    311     std::map<StdString, StdSize>::const_iterator itMapN = dimSizeMap.begin(), 
    312                                                  iteMap = dimSizeMap.end(); 
     353    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(), 
     354                                                              iteMap = dimSizeMap.end(); 
    313355    for (int i = 0; i < elementPosition; ++i, ++itMapN) {} 
    314356    axis->n_glo.setValue(itMapN->second); 
     
    322364    \param [in] fieldId id (or name) associated with the grid 
    323365  */ 
    324   void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::map<StdString, StdSize>& dimSizeMap, 
     366  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    325367                                                    int elementPosition, const StdString& fieldId) 
    326368  { 
    327     std::map<StdString, StdSize>::const_iterator itMapN = dimSizeMap.begin(), 
    328                                                  iteMap = dimSizeMap.end(); 
     369    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(), 
     370                                                              iteMap = dimSizeMap.end(); 
    329371    for (int i = 0; i < elementPosition; ++i, ++itMapN) {} 
    330372 
  • XIOS/trunk/src/io/nc4_data_input.hpp

    r782 r783  
    4040 
    4141  private: 
    42     void readDomainAttributesFromFile(CDomain* domain, std::map<StdString, StdSize>& dimSizeMap, 
     42    void readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    4343                                      int elementPosition, const StdString& fieldId); 
    44     void readDomainAttributeValueFromFile(CDomain* domain, std::map<StdString, StdSize>& dimSizeMap, 
     44    void readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    4545                                          int elementPosition, const StdString& fieldId); 
    4646 
    47     void readAxisAttributesFromFile(CAxis* axis, std::map<StdString, StdSize>& dimSizeMap, 
     47    void readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    4848                                    int elementPosition, const StdString& fieldId); 
    49     void readAxisAttributeValueFromFile(CAxis* axis, std::map<StdString, StdSize>& dimSizeMap, 
     49    void readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    5050                                        int elementPosition, const StdString& fieldId); 
    5151 
  • XIOS/trunk/src/node/domain.cpp

    r782 r783  
    228228   { 
    229229     if (this->isRedistributed_) return; 
     230 
     231     this->isRedistributed_ = true; 
     232     CContext* context = CContext::getCurrent(); 
     233     CContextClient* client = context->client; 
     234     int rankClient = client->clientRank; 
     235     int rankOnDomain = rankClient%nbLocalDomain; 
     236 
     237     if (ni_glo.isEmpty() || ni_glo <= 0 ) 
     238     { 
     239        ERROR("CDomain::redistribute(int nbLocalDomain)", 
     240           << "[ Id = " << this->getId() << " ] " 
     241           << "The global domain is badly defined," 
     242           << " check the \'ni_glo\'  value !") 
     243     } 
     244 
     245     if (nj_glo.isEmpty() || nj_glo <= 0 ) 
     246     { 
     247        ERROR("CDomain::redistribute(int nbLocalDomain)", 
     248           << "[ Id = " << this->getId() << " ] " 
     249           << "The global domain is badly defined," 
     250           << " check the \'nj_glo\'  value !") 
     251     } 
     252 
    230253     if ((type_attr::rectilinear == type)  || (type_attr::curvilinear == type)) 
    231254     { 
    232         this->isRedistributed_ = true; 
    233  
    234         CContext* context = CContext::getCurrent(); 
    235         CContextClient* client = context->client; 
    236         int rankClient = client->clientRank; 
    237         int rankOnDomain = rankClient%nbLocalDomain; 
    238  
    239         if (ni_glo.isEmpty() || ni_glo <= 0 ) 
    240         { 
    241            ERROR("CDomain::redistribute(int nbLocalDomain)", 
    242               << "[ Id = " << this->getId() << " ] " 
    243               << "The global domain is badly defined," 
    244               << " check the \'ni_glo\'  value !") 
    245         } 
    246  
    247         if (nj_glo.isEmpty() || nj_glo <= 0 ) 
    248         { 
    249            ERROR("CDomain::redistribute(int nbLocalDomain)", 
    250               << "[ Id = " << this->getId() << " ] " 
    251               << "The global domain is badly defined," 
    252               << " check the \'nj_glo\'  value !") 
    253         } 
    254  
    255255        int globalDomainSize = ni_glo * nj_glo; 
    256256        if (globalDomainSize <= nbLocalDomain) 
     
    329329        // Now fill other attributes 
    330330        if (type_attr::rectilinear == type) fillInRectilinearLonLat(); 
     331     } 
     332     else  // unstructured domain 
     333     { 
     334        int globalDomainSize = ni_glo * nj_glo; 
     335        if (globalDomainSize <= nbLocalDomain) 
     336        { 
     337          for (int idx = 0; idx < nbLocalDomain; ++idx) 
     338          { 
     339            if (rankOnDomain < globalDomainSize) 
     340            { 
     341              int iIdx = rankOnDomain % ni_glo; 
     342              int jIdx = rankOnDomain / ni_glo; 
     343              ibegin.setValue(iIdx); jbegin.setValue(jIdx); 
     344              ni.setValue(1); nj.setValue(1); 
     345            } 
     346            else 
     347            { 
     348              ibegin.setValue(0); jbegin.setValue(0); 
     349              ni.setValue(0); nj.setValue(0); 
     350            } 
     351          } 
     352        } 
     353        else 
     354        { 
     355          float njGlo = nj_glo.getValue(); 
     356          float niGlo = ni_glo.getValue(); 
     357          std::vector<int> ibeginVec(nbLocalDomain,0); 
     358          std::vector<int> niVec(nbLocalDomain); 
     359          for (int i = 1; i < nbLocalDomain; ++i) 
     360          { 
     361            int range = ni_glo / nbLocalDomain; 
     362            if (i < (ni_glo%nbLocalDomain)) ++range; 
     363            niVec[i-1] = range; 
     364            ibeginVec[i] = ibeginVec[i-1] + niVec[i-1]; 
     365          } 
     366          niVec[nbLocalDomain-1] = ni_glo - ibeginVec[nbLocalDomain-1]; 
     367 
     368          int iIdx = rankOnDomain % nbLocalDomain; 
     369          ibegin.setValue(ibeginVec[iIdx]); 
     370          jbegin.setValue(0); 
     371          ni.setValue(niVec[iIdx]); 
     372          nj.setValue(1); 
     373        } 
    331374     } 
    332375   } 
  • XIOS/trunk/src/test/test_remap.f90

    r775 r783  
    2020  DOUBLE PRECISION,ALLOCATABLE :: src_boundslon(:,:), dst_boundslon(:,:) 
    2121  DOUBLE PRECISION,ALLOCATABLE :: src_boundslat(:,:), dst_boundslat(:,:) 
    22   DOUBLE PRECISION,ALLOCATABLE :: src_field(:), tmp_field(:), tmp_field_1(:) 
     22  DOUBLE PRECISION,ALLOCATABLE :: src_field(:), tmp_field(:), tmp_field_1(:), tmp_field_2(:) 
    2323  INTEGER :: src_ni_glo, dst_ni_glo; 
    2424  INTEGER :: src_nvertex, dst_nvertex; 
     
    132132  ALLOCATE(tmp_field_1(src_tmp_ni*src_tmp_nj*src_tmp_n)) 
    133133 
     134  CALL xios_get_domain_attr("domain_src_unstructured", ni=src_tmp_ni, nj=src_tmp_nj) 
     135  ALLOCATE(tmp_field_2(src_tmp_ni*src_tmp_nj)) 
     136 
    134137  DO ts=1,1 
    135138    CALL xios_recv_field("src_field_regular_tmp", tmp_field) 
    136139    CALL xios_recv_field("src_field_curvilinear", tmp_field_1) 
     140    CALL xios_recv_field("field_src_unstructred", tmp_field_2) 
    137141    CALL xios_update_calendar(ts) 
    138142    CALL xios_send_field("src_field",src_field) 
    139143    CALL xios_send_field("tmp_field",tmp_field) 
    140144    CALL xios_send_field("tmp_field_1",tmp_field_1) 
     145    CALL xios_send_field("tmp_field_2",tmp_field_2) 
    141146    CALL wait_us(5000) ; 
    142147  ENDDO 
     
    146151  DEALLOCATE(src_lon, src_lat, src_boundslon,src_boundslat, src_field) 
    147152  DEALLOCATE(dst_lon, dst_lat, dst_boundslon,dst_boundslat) 
     153  DEALLOCATE(tmp_field, tmp_field_1, tmp_field_2) 
    148154 
    149155  CALL MPI_COMM_FREE(comm, ierr) 
Note: See TracChangeset for help on using the changeset viewer.