]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Change the way timesteps are inserted since the old way was not so useful when it...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 18 Aug 1999 13:37:03 +0000 (13:37 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 18 Aug 1999 13:37:03 +0000 (13:37 +0000)
git-svn-id: https://svn.dealii.org/trunk@1712 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/numerics/time_dependent.h
deal.II/deal.II/source/numerics/time_dependent.cc

index 4c58be489ba1a869f063e47a73d83eae2d9da704..008254309ca20961541dd4872caeaeeb12ccf399 100644 (file)
@@ -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; i<N; ++i)
-                                     *   manager.add_timestep(new MyTimeStep());
-                                     * \end{verbatim}
                                      *
                                      * There is another function,
                                      * #add_timestep#, which inserts a
@@ -470,12 +466,19 @@ class TimeDependent
                                      * one can always use the timestep numbers
                                      * that were used in the previous sweep.
                                      */
-    void insert_timestep (TimeStepBase      *new_timestep,
-                         const unsigned int position);
+    void insert_timestep (const TimeStepBase *position,
+                         TimeStepBase       *new_timestep);
 
                                     /**
                                      * Just like #insert_timestep#, but
                                      * insert at the end.
+                                     *
+                                     * This mechanism usually will result
+                                     * in a set-up loop like this
+                                     * \begin{verbatim}
+                                     * for (i=0; i<N; ++i)
+                                     *   manager.add_timestep(new MyTimeStep());
+                                     * \end{verbatim}
                                      */
     void add_timestep (TimeStepBase *new_timestep);
 
@@ -630,10 +633,7 @@ class TimeDependent
                                     /**
                                      * Exception.
                                      */
-    DeclException2 (ExcInvalidPosition,
-                   int, int,
-                   << "Can\'t insert time step at position " << arg1
-                    << " since there only " << arg2 << " positions at all.");
+    DeclException0 (ExcInvalidPosition);
     
   protected:
                                     /**
index 07145e4f847c7f9cd83f1f09eb3799b3bffa3bb5..1e34d7e5b70420698382be97f843f9028a060064 100644 (file)
@@ -43,11 +43,11 @@ TimeDependent::~TimeDependent ()
 
 
 void
-TimeDependent::insert_timestep (TimeStepBase      *new_timestep,
-                               const unsigned int position
+TimeDependent::insert_timestep (const TimeStepBase *position,
+                               TimeStepBase       *new_timestep
 {
-  Assert (position<=timesteps.size(),
-         ExcInvalidPosition(position, timesteps.size()));
+  Assert (find(timesteps.begin(), timesteps.end(), position) != timesteps.end(),
+         ExcInvalidPosition());
 
                                   // lock this timestep from deletion
   new_timestep->subscribe();
@@ -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<TimeStepBase*>::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 (&timesteps[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 (position<timesteps.size(),
-         ExcInvalidPosition(position, timesteps.size()));
+         ExcInvalidPosition());
 
   timesteps[position]->unsubscribe();
   delete timesteps[position];

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.