self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(1,0.25),(1,0.44444444444444442),(1,0.59999999999999998),(1,0.72727272727272729),(1,0.83333333333333337)]),1e-12))
self.assertRaises(InterpKernelException,f.__rdiv__,f2)
pass
+
+ def testSwig2FieldDoubleBuildSubPartRange1(self):
+ #ON_CELLS
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2) ; arr[:,0]=range(7,12) ; arr[:,1]=100+arr[:,0]
+ f.setArray(arr)
+ f.checkCoherency()
+ ff=f[1:-1:2]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(2,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[1,3]],1e-12))
+ #
+ a,b=f.buildSubMeshDataRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
+ self.assertEqual(b,slice(2,5,1))
+ ff=f[2:]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[2,3,4]],1e-12))
+ #
+ ff=f[-2:0:-1]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[3,2,1]],1e-12))
+ self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[3,2,1],1],1e-12))
+ #ON_NODES
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setMesh(m)
+ arr=DataArrayDouble(9,2) ; arr[:,0]=range(7,16) ; arr[:,1]=100+arr[:,0]
+ f.setArray(arr)
+ f.checkCoherency()
+ ff=f[1:-1:2]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([1,3],False)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(6,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(2,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,6,7]],1e-12))
+ #
+ m2=m.buildPartRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(m2,1e-12))
+ m2,b=m.buildPartRangeAndReduceNodes(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(m2,1e-12))
+ self.assertTrue(b.isEqual(DataArrayInt([-1,-1,0,1,2,3,4,5,6])))
+ a,b=f.buildSubMeshDataRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(a,1e-12))
+ self.assertTrue(b.isEqual(DataArrayInt([2,3,4,5,6,7,8])))
+ ff=f[2:]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([2,3,4],False)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(7,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,6,7,8]],1e-12))
+ #
+ ff=f[-2:0:-1]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([3,2,1],False)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(7,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,5,6,7]],1e-12))
+ self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[1,2,3,4,5,6,7],1],1e-12))
+ #ON_GAUSS_NE
+ f=MEDCouplingFieldDouble(ON_GAUSS_NE)
+ f.setMesh(m)
+ arr=DataArrayDouble(18,2) ; arr[:,0]=range(7,25) ; arr[:,1]=100+arr[:,0]
+ f.setArray(arr)
+ f.checkCoherency()
+ ff=f[1:-1:2]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(2,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[4,5,6,10,11,12,13]],1e-12))
+ #
+ a,b=f.buildSubMeshDataRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
+ self.assertEqual(b,slice(7,18,1))
+ ff=f[2:]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[7,8,9,10,11,12,13,14,15,16,17]],1e-12))
+ #
+ ff=f[-2:0:-1]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6]],1e-12))
+ self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6],1],1e-12))
+ #ON_GAUSS_PT
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT)
+ f.setMesh(m)
+ f.setGaussLocalizationOnCells([0,4],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2],[0.2,0.8]);
+ f.setGaussLocalizationOnCells([3],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2,3.,3.],[0.2,0.4,0.4]);
+ f.setGaussLocalizationOnCells([1],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.],[0.1,0.1,0.4,0.4]);
+ f.setGaussLocalizationOnCells([2],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.,5.,5.],[0.1,0.1,0.4,0.3,0.1]);
+ arr=DataArrayDouble(16,2) ; arr[:,0]=range(7,23) ; arr[:,1]=100+arr[:,0]
+ f.setArray(arr)
+ f.checkCoherency()
+ ff=f[1:-1:2]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(2,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,11,12,13]],1e-12))
+ #
+ a,b=f.buildSubMeshDataRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
+ self.assertEqual(b,slice(6,16,1))
+ ff=f[2:]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[6,7,8,9,10,11,12,13,14,15]],1e-12))
+ #
+ ff=f[-2:0:-1]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5]],1e-12))
+ self.assertTrue(f[-2:0:-1,0].getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5],0],1e-12))
+ pass
def setUp(self):
pass
%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::deepCpy;
%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clone;
%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart;
+%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clonePartRange;
%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getMeasureField;
%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getOffsetArr;
%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getLocalizationOfDiscValues;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::negate;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::getIdsInRange;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart;
+%newobject ParaMEDMEM::MEDCouplingFieldDouble::buildSubPartRange;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::__getitem__;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::__neg__;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::__add__;
%newobject ParaMEDMEM::MEDCouplingMesh::checkDeepEquivalOnSameNodesWith;
%newobject ParaMEDMEM::MEDCouplingMesh::checkTypeConsistencyAndContig;
%newobject ParaMEDMEM::MEDCouplingMesh::computeNbOfNodesPerCell;
+%newobject ParaMEDMEM::MEDCouplingMesh::buildPartRange;
%newobject ParaMEDMEM::MEDCouplingMesh::giveCellsWithType;
%newobject ParaMEDMEM::MEDCouplingMesh::getCoordinatesAndOwner;
%newobject ParaMEDMEM::MEDCouplingMesh::getBarycenterAndOwner;
virtual DataArrayDouble *computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception);
virtual DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception);
virtual DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception);
+ virtual MEDCouplingMesh *buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception);
virtual int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception);
virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception);
virtual std::string simpleRepr() const throw(INTERP_KERNEL::Exception);
return res;
}
+ PyObject *buildPartRangeAndReduceNodes(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception)
+ {
+ int a,b,c;
+ DataArrayInt *arr=0;
+ MEDCouplingMesh *ret=self->buildPartRangeAndReduceNodes(beginCellIds,endCellIds,stepCellIds,a,b,c,arr);
+ PyObject *res = PyTuple_New(2);
+ PyObject *obj0=convertMesh(ret, SWIG_POINTER_OWN | 0 );
+ PyObject *obj1=0;
+ if(arr)
+ obj1=SWIG_NewPointerObj(SWIG_as_voidptr(arr),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
+ else
+ obj1=PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(b));
+ PyTuple_SetItem(res,0,obj0);
+ PyTuple_SetItem(res,1,obj1);
+ return res;
+ }
+
PyObject *getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
{
std::vector<int> vals=self->getDistributionOfTypes();
%include "MEDCouplingFieldDiscretization.hxx"
%ignore ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart;
+%ignore ParaMEDMEM::MEDCouplingFieldDiscretization::buildSubMeshDataRange;
%ignore ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds;
namespace ParaMEDMEM
const int *inp=convertObjToPossibleCpp1_Safe(li,sw,sz,val1,val2);
return self->clonePart(inp,inp+sz);
}
+
+ PyObject *buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *ret1=0;
+ int bb,ee,ss;
+ MEDCouplingMesh *ret0=self->buildSubMeshDataRange(mesh,begin,end,step,bb,ee,ss,ret1);
+ PyObject *res=PyTuple_New(2);
+ PyTuple_SetItem(res,0,convertMesh(ret0, SWIG_POINTER_OWN | 0 ));
+ if(ret1)
+ PyTuple_SetItem(res,1,SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0));
+ else
+ {
+ PyObject *res1=PySlice_New(PyInt_FromLong(bb),PyInt_FromLong(ee),PyInt_FromLong(ss));
+ PyTuple_SetItem(res,1,res1);
+ }
+ return res;
+ }
PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception)
{
return res;
}
+ PyObject *buildSubMeshDataRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *ret1=0;
+ int bb,ee,ss;
+ MEDCouplingMesh *ret0=self->buildSubMeshDataRange(begin,end,step,bb,ee,ss,ret1);
+ PyObject *res=PyTuple_New(2);
+ PyTuple_SetItem(res,0,convertMesh(ret0, SWIG_POINTER_OWN | 0 ));
+ if(ret1)
+ PyTuple_SetItem(res,1,SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0));
+ else
+ {
+ PyObject *res1=PySlice_New(PyInt_FromLong(bb),PyInt_FromLong(ee),PyInt_FromLong(ss));
+ PyTuple_SetItem(res,1,res1);
+ }
+ return res;
+ }
+
DataArrayInt *computeTupleIdsToSelectFromCellIds(PyObject *li) const
{
int sw;
double normL1(int compId) const throw(INTERP_KERNEL::Exception);
double normL2(int compId) const throw(INTERP_KERNEL::Exception);
DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldDouble *buildSubPartRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception);
static MEDCouplingFieldDouble *MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception);
static MEDCouplingFieldDouble *MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception);
static MEDCouplingFieldDouble *DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception);
}
case 3:
{
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rg=DataArrayInt::Range(slic.first,slic.second.first,slic.second.second);
- return self->buildSubPart(rg->begin(),rg->end());
+ return self->buildSubPartRange(slic.first,slic.second.first,slic.second.second);
}
case 4:
{
case 1:
{
std::vector<int> v2(1,singleVal);
- ret0->setArray(ret0Arr->keepSelectedComponents(v2));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aarr=ret0Arr->keepSelectedComponents(v2);
+ ret0->setArray(aarr);
return ret0.retn();
}
case 2:
{
- ret0->setArray(ret0Arr->keepSelectedComponents(multiVal));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aarr=ret0Arr->keepSelectedComponents(multiVal);
+ ret0->setArray(aarr);
return ret0.retn();
}
case 3:
std::vector<int> v2(nbOfComp);
for(int i=0;i<nbOfComp;i++)
v2[i]=slic.first+i*slic.second.second;
- ret0->setArray(ret0Arr->keepSelectedComponents(v2));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aarr=ret0Arr->keepSelectedComponents(v2);
+ ret0->setArray(aarr);
return ret0.retn();
}
default: