4 * Created on: 07 fevrier. 2012
5 * Authors: CDMAT groups
13 class MEDCouplingFieldDouble;
14 class DataArrayDouble;
17 #include "DoubleTab.hxx"
24 * Field class is defined by
30 public: //----------------------------------------------------------------
34 Field ( EntityType typeField = CELLS ) ;
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
44 Field(const std::string fieldName, EntityType type, const Mesh& mesh, int numberOfComponents=1, double time=0.0) ;
53 * @param field : The Field object to be copied
55 Field ( const Field & field ) ;
58 * deep copy of a field (values are copied)
59 * @param field : The Field object to be copied
61 Field deepCopy( ) const;
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)
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);
79 * constructor with data
80 * \brief defines a constant field on a mesh stored in a med file
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
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);
93 * constructor with data
94 * \brief defines a constant field
97 * \param [in] fieldType: field type
99 * \param [in] fieldName: field name
101 Field(const Mesh& M, EntityType fieldType, const Vector Vconstant,
102 const std::string & fieldName = "", double time=0.0);
105 * constructor with data
106 * \brief defines a constant field
109 * \param [in] fieldType: field type
110 * \param [in] vector<double>
111 * \param [in] fieldName: field name
113 Field(const Mesh& M, EntityType fieldType, const std::vector<double> Vconstant, const std::string & fieldName = "", double time=0.0);
116 * constructor with data
117 * \brief Builds a rectangular mesh M and defines a constant field on M
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
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);
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
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
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);
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
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);
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
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
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);
202 void readFieldMed( const std::string & fileNameRadical,
204 const std::string & fieldName = "",
208 void buildFieldMemoryStructure();
210 MEDCoupling::DataArrayDouble * getArray();
212 double& operator[] ( int ielem ) ;
214 double operator[] ( int ielem ) const;
216 double& operator() ( int ielem ) ;
218 double operator() ( int ielem ) const;
220 double& operator() ( int ielem, int jcomp ) ;
222 double operator() ( int ielem, int jcomp ) const ;
224 int getNumberOfComponents ( void ) const ;
226 const double* getValues ( void ) const ;
228 const std::string getName ( void ) const;
230 const Mesh& getMesh ( void ) const ;
232 int getNumberOfElements ( void ) const ;
234 EntityType getTypeOfField ( void ) const ;
237 * return the MEDCouplingField pointer
240 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> getField ( void ) const ;
242 void setFieldByMEDCouplingFieldDouble ( const MEDCoupling::MEDCouplingFieldDouble* field );
244 void setFieldByDataArrayDouble ( const MEDCoupling::DataArrayDouble* array );
246 DoubleTab getNormEuclidean( void ) const ;
248 double max( int component=0 ) const ;
250 double min( int component=0 ) const ;
252 void setTime ( double time, int iter );
254 Vector getValuesOnComponent(int compo) const ;
256 Vector getValuesOnAllComponents(int elem) const ;
258 int getSpaceDimension( void ) const;
260 double getTime ( void ) const;
262 void setName ( const std::string fieldName ) ;
264 void setInfoOnComponent(int icomp, std::string nameCompo) ;
266 std::string getInfoOnComponent(int icomp) const;
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
273 Vector integral() const;
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
280 double integral(int compId) const;
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
287 Vector normL1() const;
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
294 Vector normL2() const;
297 * Computes the maximum of each component of the field
298 * The field may be multicomponent so the result of the function is a vector
299 * return the vector of numerical value of the Linfinity norm of each component of the field
301 Vector normMax() const;
304 * Computes the maximum of each component of the field as well as the index where the maximum was found
305 * The field may be multicomponent so the result of the function is a vector of values and a vector of indices
306 * return the vector of numerical value of the Linfinity norm of each component of the field AND the corresponding vector of indices
308 Vector componentMax(Vector & Indices) const;
310 const Field& operator= ( const Field& f ) ;
312 Field operator+ ( const Field& f ) const ;
314 Field operator- ( const Field& f ) const ;
316 const Field& operator+= ( const Field& f ) ;
318 const Field& operator-= ( const Field& f ) ;
320 const Field& operator*= ( double s ) ;
322 const Field& operator/= ( double s ) ;
324 const Field& operator-= ( double s ) ;
326 const Field& operator+= ( double s ) ;
328 void writeVTK ( const std::string fileName, bool fromScratch=true ) const ;
330 void writeMED ( const std::string fileName, bool fromScratch=true ) const ;
332 void writeCSV ( const std::string fileName ) const ;
334 friend Field operator* (double value , const Field& field ) ;
336 friend Field operator* (const Field& field, double value ) ;
338 friend Field operator/ (const Field& field, double value) ;
340 friend std::ostream& operator<<(std::ostream& out, const Field& field ) ;
342 protected: //----------------------------------------------------------------
344 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> _field;
346 EntityType _typeField;
347 int _numberOfComponents;
349 std::string _fieldName;
355 #endif /* Field_HXX_ */