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)
//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;i<nbOfElem;i++)
+ pt[i*spaceDim+pos]=cptr[i];
+ pos++;
+ }
+ return ret;
+}
+
+DataArrayDouble *MEDCouplingCMesh::getBarycenterAndOwner() const
+{
+ DataArrayDouble *ret=DataArrayDouble::New();
+ int spaceDim=getSpaceDimension();
+ ret->alloc(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;i<nbOfElem;i++)
+ pt[i*spaceDim+pos]=(cptr[i]+cptr[i+1])/2.;
+ pos++;
+ }
+ return ret;
+}
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:
MEDCouplingCMesh();
~MEDCouplingCMesh();
MEDCouplingFieldDouble *MEDCouplingExtrudedMesh::getMeasureField(bool) const
{
+ //not implemented yet
return 0;
}
return 0;
}
+DataArrayDouble *MEDCouplingExtrudedMesh::getCoordinatesAndOwner() const
+{
+ DataArrayDouble *arr2D=_mesh2D->getCoords();
+ 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;i<nbOf1DLev;i++)
+ {
+ std::copy(ptSrc,ptSrc+3*nbOf2DNodes,pt+3*i*nbOf2DNodes);
+ double vec[3];
+ std::copy(arr1D->getConstPointer()+3*i,arr1D->getConstPointer()+3*(i+1),vec);
+ std::transform(arr1D->getConstPointer()+3*(i-1),arr1D->getConstPointer()+3*i,vec,vec,std::minus<double>());
+ for(int j=0;j<nbOf2DNodes;j++)
+ std::transform(vec,vec+3,pt+3*(i*nbOf2DNodes+j),pt+3*(i*nbOf2DNodes+j),std::plus<double>());
+ }
+ 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);
revDesc->decrRef();
revDescIndx->decrRef();
}
-
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);
return mesh->getNumberOfCells();
}
+DataArrayDouble *MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const
+{
+ return mesh->getBarycenterAndOwner();
+}
+
void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception)
{
}
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)
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;
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;
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;
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<const MEDCouplingFieldDouble *>(other);
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;i<nbOfTuple;i++,ptr+=nbOfComp)
- *ptr=a*(*ptr)+b;
+ _time_discr->applyLin(a,b,compoId);
+}
+
+void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func)
+{
+ _time_discr->applyFunc(nbOfComp,func);
}
int MEDCouplingFieldDouble::getNumberOfComponents() const
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;
+}
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; }
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();
void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
void serialize(std::vector<DataArrayDouble *>& arrays) const;
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);
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();
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<double>());
+ 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<double>());
+ 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<double>());
+ 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<double>());
+ ret->copyStringInfoFrom(*a1);
+ return ret;
+}
+
DataArrayInt *DataArrayInt::New()
{
return new DataArrayInt;
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:
// 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 <sstream>
+#include <iterator>
using namespace ParaMEDMEM;
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<nbOfTuple;i++)
+ {
+ if(!func(locPtr+nbCompIn*i,ptToFill))
+ {
+ std::ostringstream oss; oss << "For tuple # " << i << " localized on (";
+ std::copy(locPtr+nbCompIn*i,locPtr+nbCompIn*(i+1),std::ostream_iterator<double>(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);
+}
EXTRUDED = 8
} MEDCouplingMeshType;
+ class DataArrayDouble;
class MEDCouplingFieldDouble;
class MEDCOUPLING_EXPORT MEDCouplingMesh : public RefCountObject, public TimeLabel
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) { }
}
}
+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)
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;
{
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:
#include "MEDCouplingMemArray.hxx"
#include <cmath>
+#include <iterator>
using namespace ParaMEDMEM;
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)
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");
}
return true;
if(_array==0 || other->_array==0)
return false;
+ if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
+ return false;
return true;
}
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<int>& tinyInfo) const
{
if(_array)
return time1<time2;
}
+void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId)
+{
+ double *ptr=_array->getPointer()+compoId;
+ int nbOfComp=_array->getNumberOfComponents();
+ int nbOfTuple=_array->getNumberOfTuples();
+ for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
+ *ptr=a*(*ptr)+b;
+}
+
+void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate func)
+{
+ DataArrayDouble *newArr=DataArrayDouble::New();
+ int nbOfTuples=_array->getNumberOfTuples();
+ int oldNbOfComp=_array->getNumberOfComponents();
+ newArr->alloc(nbOfTuples,nbOfComp);
+ const double *ptr=_array->getConstPointer();
+ double *ptrToFill=newArr->getPointer();
+ for(int i=0;i<nbOfTuples;i++)
+ {
+ if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
+ {
+ std::ostringstream oss; oss << "For tuple # " << i << " with value (";
+ std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
+ oss << ") : Evaluation of function failed !";
+ newArr->decrRef();
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ _array->decrRef();
+ _array=newArr;
+}
+
MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
{
}
return ret;
}
+MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const
+{
+ const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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<const MEDCouplingNoTimeLabel *>(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<const MEDCouplingNoTimeLabel *>(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<const MEDCouplingNoTimeLabel *>(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);
if(!MEDCouplingTimeDiscretization::areCompatible(other))
return false;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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
return ret;
}
+MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const
+{
+ const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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<const MEDCouplingWithTimeStep *>(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<const MEDCouplingWithTimeStep *>(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<const MEDCouplingWithTimeStep *>(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);
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<int>& 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<double>& tinyInfo) const
+{
+ MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
+ tinyInfo.push_back(_start_time);
+ tinyInfo.push_back(_end_time);
+}
+
+void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
+{
+ MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
+ _start_time=tinyInfoD[1];
+ _end_time=tinyInfoD[2];
+ _start_dt=tinyInfoI[2];
+ _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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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)
{
}
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<int>& tinyInfo) const;
virtual void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
virtual void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
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;
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;
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<int>& tinyInfo) const;
int _it;
};
+ class MEDCOUPLING_EXPORT MEDCouplingConstOnTimeInterval : public MEDCouplingTimeDiscretization
+ {
+ protected:
+ MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCpy);
+ public:
+ MEDCouplingConstOnTimeInterval();
+ void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
+ void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
+ void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
+ MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const;
+ 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:
if(other->getType()!=UNSTRUCTURED)
throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh each other !");
const MEDCouplingUMesh *otherC=static_cast<const MEDCouplingUMesh *>(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<nbOfCells;i++)
+ {
+ int nbOfPts=0;
+ std::fill(tmp,tmp+spaceDim,0.);
+ for(const int *node=nodal+nodalI[i]+1;node!=nodal+nodalI[i+1];node++)
+ if(*node!=-1)
+ {
+ std::transform(tmp,tmp+spaceDim,coor+(*node)*spaceDim,tmp,std::plus<double>());
+ nbOfPts++;
+ }
+ ptToFill=std::transform(tmp,tmp+spaceDim,ptToFill,std::bind2nd(std::divides<double>(),(double)nbOfPts));
+ }
+ delete [] tmp;
+ return ret;
+}
+
+MEDCouplingUMesh *MEDCouplingUMesh::mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2)
{
MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
DataArrayDouble *pts=mergeNodesArray(mesh1,mesh2);
MEDCouplingFieldDouble *getMeasureField(bool isAbs) const;
void checkButterflyCells(std::vector<int>& 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);
return 0;
}
+DataArrayDouble *MEDCouplingUMeshDesc::getBarycenterAndOwner() const
+{
+ //not implemented yet.
+ return 0;
+}
MEDCouplingFieldDouble *getMeasureField(bool isAbs) const;
DataArrayInt *zipCoordsTraducer();
MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const;
+ DataArrayDouble *getBarycenterAndOwner() const;
private:
MEDCouplingUMeshDesc();
~MEDCouplingUMeshDesc();