medcoupling 9.13.0__cp313-cp313-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.
MEDLoaderFinalize.py ADDED
@@ -0,0 +1,66 @@
1
+ # -*- coding: iso-8859-1 -*-
2
+ # Copyright (C) 2023-2024 CEA, EDF
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ #
18
+ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19
+ #
20
+
21
+ def MEDFileUMeshReduceToCells(self, level, keepCells, removeOrphanNodes=True):
22
+ """
23
+ Method returning a new MEDFileUMesh, restriction of self to level and keepCell cells at this level.
24
+ This method also
25
+
26
+ :param level: Specifies the top level of the returned MEDFileUMesh expected
27
+ :param keepCells: A DataArrayInt specifying cell ids at level level of self
28
+ :param removeOrphanNodes: Specifies if orphan nodes should be removed at the end
29
+
30
+ see also MEDFileUMesh.extractPart
31
+ """
32
+ import MEDLoader as ml
33
+ subLevs = [l for l in self.getNonEmptyLevels() if l<=level]
34
+ subMeshes = [self[lev] for lev in subLevs]
35
+ allFamilyFields = [self.getFamilyFieldAtLevel(lev) for lev in subLevs]
36
+ allRefMesh = subMeshes[0]
37
+ refMesh = allRefMesh[keepCells]
38
+
39
+ mmOut = ml.MEDFileUMesh()
40
+ # level 0
41
+ mmOut[0] = refMesh
42
+ mmOut.setFamilyFieldArr(0,allFamilyFields[0][keepCells])
43
+
44
+ # subLevels
45
+ for curLev,meshLev,famFieldLev in zip(subLevs[1:],subMeshes[1:],allFamilyFields[1:]):
46
+ allMeshLev,d,di, rd,rdi = allRefMesh.explodeMeshTo( curLev-level )
47
+ a,b = allMeshLev.areCellsIncludedIn(meshLev,2)
48
+ if not a:
49
+ raise RuntimeError("Error in mesh {}")
50
+ dlev,dlevi = ml.DataArrayInt.ExtractFromIndexedArrays( keepCells, d,di )
51
+ dlev2 = dlev.buildUniqueNotSorted()
52
+ cellsToKeepLev = ml.DataArrayInt.BuildIntersection([dlev2,b])
53
+ cellsToKeepLev = b.indicesOfSubPart(cellsToKeepLev)
54
+ cellsToKeepLev.sort()
55
+ mmOut[curLev] = meshLev[cellsToKeepLev]
56
+ mmOut.setFamilyFieldArr(curLev,famFieldLev[cellsToKeepLev])
57
+
58
+ allFamNodes = mmOut.getFamilyFieldAtLevel(1)
59
+ if allFamNodes:
60
+ mmOut.setFamilyFieldArr(1,allFamNodes[:])
61
+
62
+ if removeOrphanNodes:
63
+ mmOut.zipCoords()
64
+
65
+ mmOut.copyFamGrpMapsFrom(self)
66
+ return mmOut
MEDLoaderSplitter.py ADDED
@@ -0,0 +1,199 @@
1
+ # -*- coding: iso-8859-1 -*-
2
+ # Copyright (C) 2007-2024 CEA, EDF
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ #
18
+ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19
+ #
20
+ # Author : Anthony GEAY (CEA/DEN/DM2S/STMF/LGLS)
21
+
22
+ from medcoupling import *
23
+ import os
24
+
25
+ class MEDLoaderSplitter:
26
+ @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)
30
+ pass
31
+
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:
37
+ 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)
44
+ pass
45
+ pass
46
+
47
+ def getSplittedInstances(self):
48
+ return self._mfd_splitted
49
+
50
+ @classmethod
51
+ def __splitMEDFileField1TSNodePfl(cls,mm,fieldName,pfl,ids,cache,procID):
52
+ zeLev = None
53
+ for lev in reversed(mm.getNonEmptyLevels()):
54
+ cellIds = mm[lev].getCellIdsLyingOnNodes(pfl,True)
55
+ if mm[lev][cellIds].computeFetchedNodeIds().isEqualWithoutConsideringStr(pfl):
56
+ zeLev = lev
57
+ break
58
+ assert(zeLev is not None)
59
+ cache[(fieldName,procID)]["zeLev"]=zeLev
60
+ #
61
+ m0Part=mm[0][ids]
62
+ mLev=mm[zeLev]
63
+ #
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
69
+ #
70
+ if mSubPart.getNumberOfCells()==0:
71
+ cache[(fieldName,procID)]["res"] = None
72
+ cache[(fieldName,procID)]["subProfileInProcReducedNode"] = None
73
+ return
74
+ cellsInSubPartFetchedByProfile = mSubPart.getCellIdsFullyIncludedInNodeIds(pfl)
75
+ mSubPartFetchedByPfl=mSubPart[cellsInSubPartFetchedByProfile]
76
+ subProfileInProc=mSubPartFetchedByPfl.computeFetchedNodeIds()
77
+ mSubPartFetchedByPfl.zipCoords()
78
+ #
79
+ res=pfl.findIdForEach(subProfileInProc)
80
+ subProfileInProcReducedNode=subProfileInProc.deepCopy() ; subProfileInProcReducedNode.transformWithIndArr(trado2n)
81
+ subProfileInProcReducedNode.setName(pfl.getName())
82
+ #
83
+ cache[(fieldName,procID)]["res"] = res
84
+ cache[(fieldName,procID)]["subProfileInProcReducedNode"] = subProfileInProcReducedNode
85
+ pass
86
+
87
+
88
+ @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)
92
+ #
93
+ if (f1tsIn.getName(),procID) not in cache:
94
+ cls.__splitMEDFileField1TSNodePfl(mm,f1tsIn.getName(),pfl,ids,cache,procID)
95
+ 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):
100
+ return
101
+ if len(res)>0:
102
+ fRes=MEDCouplingFieldDouble(ON_NODES)
103
+ fRes.setArray(arr[res])
104
+ 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)
109
+ pass
110
+ #raise RuntimeError("Field \"%s\" contains profiles ! Not supported yet ! This field will be ignored !" % (f1tsIn.getName()))
111
+ else:
112
+ f=f1tsIn.getFieldOnMeshAtLevel(t,0,mm)
113
+ fRet=f[ids]
114
+ f1tsOut.setFieldNoProfileSBT(fRet)
115
+ pass
116
+ pass
117
+
118
+ @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)
124
+ f1tsOut.setFieldNoProfileSBT(fRet)
125
+ pass
126
+
127
+ def __splitMEDFileField1TS(self,mm,mmOutList,f1ts,idsLst,cache):
128
+ """
129
+ Split input f1ts into parts defined by idsLst.
130
+
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.
135
+ """
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}
141
+ 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)
144
+ pass
145
+ pass
146
+ return ret
147
+
148
+ def __splitFields(self,mm,mmOutList,mfflds,idsLst):
149
+ ret0 = [MEDFileFields() for i in range(len(idsLst))]
150
+ from collections import defaultdict
151
+ cache = defaultdict(dict)
152
+ for fmts in mfflds:
153
+ ret1=[fmts.__class__() for i in range(len(idsLst))]
154
+ for f1ts in fmts:
155
+ for fmtsPart,f1tsPart in zip(ret1,self.__splitMEDFileField1TS(mm,mmOutList,f1ts,idsLst,cache)):
156
+ if f1tsPart.getUndergroundDataArray():
157
+ if len(f1tsPart.getUndergroundDataArray())!=0 :
158
+ fmtsPart.pushBackTimeStep(f1tsPart)
159
+ pass
160
+ pass
161
+ for fieldsPart,fmtsPart in zip(ret0,ret1):
162
+ if len(fmtsPart) != 0 :
163
+ fieldsPart.pushField(fmtsPart);
164
+ pass
165
+ pass
166
+ return ret0
167
+
168
+ def __splitMesh(self,mfm,idsLst):
169
+ 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
178
+ if 0 in mfm.getFamArrNonEmptyLevelsExt():
179
+ mlPart.setFamilyFieldArr(0,mfm.getFamilyFieldAtLevel(0)[ids])
180
+ pass
181
+ if 0 in mfm.getNameArrNonEmptyLevelsExt():
182
+ mlPart.setNameFieldAtLevel(0, mfm.getNameFieldAtLevel(0)[ids])
183
+ if 1 in mfm.getFamArrNonEmptyLevelsExt():
184
+ mlPart.setFamilyFieldArr(1,mfm.getFamilyFieldAtLevel(1)[trad])
185
+ pass
186
+ if 1 in mfm.getNameArrNonEmptyLevelsExt():
187
+ 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])
193
+ if k in mfm.getNameArrNonEmptyLevelsExt():
194
+ mlPart.setNameFieldAtLevel(k, mfm.getNameFieldAtLevel(k)[part])
195
+ mlPart.copyFamGrpMapsFrom(mfm)
196
+ ret.pushMesh(mlPart)
197
+ pass
198
+ return ret0
199
+ pass
MEDPartitioner.py ADDED
@@ -0,0 +1,163 @@
1
+ # This file was automatically generated by SWIG (https://www.swig.org).
2
+ # Version 4.1.1
3
+ #
4
+ # Do not make changes to this file unless you know what you are doing - modify
5
+ # the SWIG interface file instead.
6
+
7
+ from sys import version_info as _swig_python_version_info
8
+ # Import the low-level C/C++ module
9
+ if __package__ or "." in __name__:
10
+ from . import _MEDPartitioner
11
+ else:
12
+ import _MEDPartitioner
13
+
14
+ try:
15
+ import builtins as __builtin__
16
+ except ImportError:
17
+ import __builtin__
18
+
19
+ def _swig_repr(self):
20
+ try:
21
+ strthis = "proxy of " + self.this.__repr__()
22
+ except __builtin__.Exception:
23
+ strthis = ""
24
+ return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
25
+
26
+
27
+ def _swig_setattr_nondynamic_instance_variable(set):
28
+ def set_instance_attr(self, name, value):
29
+ if name == "this":
30
+ set(self, name, value)
31
+ elif name == "thisown":
32
+ self.this.own(value)
33
+ elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
34
+ set(self, name, value)
35
+ else:
36
+ raise AttributeError("You cannot add instance attributes to %s" % self)
37
+ return set_instance_attr
38
+
39
+
40
+ def _swig_setattr_nondynamic_class_variable(set):
41
+ def set_class_attr(cls, name, value):
42
+ if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
43
+ set(cls, name, value)
44
+ else:
45
+ raise AttributeError("You cannot add class attributes to %s" % cls)
46
+ return set_class_attr
47
+
48
+
49
+ def _swig_add_metaclass(metaclass):
50
+ """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
51
+ def wrapper(cls):
52
+ return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
53
+ return wrapper
54
+
55
+
56
+ class _SwigNonDynamicMeta(type):
57
+ """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
58
+ __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
59
+
60
+
61
+ class Graph(object):
62
+ r"""1"""
63
+
64
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
65
+
66
+ def __init__(self, *args, **kwargs):
67
+ raise AttributeError("No constructor defined")
68
+ __repr__ = _swig_repr
69
+ METIS = _MEDPartitioner.Graph_METIS
70
+ r"""1"""
71
+ SCOTCH = _MEDPartitioner.Graph_SCOTCH
72
+ r"""1"""
73
+ PTSCOTCH = _MEDPartitioner.Graph_PTSCOTCH
74
+ r"""1"""
75
+
76
+ def partGraph(self, *args):
77
+ r"""
78
+ partGraph(Graph self, int ndomain, std::string const & options_string="", ParaDomainSelector * sel=None)
79
+ 1
80
+ """
81
+ return _MEDPartitioner.Graph_partGraph(self, *args)
82
+
83
+ def getGraph(self):
84
+ r"""
85
+ getGraph(Graph self) -> MEDCoupling::MEDCouplingSkyLineArray *
86
+ 1
87
+ """
88
+ return _MEDPartitioner.Graph_getGraph(self)
89
+
90
+ def getPartition(self):
91
+ r"""
92
+ getPartition(Graph self) -> MEDCoupling::MEDCouplingSkyLineArray const *
93
+ 1
94
+ """
95
+ return _MEDPartitioner.Graph_getPartition(self)
96
+
97
+ def nbVertices(self):
98
+ r"""
99
+ nbVertices(Graph self) -> int
100
+ 1
101
+ """
102
+ return _MEDPartitioner.Graph_nbVertices(self)
103
+ __swig_destroy__ = _MEDPartitioner.delete_Graph
104
+
105
+ # Register Graph in _MEDPartitioner:
106
+ _MEDPartitioner.Graph_swigregister(Graph)
107
+ class MEDPartitioner(object):
108
+ r"""1"""
109
+
110
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
111
+ __repr__ = _swig_repr
112
+
113
+ def __init__(self, *args):
114
+ r"""
115
+ __init__(MEDPartitioner self, std::string const & filename, int ndomains=1, std::string const & library="metis", bool create_boundary_faces=False, bool create_joints=False, bool mesure_memory=False) -> MEDPartitioner
116
+ __init__(MEDPartitioner self, MEDCoupling::MEDFileData const * fileData, int ndomains=1, std::string const & library="metis", bool create_boundary_faces=False, bool create_joints=False, bool mesure_memory=False) -> MEDPartitioner
117
+ __init__(MEDPartitioner self, MEDCoupling::MEDFileData const * fileData, Graph graph, bool create_boundary_faces=False, bool create_joints=False, bool mesure_memory=False) -> MEDPartitioner
118
+ 1
119
+ """
120
+ _MEDPartitioner.MEDPartitioner_swiginit(self, _MEDPartitioner.new_MEDPartitioner(*args))
121
+
122
+ @staticmethod
123
+ def Graph(*args):
124
+ r"""
125
+ Graph(MEDCoupling::MEDCouplingSkyLineArray * graph, MEDPARTITIONER::Graph::splitter_type split=METIS, int * edgeweight=None, MEDCoupling::DataArrayIdType * vlbloctab=None) -> Graph
126
+ 1
127
+ """
128
+ return _MEDPartitioner.MEDPartitioner_Graph(*args)
129
+
130
+ @staticmethod
131
+ def AvailableAlgorithms():
132
+ r"""
133
+ AvailableAlgorithms() -> std::vector< std::string >
134
+ 1
135
+ """
136
+ return _MEDPartitioner.MEDPartitioner_AvailableAlgorithms()
137
+
138
+ @staticmethod
139
+ def AllAlgorithms():
140
+ r"""
141
+ AllAlgorithms() -> std::vector< std::string >
142
+ 1
143
+ """
144
+ return _MEDPartitioner.MEDPartitioner_AllAlgorithms()
145
+
146
+ def getMEDFileData(self):
147
+ r"""
148
+ getMEDFileData(MEDPartitioner self) -> MEDCoupling::MEDFileData *
149
+ 1
150
+ """
151
+ return _MEDPartitioner.MEDPartitioner_getMEDFileData(self)
152
+
153
+ def write(self, filename):
154
+ r"""
155
+ write(MEDPartitioner self, std::string const & filename)
156
+ 1
157
+ """
158
+ return _MEDPartitioner.MEDPartitioner_write(self, filename)
159
+ __swig_destroy__ = _MEDPartitioner.delete_MEDPartitioner
160
+
161
+ # Register MEDPartitioner in _MEDPartitioner:
162
+ _MEDPartitioner.MEDPartitioner_swigregister(MEDPartitioner)
163
+