Back to index

salome-med  6.5.0
TestMedCorba5.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 import os
00025 BASE = os.environ["MED_ROOT_DIR"]
00026 BASE = os.path.join( BASE, 'share', 'salome', 'resources', 'med' )
00027 
00028 fileName = os.path.join( BASE, 'pointe.med' )
00029 fileName = os.path.join( BASE, 'carre_en_quad4_seg2.med' )
00030 
00031 
00032 def compare(x, y):
00033     if (len(x) != len(y)):
00034         return 0
00035     for i in xrange(len(x)):
00036         if x[i] != y[i]:
00037             return 0
00038     return 1
00039 
00040 # MED Mesh read from a (local) file
00041 
00042 from libMEDMEM_Swig import *
00043 
00044 md = MED()
00045 
00046 mdDriver = MED_MED_RDONLY_DRIVER(fileName, md)
00047 
00048 mdDriver.open()
00049 mdDriver.readFileStruct()
00050 mdDriver.close()
00051 
00052 mLocal = md.getMesh(md.getMeshName(0))
00053 mLocal.read()
00054 
00055 # MED Mesh recieved from a distant component (via CORBA)
00056 
00057 from omniORB import CORBA
00058 from LifeCycleCORBA import *
00059 from libSALOME_Swig import *
00060 
00061 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
00062 lcc = LifeCycleCORBA(orb)
00063 
00064 C = lcc.FindOrLoadComponent("FactoryServerPy", "Compo1Py")
00065 C.Initialise(fileName)
00066 
00067 mDistant = C.Calcul1()
00068 
00069 
00070 print "Name              : ", mDistant.getName()
00071 
00072 
00073 for i in [MED_CELL,
00074           MED_FACE,
00075           MED_EDGE,
00076           MED_NODE,
00077           MED_ALL_ENTITIES ]:
00078 
00079     n1 = mLocal.getNumberOfTypes(i);
00080     n2 = mDistant.getNumberOfTypes(i);
00081 
00082     if (n1 != n2):
00083         raise RuntimeError, "MESH::getNumberOfTypes()"
00084 
00085     if ((n1 > 0) & (i != MED_NODE)):
00086         T1 = mLocal.getTypes(i);
00087         T2 = mDistant.getTypes(i);
00088  
00089         if (n2 !=  len(T2)):
00090             raise RuntimeError, \
00091                   "len(MESH::getTypes()) <> MESH::getNumberOfTypes()"
00092 
00093         for j in range(n2):
00094             if (T1[j] != T2[j]):
00095                 raise RuntimeError, "MESH::getTypes()"
00096 
00097             c1 = mLocal.getConnectivity(MED_FULL_INTERLACE, MED_NODAL, \
00098                                         i, T1[j]);
00099             c2 = mDistant.getConnectivity(MED_FULL_INTERLACE, MED_NODAL, \
00100                                         i, T2[j]);
00101 
00102             print "connectivity (local)   : ", T1[j], " : ", c1;
00103             print "connectivity (distant) : ", T2[j], " : ", c2;
00104 
00105             if (compare(c1, c2) == 0):
00106                 raise RuntimeError, "MESH::getConnectivity()"
00107         
00108 print
00109 print "All tests passed"