1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef MEDMEM_INTERLACING_HXX
24 #define MEDMEM_INTERLACING_HXX
29 #include "MEDMEM_Utilities.hxx"
31 #include "MEDMEM_PointerOf.hxx"
32 #include "MEDMEM_define.hxx"
36 class MEDMEM_EXPORT InterlacingPolicy {
38 ~InterlacingPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
40 InterlacingPolicy(void) : _dim(0), _nbelem(0),
42 _interlacing(MED_EN::MED_UNDEFINED_INTERLACE),
43 _gaussPresence(false) {}
45 InterlacingPolicy(int nbelem, int dim, int arraySize=0, int interlacing=MED_EN::MED_UNDEFINED_INTERLACE) :
48 _arraySize(arraySize),
49 _interlacing(interlacing),
50 _gaussPresence(false) {}
52 // Constructeur par recopie
53 InterlacingPolicy(const InterlacingPolicy & intpol,
54 bool shallowcopy = true) :_dim(intpol._dim),
55 _nbelem(intpol._nbelem),
56 _arraySize(intpol._arraySize),
57 _interlacing(intpol._interlacing),
58 _gaussPresence(intpol._gaussPresence) {}
60 InterlacingPolicy & operator=(const InterlacingPolicy & intpol) {
61 if ( this == &intpol ) return *this;
62 const char* LOC = "InterlacingPolicy operator =";
66 _nbelem = intpol._nbelem; //ne prend pas en compte les points de Gauss
67 _arraySize = intpol._arraySize;
68 _interlacing = intpol._interlacing;
69 _gaussPresence = intpol._gaussPresence;
74 inline int getDim() const { return _dim; }
75 inline int getNbElem() const { return _nbelem; }
76 inline int getArraySize() const { return _arraySize; }
77 inline MED_EN::medModeSwitch getInterlacingType() const {return _interlacing;}
78 inline bool getGaussPresence() const { return _gaussPresence;}
79 virtual int getNbGauss(int i) const = 0;
84 MED_EN::medModeSwitch _interlacing;
89 class MEDMEM_EXPORT FullInterlaceNoGaussPolicy : public InterlacingPolicy {
92 ~FullInterlaceNoGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
95 FullInterlaceNoGaussPolicy() : InterlacingPolicy() {}
96 FullInterlaceNoGaussPolicy(int nbelem, int dim) :
97 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_FULL_INTERLACE) {}
99 FullInterlaceNoGaussPolicy(const FullInterlaceNoGaussPolicy & policy,
100 bool shallowcopie=true)
101 : InterlacingPolicy(policy) {};
103 inline int getIndex(int i,int j) const {
104 return (i-1)*_dim + j-1;
107 inline int getIndex(int i,int j,int k) const {
108 return (i-1)*_dim + j-1;
111 inline int getNbGauss(int i) const { return 1; }
115 class MEDMEM_EXPORT NoInterlaceNoGaussPolicy : public InterlacingPolicy {
118 ~NoInterlaceNoGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
122 NoInterlaceNoGaussPolicy():InterlacingPolicy() {}
123 NoInterlaceNoGaussPolicy(int nbelem, int dim) :
124 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_NO_INTERLACE) {}
126 NoInterlaceNoGaussPolicy(const NoInterlaceNoGaussPolicy & policy,
127 bool shallowcopie=true)
128 : InterlacingPolicy(policy) {}
130 inline int getIndex(int i,int j) const {
131 return (j-1)*_nbelem + i-1;
134 inline int getIndex(int i,int j,int k) const {
135 return (j-1)*_nbelem + i-1;
138 inline int getNbGauss(int i) const { return 1; }
142 class MEDMEM_EXPORT NoInterlaceByTypeNoGaussPolicy : public InterlacingPolicy {
145 ~NoInterlaceByTypeNoGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
147 PointerOf<int> _T; //!< type of element
148 PointerOf<int> _G; //!< where type begin
150 PointerOf<int> _nbelegeoc;
154 NoInterlaceByTypeNoGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1)
158 NoInterlaceByTypeNoGaussPolicy(int nbelem, int dim):InterlacingPolicy()
160 // constructor is incoorect for this type of interlace
161 throw MEDEXCEPTION(LOCALIZED("Wrong constructor of NoInterlaceByTypeNoGaussPolicy "));
164 NoInterlaceByTypeNoGaussPolicy(int nbelem, int dim, int nbtypegeo,
165 const int * const nbelgeoc) :
166 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_NO_INTERLACE_BY_TYPE),
167 _nbtypegeo(nbtypegeo)
169 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
175 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
176 int nbelcurtype = nbelgeoc[ntyp]-nbelgeoc[ntyp-1];
177 for (int i=0; i < nbelcurtype; i++ ) {
182 cumul += nbelcurtype*_dim;
184 std::cout << "Valeur de cumul " << cumul << std::endl;
191 for (int i =0; i< nbelem+1; i++ )
192 std::cout << "Valeur de _T["<<i<<"] = "<<_T[i] << std::endl;
196 NoInterlaceByTypeNoGaussPolicy(const NoInterlaceByTypeNoGaussPolicy & policy,
197 bool shallowcopie=true)
198 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo)
200 //Seuls les tableaux de grande taille sont recopiés superficiellement
203 this->_G.set(policy._G);
204 this->_T.set(policy._T);
208 this->_G.set(_nbtypegeo+1,policy._G);
209 this->_T.set(_nbelem+1,policy._T);
212 // Tableaux toujours recopiés par recopie profonde
213 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
216 NoInterlaceByTypeNoGaussPolicy & operator=(const NoInterlaceByTypeNoGaussPolicy & policy) {
217 if ( this == &policy) return *this;
219 const char* LOC = "NoInterlaceNoGaussPolicy operator =";
221 InterlacingPolicy::operator=(policy);
222 this->_G.set(policy._G);
223 this->_T.set(policy._T);
225 // Tableaux toujours recopiés par recopie profonde
226 this->_nbtypegeo=policy._nbtypegeo;
227 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
231 inline int getIndex(int t) const {
235 inline int getIndex(int i,int j) const {
237 return getIndexByType( i-(_nbelegeoc[t-1]-_nbelegeoc[0]), j, t );
240 inline int getIndex(int i,int j,int k) const {
241 return getIndex(i,j);
244 inline int getIndexByType(int i,int j,int t) const {
245 return _G[t] + i-1 + (j-1)*(_nbelegeoc[t]-_nbelegeoc[t-1]);
248 inline int getIndexByType(int i,int j,int k,int t) const {
249 return getIndexByType( i, j, t );
252 inline int getLengthOfType(int t) const {
253 return (_nbelegeoc[t]-_nbelegeoc[t-1]) * _dim;
256 inline int getNbGauss(int i) const { return 1; }
258 inline int getNbGeoType() const {return _nbtypegeo;}
260 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
264 class MEDMEM_EXPORT FullInterlaceGaussPolicy : public InterlacingPolicy {
266 ~FullInterlaceGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
272 PointerOf<int> _nbelegeoc;
273 PointerOf<int> _nbgaussgeo;
275 FullInterlaceGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1) {
276 InterlacingPolicy::_gaussPresence=true;
278 FullInterlaceGaussPolicy(int nbelem, int dim, int nbtypegeo,
279 const int * const nbelgeoc, const int * const nbgaussgeo)
280 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_FULL_INTERLACE),_nbtypegeo(nbtypegeo) {
282 InterlacingPolicy::_gaussPresence=true;
284 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
285 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
293 // Construction of _G
294 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
295 for (int i=0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) ; i++ ) {
296 _G[ elemno ] = cumul + i*nbgaussgeo[ntyp]*dim + 1;
298 _S[ elemno ] = nbgaussgeo[ntyp];
300 cumul += (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) * nbgaussgeo[ntyp] * dim;
302 std::cout << "Valeur de cumul " << cumul << std::endl;
306 _G[ elemno ] = cumul+1;
307 _arraySize = _G[ elemno ] -1 ;
310 for (int i =0; i< nbelem+1; i++ )
311 std::cout << "Valeur de _G["<<i<<"] = "<<_G[i] << std::endl;
315 FullInterlaceGaussPolicy(const FullInterlaceGaussPolicy & policy,
316 bool shallowcopie=true)
317 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo) {
319 //Seuls les tableaux de grande taille sont recopiés superficiellement
321 this->_G.set(policy._G);
322 this->_S.set(policy._S);
324 this->_G.set(_nbelem+1,policy._G);
325 this->_S.set(_nbelem+1,policy._S);
327 // Tableaux toujours recopiés par recopie profonde
328 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
329 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
332 FullInterlaceGaussPolicy & operator=(const FullInterlaceGaussPolicy & policy) {
333 const char* LOC = "FullInterlaceGaussPolicy operator =";
336 if ( this == &policy) return *this;
338 //Seuls les tableaux de grande taille sont recopiés superficiellement
339 InterlacingPolicy::operator=(policy);
340 this->_G.set(policy._G);
341 this->_S.set(policy._S);
343 // Tableaux toujours recopiés par recopie profonde
344 this->_nbtypegeo=policy._nbtypegeo;
345 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
346 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
351 inline int getIndex(int i,int j ) const {
352 return _G[i-1]-1 + (j-1);
355 inline int getIndex(int i,int j, int k ) const {
356 //std::cout << "Index : " << _G[i-1]-1 + _dim *(k-1) + (j-1) << std::endl;
357 return _G[i-1]-1 + (k-1)*_dim + (j-1);
360 inline int getNbGauss(int i) const { return _S[i]; }
362 inline int getNbGeoType() const {return _nbtypegeo;}
364 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
366 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
371 class MEDMEM_EXPORT NoInterlaceGaussPolicy : public InterlacingPolicy {
374 ~NoInterlaceGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
381 PointerOf<int> _nbelegeoc;
382 PointerOf<int> _nbgaussgeo;
383 // _cumul is used in getIndex() to access directly to the first value
384 // of a given dimension.
387 NoInterlaceGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1),_cumul(0) {
388 InterlacingPolicy::_gaussPresence=true;
391 NoInterlaceGaussPolicy(int nbelem, int dim, int nbtypegeo,
392 const int * const nbelgeoc, const int * const nbgaussgeo)
393 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_NO_INTERLACE),_nbtypegeo(nbtypegeo) {
395 InterlacingPolicy::_gaussPresence=true;
397 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
398 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
406 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
407 for (int i=0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) ; i++ ) {
408 _G[ elemno ] = _cumul + i*nbgaussgeo[ntyp] + 1;
410 _S[ elemno ] = nbgaussgeo[ntyp];
412 _cumul += (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) * nbgaussgeo[ntyp];
414 std::cout << "Valeur de _cumul " << _cumul << std::endl;
418 _G[ elemno ] = _cumul+1;
419 _arraySize = ( _G[ elemno ] -1 ) * dim ;
422 for (int i =0; i< nbelem+1; i++ )
423 std::cout << "Valeur de _G["<<i<<"] = "<<_G[i] << std::endl;
428 NoInterlaceGaussPolicy(const NoInterlaceGaussPolicy & policy,
429 bool shallowcopie=true)
430 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo),_cumul(policy._cumul)
432 //Seuls les tableaux de grande taille sont recopiés superficiellement
434 this->_G.set(policy._G);
435 this->_S.set(policy._S);
437 this->_G.set(_nbelem+1,policy._G);
438 this->_S.set(_nbelem+1,policy._S);
440 // Tableaux toujours recopiés par recopie profonde
441 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
442 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
445 NoInterlaceGaussPolicy & operator=(const NoInterlaceGaussPolicy & policy) {
446 if ( this == &policy) return *this;
448 const char* LOC = "NoInterlaceGaussPolicy operator =";
450 InterlacingPolicy::operator=(policy);
451 this->_G.set(policy._G);
452 this->_S.set(policy._S);
454 this->_cumul = policy._cumul;
456 // Tableaux toujours recopiés par recopie profonde
457 this->_nbtypegeo=policy._nbtypegeo;
458 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
459 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
464 inline int getIndex(int i,int j ) const {
465 return _G[i-1]-1 + (j-1)*_cumul ;
468 inline int getIndex(int i,int j, int k ) const {
469 return _G[i-1]-1 + (j-1)*_cumul + (k-1) ;
472 inline int getNbGauss(int i) const { return _S[i]; }
474 inline int getNbGeoType() const {return _nbtypegeo;}
476 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
478 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
482 class MEDMEM_EXPORT NoInterlaceByTypeGaussPolicy : public InterlacingPolicy {
485 ~NoInterlaceByTypeGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
487 PointerOf<int> _T; //!< type of element
488 PointerOf<int> _G; //!< where type begin
490 PointerOf<int> _nbelegeoc;
491 PointerOf<int> _nbgaussgeo;
495 NoInterlaceByTypeGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1) {
496 InterlacingPolicy::_gaussPresence=true;
499 NoInterlaceByTypeGaussPolicy(int nbelem, int dim, int nbtypegeo,
500 const int * const nbelgeoc, const int * const nbgaussgeo)
501 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_NO_INTERLACE_BY_TYPE),_nbtypegeo(nbtypegeo) {
503 InterlacingPolicy::_gaussPresence=true;
505 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
506 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
507 _G.set(_nbtypegeo+1);
512 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
513 int nbelcurtype = nbelgeoc[ntyp]-nbelgeoc[ntyp-1];
514 for (int i=0; i < nbelcurtype; i++ ) {
519 cumul += nbelcurtype * _dim * nbgaussgeo[ntyp];
521 std::cout << "Valeur de cumul " << cumul << std::endl;
528 for (int i =0; i< nbelem+1; i++ )
529 std::cout << "Valeur de _T["<<i<<"] = "<<_T[i] << std::endl;
534 NoInterlaceByTypeGaussPolicy(const NoInterlaceByTypeGaussPolicy & policy,
535 bool shallowcopie=true)
536 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo)
538 //Seuls les tableaux de grande taille sont recopiés superficiellement
540 this->_G.set(policy._G);
541 this->_T.set(policy._T);
543 this->_G.set(_nbtypegeo+1,policy._G);
544 this->_T.set(_nbelem+1,policy._T);
546 // Tableaux toujours recopiés par recopie profonde
547 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
548 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
551 NoInterlaceByTypeGaussPolicy & operator=(const NoInterlaceByTypeGaussPolicy & policy) {
552 if ( this == &policy) return *this;
554 const char* LOC = "NoInterlaceGaussPolicy operator =";
556 InterlacingPolicy::operator=(policy);
557 this->_G.set(policy._G);
558 this->_T.set(policy._T);
560 // Tableaux toujours recopiés par recopie profonde
561 this->_nbtypegeo=policy._nbtypegeo;
562 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
563 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
568 inline int getIndex(int t) const {
571 inline int getIndex(int i,int j ) const {
573 return getIndexByType( i-(_nbelegeoc[t-1]-_nbelegeoc[0]), j, t );
576 inline int getIndex(int i,int j, int k ) const {
577 return getIndex( i, j ) + (k-1);
580 inline int getIndexByType(int i,int j,int t) const {
581 return _G[t] + (i-1 + (j-1)*(_nbelegeoc[t]-_nbelegeoc[t-1])) * _nbgaussgeo[t];
584 inline int getIndexByType(int i,int j,int k,int t) const {
585 return getIndexByType( i,j,t ) + (k-1);
588 inline int getNbGauss(int i) const { return _nbgaussgeo[ _T[i] ]; }
590 inline int getNbGaussByType(int t) const { return _nbgaussgeo[ t ]; }
592 inline int getNbGeoType() const {return _nbtypegeo;}
594 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
596 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
598 inline int getLengthOfType(int t) const {
599 return (_nbelegeoc[t]-_nbelegeoc[t-1]) * _dim * _nbgaussgeo[t];