Ignore:
Timestamp:
12/07/22 18:42:46 (19 months ago)
Author:
ymipsl
Message:

Add bounds management for rectilinear domain.
First try.
YM

File:
1 edited

Legend:

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

    r2314 r2440  
    187187       size_t sizeLonLatEvent = CArray<double,1>::size(idxCount); 
    188188       if (hasBounds) 
    189          sizeLonLatEvent += CArray<double,2>::size(nvertex * idxCount); 
     189       { 
     190         int nvertexValue ; 
     191         if (type==type_attr::rectilinear || type==type_attr::curvilinear) nvertexValue=4 ; 
     192         else nvertexValue=nvertex ; 
     193         sizeLonLatEvent += CArray<double,2>::size(nvertexValue * idxCount); 
     194       } 
    190195 
    191196       size_t size = CEventClient::headerSize + getId().size() + sizeof(size_t) + std::max(sizeIndexEvent, sizeLonLatEvent); 
     
    14281433           if (hasBounds) 
    14291434           { 
    1430              bounds_lonvalue.resize(nvertex, ni * nj); 
    1431              bounds_latvalue.resize(nvertex, ni * nj); 
     1435             bounds_lonvalue.resize(4, ni * nj); 
     1436             bounds_latvalue.resize(4, ni * nj); 
    14321437           } 
    14331438 
     
    14431448               if (hasBounds) 
    14441449               { 
    1445                  for (int n = 0; n < nvertex; ++n) 
    1446                  { 
    1447                    bounds_lonvalue(n,k) = bounds_lon_1d(n,i); 
    1448                    bounds_latvalue(n,k) = bounds_lat_1d(n,j); 
    1449                  } 
     1450                  bounds_lonvalue(0,k) = bounds_lon_1d(0,i); 
     1451                  bounds_latvalue(0,k) = bounds_lat_1d(0,j); 
     1452                  bounds_lonvalue(1,k) = bounds_lon_1d(1,i); 
     1453                  bounds_latvalue(1,k) = bounds_lat_1d(0,j); 
     1454                  bounds_lonvalue(2,k) = bounds_lon_1d(1,i); 
     1455                  bounds_latvalue(2,k) = bounds_lat_1d(1,j); 
     1456                  bounds_lonvalue(3,k) = bounds_lon_1d(0,i); 
     1457                  bounds_latvalue(3,k) = bounds_lat_1d(1,j); 
    14501458               } 
    14511459             } 
     
    15451553           if (hasBounds) 
    15461554           { 
    1547              bounds_lonvalue.resize(nvertex, ni * nj); 
    1548              bounds_latvalue.resize(nvertex, ni * nj); 
     1555             bounds_lonvalue.resize(4, ni * nj); 
     1556             bounds_latvalue.resize(4, ni * nj); 
    15491557           } 
    15501558 
     
    15601568               if (hasBounds) 
    15611569               { 
    1562                  for (int n = 0; n < nvertex; ++n) 
    1563                  { 
    1564                    bounds_lonvalue(n,k) = bounds_lon_1d(n,i); 
    1565                    bounds_latvalue(n,k) = bounds_lat_1d(n,j); 
    1566                  } 
     1570                  bounds_lonvalue(0,k) = bounds_lon_1d(0,i); 
     1571                  bounds_latvalue(0,k) = bounds_lat_1d(0,j); 
     1572                  bounds_lonvalue(1,k) = bounds_lon_1d(1,i); 
     1573                  bounds_latvalue(1,k) = bounds_lat_1d(0,j); 
     1574                  bounds_lonvalue(2,k) = bounds_lon_1d(1,i); 
     1575                  bounds_latvalue(2,k) = bounds_lat_1d(1,j); 
     1576                  bounds_lonvalue(3,k) = bounds_lon_1d(0,i); 
     1577                  bounds_latvalue(3,k) = bounds_lat_1d(1,j); 
    15671578               } 
    15681579             } 
     
    16051616   TRY 
    16061617   { 
     1618     int nvertexValue ;  
    16071619     bool hasBoundValues = (0 != bounds_lonvalue.numElements()) || (0 != bounds_latvalue.numElements()); 
    1608      if (!nvertex.isEmpty() && nvertex > 0 && !hasBoundValues) 
    1609      { 
    1610        if (!bounds_lon_1d.isEmpty() && !bounds_lon_2d.isEmpty()) 
    1611          ERROR("CDomain::checkBounds(void)", 
    1612                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1613                << "Only one longitude boundary attribute can be used but both 'bounds_lon_1d' and 'bounds_lon_2d' are defined." << std::endl 
    1614                << "Define only one longitude boundary attribute: 'bounds_lon_1d' or 'bounds_lon_2d'."); 
    1615  
    1616        if (!bounds_lat_1d.isEmpty() && !bounds_lat_2d.isEmpty()) 
    1617          ERROR("CDomain::checkBounds(void)", 
    1618                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1619                << "Only one latitude boundary attribute can be used but both 'bounds_lat_1d' and 'bounds_lat_2d' are defined." << std::endl 
    1620                << "Define only one latitude boundary attribute: 'bounds_lat_1d' or 'bounds_lat_2d'."); 
    1621  
    1622        if ((!bounds_lon_1d.isEmpty() && bounds_lat_1d.isEmpty()) || (bounds_lon_1d.isEmpty() && !bounds_lat_1d.isEmpty())) 
    1623        { 
    1624          ERROR("CDomain::checkBounds(void)", 
    1625                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1626                << "Only 'bounds_lon_1d' or 'bounds_lat_1d' is defined." << std::endl 
    1627                << "Please define either both attributes or none."); 
    1628        } 
    1629  
    1630        if ((!bounds_lon_2d.isEmpty() && bounds_lat_2d.isEmpty()) || (bounds_lon_2d.isEmpty() && !bounds_lat_2d.isEmpty())) 
    1631        { 
    1632          ERROR("CDomain::checkBounds(void)", 
    1633                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1634                << "Only 'bounds_lon_2d' or 'bounds_lat_2d' is defined." << std::endl 
    1635                << "Please define either both attributes or none."); 
    1636        } 
    1637  
    1638        if (!bounds_lon_1d.isEmpty() && nvertex.getValue() != bounds_lon_1d.extent(0)) 
    1639          ERROR("CDomain::checkBounds(void)", 
    1640                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1641                << "'bounds_lon_1d' dimension is not compatible with 'nvertex'." << std::endl 
    1642                << "'bounds_lon_1d' dimension is " << bounds_lon_1d.extent(0) 
    1643                << " but nvertex is " << nvertex.getValue() << "."); 
    1644  
    1645        if (!bounds_lon_2d.isEmpty() && nvertex.getValue() != bounds_lon_2d.extent(0)) 
    1646          ERROR("CDomain::checkBounds(void)", 
    1647                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1648                << "'bounds_lon_2d' dimension is not compatible with 'nvertex'." << std::endl 
    1649                << "'bounds_lon_2d' dimension is " << bounds_lon_2d.extent(0) 
    1650                << " but nvertex is " << nvertex.getValue() << "."); 
    1651  
    1652        if (!bounds_lon_1d.isEmpty() && lonvalue_1d.isEmpty()) 
    1653          ERROR("CDomain::checkBounds(void)", 
    1654                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1655                << "Since 'bounds_lon_1d' is defined, 'lonvalue_1d' must be defined too." << std::endl); 
    1656  
    1657        if (!bounds_lon_2d.isEmpty() && lonvalue_2d.isEmpty()) 
    1658          ERROR("CDomain::checkBounds(void)", 
    1659                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1660                << "Since 'bounds_lon_2d' is defined, 'lonvalue_2d' must be defined too." << std::endl); 
    1661  
    1662        if (!bounds_lat_1d.isEmpty() && nvertex.getValue() != bounds_lat_1d.extent(0)) 
    1663          ERROR("CDomain::checkBounds(void)", 
    1664                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1665                << "'bounds_lat_1d' dimension is not compatible with 'nvertex'." << std::endl 
    1666                << "'bounds_lat_1d' dimension is " << bounds_lat_1d.extent(0) 
    1667                << " but nvertex is " << nvertex.getValue() << "."); 
    1668  
    1669        if (!bounds_lat_2d.isEmpty() && nvertex.getValue() != bounds_lat_2d.extent(0)) 
    1670          ERROR("CDomain::checkBounds(void)", 
    1671                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1672                << "'bounds_lat_2d' dimension is not compatible with 'nvertex'." << std::endl 
    1673                << "'bounds_lat_2d' dimension is " << bounds_lat_2d.extent(0) 
    1674                << " but nvertex is " << nvertex.getValue() << "."); 
    1675  
    1676        if (!bounds_lat_1d.isEmpty() && latvalue_1d.isEmpty()) 
    1677          ERROR("CDomain::checkBounds(void)", 
    1678                << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
    1679                << "Since 'bounds_lat_1d' is defined, 'latvalue_1d' must be defined too." << std::endl); 
    1680  
    1681        if (!bounds_lat_2d.isEmpty() && latvalue_2d.isEmpty()) 
    1682          ERROR("CDomain::checkBounds(void)", 
    1683                << "Since 'bounds_lat_2d' is defined, 'latvalue_2d' must be defined too." << std::endl); 
    1684  
    1685        // In case of reading UGRID bounds values are not required 
    1686        hasBounds = (!bounds_lat_1d.isEmpty() || !bounds_lat_2d.isEmpty() ); 
    1687      } 
    1688      else if (hasBoundValues) 
    1689      { 
    1690        hasBounds = true;        
    1691      } 
    1692      else 
    1693      { 
    1694        hasBounds = false; 
    1695      } 
     1620     if (hasBoundValues)  
     1621     { 
     1622       hasBounds=true ; 
     1623       return ; 
     1624      } 
     1625 
     1626     if (type_attr::rectilinear == type) nvertexValue=2 ; 
     1627     else if (type_attr::curvilinear == type) nvertexValue=4 ; 
     1628     else if (!nvertex.isEmpty() && nvertex>0) nvertexValue = nvertex ; 
     1629     else  
     1630     { 
     1631       hasBounds=false ; 
     1632       return ; 
     1633     } 
     1634     
     1635      if (!bounds_lon_1d.isEmpty() && !bounds_lon_2d.isEmpty()) 
     1636        ERROR("CDomain::checkBounds(void)", 
     1637              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1638              << "Only one longitude boundary attribute can be used but both 'bounds_lon_1d' and 'bounds_lon_2d' are defined." << std::endl 
     1639              << "Define only one longitude boundary attribute: 'bounds_lon_1d' or 'bounds_lon_2d'."); 
     1640 
     1641      if (!bounds_lat_1d.isEmpty() && !bounds_lat_2d.isEmpty()) 
     1642        ERROR("CDomain::checkBounds(void)", 
     1643              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1644              << "Only one latitude boundary attribute can be used but both 'bounds_lat_1d' and 'bounds_lat_2d' are defined." << std::endl 
     1645              << "Define only one latitude boundary attribute: 'bounds_lat_1d' or 'bounds_lat_2d'."); 
     1646 
     1647      if ((!bounds_lon_1d.isEmpty() && bounds_lat_1d.isEmpty()) || (bounds_lon_1d.isEmpty() && !bounds_lat_1d.isEmpty())) 
     1648      { 
     1649        ERROR("CDomain::checkBounds(void)", 
     1650              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1651              << "Only 'bounds_lon_1d' or 'bounds_lat_1d' is defined." << std::endl 
     1652              << "Please define either both attributes or none."); 
     1653      } 
     1654 
     1655      if ((!bounds_lon_2d.isEmpty() && bounds_lat_2d.isEmpty()) || (bounds_lon_2d.isEmpty() && !bounds_lat_2d.isEmpty())) 
     1656      { 
     1657        ERROR("CDomain::checkBounds(void)", 
     1658              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1659              << "Only 'bounds_lon_2d' or 'bounds_lat_2d' is defined." << std::endl 
     1660              << "Please define either both attributes or none."); 
     1661      } 
     1662 
     1663      if (!bounds_lon_1d.isEmpty() && nvertexValue != bounds_lon_1d.extent(0)) 
     1664        ERROR("CDomain::checkBounds(void)", 
     1665              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1666              << "'bounds_lon_1d' dimension is not compatible with 'nvertex'." << std::endl 
     1667              << "'bounds_lon_1d' dimension is " << bounds_lon_1d.extent(0) 
     1668              << " but nvertex is " << nvertexValue << "."); 
     1669 
     1670      if (!bounds_lon_2d.isEmpty() && nvertexValue != bounds_lon_2d.extent(0)) 
     1671        ERROR("CDomain::checkBounds(void)", 
     1672              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1673              << "'bounds_lon_2d' dimension is not compatible with 'nvertex'." << std::endl 
     1674              << "'bounds_lon_2d' dimension is " << bounds_lon_2d.extent(0) 
     1675              << " but nvertex is " << nvertexValue << "."); 
     1676 
     1677      if (!bounds_lon_1d.isEmpty() && lonvalue_1d.isEmpty()) 
     1678        ERROR("CDomain::checkBounds(void)", 
     1679              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1680              << "Since 'bounds_lon_1d' is defined, 'lonvalue_1d' must be defined too." << std::endl); 
     1681 
     1682      if (!bounds_lon_2d.isEmpty() && lonvalue_2d.isEmpty()) 
     1683        ERROR("CDomain::checkBounds(void)", 
     1684              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1685              << "Since 'bounds_lon_2d' is defined, 'lonvalue_2d' must be defined too." << std::endl); 
     1686 
     1687      if (!bounds_lat_1d.isEmpty() && nvertexValue != bounds_lat_1d.extent(0)) 
     1688        ERROR("CDomain::checkBounds(void)", 
     1689              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1690              << "'bounds_lat_1d' dimension is not compatible with 'nvertex'." << std::endl 
     1691              << "'bounds_lat_1d' dimension is " << bounds_lat_1d.extent(0) 
     1692              << " but nvertex is " << nvertexValue << "."); 
     1693 
     1694      if (!bounds_lat_2d.isEmpty() && nvertex.getValue() != bounds_lat_2d.extent(0)) 
     1695        ERROR("CDomain::checkBounds(void)", 
     1696              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1697              << "'bounds_lat_2d' dimension is not compatible with 'nvertex'." << std::endl 
     1698              << "'bounds_lat_2d' dimension is " << bounds_lat_2d.extent(0) 
     1699              << " but nvertex is " << nvertexValue << "."); 
     1700 
     1701      if (!bounds_lat_1d.isEmpty() && latvalue_1d.isEmpty()) 
     1702        ERROR("CDomain::checkBounds(void)", 
     1703              << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1704              << "Since 'bounds_lat_1d' is defined, 'latvalue_1d' must be defined too." << std::endl); 
     1705 
     1706      if (!bounds_lat_2d.isEmpty() && latvalue_2d.isEmpty()) 
     1707        ERROR("CDomain::checkBounds(void)", 
     1708              << "Since 'bounds_lat_2d' is defined, 'latvalue_2d' must be defined too." << std::endl); 
     1709 
     1710      // In case of reading UGRID bounds values are not required 
     1711      hasBounds = (!bounds_lat_1d.isEmpty() || !bounds_lat_2d.isEmpty() ); 
    16961712   } 
    16971713   CATCH_DUMP_ATTR 
     
    24512467        if (hasBounds) 
    24522468        { 
    2453           list_boundslon.push_back(CArray<double,2>(nvertex, nbData)); 
    2454           list_boundslat.push_back(CArray<double,2>(nvertex, nbData)); 
     2469          int nvertexValue ; 
     2470          if (type==type_attr::rectilinear || type==type_attr::curvilinear) nvertexValue=4 ; 
     2471          else nvertexValue=nvertex ; 
     2472          list_boundslon.push_back(CArray<double,2>(nvertexValue, nbData)); 
     2473          list_boundslat.push_back(CArray<double,2>(nvertexValue, nbData)); 
    24552474        } 
    24562475 
     
    24692488            CArray<double,2>& boundslon = list_boundslon.back(); 
    24702489            CArray<double,2>& boundslat = list_boundslat.back(); 
    2471  
    2472             for (nv = 0; nv < nvertex; ++nv) 
     2490             
     2491            int nvertexValue ; 
     2492            if (type==type_attr::rectilinear || type==type_attr::curvilinear) nvertexValue=4 ; 
     2493            else nvertexValue=nvertex ; 
     2494             
     2495            for (nv = 0; nv < nvertexValue; ++nv) 
    24732496            { 
    24742497              boundslon(nv, n) = bounds_lonvalue(nv, localInd); 
     
    28172840      if (hasBounds) 
    28182841      { 
    2819         bounds_lonvalue.resize(nvertex,nbLonInd); 
     2842        int nvertexValue = (type==type_attr::rectilinear || type==type_attr::curvilinear) ? 4 : nvertex ; 
     2843        bounds_lonvalue.resize(nvertexValue,nbLonInd); 
    28202844        bounds_lonvalue = 0.; 
    28212845      } 
     
    28322856           if (hasBounds) 
    28332857           {           
    2834             for (int nv = 0; nv < nvertex; ++nv) 
    2835               bounds_lonvalue(nv, lInd) = recvBoundsLonValue[i](nv, ind); 
     2858              int nvertexValue = (type==type_attr::rectilinear || type==type_attr::curvilinear) ? 4 : nvertex ; 
     2859              for (int nv = 0; nv < nvertexValue; ++nv) 
     2860                bounds_lonvalue(nv, lInd) = recvBoundsLonValue[i](nv, ind); 
    28362861           }                   
    28372862        } 
     
    29052930      if (hasBounds) 
    29062931      { 
    2907         bounds_latvalue.resize(nvertex,nbLatInd); 
     2932        int nvertexValue = (type==type_attr::rectilinear || type==type_attr::curvilinear) ? 4 : nvertex ; 
     2933         
     2934        bounds_latvalue.resize(nvertexValue,nbLatInd); 
    29082935        bounds_latvalue = 0. ; 
    29092936      } 
     
    29202947           if (hasBounds) 
    29212948           { 
    2922             CArray<double,2>& boundslat = recvBoundsLatValue[i]; 
    2923             for (int nv = 0; nv < nvertex; ++nv) 
    2924               bounds_latvalue(nv, lInd) = boundslat(nv, ind); 
     2949             int nvertexValue = (type==type_attr::rectilinear || type==type_attr::curvilinear) ? 4 : nvertex ; 
     2950 
     2951             CArray<double,2>& boundslat = recvBoundsLatValue[i]; 
     2952             for (int nv = 0; nv < nvertexValue; ++nv) 
     2953             bounds_latvalue(nv, lInd) = boundslat(nv, ind); 
    29252954           }    
    29262955          ++nbLatInd; 
Note: See TracChangeset for help on using the changeset viewer.