1 // Copyright (C) 2007-2008 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
22 #ifndef MEDMEM_INTERLACING_HXX
23 #define MEDMEM_INTERLACING_HXX
28 #include "MEDMEM_Utilities.hxx"
30 #include "MEDMEM_PointerOf.hxx"
31 #include "MEDMEM_define.hxx"
35 class MEDMEM_EXPORT InterlacingPolicy {
37 ~InterlacingPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
39 InterlacingPolicy(void) : _dim(0), _nbelem(0),
41 _interlacing(MED_EN::MED_UNDEFINED_INTERLACE),
42 _gaussPresence(false) {}
44 InterlacingPolicy(int nbelem, int dim, int arraySize=0, int interlacing=MED_EN::MED_UNDEFINED_INTERLACE) :
47 _arraySize(arraySize),
48 _interlacing(interlacing),
49 _gaussPresence(false) {}
51 // Constructeur par recopie
52 InterlacingPolicy(const InterlacingPolicy & intpol,
53 bool shallowcopy = true) :_dim(intpol._dim),
54 _nbelem(intpol._nbelem),
55 _arraySize(intpol._arraySize),
56 _interlacing(intpol._interlacing),
57 _gaussPresence(intpol._gaussPresence) {}
59 InterlacingPolicy & operator=(const InterlacingPolicy & intpol) {
60 if ( this == &intpol ) return *this;
61 const char* LOC = "InterlacingPolicy operator =";
65 _nbelem = intpol._nbelem; //ne prend pas en compte les points de Gauss
66 _arraySize = intpol._arraySize;
67 _interlacing = intpol._interlacing;
68 _gaussPresence = intpol._gaussPresence;
73 inline int getDim() const { return _dim; }
74 inline int getNbElem() const { return _nbelem; }
75 inline int getArraySize() const { return _arraySize; }
76 inline MED_EN::medModeSwitch getInterlacingType() const {return _interlacing;}
77 inline bool getGaussPresence() const { return _gaussPresence;}
78 virtual int getNbGauss(int i) const = 0;
83 MED_EN::medModeSwitch _interlacing;
88 class MEDMEM_EXPORT FullInterlaceNoGaussPolicy : public InterlacingPolicy {
91 ~FullInterlaceNoGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
94 FullInterlaceNoGaussPolicy() : InterlacingPolicy() {}
95 FullInterlaceNoGaussPolicy(int nbelem, int dim) :
96 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_FULL_INTERLACE) {}
98 FullInterlaceNoGaussPolicy(const FullInterlaceNoGaussPolicy & policy,
99 bool shallowcopie=true)
100 : InterlacingPolicy(policy) {};
102 inline int getIndex(int i,int j) const {
103 return (i-1)*_dim + j-1;
106 inline int getIndex(int i,int j,int k) const {
107 return (i-1)*_dim + j-1;
110 inline int getNbGauss(int i) const { return 1; }
114 class MEDMEM_EXPORT NoInterlaceNoGaussPolicy : public InterlacingPolicy {
117 ~NoInterlaceNoGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
121 NoInterlaceNoGaussPolicy():InterlacingPolicy() {}
122 NoInterlaceNoGaussPolicy(int nbelem, int dim) :
123 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_NO_INTERLACE) {}
125 NoInterlaceNoGaussPolicy(const NoInterlaceNoGaussPolicy & policy,
126 bool shallowcopie=true)
127 : InterlacingPolicy(policy) {}
129 inline int getIndex(int i,int j) const {
130 return (j-1)*_nbelem + i-1;
133 inline int getIndex(int i,int j,int k) const {
134 return (j-1)*_nbelem + i-1;
137 inline int getNbGauss(int i) const { return 1; }
141 class MEDMEM_EXPORT NoInterlaceByTypeNoGaussPolicy : public InterlacingPolicy {
144 ~NoInterlaceByTypeNoGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
146 PointerOf<int> _T; //!< type of element
147 PointerOf<int> _G; //!< where type begin
149 PointerOf<int> _nbelegeoc;
153 NoInterlaceByTypeNoGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1)
157 NoInterlaceByTypeNoGaussPolicy(int nbelem, int dim):InterlacingPolicy()
159 // constructor is incoorect for this type of interlace
160 throw MEDEXCEPTION(LOCALIZED("Wrong constructor of NoInterlaceByTypeNoGaussPolicy "));
163 NoInterlaceByTypeNoGaussPolicy(int nbelem, int dim, int nbtypegeo,
164 const int * const nbelgeoc) :
165 InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_NO_INTERLACE_BY_TYPE),
166 _nbtypegeo(nbtypegeo)
168 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
174 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
175 int nbelcurtype = nbelgeoc[ntyp]-nbelgeoc[ntyp-1];
176 for (int i=0; i < nbelcurtype; i++ ) {
181 cumul += nbelcurtype*_dim;
183 std::cout << "Valeur de cumul " << cumul << std::endl;
190 for (int i =0; i< nbelem+1; i++ )
191 std::cout << "Valeur de _T["<<i<<"] = "<<_T[i] << std::endl;
195 NoInterlaceByTypeNoGaussPolicy(const NoInterlaceByTypeNoGaussPolicy & policy,
196 bool shallowcopie=true)
197 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo)
199 //Seuls les tableaux de grande taille sont recopiés superficiellement
202 this->_G.set(policy._G);
203 this->_T.set(policy._T);
207 this->_G.set(_nbtypegeo+1,policy._G);
208 this->_T.set(_nbelem+1,policy._T);
211 // Tableaux toujours recopiés par recopie profonde
212 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
215 NoInterlaceByTypeNoGaussPolicy & operator=(const NoInterlaceByTypeNoGaussPolicy & policy) {
216 if ( this == &policy) return *this;
218 const char* LOC = "NoInterlaceNoGaussPolicy operator =";
220 InterlacingPolicy::operator=(policy);
221 this->_G.set(policy._G);
222 this->_T.set(policy._T);
224 // Tableaux toujours recopiés par recopie profonde
225 this->_nbtypegeo=policy._nbtypegeo;
226 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
230 inline int getIndex(int t) const {
234 inline int getIndex(int i,int j) const {
236 return getIndexByType( i-(_nbelegeoc[t-1]-_nbelegeoc[0]), j, t );
239 inline int getIndex(int i,int j,int k) const {
240 return getIndex(i,j);
243 inline int getIndexByType(int i,int j,int t) const {
244 return _G[t] + i-1 + (j-1)*(_nbelegeoc[t]-_nbelegeoc[t-1]);
247 inline int getIndexByType(int i,int j,int k,int t) const {
248 return getIndexByType( i, j, t );
251 inline int getLengthOfType(int t) const {
252 return (_nbelegeoc[t]-_nbelegeoc[t-1]) * _dim;
255 inline int getNbGauss(int i) const { return 1; }
257 inline int getNbGeoType() const {return _nbtypegeo;}
259 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
263 class MEDMEM_EXPORT FullInterlaceGaussPolicy : public InterlacingPolicy {
265 ~FullInterlaceGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
271 PointerOf<int> _nbelegeoc;
272 PointerOf<int> _nbgaussgeo;
274 FullInterlaceGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1) {
275 InterlacingPolicy::_gaussPresence=true;
277 FullInterlaceGaussPolicy(int nbelem, int dim, int nbtypegeo,
278 const int * const nbelgeoc, const int * const nbgaussgeo)
279 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_FULL_INTERLACE),_nbtypegeo(nbtypegeo) {
281 InterlacingPolicy::_gaussPresence=true;
283 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
284 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
292 // Construction of _G
293 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
294 for (int i=0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) ; i++ ) {
295 _G[ elemno ] = cumul + i*nbgaussgeo[ntyp]*dim + 1;
297 _S[ elemno ] = nbgaussgeo[ntyp];
299 cumul += (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) * nbgaussgeo[ntyp] * dim;
301 std::cout << "Valeur de cumul " << cumul << std::endl;
305 _G[ elemno ] = cumul+1;
306 _arraySize = _G[ elemno ] -1 ;
309 for (int i =0; i< nbelem+1; i++ )
310 std::cout << "Valeur de _G["<<i<<"] = "<<_G[i] << std::endl;
314 FullInterlaceGaussPolicy(const FullInterlaceGaussPolicy & policy,
315 bool shallowcopie=true)
316 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo) {
318 //Seuls les tableaux de grande taille sont recopiés superficiellement
320 this->_G.set(policy._G);
321 this->_S.set(policy._S);
323 this->_G.set(_nbelem+1,policy._G);
324 this->_S.set(_nbelem+1,policy._S);
326 // Tableaux toujours recopiés par recopie profonde
327 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
328 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
331 FullInterlaceGaussPolicy & operator=(const FullInterlaceGaussPolicy & policy) {
332 const char* LOC = "FullInterlaceGaussPolicy operator =";
335 if ( this == &policy) return *this;
337 //Seuls les tableaux de grande taille sont recopiés superficiellement
338 InterlacingPolicy::operator=(policy);
339 this->_G.set(policy._G);
340 this->_S.set(policy._S);
342 // Tableaux toujours recopiés par recopie profonde
343 this->_nbtypegeo=policy._nbtypegeo;
344 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
345 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
350 inline int getIndex(int i,int j ) const {
351 return _G[i-1]-1 + (j-1);
354 inline int getIndex(int i,int j, int k ) const {
355 //std::cout << "Index : " << _G[i-1]-1 + _dim *(k-1) + (j-1) << std::endl;
356 return _G[i-1]-1 + (k-1)*_dim + (j-1);
359 inline int getNbGauss(int i) const { return _S[i]; }
361 inline int getNbGeoType() const {return _nbtypegeo;}
363 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
365 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
370 class MEDMEM_EXPORT NoInterlaceGaussPolicy : public InterlacingPolicy {
373 ~NoInterlaceGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
380 PointerOf<int> _nbelegeoc;
381 PointerOf<int> _nbgaussgeo;
382 // _cumul is used in getIndex() to access directly to the first value
383 // of a given dimension.
386 NoInterlaceGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1),_cumul(0) {
387 InterlacingPolicy::_gaussPresence=true;
390 NoInterlaceGaussPolicy(int nbelem, int dim, int nbtypegeo,
391 const int * const nbelgeoc, const int * const nbgaussgeo)
392 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_NO_INTERLACE),_nbtypegeo(nbtypegeo) {
394 InterlacingPolicy::_gaussPresence=true;
396 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
397 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
405 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
406 for (int i=0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) ; i++ ) {
407 _G[ elemno ] = _cumul + i*nbgaussgeo[ntyp] + 1;
409 _S[ elemno ] = nbgaussgeo[ntyp];
411 _cumul += (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) * nbgaussgeo[ntyp];
413 std::cout << "Valeur de _cumul " << _cumul << std::endl;
417 _G[ elemno ] = _cumul+1;
418 _arraySize = ( _G[ elemno ] -1 ) * dim ;
421 for (int i =0; i< nbelem+1; i++ )
422 std::cout << "Valeur de _G["<<i<<"] = "<<_G[i] << std::endl;
427 NoInterlaceGaussPolicy(const NoInterlaceGaussPolicy & policy,
428 bool shallowcopie=true)
429 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo),_cumul(policy._cumul)
431 //Seuls les tableaux de grande taille sont recopiés superficiellement
433 this->_G.set(policy._G);
434 this->_S.set(policy._S);
436 this->_G.set(_nbelem+1,policy._G);
437 this->_S.set(_nbelem+1,policy._S);
439 // Tableaux toujours recopiés par recopie profonde
440 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
441 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
444 NoInterlaceGaussPolicy & operator=(const NoInterlaceGaussPolicy & policy) {
445 if ( this == &policy) return *this;
447 const char* LOC = "NoInterlaceGaussPolicy operator =";
449 InterlacingPolicy::operator=(policy);
450 this->_G.set(policy._G);
451 this->_S.set(policy._S);
453 this->_cumul = policy._cumul;
455 // Tableaux toujours recopiés par recopie profonde
456 this->_nbtypegeo=policy._nbtypegeo;
457 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
458 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
463 inline int getIndex(int i,int j ) const {
464 return _G[i-1]-1 + (j-1)*_cumul ;
467 inline int getIndex(int i,int j, int k ) const {
468 return _G[i-1]-1 + (j-1)*_cumul + (k-1) ;
471 inline int getNbGauss(int i) const { return _S[i]; }
473 inline int getNbGeoType() const {return _nbtypegeo;}
475 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
477 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
481 class MEDMEM_EXPORT NoInterlaceByTypeGaussPolicy : public InterlacingPolicy {
484 ~NoInterlaceByTypeGaussPolicy() {} //pour éviter qu'un utilisateur cast la class array en politique
486 PointerOf<int> _T; //!< type of element
487 PointerOf<int> _G; //!< where type begin
489 PointerOf<int> _nbelegeoc;
490 PointerOf<int> _nbgaussgeo;
494 NoInterlaceByTypeGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1) {
495 InterlacingPolicy::_gaussPresence=true;
498 NoInterlaceByTypeGaussPolicy(int nbelem, int dim, int nbtypegeo,
499 const int * const nbelgeoc, const int * const nbgaussgeo)
500 : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_NO_INTERLACE_BY_TYPE),_nbtypegeo(nbtypegeo) {
502 InterlacingPolicy::_gaussPresence=true;
504 _nbelegeoc.set(_nbtypegeo+1,nbelgeoc);
505 _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo);
506 _G.set(_nbtypegeo+1);
511 for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) {
512 int nbelcurtype = nbelgeoc[ntyp]-nbelgeoc[ntyp-1];
513 for (int i=0; i < nbelcurtype; i++ ) {
518 cumul += nbelcurtype * _dim * nbgaussgeo[ntyp];
520 std::cout << "Valeur de cumul " << cumul << std::endl;
527 for (int i =0; i< nbelem+1; i++ )
528 std::cout << "Valeur de _T["<<i<<"] = "<<_T[i] << std::endl;
533 NoInterlaceByTypeGaussPolicy(const NoInterlaceByTypeGaussPolicy & policy,
534 bool shallowcopie=true)
535 : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo)
537 //Seuls les tableaux de grande taille sont recopiés superficiellement
539 this->_G.set(policy._G);
540 this->_T.set(policy._T);
542 this->_G.set(_nbtypegeo+1,policy._G);
543 this->_T.set(_nbelem+1,policy._T);
545 // Tableaux toujours recopiés par recopie profonde
546 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
547 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
550 NoInterlaceByTypeGaussPolicy & operator=(const NoInterlaceByTypeGaussPolicy & policy) {
551 if ( this == &policy) return *this;
553 const char* LOC = "NoInterlaceGaussPolicy operator =";
555 InterlacingPolicy::operator=(policy);
556 this->_G.set(policy._G);
557 this->_T.set(policy._T);
559 // Tableaux toujours recopiés par recopie profonde
560 this->_nbtypegeo=policy._nbtypegeo;
561 this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc);
562 this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo);
567 inline int getIndex(int t) const {
570 inline int getIndex(int i,int j ) const {
572 return getIndexByType( i-(_nbelegeoc[t-1]-_nbelegeoc[0]), j, t );
575 inline int getIndex(int i,int j, int k ) const {
576 return getIndex( i, j ) + (k-1);
579 inline int getIndexByType(int i,int j,int t) const {
580 return _G[t] + (i-1 + (j-1)*(_nbelegeoc[t]-_nbelegeoc[t-1])) * _nbgaussgeo[t];
583 inline int getIndexByType(int i,int j,int k,int t) const {
584 return getIndexByType( i,j,t ) + (k-1);
587 inline int getNbGauss(int i) const { return _nbgaussgeo[ _T[i] ]; }
589 inline int getNbGaussByType(int t) const { return _nbgaussgeo[ t ]; }
591 inline int getNbGeoType() const {return _nbtypegeo;}
593 inline const int * const getNbElemGeoC() const {return _nbelegeoc;}
595 inline const int * const getNbGaussGeo() const {return _nbgaussgeo;}
597 inline int getLengthOfType(int t) const {
598 return (_nbelegeoc[t]-_nbelegeoc[t-1]) * _dim * _nbgaussgeo[t];