/[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

revision 149 by jgs, Thu Sep 1 03:31:39 2005 UTC revision 150 by jgs, Thu Sep 15 03:44:45 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 555  class Model(ParameterSet): Line 575  class Model(ParameterSet):
575      """      """
576          pset = document.createElement('Model')          pset = document.createElement('Model')
577          pset.setAttribute('type', self.__class__.__name__)          pset.setAttribute('type', self.__class__.__name__)
578            if not self.__class__.__module__.startswith('esys.escript'):
579                pset.setAttribute('module', self.__class__.__module__)
580          node.appendChild(pset)          node.appendChild(pset)
581          self._parametersToDom(document, pset)          self._parametersToDom(document, pset)
582    
# Line 733  class Simulation(Model): Line 755  class Simulation(Model):
755          This is the minimum over the time step sizes of all models.          This is the minimum over the time step sizes of all models.
756      """      """
757          out=min([o.getSafeTimeStepSize(dt) for o in self.iterModels()])          out=min([o.getSafeTimeStepSize(dt) for o in self.iterModels()])
758          print "%s: safe step size is %e."%(str(self),out)          #print "%s: safe step size is %e."%(str(self),out)
759          return out          return out
760            
761      def doInitialization(self):      def doInitialization(self):

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

  ViewVC Help
Powered by ViewVC 1.1.26