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