From: guido Date: Sun, 22 May 2005 09:35:33 +0000 (+0000) Subject: fixed subscription problems X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b17c539bb506b67e260d09abd8bf86900dc6e2c6;p=dealii-svn.git fixed subscription problems git-svn-id: https://svn.dealii.org/trunk@10694 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/numerics/time_dependent.h b/deal.II/deal.II/include/numerics/time_dependent.h index 138fcd6ee8..3d2b71e98d 100644 --- a/deal.II/deal.II/include/numerics/time_dependent.h +++ b/deal.II/deal.II/include/numerics/time_dependent.h @@ -697,7 +697,7 @@ class TimeDependent * objects pointed to by the pointers * in this collection. */ - std::vector timesteps; + std::vector > timesteps; /** * Number of the present sweep. This is @@ -1797,7 +1797,7 @@ class TimeStepBase_Tria : public TimeStepBase * such a behaviour is specified * in the @p flags structure. */ - Triangulation *tria; + SmartPointer > tria; /** * Pointer to a grid which is to @@ -1882,11 +1882,11 @@ void TimeDependent::do_loop (InitFunctionObject init_function, { case forward: init_function (static_cast - (timesteps[step])); + (&*timesteps[step])); break; case backward: init_function (static_cast - (timesteps[n_timesteps-step-1])); + (&*timesteps[n_timesteps-step-1])); break; }; @@ -1932,11 +1932,11 @@ void TimeDependent::do_loop (InitFunctionObject init_function, { case forward: loop_function (static_cast - (timesteps[step])); + (&*timesteps[step])); break; case backward: loop_function (static_cast - (timesteps[n_timesteps-step-1])); + (&*timesteps[n_timesteps-step-1])); break; }; diff --git a/deal.II/deal.II/source/numerics/time_dependent.cc b/deal.II/deal.II/source/numerics/time_dependent.cc index 3a28e7f1d5..2c33d0c18c 100644 --- a/deal.II/deal.II/source/numerics/time_dependent.cc +++ b/deal.II/deal.II/source/numerics/time_dependent.cc @@ -58,10 +58,6 @@ TimeDependent::insert_timestep (const TimeStepBase *position, Assert ((std::find(timesteps.begin(), timesteps.end(), position) != timesteps.end()) || (position == 0), ExcInvalidPosition()); - - // lock this timestep from deletion - new_timestep->subscribe(typeid(*this).name()); - // first insert the new time step // into the doubly linked list // of timesteps @@ -93,7 +89,7 @@ TimeDependent::insert_timestep (const TimeStepBase *position, else { // inner time step - std::vector::iterator insert_position + std::vector >::iterator insert_position = std::find(timesteps.begin(), timesteps.end(), position); (*(insert_position-1))->set_next_timestep (new_timestep); @@ -122,9 +118,15 @@ void TimeDependent::delete_timestep (const unsigned int position) { Assert (positionunsubscribe(typeid(*this).name()); - delete timesteps[position]; + + // Remember time step object for + // later deletion and unlock + // SmartPointer + TimeStepBase* t = timesteps[position]; + timesteps[position] = 0; + // Now delete unsubscribed object + delete t; + timesteps.erase (timesteps.begin() + position); // reset "next" pointer of previous @@ -424,7 +426,7 @@ TimeStepBase_Tria::TimeStepBase_Tria (const double time, const Flags &flags, const RefinementFlags &refinement_flags) : TimeStepBase (time), - tria(0), + tria(0, typeid(*this).name()), coarse_grid (&coarse_grid), flags (flags), refinement_flags (refinement_flags) @@ -437,8 +439,9 @@ TimeStepBase_Tria::~TimeStepBase_Tria () { if (!flags.delete_and_rebuild_tria) { - tria->unsubscribe(typeid(*this).name()); - delete tria; + Triangulation* t = tria; + tria = 0; + delete t; } else Assert (tria==0, ExcInternalError()); @@ -471,11 +474,11 @@ TimeStepBase_Tria::sleep (const unsigned sleep_level) if (flags.delete_and_rebuild_tria) { - tria->unsubscribe(typeid(*this).name()); - delete tria; + Triangulation* t = tria; tria = 0; - }; - }; + delete t; + } + } TimeStepBase::sleep (sleep_level); } @@ -505,7 +508,6 @@ void TimeStepBase_Tria::restore_grid () // create a virgin triangulation and // set it to a copy of the coarse grid tria = new Triangulation (); - tria->subscribe(typeid(*this).name()); tria->copy_triangulation (*coarse_grid); // for each of the previous refinement diff --git a/tests/deal.II/wave-test-3.cc b/tests/deal.II/wave-test-3.cc index b63a5a2805..f5898d0258 100644 --- a/tests/deal.II/wave-test-3.cc +++ b/tests/deal.II/wave-test-3.cc @@ -2858,11 +2858,12 @@ void TimestepManager::run_sweep (const unsigned int sweep_no) start_sweep (sweep_no); - for (std::vector::iterator timestep=timesteps.begin(); + for (std::vector >::iterator timestep=timesteps.begin(); timestep!=timesteps.end(); ++timestep) { - dynamic_cast*>(*timestep)->attach_sweep_info (sweep_info); - dynamic_cast*>(*timestep)->attach_sweep_data (sweep_data); + TimeStepBase* t = *timestep; + dynamic_cast*>(t)->attach_sweep_info (sweep_info); + dynamic_cast*>(t)->attach_sweep_data (sweep_data); }; solve_primal_problem (); @@ -2905,9 +2906,11 @@ const unsigned int n_timesteps = timesteps.size(); std::vector > indicators (n_timesteps); for (unsigned int i=0; i*>(timesteps[i]) - ->get_timestep_postprocess().get_tria_refinement_criteria (indicators[i]); - + { + TimeStepBase* t = timesteps[i]; + static_cast*>(t) + ->get_timestep_postprocess().get_tria_refinement_criteria (indicators[i]); + } unsigned int total_number_of_cells = 0; for (unsigned int i=0; i*>(timesteps[timestep])->init_for_refinement(); - + { + TimeStepBase* t = timesteps[timestep]; + static_cast*>(t)->init_for_refinement(); + } + unsigned int total_expected_cells = 0; for (unsigned int timestep=0; timestep *this_timestep - = static_cast*>(timesteps[timestep]); + = static_cast*>(t); this_timestep->wake_up (0); @@ -3051,11 +3058,11 @@ if (parameters.compare_indicators_globally) this_timestep->sleep (0); if (timestep!=0) - static_cast*>(timesteps[timestep-1])->sleep(1); + static_cast&>(*timesteps[timestep-1]).sleep(1); }; if (timesteps.size() != 0) - static_cast*>(timesteps.back())->sleep(1); + static_cast&>(*timesteps.back()).sleep(1); deallog << " Got " << total_number_of_cells << " presently, expecting " @@ -3083,9 +3090,9 @@ void TimestepManager::write_statistics (const SweepInfo &sweep_info) const { deallog << timesteps[timestep]->get_time() << " "; - dynamic_cast*> - (static_cast*> - (timesteps[timestep]))->write_statistics (logfile); + dynamic_cast&> + (static_cast&> + (*timesteps[timestep])).write_statistics (logfile); deallog << std::endl; };