return _MEDCalculator.MEDCouplingExtrudedMesh____new___(cls,args)
%}
+%pythoncode %{
+def ParaMEDMEMMEDFileUMeshnew(cls,*args):
+ import _MEDCalculator
+ return _MEDCalculator.MEDFileUMesh____new___(cls,args)
+%}
+
%include "MEDCouplingFinalize.i"
+
+%pythoncode %{
+MEDFileUMesh.__new__=classmethod(ParaMEDMEMMEDFileUMeshnew)
+del ParaMEDMEMMEDFileUMeshnew
+%}
return DataArrayPartDefinition::New(listOfIds);
}
+PartDefinition *PartDefinition::Unserialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
+{
+ if(tinyInt.empty())
+ {
+ MEDCouplingAutoRefCountObjectPtr<PartDefinition> ret(DataArrayPartDefinition::New(bigArraysI.back()));
+ bigArraysI.pop_back();
+ return ret.retn();
+ }
+ else if(tinyInt.size()==3)
+ {
+ MEDCouplingAutoRefCountObjectPtr<PartDefinition> ret(SlicePartDefinition::New(tinyInt[0],tinyInt[1],tinyInt[2]));
+ tinyInt.erase(tinyInt.begin(),tinyInt.begin()+3);
+ return ret.retn();
+ }
+ else
+ throw INTERP_KERNEL::Exception("PartDefinition::Unserialize");
+}
+
PartDefinition::~PartDefinition()
{
}
return new DataArrayPartDefinition(listOfIds);
}
+bool DataArrayPartDefinition::isEqual(const PartDefinition *other, std::string& what) const
+{
+ if(!other)
+ {
+ what="DataArrayPartDefinition::isEqual : other is null, this is not null !";
+ return false;
+ }
+ const DataArrayPartDefinition *otherC(dynamic_cast<const DataArrayPartDefinition *>(other));
+ if(!otherC)
+ {
+ what="DataArrayPartDefinition::isEqual : other is not DataArrayPartDefinition !";
+ return false;
+ }
+ const DataArrayInt *arr0(_arr),*arr1(otherC->_arr);
+ if(!arr0 && !arr1)
+ return true;
+ if((arr0 && !arr1) || (!arr0 && arr1))
+ {
+ what="DataArrayPartDefinition::isEqual : array is not defined both in other and this !";
+ return false;
+ }
+ std::string what1;
+ bool ret(arr0->isEqualIfNotWhy(*arr1,what1));
+ if(!ret)
+ {
+ what=std::string("DataArrayPartDefinition::isEqual : arrays are not equal :\n")+what1;
+ return false;
+ }
+ return true;
+}
+
+DataArrayPartDefinition *DataArrayPartDefinition::deepCpy() const
+{
+ const DataArrayInt *arr(_arr);
+ if(!arr)
+ throw INTERP_KERNEL::Exception("DataArrayPartDefinition::deepCpy : array is null !");
+ return DataArrayPartDefinition::New(const_cast<DataArrayInt *>(arr));
+}
+
int DataArrayPartDefinition::getNumberOfElems() const
{
checkInternalArrayOK();
}
}
+void DataArrayPartDefinition::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
+{
+ bigArraysI.push_back(_arr);
+}
+
DataArrayInt *DataArrayPartDefinition::toDAI() const
{
checkInternalArrayOK();
return new SlicePartDefinition(start,stop,step);
}
+bool SlicePartDefinition::isEqual(const PartDefinition *other, std::string& what) const
+{
+ if(!other)
+ {
+ what="SlicePartDefinition::isEqual : other is null, this is not null !";
+ return false;
+ }
+ const SlicePartDefinition *otherC(dynamic_cast<const SlicePartDefinition *>(other));
+ if(!otherC)
+ {
+ what="SlicePartDefinition::isEqual : other is not SlicePartDefinition !";
+ return false;
+ }
+ bool ret((_start==otherC->_start) && (_stop==otherC->_stop) && (_step==otherC->_step));
+ if(!ret)
+ {
+ what="SlicePartDefinition::isEqual : values are not the same !";
+ return false;
+ }
+ return true;
+}
+
+SlicePartDefinition *SlicePartDefinition::deepCpy() const
+{
+ return SlicePartDefinition::New(_start,_stop,_step);
+}
+
DataArrayInt *SlicePartDefinition::toDAI() const
{
return DataArrayInt::Range(_start,_stop,_step);
return ret;
}
+void SlicePartDefinition::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
+{
+ tinyInt.push_back(_start);
+ tinyInt.push_back(_stop);
+ tinyInt.push_back(_step);
+}
+
std::string SlicePartDefinition::getRepr() const
{
std::ostringstream oss;
public:
MEDCOUPLING_EXPORT static PartDefinition *New(int start, int stop, int step);
MEDCOUPLING_EXPORT static PartDefinition *New(DataArrayInt *listOfIds);
+ MEDCOUPLING_EXPORT static PartDefinition *Unserialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
+ MEDCOUPLING_EXPORT virtual bool isEqual(const PartDefinition *other, std::string& what) const = 0;
+ MEDCOUPLING_EXPORT virtual PartDefinition *deepCpy() const = 0;
MEDCOUPLING_EXPORT virtual DataArrayInt *toDAI() const = 0;
MEDCOUPLING_EXPORT virtual int getNumberOfElems() const = 0;
MEDCOUPLING_EXPORT virtual PartDefinition *operator+(const PartDefinition& other) const = 0;
MEDCOUPLING_EXPORT virtual PartDefinition *composeWith(const PartDefinition *other) const = 0;
MEDCOUPLING_EXPORT virtual void checkCoherency() const = 0;
MEDCOUPLING_EXPORT virtual PartDefinition *tryToSimplify() const = 0;
+ MEDCOUPLING_EXPORT virtual void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const = 0;
protected:
virtual ~PartDefinition();
};
{
public:
MEDCOUPLING_EXPORT static DataArrayPartDefinition *New(DataArrayInt *listOfIds);
+ MEDCOUPLING_EXPORT bool isEqual(const PartDefinition *other, std::string& what) const;
+ MEDCOUPLING_EXPORT DataArrayPartDefinition *deepCpy() const;
MEDCOUPLING_EXPORT DataArrayInt *toDAI() const;
MEDCOUPLING_EXPORT int getNumberOfElems() const;
MEDCOUPLING_EXPORT PartDefinition *operator+(const PartDefinition& other) const;
MEDCOUPLING_EXPORT PartDefinition *composeWith(const PartDefinition *other) const;
MEDCOUPLING_EXPORT void checkCoherency() const;
MEDCOUPLING_EXPORT PartDefinition *tryToSimplify() const;
+ MEDCOUPLING_EXPORT void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const;
private:
DataArrayPartDefinition(DataArrayInt *listOfIds);
void checkInternalArrayOK() const;
{
public:
MEDCOUPLING_EXPORT static SlicePartDefinition *New(int start, int stop, int step);
+ MEDCOUPLING_EXPORT bool isEqual(const PartDefinition *other, std::string& what) const;
+ MEDCOUPLING_EXPORT SlicePartDefinition *deepCpy() const;
MEDCOUPLING_EXPORT DataArrayInt *toDAI() const;
MEDCOUPLING_EXPORT int getNumberOfElems() const;
MEDCOUPLING_EXPORT PartDefinition *operator+(const PartDefinition& other) const;
MEDCOUPLING_EXPORT PartDefinition *composeWith(const PartDefinition *other) const;
MEDCOUPLING_EXPORT void checkCoherency() const;
MEDCOUPLING_EXPORT PartDefinition *tryToSimplify() const;
+ MEDCOUPLING_EXPORT void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const;
//specific method
MEDCOUPLING_EXPORT int getEffectiveStop() const;
MEDCOUPLING_EXPORT void getSlice(int& start, int& stop, int& step) const;
INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON})
INSTALL(FILES MEDCoupling.i MEDCouplingCommon.i MEDCouplingRefCountObject.i MEDCouplingMemArray.i MEDCouplingFieldDiscretization.i MEDCouplingTimeDiscretization.i MEDCouplingFinalize.i MEDCouplingRemapper.i MEDCouplingTypemaps.i MEDCouplingDataArrayTypemaps.i DESTINATION ${SALOME_INSTALL_HEADERS})
-INSTALL(FILES MEDCouplingBasicsTest.py MEDCouplingRemapperTest.py MEDCouplingDataForTest.py MEDCouplingNumPyTest.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON})
+INSTALL(FILES MEDCouplingBasicsTest.py MEDCouplingRemapperTest.py MEDCouplingDataForTest.py MEDCouplingNumPyTest.py MEDCouplingPickleTest.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON})
INSTALL(FILES MEDCouplingExamplesTest.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON})
SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
def testSwig2PartDefinitionComposeWith1(self):
f=PartDefinition.New(DataArrayInt([0,1,2,3,6,7,8,9]))
g=PartDefinition.New(4,14,1)
+ g2=g.deepCpy()
+ self.assertTrue(g2.isEqual(g)[0])
h=f.composeWith(g)
self.assertTrue(isinstance(h,DataArrayPartDefinition))
self.assertTrue(h.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
self.assertNotEqual(p2.getHiddenCppPointer(),p.getHiddenCppPointer())
self.assertTrue(isinstance(p2,SlicePartDefinition))
self.assertEqual(p2.getSlice(),slice(2,11,4))
+ self.assertTrue(p2.isEqual(SlicePartDefinition(2,11,4))[0])
+ self.assertTrue(p2.isEqual(p2.deepCpy())[0])
+ self.assertTrue(not p2.isEqual(SlicePartDefinition(1,11,4))[0])
+ self.assertTrue(not p2.isEqual(SlicePartDefinition(2,10,4))[0])
+ self.assertTrue(not p2.isEqual(SlicePartDefinition(2,11,3))[0])
pass
def testSwig2DAIGetIdsStrictlyNegative1(self):
{
return (*self)+other;
}
+
+ virtual PyObject *isEqual(const PartDefinition *other) const throw(INTERP_KERNEL::Exception)
+ {
+ std::string ret1;
+ bool ret0(self->isEqual(other,ret1));
+ PyObject *ret=PyTuple_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyTuple_SetItem(ret,0,ret0Py);
+ PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str()));
+ return ret;
+ }
+
+ virtual PyObject *deepCpy() const throw(INTERP_KERNEL::Exception)
+ {
+ return convertPartDefinition(self->deepCpy(),SWIG_POINTER_OWN | 0);
+ }
}
protected:
virtual ~PartDefinition();
if((const MEDFileUMeshSplitL1 *)(*it))
ret->_ms[i]=(*it)->deepCpy(ret->_coords);
}
+ if((const PartDefinition*)_part_coords)
+ ret->_part_coords=_part_coords->deepCpy();
return ret.retn();
}
return false;
}
}
- return true;
+ const PartDefinition *pd0(_part_coords),*pd1(otherC->_part_coords);
+ if(!pd0 && !pd1)
+ return true;
+ if((!pd0 && pd1) || (pd0 && !pd1))
+ {
+ what=std::string("node part def is defined only for one among this or other !");
+ return false;
+ }
+ return pd0->isEqual(pd1,what);
}
/*!
return ret.retn();
}
+void MEDFileUMesh::serialize(std::vector<double>& tinyDouble, std::vector<int>& tinyInt, std::vector<std::string>& tinyStr, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI, MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& bigArrayD)
+{
+ clearNonDiscrAttributes();
+ forceComputationOfParts();
+ tinyDouble.clear(); tinyInt.clear(); tinyStr.clear(); bigArraysI.clear(); bigArrayD=0;
+ std::vector<int> layer0;
+ layer0.push_back(_order); //0 i
+ layer0.push_back(_iteration);//1 i
+ layer0.push_back(getSpaceDimension());//2 i
+ tinyDouble.push_back(_time);//0 d
+ tinyStr.push_back(_name);//0 s
+ tinyStr.push_back(_desc_name);//1 s
+ for(int i=0;i<getSpaceDimension();i++)
+ tinyStr.push_back(_coords->getInfoOnComponent(i));
+ layer0.push_back((int)_families.size());//3 i <- key info aa layer#0
+ for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ {
+ tinyStr.push_back((*it).first);
+ layer0.push_back((*it).second);
+ }
+ layer0.push_back((int)_groups.size());//3+aa i <- key info bb layer#0
+ for(std::map<std::string, std::vector<std::string> >::const_iterator it0=_groups.begin();it0!=_groups.end();it0++)
+ {
+ layer0.push_back((int)(*it0).second.size());
+ tinyStr.push_back((*it0).first);
+ for(std::vector<std::string>::const_iterator it1=((*it0).second).begin();it1!=((*it0).second).end();it1++)
+ tinyStr.push_back(*it1);
+ }
+ // sizeof(layer0)==3+aa+1+bb layer#0
+ bigArrayD=_coords;// 0 bd
+ bigArraysI.push_back(_fam_coords);// 0 bi
+ bigArraysI.push_back(_num_coords);// 1 bi
+ const PartDefinition *pd(_part_coords);
+ if(!pd)
+ layer0.push_back(-1);
+ else
+ {
+ std::vector<int> tmp0;
+ pd->serialize(tmp0,bigArraysI);
+ tinyInt.push_back(tmp0.size());
+ tinyInt.insert(tinyInt.end(),tmp0.begin(),tmp0.end());
+ }
+ //
+ std::vector<int> layer1;
+ std::vector<int> levs(getNonEmptyLevels());
+ layer1.push_back((int)levs.size());// 0 i <- key
+ layer1.insert(layer1.end(),levs.begin(),levs.end());
+ for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
+ {
+ const MEDFileUMeshSplitL1 *lev(getMeshAtLevSafe(*it));
+ lev->serialize(layer1,bigArraysI);
+ }
+ // put layers all together.
+ tinyInt.push_back(layer0.size());
+ tinyInt.insert(tinyInt.end(),layer0.begin(),layer0.end());
+ tinyInt.push_back(layer1.size());
+ tinyInt.insert(tinyInt.end(),layer1.begin(),layer1.end());
+}
+
+void MEDFileUMesh::unserialize(std::vector<double>& tinyDouble, std::vector<int>& tinyInt, std::vector<std::string>& tinyStr,
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI, MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& bigArrayD)
+{
+ int sz0(tinyInt[0]);
+ std::vector<int> layer0(tinyInt.begin()+1,tinyInt.begin()+1+sz0);
+ int sz1(tinyInt[sz0+1]);
+ std::vector<int> layer1(tinyInt.begin()+2+sz0,tinyInt.begin()+2+sz0+sz1);
+ //
+ std::reverse(layer0.begin(),layer0.end());
+ std::reverse(layer1.begin(),layer1.end());
+ std::reverse(tinyDouble.begin(),tinyDouble.end());
+ std::reverse(tinyStr.begin(),tinyStr.end());
+ std::reverse(bigArraysI.begin(),bigArraysI.end());
+ //
+ _order=layer0.back(); layer0.pop_back();
+ _iteration=layer0.back(); layer0.pop_back();
+ int spaceDim(layer0.back()); layer0.pop_back();
+ _time=tinyDouble.back(); tinyDouble.pop_back();
+ _name=tinyStr.back(); tinyStr.pop_back();
+ _desc_name=tinyStr.back(); tinyStr.pop_back();
+ _coords=bigArrayD; _coords->rearrange(spaceDim);
+ for(int i=0;i<spaceDim;i++)
+ {
+ _coords->setInfoOnComponent(i,tinyStr.back());
+ tinyStr.pop_back();
+ }
+ int nbOfFams(layer0.back()); layer0.pop_back();
+ _families.clear();
+ for(int i=0;i<nbOfFams;i++)
+ {
+ _families[tinyStr.back()]=layer0.back();
+ tinyStr.pop_back(); layer0.pop_back();
+ }
+ int nbGroups(layer0.back()); layer0.pop_back();
+ _groups.clear();
+ for(int i=0;i<nbGroups;i++)
+ {
+ std::string grpName(tinyStr.back()); tinyStr.pop_back();
+ int nbOfFamsOnGrp(layer0.back()); layer0.pop_back();
+ std::vector<std::string> fams(nbOfFamsOnGrp);
+ for(int j=0;j<nbOfFamsOnGrp;j++)
+ {
+ fams[j]=tinyStr.back(); tinyStr.pop_back();
+ }
+ _groups[grpName]=fams;
+ }
+ _fam_coords=bigArraysI.back(); bigArraysI.pop_back();
+ _num_coords=bigArraysI.back(); bigArraysI.pop_back();
+ _part_coords=0;
+ int isPd(layer0.back()); layer0.pop_back();
+ if(isPd!=-1)
+ {
+ std::vector<int> tmp0(layer0.begin(),layer0.begin()+isPd);
+ layer0.erase(layer0.begin(),layer0.begin()+isPd);
+ _part_coords=PartDefinition::Unserialize(tmp0,bigArraysI);
+ }
+ if(!layer0.empty())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::unserialize : something wrong during unserialization #1 !");
+ //
+ int nbLevs(layer1.back()); layer1.pop_back();
+ std::vector<int> levs(layer1.rbegin(),layer1.rbegin()+nbLevs); layer1.erase(layer1.end()-nbLevs,layer1.end());
+ _ms.clear();
+ int maxLev(-(*std::min_element(levs.begin(),levs.end())));
+ _ms.resize(maxLev+1);
+ for(int i=0;i<nbLevs;i++)
+ {
+ int lev(levs[i]);
+ int pos(-lev);
+ _ms[pos]=MEDFileUMeshSplitL1::Unserialize(_name,_coords,layer1,bigArraysI);
+ }
+}
+
/*!
* Adds a group of nodes to \a this mesh.
* \param [in] ids - a DataArrayInt providing ids and a name of the group to add.
MEDLOADER_EXPORT bool unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell);
MEDLOADER_EXPORT DataArrayInt *zipCoords();
MEDLOADER_EXPORT MEDFileUMesh *buildExtrudedMesh(const MEDCouplingUMesh *m1D, int policy) const;
+ // serialization
+ MEDLOADER_EXPORT void serialize(std::vector<double>& tinyDouble, std::vector<int>& tinyInt, std::vector<std::string>& tinyStr,
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI, MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& bigArrayD);
+ MEDLOADER_EXPORT void unserialize(std::vector<double>& tinyDouble, std::vector<int>& tinyInt, std::vector<std::string>& tinyStr,
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI, MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& bigArrayD);
private:
MEDLOADER_EXPORT ~MEDFileUMesh();
void writeLL(med_idt fid) const;
assignCommonPart();
}
+MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this)
+{
+}
+
void MEDFileUMeshSplitL1::assignCommonPart()
{
_fam=DataArrayInt::New();
_m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
}
+void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
+{
+ bigArraysI.push_back(_fam);
+ bigArraysI.push_back(_num);
+ _m_by_types.serialize(tinyInt,bigArraysI);
+}
+
+void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
+{
+ _fam=bigArraysI.back(); bigArraysI.pop_back();
+ _num=bigArraysI.back(); bigArraysI.pop_back();
+ _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
+}
+
void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId)
{
DataArrayInt *arr=_fam;
return m;
}
+MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
+ ret->unserialize(name,coo,tinyInt,bigArraysI);
+ return ret.retn();
+}
+
MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
{
return Renumber2(_num,m,cellIds);
throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
}
+void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
+{
+ if(_mp_time<_m_time)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
+ std::size_t sz(_m_parts.size());
+ tinyInt.push_back((int)sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
+ tinyInt.push_back(mesh->getCellModelEnum());
+ const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
+ const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
+ if(mesh1)
+ {
+ DataArrayInt *elt(mesh1->getNodalConnectivity());
+ if(elt)
+ elt->incrRef();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt1(elt);
+ bigArraysI.push_back(elt1);
+ }
+ else if(mesh2)
+ {
+ DataArrayInt *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
+ if(elt1)
+ elt1->incrRef();
+ if(elt2)
+ elt2->incrRef();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt11(elt1),elt22(elt2);
+ bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
+ const PartDefinition *pd(_part_def[i]);
+ if(!pd)
+ tinyInt.push_back(-1);
+ else
+ {
+ std::vector<int> tinyTmp;
+ pd->serialize(tinyTmp,bigArraysI);
+ tinyInt.push_back((int)tinyTmp.size());
+ tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
+ }
+ }
+}
+
+void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
+{
+ int nbParts(tinyInt.back()); tinyInt.pop_back();
+ _part_def.clear(); _part_def.resize(nbParts);
+ _m_parts.clear(); _m_parts.resize(nbParts);
+ for(int i=0;i<nbParts;i++)
+ {
+ INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
+ MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
+ mesh->setCoords(coo);
+ MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
+ MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
+ if(mesh1)
+ {
+ mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
+ }
+ else if(mesh2)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt0,elt1;
+ elt0=bigArraysI.back(); bigArraysI.pop_back();
+ elt1=bigArraysI.back(); bigArraysI.pop_back();
+ mesh2->setNodalConnectivity(elt0,elt1);
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
+ _m_parts[i]=mesh;
+ int pdid(tinyInt.back()); tinyInt.pop_back();
+ if(pdid!=-1)
+ _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
+ _mp_time=std::max(_mp_time,_m_time)+1;
+ }
+}
+
/*!
* This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
*/
ret._m=static_cast<ParaMEDMEM::MEDCouplingUMesh*>(_m->deepCpy());
ret._m->setCoords(coords);
}
+ std::size_t sz(_part_def.size());
+ ret._part_def.clear(); ret._part_def.resize(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const PartDefinition *elt(_part_def[i]);
+ if(elt)
+ ret._part_def[i]=elt->deepCpy();
+ }
return ret;
}
return false;
}
}
+ std::size_t sz(_part_def.size());
+ if(sz!=other._part_def.size())
+ {
+ what=std::string("number of subdivision per geo type for part definition is not the same !");
+ return false;
+ }
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
+ if(!pd0 && !pd1)
+ continue;
+ if((!pd0 && pd1) || (pd0 && !pd1))
+ {
+ what=std::string("a cell part def is defined only for one among this or other !");
+ return false;
+ }
+ bool ret(pd0->isEqual(pd1,what));
+ if(!ret)
+ return false;
+ }
return true;
}
void setCoords(DataArrayDouble *coords);
void forceComputationOfPartsFromUMesh() const;
const PartDefinition *getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
+ void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const;
+ void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
private:
std::size_t getTimeOfParts() const;
std::size_t getTimeOfUMesh() const;
//
void renumberNodesInConn(const int *newNodeNumbersO2N);
//
+ void serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const;
+ void unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
+ //
static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
+ static MEDFileUMeshSplitL1 *Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI);
private:
+ MEDFileUMeshSplitL1();
void assignCommonPart();
MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
return _MEDLoader.MEDCouplingExtrudedMesh____new___(cls,args)
%}
+%pythoncode %{
+def ParaMEDMEMMEDFileUMeshnew(cls,*args):
+ import _MEDLoader
+ return _MEDLoader.MEDFileUMesh____new___(cls,args)
+%}
+
%include "MEDCouplingFinalize.i"
+
+%pythoncode %{
+MEDFileUMesh.__new__=classmethod(ParaMEDMEMMEDFileUMeshnew)
+del ParaMEDMEMMEDFileUMeshnew
+%}
return MEDFileUMesh::New();
}
+ // serialization
+ static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+ {
+ return NewMethWrapCallInitOnlyIfEmptyDictInInput(cls,args,"MEDFileUMesh");
+ }
+
static MEDFileUMesh *LoadPartOf(const std::string& fileName, const std::string& mName, PyObject *types, const std::vector<int>& slicPerTyp, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception)
{
std::vector<int> typesCpp1;
return MEDFileUMesh::LoadPartOf(fileName,mName,typesCpp2,slicPerTyp,dt,it,mrs);
}
+ PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
+ {// put an empty dict in input to say to __new__ to call __init__...
+ PyObject *ret(PyTuple_New(1));
+ PyObject *ret0(PyDict_New());
+ PyTuple_SetItem(ret,0,ret0);
+ return ret;
+ }
+
+ PyObject *__getstate__() throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<double> a0;
+ std::vector<int> a1;
+ std::vector<std::string> a2;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a3;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a4;
+ self->serialize(a0,a1,a2,a3,a4);
+ PyObject *ret(PyTuple_New(5));
+ PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0));
+ PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1));
+ int sz(a2.size());
+ PyObject *ret2(PyList_New(sz));
+ for(int i=0;i<sz;i++)
+ PyList_SetItem(ret2,i,PyString_FromString(a2[i].c_str()));
+ PyTuple_SetItem(ret,2,ret2);
+ sz=a3.size();
+ PyObject *ret3(PyList_New(sz));
+ for(int i=0;i<sz;i++)
+ {
+ DataArrayInt *elt(a3[i]);
+ if(elt)
+ elt->incrRef();
+ PyList_SetItem(ret3,i,SWIG_NewPointerObj(SWIG_as_voidptr(elt),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ }
+ PyTuple_SetItem(ret,3,ret3);
+ DataArrayDouble *ret4(a4);
+ if(ret4)
+ ret4->incrRef();
+ PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(ret4),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
+
+ void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
+ {
+ static const char MSG[]="MEDFileUMesh.__setstate__ : expected input is a tuple of size 4 !";
+ if(!PyTuple_Check(inp))
+ throw INTERP_KERNEL::Exception(MSG);
+ int sz(PyTuple_Size(inp));
+ if(sz!=5)
+ throw INTERP_KERNEL::Exception(MSG);
+ std::vector<double> a0;
+ std::vector<int> a1;
+ std::vector<std::string> a2;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a3;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a4;
+ //
+ PyObject *a0py(PyTuple_GetItem(inp,0)),*a1py(PyTuple_GetItem(inp,1)),*a2py(PyTuple_GetItem(inp,2));
+ int tmp(-1);
+ fillArrayWithPyListDbl3(a0py,tmp,a0);
+ convertPyToNewIntArr3(a1py,a1);
+ fillStringVector(a2py,a2);
+ //
+ PyObject *b0py(PyTuple_GetItem(inp,3)),*b1py(PyTuple_GetItem(inp,4));
+ void *argp(0);
+ int status(SWIG_ConvertPtr(b1py,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0));
+ if(!SWIG_IsOK(status))
+ throw INTERP_KERNEL::Exception(MSG);
+ a4=reinterpret_cast<DataArrayDouble *>(argp);
+ if((DataArrayDouble *)a4)
+ a4->incrRef();
+ {
+ std::vector< DataArrayInt * > a3Tmp;
+ convertFromPyObjVectorOfObj<ParaMEDMEM::DataArrayInt *>(b0py,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",a3Tmp);
+ std::size_t sz(a3Tmp.size());
+ a3.resize(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ a3[i]=a3Tmp[i];
+ if(a3Tmp[i])
+ a3Tmp[i]->incrRef();
+ }
+ self->unserialize(a0,a1,a2,a3,a4);
+ }
+ }
+
void setMeshes(PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception)
{
std::vector<const MEDCouplingUMesh *> ms;
mm3D.setName("MeshExtruded")
mm3D.write(fileName,0)
pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def testMEDFileUMeshPickeling1(self):
+ import cPickle
+ outFileName="Pyfile86.med"
+ c=DataArrayDouble([-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ],9,2)
+ c.setInfoOnComponents(["aa","bbb"])
+ targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
+ m=MEDCouplingUMesh();
+ m.setMeshDimension(2);
+ m.allocateCells(5);
+ m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
+ m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
+ m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
+ m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
+ m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
+ m.finishInsertingCells();
+ m.setCoords(c)
+ m.checkCoherency()
+ m1=MEDCouplingUMesh.New();
+ m1.setMeshDimension(1);
+ m1.allocateCells(3);
+ m1.insertNextCell(NORM_SEG2,2,[1,4])
+ m1.insertNextCell(NORM_SEG2,2,[3,6])
+ m1.insertNextCell(NORM_SEG3,3,[2,8,5])
+ m1.finishInsertingCells();
+ m1.setCoords(c)
+ m1.checkCoherency()
+ m2=MEDCouplingUMesh.New();
+ m2.setMeshDimension(0);
+ m2.allocateCells(4);
+ m2.insertNextCell(NORM_POINT1,1,[1])
+ m2.insertNextCell(NORM_POINT1,1,[3])
+ m2.insertNextCell(NORM_POINT1,1,[2])
+ m2.insertNextCell(NORM_POINT1,1,[6])
+ m2.finishInsertingCells();
+ m2.setCoords(c)
+ m2.checkCoherency()
+ #
+ mm=MEDFileUMesh.New()
+ self.assertTrue(mm.getUnivNameWrStatus())
+ mm.setName("MyFirstMEDCouplingMEDmesh")
+ mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
+ mm.setCoords(c)
+ mm.setMeshAtLevel(-1,m1);
+ mm.setMeshAtLevel(0,m);
+ mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
+ mm.setMeshAtLevel(-2,m2);
+ mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
+ # playing with groups
+ g1_2=DataArrayInt.New()
+ g1_2.setValues([1,3],2,1)
+ g1_2.setName("G1")
+ g2_2=DataArrayInt.New()
+ g2_2.setValues([1,2,3],3,1)
+ g2_2.setName("G2")
+ mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
+ g1_1=DataArrayInt.New()
+ g1_1.setValues([0,1,2],3,1)
+ g1_1.setName("G1")
+ g2_1=DataArrayInt.New()
+ g2_1.setValues([0,2],2,1)
+ g2_1.setName("G2")
+ mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
+ g1_N=DataArrayInt.New()
+ g1_N.setValues(range(8),8,1)
+ g1_N.setName("G1")
+ g2_N=DataArrayInt.New()
+ g2_N.setValues(range(9),9,1)
+ g2_N.setName("G2")
+ mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
+ mm.createGroupOnAll(0,"GrpOnAllCell")
+ # check content of mm
+ t=mm.getGroupArr(0,"G1",False)
+ self.assertTrue(g1_2.isEqual(t));
+ t=mm.getGroupArr(0,"G2",False)
+ self.assertTrue(g2_2.isEqual(t));
+ t=mm.getGroupArr(-1,"G1",False)
+ self.assertTrue(g1_1.isEqual(t));
+ t=mm.getGroupArr(-1,"G2",False)
+ self.assertTrue(g2_1.isEqual(t));
+ t=mm.getGroupArr(1,"G1",False)
+ self.assertTrue(g1_N.isEqual(t));
+ t=mm.getGroupArr(1,"G2",False)
+ self.assertTrue(g2_N.isEqual(t));
+ self.assertTrue(mm.existsGroup("GrpOnAllCell"));
+ t=mm.getGroupArr(0,"GrpOnAllCell")
+ #
+ st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
+ mm2=cPickle.loads(st)
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ pass
pass
unittest.main()