/[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 926 by gross, Fri Jan 12 06:31:37 2007 UTC revision 964 by gross, Tue Feb 13 05:10:26 2007 UTC
# Line 71  class ESySXMLParser(object): Line 71  class ESySXMLParser(object):
71        self.__dom = minidom.parseString(xml)        self.__dom = minidom.parseString(xml)
72        self.__linkable_object_registry= {}        self.__linkable_object_registry= {}
73        self.__link_registry=  []        self.__link_registry=  []
74        self.__esys=self.__dom.firstChild        self.__esys=self.__dom.getElementsByTagName('ESys')[0]
75        self.debug=debug        self.debug=debug
76        
77      def getClassPath(self, node):      def getClassPath(self, node):
# Line 214  class Link: Line 214  class Link:
214          self.attribute = None          self.attribute = None
215          self.setAttributeName(attribute)          self.setAttributeName(attribute)
216    
217        def getTarget(self):
218            """
219            returns the target
220            """
221            return self.target
222      def getAttributeName(self):      def getAttributeName(self):
223          """          """
224          returns the name of the attribute the link is pointing to          returns the name of the attribute the link is pointing to
# Line 462  class ParameterSet(LinkableObject): Line 467  class ParameterSet(LinkableObject):
467              setattr(self,prm,value)              setattr(self,prm,value)
468              self.parameters.add(prm)              self.parameters.add(prm)
469    
             self.trace("parameter %s has been declared."%prm)  
   
470      def releaseParameters(self,name):      def releaseParameters(self,name):
471          """          """
472      Removes parameter name from the paramameters.      Removes parameter name from the paramameters.
# Line 471  class ParameterSet(LinkableObject): Line 474  class ParameterSet(LinkableObject):
474          if self.isParameter(name):          if self.isParameter(name):
475              self.parameters.remove(name)              self.parameters.remove(name)
476              self.trace("parameter %s has been removed."%name)              self.trace("parameter %s has been removed."%name)
477    
478        def checkLinkTargets(self, models, hash):
479            """
480            returns a set of tuples ("<self>(<name>)", <target model>) if the parameter <name> is linked to model <target model>
481            but <target model> is not in the list models. If the a parameter is linked to another parameter set which is not in the hash list
482            the parameter set is checked for its models. hash gives the call history.
483            """
484            out=set()
485            for name, value in self:
486                if isinstance(value, Link):
487                   m=value.getTarget()
488                   if isinstance(m, Model):
489                       if not m in models: out.add( (str(self)+"("+name+")",m) )
490                   elif isinstance(m, ParameterSet) and not m in hash:
491                         out|=set( [ (str(self)+"("+name+")."+f[0],f[1]) for f in m.checkLinkTargets(models, hash+[ self ] ) ] )
492            return out
493            
494      def __iter__(self):      def __iter__(self):
495          """          """
# Line 522  class ParameterSet(LinkableObject): Line 541  class ParameterSet(LinkableObject):
541                  for i in value:                  for i in value:
542                      if isinstance(i, bool):                      if isinstance(i, bool):
543                          elem_type = max(elem_type,0)                          elem_type = max(elem_type,0)
544                      if isinstance(i, int) and not isinstance(i, bool):                      elif isinstance(i, int):
545                          elem_type = max(elem_type,1)                          elem_type = max(elem_type,1)
546                      if isinstance(i, float):                      elif isinstance(i, float):
547                          elem_type = max(elem_type,2)                          elem_type = max(elem_type,2)
548                  if elem_type == 0: value = numarray.array(value,numarray.Bool)                  if elem_type == 0: value = numarray.array(value,numarray.Bool)
549                  if elem_type == 1: value = numarray.array(value,numarray.Int)                  if elem_type == 1: value = numarray.array(value,numarray.Int)
# Line 582  class ParameterSet(LinkableObject): Line 601  class ParameterSet(LinkableObject):
601                      dic.appendChild(i)                      dic.appendChild(i)
602                   param.appendChild(dic)                   param.appendChild(dic)
603              else:              else:
                 print value  
604                  raise ValueError("cannot serialize %s type to XML."%str(value.__class__))                  raise ValueError("cannot serialize %s type to XML."%str(value.__class__))
605    
606              node.appendChild(param)              node.appendChild(param)
# Line 844  class Simulation(Model): Line 862  class Simulation(Model):
862      Initiates a simulation from a list of models.      Initiates a simulation from a list of models.
863      """      """
864          super(Simulation, self).__init__(**kwargs)          super(Simulation, self).__init__(**kwargs)
865            for m in models:
866                if not isinstance(m, Model):
867                     raise TypeError("%s is not a subclass of Model."%m)
868          self.__models=[]          self.__models=[]
           
869          for i in range(len(models)):          for i in range(len(models)):
870              self[i] = models[i]              self[i] = models[i]
871                            
# Line 890  class Simulation(Model): Line 910  class Simulation(Model):
910      """      """
911          return len(self.__models)          return len(self.__models)
912    
913        def getAllModels(self):
914            """
915            returns a list of all models used in the Simulation including subsimulations
916            """
917            out=[]
918            for m in self.iterModels():
919                if isinstance(m, Simulation):
920                   out+=m.getAllModels()
921                else:
922                   out.append(m)
923            return list(set(out))
924    
925        def checkModels(self, models, hash):
926            """
927            returns a list of (model,parameter, target model ) if the the parameter of model
928            is linking to the target_model which is not in list of models.
929            """
930            out=self.checkLinkTargets(models, hash + [self])
931            for m in self.iterModels():
932                if isinstance(m, Simulation):
933                     out|=m.checkModels(models, hash)
934                else:
935                     out|=m.checkLinkTargets(models, hash + [self])
936            return set( [ (str(self)+"."+f[0],f[1]) for f in out ] )
937    
938            
939      def getSafeTimeStepSize(self,dt):      def getSafeTimeStepSize(self,dt):
940          """          """
# Line 1015  class Simulation(Model): Line 1060  class Simulation(Model):
1060          In both cases the time integration is given up after          In both cases the time integration is given up after
1061      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.
1062          """          """
1063            # check the completness of the models:
1064            # first a list of all the models involved in the simulation including subsimulations:
1065            #
1066            missing=self.checkModels(self.getAllModels(), [])
1067            if len(missing)>0:
1068                msg=""
1069                for l in missing:
1070                     msg+="\n\t"+str(l[1])+" at "+l[0]
1071                raise MissingLink("link targets missing in the Simulation: %s"%msg)
1072            #==============================
1073          self.doInitialization()          self.doInitialization()
1074          self.doInitialStep()          self.doInitialStep()
1075          self.doInitialPostprocessing()          self.doInitialPostprocessing()
# Line 1122  class NonPositiveStepSizeError(Exception Line 1177  class NonPositiveStepSizeError(Exception
1177      """      """
1178      pass      pass
1179    
1180    class MissingLink(Exception):
1181        """
1182        Exception thrown when a link is missing
1183        """
1184        pass
1185    
1186  class DataSource(object):  class DataSource(object):
1187      """      """
1188      Class for handling data sources, including local and remote files. This class is under development.      Class for handling data sources, including local and remote files. This class is under development.

Legend:
Removed from v.926  
changed lines
  Added in v.964

  ViewVC Help
Powered by ViewVC 1.1.26