/[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 937 by gross, Fri Jan 12 06:31:37 2007 UTC revision 938 by gross, Thu Jan 25 03:40:54 2007 UTC
# 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 844  class Simulation(Model): Line 849  class Simulation(Model):
849      Initiates a simulation from a list of models.      Initiates a simulation from a list of models.
850      """      """
851          super(Simulation, self).__init__(**kwargs)          super(Simulation, self).__init__(**kwargs)
852            for m in models:
853                if not isinstance(m, Model):
854                     raise TypeError("%s is not a subclass of Model."%m)
855          self.__models=[]          self.__models=[]
           
856          for i in range(len(models)):          for i in range(len(models)):
857              self[i] = models[i]              self[i] = models[i]
858                            
# Line 890  class Simulation(Model): Line 897  class Simulation(Model):
897      """      """
898          return len(self.__models)          return len(self.__models)
899    
900        def getAllModels(self):
901            """
902            returns a list of all models used in the Simulation including subsimulations
903            """
904            out=[]
905            for m in self.iterModels():
906                if isinstance(m, Simulation):
907                   out+=m.getAllModels()
908                else:
909                   out.append(m)
910            return list(set(out))
911    
912        def checkModelLinks(self, models):
913            """
914            returns a list of (model,parameter, target model ) if the the parameter of model
915            is linking to the target_model which is not in list of models.
916            """
917            out=[]
918            for m in self.iterModels():
919                if isinstance(m, Simulation):
920                   out+=[ (m,) + f for f in  m.checkModelLinks(models) ]
921                else:
922                  for p in m:
923                     if isinstance(p[1], Link):
924                        l_m=p[1].getTarget()
925                        if isinstance(l_m, Model) and not l_m in models: out.append( (m,p[0],l_m) )
926            return out
927    
928            
929      def getSafeTimeStepSize(self,dt):      def getSafeTimeStepSize(self,dt):
930          """          """
# Line 1015  class Simulation(Model): Line 1050  class Simulation(Model):
1050          In both cases the time integration is given up after          In both cases the time integration is given up after
1051      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.
1052          """          """
1053            # check the completness of the models:
1054            # first a list of all the models involved in the simulation including subsimulations:
1055            #
1056            missing=self.checkModelLinks(self.getAllModels())
1057            if len(missing)>0:
1058                msg=""
1059                for l in missing:
1060                     line=str(self)
1061                     settarget=False
1062                     for c in l:
1063                        if settarget:
1064                           line+=" linked to "+str(c)
1065                        else:
1066                           line+="."+str(c)
1067                        if isinstance(c,str): settarget=True
1068                     msg+="\n\t"+line
1069                raise MissingLink("link targets missing in the Simulation: %s"%msg)
1070            #==============================
1071          self.doInitialization()          self.doInitialization()
1072          self.doInitialStep()          self.doInitialStep()
1073          self.doInitialPostprocessing()          self.doInitialPostprocessing()
# Line 1122  class NonPositiveStepSizeError(Exception Line 1175  class NonPositiveStepSizeError(Exception
1175      """      """
1176      pass      pass
1177    
1178    class MissingLink(Exception):
1179        """
1180        Exception thrown when a link is missing
1181        """
1182        pass
1183    
1184  class DataSource(object):  class DataSource(object):
1185      """      """
1186      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.937  
changed lines
  Added in v.938

  ViewVC Help
Powered by ViewVC 1.1.26