medcoupling 9.13.0__cp39-cp39-win_amd64.whl → 9.15.0__cp39-cp39-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.
vtk2medcoupling.py CHANGED
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
- # Copyright (C) 2020-2024 CEA, EDF
3
+ # Copyright (C) 2020-2025 CEA, EDF
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -24,17 +24,263 @@ import vtk
24
24
  from vtk.util import numpy_support
25
25
  import medcoupling as mc
26
26
  import numpy as np
27
+ import logging
28
+
29
+ logger = None
30
+
31
+
32
+ def getLogger():
33
+ global logger
34
+ if logger is None:
35
+ logging.basicConfig(level=logging.INFO)
36
+ logger = logging.getLogger()
37
+ return logger
38
+
39
+
40
+ def setLogLevel(lev):
41
+ getLogger().setLevel(lev)
42
+
27
43
 
28
44
  def mesh_convertor(fileName):
29
- #vtk.vtkDataSetReader()
45
+ # vtk.vtkDataSetReader()
30
46
  reader = vtk.vtkXMLUnstructuredGridReader()
31
47
  reader.SetFileName(fileName)
32
48
  reader.Update()
33
49
  ug = reader.GetOutput()
34
- return mesh_convertor_mem(ug),ug
35
-
36
- def mesh_convertor_mem(ug):
50
+ return mesh_convertor_mem(ug), ug
51
+
52
+
53
+ def mesh_convertor_mem(ug, dimRequested=-1):
54
+ """
55
+ Main entry
56
+ """
37
57
  from distutils.version import LooseVersion
58
+
59
+ vtkVersion = vtk.vtkVersion().GetVTKVersion()
60
+ getLogger().debug(f"VTK version : {vtkVersion}")
61
+ if LooseVersion(vtkVersion) <= LooseVersion("9.3.0"):
62
+ return mesh_convertor_mem_93(ug, dimRequested)
63
+ else:
64
+ return mesh_convertor_mem_94(ug, dimRequested)
65
+
66
+
67
+ def get_coarse_data_from_VTK_unstructuredGrid93(ug):
68
+ facesLoc = numpy_support.vtk_to_numpy(ug.GetFaceLocations())
69
+ faces = numpy_support.vtk_to_numpy(ug.GetFaces())
70
+ return facesLoc, faces
71
+
72
+
73
+ def generate_polyhedrons_mesh_from_VTK_UnstructuredGrid_93(ug):
74
+ """
75
+ Returns from vtkUnstructuredGrid instance MEDCouplingMesh containing only polyhedra cells
76
+ """
77
+ facesLoc, faces = get_coarse_data_from_VTK_unstructuredGrid93(ug)
78
+ facesLocMed = mc.DataArrayInt(facesLoc)
79
+ facesMed = mc.DataArrayInt(faces)
80
+ cellIdsPolyh = facesLocMed.findIdsNotEqual(-1)
81
+ facesLocCpy = facesLocMed[:]
82
+ #
83
+ polyhStart = facesLocCpy[cellIdsPolyh]
84
+ polyhStart.pushBackSilent(len(facesMed))
85
+ a, b = mc.DataArrayInt64.FromVTKInternalReprOfPolyedra(facesMed, polyhStart)
86
+ m = mc.MEDCoupling1DGTUMesh("mesh", mc.NORM_POLYHED)
87
+ m.setNodalConnectivity(a, b)
88
+ return m.buildUnstructured()
89
+
90
+
91
+ def generate_polyhedrons_mesh_from_VTK_UnstructuredGrid_94(ug):
92
+ facesLoc = (
93
+ ug.GetPolyhedronFaceLocations()
94
+ ) # vtkCellArray.SetData(offsets,connectivity)
95
+ facesLoc_o = mc.DataArrayInt(numpy_support.vtk_to_numpy(facesLoc.GetOffsetsArray()))
96
+ facesLoc_c = mc.DataArrayInt(
97
+ numpy_support.vtk_to_numpy(facesLoc.GetConnectivityArray())
98
+ )
99
+
100
+ faces = ug.GetPolyhedronFaces()
101
+ faces_o = mc.DataArrayInt(numpy_support.vtk_to_numpy(faces.GetOffsetsArray()))
102
+ faces_c = mc.DataArrayInt(numpy_support.vtk_to_numpy(faces.GetConnectivityArray()))
103
+
104
+ nbFacesPerCell = facesLoc_o.deltaShiftIndex()
105
+ polyhedronsCellIds = nbFacesPerCell.findIdsNotEqual(0)
106
+
107
+ _, facesLoc_o_eff = mc.DataArrayInt.ExtractFromIndexedArrays(
108
+ polyhedronsCellIds, facesLoc_c, facesLoc_o
109
+ )
110
+
111
+ a, b = mc.DataArrayInt64.FromVTK94InternalReprOfPolyedra(
112
+ faces_c, faces_o, facesLoc_o_eff
113
+ )
114
+
115
+ m = mc.MEDCoupling1DGTUMesh("mesh", mc.NORM_POLYHED)
116
+ m.setNodalConnectivity(a, b)
117
+ return m.buildUnstructured()
118
+
119
+
120
+ def from_93_to_94_coarse_VTK_data(ug):
121
+ facesLoc, faces, _ = get_coarse_data_from_VTK_unstructuredGrid93(ug)
122
+ facesLocMed = mc.DataArrayInt(facesLoc)
123
+ facesMed = mc.DataArrayInt(faces)
124
+ cellIdsPolyh = facesLocMed.findIdsNotEqual(-1)
125
+ nbFacesPerPolyh = facesMed[facesLocMed[cellIdsPolyh]]
126
+ facesLoc_o = mc.DataArrayInt(len(facesLocMed))
127
+ facesLoc_o[:] = 0
128
+ facesLoc_o[cellIdsPolyh] = nbFacesPerPolyh
129
+ facesLoc_o.computeOffsetsFull()
130
+ faceLocMedNoMinusOne = facesLocMed[cellIdsPolyh]
131
+ faceLocMedNoMinusOne.pushBackSilent(len(facesMed))
132
+ faces_c, faces_o = mc.DataArrayInt64.FromVTK93To94FacesInternaReprOfPolyedra(
133
+ facesMed, faceLocMedNoMinusOne
134
+ )
135
+ nbFacesInPolyhedra = facesLoc_o[-1]
136
+ facesLoc_c = mc.DataArrayInt(nbFacesInPolyhedra)
137
+ facesLoc_c.iota()
138
+ return facesLoc_o, facesLoc_c, faces_o, faces_c
139
+
140
+
141
+ def get_coarse_data_from_VTK_unstructuredGrid_94(ug):
142
+ facesLoc = ug.GetPolyhedronFaceLocations()
143
+ facesLoc_o = numpy_support.vtk_to_numpy(facesLoc.GetOffsetsArray())
144
+ facesLoc_c = numpy_support.vtk_to_numpy(facesLoc.GetConnectivityArray())
145
+
146
+ faces = ug.GetPolyhedronFaces()
147
+ faces_o = numpy_support.vtk_to_numpy(faces.GetOffsetsArray())
148
+ faces_c = numpy_support.vtk_to_numpy(faces.GetConnectivityArray())
149
+ return facesLoc_o, facesLoc_c, faces_o, faces_c
150
+
151
+
152
+ def mesh_convertor_mem_gen(ug, dimRequested, callback_for_polyedrons):
153
+ coords = mc.DataArrayDouble(
154
+ np.array(numpy_support.vtk_to_numpy(ug.GetPoints().GetData()), dtype=np.float64)
155
+ )
156
+ cells = ug.GetCells()
157
+ offsets = numpy_support.vtk_to_numpy(cells.GetOffsetsArray())
158
+ ci = mc.DataArrayInt(np.array(offsets, dtype=np.int64))[:]
159
+ conn = mc.DataArrayInt(
160
+ np.array(
161
+ numpy_support.vtk_to_numpy(cells.GetConnectivityArray()), dtype=np.int64
162
+ )
163
+ )
164
+ types = numpy_support.vtk_to_numpy(ug.GetCellTypesArray())
165
+ ct = mc.DataArrayInt(
166
+ np.array(types, dtype="int{}".format(mc.MEDCouplingSizeOfIDs()))
167
+ )[:]
168
+ vtk2med = mc.DataArrayInt(mc.vtk2med_cell_types())
169
+ ctdim = ct[:]
170
+ ct.transformWithIndArr(vtk2med)
171
+
172
+ activeType = vtk2med.findIdsNotEqual(-1)
173
+ vtk2dim = vtk2med[:]
174
+ vtk2dim[activeType] = mc.DataArrayInt(
175
+ [
176
+ mc.MEDCouplingUMesh.GetDimensionOfGeometricType(int(elt))
177
+ for elt in vtk2med[activeType]
178
+ ]
179
+ )
180
+ ctdim.transformWithIndArr(vtk2dim)
181
+ dims = ctdim.getDifferentValues().getValues()
182
+ getLogger().debug(f"Available dimensions : {dims}")
183
+ zeDim = dimRequested
184
+ if zeDim < 0:
185
+ zeDim = max(dims)
186
+ else:
187
+ if zeDim not in dims:
188
+ raise RuntimeError(
189
+ f"{zeDim} not in detected dimension of vtkUnstructuredGrid instance : {dims}"
190
+ )
191
+ getLogger().debug(f"Filtering on dimension : {zeDim}")
192
+ selectedCells = ctdim.findIdsEqual(zeDim)
193
+ conn1, ci1 = mc.DataArrayInt.ExtractFromIndexedArrays(selectedCells, conn, ci)
194
+ ct1 = ct[selectedCells]
195
+
196
+ classicalCells = ct1.findIdsNotEqual(mc.NORM_POLYHED)
197
+ isPostWithPoly = ct1.presenceOfValue(mc.NORM_POLYHED)
198
+ resu = []
199
+ resu2 = []
200
+ if not classicalCells.empty():
201
+ getLogger().debug(f"Presence of {len(classicalCells)} classical cells")
202
+ conn2, ci2 = mc.DataArrayInt.ExtractFromIndexedArrays(
203
+ classicalCells, conn1, ci1
204
+ )
205
+ ct2 = ct1[classicalCells]
206
+ m = mc.MEDCouplingUMesh("mesh", zeDim)
207
+ # insert geo type in connectivity
208
+ a = ci2.deltaShiftIndex()
209
+ a2 = a + 1
210
+ a2.computeOffsetsFull()
211
+ b = mc.DataArrayInt(len(a))
212
+ b[:] = 1
213
+ c = mc.DataArrayInt.Meld([b, a])
214
+ c.rearrange(1)
215
+ c.computeOffsetsFull()
216
+ d = mc.DataArrayInt(len(classicalCells))
217
+ d.iota()
218
+ d *= 2
219
+ d += 1
220
+ d2 = d.buildExplicitArrByRanges(c)
221
+ d3 = mc.DataArrayInt(len(conn2) + len(classicalCells))
222
+ d3[:] = -1
223
+ idsForGeoType = d2.buildComplement(len(conn2) + len(classicalCells))
224
+ d3[idsForGeoType] = ct2
225
+ d3[d2] = conn2
226
+ #
227
+ m.setConnectivity(d3, a2, True)
228
+ m.setCoords(coords)
229
+ resu2.append(classicalCells)
230
+ resu.append(m)
231
+
232
+ if isPostWithPoly:
233
+ getLogger().debug(f"Presence of polyhedrons cells")
234
+ resu2.append(ct1.findIdsEqual(mc.NORM_POLYHED))
235
+ m = callback_for_polyedrons(ug)
236
+ m.setCoords(coords)
237
+ resu.append(m)
238
+
239
+ resu2 = mc.DataArrayInt.Aggregate(resu2)
240
+ resu = mc.MEDCouplingUMesh.MergeUMeshesOnSameCoords(resu)
241
+ ren = resu2.invertArrayO2N2N2O(len(resu2))
242
+ ret = resu[ren]
243
+ return ret
244
+
245
+
246
+ def mesh_convertor_mem_93(ug, dimRequested=-1):
247
+ getLogger().debug(f"Reader 9.3")
248
+ return mesh_convertor_mem_gen(
249
+ ug, dimRequested, generate_polyhedrons_mesh_from_VTK_UnstructuredGrid_93
250
+ )
251
+
252
+
253
+ def mesh_convertor_mem_94(ug, dimRequested=-1):
254
+ getLogger().debug(f"Reader 9.4")
255
+ return mesh_convertor_mem_gen(
256
+ ug, dimRequested, generate_polyhedrons_mesh_from_VTK_UnstructuredGrid_94
257
+ )
258
+
259
+
260
+ def mesh_convertor_mem_93_legacy(ug):
261
+ def patchForPolyedra(polyhedCellIds, ug, mesh):
262
+ """
263
+ Method in charge to change the connectivity of polyedra contained in mesh using ug vtkUnstructuredGrid.
264
+
265
+ :param in polyhedCellIds: mc.DataArrayInt of cells ids in mesh to be patched
266
+ :param in ug: vtkUnstructuredGrid containing polyhedra
267
+ :param in-out mesh: mc.MEDCouplingUMesh. 3D Mesh whose polyedra cells connectivity will be modified
268
+ """
269
+ facesLoc = mc.DataArrayInt(numpy_support.vtk_to_numpy(ug.GetFaceLocations()))
270
+ faces = mc.DataArrayInt(numpy_support.vtk_to_numpy(ug.GetFaces()))
271
+ facesLoc = facesLoc[polyhedCellIds]
272
+ facesLoc = mc.DataArrayInt.Aggregate([facesLoc, mc.DataArrayInt([len(faces)])])
273
+ connForPoly, facesLoc = mc.DataArrayInt.FromVTKInternalReprOfPolyedra(
274
+ faces, facesLoc
275
+ )
276
+ meshPoly = mc.MEDCoupling1DGTUMesh(mesh.getName(), mc.NORM_POLYHED)
277
+ meshPoly.setCoords(mesh.getCoords())
278
+ meshPoly.setNodalConnectivity(connForPoly, facesLoc)
279
+ mesh[polyhedCellIds] = meshPoly.buildUnstructured()
280
+ pass
281
+
282
+ from distutils.version import LooseVersion
283
+
38
284
  #
39
285
  pts = numpy_support.vtk_to_numpy(ug.GetPoints().GetData())
40
286
  #
@@ -42,31 +288,41 @@ def mesh_convertor_mem(ug):
42
288
  ctvtk = numpy_support.vtk_to_numpy(ug.GetCellTypesArray())
43
289
  conn = numpy_support.vtk_to_numpy(ug.GetCells().GetData())
44
290
  #
45
- ct=mc.DataArrayInt(np.array(ctvtk,dtype="int{}".format(mc.MEDCouplingSizeOfIDs())))[:]
46
- c=mc.DataArrayInt(conn)[:]
47
- ci=mc.DataArrayInt(cla)[:]
291
+ ct = mc.DataArrayInt(
292
+ np.array(ctvtk, dtype="int{}".format(mc.MEDCouplingSizeOfIDs()))
293
+ )[:]
294
+ c = mc.DataArrayInt(conn)[:]
295
+ ci = mc.DataArrayInt(cla)[:]
48
296
  # for pv580
49
297
  if LooseVersion(vtk.vtkVersion().GetVTKVersion()) >= LooseVersion("8.90.0"):
50
- ci = ci.deltaShiftIndex()+1
298
+ ci = ci.deltaShiftIndex() + 1
51
299
  ci.computeOffsetsFull()
52
300
  #
53
301
  vtk2med = mc.DataArrayInt(mc.vtk2med_cell_types())
54
302
  #
55
303
  ct.transformWithIndArr(vtk2med)
56
- c[ci]=ct
57
- ci = mc.DataArrayInt.Aggregate([ci,mc.DataArrayInt([len(c)])])
304
+ c[ci] = ct
305
+ ci = mc.DataArrayInt.Aggregate([ci, mc.DataArrayInt([len(c)])])
58
306
  #
59
307
  gtv = ct.getDifferentValues().getValues()
60
- dimArray = mc.DataArrayInt(len(gtv)) ; dimArray[:] = -1
61
- for i,gt in enumerate(gtv):
308
+ dimArray = mc.DataArrayInt(len(gtv))
309
+ dimArray[:] = -1
310
+ for i, gt in enumerate(gtv):
62
311
  dimArray[i] = mc.MEDCouplingUMesh.GetDimensionOfGeometricType(gt)
63
312
  dim = dimArray.getMaxValueInArray()
64
313
  if not dimArray.isUniform(dim):
65
- raise RuntimeError("The input vtkUnstructuredGrid instance is not a single level mesh ! need to split it !")
314
+ raise RuntimeError(
315
+ "The input vtkUnstructuredGrid instance is not a single level mesh ! need to split it !"
316
+ )
66
317
  #
67
- m=mc.MEDCouplingUMesh("mesh",dim)
68
- m.setCoords(mc.DataArrayDouble(np.array(pts,dtype=np.float64)))
69
- m.setConnectivity(c,ci,True)
318
+ m = mc.MEDCouplingUMesh("mesh", dim)
319
+ m.setCoords(mc.DataArrayDouble(np.array(pts, dtype=np.float64)))
320
+ m.setConnectivity(c, ci, True)
70
321
  m.checkConsistencyLight()
71
322
  #
323
+ if m.getMeshDimension() == 3:
324
+ polyhedCellIds = ct.findIdsEqual(mc.NORM_POLYHED)
325
+ if not polyhedCellIds.empty():
326
+ patchForPolyedra(polyhedCellIds, ug, m)
327
+ #
72
328
  return m
@@ -1,30 +0,0 @@
1
- .\CaseIO.py,sha256=h_tsPehWcmy7zymcWY4w_qzL5w8vPiX2ZvnsDXomZD4=,1735
2
- .\CaseReader.py,sha256=Q-dRk0LiM_fFm9sX4JEPxk8lrmDJpqckvt5SToQIvuU=,20194
3
- .\CaseWriter.py,sha256=BYosBK-cTq0nRWcWvpwox8Ha-ydJfQrJKTWRvud3HkM=,16368
4
- .\geom2medcoupling.py,sha256=PYs1yQlxycYd5jamSDvRG0kN74u327OiXMM3yLx9t6M=,4108
5
- .\hdf5.dll,sha256=I3A-7yoSrVezzpOPTijCJ4mlKCr9rl7uxo73vkmaYVc=,2956288
6
- .\interpkernel.dll,sha256=WVbnv6if7U2STQ84DCuDF3WAo7wml8wy0fxrkcUzqh8=,733696
7
- .\libxml2.dll,sha256=HUa_sIbRgg4fBXfQ72ZsZIGEjPVMKEyIpDdw5TTjvEI=,1407488
8
- .\medC.dll,sha256=4Mfq_Ira02DogCoLe808rZRTvpD35T9PqJHeNZPFMZ8=,5445632
9
- .\medcoupling.dll,sha256=jbJlIPu9xzH--CEEkvB4hylm9WlNPhZUJBeI1PwnI2Q=,2631680
10
- .\medcoupling.py,sha256=s4xGJq1Iss5zbeK9WJIsxHNsI55gv4cElLKBMDY2YYE=,810254
11
- .\MEDCouplingCompat.py,sha256=pcpmSeGEZNpVecuBCdmaOVplUXJXpGMkrGKMslSDYYo=,538877
12
- .\medcouplingremapper.dll,sha256=DJ3hQDeyDvP8Wi00EdNtmdCOWH4sIbKwcSAoaMnXCNI=,574464
13
- .\MEDCouplingRemapper.py,sha256=BuCmc-9KeZWFIZ6A23l-cYylo-_IxENH8GxRJYiTyi4=,563761
14
- .\medicoco.dll,sha256=CrbN31f1B6opTTuOeuINbMsKEP4npeiULtE3XDjSTEU=,19456
15
- .\medloader.dll,sha256=VAlM9TwXT6UoU3gwWFI_VbpVgH0z7SzD7PnJ3JPDnl8=,2010624
16
- .\MEDLoader.py,sha256=cCCwa2x1TVKQRW56zz-7m6zhNz8Dp5cWT-85RdvSVck=,771453
17
- .\MEDLoaderFinalize.py,sha256=USOqudg9lHQpfDzybNNmePqJLDF8VU4O4WDc7OL23vc=,2794
18
- .\MEDLoaderSplitter.py,sha256=5G612vtDORCcV7kxYWAxnireNIQY-miZowTv57ppTkA=,9357
19
- .\MEDPartitioner.py,sha256=cQIboO-wCLxay01TOARvvdDYzWRdeh2nq5-W2Raxh0c=,5798
20
- .\medpartitionercpp.dll,sha256=cC5IToN6oN7s5-Im7qcXxttvbYcchMoRbqUS-ouhoz8=,468480
21
- .\MEDRenumber.py,sha256=rywrn1niHDoTsLGJUlPz1xJhE725-GnndnPsccHUnEQ=,520363
22
- .\renumbercpp.dll,sha256=wKOJn8AwmeEwx9_2QOTxlR6byS4tU1Rhglhni2hRpOQ=,132608
23
- .\vtk2medcoupling.py,sha256=RfyXlfLiT_z8msaW75m_n65o7vLXvm00qCjT62Rugl8=,2775
24
- .\VTKReader.py,sha256=tRvp_wjkdxjs0Sli9S3A4OFC6EhiFpd05PD_9MXr4wo=,12601
25
- .\_medcoupling.pyd,sha256=Gv_iTHhefcovl9TUXXQcILEDPC58s__HsH4fmLmSAXs=,5433344
26
- .\_MEDCouplingCompat.pyd,sha256=phGFqefYTzljwVQEtd_HdMRuDP7DgaSIOgwkbTMcn-E=,3523072
27
- .\_MEDCouplingRemapper.pyd,sha256=eMiB7ibiz-sK4cICdHxyBS5N94M1QFH0t045m1LLqzE=,3629056
28
- .\_MEDLoader.pyd,sha256=4Pxu__12gnJEzGe0gFQuYKprsguEnFHUZsdzR-rEMrQ=,5248512
29
- .\_MEDPartitioner.pyd,sha256=RPzTIqBrUBgzRJE8KGC79-TvGNtjC7RKdxc-MVKGrkw=,76800
30
- .\_MEDRenumber.pyd,sha256=wKkGu2Y1Jjyc4syz_vWCiZNA0fB47ygaobdOqeBkpcM=,3530240