dmorse / pscfpp

Polymer Self-Consistent Field Theory (C++/CUDA version)
https://pscf-home.cems.umn.edu
GNU General Public License v3.0
25 stars 20 forks source link

Move Iterator::setParameterTypes -> ParameterModifier::getParameterTypes #184

Closed benmagruder closed 2 weeks ago

benmagruder commented 2 weeks ago

In our previous implementation of the ParameterModifier feature, ParameterModifier had two methods, setParameter and getParameter. The subclasses of ParameterModifier were responsible for creating a method to add the specialized parameter(s) to the Sweep object. For example, rpc::Iterator has a virtual method called addParameterTypes, which is called by rpc::Sweep in its constructor method to add any specialized sweep parameters from the Iterator. This was OK, but I felt like it would be more appropriate if ParameterModifier itself contained a (virtual) method that was responsible for adding the specialized sweep parameters to the Sweep object. This way, all of the operations that are necessary for a ParameterModifier to work properly are actually laid out in the base class, rather than being left for the subclasses to define separately. This change will also make future development on the thin film code easier, so I decided to make the change.

The primary barrier to making this change was that the ParameterModifier needed to know the class type of the Sweep object to which it should send its ParameterTypes. In the pscf namespace, the only Sweep class is the SweepTmpl<State> template class, which requires a template parameter that we do not know. Therefore, it is easier to find a way for the ParameterModifier to send its ParameterTypes without any knowledge of the Sweep object. This is achieved in this pull request by the method ParameterModifier::getParameterTypes(), which requires no input parameters and returns a DArray<ParameterType> that contains all of the ParameterType objects associated with this ParameterModifier. A Sweep object must then have a method called addParameterTypes(DArray<ParameterType>) that can accept a DArray of ParameterType objects and add them all to its own parameterTypes_ array. Then, the Sweep class can retrieve the ParameterType objects from the Iterator with one line of code, just as it did before: addParameterTypes(system().iterator().getParameterTypes())

This change is preferable over the previous version of ParameterModifier, because now the ParameterModifier does not need to know anything about the system's Sweep object, and because it now contains a virtual method getParameterTypes() that defines the way in which subclasses will provide their ParameterType objects to the Sweep.

All unit tests have been ran, and they all pass.