From 426575aadce34887b714ec71b55f7d7325ddb0a4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 18 Aug 1999 13:37:03 +0000 Subject: [PATCH] Change the way timesteps are inserted since the old way was not so useful when it came to adding timesteps in the middle. git-svn-id: https://svn.dealii.org/trunk@1712 0785d39b-7218-0410-832d-ea1e28bc413d --- .../deal.II/include/numerics/time_dependent.h | 32 +++++++++---------- .../deal.II/source/numerics/time_dependent.cc | 30 ++++++++++------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/deal.II/deal.II/include/numerics/time_dependent.h b/deal.II/deal.II/include/numerics/time_dependent.h index 4c58be489b..008254309c 100644 --- a/deal.II/deal.II/include/numerics/time_dependent.h +++ b/deal.II/deal.II/include/numerics/time_dependent.h @@ -436,10 +436,12 @@ class TimeDependent /** * Add a timestep at any position. The - * position may be zero (at the start) - * through #N# (at the end), where - * #N# is the number of timesteps - * stored in this object previously. + * position is a pointer to an existing + * time step object, or a null pointer + * denoting the end of the timestep + * sequence. If #position# is non-null, + * the new time step will be inserted + * before the respective element. * * Note that by giving an object * to this function, the @@ -447,12 +449,6 @@ class TimeDependent * ownership of the object; it will * therefore also take care of * deletion of the objects its manages. - * This mechanism usually will result - * in a set-up loop like this - * \begin{verbatim} - * for (i=0; isubscribe(); @@ -55,7 +55,7 @@ TimeDependent::insert_timestep (TimeStepBase *new_timestep, // first insert the new time step // into the doubly linked list // of timesteps - if (position == timesteps.size()) + if (position == 0) { // at the end new_timestep->set_next_timestep (0); @@ -68,7 +68,7 @@ TimeDependent::insert_timestep (TimeStepBase *new_timestep, new_timestep->set_previous_timestep (0); } else - if (position == 0) + if (position == timesteps[0]) { // at the beginning new_timestep->set_previous_timestep (0); @@ -83,14 +83,20 @@ TimeDependent::insert_timestep (TimeStepBase *new_timestep, else { // inner time step - timesteps[position-1]->set_next_timestep (new_timestep); - new_timestep->set_next_timestep (timesteps[position]); - timesteps[position]->set_previous_timestep (new_timestep); + vector::iterator insert_position + = find(timesteps.begin(), timesteps.end(), position); + + (*(insert_position-1))->set_next_timestep (new_timestep); + new_timestep->set_next_timestep (*insert_position); + (*insert_position)->set_previous_timestep (new_timestep); }; // finally enter it into the // array - timesteps.insert (×teps[position], new_timestep); + timesteps.insert ((position == 0 ? + timesteps.end() : + find(timesteps.begin(), timesteps.end(), position)), + new_timestep); }; @@ -98,7 +104,7 @@ TimeDependent::insert_timestep (TimeStepBase *new_timestep, void TimeDependent::add_timestep (TimeStepBase *new_timestep) { - insert_timestep (new_timestep, timesteps.size()); + insert_timestep (0, new_timestep); }; @@ -106,7 +112,7 @@ TimeDependent::add_timestep (TimeStepBase *new_timestep) void TimeDependent::delete_timestep (const unsigned int position) { Assert (positionunsubscribe(); delete timesteps[position]; -- 2.39.5