1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015 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, or (at your option) any later version.
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)
22 from MEDLoader import *
23 from math import pi,e,sqrt
25 class MEDLoaderDataForTest:
26 def build1DMesh_1(cls):
27 coords=[ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 ]
28 conn=[ 0,1, 1,2, 2,3 , 3,4,5]
29 mesh=MEDCouplingUMesh.New();
30 mesh.setName("1DMesh_1");
31 mesh.setMeshDimension(1);
32 mesh.allocateCells(4);
33 mesh.insertNextCell(NORM_SEG2,2,conn[0:2])
34 mesh.insertNextCell(NORM_SEG2,2,conn[2:4])
35 mesh.insertNextCell(NORM_SEG2,2,conn[4:6])
36 mesh.insertNextCell(NORM_SEG3,3,conn[6:9])
37 mesh.finishInsertingCells();
38 myCoords=DataArrayDouble.New();
39 myCoords.setValues(coords,6,1);
40 myCoords.setInfoOnComponent(0,"tototototototot [m*m*m*m*m*m*m*m]");
41 mesh.setCoords(myCoords);
44 def build2DCurveMesh_1(cls):
45 coords=[ 0.0,0.0, 0.3,0.3, 0.75,0.75, 1.0,1.0, 1.4,1.4, 1.3,1.3 ]
46 conn=[ 0,1, 1,2, 2,3 , 3,4,5]
47 mesh=MEDCouplingUMesh.New();
48 mesh.setName("2DCurveMesh_1");
49 mesh.setMeshDimension(1);
50 mesh.allocateCells(4);
51 mesh.insertNextCell(NORM_SEG2,2,conn[0:2])
52 mesh.insertNextCell(NORM_SEG2,2,conn[2:4])
53 mesh.insertNextCell(NORM_SEG2,2,conn[4:6])
54 mesh.insertNextCell(NORM_SEG3,3,conn[6:9])
55 mesh.finishInsertingCells();
56 myCoords=DataArrayDouble.New();
57 myCoords.setValues(coords,6,2);
58 mesh.setCoords(myCoords);
61 def build2DMesh_1(cls):
62 targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
63 -0.05,0.95, 0.2,1.2, 0.45,0.95]
64 targetConn=[1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4]
65 targetMesh=MEDCouplingUMesh.New();
66 targetMesh.setMeshDimension(2);
67 targetMesh.allocateCells(6);
68 targetMesh.setName("2DMesh_1");
69 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
70 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
71 targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
72 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[12:16])
73 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[16:20])
74 targetMesh.insertNextCell(NORM_POLYGON,4,targetConn[20:24])
75 targetMesh.finishInsertingCells();
76 myCoords=DataArrayDouble.New();
77 myCoords.setValues(targetCoords,12,2);
78 myCoords.setInfoOnComponent(0,"tototototototot [m]");
79 myCoords.setInfoOnComponent(1,"energie [kW]");
80 targetMesh.setCoords(myCoords)
83 def build2DMesh_2(cls):
84 targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
85 -0.05,0.95, 0.2,1.2, 0.45,0.95]
86 targetConn=[1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4]
87 targetMesh=MEDCouplingUMesh.New();
88 targetMesh.setMeshDimension(2);
89 targetMesh.allocateCells(5);
90 targetMesh.setName("2DMesh_2");
91 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
92 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
93 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[12:16])
94 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[16:20])
95 targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
96 targetMesh.finishInsertingCells();
97 myCoords=DataArrayDouble.New();
98 myCoords.setValues(targetCoords,12,2);
99 myCoords.setInfoOnComponent(0,"toto [m]");
100 myCoords.setInfoOnComponent(1,"energie [kW]");
101 targetMesh.setCoords(myCoords);
104 #this mesh has several cells duplicated ! it is not beautiful but efficient to test file WR.
105 def build2DMesh_3(cls):
106 targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
107 -0.05,0.95, 0.2,1.2, 0.45,0.95]
108 targetConn=[1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4]
109 targetMesh=MEDCouplingUMesh.New();
110 targetMesh.setMeshDimension(2);
111 targetMesh.allocateCells(13);
112 targetMesh.setName("2DMesh_3");
113 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
114 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
115 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
116 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
117 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
118 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
119 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[12:16])
120 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[16:20])
121 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[12:16])
122 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[16:20])
123 targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
124 targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
125 targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
126 targetMesh.finishInsertingCells();
127 myCoords=DataArrayDouble.New();
128 myCoords.setValues(targetCoords,12,2);
129 myCoords.setInfoOnComponent(0,"toto [m]");
130 myCoords.setInfoOnComponent(1,"energie [kW]");
131 targetMesh.setCoords(myCoords);
134 def build3DMesh_1(cls):
135 coords=[0.,0.,0., 1.,1.,0., 1.,1.25,0., 0.,1.,0., 1.,1.5,0., 2.,0.,0., 2.,1.,0., 1.,2.,0., 0.,2.,0., 3.,1.,0.,
136 3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
137 0.,0.,1., 1.,1.,1., 1.,1.25,1., 0.,1.,1., 1.,1.5,1., 2.,0.,1., 2.,1.,1., 1.,2.,1., 0.,2.,1., 3.,1.,1.,
138 3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
139 0.,0.,2., 1.,1.,2., 1.,1.25,2., 0.,1.,2., 1.,1.5,2., 2.,0.,2., 2.,1.,2., 1.,2.,2., 0.,2.,2., 3.,1.,2.,
140 3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
141 0.,0.,3., 1.,1.,3., 1.,1.25,3., 0.,1.,3., 1.,1.5,3., 2.,0.,3., 2.,1.,3., 1.,2.,3., 0.,2.,3., 3.,1.,3.,
142 3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.]
145 0,11,1,3,15,26,16,18, 1,2,4,7,13,6,-1,1,16,21,6,-1,6,21,28,13,-1,13,7,22,28,-1,7,4,19,22,-1,4,2,17,19,-1,2,1,16,17,-1,16,21,28,22,19,17,
146 1,6,5,3,16,21,20,18, 13,10,9,6,28,25,24,21,
147 11,8,7,4,2,1,-1,11,26,16,1,-1,1,16,17,2,-1,2,17,19,4,-1,4,19,22,7,-1,7,8,23,22,-1,8,11,26,23,-1,26,16,17,19,22,23,
148 7,12,14,13,22,27,29,28,
150 15,26,16,18,30,41,31,33, 16,17,19,22,28,21,-1,16,31,36,21,-1,21,36,43,28,-1,28,22,37,43,-1,22,19,34,37,-1,19,17,32,34,-1,17,16,31,32,-1,31,36,43,37,34,32,
151 16,21,20,18,31,36,35,33, 28,25,24,21,43,40,39,36,
152 26,23,22,19,17,16,-1,26,41,31,16,-1,16,31,32,17,-1,17,32,34,19,-1,19,34,37,22,-1,22,23,38,37,-1,23,26,41,38,-1,41,31,32,34,37,38,
153 22,27,29,28,37,42,44,43,
155 30,41,31,33,45,56,46,48, 31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47,
156 31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51,
157 41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53,
158 37,42,44,43,52,57,59,58]
160 ret=MEDCouplingUMesh.New();
161 ret.setName("3DMesh_1");
162 ret.setMeshDimension(3);
163 ret.allocateCells(18);
165 ret.insertNextCell(NORM_HEXA8,8,conn[0:8])
166 ret.insertNextCell(NORM_HEXA8,8,conn[51:59])
167 ret.insertNextCell(NORM_HEXA8,8,conn[59:67])
168 ret.insertNextCell(NORM_HEXA8,8,conn[110:118])
170 ret.insertNextCell(NORM_HEXA8,8,conn[118:126])
171 ret.insertNextCell(NORM_HEXA8,8,conn[169:177])
172 ret.insertNextCell(NORM_HEXA8,8,conn[177:185])
173 ret.insertNextCell(NORM_HEXA8,8,conn[228:236])
175 ret.insertNextCell(NORM_HEXA8,8,conn[236:244])
176 ret.insertNextCell(NORM_HEXA8,8,conn[287:295])
177 ret.insertNextCell(NORM_HEXA8,8,conn[295:303])
178 ret.insertNextCell(NORM_HEXA8,8,conn[346:354])
180 ret.insertNextCell(NORM_POLYHED,43,conn[8:51])
181 ret.insertNextCell(NORM_POLYHED,43,conn[67:110])
182 ret.insertNextCell(NORM_POLYHED,43,conn[126:169])
183 ret.insertNextCell(NORM_POLYHED,43,conn[185:228])
184 ret.insertNextCell(NORM_POLYHED,43,conn[244:287])
185 ret.insertNextCell(NORM_POLYHED,43,conn[303:346])
187 ret.finishInsertingCells();
188 myCoords=DataArrayDouble.New();
189 myCoords.setValues(coords,60,3);
190 myCoords.setInfoOnComponent(0,"titi [m]");
191 myCoords.setInfoOnComponent(1,"density power [MW/m^3]");
192 myCoords.setInfoOnComponent(2,"t [kW]");
193 ret.setCoords(myCoords);
196 def build3DSurfMesh_1(cls):
197 targetCoords=[-0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3
198 ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3]
199 targetConn=[1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4]
200 targetMesh=MEDCouplingUMesh.New();
201 targetMesh.setMeshDimension(2);
202 targetMesh.allocateCells(6);
203 targetMesh.setName("3DSurfMesh_1");
204 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
205 targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
206 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[12:16])
207 targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[16:20])
208 targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
209 targetMesh.insertNextCell(NORM_POLYGON,4,targetConn[20:24])
210 targetMesh.finishInsertingCells();
211 myCoords=DataArrayDouble.New();
212 myCoords.setValues(targetCoords,12,3);
213 myCoords.setInfoOnComponent(0,"toto [m]");
214 myCoords.setInfoOnComponent(2,"ff [km]");#component 1 is not set for test
215 targetMesh.setCoords(myCoords);
218 def build3DMesh_2(cls):
219 m3dsurfBase=MEDLoaderDataForTest.build3DSurfMesh_1();
221 m3dsurf=m3dsurfBase.buildPartOfMySelf(numbers,False);
222 m1dBase=MEDLoaderDataForTest.build1DMesh_1();
224 m1d=m1dBase.buildPartOfMySelf(numbers2,False);
225 m1d.changeSpaceDimension(3);
228 m1d.rotate(pt,vec,-pi/2.);
229 ret=m3dsurf.buildExtrudedMesh(m1d,0);
232 def buildMultiLevelMesh_1(cls):
233 coo=[10.,0.,10.,1.25,10.,2.5,10.,3.75,10.,5.,8.75,0.,8.75,1.25,8.75,2.5,8.75,3.75,8.75,5.,7.5,0.,7.5,1.25,7.5,2.5,7.5,3.75,7.5,5.,6.25,0.,6.25,1.25,6.25,2.5,6.25,3.75,6.25,5.,5.,0.,5.,1.25,5.,2.5,5.,3.75,5.,5.,3.75,0.,3.75,1.25,3.75,2.5,3.75,3.75,3.75,5.,2.5,0.,2.5,1.25,2.5,2.5,2.5,3.75,2.5,5.,1.25,0.,1.25,1.25,1.25,2.5,1.25,3.75,1.25,5.,0.,1.25,0.,2.5,0.,3.75,0.,5.,0.,0.,0.,5.,10.,5.,0.,10.,10.,10.,5.,5.,5.,5.,5.,10.,5.,10.,0.625,5.,1.25,5.,1.875,5.,2.5,5.,3.125,5.,3.75,5.,4.375,5.,5.,6.25,5.,7.5,5.,8.75,4.375,10.,3.75,10.,3.125,10.,2.5,10.,1.875,10.,1.25,10.,0.625,10.,0.,8.75,0.,7.5,0.,6.25,4.375,6.25,4.375,7.5,4.375,8.75,3.75,6.25,3.75,7.5,3.75,8.75,3.125,6.25,3.125,7.5,3.125,8.75,2.5,6.25,2.5,7.5,2.5,8.75,1.875,6.25,1.875,7.5,1.875,8.75,1.25,6.25,1.25,7.5,1.25,8.75,0.625,6.25,0.625,7.5,0.625,8.75,5.625,5.,6.25,5.,6.875,5.,7.5,5.,8.125,5.,8.75,5.,9.375,5.,10.,6.25,10.,7.5,10.,8.75,9.375,10.,8.75,10.,8.125,10.,7.5,10.,6.875,10.,6.25,10.,5.625,10.,5.,8.75,5.,7.5,5.,6.25,9.375,6.25,9.375,7.5,9.375,8.75,8.75,6.25,8.75,7.5,8.75,8.75,8.125,6.25,8.125,7.5,8.125,8.75,7.5,6.25,7.5,7.5,7.5,8.75,6.875,6.25,6.875,7.5,6.875,8.75,6.25,6.25,6.25,7.5,6.25,8.75,5.625,6.25,5.625,7.5,5.625,8.75]
234 coo2=DataArrayDouble.New()
235 coo2.setValues(coo,135,2)
236 coo2=coo2.changeNbOfComponents(3,0.)
237 coo2.setInfoOnComponent(0,"X [INCONNUE]")
238 coo2.setInfoOnComponent(1,"Y [INCONNUE]")
239 coo2.setInfoOnComponent(2,"Z [INCONNUE]")
240 c2tri=[0,1,6,0,6,5,1,2,6,2,7,6,2,3,8,2,8,7,3,4,8,4,9,8,5,6,11,5,11,10,6,7,11,7,12,11,7,8,13,7,13,12,8,9,13,9,14,13,10,11,16,10,16,15,11,12,16,12,17,16,12,13,18,12,18,17,13,14,18,14,19,18,15,16,21,15,21,20,16,17,21,17,22,21,17,18,23,17,23,22,18,19,23,19,24,23,20,21,26,20,26,25,21,22,26,22,27,26,22,23,28,22,28,27,23,24,28,24,29,28,25,26,31,25,31,30,26,27,31,27,32,31,27,28,33,27,33,32,28,29,33,29,34,33,30,31,36,30,36,35,31,32,36,32,37,36,32,33,38,32,38,37,33,34,38,34,39,38,35,36,40,35,40,44,36,37,40,37,41,40,37,38,42,37,42,41,38,39,42,39,43,42]
241 c2quad4=[46,101,114,100,101,102,115,114,102,103,116,115,103,48,104,116,100,114,117,99,114,115,118,117,115,116,119,118,116,104,105,119,99,117,120,98,117,118,121,120,118,119,122,121,119,105,106,122,98,120,123,97,120,121,124,123,121,122,125,124,122,106,107,125,97,123,126,96,123,124,127,126,124,125,128,127,125,107,108,128,96,126,129,95,126,127,130,129,127,128,131,130,128,108,109,131,95,129,132,94,129,130,133,132,130,131,134,133,131,109,110,134,94,132,113,50,132,133,112,113,133,134,111,112,134,110,51,111,49,60,73,59,60,61,74,73,61,62,75,74,62,52,63,75,59,73,76,58,73,74,77,76,74,75,78,77,75,63,64,78,58,76,79,57,76,77,80,79,77,78,81,80,78,64,65,81,57,79,82,56,79,80,83,82,80,81,84,83,81,65,66,84,56,82,85,55,82,83,86,85,83,84,87,86,84,66,67,87,55,85,88,54,85,86,89,88,86,87,90,89,87,67,68,90,54,88,91,53,88,89,92,91,89,90,93,92,90,68,69,93,53,91,72,45,91,92,71,72,92,93,70,71,93,69,47,70]
242 m2=MEDCouplingUMesh.New("ma",2)
244 m2.allocateCells(128)
246 for i in xrange(nbTri):
247 m2.insertNextCell(NORM_TRI3,3,c2tri[3*i:3*i+3])
250 for i in xrange(nbQua):
251 m2.insertNextCell(NORM_QUAD4,4,c2quad4[4*i:4*i+4])
253 m2.finishInsertingCells()
254 m2.setDescription("CREE PAR CODE_ASTER")
255 m1=MEDCouplingUMesh.New("ma",1)
257 c1seg=[0,1,1,2,2,3,3,4,4,9,9,14,14,19,19,24,24,29,29,34,34,39,39,43,43,42,42,41,41,40,40,44,44,35,35,30,30,25,25,20,20,15,15,10,10,5,5,0,43,39,39,34,34,29,29,24,24,19,19,14,14,9,9,4,45,53,53,54,54,55,55,56,56,57,57,58,58,59,59,49,49,60,60,61,61,62,62,52,52,63,63,64,64,65,65,66,66,67,67,68,68,69,69,47,47,70,70,71,71,72,72,45,50,94,94,95,95,96,96,97,97,98,98,99,99,100,100,46,46,101,101,102,102,103,103,48,48,104,104,105,105,106,106,107,107,108,108,109,109,110,110,51,51,111,111,112,112,113,113,50]
260 m1.insertNextCell(NORM_SEG2,2,c1seg[2*i:2*i+2])
262 m1.finishInsertingCells()
263 m1.setDescription("CREE PAR CODE_ASTER")
264 m0=MEDCouplingUMesh.New("ma",0)
269 m0.insertNextCell(NORM_POINT1,1,[c0pt[i]])
271 m0.finishInsertingCells()
272 f2=DataArrayInt.New()
277 f1=DataArrayInt.New()
293 f0=DataArrayInt.New()
294 f0.setValues([-4,-5,-6,-7],4,1)
298 p1=DataArrayInt.New()
301 p[[0,4,24,43,44,45,46,47,48,49,50,51,52]]=p1
302 n2=DataArrayInt.New()
305 n1=DataArrayInt.New()
308 n0=DataArrayInt.New()
311 fns=['A1A2____________________________', 'A1______________________________', 'A2A4____________________________', 'A2______________________________', 'A3A1____________________________', 'A3C5____________________________', 'A3______________________________', 'A4A3____________________________', 'A4______________________________', 'B1C1____________________________', 'B1______________________________', 'B2B4____________________________', 'B2______________________________', 'B3B1____________________________', 'B3______________________________', 'B4C3____________________________', 'B4______________________________', 'C1C4____________________________', 'C1______________________________', 'C2B2____________________________', 'C2______________________________', 'C3C2____________________________', 'C3______________________________', 'C4B3____________________________', 'C4______________________________', 'C5A4____________________________', 'C5______PMMA____________________', 'FAMILLE_ZERO', 'MESH____APPS____AP1_____________', 'MESH____APPS____AP2_____________', 'MESH____APPS____AP3_____________', 'MESH____APPS____AP4_____________', 'MESH____DALQ1___DALLE___________', 'MESH____DALQ2___DALLE___________', 'MESH____DALT3___DALLE___________']
312 fids=[-11, 5, -8, 1, -10, -12, 4, -9, 2, -14, 6, -19, 7, -17, 8, -20, 9, -15, 10, -18, 11, -21, 12, -16, 13, -13, 3, 0, -4, -5, -6, -7, -3, -2, -1]
313 grpns=['A1', 'A1A2', 'A2', 'A2A4', 'A3', 'A3A1', 'A3C5', 'A4', 'A4A3', 'AP1', 'AP2', 'AP3', 'AP4', 'APPS', 'B1', 'B1C1', 'B2', 'B2B4', 'B3', 'B3B1', 'B4', 'B4C3', 'C1', 'C1C4', 'C2', 'C2B2', 'C3', 'C3C2', 'C4', 'C4B3', 'C5', 'C5A4', 'DALLE', 'DALQ1', 'DALQ2', 'DALT3', 'MESH', 'PMMA']
314 famIdsPerGrp=[[5],[-11],[1],[-8],[4],[-10],[-12],[2],[-9],[-4],[-5],[-6],[-7],[-4,-5,-6,-7],[6],[-14],[7],[-19],[8],[-17],[9],[-20],[10],[-15],[11],[-18],[12],[-21],[13],[-16],[3],[-13],[-3,-2,-1],[-3],[-2],[-1],[-4,-5,-6,-7,-3,-2,-1],[3]]
315 return m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp
317 def buildMLMeshUnPolyze(cls,tester):
318 """Level 0 (meshDim=3) - 2 TETRA4 + 3 PENTA6 + 2 POLYH
319 # POLYH #0 becomes 1 TETRA4
320 # POLYH #1 becomes HEXA8
321 # Level -1 (meshDim=2) - 2 TRI3 + 3 QUAD4 + 4 POLYG
322 # POLYG #2 becomes TRI3"""
323 meshName="NightmareMesh"
325 coords=DataArrayDouble.New(38,3) ; coords.rearrange(1) ; coords.iota(1000.) ; coords.rearrange(3) ; coords.setInfoOnComponents(["X [m]","Y [m]","Z [m]"])
326 mesh0=MEDCouplingUMesh(meshName,3)
327 type0=[NORM_TETRA4,NORM_TETRA4, NORM_PENTA6,NORM_PENTA6,NORM_PENTA6, NORM_POLYHED,NORM_POLYHED]
328 conn0=[[0,1,2,3],[4,5,6,7], [8,9,10,11,12,13],[14,15,16,17,18,19],[20,21,22,23,24,25], [26,27,28,-1,26,29,27,-1,27,29,28,-1,28,29,26],[30,31,32,33,-1,34,37,36,35,-1,30,34,35,31,-1,31,35,36,32,-1,32,36,37,33,-1,33,37,34,30]]
329 mesh0.allocateCells(len(type0))
330 for typ,nodalConn in zip(type0,conn0):
331 mesh0.insertNextCell(typ,nodalConn);
333 mesh0.finishInsertingCells()
334 mesh0.setCoords(coords)
336 meshM1=MEDCouplingUMesh(meshName,2)
337 typeM1=[NORM_TRI3,NORM_TRI3, NORM_QUAD4,NORM_QUAD4,NORM_QUAD4, NORM_POLYGON,NORM_POLYGON,NORM_POLYGON,NORM_POLYGON]
338 connM1=[[0,1,2],[3,4,5], [6,7,8,9],[10,11,12,13],[14,15,16,17], [18,19,20,21,22],[23,24,25,26,27],[28,29,30],[31,32,33,34,35,36,37]]
339 meshM1.allocateCells(len(typeM1))
340 for typ,nodalConn in zip(typeM1,connM1):
341 meshM1.insertNextCell(typ,nodalConn);
343 meshM1.finishInsertingCells()
344 meshM1.setCoords(coords)
346 mm=MEDFileUMesh.New()
347 mm.setMeshAtLevel(0,mesh0)
348 mm.setMeshAtLevel(-1,meshM1)
349 grp0_L0=DataArrayInt.New([0,1,5,7]) ; grp0_L0.setName("grp0_L0")
350 grp1_L0=DataArrayInt.New([1,2,3,4,6]) ; grp1_L0.setName("grp1_L0")
351 tester.assertRaises(InterpKernelException,mm.setGroupsAtLevel,0,[grp0_L0,grp1_L0])# presence of 7 in grp0_L0 (only 7 cells at level 0) -> throw
352 grp0_L0=DataArrayInt.New([0,1,5,6]) ; grp0_L0.setName("grp0_L0")
353 mm.setGroupsAtLevel(0,[grp0_L0,grp1_L0])
354 grp0_LM1=DataArrayInt.New([1,2,3,4,7]) ; grp0_LM1.setName("grp0_LM1")
355 grp1_LM1=DataArrayInt.New([2,3,4,5]) ; grp1_LM1.setName("grp1_LM1")
356 grp2_LM1=DataArrayInt.New([5,6,7,8]) ; grp2_LM1.setName("grp2_LM1")
357 mm.setGroupsAtLevel(-1,[grp0_LM1,grp1_LM1,grp2_LM1])
358 grp0_Node=DataArrayInt.New([0,11,15,16]) ; grp0_Node.setName("grp0_Node")
359 grp1_Node=DataArrayInt.New([1,2,13,14,16]) ; grp1_Node.setName("grp1_Node")
360 mm.setGroupsAtLevel(1,[grp0_Node,grp1_Node])
362 tester.assertRaises(InterpKernelException,mm.setRenumFieldArr,0,DataArrayInt.New([0,8,9,4,5,6,7,10]))# to big array
363 mm.setRenumFieldArr(0,DataArrayInt.New([0,8,9,4,5,6,7]))
364 da=DataArrayInt.New([0,8,9,4,5,6,7,11,12])
365 mm.setRenumFieldArr(-1,da)
366 mm.setRenumFieldArr(-1,None)
367 mm.setRenumFieldArr(-1,da)
368 da=DataArrayInt.New(mm.getNumberOfNodes()+1) ; da.iota(8) ; tester.assertRaises(InterpKernelException,mm.setRenumFieldArr,1,da) # to big array more than number of nodes
369 da=DataArrayInt.New(mm.getNumberOfNodes()) ; da.iota(8) ; mm.setRenumFieldArr(1,da)
372 def buildVecFieldOnCells_1(cls):
373 mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
374 nbOfCells=mesh.getNumberOfCells();
375 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
376 f1.setName("VectorFieldOnCells");
378 array=DataArrayDouble.New();
379 arr1=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.]
380 array.setValues(arr1,nbOfCells,3);
381 array.setInfoOnComponent(0,"power [MW/m^3]");
382 array.setInfoOnComponent(1,"density [g/cm^3]");
383 array.setInfoOnComponent(2,"temperature [K]");
385 tmp=array.getPointer();
390 def buildVecFieldOnNodes_1(cls):
391 mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
392 nbOfNodes=mesh.getNumberOfNodes();
393 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
394 f1.setName("VectorFieldOnNodes");
396 array=DataArrayDouble.New();
398 arr1=[70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95.,
399 1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025.]
400 array.setValues(arr1,nbOfNodes,3);
401 array.setInfoOnComponent(0,"power [MW/m^3]");
402 array.setInfoOnComponent(1,"density [g/cm^3]");
403 array.setInfoOnComponent(2,"temperature [K]");
404 f1.setTime(2.12,2,3);
408 def buildVecFieldOnGauss_1(cls):
409 _a=0.446948490915965;
410 _b=0.091576213509771;
411 _p1=0.11169079483905;
412 _p2=0.0549758718227661;
413 refCoo1=[ 0.,0., 1.,0., 0.,1. ]
414 gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
415 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ];
416 wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
420 m=MEDLoaderDataForTest.build2DMesh_2();
421 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
424 f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
425 refCoo2=[-1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 ]
427 _gsCoo1=_gsCoo1[0:6];
431 refCoo3=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
433 _gsCoo1=_gsCoo1[0:4];
435 f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo3,_gsCoo1,_wg1);
436 f.setGaussLocalizationOnType(NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
437 array=DataArrayDouble.New();
439 ptr=array.getPointer();
440 for i in xrange(19*2):
441 array.setIJ(0,i,float(i+7));
444 f.setName("MyFirstFieldOnGaussPoint");
445 array.setInfoOnComponent(0,"power [MW/m^3]");
446 array.setInfoOnComponent(1,"density");
450 def buildVecFieldOnGauss_2(cls):
451 _a=0.446948490915965;
452 _b=0.091576213509771;
453 _p1=0.11169079483905;
454 _p2=0.0549758718227661;
455 refCoo1=[ 0.,0., 1.,0., 0.,1. ]
456 gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
457 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ];
458 wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
462 m=MEDLoaderDataForTest.build2DMesh_3();
463 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
466 di=DataArrayInt.New(); di.setValues([0,2,3],3,1)
467 f.setGaussLocalizationOnCells(di,_refCoo1,_gsCoo1,_wg1)
469 f.setGaussLocalizationOnCells([1,5],_refCoo1,_gsCoo1,_wg1);
471 f.setGaussLocalizationOnCells([4],_refCoo1,_gsCoo1,_wg1);
472 refCoo2=[-1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 ]
474 _gsCoo1=_gsCoo1[0:6];
478 refCoo3=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
480 _gsCoo1=_gsCoo1[0:4];
482 f.setGaussLocalizationOnCells([6,7,8],_refCoo3,_gsCoo1,_wg1);
484 f.setGaussLocalizationOnCells([9],_refCoo3,_gsCoo1,_wg1);
485 f.setGaussLocalizationOnType(NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
486 array=DataArrayDouble.New();
488 ptr=array.getPointer();
489 for i in xrange(53*2):
490 array.setIJ(0,i,float(i+7));
493 f.setName("MyFirstFieldOnGaussPoint");
494 array.setInfoOnComponent(0,"power [MW/m^3]");
495 array.setInfoOnComponent(1,"density");
499 # idem buildVecFieldOnGauss_2 except that different discretizations are sorted inside one type
500 def buildVecFieldOnGauss_2_Simpler(cls):
501 _a=0.446948490915965;
502 _b=0.091576213509771;
503 _p1=0.11169079483905;
504 _p2=0.0549758718227661;
505 refCoo1=[ 0.,0., 1.,0., 0.,1. ]
506 gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
507 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ];
508 wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
512 m=MEDLoaderDataForTest.build2DMesh_3();
513 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
516 di=DataArrayInt.New(); di.setValues([0,1,2],3,1)
517 f.setGaussLocalizationOnCells(di,_refCoo1,_gsCoo1,_wg1)
519 f.setGaussLocalizationOnCells([3,4],_refCoo1,_gsCoo1,_wg1);
521 f.setGaussLocalizationOnCells([5],_refCoo1,_gsCoo1,_wg1);
522 refCoo2=[-1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 ]
524 _gsCoo1=_gsCoo1[0:6];
528 refCoo3=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
530 _gsCoo1=_gsCoo1[0:4];
532 f.setGaussLocalizationOnCells([6,7,8],_refCoo3,_gsCoo1,_wg1);
534 f.setGaussLocalizationOnCells([9],_refCoo3,_gsCoo1,_wg1);
535 f.setGaussLocalizationOnType(NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
536 array=DataArrayDouble.New();
538 ptr=array.getPointer();
539 for i in xrange(53*2):
540 array.setIJ(0,i,float(i+7));
543 f.setName("MyFirstFieldOnGaussPoint");
544 array.setInfoOnComponent(0,"power [MW/m^3]");
545 array.setInfoOnComponent(1,"density");
549 def buildVecFieldOnGaussNE_1(cls):
550 m=MEDLoaderDataForTest.build2DMesh_2();
551 f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME);
554 array=DataArrayDouble.New();
556 for i in xrange(2*20):
557 array.setIJ(0,i,float(i+8));
559 array.setInfoOnComponent(0,"power [W]");
560 array.setInfoOnComponent(1,"temperature");
561 f.setName("MyFieldOnGaussNE");
565 def buildACompleteMEDDataStructureWithFieldsOnCells_1(cls):
566 coo=DataArrayDouble([0,0,1,0,2,0,0,1,1,1,2,1,0,2,1,2,2,2],9,2)
567 m0=MEDCouplingUMesh("mesh",2)
570 m0.insertNextCell(NORM_TRI3,[1,4,2])
571 m0.insertNextCell(NORM_TRI3,[4,5,2])
572 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
573 m0.insertNextCell(NORM_QUAD4,[6,7,4,3])
574 m0.insertNextCell(NORM_QUAD4,[7,8,5,4])
578 mm.setMeshAtLevel(0,m0) ; mm.setMeshAtLevel(-1,m1)
579 #some grps/families on the 2 levels
580 grp0=DataArrayInt([0,2,4]); grp0.setName("gr0_0_2_4")
581 grp1=DataArrayInt([1,2,3,4]); grp1.setName("gr0_1_2_3_4")
582 grp2=DataArrayInt([0,4]); grp2.setName("gr0_0_4")
583 mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
584 grp3=DataArrayInt([0,1]); grp3.setName("grM1_SegOnTri3")
585 grp4=DataArrayInt([2,3,4,5,6,7]); grp4.setName("grM1_SegOnQuad4")
586 grp5=DataArrayInt([0,3]); grp5.setName("grM1_bottom")
587 mm.setGroupsAtLevel(-1,[grp3,grp4,grp5])
592 # 1st Field - fNoProfile - no profile on levels 0
594 timeStepsF1=[(0,-1,0.01),(1,-1,0.02)]
595 f1=MEDFileFieldMultiTS()
596 for i,(it,order,tim) in enumerate(timeStepsF1):
597 f11Tmp=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
598 f11Tmp.setTime(tim,it,order)
600 arr=DataArrayDouble(m0.getNumberOfCells(),1) ; arr.iota() ; arr+=1+i ; arr*=0.1
602 f11Tmp.checkCoherency()
603 f11Tmp.setName(f1Name)
604 f1.appendFieldNoProfileSBT(f11Tmp)
607 # 2nd Field - fNoProfileMultiLevs - no profile on levels 0 and -1
608 f2Name="fNoProfileMultiLevs"
609 timeStepsF2=[(0,-1,0.),(1,-1,0.1),(2,-1,0.2)]
610 f2=MEDFileFieldMultiTS()
611 for i,(it,order,tim) in enumerate(timeStepsF2):
612 f21Tmp=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
613 f21Tmp.setTime(tim,it,order)
615 arr=DataArrayDouble(m0.getNumberOfCells(),1) ; arr.iota() ; arr+=1+i
617 f21Tmp.checkCoherency()
618 f21Tmp.setName(f2Name)
619 f2.appendFieldNoProfileSBT(f21Tmp)
620 f22Tmp=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
621 f22Tmp.setTime(tim,it,order)
623 arr=DataArrayDouble(m1.getNumberOfCells(),1) ; arr.iota() ; arr+=100+1+i
625 f22Tmp.checkCoherency()
626 f22Tmp.setName(f2Name)
627 f2[it,order].setFieldNoProfileSBT(f22Tmp)
630 # 3rd field - fProfileMultiLevs - The most complex one
631 f3Name="fProfileMultiLevs"
632 timeStepsF3=[(0,-1,0.),(1,-1,10.),(2,-1,20.),(3,-1,30.),]
633 f3=MEDFileFieldMultiTS()
634 for i,(it,order,tim) in enumerate(timeStepsF3):
635 pfl1=DataArrayInt([0,1,3,4]) ; pfl1.setName("pfl1")
637 f31Tmp=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
638 f31Tmp.setTime(tim,it,order)
639 f31Tmp.setMesh(m0Part)
640 arr=DataArrayDouble(m0Part.getNumberOfCells(),1) ; arr.iota() ; arr+=1000+i+1
642 f31Tmp.checkCoherency()
643 f31Tmp.setName(f3Name)
644 f3.appendFieldProfile(f31Tmp,mm,0,pfl1)
645 pfl2=DataArrayInt([0,3]) ; pfl2.setName("pfl2Bottom")
647 f32Tmp=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
648 f32Tmp.setTime(tim,it,order)
649 f32Tmp.setMesh(m1Part)
650 arr=DataArrayDouble(m1Part.getNumberOfCells(),1) ; arr.iota() ; arr+=2000+1+i
652 f32Tmp.checkCoherency()
653 f32Tmp.setName(f3Name)
654 f3[it,order].setFieldProfile(f32Tmp,mm,-1,pfl2)
658 data=MEDFileData() ; data.setMeshes(ms) ; data.setFields(fs)
661 def buildAMEDFileDataWithGroupOnOneFamilyForSauv(self):
663 coords = [0.,0., 0.,1., 1.,1., 1.,0.]
666 # lvl -1 connectivity
667 conn1D = [0,1, 1,2, 2,3, 4,1]
669 mesh2D=MEDCouplingUMesh.New()
670 mesh2D.setMeshDimension(2)
671 mesh2D.allocateCells(1)
672 mesh2D.insertNextCell(NORM_QUAD4,4,conn2D)
673 mesh2D.finishInsertingCells()
675 mesh1D=MEDCouplingUMesh.New()
676 mesh1D.setMeshDimension(1)
677 mesh1D.allocateCells(4)
678 mesh1D.insertNextCell(NORM_SEG2,2,conn1D[0:2])
679 mesh1D.insertNextCell(NORM_SEG2,2,conn1D[2:4])
680 mesh1D.insertNextCell(NORM_SEG2,2,conn1D[4:6])
681 mesh1D.insertNextCell(NORM_SEG2,2,conn1D[6:8])
682 mesh1D.finishInsertingCells()
683 # assigning coordinates
684 meshCoords=DataArrayDouble.New()
685 meshCoords.setValues(coords, 4, 2)
686 mesh2D.setCoords(meshCoords)
687 mesh1D.setCoords(meshCoords)
688 # Creating a multi level mesh
689 mm = MEDFileUMesh.New()
690 mm.setMeshAtLevel(0, mesh2D)
691 mm.setMeshAtLevel(-1, mesh1D)
694 # Creating a group with an element on level -1
695 grp0_LM1 = DataArrayInt.New([0])
696 grp0_LM1.setName("grp0_LM1")
697 # Creating a group with all elements on level -1
698 grp1_LM1 = DataArrayInt.New([0,1,2,3])
699 grp1_LM1.setName("grp1_LM1")
701 mm.setGroupsAtLevel(-1,[grp0_LM1,grp1_LM1])
703 ms=MEDFileMeshes.New()
704 ms.setMeshAtPos(0,mm)
705 mfd=MEDFileData.New()
710 build1DMesh_1=classmethod(build1DMesh_1)
711 build2DCurveMesh_1=classmethod(build2DCurveMesh_1)
712 build2DMesh_1=classmethod(build2DMesh_1)
713 build2DMesh_2=classmethod(build2DMesh_2)
714 build2DMesh_3=classmethod(build2DMesh_3)
715 build3DMesh_1=classmethod(build3DMesh_1)
716 build3DSurfMesh_1=classmethod(build3DSurfMesh_1)
717 build3DMesh_2=classmethod(build3DMesh_2)
718 buildMLMeshUnPolyze=classmethod(buildMLMeshUnPolyze)
719 buildMultiLevelMesh_1=classmethod(buildMultiLevelMesh_1)
720 buildVecFieldOnCells_1=classmethod(buildVecFieldOnCells_1)
721 buildVecFieldOnNodes_1=classmethod(buildVecFieldOnNodes_1)
722 buildVecFieldOnGauss_1=classmethod(buildVecFieldOnGauss_1)
723 buildVecFieldOnGauss_2=classmethod(buildVecFieldOnGauss_2)
724 buildVecFieldOnGauss_2_Simpler=classmethod(buildVecFieldOnGauss_2_Simpler)
725 buildVecFieldOnGaussNE_1=classmethod(buildVecFieldOnGaussNE_1)
726 buildACompleteMEDDataStructureWithFieldsOnCells_1=classmethod(buildACompleteMEDDataStructureWithFieldsOnCells_1)
727 buildAMEDFileDataWithGroupOnOneFamilyForSauv=classmethod(buildAMEDFileDataWithGroupOnOneFamilyForSauv)