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
Line 
1#include "grid.hpp"
2
3#include "attribute_template_impl.hpp"
4#include "object_template_impl.hpp"
5#include "group_template_impl.hpp"
6
7namespace xmlioserver {
8namespace tree {
9
10   /// ////////////////////// Définitions ////////////////////// ///
11
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 */ }
17
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 */ }
23
24   CGrid::~CGrid(void)
25   { /* Ne rien faire de plus */ }
26
27   ///---------------------------------------------------------------
28
29   StdString CGrid::GetName(void)    { return (StdString("grid")); }
30   StdString CGrid::GetDefName(void) { return (CGrid::GetName()); }
31   ENodeType CGrid::GetType(void)    { return (eGrid); }
32
33   //----------------------------------------------------------------
34
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 ); }
43
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 ); }
48
49   bool CGrid::hasAxis(void) const { return (this->withAxis); }
50
51   //---------------------------------------------------------------
52
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())
65      {
66         if (CObjectFactory::HasObject<CDomain>(domain_ref.getValue()))
67         {
68            this->domain = CObjectFactory::GetObject<CDomain>(domain_ref.getValue()) ;
69            domain->checkAttributes() ;
70         }
71         else ERROR("CGrid::solveDomainRef(void)",
72                     << "Référence au domaine incorrecte") ;
73      }
74      else ERROR("CGrid::solveDomainRef(void)",
75                  << "Domaine non défini") ;
76   }
77
78   void CGrid::solveAxisRef(void)
79   {
80      if (!axis_ref.isEmpty())
81      {
82         this->withAxis = true ;
83         if (CObjectFactory::GetObject<CAxis>(axis_ref.getValue()))
84         {
85            this->axis = CObjectFactory::GetObject<CAxis>(axis_ref.getValue()) ;
86            axis->checkAttributes() ;
87         }
88         else ERROR("CGrid::solveAxisRef(void)",
89                    << "Référence a l'axe incorrecte") ;
90      }
91      else withAxis = false ;
92   }
93
94   //---------------------------------------------------------------
95
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 ;
101
102      /*std::cout << ni   << " : "
103                  << nj   << " : "
104                  << size << std::endl;*/
105
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;
111
112      ARRAY(int, 1) data_i_index = domain->data_i_index.getValue() ,
113                    data_j_index = domain->data_j_index.getValue() ;
114
115      /*std::cout << data_n_index        << " : "
116                  << data_i_index.size() << " : "
117                  << data_j_index.size() << std::endl;*/
118
119      ARRAY(bool, 2) mask = domain->mask.getValue() ;
120
121      int indexCount = 0;
122
123      for(int l = 0; l < size ; l++)
124      {
125         for(int n = 0, i = 0, j = 0; n < data_n_index; n++)
126         {
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) ;
134
135            if ((i >= 0 && i < ni) &&
136                (j >= 0 && j < nj) && (*mask)[i][j])
137               indexCount++ ;
138         }
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]);
146
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++)
150         {
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])
161            {
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++ ;
167            }
168         }
169      }
170   }
171
172   //----------------------------------------------------------------
173
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   }
183
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   }
195
196   //----------------------------------------------------------------
197
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   }
205
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   }
213
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   }
221
222   //----------------------------------------------------------------
223
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
236} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.