/[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 952 by gross, Wed Feb 7 23:53:24 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 471  class ParameterSet(LinkableObject): Line 476  class ParameterSet(LinkableObject):
476          if self.isParameter(name):          if self.isParameter(name):
477              self.parameters.remove(name)              self.parameters.remove(name)
478              self.trace("parameter %s has been removed."%name)              self.trace("parameter %s has been removed."%name)
479    
480        def checkLinkTargets(self, models, hash):
481            """
482            returns a set of tuples ("<self>(<name>)", <target model>) if the parameter <name> is linked to model <target model>
483            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
484            the parameter set is checked for its models. hash gives the call history.
485            """
486            out=set()
487            for name, value in self:
488                if isinstance(value, Link):
489                   m=value.getTarget()
490                   if isinstance(m, Model):
491                       if not m in models: out.add( (str(self)+"("+name+")",m) )
492                   elif isinstance(m, ParameterSet) and not m in hash:
493                         out|=set( [ (str(self)+"("+name+")."+f[0],f[1]) for f in m.checkLinkTargets(models, hash+[ self ] ) ] )
494            return out
495            
496      def __iter__(self):      def __iter__(self):
497          """          """
# Line 582  class ParameterSet(LinkableObject): Line 603  class ParameterSet(LinkableObject):
603                      dic.appendChild(i)                      dic.appendChild(i)
604                   param.appendChild(dic)                   param.appendChild(dic)
605              else:              else:
                 print value  
606                  raise ValueError("cannot serialize %s type to XML."%str(value.__class__))                  raise ValueError("cannot serialize %s type to XML."%str(value.__class__))
607    
608              node.appendChild(param)              node.appendChild(param)
# Line 844  class Simulation(Model): Line 864  class Simulation(Model):
864      Initiates a simulation from a list of models.      Initiates a simulation from a list of models.
865      """      """
866          super(Simulation, self).__init__(**kwargs)          super(Simulation, self).__init__(**kwargs)
867            for m in models:
868                if not isinstance(m, Model):
869                     raise TypeError("%s is not a subclass of Model."%m)
870          self.__models=[]          self.__models=[]
           
871          for i in range(len(models)):          for i in range(len(models)):
872              self[i] = models[i]              self[i] = models[i]
873                            
# Line 890  class Simulation(Model): Line 912  class Simulation(Model):
912      """      """
913          return len(self.__models)          return len(self.__models)
914    
915        def getAllModels(self):
916            """
917            returns a list of all models used in the Simulation including subsimulations
918            """
919            out=[]
920            for m in self.iterModels():
921                if isinstance(m, Simulation):
922                   out+=m.getAllModels()
923                else:
924                   out.append(m)
925            return list(set(out))
926    
927        def checkModels(self, models, hash):
928            """
929            returns a list of (model,parameter, target model ) if the the parameter of model
930            is linking to the target_model which is not in list of models.
931            """
932            out=self.checkLinkTargets(models, hash + [self])
933            for m in self.iterModels():
934                if isinstance(m, Simulation):
935                     out|=m.checkModels(models, hash)
936                else:
937                     out|=m.checkLinkTargets(models, hash + [self])
938            return set( [ (str(self)+"."+f[0],f[1]) for f in out ] )
939    
940            
941      def getSafeTimeStepSize(self,dt):      def getSafeTimeStepSize(self,dt):
942          """          """
# Line 1015  class Simulation(Model): Line 1062  class Simulation(Model):
1062          In both cases the time integration is given up after          In both cases the time integration is given up after
1063      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.
1064          """          """
1065            # check the completness of the models:
1066            # first a list of all the models involved in the simulation including subsimulations:
1067            #
1068            missing=self.checkModels(self.getAllModels(), [])
1069            if len(missing)>0:
1070                msg=""
1071                for l in missing:
1072                     msg+="\n\t"+str(l[1])+" at "+l[0]
1073                raise MissingLink("link targets missing in the Simulation: %s"%msg)
1074            #==============================
1075          self.doInitialization()          self.doInitialization()
1076          self.doInitialStep()          self.doInitialStep()
1077          self.doInitialPostprocessing()          self.doInitialPostprocessing()
# Line 1122  class NonPositiveStepSizeError(Exception Line 1179  class NonPositiveStepSizeError(Exception
1179      """      """
1180      pass      pass
1181    
1182    class MissingLink(Exception):
1183        """
1184        Exception thrown when a link is missing
1185        """
1186        pass
1187    
1188  class DataSource(object):  class DataSource(object):
1189      """      """
1190      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.952

  ViewVC Help
Powered by ViewVC 1.1.26