/[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 908 by gross, Thu Nov 23 06:39:39 2006 UTC
# Line 397  class ParameterSet(LinkableObject): Line 397  class ParameterSet(LinkableObject):
397          self.declareParameters(parameters)          self.declareParameters(parameters)
398    
399      def __repr__(self):      def __repr__(self):
400          return "<%s %r>" % (self.__class__.__name__,          return "<%s %d>"%(self.__class__.__name__,id(self))
                             [(p, getattr(self, p, None)) for p in self.parameters])  
401            
402      def declareParameter(self,**parameters):      def declareParameter(self,**parameters):
403          """          """
# Line 621  class Model(ParameterSet): Line 620  class Model(ParameterSet):
620      finalizing condition is fullfilled. At each time step an iterative      finalizing condition is fullfilled. At each time step an iterative
621      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
622      Model has the following work flow::      Model has the following work flow::
623              
624            doInitialization()            doInitialization()
625              while not terminateInitialIteration(): doInitializationiStep()
626              doInitialPostprocessing()
627            while not finalize():            while not finalize():
628                 dt=getSafeTimeStepSize(dt)                 dt=getSafeTimeStepSize(dt)
629                 doStepPreprocessing(dt)                 doStepPreprocessing(dt)
# Line 648  class Model(ParameterSet): Line 649  class Model(ParameterSet):
649          ParameterSet.__init__(self, parameters=parameters,**kwarg)          ParameterSet.__init__(self, parameters=parameters,**kwarg)
650    
651      def __str__(self):      def __str__(self):
652         return "<%s %d>"%(self.__class__,id(self))         return "<%s %d>"%(self.__class__.__name__,id(self))
653    
654      def toDom(self, document, node):      def toDom(self, document, node):
655          """          """
# Line 668  class Model(ParameterSet): Line 669  class Model(ParameterSet):
669      This function may be overwritten.      This function may be overwritten.
670      """      """
671          pass          pass
672        def doInitialStep(self):
673            """
674        performs an iteration step in the initialization phase
675    
676        This function may be overwritten.
677        """
678            pass
679    
680        def terminateInitialIteration(self):
681            """
682        Returns True if iteration at the inital phase is terminated.
683        """
684            return True
685    
686        def doInitialPostprocessing(self):
687            """
688        finalises the initialization iteration process
689    
690        This function may be overwritten.
691        """
692            pass
693            
694      def getSafeTimeStepSize(self,dt):      def getSafeTimeStepSize(self,dt):
695          """          """
# Line 718  class Model(ParameterSet): Line 740  class Model(ParameterSet):
740      Returns True if iteration on a time step is terminated.      Returns True if iteration on a time step is terminated.
741      """      """
742          return True          return True
743    
744                
745      def doStepPostprocessing(self,dt):      def doStepPostprocessing(self,dt):
746          """          """
747      Finalalizes the time step.      finalises the time step.
748    
749          dt is the currently used time step size.          dt is the currently used time step size.
750    
# Line 840  class Simulation(Model): Line 863  class Simulation(Model):
863          This is the minimum over the time step sizes of all models.          This is the minimum over the time step sizes of all models.
864      """      """
865          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)  
866          return out          return out
867            
868      def doInitialization(self):      def doInitialization(self):
# Line 850  class Simulation(Model): Line 872  class Simulation(Model):
872          self.n=0          self.n=0
873          self.tn=0.          self.tn=0.
874          for o in self.iterModels():          for o in self.iterModels():
875              o.doInitialization()               o.doInitialization()
876            def doInitialStep(self):
877            """
878        performs an iteration step in the initialization step for all models
879        """
880            iter=0
881            while not self.terminateInitialIteration():
882                if iter==0: self.trace("iteration for initialization starts")
883                iter+=1
884                self.trace("iteration step %d"%(iter))
885                for o in self.iterModels():
886                     o.doInitialStep()
887                if iter>self.MAX_ITER_STEPS:
888                     raise IterationDivergenceError("initial iteration did not converge after %s steps."%iter)
889            self.trace("Initialization finalized after %s iteration steps."%iter)
890    
891        def doInitialPostprocessing(self):
892            """
893        finalises the initialization iteration process for all models.
894        """
895            for o in self.iterModels():
896                o.doInitialPostprocessing()
897      def finalize(self):      def finalize(self):
898          """          """
899      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 902  class Simulation(Model):
902                
903      def doFinalization(self):      def doFinalization(self):
904          """          """
905      Finalalizes the time stepping for all models.      finalises the time stepping for all models.
906      """      """
907          for i in self.iterModels(): i.doFinalization()          for i in self.iterModels(): i.doFinalization()
908          self.trace("end of time integation.")          self.trace("end of time integation.")
# Line 878  class Simulation(Model): Line 920  class Simulation(Model):
920      """      """
921          out=all([o.terminateIteration() for o in self.iterModels()])          out=all([o.terminateIteration() for o in self.iterModels()])
922          return out          return out
923    
924        def terminateInitialIteration(self):
925            """
926        Returns True if all initial iterations for all models are terminated.
927        """
928            out=all([o.terminateInitialIteration() for o in self.iterModels()])
929            return out
930                
931      def doStepPostprocessing(self,dt):      def doStepPostprocessing(self,dt):
932          """          """
933      Finalalizes the iteration process for all models.      finalises the iteration process for all models.
934      """      """
935          for o in self.iterModels():          for o in self.iterModels():
936              o.doStepPostprocessing(dt)              o.doStepPostprocessing(dt)
# Line 912  class Simulation(Model): Line 961  class Simulation(Model):
961      Run the simulation by performing essentially::      Run the simulation by performing essentially::
962            
963          self.doInitialization()          self.doInitialization()
964                while not self.terminateInitialIteration(): self.doInitialStep()
965                self.doInitialPostprocessing()
966          while not self.finalize():          while not self.finalize():
967              dt=self.getSafeTimeStepSize()              dt=self.getSafeTimeStepSize()
968              self.doStep(dt)              self.doStep(dt)
# Line 929  class Simulation(Model): Line 980  class Simulation(Model):
980          In both cases the time integration is given up after          In both cases the time integration is given up after
981      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.
982          """          """
         dt=self.UNDEF_DT  
983          self.doInitialization()          self.doInitialization()
984            self.doInitialStep()
985            self.doInitialPostprocessing()
986            dt=self.UNDEF_DT
987          while not self.finalize():          while not self.finalize():
988              step_fail_counter=0              step_fail_counter=0
989              iteration_fail_counter=0              iteration_fail_counter=0

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

  ViewVC Help
Powered by ViewVC 1.1.26