4 * Created on: 07 fevrier. 2012
5 * Authors: CDMAT groups
13 class MEDCouplingFieldDouble;
14 class DataArrayDouble;
15 class MEDFileField1TS;
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);
78 * constructor with data
79 * \brief defines a constant field on a mesh stored in a med file
81 * \param [in] string : the mesh file name
82 * \param fieldType: field type
83 * \param [in] vector<double> : the value in each cell
84 * \param [in] fieldName: field name
85 * \param [in] meshLevel : relative mesh dimension : 0->cells, 1->Faces etc
87 Field(const std::string meshfileName, EntityType fieldType,
88 const std::vector<double> Vconstant,const std::string & fieldName = "",
89 int meshLevel=0, double time=0.0, std::string meshName="");
92 * constructor with data
93 * \brief defines a constant field
96 * \param [in] fieldType: field type
98 * \param [in] fieldName: field name
100 Field(const Mesh& M, EntityType fieldType, const Vector Vconstant,
101 const std::string & fieldName = "", double time=0.0);
104 * constructor with data
105 * \brief defines a constant field
108 * \param [in] fieldType: field type
109 * \param [in] vector<double>
110 * \param [in] fieldName: field name
112 Field(const Mesh& M, EntityType fieldType, const std::vector<double> Vconstant, const std::string & fieldName = "", double time=0.0);
115 * constructor with data
116 * \brief Builds a rectangular mesh M and defines a constant field on M
118 * \param [in] int the space dimension
119 * \param [in] vector<double> the value in each cell
120 * \param [in] fieldType: field type
121 * \param [in] fieldName: field name
122 * \param [in] double the lowest value in the x direction
123 * \param [in] double the highest value in the x direction
124 * \param [in] string name of the left boundary
125 * \param [in] string name of the right boundary
126 * \param [in] double the lowest value in the y direction
127 * \param [in] double the highest value in the y direction
128 * \param [in] string name of the back boundary
129 * \param [in] string name of the front boundary
130 * \param [in] double the lowest value in the z direction
131 * \param [in] double the highest value in the z direction
132 * \param [in] string name of the bottom boundary
133 * \param [in] string name of the top boundary
135 Field( int nDim, const std::vector<double> Vconstant, EntityType type,
136 double xmin, double xmax,int nx, std::string leftSide, std::string rightSide,
137 double ymin=0, double ymax=0, int ny=0, std::string backSide="", std::string frontSide="",
138 double zmin=0, double zmax=0, int nz=0, std::string bottomSide="", std::string topSide="",
139 const std::string & fieldName="", double time=0.0,double epsilon=1e-6);
142 * constructor with data
143 * \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
148 * \param [in] double position of the discontinuity on one of the three axis
149 * \param [in] int direction (axis carrying the discontinuity) : 0 for x, 1 for y, 2 for z
150 * \param [in] fieldType: field type
151 * \param [in] fieldName: field name
153 Field(const Mesh M, const Vector VV_left, const Vector VV_right, double disc_pos,
154 EntityType type, int direction=0, const std::string & fieldName="", double time=0.0);
157 * constructor with data
158 * \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
159 * \param [in] int the space dimension
160 * \param [in] vector<double> the value left of the discontinuity
161 * \param [in] vector<double> the value right of the discontinuity
162 * \param [in] double the position of the discontinuity in the x direction
163 * \param [in] fieldType: field type
164 * \param [in] fieldName: field name
165 * \param [in] double the lowest value in the x direction
166 * \param [in] double the highest value in the x direction
167 * \param [in] string name of the left boundary
168 * \param [in] string name of the right boundary
169 * \param [in] double the lowest value in the y direction
170 * \param [in] double the highest value in the y direction
171 * \param [in] string name of the back boundary
172 * \param [in] string name of the front boundary
173 * \param [in] double the lowest value in the z direction
174 * \param [in] double the highest value in the z direction
175 * \param [in] string name of the bottom boundary
176 * \param [in] string name of the top boundary
179 Field( int nDim, const std::vector<double> VV_Left, std::vector<double> VV_Right,
180 double xstep, EntityType type,
181 double xmin, double xmax,int nx, std::string leftSide, std::string rightSide,
182 double ymin=0, double ymax=0, int ny=0, std::string backSide="", std::string frontSide="",
183 double zmin=0, double zmax=0, int nz=0, std::string bottomSide="", std::string topSide="",
184 int direction=0, const std::string & fieldName="", double time=0.0, double epsilon=1e-6);
187 * constructor with data
188 * \brief builds a step function field on mesh M with values Vin inside the ball with radius Radius and Vout outside
191 * \param [in] Vector Vin, value inside the ball
192 * \param [in] Vector Vout, value outside the ball
193 * \param [in] double radius of the ball
194 * \param [in] Vector Center, coordinates of the ball center
195 * \param [in] fieldType: field type
196 * \param [in] fieldName: field name
198 Field(const Mesh M, const Vector Vin, const Vector Vout, double Radius,
199 Vector Center, EntityType type, const std::string & fieldName="", double time=0.0);
201 void readFieldMed( const std::string & fileNameRadical,
203 const std::string & fieldName = "",
207 void buildFieldMemoryStructure();
209 MEDCoupling::DataArrayDouble * getArray();
211 double& operator[] ( int ielem ) ;
213 double operator[] ( int ielem ) const;
215 double& operator() ( int ielem ) ;
217 double operator() ( int ielem ) const;
219 double& operator() ( int ielem, int jcomp ) ;
221 double operator() ( int ielem, int jcomp ) const ;
223 int getNumberOfComponents ( void ) const ;
225 const double* getValues ( void ) const ;
227 void getValues ( Vector myVector ) const ;
229 void setValues ( Vector values ) ;
231 void setValues ( double * values, int nbValues ) ;
233 const std::string getName ( void ) const;
235 const Mesh& getMesh ( void ) const ;
237 int getNumberOfElements ( void ) const ;
239 EntityType getTypeOfField ( void ) const ;
241 // returns the x, y or z component of the element (node cell or face) with number i
242 double getElementComponent(int i, int comp) const;
244 * return the MEDCouplingField pointer
247 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> getField ( void ) const ;
249 void setFieldByMEDCouplingFieldDouble ( const MEDCoupling::MEDCouplingFieldDouble* field );
251 void setFieldByDataArrayDouble ( const MEDCoupling::DataArrayDouble* array );
254 * \brief Delete the medcoupling mesh to save memory space
256 void deleteMEDCouplingMesh();
259 * \brief Returns true iff an unstructured mesh has been loaded
261 bool meshNotDeleted() const {return _mesh.meshNotDeleted();}
263 Vector getNormEuclidean( void ) const ;
265 double max( int component=0 ) const ;
267 double min( int component=0 ) const ;
269 void setTime ( double time, int iter );
271 std::vector< double > getFieldValues(int compo=0) const ;
273 Vector getValuesOnComponent(int compo) const ;
275 Vector getValuesOnAllComponents(int elem) const ;
277 int getSpaceDimension( void ) const;
279 double getTime ( void ) const;
281 void setName ( const std::string fieldName ) ;
283 void setInfoOnComponent(int icomp, std::string nameCompo) ;
285 std::string getInfoOnComponent(int icomp) const;
288 * 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
289 * The field may be multicomponent so the result of the integral should be a vector
290 * return the vector of numerical value of the integral of the field
292 Vector integral() const;
295 * 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
296 * @param the index of the component of interest
297 * return the numerical value of the integral of the field
299 double integral(int compId) const;
302 * 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.
303 * The field may be multicomponent so the result of the integral should be a vector
304 * return the vector of numerical value of the L1 norm of each component of the field
306 Vector normL1() const;
309 * 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
310 * The field may be multicomponent so the result of the integral should be a vector
311 * return the vector of numerical value of the L2 norm of each component of the field
313 Vector normL2() const;
316 * Computes the maximum of each component of the field
317 * The field may be multicomponent so the result of the function is a vector
318 * return the vector of numerical value of the Linfinity norm of each component of the field
320 Vector normMax() const;
323 * Computes the maximum of each component of the field as well as the index where the maximum was found
324 * The field may be multicomponent so the result of the function is a vector of values and a vector of indices
325 * return the vector of numerical value of the Linfinity norm of each component of the field AND the corresponding vector of indices
327 Vector componentMax(Vector & Indices) const;
329 const Field& operator= ( const Field& f ) ;
331 Field operator+ ( const Field& f ) const ;
333 Field operator- ( const Field& f ) const ;
335 const Field& operator+= ( const Field& f ) ;
337 const Field& operator-= ( const Field& f ) ;
339 const Field& operator*= ( double s ) ;
341 const Field& operator/= ( double s ) ;
343 const Field& operator-= ( double s ) ;
345 const Field& operator+= ( double s ) ;
347 void writeVTK ( const std::string fileName, bool fromScratch=true ) const ;
349 void writeMED ( const std::string fileName, bool fromScratch=true ) ;
351 void writeCSV ( const std::string fileName ) const ;
353 friend Field operator* (double value , const Field& field ) ;
355 friend Field operator* (const Field& field, double value ) ;
357 friend Field operator/ (const Field& field, double value) ;
359 friend std::ostream& operator<<(std::ostream& out, const Field& field ) ;
361 protected: //----------------------------------------------------------------
363 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> _field;
365 EntityType _typeField;
366 int _numberOfComponents;
368 std::string _fieldName;
374 #endif /* Field_HXX_ */