source: XMLIO_V2/dev/dev_rv/src/XMLIO/grid.hpp @ 122

Last change on this file since 122 was 122, checked in by hozdoba, 14 years ago

Plusieurs modifications en attendant une version propre et stable.

File size: 7.4 KB
Line 
1#ifndef __GRID__
2#define __GRID__
3
4using XMLIOSERVER::XML::XMLNode;
5using XMLIOSERVER::XML::THashAttributes;
6
7namespace XMLIOSERVER
8{
9   class CGrid : public ObjectTemplate<CGrid>, public GridAttribut
10   {
11      public:
12
13         CGrid(void) : ObjectTemplate<CGrid>(), GridAttribut(), hasAxis(false), axis(NULL), domain(NULL)
14         { /* Ne rien faire de plus */ }
15
16         CGrid(const string& _id) : ObjectTemplate<CGrid>(_id), GridAttribut(), hasAxis(false), axis(NULL), domain(NULL)
17         { /* Ne rien faire de plus */ }
18
19         static string GetName(void) { return ("grid"); }
20
21         const CAxis* getRelAxis(void) const { return (axis); }
22         const CDomain* getRelDomain(void) const { return (domain); }
23
24         inline void solveReference(void) ;
25         inline void solveDomainRef(void) ;
26         inline void solveAxisRef(void) ;
27
28         inline void computeIndex(void);
29
30         bool _hasAxis(void) const { return (hasAxis); }
31
32         inline void storeField(const Array<double, 1>& field, Array<double, 1>& stored);
33         inline void storeField(const Array<double, 2>& field, Array<double, 1>& stored);
34         inline void storeField(const Array<double, 3>& field, Array<double, 1>& stored);
35         inline void storeField(const double* const data, Array<double, 1>& stored);
36
37         inline void outputField(const Array<double,1>& stored, Array<double, 2>& outField);
38         inline void outputField(const Array<double,1>& stored, Array<double, 3>& outField);
39
40         inline static CGrid* CreateObject(const CDomain* const a_domain, const CAxis* const a_axis);
41         inline static CGrid* CreateObject(const CDomain* const a_domain);
42
43         virtual ~CGrid(void)
44         { /* Ne rien faire de plus */ }
45
46
47      private:
48
49         bool hasAxis ;
50
51         CAxis* axis ;
52         CDomain* domain ;
53
54         Array<int,1> storeIndex ;
55         Array<int,1> out_i_index ;
56         Array<int,1> out_j_index ;
57         Array<int,1> out_l_index ;
58
59   }; // class CGrid
60
61
62   CGrid* CGrid::CreateObject(const CDomain* const a_domain, const CAxis* const a_axis)
63   {
64      string new_id = string("___") + a_domain->getId() + string("_") + a_axis->getId() + string("__") ;
65      CGrid* const grid = ObjectTemplate<CGrid>::CreateObject(new_id) ;
66
67      grid->domain_ref = a_domain->getId() ;
68      grid->axis_ref = a_axis->getId() ;
69
70      return (grid);
71   }
72
73   CGrid* CGrid::CreateObject(const CDomain* const a_domain)
74   {
75      string new_id = string("___") + a_domain->getId() + string("__") ;
76      CGrid* const grid = ObjectTemplate<CGrid>::CreateObject(new_id) ;
77
78      grid->domain_ref = a_domain->getId() ;
79
80      return (grid);
81   }
82
83   void CGrid::solveReference(void)
84   {
85
86      static bool isReferenceSolved = false;
87      if (isReferenceSolved) return;
88
89      // Résolution de chacune des références et indexation.
90      solveDomainRef() ;
91      solveAxisRef() ;
92      computeIndex() ;
93
94      isReferenceSolved = true ;
95   }
96
97   void CGrid::solveDomainRef(void)
98   {
99      if (domain_ref.hasValue())
100      {
101         if (CDomain::HasObject(domain_ref))
102         {
103           domain = CDomain::GetObject(domain_ref) ;
104           domain->check() ;
105         }
106         else ERROR("Référence au domaine incorrecte") ;
107      }
108      else ERROR("Domaine non défini") ;
109   }
110
111   void CGrid::solveAxisRef(void)
112   {
113      if (axis_ref.hasValue())
114      {
115         hasAxis = true ;
116         if (CAxis::HasObject(axis_ref)) axis = CAxis::GetObject(axis_ref) ;
117         else ERROR("Référence a l'axe incorrecte") ;
118      }
119      else hasAxis = false ; // hasAxis est normalement déjà à false(?).
120   }
121
122   void CGrid::computeIndex(void)
123   {
124
125      int ni = domain->ni ;
126      int nj = domain->nj ;
127      int size = (hasAxis) ? (int)axis->size : 1 ;
128      int data_dim = domain->data_dim ;
129      int data_n_index = domain->data_n_index ;
130      int data_ibegin  = domain->data_ibegin ;
131      int data_jbegin  = (data_dim == 2) ? (int)domain->data_jbegin : -1;
132
133      Array<int, 1>& data_i_index =* domain->data_i_index ;
134      Array<int, 1>& data_j_index =* domain->data_j_index ;
135      Array<bool, 2>& mask =* domain->mask ;
136      int i, j, l, n ;
137      int count, indexCount ;
138
139      for(indexCount=0, l=0; l<size ; l++)
140      {
141         for(n=0; n<data_n_index; n++)
142         {
143            if (data_dim == 1)
144            {
145               i = (data_i_index(n) + data_ibegin) % ni ;
146               j = (data_i_index(n) + data_ibegin) / ni ;
147               //cout<<i<<" "<<j<<" "<<mask(i,j)<<endl ;
148            }
149            else
150            {
151               i = data_i_index(n) + data_ibegin ;
152               j = data_j_index(n) + data_jbegin ;
153               //cout<<i<<" "<<j<<" "<<mask(i,j)<<endl ;
154            }
155
156            if (i>=0 && i<ni && j>=0 && j<nj && mask(i,j) ) indexCount++ ;
157         }
158      }
159
160      storeIndex.resize(indexCount) ;
161      out_l_index.resize(indexCount) ;
162      out_i_index.resize(indexCount) ;
163      out_j_index.resize(indexCount) ;
164
165      for(count=0, indexCount=0, l=0; l<size; l++)
166      {
167         for(n=0; n<data_n_index; n++, count++)
168         {
169            if (data_dim == 1)
170            {
171               i = (data_i_index(n) + data_ibegin) % ni ;
172               j = (data_i_index(n) + data_ibegin) / ni ;
173            }
174            else // (dat_dim == 2)
175            {
176               i = data_i_index(n) + data_ibegin ;
177               j = data_j_index(n) + data_jbegin ;
178            }
179
180            if (i>=0 && i<ni && j>=0 && j<nj && mask(i,j))
181            {
182               storeIndex(indexCount) = count ;
183               out_l_index(indexCount) = l ;
184               out_i_index(indexCount) = i ;
185               out_j_index(indexCount) = j ;
186               indexCount++ ;
187            }
188         }
189      }
190
191      /** Pour tests
192
193      cout << "Out of CGrid::ComputeIndex" << endl ;
194
195      cout << "storeIndex : " << endl ;
196      cout << storeIndex << endl ;
197
198      cout << "out_i_index : " << endl ;
199      cout << out_i_index << endl ;
200
201      cout << "out_j_index : " << endl ;
202      cout << out_j_index << endl ;
203
204      cout << "out_l_index : " << endl ;
205      cout << out_l_index << endl ;
206
207      **/
208
209   }
210
211   void CGrid::storeField(const Array<double, 1>& field, Array<double, 1>& stored)
212   {
213      storeField(field.dataFirst(), stored) ;
214      //cout<<"Stored 1"<<stored<<endl ;
215   }
216
217   void CGrid::storeField(const Array<double, 2>& field, Array<double, 1>& stored)
218   {
219      storeField(field.dataFirst(), stored) ;
220      //cout<<"Stored 2"<<stored<<endl ;
221   }
222
223   void CGrid::storeField(const Array<double, 3>& field, Array<double, 1>& stored)
224   {
225      storeField(field.dataFirst(), stored) ;
226      //cout<<"Stored 3"<<stored<<endl ;
227   }
228
229   void CGrid::storeField(const double* const data, Array<double, 1>& stored)
230   {
231      int size = storeIndex.size() ;
232      //cout << "size " << size << endl ;
233
234      stored.resize(shape(size)) ;
235      //cout << "Stored " << stored << endl ;
236
237      for(int i = 0; i < size; i++) stored(i) = data[storeIndex(i)] ;
238      //cout << "Stored " << stored << endl ;
239   }
240
241   void CGrid::outputField(const Array<double, 1>& stored, Array<double, 2>& outField)
242   {
243      for(int n = 0; n < storeIndex.size(); n++)
244         outField(out_i_index(n), out_j_index(n)) = stored(n) ;
245   }
246
247   void CGrid::outputField(const Array<double, 1>& stored, Array<double, 3>& outField)
248   {
249      for(int n = 0; n < storeIndex.size(); n++)
250         outField(out_i_index(n), out_j_index(n), out_l_index(n)) = stored(n) ;
251   }
252} // namespace XMLIOSERVER
253
254
255DECLARE_GROUP(Grid)
256
257
258
259#endif // __GRID__
260
Note: See TracBrowser for help on using the repository browser.