colvars icon indicating copy to clipboard operation
colvars copied to clipboard

Use map of output streams, and return references to its elements

Open giacomofiorin opened this issue 2 years ago • 1 comments

As mentioned in the conversation for #481, update the registry of output files to use a std::map rather than two paired lists, which are no longer worth using any more.

giacomofiorin avatar Jul 11 '22 18:07 giacomofiorin

To summarize, I got confused a bit about which functions need to be overridden and which overloaded. The former gets a little tricky depending on the compiler. Eventually I fixed my mistakes and squashed them and the fixes back into one commit.

Since we're dealing with a class template (colvar_grid<...>) as a base, we're not really using base-class pointers and vtables, except in three cases (value_input(), value_output() and the destructor). But even those don't need to be virtual, either. I'd like to simplify this if possible, and instantiate them explicitly in the derived classes before moving on with this PR. Comments welcome, especially when concerning the ABF code.

giacomofiorin avatar Jul 12 '22 16:07 giacomofiorin

@jhenin I addressed your comment, feel free to look again but do keep in mind that this is still a draft.

Before finishing it, I would like to eliminate the last remaining virtual functions from the colvar_grid class template. Are you okay with that? Do the existing ABF tests cover a reasonable combination of features?

giacomofiorin avatar Nov 02 '22 13:11 giacomofiorin

I think the tests should do the job, yes.

jhenin avatar Nov 07 '22 17:11 jhenin

@jhenin I have reconsidered switching from deriving the class template to instantiating an object of it. Replacing the many existing member functions with wrappers around the instantiated object would be tedious but conceptually simple.

But then there's the trickier issue that read_raw and write_raw need internally to call the derived functions value_input() and value_output(). They need to do that because colvar_grid_gradient and colvar_grid_count are intertwined, and need to call each other at a relatively low level. Changing that design seems possible, but beyond scope for this PR.

Tests pass, I'll just update the Actions workflow because GitHub is nagging and wrap this up.

giacomofiorin avatar Jan 26 '23 00:01 giacomofiorin