From 214a1193799d7684322c69e03d5d30e4b61b79f5 Mon Sep 17 00:00:00 2001 From: David Wells Date: Fri, 21 May 2021 12:23:51 -0400 Subject: [PATCH] step-78: Avoid doing another timestep at the end. We should finish at 1, not 1 + dt. --- examples/step-78/step-78.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/step-78/step-78.cc b/examples/step-78/step-78.cc index 0b839c561b..1b3fc652a2 100644 --- a/examples/step-78/step-78.cc +++ b/examples/step-78/step-78.cc @@ -334,12 +334,12 @@ namespace BlackScholesSolver Vector solution; Vector 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 data_out_stack; std::vector 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 -- 2.39.5