Ignore:
Timestamp:
12/06/20 22:14:56 (4 years ago)
Author:
ymipsl
Message:

intermediate commit for new tranformation engine?
YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp

    r1974 r1984  
    2424#include "grid_local_view.hpp" 
    2525#include "grid_mask_connector.hpp" 
    26  
    27  
    28 namespace xios { 
     26#include "transformation_path.hpp" 
     27#include "grid_transformation_factory_impl.hpp" 
     28#include "transform_filter.hpp" 
     29 
     30 
     31namespace xios 
     32{ 
    2933 
    3034   /// ////////////////////// Dfinitions ////////////////////// /// 
     
    236240     axis_domain_order.resize(order_.size()); 
    237241     for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 
    238      return vDomainGroup_->createChild(id); 
     242     CDomain* domain = vDomainGroup_->createChild(id); 
     243     computeElements(); 
     244     return domain ; 
    239245   } 
    240246   CATCH_DUMP_ATTR 
     
    246252     axis_domain_order.resize(order_.size()); 
    247253     for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 
    248      return vAxisGroup_->createChild(id); 
     254     CAxis* axis=vAxisGroup_->createChild(id); 
     255     computeElements();  
     256     return axis ; 
    249257   } 
    250258   CATCH_DUMP_ATTR 
     
    256264     axis_domain_order.resize(order_.size()); 
    257265     for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 
    258      return vScalarGroup_->createChild(id); 
     266     CScalar* scalar =  vScalarGroup_->createChild(id); 
     267     computeElements(); 
     268     return scalar; 
    259269   } 
    260270   CATCH_DUMP_ATTR 
     
    518528    int idxDomain = 0, idxAxis=0 , idxScalar=0 ;  
    519529  
     530    elements_.clear() ; 
    520531    for(auto type : order_) 
    521532    { 
     
    572583    setAxisList(); 
    573584    setScalarList(); 
     585    computeElements() ; 
    574586   } 
    575587   CATCH_DUMP_ATTR 
     
    960972 
    961973    
    962 //---------------------------------------------------------------- 
    963  
    964974 
    965975 
     
    18711881 
    18721882 
    1873  
    1874  
    1875  
    1876  
    1877  
    18781883  bool CGrid::hasTransform() 
    18791884  TRY 
     
    18921897  } 
    18931898  CATCH_DUMP_ATTR 
     1899 
     1900 
     1901 
     1902//********************************************************** 
     1903//**************   New transformation method  ************** 
     1904//********************************************************** 
     1905 
     1906  std::pair<std::shared_ptr<CFilter>, std::shared_ptr<CFilter> >  
     1907  CGrid::buildTransformationGraph(CGarbageCollector& gc, CGrid* gridSrc, double detectMissingValues, double defaultValue, CGrid*& newGrid) 
     1908  TRY 
     1909  { 
     1910    std::shared_ptr<CFilter> inputFilter = std::shared_ptr<CPassThroughFilter>(new CPassThroughFilter(gc)); 
     1911    std::shared_ptr<CFilter> outputFilter = inputFilter ; 
     1912     
     1913    newGrid = CGrid::create() ; // give it an id later ?? 
     1914    bool hadTransform=false ; 
     1915    bool hasTransform=false ; 
     1916    CGenericAlgorithmTransformation* algo ; 
     1917    int dimBefore=1 ; 
     1918    int dimAfter=1 ; 
     1919 
     1920    for(int i=0 ; i<elements_.size(); i++) 
     1921    { 
     1922      CTransformationPaths transformationPath ; 
     1923      auto dstElement = elements_[i] ; 
     1924 
     1925      if (dstElement.type==TYPE_DOMAIN)      transformationPath = dstElement.domain->getTransformationPaths() ; 
     1926      else if (dstElement.type==TYPE_AXIS)   transformationPath = dstElement.axis->getTransformationPaths() ; 
     1927      else if (dstElement.type==TYPE_SCALAR) transformationPath = dstElement.scalar->getTransformationPaths() ; 
     1928 
     1929      SElement srcElement  ; 
     1930      if (gridSrc==nullptr) srcElement = this->elements_[i] ; 
     1931      else srcElement = gridSrc->elements_[i] ; 
     1932 
     1933      if (gridSrc==nullptr) transformationPath.mergePaths() ; 
     1934      else 
     1935      {   
     1936        if (srcElement.type==TYPE_DOMAIN)      transformationPath.mergePaths(srcElement.domain->getTransformationPaths()) ; 
     1937        else if (srcElement.type==TYPE_AXIS)   transformationPath.mergePaths(srcElement.axis->getTransformationPaths()) ; 
     1938        else if (srcElement.type==TYPE_SCALAR) transformationPath.mergePaths(srcElement.scalar->getTransformationPaths()) ; 
     1939      } 
     1940 
     1941      hasTransform=transformationPath.hasTransform()  ; 
     1942       
     1943 
     1944      if (hasTransform && !hadTransform) 
     1945      { 
     1946        EElement dstElementType=transformationPath.getNextElementType() ; 
     1947        string dstElementId=transformationPath.getNextElementId() ; 
     1948        string srcElementId=transformationPath.getNextElementSrcId() ; 
     1949        auto transType = transformationPath.getNextTransformationType() ; 
     1950        auto transId = transformationPath.getNextTransformationId() ; 
     1951 
     1952        CGrid* tmpGridSrc=CGrid::create(); // source grid  
     1953        if (srcElement.type==TYPE_DOMAIN)      tmpGridSrc->addDomain(srcElement.domain->getId()) ; 
     1954        else if (srcElement.type==TYPE_AXIS)   tmpGridSrc->addAxis(srcElement.axis->getId()) ; 
     1955        else if (srcElement.type==TYPE_SCALAR) tmpGridSrc->addScalar(srcElement.scalar->getId()) ; 
     1956        tmpGridSrc->checkElementsAttributes() ; 
     1957        CGrid* tmpGridDst=CGrid::create(); // destination Grid 
     1958        map<int,int> posInGrid={{0,0}} ; 
     1959                
     1960        cout<<"--> New transform from "<<srcElementId<<" to "<<dstElementId<<endl ; 
     1961        if (dstElementType==EElement::DOMAIN) 
     1962        { 
     1963          CDomain* dstDomain ; 
     1964          if (CDomain::has(dstElementId)) dstDomain = CDomain::get(dstElementId) ; 
     1965          else 
     1966          { 
     1967            dstDomain = CDomain::create() ; 
     1968            dstDomain->createAlias(dstElementId) ; 
     1969            if (srcElementId=="" && srcElement.type==TYPE_DOMAIN)  dstDomain->duplicateAttributes(srcElement.domain) ; // make a copy 
     1970            else dstDomain->duplicateAttributes(CDomain::get(srcElementId)) ; // make a copy 
     1971            CTransformation<CDomain>* transformation = CTransformation<CDomain>::createTransformation(transType,"") ; 
     1972            auto srcTransform = CTransformation<CDomain>::getTransformation(transType, transId) ; 
     1973            transformation->inheritFrom(srcTransform) ; 
     1974            tmpGridDst->addDomain(dstDomain->getId()) ; 
     1975 
     1976            //reuse existing algorithm interface for, now 
     1977            algo = CGridTransformationFactory<CDomain>::createTransformation(transType, tmpGridDst, tmpGridSrc, 
     1978                                                                             transformation, 0,  
     1979                                                                             posInGrid,posInGrid,posInGrid, 
     1980                                                                             posInGrid,posInGrid,posInGrid ); 
     1981            dstDomain->setTransformationAlgorithm(algo) ; 
     1982            transformationPath.removeNextTransform() ; 
     1983            dstDomain->setTransformationPaths(transformationPath) ; 
     1984            newGrid->addDomain(dstDomain->getId()) ; 
     1985          } 
     1986          algo = dstDomain->getTransformationAlgorithm() ; 
     1987        } 
     1988        else if (dstElementType==EElement::AXIS) 
     1989        { 
     1990          CAxis* dstAxis ; 
     1991          if (CAxis::has(dstElementId)) dstAxis = CAxis::get(dstElementId) ; 
     1992          else 
     1993          { 
     1994            dstAxis = CAxis::create() ; 
     1995            dstAxis->createAlias(dstElementId) ; 
     1996            if (srcElementId=="" && srcElement.type==TYPE_AXIS)  dstAxis->duplicateAttributes(srcElement.axis) ; // make a copy 
     1997            else dstAxis->duplicateAttributes(CAxis::get(srcElementId)) ; // make a copy 
     1998            CTransformation<CAxis>* transformation = CTransformation<CAxis>::createTransformation(transType,"") ; 
     1999            auto srcTransform = CTransformation<CAxis>::getTransformation(transType, transId) ; 
     2000            transformation->inheritFrom(srcTransform) ; 
     2001            tmpGridDst->addAxis(dstAxis->getId()) ; 
     2002 
     2003            //reuse existing algorithm interface for, now 
     2004            algo = CGridTransformationFactory<CAxis>::createTransformation(transType, tmpGridDst, tmpGridSrc, 
     2005                                                                           transformation, 0,  
     2006                                                                           posInGrid,posInGrid,posInGrid, 
     2007                                                                           posInGrid,posInGrid,posInGrid ); 
     2008            dstAxis->setTransformationAlgorithm(algo) ; 
     2009            transformationPath.removeNextTransform() ; 
     2010            dstAxis->setTransformationPaths(transformationPath) ; 
     2011            newGrid->addAxis(dstAxis->getId()) ; 
     2012          } 
     2013          algo = dstAxis->getTransformationAlgorithm() ; 
     2014        } 
     2015        else if (dstElementType==EElement::SCALAR) 
     2016        { 
     2017          CScalar* dstScalar ; 
     2018          if (CScalar::has(dstElementId)) dstScalar = CScalar::get(dstElementId) ; 
     2019          else 
     2020          { 
     2021            dstScalar = CScalar::create() ; 
     2022            dstScalar->createAlias(dstElementId) ; 
     2023            if (srcElementId=="" && srcElement.type==TYPE_SCALAR)  dstScalar->duplicateAttributes(srcElement.scalar) ; // make a copy 
     2024            else dstScalar->duplicateAttributes(CScalar::get(srcElementId)) ; // make a copy 
     2025            CTransformation<CScalar>* transformation = CTransformation<CScalar>::createTransformation(transType,"") ; 
     2026            auto srcTransform = CTransformation<CScalar>::getTransformation(transType, transId) ; 
     2027            transformation->inheritFrom(srcTransform) ; 
     2028            tmpGridDst->addScalar(dstScalar->getId()) ; 
     2029 
     2030            //reuse existing algorithm interface for, now 
     2031            algo = CGridTransformationFactory<CScalar>::createTransformation(transType, tmpGridDst, tmpGridSrc, 
     2032                                                                             transformation, 0,  
     2033                                                                             posInGrid,posInGrid,posInGrid, 
     2034                                                                             posInGrid,posInGrid,posInGrid ); 
     2035            dstScalar->setTransformationAlgorithm(algo) ; 
     2036            transformationPath.removeNextTransform() ; 
     2037            dstScalar->setTransformationPaths(transformationPath) ; 
     2038            newGrid->addScalar(dstScalar->getId()) ; 
     2039          } 
     2040          algo = dstScalar->getTransformationAlgorithm() ;           
     2041        } 
     2042        // here create a new spatial filter with algo 
     2043         
     2044        hadTransform=true ; 
     2045        hasTransform=false ;  
     2046      } 
     2047      else 
     2048      { 
     2049        string srcElementId=transformationPath.getNextElementSrcId() ; 
     2050        if (srcElement.type==TYPE_DOMAIN)       
     2051        { 
     2052          CDomain* domain ; 
     2053          if (!CDomain::has(srcElementId))  
     2054          { 
     2055            domain=srcElement.domain ; 
     2056            domain->createAlias(srcElementId) ; 
     2057          } 
     2058          else domain = CDomain::get(srcElementId) ; 
     2059          domain->checkAttributes() ; 
     2060          
     2061          if (hadTransform) dimBefore*=domain->getLocalView(CElementView::WORKFLOW)->getLocalSize() ; 
     2062          else dimAfter*=domain->getLocalView(CElementView::WORKFLOW)->getLocalSize() ; 
     2063          newGrid->addDomain(srcElementId) ; 
     2064        } 
     2065        else if (srcElement.type==TYPE_AXIS) 
     2066        {    
     2067          CAxis* axis ; 
     2068          if (!CAxis::has(srcElementId))  
     2069          { 
     2070            axis=srcElement.axis ; 
     2071            axis->createAlias(srcElementId) ; 
     2072          } 
     2073          else axis = CAxis::get(srcElementId) ; 
     2074          axis->checkAttributes() ; 
     2075          
     2076          if (hadTransform) dimBefore*=axis->getLocalView(CElementView::WORKFLOW)->getLocalSize() ; 
     2077          else dimAfter*=axis->getLocalView(CElementView::WORKFLOW)->getLocalSize() ; 
     2078          newGrid->addAxis(srcElementId) ; 
     2079        } 
     2080        else if (srcElement.type==TYPE_SCALAR) 
     2081        { 
     2082          CScalar* scalar ; 
     2083          if (!CScalar::has(srcElementId))  
     2084          { 
     2085            scalar=srcElement.scalar ; 
     2086            scalar->createAlias(srcElementId) ; 
     2087          } 
     2088          else scalar = CScalar::get(srcElementId) ; 
     2089          scalar->checkAttributes() ; 
     2090          
     2091          if (hadTransform) dimBefore*=scalar->getLocalView(CElementView::WORKFLOW)->getLocalSize() ; 
     2092          else dimAfter*=scalar->getLocalView(CElementView::WORKFLOW)->getLocalSize() ; 
     2093          newGrid->addScalar(srcElementId) ; 
     2094        } 
     2095      } 
     2096    }   
     2097     
     2098    if (hadTransform) 
     2099    { 
     2100      shared_ptr<CTransformFilter> transformFilter = shared_ptr<CTransformFilter>(new CTransformFilter(gc, algo, dimBefore, dimAfter, detectMissingValues, defaultValue)) ; 
     2101      outputFilter->connectOutput(transformFilter,0) ; 
     2102      outputFilter = transformFilter ; 
     2103 
     2104      gridSrc=newGrid ; 
     2105      pair<shared_ptr<CFilter>, shared_ptr<CFilter> > filters = gridSrc->buildTransformationGraph(gc, gridSrc, detectMissingValues, defaultValue, newGrid) ; 
     2106      outputFilter->connectOutput(filters.first,0) ; 
     2107      outputFilter=filters.second ; 
     2108    } 
     2109      
     2110    return {inputFilter,outputFilter} ; 
     2111  } 
     2112  CATCH_DUMP_ATTR 
     2113 
     2114 
     2115//**************************************************************** 
     2116//**************************************************************** 
     2117 
     2118//---------------------------------------------------------------- 
     2119 
     2120  CGrid* CGrid::duplicateSentGrid(void) 
     2121  { 
     2122    CGrid* newGrid ; 
     2123    string sentGridId="sent__"+getId() ; 
     2124    if (has(sentGridId)) newGrid = get(sentGridId) ; 
     2125    else 
     2126    { 
     2127      newGrid = CGrid::create(sentGridId) ; 
     2128      for(auto element : elements_) 
     2129      { 
     2130        if (element.type==TYPE_DOMAIN)       
     2131        { 
     2132          CDomain* domain = CDomain::create(); 
     2133          domain->duplicateAttributes(element.domain) ; 
     2134          domain->name = element.domain->getId() ; 
     2135          newGrid->addDomain(domain->getId()) ; 
     2136        } 
     2137        else if (element.type==TYPE_AXIS)       
     2138        { 
     2139          CAxis* axis = CAxis::create(); 
     2140          axis->duplicateAttributes(element.axis) ; 
     2141          axis->name = element.axis->getId() ; 
     2142          newGrid->addAxis(axis->getId()) ; 
     2143        } 
     2144        else if (element.type==TYPE_SCALAR)       
     2145        { 
     2146          CScalar* scalar = CScalar::create(); 
     2147          scalar->duplicateAttributes(element.scalar) ; 
     2148          scalar->name = element.scalar->getId() ; 
     2149          newGrid->addScalar(scalar->getId()) ; 
     2150        } 
     2151      } 
     2152      newGrid->checkElementsAttributes() ; 
     2153    } 
     2154    return newGrid ; 
     2155  } 
     2156 
    18942157 
    18952158  void CGrid::setContextClient(CContextClient* contextClient) 
Note: See TracChangeset for help on using the changeset viewer.