* 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
* such a behaviour is specified
* in the @p flags structure.
*/
- Triangulation<dim> *tria;
+ SmartPointer<Triangulation<dim> > tria;
/**
* Pointer to a grid which is to
{
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;
};
{
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;
};
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
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);
{
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
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)
{
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());
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);
}
// 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
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 ();
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)
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);
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 "
{
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;
};