Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / GaussToCell / script / TestCase.py
1 # Copyright (C) 2018-2022  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 fname="VoroGauss1.med"
23 meshName="mesh"
24 mm=MEDFileUMesh()
25 coords=DataArrayDouble([0,0, 1,0, 2,0, 3,0, 4,0, 5,0, 0,1, 1,1, 2,1, 0,2, 1,2, 3,1, 4,1],13,2)
26 m0=MEDCouplingUMesh(meshName,2)
27 m0.setCoords(coords)
28 m0.allocateCells()
29 m0.insertNextCell(NORM_TRI3,[2,3,8])
30 m0.insertNextCell(NORM_TRI3,[3,4,11])
31 m0.insertNextCell(NORM_TRI3,[4,5,12])
32 m0.insertNextCell(NORM_TRI3,[6,7,9])
33 m0.insertNextCell(NORM_TRI3,[7,8,10])
34 m0.insertNextCell(NORM_QUAD4,[0,1,7,6])
35 m0.insertNextCell(NORM_QUAD4,[1,2,8,7])
36 mm[0]=m0
37 m1=MEDCouplingUMesh(meshName,1)
38 m1.setCoords(coords)
39 m1.allocateCells()
40 m1.insertNextCell(NORM_SEG2,[0,1])
41 m1.insertNextCell(NORM_SEG2,[1,2])
42 m1.insertNextCell(NORM_SEG2,[2,3])
43 m1.insertNextCell(NORM_SEG2,[3,4])
44 m1.insertNextCell(NORM_SEG2,[4,5])
45 mm[-1]=m1
46 mm.setFamilyFieldArr(0,DataArrayInt([-1,-1,-2,-3,-3,-1,-3]))
47 mm.setFamilyFieldArr(-1,DataArrayInt([-1,-4,-4,-4,-1]))
48 for i in [-1,-2,-3,-4]:
49     mm.setFamilyId("Fam_%d"%i,i)
50     mm.setFamiliesOnGroup("G%d"%(abs(i)),["Fam_%d"%i])
51     pass
52 mm.write(fname,2)
53 #
54 f0=MEDCouplingFieldDouble(ON_GAUSS_PT)
55 f0.setMesh(m0)
56 f0.setName("MyFieldPG") ; f0.setMesh(m0)
57 f0.setGaussLocalizationOnType(NORM_TRI3,[0,0, 1,0, 0,1],[0.1,0.1, 0.8,0.1, 0.1,0.8],[0.3,0.3,0.4])
58 f0.setGaussLocalizationOnType(NORM_QUAD4,[-1,-1, 1,-1, 1,1, -1,1],[-0.57735,-0.57735,0.57735,-0.57735,0.57735,0.57735,-0.57735,0.57735],[0.25,0.25,0.25,0.25])
59 arr=DataArrayDouble(f0.getNumberOfTuplesExpected()) ; arr.iota()
60 arr=DataArrayDouble.Meld(arr,arr)
61 arr.setInfoOnComponents(["comp0","comp1"])
62 f0.setArray(arr)
63 WriteFieldUsingAlreadyWrittenMesh(fname,f0)
64 #
65 f1=MEDCouplingFieldDouble(ON_CELLS)
66 f1.setMesh(m0)
67 f1.setName("MyFieldCell") ; f1.setMesh(m0)
68 arr=DataArrayDouble(f1.getNumberOfTuplesExpected()) ; arr.iota()
69 arr=DataArrayDouble.Meld(arr,arr)
70 arr.setInfoOnComponents(["comp2","comp3"])
71 f1.setArray(arr)
72 WriteFieldUsingAlreadyWrittenMesh(fname,f1)
73