- # On stocke dans l'attribut _naming_service, une reference sur
- # le Naming Service CORBA
- self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
- self.case = None
- self.wrapperDescription = ""
-
-######################################################################
-# This is the Wrapper part of the GENERICSOLVER module, ie
-# the three following methods are used by generic controlling
-# modules like OpenTURNS in order to launch a computation.
-# The interface is declared in GENERICSOLVER_Gen.idl. The methods
-# are free to call the legacy interface (see below).
-######################################################################
-
- def _raiseSalomeError(self):
- message = "Error in %s.%s" % (self.__class__.__name__, inspect.stack()[1][3])
- logger.exception(message)
- message += ". See logs of container %s for more details." % self._containerName
- exc = SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR, message,
- inspect.stack()[1][1], inspect.stack()[1][2])
- raise SALOME.SALOME_Exception(exc)
-
- def Init ( self, studyId, caseEntry, wrapperDescription ):
- """
- This method is an implementation for the GENERICSOLVER interface.
- It sets the component with some deterministic parametrization.
- """
- try:
- logger.info("GENERICSOLVER.Init: " + self._containerName + ' ; ' + self._instanceName)
- logger.debug("GENERICSOLVER.Init : enter")
- logger.debug("GENERICSOLVER.Init : studyId = %d - caseEntry = %s - wrapperDescription = %s" % ( studyId, caseEntry, wrapperDescription ))
- self.wrapperDescription = wrapperDescription
- GENERICSOLVER.lock.acquire()
- salome.salome_init()
- GENERICSOLVER.lock.release()
-
- self.case = GetDataFromCase( studyId, caseEntry )
- if self.case is None:
- return 1
- logger.debug("GENERICSOLVER.Init : exit")
- return 0
- except:
- self._raiseSalomeError()
-
- def Exec ( self , inPoint ):
- """
- This method is an implementation for the GENERICSOLVER interface.
- It runs the component with some new parameters compared with the deterministic ones.
- """
- try:
- logger.info("GENERICSOLVER.Exec: " + self._containerName + ' ; ' + self._instanceName)
- if self.case is None :
- logger.error("GENERICSOLVER.Exec : Init not run")
- return 1, None
-
- logger.debug("GENERICSOLVER.Exec (1): inPoint = %s" % inPoint)
- case = dict( self.case )
- if self.wrapperDescription != "":
- import sys
- logger.debug("sys.path = %s" % sys.path)
- import openturns.wrapper
- wrapper = openturns.wrapper.WrapperFile.BuildWrapperFromStream( self.wrapperDescription )
- data = wrapper.getWrapperData()
- variableList = data.getVariableList()
- i = 0
- for idx in range( variableList.getSize() ):
- variable = variableList[ idx ]
- if variable.type_ == 0:
- logger.debug("variable %s <-> index %d" % ( variable.id_, i ))
- case[ variable.id_ ] = inPoint[ i ]
- i += 1
-
- logger.debug("Case = %s" % case)
- logger.info("Evaluating case by component %s in container %s" %
- (self._instanceName, self._containerName))
- outPoint = self.BeamModel( **case )
-
- logger.debug("GENERICSOLVER.Exec (2): inPoint = %s" % inPoint)
- logger.debug("GENERICSOLVER.Exec (2): outPoint = %s" % outPoint)
- return 0, outPoint
-
- except:
- self._raiseSalomeError()
-
- def Finalize ( self ):
- """
- This method is an implementation for the GENERICSOLVER interface.
- It cleans everything set so far.
- """
- try:
- logger.info("GENERICSOLVER.Finalize: " + self._containerName + ' ; ' + self._instanceName)
- logger.debug("GENERICSOLVER.Finalize : enter")
- logger.debug("GENERICSOLVER.Finalize : exit")
- return 0
- except:
- self._raiseSalomeError()
-
-######################################################################
-# This is the computation part of the GENERICSOLVER module, ie
-# the following method realizes what the solver is intended to do.
-# The interface of this method (and maybe other ones) is absolutely
-# free and depends on the module (legacy interface).
-######################################################################
-
- def BeamModel ( self , E=1., F=0., L=0., I=1. ):
- """
- This method implements a beam bending model based on the following formula:
- deviation = ( Force * Length^3 ) / ( 3 * YoungModulus * InertiaSection )
- """
- d = ( F * L*L*L ) / ( 3. * E * I )
- logger.debug("GENERICSOLVER.BeamModel (E=%g, F=%g, L=%g, I=%g) = %g" % (E,F,L,I,d))
-
- return (d,)
-
-
-
- def InitWithVarList(self, inputVarList, outputVarList, deterministicVars):
- """
- This method is an example for the initialization of a computation component for
- use with OpenTURNS in SALOME 5.1.5 and later (for YACS integration)
- """
- try:
- logger.info("GENERICSOLVER.InitWithVarList: " + self._containerName +
- ' ; ' + self._instanceName)
- import cPickle
- self.inputVarList = inputVarList
- self.outputVarList = outputVarList
- self.evalPoint = cPickle.loads(deterministicVars)
- logger.debug("inputVarList: %s" % self.inputVarList)
- logger.debug("outputVarList: %s" % self.outputVarList)
- logger.debug("evalPoint: %s" % self.evalPoint)
- except:
- self._raiseSalomeError()
-
- def ExecWithVarList(self, inPoint):
- """
- This method is an example for the execution of a computation component for
- use with OpenTURNS in SALOME 5.1.5 and later (for YACS integration)
- """
- try:
- logger.info("GENERICSOLVER.ExecWithVarList: " + self._containerName +
- ' ; ' + self._instanceName)
- if self.inputVarList is None:
- raise Exception("InitWithVarList not run")
- if len(inPoint) != len(self.inputVarList):
- raise Exception("Size mismatch between inputVarList and point to evaluate")
-
- logger.debug("GENERICSOLVER.ExecWithVarList (1): inPoint = %s" % inPoint)
- for i in range(len(self.inputVarList)):
- self.evalPoint[self.inputVarList[i]] = inPoint[i]
- logger.debug("evalPoint = %s" % self.evalPoint)
-
- (dev,) = self.BeamModel(**self.evalPoint)
-
- outPoint = []
- for outputVar in self.outputVarList:
- outPoint.append(eval(outputVar))
- logger.debug("GENERICSOLVER.ExecWithVarList (2): outPoint = %s" % outPoint)
- return outPoint
- except:
- self._raiseSalomeError()