Skip to content

Commit b7d12ee

Browse files
authored
Merge pull request #6870 from bangerth/observer-pointer
Let SimulatorAccess store an observer pointer to Simulator.
2 parents 95797cd + 1d1aa58 commit b7d12ee

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

include/aspect/compat.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ namespace aspect
6464
#endif
6565

6666

67+
#if !DEAL_II_VERSION_GTE(9,7,0)
68+
/**
69+
* A type alias for the SmartPointer class that makes sure the new
70+
* name of the class, ObserverPointer, can be used in all versions of
71+
* deal.II. The SmartPointer class was renamed to ObserverPointer in
72+
* deal.II 9.7.
73+
*/
74+
template <typename T, typename P = void>
75+
using ObserverPointer = dealii::SmartPointer<T, P>;
76+
77+
/**
78+
* Same for the transition from Subscriptor to EnableObserverPointer.
79+
*/
80+
using EnableObserverPointer = dealii::Subscriptor;
81+
#endif
82+
6783

6884
// deal.II versions up to 9.5 had a poorly designed interface of the
6985
// SphericalManifold class that made it impossible for us to use.

include/aspect/simulator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ namespace aspect
197197
* @ingroup Simulator
198198
*/
199199
template <int dim>
200-
class Simulator
200+
class Simulator : public EnableObserverPointer
201201
{
202202
public:
203203
/**

include/aspect/simulator_access.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ namespace aspect
223223
* Destructor. Does nothing but is virtual so that derived classes
224224
* destructors are also virtual.
225225
*/
226-
virtual ~SimulatorAccess () = default;
226+
virtual ~SimulatorAccess ();
227227

228228
/**
229229
* Initialize this class for a given simulator. This function is marked
@@ -1081,7 +1081,7 @@ namespace aspect
10811081
/**
10821082
* A pointer to the simulator object to which we want to get access.
10831083
*/
1084-
const Simulator<dim> *simulator;
1084+
ObserverPointer<const Simulator<dim>, SimulatorAccess<dim>> simulator;
10851085
};
10861086
}
10871087

source/particle/property/cpo_bingham_average.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <aspect/particle/manager.h>
2323

2424
#include <aspect/utilities.h>
25+
#include <aspect/simulator.h>
2526

2627
namespace aspect
2728
{

source/simulator/simulator_access.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ namespace aspect
4949

5050

5151

52+
// Define the destructor as defaulted. One might have wanted to do that in
53+
// the header file, but that requires all member variables to be complete
54+
// types (in particular, the Simulator class), which is not the casein the
55+
// .h file.
56+
template <int dim>
57+
SimulatorAccess<dim>::~SimulatorAccess () = default;
58+
59+
60+
5261
template <int dim>
5362
void
5463
SimulatorAccess<dim>::initialize_simulator (const Simulator<dim> &simulator_object)

unit_tests/particles.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,39 @@
2121
#include "common.h"
2222
#include <aspect/particle/property/interface.h>
2323
#include <aspect/particle/manager.h>
24+
#include <aspect/simulator.h>
2425
#include <deal.II/base/parameter_handler.h>
2526

2627
TEST_CASE("Particle Manager plugin names")
2728
{
29+
// The Particle::Property::Manager needs to know about the Simulator object,
30+
// so we need to create a dummy one to initialize the manager. That, in
31+
// turn, needs to be initialized with a ParameterHandler, so we create one
32+
// and fill it with the minimum information needed to create a Simulator object.
33+
aspect::ParameterHandler sim_prm;
34+
aspect::Simulator<2>::declare_parameters(sim_prm, 0);
35+
{
36+
sim_prm.enter_subsection("Geometry model");
37+
sim_prm.set("Model name", "box");
38+
sim_prm.leave_subsection();
39+
}
40+
{
41+
sim_prm.enter_subsection("Material model");
42+
sim_prm.set("Model name", "simple");
43+
sim_prm.leave_subsection();
44+
}
45+
{
46+
sim_prm.enter_subsection("Gravity model");
47+
sim_prm.set("Model name", "vertical");
48+
sim_prm.leave_subsection();
49+
}
50+
aspect::Simulator<2> dummy_sim (MPI_COMM_SELF, sim_prm);
51+
52+
// Now create a Particle::Property::Manager and initialize it with the dummy simulator.
2853
dealii::ParameterHandler prm;
2954
aspect::Particle::Property::Manager<2> manager;
55+
manager.initialize_simulator (dummy_sim);
56+
3057
// The property manager needs to know about the integrator, which is declared in World
3158
aspect::Particle::Manager<2>::declare_parameters(prm);
3259

0 commit comments

Comments
 (0)