medcoupling 9.11.0__cp311-cp311-win_amd64.whl → 9.15.0__cp311-cp311-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.
medcouplingremapper.dll CHANGED
Binary file
medicoco.dll CHANGED
Binary file
medloader.dll CHANGED
Binary file
medpartitionercpp.dll CHANGED
Binary file
renumbercpp.dll CHANGED
Binary file
vtk2medcoupling.py CHANGED
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
- # Copyright (C) 2020-2023 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,22 +0,0 @@
1
- Metadata-Version: 2.0
2
- Name: medcoupling
3
- Version: 9.11.0
4
- Summary: Powerful library to manipulate meshes and fields
5
- Home-page: https://www.salome-platform.org/downloads
6
- Author: EDF R&D
7
- Author-email: eric.fayolle@edf.fr
8
- License: LGPL
9
- Keywords: salome mesh numerical simulation
10
- Platform: any
11
- Classifier: Development Status :: 5 - Production/Stable
12
- Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
13
- Classifier: Operating System :: Microsoft :: Windows
14
- Classifier: Operating System :: MacOS :: MacOS X
15
- Classifier: Operating System :: POSIX :: Linux
16
- Classifier: Programming Language :: C
17
- Classifier: Programming Language :: Python :: 3
18
- Classifier: Topic :: Scientific/Engineering :: Physics
19
- Classifier: Intended Audience :: Science/Research
20
- Requires-Dist: numpy
21
-
22
- Powerful library to manipulate meshes and fields from SALOME platform
@@ -1 +0,0 @@
1
- medcoupling-9.11.0.dist-info\RECORD,,
@@ -1 +0,0 @@
1
- Wheel-Version: 1.0