--- /dev/null
+// 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<const MEDCouplingCMesh *>(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;
+}
--- /dev/null
+// 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
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)
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)
{
MEDCouplingField::~MEDCouplingField()
{
if(_mesh)
- _mesh->decrRef();
+ ((MEDCouplingMesh *)_mesh)->decrRef();
delete _type;
}
#define __PARAMEDMEM_MEDCOUPLINGFIELD_HXX__
#include "MEDCoupling.hxx"
-#include "RefCountObject.hxx"
+#include "MEDCouplingTimeLabel.hxx"
+#include "MEDCouplingRefCountObject.hxx"
#include "InterpKernelException.hxx"
#include <string>
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;
protected:
std::string _name;
std::string _desc;
- MEDCouplingMesh *_mesh;
+ const MEDCouplingMesh *_mesh;
MEDCouplingFieldDiscretization *_type;
};
}
return REPR;
}
+bool MEDCouplingFieldDiscretizationP0::isEqual(const MEDCouplingFieldDiscretization *other) const
+{
+ const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationP0 *>(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())
return REPR;
}
+bool MEDCouplingFieldDiscretizationP1::isEqual(const MEDCouplingFieldDiscretization *other) const
+{
+ const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast<const MEDCouplingFieldDiscretizationP1 *>(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())
#define __MEDCOUPLINGFIELDDISCRETIZATION_HXX__
#include "MEDCoupling.hxx"
-#include "RefCountObject.hxx"
+#include "MEDCouplingRefCountObject.hxx"
#include "InterpKernelException.hxx"
+#include "MEDCouplingNatureOfField.hxx"
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;
};
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:
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:
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<const MEDCouplingFieldDouble *>(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))
{
}
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<std::string>& 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<int>& 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<double>& 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<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
+{
+ std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
+ _time_discr->resizeForUnserialization(tinyInfoI2,arrays);
+}
+
+void MEDCouplingFieldDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
+{
+ std::vector<int> 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<DataArrayDouble *>& arrays) const
+{
+ _time_discr->getArrays(arrays);
+}
#include "MEDCoupling.hxx"
#include "MEDCouplingField.hxx"
#include "MEDCouplingTimeDiscretization.hxx"
-#include "MemArray.hxx"
+#include "MEDCouplingNatureOfField.hxx"
+#include "MEDCouplingMemArray.hxx"
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); }
int getNumberOfComponents() const;
int getNumberOfTuples() const throw(INTERP_KERNEL::Exception);
void updateTime();
+ //
+ void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
+ void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
+ void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
+ void resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays);
+ void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
+ void serialize(std::vector<DataArrayDouble *>& arrays) const;
private:
MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td);
MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy);
~MEDCouplingFieldDouble();
private:
+ NatureOfField _nature;
MEDCouplingTimeDiscretization *_time_discr;
};
}
--- /dev/null
+// 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<DataArrayDouble *>(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<DataArrayInt *>(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();
+ }
+}
--- /dev/null
+// 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 <string>
+#include <vector>
+
+namespace ParaMEDMEM
+{
+ template<class T>
+ 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 T>
+ class MemArray
+ {
+ public:
+ MemArray():_nb_of_elem(-1),_ownership(false),_dealloc(CPP_DEALLOC) { }
+ MemArray(const MemArray<T>& 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<T> &operator=(const MemArray<T>& other);
+ T operator[](int id) const { return _pointer.getConstPointer()[id]; }
+ T& operator[](int id) { return _pointer.getPointer()[id]; }
+ bool isEqual(const MemArray<T>& 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<T> _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<std::string> _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<double> _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<int> _mem;
+ };
+}
+
+#endif
--- /dev/null
+// 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 <sstream>
+#include <algorithm>
+
+namespace ParaMEDMEM
+{
+ template<class T>
+ void MEDCouplingPointer<T>::setInternal(T *pointer)
+ {
+ _internal=pointer;
+ _external=0;
+ }
+
+ template<class T>
+ void MEDCouplingPointer<T>::setExternal(const T *pointer)
+ {
+ _external=pointer;
+ _internal=0;
+ }
+
+ template<class T>
+ MemArray<T>::MemArray(const MemArray<T>& 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<class T>
+ void MemArray<T>::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<class T>
+ void MemArray<T>::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<class T>
+ bool MemArray<T>::isEqual(const MemArray<T>& 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<class T>
+ void MemArray<T>::alloc(int nbOfElements)
+ {
+ destroy();
+ _nb_of_elem=nbOfElements;
+ _pointer.setInternal(new T[_nb_of_elem]);
+ _ownership=true;
+ _dealloc=CPP_DEALLOC;
+ }
+
+ template<class T>
+ void MemArray<T>::reAlloc(int newNbOfElements)
+ {
+ T *pointer=new T[newNbOfElements];
+ std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<int>(_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<class T>
+ void MemArray<T>::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<class T>
+ void MemArray<T>::destroy()
+ {
+ if(_ownership)
+ destroyPointer((T *)_pointer.getConstPointer(),_dealloc);
+ _pointer.null();
+ _ownership=false;
+ }
+
+ template<class T>
+ MemArray<T> &MemArray<T>::operator=(const MemArray<T>& other)
+ {
+ alloc(other._nb_of_elem);
+ std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+_nb_of_elem,_pointer.getPointer());
+ return *this;
+ }
+}
+
+#endif
#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;
--- /dev/null
+// 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
#include "MEDCouplingNormalizedUnstructuredMesh.hxx"
#include "MEDCouplingUMesh.hxx"
-#include "MemArray.hxx"
+#include "MEDCouplingMemArray.hxx"
template<int SPACEDIM,int MESHDIM>
MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::MEDCouplingNormalizedUnstructuredMesh(ParaMEDMEM::MEDCouplingUMesh *mesh):_mesh(mesh)
// 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;
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
}
}
+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<int>& tinyInfo, std::vector<std::string>& littleStrings) const
+{
+ if(_coords)
+ {
+ int spaceDim=getSpaceDimension();
+ littleStrings.resize(spaceDim+1);
+ littleStrings[0]=getName();
+ for(int i=0;i<spaceDim;i++)
+ littleStrings[i+1]=getCoords()->getInfoOnComponent(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<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& 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<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& littleStrings)
+{
+ if(tinyInfo[2]>=0 && tinyInfo[1]>=1)
+ {
+ setCoords(a2);
+ setName(littleStrings[0].c_str());
+ for(int i=0;i<tinyInfo[1];i++)
+ getCoords()->setInfoOnComponent(i,littleStrings[i+1].c_str());
+ }
+ else
+ setName(littleStrings[0].c_str());
+}
+
// =============================================
// Intersect Bounding Box given 2 Bounding Boxes
// =============================================
}
return true;
}
+
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<int>& tinyInfo) const = 0;
- virtual void resizeForSerialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) = 0;
- virtual void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) = 0;
- virtual MEDCouplingPointSet *buildObjectFromUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) = 0;
+ virtual void getTinySerializationInformation(std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
+ virtual void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings);
+ virtual void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const;
+ virtual void unserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2,
+ const std::vector<std::string>& littleStrings);
virtual void giveElemsInBoundingBox(const double *bbox, double eps, std::vector<int>& elems) = 0;
protected:
static bool intersectsBoundingBox(const double* bb1, const double* bb2, int dim, double eps);
+++ /dev/null
-// 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<const MEDCouplingRMesh *>(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 !
-}
+++ /dev/null
-// 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
--- /dev/null
+// 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()
+{
+}
--- /dev/null
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "MEDCouplingTimeDiscretization.hxx"
-#include "MemArray.hxx"
+#include "MEDCouplingMemArray.hxx"
#include <cmath>
}
}
+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<int>& 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<int>& tinyInfoI, std::vector<DataArrayDouble *>& 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<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
+{
+ _time_tolerance=tinyInfoD[0];
+ int nbOfCompo=_array->getNumberOfComponents();
+ for(int i=0;i<nbOfCompo;i++)
+ _array->setInfoOnComponent(i,tinyInfoS[i].c_str());
+}
+
+void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
+{
+ tinyInfo.push_back(_time_tolerance);
+}
+
+void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
+{
+ int nbOfCompo=_array->getNumberOfComponents();
+ for(int i=0;i<nbOfCompo;i++)
+ tinyInfo.push_back(_array->getInfoOnComponent(i));
+}
+
MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization():_time_tolerance(TIME_TOLERANCE_DFT),_array(0)
{
}
{
}
+bool MEDCouplingNoTimeLabel::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
+{
+ const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
+ if(!otherC)
+ return false;
+ return MEDCouplingTimeDiscretization::isEqual(other,prec);
+}
+
MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCpy(bool deepCpy) const
{
return new MEDCouplingNoTimeLabel(*this,deepCpy);
{
}
+void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
+{
+ MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
+ tinyInfo.push_back(_dt);
+ tinyInfo.push_back(_it);
+}
+
+void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
+{
+ MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
+ tinyInfo.push_back(_time);
+}
+
+void MEDCouplingWithTimeStep::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& 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<const MEDCouplingWithTimeStep *>(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);
arrays[0]=_array;
arrays[1]=_end_array;
}
+
+void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& 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<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& 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];
+}
#define __MEDCOUPLINGTIMEDISCRETIZATION_HXX__
#include "MEDCoupling.hxx"
-#include "RefCountObject.hxx"
+#include "MEDCouplingRefCountObject.hxx"
#include "InterpKernelException.hxx"
#include <vector>
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<int>& tinyInfo) const;
+ virtual void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
+ virtual void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
+ virtual void resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays);
+ virtual void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
virtual MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const = 0;
void setTimeTolerance(double val);
double getTimeTolerance() const { return _time_tolerance; }
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);
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<int>& tinyInfo) const;
+ void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
+ void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const;
void checkNoTimePresence() const throw(INTERP_KERNEL::Exception);
void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception);
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<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays);
+ void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
protected:
double _start_time;
double _end_time;
class MEDCOUPLING_EXPORT MEDCouplingLinearTime : public MEDCouplingTwoTimeSteps
{
public:
+ TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; }
static const TypeOfTimeDiscretization DISCRETIZATION=LINEAR_TIME;
};
}
--- /dev/null
+// 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(_time<other._time)
+ _time=other._time;
+}
--- /dev/null
+// 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_TIMELABEL_HXX__
+#define __PARAMEDMEM_TIMELABEL_HXX__
+
+#include "MEDCoupling.hxx"
+
+namespace ParaMEDMEM
+{
+ /*!
+ * Class representing a label of time of the lastely modified part of this.
+ * More _time is high more the object has been modified recently.
+ */
+ class MEDCOUPLING_EXPORT TimeLabel
+ {
+ public:
+ TimeLabel& operator=(const TimeLabel& other);
+ //! This method should be called when write access has been done on this.
+ void declareAsNew();
+ //! This method should be called on high level classes as Field or Mesh to take into acount modifications done in aggragates objects.
+ virtual void updateTime() = 0;
+ protected:
+ TimeLabel();
+ virtual ~TimeLabel();
+ void updateTimeWith(const TimeLabel& other);
+ private:
+ static unsigned int GLOBAL_TIME;
+ unsigned int _time;
+ };
+}
+
+#endif
return new MEDCouplingUMesh;
}
+MEDCouplingUMesh *MEDCouplingUMesh::New(const char *meshName, int meshDim)
+{
+ MEDCouplingUMesh *ret=new MEDCouplingUMesh;
+ ret->setName(meshName);
+ ret->setMeshDimension(meshDim);
+ return ret;
+}
+
MEDCouplingUMesh *MEDCouplingUMesh::clone(bool recDeepCpy) const
{
return new MEDCouplingUMesh(*this,recDeepCpy);
}
}
-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<INTERP_KERNEL::NormalizedCellType>::const_iterator iter=_types.begin();iter!=_types.end();iter++)
{
if(INTERP_KERNEL::CellModel::getCellModel(*iter).getDimension()!=_mesh_dim)
}
}
-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();
}
bool MEDCouplingUMesh::isEqual(const MEDCouplingMesh *other, double prec) const
{
- checkFullyDefined();
+ //checkFullyDefined();
const MEDCouplingUMesh *otherC=dynamic_cast<const MEDCouplingUMesh *>(other);
if(!otherC)
return false;
- otherC->checkFullyDefined();
+ //otherC->checkFullyDefined();
if(!MEDCouplingMesh::isEqual(other,prec))
return false;
if(_mesh_dim!=otherC->_mesh_dim)
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;
}
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
return _nodal_connec->getNbOfElems();
}
-void MEDCouplingUMesh::getTinySerializationInformation(std::vector<int>& tinyInfo) const
+void MEDCouplingUMesh::getTinySerializationInformation(std::vector<int>& tinyInfo, std::vector<std::string>& 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<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2)
+void MEDCouplingUMesh::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& 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<int>& 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<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& 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
#include "MEDCoupling.hxx"
#include "MEDCouplingPointSet.hxx"
-#include "MemArray.hxx"
+#include "MEDCouplingMemArray.hxx"
#include <set>
{
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();
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<int>& tinyInfo) const;
- void resizeForSerialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2);
- void serialize(DataArrayInt *&a1, DataArrayDouble *&a2);
- MEDCouplingPointSet *buildObjectFromUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2);
+ void getTinySerializationInformation(std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
+ void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings);
+ void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const;
+ void unserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2,
+ const std::vector<std::string>& littleStrings);
//tools
void zipCoords();
DataArrayInt *zipCoordsTraducer();
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<INTERP_KERNEL::NormalizedCellType> _types;
//
#include "MEDCouplingUMeshDesc.hxx"
#include "CellModel.hxx"
-#include "MemArray.hxx"
+#include "MEDCouplingMemArray.hxx"
using namespace ParaMEDMEM;
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<INTERP_KERNEL::NormalizedCellType>::const_iterator iter=_types.begin();iter!=_types.end();iter++)
computeTypes();
}
-void MEDCouplingUMeshDesc::getTinySerializationInformation(std::vector<int>& tinyInfo) const
+void MEDCouplingUMeshDesc::getTinySerializationInformation(std::vector<int>& tinyInfo, std::vector<std::string>& 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<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2)
+void MEDCouplingUMeshDesc::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings)
{
- a1->alloc(tinyInfo[4]+tinyInfo[3]+1+tinyInfo[6]+tinyInfo[5]+1,1);
- a2->alloc(tinyInfo[2],tinyInfo[0]);
+ std::vector<int> 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();
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<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2)
+void MEDCouplingUMeshDesc::unserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& littleStrings)
{
- MEDCouplingUMeshDesc *meshing=MEDCouplingUMeshDesc::New();
- meshing->setCoords(a2);
+ std::vector<int> 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<int>& elems)
elem_bb[i*2+1]=-std::numeric_limits<double>::max();
}
- for (int iface=conn_index[ielem]+1; iface<conn_index[ielem+1]; iface++)//+1 due to offset of cell type.
+ for (int jface=conn_index[ielem]+1; jface<conn_index[ielem+1]; jface++)//+1 due to offset of cell type.
{
+ int iface=conn[jface];
for(int inode=face_index[iface]+1;inode<face_index[iface+1];inode++)
{
int node=face[inode];
{
public:
static MEDCouplingUMeshDesc *New();
+ static MEDCouplingUMeshDesc *New(const char *meshName, int meshDim);
void checkCoherency() const throw(INTERP_KERNEL::Exception);
void setMeshDimension(unsigned meshDim);
int getNumberOfCells() const;
int getCellMeshLength() const;
int getFaceMeshLength() const;
int getMeshDimension() const { return _mesh_dim; }
+ MEDCouplingMeshType getType() const { return UNSTRUCTURED_DESC; }
void setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx);
//tools to overload
- void getTinySerializationInformation(std::vector<int>& tinyInfo) const;
- void resizeForSerialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2);
- void serialize(DataArrayInt *&a1, DataArrayDouble *&a2);
- MEDCouplingPointSet *buildObjectFromUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2);
+ void getTinySerializationInformation(std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
+ void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings);
+ void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const;
+ void unserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2,
+ const std::vector<std::string>& littleStrings);
void giveElemsInBoundingBox(const double *bbox, double eps, std::vector<int>& elems);
MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const;
MEDCouplingFieldDouble *getMeasureField() const;
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=
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
+++ /dev/null
-// 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<DataArrayDouble *>(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<DataArrayInt *>(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();
- }
-}
+++ /dev/null
-// 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 <string>
-#include <vector>
-
-namespace ParaMEDMEM
-{
- template<class T>
- 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 T>
- class MemArray
- {
- public:
- MemArray():_nb_of_elem(-1),_ownership(false),_dealloc(CPP_DEALLOC) { }
- MemArray(const MemArray<T>& 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<T> &operator=(const MemArray<T>& 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<T> _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<std::string> _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<double> _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<int> _mem;
- };
-}
-
-#endif
+++ /dev/null
-// 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 <sstream>
-#include <algorithm>
-
-namespace ParaMEDMEM
-{
- template<class T>
- void MEDCouplingPointer<T>::setInternal(T *pointer)
- {
- _internal=pointer;
- _external=0;
- }
-
- template<class T>
- void MEDCouplingPointer<T>::setExternal(const T *pointer)
- {
- _external=pointer;
- _internal=0;
- }
-
- template<class T>
- MemArray<T>::MemArray(const MemArray<T>& 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<class T>
- void MemArray<T>::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<class T>
- void MemArray<T>::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<class T>
- void MemArray<T>::alloc(int nbOfElements)
- {
- destroy();
- _nb_of_elem=nbOfElements;
- _pointer.setInternal(new T[_nb_of_elem]);
- _ownership=true;
- _dealloc=CPP_DEALLOC;
- }
-
- template<class T>
- void MemArray<T>::reAlloc(int newNbOfElements)
- {
- T *pointer=new T[newNbOfElements];
- std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<int>(_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<class T>
- void MemArray<T>::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<class T>
- void MemArray<T>::destroy()
- {
- if(_ownership)
- destroyPointer((T *)_pointer.getConstPointer(),_dealloc);
- _pointer.null();
- _ownership=false;
- }
-
- template<class T>
- MemArray<T> &MemArray<T>::operator=(const MemArray<T>& other)
- {
- alloc(other._nb_of_elem);
- std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+_nb_of_elem,_pointer.getPointer());
- return *this;
- }
-}
-
-#endif
+++ /dev/null
-// 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
#include "MEDCouplingBasicsTest.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingFieldDouble.hxx"
-#include "MemArray.hxx"
+#include "MEDCouplingMemArray.hxx"
#include "Interpolation2D.txx"
#include "Interpolation3DSurf.txx"
#include "Interpolation3D.txx"
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();
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();
{
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);
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 );
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();
+++ /dev/null
-// 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(_time<other._time)
- _time=other._time;
-}
+++ /dev/null
-// 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_TIMELABEL_HXX__
-#define __PARAMEDMEM_TIMELABEL_HXX__
-
-#include "MEDCoupling.hxx"
-
-namespace ParaMEDMEM
-{
- /*!
- * Class representing a label of time of the lastely modified part of this.
- * More _time is high more the object has been modified recently.
- */
- class MEDCOUPLING_EXPORT TimeLabel
- {
- public:
- TimeLabel& operator=(const TimeLabel& other);
- //! This method should be called when write access has been done on this.
- void declareAsNew();
- //! This method should be called on high level classes as Field or Mesh to take into acount modifications done in aggragates objects.
- virtual void updateTime() = 0;
- protected:
- TimeLabel();
- void updateTimeWith(const TimeLabel& other);
- private:
- static unsigned int GLOBAL_TIME;
- unsigned int _time;
- };
-}
-
-#endif
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "BlockTopology.hxx"
-#include "MemArray.hxx"
-#include "MEDCouplingRMesh.hxx"
+#include "MEDCouplingMemArray.hxx"
+#include "MEDCouplingCMesh.hxx"
#include "CommInterface.hxx"
#include "ProcessorGroup.hxx"
#include "MPIProcessorGroup.hxx"
* instead of making the best choice with respect to the
* values of the different axes.
*/
- BlockTopology::BlockTopology(const ProcessorGroup& group, MEDCouplingRMesh *grid):
+ BlockTopology::BlockTopology(const ProcessorGroup& group, MEDCouplingCMesh *grid):
_proc_group(&group), _dimension(grid->getSpaceDimension()), _owns_processor_group(false)
{
vector <int> axis_length(_dimension);
namespace ParaMEDMEM
{
class ComponentTopology;
- class MEDCouplingRMesh;
+ class MEDCouplingCMesh;
typedef enum{Block,Cycle} CYCLE_TYPE;
{
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();
// First stage : exchanging sizes
// ------------------------------
vector<int> tinyInfoLocal,tinyInfoDistant;
- local_mesh->getTinySerializationInformation(tinyInfoLocal);
+ vector<string> 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);
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<std::string> 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,
*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,
#ifndef __PARAFIELD_HXX__
#define __PARAFIELD_HXX__
-#include "RefCountObject.hxx"
+#include "MEDCouplingRefCountObject.hxx"
namespace ParaMEDMEM
{
#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 <iostream>
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<BlockTopology*>(topology);
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());*/
{
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
#include "MPIProcessorGroup.hxx"
#include "Topology.hxx"
#include "BlockTopology.hxx"
-#include "MemArray.hxx"
+#include "MEDCouplingMemArray.hxx"
#include <fstream>
#include <vector>
#include "MEDCouplingPointSet.hxx"
#include "ProcessorGroup.hxx"
-#include "MemArray.hxx"
+#include "MEDCouplingMemArray.hxx"
#include <string>
#include <vector>
std::transform(field0->getArray()->getPointer(),field0->getArray()->getPointer()+16,expectedValues,diffValue,std::minus<double>());
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<MEDCouplingUMesh *>(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<const MEDCouplingUMesh *>(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);
std::transform(field1->getArray()->getPointer(),field1->getArray()->getPointer()+48,expectedValues2,diffValue2,std::minus<double>());
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<MEDCouplingUMesh *>(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<const MEDCouplingUMesh *>(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<std::string> fieldsNameNode=MEDLoader::GetNodeFieldNamesOnMesh(fileName,meshNames[0].c_str());
std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues3,diffValue3,std::minus<double>());
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<MEDCouplingUMesh *>(field0Nodes->getMesh());
- CPPUNIT_ASSERT(mesh);
+ constMesh=dynamic_cast<const MEDCouplingUMesh *>(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);
std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues4,diffValue3,std::minus<double>());
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<MEDCouplingUMesh *>(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<const MEDCouplingUMesh *>(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);
std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues5,diffValue3,std::minus<double>());
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<MEDCouplingUMesh *>(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<const MEDCouplingUMesh *>(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();
}
CPPUNIT_ASSERT(field->getName()==fieldsName[0]);
CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfComponents());
CPPUNIT_ASSERT_EQUAL(538,field->getNumberOfTuples());
- mesh=dynamic_cast<MEDCouplingUMesh *>(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<const MEDCouplingUMesh *>(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<double>());
+ 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<double>());
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();