/*!
* See MEDCouplingUMesh::splitProfilePerType for more information
*/
-void MEDCouplingCMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
+void MEDCouplingCMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
{
int nbCells=getNumberOfCells();
code.resize(3);
code[1]=nbCells;
code[2]=0;
idsPerType.push_back(profile->deepCpy());
+ globIdsPerType.push_back(profile->deepCpy());
}
MEDCouplingUMesh *MEDCouplingCMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
const DataArrayDouble *coordsZ=0);
// tools
DataArrayInt *checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
- void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
+ void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& 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;
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
-void MEDCouplingExtrudedMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
+void MEDCouplingExtrudedMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
{
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
void translate(const double *vector);
void scale(const double *point, double factor);
DataArrayInt *checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
- void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
+ void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& 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);
virtual std::string advancedRepr() const = 0;
// tools
virtual DataArrayInt *checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception) = 0;
- virtual void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception) = 0;
+ virtual void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& 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;
* 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<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
+void MEDCouplingUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
{
if(profile->getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::splitProfilePerType : input profile should have exactly one component !");
//
int nbOfCastsFinal=castsPresent->getNumberOfTuples();
code.resize(3*nbOfCastsFinal);
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > globIdsPerType2;
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2;
for(int i=0;i<nbOfCastsFinal;i++)
{
int castId=castsPresent->getIJ(i,0);
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp3=castArr->getIdsEqual(castId);
+ globIdsPerType2.push_back(tmp3);
code[3*i]=(int)types[castId];
code[3*i+1]=tmp3->getNumberOfTuples();
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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;
}
code[3*i+2]=-1;
}
}
+ int sz2=globIdsPerType2.size();
+ globIdsPerType.resize(sz2);
+ for(int i=0;i<sz2;i++)
+ {
+ DataArrayInt *locDa=globIdsPerType2[i];
+ locDa->incrRef();
+ globIdsPerType[i]=locDa;
+ }
int sz=idsPerType2.size();
idsPerType.resize(sz);
for(int i=0;i<sz;i++)
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception);
//utilities for MED File RW
MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
- MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& 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;
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
-void MEDCouplingUMeshDesc::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
+void MEDCouplingUMeshDesc::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
{
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
MEDCOUPLING_EXPORT void setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx);
//tools to overload
MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
- MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& globIdsPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
MEDCOUPLING_EXPORT bool isEmptyMesh(const std::vector<int>& tinyInfo) const;
MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const;
MEDCouplingUMesh *m=build2DTargetMesh_1();
m->renumberCells(val0,false);
std::vector<int> code;
+ std::vector<DataArrayInt *> globIdsPerType;
std::vector<DataArrayInt *> 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();
//
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();
//
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));
pfls[0]->decrRef();
pfls[1]->decrRef();
d->decrRef();
+ globIdsPerType.clear();
pfls.clear();
code.clear();
//
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();
//
return self->checkTypeConsistencyAndContig(code,idsPerType);
}
+ PyObject *splitProfilePerType(const DataArrayInt *profile) const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> code;
+ std::vector<DataArrayInt *> globIdsPerType;
+ std::vector<DataArrayInt *> 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<globIdsPerType.size();j++)
+ PyList_SetItem(ret1,j,SWIG_NewPointerObj(SWIG_as_voidptr(globIdsPerType[j]),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,1,ret1);
+ int n=idsPerType.size();
+ PyObject *ret2=PyList_New(n);
+ for(int i=0;i<n;i++)
+ PyList_SetItem(ret2,i,SWIG_NewPointerObj(SWIG_as_voidptr(idsPerType[i]),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,2,ret2);
+ return ret;
+ }
+
void translate(PyObject *vector) throw(INTERP_KERNEL::Exception)
{
int sz;
}
}
+ PyObject *splitByValueRange(PyObject *li) const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *ret0=0,*ret1=0,*ret2=0;
+ void *da=0;
+ int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 );
+ if (!SWIG_IsOK(res1))
+ {
+ int size;
+ INTERP_KERNEL::AutoPtr<int> 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;
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
}
}
+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<DataArrayInt> 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();
_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<int> 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<int>::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<int>::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);
return ret;
}
+std::vector<int> 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;j<sz && !found;j++)
+ {
+ if(_field_pm_pt_pd[j]->getLocId()==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<int> ret(1,0);
+ return ret;
+ }
+ else
+ {
+ std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
+ int sz2=ret2.size();
+ std::vector<int> ret3(sz2);
+ int k=0;
+ for(int i=0;i<sz2;i++)
+ {
+ int sz=_field_pm_pt_pd.size();
+ int locIdToFind=ret2[i];
+ bool found=false;
+ for(int j=0;j<sz && !found;j++)
+ {
+ if(_field_pm_pt_pd[j]->getLocId()==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<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
+{
+ const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
+ const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
+ if(!disc2)
+ throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
+ const DataArrayInt *da=disc2->getArrayOfDiscIds();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
+ std::set<int> retTmp=da2->getDifferentValues();
+ if(retTmp.find(-1)!=retTmp.end())
+ throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
+ std::vector<int> ret(retTmp.begin(),retTmp.end());
+ return ret;
+}
+
const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
{
return _father;
mesh->getTime(_mesh_iteration,_mesh_order);
}
-void MEDFileFieldPerMesh::assignFieldNoProfile(const std::vector<int>& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception)
+void MEDFileFieldPerMesh::assignFieldProfile(const std::vector<int>& code, const std::vector<DataArrayInt *>& globIdsPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception)
+{
+ int nbOfTypes=code.size()/3;
+ bool isProfile=false;
+ for(int i=0;i<nbOfTypes;i++)
+ if(code[3*i+2]!=-1)
+ isProfile=true;
+ if(!isProfile)
+ {
+ if(globIdsPerType.empty())
+ assignFieldNoProfileNoRenum(code,field,glob);
+ else
+ assignFieldProfileGeneral(code,globIdsPerType,idsPerType,field,glob);
+ }
+ else
+ assignFieldProfileGeneral(code,globIdsPerType,idsPerType,field,glob);
+}
+
+void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(const std::vector<int>& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception)
{
int nbOfTypes=code.size()/3;
int offset=0;
}
}
+/*!
+ * This method is the most general one. No optimization is done here.
+ */
+void MEDFileFieldPerMesh::assignFieldProfileGeneral(const std::vector<int>& code, const std::vector<DataArrayInt *>& globIdsPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception)
+{
+ int nbOfTypes=code.size()/3;
+ for(int i=0;i<nbOfTypes;i++)
+ {
+ INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
+ int pos=addNewEntryIfNecessary(type);
+ DataArrayInt *pfl=0;
+ if(code[3*i+2]!=-1)
+ pfl=idsPerType[code[3*i+2]];
+ _field_pm_pt[pos]->assignFieldProfile(globIdsPerType[i],pfl,field,glob);
+ }
+}
+
void MEDFileFieldPerMesh::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception)
{
int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
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];
}
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<const DataArrayInt *> idsPerType;//no profiles
DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
/*!
* 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<DataArrayInt *> dummy;
+ copyTinyInfoFrom(field);
if(type!=ON_NODES)
{
std::vector<int> 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<int> code;
+ std::vector<DataArrayInt *> globIdsPerType;
+ std::vector<DataArrayInt *> idsPerType;
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
+ m->splitProfilePerType(profile,code,globIdsPerType,idsPerType);
+ //
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > globIdsPerType2(globIdsPerType.size());
+ for(std::size_t i=0;i<globIdsPerType.size();i++)
+ globIdsPerType2[i]=globIdsPerType[i];
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size());
+ for(std::size_t i=0;i<idsPerType.size();i++)
+ idsPerType2[i]=idsPerType[i];
+ //
+ int pos=addNewEntryIfNecessary(m);
+ _field_per_mesh[pos]->assignFieldProfile(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<MEDFileMesh> mm;
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);
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<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
{
return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos,nbOfStep);
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<nbOfTS;i++)
}
}
+void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
+{
+ if(_time_steps.empty())
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutDAS> obj=new MEDFileField1TSWithoutDAS;
+ obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this);
+ copyTinyInfoFrom(field);
+ _time_steps.push_back(obj);
+ }
+ else
+ {
+ checkCoherencyOfTinyInfo(field);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutDAS> obj=new MEDFileField1TSWithoutDAS;
+ obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this);
+ _time_steps.push_back(obj);
+ }
+}
+
MEDFileFieldMultiTS::MEDFileFieldMultiTS()
{
}
{
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;
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());
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;
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);
private:
std::vector<int> addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception);
std::vector<int> addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception);
+ std::vector<int> addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception);
+ std::vector<int> 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;
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<int>& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception);
+ void assignFieldProfile(const std::vector<int>& code, const std::vector<DataArrayInt *>& globIdsPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception);
+ void assignFieldProfileGeneral(const std::vector<int>& code, const std::vector<DataArrayInt *>& globIdsPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception);
+ void assignFieldNoProfileNoRenum(const std::vector<int>& 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);
static std::vector<int> 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);
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<std::string> getPflsReallyUsed() const;
std::vector<std::string> getLocsReallyUsed() const;
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<std::string> getPflsReallyUsed() const;
std::vector<std::string> getLocsReallyUsed() const;
std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<int>(),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);
void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
{
+ dealWithTinyInfo(m);
std::vector<int> levSet=getNonEmptyLevels();
if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end())
{
return const_cast<MEDCouplingCMesh *>(m);
}
-void MEDFileCMesh::setMesh(MEDCouplingCMesh *m)
+void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception)
{
+ dealWithTinyInfo(m);
if(m)
m->incrRef();
_cmesh=m;
{
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);
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());
virtual DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& 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<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames);
static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp);
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<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
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
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
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
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