clarifying some points in the tutorial.
for i in range(nbOfCells):
mesh.insertNextCell(NORM_HEXA8,8,connectivity[8*i:8*(i+1)])
pass
- mesh.finishInsertingCells()
print "5 ********************"
# Settings of coordinates and verify if it's OK
for i in range(NbCell2D):
m1.insertNextCell(NORM_QUAD4,4,Connectivities[4*i:4*(i+1)])
- m1.finishInsertingCells()
m1.changeSpaceDimension(3)
# Creation of 1D meshing
m2.insertNextCell(NORM_SEG2,2,conn[0:2])
m2.insertNextCell(NORM_SEG2,2,conn[2:4])
m2.insertNextCell(NORM_SEG2,2,conn[4:6])
- m2.finishInsertingCells()
myCoords1D=DataArrayDouble.New()
myCoords1D.setValues(coords,4,1)
m2.setCoords(myCoords1D)
cell_connec = o2n[6*i:6*(i+1)]
m.insertNextCell(mc.NORM_POLYGON, cell_connec.getValues())
pass
- m.finishInsertingCells()
# Check that everything is coherent (will throw if not)
m.checkCoherency()
# Write the result into a VTU file that can be read with ParaView
for i in range(6):
mesh.insertNextCell(NORM_POLYGON,6,connectivity[6*i:6*(i+1)])
pass
- mesh.finishInsertingCells()
print "5 ********************"
mesh.checkCoherency()
mesh3D.insertNextCell(mc.NORM_HEXA8,conn[0:8]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[8:51]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[51:59]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[59:67]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[67:110]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[110:118]);
mesh3D.insertNextCell(mc.NORM_HEXA8,conn[118:126]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[126:169]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[169:177]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[177:185]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[185:228]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[228:236]);
mesh3D.insertNextCell(mc.NORM_HEXA8,conn[236:244]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[244:287]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[287:295]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[295:303]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[303:346]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[346:354]);
- mesh3D.finishInsertingCells();
myCoords = mc.DataArrayDouble(coords,60,3);
myCoords.setInfoOnComponents(["X [m]","Y [m]","Z [m]"])
mesh3D.setCoords(myCoords);
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[0:4])
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[10:14])
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[14:18])
- targetMesh.finishInsertingCells()
myCoords = ml.DataArrayDouble(targetCoords,9,2)
myCoords.setInfoOnComponents(["X [km]","YY [mm]"])
targetMesh.setCoords(myCoords)
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[0:4])
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[10:14])
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[14:18])
- targetMesh.finishInsertingCells()
myCoords = ml.DataArrayDouble(targetCoords,9,2)
myCoords.setInfoOnComponents(["X [km]","YY [mm]"])
targetMesh.setCoords(myCoords)
for i in range(6):
mesh.insertNextCell(NORM_POLYGON,6,connectivity[6*i:6*(i+1)])
pass
- mesh.finishInsertingCells()
mesh.checkCoherency()
Saving the mesh in a med file
mesh.insertNextCell(NORM_HEXA8,8,connectivity[8*i:8*(i+1)])
pass
- # Finishing insertion
- mesh.finishInsertingCells()
+ # Check mesh consistency:
mesh.checkCoherency()
Method by extrusion
for i in range(NbCell2D):
m1.insertNextCell(NORM_QUAD4,4,Connectivities[4*i:4*(i+1)])
- m1.finishInsertingCells()
m1.changeSpaceDimension(3)
Definition of 1D mesh
m2.insertNextCell(NORM_SEG2,2,conn[0:2])
m2.insertNextCell(NORM_SEG2,2,conn[2:4])
m2.insertNextCell(NORM_SEG2,2,conn[4:6])
- m2.finishInsertingCells()
myCoords1D=DataArrayDouble.New()
myCoords1D.setValues(coords,4,1)
m2.setCoords(myCoords1D)
Finally thanks to o2n we know the connectivity of all 7 hexagons using the coordinates stored in d3.
-Do not forget to invoke MEDCouplingUMesh.finishInsertingCells() (this last bit should disappear after the release 6.6) ::
-
for i in xrange(7):
m.insertNextCell(NORM_POLYGON,o2n[6*i:6*(i+1)].getValues())
pass
- m.finishInsertingCells()
Check that m is coherent. ::
faciliter l'accès et le repérage des données. C'est par exemple une différence essentielle avec le
modèle MED fichier comme on le verra plus tard.
-.. note:: La méthode similaire permettant d'agréger par composante (plutôt que par tuples) s'appelle ``Meld()``.
+.. note:: La méthode permettant d'agréger par composante (c'est-à-dire de concaténer des tableaux
+ colonne par colonne, plutôt que par tuples) s'appelle ``Meld()``.
Trouver les tuples égaux
~~~~~~~~~~~~~~~~~~~~~~~~
cell_connec = o2n[6*i:6*(i+1)]
m.insertNextCell(mc.NORM_POLYGON, cell_connec.getValues())
pass
- m.finishInsertingCells()
-
-.. note:: Après SALOME 6.6, l'appel à ``MEDCouplingUMesh.finishInsertingCells()`` n'est plus nécessaire.
Vérifier que ``m`` est correct et ne contient pas d'anomalie. ::
22,27,29,28,37,42,44,43, 30,41,31,33,45,56,46,48, 31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47,
31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51, 41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53,
37,42,44,43,52,57,59,58]
- mesh3D=MEDCouplingUMesh.New("mesh3D",3);
- mesh3D.allocateCells(18);
+ mesh3D=MEDCouplingUMesh.New("mesh3D",3)
+ mesh3D.allocateCells(18)
mesh3D.insertNextCell(NORM_HEXA8,conn[0:8]); mesh3D.insertNextCell(NORM_POLYHED,conn[8:51]); mesh3D.insertNextCell(NORM_HEXA8,conn[51:59]); mesh3D.insertNextCell(NORM_HEXA8,conn[59:67]); mesh3D.insertNextCell(NORM_POLYHED,conn[67:110]); mesh3D.insertNextCell(NORM_HEXA8,conn[110:118]);
mesh3D.insertNextCell(NORM_HEXA8,conn[118:126]); mesh3D.insertNextCell(NORM_POLYHED,conn[126:169]); mesh3D.insertNextCell(NORM_HEXA8,conn[169:177]); mesh3D.insertNextCell(NORM_HEXA8,conn[177:185]); mesh3D.insertNextCell(NORM_POLYHED,conn[185:228]); mesh3D.insertNextCell(NORM_HEXA8,conn[228:236]);
mesh3D.insertNextCell(NORM_HEXA8,conn[236:244]); mesh3D.insertNextCell(NORM_POLYHED,conn[244:287]); mesh3D.insertNextCell(NORM_HEXA8,conn[287:295]); mesh3D.insertNextCell(NORM_HEXA8,conn[295:303]); mesh3D.insertNextCell(NORM_POLYHED,conn[303:346]); mesh3D.insertNextCell(NORM_HEXA8,conn[346:354]);
- mesh3D.finishInsertingCells();
- myCoords=DataArrayDouble.New(coords,60,3);
+ myCoords=DataArrayDouble.New(coords,60,3)
myCoords.setInfoOnComponents(["X [m]","Y [m]","Z [m]"])
- mesh3D.setCoords(myCoords);
+ mesh3D.setCoords(myCoords)
mesh3D.orientCorrectlyPolyhedrons()
mesh3D.sortCellsInMEDFileFrmt()
mesh3D.checkCoherency()
22,27,29,28,37,42,44,43, 30,41,31,33,45,56,46,48, 31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47,
31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51, 41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53,
37,42,44,43,52,57,59,58]
- mesh3D = mc.MEDCouplingUMesh("mesh3D",3);
- mesh3D.allocateCells(18);
+ mesh3D = mc.MEDCouplingUMesh("mesh3D",3)
+ mesh3D.allocateCells(18)
mesh3D.insertNextCell(mc.NORM_HEXA8,conn[0:8]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[8:51]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[51:59]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[59:67]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[67:110]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[110:118]);
mesh3D.insertNextCell(mc.NORM_HEXA8,conn[118:126]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[126:169]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[169:177]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[177:185]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[185:228]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[228:236]);
mesh3D.insertNextCell(mc.NORM_HEXA8,conn[236:244]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[244:287]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[287:295]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[295:303]); mesh3D.insertNextCell(mc.NORM_POLYHED,conn[303:346]); mesh3D.insertNextCell(mc.NORM_HEXA8,conn[346:354]);
- mesh3D.finishInsertingCells();
- myCoords = mc.DataArrayDouble(coords,60,3);
+ myCoords = mc.DataArrayDouble(coords,60,3)
myCoords.setInfoOnComponents(["X [m]","Y [m]","Z [m]"])
- mesh3D.setCoords(myCoords);
+ mesh3D.setCoords(myCoords)
mesh3D.orientCorrectlyPolyhedrons()
mesh3D.sortCellsInMEDFileFrmt()
mesh3D.checkCoherency()
.. note:: Pour information pour merger deux (ou plus) maillages non structurés, il faut invoquer ``MEDCouplingUMesh.MergeUMeshes()``
puis ``MEDCouplingUMesh.mergeNodes()`` sur le résultat, et enfin ``MEDCouplingUMesh.zipConnectivity()``.
+.. _exo-umesh-desc-connec:
+
Connectivité descendante
~~~~~~~~~~~~~~~~~~~~~~~~
* YACS, to create visualization nodes
* create a Python mock-up script and use the standard Python interpreter whilst benefiting
-from the ParaViS graphical interface
+ from the ParaViS graphical interface
Implementation start
~~~~~~~~~~~~~~~~~~~~
arr=DataArrayDouble(31,1) ; arr.iota(0.)
m0.setCoords(arr,arr)
m0=m0.buildUnstructured()
- m00=m0[::2] ; m00.simplexize(0) ; m01=m0[1::2]
+ m00=m0[::2] # Extract even cells
+ m00.simplexize(0)
+ m01=m0[1::2]
m0=MEDCouplingUMesh.MergeUMeshes([m00,m01])
- m0.getCoords()[:]*=1/15.
+ m0.getCoords()[:]*=1/15. # Illustrate how to quickly rescale a mesh
m0.setName("mesh")
.. note:: The call to setName() on "m0" is mandatory. Don't forget that the correct naming of the meshes is paramount in the MED file context.
arr = ml.DataArrayDouble(31,1) ; arr.iota(0.)
m0.setCoords(arr,arr)
m0 = m0.buildUnstructured()
- m00 = m0[::2] # Extract even cells
+ m00 = m0[::2] # Extract even cells
m00.simplexize(0)
m01 = m0[1::2]
m0 = ml.MEDCouplingUMesh.MergeUMeshes([m00,m01])
- m0.getCoords()[:] *= 1/15.
+ m0.getCoords()[:] *= 1/15. # Illustrate how to quickly rescale a mesh
m0.setName("mesh")
.. note:: Le ``setName()`` sur "m0" est obligatoire. Ne pas oublier que dans le contexte MED fichier
First of all, creation of a mesh "targetMesh". ::
- targetCoords=[-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 ];
- targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
- targetMesh=MEDCouplingUMesh.New("MyMesh",2);
- targetMesh.allocateCells(5);
- targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
- targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
- targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
- targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
- targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
- targetMesh.finishInsertingCells();
- myCoords=DataArrayDouble.New(targetCoords,9,2);
- targetMesh.setCoords(myCoords);
+ targetCoords=[-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 ]
+ targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
+ targetMesh=MEDCouplingUMesh.New("MyMesh",2)
+ targetMesh.allocateCells(5)
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7])
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
+ myCoords=DataArrayDouble.New(targetCoords,9,2)
+ targetMesh.setCoords(myCoords)
.. note:: targetMesh is grouped by geometric type.
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[0:4])
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[10:14])
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[14:18])
- targetMesh.finishInsertingCells()
myCoords = ml.DataArrayDouble(targetCoords,9,2)
myCoords.setInfoOnComponents(["X [km]","YY [mm]"])
targetMesh.setCoords(myCoords)
.. note:: Le maillage ``targetMesh`` est ordonné par type géométrique.
Nous construisons ensuite ``targetMesh1`` représentant les sous-constituants (*faces*) du maillage
-``targetMesh`` reduits aux cellules [3,4,7,8]. Cela peut par exemple représenter un ensemble d'intérêt pour un calcul : ::
+``targetMesh``, et nous en extrayons seulement les cellules (donc ici des surfaces) [3,4,7,8].
+Pour plus de détails sur la connectivité descendante,
+consulter la section :ref:`exo-umesh-desc-connec` du deuxième exercise.
+Cet ensemble peut par exemple représenter un ensemble d'intérêt pour un calcul : ::
targetMeshConsti, _, _, _, _ = targetMesh.buildDescendingConnectivity()
targetMesh1 = targetMeshConsti[[3,4,7,8]]
First of all, creation of a mesh "targetMesh". ::
- targetCoords=[-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 ];
- targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
- targetMesh=MEDCouplingUMesh.New("MyMesh",2);
- targetMesh.allocateCells(5);
- targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
- targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
- targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
- targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
- targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
- targetMesh.finishInsertingCells();
- myCoords=DataArrayDouble.New(targetCoords,9,2);
+ targetCoords=[-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 ]
+ targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
+ targetMesh=MEDCouplingUMesh.New("MyMesh",2)
+ targetMesh.allocateCells(5)
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7])
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
+ myCoords=DataArrayDouble.New(targetCoords,9,2)
myCoords.setInfoOnComponents(["X [km]","YY [mm]"])
- targetMesh.setCoords(myCoords);
+ targetMesh.setCoords(myCoords)
.. note:: targetMesh is ordered by geometric type.
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[0:4])
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[10:14])
targetMesh.insertNextCell(ml.NORM_QUAD4,4,targetConn[14:18])
- targetMesh.finishInsertingCells()
myCoords = ml.DataArrayDouble(targetCoords,9,2)
myCoords.setInfoOnComponents(["X [km]","YY [mm]"])
targetMesh.setCoords(myCoords)