/[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 3891 by jfenwick, Thu Mar 1 05:34:52 2012 UTC revision 3892 by jfenwick, Tue Apr 10 08:57:23 2012 UTC
# Line 33  Environment for implementing models in e Line 33  Environment for implementing models in e
33  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
34    
35    
 from types import StringType,IntType,FloatType,BooleanType,ListType,DictType  
36  import sys  import sys
37  import numpy  import numpy
38  import operator  import operator
# Line 93  class ESySXMLParser(object): Line 92  class ESySXMLParser(object):
92      def __init__(self,xml, debug=False):      def __init__(self,xml, debug=False):
93          if sys.version_info[0]<3:          if sys.version_info[0]<3:
94              xml=str(xml)    # xml might be unicode              xml=str(xml)    # xml might be unicode
95          print("\n")          #print("\n")
96          print(type(xml))          #print(type(xml))
97          print(xml)          #print(xml)
98          print("\n")          #print("\n")
99          self.__dom = minidom.parseString(xml)          self.__dom = minidom.parseString(xml)
100          self.__linkable_object_registry= {}          self.__linkable_object_registry= {}
101          self.__link_registry=  []          self.__link_registry=  []
# Line 356  class LinkableObject(object): Line 355  class LinkableObject(object):
355          If debugging is on, prints the message, otherwise does nothing.          If debugging is on, prints the message, otherwise does nothing.
356          """          """
357          if self.debug:          if self.debug:
358              print(("%s: %s"%(str(self),msg)))              print("%s: %s"%(str(self),msg))
359    
360      def __getattr__(self,name):      def __getattr__(self,name):
361          """          """
# Line 494  class ParameterSet(LinkableObject): Line 493  class ParameterSet(LinkableObject):
493          Declares a set of parameters. parameters can be a list, a dictionary          Declares a set of parameters. parameters can be a list, a dictionary
494          or a ParameterSet.          or a ParameterSet.
495          """          """
496          if isinstance(parameters,ListType):          if isinstance(parameters,type([])):
497              parameters = list(zip(parameters, itertools.repeat(None)))              parameters = list(zip(parameters, itertools.repeat(None)))
498          if isinstance(parameters,DictType):          if isinstance(parameters,type(dict())):
499              parameters = iter(list(parameters.items()))              parameters = iter(list(parameters.items()))
500    
501          for prm, value in parameters:          for prm, value in parameters:
# Line 734  class ParameterSet(LinkableObject): Line 733  class ParameterSet(LinkableObject):
733          try:          try:
734             o = cls(debug=esysxml.debug)             o = cls(debug=esysxml.debug)
735          except TypeError as inst:          except TypeError as inst:
736             print((inst.args[0]))             print(inst.args[0])
737             if inst.args[0]=="__init__() got an unexpected keyword argument 'debug'":             if inst.args[0]=="__init__() got an unexpected keyword argument 'debug'":
738                raise TypeError("The Model class %s __init__ needs to have argument 'debug'.")                raise TypeError("The Model class %s __init__ needs to have argument 'debug'.")
739             else:             else:
# Line 1211  class Simulation(Model): Line 1210  class Simulation(Model):
1210              if isinstance(n, minidom.Text):              if isinstance(n, minidom.Text):
1211                  continue                  continue
1212              sims.append(esysxml.getComponent(n))              sims.append(esysxml.getComponent(n))
1213          sims.sort(_comp)          sims.sort(key=_cmpkey)
1214          sim=cls([s[1] for s in sims], debug=esysxml.debug)          sim=cls([s[1] for s in sims], debug=esysxml.debug)
1215          esysxml.registerLinkableObject(sim, node)          esysxml.registerLinkableObject(sim, node)
1216          return sim          return sim
1217    
1218      fromDom = classmethod(fromDom)      fromDom = classmethod(fromDom)
1219    
1220    def _cmpkey(a):
1221        return a[0]
1222    
1223  def _comp(a,b):  def _comp(a,b):
1224      if a[0]<a[1]:      if a[0]<a[1]:
1225          return 1          return 1

Legend:
Removed from v.3891  
changed lines
  Added in v.3892

  ViewVC Help
Powered by ViewVC 1.1.26