]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_GaussLocalization.hxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_GaussLocalization.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef GAUSS_LOCALIZATION_HXX
23 #define GAUSS_LOCALIZATION_HXX
24
25 #include <vector>
26 #include <MEDMEM.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"
33
34 using namespace std;
35 using namespace MEDMEM;
36 using namespace MED_EN;
37
38 namespace MEDMEM {
39
40   class MEDMEM_EXPORT GAUSS_LOCALIZATION_ {
41   public:
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é
44
45     /*!
46      * \brief Creates a localization filled with default values. The caller gets pointer ownership
47      */
48     static GAUSS_LOCALIZATION_* makeDefaultLocalization(const string &     locName,
49                                                         medGeometryElement typeGeo,
50                                                         int                nGauss) throw (MEDEXCEPTION);
51   };
52
53   template <class INTERLACING_TAG=FullInterlace> class GAUSS_LOCALIZATION;
54
55   template <class INTERLACING_TAG> ostream & operator<< (ostream &os,
56                                                          const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
57
58   template <class INTERLACING_TAG> class GAUSS_LOCALIZATION : public GAUSS_LOCALIZATION_{
59   public:
60     typedef  typename MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
61
62   protected:
63
64     string                      _locName;
65     MED_EN::medGeometryElement  _typeGeo;
66     int                         _nGauss;
67     ArrayNoGauss                _cooRef;
68     ArrayNoGauss                _cooGauss;
69     vector<double>              _wg;
70     MED_EN::medModeSwitch       _interlacingType;
71
72   public:
73     friend ostream & operator<< <INTERLACING_TAG>(ostream &os,
74                                                   const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
75
76     GAUSS_LOCALIZATION() throw (MEDEXCEPTION);
77     GAUSS_LOCALIZATION(const string & locName,
78                        const MED_EN::medGeometryElement typeGeo,
79                        const int  nGauss,
80                        const ArrayNoGauss & cooRef,
81                        const ArrayNoGauss & cooGauss,
82                        const vector<double>  & wg) throw (MEDEXCEPTION);
83
84     GAUSS_LOCALIZATION(const string & locName,
85                        const MED_EN::medGeometryElement  typeGeo,
86                        const int  nGauss,
87                        const double  * const cooRef,
88                        const double  * const cooGauss,
89                        const double  * const wg) throw (MEDEXCEPTION);
90
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;
95
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;}
103
104   };
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) 
108   {}
109
110   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION(const string & locName,
111                                                                                            const MED_EN::medGeometryElement typeGeo,
112                                                                                            const int  nGauss,
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)
118   {
119     const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const ArrayNoGauss & cooRef,..) : ";
120     BEGIN_OF_MED(LOC);
121     if (_cooRef.getDim() != _cooGauss.getDim() )
122       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
123
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))) ;
128
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 "
134                                      << _nGauss ));
135
136   END_OF_MED(LOC);
137   }
138
139   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION
140              (const string & locName,
141               const MED_EN::medGeometryElement  typeGeo,
142               const int  nGauss,
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)
151   {
152     const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const double * cooRef,..) :";
153     BEGIN_OF_MED(LOC);
154     if (_cooRef.getDim() != _cooGauss.getDim() )
155       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
156
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))) ;
160
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 "
166                                      << _nGauss ));
167   END_OF_MED(LOC);
168   }
169
170   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG> &
171   GAUSS_LOCALIZATION<INTERLACING_TAG>::operator=(const GAUSS_LOCALIZATION & gaussLoc)
172   {
173     if ( this == &gaussLoc) return *this;
174
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;
182     _wg       = gaussLoc._wg;
183
184     return *this;
185   }
186
187   template <class INTERLACING_TAG> bool
188   GAUSS_LOCALIZATION<INTERLACING_TAG>::operator == (const GAUSS_LOCALIZATION & gaussLoc) const {
189     return (
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
195             _wg       == gaussLoc._wg
196             );
197   }
198
199
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;
210     return os;
211   }
212
213 } //END NAMESPACE
214
215 #endif