-# Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
#
# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-import salome
-import SALOME
-import SALOME_MED
-import PYCALCULATOR_ORB
-import os
-
-#==============================================================================
-
-def AnalyzeField(field):
- name = field.getName()
- desc = field.getDescription()
- nbComp = field.getNumberOfComponents()
- itNum = field.getIterationNumber()
- ordNum = field.getOrderNumber()
-
- print "Analysis of the field ",name," with the description ",desc
- print "iteration number ",itNum," order Number ",ordNum
- print "It has ",nbComp," component(s)"
-
- fieldValue = field.getValue(SALOME_MED.MED_FULL_INTERLACE)
- fieldSupport = field.getSupport()
- fieldMesh = fieldSupport.getMesh()
- fieldEntity = fieldSupport.getEntity()
- bool = fieldSupport.isOnAllElements()
-
- if bool:
- print "The support of this field is on all entities ",fieldEntity," of the mesh ",fieldMesh.getName()
- if fieldEntity == SALOME_MED.MED_NODE:
- nbValByComp = fieldMesh.getNumberOfNodes()
- else:
- nbValByComp = fieldMesh.getNumberOfElements(fieldEntity,SALOME_MED.MED_ALL_ELEMENTS)
- print "and its dimension (number of values by component of the field) is ",nbValByComp
- else:
- print "The support of this field is partially on entities ",fieldEntity," of the mesh ",fieldMesh.getName()
- nbValByComp = fieldSupport.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
- print "and its dimension (number of values by component of the field) is ",nbValByComp
-
- for i in range(nbComp):
- compName = field.getComponentName(i+1)
- compUnit = field.getComponentUnit(i+1)
- print "The ",(i+1),"-th component ",compName," with the unit ",compUnit
-
- for i in range(nbValByComp):
- print " * ",fieldValue[i*nbComp:(i+1)*nbComp]
-
-#==============================================================================
-
-def getFieldIntObjectFromStudy(number,subnumber):
- mySO = salome.myStudy.FindObject("MEDFIELD")
- mysub = mySO.FindSubObject(number)[1]
- if mysub:
- mysubsub = mysub.FindSubObject(subnumber)[1]
- if mysubsub:
- Builder = salome.myStudy.NewBuilder()
- anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
- obj = salome.orb.string_to_object(anAttr.Value())
- myObj = obj._narrow(SALOME_MED.FIELDINT)
- return myObj
- else:
- print "ERROR: No FieldInt Object stored in this Study"
- return None
- else:
- print "ERROR: No FieldInt Object stored in this Study"
- return None
-
-#==============================================================================
-
-def getFieldDoubleObjectFromStudy(number,subnumber):
- mySO = salome.myStudy.FindObject("MEDFIELD")
- mysub = mySO.FindSubObject(number)[1]
- if mysub:
- mysubsub = mysub.FindSubObject(subnumber)[1]
- if mysubsub:
- Builder = salome.myStudy.NewBuilder()
- anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
- obj = salome.orb.string_to_object(anAttr.Value())
- myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
- return myObj
- else:
- print "ERROR: No FieldDouble Object stored in this Study"
- return None
- else:
- print "ERROR: No FieldDouble Object stored in this Study"
- return None
-
-#==============================================================================
-
-studyname = salome.myStudyName
-studynameId = salome.myStudyId
+#============================================================================
+# File : PYCALCULATOR_TEST.py
+# Author : Vadim SANDLER, OPEN CASCADE S.A.S. (vadim.sandler@opencascade.com)
+#============================================================================
-print "We are working in the study ",studyname," with the ID ",studynameId
-print ""
-
-filePath=os.environ["MED_ROOT_DIR"]
-filePath=filePath+"/share/salome/resources/med/"
-medFile=filePath+"pointe.med"
-fieldname = "fieldcelldoublevector"
-
-print "Load the Med Component "
-med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
-
-try:
- fieldcell = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
-except SALOME.SALOME_Exception, ex:
- print ex.details
- print ex.details.type
- print ex.details.text
- print ex.details.sourceFile
- print ex.details.lineNumber
- raise
-
-print fieldcell
-print fieldcell.getName()
-print fieldcell.getDescription()
-print fieldcell.getNumberOfComponents()
-
-
-AnalyzeField(fieldcell)
-
-
-
-print "Loading of the CalculatorPy Component "
-calculator = salome.lcc.FindOrLoadComponent("FactoryServerPy", "PYCALCULATOR")
-print "calculator = ", calculator
-
-alpha = 2.0
-print "Multiplication of fieldcelldouble by alpha"
-fieldcellalpha = calculator.Mul(fieldcell,alpha)
-print fieldcellalpha
-AnalyzeField(fieldcellalpha)
-
-print "Adding of alpha*fieldcelldouble and fieldcelldouble"
-fieldcelladd = calculator.Add(fieldcell,fieldcellalpha)
-print fieldcelladd
-AnalyzeField(fieldcelladd)
-
-print "Put fieldcelladd in study"
-fieldcelladd.addInStudy(salome.myStudy,fieldcelladd)
-
-print "update Salome GUI"
-salome.sg.updateObjBrowser(1)
+import os
-print "Get back Field from study"
-# we grab the second field in MEDFIELD - first iteration
-fieldcelldouble = getFieldDoubleObjectFromStudy(1,1)
-print fieldcelldouble
-AnalyzeField(fieldcelldouble)
+import salome
+salome.salome_init()
+import PYCALCULATOR_ORB
-print "Fin du test PYCALCULATOR"
+from MEDCouplingCorba import *
+from MEDCoupling import *
+from MEDLoader import *
+from MEDCouplingClient import *
+
+pc = salome.lcc.FindOrLoadComponent('FactoryServer','PYCALCULATOR')
+
+medFile = os.path.join(os.getenv("DATA_DIR"), "MedFiles", "pointe.med")
+meshName = "maa1"
+fieldName = "fieldcelldoublevector"
+print medFile, meshName, fieldName
+
+f = MEDLoader.ReadFieldCell(medFile, meshName, 0, fieldName, -1, -1)
+forig = MEDCouplingFieldDoubleServant._this(f)
+
+fcopy = pc.Clone(forig)
+f1 = pc.Add(forig, fcopy)
+f2 = pc.Mul(forig, fcopy)
+f3 = pc.AddConstant(forig, 3.5)
+f4 = pc.MulConstant(forig, 3.5)
+
+clt_forig = MEDCouplingFieldDoubleClient.New(forig)
+clt_fcopy = MEDCouplingFieldDoubleClient.New(fcopy)
+clt_f1 = MEDCouplingFieldDoubleClient.New(f1)
+clt_f2 = MEDCouplingFieldDoubleClient.New(f2)
+clt_f3 = MEDCouplingFieldDoubleClient.New(f3)
+clt_f4 = MEDCouplingFieldDoubleClient.New(f4)
+
+print "clt_forig:", clt_forig
+print "clt_fcopy:", clt_fcopy
+print "clt_f1:", clt_f1
+print "clt_f2:", clt_f2
+print "clt_f3:", clt_f3
+print "clt_f4:", clt_f4