Back to index

salome-med  6.5.0
TestMEDCouplingCorbaClt.py
Go to the documentation of this file.
00001 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 import unittest
00021 import CORBA
00022 import MEDCouplingCorbaServantTest_idl
00023 import MEDCouplingCorbaSwigTest
00024 from MEDCouplingClient import *
00025 import MEDCouplingCorbaServant_idl
00026 import threading
00027 
00028 class MEDCouplingCorbaServBasicsTestClt(unittest.TestCase):
00029     def testBaseCorbaFetching(self):
00030         self.assertTrue(not CORBA.is_nil(self._objC))
00031         pass
00032 
00033     def testContentOfFetched1DMesh(self):
00034         meshPtr=self._objC.get1DMesh();
00035         _mesh_from_distant=MEDCouplingUMeshClient.New(meshPtr);
00036         meshPtr.UnRegister();
00037         self.assertTrue(_mesh_from_distant.getSpaceDimension()==3);
00038         self.assertTrue(_mesh_from_distant.getMeshDimension()==1);
00039         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00040         meshRef=test.build1DMesh()
00041         self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12));
00042         pass
00043 
00044     def testCorbaFetching2D(self):
00045         meshPtr=self._objC.get2DMesh();
00046         _mesh_from_distant=MEDCouplingUMeshClient.New(meshPtr);
00047         meshPtr.UnRegister();
00048         self.assertTrue(_mesh_from_distant.getSpaceDimension()==2);
00049         self.assertTrue(_mesh_from_distant.getMeshDimension()==2);
00050         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00051         meshRef=test.build2DMesh()
00052         self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12));
00053         pass
00054     
00055     def testContentOfFetched2DMesh(self):
00056         pass
00057     
00058     def testMultiFetchingToTestMemoryManagement(self):
00059         for i in xrange(1000):
00060             meshPtr=self._objC.get2DMesh();
00061             _mesh_from_distant=MEDCouplingUMeshClient.New(meshPtr);
00062             meshPtr.UnRegister();
00063             test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00064             meshRef=test.build2DMesh();
00065             self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12));
00066             pass
00067         pass
00068     
00069     def testCorbaFetching3D(self):
00070         meshPtr=self._objC.get3DMesh();
00071         _mesh_from_distant=MEDCouplingUMeshClient.New(meshPtr);
00072         meshPtr.UnRegister();
00073         self.assertTrue(3==_mesh_from_distant.getSpaceDimension());
00074         self.assertTrue(3==_mesh_from_distant.getMeshDimension());
00075         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00076         meshRef=test.build3DMesh();
00077         self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12));
00078         pass
00079     
00080     def testContentOfFetched3DMesh(self):
00081         pass
00082     
00083     def testCorbaFetching3DSurf(self):
00084         meshPtr=self._objC.get3DSurfMesh();
00085         _mesh_from_distant=MEDCouplingUMeshClient.New(meshPtr);
00086         meshPtr.UnRegister();
00087         self.assertTrue(3==_mesh_from_distant.getSpaceDimension());
00088         self.assertTrue(2==_mesh_from_distant.getMeshDimension());
00089         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00090         meshRef=test.build3DSurfMesh();
00091         self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12));
00092         pass
00093     
00094     def testContentOfFetched3DSurfMesh(self):
00095         pass
00096     
00097     def testCorbaFetching0D(self):
00098         meshPtr=self._objC.get0DMesh();
00099         _mesh_from_distant=MEDCouplingUMeshClient.New(meshPtr);
00100         meshPtr.UnRegister();
00101         self.assertTrue(3==_mesh_from_distant.getSpaceDimension());
00102         self.assertTrue(0==_mesh_from_distant.getMeshDimension());
00103         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00104         meshRef=test.build0DMesh();
00105         self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12));
00106         pass
00107     
00108     def testCorbaFetchingM1D(self):
00109         meshPtr=self._objC.getM1DMesh();
00110         _mesh_from_distant=MEDCouplingUMeshClient.New(meshPtr);
00111         meshPtr.UnRegister();
00112         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00113         meshRef=test.buildM1DMesh();
00114         self.assertTrue(-1==_mesh_from_distant.getMeshDimension());
00115         self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12));
00116         pass
00117 
00118     def testCorbaFetchingExtruded(self):
00119         meshPtr=self._objC.getExtrudedMesh();
00120         _mesh_from_distant=MEDCouplingExtrudedMeshClient.New(meshPtr);
00121         meshPtr.UnRegister();
00122         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00123         meshRef=test.buildExtrudedMesh();
00124         self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12))
00125         pass
00126 
00127     def testCorbaFetchingCMesh(self):
00128         meshPtr=self._objC.getCMesh();
00129         _mesh_from_distant=MEDCouplingCMeshClient.New(meshPtr);
00130         meshPtr.UnRegister();
00131         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00132         meshRef=test.buildCMesh();
00133         self.assertTrue(_mesh_from_distant.isEqual(meshRef,1e-12))
00134         pass
00135     
00136     def testCorbaField2DNTFetching(self):
00137         fieldPtr=self._objC.getFieldScalarOn2DNT();
00138         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00139         fieldPtr.UnRegister();
00140         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00141         refField=test.buildFieldScalarOn2DNT();
00142         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00143         pass
00144     
00145     def testCorbaField2DNTMultiFetching(self):
00146         fieldPtr=self._objC.getFieldScalarOn2DNT();
00147         fieldCpp1=MEDCouplingFieldDoubleClient.New(fieldPtr);
00148         fieldCpp2=MEDCouplingFieldDoubleClient.New(fieldPtr);
00149         fieldPtr.UnRegister();
00150         self.assertTrue(fieldCpp1.isEqual(fieldCpp2,1.e-12,1.e-15))
00151         pass
00152 
00153     def corbaField2DNTMFMTThread(self,i,fieldPtr,li):
00154         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00155         li[i]=fieldCpp
00156         pass
00157     
00158     def testCorbaField2DNTMultiFetchingMT(self):
00159         li=8*[None]
00160         th=8*[None]
00161         fieldPtr=self._objC.getFieldScalarOn2DNT();
00162         for i in xrange(8):
00163             th[i]=threading.Thread(None,self.corbaField2DNTMFMTThread,"Test"+str(i),(i,fieldPtr,li))
00164             th[i].start()
00165             pass
00166         for i in xrange(8):
00167             th[i].join()
00168             pass
00169         for i in xrange(8-1):
00170             self.assertTrue(li[i].isEqual(li[i+1],1.e-12,1.e-15));
00171             pass
00172         fieldPtr.UnRegister()
00173         pass
00174     
00175     def testCorbaFieldNode2DNTFetching(self):
00176         fieldPtr=self._objC.getFieldNodeScalarOn2DNT();
00177         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00178         fieldPtr.UnRegister();
00179         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00180         refField=test.buildFieldNodeScalarOn2DNT();
00181         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00182         pass
00183     
00184     def testCorbaField3DNTFetching(self):
00185         fieldPtr=self._objC.getFieldScalarOn3DNT();
00186         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00187         fieldPtr.UnRegister();
00188         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00189         refField=test.buildFieldScalarOn3DNT();
00190         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00191         pass
00192     
00193     def testCorbaField3DSurfWTFetching(self):
00194         fieldPtr=self._objC.getFieldScalarOn3DSurfWT();
00195         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00196         fieldPtr.UnRegister();
00197         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00198         refField=test.buildFieldScalarOn3DSurfWT();
00199         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00200         pass
00201     
00202     def testCorbaField3DSurfCOTIFetching(self):
00203         fieldPtr=self._objC.getFieldScalarOn3DSurfCOTI();
00204         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00205         fieldPtr.UnRegister();
00206         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00207         refField=test.buildFieldScalarOn3DSurfCOTI();
00208         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00209         pass
00210 
00211     def testCorbaField2DLTFetching(self):
00212         fieldPtr=self._objC.getFieldScalarOn2DLT();
00213         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00214         fieldPtr.UnRegister();
00215         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00216         refField=test.buildFieldScalarOn2DLT();
00217         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00218         pass
00219 
00220     def testCorbaFieldGaussPt2DWTFetching(self):
00221         fieldPtr=self._objC.getFieldGaussPt2DWT();
00222         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00223         fieldPtr.UnRegister();
00224         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00225         refField=test.buildFieldGaussPt2DWT();
00226         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00227         pass
00228     
00229     def testCorbaFieldGaussPtNE2DWTFetching(self):
00230         fieldPtr=self._objC.getFieldGaussPtNE2DWT();
00231         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00232         fieldPtr.UnRegister();
00233         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00234         refField=test.buildFieldGaussPtNE2DWT();
00235         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00236         pass
00237 
00238     def testCorbaFieldVectorOnExtrudedWT(self):
00239         fieldPtr=self._objC.getFieldVectorOnExtrudedWT();
00240         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00241         fieldPtr.UnRegister();
00242         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00243         refField=test.buildFieldVectorOnExtrudedWT();
00244         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00245         pass
00246 
00247     def testCorbaFieldVectorOnCMeshWT(self):
00248         fieldPtr=self._objC.getFieldVectorOnCMeshWT();
00249         fieldCpp=MEDCouplingFieldDoubleClient.New(fieldPtr);
00250         fieldPtr.UnRegister();
00251         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00252         refField=test.buildFieldVectorOnCMeshWT();
00253         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00254         pass
00255 
00256     def testCorbaFieldTemplateCellOn2D(self):
00257         fieldPtr=self._objC.getFieldTemplateCellOn2D();
00258         fieldCpp=MEDCouplingFieldTemplateClient.New(fieldPtr);
00259         fieldPtr.UnRegister();
00260         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00261         refField=test.buildFieldTemplateCellOn2D();
00262         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00263         pass
00264     
00265     def testCorbaFieldTemplateNodeOn2D(self):
00266         fieldPtr=self._objC.getFieldTemplateNodeOn2D();
00267         fieldCpp=MEDCouplingFieldTemplateClient.New(fieldPtr);
00268         fieldPtr.UnRegister();
00269         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00270         refField=test.buildFieldTemplateNodeOn2D();
00271         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00272         pass
00273     
00274     def testCorbaFieldTemplateGaussPtOn2D(self):
00275         fieldPtr=self._objC.getFieldTemplateGaussPtOn2D();
00276         fieldCpp=MEDCouplingFieldTemplateClient.New(fieldPtr);
00277         fieldPtr.UnRegister();
00278         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00279         refField=test.buildFieldTemplateGaussPtOn2D();
00280         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00281         pass
00282     
00283     def testCorbaFieldTemplateGaussNEOn2D(self):
00284         fieldPtr=self._objC.getFieldTemplateGaussNEOn2D();
00285         fieldCpp=MEDCouplingFieldTemplateClient.New(fieldPtr);
00286         fieldPtr.UnRegister();
00287         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00288         refField=test.buildFieldTemplateGaussNEOn2D();
00289         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00290         pass
00291 
00292     def testCorbaMultiFields1(self):
00293         fieldPtr=self._objC.getMultiFields1()
00294         fieldCpp=MEDCouplingMultiFieldsClient.New(fieldPtr);
00295         fieldPtr.UnRegister()
00296         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00297         refField=test.buildMultiFields1();
00298         self.assertTrue(fieldCpp.isEqual(refField,1.e-12,1.e-15));
00299         pass
00300 
00301     def testCorbaArrayDouble1(self):
00302         fieldPtr=self._objC.getArrayDouble1()
00303         fieldCpp=DataArrayDoubleClient.New(fieldPtr)
00304         fieldPtr.UnRegister()
00305         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00306         refField=test.buildArrayDouble1();
00307         self.assertTrue(fieldCpp.isEqual(refField,1e-12))
00308         pass
00309     
00310     def testCorbaArrayDouble2(self):
00311         fieldPtr=self._objC.getArrayDouble2()
00312         fieldCpp=DataArrayDoubleClient.New(fieldPtr)
00313         fieldPtr.UnRegister()
00314         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00315         refField=test.buildArrayDouble2();
00316         self.assertTrue(fieldCpp.isEqual(refField,1e-12))
00317         pass
00318 
00319     def testCorbaArrayDouble3(self):
00320         fieldPtr=self._objC.getArrayDouble3()
00321         fieldCpp=DataArrayDoubleClient.New(fieldPtr)
00322         fieldPtr.UnRegister()
00323         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00324         refField=test.buildArrayDouble3();
00325         self.assertTrue(fieldCpp.isEqual(refField,1e-12))
00326         pass
00327 
00328     def testCorbaArrayInt1(self):
00329         fieldPtr=self._objC.getArrayInt1()
00330         fieldCpp=DataArrayIntClient.New(fieldPtr)
00331         fieldPtr.UnRegister()
00332         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00333         refField=test.buildArrayInt1();
00334         self.assertTrue(fieldCpp.isEqual(refField))
00335         pass
00336 
00337     def testCorbaArrayInt2(self):
00338         fieldPtr=self._objC.getArrayInt2()
00339         fieldCpp=DataArrayIntClient.New(fieldPtr)
00340         fieldPtr.UnRegister()
00341         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00342         refField=test.buildArrayInt2();
00343         self.assertTrue(fieldCpp.isEqual(refField))
00344         pass
00345 
00346     def testCorbaArrayInt3(self):
00347         fieldPtr=self._objC.getArrayInt3()
00348         fieldCpp=DataArrayIntClient.New(fieldPtr)
00349         fieldPtr.UnRegister()
00350         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00351         refField=test.buildArrayInt3();
00352         self.assertTrue(fieldCpp.isEqual(refField))
00353         pass
00354 
00355     def testCorbaFetchingCoords1(self):
00356         meshPtr=self._objC.get3DSurfMesh();
00357         cooPtr=meshPtr.getCoords();
00358         meshPtr.UnRegister();
00359         cooCpp=DataArrayDoubleClient.New(cooPtr);
00360         cooPtr.UnRegister();
00361         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00362         meshRef=test.build3DSurfMesh();
00363         #
00364         self.assertTrue(meshRef.getCoords().isEqual(cooCpp,1e-12));
00365         pass
00366 
00367     def testCorbaMultiFields2(self):
00368         fotPtr=self._objC.getMultiFields2();
00369         fotc=MEDCouplingFieldOverTimeClient.New(fotPtr);
00370         fotPtr.UnRegister();
00371         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00372         refField=test.buildMultiFields2()
00373         #
00374         self.assertTrue(fotc.isEqual(refField,1.e-12,1.e-15));
00375         ts=fotc.getTimeSteps();
00376         self.assertEqual(6,len(ts));
00377         expected=[0.2,0.7,1.2,1.35,1.7,2.7];
00378         for i in xrange(6):
00379             self.assertAlmostEqual(expected[i],ts[i],12);
00380         pass
00381     
00382     def testShutdownServer(self):
00383         self._objC.shutdownOrb()
00384         pass
00385     
00386     def setUp(self):
00387         self._orb=CORBA.ORB_init([''])      
00388         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()
00389         f=file(test.buildFileNameForIOR(),"r")
00390         ior=f.read()
00391         self._objC=self._orb.string_to_object(ior);
00392         pass
00393     pass
00394 
00395 unittest.main()