From aff2470ea7367745e336f5223de6cebde5f3747f Mon Sep 17 00:00:00 2001 From: geay Date: Mon, 28 Apr 2014 17:46:02 +0200 Subject: [PATCH] Add structured image grid meshes into MEDCoupling. --- idl/MEDCouplingCorbaServant.idl | 4 + idl/MEDCouplingCorbaServantTest.idl | 1 + src/MEDCoupling/CMakeLists.txt | 1 + src/MEDCoupling/MEDCouplingCMesh.cxx | 23 +- src/MEDCoupling/MEDCouplingCMesh.hxx | 3 - .../MEDCouplingCurveLinearMesh.cxx | 11 +- .../MEDCouplingCurveLinearMesh.hxx | 3 - src/MEDCoupling/MEDCouplingIMesh.cxx | 755 ++++++++++++++++++ src/MEDCoupling/MEDCouplingIMesh.hxx | 115 +++ src/MEDCoupling/MEDCouplingMemArray.cxx | 12 + src/MEDCoupling/MEDCouplingMemArray.hxx | 1 + src/MEDCoupling/MEDCouplingMesh.cxx | 2 +- src/MEDCoupling/MEDCouplingMesh.hxx | 3 +- src/MEDCouplingCorba/CMakeLists.txt | 1 + src/MEDCouplingCorba/Client/CMakeLists.txt | 1 + .../Client/MEDCouplingIMeshClient.cxx | 35 + .../Client/MEDCouplingIMeshClient.hxx | 42 + .../Client/MEDCouplingMeshClient.cxx | 35 + .../MEDCouplingFieldServant.cxx | 37 +- .../MEDCouplingIMeshServant.cxx | 33 + .../MEDCouplingIMeshServant.hxx | 45 ++ .../MEDCouplingMeshFieldFactoryComponent.cxx | 20 + .../MEDCouplingMeshFieldFactoryComponent.hxx | 2 + ...EDCouplingMeshFieldFactoryComponentClt.cxx | 14 + ...EDCouplingMeshFieldFactoryComponentClt.hxx | 2 + ...DCouplingMeshFieldFactoryComponentServ.cxx | 11 + ...DCouplingMeshFieldFactoryComponentServ.hxx | 1 + .../Client/MEDCouplingClient.i | 41 + src/MEDCouplingCorba_Swig/MEDCouplingCorba.i | 22 + .../MEDCouplingCorbaSwigTest.py | 15 + .../MEDCouplingCorbaSwigTestServ.py | 4 + .../TestMEDCouplingCorbaClt.py | 9 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 133 +++ src/MEDCoupling_Swig/MEDCouplingCommon.i | 112 ++- src/MEDCoupling_Swig/MEDCouplingMemArray.i | 1 + src/MEDCoupling_Swig/MEDCouplingTypemaps.i | 2 + 36 files changed, 1517 insertions(+), 35 deletions(-) create mode 100644 src/MEDCoupling/MEDCouplingIMesh.cxx create mode 100644 src/MEDCoupling/MEDCouplingIMesh.hxx create mode 100644 src/MEDCouplingCorba/Client/MEDCouplingIMeshClient.cxx create mode 100644 src/MEDCouplingCorba/Client/MEDCouplingIMeshClient.hxx create mode 100644 src/MEDCouplingCorba/MEDCouplingIMeshServant.cxx create mode 100644 src/MEDCouplingCorba/MEDCouplingIMeshServant.hxx diff --git a/idl/MEDCouplingCorbaServant.idl b/idl/MEDCouplingCorbaServant.idl index a00c2cca2..3882f3b06 100644 --- a/idl/MEDCouplingCorbaServant.idl +++ b/idl/MEDCouplingCorbaServant.idl @@ -100,6 +100,10 @@ module SALOME_MED { }; + interface MEDCouplingIMeshCorbaInterface : MEDCouplingStructuredMeshCorbaInterface + { + }; + interface MEDCouplingFieldCorbaInterface : MEDCouplingRefCountCorbaInterface { MEDCouplingMeshCorbaInterface getMesh(); diff --git a/idl/MEDCouplingCorbaServantTest.idl b/idl/MEDCouplingCorbaServantTest.idl index 72344223d..b55a87b8e 100644 --- a/idl/MEDCouplingCorbaServantTest.idl +++ b/idl/MEDCouplingCorbaServantTest.idl @@ -40,6 +40,7 @@ module SALOME_TEST SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface getCLMesh(); SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface get1SGTUMesh(); SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface get1DGTUMesh(); + SALOME_MED::MEDCouplingIMeshCorbaInterface getIMesh(); SALOME_MED::MEDCouplingFieldDoubleCorbaInterface getFieldScalarOn2DNT(); SALOME_MED::MEDCouplingFieldDoubleCorbaInterface getFieldNodeScalarOn2DNT(); SALOME_MED::MEDCouplingFieldDoubleCorbaInterface getFieldScalarOn3DNT(); diff --git a/src/MEDCoupling/CMakeLists.txt b/src/MEDCoupling/CMakeLists.txt index bc8961671..6af998f0c 100644 --- a/src/MEDCoupling/CMakeLists.txt +++ b/src/MEDCoupling/CMakeLists.txt @@ -40,6 +40,7 @@ SET(medcoupling_SOURCES MEDCouplingMemArrayChar.cxx MEDCouplingTimeLabel.cxx MEDCouplingCMesh.cxx + MEDCouplingIMesh.cxx MEDCouplingCurveLinearMesh.cxx MEDCouplingStructuredMesh.cxx MEDCouplingTimeDiscretization.cxx diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 22851038d..3eeadc142 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -128,11 +128,11 @@ std::vector MEDCouplingCMesh::getDirectChildren() const * @throw if other and this have not same mesh type. */ void MEDCouplingCMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) -{ - const MEDCouplingCMesh *otherC=dynamic_cast(other); +{ + MEDCouplingStructuredMesh::copyTinyStringsFrom(other); + const MEDCouplingCMesh *otherC(dynamic_cast(other)); if(!otherC) throw INTERP_KERNEL::Exception("MEDCouplingCMesh::copyTinyStringsFrom : meshes have not same type !"); - MEDCouplingStructuredMesh::copyTinyStringsFrom(other); if(_x_array && otherC->_x_array) _x_array->copyStringInfoFrom(*otherC->_x_array); if(_y_array && otherC->_y_array) @@ -151,7 +151,7 @@ bool MEDCouplingCMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec reason="mesh given in input is not castable in MEDCouplingCMesh !"; return false; } - if(!MEDCouplingMesh::isEqualIfNotWhy(other,prec,reason)) + if(!MEDCouplingStructuredMesh::isEqualIfNotWhy(other,prec,reason)) return false; const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array}; const DataArrayDouble *otherArr[3]={otherC->_x_array,otherC->_y_array,otherC->_z_array}; @@ -202,14 +202,13 @@ void MEDCouplingCMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int ce /*! * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingCMesh instance too). - * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCMesh, 'this' and 'other' are the same ! + * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCMesh, \a this and \a other are the same ! */ void MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor) const { - const MEDCouplingCMesh *otherC=dynamic_cast(other); - if(!otherC) - throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith : other is NOT a cartesian mesh ! Impossible to check equivalence !"); + if(!isEqualWithoutConsideringStr(other,prec)) + throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith : Meshes are not the same !"); } void MEDCouplingCMesh::checkCoherency() const @@ -342,10 +341,10 @@ std::vector MEDCouplingCMesh::getNodeGridStructure() const MEDCouplingStructuredMesh *MEDCouplingCMesh::buildStructuredSubPart(const std::vector< std::pair >& cellPart) const { checkCoherency(); - int dim(getMeshDimension()); + int dim(getSpaceDimension()); if(dim!=(int)cellPart.size()) { - std::ostringstream oss; oss << "MEDCouplingCMesh::buildStructuredSubPart : the mesh dimension is " << dim << " and cell part size is " << cellPart.size() << " !"; + std::ostringstream oss; oss << "MEDCouplingCMesh::buildStructuredSubPart : the space dimension is " << dim << " and cell part size is " << cellPart.size() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } MEDCouplingAutoRefCountObjectPtr ret(dynamic_cast(deepCpy())); @@ -388,7 +387,7 @@ std::string MEDCouplingCMesh::simpleRepr() const double tt=getTime(tmpp1,tmpp2); ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n"; ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n"; - ret << "Mesh and SpaceDimension dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n"; + ret << "Space dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n"; if(_x_array) { ret << "X Array :\n"; @@ -646,7 +645,7 @@ int MEDCouplingCMesh::getCellContainingPoint(const double *pos, double eps) cons void MEDCouplingCMesh::rotate(const double *center, const double *vector, double angle) { - throw INTERP_KERNEL::Exception("No rotation available on CMesh : Traduce it to StructuredMesh to apply it !"); + throw INTERP_KERNEL::Exception("No rotation available on CMesh : Traduce it to untructured mesh to apply it !"); } /*! diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index 8011fb8ca..92909bea3 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -26,9 +26,6 @@ namespace ParaMEDMEM { - class DataArrayDouble; - class MEDCouplingUMesh; - class MEDCouplingCMesh : public MEDCouplingStructuredMesh { public: diff --git a/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx b/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx index c96ed77f1..6745edac4 100644 --- a/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx @@ -168,14 +168,13 @@ void MEDCouplingCurveLinearMesh::checkDeepEquivalWith(const MEDCouplingMesh *oth /*! * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingCurveLinearMesh instance too). - * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCurveLinearMesh, 'this' and 'other' are the same ! + * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCurveLinearMesh, \a this and \a other are the same ! */ void MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor) const { - const MEDCouplingCurveLinearMesh *otherC=dynamic_cast(other); - if(!otherC) - throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith : other is NOT a cartesian mesh ! Impossible to check equivalence !"); + if(!isEqualWithoutConsideringStr(other,prec)) + throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith : Meshes are not the same !"); } void MEDCouplingCurveLinearMesh::checkCoherency() const @@ -345,11 +344,11 @@ std::vector MEDCouplingCurveLinearMesh::getNodeGridStructure() const MEDCouplingStructuredMesh *MEDCouplingCurveLinearMesh::buildStructuredSubPart(const std::vector< std::pair >& cellPart) const { checkCoherency(); - int dim(getMeshDimension()); + int dim(getSpaceDimension()); std::vector dims(getMeshDimension()); if(dim!=(int)cellPart.size()) { - std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::buildStructuredSubPart : the mesh dimension is " << dim << " and cell part size is " << cellPart.size() << " !"; + std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::buildStructuredSubPart : the space dimension is " << dim << " and cell part size is " << cellPart.size() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } std::vector< std::pair > nodePartFormat(cellPart); diff --git a/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx b/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx index 56505d921..98be1d779 100644 --- a/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx @@ -27,9 +27,6 @@ namespace ParaMEDMEM { - class DataArrayDouble; - class MEDCouplingUMesh; - class MEDCouplingCurveLinearMesh : public MEDCouplingStructuredMesh { public: diff --git a/src/MEDCoupling/MEDCouplingIMesh.cxx b/src/MEDCoupling/MEDCouplingIMesh.cxx new file mode 100644 index 000000000..6ef737b8e --- /dev/null +++ b/src/MEDCoupling/MEDCouplingIMesh.cxx @@ -0,0 +1,755 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#include "MEDCouplingIMesh.hxx" +#include "MEDCouplingCMesh.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingFieldDouble.hxx" + +#include +#include +#include +#include + +using namespace ParaMEDMEM; + +MEDCouplingIMesh::MEDCouplingIMesh():_space_dim(-1) +{ + _origin[0]=0.; _origin[1]=0.; _origin[2]=0.; + _dxyz[0]=0.; _dxyz[1]=0.; _dxyz[2]=0.; + _structure[0]=0; _structure[1]=0; _structure[2]=0; +} + +MEDCouplingIMesh::MEDCouplingIMesh(const MEDCouplingIMesh& other, bool deepCopy):MEDCouplingStructuredMesh(other,deepCopy),_space_dim(other._space_dim),_axis_unit(other._axis_unit) +{ + _origin[0]=other._origin[0]; _origin[1]=other._origin[1]; _origin[2]=other._origin[2]; + _dxyz[0]=other._dxyz[0]; _dxyz[1]=other._dxyz[1]; _dxyz[2]=other._dxyz[2]; + _structure[0]=other._structure[0]; _structure[1]=other._structure[1]; _structure[2]=other._structure[2]; +} + +MEDCouplingIMesh::~MEDCouplingIMesh() +{ +} + +MEDCouplingIMesh *MEDCouplingIMesh::New() +{ + return new MEDCouplingIMesh; +} + +MEDCouplingIMesh *MEDCouplingIMesh::New(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop, + const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop) +{ + MEDCouplingAutoRefCountObjectPtr ret(new MEDCouplingIMesh); + ret->setName(meshName); + ret->setSpaceDimension(spaceDim); + ret->setNodeStruct(nodeStrctStart,nodeStrctStop); + ret->setOrigin(originStart,originStop); + ret->setDXYZ(dxyzStart,dxyzStop); + return ret.retn(); +} + +MEDCouplingMesh *MEDCouplingIMesh::deepCpy() const +{ + return clone(true); +} + +MEDCouplingIMesh *MEDCouplingIMesh::clone(bool recDeepCpy) const +{ + return new MEDCouplingIMesh(*this,recDeepCpy); +} + +void MEDCouplingIMesh::setNodeStruct(const int *nodeStrctStart, const int *nodeStrctStop) +{ + checkSpaceDimension(); + int sz((int)std::distance(nodeStrctStart,nodeStrctStop)); + if(sz!=_space_dim) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::setNodeStruct : input vector of node structure has not the right size ! Or change space dimension before calling it !"); + std::copy(nodeStrctStart,nodeStrctStop,_structure); + declareAsNew(); +} + +std::vector MEDCouplingIMesh::getNodeStruct() const +{ + checkSpaceDimension(); + return std::vector(_structure,_structure+_space_dim); +} + +void MEDCouplingIMesh::setOrigin(const double *originStart, const double *originStop) +{ + checkSpaceDimension(); + int sz((int)std::distance(originStart,originStop)); + if(sz!=_space_dim) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::setOrigin : input vector of origin vector has not the right size ! Or change space dimension before calling it !"); + std::copy(originStart,originStop,_origin); + declareAsNew(); +} + +std::vector MEDCouplingIMesh::getOrigin() const +{ + checkSpaceDimension(); + return std::vector(_origin,_origin+_space_dim); +} + +void MEDCouplingIMesh::setDXYZ(const double *dxyzStart, const double *dxyzStop) +{ + checkSpaceDimension(); + int sz((int)std::distance(dxyzStart,dxyzStop)); + if(sz!=_space_dim) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::setDXYZ : input vector of dxyz vector has not the right size ! Or change space dimension before calling it !"); + std::copy(dxyzStart,dxyzStop,_dxyz); + declareAsNew(); +} + +std::vector MEDCouplingIMesh::getDXYZ() const +{ + checkSpaceDimension(); + return std::vector(_dxyz,_dxyz+_space_dim); +} + +void MEDCouplingIMesh::setAxisUnit(const std::string& unitName) +{ + _axis_unit=unitName; + declareAsNew(); +} + +std::string MEDCouplingIMesh::getAxisUnit() const +{ + return _axis_unit; +} + +/*! + * This method returns the measure of any cell in \a this. + * This specific method of image grid mesh utilizes the fact that any cell in \a this have the same measure. + * The value returned by this method is those used to feed the returned field in the MEDCouplingIMesh::getMeasureField. + * + * \sa getMeasureField + */ +double MEDCouplingIMesh::getMeasureOfAnyCell() const +{ + checkCoherency(); + int dim(getSpaceDimension()); + double ret(1.); + for(int i=0;i ret(MEDCouplingCMesh::New()); + try + { ret->copyTinyInfoFrom(this); } + catch(INTERP_KERNEL::Exception& e) { } + int spaceDim(getSpaceDimension()); + std::vector infos(buildInfoOnComponents()); + for(int i=0;i arr(DataArrayDouble::New()); arr->alloc(_structure[i],1); arr->setInfoOnComponent(0,infos[i]); + arr->iota(); arr->applyLin(_dxyz[i],_origin[i]); + ret->setCoordsAt(i,arr); + } + return ret.retn(); +} + +void MEDCouplingIMesh::setSpaceDimension(int spaceDim) +{ + if(spaceDim==_space_dim) + return ; + CheckSpaceDimension(spaceDim); + _space_dim=spaceDim; + declareAsNew(); +} + +void MEDCouplingIMesh::updateTime() const +{ +} + +std::size_t MEDCouplingIMesh::getHeapMemorySizeWithoutChildren() const +{ + return MEDCouplingStructuredMesh::getHeapMemorySizeWithoutChildren(); +} + +std::vector MEDCouplingIMesh::getDirectChildren() const +{ + return std::vector(); +} + +/*! + * This method copyies all tiny strings from other (name and components name). + * @throw if other and this have not same mesh type. + */ +void MEDCouplingIMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) +{ + const MEDCouplingIMesh *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::copyTinyStringsFrom : meshes have not same type !"); + MEDCouplingStructuredMesh::copyTinyStringsFrom(other); + declareAsNew(); +} + +bool MEDCouplingIMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const +{ + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::isEqualIfNotWhy : input other pointer is null !"); + const MEDCouplingIMesh *otherC(dynamic_cast(other)); + if(!otherC) + { + reason="mesh given in input is not castable in MEDCouplingIMesh !"; + return false; + } + if(!MEDCouplingStructuredMesh::isEqualIfNotWhy(other,prec,reason)) + return false; + if(!isEqualWithoutConsideringStrInternal(otherC,prec,reason)) + return false; + if(_axis_unit!=otherC->_axis_unit) + { + reason="The units of axis are not the same !"; + return false; + } + return true; +} + +bool MEDCouplingIMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const +{ + const MEDCouplingIMesh *otherC=dynamic_cast(other); + if(!otherC) + return false; + std::string tmp; + return isEqualWithoutConsideringStrInternal(other,prec,tmp); +} + +bool MEDCouplingIMesh::isEqualWithoutConsideringStrInternal(const MEDCouplingMesh *other, double prec, std::string& reason) const +{ + const MEDCouplingIMesh *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_space_dim!=otherC->_space_dim) + { + std::ostringstream oss; + oss << "The spaceDimension of this (" << _space_dim << ") is not equal to those of other (" << otherC->_space_dim << ") !"; + return false; + } + checkSpaceDimension(); + for(int i=0;i<_space_dim;i++) + { + if(fabs(_origin[i]-otherC->_origin[i])>prec) + { + std::ostringstream oss; + oss << "The origin of this and other differs at " << i << " !"; + reason=oss.str(); + return false; + } + } + for(int i=0;i<_space_dim;i++) + { + if(fabs(_dxyz[i]-otherC->_dxyz[i])>prec) + { + std::ostringstream oss; + oss << "The delta of this and other differs at " << i << " !"; + reason=oss.str(); + return false; + } + } + for(int i=0;i<_space_dim;i++) + { + if(_structure[i]!=otherC->_structure[i]) + { + std::ostringstream oss; + oss << "The structure of this and other differs at " << i << " !"; + reason=oss.str(); + return false; + } + } + return true; +} + +void MEDCouplingIMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const +{ + if(!isEqualWithoutConsideringStr(other,prec)) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::checkDeepEquivalWith : Meshes are not the same !"); +} + +/*! + * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingIMesh instance too). + * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingIMesh, \a this and \a other are the same ! + */ +void MEDCouplingIMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const +{ + if(!isEqualWithoutConsideringStr(other,prec)) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::checkDeepEquivalOnSameNodesWith : Meshes are not the same !"); +} + +void MEDCouplingIMesh::checkCoherency() const +{ + checkSpaceDimension(); + for(int i=0;i<_space_dim;i++) + if(_structure[i]<1) + { + std::ostringstream oss; oss << "MEDCouplingIMesh::checkCoherency : On axis " << i << "/" << _space_dim << ", number of nodes is equal to " << _structure[i] << " ! must be >=1 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +void MEDCouplingIMesh::checkCoherency1(double eps) const +{ + checkCoherency(); +} + +void MEDCouplingIMesh::checkCoherency2(double eps) const +{ + checkCoherency1(eps); +} + +void MEDCouplingIMesh::getSplitCellValues(int *res) const +{ + int meshDim(getMeshDimension()); + for(int l=0;l MEDCouplingIMesh::getNodeGridStructure() const +{ + checkSpaceDimension(); + std::vector ret(_structure,_structure+_space_dim); + return ret; +} + +MEDCouplingStructuredMesh *MEDCouplingIMesh::buildStructuredSubPart(const std::vector< std::pair >& cellPart) const +{ + checkCoherency(); + int dim(getSpaceDimension()); + if(dim!=(int)cellPart.size()) + { + std::ostringstream oss; oss << "MEDCouplingIMesh::buildStructuredSubPart : the space dimension is " << dim << " and cell part size is " << cellPart.size() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + double retOrigin[3]={0.,0.,0.}; + int retStruct[3]={0,0,0}; + MEDCouplingAutoRefCountObjectPtr ret(dynamic_cast(deepCpy())); + for(int i=0;i=_structure[i]) + { + std::ostringstream oss; oss << "MEDCouplingIMesh::buildStructuredSubPart : At dimension #" << i << " the start node id is " << startNode << " it should be in [0," << _structure[i] << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(myDelta<0 || myDelta>_structure[i]) + { + std::ostringstream oss; oss << "MEDCouplingIMesh::buildStructuredSubPart : Along dimension #" << i << " the number of nodes is " << _structure[i] << ", and you are requesting for " << myDelta << " nodes wide range !" << std::endl; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + retOrigin[i]=_origin[i]+startNode*_dxyz[i]; + retStruct[i]=myDelta; + } + ret->setNodeStruct(retStruct,retStruct+dim); + ret->setOrigin(retOrigin,retOrigin+dim); + ret->checkCoherency(); + return ret.retn(); +} + +/*! + * Return the space dimension of \a this. + */ +int MEDCouplingIMesh::getSpaceDimension() const +{ + return _space_dim; +} + +void MEDCouplingIMesh::getCoordinatesOfNode(int nodeId, std::vector& coo) const +{ + int tmp[3]; + int spaceDim(getSpaceDimension()); + getSplitNodeValues(tmp); + int tmp2[3]; + GetPosFromId(nodeId,spaceDim,tmp,tmp2); + for(int j=0;j3) + return ret.str(); + ret << "The nodal structure is : "; std::copy(_structure,_structure+spaceDim,std::ostream_iterator(ret," ")); ret << "\n"; + ret << "The origin position is [" << _axis_unit << "]: "; + std::copy(_origin,_origin+spaceDim,std::ostream_iterator(ret," ")); ret << "\n"; + ret << "The intervals along axis are : "; + std::copy(_dxyz,_dxyz+spaceDim,std::ostream_iterator(ret," ")); ret << "\n"; + return ret.str(); +} + +std::string MEDCouplingIMesh::advancedRepr() const +{ + return simpleRepr(); +} + +void MEDCouplingIMesh::getBoundingBox(double *bbox) const +{ + checkCoherency(); + int dim(getSpaceDimension()); + for(int idim=0; idim + * For 1D cells, the returned field contains lengths.
+ * For 2D cells, the returned field contains areas.
+ * For 3D cells, the returned field contains volumes. + * \param [in] isAbs - a not used parameter. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on cells + * and one time . The caller is to delete this field using decrRef() as it is no + * more needed. + */ +MEDCouplingFieldDouble *MEDCouplingIMesh::getMeasureField(bool isAbs) const +{ + checkCoherency(); + std::string name="MeasureOfMesh_"; + name+=getName(); + int nbelem(getNumberOfCells()); + MEDCouplingFieldDouble *field(MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME)); + field->setName(name); + DataArrayDouble* array(DataArrayDouble::New()); + array->alloc(nbelem,1); + array->fillWithValue(getMeasureOfAnyCell()); + field->setArray(array) ; + array->decrRef(); + field->setMesh(const_cast(this)); + field->synchronizeTimeWithMesh(); + return field; +} + +/*! + * not implemented yet ! + */ +MEDCouplingFieldDouble *MEDCouplingIMesh::getMeasureFieldOnNode(bool isAbs) const +{ + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::getMeasureFieldOnNode : not implemented yet !"); + //return 0; +} + +int MEDCouplingIMesh::getCellContainingPoint(const double *pos, double eps) const +{ + int dim(getSpaceDimension()),ret(0),coeff(1); + for(int i=0;i=0 && tmpgetSpaceDimension(). + */ +void MEDCouplingIMesh::translate(const double *vector) +{ + checkSpaceDimension(); + int dim(getSpaceDimension()); + std::transform(_origin,_origin+dim,vector,_origin,std::plus()); + declareAsNew(); +} + +/*! + * Applies scaling transformation to all nodes of \a this mesh. + * \param [in] point - coordinates of a scaling center. This array is to be of + * size \a this->getSpaceDimension() at least. + * \param [in] factor - a scale factor. + */ +void MEDCouplingIMesh::scale(const double *point, double factor) +{ + checkSpaceDimension(); + int dim(getSpaceDimension()); + std::transform(_origin,_origin+dim,point,_origin,std::minus()); + std::transform(_origin,_origin+dim,_origin,std::bind2nd(std::multiplies(),factor)); + std::transform(_dxyz,_dxyz+dim,_dxyz,std::bind2nd(std::multiplies(),factor)); + std::transform(_origin,_origin+dim,point,_origin,std::plus()); + declareAsNew(); +} + +MEDCouplingMesh *MEDCouplingIMesh::mergeMyselfWith(const MEDCouplingMesh *other) const +{ + //not implemented yet ! + return 0; +} + +/*! + * Returns a new DataArrayDouble holding coordinates of all nodes of \a this mesh. + * \return DataArrayDouble * - a new instance of DataArrayDouble, of size \a + * this->getNumberOfNodes() tuples per \a this->getSpaceDimension() + * components. The caller is to delete this array using decrRef() as it is + * no more needed. + */ +DataArrayDouble *MEDCouplingIMesh::getCoordinatesAndOwner() const +{ + checkCoherency(); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + int spaceDim(getSpaceDimension()),nbNodes(getNumberOfNodes()); + ret->alloc(nbNodes,spaceDim); + double *pt(ret->getPointer()); + ret->setInfoOnComponents(buildInfoOnComponents()); + int tmp2[3],tmp[3]; + getSplitNodeValues(tmp); + for(int i=0;igetNumberOfCells() tuples per \a this->getSpaceDimension() + * components. The caller is to delete this array using decrRef() as it is + * no more needed. + */ +DataArrayDouble *MEDCouplingIMesh::getBarycenterAndOwner() const +{ + checkCoherency(); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + int spaceDim(getSpaceDimension()),nbCells(getNumberOfCells()),tmp[3],tmp2[3]; + ret->alloc(nbCells,spaceDim); + double *pt(ret->getPointer()),shiftOrigin[3]; + std::transform(_dxyz,_dxyz+spaceDim,shiftOrigin,std::bind2nd(std::multiplies(),0.5)); + std::transform(_origin,_origin+spaceDim,shiftOrigin,shiftOrigin,std::plus()); + getSplitCellValues(tmp); + ret->setInfoOnComponents(buildInfoOnComponents()); + for(int i=0;i& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const +{ + int it,order; + double time(getTime(it,order)); + tinyInfo.clear(); + tinyInfoD.clear(); + littleStrings.clear(); + littleStrings.push_back(getName()); + littleStrings.push_back(getDescription()); + littleStrings.push_back(getTimeUnit()); + littleStrings.push_back(getAxisUnit()); + tinyInfo.push_back(it); + tinyInfo.push_back(order); + tinyInfo.push_back(_space_dim); + tinyInfo.insert(tinyInfo.end(),_structure,_structure+3); + tinyInfoD.push_back(time); + tinyInfoD.insert(tinyInfoD.end(),_dxyz,_dxyz+3); + tinyInfoD.insert(tinyInfoD.end(),_origin,_origin+3); +} + +void MEDCouplingIMesh::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const +{ + a1->alloc(0,1); + a2->alloc(0,1); +} + +void MEDCouplingIMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const +{ + a1=DataArrayInt::New(); + a1->alloc(0,1); + a2=DataArrayDouble::New(); + a2->alloc(0,1); +} + +void MEDCouplingIMesh::unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings) +{ + setName(littleStrings[0]); + setDescription(littleStrings[1]); + setTimeUnit(littleStrings[2]); + setAxisUnit(littleStrings[3]); + setTime(tinyInfoD[0],tinyInfo[0],tinyInfo[1]); + _space_dim=tinyInfo[2]; + _structure[0]=tinyInfo[3]; _structure[1]=tinyInfo[4]; _structure[2]=tinyInfo[5]; + _dxyz[0]=tinyInfoD[1]; _dxyz[1]=tinyInfoD[2]; _dxyz[2]=tinyInfoD[3]; + _origin[0]=tinyInfoD[4]; _origin[1]=tinyInfoD[5]; _origin[2]=tinyInfoD[6]; + declareAsNew(); +} + +void MEDCouplingIMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const +{ + checkCoherency(); + std::ostringstream extent; + for(int i=0;i<3;i++) + { + if(i<_space_dim) + { extent << "0 " << _structure[i]-1 << " "; } + else + { extent << "0 0 "; } + } + ofs << " <" << getVTKDataSetType() << " WholeExtent=\"" << extent.str() << "\">\n"; + ofs << " \n"; + ofs << " \n" << pointData << std::endl; + ofs << " \n"; + ofs << " \n" << cellData << std::endl; + ofs << " \n"; + ofs << " \n"; + ofs << " \n"; + ofs << " \n"; + ofs << " \n"; +} + +void MEDCouplingIMesh::reprQuickOverview(std::ostream& stream) const +{ + stream << "MEDCouplingIMesh C++ instance at " << this << ". Name : \"" << getName() << "\". Space dimension : " << _space_dim << "."; + if(_space_dim<0 || _space_dim>3) + return ; + stream << "\n"; + std::ostringstream stream0,stream1; + int nbNodes(1),nbCells(0); + bool isPb(false); + for(int i=0;i<_space_dim;i++) + { + char tmp('X'+i); + int tmpNodes(_structure[i]); + stream1 << "- Axis " << tmp << " : " << tmpNodes << " nodes (orig=" << _origin[i] << ", inter=" << _dxyz[i] << ")."; + if(i!=_space_dim-1) + stream1 << std::endl; + if(tmpNodes>=1) + nbNodes*=tmpNodes; + else + isPb=true; + if(tmpNodes>=2) + nbCells=nbCells==0?tmpNodes-1:nbCells*(tmpNodes-1); + } + if(!isPb) + { + stream0 << "Number of cells : " << nbCells << ", Number of nodes : " << nbNodes; + stream << stream0.str(); + if(_space_dim>0) + stream << std::endl; + } + stream << stream1.str(); +} + +std::string MEDCouplingIMesh::getVTKDataSetType() const +{ + return std::string("ImageData"); +} + +std::vector MEDCouplingIMesh::buildInfoOnComponents() const +{ + checkSpaceDimension(); + int dim(getSpaceDimension()); + std::vector ret(dim); + for(int i=0;i3) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CheckSpaceDimension : input spaceDim must be in [0,1,2,3] !"); +} + diff --git a/src/MEDCoupling/MEDCouplingIMesh.hxx b/src/MEDCoupling/MEDCouplingIMesh.hxx new file mode 100644 index 000000000..ecd679069 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingIMesh.hxx @@ -0,0 +1,115 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#ifndef __PARAMEDMEM_MEDCOUPLINGIMESH_HXX__ +#define __PARAMEDMEM_MEDCOUPLINGIMESH_HXX__ + +#include "MEDCoupling.hxx" +#include "MEDCouplingStructuredMesh.hxx" + +namespace ParaMEDMEM +{ + class MEDCouplingCMesh; + + class MEDCouplingIMesh : public MEDCouplingStructuredMesh + { + public: + MEDCOUPLING_EXPORT static MEDCouplingIMesh *New(); + MEDCOUPLING_EXPORT static MEDCouplingIMesh *New(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop, + const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop); + // + MEDCOUPLING_EXPORT void setSpaceDimension(int spaceDim); + MEDCOUPLING_EXPORT void setNodeStruct(const int *nodeStrctStart, const int *nodeStrctStop); + MEDCOUPLING_EXPORT std::vector getNodeStruct() const; + MEDCOUPLING_EXPORT void setOrigin(const double *originStart, const double *originStop); + MEDCOUPLING_EXPORT std::vector getOrigin() const; + MEDCOUPLING_EXPORT void setDXYZ(const double *dxyzStart, const double *dxyzStop); + MEDCOUPLING_EXPORT std::vector getDXYZ() const; + MEDCOUPLING_EXPORT void setAxisUnit(const std::string& unitName); + MEDCOUPLING_EXPORT std::string getAxisUnit() const; + MEDCOUPLING_EXPORT double getMeasureOfAnyCell() const; + MEDCOUPLING_EXPORT MEDCouplingCMesh *convertToCartesian() const; + // + MEDCOUPLING_EXPORT MEDCouplingMesh *deepCpy() const; + MEDCOUPLING_EXPORT MEDCouplingIMesh *clone(bool recDeepCpy) const; + MEDCOUPLING_EXPORT void updateTime() const; + MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; + MEDCOUPLING_EXPORT std::vector getDirectChildren() const; + MEDCOUPLING_EXPORT MEDCouplingMeshType getType() const { return IMAGE_GRID; } + MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingMesh *other); + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const; + MEDCOUPLING_EXPORT void checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const; + MEDCOUPLING_EXPORT void checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const; + MEDCOUPLING_EXPORT void checkCoherency() const; + MEDCOUPLING_EXPORT void checkCoherency1(double eps=1e-12) const; + MEDCOUPLING_EXPORT void checkCoherency2(double eps=1e-12) const; + MEDCOUPLING_EXPORT int getSpaceDimension() const; + MEDCOUPLING_EXPORT void getCoordinatesOfNode(int nodeId, std::vector& coo) const; + MEDCOUPLING_EXPORT std::string simpleRepr() const; + MEDCOUPLING_EXPORT std::string advancedRepr() const; + // tools + MEDCOUPLING_EXPORT void getBoundingBox(double *bbox) const; + MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureField(bool isAbs) const; + MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const; + MEDCOUPLING_EXPORT int getCellContainingPoint(const double *pos, double eps) const; + MEDCOUPLING_EXPORT void rotate(const double *center, const double *vector, double angle); + MEDCOUPLING_EXPORT void translate(const double *vector); + MEDCOUPLING_EXPORT void scale(const double *point, double factor); + MEDCOUPLING_EXPORT MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const; + MEDCOUPLING_EXPORT DataArrayDouble *getCoordinatesAndOwner() const; + MEDCOUPLING_EXPORT DataArrayDouble *getBarycenterAndOwner() const; + MEDCOUPLING_EXPORT DataArrayDouble *computeIsoBarycenterOfNodesPerCell() const; + MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check=true); + //some useful methods + MEDCOUPLING_EXPORT void getSplitCellValues(int *res) const; + MEDCOUPLING_EXPORT void getSplitNodeValues(int *res) const; + MEDCOUPLING_EXPORT void getNodeGridStructure(int *res) const; + MEDCOUPLING_EXPORT std::vector getNodeGridStructure() const; + MEDCouplingStructuredMesh *buildStructuredSubPart(const std::vector< std::pair >& cellPart) const; + //serialisation-unserialization + MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const; + MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; + MEDCOUPLING_EXPORT void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; + MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings); + MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + private: + MEDCouplingIMesh(); + MEDCouplingIMesh(const MEDCouplingIMesh& other, bool deepCpy); + ~MEDCouplingIMesh(); + void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const; + std::string getVTKDataSetType() const; + bool isEqualWithoutConsideringStrInternal(const MEDCouplingMesh *other, double prec, std::string& reason) const; + std::vector buildInfoOnComponents() const; + void checkSpaceDimension() const; + static void CheckSpaceDimension(int spaceDim); + private: + int _space_dim; + double _origin[3]; + double _dxyz[3]; + int _structure[3]; + std::string _axis_unit; + }; +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index e37a72b8c..6845713eb 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -422,6 +422,18 @@ std::string DataArray::GetUnitFromInfo(const std::string& info) return info.substr(p1+1,p2-p1-1); } +/*! + * This method put in info format the result of the merge of \a var and \a unit. + * The standard format for that is "var [unit]". + * Inversely you can retrieve the var part or the unit part of info string using resp. GetVarNameFromInfo and GetUnitFromInfo. + */ +std::string DataArray::BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit) +{ + std::ostringstream oss; + oss << var << " [" << unit << "]"; + return oss.str(); +} + /*! * Returns a new DataArray by concatenating all given arrays, so that (1) the number * of tuples in the result array is a sum of the number of tuples of given arrays and (2) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 48a1ea3d3..d77572698 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -167,6 +167,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step); MEDCOUPLING_EXPORT static std::string GetVarNameFromInfo(const std::string& info); MEDCOUPLING_EXPORT static std::string GetUnitFromInfo(const std::string& info); + MEDCOUPLING_EXPORT static std::string BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit); MEDCOUPLING_EXPORT static DataArray *Aggregate(const std::vector& arrs); MEDCOUPLING_EXPORT virtual void reprStream(std::ostream& stream) const = 0; MEDCOUPLING_EXPORT virtual void reprZipStream(std::ostream& stream) const = 0; diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index aefddd462..241e05120 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -329,10 +329,10 @@ void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) */ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) { - copyTinyStringsFrom(other); _time=other->_time; _iteration=other->_iteration; _order=other->_order; + copyTinyStringsFrom(other); } /*! diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index ad1102c0d..8eae2e543 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -41,7 +41,8 @@ namespace ParaMEDMEM EXTRUDED = 8, CURVE_LINEAR = 9, SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED = 10, - SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED = 11 + SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED = 11, + IMAGE_GRID = 12 } MEDCouplingMeshType; // -- WARNING this enum must be synchronized with MEDCouplingCommon.i file ! -- diff --git a/src/MEDCouplingCorba/CMakeLists.txt b/src/MEDCouplingCorba/CMakeLists.txt index 7e1ee213d..a05d4511b 100644 --- a/src/MEDCouplingCorba/CMakeLists.txt +++ b/src/MEDCouplingCorba/CMakeLists.txt @@ -45,6 +45,7 @@ SET(medcouplingcorba_SOURCES MEDCoupling1SGTUMeshServant.cxx MEDCoupling1GTUMeshServant.cxx MEDCouplingCMeshServant.cxx + MEDCouplingIMeshServant.cxx MEDCouplingUMeshServant.cxx MEDCouplingFieldServant.cxx MEDCouplingFieldDoubleServant.cxx diff --git a/src/MEDCouplingCorba/Client/CMakeLists.txt b/src/MEDCouplingCorba/Client/CMakeLists.txt index ffdc3f4e8..356213dcb 100644 --- a/src/MEDCouplingCorba/Client/CMakeLists.txt +++ b/src/MEDCouplingCorba/Client/CMakeLists.txt @@ -30,6 +30,7 @@ SET(medcouplingclient_SOURCES DataArrayDoubleClient.cxx DataArrayIntClient.cxx MEDCouplingCMeshClient.cxx + MEDCouplingIMeshClient.cxx MEDCoupling1SGTUMeshClient.cxx MEDCoupling1DGTUMeshClient.cxx MEDCouplingCurveLinearMeshClient.cxx diff --git a/src/MEDCouplingCorba/Client/MEDCouplingIMeshClient.cxx b/src/MEDCouplingCorba/Client/MEDCouplingIMeshClient.cxx new file mode 100644 index 000000000..c12c9a2ac --- /dev/null +++ b/src/MEDCouplingCorba/Client/MEDCouplingIMeshClient.cxx @@ -0,0 +1,35 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay + +#include "MEDCouplingIMeshClient.hxx" +#include "MEDCouplingMeshClient.hxx" +#include "MEDCouplingIMesh.hxx" +#include "MEDCouplingMemArray.hxx" + +#include + +using namespace ParaMEDMEM; + +MEDCouplingIMesh *MEDCouplingIMeshClient::New(SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr meshPtr) +{ + MEDCouplingIMesh *ret=MEDCouplingIMesh::New(); + MEDCouplingMeshClient::fillMeshFromCorbaData(ret,meshPtr); + return ret; +} diff --git a/src/MEDCouplingCorba/Client/MEDCouplingIMeshClient.hxx b/src/MEDCouplingCorba/Client/MEDCouplingIMeshClient.hxx new file mode 100644 index 000000000..9fd9e2657 --- /dev/null +++ b/src/MEDCouplingCorba/Client/MEDCouplingIMeshClient.hxx @@ -0,0 +1,42 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#ifndef __MEDCOUPLINGIMESHCLIENT_HXX__ +#define __MEDCOUPLINGIMESHCLIENT_HXX__ + +#include "SALOMEconfig.h" +#ifdef WIN32 +#define NOMINMAX +#endif +#include CORBA_SERVER_HEADER(MEDCouplingCorbaServant) +#include "MEDCouplingClient.hxx" + +namespace ParaMEDMEM +{ + class MEDCouplingIMesh; + + class MEDCOUPLINGCLIENT_EXPORT MEDCouplingIMeshClient + { + public: + static MEDCouplingIMesh *New(SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr mesh); + }; +} + +#endif diff --git a/src/MEDCouplingCorba/Client/MEDCouplingMeshClient.cxx b/src/MEDCouplingCorba/Client/MEDCouplingMeshClient.cxx index 75e6ac959..c6e3142cf 100644 --- a/src/MEDCouplingCorba/Client/MEDCouplingMeshClient.cxx +++ b/src/MEDCouplingCorba/Client/MEDCouplingMeshClient.cxx @@ -20,11 +20,18 @@ #include "MEDCouplingMeshClient.hxx" #include "MEDCouplingUMeshClient.hxx" +#include "MEDCoupling1SGTUMeshClient.hxx" +#include "MEDCoupling1DGTUMeshClient.hxx" #include "MEDCouplingExtrudedMeshClient.hxx" #include "MEDCouplingExtrudedMesh.hxx" #include "MEDCouplingCMeshClient.hxx" +#include "MEDCouplingCurveLinearMeshClient.hxx" +#include "MEDCouplingIMeshClient.hxx" #include "MEDCouplingCMesh.hxx" +#include "MEDCouplingCurveLinearMesh.hxx" +#include "MEDCouplingIMesh.hxx" #include "MEDCouplingUMesh.hxx" +#include "MEDCoupling1GTUMesh.hxx" #include @@ -53,6 +60,34 @@ MEDCouplingMesh *MEDCouplingMeshClient::New(SALOME_MED::MEDCouplingMeshCorbaInte CORBA::release(cmeshPtr); return ret; } + SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_ptr clmeshPtr=SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface::_narrow(meshPtr); + if(!CORBA::is_nil(clmeshPtr)) + { + MEDCouplingMesh *ret=MEDCouplingCurveLinearMeshClient::New(clmeshPtr); + CORBA::release(clmeshPtr); + return ret; + } + SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr imeshPtr=SALOME_MED::MEDCouplingIMeshCorbaInterface::_narrow(meshPtr); + if(!CORBA::is_nil(imeshPtr)) + { + MEDCouplingMesh *ret=MEDCouplingIMeshClient::New(imeshPtr); + CORBA::release(imeshPtr); + return ret; + } + SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface_ptr umeshPtr0=SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface::_narrow(meshPtr); + if(!CORBA::is_nil(umeshPtr0)) + { + MEDCouplingMesh *ret=MEDCoupling1SGTUMeshClient::New(umeshPtr0); + CORBA::release(umeshPtr0); + return ret; + } + SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface_ptr umeshPtr1=SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface::_narrow(meshPtr); + if(!CORBA::is_nil(umeshPtr1)) + { + MEDCouplingMesh *ret=MEDCoupling1DGTUMeshClient::New(umeshPtr1); + CORBA::release(umeshPtr1); + return ret; + } return 0; } diff --git a/src/MEDCouplingCorba/MEDCouplingFieldServant.cxx b/src/MEDCouplingCorba/MEDCouplingFieldServant.cxx index a49d9ad9c..aa1fe5f87 100644 --- a/src/MEDCouplingCorba/MEDCouplingFieldServant.cxx +++ b/src/MEDCouplingCorba/MEDCouplingFieldServant.cxx @@ -22,11 +22,18 @@ #include "MEDCouplingMeshServant.hxx" #include "MEDCouplingUMeshServant.hxx" #include "MEDCouplingCMeshServant.hxx" +#include "MEDCouplingIMeshServant.hxx" +#include "MEDCouplingCurveLinearMeshServant.hxx" #include "MEDCouplingExtrudedMeshServant.hxx" +#include "MEDCoupling1SGTUMeshServant.hxx" +#include "MEDCoupling1DGTUMeshServant.hxx" #include "MEDCouplingField.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingCMesh.hxx" +#include "MEDCouplingIMesh.hxx" +#include "MEDCouplingCurveLinearMesh.hxx" #include "MEDCouplingExtrudedMesh.hxx" +#include "MEDCoupling1GTUMesh.hxx" using namespace ParaMEDMEM; @@ -50,17 +57,45 @@ SALOME_MED::MEDCouplingMeshCorbaInterface_ptr MEDCouplingFieldServant::BuildCorb SALOME_MED::MEDCouplingCMeshCorbaInterface_ptr ret=retServ->_this();//let this line even if it seems fool return ret; } + const MEDCouplingIMesh *iMesh=dynamic_cast(mesh); + if(iMesh) + { + MEDCouplingIMeshServant *retServ=new MEDCouplingIMeshServant(iMesh); + SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr ret=retServ->_this();//let this line even if it seems fool + return ret; + } const MEDCouplingExtrudedMesh *eMesh=dynamic_cast(mesh); if(eMesh) { MEDCouplingExtrudedMeshServant *retServ=new MEDCouplingExtrudedMeshServant(eMesh); return retServ->_this(); } + const MEDCouplingCurveLinearMesh *clMesh=dynamic_cast(mesh); + if(clMesh) + { + MEDCouplingCurveLinearMeshServant *retServ=new MEDCouplingCurveLinearMeshServant(clMesh); + SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_ptr ret=retServ->_this();//let this line even if it seems fool + return ret; + } + const MEDCoupling1SGTUMesh *u0Mesh=dynamic_cast(mesh); + if(u0Mesh) + { + MEDCoupling1SGTUMeshServant *retServ=new MEDCoupling1SGTUMeshServant(u0Mesh); + SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface_ptr ret=retServ->_this();//let this line even if it seems fool + return ret; + } + const MEDCoupling1DGTUMesh *u1Mesh=dynamic_cast(mesh); + if(u1Mesh) + { + MEDCoupling1DGTUMeshServant *retServ=new MEDCoupling1DGTUMeshServant(u1Mesh); + SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface_ptr ret=retServ->_this();//let this line even if it seems fool + return ret; + } throw INTERP_KERNEL::Exception("Not dealt mesh type !"); } SALOME_MED::MEDCouplingMeshCorbaInterface_ptr MEDCouplingFieldServant::getMesh() { - const MEDCouplingMesh *mesh=getPointer()->getMesh(); + const MEDCouplingMesh *mesh(getPointer()->getMesh()); return BuildCorbaRefFromCppPointer(mesh); } diff --git a/src/MEDCouplingCorba/MEDCouplingIMeshServant.cxx b/src/MEDCouplingCorba/MEDCouplingIMeshServant.cxx new file mode 100644 index 000000000..84788f982 --- /dev/null +++ b/src/MEDCouplingCorba/MEDCouplingIMeshServant.cxx @@ -0,0 +1,33 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay + +#include "MEDCouplingIMeshServant.hxx" + +#include "MEDCouplingIMesh.hxx" + +using namespace ParaMEDMEM; + +MEDCouplingIMeshServant::MEDCouplingIMeshServant(const MEDCouplingIMesh *cppPointerOfMesh):MEDCouplingStructuredMeshServant(cppPointerOfMesh) +{ +} + +MEDCouplingIMeshServant::~MEDCouplingIMeshServant() +{ +} diff --git a/src/MEDCouplingCorba/MEDCouplingIMeshServant.hxx b/src/MEDCouplingCorba/MEDCouplingIMeshServant.hxx new file mode 100644 index 000000000..8eddca8c2 --- /dev/null +++ b/src/MEDCouplingCorba/MEDCouplingIMeshServant.hxx @@ -0,0 +1,45 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay + +#ifndef __MEDCOUPLINGIMESHSERVANT_HXX__ +#define __MEDCOUPLINGIMESHSERVANT_HXX__ + +#include "SALOMEconfig.h" + +#include CORBA_SERVER_HEADER(MEDCouplingCorbaServant) +#include "MEDCouplingStructuredMeshServant.hxx" +#include "MEDCouplingCorba.hxx" + +namespace ParaMEDMEM +{ + class MEDCouplingIMesh; + + class MEDCOUPLINGCORBA_EXPORT MEDCouplingIMeshServant : MEDCouplingStructuredMeshServant, public virtual POA_SALOME_MED::MEDCouplingIMeshCorbaInterface + { + public: + typedef MEDCouplingIMesh CppType; + MEDCouplingIMeshServant(const MEDCouplingIMesh *cppPointerOfMesh); + ~MEDCouplingIMeshServant(); + private: + const MEDCouplingIMesh *getPointer() const { return (const MEDCouplingIMesh *)(_cpp_pointer); } + }; +} + +#endif diff --git a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponent.cxx b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponent.cxx index 0bbc5f178..424535658 100644 --- a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponent.cxx +++ b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponent.cxx @@ -28,6 +28,7 @@ #include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingCMesh.hxx" +#include "MEDCouplingIMesh.hxx" #include "MEDCouplingCurveLinearMesh.hxx" #include @@ -218,6 +219,25 @@ namespace SALOME_TEST // return targetMesh; } + + + ParaMEDMEM::MEDCouplingIMesh *MEDCouplingCorbaServBasicsTest::buildIMesh() + { + ParaMEDMEM::MEDCouplingIMesh *targetMesh(ParaMEDMEM::MEDCouplingIMesh::New()); + targetMesh->setTime(2.3,4,5); + targetMesh->setTimeUnit("us"); + targetMesh->setName("Example of IMesh"); + targetMesh->setDescription("buildIMesh"); + int ns[3]={6,7,8}; + double orig[3]={4.25,3.75,-6.125}; + double inter[3]={0.5,0.375,0.75}; + targetMesh->setSpaceDimension(3); + targetMesh->setNodeStruct(ns,ns+3); + targetMesh->setOrigin(orig,orig+3); + targetMesh->setDXYZ(inter,inter+3); + targetMesh->setAxisUnit("mm"); + return targetMesh; + } ParaMEDMEM::MEDCouplingCurveLinearMesh *MEDCouplingCorbaServBasicsTest::buildCLMesh() { diff --git a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponent.hxx b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponent.hxx index bd3f08560..5fabaf80c 100644 --- a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponent.hxx +++ b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponent.hxx @@ -32,6 +32,7 @@ namespace ParaMEDMEM class MEDCoupling1DGTUMesh; class MEDCoupling1SGTUMesh; class MEDCouplingCMesh; + class MEDCouplingIMesh; class MEDCouplingCurveLinearMesh; class DataArrayDouble; class DataArrayInt; @@ -52,6 +53,7 @@ namespace SALOME_TEST static ParaMEDMEM::MEDCouplingUMesh *buildM1DMesh(); static ParaMEDMEM::MEDCouplingExtrudedMesh *buildExtrudedMesh(ParaMEDMEM::MEDCouplingUMesh *&m2D); static ParaMEDMEM::MEDCouplingCMesh *buildCMesh(); + static ParaMEDMEM::MEDCouplingIMesh *buildIMesh(); static ParaMEDMEM::MEDCouplingCurveLinearMesh *buildCLMesh(); static ParaMEDMEM::MEDCoupling1SGTUMesh *build1SGTUMesh(); static ParaMEDMEM::MEDCoupling1DGTUMesh *build1DGTUMesh(); diff --git a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentClt.cxx b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentClt.cxx index 8ea427b60..f99bc0988 100644 --- a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentClt.cxx +++ b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentClt.cxx @@ -29,6 +29,8 @@ #include "MEDCouplingExtrudedMeshClient.hxx" #include "MEDCouplingCMesh.hxx" #include "MEDCouplingCMeshClient.hxx" +#include "MEDCouplingIMesh.hxx" +#include "MEDCouplingIMeshClient.hxx" #include "MEDCouplingCurveLinearMesh.hxx" #include "MEDCouplingCurveLinearMeshClient.hxx" #include "MEDCouplingFieldDouble.hxx" @@ -208,6 +210,18 @@ void SALOME_TEST::MEDCouplingCorbaServBasicsTestClt::checkCorbaFetchingCMesh() meshFromDistant->decrRef(); } +void SALOME_TEST::MEDCouplingCorbaServBasicsTestClt::checkCorbaFetchingIMesh() +{ + SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr meshPtr=_objC->getIMesh(); + ParaMEDMEM::MEDCouplingIMesh *meshFromDistant=ParaMEDMEM::MEDCouplingIMeshClient::New(meshPtr); + meshPtr->UnRegister(); + CORBA::release(meshPtr); + ParaMEDMEM::MEDCouplingIMesh *meshRef=SALOME_TEST::MEDCouplingCorbaServBasicsTest::buildIMesh(); + CPPUNIT_ASSERT(meshFromDistant->isEqual(meshRef,1e-12)); + meshRef->decrRef(); + meshFromDistant->decrRef(); +} + void SALOME_TEST::MEDCouplingCorbaServBasicsTestClt::checkCorbaFetchingCurveLinearMesh() { SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_ptr meshPtr=_objC->getCLMesh(); diff --git a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentClt.hxx b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentClt.hxx index 1904a89df..5a9513968 100644 --- a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentClt.hxx +++ b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentClt.hxx @@ -52,6 +52,7 @@ namespace SALOME_TEST CPPUNIT_TEST( checkCorbaFetchingM1D ); CPPUNIT_TEST( checkCorbaFetchingExtruded ); CPPUNIT_TEST( checkCorbaFetchingCMesh ); + CPPUNIT_TEST( checkCorbaFetchingIMesh ); CPPUNIT_TEST( checkCorbaFetchingCurveLinearMesh ); CPPUNIT_TEST( checkCorbaFetching1SGTUMesh ); CPPUNIT_TEST( checkCorbaFetching1DGTUMesh ); @@ -96,6 +97,7 @@ namespace SALOME_TEST void checkCorbaFetchingM1D(); void checkCorbaFetchingExtruded(); void checkCorbaFetchingCMesh(); + void checkCorbaFetchingIMesh(); void checkCorbaFetchingCurveLinearMesh(); void checkCorbaFetching1SGTUMesh(); void checkCorbaFetching1DGTUMesh(); diff --git a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentServ.cxx b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentServ.cxx index 9324c0fa9..64e7fc564 100644 --- a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentServ.cxx +++ b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentServ.cxx @@ -29,6 +29,7 @@ #include "MEDCoupling1SGTUMeshServant.hxx" #include "MEDCoupling1DGTUMeshServant.hxx" #include "MEDCouplingCMeshServant.hxx" +#include "MEDCouplingIMeshServant.hxx" #include "MEDCouplingUMeshServant.hxx" #include "DataArrayDoubleServant.hxx" #include "DataArrayIntServant.hxx" @@ -41,6 +42,7 @@ #include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingCMesh.hxx" +#include "MEDCouplingIMesh.hxx" namespace SALOME_TEST { @@ -133,6 +135,15 @@ namespace SALOME_TEST SALOME_MED::MEDCouplingCMeshCorbaInterface_ptr ret=m->_this(); return ret; } + + SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr MEDCouplingMeshFieldFactoryComponent::getIMesh() + { + ParaMEDMEM::MEDCouplingIMesh *m1=MEDCouplingCorbaServBasicsTest::buildIMesh(); + ParaMEDMEM::MEDCouplingIMeshServant *m=new ParaMEDMEM::MEDCouplingIMeshServant(m1); + m1->decrRef(); + SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr ret=m->_this(); + return ret; + } SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_ptr MEDCouplingMeshFieldFactoryComponent::getCLMesh() { diff --git a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentServ.hxx b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentServ.hxx index 3a83f3b71..52bb99e90 100644 --- a/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentServ.hxx +++ b/src/MEDCouplingCorba/Test/MEDCouplingMeshFieldFactoryComponentServ.hxx @@ -49,6 +49,7 @@ namespace SALOME_TEST SALOME_MED::MEDCouplingUMeshCorbaInterface_ptr getM1DMesh(); SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface_ptr getExtrudedMesh(); SALOME_MED::MEDCouplingCMeshCorbaInterface_ptr getCMesh(); + SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr getIMesh(); SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_ptr getCLMesh(); SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface_ptr get1SGTUMesh(); SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface_ptr get1DGTUMesh(); diff --git a/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i b/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i index c8c6ca864..6bb5d3cae 100644 --- a/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i +++ b/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i @@ -30,6 +30,7 @@ #include "MEDCoupling1DGTUMeshClient.hxx" #include "MEDCouplingExtrudedMeshClient.hxx" #include "MEDCouplingCMeshClient.hxx" +#include "MEDCouplingIMeshClient.hxx" #include "MEDCouplingCurveLinearMeshClient.hxx" #include "DataArrayDoubleClient.hxx" #include "DataArrayIntClient.hxx" @@ -48,6 +49,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDCoupling1DGTUMeshClient::New; %newobject ParaMEDMEM::MEDCouplingExtrudedMeshClient::New; %newobject ParaMEDMEM::MEDCouplingCMeshClient::New; +%newobject ParaMEDMEM::MEDCouplingIMeshClient::New; %newobject ParaMEDMEM::MEDCouplingCurveLinearMeshClient::New; %newobject ParaMEDMEM::MEDCouplingMultiFieldsClient::New; %newobject ParaMEDMEM::MEDCouplingFieldOverTimeClient::New; @@ -223,6 +225,13 @@ namespace ParaMEDMEM Py_DECREF(iorMesh); return MEDCouplingCMeshClient::New(meshPtrCppC2); } + SALOME_MED::MEDCouplingIMeshCorbaInterface_var meshPtrCppC7=SALOME_MED::MEDCouplingIMeshCorbaInterface::_narrow(meshPtrCpp); + if(!CORBA::is_nil(meshPtrCppC7)) + { + Py_DECREF(pdict); + Py_DECREF(iorMesh); + return MEDCouplingIMeshClient::New(meshPtrCppC7); + } SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_var meshPtrCppC3=SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface::_narrow(meshPtrCpp); if(!CORBA::is_nil(meshPtrCppC3)) { @@ -416,6 +425,38 @@ namespace ParaMEDMEM } }; + class MEDCouplingIMeshClient + { + public: + %extend + { + static MEDCouplingIMesh *New(PyObject *meshPtr) throw(INTERP_KERNEL::Exception) + { + PyObject* pdict=PyDict_New(); + PyDict_SetItemString(pdict,"__builtins__",PyEval_GetBuiltins()); + PyRun_String("import MEDCouplingCorbaServant_idl",Py_single_input,pdict, pdict); + PyRun_String("import CORBA",Py_single_input,pdict, pdict); + PyRun_String("orbTmp15634=CORBA.ORB_init([''])", Py_single_input,pdict, pdict); + PyObject *orbPython=PyDict_GetItemString(pdict,"orbTmp15634"); + // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string + PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); + if(!iorMesh) + throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingIMeshClient.New appears to differ from CORBA reference ! Expecting a IMeshCorbaInterface CORBA reference !"); + char *ior=PyString_AsString(iorMesh); + int argc=0; + CORBA::ORB_var orb=CORBA::ORB_init(argc,0); + CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); + SALOME_MED::MEDCouplingIMeshCorbaInterface_var meshPtrCppC=SALOME_MED::MEDCouplingIMeshCorbaInterface::_narrow(meshPtrCpp); + if(CORBA::is_nil(meshPtrCppC)) + throw INTERP_KERNEL::Exception("error corba pointer is not a SALOME_MED.MEDCouplingIMeshInterface_ptr !"); + Py_DECREF(pdict); + Py_DECREF(iorMesh); + MEDCouplingIMesh *ret=MEDCouplingIMeshClient::New(meshPtrCppC); + return ret; + } + } + }; + class MEDCouplingCurveLinearMeshClient { public: diff --git a/src/MEDCouplingCorba_Swig/MEDCouplingCorba.i b/src/MEDCouplingCorba_Swig/MEDCouplingCorba.i index 01cb90418..a81388bbb 100644 --- a/src/MEDCouplingCorba_Swig/MEDCouplingCorba.i +++ b/src/MEDCouplingCorba_Swig/MEDCouplingCorba.i @@ -30,6 +30,7 @@ #include "MEDCoupling1DGTUMeshServant.hxx" #include "MEDCouplingExtrudedMeshServant.hxx" #include "MEDCouplingCMeshServant.hxx" +#include "MEDCouplingIMeshServant.hxx" #include "MEDCouplingCurveLinearMeshServant.hxx" #include "DataArrayDoubleServant.hxx" #include "DataArrayIntServant.hxx" @@ -129,6 +130,8 @@ namespace ParaMEDMEM return buildServantAndActivate(dynamic_cast(cppPointerOfMesh)); if(dynamic_cast(cppPointerOfMesh)) return buildServantAndActivate(dynamic_cast(cppPointerOfMesh)); + if(dynamic_cast(cppPointerOfMesh)) + return buildServantAndActivate(dynamic_cast(cppPointerOfMesh)); if(dynamic_cast(cppPointerOfMesh)) return buildServantAndActivate(dynamic_cast(cppPointerOfMesh)); throw INTERP_KERNEL::Exception("MEDCouplingMeshServant::_this : unrecognized type (or not managed type) of Mesh in input !"); @@ -148,6 +151,8 @@ namespace ParaMEDMEM return buildServantAndActivate2(dynamic_cast(cppPointerOfMesh)); if(dynamic_cast(cppPointerOfMesh)) return buildServantAndActivate2(dynamic_cast(cppPointerOfMesh)); + if(dynamic_cast(cppPointerOfMesh)) + return buildServantAndActivate2(dynamic_cast(cppPointerOfMesh)); if(dynamic_cast(cppPointerOfMesh)) return buildServantAndActivate2(dynamic_cast(cppPointerOfMesh)); throw INTERP_KERNEL::Exception("MEDCouplingMeshServant::_this2 : unrecognized type (or not managed type) of Mesh in input !"); @@ -239,6 +244,23 @@ namespace ParaMEDMEM } } }; + + class MEDCouplingIMeshServant + { + public: + %extend + { + static PyObject *_this(const MEDCouplingIMesh *cppPointerOfMesh) throw(INTERP_KERNEL::Exception) + { + return buildServantAndActivate(cppPointerOfMesh); + } + + static PyObject *_this2(const MEDCouplingIMesh *cppPointerOfMesh) throw(INTERP_KERNEL::Exception) + { + return buildServantAndActivate2(cppPointerOfMesh); + } + } + }; class MEDCouplingCurveLinearMeshServant { diff --git a/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTest.py b/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTest.py index f0e861a31..1b45eb98e 100644 --- a/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTest.py +++ b/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTest.py @@ -175,6 +175,21 @@ class MEDCouplingCorbaServBasicsTest: # return targetMesh; + def buildIMesh(self): + targetMesh=MEDCouplingIMesh.New(); + targetMesh.setTime(2.3,4,5); + targetMesh.setTimeUnit("us"); + targetMesh.setName("Example of IMesh"); + targetMesh.setDescription("buildIMesh"); + # + targetMesh.setSpaceDimension(3); + targetMesh.setNodeStruct([6,7,8]); + targetMesh.setOrigin([4.25,3.75,-6.125]); + targetMesh.setDXYZ([0.5,0.375,0.75]); + targetMesh.setAxisUnit("mm"); + # + return targetMesh + def buildCLMesh(self): targetMesh=MEDCouplingCurveLinearMesh(); targetMesh.setTime(2.3,4,5); diff --git a/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py b/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py index 8ba3fe901..e3f2383bb 100644 --- a/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py +++ b/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py @@ -72,6 +72,10 @@ class MEDCouplingMeshFieldFactoryComponentPy(MEDCouplingCorbaServantTest_idl._0_ mesh=self._test.buildCMesh() return MEDCouplingCMeshServant._this(mesh) + def getIMesh(self): + mesh=self._test.buildIMesh() + return MEDCouplingIMeshServant._this(mesh) + def getCLMesh(self): mesh=self._test.buildCLMesh() return MEDCouplingCurveLinearMeshServant._this(mesh) diff --git a/src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py b/src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py index 3b90840db..c997bebcc 100644 --- a/src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py +++ b/src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py @@ -136,6 +136,15 @@ class MEDCouplingCorbaServBasicsTestClt(unittest.TestCase): self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12)) pass + def testCorbaFetchingIMesh(self): + meshPtr=self._objC.getIMesh(); + _mesh_from_distant=MEDCouplingIMeshClient.New(meshPtr); + meshPtr.UnRegister(); + test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest() + meshRef=test.buildIMesh(); + self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12)) + pass + def testCorbaFetchingCLMesh(self): meshPtr=self._objC.getCLMesh(); _mesh_from_distant=MEDCouplingCurveLinearMeshClient.New(meshPtr); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index d21ab4ffd..fbc3370fe 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -14789,6 +14789,139 @@ class MEDCouplingBasicsTest(unittest.TestCase): j,k,l=r assert(inp.isEqual(DataArrayInt([a,b,c,d,e,f,g,h,i,j,k,l],4,3))) pass + + def testSwig2IMesh1(self): + """ 1st test of image grid mesh. + """ + m=MEDCouplingIMesh() + self.assertEqual(m.getSpaceDimension(),-1) + self.assertEqual(1,len(m.__repr__().split("\n"))) + self.assertEqual(6,len(m.__str__().split("\n"))) + self.assertRaises(InterpKernelException,m.getNodeStruct) + self.assertRaises(InterpKernelException,m.getOrigin) + self.assertRaises(InterpKernelException,m.getDXYZ) + m.setSpaceDimension(3) + self.assertEqual(9,len(m.__str__().split("\n"))) + self.assertEqual(4,len(m.__repr__().split("\n"))) + self.assertEqual((0,0,0),m.getNodeStruct()) + self.assertEqual((0.,0.,0.),m.getOrigin()) + self.assertEqual((0.,0.,0.),m.getDXYZ()) + self.assertRaises(InterpKernelException,m.setNodeStruct,[3,4]) + m.setNodeStruct([3,4,2]) + self.assertEqual((3,4,2),m.getNodeStruct()) + m.setOrigin(DataArrayDouble([1.5,2.5,3.5])) + self.assertEqual((1.5,2.5,3.5),m.getOrigin()) + m.setDXYZ((0.5,1.,0.25)) + self.assertEqual((0.5,1.,0.25),m.getDXYZ()) + for it in DataArrayDouble([(1.5,2.5,3.5)]): + m2=MEDCouplingIMesh("",3,DataArrayInt([3,4,2]),it,DataArrayDouble((0.5,1.,0.25))) + pass + self.assertEqual(3,m.getSpaceDimension()) + self.assertEqual((3,4,2),m2.getNodeStruct()) + self.assertEqual((1.5,2.5,3.5),m2.getOrigin()) + self.assertEqual((0.5,1.,0.25),m2.getDXYZ()) + self.assertEqual(24,m2.getNumberOfNodes()) + self.assertEqual(6,m2.getNumberOfCells()) + self.assertTrue(m.isEqual(m2,1e-12)) ; self.assertTrue(m.isEqualWithoutConsideringStr(m2,1e-12)) + m2.setAxisUnit("m") + self.assertTrue(not m.isEqual(m2,1e-12)) ; self.assertTrue(m.isEqualWithoutConsideringStr(m2,1e-12)) + m.setAxisUnit("m") + self.assertTrue(m.isEqual(m2,1e-12)) ; self.assertTrue(m.isEqualWithoutConsideringStr(m2,1e-12)) + m.setName("mesh") + self.assertTrue(not m.isEqual(m2,1e-12)) ; self.assertTrue(m.isEqualWithoutConsideringStr(m2,1e-12)) + m2.setName("mesh") + self.assertTrue(m.isEqual(m2,1e-12)) ; self.assertTrue(m.isEqualWithoutConsideringStr(m2,1e-12)) + m2.setTime(1.1,0,3) + self.assertTrue(not m.isEqual(m2,1e-12)) + m.setTime(1.1,0,3) + self.assertTrue(m.isEqual(m2,1e-12)) + m.setTimeUnit("ms") + self.assertTrue(not m.isEqual(m2,1e-12)) ; self.assertTrue(m.isEqualWithoutConsideringStr(m2,1e-12)) + m2.setTimeUnit("ms") + self.assertTrue(m.isEqual(m2,1e-12)) ; self.assertTrue(m.isEqualWithoutConsideringStr(m2,1e-12)) + # + m2.setNodeStruct([3,2,4]) + self.assertTrue(not m.isEqual(m2,1e-12)) + m.setNodeStruct([3,2,4]) + self.assertTrue(m.isEqual(m2,1e-12)) + m.setOrigin(DataArrayDouble([1.5,3.5,2.5])) + self.assertTrue(not m.isEqual(m2,1e-12)) + m2.setOrigin([1.5,3.5,2.5]) + self.assertTrue(m.isEqual(m2,1e-12)) + m.setDXYZ((0.5,0.25,1.)) + self.assertTrue(not m.isEqual(m2,1e-12)) + m2.setDXYZ(DataArrayDouble((0.5,0.25,1.))) + self.assertTrue(m.isEqual(m2,1e-12)) + m2bis=m2.deepCpy() + self.assertTrue(m2bis.isEqual(m2,1e-12)) + # + self.assertEqual(3,m.getMeshDimension()) + self.assertAlmostEqual(0.125,m.getMeasureOfAnyCell(),16); + mu=MEDCoupling1SGTUMesh(m.buildUnstructured()) + mu.checkCoherency2() + cooExp=DataArrayDouble([(1.5,3.5,2.5),(2,3.5,2.5),(2.5,3.5,2.5),(1.5,3.75,2.5),(2,3.75,2.5),(2.5,3.75,2.5),(1.5,3.5,3.5),(2,3.5,3.5),(2.5,3.5,3.5),(1.5,3.75,3.5),(2,3.75,3.5),(2.5,3.75,3.5),(1.5,3.5,4.5),(2,3.5,4.5),(2.5,3.5,4.5),(1.5,3.75,4.5),(2,3.75,4.5),(2.5,3.75,4.5),(1.5,3.5,5.5),(2,3.5,5.5),(2.5,3.5,5.5),(1.5,3.75,5.5),(2,3.75,5.5),(2.5,3.75,5.5)]) ; cooExp.setInfoOnComponents(["X [m]","Y [m]","Z [m]"]) + self.assertTrue(isinstance(mu,MEDCoupling1SGTUMesh)) + self.assertEqual(NORM_HEXA8,mu.getCellModelEnum()) + self.assertTrue(mu.getCoords().isEqual(cooExp,1e-12)) + self.assertTrue(mu.getNodalConnectivity().isEqual(DataArrayInt([1,0,3,4,7,6,9,10,2,1,4,5,8,7,10,11,7,6,9,10,13,12,15,16,8,7,10,11,14,13,16,17,13,12,15,16,19,18,21,22,14,13,16,17,20,19,22,23]))) + bary=m.getBarycenterAndOwner() + baryExp=DataArrayDouble([(1.75,3.625,3),(2.25,3.625,3),(1.75,3.625,4),(2.25,3.625,4),(1.75,3.625,5),(2.25,3.625,5)]) ; baryExp.setInfoOnComponents(["X [m]","Y [m]","Z [m]"]) + self.assertTrue(bary.isEqual(baryExp,1e-12)) + # + c=m.convertToCartesian() + c.checkCoherency() + self.assertEqual([1.1,0,3],c.getTime()) + self.assertEqual("ms",c.getTimeUnit()) + self.assertEqual(3,c.getMeshDimension()) + self.assertEqual(3,c.getSpaceDimension()) + arrX=DataArrayDouble([1.5,2.,2.5]) ; arrX.setInfoOnComponents(["X [m]"]) + self.assertTrue(c.getCoordsAt(0).isEqual(arrX,1e-12)) + arrY=DataArrayDouble([3.5,3.75]) ; arrY.setInfoOnComponents(["Y [m]"]) + self.assertTrue(c.getCoordsAt(1).isEqual(arrY,1e-12)) + arrZ=DataArrayDouble([2.5,3.5,4.5,5.5]) ; arrZ.setInfoOnComponents(["Z [m]"]) + self.assertTrue(c.getCoordsAt(2).isEqual(arrZ,1e-12)) + self.assertTrue(c.buildUnstructured().isEqual(m.buildUnstructured(),1e-12)) + # + a,b=m.getCellsContainingPoints(baryExp,1e-12) + self.assertTrue(a.isEqual(DataArrayInt([0,1,2,3,4,5]))) + self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,4,5,6]))) + for a,b in enumerate(baryExp): + self.assertEqual(a,m.getCellContainingPoint(b,1e-12)) + pass + # + m.translate([1.,2.,4.]) + self.assertEqual((3,2,4),m.getNodeStruct()) + self.assertEqual((2.5,5.5,6.5),m.getOrigin()) + self.assertEqual((0.5,0.25,1.),m.getDXYZ()) + m.scale([0.,1.,3.],2.) + self.assertAlmostEqual(1.,m.getMeasureOfAnyCell(),16); + self.assertEqual((3,2,4),m.getNodeStruct()) + self.assertEqual((5.,10.,10.),m.getOrigin()) + self.assertEqual((1.,0.5,2.),m.getDXYZ()) + # + f=m.getMeasureField(False) + f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(1.1,0,3) ; f2.setMesh(m) ; arr=DataArrayDouble(6) ; arr[:]=1. ; f2.setArray(arr) ; f2.setTimeUnit("ms") + f2.setName("MeasureOfMesh_mesh") + self.assertTrue(f.isEqual(f2,1e-12,1e-12)) + # + m3=m.buildStructuredSubPart([(1,2),(0,1),(1,3)]) + self.assertEqual((2,2,3),m3.getNodeStruct()) + self.assertEqual((6.,10.,12.),m3.getOrigin()) + self.assertEqual((1.,0.5,2.),m3.getDXYZ()) + # now playing with 3D surf + m4=MEDCouplingIMesh("",3,DataArrayInt([3,1,4]),DataArrayDouble([1.5,2.5,3.5]),DataArrayDouble((0.5,1.,0.25))) ; m4.setAxisUnit("km") + self.assertEqual(3,m4.getSpaceDimension()) + self.assertEqual(2,m4.getMeshDimension()) + self.assertEqual(12,m4.getNumberOfNodes()) + self.assertEqual(6,m4.getNumberOfCells()) + mu=MEDCoupling1SGTUMesh(m4.buildUnstructured()) + mu.checkCoherency2() + self.assertTrue(isinstance(mu,MEDCoupling1SGTUMesh)) + self.assertEqual(NORM_QUAD4,mu.getCellModelEnum()) + coordsExp=DataArrayDouble([(1.5,2.5,3.5),(2,2.5,3.5),(2.5,2.5,3.5),(1.5,2.5,3.75),(2,2.5,3.75),(2.5,2.5,3.75),(1.5,2.5,4),(2,2.5,4),(2.5,2.5,4),(1.5,2.5,4.25),(2,2.5,4.25),(2.5,2.5,4.25)]) ; coordsExp.setInfoOnComponents(["X [km]","Y [km]","Z [km]"]) + self.assertTrue(mu.getCoords().isEqual(coordsExp,1e-12)) + self.assertTrue(mu.getNodalConnectivity().isEqual(DataArrayInt([1,0,3,4,2,1,4,5,4,3,6,7,5,4,7,8,7,6,9,10,8,7,10,11]))) + pass def setUp(self): pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 62158e784..3efdfc62f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -28,6 +28,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingExtrudedMesh.hxx" #include "MEDCouplingCMesh.hxx" +#include "MEDCouplingIMesh.hxx" #include "MEDCouplingCurveLinearMesh.hxx" #include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingField.hxx" @@ -301,6 +302,8 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingCMesh::New; %newobject ParaMEDMEM::MEDCouplingCMesh::clone; %newobject ParaMEDMEM::MEDCouplingCMesh::getCoordsAt; +%newobject ParaMEDMEM::MEDCouplingIMesh::New; +%newobject ParaMEDMEM::MEDCouplingIMesh::convertToCartesian; %newobject ParaMEDMEM::MEDCouplingCurveLinearMesh::New; %newobject ParaMEDMEM::MEDCouplingCurveLinearMesh::clone; %newobject ParaMEDMEM::MEDCouplingCurveLinearMesh::getCoords; @@ -2856,19 +2859,19 @@ namespace ParaMEDMEM class MEDCouplingCMesh : public ParaMEDMEM::MEDCouplingStructuredMesh { public: - static MEDCouplingCMesh *New(); - static MEDCouplingCMesh *New(const std::string& meshName); + static MEDCouplingCMesh *New() throw(INTERP_KERNEL::Exception); + static MEDCouplingCMesh *New(const std::string& meshName) throw(INTERP_KERNEL::Exception); MEDCouplingCMesh *clone(bool recDeepCpy) const; void setCoords(const DataArrayDouble *coordsX, const DataArrayDouble *coordsY=0, const DataArrayDouble *coordsZ=0) throw(INTERP_KERNEL::Exception); void setCoordsAt(int i, const DataArrayDouble *arr) throw(INTERP_KERNEL::Exception); %extend { - MEDCouplingCMesh() + MEDCouplingCMesh() throw(INTERP_KERNEL::Exception) { return MEDCouplingCMesh::New(); } - MEDCouplingCMesh(const std::string& meshName) + MEDCouplingCMesh(const std::string& meshName) throw(INTERP_KERNEL::Exception) { return MEDCouplingCMesh::New(meshName); } @@ -2899,16 +2902,16 @@ namespace ParaMEDMEM class MEDCouplingCurveLinearMesh : public ParaMEDMEM::MEDCouplingStructuredMesh { public: - static MEDCouplingCurveLinearMesh *New(); - static MEDCouplingCurveLinearMesh *New(const std::string& meshName); + static MEDCouplingCurveLinearMesh *New() throw(INTERP_KERNEL::Exception); + static MEDCouplingCurveLinearMesh *New(const std::string& meshName) throw(INTERP_KERNEL::Exception); MEDCouplingCurveLinearMesh *clone(bool recDeepCpy) const; void setCoords(const DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); %extend { - MEDCouplingCurveLinearMesh() + MEDCouplingCurveLinearMesh() throw(INTERP_KERNEL::Exception) { return MEDCouplingCurveLinearMesh::New(); } - MEDCouplingCurveLinearMesh(const std::string& meshName) + MEDCouplingCurveLinearMesh(const std::string& meshName) throw(INTERP_KERNEL::Exception) { return MEDCouplingCurveLinearMesh::New(meshName); } @@ -2940,6 +2943,99 @@ namespace ParaMEDMEM }; //== MEDCouplingCurveLinearMesh End + + //== MEDCouplingIMesh + + class MEDCouplingIMesh : public ParaMEDMEM::MEDCouplingStructuredMesh + { + public: + static MEDCouplingIMesh *New() throw(INTERP_KERNEL::Exception); + // + void setSpaceDimension(int spaceDim) throw(INTERP_KERNEL::Exception); + std::vector getNodeStruct() const throw(INTERP_KERNEL::Exception); + std::vector getOrigin() const throw(INTERP_KERNEL::Exception); + std::vector getDXYZ() const throw(INTERP_KERNEL::Exception); + void setAxisUnit(const std::string& unitName) throw(INTERP_KERNEL::Exception); + std::string getAxisUnit() const throw(INTERP_KERNEL::Exception); + double getMeasureOfAnyCell() const throw(INTERP_KERNEL::Exception); + MEDCouplingCMesh *convertToCartesian() const throw(INTERP_KERNEL::Exception); + %extend + { + MEDCouplingIMesh() + { + return MEDCouplingIMesh::New(); + } + static MEDCouplingIMesh *New(const std::string& meshName, int spaceDim, PyObject *nodeStrct, PyObject *origin, PyObject *dxyz) throw(INTERP_KERNEL::Exception) + { + static const char msg0[]="MEDCouplingIMesh::New : error on 'origin' parameter !"; + static const char msg1[]="MEDCouplingIMesh::New : error on 'dxyz' parameter !"; + const int *nodeStrctPtr(0); + const double *originPtr(0),*dxyzPtr(0); + int sw,sz,val0; + std::vector bb0; + nodeStrctPtr=convertObjToPossibleCpp1_Safe(nodeStrct,sw,sz,val0,bb0); + // + double val,val2; + std::vector bb,bb2; + int sz1,sz2; + originPtr=convertObjToPossibleCpp5_SingleCompo(origin,sw,val,bb,msg0,false,sz1); + dxyzPtr=convertObjToPossibleCpp5_SingleCompo(dxyz,sw,val2,bb2,msg1,false,sz2); + // + return MEDCouplingIMesh::New(meshName,spaceDim,nodeStrctPtr,nodeStrctPtr+sz,originPtr,originPtr+sz1,dxyzPtr,dxyzPtr+sz2); + } + + MEDCouplingIMesh(const std::string& meshName, int spaceDim, PyObject *nodeStrct, PyObject *origin, PyObject *dxyz) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_MEDCouplingIMesh_New__SWIG_1(meshName,spaceDim,nodeStrct,origin,dxyz); + } + + void setNodeStruct(PyObject *nodeStrct) throw(INTERP_KERNEL::Exception) + { + int sw,sz,val0; + std::vector bb0; + const int *nodeStrctPtr(convertObjToPossibleCpp1_Safe(nodeStrct,sw,sz,val0,bb0)); + self->setNodeStruct(nodeStrctPtr,nodeStrctPtr+sz); + } + + void setOrigin(PyObject *origin) throw(INTERP_KERNEL::Exception) + { + static const char msg[]="MEDCouplingIMesh::setOrigin : invalid input 'origin' parameter ! integer, float, list/tuple of float, DataArrayDouble or DataArrayDoubleTuple supported !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw,nbTuples; + const double *originPtr(convertObjToPossibleCpp5_SingleCompo(origin,sw,val,bb,msg,false,nbTuples)); + self->setOrigin(originPtr,originPtr+nbTuples); + } + + void setDXYZ(PyObject *dxyz) throw(INTERP_KERNEL::Exception) + { + static const char msg[]="MEDCouplingIMesh::setDXYZ : invalid input 'dxyz' parameter ! integer, float, list/tuple of float, DataArrayDouble or DataArrayDoubleTuple supported !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw,nbTuples; + const double *originPtr(convertObjToPossibleCpp5_SingleCompo(dxyz,sw,val,bb,msg,false,nbTuples)); + self->setDXYZ(originPtr,originPtr+nbTuples); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + } + }; + + //== MEDCouplingIMesh End + } namespace ParaMEDMEM diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 7d583d4c8..e7e283efc 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -242,6 +242,7 @@ namespace ParaMEDMEM static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception); static std::string GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); + static std::string BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit) throw(INTERP_KERNEL::Exception); void updateTime() const; %extend { diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index b2e7702c1..f0382c2cd 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -40,6 +40,8 @@ static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingIMesh,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !"); return ret; -- 2.30.2