Back to index

salome-med  6.5.0
batchmode_medcorba_test1.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 #  MED MedCorba_Swig : binding of MED CORBA objects woth Python
00025 #  File   : batchmode_medcorba_test.py
00026 #  Module : MED
00027 #
00028 import batchmode_salome
00029 
00030 import SALOME_MED
00031 
00032 from libMedCorba_Swig import *
00033 
00034 from random import *
00035 
00036 import os
00037 
00038 filePath = os.environ["MED_ROOT_DIR"]
00039 filePath = os.path.join( filePath, "share", "salome", "resources", "med" )
00040 
00041 #==============================================================================
00042 
00043 def AnalyzeField(field):
00044     name = field.getName()
00045     desc = field.getDescription()
00046     nbComp = field.getNumberOfComponents()
00047     itNum = field.getIterationNumber()
00048     ordNum = field.getOrderNumber()
00049 
00050     print "Analysis of the field ",name," with the description ",desc
00051     print "iteration number ",itNum," order Number ",ordNum
00052     print "It has ",nbComp," component(s)"
00053 
00054     fieldValue = field.getValue(SALOME_MED.MED_FULL_INTERLACE)
00055     fieldSupport = field.getSupport()
00056     fieldMesh = fieldSupport.getMesh()
00057     fieldEntity = fieldSupport.getEntity()
00058     bool = fieldSupport.isOnAllElements()
00059 
00060     if bool:
00061         print "The support of this field is on all entities ",fieldEntity," of the mesh ",fieldMesh.getName()
00062         if fieldEntity == SALOME_MED.MED_NODE:
00063             nbValByComp = fieldMesh.getNumberOfNodes()
00064         else:
00065             nbValByComp = fieldMesh.getNumberOfElements(fieldEntity,SALOME_MED.MED_ALL_ELEMENTS)
00066         print "and its dimension (number of values by component of the field) is ",nbValByComp
00067     else:
00068         print "The support of this field is partially on entities ",fieldEntity," of the mesh ",fieldMesh.getName()
00069         nbValByComp = fieldSupport.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
00070         print "and its dimension (number of values by component of the field) is ",nbValByComp
00071 
00072     for i in range(nbComp):
00073         compName = field.getComponentName(i+1)
00074         compUnit = field.getComponentUnit(i+1)
00075         print "The ",(i+1),"-th  component ",compName," with the unit ",compUnit
00076 
00077     for i in range(nbValByComp):
00078         print "  * ",fieldValue[i*nbComp:(i+1)*nbComp]
00079 
00080 #==============================================================================
00081 
00082 def getMeshObjectFromStudy(number):
00083     mySO = batchmode_salome.myStudy.FindObject("MEDMESH")
00084     mysub = mySO.FindSubObject(number)[1]
00085     if mysub:
00086         Builder = batchmode_salome.myStudy.NewBuilder()
00087         anAttr = Builder.FindOrCreateAttribute(mysub, "AttributeIOR")
00088         obj = batchmode_salome.orb.string_to_object(anAttr.Value())
00089         myObj = obj._narrow(SALOME_MED.MESH)
00090         return myObj
00091     else:
00092         print "ERROR: No Mesh Object stored in this Study"
00093         return None
00094 
00095 
00096 #==============================================================================
00097 
00098 def getFieldDoubleObjectFromStudy(number,subnumber):
00099     mySO = batchmode_salome.myStudy.FindObject("MEDFIELD")
00100     mysub = mySO.FindSubObject(number)[1]
00101     if mysub:
00102         mysubsub = mysub.FindSubObject(subnumber)[1]
00103         if mysubsub:
00104             Builder = batchmode_salome.myStudy.NewBuilder()
00105             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
00106             obj = batchmode_salome.orb.string_to_object(anAttr.Value())
00107             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeName")
00108             myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
00109             return myObj
00110         else:
00111             print "ERROR: No FieldDouble Object stored in this Study"
00112             return None
00113     else:
00114         print "ERROR: No FieldDouble Object stored in this Study"
00115         return None
00116 
00117 
00118 #==============================================================================
00119 
00120 def getFieldIntObjectFromStudy(number,subnumber):
00121     mySO = batchmode_salome.myStudy.FindObject("MEDFIELD")
00122     mysub = mySO.FindSubObject(number)[1]
00123     if mysub:
00124         mysubsub = mysub.FindSubObject(subnumber)[1]
00125         if mysubsub:
00126             Builder = batchmode_salome.myStudy.NewBuilder()
00127             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
00128             obj = batchmode_salome.orb.string_to_object(anAttr.Value())
00129             myObj = obj._narrow(SALOME_MED.FIELDINT)
00130             return myObj
00131         else:
00132             print "ERROR: No FieldInt Object stored in this Study"
00133             return None
00134     else:
00135         print "ERROR: No FieldInt Object stored in this Study"
00136         return None
00137 
00138 #==============================================================================
00139 
00140 def getMedObjectFromStudy(fileName=None):
00141     myObj=None; Builder = batchmode_salome.myStudy.NewBuilder()
00142     if fileName is not None:
00143         objNameInStudy = "MED_OBJECT_FROM_FILE_"+fileName
00144         mySO = batchmode_salome.myStudy.FindObject(objNameInStudy)
00145         if mySO is not None:
00146             anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR")
00147             obj = batchmode_salome.orb.string_to_object(anAttr.Value())
00148             if obj is not None:
00149                 myObj = obj._narrow(SALOME_MED.MED)
00150             else:
00151                 print "ERROR: ",myObj," has been found in the Study, but with the type different of SALOME_MED.MED!!!"
00152         else:
00153             print "ERROR: ",objNameInStudy," hasn't been found in the Study!!!"
00154     else:
00155         SObj_root = batchmode_salome.myStudy.FindObjectByPath("/Med/")
00156         if SObj_root is not None:
00157             iter = batchmode_salome.myStudy.NewChildIterator(SObj_root)
00158             try:
00159                 iter.Init(); 
00160                 while iter.More():
00161                     Obj = iter.Value()
00162                     if Obj is not None:
00163                         Ok, anAttr = Builder.FindAttribute(Obj, "AttributeIOR")
00164                         if Ok:
00165                             if len(anAttr.Value()) > 0:
00166                                 obj = batchmode_salome.orb.string_to_object(anAttr.Value())
00167                                 if obj is not None:
00168                                     myObj = obj._narrow(SALOME_MED.MED)
00169                                     if myObj is not None:
00170                                         break
00171                     iter.Next()
00172             except:
00173                 print "Exception!!!"
00174         else: print "Root object Med hasn't been found in the study!!!"
00175     return myObj
00176         
00177 studyCurrent = batchmode_salome.myStudyName
00178 studyCurrentId = batchmode_salome.myStudyId
00179 
00180 med_comp = batchmode_salome.lcc.FindOrLoadComponent("FactoryServer", "MED")