From 4d877e4075f36807dc36cd9fc7b28651e3f5bb69 Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 30 Jul 2010 09:48:36 +0000 Subject: [PATCH] Addition of Gauss Points. --- src/MEDCoupling/MEDCouplingField.cxx | 118 +- src/MEDCoupling/MEDCouplingField.hxx | 14 + .../MEDCouplingFieldDiscretization.cxx | 548 ++++++- .../MEDCouplingFieldDiscretization.hxx | 114 +- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 40 +- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 5 +- .../MEDCouplingGaussLocalization.cxx | 215 +++ .../MEDCouplingGaussLocalization.hxx | 66 + src/MEDCoupling/MEDCouplingRefCountObject.hxx | 4 +- src/MEDCoupling/Makefile.am | 19 +- .../Test/MEDCouplingBasicsTest.hxx | 10 + .../Test/MEDCouplingBasicsTest2.cxx | 144 ++ src/MEDCoupling/Test/Makefile.am | 2 +- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 1297 +++++++++-------- src/MEDCoupling_Swig/libMEDCoupling_Swig.i | 37 + 15 files changed, 2007 insertions(+), 626 deletions(-) create mode 100644 src/MEDCoupling/MEDCouplingGaussLocalization.cxx create mode 100644 src/MEDCoupling/MEDCouplingGaussLocalization.hxx create mode 100644 src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 11af98a4b..bc300e025 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -29,7 +29,7 @@ bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, d return false; if(_desc!=other->_desc) return false; - if(!_type->isEqual(other->_type)) + if(!_type->isEqual(other->_type,valsPrec)) return false; if(_mesh==0 && other->_mesh==0) return true; @@ -42,13 +42,11 @@ bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, d bool MEDCouplingField::areCompatible(const MEDCouplingField *other) const { - if(!_type->isEqual(other->_type)) + if(!_type->isEqual(other->_type,1.)) return false; if(_mesh==other->_mesh) return true; - if(!_mesh->areCompatible(other->_mesh)) - return false; - return true; + return _mesh->areCompatible(other->_mesh); } void MEDCouplingField::updateTime() @@ -77,6 +75,114 @@ void MEDCouplingField::setMesh(const MEDCouplingMesh *mesh) } } +/*! + * This method sets gauss localization by geometric type. + * @param type geometric type on which the gauss localization will be set. + * @param refCoo is the reference coordinates of the specified element. Its size has to be equal to nbOfNodesPerCell*dimOfType + * @param gsCoo are the coordinates of Gauss points in reference element specified by 'refCoo'. Its size must be equal to wg.size()*dimOfType + * @param wg are the weights on Gauss points. The size of this array is used to determine the number of Gauss point in the element. + * @throw when size of 'RefCoo' is not valid regarding 'type' parameter, it throws too when the mesh is not set before or if it is not a field on Gauss points. + */ +void MEDCouplingField::setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnType method !"); + _type->setGaussLocalizationOnType(_mesh,type,refCoo,gsCoo,wg); +} + +/*! + * This method sets on ids defined by [begin;end) their gauss localization. This method checks the coherency of cells ids in [begin;end) and 'refCoo' size. + * If an incoherence appears an exception will be thrown and no seting will be performed. + * An exception is thrown too if [begin,end) has a size lesser than 1. + * + * @param refCoo is the reference coordinates of the specified element. Its size has to be equal to nbOfNodesPerCell*dimOfType + * @param gsCoo are the coordinates of Gauss points in reference element specified by 'refCoo'. Its size must be equal to wg.size()*dimOfType + * @param wg are the weights on Gauss points. The size of this array is used to determine the number of Gauss point in the element. + * @throw when size of 'RefCoo' is not valid regarding cells in [begin,end) parameters, it throws too when the mesh is not set before or if it is not a field on Gauss points. + */ +void MEDCouplingField::setGaussLocalizationOnCells(const int *begin, const int *end, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnCells method !"); + _type->setGaussLocalizationOnCells(_mesh,begin,end,refCoo,gsCoo,wg); +} + +/*! + * This method resets all Gauss loalizations if any. + */ +void MEDCouplingField::clearGaussLocalizations() +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling clearGaussLocalizations method !"); + _type->clearGaussLocalizations(); +} + +/*! + * This method returns reference to the Gauss localization object corresponding to 'locId' id. + * This method throws an exception if there is no mesh, invalid FieldDescription (different from Gauss) and if 'locId' is invalid because out of range given by + * MEDCouplingField::getNbOfGaussLocalization method. + * Warning this method is not const, so the returned object could be modified without any problem. + */ +MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception) +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !"); + return _type->getGaussLocalization(locId); +} + +/*! + * This method returns number of Gauss localization available. Implicitely all ids in [0,getNbOfGaussLocalization()) is a valid Gauss localisation id. + * This method throws an exception if there is no mesh, invalid FieldDescription (different from Gauss) + */ +int MEDCouplingField::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception) +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling getNbOfGaussLocalization method !"); + return _type->getNbOfGaussLocalization(); +} + +/*! + * This method returns an id of Gauss localization in [0,getNbOfGaussLocalization()) that corresponds to the localization of the cell specified by its cellId. + * This methods throws an exception if there is no mesh, invalid FieldDescription (different from Gauss) or if at the cell with id 'cellId' in this->_mesh no + * Gauss localization has been set. + */ +int MEDCouplingField::getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception) +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !"); + return _type->getGaussLocalizationIdOfOneCell(cellId); +} + +/*! + * This method returns all cellIds that share the same Gauss localization given by 'locId' parameter (in range [0,getNbOfGaussLocalization()) ). + * If no cells fit the Gauss localization given by 'locId' cellIds will be returned empty. + * @param locId input that specifies the id of Gauss localization. + * @param cellIds output parameter, that will contain the result if this method succeds. This parameter is systematically cleared when called. + * @throw if there is no mesh, invalid FieldDescription (different from Gauss) or if locId not in [0,getNbOfGaussLocalization()) + */ +void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) +{ + cellIds.clear(); + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !"); + _type->getCellIdsHavingGaussLocalization(locId,cellIds); +} + +/*! + * This method returns reference to the Gauss localization object corresponding to 'locId' id. + * This method throws an exception if there is no mesh, invalid FieldDescription (different from Gauss) and if 'locId' is invalid because out of range given by + * MEDCouplingField::getNbOfGaussLocalization method. + * Warning this method is const. + */ +const MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception) +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !"); + return _type->getGaussLocalization(locId); +} + MEDCouplingField::~MEDCouplingField() { if(_mesh) @@ -88,7 +194,7 @@ MEDCouplingField::MEDCouplingField(TypeOfField type):_mesh(0),_type(MEDCouplingF { } -MEDCouplingField::MEDCouplingField(const MEDCouplingField& other):_name(other._name),_desc(other._name), +MEDCouplingField::MEDCouplingField(const MEDCouplingField& other):_name(other._name),_desc(other._desc), _mesh(0),_type(other._type->clone()) { if(other._mesh) diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index 932c5d54c..e915a1f91 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -23,15 +23,18 @@ #include "MEDCoupling.hxx" #include "MEDCouplingTimeLabel.hxx" #include "MEDCouplingRefCountObject.hxx" +#include "NormalizedUnstructuredMesh.hxx" #include "InterpKernelException.hxx" #include +#include namespace ParaMEDMEM { class DataArrayInt; class MEDCouplingMesh; class MEDCouplingFieldDiscretization; + class MEDCouplingGaussLocalization; class MEDCOUPLING_EXPORT MEDCouplingField : public RefCountObject, public TimeLabel { @@ -48,6 +51,17 @@ namespace ParaMEDMEM TypeOfField getTypeOfField() const; MEDCouplingMesh *buildSubMeshData(const int *start, const int *end, DataArrayInt *&di) const; MEDCouplingFieldDiscretization *getDiscretization() const { return _type; } + // Gauss point specific methods + void setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); + void setGaussLocalizationOnCells(const int *begin, const int *end, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); + void clearGaussLocalizations(); + MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); + int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); + int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); + void getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); + const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); protected: void updateTime(); protected: diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 7e7c7b298..4d8a0d0fd 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -21,6 +21,7 @@ #include "MEDCouplingPointSet.hxx" #include "MEDCouplingCMesh.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "CellModel.hxx" #include "InterpolationUtils.hxx" @@ -40,6 +41,14 @@ const char MEDCouplingFieldDiscretizationP1::REPR[]="P1"; const TypeOfField MEDCouplingFieldDiscretizationP1::TYPE=ON_NODES; +const char MEDCouplingFieldDiscretizationGauss::REPR[]="GAUSS"; + +const TypeOfField MEDCouplingFieldDiscretizationGauss::TYPE=ON_GAUSS_PT; + +const char MEDCouplingFieldDiscretizationGaussNE::REPR[]="GSSNE"; + +const TypeOfField MEDCouplingFieldDiscretizationGaussNE::TYPE=ON_GAUSS_NE; + MEDCouplingFieldDiscretization::MEDCouplingFieldDiscretization():_precision(DFLT_PRECISION) { } @@ -52,6 +61,10 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::New(TypeOfField return new MEDCouplingFieldDiscretizationP0; case MEDCouplingFieldDiscretizationP1::TYPE: return new MEDCouplingFieldDiscretizationP1; + case MEDCouplingFieldDiscretizationGauss::TYPE: + return new MEDCouplingFieldDiscretizationGauss; + case MEDCouplingFieldDiscretizationGaussNE::TYPE: + return new MEDCouplingFieldDiscretizationGaussNE; default: throw INTERP_KERNEL::Exception("Choosen discretization is not implemented yet."); } @@ -64,9 +77,96 @@ TypeOfField MEDCouplingFieldDiscretization::getTypeOfFieldFromStringRepr(const c return MEDCouplingFieldDiscretizationP0::TYPE; if(reprCpp==MEDCouplingFieldDiscretizationP1::REPR) return MEDCouplingFieldDiscretizationP1::TYPE; + if(reprCpp==MEDCouplingFieldDiscretizationGauss::REPR) + return MEDCouplingFieldDiscretizationGauss::TYPE; + if(reprCpp==MEDCouplingFieldDiscretizationGaussNE::REPR) + return MEDCouplingFieldDiscretizationGaussNE::TYPE; throw INTERP_KERNEL::Exception("Representation does not match with any field discretization !"); } +void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& arr) const +{ + arr=0; +} + + +/*! + * Empty : Not a bug + */ +void MEDCouplingFieldDiscretization::getTinySerializationIntInformation(std::vector& tinyInfo) const +{ +} + +/*! + * Empty : Not a bug + */ +void MEDCouplingFieldDiscretization::getTinySerializationDbleInformation(std::vector& tinyInfo) const +{ +} + +void MEDCouplingFieldDiscretization::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *& arr) +{ + arr=0; +} + +/*! + * Empty : Not a bug + */ +void MEDCouplingFieldDiscretization::finishUnserialization(const std::vector& tinyInfo) +{ +} + +double MEDCouplingFieldDiscretization::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, + int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("getIJK Invalid ! only for GaussPoint and GaussNE discretizations !"); +} + +void MEDCouplingFieldDiscretization::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + +void MEDCouplingFieldDiscretization::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + +void MEDCouplingFieldDiscretization::clearGaussLocalizations() throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + +MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + +int MEDCouplingFieldDiscretization::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + +int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + +void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + +const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception) +{ +} + +MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization() +{ +} + TypeOfField MEDCouplingFieldDiscretizationP0::getEnum() const { return TYPE; @@ -82,7 +182,7 @@ const char *MEDCouplingFieldDiscretizationP0::getStringRepr() const return REPR; } -bool MEDCouplingFieldDiscretizationP0::isEqual(const MEDCouplingFieldDiscretization *other) const +bool MEDCouplingFieldDiscretizationP0::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const { const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast(other); return otherC!=0; @@ -172,7 +272,7 @@ const char *MEDCouplingFieldDiscretizationP1::getStringRepr() const return REPR; } -bool MEDCouplingFieldDiscretizationP1::isEqual(const MEDCouplingFieldDiscretization *other) const +bool MEDCouplingFieldDiscretizationP1::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const { const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast(other); return otherC!=0; @@ -313,3 +413,447 @@ MEDCouplingMesh *MEDCouplingFieldDiscretizationP1::buildSubMeshData(const int *s diInv->decrRef(); return ret; } + +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell():_discr_per_cell(0) +{ +} + +MEDCouplingFieldDiscretizationPerCell::~MEDCouplingFieldDiscretizationPerCell() +{ + if(_discr_per_cell) + _discr_per_cell->decrRef(); +} + +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other):_discr_per_cell(0) +{ + DataArrayInt *arr=other._discr_per_cell; + if(arr) + _discr_per_cell=arr->deepCopy(); +} + +void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +{ + if(!_discr_per_cell) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has no discretization per cell !"); + int nbOfTuples=_discr_per_cell->getNumberOfTuples(); + if(nbOfTuples!=mesh->getNumberOfCells()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has a discretization per cell but it's not matching the underlying mesh !"); +} + +bool MEDCouplingFieldDiscretizationPerCell::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const +{ + const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_discr_per_cell==0) + return otherC->_discr_per_cell==0; + if(otherC->_discr_per_cell==0) + return false; + return _discr_per_cell->isEqual(*otherC->_discr_per_cell); +} + +void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *m) +{ + if(!_discr_per_cell) + { + _discr_per_cell=DataArrayInt::New(); + int nbTuples=m->getNumberOfCells(); + _discr_per_cell->alloc(nbTuples,1); + int *ptr=_discr_per_cell->getPointer(); + std::fill(ptr,ptr+nbTuples,-1); + } +} + +MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss() +{ +} + +MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other):MEDCouplingFieldDiscretizationPerCell(other),_loc(other._loc) +{ +} + +TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const +{ + return TYPE; +} + +bool MEDCouplingFieldDiscretizationGauss::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const +{ + const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(!MEDCouplingFieldDiscretizationPerCell::isEqual(other,eps)) + return false; + if(_loc.size()!=otherC->_loc.size()) + return false; + int sz=_loc.size(); + for(int i=0;i_loc[i],eps)) + return false; + return true; +} + +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clone() const +{ + return new MEDCouplingFieldDiscretizationGauss(*this); +} + +const char *MEDCouplingFieldDiscretizationGauss::getStringRepr() const +{ + return REPR; +} + +int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *mesh) const +{ + int ret=0; + const int *dcPtr=_discr_per_cell->getConstPointer(); + int nbOfTuples=_discr_per_cell->getNumberOfTuples(); + for(const int *w=dcPtr;w!=dcPtr+nbOfTuples;w++) + ret+=_loc[*w].getNumberOfGaussPt(); + return ret; +} + +DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +/*! + * Empty : not a bug + */ +void MEDCouplingFieldDiscretizationGauss::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +{ +} + +void MEDCouplingFieldDiscretizationGauss::getTinySerializationIntInformation(std::vector& tinyInfo) const +{ + int val=-1; + if(_discr_per_cell) + val=_discr_per_cell->getNumberOfTuples(); + tinyInfo.push_back(val); + tinyInfo.push_back(_loc.size()); + if(_loc.empty()) + tinyInfo.push_back(-1); + else + tinyInfo.push_back(_loc[0].getDimension()); + for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++) + (*iter).pushTinySerializationIntInfo(tinyInfo); +} + +void MEDCouplingFieldDiscretizationGauss::getTinySerializationDbleInformation(std::vector& tinyInfo) const +{ + for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++) + (*iter).pushTinySerializationDblInfo(tinyInfo); +} + +void MEDCouplingFieldDiscretizationGauss::getSerializationIntArray(DataArrayInt *& arr) const +{ + arr=0; + if(_discr_per_cell) + arr=_discr_per_cell; +} + +void MEDCouplingFieldDiscretizationGauss::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *& arr) +{ + int val=tinyInfo[0]; + if(val>=0) + { + _discr_per_cell=DataArrayInt::New(); + _discr_per_cell->alloc(val,1); + } + else + _discr_per_cell=0; + arr=_discr_per_cell; + int nbOfLoc=tinyInfo[1]; + _loc.clear(); + int dim=tinyInfo[2]; + int delta=-1; + if(nbOfLoc>0) + delta=(tinyInfo.size()-3)/nbOfLoc; + for(int i=0;i tmp(tinyInfo.begin()+3+i*delta,tinyInfo.begin()+3+(i+1)*delta); + MEDCouplingGaussLocalization elt=MEDCouplingGaussLocalization::buildNewInstanceFromTinyInfo(dim,tmp); + _loc.push_back(elt); + } +} + +void MEDCouplingFieldDiscretizationGauss::finishUnserialization(const std::vector& tinyInfo) +{ + double *tmp=new double[tinyInfo.size()]; + std::copy(tinyInfo.begin(),tinyInfo.end(),tmp); + const double *work=tmp; + for(std::vector::iterator iter=_loc.begin();iter!=_loc.end();iter++) + work=(*iter).fillWithValues(work); + delete [] tmp; +} + +double MEDCouplingFieldDiscretizationGauss::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, + int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception) +{ + int offset=getOffsetOfCell(cellId); + return da->getIJ(offset+nodeIdInCell,compoId); +} + +void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(mesh,da); + for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++) + (*iter).checkCoherency(); + int nbOfDesc=_loc.size(); + int nbOfCells=mesh->getNumberOfCells(); + const int *dc=_discr_per_cell->getConstPointer(); + for(int i=0;i=nbOfDesc) + { + std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has an undefined gauss location ! Should never happend !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(dc[i]<0) + { + std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has no gauss location !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(mesh->getTypeOfCell(i)!=_loc[dc[i]].getType()) + { + std::ostringstream oss; oss << "Types of mesh and gauss location mismatch for cell # " << i; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + int nbOfTuples=getNumberOfTuples(mesh); + if(nbOfTuples!=da->getNumberOfTuples()) + { + std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGauss::getWeightingField(const MEDCouplingMesh *mesh, bool isAbs) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +void MEDCouplingFieldDiscretizationGauss::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +void MEDCouplingFieldDiscretizationGauss::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const +{ + throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applyable for Gauss points !"); +} + +MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const int *start, const int *end, const MEDCouplingMesh *mesh, DataArrayInt *&di) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +void MEDCouplingFieldDiscretizationGauss::renumberValuesOnNodes(const DataArrayInt *old2New, DataArrayDouble *arr) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +{ + buildDiscrPerCellIfNecessary(m); + int id=_loc.size(); + MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); + _loc.push_back(elt); + int *ptr=_discr_per_cell->getPointer(); + int nbCells=m->getNumberOfCells(); + for(int i=0;igetTypeOfCell(i)==type) + ptr[i]=id; +} + +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +{ + buildDiscrPerCellIfNecessary(m); + if(std::distance(begin,end)<1) + throw INTERP_KERNEL::Exception("Size of [begin,end) must be equal or greater than 1 !"); + INTERP_KERNEL::NormalizedCellType type=m->getTypeOfCell(*begin); + MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); + int id=_loc.size(); + int *ptr=_discr_per_cell->getPointer(); + for(const int *w=begin+1;w!=end;w++) + { + if(m->getTypeOfCell(*w)!=type) + { + std::ostringstream oss; oss << "The cell with id " << *w << " has been detected to be incompatible in the [begin,end) array specified !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + // + for(const int *w2=begin;w2!=end;w2++) + ptr[*w2]=id; + // + _loc.push_back(elt); +} + +void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() throw(INTERP_KERNEL::Exception) +{ + if(_discr_per_cell) + { + _discr_per_cell->decrRef(); + _discr_per_cell=0; + } + _loc.clear(); +} + +MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception) +{ + checkLocalizationId(locId); + return _loc[locId]; +} + +int MEDCouplingFieldDiscretizationGauss::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception) +{ + return _loc.size(); +} + +int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception) +{ + if(!_discr_per_cell) + throw INTERP_KERNEL::Exception("No Gauss localization still set !"); + int locId=_discr_per_cell->getConstPointer()[cellId]; + if(locId<0) + throw INTERP_KERNEL::Exception("No Gauss localization set for the specified cell !"); + return locId; +} + +void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) +{ + if(locId<0 || locId>=_loc.size()) + throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !"); + int nbOfTuples=_discr_per_cell->getNumberOfTuples(); + const int *ptr=_discr_per_cell->getConstPointer(); + for(int i=0;i=_loc.size()) + throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !"); +} + +int MEDCouplingFieldDiscretizationGauss::getOffsetOfCell(int cellId) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + const int *start=_discr_per_cell->getConstPointer(); + for(const int *w=start;w!=start+cellId;w++) + ret+=_loc[*w].getNumberOfGaussPt(); + return ret; +} + +MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE() +{ +} + +TypeOfField MEDCouplingFieldDiscretizationGaussNE::getEnum() const +{ + return TYPE; +} + +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGaussNE::clone() const +{ + return new MEDCouplingFieldDiscretizationGaussNE(*this); +} + +const char *MEDCouplingFieldDiscretizationGaussNE::getStringRepr() const +{ + return REPR; +} + +bool MEDCouplingFieldDiscretizationGaussNE::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const +{ + const MEDCouplingFieldDiscretizationGaussNE *otherC=dynamic_cast(other); + return otherC!=0; +} + +int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const +{ + int ret=0; + int nbOfCells=mesh->getNumberOfCells(); + for(int i=0;igetTypeOfCell(i); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(type); + if(cm.isDynamic()) + throw INTERP_KERNEL::Exception("Not implemented yet Gauss node on elements for polygons and polyedrons !"); + ret+=cm.getNumberOfNodes(); + } + return ret; +} + +DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +{ +} + +double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, + int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception) +{ + int offset=0; + for(int i=0;igetTypeOfCell(i); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(type); + offset+=cm.getNumberOfNodes(); + } + return da->getIJ(offset+nodeIdInCell,compoId); +} + +void MEDCouplingFieldDiscretizationGaussNE::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +{ + int nbOfTuples=getNumberOfTuples(mesh); + if(nbOfTuples!=da->getNumberOfTuples()) + { + std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGaussNE::getWeightingField(const MEDCouplingMesh *mesh, bool isAbs) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +void MEDCouplingFieldDiscretizationGaussNE::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +void MEDCouplingFieldDiscretizationGaussNE::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const +{ + throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applyable for Gauss points !"); +} + +MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const int *start, const int *end, const MEDCouplingMesh *mesh, DataArrayInt *&di) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnNodes(const DataArrayInt *old2New, DataArrayDouble *arr) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other):MEDCouplingFieldDiscretization(other) +{ +} + diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 25d52f542..057f4d741 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -24,6 +24,7 @@ #include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" #include "MEDCouplingNatureOfField.hxx" +#include "MEDCouplingGaussLocalization.hxx" namespace ParaMEDMEM { @@ -40,18 +41,35 @@ namespace ParaMEDMEM void setPrecision(double val) { _precision=val; } static TypeOfField getTypeOfFieldFromStringRepr(const char *repr) throw(INTERP_KERNEL::Exception); virtual TypeOfField getEnum() const = 0; - virtual bool isEqual(const MEDCouplingFieldDiscretization *other) const = 0; + virtual bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const = 0; virtual MEDCouplingFieldDiscretization *clone() const = 0; virtual const char *getStringRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const = 0; virtual DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const = 0; virtual void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) = 0; + virtual double getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception); virtual void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) = 0; virtual MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh, bool isAbs) const = 0; virtual void getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const = 0; virtual void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const = 0; virtual MEDCouplingMesh *buildSubMeshData(const int *start, const int *end, const MEDCouplingMesh *mesh, DataArrayInt *&di) const = 0; virtual void renumberValuesOnNodes(const DataArrayInt *old2New, DataArrayDouble *arr) const = 0; + virtual void getSerializationIntArray(DataArrayInt *& arr) const; + virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; + virtual void getTinySerializationDbleInformation(std::vector& tinyInfo) const; + virtual void finishUnserialization(const std::vector& tinyInfo); + virtual void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *& arr); + virtual void setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); + virtual void setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); + virtual void clearGaussLocalizations() throw(INTERP_KERNEL::Exception); + virtual MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); + virtual int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); + virtual int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); + virtual void getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); + virtual const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); + virtual ~MEDCouplingFieldDiscretization(); protected: MEDCouplingFieldDiscretization(); protected: @@ -65,7 +83,7 @@ namespace ParaMEDMEM TypeOfField getEnum() const; MEDCouplingFieldDiscretization *clone() const; const char *getStringRepr() const; - bool isEqual(const MEDCouplingFieldDiscretization *other) const; + bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); @@ -86,7 +104,7 @@ namespace ParaMEDMEM TypeOfField getEnum() const; MEDCouplingFieldDiscretization *clone() const; const char *getStringRepr() const; - bool isEqual(const MEDCouplingFieldDiscretization *other) const; + bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); @@ -101,6 +119,96 @@ namespace ParaMEDMEM static const char REPR[]; static const TypeOfField TYPE; }; + + /*! + * This class abstracts MEDCouplingFieldDiscretization that needs an information on each cell to perform their job. + * All classes that inherits from this are more linked to mesh. + */ + class MEDCOUPLING_EXPORT MEDCouplingFieldDiscretizationPerCell : public MEDCouplingFieldDiscretization + { + protected: + MEDCouplingFieldDiscretizationPerCell(); + MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other); + ~MEDCouplingFieldDiscretizationPerCell(); + void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; + protected: + void buildDiscrPerCellIfNecessary(const MEDCouplingMesh *m); + protected: + DataArrayInt *_discr_per_cell; + }; + + class MEDCOUPLING_EXPORT MEDCouplingFieldDiscretizationGauss : public MEDCouplingFieldDiscretizationPerCell + { + public: + MEDCouplingFieldDiscretizationGauss(); + TypeOfField getEnum() const; + bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; + MEDCouplingFieldDiscretization *clone() const; + const char *getStringRepr() const; + int getNumberOfTuples(const MEDCouplingMesh *mesh) const; + DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; + void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); + void getTinySerializationIntInformation(std::vector& tinyInfo) const; + void getTinySerializationDbleInformation(std::vector& tinyInfo) const; + void finishUnserialization(const std::vector& tinyInfo); + void getSerializationIntArray(DataArrayInt *& arr) const; + void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *& arr); + double getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception); + void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh, bool isAbs) const; + void getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const; + void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const; + MEDCouplingMesh *buildSubMeshData(const int *start, const int *end, const MEDCouplingMesh *mesh, DataArrayInt *&di) const; + void renumberValuesOnNodes(const DataArrayInt *old2New, DataArrayDouble *arr) const; + void setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); + void setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); + void clearGaussLocalizations() throw(INTERP_KERNEL::Exception); + MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); + int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); + int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); + void getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); + const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); + protected: + MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other); + int getOffsetOfCell(int cellId) const throw(INTERP_KERNEL::Exception); + void checkLocalizationId(int locId) const throw(INTERP_KERNEL::Exception); + public: + static const char REPR[]; + static const TypeOfField TYPE; + private: + std::vector _loc; + }; + + /*! + * Gauss with points of values located on nodes of element. This is a specialization of MEDCouplingFieldDiscretizationGauss. + */ + class MEDCOUPLING_EXPORT MEDCouplingFieldDiscretizationGaussNE : public MEDCouplingFieldDiscretization + { + public: + MEDCouplingFieldDiscretizationGaussNE(); + TypeOfField getEnum() const; + MEDCouplingFieldDiscretization *clone() const; + const char *getStringRepr() const; + bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; + int getNumberOfTuples(const MEDCouplingMesh *mesh) const; + DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; + void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); + double getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception); + void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh, bool isAbs) const; + void getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const; + void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const; + MEDCouplingMesh *buildSubMeshData(const int *start, const int *end, const MEDCouplingMesh *mesh, DataArrayInt *&di) const; + void renumberValuesOnNodes(const DataArrayInt *old2New, DataArrayDouble *arr) const; + protected: + MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other); + public: + static const char REPR[]; + static const TypeOfField TYPE; + }; } #endif diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 00f7ab781..7a2914fcd 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -294,6 +294,11 @@ void MEDCouplingFieldDouble::setNature(NatureOfField nat) throw(INTERP_KERNEL::E _nature=nat; } +double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) const +{ + return _type->getIJK(_mesh,getArray(),cellId,nodeIdInCell,compoId); +} + void MEDCouplingFieldDouble::setArray(DataArrayDouble *array) { _time_discr->setArray(array,this); @@ -324,6 +329,10 @@ void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector tinyInfo.push_back((int)_time_discr->getEnum()); tinyInfo.push_back((int)_nature); _time_discr->getTinySerializationIntInformation(tinyInfo); + std::vector tinyInfo2; + _type->getTinySerializationIntInformation(tinyInfo2); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.push_back(tinyInfo2.size()); } /*! @@ -334,25 +343,45 @@ void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vectorgetTinySerializationDbleInformation(tinyInfo); + std::vector tinyInfo2; + _type->getTinySerializationDbleInformation(tinyInfo2); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.push_back(tinyInfo2.size()); } /*! * 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 dataInt out parameter. If not null the pointer is already owned by 'this' after the call of this method. In this case no decrRef must be applied. * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by 'this' after the call of this method. * No decrRef must be applied to every instances in returned vector. */ -void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays) -{ - std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); +void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector& arrays) +{ + dataInt=0; + std::vector tinyInfoITmp(tinyInfoI); + int sz=tinyInfoITmp.back(); + tinyInfoITmp.pop_back(); + std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); + std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); _time_discr->resizeForUnserialization(tinyInfoI2,arrays); + std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); + _type->resizeForUnserialization(tinyInfoITmp3,dataInt); } void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); - _time_discr->finishUnserialization(tinyInfoI2,tinyInfoD,tinyInfoS); + // + std::vector tmp(tinyInfoD); + int sz=tinyInfoD.back(); + tmp.pop_back(); + std::vector tmp1(tmp.begin(),tmp.end()-sz); + std::vector tmp2(tmp.end()-sz,tmp.end()); + // + _time_discr->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS); _nature=(NatureOfField)tinyInfoI[2]; + _type->finishUnserialization(tmp2); int nbOfElemS=tinyInfoS.size(); _name=tinyInfoS[nbOfElemS-2]; _desc=tinyInfoS[nbOfElemS-1]; @@ -362,9 +391,10 @@ void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyI * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller. * The values returned must be consulted only in readonly mode. */ -void MEDCouplingFieldDouble::serialize(std::vector& arrays) const +void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector& arrays) const { _time_discr->getArrays(arrays); + _type->getSerializationIntArray(dataInt); } /*! diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 9d0732731..336885e0e 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -48,6 +48,7 @@ namespace ParaMEDMEM double getStartTime(int& dt, int& it) const { return _time_discr->getStartTime(dt,it); } double getEndTime(int& dt, int& it) const { return _time_discr->getEndTime(dt,it); } double getIJ(int tupleId, int compoId) const { return getArray()->getIJ(tupleId,compoId); } + double getIJK(int cellId, int nodeIdInCell, int compoId) const; void setArray(DataArrayDouble *array); void setEndArray(DataArrayDouble *array); DataArrayDouble *getArray() const { return _time_discr->getArray(); } @@ -71,9 +72,9 @@ namespace ParaMEDMEM void getTinySerializationIntInformation(std::vector& tinyInfo) const; void getTinySerializationDbleInformation(std::vector& tinyInfo) const; void getTinySerializationStrInformation(std::vector& tinyInfo) const; - void resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays); + void resizeForUnserialization(const std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector& arrays); void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); - void serialize(std::vector& arrays) const; + void serialize(DataArrayInt *&dataInt, std::vector& arrays) const; bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const { return addFields(this,&other); } diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx new file mode 100644 index 000000000..2b0eb984e --- /dev/null +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx @@ -0,0 +1,215 @@ +// Copyright (C) 2007-2010 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 "MEDCouplingGaussLocalization.hxx" +#include "CellModel.hxx" + +#include +#include +#include +#include + +ParaMEDMEM::MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception) +try:_type(type),_ref_coord(refCoo),_gauss_coord(gsCoo),_weight(w) + { + checkCoherency(); + } +catch(INTERP_KERNEL::Exception& e) + { + _type=INTERP_KERNEL::NORM_ERROR; + _ref_coord.clear(); + _gauss_coord.clear(); + _weight.clear(); + throw e; + } + +void ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherency() const throw(INTERP_KERNEL::Exception) +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type); + int nbNodes=cm.getNumberOfNodes(); + int dim=cm.getDimension(); + if(!cm.isDynamic()) + { + if(_ref_coord.size()!=nbNodes*dim) + { + std::ostringstream oss; oss << "Invalid size of refCoo : expecting to be : " << nbNodes << " (nbNodePerCell) * " << dim << " (dim) !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + if(_gauss_coord.size()!=dim*_weight.size()) + { + std::ostringstream oss; oss << "Invalid gsCoo size and weight size : gsCoo.size() must be equal to _weight.size() * " << dim << " (dim) !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +int ParaMEDMEM::MEDCouplingGaussLocalization::getDimension() const +{ + if(_weight.empty()) + return -1; + return _gauss_coord.size()/_weight.size(); +} + +int ParaMEDMEM::MEDCouplingGaussLocalization::getNumberOfPtsInRefCell() const +{ + int dim=getDimension(); + if(dim==0) + return -1; + return _ref_coord.size()/dim; +} + +bool ParaMEDMEM::MEDCouplingGaussLocalization::isEqual(const MEDCouplingGaussLocalization& other, double eps) const +{ + if(_type!=other._type) + return false; + if(!areAlmostEqual(_ref_coord,other._ref_coord,eps)) + return false; + if(!areAlmostEqual(_gauss_coord,other._gauss_coord,eps)) + return false; + if(!areAlmostEqual(_weight,other._weight,eps)) + return false; + return true; +} + +double ParaMEDMEM::MEDCouplingGaussLocalization::getRefCoords(int ptIdInCell, int comp) const throw(INTERP_KERNEL::Exception) +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type); + int nbNodes=cm.getNumberOfNodes(); + int dim=cm.getDimension(); + if(ptIdInCell<0 || ptIdInCell>=nbNodes) + throw INTERP_KERNEL::Exception("ptIdInCell specified is invalid : must be in [0;nbNodesPerCell) !"); + if(comp<0 || comp>=dim) + throw INTERP_KERNEL::Exception("comp specified is invalid : must be in [0:dimOfCell) !"); + return _ref_coord[ptIdInCell*dim+comp]; +} + +double ParaMEDMEM::MEDCouplingGaussLocalization::getGaussCoord(int gaussPtIdInCell, int comp) const throw(INTERP_KERNEL::Exception) +{ + int dim=checkCoherencyOfRequest(gaussPtIdInCell,comp); + return _gauss_coord[gaussPtIdInCell*dim+comp]; +} + +double ParaMEDMEM::MEDCouplingGaussLocalization::getWeight(int gaussPtIdInCell, double newVal) const throw(INTERP_KERNEL::Exception) +{ + checkCoherencyOfRequest(gaussPtIdInCell,0); + return _weight[gaussPtIdInCell]; +} + +/*! + * Completely useless method for end user. Only for CORBA MPI serialization/unserialization. + * push at the end of tinyInfo its basic serialization info. The size of pushed data is always the same. + * @param tinyInfo inout parameter. + */ +void ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo(std::vector& tinyInfo) const +{ + tinyInfo.push_back((int)_type); + tinyInfo.push_back(getNumberOfPtsInRefCell()); + tinyInfo.push_back(getNumberOfGaussPt()); +} + +/*! + * Completely useless method for end user. Only for CORBA MPI serialization/unserialization. + * push at the end of tinyInfo its basic serialization info. The size of pushed data is \b NOT always the same contrary to pushTinySerializationIntInfo. + * @param tinyInfo inout parameter. + */ +void ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo(std::vector& tinyInfo) const +{ + tinyInfo.insert(tinyInfo.end(),_ref_coord.begin(),_ref_coord.end()); + tinyInfo.insert(tinyInfo.end(),_gauss_coord.begin(),_gauss_coord.end()); + tinyInfo.insert(tinyInfo.end(),_weight.begin(),_weight.end()); +} + +/*! + * This method operates the exact inverse operation than ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo method. This is one of the last step of unserialization process. + * This method should be called on an object resized by buildNewInstanceFromTinyInfo static method. + * This method takes in argument a pointer 'vals' that point to the begin of double data pushed remotely by pushTinySerializationDblInfo method. + * This method returns the pointer 'vals' with an offset of size what it has been read in this method. + */ +const double *ParaMEDMEM::MEDCouplingGaussLocalization::fillWithValues(const double *vals) +{ + const double *work=vals; + std::copy(work,work+_ref_coord.size(),_ref_coord.begin()); + work+=_ref_coord.size(); + std::copy(work,work+_gauss_coord.size(),_gauss_coord.begin()); + work+=_gauss_coord.size(); + std::copy(work,work+_weight.size(),_weight.begin()); + work+=_weight.size(); + return work; +} + +/*! + * This method sets the comp_th component of ptIdInCell_th point coordinate of reference element of type this->_type. + * @throw if not 0<=ptIdInCell=nbNodes) + throw INTERP_KERNEL::Exception("ptIdInCell specified is invalid : must be in [0;nbNodesPerCell) !"); + if(comp<0 || comp>=dim) + throw INTERP_KERNEL::Exception("comp specified is invalid : must be in [0:dimOfCell) !"); + _ref_coord[ptIdInCell*dim+comp]=newVal; +} + +void ParaMEDMEM::MEDCouplingGaussLocalization::setGaussCoord(int gaussPtIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception) +{ + int dim=checkCoherencyOfRequest(gaussPtIdInCell,comp); + _gauss_coord[gaussPtIdInCell*dim+comp]=newVal; +} + +void ParaMEDMEM::MEDCouplingGaussLocalization::setWeight(int gaussPtIdInCell, double newVal) throw(INTERP_KERNEL::Exception) +{ + checkCoherencyOfRequest(gaussPtIdInCell,0); + _weight[gaussPtIdInCell]=newVal; +} + +/*! + * The format of 'tinyData' parameter is the same than pushed in method ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo. + */ +ParaMEDMEM::MEDCouplingGaussLocalization ParaMEDMEM::MEDCouplingGaussLocalization::buildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData) +{ + std::vector v1(dim*tinyData[1]),v2(dim*tinyData[2]),v3(tinyData[2]); + return ParaMEDMEM::MEDCouplingGaussLocalization((INTERP_KERNEL::NormalizedCellType)tinyData[0],v1,v2,v3); +} + +int ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherencyOfRequest(int gaussPtIdInCell, int comp) const throw(INTERP_KERNEL::Exception) +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type); + int dim=cm.getDimension(); + int nbGsPts=getNumberOfGaussPt(); + if(gaussPtIdInCell<0 || gaussPtIdInCell>=nbGsPts) + throw INTERP_KERNEL::Exception("gaussPtIdInCell specified is invalid : must be in [0:nbGsPts) !"); + if(comp<0 || comp>=dim) + throw INTERP_KERNEL::Exception("comp specified is invalid : must be in [0:dimOfCell) !"); + return dim; +} + +bool ParaMEDMEM::MEDCouplingGaussLocalization::areAlmostEqual(const std::vector& v1, const std::vector& v2, double eps) +{ + int sz=v1.size(); + if(sz!=v2.size()) + return false; + std::vector tmp(sz); + std::transform(v1.begin(),v1.end(),v2.begin(),tmp.begin(),std::minus()); + std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::ptr_fun(fabs)); + return *std::max_element(tmp.begin(),tmp.end()) + +namespace ParaMEDMEM +{ + class MEDCouplingMesh; + + class MEDCouplingGaussLocalization + { + public: + MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception); + INTERP_KERNEL::NormalizedCellType getType() const { return _type; } + int getNumberOfGaussPt() const { return _weight.size(); } + int getDimension() const; + int getNumberOfPtsInRefCell() const; + void checkCoherency() const throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDCouplingGaussLocalization& other, double eps) const; + void pushTinySerializationIntInfo(std::vector& tinyInfo) const; + void pushTinySerializationDblInfo(std::vector& tinyInfo) const; + const double *fillWithValues(const double *vals); + // + double getRefCoords(int ptIdInCell, int comp) const throw(INTERP_KERNEL::Exception); + double getGaussCoord(int gaussPtIdInCell, int comp) const throw(INTERP_KERNEL::Exception); + double getWeight(int gaussPtIdInCell, double newVal) const throw(INTERP_KERNEL::Exception); + void setRefCoords(int ptIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception); + void setGaussCoord(int gaussPtIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception); + void setWeight(int gaussPtIdInCell, double newVal) throw(INTERP_KERNEL::Exception); + // + static MEDCouplingGaussLocalization buildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData); + private: + int checkCoherencyOfRequest(int gaussPtIdInCell, int comp) const throw(INTERP_KERNEL::Exception); + static bool areAlmostEqual(const std::vector& v1, const std::vector& v2, double eps); + private: + INTERP_KERNEL::NormalizedCellType _type; + std::vector _ref_coord; + std::vector _gauss_coord; + std::vector _weight; + }; +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.hxx b/src/MEDCoupling/MEDCouplingRefCountObject.hxx index 6929b8533..7a473b6da 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.hxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.hxx @@ -33,7 +33,9 @@ namespace ParaMEDMEM typedef enum { ON_CELLS = 0, - ON_NODES = 1 + ON_NODES = 1, + ON_GAUSS_PT = 2, + ON_GAUSS_NE = 3 } TypeOfField; typedef enum diff --git a/src/MEDCoupling/Makefile.am b/src/MEDCoupling/Makefile.am index 870cf24d5..f02342f05 100644 --- a/src/MEDCoupling/Makefile.am +++ b/src/MEDCoupling/Makefile.am @@ -36,17 +36,16 @@ MEDCouplingCMesh.hxx MEDCouplingTimeDiscretization.hxx MEDCouplingFieldDiscretization.hxx MEDCouplingPointSet.hxx MEDCouplingPointSet.txx \ MEDCouplingUMeshDesc.hxx MEDCouplingNatureOfField.hxx \ MEDCouplingNormalizedCartesianMesh.hxx MEDCouplingNormalizedCartesianMesh.txx \ -MEDCouplingRemapper.hxx MEDCouplingExtrudedMesh.hxx - +MEDCouplingRemapper.hxx MEDCouplingExtrudedMesh.hxx MEDCouplingGaussLocalization.hxx # Libraries targets dist_libmedcoupling_la_SOURCES = \ - MEDCouplingField.cxx MEDCouplingFieldDouble.cxx \ - MEDCouplingUMesh.cxx MEDCouplingMemArray.cxx MEDCouplingTimeLabel.cxx \ - MEDCouplingCMesh.cxx MEDCouplingTimeDiscretization.cxx \ - MEDCouplingFieldDiscretization.cxx MEDCouplingRefCountObject.cxx \ - MEDCouplingPointSet.cxx MEDCouplingUMeshDesc.cxx \ - MEDCouplingExtrudedMesh.cxx MEDCouplingMesh.cxx + MEDCouplingField.cxx MEDCouplingFieldDouble.cxx \ + MEDCouplingUMesh.cxx MEDCouplingMemArray.cxx MEDCouplingTimeLabel.cxx \ + MEDCouplingCMesh.cxx MEDCouplingTimeDiscretization.cxx \ + MEDCouplingFieldDiscretization.cxx MEDCouplingRefCountObject.cxx \ + MEDCouplingPointSet.cxx MEDCouplingUMeshDesc.cxx \ + MEDCouplingExtrudedMesh.cxx MEDCouplingMesh.cxx MEDCouplingGaussLocalization.cxx libmedcoupling_la_LDFLAGS= @@ -89,4 +88,6 @@ EXTRA_DIST += \ MEDCouplingPointSet.txx \ MEDCouplingUMeshDesc.hxx \ MEDCouplingNatureOfField.hxx \ - MEDCouplingRemapper.hxx + MEDCouplingRemapper.hxx \ + MEDCouplingExtrudedMesh.hxx \ + MEDCouplingGaussLocalization.hxx diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 503eba3c0..ce8d1b8c4 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -32,6 +32,7 @@ namespace ParaMEDMEM class MEDCouplingBasicsTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(MEDCouplingBasicsTest); + //MEDCouplingBasicsTest1.cxx CPPUNIT_TEST( testArray ); CPPUNIT_TEST( testArray2 ); CPPUNIT_TEST( testArray3 ); @@ -84,6 +85,10 @@ namespace ParaMEDMEM CPPUNIT_TEST( testFindNodeOnPlane ); CPPUNIT_TEST( testRenumberCells ); CPPUNIT_TEST( testChangeSpaceDimension ); + //MEDCouplingBasicsTest2.cxx + CPPUNIT_TEST( testGaussPointField1 ); + CPPUNIT_TEST( testGaussPointNEField1 ); + //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_2 ); @@ -143,6 +148,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( test2DCurveInterpP1P1_1 ); CPPUNIT_TEST_SUITE_END(); public: + //MEDCouplingBasicsTest1.cxx void testArray(); void testArray2(); void testArray3(); @@ -195,6 +201,10 @@ namespace ParaMEDMEM void testFindNodeOnPlane(); void testRenumberCells(); void testChangeSpaceDimension(); + //MEDCouplingBasicsTest2.cxx + void testGaussPointField1(); + void testGaussPointNEField1(); + //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); void test2DInterpP0P0PL_2(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx new file mode 100644 index 000000000..81d9eee56 --- /dev/null +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -0,0 +1,144 @@ +// Copyright (C) 2007-2010 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 "MEDCouplingBasicsTest.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingCMesh.hxx" +#include "MEDCouplingExtrudedMesh.hxx" +#include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingGaussLocalization.hxx" + +#include +#include + +using namespace ParaMEDMEM; + +void MEDCouplingBasicsTest::testGaussPointField1() +{ + const double _a=0.446948490915965; + const double _b=0.091576213509771; + const double _p1=0.11169079483905; + const double _p2=0.0549758718227661; + const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. }; + const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b, + 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 }; + const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 }; + std::vector _refCoo1(refCoo1,refCoo1+6); + std::vector _gsCoo1(gsCoo1,gsCoo1+12); + std::vector _wg1(wg1,wg1+6); + // + MEDCouplingUMesh *m=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,NO_TIME); + f->setMesh(m); + CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization()); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1); + CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo1,_gsCoo1,_wg1),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_EQUAL(1,f->getNbOfGaussLocalization()); + const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. }; + std::vector _refCoo2(refCoo2,refCoo2+8); + _gsCoo1.resize(4); _wg1.resize(2); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1); + CPPUNIT_ASSERT_EQUAL(2,f->getNbOfGaussLocalization()); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(18,2); + double *ptr=array->getPointer(); + for(int i=0;i<18*2;i++) + ptr[i]=(double)(i+1); + f->setArray(array); + f->setName("MyFirstFieldOnGaussPoint"); + array->decrRef(); + f->checkCoherency(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(27.,f->getIJK(2,5,0),1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(16.,f->getIJK(1,5,1),1e-14); + // + f->clearGaussLocalizations(); + CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization()); + CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception); + int ids1[4]={0,1,3,4}; + CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnCells(ids1,ids1+4,_refCoo2,_gsCoo1,_wg1),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization()); + int ids2[2]={0,4}; + f->setGaussLocalizationOnCells(ids2,ids2+2,_refCoo2,_gsCoo1,_wg1); + CPPUNIT_ASSERT_EQUAL(1,f->getNbOfGaussLocalization()); + CPPUNIT_ASSERT_EQUAL(0,f->getGaussLocalizationIdOfOneCell(0)); + CPPUNIT_ASSERT_THROW(f->getGaussLocalizationIdOfOneCell(1),INTERP_KERNEL::Exception); + int ids3[2]={1,2}; + f->setGaussLocalizationOnCells(ids3,ids3+2,_refCoo1,_gsCoo1,_wg1); + CPPUNIT_ASSERT_EQUAL(2,f->getNbOfGaussLocalization()); + CPPUNIT_ASSERT_EQUAL(0,f->getGaussLocalizationIdOfOneCell(0)); + CPPUNIT_ASSERT_EQUAL(1,f->getGaussLocalizationIdOfOneCell(1)); + CPPUNIT_ASSERT_EQUAL(1,f->getGaussLocalizationIdOfOneCell(2)); + CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);//<- cell 3 has no localization + int ids4[1]={3}; + std::vector _gsCoo2(_gsCoo1); + std::vector _wg2(_wg1); + _gsCoo2[0]=0.8888777776666; _wg2[0]=0.1234567892377; + f->setGaussLocalizationOnCells(ids4,ids4+1,_refCoo2,_gsCoo2,_wg2); + CPPUNIT_ASSERT_EQUAL(3,f->getNbOfGaussLocalization()); + std::vector tmpIds; + f->getCellIdsHavingGaussLocalization(0,tmpIds); + CPPUNIT_ASSERT_EQUAL(2,(int)tmpIds.size()); + CPPUNIT_ASSERT(std::equal(ids2,ids2+2,tmpIds.begin())); + CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);//<- it's always not ok because undelying array not with the good size. + DataArrayDouble *array2=f->getArray()->substr(0,10); + f->setArray(array2); + array2->decrRef(); + f->checkCoherency();//<- here it is OK + MEDCouplingFieldDouble *f2=f->clone(true); + CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14)); + MEDCouplingGaussLocalization& gl1=f2->getGaussLocalization(0); + double tmp=gl1.getGaussCoord(1,1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.07*_b-1,tmp,1e-14); + gl1.setGaussCoord(1,1,0.07); + CPPUNIT_ASSERT(!f->isEqual(f2,1e-14,1e-14)); + gl1.setGaussCoord(1,1,tmp); + CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14)); + f->decrRef(); + f2->checkCoherency(); + // + f2->decrRef(); + m->decrRef(); +} + +void MEDCouplingBasicsTest::testGaussPointNEField1() +{ + MEDCouplingUMesh *m=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME); + f->setMesh(m); + f->setName("MyFirstFieldOnNE"); + f->setDescription("MyDescriptionNE"); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(18,2); + double *ptr=array->getPointer(); + for(int i=0;i<18*2;i++) + ptr[i]=(double)(i+7); + f->setArray(array); + array->decrRef(); + // + f->checkCoherency(); + MEDCouplingFieldDouble *f2=f->clone(true); + CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,f->getIJK(2,0,0),1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,f->getIJK(1,1,1),1e-14); + f2->decrRef(); + // + f->decrRef(); + m->decrRef(); +} diff --git a/src/MEDCoupling/Test/Makefile.am b/src/MEDCoupling/Test/Makefile.am index 007f9cf81..e90309b01 100755 --- a/src/MEDCoupling/Test/Makefile.am +++ b/src/MEDCoupling/Test/Makefile.am @@ -26,7 +26,7 @@ TestMEDCoupling_CPPFLAGS=@CPPUNIT_INCLUDES@ @PTHREAD_CFLAGS@ -I$(srcdir)/.. -I$( TestMEDCoupling_LDFLAGS = @CPPUNIT_LIBS@ ../libmedcoupling.la ../../INTERP_KERNEL/libinterpkernel.la dist_TestMEDCoupling_SOURCES = TestMEDCoupling.cxx MEDCouplingBasicsTest.hxx MEDCouplingBasicsTest0.cxx MEDCouplingBasicsTest1.cxx \ - MEDCouplingBasicsTestInterp.cxx MEDCouplingBasicsTestData1.hxx + MEDCouplingBasicsTest2.cxx MEDCouplingBasicsTestInterp.cxx MEDCouplingBasicsTestData1.hxx TestMEDCouplingRemapper_CPPFLAGS=@CPPUNIT_INCLUDES@ @PTHREAD_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../../INTERP_KERNEL/Bases -I$(srcdir)/../../INTERP_KERNELTest -I$(srcdir)/../../INTERP_KERNEL -I$(srcdir)/../../INTERP_KERNEL/Geometric2D diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 8fef761ba..dd70bbff5 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -33,47 +33,47 @@ class MEDCouplingBasicsTest(unittest.TestCase): arr.setInfoOnComponent(3,"kkkkkk"); arr2=arr.convertToIntArr(); arr3=arr2.convertToDblArr(); - self.failUnless(arr.isEqual(arr3,1e-14)) + self.assertTrue(arr.isEqual(arr3,1e-14)) pass def testArray3(self): arr1=DataArrayInt.New(); arr1Ref=[0,10,1,11,2,12,3,13,4,14,5,15,6,16] arr1.setValues(arr1Ref,7,2); - self.failUnlessEqual(7,arr1.getNumberOfTuples()); - self.failUnlessEqual(2,arr1.getNumberOfComponents()); - self.failUnlessEqual(arr1Ref,arr1.getValues()); + self.assertEqual(7,arr1.getNumberOfTuples()); + self.assertEqual(2,arr1.getNumberOfComponents()); + self.assertEqual(arr1Ref,arr1.getValues()); arr2=arr1.substr(3); - self.failUnlessEqual(4,arr2.getNumberOfTuples()); - self.failUnlessEqual(2,arr2.getNumberOfComponents()); - self.failUnlessEqual(arr1Ref[6:],arr2.getValues()); + self.assertEqual(4,arr2.getNumberOfTuples()); + self.assertEqual(2,arr2.getNumberOfComponents()); + self.assertEqual(arr1Ref[6:],arr2.getValues()); arr3=arr1.substr(2,5); - self.failUnlessEqual(3,arr3.getNumberOfTuples()); - self.failUnlessEqual(2,arr3.getNumberOfComponents()); - self.failUnlessEqual(arr1Ref[4:10],arr3.getValues()); + self.assertEqual(3,arr3.getNumberOfTuples()); + self.assertEqual(2,arr3.getNumberOfComponents()); + self.assertEqual(arr1Ref[4:10],arr3.getValues()); # arr4=DataArrayDouble.New(); arr4Ref=[0.8,10.8,1.9,11.9,2.1,12.1,3.2,13.2,4.3,14.3,5.4,15.4,6.5,16.5] arr4.setValues(arr4Ref,7,2); - self.failUnlessEqual(7,arr4.getNumberOfTuples()); - self.failUnlessEqual(2,arr4.getNumberOfComponents()); + self.assertEqual(7,arr4.getNumberOfTuples()); + self.assertEqual(2,arr4.getNumberOfComponents()); tmp=arr4.getValues() for i in xrange(14): - self.failUnless(abs(arr4Ref[i]-tmp[i])<1e-14); + self.assertTrue(abs(arr4Ref[i]-tmp[i])<1e-14); pass arr5=arr4.substr(3); - self.failUnlessEqual(4,arr5.getNumberOfTuples()); - self.failUnlessEqual(2,arr5.getNumberOfComponents()); + self.assertEqual(4,arr5.getNumberOfTuples()); + self.assertEqual(2,arr5.getNumberOfComponents()); tmp=arr5.getValues() for i in xrange(8): - self.failUnless(abs(arr4Ref[6+i]-tmp[i])<1e-14); + self.assertTrue(abs(arr4Ref[6+i]-tmp[i])<1e-14); pass arr6=arr4.substr(2,5); - self.failUnlessEqual(3,arr6.getNumberOfTuples()); - self.failUnlessEqual(2,arr6.getNumberOfComponents()); + self.assertEqual(3,arr6.getNumberOfTuples()); + self.assertEqual(2,arr6.getNumberOfComponents()); tmp=arr6.getValues() for i in xrange(6): - self.failUnless(abs(arr4Ref[4+i]-tmp[i])<1e-14); + self.assertTrue(abs(arr4Ref[4+i]-tmp[i])<1e-14); pass pass @@ -93,23 +93,23 @@ class MEDCouplingBasicsTest(unittest.TestCase): mesh.setMeshDimension(2) mesh.allocateCells(8); mesh.setName("mesh1") - self.failUnless(mesh.getName()=="mesh1") + self.assertTrue(mesh.getName()=="mesh1") for i in range(nbOfCells): mesh.insertNextCell(NORM_QUAD4,4,tab4[4*i:4*(i+1)]); pass mesh.finishInsertingCells() - self.failUnless(mesh.getNumberOfCells()==nbOfCells) - self.failUnless(mesh.getNodalConnectivity().getNbOfElems()==30) - self.failUnless(mesh.getNodalConnectivityIndex().getNbOfElems()==nbOfCells+1) + self.assertTrue(mesh.getNumberOfCells()==nbOfCells) + self.assertTrue(mesh.getNodalConnectivity().getNbOfElems()==30) + self.assertTrue(mesh.getNodalConnectivityIndex().getNbOfElems()==nbOfCells+1) myCoords=DataArrayDouble.New() myCoords.setValues(coords,nbOfNodes,3); - self.failUnless(myCoords.getIJ(3,2)==-0.305) + self.assertTrue(myCoords.getIJ(3,2)==-0.305) mesh.setCoords(myCoords); mesh.checkCoherency(); - self.failUnless(mesh.getAllTypes()==[4]) + self.assertTrue(mesh.getAllTypes()==[4]) myFalseConn=DataArrayInt.New() myFalseConn.setValues(tab4,6,4) - self.failUnless(myFalseConn.getIJ(1,1)==3) + self.assertTrue(myFalseConn.getIJ(1,1)==3) # field=MEDCouplingFieldDouble.New(ON_CELLS) field.setMesh(mesh) @@ -120,7 +120,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): sampleTab.append(float(i)) myCoords.setValues(sampleTab,nbOfCells,9); field.setArray(myCoords) - self.failUnless(3==mesh.getSpaceDimension()) + self.assertTrue(3==mesh.getSpaceDimension()) field.checkCoherency() mesh2=mesh.clone(False) mesh3=mesh.clone(True) @@ -151,26 +151,26 @@ class MEDCouplingBasicsTest(unittest.TestCase): myCoords=DataArrayDouble.New(); myCoords.setValues(targetCoords,9,3); targetMesh.setCoords(myCoords); - self.failUnlessEqual(targetMesh.getSpaceDimension(),3) - self.failUnlessEqual(targetMesh.getNumberOfCells(),8) - self.failUnlessEqual(targetMesh.getNumberOfNodes(),9) - self.failUnlessEqual(targetMesh.getMeshDimension(),0) + self.assertEqual(targetMesh.getSpaceDimension(),3) + self.assertEqual(targetMesh.getNumberOfCells(),8) + self.assertEqual(targetMesh.getNumberOfNodes(),9) + self.assertEqual(targetMesh.getMeshDimension(),0) pass def testMeshM1D(self): meshM1D=MEDCouplingUMesh.New(); - self.failUnlessRaises(Exception,meshM1D.getMeshDimension); - self.failUnlessRaises(Exception,meshM1D.getNumberOfNodes); - self.failUnlessRaises(Exception,meshM1D.getNumberOfCells); - self.failUnlessRaises(Exception,meshM1D.setMeshDimension,-2) - self.failUnlessRaises(Exception,meshM1D.setMeshDimension,-10) + self.assertRaises(Exception,meshM1D.getMeshDimension); + self.assertRaises(Exception,meshM1D.getNumberOfNodes); + self.assertRaises(Exception,meshM1D.getNumberOfCells); + self.assertRaises(Exception,meshM1D.setMeshDimension,-2) + self.assertRaises(Exception,meshM1D.setMeshDimension,-10) meshM1D.setMeshDimension(-1); meshM1D.checkCoherency(); - self.failUnlessEqual(meshM1D.getMeshDimension(),-1); - self.failUnlessEqual(meshM1D.getNumberOfCells(),1); - self.failUnlessRaises(Exception,meshM1D.getNumberOfNodes); - self.failUnlessRaises(Exception,meshM1D.getSpaceDimension); + self.assertEqual(meshM1D.getMeshDimension(),-1); + self.assertEqual(meshM1D.getNumberOfCells(),1); + self.assertRaises(Exception,meshM1D.getNumberOfNodes); + self.assertRaises(Exception,meshM1D.getSpaceDimension); cpy=meshM1D.clone(True); - self.failUnless(cpy.isEqual(meshM1D,1e-12)); + self.assertTrue(cpy.isEqual(meshM1D,1e-12)); fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS); fieldOnCells.setMesh(meshM1D); array=DataArrayDouble.New(); @@ -181,15 +181,15 @@ class MEDCouplingBasicsTest(unittest.TestCase): def testDeepCopy(self): array=DataArrayDouble.New(); array.setValues(5*3*[7.],5,3); - self.failUnlessEqual(array.getIJ(3,2),7.); + self.assertEqual(array.getIJ(3,2),7.); array2=array.deepCopy(); - self.failUnlessEqual(array2.getIJ(3,2),7.) + self.assertEqual(array2.getIJ(3,2),7.) # array3=DataArrayInt.New(); array3.setValues(5*3*[17],5,3); - self.failUnlessEqual(array3.getIJ(3,2),17); + self.assertEqual(array3.getIJ(3,2),17); array4=array3.deepCopy(); - self.failUnlessEqual(array4.getIJ(3,2),17); + self.assertEqual(array4.getIJ(3,2),17); pass def testRevNodal(self): mesh=MEDCouplingDataForTest.build2DTargetMesh_1() @@ -198,30 +198,30 @@ class MEDCouplingBasicsTest(unittest.TestCase): mesh.getReverseNodalConnectivity(revNodal,revNodalIndx); revNodalExpected=[0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4]; revNodalIndexExpected=[0,1,3,5,7,12,14,15,17,18]; - self.failUnlessEqual(revNodal.getNbOfElems(),18) - self.failUnlessEqual(revNodalIndx.getNbOfElems(),10) - self.failUnlessEqual(revNodal.getValues(),revNodalExpected) - self.failUnlessEqual(revNodalIndx.getValues(),revNodalIndexExpected) + self.assertEqual(revNodal.getNbOfElems(),18) + self.assertEqual(revNodalIndx.getNbOfElems(),10) + self.assertEqual(revNodal.getValues(),revNodalExpected) + self.assertEqual(revNodalIndx.getValues(),revNodalIndexExpected) pass def testConvertToPolyTypes(self): mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); elts=[1,3]; mesh.convertToPolyTypes(elts); mesh.checkCoherency(); - self.failUnlessEqual(5,mesh.getNumberOfCells()); - self.failUnlessEqual(23,mesh.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(5,mesh.getNumberOfCells()); + self.assertEqual(23,mesh.getNodalConnectivity().getNumberOfTuples()); expected1=[4, 0, 3, 4, 1, 5, 1, 4, 2, 3, 4, 5, 2, 5, 6, 7, 4, 3, 4, 7, 8, 5, 4] - self.failUnlessEqual(expected1,mesh.getNodalConnectivity().getValues()); + self.assertEqual(expected1,mesh.getNodalConnectivity().getValues()); # mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); mesh.convertToPolyTypes(elts); mesh.checkCoherency(); - self.failUnlessEqual(8,mesh.getNumberOfCells()); - self.failUnlessEqual(114,mesh.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(8,mesh.getNumberOfCells()); + self.assertEqual(114,mesh.getNodalConnectivity().getNumberOfTuples()); mesh.convertToPolyTypes(elts); mesh.checkCoherency(); - self.failUnlessEqual(8,mesh.getNumberOfCells()); - self.failUnlessEqual(114,mesh.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(8,mesh.getNumberOfCells()); + self.assertEqual(114,mesh.getNodalConnectivity().getNumberOfTuples()); pass def testDescConn2D(self): mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); @@ -231,26 +231,26 @@ class MEDCouplingBasicsTest(unittest.TestCase): revDescIndx=DataArrayInt.New(); mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); mesh2.checkCoherency(); - self.failUnlessEqual(1,mesh2.getMeshDimension()); - self.failUnlessEqual(13,mesh2.getNumberOfCells()); - self.failUnlessEqual(14,revDescIndx.getNbOfElems()); self.failUnlessEqual(14,revDescIndx.getNumberOfTuples()); - self.failUnlessEqual(6,descIndx.getNbOfElems()); self.failUnlessEqual(6,descIndx.getNumberOfTuples()); - self.failUnlessEqual(18,desc.getNbOfElems()); self.failUnlessEqual(18,desc.getNumberOfTuples()); - self.failUnlessEqual(18,revDesc.getNbOfElems()); self.failUnlessEqual(18,revDesc.getNumberOfTuples()); + self.assertEqual(1,mesh2.getMeshDimension()); + self.assertEqual(13,mesh2.getNumberOfCells()); + self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples()); + self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples()); + self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples()); + self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples()); expected1=[0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9]; - self.failUnlessEqual(expected1,desc.getValues()); + self.assertEqual(expected1,desc.getValues()); expected2=[0,4,7,10,14,18]; - self.failUnlessEqual(expected2,descIndx.getValues()); + self.assertEqual(expected2,descIndx.getValues()); expected3=[0,1,3,5,6,8,9,11,12,13,15,16,17,18]; - self.failUnlessEqual(expected3,revDescIndx.getValues()); + self.assertEqual(expected3,revDescIndx.getValues()); expected4=[0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4]; - self.failUnlessEqual(expected4,revDesc.getValues()); + self.assertEqual(expected4,revDesc.getValues()); conn=mesh2.getNodalConnectivity(); connIndex=mesh2.getNodalConnectivityIndex(); expected5=[0,3,6,9,12,15,18,21,24,27,30,33,36,39]; - self.failUnlessEqual(expected5,connIndex.getValues()); + self.assertEqual(expected5,connIndex.getValues()); expected6=[1, 0, 3, 1, 3, 4, 1, 4, 1, 1, 1, 0, 1, 4, 2, 1, 2, 1, 1, 4, 5, 1, 5, 2, 1, 6, 7, 1, 7, 4, 1, 3, 6, 1, 7, 8, 1, 8, 5]; - self.failUnlessEqual(expected6,conn.getValues()); + self.assertEqual(expected6,conn.getValues()); # eltsV=[1,3]; mesh.convertToPolyTypes(eltsV); @@ -263,20 +263,20 @@ class MEDCouplingBasicsTest(unittest.TestCase): # mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); mesh2.checkCoherency(); - self.failUnlessEqual(1,mesh2.getMeshDimension()); - self.failUnlessEqual(13,mesh2.getNumberOfCells()); - self.failUnlessEqual(14,revDescIndx.getNbOfElems()); self.failUnlessEqual(14,revDescIndx.getNumberOfTuples()); - self.failUnlessEqual(6,descIndx.getNbOfElems()); self.failUnlessEqual(6,descIndx.getNumberOfTuples()); - self.failUnlessEqual(18,desc.getNbOfElems()); self.failUnlessEqual(18,desc.getNumberOfTuples()); - self.failUnlessEqual(18,revDesc.getNbOfElems()); self.failUnlessEqual(18,revDesc.getNumberOfTuples()); - self.failUnlessEqual(expected1,desc.getValues()); - self.failUnlessEqual(expected2,descIndx.getValues()); - self.failUnlessEqual(expected3,revDescIndx.getValues()); - self.failUnlessEqual(expected4,revDesc.getValues()); + self.assertEqual(1,mesh2.getMeshDimension()); + self.assertEqual(13,mesh2.getNumberOfCells()); + self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples()); + self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples()); + self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples()); + self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples()); + self.assertEqual(expected1,desc.getValues()); + self.assertEqual(expected2,descIndx.getValues()); + self.assertEqual(expected3,revDescIndx.getValues()); + self.assertEqual(expected4,revDesc.getValues()); conn=mesh2.getNodalConnectivity(); connIndex=mesh2.getNodalConnectivityIndex(); - self.failUnlessEqual(expected5,connIndex.getValues()); - self.failUnlessEqual(expected6,conn.getValues()); + self.assertEqual(expected5,connIndex.getValues()); + self.assertEqual(expected6,conn.getValues()); pass def testDescConn3D(self): mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); @@ -287,12 +287,12 @@ class MEDCouplingBasicsTest(unittest.TestCase): # mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); mesh2.checkCoherency(); - self.failUnlessEqual(2,mesh2.getMeshDimension()); - self.failUnlessEqual(36,mesh2.getNumberOfCells()); - self.failUnlessEqual(37,revDescIndx.getNbOfElems()); self.failUnlessEqual(37,revDescIndx.getNumberOfTuples()); - self.failUnlessEqual(9,descIndx.getNbOfElems()); self.failUnlessEqual(9,descIndx.getNumberOfTuples()); - self.failUnlessEqual(48,desc.getNbOfElems()); self.failUnlessEqual(48,desc.getNumberOfTuples()); - self.failUnlessEqual(48,revDesc.getNbOfElems()); self.failUnlessEqual(48,revDesc.getNumberOfTuples()); + self.assertEqual(2,mesh2.getMeshDimension()); + self.assertEqual(36,mesh2.getNumberOfCells()); + self.assertEqual(37,revDescIndx.getNbOfElems()); self.assertEqual(37,revDescIndx.getNumberOfTuples()); + self.assertEqual(9,descIndx.getNbOfElems()); self.assertEqual(9,descIndx.getNumberOfTuples()); + self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples()); + self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples()); expected1=[0, 6, 12, 18, 24, 30, 36, 42, 48] expected2=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 11, 12, 4, 13, 14, 15, 16, 17, 10, 18, 19, 13, 1, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 22, 12, 29, 23, 30, 31, 32, 17, 33, 28, 34, 35, 30] expected3=[0, 1, 3, 4, 6, 8, 9, 10, 12, 13, 14, 16, 17, 19, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 34, 35, 36, 37, 38, 40, 41, 43, 44, 45, 46, 47, 48] @@ -307,12 +307,12 @@ class MEDCouplingBasicsTest(unittest.TestCase): 17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4, 14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16] - self.failUnlessEqual(expected1,descIndx.getValues()); - self.failUnlessEqual(expected2,desc.getValues()); - self.failUnlessEqual(expected3,revDescIndx.getValues()); - self.failUnlessEqual(expected4,revDesc.getValues()); - self.failUnlessEqual(expected5,mesh2.getNodalConnectivityIndex().getValues()); - self.failUnlessEqual(expected6,mesh2.getNodalConnectivity().getValues()); + self.assertEqual(expected1,descIndx.getValues()); + self.assertEqual(expected2,desc.getValues()); + self.assertEqual(expected3,revDescIndx.getValues()); + self.assertEqual(expected4,revDesc.getValues()); + self.assertEqual(expected5,mesh2.getNodalConnectivityIndex().getValues()); + self.assertEqual(expected6,mesh2.getNodalConnectivity().getValues()); # eltsV=[1,3] mesh.convertToPolyTypes(eltsV); @@ -323,30 +323,30 @@ class MEDCouplingBasicsTest(unittest.TestCase): revDescIndx=DataArrayInt.New(); mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); mesh2.checkCoherency(); - self.failUnlessEqual(2,mesh2.getMeshDimension()); - self.failUnlessEqual(36,mesh2.getNumberOfCells()); - self.failUnlessEqual(37,revDescIndx.getNbOfElems()); self.failUnlessEqual(37,revDescIndx.getNumberOfTuples()); - self.failUnlessEqual(9,descIndx.getNbOfElems()); self.failUnlessEqual(9,descIndx.getNumberOfTuples()); - self.failUnlessEqual(48,desc.getNbOfElems()); self.failUnlessEqual(48,desc.getNumberOfTuples()); - self.failUnlessEqual(48,revDesc.getNbOfElems()); self.failUnlessEqual(48,revDesc.getNumberOfTuples()); - self.failUnlessEqual(expected1,descIndx.getValues()); - self.failUnlessEqual(expected2,desc.getValues()); - self.failUnlessEqual(expected3,revDescIndx.getValues()); - self.failUnlessEqual(expected4,revDesc.getValues()); - self.failUnlessEqual(expected5,mesh2.getNodalConnectivityIndex().getValues()); - self.failUnlessEqual(expected7,mesh2.getNodalConnectivity().getValues()); + self.assertEqual(2,mesh2.getMeshDimension()); + self.assertEqual(36,mesh2.getNumberOfCells()); + self.assertEqual(37,revDescIndx.getNbOfElems()); self.assertEqual(37,revDescIndx.getNumberOfTuples()); + self.assertEqual(9,descIndx.getNbOfElems()); self.assertEqual(9,descIndx.getNumberOfTuples()); + self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples()); + self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples()); + self.assertEqual(expected1,descIndx.getValues()); + self.assertEqual(expected2,desc.getValues()); + self.assertEqual(expected3,revDescIndx.getValues()); + self.assertEqual(expected4,revDesc.getValues()); + self.assertEqual(expected5,mesh2.getNodalConnectivityIndex().getValues()); + self.assertEqual(expected7,mesh2.getNodalConnectivity().getValues()); pass def testFindBoundaryNodes(self): mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); boundaryNodes=mesh.findBoundaryNodes(); expected1=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]; - self.failUnlessEqual(expected1,boundaryNodes); + self.assertEqual(expected1,boundaryNodes); pass def testBoundaryMesh(self): mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); mesh2=mesh.buildBoundaryMesh(False); - self.failUnlessEqual(24,mesh2.getNumberOfCells()); - self.failUnlessEqual(26,mesh2.getNumberOfNodes()); + self.assertEqual(24,mesh2.getNumberOfCells()); + self.assertEqual(26,mesh2.getNumberOfNodes()); pass def testBuildPartOfMySelf(self): mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); @@ -355,189 +355,189 @@ class MEDCouplingBasicsTest(unittest.TestCase): tab2=[0,2,3] # subMesh=mesh.buildPartOfMySelf(tab1,True); - self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) name=subMesh.getName(); - self.failUnlessEqual(2,len(mesh.getAllTypes())); - self.failUnlessEqual(NORM_TRI3,mesh.getAllTypes()[0]); - self.failUnlessEqual(NORM_QUAD4,mesh.getAllTypes()[1]); - self.failUnlessEqual(1,len(subMesh.getAllTypes())); - self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); - self.failUnlessEqual(name,"PartOf_Toto"); - self.failUnlessEqual(2,subMesh.getNumberOfCells()); + self.assertEqual(2,len(mesh.getAllTypes())); + self.assertEqual(NORM_TRI3,mesh.getAllTypes()[0]); + self.assertEqual(NORM_QUAD4,mesh.getAllTypes()[1]); + self.assertEqual(1,len(subMesh.getAllTypes())); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.assertEqual(name,"PartOf_Toto"); + self.assertEqual(2,subMesh.getNumberOfCells()); subConn=[4,0,3,4,1,4,7,8,5,4]; subConnIndex=[0,5,10]; - self.failUnlessEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); - self.failUnlessEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); - self.failUnlessEqual(subConn[0:10],subMesh.getNodalConnectivity().getValues()); - self.failUnlessEqual(subConnIndex[0:3],subMesh.getNodalConnectivityIndex().getValues()); + self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertEqual(subConn[0:10],subMesh.getNodalConnectivity().getValues()); + self.assertEqual(subConnIndex[0:3],subMesh.getNodalConnectivityIndex().getValues()); # subMesh=mesh.buildPartOfMySelf(tab2[0:3],True); - self.failUnless(isinstance(subMesh,MEDCouplingUMesh)); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)); name=subMesh.getName(); - self.failUnlessEqual(2,len(subMesh.getAllTypes())); - self.failUnlessEqual(NORM_TRI3,subMesh.getAllTypes()[0]); - self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); - self.failUnlessEqual(name,"PartOf_Toto"); - self.failUnlessEqual(3,subMesh.getNumberOfCells()); + self.assertEqual(2,len(subMesh.getAllTypes())); + self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.assertEqual(name,"PartOf_Toto"); + self.assertEqual(3,subMesh.getNumberOfCells()); subConn2=[4,0,3,4,1,3,4,5,2,4,6,7,4,3] subConnIndex2=[0,5,9,14] - self.failUnlessEqual(14,subMesh.getNodalConnectivity().getNbOfElems()); - self.failUnlessEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems()); - self.failUnlessEqual(subConn2[0:14],subMesh.getNodalConnectivity().getValues()); - self.failUnlessEqual(subConnIndex2[0:4],subMesh.getNodalConnectivityIndex().getValues()); + self.assertEqual(14,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertEqual(subConn2[0:14],subMesh.getNodalConnectivity().getValues()); + self.assertEqual(subConnIndex2[0:4],subMesh.getNodalConnectivityIndex().getValues()); pass def testBuildPartOfMySelfNode(self): mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); tab1=[5,7] subMesh=mesh.buildPartOfMySelfNode(tab1[0:2],True); - self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) - self.failUnlessEqual(1,len(subMesh.getAllTypes())); - self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); - self.failUnlessEqual(1,subMesh.getNumberOfCells()); - self.failUnlessEqual(5,subMesh.getNodalConnectivity().getNbOfElems()); - self.failUnlessEqual(2,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + self.assertEqual(1,len(subMesh.getAllTypes())); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.assertEqual(1,subMesh.getNumberOfCells()); + self.assertEqual(5,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(2,subMesh.getNodalConnectivityIndex().getNbOfElems()); subConn=[4,7,8,5,4] subConnIndex=[0,5] - self.failUnlessEqual(subConn[0:5],subMesh.getNodalConnectivity().getValues()); - self.failUnlessEqual(subConnIndex[0:2],subMesh.getNodalConnectivityIndex().getValues()); + self.assertEqual(subConn[0:5],subMesh.getNodalConnectivity().getValues()); + self.assertEqual(subConnIndex[0:2],subMesh.getNodalConnectivityIndex().getValues()); # subMesh=mesh.buildPartOfMySelfNode(tab1[0:2],False); - self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) - self.failUnlessEqual(2,len(subMesh.getAllTypes())); - self.failUnlessEqual(NORM_TRI3,subMesh.getAllTypes()[0]); - self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); - self.failUnlessEqual(3,subMesh.getNumberOfCells()); - self.failUnlessEqual(14,subMesh.getNodalConnectivity().getNbOfElems()); - self.failUnlessEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + self.assertEqual(2,len(subMesh.getAllTypes())); + self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.assertEqual(3,subMesh.getNumberOfCells()); + self.assertEqual(14,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems()); subConn2=[3,4,5,2,4,6,7,4,3,4,7,8,5,4] subConnIndex2=[0,4,9,14] - self.failUnlessEqual(subConn2[0:14],subMesh.getNodalConnectivity().getValues()); - self.failUnlessEqual(subConnIndex2[0:4],subMesh.getNodalConnectivityIndex().getValues()); + self.assertEqual(subConn2[0:14],subMesh.getNodalConnectivity().getValues()); + self.assertEqual(subConnIndex2[0:4],subMesh.getNodalConnectivityIndex().getValues()); #testing the case where length of tab2 is greater than max number of node per cell. tab2=[0,3,2,1,4,5,6] subMesh=mesh.buildPartOfMySelfNode(tab2[0:7],True); - self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) - self.failUnlessEqual(2,len(subMesh.getAllTypes())); - self.failUnlessEqual(NORM_TRI3,subMesh.getAllTypes()[0]); - self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); - self.failUnlessEqual(3,subMesh.getNumberOfCells()); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + self.assertEqual(2,len(subMesh.getAllTypes())); + self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.assertEqual(3,subMesh.getNumberOfCells()); pass def testZipCoords(self): mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); - self.failUnlessEqual(2,len(mesh.getAllTypes())); - self.failUnlessEqual(2,mesh.getSpaceDimension()); - self.failUnlessEqual(9,mesh.getNumberOfNodes()); - self.failUnlessEqual(5,mesh.getNumberOfCells()); + self.assertEqual(2,len(mesh.getAllTypes())); + self.assertEqual(2,mesh.getSpaceDimension()); + self.assertEqual(9,mesh.getNumberOfNodes()); + self.assertEqual(5,mesh.getNumberOfCells()); oldConn=mesh.getNodalConnectivity().getValues()[0:mesh.getNodalConnectivity().getNbOfElems()]; oldConnIndex=mesh.getNodalConnectivityIndex().getValues()[0:mesh.getNumberOfCells()+1] oldCoords=mesh.getCoords(); mesh.zipCoords(); - self.failUnlessEqual(2,len(mesh.getAllTypes())); - self.failUnlessEqual(2,mesh.getSpaceDimension()); - self.failUnlessEqual(9,mesh.getNumberOfNodes()); - self.failUnlessEqual(5,mesh.getNumberOfCells()); - self.failUnlessEqual(mesh.getCoords().getValues()[0:2*9],oldCoords.getValues()); - self.failUnlessEqual(oldConn,mesh.getNodalConnectivity().getValues()); - self.failUnlessEqual(oldConnIndex,mesh.getNodalConnectivityIndex().getValues()); + self.assertEqual(2,len(mesh.getAllTypes())); + self.assertEqual(2,mesh.getSpaceDimension()); + self.assertEqual(9,mesh.getNumberOfNodes()); + self.assertEqual(5,mesh.getNumberOfCells()); + self.assertEqual(mesh.getCoords().getValues()[0:2*9],oldCoords.getValues()); + self.assertEqual(oldConn,mesh.getNodalConnectivity().getValues()); + self.assertEqual(oldConnIndex,mesh.getNodalConnectivityIndex().getValues()); # tab1=[0,4] subMesh=mesh.buildPartOfMySelf(tab1,True); - self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) traducer=subMesh.zipCoordsTraducer(); expectedTraducer=[0,1,-1,2,3,4,-1,5,6] - self.failUnlessEqual(expectedTraducer,traducer.getValues()); - self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); - self.failUnlessEqual(2,subMesh.getNumberOfCells()); + self.assertEqual(expectedTraducer,traducer.getValues()); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.assertEqual(2,subMesh.getNumberOfCells()); subConn=[4,0,2,3,1,4,5,6,4,3] subConnIndex=[0,5,10] - self.failUnlessEqual(7,subMesh.getNumberOfNodes()); - self.failUnlessEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); - self.failUnlessEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); - self.failUnlessEqual(subConn,subMesh.getNodalConnectivity().getValues()); - self.failUnlessEqual(subConnIndex,subMesh.getNodalConnectivityIndex().getValues()); + self.assertEqual(7,subMesh.getNumberOfNodes()); + self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertEqual(subConn,subMesh.getNodalConnectivity().getValues()); + self.assertEqual(subConnIndex,subMesh.getNodalConnectivityIndex().getValues()); # subMesh=mesh.buildPartOfMySelf(tab1,False); - self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) - self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); - self.failUnlessEqual(2,subMesh.getNumberOfCells()); - self.failUnlessEqual(7,subMesh.getNumberOfNodes()); - self.failUnlessEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); - self.failUnlessEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); - self.failUnlessEqual(subConn,subMesh.getNodalConnectivity().getValues()); - self.failUnlessEqual(subConnIndex,subMesh.getNodalConnectivityIndex().getValues()); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.assertEqual(2,subMesh.getNumberOfCells()); + self.assertEqual(7,subMesh.getNumberOfNodes()); + self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertEqual(subConn,subMesh.getNodalConnectivity().getValues()); + self.assertEqual(subConnIndex,subMesh.getNodalConnectivityIndex().getValues()); pass def testZipConnectivity(self): m1=MEDCouplingDataForTest.build2DTargetMesh_1(); m2=MEDCouplingDataForTest.build2DTargetMesh_1(); cells1=[2,3,4] m3=m2.buildPartOfMySelf(cells1,True); - self.failUnless(isinstance(m3,MEDCouplingUMesh)) + self.assertTrue(isinstance(m3,MEDCouplingUMesh)) m4=MEDCouplingDataForTest.build2DSourceMesh_1(); m5=MEDCouplingUMesh.mergeUMeshes(m1,m3); m6=MEDCouplingUMesh.mergeUMeshes(m5,m4); # - self.failUnlessEqual(10,m6.getNumberOfCells()); - self.failUnlessEqual(22,m6.getNumberOfNodes()); + self.assertEqual(10,m6.getNumberOfCells()); + self.assertEqual(22,m6.getNumberOfNodes()); (arr,areNodesMerged)=m6.mergeNodes(1e-13); - self.failUnless(areNodesMerged); - self.failUnlessEqual(10,m6.getNumberOfCells()); - self.failUnlessEqual(9,m6.getNumberOfNodes()); + self.assertTrue(areNodesMerged); + self.assertEqual(10,m6.getNumberOfCells()); + self.assertEqual(9,m6.getNumberOfNodes()); # arr=m6.zipConnectivityTraducer(0); - self.failUnlessEqual(7,m6.getNumberOfCells()); + self.assertEqual(7,m6.getNumberOfCells()); m7=m6.clone(True); arr=m6.zipConnectivityTraducer(0); - self.failUnless(m7.isEqual(m6,1e-12)); - self.failUnlessEqual(7,m6.getNumberOfCells()); + self.assertTrue(m7.isEqual(m6,1e-12)); + self.assertEqual(7,m6.getNumberOfCells()); pass def testEqualMesh(self): mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); mesh2=MEDCouplingDataForTest.build2DTargetMesh_1(); # - self.failUnless(mesh1.isEqual(mesh1,1e-12)); + self.assertTrue(mesh1.isEqual(mesh1,1e-12)); # - self.failUnless(mesh1.isEqual(mesh2,1e-12)); - self.failUnless(mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); pt=mesh2.getCoords().getValues(); tmp=pt[1] mesh2.getCoords().setIJ(0,1,5.999); - self.failUnless(not mesh1.isEqual(mesh2,1e-12)); - self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); mesh2.getCoords().setIJ(0,1,tmp); - self.failUnless(mesh1.isEqual(mesh2,1e-12)); - self.failUnless(mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); # pt2=mesh1.getNodalConnectivity().getValues(); mesh1.getNodalConnectivity().setIJ(5,0,pt2[5]+1); - self.failUnless(not mesh1.isEqual(mesh2,1e-12)); - self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); mesh1.getNodalConnectivity().setIJ(5,0,pt2[5]); - self.failUnless(mesh1.isEqual(mesh2,1e-12)); - self.failUnless(mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); # pt2=mesh1.getNodalConnectivityIndex().getValues(); mesh1.getNodalConnectivityIndex().setIJ(1,0,pt2[1]+1); - self.failUnless(not mesh1.isEqual(mesh2,1e-12)); - self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); mesh1.getNodalConnectivityIndex().setIJ(1,0,pt2[1]); - self.failUnless(mesh1.isEqual(mesh2,1e-12)); - self.failUnless(mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); # tmp3=mesh1.getName(); mesh1.setName("lllll"); - self.failUnless(not mesh1.isEqual(mesh2,1e-12)); - self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); mesh1.setName(tmp3); - self.failUnless(mesh1.isEqual(mesh2,1e-12)); - self.failUnless(mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); # tmp3=mesh2.getCoords().getInfoOnComponent(1); mesh2.getCoords().setInfoOnComponent(1,"kkkkkk"); - self.failUnless(not mesh1.isEqual(mesh2,1e-12)); - self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); mesh2.getCoords().setInfoOnComponent(1,tmp3); - self.failUnless(mesh1.isEqual(mesh2,1e-12)); - self.failUnless(mesh2.isEqual(mesh1,1e-12)); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); pass def testEqualFieldDouble(self): mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); @@ -548,72 +548,72 @@ class MEDCouplingBasicsTest(unittest.TestCase): fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); fieldOnCells2.setMesh(mesh2); # - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); # fieldOnNodes1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); - self.failUnless(not fieldOnCells1.isEqual(fieldOnNodes1,1e-12,1e-15)); - self.failUnless(not fieldOnNodes1.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnNodes1,1e-12,1e-15)); + self.assertTrue(not fieldOnNodes1.isEqual(fieldOnCells1,1e-12,1e-15)); # fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); - self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); fieldOnCells1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); fieldOnCells1.setTime(4.,6,7); - self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); fieldOnCells2.setTime(4.,6,7); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); fieldOnCells1.setName("Power"); - self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); fieldOnCells2.setName("Power"); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); # fieldOnCells1.setMesh(mesh1); - self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); fieldOnCells2.setMesh(mesh1); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); arr=DataArrayDouble.New(); arr.setName("popo"); arr.setValues(mesh1.getNumberOfCells()*3*[6.],mesh1.getNumberOfCells(),3); fieldOnCells1.setArray(arr); - self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); fieldOnCells2.setArray(arr); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); # arr2=arr.deepCopy(); fieldOnCells2.setArray(arr2); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); arr.setIJ(1,2,6.1); - self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); arr.setIJ(1,2,6.); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); arr2.setName("popo2"); - self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); # arr2.setName("popo"); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); # arr2.setInfoOnComponent(2,"jjj"); - self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); arr.setInfoOnComponent(2,"jjj"); - self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); - self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); pass def testNatureChecking(self): @@ -623,8 +623,8 @@ class MEDCouplingBasicsTest(unittest.TestCase): field.setNature(IntegralGlobConstraint); field=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); field.setNature(ConservativeVolumic); - self.failUnlessRaises(Exception,field.setNature,Integral); - self.failUnlessRaises(Exception,field.setNature,IntegralGlobConstraint); + self.assertRaises(Exception,field.setNature,Integral); + self.assertRaises(Exception,field.setNature,IntegralGlobConstraint); pass def testBuildSubMeshData(self): @@ -634,51 +634,51 @@ class MEDCouplingBasicsTest(unittest.TestCase): fieldCells.setMesh(targetMesh); elts=[1,2,4] ret1,di=fieldCells.buildSubMeshData(elts); - self.failUnless(isinstance(ret1,MEDCouplingUMesh)) - self.failUnlessEqual(3,ret1.getNumberOfCells()); - self.failUnlessEqual(6,ret1.getNumberOfNodes()); - self.failUnlessEqual(3,di.getNumberOfTuples()); - self.failUnlessEqual(1,di.getNumberOfComponents()); + self.assertTrue(isinstance(ret1,MEDCouplingUMesh)) + self.assertEqual(3,ret1.getNumberOfCells()); + self.assertEqual(6,ret1.getNumberOfNodes()); + self.assertEqual(3,di.getNumberOfTuples()); + self.assertEqual(1,di.getNumberOfComponents()); toCheck=di.getValues(); - self.failUnless(elts,toCheck); + self.assertTrue(elts,toCheck); #check buildSubMesh on field on nodes fieldNodes=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); fieldNodes.setMesh(targetMesh); ret2,di=fieldNodes.buildSubMeshData(elts); - self.failUnless(isinstance(ret2,MEDCouplingUMesh)) - self.failUnlessEqual(3,ret2.getNumberOfCells()); - self.failUnlessEqual(6,ret2.getNumberOfNodes()); - self.failUnlessEqual(6,di.getNumberOfTuples()); - self.failUnlessEqual(1,di.getNumberOfComponents()); + self.assertTrue(isinstance(ret2,MEDCouplingUMesh)) + self.assertEqual(3,ret2.getNumberOfCells()); + self.assertEqual(6,ret2.getNumberOfNodes()); + self.assertEqual(6,di.getNumberOfTuples()); + self.assertEqual(1,di.getNumberOfComponents()); toCheck=di.getValues(); expected=[1,2,4,5,7,8] - self.failUnlessEqual(expected,toCheck); + self.assertEqual(expected,toCheck); pass def testExtrudedMesh1(self): mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1(); ext=MEDCouplingExtrudedMesh.New(mesh3D,mesh2D,1); - self.failUnlessEqual(18,ext.getNumberOfCells()); - self.failUnlessEqual(60,ext.getNumberOfNodes()); + self.assertEqual(18,ext.getNumberOfCells()); + self.assertEqual(60,ext.getNumberOfNodes()); ids3D=ext.getMesh3DIds(); ids3DExpected=[5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12] - self.failUnlessEqual(18,ids3D.getNumberOfTuples()); - self.failUnlessEqual(1,ids3D.getNumberOfComponents()); - self.failUnlessEqual(ids3DExpected,ids3D.getValues()); + self.assertEqual(18,ids3D.getNumberOfTuples()); + self.assertEqual(1,ids3D.getNumberOfComponents()); + self.assertEqual(ids3DExpected,ids3D.getValues()); mesh1D=ext.getMesh1D(); - self.failUnlessEqual(4,mesh1D.getNumberOfNodes()); - self.failUnlessEqual(3,mesh1D.getNumberOfCells()); + self.assertEqual(4,mesh1D.getNumberOfNodes()); + self.assertEqual(3,mesh1D.getNumberOfCells()); mesh1DExpected=[0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3] mesh1DCoords=mesh1D.getCoords(); - self.failUnlessEqual(4,mesh1DCoords.getNumberOfTuples()); - self.failUnlessEqual(3,mesh1DCoords.getNumberOfComponents()); - self.failUnlessEqual(mesh1DExpected,mesh1DCoords.getValues()); + self.assertEqual(4,mesh1DCoords.getNumberOfTuples()); + self.assertEqual(3,mesh1DCoords.getNumberOfComponents()); + self.assertEqual(mesh1DExpected,mesh1DCoords.getValues()); conn1D=mesh1D.getNodalConnectivity(); - self.failUnlessEqual(9,conn1D.getNumberOfTuples()); - self.failUnlessEqual(1,conn1D.getNumberOfComponents()); + self.assertEqual(9,conn1D.getNumberOfTuples()); + self.assertEqual(1,conn1D.getNumberOfComponents()); conn1DExpected=[1,0,1,1,1,2,1,2,3] - self.failUnlessEqual(conn1DExpected,conn1D.getValues()); + self.assertEqual(conn1DExpected,conn1D.getValues()); pass def testExtrudedMesh3(self): @@ -692,85 +692,85 @@ class MEDCouplingBasicsTest(unittest.TestCase): m3=m1.buildExtrudedMeshFromThis(m2,0); # m4=MEDCouplingExtrudedMesh.New(m3,m1,0); - self.failUnlessEqual(15,m4.getNumberOfCells()); - self.failUnlessEqual(5,m4.getMesh2D().getNumberOfCells()); - self.failUnlessEqual(3,m4.getMesh1D().getNumberOfCells()); + self.assertEqual(15,m4.getNumberOfCells()); + self.assertEqual(5,m4.getMesh2D().getNumberOfCells()); + self.assertEqual(3,m4.getMesh1D().getNumberOfCells()); m3DIds=m4.getMesh3DIds().getValues(); - self.failUnlessEqual(range(15),m3DIds); + self.assertEqual(range(15),m3DIds); #some random in cells to check that extrusion alg find it correctly expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4] m3.renumberCells(expected1,False); m4=MEDCouplingExtrudedMesh.New(m3,m1,0); - self.failUnlessEqual(15,m4.getNumberOfCells()); - self.failUnlessEqual(5,m4.getMesh2D().getNumberOfCells()); - self.failUnlessEqual(3,m4.getMesh1D().getNumberOfCells()); + self.assertEqual(15,m4.getNumberOfCells()); + self.assertEqual(5,m4.getMesh2D().getNumberOfCells()); + self.assertEqual(3,m4.getMesh1D().getNumberOfCells()); m3DIds=m4.getMesh3DIds().getValues(); - self.failUnlessEqual(expected1,m3DIds); + self.assertEqual(expected1,m3DIds); #play with polygons and polyedrons cells=[2,3] m1.convertToPolyTypes(cells); m3=m1.buildExtrudedMeshFromThis(m2,0); - self.failUnlessEqual(NORM_HEXA8,m3.getTypeOfCell(0)); - self.failUnlessEqual(NORM_PENTA6,m3.getTypeOfCell(1)); - self.failUnlessEqual(NORM_POLYHED,m3.getTypeOfCell(2)); - self.failUnlessEqual(NORM_POLYHED,m3.getTypeOfCell(3)); - self.failUnlessEqual(NORM_HEXA8,m3.getTypeOfCell(4)); + self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(0)); + self.assertEqual(NORM_PENTA6,m3.getTypeOfCell(1)); + self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(2)); + self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(3)); + self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(4)); m3.renumberCells(expected1,False); m4=MEDCouplingExtrudedMesh.New(m3,m1,0); - self.failUnlessEqual(15,m4.getNumberOfCells()); - self.failUnlessEqual(5,m4.getMesh2D().getNumberOfCells()); - self.failUnlessEqual(3,m4.getMesh1D().getNumberOfCells()); + self.assertEqual(15,m4.getNumberOfCells()); + self.assertEqual(5,m4.getMesh2D().getNumberOfCells()); + self.assertEqual(3,m4.getMesh1D().getNumberOfCells()); m3DIds=m4.getMesh3DIds().getValues(); - self.failUnlessEqual(expected1,m3DIds); + self.assertEqual(expected1,m3DIds); pass def testFindCommonNodes(self): targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1(); comm,commI=targetMesh.findCommonNodes(1e-10); - self.failUnlessEqual(1,commI.getNumberOfTuples()); - self.failUnlessEqual(0,comm.getNumberOfTuples()); + self.assertEqual(1,commI.getNumberOfTuples()); + self.assertEqual(0,comm.getNumberOfTuples()); o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommNodesFrmt(comm,commI); - self.failUnlessEqual(27,newNbOfNodes); - self.failUnlessEqual(27,o2n.getNumberOfTuples()); + self.assertEqual(27,newNbOfNodes); + self.assertEqual(27,o2n.getNumberOfTuples()); o2nExp1=range(27) - self.failUnlessEqual(o2nExp1,o2n.getValues()); + self.assertEqual(o2nExp1,o2n.getValues()); # targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); - self.failUnlessEqual(31,targetMesh.getNumberOfNodes()); + self.assertEqual(31,targetMesh.getNumberOfNodes()); comm,commI=targetMesh.findCommonNodes(1e-10); - self.failUnlessEqual(3,commI.getNumberOfTuples()); - self.failUnlessEqual(6,comm.getNumberOfTuples()); + self.assertEqual(3,commI.getNumberOfTuples()); + self.assertEqual(6,comm.getNumberOfTuples()); commExpected=[1,27,28,29,23,30] commIExpected=[0,4,6] - self.failUnlessEqual(commExpected,comm.getValues()); - self.failUnlessEqual(commIExpected,commI.getValues()); + self.assertEqual(commExpected,comm.getValues()); + self.assertEqual(commIExpected,commI.getValues()); o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommNodesFrmt(comm,commI); - self.failUnlessEqual(31,o2n.getNumberOfTuples()); - self.failUnlessEqual(27,newNbOfNodes); + self.assertEqual(31,o2n.getNumberOfTuples()); + self.assertEqual(27,newNbOfNodes); o2nExp2=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,1,1,1,23] - self.failUnlessEqual(o2nExp2,o2n.getValues()); + self.assertEqual(o2nExp2,o2n.getValues()); # targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1(); time=targetMesh.getTimeOfThis(); o2n,areNodesMerged=targetMesh.mergeNodes(1e-10); targetMesh.updateTime(); - self.failUnlessEqual(time,targetMesh.getTimeOfThis()); - self.failUnless(not areNodesMerged); + self.assertEqual(time,targetMesh.getTimeOfThis()); + self.assertTrue(not areNodesMerged); # targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); time=targetMesh.getTimeOfThis(); o2n,areNodesMerged=targetMesh.mergeNodes(1e-10); targetMesh.updateTime(); - self.failUnless(time!=targetMesh.getTimeOfThis()); - self.failUnless(areNodesMerged); + self.assertTrue(time!=targetMesh.getTimeOfThis()); + self.assertTrue(areNodesMerged); connExp=[18,0,1,4,3,9,10,13,12, 18,1,2,5,4,10,11,14,13, 18,3,4,7,6,12,13,16,15, 18,4,5,8,7,13,14,17,16, 18,9,10,13,12,18,19,22,21, 18,10,11,14,13,19,20,23,22, 18,12,13,16,15,21,22,25,24, 18,13,14,17,16,22,23,26,25] - self.failUnlessEqual(72,targetMesh.getNodalConnectivity().getNumberOfTuples()); - self.failUnlessEqual(connExp,targetMesh.getNodalConnectivity().getValues()); - self.failUnlessEqual(27,targetMesh.getCoords().getNumberOfTuples()); + self.assertEqual(72,targetMesh.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(connExp,targetMesh.getNodalConnectivity().getValues()); + self.assertEqual(27,targetMesh.getCoords().getNumberOfTuples()); coordsExp=[ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. , 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. , 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50., @@ -778,55 +778,55 @@ class MEDCouplingBasicsTest(unittest.TestCase): 200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200. , 0., 50., 200., 50., 50., 200. , 200., 50., 200., 0., 200., 200., 50., 200., 200. , 200., 200., 200. ] - self.failUnlessEqual(coordsExp,targetMesh.getCoords().getValues()); + self.assertEqual(coordsExp,targetMesh.getCoords().getValues()); # 2D targetMesh=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1(); - self.failUnlessEqual(18,targetMesh.getNumberOfNodes()); + self.assertEqual(18,targetMesh.getNumberOfNodes()); time=targetMesh.getTimeOfThis(); o2n,areNodesMerged=targetMesh.mergeNodes(1e-10); - self.failUnless(time!=targetMesh.getTimeOfThis()); - self.failUnless(areNodesMerged); - self.failUnlessEqual(9,targetMesh.getNumberOfNodes()); + self.assertTrue(time!=targetMesh.getTimeOfThis()); + self.assertTrue(areNodesMerged); + self.assertEqual(9,targetMesh.getNumberOfNodes()); connExp2=[4,0,4,3,1, 3,1,3,2, 3,3,5,2, 4,4,6,7,3, 4,7,8,5,3] - self.failUnlessEqual(23,targetMesh.getNodalConnectivity().getNumberOfTuples()); - self.failUnlessEqual(connExp2,targetMesh.getNodalConnectivity().getValues()); + self.assertEqual(23,targetMesh.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(connExp2,targetMesh.getNodalConnectivity().getValues()); coordsExp2=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, 0.2,0.2, -0.3,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7] - self.failUnlessEqual(9,targetMesh.getCoords().getNumberOfTuples()); - self.failUnlessEqual(coordsExp2,targetMesh.getCoords().getValues()); + self.assertEqual(9,targetMesh.getCoords().getNumberOfTuples()); + self.assertEqual(coordsExp2,targetMesh.getCoords().getValues()); pass def testCheckButterflyCells(self): sourceMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); cells=sourceMesh.checkButterflyCells(); - self.failUnlessEqual(0,len(cells)); + self.assertEqual(0,len(cells)); conn=sourceMesh.getNodalConnectivity() tmp=conn.getIJ(15,0) conn.setIJ(15,0,conn.getIJ(16,0)) conn.setIJ(16,0,tmp) cells=sourceMesh.checkButterflyCells(); - self.failUnlessEqual(1,len(cells)); - self.failUnlessEqual(3,cells[0]); + self.assertEqual(1,len(cells)); + self.assertEqual(3,cells[0]); tmp=conn.getIJ(15,0) conn.setIJ(15,0,conn.getIJ(16,0)) conn.setIJ(16,0,tmp) cells=sourceMesh.checkButterflyCells(); - self.failUnlessEqual(0,len(cells)); + self.assertEqual(0,len(cells)); # 3D surf sourceMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); cells=sourceMesh.checkButterflyCells(); - self.failUnlessEqual(0,len(cells)); + self.assertEqual(0,len(cells)); conn=sourceMesh.getNodalConnectivity() tmp=conn.getIJ(15,0) conn.setIJ(15,0,conn.getIJ(16,0)) conn.setIJ(16,0,tmp) cells=sourceMesh.checkButterflyCells(); - self.failUnlessEqual(1,len(cells)); - self.failUnlessEqual(3,cells[0]); + self.assertEqual(1,len(cells)); + self.assertEqual(3,cells[0]); tmp=conn.getIJ(15,0) conn.setIJ(15,0,conn.getIJ(16,0)) conn.setIJ(16,0,tmp) cells=sourceMesh.checkButterflyCells(); - self.failUnlessEqual(0,len(cells)); + self.assertEqual(0,len(cells)); pass def testMergeMesh1(self): @@ -835,13 +835,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): vec=[1.,0.] m2.translate(vec); m3=m1.mergeMyselfWith(m2); - self.failUnless(isinstance(m3,MEDCouplingUMesh)); + self.assertTrue(isinstance(m3,MEDCouplingUMesh)); m3.checkCoherency(); m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1(); - self.failUnless(m3.isEqual(m4,1.e-12)); + self.assertTrue(m3.isEqual(m4,1.e-12)); da,isMerged=m3.mergeNodes(1.e-12); - self.failUnlessEqual(11,m3.getNumberOfNodes()); - self.failUnless(isMerged); + self.assertEqual(11,m3.getNumberOfNodes()); + self.assertTrue(isMerged); pass def testMergeMeshOnSameCoords1(self): @@ -855,19 +855,19 @@ class MEDCouplingBasicsTest(unittest.TestCase): meshes=[m1,m2,m3] m4=MEDCouplingUMesh.mergeUMeshesOnSameCoords(meshes); m4.checkCoherency(); - self.failUnlessEqual(15,m4.getNumberOfCells()); + self.assertEqual(15,m4.getNumberOfCells()); cells1=[0,1,2,3,4] m1_1=m4.buildPartOfMySelf(cells1,True); m1_1.setName(m1.getName()); - self.failUnless(m1.isEqual(m1_1,1e-12)); + self.assertTrue(m1.isEqual(m1_1,1e-12)); cells2=[5,6,7,8,9] m2_1=m4.buildPartOfMySelf(cells2,True); m2_1.setName(m2.getName()); - self.failUnless(m2.isEqual(m2_1,1e-12)); + self.assertTrue(m2.isEqual(m2_1,1e-12)); cells3=[10,11,12,13,14] m3_1=m4.buildPartOfMySelf(cells3,True); m3_1.setName(m3.getName()); - self.failUnless(m3.isEqual(m3_1,1e-12)); + self.assertTrue(m3.isEqual(m3_1,1e-12)); pass def testMergeField1(self): @@ -880,18 +880,18 @@ class MEDCouplingBasicsTest(unittest.TestCase): f3=MEDCouplingFieldDouble.mergeFields(f1,f2); f3.checkCoherency(); m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1(); - self.failUnless(f3.getMesh().isEqual(m4,1.e-12)); + self.assertTrue(f3.getMesh().isEqual(m4,1.e-12)); name=f3.getName(); - self.failUnlessEqual(name,"MeasureOfMesh_"); - self.failUnlessEqual(f3.getTypeOfField(),ON_CELLS); - self.failUnlessEqual(f3.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(1,f3.getNumberOfComponents()); - self.failUnlessEqual(7,f3.getNumberOfTuples()); + self.assertEqual(name,"MeasureOfMesh_"); + self.assertEqual(f3.getTypeOfField(),ON_CELLS); + self.assertEqual(f3.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f3.getNumberOfComponents()); + self.assertEqual(7,f3.getNumberOfTuples()); values=[0.25,0.125,0.125,0.25,0.25,0.5,0.5] tmp=f3.getArray().getValues(); - self.failUnlessEqual(len(values),len(tmp)) + self.assertEqual(len(values),len(tmp)) for i in xrange(7): - self.failUnless(abs(values[i]-tmp[i])<1e-12) + self.assertTrue(abs(values[i]-tmp[i])<1e-12) pass pass @@ -899,130 +899,130 @@ class MEDCouplingBasicsTest(unittest.TestCase): m=MEDCouplingDataForTest.build2DTargetMesh_1(); f1=m.fillFromAnalytic(ON_CELLS,1,"x+y"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_CELLS); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(1,f1.getNumberOfComponents()); - self.failUnlessEqual(5,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_CELLS); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(5,f1.getNumberOfTuples()); values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9] tmp=f1.getArray().getValues(); - self.failUnlessEqual(len(values1),len(tmp)) + self.assertEqual(len(values1),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values1[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values1[i])<1.e-12) pass # f1=m.fillFromAnalytic(ON_NODES,1,"x+y"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(1,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); values2=[-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4] tmp=f1.getArray().getValues(); - self.failUnlessEqual(len(values2),len(tmp)) + self.assertEqual(len(values2),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values2[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values2[i])<1.e-12) pass # f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+(2*(x+y))*JVec"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(2,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8] tmp=f1.getArray().getValues(); - self.failUnlessEqual(len(values3),len(tmp)) + self.assertEqual(len(values3),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values3[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values3[i])<1.e-12) pass values4=f1.accumulate(); - self.failUnless(abs(3.6-values4[0])<1.e-12); - self.failUnless(abs(7.2-values4[1])<1.e-12); + self.assertTrue(abs(3.6-values4[0])<1.e-12); + self.assertTrue(abs(7.2-values4[1])<1.e-12); values4=f1.measureAccumulate(True); - self.failUnless(abs(0.5-values4[0])<1.e-12); - self.failUnless(abs(1.-values4[1])<1.e-12); + self.assertTrue(abs(0.5-values4[0])<1.e-12); + self.assertTrue(abs(1.-values4[1])<1.e-12); # - self.failUnlessRaises(Exception,m.fillFromAnalytic,ON_NODES,1,"1./(x-0.2)"); + self.assertRaises(Exception,m.fillFromAnalytic,ON_NODES,1,"1./(x-0.2)"); pass def testFillFromAnalytic2(self): m=MEDCouplingDataForTest.build2DTargetMesh_1(); f1=m.fillFromAnalytic(ON_CELLS,1,"y+x"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_CELLS); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(1,f1.getNumberOfComponents()); - self.failUnlessEqual(5,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_CELLS); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(5,f1.getNumberOfTuples()); values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9] tmp=f1.getArray().getValues(); - self.failUnlessEqual(len(values1),len(tmp)) + self.assertEqual(len(values1),len(tmp)) for i in xrange(len(values1)): - self.failUnless(abs(values1[i]-tmp[i])<1.e-12); + self.assertTrue(abs(values1[i]-tmp[i])<1.e-12); pass # f1=m.fillFromAnalytic(ON_NODES,1,"y+2*x"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(1,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1] tmp=f1.getArray().getValues(); - self.failUnlessEqual(len(values2),len(tmp)) + self.assertEqual(len(values2),len(tmp)) for i in xrange(len(values2)): - self.failUnless(abs(values2[i]-tmp[i])<1.e-12); + self.assertTrue(abs(values2[i]-tmp[i])<1.e-12); pass f1=m.fillFromAnalytic(ON_NODES,1,"2.*x+y"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(1,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); tmp=f1.getArray().getValues(); values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1] - self.failUnlessEqual(len(values2Bis),len(tmp)) + self.assertEqual(len(values2Bis),len(tmp)) for i in xrange(len(values2Bis)): - self.failUnless(abs(values2Bis[i]-tmp[i])<1.e-12); + self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12); pass # f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(2,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8] tmp=f1.getArray().getValues(); - self.failUnlessEqual(len(values3),len(tmp)) + self.assertEqual(len(values3),len(tmp)) for i in xrange(len(values3)): - self.failUnless(abs(values3[i]-tmp[i])<1.e-12); + self.assertTrue(abs(values3[i]-tmp[i])<1.e-12); pass values4=f1.accumulate(); - self.failUnless(abs(3.6-values4[0])<1.e-12); - self.failUnless(abs(7.2-values4[1])<1.e-12); + self.assertTrue(abs(3.6-values4[0])<1.e-12); + self.assertTrue(abs(7.2-values4[1])<1.e-12); values4=f1.measureAccumulate(True); - self.failUnless(abs(0.5-values4[0])<1.e-12); - self.failUnless(abs(1.-values4[1])<1.e-12); + self.assertTrue(abs(0.5-values4[0])<1.e-12); + self.assertTrue(abs(1.-values4[1])<1.e-12); pass def testApplyFunc(self): m=MEDCouplingDataForTest.build2DTargetMesh_1(); f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+(2*(x+y))*JVec"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(2,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); f1.applyFunc(1,"x+y"); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(1,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2] tmp=f1.getArray().getValues(); - self.failUnlessEqual(len(values1),len(tmp)) + self.assertEqual(len(values1),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values1[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values1[i])<1.e-12) pass pass @@ -1030,38 +1030,38 @@ class MEDCouplingBasicsTest(unittest.TestCase): m=MEDCouplingDataForTest.build2DTargetMesh_1(); f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec"); f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(2,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); # f2=f1.clone(True); f2.applyFunc("abs(u)^2.4+2*u"); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(2,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); values2=[-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987, 0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987, 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295, 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295, 5.0423700574830965, 17.435300118916864] tmp=f2.getArray().getValues(); - self.failUnlessEqual(len(tmp),len(values2)) + self.assertEqual(len(tmp),len(values2)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values2[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values2[i])<1.e-12) pass # f1.applyFunc(1,"x+y"); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); - self.failUnlessEqual(1,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2] tmp=f1.getArray().getValues(); - self.failUnlessEqual(len(tmp),len(values1)) + self.assertEqual(len(tmp),len(values1)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values1[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values1[i])<1.e-12) pass pass @@ -1073,78 +1073,78 @@ class MEDCouplingBasicsTest(unittest.TestCase): f2.checkCoherency(); f3=f1+f2; f3.checkCoherency(); - self.failUnlessEqual(f3.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f3.getTimeDiscretization(),NO_TIME); + self.assertEqual(f3.getTypeOfField(),ON_NODES); + self.assertEqual(f3.getTimeDiscretization(),NO_TIME); values1=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8] tmp=f3.getArray().getValues(); - self.failUnlessEqual(len(values1),len(tmp)) + self.assertEqual(len(values1),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values1[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values1[i])<1.e-12) pass # f3=f1*f2; f3.checkCoherency(); - self.failUnlessEqual(f3.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f3.getTimeDiscretization(),NO_TIME); + self.assertEqual(f3.getTypeOfField(),ON_NODES); + self.assertEqual(f3.getTimeDiscretization(),NO_TIME); values2=[0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96] tmp=f3.getArray().getValues(); - self.failUnlessEqual(len(values2),len(tmp)) + self.assertEqual(len(values2),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values2[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values2[i])<1.e-12) pass # f3=f1+f2; f4=f1-f3; f4.checkCoherency(); - self.failUnlessEqual(f4.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f4.getTimeDiscretization(),NO_TIME); + self.assertEqual(f4.getTypeOfField(),ON_NODES); + self.assertEqual(f4.getTimeDiscretization(),NO_TIME); values3=[0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4] tmp=f4.getArray().getValues(); - self.failUnlessEqual(len(values3),len(tmp)) + self.assertEqual(len(values3),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values3[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values3[i])<1.e-12) pass # f3=f1+f2; f4=f3/f2; f4.checkCoherency(); - self.failUnlessEqual(f4.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f4.getTimeDiscretization(),NO_TIME); + self.assertEqual(f4.getTypeOfField(),ON_NODES); + self.assertEqual(f4.getTimeDiscretization(),NO_TIME); tmp=f4.getArray().getValues(); for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-2.)<1.e-12) + self.assertTrue(abs(tmp[i]-2.)<1.e-12) pass # f4=f2.buildNewTimeReprFromThis(ONE_TIME,False); f4.checkCoherency(); - self.failUnlessEqual(f4.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f4.getTimeDiscretization(),ONE_TIME); - self.failUnlessRaises(Exception,f1.__add__,f4); + self.assertEqual(f4.getTypeOfField(),ON_NODES); + self.assertEqual(f4.getTimeDiscretization(),ONE_TIME); + self.assertRaises(Exception,f1.__add__,f4); f5=f4.buildNewTimeReprFromThis(NO_TIME,False); - self.failUnlessEqual(f5.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f5.getTimeDiscretization(),NO_TIME); + self.assertEqual(f5.getTypeOfField(),ON_NODES); + self.assertEqual(f5.getTimeDiscretization(),NO_TIME); f3=f1+f5; tmp=f3.getArray().getValues(); values4=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8] - self.failUnlessEqual(len(values3),len(tmp)) + self.assertEqual(len(values3),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values4[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values4[i])<1.e-12) pass # f4=f2.buildNewTimeReprFromThis(ONE_TIME,True); f4.checkCoherency(); - self.failUnlessEqual(f4.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f4.getTimeDiscretization(),ONE_TIME); - self.failUnlessRaises(Exception,f1.__add__,f4); + self.assertEqual(f4.getTypeOfField(),ON_NODES); + self.assertEqual(f4.getTimeDiscretization(),ONE_TIME); + self.assertRaises(Exception,f1.__add__,f4); f5=f4.buildNewTimeReprFromThis(NO_TIME,True); - self.failUnlessEqual(f5.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f5.getTimeDiscretization(),NO_TIME); + self.assertEqual(f5.getTypeOfField(),ON_NODES); + self.assertEqual(f5.getTimeDiscretization(),NO_TIME); f3=f1+f5; tmp=f3.getArray().getValues(); values5=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8] - self.failUnlessEqual(len(values5),len(tmp)) + self.assertEqual(len(values5),len(tmp)) for i in xrange(len(tmp)): - self.failUnless(abs(tmp[i]-values5[i])<1.e-12) + self.assertTrue(abs(tmp[i]-values5[i])<1.e-12) pass pass @@ -1154,16 +1154,16 @@ class MEDCouplingBasicsTest(unittest.TestCase): f2=m.fillFromAnalytic(ON_NODES,1,"a*a+b+c*c"); f3=f1/f2; f3.checkCoherency(); - self.failUnlessEqual(f3.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f3.getTimeDiscretization(),NO_TIME); + self.assertEqual(f3.getTypeOfField(),ON_NODES); + self.assertEqual(f3.getTimeDiscretization(),NO_TIME); expected1=[-2.4999999999999991, 1.2162162162162162, 0.77868852459016391, 0.7407407407407407, 1.129032258064516, 0.81632653061224492, 0.86538461538461531, 1.0919540229885056, 0.84302325581395343] - self.failUnlessEqual(1,f3.getNumberOfComponents()); - self.failUnlessEqual(9,f3.getNumberOfTuples()); + self.assertEqual(1,f3.getNumberOfComponents()); + self.assertEqual(9,f3.getNumberOfTuples()); val=f3.getArray().getValues(); for i in xrange(9): - self.failUnless(abs(expected1[i]-val[i])<1.e-12); + self.assertTrue(abs(expected1[i]-val[i])<1.e-12); # f1=m.buildOrthogonalField(); f2=m.fillFromAnalytic(ON_CELLS,1,"x"); @@ -1171,13 +1171,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): expected2=[-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637] val=f3.getArray().getValues(); for i in xrange(15): - self.failUnless(abs(expected2[i]-val[i])<1.e-12); + self.assertTrue(abs(expected2[i]-val[i])<1.e-12); pass # f3=f2*f1; val=f3.getArray().getValues(); for i in xrange(15): - self.failUnless(abs(expected2[i]-val[i])<1.e-12); + self.assertTrue(abs(expected2[i]-val[i])<1.e-12); pass pass @@ -1187,16 +1187,16 @@ class MEDCouplingBasicsTest(unittest.TestCase): f2=m.fillFromAnalytic(ON_NODES,1,"a*a+b+c*c"); f1/=f2 f1.checkCoherency(); - self.failUnlessEqual(f1.getTypeOfField(),ON_NODES); - self.failUnlessEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); expected1=[-2.4999999999999991, 1.2162162162162162, 0.77868852459016391, 0.7407407407407407, 1.129032258064516, 0.81632653061224492, 0.86538461538461531, 1.0919540229885056, 0.84302325581395343] - self.failUnlessEqual(1,f1.getNumberOfComponents()); - self.failUnlessEqual(9,f1.getNumberOfTuples()); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); val=f1.getArray().getValues(); for i in xrange(9): - self.failUnless(abs(expected1[i]-val[i])<1.e-12); + self.assertTrue(abs(expected1[i]-val[i])<1.e-12); pass # f1=m.buildOrthogonalField(); @@ -1205,12 +1205,12 @@ class MEDCouplingBasicsTest(unittest.TestCase): expected2=[-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637] val=f1.getArray().getValues(); for i in xrange(15): - self.failUnless(abs(expected2[i]-val[i])<1.e-12); + self.assertTrue(abs(expected2[i]-val[i])<1.e-12); pass # f1=m.buildOrthogonalField(); # to avoid valgrind leaks - # self.failUnlessRaises(Exception,f2.__imul__,f1); + # self.assertRaises(Exception,f2.__imul__,f1); pass def testOperationsOnFields4(self): @@ -1220,8 +1220,8 @@ class MEDCouplingBasicsTest(unittest.TestCase): f1.setMesh(m); array=DataArrayDouble.New(); f1.setArray(array); - self.failUnlessRaises(Exception,f1.setEndArray,array); - self.failUnlessRaises(Exception,f1.getEndArray); + self.assertRaises(Exception,f1.setEndArray,array); + self.assertRaises(Exception,f1.getEndArray); arr1=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.] arr2=[5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.] array.setValues(arr1,nbOfCells,3); @@ -1230,22 +1230,22 @@ class MEDCouplingBasicsTest(unittest.TestCase): f1.checkCoherency(); pos=[0.3,-0.2] res=f1.getValueOn(pos); - self.failUnless(abs(arr1[3]-res[0])<1.e-12); - self.failUnless(abs(arr1[4]-res[1])<1.e-12); - self.failUnless(abs(arr1[5]-res[2])<1.e-12); + self.assertTrue(abs(arr1[3]-res[0])<1.e-12); + self.assertTrue(abs(arr1[4]-res[1])<1.e-12); + self.assertTrue(abs(arr1[5]-res[2])<1.e-12); res=None res=f1.getValueOn(pos,2.2); - self.failUnless(abs(arr1[3]-res[0])<1.e-12); - self.failUnless(abs(arr1[4]-res[1])<1.e-12); - self.failUnless(abs(arr1[5]-res[2])<1.e-12); + self.assertTrue(abs(arr1[3]-res[0])<1.e-12); + self.assertTrue(abs(arr1[4]-res[1])<1.e-12); + self.assertTrue(abs(arr1[5]-res[2])<1.e-12); res=None - self.failUnlessRaises(Exception,f1.getValueOn,pos,3.2) + self.assertRaises(Exception,f1.getValueOn,pos,3.2) f2=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME); f2.setMesh(m); f2.setArray(f1.getArray()); f2.setStartTime(2.,3,0); f2.setEndTime(4.,13,0); - self.failUnlessRaises(Exception,f2.checkCoherency) + self.assertRaises(Exception,f2.checkCoherency) array2=DataArrayDouble.New(); array2.setValues(arr2,nbOfCells,3); f2.setEndArray(array2); @@ -1253,46 +1253,46 @@ class MEDCouplingBasicsTest(unittest.TestCase): # res=None res=f2.getValueOn(pos,3.21); - self.failUnless(abs(4.025-res[0])<1.e-12); - self.failUnless(abs(14.025-res[1])<1.e-12); - self.failUnless(abs(24.025-res[2])<1.e-12); + self.assertTrue(abs(4.025-res[0])<1.e-12); + self.assertTrue(abs(14.025-res[1])<1.e-12); + self.assertTrue(abs(24.025-res[2])<1.e-12); f3=f2.clone(True); - self.failUnless(f2.isEqual(f3,1e-12,1e-12)); + self.assertTrue(f2.isEqual(f3,1e-12,1e-12)); f3.getEndArray().setIJ(0,0,5.001); - self.failUnless(not f2.isEqual(f3,1e-12,1e-12)); - self.failUnless(f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-12)); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); f3.setStartTime(2.1,3,0); - self.failUnless(not f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); f3.setStartTime(2.,3,0); - self.failUnless(f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); f3.setStartTime(2.,4,0); - self.failUnless(not f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); f3.setStartTime(2.,3,1); - self.failUnless(not f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); f3.setStartTime(2.,3,0); - self.failUnless(f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); f3.setEndTime(4.1,13,0); - self.failUnless(not f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); f3.setEndTime(4.,13,0); - self.failUnless(f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); f3.setEndTime(4.,14,0); - self.failUnless(not f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); f3.setEndTime(4.,13,1); - self.failUnless(not f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); f3.setEndTime(4.,13,0); - self.failUnless(f2.isEqual(f3,1e-12,1e-2)); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); f4=f2+f2 res=None res=f4.getValueOn(pos,3.21); - self.failUnless(abs(8.05-res[0])<1.e-12); - self.failUnless(abs(28.05-res[1])<1.e-12); - self.failUnless(abs(48.05-res[2])<1.e-12); + self.assertTrue(abs(8.05-res[0])<1.e-12); + self.assertTrue(abs(28.05-res[1])<1.e-12); + self.assertTrue(abs(48.05-res[2])<1.e-12); f4+=f2; res=None res=f4.getValueOn(pos,3.21); - self.failUnless(abs(12.075-res[0])<1.e-12); - self.failUnless(abs(42.075-res[1])<1.e-12); - self.failUnless(abs(72.075-res[2])<1.e-12); + self.assertTrue(abs(12.075-res[0])<1.e-12); + self.assertTrue(abs(42.075-res[1])<1.e-12); + self.assertTrue(abs(72.075-res[2])<1.e-12); pass def testMergeNodesOnField(self): @@ -1310,14 +1310,14 @@ class MEDCouplingBasicsTest(unittest.TestCase): f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z"); tmp=f1.getArray() tmp.setIJ(1,0,1000.); - self.failUnlessRaises(Exception,f1.mergeNodes,1.e-10) + self.assertRaises(Exception,f1.mergeNodes,1.e-10) pass def testCheckConsecutiveCellTypes(self): sourceMesh=MEDCouplingDataForTest.build2DSourceMesh_1(); targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); - self.failUnless(sourceMesh.checkConsecutiveCellTypes()); - self.failUnless(not targetMesh.checkConsecutiveCellTypes()); + self.assertTrue(sourceMesh.checkConsecutiveCellTypes()); + self.assertTrue(not targetMesh.checkConsecutiveCellTypes()); pass def testRearrange2ConsecutiveCellTypes(self): @@ -1325,70 +1325,70 @@ class MEDCouplingBasicsTest(unittest.TestCase): m2_1=MEDCouplingDataForTest.build2DTargetMesh_1(); arr1=m1_1.rearrange2ConsecutiveCellTypes(); m1_2=MEDCouplingDataForTest.build2DSourceMesh_1(); - self.failUnless(m1_2.isEqual(m1_1,1e-12)); + self.assertTrue(m1_2.isEqual(m1_1,1e-12)); expected1=[0,1] - self.failUnlessEqual(2,arr1.getNumberOfTuples()); - self.failUnlessEqual(1,arr1.getNumberOfComponents()); - self.failUnless(expected1,arr1.getValues()); + self.assertEqual(2,arr1.getNumberOfTuples()); + self.assertEqual(1,arr1.getNumberOfComponents()); + self.assertTrue(expected1,arr1.getValues()); expected2=[0,3,4,1,2] arr1=m2_1.rearrange2ConsecutiveCellTypes(); - self.failUnlessEqual(5,arr1.getNumberOfTuples()); - self.failUnlessEqual(1,arr1.getNumberOfComponents()); - self.failUnlessEqual(expected2,arr1.getValues()); + self.assertEqual(5,arr1.getNumberOfTuples()); + self.assertEqual(1,arr1.getNumberOfComponents()); + self.assertEqual(expected2,arr1.getValues()); m2_2=MEDCouplingDataForTest.build2DTargetMesh_1(); - self.failUnlessEqual(5,arr1.getNumberOfTuples()); - self.failUnlessEqual(1,arr1.getNumberOfComponents()); - self.failUnlessEqual(expected2,arr1.getValues()); - self.failUnless(not m2_2.isEqual(m2_1,1e-12)); + self.assertEqual(5,arr1.getNumberOfTuples()); + self.assertEqual(1,arr1.getNumberOfComponents()); + self.assertEqual(expected2,arr1.getValues()); + self.assertTrue(not m2_2.isEqual(m2_1,1e-12)); m2_2.renumberCells(expected2,False); - self.failUnless(m2_2.isEqual(m2_1,1e-12)); + self.assertTrue(m2_2.isEqual(m2_1,1e-12)); pass def testSplitByType(self): m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); v=m1.splitByType(); - self.failUnlessEqual(3,len(v)); + self.assertEqual(3,len(v)); m2=MEDCouplingUMesh.mergeUMeshesOnSameCoords(v); m2.setName(m1.getName()); - self.failUnless(m1.isEqual(m2,1.e-12)); + self.assertTrue(m1.isEqual(m2,1.e-12)); pass def testFuseUMeshesOnSameCoords(self): m2=MEDCouplingDataForTest.build2DTargetMesh_1(); cells1=[2,3,4] m3=m2.buildPartOfMySelf(cells1,True); - self.failUnless(isinstance(m3,MEDCouplingUMesh)) + self.assertTrue(isinstance(m3,MEDCouplingUMesh)) cells2=[1,2,4] m4=m2.buildPartOfMySelf(cells2,True); - self.failUnless(isinstance(m4,MEDCouplingUMesh)) + self.assertTrue(isinstance(m4,MEDCouplingUMesh)) cells3=[1,2] m5=m2.buildPartOfMySelf(cells3,True); - self.failUnless(isinstance(m5,MEDCouplingUMesh)) + self.assertTrue(isinstance(m5,MEDCouplingUMesh)) meshes=[m3,m4,m5] # m7,corr=MEDCouplingUMesh.fuseUMeshesOnSameCoords(meshes,0); - self.failUnlessEqual(4,m7.getNumberOfCells()); - self.failUnlessEqual(3,len(corr)); + self.assertEqual(4,m7.getNumberOfCells()); + self.assertEqual(3,len(corr)); expectedVals1=[3,3,2] expectedVals2=[[0,1,2],[3,0,2],[3,0]] for i in xrange(3): arr=corr[i]; - self.failUnlessEqual(1,arr.getNumberOfComponents()); + self.assertEqual(1,arr.getNumberOfComponents()); nbOfVals=expectedVals1[i]; - self.failUnlessEqual(nbOfVals,arr.getNumberOfTuples()); + self.assertEqual(nbOfVals,arr.getNumberOfTuples()); vals=arr.getValues(); - self.failUnlessEqual(expectedVals2[i],vals); + self.assertEqual(expectedVals2[i],vals); pass arr2,fidsOfGroups=DataArrayInt.makePartition(corr,m7.getNumberOfCells()); fidExp=[5,1,3,4] fidsGrp=[[1,3,5],[3,4,5],[4,5]] - self.failUnlessEqual(3,len(fidsOfGroups)); - self.failUnlessEqual(1,arr2.getNumberOfComponents()); - self.failUnlessEqual(4,arr2.getNumberOfTuples()); - self.failUnlessEqual(fidExp,arr2.getValues()); + self.assertEqual(3,len(fidsOfGroups)); + self.assertEqual(1,arr2.getNumberOfComponents()); + self.assertEqual(4,arr2.getNumberOfTuples()); + self.assertEqual(fidExp,arr2.getValues()); for i in xrange(3): nbOfVals=expectedVals1[i]; - self.failUnlessEqual(fidsOfGroups[i],fidsGrp[i]); + self.assertEqual(fidsOfGroups[i],fidsGrp[i]); pass pass @@ -1400,7 +1400,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): m4=m1.buildPartOfMySelf(part2,True); meshes=[m1,m3,m3,m4] m5,corr=MEDCouplingUMesh.fuseUMeshesOnSameCoords(meshes,0); - self.failUnlessEqual(18,m5.getNumberOfCells()); + self.assertEqual(18,m5.getNumberOfCells()); exp2=[ [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17], [2,3,6,4,10], @@ -1408,7 +1408,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): [5,6,4,7]] i=0; for it in corr: - self.failUnlessEqual(exp2[i],it.getValues()); + self.assertEqual(exp2[i],it.getValues()); i+=1 pass pass @@ -1417,11 +1417,11 @@ class MEDCouplingBasicsTest(unittest.TestCase): targetMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); field=targetMesh.buildOrthogonalField(); expected=[0.70710678118654746,0.,-0.70710678118654746] - self.failUnlessEqual(5,field.getNumberOfTuples()); - self.failUnlessEqual(3,field.getNumberOfComponents()); + self.assertEqual(5,field.getNumberOfTuples()); + self.assertEqual(3,field.getNumberOfComponents()); vals=field.getArray().getValues(); for i in xrange(15): - self.failUnless(abs(expected[i%3]-vals[i])<1e-12); + self.assertTrue(abs(expected[i%3]-vals[i])<1e-12); # testing targetCoords=[0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.] targetConn=[0,1,2,3] @@ -1434,12 +1434,12 @@ class MEDCouplingBasicsTest(unittest.TestCase): myCoords.setValues(targetCoords,4,3); targetMesh.setCoords(myCoords); field=targetMesh.buildOrthogonalField(); - self.failUnlessEqual(1,field.getNumberOfTuples()); - self.failUnlessEqual(3,field.getNumberOfComponents()); + self.assertEqual(1,field.getNumberOfTuples()); + self.assertEqual(3,field.getNumberOfComponents()); vals=field.getArray().getValues(); - self.failUnless(abs(-0.70710678118654746-vals[0])<1e-12); - self.failUnless(abs(0.-vals[1])<1e-12); - self.failUnless(abs(0.70710678118654746-vals[2])<1e-12); + self.assertTrue(abs(-0.70710678118654746-vals[0])<1e-12); + self.assertTrue(abs(0.-vals[1])<1e-12); + self.assertTrue(abs(0.70710678118654746-vals[2])<1e-12); pass def testGetCellsContainingPoint(self): @@ -1447,12 +1447,12 @@ class MEDCouplingBasicsTest(unittest.TestCase): pos=[0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.] #2D basic t1,t2=targetMesh.getCellsContainingPoints(pos,6,1e-12); - self.failUnlessEqual(6,len(t1)); - self.failUnlessEqual(7,len(t2)); + self.assertEqual(6,len(t1)); + self.assertEqual(7,len(t2)); expectedValues1=[0,4,3,0,1,2] expectedValues2=[0,1,2,3,4,5,6] - self.failUnlessEqual(t1,expectedValues1); - self.failUnlessEqual(t2,expectedValues2); + self.assertEqual(t1,expectedValues1); + self.assertEqual(t2,expectedValues2); #2D with no help of bounding box. center=[0.2,0.2] MEDCouplingPointSet.rotate2DAlg(center,0.78539816339744830962,6,pos); @@ -1460,53 +1460,53 @@ class MEDCouplingBasicsTest(unittest.TestCase): t1=None t2=None t1,t2=targetMesh.getCellsContainingPoints(pos,6,1e-12); - self.failUnlessEqual(6,len(t1)); - self.failUnlessEqual(7,len(t2)); - self.failUnlessEqual(t1,expectedValues1); - self.failUnlessEqual(t2,expectedValues2); + self.assertEqual(6,len(t1)); + self.assertEqual(7,len(t2)); + self.assertEqual(t1,expectedValues1); + self.assertEqual(t2,expectedValues2); #2D outside pos1bis=[-0.3303300858899107,-0.11819805153394641] - self.failUnlessEqual(-1,targetMesh.getCellContainingPoint(pos1bis,1e-12)); + self.assertEqual(-1,targetMesh.getCellContainingPoint(pos1bis,1e-12)); #test limits 2D targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); pos2=[0.2,-0.05] t1=None t1=targetMesh.getCellsContainingPoint(pos2,1e-12) - self.failUnlessEqual(2,len(t1)); + self.assertEqual(2,len(t1)); expectedValues3=[0,1] - self.failUnlessEqual(t1,expectedValues3); + self.assertEqual(t1,expectedValues3); pos3=[0.2,0.2] t1=None t1=targetMesh.getCellsContainingPoint(pos3,1e-12); - self.failUnlessEqual(5,len(t1)); + self.assertEqual(5,len(t1)); expectedValues4=[0,1,2,3,4] - self.failUnlessEqual(t1,expectedValues4); - self.failUnlessEqual(0,targetMesh.getCellContainingPoint(pos3,1e-12)); + self.assertEqual(t1,expectedValues4); + self.assertEqual(0,targetMesh.getCellContainingPoint(pos3,1e-12)); #3D targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1(); pos4=[25.,25.,25.] - self.failUnlessEqual(0,targetMesh.getCellContainingPoint(pos4,1e-12)); + self.assertEqual(0,targetMesh.getCellContainingPoint(pos4,1e-12)); pos5=[50.,50.,50.] t1=None t1=targetMesh.getCellsContainingPoint(pos5,1e-12); - self.failUnlessEqual(8,len(t1)); + self.assertEqual(8,len(t1)); expectedValues5=[0,1,2,3,4,5,6,7] - self.failUnlessEqual(t1,expectedValues5); + self.assertEqual(t1,expectedValues5); pos6=[0., 50., 0.] t1=None t1=targetMesh.getCellsContainingPoint(pos6,1e-12); - self.failUnlessEqual(2,len(t1)); + self.assertEqual(2,len(t1)); expectedValues6=[0,2] - self.failUnlessEqual(t1,expectedValues6); + self.assertEqual(t1,expectedValues6); #3D outside pos7=[-1.0,-1.0,0.] - self.failUnlessEqual(-1,targetMesh.getCellContainingPoint(pos7,1e-12)); + self.assertEqual(-1,targetMesh.getCellContainingPoint(pos7,1e-12)); #3D outside 2 center2=[0.,0.,0.] vec2=[0.,-1.,0.] targetMesh.rotate(center2,vec2,0.78539816339744830962); pos8=[-25.,25.,12.] - self.failUnlessEqual(-1,targetMesh.getCellContainingPoint(pos8,1e-12)); + self.assertEqual(-1,targetMesh.getCellContainingPoint(pos8,1e-12)); pass def testGetValueOn1(self): @@ -1525,9 +1525,9 @@ class MEDCouplingBasicsTest(unittest.TestCase): # pos1=[0.25,0.] res=fieldOnCells.getValueOn(pos1); - self.failUnlessEqual(2,len(res)) - self.failUnless(abs(8.-res[0])<1e-12); - self.failUnless(abs(18.-res[1])<1e-12); + self.assertEqual(2,len(res)) + self.assertTrue(abs(8.-res[0])<1e-12); + self.assertTrue(abs(18.-res[1])<1e-12); # # targetMesh=MEDCouplingDataForTest.build2DSourceMesh_1(); @@ -1546,15 +1546,15 @@ class MEDCouplingBasicsTest(unittest.TestCase): pos2=[-0.13333333333333333,-0.13333333333333333] res=None res=fieldOnNodes.getValueOn(pos2); - self.failUnlessEqual(2,len(res)) - self.failUnless(abs(17.5-res[0])<1e-12); - self.failUnless(abs(27.5-res[1])<1e-12); + self.assertEqual(2,len(res)) + self.assertTrue(abs(17.5-res[0])<1e-12); + self.assertTrue(abs(27.5-res[1])<1e-12); pos3=[0.033333333333333326,0.36666666666666664] res=None res=fieldOnNodes.getValueOn(pos3); - self.failUnlessEqual(2,len(res)) - self.failUnless(abs(18.666666666666667-res[0])<1e-12); - self.failUnless(abs(28.666666666666667-res[1])<1e-12); + self.assertEqual(2,len(res)) + self.assertTrue(abs(18.666666666666667-res[0])<1e-12); + self.assertTrue(abs(28.666666666666667-res[1])<1e-12); pass def testCMesh0(self): @@ -1578,37 +1578,37 @@ class MEDCouplingBasicsTest(unittest.TestCase): expected1=[-0.05,-0.05, 0.2,-0.05, 0.45,-0.05, -0.05,0.2, 0.2,0.2, 0.45,0.2, -0.05,0.45, 0.2,0.45, 0.45,0.45] val=mesh.getCoords().getValues(); - self.failUnlessEqual(18,len(val)) + self.assertEqual(18,len(val)) for i in xrange(18): - self.failUnless(abs(expected1[i]-val[i])<1e-12); + self.assertTrue(abs(expected1[i]-val[i])<1e-12); pass pass def testTryToShareSameCoords(self): m1=MEDCouplingDataForTest.build2DTargetMesh_1(); m2=MEDCouplingDataForTest.build2DTargetMesh_1(); - #self.failUnlessEqual(m1.getCoords()!=m2.getCoords()); + #self.assertEqual(m1.getCoords()!=m2.getCoords()); m1.tryToShareSameCoords(m2,1e-12); - #self.failUnlessEqual(m1.getCoords()==m2.getCoords()); + #self.assertEqual(m1.getCoords()==m2.getCoords()); m1.tryToShareSameCoords(m2,1e-12); - #self.failUnlessEqual(m1.getCoords()==m2.getCoords()); + #self.assertEqual(m1.getCoords()==m2.getCoords()); m2.tryToShareSameCoords(m1,1e-12); - #self.failUnlessEqual(m1.getCoords()==m2.getCoords()); + #self.assertEqual(m1.getCoords()==m2.getCoords()); # m1=MEDCouplingDataForTest.build2DTargetMesh_1(); m2=MEDCouplingDataForTest.build2DTargetMesh_2(); - #self.failUnlessEqual(m1.getCoords()!=m2.getCoords()); + #self.assertEqual(m1.getCoords()!=m2.getCoords()); m1.tryToShareSameCoords(m2,1e-12); - #self.failUnlessEqual(m1.getCoords()==m2.getCoords()); + #self.assertEqual(m1.getCoords()==m2.getCoords()); m1.tryToShareSameCoords(m2,1e-12); - #self.failUnlessEqual(m1.getCoords()==m2.getCoords()); + #self.assertEqual(m1.getCoords()==m2.getCoords()); m2.tryToShareSameCoords(m1,1e-12); - #self.failUnlessEqual(m1.getCoords()==m2.getCoords()); + #self.assertEqual(m1.getCoords()==m2.getCoords()); # m1=MEDCouplingDataForTest.build2DTargetMesh_1(); m2=MEDCouplingDataForTest.build2DSourceMesh_1(); - #self.failUnlessEqual(m1.getCoords()!=m2.getCoords()); - self.failUnlessRaises(Exception,m1.tryToShareSameCoords,m2,1e-12) + #self.assertEqual(m1.getCoords()!=m2.getCoords()); + self.assertRaises(Exception,m1.tryToShareSameCoords,m2,1e-12) pass def testFindNodeOnPlane(self): @@ -1616,52 +1616,155 @@ class MEDCouplingBasicsTest(unittest.TestCase): pt=[300.,300.,0.] v=[0.,0.,2.] n=mesh.findNodesOnPlane(pt,v,1e-12); - self.failUnlessEqual(9,len(n)); + self.assertEqual(9,len(n)); m3dSurf=mesh.buildFacePartOfMySelfNode(n,True); - self.failUnless(isinstance(m3dSurf,MEDCouplingUMesh)) + self.assertTrue(isinstance(m3dSurf,MEDCouplingUMesh)) me=MEDCouplingExtrudedMesh.New(mesh,m3dSurf,0); da=me.getMesh3DIds(); - self.failUnlessEqual(8,me.getNumberOfCells()); + self.assertEqual(8,me.getNumberOfCells()); expected=[0,1,2,3,4,5,6,7] val=da.getValues(); - self.failUnlessEqual(expected,val); + self.assertEqual(expected,val); pass def testRenumberCells(self): m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); - self.failUnless(m.isEqual(m2,0)); + self.assertTrue(m.isEqual(m2,0)); arr=[12,3,25,2,26] m.renumberCells(arr,True); - self.failUnless(not m.isEqual(m2,0)); - self.failUnlessEqual(NORM_QUAD4,m.getTypeOfCell(0)); - self.failUnlessEqual(NORM_TRI3,m.getTypeOfCell(1)); - self.failUnlessEqual(NORM_QUAD4,m.getTypeOfCell(2)); - self.failUnlessEqual(NORM_TRI3,m.getTypeOfCell(3)); - self.failUnlessEqual(NORM_QUAD4,m.getTypeOfCell(4)); + self.assertTrue(not m.isEqual(m2,0)); + self.assertEqual(NORM_QUAD4,m.getTypeOfCell(0)); + self.assertEqual(NORM_TRI3,m.getTypeOfCell(1)); + self.assertEqual(NORM_QUAD4,m.getTypeOfCell(2)); + self.assertEqual(NORM_TRI3,m.getTypeOfCell(3)); + self.assertEqual(NORM_QUAD4,m.getTypeOfCell(4)); arr2=[5,-1,-5,4,8] m.renumberCells(arr2,True); - self.failUnless(m.isEqual(m2,0)); + self.assertTrue(m.isEqual(m2,0)); pass def testChangeSpaceDimension(self): m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); m2=MEDCouplingDataForTest.build2DTargetMesh_1(); # - self.failUnlessEqual(3,m1.getSpaceDimension()); + self.assertEqual(3,m1.getSpaceDimension()); m1.changeSpaceDimension(2); - self.failUnlessEqual(2,m1.getSpaceDimension()); + self.assertEqual(2,m1.getSpaceDimension()); m1.setName(m2.getName()); - self.failUnless(m1.isEqual(m2,1e-12)); + self.assertTrue(m1.isEqual(m2,1e-12)); m1.changeSpaceDimension(3); - self.failUnlessEqual(3,m1.getSpaceDimension()); + self.assertEqual(3,m1.getSpaceDimension()); expected=[-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0.] val=m1.getCoords().getValues(); for i in xrange(27): - self.failUnless(abs(expected[i]-val[i])<1e-14); + self.assertTrue(abs(expected[i]-val[i])<1e-14); pass pass + def testGaussPointField1(self): + _a=0.446948490915965; + _b=0.091576213509771; + _p1=0.11169079483905; + _p2=0.0549758718227661; + refCoo1=[ 0.,0., 1.,0., 0.,1. ] + gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b, + 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ] + wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ] + _refCoo1=refCoo1 + _gsCoo1=gsCoo1 + _wg1=wg1 + # + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME); + f.setMesh(m); + self.assertEqual(0,f.getNbOfGaussLocalization()); + f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1); + self.assertRaises(Exception,f.setGaussLocalizationOnType,NORM_QUAD4,_refCoo1,_gsCoo1,_wg1) + self.assertEqual(1,f.getNbOfGaussLocalization()); + refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ] + _refCoo2=refCoo2 + _gsCoo1=_gsCoo1[0:4] + _wg1=_wg1[0:2] + f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo2,_gsCoo1,_wg1); + self.assertEqual(2,f.getNbOfGaussLocalization()); + array=DataArrayDouble.New(); + ptr=18*2*[None] + for i in xrange(18*2): + ptr[i]=float(i+1) + array.setValues(ptr,18,2); + ptr=array.getPointer(); + f.setArray(array); + f.setName("MyFirstFieldOnGaussPoint"); + f.checkCoherency(); + self.assertAlmostEqual(27.,f.getIJK(2,5,0),14); + self.assertAlmostEqual(16.,f.getIJK(1,5,1),14); + # + f.clearGaussLocalizations(); + self.assertEqual(0,f.getNbOfGaussLocalization()); + self.assertRaises(Exception,f.checkCoherency); + ids1=[0,1,3,4] + self.assertRaises(Exception,f.setGaussLocalizationOnCells,ids1,_refCoo2,_gsCoo1,_wg1); + self.assertEqual(0,f.getNbOfGaussLocalization()); + ids2=[0,4] + f.setGaussLocalizationOnCells(ids2,_refCoo2,_gsCoo1,_wg1); + self.assertEqual(1,f.getNbOfGaussLocalization()); + self.assertEqual(0,f.getGaussLocalizationIdOfOneCell(0)); + self.assertRaises(Exception,f.getGaussLocalizationIdOfOneCell,1); + ids3=[1,2] + f.setGaussLocalizationOnCells(ids3,_refCoo1,_gsCoo1,_wg1); + self.assertEqual(2,f.getNbOfGaussLocalization()); + self.assertEqual(0,f.getGaussLocalizationIdOfOneCell(0)); + self.assertEqual(1,f.getGaussLocalizationIdOfOneCell(1)); + self.assertEqual(1,f.getGaussLocalizationIdOfOneCell(2)); + self.assertRaises(Exception,f.checkCoherency);#<- cell 3 has no localization + ids4=[3] + _gsCoo2=_gsCoo1; + _wg2=_wg1; + _gsCoo2[0]=0.8888777776666; + _wg2[0]=0.1234567892377; + f.setGaussLocalizationOnCells(ids4,_refCoo2,_gsCoo2,_wg2); + self.assertEqual(3,f.getNbOfGaussLocalization()); + tmpIds=f.getCellIdsHavingGaussLocalization(0); + self.assertEqual(ids2,tmpIds); + self.assertRaises(Exception,f.checkCoherency);#<- it's always not ok because undelying array not with the good size. + array2=f.getArray().substr(0,10); + f.setArray(array2); + f.checkCoherency();#<- here it is OK + f2=f.clone(True); + self.assertTrue(f.isEqual(f2,1e-14,1e-14)); + gl1=f2.getGaussLocalization(0); + tmp=gl1.getGaussCoord(1,1); + self.assertAlmostEqual(2.07*_b-1,tmp,14); + gl1.setGaussCoord(1,1,0.07); + self.assertTrue(not f.isEqual(f2,1e-14,1e-14)); + gl1.setGaussCoord(1,1,tmp); + self.assertTrue(f.isEqual(f2,1e-14,1e-14)); + f2.checkCoherency(); + pass + + def testGaussPointNEField1(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME); + f.setMesh(m); + f.setName("MyFirstFieldOnNE"); + f.setDescription("MyDescriptionNE"); + array=DataArrayDouble.New(); + tmp=18*2*[None] + for i in xrange(18*2): + tmp[i]=float(i+7) + pass + array.setValues(tmp,18,2); + ptr=array.getPointer(); + f.setArray(array); + # + f.checkCoherency(); + f2=f.clone(True); + self.assertTrue(f.isEqual(f2,1e-14,1e-14)); + self.assertAlmostEqual(21.,f.getIJK(2,0,0),14); + self.assertAlmostEqual(18.,f.getIJK(1,1,1),14); + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i index 2f20bf5e5..8bba623ac 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i @@ -31,6 +31,7 @@ #include "MEDCouplingCMesh.hxx" #include "MEDCouplingField.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingGaussLocalization.hxx" #include "MEDCouplingTypemaps.i" using namespace ParaMEDMEM; @@ -38,6 +39,7 @@ using namespace INTERP_KERNEL; %} %template(ivec) std::vector; +%template(dvec) std::vector; %typemap(out) ParaMEDMEM::MEDCouplingMesh* { @@ -103,6 +105,10 @@ using namespace INTERP_KERNEL; %ignore ParaMEDMEM::MemArray::operator=; %ignore ParaMEDMEM::MemArray::operator[]; %ignore ParaMEDMEM::MEDCouplingPointSet::getCoords(); +%ignore ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo; +%ignore ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo; +%ignore ParaMEDMEM::MEDCouplingGaussLocalization::fillWithValues; +%ignore ParaMEDMEM::MEDCouplingGaussLocalization::buildNewInstanceFromTinyInfo; %rename (Exception) InterpKernelException; %nodefaultctor; @@ -171,6 +177,7 @@ namespace ParaMEDMEM %include "NormalizedUnstructuredMesh.hxx" %include "MEDCouplingNatureOfField.hxx" %include "MEDCouplingTimeDiscretization.hxx" +%include "MEDCouplingGaussLocalization.hxx" namespace ParaMEDMEM { @@ -597,6 +604,13 @@ namespace ParaMEDMEM const char *getName() const; TypeOfField getTypeOfField() const; MEDCouplingFieldDiscretization *getDiscretization() const; + void setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); + void clearGaussLocalizations(); + MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); + int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); + int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); + const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); %extend { PyObject *getMesh() const { @@ -617,6 +631,28 @@ namespace ParaMEDMEM PyList_SetItem(res,1,SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); return res; } + void setGaussLocalizationOnCells(PyObject *li, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + try + { + self->setGaussLocalizationOnCells(tmp,tmp+size,refCoo,gsCoo,wg); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] tmp; + throw e; + } + delete [] tmp; + } + PyObject *getCellIdsHavingGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + self->getCellIdsHavingGaussLocalization(locId,tmp); + return convertIntArrToPyList2(tmp); + } } }; @@ -629,6 +665,7 @@ namespace ParaMEDMEM TypeOfTimeDiscretization getTimeDiscretization() const; void checkCoherency() const throw(INTERP_KERNEL::Exception); double getIJ(int tupleId, int compoId) const; + double getIJK(int cellId, int nodeIdInCell, int compoId) const; void setArray(DataArrayDouble *array) throw(INTERP_KERNEL::Exception); void setEndArray(DataArrayDouble *array) throw(INTERP_KERNEL::Exception); void setTime(double val, int dt, int it) throw(INTERP_KERNEL::Exception); -- 2.39.2