Salome HOME
5ce5d5769d2fe191799d4cbeeb254f619c886889
[modules/med.git] / src / MEDMEM / MEDMEM_GaussLocalization.hxx
1 // Copyright (C) 2007-2013  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
23 #ifndef GAUSS_LOCALIZATION_HXX
24 #define GAUSS_LOCALIZATION_HXX
25
26 #include <vector>
27 #include <MEDMEM.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"
34
35 using namespace std;
36 using namespace MEDMEM;
37 using namespace MED_EN;
38
39 namespace MEDMEM {
40
41   class MEDMEM_EXPORT GAUSS_LOCALIZATION_ {
42   public:
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é
45
46     /*!
47      * \brief Creates a localization filled with default values. The caller gets pointer ownership
48      */
49     static GAUSS_LOCALIZATION_* makeDefaultLocalization(const string &     locName,
50                                                         medGeometryElement typeGeo,
51                                                         int                nGauss) throw (MEDEXCEPTION);
52   };
53
54   template <class INTERLACING_TAG=FullInterlace> class GAUSS_LOCALIZATION;
55
56   template <class INTERLACING_TAG> ostream & operator<< (ostream &os,
57                                                          const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
58
59   template <class INTERLACING_TAG> class GAUSS_LOCALIZATION : public GAUSS_LOCALIZATION_{
60   public:
61     typedef  typename MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
62
63   protected:
64
65     string                      _locName;
66     MED_EN::medGeometryElement  _typeGeo;
67     int                         _nGauss;
68     ArrayNoGauss                _cooRef;
69     ArrayNoGauss                _cooGauss;
70     vector<double>              _wg;
71     MED_EN::medModeSwitch       _interlacingType;
72
73   public:
74     friend ostream & operator<< <INTERLACING_TAG>(ostream &os,
75                                                   const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
76
77     GAUSS_LOCALIZATION() throw (MEDEXCEPTION);
78     GAUSS_LOCALIZATION(const string & locName,
79                        const MED_EN::medGeometryElement typeGeo,
80                        const int  nGauss,
81                        const ArrayNoGauss & cooRef,
82                        const ArrayNoGauss & cooGauss,
83                        const vector<double>  & wg) throw (MEDEXCEPTION);
84
85     GAUSS_LOCALIZATION(const string & locName,
86                        const MED_EN::medGeometryElement  typeGeo,
87                        const int  nGauss,
88                        const double  * const cooRef,
89                        const double  * const cooGauss,
90                        const double  * const wg) throw (MEDEXCEPTION);
91
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;
96
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;}
104
105   };
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) 
109   {}
110
111   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION(const string & locName,
112                                                                                            const MED_EN::medGeometryElement typeGeo,
113                                                                                            const int  nGauss,
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)
119   {
120     const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const ArrayNoGauss & cooRef,..) : ";
121     BEGIN_OF_MED(LOC);
122     if (_cooRef.getDim() != _cooGauss.getDim() )
123       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
124
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))) ;
129
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 "
135                                      << _nGauss ));
136
137   END_OF_MED(LOC);
138   }
139
140   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION
141              (const string & locName,
142               const MED_EN::medGeometryElement  typeGeo,
143               const int  nGauss,
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)
152   {
153     const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const double * cooRef,..) :";
154     BEGIN_OF_MED(LOC);
155     if (_cooRef.getDim() != _cooGauss.getDim() )
156       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
157
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))) ;
161
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 "
167                                      << _nGauss ));
168   END_OF_MED(LOC);
169   }
170
171   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG> &
172   GAUSS_LOCALIZATION<INTERLACING_TAG>::operator=(const GAUSS_LOCALIZATION & gaussLoc)
173   {
174     if ( this == &gaussLoc) return *this;
175
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;
183     _wg       = gaussLoc._wg;
184
185     return *this;
186   }
187
188   template <class INTERLACING_TAG> bool
189   GAUSS_LOCALIZATION<INTERLACING_TAG>::operator == (const GAUSS_LOCALIZATION & gaussLoc) const {
190     return (
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
196             _wg       == gaussLoc._wg
197             );
198   }
199
200
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;
211     return os;
212   }
213
214 } //END NAMESPACE
215
216 #endif