RustBCA icon indicating copy to clipboard operation
RustBCA copied to clipboard

[feature] re-implement interactions as trait objects

Open drobnyjt opened this issue 4 years ago • 1 comments
trafficstars

Right now, the interaction potentials are wrapped in layers of hand-typed match statements that appropriately yield the DOCA function, derivative of the DOCA function, etc. for each potential - thinking about keeping the code modular, I think it might make sense to rewrite it all as Interaction objects that implement an Interaction trait, including yielding the various functions. Maybe some operator overloading so that Interaction can be called like a function would be neat?

drobnyjt avatar Apr 05 '21 15:04 drobnyjt

This change is for the best, but it will require more work than I think I originally thought. Here's a to-do list for when I attempt this:

  • write an Interaction trait
  • write structs for ScreenedCoulomb, Spline, Polynomial, Exponential interactions that implement Interaction and new for building from enums/input file
  • refactor bca code to use structs that implement Interaction
  • write wrappers in input.rs that build the common Interactions (e.g., Kr-C) from the existing keywords to maintain backwards compatibility, as well as include the option to define your own manually
  • implement Fn trait from std so that the interactions can be called really easily:
kr_c = ScreenedCoulomb::new(...);
///if ScreenedCoulomb implements Fn, I could write:
kr_c(Z1, Z2, a, r) ///to get immediate access to the interaction potential

drobnyjt avatar Mar 14 '22 17:03 drobnyjt