Salome HOME
b488cb304861dbce0fd104f053644f64dbe1251b
[modules/med.git] / src / MEDMEM / MEDMEM_GaussLocalization.hxx
1 #ifndef GAUSS_LOCALIZATION_HXX
2 #define GAUSS_LOCALIZATION_HXX
3
4 #include <vector>
5 #include "MEDMEM_define.hxx"
6 #include "MEDMEM_Exception.hxx"
7 #include "MEDMEM_ArrayInterface.hxx"
8 #include "MEDMEM_nArray.hxx"
9 #include "MEDMEM_DriversDef.hxx"
10 #include "MEDMEM_SetInterlacingType.hxx"
11
12 using namespace std;
13 using namespace MEDMEM;
14 using namespace MED_EN;
15
16 namespace MEDMEM {
17
18   class GAUSS_LOCALIZATION_ {
19   public:
20     virtual MED_EN::medModeSwitch getInterlacingType() const {return MED_EN::MED_UNDEFINED_INTERLACE;}
21     virtual ~GAUSS_LOCALIZATION_() {}; //Indispensable pour détruire le vrai objet pointé
22   };
23
24   template <class INTERLACING_TAG=FullInterlace> class GAUSS_LOCALIZATION;
25
26   template <class INTERLACING_TAG> ostream & operator<< (ostream &os,
27                                                          const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
28
29   template <class INTERLACING_TAG> class GAUSS_LOCALIZATION : public GAUSS_LOCALIZATION_{
30   public:
31     typedef  typename MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
32
33   protected:
34
35     string                      _locName;
36     MED_EN::medGeometryElement  _typeGeo;
37     int                         _nGauss;
38     ArrayNoGauss                _cooRef;
39     ArrayNoGauss                _cooGauss;
40     vector<double>              _wg;
41     MED_EN::medModeSwitch       _interlacingType;
42
43   public:
44     friend ostream & operator<< <INTERLACING_TAG>(ostream &os,
45                                                   const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc);
46
47     GAUSS_LOCALIZATION() throw (MEDEXCEPTION);
48     GAUSS_LOCALIZATION(const string & locName,
49                        const MED_EN::medGeometryElement typeGeo,
50                        const int  nGauss,
51                        const ArrayNoGauss & cooRef,
52                        const ArrayNoGauss & cooGauss,
53                        const vector<double>  & wg) throw (MEDEXCEPTION);
54
55     GAUSS_LOCALIZATION(const string & locName,
56                        const MED_EN::medGeometryElement  typeGeo,
57                        const int  nGauss,
58                        const double  * const cooRef,
59                        const double  * const cooGauss,
60                        const double  * const wg) throw (MEDEXCEPTION);
61
62     //GAUSS_LOCALIZATION(const GAUSS_LOCALIZATION & loc); constructeur de recopie par défaut correct
63     virtual ~GAUSS_LOCALIZATION() {};
64     GAUSS_LOCALIZATION & operator=(const GAUSS_LOCALIZATION & gaussLoc);
65     bool operator == (const GAUSS_LOCALIZATION &loc) const;
66
67     string          getName()    const {return _locName;}
68     MED_EN::medGeometryElement getType() const {return _typeGeo;}
69     int             getNbGauss() const {return _nGauss;}
70     ArrayNoGauss    getRefCoo () const {return _cooRef;}     //Ces tableaux sont petits
71     ArrayNoGauss    getGsCoo  () const {return _cooGauss;}   //Ces tableaux sont petits
72     vector <double> getWeight () const {return _wg;}         //Ces tableaux sont petits
73     inline MED_EN::medModeSwitch  getInterlacingType() const { return _interlacingType;}
74
75   };
76   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION() throw (MEDEXCEPTION) : _typeGeo(MED_EN::MED_NONE), _nGauss(-1),
77                                                                                                                     _interlacingType(_interlacingType( SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType))  {};
78   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::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     _locName(locName),_typeGeo(typeGeo),_nGauss(nGauss),_cooRef(cooRef),_cooGauss(cooGauss),_wg(wg),
85     _interlacingType(SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
86   {
87     const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const ArrayNoGauss & cooRef,..) : ";
88     BEGIN_OF(LOC);
89     if (_cooRef.getDim() != _cooGauss.getDim() )
90       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
91
92     if (_cooRef.getArraySize() != (_typeGeo%100)*(_typeGeo/100) )
93       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef size is " << _cooRef.getArraySize()
94                                      << " and should be (_typeGeo%100)*(_typeGeo/100) "
95                                      << (_typeGeo%100)*(_typeGeo/100))) ;
96
97     if (_cooGauss.getArraySize() != _nGauss*(_typeGeo/100) )
98       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooGauss must be of size nGauss*(_typeGeo/100) "
99                                      << _nGauss*(_typeGeo/100) ));
100     if (_wg.size() != _nGauss )
101       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"wg must be of size nGauss "
102                                      << _nGauss ));
103
104     END_OF(LOC);
105   };
106
107   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION(const string & locName,
108                                                                                            const MED_EN::medGeometryElement  typeGeo,
109                                                                                            const int  nGauss,
110                                                                                            const double  * const cooRef,
111                                                                                            const double  * const cooGauss,
112                                                                                            const double  * const wg) throw (MEDEXCEPTION) :
113     _locName(locName),_typeGeo(typeGeo),_nGauss(nGauss),
114     _cooRef(ArrayNoGauss(const_cast<double *>(cooRef),typeGeo/100,typeGeo%100)),
115     _cooGauss(ArrayNoGauss(const_cast<double *>(cooGauss),typeGeo/100,_nGauss)),
116     _wg(vector<double>(wg,wg+nGauss)),
117     _interlacingType(SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
118   {
119     const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const double * cooRef,..) :";
120     BEGIN_OF(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 must be of size (_typeGeo%100)*(_typeGeo/100) "
126                                      << (_typeGeo%100)*(_typeGeo/100))) ;
127
128     if (_cooGauss.getArraySize() != _nGauss*(_typeGeo/100) )
129       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooGauss must be of size nGauss*(_typeGeo/100) "
130                                      << _nGauss*(_typeGeo/100) ));
131     if (_wg.size() != _nGauss )
132       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"wg must be of size nGauss "
133                                      << _nGauss ));
134     END_OF(LOC);
135   };
136
137   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG> &
138   GAUSS_LOCALIZATION<INTERLACING_TAG>::operator=(const GAUSS_LOCALIZATION & gaussLoc)
139   {
140     if ( this == &gaussLoc) return *this;
141
142     _locName  = gaussLoc._locName;
143     _typeGeo  = gaussLoc._typeGeo;
144     _nGauss   = gaussLoc._nGauss;
145     _cooRef   = ArrayNoGauss(gaussLoc._cooRef);   //utilisation de la copie superficielle par défaut n'est pas une bonne idée
146     _cooGauss = ArrayNoGauss(gaussLoc._cooGauss);  //dans l'opérateur = de MEDnArray
147     _wg       = gaussLoc._wg;
148
149     return *this;
150   }
151
152   template <class INTERLACING_TAG> bool
153   GAUSS_LOCALIZATION<INTERLACING_TAG>::operator == (const GAUSS_LOCALIZATION & gaussLoc) const {
154     return (
155             _locName  == gaussLoc._locName &&
156             _typeGeo  == gaussLoc._typeGeo &&
157             _nGauss   == gaussLoc._nGauss  &&
158             _cooRef   == gaussLoc._cooRef  &&   //utilisation de la copie superficielle par défaut n'est pas une bonne idée
159             _cooGauss == gaussLoc._cooGauss &&  //dans l'opérateur = de MEDnArray
160             _wg       == gaussLoc._wg
161             );
162   }
163
164
165   template <class INTERLACING_TAG> ostream & operator<<(ostream &os,
166                                                                 const  GAUSS_LOCALIZATION<INTERLACING_TAG> &loc) {
167     os << "Localization Name     : " << loc._locName << endl;
168     os << "Geometric Type        : " << MED_EN::geoNames[loc._typeGeo]<< endl;
169     os << "Number Of GaussPoints : " << loc._nGauss << endl;
170     os << "Ref.   Element Coords : " << endl << loc._cooRef << endl;
171     os << "Gauss points Coords   : " << endl << loc._cooGauss << endl;
172     os << "Gauss points weigth   : " << endl ;
173     for(int i=0; i<loc._wg.size();++i)
174       os << "_wg[" << i << "] = " << loc._wg[i] << endl;
175     return os;
176   }
177
178 } //END NAMESPACE
179
180 #endif