From: ageay Date: Fri, 17 Apr 2009 08:27:39 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V5_1_main_FINAL~399 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0634ef1bc982dc775e4bf854b7944956523efc51;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx new file mode 100644 index 000000000..33f7214c0 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -0,0 +1,182 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#include "MEDCouplingCMesh.hxx" +#include "MEDCouplingMemArray.hxx" + +using namespace ParaMEDMEM; + +MEDCouplingCMesh::MEDCouplingCMesh():_x_array(0),_y_array(0),_z_array(0) +{ +} + +MEDCouplingCMesh::~MEDCouplingCMesh() +{ + if(_x_array) + _x_array->decrRef(); + if(_y_array) + _y_array->decrRef(); + if(_z_array) + _z_array->decrRef(); +} + +MEDCouplingCMesh *MEDCouplingCMesh::New() +{ + return new MEDCouplingCMesh; +} + +void MEDCouplingCMesh::updateTime() +{ + if(_x_array) + updateTimeWith(*_x_array); + if(_y_array) + updateTimeWith(*_y_array); + if(_z_array) + updateTimeWith(*_z_array); +} + +bool MEDCouplingCMesh::isEqual(const MEDCouplingMesh *other, double prec) const +{ + const MEDCouplingCMesh *otherC=dynamic_cast(other); + if(!otherC) + return false; + return true; +} + +void MEDCouplingCMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +{ + const char msg0[]="Invalid "; + const char msg1[]=" array ! Must contain more than 1 element."; + if(_x_array) + if(_x_array->getNbOfElems()<2) + { + std::ostringstream os; os << msg0 << 'X' << msg1; + throw INTERP_KERNEL::Exception(os.str().c_str()); + } + if(_y_array) + if(_y_array->getNbOfElems()<2) + { + std::ostringstream os; os << msg0 << 'Y' << msg1; + throw INTERP_KERNEL::Exception(os.str().c_str()); + } + if(_z_array) + if(_z_array->getNbOfElems()<2) + { + std::ostringstream os; os << msg0 << 'Z' << msg1; + throw INTERP_KERNEL::Exception(os.str().c_str()); + } +} + +bool MEDCouplingCMesh::isStructured() const +{ + return true; +} + +int MEDCouplingCMesh::getNumberOfCells() const +{ + int ret=1; + if(_x_array) + ret*=_x_array->getNbOfElems()-1; + if(_y_array) + ret*=_y_array->getNbOfElems()-1; + if(_z_array) + ret*=_z_array->getNbOfElems()-1; + return ret; +} + +int MEDCouplingCMesh::getNumberOfNodes() const +{ + int ret=1; + if(_x_array) + ret*=_x_array->getNbOfElems(); + if(_y_array) + ret*=_y_array->getNbOfElems(); + if(_z_array) + ret*=_z_array->getNbOfElems(); + return ret; +} + +int MEDCouplingCMesh::getSpaceDimension() const +{ + int ret=0; + if(_x_array) + ret++; + if(_y_array) + ret++; + if(_z_array) + ret++; + return ret; +} + +int MEDCouplingCMesh::getMeshDimension() const +{ + int ret=0; + if(_x_array) + ret++; + if(_y_array) + ret++; + if(_z_array) + ret++; + return ret; +} + +DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) const throw(INTERP_KERNEL::Exception) +{ + switch(i) + { + case 0: + return _x_array; + case 1: + return _y_array; + case 2: + return _z_array; + default: + throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2."); + } +} + +void MEDCouplingCMesh::setCoords(DataArrayDouble *coordsX, DataArrayDouble *coordsY, DataArrayDouble *coordsZ) +{ + if(_x_array) + _x_array->decrRef(); + _x_array=coordsX; + if(_x_array) + _x_array->incrRef(); + if(_y_array) + _y_array->decrRef(); + _y_array=coordsY; + if(_y_array) + _y_array->incrRef(); + if(_z_array) + _z_array->decrRef(); + _z_array=coordsZ; + if(_z_array) + _z_array->incrRef(); + declareAsNew(); +} + +void MEDCouplingCMesh::getBoundingBox(double *bbox) const +{ + //not implemented yet ! +} + +MEDCouplingFieldDouble *MEDCouplingCMesh::getMeasureField() const +{ + //not implemented yet ! + return 0; +} diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx new file mode 100644 index 000000000..212535c44 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#ifndef __PARAMEDMEM_MEDCOUPLINGCMESH_HXX__ +#define __PARAMEDMEM_MEDCOUPLINGCMESH_HXX__ + +#include "MEDCoupling.hxx" +#include "MEDCouplingMesh.hxx" + +namespace ParaMEDMEM +{ + class DataArrayDouble; + + class MEDCouplingCMesh : public MEDCouplingMesh + { + public: + static MEDCouplingCMesh *New(); + void updateTime(); + MEDCouplingMeshType getType() const { return CARTESIAN; } + bool isEqual(const MEDCouplingMesh *other, double prec) const; + void checkCoherency() const throw(INTERP_KERNEL::Exception); + bool isStructured() const; + int getNumberOfCells() const; + int getNumberOfNodes() const; + int getSpaceDimension() const; + int getMeshDimension() const; + DataArrayDouble *getCoordsAt(int i) const throw(INTERP_KERNEL::Exception); + void setCoords(DataArrayDouble *coordsX, + DataArrayDouble *coordsY=0, + DataArrayDouble *coordsZ=0); + // tools + void getBoundingBox(double *bbox) const; + MEDCouplingFieldDouble *getMeasureField() const; + private: + MEDCouplingCMesh(); + ~MEDCouplingCMesh(); + private: + DataArrayDouble *_x_array; + DataArrayDouble *_y_array; + DataArrayDouble *_z_array; + }; +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 1a65f4722..c5b53a5f8 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -22,6 +22,23 @@ using namespace ParaMEDMEM; +bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const +{ + if(_name!=other->_name) + return false; + if(_desc!=other->_desc) + return false; + if(!_type->isEqual(other->_type)) + return false; + if(_mesh==0 && other->_mesh==0) + return true; + if(_mesh==0 || other->_mesh==0) + return false; + if(_mesh==other->_mesh) + return true; + return _mesh->isEqual(other->_mesh,meshPrec); +} + void MEDCouplingField::updateTime() { if(_mesh) @@ -33,12 +50,12 @@ TypeOfField MEDCouplingField::getEntity() const return _type->getEnum(); } -void MEDCouplingField::setMesh(MEDCouplingMesh *mesh) +void MEDCouplingField::setMesh(const MEDCouplingMesh *mesh) { if(mesh!=_mesh) { if(_mesh) - _mesh->decrRef(); + ((MEDCouplingMesh *)_mesh)->decrRef(); _mesh=mesh; if(_mesh) { @@ -51,7 +68,7 @@ void MEDCouplingField::setMesh(MEDCouplingMesh *mesh) MEDCouplingField::~MEDCouplingField() { if(_mesh) - _mesh->decrRef(); + ((MEDCouplingMesh *)_mesh)->decrRef(); delete _type; } diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index 55c32688f..5f59bccfe 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -20,7 +20,8 @@ #define __PARAMEDMEM_MEDCOUPLINGFIELD_HXX__ #include "MEDCoupling.hxx" -#include "RefCountObject.hxx" +#include "MEDCouplingTimeLabel.hxx" +#include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" #include @@ -30,13 +31,15 @@ namespace ParaMEDMEM class MEDCouplingMesh; class MEDCouplingFieldDiscretization; - class MEDCOUPLING_EXPORT MEDCouplingField : public RefCountObject + class MEDCOUPLING_EXPORT MEDCouplingField : public RefCountObject, public TimeLabel { public: virtual void checkCoherency() const throw(INTERP_KERNEL::Exception) = 0; - void setMesh(ParaMEDMEM::MEDCouplingMesh *mesh); - ParaMEDMEM::MEDCouplingMesh *getMesh() const { return _mesh; } + virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; + void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh); + const ParaMEDMEM::MEDCouplingMesh *getMesh() const { return _mesh; } void setName(const char *name) { _name=name; } + const char *getDescription() const { return _desc.c_str(); } void setDescription(const char *desc) { _desc=desc; } const char *getName() const { return _name.c_str(); } TypeOfField getEntity() const; @@ -49,7 +52,7 @@ namespace ParaMEDMEM protected: std::string _name; std::string _desc; - MEDCouplingMesh *_mesh; + const MEDCouplingMesh *_mesh; MEDCouplingFieldDiscretization *_type; }; } diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 2b45ef279..844f67eee 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -58,11 +58,21 @@ const char *MEDCouplingFieldDiscretizationP0::getStringRepr() const return REPR; } +bool MEDCouplingFieldDiscretizationP0::isEqual(const MEDCouplingFieldDiscretization *other) const +{ + const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast(other); + return otherC!=0; +} + int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const { return mesh->getNumberOfCells(); } +void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +{ +} + void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) { if(mesh->getNumberOfCells()!=da->getNumberOfTuples()) @@ -94,11 +104,23 @@ const char *MEDCouplingFieldDiscretizationP1::getStringRepr() const return REPR; } +bool MEDCouplingFieldDiscretizationP1::isEqual(const MEDCouplingFieldDiscretization *other) const +{ + const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast(other); + return otherC!=0; +} + int MEDCouplingFieldDiscretizationP1::getNumberOfTuples(const MEDCouplingMesh *mesh) const { return mesh->getNumberOfNodes(); } +void MEDCouplingFieldDiscretizationP1::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +{ + if(nat!=ConservativeVolumic) + throw INTERP_KERNEL::Exception("Invalid nature for P1 field !"); +} + void MEDCouplingFieldDiscretizationP1::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) { if(mesh->getNumberOfNodes()!=da->getNumberOfTuples()) diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 3c0c54332..35b83f809 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -20,8 +20,9 @@ #define __MEDCOUPLINGFIELDDISCRETIZATION_HXX__ #include "MEDCoupling.hxx" -#include "RefCountObject.hxx" +#include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" +#include "MEDCouplingNatureOfField.hxx" namespace ParaMEDMEM { @@ -34,9 +35,11 @@ namespace ParaMEDMEM public: static MEDCouplingFieldDiscretization *New(TypeOfField type); virtual TypeOfField getEnum() const = 0; + virtual bool isEqual(const MEDCouplingFieldDiscretization *other) const = 0; virtual MEDCouplingFieldDiscretization *clone() const = 0; virtual const char *getStringRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const = 0; + virtual void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) = 0; virtual void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) = 0; virtual MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh) const = 0; }; @@ -47,7 +50,9 @@ namespace ParaMEDMEM TypeOfField getEnum() const; MEDCouplingFieldDiscretization *clone() const; const char *getStringRepr() const; + bool isEqual(const MEDCouplingFieldDiscretization *other) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; + void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh) const; public: @@ -61,7 +66,9 @@ namespace ParaMEDMEM TypeOfField getEnum() const; MEDCouplingFieldDiscretization *clone() const; const char *getStringRepr() const; + bool isEqual(const MEDCouplingFieldDiscretization *other) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; + void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh) const; public: diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 40cc57247..6b1fa4e64 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -35,12 +35,31 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const return new MEDCouplingFieldDouble(*this,recDeepCpy); } -MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type), +bool MEDCouplingFieldDouble::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const +{ + const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_nature!=otherC->_nature) + return false; + if(!MEDCouplingField::isEqual(other,meshPrec,valsPrec)) + return false; + if(!_time_discr->isEqual(otherC->_time_discr,valsPrec)) + return false; + return true; +} + +TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const +{ + return _time_discr->getEnum(); +} + +MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),_nature(NoNature), _time_discr(MEDCouplingTimeDiscretization::New(td)) { } -MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy):MEDCouplingField(other), +MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy):MEDCouplingField(other),_nature(other._nature), _time_discr(other._time_discr->performCpy(deepCpy)) { } @@ -123,7 +142,76 @@ void MEDCouplingFieldDouble::updateTime() updateTimeWith(*getArray()); } +void MEDCouplingFieldDouble::setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception) +{ + _type->checkCompatibilityWithNature(nat); + _nature=nat; +} + void MEDCouplingFieldDouble::setArray(DataArrayDouble *array) { _time_discr->setArray(array,this); } + +void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector& tinyInfo) const +{ + tinyInfo.clear(); + _time_discr->getTinySerializationStrInformation(tinyInfo); + tinyInfo.push_back(_name); + tinyInfo.push_back(_desc); +} + +/*! + * This method retrieves some critical values to resize and prepare remote instance. + * The first two elements returned in tinyInfo correspond to the parameters to give in constructor. + * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. + */ +void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector& tinyInfo) const +{ + tinyInfo.clear(); + tinyInfo.push_back((int)_type->getEnum()); + tinyInfo.push_back((int)_time_discr->getEnum()); + tinyInfo.push_back((int)_nature); + _time_discr->getTinySerializationIntInformation(tinyInfo); +} + +/*! + * This method retrieves some critical values to resize and prepare remote instance. + * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. + */ +void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector& tinyInfo) const +{ + tinyInfo.clear(); + _time_discr->getTinySerializationDbleInformation(tinyInfo); +} + +/*! + * This method has to be called to the new instance filled by CORBA, MPI, File... + * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied. + * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by 'this' after the call of this method. + * No decrRef must be applied to every instances in returned vector. + */ +void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays) +{ + std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); + _time_discr->resizeForUnserialization(tinyInfoI2,arrays); +} + +void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) +{ + std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); + _time_discr->finishUnserialization(tinyInfoI2,tinyInfoD,tinyInfoS); + _nature=(NatureOfField)tinyInfoI[2]; + int nbOfElemS=tinyInfoS.size(); + _name=tinyInfoS[nbOfElemS-2]; + _desc=tinyInfoS[nbOfElemS-1]; +} + +/*! + * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities af the caller. + * The values returned must be consulted only in readonly mode. + */ +void MEDCouplingFieldDouble::serialize(std::vector& arrays) const +{ + _time_discr->getArrays(arrays); +} diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 8a7d32967..a05035b0f 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -22,7 +22,8 @@ #include "MEDCoupling.hxx" #include "MEDCouplingField.hxx" #include "MEDCouplingTimeDiscretization.hxx" -#include "MemArray.hxx" +#include "MEDCouplingNatureOfField.hxx" +#include "MEDCouplingMemArray.hxx" namespace ParaMEDMEM { @@ -30,8 +31,12 @@ namespace ParaMEDMEM { public: static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=NO_TIME); + bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; MEDCouplingFieldDouble *clone(bool recDeepCpy) const; + TypeOfTimeDiscretization getTimeDiscretization() const; void checkCoherency() const throw(INTERP_KERNEL::Exception); + NatureOfField getNature() const { return _nature; } + void setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception); void setTime(double val, int dt, int it) { _time_discr->setTime(val,dt,it); } double getTime(int& dt, int& it) const { return _time_discr->getTime(dt,it); } double getIJ(int tupleId, int compoId) const { return getArray()->getIJ(tupleId,compoId); } @@ -46,11 +51,19 @@ namespace ParaMEDMEM int getNumberOfComponents() const; int getNumberOfTuples() const throw(INTERP_KERNEL::Exception); void updateTime(); + // + void getTinySerializationIntInformation(std::vector& tinyInfo) const; + void getTinySerializationDbleInformation(std::vector& tinyInfo) const; + void getTinySerializationStrInformation(std::vector& tinyInfo) const; + void resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays); + void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); + void serialize(std::vector& arrays) const; private: MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy); ~MEDCouplingFieldDouble(); private: + NatureOfField _nature; MEDCouplingTimeDiscretization *_time_discr; }; } diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx new file mode 100644 index 000000000..b907df1f8 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -0,0 +1,161 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#include "MEDCouplingMemArray.txx" + +using namespace ParaMEDMEM; + +void DataArray::setName(const char *name) +{ + _name=name; +} + +bool DataArray::areInfoEquals(const DataArray& other) const +{ + if(_nb_of_tuples!=other._nb_of_tuples) + return false; + if(_name!=other._name) + return false; + return _info_on_compo==other._info_on_compo; +} + +DataArrayDouble *DataArrayDouble::New() +{ + return new DataArrayDouble; +} + +DataArrayDouble *DataArrayDouble::deepCopy() const +{ + return new DataArrayDouble(*this); +} + +DataArrayDouble *DataArrayDouble::performCpy(bool deepCpy) const +{ + if(deepCpy) + return deepCopy(); + else + { + incrRef(); + return const_cast(this); + } +} + +void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) +{ + _nb_of_tuples=nbOfTuple; + _info_on_compo.resize(nbOfCompo); + _mem.alloc(nbOfCompo*_nb_of_tuples); + declareAsNew(); +} + +bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const +{ + if(!areInfoEquals(other)) + return false; + return _mem.isEqual(other._mem,prec); +} + +void DataArrayDouble::reAlloc(int nbOfTuples) +{ + _mem.reAlloc(_info_on_compo.size()*nbOfTuples); + _nb_of_tuples=nbOfTuples; + declareAsNew(); +} + +void DataArrayDouble::setArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet) +{ + if(newArray!=arrayToSet) + { + if(arrayToSet) + arrayToSet->decrRef(); + arrayToSet=newArray; + if(arrayToSet) + arrayToSet->incrRef(); + } +} + +void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) +{ + _nb_of_tuples=nbOfTuple; + _info_on_compo.resize(nbOfCompo); + _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); + declareAsNew(); +} + +DataArrayInt *DataArrayInt::New() +{ + return new DataArrayInt; +} + +DataArrayInt *DataArrayInt::deepCopy() const +{ + return new DataArrayInt(*this); +} + +DataArrayInt *DataArrayInt::performCpy(bool deepCpy) const +{ + if(deepCpy) + return deepCopy(); + else + { + incrRef(); + return const_cast(this); + } +} + +void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) +{ + _nb_of_tuples=nbOfTuple; + _info_on_compo.resize(nbOfCompo); + _mem.alloc(nbOfCompo*_nb_of_tuples); + declareAsNew(); +} + +bool DataArrayInt::isEqual(const DataArrayInt& other) const +{ + if(!areInfoEquals(other)) + return false; + return _mem.isEqual(other._mem,0); +} + +void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) +{ + _nb_of_tuples=nbOfTuple; + _info_on_compo.resize(nbOfCompo); + _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); + declareAsNew(); +} + +void DataArrayInt::reAlloc(int nbOfTuples) +{ + _mem.reAlloc(_info_on_compo.size()*nbOfTuples); + _nb_of_tuples=nbOfTuples; + declareAsNew(); +} + +void DataArrayInt::setArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet) +{ + if(newArray!=arrayToSet) + { + if(arrayToSet) + arrayToSet->decrRef(); + arrayToSet=newArray; + if(arrayToSet) + arrayToSet->incrRef(); + } +} diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx new file mode 100644 index 000000000..1865161d6 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -0,0 +1,155 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#ifndef __PARAMEDMEM_MEDCOUPLINGMEMARRAY_HXX__ +#define __PARAMEDMEM_MEDCOUPLINGMEMARRAY_HXX__ + +#include "MEDCoupling.hxx" +#include "MEDCouplingTimeLabel.hxx" +#include "MEDCouplingRefCountObject.hxx" +#include "InterpKernelException.hxx" + +#include +#include + +namespace ParaMEDMEM +{ + template + class MEDCouplingPointer + { + public: + MEDCouplingPointer():_internal(0),_external(0) { } + void null() { _internal=0; _external=0; } + bool isNull() const { return _internal==0 && _external==0; } + void setInternal(T *pointer); + void setExternal(const T *pointer); + const T *getConstPointer() const { if(_internal) return _internal; else return _external; } + const T *getConstPointerLoc(int offset) const { if(_internal) return _internal+offset; else return _external+offset; } + T *getPointer() const { if(_internal) return _internal; if(_external) throw INTERP_KERNEL::Exception("Trying to write on an external pointer."); else return 0; } + private: + T *_internal; + const T *_external; + }; + + template + class MemArray + { + public: + MemArray():_nb_of_elem(-1),_ownership(false),_dealloc(CPP_DEALLOC) { } + MemArray(const MemArray& other); + const T *getConstPointerLoc(int offset) const { return _pointer.getConstPointerLoc(offset); } + const T *getConstPointer() const { return _pointer.getConstPointer(); } + T *getPointer() const { return _pointer.getPointer(); } + MemArray &operator=(const MemArray& other); + T operator[](int id) const { return _pointer.getConstPointer()[id]; } + T& operator[](int id) { return _pointer.getPointer()[id]; } + bool isEqual(const MemArray& other, T prec) const; + void alloc(int nbOfElements); + void reAlloc(int newNbOfElements); + void useArray(const T *array, bool ownership, DeallocType type, int nbOfElem); + void writeOnPlace(int id, T element0, const T *others, int sizeOfOthers); + ~MemArray() { destroy(); } + private: + void destroy(); + static void destroyPointer(T *pt, DeallocType type); + private: + int _nb_of_elem; + bool _ownership; + MEDCouplingPointer _pointer; + //T *_pointer; + DeallocType _dealloc; + }; + + class MEDCOUPLING_EXPORT DataArray : public RefCountObject, public TimeLabel + { + public: + void setName(const char *name); + bool areInfoEquals(const DataArray& other) const; + std::string getName() const { return _name; } + std::string getInfoOnComponent(int i) const { return _info_on_compo[i]; } + void setInfoOnComponent(int i, const char *info) { _info_on_compo[i]=info; } + int getNumberOfComponents() const { return _info_on_compo.size(); } + int getNumberOfTuples() const { return _nb_of_tuples; } + int getNbOfElems() const { return _info_on_compo.size()*_nb_of_tuples; } + protected: + DataArray():_nb_of_tuples(-1) { } + protected: + int _nb_of_tuples; + std::string _name; + std::vector _info_on_compo; + }; +} + +#include "MEDCouplingMemArray.txx" + +namespace ParaMEDMEM +{ + class MEDCOUPLING_EXPORT DataArrayDouble : public DataArray + { + public: + static DataArrayDouble *New(); + DataArrayDouble *deepCopy() const; + DataArrayDouble *performCpy(bool deepCpy) const; + void alloc(int nbOfTuple, int nbOfCompo); + bool isEqual(const DataArrayDouble& other, double prec) const; + //!alloc or useArray should have been called before. + void reAlloc(int nbOfTuples); + void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } + double getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } + void setIJ(int tupleId, int compoId, double newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } + double *getPointer() const { return _mem.getPointer(); } + static void setArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet); + const double *getConstPointer() const { return _mem.getConstPointer(); } + void useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); + void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } + //! nothing to do here because this class does not aggregate any TimeLabel instance. + void updateTime() { } + private: + DataArrayDouble() { } + private: + MemArray _mem; + }; + + class MEDCOUPLING_EXPORT DataArrayInt : public DataArray + { + public: + static DataArrayInt *New(); + DataArrayInt *deepCopy() const; + DataArrayInt *performCpy(bool deepCpy) const; + void alloc(int nbOfTuple, int nbOfCompo); + bool isEqual(const DataArrayInt& other) const; + //!alloc or useArray should have been called before. + void reAlloc(int nbOfTuples); + void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } + int getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } + void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } + int *getPointer() const { return _mem.getPointer(); } + static void setArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet); + const int *getConstPointer() const { return _mem.getConstPointer(); } + void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); + void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } + //! nothing to do here because this class does not aggregate any TimeLabel instance. + void updateTime() { } + private: + DataArrayInt() { } + private: + MemArray _mem; + }; +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx new file mode 100644 index 000000000..8d6a8191f --- /dev/null +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -0,0 +1,159 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#ifndef __PARAMEDMEM_MEDCOUPLINGMEMARRAY_TXX__ +#define __PARAMEDMEM_MEDCOUPLINGMEMARRAY_TXX__ + +#include "MEDCouplingMemArray.hxx" +#include "NormalizedUnstructuredMesh.hxx" +#include "InterpKernelException.hxx" + +#include +#include + +namespace ParaMEDMEM +{ + template + void MEDCouplingPointer::setInternal(T *pointer) + { + _internal=pointer; + _external=0; + } + + template + void MEDCouplingPointer::setExternal(const T *pointer) + { + _external=pointer; + _internal=0; + } + + template + MemArray::MemArray(const MemArray& other):_nb_of_elem(-1),_ownership(false),_dealloc(CPP_DEALLOC) + { + if(!other._pointer.isNull()) + { + T *pointer=new T[other._nb_of_elem]; + std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+other._nb_of_elem,pointer); + useArray(pointer,true,CPP_DEALLOC,other._nb_of_elem); + } + } + + template + void MemArray::useArray(const T *array, bool ownership, DeallocType type, int nbOfElem) + { + _nb_of_elem=nbOfElem; + destroy(); + if(ownership) + _pointer.setInternal((T *)array); + else + _pointer.setExternal(array); + _ownership=ownership; + _dealloc=type; + } + + template + void MemArray::writeOnPlace(int id, T element0, const T *others, int sizeOfOthers) + { + if(id+sizeOfOthers>=_nb_of_elem) + reAlloc(2*_nb_of_elem+sizeOfOthers+1); + T *pointer=_pointer.getPointer(); + pointer[id]=element0; + std::copy(others,others+sizeOfOthers,pointer+id+1); + } + + template + bool MemArray::isEqual(const MemArray& other, T prec) const + { + if(_nb_of_elem!=other._nb_of_elem) + return false; + const T *pt1=_pointer.getConstPointer(); + const T *pt2=other._pointer.getConstPointer(); + if(pt1==0 && pt2==0) + return true; + if(pt1==0 || pt2==0) + return false; + for(int i=0;i<_nb_of_elem;i++) + if(pt1[i]-pt2[i]<-prec || (pt1[i]-pt2[i])>prec) + return false; + return true; + } + + template + void MemArray::alloc(int nbOfElements) + { + destroy(); + _nb_of_elem=nbOfElements; + _pointer.setInternal(new T[_nb_of_elem]); + _ownership=true; + _dealloc=CPP_DEALLOC; + } + + template + void MemArray::reAlloc(int newNbOfElements) + { + T *pointer=new T[newNbOfElements]; + std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min(_nb_of_elem,newNbOfElements),pointer); + if(_ownership) + destroyPointer((T *)_pointer.getConstPointer(),_dealloc); + _pointer.setInternal(pointer); + _nb_of_elem=newNbOfElements; + _ownership=true; + _dealloc=CPP_DEALLOC; + } + + template + void MemArray::destroyPointer(T *pt, DeallocType type) + { + switch(type) + { + case CPP_DEALLOC: + { + delete [] pt; + return ; + } + case C_DEALLOC: + { + free(pt); + return ; + } + default: + std::stringstream stream; + stream << "Invalid deallocation requested for pointer " << pt; + throw INTERP_KERNEL::Exception(stream.str().c_str()); + } + } + + template + void MemArray::destroy() + { + if(_ownership) + destroyPointer((T *)_pointer.getConstPointer(),_dealloc); + _pointer.null(); + _ownership=false; + } + + template + MemArray &MemArray::operator=(const MemArray& other) + { + alloc(other._nb_of_elem); + std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+_nb_of_elem,_pointer.getPointer()); + return *this; + } +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 3b860a226..61324c2f8 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -20,18 +20,27 @@ #define __PARAMEDMEM_MEDCOUPLINGMESH_HXX__ #include "MEDCoupling.hxx" -#include "RefCountObject.hxx" +#include "MEDCouplingTimeLabel.hxx" +#include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" namespace ParaMEDMEM { + typedef enum + { + UNSTRUCTURED = 5, + UNSTRUCTURED_DESC = 6, + CARTESIAN = 7, + } MEDCouplingMeshType; + class MEDCouplingFieldDouble; - class MEDCOUPLING_EXPORT MEDCouplingMesh : public RefCountObject + class MEDCOUPLING_EXPORT MEDCouplingMesh : public RefCountObject, public TimeLabel { public: void setName(const char *name) { _name=name; } const char *getName() const { return _name.c_str(); } + virtual MEDCouplingMeshType getType() const = 0; virtual bool isEqual(const MEDCouplingMesh *other, double prec) const { return _name==other->_name; } virtual void checkCoherency() const throw(INTERP_KERNEL::Exception) = 0; virtual bool isStructured() const = 0; diff --git a/src/MEDCoupling/MEDCouplingNatureOfField.hxx b/src/MEDCoupling/MEDCouplingNatureOfField.hxx new file mode 100644 index 000000000..baffb734d --- /dev/null +++ b/src/MEDCoupling/MEDCouplingNatureOfField.hxx @@ -0,0 +1,33 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#ifndef __MEDCOUPLINGNATUREOFFIELD_HXX__ +#define __MEDCOUPLINGNATUREOFFIELD_HXX__ + +namespace ParaMEDMEM +{ + typedef enum + { + NoNature = 17, + ConservativeVolumic = 26, + Integral = 32, + IntegralGlobConstraint = 35 + } NatureOfField; +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.txx b/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.txx index 65970cfe9..7b08b093a 100644 --- a/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.txx +++ b/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.txx @@ -22,7 +22,7 @@ #include "MEDCouplingNormalizedUnstructuredMesh.hxx" #include "MEDCouplingUMesh.hxx" -#include "MemArray.hxx" +#include "MEDCouplingMemArray.hxx" template MEDCouplingNormalizedUnstructuredMesh::MEDCouplingNormalizedUnstructuredMesh(ParaMEDMEM::MEDCouplingUMesh *mesh):_mesh(mesh) diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index 0f0cadec2..abbc4cfd0 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -17,7 +17,9 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "MEDCouplingPointSet.hxx" -#include "MemArray.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingUMeshDesc.hxx" +#include "MEDCouplingMemArray.hxx" using namespace ParaMEDMEM; @@ -81,7 +83,13 @@ void MEDCouplingPointSet::setCoords(DataArrayDouble *coords) bool MEDCouplingPointSet::areCoordsEqual(const MEDCouplingPointSet& other, double prec) const { - return _coords->isEqual(other._coords,prec); + if(_coords==0 && other._coords==0) + return true; + if(_coords==0 || other._coords==0) + return false; + if(_coords==other._coords) + return true; + return _coords->isEqual(*other._coords,prec); } void MEDCouplingPointSet::getBoundingBox(double *bbox) const @@ -110,6 +118,81 @@ void MEDCouplingPointSet::getBoundingBox(double *bbox) const } } +MEDCouplingPointSet *MEDCouplingPointSet::buildInstanceFromMeshType(MEDCouplingMeshType type) +{ + switch(type) + { + case UNSTRUCTURED: + return MEDCouplingUMesh::New(); + case UNSTRUCTURED_DESC: + return MEDCouplingUMeshDesc::New(); + default: + throw INTERP_KERNEL::Exception("Invalid type of mesh specified"); + } +} + +void MEDCouplingPointSet::getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const +{ + if(_coords) + { + int spaceDim=getSpaceDimension(); + littleStrings.resize(spaceDim+1); + littleStrings[0]=getName(); + for(int i=0;igetInfoOnComponent(i); + tinyInfo.clear(); + tinyInfo.push_back(getType()); + tinyInfo.push_back(spaceDim); + tinyInfo.push_back(getNumberOfNodes()); + } + else + { + littleStrings.resize(1); + littleStrings[0]=getName(); + tinyInfo.clear(); + tinyInfo.push_back(getType()); + tinyInfo.push_back(-1); + tinyInfo.push_back(-1); + } +} + +void MEDCouplingPointSet::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const +{ + if(_coords) + { + a2=getCoords(); + a2->incrRef(); + } + else + a2=0; +} + +void MEDCouplingPointSet::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) +{ + if(tinyInfo[2]>=0 && tinyInfo[1]>=1) + { + a2->alloc(tinyInfo[2],tinyInfo[1]); + littleStrings.resize(tinyInfo[1]+1); + } + else + { + littleStrings.resize(1); + } +} + +void MEDCouplingPointSet::unserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings) +{ + if(tinyInfo[2]>=0 && tinyInfo[1]>=1) + { + setCoords(a2); + setName(littleStrings[0].c_str()); + for(int i=0;isetInfoOnComponent(i,littleStrings[i+1].c_str()); + } + else + setName(littleStrings[0].c_str()); +} + // ============================================= // Intersect Bounding Box given 2 Bounding Boxes // ============================================= @@ -140,3 +223,4 @@ bool MEDCouplingPointSet::intersectsBoundingBox(const double* bb1, const double* } return true; } + diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index 9acf85590..26694f413 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -44,12 +44,14 @@ namespace ParaMEDMEM DataArrayDouble *getCoords() const { return _coords; } bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const; void getBoundingBox(double *bbox) const; + static MEDCouplingPointSet *buildInstanceFromMeshType(MEDCouplingMeshType type); virtual MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const = 0; //! size of returned tinyInfo must be always the same. - virtual void getTinySerializationInformation(std::vector& tinyInfo) const = 0; - virtual void resizeForSerialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) = 0; - virtual void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) = 0; - virtual MEDCouplingPointSet *buildObjectFromUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) = 0; + virtual void getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const; + virtual void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings); + virtual void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; + virtual void unserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings); virtual void giveElemsInBoundingBox(const double *bbox, double eps, std::vector& elems) = 0; protected: static bool intersectsBoundingBox(const double* bb1, const double* bb2, int dim, double eps); diff --git a/src/MEDCoupling/MEDCouplingRMesh.cxx b/src/MEDCoupling/MEDCouplingRMesh.cxx deleted file mode 100644 index 70e2fc7da..000000000 --- a/src/MEDCoupling/MEDCouplingRMesh.cxx +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (C) 2007-2008 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. -// -// 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 -// -#include "MEDCouplingRMesh.hxx" -#include "MemArray.hxx" - -using namespace ParaMEDMEM; - -MEDCouplingRMesh::MEDCouplingRMesh():_x_array(0),_y_array(0),_z_array(0) -{ -} - -MEDCouplingRMesh::~MEDCouplingRMesh() -{ - if(_x_array) - _x_array->decrRef(); - if(_y_array) - _y_array->decrRef(); - if(_z_array) - _z_array->decrRef(); -} - -MEDCouplingRMesh *MEDCouplingRMesh::New() -{ - return new MEDCouplingRMesh; -} - -void MEDCouplingRMesh::updateTime() -{ - if(_x_array) - updateTimeWith(*_x_array); - if(_y_array) - updateTimeWith(*_y_array); - if(_z_array) - updateTimeWith(*_z_array); -} - -bool MEDCouplingRMesh::isEqual(const MEDCouplingMesh *other, double prec) const -{ - const MEDCouplingRMesh *otherC=dynamic_cast(other); - if(!otherC) - return false; - return true; -} - -void MEDCouplingRMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) -{ - const char msg0[]="Invalid "; - const char msg1[]=" array ! Must contain more than 1 element."; - if(_x_array) - if(_x_array->getNbOfElems()<2) - { - std::ostringstream os; os << msg0 << 'X' << msg1; - throw INTERP_KERNEL::Exception(os.str().c_str()); - } - if(_y_array) - if(_y_array->getNbOfElems()<2) - { - std::ostringstream os; os << msg0 << 'Y' << msg1; - throw INTERP_KERNEL::Exception(os.str().c_str()); - } - if(_z_array) - if(_z_array->getNbOfElems()<2) - { - std::ostringstream os; os << msg0 << 'Z' << msg1; - throw INTERP_KERNEL::Exception(os.str().c_str()); - } -} - -bool MEDCouplingRMesh::isStructured() const -{ - return true; -} - -int MEDCouplingRMesh::getNumberOfCells() const -{ - int ret=1; - if(_x_array) - ret*=_x_array->getNbOfElems()-1; - if(_y_array) - ret*=_y_array->getNbOfElems()-1; - if(_z_array) - ret*=_z_array->getNbOfElems()-1; - return ret; -} - -int MEDCouplingRMesh::getNumberOfNodes() const -{ - int ret=1; - if(_x_array) - ret*=_x_array->getNbOfElems(); - if(_y_array) - ret*=_y_array->getNbOfElems(); - if(_z_array) - ret*=_z_array->getNbOfElems(); - return ret; -} - -int MEDCouplingRMesh::getSpaceDimension() const -{ - int ret=0; - if(_x_array) - ret++; - if(_y_array) - ret++; - if(_z_array) - ret++; - return ret; -} - -int MEDCouplingRMesh::getMeshDimension() const -{ - int ret=0; - if(_x_array) - ret++; - if(_y_array) - ret++; - if(_z_array) - ret++; - return ret; -} - -DataArrayDouble *MEDCouplingRMesh::getCoordsAt(int i) const throw(INTERP_KERNEL::Exception) -{ - switch(i) - { - case 0: - return _x_array; - case 1: - return _y_array; - case 2: - return _z_array; - default: - throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2."); - } -} - -void MEDCouplingRMesh::setCoords(DataArrayDouble *coordsX, DataArrayDouble *coordsY, DataArrayDouble *coordsZ) -{ - if(_x_array) - _x_array->decrRef(); - _x_array=coordsX; - if(_x_array) - _x_array->incrRef(); - if(_y_array) - _y_array->decrRef(); - _y_array=coordsY; - if(_y_array) - _y_array->incrRef(); - if(_z_array) - _z_array->decrRef(); - _z_array=coordsZ; - if(_z_array) - _z_array->incrRef(); - declareAsNew(); -} - -void MEDCouplingRMesh::getBoundingBox(double *bbox) const -{ - //not implemented yet ! -} - -MEDCouplingFieldDouble *MEDCouplingRMesh::getMeasureField() const -{ - //not implemented yet ! -} diff --git a/src/MEDCoupling/MEDCouplingRMesh.hxx b/src/MEDCoupling/MEDCouplingRMesh.hxx deleted file mode 100644 index e0774596c..000000000 --- a/src/MEDCoupling/MEDCouplingRMesh.hxx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2007-2008 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. -// -// 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 -// -#ifndef __PARAMEDMEM_MEDCOUPLINGRMESH_HXX__ -#define __PARAMEDMEM_MEDCOUPLINGRMESH_HXX__ - -#include "MEDCoupling.hxx" -#include "MEDCouplingMesh.hxx" - -namespace ParaMEDMEM -{ - class DataArrayDouble; - - class MEDCouplingRMesh : public MEDCouplingMesh - { - public: - static MEDCouplingRMesh *New(); - void updateTime(); - bool isEqual(const MEDCouplingMesh *other, double prec) const; - void checkCoherency() const throw(INTERP_KERNEL::Exception); - bool isStructured() const; - int getNumberOfCells() const; - int getNumberOfNodes() const; - int getSpaceDimension() const; - int getMeshDimension() const; - DataArrayDouble *getCoordsAt(int i) const throw(INTERP_KERNEL::Exception); - void setCoords(DataArrayDouble *coordsX, - DataArrayDouble *coordsY=0, - DataArrayDouble *coordsZ=0); - // tools - void getBoundingBox(double *bbox) const; - MEDCouplingFieldDouble *getMeasureField() const; - private: - MEDCouplingRMesh(); - ~MEDCouplingRMesh(); - private: - DataArrayDouble *_x_array; - DataArrayDouble *_y_array; - DataArrayDouble *_z_array; - }; -} - -#endif diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.cxx b/src/MEDCoupling/MEDCouplingRefCountObject.cxx new file mode 100644 index 000000000..c9825ed53 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingRefCountObject.cxx @@ -0,0 +1,46 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#include "MEDCouplingRefCountObject.hxx" + +using namespace ParaMEDMEM; + +RefCountObject::RefCountObject():_cnt(1) +{ +} + +RefCountObject::RefCountObject(const RefCountObject& other):_cnt(1) +{ +} + +bool RefCountObject::decrRef() +{ + bool ret=((--_cnt)==0); + if(ret) + delete this; + return ret; +} + +void RefCountObject::incrRef() const +{ + _cnt++; +} + +RefCountObject::~RefCountObject() +{ +} diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.hxx b/src/MEDCoupling/MEDCouplingRefCountObject.hxx new file mode 100644 index 000000000..adeb8c74c --- /dev/null +++ b/src/MEDCoupling/MEDCouplingRefCountObject.hxx @@ -0,0 +1,58 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#ifndef __PARAMEDMEM_MEDCOUPLINGREFCOUNTOBJECT_HXX__ +#define __PARAMEDMEM_MEDCOUPLINGREFCOUNTOBJECT_HXX__ + +namespace ParaMEDMEM +{ + typedef enum + { + C_DEALLOC = 2, + CPP_DEALLOC = 3 + } DeallocType; + + typedef enum + { + ON_CELLS = 0, + ON_NODES = 1 + } TypeOfField; + + typedef enum + { + NO_TIME = 4, + ONE_TIME = 5, + LINEAR_TIME = 6 + } TypeOfTimeDiscretization; + + class RefCountObject + { + protected: + RefCountObject(); + RefCountObject(const RefCountObject& other); + public: + bool decrRef(); + void incrRef() const; + protected: + virtual ~RefCountObject(); + private: + mutable int _cnt; + }; +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 892a52caa..6c75e607c 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -17,7 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "MEDCouplingTimeDiscretization.hxx" -#include "MemArray.hxx" +#include "MEDCouplingMemArray.hxx" #include @@ -42,6 +42,68 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDisc } } +bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const +{ + if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) + return false; + if(_array==0 && other->_array==0) + return true; + if(_array==0 || other->_array==0) + return false; + if(_array==other->_array) + return true; + return _array->isEqual(*other->_array,prec); +} + +void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector& tinyInfo) const +{ + if(_array) + { + tinyInfo.push_back(_array->getNumberOfTuples()); + tinyInfo.push_back(_array->getNumberOfComponents()); + } + else + { + tinyInfo.push_back(-1); + tinyInfo.push_back(-1); + } +} + +void MEDCouplingTimeDiscretization::resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays) +{ + arrays.resize(1); + if(_array!=0) + _array->decrRef(); + DataArrayDouble *arr=0; + if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1) + { + arr=DataArrayDouble::New(); + arr->alloc(tinyInfoI[0],tinyInfoI[1]); + } + _array=arr; + arrays[0]=arr; +} + +void MEDCouplingTimeDiscretization::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) +{ + _time_tolerance=tinyInfoD[0]; + int nbOfCompo=_array->getNumberOfComponents(); + for(int i=0;isetInfoOnComponent(i,tinyInfoS[i].c_str()); +} + +void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector& tinyInfo) const +{ + tinyInfo.push_back(_time_tolerance); +} + +void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector& tinyInfo) const +{ + int nbOfCompo=_array->getNumberOfComponents(); + for(int i=0;igetInfoOnComponent(i)); +} + MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization():_time_tolerance(TIME_TOLERANCE_DFT),_array(0) { } @@ -110,6 +172,14 @@ MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretizati { } +bool MEDCouplingNoTimeLabel::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + return false; + return MEDCouplingTimeDiscretization::isEqual(other,prec); +} + MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCpy(bool deepCpy) const { return new MEDCouplingNoTimeLabel(*this,deepCpy); @@ -174,6 +244,41 @@ MEDCouplingWithTimeStep::MEDCouplingWithTimeStep():_time(0.),_dt(-1),_it(-1) { } +void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector& tinyInfo) const +{ + MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); + tinyInfo.push_back(_dt); + tinyInfo.push_back(_it); +} + +void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector& tinyInfo) const +{ + MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo); + tinyInfo.push_back(_time); +} + +void MEDCouplingWithTimeStep::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) +{ + MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); + _time=tinyInfoD[1]; + _dt=tinyInfoI[2]; + _it=tinyInfoI[3]; +} + +bool MEDCouplingWithTimeStep::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_dt!=otherC->_dt) + return false; + if(_it!=otherC->_it) + return false; + if(std::fabs(_time-otherC->_time)>_time_tolerance) + return false; + return MEDCouplingTimeDiscretization::isEqual(other,prec); +} + MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCpy(bool deepCpy) const { return new MEDCouplingWithTimeStep(*this,deepCpy); @@ -260,3 +365,39 @@ void MEDCouplingTwoTimeSteps::getArrays(std::vector& arrays) arrays[0]=_array; arrays[1]=_end_array; } + +void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays) +{ + arrays.resize(2); + if(_array!=0) + _array->decrRef(); + if(_end_array!=0) + _end_array->decrRef(); + DataArrayDouble *arr=0; + if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1) + { + arr=DataArrayDouble::New(); + arr->alloc(tinyInfoI[0],tinyInfoI[1]); + } + _array=arr; + arrays[0]=arr; + arr=0; + if(tinyInfoI[2]!=-1 && tinyInfoI[3]!=-1) + { + arr=DataArrayDouble::New(); + arr->alloc(tinyInfoI[2],tinyInfoI[3]); + } + _end_array=arr; + arrays[1]=arr; +} + +void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) +{ + MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); + _start_time=tinyInfoD[1]; + _end_time=tinyInfoD[2]; + _start_dt=tinyInfoI[2]; + _end_dt=tinyInfoI[3]; + _start_it=tinyInfoI[4]; + _end_it=tinyInfoI[5]; +} diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 9128f0702..6764689ff 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -20,7 +20,7 @@ #define __MEDCOUPLINGTIMEDISCRETIZATION_HXX__ #include "MEDCoupling.hxx" -#include "RefCountObject.hxx" +#include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" #include @@ -37,6 +37,13 @@ namespace ParaMEDMEM MEDCouplingTimeDiscretization(const MEDCouplingTimeDiscretization& other, bool deepCpy); public: static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type); + virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + virtual TypeOfTimeDiscretization getEnum() const = 0; + virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; + virtual void getTinySerializationDbleInformation(std::vector& tinyInfo) const; + virtual void getTinySerializationStrInformation(std::vector& tinyInfo) const; + virtual void resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays); + virtual void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); virtual MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const = 0; void setTimeTolerance(double val); double getTimeTolerance() const { return _time_tolerance; } @@ -72,6 +79,8 @@ namespace ParaMEDMEM public: MEDCouplingNoTimeLabel(); MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCpy); + TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } + bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const; void checkNoTimePresence() const throw(INTERP_KERNEL::Exception) { } void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception); @@ -96,6 +105,11 @@ namespace ParaMEDMEM MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCpy); public: MEDCouplingWithTimeStep(); + TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } + bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + void getTinySerializationIntInformation(std::vector& tinyInfo) const; + void getTinySerializationDbleInformation(std::vector& tinyInfo) const; + void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const; void checkNoTimePresence() const throw(INTERP_KERNEL::Exception); void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception); @@ -130,6 +144,8 @@ namespace ParaMEDMEM void setEndTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _end_time=time; _end_dt=dt; _end_it=it; } double getStartTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_start_dt; it=_start_it; return _start_time; } double getEndTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_end_dt; it=_end_it; return _end_time; } + void resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays); + void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); protected: double _start_time; double _end_time; @@ -143,6 +159,7 @@ namespace ParaMEDMEM class MEDCOUPLING_EXPORT MEDCouplingLinearTime : public MEDCouplingTwoTimeSteps { public: + TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } static const TypeOfTimeDiscretization DISCRETIZATION=LINEAR_TIME; }; } diff --git a/src/MEDCoupling/MEDCouplingTimeLabel.cxx b/src/MEDCoupling/MEDCouplingTimeLabel.cxx new file mode 100644 index 000000000..52e33f528 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingTimeLabel.cxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2008 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. +// +// 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 +// +#include "MEDCouplingTimeLabel.hxx" + +using namespace ParaMEDMEM; + +unsigned int TimeLabel::GLOBAL_TIME=0; + +TimeLabel::TimeLabel():_time(GLOBAL_TIME++) +{ +} + +TimeLabel::~TimeLabel() +{ +} + + TimeLabel& TimeLabel::operator=(const TimeLabel& other) +{ + _time=GLOBAL_TIME++; + return *this; +} + +void TimeLabel::declareAsNew() +{ + _time=GLOBAL_TIME++; +} + +void TimeLabel::updateTimeWith(const TimeLabel& other) +{ + if(_timesetName(meshName); + ret->setMeshDimension(meshDim); + return ret; +} + MEDCouplingUMesh *MEDCouplingUMesh::clone(bool recDeepCpy) const { return new MEDCouplingUMesh(*this,recDeepCpy); @@ -50,13 +58,15 @@ void MEDCouplingUMesh::updateTime() } } -MEDCouplingUMesh::MEDCouplingUMesh():_iterator(-1),_mesh_dim(-1), +MEDCouplingUMesh::MEDCouplingUMesh():_iterator(-1),_mesh_dim(-2), _nodal_connec(0),_nodal_connec_index(0) { } void MEDCouplingUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) { + if(_mesh_dim<-1) + throw INTERP_KERNEL::Exception("No mesh dimension specified !"); for(std::set::const_iterator iter=_types.begin();iter!=_types.end();iter++) { if(INTERP_KERNEL::CellModel::getCellModel(*iter).getDimension()!=_mesh_dim) @@ -68,8 +78,10 @@ void MEDCouplingUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) } } -void MEDCouplingUMesh::setMeshDimension(unsigned meshDim) +void MEDCouplingUMesh::setMeshDimension(int meshDim) { + if(meshDim<-1) + throw INTERP_KERNEL::Exception("Invalid meshDim specified ! Must be greater or equal to -1 !"); _mesh_dim=meshDim; declareAsNew(); } @@ -118,11 +130,11 @@ void MEDCouplingUMesh::finishInsertingCells() bool MEDCouplingUMesh::isEqual(const MEDCouplingMesh *other, double prec) const { - checkFullyDefined(); + //checkFullyDefined(); const MEDCouplingUMesh *otherC=dynamic_cast(other); if(!otherC) return false; - otherC->checkFullyDefined(); + //otherC->checkFullyDefined(); if(!MEDCouplingMesh::isEqual(other,prec)) return false; if(_mesh_dim!=otherC->_mesh_dim) @@ -131,6 +143,18 @@ bool MEDCouplingUMesh::isEqual(const MEDCouplingMesh *other, double prec) const return false; if(!areCoordsEqual(*otherC,prec)) return false; + if(_nodal_connec!=0 || otherC->_nodal_connec!=0) + if(_nodal_connec==0 || otherC->_nodal_connec==0) + return false; + if(_nodal_connec!=otherC->_nodal_connec) + if(!_nodal_connec->isEqual(*otherC->_nodal_connec)) + return false; + if(_nodal_connec_index!=0 || otherC->_nodal_connec_index!=0) + if(_nodal_connec_index==0 || otherC->_nodal_connec_index==0) + return false; + if(_nodal_connec_index!=otherC->_nodal_connec_index) + if(!_nodal_connec_index->isEqual(*otherC->_nodal_connec_index)) + return false; return true; } @@ -352,7 +376,17 @@ int MEDCouplingUMesh::getNumberOfCells() const else return _iterator; else - throw INTERP_KERNEL::Exception("Unable to get number of cells because no connectivity specified !"); + if(_mesh_dim==-1) + return 1; + else + throw INTERP_KERNEL::Exception("Unable to get number of cells because no connectivity specified !"); +} + +int MEDCouplingUMesh::getMeshDimension() const +{ + if(_mesh_dim<-1) + throw INTERP_KERNEL::Exception("No mesh dimension specified !"); + return _mesh_dim; } int MEDCouplingUMesh::getMeshLength() const @@ -360,60 +394,65 @@ int MEDCouplingUMesh::getMeshLength() const return _nodal_connec->getNbOfElems(); } -void MEDCouplingUMesh::getTinySerializationInformation(std::vector& tinyInfo) const +void MEDCouplingUMesh::getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const { - tinyInfo.resize(5); - tinyInfo[0] = getSpaceDimension(); - tinyInfo[1] = getMeshDimension(); - tinyInfo[2] = getNumberOfNodes(); - tinyInfo[3] = getNumberOfCells(); - tinyInfo[4] = getMeshLength(); + MEDCouplingPointSet::getTinySerializationInformation(tinyInfo,littleStrings); + tinyInfo.push_back(getMeshDimension()); + tinyInfo.push_back(getNumberOfCells()); + if(_nodal_connec) + tinyInfo.push_back(getMeshLength()); + else + tinyInfo.push_back(-1); } /*! * @param tinyInfo must be equal to the result given by getTinySerializationInformation method. */ -void MEDCouplingUMesh::resizeForSerialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) +void MEDCouplingUMesh::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) { - a1->alloc(tinyInfo[4]+tinyInfo[3]+1,1); - a2->alloc(tinyInfo[2],tinyInfo[0]); + MEDCouplingPointSet::resizeForUnserialization(tinyInfo,a1,a2,littleStrings); + if(tinyInfo[5]!=-1) + a1->alloc(tinyInfo[5]+tinyInfo[4]+1,1); } -void MEDCouplingUMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) +void MEDCouplingUMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const { - a1=DataArrayInt::New(); - a1->alloc(getMeshLength()+getNumberOfCells()+1,1); - int *ptA1=a1->getPointer(); - const int *conn=getNodalConnectivity()->getConstPointer(); - const int *index=getNodalConnectivityIndex()->getConstPointer(); - ptA1=std::copy(index,index+getNumberOfCells()+1,ptA1); - std::copy(conn,conn+getMeshLength(),ptA1); - a2=getCoords(); - a2->incrRef(); + MEDCouplingPointSet::serialize(a1,a2); + if(getMeshDimension()>-1) + { + a1=DataArrayInt::New(); + a1->alloc(getMeshLength()+getNumberOfCells()+1,1); + int *ptA1=a1->getPointer(); + const int *conn=getNodalConnectivity()->getConstPointer(); + const int *index=getNodalConnectivityIndex()->getConstPointer(); + ptA1=std::copy(index,index+getNumberOfCells()+1,ptA1); + std::copy(conn,conn+getMeshLength(),ptA1); + } + else + a1=0; } /*! * @param tinyInfo must be equal to the result given by getTinySerializationInformation method. */ -MEDCouplingPointSet *MEDCouplingUMesh::buildObjectFromUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) -{ - MEDCouplingUMesh* meshing = MEDCouplingUMesh::New() ; - // Coordinates - meshing->setCoords(a2); - // Connectivity - const int *recvBuffer=a1->getConstPointer(); - DataArrayInt* myConnecIndex=DataArrayInt::New(); - myConnecIndex->alloc(tinyInfo[3]+1,1); - std::copy(recvBuffer,recvBuffer+tinyInfo[3]+1,myConnecIndex->getPointer()); - DataArrayInt* myConnec=DataArrayInt::New(); - myConnec->alloc(tinyInfo[4],1); - std::copy(recvBuffer+tinyInfo[3]+1,recvBuffer+tinyInfo[3]+1+tinyInfo[4],myConnec->getPointer()); - meshing->setConnectivity(myConnec, myConnecIndex) ; - myConnec->decrRef(); - myConnecIndex->decrRef(); - // - meshing->setMeshDimension(tinyInfo[1]); - return meshing; +void MEDCouplingUMesh::unserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings) +{ + MEDCouplingPointSet::unserialization(tinyInfo,a1,a2,littleStrings); + setMeshDimension(tinyInfo[3]); + if(tinyInfo[5]!=-1) + { + // Connectivity + const int *recvBuffer=a1->getConstPointer(); + DataArrayInt* myConnecIndex=DataArrayInt::New(); + myConnecIndex->alloc(tinyInfo[4]+1,1); + std::copy(recvBuffer,recvBuffer+tinyInfo[4]+1,myConnecIndex->getPointer()); + DataArrayInt* myConnec=DataArrayInt::New(); + myConnec->alloc(tinyInfo[5],1); + std::copy(recvBuffer+tinyInfo[4]+1,recvBuffer+tinyInfo[4]+1+tinyInfo[5],myConnec->getPointer()); + setConnectivity(myConnec, myConnecIndex) ; + myConnec->decrRef(); + myConnecIndex->decrRef(); + } } MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelfKeepCoords(const int *start, const int *end) const diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 714fb865b..1c065e2d1 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -21,7 +21,7 @@ #include "MEDCoupling.hxx" #include "MEDCouplingPointSet.hxx" -#include "MemArray.hxx" +#include "MEDCouplingMemArray.hxx" #include @@ -31,11 +31,13 @@ namespace ParaMEDMEM { public: static MEDCouplingUMesh *New(); + static MEDCouplingUMesh *New(const char *meshName, int meshDim); MEDCouplingUMesh *clone(bool recDeepCpy) const; void updateTime(); + MEDCouplingMeshType getType() const { return UNSTRUCTURED; } bool isEqual(const MEDCouplingMesh *other, double prec) const; void checkCoherency() const throw(INTERP_KERNEL::Exception); - void setMeshDimension(unsigned meshDim); + void setMeshDimension(int meshDim); void allocateCells(int nbOfCells); void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell); void finishInsertingCells(); @@ -46,13 +48,14 @@ namespace ParaMEDMEM INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const; int getNumberOfNodesInCell(int cellId) const; int getNumberOfCells() const; - int getMeshDimension() const { return _mesh_dim; } + int getMeshDimension() const; int getMeshLength() const; //! size of returned tinyInfo must be always the same. - void getTinySerializationInformation(std::vector& tinyInfo) const; - void resizeForSerialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2); - void serialize(DataArrayInt *&a1, DataArrayDouble *&a2); - MEDCouplingPointSet *buildObjectFromUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2); + void getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const; + void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings); + void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; + void unserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings); //tools void zipCoords(); DataArrayInt *zipCoordsTraducer(); @@ -71,7 +74,7 @@ namespace ParaMEDMEM private: //! this iterator stores current position in _nodal_connec array. mutable int _iterator; - unsigned _mesh_dim; + int _mesh_dim; DataArrayInt *_nodal_connec; DataArrayInt *_nodal_connec_index; std::set _types; diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 71d4d1faa..995e3f77b 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -18,7 +18,7 @@ // #include "MEDCouplingUMeshDesc.hxx" #include "CellModel.hxx" -#include "MemArray.hxx" +#include "MEDCouplingMemArray.hxx" using namespace ParaMEDMEM; @@ -44,6 +44,14 @@ MEDCouplingUMeshDesc *MEDCouplingUMeshDesc::New() return new MEDCouplingUMeshDesc; } +MEDCouplingUMeshDesc *MEDCouplingUMeshDesc::New(const char *meshName, int meshDim) +{ + MEDCouplingUMeshDesc *ret=new MEDCouplingUMeshDesc; + ret->setName(meshName); + ret->setMeshDimension(meshDim); + return ret; +} + void MEDCouplingUMeshDesc::checkCoherency() const throw(INTERP_KERNEL::Exception) { for(std::set::const_iterator iter=_types.begin();iter!=_types.end();iter++) @@ -98,26 +106,28 @@ void MEDCouplingUMeshDesc::setConnectivity(DataArrayInt *descConn, DataArrayInt computeTypes(); } -void MEDCouplingUMeshDesc::getTinySerializationInformation(std::vector& tinyInfo) const +void MEDCouplingUMeshDesc::getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const { - tinyInfo.resize(7); - tinyInfo[0]=getSpaceDimension(); - tinyInfo[1]=getMeshDimension(); - tinyInfo[2]=getNumberOfNodes(); - tinyInfo[3]=getNumberOfCells(); - tinyInfo[4]=getCellMeshLength(); - tinyInfo[5]=getNumberOfFaces(); - tinyInfo[6]=getFaceMeshLength(); + MEDCouplingPointSet::getTinySerializationInformation(tinyInfo,littleStrings); + tinyInfo.push_back(getMeshDimension()); + tinyInfo.push_back(getNumberOfNodes()); + tinyInfo.push_back(getNumberOfCells()); + tinyInfo.push_back(getCellMeshLength()); + tinyInfo.push_back(getNumberOfFaces()); + tinyInfo.push_back(getFaceMeshLength()); } -void MEDCouplingUMeshDesc::resizeForSerialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) +void MEDCouplingUMeshDesc::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) { - a1->alloc(tinyInfo[4]+tinyInfo[3]+1+tinyInfo[6]+tinyInfo[5]+1,1); - a2->alloc(tinyInfo[2],tinyInfo[0]); + std::vector tinyInfoTmp(tinyInfo.begin()+1,tinyInfo.end()); + MEDCouplingPointSet::resizeForUnserialization(tinyInfoTmp,a1,a2,littleStrings); + a1->alloc(tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7]+tinyInfo[6]+1,1); } -void MEDCouplingUMeshDesc::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) +void MEDCouplingUMeshDesc::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const { + MEDCouplingPointSet::serialize(a1,a2); + // a1=DataArrayInt::New(); a1->alloc(getCellMeshLength()+getNumberOfCells()+1+getFaceMeshLength()+getNumberOfFaces()+1,1); int *ptA1=a1->getPointer(); @@ -129,35 +139,33 @@ void MEDCouplingUMeshDesc::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) ptA1=std::copy(descConnIndex,descConnIndex+getNumberOfCells()+1,ptA1); ptA1=std::copy(faceConn,faceConn+getFaceMeshLength(),ptA1); std::copy(faceConnIndex,faceConnIndex+getNumberOfFaces()+1,ptA1); - a2=getCoords(); - a2->incrRef(); } -MEDCouplingPointSet *MEDCouplingUMeshDesc::buildObjectFromUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) +void MEDCouplingUMeshDesc::unserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings) { - MEDCouplingUMeshDesc *meshing=MEDCouplingUMeshDesc::New(); - meshing->setCoords(a2); + std::vector tinyInfoTmp(tinyInfo.begin()+1,tinyInfo.end()); + MEDCouplingPointSet::unserialization(tinyInfoTmp,a1,a2,littleStrings); + // const int *recvBuffer=a1->getConstPointer(); DataArrayInt *descConn=DataArrayInt::New(); - descConn->alloc(tinyInfo[4],1); - std::copy(recvBuffer,recvBuffer+tinyInfo[4],descConn->getPointer()); + descConn->alloc(tinyInfo[5],1); + std::copy(recvBuffer,recvBuffer+tinyInfo[5],descConn->getPointer()); DataArrayInt *descConnIndex=DataArrayInt::New(); - descConnIndex->alloc(tinyInfo[3]+1,1); - std::copy(recvBuffer+tinyInfo[4],recvBuffer+tinyInfo[4]+tinyInfo[3]+1,descConnIndex->getPointer()); + descConnIndex->alloc(tinyInfo[4]+1,1); + std::copy(recvBuffer+tinyInfo[5],recvBuffer+tinyInfo[5]+tinyInfo[4]+1,descConnIndex->getPointer()); DataArrayInt *faceConn=DataArrayInt::New(); - faceConn->alloc(tinyInfo[6],1); - std::copy(recvBuffer+tinyInfo[4]+tinyInfo[3]+1,recvBuffer+tinyInfo[4]+tinyInfo[3]+1+tinyInfo[6],faceConn->getPointer()); + faceConn->alloc(tinyInfo[7],1); + std::copy(recvBuffer+tinyInfo[5]+tinyInfo[4]+1,recvBuffer+tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7],faceConn->getPointer()); DataArrayInt *faceConnIndex=DataArrayInt::New(); - faceConnIndex->alloc(tinyInfo[5]+1,1); - std::copy(recvBuffer+tinyInfo[4]+tinyInfo[3]+1+tinyInfo[6], - recvBuffer+tinyInfo[4]+tinyInfo[3]+1+tinyInfo[6]+tinyInfo[5]+1,faceConnIndex->getPointer()); - meshing->setConnectivity(descConn,descConnIndex,faceConn,faceConnIndex); + faceConnIndex->alloc(tinyInfo[6]+1,1); + std::copy(recvBuffer+tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7], + recvBuffer+tinyInfo[5]+tinyInfo[5]+1+tinyInfo[7]+tinyInfo[6]+1,faceConnIndex->getPointer()); + setConnectivity(descConn,descConnIndex,faceConn,faceConnIndex); descConn->decrRef(); descConnIndex->decrRef(); faceConn->decrRef(); faceConnIndex->decrRef(); - meshing->setMeshDimension(tinyInfo[1]); - return meshing; + setMeshDimension(tinyInfo[2]); } void MEDCouplingUMeshDesc::giveElemsInBoundingBox(const double *bbox, double eps, std::vector& elems) @@ -178,8 +186,9 @@ void MEDCouplingUMeshDesc::giveElemsInBoundingBox(const double *bbox, double eps elem_bb[i*2+1]=-std::numeric_limits::max(); } - for (int iface=conn_index[ielem]+1; iface& tinyInfo) const; - void resizeForSerialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2); - void serialize(DataArrayInt *&a1, DataArrayDouble *&a2); - MEDCouplingPointSet *buildObjectFromUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2); + void getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const; + void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings); + void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; + void unserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings); void giveElemsInBoundingBox(const double *bbox, double eps, std::vector& elems); MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const; MEDCouplingFieldDouble *getMeasureField() const; diff --git a/src/MEDCoupling/Makefile.am b/src/MEDCoupling/Makefile.am index 60e83b9c2..4b3dd4bc5 100644 --- a/src/MEDCoupling/Makefile.am +++ b/src/MEDCoupling/Makefile.am @@ -28,20 +28,20 @@ lib_LTLIBRARIES = libmedcoupling.la salomeinclude_HEADERS = MEDCoupling.hxx \ -MEDCouplingFieldDouble.hxx MEDCouplingMesh.hxx MEDCouplingUMesh.hxx TimeLabel.hxx \ -MEDCouplingField.hxx MEDCouplingNormalizedUnstructuredMesh.hxx MemArray.hxx \ -MEDCouplingNormalizedUnstructuredMesh.txx MemArray.txx RefCountObject.hxx \ -MEDCouplingRMesh.hxx MEDCouplingTimeDiscretization.hxx \ -MEDCouplingFieldDiscretization.hxx MEDCouplingPointSet.hxx \ -MEDCouplingUMeshDesc.hxx +MEDCouplingFieldDouble.hxx MEDCouplingMesh.hxx MEDCouplingUMesh.hxx MEDCouplingTimeLabel.hxx \ +MEDCouplingField.hxx MEDCouplingNormalizedUnstructuredMesh.hxx MEDCouplingMemArray.hxx \ +MEDCouplingNormalizedUnstructuredMesh.txx MEDCouplingMemArray.txx MEDCouplingRefCountObject.hxx \ +MEDCouplingCMesh.hxx MEDCouplingTimeDiscretization.hxx \ +MEDCouplingFieldDiscretization.hxx MEDCouplingPointSet.hxx \ +MEDCouplingUMeshDesc.hxx MEDCouplingNatureOfField.hxx # Libraries targets dist_libmedcoupling_la_SOURCES = \ - MEDCouplingField.cxx MEDCouplingFieldDouble.cxx \ - MEDCouplingUMesh.cxx MemArray.cxx TimeLabel.cxx \ - MEDCouplingRMesh.cxx MEDCouplingTimeDiscretization.cxx \ - MEDCouplingFieldDiscretization.cxx \ + MEDCouplingField.cxx MEDCouplingFieldDouble.cxx \ + MEDCouplingUMesh.cxx MEDCouplingMemArray.cxx MEDCouplingTimeLabel.cxx \ + MEDCouplingCMesh.cxx MEDCouplingTimeDiscretization.cxx \ + MEDCouplingFieldDiscretization.cxx MEDCouplingRefCountObject.cxx \ MEDCouplingPointSet.cxx MEDCouplingUMeshDesc.cxx libmedcoupling_la_LDFLAGS= @@ -64,13 +64,14 @@ EXTRA_DIST += \ MEDCouplingFieldDiscretization.hxx \ MEDCouplingMesh.hxx \ MEDCouplingUMesh.hxx \ - MEDCouplingRMesh.hxx \ - TimeLabel.hxx \ + MEDCouplingCMesh.hxx \ + MEDCouplingTimeLabel.hxx \ MEDCouplingField.hxx \ MEDCouplingNormalizedUnstructuredMesh.hxx \ - MemArray.hxx \ + MEDCouplingMemArray.hxx \ MEDCouplingNormalizedUnstructuredMesh.txx \ - MemArray.txx \ - RefCountObject.hxx \ + MEDCouplingMemArray.txx \ + MEDCouplingRefCountObject.hxx \ MEDCouplingPointSet.hxx \ - MEDCouplingUMeshDesc.hxx + MEDCouplingUMeshDesc.hxx \ + MEDCouplingNatureOfField.hxx diff --git a/src/MEDCoupling/MemArray.cxx b/src/MEDCoupling/MemArray.cxx deleted file mode 100644 index 6240b21f0..000000000 --- a/src/MEDCoupling/MemArray.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2007-2008 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. -// -// 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 -// -#include "MemArray.txx" - -using namespace ParaMEDMEM; - -void DataArray::setName(const char *name) -{ - _name=name; -} - -DataArrayDouble *DataArrayDouble::New() -{ - return new DataArrayDouble; -} - -DataArrayDouble *DataArrayDouble::deepCopy() const -{ - return new DataArrayDouble(*this); -} - -DataArrayDouble *DataArrayDouble::performCpy(bool deepCpy) const -{ - if(deepCpy) - return deepCopy(); - else - { - incrRef(); - return const_cast(this); - } -} - -void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) -{ - _nb_of_tuples=nbOfTuple; - _info_on_compo.resize(nbOfCompo); - _mem.alloc(nbOfCompo*_nb_of_tuples); - declareAsNew(); -} - -bool DataArrayDouble::isEqual(DataArrayDouble *other, double prec) const -{ - return true; -} - -void DataArrayDouble::reAlloc(int nbOfTuples) -{ - _mem.reAlloc(_info_on_compo.size()*nbOfTuples); - _nb_of_tuples=nbOfTuples; - declareAsNew(); -} - -void DataArrayDouble::setArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet) -{ - if(newArray!=arrayToSet) - { - if(arrayToSet) - arrayToSet->decrRef(); - arrayToSet=newArray; - if(arrayToSet) - arrayToSet->incrRef(); - } -} - -void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) -{ - _nb_of_tuples=nbOfTuple; - _info_on_compo.resize(nbOfCompo); - _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); - declareAsNew(); -} - -DataArrayInt *DataArrayInt::New() -{ - return new DataArrayInt; -} - -DataArrayInt *DataArrayInt::deepCopy() const -{ - return new DataArrayInt(*this); -} - -DataArrayInt *DataArrayInt::performCpy(bool deepCpy) const -{ - if(deepCpy) - return deepCopy(); - else - { - incrRef(); - return const_cast(this); - } -} - -void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) -{ - _nb_of_tuples=nbOfTuple; - _info_on_compo.resize(nbOfCompo); - _mem.alloc(nbOfCompo*_nb_of_tuples); - declareAsNew(); -} - -void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) -{ - _nb_of_tuples=nbOfTuple; - _info_on_compo.resize(nbOfCompo); - _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); - declareAsNew(); -} - -void DataArrayInt::reAlloc(int nbOfTuples) -{ - _mem.reAlloc(_info_on_compo.size()*nbOfTuples); - _nb_of_tuples=nbOfTuples; - declareAsNew(); -} - -void DataArrayInt::setArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet) -{ - if(newArray!=arrayToSet) - { - if(arrayToSet) - arrayToSet->decrRef(); - arrayToSet=newArray; - if(arrayToSet) - arrayToSet->incrRef(); - } -} diff --git a/src/MEDCoupling/MemArray.hxx b/src/MEDCoupling/MemArray.hxx deleted file mode 100644 index fcfbd0292..000000000 --- a/src/MEDCoupling/MemArray.hxx +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (C) 2007-2008 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. -// -// 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 -// -#ifndef __PARAMEDMEM_MEMARRAY_HXX__ -#define __PARAMEDMEM_MEMARRAY_HXX__ - -#include "MEDCoupling.hxx" -#include "RefCountObject.hxx" -#include "InterpKernelException.hxx" - -#include -#include - -namespace ParaMEDMEM -{ - template - class MEDCouplingPointer - { - public: - MEDCouplingPointer():_internal(0),_external(0) { } - void null() { _internal=0; _external=0; } - bool isNull() const { return _internal==0 && _external==0; } - void setInternal(T *pointer); - void setExternal(const T *pointer); - const T *getConstPointer() const { if(_internal) return _internal; else return _external; } - const T *getConstPointerLoc(int offset) const { if(_internal) return _internal+offset; else return _external+offset; } - T *getPointer() const { if(_internal) return _internal; throw INTERP_KERNEL::Exception("Trying to write on an external pointer."); } - private: - T *_internal; - const T *_external; - }; - - template - class MemArray - { - public: - MemArray():_nb_of_elem(-1),_ownership(false),_dealloc(CPP_DEALLOC) { } - MemArray(const MemArray& other); - const T *getConstPointerLoc(int offset) const { return _pointer.getConstPointerLoc(offset); } - const T *getConstPointer() const { return _pointer.getConstPointer(); } - T *getPointer() const { return _pointer.getPointer(); } - MemArray &operator=(const MemArray& other); - T operator[](int id) const { return _pointer.getConstPointer()[id]; } - T& operator[](int id) { return _pointer.getPointer()[id]; } - void alloc(int nbOfElements); - void reAlloc(int newNbOfElements); - void useArray(const T *array, bool ownership, DeallocType type, int nbOfElem); - void writeOnPlace(int id, T element0, const T *others, int sizeOfOthers); - ~MemArray() { destroy(); } - private: - void destroy(); - static void destroyPointer(T *pt, DeallocType type); - private: - int _nb_of_elem; - bool _ownership; - MEDCouplingPointer _pointer; - //T *_pointer; - DeallocType _dealloc; - }; - - class MEDCOUPLING_EXPORT DataArray : public RefCountObject - { - public: - void setName(const char *name); - std::string getName() const { return _name; } - std::string getInfoOnComponent(int i) const { return _info_on_compo[i]; } - void setInfoOnComponent(int i, const char *info) { _info_on_compo[i]=info; } - int getNumberOfComponents() const { return _info_on_compo.size(); } - int getNumberOfTuples() const { return _nb_of_tuples; } - int getNbOfElems() const { return _info_on_compo.size()*_nb_of_tuples; } - protected: - DataArray():_nb_of_tuples(-1) { } - protected: - int _nb_of_tuples; - std::string _name; - std::vector _info_on_compo; - }; -} - -#include "MemArray.txx" - -namespace ParaMEDMEM -{ - class MEDCOUPLING_EXPORT DataArrayDouble : public DataArray - { - public: - static DataArrayDouble *New(); - DataArrayDouble *deepCopy() const; - DataArrayDouble *performCpy(bool deepCpy) const; - void alloc(int nbOfTuple, int nbOfCompo); - bool isEqual(DataArrayDouble *other, double prec) const; - //!alloc or useArray should have been called before. - void reAlloc(int nbOfTuples); - void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } - double getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } - void setIJ(int tupleId, int compoId, double newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } - double *getPointer() const { return _mem.getPointer(); } - static void setArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet); - const double *getConstPointer() const { return _mem.getConstPointer(); } - void useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); - void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } - //! nothing to do here because this class does not aggregate any TimeLabel instance. - void updateTime() { } - private: - DataArrayDouble() { } - private: - MemArray _mem; - }; - - class MEDCOUPLING_EXPORT DataArrayInt : public DataArray - { - public: - static DataArrayInt *New(); - DataArrayInt *deepCopy() const; - DataArrayInt *performCpy(bool deepCpy) const; - void alloc(int nbOfTuple, int nbOfCompo); - //!alloc or useArray should have been called before. - void reAlloc(int nbOfTuples); - void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } - int getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } - void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } - int *getPointer() const { return _mem.getPointer(); } - static void setArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet); - const int *getConstPointer() const { return _mem.getConstPointer(); } - void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); - void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } - //! nothing to do here because this class does not aggregate any TimeLabel instance. - void updateTime() { } - private: - DataArrayInt() { } - private: - MemArray _mem; - }; -} - -#endif diff --git a/src/MEDCoupling/MemArray.txx b/src/MEDCoupling/MemArray.txx deleted file mode 100644 index c32654327..000000000 --- a/src/MEDCoupling/MemArray.txx +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (C) 2007-2008 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. -// -// 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 -// -#ifndef __PARAMEDMEM_MEMARRAY_TXX__ -#define __PARAMEDMEM_MEMARRAY_TXX__ - -#include "MemArray.hxx" -#include "NormalizedUnstructuredMesh.hxx" -#include "InterpKernelException.hxx" - -#include -#include - -namespace ParaMEDMEM -{ - template - void MEDCouplingPointer::setInternal(T *pointer) - { - _internal=pointer; - _external=0; - } - - template - void MEDCouplingPointer::setExternal(const T *pointer) - { - _external=pointer; - _internal=0; - } - - template - MemArray::MemArray(const MemArray& other):_nb_of_elem(-1),_ownership(false),_dealloc(CPP_DEALLOC) - { - if(!other._pointer.isNull()) - { - T *pointer=new T[other._nb_of_elem]; - std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+other._nb_of_elem,pointer); - useArray(pointer,true,CPP_DEALLOC,other._nb_of_elem); - } - } - - template - void MemArray::useArray(const T *array, bool ownership, DeallocType type, int nbOfElem) - { - _nb_of_elem=nbOfElem; - destroy(); - if(ownership) - _pointer.setInternal((T *)array); - else - _pointer.setExternal(array); - _ownership=ownership; - _dealloc=type; - } - - template - void MemArray::writeOnPlace(int id, T element0, const T *others, int sizeOfOthers) - { - if(id+sizeOfOthers>=_nb_of_elem) - reAlloc(2*_nb_of_elem+sizeOfOthers+1); - T *pointer=_pointer.getPointer(); - pointer[id]=element0; - std::copy(others,others+sizeOfOthers,pointer+id+1); - } - - template - void MemArray::alloc(int nbOfElements) - { - destroy(); - _nb_of_elem=nbOfElements; - _pointer.setInternal(new T[_nb_of_elem]); - _ownership=true; - _dealloc=CPP_DEALLOC; - } - - template - void MemArray::reAlloc(int newNbOfElements) - { - T *pointer=new T[newNbOfElements]; - std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min(_nb_of_elem,newNbOfElements),pointer); - if(_ownership) - destroyPointer((T *)_pointer.getConstPointer(),_dealloc); - _pointer.setInternal(pointer); - _nb_of_elem=newNbOfElements; - _ownership=true; - _dealloc=CPP_DEALLOC; - } - - template - void MemArray::destroyPointer(T *pt, DeallocType type) - { - switch(type) - { - case CPP_DEALLOC: - { - delete [] pt; - return ; - } - case C_DEALLOC: - { - free(pt); - return ; - } - default: - std::stringstream stream; - stream << "Invalid deallocation requested for pointer " << pt; - throw INTERP_KERNEL::Exception(stream.str().c_str()); - } - } - - template - void MemArray::destroy() - { - if(_ownership) - destroyPointer((T *)_pointer.getConstPointer(),_dealloc); - _pointer.null(); - _ownership=false; - } - - template - MemArray &MemArray::operator=(const MemArray& other) - { - alloc(other._nb_of_elem); - std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+_nb_of_elem,_pointer.getPointer()); - return *this; - } -} - -#endif diff --git a/src/MEDCoupling/RefCountObject.hxx b/src/MEDCoupling/RefCountObject.hxx deleted file mode 100644 index 16a2f0b34..000000000 --- a/src/MEDCoupling/RefCountObject.hxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007-2008 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. -// -// 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 -// -#ifndef __PARAMEDMEM_REFCOUNTOBJECT_HXX__ -#define __PARAMEDMEM_REFCOUNTOBJECT_HXX__ - -#include "TimeLabel.hxx" - -namespace ParaMEDMEM -{ - typedef enum - { - C_DEALLOC = 2, - CPP_DEALLOC = 3 - } DeallocType; - - typedef enum - { - ON_CELLS = 0, - ON_NODES = 1 - } TypeOfField; - - typedef enum - { - NO_TIME = 4, - ONE_TIME = 5, - LINEAR_TIME = 6 - } TypeOfTimeDiscretization; - - class RefCountObject : public TimeLabel - { - protected: - RefCountObject():_cnt(1) { } - RefCountObject(const RefCountObject& other):_cnt(1) { } - public: - bool decrRef() { bool ret=((--_cnt)==0); if(ret)delete this; return ret; } - void incrRef() const { _cnt++; } - protected: - virtual ~RefCountObject() { } - private: - mutable int _cnt; - }; -} - -#endif diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.cxx index 15087df5e..031acfd26 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.cxx @@ -19,7 +19,7 @@ #include "MEDCouplingBasicsTest.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" -#include "MemArray.hxx" +#include "MEDCouplingMemArray.hxx" #include "Interpolation2D.txx" #include "Interpolation3DSurf.txx" #include "Interpolation3D.txx" @@ -226,6 +226,38 @@ void MEDCouplingBasicsTest::testMeshPointsCloud() targetMesh->decrRef(); } +void MEDCouplingBasicsTest::testMeshM1D() +{ + MEDCouplingUMesh *meshM1D=MEDCouplingUMesh::New(); + CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(meshM1D->checkCoherency(),INTERP_KERNEL::Exception); + meshM1D->setMeshDimension(-1); + meshM1D->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(-1,meshM1D->getMeshDimension()); + CPPUNIT_ASSERT_EQUAL(1,meshM1D->getNumberOfCells()); + CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(meshM1D->getSpaceDimension(),INTERP_KERNEL::Exception); + MEDCouplingUMesh *cpy=meshM1D->clone(true); + CPPUNIT_ASSERT(cpy->isEqual(meshM1D,1e-12)); + cpy->decrRef(); + MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS); + fieldOnCells->setMesh(meshM1D); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(1,6); + fieldOnCells->setArray(array); + double *tmp=array->getPointer(); + array->decrRef(); + fill(tmp,tmp+6,7.); + fieldOnCells->checkCoherency(); + // + fieldOnCells->decrRef(); + meshM1D->decrRef(); +} + void MEDCouplingBasicsTest::testDeepCopy() { DataArrayDouble *array=DataArrayDouble::New(); @@ -383,12 +415,160 @@ void MEDCouplingBasicsTest::testEqualMesh() MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); MEDCouplingUMesh *mesh2=build2DTargetMesh_1(); // - + CPPUNIT_ASSERT(mesh1->isEqual(mesh1,1e-12)); + // + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12)); + double *pt=mesh2->getCoords()->getPointer(); + double tmp=pt[1]; + pt[1]=5.999; + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12)); + pt[1]=tmp; + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12)); + // + int *pt2=mesh1->getNodalConnectivity()->getPointer(); + pt2[5]++; + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12)); + pt2[5]--; + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12)); + // + pt2=mesh1->getNodalConnectivityIndex()->getPointer(); + pt2[1]++; + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12)); + pt2[1]--; + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12)); + // + std::string tmp3=mesh1->getName(); + mesh1->setName("lllll"); + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12)); + mesh1->setName(tmp3.c_str()); + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12)); + // + tmp3=mesh2->getCoords()->getInfoOnComponent(1); + mesh2->getCoords()->setInfoOnComponent(1,"kkkkkk"); + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12)); + mesh2->getCoords()->setInfoOnComponent(1,tmp3.c_str()); + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12)); + // + mesh1->decrRef(); + mesh2->decrRef(); +} + +void MEDCouplingBasicsTest::testEqualFieldDouble() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingUMesh *mesh2=build2DTargetMesh_1(); + // + MEDCouplingFieldDouble *fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + fieldOnCells1->setMesh(mesh1); + MEDCouplingFieldDouble *fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + fieldOnCells2->setMesh(mesh2); + // + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2->decrRef(); + // + MEDCouplingFieldDouble *fieldOnNodes1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnNodes1,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnNodes1->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnNodes1->decrRef(); + // + fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1->decrRef(); + fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1->setTime(4.,6,7); + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2->setTime(4.,6,7); + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1->setName("Power"); + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2->setName("Power"); + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + // + fieldOnCells1->setMesh(mesh1); + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2->setMesh(mesh1); + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + DataArrayDouble *arr=DataArrayDouble::New(); + arr->setName("popo"); + arr->alloc(mesh1->getNumberOfCells(),3); + double *pt=arr->getPointer(); + std::fill(pt,pt+mesh1->getNumberOfCells()*3,6.); + fieldOnCells1->setArray(arr); + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2->setArray(arr); + arr->decrRef(); + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + // + DataArrayDouble *arr2=arr->deepCopy(); + fieldOnCells2->setArray(arr2); + arr2->decrRef(); + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + pt[4]=6.1; + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + pt[4]=6.; + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + arr2->setName("popo2"); + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + // + arr2->setName("popo"); + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + // + arr2->setInfoOnComponent(2,"jjj"); + CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + arr->setInfoOnComponent(2,"jjj"); + CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); + CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); + // + fieldOnCells1->decrRef(); + fieldOnCells2->decrRef(); // mesh1->decrRef(); mesh2->decrRef(); } +void MEDCouplingBasicsTest::testNatureChecking() +{ + MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + field->setNature(Integral); + field->setNature(ConservativeVolumic); + field->setNature(IntegralGlobConstraint); + field->decrRef(); + field=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME); + field->setNature(ConservativeVolumic); + CPPUNIT_ASSERT_THROW(field->setNature(Integral),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(field->setNature(IntegralGlobConstraint),INTERP_KERNEL::Exception); + field->decrRef(); +} + void MEDCouplingBasicsTest::test2DInterpP0P0_1() { MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1(); @@ -793,8 +973,7 @@ MEDCouplingUMesh *MEDCouplingBasicsTest::build2DSourceMesh_1() { double sourceCoords[8]={-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7}; int sourceConn[6]={0,3,1,0,2,3}; - MEDCouplingUMesh *sourceMesh=MEDCouplingUMesh::New(); - sourceMesh->setMeshDimension(2); + MEDCouplingUMesh *sourceMesh=MEDCouplingUMesh::New("my name of mesh 2D",2); sourceMesh->allocateCells(2); sourceMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,sourceConn); sourceMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,sourceConn+3); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 85a903541..167e64e22 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -34,11 +34,14 @@ namespace ParaMEDMEM CPPUNIT_TEST( testArray ); CPPUNIT_TEST( testMesh ); CPPUNIT_TEST( testMeshPointsCloud ); + CPPUNIT_TEST( testMeshM1D ); CPPUNIT_TEST( testDeepCopy ); CPPUNIT_TEST( testRevNodal ); CPPUNIT_TEST( testBuildPartOfMySelf ); CPPUNIT_TEST( testZipCoords ); CPPUNIT_TEST( testEqualMesh ); + CPPUNIT_TEST( testEqualFieldDouble ); + CPPUNIT_TEST( testNatureChecking ); CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P1_1 ); CPPUNIT_TEST( test2DInterpP1P0_1 ); @@ -54,11 +57,14 @@ namespace ParaMEDMEM void testArray(); void testMesh(); void testMeshPointsCloud(); + void testMeshM1D(); void testDeepCopy(); void testRevNodal(); void testBuildPartOfMySelf(); void testZipCoords(); void testEqualMesh(); + void testEqualFieldDouble(); + void testNatureChecking(); void test2DInterpP0P0_1(); void test2DInterpP0P1_1(); void test2DInterpP1P0_1(); diff --git a/src/MEDCoupling/TimeLabel.cxx b/src/MEDCoupling/TimeLabel.cxx deleted file mode 100644 index df03416ec..000000000 --- a/src/MEDCoupling/TimeLabel.cxx +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2007-2008 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. -// -// 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 -// -#include "TimeLabel.hxx" - -using namespace ParaMEDMEM; - -unsigned int TimeLabel::GLOBAL_TIME=0; - -TimeLabel::TimeLabel():_time(GLOBAL_TIME++) -{ -} - - TimeLabel& TimeLabel::operator=(const TimeLabel& other) -{ - _time=GLOBAL_TIME++; - return *this; -} - -void TimeLabel::declareAsNew() -{ - _time=GLOBAL_TIME++; -} - -void TimeLabel::updateTimeWith(const TimeLabel& other) -{ - if(_timegetSpaceDimension()), _owns_processor_group(false) { vector axis_length(_dimension); diff --git a/src/ParaMEDMEM/BlockTopology.hxx b/src/ParaMEDMEM/BlockTopology.hxx index 5ce27bc13..440d6f1f7 100644 --- a/src/ParaMEDMEM/BlockTopology.hxx +++ b/src/ParaMEDMEM/BlockTopology.hxx @@ -27,7 +27,7 @@ namespace ParaMEDMEM { class ComponentTopology; - class MEDCouplingRMesh; + class MEDCouplingCMesh; typedef enum{Block,Cycle} CYCLE_TYPE; @@ -35,7 +35,7 @@ namespace ParaMEDMEM { public: BlockTopology() { } - BlockTopology(const ProcessorGroup& group, MEDCouplingRMesh *grid); + BlockTopology(const ProcessorGroup& group, MEDCouplingCMesh *grid); BlockTopology(const BlockTopology& geom_topo, const ComponentTopology& comp_topo); BlockTopology(const ProcessorGroup& group, int nb_elem); virtual ~BlockTopology(); diff --git a/src/ParaMEDMEM/ElementLocator.cxx b/src/ParaMEDMEM/ElementLocator.cxx index 11ba8a0ee..2d243a4c2 100644 --- a/src/ParaMEDMEM/ElementLocator.cxx +++ b/src/ParaMEDMEM/ElementLocator.cxx @@ -181,7 +181,10 @@ namespace ParaMEDMEM // First stage : exchanging sizes // ------------------------------ vector tinyInfoLocal,tinyInfoDistant; - local_mesh->getTinySerializationInformation(tinyInfoLocal); + vector tinyInfoLocalS; + //Getting tiny info of local mesh to allow the distant proc to initialize and allocate + //the transmitted mesh. + local_mesh->getTinySerializationInformation(tinyInfoLocal,tinyInfoLocalS); tinyInfoLocal.push_back(local_mesh->getNumberOfCells()); tinyInfoDistant.resize(tinyInfoLocal.size()); std::fill(tinyInfoDistant.begin(),tinyInfoDistant.end(),0); @@ -201,8 +204,12 @@ namespace ParaMEDMEM DataArrayDouble *v2Local=0; DataArrayInt *v1Distant=DataArrayInt::New(); DataArrayDouble *v2Distant=DataArrayDouble::New(); + //serialization of local mesh to send data to distant proc. local_mesh->serialize(v1Local,v2Local); - local_mesh->resizeForSerialization(tinyInfoDistant,v1Distant,v2Distant); + //Building the right instance of copy of distant mesh. + MEDCouplingPointSet *distant_mesh_tmp=MEDCouplingPointSet::buildInstanceFromMeshType((MEDCouplingMeshType)tinyInfoDistant[0]); + std::vector unusedTinyDistantSts; + distant_mesh_tmp->resizeForUnserialization(tinyInfoDistant,v1Distant,v2Distant,unusedTinyDistantSts); comm_interface.sendRecv(v1Local->getPointer(), v1Local->getNbOfElems(), MPI_INT, iprocdistant_in_union, 1111, v1Distant->getPointer(), v1Distant->getNbOfElems(), MPI_INT, @@ -215,8 +222,12 @@ namespace ParaMEDMEM *comm, &status); if(v1Distant->getNbOfElems()>0) { - distant_mesh=local_mesh->buildObjectFromUnserialization(tinyInfoDistant,v1Distant,v2Distant); + distant_mesh=distant_mesh_tmp; + //finish unserialization + distant_mesh->unserialization(tinyInfoDistant,v1Distant,v2Distant,unusedTinyDistantSts); } + else + distant_mesh_tmp->decrRef(); distant_ids_recv=new int[tinyInfoDistant.back()]; comm_interface.sendRecv((void *)distant_ids_send,tinyInfoLocal.back(), MPI_INT, iprocdistant_in_union, 1113, diff --git a/src/ParaMEDMEM/ParaFIELD.hxx b/src/ParaMEDMEM/ParaFIELD.hxx index b0c241db0..5b89e2e8f 100644 --- a/src/ParaMEDMEM/ParaFIELD.hxx +++ b/src/ParaMEDMEM/ParaFIELD.hxx @@ -19,7 +19,7 @@ #ifndef __PARAFIELD_HXX__ #define __PARAFIELD_HXX__ -#include "RefCountObject.hxx" +#include "MEDCouplingRefCountObject.hxx" namespace ParaMEDMEM { diff --git a/src/ParaMEDMEM/ParaGRID.cxx b/src/ParaMEDMEM/ParaGRID.cxx index ce36ce316..86c94d96a 100644 --- a/src/ParaMEDMEM/ParaGRID.cxx +++ b/src/ParaMEDMEM/ParaGRID.cxx @@ -19,8 +19,8 @@ #include "ParaGRID.hxx" #include "Topology.hxx" #include "BlockTopology.hxx" -#include "MemArray.hxx" -#include "MEDCouplingRMesh.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingCMesh.hxx" #include "InterpKernelUtilities.hxx" #include @@ -30,7 +30,7 @@ using namespace std; namespace ParaMEDMEM { - ParaGRID::ParaGRID(MEDCouplingRMesh* global_grid, Topology* topology) throw(INTERP_KERNEL::Exception) + ParaGRID::ParaGRID(MEDCouplingCMesh* global_grid, Topology* topology) throw(INTERP_KERNEL::Exception) { _block_topology = dynamic_cast(topology); @@ -59,7 +59,7 @@ namespace ParaMEDMEM coordinates_names.push_back(array->getName()); coordinates_units.push_back(array->getInfoOnComponentAt(0)); } - _grid=MEDCouplingRMesh::New(); + _grid=MEDCouplingCMesh::New(); _grid->set(xyz_array, coordinates_names,coordinates_units); _grid->setName(global_grid->getName()); _grid->setDescription(global_grid->getDescription());*/ diff --git a/src/ParaMEDMEM/ParaGRID.hxx b/src/ParaMEDMEM/ParaGRID.hxx index 8bb5a5f5f..7738d39da 100644 --- a/src/ParaMEDMEM/ParaGRID.hxx +++ b/src/ParaMEDMEM/ParaGRID.hxx @@ -27,17 +27,17 @@ namespace ParaMEDMEM { class Topology; class BlockTopology; - class MEDCouplingRMesh; + class MEDCouplingCMesh; class ParaGRID { public: - ParaGRID(MEDCouplingRMesh* global_grid, Topology* topology) throw(INTERP_KERNEL::Exception); + ParaGRID(MEDCouplingCMesh* global_grid, Topology* topology) throw(INTERP_KERNEL::Exception); BlockTopology * getBlockTopology() const { return _block_topology; } virtual ~ParaGRID(); - MEDCouplingRMesh* getGrid() const { return _grid; } + MEDCouplingCMesh* getGrid() const { return _grid; } private: - MEDCouplingRMesh* _grid; + MEDCouplingCMesh* _grid; // structured grid topology ParaMEDMEM::BlockTopology* _block_topology; // stores the x,y,z axes on the global grid diff --git a/src/ParaMEDMEM/ParaMESH.cxx b/src/ParaMEDMEM/ParaMESH.cxx index 755ab3bfb..9bc8c6266 100644 --- a/src/ParaMEDMEM/ParaMESH.cxx +++ b/src/ParaMEDMEM/ParaMESH.cxx @@ -21,7 +21,7 @@ #include "MPIProcessorGroup.hxx" #include "Topology.hxx" #include "BlockTopology.hxx" -#include "MemArray.hxx" +#include "MEDCouplingMemArray.hxx" #include #include diff --git a/src/ParaMEDMEM/ParaMESH.hxx b/src/ParaMEDMEM/ParaMESH.hxx index bf3ef4345..2de2f6759 100644 --- a/src/ParaMEDMEM/ParaMESH.hxx +++ b/src/ParaMEDMEM/ParaMESH.hxx @@ -21,7 +21,7 @@ #include "MEDCouplingPointSet.hxx" #include "ProcessorGroup.hxx" -#include "MemArray.hxx" +#include "MEDCouplingMemArray.hxx" #include #include diff --git a/src/ParaMEDMEM/Test/ParaMEDMEMTest_MEDLoader.cxx b/src/ParaMEDMEM/Test/ParaMEDMEMTest_MEDLoader.cxx index be29e0f51..12afe8f4f 100644 --- a/src/ParaMEDMEM/Test/ParaMEDMEMTest_MEDLoader.cxx +++ b/src/ParaMEDMEM/Test/ParaMEDMEMTest_MEDLoader.cxx @@ -105,23 +105,23 @@ void ParaMEDMEMTest::testMEDLoaderRead1() std::transform(field0->getArray()->getPointer(),field0->getArray()->getPointer()+16,expectedValues,diffValue,std::minus()); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue,diffValue+16),1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue,diffValue+16),1e-12); - mesh=dynamic_cast(field0->getMesh()); - CPPUNIT_ASSERT(mesh); - CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension()); - CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension()); - CPPUNIT_ASSERT_EQUAL(16,mesh->getNumberOfCells()); - CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes()); - CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllTypes().size()); + const MEDCouplingUMesh *constMesh=dynamic_cast(field0->getMesh()); + CPPUNIT_ASSERT(constMesh); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension()); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension()); + CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes()); + CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllTypes().size()); for(int i=0;i<12;i++) - CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i)); for(int i=12;i<14;i++) - CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(i)); for(int i=14;i<16;i++) - CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(i)); - CPPUNIT_ASSERT_EQUAL(90,mesh->getNodalConnectivity()->getNbOfElems()); - CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0)); - CPPUNIT_ASSERT_EQUAL(711,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12); + CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(90,constMesh->getNodalConnectivity()->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getPointer(),constMesh->getNodalConnectivity()->getPointer()+90,0)); + CPPUNIT_ASSERT_EQUAL(711,std::accumulate(constMesh->getNodalConnectivityIndex()->getPointer(),constMesh->getNodalConnectivityIndex()->getPointer()+17,0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getPointer(),constMesh->getCoords()->getPointer()+57,0),1e-12); field0->decrRef(); // MEDCouplingFieldDouble *field1=MEDLoader::ReadFieldDoubleCell(fileName,meshNames[0].c_str(),0,fieldsName[1].c_str(),its1[0].first,its1[0].second); @@ -134,23 +134,23 @@ void ParaMEDMEMTest::testMEDLoaderRead1() std::transform(field1->getArray()->getPointer(),field1->getArray()->getPointer()+48,expectedValues2,diffValue2,std::minus()); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue2,diffValue2+48),1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue2,diffValue2+48),1e-12); - mesh=dynamic_cast(field1->getMesh()); - CPPUNIT_ASSERT(mesh); - CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension()); - CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension()); - CPPUNIT_ASSERT_EQUAL(16,mesh->getNumberOfCells()); - CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes()); - CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllTypes().size()); + constMesh=dynamic_cast(field1->getMesh()); + CPPUNIT_ASSERT(constMesh); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension()); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension()); + CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes()); + CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllTypes().size()); for(int i=0;i<12;i++) - CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i)); for(int i=12;i<14;i++) - CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(i)); for(int i=14;i<16;i++) - CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(i)); - CPPUNIT_ASSERT_EQUAL(90,mesh->getNodalConnectivity()->getNbOfElems()); - CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0)); - CPPUNIT_ASSERT_EQUAL(711,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12); + CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(90,constMesh->getNodalConnectivity()->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getPointer(),constMesh->getNodalConnectivity()->getPointer()+90,0)); + CPPUNIT_ASSERT_EQUAL(711,std::accumulate(constMesh->getNodalConnectivityIndex()->getPointer(),constMesh->getNodalConnectivityIndex()->getPointer()+17,0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getPointer(),constMesh->getCoords()->getPointer()+57,0),1e-12); field1->decrRef(); //fields on nodes std::vector fieldsNameNode=MEDLoader::GetNodeFieldNamesOnMesh(fileName,meshNames[0].c_str()); @@ -175,8 +175,8 @@ void ParaMEDMEMTest::testMEDLoaderRead1() std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues3,diffValue3,std::minus()); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12); - mesh=dynamic_cast(field0Nodes->getMesh()); - CPPUNIT_ASSERT(mesh); + constMesh=dynamic_cast(field0Nodes->getMesh()); + CPPUNIT_ASSERT(constMesh); field0Nodes->decrRef(); // field0Nodes=MEDLoader::ReadFieldDoubleNode(fileName,meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[1].first,its0Node[1].second); @@ -188,23 +188,23 @@ void ParaMEDMEMTest::testMEDLoaderRead1() std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues4,diffValue3,std::minus()); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12); - mesh=dynamic_cast(field0Nodes->getMesh()); - CPPUNIT_ASSERT(mesh); - CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension()); - CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension()); - CPPUNIT_ASSERT_EQUAL(16,mesh->getNumberOfCells()); - CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes()); - CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllTypes().size()); + constMesh=dynamic_cast(field0Nodes->getMesh()); + CPPUNIT_ASSERT(constMesh); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension()); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension()); + CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes()); + CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllTypes().size()); for(int i=0;i<12;i++) - CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i)); for(int i=12;i<14;i++) - CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(i)); for(int i=14;i<16;i++) - CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(i)); - CPPUNIT_ASSERT_EQUAL(90,mesh->getNodalConnectivity()->getNbOfElems()); - CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0)); - CPPUNIT_ASSERT_EQUAL(711,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12); + CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(90,constMesh->getNodalConnectivity()->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getPointer(),constMesh->getNodalConnectivity()->getPointer()+90,0)); + CPPUNIT_ASSERT_EQUAL(711,std::accumulate(constMesh->getNodalConnectivityIndex()->getPointer(),constMesh->getNodalConnectivityIndex()->getPointer()+17,0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getPointer(),constMesh->getCoords()->getPointer()+57,0),1e-12); field0Nodes->decrRef(); // field0Nodes=MEDLoader::ReadFieldDoubleNode(fileName,meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[2].first,its0Node[2].second); @@ -216,23 +216,23 @@ void ParaMEDMEMTest::testMEDLoaderRead1() std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues5,diffValue3,std::minus()); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12); - mesh=dynamic_cast(field0Nodes->getMesh()); - CPPUNIT_ASSERT(mesh); - CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension()); - CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension()); - CPPUNIT_ASSERT_EQUAL(16,mesh->getNumberOfCells()); - CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes()); - CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllTypes().size()); + constMesh=dynamic_cast(field0Nodes->getMesh()); + CPPUNIT_ASSERT(constMesh); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension()); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension()); + CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes()); + CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllTypes().size()); for(int i=0;i<12;i++) - CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i)); for(int i=12;i<14;i++) - CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(i)); for(int i=14;i<16;i++) - CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(i)); - CPPUNIT_ASSERT_EQUAL(90,mesh->getNodalConnectivity()->getNbOfElems()); - CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0)); - CPPUNIT_ASSERT_EQUAL(711,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12); + CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(90,constMesh->getNodalConnectivity()->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getPointer(),constMesh->getNodalConnectivity()->getPointer()+90,0)); + CPPUNIT_ASSERT_EQUAL(711,std::accumulate(constMesh->getNodalConnectivityIndex()->getPointer(),constMesh->getNodalConnectivityIndex()->getPointer()+17,0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getPointer(),constMesh->getCoords()->getPointer()+57,0),1e-12); field0Nodes->decrRef(); } @@ -278,24 +278,24 @@ void ParaMEDMEMTest::testMEDLoaderPolygonRead() CPPUNIT_ASSERT(field->getName()==fieldsName[0]); CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfComponents()); CPPUNIT_ASSERT_EQUAL(538,field->getNumberOfTuples()); - mesh=dynamic_cast(field->getMesh()); - CPPUNIT_ASSERT(mesh); - CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension()); - CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension()); - CPPUNIT_ASSERT_EQUAL(538,mesh->getNumberOfCells()); - CPPUNIT_ASSERT_EQUAL(579,mesh->getNumberOfNodes()); - CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size()); + const MEDCouplingUMesh *constMesh=dynamic_cast(field->getMesh()); + CPPUNIT_ASSERT(constMesh); + CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension()); + CPPUNIT_ASSERT_EQUAL(2,constMesh->getMeshDimension()); + CPPUNIT_ASSERT_EQUAL(538,constMesh->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(579,constMesh->getNumberOfNodes()); + CPPUNIT_ASSERT_EQUAL(2,(int)constMesh->getAllTypes().size()); for(int i=0;i<514;i++) - CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,constMesh->getTypeOfCell(i)); for(int i=514;i<538;i++) - CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+1737,0),1e-12); - std::transform(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+12,expectedVals1,diffValue1,std::minus()); + CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,constMesh->getTypeOfCell(i)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(constMesh->getCoords()->getPointer(),constMesh->getCoords()->getPointer()+1737,0),1e-12); + std::transform(constMesh->getCoords()->getPointer(),constMesh->getCoords()->getPointer()+12,expectedVals1,diffValue1,std::minus()); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12); - CPPUNIT_ASSERT_EQUAL(2768,mesh->getNodalConnectivity()->getNbOfElems()); - CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+2768,0)); - CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+539,0)); + CPPUNIT_ASSERT_EQUAL(2768,constMesh->getNodalConnectivity()->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(constMesh->getNodalConnectivity()->getPointer(),constMesh->getNodalConnectivity()->getPointer()+2768,0)); + CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(constMesh->getNodalConnectivityIndex()->getPointer(),constMesh->getNodalConnectivityIndex()->getPointer()+539,0)); const double *values=field->getArray()->getPointer(); CPPUNIT_ASSERT_DOUBLES_EQUAL(2.87214203182918,std::accumulate(values,values+538,0.),1e-12); field->decrRef();