aboria / Aboria

Enables computations over a set of particles in N-dimensional space
https://aboria.github.io/Aboria
Other
105 stars 30 forks source link

Question: is Aboria::Particles<>'s design similar to std::variant? #28

Closed Char-Aznable closed 6 years ago

Char-Aznable commented 6 years ago

What's the programming pattern behind Aboria::Particles<>'s capability to handle arbitrary number of types, e.g., position, velocity, id...? Just by skimming the code I found that it's kinda designed similarly to std::variant in c++17 or boost::variant -- just curious, is my guess correct?

martinjrobins commented 6 years ago

No, its more based on boost::zip_iterator or thrust::zip_iterator. I wanted to see if you could do a similar thing, but at the container level. That is have a vector container that was really just a zip'ed collection of other vectors (so each variable in Aboria would have its own lower-level vector container). Once the user supplies the type list of variables, you just use some meta-programming techniques to build up your zip container. Aboria enforces that the type list of variables is made up of unique types, so then you can use get<variable>(particles[i]) functions to access a single variable from the particle in index i.

Good news is that you can build up this zip container easily enough, bad news is that its not 100% STL compatible, in much the same reason that std::vector is not compatible because it uses proxy references. Note that the value_type of this container is something like std::tuple<T1,T2,T3,...>, but the reference is std::tuple<T1&,T2&,T3&,...>, so the reference type is not a reference of the value_type. But saying that, it does work fine for most situations.

Char-Aznable commented 6 years ago

That makes sense. Thanks for the explanation.