From 251ecc39881af3d5889ad3c39ee1e7b99975cd4c Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 8 Oct 2010 07:50:14 +0000 Subject: [PATCH] *** empty log message *** --- .../MEDCouplingAutoRefCountObjectPtr.hxx | 6 +- src/MEDCoupling/MEDCouplingCMesh.cxx | 24 + src/MEDCoupling/MEDCouplingCMesh.hxx | 3 + src/MEDCoupling/MEDCouplingExtrudedMesh.cxx | 22 + src/MEDCoupling/MEDCouplingExtrudedMesh.hxx | 3 + src/MEDCoupling/MEDCouplingField.cxx | 17 + src/MEDCoupling/MEDCouplingField.hxx | 2 + .../MEDCouplingFieldDiscretization.cxx | 54 +- .../MEDCouplingFieldDiscretization.hxx | 3 + src/MEDCoupling/MEDCouplingFieldDouble.cxx | 140 ++++- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 26 +- src/MEDCoupling/MEDCouplingMemArray.cxx | 285 +++++++++ src/MEDCoupling/MEDCouplingMemArray.hxx | 14 + src/MEDCoupling/MEDCouplingMemArray.txx | 2 + src/MEDCoupling/MEDCouplingMesh.cxx | 44 +- src/MEDCoupling/MEDCouplingMesh.hxx | 4 + src/MEDCoupling/MEDCouplingPointSet.cxx | 43 +- src/MEDCoupling/MEDCouplingPointSet.hxx | 4 +- .../MEDCouplingTimeDiscretization.cxx | 436 +++++++++++--- .../MEDCouplingTimeDiscretization.hxx | 91 +-- src/MEDCoupling/MEDCouplingUMesh.cxx | 67 +++ src/MEDCoupling/MEDCouplingUMesh.hxx | 3 + src/MEDCoupling/MEDCouplingUMeshDesc.cxx | 6 + src/MEDCoupling/MEDCouplingUMeshDesc.hxx | 2 + .../Test/MEDCouplingBasicsTest.hxx | 24 + .../Test/MEDCouplingBasicsTest2.cxx | 565 ++++++++++++++++++ 26 files changed, 1715 insertions(+), 175 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingAutoRefCountObjectPtr.hxx b/src/MEDCoupling/MEDCouplingAutoRefCountObjectPtr.hxx index 7dd470af8..9a30b7d8f 100644 --- a/src/MEDCoupling/MEDCouplingAutoRefCountObjectPtr.hxx +++ b/src/MEDCoupling/MEDCouplingAutoRefCountObjectPtr.hxx @@ -29,10 +29,10 @@ namespace ParaMEDMEM { public: MEDCouplingAutoRefCountObjectPtr(const MEDCouplingAutoRefCountObjectPtr& other):_ptr(0) { referPtr(other._ptr); } - MEDCouplingAutoRefCountObjectPtr(T *ptr):_ptr(ptr) { } + MEDCouplingAutoRefCountObjectPtr(T *ptr=0):_ptr(ptr) { } ~MEDCouplingAutoRefCountObjectPtr() { destroyPtr(); } - MEDCouplingAutoRefCountObjectPtr &operator=(const MEDCouplingAutoRefCountObjectPtr& other) { destroyPtr(); referPtr(other._ptr); return *this; } - MEDCouplingAutoRefCountObjectPtr &operator=(T *ptr) { destroyPtr(); _ptr=ptr; return *this; } + MEDCouplingAutoRefCountObjectPtr &operator=(const MEDCouplingAutoRefCountObjectPtr& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; } + MEDCouplingAutoRefCountObjectPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } T *operator->() { return _ptr ; } const T *operator->() const { return _ptr; } T& operator*() { return *_ptr; } diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index a69362f47..3fd5fd404 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -129,12 +129,36 @@ bool MEDCouplingCMesh::isEqual(const MEDCouplingMesh *other, double prec) const return true; } +bool MEDCouplingCMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const +{ + const MEDCouplingCMesh *otherC=dynamic_cast(other); + if(!otherC) + return false; + const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array}; + const DataArrayDouble *otherArr[3]={otherC->_x_array,otherC->_y_array,otherC->_z_array}; + for(int i=0;i<3;i++) + { + if((thisArr[i]!=0 && otherArr[i]==0) || (thisArr[i]==0 && otherArr[i]!=0)) + return false; + if(thisArr[i]) + if(!thisArr[i]->isEqualWithoutConsideringStr(*otherArr[i],prec)) + return false; + } + return true; +} + void MEDCouplingCMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception("Not implemented yet !"); } +void MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + void MEDCouplingCMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) { const char msg0[]="Invalid "; diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index 754f5b54d..e08226512 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -37,8 +37,11 @@ namespace ParaMEDMEM MEDCouplingMeshType getType() const { return CARTESIAN; } void copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception); bool isEqual(const MEDCouplingMesh *other, double prec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const; void checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception); + void checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception); void checkCoherency() const throw(INTERP_KERNEL::Exception); int getNumberOfCells() const; int getNumberOfNodes() const; diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index a95d38e4e..29d27ade9 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -168,12 +168,34 @@ bool MEDCouplingExtrudedMesh::isEqual(const MEDCouplingMesh *other, double prec) return true; } +bool MEDCouplingExtrudedMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const +{ + const MEDCouplingExtrudedMesh *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(!_mesh2D->isEqualWithoutConsideringStr(otherC->_mesh2D,prec)) + return false; + if(!_mesh1D->isEqualWithoutConsideringStr(otherC->_mesh1D,prec)) + return false; + if(!_mesh3D_ids->isEqualWithoutConsideringStr(*otherC->_mesh3D_ids)) + return false; + if(_cell_2D_id!=otherC->_cell_2D_id) + return false; + return true; +} + void MEDCouplingExtrudedMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::checkDeepEquivalWith : not implemented yet !"); } +void MEDCouplingExtrudedMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::checkDeepEquivalOnSameNodesWith : not implemented yet !"); +} + INTERP_KERNEL::NormalizedCellType MEDCouplingExtrudedMesh::getTypeOfCell(int cellId) const { const int *ids=_mesh3D_ids->getConstPointer(); diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 916beae9b..e8915f4ee 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -46,8 +46,11 @@ namespace ParaMEDMEM MEDCouplingMesh *deepCpy() const; MEDCouplingExtrudedMesh *clone(bool recDeepCpy) const; bool isEqual(const MEDCouplingMesh *other, double prec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const; void checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception); + void checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception); INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const; int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; void getNodeIdsOfCell(int cellId, std::vector& conn) const; diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 8982d4760..3a917c753 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -40,6 +40,19 @@ bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, d return _mesh->isEqual(other->_mesh,meshPrec); } +bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const +{ + if(!_type->isEqualWithoutConsideringStr(other->_type,valsPrec)) + return false; + if(_mesh==0 && other->_mesh==0) + return true; + if(_mesh==0 || other->_mesh==0) + return false; + if(_mesh==other->_mesh) + return true; + return _mesh->isEqualWithoutConsideringStr(other->_mesh,meshPrec); +} + /*! * This method states if 'this' and 'other' are compatibles each other before performing any treatment. * This method is good for methods like : mergeFields. @@ -231,6 +244,10 @@ MEDCouplingField::~MEDCouplingField() delete _type; } +MEDCouplingField::MEDCouplingField(MEDCouplingFieldDiscretization *type):_mesh(0),_type(type) +{ +} + MEDCouplingField::MEDCouplingField(TypeOfField type):_mesh(0),_type(MEDCouplingFieldDiscretization::New(type)) { } diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index 8287acecd..d1ed3a27f 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -44,6 +44,7 @@ namespace ParaMEDMEM virtual bool areCompatibleForMerge(const MEDCouplingField *other) const; virtual bool areStrictlyCompatible(const MEDCouplingField *other) const; virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; + virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh); const ParaMEDMEM::MEDCouplingMesh *getMesh() const { return _mesh; } void setName(const char *name) { _name=name; } @@ -71,6 +72,7 @@ namespace ParaMEDMEM protected: MEDCouplingField(TypeOfField type); MEDCouplingField(const MEDCouplingField& other); + MEDCouplingField(MEDCouplingFieldDiscretization *type); virtual ~MEDCouplingField(); protected: std::string _name; diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 77a958052..8633dc1f3 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -84,6 +84,11 @@ TypeOfField MEDCouplingFieldDiscretization::getTypeOfFieldFromStringRepr(const c throw INTERP_KERNEL::Exception("Representation does not match with any field discretization !"); } +bool MEDCouplingFieldDiscretization::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const +{ + return isEqual(other,eps); +} + /*! * Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally. */ @@ -408,24 +413,7 @@ DataArrayDouble *MEDCouplingFieldDiscretizationP1::getLocalizationOfDiscValues(c void MEDCouplingFieldDiscretizationP1::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *partBg, const int *partEnd, DataArrayInt *&cellRest) { - std::vector crest; - std::vector conn; - std::set p(partBg,partEnd); - int nbOfCells=mesh->getNumberOfCells(); - for(int i=0;i conn; - mesh->getNodeIdsOfCell(i,conn); - bool cont=true; - for(std::vector::const_iterator iter=conn.begin();iter!=conn.end() && cont;iter++) - if(p.find(*iter)==p.end()) - cont=false; - if(cont) - crest.push_back(i); - } - cellRest=DataArrayInt::New(); - cellRest->alloc(crest.size(),1); - std::copy(crest.begin(),crest.end(),cellRest->getPointer()); + cellRest=mesh->getCellIdsFullyIncludedInNodeIds(partBg,partEnd); } void MEDCouplingFieldDiscretizationP1::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) @@ -440,7 +428,7 @@ void MEDCouplingFieldDiscretizationP1::checkCoherencyBetween(const MEDCouplingMe { std::ostringstream message; message << "Field on nodes invalid because there are " << mesh->getNumberOfNodes(); - message << " cells in mesh and " << da->getNumberOfTuples() << " tuples in field !"; + message << " nodes in mesh and " << da->getNumberOfTuples() << " tuples in field !"; throw INTERP_KERNEL::Exception(message.str().c_str()); } } @@ -578,6 +566,18 @@ bool MEDCouplingFieldDiscretizationPerCell::isEqual(const MEDCouplingFieldDiscre return _discr_per_cell->isEqual(*otherC->_discr_per_cell); } +bool MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(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->isEqualWithoutConsideringStr(*otherC->_discr_per_cell); +} + /*! * This method is typically the first step of renumbering. The impact on _discr_per_cell is necessary here. * virtualy by this method. @@ -638,6 +638,22 @@ bool MEDCouplingFieldDiscretizationGauss::isEqual(const MEDCouplingFieldDiscreti return true; } +bool MEDCouplingFieldDiscretizationGauss::isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const +{ + const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(!MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(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); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 89d3e7c0f..0773d13e7 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -46,6 +46,7 @@ namespace ParaMEDMEM static TypeOfField getTypeOfFieldFromStringRepr(const char *repr) throw(INTERP_KERNEL::Exception); virtual TypeOfField getEnum() const = 0; virtual bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const = 0; + virtual bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; virtual MEDCouplingFieldDiscretization *clone() const = 0; virtual const char *getStringRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const = 0; @@ -153,6 +154,7 @@ namespace ParaMEDMEM void updateTime(); void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; + bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); protected: void buildDiscrPerCellIfNecessary(const MEDCouplingMesh *m); @@ -166,6 +168,7 @@ namespace ParaMEDMEM MEDCouplingFieldDiscretizationGauss(); TypeOfField getEnum() const; bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; + bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; MEDCouplingFieldDiscretization *clone() const; const char *getStringRepr() const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index e7f431fdf..81758deda 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -55,7 +55,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::cloneWithMesh(bool recDeepCpy) c MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const { MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(_time_discr,td,deepCpy); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),tdo,getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),tdo,_type->clone()); ret->setMesh(getMesh()); ret->setName(getName()); ret->setDescription(getDescription()); @@ -134,6 +134,20 @@ bool MEDCouplingFieldDouble::isEqual(const MEDCouplingField *other, double meshP return true; } +bool MEDCouplingFieldDouble::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const +{ + const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_nature!=otherC->_nature) + return false; + if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec)) + return false; + if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,valsPrec)) + return false; + return true; +} + /*! * This method states if 'this' and 'other' are compatibles each other before performing any treatment. * This method is good for methods like : mergeFields. @@ -328,8 +342,8 @@ MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& oth { } -MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, TypeOfField type):MEDCouplingField(type), - _nature(n),_time_discr(td) +MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type), + _nature(n),_time_discr(td) { } @@ -878,6 +892,108 @@ bool MEDCouplingFieldDouble::mergeNodes(double eps) throw(INTERP_KERNEL::Excepti return true; } +MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("DoublyContractedProduct"); + ret->setMesh(getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->determinant(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("Determinant"); + ret->setMesh(getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->eigenValues(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("EigenValues"); + ret->setMesh(getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("EigenVectors"); + ret->setMesh(getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->inverse(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("Inversion"); + ret->setMesh(getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->trace(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("Trace"); + ret->setMesh(getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->deviator(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("Trace"); + ret->setMesh(getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->magnitude(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("Magnitude"); + ret->setMesh(getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + std::ostringstream oss; + oss << "Max_" << getName(); + ret->setName(oss.str().c_str()); + ret->setMesh(getMesh()); + return ret; +} + +void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception) +{ + _time_discr->changeNbOfComponents(newNbOfComp,dftValue); +} + +void MEDCouplingFieldDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception) +{ + _time_discr->sortPerTuple(asc); +} + MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) { if(!f1->areCompatibleForMerge(f2)) @@ -886,7 +1002,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const MEDCouplingFie const MEDCouplingMesh *m2=f2->getMesh(); MEDCouplingMesh *m=m1->mergeMyselfWith(m2); MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(m); m->decrRef(); ret->setName(f1->getName()); @@ -900,7 +1016,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::dotFields(const MEDCouplingField throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply dotFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } @@ -911,7 +1027,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::crossProductFields(const MEDCoup throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply crossProductFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } @@ -922,7 +1038,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxFields(const MEDCouplingField throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply maxFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } @@ -933,7 +1049,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::minFields(const MEDCouplingField throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply minFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } @@ -944,7 +1060,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::addFields(const MEDCouplingField throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply addFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } @@ -963,7 +1079,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::substractFields(const MEDCouplin throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply substractFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } @@ -982,7 +1098,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::multiplyFields(const MEDCoupling throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply multiplyFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } @@ -1001,7 +1117,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::divideFields(const MEDCouplingFi throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply divideFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index d29f8c6ca..cbc0cf924 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -36,6 +36,7 @@ namespace ParaMEDMEM std::string simpleRepr() const; std::string advancedRepr() const; bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; bool areCompatibleForMerge(const MEDCouplingField *other) const; bool areStrictlyCompatible(const MEDCouplingField *other) const; bool areCompatibleForMul(const MEDCouplingField *other) const; @@ -53,12 +54,12 @@ namespace ParaMEDMEM void checkCoherency() const throw(INTERP_KERNEL::Exception); NatureOfField getNature() const { return _nature; } void setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception); - void setTime(double val, int dt, int it) { _time_discr->setTime(val,dt,it); } - void setStartTime(double val, int dt, int it) { _time_discr->setStartTime(val,dt,it); } - void setEndTime(double val, int dt, int it) { _time_discr->setEndTime(val,dt,it); } - double getTime(int& dt, int& it) const { return _time_discr->getTime(dt,it); } - 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); } + void setTime(double val, int iteration, int order) { _time_discr->setTime(val,iteration,order); } + void setStartTime(double val, int iteration, int order) { _time_discr->setStartTime(val,iteration,order); } + void setEndTime(double val, int iteration, int order) { _time_discr->setEndTime(val,iteration,order); } + double getTime(int& iteration, int& order) const { return _time_discr->getTime(iteration,order); } + double getStartTime(int& iteration, int& order) const { return _time_discr->getStartTime(iteration,order); } + double getEndTime(int& iteration, int& order) const { return _time_discr->getEndTime(iteration,order); } 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); @@ -102,6 +103,17 @@ namespace ParaMEDMEM void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *determinant() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *eigenValues() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *eigenVectors() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *inverse() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *trace() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *deviator() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *magnitude() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *maxPerTuple() const throw(INTERP_KERNEL::Exception); + void changeNbOfComponents(int newNbOfComp, double dftValue=0.) throw(INTERP_KERNEL::Exception); + void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); static MEDCouplingFieldDouble *dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); MEDCouplingFieldDouble *dot(const MEDCouplingFieldDouble& other) const { return dotFields(this,&other); } @@ -126,7 +138,7 @@ namespace ParaMEDMEM private: MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy); - MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, TypeOfField type); + MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type); ~MEDCouplingFieldDouble(); private: NatureOfField _nature; diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 65d3d9ee3..e481cd340 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -19,9 +19,11 @@ #include "MEDCouplingMemArray.txx" +#include "GenMathFormulae.hxx" #include "InterpKernelExprParser.hxx" #include +#include #include #include @@ -141,6 +143,11 @@ bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const return _mem.isEqual(other._mem,prec); } +bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const +{ + return _mem.isEqual(other._mem,prec); +} + void DataArrayDouble::reAlloc(int nbOfTuples) { _mem.reAlloc(_info_on_compo.size()*nbOfTuples); @@ -223,6 +230,35 @@ DataArrayDouble *DataArrayDouble::substr(int tupleIdBg, int tupleIdEnd) const th return ret; } +/*! + * This method builds a new instance of DataArrayDouble (to deal with) that is reduction or an extension of 'this'. + * if 'newNbOfComp' < this->getNumberOfComponents() a reduction is done and for each tuple 'newNbOfComp' first components are kept. + * If 'newNbOfComp' > this->getNumberOfComponents() an extension is done, and for each components i such that i > getNumberOfComponents() 'dftValue' parameter is taken. + */ +DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception) +{ + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(getNumberOfTuples(),newNbOfComp); + const double *oldc=getConstPointer(); + double *nc=ret->getPointer(); + int nbOfTuples=getNumberOfTuples(); + int oldNbOfComp=getNumberOfComponents(); + int dim=std::min(oldNbOfComp,newNbOfComp); + for(int i=0;isetName(getName().c_str()); + for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); + ret->setName(getName().c_str()); + return ret; +} + /*! * This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here. */ @@ -330,6 +366,220 @@ double DataArrayDouble::accumulate(int compId) const return ret; } +DataArrayDouble *DataArrayDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception) +{ + int nbOfComp=getNumberOfComponents(); + if(nbOfComp!=6) + throw INTERP_KERNEL::Exception("DataArrayDouble::doublyContractedProduct : must be an array with exactly 6 components !"); + DataArrayDouble *ret=DataArrayDouble::New(); + int nbOfTuple=getNumberOfTuples(); + ret->alloc(nbOfTuple,1); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); + for(int i=0;ialloc(nbOfTuple,1); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); + switch(getNumberOfComponents()) + { + case 6: + for(int i=0;idecrRef(); + throw INTERP_KERNEL::Exception("DataArrayDouble::determinant : Invalid number of components ! must be in 4,6,9 !"); + } +} + +DataArrayDouble *DataArrayDouble::eigenValues() const throw(INTERP_KERNEL::Exception) +{ + int nbOfComp=getNumberOfComponents(); + if(nbOfComp!=6) + throw INTERP_KERNEL::Exception("DataArrayDouble::eigenValues : must be an array with exactly 6 components !"); + DataArrayDouble *ret=DataArrayDouble::New(); + int nbOfTuple=getNumberOfTuples(); + ret->alloc(nbOfTuple,3); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); + for(int i=0;ialloc(nbOfTuple,9); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); + for(int i=0;ialloc(nbOfTuple,nbOfComp); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); +if(nbOfComp==6) + for(int i=0;ialloc(nbOfTuple,1); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); + if(nbOfComp==6) + for(int i=0;ialloc(nbOfTuple,6); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); + for(int i=0;ialloc(nbOfTuple,1); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); + for(int i=0;ialloc(nbOfTuple,1); + const double *src=getConstPointer(); + double *dest=ret->getPointer(); + for(int i=0;i()); + declareAsNew(); +} + void DataArrayDouble::applyLin(double a, double b, int compoId) { double *ptr=getPointer()+compoId; @@ -845,6 +1095,11 @@ bool DataArrayInt::isEqual(const DataArrayInt& other) const return _mem.isEqual(other._mem,0); } +bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const +{ + return _mem.isEqual(other._mem,0); +} + void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) { _nb_of_tuples=nbOfTuple; @@ -937,6 +1192,36 @@ DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const throw(IN return ret; } +/*! + * This method builds a new instance of DataArrayInt (to deal with) that is reduction or an extension of 'this'. + * if 'newNbOfComp' < this->getNumberOfComponents() a reduction is done and for each tuple 'newNbOfComp' first components are kept. + * If 'newNbOfComp' > this->getNumberOfComponents() an extension is done, and for each components i such that i > getNumberOfComponents() 'dftValue' parameter is taken. + */ +DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception) +{ + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(getNumberOfTuples(),newNbOfComp); + const int *oldc=getConstPointer(); + int *nc=ret->getPointer(); + int nbOfTuples=getNumberOfTuples(); + int oldNbOfComp=getNumberOfComponents(); + int dim=std::min(oldNbOfComp,newNbOfComp); + for(int i=0;isetName(getName().c_str()); + for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); + ret->setName(getName().c_str()); + return ret; +} + + /*! * This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here. */ diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 9e71e2db5..18396d86f 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -122,12 +122,14 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const; //!alloc or useArray should have been called before. MEDCOUPLING_EXPORT void reAlloc(int nbOfTuples); MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const; MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New); MEDCOUPLING_EXPORT DataArrayDouble *renumber(const int *old2New) const; MEDCOUPLING_EXPORT DataArrayDouble *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *start, const int *end) const; MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } MEDCOUPLING_EXPORT double getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } @@ -143,6 +145,16 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT double getAverageValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void accumulate(double *res) const; MEDCOUPLING_EXPORT double accumulate(int compId) const; + MEDCOUPLING_EXPORT DataArrayDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *determinant() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *eigenValues() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *eigenVectors() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *inverse() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *trace() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *deviator() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *magnitude() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *maxPerTuple() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void applyLin(double a, double b, int compoId); MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception); @@ -179,6 +191,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *performCpy(bool deepCpy) const; MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt& other) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt& other) const; MEDCOUPLING_EXPORT void fillWithZero(); MEDCOUPLING_EXPORT std::string repr() const; MEDCOUPLING_EXPORT std::string reprZip() const; @@ -195,6 +208,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *renumber(const int *old2New) const; MEDCOUPLING_EXPORT bool isIdentity() const; MEDCOUPLING_EXPORT DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *start, const int *end) const; MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } MEDCOUPLING_EXPORT int getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 21c88c78c..5a1a048d5 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -87,6 +87,8 @@ namespace ParaMEDMEM return true; if(pt1==0 || pt2==0) return false; + if(pt1==pt2) + return true; for(int i=0;i<_nb_of_elem;i++) if(pt1[i]-pt2[i]<-prec || (pt1[i]-pt2[i])>prec) return false; diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index cf181274f..1f60dc669 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -55,7 +55,9 @@ bool MEDCouplingMesh::isEqual(const MEDCouplingMesh *other, double prec) const * Possible values for levOfCheck : * - 0 for strict equality. This is the strongest level. 'cellCor' and 'nodeCor' params are never informed. * - 10,11,12 for less strict equality. Two meshes are compared geometrically. In case of success 'cellCor' and 'nodeCor' are informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details) + * - 20,21,22, for less strict equality. Two meshes are compared geometrically. The difference with the previous version is that nodes(coordinates) are expected to be the same between this and other. In case of success 'cellCor' is informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details) * - 1 for fast 'equality'. This is a lazy level. Just number of cells and number of nodes are considered here and 3 cells (begin,middle,end) + * - 2 for deep 'equality' as 0 option except that no control is done on all strings in mesh. */ void MEDCouplingMesh::checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception) @@ -79,14 +81,54 @@ void MEDCouplingMesh::checkGeoEquivalWith(const MEDCouplingMesh *other, int levO checkDeepEquivalWith(other,levOfCheck-10,prec,cellCor,nodeCor); return ; } + case 20: + case 21: + case 22: + { + checkDeepEquivalOnSameNodesWith(other,levOfCheck-20,prec,cellCor); + return ; + } case 1: { checkFastEquivalWith(other,prec); return; } + case 2: + { + if(!isEqualWithoutConsideringStr(other,prec)) + throw INTERP_KERNEL::Exception("checkGeoFitWith : Meshes are not equal without considering strings !"); + return ; + } default: - throw INTERP_KERNEL::Exception("checkGeoFitWith : Invalid levOfCheck specified ! Value must be in 0,1,10,11 or 12."); + throw INTERP_KERNEL::Exception("checkGeoFitWith : Invalid levOfCheck specified ! Value must be in 0,1,2,10,11 or 12."); + } +} + +/*! + * Given a nodeIds range ['partBg','partEnd'), this method returns the set of cell ids in ascendant order that are \b fully whose connectivity of + * these cells are fully included in the range. As a consequence the returned set of cell ids does not \b always fit the nodes in ['partBg','partEnd') + * This method returns the corresponding cells in a newly created array that the caller has the responsability. + */ +DataArrayInt *MEDCouplingMesh::getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const +{ + std::vector crest; + std::set p(partBg,partEnd); + int nbOfCells=getNumberOfCells(); + for(int i=0;i conn; + getNodeIdsOfCell(i,conn); + bool cont=true; + for(std::vector::const_iterator iter=conn.begin();iter!=conn.end() && cont;iter++) + if(p.find(*iter)==p.end()) + cont=false; + if(cont) + crest.push_back(i); } + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(crest.size(),1); + std::copy(crest.begin(),crest.end(),ret->getPointer()); + return ret; } /*! diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 7ca13c6f3..3cdbe20a8 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -53,8 +53,11 @@ namespace ParaMEDMEM virtual void copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception); // comparison methods virtual bool isEqual(const MEDCouplingMesh *other, double prec) const; + virtual bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const = 0; virtual void checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception) = 0; + virtual void checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception) = 0; virtual void checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception); void checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception); @@ -69,6 +72,7 @@ namespace ParaMEDMEM virtual int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const = 0; virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0; virtual void getNodeIdsOfCell(int cellId, std::vector& conn) const = 0; + virtual DataArrayInt *getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const; virtual void getCoordinatesOfNode(int nodeId, std::vector& coo) const = 0; virtual std::string simpleRepr() const = 0; virtual std::string advancedRepr() const = 0; diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index 709ae8ce2..f451ea61a 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -119,6 +119,16 @@ bool MEDCouplingPointSet::isEqual(const MEDCouplingMesh *other, double prec) con return true; } +bool MEDCouplingPointSet::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const +{ + const MEDCouplingPointSet *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(!areCoordsEqualWithoutConsideringStr(*otherC,prec)) + return false; + return true; +} + bool MEDCouplingPointSet::areCoordsEqual(const MEDCouplingPointSet& other, double prec) const { if(_coords==0 && other._coords==0) @@ -130,6 +140,17 @@ bool MEDCouplingPointSet::areCoordsEqual(const MEDCouplingPointSet& other, doubl return _coords->isEqual(*other._coords,prec); } +bool MEDCouplingPointSet::areCoordsEqualWithoutConsideringStr(const MEDCouplingPointSet& other, double prec) const +{ + if(_coords==0 && other._coords==0) + return true; + if(_coords==0 || other._coords==0) + return false; + if(_coords==other._coords) + return true; + return _coords->isEqualWithoutConsideringStr(*other._coords,prec); +} + /*! * This method is typically the base method used for implementation of mergeNodes. This method computes this permutation array using as input, * This method is const ! So this method simply computes the array, no permutation of nodes is done. @@ -388,7 +409,7 @@ void MEDCouplingPointSet::scale(const double *point, double factor) * - by ignoring each \f$ i^{th} \f$ components of each coord of nodes so that i >= 'newSpaceDim', 'newSpaceDim'alloc(getCoords()->getNumberOfTuples(),newSpaceDim); - const double *oldc=getCoords()->getConstPointer(); - double *nc=newCoords->getPointer(); - int nbOfNodes=getNumberOfNodes(); - int dim=std::min(oldSpaceDim,newSpaceDim); - for(int i=0;isetName(getCoords()->getName().c_str()); - for(int i=0;isetInfoOnComponent(i,getCoords()->getInfoOnComponent(i).c_str()); + DataArrayDouble *newCoords=getCoords()->changeNbOfComponents(newSpaceDim,dftValue); setCoords(newCoords); newCoords->decrRef(); updateTime(); @@ -431,7 +436,7 @@ void MEDCouplingPointSet::tryToShareSameCoords(const MEDCouplingPointSet& other, throw INTERP_KERNEL::Exception("Current instance has no coords whereas other has !"); if(!other._coords) throw INTERP_KERNEL::Exception("Other instance has no coords whereas current has !"); - if(!_coords->isEqual(*other._coords,epsilon)) + if(!_coords->isEqualWithoutConsideringStr(*other._coords,epsilon)) throw INTERP_KERNEL::Exception("Coords are not the same !"); setCoords(other._coords); } diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index 21f56317e..687124fa8 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -50,7 +50,9 @@ namespace ParaMEDMEM DataArrayDouble *getCoordinatesAndOwner() const; void copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception); bool isEqual(const MEDCouplingMesh *other, double prec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const; bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const; + bool areCoordsEqualWithoutConsideringStr(const MEDCouplingPointSet& other, double prec) const; virtual DataArrayInt *mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes) = 0; DataArrayInt *buildPermArrayForMergeNode(int limitNodeId, double precision, bool& areNodesMerged, int& newNbOfNodes) const; void findCommonNodes(int limitNodeId, double prec, DataArrayInt *&comm, DataArrayInt *&commIndex) const; @@ -62,7 +64,7 @@ namespace ParaMEDMEM void rotate(const double *center, const double *vector, double angle); void translate(const double *vector); void scale(const double *point, double factor); - void changeSpaceDimension(int newSpaceDim) throw(INTERP_KERNEL::Exception); + void changeSpaceDimension(int newSpaceDim, double dftVal=0.) throw(INTERP_KERNEL::Exception); void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) = 0; void findNodesOnPlane(const double *pt, const double *vec, double eps, std::vector& nodes) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 95074ef82..c9c8a41d2 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -19,6 +19,7 @@ #include "MEDCouplingTimeDiscretization.hxx" #include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" #include #include @@ -139,6 +140,15 @@ bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization return _array->isEqual(*other->_array,prec); } +bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +{ + if(!areStrictlyCompatible(other)) + return false; + if(_array==other->_array) + return true; + return _array->isEqualWithoutConsideringStr(*other->_array,prec); +} + MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other, TypeOfTimeDiscretization type, bool deepCpy) const { @@ -260,20 +270,229 @@ void MEDCouplingTimeDiscretization::getArrays(std::vector& ar bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception) { - int dt,it; - double time1=getEndTime(dt,it)-_time_tolerance; - double time2=other->getStartTime(dt,it)+other->getTimeTolerance(); + int iteration,order; + double time1=getEndTime(iteration,order)-_time_tolerance; + double time2=other->getStartTime(iteration,order)+other->getTimeTolerance(); return time1<=time2; } bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception) { - int dt,it; - double time1=getEndTime(dt,it)+_time_tolerance; - double time2=other->getStartTime(dt,it)-other->getTimeTolerance(); + int iteration,order; + double time1=getEndTime(iteration,order)+_time_tolerance; + double time2=other->getStartTime(iteration,order)-other->getTimeTolerance(); return time1 arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->doublyContractedProduct(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->determinant(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->eigenValues(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->eigenVectors(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->inverse(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->trace(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->deviator(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->magnitude(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->maxPerTuple(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + ret->setArrays(arrays3,0); + return ret; +} + +void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception) +{ + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->changeNbOfComponents(newNbOfComp,dftValue); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + setArrays(arrays3,0); +} + +void MEDCouplingTimeDiscretization::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception) +{ + std::vector arrays; + getArrays(arrays); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays[j]->sortPerTuple(asc); + } +} + void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId) { std::vector arrays; @@ -408,6 +627,14 @@ bool MEDCouplingNoTimeLabel::isEqual(const MEDCouplingTimeDiscretization *other, return MEDCouplingTimeDiscretization::isEqual(other,prec); } +bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + return false; + return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); +} + MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const { const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); @@ -579,22 +806,22 @@ bool MEDCouplingNoTimeLabel::isStrictlyBefore(const MEDCouplingTimeDiscretizatio throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -double MEDCouplingNoTimeLabel::getStartTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) +double MEDCouplingNoTimeLabel::getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -double MEDCouplingNoTimeLabel::getEndTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) +double MEDCouplingNoTimeLabel::getEndTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -void MEDCouplingNoTimeLabel::setStartTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) +void MEDCouplingNoTimeLabel::setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -void MEDCouplingNoTimeLabel::setEndTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) +void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } @@ -604,32 +831,32 @@ void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *valu throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception) +void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy), - _time(other._time),_dt(other._dt),_it(other._it) + _time(other._time),_iteration(other._iteration),_order(other._order) { } -MEDCouplingWithTimeStep::MEDCouplingWithTimeStep():_time(0.),_dt(-1),_it(-1) +MEDCouplingWithTimeStep::MEDCouplingWithTimeStep():_time(0.),_iteration(-1),_order(-1) { } std::string MEDCouplingWithTimeStep::getStringRepr() const { std::ostringstream stream; - stream << REPR << " Time is defined by dt=" << _dt << " it=" << _it << " and time=" << _time << "."; + stream << REPR << " Time is defined by iteration=" << _iteration << " order=" << _order << " and time=" << _time << "."; return stream.str(); } void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); - tinyInfo.push_back(_dt); - tinyInfo.push_back(_it); + tinyInfo.push_back(_iteration); + tinyInfo.push_back(_order); } void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector& tinyInfo) const @@ -642,8 +869,8 @@ void MEDCouplingWithTimeStep::finishUnserialization(const std::vector& tiny { MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); _time=tinyInfoD[1]; - _dt=tinyInfoI[2]; - _it=tinyInfoI[3]; + _iteration=tinyInfoI[2]; + _order=tinyInfoI[3]; } bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretization *other) const @@ -675,22 +902,36 @@ bool MEDCouplingWithTimeStep::isEqual(const MEDCouplingTimeDiscretization *other const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) return false; - if(_dt!=otherC->_dt) + if(_iteration!=otherC->_iteration) return false; - if(_it!=otherC->_it) + if(_order!=otherC->_order) return false; if(std::fabs(_time-otherC->_time)>_time_tolerance) return false; return MEDCouplingTimeDiscretization::isEqual(other,prec); } +bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_iteration!=otherC->_iteration) + return false; + if(_order!=otherC->_order) + return false; + if(std::fabs(_time-otherC->_time)>_time_tolerance) + return false; + return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); +} + void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) { MEDCouplingTimeDiscretization::copyTinyAttrFrom(other); const MEDCouplingWithTimeStep& otherC=dynamic_cast(other); _time=otherC._time; - _dt=otherC._dt; - _it=otherC._it; + _iteration=otherC._iteration; + _order=otherC._order; } MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const @@ -897,9 +1138,9 @@ void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *val throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception) +void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception) { - if(_dt==dt && _it==it) + if(_iteration==iteration && _order==order) if(_array) _array->getTuple(eltId,value); else @@ -908,7 +1149,7 @@ void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int dt, int it, doub throw INTERP_KERNEL::Exception("No data on this discrete time."); } -MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval():_start_time(0.),_end_time(0.),_start_dt(-1),_end_dt(-1),_start_it(-1),_end_it(-1) +MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1) { } @@ -918,19 +1159,19 @@ void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscr const MEDCouplingConstOnTimeInterval& otherC=dynamic_cast(other); _start_time=otherC._start_time; _end_time=otherC._end_time; - _start_dt=otherC._start_dt; - _end_dt=otherC._end_dt; - _start_it=otherC._start_it; - _end_it=otherC._end_it; + _start_iteration=otherC._start_iteration; + _end_iteration=otherC._end_iteration; + _start_order=otherC._start_order; + _end_order=otherC._end_order; } void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); - tinyInfo.push_back(_start_dt); - tinyInfo.push_back(_start_it); - tinyInfo.push_back(_end_dt); - tinyInfo.push_back(_end_it); + tinyInfo.push_back(_start_iteration); + tinyInfo.push_back(_start_order); + tinyInfo.push_back(_end_iteration); + tinyInfo.push_back(_end_order); } void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector& tinyInfo) const @@ -945,23 +1186,23 @@ void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector(other); if(!otherC) return false; - if(_start_dt!=otherC->_start_dt) + if(_start_iteration!=otherC->_start_iteration) return false; - if(_start_it!=otherC->_start_it) + if(_start_order!=otherC->_start_order) return false; if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) return false; - if(_end_dt!=otherC->_end_dt) + if(_end_iteration!=otherC->_end_iteration) return false; - if(_end_it!=otherC->_end_it) + if(_end_order!=otherC->_end_order) return false; if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance) return false; return MEDCouplingTimeDiscretization::isEqual(other,prec); } +bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_start_iteration!=otherC->_start_iteration) + return false; + if(_start_order!=otherC->_start_order) + return false; + if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) + return false; + if(_end_iteration!=otherC->_end_iteration) + return false; + if(_end_order!=otherC->_end_order) + return false; + if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance) + return false; + return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); +} + void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception) { if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance) @@ -1042,9 +1303,9 @@ void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, doub throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception) +void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception) { - if(dt>=_start_dt && dt<=_end_dt) + if(iteration>=_start_iteration && iteration<=_end_iteration) if(_array) _array->getTuple(eltId,value); else @@ -1063,7 +1324,7 @@ void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const throw( if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance) { std::ostringstream stream; - stream << "The field is defined between times " << _start_time << " and " << _end_time << " with tolerance "; + stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance "; stream << _time_tolerance << " and trying to access on time = " << time; throw INTERP_KERNEL::Exception(stream.str().c_str()); } @@ -1237,8 +1498,8 @@ void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretiza MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy), _start_time(other._start_time),_end_time(other._end_time), - _start_dt(other._start_dt),_end_dt(other._end_dt), - _start_it(other._start_it),_end_it(other._end_it) + _start_iteration(other._start_iteration),_end_iteration(other._end_iteration), + _start_order(other._start_order),_end_order(other._end_order) { if(other._end_array) _end_array=other._end_array->performCpy(deepCpy); @@ -1259,10 +1520,10 @@ void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizati const MEDCouplingTwoTimeSteps& otherC=dynamic_cast(other); _start_time=otherC._start_time; _end_time=otherC._end_time; - _start_dt=otherC._start_dt; - _end_dt=otherC._end_dt; - _start_it=otherC._start_it; - _end_it=otherC._end_it; + _start_iteration=otherC._start_iteration; + _end_iteration=otherC._end_iteration; + _start_order=otherC._start_order; + _end_order=otherC._end_order; } void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other) @@ -1296,13 +1557,13 @@ bool MEDCouplingTwoTimeSteps::isEqual(const MEDCouplingTimeDiscretization *other const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(other); if(!otherC) return false; - if(_start_dt!=otherC->_start_dt) + if(_start_iteration!=otherC->_start_iteration) return false; - if(_end_dt!=otherC->_end_dt) + if(_end_iteration!=otherC->_end_iteration) return false; - if(_start_it!=otherC->_start_it) + if(_start_order!=otherC->_start_order) return false; - if(_end_it!=otherC->_end_it) + if(_end_order!=otherC->_end_order) return false; if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) return false; @@ -1314,7 +1575,30 @@ bool MEDCouplingTwoTimeSteps::isEqual(const MEDCouplingTimeDiscretization *other return MEDCouplingTimeDiscretization::isEqual(other,prec); } -MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_dt(-1),_end_dt(-1),_start_it(-1),_end_it(-1),_end_array(0) +bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +{ + const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_start_iteration!=otherC->_start_iteration) + return false; + if(_end_iteration!=otherC->_end_iteration) + return false; + if(_start_order!=otherC->_start_order) + return false; + if(_end_order!=otherC->_end_order) + return false; + if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) + return false; + if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance) + return false; + if(_end_array!=otherC->_end_array) + if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec)) + return false; + return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); +} + +MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1),_end_array(0) { } @@ -1334,7 +1618,7 @@ void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const throw(INTERP_ if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance) { std::ostringstream stream; - stream << "The field is defined between times " << _start_time << " and " << _end_time << " with tolerance "; + stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance "; stream << _time_tolerance << " and trying to access on time = " << time; throw INTERP_KERNEL::Exception(stream.str().c_str()); } @@ -1364,10 +1648,10 @@ void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *own void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); - tinyInfo.push_back(_start_dt); - tinyInfo.push_back(_start_it); - tinyInfo.push_back(_end_dt); - tinyInfo.push_back(_end_it); + tinyInfo.push_back(_start_iteration); + tinyInfo.push_back(_start_order); + tinyInfo.push_back(_end_iteration); + tinyInfo.push_back(_end_order); if(_end_array) { tinyInfo.push_back(_end_array->getNumberOfTuples()); @@ -1426,10 +1710,10 @@ void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector& tiny MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); _start_time=tinyInfoD[1]; _end_time=tinyInfoD[2]; - _start_dt=tinyInfoI[2]; - _start_it=tinyInfoI[3]; - _end_dt=tinyInfoI[4]; - _end_it=tinyInfoI[5]; + _start_iteration=tinyInfoI[2]; + _start_order=tinyInfoI[3]; + _end_iteration=tinyInfoI[4]; + _end_order=tinyInfoI[5]; } std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception) @@ -1450,7 +1734,7 @@ void MEDCouplingTwoTimeSteps::setArrays(const std::vector& ar if(arrays.size()!=2) throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::setArrays : number of arrays must be two."); setArray(arrays.front(),owner); - setArray(arrays.back(),owner); + setEndArray(arrays.back(),owner); } MEDCouplingLinearTime::MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCpy):MEDCouplingTwoTimeSteps(other,deepCpy) @@ -1464,8 +1748,8 @@ MEDCouplingLinearTime::MEDCouplingLinearTime() std::string MEDCouplingLinearTime::getStringRepr() const { std::ostringstream stream; - stream << REPR << " Time interval is defined by :\ndt_start=" << _start_dt << " it_start=" << _start_it << " and time_start=" << _start_time << "\n"; - stream << "dt_end=" << _end_dt << " it_end=" << _end_it << " and end_time=" << _end_time << "\n"; + stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n"; + stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n"; return stream.str(); } @@ -1537,21 +1821,21 @@ void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value std::transform(tmp.begin(),tmp.end(),value,value,std::plus()); } -void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception) +void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception) { - if(dt==_start_dt && it==_start_it) + if(iteration==_start_iteration && order==_start_order) { if(_array) _array->getTuple(eltId,value); else - throw INTERP_KERNEL::Exception("dt it match with start time but no start array existing."); + throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing."); } - if(dt==_end_dt && it==_end_it) + if(iteration==_end_iteration && order==_end_order) { if(_end_array) _end_array->getTuple(eltId,value); else - throw INTERP_KERNEL::Exception("dt it match with end time but no end array existing."); + throw INTERP_KERNEL::Exception("iteration order match with end time but no end array existing."); } else throw INTERP_KERNEL::Exception(EXCEPTION_MSG); diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 7c15d06d2..a9f1de097 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -47,6 +47,7 @@ namespace ParaMEDMEM virtual bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; virtual bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + virtual bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other, TypeOfTimeDiscretization type, bool deepCpy) const; virtual std::string getStringRepr() const = 0; @@ -84,21 +85,33 @@ namespace ParaMEDMEM virtual void getArrays(std::vector& arrays) const; virtual bool isBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception); virtual bool isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception); - double getTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { return getStartTime(dt,it); } - virtual double getStartTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) = 0; - virtual double getEndTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) = 0; - void setTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { setStartTime(time,dt,it); } - virtual void setStartTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) = 0; - virtual void setEndTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) = 0; + double getTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { return getStartTime(iteration,order); } + virtual double getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) = 0; + virtual double getEndTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) = 0; + void setTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { setStartTime(time,iteration,order); } + virtual void setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) = 0; + virtual void setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) = 0; virtual void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception) = 0; - virtual void getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception) = 0; + virtual void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception) = 0; // + virtual MEDCouplingTimeDiscretization *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *determinant() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *eigenValues() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *eigenVectors() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *inverse() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *trace() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *deviator() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *magnitude() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *maxPerTuple() const throw(INTERP_KERNEL::Exception); + virtual void changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception); + virtual void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); virtual void applyLin(double a, double b, int compoId); virtual void applyFunc(int nbOfComp, FunctionToEvaluate func); virtual void applyFunc(int nbOfComp, const char *func); virtual void applyFunc(const char *func); virtual void applyFuncFast32(const char *func); virtual void applyFuncFast64(const char *func); + // virtual ~MEDCouplingTimeDiscretization(); protected: @@ -129,6 +142,7 @@ namespace ParaMEDMEM MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; bool areCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; @@ -139,12 +153,12 @@ namespace ParaMEDMEM void getValueForTime(double time, const std::vector& vals, double *res) const; bool isBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception); bool isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception); - double getStartTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception); - double getEndTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception); - void setStartTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception); - void setEndTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception); + double getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception); + double getEndTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception); + void setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception); + void setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception); void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception); - void getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception); + void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception); public: static const TypeOfTimeDiscretization DISCRETIZATION=NO_TIME; static const char REPR[]; @@ -175,6 +189,7 @@ namespace ParaMEDMEM MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; bool areCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; @@ -184,14 +199,14 @@ namespace ParaMEDMEM MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const; void checkNoTimePresence() const throw(INTERP_KERNEL::Exception); void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception); - void setStartTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _time=time; _dt=dt; _it=it; } - void setEndTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _time=time; _dt=dt; _it=it; } - double getStartTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_dt; it=_it; return _time; } - double getEndTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_dt; it=_it; return _time; } + void setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _time=time; _iteration=iteration; _order=order; } + void setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _time=time; _iteration=iteration; _order=order; } + double getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { iteration=_iteration; order=_order; return _time; } + double getEndTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { iteration=_iteration; order=_order; return _time; } std::vector< const DataArrayDouble *> getArraysForTime(double time) const throw(INTERP_KERNEL::Exception); void getValueForTime(double time, const std::vector& vals, double *res) const; void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception); - void getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception); + void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception); public: static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME; static const char REPR[]; @@ -199,8 +214,8 @@ namespace ParaMEDMEM static const char EXCEPTION_MSG[]; protected: double _time; - int _dt; - int _it; + int _iteration; + int _order; }; class MEDCOUPLING_EXPORT MEDCouplingConstOnTimeInterval : public MEDCouplingTimeDiscretization @@ -218,10 +233,11 @@ namespace ParaMEDMEM bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; std::vector< const DataArrayDouble *> getArraysForTime(double time) const throw(INTERP_KERNEL::Exception); void getValueForTime(double time, const std::vector& vals, double *res) const; void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception); - void getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception); + void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception); TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } std::string getStringRepr() const; MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; @@ -237,10 +253,10 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); - void setStartTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _start_time=time; _start_dt=dt; _start_it=it; } - void setEndTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _end_time=time; _end_dt=dt; _end_it=it; } - double getStartTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_start_dt; it=_start_it; return _start_time; } - double getEndTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_end_dt; it=_end_it; return _end_time; } + void setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _start_time=time; _start_iteration=iteration; _start_order=order; } + void setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _end_time=time; _end_iteration=iteration; _end_order=order; } + double getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { iteration=_start_iteration; order=_start_order; return _start_time; } + double getEndTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { iteration=_end_iteration; order=_end_order; return _end_time; } void checkNoTimePresence() const throw(INTERP_KERNEL::Exception); void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception); public: @@ -251,10 +267,10 @@ namespace ParaMEDMEM protected: double _start_time; double _end_time; - int _start_dt; - int _end_dt; - int _start_it; - int _end_it; + int _start_iteration; + int _end_iteration; + int _start_order; + int _end_order; }; class MEDCOUPLING_EXPORT MEDCouplingTwoTimeSteps : public MEDCouplingTimeDiscretization @@ -270,14 +286,15 @@ namespace ParaMEDMEM DataArrayDouble *getEndArray() const; void checkCoherency() const throw(INTERP_KERNEL::Exception); bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; void checkNoTimePresence() const throw(INTERP_KERNEL::Exception); void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception); void getArrays(std::vector& arrays) const; void setEndArray(DataArrayDouble *array, TimeLabel *owner); - void setStartTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _start_time=time; _start_dt=dt; _start_it=it; } - void setEndTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _end_time=time; _end_dt=dt; _end_it=it; } - double getStartTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_start_dt; it=_start_it; return _start_time; } - double getEndTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_end_dt; it=_end_it; return _end_time; } + void setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _start_time=time; _start_iteration=iteration; _start_order=order; } + void setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _end_time=time; _end_iteration=iteration; _end_order=order; } + double getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { iteration=_start_iteration; order=_start_order; return _start_time; } + double getEndTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { iteration=_end_iteration; order=_end_order; return _end_time; } void getTinySerializationIntInformation(std::vector& tinyInfo) const; void getTinySerializationDbleInformation(std::vector& tinyInfo) const; void getTinySerializationStrInformation(std::vector& tinyInfo) const; @@ -290,10 +307,10 @@ namespace ParaMEDMEM protected: double _start_time; double _end_time; - int _start_dt; - int _end_dt; - int _start_it; - int _end_it; + int _start_iteration; + int _end_iteration; + int _start_order; + int _end_order; DataArrayDouble *_end_array; }; @@ -312,7 +329,7 @@ namespace ParaMEDMEM bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; void getValueForTime(double time, const std::vector& vals, double *res) const; void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception); - void getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception); + void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception); MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index e77d8bba4..e27fe875c 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -201,6 +201,32 @@ bool MEDCouplingUMesh::isEqual(const MEDCouplingMesh *other, double prec) const return true; } +bool MEDCouplingUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const +{ + const MEDCouplingUMesh *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(!MEDCouplingPointSet::isEqualWithoutConsideringStr(other,prec)) + return false; + if(_mesh_dim!=otherC->_mesh_dim) + return false; + if(_types!=otherC->_types) + return false; + if(_nodal_connec!=0 || otherC->_nodal_connec!=0) + if(_nodal_connec==0 || otherC->_nodal_connec==0) + return false; + if(_nodal_connec!=otherC->_nodal_connec) + if(!_nodal_connec->isEqualWithoutConsideringStr(*otherC->_nodal_connec)) + return false; + if(_nodal_connec_index!=0 || otherC->_nodal_connec_index!=0) + if(_nodal_connec_index==0 || otherC->_nodal_connec_index==0) + return false; + if(_nodal_connec_index!=otherC->_nodal_connec_index) + if(!_nodal_connec_index->isEqualWithoutConsideringStr(*otherC->_nodal_connec_index)) + return false; + return true; +} + /*! * This method looks if 'this' and 'other' are geometrically equivalent that is to say if each cell in 'other' correspond to one cell and only one * in 'this' is found regarding 'prec' parameter and 'cellCompPol' parameter. @@ -258,6 +284,47 @@ void MEDCouplingUMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int ce } } +/*! + * This method looks if 'this' and 'other' are geometrically equivalent that is to say if each cell in 'other' correspond to one cell and only one + * in 'this' is found regarding 'prec' parameter and 'cellCompPol' parameter. The difference with MEDCouplingUMesh::checkDeepEquivalWith method is that + * coordinates of 'this' and 'other' are expected to be the same. If not an exception will be thrown. + * + * In case of success cellCor are informed both. + * @param cellCompPol values are described in MEDCouplingUMesh::zipConnectivityTraducer method. + * @param cellCor output array giving the correspondance of cells from 'other' to 'this'. + */ +void MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception) +{ + const MEDCouplingUMesh *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("checkDeepEquivalOnSameNodesWith : Two meshes are not not unstructured !"); + MEDCouplingMesh::checkFastEquivalWith(other,prec); + if(_types!=otherC->_types) + throw INTERP_KERNEL::Exception("checkDeepEquivalOnSameNodesWith : Types are not equal !"); + if(_coords!=otherC->_coords) + throw INTERP_KERNEL::Exception("checkDeepEquivalOnSameNodesWith : meshes do not share the same coordinates ! Use tryToShareSameCoordinates or call checkDeepEquivalWith !"); + std::vector ms(2); + ms[0]=const_cast(this); + ms[1]=const_cast(otherC); + MEDCouplingAutoRefCountObjectPtr m=mergeUMeshesOnSameCoords(ms); + MEDCouplingAutoRefCountObjectPtr da=m->zipConnectivityTraducer(cellCompPol); + int maxId=*std::max_element(da->getConstPointer(),da->getConstPointer()+getNumberOfCells()); + const int *pt=std::find_if(da->getConstPointer()+getNumberOfCells(),da->getConstPointer()+da->getNbOfElems(),std::bind2nd(std::greater(),maxId)); + if(pt!=da->getConstPointer()+da->getNbOfElems()) + { + throw INTERP_KERNEL::Exception("checkDeepEquivalOnSameNodesWith : some cells in other are not in this !"); + } + cellCor=DataArrayInt::New(); + cellCor->alloc(otherC->getNumberOfCells(),1); + std::copy(da->getConstPointer()+getNumberOfCells(),da->getConstPointer()+da->getNbOfElems(),cellCor->getPointer()); + if(cellCor->isIdentity()) + { + cellCor->decrRef(); + cellCor=0; + } +} + /*! * This method checks fastly that 'this' and 'other' are equal. */ diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index ee3cb8b19..0d06ef235 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -38,8 +38,11 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void updateTime(); MEDCOUPLING_EXPORT MEDCouplingMeshType getType() const { return UNSTRUCTURED; } MEDCOUPLING_EXPORT bool isEqual(const MEDCouplingMesh *other, double prec) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const; MEDCOUPLING_EXPORT void checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkCoherency() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setMeshDimension(int meshDim); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 5fb8072db..f45cd5eba 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -82,6 +82,12 @@ void MEDCouplingUMeshDesc::checkDeepEquivalWith(const MEDCouplingMesh *other, in throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::checkDeepEquivalWith : not implemented yet !"); } +void MEDCouplingUMeshDesc::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::checkDeepEquivalOnSameNodesWith : not implemented yet !"); +} + void MEDCouplingUMeshDesc::setMeshDimension(unsigned meshDim) { _mesh_dim=meshDim; diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index 7c1648e47..7c965a31c 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -37,6 +37,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void checkCoherency() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, + DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setMeshDimension(unsigned meshDim); MEDCOUPLING_EXPORT int getNumberOfCells() const; MEDCOUPLING_EXPORT int getNumberOfFaces() const; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 23deef32e..ad916caa0 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -111,6 +111,18 @@ namespace ParaMEDMEM CPPUNIT_TEST( testApplyLin1 ); CPPUNIT_TEST( testGetIdsInRange1 ); CPPUNIT_TEST( testBuildSubPart1 ); + CPPUNIT_TEST( testDoublyContractedProduct1 ); + CPPUNIT_TEST( testDeterminant1 ); + CPPUNIT_TEST( testEigenValues1 ); + CPPUNIT_TEST( testEigenVectors1 ); + CPPUNIT_TEST( testInverse1 ); + CPPUNIT_TEST( testTrace1 ); + CPPUNIT_TEST( testDeviator1 ); + CPPUNIT_TEST( testMagnitude1 ); + CPPUNIT_TEST( testMaxPerTuple1 ); + CPPUNIT_TEST( testChangeNbOfComponents ); + CPPUNIT_TEST( testSortPerTuple1 ); + CPPUNIT_TEST( testIsEqualWithoutConsideringStr1 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -250,6 +262,18 @@ namespace ParaMEDMEM void testApplyLin1(); void testGetIdsInRange1(); void testBuildSubPart1(); + void testDoublyContractedProduct1(); + void testDeterminant1(); + void testEigenValues1(); + void testEigenVectors1(); + void testInverse1(); + void testTrace1(); + void testDeviator1(); + void testMagnitude1(); + void testMaxPerTuple1(); + void testChangeNbOfComponents(); + void testSortPerTuple1(); + void testIsEqualWithoutConsideringStr1(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index eca5b836e..a36e06349 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -1395,3 +1395,568 @@ void MEDCouplingBasicsTest::testBuildSubPart1() f1->decrRef(); mesh1->decrRef(); } + +void MEDCouplingBasicsTest::testDoublyContractedProduct1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),6); + const double arr1[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5}; + std::copy(arr1,arr1+30,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->doublyContractedProduct(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(3906.56,f2->getIJ(i,0),1e-9); + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testDeterminant1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL); + f1->setTime(2.3,5,6); + f1->setEndTime(3.8,7,3); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),4); + const double arr1[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5}; + std::copy(arr1,arr1+20,array->getPointer()); + f1->setArray(array); + array->decrRef(); + //4 components + f1->checkCoherency(); + MEDCouplingFieldDouble *f2=f1->determinant(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(CONST_ON_TIME_INTERVAL,f2->getTimeDiscretization()); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfValues()); + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.42,f2->getIJ(i,0),1e-13); + f2->decrRef(); + f1->decrRef(); + //6 components multi arrays with end array not defined + f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME); + f1->setTime(2.3,5,6); + f1->setEndTime(3.8,7,3); + f1->setMesh(mesh1); + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfNodes(),6); + const double arr2[54]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, + 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7}; + std::copy(arr2,arr2+54,array->getPointer()); + f1->setArray(array); + array->decrRef(); + CPPUNIT_ASSERT_THROW(f1->checkCoherency(),INTERP_KERNEL::Exception);//no end array specified ! + // + f2=f1->determinant(); + CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization()); + CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples()); + for(int i=0;i<9;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10); + f2->decrRef(); + //6 components multi arrays with end array defined + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfNodes(),6); + const double arr3[54]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, + 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5}; + std::copy(arr3,arr3+54,array->getPointer()); + f1->setEndArray(array); + array->decrRef(); + f1->checkCoherency(); + f2=f1->determinant(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization()); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples()); + int it,order; + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(it,order),1e-12); + CPPUNIT_ASSERT_EQUAL(5,it); CPPUNIT_ASSERT_EQUAL(6,order); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.8,f2->getEndTime(it,order),1e-12); + CPPUNIT_ASSERT_EQUAL(7,it); CPPUNIT_ASSERT_EQUAL(3,order); + for(int i=0;i<9;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1289.685,f2->getEndArray()->getIJ(i,0),1e-9); + } + f2->decrRef(); + f1->decrRef(); + //9 components + f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setTime(7.8,10,2); + f1->setMesh(mesh1); + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),9); + const double arr4[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1}; + std::copy(arr4,arr4+45,array->getPointer()); + f1->setArray(array); + array->decrRef(); + // + f1->checkCoherency(); + f2=f1->determinant(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(ONE_TIME,f2->getTimeDiscretization()); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8,f2->getTime(it,order),1e-12); + CPPUNIT_ASSERT_EQUAL(10,it); CPPUNIT_ASSERT_EQUAL(2,order); + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.267,f2->getIJ(i,0),1e-13); + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testEigenValues1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),6); + const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7}; + std::copy(arr1,arr1+30,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->eigenValues(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + const double expected1[3]={13.638813677891717,-4.502313844635971,-2.2364998332557486}; + for(int i=0;i<5;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13); + } + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testEigenVectors1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),6); + const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7}; + std::copy(arr1,arr1+30,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->eigenVectors(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + const double expected1[9]={ + 0.5424262364180696, 0.5351201064614425, 0.6476266283176001,//eigenvect 0 + 0.7381111277307373, 0.06458838384003074, -0.6715804522117897,//eigenvect 1 + -0.4012053603397987, 0.8423032781211455, -0.3599436712889738//eigenvect 2 + }; + for(int i=0;i<5;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13); + } + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testInverse1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),9); + const double arr1[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1}; + std::copy(arr1,arr1+45,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->inverse(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + const double expected1[9]={-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072}; + for(int i=0;i<5;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13); + } + f2->decrRef(); + // + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),6); + const double arr3[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5}; + std::copy(arr3,arr3+30,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + f2=f1->inverse(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + const double expected3[6]={-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887}; + for(int i=0;i<5;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f2->getIJ(i,0),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f2->getIJ(i,1),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f2->getIJ(i,2),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[3],f2->getIJ(i,3),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[4],f2->getIJ(i,4),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[5],f2->getIJ(i,5),1e-13); + } + f2->decrRef(); + // + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),4); + const double arr2[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5}; + std::copy(arr2,arr2+20,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + f2=f1->inverse(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + const double expected2[4]={-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156}; + for(int i=0;i<5;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[0],f2->getIJ(i,0),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[1],f2->getIJ(i,1),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[2],f2->getIJ(i,2),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[3],f2->getIJ(i,3),1e-13); + } + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testTrace1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),9); + const double arr1[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1}; + std::copy(arr1,arr1+45,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->trace(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(15.9,f2->getIJ(i,0),1e-13); + f2->decrRef(); + // + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),6); + const double arr3[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5}; + std::copy(arr3,arr3+30,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + f2=f1->trace(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(25.8,f2->getIJ(i,0),1e-13); + f2->decrRef(); + // + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),4); + const double arr2[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5}; + std::copy(arr2,arr2+20,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + f2=f1->trace(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(5.7,f2->getIJ(i,0),1e-13); + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testDeviator1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),6); + const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7}; + std::copy(arr1,arr1+30,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->deviator(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + const double expected1[6]={-1.1,0.,1.1,4.5,5.6,6.7}; + for(int i=0;i<5;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13); + } + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testMagnitude1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),5); + const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6}; + std::copy(arr1,arr1+25,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->magnitude(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(8.3606219864313918,f2->getIJ(i,0),1e-13); + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testMaxPerTuple1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),5); + const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4}; + std::copy(arr1,arr1+25,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->maxPerTuple(); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(5.6,f2->getIJ(i,0),1e-13); + f2->decrRef(); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testChangeNbOfComponents() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),5); + const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4}; + std::copy(arr1,arr1+25,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + f1->changeNbOfComponents(3,7.77); + f1->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(3,f1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples()); + const double expected1[15]={1.2,2.3,3.4, 1.2,3.4,4.5, 3.4,4.5,5.6, 5.6,1.2,2.3, 4.5,5.6,1.2}; + for(int i=0;i<15;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-13); + f1->changeNbOfComponents(4,7.77); + f1->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(4,f1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples()); + const double expected2[20]={1.2,2.3,3.4,7.77, 1.2,3.4,4.5,7.77, 3.4,4.5,5.6,7.77, 5.6,1.2,2.3,7.77, 4.5,5.6,1.2,7.77}; + for(int i=0;i<20;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-13); + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testSortPerTuple1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),5); + const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4}; + std::copy(arr1,arr1+25,array->getPointer()); + f1->setArray(array); + array->decrRef(); + f1->checkCoherency(); + // + f1->sortPerTuple(true); + f1->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples()); + for(int i=0;i<5;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,0),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,1),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,3),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,4),1e-13); + } + // + f1->sortPerTuple(false); + f1->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples()); + for(int i=0;i<5;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,0),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,1),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,3),1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,4),1e-13); + } + // + mesh1->decrRef(); + f1->decrRef(); +} + +void MEDCouplingBasicsTest::testIsEqualWithoutConsideringStr1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_1(); + MEDCouplingUMesh *mesh2=build2DTargetMesh_1(); + DataArrayInt *da1,*da2; + // + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2->setName("rr"); + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh1->checkDeepEquivalWith(mesh2,2,1e-12,da1,da2); + CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,da1,da2),INTERP_KERNEL::Exception); + mesh2->setName(""); + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2->getCoords()->setInfoOnComponent(0,"tty"); + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2->getCoords()->setInfoOnComponent(0,""); + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2->getCoords()->setInfoOnComponent(1,"tty"); + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2->getCoords()->setInfoOnComponent(1,""); + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + double tmp=mesh2->getCoords()->getIJ(0,3); + mesh2->getCoords()->setIJ(0,3,9999.); + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2->getCoords()->setIJ(0,3,tmp); + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + int tmp2=mesh2->getNodalConnectivity()->getIJ(0,4); + mesh2->getNodalConnectivity()->setIJ(0,4,0); + CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2->getNodalConnectivity()->setIJ(0,4,tmp2); + CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12)); + CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12)); + // + MEDCouplingFieldDouble *f1=mesh1->getMeasureField(true); + MEDCouplingFieldDouble *f2=mesh2->getMeasureField(true); + CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); + CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + f2->setName("ftest"); + CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12)); + CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + f1->setName("ftest"); + CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); + CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + // + f2->getArray()->setInfoOnComponent(0,"eee"); + CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12)); + CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + f2->getArray()->setInfoOnComponent(0,""); + CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); + CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + // + f2->getArray()->setIJ(1,0,0.123); + CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12)); + CPPUNIT_ASSERT(!f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + f2->getArray()->setIJ(1,0,0.125); + CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); + CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + // + f1->decrRef(); + f2->decrRef(); + // + mesh1->decrRef(); + mesh2->decrRef(); +} -- 2.39.2