medcoupling 9.11.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.
MEDLoaderSplitter.py CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- coding: iso-8859-1 -*-
2
- # Copyright (C) 2007-2023 CEA, EDF
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
@@ -22,178 +22,219 @@
22
22
  from medcoupling import *
23
23
  import os
24
24
 
25
+
25
26
  class MEDLoaderSplitter:
26
27
  @classmethod
27
- def New(cls,mfd,idsLst):
28
- """ mfd is a MEDFileData instance containing only one mesh. idsLst is a list of DataArrayInt containing each the ids per processor """
29
- return MEDLoaderSplitter(mfd,idsLst)
28
+ def New(cls, mfd, idsLst):
29
+ """mfd is a MEDFileData instance containing only one mesh. idsLst is a list of DataArrayInt containing each the ids per processor"""
30
+ return MEDLoaderSplitter(mfd, idsLst)
30
31
  pass
31
32
 
32
- def __init__(self,mfd,idsLst):
33
- """ mfd is a MEDFileData instance containing only one mesh. idsLst is a list of DataArrayInt containing each the ids per processor """
34
- mfmsh=mfd.getMeshes()
35
- mfflds=mfd.getFields()
36
- if len(mfmsh)!=1:
33
+ def __init__(self, mfd, idsLst):
34
+ """mfd is a MEDFileData instance containing only one mesh. idsLst is a list of DataArrayInt containing each the ids per processor"""
35
+ mfmsh = mfd.getMeshes()
36
+ mfflds = mfd.getFields()
37
+ if len(mfmsh) != 1:
37
38
  raise InterpKernelException("Works only with one mesh !")
38
- mfflds=mfflds.partOfThisLyingOnSpecifiedMeshName(mfmsh[0].getName())
39
- retm=self.__splitMesh(mfmsh[0],idsLst)
40
- retf=self.__splitFields(mfmsh[0],retm,mfflds,idsLst)
41
- self._mfd_splitted=[MEDFileData() for i in range(len(idsLst))]
42
- for a,b,c in zip(self._mfd_splitted,retf,retm):
43
- a.setFields(b) ; a.setMeshes(c)
39
+ mfflds = mfflds.partOfThisLyingOnSpecifiedMeshName(mfmsh[0].getName())
40
+ retm = self.__splitMesh(mfmsh[0], idsLst)
41
+ retf = self.__splitFields(mfmsh[0], retm, mfflds, idsLst)
42
+ self._mfd_splitted = [MEDFileData() for i in range(len(idsLst))]
43
+ for a, b, c in zip(self._mfd_splitted, retf, retm):
44
+ a.setFields(b)
45
+ a.setMeshes(c)
44
46
  pass
45
47
  pass
46
48
 
47
49
  def getSplittedInstances(self):
48
50
  return self._mfd_splitted
49
-
51
+
50
52
  @classmethod
51
- def __splitMEDFileField1TSNodePfl(cls,mm,fieldName,pfl,ids,cache,procID):
53
+ def __splitMEDFileField1TSNodePfl(cls, mm, fieldName, pfl, ids, cache, procID):
52
54
  zeLev = None
53
55
  for lev in reversed(mm.getNonEmptyLevels()):
54
- cellIds = mm[lev].getCellIdsLyingOnNodes(pfl,True)
55
- if mm[lev][cellIds].computeFetchedNodeIds().isEqualWithoutConsideringStr(pfl):
56
+ cellIds = mm[lev].getCellIdsLyingOnNodes(pfl, True)
57
+ if (
58
+ mm[lev][cellIds]
59
+ .computeFetchedNodeIds()
60
+ .isEqualWithoutConsideringStr(pfl)
61
+ ):
56
62
  zeLev = lev
57
63
  break
58
- assert(zeLev is not None)
59
- cache[(fieldName,procID)]["zeLev"]=zeLev
64
+ assert zeLev is not None
65
+ cache[(fieldName, procID)]["zeLev"] = zeLev
60
66
  #
61
- m0Part=mm[0][ids]
62
- mLev=mm[zeLev]
67
+ m0Part = mm[0][ids]
68
+ mLev = mm[zeLev]
63
69
  #
64
- trado2n=m0Part.zipCoordsTraducer() # 3D part of nodes o2n
65
- trad=trado2n.invertArrayO2N2N2O(m0Part.getNumberOfNodes()) # 3D part of nodes n2o
66
- part=mLev.getCellIdsFullyIncludedInNodeIds(trad)
67
- mSubPart=mLev[part] # 2D part lying on 3D part
68
- mSubPartReducedNode=mSubPart.deepCopy() ; mSubPartReducedNode.renumberNodesInConn(trado2n) ; mSubPartReducedNode.setCoords(m0Part.getCoords()) # 2D part lying on 3D part node zipped
70
+ trado2n = m0Part.zipCoordsTraducer() # 3D part of nodes o2n
71
+ trad = trado2n.invertArrayO2N2N2O(
72
+ m0Part.getNumberOfNodes()
73
+ ) # 3D part of nodes n2o
74
+ part = mLev.getCellIdsFullyIncludedInNodeIds(trad)
75
+ mSubPart = mLev[part] # 2D part lying on 3D part
76
+ mSubPartReducedNode = mSubPart.deepCopy()
77
+ mSubPartReducedNode.renumberNodesInConn(trado2n)
78
+ mSubPartReducedNode.setCoords(
79
+ m0Part.getCoords()
80
+ ) # 2D part lying on 3D part node zipped
69
81
  #
70
- if mSubPart.getNumberOfCells()==0:
71
- cache[(fieldName,procID)]["res"] = None
72
- cache[(fieldName,procID)]["subProfileInProcReducedNode"] = None
82
+ if mSubPart.getNumberOfCells() == 0:
83
+ cache[(fieldName, procID)]["res"] = None
84
+ cache[(fieldName, procID)]["subProfileInProcReducedNode"] = None
73
85
  return
74
86
  cellsInSubPartFetchedByProfile = mSubPart.getCellIdsFullyIncludedInNodeIds(pfl)
75
- mSubPartFetchedByPfl=mSubPart[cellsInSubPartFetchedByProfile]
76
- subProfileInProc=mSubPartFetchedByPfl.computeFetchedNodeIds()
87
+ mSubPartFetchedByPfl = mSubPart[cellsInSubPartFetchedByProfile]
88
+ subProfileInProc = mSubPartFetchedByPfl.computeFetchedNodeIds()
77
89
  mSubPartFetchedByPfl.zipCoords()
78
90
  #
79
- res=pfl.findIdForEach(subProfileInProc)
80
- subProfileInProcReducedNode=subProfileInProc.deepCopy() ; subProfileInProcReducedNode.transformWithIndArr(trado2n)
91
+ res = pfl.findIdForEach(subProfileInProc)
92
+ subProfileInProcReducedNode = subProfileInProc.deepCopy()
93
+ subProfileInProcReducedNode.transformWithIndArr(trado2n)
81
94
  subProfileInProcReducedNode.setName(pfl.getName())
82
95
  #
83
- cache[(fieldName,procID)]["res"] = res
84
- cache[(fieldName,procID)]["subProfileInProcReducedNode"] = subProfileInProcReducedNode
96
+ cache[(fieldName, procID)]["res"] = res
97
+ cache[(fieldName, procID)]["subProfileInProcReducedNode"] = (
98
+ subProfileInProcReducedNode
99
+ )
85
100
  pass
86
101
 
87
-
88
102
  @classmethod
89
- def __splitMEDFileField1TSNode(cls,t,mm,mmOut,f1tsIn,f1tsOut,ids,cache,procID):
90
- if len(f1tsIn.getPflsReallyUsed())!=0:
91
- arr,pfl=f1tsIn.getFieldWithProfile(ON_NODES,0,mm)
103
+ def __splitMEDFileField1TSNode(
104
+ cls, t, mm, mmOut, f1tsIn, f1tsOut, ids, cache, procID
105
+ ):
106
+ if len(f1tsIn.getPflsReallyUsed()) != 0:
107
+ arr, pfl = f1tsIn.getFieldWithProfile(ON_NODES, 0, mm)
92
108
  #
93
- if (f1tsIn.getName(),procID) not in cache:
94
- cls.__splitMEDFileField1TSNodePfl(mm,f1tsIn.getName(),pfl,ids,cache,procID)
109
+ if (f1tsIn.getName(), procID) not in cache:
110
+ cls.__splitMEDFileField1TSNodePfl(
111
+ mm, f1tsIn.getName(), pfl, ids, cache, procID
112
+ )
95
113
  pass
96
- zeLev = cache[(f1tsIn.getName(),procID)]["zeLev"]
97
- res = cache[(f1tsIn.getName(),procID)]["res"]
98
- subProfileInProcReducedNode = cache[(f1tsIn.getName(),procID)]["subProfileInProcReducedNode"]
99
- if (zeLev is None) or (res is None) or (subProfileInProcReducedNode is None):
114
+ zeLev = cache[(f1tsIn.getName(), procID)]["zeLev"]
115
+ res = cache[(f1tsIn.getName(), procID)]["res"]
116
+ subProfileInProcReducedNode = cache[(f1tsIn.getName(), procID)][
117
+ "subProfileInProcReducedNode"
118
+ ]
119
+ if (
120
+ (zeLev is None)
121
+ or (res is None)
122
+ or (subProfileInProcReducedNode is None)
123
+ ):
100
124
  return
101
- if len(res)>0:
102
- fRes=MEDCouplingFieldDouble(ON_NODES)
125
+ if len(res) > 0:
126
+ fRes = MEDCouplingFieldDouble(ON_NODES)
103
127
  fRes.setArray(arr[res])
104
128
  fRes.setName(f1tsIn.getName())
105
- #fRes.setMesh(mSubPartFetchedByPfl)
106
- #fRes.copyAllTinyAttrFrom(f_medcoupling)
107
- a,b,c=f1tsIn.getTime(); fRes.setTime(c,a,b)
108
- f1tsOut.setFieldProfile(fRes,mmOut,zeLev,subProfileInProcReducedNode)
129
+ # fRes.setMesh(mSubPartFetchedByPfl)
130
+ # fRes.copyAllTinyAttrFrom(f_medcoupling)
131
+ a, b, c = f1tsIn.getTime()
132
+ fRes.setTime(c, a, b)
133
+ f1tsOut.setFieldProfile(fRes, mmOut, zeLev, subProfileInProcReducedNode)
109
134
  pass
110
- #raise RuntimeError("Field \"%s\" contains profiles ! Not supported yet ! This field will be ignored !" % (f1tsIn.getName()))
135
+ # raise RuntimeError("Field \"%s\" contains profiles ! Not supported yet ! This field will be ignored !" % (f1tsIn.getName()))
111
136
  else:
112
- f=f1tsIn.getFieldOnMeshAtLevel(t,0,mm)
113
- fRet=f[ids]
137
+ f = f1tsIn.getFieldOnMeshAtLevel(t, 0, mm)
138
+ fRet = f[ids]
114
139
  f1tsOut.setFieldNoProfileSBT(fRet)
115
140
  pass
116
141
  pass
117
-
142
+
118
143
  @classmethod
119
- def __splitMEDFileField1TSCell(cls,t,mm,mmOut,f1tsIn,f1tsOut,ids,cache,procID):
120
- f=f1tsIn.getFieldOnMeshAtLevel(t,0,mm)
121
- fRet=f[ids]
122
- m=fRet.getMesh() ; m.zipCoords()
123
- o2n=m.getRenumArrForMEDFileFrmt() ; fRet.renumberCells(o2n,False)
144
+ def __splitMEDFileField1TSCell(
145
+ cls, t, mm, mmOut, f1tsIn, f1tsOut, ids, cache, procID
146
+ ):
147
+ f = f1tsIn.getFieldOnMeshAtLevel(t, 0, mm)
148
+ fRet = f[ids]
149
+ m = fRet.getMesh()
150
+ m.zipCoords()
151
+ o2n = m.getRenumArrForMEDFileFrmt()
152
+ fRet.renumberCells(o2n, False)
124
153
  f1tsOut.setFieldNoProfileSBT(fRet)
125
154
  pass
126
-
127
- def __splitMEDFileField1TS(self,mm,mmOutList,f1ts,idsLst,cache):
155
+
156
+ def __splitMEDFileField1TS(self, mm, mmOutList, f1ts, idsLst, cache):
128
157
  """
129
- Split input f1ts into parts defined by idsLst.
158
+ Split input f1ts into parts defined by idsLst.
130
159
 
131
- :param mm: The underlying mesh of f1ts
132
- :param f1ts: The field to be split
133
- :param idsLst: For each proc the cell ids at level 0
134
- :return: A list of fields.
160
+ :param mm: The underlying mesh of f1ts
161
+ :param f1ts: The field to be split
162
+ :param idsLst: For each proc the cell ids at level 0
163
+ :return: A list of fields.
135
164
  """
136
- ret=[f1ts.__class__() for i in range(len(idsLst))]
137
- dico={ON_CELLS:MEDLoaderSplitter.__splitMEDFileField1TSCell,
138
- ON_NODES:MEDLoaderSplitter.__splitMEDFileField1TSNode,
139
- ON_GAUSS_PT:MEDLoaderSplitter.__splitMEDFileField1TSCell,
140
- ON_GAUSS_NE:MEDLoaderSplitter.__splitMEDFileField1TSCell}
165
+ ret = [f1ts.__class__() for i in range(len(idsLst))]
166
+ dico = {
167
+ ON_CELLS: MEDLoaderSplitter.__splitMEDFileField1TSCell,
168
+ ON_NODES: MEDLoaderSplitter.__splitMEDFileField1TSNode,
169
+ ON_GAUSS_PT: MEDLoaderSplitter.__splitMEDFileField1TSCell,
170
+ ON_GAUSS_NE: MEDLoaderSplitter.__splitMEDFileField1TSCell,
171
+ }
141
172
  for t in f1ts.getTypesOfFieldAvailable():
142
- for procID,f0 in enumerate(ret):
143
- dico[t](t,mm,mmOutList[procID][0],f1ts,f0,idsLst[procID],cache,procID)
173
+ for procID, f0 in enumerate(ret):
174
+ dico[t](
175
+ t, mm, mmOutList[procID][0], f1ts, f0, idsLst[procID], cache, procID
176
+ )
144
177
  pass
145
178
  pass
146
179
  return ret
147
-
148
- def __splitFields(self,mm,mmOutList,mfflds,idsLst):
180
+
181
+ def __splitFields(self, mm, mmOutList, mfflds, idsLst):
149
182
  ret0 = [MEDFileFields() for i in range(len(idsLst))]
150
183
  from collections import defaultdict
184
+
151
185
  cache = defaultdict(dict)
152
186
  for fmts in mfflds:
153
- ret1=[fmts.__class__() for i in range(len(idsLst))]
187
+ ret1 = [fmts.__class__() for i in range(len(idsLst))]
154
188
  for f1ts in fmts:
155
- for fmtsPart,f1tsPart in zip(ret1,self.__splitMEDFileField1TS(mm,mmOutList,f1ts,idsLst,cache)):
189
+ for fmtsPart, f1tsPart in zip(
190
+ ret1,
191
+ self.__splitMEDFileField1TS(mm, mmOutList, f1ts, idsLst, cache),
192
+ ):
156
193
  if f1tsPart.getUndergroundDataArray():
157
- if len(f1tsPart.getUndergroundDataArray())!=0 :
194
+ if len(f1tsPart.getUndergroundDataArray()) != 0:
158
195
  fmtsPart.pushBackTimeStep(f1tsPart)
159
196
  pass
160
197
  pass
161
- for fieldsPart,fmtsPart in zip(ret0,ret1):
162
- if len(fmtsPart) != 0 :
163
- fieldsPart.pushField(fmtsPart);
198
+ for fieldsPart, fmtsPart in zip(ret0, ret1):
199
+ if len(fmtsPart) != 0:
200
+ fieldsPart.pushField(fmtsPart)
164
201
  pass
165
202
  pass
166
203
  return ret0
167
204
 
168
- def __splitMesh(self,mfm,idsLst):
205
+ def __splitMesh(self, mfm, idsLst):
169
206
  ret0 = [MEDFileMeshes() for i in range(len(idsLst))]
170
- m=mfm[0]
171
- addlevs=list(mfm.getNonEmptyLevels())[1:]
172
- dAddlevs={k:mfm[k] for k in addlevs}
173
- for ret,ids in zip(ret0,idsLst):
174
- mlPart=mfm.createNewEmpty()
175
- mPart=m[ids] ; trado2n=mPart.zipCoordsTraducer()
176
- trad=trado2n.invertArrayO2N2N2O(mPart.getNumberOfNodes())
177
- mlPart[0]=mPart
207
+ m = mfm[0]
208
+ addlevs = list(mfm.getNonEmptyLevels())[1:]
209
+ dAddlevs = {k: mfm[k] for k in addlevs}
210
+ for ret, ids in zip(ret0, idsLst):
211
+ mlPart = mfm.createNewEmpty()
212
+ mPart = m[ids]
213
+ trado2n = mPart.zipCoordsTraducer()
214
+ trad = trado2n.invertArrayO2N2N2O(mPart.getNumberOfNodes())
215
+ mlPart[0] = mPart
178
216
  if 0 in mfm.getFamArrNonEmptyLevelsExt():
179
- mlPart.setFamilyFieldArr(0,mfm.getFamilyFieldAtLevel(0)[ids])
217
+ mlPart.setFamilyFieldArr(0, mfm.getFamilyFieldAtLevel(0)[ids])
180
218
  pass
181
219
  if 0 in mfm.getNameArrNonEmptyLevelsExt():
182
220
  mlPart.setNameFieldAtLevel(0, mfm.getNameFieldAtLevel(0)[ids])
183
221
  if 1 in mfm.getFamArrNonEmptyLevelsExt():
184
- mlPart.setFamilyFieldArr(1,mfm.getFamilyFieldAtLevel(1)[trad])
222
+ mlPart.setFamilyFieldArr(1, mfm.getFamilyFieldAtLevel(1)[trad])
185
223
  pass
186
224
  if 1 in mfm.getNameArrNonEmptyLevelsExt():
187
225
  mlPart.setNameFieldAtLevel(1, mfm.getNameFieldAtLevel(1)[trad])
188
- for k,v in dAddlevs.items():
189
- part=v.getCellIdsFullyIncludedInNodeIds(trad)
190
- mSubPart=v[part] ; mSubPart.renumberNodesInConn(trado2n) ; mSubPart.setCoords(mPart.getCoords())
191
- mlPart[k]=mSubPart
192
- mlPart.setFamilyFieldArr(k,mfm.getFamilyFieldAtLevel(k)[part])
226
+ for k, v in dAddlevs.items():
227
+ part = v.getCellIdsFullyIncludedInNodeIds(trad)
228
+ mSubPart = v[part]
229
+ mSubPart.renumberNodesInConn(trado2n)
230
+ mSubPart.setCoords(mPart.getCoords())
231
+ mlPart[k] = mSubPart
232
+ mlPart.setFamilyFieldArr(k, mfm.getFamilyFieldAtLevel(k)[part])
193
233
  if k in mfm.getNameArrNonEmptyLevelsExt():
194
234
  mlPart.setNameFieldAtLevel(k, mfm.getNameFieldAtLevel(k)[part])
195
235
  mlPart.copyFamGrpMapsFrom(mfm)
196
236
  ret.pushMesh(mlPart)
197
237
  pass
198
238
  return ret0
239
+
199
240
  pass