/[escript]/trunk/escript/py_src/modelframe.py
ViewVC logotype

Diff of /trunk/escript/py_src/modelframe.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/py_src/modelframe.py revision 149 by jgs, Thu Sep 1 03:31:39 2005 UTC trunk/escript/py_src/modelframe.py revision 266 by elspeth, Wed Nov 30 00:21:51 2005 UTC
# Line 73  def parse(xml): Line 73  def parse(xml):
73    
74      return sim      return sim
75    
76    def importName(modulename, name):
77        """ Import a named object from a module in the context of this function,
78            which means you should use fully qualified module paths.
79            
80            Return None on failure.
81    
82            This function from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52241
83        """
84        module = __import__(modulename, globals(), locals(), [name])
85            
86        try:
87            return vars(module)[name]
88        except KeyError:
89            raise ImportError("Could not import %s from %s" % (name, modulename))
90    
91  def getComponent(doc):  def getComponent(doc):
92      """      """
93      Used to get components of Simualtions, Models.      Used to get components of Simualtions, Models.
# Line 84  def getComponent(doc): Line 99  def getComponent(doc):
99                  if node.getAttribute("type") == 'Simulation':                  if node.getAttribute("type") == 'Simulation':
100                      return Simulation.fromDom(node)                      return Simulation.fromDom(node)
101              if node.tagName == 'Model':              if node.tagName == 'Model':
102                  model_type = node.getAttribute("type")                  if (node.getAttribute("module")):
103                  model_subclasses = Model.__subclasses__()                      model_module = node.getAttribute("module")
104                  for model in model_subclasses:                      model_type = node.getAttribute("type")
105                      if model_type == model.__name__:                      return importName(model_module, model_type).fromDom(node)
106                          return Model.fromDom(node)                  else:
107                        model_type = node.getAttribute("type")
108                        model_subclasses = Model.__subclasses__()
109                        for model in model_subclasses:
110                            if model_type == model.__name__:
111                                return Model.fromDom(node)
112              if node.tagName == 'ParameterSet':              if node.tagName == 'ParameterSet':
113                  parameter_type = node.getAttribute("type")                  parameter_type = node.getAttribute("type")
114                  return ParameterSet.fromDom(node)                  return ParameterSet.fromDom(node)
# Line 467  class ParameterSet(LinkableObject): Line 487  class ParameterSet(LinkableObject):
487    
488          def _boolfromValue(doc):          def _boolfromValue(doc):
489              return bool(doc.nodeValue.strip())              return bool(doc.nodeValue.strip())
490    
491            def _nonefromValue(doc):
492                return None
493                
494          # Mapping from text types in the xml to methods used to process trees of that type          # Mapping from text types in the xml to methods used to process trees of that type
495          ptypemap = {"Simulation": Simulation.fromDom,          ptypemap = {"Simulation": Simulation.fromDom,
# Line 477  class ParameterSet(LinkableObject): Line 500  class ParameterSet(LinkableObject):
500                      "int":_intfromValue,                      "int":_intfromValue,
501                      "str":_stringfromValue,                      "str":_stringfromValue,
502                      "bool":_boolfromValue                      "bool":_boolfromValue
503                        "NoneType":_nonefromValue,
504                      }                      }
505    
506  #        print doc.toxml()  #        print doc.toxml()
# Line 555  class Model(ParameterSet): Line 579  class Model(ParameterSet):
579      """      """
580          pset = document.createElement('Model')          pset = document.createElement('Model')
581          pset.setAttribute('type', self.__class__.__name__)          pset.setAttribute('type', self.__class__.__name__)
582            if not self.__class__.__module__.startswith('esys.escript'):
583                pset.setAttribute('module', self.__class__.__module__)
584          node.appendChild(pset)          node.appendChild(pset)
585          self._parametersToDom(document, pset)          self._parametersToDom(document, pset)
586    
# Line 733  class Simulation(Model): Line 759  class Simulation(Model):
759          This is the minimum over the time step sizes of all models.          This is the minimum over the time step sizes of all models.
760      """      """
761          out=min([o.getSafeTimeStepSize(dt) for o in self.iterModels()])          out=min([o.getSafeTimeStepSize(dt) for o in self.iterModels()])
762          print "%s: safe step size is %e."%(str(self),out)          #print "%s: safe step size is %e."%(str(self),out)
763          return out          return out
764            
765      def doInitialization(self):      def doInitialization(self):

Legend:
Removed from v.149  
changed lines
  Added in v.266

  ViewVC Help
Powered by ViewVC 1.1.26