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 GAUSS_LOCALIZATION_HXX
23 #define GAUSS_LOCALIZATION_HXX
27 #include "MEDMEM_define.hxx"
28 #include "MEDMEM_Exception.hxx"
29 #include "MEDMEM_ArrayInterface.hxx"
30 #include "MEDMEM_nArray.hxx"
31 #include "MEDMEM_DriversDef.hxx"
32 #include "MEDMEM_SetInterlacingType.hxx"
35 using namespace MEDMEM;
36 using namespace MED_EN;
40 class MEDMEM_EXPORT GAUSS_LOCALIZATION_ {
42 virtual MED_EN::medModeSwitch getInterlacingType() const {return MED_EN::MED_UNDEFINED_INTERLACE;}
43 virtual ~GAUSS_LOCALIZATION_() {}; //Indispensable pour détruire le vrai objet pointé
46 * \brief Creates a localization filled with default values. The caller gets pointer ownership
48 static GAUSS_LOCALIZATION_* makeDefaultLocalization(const string & locName,
49 medGeometryElement typeGeo,
50 int nGauss) throw (MEDEXCEPTION);
53 template <class INTERLACING_TAG=FullInterlace> class GAUSS_LOCALIZATION;
55 template <class INTERLACING_TAG> ostream & operator<< (ostream &os,
56 const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
58 template <class INTERLACING_TAG> class GAUSS_LOCALIZATION : public GAUSS_LOCALIZATION_{
60 typedef typename MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
65 MED_EN::medGeometryElement _typeGeo;
68 ArrayNoGauss _cooGauss;
70 MED_EN::medModeSwitch _interlacingType;
73 friend ostream & operator<< <INTERLACING_TAG>(ostream &os,
74 const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
76 GAUSS_LOCALIZATION() throw (MEDEXCEPTION);
77 GAUSS_LOCALIZATION(const string & locName,
78 const MED_EN::medGeometryElement typeGeo,
80 const ArrayNoGauss & cooRef,
81 const ArrayNoGauss & cooGauss,
82 const vector<double> & wg) throw (MEDEXCEPTION);
84 GAUSS_LOCALIZATION(const string & locName,
85 const MED_EN::medGeometryElement typeGeo,
87 const double * const cooRef,
88 const double * const cooGauss,
89 const double * const wg) throw (MEDEXCEPTION);
91 //GAUSS_LOCALIZATION(const GAUSS_LOCALIZATION & loc); constructeur de recopie par défaut correct
92 virtual ~GAUSS_LOCALIZATION() {};
93 GAUSS_LOCALIZATION & operator=(const GAUSS_LOCALIZATION & gaussLoc);
94 bool operator == (const GAUSS_LOCALIZATION &loc) const;
96 string getName() const {return _locName;}
97 MED_EN::medGeometryElement getType() const {return _typeGeo;}
98 int getNbGauss() const {return _nGauss;}
99 const ArrayNoGauss& getRefCoo () const {return _cooRef;} //Ces tableaux sont petits
100 const ArrayNoGauss& getGsCoo () const {return _cooGauss;} //Ces tableaux sont petits
101 vector <double> getWeight () const {return _wg;} //Ces tableaux sont petits
102 inline MED_EN::medModeSwitch getInterlacingType() const { return _interlacingType;}
105 template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION() throw (MEDEXCEPTION) :
106 _typeGeo(MED_EN::MED_NONE), _nGauss(-1),
107 _interlacingType( SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
110 template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION(const string & locName,
111 const MED_EN::medGeometryElement typeGeo,
113 const ArrayNoGauss & cooRef,
114 const ArrayNoGauss & cooGauss,
115 const vector<double> & wg) throw (MEDEXCEPTION) :
116 _locName(locName),_typeGeo(typeGeo),_nGauss(nGauss),_cooRef(cooRef),_cooGauss(cooGauss),_wg(wg),
117 _interlacingType(SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
119 const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const ArrayNoGauss & cooRef,..) : ";
121 if (_cooRef.getDim() != _cooGauss.getDim() )
122 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
124 if (_cooRef.getArraySize() != (_typeGeo%100)*(_typeGeo/100) )
125 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef size is " << _cooRef.getArraySize()
126 << " and should be (_typeGeo%100)*(_typeGeo/100) "
127 << (_typeGeo%100)*(_typeGeo/100))) ;
129 if (_cooGauss.getArraySize() != _nGauss*(_typeGeo/100) )
130 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooGauss must be of size nGauss*(_typeGeo/100) "
131 << _nGauss*(_typeGeo/100) ));
132 if (_wg.size() != _nGauss )
133 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"wg must be of size nGauss "
139 template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION
140 (const string & locName,
141 const MED_EN::medGeometryElement typeGeo,
143 const double * const cooRef,
144 const double * const cooGauss,
145 const double * const wg) throw (MEDEXCEPTION) :
146 _locName(locName),_typeGeo(typeGeo),_nGauss(nGauss),
147 _cooRef(ArrayNoGauss(const_cast<double *>(cooRef),typeGeo/100,typeGeo%100)),
148 _cooGauss(ArrayNoGauss(const_cast<double *>(cooGauss),typeGeo/100,_nGauss)),
149 _wg(vector<double>(wg,wg+nGauss)),
150 _interlacingType(SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
152 const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const double * cooRef,..) :";
154 if (_cooRef.getDim() != _cooGauss.getDim() )
155 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
157 if (_cooRef.getArraySize() != (_typeGeo%100)*(_typeGeo/100) )
158 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef must be of size (_typeGeo%100)*(_typeGeo/100) "
159 << (_typeGeo%100)*(_typeGeo/100))) ;
161 if (_cooGauss.getArraySize() != _nGauss*(_typeGeo/100) )
162 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooGauss must be of size nGauss*(_typeGeo/100) "
163 << _nGauss*(_typeGeo/100) ));
164 if (_wg.size() != _nGauss )
165 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"wg must be of size nGauss "
170 template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG> &
171 GAUSS_LOCALIZATION<INTERLACING_TAG>::operator=(const GAUSS_LOCALIZATION & gaussLoc)
173 if ( this == &gaussLoc) return *this;
175 _locName = gaussLoc._locName;
176 _typeGeo = gaussLoc._typeGeo;
177 _nGauss = gaussLoc._nGauss;
178 //_cooRef.setPtr((double*)gaussLoc._cooRef.getPtr(), false, true); //utilisation de la copie superficielle par défaut n'est pas une bonne idée
179 //_cooGauss.setPtr((double*)gaussLoc._cooGauss.getPtr(), false, true); //dans l'opérateur = de MEDnArray
180 _cooRef = gaussLoc._cooRef;
181 _cooGauss = gaussLoc._cooGauss;
187 template <class INTERLACING_TAG> bool
188 GAUSS_LOCALIZATION<INTERLACING_TAG>::operator == (const GAUSS_LOCALIZATION & gaussLoc) const {
190 _locName == gaussLoc._locName &&
191 _typeGeo == gaussLoc._typeGeo &&
192 _nGauss == gaussLoc._nGauss &&
193 _cooRef == gaussLoc._cooRef && //utilisation de la copie superficielle par défaut n'est pas une bonne idée
194 _cooGauss == gaussLoc._cooGauss && //dans l'opérateur = de MEDnArray
200 template <class INTERLACING_TAG> ostream & operator<<(ostream &os,
201 const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc) {
202 os << "Localization Name : " << loc._locName << endl;
203 os << "Geometric Type : " << MED_EN::geoNames[loc._typeGeo]<< endl;
204 os << "Number Of GaussPoints : " << loc._nGauss << endl;
205 os << "Ref. Element Coords : " << endl << loc._cooRef << endl;
206 os << "Gauss points Coords : " << endl << loc._cooGauss << endl;
207 os << "Gauss points weigth : " << endl ;
208 for(int i=0; i<loc._wg.size();++i)
209 os << "_wg[" << i << "] = " << loc._wg[i] << endl;