/[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 906 by gross, Tue Nov 21 05:34:15 2006 UTC
# Line 621  class Model(ParameterSet): Line 621  class Model(ParameterSet):
621      finalizing condition is fullfilled. At each time step an iterative      finalizing condition is fullfilled. At each time step an iterative
622      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
623      Model has the following work flow::      Model has the following work flow::
624              
625            doInitialization()            doInitialization()
626              while not terminateInitialIteration(): doInitializationiStep()
627              doInitialPostprocessing()
628            while not finalize():            while not finalize():
629                 dt=getSafeTimeStepSize(dt)                 dt=getSafeTimeStepSize(dt)
630                 doStepPreprocessing(dt)                 doStepPreprocessing(dt)
# Line 668  class Model(ParameterSet): Line 670  class Model(ParameterSet):
670      This function may be overwritten.      This function may be overwritten.
671      """      """
672          pass          pass
673        def doInitialStep(self):
674            """
675        performs an iteration step in the initialization phase
676    
677        This function may be overwritten.
678        """
679            pass
680    
681        def terminateInitialIteration(self):
682            """
683        Returns True if iteration at the inital phase is terminated.
684        """
685            return True
686    
687        def doInitialPostprocessing(self):
688            """
689        finalises the initialization iteration process
690    
691        This function may be overwritten.
692        """
693            pass
694            
695      def getSafeTimeStepSize(self,dt):      def getSafeTimeStepSize(self,dt):
696          """          """
# Line 718  class Model(ParameterSet): Line 741  class Model(ParameterSet):
741      Returns True if iteration on a time step is terminated.      Returns True if iteration on a time step is terminated.
742      """      """
743          return True          return True
744    
745                
746      def doStepPostprocessing(self,dt):      def doStepPostprocessing(self,dt):
747          """          """
748      Finalalizes the time step.      finalises the time step.
749    
750          dt is the currently used time step size.          dt is the currently used time step size.
751    
# Line 840  class Simulation(Model): Line 864  class Simulation(Model):
864          This is the minimum over the time step sizes of all models.          This is the minimum over the time step sizes of all models.
865      """      """
866          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)  
867          return out          return out
868            
869      def doInitialization(self):      def doInitialization(self):
# Line 850  class Simulation(Model): Line 873  class Simulation(Model):
873          self.n=0          self.n=0
874          self.tn=0.          self.tn=0.
875          for o in self.iterModels():          for o in self.iterModels():
876              o.doInitialization()               o.doInitialization()
877            def doInitialStep(self):
878            """
879        performs an iteration step in the initialization step for all models
880        """
881            for o in self.iterModels():
882                 o.doInitialStep()
883    
884        def doInitialPostprocessing(self):
885            """
886        finalises the initialization iteration process for all models.
887        """
888            for o in self.iterModels():
889                o.doInitialPostprocessing()
890      def finalize(self):      def finalize(self):
891          """          """
892      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 895  class Simulation(Model):
895                
896      def doFinalization(self):      def doFinalization(self):
897          """          """
898      Finalalizes the time stepping for all models.      finalises the time stepping for all models.
899      """      """
900          for i in self.iterModels(): i.doFinalization()          for i in self.iterModels(): i.doFinalization()
901          self.trace("end of time integation.")          self.trace("end of time integation.")
# Line 878  class Simulation(Model): Line 913  class Simulation(Model):
913      """      """
914          out=all([o.terminateIteration() for o in self.iterModels()])          out=all([o.terminateIteration() for o in self.iterModels()])
915          return out          return out
916    
917        def terminateInitialIteration(self):
918            """
919        Returns True if all initial iterations for all models are terminated.
920        """
921            out=all([o.terminateInitialIteration() for o in self.iterModels()])
922            return out
923                
924      def doStepPostprocessing(self,dt):      def doStepPostprocessing(self,dt):
925          """          """
926      Finalalizes the iteration process for all models.      finalises the iteration process for all models.
927      """      """
928          for o in self.iterModels():          for o in self.iterModels():
929              o.doStepPostprocessing(dt)              o.doStepPostprocessing(dt)
# Line 912  class Simulation(Model): Line 954  class Simulation(Model):
954      Run the simulation by performing essentially::      Run the simulation by performing essentially::
955            
956          self.doInitialization()          self.doInitialization()
957                while not self.terminateInitialIteration(): self.doInitialStep()
958                self.doInitialPostprocessing()
959          while not self.finalize():          while not self.finalize():
960              dt=self.getSafeTimeStepSize()              dt=self.getSafeTimeStepSize()
961              self.doStep(dt)              self.doStep(dt)
# Line 929  class Simulation(Model): Line 973  class Simulation(Model):
973          In both cases the time integration is given up after          In both cases the time integration is given up after
974      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.      C{Simulation.FAILED_TIME_STEPS_MAX} attempts.
975          """          """
         dt=self.UNDEF_DT  
976          self.doInitialization()          self.doInitialization()
977            iter=0
978            while not self.terminateInitialIteration():
979                self.doInitialStep()
980                iter+=1
981                if iter>self.MAX_ITER_STEPS:
982                     raise IterationDivergenceError("initial iteration did not converge after %s steps."%iter)
983            self.doInitialPostprocessing()
984            self.trace("Initialization finalized after %s iteration steps."%iter)
985            dt=self.UNDEF_DT
986          while not self.finalize():          while not self.finalize():
987              step_fail_counter=0              step_fail_counter=0
988              iteration_fail_counter=0              iteration_fail_counter=0

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

  ViewVC Help
Powered by ViewVC 1.1.26