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 GAUSS_LOCALIZATION_HXX
24 #define GAUSS_LOCALIZATION_HXX
28 #include "MEDMEM_define.hxx"
29 #include "MEDMEM_Exception.hxx"
30 #include "MEDMEM_ArrayInterface.hxx"
31 #include "MEDMEM_nArray.hxx"
32 #include "MEDMEM_DriversDef.hxx"
33 #include "MEDMEM_SetInterlacingType.hxx"
36 using namespace MEDMEM;
37 using namespace MED_EN;
41 class MEDMEM_EXPORT GAUSS_LOCALIZATION_ {
43 virtual MED_EN::medModeSwitch getInterlacingType() const {return MED_EN::MED_UNDEFINED_INTERLACE;}
44 virtual ~GAUSS_LOCALIZATION_() {}; //Indispensable pour détruire le vrai objet pointé
47 * \brief Creates a localization filled with default values. The caller gets pointer ownership
49 static GAUSS_LOCALIZATION_* makeDefaultLocalization(const string & locName,
50 medGeometryElement typeGeo,
51 int nGauss) throw (MEDEXCEPTION);
54 template <class INTERLACING_TAG=FullInterlace> class GAUSS_LOCALIZATION;
56 template <class INTERLACING_TAG> ostream & operator<< (ostream &os,
57 const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
59 template <class INTERLACING_TAG> class GAUSS_LOCALIZATION : public GAUSS_LOCALIZATION_{
61 typedef typename MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
66 MED_EN::medGeometryElement _typeGeo;
69 ArrayNoGauss _cooGauss;
71 MED_EN::medModeSwitch _interlacingType;
74 friend ostream & operator<< <INTERLACING_TAG>(ostream &os,
75 const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
77 GAUSS_LOCALIZATION() throw (MEDEXCEPTION);
78 GAUSS_LOCALIZATION(const string & locName,
79 const MED_EN::medGeometryElement typeGeo,
81 const ArrayNoGauss & cooRef,
82 const ArrayNoGauss & cooGauss,
83 const vector<double> & wg) throw (MEDEXCEPTION);
85 GAUSS_LOCALIZATION(const string & locName,
86 const MED_EN::medGeometryElement typeGeo,
88 const double * const cooRef,
89 const double * const cooGauss,
90 const double * const wg) throw (MEDEXCEPTION);
92 //GAUSS_LOCALIZATION(const GAUSS_LOCALIZATION & loc); constructeur de recopie par défaut correct
93 virtual ~GAUSS_LOCALIZATION() {};
94 GAUSS_LOCALIZATION & operator=(const GAUSS_LOCALIZATION & gaussLoc);
95 bool operator == (const GAUSS_LOCALIZATION &loc) const;
97 string getName() const {return _locName;}
98 MED_EN::medGeometryElement getType() const {return _typeGeo;}
99 int getNbGauss() const {return _nGauss;}
100 const ArrayNoGauss& getRefCoo () const {return _cooRef;} //Ces tableaux sont petits
101 const ArrayNoGauss& getGsCoo () const {return _cooGauss;} //Ces tableaux sont petits
102 vector <double> getWeight () const {return _wg;} //Ces tableaux sont petits
103 inline MED_EN::medModeSwitch getInterlacingType() const { return _interlacingType;}
106 template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION() throw (MEDEXCEPTION) :
107 _typeGeo(MED_EN::MED_NONE), _nGauss(-1),
108 _interlacingType( SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
111 template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION(const string & locName,
112 const MED_EN::medGeometryElement typeGeo,
114 const ArrayNoGauss & cooRef,
115 const ArrayNoGauss & cooGauss,
116 const vector<double> & wg) throw (MEDEXCEPTION) :
117 _locName(locName),_typeGeo(typeGeo),_nGauss(nGauss),_cooRef(cooRef),_cooGauss(cooGauss),_wg(wg),
118 _interlacingType(SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
120 const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const ArrayNoGauss & cooRef,..) : ";
122 if (_cooRef.getDim() != _cooGauss.getDim() )
123 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
125 if (_cooRef.getArraySize() != (_typeGeo%100)*(_typeGeo/100) )
126 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef size is " << _cooRef.getArraySize()
127 << " and should be (_typeGeo%100)*(_typeGeo/100) "
128 << (_typeGeo%100)*(_typeGeo/100))) ;
130 if (_cooGauss.getArraySize() != _nGauss*(_typeGeo/100) )
131 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooGauss must be of size nGauss*(_typeGeo/100) "
132 << _nGauss*(_typeGeo/100) ));
133 if ((int)_wg.size() != _nGauss )
134 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"wg must be of size nGauss "
140 template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION
141 (const string & locName,
142 const MED_EN::medGeometryElement typeGeo,
144 const double * const cooRef,
145 const double * const cooGauss,
146 const double * const wg) throw (MEDEXCEPTION) :
147 _locName(locName),_typeGeo(typeGeo),_nGauss(nGauss),
148 _cooRef(ArrayNoGauss(const_cast<double *>(cooRef),typeGeo/100,typeGeo%100)),
149 _cooGauss(ArrayNoGauss(const_cast<double *>(cooGauss),typeGeo/100,_nGauss)),
150 _wg(vector<double>(wg,wg+nGauss)),
151 _interlacingType(SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
153 const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const double * cooRef,..) :";
155 if (_cooRef.getDim() != _cooGauss.getDim() )
156 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
158 if (_cooRef.getArraySize() != (_typeGeo%100)*(_typeGeo/100) )
159 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef must be of size (_typeGeo%100)*(_typeGeo/100) "
160 << (_typeGeo%100)*(_typeGeo/100))) ;
162 if (_cooGauss.getArraySize() != _nGauss*(_typeGeo/100) )
163 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooGauss must be of size nGauss*(_typeGeo/100) "
164 << _nGauss*(_typeGeo/100) ));
165 if ((int)_wg.size() != _nGauss )
166 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"wg must be of size nGauss "
171 template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG> &
172 GAUSS_LOCALIZATION<INTERLACING_TAG>::operator=(const GAUSS_LOCALIZATION & gaussLoc)
174 if ( this == &gaussLoc) return *this;
176 _locName = gaussLoc._locName;
177 _typeGeo = gaussLoc._typeGeo;
178 _nGauss = gaussLoc._nGauss;
179 //_cooRef.setPtr((double*)gaussLoc._cooRef.getPtr(), false, true); //utilisation de la copie superficielle par défaut n'est pas une bonne idée
180 //_cooGauss.setPtr((double*)gaussLoc._cooGauss.getPtr(), false, true); //dans l'opérateur = de MEDnArray
181 _cooRef = gaussLoc._cooRef;
182 _cooGauss = gaussLoc._cooGauss;
188 template <class INTERLACING_TAG> bool
189 GAUSS_LOCALIZATION<INTERLACING_TAG>::operator == (const GAUSS_LOCALIZATION & gaussLoc) const {
191 _locName == gaussLoc._locName &&
192 _typeGeo == gaussLoc._typeGeo &&
193 _nGauss == gaussLoc._nGauss &&
194 _cooRef == gaussLoc._cooRef && //utilisation de la copie superficielle par défaut n'est pas une bonne idée
195 _cooGauss == gaussLoc._cooGauss && //dans l'opérateur = de MEDnArray
201 template <class INTERLACING_TAG> ostream & operator<<(ostream &os,
202 const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc) {
203 os << "Localization Name : " << loc._locName << endl;
204 os << "Geometric Type : " << MED_EN::geoNames[loc._typeGeo]<< endl;
205 os << "Number Of GaussPoints : " << loc._nGauss << endl;
206 os << "Ref. Element Coords : " << endl << loc._cooRef << endl;
207 os << "Gauss points Coords : " << endl << loc._cooGauss << endl;
208 os << "Gauss points weigth : " << endl ;
209 for(unsigned i=0; i<loc._wg.size();++i)
210 os << "_wg[" << i << "] = " << loc._wg[i] << endl;