Not all things you may want to do fit neatly into the list of plugins of the previous sections. Rather, there are cases where you may want to change things that are more of the one-off kind and that require code that is at a lower level and requires more knowledge about ASPECT’s internal workings. For such changes, we still want to stick with the general principle outlined at the beginning of Section 6: You should be able to make all of your changes and extensions in your own files, without having to modify ASPECT’s own sources.
To support this, ASPECT uses a “signals” mechanism. Signals are, in essence, objects that represent events, for example the fact that the solver has finished a time step. The core of ASPECT defines a number of such signals, and triggers them at the appropriate points. The idea of signals is now that you can connect to them: you can tell the signal that it should call a particular function every time the signal is triggered. The functions that are connected to a signal are called “slots” in common diction. One, several, or no slots may be connected to each signal.
There are two kinds of signals that ASPECT provides:
For both of these kinds, a user-written plugin file can (but does not need) to register functions that connect functions in this file (i.e., slots) to their respective signals.
In the first case, code that registers slots with global signals would look like this:
The second kind of signal can be connected to once a simulator object has been created. As above, one needs to define the slots, define a connector function, and register the connector function. The following gives an example:
As mentioned above, each signal may be connected to zero, one, or many slots. Consequently, you could have multiple plugins each of which connect to the same slot, or the connector function above may just connect multiple slots (i.e., functions in your program) to the same signal.
So what could one do in a place like this? One option would be to just monitor what is going on, e.g., in code like this that simply outputs into the statistics file (see Section 4.4.2):
This will produce, for every time step (because this is how often the signal is called) an entry in a new column in the statistics file that records the number of constraints. On the other hand, it is equally possible to also modify the constraints object at this point. An application would be if you wanted to run a simulation where you prescribe the velocity in a part of the domain, e.g., for a subducting slab (see Section 5.2.9).
Signals exist for various waypoints in a simulation and you can consequently monitor and change what is happening inside a simulation by connecting your own functions to these signals. It would be pointless to list here what signals actually exist – simply refer to the documentation of the SimulatorSignals class for a complete list of signals you can connect to.
As a final note, it is generally true that writing functions that can connect to signals require significantly more internal knowledge of the workings of ASPECT than writing plugins through the mechanisms outlined above. It also allows to affect the course of a simulation by working on the internal data structures of ASPECT in ways that are not available to the largely passive and reactive plugins discussed in previous sections. With this obviously also comes the potential for trouble. On the other hand, it also allows to do things with ASPECT that were not initially intended by the authors, and that would be hard or impossible to implement through plugins. An example would be to couple different codes by exchanging details of the internal data structures, or even update the solution vectors using information received from another code.
Rather, a more productive approach would be to either define a new signal that is triggered where you need it, and connect a function (slot) in your own plugin file to this signal using the mechanisms outlined above. Then send the code that defines and triggers the signal to the developers of ASPECT to make sure that it is also included in the next release. Alternatively, you can also simply ask on the mailing lists for someone to add such a signal in the place where you want it. Either way, adding signals is something that is easy to do, and we would much rather add signals than have people who modify the ASPECT source files for their own needs and are then stuck on a particular version.