[cig-commits] commit 2016 by ryan.grove to /var/svn/dealii/aspect

dealii.demon at gmail.com dealii.demon at gmail.com
Tue Nov 19 13:08:23 PST 2013


Revision 2016

When the user selects to terminate by end time, the final time step is adjusted to hit the final time exactly.

U   trunk/aspect/doc/modules/changes.h
U   trunk/aspect/include/aspect/termination_criteria/end_time.h
U   trunk/aspect/include/aspect/termination_criteria/interface.h
U   trunk/aspect/source/simulator/core.cc
U   trunk/aspect/source/termination_criteria/end_time.cc
U   trunk/aspect/source/termination_criteria/interface.cc


http://www.dealii.org/websvn/revision.php?repname=Aspect+Repository&path=%2F&rev=2016&peg=2016

Diff:
Modified: trunk/aspect/doc/modules/changes.h
===================================================================
--- trunk/aspect/doc/modules/changes.h	2013-11-19 20:48:11 UTC (rev 2015)
+++ trunk/aspect/doc/modules/changes.h	2013-11-19 21:07:57 UTC (rev 2016)
@@ -8,6 +8,11 @@
 </p>
 
 <ol>
+  <li>Changed: When the user selects to terminate by end time, the
+  final time step is adjusted to hit the final time exactly.
+  <br>
+  (Ryan Grove 2013/11/19)
+
   <li>Fixed: When using compressible models, we fixed up the right hand side
   vector in a way so that the mean divergence is zero (even though it is of
   course locally nonzero due to the compressibility). This is necessary to ensure

Modified: trunk/aspect/include/aspect/termination_criteria/end_time.h
===================================================================
--- trunk/aspect/include/aspect/termination_criteria/end_time.h	2013-11-19 20:48:11 UTC (rev 2015)
+++ trunk/aspect/include/aspect/termination_criteria/end_time.h	2013-11-19 21:07:57 UTC (rev 2016)
@@ -41,7 +41,13 @@
     class EndTime : public Interface<dim>, public SimulatorAccess<dim>
     {
       public:
+       
         /**
+         * Check this termination criterion and possibly reduce time step size
+         */
+        double check_for_last_time_step (double time_step) const;
+
+        /**
          * Evaluate this termination criterion.
          *
          * @return Whether to terminate the simulation (true) or continue (false).

Modified: trunk/aspect/include/aspect/termination_criteria/interface.h
===================================================================
--- trunk/aspect/include/aspect/termination_criteria/interface.h	2013-11-19 20:48:11 UTC (rev 2015)
+++ trunk/aspect/include/aspect/termination_criteria/interface.h	2013-11-19 21:07:57 UTC (rev 2016)
@@ -91,6 +91,19 @@
         bool
         execute () = 0;
 
+         /**
+         * Check for last time step and if so reduce the time step to user 
+         * specified end time
+         *
+         * @return Reduced or current time step size
+         *
+         * @note A reduced time step size will be returned for the
+         * last time step but the current time step size will be
+         * returned otherwise. Also, the default implementation will
+         * always return the full time step size.
+         */
+        virtual double check_for_last_time_step (double time_step) const;
+
         /**
          * Declare the parameters this class takes through input files.
          * Derived classes should overload this function if they actually
@@ -162,6 +175,20 @@
         std::pair<bool,bool>
         execute () const;
 
+         /**
+         * Check all of the termination criteria objects that have
+         * been requested in the input file for criteria regarding
+         * last time step and if so get the minimum of these values.
+         *
+         * @return Reduced or current time step size
+         *
+         * @note A reduced time step size will be returned for the
+         * last time step but the current time step size will be
+         * returned otherwise. The time step will be greater than zero
+         * as well as less than or equal to the inputted time step
+         */
+        double check_for_last_time_step (double time_step) const;
+
         /**
          * Declare the parameters of all known termination criteria plugins, as
          * well as of ones this class has itself.

Modified: trunk/aspect/source/simulator/core.cc
===================================================================
--- trunk/aspect/source/simulator/core.cc	2013-11-19 20:48:11 UTC (rev 2015)
+++ trunk/aspect/source/simulator/core.cc	2013-11-19 21:07:57 UTC (rev 2016)
@@ -1281,6 +1281,7 @@
         // added to statistics later
         old_time_step = time_step;
         time_step = compute_time_step().first;
+        time_step = termination_manager.check_for_last_time_step(time_step);
 
         if (parameters.convert_to_years == true)
           statistics.add_value("Time step size (years)", time_step / year_in_seconds);

Modified: trunk/aspect/source/termination_criteria/end_time.cc
===================================================================
--- trunk/aspect/source/termination_criteria/end_time.cc	2013-11-19 20:48:11 UTC (rev 2015)
+++ trunk/aspect/source/termination_criteria/end_time.cc	2013-11-19 21:07:57 UTC (rev 2016)
@@ -30,10 +30,18 @@
     bool
     EndTime<dim>::execute()
     {
-      return (this->get_time() >= end_time);
+      return (this->get_time() > end_time);
     }
 
     template <int dim>
+    double EndTime<dim>::check_for_last_time_step (double time_step) const
+    {
+      if (this->get_time()<end_time && this->get_time()+time_step > end_time)
+	time_step = end_time - this->get_time();
+      return time_step;
+    }
+
+    template <int dim>
     void
     EndTime<dim>::declare_parameters (ParameterHandler &prm)
     {

Modified: trunk/aspect/source/termination_criteria/interface.cc
===================================================================
--- trunk/aspect/source/termination_criteria/interface.cc	2013-11-19 20:48:11 UTC (rev 2015)
+++ trunk/aspect/source/termination_criteria/interface.cc	2013-11-19 21:07:57 UTC (rev 2016)
@@ -41,8 +41,12 @@
     Interface<dim>::declare_parameters (ParameterHandler &)
     {}
 
+    template <int dim>
+    double Interface<dim>::check_for_last_time_step (double time_step) const
+    {
+      return time_step;
+    }
 
-
     template <int dim>
     void
     Interface<dim>::parse_parameters (ParameterHandler &)
@@ -64,8 +68,26 @@
       SimulatorAccess<dim>::initialize (simulator);
     }
 
+    template <int dim>
+    double Manager<dim>::check_for_last_time_step (double time_step) const
+    {
+      for (typename std::list<std_cxx1x::shared_ptr<Interface<dim> > >::const_iterator
+           p = termination_objects.begin();
+           p != termination_objects.end(); ++p)
+	   {
+              double current_time_step = (*p)->check_for_last_time_step (time_step);
 
+	      AssertThrow (current_time_step > 0,
+	        ExcMessage("Time step must be greater than 0."));
+	      AssertThrow (current_time_step <= time_step,
+	        ExcMessage("Current time step must be less than or equal to time step entered into function."));
 
+              if (current_time_step < time_step)
+                time_step = current_time_step;
+	   }
+      return time_step;
+    }
+
     template <int dim>
     std::pair<bool,bool>
     Manager<dim>::execute () const


More information about the CIG-COMMITS mailing list