From: ageay Date: Mon, 20 Sep 2010 05:58:21 +0000 (+0000) Subject: Addition of some functionalities : simpleRepr, advancedRepr, min, max, dot, crossProd... X-Git-Tag: V5_1_main_FINAL~38 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1c9829edf2f4f47654bf103ca67be33569c88bf4;p=tools%2Fmedcoupling.git Addition of some functionalities : simpleRepr, advancedRepr, min, max, dot, crossProduct, getMinValue, getAverageValue, getWeightedAverageVaue. --- diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 091fadb62..45f1e8e2e 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -324,6 +324,34 @@ void MEDCouplingCMesh::getCoordinatesOfNode(int nodeId, std::vector& coo //not implemented yet } +std::string MEDCouplingCMesh::simpleRepr() const +{ + std::ostringstream ret; + ret << "Cartesian mesh with name : \"" << getName() << "\"\n"; + ret << "Mesh and SpaceDimension dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n"; + if(_x_array) + { + ret << "X Array :\n"; + _x_array->reprZipWithoutNameStream(ret); + } + if(_y_array) + { + ret << "Y Array :\n"; + _y_array->reprZipWithoutNameStream(ret); + } + if(_z_array) + { + ret << "Z Array :\n"; + _z_array->reprZipWithoutNameStream(ret); + } + return ret.str(); +} + +std::string MEDCouplingCMesh::advancedRepr() const +{ + return simpleRepr(); +} + DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) const throw(INTERP_KERNEL::Exception) { switch(i) diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index 739c11d96..9d35de6d8 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -51,6 +51,8 @@ namespace ParaMEDMEM int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; void getNodeIdsOfCell(int cellId, std::vector& conn) const; void getCoordinatesOfNode(int nodeId, std::vector& coo) const; + std::string simpleRepr() const; + std::string advancedRepr() const; DataArrayDouble *getCoordsAt(int i) const throw(INTERP_KERNEL::Exception); void setCoordsAt(int i, DataArrayDouble *arr) throw(INTERP_KERNEL::Exception); void setCoords(DataArrayDouble *coordsX, diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 1d8b85a5c..d33eda528 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -231,6 +231,32 @@ void MEDCouplingExtrudedMesh::getCoordinatesOfNode(int nodeId, std::vectorgetNumberOfCells() << "x" << _mesh1D->getNumberOfCells() << ")\n"; + ret << "1D Mesh info : _____________________\n\n\n"; + ret << _mesh1D->simpleRepr(); + ret << "\n\n\n2D Mesh info : _____________________\n\n\n" << _mesh2D->simpleRepr() << "\n\n\n"; + return ret.str(); +} + +std::string MEDCouplingExtrudedMesh::advancedRepr() const +{ + std::ostringstream ret; + ret << "3D Extruded mesh from a 2D Surf Mesh with name : \"" << getName() << "\"\n"; + ret << "Cell id where 1D mesh has been deduced : " << _cell_2D_id << "\n"; + ret << "Number of cells : " << getNumberOfCells() << "(" << _mesh2D->getNumberOfCells() << "x" << _mesh1D->getNumberOfCells() << ")\n"; + ret << "1D Mesh info : _____________________\n\n\n"; + ret << _mesh1D->advancedRepr(); + ret << "\n\n\n2D Mesh info : _____________________\n\n\n" << _mesh2D->advancedRepr() << "\n\n\n"; + ret << "3D cell ids per level :\n"; + _mesh3D_ids; + return ret.str(); +} + void MEDCouplingExtrudedMesh::checkCoherency() const throw (INTERP_KERNEL::Exception) { } diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 50cc24ec0..1481b58d2 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -52,6 +52,8 @@ namespace ParaMEDMEM int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; void getNodeIdsOfCell(int cellId, std::vector& conn) const; void getCoordinatesOfNode(int nodeId, std::vector& coo) const; + std::string simpleRepr() const; + std::string advancedRepr() const; void checkCoherency() const throw (INTERP_KERNEL::Exception); void getBoundingBox(double *bbox) const; void updateTime(); diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index d8b9e7d9f..6425a21a1 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -55,7 +55,7 @@ bool MEDCouplingField::areCompatibleForMerge(const MEDCouplingField *other) cons } /*! - * This method is more strict than MEDCouplingField::areCompatible method. + * This method is more strict than MEDCouplingField::areCompatibleForMerge method. * This method is used for operation on fields to operate a first check before attempting operation. */ bool MEDCouplingField::areStrictlyCompatible(const MEDCouplingField *other) const diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index bfefcb24c..8823f36c0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -74,6 +74,50 @@ void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingFieldDouble *o } } +std::string MEDCouplingFieldDouble::simpleRepr() const +{ + std::ostringstream ret; + ret << "FieldDouble with name : \"" << getName() << "\"\n"; + ret << "Description of field is : \"" << getDescription() << "\"\n"; + ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; + ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; + if(getArray()) + ret << "FieldDouble default array has " << getArray()->getNumberOfComponents() << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; + if(_mesh) + ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); + else + ret << "Mesh support information : No mesh set !\n"; + return ret.str(); +} + +std::string MEDCouplingFieldDouble::advancedRepr() const +{ + std::ostringstream ret; + ret << "FieldDouble with name : \"" << getName() << "\"\n"; + ret << "Description of field is : \"" << getDescription() << "\"\n"; + ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; + ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; + if(getArray()) + ret << "FieldDouble default array has " << getArray()->getNumberOfComponents() << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; + if(_mesh) + ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); + else + ret << "Mesh support information : No mesh set !\n"; + std::vector arrays; + _time_discr->getArrays(arrays); + int arrayId=0; + for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,arrayId++) + { + ret << "Array #" << arrayId << " :\n__________\n"; + if(*iter) + (*iter)->reprWithoutNameStream(ret); + else + ret << "Array empty !"; + ret << "\n"; + } + return ret.str(); +} + bool MEDCouplingFieldDouble::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const { const MEDCouplingFieldDouble *otherC=dynamic_cast(other); @@ -108,7 +152,7 @@ bool MEDCouplingFieldDouble::areCompatibleForMerge(const MEDCouplingField *other } /*! - * This method is more strict than MEDCouplingField::areCompatible method. + * This method is more strict than MEDCouplingField::areCompatibleForMerge method. * This method is used for operation on fields to operate a first check before attempting operation. */ bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other) const @@ -125,6 +169,10 @@ bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other return true; } +/*! + * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that + * number of components between 'this' and 'other' can be different here (for operator*). + */ bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) const { if(!MEDCouplingField::areStrictlyCompatible(other)) @@ -234,24 +282,29 @@ void MEDCouplingFieldDouble::checkCoherency() const throw(INTERP_KERNEL::Excepti } /*! - * Returns the accumulation (the sum) of comId_th component of each tuples of default array. + * Returns the accumulation (the sum) of comId_th component of each tuples of \b default and \b only \b default array. */ double MEDCouplingFieldDouble::accumulate(int compId) const { - const double *ptr=getArray()->getConstPointer(); - int nbTuple=getArray()->getNumberOfTuples(); - int nbComps=getArray()->getNumberOfComponents(); - if(compId>=nbComps) - throw INTERP_KERNEL::Exception("Invalid compId specified : No such nb of components !"); - double ret=0.; - for(int i=0;iaccumulate(compId); +} + +/*! + * Returns the accumulation (the sum) of all tuples of \b default and \b only default array. + * The res is expected to be of size getNumberOfComponents(). + */ +void MEDCouplingFieldDouble::accumulate(double *res) const +{ + if(getArray()==0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !"); + getArray()->accumulate(res); } /*! - * This method returns the max value in 'this'. 'This' is expected to be a field with exactly one component. If not an exception will be thrown.x - * To getMaxValue on vector field applyFunc is needed before. This method looks only on arrays stored in 'this->_time_discr'. + * This method returns the max value in 'this'. 'This' is expected to be a field with exactly \b one component. If not an exception will be thrown. + * To getMaxValue on vector field applyFunc is needed before. This method looks only on all arrays stored in 'this->_time_discr'. * If no arrays exists, an exception will be thrown. */ double MEDCouplingFieldDouble::getMaxValue() const throw(INTERP_KERNEL::Exception) @@ -275,17 +328,58 @@ double MEDCouplingFieldDouble::getMaxValue() const throw(INTERP_KERNEL::Exceptio } /*! - * Returns the accumulation (the sum) of all tuples of default array. - * The res is expected to be of size getNumberOfComponents(). + * This method returns the min value in 'this'. 'This' is expected to be a field with exactly \b one component. If not an exception will be thrown. + * To getMinValue on vector field applyFunc is needed before. This method looks only on all arrays stored in 'this->_time_discr'. + * If no arrays exists, an exception will be thrown. */ -void MEDCouplingFieldDouble::accumulate(double *res) const +double MEDCouplingFieldDouble::getMinValue() const throw(INTERP_KERNEL::Exception) { - const double *ptr=getArray()->getConstPointer(); - int nbTuple=getArray()->getNumberOfTuples(); - int nbComps=getArray()->getNumberOfComponents(); - std::fill(res,res+nbComps,0.); - for(int i=0;i()); + std::vector arrays; + _time_discr->getArrays(arrays); + double ret=std::numeric_limits::max(); + bool isExistingArr=false; + for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) + { + if(*iter) + { + isExistingArr=true; + int loc; + ret=std::min(ret,(*iter)->getMinValue(loc)); + } + } + if(!isExistingArr) + throw INTERP_KERNEL::Exception("getMinValue : No arrays defined !"); + return ret; +} + +/*! + * This method returns the average value in 'this'. 'This' is expected to be a field with exactly \b one component. If not an exception will be thrown. + * To getAverageValue on vector field applyFunc is needed before. This method looks only \b default array \b and \b only \b default. + * If default array does not exist, an exception will be thrown. + */ +double MEDCouplingFieldDouble::getAverageValue() const throw(INTERP_KERNEL::Exception) +{ + if(getArray()==0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getAverageValue : no default array defined !"); + return getArray()->getAverageValue(); +} + +/*! + * This method returns the average value in 'this' weighted by ParaMEDMEM::MEDCouplingField::buildWeightingField. + * 'This' is expected to be a field with exactly \b one component. If not an exception will be thrown. + * To getAverageValue on vector field applyFunc is needed before. This method looks only \b default array \b and \b only \b default. + * If default array does not exist, an exception will be thrown. + */ +double MEDCouplingFieldDouble::getWeightedAverageValue() const throw(INTERP_KERNEL::Exception) +{ + if(getArray()==0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getWeightedAverageValue : no default array defined !"); + MEDCouplingFieldDouble *w=buildWeightingField(true); + double deno=w->getArray()->accumulate(0); + w->getArray()->multiplyEqual(getArray()); + double res=w->getArray()->accumulate(0); + w->decrRef(); + return res/deno; } /*! @@ -694,6 +788,50 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const MEDCouplingFie return ret; } +MEDCouplingFieldDouble *MEDCouplingFieldDouble::dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +{ + if(!f1->areStrictlyCompatible(f2)) + 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()); + ret->setMesh(f1->getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +{ + if(!f1->areStrictlyCompatible(f2)) + 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()); + ret->setMesh(f1->getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +{ + if(!f1->areStrictlyCompatible(f2)) + 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()); + ret->setMesh(f1->getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +{ + if(!f1->areStrictlyCompatible(f2)) + 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()); + ret->setMesh(f1->getMesh()); + return ret; +} + MEDCouplingFieldDouble *MEDCouplingFieldDouble::addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) { if(!f1->areStrictlyCompatible(f2)) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index b6524128a..d3e35bf60 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -33,6 +33,8 @@ namespace ParaMEDMEM public: static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=NO_TIME); void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + std::string advancedRepr() const; bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; bool areCompatibleForMerge(const MEDCouplingField *other) const; bool areStrictlyCompatible(const MEDCouplingField *other) const; @@ -63,6 +65,9 @@ namespace ParaMEDMEM double accumulate(int compId) const; void accumulate(double *res) const; double getMaxValue() const throw(INTERP_KERNEL::Exception); + double getMinValue() const throw(INTERP_KERNEL::Exception); + double getAverageValue() const throw(INTERP_KERNEL::Exception); + double getWeightedAverageValue() const throw(INTERP_KERNEL::Exception); double normL1(int compId) const throw(INTERP_KERNEL::Exception); void normL1(double *res) const throw(INTERP_KERNEL::Exception); double normL2(int compId) const throw(INTERP_KERNEL::Exception); @@ -92,6 +97,14 @@ namespace ParaMEDMEM void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); bool mergeNodes(double eps) 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); } + static MEDCouplingFieldDouble *crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *crossProduct(const MEDCouplingFieldDouble& other) const { return crossProductFields(this,&other); } + static MEDCouplingFieldDouble *maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const { return maxFields(this,&other); } + static MEDCouplingFieldDouble *minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const { return minFields(this,&other); } MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const { return addFields(this,&other); } const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other); static MEDCouplingFieldDouble *addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index d7d9e9f28..3d2e5c16b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -20,6 +20,7 @@ #include "MEDCouplingMemArray.txx" #include +#include #include using namespace ParaMEDMEM; @@ -46,6 +47,15 @@ bool DataArray::areInfoEquals(const DataArray& other) const return _info_on_compo==other._info_on_compo; } +void DataArray::reprWithoutNameStream(std::ostream& stream) const +{ + stream << "Nb of components : "<< getNumberOfComponents() << "\n"; + stream << "Info of these components : "; + for(std::vector::const_iterator iter=_info_on_compo.begin();iter!=_info_on_compo.end();iter++) + stream << "\"" << *iter << "\" "; + stream << "\n"; +} + DataArrayDouble *DataArrayDouble::New() { return new DataArrayDouble; @@ -80,6 +90,46 @@ void DataArrayDouble::fillWithZero() _mem.fillWithValue(0.); } +std::string DataArrayDouble::repr() const +{ + std::ostringstream ret; + reprStream(ret); + return ret.str(); +} + +std::string DataArrayDouble::reprZip() const +{ + std::ostringstream ret; + reprZipStream(ret); + return ret.str(); +} + +void DataArrayDouble::reprStream(std::ostream& stream) const +{ + stream << "Name of double array : \"" << _name << "\"\n"; + reprWithoutNameStream(stream); +} + +void DataArrayDouble::reprZipStream(std::ostream& stream) const +{ + stream << "Name of double array : \"" << _name << "\"\n"; + reprZipWithoutNameStream(stream); +} + +void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const +{ + DataArray::reprWithoutNameStream(stream); + stream.precision(15); + _mem.repr(getNumberOfComponents(),stream); +} + +void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const +{ + DataArray::reprWithoutNameStream(stream); + stream.precision(15); + _mem.reprZip(getNumberOfComponents(),stream); +} + bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const { if(!areInfoEquals(other)) @@ -195,12 +245,62 @@ double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exc if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component !"); int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<=0) + throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !"); const double *vals=getConstPointer(); const double *loc=std::max_element(vals,vals+nbOfTuples); tupleId=std::distance(vals,loc); return *loc; } +double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component !"); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<=0) + throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !"); + const double *vals=getConstPointer(); + const double *loc=std::min_element(vals,vals+nbOfTuples); + tupleId=std::distance(vals,loc); + return *loc; +} + +double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : must be applied on DataArrayDouble with only one component !"); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<=0) + throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : array exists but number of tuples must be > 0 !"); + const double *vals=getConstPointer(); + double ret=std::accumulate(vals,vals+nbOfTuples,0.); + return ret/nbOfTuples; +} + +void DataArrayDouble::accumulate(double *res) const +{ + const double *ptr=getConstPointer(); + int nbTuple=getNumberOfTuples(); + int nbComps=getNumberOfComponents(); + std::fill(res,res+nbComps,0.); + for(int i=0;i()); +} + +double DataArrayDouble::accumulate(int compId) const +{ + const double *ptr=getConstPointer(); + int nbTuple=getNumberOfTuples(); + int nbComps=getNumberOfComponents(); + if(compId>=nbComps) + throw INTERP_KERNEL::Exception("DataArrayDouble::accumulate : Invalid compId specified : No such nb of components !"); + double ret=0.; + for(int i=0;igetNumberOfComponents(); @@ -216,6 +316,96 @@ DataArrayDouble *DataArrayDouble::aggregate(const DataArrayDouble *a1, const Dat return ret; } +DataArrayDouble *DataArrayDouble::dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfComp=a1->getNumberOfComponents(); + if(nbOfComp!=a2->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Nb of components mismatch for array dot !"); + int nbOfTuple=a1->getNumberOfTuples(); + if(nbOfTuple!=a2->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array dot !"); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,1); + double *retPtr=ret->getPointer(); + const double *a1Ptr=a1->getConstPointer(); + const double *a2Ptr=a2->getConstPointer(); + for(int i=0;isetInfoOnComponent(0,a1->getInfoOnComponent(0).c_str()); + ret->setName(a1->getName().c_str()); + return ret; +} + +DataArrayDouble *DataArrayDouble::crossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfComp=a1->getNumberOfComponents(); + if(nbOfComp!=a2->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !"); + if(nbOfComp!=3) + throw INTERP_KERNEL::Exception("Nb of components must be equal to 3 for array crossProduct !"); + int nbOfTuple=a1->getNumberOfTuples(); + if(nbOfTuple!=a2->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array crossProduct !"); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,3); + double *retPtr=ret->getPointer(); + const double *a1Ptr=a1->getConstPointer(); + const double *a2Ptr=a2->getConstPointer(); + for(int i=0;icopyStringInfoFrom(*a1); + return ret; +} + +DataArrayDouble *DataArrayDouble::max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfComp=a1->getNumberOfComponents(); + if(nbOfComp!=a2->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Nb of components mismatch for array max !"); + int nbOfTuple=a1->getNumberOfTuples(); + if(nbOfTuple!=a2->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array max !"); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,nbOfComp); + double *retPtr=ret->getPointer(); + const double *a1Ptr=a1->getConstPointer(); + const double *a2Ptr=a2->getConstPointer(); + int nbElem=nbOfTuple*nbOfComp; + for(int i=0;icopyStringInfoFrom(*a1); + return ret; +} + +DataArrayDouble *DataArrayDouble::min(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfComp=a1->getNumberOfComponents(); + if(nbOfComp!=a2->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !"); + int nbOfTuple=a1->getNumberOfTuples(); + if(nbOfTuple!=a2->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array min !"); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,nbOfComp); + double *retPtr=ret->getPointer(); + const double *a1Ptr=a1->getConstPointer(); + const double *a2Ptr=a2->getConstPointer(); + int nbElem=nbOfTuple*nbOfComp; + for(int i=0;icopyStringInfoFrom(*a1); + return ret; +} + DataArrayDouble *DataArrayDouble::add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { int nbOfComp=a1->getNumberOfComponents(); @@ -325,11 +515,8 @@ void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_K int nbOfComp2=other->getNumberOfComponents(); if(nbOfTuple!=nbOfTuple2) throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array multiplyEqual !"); - DataArrayDouble *ret=0; if(nbOfComp==nbOfComp2) { - ret=DataArrayDouble::New(); - ret->alloc(nbOfTuple,nbOfComp); std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::multiplies()); } else @@ -408,6 +595,44 @@ void DataArrayInt::fillWithZero() _mem.fillWithValue(0); } +std::string DataArrayInt::repr() const +{ + std::ostringstream ret; + reprStream(ret); + return ret.str(); +} + +std::string DataArrayInt::reprZip() const +{ + std::ostringstream ret; + reprZipStream(ret); + return ret.str(); +} + +void DataArrayInt::reprStream(std::ostream& stream) const +{ + stream << "Name of int array : \"" << _name << "\"\n"; + reprWithoutNameStream(stream); +} + +void DataArrayInt::reprZipStream(std::ostream& stream) const +{ + stream << "Name of int array : \"" << _name << "\"\n"; + reprZipWithoutNameStream(stream); +} + +void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const +{ + DataArray::reprWithoutNameStream(stream); + _mem.repr(getNumberOfComponents(),stream); +} + +void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const +{ + DataArray::reprWithoutNameStream(stream); + _mem.reprZip(getNumberOfComponents(),stream); +} + void DataArrayInt::transformWithIndArr(const int *indArr) { if(getNumberOfComponents()!=1) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 1c1739199..640fe8c8f 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -27,6 +27,7 @@ #include #include +#include namespace ParaMEDMEM { @@ -60,6 +61,8 @@ namespace ParaMEDMEM T operator[](int id) const { return _pointer.getConstPointer()[id]; } T& operator[](int id) { return _pointer.getPointer()[id]; } bool isEqual(const MemArray& other, T prec) const; + void repr(int sl, std::ostream& stream) const; + void reprZip(int sl, std::ostream& stream) const; void fillWithValue(const T& val); void alloc(int nbOfElements); void reAlloc(int newNbOfElements); @@ -73,7 +76,6 @@ namespace ParaMEDMEM int _nb_of_elem; bool _ownership; MEDCouplingPointer _pointer; - //T *_pointer; DeallocType _dealloc; }; @@ -83,7 +85,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setName(const char *name); MEDCOUPLING_EXPORT void copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool areInfoEquals(const DataArray& other) const; + MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT std::string getName() const { return _name; } + MEDCOUPLING_EXPORT const std::vector &getInfoOnComponent() const { return _info_on_compo; } MEDCOUPLING_EXPORT std::string getInfoOnComponent(int i) const { return _info_on_compo[i]; } MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const char *info) { _info_on_compo[i]=info; } MEDCOUPLING_EXPORT int getNumberOfComponents() const { return _info_on_compo.size(); } @@ -111,6 +115,12 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayDouble *performCpy(bool deepCpy) const; MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void fillWithZero(); + MEDCOUPLING_EXPORT std::string repr() const; + MEDCOUPLING_EXPORT std::string reprZip() const; + MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; + 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; //!alloc or useArray should have been called before. MEDCOUPLING_EXPORT void reAlloc(int nbOfTuples); @@ -128,7 +138,15 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } MEDCOUPLING_EXPORT void checkNoNullValues() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT double getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + 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 static DataArrayDouble *aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *crossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *min(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayDouble *add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayDouble *substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); @@ -154,6 +172,12 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt& other) const; MEDCOUPLING_EXPORT void fillWithZero(); + MEDCOUPLING_EXPORT std::string repr() const; + MEDCOUPLING_EXPORT std::string reprZip() const; + MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArr); //!alloc or useArray should have been called before. MEDCOUPLING_EXPORT void reAlloc(int nbOfTuples); diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index cff97d05a..21c88c78c 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -93,6 +93,85 @@ namespace ParaMEDMEM return true; } + /*! + * @param sl is typically the number of components [in parameter] + */ + template + void MemArray::repr(int sl, std::ostream& stream) const + { + stream << "Number of tuples : "; + if(!_pointer.isNull()) + { + if(sl!=0) + stream << _nb_of_elem/sl; + else + stream << "Empty Data"; + } + else + stream << "No data"; + stream << "\n"; + stream << "Data content :\n"; + const T *data=getConstPointer(); + if(!_pointer.isNull()) + { + if(_nb_of_elem!=0 && sl!=0) + { + int nbOfTuples=_nb_of_elem/sl; + for(int i=0;i(stream," ")); + stream << "\n"; + data+=sl; + } + } + else + stream << "Empty Data\n"; + } + else + stream << "No data !\n"; + } + + /*! + * @param sl is typically the number of components [in parameter] + */ + template + void MemArray::reprZip(int sl, std::ostream& stream) const + { + stream << "Number of tuples : "; + if(!_pointer.isNull()) + { + if(sl!=0) + stream << _nb_of_elem/sl; + else + stream << "Empty Data"; + } + else + stream << "No data"; + stream << "\n"; + stream << "Data content : "; + const T *data=getConstPointer(); + if(!_pointer.isNull()) + { + if(_nb_of_elem!=0 && sl!=0) + { + int nbOfTuples=_nb_of_elem/sl; + for(int i=0;i(stream," ")); + stream << "| "; + data+=sl; + } + stream << "\n"; + } + else + stream << "Empty Data\n"; + } + else + stream << "No data !\n"; + } + template void MemArray::fillWithValue(const T& val) { diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index dfb54ce21..bb1d9adfc 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -70,6 +70,8 @@ namespace ParaMEDMEM virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0; virtual void getNodeIdsOfCell(int cellId, std::vector& conn) const = 0; virtual void getCoordinatesOfNode(int nodeId, std::vector& coo) const = 0; + virtual std::string simpleRepr() const = 0; + virtual std::string advancedRepr() const = 0; // tools virtual void getBoundingBox(double *bbox) const = 0; virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index cb5d7e6f6..ff27a1996 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -27,15 +27,23 @@ using namespace ParaMEDMEM; +const double MEDCouplingTimeDiscretization::TIME_TOLERANCE_DFT=1.e-12; + const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached."; +const char MEDCouplingNoTimeLabel::REPR[]="No time label defined."; + const char MEDCouplingWithTimeStep::EXCEPTION_MSG[]="No data on this time."; +const char MEDCouplingWithTimeStep::REPR[]="One time label."; + const char MEDCouplingConstOnTimeInterval::EXCEPTION_MSG[]="No data on this time."; +const char MEDCouplingConstOnTimeInterval::REPR[]="Constant on a time interval."; + const char MEDCouplingTwoTimeSteps::EXCEPTION_MSG[]="No data on this time."; -const double MEDCouplingTimeDiscretization::TIME_TOLERANCE_DFT=1.e-12; +const char MEDCouplingLinearTime::REPR[]="Linear time between 2 time steps."; MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDiscretization type) { @@ -379,6 +387,13 @@ MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretizati { } +std::string MEDCouplingNoTimeLabel::getStringRepr() const +{ + std::ostringstream stream; + stream << REPR; + return stream.str(); +} + bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretization *other) const { if(!MEDCouplingTimeDiscretization::areCompatible(other)) @@ -424,6 +439,54 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCoupli return ret; } +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !"); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + DataArrayDouble *arr=DataArrayDouble::dot(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !"); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + DataArrayDouble *arr=DataArrayDouble::crossProduct(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !"); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + DataArrayDouble *arr=DataArrayDouble::max(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !"); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + DataArrayDouble *arr=DataArrayDouble::min(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const { const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); @@ -573,6 +636,13 @@ MEDCouplingWithTimeStep::MEDCouplingWithTimeStep():_time(0.),_dt(-1),_it(-1) { } +std::string MEDCouplingWithTimeStep::getStringRepr() const +{ + std::ostringstream stream; + stream << REPR << " Time is defined by dt=" << _dt << " it=" << _it << " and time=" << _time << "."; + return stream.str(); +} + void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); @@ -657,6 +727,54 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCoupl return ret; } +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::dot on mismatched time discretization !"); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + DataArrayDouble *arr=DataArrayDouble::dot(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !"); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + DataArrayDouble *arr=DataArrayDouble::crossProduct(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !"); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + DataArrayDouble *arr=DataArrayDouble::max(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !"); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + DataArrayDouble *arr=DataArrayDouble::min(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const { const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); @@ -812,6 +930,18 @@ MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval():_start_time(0.) { } +void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) +{ + MEDCouplingTimeDiscretization::copyTinyAttrFrom(other); + 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; +} + void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); @@ -845,6 +975,14 @@ MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCoupling { } +std::string MEDCouplingConstOnTimeInterval::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"; + return stream.str(); +} + MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCpy(bool deepCpy) const { return new MEDCouplingConstOnTimeInterval(*this,deepCpy); @@ -967,6 +1105,54 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const M return ret; } +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + DataArrayDouble *arr=DataArrayDouble::dot(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + DataArrayDouble *arr=DataArrayDouble::crossProduct(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + DataArrayDouble *arr=DataArrayDouble::max(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !"); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + DataArrayDouble *arr=DataArrayDouble::min(getArray(),other->getArray()); + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const { const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); @@ -1293,6 +1479,14 @@ 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"; + return stream.str(); +} + void MEDCouplingLinearTime::checkCoherency() const throw(INTERP_KERNEL::Exception) { MEDCouplingTwoTimeSteps::checkCoherency(); @@ -1397,6 +1591,66 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplin return ret; } +MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !"); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + DataArrayDouble *arr1=DataArrayDouble::dot(getArray(),other->getArray()); + ret->setArray(arr1,0); + arr1->decrRef(); + DataArrayDouble *arr2=DataArrayDouble::dot(getEndArray(),other->getEndArray()); + ret->setEndArray(arr2,0); + arr2->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !"); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + DataArrayDouble *arr1=DataArrayDouble::crossProduct(getArray(),other->getArray()); + ret->setArray(arr1,0); + arr1->decrRef(); + DataArrayDouble *arr2=DataArrayDouble::crossProduct(getEndArray(),other->getEndArray()); + ret->setEndArray(arr2,0); + arr2->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !"); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + DataArrayDouble *arr1=DataArrayDouble::max(getArray(),other->getArray()); + ret->setArray(arr1,0); + arr1->decrRef(); + DataArrayDouble *arr2=DataArrayDouble::max(getEndArray(),other->getEndArray()); + ret->setEndArray(arr2,0); + arr2->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !"); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + DataArrayDouble *arr1=DataArrayDouble::min(getArray(),other->getArray()); + ret->setArray(arr1,0); + arr1->decrRef(); + DataArrayDouble *arr2=DataArrayDouble::min(getEndArray(),other->getEndArray()); + ret->setEndArray(arr2,0); + arr2->decrRef(); + return ret; +} + MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeDiscretization *other) const { const MEDCouplingLinearTime *otherC=dynamic_cast(other); diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 232f008b8..e10892081 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -49,8 +49,13 @@ namespace ParaMEDMEM virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other, TypeOfTimeDiscretization type, bool deepCpy) const; + virtual std::string getStringRepr() const = 0; virtual TypeOfTimeDiscretization getEnum() const = 0; virtual MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *min(const MEDCouplingTimeDiscretization *other) const = 0; virtual MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const = 0; virtual void addEqual(const MEDCouplingTimeDiscretization *other) = 0; virtual MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const = 0; @@ -106,8 +111,13 @@ namespace ParaMEDMEM public: MEDCouplingNoTimeLabel(); MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCpy); + std::string getStringRepr() const; TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *min(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const; void addEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const; @@ -135,6 +145,7 @@ namespace ParaMEDMEM void getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception); public: static const TypeOfTimeDiscretization DISCRETIZATION=NO_TIME; + static const char REPR[]; private: static const char EXCEPTION_MSG[]; }; @@ -145,9 +156,14 @@ namespace ParaMEDMEM MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCpy); public: MEDCouplingWithTimeStep(); + std::string getStringRepr() const; void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *min(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const; void addEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const; @@ -176,6 +192,7 @@ namespace ParaMEDMEM void getValueOnDiscTime(int eltId, int dt, int it, double *value) const throw(INTERP_KERNEL::Exception); public: static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME; + static const char REPR[]; private: static const char EXCEPTION_MSG[]; protected: @@ -190,6 +207,7 @@ namespace ParaMEDMEM MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCpy); public: MEDCouplingConstOnTimeInterval(); + void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); 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); @@ -203,7 +221,12 @@ namespace ParaMEDMEM 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; } + std::string getStringRepr() const; MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *min(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const; void addEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const; @@ -220,6 +243,7 @@ namespace ParaMEDMEM void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception); public: static const TypeOfTimeDiscretization DISCRETIZATION=CONST_ON_TIME_INTERVAL; + static const char REPR[]; private: static const char EXCEPTION_MSG[]; protected: @@ -277,6 +301,7 @@ namespace ParaMEDMEM MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCpy); public: MEDCouplingLinearTime(); + std::string getStringRepr() const; TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } void checkCoherency() const throw(INTERP_KERNEL::Exception); MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const; @@ -287,6 +312,10 @@ namespace ParaMEDMEM 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); MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *min(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const; void addEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const; @@ -297,6 +326,7 @@ namespace ParaMEDMEM void divideEqual(const MEDCouplingTimeDiscretization *other); public: static const TypeOfTimeDiscretization DISCRETIZATION=LINEAR_TIME; + static const char REPR[]; }; } diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index d3e93fb91..1cdf18668 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1191,6 +1191,75 @@ void MEDCouplingUMesh::getCoordinatesOfNode(int nodeId, std::vector& coo coo.insert(coo.end(),cooPtr+spaceDim*nodeId,cooPtr+spaceDim*(nodeId+1)); } +std::string MEDCouplingUMesh::simpleRepr() const +{ + static const char msg0[]="No coordinates specified !"; + std::ostringstream ret; + ret << "Unstructured mesh with name : \"" << getName() << "\"\n"; + ret << "Mesh dimension : " << _mesh_dim << "\nSpace dimension : "; + if(_coords!=0) + ret << getSpaceDimension() << "\n"; + else + ret << msg0 << "\n"; + ret << "Number of nodes : "; + if(_coords!=0) + ret << getNumberOfNodes() << "\n"; + else + ret << msg0 << "\n"; + ret << "Number of cells : "; + if(_nodal_connec!=0 && _nodal_connec_index!=0) + ret << getNumberOfCells() << "\n"; + else + ret << "No connectivity specified !" << "\n"; + ret << "Cell types present : "; + for(std::set::const_iterator iter=_types.begin();iter!=_types.end();iter++) + { + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(*iter); + ret << cm.getRepr() << " "; + } + ret << "\n"; + return ret.str(); +} + +std::string MEDCouplingUMesh::advancedRepr() const +{ + std::ostringstream ret; + ret << simpleRepr(); + ret << "\nCoordinates array : \n___________________\n\n"; + if(_coords) + _coords->reprWithoutNameStream(ret); + else + ret << "No array set !\n"; + ret << "\n\nConnectivity arrays : \n_____________________\n\n"; + reprConnectivityOfThisLL(ret); + return ret.str(); +} +std::string MEDCouplingUMesh::reprConnectivityOfThis() const +{ + std::ostringstream ret; + reprConnectivityOfThisLL(ret); + return ret.str(); +} + +void MEDCouplingUMesh::reprConnectivityOfThisLL(std::ostringstream& stream) const +{ + if(_nodal_connec!=0 && _nodal_connec_index!=0) + { + int nbOfCells=getNumberOfCells(); + const int *c=_nodal_connec->getConstPointer(); + const int *ci=_nodal_connec_index->getConstPointer(); + for(int i=0;i(stream," ")); + stream << "\n"; + } + } + else + stream << "Connectivity not defined !\n"; +} + int MEDCouplingUMesh::getNumberOfNodesInCell(int cellId) const { const int *ptI=_nodal_connec_index->getConstPointer(); diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 9a294e3fe..ee3cb8b19 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -54,6 +54,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; MEDCOUPLING_EXPORT void getNodeIdsOfCell(int cellId, std::vector& conn) const; MEDCOUPLING_EXPORT void getCoordinatesOfNode(int nodeId, std::vector& coo) const; + MEDCOUPLING_EXPORT std::string simpleRepr() const; + MEDCOUPLING_EXPORT std::string advancedRepr() const; + MEDCOUPLING_EXPORT std::string reprConnectivityOfThis() const; MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const; MEDCOUPLING_EXPORT int getNumberOfCells() const; MEDCOUPLING_EXPORT int getMeshDimension() const; @@ -128,6 +131,7 @@ namespace ParaMEDMEM MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCpy); ~MEDCouplingUMesh(); void checkFullyDefined() const throw(INTERP_KERNEL::Exception); + void reprConnectivityOfThisLL(std::ostringstream& stream) const; //tools void renumberNodesInConn(const int *newNodeNumbers); MEDCouplingUMesh *buildExtrudedMeshFromThisLowLev(int nbOfNodesOf1Lev, bool isQuad) const; diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index ec9f3e3c5..5fb8072db 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -143,6 +143,22 @@ void MEDCouplingUMeshDesc::getCoordinatesOfNode(int nodeId, std::vector& //not implemented yet. } +std::string MEDCouplingUMeshDesc::simpleRepr() const +{ + std::string ret("Unstructured mesh with descending connectivity : "); + ret+=getName(); + ret+="\n"; + return ret; +} + +std::string MEDCouplingUMeshDesc::advancedRepr() const +{ + std::string ret("Unstructured mesh with descending connectivity : "); + ret+=getName(); + ret+="\n"; + return ret; +} + void MEDCouplingUMeshDesc::setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx) { DataArrayInt::setArrayIn(descConn,_desc_connec); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index aaa147abf..7c1648e47 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -47,6 +47,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; MEDCOUPLING_EXPORT void getNodeIdsOfCell(int cellId, std::vector& conn) const; MEDCOUPLING_EXPORT void getCoordinatesOfNode(int nodeId, std::vector& coo) const; + MEDCOUPLING_EXPORT std::string simpleRepr() const; + MEDCOUPLING_EXPORT std::string advancedRepr() const; MEDCOUPLING_EXPORT MEDCouplingMeshType getType() const { return UNSTRUCTURED_DESC; } MEDCOUPLING_EXPORT void setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx); //tools to overload diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index ee642bcec..ea09df02b 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -106,6 +106,8 @@ namespace ParaMEDMEM CPPUNIT_TEST( testChangeUnderlyingMesh1 ); CPPUNIT_TEST( testGetMaxValue1 ); CPPUNIT_TEST( testSubstractInPlaceDM1 ); + CPPUNIT_TEST( testDotCrossProduct1 ); + CPPUNIT_TEST( testMinMaxFields1 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -240,6 +242,8 @@ namespace ParaMEDMEM void testChangeUnderlyingMesh1(); void testGetMaxValue1(); void testSubstractInPlaceDM1(); + void testDotCrossProduct1(); + void testMinMaxFields1(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index d0ff53675..3cdd02f3e 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -1085,8 +1085,15 @@ void MEDCouplingBasicsTest::testGetMaxValue1() f->checkCoherency(); // CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,f->getMaxValue(),1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5.,f->getAverageValue(),1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5.125,f->getWeightedAverageValue(),1e-14); a1->setIJ(0,2,9.5); CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14); + a2->setIJ(0,0,9.); + CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,f->getMinValue(),1e-14); // a2->decrRef(); a1->decrRef(); @@ -1128,3 +1135,81 @@ void MEDCouplingBasicsTest::testSubstractInPlaceDM1() mesh1->decrRef(); mesh2->decrRef(); } + +void MEDCouplingBasicsTest::testDotCrossProduct1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_3(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setTime(2.3,5,6); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),3); + const double arr1[30]={7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.}; + std::copy(arr1,arr1+30,array->getPointer()); + f1->setArray(array); + array->decrRef(); + MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f2->setTime(7.8,4,5); + f2->setMesh(mesh1); + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),3); + const double arr2[30]={1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.,29.,30.}; + std::copy(arr2,arr2+30,array->getPointer()); + f2->setArray(array); + array->decrRef(); + // + MEDCouplingFieldDouble *f3=f1->dot(*f2); + const double expected1[10]={842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.}; + for(int i=0;i<10;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(i,0),1e-9); + f3->decrRef(); + // + MEDCouplingFieldDouble *f4=f1->crossProduct(*f2); + const double expected2[30]={-93., 186., -93., -392., 784., -392., -691., 1382., -691., -990., 1980., -990., -1289., 2578., -1289., -1588., 3176., -1588., -1887., 3774., -1887., -2186., 4372., -2186., -2485., 4970., -2485., -2784., 5568., -2784.}; + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9); + f4->decrRef(); + // + f2->decrRef(); + f1->decrRef(); + mesh1->decrRef(); +} + +void MEDCouplingBasicsTest::testMinMaxFields1() +{ + MEDCouplingUMesh *mesh1=build2DTargetMesh_3(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setTime(2.3,5,6); + f1->setMesh(mesh1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),3); + const double arr1[30]={7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.}; + std::copy(arr1,arr1+30,array->getPointer()); + f1->setArray(array); + array->decrRef(); + MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f2->setTime(7.8,4,5); + f2->setMesh(mesh1); + array=DataArrayDouble::New(); + array->alloc(mesh1->getNumberOfCells(),3); + const double arr2[30]={6.,108.,206.,9.,107.,209.,8.,110.,208.,11.,109.,211.,10.,112.,210.,13.,111.,213.,12.,114.,212.,15.,113.,215.,14.,116.,214.,17.,115.,217.}; + std::copy(arr2,arr2+30,array->getPointer()); + f2->setArray(array); + array->decrRef(); + // + MEDCouplingFieldDouble *f3=f1->max(*f2); + const double expected1[30]={7.,108.,207.,9.,108.,209.,9.,110.,209.,11.,110.,211.,11.,112.,211.,13.,112.,213.,13.,114.,213.,15.,114.,215.,15.,116.,215.,17.,116.,217.}; + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-9); + f3->decrRef(); + // + MEDCouplingFieldDouble *f4=f1->min(*f2); + const double expected2[30]={6.,107.,206.,8.,107.,208.,8.,109.,208.,10.,109.,210.,10.,111.,210.,12.,111.,212.,12.,113.,212.,14.,113.,214.,14.,115.,214.,16.,115.,216.}; + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9); + f4->decrRef(); + // + f2->decrRef(); + f1->decrRef(); + mesh1->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 6773e5c21..986547d47 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -2627,8 +2627,15 @@ class MEDCouplingBasicsTest(unittest.TestCase): f.checkCoherency(); # self.assertAlmostEqual(8.,f.getMaxValue(),14); + self.assertAlmostEqual(0.,f.getMinValue(),14); + self.assertAlmostEqual(5.,f.getAverageValue(),14); + self.assertAlmostEqual(5.125,f.getWeightedAverageValue(),14); a1.setIJ(0,2,9.5); self.assertAlmostEqual(9.5,f.getMaxValue(),14); + self.assertAlmostEqual(0.,f.getMinValue(),14); + a2.setIJ(0,0,9.); + self.assertAlmostEqual(9.5,f.getMaxValue(),14); + self.assertAlmostEqual(1.,f.getMinValue(),14); pass def testSubstractInPlaceDM1(self): @@ -2655,6 +2662,67 @@ class MEDCouplingBasicsTest(unittest.TestCase): f1.applyFunc(1,"abs(x+y+0.2)"); self.assertAlmostEqual(0.,f1.getMaxValue(),13); pass + + def testDotCrossProduct1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setTime(2.3,5,6); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr1=[7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.] + array.setValues(arr1,mesh1.getNumberOfCells(),3); + f1.setArray(array); + f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f2.setTime(7.8,4,5); + f2.setMesh(mesh1); + array=DataArrayDouble.New(); + arr2=[1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.,29.,30.] + array.setValues(arr2,mesh1.getNumberOfCells(),3); + f2.setArray(array); + # + f3=f1.dot(f2); + expected1=[842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.] + for i in xrange(10): + self.assertAlmostEqual(expected1[i],f3.getIJ(i,0),9); + pass + # + f4=f1.crossProduct(f2); + expected2=[-93., 186., -93., -392., 784., -392., -691., 1382., -691., -990., 1980., -990., -1289., 2578., -1289., -1588., 3176., -1588., -1887., 3774., -1887., -2186., 4372., -2186., -2485., 4970., -2485., -2784., 5568., -2784.] + for i in xrange(30): + self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9); + pass + pass + + def testMinMaxFields1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setTime(2.3,5,6); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr1=[7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.] + array.setValues(arr1,mesh1.getNumberOfCells(),3); + f1.setArray(array); + f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f2.setTime(7.8,4,5); + f2.setMesh(mesh1); + array=DataArrayDouble.New(); + arr2=[6.,108.,206.,9.,107.,209.,8.,110.,208.,11.,109.,211.,10.,112.,210.,13.,111.,213.,12.,114.,212.,15.,113.,215.,14.,116.,214.,17.,115.,217.] + array.setValues(arr2,mesh1.getNumberOfCells(),3); + f2.setArray(array); + # + f3=f1.max(f2); + expected1=[7.,108.,207.,9.,108.,209.,9.,110.,209.,11.,110.,211.,11.,112.,211.,13.,112.,213.,13.,114.,213.,15.,114.,215.,15.,116.,215.,17.,116.,217.] + for i in xrange(30): + self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),9); + pass + # + f4=f1.min(f2); + expected2=[6.,107.,206.,8.,107.,208.,8.,109.,208.,10.,109.,210.,10.,111.,210.,12.,111.,212.,12.,113.,212.,14.,113.,214.,14.,115.,214.,16.,115.,216.] + for i in xrange(30): + self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9); + pass + # + pass def setUp(self): pass diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i index 56e967e3f..559daa4ea 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i @@ -40,6 +40,7 @@ using namespace INTERP_KERNEL; %template(ivec) std::vector; %template(dvec) std::vector; +%template(svec) std::vector; %typemap(out) ParaMEDMEM::MEDCouplingMesh* { @@ -59,6 +60,14 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingField::buildWeightingField; %newobject ParaMEDMEM::MEDCouplingFieldDouble::New; %newobject ParaMEDMEM::MEDCouplingFieldDouble::mergeFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::dotFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::dot; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::crossProductFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::crossProduct; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::maxFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::max; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::minFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::min; %newobject ParaMEDMEM::MEDCouplingFieldDouble::operator+; %newobject ParaMEDMEM::MEDCouplingFieldDouble::operator-; %newobject ParaMEDMEM::MEDCouplingFieldDouble::operator*; @@ -70,6 +79,8 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::performCpy; %newobject ParaMEDMEM::DataArrayInt::substr; %newobject ParaMEDMEM::DataArrayDouble::aggregate; +%newobject ParaMEDMEM::DataArrayDouble::dot; +%newobject ParaMEDMEM::DataArrayDouble::crossProduct; %newobject ParaMEDMEM::DataArrayDouble::add; %newobject ParaMEDMEM::DataArrayDouble::substract; %newobject ParaMEDMEM::DataArrayDouble::multiply; @@ -163,6 +174,8 @@ namespace ParaMEDMEM virtual DataArrayDouble *getCoordinatesAndOwner() const = 0; virtual DataArrayDouble *getBarycenterAndOwner() const = 0; virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0; + virtual std::string simpleRepr() const = 0; + virtual std::string advancedRepr() const = 0; virtual void getNodeIdsOfCell(int cellId, std::vector& conn) const = 0; virtual void getCoordinatesOfNode(int nodeId, std::vector& coo) const = 0; // tools @@ -388,6 +401,7 @@ namespace ParaMEDMEM int getNumberOfNodesInCell(int cellId) const; int getMeshLength() const; void computeTypes(); + std::string reprConnectivityOfThis() const; //tools bool checkConsecutiveCellTypes() const; DataArrayInt *rearrange2ConsecutiveCellTypes(); @@ -747,6 +761,8 @@ namespace ParaMEDMEM public: static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=NO_TIME); void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + std::string advancedRepr() const; MEDCouplingFieldDouble *clone(bool recDeepCpy) const; MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const; @@ -774,10 +790,21 @@ namespace ParaMEDMEM void applyFunc(const char *func) throw(INTERP_KERNEL::Exception); double accumulate(int compId) const throw(INTERP_KERNEL::Exception); double getMaxValue() const throw(INTERP_KERNEL::Exception); + double getMinValue() const throw(INTERP_KERNEL::Exception); + double getAverageValue() const throw(INTERP_KERNEL::Exception); + double getWeightedAverageValue() const throw(INTERP_KERNEL::Exception); double integral(int compId, bool isWAbs) const throw(INTERP_KERNEL::Exception); double normL1(int compId) const throw(INTERP_KERNEL::Exception); double normL2(int compId) const throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *dot(const MEDCouplingFieldDouble& other) const; + static MEDCouplingFieldDouble *crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *crossProduct(const MEDCouplingFieldDouble& other) const; + static MEDCouplingFieldDouble *maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const; + static MEDCouplingFieldDouble *minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const; MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception);