Esempio n. 1
0
 def _readMoreXML(self,xmlNode):
   """
     Function to read the portion of the xml input that belongs to this
     specialized class and initialize some variables based on the inputs
     received.
     @ In, xmlNode, xml.etree.ElementTree.Element, XML element node that represents the portion of the input that belongs to this class
     @ Out, None
   """
   if 'file' in xmlNode.attrib.keys():
     self.functionFile = xmlNode.attrib['file']
     # get the module to load and the filename without path
     moduleToLoadString, self.functionFile = utils.identifyIfExternalModelExists(self, self.functionFile, self.workingDir)
     # import the external function
     importedModule = utils.importFromPath(moduleToLoadString,self.messageHandler.getDesiredVerbosity(self)>1)
     if not importedModule:
       self.raiseAnError(IOError,'Failed to import the module '+moduleToLoadString+' supposed to contain the function: '+self.name)
     #here the methods in the imported file are brought inside the class
     for method in importedModule.__dict__.keys():
       if method in ['__residuumSign__','__residuumSign','residuumSign',
                     '__supportBoundingTest__','__supportBoundingTest','supportBoundingTest',
                     '__residuum__','__residuum','residuum','__gradient__','__gradient','gradient']:
         if method in ['__residuumSign__','__residuumSign','residuumSign']:
           self.__residuumSign                                =  importedModule.__dict__[method]
           self.__actionDictionary['residuumSign' ]           = self.__residuumSign
           self.__actionImplemented['residuumSign']           = True
         if method in ['__supportBoundingTest__','__supportBoundingTest','supportBoundingTest']:
           self.__supportBoundingTest                         =  importedModule.__dict__[method]
           self.__actionDictionary['supportBoundingTest' ]    = self.__supportBoundingTest
           self.__actionImplemented['supportBoundingTest']    = True
         if method in ['__residuum__','__residuum','residuum']:
           self.__residuum                                    =  importedModule.__dict__[method]
           self.__actionDictionary['residuum' ]               = self.__residuum
           self.__actionImplemented['residuum']               = True
         if method in ['__gradient__','__gradient','gradient']:
           self.__gradient                                    =  importedModule.__dict__[method]
           self.__actionDictionary['gradient']                = self.__gradient
           self.__actionImplemented['gradient']               = True
       else:
         #custom
         self.__actionDictionary[method]                    = importedModule.__dict__[method]
         self.__actionImplemented[method]                   = True
   else:
     self.raiseAnError(IOError,'No file name for the external function has been provided for external function '+self.name+' of type '+self.type)
   cnt = 0
   for child in xmlNode:
     if child.tag=='variable':
       execCommand('self.'+child.text+' = None',self=self)
       self.__inputVariables.append(child.text)
       cnt +=1
       if len(child.attrib.keys()) > 0:
         self.raiseAnError(IOError,'variable block in the definition of the function '+self.name + ' should not have any attribute!')
   if cnt == 0:
     self.raiseAnError(IOError,'not variable found in the definition of the function '+self.name)
Esempio n. 2
0
 def _handleInput(self, paramInput):
     """
   Method to handle the External Function parameter input.
   @ In, paramInput, InputData.ParameterInput, the already parsed input.
   @ Out, None
 """
     self.functionFile = paramInput.parameterValues["file"]
     # get the module to load and the filename without path
     moduleToLoadString, self.functionFile = utils.identifyIfExternalModelExists(
         self, self.functionFile, self.workingDir)
     # import the external function
     importedModule = utils.importFromPath(
         moduleToLoadString,
         self.messageHandler.getDesiredVerbosity(self) > 1)
     if not importedModule:
         self.raiseAnError(
             IOError, 'Failed to import the module ' + moduleToLoadString +
             ' supposed to contain the function: ' + self.name)
     #here the methods in the imported file are brought inside the class
     for method, action in importedModule.__dict__.items():
         if method in [
                 '__residuumSign__', '__residuumSign', 'residuumSign',
                 '__supportBoundingTest__', '__supportBoundingTest',
                 'supportBoundingTest', '__residuum__', '__residuum',
                 'residuum', '__gradient__', '__gradient', 'gradient'
         ]:
             if method in [
                     '__residuumSign__', '__residuumSign', 'residuumSign'
             ]:
                 self.__actionDictionary['residuumSign'] = action
                 self.__actionImplemented['residuumSign'] = True
             if method in [
                     '__supportBoundingTest__', '__supportBoundingTest',
                     'supportBoundingTest'
             ]:
                 self.__actionDictionary['supportBoundingTest'] = action
                 self.__actionImplemented['supportBoundingTest'] = True
             if method in ['__residuum__', '__residuum', 'residuum']:
                 self.__actionDictionary['residuum'] = action
                 self.__actionImplemented['residuum'] = True
             if method in ['__gradient__', '__gradient', 'gradient']:
                 self.__actionDictionary['gradient'] = action
                 self.__actionImplemented['gradient'] = True
         else:
             #custom
             self.__actionDictionary[method] = action
             self.__actionImplemented[method] = True
     # get variables
     self.__inputVariables = paramInput.findFirst("variables").value
     # initialize variables
     for var in self.__inputVariables:
         execCommand('self.' + var + ' = None', self=self)
Esempio n. 3
0
 def __inputFromDict(self,myInputDict):
   """
     This is meant to be used to collect the input directly from a sampler generated input or simply from a generic dictionary
     In case the input comes from a sampler the expected structure is myInputDict['SampledVars'][variable name] = value
     In case it is a generic dictionary the expected structure is myInputDict[variable name] = value
     @ In, myInputDict, dict, dict from which the data need to be imported
     @ Out, None
   """
   if 'SampledVars' in myInputDict.keys(): inDict = myInputDict['SampledVars']
   else                                  : inDict = myInputDict
   for name in self.__inputVariables:
     if name in inDict.keys(): execCommand('self.'+name+'=object["'+name+'"]',self=self,object=inDict)
     else                    : self.raiseAnError(IOError,'The input variable '+name+' in external function seems not to be passed in')
Esempio n. 4
0
 def getCurrentSetting(self):
   """
     This function is called from the base class to print some of the information inside the class.
     Whatever is a temporary value in the class and not inherited from the parent class should be mentioned here
     The information is passed back in the dictionary
     Function adds the current settings in a temporary dictionary
     @ In, None
     @ Out, paramDict, dict, dictionary containing the parameter names as keys
       and each parameter's initial value as the dictionary values
   """
   paramDict = {}
   for key in self.__inputVariables:
     execCommand("object['variable "+str(key)+" has value']=self."+key,self=self,object=paramDict)
   return paramDict