//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)
int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
void getCoordinatesOfNode(int nodeId, std::vector<double>& 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,
coo.insert(coo.end(),tmp2.begin(),tmp2.end());
}
+std::string MEDCouplingExtrudedMesh::simpleRepr() 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->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)
{
}
int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
void getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const;
+ std::string simpleRepr() const;
+ std::string advancedRepr() const;
void checkCoherency() const throw (INTERP_KERNEL::Exception);
void getBoundingBox(double *bbox) const;
void updateTime();
}
/*!
- * 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
}
}
+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<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ int arrayId=0;
+ for(std::vector<DataArrayDouble *>::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<const MEDCouplingFieldDouble *>(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
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))
}
/*!
- * 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;i<nbTuple;i++)
- ret+=ptr[i*nbComps+compId];
- return ret;
+ if(getArray()==0)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
+ return getArray()->accumulate(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)
}
/*!
- * 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<nbTuple;i++)
- std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<double>());
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ double ret=std::numeric_limits<double>::max();
+ bool isExistingArr=false;
+ for(std::vector<DataArrayDouble *>::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;
}
/*!
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))
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;
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);
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);
#include "MEDCouplingMemArray.txx"
#include <set>
+#include <numeric>
#include <functional>
using namespace ParaMEDMEM;
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<std::string>::const_iterator iter=_info_on_compo.begin();iter!=_info_on_compo.end();iter++)
+ stream << "\"" << *iter << "\" ";
+ stream << "\n";
+}
+
DataArrayDouble *DataArrayDouble::New()
{
return new DataArrayDouble;
_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))
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<nbTuple;i++)
+ std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<double>());
+}
+
+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;i<nbTuple;i++)
+ ret+=ptr[i*nbComps+compId];
+ return ret;
+}
+
DataArrayDouble *DataArrayDouble::aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
{
int nbOfComp=a1->getNumberOfComponents();
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;i<nbOfTuple;i++)
+ {
+ double sum=0.;
+ for(int j=0;j<nbOfComp;j++)
+ sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
+ retPtr[i]=sum;
+ }
+ ret->setInfoOnComponent(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;i<nbOfTuple;i++)
+ {
+ retPtr[3*i]=a1Ptr[3*i+1]*a2Ptr[3*i+2]-a1Ptr[3*i+2]*a2Ptr[3*i+1];
+ retPtr[3*i+1]=a1Ptr[3*i+2]*a2Ptr[3*i]-a1Ptr[3*i]*a2Ptr[3*i+2];
+ retPtr[3*i+2]=a1Ptr[3*i]*a2Ptr[3*i+1]-a1Ptr[3*i+1]*a2Ptr[3*i];
+ }
+ ret->copyStringInfoFrom(*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;i<nbElem;i++)
+ retPtr[i]=std::max(a1Ptr[i],a2Ptr[i]);
+ ret->copyStringInfoFrom(*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;i<nbElem;i++)
+ retPtr[i]=std::min(a1Ptr[i],a2Ptr[i]);
+ ret->copyStringInfoFrom(*a1);
+ return ret;
+}
+
DataArrayDouble *DataArrayDouble::add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
{
int nbOfComp=a1->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
_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)
#include <string>
#include <vector>
+#include <iterator>
namespace ParaMEDMEM
{
T operator[](int id) const { return _pointer.getConstPointer()[id]; }
T& operator[](int id) { return _pointer.getPointer()[id]; }
bool isEqual(const MemArray<T>& 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);
int _nb_of_elem;
bool _ownership;
MEDCouplingPointer<T> _pointer;
- //T *_pointer;
DeallocType _dealloc;
};
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<std::string> &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(); }
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);
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);
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);
return true;
}
+ /*!
+ * @param sl is typically the number of components [in parameter]
+ */
+ template<class T>
+ void MemArray<T>::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<nbOfTuples;i++)
+ {
+ stream << "Tuple #" << i << " : ";
+ std::copy(data,data+sl,std::ostream_iterator<T>(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<class T>
+ void MemArray<T>::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<nbOfTuples;i++)
+ {
+ stream << "|";
+ std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
+ stream << "| ";
+ data+=sl;
+ }
+ stream << "\n";
+ }
+ else
+ stream << "Empty Data\n";
+ }
+ else
+ stream << "No data !\n";
+ }
+
template<class T>
void MemArray<T>::fillWithValue(const T& val)
{
virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0;
virtual void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const = 0;
virtual void getCoordinatesOfNode(int nodeId, std::vector<double>& 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;
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)
{
{
}
+std::string MEDCouplingNoTimeLabel::getStringRepr() const
+{
+ std::ostringstream stream;
+ stream << REPR;
+ return stream.str();
+}
+
bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretization *other) const
{
if(!MEDCouplingTimeDiscretization::areCompatible(other))
return ret;
}
+MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const
+{
+ const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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<const MEDCouplingNoTimeLabel *>(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<const MEDCouplingNoTimeLabel *>(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<const MEDCouplingNoTimeLabel *>(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<const MEDCouplingNoTimeLabel *>(other);
{
}
+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<int>& tinyInfo) const
{
MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
return ret;
}
+MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const
+{
+ const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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<const MEDCouplingWithTimeStep *>(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<const MEDCouplingWithTimeStep *>(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<const MEDCouplingWithTimeStep *>(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<const MEDCouplingWithTimeStep *>(other);
{
}
+void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other)
+{
+ MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
+ const MEDCouplingConstOnTimeInterval& otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval& >(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<int>& tinyInfo) const
{
MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
{
}
+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);
return ret;
}
+MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const
+{
+ const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(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<const MEDCouplingConstOnTimeInterval *>(other);
{
}
+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();
return ret;
}
+MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const
+{
+ const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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<const MEDCouplingLinearTime *>(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<const MEDCouplingLinearTime *>(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<const MEDCouplingLinearTime *>(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<const MEDCouplingLinearTime *>(other);
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;
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;
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[];
};
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;
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:
MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCpy);
public:
MEDCouplingConstOnTimeInterval();
+ void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other);
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);
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;
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:
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;
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;
void divideEqual(const MEDCouplingTimeDiscretization *other);
public:
static const TypeOfTimeDiscretization DISCRETIZATION=LINEAR_TIME;
+ static const char REPR[];
};
}
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<INTERP_KERNEL::NormalizedCellType>::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<nbOfCells;i++)
+ {
+ const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel((INTERP_KERNEL::NormalizedCellType)c[ci[i]]);
+ stream << "Cell #" << i << " " << cm.getRepr() << " : ";
+ std::copy(c+ci[i]+1,c+ci[i+1],std::ostream_iterator<int>(stream," "));
+ stream << "\n";
+ }
+ }
+ else
+ stream << "Connectivity not defined !\n";
+}
+
int MEDCouplingUMesh::getNumberOfNodesInCell(int cellId) const
{
const int *ptI=_nodal_connec_index->getConstPointer();
MEDCOUPLING_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
MEDCOUPLING_EXPORT void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
MEDCOUPLING_EXPORT void getCoordinatesOfNode(int nodeId, std::vector<double>& 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;
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;
//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);
MEDCOUPLING_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
MEDCOUPLING_EXPORT void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
MEDCOUPLING_EXPORT void getCoordinatesOfNode(int nodeId, std::vector<double>& 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
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 );
void testChangeUnderlyingMesh1();
void testGetMaxValue1();
void testSubstractInPlaceDM1();
+ void testDotCrossProduct1();
+ void testMinMaxFields1();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
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();
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();
+}
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):
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
%template(ivec) std::vector<int>;
%template(dvec) std::vector<double>;
+%template(svec) std::vector<std::string>;
%typemap(out) ParaMEDMEM::MEDCouplingMesh*
{
%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*;
%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;
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<int>& conn) const = 0;
virtual void getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const = 0;
// tools
int getNumberOfNodesInCell(int cellId) const;
int getMeshLength() const;
void computeTypes();
+ std::string reprConnectivityOfThis() const;
//tools
bool checkConsecutiveCellTypes() const;
DataArrayInt *rearrange2ConsecutiveCellTypes();
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;
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);