I use a C++ subroutine for the GFORCEs in one of my models. There are three GFORCEs in the model and as such, the same subroutine is called multiple times at the same timestep. I want to make sure that the values of certain variables are not mixed between forces so I used global variables for these.
My question is, if I define the initial value for a global variable inside the main(), will that be called only once when loading the .dll, or will it never be called if I dont explicitly do so?
Also, since I also want to use a unique number (such as the force ID) when initializing these global variables, is the id made avalaible to the before actually calling the force function insed the dll?
Use the IFLAG to set initial values. You might get several calls when IFLAG is true, but all before start of the simulation.
It is bad habit to hardcode initial values, better to send the value as a parameter to the subroutine.
Use the ID to index all global data. Build an index when IFLAG is called by looping over an array ID_index (for example). If ID does not exist in ID_index, append ID. Then at each call check the index for ID in ID_index and you have your index into all global arrays. No problem using this method even with hundreds of GForces using the same subroutine.