* are created ('m1r' and 'm2r') that can be used for interpolation.
* @param m1 input mesh with meshDim==1 and spaceDim==3
* @param m2 input mesh with meshDim==1 and spaceDim==3
- * @param m1r output mesh with ref count equal to 1 with meshDim==1 and spaceDim==2
- * @param m2r output mesh with ref count equal to 1 with meshDim==1 and spaceDim==2
+ * @param eps tolerance acceptable to determine compatibility
+ * @param m1r output mesh with ref count equal to 1 with meshDim==1 and spaceDim==1
+ * @param m2r output mesh with ref count equal to 1 with meshDim==1 and spaceDim==1
+ * @param v is the output normalized vector of the common direction of 'm1' and 'm2'
* @throw in case that m1 and m2 are not compatible each other.
*/
-void MEDCouplingExtrudedMesh::project1DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2,
- MEDCouplingUMesh *&m1r, MEDCouplingUMesh *&m2r) throw(INTERP_KERNEL::Exception)
+void MEDCouplingExtrudedMesh::project1DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps,
+ MEDCouplingUMesh *&m1r, MEDCouplingUMesh *&m2r, double *v) throw(INTERP_KERNEL::Exception)
{
- m1r=0;
- m2r=0;
+ m1r=m1->clone(true);
+ m2r=m2->clone(true);
+ m1r->changeSpaceDimension(1);
+ m2r->changeSpaceDimension(1);
}
void MEDCouplingExtrudedMesh::rotate(const double *center, const double *vector, double angle)
int getCellContainingPoint(const double *pos, double eps) const;
static int findCorrespCellByNodalConn(const std::vector<int>& nodalConnec,
const int *revNodalPtr, const int *revNodalIndxPtr) throw(INTERP_KERNEL::Exception);
- static void project1DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2,
- MEDCouplingUMesh *&m1r, MEDCouplingUMesh *&m2r) throw(INTERP_KERNEL::Exception);
+ static void project1DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps,
+ MEDCouplingUMesh *&m1r, MEDCouplingUMesh *&m2r, double *v) throw(INTERP_KERNEL::Exception);
void rotate(const double *center, const double *vector, double angle);
void translate(const double *vector);
MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const;
return ret;
}
+void MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other)
+{
+ if(!areCompatible(&other))
+ throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply += on them !");
+ _time_discr->addEqual(other._time_discr);
+}
+
MEDCouplingFieldDouble *MEDCouplingFieldDouble::substractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
{
if(!f1->areCompatible(f2))
return ret;
}
+void MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other)
+{
+ if(!areCompatible(&other))
+ throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply -= on them !");
+ _time_discr->substractEqual(other._time_discr);
+}
+
MEDCouplingFieldDouble *MEDCouplingFieldDouble::multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
{
if(!f1->areCompatibleForMul(f2))
- throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to applymultiplyFields on them !");
+ throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply multiplyFields on them !");
MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr);
MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField());
ret->setMesh(f1->getMesh());
return ret;
}
+void MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other)
+{
+ if(!areCompatibleForMul(&other))
+ throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply *= on them !");
+ _time_discr->multiplyEqual(other._time_discr);
+}
+
MEDCouplingFieldDouble *MEDCouplingFieldDouble::divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
{
if(!f1->areCompatible(f2))
ret->setMesh(f1->getMesh());
return ret;
}
+
+void MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other)
+{
+ if(!areCompatible(&other))
+ throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !");
+ _time_discr->divideEqual(other._time_discr);
+}
bool mergeNodes(double eps);
static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const { return addFields(this,&other); }
+ void operator+=(const MEDCouplingFieldDouble& other);
static MEDCouplingFieldDouble *addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const { return substractFields(this,&other); }
+ void operator-=(const MEDCouplingFieldDouble& other);
static MEDCouplingFieldDouble *substractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const { return multiplyFields(this,&other); }
+ void operator*=(const MEDCouplingFieldDouble& other);
static MEDCouplingFieldDouble *multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const { return divideFields(this,&other); }
+ void operator/=(const MEDCouplingFieldDouble& other);
static MEDCouplingFieldDouble *divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
private:
MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td);
return ret;
}
+void DataArrayDouble::addEqual(const DataArrayDouble *other)
+{
+ int nbOfComp=getNumberOfComponents();
+ if(nbOfComp!=other->getNumberOfComponents())
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array add !");
+ int nbOfTuple=getNumberOfTuples();
+ if(nbOfTuple!=other->getNumberOfTuples())
+ throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array add !");
+ std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::plus<double>());
+ declareAsNew();
+}
+
DataArrayDouble *DataArrayDouble::substract(const DataArrayDouble *a1, const DataArrayDouble *a2)
{
int nbOfComp=a1->getNumberOfComponents();
return ret;
}
+void DataArrayDouble::substractEqual(const DataArrayDouble *other)
+{
+ int nbOfComp=getNumberOfComponents();
+ if(nbOfComp!=other->getNumberOfComponents())
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array substract !");
+ int nbOfTuple=getNumberOfTuples();
+ if(nbOfTuple!=other->getNumberOfTuples())
+ throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array substract !");
+ std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::minus<double>());
+ declareAsNew();
+}
+
DataArrayDouble *DataArrayDouble::multiply(const DataArrayDouble *a1, const DataArrayDouble *a2)
{
int nbOfTuple=a1->getNumberOfTuples();
return ret;
}
+void DataArrayDouble::multiplyEqual(const DataArrayDouble *other)
+{
+ int nbOfTuple=getNumberOfTuples();
+ int nbOfTuple2=other->getNumberOfTuples();
+ int nbOfComp=getNumberOfComponents();
+ 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<double>());
+ }
+ else
+ {
+ if(nbOfComp2==1)
+ {
+ const double *ptr=other->getConstPointer();
+ double *myPtr=getPointer();
+ for(int i=0;i<nbOfTuple;i++)
+ myPtr=std::transform(myPtr,myPtr+nbOfComp,myPtr,std::bind2nd(std::multiplies<double>(),ptr[i]));
+ }
+ else
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array multiplyEqual !");
+ }
+ declareAsNew();
+}
+
DataArrayDouble *DataArrayDouble::divide(const DataArrayDouble *a1, const DataArrayDouble *a2)
{
int nbOfComp=a1->getNumberOfComponents();
return ret;
}
+void DataArrayDouble::divideEqual(const DataArrayDouble *other)
+{
+ int nbOfComp=getNumberOfComponents();
+ if(nbOfComp!=other->getNumberOfComponents())
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array divideEqual !");
+ int nbOfTuple=getNumberOfTuples();
+ if(nbOfTuple!=other->getNumberOfTuples())
+ throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array divideEqual !");
+ std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::divides<double>());
+ declareAsNew();
+}
+
DataArrayInt *DataArrayInt::New()
{
return new DataArrayInt;
return ret;
}
+int *DataArrayInt::checkAndPreparePermutation(const int *start, const int *end)
+{
+ int sz=std::distance(start,end);
+ int *ret=new int[sz];
+ int *work=new int[sz];
+ std::copy(start,end,work);
+ std::sort(work,work+sz);
+ if(std::unique(work,work+sz)!=work+sz)
+ {
+ delete [] work;
+ delete [] ret;
+ throw INTERP_KERNEL::Exception("Some elements are equals in the specified array !");
+ }
+ int *iter2=ret;
+ for(const int *iter=start;iter!=end;iter++,iter2++)
+ *iter2=std::distance(work,std::find(work,work+sz,*iter));
+ delete [] work;
+ return ret;
+}
MEDCOUPLING_EXPORT void checkNoNullValues() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT static DataArrayDouble *aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2);
MEDCOUPLING_EXPORT static DataArrayDouble *add(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT void addEqual(const DataArrayDouble *other);
MEDCOUPLING_EXPORT static DataArrayDouble *substract(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT void substractEqual(const DataArrayDouble *other);
MEDCOUPLING_EXPORT static DataArrayDouble *multiply(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT void multiplyEqual(const DataArrayDouble *other);
MEDCOUPLING_EXPORT static DataArrayDouble *divide(const DataArrayDouble *a1, const DataArrayDouble *a2);
+ MEDCOUPLING_EXPORT void divideEqual(const DataArrayDouble *other);
//! nothing to do here because this class does not aggregate any TimeLabel instance.
MEDCOUPLING_EXPORT void updateTime() { }
private:
MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
//! nothing to do here because this class does not aggregate any TimeLabel instance.
MEDCOUPLING_EXPORT void updateTime() { }
+ public:
+ MEDCOUPLING_EXPORT static int *checkAndPreparePermutation(const int *start, const int *end);
private:
DataArrayInt() { }
private:
updateTime();
}
+/*!
+ * This method is only available for already defined coordinates.
+ * If not an INTERP_KERNEL::Exception is thrown. The 'newSpaceDim' input must be greater or equal to 1.
+ * This method simply convert this to newSpaceDim space :
+ * - by putting a 0. for each \f$ i^{th} \f$ components of each coord of nodes so that i>=getSpaceDim(), if 'newSpaceDim'>getSpaceDimsion()
+ * - by ignoring each \f$ i^{th} \f$ components of each coord of nodes so that i >= 'newSpaceDim', 'newSpaceDim'<getSpaceDimension()
+ * If newSpaceDim==getSpaceDim() nothing is done by this method.
+ */
+void MEDCouplingPointSet::changeSpaceDimension(int newSpaceDim) throw(INTERP_KERNEL::Exception)
+{
+ if(getCoords()==0)
+ throw INTERP_KERNEL::Exception("changeSpaceDimension must be called on an MEDCouplingPointSet instance with coordinates set !");
+ if(newSpaceDim<1)
+ throw INTERP_KERNEL::Exception("changeSpaceDimension must be called a newSpaceDim >=1 !");
+ int oldSpaceDim=getSpaceDimension();
+ if(newSpaceDim==oldSpaceDim)
+ return ;
+ DataArrayDouble *newCoords=DataArrayDouble::New();
+ newCoords->alloc(getCoords()->getNumberOfTuples(),newSpaceDim);
+ const double *oldc=getCoords()->getConstPointer();
+ double *nc=newCoords->getPointer();
+ int nbOfNodes=getNumberOfNodes();
+ int dim=std::min(oldSpaceDim,newSpaceDim);
+ for(int i=0;i<nbOfNodes;i++)
+ {
+ int j=0;
+ for(;j<dim;j++)
+ nc[newSpaceDim*i+j]=oldc[i*oldSpaceDim+j];
+ for(;j<newSpaceDim;j++)
+ nc[newSpaceDim*i+j]=0.;
+ }
+ newCoords->setName(getCoords()->getName().c_str());
+ for(int i=0;i<dim;i++)
+ newCoords->setInfoOnComponent(i,getCoords()->getInfoOnComponent(i).c_str());
+ setCoords(newCoords);
+ newCoords->decrRef();
+}
+
/*!
* This method try to substitute this->_coords with other._coords if arrays match.
* This method potentially modifies 'this' if it succeeds, otherway an exception is thrown.
void rotate(const double *center, const double *vector, double angle);
void translate(const double *vector);
void scale(const double *point, double factor);
+ void changeSpaceDimension(int newSpaceDim) throw(INTERP_KERNEL::Exception);
void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception);
void findNodesOnPlane(const double *pt, const double *vec, double eps, std::vector<int>& nodes) const throw(INTERP_KERNEL::Exception);
static DataArrayDouble *mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2);
std::vector<std::map<int,double> > matrix2D;
int nbCols2D=interpolation.interpolateMeshes(source_mesh_wrapper,target_mesh_wrapper,matrix2D,method);
MEDCouplingUMesh *s1D,*t1D;
- MEDCouplingExtrudedMesh::project1DMeshes(src_mesh->getMesh1D(),target_mesh->getMesh1D(),s1D,t1D);
+ double v[3];
+ MEDCouplingExtrudedMesh::project1DMeshes(src_mesh->getMesh1D(),target_mesh->getMesh1D(),getPrecision(),s1D,t1D,v);
MEDCouplingNormalizedUnstructuredMesh<2,1> s1DWrapper(s1D);
MEDCouplingNormalizedUnstructuredMesh<2,1> t1DWrapper(t1D);
std::vector<std::map<int,double> > matrix1D;
{
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
if(!otherC)
- throw INTERP_KERNEL::Exception("aggregation on mismatched time discretization !");
+ throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !");
MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
ret->setTimeTolerance(getTimeTolerance());
DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray());
{
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
if(!otherC)
- throw INTERP_KERNEL::Exception("add on mismatched time discretization !");
+ throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !");
MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray());
ret->setArray(arr,0);
return ret;
}
+void MEDCouplingNoTimeLabel::addEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("NoTimeLabel::addEqual on mismatched time discretization !");
+ getArray()->addEqual(other->getArray());
+}
+
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 !");
+ throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !");
MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray());
ret->setArray(arr,0);
return ret;
}
+void MEDCouplingNoTimeLabel::substractEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("NoTimeLabel::substractEqual on mismatched time discretization !");
+ getArray()->substractEqual(other->getArray());
+}
+
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 !");
+ throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !");
MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
DataArrayDouble *arr=DataArrayDouble::multiply(getArray(),other->getArray());
ret->setArray(arr,0);
return ret;
}
+void MEDCouplingNoTimeLabel::multiplyEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("NoTimeLabel::multiplyEqual on mismatched time discretization !");
+ getArray()->multiplyEqual(other->getArray());
+}
+
MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const
{
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
return ret;
}
+void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("NoTimeLabel::divideEqual on mismatched time discretization !");
+ getArray()->divideEqual(other->getArray());
+}
+
MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCpy(bool deepCpy) const
{
return new MEDCouplingNoTimeLabel(*this,deepCpy);
{
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
if(!otherC)
- throw INTERP_KERNEL::Exception("aggregation on mismatched time discretization !");
+ throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !");
MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
ret->setTimeTolerance(getTimeTolerance());
DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray());
{
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
if(!otherC)
- throw INTERP_KERNEL::Exception("add on mismatched time discretization !");
+ throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !");
MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray());
ret->setArray(arr,0);
return ret;
}
+void MEDCouplingWithTimeStep::addEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("WithTimeStep::addEqual on mismatched time discretization !");
+ getArray()->addEqual(other->getArray());
+}
+
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 !");
+ throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !");
MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray());
ret->setArray(arr,0);
return ret;
}
+void MEDCouplingWithTimeStep::substractEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("WithTimeStep::substractEqual on mismatched time discretization !");
+ getArray()->substractEqual(other->getArray());
+}
+
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 !");
+ throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !");
MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
DataArrayDouble *arr=DataArrayDouble::multiply(getArray(),other->getArray());
ret->setArray(arr,0);
return ret;
}
+void MEDCouplingWithTimeStep::multiplyEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("WithTimeStep::multiplyEqual on mismatched time discretization !");
+ getArray()->multiplyEqual(other->getArray());
+}
+
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 !");
+ throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !");
MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
DataArrayDouble *arr=DataArrayDouble::divide(getArray(),other->getArray());
ret->setArray(arr,0);
return ret;
}
+void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("WithTimeStep::divideEqual on mismatched time discretization !");
+ getArray()->divideEqual(other->getArray());
+}
+
MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCpy(bool deepCpy) const
{
return new MEDCouplingWithTimeStep(*this,deepCpy);
{
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
if(!otherC)
- throw INTERP_KERNEL::Exception("aggregation on mismatched time discretization !");
+ throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !");
MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
ret->setTimeTolerance(getTimeTolerance());
DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray());
{
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
if(!otherC)
- throw INTERP_KERNEL::Exception("add on mismatched time discretization !");
+ throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !");
MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray());
ret->setArray(arr,0);
ret->setEndTime(tmp3,tmp1,tmp2);
return ret;
}
+
+void MEDCouplingConstOnTimeInterval::addEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("ConstOnTimeInterval::addEqual on mismatched time discretization !");
+ getArray()->addEqual(other->getArray());
+}
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 !");
+ throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !");
MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray());
ret->setArray(arr,0);
return ret;
}
+void MEDCouplingConstOnTimeInterval::substractEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substractEqual on mismatched time discretization !");
+ getArray()->substractEqual(other->getArray());
+}
+
MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const
{
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
return ret;
}
+void MEDCouplingConstOnTimeInterval::multiplyEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("ConstOnTimeInterval::multiplyEqual on mismatched time discretization !");
+ getArray()->multiplyEqual(other->getArray());
+}
+
MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const
{
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
return ret;
}
+void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretization *other)
+{
+ const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("ConstOnTimeInterval::divideEqual on mismatched time discretization !");
+ getArray()->divideEqual(other->getArray());
+}
+
MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_dt(-1),_end_dt(-1),_start_it(-1),_end_it(-1),_end_array(0)
{
}
virtual TypeOfTimeDiscretization getEnum() const = 0;
virtual MEDCouplingTimeDiscretization *aggregate(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;
+ virtual void substractEqual(const MEDCouplingTimeDiscretization *other) = 0;
virtual MEDCouplingTimeDiscretization *multiply(const MEDCouplingTimeDiscretization *other) const = 0;
+ virtual void multiplyEqual(const MEDCouplingTimeDiscretization *other) = 0;
virtual MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const = 0;
+ virtual void divideEqual(const MEDCouplingTimeDiscretization *other) = 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;
TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; }
MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const;
MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const;
+ void addEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const;
+ void substractEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *multiply(const MEDCouplingTimeDiscretization *other) const;
+ void multiplyEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const;
+ void divideEqual(const MEDCouplingTimeDiscretization *other);
bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
bool areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; }
MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const;
MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const;
+ void addEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const;
+ void substractEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *multiply(const MEDCouplingTimeDiscretization *other) const;
+ void multiplyEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const;
+ void divideEqual(const MEDCouplingTimeDiscretization *other);
bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
bool areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; }
MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const;
MEDCouplingTimeDiscretization *add(const MEDCouplingTimeDiscretization *other) const;
+ void addEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *substract(const MEDCouplingTimeDiscretization *other) const;
+ void substractEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *multiply(const MEDCouplingTimeDiscretization *other) const;
+ void multiplyEqual(const MEDCouplingTimeDiscretization *other);
MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const;
+ void divideEqual(const MEDCouplingTimeDiscretization *other);
void setStartTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _start_time=time; _start_dt=dt; _start_it=it; }
void setEndTime(double time, int dt, int it) throw(INTERP_KERNEL::Exception) { _end_time=time; _end_dt=dt; _end_it=it; }
double getStartTime(int& dt, int& it) const throw(INTERP_KERNEL::Exception) { dt=_start_dt; it=_start_it; return _start_time; }
updateTime();
}
+/*!
+ * This method renumbers cells of 'this' using the array specified by [old2NewBg;old2NewEnd)
+ * If std::distance(old2NewBg,old2NewEnd)!=this->getNumberOfCells() an INTERP_KERNEL::Exception will be thrown.
+ *
+ * If 'check' equals true the method will check that any elements in [old2NewBg;old2NewEnd) is unique ; if not
+ * an INTERP_KERNEL::Exception will be thrown. When 'check' equals true [old2NewBg;old2NewEnd) is not expected to
+ * be strictly in [0;this->getNumberOfCells()).
+ *
+ * If 'check' equals false the method will not check the content of [old2NewBg;old2NewEnd).
+ * To avoid any throw of SIGSEGV when 'check' equals false, the elements in [old2NewBg;old2NewEnd) should be unique and
+ * should be contained in[0;this->getNumberOfCells()).
+ */
+void MEDCouplingUMesh::renumberCells(const int *old2NewBg, const int *old2NewEnd, bool check)
+{
+ int nbCells=getNumberOfCells();
+ const int *array=old2NewBg;
+ if(std::distance(old2NewBg,old2NewEnd)!=nbCells)
+ throw INTERP_KERNEL::Exception("MEDCouplingUMesh::renumberCells expected to take an array of size getNumberOfCells !");
+ if(check)
+ array=DataArrayInt::checkAndPreparePermutation(old2NewBg,old2NewEnd);
+ //
+ const int *conn=_nodal_connec->getConstPointer();
+ const int *connI=_nodal_connec_index->getConstPointer();
+ DataArrayInt *newConn=DataArrayInt::New();
+ newConn->alloc(_nodal_connec->getNumberOfTuples(),_nodal_connec->getNumberOfComponents());
+ newConn->copyStringInfoFrom(*_nodal_connec);
+ DataArrayInt *newConnI=DataArrayInt::New();
+ newConnI->alloc(_nodal_connec_index->getNumberOfTuples(),_nodal_connec_index->getNumberOfComponents());
+ newConnI->copyStringInfoFrom(*_nodal_connec_index);
+ //
+ int *newC=newConn->getPointer();
+ int *newCI=newConnI->getPointer();
+ int loc=0;
+ newCI[0]=loc;
+ for(int i=0;i<nbCells;i++)
+ {
+ int pos=std::distance(array,std::find(array,array+nbCells,i));
+ int nbOfElts=connI[pos+1]-connI[pos];
+ newC=std::copy(conn+connI[pos],conn+connI[pos+1],newC);
+ loc+=nbOfElts;
+ newCI[i+1]=loc;
+ }
+ //
+ setConnectivity(newConn,newConnI);
+ //
+ newConn->decrRef();
+ newConnI->decrRef();
+ if(check)
+ delete [] (int *)array;
+}
+
/*!
* Given a boundary box 'bbox' returns elements 'elems' contained in this 'bbox'.
* Warning 'elems' is incremented during the call so if elems is not empty before call returned elements will be
return ret;
}
+/*!
+ * This methods returns a vector newly created field on cells that represents the director vector of each 1D cell of this.
+ * This method is only callable on mesh with meshdim == 1 containing only SEG2.
+ */
+MEDCouplingFieldDouble *MEDCouplingUMesh::buildLinearField() const
+{
+ if(getMeshDimension()!=1)
+ throw INTERP_KERNEL::Exception("Expected a umesh with meshDim == 1 for buildLinearField !");
+ if(_types.size()!=1 || *(_types.begin())!=INTERP_KERNEL::NORM_SEG2)
+ throw INTERP_KERNEL::Exception("Expected a umesh with only NORM_SEG2 type of elements for buildLinearField !");
+ MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+ DataArrayDouble *array=DataArrayDouble::New();
+ int nbOfCells=getNumberOfCells();
+ int spaceDim=getSpaceDimension();
+ array->alloc(nbOfCells,spaceDim);
+ double *pt=array->getPointer();
+ const double *coo=getCoords()->getConstPointer();
+ std::vector<int> conn;
+ conn.reserve(2);
+ for(int i=0;i<nbOfCells;i++)
+ {
+ conn.resize(0);
+ getNodeIdsOfCell(i,conn);
+ pt=std::transform(coo+conn[1]*spaceDim,coo+(conn[1]+1)*spaceDim,coo+conn[0]*spaceDim,pt,std::minus<double>());
+ }
+ array->alloc(nbOfCells,spaceDim);
+ array->decrRef();
+ ret->setMesh(this);
+ return ret;
+}
+
/*!
* Returns a cell if any that contains the point located on 'pos' with precison eps.
* If 'pos' is outside 'this' -1 is returned. If several cells contain this point the cell with the smallest id is returned.
MEDCOUPLING_EXPORT void findBoundaryNodes(std::vector<int>& nodes) const;
MEDCOUPLING_EXPORT MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const;
MEDCOUPLING_EXPORT void renumberNodes(const int *newNodeNumbers, int newNbOfNodes);
+ MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, const int *old2NewEnd, bool check);
MEDCOUPLING_EXPORT void giveElemsInBoundingBox(const double *bbox, double eps, std::vector<int>& elems);
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureField(bool isAbs) const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildOrthogonalField() const;
+ MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildLinearField() const;
MEDCOUPLING_EXPORT int getCellContainingPoint(const double *pos, double eps) const;
MEDCOUPLING_EXPORT void getCellsContainingPoint(const double *pos, double eps, std::vector<int>& elts) const;
MEDCOUPLING_EXPORT void getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector<int>& elts, std::vector<int>& eltsIndex) const;
CPPUNIT_TEST( testApplyFunc2 );
CPPUNIT_TEST( testOperationsOnFields );
CPPUNIT_TEST( testOperationsOnFields2 );
+ CPPUNIT_TEST( testOperationsOnFields3 );
CPPUNIT_TEST( testMergeNodesOnField );
CPPUNIT_TEST( testCheckConsecutiveCellTypes );
CPPUNIT_TEST( testBuildOrthogonalField );
CPPUNIT_TEST( testScale );
CPPUNIT_TEST( testTryToShareSameCoords );
CPPUNIT_TEST( testFindNodeOnPlane );
+ CPPUNIT_TEST( testRenumberCells );
+ CPPUNIT_TEST( testChangeSpaceDimension );
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_2 );
void testApplyFunc2();
void testOperationsOnFields();
void testOperationsOnFields2();
+ void testOperationsOnFields3();
void testMergeNodesOnField();
void testCheckConsecutiveCellTypes();
void testBuildOrthogonalField();
void testScale();
void testTryToShareSameCoords();
void testFindNodeOnPlane();
+ void testRenumberCells();
+ void testChangeSpaceDimension();
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
void test2DInterpP0P0PL_2();
m->decrRef();
}
+void MEDCouplingBasicsTest::testOperationsOnFields3()
+{
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
+ MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
+ (*f1)/=(*f2);
+ f1->checkCoherency();
+ CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
+ CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
+ const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
+ 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
+ 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
+ CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
+ const double *val=f1->getArray()->getConstPointer();
+ for(int i=0;i<9;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
+ f1->decrRef();
+ f2->decrRef();
+ //
+ f1=m->buildOrthogonalField();
+ f2=m->fillFromAnalytic(ON_CELLS,1,"x");
+ (*f1)*=(*f2);
+ const double expected2[15]={-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637};
+ val=f1->getArray()->getConstPointer();
+ for(int i=0;i<15;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
+ f1->decrRef();
+ //
+ f1=m->buildOrthogonalField();
+ CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
+ f1->decrRef();
+ f2->decrRef();
+ //
+ m->decrRef();
+}
+
bool func4(const double *pt, double *res)
{
res[0]=pt[0]+pt[1]+pt[2];
m3dSurf->decrRef();
mesh->decrRef();
}
+
+void MEDCouplingBasicsTest::testRenumberCells()
+{
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
+ CPPUNIT_ASSERT(m->isEqual(m2,0));
+ const int arr[5]={12,3,25,2,26};
+ m->renumberCells(arr,arr+5,true);
+ CPPUNIT_ASSERT(!m->isEqual(m2,0));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
+ const int arr2[5]={5,-1,-5,4,8};
+ m->renumberCells(arr2,arr2+5,true);
+ CPPUNIT_ASSERT(m->isEqual(m2,0));
+ m->decrRef();
+ m2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testChangeSpaceDimension()
+{
+ MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
+ MEDCouplingUMesh *m2=build2DTargetMesh_1();
+ //
+ CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
+ m1->changeSpaceDimension(2);
+ CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
+ m1->setName(m2->getName());
+ CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
+ m1->changeSpaceDimension(3);
+ CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
+ const double expected[27]={-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0.};
+ const double *val=m1->getCoords()->getConstPointer();
+ for(int i=0;i<27;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
+ //
+ m1->decrRef();
+ m2->decrRef();
+}