1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 ############################################################################
25 # This Python script is testing the generation of MED field using a
26 # user-callable function with different number of components and
28 ############################################################################
32 def f_scal_dbl_2d(x, y):
37 def f_scal_dbl_3d(x, y, z):
42 def f_vect_dbl_2d(x, y):
45 ret.append(2.*(x + y))
48 def f_vect_dbl_3d(x, y, z):
51 ret.append(2.*(x + y + z))
52 ret.append(3.*(x + y + z))
55 def f_scal_int_2d(x, y):
58 ret_tmp = int(ret_tmp)
62 def f_scal_int_3d(x, y, z):
65 ret_tmp = int(ret_tmp)
69 def f_vect_int_2d(x, y):
71 ret.append(int(x + y))
72 ret.append(int(2.*(x + y)))
75 def f_vect_int_3d(x, y, z):
77 ret.append(int(x + y + z))
78 ret.append(int(2.*(x + y + z)))
79 ret.append(int(3.*(x + y + z)))
82 from libMEDMEM_Swig import *
86 #befor running this script, please be sure about the path the file fileName
88 filePath=os.environ["MED_ROOT_DIR"]
89 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
91 medFile = os.path.join(filePath, "carre_en_quad4_seg2.med")
92 medFile = os.path.join(filePath, "cube_hexa8_quad4.med")
104 md = MEDFILEBROWSER(medFile)
105 nbMeshes = md.getNumberOfMeshes()
107 print "The med file", medFile, "contains", nbMeshes, "mesh(es)"
109 mesh_name = md.getMeshName(0)
110 mesh = MESH(MED_DRIVER,medFile,mesh_name)
111 spaceDim = mesh.getSpaceDimension()
112 meshDim = mesh.getMeshDimension()
113 nbNodes = mesh.getNumberOfNodes()
116 print "The mesh",mesh_name,"is a",spaceDim,"D mesh on a",meshDim,"D geometry and has",nbNodes,"Nodes"
118 supportOnCell = mesh.getSupportOnAll(MED_CELL)
120 supportOnNode = mesh.getSupportOnAll(MED_NODE)
123 supportOnConst = mesh.getSupportOnAll(MED_FACE)
124 elif (spaceDim == 2) :
125 supportOnConst = mesh.getSupportOnAll(MED_EDGE)
128 ##print supportOnCell
131 fieldDoubleScalOnCell = createFieldDoubleFromAnalytic(supportOnCell,1,
133 fieldDoubleVectOnCell = createFieldDoubleFromAnalytic(supportOnCell,
136 fieldIntScalOnCell = createFieldIntFromAnalytic(supportOnCell,1,
138 fieldIntVectOnCell = createFieldIntFromAnalytic(supportOnCell,spaceDim,
140 elif (spaceDim == 3) :
141 fieldDoubleScalOnCell = createFieldDoubleFromAnalytic(supportOnCell,1,
143 fieldDoubleVectOnCell = createFieldDoubleFromAnalytic(supportOnCell,
146 fieldIntScalOnCell = createFieldIntFromAnalytic(supportOnCell,1,
148 fieldIntVectOnCell = createFieldIntFromAnalytic(supportOnCell,spaceDim,
151 fieldDoubleScalOnCell.setName("Scalar Double Field on all Cells")
152 fieldDoubleScalOnCell.setDescription("Generated via a Python function")
154 fieldDoubleVectOnCell.setName("Vector Double Field on all Cells")
155 fieldDoubleVectOnCell.setDescription("Generated via a Python function")
157 fieldIntScalOnCell.setName("Scalar Integer Field on all Cells")
158 fieldIntScalOnCell.setDescription("Generated via a Python function")
160 fieldIntVectOnCell.setName("Vector Integer Field on all Cells")
161 fieldIntVectOnCell.setDescription("Generated via a Python function")
163 name = fieldDoubleScalOnCell.getName()
164 desc = fieldDoubleScalOnCell.getDescription()
165 nbOfComp = fieldDoubleScalOnCell.getNumberOfComponents()
166 print " Field",name," : ",desc
167 print " Number Of Components:",nbOfComp
168 iterationNb = fieldDoubleScalOnCell.getIterationNumber()
169 orderNb = fieldDoubleScalOnCell.getOrderNumber()
170 time = fieldDoubleScalOnCell.getTime()
171 print " Iteration Number",iterationNb
172 print " Order Number",orderNb
174 for k in range(nbOfComp):
176 compName = fieldDoubleScalOnCell.getComponentName(kp1)
177 compDesc = fieldDoubleScalOnCell.getComponentDescription(kp1)
178 compUnit = fieldDoubleScalOnCell.getMEDComponentUnit(kp1)
179 print " * Component:",kp1
180 print " Name:",compName
181 print " Description:",compDesc
182 print " Unit:",compUnit
184 support = fieldDoubleScalOnCell.getSupport()
185 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
186 print " Values:",nbOf
187 for k in range(nbOf):
188 valueI = fieldDoubleScalOnCell.getRow(k+1)
189 print " *",valueI[:nbOfComp]
192 name = fieldDoubleVectOnCell.getName()
193 desc = fieldDoubleVectOnCell.getDescription()
194 nbOfComp = fieldDoubleVectOnCell.getNumberOfComponents()
195 print " Field",name," : ",desc
196 print " Number Of Components:",nbOfComp
197 iterationNb = fieldDoubleVectOnCell.getIterationNumber()
198 orderNb = fieldDoubleVectOnCell.getOrderNumber()
199 time = fieldDoubleVectOnCell.getTime()
200 print " Iteration Number",iterationNb
201 print " Order Number",orderNb
203 for k in range(nbOfComp):
205 compName = fieldDoubleVectOnCell.getComponentName(kp1)
206 compDesc = fieldDoubleVectOnCell.getComponentDescription(kp1)
207 compUnit = fieldDoubleVectOnCell.getMEDComponentUnit(kp1)
208 print " * Component:",kp1
209 print " Name:",compName
210 print " Description:",compDesc
211 print " Unit:",compUnit
213 support = fieldDoubleVectOnCell.getSupport()
214 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
215 print " Values:",nbOf
216 for k in range(nbOf):
217 valueI = fieldDoubleVectOnCell.getRow(k+1)
218 print " *",valueI[:nbOfComp]
221 name = fieldIntScalOnCell.getName()
222 desc = fieldIntScalOnCell.getDescription()
223 nbOfComp = fieldIntScalOnCell.getNumberOfComponents()
224 print " Field",name," : ",desc
225 print " Number Of Components:",nbOfComp
226 iterationNb = fieldIntScalOnCell.getIterationNumber()
227 orderNb = fieldIntScalOnCell.getOrderNumber()
228 time = fieldIntScalOnCell.getTime()
229 print " Iteration Number",iterationNb
230 print " Order Number",orderNb
232 for k in range(nbOfComp):
234 compName = fieldIntScalOnCell.getComponentName(kp1)
235 compDesc = fieldIntScalOnCell.getComponentDescription(kp1)
236 compUnit = fieldIntScalOnCell.getMEDComponentUnit(kp1)
237 print " * Component:",kp1
238 print " Name:",compName
239 print " Description:",compDesc
240 print " Unit:",compUnit
242 support = fieldIntScalOnCell.getSupport()
243 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
244 print " Values:",nbOf
245 for k in range(nbOf):
246 valueI = fieldIntScalOnCell.getRow(k+1)
247 print " *",valueI[:nbOfComp]
250 name = fieldIntVectOnCell.getName()
251 desc = fieldIntVectOnCell.getDescription()
252 nbOfComp = fieldIntVectOnCell.getNumberOfComponents()
253 print " Field",name," : ",desc
254 print " Number Of Components:",nbOfComp
255 iterationNb = fieldIntVectOnCell.getIterationNumber()
256 orderNb = fieldIntVectOnCell.getOrderNumber()
257 time = fieldIntVectOnCell.getTime()
258 print " Iteration Number",iterationNb
259 print " Order Number",orderNb
261 for k in range(nbOfComp):
263 compName = fieldIntVectOnCell.getComponentName(kp1)
264 compDesc = fieldIntVectOnCell.getComponentDescription(kp1)
265 compUnit = fieldIntVectOnCell.getMEDComponentUnit(kp1)
266 print " * Component:",kp1
267 print " Name:",compName
268 print " Description:",compDesc
269 print " Unit:",compUnit
271 support = fieldIntVectOnCell.getSupport()
272 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
273 print " Values:",nbOf
274 for k in range(nbOf):
275 valueI = fieldIntVectOnCell.getRow(k+1)
276 print " *",valueI[:nbOfComp]
279 ##print supportOnNode
282 fieldDoubleScalOnNode = createFieldDoubleFromAnalytic(supportOnNode,1,
284 fieldDoubleVectOnNode = createFieldDoubleFromAnalytic(supportOnNode,
287 fieldIntScalOnNode = createFieldIntFromAnalytic(supportOnNode,1,
289 fieldIntVectOnNode = createFieldIntFromAnalytic(supportOnNode, spaceDim,
291 elif (spaceDim == 3) :
292 fieldDoubleScalOnNode = createFieldDoubleFromAnalytic(supportOnNode,1,
294 fieldDoubleVectOnNode = createFieldDoubleFromAnalytic(supportOnNode,
297 fieldIntScalOnNode = createFieldIntFromAnalytic(supportOnNode,1,
299 fieldIntVectOnNode = createFieldIntFromAnalytic(supportOnNode, spaceDim,
302 fieldDoubleScalOnNode.setName("Scalar Double Field on all Nodes")
303 fieldDoubleScalOnNode.setDescription("Generated via a Python function")
305 fieldDoubleVectOnNode.setName("Vector Double Field on all Nodes")
306 fieldDoubleVectOnNode.setDescription("Generated via a Python function")
308 fieldIntScalOnNode.setName("Scalar Integer Field on all Nodes")
309 fieldIntScalOnNode.setDescription("Generated via a Python function")
311 fieldIntVectOnNode.setName("Vector Integer Field on all Nodes")
312 fieldIntVectOnNode.setDescription("Generated via a Python function")
315 name = fieldDoubleScalOnNode.getName()
316 desc = fieldDoubleScalOnNode.getDescription()
317 nbOfComp = fieldDoubleScalOnNode.getNumberOfComponents()
318 print " Field",name," : ",desc
319 print " Number Of Components:",nbOfComp
320 iterationNb = fieldDoubleScalOnNode.getIterationNumber()
321 orderNb = fieldDoubleScalOnNode.getOrderNumber()
322 time = fieldDoubleScalOnNode.getTime()
323 print " Iteration Number",iterationNb
324 print " Order Number",orderNb
326 for k in range(nbOfComp):
328 compName = fieldDoubleScalOnNode.getComponentName(kp1)
329 compDesc = fieldDoubleScalOnNode.getComponentDescription(kp1)
330 compUnit = fieldDoubleScalOnNode.getMEDComponentUnit(kp1)
331 print " * Component:",kp1
332 print " Name:",compName
333 print " Description:",compDesc
334 print " Unit:",compUnit
336 support = fieldDoubleScalOnNode.getSupport()
337 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
338 print " Values:",nbOf
339 for k in range(nbOf):
340 valueI = fieldDoubleScalOnNode.getRow(k+1)
341 print " *",valueI[:nbOfComp]
344 name = fieldDoubleVectOnNode.getName()
345 desc = fieldDoubleVectOnNode.getDescription()
346 nbOfComp = fieldDoubleVectOnNode.getNumberOfComponents()
347 print " Field",name," : ",desc
348 print " Number Of Components:",nbOfComp
349 iterationNb = fieldDoubleVectOnNode.getIterationNumber()
350 orderNb = fieldDoubleVectOnNode.getOrderNumber()
351 time = fieldDoubleVectOnNode.getTime()
352 print " Iteration Number",iterationNb
353 print " Order Number",orderNb
355 for k in range(nbOfComp):
357 compName = fieldDoubleVectOnNode.getComponentName(kp1)
358 compDesc = fieldDoubleVectOnNode.getComponentDescription(kp1)
359 compUnit = fieldDoubleVectOnNode.getMEDComponentUnit(kp1)
360 print " * Component:",kp1
361 print " Name:",compName
362 print " Description:",compDesc
363 print " Unit:",compUnit
365 support = fieldDoubleVectOnNode.getSupport()
366 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
367 print " Values:",nbOf
368 for k in range(nbOf):
369 valueI = fieldDoubleVectOnNode.getRow(k+1)
370 print " *",valueI[:nbOfComp]
373 name = fieldIntScalOnNode.getName()
374 desc = fieldIntScalOnNode.getDescription()
375 nbOfComp = fieldIntScalOnNode.getNumberOfComponents()
376 print " Field",name," : ",desc
377 print " Number Of Components:",nbOfComp
378 iterationNb = fieldIntScalOnNode.getIterationNumber()
379 orderNb = fieldIntScalOnNode.getOrderNumber()
380 time = fieldIntScalOnNode.getTime()
381 print " Iteration Number",iterationNb
382 print " Order Number",orderNb
384 for k in range(nbOfComp):
386 compName = fieldIntScalOnNode.getComponentName(kp1)
387 compDesc = fieldIntScalOnNode.getComponentDescription(kp1)
388 compUnit = fieldIntScalOnNode.getMEDComponentUnit(kp1)
389 print " * Component:",kp1
390 print " Name:",compName
391 print " Description:",compDesc
392 print " Unit:",compUnit
394 support = fieldIntScalOnNode.getSupport()
395 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
396 print " Values:",nbOf
397 for k in range(nbOf):
398 valueI = fieldIntScalOnNode.getRow(k+1)
399 print " *",valueI[:nbOfComp]
402 name = fieldIntVectOnNode.getName()
403 desc = fieldIntVectOnNode.getDescription()
404 nbOfComp = fieldIntVectOnNode.getNumberOfComponents()
405 print " Field",name," : ",desc
406 print " Number Of Components:",nbOfComp
407 iterationNb = fieldIntVectOnNode.getIterationNumber()
408 orderNb = fieldIntVectOnNode.getOrderNumber()
409 time = fieldIntVectOnNode.getTime()
410 print " Iteration Number",iterationNb
411 print " Order Number",orderNb
413 for k in range(nbOfComp):
415 compName = fieldIntVectOnNode.getComponentName(kp1)
416 compDesc = fieldIntVectOnNode.getComponentDescription(kp1)
417 compUnit = fieldIntVectOnNode.getMEDComponentUnit(kp1)
418 print " * Component:",kp1
419 print " Name:",compName
420 print " Description:",compDesc
421 print " Unit:",compUnit
423 support = fieldIntVectOnNode.getSupport()
424 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
425 print " Values:",nbOf
426 for k in range(nbOf):
427 valueI = fieldIntVectOnNode.getRow(k+1)
428 print " *",valueI[:nbOfComp]
431 ##print supportOnConst
434 fieldDoubleScalOnConst = createFieldDoubleFromAnalytic(supportOnConst,1,
436 fieldDoubleVectOnConst = createFieldDoubleFromAnalytic(supportOnConst,
439 fieldIntScalOnConst = createFieldIntFromAnalytic(supportOnConst,1,
441 fieldIntVectOnConst = createFieldIntFromAnalytic(supportOnConst, spaceDim,
443 elif (spaceDim == 3) :
444 fieldDoubleScalOnConst = createFieldDoubleFromAnalytic(supportOnConst,1,
446 fieldDoubleVectOnConst = createFieldDoubleFromAnalytic(supportOnConst,
449 fieldIntScalOnConst = createFieldIntFromAnalytic(supportOnConst,1,
451 fieldIntVectOnConst = createFieldIntFromAnalytic(supportOnConst, spaceDim,
454 fieldDoubleScalOnConst.setName("Scalar Double Field on all Faces/Edges")
455 fieldDoubleScalOnConst.setDescription("Generated via a Python function")
457 fieldDoubleVectOnConst.setName("Vector Double Field on all Faces/Edges")
458 fieldDoubleVectOnConst.setDescription("Generated via a Python function")
460 fieldIntScalOnConst.setName("Scalar Integer Field on all Faces/Edges")
461 fieldIntScalOnConst.setDescription("Generated via a Python function")
463 fieldIntVectOnConst.setName("Vector Integer Field on all Faces/Edges")
464 fieldIntVectOnConst.setDescription("Generated via a Python function")
467 name = fieldDoubleScalOnConst.getName()
468 desc = fieldDoubleScalOnConst.getDescription()
469 nbOfComp = fieldDoubleScalOnConst.getNumberOfComponents()
470 print " Field",name," : ",desc
471 print " Number Of Components:",nbOfComp
472 iterationNb = fieldDoubleScalOnConst.getIterationNumber()
473 orderNb = fieldDoubleScalOnConst.getOrderNumber()
474 time = fieldDoubleScalOnConst.getTime()
475 print " Iteration Number",iterationNb
476 print " Order Number",orderNb
478 for k in range(nbOfComp):
480 compName = fieldDoubleScalOnConst.getComponentName(kp1)
481 compDesc = fieldDoubleScalOnConst.getComponentDescription(kp1)
482 compUnit = fieldDoubleScalOnConst.getMEDComponentUnit(kp1)
483 print " * Component:",kp1
484 print " Name:",compName
485 print " Description:",compDesc
486 print " Unit:",compUnit
488 support = fieldDoubleScalOnConst.getSupport()
489 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
490 print " Values:",nbOf
491 for k in range(nbOf):
492 valueI = fieldDoubleScalOnConst.getRow(k+1)
493 print " *",valueI[:nbOfComp]
496 name = fieldDoubleVectOnConst.getName()
497 desc = fieldDoubleVectOnConst.getDescription()
498 nbOfComp = fieldDoubleVectOnConst.getNumberOfComponents()
499 print " Field",name," : ",desc
500 print " Number Of Components:",nbOfComp
501 iterationNb = fieldDoubleVectOnConst.getIterationNumber()
502 orderNb = fieldDoubleVectOnConst.getOrderNumber()
503 time = fieldDoubleVectOnConst.getTime()
504 print " Iteration Number",iterationNb
505 print " Order Number",orderNb
507 for k in range(nbOfComp):
509 compName = fieldDoubleVectOnConst.getComponentName(kp1)
510 compDesc = fieldDoubleVectOnConst.getComponentDescription(kp1)
511 compUnit = fieldDoubleVectOnConst.getMEDComponentUnit(kp1)
512 print " * Component:",kp1
513 print " Name:",compName
514 print " Description:",compDesc
515 print " Unit:",compUnit
517 support = fieldDoubleVectOnConst.getSupport()
518 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
519 print " Values:",nbOf
520 for k in range(nbOf):
521 valueI = fieldDoubleVectOnConst.getRow(k+1)
522 print " *",valueI[:nbOfComp]
525 name = fieldIntScalOnConst.getName()
526 desc = fieldIntScalOnConst.getDescription()
527 nbOfComp = fieldIntScalOnConst.getNumberOfComponents()
528 print " Field",name," : ",desc
529 print " Number Of Components:",nbOfComp
530 iterationNb = fieldIntScalOnConst.getIterationNumber()
531 orderNb = fieldIntScalOnConst.getOrderNumber()
532 time = fieldIntScalOnConst.getTime()
533 print " Iteration Number",iterationNb
534 print " Order Number",orderNb
536 for k in range(nbOfComp):
538 compName = fieldIntScalOnConst.getComponentName(kp1)
539 compDesc = fieldIntScalOnConst.getComponentDescription(kp1)
540 compUnit = fieldIntScalOnConst.getMEDComponentUnit(kp1)
541 print " * Component:",kp1
542 print " Name:",compName
543 print " Description:",compDesc
544 print " Unit:",compUnit
546 support = fieldIntScalOnConst.getSupport()
547 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
548 print " Values:",nbOf
549 for k in range(nbOf):
550 valueI = fieldIntScalOnConst.getRow(k+1)
551 print " *",valueI[:nbOfComp]
554 name = fieldIntVectOnConst.getName()
555 desc = fieldIntVectOnConst.getDescription()
556 nbOfComp = fieldIntVectOnConst.getNumberOfComponents()
557 print " Field",name," : ",desc
558 print " Number Of Components:",nbOfComp
559 iterationNb = fieldIntVectOnConst.getIterationNumber()
560 orderNb = fieldIntVectOnConst.getOrderNumber()
561 time = fieldIntVectOnConst.getTime()
562 print " Iteration Number",iterationNb
563 print " Order Number",orderNb
565 for k in range(nbOfComp):
567 compName = fieldIntVectOnConst.getComponentName(kp1)
568 compDesc = fieldIntVectOnConst.getComponentDescription(kp1)
569 compUnit = fieldIntVectOnConst.getMEDComponentUnit(kp1)
570 print " * Component:",kp1
571 print " Name:",compName
572 print " Description:",compDesc
573 print " Unit:",compUnit
575 support = fieldIntVectOnConst.getSupport()
576 nbOf = support.getNumberOfElements(MED_ALL_ELEMENTS)
577 print " Values:",nbOf
578 for k in range(nbOf):
579 valueI = fieldIntVectOnConst.getRow(k+1)
580 print " *",valueI[:nbOfComp]
583 print "END of the Pyhton script ..... Ctrl D to exit"