return pfl->getName();
}
+int MEDMeshMultiLev::getNumberOfCells() const throw(INTERP_KERNEL::Exception)
+{
+ std::size_t sz(_nb_entities.size()/3);
+ if(_nb_entities.size()%3!=0)
+ throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : invalid code !");
+ int ret(0);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ if(_nb_entities[3*i+2]==-1)
+ ret+=_nb_entities[3*i+1];
+ else
+ {
+ const DataArrayInt *pfl(_pfls[_nb_entities[3*i+2]]);
+ if(!pfl)
+ throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : internal error !");
+ ret+=pfl->getNumberOfTuples();
+ }
+ }
+ return ret;
+}
+
+int MEDMeshMultiLev::getNumberOfNodes() const throw(INTERP_KERNEL::Exception)
+{
+ return _nb_nodes;
+}
+
DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const throw(INTERP_KERNEL::Exception)
{
if(fst.getType()==ON_NODES)
{
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
p1->sort(true);
- if(!p1->isIdentity() || p1->getNumberOfTuples()!=p.getNbEntity())
+ if(!p1->isIdentity() || p1->getNumberOfTuples()!=getNumberOfNodes())
throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
{
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->deepCpy());
p1->sort(true);
- if(!p1->isIdentity() || p1->getNumberOfTuples()!=p.getNbEntity())
+ if(!p1->isIdentity() || p1->getNumberOfTuples()!=getNumberOfCells())
throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
ret->rearrange(nbi*nc); ret->renumberInPlace(otherP->begin()); ret->rearrange(nc);
arrSafe[i]=ret; arr[i]=ret;
{
}
-MEDMeshMultiLev::MEDMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):_geo_types(gts),_nb_entities(nbEntities)
+MEDMeshMultiLev::MEDMeshMultiLev(int nbNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):_geo_types(gts),_nb_entities(nbEntities),_nb_nodes(nbNodes)
{
std::size_t sz(_geo_types.size());
if(sz!=pfls.size() || sz!=nbEntities.size())
}
}
-MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):_pfls(other._pfls),_geo_types(other._geo_types),_nb_entities(other._nb_entities),_node_reduction(other._node_reduction)
+MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):_pfls(other._pfls),_geo_types(other._geo_types),_nb_entities(other._nb_entities),_node_reduction(other._node_reduction),_nb_nodes(other._nb_nodes)
{
}
return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
}
-MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
+MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(m->getNumberOfNodes(),gts,pfls,nbEntities)
{
std::size_t sz(gts.size());
_parts.resize(sz);
{
_parts.resize(1);
_parts[0]=part;
+ _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
+ _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
+ _pfls.resize(1); _pfls[0]=0;
}
void MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const throw(INTERP_KERNEL::Exception)
{
}
-MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
+MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(int nbOfNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(nbOfNodes,gts,pfls,nbEntities)
{
}
}
}
-MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(gts,pfls,nbEntities)
+MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(m->getNumberOfNodes(),gts,pfls,nbEntities)
{
if(!m)
throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
if(!elt)
throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
- _coords[i]=elt;
+ _coords[i]=elt; _coords[i]->incrRef();
}
}
-MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other)
+MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
{
}
_structure=m->getMesh()->getNodeGridStructure();
}
-MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(gts,pfls,nbEntities)
+MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(m->getNumberOfNodes(),gts,pfls,nbEntities)
{
if(!m)
throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
pass
def test5(self):
+ """ This test plays with profiles both cell profiles and node profiles. Two first fields (resp on cells and on nodes) lie on the same mesh support whereas the third
+ mesh lies on a different mesh.
+ """
fname="ForMEDReader5.med"
# building a mesh containing 6 tri3 + 5 quad4
m=MEDCouplingUMesh("mesh",2)
self.assertTrue(v.isEqual(vExp,1e-12))
pass
pass
-
+
+ def test6(self):
+ """ This test plays with cartesian mesh and profiles. When a sub cartesian mesh can also be considered as a cartesian mesh it is done.
+ """
+ fname="ForMEDReader6.med"
+ m=MEDCouplingCMesh("mesh")
+ coordsX=DataArrayDouble([0,1.1,2.2,3.3,4.4]) ; coordsX.setInfoOnComponents(["XX [m]"])
+ coordsY=DataArrayDouble([0,1.7,3.4]) ; coordsY.setInfoOnComponents(["YYY [km]"])
+ m.setCoords(coordsX,coordsY)
+ mm=MEDFileCMesh() ; mm.setMesh(m)
+ #
+ fieldName0="zeField0" ; # on cells
+ fieldName1="zeField1" ; pfl1=DataArrayInt([2,3,6,7]) ; pfl1.setName("pfl1") # on cells
+ fieldName2="zeField2" ; pfl2=DataArrayInt([2,3,4,7,8,9,12,13,14]) ; pfl2.setName("pfl2") # on nodes
+ fieldName3="zeField3" ; pfl3=DataArrayInt([2,3,5,7]) ; pfl3.setName("pfl3") # on cells but different support
+ fieldName4="zeField4" ;# on nodes
+ fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS() ; fs4=MEDFileFieldMultiTS()
+ #
+ for i in xrange(5):
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName0) ; fNode.setMesh(m)
+ arr=DataArrayDouble(2*8) ; arr.iota(0+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
+ f.setFieldNoProfileSBT(fNode)
+ fs0.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName1)
+ arr=DataArrayDouble(2*4) ; arr.iota(100+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl1)
+ self.assertEqual(pfl1.getName(),"pfl1")
+ fs1.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName2)
+ arr=DataArrayDouble(2*9) ; arr.iota(200+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl2)
+ self.assertEqual(pfl2.getName(),"pfl2")
+ fs2.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName3)
+ arr=DataArrayDouble(2*4) ; arr.iota(300+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_3 [m]","Com2_3 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl3)
+ self.assertEqual(pfl3.getName(),"pfl3")
+ fs3.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName4) ; fNode.setMesh(m)
+ arr=DataArrayDouble(2*15) ; arr.iota(400+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_4 [m]","Com2_4 [s^2]"]) ; fNode.checkCoherency()
+ f.setFieldNoProfileSBT(fNode)
+ fs4.pushBackTimeStep(f)
+ pass
+ mm.write(fname,2)
+ fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0) ; fs4.write(fname,0)
+ del m,mm,fs1,fs2,fs3,f,fNode
+ ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
+ ms=MEDFileMeshes(fname)
+ fields=MEDFileFields(fname,False)
+ fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
+ allFMTSLeavesToDisplay=[]
+ for fields in fields_per_mesh:
+ allFMTSLeavesToDisplay2=[]
+ for fmts in fields:
+ allFMTSLeavesToDisplay2+=fmts.splitDiscretizations()
+ pass
+ allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
+ pass
+ self.assertEqual(len(allFMTSLeavesToDisplay),1)
+ self.assertEqual(len(allFMTSLeavesToDisplay[0]),5)
+ allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 5 fields are defined on the same time steps
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),5)
+ allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport),3)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport[1][0]),2)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport[2][0]),1)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields).prepare()
+ a,b=mml.buildVTUArrays()
+ self.assertTrue(a.isEqual(coordsX,1e-12))
+ self.assertTrue(b.isEqual(coordsY,1e-12))
+ self.assertTrue(isinstance(mml,MEDCMeshMultiLev))
+ for i in xrange(1,5):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ for i in xrange(5):
+ f=allFMTSLeavesPerCommonSupport[0][0][0][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName0)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(8*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport[0][0][1][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName4)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(15*2) ; vExp.iota(400+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_4 [m]','Com2_4 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ pass
+
+ fcscp=allFMTSLeavesPerCommonSupport[1][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDCMeshMultiLev)) # here the 2nd support is a part of CMesh that is also a CMesh -> CMesh not a UMesh
+ a,b=mml2.buildVTUArrays()
+ self.assertTrue(a.isEqual(coordsX[[2,3,4]],1e-12))
+ self.assertTrue(b.isEqual(coordsY,1e-12))
+ for i in xrange(1,5):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ for i in xrange(5):
+ f=allFMTSLeavesPerCommonSupport[1][0][0][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName1)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(4*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport[1][0][1][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName2)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(9*2) ; vExp.iota(200+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ pass
+ #
+ fcscp=allFMTSLeavesPerCommonSupport[2][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) # here the 3rd support is a part of CMesh but impossible to simplify more than a UMesh
+ a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ a0Exp=DataArrayDouble([0.,0.,1.1,0.,2.2,0.,3.3,0.,4.4,0.,0.,1.7,1.1,1.7,2.2,1.7,3.3,1.7,4.4,1.7,0.,3.4,1.1,3.4,2.2,3.4,3.3,3.4,4.4,3.4],15,2)
+ a0Exp.setInfoOnComponents(["XX [m]","YYY [km]"])
+ self.assertTrue(a0.isEqual(a0Exp,1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([4,8,12,16])))
+ self.assertTrue(a3.isEqual(DataArrayInt([4,3,2,7,8,4,4,3,8,9,4,7,6,11,12,4,9,8,13,14])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ for i in xrange(5):
+ f=allFMTSLeavesPerCommonSupport[2][0][0][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName3)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(4*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_3 [m]','Com2_3 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ pass
+ pass
pass
unittest.main()