MEDCouplingAutoRefCountObjectPtr(const MEDCouplingAutoRefCountObjectPtr& other):_ptr(0) { referPtr(other._ptr); }
MEDCouplingAutoRefCountObjectPtr(T *ptr=0):_ptr(ptr) { }
~MEDCouplingAutoRefCountObjectPtr() { destroyPtr(); }
+ bool operator==(const MEDCouplingAutoRefCountObjectPtr& other) { return _ptr==other._ptr; }
MEDCouplingAutoRefCountObjectPtr &operator=(const MEDCouplingAutoRefCountObjectPtr& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; }
MEDCouplingAutoRefCountObjectPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
T *operator->() { return _ptr ; }
{
std::ostringstream ret;
ret << "Cartesian mesh with name : \"" << getName() << "\"\n";
+ ret << "Description of mesh : \"" << getDescription() << "\"\n";
ret << "Mesh and SpaceDimension dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n";
if(_x_array)
{
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "MEDCouplingDefinitionTime.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+
+#include <cmath>
+
+using namespace ParaMEDMEM;
+
+MEDCouplingDefinitionTimeSlice *MEDCouplingDefinitionTimeSlice::New(const MEDCouplingFieldDouble *f, int meshId, const std::vector<int>& arrId, int fieldId) throw(INTERP_KERNEL::Exception)
+{
+ static const char msg[]="TimeSlice::New : mismatch of arrays number of a fieldDouble and its policy !!! Internal error !!!";
+ if(!f)
+ throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTimeSlice::New : empty field !");
+ switch(f->getTimeDiscretization())
+ {
+ case ONE_TIME:
+ {
+ if(arrId.size()!=1)
+ throw INTERP_KERNEL::Exception(msg);
+ return new MEDCouplingDefinitionTimeSliceInst(f,meshId,arrId[0],fieldId);
+ }
+ case CONST_ON_TIME_INTERVAL:
+ {
+ if(arrId.size()!=1)
+ throw INTERP_KERNEL::Exception(msg);
+ return new MEDCouplingDefinitionTimeSliceCstOnTI(f,meshId,arrId[0],fieldId);
+ }
+ case LINEAR_TIME:
+ {
+ if(arrId.size()!=2)
+ throw INTERP_KERNEL::Exception(msg);
+ return new MEDCouplingDefinitionTimeSliceLT(f,meshId,arrId[0],arrId[1],fieldId);
+ }
+ case NO_TIME:
+ throw INTERP_KERNEL::Exception("Invalide time discretization ! NO_TIME ! Impossible to build a definition time slice !");
+ default:
+ throw INTERP_KERNEL::Exception("Invalide time discretization : Not recognized !");
+ }
+}
+
+int MEDCouplingDefinitionTimeSlice::getStartId() const
+{
+ return _array_id;
+}
+
+int MEDCouplingDefinitionTimeSlice::getEndId() const
+{
+ return _array_id;
+}
+
+void MEDCouplingDefinitionTimeSlice::appendRepr(std::ostream& stream) const
+{
+ stream << " *** MeshId : " << _mesh_id << " ArrayId : " << _array_id;
+}
+
+MEDCouplingDefinitionTimeSlice::MEDCouplingDefinitionTimeSlice(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception):_mesh_id(meshId),_array_id(arrId),_field_id(fieldId)
+{
+ int tmp1,tmp2;
+ double t1=f->getStartTime(tmp1,tmp2);
+ double t2=f->getEndTime(tmp1,tmp2);
+ if(t2<t1)
+ throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTimeSlice : End time strictly before Start time ...");
+}
+
+bool MEDCouplingDefinitionTimeSlice::isFullyIncludedInMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const
+{
+ double t1=getStartTime();
+ double t2=getEndTime();
+ double o1=other->getStartTime();
+ double o2=other->getEndTime();
+ return o1>t1-eps && o2<t2+eps;
+}
+
+bool MEDCouplingDefinitionTimeSlice::isOverllapingWithMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const
+{
+ double t1=getStartTime();
+ double t2=getEndTime();
+ double o1=other->getStartTime();
+ double o2=other->getEndTime();
+ return (o1<t1+eps && o2<t1+eps) || (o1>t2-eps && o2>t2-eps);
+}
+
+bool MEDCouplingDefinitionTimeSlice::isAfterMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const
+{
+ double t2=getEndTime();
+ double o1=other->getStartTime();
+ double o2=other->getEndTime();
+ return (o1>t2-eps && o2>t2-eps);
+}
+
+bool MEDCouplingDefinitionTimeSlice::isBeforeMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const
+{
+ double t1=getStartTime();
+ double o1=other->getStartTime();
+ double o2=other->getEndTime();
+ return (o1<t1+eps && o2<t1+eps);
+}
+
+bool MEDCouplingDefinitionTimeSliceInst::isContaining(double tmp, double eps) const
+{
+ return fabs(tmp-_instant)<eps;
+}
+
+void MEDCouplingDefinitionTimeSliceInst::appendRepr(std::ostream& stream) const
+{
+ stream << "single point " << _instant;
+ MEDCouplingDefinitionTimeSlice::appendRepr(stream);
+}
+
+double MEDCouplingDefinitionTimeSliceInst::getStartTime() const
+{
+ return _instant;
+}
+
+double MEDCouplingDefinitionTimeSliceInst::getEndTime() const
+{
+ return _instant;
+}
+
+MEDCouplingDefinitionTimeSliceInst::MEDCouplingDefinitionTimeSliceInst(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception):MEDCouplingDefinitionTimeSlice(f,meshId,arrId,fieldId)
+{
+ int tmp1,tmp2;
+ double t1=f->getStartTime(tmp1,tmp2);
+ double t2=f->getEndTime(tmp1,tmp2);
+ double eps=f->getTimeTolerance();
+ if(fabs(t1-t2)>eps)
+ throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTimeSliceInst : times differs in this");
+ _instant=t1;
+}
+
+bool MEDCouplingDefinitionTimeSliceCstOnTI::isContaining(double tmp, double eps) const
+{
+ return _start-eps>tmp && _end+eps<tmp;
+}
+
+void MEDCouplingDefinitionTimeSliceCstOnTI::appendRepr(std::ostream& stream) const
+{
+ stream << "Constant on time interval [" << _start << "," << _end << "]";
+ MEDCouplingDefinitionTimeSlice::appendRepr(stream);
+}
+
+double MEDCouplingDefinitionTimeSliceCstOnTI::getStartTime() const
+{
+ return _start;
+}
+
+double MEDCouplingDefinitionTimeSliceCstOnTI::getEndTime() const
+{
+ return _end;
+}
+
+MEDCouplingDefinitionTimeSliceCstOnTI::MEDCouplingDefinitionTimeSliceCstOnTI(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception):MEDCouplingDefinitionTimeSlice(f,meshId,arrId,fieldId)
+{
+ int tmp1,tmp2;
+ double t1=f->getStartTime(tmp1,tmp2);
+ double t2=f->getEndTime(tmp1,tmp2);
+ _start=t1;
+ _end=t2;
+}
+
+bool MEDCouplingDefinitionTimeSliceLT::isContaining(double tmp, double eps) const
+{
+ return _start-eps>tmp && _end+eps<tmp;
+}
+
+void MEDCouplingDefinitionTimeSliceLT::appendRepr(std::ostream& stream) const
+{
+ stream << "Linear on time interval [" << _start << "," << _end << "]";
+ MEDCouplingDefinitionTimeSlice::appendRepr(stream);
+ stream << " EndArrayId : " << _array_id_end;
+}
+
+double MEDCouplingDefinitionTimeSliceLT::getStartTime() const
+{
+ return _start;
+}
+
+double MEDCouplingDefinitionTimeSliceLT::getEndTime() const
+{
+ return _end;
+}
+
+int MEDCouplingDefinitionTimeSliceLT::getEndId() const
+{
+ return _array_id_end;
+}
+
+MEDCouplingDefinitionTimeSliceLT::MEDCouplingDefinitionTimeSliceLT(const MEDCouplingFieldDouble *f, int meshId, int arrId, int arr2Id, int fieldId) throw(INTERP_KERNEL::Exception):MEDCouplingDefinitionTimeSlice(f,meshId,arrId,fieldId),_array_id_end(arr2Id)
+{
+ int tmp1,tmp2;
+ double t1=f->getStartTime(tmp1,tmp2);
+ double t2=f->getEndTime(tmp1,tmp2);
+ _start=t1;
+ _end=t2;
+}
+
+MEDCouplingDefinitionTime::MEDCouplingDefinitionTime()
+{
+}
+
+MEDCouplingDefinitionTime::MEDCouplingDefinitionTime(const std::vector<const MEDCouplingFieldDouble *>& fs, const std::vector<int>& meshRefs, const std::vector<std::vector<int> >& arrRefs) throw(INTERP_KERNEL::Exception)
+{
+ std::size_t sz=fs.size();
+ if(sz!=arrRefs.size())
+ throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime constructor : internal error ! should never happen !");
+ _slices.resize(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ if(arrRefs.empty())
+ throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime constructor : A field is null in list impossible to build a time definition !");
+ _slices[i]=MEDCouplingDefinitionTimeSlice::New(fs[i],meshRefs[i],arrRefs[i],i);
+ }
+ if(sz<=1)
+ return ;
+ const MEDCouplingDefinitionTimeSlice *ref=_slices[0];
+ _eps=fs[0]->getTimeTolerance();
+ for(std::size_t i=1;i<sz;i++)
+ {
+ if(!ref->isAfterMe(_slices[i],_eps))
+ throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime constructors : the sequences of fields does NOT defines a stricly ascendant monotonic time sequence !");
+ // double t1=ref->getEndTime();
+ // double t2=_slices[i]->getStartTime();
+ // if(fabs(t1-t2)<_eps)
+ // if(ref->getEndId() != _slices[i]->getStartId())
+ // throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime constructor : 2 slices refers to the same time and underlying arrays differs !");
+ ref=_slices[i];
+ }
+}
+
+void MEDCouplingDefinitionTime::getIdsOnTimeRight(double tm, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> meshIds;
+ std::vector<int> arrIds;
+ std::vector<int> arrIdsInField;
+ std::vector<int> fieldIds;
+ getIdsOnTime(tm,meshIds,arrIds,arrIdsInField,fieldIds);
+ meshId=meshIds.back();
+ arrId=arrIds.back();
+ arrIdInField=arrIdsInField.back();
+ fieldId=fieldIds.back();
+}
+
+void MEDCouplingDefinitionTime::getIdsOnTimeLeft(double tm, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> meshIds;
+ std::vector<int> arrIds;
+ std::vector<int> arrIdsInField;
+ std::vector<int> fieldIds;
+ getIdsOnTime(tm,meshIds,arrIds,arrIdsInField,fieldIds);
+ meshId=meshIds.front();
+ arrId=arrIds.front();
+ arrIdInField=arrIdsInField.front();
+ fieldId=fieldIds.front();
+}
+
+void MEDCouplingDefinitionTime::getIdsOnTime(double tm, std::vector<int>& meshIds, std::vector<int>& arrIds, std::vector<int>& arrIdsInField, std::vector<int>& fieldIds) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> ids;
+ int id=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingDefinitionTimeSlice> >::const_iterator it=_slices.begin();it!=_slices.end();it++,id++)
+ if((*it)->isContaining(tm,_eps))
+ ids.push_back(id);
+ if(ids.empty())
+ throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime::getIdsOnTime : No matching slice for such time !");
+ int sz=ids.size();
+ if(sz>2)
+ throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime::getIdsOnTime : Too many slices match this time !");
+ //tony
+}
+
+void MEDCouplingDefinitionTime::appendRepr(std::ostream& stream) const
+{
+ stream << "Time definition :\n";
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingDefinitionTimeSlice> >::const_iterator it=_slices.begin();it!=_slices.end();it++)
+ {
+ stream << " - ";
+ (*it)->appendRepr(stream);
+ stream << std::endl;
+ }
+}
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef __PARAMEDMEM_MEDCOUPLINGDEFINITIONTIME_HXX__
+#define __PARAMEDMEM_MEDCOUPLINGDEFINITIONTIME_HXX__
+
+#include "MEDCouplingRefCountObject.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+
+#include "InterpKernelException.hxx"
+
+#include <vector>
+#include <sstream>
+
+namespace ParaMEDMEM
+{
+ class MEDCouplingFieldDouble;
+
+ class MEDCouplingDefinitionTimeSlice : public RefCountObject
+ {
+ public:
+ static MEDCouplingDefinitionTimeSlice *New(const MEDCouplingFieldDouble *f, int meshId, const std::vector<int>& arrId, int fieldId) throw(INTERP_KERNEL::Exception);
+ int getArrayId() const { return _array_id; }
+ virtual bool isContaining(double tmp, double eps) const = 0;
+ virtual int getStartId() const;
+ virtual int getEndId() const;
+ virtual void appendRepr(std::ostream& stream) const;
+ virtual double getStartTime() const = 0;
+ virtual double getEndTime() const = 0;
+ bool isFullyIncludedInMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const;
+ bool isOverllapingWithMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const;
+ bool isAfterMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const;
+ bool isBeforeMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const;
+ protected:
+ MEDCouplingDefinitionTimeSlice(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception);
+ protected:
+ int _mesh_id;
+ int _array_id;
+ int _field_id;
+ };
+
+ class MEDCouplingDefinitionTimeSliceInst : public MEDCouplingDefinitionTimeSlice
+ {
+ public:
+ bool isContaining(double tmp, double eps) const;
+ void appendRepr(std::ostream& stream) const;
+ double getStartTime() const;
+ double getEndTime() const;
+ public:
+ MEDCouplingDefinitionTimeSliceInst(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception);
+ protected:
+ double _instant;
+ };
+
+ class MEDCouplingDefinitionTimeSliceCstOnTI : public MEDCouplingDefinitionTimeSlice
+ {
+ public:
+ bool isContaining(double tmp, double eps) const;
+ void appendRepr(std::ostream& stream) const;
+ double getStartTime() const;
+ double getEndTime() const;
+ public:
+ MEDCouplingDefinitionTimeSliceCstOnTI(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception);
+ protected:
+ double _start;
+ double _end;
+ };
+
+
+ class MEDCouplingDefinitionTimeSliceLT : public MEDCouplingDefinitionTimeSlice
+ {
+ public:
+ bool isContaining(double tmp, double eps) const;
+ void appendRepr(std::ostream& stream) const;
+ double getStartTime() const;
+ double getEndTime() const;
+ int getEndId() const;
+ public:
+ MEDCouplingDefinitionTimeSliceLT(const MEDCouplingFieldDouble *f, int meshId, int arrId, int arr2Id, int fieldId) throw(INTERP_KERNEL::Exception);
+ protected:
+ int _array_id_end;
+ double _start;
+ double _end;
+ };
+
+ class MEDCouplingDefinitionTime
+ {
+ public:
+ MEDCouplingDefinitionTime();
+ MEDCouplingDefinitionTime(const std::vector<const MEDCouplingFieldDouble *>& fs, const std::vector<int>& meshRefs, const std::vector<std::vector<int> >& arrRefs) throw(INTERP_KERNEL::Exception);
+ double getTimeResolution() const { return _eps; }
+ void getIdsOnTimeRight(double tm, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception);
+ void getIdsOnTimeLeft(double tm, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception);
+ void appendRepr(std::ostream& stream) const;
+ private:
+ void getIdsOnTime(double tm, std::vector<int>& meshIds, std::vector<int>& arrIds, std::vector<int>& arrIdsInField, std::vector<int>& fieldIds) const throw(INTERP_KERNEL::Exception);
+ private:
+ double _eps;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingDefinitionTimeSlice> > _slices;
+ };
+}
+
+#endif
{
std::ostringstream ret;
ret << "3D Extruded mesh from a 2D Surf Mesh with name : \"" << getName() << "\"\n";
+ ret << "Description of mesh : \"" << getDescription() << "\"\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";
{
std::ostringstream ret;
ret << "3D Extruded mesh from a 2D Surf Mesh with name : \"" << getName() << "\"\n";
+ ret << "Description of mesh : \"" << getDescription() << "\"\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";
//
#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldTemplate.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingTimeDiscretization.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
return new MEDCouplingFieldDouble(type,td);
}
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::New(const MEDCouplingFieldTemplate *ft, TypeOfTimeDiscretization td)
+{
+ return new MEDCouplingFieldDouble(ft,td);
+}
+
+void MEDCouplingFieldDouble::setTimeUnit(const char *unit)
+{
+ _time_discr->setTimeUnit(unit);
+}
+
+const char *MEDCouplingFieldDouble::getTimeUnit() const
+{
+ return _time_discr->getTimeUnit();
+}
+
MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const
{
return new MEDCouplingFieldDouble(*this,recDeepCpy);
MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const
{
- MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(_time_discr,td,deepCpy);
+ MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(td,deepCpy);
MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),tdo,_type->clone());
ret->setMesh(getMesh());
ret->setName(getName());
{
}
+MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate *ft, TypeOfTimeDiscretization td):MEDCouplingField(*ft),
+ _time_discr(MEDCouplingTimeDiscretization::New(td))
+{
+}
+
MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy):MEDCouplingField(other),
_time_discr(other._time_discr->performCpy(deepCpy))
{
_time_discr->setEndArray(array,this);
}
+void MEDCouplingFieldDouble::setArrays(const std::vector<DataArrayDouble *>& arrs) throw(INTERP_KERNEL::Exception)
+{
+ _time_discr->setArrays(arrs,this);
+}
+
void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
{
tinyInfo.clear();
namespace ParaMEDMEM
{
+ class MEDCouplingFieldTemplate;
+
class MEDCOUPLING_EXPORT MEDCouplingFieldDouble : public MEDCouplingField
{
public:
static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=NO_TIME);
+ static MEDCouplingFieldDouble *New(const MEDCouplingFieldTemplate *ft, TypeOfTimeDiscretization td=NO_TIME);
+ void setTimeUnit(const char *unit);
+ const char *getTimeUnit() const;
void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception);
void copyTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception);
std::string simpleRepr() const;
double getIJK(int cellId, int nodeIdInCell, int compoId) const;
void setArray(DataArrayDouble *array);
void setEndArray(DataArrayDouble *array);
+ void setArrays(const std::vector<DataArrayDouble *>& arrs) throw(INTERP_KERNEL::Exception);
DataArrayDouble *getArray() const { return _time_discr->getArray(); }
DataArrayDouble *getEndArray() const { return _time_discr->getEndArray(); }
+ std::vector<DataArrayDouble *> getArrays() const { std::vector<DataArrayDouble *> ret; _time_discr->getArrays(ret); return ret; }
double accumulate(int compId) const;
void accumulate(double *res) const;
double getMaxValue() const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return DivideFields(this,&other); }
const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception);
static MEDCouplingFieldDouble *DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception);
+ public:
+ const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; }
+ MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return _time_discr; }
private:
MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td);
+ MEDCouplingFieldDouble(const MEDCouplingFieldTemplate *ft, TypeOfTimeDiscretization td);
MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy);
MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type);
~MEDCouplingFieldDouble();
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "MEDCouplingFieldOverTime.hxx"
+#include "MEDCouplingMesh.hxx"
+
+#include <cmath>
+
+using namespace ParaMEDMEM;
+
+MEDCouplingFieldOverTime *MEDCouplingFieldOverTime::New(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDCouplingFieldOverTime(fs);
+}
+
+double MEDCouplingFieldOverTime::getTimeTolerance() const throw(INTERP_KERNEL::Exception)
+{
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
+ if(_fs.empty())
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::getTimeTolerance : empty set !");
+ for(;it!=_fs.end();it++)
+ if((const MEDCouplingFieldDouble *)(*it)!=0)
+ return (*it)->getTimeTolerance();
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::getTimeTolerance : only empty fields in this !");
+}
+
+void MEDCouplingFieldOverTime::checkCoherency() const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingMultiFields::checkCoherency();
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
+ for(;it!=_fs.end();it++)
+ if((*it)->getTimeDiscretization()==NO_TIME)
+ {
+ std::ostringstream oss; oss << "MEDCouplingFieldOverTime::checkCoherency : At rank #" << std::distance(_fs.begin(),it) << " the field has no time !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(_fs.empty())
+ return ;
+ it=_fs.begin();
+ const MEDCouplingFieldDouble& ref=*(*(it++));
+ int tt1,tt2;
+ double reft=ref.getEndTime(tt1,tt2);
+ double eps=getTimeTolerance();
+ int id=1;
+ for(;it!=_fs.end();it++,id++)
+ {
+ if(!ref.getMesh()->areCompatibleForMerge((*it)->getMesh()))
+ {
+ std::ostringstream oss; oss << "Field slice at rank #" << id << " is not compatible with the first !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ double curt=(*it)->getStartTime(tt1,tt2);
+ if(curt<reft-eps)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::checkCoherency : fields are NOT sorted properly in ascending time !");
+ reft=(*it)->getEndTime(tt1,tt2);
+ }
+}
+
+std::string MEDCouplingFieldOverTime::simpleRepr() const
+{
+ std::ostringstream ret;
+ ret << "MEDCouplingFieldOverTime with name : \"" << getName() << "\"\n";
+ ret << "Description of MEDCouplingFieldOverTime is : \"" << getDescription() << "\"\n";
+ ret << "Number of discretization : " << _fs.size() << "\n";
+ ret << "Number of different meshes : ";
+ std::vector<MEDCouplingMesh *> ms;
+ std::vector<int> refms;
+ try
+ {
+ ms=getDifferentMeshes(refms);
+ ret << ms.size() << "\n";
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ { ret << "Current instance is INVALID !\n"; }
+ try
+ {
+ MEDCouplingDefinitionTime dt=getDefinitionTimeZone();
+ dt.appendRepr(ret);
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ { ret << "Definition zone is INVALID !\n"; }
+ return ret.str();
+}
+
+bool MEDCouplingFieldOverTime::isEqual(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
+{
+ if(!MEDCouplingMultiFields::isEqual(other,meshPrec,valsPrec))
+ return false;
+ const MEDCouplingFieldOverTime *otherC=dynamic_cast<const MEDCouplingFieldOverTime *>(other);
+ if(!otherC)
+ return false;
+ // to implement
+ return true;
+}
+
+bool MEDCouplingFieldOverTime::isEqualWithoutConsideringStr(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
+{
+ if(!MEDCouplingMultiFields::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
+ return false;
+ const MEDCouplingFieldOverTime *otherC=dynamic_cast<const MEDCouplingFieldOverTime *>(other);
+ if(!otherC)
+ return false;
+ // to implement
+ return true;
+}
+
+std::vector<MEDCouplingMesh *> MEDCouplingFieldOverTime::getMeshes() const throw(INTERP_KERNEL::Exception)
+{
+ checkCoherency();
+ return MEDCouplingMultiFields::getMeshes();
+}
+
+std::vector<MEDCouplingMesh *> MEDCouplingFieldOverTime::getDifferentMeshes(std::vector<int>& refs) const throw(INTERP_KERNEL::Exception)
+{
+ checkCoherency();
+ return MEDCouplingMultiFields::getDifferentMeshes(refs);
+}
+
+std::vector<DataArrayDouble *> MEDCouplingFieldOverTime::getArrays() const throw(INTERP_KERNEL::Exception)
+{
+ checkCoherency();
+ return MEDCouplingMultiFields::getArrays();
+}
+
+std::vector<DataArrayDouble *> MEDCouplingFieldOverTime::getDifferentArrays(std::vector< std::vector<int> >& refs) const throw(INTERP_KERNEL::Exception)
+{
+ checkCoherency();
+ return MEDCouplingMultiFields::getDifferentArrays(refs);
+}
+
+MEDCouplingDefinitionTime MEDCouplingFieldOverTime::getDefinitionTimeZone() const
+{
+ std::vector< std::vector<int> > tmp;
+ getDifferentArrays(tmp);
+ std::vector<const MEDCouplingFieldDouble *> tmp2(_fs.begin(),_fs.end());
+ std::vector<int> tmp3;
+ getDifferentMeshes(tmp3);
+ return MEDCouplingDefinitionTime(tmp2,tmp3,tmp);
+}
+
+MEDCouplingFieldOverTime::MEDCouplingFieldOverTime(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception):MEDCouplingMultiFields(fs)
+{
+ checkCoherency();
+}
+
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef __PARAMEDMEM_MEDCOUPLINGFIELDOVERTIME_HXX__
+#define __PARAMEDMEM_MEDCOUPLINGFIELDOVERTIME_HXX__
+
+#include "MEDCouplingMultiFields.hxx"
+#include "MEDCouplingDefinitionTime.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+
+#include <vector>
+
+namespace ParaMEDMEM
+{
+ class MEDCouplingFieldOverTime : public MEDCouplingMultiFields
+ {
+ public:
+ static MEDCouplingFieldOverTime *New(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception);
+ void checkCoherency() const throw(INTERP_KERNEL::Exception);
+ double getTimeTolerance() const throw(INTERP_KERNEL::Exception);
+ std::string simpleRepr() const;
+ bool isEqual(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const;
+ bool isEqualWithoutConsideringStr(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const;
+ std::vector<MEDCouplingMesh *> getMeshes() const throw(INTERP_KERNEL::Exception);
+ std::vector<MEDCouplingMesh *> getDifferentMeshes(std::vector<int>& refs) const throw(INTERP_KERNEL::Exception);
+ std::vector<DataArrayDouble *> getArrays() const throw(INTERP_KERNEL::Exception);
+ std::vector<DataArrayDouble *> getDifferentArrays(std::vector< std::vector<int> >& refs) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingDefinitionTime getDefinitionTimeZone() const;
+ private:
+ MEDCouplingFieldOverTime(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception);
+ };
+}
+
+#endif
//
#include "MEDCouplingFieldTemplate.hxx"
+#include "MEDCouplingMesh.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkCoherency : Empty mesh !");
}
+std::string MEDCouplingFieldTemplate::simpleRepr() const
+{
+ std::ostringstream ret;
+ ret << "FieldTemplate with name : \"" << getName() << "\"\n";
+ ret << "Description of field is : \"" << getDescription() << "\"\n";
+ ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n";
+ ret << "FieldTemplate nature of field is : " << MEDCouplingNatureOfField::getRepr(_nature) << "\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 MEDCouplingFieldTemplate::advancedRepr() const
+{
+ return simpleRepr();
+}
+
void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
{
tinyInfo.clear();
public:
static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception);
static MEDCouplingFieldTemplate *New(TypeOfField type);
+ std::string simpleRepr() const;
+ std::string advancedRepr() const;
void checkCoherency() const throw(INTERP_KERNEL::Exception);
//
void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
declareAsNew();
}
+/*!
+ * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
+ * Server side.
+ */
+void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
+{
+ tinyInfo.resize(2);
+ if(isAllocated())
+ {
+ tinyInfo[0]=getNumberOfTuples();
+ tinyInfo[1]=getNumberOfComponents();
+ }
+ else
+ {
+ tinyInfo[0]=-1;
+ tinyInfo[1]=-1;
+ }
+}
+
+/*!
+ * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
+ * Server side.
+ */
+void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
+{
+ if(isAllocated())
+ {
+ int nbOfCompo=getNumberOfComponents();
+ tinyInfo.resize(nbOfCompo+1);
+ tinyInfo[0]=getName();
+ for(int i=0;i<nbOfCompo;i++)
+ tinyInfo[i+1]=getInfoOnComponent(i);
+ }
+ else
+ {
+ tinyInfo.resize(1);
+ tinyInfo[0]=getName();
+ }
+}
+
+/*!
+ * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
+ * This method returns if a feeding is needed.
+ */
+bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
+{
+ int nbOfTuple=tinyInfoI[0];
+ int nbOfComp=tinyInfoI[1];
+ if(nbOfTuple!=-1 || nbOfComp!=-1)
+ {
+ alloc(nbOfTuple,nbOfComp);
+ return true;
+ }
+ return false;
+}
+
+/*!
+ * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
+ */
+void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
+{
+ setName(tinyInfoS[0].c_str());
+ if(isAllocated())
+ {
+ int nbOfCompo=getNumberOfComponents();
+ for(int i=0;i<nbOfCompo;i++)
+ setInfoOnComponent(i,tinyInfoS[i+1].c_str());
+ }
+}
+
DataArrayInt *DataArrayInt::New()
{
return new DataArrayInt;
return ret;
}
+/*!
+ *
+ */
+DataArrayInt *DataArrayInt::checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::checkAndPreparePermutation : number of components must == 1 !");
+ int nbTuples=getNumberOfTuples();
+ const int *pt=getConstPointer();
+ int *pt2=CheckAndPreparePermutation(pt,pt+nbTuples);
+ DataArrayInt *ret=DataArrayInt::New();
+ ret->useArray(pt2,true,CPP_DEALLOC,nbTuples,1);
+ return ret;
+}
+
/*!
* This method checks that 'this' is with numberofcomponents == 1 and that it is equal to
* stdext::iota() of size getNumberOfTuples. This method is particalary usefull for DataArrayInt instances
MEDCOUPLING_EXPORT void divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception);
//! nothing to do here because this class does not aggregate any TimeLabel instance.
MEDCOUPLING_EXPORT void updateTime() { }
+ public:
+ void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
+ void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
+ bool resizeForUnserialization(const std::vector<int>& tinyInfoI);
+ void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
private:
DataArrayDouble() { }
private:
MEDCOUPLING_EXPORT DataArrayInt *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const;
MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const;
MEDCOUPLING_EXPORT DataArrayInt *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayInt *checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool isIdentity() const;
MEDCOUPLING_EXPORT bool isUniform(int val) const;
MEDCOUPLING_EXPORT DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception);
bool MEDCouplingMesh::isEqual(const MEDCouplingMesh *other, double prec) const
{
- return _name==other->_name;
+ return _name==other->_name && _description==other->_description;
}
/*!
void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception)
{
_name=other->_name;
+ _description=other->_description;
}
/*!
public:
void setName(const char *name) { _name=name; }
const char *getName() const { return _name.c_str(); }
+ void setDescription(const char *descr) { _description=descr; }
+ const char *getDescription() const { return _description.c_str(); }
virtual MEDCouplingMesh *deepCpy() const = 0;
virtual MEDCouplingMeshType getType() const = 0;
bool isStructured() const;
const std::vector<std::string>& littleStrings) = 0;
protected:
MEDCouplingMesh() { }
- MEDCouplingMesh(const MEDCouplingMesh& other):_name(other._name) { }
+ MEDCouplingMesh(const MEDCouplingMesh& other):_name(other._name),_description(other._description) { }
virtual ~MEDCouplingMesh() { }
private:
std::string _name;
+ std::string _description;
};
}
--- /dev/null
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "MEDCouplingMultiFields.hxx"
+#include "MEDCouplingFieldTemplate.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingMesh.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+
+using namespace ParaMEDMEM;
+
+MEDCouplingMultiFields *MEDCouplingMultiFields::New(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDCouplingMultiFields(fs);
+}
+
+MEDCouplingMultiFields *MEDCouplingMultiFields::New()
+{
+ return new MEDCouplingMultiFields;
+}
+
+MEDCouplingMultiFields *MEDCouplingMultiFields::deepCpy() const
+{
+ return new MEDCouplingMultiFields(*this);
+}
+
+bool MEDCouplingMultiFields::isEqual(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
+{
+ std::size_t sz=_fs.size();
+ if(sz!=other->_fs.size())
+ return false;
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const MEDCouplingFieldDouble *f1=_fs[i];
+ const MEDCouplingFieldDouble *f2=other->_fs[i];
+ if(f1!=f2)
+ {
+ if(f1==0 || f2==0)
+ return false;
+ if(!_fs[i]->isEqual(other->_fs[i],meshPrec,valsPrec))
+ return false;
+ }
+ }
+ std::vector<int> refs1,refs2;
+ std::vector<MEDCouplingMesh *> ms1=getDifferentMeshes(refs1);
+ std::vector<MEDCouplingMesh *> ms2=other->getDifferentMeshes(refs2);
+ if(ms1.size()!=ms2.size())
+ return false;
+ if(refs1!=refs2)
+ return false;
+ std::vector< std::vector<int> > refs3,refs4;
+ std::vector<DataArrayDouble *> das1=getDifferentArrays(refs3);
+ std::vector<DataArrayDouble *> das2=getDifferentArrays(refs4);
+ if(das1.size()!=das2.size())
+ return false;
+ if(refs3!=refs4)
+ return false;
+ return true;
+}
+
+std::string MEDCouplingMultiFields::getName() const
+{
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
+ for(;it!=_fs.end();it++)
+ if((const MEDCouplingFieldDouble *)(*it))
+ return (*it)->getName();
+ return std::string();
+}
+
+std::string MEDCouplingMultiFields::getDescription() const
+{
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
+ for(;it!=_fs.end();it++)
+ if((const MEDCouplingFieldDouble *)(*it))
+ return (*it)->getDescription();
+ return std::string();
+}
+
+std::string MEDCouplingMultiFields::getTimeUnit() const
+{
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
+ for(;it!=_fs.end();it++)
+ if((const MEDCouplingFieldDouble *)(*it))
+ return (*it)->getTimeUnit();
+ return std::string();
+}
+
+double MEDCouplingMultiFields::getTimeResolution() const throw(INTERP_KERNEL::Exception)
+{
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
+ for(;it!=_fs.end();it++)
+ if((const MEDCouplingFieldDouble *)(*it))
+ return (*it)->getTimeTolerance();
+ throw INTERP_KERNEL::Exception("MEDCouplingMultiFields::getTimeResolution : no not null field !");
+}
+
+std::string MEDCouplingMultiFields::simpleRepr() const
+{
+ std::ostringstream ret;
+ ret << "MEDCouplingMultiFields with name : \"" << getName() << "\"\n";
+ ret << "Description of MEDCouplingMultiFields is : \"" << getDescription() << "\"\n";
+ ret << "Number of discretization : " << _fs.size() << "\n";
+ ret << "Number of different meshes : ";
+ std::vector<MEDCouplingMesh *> ms;
+ std::vector<int> refms;
+ try
+ {
+ ms=getDifferentMeshes(refms);
+ ret << ms.size() << "\n";
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ { ret << "Current instance is INVALID !\n"; }
+ return ret.str();
+}
+
+std::string MEDCouplingMultiFields::advancedRepr() const
+{
+ return simpleRepr();
+}
+
+bool MEDCouplingMultiFields::isEqualWithoutConsideringStr(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
+{
+ std::size_t sz=_fs.size();
+ if(sz!=other->_fs.size())
+ return false;
+ for(std::size_t i=0;i<sz;i++)
+ if(!_fs[i]->isEqualWithoutConsideringStr(other->_fs[i],meshPrec,valsPrec))
+ return false;
+ return true;
+}
+
+const MEDCouplingFieldDouble *MEDCouplingMultiFields::getFieldWithId(int id) const throw(INTERP_KERNEL::Exception)
+{
+ if(id>=(int)_fs.size() || id < 0)
+ throw INTERP_KERNEL::Exception("MEDCouplingMultiFields::getFieldWithId : invalid id outside boundaries !");
+ return _fs[id];
+}
+
+std::vector<const MEDCouplingFieldDouble *> MEDCouplingMultiFields::getFields() const
+{
+ std::vector<const MEDCouplingFieldDouble *> ret(_fs.size());
+ std::copy(_fs.begin(),_fs.end(),ret.begin());
+ return ret;
+}
+
+int MEDCouplingMultiFields::getNumberOfFields() const
+{
+ return _fs.size();
+}
+
+const MEDCouplingFieldDouble *MEDCouplingMultiFields::getFieldAtPos(int id) const throw(INTERP_KERNEL::Exception)
+{
+ if(id<0 || id>=(int)_fs.size())
+ {
+ std::ostringstream oss; oss << "MEDCouplingMultiFields::getFieldAtPos : Invalid given pos : should be >=0 and < " << _fs.size() << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return _fs[id];
+}
+
+void MEDCouplingMultiFields::updateTime()
+{
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::iterator it=_fs.begin();
+ for(;it!=_fs.end();it++)
+ if((MEDCouplingFieldDouble *)(*it))
+ (*it)->updateTime();
+ it=_fs.begin();
+ for(;it!=_fs.end();it++)
+ if((MEDCouplingFieldDouble *)(*it))
+ updateTimeWith(*(*it));
+}
+
+std::vector<MEDCouplingMesh *> MEDCouplingMultiFields::getMeshes() const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<MEDCouplingMesh *> ms;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();it!=_fs.end();it++)
+ {
+ const MEDCouplingMesh *m=0;
+ if((const MEDCouplingFieldDouble *)(*it))
+ m=(*it)->getMesh();
+ ms.push_back(const_cast<MEDCouplingMesh *>(m));
+ }
+ return ms;
+}
+
+std::vector<MEDCouplingMesh *> MEDCouplingMultiFields::getDifferentMeshes(std::vector<int>& refs) const throw(INTERP_KERNEL::Exception)
+{
+ refs.resize(_fs.size());
+ std::vector<MEDCouplingMesh *> ms;
+ int id=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();it!=_fs.end();it++,id++)
+ {
+ const MEDCouplingMesh *m=0;
+ if((const MEDCouplingFieldDouble *)(*it))
+ m=(*it)->getMesh();
+ if(m)
+ {
+ std::vector<MEDCouplingMesh *>::iterator it=std::find(ms.begin(),ms.end(),m);
+ if(it==ms.end())
+ {
+ ms.push_back(const_cast<MEDCouplingMesh *>(m));
+ refs[id]=ms.size()-1;
+ }
+ else
+ refs[id]=std::distance(ms.begin(),it);
+ }
+ else
+ refs[id]=-1;
+ }
+ return ms;
+}
+
+std::vector<DataArrayDouble *> MEDCouplingMultiFields::getArrays() const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<DataArrayDouble *> tmp;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();it!=_fs.end();it++)
+ {
+ std::vector<DataArrayDouble *> tmp2=(*it)->getArrays();
+ tmp.insert(tmp.end(),tmp2.begin(),tmp2.end());
+ }
+ return tmp;
+}
+
+std::vector<DataArrayDouble *> MEDCouplingMultiFields::getDifferentArrays(std::vector< std::vector<int> >& refs) const throw(INTERP_KERNEL::Exception)
+{
+ refs.resize(_fs.size());
+ int id=0;
+ std::vector<DataArrayDouble *> ret;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();it!=_fs.end();it++,id++)
+ {
+ std::vector<DataArrayDouble *> tmp2;
+ if((const MEDCouplingFieldDouble *)(*it))
+ {
+ tmp2=(*it)->getArrays();
+ refs[id].resize(tmp2.size());
+ }
+ else
+ refs[id].clear();
+ int id2=0;
+ for(std::vector<DataArrayDouble *>::const_iterator it2=tmp2.begin();it2!=tmp2.end();it2++,id2++)
+ {
+ if(*it2)
+ {
+ std::vector<DataArrayDouble *>::iterator it3=std::find(ret.begin(),ret.end(),*it2);
+ if(it3==ret.end())
+ {
+ ret.push_back(*it2);
+ refs[id][id2]=ret.size()-1;
+ }
+ else
+ refs[id][id2]=std::distance(ret.begin(),it3);
+ }
+ else
+ refs[id][id2]=-1;
+ }
+ }
+ return ret;
+}
+
+void MEDCouplingMultiFields::checkCoherency() const throw(INTERP_KERNEL::Exception)
+{
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
+ for(;it!=_fs.end();it++)
+ {
+ if((const MEDCouplingFieldDouble *)(*it)==0)
+ throw INTERP_KERNEL::Exception("MEDCouplingMultiFields::checkCoherency : There is an empty Field in array...");
+ (*it)->checkCoherency();
+ }
+}
+
+MEDCouplingMultiFields::MEDCouplingMultiFields(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception):_fs(fs.size())
+{
+ int id=0;
+ for(std::vector< MEDCouplingFieldDouble * >::const_iterator it=fs.begin();it!=fs.end();it++,id++)
+ {
+ if(*it)
+ (*it)->incrRef();
+ else
+ throw INTERP_KERNEL::Exception("MEDCouplingMultiFields constructor : empty field found in vector !");
+ (*it)->checkCoherency();
+ _fs[id]=*it;
+ }
+}
+
+
+/*!
+ * Performs deepCpy.
+ */
+MEDCouplingMultiFields::MEDCouplingMultiFields(const MEDCouplingMultiFields& other)
+{
+ int sz=other._fs.size();
+ _fs.resize(sz);
+ std::vector<int> refs;
+ std::vector< std::vector<int> > refs2;
+ std::vector<MEDCouplingMesh *> ms=other.getDifferentMeshes(refs);
+ int msLgh=ms.size();
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> > ms2(msLgh);
+ for(int i=0;i<msLgh;i++)
+ ms2[i]=ms[i]->deepCpy();
+ std::vector<DataArrayDouble *> das=other.getDifferentArrays(refs2);
+ int dasLgth=das.size();
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > das2(dasLgth);
+ for(int i=0;i<dasLgth;i++)
+ das2[i]=das[i]->deepCpy();
+ for(int i=0;i<sz;i++)
+ {
+ if((const MEDCouplingFieldDouble *)other._fs[i])
+ {
+ MEDCouplingFieldTemplate *tmp=MEDCouplingFieldTemplate::New(other._fs[i]);
+ _fs[i]=MEDCouplingFieldDouble::New(tmp,other._fs[i]->getTimeDiscretization());
+ tmp->decrRef();
+ if(refs[i]!=-1)
+ _fs[i]->setMesh(ms2[refs[i]]);
+ int nbOfArr=refs2[i].size();
+ std::vector<DataArrayDouble *> tmp2(nbOfArr);
+ for(int j=0;j<nbOfArr;j++)
+ {
+ if(refs2[i][j]!=-1)
+ tmp2[j]=das2[refs2[i][j]];
+ else
+ tmp2[j]=0;
+ }
+ _fs[i]->setArrays(tmp2);
+ std::vector<int> tinyInfo;
+ std::vector<double> tinyInfo2;
+ other._fs[i]->getTimeDiscretizationUnderGround()->getTinySerializationIntInformation2(tinyInfo);
+ other._fs[i]->getTimeDiscretizationUnderGround()->getTinySerializationDbleInformation2(tinyInfo2);
+ _fs[i]->getTimeDiscretizationUnderGround()->finishUnserialization2(tinyInfo,tinyInfo2);
+ }
+ }
+}
+
+MEDCouplingMultiFields::MEDCouplingMultiFields()
+{
+}
+
+void MEDCouplingMultiFields::getTinySerializationInformation(std::vector<int>& tinyInfo, std::vector<double>& tinyInfo2, int& nbOfDiffMeshes, int& nbOfDiffArr) const
+{
+ std::vector<int> refs;
+ std::vector<MEDCouplingMesh *> ms=getDifferentMeshes(refs);
+ nbOfDiffMeshes=ms.size();
+ std::vector< std::vector<int> > refs2;
+ std::vector<DataArrayDouble *> fs=getDifferentArrays(refs2);
+ nbOfDiffArr=fs.size();
+ //
+ int sz=refs.size();//==_fs.size()
+ int sz2=0;
+ for(int i=0;i<sz;i++)
+ sz2+=refs2[i].size();
+ //
+ tinyInfo2.clear();
+ std::vector<int> doubleDaInd(sz);
+ std::vector<int> timeDiscrInt;
+ tinyInfo.resize(sz2+5*sz+3);
+ tinyInfo[0]=sz;
+ tinyInfo[1]=sz2;
+ for(int i=0;i<sz;i++)
+ {
+ std::vector<double> tmp;
+ std::vector<int> tmp2;
+ _fs[i]->getTimeDiscretizationUnderGround()->getTinySerializationDbleInformation2(tmp);
+ _fs[i]->getTimeDiscretizationUnderGround()->getTinySerializationIntInformation2(tmp2);
+ tinyInfo[3*sz+3+i]=tmp.size();
+ tinyInfo[4*sz+3+i]=tmp2.size();
+ tinyInfo2.insert(tinyInfo2.end(),tmp.begin(),tmp.end());
+ timeDiscrInt.insert(timeDiscrInt.end(),tmp2.begin(),tmp2.end());
+ }
+ int sz3=timeDiscrInt.size();
+ tinyInfo[2]=sz3;
+ //
+ for(int i=0;i<sz;i++)
+ tinyInfo[i+3]=refs[i];
+ for(int i=0;i<sz;i++)
+ tinyInfo[i+sz+3]=refs2[i].size();
+ for(int i=0;i<sz;i++)
+ tinyInfo[i+2*sz+3]=(int)_fs[i]->getTimeDiscretization();
+ int k=0;
+ for(int i=0;i<sz;i++)
+ for(std::vector<int>::const_iterator it=refs2[i].begin();it!=refs2[i].end();it++,k++)
+ tinyInfo[5*sz+k+3]=*it;
+ tinyInfo.insert(tinyInfo.end(),timeDiscrInt.begin(),timeDiscrInt.end());//tinyInfo has lgth==sz3+sz2+5*sz+3
+}
+
+void MEDCouplingMultiFields::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD,
+ const std::vector<MEDCouplingFieldTemplate *>& ft, const std::vector<MEDCouplingMesh *>& ms,
+ const std::vector<DataArrayDouble *>& das)
+{
+ int sz=tinyInfoI[0];
+ _fs.resize(sz);
+ int sz2=tinyInfoI[1];
+ // dealing with ft with no mesh set.
+ for(int i=0;i<sz;i++)
+ {
+ int meshId=tinyInfoI[3+i];
+ if(meshId!=-1)
+ ft[i]->setMesh(ms[meshId]);
+ }
+ // dealing with fieldtemplate->fielddouble
+ int k=0;
+ int offI=0;
+ int offD=0;
+ for(int i=0;i<sz;i++)
+ {
+ _fs[i]=MEDCouplingFieldDouble::New(ft[i],(TypeOfTimeDiscretization)tinyInfoI[2*sz+3+i]);
+ int sz3=tinyInfoI[sz+i+3];
+ std::vector<DataArrayDouble *> tmp(sz3);
+ for(int j=0;j<sz3;j++,k++)
+ {
+ int daId=tinyInfoI[5*sz+k+3];
+ if(daId!=-1)
+ tmp[j]=das[daId];
+ else
+ tmp[j]=0;
+ }
+ _fs[i]->setArrays(tmp);
+ // time discr tiny info
+ int lgthI=tinyInfoI[4*sz+3+i];
+ int lgthD=tinyInfoI[3*sz+3+i];
+ //
+ std::vector<int> tdInfoI(tinyInfoI.begin()+sz2+5*sz+3+offI,tinyInfoI.begin()+sz2+5*sz+3+offI+lgthI);
+ std::vector<double> tdInfoD(tinyInfoD.begin()+offD,tinyInfoD.begin()+offD+lgthD);
+ _fs[i]->getTimeDiscretizationUnderGround()->finishUnserialization2(tdInfoI,tdInfoD);
+ //
+ offI+=lgthI;
+ offD+=lgthD;
+ }
+}
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef __PARAMEDMEM_MEDCOUPLINGMULTIFIELDS_HXX__
+#define __PARAMEDMEM_MEDCOUPLINGMULTIFIELDS_HXX__
+
+#include "MEDCouplingRefCountObject.hxx"
+#include "MEDCouplingTimeLabel.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+
+#include "InterpKernelException.hxx"
+
+#include <vector>
+
+namespace ParaMEDMEM
+{
+ class MEDCouplingMesh;
+ class DataArrayDouble;
+ class MEDCouplingFieldDouble;
+ class MEDCouplingFieldTemplate;
+
+ class MEDCouplingMultiFields : public RefCountObject, public TimeLabel
+ {
+ public:
+ static MEDCouplingMultiFields *New(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception);
+ static MEDCouplingMultiFields *New();
+ MEDCouplingMultiFields *deepCpy() const;
+ std::string getName() const;
+ std::string getDescription() const;
+ std::string getTimeUnit() const;
+ double getTimeResolution() const throw(INTERP_KERNEL::Exception);
+ virtual std::string simpleRepr() const;
+ virtual std::string advancedRepr() const;
+ virtual bool isEqual(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const;
+ virtual bool isEqualWithoutConsideringStr(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const;
+ const MEDCouplingFieldDouble *getFieldWithId(int id) const throw(INTERP_KERNEL::Exception);
+ std::vector<const MEDCouplingFieldDouble *> getFields() const;
+ int getNumberOfFields() const;
+ const MEDCouplingFieldDouble *getFieldAtPos(int id) const throw(INTERP_KERNEL::Exception);
+ virtual std::vector<MEDCouplingMesh *> getMeshes() const throw(INTERP_KERNEL::Exception);
+ virtual std::vector<MEDCouplingMesh *> getDifferentMeshes(std::vector<int>& refs) const throw(INTERP_KERNEL::Exception);
+ virtual std::vector<DataArrayDouble *> getArrays() const throw(INTERP_KERNEL::Exception);
+ virtual std::vector<DataArrayDouble *> getDifferentArrays(std::vector< std::vector<int> >& refs) const throw(INTERP_KERNEL::Exception);
+ void updateTime();
+ void getTinySerializationInformation(std::vector<int>& tinyInfo, std::vector<double>& tinyInfo2, int& nbOfDiffMeshes, int& nbOfDiffArr) const;
+ void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD,
+ const std::vector<MEDCouplingFieldTemplate *>& ft, const std::vector<MEDCouplingMesh *>& ms,
+ const std::vector<DataArrayDouble *>& das);
+ virtual void checkCoherency() const throw(INTERP_KERNEL::Exception);
+ protected:
+ MEDCouplingMultiFields(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception);
+ MEDCouplingMultiFields(const MEDCouplingMultiFields& other);
+ MEDCouplingMultiFields();
+ protected:
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > _fs;
+ };
+}
+
+#endif
+
void MEDCouplingTimeDiscretization::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other)
{
_time_tolerance=other._time_tolerance;
+ _time_unit=other._time_unit;
}
void MEDCouplingTimeDiscretization::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other)
{
+ _time_unit=other._time_unit;
if(_array && other._array)
_array->copyStringInfoFrom(*other._array);
}
bool MEDCouplingTimeDiscretization::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const
{
+ if(_time_unit!=other->_time_unit)
+ return false;
if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
return false;
if(_array==0 && other->_array==0)
return _array->isEqualWithoutConsideringStr(*other->_array,prec);
}
-MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other,
- TypeOfTimeDiscretization type, bool deepCpy) const
+MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCpy) const
{
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(type);
+ ret->setTimeUnit(getTimeUnit());
DataArrayDouble *arrSrc=getArray();
DataArrayDouble *arr=0;
if(arrSrc)
{
}
-MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization(const MEDCouplingTimeDiscretization& other, bool deepCpy):_time_tolerance(other._time_tolerance)
+MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization(const MEDCouplingTimeDiscretization& other, bool deepCpy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance)
{
if(other._array)
_array=other._array->performCpy(deepCpy);
MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
{
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
std::vector<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
for(int j=0;j<(int)arrays.size();j++)
arrays3[j]=arrays2[j];
MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
+ ret->setTimeUnit(getTimeUnit());
ret->setArrays(arrays3,0);
return ret;
}
{
std::ostringstream stream;
stream << REPR;
+ stream << "\nTime unit is : \"" << _time_unit << "\"";
return stream.str();
}
throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
}
+/*!
+ * idem getTinySerializationIntInformation except that it is for multi field fetch
+ */
+void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
+{
+ tinyInfo.clear();
+}
+
+/*!
+ * idem getTinySerializationDbleInformation except that it is for multi field fetch
+ */
+void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
+{
+ tinyInfo.resize(1);
+ tinyInfo[0]=_time_tolerance;
+}
+
+/*!
+ * idem finishUnserialization except that it is for multi field fetch
+ */
+void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
+{
+ _time_tolerance=tinyInfoD[0];
+}
+
MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy),
_time(other._time),_iteration(other._iteration),_order(other._order)
{
{
std::ostringstream stream;
stream << REPR << " Time is defined by iteration=" << _iteration << " order=" << _order << " and time=" << _time << ".";
+ stream << "\nTime unit is : \"" << _time_unit << "\"";
return stream.str();
}
_order=tinyInfoI[3];
}
+/*!
+ * idem getTinySerializationIntInformation except that it is for multi field fetch
+ */
+void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
+{
+ tinyInfo.resize(2);
+ tinyInfo[0]=_iteration;
+ tinyInfo[1]=_order;
+}
+
+/*!
+ * idem getTinySerializationDbleInformation except that it is for multi field fetch
+ */
+void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
+{
+ tinyInfo.resize(2);
+ tinyInfo[0]=_time_tolerance;
+ tinyInfo[1]=_time;
+}
+
+/*!
+ * idem finishUnserialization except that it is for multi field fetch
+ */
+void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
+{
+ _iteration=tinyInfoI[0];
+ _order=tinyInfoI[1];
+ _time_tolerance=tinyInfoD[0];
+ _time=tinyInfoD[1];
+}
+
bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretization *other) const
{
if(!MEDCouplingTimeDiscretization::areCompatible(other))
_end_order=tinyInfoI[5];
}
+/*!
+ * idem getTinySerializationIntInformation except that it is for multi field fetch
+ */
+void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
+{
+ tinyInfo.resize(4);
+ tinyInfo[0]=_start_iteration;
+ tinyInfo[1]=_start_order;
+ tinyInfo[2]=_end_iteration;
+ tinyInfo[3]=_end_order;
+}
+
+/*!
+ * idem getTinySerializationDbleInformation except that it is for multi field fetch
+ */
+void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
+{
+ tinyInfo.resize(3);
+ tinyInfo[0]=_time_tolerance;
+ tinyInfo[1]=_start_time;
+ tinyInfo[2]=_end_time;
+}
+
+/*!
+ * idem finishUnserialization except that it is for multi field fetch
+ */
+void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
+{
+ _start_iteration=tinyInfoI[0];
+ _start_order=tinyInfoI[1];
+ _end_iteration=tinyInfoI[2];
+ _end_order=tinyInfoI[3];
+ _time_tolerance=tinyInfoD[0];
+ _start_time=tinyInfoD[1];
+ _end_time=tinyInfoD[2];
+}
+
MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCpy):
MEDCouplingTimeDiscretization(other,deepCpy),_start_time(other._start_time),_end_time(other._end_time),_start_iteration(other._start_iteration),
_end_iteration(other._end_iteration),_start_order(other._start_order),_end_order(other._end_order)
std::ostringstream stream;
stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n";
stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n";
+ stream << "\nTime unit is : \"" << _time_unit << "\"";
return stream.str();
}
_end_order=tinyInfoI[5];
}
+/*!
+ * idem getTinySerializationIntInformation except that it is for multi field fetch
+ */
+void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
+{
+ tinyInfo.resize(4);
+ tinyInfo[0]=_start_iteration;
+ tinyInfo[1]=_start_order;
+ tinyInfo[2]=_end_iteration;
+ tinyInfo[3]=_end_order;
+}
+
+/*!
+ * idem getTinySerializationDbleInformation except that it is for multi field fetch
+ */
+void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
+{
+ tinyInfo.resize(3);
+ tinyInfo[0]=_time_tolerance;
+ tinyInfo[1]=_start_time;
+ tinyInfo[2]=_end_time;
+}
+
+/*!
+ * idem finishUnserialization except that it is for multi field fetch
+ */
+void MEDCouplingTwoTimeSteps::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
+{
+ _start_iteration=tinyInfoI[0];
+ _start_order=tinyInfoI[1];
+ _end_iteration=tinyInfoI[2];
+ _end_order=tinyInfoI[3];
+ _time_tolerance=tinyInfoD[0];
+ _start_time=tinyInfoD[1];
+ _end_time=tinyInfoD[2];
+}
+
std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
{
if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
std::ostringstream stream;
stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n";
stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n";
+ stream << "Time unit is : \"" << _time_unit << "\"";
return stream.str();
}
public:
void updateTime();
static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type);
+ void setTimeUnit(const char *unit) { _time_unit=unit; }
+ const char *getTimeUnit() const { return _time_unit.c_str(); }
virtual void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other);
virtual void copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other);
virtual void checkCoherency() const throw(INTERP_KERNEL::Exception);
virtual bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const;
virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
virtual bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const;
- virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other,
- TypeOfTimeDiscretization type, bool deepCpy) const;
+ virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(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 void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
virtual void resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays);
virtual void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
+ virtual void getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const = 0;
+ virtual void getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const = 0;
+ virtual void finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD) = 0;
virtual MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const = 0;
void setTimeTolerance(double val) { _time_tolerance=val; }
double getTimeTolerance() const { return _time_tolerance; }
//
virtual ~MEDCouplingTimeDiscretization();
protected:
+ std::string _time_unit;
double _time_tolerance;
DataArrayDouble *_array;
protected:
void setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception);
void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception);
void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception);
+ void getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const;
+ void getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const;
+ void finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD);
public:
static const TypeOfTimeDiscretization DISCRETIZATION=NO_TIME;
static const char REPR[];
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 getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const;
+ void getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const;
+ void finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD);
MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const;
void checkNoTimePresence() const throw(INTERP_KERNEL::Exception);
void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception);
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 getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const;
+ void getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const;
+ void finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD);
MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const;
bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const;
void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
void resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays);
void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
+ void getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const;
+ void getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const;
+ void finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD);
std::vector< const DataArrayDouble *> getArraysForTime(double time) const throw(INTERP_KERNEL::Exception);
void setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner) throw(INTERP_KERNEL::Exception);
protected:
static const char msg0[]="No coordinates specified !";
std::ostringstream ret;
ret << "Unstructured mesh with name : \"" << getName() << "\"\n";
+ ret << "Description of mesh : \"" << getDescription() << "\"\n";
ret << "Mesh dimension : " << _mesh_dim << "\nSpace dimension : ";
if(_coords!=0)
{
return 0;
}
ret2->setName(getName());
+ ret2->setDescription(getDescription());
return ret2;
}
MEDCouplingUMeshDesc.hxx MEDCouplingNatureOfField.hxx MEDCouplingFieldTemplate.hxx \
MEDCouplingNormalizedCartesianMesh.hxx MEDCouplingNormalizedCartesianMesh.txx \
MEDCouplingRemapper.hxx MEDCouplingExtrudedMesh.hxx MEDCouplingGaussLocalization.hxx \
-MEDCouplingAutoRefCountObjectPtr.hxx
+MEDCouplingAutoRefCountObjectPtr.hxx MEDCouplingMultiFields.hxx MEDCouplingDefinitionTime.hxx \
+MEDCouplingFieldOverTime.hxx
# Libraries targets
MEDCouplingFieldDiscretization.cxx MEDCouplingRefCountObject.cxx \
MEDCouplingPointSet.cxx MEDCouplingUMeshDesc.cxx MEDCouplingFieldTemplate.cxx \
MEDCouplingExtrudedMesh.cxx MEDCouplingMesh.cxx MEDCouplingGaussLocalization.cxx \
- MEDCouplingNatureOfField.cxx
+ MEDCouplingNatureOfField.cxx MEDCouplingMultiFields.cxx \
+ MEDCouplingDefinitionTime.cxx MEDCouplingFieldOverTime.cxx
libmedcoupling_la_LDFLAGS=
MEDCouplingNatureOfField.hxx \
MEDCouplingRemapper.hxx \
MEDCouplingExtrudedMesh.hxx \
- MEDCouplingGaussLocalization.hxx
+ MEDCouplingGaussLocalization.hxx \
+ MEDCouplingMultiFields.hxx \
+ MEDCouplingFieldTemplate.hxx \
+ MEDCouplingDefinitionTime.hxx \
+ MEDCouplingFieldOverTime.hxx
namespace ParaMEDMEM
{
class MEDCouplingUMesh;
+ class MEDCouplingFieldDouble;
+ class MEDCouplingMultiFields;
class MEDCouplingBasicsTest : public CppUnit::TestFixture
{
CPPUNIT_TEST( testFillFromAnalytic3 );
CPPUNIT_TEST( testFieldDoubleOpEqual1 );
CPPUNIT_TEST( testAreaBary3D2 );
+ //MEDCouplingBasicsTest3.cxx
CPPUNIT_TEST( testGetMeasureFieldCMesh1 );
CPPUNIT_TEST( testFieldDoubleZipCoords1 );
CPPUNIT_TEST( testFieldDoubleZipConnectivity1 );
CPPUNIT_TEST( testDAIAggregateMulti1 );
CPPUNIT_TEST( testMergeUMeshes2 );
CPPUNIT_TEST( testBuild0DMeshFromCoords1 );
+ //MEDCouplingBasicsTest4.cxx
+ CPPUNIT_TEST( testDescriptionInMeshTimeUnit1 );
+ CPPUNIT_TEST( testMultiFields1 );
+ CPPUNIT_TEST( testFieldOverTime1 );
//MEDCouplingBasicsTestInterp.cxx
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
void testFillFromAnalytic3();
void testFieldDoubleOpEqual1();
void testAreaBary3D2();
+ //MEDCouplingBasicsTest3.cxx
void testGetMeasureFieldCMesh1();
void testFieldDoubleZipCoords1();
void testFieldDoubleZipConnectivity1();
void testDAIAggregateMulti1();
void testMergeUMeshes2();
void testBuild0DMeshFromCoords1();
+ //MEDCouplingBasicsTest4.cxx
+ void testDescriptionInMeshTimeUnit1();
+ void testMultiFields1();
+ void testFieldOverTime1();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
static MEDCouplingUMesh *build2DTargetMesh_3();
static MEDCouplingUMesh *build3DTargetMesh_3();
static MEDCouplingUMesh *build2DTargetMesh_4();
+ static MEDCouplingMultiFields *buildMultiFields_1();
+ static std::vector<MEDCouplingFieldDouble *> buildMultiFields_2();
static double sumAll(const std::vector< std::map<int,double> >& matrix);
};
}
#include "MEDCouplingExtrudedMesh.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingMemArray.hxx"
+#include "MEDCouplingMultiFields.hxx"
#include "MEDCouplingBasicsTestData1.hxx"
return 0;
}
+MEDCouplingMultiFields *MEDCouplingBasicsTest::buildMultiFields_1()
+{
+ ParaMEDMEM::MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ m1->setName("m1");
+ ParaMEDMEM::MEDCouplingUMesh *m2=build2DTargetMesh_1();
+ m2->setName("m2");
+ const double vals0[]={-0.7,-1.,-2.,-3.,-4.};
+ const double vals1[]={0.,1.,2.,3.,4.,0.1,0.2,0.3,0.4};
+ const double vals1_1[]={170.,171.,172.,173.,174.,170.1,170.2,170.3,170.4};
+ const double vals2[]={5.,6.,7.,8.,9.};
+ const double vals4[]={15.,16.,17.,18.,19.};
+ //
+ ParaMEDMEM::DataArrayDouble *d0=ParaMEDMEM::DataArrayDouble::New(); d0->alloc(5,1); std::copy(vals0,vals0+5,d0->getPointer());
+ ParaMEDMEM::DataArrayDouble *d1=ParaMEDMEM::DataArrayDouble::New(); d1->alloc(9,1); std::copy(vals1,vals1+9,d1->getPointer());
+ ParaMEDMEM::DataArrayDouble *d1_1=ParaMEDMEM::DataArrayDouble::New(); d1_1->alloc(9,1); std::copy(vals1_1,vals1_1+9,d1_1->getPointer());
+ ParaMEDMEM::DataArrayDouble *d2=ParaMEDMEM::DataArrayDouble::New(); d2->alloc(5,1); std::copy(vals2,vals2+5,d2->getPointer());
+ ParaMEDMEM::DataArrayDouble *d4=ParaMEDMEM::DataArrayDouble::New(); d4->alloc(5,1); std::copy(vals4,vals4+5,d4->getPointer());
+ //
+ d0->setName("d0"); d1->setName("d1"); d1_1->setName("d1_1"); d2->setName("d2"); d4->setName("d4");
+ d0->setInfoOnComponent(0,"c1");
+ d1->setInfoOnComponent(0,"c6");
+ d1_1->setInfoOnComponent(0,"c9");
+ d2->setInfoOnComponent(0,"c5");
+ d4->setInfoOnComponent(0,"c7");
+ //
+ ParaMEDMEM::MEDCouplingFieldDouble *f0=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
+ f0->setMesh(m1);
+ f0->setArray(d0);
+ f0->setTime(0.2,5,6);
+ f0->setName("f0");
+ ParaMEDMEM::MEDCouplingFieldDouble *f1=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::LINEAR_TIME);
+ f1->setMesh(m1);
+ std::vector<ParaMEDMEM::DataArrayDouble *> d1s(2); d1s[0]=d1; d1s[1]=d1_1;
+ f1->setArrays(d1s);
+ f1->setStartTime(0.7,7,8);
+ f1->setEndTime(1.2,9,10);
+ f1->setName("f1");
+ ParaMEDMEM::MEDCouplingFieldDouble *f2=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::CONST_ON_TIME_INTERVAL);
+ f2->setMesh(m2);
+ f2->setArray(d2);
+ f2->setTime(1.2,11,12);
+ f2->setEndTime(1.5,13,14);
+ f2->setName("f2");
+ ParaMEDMEM::MEDCouplingFieldDouble *f3=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
+ f3->setMesh(m1);
+ f3->setArray(d2);
+ f3->setTime(1.7,15,16);
+ f3->setName("f3");
+ ParaMEDMEM::MEDCouplingFieldDouble *f4=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::NO_TIME);
+ f4->setMesh(m2);
+ f4->setArray(d4);
+ f4->setName("f4");
+ //
+ std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> fs(5);
+ fs[0]=f0; fs[1]=f1; fs[2]=f2; fs[3]=f3; fs[4]=f4;
+ ParaMEDMEM::MEDCouplingMultiFields *ret=ParaMEDMEM::MEDCouplingMultiFields::New(fs);
+ //
+ m1->decrRef();
+ m2->decrRef();
+ d0->decrRef();
+ d1->decrRef();
+ d1_1->decrRef();
+ d2->decrRef();
+ d4->decrRef();
+ f0->decrRef();
+ f1->decrRef();
+ f2->decrRef();
+ f3->decrRef();
+ f4->decrRef();
+ //
+ return ret;
+}
+
+std::vector<MEDCouplingFieldDouble *> MEDCouplingBasicsTest::buildMultiFields_2()
+{
+ ParaMEDMEM::MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ m1->setName("m1");
+ ParaMEDMEM::MEDCouplingUMesh *m2=build2DTargetMesh_1();
+ m2->setName("m2");
+ const double vals0[]={-0.7,-1.,-2.,-3.,-4.};
+ const double vals1[]={0.,1.,2.,3.,4.};
+ const double vals1_1[]={170.,171.,172.,173.,174.};
+ const double vals2[]={5.,6.,7.,8.,9.};
+ const double vals4[]={15.,16.,17.,18.,19.};
+ //
+ ParaMEDMEM::DataArrayDouble *d0=ParaMEDMEM::DataArrayDouble::New(); d0->alloc(5,1); std::copy(vals0,vals0+5,d0->getPointer());
+ ParaMEDMEM::DataArrayDouble *d1=ParaMEDMEM::DataArrayDouble::New(); d1->alloc(5,1); std::copy(vals1,vals1+5,d1->getPointer());
+ ParaMEDMEM::DataArrayDouble *d1_1=ParaMEDMEM::DataArrayDouble::New(); d1_1->alloc(5,1); std::copy(vals1_1,vals1_1+5,d1_1->getPointer());
+ ParaMEDMEM::DataArrayDouble *d2=ParaMEDMEM::DataArrayDouble::New(); d2->alloc(5,1); std::copy(vals2,vals2+5,d2->getPointer());
+ ParaMEDMEM::DataArrayDouble *d4=ParaMEDMEM::DataArrayDouble::New(); d4->alloc(5,1); std::copy(vals4,vals4+5,d4->getPointer());
+ //
+ d0->setName("d0"); d1->setName("d1"); d1_1->setName("d1_1"); d2->setName("d2"); d4->setName("d4");
+ d0->setInfoOnComponent(0,"c1");
+ d1->setInfoOnComponent(0,"c6");
+ d1_1->setInfoOnComponent(0,"c9");
+ d2->setInfoOnComponent(0,"c5");
+ d4->setInfoOnComponent(0,"c7");
+ //
+ ParaMEDMEM::MEDCouplingFieldDouble *f0=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
+ f0->setMesh(m1);
+ f0->setArray(d0);
+ f0->setTime(0.2,5,6);
+ f0->setName("f0");
+ ParaMEDMEM::MEDCouplingFieldDouble *f1=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::LINEAR_TIME);
+ f1->setMesh(m1);
+ std::vector<ParaMEDMEM::DataArrayDouble *> d1s(2); d1s[0]=d1; d1s[1]=d1_1;
+ f1->setArrays(d1s);
+ f1->setStartTime(0.7,7,8);
+ f1->setEndTime(1.2,9,10);
+ f1->setName("f1");
+ ParaMEDMEM::MEDCouplingFieldDouble *f2=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::CONST_ON_TIME_INTERVAL);
+ f2->setMesh(m2);
+ f2->setArray(d2);
+ f2->setTime(1.2,11,12);
+ f2->setEndTime(1.5,13,14);
+ f2->setName("f2");
+ ParaMEDMEM::MEDCouplingFieldDouble *f3=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
+ f3->setMesh(m1);
+ f3->setArray(d2);
+ f3->setTime(1.7,15,16);
+ f3->setName("f3");
+ ParaMEDMEM::MEDCouplingFieldDouble *f4=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::NO_TIME);
+ f4->setMesh(m2);
+ f4->setArray(d4);
+ f4->setName("f4");
+ //
+ std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> fs(5);
+ fs[0]=f0; fs[1]=f1; fs[2]=f2; fs[3]=f3; fs[4]=f4;
+ m1->decrRef();
+ m2->decrRef();
+ d0->decrRef();
+ d1->decrRef();
+ d1_1->decrRef();
+ d2->decrRef();
+ d4->decrRef();
+ //
+ return fs;
+}
+
double MEDCouplingBasicsTest::sumAll(const std::vector< std::map<int,double> >& matrix)
{
double ret=0.;
//
mesh->decrRef();
}
-
-void MEDCouplingBasicsTest::testGetMeasureFieldCMesh1()
-{
- MEDCouplingCMesh *m=MEDCouplingCMesh::New();
- DataArrayDouble *da=DataArrayDouble::New();
- const double discX[4]={2.3,3.4,5.8,10.2};
- const double discY[3]={12.3,23.4,45.8};
- const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
- da->alloc(4,1);
- std::copy(discX,discX+4,da->getPointer());
- m->setCoordsAt(0,da);
- da->decrRef();
- m->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
- CPPUNIT_ASSERT_EQUAL(3,m->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(1,m->getSpaceDimension());
- MEDCouplingFieldDouble *f=m->getMeasureField(true);
- CPPUNIT_ASSERT_EQUAL(3,f->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
- const double expected1[3]={1.1,2.4,4.4};
- for(int i=0;i<3;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(i,0),1e-12);
- f->decrRef();
- DataArrayDouble *coords=m->getCoordinatesAndOwner();
- CPPUNIT_ASSERT_EQUAL(4,coords->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
- for(int i=0;i<4;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(discX[i],coords->getIJ(i,0),1e-12);
- coords->decrRef();
- coords=m->getBarycenterAndOwner();
- CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
- const double expected1_3[3]={2.85,4.6,8.};
- for(int i=0;i<3;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1_3[i],coords->getIJ(i,0),1e-12);
- coords->decrRef();
- //
- da=DataArrayDouble::New();
- da->alloc(3,1);
- std::copy(discY,discY+3,da->getPointer());
- m->setCoordsAt(1,da);
- da->decrRef();
- m->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(12,m->getNumberOfNodes());
- CPPUNIT_ASSERT_EQUAL(6,m->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(2,m->getSpaceDimension());
- f=m->getMeasureField(true);
- CPPUNIT_ASSERT_EQUAL(6,f->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
- const double expected2[6]={12.21,26.64,48.84,24.64,53.76,98.56};
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(i,0),1e-12);
- f->decrRef();
- coords=m->getCoordinatesAndOwner();
- CPPUNIT_ASSERT_EQUAL(12,coords->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
- const double expected2_2[24]={2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8};
- for(int i=0;i<24;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_2[i],coords->getIJ(0,i),1e-12);
- coords->decrRef();
- coords=m->getBarycenterAndOwner();
- CPPUNIT_ASSERT_EQUAL(6,coords->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
- const double expected2_3[12]={2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6};
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_3[i],coords->getIJ(0,i),1e-12);
- coords->decrRef();
- //
- da=DataArrayDouble::New();
- da->alloc(5,1);
- std::copy(discZ,discZ+5,da->getPointer());
- m->setCoordsAt(2,da);
- da->decrRef();
- m->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(60,m->getNumberOfNodes());
- CPPUNIT_ASSERT_EQUAL(24,m->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
- f=m->getMeasureField(true);
- CPPUNIT_ASSERT_EQUAL(24,f->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
- const double expected3[24]={23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224};
- for(int i=0;i<24;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f->getIJ(i,0),1e-12);
- f->decrRef();
- coords=m->getCoordinatesAndOwner();
- CPPUNIT_ASSERT_EQUAL(60,coords->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
- const double expected3_2[180]={
- 2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
- 2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
- 2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
- 2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
- 2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67
- };
- for(int i=0;i<180;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_2[i],coords->getIJ(0,i),1e-12);
- coords->decrRef();
- coords=m->getBarycenterAndOwner();
- CPPUNIT_ASSERT_EQUAL(24,coords->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
- const double expected3_3[72]={
- 2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
- 2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
- 2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
- 2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4
- };
- for(int i=0;i<72;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_3[i],coords->getIJ(0,i),1e-12);
- coords->decrRef();
- //
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testFieldDoubleZipCoords1()
-{
- MEDCouplingUMesh *m=build2DTargetMeshMergeNode_1();
- MEDCouplingFieldDouble *f=m->fillFromAnalytic(ON_NODES,2,"x*2.");
- f->getArray()->setInfoOnComponent(0,"titi");
- f->getArray()->setInfoOnComponent(1,"tutu");
- f->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(18,f->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
- const double expected1[36]={-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
- for(int i=0;i<36;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
- CPPUNIT_ASSERT(f->zipCoords());
- f->checkCoherency();
- const double expected2[30]={-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
- CPPUNIT_ASSERT(!f->zipCoords());
- f->checkCoherency();
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
- CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
- CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
- f->decrRef();
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testFieldDoubleZipConnectivity1()
-{
- MEDCouplingUMesh *m1=build2DTargetMesh_1();
- MEDCouplingUMesh *m2=build2DTargetMesh_1();
- const int cells1[3]={2,3,4};
- MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
- MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
- CPPUNIT_ASSERT(m3);
- m2->decrRef();
- MEDCouplingUMesh *m4=build2DSourceMesh_1();
- MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
- m1->decrRef();
- m3->decrRef();
- MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
- m4->decrRef();
- m5->decrRef();
- //
- CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
- bool areNodesMerged;
- int newNbOfNodes;
- DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
- CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
- arr->decrRef();
- MEDCouplingFieldDouble *f=m6->fillFromAnalytic(ON_CELLS,2,"x");
- MEDCouplingFieldDouble *f2=m6->fillFromAnalytic(ON_NODES,2,"x");
- CPPUNIT_ASSERT_EQUAL(10,f->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
- const double expected1[20]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
- -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
- 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
- for(int i=0;i<20;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
- f->getArray()->setInfoOnComponent(0,"titi");
- f->getArray()->setInfoOnComponent(1,"tutu");
- f->checkCoherency();
- CPPUNIT_ASSERT(f->zipConnectivity(0));
- const double expected2[14]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
- -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
- CPPUNIT_ASSERT_EQUAL(7,f->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
- CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
- CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
- CPPUNIT_ASSERT(!f->zipConnectivity(0));
- f->decrRef();
- //
- const double expected3[18]={-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7,
- -0.3, -0.3, 0.2, 0.2, 0.7, 0.7};
- CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
- for(int i=0;i<18;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
- CPPUNIT_ASSERT(f2->zipConnectivity(0));
- CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
- for(int i=0;i<18;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
- f2->decrRef();
- //
- m6->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDaDoubleRenumber1()
-{
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(7,2);
- a->setInfoOnComponent(0,"toto");
- a->setInfoOnComponent(1,"tata");
- const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
- std::copy(arr1,arr1+14,a->getPointer());
- //
- const int arr2[7]={3,1,0,6,5,4,2};
- DataArrayDouble *b=a->renumber(arr2);
- CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
- const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
- b->decrRef();
- a->decrRef();
- //
- DataArrayInt *c=DataArrayInt::New();
- c->alloc(7,2);
- c->setInfoOnComponent(0,"toto");
- c->setInfoOnComponent(1,"tata");
- const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
- std::copy(arr3,arr3+14,c->getPointer());
- DataArrayInt *d=c->renumber(arr2);
- CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
- const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
- c->decrRef();
- d->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDaDoubleRenumberAndReduce1()
-{
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(7,2);
- a->setInfoOnComponent(0,"toto");
- a->setInfoOnComponent(1,"tata");
- const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
- std::copy(arr1,arr1+14,a->getPointer());
- //
- const int arr2[7]={2,-1,1,-1,0,4,3};
- DataArrayDouble *b=a->renumberAndReduce(arr2,5);
- CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
- const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
- for(int i=0;i<10;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
- b->decrRef();
- a->decrRef();
- //
- DataArrayInt *c=DataArrayInt::New();
- c->alloc(7,2);
- c->setInfoOnComponent(0,"toto");
- c->setInfoOnComponent(1,"tata");
- const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
- std::copy(arr3,arr3+14,c->getPointer());
- DataArrayInt *d=c->renumberAndReduce(arr2,5);
- CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
- const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
- for(int i=0;i<10;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
- c->decrRef();
- d->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDaDoubleRenumberInPlace1()
-{
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(7,2);
- const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
- std::copy(arr1,arr1+14,a->getPointer());
- //
- const int arr2[7]={3,1,0,6,5,4,2};
- a->renumberInPlace(arr2);
- CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
- const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
- a->decrRef();
- //
- DataArrayInt *c=DataArrayInt::New();
- c->alloc(7,2);
- const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
- std::copy(arr3,arr3+14,c->getPointer());
- c->renumberInPlace(arr2);
- CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
- const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
- c->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDaDoubleRenumberR1()
-{
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(7,2);
- a->setInfoOnComponent(0,"toto");
- a->setInfoOnComponent(1,"tata");
- const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
- std::copy(arr1,arr1+14,a->getPointer());
- //
- const int arr2[7]={3,1,0,6,5,4,2};
- DataArrayDouble *b=a->renumberR(arr2);
- CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
- const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
- b->decrRef();
- a->decrRef();
- //
- DataArrayInt *c=DataArrayInt::New();
- c->alloc(7,2);
- c->setInfoOnComponent(0,"toto");
- c->setInfoOnComponent(1,"tata");
- const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
- std::copy(arr3,arr3+14,c->getPointer());
- DataArrayInt *d=c->renumberR(arr2);
- CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
- const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
- c->decrRef();
- d->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDaDoubleRenumberInPlaceR1()
-{
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(7,2);
- const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
- std::copy(arr1,arr1+14,a->getPointer());
- //
- const int arr2[7]={3,1,0,6,5,4,2};
- a->renumberInPlaceR(arr2);
- CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
- const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
- a->decrRef();
- //
- DataArrayInt *c=DataArrayInt::New();
- c->alloc(7,2);
- const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
- std::copy(arr3,arr3+14,c->getPointer());
- c->renumberInPlaceR(arr2);
- CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
- const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
- c->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDaDoubleSelectByTupleId1()
-{
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(7,2);
- a->setInfoOnComponent(0,"toto");
- a->setInfoOnComponent(1,"tata");
- const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
- std::copy(arr1,arr1+14,a->getPointer());
- //
- const int arr2[7]={4,2,0,6,5};
- DataArrayDouble *b=a->selectByTupleId(arr2,arr2+5);
- CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
- const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
- for(int i=0;i<10;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
- b->decrRef();
- a->decrRef();
- //
- DataArrayInt *c=DataArrayInt::New();
- c->alloc(7,2);
- c->setInfoOnComponent(0,"toto");
- c->setInfoOnComponent(1,"tata");
- const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
- std::copy(arr3,arr3+14,c->getPointer());
- DataArrayInt *d=c->selectByTupleId(arr2,arr2+5);
- CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
- const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
- for(int i=0;i<10;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
- c->decrRef();
- d->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDaDoubleGetMinMaxValues1()
-{
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(9,1);
- const double arr1[9]={2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56};
- std::copy(arr1,arr1+9,a->getPointer());
- int where;
- double m=a->getMaxValue(where);
- CPPUNIT_ASSERT_EQUAL(1,where);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
- DataArrayInt *ws;
- m=a->getMaxValue2(ws);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
- CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
- const int expected1[3]={1,4,8};
- for(int i=0;i<3;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
- ws->decrRef();
- a->decrRef();
- a=DataArrayDouble::New();
- const double arr2[9]={-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56};
- a->alloc(9,1);
- std::copy(arr2,arr2+9,a->getPointer());
- where=-2;
- m=a->getMinValue(where);
- CPPUNIT_ASSERT_EQUAL(1,where);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
- m=a->getMinValue2(ws);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
- CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
- for(int i=0;i<3;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
- ws->decrRef();
- a->decrRef();
-}
-
-void MEDCouplingBasicsTest::testFieldDoubleGetMinMaxValues2()
-{
- MEDCouplingUMesh *m1=0;
- MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
- m1->decrRef();
- CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
- const double arr1[18]={8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71};
- MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(18,1);
- std::copy(arr1,arr1+18,a->getPointer());
- f->setArray(a);
- a->decrRef();
- f->setMesh(m2);
- //
- f->checkCoherency();
- double m=f->getMaxValue();
- CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
- DataArrayInt *ws;
- m=f->getMaxValue2(ws);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
- CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
- const int expected1[4]={0,3,7,17};
- for(int i=0;i<4;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
- ws->decrRef();
- //
- const double arr2[18]={-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71};
- std::copy(arr2,arr2+18,a->getPointer());
- f->checkCoherency();
- m=f->getMinValue();
- CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
- m=f->getMinValue2(ws);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
- CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
- for(int i=0;i<4;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
- ws->decrRef();
- //
- f->decrRef();
- m2->decrRef();
-}
-
-void MEDCouplingBasicsTest::testBuildUnstructuredCMesh1()
-{
- MEDCouplingCMesh *m=MEDCouplingCMesh::New();
- DataArrayDouble *da=DataArrayDouble::New();
- const double discX[4]={2.3,3.4,5.8,10.2};
- const double discY[3]={12.3,23.4,45.8};
- const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
- da->alloc(4,1);
- std::copy(discX,discX+4,da->getPointer());
- m->setCoordsAt(0,da);
- da->decrRef();
- m->checkCoherency();
- double pos=2.4;
- CPPUNIT_ASSERT_EQUAL(0,m->getCellContainingPoint(&pos,1e-12));
- pos=3.7;
- CPPUNIT_ASSERT_EQUAL(1,m->getCellContainingPoint(&pos,1e-12));
- pos=5.9;
- CPPUNIT_ASSERT_EQUAL(2,m->getCellContainingPoint(&pos,1e-12));
- pos=10.3;
- CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
- pos=1.3;
- CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
- //
- MEDCouplingUMesh *m2=m->buildUnstructured();
- m2->checkCoherency();
- MEDCouplingFieldDouble *f1=m->getMeasureField(false);
- MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
- CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),3);
- CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),3);
- CPPUNIT_ASSERT_EQUAL(1,m2->getMeshDimension());
- CPPUNIT_ASSERT_EQUAL(1,m2->getSpaceDimension());
- for(int i=0;i<3;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
- da=DataArrayDouble::New();
- da->alloc(3,1);
- std::copy(discY,discY+3,da->getPointer());
- m->setCoordsAt(1,da);
- da->decrRef();
- m2->decrRef();
- f1->decrRef();
- f2->decrRef();
- //
- m2=m->buildUnstructured();
- m2->checkCoherency();
- f1=m->getMeasureField(false);
- f2=m2->getMeasureField(false);
- CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),6);
- CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),6);
- CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
- CPPUNIT_ASSERT_EQUAL(2,m2->getSpaceDimension());
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
- f1->decrRef();
- f2->decrRef();
- m2->decrRef();
- //
- da=DataArrayDouble::New();
- da->alloc(5,1);
- std::copy(discZ,discZ+5,da->getPointer());
- m->setCoordsAt(2,da);
- da->decrRef();
- m2=m->buildUnstructured();
- m2->checkCoherency();
- f1=m->getMeasureField(false);
- f2=m2->getMeasureField(false);
- CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),24);
- CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),24);
- CPPUNIT_ASSERT_EQUAL(3,m2->getMeshDimension());
- CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
- for(int i=0;i<24;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
- f1->decrRef();
- f2->decrRef();
- //
- double pos1[3]={5.,30.,2.};
- CPPUNIT_ASSERT_EQUAL(16,m->getCellContainingPoint(pos1,1e-12));
- //
- const double pt[3]={2.4,12.7,-3.4};
- m->scale(pt,3.7);
- MEDCouplingUMesh *m3=m->buildUnstructured();
- m2->scale(pt,3.7);
- CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
- m2->decrRef();
- m3->decrRef();
- //
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDataArrayIntInvertO2NNO21()
-{
- const int arr1[6]={2,0,4,1,5,3};
- DataArrayInt *da=DataArrayInt::New();
- da->alloc(6,1);
- std::copy(arr1,arr1+6,da->getPointer());
- DataArrayInt *da2=da->invertArrayO2N2N2O(6);
- CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
- const int expected1[6]={1,3,0,5,2,4};
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
- DataArrayInt *da3=da2->invertArrayN2O2O2N(6);
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_EQUAL(arr1[i],da3->getIJ(i,0));
- da3->decrRef();
- da2->decrRef();
- da->decrRef();
- //
- const int arr2[10]={3,-1,5,4,-1,0,-1,1,2,-1};
- da=DataArrayInt::New();
- da->alloc(10,1);
- std::copy(arr2,arr2+10,da->getPointer());
- da2=da->invertArrayO2N2N2O(6);
- CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
- const int expected2[10]={5,7,8,0,3,2};
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],da2->getIJ(i,0));
- da3=da2->invertArrayN2O2O2N(10);
- for(int i=0;i<10;i++)
- CPPUNIT_ASSERT_EQUAL(arr2[i],da3->getIJ(i,0));
- da3->decrRef();
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testKeepSetSelectedComponent1()
-{
- const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
- DataArrayDouble *a1=DataArrayDouble::New();
- a1->alloc(5,4);
- std::copy(arr1,arr1+20,a1->getPointer());
- a1->setInfoOnComponent(0,"aaaa");
- a1->setInfoOnComponent(1,"bbbb");
- a1->setInfoOnComponent(2,"cccc");
- a1->setInfoOnComponent(3,"dddd");
- const int arr2[6]={1,2,1,2,0,0};
- std::vector<int> arr2V(arr2,arr2+6);
- DataArrayDouble *a2=a1->keepSelectedComponents(arr2V);
- CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="cccc");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="bbbb");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
- const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
- DataArrayInt *a3=a1->convertToIntArr();
- DataArrayInt *a4=a3->keepSelectedComponents(arr2V);
- CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="cccc");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="bbbb");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_EQUAL(int(expected1[i]),a4->getIJ(0,i));
- // setSelectedComponents
- const int arr3[2]={3,2};
- std::vector<int> arr3V(arr3,arr3+2);
- DataArrayDouble *a5=a1->keepSelectedComponents(arr3V);
- a5->setInfoOnComponent(0,"eeee");
- a5->setInfoOnComponent(1,"ffff");
- const int arr4[2]={1,2};
- std::vector<int> arr4V(arr4,arr4+2);
- a2->setSelectedComponents(a5,arr4V);
- CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="eeee");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="ffff");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
- CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
- const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
- DataArrayInt *a6=a5->convertToIntArr();
- a6->setInfoOnComponent(0,"eeee");
- a6->setInfoOnComponent(1,"ffff");
- a4->setSelectedComponents(a6,arr4V);
- CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="eeee");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="ffff");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
- CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_EQUAL(int(expected2[i]),a4->getIJ(0,i));
- // test of throw
- const int arr5[3]={2,3,6};
- const int arr6[3]={2,7,5};
- const int arr7[4]={2,1,4,6};
- std::vector<int> arr5V(arr5,arr5+3);
- std::vector<int> arr6V(arr6,arr6+3);
- std::vector<int> arr7V(arr7,arr7+4);
- CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr5V),INTERP_KERNEL::Exception);
- CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr6V),INTERP_KERNEL::Exception);
- CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
- arr7V.resize(3);
- CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
- //
- a6->decrRef();
- a5->decrRef();
- a4->decrRef();
- a3->decrRef();
- a2->decrRef();
- a1->decrRef();
-}
-
-void MEDCouplingBasicsTest::testKeepSetSelectedComponent2()
-{
- MEDCouplingUMesh *m1=build2DTargetMesh_1();
- const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
- DataArrayDouble *a1=DataArrayDouble::New();
- a1->alloc(5,4);
- std::copy(arr1,arr1+20,a1->getPointer());
- a1->setInfoOnComponent(0,"aaaa");
- a1->setInfoOnComponent(1,"bbbb");
- a1->setInfoOnComponent(2,"cccc");
- a1->setInfoOnComponent(3,"dddd");
- MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
- f1->setTime(2.3,4,5);
- f1->setMesh(m1);
- f1->setName("f1");
- f1->setArray(a1);
- f1->checkCoherency();
- //
- const int arr2[6]={1,2,1,2,0,0};
- std::vector<int> arr2V(arr2,arr2+6);
- MEDCouplingFieldDouble *f2=f1->keepSelectedComponents(arr2V);
- CPPUNIT_ASSERT(f2->getMesh()==f1->getMesh());
- CPPUNIT_ASSERT(f2->getTimeDiscretization()==ONE_TIME);
- int dt,it;
- CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
- CPPUNIT_ASSERT_EQUAL(4,dt);
- CPPUNIT_ASSERT_EQUAL(5,it);
- f2->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="cccc");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="bbbb");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
- const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f2->getIJ(0,i),1e-14);
- //setSelectedComponents
- const int arr3[2]={3,2};
- std::vector<int> arr3V(arr3,arr3+2);
- MEDCouplingFieldDouble *f5=f1->keepSelectedComponents(arr3V);
- f5->setTime(6.7,8,9);
- f5->getArray()->setInfoOnComponent(0,"eeee");
- f5->getArray()->setInfoOnComponent(1,"ffff");
- f5->checkCoherency();
- const int arr4[2]={1,2};
- std::vector<int> arr4V(arr4,arr4+2);
- f2->setSelectedComponents(f5,arr4V);
- CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
- f2->checkCoherency();
- CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
- CPPUNIT_ASSERT_EQUAL(4,dt);
- CPPUNIT_ASSERT_EQUAL(5,it);
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="eeee");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="ffff");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
- CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
- const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-14);
- f5->decrRef();
- f1->decrRef();
- f2->decrRef();
- a1->decrRef();
- m1->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIGetIdsEqual1()
-{
- const int tab1[7]={5,-2,-4,-2,3,2,-2};
- DataArrayInt *da=DataArrayInt::New();
- da->alloc(7,1);
- std::copy(tab1,tab1+7,da->getPointer());
- DataArrayInt *da2=da->getIdsEqual(-2);
- CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
- const int expected1[3]={1,3,6};
- CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da2->getConstPointer()));
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIGetIdsEqualList1()
-{
- const int tab1[7]={5,-2,-4,-2,3,2,-2};
- DataArrayInt *da=DataArrayInt::New();
- da->alloc(7,1);
- std::copy(tab1,tab1+7,da->getPointer());
- const int tab2[3]={3,-2,0};
- std::vector<int> tab2V(tab2,tab2+3);
- DataArrayInt *da2=da->getIdsEqualList(tab2V);
- CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
- const int expected1[4]={1,3,4,6};
- CPPUNIT_ASSERT(std::equal(expected1,expected1+4,da2->getConstPointer()));
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAFromNoInterlace1()
-{
- const int tab1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
- DataArrayInt *da=DataArrayInt::New();
- da->alloc(5,3);
- std::copy(tab1,tab1+15,da->getPointer());
- DataArrayInt *da2=da->fromNoInterlace();
- const int expected1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
- CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
- CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
- DataArrayDouble *da3=da->convertToDblArr();
- DataArrayDouble *da4=da3->fromNoInterlace();
- CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
- for(int i=0;i<15;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
- da4->decrRef();
- da3->decrRef();
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAToNoInterlace1()
-{
- const int tab1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
- DataArrayInt *da=DataArrayInt::New();
- da->alloc(5,3);
- std::copy(tab1,tab1+15,da->getPointer());
- DataArrayInt *da2=da->toNoInterlace();
- const int expected1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
- CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
- CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
- DataArrayDouble *da3=da->convertToDblArr();
- DataArrayDouble *da4=da3->toNoInterlace();
- CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
- for(int i=0;i<15;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
- da4->decrRef();
- da3->decrRef();
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIsUniform1()
-{
- const int tab1[5]={1,1,1,1,1};
- DataArrayInt *da=DataArrayInt::New();
- da->alloc(5,1);
- std::copy(tab1,tab1+5,da->getPointer());
- CPPUNIT_ASSERT(da->isUniform(1));
- da->setIJ(2,0,2);
- CPPUNIT_ASSERT(!da->isUniform(1));
- da->setIJ(2,0,1);
- CPPUNIT_ASSERT(da->isUniform(1));
- DataArrayDouble *da2=da->convertToDblArr();
- CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
- da2->setIJ(1,0,1.+1.e-13);
- CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
- da2->setIJ(1,0,1.+1.e-11);
- CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDADFromPolarToCart1()
-{
- const double tab1[4]={2.,0.2,2.5,0.7};
- DataArrayDouble *da=DataArrayDouble::New();
- da->alloc(2,2);
- std::copy(tab1,tab1+4,da->getPointer());
- DataArrayDouble *da2=da->fromPolarToCart();
- const double expected1[4]={1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275};
- for(int i=0;i<4;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDADFromCylToCart1()
-{
- const double tab1[6]={2.,0.2,4.,2.5,0.7,9.};
- DataArrayDouble *da=DataArrayDouble::New();
- da->alloc(2,3);
- std::copy(tab1,tab1+6,da->getPointer());
- DataArrayDouble *da2=da->fromCylToCart();
- const double expected1[6]={1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.};
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDADFromSpherToCart1()
-{
- const double tab1[6]={2.,0.2,0.3,2.5,0.7,0.8};
- DataArrayDouble *da=DataArrayDouble::New();
- da->alloc(2,3);
- std::copy(tab1,tab1+6,da->getPointer());
- DataArrayDouble *da2=da->fromSpherToCart();
- const double expected1[6]={0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213};
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
- da2->decrRef();
- da->decrRef();
-}
-
-void MEDCouplingBasicsTest::testUnPolyze1()
-{
- const int elts[8]={0,1,2,3,4,5,6,7};
- std::vector<int> eltsV(elts,elts+8);
- MEDCouplingUMesh *mesh=build3DTargetMesh_1();
- mesh->convertToPolyTypes(eltsV);
- mesh->unPolyze();
- MEDCouplingUMesh *mesh2=build3DTargetMesh_1();
- mesh->checkCoherency();
- CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
- mesh->convertToPolyTypes(eltsV);
- CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
- mesh->getNodalConnectivity()->setIJ(0,6,10);
- mesh->getNodalConnectivity()->setIJ(0,7,9);
- mesh->getNodalConnectivity()->setIJ(0,8,12);
- mesh->getNodalConnectivity()->setIJ(0,9,13);
- mesh->unPolyze();
- CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
- mesh->convertToPolyTypes(eltsV);
- mesh->getNodalConnectivity()->setIJ(0,6,12);
- mesh->getNodalConnectivity()->setIJ(0,7,13);
- mesh->getNodalConnectivity()->setIJ(0,8,10);
- mesh->getNodalConnectivity()->setIJ(0,9,9);
- mesh->unPolyze();
- CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
- mesh->convertToPolyTypes(eltsV);
- mesh->getNodalConnectivity()->setIJ(0,6,12);
- mesh->getNodalConnectivity()->setIJ(0,7,10);
- mesh->getNodalConnectivity()->setIJ(0,8,13);
- mesh->getNodalConnectivity()->setIJ(0,9,9);
- mesh->unPolyze();
- CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
- mesh->decrRef();
- mesh2->decrRef();
- // Test for 2D mesh
- mesh=build2DTargetMesh_1();
- mesh2=build2DTargetMesh_1();
- eltsV.resize(5);
- mesh->convertToPolyTypes(eltsV);
- CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
- mesh->unPolyze();
- CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
- mesh->decrRef();
- mesh2->decrRef();
-}
-
-void MEDCouplingBasicsTest::testConvertDegeneratedCells1()
-{
- MEDCouplingUMesh *mesh=build3DTargetMesh_1();
- int conn[32]={0,1,3,3,9,10,12,12, 0,1,3,4,9,9,9,9, 1,1,1,1,10,12,9,10, 10,11,12,9,1,1,1,1};
- mesh->allocateCells(4);
- mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
- mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+8);
- mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+16);
- mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+24);
- mesh->finishInsertingCells();
- mesh->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(0));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(1));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(2));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(3));
- MEDCouplingFieldDouble *f1=mesh->getMeasureField(true);
- mesh->convertDegeneratedCells();
- mesh->checkCoherency();
- MEDCouplingFieldDouble *f2=mesh->getMeasureField(true);
- CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,mesh->getTypeOfCell(0));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(1));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TETRA4,mesh->getTypeOfCell(2));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(3));
- for(int i=0;i<4;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getArray()->getIJ(0,i),f2->getArray()->getIJ(0,i),1e-5);
- f1->decrRef();
- f2->decrRef();
- mesh->decrRef();
-}
-
-void MEDCouplingBasicsTest::testGetNodeIdsNearPoints1()
-{
- MEDCouplingUMesh *mesh=build2DTargetMesh_1();
- DataArrayDouble *coords=mesh->getCoords();
- DataArrayDouble *tmp=DataArrayDouble::New();
- tmp->alloc(3,2);
- const double vals[6]={0.2,0.2,0.1,0.2,0.2,0.2};
- std::copy(vals,vals+6,tmp->getPointer());
- DataArrayDouble *tmp2=DataArrayDouble::Aggregate(coords,tmp);
- tmp->decrRef();
- mesh->setCoords(tmp2);
- tmp2->decrRef();
- const double pts[6]={0.2,0.2,0.1,0.3,-0.3,0.7};
- std::vector<int> c=mesh->getNodeIdsNearPoint(pts,1e-7);
- CPPUNIT_ASSERT_EQUAL(3,(int)c.size());
- CPPUNIT_ASSERT_EQUAL(4,c[0]);
- CPPUNIT_ASSERT_EQUAL(9,c[1]);
- CPPUNIT_ASSERT_EQUAL(11,c[2]);
- c.clear();
- std::vector<int> cI;
- mesh->getNodeIdsNearPoints(pts,3,1e-7,c,cI);
- CPPUNIT_ASSERT_EQUAL(4,(int)cI.size());
- CPPUNIT_ASSERT_EQUAL(4,(int)c.size());
- CPPUNIT_ASSERT_EQUAL(4,c[0]);
- CPPUNIT_ASSERT_EQUAL(9,c[1]);
- CPPUNIT_ASSERT_EQUAL(11,c[2]);
- CPPUNIT_ASSERT_EQUAL(6,c[3]);
- CPPUNIT_ASSERT_EQUAL(0,cI[0]);
- CPPUNIT_ASSERT_EQUAL(3,cI[1]);
- CPPUNIT_ASSERT_EQUAL(3,cI[2]);
- CPPUNIT_ASSERT_EQUAL(4,cI[3]);
- mesh->decrRef();
-}
-
-void MEDCouplingBasicsTest::testFieldCopyTinyAttrFrom1()
-{
- MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
- f1->setName("f1");
- f1->setTimeTolerance(1.e-5);
- f1->setDescription("f1Desc");
- f1->setTime(1.23,4,5);
- MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
- f2->setName("f2");
- f2->setDescription("f2Desc");
- f2->setTime(6.78,9,10);
- f2->setTimeTolerance(4.556e-12);
- //
- int dt,it;
- f1->copyTinyAttrFrom(f2);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
- CPPUNIT_ASSERT_EQUAL(9,dt);
- CPPUNIT_ASSERT_EQUAL(10,it);
- CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
- CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
- f1->decrRef();
- f2->decrRef();
- //
- f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
- f1->setName("f1");
- f1->setTimeTolerance(1.e-5);
- f1->setDescription("f1Desc");
- f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
- f2->setName("f2");
- f2->setDescription("f2Desc");
- f2->setTimeTolerance(4.556e-12);
- //
- f1->copyTinyAttrFrom(f2);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
- CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
- CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
- f1->decrRef();
- f2->decrRef();
- //
- f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
- f1->setName("f1");
- f1->setTimeTolerance(1.e-5);
- f1->setDescription("f1Desc");
- f1->setTime(1.23,4,5);
- f1->setEndTime(5.43,2,1);
- f2=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
- f2->setName("f2");
- f2->setDescription("f2Desc");
- f2->setTimeTolerance(4.556e-12);
- f2->setTime(6.78,9,10);
- f2->setEndTime(10.98,7,6);
- //
- f1->copyTinyAttrFrom(f2);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
- CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
- CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
- CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
- CPPUNIT_ASSERT_EQUAL(9,dt);
- CPPUNIT_ASSERT_EQUAL(10,it);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
- CPPUNIT_ASSERT_EQUAL(7,dt);
- CPPUNIT_ASSERT_EQUAL(6,it);
- f1->decrRef();
- f2->decrRef();
- //
- f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
- f1->setName("f1");
- f1->setTimeTolerance(1.e-5);
- f1->setDescription("f1Desc");
- f1->setTime(1.23,4,5);
- f1->setEndTime(5.43,2,1);
- f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
- f2->setName("f2");
- f2->setDescription("f2Desc");
- f2->setTimeTolerance(4.556e-12);
- f2->setTime(6.78,9,10);
- f2->setEndTime(10.98,7,6);
- //
- f1->copyTinyAttrFrom(f2);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
- CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
- CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
- CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
- CPPUNIT_ASSERT_EQUAL(9,dt);
- CPPUNIT_ASSERT_EQUAL(10,it);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
- CPPUNIT_ASSERT_EQUAL(7,dt);
- CPPUNIT_ASSERT_EQUAL(6,it);
- f1->decrRef();
- f2->decrRef();
-}
-
-/*!
- * 1D -> 2D extrusion with rotation
- */
-void MEDCouplingBasicsTest::testExtrudedMesh5()
-{
- const double coo1[4]={0.,1.,2.,3.5};
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(4,1);
- std::copy(coo1,coo1+4,a->getPointer());
- MEDCouplingCMesh *b=MEDCouplingCMesh::New();
- b->setCoordsAt(0,a);
- MEDCouplingUMesh *c=b->buildUnstructured();
- CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
- c->changeSpaceDimension(2);
- //
- DataArrayDouble *d=DataArrayDouble::New();
- d->alloc(13,1);
- d->iota();
- MEDCouplingCMesh *e=MEDCouplingCMesh::New();
- e->setCoordsAt(0,d);
- MEDCouplingUMesh *f=e->buildUnstructured();
- DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
- DataArrayDouble *h=g->fromPolarToCart();
- f->setCoords(h);
- MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
- CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
- bool tmp2;
- int tmp3;
- DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
- CPPUNIT_ASSERT(tmp2);
- CPPUNIT_ASSERT_EQUAL(37,tmp3);
- tmp->decrRef();
- i->convertDegeneratedCells();
- i->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(36,i->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(37,i->getNumberOfNodes());
- CPPUNIT_ASSERT_EQUAL(12,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3));
- CPPUNIT_ASSERT_EQUAL(24,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4));
- const double expected1[3]={0.25,0.75,2.0625};
- MEDCouplingFieldDouble *j=i->getMeasureField(true);
- for(int i=0;i<12;i++)
- for(int k=0;k<3;k++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[k],j->getIJ(0,i*3+k),1e-10);
- const double expected2[72]={0.62200846792814113, 0.16666666666681595, 1.4513530918323276, 0.38888888888923495, 2.6293994326053212, 0.7045454545460802, 0.45534180126145435, 0.45534180126150181, 1.0624642029433926, 1.0624642029435025, 1.9248539780597826, 1.9248539780599816, 0.16666666666661334, 0.62200846792815856, 0.38888888888876294, 1.4513530918323678, 0.70454545454522521, 2.629399432605394, -0.16666666666674007, 0.62200846792812436, -0.38888888888906142, 1.4513530918322881, -0.70454545454576778, 2.6293994326052488, -0.45534180126154766, 0.45534180126140844, -1.0624642029436118, 1.0624642029432834, -1.9248539780601803, 1.9248539780595841, -0.62200846792817499, 0.1666666666665495, -1.451353091832408, 0.388888888888613, -2.6293994326054668, 0.70454545454495332, -0.62200846792810593, -0.16666666666680507, -1.451353091832247, -0.38888888888921297, -2.6293994326051746, -0.70454545454604123, -0.45534180126135926, -0.45534180126159562, -1.0624642029431723, -1.0624642029437235, -1.9248539780593836, -1.9248539780603811, -0.1666666666664828, -0.62200846792819242, -0.38888888888846079, -1.4513530918324489, -0.70454545454467987, -2.6293994326055397, 0.16666666666687083, -0.62200846792808862, 0.38888888888936374, -1.4513530918322073, 0.70454545454631357, -2.6293994326051022, 0.45534180126164348, -0.45534180126131207, 1.0624642029438327, -1.0624642029430627, 1.9248539780605791, -1.9248539780591853, 0.62200846792821063, -0.16666666666641802, 1.4513530918324888, -0.38888888888831086, 2.6293994326056125, -0.70454545454440853};
- DataArrayDouble *m=i->getBarycenterAndOwner();
- for(int i=0;i<72;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m->getIJ(0,i),1e-10);
- //
- m->decrRef();
- j->decrRef();
- i->decrRef();
- h->decrRef();
- g->decrRef();
- f->decrRef();
- e->decrRef();
- d->decrRef();
- c->decrRef();
- b->decrRef();
- a->decrRef();
-}
-
-/*!
- * 1D -> 2D extrusion without rotation
- */
-void MEDCouplingBasicsTest::testExtrudedMesh6()
-{
- const double coo1[4]={0.,1.,2.,3.5};
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(4,1);
- std::copy(coo1,coo1+4,a->getPointer());
- MEDCouplingCMesh *b=MEDCouplingCMesh::New();
- b->setCoordsAt(0,a);
- MEDCouplingUMesh *c=b->buildUnstructured();
- CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
- c->changeSpaceDimension(2);
- //
- DataArrayDouble *d=DataArrayDouble::New();
- d->alloc(5,1);
- d->iota();
- MEDCouplingCMesh *e=MEDCouplingCMesh::New();
- e->setCoordsAt(0,d);
- MEDCouplingUMesh *f=e->buildUnstructured();
- DataArrayDouble *d2=f->getCoords()->applyFunc("x*x/2");
- f->setCoords(d2);
- f->changeSpaceDimension(2);
- //
- const double center[2]={0.,0.};
- f->rotate(center,0,M_PI/3);
- MEDCouplingUMesh *g=c->buildExtrudedMesh(f,0);
- g->checkCoherency();
- const double expected1[]={ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 };
- MEDCouplingFieldDouble *f1=g->getMeasureField(true);
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-12);
-
- const double expected2[]={0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414};
- DataArrayDouble *f2=g->getBarycenterAndOwner();
- for(int i=0;i<24;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-12);
- //
- f1->decrRef();
- f2->decrRef();
- g->decrRef();
- f->decrRef();
- e->decrRef();
- d->decrRef();
- d2->decrRef();
- c->decrRef();
- b->decrRef();
- a->decrRef();
-}
-
-/*!
- * 2D -> 3D extrusion with rotation
- */
-void MEDCouplingBasicsTest::testExtrudedMesh7()
-{
- const double coo1[4]={0.,1.,2.,3.5};
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(4,1);
- std::copy(coo1,coo1+4,a->getPointer());
- MEDCouplingCMesh *b=MEDCouplingCMesh::New();
- b->setCoordsAt(0,a);
- MEDCouplingUMesh *c=b->buildUnstructured();
- CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
- c->changeSpaceDimension(2);
- //
- DataArrayDouble *d=DataArrayDouble::New();
- d->alloc(13,1);
- d->iota();
- MEDCouplingCMesh *e=MEDCouplingCMesh::New();
- e->setCoordsAt(0,d);
- MEDCouplingUMesh *f=e->buildUnstructured();
- DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
- DataArrayDouble *h=g->fromPolarToCart();
- f->setCoords(h);
- MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
- CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
- bool tmp2;
- int tmp3;
- DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
- CPPUNIT_ASSERT(tmp2);
- CPPUNIT_ASSERT_EQUAL(37,tmp3);
- tmp->decrRef();
- i->convertDegeneratedCells();
- const double vec1[3]={10.,0.,0.};
- i->translate(vec1);
- DataArrayDouble *g2=h->applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
- f->setCoords(g2);
- i->changeSpaceDimension(3);
- MEDCouplingUMesh *i3=i->buildExtrudedMesh(f,1);
- MEDCouplingFieldDouble *f2=i3->getMeasureField(true);
- tmp=i->mergeNodes(1e-9,tmp2,tmp3);
- CPPUNIT_ASSERT(tmp2);
- CPPUNIT_ASSERT_EQUAL(444,tmp3);
- tmp->decrRef();
- const double expected1[36]={1.327751058489274, 4.2942574094314701, 13.024068164857139, 1.3069177251569044, 4.1484240761012954, 12.297505664866796, 1.270833333332571, 3.8958333333309674, 11.039062499993179, 1.2291666666659207, 3.6041666666644425, 9.585937499993932, 1.1930822748415895, 3.3515759238941376, 8.3274943351204556, 1.1722489415082769, 3.2057425905609289, 7.6009318351210622, 1.1722489415082862, 3.2057425905609884, 7.6009318351213713, 1.1930822748416161, 3.3515759238943001, 8.3274943351212727, 1.2291666666659564, 3.6041666666646734, 9.5859374999950777, 1.2708333333326081, 3.8958333333311868, 11.039062499994293, 1.3069177251569224, 4.1484240761014384, 12.297505664867627, 1.3277510584902354, 4.2942574094346071, 13.024068164866796};
- int kk=0;
- for(int ii=0;ii<12;ii++)
- for(int jj=0;jj<36;jj++,kk++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[jj],f2->getIJ(0,kk),1e-9);
- //
- f2->decrRef();
- i3->decrRef();
- g2->decrRef();
- i->decrRef();
- h->decrRef();
- g->decrRef();
- f->decrRef();
- e->decrRef();
- d->decrRef();
- c->decrRef();
- b->decrRef();
- a->decrRef();
-}
-
-void MEDCouplingBasicsTest::testSimplexize1()
-{
- MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
- std::vector<int> v(1);
- v[0]=3;
- m->convertToPolyTypes(v);
- DataArrayInt *da=m->simplexize(0);
- CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
- const int expected2[7]={0,0,1,2,3,4,4};
- for(int i=0;i<7;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
- m->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
- const double expected1[7]={0.125,0.125,0.125,0.125,0.25,0.125,0.125};
- MEDCouplingFieldDouble *f=m->getMeasureField(false);
- for(int i=0;i<7;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
- std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllTypes();
- CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
- f->decrRef();
- da->decrRef();
- m->decrRef();
- //
- m=build3DSurfTargetMesh_1();
- v[0]=3;
- m->convertToPolyTypes(v);
- da=m->simplexize(1);
- CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
- for(int i=0;i<7;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
- m->checkCoherency();
- types=m->getAllTypes();
- CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
- CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
- f=m->getMeasureField(false);
- for(int i=0;i<7;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
- f->decrRef();
- da->decrRef();
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testSimplexize2()
-{
- MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
- std::vector<int> v(1);
- v[0]=3;
- m->convertToPolyTypes(v);
- MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
- f1->setMesh(m);
- DataArrayDouble *arr=DataArrayDouble::New();
- const double arr1[10]={10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
- arr->alloc(5,2);
- std::copy(arr1,arr1+10,arr->getPointer());
- f1->setArray(arr);
- arr->decrRef();
- //
- f1->checkCoherency();
- CPPUNIT_ASSERT(f1->simplexize(0));
- f1->checkCoherency();
- const double expected1[14]={10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.};
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
- CPPUNIT_ASSERT(!f1->simplexize(0));
- for(int i=0;i<14;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
- //
- f1->decrRef();
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAMeld1()
-{
- DataArrayDouble *da1=DataArrayDouble::New();
- da1->alloc(7,2);
- DataArrayDouble *da2=DataArrayDouble::New();
- da2->alloc(7,1);
- //
- da1->fillWithValue(7.);
- da2->iota(0.);
- DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
- //
- da1->setInfoOnComponent(0,"c0da1");
- da1->setInfoOnComponent(1,"c1da1");
- da3->setInfoOnComponent(0,"c0da3");
- da3->setInfoOnComponent(1,"c1da3");
- da3->setInfoOnComponent(2,"c2da3");
- //
- DataArrayDouble *da1C=da1->deepCpy();
- da1->meldWith(da3);
- CPPUNIT_ASSERT_EQUAL(5,da1->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(7,da1->getNumberOfTuples());
- CPPUNIT_ASSERT(da1->getInfoOnComponent(0)=="c0da1");
- CPPUNIT_ASSERT(da1->getInfoOnComponent(1)=="c1da1");
- CPPUNIT_ASSERT(da1->getInfoOnComponent(2)=="c0da3");
- CPPUNIT_ASSERT(da1->getInfoOnComponent(3)=="c1da3");
- CPPUNIT_ASSERT(da1->getInfoOnComponent(4)=="c2da3");
- //
- const double expected1[35]={7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.};
- for(int i=0;i<35;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
- //
- DataArrayInt *dai1=da1C->convertToIntArr();
- DataArrayInt *dai3=da3->convertToIntArr();
- dai1->meldWith(dai3);
- CPPUNIT_ASSERT_EQUAL(5,dai1->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(7,dai1->getNumberOfTuples());
- CPPUNIT_ASSERT(dai1->getInfoOnComponent(0)=="c0da1");
- CPPUNIT_ASSERT(dai1->getInfoOnComponent(1)=="c1da1");
- CPPUNIT_ASSERT(dai1->getInfoOnComponent(2)=="c0da3");
- CPPUNIT_ASSERT(dai1->getInfoOnComponent(3)=="c1da3");
- CPPUNIT_ASSERT(dai1->getInfoOnComponent(4)=="c2da3");
- for(int i=0;i<35;i++)
- CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai1->getIJ(0,i));
- // test of static method DataArrayDouble::meld
- DataArrayDouble *da4=DataArrayDouble::Meld(da1C,da3);
- CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(7,da4->getNumberOfTuples());
- CPPUNIT_ASSERT(da4->getInfoOnComponent(0)=="c0da1");
- CPPUNIT_ASSERT(da4->getInfoOnComponent(1)=="c1da1");
- CPPUNIT_ASSERT(da4->getInfoOnComponent(2)=="c0da3");
- CPPUNIT_ASSERT(da4->getInfoOnComponent(3)=="c1da3");
- CPPUNIT_ASSERT(da4->getInfoOnComponent(4)=="c2da3");
- for(int i=0;i<35;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
- // test of static method DataArrayInt::meld
- dai1->decrRef();
- dai1=da1C->convertToIntArr();
- DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
- CPPUNIT_ASSERT_EQUAL(5,dai4->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(7,dai4->getNumberOfTuples());
- CPPUNIT_ASSERT(dai4->getInfoOnComponent(0)=="c0da1");
- CPPUNIT_ASSERT(dai4->getInfoOnComponent(1)=="c1da1");
- CPPUNIT_ASSERT(dai4->getInfoOnComponent(2)=="c0da3");
- CPPUNIT_ASSERT(dai4->getInfoOnComponent(3)=="c1da3");
- CPPUNIT_ASSERT(dai4->getInfoOnComponent(4)=="c2da3");
- for(int i=0;i<35;i++)
- CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai4->getIJ(0,i));
- //
- dai4->decrRef();
- da4->decrRef();
- dai3->decrRef();
- dai1->decrRef();
- da1C->decrRef();
- da1->decrRef();
- da2->decrRef();
- da3->decrRef();
-}
-
-void MEDCouplingBasicsTest::testFieldMeld1()
-{
- MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
- MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
- f1->setMesh(m);
- DataArrayDouble *da1=DataArrayDouble::New();
- const double arr1[5]={12.,23.,34.,45.,56.};
- da1->alloc(5,1);
- std::copy(arr1,arr1+5,da1->getPointer());
- da1->setInfoOnComponent(0,"aaa");
- f1->setArray(da1);
- f1->setTime(3.4,2,1);
- f1->checkCoherency();
- //
- MEDCouplingFieldDouble *f2=f1->deepCpy();
- f2->setMesh(f1->getMesh());
- f2->checkCoherency();
- f2->changeNbOfComponents(2,5.);
- (*f2)=5.;
- f2->getArray()->setInfoOnComponent(0,"bbb");
- f2->getArray()->setInfoOnComponent(1,"ccc");
- f2->checkCoherency();
- //
- MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MeldFields(f2,f1);
- f3->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(5,f3->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,f3->getNumberOfComponents());
- CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(0)=="bbb");
- CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(1)=="ccc");
- CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(2)=="aaa");
- const double expected1[15]={5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.};
- for(int i=0;i<15;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-12);
- int dt,it;
- double time=f3->getTime(dt,it);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,time,1e-14);
- CPPUNIT_ASSERT_EQUAL(2,dt);
- CPPUNIT_ASSERT_EQUAL(1,it);
- //
- MEDCouplingFieldDouble *f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
- MEDCouplingFieldDouble *f5=f1->buildNewTimeReprFromThis(NO_TIME,false);
- MEDCouplingFieldDouble *f6=MEDCouplingFieldDouble::MeldFields(f4,f5);
- f6->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(5,f6->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,f6->getNumberOfComponents());
- CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(0)=="bbb");
- CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(1)=="ccc");
- CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(2)=="aaa");
- for(int i=0;i<15;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f6->getIJ(0,i),1e-12);
- //
- f6->decrRef();
- f4->decrRef();
- f5->decrRef();
- f3->decrRef();
- da1->decrRef();
- f2->decrRef();
- f1->decrRef();
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testMergeNodes2()
-{
- MEDCouplingUMesh *m1=build2DTargetMesh_1();
- MEDCouplingUMesh *m2=build2DTargetMesh_1();
- const double vec[2]={0.002,0.};
- m2->translate(vec);
- //
- std::vector<const MEDCouplingUMesh *> tmp(2);
- tmp[0]=m1;
- tmp[1]=m2;
- MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(tmp);
- bool b;
- int newNbOfNodes;
- DataArrayInt *da=m3->mergeNodes2(0.01,b,newNbOfNodes);
- CPPUNIT_ASSERT_EQUAL(9,m3->getNumberOfNodes());
- const double expected1[18]={-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7};
- for(int i=0;i<18;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],m3->getCoords()->getIJ(0,i),1e-13);
- //
- da->decrRef();
- m3->decrRef();
- m1->decrRef();
- m2->decrRef();
-}
-
-void MEDCouplingBasicsTest::testMergeField2()
-{
- MEDCouplingUMesh *m=build2DTargetMesh_1();
- MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
- f1->setMesh(m);
- DataArrayDouble *arr=DataArrayDouble::New();
- arr->alloc(5,2);
- arr->fillWithValue(2.);
- f1->setArray(arr);
- arr->decrRef();
- MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
- f2->setMesh(m);
- arr=DataArrayDouble::New();
- arr->alloc(5,2);
- arr->fillWithValue(5.);
- f2->setArray(arr);
- arr->decrRef();
- MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
- f3->setMesh(m);
- arr=DataArrayDouble::New();
- arr->alloc(5,2);
- arr->fillWithValue(7.);
- f3->setArray(arr);
- arr->decrRef();
- //
- std::vector<const MEDCouplingFieldDouble *> tmp(3);
- tmp[0]=f1; tmp[1]=f2; tmp[2]=f3;
- MEDCouplingFieldDouble *f4=MEDCouplingFieldDouble::MergeFields(tmp);
- CPPUNIT_ASSERT_EQUAL(15,f4->getMesh()->getNumberOfCells());
- const double expected1[30]={2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.};
- for(int i=0;i<30;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f4->getIJ(0,i),1.e-13);
- //
- f4->decrRef();
- f1->decrRef();
- f2->decrRef();
- f3->decrRef();
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIBuildComplement1()
-{
- DataArrayInt *a=DataArrayInt::New();
- const int tab[4]={3,1,7,8};
- a->alloc(4,1);
- std::copy(tab,tab+4,a->getPointer());
- DataArrayInt *b=a->buildComplement(12);
- CPPUNIT_ASSERT_EQUAL(8,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
- const int expected1[8]={0,2,4,5,6,9,10,11};
- for(int i=0;i<8;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
- b->decrRef();
- a->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIBuildUnion1()
-{
- DataArrayInt *a=DataArrayInt::New();
- const int tab1[4]={3,1,7,8};
- a->alloc(4,1);
- std::copy(tab1,tab1+4,a->getPointer());
- DataArrayInt *c=DataArrayInt::New();
- const int tab2[5]={5,3,0,18,8};
- c->alloc(5,1);
- std::copy(tab2,tab2+5,c->getPointer());
- DataArrayInt *b=a->buildUnion(c);
- CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
- const int expected1[7]={0,1,3,5,7,8,18};
- for(int i=0;i<7;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
- c->decrRef();
- b->decrRef();
- a->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIBuildIntersection1()
-{
- DataArrayInt *a=DataArrayInt::New();
- const int tab1[4]={3,1,7,8};
- a->alloc(4,1);
- std::copy(tab1,tab1+4,a->getPointer());
- DataArrayInt *c=DataArrayInt::New();
- const int tab2[5]={5,3,0,18,8};
- c->alloc(5,1);
- std::copy(tab2,tab2+5,c->getPointer());
- DataArrayInt *b=a->buildIntersection(c);
- CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
- const int expected1[2]={3,8};
- for(int i=0;i<2;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
- c->decrRef();
- b->decrRef();
- a->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIDeltaShiftIndex1()
-{
- DataArrayInt *a=DataArrayInt::New();
- const int tab[7]={1,3,6,7,7,9,15};
- a->alloc(7,1);
- std::copy(tab,tab+7,a->getPointer());
- DataArrayInt *b=a->deltaShiftIndex();
- CPPUNIT_ASSERT_EQUAL(6,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
- const int expected1[6]={2,3,1,0,2,6};
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
- b->decrRef();
- a->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDaDoubleSelectByTupleIdSafe1()
-{
- DataArrayDouble *a=DataArrayDouble::New();
- a->alloc(7,2);
- a->setInfoOnComponent(0,"toto");
- a->setInfoOnComponent(1,"tata");
- const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
- std::copy(arr1,arr1+14,a->getPointer());
- //
- const int arr2[7]={4,2,0,6,5};
- DataArrayDouble *b=a->selectByTupleIdSafe(arr2,arr2+5);
- CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
- const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
- for(int i=0;i<10;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
- const int arr4[5]={4,-1,0,6,5};
- CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
- const int arr5[5]={4,2,0,6,7};
- CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
- b->decrRef();
- a->decrRef();
- //
- DataArrayInt *c=DataArrayInt::New();
- c->alloc(7,2);
- c->setInfoOnComponent(0,"toto");
- c->setInfoOnComponent(1,"tata");
- const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
- std::copy(arr3,arr3+14,c->getPointer());
- DataArrayInt *d=c->selectByTupleIdSafe(arr2,arr2+5);
- CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
- CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
- const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
- for(int i=0;i<10;i++)
- CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
- CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
- CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
- c->decrRef();
- d->decrRef();
-}
-
-void MEDCouplingBasicsTest::testAreCellsIncludedIn1()
-{
- MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
- const int pt[2]={1,3};
- MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(pt,pt+2,true);
- DataArrayInt *tmp;
- CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
- CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(pt[0],tmp->getIJ(0,0));
- CPPUNIT_ASSERT_EQUAL(pt[1],tmp->getIJ(0,1));
- tmp->decrRef();
- CPPUNIT_ASSERT(!m2->areCellsIncludedIn(m,0,tmp));
- tmp->decrRef();
- m2->decrRef();
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIBuildSubstraction1()
-{
- DataArrayInt *a=DataArrayInt::New();
- const int aa[]={2,3,6,8,9};
- a->alloc(5,1);
- std::copy(aa,aa+5,a->getPointer());
- DataArrayInt *b=DataArrayInt::New();
- const int bb[]={1,3,5,9,11};
- b->alloc(5,1);
- std::copy(bb,bb+5,b->getPointer());
- //
- DataArrayInt *c=a->buildSubstraction(b);
- CPPUNIT_ASSERT_EQUAL(3,c->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
- const int expected1[3]={2,6,8};
- CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
- //
- c->decrRef();
- b->decrRef();
- a->decrRef();
-}
-
-void MEDCouplingBasicsTest::testBuildOrthogonalField2()
-{
- MEDCouplingUMesh *m=build2DTargetMesh_1();
- DataArrayInt *d1=DataArrayInt::New();
- DataArrayInt *d2=DataArrayInt::New();
- DataArrayInt *d3=DataArrayInt::New();
- DataArrayInt *d4=DataArrayInt::New();
- MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
- //
- MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
- DataArrayDouble *da1=f1->getArray();
- CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(13,da1->getNumberOfTuples());
- //
- const double expected1[26]={-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.};
- for(int i=0;i<26;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-14);
- //
- f1->decrRef();
- m1->decrRef();
- d1->decrRef();
- d2->decrRef();
- d3->decrRef();
- d4->decrRef();
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testUMInsertNextCell1()
-{
- double targetCoords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
- int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
- MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
- targetMesh->allocateCells(5);
- CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn),INTERP_KERNEL::Exception);
- targetMesh->setMeshDimension(2);
- targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
- CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,targetConn),INTERP_KERNEL::Exception);
- CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn),INTERP_KERNEL::Exception);
- CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn),INTERP_KERNEL::Exception);
- targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
- targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
- targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
- targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
- targetMesh->finishInsertingCells();
- DataArrayDouble *myCoords=DataArrayDouble::New();
- myCoords->alloc(9,2);
- std::copy(targetCoords,targetCoords+18,myCoords->getPointer());
- targetMesh->setCoords(myCoords);
- myCoords->decrRef();
- targetMesh->checkCoherency();
- targetMesh->decrRef();
-}
-
-void MEDCouplingBasicsTest::testFieldOperatorDivDiffComp1()
-{
- MEDCouplingUMesh *m=build2DTargetMesh_1();
- DataArrayInt *d1=DataArrayInt::New();
- DataArrayInt *d2=DataArrayInt::New();
- DataArrayInt *d3=DataArrayInt::New();
- DataArrayInt *d4=DataArrayInt::New();
- MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
- //
- MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
- const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.};
- DataArrayDouble *arr=DataArrayDouble::New();
- arr->alloc(13,1);
- std::copy(arr1,arr1+13,arr->getPointer());
- MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS);
- f2->setArray(arr);
- f2->setMesh(m1);
- f2->checkCoherency();
- //
- MEDCouplingFieldDouble *f3=(*f1)/(*f2);
- CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception);
- f3->checkCoherency();
- (*f1)/=(*f2);
- CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10));
- CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception);
- const double expected1[26]={-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0};
- for(int i=0;i<26;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10);
- //
- f3->decrRef();
- f2->decrRef();
- arr->decrRef();
- f1->decrRef();
- m1->decrRef();
- d1->decrRef();
- d2->decrRef();
- d3->decrRef();
- d4->decrRef();
- m->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDARearrange1()
-{
- DataArrayInt *da1=DataArrayInt::New();
- da1->alloc(12,1);
- da1->iota(0);
- const int *ptr=da1->getConstPointer();
- //
- CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfTuples());
- da1->rearrange(4);
- CPPUNIT_ASSERT(ptr==da1->getConstPointer());
- CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfTuples());
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
- //
- da1->rearrange(6);
- CPPUNIT_ASSERT(ptr==da1->getConstPointer());
- CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(6,da1->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfTuples());
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
- //
- CPPUNIT_ASSERT_THROW(da1->rearrange(7),INTERP_KERNEL::Exception);
- //
- da1->rearrange(12);
- CPPUNIT_ASSERT(ptr==da1->getConstPointer());
- CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfTuples());
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
- //
- da1->rearrange(3);
- CPPUNIT_ASSERT(ptr==da1->getConstPointer());
- CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples());
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
- //double
- DataArrayDouble *da2=da1->convertToDblArr();
- da1->decrRef();
- const double *ptr2=da2->getConstPointer();
- //
- CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
- da2->rearrange(4);
- CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
- CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
- //
- da2->rearrange(6);
- CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
- CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(2,da2->getNumberOfTuples());
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
- //
- CPPUNIT_ASSERT_THROW(da2->rearrange(7),INTERP_KERNEL::Exception);
- //
- da2->rearrange(1);
- CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
- CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(12,da2->getNumberOfTuples());
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
- //
- da2->rearrange(3);
- CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
- CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
- CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
- for(int i=0;i<12;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
- da2->decrRef();
-}
-
-void MEDCouplingBasicsTest::testGetDifferentValues1()
-{
- DataArrayInt *da1=DataArrayInt::New();
- const int arr[12]={1,2,3,2,2,3,5,1,5,5,2,2};
- da1->alloc(4,3);
- std::copy(arr,arr+12,da1->getPointer());
- std::set<int> s=da1->getDifferentValues();
- const int expected1[4]={1,2,3,5};
- CPPUNIT_ASSERT_EQUAL(4,(int)s.size());
- CPPUNIT_ASSERT(std::equal(expected1,expected1+4,s.begin()));
- da1->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIBuildPermutationArr1()
-{
- DataArrayInt *a=DataArrayInt::New();
- const int vala[5]={4,5,6,7,8};
- a->alloc(5,1);
- std::copy(vala,vala+5,a->getPointer());
- DataArrayInt *b=DataArrayInt::New();
- const int valb[5]={5,4,8,6,7};
- b->alloc(5,1);
- std::copy(valb,valb+5,b->getPointer());
- DataArrayInt *c=a->buildPermutationArr(*b);
- const int expect1[5]={1,0,4,2,3};
- CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
- CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
- CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
- b->setIJ(0,0,9);
- CPPUNIT_ASSERT(!a->isEqualWithoutConsideringStrAndOrder(*b));
- CPPUNIT_ASSERT_THROW(a->buildPermutationArr(*b),INTERP_KERNEL::Exception);
- a->setIJ(3,0,4);
- b->setIJ(0,0,5);
- b->setIJ(4,0,4);//;a==[4,5,6,4,8] and b==[5,4,8,6,4]
- CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
- c->decrRef();
- c=a->buildPermutationArr(*b);
- const int expect2[5]={1,3,4,2,3};
- CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
- DataArrayDouble *d=b->convertToDblArr();
- b->sort();
- const int expect3[5]={4,4,5,6,8};
- CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
- d->sort();
- CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
- for(int i=0;i<5;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
- //
- d->decrRef();
- c->decrRef();
- a->decrRef();
- b->decrRef();
-}
-
-void MEDCouplingBasicsTest::testAreCellsIncludedIn2()
-{
- const char myName[]="Vitoo";
- MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
- MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(0,0,true);
- CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
- CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
- m2->setName(myName);
- DataArrayInt *tmp;
- CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
- CPPUNIT_ASSERT(std::string(myName)==tmp->getName());
- CPPUNIT_ASSERT_EQUAL(0,tmp->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
- m->decrRef();
- m2->decrRef();
- tmp->decrRef();
-}
-
-void MEDCouplingBasicsTest::testUMeshGetPartBarycenterAndOwner1()
-{
- MEDCouplingUMesh *m1=build2DTargetMesh_1();
- const int part[3]={1,0,4};
- DataArrayDouble *b=m1->getPartBarycenterAndOwner(part,part+3);
- CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
- const double expected1[6]={0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45};
- for(int i=0;i<6;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
- b->decrRef();
- m1->decrRef();
-}
-
-void MEDCouplingBasicsTest::testUMeshGetPartMeasureField1()
-{
- MEDCouplingUMesh *m1=build2DTargetMesh_1();
- const int part[3]={1,0,4};
- DataArrayDouble *b=m1->getPartMeasureField(true,part,part+3);
- CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
- const double expected1[3]={0.125,0.25,0.25};
- for(int i=0;i<3;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
- b->decrRef();
- m1->decrRef();
-}
-
-void MEDCouplingBasicsTest::testUMeshBuildPartOrthogonalField1()
-{
- MEDCouplingUMesh *m1=build2DTargetMesh_1();
- m1->changeSpaceDimension(3);
- const int part[3]={1,0,4};
- MEDCouplingFieldDouble *b=m1->buildPartOrthogonalField(part,part+3);
- CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfTuples());
- const double expected1[9]={0.,0.,-1.,0.,0.,-1.,0.,0.,-1.};
- for(int i=0;i<9;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getArray()->getIJ(0,i),1e-14);
- b->decrRef();
- m1->decrRef();
-}
-
-void MEDCouplingBasicsTest::testUMeshGetTypesOfPart1()
-{
- MEDCouplingUMesh *m1=build2DTargetMesh_1();
- const int part1[]={0,3,4};
- std::set<INTERP_KERNEL::NormalizedCellType> s;
- s=m1->getTypesOfPart(part1,part1+3);
- CPPUNIT_ASSERT(s.size()==1);
- CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_QUAD4);
- const int part2[]={2,2,2,1};
- s=m1->getTypesOfPart(part2,part2+4);
- CPPUNIT_ASSERT(s.size()==1);
- CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
- const int part3[]={3,2,1};
- s=m1->getTypesOfPart(part3,part3+3);
- CPPUNIT_ASSERT(s.size()==2);
- CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
- CPPUNIT_ASSERT(*(++s.begin())==INTERP_KERNEL::NORM_QUAD4);
- m1->decrRef();
-}
-
-void MEDCouplingBasicsTest::testUMeshKeepCellIdsByType1()
-{
- MEDCouplingUMesh *m1=build2DTargetMesh_1();
- const int part1[3]={0,3,4};
- DataArrayInt *a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part1,part1+3);
- CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(0,a->getNumberOfTuples());
- a->decrRef();
- //
- const int part2[5]={3,2,0,2,4};
- a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part2,part2+5);
- CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,a->getIJ(0,0));
- CPPUNIT_ASSERT_EQUAL(2,a->getIJ(1,0));
- a->decrRef();
- //
- a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_QUAD4,part2,part2+5);
- CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
- CPPUNIT_ASSERT_EQUAL(3,a->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(3,a->getIJ(0,0));
- CPPUNIT_ASSERT_EQUAL(0,a->getIJ(1,0));
- CPPUNIT_ASSERT_EQUAL(4,a->getIJ(2,0));
- //
- a->decrRef();
- m1->decrRef();
-}
-
-void MEDCouplingBasicsTest::testDAIAggregateMulti1()
-{
- DataArrayInt *a=DataArrayInt::New();
- a->setName("aa");
- a->alloc(4,1);
- a->iota(0);
- a->rearrange(2);
- DataArrayInt *b=DataArrayInt::New();
- b->setName("bb");
- b->alloc(6,1);
- b->iota(0);
- b->rearrange(2);
- //
- std::vector<const DataArrayInt *> v(2);
- v[0]=a; v[1]=b;
- DataArrayInt *c=DataArrayInt::Aggregate(v);
- CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
- CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
- CPPUNIT_ASSERT(c->getName()=="aa");
- const int expect1[10]={0,1,2,3,0,1,2,3,4,5};
- for(int i=0;i<10;i++)
- CPPUNIT_ASSERT_EQUAL(expect1[i],c->getIJ(0,i));
- //
- c->decrRef();
- a->decrRef();
- b->decrRef();
-}
-
-void MEDCouplingBasicsTest::testMergeUMeshes2()
-{
- MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
- MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
- MEDCouplingUMesh *m3=build3DSurfTargetMesh_1();
- //
- const int vec1[3]={0,2,3};
- MEDCouplingUMesh *m2_2=(MEDCouplingUMesh *)m2->buildPartOfMySelf(vec1,vec1+3,false);
- const int vec2[2]={1,1};
- MEDCouplingUMesh *m3_2=(MEDCouplingUMesh *)m3->buildPartOfMySelf(vec2,vec2+2,false);
- //
- std::vector<const MEDCouplingUMesh *> ms(3);
- ms[0]=m1; ms[1]=m2_2; ms[2]=m3_2;
- //
- MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshes(ms);
- m4->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(10,m4->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(20,m4->getNumberOfNodes());
- CPPUNIT_ASSERT_EQUAL(45,m4->getMeshLength());
- //
- const int vec3[5]={0,1,2,3,4};
- MEDCouplingUMesh *m4_1=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec3,vec3+5,false);
- m4_1->setName(m1->getName());
- CPPUNIT_ASSERT(m4_1->isEqual(m1,1e-12));
- m4_1->decrRef();
- //
- const int vec4[3]={5,6,7};
- MEDCouplingUMesh *m4_2=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec4,vec4+3,false);
- DataArrayInt *cellCor=0;
- DataArrayInt *nodeCor=0;
- m4_2->checkGeoEquivalWith(m2_2,10,1e-12,cellCor,nodeCor);
- CPPUNIT_ASSERT(cellCor==0);
- CPPUNIT_ASSERT(nodeCor==0);
- m4_2->decrRef();
- //
- const int vec5[2]={8,9};
- MEDCouplingUMesh *m4_3=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec5,vec5+2,false);
- CPPUNIT_ASSERT_EQUAL(2,m4_3->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(3,m4_3->getNumberOfNodes());
- m3_2->zipCoords();
- m4_3->setName(m3_2->getName());
- CPPUNIT_ASSERT(m4_3->isEqual(m3_2,1e-12));
- m4_3->decrRef();
- //
- m4->decrRef();
- m1->decrRef();
- m2->decrRef();
- m2_2->decrRef();
- m3->decrRef();
- m3_2->decrRef();
-}
-
-void MEDCouplingBasicsTest::testBuild0DMeshFromCoords1()
-{
- const double sourceCoords[12]={-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.};
- DataArrayDouble *coo=DataArrayDouble::New();
- coo->alloc(4,3);
- coo->setName("My0D");
- std::copy(sourceCoords,sourceCoords+12,coo->getPointer());
- MEDCouplingUMesh *m=MEDCouplingUMesh::Build0DMeshFromCoords(coo);
- m->checkCoherency();
- CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
- CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfCells());
- CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
- CPPUNIT_ASSERT_EQUAL(0,m->getMeshDimension());
- const std::set<INTERP_KERNEL::NormalizedCellType>& types=m->getAllTypes();
- CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
- CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POINT1,*types.begin());
- for(int i=0;i<4;i++)
- {
- std::vector<int> conn;
- m->getNodeIdsOfCell(i,conn);
- CPPUNIT_ASSERT_EQUAL(1,(int)conn.size());
- CPPUNIT_ASSERT_EQUAL(i,conn[0]);
- CPPUNIT_ASSERT(INTERP_KERNEL::NORM_POINT1==m->getTypeOfCell(i));
- }
- CPPUNIT_ASSERT(std::string(m->getName())=="My0D");
- m->decrRef();
- coo->decrRef();
-}
-
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "MEDCouplingBasicsTest.hxx"
+#include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingCMesh.hxx"
+#include "MEDCouplingExtrudedMesh.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingMemArray.hxx"
+#include "MEDCouplingGaussLocalization.hxx"
+
+#include <cmath>
+#include <functional>
+#include <iterator>
+
+using namespace ParaMEDMEM;
+
+void MEDCouplingBasicsTest::testGetMeasureFieldCMesh1()
+{
+ MEDCouplingCMesh *m=MEDCouplingCMesh::New();
+ DataArrayDouble *da=DataArrayDouble::New();
+ const double discX[4]={2.3,3.4,5.8,10.2};
+ const double discY[3]={12.3,23.4,45.8};
+ const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
+ da->alloc(4,1);
+ std::copy(discX,discX+4,da->getPointer());
+ m->setCoordsAt(0,da);
+ da->decrRef();
+ m->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(3,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(1,m->getSpaceDimension());
+ MEDCouplingFieldDouble *f=m->getMeasureField(true);
+ CPPUNIT_ASSERT_EQUAL(3,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
+ const double expected1[3]={1.1,2.4,4.4};
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(i,0),1e-12);
+ f->decrRef();
+ DataArrayDouble *coords=m->getCoordinatesAndOwner();
+ CPPUNIT_ASSERT_EQUAL(4,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
+ for(int i=0;i<4;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(discX[i],coords->getIJ(i,0),1e-12);
+ coords->decrRef();
+ coords=m->getBarycenterAndOwner();
+ CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
+ const double expected1_3[3]={2.85,4.6,8.};
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1_3[i],coords->getIJ(i,0),1e-12);
+ coords->decrRef();
+ //
+ da=DataArrayDouble::New();
+ da->alloc(3,1);
+ std::copy(discY,discY+3,da->getPointer());
+ m->setCoordsAt(1,da);
+ da->decrRef();
+ m->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(12,m->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(6,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(2,m->getSpaceDimension());
+ f=m->getMeasureField(true);
+ CPPUNIT_ASSERT_EQUAL(6,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
+ const double expected2[6]={12.21,26.64,48.84,24.64,53.76,98.56};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(i,0),1e-12);
+ f->decrRef();
+ coords=m->getCoordinatesAndOwner();
+ CPPUNIT_ASSERT_EQUAL(12,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
+ const double expected2_2[24]={2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8};
+ for(int i=0;i<24;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_2[i],coords->getIJ(0,i),1e-12);
+ coords->decrRef();
+ coords=m->getBarycenterAndOwner();
+ CPPUNIT_ASSERT_EQUAL(6,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
+ const double expected2_3[12]={2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6};
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_3[i],coords->getIJ(0,i),1e-12);
+ coords->decrRef();
+ //
+ da=DataArrayDouble::New();
+ da->alloc(5,1);
+ std::copy(discZ,discZ+5,da->getPointer());
+ m->setCoordsAt(2,da);
+ da->decrRef();
+ m->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(60,m->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(24,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
+ f=m->getMeasureField(true);
+ CPPUNIT_ASSERT_EQUAL(24,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
+ const double expected3[24]={23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224};
+ for(int i=0;i<24;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f->getIJ(i,0),1e-12);
+ f->decrRef();
+ coords=m->getCoordinatesAndOwner();
+ CPPUNIT_ASSERT_EQUAL(60,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
+ const double expected3_2[180]={
+ 2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
+ 2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
+ 2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
+ 2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
+ 2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67
+ };
+ for(int i=0;i<180;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_2[i],coords->getIJ(0,i),1e-12);
+ coords->decrRef();
+ coords=m->getBarycenterAndOwner();
+ CPPUNIT_ASSERT_EQUAL(24,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
+ const double expected3_3[72]={
+ 2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
+ 2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
+ 2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
+ 2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4
+ };
+ for(int i=0;i<72;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_3[i],coords->getIJ(0,i),1e-12);
+ coords->decrRef();
+ //
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldDoubleZipCoords1()
+{
+ MEDCouplingUMesh *m=build2DTargetMeshMergeNode_1();
+ MEDCouplingFieldDouble *f=m->fillFromAnalytic(ON_NODES,2,"x*2.");
+ f->getArray()->setInfoOnComponent(0,"titi");
+ f->getArray()->setInfoOnComponent(1,"tutu");
+ f->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(18,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
+ const double expected1[36]={-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
+ for(int i=0;i<36;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(f->zipCoords());
+ f->checkCoherency();
+ const double expected2[30]={-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(!f->zipCoords());
+ f->checkCoherency();
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
+ CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
+ f->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldDoubleZipConnectivity1()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ MEDCouplingUMesh *m2=build2DTargetMesh_1();
+ const int cells1[3]={2,3,4};
+ MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
+ MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
+ CPPUNIT_ASSERT(m3);
+ m2->decrRef();
+ MEDCouplingUMesh *m4=build2DSourceMesh_1();
+ MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
+ m1->decrRef();
+ m3->decrRef();
+ MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
+ m4->decrRef();
+ m5->decrRef();
+ //
+ CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
+ bool areNodesMerged;
+ int newNbOfNodes;
+ DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
+ CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
+ arr->decrRef();
+ MEDCouplingFieldDouble *f=m6->fillFromAnalytic(ON_CELLS,2,"x");
+ MEDCouplingFieldDouble *f2=m6->fillFromAnalytic(ON_NODES,2,"x");
+ CPPUNIT_ASSERT_EQUAL(10,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
+ const double expected1[20]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
+ -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
+ 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
+ for(int i=0;i<20;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
+ f->getArray()->setInfoOnComponent(0,"titi");
+ f->getArray()->setInfoOnComponent(1,"tutu");
+ f->checkCoherency();
+ CPPUNIT_ASSERT(f->zipConnectivity(0));
+ const double expected2[14]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
+ -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
+ CPPUNIT_ASSERT_EQUAL(7,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
+ CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
+ CPPUNIT_ASSERT(!f->zipConnectivity(0));
+ f->decrRef();
+ //
+ const double expected3[18]={-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7,
+ -0.3, -0.3, 0.2, 0.2, 0.7, 0.7};
+ CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
+ for(int i=0;i<18;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(f2->zipConnectivity(0));
+ CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
+ for(int i=0;i<18;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
+ f2->decrRef();
+ //
+ m6->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumber1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={3,1,0,6,5,4,2};
+ DataArrayDouble *b=a->renumber(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->renumber(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumberAndReduce1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={2,-1,1,-1,0,4,3};
+ DataArrayDouble *b=a->renumberAndReduce(arr2,5);
+ CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->renumberAndReduce(arr2,5);
+ CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumberInPlace1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={3,1,0,6,5,4,2};
+ a->renumberInPlace(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
+ const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ c->renumberInPlace(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
+ const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
+ c->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumberR1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={3,1,0,6,5,4,2};
+ DataArrayDouble *b=a->renumberR(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->renumberR(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumberInPlaceR1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={3,1,0,6,5,4,2};
+ a->renumberInPlaceR(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
+ const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ c->renumberInPlaceR(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
+ const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
+ c->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleSelectByTupleId1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={4,2,0,6,5};
+ DataArrayDouble *b=a->selectByTupleId(arr2,arr2+5);
+ CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->selectByTupleId(arr2,arr2+5);
+ CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleGetMinMaxValues1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(9,1);
+ const double arr1[9]={2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56};
+ std::copy(arr1,arr1+9,a->getPointer());
+ int where;
+ double m=a->getMaxValue(where);
+ CPPUNIT_ASSERT_EQUAL(1,where);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
+ DataArrayInt *ws;
+ m=a->getMaxValue2(ws);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
+ CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
+ const int expected1[3]={1,4,8};
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
+ ws->decrRef();
+ a->decrRef();
+ a=DataArrayDouble::New();
+ const double arr2[9]={-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56};
+ a->alloc(9,1);
+ std::copy(arr2,arr2+9,a->getPointer());
+ where=-2;
+ m=a->getMinValue(where);
+ CPPUNIT_ASSERT_EQUAL(1,where);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
+ m=a->getMinValue2(ws);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
+ CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
+ ws->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldDoubleGetMinMaxValues2()
+{
+ MEDCouplingUMesh *m1=0;
+ MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
+ m1->decrRef();
+ CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
+ const double arr1[18]={8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71};
+ MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(18,1);
+ std::copy(arr1,arr1+18,a->getPointer());
+ f->setArray(a);
+ a->decrRef();
+ f->setMesh(m2);
+ //
+ f->checkCoherency();
+ double m=f->getMaxValue();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
+ DataArrayInt *ws;
+ m=f->getMaxValue2(ws);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
+ CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
+ const int expected1[4]={0,3,7,17};
+ for(int i=0;i<4;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
+ ws->decrRef();
+ //
+ const double arr2[18]={-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71};
+ std::copy(arr2,arr2+18,a->getPointer());
+ f->checkCoherency();
+ m=f->getMinValue();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
+ m=f->getMinValue2(ws);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
+ CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
+ for(int i=0;i<4;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
+ ws->decrRef();
+ //
+ f->decrRef();
+ m2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testBuildUnstructuredCMesh1()
+{
+ MEDCouplingCMesh *m=MEDCouplingCMesh::New();
+ DataArrayDouble *da=DataArrayDouble::New();
+ const double discX[4]={2.3,3.4,5.8,10.2};
+ const double discY[3]={12.3,23.4,45.8};
+ const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
+ da->alloc(4,1);
+ std::copy(discX,discX+4,da->getPointer());
+ m->setCoordsAt(0,da);
+ da->decrRef();
+ m->checkCoherency();
+ double pos=2.4;
+ CPPUNIT_ASSERT_EQUAL(0,m->getCellContainingPoint(&pos,1e-12));
+ pos=3.7;
+ CPPUNIT_ASSERT_EQUAL(1,m->getCellContainingPoint(&pos,1e-12));
+ pos=5.9;
+ CPPUNIT_ASSERT_EQUAL(2,m->getCellContainingPoint(&pos,1e-12));
+ pos=10.3;
+ CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
+ pos=1.3;
+ CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
+ //
+ MEDCouplingUMesh *m2=m->buildUnstructured();
+ m2->checkCoherency();
+ MEDCouplingFieldDouble *f1=m->getMeasureField(false);
+ MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
+ CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),3);
+ CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),3);
+ CPPUNIT_ASSERT_EQUAL(1,m2->getMeshDimension());
+ CPPUNIT_ASSERT_EQUAL(1,m2->getSpaceDimension());
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
+ da=DataArrayDouble::New();
+ da->alloc(3,1);
+ std::copy(discY,discY+3,da->getPointer());
+ m->setCoordsAt(1,da);
+ da->decrRef();
+ m2->decrRef();
+ f1->decrRef();
+ f2->decrRef();
+ //
+ m2=m->buildUnstructured();
+ m2->checkCoherency();
+ f1=m->getMeasureField(false);
+ f2=m2->getMeasureField(false);
+ CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),6);
+ CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),6);
+ CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
+ CPPUNIT_ASSERT_EQUAL(2,m2->getSpaceDimension());
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
+ f1->decrRef();
+ f2->decrRef();
+ m2->decrRef();
+ //
+ da=DataArrayDouble::New();
+ da->alloc(5,1);
+ std::copy(discZ,discZ+5,da->getPointer());
+ m->setCoordsAt(2,da);
+ da->decrRef();
+ m2=m->buildUnstructured();
+ m2->checkCoherency();
+ f1=m->getMeasureField(false);
+ f2=m2->getMeasureField(false);
+ CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),24);
+ CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),24);
+ CPPUNIT_ASSERT_EQUAL(3,m2->getMeshDimension());
+ CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
+ for(int i=0;i<24;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
+ f1->decrRef();
+ f2->decrRef();
+ //
+ double pos1[3]={5.,30.,2.};
+ CPPUNIT_ASSERT_EQUAL(16,m->getCellContainingPoint(pos1,1e-12));
+ //
+ const double pt[3]={2.4,12.7,-3.4};
+ m->scale(pt,3.7);
+ MEDCouplingUMesh *m3=m->buildUnstructured();
+ m2->scale(pt,3.7);
+ CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
+ m2->decrRef();
+ m3->decrRef();
+ //
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDataArrayIntInvertO2NNO21()
+{
+ const int arr1[6]={2,0,4,1,5,3};
+ DataArrayInt *da=DataArrayInt::New();
+ da->alloc(6,1);
+ std::copy(arr1,arr1+6,da->getPointer());
+ DataArrayInt *da2=da->invertArrayO2N2N2O(6);
+ CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+ const int expected1[6]={1,3,0,5,2,4};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
+ DataArrayInt *da3=da2->invertArrayN2O2O2N(6);
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_EQUAL(arr1[i],da3->getIJ(i,0));
+ da3->decrRef();
+ da2->decrRef();
+ da->decrRef();
+ //
+ const int arr2[10]={3,-1,5,4,-1,0,-1,1,2,-1};
+ da=DataArrayInt::New();
+ da->alloc(10,1);
+ std::copy(arr2,arr2+10,da->getPointer());
+ da2=da->invertArrayO2N2N2O(6);
+ CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+ const int expected2[10]={5,7,8,0,3,2};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],da2->getIJ(i,0));
+ da3=da2->invertArrayN2O2O2N(10);
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_EQUAL(arr2[i],da3->getIJ(i,0));
+ da3->decrRef();
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testKeepSetSelectedComponent1()
+{
+ const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
+ DataArrayDouble *a1=DataArrayDouble::New();
+ a1->alloc(5,4);
+ std::copy(arr1,arr1+20,a1->getPointer());
+ a1->setInfoOnComponent(0,"aaaa");
+ a1->setInfoOnComponent(1,"bbbb");
+ a1->setInfoOnComponent(2,"cccc");
+ a1->setInfoOnComponent(3,"dddd");
+ const int arr2[6]={1,2,1,2,0,0};
+ std::vector<int> arr2V(arr2,arr2+6);
+ DataArrayDouble *a2=a1->keepSelectedComponents(arr2V);
+ CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="cccc");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="bbbb");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
+ const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
+ DataArrayInt *a3=a1->convertToIntArr();
+ DataArrayInt *a4=a3->keepSelectedComponents(arr2V);
+ CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="cccc");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="bbbb");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_EQUAL(int(expected1[i]),a4->getIJ(0,i));
+ // setSelectedComponents
+ const int arr3[2]={3,2};
+ std::vector<int> arr3V(arr3,arr3+2);
+ DataArrayDouble *a5=a1->keepSelectedComponents(arr3V);
+ a5->setInfoOnComponent(0,"eeee");
+ a5->setInfoOnComponent(1,"ffff");
+ const int arr4[2]={1,2};
+ std::vector<int> arr4V(arr4,arr4+2);
+ a2->setSelectedComponents(a5,arr4V);
+ CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="eeee");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="ffff");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
+ CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
+ const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
+ DataArrayInt *a6=a5->convertToIntArr();
+ a6->setInfoOnComponent(0,"eeee");
+ a6->setInfoOnComponent(1,"ffff");
+ a4->setSelectedComponents(a6,arr4V);
+ CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="eeee");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="ffff");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
+ CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_EQUAL(int(expected2[i]),a4->getIJ(0,i));
+ // test of throw
+ const int arr5[3]={2,3,6};
+ const int arr6[3]={2,7,5};
+ const int arr7[4]={2,1,4,6};
+ std::vector<int> arr5V(arr5,arr5+3);
+ std::vector<int> arr6V(arr6,arr6+3);
+ std::vector<int> arr7V(arr7,arr7+4);
+ CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr5V),INTERP_KERNEL::Exception);
+ CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr6V),INTERP_KERNEL::Exception);
+ CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
+ arr7V.resize(3);
+ CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
+ //
+ a6->decrRef();
+ a5->decrRef();
+ a4->decrRef();
+ a3->decrRef();
+ a2->decrRef();
+ a1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testKeepSetSelectedComponent2()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
+ DataArrayDouble *a1=DataArrayDouble::New();
+ a1->alloc(5,4);
+ std::copy(arr1,arr1+20,a1->getPointer());
+ a1->setInfoOnComponent(0,"aaaa");
+ a1->setInfoOnComponent(1,"bbbb");
+ a1->setInfoOnComponent(2,"cccc");
+ a1->setInfoOnComponent(3,"dddd");
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setTime(2.3,4,5);
+ f1->setMesh(m1);
+ f1->setName("f1");
+ f1->setArray(a1);
+ f1->checkCoherency();
+ //
+ const int arr2[6]={1,2,1,2,0,0};
+ std::vector<int> arr2V(arr2,arr2+6);
+ MEDCouplingFieldDouble *f2=f1->keepSelectedComponents(arr2V);
+ CPPUNIT_ASSERT(f2->getMesh()==f1->getMesh());
+ CPPUNIT_ASSERT(f2->getTimeDiscretization()==ONE_TIME);
+ int dt,it;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
+ CPPUNIT_ASSERT_EQUAL(4,dt);
+ CPPUNIT_ASSERT_EQUAL(5,it);
+ f2->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="cccc");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="bbbb");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
+ const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f2->getIJ(0,i),1e-14);
+ //setSelectedComponents
+ const int arr3[2]={3,2};
+ std::vector<int> arr3V(arr3,arr3+2);
+ MEDCouplingFieldDouble *f5=f1->keepSelectedComponents(arr3V);
+ f5->setTime(6.7,8,9);
+ f5->getArray()->setInfoOnComponent(0,"eeee");
+ f5->getArray()->setInfoOnComponent(1,"ffff");
+ f5->checkCoherency();
+ const int arr4[2]={1,2};
+ std::vector<int> arr4V(arr4,arr4+2);
+ f2->setSelectedComponents(f5,arr4V);
+ CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
+ f2->checkCoherency();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
+ CPPUNIT_ASSERT_EQUAL(4,dt);
+ CPPUNIT_ASSERT_EQUAL(5,it);
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="eeee");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="ffff");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
+ CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
+ const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-14);
+ f5->decrRef();
+ f1->decrRef();
+ f2->decrRef();
+ a1->decrRef();
+ m1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIGetIdsEqual1()
+{
+ const int tab1[7]={5,-2,-4,-2,3,2,-2};
+ DataArrayInt *da=DataArrayInt::New();
+ da->alloc(7,1);
+ std::copy(tab1,tab1+7,da->getPointer());
+ DataArrayInt *da2=da->getIdsEqual(-2);
+ CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+ const int expected1[3]={1,3,6};
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da2->getConstPointer()));
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIGetIdsEqualList1()
+{
+ const int tab1[7]={5,-2,-4,-2,3,2,-2};
+ DataArrayInt *da=DataArrayInt::New();
+ da->alloc(7,1);
+ std::copy(tab1,tab1+7,da->getPointer());
+ const int tab2[3]={3,-2,0};
+ std::vector<int> tab2V(tab2,tab2+3);
+ DataArrayInt *da2=da->getIdsEqualList(tab2V);
+ CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+ const int expected1[4]={1,3,4,6};
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+4,da2->getConstPointer()));
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAFromNoInterlace1()
+{
+ const int tab1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
+ DataArrayInt *da=DataArrayInt::New();
+ da->alloc(5,3);
+ std::copy(tab1,tab1+15,da->getPointer());
+ DataArrayInt *da2=da->fromNoInterlace();
+ const int expected1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
+ CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
+ DataArrayDouble *da3=da->convertToDblArr();
+ DataArrayDouble *da4=da3->fromNoInterlace();
+ CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
+ for(int i=0;i<15;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
+ da4->decrRef();
+ da3->decrRef();
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAToNoInterlace1()
+{
+ const int tab1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
+ DataArrayInt *da=DataArrayInt::New();
+ da->alloc(5,3);
+ std::copy(tab1,tab1+15,da->getPointer());
+ DataArrayInt *da2=da->toNoInterlace();
+ const int expected1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
+ CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
+ DataArrayDouble *da3=da->convertToDblArr();
+ DataArrayDouble *da4=da3->toNoInterlace();
+ CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
+ for(int i=0;i<15;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
+ da4->decrRef();
+ da3->decrRef();
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIsUniform1()
+{
+ const int tab1[5]={1,1,1,1,1};
+ DataArrayInt *da=DataArrayInt::New();
+ da->alloc(5,1);
+ std::copy(tab1,tab1+5,da->getPointer());
+ CPPUNIT_ASSERT(da->isUniform(1));
+ da->setIJ(2,0,2);
+ CPPUNIT_ASSERT(!da->isUniform(1));
+ da->setIJ(2,0,1);
+ CPPUNIT_ASSERT(da->isUniform(1));
+ DataArrayDouble *da2=da->convertToDblArr();
+ CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
+ da2->setIJ(1,0,1.+1.e-13);
+ CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
+ da2->setIJ(1,0,1.+1.e-11);
+ CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDADFromPolarToCart1()
+{
+ const double tab1[4]={2.,0.2,2.5,0.7};
+ DataArrayDouble *da=DataArrayDouble::New();
+ da->alloc(2,2);
+ std::copy(tab1,tab1+4,da->getPointer());
+ DataArrayDouble *da2=da->fromPolarToCart();
+ const double expected1[4]={1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275};
+ for(int i=0;i<4;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDADFromCylToCart1()
+{
+ const double tab1[6]={2.,0.2,4.,2.5,0.7,9.};
+ DataArrayDouble *da=DataArrayDouble::New();
+ da->alloc(2,3);
+ std::copy(tab1,tab1+6,da->getPointer());
+ DataArrayDouble *da2=da->fromCylToCart();
+ const double expected1[6]={1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDADFromSpherToCart1()
+{
+ const double tab1[6]={2.,0.2,0.3,2.5,0.7,0.8};
+ DataArrayDouble *da=DataArrayDouble::New();
+ da->alloc(2,3);
+ std::copy(tab1,tab1+6,da->getPointer());
+ DataArrayDouble *da2=da->fromSpherToCart();
+ const double expected1[6]={0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
+ da2->decrRef();
+ da->decrRef();
+}
+
+void MEDCouplingBasicsTest::testUnPolyze1()
+{
+ const int elts[8]={0,1,2,3,4,5,6,7};
+ std::vector<int> eltsV(elts,elts+8);
+ MEDCouplingUMesh *mesh=build3DTargetMesh_1();
+ mesh->convertToPolyTypes(eltsV);
+ mesh->unPolyze();
+ MEDCouplingUMesh *mesh2=build3DTargetMesh_1();
+ mesh->checkCoherency();
+ CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
+ mesh->convertToPolyTypes(eltsV);
+ CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
+ mesh->getNodalConnectivity()->setIJ(0,6,10);
+ mesh->getNodalConnectivity()->setIJ(0,7,9);
+ mesh->getNodalConnectivity()->setIJ(0,8,12);
+ mesh->getNodalConnectivity()->setIJ(0,9,13);
+ mesh->unPolyze();
+ CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
+ mesh->convertToPolyTypes(eltsV);
+ mesh->getNodalConnectivity()->setIJ(0,6,12);
+ mesh->getNodalConnectivity()->setIJ(0,7,13);
+ mesh->getNodalConnectivity()->setIJ(0,8,10);
+ mesh->getNodalConnectivity()->setIJ(0,9,9);
+ mesh->unPolyze();
+ CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
+ mesh->convertToPolyTypes(eltsV);
+ mesh->getNodalConnectivity()->setIJ(0,6,12);
+ mesh->getNodalConnectivity()->setIJ(0,7,10);
+ mesh->getNodalConnectivity()->setIJ(0,8,13);
+ mesh->getNodalConnectivity()->setIJ(0,9,9);
+ mesh->unPolyze();
+ CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
+ mesh->decrRef();
+ mesh2->decrRef();
+ // Test for 2D mesh
+ mesh=build2DTargetMesh_1();
+ mesh2=build2DTargetMesh_1();
+ eltsV.resize(5);
+ mesh->convertToPolyTypes(eltsV);
+ CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
+ mesh->unPolyze();
+ CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
+ mesh->decrRef();
+ mesh2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testConvertDegeneratedCells1()
+{
+ MEDCouplingUMesh *mesh=build3DTargetMesh_1();
+ int conn[32]={0,1,3,3,9,10,12,12, 0,1,3,4,9,9,9,9, 1,1,1,1,10,12,9,10, 10,11,12,9,1,1,1,1};
+ mesh->allocateCells(4);
+ mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
+ mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+8);
+ mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+16);
+ mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+24);
+ mesh->finishInsertingCells();
+ mesh->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(0));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(1));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(2));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(3));
+ MEDCouplingFieldDouble *f1=mesh->getMeasureField(true);
+ mesh->convertDegeneratedCells();
+ mesh->checkCoherency();
+ MEDCouplingFieldDouble *f2=mesh->getMeasureField(true);
+ CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,mesh->getTypeOfCell(0));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(1));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TETRA4,mesh->getTypeOfCell(2));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(3));
+ for(int i=0;i<4;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getArray()->getIJ(0,i),f2->getArray()->getIJ(0,i),1e-5);
+ f1->decrRef();
+ f2->decrRef();
+ mesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::testGetNodeIdsNearPoints1()
+{
+ MEDCouplingUMesh *mesh=build2DTargetMesh_1();
+ DataArrayDouble *coords=mesh->getCoords();
+ DataArrayDouble *tmp=DataArrayDouble::New();
+ tmp->alloc(3,2);
+ const double vals[6]={0.2,0.2,0.1,0.2,0.2,0.2};
+ std::copy(vals,vals+6,tmp->getPointer());
+ DataArrayDouble *tmp2=DataArrayDouble::Aggregate(coords,tmp);
+ tmp->decrRef();
+ mesh->setCoords(tmp2);
+ tmp2->decrRef();
+ const double pts[6]={0.2,0.2,0.1,0.3,-0.3,0.7};
+ std::vector<int> c=mesh->getNodeIdsNearPoint(pts,1e-7);
+ CPPUNIT_ASSERT_EQUAL(3,(int)c.size());
+ CPPUNIT_ASSERT_EQUAL(4,c[0]);
+ CPPUNIT_ASSERT_EQUAL(9,c[1]);
+ CPPUNIT_ASSERT_EQUAL(11,c[2]);
+ c.clear();
+ std::vector<int> cI;
+ mesh->getNodeIdsNearPoints(pts,3,1e-7,c,cI);
+ CPPUNIT_ASSERT_EQUAL(4,(int)cI.size());
+ CPPUNIT_ASSERT_EQUAL(4,(int)c.size());
+ CPPUNIT_ASSERT_EQUAL(4,c[0]);
+ CPPUNIT_ASSERT_EQUAL(9,c[1]);
+ CPPUNIT_ASSERT_EQUAL(11,c[2]);
+ CPPUNIT_ASSERT_EQUAL(6,c[3]);
+ CPPUNIT_ASSERT_EQUAL(0,cI[0]);
+ CPPUNIT_ASSERT_EQUAL(3,cI[1]);
+ CPPUNIT_ASSERT_EQUAL(3,cI[2]);
+ CPPUNIT_ASSERT_EQUAL(4,cI[3]);
+ mesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldCopyTinyAttrFrom1()
+{
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setName("f1");
+ f1->setTimeTolerance(1.e-5);
+ f1->setDescription("f1Desc");
+ f1->setTime(1.23,4,5);
+ MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f2->setName("f2");
+ f2->setDescription("f2Desc");
+ f2->setTime(6.78,9,10);
+ f2->setTimeTolerance(4.556e-12);
+ //
+ int dt,it;
+ f1->copyTinyAttrFrom(f2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
+ CPPUNIT_ASSERT_EQUAL(9,dt);
+ CPPUNIT_ASSERT_EQUAL(10,it);
+ CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
+ CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
+ f1->decrRef();
+ f2->decrRef();
+ //
+ f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+ f1->setName("f1");
+ f1->setTimeTolerance(1.e-5);
+ f1->setDescription("f1Desc");
+ f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+ f2->setName("f2");
+ f2->setDescription("f2Desc");
+ f2->setTimeTolerance(4.556e-12);
+ //
+ f1->copyTinyAttrFrom(f2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
+ CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
+ CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
+ f1->decrRef();
+ f2->decrRef();
+ //
+ f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
+ f1->setName("f1");
+ f1->setTimeTolerance(1.e-5);
+ f1->setDescription("f1Desc");
+ f1->setTime(1.23,4,5);
+ f1->setEndTime(5.43,2,1);
+ f2=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
+ f2->setName("f2");
+ f2->setDescription("f2Desc");
+ f2->setTimeTolerance(4.556e-12);
+ f2->setTime(6.78,9,10);
+ f2->setEndTime(10.98,7,6);
+ //
+ f1->copyTinyAttrFrom(f2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
+ CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
+ CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
+ CPPUNIT_ASSERT_EQUAL(9,dt);
+ CPPUNIT_ASSERT_EQUAL(10,it);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
+ CPPUNIT_ASSERT_EQUAL(7,dt);
+ CPPUNIT_ASSERT_EQUAL(6,it);
+ f1->decrRef();
+ f2->decrRef();
+ //
+ f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
+ f1->setName("f1");
+ f1->setTimeTolerance(1.e-5);
+ f1->setDescription("f1Desc");
+ f1->setTime(1.23,4,5);
+ f1->setEndTime(5.43,2,1);
+ f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
+ f2->setName("f2");
+ f2->setDescription("f2Desc");
+ f2->setTimeTolerance(4.556e-12);
+ f2->setTime(6.78,9,10);
+ f2->setEndTime(10.98,7,6);
+ //
+ f1->copyTinyAttrFrom(f2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
+ CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
+ CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
+ CPPUNIT_ASSERT_EQUAL(9,dt);
+ CPPUNIT_ASSERT_EQUAL(10,it);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
+ CPPUNIT_ASSERT_EQUAL(7,dt);
+ CPPUNIT_ASSERT_EQUAL(6,it);
+ f1->decrRef();
+ f2->decrRef();
+}
+
+/*!
+ * 1D -> 2D extrusion with rotation
+ */
+void MEDCouplingBasicsTest::testExtrudedMesh5()
+{
+ const double coo1[4]={0.,1.,2.,3.5};
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(4,1);
+ std::copy(coo1,coo1+4,a->getPointer());
+ MEDCouplingCMesh *b=MEDCouplingCMesh::New();
+ b->setCoordsAt(0,a);
+ MEDCouplingUMesh *c=b->buildUnstructured();
+ CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
+ c->changeSpaceDimension(2);
+ //
+ DataArrayDouble *d=DataArrayDouble::New();
+ d->alloc(13,1);
+ d->iota();
+ MEDCouplingCMesh *e=MEDCouplingCMesh::New();
+ e->setCoordsAt(0,d);
+ MEDCouplingUMesh *f=e->buildUnstructured();
+ DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
+ DataArrayDouble *h=g->fromPolarToCart();
+ f->setCoords(h);
+ MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
+ CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
+ bool tmp2;
+ int tmp3;
+ DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
+ CPPUNIT_ASSERT(tmp2);
+ CPPUNIT_ASSERT_EQUAL(37,tmp3);
+ tmp->decrRef();
+ i->convertDegeneratedCells();
+ i->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(36,i->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(37,i->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(12,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3));
+ CPPUNIT_ASSERT_EQUAL(24,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4));
+ const double expected1[3]={0.25,0.75,2.0625};
+ MEDCouplingFieldDouble *j=i->getMeasureField(true);
+ for(int i=0;i<12;i++)
+ for(int k=0;k<3;k++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[k],j->getIJ(0,i*3+k),1e-10);
+ const double expected2[72]={0.62200846792814113, 0.16666666666681595, 1.4513530918323276, 0.38888888888923495, 2.6293994326053212, 0.7045454545460802, 0.45534180126145435, 0.45534180126150181, 1.0624642029433926, 1.0624642029435025, 1.9248539780597826, 1.9248539780599816, 0.16666666666661334, 0.62200846792815856, 0.38888888888876294, 1.4513530918323678, 0.70454545454522521, 2.629399432605394, -0.16666666666674007, 0.62200846792812436, -0.38888888888906142, 1.4513530918322881, -0.70454545454576778, 2.6293994326052488, -0.45534180126154766, 0.45534180126140844, -1.0624642029436118, 1.0624642029432834, -1.9248539780601803, 1.9248539780595841, -0.62200846792817499, 0.1666666666665495, -1.451353091832408, 0.388888888888613, -2.6293994326054668, 0.70454545454495332, -0.62200846792810593, -0.16666666666680507, -1.451353091832247, -0.38888888888921297, -2.6293994326051746, -0.70454545454604123, -0.45534180126135926, -0.45534180126159562, -1.0624642029431723, -1.0624642029437235, -1.9248539780593836, -1.9248539780603811, -0.1666666666664828, -0.62200846792819242, -0.38888888888846079, -1.4513530918324489, -0.70454545454467987, -2.6293994326055397, 0.16666666666687083, -0.62200846792808862, 0.38888888888936374, -1.4513530918322073, 0.70454545454631357, -2.6293994326051022, 0.45534180126164348, -0.45534180126131207, 1.0624642029438327, -1.0624642029430627, 1.9248539780605791, -1.9248539780591853, 0.62200846792821063, -0.16666666666641802, 1.4513530918324888, -0.38888888888831086, 2.6293994326056125, -0.70454545454440853};
+ DataArrayDouble *m=i->getBarycenterAndOwner();
+ for(int i=0;i<72;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m->getIJ(0,i),1e-10);
+ //
+ m->decrRef();
+ j->decrRef();
+ i->decrRef();
+ h->decrRef();
+ g->decrRef();
+ f->decrRef();
+ e->decrRef();
+ d->decrRef();
+ c->decrRef();
+ b->decrRef();
+ a->decrRef();
+}
+
+/*!
+ * 1D -> 2D extrusion without rotation
+ */
+void MEDCouplingBasicsTest::testExtrudedMesh6()
+{
+ const double coo1[4]={0.,1.,2.,3.5};
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(4,1);
+ std::copy(coo1,coo1+4,a->getPointer());
+ MEDCouplingCMesh *b=MEDCouplingCMesh::New();
+ b->setCoordsAt(0,a);
+ MEDCouplingUMesh *c=b->buildUnstructured();
+ CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
+ c->changeSpaceDimension(2);
+ //
+ DataArrayDouble *d=DataArrayDouble::New();
+ d->alloc(5,1);
+ d->iota();
+ MEDCouplingCMesh *e=MEDCouplingCMesh::New();
+ e->setCoordsAt(0,d);
+ MEDCouplingUMesh *f=e->buildUnstructured();
+ DataArrayDouble *d2=f->getCoords()->applyFunc("x*x/2");
+ f->setCoords(d2);
+ f->changeSpaceDimension(2);
+ //
+ const double center[2]={0.,0.};
+ f->rotate(center,0,M_PI/3);
+ MEDCouplingUMesh *g=c->buildExtrudedMesh(f,0);
+ g->checkCoherency();
+ const double expected1[]={ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 };
+ MEDCouplingFieldDouble *f1=g->getMeasureField(true);
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-12);
+
+ const double expected2[]={0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414};
+ DataArrayDouble *f2=g->getBarycenterAndOwner();
+ for(int i=0;i<24;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-12);
+ //
+ f1->decrRef();
+ f2->decrRef();
+ g->decrRef();
+ f->decrRef();
+ e->decrRef();
+ d->decrRef();
+ d2->decrRef();
+ c->decrRef();
+ b->decrRef();
+ a->decrRef();
+}
+
+/*!
+ * 2D -> 3D extrusion with rotation
+ */
+void MEDCouplingBasicsTest::testExtrudedMesh7()
+{
+ const double coo1[4]={0.,1.,2.,3.5};
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(4,1);
+ std::copy(coo1,coo1+4,a->getPointer());
+ MEDCouplingCMesh *b=MEDCouplingCMesh::New();
+ b->setCoordsAt(0,a);
+ MEDCouplingUMesh *c=b->buildUnstructured();
+ CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
+ c->changeSpaceDimension(2);
+ //
+ DataArrayDouble *d=DataArrayDouble::New();
+ d->alloc(13,1);
+ d->iota();
+ MEDCouplingCMesh *e=MEDCouplingCMesh::New();
+ e->setCoordsAt(0,d);
+ MEDCouplingUMesh *f=e->buildUnstructured();
+ DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
+ DataArrayDouble *h=g->fromPolarToCart();
+ f->setCoords(h);
+ MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
+ CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
+ bool tmp2;
+ int tmp3;
+ DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
+ CPPUNIT_ASSERT(tmp2);
+ CPPUNIT_ASSERT_EQUAL(37,tmp3);
+ tmp->decrRef();
+ i->convertDegeneratedCells();
+ const double vec1[3]={10.,0.,0.};
+ i->translate(vec1);
+ DataArrayDouble *g2=h->applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
+ f->setCoords(g2);
+ i->changeSpaceDimension(3);
+ MEDCouplingUMesh *i3=i->buildExtrudedMesh(f,1);
+ MEDCouplingFieldDouble *f2=i3->getMeasureField(true);
+ tmp=i->mergeNodes(1e-9,tmp2,tmp3);
+ CPPUNIT_ASSERT(tmp2);
+ CPPUNIT_ASSERT_EQUAL(444,tmp3);
+ tmp->decrRef();
+ const double expected1[36]={1.327751058489274, 4.2942574094314701, 13.024068164857139, 1.3069177251569044, 4.1484240761012954, 12.297505664866796, 1.270833333332571, 3.8958333333309674, 11.039062499993179, 1.2291666666659207, 3.6041666666644425, 9.585937499993932, 1.1930822748415895, 3.3515759238941376, 8.3274943351204556, 1.1722489415082769, 3.2057425905609289, 7.6009318351210622, 1.1722489415082862, 3.2057425905609884, 7.6009318351213713, 1.1930822748416161, 3.3515759238943001, 8.3274943351212727, 1.2291666666659564, 3.6041666666646734, 9.5859374999950777, 1.2708333333326081, 3.8958333333311868, 11.039062499994293, 1.3069177251569224, 4.1484240761014384, 12.297505664867627, 1.3277510584902354, 4.2942574094346071, 13.024068164866796};
+ int kk=0;
+ for(int ii=0;ii<12;ii++)
+ for(int jj=0;jj<36;jj++,kk++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[jj],f2->getIJ(0,kk),1e-9);
+ //
+ f2->decrRef();
+ i3->decrRef();
+ g2->decrRef();
+ i->decrRef();
+ h->decrRef();
+ g->decrRef();
+ f->decrRef();
+ e->decrRef();
+ d->decrRef();
+ c->decrRef();
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testSimplexize1()
+{
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ std::vector<int> v(1);
+ v[0]=3;
+ m->convertToPolyTypes(v);
+ DataArrayInt *da=m->simplexize(0);
+ CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
+ const int expected2[7]={0,0,1,2,3,4,4};
+ for(int i=0;i<7;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
+ m->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
+ const double expected1[7]={0.125,0.125,0.125,0.125,0.25,0.125,0.125};
+ MEDCouplingFieldDouble *f=m->getMeasureField(false);
+ for(int i=0;i<7;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
+ std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllTypes();
+ CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
+ f->decrRef();
+ da->decrRef();
+ m->decrRef();
+ //
+ m=build3DSurfTargetMesh_1();
+ v[0]=3;
+ m->convertToPolyTypes(v);
+ da=m->simplexize(1);
+ CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
+ for(int i=0;i<7;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
+ m->checkCoherency();
+ types=m->getAllTypes();
+ CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
+ CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
+ f=m->getMeasureField(false);
+ for(int i=0;i<7;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
+ f->decrRef();
+ da->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testSimplexize2()
+{
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ std::vector<int> v(1);
+ v[0]=3;
+ m->convertToPolyTypes(v);
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setMesh(m);
+ DataArrayDouble *arr=DataArrayDouble::New();
+ const double arr1[10]={10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
+ arr->alloc(5,2);
+ std::copy(arr1,arr1+10,arr->getPointer());
+ f1->setArray(arr);
+ arr->decrRef();
+ //
+ f1->checkCoherency();
+ CPPUNIT_ASSERT(f1->simplexize(0));
+ f1->checkCoherency();
+ const double expected1[14]={10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
+ CPPUNIT_ASSERT(!f1->simplexize(0));
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
+ //
+ f1->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAMeld1()
+{
+ DataArrayDouble *da1=DataArrayDouble::New();
+ da1->alloc(7,2);
+ DataArrayDouble *da2=DataArrayDouble::New();
+ da2->alloc(7,1);
+ //
+ da1->fillWithValue(7.);
+ da2->iota(0.);
+ DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
+ //
+ da1->setInfoOnComponent(0,"c0da1");
+ da1->setInfoOnComponent(1,"c1da1");
+ da3->setInfoOnComponent(0,"c0da3");
+ da3->setInfoOnComponent(1,"c1da3");
+ da3->setInfoOnComponent(2,"c2da3");
+ //
+ DataArrayDouble *da1C=da1->deepCpy();
+ da1->meldWith(da3);
+ CPPUNIT_ASSERT_EQUAL(5,da1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(7,da1->getNumberOfTuples());
+ CPPUNIT_ASSERT(da1->getInfoOnComponent(0)=="c0da1");
+ CPPUNIT_ASSERT(da1->getInfoOnComponent(1)=="c1da1");
+ CPPUNIT_ASSERT(da1->getInfoOnComponent(2)=="c0da3");
+ CPPUNIT_ASSERT(da1->getInfoOnComponent(3)=="c1da3");
+ CPPUNIT_ASSERT(da1->getInfoOnComponent(4)=="c2da3");
+ //
+ const double expected1[35]={7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.};
+ for(int i=0;i<35;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
+ //
+ DataArrayInt *dai1=da1C->convertToIntArr();
+ DataArrayInt *dai3=da3->convertToIntArr();
+ dai1->meldWith(dai3);
+ CPPUNIT_ASSERT_EQUAL(5,dai1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(7,dai1->getNumberOfTuples());
+ CPPUNIT_ASSERT(dai1->getInfoOnComponent(0)=="c0da1");
+ CPPUNIT_ASSERT(dai1->getInfoOnComponent(1)=="c1da1");
+ CPPUNIT_ASSERT(dai1->getInfoOnComponent(2)=="c0da3");
+ CPPUNIT_ASSERT(dai1->getInfoOnComponent(3)=="c1da3");
+ CPPUNIT_ASSERT(dai1->getInfoOnComponent(4)=="c2da3");
+ for(int i=0;i<35;i++)
+ CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai1->getIJ(0,i));
+ // test of static method DataArrayDouble::meld
+ DataArrayDouble *da4=DataArrayDouble::Meld(da1C,da3);
+ CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(7,da4->getNumberOfTuples());
+ CPPUNIT_ASSERT(da4->getInfoOnComponent(0)=="c0da1");
+ CPPUNIT_ASSERT(da4->getInfoOnComponent(1)=="c1da1");
+ CPPUNIT_ASSERT(da4->getInfoOnComponent(2)=="c0da3");
+ CPPUNIT_ASSERT(da4->getInfoOnComponent(3)=="c1da3");
+ CPPUNIT_ASSERT(da4->getInfoOnComponent(4)=="c2da3");
+ for(int i=0;i<35;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
+ // test of static method DataArrayInt::meld
+ dai1->decrRef();
+ dai1=da1C->convertToIntArr();
+ DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
+ CPPUNIT_ASSERT_EQUAL(5,dai4->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(7,dai4->getNumberOfTuples());
+ CPPUNIT_ASSERT(dai4->getInfoOnComponent(0)=="c0da1");
+ CPPUNIT_ASSERT(dai4->getInfoOnComponent(1)=="c1da1");
+ CPPUNIT_ASSERT(dai4->getInfoOnComponent(2)=="c0da3");
+ CPPUNIT_ASSERT(dai4->getInfoOnComponent(3)=="c1da3");
+ CPPUNIT_ASSERT(dai4->getInfoOnComponent(4)=="c2da3");
+ for(int i=0;i<35;i++)
+ CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai4->getIJ(0,i));
+ //
+ dai4->decrRef();
+ da4->decrRef();
+ dai3->decrRef();
+ dai1->decrRef();
+ da1C->decrRef();
+ da1->decrRef();
+ da2->decrRef();
+ da3->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldMeld1()
+{
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setMesh(m);
+ DataArrayDouble *da1=DataArrayDouble::New();
+ const double arr1[5]={12.,23.,34.,45.,56.};
+ da1->alloc(5,1);
+ std::copy(arr1,arr1+5,da1->getPointer());
+ da1->setInfoOnComponent(0,"aaa");
+ f1->setArray(da1);
+ f1->setTime(3.4,2,1);
+ f1->checkCoherency();
+ //
+ MEDCouplingFieldDouble *f2=f1->deepCpy();
+ f2->setMesh(f1->getMesh());
+ f2->checkCoherency();
+ f2->changeNbOfComponents(2,5.);
+ (*f2)=5.;
+ f2->getArray()->setInfoOnComponent(0,"bbb");
+ f2->getArray()->setInfoOnComponent(1,"ccc");
+ f2->checkCoherency();
+ //
+ MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MeldFields(f2,f1);
+ f3->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(5,f3->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,f3->getNumberOfComponents());
+ CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(0)=="bbb");
+ CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(1)=="ccc");
+ CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(2)=="aaa");
+ const double expected1[15]={5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.};
+ for(int i=0;i<15;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-12);
+ int dt,it;
+ double time=f3->getTime(dt,it);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,time,1e-14);
+ CPPUNIT_ASSERT_EQUAL(2,dt);
+ CPPUNIT_ASSERT_EQUAL(1,it);
+ //
+ MEDCouplingFieldDouble *f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
+ MEDCouplingFieldDouble *f5=f1->buildNewTimeReprFromThis(NO_TIME,false);
+ MEDCouplingFieldDouble *f6=MEDCouplingFieldDouble::MeldFields(f4,f5);
+ f6->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(5,f6->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,f6->getNumberOfComponents());
+ CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(0)=="bbb");
+ CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(1)=="ccc");
+ CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(2)=="aaa");
+ for(int i=0;i<15;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f6->getIJ(0,i),1e-12);
+ //
+ f6->decrRef();
+ f4->decrRef();
+ f5->decrRef();
+ f3->decrRef();
+ da1->decrRef();
+ f2->decrRef();
+ f1->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testMergeNodes2()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ MEDCouplingUMesh *m2=build2DTargetMesh_1();
+ const double vec[2]={0.002,0.};
+ m2->translate(vec);
+ //
+ std::vector<const MEDCouplingUMesh *> tmp(2);
+ tmp[0]=m1;
+ tmp[1]=m2;
+ MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(tmp);
+ bool b;
+ int newNbOfNodes;
+ DataArrayInt *da=m3->mergeNodes2(0.01,b,newNbOfNodes);
+ CPPUNIT_ASSERT_EQUAL(9,m3->getNumberOfNodes());
+ const double expected1[18]={-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7};
+ for(int i=0;i<18;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],m3->getCoords()->getIJ(0,i),1e-13);
+ //
+ da->decrRef();
+ m3->decrRef();
+ m1->decrRef();
+ m2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testMergeField2()
+{
+ MEDCouplingUMesh *m=build2DTargetMesh_1();
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setMesh(m);
+ DataArrayDouble *arr=DataArrayDouble::New();
+ arr->alloc(5,2);
+ arr->fillWithValue(2.);
+ f1->setArray(arr);
+ arr->decrRef();
+ MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f2->setMesh(m);
+ arr=DataArrayDouble::New();
+ arr->alloc(5,2);
+ arr->fillWithValue(5.);
+ f2->setArray(arr);
+ arr->decrRef();
+ MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f3->setMesh(m);
+ arr=DataArrayDouble::New();
+ arr->alloc(5,2);
+ arr->fillWithValue(7.);
+ f3->setArray(arr);
+ arr->decrRef();
+ //
+ std::vector<const MEDCouplingFieldDouble *> tmp(3);
+ tmp[0]=f1; tmp[1]=f2; tmp[2]=f3;
+ MEDCouplingFieldDouble *f4=MEDCouplingFieldDouble::MergeFields(tmp);
+ CPPUNIT_ASSERT_EQUAL(15,f4->getMesh()->getNumberOfCells());
+ const double expected1[30]={2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.};
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f4->getIJ(0,i),1.e-13);
+ //
+ f4->decrRef();
+ f1->decrRef();
+ f2->decrRef();
+ f3->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIBuildComplement1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int tab[4]={3,1,7,8};
+ a->alloc(4,1);
+ std::copy(tab,tab+4,a->getPointer());
+ DataArrayInt *b=a->buildComplement(12);
+ CPPUNIT_ASSERT_EQUAL(8,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ const int expected1[8]={0,2,4,5,6,9,10,11};
+ for(int i=0;i<8;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIBuildUnion1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int tab1[4]={3,1,7,8};
+ a->alloc(4,1);
+ std::copy(tab1,tab1+4,a->getPointer());
+ DataArrayInt *c=DataArrayInt::New();
+ const int tab2[5]={5,3,0,18,8};
+ c->alloc(5,1);
+ std::copy(tab2,tab2+5,c->getPointer());
+ DataArrayInt *b=a->buildUnion(c);
+ CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ const int expected1[7]={0,1,3,5,7,8,18};
+ for(int i=0;i<7;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
+ c->decrRef();
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIBuildIntersection1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int tab1[4]={3,1,7,8};
+ a->alloc(4,1);
+ std::copy(tab1,tab1+4,a->getPointer());
+ DataArrayInt *c=DataArrayInt::New();
+ const int tab2[5]={5,3,0,18,8};
+ c->alloc(5,1);
+ std::copy(tab2,tab2+5,c->getPointer());
+ DataArrayInt *b=a->buildIntersection(c);
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ const int expected1[2]={3,8};
+ for(int i=0;i<2;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
+ c->decrRef();
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIDeltaShiftIndex1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int tab[7]={1,3,6,7,7,9,15};
+ a->alloc(7,1);
+ std::copy(tab,tab+7,a->getPointer());
+ DataArrayInt *b=a->deltaShiftIndex();
+ CPPUNIT_ASSERT_EQUAL(6,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ const int expected1[6]={2,3,1,0,2,6};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleSelectByTupleIdSafe1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={4,2,0,6,5};
+ DataArrayDouble *b=a->selectByTupleIdSafe(arr2,arr2+5);
+ CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ const int arr4[5]={4,-1,0,6,5};
+ CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
+ const int arr5[5]={4,2,0,6,7};
+ CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->selectByTupleIdSafe(arr2,arr2+5);
+ CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
+ CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testAreCellsIncludedIn1()
+{
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ const int pt[2]={1,3};
+ MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(pt,pt+2,true);
+ DataArrayInt *tmp;
+ CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
+ CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(pt[0],tmp->getIJ(0,0));
+ CPPUNIT_ASSERT_EQUAL(pt[1],tmp->getIJ(0,1));
+ tmp->decrRef();
+ CPPUNIT_ASSERT(!m2->areCellsIncludedIn(m,0,tmp));
+ tmp->decrRef();
+ m2->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIBuildSubstraction1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int aa[]={2,3,6,8,9};
+ a->alloc(5,1);
+ std::copy(aa,aa+5,a->getPointer());
+ DataArrayInt *b=DataArrayInt::New();
+ const int bb[]={1,3,5,9,11};
+ b->alloc(5,1);
+ std::copy(bb,bb+5,b->getPointer());
+ //
+ DataArrayInt *c=a->buildSubstraction(b);
+ CPPUNIT_ASSERT_EQUAL(3,c->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
+ const int expected1[3]={2,6,8};
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
+ //
+ c->decrRef();
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testBuildOrthogonalField2()
+{
+ MEDCouplingUMesh *m=build2DTargetMesh_1();
+ DataArrayInt *d1=DataArrayInt::New();
+ DataArrayInt *d2=DataArrayInt::New();
+ DataArrayInt *d3=DataArrayInt::New();
+ DataArrayInt *d4=DataArrayInt::New();
+ MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
+ //
+ MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
+ DataArrayDouble *da1=f1->getArray();
+ CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(13,da1->getNumberOfTuples());
+ //
+ const double expected1[26]={-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.};
+ for(int i=0;i<26;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-14);
+ //
+ f1->decrRef();
+ m1->decrRef();
+ d1->decrRef();
+ d2->decrRef();
+ d3->decrRef();
+ d4->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testUMInsertNextCell1()
+{
+ double targetCoords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
+ int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
+ MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
+ targetMesh->allocateCells(5);
+ CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn),INTERP_KERNEL::Exception);
+ targetMesh->setMeshDimension(2);
+ targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
+ CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,targetConn),INTERP_KERNEL::Exception);
+ CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn),INTERP_KERNEL::Exception);
+ CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn),INTERP_KERNEL::Exception);
+ targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
+ targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
+ targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
+ targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
+ targetMesh->finishInsertingCells();
+ DataArrayDouble *myCoords=DataArrayDouble::New();
+ myCoords->alloc(9,2);
+ std::copy(targetCoords,targetCoords+18,myCoords->getPointer());
+ targetMesh->setCoords(myCoords);
+ myCoords->decrRef();
+ targetMesh->checkCoherency();
+ targetMesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldOperatorDivDiffComp1()
+{
+ MEDCouplingUMesh *m=build2DTargetMesh_1();
+ DataArrayInt *d1=DataArrayInt::New();
+ DataArrayInt *d2=DataArrayInt::New();
+ DataArrayInt *d3=DataArrayInt::New();
+ DataArrayInt *d4=DataArrayInt::New();
+ MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
+ //
+ MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
+ const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.};
+ DataArrayDouble *arr=DataArrayDouble::New();
+ arr->alloc(13,1);
+ std::copy(arr1,arr1+13,arr->getPointer());
+ MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS);
+ f2->setArray(arr);
+ f2->setMesh(m1);
+ f2->checkCoherency();
+ //
+ MEDCouplingFieldDouble *f3=(*f1)/(*f2);
+ CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception);
+ f3->checkCoherency();
+ (*f1)/=(*f2);
+ CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10));
+ CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception);
+ const double expected1[26]={-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0};
+ for(int i=0;i<26;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10);
+ //
+ f3->decrRef();
+ f2->decrRef();
+ arr->decrRef();
+ f1->decrRef();
+ m1->decrRef();
+ d1->decrRef();
+ d2->decrRef();
+ d3->decrRef();
+ d4->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDARearrange1()
+{
+ DataArrayInt *da1=DataArrayInt::New();
+ da1->alloc(12,1);
+ da1->iota(0);
+ const int *ptr=da1->getConstPointer();
+ //
+ CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfTuples());
+ da1->rearrange(4);
+ CPPUNIT_ASSERT(ptr==da1->getConstPointer());
+ CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfTuples());
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
+ //
+ da1->rearrange(6);
+ CPPUNIT_ASSERT(ptr==da1->getConstPointer());
+ CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(6,da1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfTuples());
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
+ //
+ CPPUNIT_ASSERT_THROW(da1->rearrange(7),INTERP_KERNEL::Exception);
+ //
+ da1->rearrange(12);
+ CPPUNIT_ASSERT(ptr==da1->getConstPointer());
+ CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfTuples());
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
+ //
+ da1->rearrange(3);
+ CPPUNIT_ASSERT(ptr==da1->getConstPointer());
+ CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples());
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
+ //double
+ DataArrayDouble *da2=da1->convertToDblArr();
+ da1->decrRef();
+ const double *ptr2=da2->getConstPointer();
+ //
+ CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
+ da2->rearrange(4);
+ CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
+ CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
+ //
+ da2->rearrange(6);
+ CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
+ CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(2,da2->getNumberOfTuples());
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
+ //
+ CPPUNIT_ASSERT_THROW(da2->rearrange(7),INTERP_KERNEL::Exception);
+ //
+ da2->rearrange(1);
+ CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
+ CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(12,da2->getNumberOfTuples());
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
+ //
+ da2->rearrange(3);
+ CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
+ CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
+ da2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testGetDifferentValues1()
+{
+ DataArrayInt *da1=DataArrayInt::New();
+ const int arr[12]={1,2,3,2,2,3,5,1,5,5,2,2};
+ da1->alloc(4,3);
+ std::copy(arr,arr+12,da1->getPointer());
+ std::set<int> s=da1->getDifferentValues();
+ const int expected1[4]={1,2,3,5};
+ CPPUNIT_ASSERT_EQUAL(4,(int)s.size());
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+4,s.begin()));
+ da1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIBuildPermutationArr1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int vala[5]={4,5,6,7,8};
+ a->alloc(5,1);
+ std::copy(vala,vala+5,a->getPointer());
+ DataArrayInt *b=DataArrayInt::New();
+ const int valb[5]={5,4,8,6,7};
+ b->alloc(5,1);
+ std::copy(valb,valb+5,b->getPointer());
+ DataArrayInt *c=a->buildPermutationArr(*b);
+ const int expect1[5]={1,0,4,2,3};
+ CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
+ CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
+ b->setIJ(0,0,9);
+ CPPUNIT_ASSERT(!a->isEqualWithoutConsideringStrAndOrder(*b));
+ CPPUNIT_ASSERT_THROW(a->buildPermutationArr(*b),INTERP_KERNEL::Exception);
+ a->setIJ(3,0,4);
+ b->setIJ(0,0,5);
+ b->setIJ(4,0,4);//;a==[4,5,6,4,8] and b==[5,4,8,6,4]
+ CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
+ c->decrRef();
+ c=a->buildPermutationArr(*b);
+ const int expect2[5]={1,3,4,2,3};
+ CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
+ DataArrayDouble *d=b->convertToDblArr();
+ b->sort();
+ const int expect3[5]={4,4,5,6,8};
+ CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
+ d->sort();
+ CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
+ for(int i=0;i<5;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
+ //
+ d->decrRef();
+ c->decrRef();
+ a->decrRef();
+ b->decrRef();
+}
+
+void MEDCouplingBasicsTest::testAreCellsIncludedIn2()
+{
+ const char myName[]="Vitoo";
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(0,0,true);
+ CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
+ CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
+ m2->setName(myName);
+ DataArrayInt *tmp;
+ CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
+ CPPUNIT_ASSERT(std::string(myName)==tmp->getName());
+ CPPUNIT_ASSERT_EQUAL(0,tmp->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
+ m->decrRef();
+ m2->decrRef();
+ tmp->decrRef();
+}
+
+void MEDCouplingBasicsTest::testUMeshGetPartBarycenterAndOwner1()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ const int part[3]={1,0,4};
+ DataArrayDouble *b=m1->getPartBarycenterAndOwner(part,part+3);
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
+ const double expected1[6]={0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ m1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testUMeshGetPartMeasureField1()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ const int part[3]={1,0,4};
+ DataArrayDouble *b=m1->getPartMeasureField(true,part,part+3);
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
+ const double expected1[3]={0.125,0.25,0.25};
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ m1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testUMeshBuildPartOrthogonalField1()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ m1->changeSpaceDimension(3);
+ const int part[3]={1,0,4};
+ MEDCouplingFieldDouble *b=m1->buildPartOrthogonalField(part,part+3);
+ CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfTuples());
+ const double expected1[9]={0.,0.,-1.,0.,0.,-1.,0.,0.,-1.};
+ for(int i=0;i<9;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getArray()->getIJ(0,i),1e-14);
+ b->decrRef();
+ m1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testUMeshGetTypesOfPart1()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ const int part1[]={0,3,4};
+ std::set<INTERP_KERNEL::NormalizedCellType> s;
+ s=m1->getTypesOfPart(part1,part1+3);
+ CPPUNIT_ASSERT(s.size()==1);
+ CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_QUAD4);
+ const int part2[]={2,2,2,1};
+ s=m1->getTypesOfPart(part2,part2+4);
+ CPPUNIT_ASSERT(s.size()==1);
+ CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
+ const int part3[]={3,2,1};
+ s=m1->getTypesOfPart(part3,part3+3);
+ CPPUNIT_ASSERT(s.size()==2);
+ CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
+ CPPUNIT_ASSERT(*(++s.begin())==INTERP_KERNEL::NORM_QUAD4);
+ m1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testUMeshKeepCellIdsByType1()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ const int part1[3]={0,3,4};
+ DataArrayInt *a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part1,part1+3);
+ CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(0,a->getNumberOfTuples());
+ a->decrRef();
+ //
+ const int part2[5]={3,2,0,2,4};
+ a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part2,part2+5);
+ CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,a->getIJ(0,0));
+ CPPUNIT_ASSERT_EQUAL(2,a->getIJ(1,0));
+ a->decrRef();
+ //
+ a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_QUAD4,part2,part2+5);
+ CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(3,a->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,a->getIJ(0,0));
+ CPPUNIT_ASSERT_EQUAL(0,a->getIJ(1,0));
+ CPPUNIT_ASSERT_EQUAL(4,a->getIJ(2,0));
+ //
+ a->decrRef();
+ m1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIAggregateMulti1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ a->setName("aa");
+ a->alloc(4,1);
+ a->iota(0);
+ a->rearrange(2);
+ DataArrayInt *b=DataArrayInt::New();
+ b->setName("bb");
+ b->alloc(6,1);
+ b->iota(0);
+ b->rearrange(2);
+ //
+ std::vector<const DataArrayInt *> v(2);
+ v[0]=a; v[1]=b;
+ DataArrayInt *c=DataArrayInt::Aggregate(v);
+ CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
+ CPPUNIT_ASSERT(c->getName()=="aa");
+ const int expect1[10]={0,1,2,3,0,1,2,3,4,5};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_EQUAL(expect1[i],c->getIJ(0,i));
+ //
+ c->decrRef();
+ a->decrRef();
+ b->decrRef();
+}
+
+void MEDCouplingBasicsTest::testMergeUMeshes2()
+{
+ MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
+ MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
+ MEDCouplingUMesh *m3=build3DSurfTargetMesh_1();
+ //
+ const int vec1[3]={0,2,3};
+ MEDCouplingUMesh *m2_2=(MEDCouplingUMesh *)m2->buildPartOfMySelf(vec1,vec1+3,false);
+ const int vec2[2]={1,1};
+ MEDCouplingUMesh *m3_2=(MEDCouplingUMesh *)m3->buildPartOfMySelf(vec2,vec2+2,false);
+ //
+ std::vector<const MEDCouplingUMesh *> ms(3);
+ ms[0]=m1; ms[1]=m2_2; ms[2]=m3_2;
+ //
+ MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshes(ms);
+ m4->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(10,m4->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(20,m4->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(45,m4->getMeshLength());
+ //
+ const int vec3[5]={0,1,2,3,4};
+ MEDCouplingUMesh *m4_1=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec3,vec3+5,false);
+ m4_1->setName(m1->getName());
+ CPPUNIT_ASSERT(m4_1->isEqual(m1,1e-12));
+ m4_1->decrRef();
+ //
+ const int vec4[3]={5,6,7};
+ MEDCouplingUMesh *m4_2=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec4,vec4+3,false);
+ DataArrayInt *cellCor=0;
+ DataArrayInt *nodeCor=0;
+ m4_2->checkGeoEquivalWith(m2_2,10,1e-12,cellCor,nodeCor);
+ CPPUNIT_ASSERT(cellCor==0);
+ CPPUNIT_ASSERT(nodeCor==0);
+ m4_2->decrRef();
+ //
+ const int vec5[2]={8,9};
+ MEDCouplingUMesh *m4_3=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec5,vec5+2,false);
+ CPPUNIT_ASSERT_EQUAL(2,m4_3->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(3,m4_3->getNumberOfNodes());
+ m3_2->zipCoords();
+ m4_3->setName(m3_2->getName());
+ CPPUNIT_ASSERT(m4_3->isEqual(m3_2,1e-12));
+ m4_3->decrRef();
+ //
+ m4->decrRef();
+ m1->decrRef();
+ m2->decrRef();
+ m2_2->decrRef();
+ m3->decrRef();
+ m3_2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testBuild0DMeshFromCoords1()
+{
+ const double sourceCoords[12]={-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.};
+ DataArrayDouble *coo=DataArrayDouble::New();
+ coo->alloc(4,3);
+ coo->setName("My0D");
+ std::copy(sourceCoords,sourceCoords+12,coo->getPointer());
+ MEDCouplingUMesh *m=MEDCouplingUMesh::Build0DMeshFromCoords(coo);
+ m->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
+ CPPUNIT_ASSERT_EQUAL(0,m->getMeshDimension());
+ const std::set<INTERP_KERNEL::NormalizedCellType>& types=m->getAllTypes();
+ CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
+ CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POINT1,*types.begin());
+ for(int i=0;i<4;i++)
+ {
+ std::vector<int> conn;
+ m->getNodeIdsOfCell(i,conn);
+ CPPUNIT_ASSERT_EQUAL(1,(int)conn.size());
+ CPPUNIT_ASSERT_EQUAL(i,conn[0]);
+ CPPUNIT_ASSERT(INTERP_KERNEL::NORM_POINT1==m->getTypeOfCell(i));
+ }
+ CPPUNIT_ASSERT(std::string(m->getName())=="My0D");
+ m->decrRef();
+ coo->decrRef();
+}
+
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "MEDCouplingBasicsTest.hxx"
+#include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingCMesh.hxx"
+#include "MEDCouplingExtrudedMesh.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingMemArray.hxx"
+#include "MEDCouplingGaussLocalization.hxx"
+#include "MEDCouplingMultiFields.hxx"
+#include "MEDCouplingFieldOverTime.hxx"
+
+#include <cmath>
+#include <functional>
+#include <iterator>
+
+using namespace ParaMEDMEM;
+
+void MEDCouplingBasicsTest::testDescriptionInMeshTimeUnit1()
+{
+ static const char text1[]="totoTTEDD";
+ MEDCouplingUMesh *m=build2DTargetMesh_1();
+ m->setDescription(text1);
+ CPPUNIT_ASSERT(std::string(m->getDescription())==text1);
+ MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->deepCpy();
+ CPPUNIT_ASSERT(m->isEqual(m2,1e-12));
+ CPPUNIT_ASSERT(std::string(m2->getDescription())==text1);
+ m2->setDescription("ggg");
+ CPPUNIT_ASSERT(!m->isEqual(m2,1e-12));
+ m2->decrRef();
+ //
+ MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f->setTimeUnit(text1);
+ CPPUNIT_ASSERT(std::string(f->getTimeUnit())==text1);
+ MEDCouplingFieldDouble *f2=f->deepCpy();
+ CPPUNIT_ASSERT(std::string(f2->getTimeUnit())==text1);
+ f2->decrRef();
+ //
+ f->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testMultiFields1()
+{
+ MEDCouplingMultiFields *mfs=buildMultiFields_1();
+ std::vector<MEDCouplingMesh *> ms=mfs->getMeshes();
+ std::vector<int> refs;
+ std::vector<MEDCouplingMesh *> dms=mfs->getDifferentMeshes(refs);
+ std::vector<DataArrayDouble *> das=mfs->getArrays();
+ std::vector< std::vector<int> > refs2;
+ std::vector<DataArrayDouble *> das2=mfs->getDifferentArrays(refs2);
+ //
+ CPPUNIT_ASSERT_EQUAL(5,(int)ms.size());
+ CPPUNIT_ASSERT_EQUAL(2,(int)dms.size());
+ CPPUNIT_ASSERT_EQUAL(6,(int)das.size());
+ CPPUNIT_ASSERT_EQUAL(5,(int)das2.size());
+ //
+ MEDCouplingMultiFields *mfs2=mfs->deepCpy();
+ CPPUNIT_ASSERT(mfs->isEqual(mfs2,1e-12,1e-12));
+ mfs2->decrRef();
+ //
+ mfs->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldOverTime1()
+{
+ std::vector<MEDCouplingFieldDouble *> fs=buildMultiFields_2();
+ CPPUNIT_ASSERT_THROW(MEDCouplingFieldOverTime::New(fs),INTERP_KERNEL::Exception);
+ MEDCouplingFieldDouble *f4bis=fs[4]->buildNewTimeReprFromThis(ONE_TIME,false);
+ fs[4]->decrRef();
+ fs[4]=f4bis;
+ CPPUNIT_ASSERT_THROW(MEDCouplingFieldOverTime::New(fs),INTERP_KERNEL::Exception);
+ f4bis->setTime(2.7,20,21);
+ MEDCouplingFieldOverTime *fot=MEDCouplingFieldOverTime::New(fs);
+ MEDCouplingDefinitionTime dt=fot->getDefinitionTimeZone();
+ dt.appendRepr(std::cout);
+ //
+ for(std::vector<MEDCouplingFieldDouble *>::iterator it=fs.begin();it!=fs.end();it++)
+ (*it)->decrRef();
+ fot->decrRef();
+}
TestMEDCoupling_LDFLAGS = @CPPUNIT_LIBS@ ../libmedcoupling.la ../../INTERP_KERNEL/libinterpkernel.la
dist_TestMEDCoupling_SOURCES = TestMEDCoupling.cxx MEDCouplingBasicsTest.hxx MEDCouplingBasicsTest0.cxx MEDCouplingBasicsTest1.cxx \
- MEDCouplingBasicsTest2.cxx MEDCouplingBasicsTestInterp.cxx MEDCouplingBasicsTestData1.hxx
+ MEDCouplingBasicsTest2.cxx MEDCouplingBasicsTest3.cxx MEDCouplingBasicsTestInterp.cxx MEDCouplingBasicsTestData1.hxx \
+ MEDCouplingBasicsTest4.cxx
TestMEDCouplingRemapper_CPPFLAGS=@CPPUNIT_INCLUDES@ @PTHREAD_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../../INTERP_KERNEL/Bases -I$(srcdir)/../../INTERP_KERNELTest -I$(srcdir)/../../INTERP_KERNEL -I$(srcdir)/../../INTERP_KERNEL/Geometric2D
#include "MEDCouplingFieldTemplate.hxx"
#include "MEDCouplingGaussLocalization.hxx"
#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+#include "MEDCouplingMultiFields.hxx"
+#include "MEDCouplingFieldOverTime.hxx"
+#include "MEDCouplingDefinitionTime.hxx"
#include "MEDCouplingTypemaps.i"
#include "InterpKernelAutoPtr.hxx"
$result=convertMesh($1,$owner);
}
+%typemap(out) ParaMEDMEM::MEDCouplingMultiFields*
+{
+ $result=convertMultiFields($1,$owner);
+}
+
#ifdef WITH_NUMPY2
%init %{ import_array(); %}
#endif
%newobject ParaMEDMEM::DataArrayInt::keepSelectedComponents;
%newobject ParaMEDMEM::DataArrayInt::selectByTupleId;
%newobject ParaMEDMEM::DataArrayInt::selectByTupleIdSafe;
+%newobject ParaMEDMEM::DataArrayInt::checkAndPreparePermutation;
%newobject ParaMEDMEM::DataArrayInt::renumber;
%newobject ParaMEDMEM::DataArrayInt::renumberR;
%newobject ParaMEDMEM::DataArrayInt::renumberAndReduce;
%newobject ParaMEDMEM::DataArrayDouble::fromPolarToCart;
%newobject ParaMEDMEM::DataArrayDouble::fromCylToCart;
%newobject ParaMEDMEM::DataArrayDouble::fromSpherToCart;
+%newobject ParaMEDMEM::MEDCouplingMesh::deepCpy;
%newobject ParaMEDMEM::MEDCouplingMesh::getCoordinatesAndOwner;
%newobject ParaMEDMEM::MEDCouplingMesh::getBarycenterAndOwner;
%newobject ParaMEDMEM::MEDCouplingMesh::buildOrthogonalField;
%newobject ParaMEDMEM::MEDCouplingExtrudedMesh::build3DUnstructuredMesh;
%newobject ParaMEDMEM::MEDCouplingCMesh::New;
%newobject ParaMEDMEM::MEDCouplingCMesh::getCoordsAt;
+%newobject ParaMEDMEM::MEDCouplingMultiFields::New;
+%newobject ParaMEDMEM::MEDCouplingMultiFields::deepCpy;
+%newobject ParaMEDMEM::MEDCouplingFieldOverTime::New;
+
%feature("unref") DataArrayDouble "$this->decrRef();"
%feature("unref") MEDCouplingPointSet "$this->decrRef();"
%feature("unref") MEDCouplingMesh "$this->decrRef();"
%feature("unref") DataArrayInt "$this->decrRef();"
%feature("unref") MEDCouplingField "$this->decrRef();"
%feature("unref") MEDCouplingFieldDouble "$this->decrRef();"
+%feature("unref") MEDCouplingMultiFields "$this->decrRef();"
%rename(assign) *::operator=;
%ignore ParaMEDMEM::MemArray::operator=;
class MEDCouplingMesh : public RefCountObject, public TimeLabel
{
public:
- void setName(const char *name) { _name=name; }
- const char *getName() const { return _name.c_str(); }
+ void setName(const char *name);
+ const char *getName() const;
+ void setDescription(const char *descr);
+ const char *getDescription() const;
virtual MEDCouplingMeshType getType() const throw(INTERP_KERNEL::Exception) = 0;
bool isStructured() const throw(INTERP_KERNEL::Exception);
+ virtual MEDCouplingMesh *deepCpy() const = 0;
virtual bool isEqual(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception);
virtual bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception) = 0;
virtual void copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception);
{
public:
static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=NO_TIME);
+ static MEDCouplingFieldDouble *New(const MEDCouplingFieldTemplate *ft, TypeOfTimeDiscretization td=NO_TIME);
+ void setTimeUnit(const char *unit);
+ const char *getTimeUnit() const;
void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception);
void copyTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception);
std::string simpleRepr() const;
return ret;
}
+ PyObject *getArrays() const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<DataArrayDouble *> arrs=self->getArrays();
+ for(std::vector<DataArrayDouble *>::iterator it=arrs.begin();it!=arrs.end();it++)
+ if(*it)
+ (*it)->incrRef();
+ int sz=arrs.size();
+ PyObject *ret=PyTuple_New(sz);
+ for(int i=0;i<sz;i++)
+ {
+ if(arrs[i])
+ PyTuple_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(arrs[i]),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+ else
+ PyTuple_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ));
+ }
+ return ret;
+ }
+
+ void setArrays(PyObject *ls) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const DataArrayDouble *> tmp;
+ convertPyObjToVecDataArrayDblCst(ls,tmp);
+ int sz=tmp.size();
+ std::vector<DataArrayDouble *> arrs(sz);
+ for(int i=0;i<sz;i++)
+ arrs[i]=const_cast<DataArrayDouble *>(tmp[i]);
+ self->setArrays(arrs);
+ }
+
DataArrayDouble *getEndArray() const throw(INTERP_KERNEL::Exception)
{
DataArrayDouble *ret=self->getEndArray();
{
public:
static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception);
+ std::string simpleRepr() const;
+ std::string advancedRepr() const;
+ %extend
+ {
+ std::string __str__() const
+ {
+ return self->simpleRepr();
+ }
+ }
+ };
+
+ class MEDCouplingMultiFields : public RefCountObject, public TimeLabel
+ {
+ public:
+ int getNumberOfFields() const;
+ MEDCouplingMultiFields *deepCpy() const;
+ virtual std::string simpleRepr() const;
+ virtual std::string advancedRepr() const;
+ virtual bool isEqual(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const;
+ virtual bool isEqualWithoutConsideringStr(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const;
+ virtual void checkCoherency() const throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ std::string __str__() const
+ {
+ return self->simpleRepr();
+ }
+ static MEDCouplingMultiFields *New(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const ParaMEDMEM::MEDCouplingFieldDouble *> tmp;
+ convertPyObjToVecFieldDblCst(li,tmp);
+ int sz=tmp.size();
+ std::vector<MEDCouplingFieldDouble *> fs(sz);
+ for(int i=0;i<sz;i++)
+ fs[i]=const_cast<MEDCouplingFieldDouble *>(tmp[i]);
+ return MEDCouplingMultiFields::New(fs);
+ }
+ PyObject *getFields() const
+ {
+ std::vector<const MEDCouplingFieldDouble *> fields=self->getFields();
+ int sz=fields.size();
+ PyObject *res = PyList_New(sz);
+ for(int i=0;i<sz;i++)
+ {
+ if(fields[i])
+ {
+ fields[i]->incrRef();
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(fields[i]),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ));
+ }
+ else
+ {
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, 0 ));
+ }
+ }
+ return res;
+ }
+ PyObject *getFieldAtPos(int id) const throw(INTERP_KERNEL::Exception)
+ {
+ const MEDCouplingFieldDouble *ret=self->getFieldAtPos(id);
+ if(ret)
+ {
+ ret->incrRef();
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 );
+ }
+ else
+ return SWIG_NewPointerObj(SWIG_as_voidptr(0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, 0 );
+ }
+ PyObject *getMeshes() const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<MEDCouplingMesh *> ms=self->getMeshes();
+ int sz=ms.size();
+ PyObject *res = PyList_New(sz);
+ for(int i=0;i<sz;i++)
+ {
+ if(ms[i])
+ {
+ ms[i]->incrRef();
+ PyList_SetItem(res,i,convertMesh(ms[i], SWIG_POINTER_OWN | 0 ));
+ }
+ else
+ {
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, 0 ));
+ }
+ }
+ return res;
+ }
+ PyObject *getDifferentMeshes() const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> refs;
+ std::vector<MEDCouplingMesh *> ms=self->getDifferentMeshes(refs);
+ int sz=ms.size();
+ PyObject *res = PyList_New(sz);
+ for(int i=0;i<sz;i++)
+ {
+ if(ms[i])
+ {
+ ms[i]->incrRef();
+ PyList_SetItem(res,i,convertMesh(ms[i], SWIG_POINTER_OWN | 0 ));
+ }
+ else
+ {
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, 0 ));
+ }
+ }
+ //
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,res);
+ PyTuple_SetItem(ret,1,convertIntArrToPyList2(refs));
+ return ret;
+ }
+ PyObject *getArrays() const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<DataArrayDouble *> ms=self->getArrays();
+ int sz=ms.size();
+ PyObject *res = PyList_New(sz);
+ for(int i=0;i<sz;i++)
+ {
+ if(ms[i])
+ {
+ ms[i]->incrRef();
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(ms[i]),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+ }
+ else
+ {
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 ));
+ }
+ }
+ return res;
+ }
+ PyObject *getDifferentArrays() const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector< std::vector<int> > refs;
+ std::vector<DataArrayDouble *> ms=self->getDifferentArrays(refs);
+ int sz=ms.size();
+ PyObject *res = PyList_New(sz);
+ PyObject *res2 = PyList_New(sz);
+ for(int i=0;i<sz;i++)
+ {
+ if(ms[i])
+ {
+ ms[i]->incrRef();
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(ms[i]),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+ }
+ else
+ {
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 ));
+ }
+ PyList_SetItem(res2,i,convertIntArrToPyList2(refs[i]));
+ }
+ //
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,res);
+ PyTuple_SetItem(ret,1,res2);
+ return ret;
+ }
+ }
+ };
+
+ class MEDCouplingDefinitionTime
+ {
+ public:
+ %extend
+ {
+ std::string __str__() const
+ {
+ std::ostringstream oss;
+ self->appendRepr(oss);
+ return oss.str();
+ }
+ }
+ };
+
+ class MEDCouplingFieldOverTime : public MEDCouplingMultiFields
+ {
+ public:
+ double getTimeTolerance() const throw(INTERP_KERNEL::Exception);
+ MEDCouplingDefinitionTime getDefinitionTimeZone() const;
+ %extend
+ {
+ std::string __str__() const
+ {
+ return self->simpleRepr();
+ }
+ static MEDCouplingFieldOverTime *New(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const ParaMEDMEM::MEDCouplingFieldDouble *> tmp;
+ convertPyObjToVecFieldDblCst(li,tmp);
+ int sz=tmp.size();
+ std::vector<MEDCouplingFieldDouble *> fs(sz);
+ for(int i=0;i<sz;i++)
+ fs[i]=const_cast<MEDCouplingFieldDouble *>(tmp[i]);
+ return MEDCouplingFieldOverTime::New(fs);
+ }
+ }
};
}
pass
self.assertEqual(m.getName(),"My0D");
pass
+
+ def testDescriptionInMeshTimeUnit1(self):
+ text1="totoTTEDD";
+ m=MEDCouplingDataForTest.build2DTargetMesh_1();
+ m.setDescription(text1);
+ self.assertEqual(m.getDescription(),text1);
+ m2=m.deepCpy();
+ self.assertTrue(m.isEqual(m2,1e-12));
+ self.assertEqual(m2.getDescription(),text1);
+ m2.setDescription("ggg");
+ self.assertTrue(not m.isEqual(m2,1e-12));
+ #
+ f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+ f.setTimeUnit(text1);
+ self.assertEqual(f.getTimeUnit(),text1);
+ f2=f.deepCpy();
+ self.assertEqual(f2.getTimeUnit(),text1);
+ #
+ pass
+
+ def testMultiFields1(self):
+ mfs=MEDCouplingDataForTest.buildMultiFields_1();
+ ms=mfs.getMeshes();
+ dms,refs=mfs.getDifferentMeshes()
+ das=mfs.getArrays();
+ das2,refs2=mfs.getDifferentArrays()
+ self.assertEqual(5,len(mfs.getFields()))
+ self.assertEqual(1,len(mfs.getFields()[0].getArrays()));
+ self.assertEqual(2,len(mfs.getFields()[1].getArrays()));
+ self.assertEqual(1,len(mfs.getFields()[2].getArrays()));
+ self.assertEqual(1,len(mfs.getFields()[3].getArrays()));
+ self.assertEqual(1,len(mfs.getFields()[4].getArrays()));
+ self.assertEqual(5,len(ms));
+ self.assertEqual(2,len(dms));
+ self.assertEqual(6,len(das));
+ self.assertEqual(5,len(das2));
+ mfs2=mfs.deepCpy();
+ self.assertTrue(mfs.isEqual(mfs2,1e-12,1e-12))
+ pass
def setUp(self):
pass
targetMesh.setCoords(myCoords);
return targetMesh;
+ def buildMultiFields_1(cls):
+ m1=MEDCouplingDataForTest.build2DTargetMesh_1();
+ m1.setName("m1");
+ m2=MEDCouplingDataForTest.build2DTargetMesh_1();
+ m2.setName("m2");
+ vals0=[-0.7,-1.,-2.,-3.,-4.];
+ vals1=[0.,1.,2.,3.,4.,0.1,0.2,0.3,0.4];
+ vals1_1=[170.,171.,172.,173.,174.,170.1,170.2,170.3,170.4];
+ vals2=[5.,6.,7.,8.,9.];
+ vals4=[15.,16.,17.,18.,19.];
+ d0=DataArrayDouble.New();
+ d0.setValues(vals0,5,1);
+ d1=DataArrayDouble.New();
+ d1.setValues(vals1,9,1);
+ d1_1=DataArrayDouble.New();
+ d1_1.setValues(vals1_1,9,1);
+ d2=DataArrayDouble.New();
+ d2.setValues(vals2,5,1);
+ d4=DataArrayDouble.New();
+ d4.setValues(vals4,5,1);
+ d0.setName("d0"); d1.setName("d1"); d1_1.setName("d1_1"); d2.setName("d2"); d4.setName("d4");
+ d0.setInfoOnComponent(0,"c1");
+ d1.setInfoOnComponent(0,"c6");
+ d1_1.setInfoOnComponent(0,"c9");
+ d2.setInfoOnComponent(0,"c5");
+ d4.setInfoOnComponent(0,"c7");
+ f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+ f0.setMesh(m1);
+ f0.setArray(d0);
+ f0.setTime(0.2,5,6);
+ f0.setName("f0");
+ f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
+ f1.setMesh(m1);
+ f1.setArrays([d1,d1_1]);
+ f1.setStartTime(0.7,7,8);
+ f1.setEndTime(1.2,9,10);
+ f1.setName("f1");
+ f2=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
+ f2.setMesh(m2);
+ f2.setArray(d2);
+ f2.setTime(1.2,11,12);
+ f2.setEndTime(1.5,13,14);
+ f2.setName("f2");
+ f3=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+ f3.setMesh(m1);
+ f3.setArray(d2);
+ f3.setTime(1.7,15,16);
+ f3.setName("f3");
+ f4=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
+ f4.setMesh(m2);
+ f4.setArray(d4);
+ f4.setName("f4");
+ ret=MEDCouplingMultiFields.New([f0,f1,f2,f3,f4]);
+ return ret;
+
build2DTargetMesh_1=classmethod(build2DTargetMesh_1)
build2DSourceMesh_1=classmethod(build2DSourceMesh_1)
build3DTargetMesh_1=classmethod(build3DTargetMesh_1)
build2DCurveTargetMesh_3=classmethod(build2DCurveTargetMesh_3)
build2DTargetMesh_3=classmethod(build2DTargetMesh_3)
build2DTargetMesh_4=classmethod(build2DTargetMesh_4)
+ buildMultiFields_1=classmethod(buildMultiFields_1)
pass
return ret;
}
+static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
+{
+ PyObject *ret=0;
+ if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
+ ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
+ else
+ ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
+ return ret;
+}
+
static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
{
#ifndef WITH_NUMPY2