//! Initialises the model by reading in the regions and checking recording //! data. //! \param[out] timer_period a pointer for the memory address where the timer //! period should be stored during the function. //! \param[out] update_sdp_port The SDP port on which to listen for rate //! updates //! \return boolean of True if it successfully read all the regions and set up //! all its internal data structures. Otherwise returns False static bool initialize() { log_info("Initialise: started"); // Get the address this core's DTCM data starts at from SRAM address_t address = data_specification_get_data_address(); // Read the header if (!data_specification_read_header(address)) { return false; } // Get the timing details and set up the simulation interface if (!simulation_initialise( data_specification_get_region(SYSTEM, address), APPLICATION_NAME_HASH, &timer_period, &simulation_ticks, &infinite_run, SDP, DMA)) { return false; } simulation_set_provenance_data_address( data_specification_get_region(PROVENANCE_REGION, address)); // setup recording region if (!initialise_recording()){ return false; } // Setup regions that specify spike source array data if (!read_global_parameters( data_specification_get_region(POISSON_PARAMS, address))) { return false; } if (!read_poisson_parameters( data_specification_get_region(POISSON_PARAMS, address))) { return false; } // Loop through slow spike sources and initialise 1st time to spike for (index_t s = 0; s < global_parameters.n_spike_sources; s++) { if (!poisson_parameters[s].is_fast_source) { poisson_parameters[s].time_to_spike_ticks = slow_spike_source_get_time_to_spike( poisson_parameters[s].mean_isi_ticks); } } // print spike sources for debug purposes // print_spike_sources(); // Set up recording buffer n_spike_buffers_allocated = 0; n_spike_buffer_words = get_bit_field_size( global_parameters.n_spike_sources); spike_buffer_size = n_spike_buffer_words * sizeof(uint32_t); log_info("Initialise: completed successfully"); return true; }
void read_keywords_and_parameters(char const* filename, FILE* infile, fpos_t startpos) { print_model_parameters(g_param.kim_model_params); fsetpos(infile, &startpos); read_global_parameters(infile, filename); fsetpos(infile, &startpos); if (g_param.kim_model_params == KIM_MODEL_PARAMS_NONE) read_cutoff_parameter(infile, filename); }
void read_pot_table0(char const* potential_filename, FILE* pfile) { apot_state state; apot_table_t* apt = &g_pot.apot_table; pot_table_t* pt = &g_pot.opt_pot; state.filename = potential_filename; state.pfile = pfile; // save starting position fgetpos(pfile, &state.startpos); // initialize the function table for analytic potentials initialize_analytic_potentials(); read_chemical_potentials(&state); read_elstat_table(&state); read_global_parameters(&state); read_analytic_potentials(&state); #if defined(COULOMB) apt->total_ne_par = apt->total_par; #endif // COULOMB /* if we have global parameters, are they actually used ? */ if (g_pot.have_globals) { int use_count = 0; for (int i = 0; i < apt->globals; i++) use_count += apt->n_glob[i]; if (use_count == 0) { g_pot.have_globals = 0; printf("You defined global parameters but did not use them.\n"); printf("Disabling global parameters.\n\n"); } } /* assign the potential functions to the function pointers */ if (apot_assign_function_pointers(apt) == -1) error(1, "Could not assign the function pointers.\n"); #if defined(PAIR) if (g_param.enable_cp) { g_pot.cp_start = apt->total_par - apt->globals + g_param.ntypes * (g_param.ntypes + 1); apt->total_par += (g_param.ntypes + g_param.compnodes - apt->invar_par[apt->number][g_param.ntypes]); } #endif // PAIR #if defined(COULOMB) apt->total_par += g_param.ntypes; #endif // COULOMB #if defined(DIPOLE) apt->total_par += g_param.ntypes * (g_param.ntypes + 2); #endif // DIPOLE /* initialize function table and write indirect index */ for (int i = 0; i < apt->number; i++) { pt->begin[i] = apt->begin[i]; pt->end[i] = apt->end[i]; pt->step[i] = 0; pt->invstep[i] = 0; if (i == 0) pt->first[i] = 2; else pt->first[i] = pt->last[i - 1] + 3; pt->last[i] = pt->first[i] + apt->n_par[i] - 1; } pt->len = pt->first[apt->number - 1] + apt->n_par[apt->number - 1]; if (g_pot.have_globals) pt->len += apt->globals; #if defined(PAIR) if (g_param.enable_cp) { pt->len += (g_param.ntypes + g_param.compnodes); } #endif // PAIR #if defined(COULOMB) pt->len += 2 * g_param.ntypes - 1; #endif // COULOMB #if defined(DIPOLE) pt->len += g_param.ntypes * (g_param.ntypes + 2); #endif // DIPOLE pt->table = (double*)Malloc(pt->len * sizeof(double)); g_pot.calc_list = (double*)Malloc(pt->len * sizeof(double)); pt->idx = (int*)Malloc(pt->len * sizeof(int)); apt->idxpot = (int*)Malloc(apt->total_par * sizeof(int)); apt->idxparam = (int*)Malloc(apt->total_par * sizeof(int)); /* this is the indirect index */ int k = 0; int l = 0; double* val = pt->table; double* list = g_pot.calc_list; for (int i = 0; i < apt->number; i++) { /* loop over potentials */ val += 2; list += 2; l += 2; for (int j = 0; j < apt->n_par[i]; j++) { /* loop over parameters */ *val = apt->values[i][j]; *list = apt->values[i][j]; val++; list++; if (!g_pot.invar_pot[i] && !apt->invar_par[i][j]) { pt->idx[k] = l++; apt->idxpot[k] = i; apt->idxparam[k++] = j; } else l++; } if (!g_pot.invar_pot[i]) pt->idxlen += apt->n_par[i] - apt->invar_par[i][apt->n_par[i]]; apt->total_par -= apt->invar_par[i][apt->n_par[i]]; } #if defined(PAIR) if (g_param.enable_cp) { init_chemical_potential(g_param.ntypes); int i = apt->number; for (int j = 0; j < (g_param.ntypes + g_param.compnodes); j++) { *val = apt->values[i][j]; val++; if (!apt->invar_par[i][j]) { pt->idx[k] = l++; apt->idxpot[k] = i; apt->idxparam[k++] = j; } } pt->idxlen += (g_param.ntypes + g_param.compnodes - apt->invar_par[apt->number][g_param.ntypes]); g_pot.global_idx += (g_param.ntypes + g_param.compnodes - apt->invar_par[apt->number][g_param.ntypes]); } #endif // PAIR #if defined(COULOMB) int i = apt->number; for (int j = 0; j < (g_param.ntypes - 1); j++) { *val = apt->values[i][j]; val++; if (!apt->invar_par[i][j]) { pt->idx[k] = l++; apt->idxpot[k] = i; apt->idxparam[k++] = j; } else { l++; apt->total_par -= apt->invar_par[i][j]; pt->idxlen -= apt->invar_par[i][j]; } } i = apt->number + 1; *val = apt->values[i][0]; val++; if (!apt->invar_par[i][0]) { pt->idx[k] = l++; apt->idxpot[k] = i; apt->idxparam[k++] = 0; } else { l++; apt->total_par -= apt->invar_par[i][0]; pt->idxlen -= apt->invar_par[i][0]; } pt->idxlen += g_param.ntypes; #endif // COULOMB #if defined(DIPOLE) i = apt->number + 2; for (int j = 0; j < (g_param.ntypes); j++) { *val = apt->values[i][j]; val++; if (!apt->invar_par[i][j]) { pt->idx[k] = l++; apt->idxpot[k] = i; apt->idxparam[k++] = j; } else { l++; apt->total_par -= apt->invar_par[i][j]; pt->idxlen -= apt->invar_par[i][j]; } } for (i = apt->number + 3; i < apt->number + 5; i++) { for (int j = 0; j < (g_param.ntypes * (g_param.ntypes + 1) / 2); j++) { *val = apt->values[i][j]; val++; if (!apt->invar_par[i][j]) { pt->idx[k] = l++; apt->idxpot[k] = i; apt->idxparam[k++] = j; } else { l++; apt->total_par -= apt->invar_par[i][j]; pt->idxlen -= apt->invar_par[i][j]; } } } pt->idxlen += g_param.ntypes * (g_param.ntypes + 2); #endif // DIPOLE if (g_pot.have_globals) { int i = g_pot.global_pot; for (int j = 0; j < apt->globals; j++) { *val = apt->values[i][j]; *list = apt->values[i][j]; val++; list++; if (!apt->invar_par[i][j]) { pt->idx[k] = l++; apt->idxpot[k] = i; apt->idxparam[k++] = j; } else l++; } pt->idxlen += apt->globals - apt->invar_par[i][apt->globals]; apt->total_par -= apt->invar_par[i][apt->globals]; } g_pot.global_idx += pt->last[apt->number - 1] + 1; #if defined(NOPUNISH) if (g_param.opt) warning("Gauge degrees of freedom are NOT fixed!\n"); #endif // NOPUNISH check_correct_apot_functions(); init_calc_table0(); return; }