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 void getValues ( Vector myVector ) const ;
230 void setValues ( Vector values ) ;
232 void setValues ( double * values, int nbValues ) ;
234 const std::string getName ( void ) const;
236 const Mesh& getMesh ( void ) const ;
238 int getNumberOfElements ( void ) const ;
240 EntityType getTypeOfField ( void ) const ;
243 * return the MEDCouplingField pointer
246 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> getField ( void ) const ;
248 void setFieldByMEDCouplingFieldDouble ( const MEDCoupling::MEDCouplingFieldDouble* field );
250 void setFieldByDataArrayDouble ( const MEDCoupling::DataArrayDouble* array );
252 Vector getNormEuclidean( void ) const ;
254 double max( int component=0 ) const ;
256 double min( int component=0 ) const ;
258 void setTime ( double time, int iter );
260 Vector getValuesOnComponent(int compo) const ;
262 Vector getValuesOnAllComponents(int elem) const ;
264 int getSpaceDimension( void ) const;
266 double getTime ( void ) const;
268 void setName ( const std::string fieldName ) ;
270 void setInfoOnComponent(int icomp, std::string nameCompo) ;
272 std::string getInfoOnComponent(int icomp) const;
275 * 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
276 * The field may be multicomponent so the result of the integral should be a vector
277 * return the vector of numerical value of the integral of the field
279 Vector integral() const;
282 * 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
283 * @param the index of the component of interest
284 * return the numerical value of the integral of the field
286 double integral(int compId) const;
289 * 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.
290 * The field may be multicomponent so the result of the integral should be a vector
291 * return the vector of numerical value of the L1 norm of each component of the field
293 Vector normL1() const;
296 * 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
297 * The field may be multicomponent so the result of the integral should be a vector
298 * return the vector of numerical value of the L2 norm of each component of the field
300 Vector normL2() const;
303 * Computes the maximum of each component of the field
304 * The field may be multicomponent so the result of the function is a vector
305 * return the vector of numerical value of the Linfinity norm of each component of the field
307 Vector normMax() const;
310 * Computes the maximum of each component of the field as well as the index where the maximum was found
311 * The field may be multicomponent so the result of the function is a vector of values and a vector of indices
312 * return the vector of numerical value of the Linfinity norm of each component of the field AND the corresponding vector of indices
314 Vector componentMax(Vector & Indices) const;
316 const Field& operator= ( const Field& f ) ;
318 Field operator+ ( const Field& f ) const ;
320 Field operator- ( const Field& f ) const ;
322 const Field& operator+= ( const Field& f ) ;
324 const Field& operator-= ( const Field& f ) ;
326 const Field& operator*= ( double s ) ;
328 const Field& operator/= ( double s ) ;
330 const Field& operator-= ( double s ) ;
332 const Field& operator+= ( double s ) ;
334 void writeVTK ( const std::string fileName, bool fromScratch=true ) const ;
336 void writeMED ( const std::string fileName, bool fromScratch=true ) const ;
338 void writeCSV ( const std::string fileName ) const ;
340 friend Field operator* (double value , const Field& field ) ;
342 friend Field operator* (const Field& field, double value ) ;
344 friend Field operator/ (const Field& field, double value) ;
346 friend std::ostream& operator<<(std::ostream& out, const Field& field ) ;
348 protected: //----------------------------------------------------------------
350 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> _field;
352 EntityType _typeField;
353 int _numberOfComponents;
355 std::string _fieldName;
361 #endif /* Field_HXX_ */