Beginning of implementation
~~~~~~~~~~~~~~~~~~~~~~~~~~~
-To implement this exercice we use the python language script and import the MEDCoupling and MEDLoader parts of the MED module. We need also mathematical functions, so we import the python math module::
+To implement this exercice we use the python language script and import the medcoupling module. We need also mathematical functions, so we import the python math module::
- from MEDCoupling import *
- from MEDLoader import *
+ import medcoupling as mc
from math import *
You must define 3 variables for space dimension, number of nodes on each dimension and total number of nodes::
::
- mesh=MEDCouplingUMesh.New()
+ mesh = mc.MEDCouplingUMesh.New()
mesh.setMeshDimension(3)
mesh.allocateCells(...)
mesh.setName("3Dcube")
for i in range(N):
coordinates.append(...)
- myCoords = DataArrayDouble.New()
+ myCoords = mc.DataArrayDouble.New()
myCoords.setValues(coordinates,nbOfNodes,3)
mesh.setCoords(myCoords)
# Adding cells in meshing
for i in range(nbOfCells):
- mesh.insertNextCell(NORM_HEXA8,8,connectivity[8*i:8*(i+1)])
+ mesh.insertNextCell(mc.NORM_HEXA8,8,connectivity[8*i:8*(i+1)])
pass
# Check mesh consistency:
coordinates.append(...)
...
Connectivities = [...]
- myCoords = DataArrayDouble.New()
+ myCoords = mc.DataArrayDouble.New()
myCoords.setValues(coordinates,NbNode2D,MeshDim2D)
- m1 = MEDCouplingUMesh.New()
+ m1 = mc.MEDCouplingUMesh.New()
m1.setMeshDimension(MeshDim2D)
m1.allocateCells(NbCell2D)
m1.setCoords(myCoords)
m1.setName("2D_Support")
for i in range(NbCell2D):
- m1.insertNextCell(NORM_QUAD4,4,Connectivities[4*i:4*(i+1)])
+ m1.insertNextCell(mc.NORM_QUAD4,4,Connectivities[4*i:4*(i+1)])
m1.changeSpaceDimension(3)
Definition of 1D mesh
coords = [ ... ]
conn = [ ... ]
- m2 = MEDCouplingUMesh.New()
+ m2 = mc.MEDCouplingUMesh.New()
m2.setMeshDimension(1)
m2.allocateCells(3)
- m2.insertNextCell(NORM_SEG2,2,conn[0:2])
- m2.insertNextCell(NORM_SEG2,2,conn[2:4])
- m2.insertNextCell(NORM_SEG2,2,conn[4:6])
- myCoords1D=DataArrayDouble.New()
+ m2.insertNextCell(mc.NORM_SEG2,2,conn[0:2])
+ m2.insertNextCell(mc.NORM_SEG2,2,conn[2:4])
+ m2.insertNextCell(mc.NORM_SEG2,2,conn[4:6])
+ myCoords1D=mc.DataArrayDouble.New()
myCoords1D.setValues(coords,4,1)
m2.setCoords(myCoords1D)
m2.changeSpaceDimension(3)
::
- mesh=MEDCouplingCMesh.New()
- coordsX=DataArrayDouble.New()
+ mesh=mc.MEDCouplingCMesh.New()
+ coordsX=mc.DataArrayDouble.New()
arrX=[ ... ]
coordsX.setValues(arrX,4,1)
- coordsY=DataArrayDouble.New()
+ coordsY=mc.DataArrayDouble.New()
arrY=[ ... ]
coordsY.setValues(arrY,4,1)
- coordsZ=DataArrayDouble.New()
+ coordsZ=mc.DataArrayDouble.New()
arrZ=[ ... ]
coordsZ.setValues(arrZ,4,1)
mesh.setCoords(coordsX,coordsY,coordsZ)
Generally ids cells using in group are known. So you just need put these ids in a DataArray.
::
- tabIdCells = DataArrayInt.New()
+ tabIdCells = mc.DataArrayInt.New()
IdCells = [ ... ]
tabIdCells.setValues(IdCells,...)
::
# Passing MEDCoupling to MEDFile
- fmeshU = MEDFileUMesh.New()
+ fmeshU = mc.MEDFileUMesh.New()
fmeshU.setName("Grid")
fmeshU.setDescription("IHopeToConvinceLastMEDMEMUsers")
myCoords = meshU.getCoords()
# => Definition of the mesh support
# => Definition of field name
# => Definition of field nature
- field = MEDCouplingFieldDouble.New(ON_CELLS)
+ field = mc.MEDCouplingFieldDouble.New(ON_CELLS)
field.setMesh(mesh)
field.setName("field")
field.setNature(ExtensiveMaximum)
# Computing and setting field values
- myCoords=DataArrayDouble.New()
+ myCoords=mc.DataArrayDouble.New()
sampleTab=[]
bar = mesh.computeCellCenterOfMass()
print(bar.getNbOfElems())
::
medFileName = "MEDCoupling_Extrudedcube3D.med"
- MEDLoader.WriteUMesh(medFileName,meshU,True)
+ mc.WriteUMesh(medFileName,meshU,True)
.. note:: True / False in Write* functions : True for overwriting existing file and False for adding in existing file
medFileName = "MEDCoupling_cube3D.med"
meshes=[mesh2D,mesh]
- MEDLoader.WriteUMeshes(medFileName,meshes,True)
+ mc.WriteUMeshes(medFileName,meshes,True)
Group Case
````````````
::
- MEDLoader.WriteField(medFileName,field,False)
+ mc.WriteField(medFileName,field,False)
Visualize the mesh with the SMESH module of Salome
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~