Salome HOME
Copyright update 2020
[modules/med.git] / doc / tut / mergefields / splitdemo / splitdemo.py
1 # Copyright (C) 2012-2020  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from MEDLoader import *
21
22 fns=['DomainMesh_1.med', 'DomainMesh_2.med','DomainMesh_3.med', 'DomainMesh_4.med']
23 outs=["out1.vtu","out2.vtu","out3.vtu","out4.vtu"]
24 trs=[(-0.714,-0.714,0.),(0.,0.,0.),(-0.577,-0.577,-0.577),(-0.577,0.3,-0.577)]
25 scal=0.5
26 fs=4*[None]
27 dds=4*[None]
28 mns=4*[None]
29 i=0
30
31 splitview=True
32
33 for fn in fns:
34     m=MEDFileMesh.New(fn)
35     m=m.getMeshAtLevel(0)
36     m.writeVTK(outs[i])
37     mns[i]=m.deepCopy()
38     if splitview:
39         m.translate([scal*elt for elt in trs[i]])
40     f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME)
41     f.setMesh(m)
42     da=DataArrayDouble.New()
43     da.alloc(m.getNumberOfCells(),1)
44     da.fillWithValue(i)
45     dds[i]=da.deepCopy()
46     f.setArray(da)
47     fs[i]=f
48     i+=1
49     pass
50
51
52 f=MEDCouplingFieldDouble.MergeFields(fs)
53 f.setName("PID")
54
55 MEDCouplingFieldDouble.WriteVTK("Domain.vtu",[f])
56 dd=DataArrayDouble.Aggregate(dds)
57 m=MEDCouplingUMesh.MergeUMeshes(mns)
58 if splitview:
59     m.translate([4.*elt for elt in [0.577,0.577,0.577]])
60 f2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME)
61 f2.setMesh(m)
62 f2.setArray(dd)
63 f2.setName("PID")
64 MEDCouplingFieldDouble.WriteVTK('DomainMesh.vtu',[f2])
65 #m=MEDCouplingUMesh.MergeUMeshes(mns)
66 #m.writeVTK("DomainMesh.vtu")