gvec[] doesn't work with plugins
Summary
When the gvec[] interface is used to attempt to output data from a state variable (SV) in a plugin, the program instead outputs SV data from the main ionic model.
What version of openCARP are you using?
master branch as of time of posting: SHA1 ID: 68e34868
What operating system and processor architecture are you using?
> uname -a
Linux frazier 4.15.0-130-generic #134-Ubuntu SMP Tue Jan 5 20:46:26 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Steps to reproduce
I attached a tarball with minimal examples. I have reproduced this bug with two plugins, one built-in (MacCannell_Fb_plug) and one dynamically loaded via the external_imp[] interface (my own IChR2 implementation).
What is the current bug behavior?
Consider the following example:
num_gvecs = 2
gvec[0].ID = Ca_i
gvec[0].name = TT2.Ca_i
gvec[1].imp = MacCannell_Fb_plug
gvec[1].ID = V_fb
gvec[1].name = FbPlug.Vm
The resulting output files are binary identical (they should not be!):
> diff GVecProblemTest/FbPlug.Vm.igb GVecProblemTest/TT2.Ca_i.igb
>
They are identical because I cherry-picked the Ca_i variable from the TT2. When I opened the GVecProblemTest/FbPlug.Vm.igb and I saw that the initial condition in all nodes was 0.07 (same as default value for Ca_i in uM), I suspected something was up. If you change the .ID parameters to different SV names, the igb files will differ.
I think what is happening is that the size of the memory block where base ionic model SVs live is not being taken into account when the gvec[] code tries to index into the memory where plugin SVs live.
What is the expected correct behavior?
The values over time of the requested SV in the plugin should be output :)
Relevant logs and/or screenshots
See attached + above.
Possible fixes
If I'm not mistaken, the issue is on/around L461 of physics/ionics.cc. If the requested SV is in plugin N, I think the memory offset needs to be added to the whole byte size of miif->iontypes[idx] plus the size of any preceding miif->plugtypes[idx][k] (where k < N). I have no idea how to fix this though, function pointers terrify me.