1 #include "MEDMEM_Coordinate.hxx"
2 #include "MEDMEM_Exception.hxx"
3 #include "MEDMEM_STRING.hxx"
8 using namespace MEDMEM;
9 using namespace MED_EN;
11 /*! Default Constructor : should not be used */
12 //----------------------------------------------------------//
13 COORDINATE::COORDINATE():_coordinateSystem(""),
14 _coordinate(MEDARRAY<double>()),
18 //----------------------------------------------------------//
20 BEGIN_OF("Default Constructor COORDINATE");
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),
33 //------------------------------------------------------------------------------//
35 BEGIN_OF("Constructor COORDINATE");
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.
44 //------------------------------------------------------------------------------//
45 COORDINATE::COORDINATE(int SpaceDimension,const string * CoordinateName, const string * CoordinateUnit):
46 _coordinateSystem(""), _coordinate(MEDARRAY<double>()), _coordinateName(SpaceDimension),
47 _coordinateUnit(SpaceDimension), _nodeNumber()
49 for (int i=0; i<SpaceDimension; ++i)
51 _coordinateName[i]=CoordinateName[i];
52 _coordinateUnit[i]=CoordinateUnit[i];
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 //------------------------------------------------------------------------------//
67 BEGIN_OF("Copy Constructor COORDINATE");
69 int spaceDimension = _coordinate.getLeadingValue();
70 int numberOfNodes = _coordinate.getLengthValue();
72 SCRUTE(spaceDimension);
73 setCoordinatesNames((const string*)m._coordinateName) ;
74 setCoordinatesUnits((const string*)m._coordinateUnit) ;
76 if ( (const int * const) m._nodeNumber != NULL)
77 _nodeNumber.set(numberOfNodes,(const int*)m._nodeNumber);
78 // PG : it's default no ?
81 // _nodeNumber.set(0);
86 /* does nothing : all attributs are object (not pointers) */
87 //----------------------//
88 COORDINATE::~COORDINATE()
89 //----------------------//
91 MESSAGE("~COORDINATE()");
94 /*! sets the attribute _coordinate with Coordinate */
95 //----------------------------------------------------------//
96 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate,bool shallowCopy)
97 //----------------------------------------------------------//
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)
107 _coordinate.shallowCopy(*Coordinate);
111 MEDARRAY<double> pourAttribut(*Coordinate,false);
112 _coordinate = pourAttribut;
113 //_coordinate.set(mode,Coordinate->get(mode));
118 throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double> *Coordinate)") << "No Coordinate"));
123 Sets the value in attribute _coordinate with Coordinate.
124 _coordinate must be allocated (with
125 COORDINATE::COORDINATE(int,int,medModeSwitch).
127 //----------------------------------------------------------//
128 void COORDINATE::setCoordinates(const medModeSwitch Mode,
129 const double *Coordinate)
130 //----------------------------------------------------------//
132 // if (_coordinate == NULL)
133 // throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
135 _coordinate.set(Mode,Coordinate);
138 /*! sets the attribute _coordinateName with CoordinateName */
139 //----------------------------------------------------------//
140 void COORDINATE::setCoordinatesNames(const string * CoordinateName)
141 //----------------------------------------------------------//
143 int SpaceDimension = getSpaceDimension() ;
144 _coordinateName.set(SpaceDimension) ;
145 for (int i=0; i<SpaceDimension; i++)
146 _coordinateName[i]=CoordinateName[i];
150 sets the (i+1)^th component of the attribute _coordinateName with
153 //----------------------------------------------------------//
154 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
155 //----------------------------------------------------------//
157 _coordinateName[i]=CoordinateName;
160 /*! sets the attribute _coordinateUnit with CoordinateUnit */
161 //----------------------------------------------------------//
162 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit)
163 //----------------------------------------------------------//
165 int SpaceDimension = getSpaceDimension() ;
166 _coordinateUnit.set(SpaceDimension) ;
167 for (int i=0; i<SpaceDimension; i++)
168 _coordinateUnit[i]=CoordinateUnit[i];
172 sets the (i+1)^th component of the attribute _coordinateUnit with
175 //----------------------------------------------------------//
176 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i)
177 //----------------------------------------------------------//
179 _coordinateUnit[i]=CoordinateUnit;
182 /*! sets the attribute _coordinateSystem with CoordinateSystem */
183 //----------------------------------------------------------//
184 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem)
185 //----------------------------------------------------------//
187 _coordinateSystem=CoordinateSystem;
190 /*! sets the attribute _nodeNumber with NodeNumber */
191 //------------------------------------------------//
192 void COORDINATE::setNodesNumbers(const int * NodeNumber)
193 //------------------------------------------------//
195 int NumberOfNodes = getNumberOfNodes() ;
196 _nodeNumber.set(NumberOfNodes,NodeNumber) ;
199 int COORDINATE::getSpaceDimension() const
201 return _coordinate.getLeadingValue() ;
204 int COORDINATE::getNumberOfNodes() const
206 return _coordinate.getLengthValue() ;
210 /*! returns a pointer to the optional array storing
211 eventual nodes numbers */
212 //-------------------------------------------------//
213 const int * COORDINATE::getNodesNumbers() const
214 //-------------------------------------------------//
216 return (const int *)_nodeNumber;
219 /*! returns a Pointer to Coordinates Array in specified mode representation */
220 //--------------------------------------------------------------------------//
221 const double * COORDINATE::getCoordinates (medModeSwitch Mode)
222 //--------------------------------------------------------------------------//
224 return _coordinate.get(Mode) ;
227 /* returns the coordinate of node Number on axis Axis */
228 //----------------------------------------------------//
229 double COORDINATE::getCoordinate(int Number,int Axis)
230 //----------------------------------------------------//
232 return _coordinate.getIJ(Number,Axis) ;
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) ;
243 /*! returns an array with names of coordinates. \n
248 //--------------------------------------//
249 const string * COORDINATE::getCoordinatesNames() const
251 return _coordinateName ;
254 /* returns the name of axis Axis */
255 //-------------------------------------------//
256 string COORDINATE::getCoordinateName(int Axis) const
257 //-------------------------------------------//
259 return _coordinateName[Axis-1];
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 //-----------------------------------------------------//
268 return _coordinateUnit ;
271 /*! returns the unit of axis Axis */
272 //------------------------------------------//
273 string COORDINATE::getCoordinateUnit(int Axis) const
274 //------------------------------------------//
276 return _coordinateUnit[Axis-1] ;
278 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
279 //---------------------------------------------------//
280 string COORDINATE::getCoordinatesSystem() const
281 //---------------------------------------------------//
283 return _coordinateSystem ;