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

Last change on this file since 141 was 141, checked in by hozdoba, 13 years ago

Mise à jour depuis un autre dépôt

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