From: ageay Date: Thu, 30 Jun 2011 08:25:26 +0000 (+0000) Subject: Dealing with profiles. X-Git-Tag: V6_3_1rc1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=032262d6481250030502b7c4f727535bdee343d4;p=tools%2Fmedcoupling.git Dealing with profiles. --- diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index f60cd6015..6e564d28d 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -537,7 +537,7 @@ DataArrayInt *MEDCouplingCMesh::checkTypeConsistencyAndContig(const std::vector< /*! * See MEDCouplingUMesh::splitProfilePerType for more information */ -void MEDCouplingCMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +void MEDCouplingCMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) { int nbCells=getNumberOfCells(); code.resize(3); @@ -545,6 +545,7 @@ void MEDCouplingCMesh::splitProfilePerType(const DataArrayInt *profile, std::vec code[1]=nbCells; code[2]=0; idsPerType.push_back(profile->deepCpy()); + globIdsPerType.push_back(profile->deepCpy()); } MEDCouplingUMesh *MEDCouplingCMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index c18554e85..45d81d1a0 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -68,7 +68,7 @@ namespace ParaMEDMEM const DataArrayDouble *coordsZ=0); // tools DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); - void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); + void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception); MEDCouplingMesh *buildPart(const int *start, const int *end) const; MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const; diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 105577dbe..8ecb61a38 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -606,7 +606,7 @@ DataArrayInt *MEDCouplingExtrudedMesh::checkTypeConsistencyAndContig(const std:: throw INTERP_KERNEL::Exception("Not implemented yet !"); } -void MEDCouplingExtrudedMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +void MEDCouplingExtrudedMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception("Not implemented yet !"); } diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 65e08e7e3..692f813a5 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -81,7 +81,7 @@ namespace ParaMEDMEM void translate(const double *vector); void scale(const double *point, double factor); DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); - void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); + void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCouplingMesh *buildPart(const int *start, const int *end) const; MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const; DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 11193f773..283d5fc39 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -90,7 +90,7 @@ namespace ParaMEDMEM virtual std::string advancedRepr() const = 0; // tools virtual DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) = 0; - virtual void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) = 0; + virtual void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) = 0; virtual void getBoundingBox(double *bbox) const = 0; virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0; virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const = 0; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 19c8de91b..307e376c3 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -3421,7 +3421,7 @@ DataArrayInt *MEDCouplingUMesh::checkTypeConsistencyAndContig(const std::vector< * This method has 1 input 'profile' and 2 outputs 'code' and 'idsPerType'. * @throw if 'profile' has not exactly one component. It throws too, if 'profile' contains some values not in [0,getNumberOfCells()) or if 'this' is not fully defined */ -void MEDCouplingUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +void MEDCouplingUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) { if(profile->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::splitProfilePerType : input profile should have exactly one component !"); @@ -3451,16 +3451,19 @@ void MEDCouplingUMesh::splitProfilePerType(const DataArrayInt *profile, std::vec // int nbOfCastsFinal=castsPresent->getNumberOfTuples(); code.resize(3*nbOfCastsFinal); + std::vector< MEDCouplingAutoRefCountObjectPtr > globIdsPerType2; std::vector< MEDCouplingAutoRefCountObjectPtr > idsPerType2; for(int i=0;igetIJ(i,0); MEDCouplingAutoRefCountObjectPtr tmp3=castArr->getIdsEqual(castId); + globIdsPerType2.push_back(tmp3); code[3*i]=(int)types[castId]; code[3*i+1]=tmp3->getNumberOfTuples(); MEDCouplingAutoRefCountObjectPtr tmp4=rankInsideCast->selectByTupleId(tmp3->getConstPointer(),tmp3->getConstPointer()+tmp3->getNumberOfTuples()); if(tmp4->getNumberOfTuples()!=typeRangeVals[castId+1]-typeRangeVals[castId] || !tmp4->isIdentity()) { + tmp4->copyStringInfoFrom(*profile); idsPerType2.push_back(tmp4); code[3*i+2]=(int)idsPerType2.size()-1; } @@ -3469,6 +3472,14 @@ void MEDCouplingUMesh::splitProfilePerType(const DataArrayInt *profile, std::vec code[3*i+2]=-1; } } + int sz2=globIdsPerType2.size(); + globIdsPerType.resize(sz2); + for(int i=0;iincrRef(); + globIdsPerType[i]=locDa; + } int sz=idsPerType2.size(); idsPerType.resize(sz); for(int i=0;i& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCouplingUMesh *emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh, DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *&revDesc, DataArrayInt *&revDescIndx, DataArrayInt *& nM1LevMeshIds, DataArrayInt *&meshnM1Old2New) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *sortCellsInMEDFileFrmt() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool checkConsecutiveCellTypes() const; diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 872b793e5..1942ca1bc 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -194,7 +194,7 @@ DataArrayInt *MEDCouplingUMeshDesc::checkTypeConsistencyAndContig(const std::vec throw INTERP_KERNEL::Exception("Not implemented yet !"); } -void MEDCouplingUMeshDesc::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +void MEDCouplingUMeshDesc::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception("Not implemented yet !"); } diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index 86dcf63aa..7a7aeaee6 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -58,7 +58,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx); //tools to overload MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& globIdsPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const; MEDCOUPLING_EXPORT bool isEmptyMesh(const std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 8fc38677a..dbaf613f0 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1313,26 +1313,39 @@ void MEDCouplingBasicsTest::testUMeshSplitProfilePerType1() MEDCouplingUMesh *m=build2DTargetMesh_1(); m->renumberCells(val0,false); std::vector code; + std::vector globIdsPerType; std::vector pfls; // const int val1[3]={0,2,3}; DataArrayInt *d=DataArrayInt::New(); d->alloc(3,1); + d->setName("sup"); std::copy(val1,val1+3,d->getPointer()); - m->splitProfilePerType(d,code,pfls); + m->splitProfilePerType(d,code,globIdsPerType,pfls); CPPUNIT_ASSERT_EQUAL(6,(int)code.size()); + CPPUNIT_ASSERT_EQUAL(2,(int)globIdsPerType.size()); const int expected1[6]={3,1,0, 4,2,1}; for(int i=0;i<6;i++) CPPUNIT_ASSERT_EQUAL(expected1[i],code[i]); + CPPUNIT_ASSERT_EQUAL(1,globIdsPerType[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,globIdsPerType[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(2,globIdsPerType[1]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,globIdsPerType[1]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(2,globIdsPerType[1]->getIJ(1,0)); + globIdsPerType[0]->decrRef(); + globIdsPerType[1]->decrRef(); CPPUNIT_ASSERT_EQUAL(2,(int)pfls.size()); + CPPUNIT_ASSERT(std::string("sup")==pfls[0]->getName()); CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(0,pfls[0]->getIJ(0,0)); + CPPUNIT_ASSERT(std::string("sup")==pfls[1]->getName()); CPPUNIT_ASSERT_EQUAL(2,pfls[1]->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(0,pfls[1]->getIJ(0,0)); CPPUNIT_ASSERT_EQUAL(1,pfls[1]->getIJ(1,0)); pfls[0]->decrRef(); pfls[1]->decrRef(); d->decrRef(); + globIdsPerType.clear(); pfls.clear(); code.clear(); // @@ -1340,16 +1353,26 @@ void MEDCouplingBasicsTest::testUMeshSplitProfilePerType1() d=DataArrayInt::New(); d->alloc(4,1); std::copy(val2,val2+4,d->getPointer()); - m->splitProfilePerType(d,code,pfls); + m->splitProfilePerType(d,code,globIdsPerType,pfls); CPPUNIT_ASSERT_EQUAL(6,(int)code.size()); + CPPUNIT_ASSERT_EQUAL(2,(int)globIdsPerType.size()); const int expected2[6]={3,1,0, 4,3,-1}; for(int i=0;i<6;i++) CPPUNIT_ASSERT_EQUAL(expected2[i],code[i]); + CPPUNIT_ASSERT_EQUAL(1,globIdsPerType[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,globIdsPerType[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(3,globIdsPerType[1]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,globIdsPerType[1]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(2,globIdsPerType[1]->getIJ(1,0)); + CPPUNIT_ASSERT_EQUAL(3,globIdsPerType[1]->getIJ(2,0)); + globIdsPerType[0]->decrRef(); + globIdsPerType[1]->decrRef(); CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size()); CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(0,pfls[0]->getIJ(0,0)); pfls[0]->decrRef(); d->decrRef(); + globIdsPerType.clear(); pfls.clear(); code.clear(); // @@ -1357,11 +1380,19 @@ void MEDCouplingBasicsTest::testUMeshSplitProfilePerType1() d=DataArrayInt::New(); d->alloc(3,1); std::copy(val3,val3+3,d->getPointer()); - m->splitProfilePerType(d,code,pfls); + m->splitProfilePerType(d,code,globIdsPerType,pfls); CPPUNIT_ASSERT_EQUAL(6,(int)code.size()); + CPPUNIT_ASSERT_EQUAL(2,(int)globIdsPerType.size()); const int expected3[6]={3,2,0, 4,1,1}; for(int i=0;i<6;i++) CPPUNIT_ASSERT_EQUAL(expected3[i],code[i]); + CPPUNIT_ASSERT_EQUAL(2,globIdsPerType[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,globIdsPerType[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(1,globIdsPerType[0]->getIJ(1,0)); + CPPUNIT_ASSERT_EQUAL(1,globIdsPerType[1]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(2,globIdsPerType[1]->getIJ(0,0)); + globIdsPerType[0]->decrRef(); + globIdsPerType[1]->decrRef(); CPPUNIT_ASSERT_EQUAL(2,(int)pfls.size()); CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getIJ(0,0)); @@ -1370,6 +1401,7 @@ void MEDCouplingBasicsTest::testUMeshSplitProfilePerType1() pfls[0]->decrRef(); pfls[1]->decrRef(); d->decrRef(); + globIdsPerType.clear(); pfls.clear(); code.clear(); // @@ -1377,17 +1409,23 @@ void MEDCouplingBasicsTest::testUMeshSplitProfilePerType1() d=DataArrayInt::New(); d->alloc(2,1); std::copy(val4,val4+2,d->getPointer()); - m->splitProfilePerType(d,code,pfls); + m->splitProfilePerType(d,code,globIdsPerType,pfls); CPPUNIT_ASSERT_EQUAL(3,(int)code.size()); + CPPUNIT_ASSERT_EQUAL(1,(int)globIdsPerType.size()); const int expected4[3]={4,2,0}; for(int i=0;i<3;i++) CPPUNIT_ASSERT_EQUAL(expected4[i],code[i]); + CPPUNIT_ASSERT_EQUAL(2,globIdsPerType[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,globIdsPerType[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(1,globIdsPerType[0]->getIJ(1,0)); + globIdsPerType[0]->decrRef(); CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size()); CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getIJ(0,0)); CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getIJ(1,0)); pfls[0]->decrRef(); d->decrRef(); + globIdsPerType.clear(); pfls.clear(); code.clear(); // diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 65261b0c8..e6e37f2cd 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -565,6 +565,26 @@ namespace ParaMEDMEM return self->checkTypeConsistencyAndContig(code,idsPerType); } + PyObject *splitProfilePerType(const DataArrayInt *profile) const throw(INTERP_KERNEL::Exception) + { + std::vector code; + std::vector globIdsPerType; + std::vector idsPerType; + self->splitProfilePerType(profile,code,globIdsPerType,idsPerType); + PyObject *ret=PyTuple_New(3); + PyTuple_SetItem(ret,0,convertIntArrToPyList2(code)); + PyObject *ret1=PyList_New(globIdsPerType.size()); + for(std::size_t j=0;j tmp=convertPyToNewIntArr2(li,&size); + self->splitByValueRange(tmp,(int *)tmp+size,ret0,ret1,ret2); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + self->splitByValueRange(da2->getConstPointer(),da2->getConstPointer()+size,ret0,ret1,ret2); + } + PyObject *ret = PyList_New(3); + PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + DataArrayInt *transformWithIndArrR(PyObject *li) const { void *da=0; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 391a5036d..201362cba 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -7402,6 +7402,122 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected[i],d3.getIJ(i,0)); pass pass + + def testDAISplitByValueRange1(self): + val1=[6,5,0,3,2,7,8,1,4] + val2=[0,4,9] + d=DataArrayInt.New(); + d.setValues(val1,9,1); + e,f,g=d.splitByValueRange(val2); + self.assertEqual(9,e.getNumberOfTuples()); + self.assertEqual(1,e.getNumberOfComponents()); + self.assertEqual(9,f.getNumberOfTuples()); + self.assertEqual(1,f.getNumberOfComponents()); + self.assertEqual(2,g.getNumberOfTuples()); + self.assertEqual(1,g.getNumberOfComponents()); + # + expected1=[1,1,0,0,0,1,1,0,1] + expected2=[2,1,0,3,2,3,4,1,0] + for i in xrange(9): + self.assertEqual(expected1[i],e.getIJ(i,0)); + self.assertEqual(expected2[i],f.getIJ(i,0)); + pass + self.assertEqual(0,g.getIJ(0,0)); + self.assertEqual(1,g.getIJ(1,0)); + # + d.setIJ(6,0,9); + self.assertRaises(InterpKernelException,d.splitByValueRange,val2); + pass + + def testUMeshSplitProfilePerType1(self): + val0=[2,0,1,3,4] + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + m.renumberCells(val0,False); + # + val1=[0,2,3] + d=DataArrayInt.New(); + d.setValues(val1,3,1); + d.setName("sup") + code,globIdsPerType,pfls=m.splitProfilePerType(d); + self.assertEqual(6,len(code)); + self.assertEqual(2,len(globIdsPerType)); + expected1=[3,1,0, 4,2,1] + for i in xrange(6): + self.assertEqual(expected1[i],code[i]); + pass + self.assertEqual(1,globIdsPerType[0].getNumberOfTuples()); + self.assertEqual(0,globIdsPerType[0].getIJ(0,0)); + self.assertEqual(2,globIdsPerType[1].getNumberOfTuples()); + self.assertEqual(1,globIdsPerType[1].getIJ(0,0)); + self.assertEqual(2,globIdsPerType[1].getIJ(1,0)); + self.assertEqual(2,len(pfls)); + self.assertEqual("sup",pfls[0].getName()) + self.assertEqual(1,pfls[0].getNumberOfTuples()); + self.assertEqual(0,pfls[0].getIJ(0,0)); + self.assertEqual("sup",pfls[1].getName()) + self.assertEqual(2,pfls[1].getNumberOfTuples()); + self.assertEqual(0,pfls[1].getIJ(0,0)); + self.assertEqual(1,pfls[1].getIJ(1,0)); + # + val2=[0,2,3,4] + d=DataArrayInt.New(); + d.setValues(val2,4,1); + code,globIdsPerType,pfls=m.splitProfilePerType(d); + self.assertEqual(6,len(code)); + self.assertEqual(2,len(globIdsPerType)); + expected2=[3,1,0, 4,3,-1] + for i in xrange(6): + self.assertEqual(expected2[i],code[i]); + pass + self.assertEqual(1,globIdsPerType[0].getNumberOfTuples()); + self.assertEqual(0,globIdsPerType[0].getIJ(0,0)); + self.assertEqual(3,globIdsPerType[1].getNumberOfTuples()); + self.assertEqual(1,globIdsPerType[1].getIJ(0,0)); + self.assertEqual(2,globIdsPerType[1].getIJ(1,0)); + self.assertEqual(3,globIdsPerType[1].getIJ(2,0)); + self.assertEqual(1,len(pfls)); + self.assertEqual(1,pfls[0].getNumberOfTuples()); + self.assertEqual(0,pfls[0].getIJ(0,0)); + # + val3=[1,0,2] + d=DataArrayInt.New(); + d.setValues(val3,3,1); + code,globIdsPerType,pfls=m.splitProfilePerType(d); + self.assertEqual(6,len(code)); + self.assertEqual(2,len(globIdsPerType)); + expected3=[3,2,0, 4,1,1] + for i in xrange(6): + self.assertEqual(expected3[i],code[i]); + pass + self.assertEqual(2,globIdsPerType[0].getNumberOfTuples()); + self.assertEqual(0,globIdsPerType[0].getIJ(0,0)); + self.assertEqual(1,globIdsPerType[0].getIJ(1,0)); + self.assertEqual(1,globIdsPerType[1].getNumberOfTuples()); + self.assertEqual(2,globIdsPerType[1].getIJ(0,0)); + self.assertEqual(2,len(pfls)); + self.assertEqual(2,pfls[0].getNumberOfTuples()); + self.assertEqual(1,pfls[0].getIJ(0,0)); + self.assertEqual(0,pfls[0].getIJ(1,0)); + self.assertEqual(0,pfls[1].getIJ(0,0)); + # + val4=[3,4] + d=DataArrayInt.New(); + d.setValues(val4,2,1); + code,globIdsPerType,pfls=m.splitProfilePerType(d); + self.assertEqual(3,len(code)); + self.assertEqual(1,len(globIdsPerType)); + expected4=[4,2,0] + for i in xrange(3): + self.assertEqual(expected4[i],code[i]); + pass + self.assertEqual(2,globIdsPerType[0].getNumberOfTuples()); + self.assertEqual(0,globIdsPerType[0].getIJ(0,0)); + self.assertEqual(1,globIdsPerType[0].getIJ(1,0)); + self.assertEqual(1,len(pfls)); + self.assertEqual(2,pfls[0].getNumberOfTuples()); + self.assertEqual(1,pfls[0].getIJ(0,0)); + self.assertEqual(2,pfls[0].getIJ(1,0)); + pass def setUp(self): pass diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index e5832ec7e..9f2ab9a9d 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -163,6 +163,40 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int offset, int nbO } } +void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(const char *pflName, const DataArrayInt *globIds, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +{ + if(pflName) + _profile=pflName; + else + _profile.clear(); + _type=field->getTypeOfField(); + const DataArrayDouble *da=field->getArray(); + switch(_type) + { + case ON_CELLS: + { + _nval=globIds->getNumberOfTuples(); + _arr=da->selectByTupleId(globIds->getConstPointer(),globIds->getConstPointer()+_nval); + break; + } + case ON_GAUSS_NE: + { + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for profiles on gauss NE points !"); + /*MEDCouplingAutoRefCountObjectPtr arr=field->getDiscretization()->getOffsetArr(field->getMesh()); + const int *arrPtr=arr->getConstPointer(); + _nval=nbOfCells; + _arr=da->selectByTupleId(arrPtr[offset],arrPtr[offset+nbOfCells],1); + break;*/ + } + case ON_GAUSS_PT: + { + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for profiles on gauss points !"); + } + default: + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !"); + } +} + void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) { _arr=field->getArray()->deepCpy(); @@ -342,6 +376,30 @@ void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int offset, int nbOfCells, _field_pm_pt_pd[*it]->assignFieldNoProfile(offset,nbOfCells,field,glob); } +void MEDFileFieldPerMeshPerType::assignFieldProfile(const DataArrayInt *globIds, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +{ + std::vector pos=addNewEntryIfNecessary(field,globIds); + if(locIds) + { + // + std::string pflName(locIds->getName()); + if(pflName.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignFieldProfile : existing profile with empty name !"); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); + std::ostringstream oss; oss << locIds->getName() << "_" << cm.getRepr(); + locIds->setName(oss.str().c_str()); + glob.appendProfile(locIds); + // + for(std::vector::const_iterator it=pos.begin();it!=pos.end();it++) + _field_pm_pt_pd[*it]->assignFieldProfile(oss.str().c_str(),globIds,field,glob); + } + else + { + for(std::vector::const_iterator it=pos.begin();it!=pos.end();it++) + _field_pm_pt_pd[*it]->assignFieldProfile(0,globIds,field,glob); + } +} + void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) { _field_pm_pt_pd.resize(1); @@ -419,6 +477,76 @@ std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const M return ret; } +std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception) +{ + TypeOfField type=field->getTypeOfField(); + if(type!=ON_GAUSS_PT) + { + int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0); + int sz=_field_pm_pt_pd.size(); + bool found=false; + for(int j=0;jgetLocId()==locIdToFind) + { + _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind); + found=true; + } + } + if(!found) + { + _field_pm_pt_pd.resize(sz+1); + _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind); + } + std::vector ret(1,0); + return ret; + } + else + { + std::vector ret2=addNewEntryIfNecessaryGauss(field,subCells); + int sz2=ret2.size(); + std::vector ret3(sz2); + int k=0; + for(int i=0;igetLocId()==locIdToFind) + { + _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind); + ret3[k++]=j; + found=true; + } + } + if(!found) + { + _field_pm_pt_pd.resize(sz+1); + _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind); + ret3[k++]=sz; + } + } + return ret3; + } +} + +std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception) +{ + const MEDCouplingFieldDiscretization *disc=field->getDiscretization(); + const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast(disc); + if(!disc2) + throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !"); + const DataArrayInt *da=disc2->getArrayOfDiscIds(); + MEDCouplingAutoRefCountObjectPtr da2=da->selectByTupleId(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples()); + std::set retTmp=da2->getDifferentValues(); + if(retTmp.find(-1)!=retTmp.end()) + throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !"); + std::vector ret(retTmp.begin(),retTmp.end()); + return ret; +} + const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const { return _father; @@ -574,7 +702,25 @@ void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(IN mesh->getTime(_mesh_iteration,_mesh_order); } -void MEDFileFieldPerMesh::assignFieldNoProfile(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMesh::assignFieldProfile(const std::vector& code, const std::vector& globIdsPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +{ + int nbOfTypes=code.size()/3; + bool isProfile=false; + for(int i=0;i& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) { int nbOfTypes=code.size()/3; int offset=0; @@ -588,6 +734,23 @@ void MEDFileFieldPerMesh::assignFieldNoProfile(const std::vector& code, con } } +/*! + * This method is the most general one. No optimization is done here. + */ +void MEDFileFieldPerMesh::assignFieldProfileGeneral(const std::vector& code, const std::vector& globIdsPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +{ + int nbOfTypes=code.size()/3; + for(int i=0;iassignFieldProfile(globIdsPerType[i],pfl,field,glob); + } +} + void MEDFileFieldPerMesh::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) { int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR); @@ -1032,14 +1195,14 @@ void MEDFieldFieldGlobs::setFileName(const char *fileName) int MEDFieldFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception) { - if(locId<0 || locId>=_locs.size()) + if(locId<0 || locId>=(int)_locs.size()) throw INTERP_KERNEL::Exception("MEDFieldFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !"); return _locs[locId]->getNbOfGaussPtPerCell(); } const MEDFileFieldLoc& MEDFieldFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception) { - if(locId<0 || locId>=_locs.size()) + if(locId<0 || locId>=(int)_locs.size()) throw INTERP_KERNEL::Exception("MEDFieldFieldGlobs::getLocalizationFromId : Invalid localization id !"); return *_locs[locId]; } @@ -1184,7 +1347,7 @@ std::vector MEDFileField1TSWithoutDAS::CheckSBTMesh(const MEDCouplingMesh * int nbCells=mesh->getNumberOfCellsWithType(*it); code[3*pos]=(int)(*it); code[3*pos+1]=nbCells; - code[3*pos+2]=0;//no profiles + code[3*pos+2]=-1;//no profiles } std::vector idsPerType;//no profiles DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType); @@ -1318,29 +1481,57 @@ void MEDFileField1TSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERNEL:: /*! * SBT means Sort By Type. * This method is the most basic method to assign field in this. Basic in sense that no renumbering is done. Underlying mesh in 'field' is globaly ignored except for type contiguous check. - * */ void MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) { const MEDCouplingMesh *mesh=field->getMesh(); // TypeOfField type=field->getTypeOfField(); + std::vector dummy; + copyTinyInfoFrom(field); if(type!=ON_NODES) { std::vector code=MEDFileField1TSWithoutDAS::CheckSBTMesh(mesh); - copyTinyInfoFrom(field); // int pos=addNewEntryIfNecessary(mesh); - _field_per_mesh[pos]->assignFieldNoProfile(code,field,glob); + _field_per_mesh[pos]->assignFieldProfile(code,dummy,dummy,field,glob); } else { - copyTinyInfoFrom(field); int pos=addNewEntryIfNecessary(mesh); _field_per_mesh[pos]->assignNodeFieldNoProfile(field,glob); } } +/*! + * Generalization of MEDFileField1TSWithoutDAS::setFieldNoProfileSBT method. + */ +void MEDFileField1TSWithoutDAS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +{ + TypeOfField type=field->getTypeOfField(); + copyTinyInfoFrom(field); + if(type!=ON_NODES) + { + std::vector code; + std::vector globIdsPerType; + std::vector idsPerType; + MEDCouplingAutoRefCountObjectPtr m=mesh->getGenMeshAtLevel(meshDimRelToMax); + m->splitProfilePerType(profile,code,globIdsPerType,idsPerType); + // + std::vector< MEDCouplingAutoRefCountObjectPtr > globIdsPerType2(globIdsPerType.size()); + for(std::size_t i=0;i > idsPerType2(idsPerType.size()); + for(std::size_t i=0;iassignFieldProfile(code,globIdsPerType,idsPerType,field,glob); + } + else + throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::setFieldProfile : not implemented yet !"); +} + MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) { MEDCouplingAutoRefCountObjectPtr mm; @@ -1492,6 +1683,8 @@ void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_K MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str); MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str); } + if(_name.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !"); MEDfieldCr(fid,_name.c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()); writeGlobals(fid,*this); writeLL(fid); @@ -1638,6 +1831,20 @@ void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(field,*this); } +/*! + * This method is a generalization of MEDFileField1TS::setFieldNoProfileSBT method. Here a profile array is given in input. + * The support of field 'field' is \b not used by this method, so it can be null or incoherent with field. + * This method uses input parameters 'mesh', 'meshDimRelToMax' and 'profile' to determine what is really the support of field 'field'. If field is incoherent regarding this deduced support, + * an exception will be thrown. + * This method is trying to reduce the size of MEDfile file so profile is created only if it is absolutely necessary. If it is necessary the name of 'profile' will be used to create it in 'this'. + * In this case, if this profile name is empty an exception will be thrown. + */ +void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception) +{ + _file_name=""; + MEDFileField1TSWithoutDAS::setFieldProfile(field,mesh,meshDimRelToMax,profile,*this); +} + MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) { return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos,nbOfStep); @@ -1748,6 +1955,8 @@ void MEDFileFieldMultiTSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERN MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str); MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str); } + if(_name.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::write : MED file does not accept field with empty name !"); MEDfieldCr(fid,_name.c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()); int nbOfTS=_time_steps.size(); for(int i=0;i obj=new MEDFileField1TSWithoutDAS; + obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this); + copyTinyInfoFrom(field); + _time_steps.push_back(obj); + } + else + { + checkCoherencyOfTinyInfo(field); + MEDCouplingAutoRefCountObjectPtr obj=new MEDFileField1TSWithoutDAS; + obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this); + _time_steps.push_back(obj); + } +} + MEDFileFieldMultiTS::MEDFileFieldMultiTS() { } @@ -2083,7 +2310,7 @@ void MEDFileFields::setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTER { if(!field) throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !"); - if(i>=_fields.size()) + if(i>=(int)_fields.size()) _fields.resize(i+1); field->incrRef(); _fields[i]=field; @@ -2091,7 +2318,7 @@ void MEDFileFields::setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTER void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception) { - if(i<0 || i>=_fields.size()) + if(i<0 || i>=(int)_fields.size()) { std::ostringstream oss; oss << "MEDFileFields::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index b1d90a3f7..0b7260910 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -81,6 +81,7 @@ namespace ParaMEDMEM static MEDFileFieldPerMeshPerTypePerDisc *New(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception); static MEDFileFieldPerMeshPerTypePerDisc *New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId); void assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfile(const char *pflName, const DataArrayInt *globIds, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMeshPerType *getFather() const; @@ -122,6 +123,7 @@ namespace ParaMEDMEM public: static MEDFileFieldPerMeshPerType *New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); void assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfile(const DataArrayInt *globIds, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMesh *getFather() const; void finishLoading(med_idt fid, TypeOfField type) throw(INTERP_KERNEL::Exception); @@ -142,6 +144,8 @@ namespace ParaMEDMEM private: std::vector addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception); std::vector addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception); + std::vector addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception); + std::vector addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception); MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); private: MEDFileFieldPerMesh *_father; @@ -155,7 +159,9 @@ namespace ParaMEDMEM static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, const MEDCouplingMesh *mesh); static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, int meshCsit, int meshIteration, int meshOrder); void copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); - void assignFieldNoProfile(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfile(const std::vector& code, const std::vector& globIdsPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfileGeneral(const std::vector& code, const std::vector& globIdsPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignFieldNoProfileNoRenum(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); @@ -254,6 +260,7 @@ namespace ParaMEDMEM static std::vector CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); // void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); public: MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFieldFieldGlobs *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); @@ -291,6 +298,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); // void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); + void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); private: std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; @@ -341,6 +349,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); // void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); + void appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); private: std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 4c03dd94d..ffacbfe8b 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -705,6 +705,31 @@ void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vect std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus(),offset)); } +/*! + * This method should be called by any set* method of subclasses to deal automatically with _name attribute. + * If _name attribute is empty the name of 'm' if taken as _name attribute. + * If _name is not empty and that 'm' has the same name nothing is done. + * If _name is not emplt and that 'm' has \b NOT the same name an exception is thrown. + */ +void MEDFileMesh::dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception) +{ + if(_name.empty()) + _name=m->getName(); + else + { + std::string name(m->getName()); + if(!name.empty()) + { + if(_name!=name) + { + std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : name of current MEDfile mesh is '" << _name << "' whereas name of input mesh is : '"; + oss << name << "' ! Names must match !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } +} + MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) { MEDFileUtilities::CheckFileForRead(fileName); @@ -1364,6 +1389,7 @@ void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception) { + dealWithTinyInfo(m); std::vector levSet=getNonEmptyLevels(); if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end()) { @@ -1773,8 +1799,9 @@ MEDCouplingMesh *MEDFileCMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum return const_cast(m); } -void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) +void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception) { + dealWithTinyInfo(m); if(m) m->incrRef(); _cmesh=m; @@ -2120,7 +2147,7 @@ void MEDFileMeshes::setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL:: { if(!mesh) throw INTERP_KERNEL::Exception("MEDFileMeshes::setMeshAtPos : invalid input pointer ! should be different from 0 !"); - if(i>=_meshes.size()) + if(i>=(int)_meshes.size()) _meshes.resize(i+1); MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New(); elt->setOneTimeStep(mesh); @@ -2129,7 +2156,7 @@ void MEDFileMeshes::setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL:: void MEDFileMeshes::destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception) { - if(i<0 || i>=_meshes.size()) + if(i<0 || i>=(int)_meshes.size()) { std::ostringstream oss; oss << "MEDFileMeshes::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _meshes.size() << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index cc8b78e69..5429133cc 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -101,6 +101,7 @@ namespace ParaMEDMEM virtual DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); protected: MEDFileMesh(); + void dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception); virtual void synchronizeTinyInfoOnLeaves() const = 0; virtual void appendFamilyEntries(const std::set& famIds, const std::vector< std::vector >& fidsOfGrps, const std::vector& grpNames); static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector >& famIdsPerGrp); @@ -202,7 +203,7 @@ namespace ParaMEDMEM void clearNonDiscrAttributes() const; const MEDCouplingCMesh *getMesh() const; MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception); - void setMesh(MEDCouplingCMesh *m); + void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 8f8dc2e4a..8be720510 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -453,7 +453,7 @@ namespace ParaMEDMEM static MEDFileCMesh *New(); static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); - void setMesh(MEDCouplingCMesh *m); + void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception); %extend { PyObject *getMesh() const @@ -558,6 +558,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); // void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); + void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); }; class MEDFileFieldMultiTSWithoutDAS @@ -595,6 +596,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); // void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); + void appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); }; class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs, public MEDFileWritable diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 72ffb5eea..d35dbf2ac 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -528,6 +528,38 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual(3,d2.getNumberOfFields()) m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0) self.assertTrue(m1.isEqual(m1bis,1e-12)) + pass + def testMEDField9(self): + # first test field profile WR. Full type but with some type missing + fname="Pyfile30.med" + m1=MEDLoaderDataForTest.build2DMesh_3() + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; + mm1.write(fname,2) + ff1=MEDFileField1TS.New() + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1") + d=DataArrayDouble.New() ; d.alloc(2*10,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1") + # + ff1.setFieldProfile(f1,mm1,0,da) + ff1.write(fname,0) + pass + def testMEDField10(self): + fname="Pyfile31.med" + m1=MEDLoaderDataForTest.build2DMesh_1() + m1.renumberCells([0,1,4,2,3,5],False) + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName()) + mm1.write(fname,2) + ff1=MEDFileFieldMultiTS.New() + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2") + d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2") + # + ff1.appendFieldProfile(f1,mm1,0,da) + f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ; + ff1.appendFieldProfile(f1,mm1,0,da) + ff1.write(fname,0) pass pass