From: nri Date: Thu, 10 Jul 2003 15:44:02 +0000 (+0000) Subject: NRI : Merge from V1_2. X-Git-Tag: V1_2_1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=954b8e70a978c9084d1f05ddd7fbc51081d3b849;p=modules%2Fmed.git NRI : Merge from V1_2. --- diff --git a/src/MEDMEM/MEDMEM_CellModel.hxx b/src/MEDMEM/MEDMEM_CellModel.hxx index 5dd41ff9a..d09bd4fad 100644 --- a/src/MEDMEM/MEDMEM_CellModel.hxx +++ b/src/MEDMEM/MEDMEM_CellModel.hxx @@ -1,3 +1,29 @@ +// MED MEDMEM : MED files in memory +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MEDMEM_CellModel.hxx +// Module : MED + /* File MEDMEM_CellModel.hxx $Header$ @@ -6,110 +32,133 @@ #ifndef CELLMODEL_HXX #define CELLMODEL_HXX -//#include #include #include #include +#include "utilities.h" #include "MEDMEM_define.hxx" using namespace std ; - using namespace MED_EN; -class CELLMODEL { +/*! + This class is an internal class and should not be used by the end-user. + This class describes all possible cell models and is used in order + to acces informations about geometric type of the cell : + Each object (if instancied), contains generic informations about + the cell model it describes as cell dimensions, number of nodes... +*/ + +class CELLMODEL +{ private: - // use in constructor and operator= - void init(const CELLMODEL &m) ; - // use in operator= and destructor - void clean() ; - -protected: - - string _name ; - medGeometryElement _type ; - int _dimension ; // Cell _dimension (!= space _dimension) - int _numberOfNodes ; - int _numberOfVertexes ; - int _numberOfConstituentsDimension ; // 2 in 3D, 1 in 2D - // Array of size _numberOfConstituentsDimension - int* _numberOfConstituents ; - // Array of size _numberOfConstituentsDimensionx_numberOfConstituents[i] - int** _numberOfNodeOfEachConstituent ; - // Define nodal local connectivity for each constituent for each dimension - int*** _constituents ; - // define local connectivity for each constituents - // composing it ( - // first vector : for each cell _dimension - // (first : dim-1, second if any : dim-2) - // second vector : for each constituents of this _dimension, - // third vector : list of local nodes - medGeometryElement** _constituentsType ; + /*! private method : /n + used by constructor and operator= */ + void init(const CELLMODEL &m); + + /*! private method : /n */ + void clean(); + + + //protected: + /*! explicit name (as MED_POINT1) */ + string _name; + /*! type of cell (cf define.h) */ + medGeometryElement _type; + /*! Cell dimension (not space dimension) */ + int _dimension; + /*! number of nodes forming this type of a cell */ + int _numberOfNodes; + /*! number of vertexes forming this type of a cell */ + int _numberOfVertexes; + /*! 2 for a 3D Cell and 1 for a 2DCell */ + int _numberOfConstituentsDimension; + /*! Array of size numberOfConstituentsDimension */ + int* _numberOfConstituents ; + /*! Array of size _numberOfConstituentsDimension + x_numberOfConstituents[i] */ + int** _numberOfNodeOfEachConstituent ; + /*! defines nodal local connectivity for each + constituents of each dimension: + should be seen as a vector> \n + - first vector : for each cell dimension + (first : dim-1, second if any : dim-2)\n + - second vector : for each constituent of + this dimension\n + - third vector : list of local nodes */ + int*** _constituents ; + medGeometryElement** _constituentsType ; public : - CELLMODEL(): - _type(MED_NONE), - _dimension(0), - _numberOfNodes(0), - _numberOfVertexes(0), - _numberOfConstituentsDimension(0), - _numberOfConstituents((int*)NULL), - _numberOfNodeOfEachConstituent((int**)NULL), - _constituents((int***)NULL), - _constituentsType((medGeometryElement**)NULL) - { - } - CELLMODEL(medGeometryElement t) ; - CELLMODEL(const CELLMODEL &m){ - init(m) ; - } - ~CELLMODEL() { - clean() ; - }; + /*! Constructor. */ + inline CELLMODEL(); + /*! Constructor. */ + CELLMODEL(medGeometryElement t); + /*! Copy constructor. */ + inline CELLMODEL(const CELLMODEL &m); + /*! Destructor. */ + inline ~CELLMODEL(); - CELLMODEL & operator=(const CELLMODEL &m) { - clean() ; - init(m) ; - return *this ; - } + /*! Operator = : duplicate CELLMODEL. */ + inline CELLMODEL & operator=(const CELLMODEL &m); + + /*! Operator << : print CELLMODEL to the given stream. */ friend ostream & operator<<(ostream &os,const CELLMODEL &my); - inline string getName() const ; + /*! returns _name attribute (ie: MED_PENTA15).\n + see med.h (in med/include) */ + inline string getName() const; + + /*! returns number of vertexes forming this type of cell */ inline int getNumberOfVertexes() const; - inline int getNumberOfNodes() const; - inline int getDimension() const; - inline medGeometryElement getType() const; - // Return all constituents which dimension is _dimension-dim. - // vector< vector > getConstituents(int dim) const; - int** getConstituents(int dim) const; + /*! returns number of nodes forming this type of cell */ + inline int getNumberOfNodes() const; - // Return number of constituents which dimension is _dimension-dim. - int getNumberOfConstituents(int dim) const; + /*! returns the dimension of this type of cell./n + it can be different from mesh dimension */ + inline int getDimension() const; - // Return local nodes numbers vector for num-th constituent which dimension is _dimension-dim. - int* getNodesConstituent(int dim,int num) const; + /*! returns the geometric type of the cell. \n + see med.h (in med/include) */ + inline medGeometryElement getType() const; - // Return local node number of nodes_index-th node for num-th constituent which dimension is _dimension-dim. - int getNodeConstituent(int dim,int num,int nodes_index); + /*! returns all constituents which dimension is _dimension-dim.*/ + int** getConstituents(int dim) const; - // Return types of each constituents which dimension is _dimension-dim. - medGeometryElement* getConstituentsType(int dim) const; + /*! returns number of constituents which dimension is _dimension-dim.*/ + int getNumberOfConstituents(int dim) const; - // Return type of num-th constituent which dimension is _dimension-dim. - medGeometryElement getConstituentType(int dim,int num) const; + /*! returns local nodes numbers vector for num-th constituent + which dimension is _dimension-dim.*/ + int* getNodesConstituent(int dim,int num) const; + + /*! returns local node number of nodes_index-th node for + num-th constituent which dimension is _dimension-dim.*/ + int getNodeConstituent(int dim,int num,int nodes_index) const; + /*! returns types of each constituents which dimension + is _dimension-dim.*/ + medGeometryElement* getConstituentsType(int dim) const; - // Return number of constituents type (which dimension is _dimension-1). + /*! returns type of num-th constituent which dimension + is _dimension-dim.*/ + medGeometryElement getConstituentType(int dim,int num) const; + + /*! returns number of constituents type + (which dimension is _dimension-1).*/ int getNumberOfConstituentsType() const; - // Return all types of constituents which dimension is (_dimension-1). - set getAllConstituentsType() const; + /*! returns all types of constituents which dimension + is (_dimension-1).*/ + set getAllConstituentsType() const; - // Return number of constituents foreach type (which dimension is _dimension-1). - map getNumberOfConstituentsForeachType() const; + /*! returns number of constituents foreach type (which dimension + is _dimension-1).*/ + map getNumberOfConstituentsForeachType() const; }; @@ -118,6 +167,33 @@ public : // Methodes Inline // ------------------------------------------ +inline CELLMODEL::CELLMODEL(): + _type(MED_NONE), + _dimension(0), + _numberOfNodes(0), + _numberOfVertexes(0), + _numberOfConstituentsDimension(0), + _numberOfConstituents((int*)NULL), + _numberOfNodeOfEachConstituent((int**)NULL), + _constituents((int***)NULL), + _constituentsType((medGeometryElement**)NULL) +{ +} +inline CELLMODEL::CELLMODEL(const CELLMODEL &m) +{ + init(m) ; +} +inline CELLMODEL::~CELLMODEL() +{ + MESSAGE("CELLMODEL::~CELLMODEL() destroying the cell"); + clean() ; +}; +inline CELLMODEL & CELLMODEL::operator=(const CELLMODEL &m) +{ + clean() ; + init(m) ; + return *this ; +} inline string CELLMODEL::getName() const { return _name ; @@ -138,7 +214,6 @@ inline medGeometryElement CELLMODEL::getType() const { return _type; } -//inline vector< vector > CELLMODEL::getConstituents(int dim) const inline int** CELLMODEL::getConstituents(int dim) const { return _constituents[dim-1] ; @@ -146,18 +221,15 @@ inline int** CELLMODEL::getConstituents(int dim) const inline int CELLMODEL::getNumberOfConstituents(int dim) const { return _numberOfConstituents[dim-1] ; - //return _constituents[dim-1].size() ; } -//inline vector CELLMODEL::getNodesConstituent(int dim,int num) const inline int* CELLMODEL::getNodesConstituent(int dim,int num) const { return _constituents[dim-1][num-1]; } -inline int CELLMODEL::getNodeConstituent(int dim,int num,int nodesNumber) +inline int CELLMODEL::getNodeConstituent(int dim,int num,int nodesNumber) const { return _constituents[dim-1][num-1][nodesNumber-1] ; } -//inline vector CELLMODEL::getConstituentsType(int dim) const inline medGeometryElement* CELLMODEL::getConstituentsType(int dim) const { return _constituentsType[dim-1]; diff --git a/src/MEDMEM/MEDMEM_Coordinate.cxx b/src/MEDMEM/MEDMEM_Coordinate.cxx index 8669f1d3b..686c618bc 100644 --- a/src/MEDMEM/MEDMEM_Coordinate.cxx +++ b/src/MEDMEM/MEDMEM_Coordinate.cxx @@ -1,10 +1,39 @@ +// MED MEDMEM : MED files in memory +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MEDMEM_Coordinate.cxx +// Module : MED + using namespace std; #include "MEDMEM_Coordinate.hxx" +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_STRING.hxx" + #include "utilities.h" -/*! This class contains coordinates of the nodes */ +/*! Default Constructor : should not be used */ //----------------------------------------------------------// -COORDINATE::COORDINATE():_coordinate(), +COORDINATE::COORDINATE():_coordinate(MEDARRAY()), _coordinateName(), _coordinateUnit(), _coordinateSystem(""), @@ -14,132 +43,183 @@ COORDINATE::COORDINATE():_coordinate(), BEGIN_OF("Default Constructor COORDINATE"); } +/*! This constructor allocate a MEDARRAY of SpaceDimension * NumberOfNodes./n + It will create empty array for optional data (nodeNumber..) */ //------------------------------------------------------------------------------// -COORDINATE::COORDINATE(medModeSwitch Mode, int SpaceDimension, int NumberOfNodes): - _nodeNumber(),_coordinateUnit(SpaceDimension), +COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode): + _nodeNumber(), + _coordinateUnit(SpaceDimension), _coordinateSystem(""), - _coordinateName(SpaceDimension) + _coordinateName(SpaceDimension), + _coordinate(SpaceDimension,NumberOfNodes,Mode) + //------------------------------------------------------------------------------// { BEGIN_OF("Constructor COORDINATE"); - _coordinate = new MEDARRAY(SpaceDimension,NumberOfNodes,Mode); } +/*! This constructor will COPY all data (it is a deep copy) included in m./n + But only the default storage mode of coordinates array + will be copied (not both storage representation modes even if they both + exist in original object) : for example only full_interlace mode */ //------------------------------------------------------------------------------// COORDINATE::COORDINATE(const COORDINATE & m): - _coordinateSystem(m._coordinateSystem) + _coordinateSystem(m._coordinateSystem), + _coordinate(m._coordinate,false) //------------------------------------------------------------------------------// { BEGIN_OF("Copy Constructor COORDINATE"); - int spaceDimension; - int numberOfNodes; - if (m._coordinate != NULL) - { - spaceDimension = (int) m._coordinate->getLeadingValue(); - numberOfNodes = (int) m._coordinate->getLengthValue(); - _coordinate = new MEDARRAY(*m._coordinate); - } - else - { - _coordinate = (MEDARRAY*) NULL; - spaceDimension = 0; - numberOfNodes = 0; - } - - _coordinateName.set(spaceDimension); - for (int i=0; i *Coordinate) //----------------------------------------------------------// { -//PN a voir ... - if ((_coordinate!=NULL) ) - { - MESSAGE("deleting old _coordinate" ) ; - delete _coordinate ; - } - _coordinate=Coordinate ; + + const medModeSwitch mode = Coordinate->getMode(); + const int spaceDimension = (int) Coordinate->getLeadingValue(); + const int numberOfNodes = (int) Coordinate->getLengthValue(); + if ( Coordinate->get(mode) != NULL) + { + MEDARRAY pourAttribut(*Coordinate,false); + _coordinate = pourAttribut; + //_coordinate.set(mode,Coordinate->get(mode)); + } + else + { + throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY + *Coordinate)") << "No Coordinate")); + } } -/*! set the attribute _coordinateName with CoordinateName */ +/*! + Sets the value in attribute _coordinate with Coordinate. + _coordinate must be allocated (with + COORDINATE::COORDINATE(int,int,medModeSwitch). +*/ //----------------------------------------------------------// -void COORDINATE::setCoordinatesNames(string * CoordinateName) +void COORDINATE::setCoordinates(const medModeSwitch Mode, + const double *Coordinate) //----------------------------------------------------------// -{ - _coordinateName=CoordinateName ; +{ +// if (_coordinate == NULL) +// throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !"); + + _coordinate.set(Mode,Coordinate); +} + +/*! sets the attribute _coordinateName with CoordinateName */ +//----------------------------------------------------------// +void COORDINATE::setCoordinatesNames(const string * CoordinateName) +//----------------------------------------------------------// +{ + int SpaceDimension = getSpaceDimension() ; + _coordinateName.set(SpaceDimension) ; + for (int i=0; iget(Mode) ; + return _coordinate.get(Mode) ; } /* returns the coordinate of node Number on axis Axis */ @@ -147,53 +227,53 @@ const double * COORDINATE::getCoordinates (medModeSwitch Mode) double COORDINATE::getCoordinate(int Number,int Axis) //----------------------------------------------------// { - return _coordinate->getIJ(Number,Axis) ; + return _coordinate.getIJ(Number,Axis) ; } /* returns all nodes coordinates from axis Axis */ //----------------------------------------------------// -const double * COORDINATE::getCoordinateAxis(int Axis) +const double * COORDINATE::getCoordinateAxis(int Axis) //----------------------------------------------------// { //< return all nodes coordinates from axis Axis - return _coordinate->getI(MED_NO_INTERLACE,Axis) ; + return _coordinate.getColumn(Axis) ; } -/*! Returns an array with names of coordinates. - Example : - - x,y,z - - r,teta,phi +/*! returns an array with names of coordinates. /n + Example : /n + - x,y,z /n + - r,teta,phi /n - ... */ //--------------------------------------// -string * COORDINATE::getCoordinatesNames() +const string * COORDINATE::getCoordinatesNames() const { return _coordinateName ; } /* returns the name of axis Axis */ //-------------------------------------------// -string COORDINATE::getCoordinateName(int Axis) +string COORDINATE::getCoordinateName(int Axis) const //-------------------------------------------// { return _coordinateName[Axis-1]; } -/*! Returns an array with units of coordinates (cm, m, mm, ...) +/*! returns an array with units of coordinates (cm, m, mm, ...) It could be empty. We suppose we are IS (meter). */ //-----------------------------------------------------// -string * COORDINATE::getCoordinatesUnits() +const string * COORDINATE::getCoordinatesUnits() const //-----------------------------------------------------// { return _coordinateUnit ; } -/*! Returns the unit of axis Axis */ +/*! returns the unit of axis Axis */ //------------------------------------------// -string COORDINATE::getCoordinateUnit(int Axis) +string COORDINATE::getCoordinateUnit(int Axis) const //------------------------------------------// { return _coordinateUnit[Axis-1] ; } -/*! Returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/ +/*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/ //---------------------------------------------------// string COORDINATE::getCoordinatesSystem() const //---------------------------------------------------// diff --git a/src/MEDMEM/MEDMEM_Exception.hxx b/src/MEDMEM/MEDMEM_Exception.hxx index 9b5bc55d8..aa4245f61 100644 --- a/src/MEDMEM/MEDMEM_Exception.hxx +++ b/src/MEDMEM/MEDMEM_Exception.hxx @@ -1,3 +1,29 @@ +// MED MEDMEM : MED files in memory +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MEDMEM_Exception.hxx +// Module : MED + /* File MedException.hxx $Header$ @@ -16,7 +42,14 @@ using namespace std; #endif #define MED_EXCEPTION MEDEXCEPTION -class MEDEXCEPTION : public exception + +/*! + Class used to throws exception.\n + Inherits from public exception. +*/ +//--------------------------------------// + class MEDEXCEPTION : public exception +//--------------------------------------// { private : MEDEXCEPTION(void); @@ -34,7 +67,9 @@ public : } ; +//---------------------------------------------------------// class MED_DRIVER_NOT_FOUND_EXCEPTION : public MEDEXCEPTION +//---------------------------------------------------------// { private : MED_DRIVER_NOT_FOUND_EXCEPTION(void); diff --git a/src/MEDMEM/MEDMEM_Group.cxx b/src/MEDMEM/MEDMEM_Group.cxx index f8bb743ad..4a883f3a5 100644 --- a/src/MEDMEM/MEDMEM_Group.cxx +++ b/src/MEDMEM/MEDMEM_Group.cxx @@ -1,3 +1,29 @@ +// MED MEDMEM : MED files in memory +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MEDMEM_Group.cxx +// Module : MED + using namespace std; /* File Group.cxx @@ -26,6 +52,18 @@ GROUP & GROUP::operator=(const GROUP &group) return *this; }; +ostream & operator<<(ostream &os, GROUP &myGroup) +{ + os << (SUPPORT) myGroup; + + int numberoffamilies = myGroup.getNumberOfFamilies(); + os << " - Families ("<getName().c_str()< & families) throw (MEDEXCEPTION) { const char * LOC = "GROUP( const string & , const list & ) : " ; @@ -57,18 +95,18 @@ GROUP::GROUP(const string & name, const list & families) throw (MEDEXCE _geometricType = new medGeometryElement[_numberOfGeometricType]; //_geometricTypeNumber = new int[_numberOfGeometricType] ; _numberOfGaussPoint = new int[_numberOfGeometricType] ; - _numberOfEntities = new int[_numberOfGeometricType] ; - medGeometryElement * geometricType = myFamily->getTypes() ; + _numberOfElements = new int[_numberOfGeometricType] ; + const medGeometryElement * geometricType = myFamily->getTypes() ; //int * geometricTypeNumber = myFamily->getGeometricTypeNumber() ; - int * numberOfGaussPoint = myFamily->getNumberOfGaussPoint() ; + const int * numberOfGaussPoint = myFamily->getNumberOfGaussPoint() ; for (int i=0 ; i<_numberOfGeometricType; i++) { _geometricType[i]= geometricType[i] ; // _geometricTypeNumber[i] = geometricTypeNumber[i] ; _numberOfGaussPoint[i] = numberOfGaussPoint[i] ; - _numberOfEntities[i]=myFamily->getNumberOfElements(geometricType[i]); + _numberOfElements[i]=myFamily->getNumberOfElements(geometricType[i]); } _isOnAllElts = false ; - _totalNumberOfEntities = myFamily->getNumberOfElements(MED_ALL_ELEMENTS) ; + //_totalNumberOfEntities = myFamily->getNumberOfElements(MED_ALL_ELEMENTS) ; _number = new MEDSKYLINEARRAY(*myFamily->getnumber()) ; _numberOfFamilies = families.size(); @@ -84,7 +122,7 @@ GROUP::GROUP(const string & name, const list & families) throw (MEDEXCE END_OF(LOC); }; -GROUP::GROUP(GROUP & m):SUPPORT(m) +GROUP::GROUP(const GROUP & m):SUPPORT(m) { _numberOfFamilies = m._numberOfFamilies; _family = m._family; @@ -113,7 +151,7 @@ GROUP::GROUP(GROUP & m):SUPPORT(m) // _geometricType = new medGeometryElement[_numberOfGeometricType]; // //_geometricTypeNumber = new int[_numberOfGeometricType] ; // _numberOfGaussPoint = new int[_numberOfGeometricType] ; -// _numberOfEntities = new int[_numberOfGeometricType] ; +// _numberOfElements = new int[_numberOfGeometricType] ; // medGeometryElement * geometricType = myFamily->getTypes() ; // //int * geometricTypeNumber = myFamily->getGeometricTypeNumber() ; // int * numberOfGaussPoint = myFamily->getNumberOfGaussPoint() ; @@ -121,7 +159,7 @@ GROUP::GROUP(GROUP & m):SUPPORT(m) // _geometricType[i]= geometricType[i] ; // // _geometricTypeNumber[i] = geometricTypeNumber[i] ; // _numberOfGaussPoint[i] = numberOfGaussPoint[i] ; -// _numberOfEntities[i]=myFamily->getNumberOfElements(geometricType[i]); +// _numberOfElements[i]=myFamily->getNumberOfElements(geometricType[i]); // } // _isOnAllElts = false ; // _totalNumberOfEntities = myFamily->getNumberOfElements(MED_ALL_ELEMENTS) ; diff --git a/src/MEDMEM/MEDMEM_Med.cxx b/src/MEDMEM/MEDMEM_Med.cxx index 9edc162f1..bc242f80e 100644 --- a/src/MEDMEM/MEDMEM_Med.cxx +++ b/src/MEDMEM/MEDMEM_Med.cxx @@ -1,45 +1,191 @@ +// MED MEDMEM : MED files in memory +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MEDMEM_Med.cxx +// Module : MED + using namespace std; +# include + # include "MEDMEM_Med.hxx" # include "MEDMEM_STRING.hxx" # include "MEDMEM_Mesh.hxx" +# include "MEDMEM_Grid.hxx" # include "MEDMEM_Field.hxx" # include "MEDMEM_Exception.hxx" # include "utilities.h" -// MED constructors +/*! + Constructor. +*/ MED::MED() { - const char * LOC = "MED::MED() : "; - - MESSAGE(LOC << "Construction..."); - + MESSAGE("MED::MED()"); }; -MED::MED(driverTypes driverType, const string & fileName) { +/*! + Constructor. +*/ +MED::MED(driverTypes driverType, const string & fileName) +{ const char * LOC = "MED::MED(driverTypes driverType, const string & fileName) : "; - int current; + BEGIN_OF(LOC); + + MED_MED_RDONLY_DRIVER * myDriver = new MED_MED_RDONLY_DRIVER(fileName,this) ; + int current = addDriver(*myDriver); + //int current= addDriver(driverType,fileName); - BEGIN_OF(STRING(LOC)); - current = addDriver(driverType,fileName); _drivers[current]->open(); _drivers[current]->readFileStruct(); _drivers[current]->close(); - END_OF(STRING(LOC)); + + END_OF(LOC); }; +/*! + Destructor. +*/ MED::~MED() { + const char * LOC = "MED::~MED() : "; + BEGIN_OF(LOC); + + // Analysis of the object MED + + int index; + + map::const_iterator currentField; + index = 0; + for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) { + if ( (*currentField).first != NULL) index++; + } + + MESSAGE(LOC << " there is(are) " << index << " field(s):"); + for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) { + if ( (*currentField).first != NULL) MESSAGE(" " << ((*currentField).first)->getName().c_str()); + } + + map >::iterator itSupportOnMesh ; + index = 0; + for ( itSupportOnMesh=_support.begin();itSupportOnMesh != _support.end(); itSupportOnMesh++ ) { + map::iterator itSupport ; + for ( itSupport=(*itSupportOnMesh).second.begin();itSupport!=(*itSupportOnMesh).second.end();itSupport++) + index++; + } + + MESSAGE(LOC << " there is(are) " << index << " support(s):"); + + map::const_iterator currentMesh; + index =0; + for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) { + if ( (*currentMesh).second != NULL) + index++; + } + + MESSAGE(LOC << " there is(are) " << index << " meshe(s):"); +// for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) { +// if ( (*currentMesh).second != NULL) +// { +// SCRUTE((*currentMesh).second); + +// string meshName = ((*currentMesh).second)->getName(); + +// MESSAGE(" " << meshName); +// } +// } + + // delete all ? : PG : YES ! + // map::const_iterator currentField; + for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) { + if ( (*currentField).first != NULL) { + // cast in right type to delete it ! + switch ((*currentField).first->getValueType()) { + case MED_INT32 : + // mpv: such recursive destructors call is problematic for current ALLIANCES algorithms + //delete (FIELD*) (*currentField).first ; + break ; + case MED_REEL64 : + // mpv: such recursive destructors call is problematic for current ALLIANCES algorithms + //delete (FIELD*) (*currentField).first ; + break ; + default : + INFOS("Field has type different of int or double, could not destroy its values array !") ; + // mpv: such recursive destructors call is problematic for current ALLIANCES algorithms + //delete (*currentField).first; + } + } + } + // map >::iterator itSupportOnMesh ; + for ( itSupportOnMesh=_support.begin();itSupportOnMesh != _support.end(); itSupportOnMesh++ ) { + map::iterator itSupport ; + for ( itSupport=(*itSupportOnMesh).second.begin();itSupport!=(*itSupportOnMesh).second.end();itSupport++) + ;// mpv: such recursive destructors call is problematic for current ALLIANCES algorithms + //delete (*itSupport).second ; + } + + // map::const_iterator currentMesh; + for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) { + if ( (*currentMesh).second != NULL) + { + if (!((*currentMesh).second)->getIsAGrid()) + ;// mpv: such recursive destructors call is problematic for current ALLIANCES algorithms + //delete (*currentMesh).second; + else + ;// mpv: such recursive destructors call is problematic for current ALLIANCES algorithms + //delete (GRID *) (*currentMesh).second; + } + } + + index =_drivers.size(); + + MESSAGE(LOC << "In this object MED there is(are) " << index << " driver(s):"); + + for (int ind=0; ind < _drivers.size(); ind++ ) + { + SCRUTE(_drivers[ind]); + if ( _drivers[ind] != NULL) delete _drivers[ind]; + } + + + + END_OF(LOC); } ; // ------- Drivers Management Part -MED::INSTANCE_DE MED::inst_med ; -//MED::INSTANCE_DE MED::inst_vtk ; +// Add your new driver instance declaration here (step 3-1) +MED::INSTANCE_DE MED::inst_med ; +MED::INSTANCE_DE MED::inst_vtk ; -const MED::INSTANCE * const MED::instances[] = { &MED::inst_med }; //, &MED::inst_vtk } ; +// Add your new driver instance in the MED instance list (step 3-2) +const MED::INSTANCE * const MED::instances[] = { &MED::inst_med, &MED::inst_vtk }; +/*! + Create the specified driver and return its index reference to path to + read or write methods. +*/ int MED::addDriver(driverTypes driverType, const string & fileName="Default File Name.med") { const char * LOC = "MED::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\") : "; @@ -48,8 +194,8 @@ int MED::addDriver(driverTypes driverType, const string & fileName="Default File BEGIN_OF(LOC); + MESSAGE(LOC << " the file name is " << fileName); driver = instances[driverType]->run(fileName, this) ; - driver->setId(current); current = _drivers.size()-1; driver->setId(current); @@ -57,23 +203,39 @@ int MED::addDriver(driverTypes driverType, const string & fileName="Default File return current; } -/*! Add an existing MESH driver. */ +/*! + Duplicate the given driver and return its index reference to path to + read or write methods. +*/ int MED::addDriver(GENDRIVER & driver) { const char * LOC = "MED::addDriver(GENDRIVER &) : "; int current; BEGIN_OF(LOC); + SCRUTE(_drivers.size()); + _drivers.push_back(&driver); + + SCRUTE(_drivers.size()); + + SCRUTE(_drivers[0]); + SCRUTE(driver); + current = _drivers.size()-1; driver.setId(current); + END_OF(LOC); return current; - END_OF(LOC); } -void MED::rmDriver (int index/*=0*/) { +/*! + Remove the driver referenced by its index. +*/ +void MED::rmDriver (int index/*=0*/) + throw (MED_EXCEPTION) +{ const char * LOC = "MED::rmDriver (int index=0): "; BEGIN_OF(LOC); @@ -89,16 +251,18 @@ void MED::rmDriver (int index/*=0*/) { END_OF(LOC); } - +/*! + ??? to do comment ??? +*/ void MED::writeFrom (int index/*=0*/) + throw (MED_EXCEPTION) { const char * LOC = "MED::write (int index=0): "; BEGIN_OF(LOC); if (_drivers[index]) { - _drivers[index]->open(); - _drivers[index]->writeFrom(); - _drivers[index]->close(); + // open and close are made by all objects ! + _drivers[index]->writeFrom(); } throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "The index given is invalid, index must be between 0 and |" @@ -108,16 +272,18 @@ void MED::writeFrom (int index/*=0*/) END_OF(LOC); }; - +/*! + Write all objects with the driver given by its index. +*/ void MED::write (int index/*=0*/) + throw (MED_EXCEPTION) { - const char * LOC = "MED::writeAll (int index=0): "; + const char * LOC = "MED::write (int index=0): "; BEGIN_OF(LOC); if (_drivers[index]) { - _drivers[index]->open(); + // open and close are made by the subsequent objects ! _drivers[index]->write(); - _drivers[index]->close(); } else throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) @@ -128,8 +294,17 @@ void MED::write (int index/*=0*/) END_OF(LOC); }; +/*! + Parse all the file and generate empty object. + + All object must be read explicitly later with their own method read + or use MED::read to read all. -void MED::readFileStruct (int index/*=0*/) { + This method is automaticaly call by constructor with driver information. +*/ +void MED::readFileStruct (int index/*=0*/) + throw (MED_EXCEPTION) +{ const char * LOC = "MED::readFileStruct (int index=0): "; BEGIN_OF(LOC); @@ -147,28 +322,39 @@ void MED::readFileStruct (int index/*=0*/) { END_OF(LOC); } -// void MED::read (int index=0) -// { -// const char * LOC = "MED::read (int index=0): "; -// BEGIN_OF(LOC); +/*! + Read all objects in the file specified in the driver given by its index. +*/ +void MED::read (int index/*=0*/) + throw (MED_EXCEPTION) +{ + const char * LOC = "MED::read (int index=0): "; + BEGIN_OF(LOC); -// if (_drivers[index]) -// throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) -// << "The index given is invalid, index must be between >0 and < |" -// << _drivers.size()-1 -// ) -// ); -// // GERER LE 0 -// _drivers[index]->open(); -// _drivers[index]->read(); -// _drivers[index]->close(); - -// END_OF(LOC); - -// }; + if (_drivers[index]) { + // open and close are made by all objects ! + SCRUTE(index); + SCRUTE(_drivers[index]); + SCRUTE(&_drivers[index]); + // _drivers[index]->open(); + _drivers[index]->read(); + // _drivers[index]->close(); + } + else + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "The index given is invalid, index must be between >0 and < |" + << _drivers.size()-1 + ) + ); + END_OF(LOC); + +}; // ------- End Of Drivers Management Part +/*! + Get the number of MESH objects. +*/ int MED::getNumberOfMeshes ( void ) const { const char * LOC = "MED::getNumberOfMeshes ( void ) const : "; @@ -179,19 +365,31 @@ int MED::getNumberOfMeshes ( void ) const { END_OF(LOC); }; +/*! + Get the number of FIELD objects. +*/ int MED::getNumberOfFields ( void ) const { const char * LOC = "MED::getNumberOfFields ( void ) const : "; BEGIN_OF(LOC); - // return _meshName.size(); return _fields.size(); // we get number of field with different name END_OF(LOC); }; -void MED::getMeshNames ( string * meshNames ) const { +/*! + Get the names of all MESH objects. + + meshNames is an in/out argument. + It is a string array of size the + number of MESH objects. It must be allocated before calling + this method. All names are put in it. +*/ +void MED::getMeshNames ( string * meshNames ) const + throw (MED_EXCEPTION) +{ const char * LOC = "MED::getMeshNames ( string * ) const : "; BEGIN_OF(LOC); int meshNamesSize; @@ -218,6 +416,11 @@ void MED::getMeshNames ( string * meshNames ) const { END_OF(LOC); }; +/*! + Get the names of all MESH objects. + + Return a deque object which contain the name of all MESH objects. +*/ deque MED::getMeshNames () const { const char * LOC = "MED::getMeshNames () const : "; @@ -238,14 +441,19 @@ deque MED::getMeshNames () const { return meshNames ; }; -MESH * MED::getMesh ( const string & meshName ) const { + +/*! + Return a reference to the MESH object named meshName. +*/ +MESH * MED::getMesh ( const string & meshName ) const + throw (MED_EXCEPTION) +{ const char * LOC = "MED::getMesh ( const string & meshName ) const : "; BEGIN_OF(LOC); map::const_iterator itMeshes = _meshes.find(meshName); - // if ( itMeshes == _meshName.end() ) if ( itMeshes == _meshes.end() ) throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "There is no known mesh named |" @@ -258,7 +466,13 @@ MESH * MED::getMesh ( const string & meshName ) const { END_OF(LOC); } -MESH * MED::getMesh (const FIELD_ * const field ) const { +/*! + \internal Return a reference to the MESH object associated with + field argument. +*/ +MESH * MED::getMesh (const FIELD_ * const field ) const + throw (MED_EXCEPTION) +{ const char * LOC = "MED::getMesh ( const FIELD * field ) const : "; BEGIN_OF(LOC); @@ -268,7 +482,7 @@ MESH * MED::getMesh (const FIELD_ * const field ) const { if ( itMeshName == _meshName.end() ) throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) - << "There is no known field associated with |" + << "There is no known mesh associated with |" << field << "| pointer" ) ); @@ -289,8 +503,18 @@ MESH * MED::getMesh (const FIELD_ * const field ) const { }; -void MED::getFieldNames ( string * fieldNames ) const { +/*! + Get the names of all FIELD objects. + + fieldNames is an in/out argument. + It is an array of string of size the + number of FIELD objects. It must be allocated before calling + this method. All names are put in it. +*/ +void MED::getFieldNames ( string * fieldNames ) const + throw (MED_EXCEPTION) +{ const char * LOC = "MED::getFieldNames ( string * ) const : "; BEGIN_OF(LOC); @@ -317,6 +541,11 @@ void MED::getFieldNames ( string * fieldNames ) const { }; +/*! + Get the names of all FIELD objects. + + Return a deque object which contain the name of all FIELD objects. +*/ deque MED::getFieldNames () const { const char * LOC = "MED::getFieldNames ( ) const : "; @@ -337,7 +566,13 @@ deque MED::getFieldNames () const { return fieldNames ; }; -deque MED::getFieldIteration (const string & fieldName) const { +/*! + Return a deque which contain all iteration step for the FIELD + identified by its name. +*/ +deque MED::getFieldIteration (const string & fieldName) const + throw (MED_EXCEPTION) +{ const char * LOC = "MED::getFieldIteration ( const string & ) const : "; BEGIN_OF(LOC); @@ -367,7 +602,13 @@ deque MED::getFieldIteration (const string & fieldName) const { return Iteration ; }; -FIELD_ * MED::getField ( const string & fieldName, const int dt=MED_NOPDT, const int it=MED_NOPDT ) const { +/*! + Return a reference to the FIELD object named fieldName with + time step number dt and order number it. +*/ +FIELD_ * MED::getField ( const string & fieldName, const int dt=MED_NOPDT, const int it=MED_NOPDT ) const + throw (MED_EXCEPTION) +{ const char * LOC = "MED::getField ( const string &, const int, const int ) const : "; BEGIN_OF(LOC); @@ -411,8 +652,12 @@ FIELD_ * MED::getField ( const string & fieldName, const int dt=MED_NO // return os; // }; - +/*! + Return a map which contain + foreach entity, a reference to the SUPPORT on all elements. +*/ const map & MED::getSupports(const string & meshName) const + throw (MED_EXCEPTION) { const char * LOC = "MED::getSupports ( const string ) const : "; BEGIN_OF(LOC); @@ -429,7 +674,12 @@ const map & MED::getSupports(const string return (*itSupportOnMesh).second ; } +/*! + Return a reference to the SUPPORT object on all elements of entity + for the MESH named meshName. +*/ SUPPORT * MED::getSupport (const string & meshName,MED_FR::med_entite_maillage entity) const + throw (MED_EXCEPTION) { const char * LOC = "MED::getSupport ( const string, MED_FR::med_entite_maillage ) const : "; BEGIN_OF(LOC); @@ -457,6 +707,10 @@ SUPPORT * MED::getSupport (const string & meshName,MED_FR::med_entite_maillage return (*itSupport).second ; }; +/*! + Temporary method : when all MESH objects are read, this methods + update all SUPPORT objects with the rigth dimension. +*/ void MED::updateSupport () { @@ -472,24 +726,82 @@ void MED::updateSupport () } catch (MEDEXCEPTION & ex) { // entity not defined in mesh -> we remove support on it ! + MESSAGE(LOC<getName()).size() ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrMesh->_name must not be NULL !")); + + _meshes[meshName] = ptrMesh; // if ptrMesh->meshName already exists it is modified - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "WARNING method not yet implemented")); + END_OF(LOC); } -void MED::addField(const FIELD_ * const ptrField) throw (MEDEXCEPTION) +/*! + Add the given FIELD object. MED object control it, + and destroy it, so you must not destroy it after. + + The fieldName is given by the FIELD object. +*/ +void MED::addField( FIELD_ * const ptrField) + throw (MED_EXCEPTION) { const char * LOC = "MED::addField(const FIELD_ * const ptrField): "; + BEGIN_OF(LOC); + + if ( ! ptrField ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField must not be NULL !")); + + string fieldName; + if ( ! (fieldName = ptrField->getName()).size() ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField->_name must not be NULL !")); + + SUPPORT * ptrSupport; + if ( ! ( ptrSupport = (SUPPORT * ) ptrField->getSupport()) ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField->_support must not be NULL !")); + + MESH * ptrMesh; + if ( ! ( ptrMesh = ptrSupport->getMesh()) ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField->_support->_mesh must not be NULL !")); - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "WARNING method not yet implemented")); + string meshName; + if ( ! ( meshName = ptrMesh->getName()).size() ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField->_support->_mesh->_name must not be NULL !")); + + DT_IT_ dtIt; + dtIt.dt = ptrField->getIterationNumber(); + dtIt.it = ptrField->getOrderNumber(); + + _fields [fieldName][dtIt] = ptrField; // if it already exists it is replaced + _meshName [ptrField] = meshName; // if it already exists it is replaced + _meshes [meshName] = ptrMesh; // if it already exists it is replaced + + int numberOfTypes = ptrSupport->getNumberOfTypes(); + _support [meshName][ (MED_FR::med_entite_maillage) ptrSupport->getEntity()] = ptrSupport;// if it already exists it is replaced + + + END_OF(LOC); } diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver.cxx b/src/MEDMEM/MEDMEM_MedMeshDriver.cxx index 6871d64fc..cd764c0c1 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver.cxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver.cxx @@ -1,3 +1,29 @@ +// MED MEDMEM : MED files in memory +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MEDMEM_MedMeshDriver.cxx +// Module : MED + using namespace std; #include "MEDMEM_MedMeshDriver.hxx" @@ -9,20 +35,92 @@ using namespace std; #include "MEDMEM_Connectivity.hxx" #include "MEDMEM_Mesh.hxx" #include "MEDMEM_CellModel.hxx" +#include "MEDMEM_Grid.hxx" extern "C" { extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom); extern med_err _MEDdatagroupFermer(med_idt id); } -using namespace MED_FR; // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor +MED_MESH_DRIVER::MED_MESH_DRIVER(): + GENDRIVER(), + _ptrMesh(( MESH *)MED_NULL), + _medIdt(MED_INVALID), + _meshName(""), + _meshNum(MED_INVALID) +{ +} + +MED_MESH_DRIVER::MED_MESH_DRIVER(const string & fileName, + MESH * ptrMesh, + MED_EN::med_mode_acces accessMode): + GENDRIVER(fileName,accessMode), + _ptrMesh(ptrMesh), + _medIdt(MED_INVALID), + _meshName(""), + _meshNum(MED_INVALID) +{ +} + +MED_MESH_DRIVER::MED_MESH_DRIVER(const MED_MESH_DRIVER & driver): + GENDRIVER(driver), + _ptrMesh(driver._ptrMesh), + _medIdt(MED_INVALID), + _meshName(driver._meshName), + _meshNum(driver._meshNum) +{ +} + +MED_MESH_DRIVER::~MED_MESH_DRIVER() +{ +} + +void MED_MESH_DRIVER::open() + throw (MEDEXCEPTION) +{ + const char * LOC = "MED_MESH_DRIVER::open()" ; + BEGIN_OF(LOC); + MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); + _medIdt = MED_FR::MEDouvrir( (const_cast (_fileName.c_str())),(MED_FR::med_mode_acces) _accessMode); + MESSAGE(LOC<<" _medIdt : "<< _medIdt ); + if (_medIdt > 0) + _status = MED_OPENED; + else { + _medIdt = MED_INVALID; + _status = MED_CLOSED; + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName<<" in mode "<<_accessMode)); + } + + END_OF(LOC); +} + +void MED_MESH_DRIVER::close() + throw (MEDEXCEPTION) +{ + const char * LOC = "MED_MESH_DRIVER::close() " ; + BEGIN_OF(LOC); + int err = 0; + if ( _status == MED_OPENED) { + err=MED_FR::MEDfermer(_medIdt); + H5close(); // If we call H5close() all the files are closed. + if (err != 0) + throw MEDEXCEPTION( LOCALIZED(STRING(LOC) + <<" Error when closing file !" + ) + ); + MESSAGE(LOC <<": _medIdt= " << _medIdt ); + MESSAGE(LOC<<": MEDfermer : err = " << err ); + _status = MED_CLOSED; + _medIdt = MED_INVALID; + } + END_OF(LOC); +} + void MED_MESH_DRIVER::setMeshName(const string & meshName) { _meshName = meshName; }; string MED_MESH_DRIVER::getMeshName() const { return _meshName; }; -//---------------------------------- RDONLY PART ------------------------------------------------------------- - //A FAIRE UTILISER LES MAPS... const MED_FR::med_geometrie_element MED_MESH_DRIVER::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]= { MED_FR::MED_POINT1,MED_FR::MED_SEG2,MED_FR::MED_SEG3,MED_FR::MED_TRIA3,MED_FR::MED_QUAD4,MED_FR::MED_TRIA6,MED_FR::MED_QUAD8, @@ -35,18 +133,71 @@ const char * const MED_MESH_DRIVER::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE] "MED_PENTA15","MED_HEXA20"}; +//---------------------------------- RDONLY PART ------------------------------------------------------------- +MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(): MED_MESH_DRIVER() +{ +} + +MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, + MESH * ptrMesh): + MED_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY) +{ + MESSAGE("MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created"); +} + +MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const MED_MESH_RDONLY_DRIVER & driver): + MED_MESH_DRIVER(driver) +{ +} + +MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER() +{ + //MESSAGE("MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER() has been destroyed"); +} + +GENDRIVER * MED_MESH_RDONLY_DRIVER::copy(void) const +{ + return new MED_MESH_RDONLY_DRIVER(*this); +} void MED_MESH_RDONLY_DRIVER::read(void) + throw (MEDEXCEPTION) { const char * LOC = "MED_MESH_RDONLY_DRIVER::read() : " ; BEGIN_OF(LOC); if (_status!=MED_OPENED) - throw MEDEXCEPTION(" "); - //throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " << _medIdt << " (the file is not opened)." )) ; + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " << _medIdt << " (the file is not opened)." )) ; _ptrMesh->_name = _meshName; - + + SCRUTE(_ptrMesh->getIsAGrid()); + + if (_ptrMesh->getIsAGrid()) + { + getGRID( ); + + // always call getFAMILY : families are requiered !!!! + +// int nbFam = MEDnFam(_medIdt, +// const_cast (_meshName.c_str()), +// 0, +// MED_FR::MED_FAMILLE); +// if (nbFam > 0) + { +// getFAMILY(); + + if (getFAMILY()!=MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ; + + buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ; + _ptrMesh->_numberOfNodesGroups = _ptrMesh->_groupNode.size() ; + } + + END_OF(LOC); + return; + } + if (getCOORDINATE()!=MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE" )) ; @@ -75,16 +226,196 @@ void MED_MESH_RDONLY_DRIVER::read(void) MESSAGE(LOC<<"Checking of CellModel !!!!!!!"); int nbOfTypes = _ptrMesh->_connectivity->_numberOfTypes; - for(int i=0;i_connectivity->_type[i]) ; +// } + + END_OF(LOC); +} + +//======================================================================= +//function : getGRID +//purpose : +//======================================================================= + +void MED_MESH_RDONLY_DRIVER::getGRID() +{ + const char * LOC = "MED_MESH_RDONLY_DRIVER::getGRID() : " ; + BEGIN_OF(LOC); + + if (_status!=MED_OPENED) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "med file is not opened")); + + GRID * ptrGrid = (GRID *) _ptrMesh; + + int err, i; + + // Read the dimension of the space for the mesh <_meshName> + int SpaceDimension = MED_FR::MEDdimLire(_medIdt,const_cast (_meshName.c_str())) ; + if ( SpaceDimension <= MED_VALID ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The space dimension |" << SpaceDimension << + "| seems to be incorrect " << "for the mesh : |" << + _meshName << "|")) ; + _ptrMesh->_spaceDimension = SpaceDimension; + + // Read Array length + int * ArrayLen[] = { & ptrGrid->_iArrayLength, + & ptrGrid->_jArrayLength, + & ptrGrid->_kArrayLength }; + int idim; + for (idim = 0; idim < _ptrMesh->_spaceDimension; ++idim) { - MESSAGE(LOC << _ptrMesh->_connectivity->_type[i]) ; + int lenght = MED_FR::MEDnGrid(_medIdt, + const_cast (_ptrMesh->_name.c_str()), + (MED_FR::med_grid) + idim + ); + if ( lenght <= MED_VALID ) + throw MEDEXCEPTION(STRING(LOC) <<"The number of nodes |" << lenght << + "| seems to be incorrect " + << "for the mesh : |" << _meshName << "|" ) ; + + ArrayLen [idim][0] = lenght; + } + + MED_FR::med_repere rep ; + string tmp_nom_coord (MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,' '); + string tmp_unit_coord(MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,' '); + char * tmp_nom = (const_cast ( tmp_nom_coord.c_str()) ) ; + char * tmp_unit= (const_cast ( tmp_unit_coord.c_str()) ) ; + + // Read node coordinates for MED_BODY_FITTED grid + if (ptrGrid->getGridType() == MED_EN::MED_BODY_FITTED) + { + // Read nb of nodes + int NumberOfNodes = MED_FR::MEDnGrid(_medIdt, + const_cast (_meshName.c_str()), + MED_FR::MED_GRID_NOEUD); + if ( NumberOfNodes <= MED_VALID ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes << + "| seems to be incorrect " + << "for the mesh : |" << _meshName << "|" )) ; + _ptrMesh->_numberOfNodes = NumberOfNodes ; + + // this array is useless because families numbers are read in getFAMILY + int * MEDArrayNodeFamily = new int[ NumberOfNodes ]; + // create coordinates + _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes, + MED_EN::MED_FULL_INTERLACE); + + // Read coordinates and families + double * coo = const_cast + (_ptrMesh->_coordinate->getCoordinates(MED_EN::MED_FULL_INTERLACE)); + + err = MED_FR::MEDbodyFittedLire (_medIdt, + const_cast (_ptrMesh->_name.c_str()), + _ptrMesh->_spaceDimension, + coo, + MED_FR::MED_FULL_INTERLACE, + & rep, + tmp_nom, + tmp_unit, + MEDArrayNodeFamily, + NumberOfNodes); + delete[] MEDArrayNodeFamily; + if (err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in MEDbodyFittedLire()")); + + // _ptrMesh->_MEDArrayNodeFamily = fam ; + } + else + { + // Read Arrays and Node families in Cartesian or Polar Grid + + int nbNodes = 1; + double * Array[] = { (double*) 0, (double*) 0, (double*) 0 }; + for (idim = 0; idim < _ptrMesh->_spaceDimension; ++idim) + { + int nbNodesDim = * ArrayLen [idim]; + nbNodes *= nbNodesDim; + Array [idim] = new double [ nbNodesDim ]; + err = MED_FR::MEDgridLire (_medIdt, + const_cast (_ptrMesh->_name.c_str()), + _ptrMesh->_spaceDimension, + Array [idim], + idim, + MED_FR::MED_FULL_INTERLACE, + & rep, + tmp_nom, + tmp_unit); + if (err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Error in MEDgridLire for dimention" << idim )); + + } + ptrGrid->_iArray = Array[0]; + ptrGrid->_jArray = Array[1]; + ptrGrid->_kArray = Array[2]; + + _ptrMesh->_numberOfNodes = nbNodes ; + + // create coordinates + _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,nbNodes, + MED_EN::MED_FULL_INTERLACE); + // Read node families +// int nbFamNodes = MED_FR::MEDnGrid(_medIdt, +// const_cast (_ptrMesh->_name.c_str()), +// MED_FR::MED_FAM_NOEUD); +// if (nbFamNodes > 0) +// { +// // int * fam = new int[ nbFamNodes ]; + +// //_ptrMesh->_MEDArrayNodeFamily = new int[ nbFamNodes ]; +// // this array is useless because families numbers are read in getFAMILY +// int * MEDArrayNodeFamily = new int[ nbFamNodes ]; + +// err = MED_FR::MEDfamGridLire (_medIdt, +// const_cast (_ptrMesh->_name.c_str()), +// MEDArrayNodeFamily, +// nbFamNodes, +// MED_FR::MED_NOEUD); + +// if (err != MED_VALID) +// throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read grid nodes families for " +// << idim << "-th dimention")); +// else +// _ptrMesh->_MEDArrayNodeFamily = fam; +// } + + } // end read Cartesian or Polar Grid + + // set coordinate names + + for (i=0; i<_ptrMesh->_spaceDimension; ++i ) { + string myStringName(tmp_nom,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ; + string myStringUnit(tmp_unit,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ; + // suppress space at the end + int j ; + for(j=MED_TAILLE_PNOM-1;j>=0;j--) + if (myStringName[j] != ' ') break ; + _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1); + for(j=MED_TAILLE_PNOM-1;j>=0;j--) + if (myStringUnit[j] != ' ') break ; + _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1); + } + + string coordinateSystem = "UNDEFINED"; + + if( rep == MED_FR::MED_CART) coordinateSystem = "CARTESIAN"; + else if ( rep == MED_FR::MED_CYL) coordinateSystem = "CYLINDRICAL"; + else if ( rep == MED_FR::MED_SPHER) coordinateSystem = "SPHERICAL"; + + _ptrMesh->_coordinate->setCoordinatesSystem(coordinateSystem); + END_OF(LOC); } - +//======================================================================= +//function : getCOORDINATE // A FAIRE : RENVOYER DU VOID +//======================================================================= int MED_MESH_RDONLY_DRIVER::getCOORDINATE() { const char * LOC = "MED_MESH_RDONLY_DRIVER::getCOORDINATE() : " ; @@ -96,7 +427,7 @@ int MED_MESH_RDONLY_DRIVER::getCOORDINATE() // Read the dimension of the space for the mesh <_meshName> // to be able to create a COORDINATE object - int SpaceDimension = MEDdimLire(_medIdt,const_cast (_meshName.c_str())) ; + int SpaceDimension = MED_FR::MEDdimLire(_medIdt,const_cast (_meshName.c_str())) ; if ( SpaceDimension <= MED_VALID ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The space dimension |" << SpaceDimension << "| seems to be incorrect " << "for the mesh : |" << _meshName << "|")) ; @@ -120,7 +451,7 @@ int MED_MESH_RDONLY_DRIVER::getCOORDINATE() // create a COORDINATE object - _ptrMesh->_coordinate = new COORDINATE(MED_EN::MED_FULL_INTERLACE, SpaceDimension, NumberOfNodes); + _ptrMesh->_coordinate = new COORDINATE(SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE); MED_FR::med_repere rep ; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON? string tmp_nom_coord (MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,'\0'); @@ -131,7 +462,8 @@ int MED_MESH_RDONLY_DRIVER::getCOORDINATE() err=MEDcoordLire(_medIdt, const_cast (_ptrMesh->_name.c_str()), _ptrMesh->_spaceDimension, - const_cast ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), + //const_cast ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), + const_cast ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), MED_FR::MED_FULL_INTERLACE, MED_ALL, // we read all the coordinates NULL, // we don't use a profile @@ -145,10 +477,18 @@ int MED_MESH_RDONLY_DRIVER::getCOORDINATE() << "| and units |" << tmp_unit << " |")) ; + for (int i=0;i<_ptrMesh->_spaceDimension;i++) { - // PG : What about blank !!!!! - _ptrMesh->_coordinate->_coordinateName[i]=string(tmp_nom,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ; - _ptrMesh->_coordinate->_coordinateUnit[i]=string(tmp_unit,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM); + string myStringName(tmp_nom,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ; + string myStringUnit(tmp_unit,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ; + // suppress space at the end + int j ; + for(j=MED_TAILLE_PNOM-1;j>=0;j--) + if (myStringName[j] != ' ') break ; + _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1); + for(j=MED_TAILLE_PNOM-1;j>=0;j--) + if (myStringUnit[j] != ' ') break ; + _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1); } // Pourquoi le stocker sous forme de chaîne ? @@ -176,7 +516,7 @@ int MED_MESH_RDONLY_DRIVER::getCOORDINATE() } } - // Read the unused optionnal node Names + // Read the unused optional node Names char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM+1]; tmp_node_name[NumberOfNodes]='\0' ; err=MEDnomLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), @@ -187,17 +527,19 @@ int MED_MESH_RDONLY_DRIVER::getCOORDINATE() delete[] tmp_node_name ; - // ??? Read the unused optionnal node Numbers ??? + // ??? Read the unused optional node Numbers ??? int * tmp_node_number = new int[NumberOfNodes] ; err=MEDnumLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), - tmp_node_number,NumberOfNodes,MED_NOEUD,(MED_FR::med_geometrie_element)0); + tmp_node_number,NumberOfNodes,MED_FR::MED_NOEUD,(MED_FR::med_geometrie_element)0); if (err == MED_VALID) { INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"); INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !"); INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"); - _ptrMesh->_coordinate->_nodeNumber = tmp_node_number ; - } else - delete[] tmp_node_number ; + _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ; + memcpy((int*)_ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes) ; + } + + delete[] tmp_node_number ; END_OF(LOC); return MED_VALID; @@ -387,7 +729,7 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) int numberOfEdgesTypes = 0; int * tmp_faces_count = new int[MED_NBR_GEOMETRIE_MAILLE] ; int numberOfFacesTypes = 0; - if ((version_med != "2.2")&(Entity==MED_MAILLE)) { + if ((version_med != "2.2")&(Entity==MED_FR::MED_MAILLE)) { Connectivity->_numberOfTypes=0; for (int i=1;i0) { - Connectivity->_count[TypeNumber]=Connectivity->_count[TypeNumber-1]+tmp_cells_count[i]; - + CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ; Connectivity->_type[TypeNumber-1]=t ; @@ -448,8 +789,10 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) } // Creation of the MEDSKYLINEARRAY - Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ; - int * NodalIndex = Connectivity->_nodal->getIndex() ; + //Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ; + //int * NodalIndex = Connectivity->_nodal->getIndex() ; + int * NodalValue = new int[size] ; + int * NodalIndex = new int[Connectivity->_count[Connectivity->_numberOfTypes]] ; NodalIndex[0]=1 ; // Fill the MEDSKYLINEARRAY by reading the MED file. @@ -485,14 +828,21 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) MESSAGE(LOC<<": MEDconnLire returns "<_nodal->getI(Connectivity->_count[i]) ; + int * ConnectivityArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1 ; for (int j=0; j_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1, + size, + NodalIndex, + NodalValue) ; + delete[] NodalIndex; + delete[] NodalValue; + } // end of bloc to read CELL delete[] tmp_cells_count; @@ -523,8 +873,10 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) } // Creation of the MEDSKYLINEARRAY - constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; - int * NodalIndex = constituent->_nodal->getIndex() ; + //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; + //int * NodalIndex = constituent->_nodal->getIndex() ; + int * NodalValue = new int[size] ; + int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ; NodalIndex[0]=1 ; // Fill the MEDSKYLINEARRAY by reading the MED file. @@ -553,7 +905,7 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) return MED_ERROR ; } - int * constituentArray = constituent->_nodal->getI(constituent->_count[i]) ; + int * constituentArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1 ; for (int j=0; j_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1, + size, + NodalIndex, + NodalValue) ; + delete[] NodalIndex ; + delete[] NodalValue ; + Connectivity->_constituent = constituent ; } @@ -570,7 +929,7 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) // =============== if (numberOfEdgesTypes!=0) { CONNECTIVITY * constituent = new CONNECTIVITY(numberOfEdgesTypes,MED_EDGE) ; - constituent->_entityDimension = 2 ; + constituent->_entityDimension = 1 ; constituent->_count[0]=1 ; int size = 0 ; @@ -591,8 +950,10 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) } // Creation of the MEDSKYLINEARRAY - constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; - int * NodalIndex = constituent->_nodal->getIndex() ; + //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; + //int * NodalIndex = constituent->_nodal->getIndex() ; + int * NodalValue = new int[size] ; + int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ; NodalIndex[0]=1 ; // Fill the MEDSKYLINEARRAY by reading the MED file. @@ -610,7 +971,7 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) int * tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ; int err=MEDconnLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), - Connectivity->_entityDimension,tmp_constituentArray, + _ptrMesh->_spaceDimension,tmp_constituentArray, MED_FR::MED_FULL_INTERLACE,NULL,0,MED_FR::MED_MAILLE,med_type,MED_FR::MED_NOD); if ( err != MED_VALID) { MESSAGE(LOC<<": MEDconnLire returns "<_nodal->getI(constituent->_count[i]) ; + int * constituentArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1 ; for (int j=0; j_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1, + size, + NodalIndex, + NodalValue) ; + + delete[] NodalIndex ; + delete[] NodalValue ; + if (Connectivity->_entityDimension == 3) { if (Connectivity->_constituent==NULL) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !")); @@ -695,28 +1064,65 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() if (_status==MED_OPENED) { int err = 0 ; - // read number : - // NODE : - err = getNodesFamiliesNumber() ; // error only if (_status!=MED_OPENED), other case exeception ! - // CELL - _ptrMesh->_MEDArrayCellFamily = new (int*)[_ptrMesh->_connectivity->_numberOfTypes] ; // ET SI IL N'Y A PAS DE CELLS ? - getCellsFamiliesNumber(_ptrMesh->_MEDArrayCellFamily,_ptrMesh->_connectivity) ; - if (_ptrMesh->_connectivity->_constituent != NULL) { - if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE) { - // FACE - _ptrMesh->_MEDArrayFaceFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_numberOfTypes] ; - getCellsFamiliesNumber(_ptrMesh->_MEDArrayFaceFamily,_ptrMesh->_connectivity->_constituent) ; - } else { - // EDGE in 2D - _ptrMesh->_MEDArrayEdgeFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_numberOfTypes] ; - getCellsFamiliesNumber(_ptrMesh->_MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ; + + int * MEDArrayNodeFamily = NULL ; + int ** MEDArrayCellFamily = NULL ; + int ** MEDArrayFaceFamily = NULL ; + int ** MEDArrayEdgeFamily = NULL ; + + if ( !_ptrMesh->getIsAGrid() ) + { + // read number : + // NODE : + MEDArrayNodeFamily = new int[_ptrMesh->getNumberOfNodes()] ; + err = getNodesFamiliesNumber(MEDArrayNodeFamily) ; // error only if (_status!=MED_OPENED), other case exeception ! + // CELL + MEDArrayCellFamily = new (int*)[_ptrMesh->getNumberOfTypes(MED_CELL)] ; // ET SI IL N'Y A PAS DE CELLS ? + const medGeometryElement * myTypes = _ptrMesh->getTypes(MED_CELL); + for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_CELL);i++) + MEDArrayCellFamily[i] = new int[_ptrMesh->getNumberOfElements(MED_CELL,myTypes[i])] ; + + getCellsFamiliesNumber(MEDArrayCellFamily,_ptrMesh->_connectivity) ; + if (_ptrMesh->_connectivity->_constituent != NULL) { + if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE) { + // FACE + MEDArrayFaceFamily = new (int*)[_ptrMesh->getNumberOfTypes(MED_FACE)] ; + myTypes = _ptrMesh->getTypes(MED_FACE); + for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_FACE);i++) + MEDArrayFaceFamily[i] = new int[_ptrMesh->getNumberOfElements(MED_FACE,myTypes[i])] ; + + getCellsFamiliesNumber(MEDArrayFaceFamily,_ptrMesh->_connectivity->_constituent) ; + } else { + // EDGE in 2D + MEDArrayEdgeFamily = new (int*)[_ptrMesh->getNumberOfTypes(MED_EDGE)] ; + myTypes = _ptrMesh->getTypes(MED_EDGE); + for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++) + MEDArrayEdgeFamily[i] = new int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes[i])] ; + getCellsFamiliesNumber(MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ; + } + // EDGE in 3D + if (_ptrMesh->_connectivity->_constituent->_constituent != NULL) { + MEDArrayEdgeFamily = new (int*)[_ptrMesh->getNumberOfTypes(MED_EDGE)] ; + myTypes = _ptrMesh->getTypes(MED_EDGE); + for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++) + MEDArrayEdgeFamily[i] = new int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes[i])] ; + getCellsFamiliesNumber(MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent->_constituent) ; // we are in 3D ! + } + } } - // EDGE in 3D - if (_ptrMesh->_connectivity->_constituent->_constituent != NULL) { - _ptrMesh->_MEDArrayEdgeFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_constituent->_numberOfTypes] ; - getCellsFamiliesNumber(_ptrMesh->_MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ; // we are in 3D ! + else + { + // node + int NumberOfNodes = _ptrMesh->getNumberOfNodes() ; + MEDArrayNodeFamily = new int[ NumberOfNodes ]; + err = MED_FR::MEDfamGridLire (_medIdt, + const_cast (_ptrMesh->_name.c_str()), + MEDArrayNodeFamily, + NumberOfNodes, + MED_FR::MED_NOEUD); + + // what about cell face and edge ? } - } // Creation of the families int NumberOfFamilies = MEDnFam(_medIdt,const_cast (_meshName.c_str()),0,MED_FR::MED_FAMILLE) ; @@ -748,13 +1154,13 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() int * AttributesIdentifier = new int[NumberOfAttributes] ; int * AttributesValues = new int[NumberOfAttributes] ; string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ; - string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups,' ') ; - err = MEDfamInfo(_medIdt,const_cast (_meshName.c_str()), - i+1,const_cast (FamilyName.c_str()), - &FamilyIdentifier,AttributesIdentifier,AttributesValues, - const_cast (AttributesDescription.c_str()), - &NumberOfAttributes, - const_cast (GroupsNames.c_str()),&NumberOfGroups + string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups+1,' ') ; + err = MED_FR::MEDfamInfo(_medIdt,const_cast (_meshName.c_str()), + i+1,const_cast (FamilyName.c_str()), + &FamilyIdentifier,AttributesIdentifier,AttributesValues, + const_cast (AttributesDescription.c_str()), + &NumberOfAttributes, + const_cast (GroupsNames.c_str()),&NumberOfGroups ); //SCRUTE(GroupsNames); if (err != MED_VALID) @@ -763,27 +1169,60 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName, NumberOfAttributes,AttributesIdentifier, AttributesValues,AttributesDescription, - NumberOfGroups,GroupsNames) ; - switch (Family->getEntity()) { - case MED_EN::MED_NODE : - NodeFamilyVector.push_back(Family) ; - numberOfNodesFamilies++ ; - break ; - case MED_EN::MED_CELL : - CellFamilyVector.push_back(Family) ; - numberOfCellsFamilies++ ; - break ; - case MED_EN::MED_FACE : - FaceFamilyVector.push_back(Family) ; - numberOfFacesFamilies++ ; - break ; - case MED_EN::MED_EDGE : - EdgeFamilyVector.push_back(Family) ; - numberOfEdgesFamilies++ ; - break ; - } + NumberOfGroups,GroupsNames, + MEDArrayNodeFamily, + MEDArrayCellFamily, + MEDArrayFaceFamily, + MEDArrayEdgeFamily + ) ; + // All good ? + // if nothing found, delete Family + if (Family->getNumberOfTypes() == 0) { + INFOS(LOC<<"Nothing found for family "<getEntity()) { + case MED_EN::MED_NODE : + NodeFamilyVector.push_back(Family) ; + numberOfNodesFamilies++ ; + break ; + case MED_EN::MED_CELL : + CellFamilyVector.push_back(Family) ; + numberOfCellsFamilies++ ; + break ; + case MED_EN::MED_FACE : + FaceFamilyVector.push_back(Family) ; + numberOfFacesFamilies++ ; + break ; + case MED_EN::MED_EDGE : + EdgeFamilyVector.push_back(Family) ; + numberOfEdgesFamilies++ ; + break ; + } } + + delete [] AttributesIdentifier ; + delete [] AttributesValues ; + } + + if (MEDArrayNodeFamily != NULL) + delete[] MEDArrayNodeFamily ; + if (MEDArrayCellFamily != NULL) { + for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_CELL);i++) + delete[] MEDArrayCellFamily[i] ; + delete[] MEDArrayCellFamily ; } + if (MEDArrayFaceFamily != NULL) { + for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_FACE);i++) + delete[] MEDArrayFaceFamily[i] ; + delete[] MEDArrayFaceFamily ; + } + if (MEDArrayEdgeFamily != NULL) { + for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++) + delete[] MEDArrayEdgeFamily[i] ; + delete[] MEDArrayEdgeFamily ; + } + _ptrMesh->_numberOfNodesFamilies = numberOfNodesFamilies ; _ptrMesh->_numberOfCellsFamilies = numberOfCellsFamilies ; _ptrMesh->_numberOfFacesFamilies = numberOfFacesFamilies ; @@ -795,23 +1234,21 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() return MED_ERROR; } -int MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber() +int MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily) { const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber() : " ; BEGIN_OF(LOC); if (_status==MED_OPENED) { int err = 0 ; - int * tmp_NodesFamilies = new int[_ptrMesh->getNumberOfNodes()] ; err = MEDfamLire(_medIdt,(const_cast (_ptrMesh->_name.c_str())), - tmp_NodesFamilies, _ptrMesh->getNumberOfNodes(), - MED_NOEUD,(enum MED_FR::med_geometrie_element) MED_NONE); + MEDArrayNodeFamily, + _ptrMesh->getNumberOfNodes(), + MED_FR::MED_NOEUD,(enum MED_FR::med_geometrie_element) MED_NONE); if ( err != MED_VALID) { - delete[] tmp_NodesFamilies ; throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes() << "| nodes in mesh |" << _ptrMesh->_name.c_str() << "|" )); } - _ptrMesh->_MEDArrayNodeFamily = tmp_NodesFamilies ; END_OF(LOC); return MED_VALID; } @@ -827,10 +1264,8 @@ int MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int **MEDArrayFamily,CONNECT int i, err = 0 ; for (i=0;i_numberOfTypes;i++) { int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ; - int * fam = new int[NumberOfCell] ; - err=MEDfamLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), - fam,NumberOfCell, + MEDArrayFamily[i],NumberOfCell, (MED_FR::med_entite_maillage) Connectivity->_entity, (MED_FR::med_geometrie_element) Connectivity->_geometricTypes[i]); @@ -838,12 +1273,11 @@ int MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int **MEDArrayFamily,CONNECT if (err != MED_VALID) { MESSAGE(LOC<<"search face/edge family on cell !!!"); err=MEDfamLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), - fam,NumberOfCell, + MEDArrayFamily[i],NumberOfCell, MED_FR::MED_MAILLE, (MED_FR::med_geometrie_element) Connectivity->_geometricTypes[i]); } - MEDArrayFamily[i]=fam ; if (err != MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<_entity<<" and geometric type "<_geometricTypes[i])); @@ -907,50 +1341,94 @@ void MED_MESH_RDONLY_DRIVER::updateFamily() } -void MED_MESH_RDONLY_DRIVER::write( void ) const { INFOS("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");} +void MED_MESH_RDONLY_DRIVER::write( void ) const + throw (MEDEXCEPTION) +{ + throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !"); +} -/*--------------------- RDWR PART -------------------------------*/ +/*--------------------- WRONLY PART -------------------------------*/ -void MED_MESH_RDWR_DRIVER::write(void) const { MED_MESH_WRONLY_DRIVER::write(); } -void MED_MESH_RDWR_DRIVER::read (void) { MED_MESH_RDONLY_DRIVER::read(); } +MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER():MED_MESH_DRIVER() +{ +} + +MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, + MESH * ptrMesh): + MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY) +{ + MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created"); +} +MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver): + MED_MESH_DRIVER(driver) +{ +} -/*--------------------- WRONLY PART -------------------------------*/ -void MED_MESH_WRONLY_DRIVER::read (void) { INFOS("MED_MESH_WRONLY_DRIVER::write : Can't read with a WRONLY driver !");} +MED_MESH_WRONLY_DRIVER::~MED_MESH_WRONLY_DRIVER() +{ + //MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed"); +} + +GENDRIVER * MED_MESH_WRONLY_DRIVER::copy(void) const +{ + return new MED_MESH_WRONLY_DRIVER(*this); +} + +void MED_MESH_WRONLY_DRIVER::read (void) + throw (MEDEXCEPTION) +{ + throw MEDEXCEPTION("MED_MESH_WRONLY_DRIVER::read : Can't read with a WRONLY driver !"); +} -void MED_MESH_WRONLY_DRIVER::write(void) const { +void MED_MESH_WRONLY_DRIVER::write(void) const + throw (MEDEXCEPTION) +{ const char * LOC = "void MED_MESH_WRONLY_DRIVER::write(void) const : "; BEGIN_OF(LOC); // we must first create mesh !! MESSAGE(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|"); - if (writeCoordinates()!=MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()" )) ; + if (_status!=MED_OPENED) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "File "<<_fileName<<" is not open. Open it before write !")); - if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)" )) ; - if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)" )) ; - if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)" )) ; + if (_ptrMesh->getIsAGrid()) + { + if ( writeGRID() != MED_VALID ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeGRID()" )) ; + } + else + { + if (writeCoordinates()!=MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()" )) ; + + if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)" )) ; + if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)" )) ; + if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)" )) ; + } if (writeFamilyNumbers() !=MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()" )) ; - + + // well we must first write zero family : if (_status==MED_OPENED) { int err ; // test if the family already exists (HDF trick waiting a MED evolution to be replaced) string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_0/"; - SCRUTE("|"< (dataGroupFam.c_str()) ) < MED_VALID ) { SCRUTE(err); - err = MEDfamCr( _medIdt, const_cast ( _meshName.c_str() ), - "FAMILLE_0", 0, - (int*)NULL, (int*)NULL, (char*)NULL, 0, - (char*)NULL, 0); + err = MED_FR::MEDfamCr( _medIdt, + const_cast ( _meshName.c_str() ), + "FAMILLE_0", 0, + (int*)NULL, (int*)NULL, (char*)NULL, 0, + (char*)NULL, 0); if ( err != MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_0| with identifier |0| groups names || and attributes descriptions ||")) ; @@ -979,79 +1457,231 @@ void MED_MESH_WRONLY_DRIVER::write(void) const { END_OF(LOC); } +//======================================================================= +//function : writeGRID +//purpose : +//======================================================================= + +int MED_MESH_WRONLY_DRIVER::writeGRID() const +{ + const char * LOC = "MED_MESH_WRONLY_DRIVER::writeGRID() : " ; + BEGIN_OF(LOC); + + if (_status!=MED_OPENED) + { + MESSAGE (LOC<<" Not open !!!"); + return MED_ERROR; + } + GRID * ptrGrid = (GRID*) _ptrMesh; + + MED_FR::med_err err = MED_ERROR; + MED_FR::med_repere rep; + string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM,' '); + string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM,' '); + + // Test if the mesh <_meshName> already exists + // If it doesn't exists create it + // If it already exists verify if its dimension is the same as <_ptrMesh->_spaceDimension> + // rem : <_meshName> is the driver meshName not _meshName> + int dim = MED_FR::MEDdimLire(_medIdt, const_cast (_meshName.c_str()) ); + if (dim < MED_VALID) + { + err = MEDgridCr(_medIdt, + const_cast (_meshName.c_str()), + _ptrMesh->_spaceDimension, + (MED_FR::med_grid_type) ptrGrid->getGridType()); + if (err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Grid")); + else + MESSAGE(LOC<<"Grid "<<_meshName<<" created in file "<<_fileName<<" !"); + } + else if (dim != _ptrMesh->_spaceDimension) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() << + "| already exists in file |" << _fileName << + "| with dimension |" << dim << + "| but the dimension of the mesh we want to write is |" + << _ptrMesh->_spaceDimension <<"|" )) ; + + // Recompose the <_spaceDimension> strings in 1 string + int lengthString ; + string valueString ; + for (int i=0;i<_ptrMesh->_spaceDimension;i++) { + SCRUTE(i); + valueString = _ptrMesh->_coordinate->_coordinateName[i] ; + lengthString = (MED_TAILLE_PNOM_coordinate->_coordinateUnit[i]; + lengthString = (MED_TAILLE_PNOM_coordinate->_coordinateSystem; + if (coordinateSystem == "CARTESIAN") + rep = MED_FR::MED_CART; + else if ( coordinateSystem == "CYLINDRICAL") + rep = MED_FR::MED_CYL; + else if ( coordinateSystem == "SPHERICAL" ) + rep = MED_FR::MED_SPHER; + else + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() << + "| doesn't have a valid coordinate system : |" + << _ptrMesh->_coordinate->_coordinateSystem + << "|" )) ; + + int ArrayLen[] = { ptrGrid->_iArrayLength, + ptrGrid->_jArrayLength, + ptrGrid->_kArrayLength }; + + // Write node coordinates for MED_BODY_FITTED grid + if (ptrGrid->getGridType() == MED_EN::MED_BODY_FITTED) + { + + // Write Coordinates and families + double * coo = const_cast + (_ptrMesh->_coordinate->getCoordinates(MED_EN::MED_FULL_INTERLACE)); + + // Write unused families + int * MEDArrayNodeFamily = new int[_ptrMesh->_numberOfNodes] ; + + err = MEDbodyFittedEcr (_medIdt, + const_cast (_ptrMesh->_name.c_str()), + _ptrMesh->_spaceDimension, + coo, + ArrayLen, + MED_FR::MED_FULL_INTERLACE, + rep, + const_cast (tmp_name.c_str()), + const_cast (tmp_unit.c_str()), + MEDArrayNodeFamily, + _ptrMesh->_numberOfNodes, + MED_FR::MED_REMP); + delete[] MEDArrayNodeFamily; + + if (err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in MEDbodyFittedEcr()")); + + } + else + { + // Write Arrays of Cartesian or Polar Grid + + double * Array[] = { ptrGrid->_iArray, + ptrGrid->_jArray, + ptrGrid->_kArray }; + int idim; + for (idim = 0; idim < _ptrMesh->_spaceDimension; ++idim) + { + err = MEDgridEcr (_medIdt, + const_cast (_ptrMesh->_name.c_str()), + _ptrMesh->_spaceDimension, + Array [idim], + ArrayLen [idim], + idim, + MED_FR::MED_FULL_INTERLACE, + rep, + const_cast (tmp_name.c_str()), + const_cast (tmp_unit.c_str()), + MED_FR::MED_REMP); + if (err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read grid coordinates for " + << idim << "-th dimention")); + } + +// err = MEDfamGridEcr(_medIdt, +// const_cast (_ptrMesh->_name.c_str()), +// _ptrMesh->_MEDArrayNodeFamily, +// _ptrMesh->_numberOfNodes, +// MED_FR::MED_REMP, +// MED_FR::MED_NOEUD); + if (err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in MEDfamGridEcr()")); + + } // end Write Cartesian or Polar Grid + + END_OF(LOC); + return MED_VALID; +} + +//======================================================================= +//function : writeCoordinates +//purpose : +//======================================================================= int MED_MESH_WRONLY_DRIVER::writeCoordinates() const { const char * LOC = "int MED_MESH_WRONLY_DRIVER::writeCoordinates() const : "; BEGIN_OF(LOC); - if (_status==MED_OPENED) { - MED_FR::med_err err = MED_ERROR; - MED_FR::med_repere rep; - string tmp_name,tmp_unit; + MED_FR::med_err err = MED_ERROR; + MED_FR::med_repere rep; + string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM,' '); + string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM,' '); - // Recompose the <_spaceDimension> strings in 1 string - for (int i=0;i<_ptrMesh->_spaceDimension;i++) { - tmp_name += _ptrMesh->_coordinate->_coordinateName[i]; - tmp_unit += _ptrMesh->_coordinate->_coordinateUnit[i]; - - } + // Recompose the <_spaceDimension> strings in 1 string + int lengthString ; + string valueString ; + for (int i=0;i<_ptrMesh->_spaceDimension;i++) { + valueString = _ptrMesh->_coordinate->_coordinateName[i] ; + lengthString = (MED_TAILLE_PNOM_coordinate->_coordinateUnit[i]; + lengthString = (MED_TAILLE_PNOM already exists - // If it doesn't exists create it - // If it already exists verify if its dimension is the same as <_ptrMesh->_spaceDimension> - // rem : <_meshName> is the driver meshName not _meshName> - int dim = MEDdimLire(_medIdt, const_cast (_meshName.c_str()) ); - if (dim < MED_VALID) - if (MEDmaaCr(_medIdt,const_cast (_meshName.c_str()),_ptrMesh->_spaceDimension) != 0 ) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|")); - else - { - MESSAGE(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !"); - } - else if (dim != _ptrMesh->_spaceDimension) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| already exists in file |" << _fileName - << "| with dimension |" << dim << "| but the dimension of the mesh we want to write is |" - << _ptrMesh->_spaceDimension <<"|" )) ; + // Test if the mesh <_meshName> already exists + // If it doesn't exists create it + // If it already exists verify if its dimension is the same as <_ptrMesh->_spaceDimension> + // rem : <_meshName> is the driver meshName not _meshName> + int dim = MED_FR::MEDdimLire(_medIdt, const_cast (_meshName.c_str()) ); + if (dim < MED_VALID) + if (MED_FR::MEDmaaCr(_medIdt,const_cast (_meshName.c_str()),_ptrMesh->_spaceDimension) != 0 ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|")); + else + { + MESSAGE(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !"); + } + else if (dim != _ptrMesh->_spaceDimension) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| already exists in file |" << _fileName + << "| with dimension |" << dim << "| but the dimension of the mesh we want to write is |" + << _ptrMesh->_spaceDimension <<"|" )) ; - // Pourquoi le stocker sous forme de chaîne ? - const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem; - if (coordinateSystem == "CARTESIAN") - rep = MED_FR::MED_CART; - else if ( coordinateSystem == "CYLINDRICAL") - rep = MED_FR::MED_CYL; - else if ( coordinateSystem == "SPHERICAL" ) - rep = MED_FR::MED_SPHER; - else - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |" - << _ptrMesh->_coordinate->_coordinateSystem - << "|" )) ; + // Pourquoi le stocker sous forme de chaîne ? + const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem; + if (coordinateSystem == "CARTESIAN") + rep = MED_FR::MED_CART; + else if ( coordinateSystem == "CYLINDRICAL") + rep = MED_FR::MED_CYL; + else if ( coordinateSystem == "SPHERICAL" ) + rep = MED_FR::MED_SPHER; + else + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |" + << _ptrMesh->_coordinate->_coordinateSystem + << "|" )) ; - err = MEDcoordEcr(_medIdt, const_cast (_meshName.c_str()), - _ptrMesh->_spaceDimension, - const_cast ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), - MED_FR::MED_FULL_INTERLACE, - _ptrMesh->_numberOfNodes, // _ptrMesh->_coordinate->_numberOfNodes - MED_FR::MED_REMP, - rep, - const_cast (tmp_name.c_str()), - const_cast (tmp_unit.c_str()) - ); - - if (err<0) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName - << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" - << " with units names |" << tmp_name - << "| and units |" << tmp_unit - << " |")) ; + err = MEDcoordEcr(_medIdt, const_cast (_meshName.c_str()), + _ptrMesh->_spaceDimension, + //const_cast ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), + const_cast ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), + MED_FR::MED_FULL_INTERLACE, + _ptrMesh->_numberOfNodes, // _ptrMesh->_coordinate->_numberOfNodes + MED_FR::MED_REMP, + rep, + const_cast (tmp_name.c_str()), + const_cast (tmp_unit.c_str()) + ); + + if (err<0) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName + << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" + << " with units names |" << tmp_name + << "| and units |" << tmp_unit + << " |")) ; - END_OF(LOC); + END_OF(LOC); - return MED_VALID; - } - - MESSAGE (LOC<<" Not open !!!"); - return MED_ERROR; + return MED_VALID; } @@ -1064,81 +1694,83 @@ int MED_MESH_WRONLY_DRIVER::writeConnectivities(medEntityMesh entity) const { MED_FR::med_err err; - if (_status==MED_OPENED) { - - // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB ! + // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB ! + // PG : IMPOSSIBLE : LA METHODE EST PRIVEE ! // A FAIRE : A tester surtout dans les methodes de MESH. // if ( _ptrMesh->_connectivity == (CONNECTIVITY *) MED_INVALID ) - if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL ) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ; + if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ; - if ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) { + if ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) { - int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; - medGeometryElement * types = _ptrMesh->getTypes (entity) ; + int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; + const medGeometryElement * types = _ptrMesh->getTypes (entity) ; - for (int i=0; igetNumberOfElements (entity,types[i]); - int * connectivity = _ptrMesh->getConnectivity (MED_EN::MED_FULL_INTERLACE, - MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ?? + int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]); + const int * connectivity = _ptrMesh->getConnectivity (MED_EN::MED_FULL_INTERLACE, + MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ?? - // Pour l'instant la class utilise le multi..... - int multi = 0 ; - if (entity==MED_EN::MED_CELL) - if ( (types[i]/ 100) < _ptrMesh->_spaceDimension) - multi=1 ; - int numberOfNodes = types[i]%100 ; - int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)]; - for (int j=0 ; j0) - connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0; - } - err = MEDconnEcr( _medIdt, const_cast ( _meshName.c_str()), _ptrMesh->_spaceDimension, - connectivityArray, MED_FR::MED_FULL_INTERLACE , numberOfElements, - MED_FR::MED_REMP, - (MED_FR::med_entite_maillage ) entity, - (MED_FR::med_geometrie_element) types[i], MED_NOD ); - delete[] connectivityArray ; - - if (err<0) // ETENDRE LES EXPLICATIONS - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName - << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" - )) ; + // Pour l'instant la class utilise le multi..... + int multi = 0 ; + if (entity==MED_EN::MED_CELL) + if ( (types[i]/ 100) < _ptrMesh->_spaceDimension) + multi=1 ; + int numberOfNodes = types[i]%100 ; + int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)]; + for (int j=0 ; j0) + connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0; } + err = MEDconnEcr( _medIdt, const_cast ( _meshName.c_str()), _ptrMesh->_spaceDimension, + connectivityArray, MED_FR::MED_FULL_INTERLACE , numberOfElements, + MED_FR::MED_REMP, + (MED_FR::med_entite_maillage ) entity, + (MED_FR::med_geometrie_element) types[i], MED_FR::MED_NOD ); + delete[] connectivityArray ; + + if (err<0) // ETENDRE LES EXPLICATIONS + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName + << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" + )) ; } - // Connctivity descending : - if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) { + } + // Connctivity descending : + if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) { - int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; - medGeometryElement * types = _ptrMesh->getTypes (entity) ; + int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; + const medGeometryElement * types = _ptrMesh->getTypes (entity) ; - for (int i=0; igetNumberOfElements (entity,types[i]); - int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); + int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]); + const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); - // Pour l'instant la class utilise le multi..... - err = MEDconnEcr( _medIdt, const_cast ( _meshName.c_str()), _ptrMesh->_spaceDimension, - connectivity, MED_FR::MED_FULL_INTERLACE , numberOfElements, - MED_FR::MED_REMP, - (MED_FR::med_entite_maillage ) entity, - (MED_FR::med_geometrie_element) types[i], MED_DESC ); + // Pour l'instant la class utilise le multi..... + err = MED_FR::MEDconnEcr( _medIdt, + const_cast ( _meshName.c_str()), + _ptrMesh->_spaceDimension, + const_cast (connectivity), + MED_FR::MED_FULL_INTERLACE, + numberOfElements, + MED_FR::MED_REMP, + (MED_FR::med_entite_maillage ) entity, + (MED_FR::med_geometrie_element) types[i], + MED_FR::MED_DESC ); - if (err<0) // ETENDRE LES EXPLICATIONS - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName - << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" - )) ; + if (err<0) // ETENDRE LES EXPLICATIONS + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName + << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" + )) ; - } } - END_OF(LOC); - return MED_VALID; } - return MED_ERROR; + END_OF(LOC); + return MED_VALID; } int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const { @@ -1148,135 +1780,287 @@ int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const { MED_FR::med_err err; - if (_status==MED_OPENED) { + // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH + + { // Node related block + + // We build the array from the families list objects : + int NumberOfNodes = _ptrMesh->getNumberOfNodes() ; + int * MEDArrayNodeFamily = new int[NumberOfNodes] ; + // family 0 by default + for (int i=0; i myFamilies = _ptrMesh->getFamilies(MED_NODE); + vector * myFamilies = &_ptrMesh->_familyNode; + int NumberOfNodesFamilies = myFamilies->size() ; + //bool ToDestroy = false; + if (0 == NumberOfNodesFamilies) { + //ToDestroy = true ; + vector myGroups = _ptrMesh->getGroups(MED_NODE); + int NumberOfGroups = myGroups.size() ; + // build families from groups + for (int i=0; isetIdentifier(i+1); + myFamilies->push_back(myFamily); + } + NumberOfNodesFamilies=myFamilies->size() ; + } + for (int i=0 ; igetName()); + int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ; + int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ; + if ((*myFamilies)[i]->isOnAllElements()) + for (int j=0; jgetNumber(MED_ALL_ELEMENTS) ; + for (int j=0; jgetIsAGrid() ) + err = MEDfamEcr(_medIdt, const_cast ( _meshName.c_str() ), + MEDArrayNodeFamily, NumberOfNodes,MED_FR::MED_REMP , + MED_FR::MED_NOEUD, + (enum MED_FR::med_geometrie_element) MED_NONE); + else + err = MEDfamGridEcr(_medIdt, + const_cast (_ptrMesh->_name.c_str()), + MEDArrayNodeFamily, + NumberOfNodes, + MED_FR::MED_REMP, + MED_FR::MED_NOEUD); - // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH - err = MEDfamEcr(_medIdt, const_cast ( _meshName.c_str() ), - _ptrMesh->_MEDArrayNodeFamily, _ptrMesh->getNumberOfNodes(),MED_FR::MED_REMP , - MED_NOEUD,(enum MED_FR::med_geometrie_element) MED_NONE); if ( err != MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< _ptrMesh->getNumberOfNodes() - << "| nodes in mesh |" - << _ptrMesh->_name.c_str() << "|" )); + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< NumberOfNodes + << "| nodes in mesh |" + << _ptrMesh->_name.c_str() << "|" )); + delete[] MEDArrayNodeFamily; + //if (true == ToDestroy) + // for (int i=0; i_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH + if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { + int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; + const medGeometryElement * types = _ptrMesh->getTypes (entity) ; + + // We build the array from the families list objects : + int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS); + int * MEDArrayFamily = new int[NumberOfElements] ; + // family 0 by default + for (int i=0; i myFamilies = _ptrMesh->getFamilies(entity); + vector * myFamilies = &_ptrMesh->_familyCell ; + int NumberOfFamilies = myFamilies->size() ; + //bool ToDestroy = false; + if (0 == NumberOfFamilies) { + //ToDestroy = true ; + vector myGroups = _ptrMesh->getGroups(entity); + int NumberOfGroups = myGroups.size() ; + // build families from groups + for (int i=0; igetName() ); + SUPPORT * mySupport = myGroups[i] ; + FAMILY* myFamily = new FAMILY(*mySupport); + myFamily->setIdentifier(-i-1); + myFamilies->push_back(myFamily); + } + NumberOfFamilies=myFamilies->size() ; + } + for (int i=0 ; igetIdentifier() ; + int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ; + if ((*myFamilies)[i]->isOnAllElements()) + for (int ii=0; iigetNumber(MED_ALL_ELEMENTS) ; + for (int ii=0; ii_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH - if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { + const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ; - int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; - medGeometryElement * types = _ptrMesh->getTypes (entity) ; - - for (int i=0; i ( _meshName.c_str() ), - _ptrMesh->_MEDArrayCellFamily[i], _ptrMesh->getNumberOfElements(entity, types[i]), - MED_FR::MED_REMP , - (MED_FR::med_entite_maillage) entity, - (MED_FR::med_geometrie_element) types[i]); - - if ( err != MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i]) - << "| cells of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |" - << _ptrMesh->_name.c_str() << "|" )); - } + err = MEDfamEcr(_medIdt, const_cast ( _meshName.c_str() ), + MEDArrayFamily+typeCount[i]-1,typeCount[i+1]-typeCount[i], + MED_FR::MED_REMP , + (MED_FR::med_entite_maillage) entity, + (MED_FR::med_geometrie_element) types[i] +); + MESSAGE("OK "<getNumberOfElements(entity, types[i]) + << "| cells of geometric type |" << MED_FR::geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |" + << _ptrMesh->_name.c_str() << "|" )); } + delete[] MEDArrayFamily ; + //if (true == ToDestroy) { + // int NumberOfFamilies = myFamilies->size(); + // for (int i=0; i_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH - if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { + { // FACE RELATED BLOCK + medEntityMesh entity=MED_EN::MED_FACE; + // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH + if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { - int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; - medGeometryElement * types = _ptrMesh->getTypes (entity) ; + int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; + const medGeometryElement * types = _ptrMesh->getTypes (entity) ; + SCRUTE(numberOfTypes); - int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ; - int * familyArray = new int[numberOfElements] ; - for (int i=0;igetNumberOfFamilies(entity) ; - vector myFamilies = _ptrMesh->getFamilies(entity) ; - for (int i=0;igetIdentifier() ; - int numberOfFamilyElements = myFamilies[i]->getNumberOfElements(MED_ALL_ELEMENTS) ; - int * myFamilyElements = myFamilies[i]->getNumber(MED_ALL_ELEMENTS) ; + int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ; + int * familyArray = new int[numberOfElements] ; + for (int i=0;igetNumberOfFamilies(entity) ; + //vector myFamilies = _ptrMesh->getFamilies(entity) ; + vector * myFamilies = &_ptrMesh->_familyFace ; + //bool ToDestroy = false; + if (0 == numberOfFamilies) { + //ToDestroy = true ; + vector myGroups = _ptrMesh->getGroups(entity); + int NumberOfGroups = myGroups.size() ; + // build families from groups + for (int i=0; igetName() ); + SUPPORT * mySupport = myGroups[i] ; + FAMILY* myFamily = new FAMILY(*mySupport); + myFamily->setIdentifier(-i-1000); + myFamilies->push_back(myFamily); + } + numberOfFamilies=myFamilies->size() ; + } + for (int i=0;igetIdentifier() ; + int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ; + if ((*myFamilies)[i]->isOnAllElements()) + for (int ii=0; iigetNumber(MED_ALL_ELEMENTS) ; for (int ii=0;iigetGlobalNumberingIndex(entity) ; - - for (int i=0; igetGlobalNumberingIndex(entity) ; - int typeNumberOfElements = typeCount[i+1] - typeCount[i] ; - err = MEDfamEcr(_medIdt, const_cast ( _meshName.c_str() ), - familyArray+typeCount[i]-1, typeNumberOfElements, - MED_FR::MED_REMP , - (MED_FR::med_entite_maillage) entity, - (MED_FR::med_geometrie_element) types[i]); + for (int i=0; igetNumberOfElements(entity, types[i]) - << "| faces of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |" - << _ptrMesh->_name.c_str() << "|" )); - } - delete[] familyArray ; + int typeNumberOfElements = typeCount[i+1] - typeCount[i] ; + err = MEDfamEcr(_medIdt, const_cast ( _meshName.c_str() ), + familyArray+typeCount[i]-1, typeNumberOfElements, + MED_FR::MED_REMP , + (MED_FR::med_entite_maillage) entity, + (MED_FR::med_geometrie_element) types[i]); + + if ( err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i]) + << "| faces of geometric type |" << MED_FR::geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |" + << _ptrMesh->_name.c_str() << "|" )); } + delete[] familyArray ; + //if (true == ToDestroy) { + // int NumberOfFamilies = myFamilies->size(); + // for (int i=0; i_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH - if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { + { // EDGE RELATED BLOCK + //medEntityMesh entity=MED_EN::MED_FACE; + medEntityMesh entity=MED_EN::MED_EDGE; + // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH + if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { - int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; - medGeometryElement * types = _ptrMesh->getTypes (entity) ; + int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; + const medGeometryElement * types = _ptrMesh->getTypes (entity) ; - int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ; - int * familyArray = new int[numberOfElements] ; - for (int i=0;igetNumberOfFamilies(entity) ; - vector myFamilies = _ptrMesh->getFamilies(entity) ; - for (int i=0;igetIdentifier() ; - int numberOfFamilyElements = myFamilies[i]->getNumberOfElements(MED_ALL_ELEMENTS) ; - int * myFamilyElements = myFamilies[i]->getNumber(MED_ALL_ELEMENTS) ; + int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ; + int * familyArray = new int[numberOfElements] ; + for (int i=0;igetNumberOfFamilies(entity) ; + //vector myFamilies = _ptrMesh->getFamilies(entity) ; + vector * myFamilies = &_ptrMesh->_familyEdge ; + //bool ToDestroy = false; + if (0 == numberOfFamilies) { + //ToDestroy = true ; + vector myGroups = _ptrMesh->getGroups(entity); + int NumberOfGroups = myGroups.size() ; + // build families from groups + for (int i=0; igetName() ); + SUPPORT * mySupport = myGroups[i] ; + FAMILY* myFamily = new FAMILY(*mySupport); + myFamily->setIdentifier(-i-2000); + myFamilies->push_back(myFamily); + } + numberOfFamilies=myFamilies->size() ; + } + for (int i=0;igetIdentifier() ; + int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ; + if ((*myFamilies)[i]->isOnAllElements()) + for (int ii=0; iigetNumber(MED_ALL_ELEMENTS) ; for (int ii=0;iigetGlobalNumberingIndex(entity) ; + const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ; - for (int i=0; i ( _meshName.c_str() ), - familyArray+typeCount[i]-1, typeNumberOfElements, - MED_FR::MED_REMP , - (MED_FR::med_entite_maillage) entity, - (MED_FR::med_geometrie_element) types[i]); + int typeNumberOfElements = typeCount[i+1] - typeCount[i] ; + err = MEDfamEcr(_medIdt, const_cast ( _meshName.c_str() ), + familyArray+typeCount[i]-1, typeNumberOfElements, + MED_FR::MED_REMP , + (MED_FR::med_entite_maillage) entity, + (MED_FR::med_geometrie_element) types[i]); - if ( err != MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i]) - << "| edges of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |" - << _ptrMesh->_name.c_str() << "|" )); - } + if ( err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i]) + << "| edges of geometric type |" << MED_FR::geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |" + << _ptrMesh->_name.c_str() << "|" )); } + delete[] familyArray ; + //if (true == ToDestroy) { + // int NumberOfFamilies = myFamilies->size(); + // for (int i=0; i & families ) const { const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilies(vector families) const : "; @@ -1284,91 +2068,129 @@ int MED_MESH_WRONLY_DRIVER::writeFamilies(vector & families ) const { MED_FR::med_err err; - if (_status==MED_OPENED) { - - MESSAGE(LOC<<" families.size() :"<getNumberOfAttributes (); - string attributesDescriptions = ""; + int numberOfAttributes = families[i]->getNumberOfAttributes (); + string attributesDescriptions = ""; - // Recompose the attributes descriptions arg for MED - for (int j=0; j < numberOfAttributes; j++) { + // Recompose the attributes descriptions arg for MED + for (int j=0; j < numberOfAttributes; j++) { - string attributeDescription = families[i]->getAttributeDescription(j+1); + string attributeDescription = families[i]->getAttributeDescription(j+1); - if ( attributeDescription.size() > MED_TAILLE_DESC ) - throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" << j+1 << "| of the family |" << families[i]->getName() - << "| with identifier |" << families[i]->getIdentifier() << "| is |" - << attributeDescription.size() <<"| and is more than |" << MED_TAILLE_DESC << "|")) ; + if ( attributeDescription.size() > MED_TAILLE_DESC ) + throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" << j+1 << "| of the family |" << families[i]->getName() + << "| with identifier |" << families[i]->getIdentifier() << "| is |" + << attributeDescription.size() <<"| and is more than |" << MED_TAILLE_DESC << "|")) ; - attributesDescriptions += attributeDescription; - } + attributesDescriptions += attributeDescription; + } - int numberOfGroups = families[i]->getNumberOfGroups(); - string groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0') ; - // Recompose the groups names arg for MED - for (int j=0; j < numberOfGroups; j++) { + int numberOfGroups = families[i]->getNumberOfGroups(); + string groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0') ; + // Recompose the groups names arg for MED + for (int j=0; j < numberOfGroups; j++) { - string groupName = families[i]->getGroupName(j+1); + string groupName = families[i]->getGroupName(j+1); - if ( groupName.size() > MED_TAILLE_LNOM ) - throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name n° |" << j+1 << "| of the family |" << families[i]->getName() - << "| with identifier |" << families[i]->getIdentifier() << "| is |" - << groupName.size() <<"| and is more than |" << MED_TAILLE_LNOM << "|")) ; + if ( groupName.size() > MED_TAILLE_LNOM ) + throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name n° |" << j+1 << "| of the family |" << families[i]->getName() + << "| with identifier |" << families[i]->getIdentifier() << "| is |" + << groupName.size() <<"| and is more than |" << MED_TAILLE_LNOM << "|")) ; - int length = min(MED_TAILLE_LNOM,(int)groupName.size()); - groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length); + int length = min(MED_TAILLE_LNOM,(int)groupName.size()); + groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length); - } - - // test if the family already exists (HDF trick waiting a MED evolution to be replaced) - string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/"+families[i]->getName()+"/"; - SCRUTE("|"< (dataGroupFam.c_str()) ) < MED_VALID ) { - SCRUTE(err); - - MESSAGE(LOC<<"families[i]->getName().c_str() : "<getName().c_str()); - MESSAGE(LOC<<"_meshName.c_str() : "<<_meshName.c_str()); - MESSAGE(LOC<<"families[i]->getIdentifier() : "<getIdentifier()); - MESSAGE(LOC<<"families[i]->getAttributesIdentifiers() : "<getAttributesIdentifiers()[0]); - MESSAGE(LOC<<"families[i]->getAttributesValues() : "<getAttributesValues()[0]); - MESSAGE(LOC<<"attributesDescriptions.c_str() : "< ( _meshName.c_str() ), - const_cast ( families[i]->getName().c_str() ), - families[i]->getIdentifier(), - families[i]->getAttributesIdentifiers(), - families[i]->getAttributesValues(), - const_cast (attributesDescriptions.c_str()), - numberOfAttributes, - const_cast (groupsNames.c_str()), - numberOfGroups); - SCRUTE(err); - if ( err != MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName() - << "| with identifier |" << families[i]->getIdentifier() << "| groups names |" - << groupsNames <<"| and attributes descriptions |" << attributesDescriptions << "|")) ; - } - else - _MEDdatagroupFermer(_medIdt); + } + // test if the family already exists (HDF trick waiting a MED evolution to be replaced) + string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/"+families[i]->getName()+"/"; + SCRUTE("|"< (dataGroupFam.c_str()) ) < MED_VALID ) { + SCRUTE(err); + MESSAGE(LOC<<"families[i]->getName().c_str() : "<getName().c_str()); + MESSAGE(LOC<<"_meshName.c_str() : "<<_meshName.c_str()); + MESSAGE(LOC<<"families[i]->getIdentifier() : "<getIdentifier()); + MESSAGE(LOC<<"numberOfAttributes : "<getAttributesIdentifiers() : "<getAttributesIdentifiers()[0]); + //MESSAGE(LOC<<"families[i]->getAttributesValues() : "<getAttributesValues()[0]); + MESSAGE(LOC<<"attributesDescriptions.c_str() : "< ( _meshName.c_str() ), + const_cast ( families[i]->getName().c_str() ), + families[i]->getIdentifier(), + families[i]->getAttributesIdentifiers(), + families[i]->getAttributesValues(), + const_cast (attributesDescriptions.c_str()), + numberOfAttributes, + const_cast (groupsNames.c_str()), + numberOfGroups); + SCRUTE(err); + if ( err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName() + << "| with identifier |" << families[i]->getIdentifier() << "| groups names |" + << groupsNames <<"| and attributes descriptions |" << attributesDescriptions << "|")) ; } + else + _MEDdatagroupFermer(_medIdt); + - END_OF(LOC); - - return MED_VALID; } - return MED_ERROR; + + END_OF(LOC); + + return MED_VALID; } // A FAIRE POUR LES NOEUDS ET LES ELEMENTS ret = MEDfamEcr( + + + +/*--------------------- RDWR PART -------------------------------*/ + +MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER():MED_MESH_DRIVER() +{ +} + +MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, + MESH * ptrMesh): + MED_MESH_DRIVER(fileName,ptrMesh,MED_RDWR) +{ + MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been created"); +} + +MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const MED_MESH_RDWR_DRIVER & driver): + MED_MESH_RDONLY_DRIVER::MED_MESH_DRIVER(driver) +{ +} + +MED_MESH_RDWR_DRIVER::~MED_MESH_RDWR_DRIVER() { + //MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed"); +} + +GENDRIVER * MED_MESH_RDWR_DRIVER::copy(void) const +{ + return new MED_MESH_RDWR_DRIVER(*this); +} + +void MED_MESH_RDWR_DRIVER::write(void) const + throw (MEDEXCEPTION) +{ + MED_MESH_WRONLY_DRIVER::write(); +} +void MED_MESH_RDWR_DRIVER::read (void) + throw (MEDEXCEPTION) +{ + MED_MESH_RDONLY_DRIVER::read(); +} + diff --git a/src/MEDMEM/duplicateMED.cxx b/src/MEDMEM/duplicateMED.cxx index b20b21118..ccbb810af 100644 --- a/src/MEDMEM/duplicateMED.cxx +++ b/src/MEDMEM/duplicateMED.cxx @@ -1,16 +1,34 @@ +// MED MEDMEM : MED files in memory +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : duplicateMED.cxx +// Module : MED + using namespace std; #include -#include #include "MEDMEM_Exception.hxx" -#include "MEDMEM_define.hxx" - #include "MEDMEM_Med.hxx" -#include "MEDMEM_Mesh.hxx" -#include "MEDMEM_Family.hxx" -#include "MEDMEM_Support.hxx" -#include "MEDMEM_Field.hxx" - void usage(char * name) { @@ -22,107 +40,23 @@ void usage(char * name) int main (int argc, char ** argv) { if (argc != 3) usage(argv[0]); - + string filenameIN = argv[1] ; string filenameOUT = argv[2] ; - MED * myMed = new MED() ; - MED_MED_DRIVER myMedDriver(filenameIN,myMed) ; - - // we read all meshes and fields in filenameIN try { - int read ; - myMedDriver.open(); - myMedDriver.readFileStruct(); - myMedDriver.close(); - - // read all mesh - MESSAGE("Read all meshes :") ; - int NumberOfMeshes = myMed->getNumberOfMeshes() ; - MESSAGE("Number of meshes : "< MeshName = myMed->getMeshNames() ; - map _meshes ; - for (int i=0; igetMesh(MeshName[i]) ; - _meshes[MeshName[i]]->read(); - MESSAGE(" - Mesh "<updateSupport() ; - - // read all field - MESSAGE("Read all fields :") ; - int NumberOfFields = myMed->getNumberOfFields() ; - MESSAGE("Number of fields : "< FieldName = myMed->getFieldNames() ; - map _fields ; - for (int i=0; i FieldIteration = myMed->getFieldIteration(FieldName[i]) ; - MESSAGE(" - Field "<getField(FieldName[i],FieldIteration[j].dt,FieldIteration[j].it) ; - - med_type_champ type = myField->getValueType() ; - switch (type) { - case MED_FR::MED_INT32: { - // if (type == MED_FR::MED_INT32) { - MESSAGE(" * Field named "<<((FIELD*)myField)->getName()); - ((FIELD*)myField)->read() ; - MESSAGE(" * Iteration "< myFieldDriver(filenameOUT,(FIELD*)myField); - myFieldDriver.setFieldName(FieldName[i]); - myFieldDriver.open() ; - myFieldDriver.write() ; - myFieldDriver.close() ; - break ; - } - // else - case MED_FR::MED_REEL64: { - // if (type == MED_FR::MED_REEL64) { - FIELD* myField2 = (FIELD*)myField ; - MESSAGE(" * Field named "<getName()); - myField2->read() ; - MESSAGE(" * Iteration "< myFieldDriver(filenameOUT,myField2); - myFieldDriver.setFieldName(FieldName[i]); - myFieldDriver.open() ; - myFieldDriver.write() ; - myFieldDriver.close() ; - break ; - } - // else { - default: { - MESSAGE(" * Iteration "<