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

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