int LIF_update(PVLayer *l) { int i; float r = 0.0; float phiAve = 0.0, phiMax = FLT_MIN, phiMin = FLT_MAX; float VAve = 0.0, VMax = FLT_MIN, VMin = FLT_MAX; for (i = 0; i < l->numNeurons; i++) { if (pv_random_prob() < PARAMS(LIF_NOISE_FREQ)) { r = PARAMS(LIF_NOISE_AMP) * 2 * (pv_random_prob() - 0.5); } else r = 0.0; l->V[i] += PARAMS(LIF_DT_d_TAU) * (r + l->phi[PHI0][i] - l->V[i]); l->V[i] = (l->V[i] < PARAMS(LIF_V_Min)) ? PARAMS(LIF_V_Min) : l->V[i]; // hard lower limit // Gather some statistics // TODO - take into account extended border phiAve += l->phi[0][i]; if (l->phi[PHI0][i] < phiMin) phiMin = l->phi[PHI0][i]; if (l->phi[PHI0][i] > phiMax) phiMax = l->phi[PHI0][i]; VAve += l->V[i]; if (l->V[i] < VMin) VMin = l->V[i]; if (l->V[i] > VMax) VMax = l->V[i]; //pv_log("V1 PHI %d=%f\n", i, phi[i]); // TODO - take into account extended border l->phi[PHI0][i] = 0.0; } #ifdef DEBUG_OUTPUT { char msg[128]; sprintf(msg, "IF1: phi: Max: %1.4f, Avg=%1.4f Min=%1.4f\n", phiMax, phiAve / l->numNeurons, phiMin); pv_log(stderr, msg); sprintf(msg, "IF1: V : Max: %1.4f, Avg=%1.4f Min=%1.4f\n", VMax, VAve / l->numNeurons, VMin); pv_log(stderr, msg); } #endif update_f(l); return 0; }
int main(int argc, char* argv[]){ // Input for initial condition input* inputData = new input; // Read input file inputData->readInputFile(); N = inputData->getN(); // Number of CVs CFL = inputData->getCFL(); // CFL Number double h = 1.0/N; // delta x double curr_time = 0; // Keep track of current time int count=0; // Count for no. of time steps int M = 3*N/CFL; // Estimated number of time-levels // Allocate the arrays double** w = AllocateDynamicArray(3,N); // State vector double** f = AllocateDynamicArray(3,N); // Flux vector double** rho = AllocateDynamicArray(M,N); // Density double** E = AllocateDynamicArray(M,N); // Total energy double** e = AllocateDynamicArray(M,N); // Specific internal energy double** p = AllocateDynamicArray(M,N); // Pressure double** Mach = AllocateDynamicArray(M,N); // Mach Number double** u = AllocateDynamicArray(M,N); // Velocity //Initial condition Initialize_w(inputData,w,h); Initialize_f(inputData,f,h); cout << "\nInitial time step: "<<tau(w,h)<<endl; //Calculation of w at next time steps while(curr_time<=inputData->getTime()){ //Current time curr_time = curr_time + tau(w,h); //Solve for vector w solve(inputData, w, f, h); //Update vector f with new values of vector w update_f(f,w); //Extract flow variables from vector w for(int j=0;j<N;j++){ rho[count][j] = w[0][j]; u[count][j] = w[1][j]/rho[count][j]; E[count][j] = w[2][j]; p[count][j] = 0.4*(E[count][j] - 0.5*rho[count][j]*u[count][j]*u[count][j]); e[count][j] = w[2][j]/rho[count][j] - 0.5*u[count][j]*u[count][j]; Mach[count][j] = u[count][j]/SQRT(1.4*p[count][j]/rho[count][j]); } //Count number of time steps count++; cout<<"\nTime step No. : "<<count<<"\tTime = "<<curr_time<<endl; } PrintFlowVariables(inputData, rho, u, E, e, p, Mach, count, h); cout<<"\nNumber of time steps = "<<count<<endl; cout<<"\nCurrent time = "<<curr_time<<endl; FreeDynamicArray(w); FreeDynamicArray(f); FreeDynamicArray(rho); FreeDynamicArray(E); FreeDynamicArray(e); FreeDynamicArray(p); FreeDynamicArray(u); FreeDynamicArray(Mach); delete inputData; return 0; }