@aldomann
Thank-you for bringing an interesting problem to the forum and for posting your code. Just a few comments on the latest version - from inspection. I appreciate that you haven't yet made the changes we have flooded you with.
int neurons = pow(10, 4);
pow() returns a double, with possible floating-point inaccuracy. Better just to write
int neurons =10000;
Lines like
1 2
|
double eta[neurons];
double I[steps+1];
|
would be rejected by a standards-compliant compiler - the array size needs to be known at compile-time. You use vector elsewhere - why not use it here?
In
eta[n] = tan(M_PI*(((double) rand() / (RAND_MAX))- 1/2 )) - 5;
I'm afraid that 1/2 will do integer division ... and always result in 0. Better just to write 0.5 explicitly.
std::fill_n(I, steps+1, I0);
If I is a constant ... then save memory and code it just as the constant I0. Even if you are leaving open the possibility of subsequently having a time-dependent current then you could do it by a function call, rather than a pre-filled array. It only need be evaluated once per i-loop.
You still don't need a 2-dimensional vector v - just 2 time levels will suffice.
With v_avg[] I meant having a file open and writing the value (just of scalar v_avg at the end of each timestep), not storing to the end and then writing.
For the refractory period, perhaps set a vector<int> nextfire(neurons) which you set when the potential drops back to -vp.
However, my biggest questions are these.
(1) Why do you need arrays at all, multi-dimensional or otherwise? At the moment your nth neuron doesn't interact with any others and you could just do 10000 simulations sequentially. Is the interaction between neurons something that you are going to add later?
(2) Just a comment, but if I[] is constant and you have no interactions between neurons (as at present) the equation being solved in line 65 is
dv/dt = (v
2 + constant)
This can be solved exactly without the need for numerical solution. (This will change if I[] ceases to be constant, or if you allow interaction between neurons - maybe this is something you are going to add.)