Back to index

salome-med  6.5.0
TestMedCorba3.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 # MED Mesh read from a (local) file
00032 
00033 from libMEDMEM_Swig import *
00034 
00035 md = MED()
00036 
00037 mdDriver = MED_MED_RDONLY_DRIVER(fileName, md)
00038 
00039 mdDriver.open()
00040 mdDriver.readFileStruct()
00041 mdDriver.close()
00042 
00043 mLocal = md.getMesh(md.getMeshName(0))
00044 mLocal.read()
00045 
00046 # MED Mesh recieved from a distant component (via CORBA)
00047 
00048 from omniORB import CORBA
00049 from LifeCycleCORBA import *
00050 from libSALOME_Swig import *
00051 
00052 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
00053 lcc = LifeCycleCORBA(orb)
00054 
00055 C = lcc.FindOrLoadComponent("FactoryServerPy", "Compo1Py")
00056 C.Initialise(fileName)
00057 
00058 mDistant = C.Calcul1()
00059 
00060 # Compare local and distant copies
00061 
00062 def ecart(x, y):
00063     s = 0.
00064     if (len(x) != len(y)):
00065         return 1.
00066     
00067     for i in xrange(len(x)):
00068         s = s + abs(x[i] - y[i]);
00069     return s
00070 
00071 def compare(x, y):
00072     if (len(x) != len(y)):
00073         return 0
00074     for i in xrange(len(x)):
00075         if x[i] != y[i]:
00076             return 0
00077     return 1
00078 
00079 print "Name              : ", mDistant.getName()
00080 if (mLocal.getName() != mDistant.getName()):
00081     raise RuntimeError, "MESH::getName()"
00082 
00083 print "SpaceDimension    : ", mDistant.getSpaceDimension()
00084 if (mLocal.getSpaceDimension() != mDistant.getSpaceDimension()):
00085     raise RuntimeError, "MESH::getSpaceDimension()"
00086 
00087 print "MeshDimension     : ", mDistant.getMeshDimension()
00088 if (mLocal.getMeshDimension() != mDistant.getMeshDimension()):
00089     raise RuntimeError, "MESH::getMeshDimension()"
00090 
00091 print "CoordinatesSystem : ", mDistant.getCoordinatesSystem()
00092 if (mLocal.getCoordinatesSystem() != mDistant.getCoordinatesSystem()):
00093     raise RuntimeError, "MESH::getCoordinatesSystem()"
00094 
00095 print "NumberOfNodes     : ", mDistant.getNumberOfNodes()
00096 if (mLocal.getNumberOfNodes() != mDistant.getNumberOfNodes()):
00097     raise RuntimeError, "MESH::getNumberOfNodes()"
00098 
00099 x1 = mLocal.getCoordinates(MED_FULL_INTERLACE);
00100 x2 = mDistant.getCoordinates(MED_FULL_INTERLACE);
00101 
00102 print "Coordinates (local)   : ", x1
00103 print "Coordinates (distant) : ", x2
00104 
00105 d = ecart(x1, x2);
00106 print "                    (differences between local and distant) : ", d
00107 if (d > 1.0e-7):
00108     raise RuntimeError, "MESH::getCoordinates()"
00109 
00110 s1 = mLocal.getCoordinatesNames();
00111 s2 = mDistant.getCoordinatesNames();
00112 print "CoordinatesNames (local)   : ", s1
00113 print "CoordinatesNames (distant) : ", s2
00114 
00115 if (not compare(s1, s2)):
00116     raise RuntimeError, "MESH::CoordinatesNames()"
00117 
00118 s1 = mLocal.getCoordinatesUnits();
00119 s2 = mDistant.getCoordinatesUnits();
00120 print "CoordinatesUnits (local)   : ", s1
00121 print "CoordinatesUnits (distant) : ", s2
00122 
00123 if (not compare(s1, s2)):
00124     raise RuntimeError, "MESH::CoordinatesUnits()"
00125 
00126 
00127     
00128 print
00129 print "All tests passed"