Salome HOME
Join modifications from branch CEAFor_V3_2_0
[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) :
77     _typeGeo(MED_EN::MED_NONE), _nGauss(-1),
78     _interlacingType( SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType) 
79   {};
80
81   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG>::GAUSS_LOCALIZATION(const string & locName,
82                                                                                            const MED_EN::medGeometryElement typeGeo,
83                                                                                            const int  nGauss,
84                                                                                            const ArrayNoGauss & cooRef,
85                                                                                            const ArrayNoGauss & cooGauss,
86                                                                                            const vector<double>  & wg)  throw (MEDEXCEPTION) :
87     _locName(locName),_typeGeo(typeGeo),_nGauss(nGauss),_cooRef(cooRef),_cooGauss(cooGauss),_wg(wg),
88     _interlacingType(SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
89   {
90     const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const ArrayNoGauss & cooRef,..) : ";
91     BEGIN_OF(LOC);
92     if (_cooRef.getDim() != _cooGauss.getDim() )
93       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
94
95     if (_cooRef.getArraySize() != (_typeGeo%100)*(_typeGeo/100) )
96       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef size is " << _cooRef.getArraySize()
97                                      << " and should be (_typeGeo%100)*(_typeGeo/100) "
98                                      << (_typeGeo%100)*(_typeGeo/100))) ;
99
100     if (_cooGauss.getArraySize() != _nGauss*(_typeGeo/100) )
101       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooGauss must be of size nGauss*(_typeGeo/100) "
102                                      << _nGauss*(_typeGeo/100) ));
103     if (_wg.size() != _nGauss )
104       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"wg must be of size nGauss "
105                                      << _nGauss ));
106
107     END_OF(LOC);
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 double  * const cooRef,
114                                                                                            const double  * const cooGauss,
115                                                                                            const double  * const wg) throw (MEDEXCEPTION) :
116     _locName(locName),_typeGeo(typeGeo),_nGauss(nGauss),
117     _cooRef(ArrayNoGauss(const_cast<double *>(cooRef),typeGeo/100,typeGeo%100)),
118     _cooGauss(ArrayNoGauss(const_cast<double *>(cooGauss),typeGeo/100,_nGauss)),
119     _wg(vector<double>(wg,wg+nGauss)),
120     _interlacingType(SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
121   {
122     const char * LOC = "GAUSS_LOCALIZATION(locName,typeGeo, nGauss, const double * cooRef,..) :";
123     BEGIN_OF(LOC);
124     if (_cooRef.getDim() != _cooGauss.getDim() )
125       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef and cooGaus must have the same number of components")) ;
126
127     if (_cooRef.getArraySize() != (_typeGeo%100)*(_typeGeo/100) )
128       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooRef must be of size (_typeGeo%100)*(_typeGeo/100) "
129                                      << (_typeGeo%100)*(_typeGeo/100))) ;
130
131     if (_cooGauss.getArraySize() != _nGauss*(_typeGeo/100) )
132       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"cooGauss must be of size nGauss*(_typeGeo/100) "
133                                      << _nGauss*(_typeGeo/100) ));
134     if (_wg.size() != _nGauss )
135       throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<"wg must be of size nGauss "
136                                      << _nGauss ));
137     END_OF(LOC);
138   };
139
140   template <class INTERLACING_TAG> GAUSS_LOCALIZATION<INTERLACING_TAG> &
141   GAUSS_LOCALIZATION<INTERLACING_TAG>::operator=(const GAUSS_LOCALIZATION & gaussLoc)
142   {
143     if ( this == &gaussLoc) return *this;
144
145     _locName  = gaussLoc._locName;
146     _typeGeo  = gaussLoc._typeGeo;
147     _nGauss   = gaussLoc._nGauss;
148     _cooRef   = ArrayNoGauss(gaussLoc._cooRef);   //utilisation de la copie superficielle par défaut n'est pas une bonne idée
149     _cooGauss = ArrayNoGauss(gaussLoc._cooGauss);  //dans l'opérateur = de MEDnArray
150     _wg       = gaussLoc._wg;
151
152     return *this;
153   }
154
155   template <class INTERLACING_TAG> bool
156   GAUSS_LOCALIZATION<INTERLACING_TAG>::operator == (const GAUSS_LOCALIZATION & gaussLoc) const {
157     return (
158             _locName  == gaussLoc._locName &&
159             _typeGeo  == gaussLoc._typeGeo &&
160             _nGauss   == gaussLoc._nGauss  &&
161             _cooRef   == gaussLoc._cooRef  &&   //utilisation de la copie superficielle par défaut n'est pas une bonne idée
162             _cooGauss == gaussLoc._cooGauss &&  //dans l'opérateur = de MEDnArray
163             _wg       == gaussLoc._wg
164             );
165   }
166
167
168   template <class INTERLACING_TAG> ostream & operator<<(ostream &os,
169                                                                 const  GAUSS_LOCALIZATION<INTERLACING_TAG> &loc) {
170     os << "Localization Name     : " << loc._locName << endl;
171     os << "Geometric Type        : " << MED_EN::geoNames[loc._typeGeo]<< endl;
172     os << "Number Of GaussPoints : " << loc._nGauss << endl;
173     os << "Ref.   Element Coords : " << endl << loc._cooRef << endl;
174     os << "Gauss points Coords   : " << endl << loc._cooGauss << endl;
175     os << "Gauss points weigth   : " << endl ;
176     for(int i=0; i<loc._wg.size();++i)
177       os << "_wg[" << i << "] = " << loc._wg[i] << endl;
178     return os;
179   }
180
181 } //END NAMESPACE
182
183 #endif