]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
fixed subscription problems
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 22 May 2005 09:35:33 +0000 (09:35 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 22 May 2005 09:35:33 +0000 (09:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@10694 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/numerics/time_dependent.h
deal.II/deal.II/source/numerics/time_dependent.cc
tests/deal.II/wave-test-3.cc

index 138fcd6ee82c22b726091898f875b6a5a4a8b624..3d2b71e98dcc6b181b2d68296e42158784150bb6 100644 (file)
@@ -697,7 +697,7 @@ class TimeDependent
                                      * objects pointed to by the pointers
                                      * in this collection.
                                      */
-    std::vector<TimeStepBase*> timesteps;
+    std::vector<SmartPointer<TimeStepBase> > 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<dim>       *tria;
+    SmartPointer<Triangulation<dim> > 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<typename InitFunctionObject::argument_type>
-                            (timesteps[step]));
+                            (&*timesteps[step]));
              break;
        case backward:
              init_function (static_cast<typename InitFunctionObject::argument_type>
-                            (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<typename LoopFunctionObject::argument_type>
-                              (timesteps[step]));
+                              (&*timesteps[step]));
                break;
          case backward:
                loop_function (static_cast<typename LoopFunctionObject::argument_type>
-                              (timesteps[n_timesteps-step-1]));
+                              (&*timesteps[n_timesteps-step-1]));
                break;
        };
       
index 3a28e7f1d5e9f129b34b2ff00451a9154655a9eb..2c33d0c18c3c7a7d71d07a40c65bd4f75738cd26 100644 (file)
@@ -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<TimeStepBase*>::iterator insert_position
+       std::vector<SmartPointer<TimeStepBase> >::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 (position<timesteps.size(),
          ExcInvalidPosition());
-
-  timesteps[position]->unsubscribe(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<dim>::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<dim>::~TimeStepBase_Tria ()
 {
   if (!flags.delete_and_rebuild_tria)
     {
-      tria->unsubscribe(typeid(*this).name());
-      delete tria;
+      Triangulation<dim>* t = tria;
+      tria = 0;
+      delete t;
     }
   else
     Assert (tria==0, ExcInternalError());
@@ -471,11 +474,11 @@ TimeStepBase_Tria<dim>::sleep (const unsigned sleep_level)
       
       if (flags.delete_and_rebuild_tria)
        {
-         tria->unsubscribe(typeid(*this).name());
-         delete tria;
+         Triangulation<dim>* t = tria;
          tria = 0;
-       };
-    };
+         delete t;
+       }
+    }
 
   TimeStepBase::sleep (sleep_level);
 }
@@ -505,7 +508,6 @@ void TimeStepBase_Tria<dim>::restore_grid ()
                                   // create a virgin triangulation and
                                   // set it to a copy of the coarse grid
   tria = new Triangulation<dim> ();
-  tria->subscribe(typeid(*this).name());
   tria->copy_triangulation (*coarse_grid);
 
                                   // for each of the previous refinement
index b63a5a2805e0caaf251fcd4666a3a43566273bd3..f5898d02583eceb22f0c5b33978e6e00191bbdc5 100644 (file)
@@ -2858,11 +2858,12 @@ void TimestepManager<dim>::run_sweep (const unsigned int sweep_no)
   
   start_sweep (sweep_no);
 
-  for (std::vector<TimeStepBase*>::iterator timestep=timesteps.begin();
+  for (std::vector<SmartPointer<TimeStepBase> >::iterator timestep=timesteps.begin();
        timestep!=timesteps.end(); ++timestep)
     {
-      dynamic_cast<TimeStepBase_Wave<dim>*>(*timestep)->attach_sweep_info (sweep_info);
-      dynamic_cast<TimeStepBase_Wave<dim>*>(*timestep)->attach_sweep_data (sweep_data);
+      TimeStepBase* t = *timestep;
+      dynamic_cast<TimeStepBase_Wave<dim>*>(t)->attach_sweep_info (sweep_info);
+      dynamic_cast<TimeStepBase_Wave<dim>*>(t)->attach_sweep_data (sweep_data);
     };
   
   solve_primal_problem ();
@@ -2905,9 +2906,11 @@ const unsigned int n_timesteps = timesteps.size();
   std::vector<Vector<float> > indicators (n_timesteps);
       
   for (unsigned int i=0; i<n_timesteps; ++i)
-    static_cast<TimeStepBase_Wave<dim>*>(timesteps[i])
-      ->get_timestep_postprocess().get_tria_refinement_criteria (indicators[i]);
-
+    {
+      TimeStepBase* t = timesteps[i];
+      static_cast<TimeStepBase_Wave<dim>*>(t)
+       ->get_timestep_postprocess().get_tria_refinement_criteria (indicators[i]);
+    }
 
   unsigned int total_number_of_cells = 0;
   for (unsigned int i=0; i<timesteps.size(); ++i)
@@ -3003,14 +3006,18 @@ if (parameters.compare_indicators_globally)
       deallog << "    Refining each time step separately." << std::endl;
       
       for (unsigned int timestep=0; timestep<timesteps.size(); ++timestep)
-       static_cast<TimeStepBase_Tria<dim>*>(timesteps[timestep])->init_for_refinement();
-
+       {
+         TimeStepBase* t = timesteps[timestep];
+         static_cast<TimeStepBase_Tria<dim>*>(t)->init_for_refinement();
+       }
+      
       unsigned int total_expected_cells = 0;
       
       for (unsigned int timestep=0; timestep<timesteps.size(); ++timestep)
        {
+         TimeStepBase* t = timesteps[timestep];
          TimeStepBase_Wave<dim> *this_timestep
-           = static_cast<TimeStepBase_Wave<dim>*>(timesteps[timestep]);
+           = static_cast<TimeStepBase_Wave<dim>*>(t);
            
          this_timestep->wake_up (0);
 
@@ -3051,11 +3058,11 @@ if (parameters.compare_indicators_globally)
 
          this_timestep->sleep (0);
          if (timestep!=0)
-           static_cast<TimeStepBase_Tria<dim>*>(timesteps[timestep-1])->sleep(1);
+           static_cast<TimeStepBase_Tria<dim>&>(*timesteps[timestep-1]).sleep(1);
        };
       
       if (timesteps.size() != 0)
-       static_cast<TimeStepBase_Tria<dim>*>(timesteps.back())->sleep(1);
+       static_cast<TimeStepBase_Tria<dim>&>(*timesteps.back()).sleep(1);
 
 
 deallog << "    Got " << total_number_of_cells << " presently, expecting "
@@ -3083,9 +3090,9 @@ void TimestepManager<dim>::write_statistics (const SweepInfo &sweep_info) const
        {
          deallog << timesteps[timestep]->get_time()
               << "   ";
-         dynamic_cast<TimeStep<dim>*>
-           (static_cast<TimeStepBase_Wave<dim>*>
-            (timesteps[timestep]))->write_statistics (logfile);
+         dynamic_cast<TimeStep<dim>&>
+           (static_cast<TimeStepBase_Wave<dim>&>
+            (*timesteps[timestep])).write_statistics (logfile);
          deallog << std::endl;
        };
 

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.