/[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 885 by gross, Wed Nov 1 09:05:51 2006 UTC revision 912 by gross, Wed Dec 6 03:29:49 2006 UTC
# Line 161  class Link: Line 161  class Link:
161          self.target = target          self.target = target
162          self.attribute = None          self.attribute = None
163          self.setAttributeName(attribute)          self.setAttributeName(attribute)
164    
165        def getAttributeName(self):
166            """
167            returns the name of the attribute the link is pointing to
168            """
169            return self.attribute
170            
171      def setAttributeName(self,attribute):      def setAttributeName(self,attribute):
172          """          """
# Line 397  class ParameterSet(LinkableObject): Line 403  class ParameterSet(LinkableObject):
403          self.declareParameters(parameters)          self.declareParameters(parameters)
404    
405      def __repr__(self):      def __repr__(self):
406          return "<%s %r>" % (self.__class__.__name__,          return "<%s %d>"%(self.__class__.__name__,id(self))
                             [(p, getattr(self, p, None)) for p in self.parameters])  
407            
408      def declareParameter(self,**parameters):      def declareParameter(self,**parameters):
409          """          """
# Line 621  class Model(ParameterSet): Line 626  class Model(ParameterSet):
626      finalizing condition is fullfilled. At each time step an iterative      finalizing condition is fullfilled. At each time step an iterative
627      process can be performed and the time step size can be controlled. A      process can be performed and the time step size can be controlled. A
628      Model has the following work flow::      Model has the following work flow::
629              
630            doInitialization()            doInitialization()
631              while not terminateInitialIteration(): doInitializationiStep()
632              doInitialPostprocessing()
633            while not finalize():            while not finalize():
634                 dt=getSafeTimeStepSize(dt)                 dt=getSafeTimeStepSize(dt)
635                 doStepPreprocessing(dt)                 doStepPreprocessing(dt)
# Line 648  class Model(ParameterSet): Line 655  class Model(ParameterSet):
655          ParameterSet.__init__(self, parameters=parameters,**kwarg)          ParameterSet.__init__(self, parameters=parameters,**kwarg)
656    
657      def __str__(self):      def __str__(self):
658         return "<%s %d>"%(self.__class__,id(self))         return "<%s %d>"%(self.__class__.__name__,id(self))
659    
660      def toDom(self, document, node):      def toDom(self, document, node):
661          """          """
# Line 668  class Model(ParameterSet): Line 675  class Model(ParameterSet):
675      This function may be overwritten.      This function may be overwritten.
676      """      """
677          pass          pass
678        def doInitialStep(self):
679            """
680        performs an iteration step in the initialization phase
681    
682        This function may be overwritten.
683        """
684            pass
685    
686        def terminateInitialIteration(self):
687            """
688        Returns True if iteration at the inital phase is terminated.
689        """
690            return True
691    
692        def doInitialPostprocessing(self):
693            """
694        finalises the initialization iteration process
695    
696        This function may be overwritten.
697        """
698            pass
699            
700      def getSafeTimeStepSize(self,dt):      def getSafeTimeStepSize(self,dt):
701          """          """
# Line 718  class Model(ParameterSet): Line 746  class Model(ParameterSet):
746      Returns True if iteration on a time step is terminated.      Returns True if iteration on a time step is terminated.
747      """      """
748          return True          return True
749    
750                
751      def doStepPostprocessing(self,dt):      def doStepPostprocessing(self,dt):
752          """          """
753      Finalalizes the time step.      finalises the time step.
754    
755          dt is the currently used time step size.          dt is the currently used time step size.
756    
# Line 840  class Simulation(Model): Line 869  class Simulation(Model):
869          This is the minimum over the time step sizes of all models.          This is the minimum over the time step sizes of all models.
870      """      """
871          out=min([o.getSafeTimeStepSize(dt) for o in self.iterModels()])          out=min([o.getSafeTimeStepSize(dt) for o in self.iterModels()])
         #print "%s: safe step size is %e."%(str(self),out)  
872          return out          return out
873            
874      def doInitialization(self):      def doInitialization(self):
# Line 850  class Simulation(Model): Line 878  class Simulation(Model):
878          self.n=0          self.n=0
879          self.tn=0.          self.tn=0.
880          for o in self.iterModels():          for o in self.iterModels():
881              o.doInitialization()               o.doInitialization()
882            def doInitialStep(self):
883            """
884        performs an iteration step in the initialization step for all models
885        """
886            iter=0
887            while not self.terminateInitialIteration():
888                if iter==0: self.trace("iteration for initialization starts")
889                iter+=1
890                self.trace("iteration step %d"%(iter))
891                for o in self.iterModels():
892                     o.doInitialStep()
893                if iter>self.MAX_ITER_STEPS:
894                     raise IterationDivergenceError("initial iteration did not converge after %s steps."%iter)
895            self.trace("Initialization finalized after %s iteration steps."%iter)
896    
897        def doInitialPostprocessing(self):
898            """
899        finalises the initialization iteration process for all models.
900        """
901            for o in self.iterModels():
902                o.doInitialPostprocessing()
903      def finalize(self):      def finalize(self):
904          """          """
905      Returns True if any of the models is to be finalized.      Returns True if any of the models is to be finalized.
# Line 860  class Simulation(Model): Line 908  class Simulation(Model):
908                
909      def doFinalization(self):      def doFinalization(self):
910          """          """
911      Finalalizes the time stepping for all models.      finalises the time stepping for all models.
912      """      """
913          for i in self.iterModels(): i.doFinalization()          for i in self.iterModels(): i.doFinalization()
914          self.trace("end of time integation.")          self.trace("end of time integation.")
# Line 878  class Simulation(Model): Line 926  class Simulation(Model):
926      """      """
927          out=all([o.terminateIteration() for o in self.iterModels()])          out=all([o.terminateIteration() for o in self.iterModels()])
928          return out          return out
929    
930        def terminateInitialIteration(self):
931            """
932        Returns True if all initial iterations for all models are terminated.
933        """
934            out=all([o.terminateInitialIteration() for o in self.iterModels()])
935            return out
936                
937      def doStepPostprocessing(self,dt):      def doStepPostprocessing(self,dt):
938          """          """
939      Finalalizes the iteration process for all models.      finalises the iteration process for all models.
940      """      """
941          for o in self.iterModels():          for o in self.iterModels():
942              o.doStepPostprocessing(dt)              o.doStepPostprocessing(dt)
# Line 912  class Simulation(Model): Line 967  class Simulation(Model):
967      Run the simulation by performing essentially::      Run the simulation by performing essentially::
968            
969          self.doInitialization()          self.doInitialization()
970                while not self.terminateInitialIteration(): self.doInitialStep()
971                self.doInitialPostprocessing()
972          while not self.finalize():          while not self.finalize():
973              dt=self.getSafeTimeStepSize()              dt=self.getSafeTimeStepSize()
974              self.doStep(dt)              self.doStep(dt)
# Line 929  class Simulation(Model): Line 986  class Simulation(Model):
986          In both cases the time integration is given up after          In both cases the time integration is given up after
987      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.
988          """          """
         dt=self.UNDEF_DT  
989          self.doInitialization()          self.doInitialization()
990            self.doInitialStep()
991            self.doInitialPostprocessing()
992            dt=self.UNDEF_DT
993          while not self.finalize():          while not self.finalize():
994              step_fail_counter=0              step_fail_counter=0
995              iteration_fail_counter=0              iteration_fail_counter=0

Legend:
Removed from v.885  
changed lines
  Added in v.912

  ViewVC Help
Powered by ViewVC 1.1.26