Back to index

salome-med  6.5.0
Public Member Functions
medNumPy_test.medNumPyTest Class Reference

List of all members.

Public Member Functions

def test0
def setUp

Detailed Description

Definition at line 29 of file medNumPy_test.py.


Member Function Documentation

Definition at line 183 of file medNumPy_test.py.

00183 
00184     def setUp(self):
00185         pass
00186 
00187 unittest.main()

Definition at line 30 of file medNumPy_test.py.

00030 
00031     def test0(self):
00032 
00033         try:
00034             from numpy import array, arange, ndarray
00035         except:
00036             # numpy is not available, it is not an error
00037             print "numpy unavailable"
00038             return
00039 
00040         myMeshing = MESHING()
00041         myMeshing.setName("meshing")
00042 
00043         spaceDimension = 3
00044         numberOfNodes = 19
00045         coordinates = [0.0, 0.0, 0.0  ,
00046                        0.0, 0.0, 1.0  ,
00047                        2.0, 0.0, 1.0  ,
00048                        0.0, 2.0, 1.0  ,
00049                        -2.0, 0.0, 1.0 ,
00050                        0.0, -2.0, 1.0 ,
00051                        1.0, 1.0, 2.0  ,
00052                        -1.0, 1.0, 2.0 ,
00053                        -1.0, -1.0, 2.0,
00054                        1.0, -1.0, 2.0 ,
00055                        1.0, 1.0, 3.0  ,
00056                        -1.0, 1.0, 3.0 ,
00057                        -1.0, -1.0, 3.0,
00058                        1.0, -1.0, 3.0 ,
00059                        1.0, 1.0, 4.0  ,
00060                        -1.0, 1.0, 4.0 ,
00061                        -1.0, -1.0, 4.0,
00062                        1.0, -1.0, 4.0 ,
00063                        0.0, 0.0, 5.0  ]
00064 
00065         myMeshing.setCoordinates(spaceDimension,numberOfNodes, array( coordinates ),
00066                                  "CARTESIAN",MED_FULL_INTERLACE)
00067         coord = myMeshing.getCoordinates(MED_FULL_INTERLACE)
00068         self.assertTrue( isinstance( coord, ndarray ))
00069         
00070         units = ["cm      ", "cm      ", "cm      "]
00071         names = ["X       ", "Y       ", "Z       "]
00072         myMeshing.setCoordinatesNames(names)
00073         myMeshing.setCoordinatesUnits(units)
00074 
00075         # definition of connectivities
00076 
00077         numberOfTypes = 1
00078         entity = MED_CELL
00079 
00080         types = [MED_TETRA4]
00081         numberOfElements = [12]
00082 
00083         myMeshing.setNumberOfTypes(numberOfTypes,entity)
00084         myMeshing.setTypes(types,entity)
00085         myMeshing.setNumberOfElements(numberOfElements,entity)
00086 
00087         connectivityTetra =  [1,2,3,6,
00088                               1,2,4,3 ,
00089                               1,2,5,4 ,
00090                               1,2,6,5 ,
00091                               2,7,4,3 ,
00092                               2,8,5,4 ,
00093                               2,9,6,5 ,
00094                               2,10,3,6,
00095                               2,7,3,10,
00096                               2,8,4,7 ,
00097                               2,9,5,8 ,
00098                               2,10,6,9]
00099 
00100         myMeshing.setConnectivity(entity,types[0], array( connectivityTetra ))
00101         conn = myMeshing.getConnectivity(MED_NODAL,entity,MED_ALL_ELEMENTS)
00102         self.assertTrue( isinstance( conn, ndarray ))
00103 
00104         myGroup = GROUP()
00105         myGroup.setName("SomeCells")
00106         myGroup.setMesh(myMeshing)
00107         myGroup.setEntity(MED_CELL)
00108         myGroup.setNumberOfGeometricType(1)
00109 
00110         myGroup.setGeometricType(types)
00111         myNumberOfElements = [4,1,2]
00112         myGroup.setNumberOfElements(myNumberOfElements)
00113 
00114         index = [1,5,6,8]
00115         values = [2,7,8,12,13,15,16]
00116         myGroup.setNumber( array( index ), array( values ))
00117 
00118         myMeshing.addGroup(myGroup)
00119 
00120         # saving the generated mesh in MED
00121 
00122         import os
00123         tmpDir  = os.getenv("TMP")
00124         if not tmpDir:
00125             tmpDir = os.getenv("TMPDIR", "/tmp")
00126 
00127         filename = os.path.join(tmpDir,"medNumPy_test.med")
00128         myMeshing.write(MED_DRIVER,filename)
00129 
00130         # we build now 2 fields
00131 
00132         supportOnNodes = SUPPORT(myMeshing,"On_All_Nodes",MED_NODE)
00133         numberOfNodes = supportOnNodes.getNumberOfElements(MED_ALL_ELEMENTS)
00134 
00135         fieldDoubleScalarOnNodes = FIELDDOUBLE(supportOnNodes,1)
00136         fieldDoubleScalarOnNodes.setName("fieldScalarDoubleNode")
00137         fieldDoubleScalarOnNodes.setIterationNumber(-1)
00138         fieldDoubleScalarOnNodes.setOrderNumber(-1)
00139         fieldDoubleScalarOnNodes.setTime(0.0)
00140 
00141         fieldDoubleScalarOnNodes.setComponentName(1,"Vx")
00142         fieldDoubleScalarOnNodes.setComponentDescription(1,"comp1")
00143         fieldDoubleScalarOnNodes.setMEDComponentUnit(1,"unit1")
00144 
00145         nodeValues = arange( numberOfNodes, dtype=float )
00146         fieldDoubleScalarOnNodes.setValue( nodeValues )
00147 
00148         resValue = fieldDoubleScalarOnNodes.getValue()
00149         self.assertTrue( isinstance( resValue, ndarray ))
00150 
00151         intArray = arange( numberOfNodes, dtype=int )
00152         self.assertRaises( TypeError, fieldDoubleScalarOnNodes.setValue, intArray )
00153 
00154         fieldDoubleScalarOnNodes.write(MED_DRIVER,filename)
00155 
00156 
00157         supportOnCells = SUPPORT(myMeshing,"On_All_Cells",MED_CELL)
00158         numberOfCells = supportOnCells.getNumberOfElements(MED_ALL_ELEMENTS)
00159 
00160         fieldIntScalarOnCells = FIELDINT(supportOnCells,1)
00161         fieldIntScalarOnCells.setName("fieldScalarIntCell")
00162         fieldIntScalarOnCells.setIterationNumber(-1)
00163         fieldIntScalarOnCells.setOrderNumber(-1)
00164         fieldIntScalarOnCells.setTime(0.0)
00165 
00166         fieldIntScalarOnCells.setComponentName(1,"Vx")
00167         fieldIntScalarOnCells.setComponentDescription(1,"comp1")
00168         fieldIntScalarOnCells.setMEDComponentUnit(1,"unit1")
00169 
00170         cellValues = arange(numberOfCells)
00171         fieldIntScalarOnCells.setValue( cellValues )
00172 
00173         resValue = fieldIntScalarOnCells.getValue()
00174         self.assertTrue( isinstance( resValue, ndarray ))
00175         self.assertTrue( len(resValue) == numberOfCells)
00176 
00177         dblArray = arange( numberOfNodes, dtype=float )
00178         self.assertRaises( TypeError, fieldIntScalarOnCells.setValue, dblArray )
00179 
00180         fieldIntScalarOnCells.write(MED_DRIVER,filename)
00181 
00182         os.remove( filename )


The documentation for this class was generated from the following file: