Salome HOME
Updated copyright comment
[modules/med.git] / doc / tut / medcoupling / test-paravis.py
1 # Copyright (C) 2012-2024  CEA, EDF
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 import CORBA
21 import PARAVIS_Gen_idl
22 import SALOME_ContainerManager_idl
23
24 from SALOME_NamingServicePy import SALOME_NamingServicePy_i
25
26 from MEDCouplingCorba import *
27
28 def createALocalMesh():
29     targetCoords=[ 0., 0., 0., 50., 0., 0. , 200., 0., 0.  , 0., 50., 0., 50., 50., 0. , 200., 50., 0.,   0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
30                        0., 0., 50., 50., 0., 50. , 200., 0., 50.  , 0., 50., 50., 50., 50., 50. , 200., 50., 50.,   0., 200., 50., 50., 200., 50. , 200., 200., 50. ,
31                        0., 0., 200., 50., 0., 200. , 200., 0., 200.  , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,   0., 200., 200., 50., 200., 200. , 200., 200., 200. ];
32     targetConn=[0,1,4,3,9,10,13,12, 1,2,5,4,10,11,14,13, 3,4,7,6,12,13,16,15, 4,5,8,7,13,14,17,16,
33                 9,10,13,12,18,19,22,21, 10,11,14,13,19,20,23,22, 12,13,16,15,21,22,25,24, 13,14,17,16,22,23,26,25];
34     targetMesh=MEDCouplingUMesh.New();
35     targetMesh.setMeshDimension(3);
36     targetMesh.setName("MyMesh3D");
37     targetMesh.setDescription("build3DMesh");
38     targetMesh.allocateCells(12);
39     for i in range(8):
40         targetMesh.insertNextCell(NORM_HEXA8,8,targetConn[8*i:8*(i+1)]);
41         pass
42     targetMesh.finishInsertingCells();
43     myCoords=DataArrayDouble.New();
44     myCoords.setValues(targetCoords,27,3);
45     targetMesh.setCoords(myCoords)
46     myCoords.setName("check in case")
47     return targetMesh;
48
49 def createALocalField1():
50     m=createALocalMesh()
51     field=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
52     field.setMesh(m)
53     da=DataArrayDouble.New()
54     da.setValues([1.,11.,101.,1001., 2.,12.,102.,1002., 3.,13.,103.,1003., 4.,14.,104.,1004., 5.,15.,105.,1005., 6.,16.,106.,1006., 7.,17.,107.,1007., 8.,18.,108.,1008.,],8,4)
55     field.setArray(da)
56     field.setName("vitoo")
57     field.setTime(4.5,3,4)
58     return field
59
60 def createALocalField2():
61     m=createALocalMesh()
62     field=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
63     field.setMesh(m)
64     da=DataArrayDouble.New()
65     da.setValues([float(3*i) for i in range(27)],27,1)
66     field.setArray(da)
67     field.setName("vitooNode")
68     field.setTime(4.7,9,14)
69     return field
70
71 def createALocalMultiField3():
72     fName="FieldOverTimeCorba"
73     m=createALocalMesh()
74     nbOfFields=100
75     fs=nbOfFields*[None]
76     for i in range(nbOfFields):
77         fs[i]=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
78         fs[i].setMesh(m)
79         da=DataArrayDouble.New()
80         da.setValues([0.,1.,2.+i,3.,4.,5.,7.],8,1)
81         fs[i].setArray(da)
82         fs[i].setName(fName)
83         fs[i].setTime(1.2+i,9,14)
84         pass
85     ret=MEDCouplingFieldOverTime.New(fs);
86     return ret
87
88 def createALocalCMesh4():
89     mesh=MEDCouplingCMesh.New();
90     coordsX=DataArrayDouble.New();
91     arrX=[ -1., 1., 2., 4. ]
92     coordsX.setValues(arrX,4,1);
93     coordsY=DataArrayDouble.New();
94     arrY=[ -2., 4., 8. ]
95     coordsY.setValues(arrY,3,1);
96     coordsZ=DataArrayDouble.New();
97     arrZ=[ -3., 3., 6., 12., 17. ]
98     coordsZ.setValues(arrZ,5,1);
99     mesh.setCoords(coordsX,coordsY,coordsZ);
100     mesh.setName("CMeshSample")
101     return mesh
102
103 def createALocalField5():
104     m=createALocalCMesh4()
105     field=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
106     field.setMesh(m)
107     da=DataArrayDouble.New()
108     field.setTime(14.5,0,0)
109     da.setValues([float(7*i) for i in range(24)],24,1)
110     field.setName("MeshOnCMesh");
111     field.setArray(da)
112     return field;
113     
114
115 ######
116
117 orb = CORBA.ORB_init([], CORBA.ORB_ID)
118 poa=orb.resolve_initial_references("RootPOA");
119 mgr=poa._get_the_POAManager();
120 mgr.activate();
121
122 ###### Searching for 
123
124 naming_service = SALOME_NamingServicePy_i(orb)
125 rp=SALOME_ContainerManager_idl._0_Engines.ResourceParameters("","","",["PARAVIS"],1,10,10,1,1,"first",[])
126 cp=SALOME_ContainerManager_idl._0_Engines.ContainerParameters("","get","",1,False,"",rp)
127 sm=naming_service.Resolve("/ContainerManager")
128 cont=sm.GiveContainer(cp)
129 paraviz=naming_service.Resolve("/Containers/%s/FactoryServer/PARAVIS_inst_1"%(cont.getHostName()))
130
131 ######
132
133 meshCorba=MEDCouplingUMeshServant._this(createALocalMesh())
134 ior=orb.object_to_string(meshCorba)
135 print("mesh : ",ior)
136
137 f1=MEDCouplingFieldDoubleServant._this(createALocalField1())
138 ior2=orb.object_to_string(f1)
139 print("Field on cell ",ior2)
140
141 f2=MEDCouplingFieldDoubleServant._this(createALocalField2())
142 ior3=orb.object_to_string(f2)
143 print("Field on node ",ior3)
144
145 fs3=MEDCouplingFieldOverTimeServant._this(createALocalMultiField3())
146 fs3.Register()
147 ior4=orb.object_to_string(fs3)
148 print("Fields over time ",ior4)
149
150 m2=MEDCouplingCMeshServant._this(createALocalCMesh4())
151 ior5=orb.object_to_string(m2)
152 print("CMesh 2 : ",ior5)
153
154 f5=MEDCouplingFieldDoubleServant._this(createALocalField5())
155 ior6=orb.object_to_string(f5)
156 print("Field on cell CMesh ",ior6)
157
158 script="""
159 src1 = ParaMEDCorbaPluginSource()
160 src1.IORCorba = '%s'
161 asc=GetAnimationScene()
162 rw=GetRenderView()
163 dr=Show()\ndr.Visibility = 1
164 """
165
166 content=script%(ior4)
167 paraviz.ExecuteScript(content)