source: XMLIO_V2/dev/dev_rv/src/xmlio/node/grid.cpp @ 172

Last change on this file since 172 was 168, checked in by hozdoba, 13 years ago
File size: 8.1 KB
RevLine 
[152]1#include "grid.hpp"
2
3#include "attribute_template_impl.hpp"
4#include "object_template_impl.hpp"
5#include "group_template_impl.hpp"
6
[168]7namespace xmlioserver {
8namespace tree {
[152]9
[168]10   /// ////////////////////// Définitions ////////////////////// ///
[152]11
[168]12   CGrid::CGrid(void)
13      : CObjectTemplate<CGrid>(), CGridAttributes()
14      , withAxis(false), isChecked(false), axis(), domain()
15      , storeIndex(), out_i_index(), out_j_index(), out_l_index()
16   { /* Ne rien faire de plus */ }
[152]17
[168]18   CGrid::CGrid(const StdString & id)
19      : CObjectTemplate<CGrid>(id), CGridAttributes()
20      , withAxis(false), isChecked(false), axis(), domain()
21      , storeIndex(), out_i_index(), out_j_index(), out_l_index()
22   { /* Ne rien faire de plus */ }
[152]23
[168]24   CGrid::~CGrid(void)
25   { /* Ne rien faire de plus */ }
[152]26
[168]27   ///---------------------------------------------------------------
[152]28
[168]29   StdString CGrid::GetName(void)    { return (StdString("grid")); }
30   StdString CGrid::GetDefName(void) { return (CGrid::GetName()); }
31   ENodeType CGrid::GetType(void)    { return (eGrid); }
[152]32
[168]33   //----------------------------------------------------------------
[152]34
[168]35   const ARRAY(int, 1) & CGrid::getStoreIndex(void) const
36   { return (this->storeIndex ); }
37   const ARRAY(int, 1) & CGrid::getOutIIndex(void)  const
38   { return (this->out_i_index ); }
39   const ARRAY(int, 1) & CGrid::getOutJIndex(void)  const
40   { return (this->out_j_index ); }
41   const ARRAY(int, 1) & CGrid::getOutLIndex(void)  const
42   { return (this->out_l_index ); }
[152]43
[168]44   const boost::shared_ptr<CAxis>   CGrid::getRelAxis  (void) const
45   { return (this->axis ); }
46   const boost::shared_ptr<CDomain> CGrid::getRelDomain(void) const
47   { return (this->domain ); }
[152]48
[168]49   bool CGrid::hasAxis(void) const { return (this->withAxis); }
[152]50
[168]51   //---------------------------------------------------------------
[152]52
[168]53   void CGrid::solveReference(void)
54   {
55      if (this->isChecked) return;
56      this->solveDomainRef() ;
57      this->solveAxisRef() ;
58      this->computeIndex() ;
59      this->isChecked = true;
60   }
61
62   void CGrid::solveDomainRef(void)
63   {
64      if (!domain_ref.isEmpty())
[152]65      {
[168]66         if (CObjectFactory::HasObject<CDomain>(domain_ref.getValue()))
[152]67         {
[168]68            this->domain = CObjectFactory::GetObject<CDomain>(domain_ref.getValue()) ;
69            domain->checkAttributes() ;
[152]70         }
71         else ERROR("CGrid::solveDomainRef(void)",
[168]72                     << "Référence au domaine incorrecte") ;
[152]73      }
[168]74      else ERROR("CGrid::solveDomainRef(void)",
75                  << "Domaine non défini") ;
76   }
[152]77
[168]78   void CGrid::solveAxisRef(void)
79   {
80      if (!axis_ref.isEmpty())
[152]81      {
[168]82         this->withAxis = true ;
83         if (CObjectFactory::GetObject<CAxis>(axis_ref.getValue()))
[152]84         {
[168]85            this->axis = CObjectFactory::GetObject<CAxis>(axis_ref.getValue()) ;
86            axis->checkAttributes() ;
[152]87         }
[168]88         else ERROR("CGrid::solveAxisRef(void)",
89                    << "Référence a l'axe incorrecte") ;
[152]90      }
[168]91      else withAxis = false ;
92   }
[152]93
[168]94   //---------------------------------------------------------------
[152]95
[168]96   void CGrid::computeIndex(void)
97   {
98      const int ni   = domain->ni.getValue() ,
99                nj   = domain->nj.getValue() ,
100                size = (this->hasAxis()) ? axis->size.getValue() : 1 ;
[152]101
[168]102      /*std::cout << ni   << " : "
103                  << nj   << " : "
104                  << size << std::endl;*/
[152]105
[168]106      const int data_dim     = domain->data_dim.getValue() ,
107                data_n_index = domain->data_n_index.getValue() ,
108                data_ibegin  = domain->data_ibegin.getValue() ,
109                data_jbegin  = (data_dim == 2)
110                             ? domain->data_jbegin.getValue() : -1;
[152]111
[168]112      ARRAY(int, 1) data_i_index = domain->data_i_index.getValue() ,
113                    data_j_index = domain->data_j_index.getValue() ;
[152]114
[168]115      /*std::cout << data_n_index        << " : "
116                  << data_i_index.size() << " : "
117                  << data_j_index.size() << std::endl;*/
[152]118
[168]119      ARRAY(bool, 2) mask = domain->mask.getValue() ;
[152]120
[168]121      int indexCount = 0;
[152]122
[168]123      for(int l = 0; l < size ; l++)
124      {
125         for(int n = 0, i = 0, j = 0; n < data_n_index; n++)
[152]126         {
[168]127            int temp_i = (*data_i_index)[n] + data_ibegin,
128                temp_j = (data_dim == 1) ? -1
129                       : (*data_j_index)[n] + data_jbegin;
130            i = (data_dim == 1) ? (temp_i - 2) % ni
131                                : (temp_i - 1) ;
132            j = (data_dim == 1) ? (temp_i - 2) / ni
133                                : (temp_j - 1) ;
[152]134
[168]135            if ((i >= 0 && i < ni) &&
136                (j >= 0 && j < nj) && (*mask)[i][j])
137               indexCount++ ;
[152]138         }
[168]139      }
140     
141      //std::cout << indexCount  << std::endl;
142      ARRAY_ASSIGN(this->storeIndex , int, 1, [indexCount]);
143      ARRAY_ASSIGN(this->out_l_index, int, 1, [indexCount]);
144      ARRAY_ASSIGN(this->out_i_index, int, 1, [indexCount]);
145      ARRAY_ASSIGN(this->out_j_index, int, 1, [indexCount]);
[152]146
[168]147      for(int count = 0, indexCount = 0,  l = 0; l < size; l++)
148      {
149         for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++)
[152]150         {
[168]151            int temp_i = (*data_i_index)[n] + data_ibegin,
152                temp_j = (data_dim == 1) ? -1
153                       : (*data_j_index)[n] + data_jbegin;
154            i = (data_dim == 1) ? (temp_i - 2) % ni
155                                : (temp_i - 1) ;
156            j = (data_dim == 1) ? (temp_i - 2) / ni
157                                : (temp_j - 1) ;
158
159            if ((i >= 0 && i < ni) &&
160                (j >= 0 && j < nj) && (*mask)[i][j])
[152]161            {
[168]162               (*this->storeIndex) [indexCount] = count ;
163               (*this->out_l_index)[indexCount] = l ;
164               (*this->out_i_index)[indexCount] = i ;
165               (*this->out_j_index)[indexCount] = j ;
166               indexCount++ ;
[152]167            }
168         }
169      }
[168]170   }
[152]171
[168]172   //----------------------------------------------------------------
[152]173
[168]174   boost::shared_ptr<CGrid>
175      CGrid::CreateGrid(boost::shared_ptr<CDomain> domain)
176   {
177      StdString new_id = StdString("__") + domain->getId() + StdString("__") ;
178      boost::shared_ptr<CGrid> grid =
179         CGroupFactory::CreateChild(CObjectFactory::GetObject<CGridGroup> ("grid_definition"), new_id);
180      grid->domain_ref.setValue(domain->getId());
181      return (grid);
182   }
[152]183
[168]184   boost::shared_ptr<CGrid>
185      CGrid::CreateGrid(boost::shared_ptr<CDomain> domain, boost::shared_ptr<CAxis> axis)
186   {
187      StdString new_id = StdString("__") + domain->getId() +
188                         StdString("_") + axis->getId() + StdString("__") ;
189      boost::shared_ptr<CGrid> grid =
190         CGroupFactory::CreateChild(CObjectFactory::GetObject<CGridGroup> ("grid_definition"), new_id);
191      grid->domain_ref.setValue(domain->getId());
192      grid->axis_ref.setValue(axis->getId());
193      return (grid);
194   }
[152]195
[168]196   //----------------------------------------------------------------
[152]197
[168]198   template <>
199      void CGrid::outputField
200         (const ARRAY(double, 1) stored,  ARRAY(double, 3) field) const
201   {
202      for(StdSize n = 0; n < storeIndex->num_elements(); n++)
203         (*field)[(*out_i_index)[n]][(*out_j_index)[n]][(*out_l_index)[n]] = (*stored)[n] ;
204   }
[152]205
[168]206   template <>
207      void CGrid::outputField
208         (const ARRAY(double, 1) stored,  ARRAY(double, 2) field) const
209   {
210      for(StdSize n = 0; n < storeIndex->num_elements(); n++)
211         (*field)[(*out_i_index)[n]][(*out_j_index)[n]] = (*stored)[n] ;
212   }
[152]213
[168]214   template <>
215      void CGrid::outputField
216         (const ARRAY(double, 1) stored,  ARRAY(double, 1) field) const
217   {
218      for(StdSize n = 0; n < storeIndex->num_elements(); n++)
219         (*field)[(*out_i_index)[n]] = (*stored)[n] ;
220   }
[152]221
[168]222   //----------------------------------------------------------------
[152]223
[168]224   void CGrid::storeField_arr
225      (const double * const data, ARRAY(double, 1) stored) const
226   {
227      const StdSize size = storeIndex->num_elements() ;
228      stored->resize(boost::extents[size]) ;
229      for(StdSize i = 0; i < size; i++)
230         (*stored)[i] = data[(*storeIndex)[i]] ;
231   }
232
233   ///---------------------------------------------------------------
234
235} // namespace tree
[152]236} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.