From: ageay Date: Mon, 1 Feb 2010 15:38:52 +0000 (+0000) Subject: Addition of operations on fields and CONST_ON_INTER policy for Time discretization. X-Git-Tag: V5_1_main_FINAL~236 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8d28d4e8820fdd95d27409019b02038093d66625;p=tools%2Fmedcoupling.git Addition of operations on fields and CONST_ON_INTER policy for Time discretization. --- diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 462fd9896..34c3f3c8e 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -125,14 +125,7 @@ int MEDCouplingCMesh::getSpaceDimension() const int MEDCouplingCMesh::getMeshDimension() const { - int ret=0; - if(_x_array) - ret++; - if(_y_array) - ret++; - if(_z_array) - ret++; - return ret; + return getSpaceDimension(); } DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) const throw(INTERP_KERNEL::Exception) @@ -204,3 +197,45 @@ MEDCouplingMesh *MEDCouplingCMesh::mergeMyselfWith(const MEDCouplingMesh *other) //not implemented yet ! return 0; } + +DataArrayDouble *MEDCouplingCMesh::getCoordinatesAndOwner() const +{ + DataArrayDouble *ret=DataArrayDouble::New(); + int spaceDim=getSpaceDimension(); + ret->alloc(getNumberOfNodes(),spaceDim); + double *pt=ret->getPointer(); + int pos=0; + int nbOfElem; + const double *cptr; + DataArrayDouble *tabs[3]={_x_array,_y_array,_z_array}; + for(int j=0;j<3;j++) + { + nbOfElem=tabs[j]->getNbOfElems(); + cptr=tabs[j]->getConstPointer(); + for(int i=0;ialloc(getNumberOfCells(),spaceDim); + DataArrayDouble *tabs[3]={_x_array,_y_array,_z_array}; + double *pt=ret->getPointer(); + int pos=0; + int nbOfElem; + const double *cptr; + for(int j=0;j<3;j++) + { + nbOfElem=tabs[j]->getNbOfElems()-1; + cptr=tabs[j]->getConstPointer(); + for(int i=0;igetCoords(); + DataArrayDouble *arr1D=_mesh1D->getCoords(); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(getNumberOfNodes(),3); + int nbOf1DLev=_mesh1D->getNumberOfNodes(); + int nbOf2DNodes=_mesh2D->getNumberOfNodes(); + const double *ptSrc=arr2D->getConstPointer(); + double *pt=ret->getPointer(); + std::copy(ptSrc,ptSrc+3*nbOf2DNodes,pt); + for(int i=1;igetConstPointer()+3*i,arr1D->getConstPointer()+3*(i+1),vec); + std::transform(arr1D->getConstPointer()+3*(i-1),arr1D->getConstPointer()+3*i,vec,vec,std::minus()); + for(int j=0;j()); + } + return ret; +} + +DataArrayDouble *MEDCouplingExtrudedMesh::getBarycenterAndOwner() const +{ + //not yet implemented + return 0; +} + void MEDCouplingExtrudedMesh::computeExtrusionAlg(MEDCouplingUMesh *mesh3D) throw(INTERP_KERNEL::Exception) { _mesh3D_ids->alloc(mesh3D->getNumberOfCells(),1); @@ -336,4 +366,3 @@ void MEDCouplingExtrudedMesh::computeExtrusionAlg(MEDCouplingUMesh *mesh3D) thro revDesc->decrRef(); revDescIndx->decrRef(); } - diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 1c68d3dba..5b6f0ede5 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -52,6 +52,8 @@ namespace ParaMEDMEM void rotate(const double *center, const double *vector, double angle); void translate(const double *vector); MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const; + DataArrayDouble *getCoordinatesAndOwner() const; + DataArrayDouble *getBarycenterAndOwner() const; private: MEDCouplingExtrudedMesh(MEDCouplingUMesh *mesh3D, MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception); void computeExtrusion(MEDCouplingUMesh *mesh3D) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 44eed3688..1a69a792e 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -81,6 +81,11 @@ int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *m return mesh->getNumberOfCells(); } +DataArrayDouble *MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const +{ + return mesh->getBarycenterAndOwner(); +} + void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) { } @@ -142,6 +147,11 @@ int MEDCouplingFieldDiscretizationP1::getNumberOfTuples(const MEDCouplingMesh *m return mesh->getNumberOfNodes(); } +DataArrayDouble *MEDCouplingFieldDiscretizationP1::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const +{ + return mesh->getCoordinatesAndOwner(); +} + void MEDCouplingFieldDiscretizationP1::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) { if(nat!=ConservativeVolumic) diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 41b332779..8e7c054ec 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -41,6 +41,7 @@ namespace ParaMEDMEM virtual MEDCouplingFieldDiscretization *clone() const = 0; virtual const char *getStringRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const = 0; + virtual DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const = 0; virtual void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) = 0; virtual void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) = 0; virtual MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh, bool isAbs) const = 0; @@ -55,6 +56,7 @@ namespace ParaMEDMEM const char *getStringRepr() const; bool isEqual(const MEDCouplingFieldDiscretization *other) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; + DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh, bool isAbs) const; @@ -72,6 +74,7 @@ namespace ParaMEDMEM const char *getStringRepr() const; bool isEqual(const MEDCouplingFieldDiscretization *other) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; + DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getWeightingField(const MEDCouplingMesh *mesh, bool isAbs) const; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 9fefb23f8..ccee3ab30 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -35,6 +35,16 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const return new MEDCouplingFieldDouble(*this,recDeepCpy); } +MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const +{ + MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(_time_discr,td,deepCpy); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),tdo,getTypeOfField()); + ret->setMesh(getMesh()); + ret->setName(getName()); + ret->setDescription(getDescription()); + return ret; +} + bool MEDCouplingFieldDouble::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const { const MEDCouplingFieldDouble *otherC=dynamic_cast(other); @@ -134,12 +144,12 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, dou void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId) { - double *ptr=getArray()->getPointer(); - ptr+=compoId; - int nbOfComp=getArray()->getNumberOfComponents(); - int nbOfTuple=getArray()->getNumberOfTuples(); - for(int i=0;iapplyLin(a,b,compoId); +} + +void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) +{ + _time_discr->applyFunc(nbOfComp,func); } int MEDCouplingFieldDouble::getNumberOfComponents() const @@ -250,3 +260,51 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const MEDCouplingFie ret->setDescription(f1->getDescription()); return ret; } + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +{ + if(!f1->areCompatible(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply addFields on them !"); + if(f1->getMesh()!=f2->getMesh()) + throw INTERP_KERNEL::Exception("Fields are not lying on same mesh ; addFields impossible !"); + MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + ret->setMesh(f1->getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::substractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +{ + if(!f1->areCompatible(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply substractFields on them !"); + if(f1->getMesh()!=f2->getMesh()) + throw INTERP_KERNEL::Exception("Fields are not lying on same mesh ; substractFields impossible !"); + MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + ret->setMesh(f1->getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +{ + if(!f1->areCompatible(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to applymultiplyFields on them !"); + if(f1->getMesh()!=f2->getMesh()) + throw INTERP_KERNEL::Exception("Fields are not lying on same mesh ; multiplyFields impossible !"); + MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + ret->setMesh(f1->getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +{ + if(!f1->areCompatible(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply divideFields on them !"); + if(f1->getMesh()!=f2->getMesh()) + throw INTERP_KERNEL::Exception("Fields are not lying on same mesh ; divideFields impossible !"); + MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField()); + ret->setMesh(f1->getMesh()); + return ret; +} diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index ae808dfb5..175db4479 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -34,6 +34,7 @@ namespace ParaMEDMEM bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; bool areCompatible(const MEDCouplingField *other) const; MEDCouplingFieldDouble *clone(bool recDeepCpy) const; + MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const; TypeOfTimeDiscretization getTimeDiscretization() const; void checkCoherency() const throw(INTERP_KERNEL::Exception); NatureOfField getNature() const { return _nature; } @@ -49,6 +50,7 @@ namespace ParaMEDMEM void getValueOn(const double *spaceLoc, double time, double *res) const throw(INTERP_KERNEL::Exception); //! \b temporary void applyLin(double a, double b, int compoId); + void applyFunc(int nbOfComp, FunctionToEvaluate func); int getNumberOfComponents() const; int getNumberOfTuples() const throw(INTERP_KERNEL::Exception); void updateTime(); @@ -60,6 +62,14 @@ namespace ParaMEDMEM void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); void serialize(std::vector& arrays) const; static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const { return addFields(this,&other); } + static MEDCouplingFieldDouble *addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const { return substractFields(this,&other); } + static MEDCouplingFieldDouble *substractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const { return multiplyFields(this,&other); } + static MEDCouplingFieldDouble *multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const { return divideFields(this,&other); } + static MEDCouplingFieldDouble *divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); private: MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 9e76b04a4..b4484216c 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -105,6 +105,15 @@ void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType declareAsNew(); } +void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception) +{ + const double *tmp=getConstPointer(); + int nbOfElems=getNbOfElems(); + const double *where=std::find(tmp,tmp+nbOfElems,0.); + if(where!=tmp+nbOfElems) + throw INTERP_KERNEL::Exception("A value 0.0 have been detected !"); +} + DataArrayDouble *DataArrayDouble::aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) { int nbOfComp=a1->getNumberOfComponents(); @@ -120,6 +129,66 @@ DataArrayDouble *DataArrayDouble::aggregate(const DataArrayDouble *a1, const Dat return ret; } +DataArrayDouble *DataArrayDouble::add(const DataArrayDouble *a1, const DataArrayDouble *a2) +{ + int nbOfComp=a1->getNumberOfComponents(); + if(nbOfComp!=a2->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Nb of components mismatch for array add !"); + int nbOfTuple=a1->getNumberOfTuples(); + if(nbOfTuple!=a2->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array add !"); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::plus()); + ret->copyStringInfoFrom(*a1); + return ret; +} + +DataArrayDouble *DataArrayDouble::substract(const DataArrayDouble *a1, const DataArrayDouble *a2) +{ + int nbOfComp=a1->getNumberOfComponents(); + if(nbOfComp!=a2->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Nb of components mismatch for array substract !"); + int nbOfTuple=a1->getNumberOfTuples(); + if(nbOfTuple!=a2->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array substract !"); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::minus()); + ret->copyStringInfoFrom(*a1); + return ret; +} + +DataArrayDouble *DataArrayDouble::multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) +{ + int nbOfComp=a1->getNumberOfComponents(); + if(nbOfComp!=a2->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Nb of components mismatch for array multiply !"); + int nbOfTuple=a1->getNumberOfTuples(); + if(nbOfTuple!=a2->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array multiply !"); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::multiplies()); + ret->copyStringInfoFrom(*a1); + return ret; +} + +DataArrayDouble *DataArrayDouble::divide(const DataArrayDouble *a1, const DataArrayDouble *a2) +{ + int nbOfComp=a1->getNumberOfComponents(); + if(nbOfComp!=a2->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Nb of components mismatch for array divide !"); + int nbOfTuple=a1->getNumberOfTuples(); + if(nbOfTuple!=a2->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array divide !"); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::divides()); + ret->copyStringInfoFrom(*a1); + return ret; +} + DataArrayInt *DataArrayInt::New() { return new DataArrayInt; diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index c20846893..89e042596 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -118,7 +118,12 @@ namespace ParaMEDMEM const double *getConstPointer() const { return _mem.getConstPointer(); } void useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } + void checkNoNullValues() const throw(INTERP_KERNEL::Exception); static DataArrayDouble *aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2); + static DataArrayDouble *add(const DataArrayDouble *a1, const DataArrayDouble *a2); + static DataArrayDouble *substract(const DataArrayDouble *a1, const DataArrayDouble *a2); + static DataArrayDouble *multiply(const DataArrayDouble *a1, const DataArrayDouble *a2); + static DataArrayDouble *divide(const DataArrayDouble *a1, const DataArrayDouble *a2); //! nothing to do here because this class does not aggregate any TimeLabel instance. void updateTime() { } private: diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index c757fa8f4..2b2f0ea5f 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -17,6 +17,12 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "MEDCouplingMesh.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldDiscretization.hxx" + +#include +#include using namespace ParaMEDMEM; @@ -28,3 +34,39 @@ bool MEDCouplingMesh::areCompatible(const MEDCouplingMesh *other) const return false; return true; } + +MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, FunctionToEvaluate func) const +{ + MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(t); + ret->setMesh(this); + DataArrayDouble *loc=ret->getDiscretization()->getLocalizationOfDiscValues(this); + DataArrayDouble *array=DataArrayDouble::New(); + int nbOfTuple=loc->getNumberOfTuples(); + int nbCompIn=loc->getNumberOfComponents(); + const double *locPtr=loc->getConstPointer(); + array->alloc(nbOfTuple,nbOfComp); + double *ptToFill=array->getPointer(); + for(int i=0;i(oss,", ")); + oss << ") : Evaluation of function failed !"; + loc->decrRef(); + array->decrRef(); + ret->decrRef(); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ptToFill+=nbOfComp; + } + loc->decrRef(); + ret->setArray(array); + array->decrRef(); + return ret; +} + +MEDCouplingMesh *MEDCouplingMesh::mergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) +{ + return mesh1->mergeMyselfWith(mesh2); +} diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 33d510d22..f49496d6d 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -34,6 +34,7 @@ namespace ParaMEDMEM EXTRUDED = 8 } MEDCouplingMeshType; + class DataArrayDouble; class MEDCouplingFieldDouble; class MEDCOUPLING_EXPORT MEDCouplingMesh : public RefCountObject, public TimeLabel @@ -49,13 +50,17 @@ namespace ParaMEDMEM virtual int getNumberOfNodes() const = 0; virtual int getSpaceDimension() const = 0; virtual int getMeshDimension() const = 0; + virtual DataArrayDouble *getCoordinatesAndOwner() const = 0; + virtual DataArrayDouble *getBarycenterAndOwner() const = 0; // tools virtual void getBoundingBox(double *bbox) const = 0; virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0; + virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, FunctionToEvaluate func) const; virtual void rotate(const double *center, const double *vector, double angle) = 0; virtual void translate(const double *vector) = 0; virtual MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const = 0; virtual bool areCompatible(const MEDCouplingMesh *other) const; + static MEDCouplingMesh *mergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2); protected: MEDCouplingMesh() { } MEDCouplingMesh(const MEDCouplingMesh& other):_name(other._name) { } diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index a887f965b..7067390a3 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -89,6 +89,13 @@ void MEDCouplingPointSet::setCoords(DataArrayDouble *coords) } } +DataArrayDouble *MEDCouplingPointSet::getCoordinatesAndOwner() const +{ + if(_coords) + _coords->incrRef(); + return _coords; +} + bool MEDCouplingPointSet::areCoordsEqual(const MEDCouplingPointSet& other, double prec) const { if(_coords==0 && other._coords==0) diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index 74e6ad623..9608d220e 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -42,6 +42,7 @@ namespace ParaMEDMEM int getSpaceDimension() const; void setCoords(DataArrayDouble *coords); DataArrayDouble *getCoords() const { return _coords; } + DataArrayDouble *getCoordinatesAndOwner() const; bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const; virtual DataArrayInt *mergeNodes(double precision, bool& areNodesMerged) = 0; void findCommonNodes(DataArrayInt *&comm, DataArrayInt *&commIndex, double prec) const; diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.hxx b/src/MEDCoupling/MEDCouplingRefCountObject.hxx index d6ec6da01..08b2defad 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.hxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.hxx @@ -39,9 +39,12 @@ namespace ParaMEDMEM { NO_TIME = 4, ONE_TIME = 5, - LINEAR_TIME = 6 + LINEAR_TIME = 6, + CONST_ON_TIME_INTERVAL = 7 } TypeOfTimeDiscretization; + typedef bool (*FunctionToEvaluate)(const double *pos, double *res); + class MEDCOUPLING_EXPORT RefCountObject { protected: diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 93042e671..dbc0dc5f6 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -20,6 +20,7 @@ #include "MEDCouplingMemArray.hxx" #include +#include using namespace ParaMEDMEM; @@ -27,6 +28,8 @@ const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setT const char MEDCouplingWithTimeStep::EXCEPTION_MSG[]="No data on this time."; +const char MEDCouplingConstOnTimeInterval::EXCEPTION_MSG[]="No data on this time."; + const double MEDCouplingTimeDiscretization::TIME_TOLERANCE_DFT=1.e-12; MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDiscretization type) @@ -37,6 +40,8 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDisc return new MEDCouplingNoTimeLabel; case MEDCouplingWithTimeStep::DISCRETIZATION: return new MEDCouplingWithTimeStep; + case MEDCouplingConstOnTimeInterval::DISCRETIZATION: + return new MEDCouplingConstOnTimeInterval; default: throw INTERP_KERNEL::Exception("Time discretization not implemented yet"); } @@ -50,6 +55,8 @@ bool MEDCouplingTimeDiscretization::areCompatible(const MEDCouplingTimeDiscretiz return true; if(_array==0 || other->_array==0) return false; + if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents()) + return false; return true; } @@ -62,6 +69,21 @@ bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization return _array->isEqual(*other->_array,prec); } +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other, + TypeOfTimeDiscretization type, bool deepCpy) const +{ + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(type); + DataArrayDouble *arrSrc=getArray(); + DataArrayDouble *arr=0; + if(arrSrc) + arr=arrSrc->performCpy(deepCpy); + else + arr=0; + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector& tinyInfo) const { if(_array) @@ -172,6 +194,38 @@ bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscre return time1getPointer()+compoId; + int nbOfComp=_array->getNumberOfComponents(); + int nbOfTuple=_array->getNumberOfTuples(); + for(int i=0;igetNumberOfTuples(); + int oldNbOfComp=_array->getNumberOfComponents(); + newArr->alloc(nbOfTuples,nbOfComp); + const double *ptr=_array->getConstPointer(); + double *ptrToFill=newArr->getPointer(); + for(int i=0;i(oss,", ")); + oss << ") : Evaluation of function failed !"; + newArr->decrRef(); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + _array->decrRef(); + _array=newArr; +} + MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel() { } @@ -209,6 +263,54 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCoupli return ret; } +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("add on mismatched time discretization !"); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("substract on mismatched time discretization !"); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !"); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + DataArrayDouble *arr=DataArrayDouble::multiply(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("divide on mismatched time discretization !"); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + DataArrayDouble *arr=DataArrayDouble::divide(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCpy(bool deepCpy) const { return new MEDCouplingNoTimeLabel(*this,deepCpy); @@ -299,7 +401,9 @@ bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretization if(!MEDCouplingTimeDiscretization::areCompatible(other)) return false; const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); - return otherC!=0; + if(!otherC) + return false; + return std::fabs(_time-otherC->_time)<_time_tolerance; } bool MEDCouplingWithTimeStep::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const @@ -332,6 +436,66 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCoupl return ret; } +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("add on mismatched time discretization !"); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("substract on mismatched time discretization !"); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !"); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + DataArrayDouble *arr=DataArrayDouble::multiply(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("divide on mismatched time discretization !"); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + DataArrayDouble *arr=DataArrayDouble::divide(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + return ret; +} + MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCpy(bool deepCpy) const { return new MEDCouplingWithTimeStep(*this,deepCpy); @@ -386,6 +550,208 @@ 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) +{ +} + +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); +} + +void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector& tinyInfo) const +{ + MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo); + tinyInfo.push_back(_start_time); + tinyInfo.push_back(_end_time); +} + +void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) +{ + MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); + _start_time=tinyInfoD[1]; + _end_time=tinyInfoD[2]; + _start_dt=tinyInfoI[2]; + _start_it=tinyInfoI[3]; + _end_dt=tinyInfoI[4]; + _end_it=tinyInfoI[5]; +} + +MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& 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) +{ +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCpy(bool deepCpy) const +{ + return new MEDCouplingConstOnTimeInterval(*this,deepCpy); +} + +DataArrayDouble *MEDCouplingConstOnTimeInterval::getArrayOnTime(double time) const throw(INTERP_KERNEL::Exception) +{ + if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance) + { + if(_array) + _array->incrRef(); + return _array; + } + else + throw INTERP_KERNEL::Exception(EXCEPTION_MSG); +} + +bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areCompatible(other)) + return false; + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + return false; + return (std::fabs(_start_time-otherC->_start_time)<_time_tolerance && std::fabs(_end_time-otherC->_end_time)<_time_tolerance); +} + +bool MEDCouplingConstOnTimeInterval::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_start_dt!=otherC->_start_dt) + return false; + if(_start_it!=otherC->_start_it) + return false; + if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) + return false; + return MEDCouplingTimeDiscretization::isEqual(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) + if(_array) + _array->getTuple(eltId,value); + else + throw INTERP_KERNEL::Exception("No array existing."); + else + throw INTERP_KERNEL::Exception(EXCEPTION_MSG); +} + +void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception) +{ + if(dt>=_start_dt && dt<=_end_dt) + if(_array) + _array->getTuple(eltId,value); + else + throw INTERP_KERNEL::Exception("No array existing."); + else + throw INTERP_KERNEL::Exception(EXCEPTION_MSG); +} + +void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("No time specified on a field defined as constant on one time interval"); +} + +void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception) +{ + 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 << _time_tolerance << " and trying to access on time = " << time; + throw INTERP_KERNEL::Exception(stream.str().c_str()); + } +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("aggregation on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + ret->setTimeTolerance(getTimeTolerance()); + DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + tmp3=getEndTime(tmp1,tmp2); + ret->setEndTime(tmp3,tmp1,tmp2); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("add on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + tmp3=getEndTime(tmp1,tmp2); + ret->setEndTime(tmp3,tmp1,tmp2); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("substract on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + tmp3=getEndTime(tmp1,tmp2); + ret->setEndTime(tmp3,tmp1,tmp2); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + DataArrayDouble *arr=DataArrayDouble::multiply(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + tmp3=getEndTime(tmp1,tmp2); + ret->setEndTime(tmp3,tmp1,tmp2); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("divide on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + DataArrayDouble *arr=DataArrayDouble::divide(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + tmp3=getEndTime(tmp1,tmp2); + ret->setEndTime(tmp3,tmp1,tmp2); + return ret; +} + MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_dt(-1),_end_dt(-1),_start_it(-1),_end_it(-1),_end_array(0) { } diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 1ec0a76f5..328780c9e 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -39,8 +39,14 @@ namespace ParaMEDMEM static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type); virtual bool areCompatible(const MEDCouplingTimeDiscretization *other) const; virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other, + TypeOfTimeDiscretization type, bool deepCpy) const; virtual TypeOfTimeDiscretization getEnum() const = 0; virtual MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *multiply(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const = 0; virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; virtual void getTinySerializationDbleInformation(std::vector& tinyInfo) const; virtual void getTinySerializationStrInformation(std::vector& tinyInfo) const; @@ -68,6 +74,10 @@ namespace ParaMEDMEM virtual void setEndTime(double time, int dt, int it) 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 applyLin(double a, double b, int compoId); + virtual void applyFunc(int nbOfComp, FunctionToEvaluate func); + // virtual ~MEDCouplingTimeDiscretization(); protected: double _time_tolerance; @@ -83,6 +93,10 @@ namespace ParaMEDMEM MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCpy); TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *multiply(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; bool areCompatible(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const; @@ -111,6 +125,10 @@ namespace ParaMEDMEM MEDCouplingWithTimeStep(); TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *multiply(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; bool areCompatible(const MEDCouplingTimeDiscretization *other) const; void getTinySerializationIntInformation(std::vector& tinyInfo) const; @@ -136,6 +154,46 @@ namespace ParaMEDMEM int _it; }; + class MEDCOUPLING_EXPORT MEDCouplingConstOnTimeInterval : public MEDCouplingTimeDiscretization + { + protected: + MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCpy); + public: + MEDCouplingConstOnTimeInterval(); + void getTinySerializationIntInformation(std::vector& tinyInfo) const; + void getTinySerializationDbleInformation(std::vector& tinyInfo) const; + void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); + MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const; + bool areCompatible(const MEDCouplingTimeDiscretization *other) const; + bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; + DataArrayDouble *getArrayOnTime(double time) const 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); + TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } + MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *multiply(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; + 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 checkNoTimePresence() const throw(INTERP_KERNEL::Exception); + void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception); + public: + static const TypeOfTimeDiscretization DISCRETIZATION=CONST_ON_TIME_INTERVAL; + private: + static const char EXCEPTION_MSG[]; + protected: + double _start_time; + double _end_time; + int _start_dt; + int _end_dt; + int _start_it; + int _end_it; + }; + class MEDCOUPLING_EXPORT MEDCouplingTwoTimeSteps : public MEDCouplingTimeDiscretization { protected: diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index cb5d28eb8..5397203af 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -847,10 +847,37 @@ MEDCouplingMesh *MEDCouplingUMesh::mergeMyselfWith(const MEDCouplingMesh *other) if(other->getType()!=UNSTRUCTURED) throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh each other !"); const MEDCouplingUMesh *otherC=static_cast(other); - return mergeMeshes(this,otherC); + return mergeUMeshes(this,otherC); } -MEDCouplingUMesh *MEDCouplingUMesh::mergeMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) +DataArrayDouble *MEDCouplingUMesh::getBarycenterAndOwner() const +{ + DataArrayDouble *ret=DataArrayDouble::New(); + int spaceDim=getSpaceDimension(); + int nbOfCells=getNumberOfCells(); + ret->alloc(nbOfCells,spaceDim); + double *ptToFill=ret->getPointer(); + double *tmp=new double[spaceDim]; + const int *nodal=_nodal_connec->getConstPointer(); + const int *nodalI=_nodal_connec_index->getConstPointer(); + const double *coor=_coords->getConstPointer(); + for(int i=0;i()); + nbOfPts++; + } + ptToFill=std::transform(tmp,tmp+spaceDim,ptToFill,std::bind2nd(std::divides(),(double)nbOfPts)); + } + delete [] tmp; + return ret; +} + +MEDCouplingUMesh *MEDCouplingUMesh::mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) { MEDCouplingUMesh *ret=MEDCouplingUMesh::New(); DataArrayDouble *pts=mergeNodesArray(mesh1,mesh2); diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index f6453978e..cc426d0ed 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -71,7 +71,8 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getMeasureField(bool isAbs) const; void checkButterflyCells(std::vector& cells) const; MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const; - static MEDCouplingUMesh *mergeMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2); + DataArrayDouble *getBarycenterAndOwner() const; + static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2); private: MEDCouplingUMesh(); MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCpy); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 065e7d690..35e6ad11c 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -288,3 +288,8 @@ MEDCouplingMesh *MEDCouplingUMeshDesc::mergeMyselfWith(const MEDCouplingMesh *ot return 0; } +DataArrayDouble *MEDCouplingUMeshDesc::getBarycenterAndOwner() const +{ + //not implemented yet. + return 0; +} diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index 698be87cd..14589cdef 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -57,6 +57,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getMeasureField(bool isAbs) const; DataArrayInt *zipCoordsTraducer(); MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const; + DataArrayDouble *getBarycenterAndOwner() const; private: MEDCouplingUMeshDesc(); ~MEDCouplingUMeshDesc();