Ignore:
Timestamp:
07/05/16 15:59:02 (4 years ago)
Author:
mhnguyen
Message:

Adding a new type of element into grid: Scalar

+) Add a new node Scalar for xml
+) Make some change on writing scalar value
+) Reorganize some codes
+) Remove some redundant codes

Test
+) On Curie
+) All tests pass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/transformation/grid_generate.cpp

    r775 r887  
    33   \author Ha NGUYEN 
    44   \since 28 Aug 2015 
    5    \date 28 Aug 2015 
     5   \date 23 June 2016 
    66 
    77   \brief A special transformation to generate a grid. 
    88 */ 
    99#include "grid_generate.hpp" 
     10#include "grid.hpp" 
    1011#include "domain_algorithm_generate_rectilinear.hpp" 
    11 #include "context.hpp" 
    12 #include "context_client.hpp" 
    1312#include "generate_rectilinear_domain.hpp" 
    1413 
    1514namespace xios { 
    1615CGridGenerate::CGridGenerate(CGrid* destination, CGrid* source) 
    17 : gridSource_(source), gridDestination_(destination), algoTypes_() 
     16  : CGridTransformationSelector(destination, source) 
    1817{ 
    19   if (0 != source) 
    20   { 
    21     //Verify the compatibity between two grids 
    22     int numElement = gridDestination_->axis_domain_order.numElements(); 
    23     if (numElement != gridSource_->axis_domain_order.numElements()) 
    24       ERROR("CGridGenerate::CGridGenerate(CGrid* destination, CGrid* source)", 
    25          << "Two grids have different number of elements" 
    26          << "Number of elements of grid source " <<gridSource_->getId() << " is " << gridSource_->axis_domain_order.numElements()  << std::endl 
    27          << "Number of elements of grid destination " <<gridDestination_->getId() << " is " << numElement); 
    28  
    29     for (int i = 0; i < numElement; ++i) 
    30     { 
    31       if (gridDestination_->axis_domain_order(i) != gridSource_->axis_domain_order(i)) 
    32         ERROR("CGridGenerate::CGridGenerate(CGrid* destination, CGrid* source)", 
    33            << "Transformed grid and its grid source have incompatible elements" 
    34            << "Grid source " <<gridSource_->getId() << std::endl 
    35            << "Grid destination " <<gridDestination_->getId()); 
    36     } 
    37   } 
    38  
    39   initializeAlgorithms(); 
    4018} 
    4119 
    4220CGridGenerate::~CGridGenerate() 
    4321{ 
    44   std::list<CGenericAlgorithmTransformation*>::const_iterator itb = algoTransformation_.begin(), it, 
    45                                                               ite = algoTransformation_.end(); 
    46   for (it = itb; it != ite; ++it) delete (*it); 
    4722} 
    4823 
    4924/*! 
    50   Initialize the algorithms (transformations) 
    51 */ 
    52 void CGridGenerate::initializeAlgorithms() 
    53 { 
    54   std::vector<int> axisPositionInGrid; 
    55   std::vector<int> domPositionInGrid; 
    56   std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); 
    57   std::vector<CDomain*> domListDestP = gridDestination_->getDomains(); 
    58  
    59   int idx = 0; 
    60   for (int i = 0; i < gridDestination_->axis_domain_order.numElements(); ++i) 
    61   { 
    62     if (false == (gridDestination_->axis_domain_order)(i)) 
    63     { 
    64       axisPositionInGrid.push_back(idx); 
    65       ++idx; 
    66     } 
    67     else 
    68     { 
    69       ++idx; 
    70       domPositionInGrid.push_back(idx); 
    71       ++idx; 
    72     } 
    73   } 
    74  
    75   for (int i = 0; i < axisListDestP.size(); ++i) 
    76   { 
    77     elementPosition2AxisPositionInGrid_[axisPositionInGrid[i]] = i; 
    78   } 
    79  
    80   for (int i = 0; i < domListDestP.size(); ++i) 
    81   { 
    82     elementPosition2DomainPositionInGrid_[domPositionInGrid[i]] = i; 
    83   } 
    84  
    85   idx = 0; 
    86   for (int i = 0; i < gridDestination_->axis_domain_order.numElements(); ++i) 
    87   { 
    88     if (false == (gridDestination_->axis_domain_order)(i)) 
    89     { 
    90       initializeAxisAlgorithms(idx); 
    91       ++idx; 
    92     } 
    93     else 
    94     { 
    95       ++idx; 
    96       initializeDomainAlgorithms(idx); 
    97       ++idx; 
    98     } 
    99   } 
    100 } 
    101  
    102  
    103  
    104 /*! 
    105   Initialize the algorithms corresponding to transformation info contained in each axis. 
    106 If an axis has transformations, these transformations will be represented in form of vector of CTransformation pointers 
    107 In general, each axis can have several transformations performed on itself. However, should they be done seperately or combinely (of course in order)? 
    108 For now, one approach is to do these combinely but maybe this needs changing. 
    109 \param [in] axisPositionInGrid position of an axis in grid. (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2) 
    110 */ 
    111 void CGridGenerate::initializeAxisAlgorithms(int axisPositionInGrid) 
    112 { 
    113   std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); 
    114   if (!axisListDestP.empty()) 
    115   { 
    116     if (axisListDestP[elementPosition2AxisPositionInGrid_[axisPositionInGrid]]->hasTransformation()) 
    117     { 
    118       CAxis::TransMapTypes trans = axisListDestP[elementPosition2AxisPositionInGrid_[axisPositionInGrid]]->getAllTransformations(); 
    119       CAxis::TransMapTypes::const_iterator itb = trans.begin(), it, 
    120                                            ite = trans.end(); 
    121       int transformationOrder = 0; 
    122       for (it = itb; it != ite; ++it) 
    123       { 
    124         listAlgos_.push_back(std::make_pair(axisPositionInGrid, std::make_pair(it->first, transformationOrder))); 
    125         algoTypes_.push_back(false); 
    126         ++transformationOrder; 
    127       } 
    128     } 
    129   } 
    130 } 
    131  
    132 /*! 
    133   Initialize the algorithms corresponding to transformation info contained in each domain. 
    134 If a domain has transformations, they will be represented in form of vector of CTransformation pointers 
    135 In general, each domain can have several transformations performed on itself. 
    136 \param [in] domPositionInGrid position of a domain in grid. (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2) 
    137 */ 
    138 void CGridGenerate::initializeDomainAlgorithms(int domPositionInGrid) 
    139 { 
    140   std::vector<CDomain*> domListDestP = gridDestination_->getDomains(); 
    141   if (!domListDestP.empty()) 
    142   { 
    143     if (domListDestP[elementPosition2DomainPositionInGrid_[domPositionInGrid]]->hasTransformation()) 
    144     { 
    145       CDomain::TransMapTypes trans = domListDestP[elementPosition2DomainPositionInGrid_[domPositionInGrid]]->getAllTransformations(); 
    146       CDomain::TransMapTypes::const_iterator itb = trans.begin(), it, 
    147                                              ite = trans.end(); 
    148       int transformationOrder = 0; 
    149       for (it = itb; it != ite; ++it) 
    150       { 
    151         listAlgos_.push_back(std::make_pair(domPositionInGrid, std::make_pair(it->first, transformationOrder))); 
    152         algoTypes_.push_back(true); 
    153         ++transformationOrder; 
    154       } 
    155     } 
    156   } 
    157  
    158 } 
    159  
    160 /*! 
    161   Select algorithm correspoding to its transformation type and its position in each element 
     25  Select algorithm of an axis correspoding to its transformation type and its position in each element 
    16226  \param [in] elementPositionInGrid position of element in grid. e.g: a grid has 1 domain and 1 axis, then position of domain is 1 (because it contains 2 basic elements) 
    16327                                             and position of axis is 2 
    16428  \param [in] transType transformation type, for now we have Zoom_axis, inverse_axis 
    16529  \param [in] transformationOrder position of the transformation in an element (an element can have several transformation) 
    166   \param [in] isDomainAlgo flag to specify type of algorithm (for domain or axis) 
    16730*/ 
    168 void CGridGenerate::selectAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder, bool isDomainAlgo) 
     31void CGridGenerate::selectScalarAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder) 
    16932{ 
    170    if (isDomainAlgo) selectDomainAlgo(elementPositionInGrid, transType, transformationOrder); 
    171    else selectAxisAlgo(elementPositionInGrid, transType, transformationOrder); 
     33  CGenericAlgorithmTransformation* algo = 0; 
     34  algoTransformation_.push_back(algo); 
    17235} 
    17336 
     
    18144void CGridGenerate::selectAxisAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder) 
    18245{ 
    183   std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); 
    184  
    185   int axisIndex =  elementPosition2AxisPositionInGrid_[elementPositionInGrid]; 
    186   CAxis::TransMapTypes trans = axisListDestP[axisIndex]->getAllTransformations(); 
    187   CAxis::TransMapTypes::const_iterator it = trans.begin(); 
    188  
    189   for (int i = 0; i < transformationOrder; ++i, ++it) {}  // Find the correct transformation 
    190  
    19146  CGenericAlgorithmTransformation* algo = 0; 
    192   switch (transType) 
    193   { 
    194     default: 
    195     break; 
    196   } 
    19747  algoTransformation_.push_back(algo); 
    198  
    19948} 
    20049 
     
    21261  if (0 != gridSource_) domainListSrcP = gridSource_->getDomains(); 
    21362 
    214   int domainIndex =  elementPosition2DomainPositionInGrid_[elementPositionInGrid]; 
     63  int domainIndex =  elementPositionInGridDst2DomainPosition_[elementPositionInGrid]; 
    21564  CDomain::TransMapTypes trans = domainListDestP[domainIndex]->getAllTransformations(); 
    21665  CDomain::TransMapTypes::const_iterator it = trans.begin(); 
     
    24695void CGridGenerate::completeGrid() 
    24796{ 
    248   CContext* context = CContext::getCurrent(); 
    249   CContextClient* client = context->client; 
    250  
    25197  ListAlgoType::const_iterator itb = listAlgos_.begin(), 
    25298                               ite = listAlgos_.end(), it; 
Note: See TracChangeset for help on using the changeset viewer.