Back to index

salome-med  6.5.0
TestMedCorba2.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 def transpose(x, n, m):
00080     y = range(len(x));
00081     for i in xrange(n):
00082         for j in xrange(m):
00083             y[i + j*n] = x[i*m + j];
00084     return y
00085 
00086 m = mDistant.getSpaceDimension();
00087 print "SpaceDimension    : ", m
00088 n = mDistant.getNumberOfNodes();
00089 print "NumberOfNodes     : ", n
00090 
00091 x1 = mDistant.getCoordinates(MED_FULL_INTERLACE);
00092 x2 = mDistant.getCoordinates(MED_NO_INTERLACE);
00093 x3 = mDistant.getCoordinates(MED_FULL_INTERLACE);
00094 
00095 print "Coordinates (MED_FULL_INTERLACE) : ", x1
00096 print "Coordinates (MED_NO_INTERLACE) :   ", x2
00097 
00098 if (ecart(x1, x3) > 1e-7):
00099     raise RuntimeError, "getCoordinates : INTERLACE"
00100 
00101 x4 = transpose(x1, n, m);
00102 print "Coordinates (MED_NO_INTERLACE) :   ", x4
00103 
00104 if (ecart(x2, x4) > 1e-7):
00105     raise RuntimeError, "getCoordinates : NO_INTERLACE"
00106 
00107 print
00108 print "All tests passed"