--- /dev/null
+// Copyright (C) 2009-2010 EDF R&D
+//
+// 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// $Id$
+//
+
+#ifndef __DEVIATION_GEN__
+#define __DEVIATION_GEN__
+
+#include "SALOME_Component.idl"
+#include "SALOMEDS.idl"
+#include "SALOME_Exception.idl"
+
+module GENERICSOLVER_ORB
+{
+
+ typedef sequence<double> Point;
+ typedef SALOMEDS::ID ID;
+ typedef sequence<string> VarList;
+
+ interface DEVIATION_Gen : Engines::Component, SALOMEDS::Driver
+ {
+
+ /**
+ * @brief Initialize the component with the deterministic variables and the lists of
+ * probabilistic variables.
+ *
+ * The Init method prepares the component for a series of computation with
+ * the method Exec. It extracts the deterministic data from Salome study and
+ * stores this data along with the lists of input and output variables to
+ * identify them in future calls to Exec.
+ *
+ * @param inputVarList a list of strings containing the names of the input
+ * variables in the same order as in subsequent calls to Exec.
+ * @param outputVarList a list of strings containing the names of the output
+ * variables in the same order as they should be returned
+ * in subsequent calls to Exec.
+ * @param studyID the identifier of the study containing the deterministic data
+ * @param entry the identifier of the deterministic case within the study
+ */
+ void Init(in VarList inputVarList, in VarList outputVarList, in long studyID, in ID entry)
+ raises (SALOME::SALOME_Exception);
+
+ /**
+ * @brief Execute a computation with a given sample of variables.
+ *
+ * The Exec method realizes the computation with some parameters (within
+ * inPoint) corresponding to the variables set previously with the method
+ * Init. The result is put in outPoint in the order specified by
+ * outputVarList of Init method.
+ *
+ * @param inPoint a vector of floating point values to be evaluated
+ * @param outPoint the result of the computation as a vector of floating point values
+ */
+ void Exec(in Point inPoint, out Point outPoint)
+ raises (SALOME::SALOME_Exception);
+
+ /**
+ * @brief Cleanup everything that was previously set
+ *
+ * The Finalize method is in charge of cleaning everything that what set hitherto.
+ * It may be empty.
+ */
+ void Finalize()
+ raises (SALOME::SALOME_Exception);
+
+ };
+};
+
+#endif
typedef sequence<double> Point;
typedef SALOMEDS::ID ID;
- typedef sequence<string> VarList;
- typedef Engines::fileBlock pyobj;
interface GENERICSOLVER_Gen : Engines::Component, SALOMEDS::Driver
{
long Finalize()
raises (SALOME::SALOME_Exception);
-
- /**
- * @brief Initialize the component with the deterministic variables and the lists of
- * probabilistic variables.
- *
- * The InitWithVarList method prepares the component for a series of computation
- * with the method ExecWithVarList. It stores the deterministic variables and the
- * lists of input and output variables to identify them in future calls to
- * ExecWithVarList.
- *
- * @param inputVarList a list of strings containing the names of the input
- * variables in the same order as in subsequent calls to
- * ExecWithVarList.
- * @param outputVarList a list of strings containing the names of the output
- * variables in the same order as they should be returned
- * in subsequent calls to ExecWithVarList.
- * @param deterministicVars a python dictionary containing the deterministic
- * variables (mapping variable names to variable values)
- */
- void InitWithVarList(in VarList inputVarList, in VarList outputVarList, in pyobj deterministicVars)
- raises (SALOME::SALOME_Exception);
-
- /**
- * @brief Execute a computation with a given sample of variables.
- *
- * The ExecWithVarList method realizes the computation with some parameters (within
- * inPoint) corresponding to the variables set previously with the method
- * InitWithVarList. The result is put in outPoint in the order specified by
- * outputVarList of InitWithVarList method.
- *
- * @param inPoint a vector of floating point values to be evaluated
- * @param outPoint the result of the computation as a vector of floating point values
- */
- void ExecWithVarList(in Point inPoint, out Point outPoint)
- raises (SALOME::SALOME_Exception);
-
};
};
#
include $(top_srcdir)/adm_local/unix/make_common_starter.am
-BASEIDL_FILES = GENERICSOLVER_Gen.idl
+BASEIDL_FILES = GENERICSOLVER_Gen.idl DEVIATION_Gen.idl
# This variable defines the files to be installed
dist_salomeidl_DATA = $(BASEIDL_FILES)
</outParameter>
</outParameter-list>
</component-service>
+ </component-service-list>
+ </component-interface-list>
+ </component>
+ <component>
+ <!-- Component identification -->
+ <component-name>DEVIATION</component-name>
+ <component-username>DEVIATION GUI</component-username>
+ <component-type>Data</component-type>
+ <component-author>R. Barate</component-author>
+ <component-version>@VERSION@</component-version>
+ <component-comment>EDF - RD</component-comment>
+ <component-multistudy>1</component-multistudy>
+ <component-icone>GENERICSOLVER.png</component-icone>
+ <constraint>'linux' ~ OS</constraint>
+ <component-interface-list>
+ <component-interface-name>DEVIATION</component-interface-name>
+ <component-interface-comment></component-interface-comment>
+ <component-service-list>
<component-service>
<!-- service-identification -->
- <service-name>InitWithVarList</service-name>
+ <service-name>Init</service-name>
<service-author>EDF-RD</service-author>
<service-version>@VERSION@</service-version>
<service-comment></service-comment>
<inParameter-type>stringvec</inParameter-type>
</inParameter>
<inParameter>
- <inParameter-name>deterministicVars</inParameter-name>
- <inParameter-type>pyobj</inParameter-type>
+ <inParameter-name>studyID</inParameter-name>
+ <inParameter-type>long</inParameter-type>
+ </inParameter>
+ <inParameter>
+ <inParameter-name>entry</inParameter-name>
+ <inParameter-type>string</inParameter-type>
</inParameter>
</inParameter-list>
</component-service>
<component-service>
<!-- service-identification -->
- <service-name>ExecWithVarList</service-name>
+ <service-name>Exec</service-name>
<service-author>EDF-RD</service-author>
<service-version>@VERSION@</service-version>
<service-comment></service-comment>
</outParameter>
</outParameter-list>
</component-service>
+ <component-service>
+ <!-- service-identification -->
+ <service-name>Finalize</service-name>
+ <service-author>EDF-RD</service-author>
+ <service-version>@VERSION@</service-version>
+ <service-comment></service-comment>
+ <service-by-default>0</service-by-default>
+ </component-service>
</component-service-list>
</component-interface-list>
</component>
--- /dev/null
+# Copyright (C) 2009-2010 EDF R&D
+#
+# 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.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# $Id$
+#
+
+import logging
+import threading
+import inspect
+import traceback
+
+import salome
+import GENERICSOLVER_ORB__POA
+import SALOME_ComponentPy
+import SALOME_DriverPy
+import SALOME
+
+from pal.logger import Logger
+from pal import termcolor
+logger = Logger("DEVIATION", color = termcolor.RED_FG)
+logger.setLevel(logging.INFO)
+
+VARIABLE_ID = 1030
+
+###
+# Retrieve data from selected case
+###
+def GetDataFromCase( studyId, caseEntry ):
+ theCase = {}
+ study = salome.myStudyManager.GetStudyByID( studyId )
+ case = study.FindObjectID( caseEntry )
+ builder = study.NewBuilder()
+ # Get the values of the variables and make them a list
+ for name in ("E", "F", "L", "I"):
+ var = getSubSObjectByName( studyId, case, name )
+ if var == None:
+ logger.error("GENERICSOLVER.GetDataFromCase : ERROR! no variable '%s'" % name)
+ break
+ theCase[ name ] = getValueOfVariable( builder, var )
+ return theCase
+
+###
+# Plays with study
+###
+
+def getValueOfVariable( builder, varobj ):
+ attr = builder.FindOrCreateAttribute( varobj, "AttributeLocalID" )
+ objid = attr.Value()
+ if (objid == VARIABLE_ID):
+ attr = builder.FindOrCreateAttribute( varobj, "AttributeReal" )
+ return attr.Value()
+ else:
+ attr = builder.FindOrCreateAttribute( varobj, "AttributeName" )
+ QMessageBox.information( sgPyQt.getDesktop(), 'Info', "Object '%s' isn't a variable. Can't set value." % attr.Value() )
+ return 0.
+
+def getSubSObjectByName( studyId, sobjFather, childName ):
+ logger.debug("GENERICSOLVER.getSubSObjectByName Looking for sobjet named " + childName)
+ study = salome.myStudyManager.GetStudyByID( studyId )
+ iter = study.NewChildIterator( sobjFather )
+ #builder = study.NewBuilder()
+ while iter.More():
+ sobj = iter.Value()
+ logger.debug("GENERICSOLVER.getSubSObjectByName Got sobjet named " + sobj.GetName())
+ if sobj.GetName() == childName:
+ return sobj
+ iter.Next()
+ pass
+ return None
+
+################################################
+
+class DEVIATION(GENERICSOLVER_ORB__POA.DEVIATION_Gen,
+ SALOME_ComponentPy.SALOME_ComponentPy_i,
+ SALOME_DriverPy.SALOME_DriverPy_i):
+
+ lock = threading.Lock()
+
+ """
+ Pour etre un composant SALOME cette classe Python
+ doit avoir le nom du composant et heriter de la
+ classe DEVIATION_Gen issue de la compilation de l'idl
+ par omniidl et de la classe SALOME_ComponentPy_i
+ qui porte les services generaux d'un composant SALOME
+ """
+ def __init__ ( self, orb, poa, contID, containerName, instanceName,
+ interfaceName ):
+ logger.info("DEVIATION.__init__: " + containerName + ' ; ' + instanceName)
+ SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
+ contID, containerName, instanceName, interfaceName, 0)
+ SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
+ # 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.inputVarList = None
+ self.outputVarList = None
+ self.evalPoint = None
+
+######################################################################
+# 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 component %s running in container %s." % (self._instanceName, self._containerName)
+ logger.exception(message)
+ message += " " + traceback.format_exc()
+ exc = SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR, message,
+ inspect.stack()[1][1], inspect.stack()[1][2])
+ raise SALOME.SALOME_Exception(exc)
+
+ def Init(self, inputVarList, outputVarList, studyId, caseEntry):
+ """
+ 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("DEVIATION.Init: " + self._containerName +
+ ' ; ' + self._instanceName)
+ self.inputVarList = inputVarList
+ self.outputVarList = outputVarList
+ self.evalPoint = GetDataFromCase(studyId, caseEntry)
+ logger.debug("inputVarList: %s" % self.inputVarList)
+ logger.debug("outputVarList: %s" % self.outputVarList)
+ logger.debug("evalPoint: %s" % self.evalPoint)
+ except:
+ self._raiseSalomeError()
+
+ def Exec(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("DEVIATION.Exec: " + self._containerName +
+ ' ; ' + self._instanceName)
+ if self.inputVarList is None:
+ raise Exception("Init not run")
+ if len(inPoint) != len(self.inputVarList):
+ raise Exception("Size mismatch between inputVarList and point to evaluate")
+
+ logger.debug("DEVIATION.Exec (1): inPoint = %s" % inPoint)
+ for i in range(len(self.inputVarList)):
+ self.evalPoint[self.inputVarList[i]] = inPoint[i]
+ logger.debug("evalPoint = %s" % self.evalPoint)
+
+ resDict = {}
+ resDict["dev"] = self.BeamModel(**self.evalPoint)
+
+ outPoint = []
+ for outputVar in self.outputVarList:
+ outPoint.append(resDict[outputVar])
+ logger.debug("DEVIATION.Exec (2): outPoint = %s" % outPoint)
+ return outPoint
+ except:
+ self._raiseSalomeError()
+
+ def Finalize(self):
+ """
+ This method is an implementation for the DEVIATION interface.
+ It cleans everything set so far.
+ """
+ try:
+ logger.info("DEVIATION.Finalize: " + self._containerName + ' ; ' + self._instanceName)
+ 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, F, L, I):
+ """
+ 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("DEVIATION.BeamModel (E=%g, F=%g, L=%g, I=%g) = %g" % (E, F, L, I, d))
+ return d
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)
-
- resDict = {}
- (resDict["dev"],) = self.BeamModel(**self.evalPoint)
-
- outPoint = []
- for outputVar in self.outputVarList:
- outPoint.append(resDict[outputVar])
- logger.debug("GENERICSOLVER.ExecWithVarList (2): outPoint = %s" % outPoint)
- return outPoint
- except:
- self._raiseSalomeError()
# Scripts to be installed
dist_salomescript_SCRIPTS = \
- GENERICSOLVER.py
+ GENERICSOLVER.py \
+ DEVIATION.py