]> https://gitweb.dealii.org/ - dealii.git/commitdiff
step-78: Avoid doing another timestep at the end.
authorDavid Wells <drwells@email.unc.edu>
Fri, 21 May 2021 16:23:51 +0000 (12:23 -0400)
committerDavid Wells <drwells@email.unc.edu>
Fri, 21 May 2021 16:42:12 +0000 (12:42 -0400)
We should finish at 1, not 1 + dt.

examples/step-78/step-78.cc

index 0b839c561b8dfbe6ef5efefa9df16e902121e5ad..1b3fc652a2b40b809c405ccd81f7876f9eda0418 100644 (file)
@@ -334,12 +334,12 @@ namespace BlackScholesSolver
     Vector<double> solution;
     Vector<double> system_rhs;
 
-    double       time;
-    double       time_step;
-    unsigned int timestep_number;
+    double time;
+    double time_step;
 
     const double       theta;
     const unsigned int n_cycles;
+    const unsigned int n_time_steps;
 
     DataOutStack<dim>        data_out_stack;
     std::vector<std::string> solution_names;
@@ -366,9 +366,9 @@ namespace BlackScholesSolver
     , fe(1)
     , dof_handler(triangulation)
     , time(0.0)
-    , timestep_number(0)
     , theta(0.5)
-    , n_cycles(3)
+    , n_cycles(4)
+    , n_time_steps(5000)
   {
     Assert(dim == 1, ExcNotImplemented());
   }
@@ -388,7 +388,7 @@ namespace BlackScholesSolver
   {
     dof_handler.distribute_dofs(fe);
 
-    time_step = maturity_time / 5000.;
+    time_step = maturity_time / n_time_steps;
 
     constraints.clear();
     DoFTools::make_hanging_node_constraints(dof_handler, constraints);
@@ -712,8 +712,7 @@ namespace BlackScholesSolver
         if (cycle != 0)
           {
             refine_grid();
-            time            = 0.0;
-            timestep_number = 0;
+            time = 0.0;
           }
 
         setup_system();
@@ -745,10 +744,10 @@ namespace BlackScholesSolver
         // vector:
         vmult_result.reinit(dof_handler.n_dofs());
         forcing_terms.reinit(dof_handler.n_dofs());
-        while (time < maturity_time)
+        for (unsigned int timestep_number = 0; timestep_number < n_time_steps;
+             ++timestep_number)
           {
             time += time_step;
-            ++timestep_number;
 
             if (timestep_number % 1000 == 0)
               std::cout << "Time step " << timestep_number << " at t=" << time

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.