medcoupling 9.13.0__cp310-cp310-win_amd64.whl → 9.15.0__cp310-cp310-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CaseIO.py +27 -8
- CaseReader.py +491 -275
- CaseWriter.py +344 -172
- MCMailFileReader.py +412 -0
- MEDCouplingCompat.py +221 -0
- MEDCouplingRemapper.py +407 -4
- MEDLoader.py +267 -0
- MEDLoaderFinalize.py +626 -12
- MEDLoaderSplitter.py +141 -100
- MEDRenumber.py +221 -0
- VTKReader.py +314 -151
- _MEDCouplingCompat.pyd +0 -0
- _MEDCouplingRemapper.pyd +0 -0
- _MEDLoader.pyd +0 -0
- _MEDPartitioner.pyd +0 -0
- _MEDRenumber.pyd +0 -0
- _medcoupling.pyd +0 -0
- geom2medcoupling.py +34 -17
- hdf5.dll +0 -0
- interpkernel.dll +0 -0
- libxml2.dll +0 -0
- medC.dll +0 -0
- {medcoupling-9.13.0.dist-info → medcoupling-9.15.0.dist-info}/METADATA +12 -17
- medcoupling-9.15.0.dist-info/RECORD +31 -0
- medcoupling.dll +0 -0
- medcoupling.py +467 -4
- medcouplingremapper.dll +0 -0
- medicoco.dll +0 -0
- medloader.dll +0 -0
- medpartitionercpp.dll +0 -0
- renumbercpp.dll +0 -0
- vtk2medcoupling.py +273 -17
- medcoupling-9.13.0.dist-info/RECORD +0 -30
- {medcoupling-9.13.0.dist-info → medcoupling-9.15.0.dist-info}/WHEEL +0 -0
CaseReader.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: iso-8859-1 -*-
|
2
|
-
# Copyright (C) 2007-
|
2
|
+
# Copyright (C) 2007-2025 CEA, EDF
|
3
3
|
#
|
4
4
|
# This library is free software; you can redistribute it and/or
|
5
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -23,399 +23,615 @@
|
|
23
23
|
import numpy as np
|
24
24
|
from medcoupling import *
|
25
25
|
from CaseIO import CaseIO
|
26
|
-
import sys,re,os
|
26
|
+
import sys, re, os
|
27
|
+
|
27
28
|
|
28
29
|
class CaseReader(CaseIO):
|
29
|
-
"""
|
30
|
+
"""Converting a file in the Case format (Ensight) to the MED format.
|
30
31
|
A new file with the same base name and the .med extension is created.
|
31
32
|
"""
|
32
33
|
|
33
34
|
@classmethod
|
34
|
-
def New(cls,fileName):
|
35
|
-
"""
|
35
|
+
def New(cls, fileName):
|
36
|
+
"""Static constructor."""
|
36
37
|
return CaseReader(fileName)
|
37
38
|
pass
|
38
39
|
|
39
|
-
def __init__(self,fileName):
|
40
|
-
"""
|
40
|
+
def __init__(self, fileName):
|
41
|
+
"""Constructor"""
|
41
42
|
CaseIO.__init__(self)
|
42
|
-
self._fileName=fileName
|
43
|
-
self._dirName=os.path.dirname(self._fileName)
|
43
|
+
self._fileName = fileName
|
44
|
+
self._dirName = os.path.dirname(self._fileName)
|
44
45
|
pass
|
45
46
|
|
46
|
-
def __traduceMesh(self,name,typ,coords,cells):
|
47
|
-
"""
|
47
|
+
def __traduceMesh(self, name, typ, coords, cells):
|
48
|
+
"""Convert a CASE mesh into a MEDCouplingUMesh."""
|
48
49
|
name = name.decode("ascii")
|
49
|
-
nbCoords=len(coords)
|
50
|
-
coo=np.array(coords,dtype="float64")
|
51
|
-
coo=
|
52
|
-
|
53
|
-
|
50
|
+
nbCoords = len(coords)
|
51
|
+
coo = np.array(coords, dtype="float64")
|
52
|
+
coo = coo.reshape(nbCoords, 3)
|
53
|
+
coo = DataArrayDouble(coo)
|
54
|
+
coo = coo.fromNoInterlace()
|
55
|
+
ct = self.dictMCTyp2[typ]
|
56
|
+
m = MEDCouplingUMesh(name, MEDCouplingUMesh.GetDimensionOfGeometricType(ct))
|
54
57
|
m.setCoords(coo)
|
55
|
-
nbNodesPerCell=MEDCouplingMesh.GetNumberOfNodesOfGeometricType(ct)
|
56
|
-
cI=DataArrayInt(len(cells)+1)
|
58
|
+
nbNodesPerCell = MEDCouplingMesh.GetNumberOfNodesOfGeometricType(ct)
|
59
|
+
cI = DataArrayInt(len(cells) + 1)
|
60
|
+
cI.iota()
|
61
|
+
cI *= nbNodesPerCell + 1
|
57
62
|
#
|
58
|
-
cells2=cells.reshape(len(cells),nbNodesPerCell)
|
59
|
-
c2=DataArrayInt(
|
60
|
-
|
61
|
-
|
63
|
+
cells2 = cells.reshape(len(cells), nbNodesPerCell)
|
64
|
+
c2 = DataArrayInt(
|
65
|
+
np.array(cells2, dtype="int{}".format(MEDCouplingSizeOfIDs()))
|
66
|
+
)
|
67
|
+
c = DataArrayInt(len(cells), nbNodesPerCell + 1)
|
68
|
+
c[:, 0] = ct
|
69
|
+
c[:, 1:] = c2 - 1
|
70
|
+
c.rearrange(1)
|
71
|
+
m.setConnectivity(c, cI, True)
|
62
72
|
m.checkConsistency()
|
63
73
|
return m
|
64
74
|
|
65
|
-
def __traduceMeshForPolyhed(self,name,coords,arr0,arr1,arr2):
|
66
|
-
nbCoords=len(coords)
|
67
|
-
coo=np.array(coords,dtype="float64")
|
68
|
-
coo=
|
69
|
-
|
75
|
+
def __traduceMeshForPolyhed(self, name, coords, arr0, arr1, arr2):
|
76
|
+
nbCoords = len(coords)
|
77
|
+
coo = np.array(coords, dtype="float64")
|
78
|
+
coo = coo.reshape(nbCoords, 3)
|
79
|
+
coo = DataArrayDouble(coo)
|
80
|
+
coo = coo.fromNoInterlace()
|
81
|
+
m = MEDCouplingUMesh(name, 3)
|
70
82
|
m.setCoords(coo)
|
71
83
|
#
|
72
|
-
arr2=arr2[:]-1
|
73
|
-
arr0mc0=DataArrayInt(arr0)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
84
|
+
arr2 = arr2[:] - 1
|
85
|
+
arr0mc0 = DataArrayInt(arr0)
|
86
|
+
arr0mc0.computeOffsetsFull()
|
87
|
+
arr0mc1 = DataArrayInt(arr0).deepCopy()
|
88
|
+
arr0mc2 = DataArrayInt(len(arr0), 2)
|
89
|
+
arr0mc2[:, 0] = DataArrayInt(arr0) - 1
|
90
|
+
arr0mc2[:, 1] = 1
|
91
|
+
arr0mc2.rearrange(1)
|
92
|
+
arr0mc2.computeOffsetsFull()
|
93
|
+
arr0mc3 = DataArrayInt.Range(0, 2 * len(arr0), 2).buildExplicitArrByRanges(
|
94
|
+
arr0mc2
|
95
|
+
)
|
96
|
+
arr1mc0 = DataArrayInt(arr1)
|
97
|
+
arr1mc0.computeOffsetsFull()
|
98
|
+
arr1mc1 = arr1mc0[arr0mc0]
|
99
|
+
arr1mc1[1:] += arr0mc0[1:]
|
100
|
+
arr1mc2 = DataArrayInt(arr1).deepCopy()
|
101
|
+
arr1mc2 += 1
|
102
|
+
arr1mc2.computeOffsetsFull()
|
103
|
+
arr2mc0 = (arr1mc2[1:])[arr0mc3]
|
81
104
|
#
|
82
|
-
c=DataArrayInt(arr1.size+arr2.size)
|
83
|
-
c[arr1mc1[:-1]]=NORM_POLYHED
|
84
|
-
c[arr2mc0]
|
85
|
-
a=arr2mc0.buildUnion(arr1mc1[:-1]).buildComplement(len(c))
|
86
|
-
c[a]=DataArrayInt(arr2)
|
105
|
+
c = DataArrayInt(arr1.size + arr2.size)
|
106
|
+
c[arr1mc1[:-1]] = NORM_POLYHED
|
107
|
+
c[arr2mc0] = -1
|
108
|
+
a = arr2mc0.buildUnion(arr1mc1[:-1]).buildComplement(len(c))
|
109
|
+
c[a] = DataArrayInt(arr2)
|
87
110
|
#
|
88
|
-
m.setConnectivity(c,arr1mc1,True)
|
111
|
+
m.setConnectivity(c, arr1mc1, True)
|
89
112
|
m.checkConsistency()
|
90
113
|
return m
|
91
114
|
|
92
|
-
def __traduceMeshForPolygon(self,name,coords,arr0,arr1):
|
93
|
-
nbCoords=len(coords)
|
94
|
-
coo=np.array(coords,dtype="float64")
|
95
|
-
coo=
|
96
|
-
|
115
|
+
def __traduceMeshForPolygon(self, name, coords, arr0, arr1):
|
116
|
+
nbCoords = len(coords)
|
117
|
+
coo = np.array(coords, dtype="float64")
|
118
|
+
coo = coo.reshape(nbCoords, 3)
|
119
|
+
coo = DataArrayDouble(coo)
|
120
|
+
coo = coo.fromNoInterlace()
|
121
|
+
m = MEDCouplingUMesh(name, 2)
|
97
122
|
m.setCoords(coo)
|
98
123
|
#
|
99
|
-
arr0_0=DataArrayInt(arr0+1)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
124
|
+
arr0_0 = DataArrayInt(arr0 + 1)
|
125
|
+
arr0_0.computeOffsetsFull()
|
126
|
+
arr0_1 = DataArrayInt(len(arr0), 2)
|
127
|
+
arr0_1[:, 1] = DataArrayInt(arr0)
|
128
|
+
arr0_1[:, 0] = 1
|
129
|
+
arr0_1.rearrange(1)
|
130
|
+
arr0_1.computeOffsetsFull()
|
131
|
+
arr0_2 = DataArrayInt.Range(1, 2 * len(arr0), 2).buildExplicitArrByRanges(
|
132
|
+
arr0_1
|
133
|
+
)
|
134
|
+
c = DataArrayInt(len(arr0) + len(arr1))
|
135
|
+
c[:] = 0
|
136
|
+
c[arr0_0[:-1]] = NORM_POLYGON
|
137
|
+
c[arr0_2] = DataArrayInt(arr1 - 1)
|
104
138
|
#
|
105
|
-
m.setConnectivity(c,arr0_0,True)
|
139
|
+
m.setConnectivity(c, arr0_0, True)
|
106
140
|
m.checkConsistency()
|
107
141
|
return m
|
108
142
|
|
109
|
-
def __convertGeo2MED(self,geoFileName):
|
110
|
-
"""
|
111
|
-
fd=open(os.path.join(self._dirName,geoFileName),"r+b")
|
112
|
-
|
143
|
+
def __convertGeo2MED(self, geoFileName):
|
144
|
+
"""Convert all the geometry (all the meshes) contained in the CASE file into MEDCouplingUMesh'es."""
|
145
|
+
fd = open(os.path.join(self._dirName, geoFileName), "r+b")
|
146
|
+
fd.seek(0, 2)
|
147
|
+
end = fd.tell()
|
148
|
+
fd.seek(0)
|
149
|
+
title = fd.read(80)
|
150
|
+
title = title.strip().lower()
|
113
151
|
if b"binary" not in title:
|
114
|
-
raise Exception(
|
152
|
+
raise Exception(
|
153
|
+
"Error only binary geo files are supported for the moment !"
|
154
|
+
)
|
115
155
|
pass
|
116
|
-
zeType=True
|
156
|
+
zeType = True
|
117
157
|
if b"fortran" in title:
|
118
|
-
mcmeshes=self.__convertGeo2MEDFortran(fd,end)
|
158
|
+
mcmeshes = self.__convertGeo2MEDFortran(fd, end)
|
159
|
+
zeType = False
|
119
160
|
else:
|
120
|
-
mcmeshes=self.__convertGeo2MEDC(fd,end)
|
161
|
+
mcmeshes = self.__convertGeo2MEDC(fd, end)
|
121
162
|
#
|
122
|
-
ms=MEDFileMeshes()
|
163
|
+
ms = MEDFileMeshes()
|
123
164
|
ms.resize(len(mcmeshes))
|
124
|
-
for i,m in enumerate(mcmeshes):
|
125
|
-
mlm=MEDFileUMesh()
|
126
|
-
mlm.setMeshAtLevel(0,m)
|
127
|
-
ms.setMeshAtPos(i,mlm)
|
165
|
+
for i, m in enumerate(mcmeshes):
|
166
|
+
mlm = MEDFileUMesh()
|
167
|
+
mlm.setMeshAtLevel(0, m)
|
168
|
+
ms.setMeshAtPos(i, mlm)
|
128
169
|
pass
|
129
|
-
return mcmeshes,ms,zeType
|
170
|
+
return mcmeshes, ms, zeType
|
130
171
|
|
131
|
-
def __convertGeo2MEDFortran(self,fd,end):
|
132
|
-
mcmeshes=[]
|
133
|
-
fd.read(80)
|
134
|
-
fd.read(80)
|
135
|
-
fd.read(80)
|
136
|
-
fd.read(80)
|
137
|
-
pos=fd.tell()
|
138
|
-
elt=fd.read(80)
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
172
|
+
def __convertGeo2MEDFortran(self, fd, end):
|
173
|
+
mcmeshes = []
|
174
|
+
fd.read(80) # comment 1
|
175
|
+
fd.read(80) # comment 2
|
176
|
+
fd.read(80) # node id
|
177
|
+
fd.read(80) # element id
|
178
|
+
pos = fd.tell()
|
179
|
+
elt = fd.read(80)
|
180
|
+
elt = elt.strip()
|
181
|
+
pos = fd.tell()
|
182
|
+
mcmeshes2 = []
|
183
|
+
typ = b"part"
|
184
|
+
nbOfTurn = 0
|
185
|
+
while abs(pos - end) > 8 and b"part" in typ:
|
143
186
|
if b"part" not in elt:
|
144
187
|
raise Exception("Error on reading mesh fortran #1 !")
|
145
|
-
fd.seek(fd.tell()+4)# skip #
|
146
|
-
tmp=fd.read(80)
|
147
|
-
tmp
|
188
|
+
fd.seek(fd.tell() + 4) # skip #
|
189
|
+
tmp = fd.read(80)
|
190
|
+
meshName = tmp.split("P")[-1]
|
191
|
+
tmp = fd.read(80)
|
148
192
|
if b"coordinates" not in tmp:
|
149
193
|
raise Exception("Error on reading mesh fortran #2 !")
|
150
|
-
pos=fd.tell()
|
151
|
-
if nbOfTurn==0:
|
152
|
-
pos+=76
|
194
|
+
pos = fd.tell() # 644
|
195
|
+
if nbOfTurn == 0:
|
196
|
+
pos += 76 # what else ?
|
153
197
|
else:
|
154
|
-
pos+=40
|
198
|
+
pos += 40
|
155
199
|
pass
|
156
|
-
nbNodes=np.memmap(
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
200
|
+
nbNodes = np.memmap(
|
201
|
+
fd, dtype=">i4", mode="r", offset=int(pos), shape=(1,)
|
202
|
+
).tolist()[0]
|
203
|
+
pos += 12 # what else ?
|
204
|
+
a = np.memmap(fd, dtype=">f4", mode="r", offset=int(pos), shape=(nbNodes))
|
205
|
+
b = np.memmap(
|
206
|
+
fd,
|
207
|
+
dtype=">f4",
|
208
|
+
mode="r",
|
209
|
+
offset=int(pos + nbNodes * 4 + 2 * 4),
|
210
|
+
shape=(nbNodes),
|
211
|
+
)
|
212
|
+
c = np.memmap(
|
213
|
+
fd,
|
214
|
+
dtype=">f4",
|
215
|
+
mode="r",
|
216
|
+
offset=int(pos + nbNodes * 2 * 4 + 4 * 4),
|
217
|
+
shape=(nbNodes),
|
218
|
+
)
|
219
|
+
coo = np.zeros(dtype=">f4", shape=(nbNodes * 3))
|
220
|
+
coo[:nbNodes] = a
|
221
|
+
coo[nbNodes : 2 * nbNodes] = b
|
222
|
+
coo[2 * nbNodes :] = c
|
223
|
+
coo = coo.reshape(nbNodes, 3)
|
224
|
+
pos += nbNodes * 3 * 4
|
225
|
+
fd.seek(pos) # np.array(0,dtype='float%i'%(typeOfCoo)).nbytes
|
226
|
+
typ = fd.read(80).strip()
|
227
|
+
pos = fd.tell()
|
228
|
+
zeK = b""
|
167
229
|
for k in self.dictMCTyp2:
|
168
230
|
if k in typ:
|
169
|
-
zeK=k
|
231
|
+
zeK = k
|
170
232
|
break
|
171
233
|
pass
|
172
234
|
pass
|
173
|
-
pos+=8*4
|
174
|
-
nbCellsOfType=np.memmap(
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
fd
|
235
|
+
pos += 8 * 4 # yeh man !
|
236
|
+
nbCellsOfType = np.memmap(
|
237
|
+
fd, dtype=">i4", mode="r", offset=int(pos), shape=(1,)
|
238
|
+
).tolist()[0]
|
239
|
+
pos += 4 # for the number of cells
|
240
|
+
pos += 2 * 4 # because it's great !
|
241
|
+
nbNodesPerCell = MEDCouplingMesh.GetNumberOfNodesOfGeometricType(
|
242
|
+
self.dictMCTyp2[zeK]
|
243
|
+
)
|
244
|
+
nodalConn = np.memmap(
|
245
|
+
fd,
|
246
|
+
dtype=">i4",
|
247
|
+
mode="r",
|
248
|
+
offset=pos,
|
249
|
+
shape=(nbCellsOfType, nbNodesPerCell),
|
250
|
+
)
|
251
|
+
meshName = meshName.strip()
|
252
|
+
mcmeshes2.append(self.__traduceMesh(meshName, zeK, coo, nodalConn))
|
253
|
+
pos += nbNodesPerCell * nbCellsOfType * 4
|
254
|
+
if abs(pos - end) > 8:
|
255
|
+
fd.seek(pos)
|
256
|
+
elt = fd.read(80)
|
257
|
+
typ = elt[:]
|
258
|
+
pos += 80
|
184
259
|
pass
|
185
|
-
nbOfTurn+=1
|
260
|
+
nbOfTurn += 1
|
186
261
|
pass
|
187
|
-
#coo=mcmeshes2[0].getCoords() ; name=mcmeshes2[0].getName()
|
188
|
-
#for itmesh in mcmeshes2: itmesh.setCoords(coo)
|
189
|
-
#m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(mcmeshes2) ; m.setName(name)
|
190
|
-
#mcmeshes.append(m)
|
262
|
+
# coo=mcmeshes2[0].getCoords() ; name=mcmeshes2[0].getName()
|
263
|
+
# for itmesh in mcmeshes2: itmesh.setCoords(coo)
|
264
|
+
# m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(mcmeshes2) ; m.setName(name)
|
265
|
+
# mcmeshes.append(m)
|
191
266
|
return mcmeshes2
|
192
267
|
|
193
|
-
def __convertGeo2MEDC(self,fd,end):
|
194
|
-
#fd.readline()
|
195
|
-
#name=fd.readline().strip() ; fd.readline() ; fd.readline()
|
196
|
-
name=fd.read(80)
|
197
|
-
descrip=fd.read(80).strip()
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
268
|
+
def __convertGeo2MEDC(self, fd, end):
|
269
|
+
# fd.readline()
|
270
|
+
# name=fd.readline().strip() ; fd.readline() ; fd.readline()
|
271
|
+
name = fd.read(80)
|
272
|
+
descrip = fd.read(80).strip()
|
273
|
+
fd.read(80)
|
274
|
+
fd.read(80)
|
275
|
+
pos = fd.tell()
|
276
|
+
mcmeshes = []
|
277
|
+
elt = fd.read(80)
|
278
|
+
elt = elt.strip()
|
279
|
+
pos += 80
|
280
|
+
while pos != end:
|
202
281
|
if b"part" not in elt:
|
203
282
|
raise Exception("Error on reading mesh #1 !")
|
204
|
-
fd.seek(fd.tell()+4)
|
205
|
-
meshName=fd.read(80).strip()
|
206
|
-
if fd.read(len("coordinates"))!=b"coordinates":
|
283
|
+
fd.seek(fd.tell() + 4)
|
284
|
+
meshName = fd.read(80).strip()
|
285
|
+
if fd.read(len("coordinates")) != b"coordinates":
|
207
286
|
raise Exception("Error on reading mesh #2 !")
|
208
|
-
pos=fd.tell()
|
209
|
-
typeOfCoo=np.memmap(
|
210
|
-
|
211
|
-
|
212
|
-
pos+=4
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
287
|
+
pos = fd.tell()
|
288
|
+
typeOfCoo = np.memmap(
|
289
|
+
fd, dtype="byte", mode="r", offset=int(pos), shape=(1)
|
290
|
+
).tolist()[0]
|
291
|
+
pos += 1 + 17 * 4
|
292
|
+
nbNodes = np.memmap(
|
293
|
+
fd, dtype="int32", mode="r", offset=int(pos), shape=(1,)
|
294
|
+
).tolist()[0]
|
295
|
+
pos += 4
|
296
|
+
coo = np.memmap(
|
297
|
+
fd, dtype="float32", mode="r", offset=int(pos), shape=(nbNodes, 3)
|
298
|
+
)
|
299
|
+
pos += nbNodes * 3 * 4
|
300
|
+
fd.seek(pos) # np.array(0,dtype='float%i'%(typeOfCoo)).nbytes
|
301
|
+
typ = fd.read(80).strip()
|
302
|
+
pos = fd.tell()
|
303
|
+
mcmeshes2 = []
|
304
|
+
while pos != end and typ != b"part":
|
305
|
+
if typ[0] == 0:
|
306
|
+
pos += 1
|
307
|
+
continue
|
308
|
+
mctyp = self.dictMCTyp2[typ]
|
309
|
+
nbCellsOfType = np.memmap(
|
310
|
+
fd, dtype="int32", mode="r", offset=int(pos), shape=(1,)
|
311
|
+
).tolist()[0]
|
312
|
+
pos += 4
|
313
|
+
if mctyp != NORM_POLYHED and mctyp != NORM_POLYGON:
|
314
|
+
nbNodesPerCell = MEDCouplingMesh.GetNumberOfNodesOfGeometricType(
|
315
|
+
mctyp
|
316
|
+
)
|
317
|
+
cells = np.memmap(
|
318
|
+
fd,
|
319
|
+
dtype="int32",
|
320
|
+
mode="r",
|
321
|
+
offset=pos,
|
322
|
+
shape=(nbCellsOfType, nbNodesPerCell),
|
323
|
+
)
|
324
|
+
pos += nbCellsOfType * nbNodesPerCell * 4
|
325
|
+
fd.seek(pos)
|
326
|
+
mcmeshes2.append(self.__traduceMesh(meshName, typ, coo, cells))
|
327
|
+
elif mctyp == NORM_POLYHED:
|
328
|
+
nbOfFacesPerCell = np.memmap(
|
329
|
+
fd,
|
330
|
+
dtype="int32",
|
331
|
+
mode="r",
|
332
|
+
offset=int(pos),
|
333
|
+
shape=(nbCellsOfType,),
|
334
|
+
)
|
335
|
+
pos += nbCellsOfType * 4
|
336
|
+
szOfNbOfNodesPerFacePerCellArr = int(nbOfFacesPerCell.sum())
|
337
|
+
arr1 = np.memmap(
|
338
|
+
fd,
|
339
|
+
dtype="int32",
|
340
|
+
mode="r",
|
341
|
+
offset=int(pos),
|
342
|
+
shape=(szOfNbOfNodesPerFacePerCellArr,),
|
343
|
+
) # arr1 -> nbOfNodesPerFacePerCellArr
|
344
|
+
pos += szOfNbOfNodesPerFacePerCellArr * 4
|
345
|
+
szOfNodesPerFacePerCellArr = arr1.sum()
|
346
|
+
arr2 = np.memmap(
|
347
|
+
fd,
|
348
|
+
dtype="int32",
|
349
|
+
mode="r",
|
350
|
+
offset=int(pos),
|
351
|
+
shape=(szOfNodesPerFacePerCellArr,),
|
352
|
+
) # arr2 -> nodesPerFacePerCellArr
|
353
|
+
pos += szOfNodesPerFacePerCellArr * 4
|
226
354
|
fd.seek(pos)
|
227
|
-
mcmeshes2.append(
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
arr1=np.memmap(fd,dtype='int32',mode='r',offset=int(pos),shape=(szOfNbOfNodesPerFacePerCellArr,))#arr1 -> nbOfNodesPerFacePerCellArr
|
233
|
-
pos+=szOfNbOfNodesPerFacePerCellArr*4
|
234
|
-
szOfNodesPerFacePerCellArr=arr1.sum()
|
235
|
-
arr2=np.memmap(fd,dtype='int32',mode='r',offset=int(pos),shape=(szOfNodesPerFacePerCellArr,))#arr2 -> nodesPerFacePerCellArr
|
236
|
-
pos+=szOfNodesPerFacePerCellArr*4 ; fd.seek(pos)
|
237
|
-
mcmeshes2.append(self.__traduceMeshForPolyhed(meshName,coo,nbOfFacesPerCell,arr1,arr2))
|
355
|
+
mcmeshes2.append(
|
356
|
+
self.__traduceMeshForPolyhed(
|
357
|
+
meshName, coo, nbOfFacesPerCell, arr1, arr2
|
358
|
+
)
|
359
|
+
)
|
238
360
|
pass
|
239
361
|
else:
|
240
|
-
nbOfNodesPerCell=np.memmap(
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
362
|
+
nbOfNodesPerCell = np.memmap(
|
363
|
+
fd,
|
364
|
+
dtype="int32",
|
365
|
+
mode="r",
|
366
|
+
offset=int(pos),
|
367
|
+
shape=(nbCellsOfType,),
|
368
|
+
)
|
369
|
+
pos += nbCellsOfType * 4
|
370
|
+
szOfNbOfNodesPerCellArr = int(nbOfNodesPerCell.sum())
|
371
|
+
arr1 = np.memmap(
|
372
|
+
fd,
|
373
|
+
dtype="int32",
|
374
|
+
mode="r",
|
375
|
+
offset=int(pos),
|
376
|
+
shape=(szOfNbOfNodesPerCellArr,),
|
377
|
+
)
|
378
|
+
pos += szOfNbOfNodesPerCellArr * 4
|
379
|
+
fd.seek(pos)
|
380
|
+
mcmeshes2.append(
|
381
|
+
self.__traduceMeshForPolygon(
|
382
|
+
meshName, coo, nbOfNodesPerCell, arr1
|
383
|
+
)
|
384
|
+
)
|
385
|
+
if pos != end:
|
386
|
+
elt = fd.read(80)
|
387
|
+
elt = elt.strip()
|
388
|
+
typ = elt[:]
|
389
|
+
pos += 80
|
248
390
|
pass
|
249
391
|
pass
|
250
392
|
if mcmeshes2:
|
251
|
-
coo=mcmeshes2[0].getCoords()
|
252
|
-
|
253
|
-
|
393
|
+
coo = mcmeshes2[0].getCoords()
|
394
|
+
name = mcmeshes2[0].getName()
|
395
|
+
for itmesh in mcmeshes2:
|
396
|
+
itmesh.setCoords(coo)
|
397
|
+
m = MEDCouplingUMesh.MergeUMeshesOnSameCoords(mcmeshes2)
|
398
|
+
m.setName(name)
|
254
399
|
mcmeshes.append(m)
|
255
400
|
pass
|
256
401
|
return mcmeshes
|
257
402
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
403
|
+
def __convertField(
|
404
|
+
self, mlfields, mcmeshes, fileName, fieldName, discr, nbCompo, locId, it
|
405
|
+
):
|
406
|
+
"""Convert the fields."""
|
407
|
+
stars = re.search("[\*]+", fileName).group()
|
408
|
+
st = "%0" + str(len(stars)) + "i"
|
409
|
+
trueFileName = fileName.replace(stars, st % (it))
|
410
|
+
fd = open(os.path.join(self._dirName, trueFileName), "r+b")
|
411
|
+
fd.seek(0, 2)
|
412
|
+
end = fd.tell()
|
413
|
+
fd.seek(0)
|
414
|
+
name = fd.read(80).strip().split(b" ")[0].decode("ascii")
|
415
|
+
if name != fieldName:
|
267
416
|
raise Exception("ConvertField : mismatch")
|
268
|
-
pos=fd.tell()
|
269
|
-
st=fd.read(80)
|
270
|
-
|
271
|
-
|
417
|
+
pos = fd.tell()
|
418
|
+
st = fd.read(80)
|
419
|
+
st = st.strip()
|
420
|
+
pos = fd.tell()
|
421
|
+
while pos != end:
|
422
|
+
if st != b"part":
|
272
423
|
raise Exception("ConvertField : mismatch #2")
|
273
|
-
fdisc=MEDCouplingFieldDiscretization.New(self.discSpatial2[discr])
|
274
|
-
meshId=
|
275
|
-
|
424
|
+
fdisc = MEDCouplingFieldDiscretization.New(self.discSpatial2[discr])
|
425
|
+
meshId = (
|
426
|
+
np.memmap(
|
427
|
+
fd, dtype="int32", mode="r", offset=int(pos), shape=(1)
|
428
|
+
).tolist()[0]
|
429
|
+
- 1
|
430
|
+
)
|
431
|
+
if meshId >= len(mcmeshes):
|
276
432
|
return
|
277
|
-
nbOfValues=fdisc.getNumberOfTuples(mcmeshes[meshId])
|
278
|
-
vals2=DataArrayDouble(nbOfValues,nbCompo)
|
279
|
-
fd.seek(pos+4)
|
280
|
-
st=fd.read(80).strip()
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
433
|
+
nbOfValues = fdisc.getNumberOfTuples(mcmeshes[meshId])
|
434
|
+
vals2 = DataArrayDouble(nbOfValues, nbCompo)
|
435
|
+
fd.seek(pos + 4)
|
436
|
+
st = fd.read(80).strip()
|
437
|
+
pos = fd.tell()
|
438
|
+
offset = 0
|
439
|
+
while pos != end and st != b"part":
|
440
|
+
if st != b"coordinates":
|
441
|
+
nbOfValsOfTyp = mcmeshes[meshId].getNumberOfCellsWithType(
|
442
|
+
self.dictMCTyp2[st]
|
443
|
+
)
|
285
444
|
else:
|
286
|
-
nbOfValsOfTyp=nbOfValues
|
445
|
+
nbOfValsOfTyp = nbOfValues
|
287
446
|
pass
|
288
|
-
vals=np.memmap(
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
447
|
+
vals = np.memmap(
|
448
|
+
fd,
|
449
|
+
dtype="float32",
|
450
|
+
mode="r",
|
451
|
+
offset=int(pos),
|
452
|
+
shape=(nbOfValsOfTyp, nbCompo),
|
453
|
+
) # np.memmap(fd,dtype='int32',mode='r',offset=159,shape=(1))
|
454
|
+
vals2[offset : offset + nbOfValsOfTyp] = DataArrayDouble(
|
455
|
+
np.array(vals, dtype="float64")
|
456
|
+
).fromNoInterlace()
|
457
|
+
pos += nbOfValsOfTyp * nbCompo * 4
|
458
|
+
fd.seek(pos)
|
459
|
+
st = fd.read(80)
|
460
|
+
st = st.strip()
|
461
|
+
pos = fd.tell()
|
462
|
+
offset += nbOfValsOfTyp
|
293
463
|
pass
|
294
|
-
f=MEDCouplingFieldDouble(self.discSpatial2[discr],ONE_TIME)
|
295
|
-
f.
|
464
|
+
f = MEDCouplingFieldDouble(self.discSpatial2[discr], ONE_TIME)
|
465
|
+
f.setName("%s_%s" % (fieldName, mcmeshes[meshId].getName()))
|
466
|
+
f.setMesh(mcmeshes[meshId])
|
467
|
+
f.setArray(vals2)
|
468
|
+
f.setTime(float(it), it, -1)
|
296
469
|
f.checkConsistencyLight()
|
297
|
-
mlfields[locId+meshId].appendFieldNoProfileSBT(f)
|
470
|
+
mlfields[locId + meshId].appendFieldNoProfileSBT(f)
|
298
471
|
pass
|
299
472
|
|
300
|
-
def __convertFieldFortran(
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
473
|
+
def __convertFieldFortran(
|
474
|
+
self, mlfields, mcmeshes, fileName, fieldName, discr, nbCompo, locId, it
|
475
|
+
):
|
476
|
+
"""Convert the fields."""
|
477
|
+
if re.search("[\*]+", fileName):
|
478
|
+
stars = re.search("[\*]+", fileName).group()
|
479
|
+
st = "%0" + str(len(stars)) + "i"
|
480
|
+
trueFileName = fileName.replace(stars, st % (it))
|
306
481
|
pass
|
307
482
|
else:
|
308
|
-
trueFileName=fileName
|
483
|
+
trueFileName = fileName
|
309
484
|
pass
|
310
|
-
fd=open(os.path.join(self._dirName,trueFileName),"r+b")
|
311
|
-
|
485
|
+
fd = open(os.path.join(self._dirName, trueFileName), "r+b")
|
486
|
+
fd.seek(0, 2)
|
487
|
+
end = fd.tell()
|
488
|
+
fd.seek(0)
|
489
|
+
name = fd.read(80)
|
312
490
|
if fieldName not in name:
|
313
491
|
raise Exception("ConvertField : mismatch")
|
314
|
-
pos=fd.tell()
|
315
|
-
st=fd.read(80)
|
492
|
+
pos = fd.tell()
|
493
|
+
st = fd.read(80)
|
494
|
+
st = st.strip()
|
495
|
+
pos = fd.tell()
|
316
496
|
if b"part" not in st:
|
317
497
|
raise Exception("ConvertField : mismatch #2")
|
318
|
-
st=fd.read(80).strip()
|
319
|
-
pos
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
498
|
+
st = fd.read(80).strip()
|
499
|
+
pos = fd.tell()
|
500
|
+
pos += 12 # I love it
|
501
|
+
offset = 0
|
502
|
+
nbTurn = 0
|
503
|
+
while pos != end and b"part" not in st:
|
504
|
+
fdisc = MEDCouplingFieldDiscretization.New(self.discSpatial2[discr])
|
505
|
+
nbOfValues = fdisc.getNumberOfTuples(mcmeshes[nbTurn])
|
506
|
+
vals2 = DataArrayDouble(nbOfValues, nbCompo)
|
507
|
+
pos += 24 # I love it again !
|
508
|
+
nbOfValsOfTyp = (
|
509
|
+
np.memmap(fd, dtype=">i4", mode="r", offset=pos, shape=(1)).tolist()[0]
|
510
|
+
/ 4
|
511
|
+
)
|
512
|
+
pos += 4
|
513
|
+
vals = np.zeros(dtype=">f4", shape=(nbOfValsOfTyp * nbCompo))
|
330
514
|
for iii in range(nbCompo):
|
331
|
-
valsTmp=np.memmap(
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
515
|
+
valsTmp = np.memmap(
|
516
|
+
fd, dtype=">f4", mode="r", offset=int(pos), shape=(nbOfValsOfTyp)
|
517
|
+
)
|
518
|
+
vals[iii * nbOfValsOfTyp : (iii + 1) * nbOfValsOfTyp] = valsTmp
|
519
|
+
pos += nbOfValsOfTyp * 4
|
520
|
+
pos += 2 * 4 ## hey hey, that is the ultimate class !
|
521
|
+
vals2.setInfoOnComponent(iii, chr(ord("X") + iii))
|
336
522
|
pass
|
337
|
-
if pos>end:
|
338
|
-
pos=end
|
523
|
+
if pos > end:
|
524
|
+
pos = end
|
339
525
|
pass
|
340
|
-
vals=vals.reshape(nbOfValsOfTyp,nbCompo)
|
341
|
-
vals2[offset:offset+nbOfValsOfTyp]=DataArrayDouble(
|
342
|
-
|
526
|
+
vals = vals.reshape(nbOfValsOfTyp, nbCompo)
|
527
|
+
vals2[offset : offset + nbOfValsOfTyp] = DataArrayDouble(
|
528
|
+
np.array(vals, dtype="float64")
|
529
|
+
).fromNoInterlace()
|
530
|
+
if pos != end:
|
343
531
|
fd.seek(pos)
|
344
|
-
st=fd.read(80)
|
345
|
-
st=
|
532
|
+
st = fd.read(80)
|
533
|
+
st = st.strip()
|
534
|
+
pos = fd.tell()
|
535
|
+
st = fd.read(80)
|
536
|
+
st = st.strip()
|
537
|
+
pos = fd.tell()
|
346
538
|
pass
|
347
|
-
f=MEDCouplingFieldDouble(self.discSpatial2[discr],ONE_TIME)
|
348
|
-
f.
|
539
|
+
f = MEDCouplingFieldDouble(self.discSpatial2[discr], ONE_TIME)
|
540
|
+
f.setName("%s_%s" % (fieldName, mcmeshes[nbTurn].getName()))
|
541
|
+
f.setMesh(mcmeshes[nbTurn])
|
542
|
+
f.setArray(vals2)
|
543
|
+
f.setTime(float(it), it, -1)
|
349
544
|
f.checkConsistencyLight()
|
350
|
-
mlfields[locId+nbTurn].appendFieldNoProfileSBT(f)
|
351
|
-
nbTurn+=1
|
545
|
+
mlfields[locId + nbTurn].appendFieldNoProfileSBT(f)
|
546
|
+
nbTurn += 1
|
352
547
|
pass
|
353
548
|
pass
|
354
549
|
|
355
550
|
def loadInMEDFileDS(self):
|
356
|
-
"""
|
357
|
-
f=open(self._fileName)
|
358
|
-
lines=f.readlines()
|
359
|
-
ind=lines.index("GEOMETRY\n")
|
360
|
-
if ind
|
361
|
-
raise Exception("Error with file %s"%(fname))
|
362
|
-
geoName=re.match("model:([\W]*)([\w\.]+)",lines[ind+1]).group(2)
|
363
|
-
m1,m2,typeOfFile=self.__convertGeo2MED(geoName)
|
364
|
-
fieldsInfo=[]
|
551
|
+
"""Load a CASE file into a MEDFileData object."""
|
552
|
+
f = open(self._fileName)
|
553
|
+
lines = f.readlines()
|
554
|
+
ind = lines.index("GEOMETRY\n")
|
555
|
+
if ind == -1:
|
556
|
+
raise Exception("Error with file %s" % (fname))
|
557
|
+
geoName = re.match("model:([\W]*)([\w\.]+)", lines[ind + 1]).group(2)
|
558
|
+
m1, m2, typeOfFile = self.__convertGeo2MED(geoName)
|
559
|
+
fieldsInfo = []
|
560
|
+
nbOfTimeSteps = 0
|
365
561
|
if "VARIABLE\n" in lines:
|
366
|
-
ind=lines.index("VARIABLE\n")
|
367
|
-
end=len(lines)-1
|
562
|
+
ind = lines.index("VARIABLE\n")
|
563
|
+
end = len(lines) - 1
|
368
564
|
if "TIME\n" in lines:
|
369
|
-
end=lines.index("TIME\n")
|
565
|
+
end = lines.index("TIME\n")
|
370
566
|
pass
|
371
|
-
for i in range(ind + 1,end):
|
372
|
-
m=re.match(
|
567
|
+
for i in range(ind + 1, end):
|
568
|
+
m = re.match(
|
569
|
+
"^([\w]+)[\s]+per[\s]+([\w]+)[\s]*\:[\s]*[0-9]*[\s]*([\w]+)[\s]+([\S]+)$",
|
570
|
+
lines[i],
|
571
|
+
)
|
373
572
|
if m:
|
374
|
-
if m.groups()[0]=="constant":
|
573
|
+
if m.groups()[0] == "constant":
|
375
574
|
continue
|
376
|
-
spatialDisc
|
575
|
+
spatialDisc = m.groups()[1]
|
576
|
+
fieldName = m.groups()[2]
|
577
|
+
nbOfCompo = self.dictCompo2[m.groups()[0]]
|
578
|
+
fieldFileName = m.groups()[3]
|
377
579
|
if "*" in fieldFileName:
|
378
|
-
|
580
|
+
fieldsInfo.append(
|
581
|
+
(fieldName, spatialDisc, nbOfCompo, fieldFileName)
|
582
|
+
)
|
379
583
|
pass
|
380
584
|
pass
|
381
585
|
|
382
|
-
expr=re.compile("number[\s]+of[\s]+steps[\s]*\:[\s]*([\d]+)")
|
586
|
+
expr = re.compile("number[\s]+of[\s]+steps[\s]*\:[\s]*([\d]+)")
|
383
587
|
tmp = [line for line in lines if expr.search(line)]
|
384
588
|
if tmp:
|
385
589
|
nbOfTimeSteps = int(expr.search(tmp[0]).group(1))
|
386
|
-
expr=re.compile("filename[\s]+start[\s]+number[\s]*\:[\s]*([\d]+)")
|
387
|
-
startIt = int(
|
388
|
-
|
389
|
-
|
590
|
+
expr = re.compile("filename[\s]+start[\s]+number[\s]*\:[\s]*([\d]+)")
|
591
|
+
startIt = int(
|
592
|
+
expr.search([line for line in lines if expr.search(line)][0]).group(
|
593
|
+
1
|
594
|
+
)
|
595
|
+
)
|
596
|
+
expr = re.compile("filename[\s]+increment[\s]*\:[\s]*([\d]+)")
|
597
|
+
incrIt = int(
|
598
|
+
expr.search([line for line in lines if expr.search(line)][0]).group(
|
599
|
+
1
|
600
|
+
)
|
601
|
+
)
|
390
602
|
else:
|
391
|
-
nbOfTimeSteps=1
|
392
|
-
startIt=0
|
393
|
-
incrIt=1
|
603
|
+
nbOfTimeSteps = 1
|
604
|
+
startIt = 0
|
605
|
+
incrIt = 1
|
394
606
|
pass
|
395
|
-
curIt=startIt
|
607
|
+
curIt = startIt
|
396
608
|
pass
|
397
|
-
mlfields=MEDFileFields()
|
398
|
-
mlfields.resize(len(fieldsInfo)*len(m1))
|
399
|
-
i=0
|
609
|
+
mlfields = MEDFileFields()
|
610
|
+
mlfields.resize(len(fieldsInfo) * len(m1))
|
611
|
+
i = 0
|
400
612
|
for field in fieldsInfo:
|
401
613
|
for m in m1:
|
402
|
-
mlfields.setFieldAtPos(i,MEDFileFieldMultiTS())
|
403
|
-
i+=1
|
614
|
+
mlfields.setFieldAtPos(i, MEDFileFieldMultiTS())
|
615
|
+
i += 1
|
404
616
|
pass
|
405
617
|
pass
|
406
618
|
for ts in range(nbOfTimeSteps):
|
407
|
-
i=0
|
619
|
+
i = 0
|
408
620
|
for field in fieldsInfo:
|
409
621
|
if typeOfFile:
|
410
|
-
self.__convertField(
|
622
|
+
self.__convertField(
|
623
|
+
mlfields, m1, field[3], field[0], field[1], field[2], i, curIt
|
624
|
+
)
|
411
625
|
else:
|
412
|
-
self.__convertFieldFortran(
|
626
|
+
self.__convertFieldFortran(
|
627
|
+
mlfields, m1, field[3], field[0], field[1], field[2], i, curIt
|
628
|
+
)
|
413
629
|
pass
|
414
|
-
i+=len(m1)
|
630
|
+
i += len(m1)
|
415
631
|
pass
|
416
|
-
curIt+=incrIt
|
632
|
+
curIt += incrIt
|
417
633
|
pass
|
418
|
-
ret=MEDFileData()
|
634
|
+
ret = MEDFileData()
|
419
635
|
ret.setMeshes(m2)
|
420
636
|
del mlfields[[x for x in range(len(mlfields)) if len(mlfields[x]) == 0]]
|
421
637
|
ret.setFields(mlfields)
|