-#from med import medprofile
-#from med import medlocalization
-#from med import medlink
-
-# La fonction createZfield1 ne sert plus à partir du 12/07/2017
-def createZfield1(fichierMaillage):
- """
- Complete the mesh for Telemac.
- Add a field on nodes, named "BOTTOM", of type double, containing z coordinates of nodes.
- createZfield1 is used after interpolZ. createZfield1 is base on med file interface.
- There is an alternate method based on MEDLoader, equivalent (createZfield2).
- The file <fichierMaillage>F.med produced by interpolz must exist, and is modified.
- fichierMaillage : 2D (x,y) med file produced by SMESH and used by interpolZ.
- return <fichierMaillage>F.med : med file containing the field "BOTTOM"
- """
-
- basename = fichierMaillage[:-4]
- fichierFMaillage = basename + 'F.med'
- print fichierFMaillage
-
- # --- ouverture du fichier
- fid=medfile.MEDfileOpen(fichierFMaillage, medenum.MED_ACC_RDEXT)
-
- maa, sdim, mdim, meshtype, desc, dtunit, sort, nstep, repere, axisname, axisunit = medmesh.MEDmeshInfo(fid, 1)
- print "Maillage de nom : %s , de dimension : %d , et de type %s"%(maa,mdim,meshtype)
- print " Dimension de l'espace : %d"%(sdim)
-
- # --- Combien de noeuds a lire ?
- nnoe, chgt, trsf = medmesh.MEDmeshnEntity(fid, maa, medenum.MED_NO_DT, medenum.MED_NO_IT,
- medenum.MED_NODE, medenum.MED_NONE,
- medenum.MED_COORDINATE, medenum.MED_NO_CMODE)
-
- if nnoe > 0:
- # --- Allocations memoire
- # --- table des coordonnees flt : (dimension * nombre de noeuds )
- coords = medfile.MEDFLOAT(nnoe*sdim)
- # --- table des numeros des noeuds
- numnoe = medfile.MEDINT(nnoe)
-
- # --- Lecture des composantes des coordonnees des noeuds
- medmesh.MEDmeshNodeCoordinateRd(fid, maa, medenum.MED_NO_DT, medenum.MED_NO_IT,
- medenum.MED_FULL_INTERLACE, coords)
- #print "Valeur de coords : ",coords
- valz=medfile.MEDFLOAT([z for (i,z) in enumerate(coords) if i%3==2])
- #print "Valeur de z : ",valz
-
- # --- creation du champ
- nomcha1 = "BOTTOM"
- ncomp1 = 1
- # --1234567890123456--
- comp1 = "z "
- unit1 = "m "
- dtunit = ""
- medfield.MEDfieldCr(fid, nomcha1, medfile.MED_FLOAT64,
- ncomp1, comp1, unit1, dtunit, maa)
-
- # --- ecriture du champ
-
- medfield.MEDfieldValueWr(fid, nomcha1, 0, medenum.MED_NO_IT, 0.0,
- medenum.MED_NODE, medenum.MED_NONE,
- medenum.MED_FULL_INTERLACE, medenum.MED_ALL_CONSTITUENT, nnoe, valz)
- # --- fermeture du fichier
- medfile.MEDfileClose(fid)
- print fichierFMaillage, " field BOTTOM OK"
-
-# -----------------------------------------------------------------------------
-
-# La fonction createZfield2 ne sert plus à partir du 12/07/2017
-def createZfield2(fichierMaillage):
- """
- Complete the mesh for Telemac.
- Add a field on nodes, named "BOTTOM", of type double, containing z coordinates of nodes.
- createZfield2 is used after interpolZ. createZfield1 is base on MEDLoader interface.
- There is an alternate method based on Med file, equivalent (createZfield1).
- fichierMaillage : 2D (x,y) med file produced by SMESH and used by interpolZ.
- return <fichierMaillage>F.med : med file containing the field "BOTTOM"
- """
-
- import MEDLoader
- from MEDLoader import MEDCouplingFieldDouble, ON_NODES, DataArrayDouble, MEDFileMesh
-
- basename = fichierMaillage[:-4]
- fichierZMaillage = basename + 'Z.med'
- fichierFMaillage = basename + 'F.med'
- print fichierFMaillage
-
- mymesh = MEDLoader.ReadUMeshFromFile(fichierZMaillage,0)
- fieldOnNodes=MEDCouplingFieldDouble.New(ON_NODES)
- fieldOnNodes.setName("BOTTOM")
- fieldOnNodes.setMesh(mymesh)
- fieldOnNodes.setArray(mymesh.getCoords()[:,2])
- fieldOnNodes.setTime(0.0,0,-1)
- mm=MEDFileMesh.New(fichierZMaillage)
- mm.write(fichierFMaillage,2)
- MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fichierFMaillage,fieldOnNodes)
- print fichierFMaillage, " field BOTTOM OK"