- # 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.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:
- 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.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.Exec (2): BeamModel (E=%g, F=%g, L=%g, I=%g) = %g" % (E,F,L,I,d))
-
- return (d,)