From f67b742b82cccd18591e4d03538617a16e7d057b Mon Sep 17 00:00:00 2001 From: nadir Date: Fri, 29 Aug 2003 12:26:15 +0000 Subject: [PATCH] update from the MedMemory V1.0.1 --- src/MEDMEM/MEDMEM_Array.hxx | 51 +- src/MEDMEM/MEDMEM_CellModel.cxx | 26 - src/MEDMEM/MEDMEM_CellModel.hxx | 26 - src/MEDMEM/MEDMEM_Connectivity.cxx | 990 +++++++++----- src/MEDMEM/MEDMEM_Connectivity.hxx | 116 +- src/MEDMEM/MEDMEM_Coordinate.cxx | 48 +- src/MEDMEM/MEDMEM_Coordinate.hxx | 38 +- src/MEDMEM/MEDMEM_DriverTools.cxx | 423 ++++++ src/MEDMEM/MEDMEM_DriverTools.hxx | 91 ++ src/MEDMEM/MEDMEM_DriversDef.cxx | 85 +- src/MEDMEM/MEDMEM_DriversDef.hxx | 30 +- src/MEDMEM/MEDMEM_Exception.cxx | 26 - src/MEDMEM/MEDMEM_Exception.hxx | 26 - src/MEDMEM/MEDMEM_Family.cxx | 26 - src/MEDMEM/MEDMEM_Family.hxx | 31 +- src/MEDMEM/MEDMEM_Field.cxx | 188 ++- src/MEDMEM/MEDMEM_Field.hxx | 1140 +++++++++++++++-- src/MEDMEM/MEDMEM_GenDriver.cxx | 39 +- src/MEDMEM/MEDMEM_GenDriver.hxx | 38 +- src/MEDMEM/MEDMEM_GibiMeshDriver.cxx | 376 +++++- src/MEDMEM/MEDMEM_GibiMeshDriver.hxx | 34 +- src/MEDMEM/MEDMEM_Grid.cxx | 144 ++- src/MEDMEM/MEDMEM_Grid.hxx | 356 ++++- src/MEDMEM/MEDMEM_Group.cxx | 44 +- src/MEDMEM/MEDMEM_Group.hxx | 32 +- src/MEDMEM/MEDMEM_InterpolationWrappers.hxx | 75 ++ src/MEDMEM/MEDMEM_Med.cxx | 140 +- src/MEDMEM/MEDMEM_Med.hxx | 26 - src/MEDMEM/MEDMEM_MedFieldDriver.hxx | 93 +- src/MEDMEM/MEDMEM_MedMedDriver.cxx | 68 +- src/MEDMEM/MEDMEM_MedMedDriver.hxx | 26 - src/MEDMEM/MEDMEM_MedMeshDriver.cxx | 258 ++-- src/MEDMEM/MEDMEM_MedMeshDriver.hxx | 26 - src/MEDMEM/MEDMEM_Mesh.cxx | 493 +++++-- src/MEDMEM/MEDMEM_Mesh.hxx | 383 +++--- src/MEDMEM/MEDMEM_Meshing.cxx | 13 +- src/MEDMEM/MEDMEM_Meshing.hxx | 9 - src/MEDMEM/MEDMEM_ModulusArray.hxx | 26 - src/MEDMEM/MEDMEM_PointerOf.hxx | 30 +- src/MEDMEM/MEDMEM_STRING.hxx | 26 - src/MEDMEM/MEDMEM_SkyLineArray.cxx | 26 - src/MEDMEM/MEDMEM_SkyLineArray.hxx | 26 - src/MEDMEM/MEDMEM_Support.cxx | 250 +++- src/MEDMEM/MEDMEM_Support.hxx | 57 +- src/MEDMEM/MEDMEM_TypeMeshDriver.cxx | 9 - src/MEDMEM/MEDMEM_TypeMeshDriver.hxx | 9 - src/MEDMEM/MEDMEM_Unit.cxx | 26 - src/MEDMEM/MEDMEM_Unit.hxx | 26 - src/MEDMEM/MEDMEM_Utilities.hxx | 81 ++ src/MEDMEM/MEDMEM_VtkFieldDriver.hxx | 720 +++++++++++ src/MEDMEM/MEDMEM_VtkMedDriver.cxx | 52 +- src/MEDMEM/MEDMEM_VtkMedDriver.hxx | 26 - src/MEDMEM/MEDMEM_VtkMeshDriver.cxx | 393 ++++++ src/MEDMEM/MEDMEM_VtkMeshDriver.hxx | 80 ++ src/MEDMEM/MEDMEM_define.hxx | 85 +- src/MEDMEM/Makefile.in | 11 +- src/MEDMEM/create_mesh.c | 28 - src/MEDMEM/create_mesh_c2q4.c | 226 ++++ src/MEDMEM/create_mesh_c2q4s2.c | 28 - src/MEDMEM/create_mesh_c2q4s2_wrong.c | 28 - src/MEDMEM/create_mesh_c3h8.c | 283 ++++ src/MEDMEM/create_mesh_c3h8q4.c | 28 - src/MEDMEM/create_mesh_c3h8q4_wrong.c | 28 - src/MEDMEM/duplicateMED.cxx | 26 - src/MEDMEM/duplicateMEDMESH.cxx | 28 +- src/MEDMEM/med2vtk.cxx | 9 - src/MEDMEM/med_test.cxx | 26 - src/MEDMEM/test_MEDMEM_Array.cxx | 26 - src/MEDMEM/test_MEDMEM_CellModel.cxx | 26 - src/MEDMEM/test_MEDMEM_Meshing.cxx | 263 +++- src/MEDMEM/test_MEDMEM_ModulusArray.cxx | 26 - src/MEDMEM/test_MEDMEM_SkyLineArray.cxx | 26 - src/MEDMEM/test_affect_medarray.cxx | 26 - src/MEDMEM/test_copie_connectivity.cxx | 26 - src/MEDMEM/test_copie_coordinate.cxx | 26 - src/MEDMEM/test_copie_family.cxx | 26 - src/MEDMEM/test_copie_fieldT.cxx | 28 +- src/MEDMEM/test_copie_field_.cxx | 28 +- src/MEDMEM/test_copie_group.cxx | 26 - src/MEDMEM/test_copie_medarray.cxx | 26 - src/MEDMEM/test_copie_mesh.cxx | 9 - src/MEDMEM/test_copie_support.cxx | 26 - src/MEDMEM/test_gibi_driver.cxx | 38 + src/MEDMEM/test_operation_fielddouble.cxx | 403 ++++++ src/MEDMEM/test_operation_fieldint.cxx | 301 +++++ src/MEDMEM/tests/readEntete.cxx | 37 +- src/MEDMEM/tests/testUCoordinate.cxx | 2 +- src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.cxx | 61 +- src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.hxx | 31 +- src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.cxx | 60 +- src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.hxx | 31 +- .../MEDMEM_SWIG_MedFieldDoubleDriver.cxx | 26 - .../MEDMEM_SWIG_MedFieldDoubleDriver.hxx | 26 - .../MEDMEM_SWIG_MedFieldIntDriver.cxx | 26 - .../MEDMEM_SWIG_MedFieldIntDriver.hxx | 26 - src/MEDMEM_SWIG/libMEDMEM_Swig.i | 1102 +++++++++++++--- src/MEDMEM_SWIG/medMeshing_test.py | 401 +++++- src/MEDMEM_SWIG/med_field_anal.py | 568 ++++++++ src/MEDMEM_SWIG/med_opfield_test.py | 490 +++++++ src/MEDMEM_SWIG/med_opsupp_test.py | 403 ++++++ src/MEDMEM_SWIG/med_test1.py | 60 +- src/MEDMEM_SWIG/med_test2.py | 30 +- src/MEDMEM_SWIG/med_test3.py | 27 +- src/MEDMEM_SWIG/med_test_grid.py | 10 +- src/MEDMEM_SWIG/med_test_skin.py | 9 - src/MEDMEM_SWIG/my_typemap.i | 49 +- src/MedCorba_Swig/Makefile.in | 2 + src/MedCorba_Swig/libMedCorba_Swig.i | 50 +- src/MedMem/Family_i.cxx | 41 +- src/MedMem/Family_i.hxx | 35 +- src/MedMem/FieldDouble_i.cxx | 35 +- src/MedMem/FieldDouble_i.hxx | 34 +- src/MedMem/FieldInt_i.cxx | 35 +- src/MedMem/FieldInt_i.hxx | 34 +- src/MedMem/FieldOf_i.hxx | 45 +- src/MedMem/Field_i.cxx | 37 +- src/MedMem/Field_i.hxx | 38 +- src/MedMem/Group_i.cxx | 35 +- src/MedMem/Group_i.hxx | 35 +- src/MedMem/Med_i.cxx | 71 +- src/MedMem/Med_i.hxx | 36 +- src/MedMem/Mesh_i.cxx | 57 +- src/MedMem/Mesh_i.hxx | 40 +- src/MedMem/Support_i.cxx | 107 +- src/MedMem/Support_i.hxx | 36 +- src/MedMem/convert.cxx | 39 +- src/MedMem/convert.hxx | 36 +- 127 files changed, 10599 insertions(+), 3841 deletions(-) create mode 100644 src/MEDMEM/MEDMEM_DriverTools.cxx create mode 100644 src/MEDMEM/MEDMEM_DriverTools.hxx create mode 100644 src/MEDMEM/MEDMEM_InterpolationWrappers.hxx create mode 100644 src/MEDMEM/MEDMEM_Utilities.hxx create mode 100644 src/MEDMEM/MEDMEM_VtkFieldDriver.hxx create mode 100644 src/MEDMEM/MEDMEM_VtkMeshDriver.cxx create mode 100644 src/MEDMEM/MEDMEM_VtkMeshDriver.hxx create mode 100644 src/MEDMEM/create_mesh_c2q4.c create mode 100644 src/MEDMEM/create_mesh_c3h8.c create mode 100644 src/MEDMEM/test_gibi_driver.cxx create mode 100644 src/MEDMEM/test_operation_fielddouble.cxx create mode 100644 src/MEDMEM/test_operation_fieldint.cxx create mode 100755 src/MEDMEM_SWIG/med_field_anal.py create mode 100755 src/MEDMEM_SWIG/med_opfield_test.py create mode 100755 src/MEDMEM_SWIG/med_opsupp_test.py diff --git a/src/MEDMEM/MEDMEM_Array.hxx b/src/MEDMEM/MEDMEM_Array.hxx index 6d74be7db..e0d049821 100644 --- a/src/MEDMEM/MEDMEM_Array.hxx +++ b/src/MEDMEM/MEDMEM_Array.hxx @@ -1,29 +1,3 @@ -// 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_Array.hxx -// Module : MED - #ifndef __MEDARRAY_H__ #define __MEDARRAY_H__ @@ -119,6 +93,8 @@ public : void setIJ (const med_int i, const med_int j, const T value); void calculateOther(); + bool isOtherCalculated() const {return (const T*)_valuesOther != NULL;} + void clearOtherMode(); }; //-------------------------------------------------// @@ -273,9 +249,9 @@ template MEDARRAY::MEDARRAY(MEDARRAY const & p,bool copyOther ): _ldValues(p._ldValues), _lengthValues(p._lengthValues), _mode(p._mode), - _valuesDefault(), - _valuesNo(), _valuesFull(), + _valuesNo(), + _valuesDefault(), _valuesOther() { BEGIN_OF("Constructeur deepCopy MEDARRAY::MEDARRAY(MEDARRAY const & m,bool copyOther"); @@ -318,7 +294,7 @@ template MEDARRAY::MEDARRAY(MEDARRAY const & p,bool copyOther ): // It DOES NOT copy of the memory. // The two objects will share data./n */ -template MEDARRAY & MEDARRAY::MEDARRAY::operator = (const MEDARRAY & m) +template MEDARRAY & MEDARRAY::operator = (const MEDARRAY & m) { BEGIN_OF("Operator = MEDARRAY"); @@ -584,9 +560,24 @@ template void MEDARRAY::set(const medModeSwitch mode, const T* valu } _valuesOther.set(0); - END_OF("MEDARRAY::set(mode,i,value)"); + END_OF("MEDARRAY::set(mode,i,value)"); } +/*! This function clears the other mode of representation if it exists + * It is usefull for people who needs for optimisation reasons to work directly + * on the inside array without using set-functions + */ +template void MEDARRAY::clearOtherMode() +{ + if(isOtherCalculated()) + { + if ( _mode == MED_FULL_INTERLACE) + _valuesNo.set(0); + else + _valuesFull.set(0); + _valuesOther.set(0); + } +} // ------------------ diff --git a/src/MEDMEM/MEDMEM_CellModel.cxx b/src/MEDMEM/MEDMEM_CellModel.cxx index 9ea2b3aec..e45ed624b 100644 --- a/src/MEDMEM/MEDMEM_CellModel.cxx +++ b/src/MEDMEM/MEDMEM_CellModel.cxx @@ -1,29 +1,3 @@ -// 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.cxx -// Module : MED - using namespace std; /* File MEDMEM_CellModel.cxx diff --git a/src/MEDMEM/MEDMEM_CellModel.hxx b/src/MEDMEM/MEDMEM_CellModel.hxx index d09bd4fad..068d7b443 100644 --- a/src/MEDMEM/MEDMEM_CellModel.hxx +++ b/src/MEDMEM/MEDMEM_CellModel.hxx @@ -1,29 +1,3 @@ -// 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$ diff --git a/src/MEDMEM/MEDMEM_Connectivity.cxx b/src/MEDMEM/MEDMEM_Connectivity.cxx index 72ac52e67..b785bdf50 100644 --- a/src/MEDMEM/MEDMEM_Connectivity.cxx +++ b/src/MEDMEM/MEDMEM_Connectivity.cxx @@ -1,38 +1,14 @@ -// 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_Connectivity.cxx -// Module : MED - using namespace std; #include "MEDMEM_Connectivity.hxx" #include "MEDMEM_Family.hxx" +#include "MEDMEM_Group.hxx" #include "MEDMEM_CellModel.hxx" #include "MEDMEM_SkyLineArray.hxx" #include "MEDMEM_ModulusArray.hxx" #include "MEDMEM_STRING.hxx" +#include /*! Default Constructor. /n @@ -162,7 +138,7 @@ CONNECTIVITY::~CONNECTIVITY() if (_type != NULL) delete [] _type; if (_count != NULL) - delete[] _count; + delete [] _count; if (_nodal != NULL) delete _nodal; if (_descending != NULL) @@ -242,7 +218,7 @@ void CONNECTIVITY::setCount(const int * Count, const medEntityMesh Entity) if (_nodal != NULL) delete _nodal; _nodal = new MEDSKYLINEARRAY(_count[_numberOfTypes]-1,index[_count[_numberOfTypes]-1]-1); _nodal->setIndex(index); - delete[] index; + delete [] index; } else { @@ -302,7 +278,8 @@ void CONNECTIVITY::calculateConnectivity(medConnectivity ConnectivityType, medEn throw MEDEXCEPTION("CONNECTIVITY::calculateConnectivity : Could not build DESCENDING !"); if (Entity!=_entity) { calculateDescendingConnectivity(); - _constituent->calculateConnectivity(ConnectivityType,Entity); + if (_entityDimension == 2 || _entityDimension == 3) + _constituent->calculateConnectivity(ConnectivityType,Entity); } } @@ -357,7 +334,7 @@ void CONNECTIVITY::updateFamily(vector myFamilies) calculateDescendingConnectivity(); - int newNumberOfFace = _constituent->_nodal->getNumberOf(); + // int newNumberOfFace = _constituent->_nodal->getNumberOf(); const int * newConstituentValue = _constituent->_nodal->getValue(); const int * newConstituentIndex = _constituent->_nodal->getIndex(); @@ -365,7 +342,7 @@ void CONNECTIVITY::updateFamily(vector myFamilies) _reverseDescendingConnectivity->getIndex(); const int * newDescendingIndex = _descending->getIndex(); - const int * newDescendingValue = _descending->getValue(); + // const int * newDescendingValue = _descending->getValue(); // loop on all family, // for all constituent in family, we get it's old connectivity @@ -526,19 +503,19 @@ void CONNECTIVITY::updateFamily(vector myFamilies) // else nothing to do } else {// else we are on border and we do nothing !!!!!!!! - INFOS("WARNING,WARNING,WARNING,WARNING,WARNING,WARNING"); - INFOS(LOC<<" Boudary FACE "< myFamilies) return; } +// meme methode que updateFamily, mais avec des groupes. Il n'est pas possible d'utiliser +// l'heritage car les pointeurs sont dans un conteneur. +void CONNECTIVITY::updateGroup(vector myFamilies) +//------------------------------------------------------------// +{ + const char * LOC = "CONNECTIVITY::updateFamily(vector) "; + BEGIN_OF(LOC); + + int numberOfFamilies = myFamilies.size(); + if (numberOfFamilies == 0 ) { + MESSAGE(LOC<<"No family"); + return; + } + // does we do an update ? + if ((_constituent != NULL)&(_descending != NULL)) { + MESSAGE(LOC<<"Constituent is already defined"); + return; + } + + if ((_constituent != NULL)&(_descending == NULL)) { + if (myFamilies[0]->getEntity() != _constituent->getEntity()) { + MESSAGE(LOC<<"Family and constituent entity are different. We do nothing"); + return; + } + + // well we could go ! + CONNECTIVITY * oldConstituent = _constituent; + +// for(int i=0; i_nodal == NULL) + { + MESSAGE(LOC<<"We have no nodal connectivity of sub cell"); + throw MED_EXCEPTION(LOCALIZED(STRING(LOC)<<"We have no nodal connectivity of sub cell")); + } + int oldNumberOfFace = oldConstituent->_nodal->getNumberOf(); + const int * oldConstituentValue = oldConstituent->_nodal->getValue(); + const int * oldConstituentIndex = oldConstituent->_nodal->getIndex(); + + calculateDescendingConnectivity(); + + // int newNumberOfFace = _constituent->_nodal->getNumberOf(); + const int * newConstituentValue = _constituent->_nodal->getValue(); + const int * newConstituentIndex = _constituent->_nodal->getIndex(); + + const int * newReverseDescendingIndex = + _reverseDescendingConnectivity->getIndex(); + + const int * newDescendingIndex = _descending->getIndex(); + // const int * newDescendingValue = _descending->getValue(); + + // loop on all family, + // for all constituent in family, we get it's old connectivity + // (with oldCconstituentValue and oldConstituentIndex) + // and search the constituent in newConstituentValue with class + // ModulusArry + // + // when a new face is found, replace old constituent + // number in family with new one + // If face is not rigth oriented, we must change _descending attribute + // and _reverseDescendingConnectivity (see calculateDescendingConnectivity()). + + // Voila a toi de jouer Nadir :-) + + // First we get the renumbering from the oldCconstituentValue and + // oldConstituentIndex in the the new one, newConstituentValue and + // newConstituentIndex with a negative sign if the face is not + // right orented + + int * renumberingFromOldToNew = new int [oldNumberOfFace]; + int index1 = 0; + int indexm1 = 0; + + _constituent->calculateReverseNodalConnectivity(); + + for (int iOldFace=0;iOldFacegetReverseNodalConnectivity(); + const int * reverseFaceNodalIndex = _constituent->getReverseNodalConnectivityIndex(); + + // set an array wich contains faces numbers arround first node + int BeginIndexFaceArrayFirstNode=reverseFaceNodalIndex[NodesLists[0]-1]; + int EndIndexFaceArrayFirstNode=reverseFaceNodalIndex[NodesLists[0]]; + int NumberOfFacesInList=EndIndexFaceArrayFirstNode-BeginIndexFaceArrayFirstNode; + + int * FacesList = new int[NumberOfFacesInList]; + + for (int l=BeginIndexFaceArrayFirstNode; l1) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"More than one face found ("< 2) + throw MED_EXCEPTION(LOCALIZED(STRING(LOC)<<"This face/edge should not be a (d-1) cell because it has "<getIJ(FacesList[0],1); + int cell2 = _reverseDescendingConnectivity->getIJ(FacesList[0],2); + // PROVISOIRE : en attendant que le SKYLINEARRAY de ReverseDescending soit correct (sans le zero) + // if (cell2 == 0) + // throw MED_EXCEPTION(LOCALIZED(STRING(LOC)<<"This is a boundary face/edge, it should not be renumbered and it is wrongly oriented.")); + + if (cell2 != 0) { // we are not on border !!!! + + _reverseDescendingConnectivity->setIJ(FacesList[0],1,cell2); + // Updating _constituent->_nodal because of reversity + const int * oldArray = oldConstituentValue+face_it_beginOld-1; + for(int iarray=1;iarray<=face_size_itNew;iarray++){ + _constituent->_nodal->setIJ(FacesList[0],iarray,oldArray[iarray-1]); + } + + // Updating _reverseDescendingConnectivity + + + _reverseDescendingConnectivity->setIJ(FacesList[0],2,cell1); + + // Updating _descending for cell1 and cell2 + for(int iface=newDescendingIndex[cell1-1];iface<=newDescendingIndex[cell1];iface++) + if (_descending->getIndexValue(iface)==FacesList[0]) + _descending->setIndexValue(iface,-FacesList[0]); + else if (_descending->getIndexValue(iface)==-FacesList[0]) + _descending->setIndexValue(iface,FacesList[0]); + // else nothing to do + + for(int iface=newDescendingIndex[cell2-1];ifacegetIndexValue(iface)==FacesList[0]) + _descending->setIndexValue(iface,-FacesList[0]); + else if (_descending->getIndexValue(iface)==-FacesList[0]) + _descending->setIndexValue(iface,FacesList[0]); + // else nothing to do + + } else {// else we are on border and we do nothing !!!!!!!! + MESSAGE("WARNING,WARNING,WARNING,WARNING,WARNING,WARNING"); + MESSAGE(LOC<<" Boudary FACE "<getnumber(); + int numberOfLines_skyline = number->getNumberOf(); + const int * index_skyline = number->getIndex(); + + for (int i=0;isetIndexValue(j,renumberingFromOldToNew[number->getIndexValue(j)-1]); + } + } + MESSAGE(LOC<<"updating the family (END) : " << *myFamily); + } + + delete oldConstituent ; + delete [] renumberingFromOldToNew; + } + + + END_OF(LOC); + return; +} + //------------------------------------------------------------------------------------------------------------------// const med_int * CONNECTIVITY::getConnectivity(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type) //------------------------------------------------------------------------------------------------------------------// @@ -619,7 +854,7 @@ const med_int * CONNECTIVITY::getConnectivity(medConnectivity ConnectivityType, - In fortran mode : Connectivity[ConnectivityIndex[i]+j] */ //-----------------------------------------------------------------------------------------------// const med_int * CONNECTIVITY::getConnectivityIndex(medConnectivity ConnectivityType, medEntityMesh Entity) -//------------------------------------------------------------------------------------------------// +//----0000000--------------------------------------------------------------------------------------------// { const char * LOC = "CONNECTIVITY::getConnectivityIndex"; BEGIN_OF(LOC); @@ -901,8 +1136,8 @@ void CONNECTIVITY::calculateReverseNodalConnectivity() _reverseNodalConnectivity = new MEDSKYLINEARRAY(_numberOfNodes,size_reverse_nodal_connectivity, reverse_nodal_connectivity_index, reverse_nodal_connectivity); - delete[] reverse_nodal_connectivity_index; - delete[] reverse_nodal_connectivity; + delete [] reverse_nodal_connectivity_index; + delete [] reverse_nodal_connectivity; } } @@ -914,314 +1149,316 @@ void CONNECTIVITY::calculateDescendingConnectivity() const char * LOC = "CONNECTIVITY::calculateDescendingConnectivity() : "; BEGIN_OF(LOC); - if (_descending==NULL) { - if (_nodal==NULL) { - MESSAGE(LOC<<"No connectivity found !"); - throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity found !")); - } - // calcul _descending from _nodal - // we need CONNECTIVITY for constituent - - if (_constituent != NULL) - // throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"ERROR : No descending connectivity defined, but constituent exist !")); - MESSAGE(LOC<<": No descending connectivity defined, but constituent exist !"); - - if (_entityDimension == 3) - _constituent = new CONNECTIVITY(MED_FACE); - else if (_entityDimension == 2) - _constituent = new CONNECTIVITY(MED_EDGE); - else { - MESSAGE(LOC<<"We are in 1D"); - return; - } - _constituent->_typeConnectivity = MED_NODAL; - _constituent->_numberOfNodes = _numberOfNodes; - // foreach cells, we built array of constituent - int DescendingSize = 0; - for(int i=0; i<_numberOfTypes; i++) - DescendingSize+=(_count[i+1]-_count[i])*_type[i].getNumberOfConstituents(1); - //_descending = new MEDSKYLINEARRAY(_count[_numberOfTypes]-1,DescendingSize); - //const int * descend_connectivity = _descending->getValue(); - int * descend_connectivity = new int[DescendingSize]; - for (int i=0; igetIndex(); - int * descend_connectivity_index = new int[_count[_numberOfTypes]]; - descend_connectivity_index[0]=1; - medGeometryElement* ConstituentsTypes = new medGeometryElement[2]; - ConstituentsTypes[0]=MED_NONE; - ConstituentsTypes[1]=MED_NONE; - int * NumberOfConstituentsForeachType = new int[2]; - NumberOfConstituentsForeachType[0]=0; - NumberOfConstituentsForeachType[1]=0; - for(int i=0; i<_numberOfTypes; i++) { - // initialize descend_connectivity_index array : - int NumberOfConstituents = _type[i].getNumberOfConstituents(1); - for (int j=_count[i];j<_count[i+1];j++){ - descend_connectivity_index[j]=descend_connectivity_index[j-1]+NumberOfConstituents; - // compute number of constituent of all cell for each type - for(int k=1;k_nodal = new MEDSKYLINEARRAY(TotalNumberOfConstituents,TotalNumberOfNodes); - // we use _constituent->_nodal - //const int * ConstituentNodalConnectivity = _constituent->_nodal->getValue(); - //const int * ConstituentNodalConnectivityIndex = _constituent->_nodal->getIndex(); - int * ConstituentNodalConnectivity = new int[TotalNumberOfNodes]; - int * ConstituentNodalConnectivityIndex = new int[TotalNumberOfConstituents+1]; - ConstituentNodalConnectivityIndex[0]=1; + _constituent->_typeConnectivity = MED_NODAL; + _constituent->_numberOfNodes = _numberOfNodes; + // foreach cells, we built array of constituent + int DescendingSize = 0; + for(int i=0; i<_numberOfTypes; i++) + DescendingSize+=(_count[i+1]-_count[i])*_type[i].getNumberOfConstituents(1); + //_descending = new MEDSKYLINEARRAY(_count[_numberOfTypes]-1,DescendingSize); + //const int * descend_connectivity = _descending->getValue(); + int * descend_connectivity = new int[DescendingSize]; + for (int i=0; igetIndex(); + int * descend_connectivity_index = new int[_count[_numberOfTypes]]; + descend_connectivity_index[0]=1; + medGeometryElement* ConstituentsTypes = new medGeometryElement[2]; + ConstituentsTypes[0]=MED_NONE; + ConstituentsTypes[1]=MED_NONE; + int * NumberOfConstituentsForeachType = new int[2]; + NumberOfConstituentsForeachType[0]=0; + NumberOfConstituentsForeachType[1]=0; + for(int i=0; i<_numberOfTypes; i++) { + // initialize descend_connectivity_index array : + int NumberOfConstituents = _type[i].getNumberOfConstituents(1); + for (int j=_count[i];j<_count[i+1];j++){ + descend_connectivity_index[j]=descend_connectivity_index[j-1]+NumberOfConstituents; + // compute number of constituent of all cell for each type + for(int k=1;k_entityDimension=ConstituentsTypes[0]/100; - if (ConstituentsTypes[1]==MED_NONE) - _constituent->_numberOfTypes = 1; - else - _constituent->_numberOfTypes = 2; - _constituent->_geometricTypes = new medGeometryElement[_constituent->_numberOfTypes]; - _constituent->_type = new CELLMODEL[_constituent->_numberOfTypes]; - _constituent->_count = new med_int[_constituent->_numberOfTypes+1]; - _constituent->_count[0]=1; - int* tmp_NumberOfConstituentsForeachType = new med_int[_constituent->_numberOfTypes+1]; - tmp_NumberOfConstituentsForeachType[0]=0; // to count constituent of each type - for (int i=0; i<_constituent->_numberOfTypes;i++) { - _constituent->_geometricTypes[i]=ConstituentsTypes[i]; - _constituent->_count[i+1]=_constituent->_count[i]+NumberOfConstituentsForeachType[i]; - CELLMODEL Type(ConstituentsTypes[i]); - _constituent->_type[i]=Type; - tmp_NumberOfConstituentsForeachType[i+1]=NumberOfConstituentsForeachType[i]; - for (int j=tmp_NumberOfConstituentsForeachType[i]; j_nodal = new MEDSKYLINEARRAY(TotalNumberOfConstituents,TotalNumberOfNodes); + + // we use _constituent->_nodal + //const int * ConstituentNodalConnectivity = _constituent->_nodal->getValue(); + //const int * ConstituentNodalConnectivityIndex = _constituent->_nodal->getIndex(); + int * ConstituentNodalConnectivity = new int[TotalNumberOfNodes]; + int * ConstituentNodalConnectivityIndex = new int[TotalNumberOfConstituents+1]; + ConstituentNodalConnectivityIndex[0]=1; + + _constituent->_entityDimension=ConstituentsTypes[0]/100; + if (ConstituentsTypes[1]==MED_NONE) + _constituent->_numberOfTypes = 1; + else + _constituent->_numberOfTypes = 2; + _constituent->_geometricTypes = new medGeometryElement[_constituent->_numberOfTypes]; + _constituent->_type = new CELLMODEL[_constituent->_numberOfTypes]; + _constituent->_count = new med_int[_constituent->_numberOfTypes+1]; + _constituent->_count[0]=1; + int* tmp_NumberOfConstituentsForeachType = new med_int[_constituent->_numberOfTypes+1]; + tmp_NumberOfConstituentsForeachType[0]=0; // to count constituent of each type + for (int i=0; i<_constituent->_numberOfTypes;i++) { + _constituent->_geometricTypes[i]=ConstituentsTypes[i]; + _constituent->_count[i+1]=_constituent->_count[i]+NumberOfConstituentsForeachType[i]; + CELLMODEL Type(ConstituentsTypes[i]); + _constituent->_type[i]=Type; + tmp_NumberOfConstituentsForeachType[i+1]=NumberOfConstituentsForeachType[i]; + for (int j=tmp_NumberOfConstituentsForeachType[i]; jgetIndex(); - const int * ReverseNodalConnectivityValue = _reverseNodalConnectivity->getValue(); - - // array to keep reverse descending connectivity - int * ReverseDescendingConnectivityValue = new int[TotalNumberOfConstituents*2]; + // we need reverse nodal connectivity + if (! _reverseNodalConnectivity) + calculateReverseNodalConnectivity(); + const int * ReverseNodalConnectivityIndex = _reverseNodalConnectivity->getIndex(); + const int * ReverseNodalConnectivityValue = _reverseNodalConnectivity->getValue(); + + // array to keep reverse descending connectivity + int * ReverseDescendingConnectivityValue = new int[TotalNumberOfConstituents*2]; - int TotalNumberOfSubCell = 0; - for (int i=0; i<_numberOfTypes; i++) { // loop on all cell type - CELLMODEL Type = _type[i]; - int NumberOfNodesPerCell = Type.getNumberOfNodes(); - int NumberOfConstituentPerCell = Type.getNumberOfConstituents(1); - for (int j=_count[i]; j<_count[i+1]; j++) // we loop on all cell of this type - for (int k=1; k<=NumberOfConstituentPerCell; k++) { // we loop on all sub cell of it - if (descend_connectivity[descend_connectivity_index[j-1]+k-2]==0) { - // it is a new sub cell ! - // TotalNumberOfSubCell++; - // Which type ? - if (Type.getConstituentType(1,k)==_constituent->_geometricTypes[0]){ - tmp_NumberOfConstituentsForeachType[0]++; - TotalNumberOfSubCell=tmp_NumberOfConstituentsForeachType[0]; - } else { - tmp_NumberOfConstituentsForeachType[1]++; - TotalNumberOfSubCell=tmp_NumberOfConstituentsForeachType[1]; - } - //we have maximum two types - - descend_connectivity[descend_connectivity_index[j-1]+k-2]=TotalNumberOfSubCell; - ReverseDescendingConnectivityValue[(TotalNumberOfSubCell-1)*2]=j; - int NumberOfNodesPerConstituent = Type.getConstituentType(1,k)%100; + int TotalNumberOfSubCell = 0; + for (int i=0; i<_numberOfTypes; i++) { // loop on all cell type + CELLMODEL Type = _type[i]; + // int NumberOfNodesPerCell = Type.getNumberOfNodes(); + int NumberOfConstituentPerCell = Type.getNumberOfConstituents(1); + for (int j=_count[i]; j<_count[i+1]; j++) // we loop on all cell of this type + for (int k=1; k<=NumberOfConstituentPerCell; k++) + { // we loop on all sub cell of it + if (descend_connectivity[descend_connectivity_index[j-1]+k-2]==0) { + // it is a new sub cell ! + // TotalNumberOfSubCell++; + // Which type ? + if (Type.getConstituentType(1,k)==_constituent->_geometricTypes[0]){ + tmp_NumberOfConstituentsForeachType[0]++; + TotalNumberOfSubCell=tmp_NumberOfConstituentsForeachType[0]; + } else { + tmp_NumberOfConstituentsForeachType[1]++; + TotalNumberOfSubCell=tmp_NumberOfConstituentsForeachType[1]; + } + //we have maximum two types + + descend_connectivity[descend_connectivity_index[j-1]+k-2]=TotalNumberOfSubCell; + ReverseDescendingConnectivityValue[(TotalNumberOfSubCell-1)*2]=j; + int NumberOfNodesPerConstituent = Type.getConstituentType(1,k)%100; - int * NodesLists = new int[NumberOfNodesPerConstituent]; - for (int l=0; lgetIJ(j,Type.getNodeConstituent(1,k,l+1)); - ConstituentNodalConnectivity[ConstituentNodalConnectivityIndex[TotalNumberOfSubCell-1]-1+l]=NodesLists[l]; - } - // we use reverse_nodal_connectivity to find the other element which contain this sub cell - - // all elements which contains first node of sub cell : - int ReverseNodalConnectivityIndex_0 = ReverseNodalConnectivityIndex[NodesLists[0]-1]; - int ReverseNodalConnectivityIndex_1 = ReverseNodalConnectivityIndex[NodesLists[0]]; - int NumberOfCellsInList = ReverseNodalConnectivityIndex_1-ReverseNodalConnectivityIndex_0; + int * NodesLists = new int[NumberOfNodesPerConstituent]; + for (int l=0; lgetIJ(j,Type.getNodeConstituent(1,k,l+1)); + ConstituentNodalConnectivity[ConstituentNodalConnectivityIndex[TotalNumberOfSubCell-1]-1+l]=NodesLists[l]; + } + // we use reverse_nodal_connectivity to find the other element which contain this sub cell + + // all elements which contains first node of sub cell : + int ReverseNodalConnectivityIndex_0 = ReverseNodalConnectivityIndex[NodesLists[0]-1]; + int ReverseNodalConnectivityIndex_1 = ReverseNodalConnectivityIndex[NodesLists[0]]; + int NumberOfCellsInList = ReverseNodalConnectivityIndex_1-ReverseNodalConnectivityIndex_0; + + if (NumberOfCellsInList > 0) { // we could have no element ! + int * CellsList = new int[NumberOfCellsInList]; + for (int l=ReverseNodalConnectivityIndex_0; l 0) { // we could have no element ! - int * CellsList = new int[NumberOfCellsInList]; - for (int l=ReverseNodalConnectivityIndex_0; l 0) { // We have found some elements ! - int CellNumber = CellsList[0]; - //delete [] CellsList; - if (NumberOfCellsInList>1) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"More than one other Cell ("<getIJ(CellNumber,Type2.getNodeConstituent(1,l,m)) == NodesLists[n-1]) - counter++; + if (NumberOfCellsInList > 0) { // We have found some elements ! + int CellNumber = CellsList[0]; + //delete [] CellsList; + if (NumberOfCellsInList>1) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"More than one other Cell ("<getIJ(CellNumber,Type2.getNodeConstituent(1,l,m)) == NodesLists[n-1]) + counter++; + } + if (counter==Type.getConstituentType(1,k)%100) { + descend_connectivity[descend_connectivity_index[CellNumber-1]+l-2]=-1*TotalNumberOfSubCell; // because, see it in other side ! + find2 = true; + } + if (find2) + break; } - if (counter==Type.getConstituentType(1,k)%100) { - descend_connectivity[descend_connectivity_index[CellNumber-1]+l-2]=-1*TotalNumberOfSubCell; // because, see it in other side ! - find2 = true; - } - if (find2) - break; + if (!find2) + MESSAGE(LOC<<"ERROR ERROR ERROR ERROR ERROR : we find any subcell !!!"); // exception ? + } + } else { + ReverseDescendingConnectivityValue[(TotalNumberOfSubCell-1)*2+1]=0; } - if (!find2) - INFOS(LOC<<"ERROR ERROR ERROR ERROR ERROR : we find any subcell !!!"); // exception ? - } - } else { - ReverseDescendingConnectivityValue[(TotalNumberOfSubCell-1)*2+1]=0; + delete [] CellsList; + } + + delete [] NodesLists; } - delete[] CellsList; } - - delete[] NodesLists; - } - } - } - // we adjust _constituent - int NumberOfConstituent=0; - int SizeOfConstituentNodal=0; - for (int i=0;i<_constituent->_numberOfTypes; i++) { - NumberOfConstituent += tmp_NumberOfConstituentsForeachType[i]-_constituent->_count[i]+1; - SizeOfConstituentNodal += (tmp_NumberOfConstituentsForeachType[i]-_constituent->_count[i]+1)*_constituent->_type[i].getNumberOfNodes(); - } - // we built new _nodal attribute in _constituent - //MEDSKYLINEARRAY *ConstituentNodal = new MEDSKYLINEARRAY(NumberOfConstituent,SizeOfConstituentNodal); - //const int *ConstituentNodalValue = ConstituentNodal->getValue(); - //const int *ConstituentNodalIndex = ConstituentNodal->getIndex(); - int *ConstituentNodalValue = new int[SizeOfConstituentNodal]; - int *ConstituentNodalIndex = new int[NumberOfConstituent+1]; - ConstituentNodalIndex[0]=1; - // we build _reverseDescendingConnectivity - //_reverseDescendingConnectivity = new MEDSKYLINEARRAY(NumberOfConstituent,2*NumberOfConstituent); - //const int *reverseDescendingConnectivityValue = _reverseDescendingConnectivity->getValue(); - //const int *reverseDescendingConnectivityIndex = _reverseDescendingConnectivity->getIndex(); - int *reverseDescendingConnectivityValue = new int[2*NumberOfConstituent]; - int *reverseDescendingConnectivityIndex = new int[NumberOfConstituent+1]; - reverseDescendingConnectivityIndex[0]=1; - - // first constituent type - for(int j=0; j_numberOfTypes; i++) { + NumberOfConstituent += tmp_NumberOfConstituentsForeachType[i]-_constituent->_count[i]+1; + SizeOfConstituentNodal += (tmp_NumberOfConstituentsForeachType[i]-_constituent->_count[i]+1)*_constituent->_type[i].getNumberOfNodes(); } - } - // second type if any - if (_constituent->_numberOfTypes==2) { - int offset = _constituent->_count[1]-tmp_NumberOfConstituentsForeachType[0]-1; - int offset1=offset*_constituent->_type[0].getNumberOfNodes(); - int offset2=offset*2; - int NumberOfNodesPerConstituent = _constituent->_type[1].getNumberOfNodes(); - for(int j=tmp_NumberOfConstituentsForeachType[0]; jgetValue(); + //const int *ConstituentNodalIndex = ConstituentNodal->getIndex(); + int *ConstituentNodalValue = new int[SizeOfConstituentNodal]; + int *ConstituentNodalIndex = new int[NumberOfConstituent+1]; + ConstituentNodalIndex[0]=1; + // we build _reverseDescendingConnectivity + //_reverseDescendingConnectivity = new MEDSKYLINEARRAY(NumberOfConstituent,2*NumberOfConstituent); + //const int *reverseDescendingConnectivityValue = _reverseDescendingConnectivity->getValue(); + //const int *reverseDescendingConnectivityIndex = _reverseDescendingConnectivity->getIndex(); + int *reverseDescendingConnectivityValue = new int[2*NumberOfConstituent]; + int *reverseDescendingConnectivityIndex = new int[NumberOfConstituent+1]; + reverseDescendingConnectivityIndex[0]=1; + + // first constituent type + for(int j=0; j_count[2]=NumberOfConstituent+1; - // we correct _descending to adjust face number - for(int j=0;jtmp_NumberOfConstituentsForeachType[0]) - descend_connectivity[j]-=offset; - - } + // second type if any + if (_constituent->_numberOfTypes==2) { + int offset = _constituent->_count[1]-tmp_NumberOfConstituentsForeachType[0]-1; + int offset1=offset*_constituent->_type[0].getNumberOfNodes(); + int offset2=offset*2; + int NumberOfNodesPerConstituent = _constituent->_type[1].getNumberOfNodes(); + for(int j=tmp_NumberOfConstituentsForeachType[0]; j_count[2]=NumberOfConstituent+1; + // we correct _descending to adjust face number + for(int j=0;jtmp_NumberOfConstituentsForeachType[0]) + descend_connectivity[j]-=offset; + } - delete[] ConstituentNodalConnectivityIndex; - delete[] ConstituentNodalConnectivity; - - _descending = new MEDSKYLINEARRAY(_count[_numberOfTypes]-1, - DescendingSize, - descend_connectivity_index, - descend_connectivity); - delete[] descend_connectivity_index; - delete[] descend_connectivity; - _reverseDescendingConnectivity = new MEDSKYLINEARRAY(NumberOfConstituent, - 2*NumberOfConstituent, - reverseDescendingConnectivityIndex, - reverseDescendingConnectivityValue); - delete[] reverseDescendingConnectivityIndex; - delete[] reverseDescendingConnectivityValue; - - _constituent->_count[1]=tmp_NumberOfConstituentsForeachType[0]+1; - delete[] tmp_NumberOfConstituentsForeachType; - - //delete _constituent->_nodal; - _constituent->_nodal = new MEDSKYLINEARRAY(NumberOfConstituent, - SizeOfConstituentNodal, - ConstituentNodalIndex, - ConstituentNodalValue); + delete [] ConstituentNodalConnectivityIndex; + delete [] ConstituentNodalConnectivity; + + _descending = new MEDSKYLINEARRAY(_count[_numberOfTypes]-1, + DescendingSize, + descend_connectivity_index, + descend_connectivity); + delete [] descend_connectivity_index; + delete [] descend_connectivity; + _reverseDescendingConnectivity = new MEDSKYLINEARRAY(NumberOfConstituent, + 2*NumberOfConstituent, + reverseDescendingConnectivityIndex, + reverseDescendingConnectivityValue); + delete [] reverseDescendingConnectivityIndex; + delete [] reverseDescendingConnectivityValue; + + _constituent->_count[1]=tmp_NumberOfConstituentsForeachType[0]+1; + delete [] tmp_NumberOfConstituentsForeachType; + + //delete _constituent->_nodal; + _constituent->_nodal = new MEDSKYLINEARRAY(NumberOfConstituent, + SizeOfConstituentNodal, + ConstituentNodalIndex, + ConstituentNodalValue); - delete[] ConstituentNodalIndex; - delete[] ConstituentNodalValue; + delete [] ConstituentNodalIndex; + delete [] ConstituentNodalValue; - delete[] ReverseDescendingConnectivityValue; - } + delete [] ReverseDescendingConnectivityValue; + } END_OF(LOC); } @@ -1243,29 +1480,126 @@ void CONNECTIVITY::calculateDescendingConnectivity() void CONNECTIVITY::calculateNeighbourhood(CONNECTIVITY &myConnectivity) //--------------------------------------------------------------------// { + const char * LOC = "CONNECTIVITY::calculateNeighbourhood(CONNECTIVITY &myConnectivity) : "; + BEGIN_OF(LOC); + + MESSAGE(LOC<<"method not yet implemented " << myConnectivity._entity); // Mesh dimension ! + + END_OF(LOC); return; } /*! - Give, for one element number of a specified entity the geometric type - Of this element. + Returns the geometry of an element given by its entity type & its global number. Example : medGeometryElement myType = myConnectivity.getElementType(MED_CELL,35); */ //--------------------------------------------------------------------// -medGeometryElement CONNECTIVITY::getElementType(medEntityMesh Entity,int Number) const +medGeometryElement CONNECTIVITY::getElementType(medEntityMesh Entity,int globalNumber) const //--------------------------------------------------------------------// { + const char * LOC = "medGeometryElement CONNECTIVITY::getElementType(medEntityMesh Entity, int globalNumber) const : "; + BEGIN_OF(LOC); + + // The globalNumber must verify : 1 <= globalNumber < _count[_numberOfTypes] (== totalNumberOfElement+1) + if ( (globalNumber < 1) || (globalNumber > _count[_numberOfTypes]-1 ) ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "globalNumber must be between >= |" + << 1 <<"| and <= |" << _count[_numberOfTypes]-1 )); + if (_entity==Entity) { for(int i=1; i<=_numberOfTypes;i++) - if (Number<_count[i]) + if (globalNumber<_count[i]) return _geometricTypes[i-1]; } else if (_constituent!=NULL) - return _constituent->getElementType(Entity,Number); + return _constituent->getElementType(Entity,globalNumber); else throw MEDEXCEPTION(LOCALIZED("getElementType : Entity not defined !")); throw MEDEXCEPTION(LOCALIZED("getElementType : Wrong Number !")); + + END_OF(LOC); +} + + +ostream & operator<<(ostream &os, CONNECTIVITY &co) +{ + os << endl << "------------- Entity = "; + switch (co._entity) + { + case MED_CELL: + os << "MED_CELL"; + break; + case MED_FACE: + os << "MED_FACE"; + break; + case MED_EDGE: + os << "MED_EDGE"; + break; + case MED_NODE: + os << "MED_NODE"; + break; + case MED_ALL_ENTITIES: + os << "MED_ALL_ENTITIES"; + break; + default: + os << "Unknown"; + break; + } + os << " -------------\n\nMedConnectivity : "; + switch (co._typeConnectivity) + { + case MED_NODAL: + os << "MED_NODAL\n"; + break; + case MED_DESCENDING: + os << "MED_DESCENDING\n"; + break; + default: + break; + } + os << "Entity dimension : " << co._entityDimension << endl; + os << "Number of nodes : " << co._numberOfNodes << endl; + os << "Number of types : " << co._numberOfTypes << endl; + for (int i=0; i!=co._numberOfTypes ; ++i) + os << " -> Type " << co._geometricTypes[i] << " (" << co._type[i].getName() << ") : " + << co._count[i+1]-co._count[i] << " elements" << endl; + + if (co._typeConnectivity == MED_NODAL ) + { + for (int i=0; i myFamilies); + virtual void updateFamily (vector myFamilies); + virtual void updateGroup (vector myFamilies); inline medEntityMesh getEntity () const; inline med_int getNumberOfTypes (medEntityMesh Entity) const; @@ -178,13 +159,13 @@ public: throw (MEDEXCEPTION); medGeometryElement getElementType (medEntityMesh Entity, int Number) const; - inline const int * getGlobalNumberingIndex (medEntityMesh Entity) const + virtual inline const int * getGlobalNumberingIndex (medEntityMesh Entity) const throw (MEDEXCEPTION); - const med_int * getConnectivity (medConnectivity ConnectivityType, + virtual const med_int * getConnectivity (medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type); - const med_int * getConnectivityIndex (medConnectivity ConnectivityType, + virtual const med_int * getConnectivityIndex (medConnectivity ConnectivityType, medEntityMesh Entity); const CELLMODEL & getType (medGeometryElement Type) const; @@ -193,16 +174,16 @@ public: med_int getNumberOfNodesInType (medGeometryElement Type) const; med_int getNumberOfSubCellInType (medGeometryElement Type) const; - med_int getNumberOf (medEntityMesh Entity, + virtual med_int getNumberOf (medEntityMesh Entity, medGeometryElement Type) const; - const med_int* getValue (medConnectivity TypeConnectivity, + virtual const med_int* getValue (medConnectivity TypeConnectivity, medGeometryElement Type); - const med_int* getValueIndex (medConnectivity TypeConnectivity); + virtual const med_int* getValueIndex (medConnectivity TypeConnectivity); - inline const med_int* getReverseConnectivity (medConnectivity ConnectivityType, + virtual inline const med_int* getReverseConnectivity (medConnectivity ConnectivityType, medEntityMesh Entity=MED_CELL) throw (MEDEXCEPTION); - inline const med_int* getReverseConnectivityIndex (medConnectivity ConnectivityType, + virtual inline const med_int* getReverseConnectivityIndex (medConnectivity ConnectivityType, medEntityMesh Entity=MED_CELL) throw (MEDEXCEPTION); @@ -233,6 +214,33 @@ inline med_int CONNECTIVITY::getNumberOfTypes(medEntityMesh Entity) const return _numberOfTypes; else if (_constituent!=NULL) return _constituent->getNumberOfTypes(Entity); + else if (_constituent == NULL) + { + MESSAGE("CONNECTIVITY::getNumberOfTypes : _constituent == NULL"); + try + { + (const_cast (this))->calculateDescendingConnectivity(); + } + catch (MEDEXCEPTION & ex) + { + return 0 ; + } + + SCRUTE(_entityDimension); + + if (_entityDimension != 2 && _entityDimension != 3) return 0; + + try + { + _constituent->calculateConnectivity(MED_NODAL,Entity); + } + catch (MEDEXCEPTION & ex) + { + return 0 ; + } + + return _constituent->getNumberOfTypes(Entity); + } else return 0; // because it is the right information (no exception needed)! } @@ -251,10 +259,23 @@ inline const medGeometryElement* CONNECTIVITY::getGeometricTypes(medEntityMesh E else if (_constituent!=NULL) return _constituent->getGeometricTypes(Entity); else - throw MEDEXCEPTION("Entity not defined !"); + throw MEDEXCEPTION("CONNECTIVITY::getGeometricTypes : Entity not defined !"); } -/*! A DOCUMENTER */ +/*! Returns an array containing the accumulated number of entities sorted by the geometric type./n + + Exemple :/n + + In case of a CONNECTIVITY containing 3*MED_TRIA3 et 2*MED_QUAD4 : /n + int * count = getGlobalNumberingIndex(MED_CELL)/n + count[0] is always set to 1/n + count[1] is set to 1+3=4/n + count[2] is set to 4+2=6 = total number of cells + 1/n + + Note : Not implemented for MED_ALL_ENTITIES. /n + Note : The geometric type order is given by the typedef enum medGeometryElement. + +*/ //----------------------------------------------------------------------------------// inline const int * CONNECTIVITY::getGlobalNumberingIndex(medEntityMesh Entity) const throw (MEDEXCEPTION) @@ -265,7 +286,7 @@ inline const int * CONNECTIVITY::getGlobalNumberingIndex(medEntityMesh Entity) c else if (_constituent!=NULL) return _constituent->getGlobalNumberingIndex(Entity); else - throw MEDEXCEPTION("Entity not defined !"); + throw MEDEXCEPTION("CONNECTIVITY::getGlobalNumberingIndex : Entity not defined !"); } /*! Returns true if a connectivity exists on elements of type "Entity" */ @@ -299,8 +320,8 @@ inline const CELLMODEL * CONNECTIVITY::getCellsTypes(medEntityMesh Entity) const if (_type!=NULL) return _type; else - throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) : - CELLMODEL array is not defined !"); + throw MEDEXCEPTION("CONNECTIVITY::getCellsTypes(medEntityMesh) :" + " CELLMODEL array is not defined !"); else if (_constituent != NULL) return _constituent->getCellsTypes(Entity); @@ -350,5 +371,16 @@ inline const med_int* CONNECTIVITY::getReverseConnectivityIndex(medConnectivity return _constituent->getReverseConnectivityIndex(ConnectivityType,Entity); } + +inline void CONNECTIVITY::setNumberOfNodes(med_int NumberOfNodes) +{ + _numberOfNodes=NumberOfNodes; +} + +inline void CONNECTIVITY::setEntityDimension(med_int EntityDimension) +{ + _entityDimension=EntityDimension; +} + #endif /* CONNECTIVITY_HXX */ diff --git a/src/MEDMEM/MEDMEM_Coordinate.cxx b/src/MEDMEM/MEDMEM_Coordinate.cxx index 686c618bc..caae4090b 100644 --- a/src/MEDMEM/MEDMEM_Coordinate.cxx +++ b/src/MEDMEM/MEDMEM_Coordinate.cxx @@ -1,29 +1,3 @@ -// 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" @@ -33,10 +7,10 @@ using namespace std; /*! Default Constructor : should not be used */ //----------------------------------------------------------// -COORDINATE::COORDINATE():_coordinate(MEDARRAY()), +COORDINATE::COORDINATE():_coordinateSystem(""), + _coordinate(MEDARRAY()), _coordinateName(), _coordinateUnit(), - _coordinateSystem(""), _nodeNumber() //----------------------------------------------------------// { @@ -47,11 +21,11 @@ COORDINATE::COORDINATE():_coordinate(MEDARRAY()), It will create empty array for optional data (nodeNumber..) */ //------------------------------------------------------------------------------// COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode): - _nodeNumber(), - _coordinateUnit(SpaceDimension), - _coordinateSystem(""), - _coordinateName(SpaceDimension), - _coordinate(SpaceDimension,NumberOfNodes,Mode) + _coordinateSystem(""), + _coordinate(SpaceDimension,NumberOfNodes,Mode), + _coordinateName(SpaceDimension), + _coordinateUnit(SpaceDimension), + _nodeNumber() //------------------------------------------------------------------------------// { @@ -102,8 +76,8 @@ void COORDINATE::setCoordinates(MEDARRAY *Coordinate) { const medModeSwitch mode = Coordinate->getMode(); - const int spaceDimension = (int) Coordinate->getLeadingValue(); - const int numberOfNodes = (int) Coordinate->getLengthValue(); + // const int spaceDimension = (int) Coordinate->getLeadingValue(); + // const int numberOfNodes = (int) Coordinate->getLengthValue(); if ( Coordinate->get(mode) != NULL) { MEDARRAY pourAttribut(*Coordinate,false); @@ -196,12 +170,12 @@ void COORDINATE::setNodesNumbers(const int * NodeNumber) int COORDINATE::getSpaceDimension() const { - _coordinate.getLeadingValue() ; + return _coordinate.getLeadingValue() ; } int COORDINATE::getNumberOfNodes() const { - _coordinate.getLengthValue() ; + return _coordinate.getLengthValue() ; } diff --git a/src/MEDMEM/MEDMEM_Coordinate.hxx b/src/MEDMEM/MEDMEM_Coordinate.hxx index 4bb0ee8b3..d77b84839 100644 --- a/src/MEDMEM/MEDMEM_Coordinate.hxx +++ b/src/MEDMEM/MEDMEM_Coordinate.hxx @@ -1,29 +1,3 @@ -// 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.hxx -// Module : MED - /* File Coordinate.hxx $Header$ @@ -66,7 +40,7 @@ protected: Storing the object (not a pointer to this object) is more convenient for memory management. */ - MEDARRAY _coordinate; + mutable MEDARRAY _coordinate; /*! PointerOf to an array of size spaceDimension storing axes names*/ PointerOf _coordinateName; @@ -87,7 +61,7 @@ public : COORDINATE(); COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode); COORDINATE(const COORDINATE & m); - ~COORDINATE(); + virtual ~COORDINATE(); void setCoordinates(MEDARRAY *Coordinate); void setCoordinates(const medModeSwitch Mode, const double *Coordinate); @@ -101,13 +75,13 @@ public : int getSpaceDimension() const; int getNumberOfNodes() const; - const int* getNodesNumbers() const; + virtual const int* getNodesNumbers() const; //const int* getNodesNumbers() ; string getCoordinatesSystem() const; - const double * getCoordinates(medModeSwitch Mode); - double getCoordinate(int Number,int Axis); - const double * getCoordinateAxis(int Axis); + virtual const double * getCoordinates(medModeSwitch Mode); + virtual double getCoordinate(int Number,int Axis); + virtual const double * getCoordinateAxis(int Axis); const string * getCoordinatesNames() const; string getCoordinateName(int Axis) const; diff --git a/src/MEDMEM/MEDMEM_DriverTools.cxx b/src/MEDMEM/MEDMEM_DriverTools.cxx new file mode 100644 index 000000000..82451e50d --- /dev/null +++ b/src/MEDMEM/MEDMEM_DriverTools.cxx @@ -0,0 +1,423 @@ +using namespace std; +#include "MEDMEM_DriverTools.hxx" +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Group.hxx" +#include + + +// Cet opérateur permet d'ordonner les mailles dans un set suivant l'ordre requis par MED +bool _maille::operator < (const _maille& ma) const +{ + // si le type géométrique differe, la comparaison est basée dessus + // sinon on se base sur une comparaison des numéros de sommets + if(geometricType==ma.geometricType) + { + // construction de deux vecteur temporaire contenant les numeros de sommets + // pour faire le tri et les comparaisons + size_t l=sommets.size(); + std::vector v1(l); + std::vector v2(l); + for (unsigned int i=0; i!=l; ++i) + { + v1[i]=sommets[i]->second.number; + v2[i]=ma.sommets[i]->second.number; + } + std::sort(v1.begin(), v1.end()); + std::sort(v2.begin(), v2.end()); + for(std::vector::const_iterator i1=v1.begin(), i2=v2.begin(); i1!=v1.end(); ++i1, ++i2) + if(*i1 != *i2) + return *i1 < *i2; + return false; // cas d'égalité + } + else + return geometricTypedimension(); + medEntityMesh entity; + if (mailleDimension == meshDimension) + entity = MED_CELL; + else + switch (mailleDimension) + { + case 0 : + entity = MED_NODE; + break; + case 1 : + entity = MED_EDGE; + break; + case 2 : + entity = MED_FACE; + break; + default : + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Impossible de determiner l'entite de la maille.")); + } +return entity; + +END_OF(LOC); +}; + +std::ostream& operator << (std::ostream& os, const _maille& ma) +{ + os << "maille " << ma.ordre << " (" << ma.geometricType << ") : < "; + std::vector< std::map::iterator >::const_iterator i=ma.sommets.begin(); + os << (*i++)->second.number ; + for( ; i!=ma.sommets.end(); ++i) + os << ", " << (*i)->second.number; + os << " >"; + return os; +} + +std::ostream& operator << (std::ostream& os, const _groupe& gr) +{ + os << "--- Groupe " << gr.nom << " --- " << std::endl ; + os << " -> liste des sous-groupes : "; + for( std::list::const_iterator i=gr.groupes.begin(); i!=gr.groupes.end(); ++i) + os << *i << " "; + os << std::endl << " -> liste des mailles : " << std::endl; + for( _groupe::mailleIter i=gr.mailles.begin(); i!=gr.mailles.end(); i++) + os << " " << *(*i) << std::endl; + return os; +} + +std::ostream& operator << (std::ostream& os, const _noeud& no) +{ + os << "noeud " << no.number << " : < "; + std::vector::const_iterator i=no.coord.begin(); + os << *i++ ; + for( ; i!=no.coord.end(); ++i) + os << ", " << *i; + os << " >"; + return os; +} + +std::ostream& operator << (std::ostream& os, const _intermediateMED& mi) +{ + os << "Set des mailles : " << std::endl; + for( std::set<_maille>::const_iterator i=mi.maillage.begin(); i!=mi.maillage.end(); ++i) + os << *i << std::endl; + + os << std::endl << "Vector des groupes : " << std::endl; + // for( std::vector<_groupe>::const_iterator i=mi.groupes.begin(); i!=mi.groupes.end(); ++i) + for (unsigned int i=0; i!=mi.groupes.size(); i++) + os << std::setw(3) << i << " " << mi.groupes[i] << std::endl; + + os << std::endl << "map des noeuds : " << std::endl; + for( std::map::const_iterator i=mi.points.begin(); i!=mi.points.end(); ++i) + os << i->second << std::endl; + return os; +} + +void _intermediateMED::numerotationMaillage() +{ + // numerotation des mailles par entité + int i_maille=0; + std::set<_maille>::iterator i=maillage.begin(); + int dimension=i->dimension(); + for( ; i!=maillage.end(); ++i) + { + if ( dimension!=i->dimension() ) // on change d'entite + { + dimension=i->dimension(); + i_maille=0; + } + (*i).ordre=++i_maille; + } +} + +void _intermediateMED::numerotationPoints() +{ + // Fonction de renumerotation des noeuds (necessaire quand il y a des trous dans la numerotation. + int i_noeud=0; + for( std::map::const_iterator i=points.begin(); i!=points.end(); ++i) + i->second.number = ++i_noeud ; +} + + +/*! + * \if developper + * create a MED COORDINATE from the intermediate structure. + * \endif + */ +COORDINATE * +_intermediateMED::getCoordinate() +{ + const medModeSwitch mode=MED_FULL_INTERLACE; + const string coordinateSystem="CARTESIAN"; + + int spaceDimension=points.begin()->second.coord.size(); + int numberOfNodes=points.size(); + + + // creation du tableau des coordonnees en mode MED_FULL_INTERLACE + double * coord = new double[spaceDimension*numberOfNodes]; + int k=0; + for( std::map::const_iterator i=points.begin(); i!=points.end(); ++i, ++k) + std::copy(i->second.coord.begin(), i->second.coord.end(), coord+k*spaceDimension); + + // creation de l'objet COORDINATE + COORDINATE * coordinate = new COORDINATE(spaceDimension, numberOfNodes, mode); + coordinate->setCoordinates(mode,coord); + delete [] coord; + coordinate->setCoordinatesSystem(coordinateSystem); + return coordinate; +} + + + /*! + * \if developper + * create a MED CONNECTIVITY from the intermediate structure. + * for memory optimisation, clear the intermediate structure (the "maillage" set ) + * \endif + */ +CONNECTIVITY * +_intermediateMED::getConnectivity() +{ + const char * LOC = "_intermediateMED::getConnectivity() : "; + BEGIN_OF(LOC); + int numberOfNodes=points.size(); // number of nodes in the mesh + int numberOfTypes=0; + medEntityMesh entity; + medGeometryElement * types=NULL; // pointeurs pour allouer les structures MED + int * count=NULL; + int * connectivity=NULL; + CONNECTIVITY *Connectivity, *Constituent; + + medGeometryElement type=0; // variables de travail + int nbtype=0; + int dimension=0; + bool first = true; + + std::vector vtype; // tableau de travail : stockage des types geometriques pour UNE entite + std::vector vcount; // tableau de travail : nombre d'elements pour chaque type geometrique de vtype + + std::set<_maille>::const_iterator i=maillage.begin(); // iterateurs sur les mailles + std::set<_maille>::const_iterator j=maillage.begin(); + + // renumerote les points de 1 a n (pour le cas ou certains points ne sont pas presents dans le maillage d'origine) + numerotationPoints(); + + do + { + // boucle sur les entites de la structure maillage : + // - on parcourt une premiere fois avec i les mailles d'une entite pour récupérer + // des infos sur les types geometriques, leur nombre et le nombre d'elements. + // - on alloue la connectivite + // - on parcourt une deuxieme fois avec j pour lire les noeuds. + + + type=i->geometricType; // init boucle for + dimension=i->dimension(); + nbtype=0; + vtype.push_back(type); + // Boucle sur i de parcours des mailles d'une entite + // Une entite se termine lorsqu'on atteint la fin de maillage ou lorsque la dimension des mailles change + for( ; i!=maillage.end() && dimension==i->dimension() ; ++i) + { + if (type != i->geometricType) // si changement de type geometrique + { + vcount.push_back(nbtype); // stocke le nombre d'elements de type nbtype + nbtype=0; + type=i->geometricType; + vtype.push_back(type); // stocke le nouveau type geometrique rencontre + } + + ++nbtype; + } + vcount.push_back(nbtype); // n'a pas été stocké dans la boucle + + + // Pour l'entite qu'on vient de parcourir, allocation des tableau et creation de la connectivite +// cout << "Dimension = " << dimension << endl; +// cout << "Nombre de type geometriques : " << vtype.size() << endl; +// for (unsigned k=0; k!=vtype.size(); ++k ) +// cout << " -> " << vtype[k] << " : " << vcount[k] << endl; + + numberOfTypes=vtype.size(); // nombre de types de l'entite + + if ( i==maillage.end() ) // cas de l'entite de plus haut niveau + entity=MED_CELL; + else if (dimension==2 ) + entity=MED_FACE; + else if (dimension==1 ) + entity=MED_EDGE; + else if (dimension==0 ) + entity=MED_NODE; + + Connectivity = new CONNECTIVITY(numberOfTypes,entity); + Connectivity->setEntityDimension(dimension); + Connectivity->setNumberOfNodes(numberOfNodes); + + types = new medGeometryElement[numberOfTypes]; + std::copy(vtype.begin(),vtype.end(),types); + Connectivity->setGeometricTypes(types,entity); + delete [] types; + + count = new int[numberOfTypes+1]; + count[0]=1; + for (unsigned int k=0; k!=vcount.size(); ++k ) + count[k+1]=count[k]+vcount[k]; + Connectivity->setCount (count, entity); + delete [] count; + + for (int k=0; k!=numberOfTypes; ++k ) + { + // pour chaque type geometrique k, copie des sommets dans connectivity et set dans Connectivity + int nbSommetsParMaille = j->sommets.size(); + int nbSommets = vcount[k] * j->sommets.size(); + connectivity = new int[ nbSommets ]; + for (int l=0; l!=vcount[k]; ++l, ++j) + { + for ( unsigned n=0; n != j->sommets.size(); ++n) + connectivity[nbSommetsParMaille*l+n] = j->sommets[n]->second.number; + maillage.erase(j); ; // dangereux, mais optimise la mémoire consommée! + } + + Connectivity->setNodal (connectivity, entity, vtype[k]); + delete [] connectivity; + } + + if (i!=j) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Erreur de lecture des mailles .")); + + if ( ! first) + Connectivity->setConstituent (Constituent); + else + first = false; + Constituent = Connectivity; // stocke Connectivity pour utilisation dans setConstituent lors de la boucle suivante + + vtype.clear(); + vcount.clear(); + + } + while ( i != maillage.end() ); + + END_OF(LOC); + return Connectivity; +} + + + /*! + * \if developper + * fill the arguments vector of groups from the intermediate structure. + * This function must be called before getConnectivity() + * \endif + */ +void +_intermediateMED::getGroups(std::vector & _groupCell, std::vector & _groupFace, std::vector & _groupEdge, std::vector & _groupNode, MESH * _ptrMesh) +{ + const char * LOC = "_intermediateMED::getGroups() : "; + BEGIN_OF(LOC); + if (maillage.size() == 0) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Erreur : il n'y a plus de mailles (appeler getConnectivity apres getGroups!).")); + + int dimension_maillage=maillage.rbegin()->dimension(); + + numerotationMaillage(); // Renumerotation des mailles par entite + + for (unsigned int i=0; i!=this->groupes.size(); ++i) + { + if (groupes[i].mailles.size()==0) + continue; // si le groupe est vide, on passe au suivant + + int nb_geometric_types=1; + _groupe::mailleIter j=groupes[i].mailles.begin(); + // initialise groupe_entity a l'entite de la premiere maille du groupe + medEntityMesh groupe_entity = (**j).getEntity(dimension_maillage); + medGeometryElement geometrictype=(**j).geometricType; + + //Parcours des mailles (a partir de la deuxieme) pour compter les types geometriques + for ( ++j ; j!=groupes[i].mailles.end(); ++j ) + { + //Compte nombre de types geometriques + if ( (**j).geometricType != geometrictype ) // si on change de type geometrique + { + nb_geometric_types++; + geometrictype=(**j).geometricType; + } + + //Test si groupe valide : le groupe doit pointer vers des entites de meme dimension + if ((**j).dimension() != dimension_maillage) + continue; + } + + // le groupe est valide -> on le traite + MED_EN::medGeometryElement * tab_types_geometriques = new MED_EN::medGeometryElement[nb_geometric_types]; + int * tab_index_types_geometriques = new int[nb_geometric_types+1]; + int * tab_numeros_elements = new int[groupes[i].mailles.size()]; + int * tab_nombres_elements = new int[nb_geometric_types]; + + //Remplit tableaux entree des methodes set + int indice_mailles=0; + j=groupes[i].mailles.begin(); + geometrictype=(**j).geometricType; + tab_index_types_geometriques[0]=1; + int indice_types_geometriques=1; + tab_types_geometriques[0]=geometrictype; + //parcours des mailles du groupe + for ( ; j!=groupes[i].mailles.end(); ++j , ++indice_mailles) + { + tab_numeros_elements[indice_mailles]=((**j).ordre); + if ((**j).geometricType != geometrictype) + { + tab_index_types_geometriques[indice_types_geometriques]=indice_mailles+1; + geometrictype=(**j).geometricType; + tab_types_geometriques[indice_types_geometriques]=geometrictype; + ++indice_types_geometriques; + } + } + tab_index_types_geometriques[indice_types_geometriques]=indice_mailles+1; + for (int k=0; k != nb_geometric_types; ++k) + { + tab_nombres_elements[k] = tab_index_types_geometriques[k+1]-tab_index_types_geometriques[k]; + } + + //Determination type entite du groupe + vector * vect_group; + switch ( groupe_entity ) + { + case MED_CELL : + vect_group= & _groupCell; + break; + case MED_FACE : + vect_group= & _groupFace; + break; + case MED_EDGE : + vect_group= & _groupEdge; + break; + case MED_NODE : + vect_group= & _groupNode; + break; + } + //Creation nouveau groupe MED + GROUP * new_group = new GROUP(); + //Appel methodes set + new_group->setTotalNumberOfElements(groupes[i].mailles.size()); + new_group->setName(groupes[i].nom); + new_group->setMesh(_ptrMesh); + new_group->setNumberOfGeometricType(nb_geometric_types); + new_group->setGeometricType(tab_types_geometriques); + new_group->setNumberOfElements(tab_nombres_elements); + new_group->setNumber(tab_index_types_geometriques,tab_numeros_elements); + new_group->setEntity(groupe_entity); + new_group->setAll(groupes[i].mailles.size() == maillage.size()); + vect_group->push_back(new_group); + delete [] tab_types_geometriques; + delete [] tab_index_types_geometriques; + delete [] tab_numeros_elements; + delete [] tab_nombres_elements; + } + + END_OF(LOC); +} + +///// diff --git a/src/MEDMEM/MEDMEM_DriverTools.hxx b/src/MEDMEM/MEDMEM_DriverTools.hxx new file mode 100644 index 000000000..7ea40d0e1 --- /dev/null +++ b/src/MEDMEM/MEDMEM_DriverTools.hxx @@ -0,0 +1,91 @@ +#ifndef DRIVERTOOLS_HXX +#define DRIVERTOOLS_HXX + + +#include "MEDMEM_define.hxx" +#include "MEDMEM_Exception.hxx" +#include +#include +#include +#include +#include +#include + +class MESH; +class CONNECTIVITY; +class COORDINATE; +class GROUP; + +struct _noeud +{ + mutable int number; + std::vector coord; +}; + +struct _maille +{ + typedef std::map::iterator iter; + MED_EN::medGeometryElement geometricType; + std::vector< iter > sommets; + mutable unsigned ordre; // l'ordre est fixé après insertion dans le set, et ne change ni l'état, ni l'ordre -> mutable + + _maille(MED_EN::medGeometryElement _geometricType, size_t nelem) : geometricType(_geometricType),ordre(0) + { + sommets.reserve(nelem); + }; + int dimension() const // retourne la dimension de la maille + { + return geometricType/100; + }; + bool operator < (const _maille& ma) const; + MED_EN::medEntityMesh getEntity(const int meshDimension) const throw (MEDEXCEPTION); +}; + +struct _mailleIteratorCompare // pour ordonner le set d'iterateurs sur mailles +{ + bool operator () (std::set<_maille>::iterator i1, std::set<_maille>::iterator i2) + { + return *i1<*i2; + } +}; + +struct _groupe +{ + typedef std::set< std::set<_maille>::iterator>::const_iterator mailleIter; + std::string nom; + std::set< std::set<_maille>::iterator, _mailleIteratorCompare > mailles; // iterateurs sur les mailles composant le groupe + std::list groupes; // indices des sous-groupes composant le groupe +}; + +/*! + * \if developper + * Intermediate structure used by drivers to store data read from the other format file. + * The structure provides functions that transform the stored data to the MED format : + * getCoordinate(), getConnectivity(), getGroups(). + * The elements inserted in maillage and points are automaticaly ordered. + * Renumbering are performed by getConnectivity & getGroups before writing the MED structures. + * Read the conception ducumentation for more details. + * \endif + */ +struct _intermediateMED +{ + std::set<_maille> maillage; + std::vector<_groupe> groupes; + std::map< int, _noeud > points; + + CONNECTIVITY * getConnectivity(); // set MED connectivity from the intermediate structure + COORDINATE * getCoordinate(); // set MED coordinate from the intermediate structure + void getGroups(std::vector & _groupCell, std::vector & _groupFace, std::vector & _groupEdge, std::vector & _groupNode, MESH * _ptrMesh); + + // used by previous functions to renumber points & mesh. + void numerotationMaillage(); + void numerotationPoints(); + +}; + +std::ostream& operator << (std::ostream& , const _maille& ); +std::ostream& operator << (std::ostream& , const _groupe& ); +std::ostream& operator << (std::ostream& , const _noeud& ); +std::ostream& operator << (std::ostream& , const _intermediateMED& ); + +#endif /* DRIVERTOOLS_HXX */ diff --git a/src/MEDMEM/MEDMEM_DriversDef.cxx b/src/MEDMEM/MEDMEM_DriversDef.cxx index 9ca1920f2..3eb13e685 100644 --- a/src/MEDMEM/MEDMEM_DriversDef.cxx +++ b/src/MEDMEM/MEDMEM_DriversDef.cxx @@ -1,29 +1,3 @@ -// 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_DriversDef.cxx -// Module : MED - using namespace std; #include "MEDMEM_DriversDef.hxx" @@ -53,7 +27,14 @@ GEO_NAME::GEO_NAME() : map() table[(int)MED_PYRA13 ] = "MED_PYRA13" ; assert( table.find( (int)MED_PYRA13 ) != table.end() ) ; } - + +GEO_NAME::~GEO_NAME() +{ + MESSAGE(" destructor GEO_NAME::~GEO_NAME() "<< size() ); + clear(); + MESSAGE(" end of destructor GEO_NAME::~GEO_NAME() "<< size() ); +} + string & GEO_NAME::operator[]( const med_geometrie_element &c ) const { map &table = (map&)*this ; @@ -73,6 +54,14 @@ ENT_NAME::ENT_NAME() : map() table[(int)MED_ARETE ] = "MED_ARETE"; table[(int)MED_NOEUD ] = "MED_NOEUD"; } + +ENT_NAME::~ENT_NAME() +{ + MESSAGE(" destructor ENT_NAME::~ENT_NAME() "<< size() ); + clear(); + MESSAGE(" end of destructor ENT_NAME::~ENT_NAME() "<< size() ); +} + string & ENT_NAME::operator[]( const med_entite_maillage &c ) const { map &table = (map&)*this ; @@ -83,26 +72,47 @@ string & ENT_NAME::operator[]( const med_entite_maillage &c ) const MESH_ENTITIES::MESH_ENTITIES () : map >() { // Override the const declaration in order to used the find method below - map > &table = (map >&)*this ; + // map > &table = (map >&)*this ; unused local variable // Initialize the value associated with the ROUGE_ key ( use the private operator = ) { - const med_geometrie_element T[] = { MED_POINT1, MED_SEG2, MED_SEG3, MED_TRIA3, - MED_TRIA6, MED_QUAD4, MED_QUAD8, MED_TETRA4, - MED_TETRA10, MED_HEXA8, MED_HEXA20, MED_PENTA6, - MED_PENTA15,MED_PYRA5, MED_PYRA13 }; + const med_geometrie_element T[] = { + MED_POINT1, + MED_SEG2, + MED_SEG3, + MED_TRIA3, + MED_QUAD4, + MED_TRIA6, + MED_QUAD8, + MED_TETRA4, + MED_PYRA5, + MED_PENTA6, + MED_HEXA8, + MED_TETRA10, + MED_PYRA13, + MED_PENTA15, + MED_HEXA20}; + static const list geomList(T,T+sizeof(T)/sizeof(med_geometrie_element)); (*this)[MED_MAILLE] = geomList; } { - const med_geometrie_element T[] = { MED_TRIA3,MED_TRIA6, MED_QUAD4,MED_QUAD8 }; + const med_geometrie_element T[] = { + MED_TRIA3, + MED_QUAD4, + MED_TRIA6, + MED_QUAD8}; + static const list geomList(T,T+sizeof(T)/sizeof(med_geometrie_element)); (*this)[MED_FACE] = geomList; } { - const med_geometrie_element T[] = { MED_SEG2,MED_SEG3 }; + const med_geometrie_element T[] = { + MED_SEG2, + MED_SEG3 }; + static const list geomList(T,T+sizeof(T)/sizeof(med_geometrie_element)); (*this)[MED_ARETE] = geomList; } @@ -116,6 +126,13 @@ MESH_ENTITIES::MESH_ENTITIES () : map >() } +MESH_ENTITIES::~MESH_ENTITIES() +{ + MESSAGE(" destructor MESH_ENTITIES::~MESH_ENTITIES() "<< size() ); + clear(); + MESSAGE(" end of destructor MESH_ENTITIES::~MESH_ENTITIES() "<< size() ); +} + const list & MESH_ENTITIES::operator[]( const med_entite_maillage &c ) const { map > &table = (map >&)*this ; diff --git a/src/MEDMEM/MEDMEM_DriversDef.hxx b/src/MEDMEM/MEDMEM_DriversDef.hxx index 873bb8689..c058d546e 100644 --- a/src/MEDMEM/MEDMEM_DriversDef.hxx +++ b/src/MEDMEM/MEDMEM_DriversDef.hxx @@ -1,29 +1,3 @@ -// 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_DriversDef.hxx -// Module : MED - # ifndef DRIVERS_DEF_HXX # define DRIVERS_DEF_HXX @@ -35,6 +9,7 @@ using namespace std ; #include "MEDMEM_define.hxx" +#include "utilities.h" namespace MED_FR { @@ -53,6 +28,7 @@ class GEO_NAME : public map public : GEO_NAME(); + ~GEO_NAME(); string & operator[]( const MED_FR::med_geometrie_element &c ) const; } ; @@ -76,6 +52,7 @@ class ENT_NAME : public map public : ENT_NAME (); + ~ENT_NAME(); string & operator[]( const MED_FR::med_entite_maillage &c ) const; } ; @@ -100,6 +77,7 @@ class MESH_ENTITIES : public map public : MESH_ENTITIES (); + ~MESH_ENTITIES(); const list & operator[]( const MED_FR::med_entite_maillage &c ) const; private: diff --git a/src/MEDMEM/MEDMEM_Exception.cxx b/src/MEDMEM/MEDMEM_Exception.cxx index 915f4fc75..bafedca54 100644 --- a/src/MEDMEM/MEDMEM_Exception.cxx +++ b/src/MEDMEM/MEDMEM_Exception.cxx @@ -1,29 +1,3 @@ -// 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.cxx -// Module : MED - using namespace std; /* File MedException.cxx diff --git a/src/MEDMEM/MEDMEM_Exception.hxx b/src/MEDMEM/MEDMEM_Exception.hxx index aa4245f61..e6eb49a4c 100644 --- a/src/MEDMEM/MEDMEM_Exception.hxx +++ b/src/MEDMEM/MEDMEM_Exception.hxx @@ -1,29 +1,3 @@ -// 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$ diff --git a/src/MEDMEM/MEDMEM_Family.cxx b/src/MEDMEM/MEDMEM_Family.cxx index d85fa5ec5..45d647b2f 100644 --- a/src/MEDMEM/MEDMEM_Family.cxx +++ b/src/MEDMEM/MEDMEM_Family.cxx @@ -1,29 +1,3 @@ -// 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_Family.cxx -// Module : MED - using namespace std; /* File MEDMEM_Family.cxx diff --git a/src/MEDMEM/MEDMEM_Family.hxx b/src/MEDMEM/MEDMEM_Family.hxx index 02a40a729..2be15c6c0 100644 --- a/src/MEDMEM/MEDMEM_Family.hxx +++ b/src/MEDMEM/MEDMEM_Family.hxx @@ -1,29 +1,3 @@ -// 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_Family.hxx -// Module : MED - #ifndef FAMILY_HXX #define FAMILY_HXX @@ -41,7 +15,7 @@ */ -class FAMILY : public SUPPORT +class FAMILY : virtual public SUPPORT { protected : /*! @@ -98,6 +72,7 @@ public: /*! \if developper Constructor to use with med driver. + \endif */ FAMILY( MESH* Mesh, int Identifier, string Name, int NumberOfAttribute, int *AttributeIdentifier, @@ -116,7 +91,7 @@ public: FAMILY(const SUPPORT & s); /*! Destructor. */ - ~FAMILY(); + virtual ~FAMILY(); FAMILY & operator=(const FAMILY &fam); friend ostream & operator<<(ostream &os, FAMILY &my) ; diff --git a/src/MEDMEM/MEDMEM_Field.cxx b/src/MEDMEM/MEDMEM_Field.cxx index 18191c26d..7c52fc42f 100644 --- a/src/MEDMEM/MEDMEM_Field.cxx +++ b/src/MEDMEM/MEDMEM_Field.cxx @@ -1,29 +1,3 @@ -// 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_Field.cxx -// Module : MED - using namespace std; #include "MEDMEM_Field.hxx" @@ -131,26 +105,176 @@ FIELD_::~FIELD_() MESSAGE("In this object FIELD_ there is(are) " << _drivers.size() << " driver(s)"); - for (int index=0; index < _drivers.size(); index++ ) + for (unsigned int index=0; index < _drivers.size(); index++ ) { SCRUTE(_drivers[index]); if ( _drivers[index] != NULL) delete _drivers[index]; } } +/*! + \if developper + PROVISOIRE : retourne des volumes, surfaces ou longueurs suivant les cas + \endif +*/ +FIELD* FIELD_::_getFieldSize() const +{ + FIELD* p_field_size; + switch (getSupport()->getEntity()) + { + case MED_CELL : + switch (getSupport()->getMesh()->getSpaceDimension() ) + { + case 1: + p_field_size=getSupport()->getMesh()->getLength(getSupport() ); + break; + case 2: + p_field_size=getSupport()->getMesh()->getArea(getSupport() ); + break; + case 3: + p_field_size=getSupport()->getMesh()->getVolume(getSupport() ); + break; + } + break; + + case MED_FACE : + p_field_size=getSupport()->getMesh()->getArea(getSupport() ); + break; + + case MED_EDGE : + p_field_size=getSupport()->getMesh()->getLength(getSupport() ); + break; + } + return p_field_size; +} + + +/*! + \if developper + Check up the compatibility of field before computing sobolev norm + \endif +*/ +void FIELD_::_checkNormCompatibility(const FIELD* support_volume) const throw (MEDEXCEPTION) +{ + string diagnosis; + if( getSupport()->getEntity() == MED_NODE ) + { + diagnosis="Cannot compute sobolev norm on a field "+getName()+ + " : it has support on nodes!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + + if (getNumberOfValues()*getNumberOfComponents()<= 0) // Size of array has to be strictly positive + { + diagnosis="Cannot compute the norm of "+getName()+ + " : it size is non positive!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + + const int* nbGauss=getSupport()->getNumberOfGaussPoint(); + for (int i=0; igetNumberOfTypes(); ++i) + if(nbGauss[i]!=1) + { + diagnosis="Cannot compute Lnorm of "+getName()+ + " : Gauss numbers greater than one are not yet implemented!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + + if(support_volume) // if the user has supplied the volume + { + if(support_volume->getSupport()!=getSupport()) + { + diagnosis="Cannot compute Lnorm of "+getName()+ + " : the volume furnished has not the same support!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + if(support_volume->getNumberOfValues()!=getNumberOfValues()) + { + diagnosis="Cannot compute Lnorm of "+getName()+ + " : the volume furnished has not the same number of values!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + } + +} + +/*! + \if developper + Check up the compatibility of fields before performing an arithmetic operation + \endif +*/ +void FIELD_::_checkFieldCompatibility(const FIELD_& m, const FIELD_& n ) throw (MEDEXCEPTION) +{ + string diagnosis; + + // check-up, fill diagnosis if some incompatibility is found. + if(m._support != n._support) + diagnosis+="They don't have the same support!"; + else if(m._numberOfComponents != n._numberOfComponents) + diagnosis+="They don't have the same number of components!"; + else if(m._numberOfValues != n._numberOfValues) + diagnosis+="They don't have the same number of values!"; + else + { + for(int i=0; i +#include +#include #include "utilities.h" #include "MEDMEM_Exception.hxx" @@ -46,6 +22,9 @@ #include "MEDMEM_MedFieldDriver.hxx" #include "MEDMEM_MedMedDriver.hxx" +#include "MEDMEM_VtkFieldDriver.hxx" +#include "MEDMEM_VtkMedDriver.hxx" + using namespace MED_EN; /*! @@ -143,9 +122,17 @@ protected: double _time; int _orderNumber ; + // _valueType should be a static const. Here is an initialization exemple + // template < classType T > struct SET_VALUE_TYPE { static const med_type_champ _valueType = 0; } + // template < > struct SET_VALUE_TYPE { static const med_type_champ _valueType = MED_EN::MED_REEL64; } + // template < > struct SET_VALUE_TYPE { static const med_type_champ _valueType = MED_EN::MED_INT32; } + // static const med_type_champ _valueType = SET_VALUE_TYPE ::_valueType; med_type_champ _valueType ; vector _drivers; // Storage of the drivers currently in use + static void _checkFieldCompatibility(const FIELD_& m, const FIELD_& n ) throw (MEDEXCEPTION); + void _checkNormCompatibility(const FIELD* p_field_volume=NULL) const throw (MEDEXCEPTION); + FIELD* _getFieldSize() const; public: @@ -153,6 +140,8 @@ public: friend class MED_MED_WRONLY_DRIVER; friend class MED_MED_RDWR_DRIVER; + friend class VTK_MED_DRIVER; + /*! Constructor. */ @@ -169,7 +158,7 @@ public: /*! Destructor. */ - ~FIELD_(); + virtual ~FIELD_(); // virtual void setIterationNumber (int IterationNumber); // virtual void setOrderNumber (int OrderNumber); @@ -182,37 +171,41 @@ public: virtual int addDriver( GENDRIVER & driver); virtual void read (const GENDRIVER &); virtual void read(int index=0); + virtual void openAppend( void ); virtual void write(const GENDRIVER &); virtual void write(int index=0, const string & driverName=""); - inline void setName(string Name); + virtual void writeAppend(const GENDRIVER &); + virtual void writeAppend(int index=0, const string & driverName=""); + + inline void setName(const string Name); inline string getName() const; - inline void setDescription(string Description); + inline void setDescription(const string Description); inline string getDescription() const; inline const SUPPORT * getSupport() const; - inline void setSupport(SUPPORT * support); - inline void setNumberOfComponents(int NumberOfComponents); + inline void setSupport(const SUPPORT * support); + inline void setNumberOfComponents(const int NumberOfComponents); inline int getNumberOfComponents() const; - inline void setNumberOfValues(int NumberOfValues); + inline void setNumberOfValues(const int NumberOfValues); inline int getNumberOfValues() const; // inline void setComponentType(int *ComponentType); // inline int * getComponentType() const; // inline int getComponentTypeI(int i) const; - inline void setComponentsNames(string * ComponentsNames); - inline void setComponentName(int i, string ComponentName); + inline void setComponentsNames(const string * ComponentsNames); + inline void setComponentName(int i, const string ComponentName); inline const string * getComponentsNames() const; inline string getComponentName(int i) const; - inline void setComponentsDescriptions(string *ComponentsDescriptions); - inline void setComponentDescription(int i, string ComponentDescription); + inline void setComponentsDescriptions(const string * ComponentsDescriptions); + inline void setComponentDescription(int i, const string ComponentDescription); inline const string * getComponentsDescriptions() const; inline string getComponentDescription(int i) const; // provisoire : en attendant de regler le probleme des unites ! - inline void setComponentsUnits(UNIT * ComponentsUnits); + inline void setComponentsUnits(const UNIT * ComponentsUnits); inline const UNIT * getComponentsUnits() const; inline const UNIT * getComponentUnit(int i) const; - inline void setMEDComponentsUnits(string * MEDComponentsUnits); - inline void setMEDComponentUnit(int i, string MEDComponentUnit); + inline void setMEDComponentsUnits(const string * MEDComponentsUnits); + inline void setMEDComponentUnit(int i, const string MEDComponentUnit); inline const string * getMEDComponentsUnits() const; inline string getMEDComponentUnit(int i) const; @@ -223,7 +216,7 @@ public: inline void setOrderNumber(int OrderNumber); inline int getOrderNumber() const; - inline void setValueType (med_type_champ ValueType) ; + inline void setValueType (const med_type_champ ValueType) ; inline med_type_champ getValueType () const; }; @@ -238,7 +231,7 @@ public: /*! Set FIELD name. */ -inline void FIELD_::setName(string Name) +inline void FIELD_::setName(const string Name) { _name=Name; } @@ -252,7 +245,7 @@ inline string FIELD_::getName() const /*! Set FIELD description. */ -inline void FIELD_::setDescription(string Description) +inline void FIELD_::setDescription(const string Description) { _description=Description; } @@ -313,7 +306,7 @@ inline int FIELD_::getNumberOfValues() const Duplicate the ComponentsNames string array to put components names in FIELD. ComponentsNames size must be equal to number of components. */ -inline void FIELD_::setComponentsNames(string * ComponentsNames) +inline void FIELD_::setComponentsNames(const string * ComponentsNames) { if (NULL == _componentsNames) _componentsNames = new string[_numberOfComponents] ; @@ -325,7 +318,7 @@ inline void FIELD_::setComponentsNames(string * ComponentsNames) i must be >=1 and <= number of components. */ -inline void FIELD_::setComponentName(int i, string ComponentName) +inline void FIELD_::setComponentName(int i, const string ComponentName) { _componentsNames[i-1]=ComponentName ; } @@ -352,7 +345,7 @@ inline string FIELD_::getComponentName(int i) const descriptions in FIELD. ComponentsDescriptions size must be equal to number of components. */ -inline void FIELD_::setComponentsDescriptions(string *ComponentsDescriptions) +inline void FIELD_::setComponentsDescriptions(const string * ComponentsDescriptions) { if (NULL == _componentsDescriptions) _componentsDescriptions = new string[_numberOfComponents] ; @@ -364,7 +357,7 @@ inline void FIELD_::setComponentsDescriptions(string *ComponentsDescriptions) i must be >=1 and <= number of components. */ -inline void FIELD_::setComponentDescription(int i,string ComponentDescription) +inline void FIELD_::setComponentDescription(int i,const string ComponentDescription) { _componentsDescriptions[i-1]=ComponentDescription ; } @@ -393,7 +386,7 @@ inline string FIELD_::getComponentDescription(int i) const units in FIELD. ComponentsUnits size must be equal to number of components. */ -inline void FIELD_::setComponentsUnits(UNIT * ComponentsUnits) +inline void FIELD_::setComponentsUnits(const UNIT * ComponentsUnits) { if (NULL == _componentsUnits) _componentsUnits = new UNIT[_numberOfComponents] ; @@ -424,7 +417,7 @@ inline const UNIT * FIELD_::getComponentUnit(int i) const MEDComponentsUnits size must be equal to number of components. */ -inline void FIELD_::setMEDComponentsUnits(string * MEDComponentsUnits) +inline void FIELD_::setMEDComponentsUnits(const string * MEDComponentsUnits) { if (NULL == _MEDComponentsUnits) _MEDComponentsUnits = new string[_numberOfComponents] ; @@ -436,7 +429,7 @@ inline void FIELD_::setMEDComponentsUnits(string * MEDComponentsUnits) i must be >=1 and <= number of components. */ -inline void FIELD_::setMEDComponentUnit(int i, string MEDComponentUnit) +inline void FIELD_::setMEDComponentUnit(int i, const string MEDComponentUnit) { _MEDComponentsUnits[i-1]=MEDComponentUnit ; } @@ -512,7 +505,7 @@ inline const SUPPORT * FIELD_::getSupport() const Reference is not duplicate, so it must not be deleted. */ -inline void FIELD_::setSupport(SUPPORT * support) +inline void FIELD_::setSupport(const SUPPORT * support) { _support = support ; } @@ -526,7 +519,7 @@ inline med_type_champ FIELD_::getValueType () const /*! Set the FIELD med value type (MED_INT32 or MED_REEL64). */ -inline void FIELD_::setValueType (med_type_champ ValueType) +inline void FIELD_::setValueType (const med_type_champ ValueType) { _valueType = ValueType ; } @@ -569,6 +562,8 @@ protected: // static INSTANCE_DE inst_med_rdonly ; static INSTANCE_DE > inst_med ; + static INSTANCE_DE > inst_vtk ; + static const INSTANCE * const instances[] ; // ------ End of Drivers Management Part @@ -577,19 +572,52 @@ protected: MEDARRAY *_value ; private: + void _operation(const FIELD& m,const FIELD& n, const medModeSwitch mode, char* Op); + void _operationInitialize(const FIELD& m,const FIELD& n, char* Op); + void _add_in_place(const FIELD& m,const FIELD& n, const medModeSwitch mode); + void _sub_in_place(const FIELD& m,const FIELD& n, const medModeSwitch mode); + void _mul_in_place(const FIELD& m,const FIELD& n, const medModeSwitch mode); + void _div_in_place(const FIELD& m,const FIELD& n, const medModeSwitch mode); //setValueType() ; public: FIELD(); FIELD(const FIELD &m); FIELD & operator=(const FIELD &m); // A FAIRE - FIELD(const SUPPORT * Support, const int NumberOfComponents); // Ajout NB Constructeur FIELD avec allocation de memoire de tous ses attribut + FIELD(const SUPPORT * Support, const int NumberOfComponents, const medModeSwitch Mode=MED_FULL_INTERLACE) throw (MEDEXCEPTION) ; // Ajout NB Constructeur FIELD avec allocation de memoire de tous ses attribut FIELD(const SUPPORT * Support, driverTypes driverType, - const string & fileName="", const string & fieldName=""); + const string & fileName="", const string & fieldName="", + const int iterationNumber = -1, const int orderNumber = -1) + throw (MEDEXCEPTION); ~FIELD(); + const FIELD operator+(const FIELD& m) const; + const FIELD operator-(const FIELD& m) const; + const FIELD operator*(const FIELD& m) const; + const FIELD operator/(const FIELD& m) const; + const FIELD operator-() const; + FIELD& operator+=(const FIELD& m); + FIELD& operator-=(const FIELD& m); + FIELD& operator*=(const FIELD& m); + FIELD& operator/=(const FIELD& m); + static FIELD* add(const FIELD& m, const FIELD& n); + static FIELD* sub(const FIELD& m, const FIELD& n); + static FIELD* mul(const FIELD& m, const FIELD& n); + static FIELD* div(const FIELD& m, const FIELD& n); + double normMax() const throw (MEDEXCEPTION); + double norm2() const throw (MEDEXCEPTION); + void applyLin(T a, T b); + template void applyFunc(); + static FIELD* scalarProduct(const FIELD& m, const FIELD& n); + double normL2(int component, const FIELD * p_field_volume=NULL) const; + double normL2(const FIELD * p_field_volume=NULL) const; + double normL1(int component, const FIELD * p_field_volume=NULL) const; + double normL1(const FIELD * p_field_volume=NULL) const; + friend class MED_FIELD_RDONLY_DRIVER; friend class MED_FIELD_WRONLY_DRIVER; + + friend class VTK_FIELD_DRIVER; //friend class MED_FIELD_RDWR_DRIVER ; void init (); @@ -609,6 +637,9 @@ public: inline void write(int index=0, const string & driverName = ""); inline void write(const GENDRIVER &); + inline void writeAppend(int index=0, const string & driverName = ""); + inline void writeAppend(const GENDRIVER &); + inline void setValue(MEDARRAY *Value); inline MEDARRAY* getvalue() const; @@ -678,7 +709,7 @@ public: // -------------------- /*! - Constructor. + Constructor with no parameter, most of the attribut members are set to NULL. */ template FIELD::FIELD(): _value((MEDARRAY*)NULL) @@ -687,13 +718,15 @@ template FIELD::FIELD(): } /*! - Constructor. + Constructor with parameters such that all attrribut are set but the _value + attrribut is allocated but not set. */ template FIELD::FIELD(const SUPPORT * Support, - const int NumberOfComponents): + const int NumberOfComponents, const medModeSwitch Mode) throw (MEDEXCEPTION) : FIELD_(Support, NumberOfComponents) { - BEGIN_OF("FIELD::FIELD(const SUPPORT * Support, const int NumberOfComponents)"); + BEGIN_OF("FIELD::FIELD(const SUPPORT * Support, const int NumberOfComponents, const medModeSwitch Mode)"); + SCRUTE(this); try { _numberOfValues = Support->getNumberOfElements(MED_ALL_ELEMENTS); @@ -704,12 +737,12 @@ template FIELD::FIELD(const SUPPORT * Support, } MESSAGE("FIELD : constructeur : "<< _numberOfValues <<" et "<< NumberOfComponents); if (0<_numberOfValues) { - _value = new MEDARRAY::MEDARRAY(_numberOfComponents,_numberOfValues); + _value = new MEDARRAY(_numberOfComponents,_numberOfValues,Mode); _isRead = true ; } else _value = (MEDARRAY*)NULL ; - END_OF("FIELD::FIELD(const SUPPORT * Support, const int NumberOfComponents)"); + END_OF("FIELD::FIELD(const SUPPORT * Support, const int NumberOfComponents, const medModeSwitch Mode)"); } /*! @@ -726,10 +759,11 @@ template void FIELD::init () template FIELD::FIELD(const FIELD & m): FIELD_((FIELD_) m) { + MESSAGE("Constructeur FIELD de recopie"); if (m._value != NULL) { // copie only default ! - _value = new MEDARRAY::MEDARRAY(* m._value,false); + _value = new MEDARRAY(* m._value,false); } else _value = (MEDARRAY *) NULL; @@ -741,17 +775,872 @@ template FIELD::FIELD(const FIELD & m): */ template FIELD & FIELD::operator=(const FIELD &m) { + MESSAGE("Appel de FIELD::operator="); +} + +/*! + Overload addition operator. + This operation is authorized only for compatible fields that have the same support. + The compatibility checking includes equality tests of the folowing data members:/n + - _support + - _numberOfComponents + - _numberOfValues + - _componentsTypes + - _MEDComponentsUnits. + + The data members of the returned field are initialized, based on the first field, except for the name, + which is the combination of the two field's names and the operator. + Advised Utilisation in C++ : FIELD c = a + b; /n + In this case, the (recent) compilators perform optimisation and don't call the copy constructor. + When using python, this operator calls the copy constructor in any case. + The user has to be aware that when using operator + in associatives expressions like + a = b + c + d +e; /n + no optimisation is performed : the evaluation of last expression requires the construction of + 3 temporary fields. +*/ +template +const FIELD FIELD::operator+(const FIELD & m) const +{ + BEGIN_OF("FIELD::operator+(const FIELD & m)"); + FIELD_::_checkFieldCompatibility(*this, m); // may throw exception + + // Select mode : avoid if possible any calculation of other mode for fields m or *this + medModeSwitch mode; + if(this->getvalue()->getMode()==m.getvalue()->getMode() || this->getvalue()->isOtherCalculated()) + mode=m.getvalue()->getMode(); + else + mode=this->getvalue()->getMode(); + + // Creation of the result - memory is allocated by FIELD constructor + FIELD result(this->getSupport(),this->getNumberOfComponents(),mode); + //result._operation(*this,m,mode,"+"); // perform Atribute's initialization & addition + result._operationInitialize(*this,m,"+"); // perform Atribute's initialization + result._add_in_place(*this,m,mode); // perform addition + + END_OF("FIELD::operator+(const FIELD & m)"); + return result; +} + +/*! Overloaded Operator += + * Operations are directly performed in the first field's array. + * This operation is authorized only for compatible fields that have the same support. + */ +template +FIELD& FIELD::operator+=(const FIELD & m) +{ + BEGIN_OF("FIELD::operator+=(const FIELD & m)"); + FIELD_::_checkFieldCompatibility(*this, m); // may throw exception + + // We choose to keep *this mode, even if it may cost a re-calculation for m + medModeSwitch mode=this->getvalue()->getMode(); + const T* value1=m.getValue(mode); // get pointers to the values we are adding + + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + const int size=getNumberOfValues()*getNumberOfComponents(); // size of array + const T* endV=value+size; // pointer to the end of value + for(;value!=endV; value1++,value++) + *value += *value1; + // if it exists, the alternate mode needs to be cleared because it is not up-to-date anymore + this->getvalue()->clearOtherMode(); + END_OF("FIELD::operator+=(const FIELD & m)"); + return *this; +} + + +/*! Addition of fields. Static member function. + * The function return a pointer to a new created field that holds the addition. + * Data members are checked for compatibility and initialized. + * The user is in charge of memory deallocation. + */ +template +FIELD* FIELD::add(const FIELD& m, const FIELD& n) +{ + BEGIN_OF("FIELD::add(const FIELD & m, const FIELD& n)"); + FIELD_::_checkFieldCompatibility(m, n); // may throw exception + + // Select mode : avoid if possible any calculation of other mode for fields m or *this + medModeSwitch mode; + if(m.getvalue()->getMode()==n.getvalue()->getMode() || n.getvalue()->isOtherCalculated()) + mode=m.getvalue()->getMode(); + else + mode=n.getvalue()->getMode(); + + // Creation of a new field + FIELD* result = new FIELD(m.getSupport(),m.getNumberOfComponents(),mode); + result->_operationInitialize(m,n,"+"); // perform Atribute's initialization + result->_add_in_place(m,n,mode); // perform addition + + END_OF("FIELD::add(const FIELD & m, const FIELD& n)"); + return result; +} + +/*! + Overload substraction operator. + This operation is authorized only for compatible fields that have the same support. + The compatibility checking includes equality tests of the folowing data members:/n + - _support + - _numberOfComponents + - _numberOfValues + - _componentsTypes + - _MEDComponentsUnits. + + The data members of the returned field are initialized, based on the first field, except for the name, + which is the combination of the two field's names and the operator. + Advised Utilisation in C++ : FIELD c = a - b; /n + In this case, the (recent) compilators perform optimisation and don't call the copy constructor. + When using python, this operator calls the copy constructor in any case. + The user has to be aware that when using operator - in associatives expressions like + a = b - c - d -e; /n + no optimisation is performed : the evaluation of last expression requires the construction of + 3 temporary fields. +*/ +template +const FIELD FIELD::operator-(const FIELD & m) const +{ + BEGIN_OF("FIELD::operator-(const FIELD & m)"); + FIELD_::_checkFieldCompatibility(*this, m); // may throw exception + + // Select mode : avoid if possible any calculation of other mode for fields m or *this + medModeSwitch mode; + if(this->getvalue()->getMode()==m.getvalue()->getMode() || this->getvalue()->isOtherCalculated()) + mode=m.getvalue()->getMode(); + else + mode=this->getvalue()->getMode(); + + // Creation of the result - memory is allocated by FIELD constructor + FIELD result(this->getSupport(),this->getNumberOfComponents(),mode); + //result._operation(*this,m,mode,"-"); // perform Atribute's initialization & substraction + result._operationInitialize(*this,m,"-"); // perform Atribute's initialization + result._sub_in_place(*this,m,mode); // perform substracion + + END_OF("FIELD::operator-(const FIELD & m)"); + return result; +} + +template +const FIELD FIELD::operator-() const +{ + BEGIN_OF("FIELD::operator-()"); + + medModeSwitch mode=this->getvalue()->getMode(); + // Creation of the result - memory is allocated by FIELD constructor + FIELD result(this->getSupport(),this->getNumberOfComponents(),mode); + // Atribute's initialization + result.setName("- "+getName()); + result.setComponentsNames(getComponentsNames()); + // not yet implemented setComponentType(getComponentType()); + result.setComponentsDescriptions(getComponentsDescriptions()); + result.setMEDComponentsUnits(getMEDComponentsUnits()); + result.setComponentsUnits(getComponentsUnits()); + result.setIterationNumber(getIterationNumber()); + result.setTime(getTime()); + result.setOrderNumber(getOrderNumber()); + result.setValueType(getValueType()); + + const T* value1=getValue(mode); + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (result.getValue(mode)); + const int size=getNumberOfValues()*getNumberOfComponents(); // size of array + const T* endV=value+size; // pointer to the end of value + + for(;value!=endV; value1++,value++) + *value = -(*value1); + END_OF("FIELD::operator-=(const FIELD & m)"); + return result; +} + +/*! Overloaded Operator -= + * Operations are directly performed in the first field's array. + * This operation is authorized only for compatible fields that have the same support. + */ +template +FIELD& FIELD::operator-=(const FIELD & m) +{ + BEGIN_OF("FIELD::operator-=(const FIELD & m)"); + FIELD_::_checkFieldCompatibility(*this, m); // may throw exception + + // We choose to keep *this mode, even if it may cost a re-calculation for m + medModeSwitch mode=this->getvalue()->getMode(); + const T* value1=m.getValue(mode); // get pointers to the values we are adding + + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + const int size=getNumberOfValues()*getNumberOfComponents(); // size of array + const T* endV=value+size; // pointer to the end of value + + for(;value!=endV; value1++,value++) + *value -= *value1; + // if it exists, the alternate mode needs to be cleared because it is not up-to-date anymore + this->getvalue()->clearOtherMode(); + END_OF("FIELD::operator-=(const FIELD & m)"); + return *this; +} + + +/*! Substraction of fields. Static member function. + * The function return a pointer to a new created field that holds the substraction. + * Data members are checked for compatibility and initialized. + * The user is in charge of memory deallocation. + */ +template +FIELD* FIELD::sub(const FIELD& m, const FIELD& n) +{ + BEGIN_OF("FIELD::sub(const FIELD & m, const FIELD& n)"); + FIELD_::_checkFieldCompatibility(m, n); // may throw exception + + // Select mode : avoid if possible any calculation of other mode for fields m or *this + medModeSwitch mode; + if(m.getvalue()->getMode()==n.getvalue()->getMode() || n.getvalue()->isOtherCalculated()) + mode=m.getvalue()->getMode(); + else + mode=n.getvalue()->getMode(); + + // Creation of a new field + FIELD* result = new FIELD(m.getSupport(),m.getNumberOfComponents(),mode); + result->_operationInitialize(m,n,"-"); // perform Atribute's initialization + result->_sub_in_place(m,n,mode); // perform substraction + + END_OF("FIELD::sub(const FIELD & m, const FIELD& n)"); + return result; +} + +/*! + Overload multiplication operator. + This operation is authorized only for compatible fields that have the same support. + The compatibility checking includes equality tests of the folowing data members:/n + - _support + - _numberOfComponents + - _numberOfValues + - _componentsTypes + - _MEDComponentsUnits. + + The data members of the returned field are initialized, based on the first field, except for the name, + which is the combination of the two field's names and the operator. + Advised Utilisation in C++ : FIELD c = a * b; /n + In this case, the (recent) compilators perform optimisation and don't call the copy constructor. + When using python, this operator calls the copy constructor in any case. + The user has to be aware that when using operator * in associatives expressions like + a = b * c * d *e; /n + no optimisation is performed : the evaluation of last expression requires the construction of + 3 temporary fields. +*/ +template +const FIELD FIELD::operator*(const FIELD & m) const +{ + BEGIN_OF("FIELD::operator*(const FIELD & m)"); + FIELD_::_checkFieldCompatibility(*this, m); // may throw exception + + // Select mode : avoid if possible any calculation of other mode for fields m or *this + medModeSwitch mode; + if(this->getvalue()->getMode()==m.getvalue()->getMode() || this->getvalue()->isOtherCalculated()) + mode=m.getvalue()->getMode(); + else + mode=this->getvalue()->getMode(); + + // Creation of the result - memory is allocated by FIELD constructor + FIELD result(this->getSupport(),this->getNumberOfComponents(),mode); + //result._operation(*this,m,mode,"*"); // perform Atribute's initialization & multiplication + result._operationInitialize(*this,m,"*"); // perform Atribute's initialization + result._mul_in_place(*this,m,mode); // perform multiplication + + END_OF("FIELD::operator*(const FIELD & m)"); + return result; +} + +/*! Overloaded Operator *= + * Operations are directly performed in the first field's array. + * This operation is authorized only for compatible fields that have the same support. + */ +template +FIELD& FIELD::operator*=(const FIELD & m) +{ + BEGIN_OF("FIELD::operator*=(const FIELD & m)"); + FIELD_::_checkFieldCompatibility(*this, m); // may throw exception + + // We choose to keep *this mode, even if it may cost a re-calculation for m + medModeSwitch mode=this->getvalue()->getMode(); + const T* value1=m.getValue(mode); // get pointers to the values we are adding + + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + const int size=getNumberOfValues()*getNumberOfComponents(); // size of array + const T* endV=value+size; // pointer to the end of value + + for(;value!=endV; value1++,value++) + *value *= *value1; + // if it exists, the alternate mode needs to be cleared because it is not up-to-date anymore + this->getvalue()->clearOtherMode(); + END_OF("FIELD::operator*=(const FIELD & m)"); + return *this; +} + + +/*! Multiplication of fields. Static member function. + * The function return a pointer to a new created field that holds the multiplication. + * Data members are checked for compatibility and initialized. + * The user is in charge of memory deallocation. + */ +template +FIELD* FIELD::mul(const FIELD& m, const FIELD& n) +{ + BEGIN_OF("FIELD::mul(const FIELD & m, const FIELD& n)"); + FIELD_::_checkFieldCompatibility(m, n); // may throw exception + + // Select mode : avoid if possible any calculation of other mode for fields m or *this + medModeSwitch mode; + if(m.getvalue()->getMode()==n.getvalue()->getMode() || n.getvalue()->isOtherCalculated()) + mode=m.getvalue()->getMode(); + else + mode=n.getvalue()->getMode(); + + // Creation of a new field + FIELD* result = new FIELD(m.getSupport(),m.getNumberOfComponents(),mode); + result->_operationInitialize(m,n,"*"); // perform Atribute's initialization + result->_mul_in_place(m,n,mode); // perform multiplication + + END_OF("FIELD::mul(const FIELD & m, const FIELD& n)"); + return result; +} + + +/*! + Overload division operator. + This operation is authorized only for compatible fields that have the same support. + The compatibility checking includes equality tests of the folowing data members:/n + - _support + - _numberOfComponents + - _numberOfValues + - _componentsTypes + - _MEDComponentsUnits. + + The data members of the returned field are initialized, based on the first field, except for the name, + which is the combination of the two field's names and the operator. + Advised Utilisation in C++ : FIELD c = a / b; /n + In this case, the (recent) compilators perform optimisation and don't call the copy constructor. + When using python, this operator calls the copy constructor in any case. + The user has to be aware that when using operator / in associatives expressions like + a = b / c / d /e; /n + no optimisation is performed : the evaluation of last expression requires the construction of + 3 temporary fields. +*/ +template +const FIELD FIELD::operator/(const FIELD & m) const +{ + BEGIN_OF("FIELD::operator/(const FIELD & m)"); + FIELD_::_checkFieldCompatibility(*this, m); // may throw exception + + // Select mode : avoid if possible any calculation of other mode for fields m or *this + medModeSwitch mode; + if(this->getvalue()->getMode()==m.getvalue()->getMode() || this->getvalue()->isOtherCalculated()) + mode=m.getvalue()->getMode(); + else + mode=this->getvalue()->getMode(); + + // Creation of the result - memory is allocated by FIELD constructor + FIELD result(this->getSupport(),this->getNumberOfComponents(),mode); + //result._operation(*this,m,mode,"/"); // perform Atribute's initialization & division + result._operationInitialize(*this,m,"/"); // perform Atribute's initialization + result._div_in_place(*this,m,mode); // perform division + + END_OF("FIELD::operator/(const FIELD & m)"); + return result; +} + + +/*! Overloaded Operator /= + * Operations are directly performed in the first field's array. + * This operation is authorized only for compatible fields that have the same support. + */ +template +FIELD& FIELD::operator/=(const FIELD & m) +{ + BEGIN_OF("FIELD::operator/=(const FIELD & m)"); + FIELD_::_checkFieldCompatibility(*this, m); // may throw exception + + // We choose to keep *this mode, even if it may cost a re-calculation for m + medModeSwitch mode=this->getvalue()->getMode(); + const T* value1=m.getValue(mode); // get pointers to the values we are adding + + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + const int size=getNumberOfValues()*getNumberOfComponents(); // size of array + const T* endV=value+size; // pointer to the end of value + + for(;value!=endV; value1++,value++) + *value /= *value1; + // if it exists, the alternate mode needs to be cleared because it is not up-to-date anymore + this->getvalue()->clearOtherMode(); + END_OF("FIELD::operator/=(const FIELD & m)"); + return *this; +} + + +/*! Division of fields. Static member function. + * The function return a pointer to a new created field that holds the division. + * Data members are checked for compatibility and initialized. + * The user is in charge of memory deallocation. + */ +template +FIELD* FIELD::div(const FIELD& m, const FIELD& n) +{ + BEGIN_OF("FIELD::div(const FIELD & m, const FIELD& n)"); + FIELD_::_checkFieldCompatibility(m, n); // may throw exception + + // Select mode : avoid if possible any calculation of other mode for fields m or *this + medModeSwitch mode; + if(m.getvalue()->getMode()==n.getvalue()->getMode() || n.getvalue()->isOtherCalculated()) + mode=m.getvalue()->getMode(); + else + mode=n.getvalue()->getMode(); + + // Creation of a new field + FIELD* result = new FIELD(m.getSupport(),m.getNumberOfComponents(),mode); + result->_operationInitialize(m,n,"/"); // perform Atribute's initialization + result->_div_in_place(m,n,mode); // perform division + + END_OF("FIELD::div(const FIELD & m, const FIELD& n)"); + return result; +} + + +/*! + \if developper + This internal method initialize the members of a new field created to hold the result of the operation Op . + Initialization is based on the first field, except for the name, which is the combination of the two field's names + and the operator. + \endif +*/ +template +void FIELD::_operationInitialize(const FIELD& m,const FIELD& n, char* Op) +{ + MESSAGE("Appel methode interne _add" << Op); + + // Atribute's initialization (copy of the first field's attributes) + // Other data members (_support, _numberOfValues) are initialized in the field's constr. + setName(m.getName()+" "+Op+" "+n.getName()); + setComponentsNames(m.getComponentsNames()); + // not yet implemented setComponentType(m.getComponentType()); + setComponentsDescriptions(m.getComponentsDescriptions()); + setMEDComponentsUnits(m.getMEDComponentsUnits()); + + // The following data member may differ from field m to n. + // The initialization is done based on the first field. + setComponentsUnits(m.getComponentsUnits()); + setIterationNumber(m.getIterationNumber()); + setTime(m.getTime()); + setOrderNumber(m.getOrderNumber()); + setValueType(m.getValueType()); +} + + +/*! + \if developper + Internal method called by FIELD::operator+ and FIELD::add to perform addition "in place". + This method is applied to a just created field with medModeSwitch mode. + For this reason, the alternate mode doesn't need to be set to 0 after performing operation : + it doesn't exist! + \endif +*/ +template +void FIELD::_add_in_place(const FIELD& m,const FIELD& n, const medModeSwitch mode) +{ + // get pointers to the values we are adding + const T* value1=m.getValue(mode); + const T* value2=n.getValue(mode); + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + + const int size=getNumberOfValues()*getNumberOfComponents(); + SCRUTE(size); + const T* endV1=value1+size; + for(;value1!=endV1; value1++,value2++,value++) + *value=(*value1)+(*value2); +} + +/*! + \if developper + Internal method called by FIELD::operator- and FIELD::sub to perform substraction "in place". + This method is applied to a just created field with medModeSwitch mode. + For this reason, the alternate mode doesn't need to be set to 0 after performing operation : + it doesn't exist! + \endif +*/ +template +void FIELD::_sub_in_place(const FIELD& m,const FIELD& n, const medModeSwitch mode) +{ + // get pointers to the values we are adding + const T* value1=m.getValue(mode); + const T* value2=n.getValue(mode); + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + + const int size=getNumberOfValues()*getNumberOfComponents(); + SCRUTE(size); + const T* endV1=value1+size; + for(;value1!=endV1; value1++,value2++,value++) + *value=(*value1)-(*value2); +} + +/*! + \if developper + Internal method called by FIELD::operator* and FIELD::mul to perform multiplication "in place". + This method is applied to a just created field with medModeSwitch mode. + For this reason, the alternate mode doesn't need to be set to 0 after performing operation : + it doesn't exist! + \endif +*/ +template +void FIELD::_mul_in_place(const FIELD& m,const FIELD& n, const medModeSwitch mode) +{ + // get pointers to the values we are adding + const T* value1=m.getValue(mode); + const T* value2=n.getValue(mode); + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + + const int size=getNumberOfValues()*getNumberOfComponents(); + SCRUTE(size); + const T* endV1=value1+size; + for(;value1!=endV1; value1++,value2++,value++) + *value=(*value1)*(*value2); +} + +/*! + \if developper + Internal method called by FIELD::operator/ and FIELD::div to perform division "in place". + This method is applied to a just created field with medModeSwitch mode. + For this reason, the alternate mode doesn't need to be set to 0 after performing operation : + it doesn't exist! + \endif +*/ +template +void FIELD::_div_in_place(const FIELD& m,const FIELD& n, const medModeSwitch mode) +{ + // get pointers to the values we are adding + const T* value1=m.getValue(mode); + const T* value2=n.getValue(mode); + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + + const int size=getNumberOfValues()*getNumberOfComponents(); + SCRUTE(size); + const T* endV1=value1+size; + for(;value1!=endV1; value1++,value2++,value++) + *value=(*value1)/(*value2); +} + +/*! Return Max Norm + */ +template double FIELD::normMax() const throw (MEDEXCEPTION) +{ + const T* value=getValue(getvalue()->getMode()); // get pointer to the values + const int size=getNumberOfValues()*getNumberOfComponents(); + if (size <= 0) // Size of array has to be strictly positive + { + string diagnosis; + diagnosis="FIELD::normMax() : cannot compute the norm of "+getName()+ + " : it size is non positive!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + const T* lastvalue=value+size; // get pointer just after last value + const T* pMax=value; // pointer to the max value + const T* pMin=value; // pointer to the min value + + // get pointers to the max & min value of array + while ( ++value != lastvalue ) + { + if ( *pMin > *value ) + pMin=value; + if ( *pMax < *value ) + pMax=value; + } + + T Max= *pMax>(T) 0 ? *pMax : -*pMax; // Max=abs(*pMax) + T Min= *pMin>(T) 0 ? *pMin : -*pMin; // Min=abs(*pMin) + + return Max>Min ? static_cast(Max) : static_cast(Min); +} + +/*! Return Euclidien norm + */ +template double FIELD::norm2() const throw (MEDEXCEPTION) +{ + const T* value=this->getValue(this->getvalue()->getMode()); // get const pointer to the values + const int size=getNumberOfValues()*getNumberOfComponents(); // get size of array + if (size <= 0) // Size of array has to be strictly positive + { + string diagnosis; + diagnosis="FIELD::norm2() : cannot compute the norm of "+getName()+ + " : it size is non positive!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + const T* lastvalue=value+size; // point just after last value + + T result((T)0); // init + for( ; value!=lastvalue ; ++value) + result += (*value) * (*value); + + return std::sqrt(static_cast (result)); +} + + +/*! Apply to each (scalar) field component the template parameter T_function, + * which is a pointer to function. + * Since the pointer is known at compile time, the function is inlined into the inner loop! + * calculation is done "in place". + * Use examples : + * + * \code myField.applyFunc(); // apply sqare root function \endcode + * \code myField.applyFunc(); // apply your own created function \endcode + */ +template template +void FIELD::applyFunc() +{ + medModeSwitch mode=getvalue()->getMode(); + + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (getValue(mode)); + const int size=getNumberOfValues()*getNumberOfComponents(); // size of array + + if (size>0) // for a negative size, there is nothing to do + { + const T* lastvalue=value+size; // pointer to the end of value + for(;value!=lastvalue; ++value) // apply linear transformation + *value = T_function(*value); + // if it exists, the alternate mode needs to be cleared because it is not up-to-date anymore + getvalue()->clearOtherMode(); + } } + + +/*! Apply to each (scalar) field component the linear function x -> ax+b. + * calculation is done "in place". + */ +template void FIELD::applyLin(T a, T b) +{ + medModeSwitch mode=getvalue()->getMode(); + + // get a non const pointer to the inside array of values and perform operation in place + T * value=const_cast (getValue(mode)); + const int size=getNumberOfValues()*getNumberOfComponents(); // size of array + + if (size>0) // for a negative size, there is nothing to do + { + const T* lastvalue=value+size; // pointer to the end of value + for(;value!=lastvalue; ++value) // apply linear transformation + *value = a*(*value)+b; + // if it exists, the alternate mode needs to be cleared because it is not up-to-date anymore + getvalue()->clearOtherMode(); + } +} + /*! - Constructor. + * Return a pointer to a new field that holds the scalar product. Static member function. + * This operation is authorized only for compatible fields that have the same support. + * The compatibility checking includes equality tests of the folowing data members:/n + * - _support + * - _numberOfComponents + * - _numberOfValues + * - _componentsTypes + * - _MEDComponentsUnits. + * Data members are initialized. + * The new field point to the same support and has one component. + * Each value of it is the scalar product of the two argument's fields. + * The user is in charge of memory deallocation. + */ +template FIELD* FIELD::scalarProduct(const FIELD & m, const FIELD & n) +{ + FIELD_::_checkFieldCompatibility( m, n); // may throw exception + // we need a MED_FULL_INTERLACE representation of m & n to compute the scalar product + const medModeSwitch mode=MED_FULL_INTERLACE; + + const int numberOfElements=m.getNumberOfValues(); // strictly positive + const int NumberOfComponents=m.getNumberOfComponents(); // strictly positive + + // Creation & init of a the result field on the same suppot, with one component + FIELD* result = new FIELD(m.getSupport(),1,mode); + result->setName( "scalarProduct ( " + m.getName() + " , " + n.getName() + " )" ); + result->setIterationNumber(m.getIterationNumber()); + result->setTime(m.getTime()); + result->setOrderNumber(m.getOrderNumber()); + result->setValueType(m.getValueType()); + + const T* value1=m.getValue(mode); // get const pointer to the values + const T* value2=n.getValue(mode); // get const pointer to the values + // get a non const pointer to the inside array of values and perform operation + T * value=const_cast (result->getValue(mode)); + + const T* lastvalue=value+numberOfElements; // pointing just after last value of result + for ( ; value!=lastvalue ; ++value ) // loop on all elements + { + *value=(T)0; // initialize value + const T* endofRow=value1+NumberOfComponents; // pointing just after end of row + for ( ; value1 != endofRow; ++value1, ++value2) // computation of dot product + *value += (*value1) * (*value2); + } + return result; +} + +/*! Return L2 Norm of the field's component. + * Cannot be applied to a field with a support on nodes. + * If the optional p_field_volume argument is furnished, the volume is not re-calculated. + */ +template double FIELD::normL2(int component, const FIELD * p_field_volume) const +{ + _checkNormCompatibility(p_field_volume); // may throw exception + if ( component<1 || component>getNumberOfComponents() ) + throw MEDEXCEPTION(STRING("FIELD::normL2() : The component argument should be between 1 and the number of components")); + + const FIELD * p_field_size=p_field_volume; + if(!p_field_volume) // if the user don't supply the volume + p_field_size=_getFieldSize(); // we calculate the volume [PROVISOIRE, en attendant l'implémentation dans mesh] + + // get pointer to the element's volumes. MED_FULL_INTERLACE is the default mode for p_field_size + const double* vol=p_field_size->getValue(MED_FULL_INTERLACE); + const T* value=getValueI( MED_NO_INTERLACE, component); // get pointer to the component's values + const T* lastvalue=value+getNumberOfValues(); // pointing just after the end of column + + double integrale=0.0; + double totVol=0.0; + for (; value!=lastvalue ; ++value ,++vol) + { + integrale += static_cast((*value) * (*value)) * (*vol); + totVol+=*vol; + } + + if(!p_field_volume) // if the user didn't supply the volume + delete p_field_size; // delete temporary volume field + if( totVol <= 0) + throw MEDEXCEPTION(STRING("cannot compute sobolev norm : volume is not positive!")); + + return integrale/totVol; +} + +/*! Return L2 Norm of the field. + * Cannot be applied to a field with a support on nodes. + * If the optional p_field_volume argument is furnished, the volume is not re-calculated. + */ +template double FIELD::normL2(const FIELD * p_field_volume) const +{ + _checkNormCompatibility(p_field_volume); // may throw exception + const FIELD * p_field_size=p_field_volume; + if(!p_field_volume) // if the user don't supply the volume + p_field_size=_getFieldSize(); // we calculate the volume [PROVISOIRE, en attendant l'implémentation dans mesh] + + // get pointer to the element's volumes. MED_FULL_INTERLACE is the default mode for p_field_size + const double* vol=p_field_size->getValue(MED_FULL_INTERLACE); + const double* lastvol=vol+getNumberOfValues(); // pointing just after the end of vol + const T* value=getValue( MED_NO_INTERLACE); // get pointer to the field's values + + double totVol=0.0; + const double* p_vol=vol; + for (p_vol=vol; p_vol!=lastvol ; ++p_vol) // calculate total volume + totVol+=*p_vol; + + double integrale=0.0; + for (int i=1; i<=getNumberOfComponents(); ++i) // compute integral on all components + for (p_vol=vol; p_vol!=lastvol ; ++value ,++p_vol) + integrale += static_cast((*value) * (*value)) * (*p_vol); + + if(!p_field_volume) // if the user didn't supply the volume + delete p_field_size; // delete temporary volume field + if( totVol <= 0) + throw MEDEXCEPTION(STRING("cannot compute sobolev norm : volume is not positive!")); + + return integrale/totVol; +} + +/*! Return L1 Norm of the field's component. + * Cannot be applied to a field with a support on nodes. + * If the optional p_field_volume argument is furnished, the volume is not re-calculated. + */ +template double FIELD::normL1(int component, const FIELD * p_field_volume) const +{ + _checkNormCompatibility(p_field_volume); // may throw exception + if ( component<1 || component>getNumberOfComponents() ) + throw MEDEXCEPTION(STRING("FIELD::normL2() : The component argument should be between 1 and the number of components")); + + const FIELD * p_field_size=p_field_volume; + if(!p_field_volume) // if the user don't supply the volume + p_field_size=_getFieldSize(); // we calculate the volume [PROVISOIRE, en attendant l'implémentation dans mesh] + + // get pointer to the element's volumes. MED_FULL_INTERLACE is the default mode for p_field_size + const double* vol=p_field_size->getValue(MED_FULL_INTERLACE); + const T* value=getValueI( MED_NO_INTERLACE, component); // get pointer to the component's values + const T* lastvalue=value+getNumberOfValues(); // pointing just after the end of column + + double integrale=0.0; + double totVol=0.0; + for (; value!=lastvalue ; ++value ,++vol) + { + integrale += std::abs( static_cast(*value) ) * (*vol); + totVol+=*vol; + } + + if(!p_field_volume) // if the user didn't supply the volume + delete p_field_size; // delete temporary volume field + if( totVol <= 0) + throw MEDEXCEPTION(STRING("cannot compute sobolev norm : volume is not positive!")); + + return integrale/totVol; +} + +/*! Return L1 Norm of the field. + * Cannot be applied to a field with a support on nodes. + * If the optional p_field_volume argument is furnished, the volume is not re-calculated. + */ +template double FIELD::normL1(const FIELD * p_field_volume) const +{ + _checkNormCompatibility(p_field_volume); // may throw exception + const FIELD * p_field_size=p_field_volume; + if(!p_field_volume) // if the user don't supply the volume + p_field_size=_getFieldSize(); // we calculate the volume [PROVISOIRE, en attendant l'implémentation dans mesh] + + // get pointer to the element's volumes. MED_FULL_INTERLACE is the default mode for p_field_size + const double* vol=p_field_size->getValue(MED_FULL_INTERLACE); + const double* lastvol=vol+getNumberOfValues(); // pointing just after the end of vol + const T* value=getValue( MED_NO_INTERLACE); // get pointer to the field's values + + double totVol=0.0; + const double* p_vol=vol; + for (p_vol=vol; p_vol!=lastvol ; ++p_vol) // calculate total volume + totVol+=*p_vol; + + double integrale=0.0; + for (int i=1; i<=getNumberOfComponents(); ++i) // compute integral on all components + for (p_vol=vol; p_vol!=lastvol ; ++value ,++p_vol) + integrale += std::abs( static_cast(*value) ) * (*p_vol); + + if(!p_field_volume) // if the user didn't supply the volume + delete p_field_size; // delete temporary volume field + if( totVol <= 0) + throw MEDEXCEPTION(STRING("cannot compute sobolev norm : volume is not positive!")); + + return integrale/totVol; +} + + + + +/*! + Constructor with parameters; the object is set via a file and its associated + driver. For the moment only the MED_DRIVER is considered and if the last two + argument (iterationNumber and orderNumber) are not set; their default value + is -1. If the field fieldDriverName with the iteration number + iterationNumber and the order number orderNumber does not exist in the file + fieldDriverName; the constructor raises an exception. */ template FIELD::FIELD(const SUPPORT * Support, driverTypes driverType, const string & fileName/*=""*/, - const string & fieldDriverName/*=""*/) + const string & fieldDriverName/*=""*/, + const int iterationNumber, + const int orderNumber) + throw (MEDEXCEPTION) { - const char * LOC = "template FIELD::FIELD(const SUPPORT * Support, driverTypes driverType, const string & fileName=\"\", const string & fieldName=\"\") : "; + const char * LOC = "template FIELD::FIELD(const SUPPORT * Support, driverTypes driverType, const string & fileName=\"\", const string & fieldName=\"\", const int iterationNumber=-1, const int orderNumber=-1) : "; int current; @@ -762,9 +1651,19 @@ template FIELD::FIELD(const SUPPORT * Support, _support = Support; _value = (MEDARRAY*)NULL; - MED_FIELD_RDONLY_DRIVER myDriver(fileName,this); - myDriver.setFieldName(fieldDriverName); - current = addDriver(myDriver); + _iterationNumber = iterationNumber; + _time = 0.0; + _orderNumber = orderNumber; + + switch(driverType) + { + case MED_DRIVER : + { + MED_FIELD_RDONLY_DRIVER myDriver(fileName,this); + myDriver.setFieldName(fieldDriverName); + current = addDriver(myDriver); + break; + } // current = addDriver(driverType,fileName,fieldDriverName); // switch(_drivers[current]->getAccessMode() ) { // case MED_WRONLY : { @@ -774,6 +1673,13 @@ template FIELD::FIELD(const SUPPORT * Support, // default : { // } // } + default : + { + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Driver type unknown : can't create driver!")); + break; + } + } + _drivers[current]->open(); _drivers[current]->read(); _drivers[current]->close(); @@ -787,6 +1693,7 @@ template FIELD::FIELD(const SUPPORT * Support, template FIELD::~FIELD() { BEGIN_OF(" Destructeur FIELD::~FIELD()"); + SCRUTE(this); if (_value) delete _value; END_OF(" Destructeur FIELD::~FIELD()"); } @@ -818,7 +1725,7 @@ template void FIELD::allocValue(const int NumberOfComponents) _numberOfValues = _support->getNumberOfElements(MED_ALL_ELEMENTS); MESSAGE(LOC <<" : "<<_numberOfValues <<" et "<< NumberOfComponents); - _value = new MEDARRAY::MEDARRAY(_numberOfComponents,_numberOfValues); + _value = new MEDARRAY(_numberOfComponents,_numberOfValues); _isRead = true ; } @@ -855,7 +1762,7 @@ template void FIELD::allocValue(const int NumberOfComponents, const MESSAGE("FIELD : constructeur : "<::MEDARRAY(_numberOfComponents,_numberOfValues); + _value = new MEDARRAY(_numberOfComponents,_numberOfValues); _isRead = true ; SCRUTE(_value); @@ -882,13 +1789,17 @@ template void FIELD::deallocValue() template FIELD::INSTANCE_DE > FIELD::inst_med ; -template const FIELD::INSTANCE * const FIELD::instances[] = { &FIELD::inst_med } ; + +template FIELD::INSTANCE_DE > FIELD::inst_vtk ; + +template const typename FIELD::INSTANCE * const FIELD::instances[] = { &FIELD::inst_med, &FIELD::inst_vtk} ; /*! Create the specified driver and return its index reference to path to read or write methods. */ + template int FIELD::addDriver(driverTypes driverType, const string & fileName/*="Default File Name.med"*/, const string & driverName/*="Default Field Name"*/) @@ -897,18 +1808,51 @@ template int FIELD::addDriver(driverTypes driverType, GENDRIVER * driver; int current; + int itDriver = (int) NO_DRIVER; BEGIN_OF(LOC); - driver = instances[driverType]->run(fileName, this) ; + SCRUTE(driverType); + + SCRUTE(instances[driverType]); + + switch(driverType) + { + case MED_DRIVER : { + itDriver = (int) driverType ; + break ; + } + + case VTK_DRIVER : { + itDriver = 1 ; + break ; + } + + case GIBI_DRIVER : { + throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD")); + break; + } + + case NO_DRIVER : { + throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD")); + break; + } + } + + if (itDriver == ((int) NO_DRIVER)) + throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD")); + + driver = instances[itDriver]->run(fileName, this) ; + _drivers.push_back(driver); + current = _drivers.size()-1; _drivers[current]->setFieldName(driverName); - return current; END_OF(LOC); + return current; } @@ -926,7 +1870,7 @@ template inline int FIELD::addDriver (GENDRIVER & driver ) _drivers.push_back(newDriver); return _drivers.size() -1 ; - + END_OF(LOC); }; @@ -945,7 +1889,7 @@ template void FIELD::rmDriver (int index/*=0*/) } else throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) - << "The index given is invalid, index must be between 0 and |" + << "The inline void FIELD::write(int index/*=0*/, const string & d END_OF(LOC); } +/*! + Write FIELD in the file specified in the driver given by its index. Use this + method for ASCII drivers (e.g. VTK_DRIVER) +*/ +template inline void FIELD::writeAppend(int index/*=0*/, const string & driverName /*= ""*/) +{ + const char * LOC = "FIELD::write(int index=0, const string & driverName = \"\") : "; + BEGIN_OF(LOC); + + if( _drivers[index] ) { + _drivers[index]->openAppend(); + if (driverName != "") _drivers[index]->setFieldName(driverName); + _drivers[index]->writeAppend(); + _drivers[index]->close(); + } + else + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "The index given is invalid, index must be between 0 and |" + << _drivers.size() + ) + ); + END_OF(LOC); +} + /*! \internal Write FIELD with the driver which is equal to the given driver. @@ -1009,7 +1977,7 @@ template inline void FIELD::write(const GENDRIVER & genDriver) const char * LOC = " FIELD::write(const GENDRIVER &) : "; BEGIN_OF(LOC); - for (int index=0; index < _drivers.size(); index++ ) + for (unsigned int index=0; index < _drivers.size(); index++ ) if ( *_drivers[index] == genDriver ) { _drivers[index]->open(); _drivers[index]->write(); @@ -1020,6 +1988,28 @@ template inline void FIELD::write(const GENDRIVER & genDriver) } +/*! + \internal + Write FIELD with the driver which is equal to the given driver. + + Use by MED object. Use this method for ASCII drivers (e.g. VTK_DRIVER). +*/ +template inline void FIELD::writeAppend(const GENDRIVER & genDriver) +{ + const char * LOC = " FIELD::write(const GENDRIVER &) : "; + BEGIN_OF(LOC); + + for (unsigned int index=0; index < _drivers.size(); index++ ) + if ( *_drivers[index] == genDriver ) { + _drivers[index]->openAppend(); + _drivers[index]->writeAppend(); + _drivers[index]->close(); + } + + END_OF(LOC); + +} + /*! \internal Read FIELD with the driver which is equal to the given driver. @@ -1031,7 +2021,7 @@ template inline void FIELD::read(const GENDRIVER & genDriver) const char * LOC = " FIELD::read(const GENDRIVER &) : "; BEGIN_OF(LOC); - for (int index=0; index < _drivers.size(); index++ ) + for (unsigned int index=0; index < _drivers.size(); index++ ) if ( *_drivers[index] == genDriver ) { _drivers[index]->open(); _drivers[index]->read(); diff --git a/src/MEDMEM/MEDMEM_GenDriver.cxx b/src/MEDMEM/MEDMEM_GenDriver.cxx index 41b077695..1545acf2b 100644 --- a/src/MEDMEM/MEDMEM_GenDriver.cxx +++ b/src/MEDMEM/MEDMEM_GenDriver.cxx @@ -1,29 +1,3 @@ -// 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_GenDriver.cxx -// Module : MED - using namespace std; #include "MEDMEM_GenDriver.hxx" #include "MEDMEM_STRING.hxx" @@ -71,8 +45,11 @@ GENDRIVER & GENDRIVER::operator=(const GENDRIVER & genDriver) { void GENDRIVER::writeFrom ( void ) {}; void GENDRIVER::readFileStruct ( void ) {}; -void GENDRIVER::setMeshName (const string & meshName) {}; -void GENDRIVER::setFieldName (const string & fieldName) {}; +void GENDRIVER::setMeshName (const string & ) {}; +void GENDRIVER::setFieldName (const string & ) {}; + +void GENDRIVER::openAppend ( void ) {}; +void GENDRIVER::writeAppend ( void ) const {}; void GENDRIVER::setId ( int id ) { const char * LOC = "void GENDRIVER::setId ( int id ) : "; @@ -142,6 +119,9 @@ ostream & operator<<(ostream &os,const GENDRIVER & drv) case MED_RDWR : os<<"C'est un IO d'READ/WRITE"< + #include "MEDMEM_GibiMeshDriver.hxx" #include "MEDMEM_DriversDef.hxx" @@ -18,6 +12,18 @@ using namespace std; #include "MEDMEM_Connectivity.hxx" #include "MEDMEM_Mesh.hxx" #include "MEDMEM_CellModel.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_DriverTools.hxx" + +///// +using namespace MED_EN; +///// + + +///// +const size_t GIBI_MESH_DRIVER::nb_geometrie_gibi; +const medGeometryElement GIBI_MESH_DRIVER::geomGIBItoMED[nb_geometrie_gibi]; +///// // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor @@ -33,10 +39,10 @@ GIBI_MESH_DRIVER::GIBI_MESH_DRIVER(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces accessMode): GENDRIVER(fileName,accessMode), - _ptrMesh(ptrMesh), + _ptrMesh(ptrMesh) // A VOIR _medIdt(MED_INVALID), - _meshName("") { + _meshName=fileName.substr(0,fileName.rfind(".")); } GIBI_MESH_DRIVER::GIBI_MESH_DRIVER(const GIBI_MESH_DRIVER & driver): @@ -54,40 +60,31 @@ GIBI_MESH_DRIVER::~GIBI_MESH_DRIVER() void GIBI_MESH_DRIVER::open() throw (MEDEXCEPTION) { - const char * LOC = "GIBI_MESH_DRIVER::open()" ; - BEGIN_OF(LOC); - -// 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)); -// } - + const char * LOC = "GIBI_MESH_DRIVER::open()" ; + BEGIN_OF(LOC); + + _gibi.open(_fileName.c_str(), ios::in); + if(_gibi) + _status = MED_OPENED; + else + { + _status = MED_CLOSED; + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName<<" in mode ios::in")); + } END_OF(LOC); } void GIBI_MESH_DRIVER::close() throw (MEDEXCEPTION) { - const char * LOC = "GIBI_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 !" -// ) -// ); -// _status = MED_CLOSED; -// _medIdt = MED_INVALID; -// } - - END_OF(LOC); + const char * LOC = "GIBI_MESH_DRIVER::close() " ; + BEGIN_OF(LOC); + if ( _status == MED_OPENED) + { + _gibi.close(); + _status = MED_CLOSED; + } + END_OF(LOC); } void GIBI_MESH_DRIVER::setMeshName(const string & meshName) { _meshName = meshName; }; @@ -99,42 +96,301 @@ string GIBI_MESH_DRIVER::getMeshName() const { return _meshName; }; GIBI_MESH_RDONLY_DRIVER::GIBI_MESH_RDONLY_DRIVER(): GIBI_MESH_DRIVER() { } - + GIBI_MESH_RDONLY_DRIVER::GIBI_MESH_RDONLY_DRIVER(const string & fileName, - MESH * ptrMesh): - GIBI_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY) + MESH * ptrMesh): +GIBI_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY) { - MESSAGE("GIBI_MESH_RDONLY_DRIVER::GIBI_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created"); + MESSAGE("GIBI_MESH_RDONLY_DRIVER::GIBI_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created"); } - -GIBI_MESH_RDONLY_DRIVER::GIBI_MESH_RDONLY_DRIVER(const GIBI_MESH_RDONLY_DRIVER & driver): - GIBI_MESH_DRIVER(driver) + + GIBI_MESH_RDONLY_DRIVER::GIBI_MESH_RDONLY_DRIVER(const GIBI_MESH_RDONLY_DRIVER & driver): +GIBI_MESH_DRIVER(driver) { } GIBI_MESH_RDONLY_DRIVER::~GIBI_MESH_RDONLY_DRIVER() { - //MESSAGE("GIBI_MESH_RDONLY_DRIVER::~GIBI_MESH_RDONLY_DRIVER() has been destroyed"); + //MESSAGE("GIBI_MESH_RDONLY_DRIVER::~GIBI_MESH_RDONLY_DRIVER() has been destroyed"); } GENDRIVER * GIBI_MESH_RDONLY_DRIVER::copy(void) const { - return new GIBI_MESH_RDONLY_DRIVER(*this); + return new GIBI_MESH_RDONLY_DRIVER(*this); } -void GIBI_MESH_RDONLY_DRIVER::read(void) - throw (MEDEXCEPTION) +void GIBI_MESH_RDONLY_DRIVER::read(void) throw (MEDEXCEPTION) { - const char * LOC = "GIBI_MESH_RDONLY_DRIVER::read() : " ; - BEGIN_OF(LOC); - - if (_status!=MED_OPENED) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " << " (the file is not opened)." )) ; - - _ptrMesh->_name = _meshName; - - - END_OF(LOC); + const char * LOC = "GIBI_MESH_RDONLY_DRIVER::read() : " ; + BEGIN_OF(LOC); + + if (_status!=MED_OPENED) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " + << " (the file is not opened)." )) ; + + // LECTURE DES DONNEES DS FICHIER GIBI + + _intermediateMED medi; // structure de données intermédiaire pour conversion gibi->med + string buf_ligne; // pour lire une ligne + const char* enregistrement_type="ENREGISTREMENT DE TYPE"; + std::vector numero_noeuds; // tableau de travail (indices) + + + while ( getline(_gibi, buf_ligne) ) // boucle externe de recherche de "ENREGISTREMENT DE TYPE" + { + string::size_type pos = buf_ligne.find(enregistrement_type); + if ( pos==string::npos ) + continue; // "ENREGISTREMENT DE TYPE" non trouvé -> on lit la ligne suivante + + // lecture du numéro d'enregistrement + int numero_enregistrement; + istringstream buf(buf_ligne.c_str()+strlen(enregistrement_type)+1); + buf >> numero_enregistrement; + + enum { ENREG_TYPE_2=2, ENREG_TYPE_4=4}; // énumération des types d'enregistrement traités + int niveau, niveau_erreur; + unsigned space_dimension,nb_reels; + int numero_pile, nb_objets_nommes, nb_objets, nb_indices; + string s1,s2,s3,s4,s5,s6,s7; // temporary strings + int i1; //temporary int + double d1; //temporary double + vector indices_objets_nommes; + vector objets_nommes; + + switch (numero_enregistrement) + { + case ENREG_TYPE_4: + MESSAGE(LOC << "---- Traitement enregistrement de type 4"); + _gibi >> s1 >> niveau >> s2 >> s3 >> niveau_erreur >> s4 >> space_dimension; + if ( !_gibi || s1!="NIVEAU" || s3!="ERREUR" || s4!="DIMENSION" ) // verification mots -cles + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " Could not read file " << _fileName + << " : syntax error in type 4 record")); + break; + + case ENREG_TYPE_2: + { + MESSAGE(LOC << "---- Traitement enregistrement de type 2"); + _gibi >> s1 >> s2 >> numero_pile >> s3 >> s4 >> s5 >> nb_objets_nommes >> s6 >> s7 >> nb_objets; + if ( !_gibi || s1!="PILE" || s2!="NUMERO" || s3!="NBRE" // verification mots -cles + || s4!="OBJETS" || s5!="NOMMES" || s6!="NBRE" + || s7!="OBJETS" || nb_objets_nommes<0 || nb_objets<0 ) + { + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " Could not read file " << _fileName + << " : error in type 2 record")); + } + + // lecture des objets nommés et de leurs indices + objets_nommes.resize(nb_objets_nommes); + indices_objets_nommes.resize(nb_objets_nommes); + for (int i=0; i!=nb_objets_nommes; ++i) + _gibi >> objets_nommes[i]; + + for (int i=0; i!=nb_objets_nommes; ++i) + _gibi >> indices_objets_nommes[i]; + + // boucle interne : lecture de la pile + enum {PILE_SOUS_MAILLAGE=1, PILE_NOEUDS=32, PILE_COORDONNEES=33}; + switch(numero_pile) + { + case PILE_SOUS_MAILLAGE: + { + medi.groupes.reserve(nb_objets); + for (int objet=0; objet!=nb_objets; ++objet) // pour chaque groupe + { + unsigned type_geom_castem, nb_reference,nb_noeud,nb_elements, nb_sous_maillage; + _gibi >> type_geom_castem >> nb_sous_maillage >> nb_reference >> nb_noeud >> nb_elements; + + // le cas type_geom_castem=0 correspond aux maillages composites + if (type_geom_castem<0 || (type_geom_castem>0 && geomGIBItoMED[type_geom_castem-1]==MED_NONE) ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " Error while reading file " << _fileName + << "\nCastem geometric type " << type_geom_castem + << " does not have a correspondant MED geometric type!" )); + + // lecture des references (non utilisé pour MED) + for( unsigned i=0; i!=nb_reference; ++i) + _gibi >> i1; + + // lecture des couleurs (non utilisé pour MED) + for( unsigned i=0; i!=nb_elements; ++i) + _gibi >> i1; + + _groupe groupe; + // si le groupe se compose de sous-maillages (ie groupe composite) + if (type_geom_castem==0 && nb_sous_maillage>0) + { + // lecture des indices des sous-maillages, stockage. + // les mailles correspondant a ces sous_maillages seront inserees a la fin du case + for (unsigned i=0; i!=nb_sous_maillage; ++i) + { + _gibi >> i1; + groupe.groupes.push_back(i1); + } + } + else + { + pair::iterator,bool> p; + pair::iterator,bool> p_no; + _noeud no; + no.coord.reserve(space_dimension); + no.coord.resize(space_dimension); + _maille ma(geomGIBItoMED[type_geom_castem-1], nb_noeud); + ma.sommets.resize(nb_noeud); + + // lecture pour chaque maille des sommets et insertions + for( unsigned i=0; i!=nb_elements; ++i) + { + for (unsigned n=0; n!=nb_noeud; ++n) + { + _gibi >> i1; + no.number=i1; + p_no=medi.points.insert(make_pair(i1, no)); + ma.sommets[n]=p_no.first; + } + + p=medi.maillage.insert(ma); + groupe.mailles.insert(p.first); // on stocke dans le groupe un iterateur sur la maille + +// cout << " " << p.second << ": "; +// for (unsigned n=0; n!=nb_noeud; ++n) +// cout << ma.sommets[n]->second.number << " "; +// cout << endl; + + } + } + medi.groupes.push_back(groupe); + } + + for (int i=0; i!=nb_objets_nommes; ++i) + medi.groupes[indices_objets_nommes[i]-1].nom=objets_nommes[i]; + + // scanne les groupes à la recherche de groupes composites + for( std::vector<_groupe>::iterator i=medi.groupes.begin(); i!=medi.groupes.end(); ++i) + { + if( i->groupes.size() ) // le groupe i contient des sous-maillages + { + for( std::list::iterator j=i->groupes.begin(); j!=i->groupes.end(); ++j) + { + // pour chacun des sous-maillages j, on recupere les iterateurs *k sur les maille + // contenues et on les insere dans le groupe i + std::set< std::set<_maille>::iterator >::const_iterator k=medi.groupes[*j-1].mailles.begin(); + for( ; k!=medi.groupes[*j-1].mailles.end(); ++k) + i->mailles.insert(*k); + } + i->groupes.clear(); // après avoir insere leur mailles, on efface les groupes composites + } + } + + break; + }// Fin case PILE_SOUS_MAILLAGE + + case PILE_NOEUDS: + { + std::vector place_noeuds; + _gibi >> nb_indices; + if (nb_indices != nb_objets) + { + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " Could not read file " << _fileName + << "Erreur de lecture dans enregistrement de type " << ENREG_TYPE_2 + << " (pile " << PILE_NOEUDS << ")" )); + } + + place_noeuds.resize(nb_objets); + for (unsigned i=0; i!=place_noeuds.size(); ++i) + _gibi >> place_noeuds[i]; + int max=(* std::max_element(place_noeuds.begin(),place_noeuds.end())); + + // numero_noeuds contient pour chacun des max noeuds qu'on va lire dans le case PILE_COORDONNEES + // son indice dans la connectivite du maillage. Cet indice correspond egalement a la cle du map + // medi.points ou l'on stocke les noeuds. + numero_noeuds.resize(max,-1); + for (unsigned i=0; i!=place_noeuds.size(); ++i) + numero_noeuds[place_noeuds[i]-1]=i+1; + break; + } + + case PILE_COORDONNEES: + _gibi >> nb_reels; + // PROVISOIRE : certains fichier gibi n'ont + if (nb_reels < numero_noeuds.size()*(space_dimension)) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " Could not read file " << _fileName + << "Erreur de lecture dans enregistrement de type " << ENREG_TYPE_2 + << " (pile " << PILE_COORDONNEES << ")" )); + + for (unsigned i=0; i!=numero_noeuds.size(); ++i) + { + // si le noeud est utilisé dans le maillage, on lit ses coordonnées et on les stocke dans la structure + if ( (numero_noeuds[i] != -1) && (medi.points.find(numero_noeuds[i])!=medi.points.end()) ) + { + for (unsigned j=0; j!=space_dimension; ++j) + _gibi >> medi.points[numero_noeuds[i]].coord[j]; + _gibi >> d1; // on ne conserve pas la densite + } + else // sinon, on passe au noeud suivant + { + for (unsigned j=0; j!=space_dimension+1; ++j) + _gibi >> d1; + } + } + break; + + } // Fin switch numero_pile + break; + } // Fin case ENREG_TYPE_2 + } + + } // fin de la boucle while de lecture externe + + // impression résultats + MESSAGE(LOC << "GIBI_MESH_RDONLY_DRIVER::read : RESULTATS STRUCTURE INTERMEDIAIRES : "); + MESSAGE(LOC << medi ); + + // TRANSFORMATION EN STRUCTURES MED + if ( ! _ptrMesh->isEmpty() ) + { + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh object not empty : can't fill it!")); + } + else if ( medi.maillage.size()==0 || medi.groupes.size()==0 || medi.points.size()==0) + { + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " Error while reading file " << _fileName + << " The data read are not completed " ) ) ; + } + else + { + _ptrMesh->_name = _meshName; + _ptrMesh->_spaceDimension = medi.points.begin()->second.coord.size(); + _ptrMesh->_meshDimension = medi.maillage.rbegin()->dimension(); + _ptrMesh->_numberOfNodes = medi.points.size(); + _ptrMesh->_isAGrid = 0; + _ptrMesh->_coordinate = medi.getCoordinate(); + + //Construction des groupes + vector groupCell, groupFace, groupEdge, groupNode; + medi.getGroups(groupCell, groupFace, groupEdge, groupNode, _ptrMesh); + _ptrMesh->_groupCell = groupCell; + _ptrMesh->_groupFace = groupFace; + _ptrMesh->_groupEdge = groupEdge; + _ptrMesh->_groupNode = groupNode; + + //Affectation derniers attributs objet Mesh + _ptrMesh->_numberOfCellsGroups = _ptrMesh->_groupCell.size(); + _ptrMesh->_numberOfFacesGroups = _ptrMesh->_groupFace.size(); + _ptrMesh->_numberOfEdgesGroups = _ptrMesh->_groupEdge.size(); + _ptrMesh->_numberOfNodesGroups = _ptrMesh->_groupNode.size(); + + // appele en dernier car cette fonction detruit le maillage intermediaire! + _ptrMesh->_connectivity = medi.getConnectivity(); + + // calcul de la connectivite d-1 complete, avec renumerotation des groupes + if (_ptrMesh->_spaceDimension==3) + _ptrMesh->_connectivity->updateGroup(_ptrMesh->_groupFace) ; + else if (_ptrMesh->_spaceDimension==2) + _ptrMesh->_connectivity->updateGroup(_ptrMesh->_groupEdge) ; + + } + + + + END_OF(LOC); } void GIBI_MESH_RDONLY_DRIVER::write( void ) const diff --git a/src/MEDMEM/MEDMEM_GibiMeshDriver.hxx b/src/MEDMEM/MEDMEM_GibiMeshDriver.hxx index a6a154958..bc25416b9 100644 --- a/src/MEDMEM/MEDMEM_GibiMeshDriver.hxx +++ b/src/MEDMEM/MEDMEM_GibiMeshDriver.hxx @@ -1,17 +1,9 @@ -// MED MEDMEM : MED files in memory -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : MEDMEM_GibiMeshDriver.hxx -// Module : MED - #ifndef GIBI_MESH_DRIVER_HXX #define GIBI_MESH_DRIVER_HXX #include #include +#include #include "MEDMEM_define.hxx" #include "MEDMEM_GenDriver.hxx" @@ -20,6 +12,11 @@ #include "MEDMEM_Exception.hxx" #include "utilities.h" +///// +#include +#include +///// + class MESH; class FAMILY; class GROUP; @@ -40,8 +37,25 @@ protected: MESH * _ptrMesh; // A VOIR FILE DESCRIPTEUR ? MED_FR::med_idt _medIdt; - string _meshName; + string _meshName; + ///// + ifstream _gibi; + // tableau de correspondance des types géométriques de CASTEM -> MED + static const size_t nb_geometrie_gibi=47; + static const medGeometryElement geomGIBItoMED[nb_geometrie_gibi] = // A COMPLETER + { /*1 */ MED_POINT1 ,/*2 */ MED_SEG2 ,/*3 */ MED_SEG3 ,/*4 */ MED_TRIA3 ,/*5 */ MED_NONE , + /*6 */ MED_TRIA6 ,/*7 */ MED_NONE ,/*8 */ MED_QUAD4 ,/*9 */ MED_NONE ,/*10*/ MED_QUAD8 , + /*11*/ MED_NONE ,/*12*/ MED_NONE ,/*13*/ MED_NONE ,/*14*/ MED_HEXA8 ,/*15*/ MED_HEXA20 , + /*16*/ MED_PENTA6 ,/*17*/ MED_PENTA15,/*18*/ MED_NONE ,/*19*/ MED_NONE ,/*20*/ MED_NONE , + /*21*/ MED_NONE ,/*22*/ MED_NONE ,/*23*/ MED_TETRA4 ,/*24*/ MED_TETRA10,/*25*/ MED_PYRA5 , + /*26*/ MED_PYRA13 ,/*27*/ MED_NONE ,/*28*/ MED_NONE ,/*29*/ MED_NONE ,/*30*/ MED_NONE , + /*31*/ MED_NONE ,/*32*/ MED_NONE ,/*33*/ MED_NONE ,/*34*/ MED_NONE ,/*35*/ MED_NONE , + /*36*/ MED_NONE ,/*37*/ MED_NONE ,/*38*/ MED_NONE ,/*39*/ MED_NONE ,/*40*/ MED_NONE , + /*41*/ MED_NONE ,/*42*/ MED_NONE ,/*43*/ MED_NONE ,/*44*/ MED_NONE ,/*45*/ MED_NONE , + /*46*/ MED_NONE ,/*47*/ MED_NONE }; + ///// + public : /*! diff --git a/src/MEDMEM/MEDMEM_Grid.cxx b/src/MEDMEM/MEDMEM_Grid.cxx index 40d448b08..d6f2d6b6a 100644 --- a/src/MEDMEM/MEDMEM_Grid.cxx +++ b/src/MEDMEM/MEDMEM_Grid.cxx @@ -1,15 +1,15 @@ -// MED MEDMEM : MED files in memory -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : MEDMEM_Grid.hxx -// Author : Edward AGAPOV (eap) -// Module : MED -// $Header$ - using namespace std; +// File : MEDMEM_Grid.hxx +// Created : Wed Dec 18 08:35:26 2002 +// Descr : class containing structured mesh data + +// Author : Edward AGAPOV (eap) +// Project : SALOME Pro +// Module : MED +// Copyright : Open CASCADE +// $Header$ + + #include "MEDMEM_Grid.hxx" #include #include @@ -96,17 +96,17 @@ GRID & GRID::operator=(const GRID & otherGrid) // (MED_DRIVER, ....) associated with file . //======================================================================= -GRID::GRID(driverTypes driverType, - const string & fileName, - const string & driverName) { +GRID::GRID(driverTypes driverType, const string & fileName, + const string & driverName) : MESH(driverType, fileName, driverName) +{ const char * LOC ="GRID::GRID(driverTypes , const string & , const string &) : "; BEGIN_OF(LOC); // int current; - init(); - MESH(driverType,fileName,driverName); +// init(); +// MESH(driverType,fileName,driverName); // current = addDriver(driverType,fileName,driverName); @@ -123,6 +123,8 @@ GRID::GRID(driverTypes driverType, // // fill some fields of MESH // fillMeshAfterRead(); + + fillMeshAfterRead(); END_OF(LOC); }; @@ -181,7 +183,7 @@ void GRID::fillMeshAfterRead() //purpose : //======================================================================= -void GRID::fillCoordinates() +void GRID::fillCoordinates() const { if (_is_coordinates_filled) { @@ -198,7 +200,8 @@ void GRID::fillCoordinates() bool hasJ = _jArrayLength, hasK = _kArrayLength; int J = hasJ ? _jArrayLength : 1; int K = hasK ? _kArrayLength : 1; - int nb, i, j, k; + //int nb, !! UNUSED VARIABLE !! + int i, j, k; for (k=0; k < K; ++k) { for (j=0; j < J; ++j) { for (i=0; i < _iArrayLength; ++i) { @@ -221,7 +224,7 @@ void GRID::fillCoordinates() } } - _is_coordinates_filled = true; + (const_cast (this))->_is_coordinates_filled = true; END_OF(LOC); } @@ -231,10 +234,11 @@ void GRID::fillCoordinates() //======================================================================= CONNECTIVITY * GRID::makeConnectivity (const medEntityMesh Entity, - const medGeometryElement Geometry, - const int NbEntities, - const int NbNodes, - int * NodeNumbers) + const medGeometryElement Geometry, + const int NbEntities, + const int NbNodes, + int * NodeNumbers) + const { CONNECTIVITY * Connectivity = new CONNECTIVITY(Entity) ; Connectivity->_numberOfNodes = NbNodes ; @@ -288,7 +292,7 @@ CONNECTIVITY * GRID::makeConnectivity (const medEntityMesh Entity, //purpose : fill _coordinates and _connectivity of MESH if not yet done //======================================================================= -void GRID::fillConnectivity() +void GRID::fillConnectivity() const { if (_is_connectivity_filled) { @@ -634,7 +638,7 @@ void GRID::fillConnectivity() MESH::_connectivity = CellCNCT; - _is_connectivity_filled = true; + (const_cast (this))->_is_connectivity_filled = true; END_OF(LOC); } @@ -644,7 +648,7 @@ void GRID::fillConnectivity() //purpose : return array length. Axis = [1,2,3] meaning [i,j,k], //======================================================================= -int GRID::getArrayLength( const int Axis ) throw (MEDEXCEPTION) +int GRID::getArrayLength( const int Axis ) const throw (MEDEXCEPTION) { switch (Axis) { case 1: return _iArrayLength; @@ -663,8 +667,7 @@ int GRID::getArrayLength( const int Axis ) throw (MEDEXCEPTION) // exception if i is out of range 0 <= i < getArrayLength(Axis); //======================================================================= -const double GRID::getArrayValue (const int Axis, const int i) - throw (MEDEXCEPTION) +const double GRID::getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION) { if (i < 0 || i >= getArrayLength(Axis)) throw MED_EXCEPTION @@ -684,10 +687,12 @@ const double GRID::getArrayValue (const int Axis, const int i) //======================================================================= int GRID::getEdgeNumber(const int Axis, const int i, const int j, const int k) - throw (MEDEXCEPTION) + const throw (MEDEXCEPTION) { const char * LOC = "GRID::getEdgeNumber(Axis, i,j,k) :"; + BEGIN_OF(LOC); + int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3; int maxAxis = Len[ K ] ? 3 : 2; @@ -710,7 +715,9 @@ int GRID::getEdgeNumber(const int Axis, const int i, const int j, const int k) Len[J]-- ; Nb += Len[ I ]*Len[ J ]*Len[ K ]; } - + + END_OF(LOC); + return Nb; } @@ -725,10 +732,12 @@ int GRID::getEdgeNumber(const int Axis, const int i, const int j, const int k) //======================================================================= int GRID::getFaceNumber(const int Axis, const int i, const int j, const int k) - throw (MEDEXCEPTION) + const throw (MEDEXCEPTION) { const char * LOC = "GRID::getFaceNumber(Axis, i,j,k) :"; + BEGIN_OF(LOC); + // if (Axis <= 0 || Axis > 3) if (Axis < 0 || Axis > 3) throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis = " << Axis)); @@ -748,7 +757,9 @@ int GRID::getFaceNumber(const int Axis, const int i, const int j, const int k) Len[J]++ ; Nb += Len[ I ]*Len[ J ]*Len[ K ]; } - + + END_OF(LOC); + return Nb; } @@ -757,15 +768,18 @@ int GRID::getFaceNumber(const int Axis, const int i, const int j, const int k) //purpose : //======================================================================= -void GRID::getNodePosition(const int Number, int& i, int& j, int& k) - throw (MEDEXCEPTION) +void GRID::getNodePosition(const int Number, int& i, int& j, int& k) const + throw (MEDEXCEPTION) { const char * LOC = "GRID::getNodePosition(Number, i,j,k) :"; + BEGIN_OF(LOC); + if (Number <= 0 || Number > _numberOfNodes) throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number)); - int Len[] = {_iArrayLength, _jArrayLength, _kArrayLength }, I=0, J=1, K=2; + int Len[] = {_iArrayLength, _jArrayLength, _kArrayLength }, I=0, J=1; + // , K=2; !! UNUSED VARIABLE !! int ijLen = Len[I] * Len[J]; // nb in a full k layer int kLen = (Number - 1) % ijLen; // nb in the non full k layer @@ -775,6 +789,9 @@ void GRID::getNodePosition(const int Number, int& i, int& j, int& k) k = (Number - 1) / ijLen; ////cout <<" NODE POS: " << Number << " - " << i << ", " << j << ", " << k << endl; + + END_OF(LOC); + } //======================================================================= @@ -782,12 +799,15 @@ void GRID::getNodePosition(const int Number, int& i, int& j, int& k) //purpose : //======================================================================= -void GRID::getCellPosition(const int Number, int& i, int& j, int& k) - throw (MEDEXCEPTION) +void GRID::getCellPosition(const int Number, int& i, int& j, int& k) const + throw (MEDEXCEPTION) { const char * LOC = "GRID::getCellPosition(Number, i,j,k) :"; - int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3; + BEGIN_OF(LOC); + + int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2; + // , K=3; !! UNUSED VARIABLE !! // if (Number <= 0 || Number > getCellNumber(Len[I]-1, Len[J]-1, Len[K]-1)) // throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number)); @@ -798,6 +818,8 @@ void GRID::getCellPosition(const int Number, int& i, int& j, int& k) i = kLen % Len[J]; j = kLen / Len[J]; k = (Number - 1) / ijLen; + + END_OF(LOC); } //======================================================================= @@ -806,10 +828,12 @@ void GRID::getCellPosition(const int Number, int& i, int& j, int& k) //======================================================================= void GRID::getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) - throw (MEDEXCEPTION) + const throw (MEDEXCEPTION) { const char * LOC = "GRID::getEdgePosition(Number, i,j,k) :"; + BEGIN_OF(LOC); + if (!_jArrayLength) throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no edges in the grid: ")); @@ -849,6 +873,9 @@ void GRID::getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) j = kLen / Len[J]; k = (theNb - 1) / ijLen; } + + END_OF(LOC); + return; } @@ -866,15 +893,17 @@ void GRID::getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) //======================================================================= void GRID::getFacePosition(const int Number, int& Axis, int& i, int& j, int& k) - throw (MEDEXCEPTION) + const throw (MEDEXCEPTION) { const char * LOC = "GRID::getFacePosition(Number, i,j,k) :"; - if (_kArrayLength == 0) { - getCellPosition(Number, i, j, k); - Axis = 1; - return; - }; + BEGIN_OF(LOC); + + if (_kArrayLength == 0) { + getCellPosition(Number, i, j, k); + Axis = 1; + return; + }; if (!_kArrayLength) throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no faces in the grid: ")); @@ -913,6 +942,9 @@ void GRID::getFacePosition(const int Number, int& Axis, int& i, int& j, int& k) j = kLen / Len[J]; k = (theNb - 1) / ijLen; } + + END_OF(LOC); + return; } @@ -949,3 +981,25 @@ void GRID::writeUnstructured(int index, const string & driverName) ); END_OF(LOC); } + +void GRID::read(int index) +{ + const char * LOC = "GRID::read(int index=0) : "; + BEGIN_OF(LOC); + + if (_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() + ) + ); + if (_isAGrid) + fillMeshAfterRead(); + + END_OF(LOC); +} diff --git a/src/MEDMEM/MEDMEM_Grid.hxx b/src/MEDMEM/MEDMEM_Grid.hxx index 09f938bc5..4c19f2149 100644 --- a/src/MEDMEM/MEDMEM_Grid.hxx +++ b/src/MEDMEM/MEDMEM_Grid.hxx @@ -1,13 +1,12 @@ -// MED MEDMEM : MED files in memory -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : MEDMEM_Grid.hxx -// Author : Edward AGAPOV (eap) -// Module : MED -// $Header$ +// File : MEDMEM_Grid.hxx +// Created : Wed Dec 18 08:35:26 2002 +// Descr : class containing structured mesh data + +// Author : Edward AGAPOV (eap) +// Project : SALOME Pro +// Module : MED +// Copyright : Open CASCADE +// $Header$ #ifndef MEDMEM_Grid_HeaderFile #define MEDMEM_Grid_HeaderFile @@ -47,11 +46,10 @@ class GRID: public MESH // Protected Methods //-----------------------// - CONNECTIVITY * makeConnectivity (const medEntityMesh Entity, - const medGeometryElement Geometry, - const int NbEntities, - const int NbNodes, - int * NodeNumbers); + CONNECTIVITY * makeConnectivity (const medEntityMesh Entity, + const medGeometryElement Geometry, + const int NbEntities, const int NbNodes, + int * NodeNumbers) const ; // creates nodal connectivity @@ -84,8 +82,8 @@ class GRID: public MESH virtual ~GRID(); virtual void init(); - void fillCoordinates(); - void fillConnectivity(); + void fillCoordinates() const ; + void fillConnectivity() const ; // fill _coordinates and _connectivity of MESH if not yet done inline void makeUnstructured(); @@ -97,6 +95,8 @@ class GRID: public MESH void writeUnstructured(int index=0, const string & driverName = ""); // write a Grid as an Unstructured mesh + void read(int index=0); + // API Methods returning fields of MESH that are filled while reading. // So they need not to be redefined @@ -143,16 +143,16 @@ class GRID: public MESH // Specific GRID methods - inline int getNodeNumber(const int i, const int j=0, const int k=0); + inline int getNodeNumber(const int i, const int j=0, const int k=0) const; // return a NODE number by its position in the grid. // WARNING: be carefull, there is no check that i,j,k are within a good range // A good range is: 0 <= X < getArrayLength( X_Axis ) - inline int getCellNumber(const int i, const int j=0, const int k=0) ; + inline int getCellNumber(const int i, const int j=0, const int k=0) const ; // return a CELL number by its position in the grid. // WARNING: be carefull, there is no check that i,j,k are within a good range // A good range is: 0 <= X < (getArrayLength( X_Axis )-1) - int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) throw (MEDEXCEPTION) ; + int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION) ; // return an EDGE number by its position in the grid. // Axis [1,2,3] means one of directions: along i, j or k. // It selects an edge of ones having same (i,j,k): @@ -163,7 +163,7 @@ class GRID: public MESH // 0 <= X < (getArrayLength( X_Axis )-1) // 0 <= X < getArrayLength( NOT_X_Axis ) - int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) throw (MEDEXCEPTION) ; + int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION) ; // return a FACE number by its position in the grid. // Axis [1,2,3] means one of directions: along i, j or k. // It selects a face of ones having same (i,j,k): @@ -175,10 +175,10 @@ class GRID: public MESH // 0 <= X < getArrayLength( X_Axis ) - void getNodePosition(const int Number, int& i, int& j, int& k) throw (MEDEXCEPTION) ; - void getCellPosition(const int Number, int& i, int& j, int& k) throw (MEDEXCEPTION) ; - void getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) throw (MEDEXCEPTION) ; - void getFacePosition(const int Number, int& Axis, int& i, int& j, int& k) throw (MEDEXCEPTION) ; + void getNodePosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION) ; + void getCellPosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION) ; + void getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION) ; + void getFacePosition(const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION) ; // return position (i,j,k) of an entity #Number // Axis: [1,2,3], see get*Number for details // Exception for Number out of range @@ -189,15 +189,58 @@ class GRID: public MESH inline med_grid_type getGridType() const; // return MED_CARTESIAN, MED_POLAR or MED_BODY_FITTED - int getArrayLength( const int Axis ) throw (MEDEXCEPTION); + int getArrayLength( const int Axis ) const throw (MEDEXCEPTION); // return array length. Axis = [1,2,3] meaning [i,j,k], // exception if Axis out of [1-3] range - const double getArrayValue (const int Axis, const int i) throw (MEDEXCEPTION) ; + const double getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION) ; // return i-th array component. Axis = [1,2,3] meaning [i,j,k], // exception if Axis out of [1 - 3] range // exception if i is out of range [0 - (getArrayLength(Axis)-1)]; + inline const COORDINATE * getCoordinateptr() const; + + inline const double * getCoordinates(medModeSwitch Mode) const; + + inline const double getCoordinate(int Number,int Axis) const; + + inline int getNumberOfTypes(medEntityMesh Entity) const; + + inline const medGeometryElement * getTypes(medEntityMesh Entity) const; + + inline const CELLMODEL * getCellsTypes(medEntityMesh Entity) const; + + const int * getGlobalNumberingIndex(medEntityMesh Entity) const; + + inline int getNumberOfElements(medEntityMesh Entity, + medGeometryElement Type) const; + + inline bool existConnectivity(medConnectivity ConnectivityType, + medEntityMesh Entity) const; + + inline medGeometryElement getElementType(medEntityMesh Entity, + int Number) const; + + inline void calculateConnectivity(medModeSwitch Mode, + medConnectivity ConnectivityType, + medEntityMesh Entity) const ; + + inline const CONNECTIVITY* getConnectivityptr() const; + + inline const int * getConnectivity(medModeSwitch Mode, + medConnectivity ConnectivityType, + medEntityMesh Entity, + medGeometryElement Type) const; + + inline const int * getConnectivityIndex(medConnectivity ConnectivityType, + medEntityMesh Entity) const; + + inline const int * getReverseConnectivity(medConnectivity ConnectivityType, + medEntityMesh Entity=MED_CELL) const; + + inline const int * getReverseConnectivityIndex(medConnectivity ConnectivityType, + medEntityMesh Entity=MED_CELL) const; + // Setting fields inline void setGridType(med_grid_type gridType); @@ -221,7 +264,7 @@ inline med_grid_type GRID::getGridType() const //purpose : //======================================================================= -inline int GRID::getNodeNumber(const int i, const int j, const int k) +inline int GRID::getNodeNumber(const int i, const int j, const int k) const { return 1 + i + _iArrayLength * j + _iArrayLength * _jArrayLength * k; } @@ -231,7 +274,7 @@ inline int GRID::getNodeNumber(const int i, const int j, const int k) //purpose : //======================================================================= -inline int GRID::getCellNumber(const int i, const int j, const int k) +inline int GRID::getCellNumber(const int i, const int j, const int k) const { return 1 + i + (_iArrayLength-1) * j + (_iArrayLength-1) * (_jArrayLength-1) * k; } @@ -257,4 +300,259 @@ inline void GRID::setGridType(med_grid_type gridType) _gridType = gridType; } +/*! Get the COORDINATES object. Use it only if you need COORDINATES informations not provided by the GRID class via the MESH class.*/ +inline const COORDINATE * GRID::getCoordinateptr() const +{ + fillCoordinates(); + return _coordinate; +} + +/*! Get the whole coordinates array in a given interlacing mode. The interlacing mode are : + - MED_NO_INTERLACE : X1 X2 Y1 Y2 Z1 Z2 + - MED_FULL_INTERLACE : X1 Y1 Z1 X2 Y2 Z2 + */ +inline const double * GRID::getCoordinates(medModeSwitch Mode) const +{ + fillCoordinates(); + return _coordinate->getCoordinates(Mode); +} + +/*! Get the coordinate n° number on axis n°axis*/ +inline const double GRID::getCoordinate(int number, int axis) const +{ + fillCoordinates(); + return _coordinate->getCoordinate(number,axis); +} + +/*! Get the number of different geometric types for a given entity type. + + medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_NODE, + MED_ALL_ENTITIES + + If entity is not defined, return 0. + + If there is no connectivity, return an exception. +*/ +inline int GRID::getNumberOfTypes(medEntityMesh entity) const +{ + MESSAGE("GRID::getNumberOfTypes(medEntityMesh entity) : "<getNumberOfTypes(entity); + throw MEDEXCEPTION(LOCALIZED("GRID::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !")); +} + +/*! + Get the list of geometric types used by a given entity. + medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_ALL_ENTITIES + + REM : Don't use MED_NODE + + If entity is not defined, return an exception. +*/ +inline const medGeometryElement * GRID::getTypes(medEntityMesh entity) const +{ + if (entity == MED_NODE) + throw MEDEXCEPTION(LOCALIZED("GRID::getTypes( medEntityMesh ) : No medGeometryElement with MED_NODE entity !")); + // return un tableau de taille 1 contenant MED_NONE, comme les supports pour etre coherent avec getNumberOfTypes ???? PG + + fillConnectivity(); + + if (_connectivity != NULL) + return _connectivity->getGeometricTypes(entity); + throw MEDEXCEPTION(LOCALIZED("GRID::getTypes( medEntityMesh ) : Connectivity not defined !")); +} + +/*! + Get the whole list of CELLMODEL used by cells of given type (medEntityMesh). + + REMARK : Don't use MED_NODE as medEntityMesh +*/ +inline const CELLMODEL * GRID::getCellsTypes(medEntityMesh Entity) const +{ + fillConnectivity(); + + if (_connectivity != NULL) + return _connectivity->getCellsTypes(Entity); + throw MEDEXCEPTION(LOCALIZED("GRID::getCellsTypes( medEntityMesh ) : Connectivity not defined !")); +} + +/*! Return an array of size NumbreOfTypes+1 which contains, for each + geometric type of the given entity, the first global element number + of this type. + + For exemple, if we have a mesh with 5 triangles and 4 quadrangle : + - size of GlobalNumberingIndex is 3 + - GlobalNumberingIndex[0]=1 (the first type) + - GlobalNumberingIndex[1]=6 (the second type) + - GlobalNumberingIndex[2]=10 +*/ +inline const int * GRID::getGlobalNumberingIndex(medEntityMesh entity) const +{ + fillConnectivity(); + + if (_connectivity != NULL) + return _connectivity->getGlobalNumberingIndex(entity); + throw MEDEXCEPTION(LOCALIZED("GRID::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !")); +} + +/*! + Return the number of element of given geometric type of given entity. Return 0 if query is not defined. + + Example : + - getNumberOfElements(MED_NODE,MED_NONE) : number of node + - getNumberOfElements(MED_NODE,MED_TRIA3) : return 0 (not defined) + - getNumberOfElements(MED_FACE,MED_TRIA3) : return number of triangles + elements defined in face entity (0 if not defined) + - getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) : return total number + of elements defined in cell entity +*/ +inline int GRID::getNumberOfElements(medEntityMesh entity, medGeometryElement Type) const +{ + // const char * LOC = "MESH::getNumberOfElements(medEntityMesh,medGeometryElement) : "; + if (entity==MED_NODE) + if ((Type==MED_NONE)|(Type==MED_ALL_ELEMENTS)) + return _numberOfNodes; + else + return 0; + //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"wrong medGeometryElement with MED_NODE")); + else + { + fillConnectivity(); + + if (_connectivity != (CONNECTIVITY*)NULL) + return _connectivity->getNumberOf(entity,Type); + else + return 0; + //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"connectivity not defined !")); + } +} + +/*! + Return true if the wanted connectivity exist, else return false + (to use before a getSomething method). + */ +inline bool GRID::existConnectivity(medConnectivity connectivityType, medEntityMesh entity) const +{ + fillConnectivity(); + + if (_connectivity==(CONNECTIVITY*)NULL) + throw MEDEXCEPTION("GRID::existConnectivity(medConnectivity,medEntityMesh) : no connectivity defined !"); + return _connectivity->existConnectivity(connectivityType,entity); +} + +/*! + Return the geometric type of global element Number of entity Entity. + + Throw an exception if Entity is not defined or Number are wrong (too big). + */ +inline medGeometryElement GRID::getElementType(medEntityMesh Entity,int Number) const +{ + fillConnectivity(); + + if (_connectivity==(CONNECTIVITY*)NULL) + throw MEDEXCEPTION("GRID::getElementType(medEntityMesh,int) : no connectivity defined !"); + return _connectivity->getElementType(Entity,Number); +} + +/*! + Calculate the ask connectivity. Return an exception if this could not be + done. Do nothing if connectivity already exist. + */ + +inline void GRID::calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity) const +{ + fillConnectivity(); + + if (Mode==MED_FULL_INTERLACE) + _connectivity->calculateConnectivity(ConnectivityType,entity); + else + throw MEDEXCEPTION(LOCALIZED("GRID::calculateConnectivity : only for MED_FULL_INTERLACE mode")); +} + +inline const CONNECTIVITY* GRID::getConnectivityptr() const +{ + fillConnectivity(); + + return _connectivity; +} + +/*! + Return the required connectivity in the right mode for the given + geometric type of the given entity. + + To get connectivity for all geometric type, use Mode=MED_FULL_INTERLACE + and Type=MED_ALL_ELEMENTS. + You must also get the corresponding index array. + */ +inline const int * GRID::getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity, medGeometryElement Type) const +{ + fillConnectivity(); + + if (Mode==MED_FULL_INTERLACE) + return _connectivity->getConnectivity(ConnectivityType,entity,Type); + throw MEDEXCEPTION(LOCALIZED("GRID::getConnectivity : only for MED_FULL_INTERLACE mode")); +} + +/*! + Return the required index array for a connectivity received in + MED_FULL_ENTERLACE mode and MED_ALL_ELEMENTS type. + + This array allow to find connectivity of each elements. + + Example : Connectivity of i^{th} elements (1<=i<=NumberOfElement) begin + at index ConnectivityIndex[i-1] and end at index ConnectivityIndex[i]-1 + in Connectivity array (Connectivity[ConnectivityIndex[i-1]-1] is the + first value) + */ +inline const int * GRID::getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh entity) const +{ + fillConnectivity(); + + return _connectivity->getConnectivityIndex(ConnectivityType, entity); +} + +/*! + Return the reverse connectivity required by ConnectivityType : + - If ConnectivityType=MED_NODAL : return connectivity node-cell + - If ConnectivityType=MED_DESCENDING : return connectivity face-cell + + You must get ReverseConnectivityIndex array to use it. + */ +inline const int * GRID::getReverseConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity/*=MED_CELL*/) const +{ + fillConnectivity(); + + if (NULL==_connectivity) + throw MEDEXCEPTION("GRID::getReverseConnectivity : no connectivity defined in MESH !"); + + return _connectivity->getReverseConnectivity(ConnectivityType,Entity); +} + +/*! + Return the index array required by ConnectivityType. + + This array allow to find reverse connectivity of each elements. + + Example : Reverse connectivity of i^{th} elements (1<=i<=NumberOfElement) + begin at index ReverseConnectivityIndex[i-1] and end at index + ReverseConnectivityIndex[i]-1 + in ReverseConnectivity array ( + ReverseConnectivity[ReverseConnectivityIndex[i-1]-1] + is the first value) + */ +inline const int * GRID::getReverseConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity/*=MED_CELL*/) const +{ + fillConnectivity(); + + if (NULL==_connectivity) + throw MEDEXCEPTION("GRID::getReverseConnectivityIndex : no connectivity defined in MESH !"); + + return _connectivity->getReverseConnectivityIndex(ConnectivityType,Entity); +} + #endif diff --git a/src/MEDMEM/MEDMEM_Group.cxx b/src/MEDMEM/MEDMEM_Group.cxx index 4a883f3a5..b59d981a5 100644 --- a/src/MEDMEM/MEDMEM_Group.cxx +++ b/src/MEDMEM/MEDMEM_Group.cxx @@ -1,29 +1,3 @@ -// 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 @@ -80,12 +54,18 @@ GROUP::GROUP(const string & name, const list & families) throw (MEDEXCE _mesh = myFamily->getMesh() ; _entity = myFamily->getEntity() ; bool isOnAllElts = myFamily->isOnAllElements() ; + + SCRUTE(isOnAllElts); + SCRUTE(numberOfFamilies); + + if ((numberOfFamilies==1)&(isOnAllElts)) { _numberOfFamilies = numberOfFamilies; - _isOnAllElts = false ; + _isOnAllElts = isOnAllElts ; _family.resize(_numberOfFamilies) ; _family[0] = myFamily; + update(); return; } else if ((!(numberOfFamilies==1))&(isOnAllElts)) @@ -99,11 +79,15 @@ GROUP::GROUP(const string & name, const list & families) throw (MEDEXCE const medGeometryElement * geometricType = myFamily->getTypes() ; //int * geometricTypeNumber = myFamily->getGeometricTypeNumber() ; const int * numberOfGaussPoint = myFamily->getNumberOfGaussPoint() ; + + SCRUTE(_numberOfGeometricType); + for (int i=0 ; i<_numberOfGeometricType; i++) { _geometricType[i]= geometricType[i] ; // _geometricTypeNumber[i] = geometricTypeNumber[i] ; _numberOfGaussPoint[i] = numberOfGaussPoint[i] ; _numberOfElements[i]=myFamily->getNumberOfElements(geometricType[i]); + MESSAGE(LOC << " Type : " << _geometricType[i] << " number of element(s) " << _numberOfElements[i]); } _isOnAllElts = false ; //_totalNumberOfEntities = myFamily->getNumberOfElements(MED_ALL_ELEMENTS) ; @@ -112,6 +96,10 @@ GROUP::GROUP(const string & name, const list & families) throw (MEDEXCE _numberOfFamilies = families.size(); _family.resize(_numberOfFamilies) ; list::const_iterator li ; + + MESSAGE(LOC<<"Printing of the object GROUP built right before the blending"<< (SUPPORT) *this); + + int it = 0 ; for (li=families.begin();li!=families.end();li++) { blending(*li); @@ -119,6 +107,8 @@ GROUP::GROUP(const string & name, const list & families) throw (MEDEXCE it++ ; } + MESSAGE(LOC<<"Printing of the object GROUP built "<< *this); + END_OF(LOC); }; diff --git a/src/MEDMEM/MEDMEM_Group.hxx b/src/MEDMEM/MEDMEM_Group.hxx index c19dcdbba..46e3ab9ef 100644 --- a/src/MEDMEM/MEDMEM_Group.hxx +++ b/src/MEDMEM/MEDMEM_Group.hxx @@ -1,29 +1,3 @@ -// 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.hxx -// Module : MED - /* File Group.hxx $Header$ @@ -47,18 +21,20 @@ class FAMILY; */ -class GROUP : public SUPPORT +class GROUP : virtual public SUPPORT { protected : /*! \if developper Number of families in the group. + \endif */ int _numberOfFamilies ; /*! \if developper Vector of families in the group. Note that Families are numbered from 1 to N. + \endif */ vector _family ; @@ -70,7 +46,7 @@ public: /*! Copy Constructor. */ GROUP(const GROUP & m); /*! Destructor. */ - ~GROUP(); + virtual ~GROUP(); /*! Copy operator. */ // PN ATTention il n y a pas de copie du vecteur Family ???? diff --git a/src/MEDMEM/MEDMEM_InterpolationWrappers.hxx b/src/MEDMEM/MEDMEM_InterpolationWrappers.hxx new file mode 100644 index 000000000..766994fed --- /dev/null +++ b/src/MEDMEM/MEDMEM_InterpolationWrappers.hxx @@ -0,0 +1,75 @@ + +#ifndef WRAPPERS_HPP +#define WRAPPERS_HPP + +// les classes de wrapping + +template class Wrapper_Noeud +{ +protected : + double * coordonnees; +public : + Wrapper_Noeud():coordonnees(NULL) + { + } + Wrapper_Noeud(const double * coord):coordonnees( (double *) coord) + { + } + ~Wrapper_Noeud() + { + coordonnees=NULL; + } + void positionne(double *place) + { + coordonnees=place; + } + const double & operator[] (int i) const + { + return coordonnees[i]; + } + double operator[] (int i) + { + return coordonnees[i]; + } + friend double DistanceInf(const Wrapper_Noeud &A,const Wrapper_Noeud &B) + { + double max=0; + double tmp; + for (int i=0;imax) max=tmp; + } + return max; + } + friend double DistanceL2(const Wrapper_Noeud &A,const Wrapper_Noeud &B) + { + double tmp,somme=0; + for (int i=0;i class Wrapper_Nuage + { + protected : + int nbr_noeuds; + const double * noeuds; + Wrapper_Noeud show; + public : + Wrapper_Nuage():nbr_noeuds(0),noeuds(NULL) {} + Wrapper_Nuage( const double * const n, int nn):nbr_noeuds(nn),noeuds(n),show(noeuds) {} + ~Wrapper_Nuage() {noeuds=NULL;} + Wrapper_Noeud & operator [] (int i) + { + show.positionne((double *) &noeuds[DIMENSION*i]); + return show; + } + int size() const {return nbr_noeuds;} + }; + +#endif diff --git a/src/MEDMEM/MEDMEM_Med.cxx b/src/MEDMEM/MEDMEM_Med.cxx index bc242f80e..31821b8cc 100644 --- a/src/MEDMEM/MEDMEM_Med.cxx +++ b/src/MEDMEM/MEDMEM_Med.cxx @@ -1,29 +1,3 @@ -// 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 @@ -53,6 +27,8 @@ MED::MED(driverTypes driverType, const string & fileName) const char * LOC = "MED::MED(driverTypes driverType, const string & fileName) : "; BEGIN_OF(LOC); + MESSAGE(LOC << "driverType = " << driverType); + MED_MED_RDONLY_DRIVER * myDriver = new MED_MED_RDONLY_DRIVER(fileName,this) ; int current = addDriver(*myDriver); //int current= addDriver(driverType,fileName); @@ -122,18 +98,15 @@ MED::~MED() 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 ; + case MED_INT32 : + delete (FIELD*) (*currentField).first ; break ; case MED_REEL64 : - // mpv: such recursive destructors call is problematic for current ALLIANCES algorithms - //delete (FIELD*) (*currentField).first ; + 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; + MESSAGE(LOC << "Field has type different of int or double, could not destroy its values array !") ; + delete (*currentField).first; } } } @@ -141,8 +114,7 @@ MED::~MED() 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 ; + delete (*itSupport).second ; } // map::const_iterator currentMesh; @@ -150,11 +122,9 @@ MED::~MED() if ( (*currentMesh).second != NULL) { if (!((*currentMesh).second)->getIsAGrid()) - ;// mpv: such recursive destructors call is problematic for current ALLIANCES algorithms - //delete (*currentMesh).second; + delete (*currentMesh).second; else - ;// mpv: such recursive destructors call is problematic for current ALLIANCES algorithms - //delete (GRID *) (*currentMesh).second; + delete (GRID *) (*currentMesh).second; } } @@ -162,7 +132,7 @@ MED::~MED() MESSAGE(LOC << "In this object MED there is(are) " << index << " driver(s):"); - for (int ind=0; ind < _drivers.size(); ind++ ) + for (unsigned int ind=0; ind < _drivers.size(); ind++ ) { SCRUTE(_drivers[ind]); if ( _drivers[ind] != NULL) delete _drivers[ind]; @@ -191,15 +161,50 @@ int MED::addDriver(driverTypes driverType, const string & fileName="Default File const char * LOC = "MED::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\") : "; GENDRIVER * driver; int current; + int itDriver = (int) NO_DRIVER; BEGIN_OF(LOC); MESSAGE(LOC << " the file name is " << fileName); - driver = instances[driverType]->run(fileName, this) ; + + SCRUTE(driverType); + + SCRUTE(instances[driverType]); + + switch(driverType) + { + case MED_DRIVER : { + itDriver = (int) driverType ; + break ; + } + + case VTK_DRIVER : { + itDriver = 1 ; + break ; + } + + case GIBI_DRIVER : { + throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "GIBI_DRIVER has been specified to the method which is not allowed because there is no GIBI driver for the MED object")); + break; + } + + case NO_DRIVER : { + throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "NO_DRIVER has been specified to the method which is not allowed")); + break; + } + } + + if (itDriver == ((int) NO_DRIVER)) + throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "NO_DRIVER has been specified to the method which is not allowed")); + + driver = instances[itDriver]->run(fileName, this) ; + current = _drivers.size()-1; + driver->setId(current); END_OF(LOC); + return current; } @@ -392,7 +397,7 @@ void MED::getMeshNames ( string * meshNames ) const { const char * LOC = "MED::getMeshNames ( string * ) const : "; BEGIN_OF(LOC); - int meshNamesSize; + unsigned int meshNamesSize; if ( ( meshNamesSize = sizeof(meshNames) / sizeof(string *) ) != _meshes.size() ) @@ -518,7 +523,7 @@ void MED::getFieldNames ( string * fieldNames ) const const char * LOC = "MED::getFieldNames ( string * ) const : "; BEGIN_OF(LOC); - int fieldNamesSize = sizeof(fieldNames) / sizeof(string *); + unsigned int fieldNamesSize = sizeof(fieldNames) / sizeof(string *); if ( fieldNamesSize != _fields.size() ) throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) @@ -684,16 +689,51 @@ SUPPORT * MED::getSupport (const string & meshName,MED_FR::med_entite_maillage const char * LOC = "MED::getSupport ( const string, MED_FR::med_entite_maillage ) const : "; BEGIN_OF(LOC); - map >::const_iterator itSupportOnMesh = _support.find(meshName) ; + int index = 0; + for (map >::const_iterator const_itSupportOnMesh=_support.begin(); const_itSupportOnMesh != _support.end(); + const_itSupportOnMesh++ ) + { + map::const_iterator const_itSupport ; + for (const_itSupport=(*const_itSupportOnMesh).second.begin(); + const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) index++; + } + + MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):"); + + for (map >::const_iterator const_itSupportOnMesh=_support.begin();const_itSupportOnMesh != _support.end(); const_itSupportOnMesh++ ) + { + map::const_iterator const_itSupport ; + for (const_itSupport=(*const_itSupportOnMesh).second.begin(); + const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) + { + MESSAGE(LOC << "Support on mesh " << (*const_itSupportOnMesh).first << " on entity " << (*const_itSupport).first << " : " << *((*const_itSupport).second)); + } + } + + + map >::const_iterator const_itSupportOnMesh = _support.find(meshName) ; - if ( itSupportOnMesh == _support.end() ) + if ( const_itSupportOnMesh == _support.end() ) throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "There is no support on mesh named |" << meshName << "|" ) ); - map & SupportOnMesh = (map&) ((*itSupportOnMesh).second) ; +// map & SupportOnMesh = (map&) ((*itSupportOnMesh).second) ; +// map::const_iterator itSupport = SupportOnMesh.find(entity) ; + +// if (itSupport == SupportOnMesh.end() ) +// throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) +// << "There is no support on entity " +// << entity << " in mesh named |" +// << meshName << "|" +// ) +// ); + + + map SupportOnMesh = ((*const_itSupportOnMesh).second); + map::const_iterator itSupport = SupportOnMesh.find(entity) ; if (itSupport == SupportOnMesh.end() ) @@ -755,8 +795,12 @@ void MED::addMesh( MESH * const ptrMesh) if ( ! ( meshName = ptrMesh->getName()).size() ) throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrMesh->_name must not be NULL !")); +// MESH * meshToMed = new MESH(*ptrMesh); DO WE HAVE TO COPY THE ENTRY MESH OR NOT ????? (NB) + _meshes[meshName] = ptrMesh; // if ptrMesh->meshName already exists it is modified +// _meshes[meshName] = meshToMed; + END_OF(LOC); } @@ -799,7 +843,7 @@ void MED::addField( FIELD_ * const ptrField) _meshName [ptrField] = meshName; // if it already exists it is replaced _meshes [meshName] = ptrMesh; // if it already exists it is replaced - int numberOfTypes = ptrSupport->getNumberOfTypes(); + // int numberOfTypes = ptrSupport->getNumberOfTypes(); !! UNUSED VARIABLE !! _support [meshName][ (MED_FR::med_entite_maillage) ptrSupport->getEntity()] = ptrSupport;// if it already exists it is replaced diff --git a/src/MEDMEM/MEDMEM_Med.hxx b/src/MEDMEM/MEDMEM_Med.hxx index 7a5efb5cd..137120ae3 100644 --- a/src/MEDMEM/MEDMEM_Med.hxx +++ b/src/MEDMEM/MEDMEM_Med.hxx @@ -1,29 +1,3 @@ -// 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.hxx -// Module : MED - # ifndef MED_HXX # define MED_HXX diff --git a/src/MEDMEM/MEDMEM_MedFieldDriver.hxx b/src/MEDMEM/MEDMEM_MedFieldDriver.hxx index 805536bf2..490fd4b56 100644 --- a/src/MEDMEM/MEDMEM_MedFieldDriver.hxx +++ b/src/MEDMEM/MEDMEM_MedFieldDriver.hxx @@ -1,29 +1,3 @@ -// 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_MedFieldDriver.hxx -// Module : MED - #ifndef MED_FIELD_DRIVER_HXX #define MED_FIELD_DRIVER_HXX @@ -522,6 +496,7 @@ template void MED_FIELD_RDONLY_DRIVER::read(void) MESSAGE("MED_GEOM :"<<(MED_FR::med_geometrie_element)Types[i]); MESSAGE("Iteration :"<<_ptrField->getIterationNumber()); MESSAGE("Order :"<<_ptrField->getOrderNumber()); + _ptrField->_numberOfValues+=NumberOfValues[i]; // problem with gauss point : _numberOfValues != TotalNumberOfValues !!!!!!! if ( MED_FR::MEDchampLire(_medIdt,const_cast (MeshName.c_str()), const_cast (_fieldName.c_str()), (unsigned char*) myValues[i], @@ -574,7 +549,7 @@ template void MED_FIELD_RDONLY_DRIVER::read(void) for (int j=0; j_numberOfValues+=NumberOf; // problem with gauss point : _numberOfValues != TotalNumberOfValues !!!!!!! +// _ptrField->_numberOfValues+=NumberOf; // problem with gauss point : _numberOfValues != TotalNumberOfValues !!!!!!! int offset = NumberOf*i ; for (int k=0 ; k void MED_FIELD_WRONLY_DRIVER::write(void) const MED_EN::med_type_champ ValueType=_ptrField->getValueType() ; + MESSAGE("Template Type =|"< void MED_FIELD_WRONLY_DRIVER::write(void) const for (int i=0;igetNumberOfElements(Types[i]) ; - MESSAGE(" "<<_ptrField->getName()); - MESSAGE(" "<getEntity()); - MESSAGE(" "<getIterationNumber()); - MESSAGE(" "<<_ptrField->getTime()); - MESSAGE(" "<<_ptrField->getOrderNumber()); - MESSAGE("MEDchampEcr :"<getValueI(MED_EN::MED_FULL_INTERLACE,Index) ; - - err=MED_FR::MEDchampEcr(_medIdt, const_cast ( MeshName.c_str()) , //( string(mesh_name).resize(MED_TAILLE_NOM).c_str()) + + MESSAGE("_medIdt : "<<_medIdt); + MESSAGE("MeshName.c_str() : "<getName() : "<<_ptrField->getName()); + MESSAGE("value : "<getEntity() : "<getEntity()); + MESSAGE("Types[i] : "<getIterationNumber() : "<<_ptrField->getIterationNumber()); + MESSAGE("_ptrField->getTime() : "<<_ptrField->getTime()); + MESSAGE("_ptrField->getOrderNumber() : "<<_ptrField->getOrderNumber()); + +/* char chanom[MED_TAILLE_NOM+1]; + char chacomp[MED_TAILLE_NOM+1]; + char chaunit[MED_TAILLE_NOM+1]; + MED_FR::med_type_champ chatype; + med_int chancomp=1; + + err=MED_FR::MEDchampInfo(_medIdt,1,chanom,&chatype,chacomp,chaunit,chancomp); + + if (err<0) + { + cout<<"=======================================================================> gros probleme"< nom lu = "< type lu = "< nom composante lu = "< nom unit lu = "< valeur de MED_FR::MED_REEL64 = "< ( MeshName.c_str()) , //( string(mesh_name).resize(MED_TAILLE_NOM).c_str()) const_cast ( (_ptrField->getName()).c_str()), - (unsigned char*)value, MED_FR::MED_FULL_INTERLACE, + (unsigned char*)value, + MED_FR::MED_FULL_INTERLACE, NumberOfElements, - NumberOfGaussPoint[i],MED_ALL, MED_NOPFL, MED_FR::MED_REMP, // PROFIL NON GERE, mode de remplacement non géré + NumberOfGaussPoint[i], + MED_ALL, + MED_NOPFL, + MED_FR::MED_REMP, // PROFIL NON GERE, mode de remplacement non géré (MED_FR::med_entite_maillage)mySupport->getEntity(), (MED_FR::med_geometrie_element)Types[i], - _ptrField->getIterationNumber()," ", - _ptrField->getTime(),_ptrField->getOrderNumber() + _ptrField->getIterationNumber(), + " ", + _ptrField->getTime(), + _ptrField->getOrderNumber() ); if (err < MED_VALID ) throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Error in writing Field "<< _ptrField->getName() <<", type "< @@ -87,6 +61,7 @@ void MED_MED_DRIVER::write() const } GENDRIVER * MED_MED_DRIVER::copy(void) const { + return new MED_MED_DRIVER(*this) ; } void MED_MED_DRIVER::writeFrom() const { @@ -223,7 +198,7 @@ void MED_MED_RDONLY_DRIVER::readFileStruct( void ) char meshName[MED_TAILLE_NOM+1]=""; int meshDim; MESH * ptrMesh; - MED_MESH_RDWR_DRIVER * ptrDriver; + // MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !! numberOfMeshes = MEDnMaa(_medIdt) ; if ( numberOfMeshes <= 0 ) @@ -287,6 +262,7 @@ void MED_MED_RDONLY_DRIVER::readFileStruct( void ) MESSAGE(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<getName()); // we create all global support (for each entity type : + int index = 0; for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) { string supportName="SupportOnAll_" ; supportName+=entNames[(MED_FR::med_entite_maillage)(*currentEntity).first] ; @@ -297,8 +273,44 @@ void MED_MED_RDONLY_DRIVER::readFileStruct( void ) mySupport->setEntity((MED_EN::medEntityMesh) (*currentEntity).first); mySupport->setAll(true); (_ptrMed->_support)[meshName][(MED_FR::med_entite_maillage)(*currentEntity).first] = mySupport ; + MESSAGE(LOC<< "The support " << supportName.c_str() << " on entity " << (*currentEntity).first << " is built"); + index++; } + MESSAGE(LOC <<"The mesh " <getName() << " has " << index << " support(s)"); } + + map >::const_iterator const_itSupportOnMesh ; + + int index = 0; + + vector vectSupp; + for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end(); + const_itSupportOnMesh++ ) + { + map::const_iterator const_itSupport ; + for (const_itSupport=(*const_itSupportOnMesh).second.begin(); + const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) index++; + } + + MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):"); + + vectSupp.resize(index); + + index = 0; + for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end(); + const_itSupportOnMesh++ ) + { + map::const_iterator const_itSupport ; + for (const_itSupport=(*const_itSupportOnMesh).second.begin(); + const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) + { + vectSupp[index] = (*const_itSupport).second; + SCRUTE(vectSupp[index]); + MESSAGE(LOC << "Support number " << index << " is "<< *vectSupp[index]); + index++; + } + } + } @@ -543,7 +555,7 @@ void MED_MED_RDONLY_DRIVER::readFileStruct( void ) } // read profil count and their names - int support_count_= 0 ; + // int support_count_= 0 ; !! UNUSED VARIABLE !! // il faut lire les champs pour avoir les profils stockes !!! // il faudrait implémenter la lecture des profils dans med !!! diff --git a/src/MEDMEM/MEDMEM_MedMedDriver.hxx b/src/MEDMEM/MEDMEM_MedMedDriver.hxx index db6375d0c..0b401b81d 100644 --- a/src/MEDMEM/MEDMEM_MedMedDriver.hxx +++ b/src/MEDMEM/MEDMEM_MedMedDriver.hxx @@ -1,29 +1,3 @@ -// 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_MedMedDriver.hxx -// Module : MED - #ifndef MED_MED_DRIVER_HXX #define MED_MED_DRIVER_HXX diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver.cxx b/src/MEDMEM/MEDMEM_MedMeshDriver.cxx index cd764c0c1..1c5e9e232 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver.cxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver.cxx @@ -1,29 +1,3 @@ -// 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" @@ -223,9 +197,9 @@ void MED_MESH_RDONLY_DRIVER::read(void) buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ; _ptrMesh->_numberOfEdgesGroups = _ptrMesh->_groupEdge.size() ; - MESSAGE(LOC<<"Checking of CellModel !!!!!!!"); +// MESSAGE(LOC<<"Checking of CellModel !!!!!!!"); - int nbOfTypes = _ptrMesh->_connectivity->_numberOfTypes; +// int nbOfTypes = _ptrMesh->_connectivity->_numberOfTypes; // for(int i=0;i_connectivity->_type[i]) ; @@ -523,7 +497,7 @@ int MED_MESH_RDONLY_DRIVER::getCOORDINATE() tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM,MED_FR::MED_NOEUD, (MED_FR::med_geometrie_element) MED_NONE); if (err == MED_VALID) - INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !"); + MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !"); delete[] tmp_node_name ; @@ -532,9 +506,9 @@ int MED_MESH_RDONLY_DRIVER::getCOORDINATE() err=MEDnumLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), 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"); + MESSAGE(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"); + MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !"); + MESSAGE(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"); _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ; memcpy((int*)_ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes) ; } @@ -691,15 +665,16 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) // Get the number of cells of each type & store it in . int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ; - for (int i=1;i (_ptrMesh->_name.c_str())), MED_FR::MED_CONN,(MED_FR::med_entite_maillage) Entity, all_cell_type[i],MED_FR::MED_NOD); - // We suppose there is no cells used as faces, this is forbidden !!! - - // Only in version 2.2.x of MED, but before, it's right :-( + // Get the greatest dimension of the cells : Connectivity->_entityDimension + // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!! + // In version prior to 2.2.x, it is possible if (tmp_cells_count[i]>0) { Connectivity->_entityDimension=all_cell_type[i]/100; Connectivity->_numberOfTypes++; @@ -707,7 +682,7 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) } - // well if there is nothing, we quit ! + // If there is no nodal connectivity, we quit ! if ( Connectivity->_numberOfTypes == 0 ) { delete[] tmp_cells_count ; return MED_ERROR ; @@ -722,18 +697,27 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) return MED_ERROR ; } - // we get version number -// string medVersion(version_med); -// int firstNumber = - int * tmp_edges_count = new int[MED_NBR_GEOMETRIE_MAILLE] ; + // we get MED version number + // If MED version is < 2.2 then the cells which dimension + // is lesser than the main dimension ( Connectivity->_entityDimension ) + // are either faces or edges + + // string medVersion(version_med); + // int firstNumber = + int * tmpEdgeCount = new int[MED_NBR_GEOMETRIE_MAILLE] ; + tmpEdgeCount[0] = 0 ; int numberOfEdgesTypes = 0; - int * tmp_faces_count = new int[MED_NBR_GEOMETRIE_MAILLE] ; + int * tmpFaceCount = new int[MED_NBR_GEOMETRIE_MAILLE] ; + tmpFaceCount[0] = 0 ; int numberOfFacesTypes = 0; + if ((version_med != "2.2")&(Entity==MED_FR::MED_MAILLE)) { - Connectivity->_numberOfTypes=0; - for (int i=1;i_numberOfTypes=0; + + for ( i=1;i_entityDimension==dimension) @@ -741,13 +725,13 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) if (dimension == 2) if (Connectivity->_entityDimension==3) { - tmp_faces_count[i]=tmp_cells_count[i] ; + tmpFaceCount[i]=tmp_cells_count[i] ; tmp_cells_count[i]=0 ; numberOfFacesTypes++; } if (dimension == 1) if (Connectivity->_entityDimension>dimension) { - tmp_edges_count[i]=tmp_cells_count[i] ; + tmpEdgeCount[i]=tmp_cells_count[i] ; tmp_cells_count[i]=0; numberOfEdgesTypes++ ; } @@ -765,15 +749,16 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) Connectivity->_count[0] = 1; int size = 0 ; - int TypeNumber=1 ; - for (int i=1;i0) { - Connectivity->_count[TypeNumber]=Connectivity->_count[TypeNumber-1]+tmp_cells_count[i]; + 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 ; + Connectivity->_type[typeNumber-1]=t ; - Connectivity->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ; + Connectivity->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ; // probleme avec les mailles de dimension < a dimension du maillage : // Il faut oter le zero a la lecture est le remettre a l'ecriture : ce n'est pas fait !!!!! On interdit ce cas pour l'instant !!! @@ -782,9 +767,9 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) size+=tmp_cells_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ; MESSAGE(LOC - << Connectivity->_count[TypeNumber]-1 << " cells of type " + << Connectivity->_count[typeNumber]-1 << " cells of type " << all_cell_type_tab[i] ); - TypeNumber++; + typeNumber++; } } @@ -796,7 +781,8 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) NodalIndex[0]=1 ; // Fill the MEDSKYLINEARRAY by reading the MED file. - for (int i=0;i_numberOfTypes;i++) { + int j=0; + for ( i=0;i_numberOfTypes;i++) { int multi = 0 ; MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) Connectivity->_type[i].getType() ; // if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension) @@ -808,7 +794,7 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes() ; // initialise index - for (int j=Connectivity->_count[i]; j_count[i+1];j++) + for ( j=Connectivity->_count[i]; j_count[i+1];j++) NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell ; int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ; @@ -820,16 +806,18 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) int err=MEDconnLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), _ptrMesh->_spaceDimension,tmp_ConnectivityArray, MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD); + if ( err != MED_VALID) { delete[] tmp_ConnectivityArray; delete[] tmp_cells_count; - delete[] tmp_faces_count; - delete[] tmp_edges_count; + delete[] tmpFaceCount; + delete[] tmpEdgeCount; MESSAGE(LOC<<": MEDconnLire returns "<_count[i]-1]-1 ; - for (int j=0; j_entityDimension = 2 ; constituent->_count[0]=1 ; - int size = 0 ; - int size_more_one = 0 ; - int TypeNumber=1 ; - for (int i=1;i0) { + // In order to create the MEDSKYLINEARRAY of the constituent object we need : + // 1: + // To initialize the _count array of the constituent object (containning cumulated face count by geometric type) + // _count[0]=1 and _count[_numberOfTypes] give the size of NodalIndex + // 2: + // To calculate the total number of face nodes whatever the geometric type is. + // The result is the size of the array containning all the nodes : NodalValue + // 3 : + // To calculate the starting indexes of the different face types in NodalValue, + // this is the NodalIndex array. + + int size = 0 ; + int typeNumber = 1 ; + int i; + for ( i=1; i < MED_NBR_GEOMETRIE_MAILLE; i++) { // no point1 cell type (?) + if (tmpFaceCount[i]>0) { - constituent->_count[TypeNumber]=constituent->_count[TypeNumber-1]+tmp_faces_count[i]; + constituent->_count[typeNumber] = constituent->_count[typeNumber-1] + tmpFaceCount[i]; CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ; - constituent->_type[TypeNumber-1]=t ; + constituent->_type[typeNumber-1]=t ; - constituent->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ; + constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ; - size+=tmp_faces_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ; - TypeNumber++; + size+=tmpFaceCount[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ; + typeNumber++; } } @@ -880,32 +883,39 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) NodalIndex[0]=1 ; // Fill the MEDSKYLINEARRAY by reading the MED file. - for (int i=0;i_numberOfTypes;i++) { + for ( i=0; i_numberOfTypes; i++) { MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) constituent->_type[i].getType() ; int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ; - // initialise index + // initialise NodalIndex for (int j=constituent->_count[i]; j_count[i+1];j++) NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace ; int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i] ; // Il faut ajouter 1 pour le zero a la lecture !!! - int * tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ; - + // ATTENTION UNIQUEMENT POUR MED < 2.2.x + int * tmp_constituentArray = NULL; + if (version_med != "2.2") + tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ; + else { + tmp_constituentArray = new int[NumberOfNodeByFace*tmp_numberOfFaces] ; + MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ; + } int err=MEDconnLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), Connectivity->_entityDimension,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 "<_count[i]-1]-1 ; + int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ; for (int j=0; j_constituent = constituent ; } - delete[] tmp_faces_count; + delete[] tmpFaceCount; // get Edge if any // =============== @@ -933,19 +943,23 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) constituent->_count[0]=1 ; int size = 0 ; - int size_more_one = 0 ; - int TypeNumber=1 ; - for (int i=1;i0) { + int typeNumber=1 ; + // if you declare a variable in two initialization statement, + // compiler gcc2.95.3 says nothing but there are two variables in the same block + //and the value you get in the common block seems to be the value of the first variable ! + int i; + + for ( i=1; i0) { - constituent->_count[TypeNumber]=constituent->_count[TypeNumber-1]+tmp_edges_count[i]; + constituent->_count[typeNumber]=constituent->_count[typeNumber-1]+tmpEdgeCount[i]; CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ; - constituent->_type[TypeNumber-1]=t ; + constituent->_type[typeNumber-1]=t ; - constituent->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ; + constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ; - size+=tmp_edges_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ; - TypeNumber++; + size+=tmpEdgeCount[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ; + typeNumber++; } } @@ -957,7 +971,7 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) NodalIndex[0]=1 ; // Fill the MEDSKYLINEARRAY by reading the MED file. - for (int i=0;i_numberOfTypes;i++) { + for ( i=0; i_numberOfTypes; i++) { MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) constituent->_type[i].getType() ; int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ; @@ -968,7 +982,15 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i] ; // Il faut ajouter 1 pour le zero a la lecture !!! - int * tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ; + + // ATTENTION UNIQUEMENT POUR MED < 2.2.x + int * tmp_constituentArray = NULL; + if (version_med != "2.2") + tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ; + else { + tmp_constituentArray = new int[NumberOfNodeByEdge*tmp_numberOfEdges] ; + MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ; + } int err=MEDconnLire(_medIdt,const_cast (_ptrMesh->_name.c_str()), _ptrMesh->_spaceDimension,tmp_constituentArray, @@ -977,11 +999,11 @@ int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) MESSAGE(LOC<<": MEDconnLire returns "<_count[i]-1]-1 ; + int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ; for (int j=0; j_constituent = constituent ; } - delete[] tmp_edges_count; + delete[] tmpEdgeCount; return MED_VALID; } + return MED_ERROR; } int MED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity) { - const char * LOC = "MED_MESH_RDONLY_DRIVER::getDescendingConnectivity " ; + const char * LOC = "MED_MESH_RDONLY_DRIVER::getDescendingConnectivity : " ; if (_status==MED_OPENED) { - MESSAGE(LOC<<" Not implemented !"); + MESSAGE(LOC<<"call on the object " << Connectivity); + MESSAGE(LOC<<"Not yet implemented !"); } return MED_ERROR; } @@ -1077,12 +1101,18 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() MEDArrayNodeFamily = new int[_ptrMesh->getNumberOfNodes()] ; err = getNodesFamiliesNumber(MEDArrayNodeFamily) ; // error only if (_status!=MED_OPENED), other case exeception ! // CELL + + MESSAGE(LOC << "error returned from getNodesFamiliesNumber " << err); + 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) ; + err = getCellsFamiliesNumber(MEDArrayCellFamily,_ptrMesh->_connectivity) ; + + MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Cells " << err); + if (_ptrMesh->_connectivity->_constituent != NULL) { if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE) { // FACE @@ -1091,14 +1121,20 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() 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) ; + err = getCellsFamiliesNumber(MEDArrayFaceFamily,_ptrMesh->_connectivity->_constituent) ; + + MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Faces " << err); + } 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) ; + err = getCellsFamiliesNumber(MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ; + + MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Edges in 2D " << err); + } // EDGE in 3D if (_ptrMesh->_connectivity->_constituent->_constituent != NULL) { @@ -1106,7 +1142,10 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() 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 ! + err = getCellsFamiliesNumber(MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent->_constituent) ; // we are in 3D ! + + MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Edges in 3D " << err); + } } } @@ -1129,6 +1168,8 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() if ( NumberOfFamilies < 1 ) // at least family 0 must exist throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" )); + SCRUTE(NumberOfFamilies); + vector &NodeFamilyVector = _ptrMesh->_familyNode ; vector &CellFamilyVector = _ptrMesh->_familyCell ; vector &FaceFamilyVector = _ptrMesh->_familyFace ; @@ -1162,7 +1203,12 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() &NumberOfAttributes, const_cast (GroupsNames.c_str()),&NumberOfGroups ); - //SCRUTE(GroupsNames); + + SCRUTE(GroupsNames); + SCRUTE(FamilyName); + SCRUTE(err); + SCRUTE(i); + if (err != MED_VALID) throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : ERROR when get FAMILY informations" ); if (FamilyIdentifier != 0 ) { @@ -1178,7 +1224,7 @@ int MED_MESH_RDONLY_DRIVER::getFAMILY() // All good ? // if nothing found, delete Family if (Family->getNumberOfTypes() == 0) { - INFOS(LOC<<"Nothing found for family "<getEntity()) { @@ -1421,7 +1467,8 @@ void MED_MESH_WRONLY_DRIVER::write(void) const // test if the family already exists (HDF trick waiting a MED evolution to be replaced) string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_0/"; MESSAGE("|"< (dataGroupFam.c_str()) ) < MED_VALID ) { + err =_MEDdatagroupOuvrir(_medIdt,const_cast (dataGroupFam.c_str()) ); + if ( err < MED_VALID ) { SCRUTE(err); err = MED_FR::MEDfamCr( _medIdt, @@ -2070,7 +2117,7 @@ int MED_MESH_WRONLY_DRIVER::writeFamilies(vector & families ) const { MESSAGE(LOC<<" families.size() :"<getNumberOfAttributes (); string attributesDescriptions = ""; @@ -2110,7 +2157,8 @@ int MED_MESH_WRONLY_DRIVER::writeFamilies(vector & families ) const { // 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 ) { + err =_MEDdatagroupOuvrir(_medIdt,const_cast (dataGroupFam.c_str()) ) ; + if ( err < MED_VALID ) { SCRUTE(err); MESSAGE(LOC<<"families[i]->getName().c_str() : "<getName().c_str()); diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver.hxx b/src/MEDMEM/MEDMEM_MedMeshDriver.hxx index cae5ab857..9762d263c 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver.hxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver.hxx @@ -1,29 +1,3 @@ -// 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.hxx -// Module : MED - #ifndef MED_MESH_DRIVER_HXX #define MED_MESH_DRIVER_HXX diff --git a/src/MEDMEM/MEDMEM_Mesh.cxx b/src/MEDMEM/MEDMEM_Mesh.cxx index 0050168db..93d7cfc59 100644 --- a/src/MEDMEM/MEDMEM_Mesh.cxx +++ b/src/MEDMEM/MEDMEM_Mesh.cxx @@ -1,29 +1,3 @@ -// 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_Mesh.cxx -// Module : MED - using namespace std; /* File Mesh.cxx @@ -45,7 +19,7 @@ using namespace std; #include "MEDMEM_Coordinate.hxx" #include "MEDMEM_Connectivity.hxx" #include "MEDMEM_CellModel.hxx" -#include "MEDMEM_Grid.hxx" +//#include "MEDMEM_Grid.hxx" this inclision should have never be here !!! //update Families with content list //int family_count(int family_number, int count, int * entities_number, int * entities_list) ; @@ -56,11 +30,14 @@ using namespace std; //const MESH::INSTANCE * const MESH::instances[] = { &MESH::inst_med_rdonly , &MESH::inst_med_rdwr } ; // Add a similar line for your personnal driver (step 3) + MESH::INSTANCE_DE MESH::inst_med ; MESH::INSTANCE_DE MESH::inst_gibi ; +MESH::INSTANCE_DE MESH::inst_vtk; + // Add your own driver in the driver list (step 4) // Note the list must be coherent with the driver type list defined in MEDMEM_DRIVER.hxx. -const MESH::INSTANCE * const MESH::instances[] = { &MESH::inst_med, &MESH::inst_gibi } ; +const MESH::INSTANCE * const MESH::instances[] = { &MESH::inst_med, &MESH::inst_gibi, &MESH::inst_vtk } ; /*! Add a MESH driver of type (MED_DRIVER, ....) associated with file . The meshname used in the file is . addDriver returns an int handler. */ @@ -71,18 +48,50 @@ int MESH::addDriver(driverTypes driverType, GENDRIVER * driver; int current; + int itDriver = (int) NO_DRIVER; BEGIN_OF(LOC); - driver = instances[driverType]->run(fileName, this) ; + SCRUTE(driverType); + + SCRUTE(instances[driverType]); + + switch(driverType) + { + case MED_DRIVER : { + itDriver = (int) driverType ; + break ; + } + + case GIBI_DRIVER : { + itDriver = (int) driverType ; + break ; + } + + case VTK_DRIVER : { + itDriver = 2 ; + break ; + } + + case NO_DRIVER : { + throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "NO_DRIVER has been specified to the method which is not allowed")); + } + } + + if (itDriver == ((int) NO_DRIVER)) + throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "othe driver than MED_DRIVER GIBI_DRIVER and VT_DRIVER has been specified to the method which is not allowed")); + + driver = instances[itDriver]->run(fileName, this) ; + _drivers.push_back(driver); + current = _drivers.size()-1; _drivers[current]->setMeshName(driverName); - return current; END_OF(LOC); + return current; } /*! Add an existing MESH driver. */ @@ -131,8 +140,8 @@ void MESH::init() { string _name = "NOT DEFINED"; // A POSITIONNER EN FCT DES IOS ? - COORDINATE * _coordinate = (COORDINATE *) NULL; - CONNECTIVITY * _connectivity = (CONNECTIVITY *) NULL; + _coordinate = (COORDINATE *) NULL; + _connectivity = (CONNECTIVITY *) NULL; _spaceDimension = MED_INVALID; // 0 ?!? _meshDimension = MED_INVALID; @@ -149,10 +158,12 @@ void MESH::init() { _numberOfEdgesGroups = 0; _isAGrid = false; + + END_OF(LOC); }; /*! Create an empty MESH. */ -MESH::MESH():_coordinate(NULL),_connectivity(NULL) { +MESH::MESH():_coordinate(NULL),_connectivity(NULL), _isAGrid(false) { init(); }; @@ -250,40 +261,32 @@ MESH::~MESH() { int size ; size = _familyNode.size() ; for (int i=0;i. The meshname must already exists in the file.*/ -MESH::MESH(driverTypes driverType, const string & fileName/*=""*/, const string & driverName/*=""*/) { +MESH::MESH(driverTypes driverType, const string & fileName/*=""*/, const string & driverName/*=""*/) throw (MEDEXCEPTION) +{ const char * LOC ="MESH::MESH(driverTypes driverType, const string & fileName="", const string & driverName="") : "; - int current; BEGIN_OF(LOC); init(); - - MED_MESH_RDONLY_DRIVER myDriver(fileName,this) ; - myDriver.setMeshName(driverName); - current = addDriver(myDriver); + + switch(driverType) + { + case MED_DRIVER : + { + MED_MESH_RDONLY_DRIVER myDriver(fileName,this); + myDriver.setMeshName(driverName); + current = addDriver(myDriver); + break; + } + case GIBI_DRIVER : + { + GIBI_MESH_RDONLY_DRIVER myDriver(fileName,this); + current = addDriver(myDriver); + break; + } + default : + { + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Driver type unknown : can't create driver!")); + break; + } + } + // current = addDriver(driverType,fileName,driverName); // switch(_drivers[current]->getAccessMode() ) { // case MED_WRONLY : { @@ -356,8 +383,8 @@ MESH::MESH(driverTypes driverType, const string & fileName/*=""*/, const string _drivers[current]->read(); _drivers[current]->close(); - if (_isAGrid) - ((GRID *) this)->fillMeshAfterRead(); +// if (_isAGrid) +// ((GRID *) this)->fillMeshAfterRead(); END_OF(LOC); }; @@ -371,7 +398,7 @@ MESH::MESH(driverTypes driverType, const string & fileName/*=""*/, const string // return N; // } -ostream & operator<<(ostream &os, MESH &myMesh) +ostream & operator<<(ostream &os, const MESH &myMesh) { int spacedimension = myMesh.getSpaceDimension(); int meshdimension = myMesh.getMeshDimension(); @@ -404,49 +431,8 @@ ostream & operator<<(ostream &os, MESH &myMesh) os << endl; } - const CONNECTIVITY * myConnectivity = myMesh.getConnectivityptr(); - if (!myConnectivity->existConnectivity(MED_NODAL,MED_CELL) && myConnectivity->existConnectivity(MED_DESCENDING,MED_CELL)) - { - os << endl << "SHOW CONNECTIVITY (DESCENDING) :" << endl; - int numberofelements; - const int * connectivity; - const int * connectivity_index; - myMesh.calculateConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL); - try { - numberofelements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS); - connectivity = myMesh.getConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS); - connectivity_index = myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL); - } - catch (MEDEXCEPTION m) { - os << m.what() << endl; - exit (-1); - } - for (int j=0;j* MESH::getVolume(const SUPPORT * Support) const throw (MEDEXCEPTIO throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get Volumes on it !")); break; } + + if (!onAll) delete [] global_connectivity ; } return Volume; @@ -1289,6 +1277,8 @@ FIELD* MESH::getArea(const SUPPORT * Support) const throw (MEDEXCEPTION) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get Areas on it !")); break; } + + if (!onAll) delete [] global_connectivity ; } Area->setValue(MED_FULL_INTERLACE,area); @@ -1406,6 +1396,8 @@ FIELD* MESH::getLength(const SUPPORT * Support) const throw (MEDEXCEPTIO throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get Lengths on it !")); break; } + + if (!onAll) delete [] global_connectivity ; } return Length; @@ -1523,7 +1515,7 @@ FIELD* MESH::getNormal(const SUPPORT * Support) const throw (MEDEXCEPTIO int N2 = global_connectivity[tria_index+1]-1; int N3 = global_connectivity[tria_index+2]-1; - double xarea; + //double xarea; !! UNUSED VARIABLE !! double x1 = coord[dim_space*N1]; double x2 = coord[dim_space*N2]; double x3 = coord[dim_space*N3]; @@ -1639,6 +1631,8 @@ FIELD* MESH::getNormal(const SUPPORT * Support) const throw (MEDEXCEPTIO throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get Normals on it !")); break; } + + if (!onAll) delete [] global_connectivity ; } Normal->setValue(MED_FULL_INTERLACE,normal); @@ -2047,6 +2041,8 @@ FIELD* MESH::getBarycenter(const SUPPORT * Support) const throw (MEDEXCE throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get a barycenter on it (in fact unknown type) !")); break; } + + if (!onAll) delete [] global_connectivity ; } Barycenter->setValue(MED_FULL_INTERLACE,barycenter); @@ -2063,24 +2059,35 @@ FIELD* MESH::getBarycenter(const SUPPORT * Support) const throw (MEDEXCE //purpose : if this->_isAGrid, assure that _coordinate is filled //======================================================================= -inline void MESH::checkGridFillCoords() const -{ - if (_isAGrid) - ((GRID *) this)->fillCoordinates(); -} +// inline void MESH::checkGridFillCoords() const +// { +// if (_isAGrid) +// ((GRID *) this)->fillCoordinates(); +// } //======================================================================= //function : checkGridFillConnectivity //purpose : if this->_isAGrid, assure that _connectivity is filled //======================================================================= -inline void MESH::checkGridFillConnectivity() const +// inline void MESH::checkGridFillConnectivity() const +// { +// if (_isAGrid) +// ((GRID *) this)->fillConnectivity(); +// } + +bool MESH::isEmpty() const { - if (_isAGrid) - ((GRID *) this)->fillConnectivity(); + bool notempty = _name != "" || _coordinate != NULL || _connectivity != NULL || + _spaceDimension !=MED_INVALID || _meshDimension !=MED_INVALID || + _numberOfNodes !=MED_INVALID || _numberOfNodesFamilies !=0 || + _familyNode.size() != 0 || _numberOfCellsFamilies != 0 || + _familyCell.size() != 0 || _numberOfFacesFamilies != 0 || + _familyFace.size() != 0 || _numberOfEdgesFamilies !=0 || + _familyEdge.size() != 0 || _isAGrid != 0 ; + return !notempty; } - void MESH::read(int index) { const char * LOC = "MESH::read(int index=0) : "; @@ -2097,8 +2104,8 @@ void MESH::read(int index) << _drivers.size() ) ); - if (_isAGrid) - ((GRID *) this)->fillMeshAfterRead(); +// if (_isAGrid) +// ((GRID *) this)->fillMeshAfterRead(); END_OF(LOC); } @@ -2220,7 +2227,7 @@ SUPPORT * MESH::getSkin(const SUPPORT * Support3D) throw (MEDEXCEPTION) } numberOfGeometricType = theType.size() ; geometricType = new medGeometryElement[numberOfGeometricType] ; - const medGeometryElement * allType = getTypes(MED_FACE); + //const medGeometryElement * allType = getTypes(MED_FACE); !! UNUSED VARIABLE !! numberOfGaussPoint = new int[numberOfGeometricType] ; geometricTypeNumber = new int[numberOfGeometricType] ; // not use, but initialized to nothing numberOfEntities = new int[numberOfGeometricType] ; @@ -2260,3 +2267,257 @@ SUPPORT * MESH::getSkin(const SUPPORT * Support3D) throw (MEDEXCEPTION) return mySupport ; } + +/*! + return a SUPPORT pointer on the union of all SUPPORTs in Supports. + You should delete this pointer after use to avoid memory leaks. +*/ +SUPPORT * MESH::mergeSupports(const vector Supports) const throw (MEDEXCEPTION) +{ + const char * LOC = "MESH:::mergeSupports(const vector ) : " ; + BEGIN_OF(LOC) ; + + SUPPORT * returnedSupport; + string returnedSupportName; + string returnedSupportDescription; + char * returnedSupportNameChar; + char * returnedSupportDescriptionChar; + int size = Supports.size(); + + if (size == 1) + { + MESSAGE(LOC <<" there is only one SUPPORT in the argument list, the method return a copy of this object !"); + SUPPORT * obj = const_cast (Supports[0]); + + returnedSupport = new SUPPORT(*obj); + + int lenName = strlen((Supports[0]->getName()).c_str()) + 8 + 1; + int lenDescription = strlen((Supports[0]->getDescription()).c_str()) + 8 + 1; + + returnedSupportNameChar = new char[lenName]; + returnedSupportDescriptionChar = new char[lenDescription]; + + returnedSupportNameChar = strcpy(returnedSupportNameChar,"Copy of "); + returnedSupportNameChar = strcat(returnedSupportNameChar,(Supports[0]->getName()).c_str()); + returnedSupportDescriptionChar = strcpy(returnedSupportDescriptionChar,"Copy of "); + returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar, + (Supports[0]->getDescription()).c_str()); + + returnedSupportName = string(returnedSupportNameChar); + returnedSupportDescription = string(returnedSupportDescriptionChar); + + returnedSupport->setName(returnedSupportName); + returnedSupport->setDescription(returnedSupportDescription); + + delete [] returnedSupportNameChar; + delete [] returnedSupportDescriptionChar; + } + else + { + SUPPORT * obj = const_cast (Supports[0]); + returnedSupport = new SUPPORT(*obj); + + int lenName = strlen((Supports[0]->getName()).c_str()) + 9 + 1; + int lenDescription = strlen((Supports[0]->getDescription()).c_str()) + 9 + 1; + + for(int i = 1;i (Supports[i]); + returnedSupport->blending(obj); + + if (i == (size-1)) + { + lenName = lenName + 5 + strlen((Supports[i]->getName()).c_str()); + lenDescription = lenDescription + 5 + + strlen((Supports[i]->getDescription()).c_str()); + } + else + { + lenName = lenName + 2 + strlen((Supports[i]->getName()).c_str()); + lenDescription = lenDescription + 2 + + strlen((Supports[i]->getDescription()).c_str()); + } + } + + returnedSupportNameChar = new char[lenName]; + returnedSupportDescriptionChar = new char[lenDescription]; + + returnedSupportNameChar = strcpy(returnedSupportNameChar,"Merge of "); + returnedSupportDescriptionChar = strcpy(returnedSupportDescriptionChar,"Merge of "); + + returnedSupportNameChar = strcat(returnedSupportNameChar,(Supports[0]->getName()).c_str()); + returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar, + (Supports[0]->getDescription()).c_str()); + + for(int i = 1;igetName()).c_str()); + returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar, + (Supports[i]->getDescription()).c_str()); + } + else + { + returnedSupportNameChar = strcat(returnedSupportNameChar,", "); + returnedSupportNameChar = strcat(returnedSupportNameChar, + (Supports[i]->getName()).c_str()); + + returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar,", "); + returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar, + (Supports[i]->getDescription()).c_str()); + } + } + + returnedSupportName = string(returnedSupportNameChar); + returnedSupport->setName(returnedSupportName); + + returnedSupportDescription = string(returnedSupportDescriptionChar); + returnedSupport->setDescription(returnedSupportDescription); + + delete [] returnedSupportNameChar; + delete [] returnedSupportDescriptionChar; + } + + END_OF(LOC) ; + return returnedSupport; +} + +/*! + return a SUPPORT pointer on the intersection of all SUPPORTs in Supports. + The (SUPPORT *) NULL pointer is returned if the intersection is empty. + You should delete this pointer after use to avois memory leaks. +*/ +SUPPORT * MESH::intersectSupports(const vector Supports) const throw (MEDEXCEPTION) +{ + const char * LOC = "MESH:::intersectSupports(const vector ) : " ; + BEGIN_OF(LOC) ; + + SUPPORT * returnedSupport; + string returnedSupportName; + string returnedSupportDescription; + char * returnedSupportNameChar; + char * returnedSupportDescriptionChar; + int size = Supports.size(); + + if (size == 1) + { + MESSAGE(LOC <<" there is only one SUPPORT in the argument list, the method return a copy of this object !"); + SUPPORT * obj = const_cast (Supports[0]); + + returnedSupport = new SUPPORT(*obj); + + int lenName = strlen((Supports[0]->getName()).c_str()) + 8 + 1; + int lenDescription = strlen((Supports[0]->getDescription()).c_str()) + 8 + 1; + + returnedSupportNameChar = new char[lenName]; + returnedSupportDescriptionChar = new char[lenDescription]; + + returnedSupportNameChar = strcpy(returnedSupportNameChar,"Copy of "); + returnedSupportNameChar = strcat(returnedSupportNameChar,(Supports[0]->getName()).c_str()); + returnedSupportDescriptionChar = strcpy(returnedSupportDescriptionChar,"Copy of "); + returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar, + (Supports[0]->getDescription()).c_str()); + + returnedSupportName = string(returnedSupportNameChar); + returnedSupportDescription = string(returnedSupportDescriptionChar); + + returnedSupport->setName(returnedSupportName); + returnedSupport->setDescription(returnedSupportDescription); + + delete [] returnedSupportNameChar; + delete [] returnedSupportDescriptionChar; + } + else + { + SUPPORT * obj = const_cast (Supports[0]); + returnedSupport = new SUPPORT(*obj); + + int lenName = strlen((Supports[0]->getName()).c_str()) + 16 + 1; + int lenDescription = strlen((Supports[0]->getDescription()).c_str()) + 16 + 1; + + for(int i = 1;i (Supports[i]); + returnedSupport->intersecting(obj); + + if (i == (size-1)) + { + lenName = lenName + 5 + strlen((Supports[i]->getName()).c_str()); + lenDescription = lenDescription + 5 + + strlen((Supports[i]->getDescription()).c_str()); + } + else + { + lenName = lenName + 2 + strlen((Supports[i]->getName()).c_str()); + lenDescription = lenDescription + 2 + + strlen((Supports[i]->getDescription()).c_str()); + } + } + + if(returnedSupport != (SUPPORT *) NULL) + { + returnedSupportNameChar = new char[lenName]; + returnedSupportDescriptionChar = new char[lenDescription]; + + returnedSupportNameChar = strcpy(returnedSupportNameChar, + "Intersection of "); + returnedSupportDescriptionChar = + strcpy(returnedSupportDescriptionChar,"Intersection of "); + + returnedSupportNameChar = strcat(returnedSupportNameChar, + (Supports[0]->getName()).c_str()); + returnedSupportDescriptionChar = + strcat(returnedSupportDescriptionChar, + (Supports[0]->getDescription()).c_str()); + + for(int i = 1;igetName()).c_str()); + returnedSupportDescriptionChar = + strcat(returnedSupportDescriptionChar, + (Supports[i]->getDescription()).c_str()); + } + else + { + returnedSupportNameChar = strcat(returnedSupportNameChar, + ", "); + returnedSupportNameChar = + strcat(returnedSupportNameChar, + (Supports[i]->getName()).c_str()); + + returnedSupportDescriptionChar = + strcat(returnedSupportDescriptionChar,", "); + returnedSupportDescriptionChar = + strcat(returnedSupportDescriptionChar, + (Supports[i]->getDescription()).c_str()); + } + } + + returnedSupportName = string(returnedSupportNameChar); + returnedSupport->setName(returnedSupportName); + + returnedSupportDescription = string(returnedSupportDescriptionChar); + returnedSupport->setDescription(returnedSupportDescription); + + delete [] returnedSupportNameChar; + delete [] returnedSupportDescriptionChar; + } + } + + END_OF(LOC) ; + return returnedSupport; +} diff --git a/src/MEDMEM/MEDMEM_Mesh.hxx b/src/MEDMEM/MEDMEM_Mesh.hxx index 9fad12dfa..ac8954cee 100644 --- a/src/MEDMEM/MEDMEM_Mesh.hxx +++ b/src/MEDMEM/MEDMEM_Mesh.hxx @@ -1,29 +1,3 @@ -// 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_Mesh.hxx -// Module : MED - #ifndef MESH_HXX #define MESH_HXX @@ -44,6 +18,8 @@ #include "MEDMEM_MedMedDriver.hxx" #include "MEDMEM_GibiMeshDriver.hxx" +#include "MEDMEM_VtkMeshDriver.hxx" + class CELLMODEL; class FAMILY; class GROUP; @@ -51,9 +27,9 @@ class SUPPORT; template class FIELD; -//class GENDRIVER ; -//class MED_MESH_RDONLY_DRIVER ; -//class MED_MESH_WRONLY_DRIVER ; +//class GENDRIVER; +//class MED_MESH_RDONLY_DRIVER; +//class MED_MESH_WRONLY_DRIVER; using namespace MED_EN; @@ -84,8 +60,8 @@ protected: //-----------------------// { public: - virtual GENDRIVER * run(const string & fileName, MESH * ptrMesh) const = 0 ; - } ; + virtual GENDRIVER * run(const string & fileName, MESH * ptrMesh) const = 0; + }; //-------------------------------------------------------// template class INSTANCE_DE : public INSTANCE @@ -93,14 +69,17 @@ protected: { public : GENDRIVER * run(const string & fileName, MESH * ptrMesh) const - { return new T(fileName,ptrMesh) ; } - } ; + { return new T(fileName,ptrMesh); } + }; // Add a similar line for your personnal driver (step 3) - static INSTANCE_DE inst_med ; - static INSTANCE_DE inst_gibi ; - //static INSTANCE_DE inst_vtk ; - static const INSTANCE * const instances[] ; + + static INSTANCE_DE inst_med; + static INSTANCE_DE inst_gibi; + static INSTANCE_DE inst_vtk; + + //static INSTANCE_DE inst_vtk ; + static const INSTANCE * const instances[]; // ------ End of Drivers Management Part @@ -113,21 +92,21 @@ protected : string _name; // A POSITIONNER EN FCT DES IOS ? - COORDINATE * _coordinate; - CONNECTIVITY * _connectivity; + mutable COORDINATE * _coordinate; + mutable CONNECTIVITY * _connectivity; - int _spaceDimension; - int _meshDimension ; - int _numberOfNodes ; + int _spaceDimension; + int _meshDimension; + int _numberOfNodes; int _numberOfNodesFamilies; //INUTILE ? -> _familyNode.size() - vector _familyNode ; // array of size _numberOfNodesFamilies; + vector _familyNode; // array of size _numberOfNodesFamilies; int _numberOfCellsFamilies; - vector _familyCell ; // array of size _numberOfCellsFamilies; + vector _familyCell; // array of size _numberOfCellsFamilies; int _numberOfFacesFamilies; - vector _familyFace ; // array of size _numberOfFacesFamilies; + vector _familyFace; // array of size _numberOfFacesFamilies; int _numberOfEdgesFamilies; - vector _familyEdge ; // array of size _numberOfEdgesFamilies; + vector _familyEdge; // array of size _numberOfEdgesFamilies; int _numberOfNodesGroups; //INUTILE ? vector _groupNode; // array of size _numberOfNodesGroups; @@ -147,8 +126,9 @@ protected : // Methods //-----------------------// - inline void checkGridFillCoords() const; - inline void checkGridFillConnectivity() const; +// inline void checkGridFillCoords() const; +// inline void checkGridFillConnectivity() const; + bool isEmpty() const; // if this->_isAGrid, assure that _coordinate and _connectivity are filled public : @@ -165,14 +145,16 @@ public : friend class GIBI_MESH_WRONLY_DRIVER; friend class GIBI_MESH_RDWR_DRIVER; + friend class VTK_MESH_DRIVER; + void init(); MESH(); MESH(MESH &m); MESH & operator=(const MESH &m); MESH( driverTypes driverType, const string & fileName="", - const string & meshName=""); - ~MESH(); - friend ostream & operator<<(ostream &os, MESH &my) ; + const string & meshName="") throw (MEDEXCEPTION); + virtual ~MESH(); + friend ostream & operator<<(ostream &os, const MESH &my); int addDriver(driverTypes driverType, const string & fileName ="Default File Name.med", @@ -180,65 +162,107 @@ public : int addDriver(GENDRIVER & driver); void rmDriver(int index=0); - void read(int index=0); + virtual void read(int index=0); inline void read(const MED_MED_DRIVER & genDriver); inline void write(int index=0, const string & driverName = ""); inline void write(const MED_MED_DRIVER & genDriver); // void calculateReverseConnectivity(); // void createFaces(); //Faces creation => full constituent informations - // void buildConstituent() ; // calculate descendent connectivity + face-cell connectivity + // void buildConstituent(); // calculate descendent connectivity + face-cell connectivity inline void setName(string name); inline string getName() const; - inline int getSpaceDimension() const ; - inline int getMeshDimension() const ; + inline int getSpaceDimension() const; + inline int getMeshDimension() const; inline bool getIsAGrid(); - inline int getNumberOfNodes() const ; - inline const COORDINATE * getCoordinateptr() const ; - inline string getCoordinatesSystem() const ; - inline const double * getCoordinates(medModeSwitch Mode) const ; - inline const double getCoordinate(int Number,int Axis) const ; - inline const string * getCoordinatesNames() const ; - inline const string * getCoordinatesUnits() const ; - // inline int * getNodesNumbers(); - - inline int getNumberOfTypes(medEntityMesh Entity) const ; - inline const medGeometryElement * getTypes(medEntityMesh Entity) const ; - inline const CELLMODEL * getCellsTypes(medEntityMesh Entity) const ; - inline const int * getGlobalNumberingIndex(medEntityMesh Entity) const ; - inline int getNumberOfElements(medEntityMesh Entity,medGeometryElement Type) const ; - inline bool existConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity) const ; - inline medGeometryElement getElementType(medEntityMesh Entity,int Number) const ; - inline void calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity) ; - inline const int * getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity, medGeometryElement Type) const ; - inline const int * getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity) const ; - int getElementNumber(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type, int * connectivity) const ; - inline const int * getReverseConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity=MED_CELL) const ; - inline const int * getReverseConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity=MED_CELL) const ; - - inline int getNumberOfFamilies(medEntityMesh Entity) const ; - inline const vector getFamilies(medEntityMesh Entity) const ; - inline const FAMILY* getFamily(medEntityMesh Entity,int i) const ; - inline int getNumberOfGroups(medEntityMesh Entity) const ; - inline const vector getGroups(medEntityMesh Entity) const ; - inline const GROUP* getGroup(medEntityMesh Entity,int i) const ; - inline const CONNECTIVITY* getConnectivityptr() const ; - SUPPORT * getBoundaryElements(medEntityMesh Entity) throw (MEDEXCEPTION) ; - //SUPPORT * getBoundaryElements(medEntityMesh Entity) const throw (MEDEXCEPTION) ; // problème avec le maillage dans le support : le pointeur n'est pas const, mais sa valeur oui. A voir !!! PG - - SUPPORT * getSkin(const SUPPORT * Support3D) throw (MEDEXCEPTION) ; + inline int getNumberOfNodes() const; + virtual inline const COORDINATE * getCoordinateptr() const; + inline string getCoordinatesSystem() const; + virtual inline const double * getCoordinates(medModeSwitch Mode) const; + virtual inline const double getCoordinate(int Number,int Axis) const; + inline const string * getCoordinatesNames() const; + inline const string * getCoordinatesUnits() const; + //inline int * getNodesNumbers(); + + virtual inline int getNumberOfTypes(medEntityMesh Entity) const; + virtual inline const medGeometryElement * getTypes(medEntityMesh Entity) const; + virtual inline const CELLMODEL * getCellsTypes(medEntityMesh Entity) const; + virtual const int * getGlobalNumberingIndex(medEntityMesh Entity) const; + virtual inline int getNumberOfElements(medEntityMesh Entity, + medGeometryElement Type) const; + virtual inline bool existConnectivity(medConnectivity ConnectivityType, + medEntityMesh Entity) const; + + virtual inline medGeometryElement getElementType(medEntityMesh Entity, + int Number) const; + virtual inline void calculateConnectivity(medModeSwitch Mode, + medConnectivity ConnectivityType, + medEntityMesh Entity) const ; + virtual inline const int * getConnectivity(medModeSwitch Mode, + medConnectivity ConnectivityType, + medEntityMesh Entity, + medGeometryElement Type) const; + virtual inline const int * getConnectivityIndex(medConnectivity ConnectivityType, + medEntityMesh Entity) const; + virtual int getElementNumber(medConnectivity ConnectivityType, + medEntityMesh Entity, + medGeometryElement Type, + int * connectivity) const; + + virtual inline const int * getReverseConnectivity(medConnectivity ConnectivityType, + medEntityMesh Entity=MED_CELL) const; + virtual inline const int * getReverseConnectivityIndex(medConnectivity ConnectivityType, + medEntityMesh Entity=MED_CELL) const; + + virtual int getNumberOfFamilies(medEntityMesh Entity) const; + virtual inline const vector getFamilies(medEntityMesh Entity) const; + virtual inline const FAMILY* getFamily(medEntityMesh Entity,int i) const; + virtual int getNumberOfGroups(medEntityMesh Entity) const; + virtual inline const vector getGroups(medEntityMesh Entity) const; + virtual inline const GROUP* getGroup(medEntityMesh Entity,int i) const; + virtual inline const CONNECTIVITY* getConnectivityptr() const; + virtual SUPPORT * getBoundaryElements(medEntityMesh Entity) + throw (MEDEXCEPTION); + // problème avec le maillage dans le support : + // le pointeur n'est pas const, mais sa valeur oui. A voir !!! PG + + SUPPORT * getSkin(const SUPPORT * Support3D) + throw (MEDEXCEPTION); // Node DonneBarycentre(const Cell &m) const; - FIELD* getVolume(const SUPPORT * Support) const throw (MEDEXCEPTION) ; // Support must be on 3D elements - FIELD* getArea(const SUPPORT * Support) const throw (MEDEXCEPTION) ; // Support must be on 2D elements - FIELD* getLength(const SUPPORT * Support) const throw (MEDEXCEPTION) ; // Support must be on 1D elements - FIELD* getNormal(const SUPPORT * Support) const throw (MEDEXCEPTION) ; // Support must be on 2D elements - FIELD* getBarycenter(const SUPPORT * Support) const throw (MEDEXCEPTION) ; - // FIELD* getNeighbourhood(SUPPORT * Support) const throw (MEDEXCEPTION) ; // Il faut preciser ! + virtual FIELD* getVolume (const SUPPORT * Support) const + throw (MEDEXCEPTION); + // Support must be on 3D elements + virtual FIELD* getArea (const SUPPORT * Support) const + throw (MEDEXCEPTION); + // Support must be on 2D elements + virtual FIELD* getLength (const SUPPORT * Support) const + throw (MEDEXCEPTION); + // Support must be on 1D elements + virtual FIELD* getNormal (const SUPPORT * Support) const + throw (MEDEXCEPTION); + // Support must be on 2D elements + virtual FIELD* getBarycenter (const SUPPORT * Support) const + throw (MEDEXCEPTION); + // FIELD* getNeighbourhood(SUPPORT * Support) const + // throw (MEDEXCEPTION); // Il faut preciser ! + + /*! + return a SUPPORT pointer on the union of all SUPPORTs in Supports. + You should delete this pointer after use to avois memory leaks. + */ + SUPPORT * mergeSupports(const vector Supports) const throw (MEDEXCEPTION) ; + + /*! + return a SUPPORT pointer on the intersection of all SUPPORTs in Supports. + The (SUPPORT *) NULL pointer is returned if the intersection is empty. + You should delete this pointer after use to avois memory leaks. + */ + SUPPORT * intersectSupports(const vector Supports) const throw (MEDEXCEPTION) ; }; // --------------------------------------- @@ -247,6 +271,7 @@ public : inline const CONNECTIVITY* MESH::getConnectivityptr() const { +// checkGridFillConnectivity(); return _connectivity; } @@ -297,7 +322,7 @@ inline void MESH::write(const MED_MED_DRIVER & genDriver) const char * LOC = "MESH::write(const MED_MED_DRIVER & genDriver): "; BEGIN_OF(LOC); - for (int index=0; index < _drivers.size(); index++ ) + for (unsigned int index=0; index < _drivers.size(); index++ ) if ( *_drivers[index] == genDriver ) { _drivers[index]->open(); _drivers[index]->write(); @@ -316,7 +341,7 @@ inline void MESH::read(const MED_MED_DRIVER & genDriver) const char * LOC = "MESH::read(const MED_MED_DRIVER & genDriver): "; BEGIN_OF(LOC); - for (int index=0; index < _drivers.size(); index++ ) + for (unsigned int index=0; index < _drivers.size(); index++ ) if ( *_drivers[index] == genDriver ) { _drivers[index]->open(); _drivers[index]->read(); @@ -331,13 +356,13 @@ inline void MESH::read(const MED_MED_DRIVER & genDriver) /*! Set the MESH name */ inline void MESH::setName(string name) { - _name=name ; //NOM interne à la classe + _name=name; //NOM interne à la classe } /*! Get the MESH name */ inline string MESH::getName() const { - return _name ; + return _name; } /*! Get the dimension of the space */ @@ -361,7 +386,7 @@ inline int MESH::getNumberOfNodes() const /*! Get the COORDINATES object. Use it only if you need COORDINATES informations not provided by the MESH class.*/ inline const COORDINATE * MESH::getCoordinateptr() const { - checkGridFillCoords(); +// checkGridFillCoords(); return _coordinate; } @@ -377,14 +402,14 @@ inline string MESH::getCoordinatesSystem() const */ inline const double * MESH::getCoordinates(medModeSwitch Mode) const { - checkGridFillCoords(); +// checkGridFillCoords(); return _coordinate->getCoordinates(Mode); } /*! Get the coordinate n° number on axis n°axis*/ inline const double MESH::getCoordinate(int number, int axis) const { - checkGridFillCoords(); +// checkGridFillCoords(); return _coordinate->getCoordinate(number,axis); } @@ -410,7 +435,7 @@ inline const string * MESH::getCoordinatesUnits() const /*! Get the number of different geometric types for a given entity type. - For exemple getNumberOfTypes(MED_CELL) would return 3 is the MESH + For exemple getNumberOfTypes(MED_CELL) would return 3 if the MESH have some MED_TETRA4, MED_PYRA5 and MED_HEXA6 in it. medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_NODE, MED_ALL_ENTITIES @@ -423,10 +448,10 @@ inline int MESH::getNumberOfTypes(medEntityMesh entity) const { MESSAGE("MESH::getNumberOfTypes(medEntityMesh entity) : "<getNumberOfTypes(entity) ; + return _connectivity->getNumberOfTypes(entity); throw MEDEXCEPTION(LOCALIZED("MESH::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !")); } @@ -444,9 +469,9 @@ inline const medGeometryElement * MESH::getTypes(medEntityMesh entity) const throw MEDEXCEPTION(LOCALIZED("MESH::getTypes( medEntityMesh ) : No medGeometryElement with MED_NODE entity !")); // return un tableau de taille 1 contenant MED_NONE, comme les supports pour etre coherent avec getNumberOfTypes ???? PG - checkGridFillConnectivity(); +// checkGridFillConnectivity(); if (_connectivity != NULL) - return _connectivity->getGeometricTypes(entity) ; + return _connectivity->getGeometricTypes(entity); throw MEDEXCEPTION(LOCALIZED("MESH::getTypes( medEntityMesh ) : Connectivity not defined !")); } @@ -457,9 +482,9 @@ inline const medGeometryElement * MESH::getTypes(medEntityMesh entity) const */ inline const CELLMODEL * MESH::getCellsTypes(medEntityMesh Entity) const { - checkGridFillConnectivity(); + // checkGridFillConnectivity(); if (_connectivity != NULL) - return _connectivity->getCellsTypes(Entity) ; + return _connectivity->getCellsTypes(Entity); throw MEDEXCEPTION(LOCALIZED("MESH::getCellsTypes( medEntityMesh ) : Connectivity not defined !")); } @@ -475,7 +500,7 @@ inline const CELLMODEL * MESH::getCellsTypes(medEntityMesh Entity) const */ inline const int * MESH::getGlobalNumberingIndex(medEntityMesh entity) const { - checkGridFillConnectivity(); + // checkGridFillConnectivity(); if (_connectivity != NULL) return _connectivity->getGlobalNumberingIndex(entity); throw MEDEXCEPTION(LOCALIZED("MESH::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !")); @@ -493,20 +518,20 @@ inline const int * MESH::getGlobalNumberingIndex(medEntityMesh entity) const */ inline int MESH::getNumberOfElements(medEntityMesh entity, medGeometryElement Type) const { - const char * LOC = "MESH::getNumberOfElements(medEntityMesh,medGeometryElement) : " ; + // const char * LOC = "MESH::getNumberOfElements(medEntityMesh,medGeometryElement) : "; if (entity==MED_NODE) if ((Type==MED_NONE)|(Type==MED_ALL_ELEMENTS)) - return _numberOfNodes ; + return _numberOfNodes; else - return 0 ; + return 0; //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"wrong medGeometryElement with MED_NODE")); else { - checkGridFillConnectivity(); +// checkGridFillConnectivity(); if (_connectivity != (CONNECTIVITY*)NULL) - return _connectivity->getNumberOf(entity,Type) ; + return _connectivity->getNumberOf(entity,Type); else - return 0 ; + return 0; //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"connectivity not defined !")); } } @@ -516,10 +541,10 @@ inline int MESH::getNumberOfElements(medEntityMesh entity, medGeometryElement Ty */ inline bool MESH::existConnectivity(medConnectivity connectivityType, medEntityMesh entity) const { - checkGridFillConnectivity(); +// checkGridFillConnectivity(); if (_connectivity==(CONNECTIVITY*)NULL) throw MEDEXCEPTION("MESH::existConnectivity(medConnectivity,medEntityMesh) : no connectivity defined !"); - return _connectivity->existConnectivity(connectivityType,entity) ; + return _connectivity->existConnectivity(connectivityType,entity); } /*! Return the geometric type of global element Number of entity Entity. @@ -528,21 +553,21 @@ inline bool MESH::existConnectivity(medConnectivity connectivityType, medEntityM */ inline medGeometryElement MESH::getElementType(medEntityMesh Entity,int Number) const { - checkGridFillConnectivity(); + // checkGridFillConnectivity(); if (_connectivity==(CONNECTIVITY*)NULL) throw MEDEXCEPTION("MESH::getElementType(medEntityMesh,int) : no connectivity defined !"); - return _connectivity->getElementType(Entity,Number) ; + return _connectivity->getElementType(Entity,Number); } /*! Calculate the ask connectivity. Return an exception if this could not be done. Do nothing if connectivity already exist. */ -inline void MESH::calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity) +inline void MESH::calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity) const { - checkGridFillConnectivity(); + // checkGridFillConnectivity(); if (Mode==MED_FULL_INTERLACE) - _connectivity->calculateConnectivity(ConnectivityType,entity) ; + _connectivity->calculateConnectivity(ConnectivityType,entity); else throw MEDEXCEPTION(LOCALIZED("MESH::calculateConnectivity : only for MED_FULL_INTERLACE mode")); } @@ -556,9 +581,9 @@ inline void MESH::calculateConnectivity(medModeSwitch Mode,medConnectivity Conne */ inline const int * MESH::getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity, medGeometryElement Type) const { - checkGridFillConnectivity(); + // checkGridFillConnectivity(); if (Mode==MED_FULL_INTERLACE) - return _connectivity->getConnectivity(ConnectivityType,entity,Type) ; + return _connectivity->getConnectivity(ConnectivityType,entity,Type); throw MEDEXCEPTION(LOCALIZED("MESH::getConnectivity : only for MED_FULL_INTERLACE mode")); } /*! @@ -574,8 +599,8 @@ inline const int * MESH::getConnectivity(medModeSwitch Mode,medConnectivity Conn */ inline const int * MESH::getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh entity) const { - checkGridFillConnectivity(); - return _connectivity->getConnectivityIndex(ConnectivityType, entity) ; + // checkGridFillConnectivity(); + return _connectivity->getConnectivityIndex(ConnectivityType, entity); } /*! Return the reverse connectivity required by ConnectivityType : @@ -586,11 +611,11 @@ inline const int * MESH::getConnectivityIndex(medConnectivity ConnectivityType,m */ inline const int * MESH::getReverseConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity/*=MED_CELL*/) const { - checkGridFillConnectivity(); + // checkGridFillConnectivity(); if (NULL==_connectivity) throw MEDEXCEPTION("MESH::getReverseConnectivity : no connectivity defined in MESH !"); - return _connectivity->getReverseConnectivity(ConnectivityType,Entity) ; + return _connectivity->getReverseConnectivity(ConnectivityType,Entity); } /*! Return the index array required by ConnectivityType. @@ -606,11 +631,11 @@ inline const int * MESH::getReverseConnectivity(medConnectivity ConnectivityType */ inline const int * MESH::getReverseConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity/*=MED_CELL*/) const { - checkGridFillConnectivity(); + // checkGridFillConnectivity(); if (NULL==_connectivity) throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : no connectivity defined in MESH !"); - return _connectivity->getReverseConnectivityIndex(ConnectivityType,Entity) ; + return _connectivity->getReverseConnectivityIndex(ConnectivityType,Entity); } @@ -618,13 +643,13 @@ inline int MESH::getNumberOfFamilies (medEntityMesh entity) const { switch (entity) { case MED_NODE : - return _numberOfNodesFamilies ; + return _numberOfNodesFamilies; case MED_CELL : - return _numberOfCellsFamilies ; + return _numberOfCellsFamilies; case MED_FACE : - return _numberOfFacesFamilies ; + return _numberOfFacesFamilies; case MED_EDGE : - return _numberOfEdgesFamilies ; + return _numberOfEdgesFamilies; default : throw MEDEXCEPTION("MESH::getNumberOfFamilies : Unknown entity"); } @@ -633,13 +658,13 @@ inline int MESH::getNumberOfGroups (medEntityMesh entity) const { switch (entity) { case MED_NODE : - return _numberOfNodesGroups ; + return _numberOfNodesGroups; case MED_CELL : - return _numberOfCellsGroups ; + return _numberOfCellsGroups; case MED_FACE : - return _numberOfFacesGroups ; + return _numberOfFacesGroups; case MED_EDGE : - return _numberOfEdgesGroups ; + return _numberOfEdgesGroups; default : throw MEDEXCEPTION("MESH::getNumberOfGroups : Unknown entity"); } @@ -648,13 +673,13 @@ const vector MESH::getFamilies(medEntityMesh entity) const { switch (entity) { case MED_NODE : - return _familyNode ; + return _familyNode; case MED_CELL : - return _familyCell ; + return _familyCell; case MED_FACE : - return _familyFace ; + return _familyFace; case MED_EDGE : - return _familyEdge ; + return _familyEdge; default : throw MEDEXCEPTION("MESH::getFamilies : Unknown entity"); } @@ -664,13 +689,13 @@ const vector MESH::getGroups(medEntityMesh entity) const { switch (entity) { case MED_NODE : - return _groupNode ; + return _groupNode; case MED_CELL : - return _groupCell ; + return _groupCell; case MED_FACE : - return _groupFace ; + return _groupFace; case MED_EDGE : - return _groupEdge ; + return _groupEdge; default : throw MEDEXCEPTION("MESH::getGroups : Unknown entity"); } @@ -680,28 +705,28 @@ const FAMILY* MESH::getFamily(medEntityMesh entity, int i) const { if (i<=0) throw MEDEXCEPTION("MESH::getFamily(i) : argument i must be > 0"); - int NumberOfFamilies = 0 ; - vector Family ; + int NumberOfFamilies = 0; + vector Family; switch (entity) { case MED_NODE : { - NumberOfFamilies = _numberOfNodesFamilies ; - Family = _familyNode ; - break ; + NumberOfFamilies = _numberOfNodesFamilies; + Family = _familyNode; + break; } case MED_CELL : { - NumberOfFamilies = _numberOfCellsFamilies ; - Family = _familyCell ; - break ; + NumberOfFamilies = _numberOfCellsFamilies; + Family = _familyCell; + break; } case MED_FACE : { - NumberOfFamilies = _numberOfFacesFamilies ; - Family = _familyFace ; - break ; + NumberOfFamilies = _numberOfFacesFamilies; + Family = _familyFace; + break; } case MED_EDGE : { - NumberOfFamilies = _numberOfEdgesFamilies ; - Family = _familyEdge ; - break ; + NumberOfFamilies = _numberOfEdgesFamilies; + Family = _familyEdge; + break; } default : throw MEDEXCEPTION("MESH::getFamilies : Unknown entity"); @@ -713,31 +738,31 @@ const FAMILY* MESH::getFamily(medEntityMesh entity, int i) const const GROUP* MESH::getGroup(medEntityMesh entity, int i) const { - const char * LOC = "MESH::getGroup(medEntityMesh entity, int i) : " ; + const char * LOC = "MESH::getGroup(medEntityMesh entity, int i) : "; if (i<=0) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"argument i must be > 0")); - int NumberOfGroups = 0 ; - vector Group ; + int NumberOfGroups = 0; + vector Group; switch (entity) { case MED_NODE : { - NumberOfGroups = _numberOfNodesGroups ; - Group = _groupNode ; - break ; + NumberOfGroups = _numberOfNodesGroups; + Group = _groupNode; + break; } case MED_CELL : { - NumberOfGroups = _numberOfCellsGroups ; - Group = _groupCell ; - break ; + NumberOfGroups = _numberOfCellsGroups; + Group = _groupCell; + break; } case MED_FACE : { - NumberOfGroups = _numberOfFacesGroups ; - Group = _groupFace ; - break ; + NumberOfGroups = _numberOfFacesGroups; + Group = _groupFace; + break; } case MED_EDGE : { - NumberOfGroups = _numberOfEdgesGroups ; - Group = _groupEdge ; - break ; + NumberOfGroups = _numberOfEdgesGroups; + Group = _groupEdge; + break; } default : throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Unknown entity")); @@ -749,7 +774,7 @@ const GROUP* MESH::getGroup(medEntityMesh entity, int i) const // int * get_() { -// return ; +// return ; // } //inline void MESH::write(const string & driverName) { @@ -758,6 +783,8 @@ const GROUP* MESH::getGroup(medEntityMesh entity, int i) const inline bool MESH::getIsAGrid() { + SCRUTE(_isAGrid); + return _isAGrid; } diff --git a/src/MEDMEM/MEDMEM_Meshing.cxx b/src/MEDMEM/MEDMEM_Meshing.cxx index a966be387..2f90a5df3 100644 --- a/src/MEDMEM/MEDMEM_Meshing.cxx +++ b/src/MEDMEM/MEDMEM_Meshing.cxx @@ -1,12 +1,3 @@ -// MED MEDMEM : MED files in memory -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : MEDMEM_Meshing.cxx -// Module : MED - using namespace std; /* File MEDMEM_Meshing.cxx @@ -262,6 +253,10 @@ void MESHING::setConnectivities (const int * ConnectivityIndex, throw (MEDEXCEPTION) { const char * LOC = "MESHING::setConnectivities : " ; + SCRUTE(Entity); + SCRUTE(ConnectivityType); + SCRUTE(ConnectivityValue); + SCRUTE(ConnectivityIndex); throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not Yet Implemented :: Warning !")); } diff --git a/src/MEDMEM/MEDMEM_Meshing.hxx b/src/MEDMEM/MEDMEM_Meshing.hxx index 0b1b955f8..cb68c5466 100644 --- a/src/MEDMEM/MEDMEM_Meshing.hxx +++ b/src/MEDMEM/MEDMEM_Meshing.hxx @@ -1,12 +1,3 @@ -// MED MEDMEM : MED files in memory -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : MEDMEM_Meshing.hxx -// Module : MED - /* File MEDMEM_Meshing.hxx $Header$ diff --git a/src/MEDMEM/MEDMEM_ModulusArray.hxx b/src/MEDMEM/MEDMEM_ModulusArray.hxx index 469d5b78a..956c1d69c 100644 --- a/src/MEDMEM/MEDMEM_ModulusArray.hxx +++ b/src/MEDMEM/MEDMEM_ModulusArray.hxx @@ -1,29 +1,3 @@ -// 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_ModulusArray.hxx -// Module : MED - #ifndef __MEDMODULUSARRAY_H__ #define __MEDMODULUSARRAY_H__ diff --git a/src/MEDMEM/MEDMEM_PointerOf.hxx b/src/MEDMEM/MEDMEM_PointerOf.hxx index cc68738cf..1b7b6ede2 100644 --- a/src/MEDMEM/MEDMEM_PointerOf.hxx +++ b/src/MEDMEM/MEDMEM_PointerOf.hxx @@ -1,29 +1,3 @@ -// 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_PointerOf.hxx -// Module : MED - # if ! defined( __PointerOf_HXX__ ) # define __PointerOf_HXX__ @@ -82,8 +56,8 @@ template PointerOf::PointerOf() : _pointer(0), _done(false) - The "old" PointerOf always has propriety of the pointed memory. \n - If the "old" PointerOf is detroyed, the "new" PointerOf points a desallocated memory zone. */ -template PointerOf::PointerOf(const PointerOf & pointerOf) : _done(false), - _pointer((T*)(const T* const)pointerOf) +template PointerOf::PointerOf(const PointerOf & pointerOf) : + _pointer((T*)(const T* const)pointerOf), _done(false) { BEGIN_OF("PointerOf::PointerOf(const PointerOf & pointerOf)"); MESSAGE("Warning ! No Propriety Transfer"); diff --git a/src/MEDMEM/MEDMEM_STRING.hxx b/src/MEDMEM/MEDMEM_STRING.hxx index be06dc2ab..fde1ee095 100644 --- a/src/MEDMEM/MEDMEM_STRING.hxx +++ b/src/MEDMEM/MEDMEM_STRING.hxx @@ -1,29 +1,3 @@ -// 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_STRING.hxx -// Module : MED - # ifndef MEDMEM_STRING_HXX # define MEDMEM_STRING_HXX diff --git a/src/MEDMEM/MEDMEM_SkyLineArray.cxx b/src/MEDMEM/MEDMEM_SkyLineArray.cxx index f2b2a54b0..13f24e3be 100644 --- a/src/MEDMEM/MEDMEM_SkyLineArray.cxx +++ b/src/MEDMEM/MEDMEM_SkyLineArray.cxx @@ -1,29 +1,3 @@ -// 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_SkyLineArray.cxx -// Module : MED - using namespace std; #include "MEDMEM_SkyLineArray.hxx" #include "utilities.h" diff --git a/src/MEDMEM/MEDMEM_SkyLineArray.hxx b/src/MEDMEM/MEDMEM_SkyLineArray.hxx index 2b979f3a7..5440f6fdf 100644 --- a/src/MEDMEM/MEDMEM_SkyLineArray.hxx +++ b/src/MEDMEM/MEDMEM_SkyLineArray.hxx @@ -1,29 +1,3 @@ -// 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_SkyLineArray.hxx -// Module : MED - # ifndef __MEDSKYLINEARRAY_H__ # define __MEDSKYLINEARRAY_H__ diff --git a/src/MEDMEM/MEDMEM_Support.cxx b/src/MEDMEM/MEDMEM_Support.cxx index 197f8b148..0cdfe0192 100644 --- a/src/MEDMEM/MEDMEM_Support.cxx +++ b/src/MEDMEM/MEDMEM_Support.cxx @@ -1,29 +1,3 @@ -// 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_Support.cxx -// Module : MED - using namespace std; /* File Support.cxx @@ -31,6 +5,7 @@ using namespace std; */ #include +#include #include //#include "utilities.h" @@ -164,10 +139,10 @@ SUPPORT::~SUPPORT() ostream & operator<<(ostream &os, const SUPPORT &my) //-------------------------------------------------- { - os << "Name : "<< my._name << endl ; - os << "Description : "<< my._description << endl ; + os << "Name : "<< my.getName() << endl ; + os << "Description : "<< my.getDescription() << endl ; os << "Mesh name : "; - if (my._mesh==NULL) + if (my.getMesh() == NULL) os << "ERROR : Mesh not defined !" << endl ; else os << my._mesh->getName() << endl ; @@ -178,9 +153,10 @@ ostream & operator<<(ostream &os, const SUPPORT &my) os << "NumberOfTypes : "<getI(j+1); + os << " * Type "<::const_iterator listIt ; int it=0 ; - for(listIt=(MED_FR::meshEntities[(MED_FR::med_entite_maillage)_entity]).begin();listIt!=(MED_FR::meshEntities[(MED_FR::med_entite_maillage)_entity]).end();listIt++){ + for(listIt=(MED_FR::meshEntities[(MED_FR::med_entite_maillage)_entity]).begin();listIt!=(MED_FR::meshEntities[(MED_FR::med_entite_maillage)_entity]).end();listIt++) { tmp_NumberOfElementsInType[it]=0; whereIsType[it]=0 ; try { - tmp_NumberOfElementsInType[it]+=getNumberOfElements((medGeometryElement)(*listIt)) ; + int tmp_int = 0; + tmp_int = getNumberOfElements((medGeometryElement)(*listIt)) ; + tmp_NumberOfElementsInType[it]+=tmp_int ; whereIsType[it]+=1 ; } - catch (const MEDEXCEPTION & ex) {}; + catch (MEDEXCEPTION & ex) { SCRUTE(sizeof(ex)); }; try { - tmp_NumberOfElementsInType[it]+=mySupport->getNumberOfElements((medGeometryElement)(*listIt)) ; + int tmp_int = 0; + tmp_int = mySupport->getNumberOfElements((medGeometryElement)(*listIt)) ; + tmp_NumberOfElementsInType[it]+=tmp_int ; whereIsType[it]+=2 ; } catch (const MEDEXCEPTION & ex) {}; if (whereIsType[it]!=0) { myType[it]=(medGeometryElement)(*listIt) ; + SCRUTE(myType[it]);SCRUTE(it);SCRUTE((*listIt)); it++; } } // set new value : - int * numberOfElements=_numberOfElements ; - _numberOfElements = new int[it] ; +// int * numberOfElements=_numberOfElements ; +// _numberOfElements = new int[it] ; + int * numberOfElements= new int[it]; _totalNumberOfElements = 0 ; //int totalSize = 0 ; int ** tmp_array = new (int*)[it]; for (int i=0;igetNumber(myType[i]),sizeof(int)*numberOfElementsInType); } else if (whereIsType[i] == 3) { // more difficult :-) set elementList ; - int i1 = 0 ; - int i2 = 0 ; + //int i1 = 0 ; !! UNUSED VARIABLE !! + //int i2 = 0 ; !!UNUSED VARIABLE !! int ii = 0 ; const int * number1 = getNumber(myType[i]) ; const int * number2 = mySupport->getNumber(myType[i]) ; @@ -302,24 +284,28 @@ void SUPPORT::blending(SUPPORT * mySupport) SCRUTE(number1); SCRUTE(number2); - int numberOfElements1 = numberOfElements[i] ; + int numberOfElements1 = getNumberOfElements(myType[i]) ; int numberOfElements2 = mySupport->getNumberOfElements(myType[i]) ; SCRUTE(numberOfElements1); SCRUTE(numberOfElements2); + MESSAGE(LOC << " Type : " << myType[i] << " " << i); + for(int j=0;j::iterator its ; @@ -337,6 +323,9 @@ void SUPPORT::blending(SUPPORT * mySupport) } delete[] whereIsType ; delete[] tmp_NumberOfElementsInType ; + delete [] _numberOfElements; + + _numberOfElements = numberOfElements; _numberOfGeometricType = it ; medGeometryElement * geometricType=_geometricType ; @@ -375,7 +364,15 @@ void SUPPORT::blending(SUPPORT * mySupport) delete[] geometricType ; delete[] numberOfGaussPoint ; // delete[] geometricTypeNumber ; - delete[] numberOfElements ; +// delete[] numberOfElements ; + + + + + MESSAGE(LOC<<"Printing of the object SUPPORT blended "<< *this); + + + END_OF(LOC); }; @@ -514,7 +511,7 @@ void SUPPORT::getBoundaryElements() throw (MEDEXCEPTION) } numberOfGeometricType = theType.size() ; geometricType = new medGeometryElement[numberOfGeometricType] ; - const medGeometryElement * allType = _mesh->getTypes(_entity); + //const medGeometryElement * allType = _mesh->getTypes(_entity); !! UNUSED VARIABLE !! numberOfGaussPoint = new int[numberOfGeometricType] ; geometricTypeNumber = new int[numberOfGeometricType] ; // not use, but initialized to nothing numberOfElements = new int[numberOfGeometricType] ; @@ -566,3 +563,162 @@ void SUPPORT::getBoundaryElements() throw (MEDEXCEPTION) END_OF(LOC) ; } + +/*! + intersect the given SUPPORT mySupport into the calling SUPPORT object. +*/ +//------------------- +void SUPPORT::intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION) +//------------------- +{ + const char * LOC = "SUPPORT::intersecting(SUPPORT *) : " ; + BEGIN_OF(LOC) ; + + MESSAGE(LOC<< "SUPPORT entry : " << *mySupport) ; + + MESSAGE(LOC<< "SUPPORT (calling object) : " << *this) ; + + // on same entity : + if ( _entity != mySupport->getEntity() ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !")); + + int * tmp_NumberOfElementsInType = new int[MED_NBR_GEOMETRIE_MAILLE]; + medGeometryElement * myType = new medGeometryElement[MED_NBR_GEOMETRIE_MAILLE]; + int * whereIsType = new int[MED_NBR_GEOMETRIE_MAILLE]; + //MESH_ENTITIES myMeshEntities() ; + list::const_iterator listIt ; + int it=0 ; + for(listIt=(MED_FR::meshEntities[(MED_FR::med_entite_maillage)_entity]).begin();listIt!=(MED_FR::meshEntities[(MED_FR::med_entite_maillage)_entity]).end();listIt++) { + tmp_NumberOfElementsInType[it]=0; + whereIsType[it]=0 ; + myType[it]= MED_NONE; + try { + tmp_NumberOfElementsInType[it]+=getNumberOfElements((medGeometryElement)(*listIt)) ; + whereIsType[it]+=1 ; + } + catch (const MEDEXCEPTION & ex) {}; + try { + tmp_NumberOfElementsInType[it]+=mySupport->getNumberOfElements((medGeometryElement)(*listIt)) ; + whereIsType[it]+=2 ; + } + catch (const MEDEXCEPTION & ex) {}; + if (whereIsType[it]==3) { + myType[it]=(medGeometryElement)(*listIt) ; + it++; + } + } + + MESSAGE("it = "<< it); + + // set new value : + int * numberOfElements=_numberOfElements ; + _numberOfElements = new int[it] ; + _totalNumberOfElements = 0 ; + //int totalSize = 0 ; + int ** tmp_array = new (int*)[it]; + for (int i=0;igetNumber(myType[i]) ; + + SCRUTE(number1); + SCRUTE(number2); + + int numberOfElements1 = numberOfElements[i] ; + int numberOfElements2 = mySupport->getNumberOfElements(myType[i]) ; + + SCRUTE(numberOfElements1); + SCRUTE(numberOfElements2); + + set setList1(number1,number1+numberOfElements1); + set setList2(number2,number2+numberOfElements2); + + for(set::iterator its=setList1.begin();its!=setList1.end(); its++) + { + MESSAGE("Number1 " << *its); + } + + for(set::iterator its=setList2.begin();its!=setList2.end(); its++) + { + MESSAGE("Number2 " << *its); + } + + set setListIntersect; + + set_intersection(setList1.begin(),setList1.end(),setList2.begin(), + setList2.end(),inserter(setListIntersect, + setListIntersect.begin())); + + for(set::iterator its=setListIntersect.begin(); + its!=setListIntersect.end(); its++) + { + MESSAGE("Number1 intersect Number2 " << *its); + } + + int newNumberOfElements = setListIntersect.size() ; + + SCRUTE(newNumberOfElements); + + _numberOfElements[i] = newNumberOfElements ; + int * tmp_arrayNew = new int[newNumberOfElements]; + + int ii = 0 ; + + for(set::iterator its=setListIntersect.begin(); + its!=setListIntersect.end(); its++) { + tmp_arrayNew[ii]=*its ; + SCRUTE(tmp_arrayNew[ii]); + ii++; + } + + delete[] tmp_array[i] ; + tmp_array[i] = tmp_arrayNew ; + _totalNumberOfElements-=(numberOfElementsInType-newNumberOfElements) ; + + } else + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"ERROR")) ; + } + delete[] whereIsType ; + delete[] tmp_NumberOfElementsInType ; + + _numberOfGeometricType = it ; + medGeometryElement * geometricType=_geometricType ; + _geometricType = new medGeometryElement[it] ; + int * numberOfGaussPoint=_numberOfGaussPoint ; + _numberOfGaussPoint= new int[it] ; + + int size = _mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS); + if (_totalNumberOfElements == size) _isOnAllElts = true; + + int * numberValue = new int[_totalNumberOfElements] ; + int * numberIndex = new int[it+1] ; + numberIndex[0]=1; + for (int i=0;i + +#else + +# include +# include +using namespace std; + +/* --- INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */ + +# define HEREWEARE {cout< + +#include "MEDMEM_define.hxx" + +#include "MEDMEM_GenDriver.hxx" +#include "utilities.h" + +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_Unit.hxx" +#include "MEDMEM_Array.hxx" +#include "MEDMEM_Support.hxx" +//#include "MEDMEM_Field.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_CellModel.hxx" + +//using namespace MED_FR ; + +template class FIELD; + +/*! + + Driver Med for FIELD. + + Generic part : implement open and close methods. + +*/ + +template class VTK_FIELD_DRIVER : public GENDRIVER +{ +protected: + + FIELD * _ptrField; + mutable ofstream * _vtkFile ; + string _fieldName; + int _fieldNum; + +public : + + // all MED cell type ?? Classe de Définition ?? + // static const medGeometryElement all_cell_type[MED_NBR_GEOMETRIE_MAILLE]; + + // static const char * const all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]; + + /*! + Constructor. + */ + VTK_FIELD_DRIVER():GENDRIVER(), + _ptrField((FIELD *)MED_NULL), _fieldName(""), + _fieldNum(MED_INVALID) + { + const char * LOC = "VTK_FIELD_DRIVER::VTK_FIELD_DRIVER() "; + BEGIN_OF(LOC); + + _vtkFile = new ofstream(); + + END_OF(LOC); + } + /*! + Constructor. + */ + VTK_FIELD_DRIVER(const string & fileName, FIELD * ptrField) + : GENDRIVER(fileName,MED_WRONLY), + _ptrField((FIELD *) ptrField), + _fieldName(fileName),_fieldNum(MED_INVALID) + { + const char * LOC = "VTK_FIELD_DRIVER::VTK_FIELD_DRIVER(const string & fileName, FIELD * ptrField) "; + BEGIN_OF(LOC); + + _vtkFile = new ofstream(); + + END_OF(LOC); + } + + /*! + Copy constructor. + */ + VTK_FIELD_DRIVER(const VTK_FIELD_DRIVER & fieldDriver): + GENDRIVER(fieldDriver), + _ptrField(fieldDriver._ptrField), + _fieldName(fieldDriver._fieldName), + _fieldNum(fieldDriver._fieldNum) + { + _ptrField->addDriver(*this); + _vtkFile = new ofstream(); + } + + /*! + Destructor. + */ + ~VTK_FIELD_DRIVER() + { + const char * LOC ="VTK_FIELD_DRIVER::~VTK_FIELD_DRIVER()"; + BEGIN_OF(LOC); + + close(); + + SCRUTE(_vtkFile); + + delete _vtkFile ; + + SCRUTE(_vtkFile); + + END_OF(LOC); + } + + void openConst() const throw (MEDEXCEPTION) + { + const char * LOC = "VTK_FIELD_DRIVER::openConst()" ; + BEGIN_OF(LOC); + + MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); + + if ( _fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + if (!(*_vtkFile).is_open()) + (*_vtkFile).open(_fileName.c_str()) ; +// if (*_vtkFile) +// _status = MED_OPENED ; +// else + + + SCRUTE((*_vtkFile).is_open()); + SCRUTE(_vtkFile); + + + + if (!(*_vtkFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file " + << _fileName) + ); + END_OF(LOC); + } + + void openConstAppend() const throw (MEDEXCEPTION) + { + const char * LOC = "VTK_FIELD_DRIVER::openConstAppend()" ; + BEGIN_OF(LOC); + + MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); + + if ( _fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + SCRUTE((*_vtkFile).is_open()); + + if (!(*_vtkFile).is_open()) + { + MESSAGE(LOC<<"The file is already close and it is opened with the right option"); + (*_vtkFile).open(_fileName.c_str(), ofstream::out | ofstream::app) ; + } + else + { + MESSAGE(LOC<<"The file is still open, it is closed to make sure that it will be opened with the right option"); + // closeConst(); + + + (*_vtkFile).close() ; + + _vtkFile->open(_fileName.c_str(), ofstream::out | ofstream::app) ; + } +// if (*_vtkFile) +// _status = MED_OPENED ; +// else + + + SCRUTE((*_vtkFile).is_open()); + SCRUTE(_vtkFile); + + + + if (!(*_vtkFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file " + << _fileName) + ); + END_OF(LOC); + } + + void open() throw (MEDEXCEPTION) + { + openConst() ; + } + + void openAppend() throw (MEDEXCEPTION) + { + openConstAppend() ; + } + + void closeConst() const throw (MEDEXCEPTION) + { + const char * LOC = "VTK_FIELD_DRIVER::closeConst() " ; + BEGIN_OF(LOC); + + SCRUTE(_vtkFile); + SCRUTE(*_vtkFile); + + + if ((*_vtkFile).is_open()) + (*_vtkFile).close(); + +// if (*_vtkFile) +// _status = MED_CLOSED ; +// else + + SCRUTE(_vtkFile); + SCRUTE(*_vtkFile); + + if (!(*_vtkFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close file " + << _fileName) + ); + + END_OF(LOC); + } + + void close() { + closeConst() ; + } + + /*! + Set the name of the FIELD asked in file. + + It could be different than the name of the FIELD object. + */ + void setFieldName(const string & fieldName) ; + + /*! + Get the name of the FIELD asked in file. + */ + string getFieldName() const ; + + /*! + Return a MEDEXCEPTION : it is the write-only driver. + */ + void read ( void ) throw (MEDEXCEPTION) ; + + /*! + Write FIELD in the specified file, with its mesh through its support + which has to be on all entities (excluding the faces in 3d and edges + in 2d). + */ + void write( void ) const throw (MEDEXCEPTION) ; + + /*! + Write FIELD in the specified file, the mesh is supposed to be + written in this file. The field support has to be on all entities + (excluding the faces in 3d and edges in 2d). + */ + void writeAppend( void ) const throw (MEDEXCEPTION); + +private: + GENDRIVER * copy ( void ) const ; + +}; + +/*-------------------------*/ +/* template implementation */ +/*-------------------------*/ + +/*--------------------- DRIVER PART -------------------------------*/ + +template void VTK_FIELD_DRIVER::setFieldName(const string & fieldName) +{ + _fieldName = fieldName; +} + +template string VTK_FIELD_DRIVER::getFieldName() const +{ + return _fieldName; +} + +template GENDRIVER * VTK_FIELD_DRIVER::copy(void) const +{ + VTK_FIELD_DRIVER * myDriver = new VTK_FIELD_DRIVER(*this); + + return myDriver ; +} + +template void VTK_FIELD_DRIVER::read (void) + throw (MEDEXCEPTION) +{ + throw MEDEXCEPTION("VTK_FIELD_DRIVER::read : Can't read with a VTK driver because it is write only driver !"); +} + +template void VTK_FIELD_DRIVER::write(void) const + throw (MEDEXCEPTION) +{ + const char * LOC = "VTK_FIELD_DRIVER::write(void) const " ; + BEGIN_OF(LOC); + + // we get the Support and its associated Mesh + + const SUPPORT * supportField = _ptrField->getSupport(); + MESH * meshField = supportField->getMesh(); + + // Well we must open vtk file first, because there are + // no other driver than MED for VTK that do it ! + openConst() ; + + // could we put more than one Mesh ????? + (*_vtkFile) << "# vtk DataFile Version 2.0" << endl + << "maillage from MedMemory" << endl ; + // only ASCII for the moment (binary came later :-) + (*_vtkFile) << "ASCII" << endl ; + + (*_vtkFile) << "DATASET UNSTRUCTURED_GRID" << endl ; + // put points (all point are in 3D, so if we are in 1D or 2D, we complete by zero ! + int SpaceDimension = meshField->getSpaceDimension() ; + int NumberOfNodes = meshField->getNumberOfNodes() ; + (*_vtkFile) << "POINTS " << NumberOfNodes << " float" << endl ; + const double *coordinate = meshField->getCoordinates(MED_FULL_INTERLACE) ; + for (int i=0;igetNumberOfTypes(MED_CELL) ; + // int * cells_count = meshField->get_cells_count() ; + // int cells_sum = cells_count[cells_types_count] ; + int cells_sum = meshField->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) ; + const CELLMODEL * cells_type = meshField->getCellsTypes(MED_CELL) ; + // int connectivity_sum = 0 ; + + //const int * connectivity = meshField->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS) ; !! UNUSED VARIABLE !! + const int * connectivityIndex = meshField->getConnectivityIndex(MED_NODAL,MED_CELL) ; + + int connectivity_sum = connectivityIndex[cells_sum]-1 ; + + (*_vtkFile) << "CELLS " << cells_sum << " " << connectivity_sum+cells_sum << endl ; + // we put connectivity + for (int i=0;igetNumberOfElements(MED_CELL,cells_type[i].getType()) ; + const int * connectivityArray = meshField->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,cells_type[i].getType()); + for (int j=0;jgetNumberOfElements(MED_CELL,cells_type[i].getType()) ; + for (int j=0;jgetIterationNumber(); + int it = _ptrField->getOrderNumber(); + + ostringstream name ; + string nameField = _ptrField->getName(); + medEntityMesh entitySupport = supportField->getEntity(); + name << nameField << "_" << dt << "_" << it ; + + if (!(supportField->isOnAllElements())) + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which is not on all entities of the mesh !" << entitySupport)); + + if (entitySupport == MED_NODE) + (*_vtkFile) << "POINT_DATA " << meshField->getNumberOfNodes() << endl ; + else if (entitySupport == MED_CELL) + (*_vtkFile) << "CELL_DATA " << meshField->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) << endl ; + else + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which is not on all nodes or cells but it's on !" << entitySupport)); + + int NomberOfValue = supportField->getNumberOfElements(MED_ALL_ELEMENTS) ; + int NomberOfComponents = _ptrField->getNumberOfComponents() ; + + med_type_champ fieldType = _ptrField->getValueType() ; + + SCRUTE(name.str()); + SCRUTE(fieldType); + + switch (fieldType) + { + case MED_INT32 : { + MESSAGE("MED_INT32"); + if (NomberOfComponents==3) + (*_vtkFile) << "VECTORS " << name.str() << " int" << endl ; + else if (NomberOfComponents<=4) + { + (*_vtkFile) << "SCALARS " << name.str() << " int " << NomberOfComponents << endl ; + (*_vtkFile) << "LOOKUP_TABLE default" << endl ; + } + else + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" there are more than 4 components !")); + + //const int * value = ((FIELD*)myField)->getValue(MED_NO_INTERLACE) ; + const int * value = ((FIELD*)_ptrField)->getValue(MED_NO_INTERLACE) ; + for (int i=0; igetName()<<" there are more than 4 components !")); + + const double * value = ((FIELD*)_ptrField)->getValue(MED_NO_INTERLACE) ; + for (int i=0; i void VTK_FIELD_DRIVER::writeAppend(void) const + throw (MEDEXCEPTION) +{ + const char * LOC = "VTK_FIELD_DRIVER::writeAppend(void) const " ; + BEGIN_OF(LOC); + + // we get the Support and its associated Mesh + + const SUPPORT * supportField = _ptrField->getSupport(); + MESH * meshField = supportField->getMesh(); + + // Well we must open vtk file first, because there are + // no other driver than MED for VTK that do it ! + openConstAppend() ; + + // first : field on node + // fields is on all node ! + + // second : field on cell + // fields is on all cell ! + + int dt = _ptrField->getIterationNumber(); + int it = _ptrField->getOrderNumber(); + + ostringstream name ; + string nameField = _ptrField->getName(); + medEntityMesh entitySupport = supportField->getEntity(); + name << nameField << "_" << dt << "_" << it ; + + if (!(supportField->isOnAllElements())) + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which is not on all entities of the mesh !" << entitySupport)); + + if (entitySupport == MED_NODE) + (*_vtkFile) << "POINT_DATA " << meshField->getNumberOfNodes() << endl ; + else if (entitySupport == MED_CELL) + (*_vtkFile) << "CELL_DATA " << meshField->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) << endl ; + else + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which is not on all nodes or cells but it's on !" << entitySupport)); + + int NomberOfValue = supportField->getNumberOfElements(MED_ALL_ELEMENTS) ; + int NomberOfComponents = _ptrField->getNumberOfComponents() ; + + med_type_champ fieldType = _ptrField->getValueType() ; + + SCRUTE(name.str()); + SCRUTE(fieldType); + + switch (fieldType) + { + case MED_INT32 : { + MESSAGE("MED_INT32"); + if (NomberOfComponents==3) + (*_vtkFile) << "VECTORS " << name.str() << " int" << endl ; + else if (NomberOfComponents<=4) + { + (*_vtkFile) << "SCALARS " << name.str() << " int " << NomberOfComponents << endl ; + (*_vtkFile) << "LOOKUP_TABLE default" << endl ; + } + else + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" there are more than 4 components !")); + + //const int * value = ((FIELD*)myField)->getValue(MED_NO_INTERLACE) ; + const int * value = ((FIELD*)_ptrField)->getValue(MED_NO_INTERLACE) ; + for (int i=0; igetName()<<" there are more than 4 components !")); + + const double * value = ((FIELD*)_ptrField)->getValue(MED_NO_INTERLACE) ; + for (int i=0; igetNumberOfMeshes() ; deque MeshNames = _ptrMed->getMeshNames() ; - deque::const_iterator currentMesh ; + //deque::const_iterator currentMesh ; !! UNUSED VARIABLE !! // In fact, we must take care of all supports // We restrict Field on all nodes or cells int NumberOfFields = _ptrMed->getNumberOfFields() ; deque FieldNames = _ptrMed->getFieldNames() ; - deque::const_iterator currentField ; + //deque::const_iterator currentField ; !! UNUSED VARIABLE !! // for ( currentMesh=MeshName.begin();currentMesh != MeshName.end(); currentMesh++) { for (int i=0; igetName() << "_" << dt << "_" << it ; writeField(myField,name.str()) ; } else - INFOS("Could not write field "<getName()<<" which is not on all nodes !"); + MESSAGE(LOC << "Could not write field "<getName()<<" which is not on all nodes !"); } } } @@ -196,7 +175,7 @@ void VTK_MED_DRIVER::write() const { name << myField->getName() << "_" << dt << "_" << it ; writeField(myField,name.str()) ; } else - INFOS("Could not write field "<getName()<<" which is not on all cells !"); + MESSAGE(LOC << "Could not write field "<getName()<<" which is not on all cells !"); } } } @@ -205,7 +184,7 @@ void VTK_MED_DRIVER::write() const { // Well we must close vtk file first, because there are // no other driver than MED for VTK that do it ! - closeConst() ; + // closeConst() ; END_OF(LOC); } @@ -240,7 +219,7 @@ void VTK_MED_DRIVER::writeMesh(MESH * myMesh) const { const CELLMODEL * cells_type = myMesh->getCellsTypes(MED_CELL) ; // int connectivity_sum = 0 ; - const int * connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS) ; + //const int * connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS) ; !! UNUSED VARIABLE !! const int * connectivityIndex = myMesh->getConnectivityIndex(MED_NODAL,MED_CELL) ; int connectivity_sum = connectivityIndex[cells_sum]-1 ; @@ -468,7 +447,7 @@ void VTK_MED_DRIVER::writeField(FIELD_ * myField,string name) const { (*_vtkFile) << "SCALARS " << name << " int " << NomberOfComponents << endl ; (*_vtkFile) << "LOOKUP_TABLE default" << endl ; } else { - INFOS("Could not write field "<getName()<<" there are more than 4 components !"); + MESSAGE(LOC << "Could not write field "<getName()<<" there are more than 4 components !"); return ; } @@ -489,7 +468,7 @@ void VTK_MED_DRIVER::writeField(FIELD_ * myField,string name) const { (*_vtkFile) << "SCALARS " << name << " float " << NomberOfComponents << endl ; (*_vtkFile) << "LOOKUP_TABLE default" << endl ; } else { - INFOS("Could not write field "<getName()<<" there are more than 4 components !"); + MESSAGE(LOC << "Could not write field "<getName()<<" there are more than 4 components !"); return ; } const double * value = ((FIELD*)myField)->getValue(MED_NO_INTERLACE) ; @@ -501,7 +480,7 @@ void VTK_MED_DRIVER::writeField(FIELD_ * myField,string name) const { break ; } default : { - INFOS("Could not write field "< + +VTK_MESH_DRIVER::VTK_MESH_DRIVER(): GENDRIVER(), + _ptrMesh((MESH * const)MED_NULL) +{ + _vtkFile = new ofstream(); + // What about _id in Gendriver ? + // _driverType ??? +} + +VTK_MESH_DRIVER::VTK_MESH_DRIVER(const string & fileName, + MESH * ptrMesh) : + GENDRIVER(fileName,MED_WRONLY), + _ptrMesh(ptrMesh) +{ + const char * LOC = "VTK_MESH_DRIVER::VTK_MESH_DRIVER(const string & fileName, MESH * ptrMesh) : " ; + + // Send an exception because a VTK_MESH_DRIVER object cannot be instantied + // from a file and there is no read for that kind of driver + + // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "This driver is only used to write in VTK format So thie object can not be instantied using a file!")); + + // _ptrMesh->addDriver(*this); // OU RECUPERER L'ID. + MESSAGE(LOC << "WARNING this driver is only used to write in VTK format So the object can not be instantied using a file!"); + + _vtkFile = new ofstream(); +} + +VTK_MESH_DRIVER::VTK_MESH_DRIVER(const VTK_MESH_DRIVER & driver): + GENDRIVER(driver), + _ptrMesh(driver._ptrMesh), + _meshName(driver._meshName) +{ + _ptrMesh->addDriver(*this); + _vtkFile = new ofstream(); +} + +VTK_MESH_DRIVER::~VTK_MESH_DRIVER() +{ + const char * LOC ="VTK_MESH_DRIVER::~VTK_MESH_DRIVER()"; + BEGIN_OF(LOC); + + close(); + + SCRUTE(_vtkFile); + + delete _vtkFile ; + + SCRUTE(_vtkFile); + + END_OF(LOC); +} + +void VTK_MESH_DRIVER::openConst() const throw (MEDEXCEPTION) +{ + const char * LOC = "VTK_MESH_DRIVER::openConst()" ; + BEGIN_OF(LOC); + + MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); + + if ( _fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + if (!(*_vtkFile).is_open()) + (*_vtkFile).open(_fileName.c_str()) ; +// if (*_vtkFile) +// _status = MED_OPENED ; +// else + + + SCRUTE((*_vtkFile).is_open()); + SCRUTE(_vtkFile); + + + + if (!(*_vtkFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file " + << _fileName) + ); + END_OF(LOC); +} + +void VTK_MESH_DRIVER::open() { + openConst() ; +} + +void VTK_MESH_DRIVER::closeConst() const throw (MEDEXCEPTION) +{ + const char * LOC = "VTK_MESH_DRIVER::closeConst() " ; + BEGIN_OF(LOC); + + SCRUTE(_vtkFile); + SCRUTE(*_vtkFile); + + + if ((*_vtkFile).is_open()) + (*_vtkFile).close(); + +// if (*_vtkFile) +// _status = MED_CLOSED ; +// else + + SCRUTE(_vtkFile); + SCRUTE(*_vtkFile); + + if (!(*_vtkFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close file " + << _fileName) + ); + + END_OF(LOC); +} + +void VTK_MESH_DRIVER::close() { + closeConst() ; +} + +void VTK_MESH_DRIVER::setMeshName(const string & meshName) { _meshName = meshName; }; +string VTK_MESH_DRIVER::getMeshName() const { return _meshName; }; + +void VTK_MESH_DRIVER::read(void) throw (MEDEXCEPTION) +{ + const char * LOC = "VTK_MESH_DRIVER::read() : " ; + BEGIN_OF(LOC); + + // Send an exception + + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "This driver is only used to write in VTK format !")); + + END_OF(LOC); +} + + +void VTK_MESH_DRIVER::write(void) const + throw (MEDEXCEPTION) +{ + const char * LOC = "void VTK_MESH_DRIVER::write(void) const : "; + BEGIN_OF(LOC); + + // Well we must open vtk file first, because there are + // no other driver than MED for VTK that do it ! + + openConst(); + + (*_vtkFile) << "# vtk DataFile Version 2.0" << endl + << "maillage from MedMemory" << endl ; + // only ASCII for the moment (binary came later :-) + (*_vtkFile) << "ASCII" << endl ; + + + (*_vtkFile) << "DATASET UNSTRUCTURED_GRID" << endl ; + // put points (all point are in 3D, so if we are in 1D or 2D, we complete by zero ! + int SpaceDimension = _ptrMesh->getSpaceDimension() ; + int NumberOfNodes = _ptrMesh->getNumberOfNodes() ; + (*_vtkFile) << "POINTS " << NumberOfNodes << " float" << endl ; + const double *coordinate = _ptrMesh->getCoordinates(MED_FULL_INTERLACE) ; + for (int i=0;igetNumberOfTypes(MED_CELL) ; + // int * cells_count = _ptrMesh->get_cells_count() ; + // int cells_sum = cells_count[cells_types_count] ; + int cells_sum = _ptrMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) ; + const CELLMODEL * cells_type = _ptrMesh->getCellsTypes(MED_CELL) ; + // int connectivity_sum = 0 ; + + //const int * connectivity = _ptrMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS) ; !! UNUSED VARIABLE !! + const int * connectivityIndex = _ptrMesh->getConnectivityIndex(MED_NODAL,MED_CELL) ; + + int connectivity_sum = connectivityIndex[cells_sum]-1 ; + + (*_vtkFile) << "CELLS " << cells_sum << " " << connectivity_sum+cells_sum << endl ; + // we put connectivity + for (int i=0;igetNumberOfElements(MED_CELL,cells_type[i].getType()) ; + const int * connectivityArray = _ptrMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,cells_type[i].getType()); + for (int j=0;jgetNumberOfElements(MED_CELL,cells_type[i].getType()) ; + for (int j=0;j +#include +#include "MEDMEM_define.hxx" +#include "MEDMEM_GenDriver.hxx" + +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Exception.hxx" +#include "utilities.h" + +#include + +class MESH; +class FAMILY; +class GROUP; +class CONNECTIVITY; + +/*! + + Driver Vtk for MESH (only for writing). + + Generic part : implement open and close methods. + +*/ +class VTK_MESH_DRIVER : public GENDRIVER +{ +protected: + + MESH * _ptrMesh; + ofstream * _vtkFile ; // The _vtkFile used to write Meshes and Fields to _filename + string _meshName; + +public : + + /*! + Constructor. + */ + VTK_MESH_DRIVER() ; + /*! + Constructor. + */ + VTK_MESH_DRIVER(const string & fileName, MESH * ptrMesh) ; + /*! + Copy constructor. + */ + VTK_MESH_DRIVER(const VTK_MESH_DRIVER & driver) ; + + /*! + Destructor. + */ + ~VTK_MESH_DRIVER() ; + + void open() ; + void close() ; + + void openConst() const throw (MEDEXCEPTION); + void closeConst() const throw (MEDEXCEPTION); + + void write( void ) const throw (MEDEXCEPTION) ; + void read ( void ) throw (MEDEXCEPTION) ; + + /*! + Set the name of the MESH asked in file. + + It could be different than the name of the MESH object. + */ + void setMeshName(const string & meshName) ; + /*! + Get the name of the MESH asked in file. + */ + string getMeshName() const ; + +private: + GENDRIVER * copy ( void ) const; + +}; + +#endif /* VTK_MESH_DRIVER_HXX */ diff --git a/src/MEDMEM/MEDMEM_define.hxx b/src/MEDMEM/MEDMEM_define.hxx index 92d578b0f..bbc2be345 100644 --- a/src/MEDMEM/MEDMEM_define.hxx +++ b/src/MEDMEM/MEDMEM_define.hxx @@ -1,29 +1,3 @@ -// 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_define.hxx -// Module : MED - #ifndef DEFINE_HXX #define DEFINE_HXX @@ -55,29 +29,52 @@ namespace MED_EN { #define MED_TAILLE_LNOM 80 #define MED_TAILLE_PNOM 8 -typedef enum {MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED} med_grid_type; - -typedef enum {MED_FULL_INTERLACE, - MED_NO_INTERLACE} medModeSwitch; - -typedef enum {MED_LECT,MED_ECRI,MED_REMP} med_mode_acces; -typedef enum {MED_CELL, MED_FACE, MED_EDGE, MED_NODE, MED_ALL_ENTITIES} medEntityMesh; - -typedef enum {MED_COOR, MED_CONN, MED_NOM, MED_NUM, MED_FAM} med_table; - -typedef enum {MED_REEL64=6, MED_INT32=24,MED_INT64=26, MED_INT} med_type_champ; + typedef long medGeometryElement; + const medGeometryElement MED_NONE = 0; + const medGeometryElement MED_POINT1 = 1; + const medGeometryElement MED_SEG2 = 102; + const medGeometryElement MED_SEG3 = 103; + const medGeometryElement MED_TRIA3 = 203; + const medGeometryElement MED_QUAD4 = 204; + const medGeometryElement MED_TRIA6 = 206; + const medGeometryElement MED_QUAD8 = 208; + const medGeometryElement MED_TETRA4 = 304; + const medGeometryElement MED_PYRA5 = 305; + const medGeometryElement MED_PENTA6 = 306; + const medGeometryElement MED_HEXA8 = 308; + const medGeometryElement MED_TETRA10 = 310; + const medGeometryElement MED_PYRA13 = 313; + const medGeometryElement MED_PENTA15 = 315; + const medGeometryElement MED_HEXA20 = 320; + const medGeometryElement MED_ALL_ELEMENTS = 999; + + typedef long medEntityMesh; + const medEntityMesh MED_CELL = 0; + const medEntityMesh MED_FACE = 1; + const medEntityMesh MED_EDGE = 2; + const medEntityMesh MED_NODE = 3; + const medEntityMesh MED_ALL_ENTITIES = 4; + + typedef long medModeSwitch; + const medModeSwitch MED_FULL_INTERLACE = 0; + const medModeSwitch MED_NO_INTERLACE = 1; + + typedef long medConnectivity; + const medConnectivity MED_NODAL = 0; + const medConnectivity MED_DESCENDING = 1; + + typedef enum {MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED} med_grid_type; + + typedef enum {MED_LECT,MED_ECRI,MED_REMP} med_mode_acces; + + typedef enum {MED_COOR, MED_CONN, MED_NOM, MED_NUM, MED_FAM} med_table; + + typedef enum {MED_REEL64=6, MED_INT32=24,MED_INT64=26, MED_INT} med_type_champ; #define MED_NBR_GEOMETRIE_MAILLE 15 #define MED_NBR_GEOMETRIE_FACE 4 #define MED_NBR_GEOMETRIE_ARETE 2 -typedef enum {MED_NONE=0, MED_POINT1=1, MED_SEG2=102, MED_SEG3=103, MED_TRIA3=203, - MED_QUAD4=204, MED_TRIA6=206,MED_QUAD8=208, MED_TETRA4=304, - MED_PYRA5=305, MED_PENTA6=306, MED_HEXA8=308, MED_TETRA10=310, - MED_PYRA13=313, MED_PENTA15=315, MED_HEXA20=320, MED_ALL_ELEMENTS=999} -medGeometryElement; - -typedef enum {MED_NODAL, MED_DESCENDING} medConnectivity ; typedef enum {MED_CART, MED_CYL, MED_SPHER} med_repere; diff --git a/src/MEDMEM/Makefile.in b/src/MEDMEM/Makefile.in index f1000048e..99295e104 100644 --- a/src/MEDMEM/Makefile.in +++ b/src/MEDMEM/Makefile.in @@ -56,9 +56,12 @@ MEDMEM_Med.hxx \ MEDMEM_MedMedDriver.hxx \ MEDMEM_MedMeshDriver.hxx \ MEDMEM_GibiMeshDriver.hxx \ +MEDMEM_DriverTools.hxx \ MEDMEM_ModulusArray.hxx \ MEDMEM_SkyLineArray.hxx \ MEDMEM_VtkMedDriver.hxx \ +MEDMEM_VtkMeshDriver.hxx \ +MEDMEM_VtkFieldDriver.hxx \ MEDMEM_Mesh.hxx \ MEDMEM_Meshing.hxx \ MEDMEM_STRING.hxx \ @@ -84,12 +87,14 @@ MEDMEM_Exception.cxx \ MEDMEM_MedMedDriver.cxx \ MEDMEM_MedMeshDriver.cxx \ MEDMEM_GibiMeshDriver.cxx \ +MEDMEM_DriverTools.cxx \ MEDMEM_SkyLineArray.cxx \ MEDMEM_Mesh.cxx \ MEDMEM_Meshing.cxx \ MEDMEM_Support.cxx \ MEDMEM_Unit.cxx \ MEDMEM_VtkMedDriver.cxx \ +MEDMEM_VtkMeshDriver.cxx \ MEDMEM_Grid.cxx @@ -99,7 +104,7 @@ BIN_SRC = BIN_SERVER_IDL = BIN_CLIENT_IDL = -TEST_PROGS = test_MEDMEM_ModulusArray test_MEDMEM_Array test_MEDMEM_SkyLineArray test_MEDMEM_CellModel testUPointerOf testUCoordinate testUUnit testUGeoNameMeshEntities testUMedException testUModulusArray testUSkyLineArray testUArray testUCellModel readEntete readCoordinate test_copie_field_ test_copie_fieldT test_copie_coordinate test_copie_medarray test_copie_connectivity test_copie_support test_copie_family test_copie_group test_copie_mesh test_affect_medarray test_MEDMEM_Meshing +TEST_PROGS = test_MEDMEM_ModulusArray test_MEDMEM_Array test_MEDMEM_SkyLineArray test_MEDMEM_CellModel testUPointerOf testUCoordinate testUUnit testUGeoNameMeshEntities testUMedException testUModulusArray testUSkyLineArray testUArray testUCellModel readEntete readCoordinate test_copie_field_ test_copie_fieldT test_copie_coordinate test_copie_medarray test_copie_connectivity test_copie_support test_copie_family test_copie_group test_copie_mesh test_affect_medarray test_MEDMEM_Meshing test_operation_fielddouble test_operation_fieldint test_gibi_driver # testUCellModel -> a revoir car l'API a changee (plus de vector) @@ -108,9 +113,9 @@ CXXFLAGS+=-ftemplate-depth-42 -I${KERNEL_ROOT_DIR}/include/salome LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -lSalomeLoggerServer -L${KERNEL_ROOT_DIR}/lib/salome # build create_mesh : -bin: create_mesh create_mesh_c2q4s2 create_mesh_c3h8q4 create_mesh_c3h8q4_wrong create_mesh_c2q4s2_wrong create_grid +bin: create_mesh create_mesh_c2q4s2 create_mesh_c3h8q4 create_mesh_c3h8q4_wrong create_mesh_c2q4s2_wrong create_grid create_mesh_c2q4 create_mesh_c3h8 -create_mesh create_mesh_c2q4s2 create_mesh_c3h8q4 create_grid: %: %.c +create_mesh create_mesh_c2q4s2 create_mesh_c3h8q4 create_grid create_mesh_c2q4 create_mesh_c3h8: %: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(MED2_LIBS) $(HDF5_LIBS) $(LDFLAGS) $< @CONCLUDE@ diff --git a/src/MEDMEM/create_mesh.c b/src/MEDMEM/create_mesh.c index 8e0446897..2dbedc1e1 100644 --- a/src/MEDMEM/create_mesh.c +++ b/src/MEDMEM/create_mesh.c @@ -1,31 +1,3 @@ -/*---------------------------------------------------------------------------- -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 : create_mesh.c -Module : MED -----------------------------------------------------------------------------*/ - #include #include diff --git a/src/MEDMEM/create_mesh_c2q4.c b/src/MEDMEM/create_mesh_c2q4.c new file mode 100644 index 000000000..2d85f4cab --- /dev/null +++ b/src/MEDMEM/create_mesh_c2q4.c @@ -0,0 +1,226 @@ +/* + creation d'une geometrie 2d : un cube [0,1]^2 + maillé uniformement en quadrangle reguliers; + avec en plus une partie des aretes (une partie + des arretes de la frontiere) du maillage. + ATTENTION : 3 noeuds dans chaque direction +*/ + +#include +#include + +int main (int argc, char **argv) +{ + med_err ret; + med_idt fid; + char maa[MED_TAILLE_NOM+1] = "carre_en_quad4"; + med_int mdim = 2; + med_int nnoe = 9; + /* + les noeuds: + */ + med_float coo[18] = { + 0.0, 0.0, + 0.5, 0.0, + 1.0, 0.0, + 0.0, 0.5, + 0.5, 0.5, + 1.0, 0.5, + 0.0, 1.0, + 0.5, 1.0, + 1.0, 1.0 + }; + char nomcoo[2*MED_TAILLE_PNOM+1] = "x y "; + char unicoo[2*MED_TAILLE_PNOM+1] = "cm cm "; + /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/ + char *nomnoe ; + med_int numnoe[9] = {1,2,3,4,5,6,7,8,9}; + med_int nufano[9] = {0,0,0,0,0,0,0,0,0}; + /* + les elements: + */ + med_int nquad4 = 4; + med_int quad4[16] = { + 4, 5, 2, 1, + 5, 6, 3, 2, + 7, 8, 5, 4, + 8, 9, 6, 5 + }; + char nomquad4[MED_TAILLE_PNOM*4+1] = "quad1 quad2 quad3 quad4 "; + med_int numquad4[4] = {1,2,3,4}; + med_int nufaquad4[4] = {-1,-1,0,0}; + + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + char attdes[MED_TAILLE_DESC+1]; + med_int natt; + med_int attide; + med_int attval; + med_int ngro; + char gro[MED_TAILLE_LNOM+1]; + int i; + int nfame = 1; + int nfamn = 1; + + /* + Some fields : 2 on nodes : one int and one double , one on cells : double + */ + char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ; + char champ1_comp[MED_TAILLE_PNOM+1]="comp1 " ; + char champ1_unit[MED_TAILLE_PNOM+1]="M " ; + med_int fieldnodeint[9] = {1,1,3,2,2,3,4,4,5}; + + char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ; + char champ2_comp[MED_TAILLE_PNOM+1]="comp1 " ; + char champ2_unit[MED_TAILLE_PNOM+1]="J " ; + med_float fieldnodedouble1[9] = {1.,3.,4.,1.,3.,4.,3.,2.,5.}; + med_float fieldnodedouble2[9] = {1.,2.,2.,3.,3.,3.,4.,4.,5.}; + + char champ3[MED_TAILLE_NOM+1]="fieldcelldouble" ; + char champ3_comp[MED_TAILLE_PNOM*2+1]="comp1 comp2 " ; + char champ3_unit[MED_TAILLE_PNOM*2+1]="M/S m/s " ; + med_float fieldcelldouble[4*2] = {0.,1.,1.,1.,1.,2.,2.,3.}; + + /***************************************************************************/ + fid = MEDouvrir("carre_en_quad4.med",MED_REMP); + if (fid < 0) + ret = -1; + else + ret = 0; + printf("%d\n",ret); + + /***************************************************************************/ + if (ret == 0) + ret = MEDmaaCr(fid,maa,mdim); + printf("%d\n",ret); + if (ret == 0) + ret = MEDunvCr(fid,maa); + printf("%d\n",ret); + + /***************************************************************************/ + if (ret == 0) + ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART, + nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI, + nufano,nnoe,MED_ECRI); + printf("%d\n",ret); + + /* ecriture des mailles MED_QUAD4 : + - connectivite + - noms (optionnel) + - numeros (optionnel) + - numeros des familles */ + if (ret == 0) + ret = MEDelementsEcr(fid,maa,mdim,quad4,MED_FULL_INTERLACE, + nomquad4,MED_FAUX,numquad4,MED_VRAI,nufaquad4,nquad4, + MED_MAILLE,MED_QUAD4,MED_NOD,MED_ECRI); + printf("%d \n",ret); + + /***************************************************************************/ + /* ecriture des familles */ + /* Conventions : + - toujours creer une famille de numero 0 ne comportant aucun attribut + ni groupe (famille de reference pour les noeuds ou les elements + qui ne sont rattaches a aucun groupe ni attribut) + - les numeros de familles de noeuds sont > 0 + - les numeros de familles des elements sont < 0 + - rien d'imposer sur les noms de familles + */ + + /* la famille 0 */ + if (ret == 0) + { + strcpy(nomfam,"FAMILLE_0"); + numfam = 0; + ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0, + gro,0); + } + printf("%d \n",ret); + + /* on cree : + - 1 familles d'elements de dimension (d) + en fait de face (-10) + */ + + if (ret == 0) + { + numfam = -1; + strcpy(nomfam,"FAMILLE_CELL_"); + sprintf(nomfam,"%s%d",nomfam,-numfam); + attide = 1; + attval = numfam*100; + natt = 1; + strcpy(attdes,"description attribut"); + strcpy(gro,"groupe0"); + ngro = 1; + + ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes, + natt,gro,ngro); + printf("MEDfamCr : %d\n",ret); + } + /***************************************************************************/ + /* + Les champs + */ + if (ret == 0) + { + ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1); + printf("MEDchampCr : %d \n",ret); + if (ret == 0) { + ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint, + MED_NO_INTERLACE, nnoe, + MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, + 0, MED_NOPDT," ", 0., MED_NONOR); + + printf("MEDchampEcr : %d \n",ret); + } + } + + if (ret == 0) + { + ret = MEDchampCr(fid,champ2,MED_REEL64,champ2_comp,champ2_unit,1); + printf("MEDchampCr : %d \n",ret); + if (ret == 0) { + ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1, + MED_NO_INTERLACE, nnoe, + MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, + 0, 1,"S ", 1.1 , MED_NONOR); + printf("MEDchampEcr1 : %d \n",ret); + ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2, + MED_NO_INTERLACE, nnoe, + MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, + 0, 2,"S ", 1.2 , MED_NONOR); + printf("MEDchampEcr2 : %d \n",ret); + } + } + + // on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut ! + if (ret == 0) + { + ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1, + MED_NO_INTERLACE, nnoe, + MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, + 0, MED_NOPDT," ", 0. , MED_NONOR); + printf("MEDchampEcr : %d \n",ret); + } + + if (ret == 0) + { + ret = MEDchampCr(fid,champ3,MED_REEL64,champ3_comp,champ3_unit,2); + printf("MEDchampCr : %d \n",ret); + if (ret == 0) { + ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble, + MED_NO_INTERLACE, nquad4, + MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE, + MED_QUAD4, MED_NOPDT," ", 0., MED_NONOR); + printf("MEDchampEcr : %d \n",ret); + } + } + + /***************************************************************************/ + + ret = MEDfermer(fid); + printf("%d\n",ret); + + return 0; +} + diff --git a/src/MEDMEM/create_mesh_c2q4s2.c b/src/MEDMEM/create_mesh_c2q4s2.c index ceb89f4bb..3896ae7e2 100644 --- a/src/MEDMEM/create_mesh_c2q4s2.c +++ b/src/MEDMEM/create_mesh_c2q4s2.c @@ -1,31 +1,3 @@ -/*---------------------------------------------------------------------------- -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 : create_mesh_c2q4s2.c -Module : MED -----------------------------------------------------------------------------*/ - /* creation d'une geometrie 2d : un cube [0,1]^2 maillé uniformement en quadrangle reguliers; diff --git a/src/MEDMEM/create_mesh_c2q4s2_wrong.c b/src/MEDMEM/create_mesh_c2q4s2_wrong.c index 07dcf2a01..a4d020de7 100644 --- a/src/MEDMEM/create_mesh_c2q4s2_wrong.c +++ b/src/MEDMEM/create_mesh_c2q4s2_wrong.c @@ -1,31 +1,3 @@ -/*---------------------------------------------------------------------------- -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 : create_mesh_c2q4s2_wrong.c -Module : MED -----------------------------------------------------------------------------*/ - /* creation d'une geometrie 2d : un cube [0,1]^2 maillé uniformement en quadrangle reguliers; diff --git a/src/MEDMEM/create_mesh_c3h8.c b/src/MEDMEM/create_mesh_c3h8.c new file mode 100644 index 000000000..1153597da --- /dev/null +++ b/src/MEDMEM/create_mesh_c3h8.c @@ -0,0 +1,283 @@ +/* + creation d'une geometrie 3d : un cube [0,1]^3 + maillé uniformement en hexahedres reguliers; + avec en plus une partie des faces (une partie + des faces de la frontiere) du maillage. + ATTENTION : 3 noeuds dans chaque direction +*/ + +#include +#include + +int main (int argc, char **argv) +{ + med_err ret; + med_idt fid; + char maa[MED_TAILLE_NOM+1] = "CUBE_EN_HEXA8"; + med_int mdim = 3; + med_int nnoe = 27; + /* + les noeuds: + */ + med_float coo[81] = { + 0.0, 0.0, 0.0, + 0.5, 0.0, 0.0, + 1.0, 0.0, 0.0, + 0.0, 0.5, 0.0, + 0.5, 0.5, 0.0, + 1.0, 0.5, 0.0, + 0.0, 1.0, 0.0, + 0.5, 1.0, 0.0, + 1.0, 1.0, 0.0, + 0.0, 0.0, 0.5, + 0.5, 0.0, 0.5, + 1.0, 0.0, 0.5, + 0.0, 0.5, 0.5, + 0.5, 0.5, 0.5, + 1.0, 0.5, 0.5, + 0.0, 1.0, 0.5, + 0.5, 1.0, 0.5, + 1.0, 1.0, 0.5, + 0.0, 0.0, 1.0, + 0.5, 0.0, 1.0, + 1.0, 0.0, 1.0, + 0.0, 0.5, 1.0, + 0.5, 0.5, 1.0, + 1.0, 0.5, 1.0, + 0.0, 1.0, 1.0, + 0.5, 1.0, 1.0, + 1.0, 1.0, 1.0 + }; + char nomcoo[3*MED_TAILLE_PNOM+1] = "x y z "; + char unicoo[3*MED_TAILLE_PNOM+1] = "cm cm cm "; + /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/ + char *nomnoe ; + med_int numnoe[27] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27}; + med_int nufano[27] = {1,1,1,1,1,1,1,1,1,3,3,3,3,0,3,3,3,3,2,2,2,2,2,2,2,2,2}; + /* + les elements: + */ + med_int nhexa8 = 8; + med_int hexa8[64] = { + 4, 13, 14, 5, 1, 10, 11, 2, + 5, 14, 15, 6, 2, 11, 12, 3, + 7, 16, 17, 8, 4, 13, 14, 5, + 8, 17, 18, 9, 5, 14, 15, 6, + 13, 22, 23, 14, 10, 19, 20, 11, + 14, 23, 24, 15, 11, 20, 21, 12, + 16, 25, 26, 17, 13, 22, 23, 14, + 17, 26, 27, 18, 14, 23, 24, 15 + }; + char nomhexa8[MED_TAILLE_PNOM*8+1] = "hexa1 hexa2 hexa3 hexa4 hexa5 hexa6 hexa7 hexa8 "; + med_int numhexa8[8] = {1,2,3,4,5,6,7,8}; + med_int nufahexa8[8] = {-1,-1,-1,-1,-2,-2,-2,-2}; + + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + char attdes[MED_TAILLE_DESC+1]; + med_int natt; + med_int attide; + med_int attval; + med_int ngro; + char gro[MED_TAILLE_LNOM+1]; + int i; + int nfame = 1; + int nfamn = 1; + int nfamf = 1; + + /* + Some fields : 2 on nodes : one int and one double , one on cells : double + */ + + char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ; + char champ1_comp[MED_TAILLE_PNOM+1]="comp1 " ; + char champ1_unit[MED_TAILLE_PNOM+1]="M " ; + med_int fieldnodeint[27] = {1,1,3,2,2,3,4,4,5,1,1,3,2,2,3,4,4,5,1,1,3,2,2,3,4,4,5}; + + char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ; + char champ2_comp[MED_TAILLE_PNOM+1]="comp1 " ; + char champ2_unit[MED_TAILLE_PNOM+1]="J " ; + med_float fieldnodedouble1[27] = {1.,3.,4.,1.,3.,4.,3.,2.,5.,1.,3.,4.,1.,3.,4.,3.,2.,5.,1.,3.,4.,1.,3.,4.,3.,2.,5.}; + med_float fieldnodedouble2[27] = {1.,2.,2.,3.,3.,3.,4.,4.,5.,1.,2.,2.,3.,3.,3.,4.,4.,5.,1.,2.,2.,3.,3.,3.,4.,4.,5.}; + + char champ3[MED_TAILLE_NOM+1]="fieldcelldouble" ; + char champ3_comp[MED_TAILLE_PNOM*3+1]="comp1 comp2 comp3 " ; + char champ3_unit[MED_TAILLE_PNOM*3+1]="M/S m/s m/s " ; + med_float fieldcelldouble[8*3] = {0.,1.,1.,1.,1.,2.,2.,3.,0.,1.,1.,1.,1.,2.,2.,3.,0.,1.,1.,1.,1.,2.,2.,3.}; + + /***************************************************************************/ + fid = MEDouvrir("cube_hexa8.med",MED_REMP); + if (fid < 0) + ret = -1; + else + ret = 0; + printf("%d\n",ret); + + /***************************************************************************/ + if (ret == 0) + ret = MEDmaaCr(fid,maa,mdim); + printf("%d\n",ret); + if (ret == 0) + ret = MEDunvCr(fid,maa); + printf("%d\n",ret); + + /***************************************************************************/ + if (ret == 0) + ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART, + nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI, + nufano,nnoe,MED_ECRI); + printf("%d\n",ret); + + /* ecriture des mailles MED_HEXA8 : + - connectivite + - noms (optionnel) + - numeros (optionnel) + - numeros des familles */ + if (ret == 0) + ret = MEDelementsEcr(fid,maa,mdim,hexa8,MED_FULL_INTERLACE, + nomhexa8,MED_FAUX,numhexa8,MED_VRAI,nufahexa8,nhexa8, + MED_MAILLE,MED_HEXA8,MED_NOD,MED_ECRI); + printf("%d \n",ret); + + /***************************************************************************/ + /* ecriture des familles */ + /* Conventions : + - toujours creer une famille de numero 0 ne comportant aucun attribut + ni groupe (famille de reference pour les noeuds ou les elements + qui ne sont rattaches a aucun groupe ni attribut) + - les numeros de familles de noeuds sont > 0 + - les numeros de familles des elements sont < 0 + - rien d'imposer sur les noms de familles + */ + + /* la famille 0 */ + if (ret == 0) + { + strcpy(nomfam,"FAMILLE_0"); + numfam = 0; + ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0, + gro,0); + } + printf("%d \n",ret); + + /* on cree : + - 2 familles d'elements (-1,-2) et + - 3 familles de noeuds (1,2,3) + */ + + if (ret == 0) + { + nfame = 2; + for (i=0;i diff --git a/src/MEDMEM/duplicateMEDMESH.cxx b/src/MEDMEM/duplicateMEDMESH.cxx index c2615b099..94f207b3f 100644 --- a/src/MEDMEM/duplicateMEDMESH.cxx +++ b/src/MEDMEM/duplicateMEDMESH.cxx @@ -1,29 +1,3 @@ -// 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 : duplicateMEDMESH.cxx -// Module : MED - using namespace std; #include #include @@ -51,7 +25,7 @@ int main (int argc, char ** argv) { // we read all meshes in filenameIN try { - int read ; + //int read ; !! UNUSED VARIABLE !! myMedDriver.open(); myMedDriver.readFileStruct(); myMedDriver.close(); diff --git a/src/MEDMEM/med2vtk.cxx b/src/MEDMEM/med2vtk.cxx index 877459412..39dd5c871 100644 --- a/src/MEDMEM/med2vtk.cxx +++ b/src/MEDMEM/med2vtk.cxx @@ -1,12 +1,3 @@ -// MED MEDMEM : MED files in memory -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : med2vtk.cxx -// Module : MED - using namespace std; #include #include diff --git a/src/MEDMEM/med_test.cxx b/src/MEDMEM/med_test.cxx index 5090890bc..01bf6ea8f 100644 --- a/src/MEDMEM/med_test.cxx +++ b/src/MEDMEM/med_test.cxx @@ -1,29 +1,3 @@ -// 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 : med_test.cxx -// Module : MED - using namespace std; #include diff --git a/src/MEDMEM/test_MEDMEM_Array.cxx b/src/MEDMEM/test_MEDMEM_Array.cxx index 418824c4a..be5040b3e 100644 --- a/src/MEDMEM/test_MEDMEM_Array.cxx +++ b/src/MEDMEM/test_MEDMEM_Array.cxx @@ -1,29 +1,3 @@ -// 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 : test_MEDMEM_Array.cxx -// Module : MED - using namespace std; #include "utilities.h" #include "MEDMEM_Array.hxx" diff --git a/src/MEDMEM/test_MEDMEM_CellModel.cxx b/src/MEDMEM/test_MEDMEM_CellModel.cxx index e733843d3..c125aed14 100644 --- a/src/MEDMEM/test_MEDMEM_CellModel.cxx +++ b/src/MEDMEM/test_MEDMEM_CellModel.cxx @@ -1,29 +1,3 @@ -// 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 : test_MEDMEM_CellModel.cxx -// Module : MED - using namespace std; #include "utilities.h" #include "MEDMEM_CellModel.hxx" diff --git a/src/MEDMEM/test_MEDMEM_Meshing.cxx b/src/MEDMEM/test_MEDMEM_Meshing.cxx index 087ecf343..feea08dea 100644 --- a/src/MEDMEM/test_MEDMEM_Meshing.cxx +++ b/src/MEDMEM/test_MEDMEM_Meshing.cxx @@ -1,14 +1,6 @@ -// MED MEDMEM : MED files in memory -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : test_MEDMEM_Meshing.cxx -// Module : MED - #include "MEDMEM_Meshing.hxx" #include "MEDMEM_Group.hxx" +#include "MEDMEM_Field.hxx" using namespace std; @@ -16,12 +8,17 @@ int main (int argc, char ** argv) { if (argc <2) { cerr << "Usage : " << argv[0] - << " filename" << endl << endl; + << " filenameRoot" << endl; + cerr << " where filenameRoot is a root filename, the program will produce" << endl; + cerr << " 2 files filenameRoot.med and filenameRoot.vtk" << endl << endl; exit(-1); } // filename to save the generated MESH - string filename = argv[1] ; + string filenameRoot = argv[1] ; + + string filenameMed = filenameRoot+".med"; + string filenameVtk = filenameRoot+".vtk"; MESHING myMeshing ; myMeshing.setName("meshing") ; @@ -210,7 +207,7 @@ int main (int argc, char ** argv) { myGroup.setGeometricType(myTypes); const int myNumberOfElements[] = {4,1} ; myGroup.setNumberOfElements(myNumberOfElements); - const int index[3+1] = {1,5,6} ; + const int index[2+1] = {1,5,6} ; const int value[4+1]= { 3,4,5,9, @@ -264,7 +261,245 @@ int main (int argc, char ** argv) { // all rigtht, we save it ! - int id = myMeshing.addDriver(MED_DRIVER,filename,myMeshing.getName()); - myMeshing.write(id) ; + int idMed = myMeshing.addDriver(MED_DRIVER,filenameMed,myMeshing.getName()); + myMeshing.write(idMed) ; + + int idVtk = myMeshing.addDriver(VTK_DRIVER,filenameVtk,myMeshing.getName()); + myMeshing.write(idVtk) ; + + // we build now 8 fields : 4 fields double (integer) : + // 2 fields on nodes (cells) : + // 1 scalar (vector) + + SUPPORT * supportOnNodes = new SUPPORT(&myMeshing,"On_All_Nodes",MED_NODE); + int numberOfNodes = supportOnNodes->getNumberOfElements(MED_ALL_ELEMENTS); + + SUPPORT * supportOnCells = new SUPPORT(&myMeshing,"On_All_Cells",MED_CELL); + int numberOfCells = supportOnCells->getNumberOfElements(MED_ALL_ELEMENTS); + + FIELD * fieldDoubleScalarOnNodes = new FIELD(supportOnNodes,1); + fieldDoubleScalarOnNodes->setName("fieldScalarDoubleNode"); + fieldDoubleScalarOnNodes->setIterationNumber(-1); + fieldDoubleScalarOnNodes->setOrderNumber(-1); + fieldDoubleScalarOnNodes->setTime(0.0); + + fieldDoubleScalarOnNodes->setComponentName(1,"Vx"); + fieldDoubleScalarOnNodes->setComponentDescription(1,"comp1"); + fieldDoubleScalarOnNodes->setMEDComponentUnit(1,"unit1"); + + fieldDoubleScalarOnNodes->setValueType(MED_REEL64); + + FIELD * fieldDoubleVectorOnNodes = new FIELD(supportOnNodes,SpaceDimension); + fieldDoubleVectorOnNodes->setName("fieldVectorDoubleNode"); + fieldDoubleVectorOnNodes->setIterationNumber(-1); + fieldDoubleVectorOnNodes->setOrderNumber(-1); + fieldDoubleVectorOnNodes->setTime(0.0); + + fieldDoubleVectorOnNodes->setComponentName(1,"Vx"); + fieldDoubleVectorOnNodes->setComponentDescription(1,"comp1"); + fieldDoubleVectorOnNodes->setMEDComponentUnit(1,"unit1"); + fieldDoubleVectorOnNodes->setComponentName(2,"Vy"); + fieldDoubleVectorOnNodes->setComponentDescription(2,"comp2"); + fieldDoubleVectorOnNodes->setMEDComponentUnit(2,"unit2"); + fieldDoubleVectorOnNodes->setComponentName(3,"Vz"); + fieldDoubleVectorOnNodes->setComponentDescription(3,"comp3"); + fieldDoubleVectorOnNodes->setMEDComponentUnit(3,"unit3"); + + fieldDoubleVectorOnNodes->setValueType(MED_REEL64); + + FIELD * fieldDoubleScalarOnCells = new FIELD(supportOnCells,1); + fieldDoubleScalarOnCells->setName("fieldScalarDoubleCell"); + fieldDoubleScalarOnCells->setIterationNumber(-1); + fieldDoubleScalarOnCells->setOrderNumber(-1); + fieldDoubleScalarOnCells->setTime(0.0); + + fieldDoubleScalarOnCells->setComponentName(1,"Vx"); + fieldDoubleScalarOnCells->setComponentDescription(1,"comp1"); + fieldDoubleScalarOnCells->setMEDComponentUnit(1,"unit1"); + + fieldDoubleScalarOnCells->setValueType(MED_REEL64); + + FIELD * fieldDoubleVectorOnCells = new FIELD(supportOnCells,SpaceDimension); + fieldDoubleVectorOnCells->setName("fieldVectorrDoubleCell"); + fieldDoubleVectorOnCells->setIterationNumber(-1); + fieldDoubleVectorOnCells->setOrderNumber(-1); + fieldDoubleVectorOnCells->setTime(0.0); + + fieldDoubleVectorOnCells->setComponentName(1,"Vx"); + fieldDoubleVectorOnCells->setComponentDescription(1,"comp1"); + fieldDoubleVectorOnCells->setMEDComponentUnit(1,"unit1"); + fieldDoubleVectorOnCells->setComponentName(2,"Vy"); + fieldDoubleVectorOnCells->setComponentDescription(2,"comp2"); + fieldDoubleVectorOnCells->setMEDComponentUnit(2,"unit2"); + fieldDoubleVectorOnCells->setComponentName(3,"Vz"); + fieldDoubleVectorOnCells->setComponentDescription(3,"comp3"); + fieldDoubleVectorOnCells->setMEDComponentUnit(3,"unit3"); + + fieldDoubleVectorOnCells->setValueType(MED_REEL64); + + FIELD * fieldIntScalarOnNodes = new FIELD(supportOnNodes,1); + fieldIntScalarOnNodes->setName("fieldScalarIntNode"); + fieldIntScalarOnNodes->setIterationNumber(-1); + fieldIntScalarOnNodes->setOrderNumber(-1); + fieldIntScalarOnNodes->setTime(0.0); + + fieldIntScalarOnNodes->setComponentName(1,"Vx"); + fieldIntScalarOnNodes->setComponentDescription(1,"comp1"); + fieldIntScalarOnNodes->setMEDComponentUnit(1,"unit1"); + + fieldIntScalarOnNodes->setValueType(MED_INT32); + + FIELD * fieldIntVectorOnNodes = new FIELD(supportOnNodes,SpaceDimension); + fieldIntVectorOnNodes->setName("fieldVectorIntNode"); + fieldIntVectorOnNodes->setIterationNumber(-1); + fieldIntVectorOnNodes->setOrderNumber(-1); + fieldIntVectorOnNodes->setTime(0.0); + + fieldIntVectorOnNodes->setComponentName(1,"Vx"); + fieldIntVectorOnNodes->setComponentDescription(1,"comp1"); + fieldIntVectorOnNodes->setMEDComponentUnit(1,"unit1"); + fieldIntVectorOnNodes->setComponentName(2,"Vy"); + fieldIntVectorOnNodes->setComponentDescription(2,"comp2"); + fieldIntVectorOnNodes->setMEDComponentUnit(2,"unit2"); + fieldIntVectorOnNodes->setComponentName(3,"Vz"); + fieldIntVectorOnNodes->setComponentDescription(3,"comp3"); + fieldIntVectorOnNodes->setMEDComponentUnit(3,"unit3"); + + fieldIntVectorOnNodes->setValueType(MED_INT32); + + FIELD * fieldIntScalarOnCells = new FIELD(supportOnCells,1); + fieldIntScalarOnCells->setName("fieldScalarIntCell"); + fieldIntScalarOnCells->setIterationNumber(-1); + fieldIntScalarOnCells->setOrderNumber(-1); + fieldIntScalarOnCells->setTime(0.0); + + fieldIntScalarOnCells->setComponentName(1,"Vx"); + fieldIntScalarOnCells->setComponentDescription(1,"comp1"); + fieldIntScalarOnCells->setMEDComponentUnit(1,"unit1"); + + fieldIntScalarOnCells->setValueType(MED_INT32); + + FIELD * fieldIntVectorOnCells = new FIELD(supportOnCells,SpaceDimension); + fieldIntVectorOnCells->setName("fieldVectorrIntCell"); + fieldIntVectorOnCells->setIterationNumber(-1); + fieldIntVectorOnCells->setOrderNumber(-1); + fieldIntVectorOnCells->setTime(0.0); + + fieldIntVectorOnCells->setComponentName(1,"Vx"); + fieldIntVectorOnCells->setComponentDescription(1,"comp1"); + fieldIntVectorOnCells->setMEDComponentUnit(1,"unit1"); + fieldIntVectorOnCells->setComponentName(2,"Vy"); + fieldIntVectorOnCells->setComponentDescription(2,"comp2"); + fieldIntVectorOnCells->setMEDComponentUnit(2,"unit2"); + fieldIntVectorOnCells->setComponentName(3,"Vz"); + fieldIntVectorOnCells->setComponentDescription(3,"comp3"); + fieldIntVectorOnCells->setMEDComponentUnit(3,"unit3"); + + fieldIntVectorOnCells->setValueType(MED_INT32); + + for (int i = 0; isetValueIJ(i+1,1,valueDbl1); + + fieldIntScalarOnNodes->setValueIJ(i+1,1,valueInt1); + + fieldDoubleVectorOnNodes->setValueIJ(i+1,1,valueDbl1); + fieldDoubleVectorOnNodes->setValueIJ(i+1,2,valueDbl2); + fieldDoubleVectorOnNodes->setValueIJ(i+1,3,valueDbl3); + + fieldIntVectorOnNodes->setValueIJ(i+1,1,valueInt1); + fieldIntVectorOnNodes->setValueIJ(i+1,2,valueInt2); + fieldIntVectorOnNodes->setValueIJ(i+1,3,valueInt3); + } + + for (int i = 0; isetValueIJ(i+1,1,valueDbl1); + + fieldIntScalarOnCells->setValueIJ(i+1,1,valueInt1); + + fieldDoubleVectorOnCells->setValueIJ(i+1,1,valueDbl1); + fieldDoubleVectorOnCells->setValueIJ(i+1,2,valueDbl2); + fieldDoubleVectorOnCells->setValueIJ(i+1,3,valueDbl3); + + fieldIntVectorOnCells->setValueIJ(i+1,1,valueInt1); + fieldIntVectorOnCells->setValueIJ(i+1,2,valueInt2); + fieldIntVectorOnCells->setValueIJ(i+1,3,valueInt3); + } + + idMed = fieldDoubleScalarOnNodes->addDriver(MED_DRIVER,filenameMed,fieldDoubleScalarOnNodes->getName()); + fieldDoubleScalarOnNodes->write(idMed) ; + + idMed = fieldIntScalarOnNodes->addDriver(MED_DRIVER,filenameMed,fieldIntScalarOnNodes->getName()); + fieldIntScalarOnNodes->write(idMed) ; + + idMed = fieldDoubleVectorOnNodes->addDriver(MED_DRIVER,filenameMed,fieldDoubleVectorOnNodes->getName()); + fieldDoubleVectorOnNodes->write(idMed) ; + + idMed = fieldIntVectorOnNodes->addDriver(MED_DRIVER,filenameMed,fieldIntVectorOnNodes->getName()); + fieldIntVectorOnNodes->write(idMed) ; + + idMed = fieldDoubleScalarOnCells->addDriver(MED_DRIVER,filenameMed,fieldDoubleScalarOnCells->getName()); + fieldDoubleScalarOnCells->write(idMed) ; + + idMed = fieldIntScalarOnCells->addDriver(MED_DRIVER,filenameMed,fieldIntScalarOnCells->getName()); + fieldIntScalarOnCells->write(idMed) ; + + idMed = fieldDoubleVectorOnCells->addDriver(MED_DRIVER,filenameMed,fieldDoubleVectorOnCells->getName()); + fieldDoubleVectorOnCells->write(idMed) ; + + idMed = fieldIntVectorOnCells->addDriver(MED_DRIVER,filenameMed,fieldIntVectorOnCells->getName()); + fieldIntVectorOnCells->write(idMed) ; + + idVtk = fieldDoubleScalarOnNodes->addDriver(VTK_DRIVER,filenameVtk,fieldDoubleScalarOnNodes->getName()); + fieldDoubleScalarOnNodes->writeAppend(idVtk) ; + + idVtk = fieldIntScalarOnNodes->addDriver(VTK_DRIVER,filenameVtk,fieldIntScalarOnNodes->getName()); + fieldIntScalarOnNodes->writeAppend(idVtk) ; + + idVtk = fieldDoubleVectorOnNodes->addDriver(VTK_DRIVER,filenameVtk,fieldDoubleVectorOnNodes->getName()); + fieldDoubleVectorOnNodes->writeAppend(idVtk) ; + + idVtk = fieldIntVectorOnNodes->addDriver(VTK_DRIVER,filenameVtk,fieldIntVectorOnNodes->getName()); + fieldIntVectorOnNodes->writeAppend(idVtk) ; + + idVtk = fieldDoubleScalarOnCells->addDriver(VTK_DRIVER,filenameVtk,fieldDoubleScalarOnCells->getName()); + fieldDoubleScalarOnCells->writeAppend(idVtk) ; + + idVtk = fieldIntScalarOnCells->addDriver(VTK_DRIVER,filenameVtk,fieldIntScalarOnCells->getName()); + fieldIntScalarOnCells->writeAppend(idVtk) ; + + idVtk = fieldDoubleVectorOnCells->addDriver(VTK_DRIVER,filenameVtk,fieldDoubleVectorOnCells->getName()); + fieldDoubleVectorOnCells->writeAppend(idVtk) ; + + idVtk = fieldIntVectorOnCells->addDriver(VTK_DRIVER,filenameVtk,fieldIntVectorOnCells->getName()); + fieldIntVectorOnCells->writeAppend(idVtk) ; + + delete fieldDoubleScalarOnNodes; + delete fieldIntScalarOnNodes; + delete fieldDoubleVectorOnNodes; + delete fieldIntVectorOnNodes; + delete fieldDoubleScalarOnCells; + delete fieldIntScalarOnCells; + delete fieldDoubleVectorOnCells; + delete fieldIntVectorOnCells; + delete supportOnNodes; + delete supportOnCells; } diff --git a/src/MEDMEM/test_MEDMEM_ModulusArray.cxx b/src/MEDMEM/test_MEDMEM_ModulusArray.cxx index bdb7fa51a..97f6bf302 100644 --- a/src/MEDMEM/test_MEDMEM_ModulusArray.cxx +++ b/src/MEDMEM/test_MEDMEM_ModulusArray.cxx @@ -1,29 +1,3 @@ -// 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 : test_MEDMEM_ModulusArray.cxx -// Module : MED - using namespace std; #include "utilities.h" diff --git a/src/MEDMEM/test_MEDMEM_SkyLineArray.cxx b/src/MEDMEM/test_MEDMEM_SkyLineArray.cxx index ba1fef4bd..6d7dc268e 100644 --- a/src/MEDMEM/test_MEDMEM_SkyLineArray.cxx +++ b/src/MEDMEM/test_MEDMEM_SkyLineArray.cxx @@ -1,29 +1,3 @@ -// 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 : test_MEDMEM_SkyLineArray.cxx -// Module : MED - using namespace std; #include "utilities.h" #include "MEDMEM_SkyLineArray.hxx" diff --git a/src/MEDMEM/test_affect_medarray.cxx b/src/MEDMEM/test_affect_medarray.cxx index cc9a79485..eb72d86d3 100644 --- a/src/MEDMEM/test_affect_medarray.cxx +++ b/src/MEDMEM/test_affect_medarray.cxx @@ -1,29 +1,3 @@ -// 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 : test_affect_medarray.cxx -// Module : MED - using namespace std; /* Programme de test du constructeur de copies de la classe MEDARRAY de MEDMEM jroy - 16/12/2002 */ diff --git a/src/MEDMEM/test_copie_connectivity.cxx b/src/MEDMEM/test_copie_connectivity.cxx index b3442471a..962de0640 100644 --- a/src/MEDMEM/test_copie_connectivity.cxx +++ b/src/MEDMEM/test_copie_connectivity.cxx @@ -1,29 +1,3 @@ -// 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 : test_copie_connectivity.cxx -// Module : MED - using namespace std; /* Programme de test du constructeur de copies de la classe CONNECTIVITY de MEDMEM jroy - 19/12/2002 */ diff --git a/src/MEDMEM/test_copie_coordinate.cxx b/src/MEDMEM/test_copie_coordinate.cxx index 385b8ab0e..4a40c89df 100644 --- a/src/MEDMEM/test_copie_coordinate.cxx +++ b/src/MEDMEM/test_copie_coordinate.cxx @@ -1,29 +1,3 @@ -// 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 : test_copie_coordinate.cxx -// Module : MED - using namespace std; /* Programme de test du constructeur de copies de la classe COORDINATE de MEDMEM jroy - 17/12/2002 */ diff --git a/src/MEDMEM/test_copie_family.cxx b/src/MEDMEM/test_copie_family.cxx index 29fbcab8a..34633dc27 100644 --- a/src/MEDMEM/test_copie_family.cxx +++ b/src/MEDMEM/test_copie_family.cxx @@ -1,29 +1,3 @@ -// 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 : test_copie_family.cxx -// Module : MED - using namespace std; #include diff --git a/src/MEDMEM/test_copie_fieldT.cxx b/src/MEDMEM/test_copie_fieldT.cxx index 7d6109bd4..fc9ad2142 100644 --- a/src/MEDMEM/test_copie_fieldT.cxx +++ b/src/MEDMEM/test_copie_fieldT.cxx @@ -1,29 +1,3 @@ -// 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 : test_copie_fieldT.cxx -// Module : MED - using namespace std; /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM jroy - 12/12/2002 */ @@ -84,7 +58,7 @@ void affiche_fieldT(FIELD * myField, const SUPPORT * mySupport) int main (int argc, char ** argv) { - int read; + // int read; !! UNUSED VARIABLE !! if ((argc !=3) && (argc != 4)) { cerr << "Usage : " << argv[0] diff --git a/src/MEDMEM/test_copie_field_.cxx b/src/MEDMEM/test_copie_field_.cxx index 08f8c9e93..0598a26b1 100644 --- a/src/MEDMEM/test_copie_field_.cxx +++ b/src/MEDMEM/test_copie_field_.cxx @@ -1,29 +1,3 @@ -// 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 : test_copie_field_.cxx -// Module : MED - /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM jroy - 12/12/2002 */ @@ -78,7 +52,7 @@ void affiche_field(FIELD_ * myField, const SUPPORT * mySupport) int main (int argc, char ** argv) { - int read; + // int read; !! UNUSED VARIABLE !! if ((argc !=3) && (argc != 4)) { cerr << "Usage : " << argv[0] diff --git a/src/MEDMEM/test_copie_group.cxx b/src/MEDMEM/test_copie_group.cxx index 7bf53c8e2..96e464f7d 100644 --- a/src/MEDMEM/test_copie_group.cxx +++ b/src/MEDMEM/test_copie_group.cxx @@ -1,29 +1,3 @@ -// 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 : test_copie_group.cxx -// Module : MED - using namespace std; #include diff --git a/src/MEDMEM/test_copie_medarray.cxx b/src/MEDMEM/test_copie_medarray.cxx index afe04ccb0..3cd8745bc 100644 --- a/src/MEDMEM/test_copie_medarray.cxx +++ b/src/MEDMEM/test_copie_medarray.cxx @@ -1,29 +1,3 @@ -// 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 : test_copie_medarray.cxx -// Module : MED - using namespace std; /* Programme de test du constructeur de copies de la classe MEDARRAY de MEDMEM jroy - 16/12/2002 */ diff --git a/src/MEDMEM/test_copie_mesh.cxx b/src/MEDMEM/test_copie_mesh.cxx index 53f794410..c8e83c56e 100644 --- a/src/MEDMEM/test_copie_mesh.cxx +++ b/src/MEDMEM/test_copie_mesh.cxx @@ -1,12 +1,3 @@ -// MED MEDMEM : MED files in memory -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : test_copie_mesh.cxx -// Module : MED - using namespace std; #include diff --git a/src/MEDMEM/test_copie_support.cxx b/src/MEDMEM/test_copie_support.cxx index bc228814a..5abfe4f5e 100644 --- a/src/MEDMEM/test_copie_support.cxx +++ b/src/MEDMEM/test_copie_support.cxx @@ -1,29 +1,3 @@ -// 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 : test_copie_support.cxx -// Module : MED - using namespace std; #include diff --git a/src/MEDMEM/test_gibi_driver.cxx b/src/MEDMEM/test_gibi_driver.cxx new file mode 100644 index 000000000..cfa50ec21 --- /dev/null +++ b/src/MEDMEM/test_gibi_driver.cxx @@ -0,0 +1,38 @@ +#include "MEDMEM_GibiMeshDriver.hxx" +#include "MEDMEM_Mesh.hxx" + +int main (int argc, char ** argv) +{ + /* process the arguments */ + if (argc != 2) + { + cerr << "Usage : " << argv[0] + << "Gibifilename" << endl << endl + << "-> lit le fichier gibi filename ,crée un fichier MED" << endl; + exit(-1); + } + string gibifilename = argv[1]; + + // Construction des noms de fichier + const string ext=".sauve"; + string::size_type pos=gibifilename.find(ext,0); + string basename (gibifilename, 0, pos); + string medfile=basename+".med"; + string cast2medfile="cast_"+basename+".med"; + + // lecture du fichier gibi + MESH * myMesh= new MESH() ; + GIBI_MESH_RDONLY_DRIVER myGibiMeshDriver(gibifilename, myMesh) ; + myGibiMeshDriver.open() ; + myGibiMeshDriver.read() ; + myGibiMeshDriver.close() ; + + cout << "Impression de MESH : " << endl; + cout << *myMesh; + + // creation d'un fichier med + int idMed = myMesh->addDriver(MED_DRIVER, medfile, basename); + myMesh->write(idMed) ; + delete myMesh; + +} diff --git a/src/MEDMEM/test_operation_fielddouble.cxx b/src/MEDMEM/test_operation_fielddouble.cxx new file mode 100644 index 000000000..4338f6ed5 --- /dev/null +++ b/src/MEDMEM/test_operation_fielddouble.cxx @@ -0,0 +1,403 @@ +// Programme de test des operations sur les champs + +#include +#include +#include +#include + +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_Group.hxx" + +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_MedFieldDriver.hxx" +#include "MEDMEM_Support.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_define.hxx" + +double myfunction1(double x) +{ + return 0.25*(x-1.0); +} + + +using namespace std; +void affiche_field_(FIELD_ * myField, const SUPPORT * mySupport) +{ + cout << "Field "<< myField->getName() << " : " <getDescription() << endl ; + int NumberOfComponents = myField->getNumberOfComponents() ; + cout << "- Nombre de composantes : "<< NumberOfComponents << endl ; + cout << "- Nombre de valeurs : "<< myField->getNumberOfValues() << endl ; + for (int i=1; igetComponentName(i)<< endl; + cout << " - description : "<getComponentDescription(i) << endl; + cout << " - units : "<getMEDComponentUnit(i) << endl; + } + cout << "- iteration :" << endl ; + cout << " - numero : " << myField->getIterationNumber()<< endl ; + cout << " - ordre : " << myField->getOrderNumber()<< endl ; + cout << " - temps : " << myField->getTime()<< endl ; + + cout << "- Type : " << myField->getValueType()<< endl; + + cout << "- Adresse support : " << mySupport << endl; +} + +void affiche_fieldT(FIELD * myField, const SUPPORT * mySupport) +{ + affiche_field_((FIELD_ *) myField, mySupport); + + cout << "- Valeurs :"<getNumberOfElements(MED_ALL_ELEMENTS); + int NumberOfComponents = myField->getNumberOfComponents() ; + + for (int i=1; igetValueI(MED_FULL_INTERLACE,i) ; + for (int j=0; jnorm2() << endl; + cout << "Norme max : " << myField->normMax() << endl; + try + { + for (int i=1; i<=myField->getNumberOfComponents(); ++i) + cout << "Norme L2 - comp=" << i << " : " << myField->normL2(i) << endl; + cout << "Norme L2 : " << myField->normL2() << endl; + + for (int i=1; i<=myField->getNumberOfComponents(); ++i) + cout << "Norme L1 - comp=" << i << " : " << myField->normL1(i) << endl; + cout << "Norme L1 : " << myField->normL1() << endl; + } + catch (MEDEXCEPTION &ex) + { + cout << ex.what() << endl; + } +} + +void affiche_valeur_field(const FIELD& f) +{ + const int tailleMax=12; + const int taille=f.getNumberOfValues()*f.getNumberOfComponents(); + const double * value=f.getValue(f.getvalue()->getMode()); + if(taille<=tailleMax) + for(int i=0;i& resOp, const FIELD& f1, const FIELD& f2, + char Op, const char* intitule, int verbose) +{ + int res=0; + + // get pointers to inside arrays of values + medModeSwitch mode=resOp.getvalue()->getMode(); + const double * value=resOp.getValue(mode); + const double * value1=f1.getValue(mode); + const double * value2=f2.getValue(mode); + const int size=f1.getNumberOfValues()*f1.getNumberOfComponents(); // size of field1 + + // check size compatibility + if(f1.getNumberOfValues()*f1.getNumberOfComponents()!=size || + resOp.getNumberOfValues()*resOp.getNumberOfComponents()!=size) + res=1; + + if(!res) + { + switch(Op) + { + case '+': + for(int i=0; i!=size; ++i) + if(value[i]!=value1[i]+value2[i]) + res+=1; + break; + case '-': + for(int i=0; i!=size; ++i) + if(value[i]!=value1[i]-value2[i]) + res+=1; + break; + case 'n': + for(int i=0; i!=size; ++i) + if(value[i]!=-value1[i]) + res+=1; + break; + case '*': + for(int i=0; i!=size; ++i) + if(value[i]!=value1[i]*value2[i]) + res+=1; + break; + case '/': + for(int i=0; i!=size; ++i) + if(value2[i]!=0.0) + if(value[i]!=value1[i]/value2[i]) + res+=1; + break; + case '=': + for(int i=0; i!=size; ++i) + if(value[i]!=value2[i]) + res+=1; + break; + case 'a': + for(int i=0; i!=size; ++i) + if(value[i]!=value1[i]+value2[i]*value2[i]) + res+=1; + break; + } + + } + + if (verbose) + cout << endl << intitule << "["; + cout << res; + if (verbose) + { + cout << "] : "; + affiche_valeur_field(resOp); + } + else + cout << endl; +} + +int main (int argc, char ** argv) +{ + /* process the arguments */ + int verbose=0; // verbose=1 if the verbose mode is selected + int res=0; // unit test result + int ntest=0; // numéro du test + + if (argc>=2 && !strcmp(argv[1],"-v")) + verbose=1; + + if (argc != 4+verbose) + { + cerr << "Usage : " << argv[0] + << "[-v] filename meshname fieldname" << endl << endl + << "-> tests field's operations on the FIELD fieldname" << endl + << "Use optional option -v to select verbose mode" << endl; + exit(-1); + } + string filename = argv[verbose+1]; + string meshname = argv[verbose+2]; + string fieldname = argv[verbose+3]; + + /* read MESH, SUPPORT and FIELDS */ + MESH * myMesh = new MESH(MED_DRIVER,filename,meshname); + SUPPORT * mySupport; + FIELD * myField1; + try + { + mySupport = new SUPPORT(myMesh,"Support on all Cells",MED_CELL); + myField1 = new FIELD(mySupport,MED_DRIVER,filename,fieldname) ; + myField1->setValueType(MED_REEL64); + } + catch (MEDEXCEPTION &ex) + { + // field wasn't found on cells, try on nodes + delete mySupport ; + mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE); + try + { + myField1 = new FIELD(mySupport,MED_DRIVER,filename,fieldname) ; + } + catch (...) + { + cout << "Field double " << fieldname << " not found !!!" << endl ; + exit (-1) ; + } + } + FIELD * myField2 = new FIELD(* myField1); + FIELD myFieldPlus = *myField1 + *myField2; + if(verbose) + { + // affichage des nprmes,des champs f1, f2, scalarProduct(f1,f2) et f1+f2 + FIELD* myField1_vol=myField1->getSupport()->getMesh()->getVolume(myField1->getSupport()); + cout << "Norme L2 calculée en fournissant le volume : " << myField1->normL2(myField1_vol) << endl; + for (int i=1; i<=myField1->getNumberOfComponents(); ++i) + cout << "Norme L2 - comp=" << i << " : " << myField1->normL2(i,myField1_vol) << endl; + cout << "Norme L1 calculée en fournissant le volume : " << myField1->normL1(myField1_vol) << endl; + for (int i=1; i<=myField1->getNumberOfComponents(); ++i) + cout << "Norme L1 - comp=" << i << " : " << myField1->normL1(i,myField1_vol) << endl; + delete myField1_vol; + + affiche_fieldT(myField1, myField1->getSupport()); + cout << endl << string(60,'-') << endl; + affiche_fieldT(myField2, myField2->getSupport()); + cout << endl << string(60,'-') << endl; + + FIELD* myFieldDot = FIELD::scalarProduct(*myField1, *myField2); + affiche_fieldT(myFieldDot, myFieldDot->getSupport()); + delete myFieldDot; + cout << endl << string(60,'-') << endl ; + affiche_fieldT(&myFieldPlus, myFieldPlus.getSupport()); + cout << endl << string(60,'-') << endl << endl ; + } + + + // Verifie plusieurs cas de non compatibilité + + // test 1 : Unites non compatibles + const string unite=myField1->getMEDComponentUnit(1); + myField1->setMEDComponentUnit(1,string("UniteBidon")); + ntest++; res=1; + try + { + FIELD myFieldPlus = *myField1 + *myField2; + if(verbose) + { + cout << endl << string(60,'-') << endl; + cout<< "Test " << ntest << " : incompatibilité d'unité : " << endl << endl; + } + } + catch (MEDEXCEPTION & ex) + { + res=0; + if(verbose) + cout << ex.what() << endl; + myField1->setMEDComponentUnit(1,unite); + } + cout << res << endl; + + // test 2 : numberOfComponents non compatibles + const int numberOfComponents =myField1->getNumberOfComponents(); + myField1->setNumberOfComponents(13); + ntest++; res=1; + try + { + if(verbose) + { + cout << endl << string(60,'-') << endl; + cout<< "Test " << ntest << " : incompatibilité nombre de composantes : " << endl << endl; + } + FIELD myFieldPlus = *myField1 + *myField2; + } + catch (MEDEXCEPTION & ex) + { + res=0; + if(verbose) + cout << endl << ex.what() << endl << endl; + myField1->setNumberOfComponents(numberOfComponents); + } + cout << res << endl; + + // test 3 : supports non compatibles + const SUPPORT mySupport2(myMesh,"On_all_node",MED_NODE); + myField1->setSupport(&mySupport2); + ntest++; res=1; + try + { + if(verbose) + cout << endl << string(60,'-') << endl << "Test " << ntest << " : incompatibilité des supports" << endl << endl; + FIELD myFieldPlus = *myField1 + *myField2; + } + catch (MEDEXCEPTION & ex) + { + res=0; + if(verbose) + cout << ex.what() << endl << endl << endl; + myField1->setSupport(mySupport); + } + cout << res << endl; + + // test 4 : champs de taille nulle + myField1->setNumberOfComponents(0); + myField2->setNumberOfComponents(0); + ntest++; res=2; + try + { + if(verbose) + cout<< endl << string(60,'-') << endl << "Test " << ntest << " : incompatibilité taille nulle" << endl << endl; + FIELD myFieldPlus = *myField1 + *myField2; + } + catch (MEDEXCEPTION & ex) + { + --res; + if(verbose) + cout << ex.what() << endl << endl ; + } + try + { + double mynorm2=myField1->norm2(); + } + catch (MEDEXCEPTION & ex) + { + --res; + if(verbose) + cout << ex.what() << endl << endl ; + myField1->setNumberOfComponents(numberOfComponents); + myField2->setNumberOfComponents(numberOfComponents); + } + cout << res << endl; + + // Apres toutes ces exceptions, des opérations qui marchent! + + if(verbose) + { + cout<< endl << string(60,'-') << endl << "Test " << ++ntest << " : Operations arithmétiques" << endl; + cout << endl << " f1 : "; affiche_valeur_field(*myField1); + cout << endl << " f2 : "; affiche_valeur_field(*myField2); + cout << endl << string(140,'-'); + } + + // Test du résultats de certaines opérations et affichage si verbose + checkOperation(myFieldPlus, *myField1, *myField2, '+', " f1+f2 ", verbose); + FIELD* myFieldadd = FIELD::add(*myField1, *myField2); + checkOperation( *myFieldadd, *myField1, *myField2, '+', "add(f1,f2)", verbose); + delete myFieldadd; + + FIELD myFieldMoins = *myField1 - *myField2; + checkOperation(myFieldMoins, *myField1, *myField2, '-', " f1-f2 ", verbose); + FIELD* myFieldsub = FIELD::sub(*myField1, *myField2); + checkOperation( *myFieldsub, *myField1, *myField2, '-', "sub(f1,f2)", verbose); + delete myFieldsub; + FIELD myFieldNeg = -(*myField1); + checkOperation(myFieldNeg, *myField1, *myField1, 'n', " -f1 ", verbose); + + FIELD myFieldFois = *myField1 * *myField2; + checkOperation(myFieldFois, *myField1, *myField2, '*', " f1*f2 ", verbose); + FIELD* myFieldmul = FIELD::mul(*myField1, *myField2); + checkOperation( *myFieldmul, *myField1, *myField2, '*', "mul(f1,f2)", verbose); + + FIELD myFieldDiv = *myField1 / *myField2; + checkOperation(myFieldDiv, *myField1, *myField2, '/', " f1/f2 ", verbose); + FIELD* myFielddiv = FIELD::div(*myField1, *myField2); + checkOperation( *myFielddiv, *myField1, *myField2, '/', "div(f1,f2)", verbose); + delete myFielddiv; + + FIELD myFieldAsso = (*myField1)+(*myField2)*(*myField2); + checkOperation(myFieldAsso, *myField1, *myField2, 'a', " f1+f2*f2 ", verbose); + + myField1->applyLin(4.0,1.0); + checkOperation(*myField1, *myField2, *myField2, 'l', " 4.f1 + 1 ", verbose); + myField1->applyFunc(); + checkOperation( *myField1, *myField2, *myField1, '=', "CB : ->f1)", verbose); + + *myField1 += *myField2; + checkOperation(*myField1, *myField2, *myField2, '+', " f1+=f2 ", verbose); + + *myField1 -= *myField2; + checkOperation(*myField1, *myField2, *myField2, '=', " f1-=f2 ", verbose); + + *myField1 *= *myField2; + checkOperation(*myField1, *myField2, *myField2, '*', " f1*=f2 ", verbose); + *myField1 /= *myField2; + checkOperation(*myField1, *myFieldmul, *myField2, '/', " f1/=f2 ", verbose); + delete myFieldmul; + + + delete myField1; + delete myField2; + delete mySupport ; + delete myMesh ; + return 0; +} diff --git a/src/MEDMEM/test_operation_fieldint.cxx b/src/MEDMEM/test_operation_fieldint.cxx new file mode 100644 index 000000000..48e33eaba --- /dev/null +++ b/src/MEDMEM/test_operation_fieldint.cxx @@ -0,0 +1,301 @@ +// Programme de test des operations sur les champs + +#include +#include +#include +#include + +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_Group.hxx" + +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_MedFieldDriver.hxx" +#include "MEDMEM_Support.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_define.hxx" + +int myfunction1(int x) +{ + return 2*x; +} + +int myfunction2(int x) +{ + return x/2; +} + +using namespace std; +void affiche_field_(FIELD_ * myField, const SUPPORT * mySupport) +{ + cout << "Field "<< myField->getName() << " : " <getDescription() << endl ; + int NumberOfComponents = myField->getNumberOfComponents() ; + cout << "- Nombre de composantes : "<< NumberOfComponents << endl ; + cout << "- Nombre de valeurs : "<< myField->getNumberOfValues() << endl ; + for (int i=1; igetComponentName(i)<< endl; + cout << " - description : "<getComponentDescription(i) << endl; + cout << " - units : "<getMEDComponentUnit(i) << endl; + } + cout << "- iteration :" << endl ; + cout << " - numero : " << myField->getIterationNumber()<< endl ; + cout << " - ordre : " << myField->getOrderNumber()<< endl ; + cout << " - temps : " << myField->getTime()<< endl ; + + cout << "- Type : " << myField->getValueType()<< endl; + + cout << "- Adresse support : " << mySupport << endl; +} + +void affiche_fieldT(FIELD * myField, const SUPPORT * mySupport) +{ + affiche_field_((FIELD_ *) myField, mySupport); + + cout << "- Valeurs :"<getNumberOfElements(MED_ALL_ELEMENTS); + int NumberOfComponents = myField->getNumberOfComponents() ; + + for (int i=1; igetValueI(MED_FULL_INTERLACE,i) ; + for (int j=0; jnorm2() << endl; + std::cout << "Norme max : " << myField->normMax() << endl; + try + { + for (int i=1; i<=myField->getNumberOfComponents(); ++i) + std::cout << "Norme L2 - comp=" << i << " : " << myField->normL2(i) << endl; + std::cout << "Norme L2 : " << myField->normL2() << endl; + + for (int i=1; i<=myField->getNumberOfComponents(); ++i) + std::cout << "Norme L1 - comp=" << i << " : " << myField->normL1(i) << endl; + std::cout << "Norme L1 : " << myField->normL1() << endl; + } + catch (MEDEXCEPTION &ex) + { + std::cout << ex.what() << std::endl; + } +} + +void affiche_valeur_field(const char * intitule, const int taille, const FIELD& f) +{ + const int * value=f.getValue(f.getvalue()->getMode()); + std::cout << endl << intitule; + for(int i=0;i * myField1; + try + { + /* read MESH, SUPPORT and FIELD */ + mySupport = new SUPPORT(myMesh,"Support on all Cells",MED_CELL); + myField1 = new FIELD(mySupport,MED_DRIVER,filename,fieldname) ; + myField1->setValueType(MED_REEL64); + } + catch (MEDEXCEPTION &ex) + { + delete mySupport ; + mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE); + try + { + myField1 = new FIELD(mySupport,MED_DRIVER,filename,fieldname) ; + myField1->setValueType(MED_INT32); + myField1->setValueIJ(10,1,-9); // pour tester les normes max avec une valeur negative + } + catch (...) + { + cout << "Field int " << fieldname << " not found !!!" << endl ; + exit (-1) ; + } + } + + FIELD * myField2 = new FIELD(* myField1); + //myField1->setNumberOfValues(16); // PROVISOIRE !! BUG + //myField2->setNumberOfValues(16); // PROVISOIRE !! BUG +// FIELD* myField1_vol=myField1->getSupport()->getMesh()->getVolume(myField1->getSupport()); +// affiche_fieldT(myField1_vol, myField1->getSupport()); + + affiche_fieldT(myField1, myField1->getSupport()); + std::cout << endl << string(60,'-') << endl; + affiche_fieldT(myField2, myField2->getSupport()); + + // Verifie plusieurs cas de non compatibilité + + // Unites non compatibles + const string unite=myField1->getMEDComponentUnit(1); + myField1->setMEDComponentUnit(1,string("UniteBidon")); + try + { + std::cout << endl << string(60,'-') << endl; + std::cout<< "Test incompatibilité d'unité :" << endl; + FIELD myFieldPlus = *myField1 + *myField2; + } + catch (MEDEXCEPTION & ex) + { + std::cout << "MEDEXCEPTION : " << ex.what() << endl; + myField1->setMEDComponentUnit(1,unite); + } + + // numberOfComponents non compatibles + const int numberOfComponents =myField1->getNumberOfComponents(); + myField1->setNumberOfComponents(4); + try + { + std::cout << endl << string(60,'-') << endl; + std::cout<< "Test incompatibilité nombre de composantes :" << endl; + FIELD myFieldPlus = *myField1 + *myField2; + } + catch (MEDEXCEPTION & ex) + { + std::cout << ex.what() << endl; + myField1->setNumberOfComponents(numberOfComponents); + } + + // supports non compatibles + const SUPPORT mySupport2(myMesh,"On_all_node",MED_NODE); + myField1->setSupport(&mySupport2); + try + { + std::cout << endl << string(60,'-') << endl; + std::cout<< "Test incompatibilité des supports :" << endl; + FIELD myFieldPlus = *myField1 + *myField2; + } + catch (MEDEXCEPTION & ex) + { + std::cout << ex.what() << endl; + myField1->setSupport(mySupport); + } + + // champs de taille nulle + myField1->setNumberOfComponents(0); + myField2->setNumberOfComponents(0); + try + { + std::cout << endl << string(60,'-') << endl; + std::cout<< "Test incompatibilité taille nulle :" << endl; + FIELD myFieldPlus = *myField1 + *myField2; + } + catch (MEDEXCEPTION & ex) + { + std::cout << ex.what() << endl; + } + try + { + double mynorm2=myField1->norm2(); + } + catch (MEDEXCEPTION & ex) + { + std::cout << ex.what() << endl; + myField1->setNumberOfComponents(numberOfComponents); + myField2->setNumberOfComponents(numberOfComponents); + } + + // Apres toutes ces exceptions, des opérations qui marchent! + + FIELD myFieldPlus = *myField1 + *myField2; + FIELD myFieldMoins = *myField1 - *myField2; + FIELD myFieldNeg = -(*myField1); + FIELD myFieldFois = *myField1 * *myField2; + FIELD myFieldDiv = *myField1 / *myField2; + FIELD myFieldAsso = (*myField1)+(*myField2)*(*myField2); + FIELD* myFieldadd = FIELD::add(*myField1, *myField2); + FIELD* myFieldsub = FIELD::sub(*myField1, *myField2); + FIELD* myFieldmul = FIELD::mul(*myField1, *myField2); + FIELD* myFielddiv = FIELD::div(*myField1, *myField2); + FIELD* myFieldDot = FIELD::scalarProduct(*myField1, *myField2); + + std::cout << endl << string(60,'-') << endl << "f1+f2 :" << endl << endl; + affiche_fieldT(&myFieldPlus, myFieldPlus.getSupport()); + std::cout << endl << string(60,'-') << endl << "add(f1,f2) :" << endl << endl; + affiche_fieldT(myFieldadd, myFieldadd->getSupport()); + std::cout << endl << string(60,'-') << endl << "scalarProduct(f1,f2) :" << endl << endl; + affiche_fieldT(myFieldDot, myFieldDot->getSupport()); + std::cout << endl << string(60,'-') << endl << " - f1 :" << endl << endl; + affiche_fieldT(&myFieldNeg, myFieldNeg.getSupport()); + + medModeSwitch mode=myFieldPlus.getvalue()->getMode(); + int size=myFieldPlus.getNumberOfValues()*myFieldPlus.getNumberOfComponents(); + + std::cout << endl << string(60,'-') << endl << "Tests opérations :" << endl << endl; + affiche_valeur_field(" f1 :", size, *myField1); + affiche_valeur_field(" f2 :", size, *myField2); + std::cout << endl << " " << string(4*size,'-'); + + affiche_valeur_field(" + :", size, myFieldPlus); + affiche_valeur_field(" add :", size, *myFieldadd); + affiche_valeur_field(" - :", size, myFieldMoins); + affiche_valeur_field(" sub :", size, *myFieldsub); + affiche_valeur_field(" * :", size, myFieldFois); + affiche_valeur_field(" mul :", size, *myFieldmul); + affiche_valeur_field(" / :", size, myFieldDiv); + affiche_valeur_field(" div :", size, *myFielddiv); + affiche_valeur_field("f1+f2*f1:", size, myFieldAsso); + affiche_valeur_field(" - f1 :", size, myFieldNeg); + + // Test applyLin + std::cout << endl; + myField1->applyLin(1,1); + affiche_valeur_field(" f1+1 :", size, *myField1); + myField1->applyLin(1,-1); + affiche_valeur_field(" -> f1 :", size, *myField1); + + // Test applyFunc + std::cout << endl; + myField1->applyFunc(); + affiche_valeur_field(" CB 2f1 :", size, *myField1); + myField1->applyFunc(); + affiche_valeur_field(" -> f1 :", size, *myField1); + + // Test operateur += + std::cout << endl; + *myField1 += *myField2; + affiche_valeur_field(" f1+=f2 :", size, *myField1); + + // Test operateur *= + *myField1 *= *myField2; + affiche_valeur_field(" f1*=f2 :", size, *myField1); + + // Test operateur /= + *myField1 /= *myField2; + affiche_valeur_field(" f1/=f2 :", size, *myField1); + + // Test operateur -= + *myField1 -= *myField2; + affiche_valeur_field(" f1-=f2 :", size, *myField1); + + std::cout << endl << endl; + + + delete myFieldadd; + delete myFieldsub; + delete myFieldmul; + delete myFielddiv; + delete myFieldDot; +// delete myField1_vol; + + delete myField1; + delete myField2; + delete mySupport ; + delete myMesh ; + return 0; +} diff --git a/src/MEDMEM/tests/readEntete.cxx b/src/MEDMEM/tests/readEntete.cxx index e45c82c26..56f008638 100755 --- a/src/MEDMEM/tests/readEntete.cxx +++ b/src/MEDMEM/tests/readEntete.cxx @@ -93,14 +93,23 @@ int main (int argc, char ** argv) { string chainevide(MED_TAILLE_PNOM+2,' '); cout << "- Nom du maillage : <<" << meshName << ">>" << endl; - cout << "- Dimension du maillage : "<< SpaceDimension << endl; + cout << "- Dimension d'espace : "<< SpaceDimension << endl; + cout << "- Dimension du maillage : "<< MeshDimension << endl; cout << "- Pas de nom universel " << endl ; cout << "- Nombre de noeuds : " << NumberOfNodes << " " << endl; int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL); const medGeometryElement * Types = myMesh->getTypes(MED_CELL); - + cout << "- Nombre de Type de mailles : " << NumberOfTypes << endl; + + if (NumberOfTypes > 0) + { + cout << " Types : "; + for (int itype=0; itype currentEntity = MED_FR::meshEntities[(MED_FR::med_entite_maillage)MED_CELL]; list::const_iterator currentGeometry; for (currentGeometry = currentEntity.begin(); @@ -113,6 +122,18 @@ int main (int argc, char ** argv) { cout << " " << endl; } + NumberOfTypes = myMesh->getNumberOfTypes(MED_FACE); + Types = myMesh->getTypes(MED_FACE); + + cout << "- Nombre de Type de faces : " << NumberOfTypes << endl; + + if (NumberOfTypes > 0) + { + cout << " Types : "; + for (int itype=0; itype currentEntity2 = MED_FR::meshEntities[(MED_FR::med_entite_maillage)MED_FACE]; for (currentGeometry = currentEntity2.begin(); currentGeometry != currentEntity2.end(); @@ -124,6 +145,18 @@ int main (int argc, char ** argv) { cout << " " << endl; } + NumberOfTypes = myMesh->getNumberOfTypes(MED_EDGE); + Types = myMesh->getTypes(MED_EDGE); + + cout << "- Nombre de Type de aretes : " << NumberOfTypes << endl; + + if (NumberOfTypes > 0) + { + cout << " Types : "; + for (int itype=0; itype currentEntity3 = MED_FR::meshEntities[(MED_FR::med_entite_maillage)MED_EDGE]; for (currentGeometry = currentEntity3.begin(); currentGeometry != currentEntity3.end(); diff --git a/src/MEDMEM/tests/testUCoordinate.cxx b/src/MEDMEM/tests/testUCoordinate.cxx index b43749ee3..41529316a 100755 --- a/src/MEDMEM/tests/testUCoordinate.cxx +++ b/src/MEDMEM/tests/testUCoordinate.cxx @@ -330,7 +330,7 @@ int main (int argc, char ** argv) { try { - double d = mycoo.getCoordinate(num + 1,axe+1); + const double d = mycoo.getCoordinate(num + 1,axe+1); cout << d <<" , "; ASSERT(fabs(d - coor3[num]) < pouieme); ASSERT(fabs(d - coor2[(num * SpaceDim)+axe]) < pouieme); diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.cxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.cxx index fe011b004..4a7d77514 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.cxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.cxx @@ -1,29 +1,3 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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_SWIG_FieldDouble.cxx -// Module : MED - using namespace std; #include "MEDMEM_SWIG_FieldDouble.hxx" @@ -59,15 +33,44 @@ FIELDDOUBLE::FIELDDOUBLE(const SUPPORT * Support, const int NumberOfComponents) */ //============================================================================= FIELDDOUBLE::FIELDDOUBLE(const SUPPORT * Support, driverTypes driverType, - const string & fileName, - const string & fieldName) : - FIELD(Support, driverType, fileName, fieldName) + const string & fileName, const string & fieldName, + const int iterationNumber, const int orderNumber) : + FIELD(Support, driverType, fileName, fieldName, + iterationNumber, orderNumber) { BEGIN_OF("Another constructor with arguments (for Python API) FIELDDOUBLE"); + med_type_champ type = MED_REEL64; + + setValueType(type); + END_OF("Another constructor with arguments (for Python API) FIELDDOUBLE"); } //============================================================================= +/*! + * Copy constructor + */ +//============================================================================= +FIELDDOUBLE::FIELDDOUBLE(const FIELDDOUBLE & m) : + FIELD( (FIELD &) m) +{ + BEGIN_OF("Copy constructor (for Python API) FIELDDOUBLE"); + + END_OF("Copy constructor (for Python API) FIELDDOUBLE"); +} +//============================================================================= +/*! + * Copy constructor from a FIELD + */ +//============================================================================= +FIELDDOUBLE::FIELDDOUBLE(const FIELD & m) : + FIELD( m) +{ + BEGIN_OF("Copy constructor (for Python API) FIELDDOUBLE from a FIELD"); + + END_OF("Copy constructor (for Python API) FIELDDOUBLE from a FIELD"); +} +//============================================================================= /*! * Destructor */ diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.hxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.hxx index c4e0a5d8d..408f100a1 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.hxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldDouble.hxx @@ -1,29 +1,3 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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_SWIG_FieldDouble.hxx -// Module : MED - #ifndef MEDMEM_SWIG_FIELDDOUBLE_HXX_ #define MEDMEM_SWIG_FIELDDOUBLE_HXX_ @@ -35,7 +9,10 @@ public: FIELDDOUBLE(); FIELDDOUBLE(const SUPPORT * Support, const int NumberOfComponents); FIELDDOUBLE(const SUPPORT * Support, driverTypes driverType, - const string & fileName="", const string & fieldName=""); + const string & fileName="", const string & fieldName="", + const int iterationNumber=-1, const int orderNumber=-1); + FIELDDOUBLE(const FIELDDOUBLE & m); + FIELDDOUBLE(const FIELD & m); ~FIELDDOUBLE(); }; diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.cxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.cxx index 125948dbb..f2f002af1 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.cxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.cxx @@ -1,29 +1,3 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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_SWIG_FieldInt.cxx -// Module : MED - using namespace std; #include "MEDMEM_SWIG_FieldInt.hxx" @@ -59,15 +33,43 @@ FIELDINT::FIELDINT(const SUPPORT * Support, const int NumberOfComponents) : FIEL */ //============================================================================= FIELDINT::FIELDINT(const SUPPORT * Support, driverTypes driverType, - const string & fileName, - const string & fieldName) : - FIELD(Support, driverType, fileName, fieldName) + const string & fileName, const string & fieldName, + const int iterationNumber, const int orderNumber) : + FIELD(Support, driverType, fileName, fieldName, + iterationNumber, orderNumber) { BEGIN_OF("Another constructor with arguments (for Python API) FIELDINT"); + med_type_champ type = MED_INT32; + + setValueType(type); + END_OF("Another constructor with arguments (for Python API) FIELDINT"); } //============================================================================= +/*! + * Copy constructor + */ +//============================================================================= +FIELDINT::FIELDINT(const FIELDINT & m) : FIELD( (FIELD &) m) +{ + BEGIN_OF("Copy constructor (for Python API) FIELDINT"); + + END_OF("Copy constructor (for Python API) FIELDINT"); +} +//============================================================================= +/*! + * Copy constructor from a FIELD + */ +//============================================================================= +FIELDINT::FIELDINT(const FIELD & m) : + FIELD( m) +{ + BEGIN_OF("Copy constructor (for Python API) FIELDINT from a FIELD"); + + END_OF("Copy constructor (for Python API) FIELDINT from a FIELD"); +} +//============================================================================= /*! * Destructor */ diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.hxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.hxx index 1393c9b78..557066196 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.hxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_FieldInt.hxx @@ -1,29 +1,3 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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_SWIG_FieldInt.hxx -// Module : MED - #ifndef MEDMEM_SWIG_FIELDINT_HXX_ #define MEDMEM_SWIG_FIELDINT_HXX_ @@ -35,7 +9,10 @@ public: FIELDINT(); FIELDINT(const SUPPORT * Support, const int NumberOfComponents); FIELDINT(const SUPPORT * Support, driverTypes driverType, - const string & fileName="", const string & fieldName=""); + const string & fileName="", const string & fieldName="", + const int iterationNumber=-1, const int orderNumber=-1); + FIELDINT(const FIELDINT & m); + FIELDINT(const FIELD & m); ~FIELDINT(); }; diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldDoubleDriver.cxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldDoubleDriver.cxx index 69f1e777f..8b662aee8 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldDoubleDriver.cxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldDoubleDriver.cxx @@ -1,29 +1,3 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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_SWIG_MedFieldDoubleDriver.cxx -// Module : MED - using namespace std; #include "MEDMEM_SWIG_MedFieldDoubleDriver.hxx" diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldDoubleDriver.hxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldDoubleDriver.hxx index 8238c94e1..65e5d6573 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldDoubleDriver.hxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldDoubleDriver.hxx @@ -1,29 +1,3 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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_SWIG_MedFieldDoubleDriver.hxx -// Module : MED - #ifndef MEDMEM_SWIG_MEDFIELDDOUBLEDRIVER_HXX_ #define MEDMEM_SWIG_MEDFIELDDOUBLEDRIVER_HXX_ diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldIntDriver.cxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldIntDriver.cxx index 8639d925f..87b25165d 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldIntDriver.cxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldIntDriver.cxx @@ -1,29 +1,3 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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_SWIG_MedFieldIntDriver.cxx -// Module : MED - using namespace std; #include "MEDMEM_SWIG_MedFieldIntDriver.hxx" diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldIntDriver.hxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldIntDriver.hxx index 5ba830817..bb43c893f 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldIntDriver.hxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_MedFieldIntDriver.hxx @@ -1,29 +1,3 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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_SWIG_MedFieldIntDriver.hxx -// Module : MED - #ifndef MEDMEM_SWIG_MEDFIELDINTDRIVER_HXX_ #define MEDMEM_SWIG_MEDFIELDINTDRIVER_HXX_ diff --git a/src/MEDMEM_SWIG/libMEDMEM_Swig.i b/src/MEDMEM_SWIG/libMEDMEM_Swig.i index 480d3a9cc..2c1e9343e 100644 --- a/src/MEDMEM_SWIG/libMEDMEM_Swig.i +++ b/src/MEDMEM_SWIG/libMEDMEM_Swig.i @@ -1,32 +1,8 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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 : libMEDMEM_Swig.i -// Module : MED - %module libMEDMEM_Swig %{ +#include +#include #include "MEDMEM_CellModel.hxx" #include "MEDMEM_GenDriver.hxx" #include "MEDMEM_MedMeshDriver.hxx" @@ -66,7 +42,7 @@ { try { - $action ; + $action } catch(MEDEXCEPTION& exception) { @@ -86,6 +62,145 @@ %rename(assign) *::operator=; +/* + typemap for vector C++ object +*/ + +%typemap(python,in) vector, const vector +{ + /* typemap in for vector */ + /* Check if is a list */ + + if (PyList_Check($input)) { + int size = PyList_Size($input); + $1.resize(size); + + for (int i=0; i < size; i++) + { + PyObject * tmp = PyList_GetItem($input,i); + FAMILY * f; + + int err = SWIG_ConvertPtr(tmp, (void **) &f, $descriptor(FAMILY *), + SWIG_POINTER_EXCEPTION); + + if (err == -1) + { + char * message = "Error in typemap(python,in) for vector each component should be a FAMILY pointer"; + PyErr_SetString(PyExc_RuntimeError, message); + return NULL; + } + + $1[i] = f; + } + } + else + { + PyErr_SetString(PyExc_TypeError,"not a list"); + return NULL; + } +} + +%typemap(python,out) vector +{ + /* typemap out for vector */ + int size = $1.size(); + $result = PyList_New(size); + + for (int i=0;i C++ object +*/ + +%typemap(python,in) vector, const vector +{ + /* typemap in for vector */ + /* Check if is a list */ + + if (PyList_Check($input)) { + int size = PyList_Size($input); + $1.resize(size); + + for (int i=0; i < size; i++) + { + PyObject * tmp = PyList_GetItem($input,i); + SUPPORT * s; + + int err = SWIG_ConvertPtr(tmp, (void **) &s, $descriptor(SUPPORT *), + SWIG_POINTER_EXCEPTION); + + if (err == -1) + { + char * message = "Error in typemap(python,in) for vector each component should be a SUPPORT pointer"; + PyErr_SetString(PyExc_RuntimeError, message); + return NULL; + } + + $1[i] = s; + } + } + else + { + PyErr_SetString(PyExc_TypeError,"not a list"); + return NULL; + } +} + +%typemap(python,out) vector +{ + /* typemap out for vector */ + int size = $1.size(); + $result = PyList_New(size); + + for (int i=0;i getAllConstituentsType() const; */ - - -/* map getNumberOfConstituentsForeachType() const; */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ~CELLMODEL(); @@ -234,11 +286,9 @@ class CELLMODEL %newobject __str__(); const char* __str__() { - ostrstream line; - line << "Python Printing CELLMODEL : " << *self << endl; - char * tmp = new char[strlen(line.str())+1]; - strcpy(tmp,line.str()); - return tmp; + ostringstream mess; + mess << "Python Printing CELLMODEL : " << *self << endl; + return strdup(mess.str().c_str()); } } }; @@ -280,6 +330,8 @@ class SUPPORT void getBoundaryElements(); + void setNumber(const int * index, const int* value); + %extend { SUPPORT(MESH* Mesh, char * Name="", medEntityMesh Entity=MED_CELL) { @@ -289,11 +341,11 @@ class SUPPORT %newobject __str__(); const char* __str__() { - ostrstream line; - line << "Python Printing SUPPORT : " << *self << endl; - char * tmp = new char[strlen(line.str())+1]; - strcpy(tmp,line.str()); - return tmp; + ostringstream mess; + mess << "Python Printing SUPPORT : " << *self << endl; + char * tmp = const_cast (mess.str().c_str()); + char * returned = strdup(tmp); + return returned; } void setpartial(char * Description, int NumberOfGeometricType, @@ -352,6 +404,7 @@ class SUPPORT } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -375,6 +428,7 @@ class SUPPORT } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -398,6 +452,7 @@ class SUPPORT } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } } @@ -453,10 +508,9 @@ class FAMILY : public SUPPORT %newobject __str__(); const char* __str__() { - ostrstream line; - line << "Python Printing Family : " << *self << endl; - char * tmp = new char[strlen(line.str())+1]; - strcpy(tmp,line.str()); + ostringstream mess; + mess << "Python Printing Family : " << *self << endl; + return strdup(mess.str().c_str()); } %newobject getAttributeDescription(int ); @@ -497,6 +551,7 @@ class FAMILY : public SUPPORT } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -520,11 +575,15 @@ class FAMILY : public SUPPORT } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } } }; + + + class FIELD_ { public: @@ -555,6 +614,17 @@ public: void setNumberOfValues(int NumberOfValues); int getNumberOfValues() const; + string getName() const; + string getDescription() const; + string getComponentName(int i) const; + string getComponentDescription(int i) const; + string getMEDComponentUnit(int i) const; + void setName(string Name); + void setComponentName(int i, string ComponentName); + void setMEDComponentUnit(int i, string MEDComponentUnit); + void setDescription(string Description); + void setComponentDescription(int i, string ComponentDescription); + %extend { int addDriver(driverTypes driverType, char * fileName="Default File Name.med", @@ -564,78 +634,10 @@ public: string(driverName)); } - void setName(char * name) - { - self->setName(string(name)); - } - - %newobject getName(); - const char * getName() - { - string tmp_str = self->getName(); - char * tmp = new char[strlen(tmp_str.c_str())+1]; - strcpy(tmp,tmp_str.c_str()); - return tmp; - } - - void setDescription(char * Description) - { - self->setDescription(string(Description)); - } - - %newobject getDescription(); - const char * getDescription() const - { - string tmp_str = self->getDescription(); - char * tmp = new char[strlen(tmp_str.c_str())+1]; - strcpy(tmp,tmp_str.c_str()); - return tmp; - } - - %newobject getComponentName(int ); - const char * getComponentName(int i) - { - string tmp_str = self->getComponentName(i); - char * tmp = new char[strlen(tmp_str.c_str())+1]; - strcpy(tmp,tmp_str.c_str()); - return tmp; - } - - void setComponentName(int i, char * ComponentName) - { - self->setComponentName(i,string(ComponentName)); - } - - %newobject getComponentDescription(int ); - const char * getComponentDescription(int i) - { - string tmp_str = self->getComponentDescription(i); - char * tmp = new char[strlen(tmp_str.c_str())+1]; - strcpy(tmp,tmp_str.c_str()); - return tmp; - } - - void setComponentDescription(int i, char * ComponentDescription) - { - self->setComponentDescription(i,string(ComponentDescription)); - } - - %newobject getMEDComponentUnit(int ); - const char * getMEDComponentUnit(int i) - { - string tmp_str = self->getMEDComponentUnit(i); - char * tmp = new char[strlen(tmp_str.c_str())+1]; - strcpy(tmp,tmp_str.c_str()); - return tmp; - } - - void setMEDComponentUnit(int i, char * MEDComponentUnit) - { - self->setMEDComponentUnit(i,string(MEDComponentUnit)); - } } }; + class FIELDDOUBLE : public FIELD_ { public: @@ -653,6 +655,8 @@ public: FIELDDOUBLE(); + FIELDDOUBLE(const FIELDDOUBLE & m); + void read(int index=0); double getValueIJ(int i,int j) const; @@ -667,12 +671,83 @@ public: void deallocValue(); + void applyLin(double a, double n); + + double normMax(); + double norm2(); + double normL2(int component, const FIELDDOUBLE * p_field_volume=NULL) const; + double normL2(const FIELDDOUBLE * p_field_volume=NULL) const; + double normL1(int component, const FIELDDOUBLE * p_field_volume=NULL) const; + double normL1(const FIELDDOUBLE * p_field_volume=NULL) const; + + %extend { + PyObject * applyPyFunc( PyObject * func ) + { + MESSAGE("Appel de applyPyFunc"); + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "FIELDDOUBLE.applyPyFunc prend en argument une fonction"); + return NULL; + } + + int nComp=self->getNumberOfComponents(); + int nVal=self->getNumberOfValues(); + for (int i=1; i!=nVal+1; ++i) + for ( int j=1 ;j!=nComp+1 ;++j ) + { + self->setValueIJ(i,j,PyFloat_AsDouble (PyObject_CallFunction( func, "f", self->getValueIJ(i,j) ) ) ); + //cout << "value(" << i << "," << j << ") = " << self->getValueIJ(i,j) << " -> "; + //cout << PyFloat_AsDouble (PyObject_CallFunction( func, "f", self->getValueIJ(i,j) ) ) << endl; + } + PyObject * result = Py_BuildValue("d", nComp*nVal); + return result; + } + + %newobject __add__(const FIELDDOUBLE & ); + FIELDDOUBLE * __add__(const FIELDDOUBLE & m) + { + MESSAGE("operator + : Creation of the addition of two FIELDDOUBLEs"); + + FIELD* result = FIELD::add( *(FIELD*)self , (FIELD&)m ); + return (FIELDDOUBLE*) result; + +/* const FIELD result = (*(FIELD*)self) + + (FIELD&)m; + return new FIELDDOUBLE(result); */ + } + + %newobject __sub__(const FIELDDOUBLE & ); + FIELDDOUBLE * __sub__(const FIELDDOUBLE & m) + { + MESSAGE("operator - : Creation of the substraction of two FIELDDOUBLEs"); + FIELD* result = FIELD::sub( *(FIELD*)self , (FIELD&)m ); + return (FIELDDOUBLE*) result; + } + + %newobject __mul__(const FIELDDOUBLE & ); + FIELDDOUBLE * __mul__(const FIELDDOUBLE & m) + { + MESSAGE("operator * : Creation of the multiplication of two FIELDDOUBLEs"); + FIELD* result = FIELD::mul( *(FIELD*)self , (FIELD&)m ); + return (FIELDDOUBLE*) result; + } + + %newobject __div__(const FIELDDOUBLE & ); + FIELDDOUBLE * __div__(const FIELDDOUBLE & m) + { + MESSAGE("operator / : Creation of the division of two FIELDDOUBLEs"); + FIELD* result = FIELD::div( *(FIELD*)self , (FIELD&)m ); + return (FIELDDOUBLE*) result; + } + FIELDDOUBLE (const SUPPORT * Support, driverTypes driverType, - char * fileName, char * fieldName) + char * fileName, char * fieldName, + const int iterationNumber, + const int orderNumber) { return new FIELDDOUBLE(Support, driverType, string(fileName), - string(fieldName)); + string(fieldName),iterationNumber, + orderNumber); } void write(int index=0, char * driverName="") @@ -680,6 +755,11 @@ public: self->write(index, string(driverName)); } + void writeAppend(int index=0, char * driverName="") + { + self->writeAppend(index, string(driverName)); + } + PyObject * getValue(medModeSwitch Mode) { PyObject *py_list; @@ -702,6 +782,7 @@ public: } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -729,6 +810,7 @@ public: } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -757,6 +839,8 @@ public: FIELDINT(); + FIELDINT(const FIELDINT & m); + void read(int index=0); int getValueIJ(int i,int j) const; @@ -771,12 +855,74 @@ public: void deallocValue(); + void applyLin(int a, int n); + + double normMax(); + double norm2(); + double normL2(int component, const FIELDDOUBLE * p_field_volume=NULL) const; + double normL2(const FIELDDOUBLE * p_field_volume=NULL) const; + double normL1(int component, const FIELDDOUBLE * p_field_volume=NULL) const; + double normL1(const FIELDDOUBLE * p_field_volume=NULL) const; + + %extend { + + PyObject * applyPyFunc( PyObject * func ) + { + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "FIELDDOUBLE.applyPyFunc prend en argument une fonction"); + return NULL; + } + + int nComp=self->getNumberOfComponents(); + int nVal=self->getNumberOfValues(); + for (int i=1; i!=nVal+1; ++i) + for ( int j=1 ;j!=nComp+1 ;++j ) + self->setValueIJ(i,j,PyInt_AsLong (PyObject_CallFunction( func, "i", self->getValueIJ(i,j) ) ) ); + PyObject * result = Py_BuildValue("d", nComp*nVal); + return result; + } + + %newobject __add__(const FIELDINT & ); + FIELDINT * __add__(const FIELDINT & m) + { + MESSAGE("operator + : Creation of the addition of two FIELDINTs"); + FIELD* result = FIELD::add( *(FIELD*)self , (FIELD&)m ); + return (FIELDINT*) result; + } + + %newobject __sub__(const FIELDINT & ); + FIELDINT * __sub__(const FIELDINT & m) + { + MESSAGE("operator - : Creation of the substraction of two FIELDINTs"); + FIELD* result = FIELD::sub( *(FIELD*)self , (FIELD&)m ); + return (FIELDINT*) result; + } + + %newobject __mul__(const FIELDINT & ); + FIELDINT * __mul__(const FIELDINT & m) + { + MESSAGE("operator * : Creation of the multiplication of two FIELDINTs"); + FIELD* result = FIELD::mul( *(FIELD*)self , (FIELD&)m ); + return (FIELDINT*) result; + } + + %newobject __div__(const FIELDINT & ); + FIELDINT * __div__(const FIELDINT & m) + { + MESSAGE("operator / : Creation of the division of two FIELDINTs"); + FIELD* result = FIELD::div( *(FIELD*)self , (FIELD&)m ); + return (FIELDINT*) result; + } + FIELDINT(const SUPPORT * Support, driverTypes driverType, - char * fileName, char * fieldName) + char * fileName, char * fieldName, + const int iterationNumber, + const int orderNumber) { return new FIELDINT(Support, driverType, string(fileName), - string(fieldName)); + string(fieldName), iterationNumber, + orderNumber); } void write(int index=0, char * driverName="") @@ -784,6 +930,11 @@ public: self->write(index, string(driverName)); } + void writeAppend(int index=0, char * driverName="") + { + self->writeAppend(index, string(driverName)); + } + PyObject * getValue(medModeSwitch Mode) { PyObject *py_list; @@ -806,6 +957,7 @@ public: } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -832,6 +984,7 @@ public: } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -919,6 +1072,18 @@ public : return self->getSkin(Support3D); } + %newobject mergeSupports(const vector ); + SUPPORT * mergeSupports(const vector Supports) + { + return self->mergeSupports(Supports); + } + + %newobject intersectSupports(const vector ); + SUPPORT * intersectSupports(const vector Supports) + { + return self->intersectSupports(Supports); + } + CELLMODEL getCellType(medEntityMesh Entity,int i) { return self->getCellsTypes(Entity)[i]; @@ -965,6 +1130,14 @@ public : return tmp; } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MESH : " << *self << endl; + return strdup(mess.str().c_str()); + } + %newobject getCoordinateName(int ); const char * getCoordinateName(int i) { @@ -1001,6 +1174,7 @@ public : } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -1022,6 +1196,7 @@ public : } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -1043,6 +1218,7 @@ public : } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -1065,6 +1241,7 @@ public : } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -1101,6 +1278,7 @@ public : } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -1126,6 +1304,7 @@ public : } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -1167,6 +1346,7 @@ public : } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -1207,6 +1387,31 @@ public : } } PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); + return result; + } + + PyObject * getGlobalNumberingIndex(medEntityMesh Entity) + { + PyObject *py_list; + const int * numberingIndex = self->getGlobalNumberingIndex(Entity); + int nbOfTypes = self->getNumberOfTypes(Entity); + int size = nbOfTypes+1; + + py_list = PyList_New(size); + for (int i=0; i < size; i++) + { + int err = PyList_SetItem(py_list, i, + Py_BuildValue("i", numberingIndex[i])); + if(err) + { + char * message = "Error in MESH::getGlobalNumberingIndex"; + PyErr_SetString(PyExc_RuntimeError, message); + return NULL; + } + } + PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } @@ -1307,13 +1512,13 @@ class GRID : public MESH ~GRID(); - int getNodeNumber(const int i, const int j=0, const int k=0); + int getNodeNumber(const int i, const int j=0, const int k=0) const ; - int getCellNumber(const int i, const int j=0, const int k=0) ; + int getCellNumber(const int i, const int j=0, const int k=0) const ; - int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0); + int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) const ; - int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0); + int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) const ; med_grid_type getGridType(); @@ -1372,6 +1577,7 @@ class GRID : public MESH PyList_SetItem(py_list, 0, Py_BuildValue("i", Axis)); PyObject * result = Py_BuildValue("O", py_list); + Py_DECREF(py_list); return result; } } @@ -1394,6 +1600,10 @@ class MED void write (int index=0); + void addField ( FIELD_ * const ptrField ); + + void addMesh ( MESH * const ptrMesh ); + %extend { /* WARNING: @@ -1456,6 +1666,12 @@ class MED { return self->getField(string(fieldName),dt,it); } + + SUPPORT * getSupport(char * meshName, medEntityMesh entity) + { + return self->getSupport(string(meshName), + (MED_FR::med_entite_maillage) entity); + } } }; @@ -1479,6 +1695,14 @@ class MED_MED_RDONLY_DRIVER { return new MED_MED_RDONLY_DRIVER(string(fileName), ptrMed); } + + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_MED_RDONLY_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } } }; @@ -1498,6 +1722,14 @@ class MED_MED_WRONLY_DRIVER { return new MED_MED_WRONLY_DRIVER(string(fileName), ptrMed); } + + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_MED_WRONLY_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } } }; @@ -1520,6 +1752,14 @@ class MED_MED_RDWR_DRIVER : public virtual MED_MED_RDONLY_DRIVER, { return new MED_MED_RDWR_DRIVER(string(fileName), ptrMed); } + + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_MED_RDWR_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } } }; @@ -1547,6 +1787,14 @@ class MED_MESH_RDONLY_DRIVER return new MED_MESH_RDONLY_DRIVER(string(fileName), ptrMesh); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_MESH_RDONLY_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setMeshName(char * meshName) { self->setMeshName(string(meshName)); @@ -1582,6 +1830,14 @@ class MED_MESH_WRONLY_DRIVER return new MED_MESH_WRONLY_DRIVER(string(fileName), ptrMesh); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_MESH_WRONLY_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setMeshName(char * meshName) { self->setMeshName(string(meshName)); @@ -1619,6 +1875,14 @@ class MED_MESH_RDWR_DRIVER : public virtual MED_MESH_RDONLY_DRIVER, return new MED_MESH_RDWR_DRIVER(string(fileName), ptrMesh); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_MESH_RDWR_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setMeshName(char * meshName) { self->setMeshName(string(meshName)); @@ -1659,6 +1923,14 @@ public: return new MED_FIELDDOUBLE_RDONLY_DRIVER(string(fileName), ptrField); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_FIELDDOUBLE_RDONLY_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setFieldName(char * fieldName) { self->setFieldName(string(fieldName)); @@ -1695,6 +1967,14 @@ public: return new MED_FIELDDOUBLE_WRONLY_DRIVER(string(fileName), ptrField); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_FIELDDOUBLE_WRONLY_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setFieldName(char * fieldName) { self->setFieldName(string(fieldName)); @@ -1731,6 +2011,14 @@ public: return new MED_FIELDDOUBLE_RDWR_DRIVER(string(fileName), ptrField); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_FIELDDOUBLE_RDWR_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setFieldName(char * fieldName) { self->setFieldName(string(fieldName)); @@ -1771,6 +2059,14 @@ public: return new MED_FIELDINT_RDONLY_DRIVER(string(fileName), ptrField); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_FIELDINT_RDONLY_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setFieldName(char * fieldName) { self->setFieldName(string(fieldName)); @@ -1807,6 +2103,14 @@ public: return new MED_FIELDINT_WRONLY_DRIVER(string(fileName), ptrField); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_FIELDINT_WRONLY_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setFieldName(char * fieldName) { self->setFieldName(string(fieldName)); @@ -1843,6 +2147,14 @@ public: return new MED_FIELDINT_RDWR_DRIVER(string(fileName), ptrField); } + %newobject __str__(); + const char* __str__() + { + ostringstream mess; + mess << "Python Printing MED_FIELDINT_RDWR_DRIVER : " << *self << endl; + return strdup(mess.str().c_str()); + } + void setFieldName(char * fieldName) { self->setFieldName(string(fieldName)); @@ -1859,27 +2171,447 @@ public: } }; +%newobject createFieldDoubleScalarProduct(FIELDDOUBLE * field1, FIELDDOUBLE * field2) ; +FIELDDOUBLE * createFieldDoubleScalarProduct(FIELDDOUBLE * field1, FIELDDOUBLE * field2) ; + +%newobject createFieldIntScalarProduct(FIELDINT * field1, FIELDINT * field2) ; +FIELDINT * createFieldIntScalarProduct(FIELDINT * field1, FIELDINT * field2) ; + FIELDDOUBLE * createFieldDoubleFromField(FIELD_ * field) ; FIELDINT * createFieldIntFromField(FIELD_ * field) ; +%newobject createFieldDoubleFromAnalytic(SUPPORT * , int , PyObject *); +FIELDDOUBLE * createFieldDoubleFromAnalytic(SUPPORT * Support, + int NumberOfComponents, + PyObject * double_function) ; + +%newobject createFieldIntFromAnalytic(SUPPORT * , int , PyObject *); +FIELDINT * createFieldIntFromAnalytic(SUPPORT * Support, + int NumberOfComponents, + PyObject * integer_function) ; + GRID * createGridFromMesh( MESH * aMesh ); %{ + FIELDDOUBLE * createFieldDoubleScalarProduct(FIELDDOUBLE * field1, FIELDDOUBLE * field2) + { + return (FIELDDOUBLE *) FIELD::scalarProduct( (FIELD)*field1, (FIELD)*field2); + } + + FIELDINT * createFieldIntScalarProduct(FIELDINT * field1, FIELDINT * field2) + { + return (FIELDINT *) FIELD::scalarProduct( (FIELD)*field1, (FIELD)*field2); + } + FIELDDOUBLE * createFieldDoubleFromField(FIELD_ * field) { - MESSAGE("creatFieldDoubleFromField : Constructor (for Python API) FIELDDOUBLE with parameter FIELD_"); + MESSAGE("createFieldDoubleFromField : Constructor (for Python API) FIELDDOUBLE with parameter FIELD_"); MESSAGE("Its returns a proper cast of the input pointer :: FIELD_ --> FIELDDOUBLE"); return (FIELDDOUBLE *) field; } FIELDINT * createFieldIntFromField(FIELD_ * field) { - MESSAGE("creatFieldIntFromField : Constructor (for Python API) FIELDINT with parameter FIELD_"); + MESSAGE("createFieldIntFromField : Constructor (for Python API) FIELDINT with parameter FIELD_"); MESSAGE("Its returns a proper cast of the input pointer :: FIELD_ --> FIELDINT"); return (FIELDINT *) field; } + FIELDDOUBLE * createFieldDoubleFromAnalytic(SUPPORT * Support, + int NumberOfComponents, + PyObject * double_function) + { + MESSAGE("createFieldDoubleFromAnalytic : Constructor (for Python API) FIELDDOUBLE from an analytic fonction"); + + FIELDDOUBLE * fieldDouble = new FIELDDOUBLE(Support,NumberOfComponents); + + int NumberOfValues = fieldDouble->getNumberOfValues(); + double * values = new double[NumberOfValues*NumberOfComponents]; + + const double * x = (const double *) NULL; + const double * y = (const double *) NULL; + const double * z = (const double *) NULL; + + FIELD * barycenterField = (FIELD *) NULL; + + medEntityMesh entity = Support->getEntity(); + bool onAll = Support->isOnAllElements(); + + MESH * mesh = Support->getMesh(); + int spaceDim = mesh->getSpaceDimension(); + + if (entity == MED_NODE) + { + if (onAll) + { + const double * coord = mesh->getCoordinates(MED_NO_INTERLACE); + + x = coord; + y = coord+NumberOfValues; + if (spaceDim == 3) z = y+NumberOfValues; + } + else + { + const int * nodesNumber = Support->getNumber(MED_ALL_ELEMENTS); + const double * coord = mesh->getCoordinates(MED_FULL_INTERLACE); + + double * x_tmp = new double [NumberOfValues]; + double * y_tmp = new double [NumberOfValues]; + + for (int i=0; igetBarycenter(Support); + const double * barycenter = + barycenterField->getValue(MED_NO_INTERLACE); + + x = barycenter; + y = barycenter+NumberOfValues; + if (spaceDim == 3) z = y+NumberOfValues; + } + + for (int i=0; isetValue(MED_FULL_INTERLACE,values); + + delete [] values; + + if ((entity == MED_NODE) && (!onAll)) + { + delete [] x; + delete [] y; + + if (Support->getMesh()->getSpaceDimension() == 3) + delete [] z; + } + else if (entity != MED_NODE) delete barycenterField ; + + return fieldDouble; + } + + FIELDINT * createFieldIntFromAnalytic(SUPPORT * Support, + int NumberOfComponents, + PyObject * integer_function) + { + MESSAGE("createFieldIntFromAnalytic : Constructor (for Python API) FIELDINT from an analytic fonction"); + + FIELDINT * fieldInt = new FIELDINT(Support,NumberOfComponents); + + int NumberOfValues = fieldInt->getNumberOfValues(); + int * values = new int[NumberOfValues*NumberOfComponents]; + + const double * x = (const double *) NULL; + const double * y = (const double *) NULL; + const double * z = (const double *) NULL; + + FIELD * barycenterField = (FIELD *) NULL; + + medEntityMesh entity = Support->getEntity(); + bool onAll = Support->isOnAllElements(); + + MESH * mesh = Support->getMesh(); + int spaceDim = mesh->getSpaceDimension(); + + if (entity == MED_NODE) + { + if (onAll) + { + const double * coord = mesh->getCoordinates(MED_NO_INTERLACE); + + x = coord; + y = coord+NumberOfValues; + if (spaceDim == 3) z = y+NumberOfValues; + } + else + { + const int * nodesNumber = Support->getNumber(MED_ALL_ELEMENTS); + const double * coord = mesh->getCoordinates(MED_FULL_INTERLACE); + + double * x_tmp = new double [NumberOfValues]; + double * y_tmp = new double [NumberOfValues]; + + for (int i=0; igetBarycenter(Support); + const double * barycenter = + barycenterField->getValue(MED_NO_INTERLACE); + + x = barycenter; + y = barycenter+NumberOfValues; + if (spaceDim == 3) z = y+NumberOfValues; + } + + for (int i=0; isetValue(MED_FULL_INTERLACE,values); + + delete [] values; + + if ((entity == MED_NODE) && (!onAll)) + { + delete [] x; + delete [] y; + + if (Support->getMesh()->getSpaceDimension() == 3) + delete [] z; + } + else if (entity != MED_NODE) delete barycenterField ; + + return fieldInt; + } + GRID * createGridFromMesh( MESH * aMesh ) { MESSAGE("createGridFromMesh : Constructor (for Python API) GRID with parameter MESH *"); diff --git a/src/MEDMEM_SWIG/medMeshing_test.py b/src/MEDMEM_SWIG/medMeshing_test.py index dac89e76a..63090c50e 100644 --- a/src/MEDMEM_SWIG/medMeshing_test.py +++ b/src/MEDMEM_SWIG/medMeshing_test.py @@ -1,11 +1,11 @@ -# MED MEDMEM_SWIG : binding of C++ implementation and Python +################################################################################### # -# Copyright (C) 2003 CEA/DEN, EDF R&D +# This Python script uses the wrapped C++ class MESHING to buid a mesh from only +# primitive data like coordinates (Pythoin double array) and connectivity (Python +# integer arrays). It is the Python equivalent of the C++ program +# test_MEDMEM_Meshing.cxx in the ../MEDMEM directory of the SALOME distribution # -# -# -# File : medMeshing_test.py -# Module : MED +################################################################################### from libMEDMEM_Swig import * @@ -245,12 +245,399 @@ myMeshing.setConnectivity(connectivityHexa,entity,types[2]) # face part +numberOfTypes = 2 +entity = MED_FACE + +types = [] +numberOfElements = [] + +types.append(MED_TRIA3) +numberOfElements.append(4) + +types.append(MED_QUAD4) +numberOfElements.append(4) + +myMeshing.setNumberOfTypes(numberOfTypes,entity) +myMeshing.setTypes(types,entity) +myMeshing.setNumberOfElements(numberOfElements,entity) + +connectivityTria = [] +connectivity = [1,4,3] +connectivityTria.append(connectivity[0]) +connectivityTria.append(connectivity[1]) +connectivityTria.append(connectivity[2]) +connectivity = [1,5,4] +connectivityTria.append(connectivity[0]) +connectivityTria.append(connectivity[1]) +connectivityTria.append(connectivity[2]) +connectivity = [1,6,5] +connectivityTria.append(connectivity[0]) +connectivityTria.append(connectivity[1]) +connectivityTria.append(connectivity[2]) +connectivity = [1,3,6] +connectivityTria.append(connectivity[0]) +connectivityTria.append(connectivity[1]) +connectivityTria.append(connectivity[2]) + +myMeshing.setConnectivity(connectivityTria,entity,types[0]) + +connectivityQuad = [] +connectivity = [7,8,9,10] +connectivityQuad.append(connectivity[0]) +connectivityQuad.append(connectivity[1]) +connectivityQuad.append(connectivity[2]) +connectivityQuad.append(connectivity[3]) +connectivity = [11,12,13,14] +connectivityQuad.append(connectivity[0]) +connectivityQuad.append(connectivity[1]) +connectivityQuad.append(connectivity[2]) +connectivityQuad.append(connectivity[3]) +connectivity = [11,7,8,12] +connectivityQuad.append(connectivity[0]) +connectivityQuad.append(connectivity[1]) +connectivityQuad.append(connectivity[2]) +connectivityQuad.append(connectivity[3]) +connectivity = [12,8,9,13] +connectivityQuad.append(connectivity[0]) +connectivityQuad.append(connectivity[1]) +connectivityQuad.append(connectivity[2]) +connectivityQuad.append(connectivity[3]) + +myMeshing.setConnectivity(connectivityQuad,entity,types[1]) + # edge part # saving of the generated mesh in MED and VTK format +# adding GROUPs +# on Node + +myGroup = GROUP() +myGroup.setName("SomeNodes") +myGroup.setMesh(myMeshing) +myGroup.setEntity(MED_NODE) +myGroup.setNumberOfGeometricType(1) + +myTypes = [MED_NONE] +myGroup.setGeometricType(myTypes) + +myNumberOfElements = [4] +myGroup.setNumberOfElements(myNumberOfElements) + +index = [1,5] +values = [1,4,5,7] +myGroup.setNumber(index,values) + +myMeshing.addGroup(myGroup) + +myGroup = GROUP() +myGroup.setName("OtherNodes") +myGroup.setMesh(myMeshing) +myGroup.setEntity(MED_NODE) +myGroup.setNumberOfGeometricType(1) + +myTypes = [MED_NONE] +myGroup.setGeometricType(myTypes) + +myNumberOfElements = [3] +myGroup.setNumberOfElements(myNumberOfElements) + +index = [1,4] +values = [2,3,6] +myGroup.setNumber(index,values) + +myMeshing.addGroup(myGroup) + +# on Cell + +myGroup = GROUP() +myGroup.setName("SomeCells") +myGroup.setMesh(myMeshing) +myGroup.setEntity(MED_CELL) +myGroup.setNumberOfGeometricType(3) + +myTypes = [MED_TETRA4,MED_PYRA5,MED_HEXA8] +myGroup.setGeometricType(myTypes) + +myNumberOfElements = [4,1,2] +myGroup.setNumberOfElements(myNumberOfElements) + +index = [1,5,6,8] +values = [ + 2,7,8,12, + 13, + 15,16 + ] +myGroup.setNumber(index,values) + +myMeshing.addGroup(myGroup) + +myGroup = GROUP() +myGroup.setName("OtherCells") +myGroup.setMesh(myMeshing) +myGroup.setEntity(MED_CELL) +myGroup.setNumberOfGeometricType(2) + +myTypes = [MED_TETRA4,MED_PYRA5] +myGroup.setGeometricType(myTypes) + +myNumberOfElements = [4,1] +myGroup.setNumberOfElements(myNumberOfElements) + +index = [1,5,6] +values = [ + 3,4,5,9, + 14 + ] +myGroup.setNumber(index,values) + +myMeshing.addGroup(myGroup) + +# on Face + +myGroup = GROUP() +myGroup.setName("SomeFaces") +myGroup.setMesh(myMeshing) +myGroup.setEntity(MED_FACE) +myGroup.setNumberOfGeometricType(2) + +myTypes = [MED_TRIA3,MED_QUAD4] +myGroup.setGeometricType(myTypes) + +myNumberOfElements = [2,3] +myGroup.setNumberOfElements(myNumberOfElements) + +index = [1,3,6] +values = [ + 2,4, + 5,6,8 + ] +myGroup.setNumber(index,values) + +myMeshing.addGroup(myGroup) + +myGroup = GROUP() +myGroup.setName("OtherFaces") +myGroup.setMesh(myMeshing) +myGroup.setEntity(MED_FACE) +myGroup.setNumberOfGeometricType(1) + +myTypes = [MED_TRIA3] +myGroup.setGeometricType(myTypes) + +myNumberOfElements = [2] +myGroup.setNumberOfElements(myNumberOfElements) + +index = [1,3] +values = [ + 1,3 + ] +myGroup.setNumber(index,values) + +myMeshing.addGroup(myGroup) + idMed = myMeshing.addDriver(MED_DRIVER,medFileName,myMeshing.getName()) myMeshing.write(idMed) -idVtk = myMeshing.addDriver(MED_DRIVER,vtkFileName,myMeshing.getName()) +idVtk = myMeshing.addDriver(VTK_DRIVER,vtkFileName,myMeshing.getName()) myMeshing.write(idVtk) + +# we build now 8 fields : 4 fields double (integer) : +# 2 fields on nodes (cells) : +# 1 scalar (vector) + +supportOnNodes = SUPPORT(myMeshing,"On_All_Nodes",MED_NODE) +numberOfNodes = supportOnNodes.getNumberOfElements(MED_ALL_ELEMENTS) + +supportOnCells = SUPPORT(myMeshing,"On_All_Cells",MED_CELL) +numberOfCells = supportOnCells.getNumberOfElements(MED_ALL_ELEMENTS) + +fieldDoubleScalarOnNodes = FIELDDOUBLE(supportOnNodes,1) +fieldDoubleScalarOnNodes.setName("fieldScalarDoubleNode") +fieldDoubleScalarOnNodes.setIterationNumber(-1) +fieldDoubleScalarOnNodes.setOrderNumber(-1) +fieldDoubleScalarOnNodes.setTime(0.0) + +fieldDoubleScalarOnNodes.setComponentName(1,"Vx") +fieldDoubleScalarOnNodes.setComponentDescription(1,"comp1") +fieldDoubleScalarOnNodes.setMEDComponentUnit(1,"unit1") + +fieldDoubleVectorOnNodes = FIELDDOUBLE(supportOnNodes,spaceDimension) +fieldDoubleVectorOnNodes.setName("fieldVectorDoubleNode") +fieldDoubleVectorOnNodes.setIterationNumber(-1) +fieldDoubleVectorOnNodes.setOrderNumber(-1) +fieldDoubleVectorOnNodes.setTime(0.0) + +fieldDoubleVectorOnNodes.setComponentName(1,"Vx") +fieldDoubleVectorOnNodes.setComponentDescription(1,"comp1") +fieldDoubleVectorOnNodes.setMEDComponentUnit(1,"unit1") +fieldDoubleVectorOnNodes.setComponentName(2,"Vy") +fieldDoubleVectorOnNodes.setComponentDescription(2,"comp2") +fieldDoubleVectorOnNodes.setMEDComponentUnit(2,"unit2") +fieldDoubleVectorOnNodes.setComponentName(3,"Vz") +fieldDoubleVectorOnNodes.setComponentDescription(3,"comp3") +fieldDoubleVectorOnNodes.setMEDComponentUnit(3,"unit3") + +fieldDoubleScalarOnCells = FIELDDOUBLE(supportOnCells,1) +fieldDoubleScalarOnCells.setName("fieldScalarDoubleCell") +fieldDoubleScalarOnCells.setIterationNumber(-1) +fieldDoubleScalarOnCells.setOrderNumber(-1) +fieldDoubleScalarOnCells.setTime(0.0) + +fieldDoubleScalarOnCells.setComponentName(1,"Vx") +fieldDoubleScalarOnCells.setComponentDescription(1,"comp1") +fieldDoubleScalarOnCells.setMEDComponentUnit(1,"unit1") + +fieldDoubleVectorOnCells = FIELDDOUBLE(supportOnCells,spaceDimension) +fieldDoubleVectorOnCells.setName("fieldVectorrDoubleCell") +fieldDoubleVectorOnCells.setIterationNumber(-1) +fieldDoubleVectorOnCells.setOrderNumber(-1) +fieldDoubleVectorOnCells.setTime(0.0) + +fieldDoubleVectorOnCells.setComponentName(1,"Vx") +fieldDoubleVectorOnCells.setComponentDescription(1,"comp1") +fieldDoubleVectorOnCells.setMEDComponentUnit(1,"unit1") +fieldDoubleVectorOnCells.setComponentName(2,"Vy") +fieldDoubleVectorOnCells.setComponentDescription(2,"comp2") +fieldDoubleVectorOnCells.setMEDComponentUnit(2,"unit2") +fieldDoubleVectorOnCells.setComponentName(3,"Vz") +fieldDoubleVectorOnCells.setComponentDescription(3,"comp3") +fieldDoubleVectorOnCells.setMEDComponentUnit(3,"unit3") + +fieldIntScalarOnNodes = FIELDINT(supportOnNodes,1) +fieldIntScalarOnNodes.setName("fieldScalarIntNode") +fieldIntScalarOnNodes.setIterationNumber(-1) +fieldIntScalarOnNodes.setOrderNumber(-1) +fieldIntScalarOnNodes.setTime(0.0) + +fieldIntScalarOnNodes.setComponentName(1,"Vx") +fieldIntScalarOnNodes.setComponentDescription(1,"comp1") +fieldIntScalarOnNodes.setMEDComponentUnit(1,"unit1") + +fieldIntVectorOnNodes = FIELDINT(supportOnNodes,spaceDimension) +fieldIntVectorOnNodes.setName("fieldVectorIntNode") +fieldIntVectorOnNodes.setIterationNumber(-1) +fieldIntVectorOnNodes.setOrderNumber(-1) +fieldIntVectorOnNodes.setTime(0.0) + +fieldIntVectorOnNodes.setComponentName(1,"Vx") +fieldIntVectorOnNodes.setComponentDescription(1,"comp1") +fieldIntVectorOnNodes.setMEDComponentUnit(1,"unit1") +fieldIntVectorOnNodes.setComponentName(2,"Vy") +fieldIntVectorOnNodes.setComponentDescription(2,"comp2") +fieldIntVectorOnNodes.setMEDComponentUnit(2,"unit2") +fieldIntVectorOnNodes.setComponentName(3,"Vz") +fieldIntVectorOnNodes.setComponentDescription(3,"comp3") +fieldIntVectorOnNodes.setMEDComponentUnit(3,"unit3") + +fieldIntScalarOnCells = FIELDINT(supportOnCells,1) +fieldIntScalarOnCells.setName("fieldScalarIntCell") +fieldIntScalarOnCells.setIterationNumber(-1) +fieldIntScalarOnCells.setOrderNumber(-1) +fieldIntScalarOnCells.setTime(0.0) + +fieldIntScalarOnCells.setComponentName(1,"Vx") +fieldIntScalarOnCells.setComponentDescription(1,"comp1") +fieldIntScalarOnCells.setMEDComponentUnit(1,"unit1") + +fieldIntVectorOnCells = FIELDINT(supportOnCells,spaceDimension) +fieldIntVectorOnCells.setName("fieldVectorrIntCell") +fieldIntVectorOnCells.setIterationNumber(-1) +fieldIntVectorOnCells.setOrderNumber(-1) +fieldIntVectorOnCells.setTime(0.0) + +fieldIntVectorOnCells.setComponentName(1,"Vx") +fieldIntVectorOnCells.setComponentDescription(1,"comp1") +fieldIntVectorOnCells.setMEDComponentUnit(1,"unit1") +fieldIntVectorOnCells.setComponentName(2,"Vy") +fieldIntVectorOnCells.setComponentDescription(2,"comp2") +fieldIntVectorOnCells.setMEDComponentUnit(2,"unit2") +fieldIntVectorOnCells.setComponentName(3,"Vz") +fieldIntVectorOnCells.setComponentDescription(3,"comp3") +fieldIntVectorOnCells.setMEDComponentUnit(3,"unit3") + +for i in range(numberOfNodes): + valueInt1 = i+1 + valueInt2 = i+2 + valueInt3 = i+3 + valueDbl1 = valueInt1*0.1 + valueDbl2 = valueInt2*0.1 + valueDbl3 = valueInt3*0.1 + fieldDoubleScalarOnNodes.setValueIJ(i+1,1,valueDbl1) + + fieldIntScalarOnNodes.setValueIJ(i+1,1,valueInt1) + + fieldDoubleVectorOnNodes.setValueIJ(i+1,1,valueDbl1) + fieldDoubleVectorOnNodes.setValueIJ(i+1,2,valueDbl2) + fieldDoubleVectorOnNodes.setValueIJ(i+1,3,valueDbl3) + + fieldIntVectorOnNodes.setValueIJ(i+1,1,valueInt1) + fieldIntVectorOnNodes.setValueIJ(i+1,2,valueInt2) + fieldIntVectorOnNodes.setValueIJ(i+1,3,valueInt3) + +for i in range(numberOfCells): + valueInt1 = i+1 + valueInt2 = i+2 + valueInt3 = i+3 + valueDbl1 = valueInt1*0.1 + valueDbl2 = valueInt2*0.1 + valueDbl3 = valueInt3*0.1 + fieldDoubleScalarOnCells.setValueIJ(i+1,1,valueDbl1) + + fieldIntScalarOnCells.setValueIJ(i+1,1,valueInt1) + + fieldDoubleVectorOnCells.setValueIJ(i+1,1,valueDbl1) + fieldDoubleVectorOnCells.setValueIJ(i+1,2,valueDbl2) + fieldDoubleVectorOnCells.setValueIJ(i+1,3,valueDbl3) + + fieldIntVectorOnCells.setValueIJ(i+1,1,valueInt1) + fieldIntVectorOnCells.setValueIJ(i+1,2,valueInt2) + fieldIntVectorOnCells.setValueIJ(i+1,3,valueInt3) + +idMed = fieldDoubleScalarOnNodes.addDriver(MED_DRIVER,medFileName,fieldDoubleScalarOnNodes.getName()) +fieldDoubleScalarOnNodes.write(idMed) + +idMed = fieldIntScalarOnNodes.addDriver(MED_DRIVER,medFileName,fieldIntScalarOnNodes.getName()) +fieldIntScalarOnNodes.write(idMed) + +idMed = fieldDoubleVectorOnNodes.addDriver(MED_DRIVER,medFileName,fieldDoubleVectorOnNodes.getName()) +fieldDoubleVectorOnNodes.write(idMed) + +idMed = fieldIntVectorOnNodes.addDriver(MED_DRIVER,medFileName,fieldIntVectorOnNodes.getName()) +fieldIntVectorOnNodes.write(idMed) + +idMed = fieldDoubleScalarOnCells.addDriver(MED_DRIVER,medFileName,fieldDoubleScalarOnCells.getName()) +fieldDoubleScalarOnCells.write(idMed) + +idMed = fieldIntScalarOnCells.addDriver(MED_DRIVER,medFileName,fieldIntScalarOnCells.getName()) +fieldIntScalarOnCells.write(idMed) + +idMed = fieldDoubleVectorOnCells.addDriver(MED_DRIVER,medFileName,fieldDoubleVectorOnCells.getName()) +fieldDoubleVectorOnCells.write(idMed) + +idMed = fieldIntVectorOnCells.addDriver(MED_DRIVER,medFileName,fieldIntVectorOnCells.getName()) +fieldIntVectorOnCells.write(idMed) + +idVtk = fieldDoubleScalarOnNodes.addDriver(VTK_DRIVER,vtkFileName,fieldDoubleScalarOnNodes.getName()) +fieldDoubleScalarOnNodes.writeAppend(idVtk) + +idVtk = fieldIntScalarOnNodes.addDriver(VTK_DRIVER,vtkFileName,fieldIntScalarOnNodes.getName()) +fieldIntScalarOnNodes.writeAppend(idVtk) + +idVtk = fieldDoubleVectorOnNodes.addDriver(VTK_DRIVER,vtkFileName,fieldDoubleVectorOnNodes.getName()) +fieldDoubleVectorOnNodes.writeAppend(idVtk) + +idVtk = fieldIntVectorOnNodes.addDriver(VTK_DRIVER,vtkFileName,fieldIntVectorOnNodes.getName()) +fieldIntVectorOnNodes.writeAppend(idVtk) + +idVtk = fieldDoubleScalarOnCells.addDriver(VTK_DRIVER,vtkFileName,fieldDoubleScalarOnCells.getName()) +fieldDoubleScalarOnCells.writeAppend(idVtk) + +idVtk = fieldIntScalarOnCells.addDriver(VTK_DRIVER,vtkFileName,fieldIntScalarOnCells.getName()) +fieldIntScalarOnCells.writeAppend(idVtk) + +idVtk = fieldDoubleVectorOnCells.addDriver(VTK_DRIVER,vtkFileName,fieldDoubleVectorOnCells.getName()) +fieldDoubleVectorOnCells.writeAppend(idVtk) + +idVtk = fieldIntVectorOnCells.addDriver(VTK_DRIVER,vtkFileName,fieldIntVectorOnCells.getName()) +fieldIntVectorOnCells.writeAppend(idVtk) diff --git a/src/MEDMEM_SWIG/med_field_anal.py b/src/MEDMEM_SWIG/med_field_anal.py new file mode 100755 index 000000000..b250f1577 --- /dev/null +++ b/src/MEDMEM_SWIG/med_field_anal.py @@ -0,0 +1,568 @@ +############################################################################ +# +# This Python script is testing the generation of MED field using a +# user-callable function with different number of components and +# different SUPPORTs. +# +############################################################################ + +from math import * + +def f_scal_dbl_2d(x, y): + ret = [] + ret.append(x + y) + return ret + +def f_scal_dbl_3d(x, y, z): + ret = [] + ret.append(x + y + z) + return ret + +def f_vect_dbl_2d(x, y): + ret = [] + ret.append(x + y) + ret.append(2.*(x + y)) + return ret + +def f_vect_dbl_3d(x, y, z): + ret = [] + ret.append(x + y + z) + ret.append(2.*(x + y + z)) + ret.append(3.*(x + y + z)) + return ret + +def f_scal_int_2d(x, y): + ret = [] + ret_tmp = x + y + ret_tmp = int(ret_tmp) + ret.append(ret_tmp) + return ret + +def f_scal_int_3d(x, y, z): + ret = [] + ret_tmp = x + y + z + ret_tmp = int(ret_tmp) + ret.append(ret_tmp) + return ret + +def f_vect_int_2d(x, y): + ret = [] + ret.append(int(x + y)) + ret.append(int(2.*(x + y))) + return ret + +def f_vect_int_3d(x, y, z): + ret = [] + ret.append(int(x + y + z)) + ret.append(int(2.*(x + y + z))) + ret.append(int(3.*(x + y + z))) + return ret + +from libMEDMEM_Swig import * +from random import * + +medFile = "carre_en_quad4_seg2.med" +medFile = "cube_hexa8_quad4.med" + +def print_ord(i): + if i == 0: + return 'first' + elif i == 1: + return 'second' + elif i == 2: + return 'third' + else: + return `i`+'th' + +md = MED() + +mdDriver = MED_MED_RDONLY_DRIVER(medFile,md) + +mdDriver.open() +mdDriver.readFileStruct() +mdDriver.close() + +nbMeshes = md.getNumberOfMeshes() + +print "The med file", medFile, "contains", nbMeshes, "mesh(es)" + +mesh_name = md.getMeshName(0) +mesh = md.getMesh(mesh_name) +mesh.read() +spaceDim = mesh.getSpaceDimension() +meshDim = mesh.getMeshDimension() +nbNodes = mesh.getNumberOfNodes() + +print "" +print "The mesh",mesh_name,"is a",spaceDim,"D mesh on a",meshDim,"D geometry and has",nbNodes,"Nodes" + +print "" +print "Updating supports in the Med Object" +md.updateSupport() + +supportOnCell = md.getSupport(mesh_name,MED_CELL) + +supportOnNode = md.getSupport(mesh_name,MED_NODE) + +if (spaceDim == 3) : + supportOnConst = md.getSupport(mesh_name,MED_FACE) +elif (spaceDim == 2) : + supportOnConst = md.getSupport(mesh_name,MED_EDGE) + +##print "" +##print supportOnCell + +if (spaceDim == 2) : + fieldDoubleScalOnCell = createFieldDoubleFromAnalytic(supportOnCell,1, + f_scal_dbl_2d) + fieldDoubleVectOnCell = createFieldDoubleFromAnalytic(supportOnCell, + spaceDim, + f_vect_dbl_2d) + fieldIntScalOnCell = createFieldIntFromAnalytic(supportOnCell,1, + f_scal_int_2d) + fieldIntVectOnCell = createFieldIntFromAnalytic(supportOnCell,spaceDim, + f_vect_int_2d) +elif (spaceDim == 3) : + fieldDoubleScalOnCell = createFieldDoubleFromAnalytic(supportOnCell,1, + f_scal_dbl_3d) + fieldDoubleVectOnCell = createFieldDoubleFromAnalytic(supportOnCell, + spaceDim, + f_vect_dbl_3d) + fieldIntScalOnCell = createFieldIntFromAnalytic(supportOnCell,1, + f_scal_int_3d) + fieldIntVectOnCell = createFieldIntFromAnalytic(supportOnCell,spaceDim, + f_vect_int_3d) + +fieldDoubleScalOnCell.setName("Scalar Double Field on all Cells") +fieldDoubleScalOnCell.setDescription("Generated via a Python function") + +fieldDoubleVectOnCell.setName("Vector Double Field on all Cells") +fieldDoubleVectOnCell.setDescription("Generated via a Python function") + +fieldIntScalOnCell.setName("Scalar Integer Field on all Cells") +fieldIntScalOnCell.setDescription("Generated via a Python function") + +fieldIntVectOnCell.setName("Vector Integer Field on all Cells") +fieldIntVectOnCell.setDescription("Generated via a Python function") + +name = fieldDoubleScalOnCell.getName() +desc = fieldDoubleScalOnCell.getDescription() +nbOfComp = fieldDoubleScalOnCell.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldDoubleScalOnCell.getIterationNumber() +orderNb = fieldDoubleScalOnCell.getOrderNumber() +time = fieldDoubleScalOnCell.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldDoubleScalOnCell.getComponentName(kp1) + compDesc = fieldDoubleScalOnCell.getComponentDescription(kp1) + compUnit = fieldDoubleScalOnCell.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldDoubleScalOnCell.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldDoubleScalOnCell.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldDoubleVectOnCell.getName() +desc = fieldDoubleVectOnCell.getDescription() +nbOfComp = fieldDoubleVectOnCell.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldDoubleVectOnCell.getIterationNumber() +orderNb = fieldDoubleVectOnCell.getOrderNumber() +time = fieldDoubleVectOnCell.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldDoubleVectOnCell.getComponentName(kp1) + compDesc = fieldDoubleVectOnCell.getComponentDescription(kp1) + compUnit = fieldDoubleVectOnCell.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldDoubleVectOnCell.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldDoubleVectOnCell.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldIntScalOnCell.getName() +desc = fieldIntScalOnCell.getDescription() +nbOfComp = fieldIntScalOnCell.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldIntScalOnCell.getIterationNumber() +orderNb = fieldIntScalOnCell.getOrderNumber() +time = fieldIntScalOnCell.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldIntScalOnCell.getComponentName(kp1) + compDesc = fieldIntScalOnCell.getComponentDescription(kp1) + compUnit = fieldIntScalOnCell.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldIntScalOnCell.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldIntScalOnCell.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldIntVectOnCell.getName() +desc = fieldIntVectOnCell.getDescription() +nbOfComp = fieldIntVectOnCell.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldIntVectOnCell.getIterationNumber() +orderNb = fieldIntVectOnCell.getOrderNumber() +time = fieldIntVectOnCell.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldIntVectOnCell.getComponentName(kp1) + compDesc = fieldIntVectOnCell.getComponentDescription(kp1) + compUnit = fieldIntVectOnCell.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldIntVectOnCell.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldIntVectOnCell.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +##print "" +##print supportOnNode + +if (spaceDim == 2) : + fieldDoubleScalOnNode = createFieldDoubleFromAnalytic(supportOnNode,1, + f_scal_dbl_2d) + fieldDoubleVectOnNode = createFieldDoubleFromAnalytic(supportOnNode, + spaceDim, + f_vect_dbl_2d) + fieldIntScalOnNode = createFieldIntFromAnalytic(supportOnNode,1, + f_scal_int_2d) + fieldIntVectOnNode = createFieldIntFromAnalytic(supportOnNode, spaceDim, + f_vect_int_2d) +elif (spaceDim == 3) : + fieldDoubleScalOnNode = createFieldDoubleFromAnalytic(supportOnNode,1, + f_scal_dbl_3d) + fieldDoubleVectOnNode = createFieldDoubleFromAnalytic(supportOnNode, + spaceDim, + f_vect_dbl_3d) + fieldIntScalOnNode = createFieldIntFromAnalytic(supportOnNode,1, + f_scal_int_3d) + fieldIntVectOnNode = createFieldIntFromAnalytic(supportOnNode, spaceDim, + f_vect_int_3d) + +fieldDoubleScalOnNode.setName("Scalar Double Field on all Nodes") +fieldDoubleScalOnNode.setDescription("Generated via a Python function") + +fieldDoubleVectOnNode.setName("Vector Double Field on all Nodes") +fieldDoubleVectOnNode.setDescription("Generated via a Python function") + +fieldIntScalOnNode.setName("Scalar Integer Field on all Nodes") +fieldIntScalOnNode.setDescription("Generated via a Python function") + +fieldIntVectOnNode.setName("Vector Integer Field on all Nodes") +fieldIntVectOnNode.setDescription("Generated via a Python function") + +print "" +name = fieldDoubleScalOnNode.getName() +desc = fieldDoubleScalOnNode.getDescription() +nbOfComp = fieldDoubleScalOnNode.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldDoubleScalOnNode.getIterationNumber() +orderNb = fieldDoubleScalOnNode.getOrderNumber() +time = fieldDoubleScalOnNode.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldDoubleScalOnNode.getComponentName(kp1) + compDesc = fieldDoubleScalOnNode.getComponentDescription(kp1) + compUnit = fieldDoubleScalOnNode.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldDoubleScalOnNode.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldDoubleScalOnNode.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldDoubleVectOnNode.getName() +desc = fieldDoubleVectOnNode.getDescription() +nbOfComp = fieldDoubleVectOnNode.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldDoubleVectOnNode.getIterationNumber() +orderNb = fieldDoubleVectOnNode.getOrderNumber() +time = fieldDoubleVectOnNode.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldDoubleVectOnNode.getComponentName(kp1) + compDesc = fieldDoubleVectOnNode.getComponentDescription(kp1) + compUnit = fieldDoubleVectOnNode.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldDoubleVectOnNode.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldDoubleVectOnNode.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldIntScalOnNode.getName() +desc = fieldIntScalOnNode.getDescription() +nbOfComp = fieldIntScalOnNode.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldIntScalOnNode.getIterationNumber() +orderNb = fieldIntScalOnNode.getOrderNumber() +time = fieldIntScalOnNode.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldIntScalOnNode.getComponentName(kp1) + compDesc = fieldIntScalOnNode.getComponentDescription(kp1) + compUnit = fieldIntScalOnNode.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldIntScalOnNode.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldIntScalOnNode.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldIntVectOnNode.getName() +desc = fieldIntVectOnNode.getDescription() +nbOfComp = fieldIntVectOnNode.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldIntVectOnNode.getIterationNumber() +orderNb = fieldIntVectOnNode.getOrderNumber() +time = fieldIntVectOnNode.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldIntVectOnNode.getComponentName(kp1) + compDesc = fieldIntVectOnNode.getComponentDescription(kp1) + compUnit = fieldIntVectOnNode.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldIntVectOnNode.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldIntVectOnNode.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +##print "" +##print supportOnConst + +if (spaceDim == 2) : + fieldDoubleScalOnConst = createFieldDoubleFromAnalytic(supportOnConst,1, + f_scal_dbl_2d) + fieldDoubleVectOnConst = createFieldDoubleFromAnalytic(supportOnConst, + spaceDim, + f_vect_dbl_2d) + fieldIntScalOnConst = createFieldIntFromAnalytic(supportOnConst,1, + f_scal_int_2d) + fieldIntVectOnConst = createFieldIntFromAnalytic(supportOnConst, spaceDim, + f_vect_int_2d) +elif (spaceDim == 3) : + fieldDoubleScalOnConst = createFieldDoubleFromAnalytic(supportOnConst,1, + f_scal_dbl_3d) + fieldDoubleVectOnConst = createFieldDoubleFromAnalytic(supportOnConst, + spaceDim, + f_vect_dbl_3d) + fieldIntScalOnConst = createFieldIntFromAnalytic(supportOnConst,1, + f_scal_int_3d) + fieldIntVectOnConst = createFieldIntFromAnalytic(supportOnConst, spaceDim, + f_vect_int_3d) + +fieldDoubleScalOnConst.setName("Scalar Double Field on all Faces/Edges") +fieldDoubleScalOnConst.setDescription("Generated via a Python function") + +fieldDoubleVectOnConst.setName("Vector Double Field on all Faces/Edges") +fieldDoubleVectOnConst.setDescription("Generated via a Python function") + +fieldIntScalOnConst.setName("Scalar Integer Field on all Faces/Edges") +fieldIntScalOnConst.setDescription("Generated via a Python function") + +fieldIntVectOnConst.setName("Vector Integer Field on all Faces/Edges") +fieldIntVectOnConst.setDescription("Generated via a Python function") + +print "" +name = fieldDoubleScalOnConst.getName() +desc = fieldDoubleScalOnConst.getDescription() +nbOfComp = fieldDoubleScalOnConst.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldDoubleScalOnConst.getIterationNumber() +orderNb = fieldDoubleScalOnConst.getOrderNumber() +time = fieldDoubleScalOnConst.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldDoubleScalOnConst.getComponentName(kp1) + compDesc = fieldDoubleScalOnConst.getComponentDescription(kp1) + compUnit = fieldDoubleScalOnConst.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldDoubleScalOnConst.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldDoubleScalOnConst.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldDoubleVectOnConst.getName() +desc = fieldDoubleVectOnConst.getDescription() +nbOfComp = fieldDoubleVectOnConst.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldDoubleVectOnConst.getIterationNumber() +orderNb = fieldDoubleVectOnConst.getOrderNumber() +time = fieldDoubleVectOnConst.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldDoubleVectOnConst.getComponentName(kp1) + compDesc = fieldDoubleVectOnConst.getComponentDescription(kp1) + compUnit = fieldDoubleVectOnConst.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldDoubleVectOnConst.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldDoubleVectOnConst.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldIntScalOnConst.getName() +desc = fieldIntScalOnConst.getDescription() +nbOfComp = fieldIntScalOnConst.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldIntScalOnConst.getIterationNumber() +orderNb = fieldIntScalOnConst.getOrderNumber() +time = fieldIntScalOnConst.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldIntScalOnConst.getComponentName(kp1) + compDesc = fieldIntScalOnConst.getComponentDescription(kp1) + compUnit = fieldIntScalOnConst.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldIntScalOnConst.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldIntScalOnConst.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +name = fieldIntVectOnConst.getName() +desc = fieldIntVectOnConst.getDescription() +nbOfComp = fieldIntVectOnConst.getNumberOfComponents() +print " Field",name," : ",desc +print " Number Of Components:",nbOfComp +iterationNb = fieldIntVectOnConst.getIterationNumber() +orderNb = fieldIntVectOnConst.getOrderNumber() +time = fieldIntVectOnConst.getTime() +print " Iteration Number",iterationNb +print " Order Number",orderNb +print " Time",time +for k in range(nbOfComp): + kp1 = k+1 + compName = fieldIntVectOnConst.getComponentName(kp1) + compDesc = fieldIntVectOnConst.getComponentDescription(kp1) + compUnit = fieldIntVectOnConst.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + +support = fieldIntVectOnConst.getSupport() +nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) +print " Values:",nbOf +for k in range(nbOf): + valueI = fieldIntVectOnConst.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + +print "" +print "END of the Pyhton script ..... Ctrl D to exit" diff --git a/src/MEDMEM_SWIG/med_opfield_test.py b/src/MEDMEM_SWIG/med_opfield_test.py new file mode 100755 index 000000000..1d761e16c --- /dev/null +++ b/src/MEDMEM_SWIG/med_opfield_test.py @@ -0,0 +1,490 @@ +############################################################################ +# +# this Python script is testing all operations between FIELD(DOUBLE,INT) +# +############################################################################ + +from libMEDMEM_Swig import * +from random import * + +medFile = "pointe.med" + +def add_one(i): + return i+1 + +def print_ord(i): + if i == 0: + return 'first' + elif i == 1: + return 'second' + elif i == 2: + return 'third' + else: + return `i`+'th' + +md = MED() + +mdDriver = MED_MED_RDONLY_DRIVER(medFile,md) + +mdDriver.open() +mdDriver.readFileStruct() +mdDriver.close() + +nbMeshes = md.getNumberOfMeshes() + +nbFields = md.getNumberOfFields() + +print "The med file", medFile, "contains", nbMeshes, "mesh(es) and", nbFields, "field(s)" + +if (nbMeshes>0): + print "Mesh(es) Name(s) is(are) " + + for i in range(nbMeshes): + mesh_name = md.getMeshName(i) + print " - ",mesh_name + +if (nbFields>0): + print "Field(s) Name(s) is(are) " + + for i in range(nbFields): + field_name = md.getFieldName(i) + print " - ",field_name + +print "" + +mesh_name = md.getMeshName(0) +mesh = md.getMesh(mesh_name) +mesh.read() +spaceDim = mesh.getSpaceDimension() +meshDim = mesh.getMeshDimension() +nbNodes = mesh.getNumberOfNodes() +print "The mesh",mesh_name,"is a",spaceDim,"D mesh on a",meshDim,"D geometry and has",nbNodes,"Nodes" + +if (nbFields>0): + print "Updating supports in the Med Object" + md.updateSupport() + print "" + print "Field(s) Analysis " + for i in range(nbFields): + print "" + field_name = md.getFieldName(i) + nbOfIt = md.getFieldNumberOfIteration(field_name) + print "The",print_ord(i),"field is",field_name,"with",nbOfIt,"iteration(s)" + for j in range(nbOfIt): + print "" + dtitfield = md.getFieldIteration(field_name,j) + dt = dtitfield.getdt() + it = dtitfield.getit() + field = md.getField(field_name,dt,it) + type = field.getValueType() + print " * Iteration:",dt,"Order number:",it,"Type:",type + if type == MED_INT32: + fieldint = createFieldIntFromField(field) + fieldint.read() + name = fieldint.getName() + desc = fieldint.getDescription() + nbOfComp = fieldint.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fieldint.getIterationNumber() + orderNb = fieldint.getOrderNumber() + time = fieldint.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + print "Norme 2 : ", fieldint.norm2() + print "Norme Max : ", fieldint.normMax() + + if fielddouble.getSupport().getEntity()!=MED_NODE: + fieldint_vol=fieldint.getSupport().getMesh().getVolume(fieldint.getSupport()) + print "Norme L1 : ", fieldint.normL1() + print "Norme L2 : ", fieldint.normL2() + print "Norme L2(vol) : ", fieldint.normL2(fieldint_vol) + + for k in range(nbOfComp): + kp1 = k+1 + compName = fieldint.getComponentName(kp1) + compDesc = fieldint.getComponentDescription(kp1) + compUnit = fieldint.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + if fielddouble.getSupport().getEntity()!=MED_NODE: + print " Norme L1 : ", fieldint.normL1(kp1) + print " Norme L2 : ", fieldint.normL2(kp1) + print " Norme L2(vol) : ", fieldint.normL2(kp1,fieldint_vol) + + support = fieldint.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fieldint.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + fieldint2 = FIELDINT(fieldint) + print "" + fieldintadd = fieldint + fieldint2 + print "Test of the addition of two integer fields with creation a new one" + print "" + name = fieldintadd.getName() + desc = fieldintadd.getDescription() + nbOfComp = fieldintadd.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fieldintadd.getIterationNumber() + orderNb = fieldintadd.getOrderNumber() + time = fieldintadd.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + for k in range(nbOfComp): + kp1 = k+1 + compName = fieldintadd.getComponentName(kp1) + compDesc = fieldintadd.getComponentDescription(kp1) + compUnit = fieldintadd.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + + support = fieldintadd.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fieldintadd.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + print "" + fieldintsub = fieldint - fieldint2 + print "Test of the substraction of two integer fields with creation a new one" + print "" + name = fieldintsub.getName() + desc = fieldintsub.getDescription() + nbOfComp = fieldintsub.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fieldintsub.getIterationNumber() + orderNb = fieldintsub.getOrderNumber() + time = fieldintsub.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + for k in range(nbOfComp): + kp1 = k+1 + compName = fieldintsub.getComponentName(kp1) + compDesc = fieldintsub.getComponentDescription(kp1) + compUnit = fieldintsub.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + + support = fieldintsub.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fieldintsub.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + print "" + fieldintmul = fieldint * fieldint2 + print "Test of the multiplication of two integer fields with creation a new one" + print "" + name = fieldintmul.getName() + desc = fieldintmul.getDescription() + nbOfComp = fieldintmul.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fieldintmul.getIterationNumber() + orderNb = fieldintmul.getOrderNumber() + time = fieldintmul.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + for k in range(nbOfComp): + kp1 = k+1 + compName = fieldintmul.getComponentName(kp1) + compDesc = fieldintmul.getComponentDescription(kp1) + compUnit = fieldintmul.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + + support = fieldintmul.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fieldintmul.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + print "" + fieldintdiv = fieldint / fieldint2 + print "Test of the division of two integer fields with creation a new one" + print "" + name = fieldintdiv.getName() + desc = fieldintdiv.getDescription() + nbOfComp = fieldintdiv.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fieldintdiv.getIterationNumber() + orderNb = fieldintdiv.getOrderNumber() + time = fieldintdiv.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + for k in range(nbOfComp): + kp1 = k+1 + compName = fieldintdiv.getComponentName(kp1) + compDesc = fieldintdiv.getComponentDescription(kp1) + compUnit = fieldintdiv.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + + support = fieldintdiv.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fieldintdiv.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + elif type == MED_REEL64: + fielddouble = createFieldDoubleFromField(field) + fielddouble.read() + name = fielddouble.getName() + desc = fielddouble.getDescription() + nbOfComp = fielddouble.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fielddouble.getIterationNumber() + orderNb = fielddouble.getOrderNumber() + time = fielddouble.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + print "Norme 2 : ", fielddouble.norm2() + print "Norme Max : ", fielddouble.normMax() + print "try sobolev",fielddouble.getSupport().getEntity() + if fielddouble.getSupport().getEntity()!=MED_NODE: + fielddouble_vol=fielddouble.getSupport().getMesh().getVolume(fielddouble.getSupport()) + print "Norme L1 : ", fielddouble.normL1() + print "Norme L2 : ", fielddouble.normL2() + print "Norme L2(vol) : ", fielddouble.normL2(fielddouble_vol) + + for k in range(nbOfComp): + kp1 = k+1 + compName = fielddouble.getComponentName(kp1) + compDesc = fielddouble.getComponentDescription(kp1) + compUnit = fielddouble.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + if fielddouble.getSupport().getEntity()!=MED_NODE: + print " Norme L1 : ", fielddouble.normL1(kp1) + print " Norme L2 : ", fielddouble.normL2(kp1) + print " Norme L2(vol) : ", fielddouble.normL2(kp1, fielddouble_vol) + + support = fielddouble.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fielddouble.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + fielddouble2 = FIELDDOUBLE(fielddouble) + print "" + fielddoubleadd = fielddouble + fielddouble2 + print "Test of the addition of two double fields with creation a new one" + print "" + name = fielddoubleadd.getName() + desc = fielddoubleadd.getDescription() + nbOfComp = fielddoubleadd.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fielddoubleadd.getIterationNumber() + orderNb = fielddoubleadd.getOrderNumber() + time = fielddoubleadd.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + for k in range(nbOfComp): + kp1 = k+1 + compName = fielddoubleadd.getComponentName(kp1) + compDesc = fielddoubleadd.getComponentDescription(kp1) + compUnit = fielddoubleadd.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + + support = fielddoubleadd.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fielddoubleadd.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + print "" + fielddoublesub = fielddouble - fielddouble2 + print "Test of the substraction of two double fields with creation a new one" + print "" + name = fielddoublesub.getName() + desc = fielddoublesub.getDescription() + nbOfComp = fielddoublesub.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fielddoublesub.getIterationNumber() + orderNb = fielddoublesub.getOrderNumber() + time = fielddoublesub.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + for k in range(nbOfComp): + kp1 = k+1 + compName = fielddoublesub.getComponentName(kp1) + compDesc = fielddoublesub.getComponentDescription(kp1) + compUnit = fielddoublesub.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + + support = fielddoublesub.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fielddoublesub.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + print "" + fielddoublemul = fielddouble * fielddouble2 + print "Test of the multiplication of two double fields with creation a new one" + print "" + name = fielddoublemul.getName() + desc = fielddoublemul.getDescription() + nbOfComp = fielddoublemul.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fielddoublemul.getIterationNumber() + orderNb = fielddoublemul.getOrderNumber() + time = fielddoublemul.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + for k in range(nbOfComp): + kp1 = k+1 + compName = fielddoublemul.getComponentName(kp1) + compDesc = fielddoublemul.getComponentDescription(kp1) + compUnit = fielddoublemul.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + + support = fielddoublemul.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fielddoublemul.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + print "" + fielddoublediv = fielddouble / fielddouble2 + print "Test of the division of two double fields with creation a new one" + print "" + name = fielddoublediv.getName() + desc = fielddoublediv.getDescription() + nbOfComp = fielddoublediv.getNumberOfComponents() + print " Field",name," : ",desc + print " Number Of Components:",nbOfComp + iterationNb = fielddoublediv.getIterationNumber() + orderNb = fielddoublediv.getOrderNumber() + time = fielddoublediv.getTime() + print " Iteration Number",iterationNb + print " Order Number",orderNb + print " Time",time + for k in range(nbOfComp): + kp1 = k+1 + compName = fielddoublediv.getComponentName(kp1) + compDesc = fielddoublediv.getComponentDescription(kp1) + compUnit = fielddoublediv.getMEDComponentUnit(kp1) + print " * Component:",kp1 + print " Name:",compName + print " Description:",compDesc + print " Unit:",compUnit + + support = fielddoublediv.getSupport() + nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS) + print " Values:",nbOf + for k in range(nbOf): + valueI = fielddoublediv.getValueI(MED_FULL_INTERLACE,k+1) + print " *",valueI[:nbOfComp] + else: + print " !!!! Bad type of Field !!!!" + +print "" +print "TESTS OPERATIONS SUR FIELDDOUBLE : " + + +fielddoublesub = fielddouble-fielddouble2 +fielddoublemul = fielddouble*fielddouble2 +fielddoublediv = fielddouble/fielddouble2 +fielddoubleasso = fielddouble+fielddouble2*fielddouble2 +fielddoubleSP=createFieldDoubleScalarProduct(fielddouble, fielddouble2) + + +print " f1 : ",fielddouble.getValue(MED_FULL_INTERLACE) +print " f2 : ",fielddouble2.getValue(MED_FULL_INTERLACE) +print "--------------------------------------------------------------------------------------------------------------" +print " + : ",fielddoubleadd.getValue(MED_FULL_INTERLACE) +print " - : ",fielddoublesub.getValue(MED_FULL_INTERLACE) +print " * : ",fielddoublemul.getValue(MED_FULL_INTERLACE) +print " / : ",fielddoublediv.getValue(MED_FULL_INTERLACE) + +fielddouble+=fielddouble2; +print " += : ",fielddouble.getValue(MED_FULL_INTERLACE) +fielddouble-=fielddouble2; +print " -= : ",fielddouble.getValue(MED_FULL_INTERLACE) +fielddouble*=fielddouble2; +print " *= : ",fielddouble.getValue(MED_FULL_INTERLACE) +fielddouble/=fielddouble2; +print " /= : ",fielddouble.getValue(MED_FULL_INTERLACE) +print "f1+f2*f2: ",fielddoubleasso.getValue(MED_FULL_INTERLACE) +fielddouble.applyLin(4,1); +print " 4f1+1 : ",fielddouble.getValue(MED_FULL_INTERLACE) +print " f1.f2 : ",fielddoubleSP.getValue(MED_FULL_INTERLACE) +fielddouble2.applyPyFunc(add_one) +print " CB:f2+1: ",fielddouble2.getValue(MED_FULL_INTERLACE) + +print "" +print "TESTS OPERATIONS SUR FIELDINT : " + + +fieldintadd = fieldint+fieldint2 +fieldintsub = fieldint-fieldint2 +fieldintmul = fieldint*fieldint2 +fieldintdiv = fieldint/fieldint2 +fieldintasso = fieldint+fieldint*fieldint +fieldintSP=createFieldIntScalarProduct(fieldint, fieldint2) + +print " f1 : ",fieldint.getValue(MED_FULL_INTERLACE) +print " f2 : ",fieldint2.getValue(MED_FULL_INTERLACE) +print "--------------------------------------------------------------------------------------------------------------" +print " + : ",fieldintadd.getValue(MED_FULL_INTERLACE) +print " - : ",fieldintsub.getValue(MED_FULL_INTERLACE) +print " * : ",fieldintmul.getValue(MED_FULL_INTERLACE) +print " / : ",fieldintdiv.getValue(MED_FULL_INTERLACE) +fieldint+=fieldint2; +print " += : ",fieldint.getValue(MED_FULL_INTERLACE) +fieldint-=fieldint2; +print " -= : ",fieldint.getValue(MED_FULL_INTERLACE) +fieldint*=fieldint2; +print " *= : ",fieldint.getValue(MED_FULL_INTERLACE) +fieldint/=fieldint2; +print " /= : ",fieldint.getValue(MED_FULL_INTERLACE) +print "f1+f2*f2: ",fieldintasso.getValue(MED_FULL_INTERLACE) +fieldint.applyLin(4,1); +print " 4f1+1 : ",fieldint.getValue(MED_FULL_INTERLACE) +print " f1.f2 : ",fieldintSP.getValue(MED_FULL_INTERLACE) +fieldint2.applyPyFunc(add_one) +print " CB:f2+1: ",fieldint2.getValue(MED_FULL_INTERLACE) +myname="toto" +fieldint.setName(myname) +name = fieldint.getName() +print "test de setName : ",name +print "END of the Pyhton script ..... Ctrl D to exit" diff --git a/src/MEDMEM_SWIG/med_opsupp_test.py b/src/MEDMEM_SWIG/med_opsupp_test.py new file mode 100755 index 000000000..de43fc64f --- /dev/null +++ b/src/MEDMEM_SWIG/med_opsupp_test.py @@ -0,0 +1,403 @@ +############################################################################ +# +# This Python script is testing the merge and the intersection of +# several SUPPORTs +# +############################################################################ + +from libMEDMEM_Swig import * +from random import * + +medFile = "pointe.med" + +def print_ord(i): + if i == 0: + return 'first' + elif i == 1: + return 'second' + elif i == 2: + return 'third' + else: + return `i`+'th' + +md = MED() + +mdDriver = MED_MED_RDONLY_DRIVER(medFile,md) + +mdDriver.open() +mdDriver.readFileStruct() +mdDriver.close() + +nbMeshes = md.getNumberOfMeshes() + +print "The med file", medFile, "contains", nbMeshes, "mesh(es)" + +mesh_name = md.getMeshName(0) +mesh = md.getMesh(mesh_name) +mesh.read() +spaceDim = mesh.getSpaceDimension() +meshDim = mesh.getMeshDimension() +nbNodes = mesh.getNumberOfNodes() +print "The mesh",mesh_name,"is a",spaceDim,"D mesh on a",meshDim,"D geometry and has",nbNodes,"Nodes" + +print "" +print "Mesh Families analysis:" +print "" + +for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]: + nbFam = mesh.getNumberOfFamilies(entity) + if (entity == MED_NODE) & (nbFam > 0): + print "This mesh has",nbFam,"Node Family(ies)" + elif (entity == MED_NODE) & (nbFam == 0): + print "This mesh has no Node Family(ies)" + elif (entity == MED_CELL) & (nbFam > 0): + print "This mesh has",nbFam,"Cell Family(ies)" + elif (entity == MED_CELL) & (nbFam == 0): + print "This mesh has no Cell Family(ies)" + elif (entity == MED_FACE) & (nbFam > 0): + print "This mesh has",nbFam,"Face Family(ies)" + elif (entity == MED_FACE) & (nbFam == 0): + print "This mesh has no Face Family(ies)" + elif (entity == MED_EDGE) & (nbFam > 0): + print "This mesh has",nbFam,"Edge Family(ies)" + elif (entity == MED_EDGE) & (nbFam == 0): + print "This mesh has no Edge Family(ies)" + print "" + + if nbFam > 0: + for j in range(nbFam): + family = mesh.getFamily(entity,j+1) + familyName = family.getName() + familyDescription = family.getDescription() + familyEntity = family.getEntity() + familyBool = family.isOnAllElements() + print " -Name:",familyName + print " -Description:",familyDescription + print " -Entity:",familyEntity + familyIdentifier = family.getIdentifier() + nbOfAtt = family.getNumberOfAttributes() + print " -Identifier:",familyIdentifier + print " -Number Of Attributes:",nbOfAtt + attributesids = family.getAttributesIdentifiers() + attributesvals = family.getAttributesValues() + for k in range(nbOfAtt): + print " * Attributes:",attributesids[k],":",attributesvals[k],",",family.getAttributeDescription(k+1) + nbOfGrp = family.getNumberOfGroups() + print " -Number Of Groups:",nbOfGrp + for k in range(nbOfGrp): + print " * Group:",family.getGroupName(k+1) + print " -Entities list:" + if (familyBool): + print " -Is on all entities" + else: + nbOfTypes = family.getNumberOfTypes() + types = family.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = family.getNumberOfElements(type) + number = family.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +print "we are going to do some operation on Node families" +print "by definition families have no intersection" +print "" +entity = MED_NODE +familyNode1 = mesh.getFamily(entity,1) +familyNode2 = mesh.getFamily(entity,2) +familyNode3 = mesh.getFamily(entity,3) +familyNode4 = mesh.getFamily(entity,4) + +listOfSupports = [] +listOfSupports.append(familyNode1) +listOfSupports.append(familyNode2) + +support = mesh.mergeSupports(listOfSupports) + +supportName = support.getName() +supportDescription = support.getDescription() +supportMeshname = support.getMesh().getName() +supportEntity = support.getEntity() +supportBool = support.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support.getNumberOfTypes() + types = support.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support.getNumberOfElements(type) + number = support.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +support = mesh.intersectSupports(listOfSupports) + +supportName = support.getName() +supportDescription = support.getDescription() +supportMeshname = support.getMesh().getName() +supportEntity = support.getEntity() +supportBool = support.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support.getNumberOfTypes() + types = support.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support.getNumberOfElements(type) + number = support.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +listOfSupports.append(familyNode3) + +support = mesh.mergeSupports(listOfSupports) + +supportName = support.getName() +supportDescription = support.getDescription() +supportMeshname = support.getMesh().getName() +supportEntity = support.getEntity() +supportBool = support.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support.getNumberOfTypes() + types = support.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support.getNumberOfElements(type) + number = support.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +print "we are going to do some operation on Cell families" +print "by definition families have no intersection" +print "" +entity = MED_CELL +familyCell1 = mesh.getFamily(entity,1) +familyCell2 = mesh.getFamily(entity,2) +familyCell3 = mesh.getFamily(entity,3) + +listOfSupports = [] +listOfSupports.append(familyCell1) +listOfSupports.append(familyCell2) + +support = mesh.mergeSupports(listOfSupports) + +supportName = support.getName() +supportDescription = support.getDescription() +supportMeshname = support.getMesh().getName() +supportEntity = support.getEntity() +supportBool = support.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support.getNumberOfTypes() + types = support.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support.getNumberOfElements(type) + number = support.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +support = mesh.intersectSupports(listOfSupports) + +supportName = support.getName() +supportDescription = support.getDescription() +supportMeshname = support.getMesh().getName() +supportEntity = support.getEntity() +supportBool = support.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support.getNumberOfTypes() + types = support.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support.getNumberOfElements(type) + number = support.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +listOfSupports.append(familyCell3) + +support = mesh.mergeSupports(listOfSupports) + +supportName = support.getName() +supportDescription = support.getDescription() +supportMeshname = support.getMesh().getName() +supportEntity = support.getEntity() +supportBool = support.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support.getNumberOfTypes() + types = support.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support.getNumberOfElements(type) + number = support.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +print "Let's now do an example of union and intersection of two supports with a non empty intersection" +print "" +support1 = SUPPORT(mesh,"Partial_Support_1",MED_CELL) +support1Description = "Partial Support 1" +support1NbOfTypes = 3 +support1TotNbElm = 8 +support1GeoType = [MED_TRIA3,MED_HEXA8,MED_PYRA5] +support1NbOfElm = [4,2,2] +support1NbValue = [1,2,3,4,15,16,13,14] + +support1.setpartial(support1Description,support1NbOfTypes,support1TotNbElm, + support1GeoType,support1NbOfElm,support1NbValue) + +supportName = support1.getName() +supportDescription = support1.getDescription() +supportMeshname = support1.getMesh().getName() +supportEntity = support1.getEntity() +supportBool = support1.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support1.getNumberOfTypes() + types = support1.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support1.getNumberOfElements(type) + number = support1.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +support2 = SUPPORT(mesh,"Partial_Support_2",MED_CELL) +support2Description = "Partial Support 2" +support2NbOfTypes = 3 +support2TotNbElm = 8 +support2GeoType = [MED_TRIA3,MED_HEXA8,MED_PYRA5] +support2NbOfElm = [6,1,1] +support2NbValue = [3,4,9,10,11,12,16,14] + +support2.setpartial(support2Description,support2NbOfTypes,support2TotNbElm, + support2GeoType,support2NbOfElm,support2NbValue) + +supportName = support2.getName() +supportDescription = support2.getDescription() +supportMeshname = support2.getMesh().getName() +supportEntity = support2.getEntity() +supportBool = support2.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support2.getNumberOfTypes() + types = support2.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support2.getNumberOfElements(type) + number = support2.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +listOfSupports = [] +listOfSupports.append(support1) +listOfSupports.append(support2) + +print "The union" +print "" + +support = mesh.mergeSupports(listOfSupports) + +supportName = support.getName() +supportDescription = support.getDescription() +supportMeshname = support.getMesh().getName() +supportEntity = support.getEntity() +supportBool = support.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support.getNumberOfTypes() + types = support.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support.getNumberOfElements(type) + number = support.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +print "The intersection" +print "" + +support = mesh.intersectSupports(listOfSupports) + +supportName = support.getName() +supportDescription = support.getDescription() +supportMeshname = support.getMesh().getName() +supportEntity = support.getEntity() +supportBool = support.isOnAllElements() +print " -Name:",supportName +print " -Description:",supportDescription +print " -Entity:",supportEntity +if (supportBool): + print " -Is on all entities" +else: + nbOfTypes = support.getNumberOfTypes() + types = support.getTypes() + print " -Number Of Types:",nbOfTypes + for k in range(nbOfTypes): + type = types[k] + nbOfElmtsOfType = support.getNumberOfElements(type) + number = support.getNumber(type) + print " * Type",type + print " * Number",number[0:nbOfElmtsOfType] + print "" + +print "END of the Pyhton script ..... Ctrl D to exit" diff --git a/src/MEDMEM_SWIG/med_test1.py b/src/MEDMEM_SWIG/med_test1.py index 1525c9928..57dc43cc3 100644 --- a/src/MEDMEM_SWIG/med_test1.py +++ b/src/MEDMEM_SWIG/med_test1.py @@ -1,28 +1,11 @@ -# MED MEDMEM_SWIG : binding of C++ implementation and Python +################################################################################### # -# 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 +# This Python script is parsing a MED file using MED Memory from SALOME platform: +# It analyses all meshes in the MED file (coordinates, connectivity of d-cells as +# well as (d-1)-cells, families). It analyses fields stored in the MED file (d is +# the space dimension). You can assume that it is a kind of MED file parser. # -# -# -# File : med_test1.py -# Module : MED +################################################################################### from libMEDMEM_Swig import * from random import * @@ -409,25 +392,25 @@ if (nbMeshes>0): suppBound = mesh.getBoundaryElements(MED_FACE) nbElmBound = suppBound.getNumberOfElements(MED_ALL_ELEMENTS) print "Getting normal field on the boundary",nbElmBound -## normalBound = mesh.getNormal(suppBound) -## for j in range(nbElmBound): -## normalBoundJ = normalBound.getValueI(MED_FULL_INTERLACE,j+1) -## value1 = normalBoundJ[0] -## value2 = normalBoundJ[1] -## value3 = normalBoundJ[2] -## norm = (value1*value1 + value2*value2 + value3*value3)**(0.5) -## print " * ",normalBoundJ[:spaceDim],"norm:",norm + normalBound = mesh.getNormal(suppBound) + for j in range(nbElmBound): + normalBoundJ = normalBound.getValueI(MED_FULL_INTERLACE,j+1) + value1 = normalBoundJ[0] + value2 = normalBoundJ[1] + value3 = normalBoundJ[2] + norm = (value1*value1 + value2*value2 + value3*value3)**(0.5) + print " * ",normalBoundJ[:spaceDim],"norm:",norm elif spaceDim == 2: suppBound = mesh.getBoundaryElements(MED_EDGE) nbElmBound = suppBound.getNumberOfElements(MED_ALL_ELEMENTS) print "Getting normal field on the boundary",nbElmBound -## normalBound = mesh.getNormal(suppBound) -## for j in range(nbElmBound): -## normalBoundJ = normalBound.getValueI(MED_FULL_INTERLACE,j+1) -## value1 = normalBoundJ[0] -## value2 = normalBoundJ[1] -## norm = (value1*value1 + value2*value2)**(0.5) -## print " * ",normalBoundJ[:spaceDim],"norm:",norm + normalBound = mesh.getNormal(suppBound) + for j in range(nbElmBound): + normalBoundJ = normalBound.getValueI(MED_FULL_INTERLACE,j+1) + value1 = normalBoundJ[0] + value2 = normalBoundJ[1] + norm = (value1*value1 + value2*value2)**(0.5) + print " * ",normalBoundJ[:spaceDim],"norm:",norm print "" if (nbFields>0): print "Updating supports in the Med Object" @@ -507,3 +490,4 @@ if (nbFields>0): else: print " !!!! Bad type of Field !!!!" +print "END of the Pyhton script ..... Ctrl D to exit" diff --git a/src/MEDMEM_SWIG/med_test2.py b/src/MEDMEM_SWIG/med_test2.py index 0bbb48f81..73a5c23bb 100644 --- a/src/MEDMEM_SWIG/med_test2.py +++ b/src/MEDMEM_SWIG/med_test2.py @@ -1,28 +1,12 @@ -# MED MEDMEM_SWIG : binding of C++ implementation and Python +################################################################################### # -# 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 +# This Python script is parsing a MED file using MED Memory from SALOME platform: +# It analyses all meshes in the MED file (coordinates, connectivity of d-cells as +# well as (d-1)-cells, families), it tests all fields generated ine the MESH class +# and write them in a new file , it gives only the number of fields stored in the +# MED file (d is the space dimension). # -# -# -# File : med_test2.py -# Module : MED +################################################################################### from libMEDMEM_Swig import * from random import * diff --git a/src/MEDMEM_SWIG/med_test3.py b/src/MEDMEM_SWIG/med_test3.py index c179f07d8..9822fc08e 100644 --- a/src/MEDMEM_SWIG/med_test3.py +++ b/src/MEDMEM_SWIG/med_test3.py @@ -1,28 +1,9 @@ -# MED MEDMEM_SWIG : binding of C++ implementation and Python +################################################################################### # -# 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 +# This Python script is parsing a MED file using MED Memory from SALOME platform: +# It tests the setValue(I) function on MED fields # -# -# -# File : med_test3.py -# Module : MED +################################################################################### from libMEDMEM_Swig import * from random import * diff --git a/src/MEDMEM_SWIG/med_test_grid.py b/src/MEDMEM_SWIG/med_test_grid.py index 0c4ecad4d..d22503090 100755 --- a/src/MEDMEM_SWIG/med_test_grid.py +++ b/src/MEDMEM_SWIG/med_test_grid.py @@ -1,11 +1,5 @@ -# MED MEDMEM_SWIG : binding of C++ implementation and Python -# -# Copyright (C) 2003 CEA/DEN, EDF R&D -# -# -# -# File : med_test_grid.py -# Module : MED +# Python script for testing T5.10 task +# ########################################### #% Test structured mesh (GRID) reading from file test19.med #% test19.med can be obtained by running test19_c.out executable diff --git a/src/MEDMEM_SWIG/med_test_skin.py b/src/MEDMEM_SWIG/med_test_skin.py index df3864b29..79d95b42b 100644 --- a/src/MEDMEM_SWIG/med_test_skin.py +++ b/src/MEDMEM_SWIG/med_test_skin.py @@ -1,12 +1,3 @@ -# MED MEDMEM_SWIG : binding of C++ implementation and Python -# -# Copyright (C) 2003 CEA/DEN, EDF R&D -# -# -# -# File : med_test_skin.py -# Module : MED - #% Test function MESH::getSkin() on mesh from file cube_hexa8_quad4.med #% The med file can be obtained by running create_mesh_c3h8q4 executable diff --git a/src/MEDMEM_SWIG/my_typemap.i b/src/MEDMEM_SWIG/my_typemap.i index a9a1b07e6..a527ec4d6 100644 --- a/src/MEDMEM_SWIG/my_typemap.i +++ b/src/MEDMEM_SWIG/my_typemap.i @@ -1,54 +1,30 @@ -// MED MEDMEM_SWIG : binding of C++ implementation and Python -// -// 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 : my_typemap.i -// Module : MED - %{ #include %} %typemap(python,in) string * { + /* typemap in for string * */ /* Check if is a list */ - if (PyList_Check($source)) { - int size = PyList_Size($source); + if (PyList_Check($input)) { + int size = PyList_Size($input); int i = 0; - $target = new string[size]; + $1 = new string[size]; for (i = 0; i < size; i++) { - PyObject *o = PyList_GetItem($source,i); + PyObject *o = PyList_GetItem($input,i); if (PyString_Check(o)) - $target[i] = string(PyString_AsString(PyList_GetItem($source,i))); + $1[i] = string(PyString_AsString(PyList_GetItem($input,i))); else { PyErr_SetString(PyExc_TypeError,"list must contain strings"); - free($target); + free($1); return NULL; } } - // $target[i] = 0; - } else { - PyErr_SetString(PyExc_TypeError,"not a list"); - return NULL; } + else + { + PyErr_SetString(PyExc_TypeError,"not a list"); + return NULL; + } } %typemap(python,in) double * @@ -153,3 +129,4 @@ /* free the memory allocated in the typemap in for medGeometryElement * */ free($1); } + diff --git a/src/MedCorba_Swig/Makefile.in b/src/MedCorba_Swig/Makefile.in index 9cb1be44e..cc7d34f40 100644 --- a/src/MedCorba_Swig/Makefile.in +++ b/src/MedCorba_Swig/Makefile.in @@ -46,6 +46,8 @@ LIB_CLIENT_IDL= SALOME_Component.idl SALOMEDS.idl SALOMEDS_Attributes.idl SALOME EXPORT_PYSCRIPTS = libMedCorba_Swig.py medcorba_test.py batchmode_medcorba_test.py +EXPORT_HEADERS = libMedCorba_Swig.i + ############################################################################# CPPFLAGS+= $(PYTHON_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome diff --git a/src/MedCorba_Swig/libMedCorba_Swig.i b/src/MedCorba_Swig/libMedCorba_Swig.i index 756fddeb6..6035d7b98 100644 --- a/src/MedCorba_Swig/libMedCorba_Swig.i +++ b/src/MedCorba_Swig/libMedCorba_Swig.i @@ -1,29 +1,3 @@ -// MED MedCorba_Swig : binding of MED CORBA objects woth Python -// -// 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 : libMedCorba_Swig.i -// Module : MED - %module libMedCorba_Swig %include "libMEDMEM_Swig.i" @@ -444,6 +418,8 @@ FIELDDOUBLE * createLocalFieldDouble(const int, const int); FIELDINT * createLocalFieldInt(const int, const int); +SALOME_MED::MESH_ptr createCorbaMesh(MESH * mesh); + %{ SALOME_MED::FIELDDOUBLE_ptr createCorbaFieldDouble(SALOME_MED::SUPPORT_ptr mySupportIOR,FIELDDOUBLE * field) { @@ -550,6 +526,28 @@ FIELDINT * createLocalFieldInt(const int, const int); return supportcorba; } + SALOME_MED::MESH_ptr createCorbaMesh(MESH * mesh) + { + BEGIN_OF("SALOME_MED::MESH_ptr createCorbaMesh from libMedCorba_Swig"); + + SCRUTE(mesh); + + MESH_i * meshimpl = new MESH_i(mesh); + + SALOME_MED::MESH_ptr meshcorba = + meshimpl->POA_SALOME_MED::MESH::_this(); + + SCRUTE(meshimpl); + + SCRUTE(meshcorba); + + meshimpl->_remove_ref(); + + END_OF("SALOME_MED::MESH_ptr createCorbaMesh from libMedCorba_Swig"); + + return meshcorba; + } + FIELDDOUBLE * createLocalFieldDouble(const int NumberOfComponents, const int LengthValue) { diff --git a/src/MedMem/Family_i.cxx b/src/MedMem/Family_i.cxx index 81d51782a..3f2d3fb37 100644 --- a/src/MedMem/Family_i.cxx +++ b/src/MedMem/Family_i.cxx @@ -1,37 +1,14 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Family_i.cxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Family_i.cxx - -using namespace std; -#include "Family_i.hxx" +//============================================================================= +// File : Family_i.cxx +// Project : SALOME +// Copyright : EDF 2002 +// Author : EDF +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Family_i.cxx +//============================================================================= #include "utilities.h" +#include "Family_i.hxx" #include "Utils_CorbaException.hxx" - #include "MEDMEM_Family.hxx" //============================================================================= @@ -47,7 +24,7 @@ FAMILY_i::FAMILY_i(): _family((::FAMILY*)NULL), } //============================================================================= /*! - * constructor par recopie + * Copy Constructor */ //============================================================================= FAMILY_i::FAMILY_i(const FAMILY_i & f): _family(f._family), diff --git a/src/MedMem/Family_i.hxx b/src/MedMem/Family_i.hxx index 8a1ae3153..11a9b3e7c 100644 --- a/src/MedMem/Family_i.hxx +++ b/src/MedMem/Family_i.hxx @@ -1,31 +1,10 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Family_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Family_i.hxx - +//============================================================================= +// File : Family_i.hxx +// Project : SALOME +// Copyright : EDF 2002 +// Author : EDF +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Family_i.hxx +//============================================================================= #ifndef MED_FAMILY_I_HXX_ #define MED_FAMILY_I_HXX_ diff --git a/src/MedMem/FieldDouble_i.cxx b/src/MedMem/FieldDouble_i.cxx index d44257488..f10252705 100644 --- a/src/MedMem/FieldDouble_i.cxx +++ b/src/MedMem/FieldDouble_i.cxx @@ -1,32 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Fielddouble_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Fielddouble_i.hxx +//============================================================================= +// File : Fielddouble_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Fielddouble_i.hxx +//============================================================================= -using namespace std; #include "FieldDouble_i.hxx" #include "utilities.h" #include "convert.hxx" diff --git a/src/MedMem/FieldDouble_i.hxx b/src/MedMem/FieldDouble_i.hxx index ff9fdb022..fe149dd37 100644 --- a/src/MedMem/FieldDouble_i.hxx +++ b/src/MedMem/FieldDouble_i.hxx @@ -1,30 +1,10 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Fielddouble_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Fielddouble_i.hxx +//============================================================================= +// File : Fielddouble_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Fielddouble_i.hxx +//============================================================================= #ifndef MED_FIELDDOUBLE_I_HXX_ #define MED_FIELDDOUBLE_I_HXX_ diff --git a/src/MedMem/FieldInt_i.cxx b/src/MedMem/FieldInt_i.cxx index 7ab178229..c0a52b84d 100644 --- a/src/MedMem/FieldInt_i.cxx +++ b/src/MedMem/FieldInt_i.cxx @@ -1,32 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Fieldint_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Fieldint_i.hxx +//============================================================================= +// File : Fieldint_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Fieldint_i.hxx +//============================================================================= -using namespace std; #include "FieldInt_i.hxx" #include "utilities.h" #include "convert.hxx" diff --git a/src/MedMem/FieldInt_i.hxx b/src/MedMem/FieldInt_i.hxx index ce338ff5b..a5f20621c 100644 --- a/src/MedMem/FieldInt_i.hxx +++ b/src/MedMem/FieldInt_i.hxx @@ -1,30 +1,10 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : FieldInt_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/FieldInt_i.hxx +//============================================================================= +// File : FieldInt_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/FieldInt_i.hxx +//============================================================================= #ifndef MED_FIELDINT_I_HXX_ #define MED_FIELDINT_I_HXX_ diff --git a/src/MedMem/FieldOf_i.hxx b/src/MedMem/FieldOf_i.hxx index bb0fd8abe..f4db3ad73 100644 --- a/src/MedMem/FieldOf_i.hxx +++ b/src/MedMem/FieldOf_i.hxx @@ -1,30 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : FieldOf_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/FieldOf_i.hxx +//============================================================================= +// File : FieldOf_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/FieldOf_i.hxx +//============================================================================= + #ifndef MED_FIELDOF_I_HXX_ #define MED_FIELDOF_I_HXX_ @@ -93,7 +74,7 @@ public : Engines::string_array * getComponentsNames() throw (SALOME::SALOME_Exception); Engines::string_array * getComponentsUnits() throw (SALOME::SALOME_Exception); void addInStudy(SALOMEDS::Study_ptr myStudy, - SALOME_MED::FIELD_ptr myIor) throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + SALOME_MED::FIELD_ptr myIor) throw (SALOME::SALOME_Exception); CORBA::Long addDriver (SALOME_MED::medDriverTypes driverType, const char* fileName, const char* fieldName) @@ -472,7 +453,7 @@ throw (SALOME::SALOME_Exception) //============================================================================= template void FIELDOF_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::FIELD_ptr myIor ) -throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) +throw (SALOME::SALOME_Exception) { BEGIN_OF(" FIELDOF_i::addInStudy"); if (_fieldTptr==NULL) @@ -492,14 +473,12 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) SALOMEDS::AttributeIOR_var aIOR; // Create SComponent labelled 'Med' - SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED"); + SALOMEDS::SComponent_var medfather = myStudy->FindComponent("Med"); if ( CORBA::is_nil(medfather) ) THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR); // Create SObject labelled 'MEDFIELD' if it doesn't already exit SALOMEDS::SObject_var medfieldfather = myStudy->FindObject("MEDFIELD"); - - myBuilder->NewCommand(); if ( CORBA::is_nil(medfieldfather) ) { MESSAGE("Add Object 'MEDFIELD'"); @@ -525,6 +504,7 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) // Create object labelled according to Field's Name MESSAGE("Add a Field Object under "<<_fieldTptr->getName()); + myBuilder->NewCommand(); SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfieldnamefather); ORB_INIT &init = *SINGLETON_::Instance() ; @@ -549,7 +529,6 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) SALOMEDS::SObject_var newObjSupport = myBuilder->NewObject(newObj); myBuilder->Addreference(newObjSupport,supportObject); } - myBuilder->CommitCommand(); _FieldId = newObj->GetID(); MESSAGE("FIELDOF_i::addInStudy _FieldId="<< _FieldId); diff --git a/src/MedMem/Field_i.cxx b/src/MedMem/Field_i.cxx index c6a5871a0..a4c941c85 100644 --- a/src/MedMem/Field_i.cxx +++ b/src/MedMem/Field_i.cxx @@ -1,32 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Field_i.cxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Field_i.cxx - -using namespace std; +//============================================================================= +// File : Field_i.cxx +// Created : mer fév 20 15:47:57 CET 2002 +// Author : EDF +// Project : SALOME +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Field_i.cxx +//============================================================================= # include "Field_i.hxx" FIELD_i::FIELD_i() diff --git a/src/MedMem/Field_i.hxx b/src/MedMem/Field_i.hxx index fb44359c3..22fa2d998 100644 --- a/src/MedMem/Field_i.hxx +++ b/src/MedMem/Field_i.hxx @@ -1,31 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Field_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Field_i.hxx - +//============================================================================= +// File : Field_i.hxx +// Created : mer fév 20 15:47:57 CET 2002 +// Author : EDF +// Project : SALOME +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Field_i.hxx +//============================================================================= # ifndef __FIELD_I_H__ # define __FIELD_I_H__ @@ -71,7 +51,7 @@ public : throw (SALOME::SALOME_Exception) = 0; virtual void addInStudy(SALOMEDS::Study_ptr myStudy , SALOME_MED::FIELD_ptr myIor) - throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) = 0; + throw (SALOME::SALOME_Exception) = 0; virtual CORBA::Long addDriver (SALOME_MED::medDriverTypes driverType, const char* fileName, const char* fieldName) diff --git a/src/MedMem/Group_i.cxx b/src/MedMem/Group_i.cxx index 10c6a068e..d9e89d87e 100644 --- a/src/MedMem/Group_i.cxx +++ b/src/MedMem/Group_i.cxx @@ -1,32 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Group_i.cxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/ +//============================================================================= +// File : Group_i.cxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/ +//============================================================================= -using namespace std; #include #include "utilities.h" diff --git a/src/MedMem/Group_i.hxx b/src/MedMem/Group_i.hxx index 35dc8828c..12419693b 100644 --- a/src/MedMem/Group_i.hxx +++ b/src/MedMem/Group_i.hxx @@ -1,31 +1,10 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Group_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Group_i.hxx - +//============================================================================= +// File : Group_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Group_i.hxx +//============================================================================= #ifndef MED_GROUP_I_HXX_ #define MED_GROUP_I_HXX_ diff --git a/src/MedMem/Med_i.cxx b/src/MedMem/Med_i.cxx index b3be89ac8..9e3538de8 100644 --- a/src/MedMem/Med_i.cxx +++ b/src/MedMem/Med_i.cxx @@ -1,32 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Med_i.cxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Med_i.cxx - -using namespace std; +//============================================================================= +// File : Med_i.cxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Med_i.cxx +//============================================================================= + #include //#include "MEDMEM_Field.hxx" @@ -222,36 +201,6 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType // SUPPORT : _med->updateSupport() ; - - // we add all group and family in study : - // we add all families - vector familyVector ; - vector::iterator familyVectorIt ; - // we add all groups - vector groupVector ; - vector::iterator groupVectorIt ; - - MED_FR::MESH_ENTITIES::const_iterator currentEntity; - for (int i=0; igetMesh(meshesNames[i]) ; - for (currentEntity=MED_FR::meshEntities.begin();currentEntity != MED_FR::meshEntities.end(); currentEntity++) { - // family : - familyVector = ptrMesh->getFamilies((MED_EN::medEntityMesh)(*currentEntity).first) ; - for(familyVectorIt=familyVector.begin();familyVectorIt!=familyVector.end();familyVectorIt++) { - FAMILY_i * myFamilyI = new FAMILY_i(*familyVectorIt); - SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->POA_SALOME_MED::FAMILY::_this() ; - myFamilyI->addInStudy(myStudy,myFamilyIOR) ; - } - // group : - groupVector = ptrMesh->getGroups((MED_EN::medEntityMesh)(*currentEntity).first) ; - for(groupVectorIt=groupVector.begin();groupVectorIt!=groupVector.end();groupVectorIt++) { - GROUP_i * myGroupI = new GROUP_i(*groupVectorIt); - SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->POA_SALOME_MED::GROUP::_this() ; - myGroupI->addInStudy(myStudy,myGroupIOR) ; - } - } - } - for (int i=0; i mySupports = _med->getSupports(meshesNames[i]) ; map::const_iterator itSupport ; @@ -808,7 +757,7 @@ throw (SALOME::SALOME_Exception) */ //============================================================================= void MED_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor) -throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) +throw (SALOME::SALOME_Exception) { BEGIN_OF("MED_Mesh_i::addInStudy"); if ( _medId != "" ) @@ -825,7 +774,7 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) SALOMEDS::AttributeIOR_var aIOR; // Create SComponent labelled 'MED' if it doesn't already exit - SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED"); + SALOMEDS::SComponent_var medfather = myStudy->FindComponent("Med"); if ( CORBA::is_nil(medfather) ) { THROW_SALOME_CORBA_EXCEPTION("Component Med not found", diff --git a/src/MedMem/Med_i.hxx b/src/MedMem/Med_i.hxx index fb006e63e..c50baec47 100644 --- a/src/MedMem/Med_i.hxx +++ b/src/MedMem/Med_i.hxx @@ -1,30 +1,10 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Med_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Med_i.hxx +//============================================================================= +// File : Med_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Med_i.hxx +//============================================================================= #ifndef _MED_MED_I_HXX_ #define _MED_MED_I_HXX_ @@ -99,7 +79,7 @@ public: throw (SALOME::SALOME_Exception); void addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor) - throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + throw (SALOME::SALOME_Exception); }; #endif /* _MED_MED_I_HXX_ */ diff --git a/src/MedMem/Mesh_i.cxx b/src/MedMem/Mesh_i.cxx index b32dbce0f..261325421 100644 --- a/src/MedMem/Mesh_i.cxx +++ b/src/MedMem/Mesh_i.cxx @@ -1,32 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Mesh_i.cxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Mesh_i.cxx +//============================================================================= +// File : Mesh_i.cxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Mesh_i.cxx +//============================================================================= -using namespace std; #include #include "utilities.h" @@ -91,7 +70,7 @@ MESH_i::MESH_i(::MESH * const m ) :_mesh(m), } //============================================================================= /*! - * Constructor par recopie + * Copy Constructor */ //============================================================================= //MESH_i::MESH_i(const MESH_i & m) :_mesh(m._mesh), @@ -105,7 +84,7 @@ MESH_i::MESH_i( MESH_i & m) :_mesh(m._mesh), } //============================================================================= /*! - * + * Internal Method in order to have a const ptr */ //============================================================================= ::MESH * MESH_i::constructConstMesh() const @@ -198,7 +177,7 @@ throw (SALOME::SALOME_Exception) * CORBA: Accessor for Coordinates System */ //============================================================================= -char * MESH_i::getCoordinateSystem() +char * MESH_i::getCoordinatesSystem() throw (SALOME::SALOME_Exception) { if (_mesh==NULL) @@ -460,8 +439,7 @@ MESSAGE("MED_NODAL"); const int * tab=_mesh->getConnectivityIndex( convertIdlConnToMedConn(mode), convertIdlEntToMedEnt(entity)); - nbelements = elt1*(convertIdlEltToMedElt(geomElement)%100); - //nbelements = tab[elt1 ] - 1 ; + nbelements = tab[elt1 ] - 1 ; } SCRUTE(entity); SCRUTE(geomElement); @@ -604,7 +582,6 @@ throw (SALOME::SALOME_Exception) Engines::long_array_var myseq= new Engines::long_array; try { - //int nbelements= ???? int nbelements; if ( mode == SALOME_MED::MED_DESCENDING) { @@ -980,7 +957,7 @@ throw (SALOME::SALOME_Exception) */ //============================================================================= void MESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::MESH_ptr myIor ) -throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) +throw (SALOME::SALOME_Exception) { BEGIN_OF("MED_Mesh_i::addInStudy"); if ( _meshId != "" ) @@ -996,13 +973,12 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) SALOMEDS::AttributeIOR_var aIOR; // Find SComponent labelled 'MED' - SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED"); + SALOMEDS::SComponent_var medfather = myStudy->FindComponent("Med"); if ( CORBA::is_nil(medfather) ) THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR); // Create SObject labelled 'MESH' if it doesn't already exit SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH"); - myBuilder->NewCommand(); if ( CORBA::is_nil(medmeshfather) ) { MESSAGE("Add Object MEDMESH"); @@ -1015,6 +991,7 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) } ; MESSAGE("Add a mesh Object under MED/MEDMESH"); + myBuilder->NewCommand(); SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather); ORB_INIT &init = *SINGLETON_::Instance() ; @@ -1038,7 +1015,7 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) */ //============================================================================= void MESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::MESH_ptr myIor,const string & fileName ) -throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) +throw (SALOME::SALOME_Exception) { BEGIN_OF("MED_Mesh_i::addInStudy"); if ( _meshId != "" ) @@ -1055,13 +1032,12 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) SALOMEDS::AttributeComment_var aComment; // Find SComponent labelled 'Med' - SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED"); + SALOMEDS::SComponent_var medfather = myStudy->FindComponent("Med"); if ( CORBA::is_nil(medfather) ) THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR); // Create SObject labelled 'MESH' if it doesn't already exit SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH"); - myBuilder->NewCommand(); if ( CORBA::is_nil(medmeshfather) ) { MESSAGE("Add Object MEDMESH"); @@ -1074,6 +1050,7 @@ throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) } ; MESSAGE("Add a mesh Object under MED/MEDMESH"); + myBuilder->NewCommand(); SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather); ORB_INIT &init = *SINGLETON_::Instance() ; diff --git a/src/MedMem/Mesh_i.hxx b/src/MedMem/Mesh_i.hxx index 68429440e..a2b167114 100644 --- a/src/MedMem/Mesh_i.hxx +++ b/src/MedMem/Mesh_i.hxx @@ -1,30 +1,10 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Mesh_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Mesh_i.hxx +//============================================================================= +// File : Mesh_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Mesh_i.hxx +//============================================================================= #ifndef _MED_MESH_I_HXX_ #define _MED_MESH_I_HXX_ @@ -73,7 +53,7 @@ public: CORBA::Long getMeshDimension() throw (SALOME::SALOME_Exception); - char * getCoordinateSystem() + char * getCoordinatesSystem() throw (SALOME::SALOME_Exception); Engines::double_array* getCoordinates(SALOME_MED::medModeSwitch typeSwitch) @@ -152,10 +132,10 @@ public: // Others void addInStudy (SALOMEDS::Study_ptr myStudy, - SALOME_MED::MESH_ptr myIor) throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + SALOME_MED::MESH_ptr myIor) throw (SALOME::SALOME_Exception); void addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::MESH_ptr myIor, - const string & fileName) throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + const string & fileName) throw (SALOME::SALOME_Exception); CORBA::Long addDriver (SALOME_MED::medDriverTypes driverType, const char* fileName, const char* meshName) throw (SALOME::SALOME_Exception); diff --git a/src/MedMem/Support_i.cxx b/src/MedMem/Support_i.cxx index ea1d9b39a..c82bd5548 100644 --- a/src/MedMem/Support_i.cxx +++ b/src/MedMem/Support_i.cxx @@ -1,32 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Support_i.cxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Support_i.cxx - -using namespace std; +//============================================================================= +// File : Support_i.cxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Support_i.cxx +//============================================================================= + #include "utilities.h" #include "Utils_CorbaException.hxx" #include "Utils_ORB_INIT.hxx" @@ -292,6 +271,10 @@ throw (SALOME::SALOME_Exception) CORBA::Long SUPPORT_i::getNumberOfElements(SALOME_MED::medGeometryElement geomElement) throw (SALOME::SALOME_Exception) { + + SCRUTE(geomElement); + SCRUTE(SALOME_MED::MED_ALL_ELEMENTS); + if (_support==NULL) THROW_SALOME_CORBA_EXCEPTION("No associated Support", \ SALOME::INTERNAL_ERROR); @@ -317,6 +300,10 @@ throw (SALOME::SALOME_Exception) Engines::long_array * SUPPORT_i::getNumber(SALOME_MED::medGeometryElement geomElement) throw (SALOME::SALOME_Exception) { + SCRUTE(_support); + SCRUTE(geomElement); + SCRUTE(convertIdlEltToMedElt(geomElement)); + if (_support==NULL) THROW_SALOME_CORBA_EXCEPTION("No associated Support", \ SALOME::INTERNAL_ERROR); @@ -409,16 +396,16 @@ throw (SALOME::SALOME_Exception) */ //============================================================================= void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr myIor) - throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) + throw (SALOME::SALOME_Exception) { BEGIN_OF("SUPPORT_i::addInStudy"); if ( _supportId != "" ) - { + { MESSAGE("Support already in Study"); THROW_SALOME_CORBA_EXCEPTION("Support already in Study", \ SALOME::BAD_PARAM); - }; + }; SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; @@ -427,44 +414,50 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr // Find SComponent labelled 'Med' MESSAGE("Find SComponent labelled 'Med'"); - SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED"); + SALOMEDS::SComponent_var medfather = myStudy->FindComponent("Med"); if ( CORBA::is_nil(medfather) ) THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR); - // Find SObject labelled 'MEDMESH' - MESSAGE("Find SObject labelled 'MEDMESH'"); - cerr<FindObject("MEDMESH"); - MESSAGE("Find SObject labelled 'MEDMESH' 2"); - cerr<getName() ; - SALOMEDS::SObject_var medsupportfather = myStudy->FindObject(meshName.c_str()); // seulement sous Med : il peut y avoir le meme sous SMESH !!! + + // seulement sous Med : il peut y avoir le meme sous SMESH !!! + SALOMEDS::SObject_var medsupportfather = myStudy->FindObject(meshName.c_str()); if ( CORBA::is_nil(medsupportfather) ) THROW_SALOME_CORBA_EXCEPTION("SObject Mesh in Support not Found",SALOME::INTERNAL_ERROR); // perhaps add MESH automatically ? MESSAGE("Add a support Object under MED/MESH/MESHNAME"); - cerr<NewCommand(); - - SALOMEDS::SObject_var supportEntry = myStudy->FindObject(_support->getName().c_str()); // c'est pas bon, car il faut rechercher uniquement sous le bon MESH !!! - if ( CORBA::is_nil(supportEntry) ) { + SALOMEDS::SObject_var medsupfather = myStudy->FindObject("MEDSUPPORT"); + if ( CORBA::is_nil(medsupfather) ) + { + MESSAGE("Add Object MEDSUPPORT"); + medsupfather = myBuilder->NewObject(medmeshfather); + anAttr = myBuilder->FindOrCreateAttribute(medsupfather, "AttributeName"); + aName = SALOMEDS::AttributeName::_narrow(anAttr); + aName->SetValue("MEDSUPPORT"); + + } ; + + + //myBuilder->NewCommand(); + SALOMEDS::SObject_var supportEntry = myStudy->FindObject(_support->getName().c_str()); + // c'est pas bon, car il faut rechercher uniquement sous le bon MESH !!! + if ( CORBA::is_nil(supportEntry) ) + { // not already in study : we create it ! - SALOMEDS::SObject_var newObj = myBuilder->NewObject(medsupportfather); - + SALOMEDS::SObject_var newObj = myBuilder->NewObject(medsupfather); ORB_INIT &init = *SINGLETON_::Instance() ; ASSERT(SINGLETON_::IsAlreadyExisting()) ; CORBA::ORB_var &orb = init(0,0); @@ -476,7 +469,9 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(_support->getName().c_str()); _supportId = newObj->GetID(); - } else { + } + else + { // already in study : put new AttributeIOR ! ORB_INIT &init = *SINGLETON_::Instance() ; ASSERT(SINGLETON_::IsAlreadyExisting()) ; diff --git a/src/MedMem/Support_i.hxx b/src/MedMem/Support_i.hxx index 58475ab14..8929bf5fd 100644 --- a/src/MedMem/Support_i.hxx +++ b/src/MedMem/Support_i.hxx @@ -1,30 +1,10 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : Support_i.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Support_i.hxx +//============================================================================= +// File : Support_i.hxx +// Project : SALOME +// Author : EDF +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/Support_i.hxx +//============================================================================= #ifndef _MED_SUPPORT_I_HXX_ #define _MED_SUPPORT_I_HXX_ @@ -84,7 +64,7 @@ public: // Others void addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr myIor) - throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + throw (SALOME::SALOME_Exception); // Cuisine interne CORBA::Long getCorbaIndex() throw (SALOME::SALOME_Exception); diff --git a/src/MedMem/convert.cxx b/src/MedMem/convert.cxx index e0bed8471..9bd0ee293 100644 --- a/src/MedMem/convert.cxx +++ b/src/MedMem/convert.cxx @@ -1,32 +1,12 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : convert.cxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/convert.cxx +//============================================================================= +// File : convert.cxx +// Created : mer fév 20 15:47:57 CET 2002 +// Author : EDF +// Project : SALOME +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/convert.cxx +//============================================================================= -using namespace std; #include "utilities.h" #include "Utils_CorbaException.hxx" @@ -66,6 +46,9 @@ throw (SALOME::SALOME_Exception) medGeometryElement convertIdlEltToMedElt(SALOME_MED::medGeometryElement element) throw (SALOME::SALOME_Exception) { + + SCRUTE(element); + switch (element) { case SALOME_MED::MED_NONE : return MED_NONE; diff --git a/src/MedMem/convert.hxx b/src/MedMem/convert.hxx index f3217d6b9..78a5de6e9 100644 --- a/src/MedMem/convert.hxx +++ b/src/MedMem/convert.hxx @@ -1,31 +1,11 @@ -// MED MedMem : MED idl descriptions implementation based on the classes of MEDMEM -// -// 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 : convert.hxx -// Author : EDF -// Module : MED -// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/convert.hxx - +//============================================================================= +// File : convert.hxx +// Created : mer fév 20 15:47:57 CET 2002 +// Author : EDF +// Project : SALOME +// Copyright : EDF 2002 +// $Header: /export/home/CVS/SALOME_ROOT/MED/src/MedMem/convert.hxx +//============================================================================= # if ! defined ( __CONVERT_H__ ) # define __CONVERT_H__ -- 2.39.2