/[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 918 by gross, Wed Jan 3 06:30:00 2007 UTC revision 939 by gross, Thu Jan 25 04:23:38 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 570  class ParameterSet(LinkableObject): Line 575  class ParameterSet(LinkableObject):
575                  param.appendChild(esysxml.createDataNode('Value', ' '.join([str(x) for x in value]) ))                  param.appendChild(esysxml.createDataNode('Value', ' '.join([str(x) for x in value]) ))
576              elif isinstance(value, (str, bool, int, float, type(None))):              elif isinstance(value, (str, bool, int, float, type(None))):
577                  param.appendChild(esysxml.createDataNode('Value', str(value)))                  param.appendChild(esysxml.createDataNode('Value', str(value)))
578                elif isinstance(value, dict):
579                     dic = esysxml.createElement('dictionary')
580                     if len(value.keys())>0:
581                         dic.setAttribute('key_type', value.keys()[0].__class__.__name__)
582                         dic.setAttribute('value_type', value[value.keys()[0]].__class__.__name__)
583                     for k,v in value.items():
584                        i=esysxml.createElement('item')
585                        i.appendChild(esysxml.createDataNode('key', k))
586                        i.appendChild(esysxml.createDataNode('value', v))
587                        dic.appendChild(i)
588                     param.appendChild(dic)
589              else:              else:
590                    print value
591                  raise ValueError("cannot serialize %s type to XML."%str(value.__class__))                  raise ValueError("cannot serialize %s type to XML."%str(value.__class__))
592    
593              node.appendChild(param)              node.appendChild(param)
# Line 832  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 878  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 1003  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                     msg+="\n\t"+str(l[-1])+" at "+str(self)
1061                     for i in xrange(len(l)-1): msg+="."+str(l[i])
1062                raise MissingLink("link targets missing in the Simulation: %s"%msg)
1063            #==============================
1064          self.doInitialization()          self.doInitialization()
1065          self.doInitialStep()          self.doInitialStep()
1066          self.doInitialPostprocessing()          self.doInitialPostprocessing()
# Line 1110  class NonPositiveStepSizeError(Exception Line 1168  class NonPositiveStepSizeError(Exception
1168      """      """
1169      pass      pass
1170    
1171    class MissingLink(Exception):
1172        """
1173        Exception thrown when a link is missing
1174        """
1175        pass
1176    
1177  class DataSource(object):  class DataSource(object):
1178      """      """
1179      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.
# Line 1130  class DataSource(object): Line 1194  class DataSource(object):
1194          node.appendChild(ds)          node.appendChild(ds)
1195    
1196      def fromDom(cls, esysxml, node):      def fromDom(cls, esysxml, node):
1197          uri= node.getElementsByTagName("URI")[0].firstChild.nodeValue.strip()          uri= str(node.getElementsByTagName("URI")[0].firstChild.nodeValue.strip())
1198          fileformat= node.getElementsByTagName("FileFormat")[0].firstChild.nodeValue.strip()          fileformat= str(node.getElementsByTagName("FileFormat")[0].firstChild.nodeValue.strip())
1199          ds = cls(uri, fileformat)          ds = cls(uri, fileformat)
1200          return ds          return ds
1201    

Legend:
Removed from v.918  
changed lines
  Added in v.939

  ViewVC Help
Powered by ViewVC 1.1.26