Salome HOME
update due to bugs PAL8113 and another I do not remember the number ;) .
[modules/med.git] / src / MEDMEM / MEDMEM_Coordinate.cxx
1 #include "MEDMEM_Coordinate.hxx"
2 #include "MEDMEM_Exception.hxx"
3 #include "MEDMEM_STRING.hxx"
4
5 #include "utilities.h"
6
7 using namespace std;
8 using namespace MEDMEM;
9 using namespace MED_EN;
10
11 /*! Default Constructor : should not be used */
12 //----------------------------------------------------------//
13 COORDINATE::COORDINATE():_coordinateSystem(""),
14                          _coordinate(MEDARRAY<double>()),
15                          _coordinateName(),
16                          _coordinateUnit(),
17                          _nodeNumber()
18 //----------------------------------------------------------//
19 {
20     BEGIN_OF("Default Constructor COORDINATE");
21 }
22
23 /*! This constructor allocate a MEDARRAY of SpaceDimension * NumberOfNodes.\n
24     It will create empty array for optional data (nodeNumber..) */
25 //------------------------------------------------------------------------------//
26 COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode):
27   _coordinateSystem(""),
28   _coordinate(SpaceDimension,NumberOfNodes,Mode),
29   _coordinateName(SpaceDimension),
30   _coordinateUnit(SpaceDimension),
31   _nodeNumber()
32
33 //------------------------------------------------------------------------------//
34 {
35     BEGIN_OF("Constructor COORDINATE");
36 }
37
38 /*! This constructor is specialy designed for use in class GRID.\n
39  *  The purpose is to create a COORDINATE without allocating memory for nodes (in the MEDARRAY).
40  *  The allocation (call to setCoordinates) is performed afterward by GRID, if necessary.
41  *  We set _coordinateName & _coordinateUnit in the constructor, because calls to setCoordinateName
42  *  and setCoordinateUnit are not possible before allocation of MEDARRAY.
43  */
44 //------------------------------------------------------------------------------//
45 COORDINATE::COORDINATE(int SpaceDimension,const string * CoordinateName, const string * CoordinateUnit): 
46    _coordinateSystem(""), _coordinate(MEDARRAY<double>()), _coordinateName(SpaceDimension), 
47    _coordinateUnit(SpaceDimension), _nodeNumber()
48 {
49     for (int i=0; i<SpaceDimension; ++i)
50     {
51         _coordinateName[i]=CoordinateName[i];
52         _coordinateUnit[i]=CoordinateUnit[i];
53     }
54 }
55
56
57 /*! This constructor will COPY all data (it is a deep copy) included in m.\n  
58     But only the default storage mode of coordinates array
59     will be copied (not both storage representation modes even if they both
60     exist in original object) :  for example only full_interlace mode  */
61 //------------------------------------------------------------------------------//
62 COORDINATE::COORDINATE(const COORDINATE & m):
63   _coordinateSystem(m._coordinateSystem),
64   _coordinate(m._coordinate,false)
65 //------------------------------------------------------------------------------//
66 {
67   BEGIN_OF("Copy Constructor COORDINATE");
68
69   int spaceDimension = _coordinate.getLeadingValue();
70   int numberOfNodes = _coordinate.getLengthValue();
71
72   SCRUTE(spaceDimension);
73   setCoordinatesNames((const string*)m._coordinateName) ;
74   setCoordinatesUnits((const string*)m._coordinateUnit) ;
75
76   if ( (const int * const) m._nodeNumber != NULL)
77     _nodeNumber.set(numberOfNodes,(const int*)m._nodeNumber);
78   // PG : it's default no ?
79 //    else
80 //      {
81 //        _nodeNumber.set(0);
82 //      }
83 }
84
85
86 /* does nothing :   all attributs are object (not pointers) */
87 //----------------------//
88 COORDINATE::~COORDINATE()
89 //----------------------//
90 {
91   MESSAGE("~COORDINATE()");
92 }
93
94 /*! sets the attribute _coordinate with Coordinate           */
95 //----------------------------------------------------------//
96 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate,bool shallowCopy) 
97 //----------------------------------------------------------//
98
99
100   const medModeSwitch mode = Coordinate->getMode(); 
101   //  const int  spaceDimension = (int) Coordinate->getLeadingValue();
102   //  const int  numberOfNodes  = (int) Coordinate->getLengthValue();
103   if ( Coordinate->get(mode) != NULL)
104   {
105     if(shallowCopy)
106       {
107         _coordinate.shallowCopy(*Coordinate);
108       }
109     else
110       {
111         MEDARRAY<double> pourAttribut(*Coordinate,false);
112         _coordinate = pourAttribut;
113         //_coordinate.set(mode,Coordinate->get(mode));
114       }
115   }
116   else
117   {
118         throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double> *Coordinate)") << "No Coordinate"));
119   }
120 }
121
122 /*!
123   Sets the value in attribute _coordinate with Coordinate.
124   _coordinate must be allocated (with 
125   COORDINATE::COORDINATE(int,int,medModeSwitch).
126 */
127 //----------------------------------------------------------//
128 void COORDINATE::setCoordinates(const medModeSwitch Mode, 
129                                 const double *Coordinate) 
130 //----------------------------------------------------------//
131
132 //    if (_coordinate == NULL)
133 //      throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
134
135   _coordinate.set(Mode,Coordinate);
136 }
137
138 /*! sets the attribute _coordinateName with CoordinateName   */
139 //----------------------------------------------------------//
140 void COORDINATE::setCoordinatesNames(const string * CoordinateName) 
141 //----------------------------------------------------------//
142 {
143   int SpaceDimension = getSpaceDimension() ;
144   _coordinateName.set(SpaceDimension) ;
145   for (int i=0; i<SpaceDimension; i++)
146     _coordinateName[i]=CoordinateName[i];
147 }
148
149 /*!
150   sets the (i+1)^th component of the attribute _coordinateName with
151   CoordinateName
152 */
153 //----------------------------------------------------------//
154 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
155 //----------------------------------------------------------//
156 {
157   _coordinateName[i]=CoordinateName;
158 }
159
160 /*! sets the attribute _coordinateUnit with CoordinateUnit   */
161 //----------------------------------------------------------//
162 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit) 
163 //----------------------------------------------------------//
164
165   int SpaceDimension = getSpaceDimension() ;
166   _coordinateUnit.set(SpaceDimension) ; 
167   for (int i=0; i<SpaceDimension; i++)
168     _coordinateUnit[i]=CoordinateUnit[i];
169 }
170
171 /*!
172   sets the (i+1)^th component of the attribute _coordinateUnit with
173   CoordinateUnit
174 */
175 //----------------------------------------------------------//
176 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i) 
177 //----------------------------------------------------------//
178
179   _coordinateUnit[i]=CoordinateUnit;
180 }
181
182 /*! sets the attribute _coordinateSystem with CoordinateSystem   */
183 //----------------------------------------------------------//
184 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem) 
185 //----------------------------------------------------------//
186
187         _coordinateSystem=CoordinateSystem; 
188 }
189
190 /*! sets the attribute _nodeNumber with NodeNumber */
191 //------------------------------------------------//
192 void COORDINATE::setNodesNumbers(const int * NodeNumber) 
193 //------------------------------------------------//
194 {       
195   int NumberOfNodes = getNumberOfNodes() ;
196   _nodeNumber.set(NumberOfNodes,NodeNumber) ; 
197 }
198
199 int COORDINATE::getSpaceDimension() const
200 {       
201   return _coordinate.getLeadingValue() ; 
202 }
203
204 int COORDINATE::getNumberOfNodes() const
205 {       
206   return _coordinate.getLengthValue() ; 
207 }
208
209
210 /*! returns a pointer to the optional array storing 
211     eventual nodes numbers */
212 //-------------------------------------------------//
213 const int * COORDINATE::getNodesNumbers() const
214 //-------------------------------------------------//
215 {
216         return  (const int *)_nodeNumber;
217 }
218
219 /*! returns a Pointer to Coordinates Array in specified mode representation */
220 //--------------------------------------------------------------------------//
221 const double *  COORDINATE::getCoordinates (medModeSwitch Mode)
222 //--------------------------------------------------------------------------//
223 {
224         return _coordinate.get(Mode) ;
225 }
226
227 /* returns the coordinate of node Number on axis Axis */
228 //----------------------------------------------------//
229 double COORDINATE::getCoordinate(int Number,int Axis) 
230 //----------------------------------------------------//
231 {       
232         return _coordinate.getIJ(Number,Axis) ;
233 }
234
235 /* returns all nodes coordinates from  axis Axis      */
236 //----------------------------------------------------//
237 const double *  COORDINATE::getCoordinateAxis(int Axis)
238 //----------------------------------------------------//
239 {                       //< return all nodes coordinates from axis Axis
240          return _coordinate.getColumn(Axis) ;
241 }
242
243 /*! returns an array with names of coordinates. \n
244       Example : \n
245       - x,y,z \n
246       - r,teta,phi \n
247       - ... */
248 //--------------------------------------//
249 const string * COORDINATE::getCoordinatesNames() const
250 {
251         return _coordinateName ;
252 }
253
254 /* returns the name of axis Axis             */
255 //-------------------------------------------//
256 string COORDINATE::getCoordinateName(int Axis) const
257 //-------------------------------------------//
258 {
259         return _coordinateName[Axis-1];
260 }
261
262 /*!  returns an array with units of coordinates (cm, m, mm, ...)
263      It could be empty. We suppose we are IS (meter).  */
264 //-----------------------------------------------------//
265 const string * COORDINATE::getCoordinatesUnits() const
266 //-----------------------------------------------------//
267 {
268         return _coordinateUnit ;
269 }
270
271 /*! returns the unit of axis Axis           */
272 //------------------------------------------//
273 string COORDINATE::getCoordinateUnit(int Axis) const
274 //------------------------------------------//
275 {
276         return _coordinateUnit[Axis-1] ;
277 }
278 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
279 //---------------------------------------------------//
280 string COORDINATE::getCoordinatesSystem() const
281 //---------------------------------------------------//
282 {
283   return _coordinateSystem ;
284 }