Back to index

salome-med  6.5.0
Public Member Functions
SauvLoaderTest.SauvLoaderTest Class Reference

List of all members.

Public Member Functions

def testSauv2Med
def testMed2Sauv

Detailed Description

Definition at line 25 of file SauvLoaderTest.py.


Member Function Documentation

Definition at line 50 of file SauvLoaderTest.py.

00050 
00051     def testMed2Sauv(self):
00052         # read pointe.med
00053         self.assertTrue( os.getenv("MED_ROOT_DIR") )
00054         medFile = os.path.join( os.getenv("MED_ROOT_DIR"), "share","salome",
00055                                 "resources","med","pointe.med")
00056         self.assertTrue( os.access( medFile, os.F_OK))
00057         pointeMed = MEDFileData.New( medFile )
00058 
00059         # add 3 faces to pointeMed
00060         pointeMedMesh = pointeMed.getMeshes().getMeshAtPos(0)
00061         pointeM1D = MEDCouplingUMesh.New()
00062         pointeM1D.setCoords( pointeMedMesh.getCoords() )
00063         pointeM1D.setMeshDimension( 2 )
00064         pointeM1D.allocateCells( 3 )
00065         pointeM1D.insertNextCell( NORM_TRI3, 3, [0,1,2])
00066         pointeM1D.insertNextCell( NORM_TRI3, 3, [0,1,3])
00067         pointeM1D.insertNextCell( NORM_QUAD4, 4, [10,11,12,13])
00068         pointeM1D.finishInsertingCells()
00069         pointeMedMesh.setMeshAtLevel( -1, pointeM1D )
00070         pointeMed.getMeshes().setMeshAtPos( 0, pointeMedMesh )
00071 
00072         # add a field on 2 faces to pointeMed
00073         ff1=MEDFileFieldMultiTS.New()
00074         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME)
00075         #f1.setMesh( pointeM1D )
00076         f1.setName("Field on 2 faces")
00077         d=DataArrayDouble.New()
00078         d.alloc(3+4,2)
00079         d.setInfoOnComponent(0,"sigX [MPa]")
00080         d.setInfoOnComponent(1,"sigY [GPa]")
00081         d.setValues([311,312,321,322,331,332,411,412,421,422,431,432,441,442],3+4,2)
00082         f1.setArray(d)
00083         da=DataArrayInt.New()
00084         da.setValues([0,2],2,1)
00085         da.setName("sup2")
00086         ff1.appendFieldProfile(f1,pointeMedMesh,-1,da)
00087         pointeMed.getFields().pushField( ff1 )
00088 
00089         #remove fieldnodeint
00090         pointeFields = pointeMed.getFields()
00091         for i in range( pointeFields.getNumberOfFields() ):
00092             if pointeFields.getFieldAtPos(i).getName() == "fieldnodeint":
00093                 pointeFields.destroyFieldAtPos( i )
00094                 break
00095 
00096         # write pointeMed to SAUV
00097         sauvFile = "SauvLoaderTest.sauv"
00098         sw=SauvWriter.New();
00099         sw.setMEDFileDS(pointeMed);
00100         sw.write(sauvFile);
00101 
00102         # read SAUV and check
00103         sr=SauvReader.New(sauvFile);
00104         d2=sr.loadInMEDFileDS();
00105         self.assertEqual(1,d2.getNumberOfMeshes())
00106         self.assertEqual(4,d2.getNumberOfFields())
00107         m = d2.getMeshes().getMeshAtPos(0)
00108         self.assertEqual("maa1",m.getName())
00109         self.assertEqual(5,len(m.getGroupsNames()))
00110         self.assertEqual(3,m.getMeshDimension())
00111         groups = m.getGroupsNames()
00112         self.assertTrue( "groupe1" in groups )
00113         self.assertTrue( "groupe2" in groups )
00114         self.assertTrue( "groupe3" in groups )
00115         self.assertTrue( "groupe4" in groups )
00116         self.assertTrue( "groupe5" in groups )
00117         self.assertEqual(16,m.getSizeAtLevel(0))
00118         um0 = m.getGenMeshAtLevel(0)
00119         self.assertEqual(12, um0.getNumberOfCellsWithType( NORM_TETRA4 ))
00120         self.assertEqual(2, um0.getNumberOfCellsWithType( NORM_PYRA5 ))
00121         self.assertEqual(2, um0.getNumberOfCellsWithType( NORM_HEXA8 ))
00122         um1 = m.getGenMeshAtLevel(-1)
00123         self.assertEqual(2, um1.getNumberOfCellsWithType( NORM_TRI3 ))
00124         pointeUM0 = pointeMedMesh.getGenMeshAtLevel(0)
00125         self.assertTrue(m.getCoords().isEqualWithoutConsideringStr(pointeMedMesh.getCoords(),1e-12))
00126         self.assertEqual( um0.getMeasureField(0).accumulate(0),
00127                           pointeUM0.getMeasureField(0).accumulate(0),1e-12)
00128         # check fields
00129         # fieldnodedouble
00130         fieldnodedoubleTS1 = pointeMed.getFields().getFieldWithName("fieldnodedouble")
00131         fieldnodedoubleTS2 = d2.getFields().getFieldWithName("fieldnodedouble")
00132         self.assertEqual( fieldnodedoubleTS1.getInfo(), fieldnodedoubleTS2.getInfo())
00133         self.assertEqual( fieldnodedoubleTS1.getNumberOfTS(), fieldnodedoubleTS2.getNumberOfTS())
00134         io1 = fieldnodedoubleTS1.getIterations()
00135         io2 = fieldnodedoubleTS2.getIterations()
00136         for i in range(fieldnodedoubleTS1.getNumberOfTS() ):
00137             fnd1 = fieldnodedoubleTS1.getFieldOnMeshAtLevel(ON_NODES, io1[i][0],io1[i][1],pointeUM0)
00138             fnd2 = fieldnodedoubleTS2.getFieldOnMeshAtLevel(ON_NODES, io2[i][0],io2[i][1],um0)
00139             self.assertTrue( fnd1.getArray().isEqual( fnd2.getArray(), 1e-12 ))
00140         # fieldcelldoublevector
00141         fieldnodedoubleTS1 = pointeMed.getFields().getFieldWithName("fieldcelldoublevector")
00142         fieldnodedoubleTS2 = d2.getFields().getFieldWithName("fieldcelldoublevector")
00143         self.assertEqual( fieldnodedoubleTS1.getInfo(), fieldnodedoubleTS2.getInfo())
00144         self.assertEqual( fieldnodedoubleTS1.getNumberOfTS(), fieldnodedoubleTS2.getNumberOfTS())
00145         io1 = fieldnodedoubleTS1.getIterations()
00146         io2 = fieldnodedoubleTS2.getIterations()
00147         for i in range(fieldnodedoubleTS1.getNumberOfTS() ):
00148             fnd1 = fieldnodedoubleTS1.getFieldOnMeshAtLevel(ON_CELLS, io1[i][0],io1[i][1],pointeUM0)
00149             fnd2 = fieldnodedoubleTS2.getFieldOnMeshAtLevel(ON_CELLS, io2[i][0],io2[i][1],um0)
00150             self.assertAlmostEqual( fnd1.accumulate(0), fnd2.accumulate(0) )
00151             self.assertAlmostEqual( fnd1.accumulate(1), fnd2.accumulate(1) )
00152             self.assertAlmostEqual( fnd1.accumulate(2), fnd2.accumulate(2) )
00153         # Field on 2 faces
00154         fieldOnFaces = d2.getFields().getFieldWithName(f1.getName())
00155         io1 = fieldOnFaces.getIterations()
00156         fof = fieldOnFaces.getFieldOnMeshAtLevel(f1.getTypeOfField(),io1[i][0],io1[i][1],um1)
00157         self.assertTrue( d.isEqual( fof.getArray(), 1e-12 ))
00158 
00159         os.remove( sauvFile )
        pass

Definition at line 27 of file SauvLoaderTest.py.

00027 
00028     def testSauv2Med(self):
00029         # get a file containing all types of readable piles
00030         self.assertTrue( os.getenv("MED_ROOT_DIR") )
00031         sauvFile = os.path.join( os.getenv("MED_ROOT_DIR"), "share","salome",
00032                                  "resources","med","allPillesTest.sauv")
00033         self.assertTrue( os.access( sauvFile, os.F_OK))
00034 
00035         # read SAUV and write MED
00036         medFile = "SauvLoaderTest.med"
00037         sr=SauvReader.New(sauvFile);
00038         d2=sr.loadInMEDFileDS();
00039         d2.write(medFile,0);
00040 
00041         # check 
00042         self.assertEqual(1,d2.getNumberOfMeshes())
00043         self.assertEqual(8+97,d2.getNumberOfFields())
00044         mm = d2.getMeshes()
00045         m = mm.getMeshAtPos(0)
00046         self.assertEqual(17,len(m.getGroupsNames()))
00047 
00048         os.remove( medFile )
00049         pass


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