Skip to content

Manipulators

Stephen Berry edited this page Jun 30, 2016 · 2 revisions

What is a Manipulator in Ascent?

  • A Manipulator is a Module (a class that inherits from asc::Module)
  • A Manipulator is instantiated via the addManipulator() method in asc::Module
  • A Manipulator's memory is owned by the Module that instantiates it
  • A Manipulator's memory can be shared, but often shouldn't be
  • A Manipulator is designed to manipulate one or more variables within the Module that instantiates it

The purpose of a manipulator is to have a standard method of designing and using modules that are intended to manipulate other module's variables without the module knowing that it is being manipulated. And, without the manipulator module knowing anything about the module it is manipulating. This allows the design of highly generic code.

See Ascent Statistics for modules that also function as manipulators.

Snippet of Statistics example:

   Tester tester(sim);
   asc::Link<Normal> normal = tester.addManipulator<Normal>(sim, 5.0, 2.0);
   normal->variable = &tester.x;

The Tester class is a module with a variable x. The addManipulator() method makes the Tester class own a std::shared_ptr to the stats::Normal module and sets up ordering such that the Normal distribution module will run before Tester.

Manipulators can only be designed to run before the module they are manipulating, so they will only have fully defined ordering with algorithms in their update() and/or postcalc() methods. If asynchronous ordering is acceptable, implementing other phase methods in the manipulator can be fine.

Why use manipulators if they have so many limitations?

  • They allow driving modules (manipulators) to be deleted when the module they are manipulating is destroyed.
  • They allow two completely separate modules to work together without needing any includes or class information.
  • Manipulator modules can be designed to work just like normal modules without the use of addManipulator() (see statistical modules).
Clone this wiki locally