Salome HOME
initial project version
[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     const std::string getName ( void ) const;
229
230     const Mesh& getMesh ( void ) const ;
231
232     int getNumberOfElements ( void ) const ;
233
234     EntityType getTypeOfField ( void ) const ;
235
236     /**
237      * return the MEDCouplingField pointer
238      * return _field
239      */
240     MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> getField ( void )  const ;
241
242     void setFieldByMEDCouplingFieldDouble ( const MEDCoupling::MEDCouplingFieldDouble* field );
243
244     void setFieldByDataArrayDouble ( const MEDCoupling::DataArrayDouble* array );
245
246     DoubleTab getNormEuclidean( void ) const ;
247
248     double max( void ) const ;
249
250     double min( void ) const ;
251
252     void setTime ( double time, int iter );
253
254     Vector getValuesOnComponent(int compo) const ;
255
256     Vector getValuesOnAllComponents(int elem) const ;
257
258     int getSpaceDimension( void ) const;
259
260     double getTime ( void ) const;
261
262     void setName ( const std::string fieldName ) ;
263
264     void setInfoOnComponent(int icomp, std::string nameCompo) ;
265
266     std::string getInfoOnComponent(int icomp) const;
267
268     /**
269      * 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
270      * The field may be multicomponent so the result of the integral should be a vector
271      * return the vector of numerical value of the integral of the field
272      */
273     Vector integral() const;
274
275     /**
276      * 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
277      * @param the index of the component of interest
278      * return the numerical value of the integral of the field
279      */
280     double integral(int compId) const;
281
282     /**
283      * 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.
284      * The field may be multicomponent so the result of the integral should be a vector
285      * return the vector of numerical value of the L1 norm of each component of the field
286      */
287     Vector normL1() const;
288
289     /**
290      * 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
291      * The field may be multicomponent so the result of the integral should be a vector
292      * return the vector of numerical value of the L2 norm of each component of the field
293      */
294     Vector normL2() const;
295
296     /**
297      * Computes the maximum of each component of the field
298      * The field may be multicomponent so the result of the function
299      * return the vector of numerical value of the Linfinity norm of each component of the field
300      */
301     Vector normMax() const;
302
303     const Field& operator= ( const Field& f ) ;
304
305     Field operator+ ( const Field& f ) const ;
306
307     Field operator- ( const Field& f ) const ;
308
309     const Field& operator+= ( const Field& f ) ;
310
311     const Field& operator-= ( const Field& f ) ;
312
313     const Field& operator*= ( double s ) ;
314
315     const Field& operator/= ( double s ) ;
316
317     const Field& operator-= ( double s ) ;
318
319     const Field& operator+= ( double s ) ;
320
321     void writeVTK ( const std::string fileName, bool fromScratch=true ) const ;
322
323     void writeMED ( const std::string fileName, bool fromScratch=true ) const ;
324
325     void writeCSV ( const std::string fileName ) const ;
326
327     friend Field operator* (double value , const Field& field ) ;
328
329     friend Field operator* (const Field& field, double value ) ;
330
331     friend Field operator/ (const Field& field, double value) ;
332
333     friend std::ostream& operator<<(std::ostream& out, const Field& field ) ;
334
335     protected: //----------------------------------------------------------------
336
337     MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> _field;
338     Mesh _mesh ;
339     EntityType _typeField;
340         int _numberOfComponents;
341         double _time;
342         std::string _fieldName;
343         
344     private:
345
346 };
347
348 #endif /* Field_HXX_ */