00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MEDMEM_INTERLACING_HXX
00024 #define MEDMEM_INTERLACING_HXX
00025
00026 #include <MEDMEM.hxx>
00027
00028 #include <iostream>
00029 #include "MEDMEM_Utilities.hxx"
00030
00031 #include "MEDMEM_PointerOf.hxx"
00032 #include "MEDMEM_define.hxx"
00033
00034 namespace MEDMEM {
00035
00036 class MEDMEM_EXPORT InterlacingPolicy {
00037 protected:
00038 ~InterlacingPolicy() {}
00039 public :
00040 InterlacingPolicy(void) : _dim(0), _nbelem(0),
00041 _arraySize(0),
00042 _interlacing(MED_EN::MED_UNDEFINED_INTERLACE),
00043 _gaussPresence(false) {}
00044
00045 InterlacingPolicy(int nbelem, int dim, int arraySize=0, int interlacing=MED_EN::MED_UNDEFINED_INTERLACE) :
00046 _dim(dim),
00047 _nbelem(nbelem),
00048 _arraySize(arraySize),
00049 _interlacing(interlacing),
00050 _gaussPresence(false) {}
00051
00052
00053 InterlacingPolicy(const InterlacingPolicy & intpol,
00054 bool shallowcopy = true) :_dim(intpol._dim),
00055 _nbelem(intpol._nbelem),
00056 _arraySize(intpol._arraySize),
00057 _interlacing(intpol._interlacing),
00058 _gaussPresence(intpol._gaussPresence) {}
00059
00060 InterlacingPolicy & operator=(const InterlacingPolicy & intpol) {
00061 if ( this == &intpol ) return *this;
00062 const char* LOC = "InterlacingPolicy operator =";
00063 BEGIN_OF_MED(LOC);
00064
00065 _dim = intpol._dim;
00066 _nbelem = intpol._nbelem;
00067 _arraySize = intpol._arraySize;
00068 _interlacing = intpol._interlacing;
00069 _gaussPresence = intpol._gaussPresence;
00070
00071 return *this;
00072 }
00073
00074 inline int getDim() const { return _dim; }
00075 inline int getNbElem() const { return _nbelem; }
00076 inline int getArraySize() const { return _arraySize; }
00077 inline MED_EN::medModeSwitch getInterlacingType() const {return _interlacing;}
00078 inline bool getGaussPresence() const { return _gaussPresence;}
00079 virtual int getNbGauss(int i) const = 0;
00080
00081 int _dim;
00082 int _nbelem;
00083 int _arraySize;
00084 MED_EN::medModeSwitch _interlacing;
00085 bool _gaussPresence;
00086 };
00087
00088
00089 class MEDMEM_EXPORT FullInterlaceNoGaussPolicy : public InterlacingPolicy {
00090
00091 protected:
00092 ~FullInterlaceNoGaussPolicy() {}
00093
00094 public :
00095 FullInterlaceNoGaussPolicy() : InterlacingPolicy() {}
00096 FullInterlaceNoGaussPolicy(int nbelem, int dim) :
00097 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_FULL_INTERLACE) {}
00098
00099 FullInterlaceNoGaussPolicy(const FullInterlaceNoGaussPolicy & policy,
00100 bool shallowcopie=true)
00101 : InterlacingPolicy(policy) {};
00102
00103 inline int getIndex(int i,int j) const {
00104 return (i-1)*_dim + j-1;
00105 }
00106
00107 inline int getIndex(int i,int j,int k) const {
00108 return (i-1)*_dim + j-1;
00109 }
00110
00111 inline int getNbGauss(int i) const { return 1; }
00112
00113 };
00114
00115 class MEDMEM_EXPORT NoInterlaceNoGaussPolicy : public InterlacingPolicy {
00116
00117 protected:
00118 ~NoInterlaceNoGaussPolicy() {}
00119
00120 public :
00121
00122 NoInterlaceNoGaussPolicy():InterlacingPolicy() {}
00123 NoInterlaceNoGaussPolicy(int nbelem, int dim) :
00124 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_NO_INTERLACE) {}
00125
00126 NoInterlaceNoGaussPolicy(const NoInterlaceNoGaussPolicy & policy,
00127 bool shallowcopie=true)
00128 : InterlacingPolicy(policy) {}
00129
00130 inline int getIndex(int i,int j) const {
00131 return (j-1)*_nbelem + i-1;
00132 }
00133
00134 inline int getIndex(int i,int j,int k) const {
00135 return (j-1)*_nbelem + i-1;
00136 }
00137
00138 inline int getNbGauss(int i) const { return 1; }
00139
00140 };
00141
00142 class MEDMEM_EXPORT NoInterlaceByTypeNoGaussPolicy : public InterlacingPolicy {
00143
00144 protected:
00145 ~NoInterlaceByTypeNoGaussPolicy() {}
00146
00147 PointerOf<int> _T;
00148 PointerOf<int> _G;
00149 int _nbtypegeo;
00150 PointerOf<int> _nbelegeoc;
00151
00152 public :
00153
00154 NoInterlaceByTypeNoGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1)
00155 {
00156 }
00157
00158 NoInterlaceByTypeNoGaussPolicy(int nbelem, int dim):InterlacingPolicy()
00159 {
00160
00161 throw MEDEXCEPTION(LOCALIZED("Wrong constructor of NoInterlaceByTypeNoGaussPolicy "));
00162 }
00163
00164 NoInterlaceByTypeNoGaussPolicy(int nbelem, int dim, int nbtypegeo,
00165 const int * const nbelgeoc) :
00166 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_NO_INTERLACE_BY_TYPE),
00167 _nbtypegeo(nbtypegeo)
00168 {
00169 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
00170 _G.set(nbtypegeo+1);
00171 _T.set(nbelem+1);
00172 int elemno = 1;
00173 int cumul = 0;
00174
00175 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
00176 int nbelcurtype = nbelgeoc[ntyp]-nbelgeoc[ntyp-1];
00177 for (int i=0; i < nbelcurtype; i++ ) {
00178 _T[ elemno ] = ntyp;
00179 elemno++;
00180 };
00181 _G[ ntyp ] = cumul;
00182 cumul += nbelcurtype*_dim;
00183 #ifdef ARRAY_DEBUG
00184 std::cout << "Valeur de cumul " << cumul << std::endl;
00185 #endif
00186 };
00187
00188 _arraySize = cumul;
00189
00190 #ifdef ARRAY_DEBUG
00191 for (int i =0; i< nbelem+1; i++ )
00192 std::cout << "Valeur de _T["<<i<<"] = "<<_T[i] << std::endl;
00193 #endif
00194 }
00195
00196 NoInterlaceByTypeNoGaussPolicy(const NoInterlaceByTypeNoGaussPolicy & policy,
00197 bool shallowcopie=true)
00198 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo)
00199 {
00200
00201 if(shallowcopie)
00202 {
00203 this->_G.set(policy._G);
00204 this->_T.set(policy._T);
00205 }
00206 else
00207 {
00208 this->_G.set(_nbtypegeo+1,policy._G);
00209 this->_T.set(_nbelem+1,policy._T);
00210 }
00211
00212
00213 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
00214 }
00215
00216 NoInterlaceByTypeNoGaussPolicy & operator=(const NoInterlaceByTypeNoGaussPolicy & policy) {
00217 if ( this == &policy) return *this;
00218
00219 const char* LOC = "NoInterlaceNoGaussPolicy operator =";
00220 BEGIN_OF_MED(LOC);
00221 InterlacingPolicy::operator=(policy);
00222 this->_G.set(policy._G);
00223 this->_T.set(policy._T);
00224
00225
00226 this->_nbtypegeo=policy._nbtypegeo;
00227 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
00228
00229 return *this;
00230 }
00231 inline int getIndex(int t) const {
00232 return _G[t];
00233 }
00234
00235 inline int getIndex(int i,int j) const {
00236 int t = _T[i];
00237 return getIndexByType( i-(_nbelegeoc[t-1]-_nbelegeoc[0]), j, t );
00238 }
00239
00240 inline int getIndex(int i,int j,int k) const {
00241 return getIndex(i,j);
00242 }
00243
00244 inline int getIndexByType(int i,int j,int t) const {
00245 return _G[t] + i-1 + (j-1)*(_nbelegeoc[t]-_nbelegeoc[t-1]);
00246 }
00247
00248 inline int getIndexByType(int i,int j,int k,int t) const {
00249 return getIndexByType( i, j, t );
00250 }
00251
00252 inline int getLengthOfType(int t) const {
00253 return (_nbelegeoc[t]-_nbelegeoc[t-1]) * _dim;
00254 }
00255
00256 inline int getNbGauss(int i) const { return 1; }
00257
00258 inline int getNbGeoType() const {return _nbtypegeo;}
00259
00260 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
00261
00262 };
00263
00264 class MEDMEM_EXPORT FullInterlaceGaussPolicy : public InterlacingPolicy {
00265 protected:
00266 ~FullInterlaceGaussPolicy() {}
00267 public :
00268
00269 PointerOf<int> _G;
00270 PointerOf<int> _S;
00271 int _nbtypegeo;
00272 PointerOf<int> _nbelegeoc;
00273 PointerOf<int> _nbgaussgeo;
00274
00275 FullInterlaceGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1) {
00276 InterlacingPolicy::_gaussPresence=true;
00277 }
00278 FullInterlaceGaussPolicy(int nbelem, int dim, int nbtypegeo,
00279 const int * const nbelgeoc, const int * const nbgaussgeo)
00280 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_FULL_INTERLACE),_nbtypegeo(nbtypegeo) {
00281
00282 InterlacingPolicy::_gaussPresence=true;
00283
00284 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
00285 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
00286 _G.set(nbelem+1);
00287
00288 _S.set(nbelem+1);
00289 _S[0] = -1;
00290 int cumul = 0;
00291 int elemno = 0;
00292
00293
00294 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
00295 for (int i=0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) ; i++ ) {
00296 _G[ elemno ] = cumul + i*nbgaussgeo[ntyp]*dim + 1;
00297 elemno++;
00298 _S[ elemno ] = nbgaussgeo[ntyp];
00299 };
00300 cumul += (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) * nbgaussgeo[ntyp] * dim;
00301 #ifdef ARRAY_DEBUG
00302 std::cout << "Valeur de cumul " << cumul << std::endl;
00303 #endif
00304 };
00305
00306 _G[ elemno ] = cumul+1;
00307 _arraySize = _G[ elemno ] -1 ;
00308
00309 #ifdef ARRAY_DEBUG
00310 for (int i =0; i< nbelem+1; i++ )
00311 std::cout << "Valeur de _G["<<i<<"] = "<<_G[i] << std::endl;
00312 #endif
00313 }
00314
00315 FullInterlaceGaussPolicy(const FullInterlaceGaussPolicy & policy,
00316 bool shallowcopie=true)
00317 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo) {
00318
00319
00320 if(shallowcopie) {
00321 this->_G.set(policy._G);
00322 this->_S.set(policy._S);
00323 } else {
00324 this->_G.set(_nbelem+1,policy._G);
00325 this->_S.set(_nbelem+1,policy._S);
00326 }
00327
00328 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
00329 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
00330 }
00331
00332 FullInterlaceGaussPolicy & operator=(const FullInterlaceGaussPolicy & policy) {
00333 const char* LOC = "FullInterlaceGaussPolicy operator =";
00334 BEGIN_OF_MED(LOC);
00335
00336 if ( this == &policy) return *this;
00337
00338
00339 InterlacingPolicy::operator=(policy);
00340 this->_G.set(policy._G);
00341 this->_S.set(policy._S);
00342
00343
00344 this->_nbtypegeo=policy._nbtypegeo;
00345 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
00346 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
00347
00348 return *this;
00349 }
00350
00351 inline int getIndex(int i,int j ) const {
00352 return _G[i-1]-1 + (j-1);
00353 }
00354
00355 inline int getIndex(int i,int j, int k ) const {
00356
00357 return _G[i-1]-1 + (k-1)*_dim + (j-1);
00358 }
00359
00360 inline int getNbGauss(int i) const { return _S[i]; }
00361
00362 inline int getNbGeoType() const {return _nbtypegeo;}
00363
00364 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
00365
00366 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
00367
00368
00369 };
00370
00371 class MEDMEM_EXPORT NoInterlaceGaussPolicy : public InterlacingPolicy {
00372
00373 protected:
00374 ~NoInterlaceGaussPolicy() {}
00375
00376 public :
00377
00378 PointerOf<int> _G;
00379 PointerOf<int> _S;
00380 int _nbtypegeo;
00381 PointerOf<int> _nbelegeoc;
00382 PointerOf<int> _nbgaussgeo;
00383
00384
00385 int _cumul;
00386
00387 NoInterlaceGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1),_cumul(0) {
00388 InterlacingPolicy::_gaussPresence=true;
00389 }
00390
00391 NoInterlaceGaussPolicy(int nbelem, int dim, int nbtypegeo,
00392 const int * const nbelgeoc, const int * const nbgaussgeo)
00393 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_NO_INTERLACE),_nbtypegeo(nbtypegeo) {
00394
00395 InterlacingPolicy::_gaussPresence=true;
00396
00397 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
00398 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
00399 _G.set(nbelem+1);
00400
00401 _S.set(nbelem+1);
00402 _S[0] = -1;
00403 int elemno = 0;
00404
00405 _cumul = 0;
00406 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
00407 for (int i=0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) ; i++ ) {
00408 _G[ elemno ] = _cumul + i*nbgaussgeo[ntyp] + 1;
00409 elemno++;
00410 _S[ elemno ] = nbgaussgeo[ntyp];
00411 };
00412 _cumul += (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) * nbgaussgeo[ntyp];
00413 #ifdef ARRAY_DEBUG
00414 std::cout << "Valeur de _cumul " << _cumul << std::endl;
00415 #endif
00416 };
00417
00418 _G[ elemno ] = _cumul+1;
00419 _arraySize = ( _G[ elemno ] -1 ) * dim ;
00420
00421 #ifdef ARRAY_DEBUG
00422 for (int i =0; i< nbelem+1; i++ )
00423 std::cout << "Valeur de _G["<<i<<"] = "<<_G[i] << std::endl;
00424 #endif
00425 }
00426
00427
00428 NoInterlaceGaussPolicy(const NoInterlaceGaussPolicy & policy,
00429 bool shallowcopie=true)
00430 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo),_cumul(policy._cumul)
00431 {
00432
00433 if(shallowcopie) {
00434 this->_G.set(policy._G);
00435 this->_S.set(policy._S);
00436 } else {
00437 this->_G.set(_nbelem+1,policy._G);
00438 this->_S.set(_nbelem+1,policy._S);
00439 }
00440
00441 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
00442 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
00443 }
00444
00445 NoInterlaceGaussPolicy & operator=(const NoInterlaceGaussPolicy & policy) {
00446 if ( this == &policy) return *this;
00447
00448 const char* LOC = "NoInterlaceGaussPolicy operator =";
00449 BEGIN_OF_MED(LOC);
00450 InterlacingPolicy::operator=(policy);
00451 this->_G.set(policy._G);
00452 this->_S.set(policy._S);
00453
00454 this->_cumul = policy._cumul;
00455
00456
00457 this->_nbtypegeo=policy._nbtypegeo;
00458 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
00459 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
00460
00461 return *this;
00462 }
00463
00464 inline int getIndex(int i,int j ) const {
00465 return _G[i-1]-1 + (j-1)*_cumul ;
00466 }
00467
00468 inline int getIndex(int i,int j, int k ) const {
00469 return _G[i-1]-1 + (j-1)*_cumul + (k-1) ;
00470 }
00471
00472 inline int getNbGauss(int i) const { return _S[i]; }
00473
00474 inline int getNbGeoType() const {return _nbtypegeo;}
00475
00476 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
00477
00478 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
00479
00480 };
00481
00482 class MEDMEM_EXPORT NoInterlaceByTypeGaussPolicy : public InterlacingPolicy {
00483
00484 protected:
00485 ~NoInterlaceByTypeGaussPolicy() {}
00486
00487 PointerOf<int> _T;
00488 PointerOf<int> _G;
00489 int _nbtypegeo;
00490 PointerOf<int> _nbelegeoc;
00491 PointerOf<int> _nbgaussgeo;
00492
00493 public :
00494
00495 NoInterlaceByTypeGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1) {
00496 InterlacingPolicy::_gaussPresence=true;
00497 }
00498
00499 NoInterlaceByTypeGaussPolicy(int nbelem, int dim, int nbtypegeo,
00500 const int * const nbelgeoc, const int * const nbgaussgeo)
00501 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_NO_INTERLACE_BY_TYPE),_nbtypegeo(nbtypegeo) {
00502
00503 InterlacingPolicy::_gaussPresence=true;
00504
00505 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
00506 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
00507 _G.set(_nbtypegeo+1);
00508 _T.set(nbelem+1);
00509 int elemno = 1;
00510 int cumul = 0;
00511
00512 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
00513 int nbelcurtype = nbelgeoc[ntyp]-nbelgeoc[ntyp-1];
00514 for (int i=0; i < nbelcurtype; i++ ) {
00515 _T[ elemno ] = ntyp;
00516 elemno++;
00517 };
00518 _G[ ntyp ] = cumul;
00519 cumul += nbelcurtype * _dim * nbgaussgeo[ntyp];
00520 #ifdef ARRAY_DEBUG
00521 std::cout << "Valeur de cumul " << cumul << std::endl;
00522 #endif
00523 };
00524
00525 _arraySize = cumul;
00526
00527 #ifdef ARRAY_DEBUG
00528 for (int i =0; i< nbelem+1; i++ )
00529 std::cout << "Valeur de _T["<<i<<"] = "<<_T[i] << std::endl;
00530 #endif
00531 }
00532
00533
00534 NoInterlaceByTypeGaussPolicy(const NoInterlaceByTypeGaussPolicy & policy,
00535 bool shallowcopie=true)
00536 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo)
00537 {
00538
00539 if(shallowcopie) {
00540 this->_G.set(policy._G);
00541 this->_T.set(policy._T);
00542 } else {
00543 this->_G.set(_nbtypegeo+1,policy._G);
00544 this->_T.set(_nbelem+1,policy._T);
00545 }
00546
00547 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
00548 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
00549 }
00550
00551 NoInterlaceByTypeGaussPolicy & operator=(const NoInterlaceByTypeGaussPolicy & policy) {
00552 if ( this == &policy) return *this;
00553
00554 const char* LOC = "NoInterlaceGaussPolicy operator =";
00555 BEGIN_OF_MED(LOC);
00556 InterlacingPolicy::operator=(policy);
00557 this->_G.set(policy._G);
00558 this->_T.set(policy._T);
00559
00560
00561 this->_nbtypegeo=policy._nbtypegeo;
00562 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
00563 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
00564
00565 return *this;
00566 }
00567
00568 inline int getIndex(int t) const {
00569 return _G[t];
00570 }
00571 inline int getIndex(int i,int j ) const {
00572 int t = _T[i];
00573 return getIndexByType( i-(_nbelegeoc[t-1]-_nbelegeoc[0]), j, t );
00574 }
00575
00576 inline int getIndex(int i,int j, int k ) const {
00577 return getIndex( i, j ) + (k-1);
00578 }
00579
00580 inline int getIndexByType(int i,int j,int t) const {
00581 return _G[t] + (i-1 + (j-1)*(_nbelegeoc[t]-_nbelegeoc[t-1])) * _nbgaussgeo[t];
00582 }
00583
00584 inline int getIndexByType(int i,int j,int k,int t) const {
00585 return getIndexByType( i,j,t ) + (k-1);
00586 }
00587
00588 inline int getNbGauss(int i) const { return _nbgaussgeo[ _T[i] ]; }
00589
00590 inline int getNbGaussByType(int t) const { return _nbgaussgeo[ t ]; }
00591
00592 inline int getNbGeoType() const {return _nbtypegeo;}
00593
00594 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
00595
00596 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
00597
00598 inline int getLengthOfType(int t) const {
00599 return (_nbelegeoc[t]-_nbelegeoc[t-1]) * _dim * _nbgaussgeo[t];
00600 }
00601
00602 };
00603
00604 }
00605
00606 #endif