]> SALOME platform Git repositories - tools/solverlab.git/blob - CDMATH/mesh/inc/Field.hxx
Salome HOME
542a68828597d9764bd0e6f49bf72ce216199ce1
[tools/solverlab.git] / CDMATH / mesh / inc / Field.hxx
1 /*
2  * field.hxx
3  *
4  *  Created on: 07 fevrier. 2012
5  *      Authors: CDMAT groups
6  */
7
8 #ifndef FIELD_HXX_
9 #define FIELD_HXX_
10
11 namespace MEDCoupling
12 {
13   class MEDCouplingFieldDouble;
14   class DataArrayDouble;
15 }
16
17 #include "DoubleTab.hxx"
18 #include "Vector.hxx"
19 #include "Mesh.hxx"
20
21 #include <MCAuto.hxx>
22
23 /**
24  * Field class is defined by
25  * - ........
26  */
27
28 class Field
29 {
30     public: //----------------------------------------------------------------
31     /**
32      * default constructor
33      */
34     Field ( EntityType typeField = CELLS ) ;
35
36     /**
37     * constructor with data:
38     * @param fieldName : name of the field
39     * @param type : type of the field
40     * @param mesh : mesh of the field
41     * @param numberOfComponents : number of the component
42     * @param time : time of the field
43     */
44     Field(const std::string fieldName, EntityType type, const Mesh& mesh, int numberOfComponents=1, double time=0.0) ;
45
46     /**
47     * destructor
48     */
49     ~Field ( void ) ;
50
51     /**
52     * constructor by copy
53     * @param field : The Field object to be copied
54     */
55     Field ( const Field & field ) ;
56
57     /**
58      * deep copy of a field (values are copied)
59      * @param field : The Field object to be copied
60      */
61     Field deepCopy( ) const;
62
63     /**
64      * constructor with data
65      * @param filename : file name of field med file
66      * @param fieldType: field type
67      * @param fieldName: field name
68      * @param iteration: iteration number (optional)
69      * @param order:     order inside an iteration (optional)
70      * @param numberOfComponents:     number of components of the field (optional)
71      * @param time:     time index of the field (optional)
72      */
73     Field( const std::string filename, EntityType fieldType,
74            const std::string & fieldName = "",
75            int iteration = -1, int order = -1, int meshLevel=0,
76            int numberOfComponents=1, double time=0.0);
77   
78     /**
79      * constructor with data
80          * \brief defines a constant field on a mesh stored in a med file
81          * \details
82          * \param [in] string : the mesh file name
83      * \param fieldType: field type
84          * \param [in] vector<double> : the value in each cell
85      * \param [in] fieldName: field name
86          * \param [in] meshLevel : relative mesh dimension : 0->cells, 1->Faces etc
87          *  */
88         Field(const std::string meshfileName, EntityType fieldType, 
89                   const std::vector<double> Vconstant,const std::string & fieldName = "",
90                    int meshLevel=0, double time=0.0);
91
92     /**
93      * constructor with data
94          * \brief defines a constant field 
95          * \details
96          * \param [in] Mesh 
97      * \param [in] fieldType: field type
98          * \param [in] Vector
99      * \param [in] fieldName: field name
100          *  */
101         Field(const Mesh& M, EntityType fieldType, const Vector Vconstant,
102                   const std::string & fieldName = "", double time=0.0);
103
104     /**
105      * constructor with data
106          * \brief defines a constant field 
107          * \details
108          * \param [in] Mesh
109      * \param [in] fieldType: field type
110          * \param [in] vector<double>
111      * \param [in] fieldName: field name
112          *  */
113         Field(const Mesh& M, EntityType fieldType, const std::vector<double> Vconstant, const std::string & fieldName = "", double time=0.0);
114
115     /**
116      * constructor with data
117          * \brief Builds a rectangular mesh M and defines a constant field on M
118          * \details
119          * \param [in] int the space dimension
120          * \param [in] vector<double> the value in each cell
121      * \param [in] fieldType: field type
122      * \param [in] fieldName: field name
123          * \param [in] double the lowest value in the x direction
124          * \param [in] double the highest value in the x direction
125          * \param [in] string name of the left boundary
126          * \param [in] string name of the right boundary
127          * \param [in] double the lowest value in the y direction
128          * \param [in] double the highest value in the y direction
129          * \param [in] string name of the back boundary
130          * \param [in] string name of the front boundary
131          * \param [in] double the lowest value in the z direction
132          * \param [in] double the highest value in the z direction
133          * \param [in] string name of the bottom boundary
134          * \param [in] string name of the top boundary
135          *  */
136         Field( int nDim, const std::vector<double> Vconstant, EntityType type, 
137                         double xmin, double xmax,int nx, std::string leftSide, std::string rightSide,
138                         double ymin=0, double ymax=0, int ny=0, std::string backSide="", std::string frontSide="",
139                         double zmin=0, double zmax=0, int nz=0, std::string bottomSide="", std::string topSide="",
140                         const std::string & fieldName="", double time=0.0,double epsilon=1e-6);
141
142     /**
143      * constructor with data
144          * \brief Builds a step function field on the mesh M. The direction of the discontinuity is determined by the parameter "direction". The field takes value VV_left for x,y or z<disc_pos and VV_right for x,y or z>disc_pos
145          * \details
146          * \param [in] Mesh
147          * \param [in] Vector
148          * \param [in] Vector
149          * \param [in] double position of the discontinuity on one of the three axis
150          * \param [in] int direction (axis carrying the discontinuity) : 0 for x, 1 for y, 2 for z
151      * \param [in] fieldType: field type
152      * \param [in] fieldName: field name
153          *  */
154         Field(const Mesh M, const Vector VV_left, const Vector VV_right, double disc_pos, 
155                         EntityType type, int direction=0, const std::string & fieldName="", double time=0.0);
156
157     /**
158      * constructor with data
159          * \brief Builds a rectangular mesh M and defines a step function field on M that takes values VV_left for x<xstep and VV_right for x>xstep
160          * \param [in] int the space dimension
161          * \param [in] vector<double> the value left of the discontinuity
162          * \param [in] vector<double> the value right of the discontinuity
163          * \param [in] double the position of the discontinuity in the x direction
164      * \param [in] fieldType: field type
165      * \param [in] fieldName: field name
166          * \param [in] double the lowest value in the x direction
167          * \param [in] double the highest value in the x direction
168          * \param [in] string name of the left boundary
169          * \param [in] string name of the right boundary
170          * \param [in] double the lowest value in the y direction
171          * \param [in] double the highest value in the y direction
172          * \param [in] string name of the back boundary
173          * \param [in] string name of the front boundary
174          * \param [in] double the lowest value in the z direction
175          * \param [in] double the highest value in the z direction
176          * \param [in] string name of the bottom boundary
177          * \param [in] string name of the top boundary
178          * \param [out] void
179          *  */
180         Field( int nDim, const std::vector<double> VV_Left, std::vector<double> VV_Right, 
181                         double xstep, EntityType type,
182                         double xmin, double xmax,int nx, std::string leftSide, std::string rightSide,
183                         double ymin=0, double ymax=0, int ny=0, std::string backSide="", std::string frontSide="",
184                         double zmin=0, double zmax=0, int nz=0, std::string bottomSide="", std::string topSide="",
185                         int direction=0, const std::string & fieldName="", double time=0.0, double epsilon=1e-6);
186
187     /**
188      * constructor with data
189          * \brief builds a step function field on mesh M with values Vin inside the ball with radius Radius and Vout outside
190          * \details
191          * \param [in] Mesh
192          * \param [in] Vector Vin, value inside the ball
193          * \param [in] Vector Vout, value outside the ball
194          * \param [in] double radius of the ball
195          * \param [in] Vector Center, coordinates of the ball center
196      * \param [in] fieldType: field type
197      * \param [in] fieldName: field name
198          *  */
199         Field(const Mesh M, const Vector Vin, const Vector Vout, double Radius, 
200                         Vector Center, EntityType type, const std::string & fieldName="", double time=0.0);
201
202     void readFieldMed( const std::string & fileNameRadical,
203                        EntityType type,
204                        const std::string & fieldName = "",
205                        int iteration = -1,
206                        int order = -1) ;
207
208     void buildFieldMemoryStructure();
209
210     MEDCoupling::DataArrayDouble * getArray();
211
212     double& operator[] ( int ielem ) ;
213
214     double operator[] ( int ielem ) const;
215
216     double& operator() ( int ielem ) ;
217
218     double operator() ( int ielem ) const;
219
220     double& operator() ( int ielem, int jcomp ) ;
221
222     double operator() ( int ielem, int jcomp ) const ;
223
224     int getNumberOfComponents ( void ) const ;
225
226     const double* getValues ( void ) const ;
227
228     void getValues ( Vector myVector ) const ;
229
230     void setValues ( Vector values ) ;
231
232     void setValues ( double * values, int nbValues ) ;
233
234     const std::string getName ( void ) const;
235
236     const Mesh& getMesh ( void ) const ;
237
238     int getNumberOfElements ( void ) const ;
239
240     EntityType getTypeOfField ( void ) const ;
241
242         // returns the x, y or z component of the element (node cell or face) with number i
243     double getElementComponent(int i, int comp) const;
244     /**
245      * return the MEDCouplingField pointer
246      * return _field
247      */
248     MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> getField ( void )  const ;
249
250     void setFieldByMEDCouplingFieldDouble ( const MEDCoupling::MEDCouplingFieldDouble* field );
251
252     void setFieldByDataArrayDouble ( const MEDCoupling::DataArrayDouble* array );
253
254     Vector getNormEuclidean( void ) const ;
255
256     double max( int component=0 ) const ;
257
258     double min( int component=0 ) const ;
259
260     void setTime ( double time, int iter );
261
262     std::vector< double > getFieldValues(int compo=0) const ;
263
264     Vector getValuesOnComponent(int compo) const ;
265
266     Vector getValuesOnAllComponents(int elem) const ;
267
268     int getSpaceDimension( void ) const;
269
270     double getTime ( void ) const;
271
272     void setName ( const std::string fieldName ) ;
273
274     void setInfoOnComponent(int icomp, std::string nameCompo) ;
275
276     std::string getInfoOnComponent(int icomp) const;
277
278     /**
279      * Computes all the components of the sum of values of the field multiplied by dual cell measures. In case of a field on cells, the dual mesh coincides with the underlying mesh
280      * The field may be multicomponent so the result of the integral should be a vector
281      * return the vector of numerical value of the integral of the field
282      */
283     Vector integral() const;
284
285     /**
286      * Computes the sum of values of a given component of the field multiplied by dual cell measures. In case of a field on cells, the dual mesh coincides with the underlying mesh
287      * @param the index of the component of interest
288      * return the numerical value of the integral of the field
289      */
290     double integral(int compId) const;
291
292     /**
293      * Computes for each component the sum of the absolute values of the field components multiplied by dual cell measures. In case of a field on cells, the dual mesh coincides with the underlying mesh.
294      * The field may be multicomponent so the result of the integral should be a vector
295      * return the vector of numerical value of the L1 norm of each component of the field
296      */
297     Vector normL1() const;
298
299     /**
300      * Computes all the components of the sum of squares of the values of the field components multiplied by dual cell measures. In case of a field on cells, the dual mesh coincides with the underlying mesh
301      * The field may be multicomponent so the result of the integral should be a vector
302      * return the vector of numerical value of the L2 norm of each component of the field
303      */
304     Vector normL2() const;
305
306     /**
307      * Computes the maximum of each component of the field
308      * The field may be multicomponent so the result of the function is a vector
309      * return the vector of numerical value of the Linfinity norm of each component of the field
310      */
311     Vector normMax() const;
312
313     /**
314      * Computes the maximum of each component of the field as well as the index where the maximum was found
315      * The field may be multicomponent so the result of the function is a vector of values and a vector of indices
316      * return the vector of numerical value of the Linfinity norm of each component of the field AND the corresponding vector of indices
317      */
318     Vector componentMax(Vector & Indices) const;
319
320     const Field& operator= ( const Field& f ) ;
321
322     Field operator+ ( const Field& f ) const ;
323
324     Field operator- ( const Field& f ) const ;
325
326     const Field& operator+= ( const Field& f ) ;
327
328     const Field& operator-= ( const Field& f ) ;
329
330     const Field& operator*= ( double s ) ;
331
332     const Field& operator/= ( double s ) ;
333
334     const Field& operator-= ( double s ) ;
335
336     const Field& operator+= ( double s ) ;
337
338     void writeVTK ( const std::string fileName, bool fromScratch=true ) const ;
339
340     void writeMED ( const std::string fileName, bool fromScratch=true ) const ;
341
342     void writeCSV ( const std::string fileName ) const ;
343
344     friend Field operator* (double value , const Field& field ) ;
345
346     friend Field operator* (const Field& field, double value ) ;
347
348     friend Field operator/ (const Field& field, double value) ;
349
350     friend std::ostream& operator<<(std::ostream& out, const Field& field ) ;
351
352     protected: //----------------------------------------------------------------
353
354     MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> _field;
355     Mesh _mesh ;
356     EntityType _typeField;
357         int _numberOfComponents;
358         double _time;
359         std::string _fieldName;
360         
361     private:
362
363 };
364
365 #endif /* Field_HXX_ */