R7571/work/week14/particle-pybind/starting_pointf183e0755bc4master
starting_point
README.md
Overloaded createSimulation method
The original *createSimulation* method of the *MaterialPointsFactory* class had 2 main roles:
- create unique *System* and *SystemEvolution* objects, and filling the System object with particles parsed from an input file
- create specific *Compute* object(s) that are going to be called at each iteration of our simulation
The main drawback of this method is that the creation and registration of *Compute* objects for this factory is hard-coded, meaning that the user has no flexibility in the type / number of *Compute* objects to be called at runtime.
We would now like to be able to register those *Compute* objects from the main.py python script, such that the user can possibly decide which one(s) to consider by simply modifying this Python script, or even better, based on command line arguments.
This is done by overloading the *createSimulation* method with another declaration inside the class *MaterialPointsFactory*, taking a functor as an extra parameter. This functor object is registered as a method of the class, called *createComputes*, in charge of creating the *Compute* objects. The overloaded *createSimulation* method then calls the "original" one, which in turns calls the method *createComputes* method previously defined.
This mechanism allows to define which *Compute* objects are created and registered through the custom *createComputes* method defined in Python thanks to the *pybinder* functionalities.