1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author Anthony GEAY (CEA/DEN/DM2S/STMF/LGLS)
22 from MEDLoader import *
25 class MEDLoaderSplitter:
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(fileName)
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 """
35 mfflds=mfd.getFields()
37 raise InterpKernelException("Works only with one mesh !")
38 mfflds=mfflds.partOfThisLyingOnSpecifiedMeshName(mfmsh[0].getName())
39 retf=self.__splitFields(mfmsh[0],mfflds,idsLst)
40 retm=self.__splitMesh(mfmsh[0],idsLst)
41 self._mfd_splitted=[MEDFileData() for i in xrange(len(idsLst))]
42 for a,b,c in zip(self._mfd_splitted,retf,retm):
43 a.setFields(b) ; a.setMeshes(c)
47 def getSplittedInstances(self):
48 return self._mfd_splitted
51 def __splitMEDFileField1TSNode(cls,f,f1ts,ids):
53 f1ts.setFieldNoProfileSBT(fRet)
57 def __splitMEDFileField1TSCell(cls,f,f1ts,ids):
59 m=fRet.getMesh() ; m.zipCoords()
60 o2n=m.getRenumArrForMEDFileFrmt() ; fRet.renumberCells(o2n,False)
61 f1ts.setFieldNoProfileSBT(fRet)
64 def __splitMEDFileField1TS(self,mm,f1ts,idsLst):
65 ret=[MEDFileField1TS() for i in xrange(len(idsLst))]
66 dico={ON_CELLS:self.__splitMEDFileField1TSCell,
67 ON_NODES:self.__splitMEDFileField1TSNode,
68 ON_GAUSS_PT:self.__splitMEDFileField1TSCell,
69 ON_GAUSS_NE:self.__splitMEDFileField1TSCell}
70 for t in f1ts.getTypesOfFieldAvailable():
71 f=f1ts.getFieldOnMeshAtLevel(t,0,mm)
72 for i,f0 in enumerate(ret):
73 dico[t](f,f0,idsLst[i])
78 def __splitFields(self,mm,mfflds,idsLst):
79 ret0=[MEDFileFields() for i in xrange(len(idsLst))]
81 if len(fmts.getPflsReallyUsed())!=0:
82 print "Field \"%s\" contains profiles ! Not supported yet ! This field will be ignored !"%(fmts.getName())
85 ret1=[MEDFileFieldMultiTS() for i in xrange(len(idsLst))]
87 for fmtsPart,f1tsPart in zip(ret1,self.__splitMEDFileField1TS(mm,f1ts,idsLst)):
88 fmtsPart.pushBackTimeStep(f1tsPart)
91 for fieldsPart,fmtsPart in zip(ret0,ret1):
92 fieldsPart.pushField(fmtsPart);
97 def __splitMesh(self,mfm,idsLst):
98 ret0=[MEDFileMeshes() for i in xrange(len(idsLst))]
99 m=mfm.getMeshAtLevel(0)
100 for ret,ids in zip(ret0,idsLst):
101 mlPart=mfm.createNewEmpty()
102 mPart=m[ids] ; trad=mPart.zipCoordsTraducer()
103 trad=trad.invertArrayO2N2N2O(mPart.getNumberOfNodes())
104 mlPart.setMeshAtLevel(0,mPart)
105 if 0 in mfm.getFamArrNonEmptyLevelsExt():
106 mlPart.setFamilyFieldArr(0,mfm.getFamilyFieldAtLevel(0)[ids])
108 if 1 in mfm.getFamArrNonEmptyLevelsExt():
109 mlPart.setFamilyFieldArr(1,mfm.getFamilyFieldAtLevel(1)[trad])
111 mlPart.copyFamGrpMapsFrom(mfm)