izhikevich.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /*
  2. * izhikevich.cpp
  3. *
  4. * This file is part of the Izhikevich console application.
  5. *
  6. * Copyright (C) 2016, Author: Guido Trensch
  7. *
  8. * The Izhikevich console application is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * It is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this application. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  23. // = IZHIKEVICH MODEL
  24. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  25. // =
  26. // = compile with:
  27. // = g++ main.cpp -o izhikevich -I/usr/include/plplot -lplplotcxxd -lplplotd
  28. // =
  29. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  30. #include <plstream.h>
  31. #include <iostream>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <math.h>
  35. #include <cstring>
  36. #include "izhikevich.h"
  37. #include "izhikevich_model.h"
  38. #include "ode_solvers.h"
  39. #define PRINT_DEBUG printf
  40. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  41. // = SIMULATION PARAMETERS
  42. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  43. #define SIMULATION_TIME (float)(600.0) // in milliseconds
  44. #define INTEGRATION_STEP_SIZE (float)(1.000) // in milliseconds
  45. #define HIGHRES_INTEGRATION_STEP_SIZE (float)(0.001) // in milliseconds
  46. #define PLOT_SHIFT (float)(0.000) // shift plot for debug, e.g. 5.0
  47. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  48. // = FORWARD DECLARATIONS
  49. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  50. void drawGraph( CNTXT* pCntxt, plstream* pPlStream, int numDataPoints, PLFLT* pTimesArray, PLFLT* pVoltagesArray, int plot_color, int plot_line_style, char* pLegendText );
  51. void exitProgram( CNTXT* pCntxt );
  52. void finalizeContext( CNTXT* pCntxt );
  53. void finalizePlot( CNTXT* pCntxt, plstream* pPlStream );
  54. void finalizeSimulation( CNTXT* pCntxt, PLFLT* pTimesArray, PLFLT* pVoltagesArray, float* pCurrentArray );
  55. void initializeContext( CNTXT** ppCntxt );
  56. void initializePlot( CNTXT* pCntxt, plstream** pPlStream );
  57. void initializeSimulation( CNTXT* pCntxt, float simulationTime, float integrationStepSize, PLFLT** ppTimesArray, PLFLT** ppVoltagesArray, PLFLT** ppFrequencyArray, float** ppCurrentArray );
  58. int runSimulation( CNTXT* pCntxt, ENUM_ODESOLVER_METHOD method, float simulationTime, float integrationStepSize, PLFLT* pTimesArray, PLFLT* pVoltagesArray, PLFLT* pFrequencyArray, float* pCurrentArray );
  59. void setCurrentShape( CNTXT* pCntxt, float* pCurrentArray, int numDataPoints, float integrationStepSize );
  60. void processMainArguments( CNTXT* pCntxt, int argc, char** argv );
  61. void processOPT_C( CNTXT* pCntxt, int argc, char** argv );
  62. void processOPT_F( CNTXT* pCntxt, int argc, char** argv );
  63. void processOPT_H( CNTXT* pCntxt, int argc, char** argv );
  64. void processOPT_M( CNTXT* pCntxt, int argc, char** argv );
  65. void processOPT_N( CNTXT* pCntxt, int argc, char** argv );
  66. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  67. // = MAIN ENTRY
  68. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  69. int main (int argc, char** argv)
  70. {
  71. CNTXT* pCntxt = NULL;
  72. PLFLT* pVoltagesArray = NULL;
  73. PLFLT* pTimesArray = NULL;
  74. PLFLT* pFrequencyArray = NULL;
  75. float* pCurrentArray = NULL;
  76. int numDataPoints = 0;
  77. plstream* pPlStream = NULL;
  78. initializeContext( &pCntxt );
  79. processMainArguments( pCntxt, argc, argv );
  80. initializePlot( pCntxt, &pPlStream );
  81. // PERFORM STANDARD EULER
  82. if( pCntxt->args.fOdeSolverStandardEuler ) {
  83. PRINT_DEBUG( " Debug: + + + perform standard Euler + + +\n" );
  84. initializeSimulation( pCntxt, SIMULATION_TIME, INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  85. numDataPoints = runSimulation( pCntxt, STANDARD_EULER, SIMULATION_TIME, INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  86. // ***GTR print frequency
  87. // drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pFrequencyArray, PLOT_COLOR_RED, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_STANDARD_EULER );
  88. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_RED, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_STANDARD_EULER );
  89. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  90. }
  91. // PERFORM SYMPLECTIC EULER
  92. if( pCntxt->args.fOdeSolverSymplecticEuler ) {
  93. PRINT_DEBUG( " Debug: + + + symplectic Euler + + +\n" );
  94. initializeSimulation( pCntxt, SIMULATION_TIME, INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  95. numDataPoints = runSimulation( pCntxt, SYMPLECTIC_EULER, SIMULATION_TIME, INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  96. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_GREEN, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_SYMPLECTIC_EULER );
  97. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  98. }
  99. // PERFORM EXPLICIT EULER SPINNAKER
  100. if( pCntxt->args.fOdeSolverEulerSpiNNaker ) {
  101. PRINT_DEBUG( " Debug: + + + perform explicit Euler - SpiNNaker implementation + + +\n" );
  102. initializeSimulation( pCntxt, SIMULATION_TIME, INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  103. numDataPoints = runSimulation( pCntxt, EXPLICIT_EULER_SPINNAKER, SIMULATION_TIME, INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  104. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_MAGENTA, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_EULER_SPINNAKER );
  105. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  106. }
  107. // EXPLICIT EULER NEST
  108. if( pCntxt->args.fOdeSolverEulerNEST ) {
  109. PRINT_DEBUG( " Debug: + + + explicit Euler - NEST implementation + + +\n" );
  110. initializeSimulation( pCntxt, SIMULATION_TIME, INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  111. numDataPoints = runSimulation( pCntxt, EXPLICIT_EULER_NEST, SIMULATION_TIME, INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  112. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_YELLOW, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_EULER_NEST );
  113. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  114. }
  115. // EXPLICIT IZHIKEVICH NUMERICS NEST
  116. if( pCntxt->args.fOdeSolverIzhikevichNEST ) {
  117. PRINT_DEBUG( " Debug: + + + explicit Izhikevich numerics - NEST implementation + + +\n" );
  118. initializeSimulation( pCntxt, SIMULATION_TIME, INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  119. numDataPoints = runSimulation( pCntxt, EXPLICIT_IZHIKEVICH_NUMERICS_NEST, SIMULATION_TIME, INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  120. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_CYAN, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_IZHIKEVICH_NEST );
  121. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  122. }
  123. // GSL library
  124. if( pCntxt->args.fOdeSolverGSL ) {
  125. PRINT_DEBUG( " Debug: + + + GSL library + + +\n" );
  126. initializeSimulation( pCntxt, SIMULATION_TIME, INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  127. numDataPoints = runSimulation( pCntxt, GSL_LIBRARY, SIMULATION_TIME, INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  128. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_GREY, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_GSL );
  129. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  130. }
  131. // Heun
  132. if( pCntxt->args.fOdeSolverHeun ) {
  133. PRINT_DEBUG( " Debug: + + + Heun's method + + +\n" );
  134. initializeSimulation( pCntxt, SIMULATION_TIME, INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  135. numDataPoints = runSimulation( pCntxt, HEUN_METHOD, SIMULATION_TIME, INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  136. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_BROWN, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_HEUN );
  137. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  138. }
  139. // Euler with adaptive stepsize
  140. if( pCntxt->args.fOdeSolverAdaptiveEuler ) {
  141. PRINT_DEBUG( " Debug: + + + perform adaptive Euler + + +\n" );
  142. initializeSimulation( pCntxt, SIMULATION_TIME, INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  143. numDataPoints = runSimulation( pCntxt, ADAPTIVE_EULER, SIMULATION_TIME, INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  144. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_BROWN, PLOT_LINE_FULL, STR_ODE_SOLVER_METHOD_ADAPTIVE_EULER );
  145. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  146. }
  147. // HIGH RESOLUTION REFERENCE USING STANDARD EULER
  148. if( pCntxt->args.fOdeSolverHighResolutionEuler ) {
  149. PRINT_DEBUG( " Debug: + + + reference high resolution standard Euler + + +\n" );
  150. initializeSimulation( pCntxt, SIMULATION_TIME, HIGHRES_INTEGRATION_STEP_SIZE, &pTimesArray, &pVoltagesArray, &pFrequencyArray, &pCurrentArray );
  151. numDataPoints = runSimulation( pCntxt, STANDARD_EULER, SIMULATION_TIME, HIGHRES_INTEGRATION_STEP_SIZE, pTimesArray, pVoltagesArray, pFrequencyArray, pCurrentArray );
  152. drawGraph( pCntxt, pPlStream, numDataPoints, pTimesArray, pVoltagesArray, PLOT_COLOR_BLUE, PLOT_LINE_DOTTED, STR_ODE_SOLVER_METHOD_HIGH_RESOLUTION_EULER );
  153. finalizeSimulation( pCntxt, pTimesArray, pVoltagesArray, pCurrentArray );
  154. }
  155. finalizePlot( pCntxt, pPlStream );
  156. finalizeContext( pCntxt );
  157. printf( " Terminated normally\n" );
  158. return 0;
  159. }
  160. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  161. // HELPER FUNCTIONS
  162. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  163. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  164. // Plot graph, i.e. write to svg file
  165. // Multiple graphs can be plotted and overlayed
  166. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  167. void drawGraph( CNTXT* pCntxt, plstream* pPlStream, int numDataPoints, PLFLT* pTimesArray, PLFLT* pVoltagesArray, int plot_color, int plot_line_style, char* pLegendText )
  168. {
  169. PRINT_DEBUG( " Debug: plot graph, i.e. write to svg file: %s\n", pCntxt->args.outputSvgFilename );
  170. pllsty( plot_line_style );
  171. plcol0( plot_color );
  172. pPlStream->line( numDataPoints, pTimesArray, pVoltagesArray );
  173. plptex( 80.0, pCntxt->legendYOffset, 0.0, 0.0, 0.5, pLegendText );
  174. pCntxt->legendYOffset += 5;
  175. return;
  176. }
  177. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  178. // Free program context area and exit the program
  179. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  180. void exitProgram( CNTXT* pCntxt )
  181. {
  182. finalizeContext( pCntxt );
  183. exit( 0 );
  184. }
  185. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  186. // Free program context area
  187. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  188. void finalizeContext( CNTXT* pCntxt )
  189. {
  190. if( pCntxt != NULL ) {
  191. free( pCntxt );
  192. }
  193. return;
  194. }
  195. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  196. // Delete Plplot stream
  197. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  198. void finalizePlot( CNTXT* pCntxt, plstream* pPlStream )
  199. {
  200. delete pPlStream;
  201. return;
  202. }
  203. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  204. // Free data arrays
  205. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  206. void finalizeSimulation( CNTXT* pCntxt, PLFLT* pTimesArray, PLFLT* pVoltagesArray, float* pCurrentArray )
  207. {
  208. PRINT_DEBUG( " Debug: finalize\n" );
  209. free( pTimesArray );
  210. free( pVoltagesArray );
  211. free( pCurrentArray );
  212. return;
  213. }
  214. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  215. // Allocate and initialize the program's context area.
  216. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  217. void initializeContext( CNTXT** ppCntxt )
  218. {
  219. PRINT_DEBUG( " Debug: initialize context\n" );
  220. *ppCntxt = (CNTXT*)malloc( S_CNTXT );
  221. if( *ppCntxt == NULL ) {
  222. printf( "ERRROR: Failed to allocate program context area\n");
  223. exitProgram( NULL );
  224. }
  225. memset( *ppCntxt, NULLCHR, S_CNTXT );
  226. return;
  227. }
  228. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  229. // Set up Plplot
  230. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  231. void initializePlot( CNTXT* pCntxt, plstream** pPlStream )
  232. {
  233. *pPlStream = new plstream();
  234. plsdev("svg");
  235. plsfnam( pCntxt->args.outputSvgFilename );
  236. plscolbg( 255, 255, 255 );
  237. plscmap0n(16);
  238. (*pPlStream)->init();
  239. (*pPlStream)->env( 0, SIMULATION_TIME, -80, 50, 0, 0 );
  240. // | | | | | |
  241. // | | | | | +--- axis - 0 draw axis box and numeric labels
  242. // | | | | +------ just - 0 axis scales independently
  243. // | | | +---------- ymax
  244. // | | +-------------- ymin
  245. // | +-------------------------------- xmax
  246. // +----------------------------------- xmin
  247. (*pPlStream)->lab( "Time [ms]", "Voltage [mv]", pCntxt->neuronTypeName );
  248. return;
  249. }
  250. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  251. // Allocate and set up data structures
  252. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  253. void initializeSimulation( CNTXT* pCntxt, float simulationTime, float integrationStepSize, PLFLT** ppTimesArray, PLFLT** ppVoltagesArray, PLFLT** ppFrequencyArray, float** ppCurrentArray )
  254. {
  255. PRINT_DEBUG( " Debug: initialize simulation and prepare data arrays\n" );
  256. PLFLT* pVoltagesArray = NULL;
  257. PLFLT* pTimesArray = NULL;
  258. PLFLT* pFrequencyArray = NULL;
  259. float* pCurrentArray = NULL;
  260. int numDataPoints = floor(simulationTime / integrationStepSize) + 10; // due to rounding errors there might be a few more datapoints returned from the simulation run; just add 10 to be on the save side
  261. PRINT_DEBUG( " Debug: number of data points calculated: %d\n", numDataPoints );
  262. pVoltagesArray = (PLFLT*)malloc( numDataPoints * sizeof(PLFLT) );
  263. pTimesArray = (PLFLT*)malloc( numDataPoints * sizeof(PLFLT) );
  264. pFrequencyArray = (PLFLT*)malloc( numDataPoints * sizeof(PLFLT) );
  265. pCurrentArray = (float*)malloc( numDataPoints * sizeof(float) );
  266. if( NULL == pVoltagesArray || NULL == pTimesArray || NULL == pFrequencyArray || NULL == pCurrentArray ) {
  267. printf( "ERROR: failed to allocate memory\n" );
  268. exitProgram( pCntxt );
  269. }
  270. memset( pVoltagesArray, 0x00, numDataPoints * sizeof(PLFLT) );
  271. memset( pTimesArray, 0x00, numDataPoints * sizeof(PLFLT) );
  272. memset( pFrequencyArray, 0x00, numDataPoints * sizeof(PLFLT) );
  273. memset( pCurrentArray, 0x00, numDataPoints * sizeof(float) );
  274. setCurrentShape( pCntxt, pCurrentArray, numDataPoints, integrationStepSize );
  275. *ppTimesArray = pTimesArray;
  276. *ppVoltagesArray = pVoltagesArray;
  277. *ppFrequencyArray = pFrequencyArray;
  278. *ppCurrentArray = pCurrentArray;
  279. // set Izhikevich model constants
  280. IZHIKEVICH_A = pCntxt->neuronParam_A;
  281. IZHIKEVICH_B = pCntxt->neuronParam_B;
  282. IZHIKEVICH_C = pCntxt->neuronParam_C;
  283. IZHIKEVICH_D = pCntxt->neuronParam_D;
  284. IZHIKEVICH_THR = pCntxt->neuronParam_THR;
  285. return;
  286. }
  287. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  288. // Depending on parameter "method", call the corresponding ODE solver and
  289. // perform the simulation
  290. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  291. int runSimulation( CNTXT* pCntxt, ENUM_ODESOLVER_METHOD method, float simulationTime, float integrationStepSize
  292. , PLFLT* pTimesArray, PLFLT* pVoltagesArray, PLFLT* pFrequencyArray, float* pCurrentArray )
  293. {
  294. PFUNCD pODE1dxdt = (PFUNCD)dvdt; // Izhikevich ODE1
  295. PFUNCD pODE2dydt = (PFUNCD)dudt; // Izhikevich ODE2
  296. float v_t = pCntxt->neuronParam_V_INIT;
  297. float u_t = pCntxt->neuronParam_U_INIT;
  298. float v_tplus1 = 0;
  299. float u_tplus1 = 0;
  300. float t = 0;
  301. int dataPointIndex = 0;
  302. PRINT_DEBUG( " Debug: run simulation\n" );
  303. switch( method ) {
  304. case STANDARD_EULER:
  305. t = PLOT_SHIFT * 1;
  306. while( t <= simulationTime ) {
  307. pTimesArray[dataPointIndex] = t;
  308. pVoltagesArray[dataPointIndex] = v_t;
  309. ode2dSolver_StandardEuler( pODE1dxdt, pODE2dydt, integrationStepSize, v_t, u_t, &v_tplus1, &u_tplus1, &pCurrentArray[dataPointIndex] );
  310. if( threshold( &v_tplus1, &u_tplus1 )) {
  311. pFrequencyArray[dataPointIndex] = 30;
  312. };
  313. v_t = v_tplus1;
  314. u_t = u_tplus1;
  315. t += integrationStepSize;
  316. dataPointIndex++;
  317. }
  318. break;
  319. case SYMPLECTIC_EULER:
  320. t = PLOT_SHIFT * 2;
  321. while( t <= simulationTime ) {
  322. pTimesArray[dataPointIndex] = t;
  323. pVoltagesArray[dataPointIndex] = v_t;
  324. ode2dSolver_SymplecticEuler( pODE1dxdt, pODE2dydt, integrationStepSize, v_t, u_t, &v_tplus1, &u_tplus1, &pCurrentArray[dataPointIndex] );
  325. threshold( &v_tplus1, &u_tplus1 );
  326. v_t = v_tplus1;
  327. u_t = u_tplus1;
  328. t += integrationStepSize;
  329. dataPointIndex++;
  330. }
  331. break;
  332. case EXPLICIT_EULER_SPINNAKER:
  333. t = PLOT_SHIFT * 3;
  334. while( t <= simulationTime ) {
  335. pTimesArray[dataPointIndex] = t;
  336. pVoltagesArray[dataPointIndex] = v_t;
  337. explizitSpiNNaker( integrationStepSize, &v_t, &u_t, pCurrentArray[dataPointIndex] );
  338. t += integrationStepSize;
  339. dataPointIndex++;
  340. }
  341. break;
  342. case EXPLICIT_EULER_NEST:
  343. t = PLOT_SHIFT * 4;
  344. while( t <= simulationTime ) {
  345. pTimesArray[dataPointIndex] = t;
  346. pVoltagesArray[dataPointIndex] = v_t;
  347. explizitNEST1( integrationStepSize, &v_t, &u_t, pCurrentArray[dataPointIndex] );
  348. t += integrationStepSize;
  349. dataPointIndex++;
  350. }
  351. break;
  352. case EXPLICIT_IZHIKEVICH_NUMERICS_NEST:
  353. t = PLOT_SHIFT * 5;
  354. while( t <= simulationTime ) {
  355. pTimesArray[dataPointIndex] = t;
  356. pVoltagesArray[dataPointIndex] = v_t;
  357. explizitNEST2( integrationStepSize, &v_t, &u_t, pCurrentArray[dataPointIndex] );
  358. t += integrationStepSize;
  359. dataPointIndex++;
  360. }
  361. break;
  362. case GSL_LIBRARY:
  363. t = PLOT_SHIFT * 6;
  364. gslODESolver_Init();
  365. while( t <= simulationTime ) {
  366. pTimesArray[dataPointIndex] = t;
  367. pVoltagesArray[dataPointIndex] = v_t;
  368. gslODESolver_Integrate( integrationStepSize, &v_t, &u_t, pCurrentArray[dataPointIndex] );
  369. t += integrationStepSize;
  370. dataPointIndex++;
  371. }
  372. break;
  373. case HEUN_METHOD:
  374. t = PLOT_SHIFT * 7;
  375. while( t <= simulationTime ) {
  376. pTimesArray[dataPointIndex] = t;
  377. pVoltagesArray[dataPointIndex] = v_t;
  378. ode2dSolver_Heun( pODE1dxdt, pODE2dydt, integrationStepSize, v_t, u_t, &v_tplus1, &u_tplus1, &pCurrentArray[dataPointIndex] );
  379. threshold( &v_tplus1, &u_tplus1 );
  380. v_t = v_tplus1;
  381. u_t = u_tplus1;
  382. t += integrationStepSize;
  383. dataPointIndex++;
  384. }
  385. break;
  386. case ADAPTIVE_EULER:
  387. t = PLOT_SHIFT * 8;
  388. while( t <= simulationTime ) {
  389. pTimesArray[dataPointIndex] = t;
  390. pVoltagesArray[dataPointIndex] = v_t;
  391. ode2dSolver_AdaptiveEuler( pODE1dxdt, pODE2dydt, integrationStepSize, v_t, u_t, &v_tplus1, &u_tplus1, &pCurrentArray[dataPointIndex] );
  392. threshold( &v_tplus1, &u_tplus1 );
  393. v_t = v_tplus1;
  394. u_t = u_tplus1;
  395. t += integrationStepSize;
  396. dataPointIndex++;
  397. }
  398. break;
  399. default:
  400. printf( "ERROR: ODE solver method not defined\n");
  401. exitProgram( pCntxt );
  402. }
  403. PRINT_DEBUG( " Debug: number of data points: %d\n", dataPointIndex );
  404. return( dataPointIndex ); // return number of data points, hence the dataPointIndex
  405. }
  406. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  407. // Fill the current-data-array with the desired current-shape.
  408. // The size of the array, i.e. the number od datapoints depend on the
  409. // resolution, hence the integration step size.
  410. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  411. void setCurrentShape( CNTXT* pCntxt, float* pCurrentArray, int numDataPoints, float integrationStepSize )
  412. {
  413. PRINT_DEBUG( " Debug: initialize current-shape array\n" );
  414. switch( pCntxt->args.currentShape ) {
  415. case CURRENT_STEP_150:
  416. for( int i = 0; i < numDataPoints; ++i ) {
  417. pCurrentArray[i] = pCntxt->neuronParam_I_EXT;
  418. }
  419. for( int i = 0; i < floor( 150 / integrationStepSize ); ++i ) {
  420. pCurrentArray[i] = 0;
  421. }
  422. // printf( " i +------------------------ \n" );
  423. // printf( " 0 ----+ \n" );
  424. // printf( " 150 t [ms] \n" );
  425. break;
  426. case CURRENT_PULSE:
  427. for( int i = 0; i < numDataPoints; ++i ) {
  428. pCurrentArray[i] = pCntxt->neuronParam_I_EXT;
  429. }
  430. for( int i = 0; i < floor( 150 / integrationStepSize ); ++i ) {
  431. pCurrentArray[i] = 0;
  432. }
  433. for( int i = floor( 200 / integrationStepSize ) ; i < floor( (200 + 2) / integrationStepSize ); ++i ) {
  434. pCurrentArray[i] = pCntxt->neuronParam_I_EXT + 5 ;
  435. }
  436. // printf( " +--+ \n" );
  437. // printf( " | | i + 5 pA \n" );
  438. // printf( " i +----------+ +---------- \n" );
  439. // printf( " 0 ----+ \n" );
  440. // printf( " 150 200 202 t [ms] \n" );
  441. break;
  442. case CURRENT_NEGATIVE_STEP:
  443. for( int i = 0; i < numDataPoints; ++i ) {
  444. pCurrentArray[i] = - pCntxt->neuronParam_I_EXT;
  445. }
  446. for( int i = floor( 150 / integrationStepSize ); i < numDataPoints; ++i ) {
  447. pCurrentArray[i] = 0;
  448. }
  449. // printf( " 0 +------------------------ \n" );
  450. // printf( " -i ----+ \n" );
  451. // printf( " 150 t [ms] \n" );
  452. break;
  453. default:
  454. printf( "ERROR: Failed to set up current shape\n" );
  455. exitProgram( pCntxt ) ;
  456. }
  457. return;
  458. }
  459. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  460. // HELPER FUNCTIONS TO PROCESS PROGRAM MAIN ARGUMENTS
  461. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  462. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  463. // Check program options
  464. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  465. void processMainArguments( CNTXT* pCntxt, int argc, char** argv )
  466. {
  467. while( --argc ) {
  468. if( argv[argc][0] != '-' ) {
  469. printf( "ERROR: Parameter error\n");
  470. processOPT_H( pCntxt, argc, argv );
  471. exitProgram( pCntxt );
  472. }
  473. switch( argv[argc][1] ) {
  474. case OPT_C:
  475. processOPT_C( pCntxt, argc, argv );
  476. break;
  477. case OPT_F:
  478. processOPT_F( pCntxt, argc, argv );
  479. break;
  480. case OPT_H:
  481. processOPT_H( pCntxt, argc, argv );
  482. exitProgram( pCntxt );
  483. break;
  484. case OPT_M:
  485. processOPT_M( pCntxt, argc, argv );
  486. break;
  487. case OPT_N:
  488. processOPT_N( pCntxt, argc, argv );
  489. break;
  490. default:
  491. printf( "ERROR: Parameter error\n");
  492. processOPT_H( pCntxt, argc, argv );
  493. exitProgram( pCntxt );
  494. }
  495. }
  496. // some parameter checks
  497. if( pCntxt->args.currentShape == 0 ) {
  498. printf( "ERROR: option -c not set\n" );
  499. processOPT_H( pCntxt, argc, argv );
  500. exitProgram( pCntxt );
  501. }
  502. if( pCntxt->args.outputSvgFilename[0] == NULLCHR ) {
  503. printf( "ERROR: option -f not set\n" );
  504. processOPT_H( pCntxt, argc, argv );
  505. exitProgram( pCntxt );
  506. }
  507. if( pCntxt->neuronParam_A == 0 ) {
  508. printf( "ERROR: option -n not set\n" );
  509. processOPT_H( pCntxt, argc, argv );
  510. exitProgram( pCntxt );
  511. }
  512. if(( pCntxt->args.fOdeSolverStandardEuler || pCntxt->args.fOdeSolverSymplecticEuler || pCntxt->args.fOdeSolverEulerSpiNNaker ||
  513. pCntxt->args.fOdeSolverEulerNEST || pCntxt->args.fOdeSolverIzhikevichNEST || pCntxt->args.fOdeSolverHighResolutionEuler ||
  514. pCntxt->args.fOdeSolverGSL || pCntxt->args.fOdeSolverHeun || pCntxt->args.fOdeSolverAdaptiveEuler ) == 0 ) {
  515. printf( "ERROR: option -m not set\n" );
  516. processOPT_H( pCntxt, argc, argv );
  517. exitProgram( pCntxt );
  518. }
  519. printf( "+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +\n" );
  520. printf( "+ INZHIKEVICH MODEL SIMULATION +\n" );
  521. printf( "+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +\n" );
  522. printf( "Following parameters are in use for this run:\n" );
  523. printf( " SVG Output File Name: %s\n", pCntxt->args.outputSvgFilename );
  524. printf( " Neuron Type : %s\n", pCntxt->neuronTypeName );
  525. switch( pCntxt->args.currentShape ) {
  526. case CURRENT_STEP_150:
  527. printf( " Current Shape : step current at 150ms\n" );
  528. printf( " i +------------------------ \n" );
  529. printf( " 0 ----+ \n" );
  530. printf( " 150 t [ms] \n" );
  531. break;
  532. case CURRENT_PULSE:
  533. printf( " Current Shape : step current at 150ms with pulse at 200ms for 2ms\n" );
  534. printf( " +--+ \n" );
  535. printf( " | | i + 5 pA \n" );
  536. printf( " i +----------+ +---------- \n" );
  537. printf( " 0 ----+ \n" );
  538. printf( " 150 200 202 t [ms] \n" );
  539. break;
  540. case CURRENT_NEGATIVE_STEP:
  541. printf( " Current Shape : negative step current at 150ms\n" );
  542. printf( " 0 +------------------------ \n" );
  543. printf( " -i ----+ \n" );
  544. printf( " 150 t [ms] \n" );
  545. break;
  546. }
  547. printf( " ODE solver selected : \n" );
  548. if( pCntxt->args.fOdeSolverStandardEuler ) {
  549. printf( " Standard Euler\n" );
  550. }
  551. if( pCntxt->args.fOdeSolverSymplecticEuler ) {
  552. printf( " Symplextic Euler\n" );
  553. }
  554. if( pCntxt->args.fOdeSolverEulerSpiNNaker ) {
  555. printf( " Explicit Euler SpiNNaker implementation\n" );
  556. }
  557. if( pCntxt->args.fOdeSolverEulerNEST ) {
  558. printf( " Explicit Euler NEST implementation\n" );
  559. }
  560. if( pCntxt->args.fOdeSolverIzhikevichNEST ) {
  561. printf( " Izhikevich numerics NEST implementation\n" );
  562. }
  563. if( pCntxt->args.fOdeSolverGSL ) {
  564. printf( " GSL library\n" );
  565. }
  566. if( pCntxt->args.fOdeSolverHeun ) {
  567. printf( " Heun's method\n" );
  568. }
  569. if( pCntxt->args.fOdeSolverHighResolutionEuler ) {
  570. printf( " Standard Euler with a high integration step resolution, i.e. 1 micro second\n" );
  571. }
  572. if( pCntxt->args.fOdeSolverAdaptiveEuler ) {
  573. printf( " Standard Euler with an adaptive integration step size\n" );
  574. }
  575. return;
  576. }
  577. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  578. // Set the current shape
  579. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  580. void processOPT_C( CNTXT* pCntxt, int argc, char** argv )
  581. {
  582. if( strncmp( &argv[argc][2], STR_CURRENT_STEP_150, sizeof( STR_CURRENT_STEP_150 )) == 0 ) {
  583. pCntxt->args.currentShape = CURRENT_STEP_150;
  584. }
  585. else if ( strncmp( &argv[argc][2], STR_CURRENT_PULSE, sizeof( STR_CURRENT_PULSE )) == 0 ) {
  586. pCntxt->args.currentShape = CURRENT_PULSE;
  587. }
  588. else if ( strncmp( &argv[argc][2], STR_CURRENT_NEGATIVE_STEP, sizeof( STR_CURRENT_NEGATIVE_STEP )) == 0 ) {
  589. pCntxt->args.currentShape = CURRENT_NEGATIVE_STEP;
  590. }
  591. else {
  592. printf( "ERROR: Parameter error, failed to set current shape\n" );
  593. exitProgram( pCntxt );
  594. }
  595. return;
  596. }
  597. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  598. // Set the svg output file name
  599. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  600. void processOPT_F( CNTXT* pCntxt, int argc, char** argv )
  601. {
  602. strncpy( pCntxt->args.outputSvgFilename, &argv[argc][2], S_NAME - 1 );
  603. pCntxt->args.outputSvgFilename[S_NAME - 1] = NULLCHR;
  604. return;
  605. }
  606. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  607. // Show help text
  608. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  609. void processOPT_H( CNTXT* pCntxt, int argc, char** argv )
  610. {
  611. printf( "USAGE : izhikevich -n<neuron type> -c<current shape> -f<svg output path/file.svg> -m<ODE solver method> ... -m<ODE solver method>\n" );
  612. printf( " -f filename svg output file name, e.g. svg\\RS_step150.svg\n" );
  613. printf( " -n RS regular spiking\n" );
  614. printf( " IB intrinsically bursting\n" );
  615. printf( " CH chattering\n" );
  616. printf( " FS fast spiking\n" );
  617. printf( " TC thalamo cortical\n" );
  618. printf( " RZ resonance\n" );
  619. printf( " LTS low threshold spiking\n" );
  620. printf( "\n" );
  621. printf( " -c step150 step current at 150ms\n" );
  622. printf( " i +------------------------ \n" );
  623. printf( " 0 ----+ \n" );
  624. printf( " 150 t [ms] \n" );
  625. printf( " pulse step current at 150ms with pulse at 200ms for 2ms\n" );
  626. printf( " +--+ \n" );
  627. printf( " | | i + 5 pA \n" );
  628. printf( " i +----------+ +---------- \n" );
  629. printf( " 0 ----+ \n" );
  630. printf( " 150 200 202 t [ms] \n" );
  631. printf( " nstep negative step current at 150ms\n" );
  632. printf( " 0 +------------------------ \n" );
  633. printf( " -i ----+ \n" );
  634. printf( " 150 t [ms] \n" );
  635. printf( "\n" );
  636. printf( " -m stdEuler standard Euler\n" );
  637. printf( " sympEuler symplectic Euler\n" );
  638. printf( " SpiNNaker explicit Euler SpiNNaker implementation\n" );
  639. printf( " EulerNEST explicit Euler NEST implementation\n" );
  640. printf( " IzhikevichNEST Izhikevich numerics implementation in NEST\n" );
  641. printf( " GSL use GSL library\n" );
  642. printf( " Heun Heun method\n" );
  643. printf( " highResEuler standard Euler with a high resolution integration step size, i.e. 1 micro second\n" );
  644. printf( " adaptiveEuler standard Euler with an adaptive integration step size\n" );
  645. printf( "\n" );
  646. printf( "EXAMPLE: compare different ODE solver methods for a regular spiking neuron with a positive external step current at 150 milliseconds\n" );
  647. printf( " izhikevich -nRS -cstep150 -fsvg/RS_step150.svg -mstdEuler -msympEuler -mSpiNNaker -mEulerNEST -mIzhikevichNEST -mhighResEuler\n" );
  648. printf( "\n" );
  649. return;
  650. }
  651. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  652. // Set ODE solver method(s)
  653. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  654. void processOPT_M( CNTXT* pCntxt, int argc, char** argv )
  655. {
  656. if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_STANDARD_EULER, sizeof( STR_ODE_SOLVER_METHOD_STANDARD_EULER )) == 0 ) {
  657. pCntxt->args.fOdeSolverStandardEuler = TRUE;
  658. }
  659. else if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_SYMPLECTIC_EULER, sizeof( STR_ODE_SOLVER_METHOD_SYMPLECTIC_EULER )) == 0 ) {
  660. pCntxt->args.fOdeSolverSymplecticEuler = TRUE;
  661. }
  662. else if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_EULER_SPINNAKER, sizeof( STR_ODE_SOLVER_METHOD_EULER_SPINNAKER )) == 0 ) {
  663. pCntxt->args.fOdeSolverEulerSpiNNaker = TRUE;
  664. }
  665. else if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_EULER_NEST, sizeof( STR_ODE_SOLVER_METHOD_EULER_NEST )) == 0 ) {
  666. pCntxt->args.fOdeSolverEulerNEST = TRUE;
  667. }
  668. else if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_IZHIKEVICH_NEST, sizeof( STR_ODE_SOLVER_METHOD_IZHIKEVICH_NEST )) == 0 ) {
  669. pCntxt->args.fOdeSolverIzhikevichNEST = TRUE;
  670. }
  671. else if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_GSL, sizeof( STR_ODE_SOLVER_METHOD_GSL )) == 0 ) {
  672. pCntxt->args.fOdeSolverGSL = TRUE;
  673. }
  674. else if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_HEUN, sizeof( STR_ODE_SOLVER_METHOD_HEUN )) == 0 ) {
  675. pCntxt->args.fOdeSolverHeun = TRUE;
  676. }
  677. else if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_HIGH_RESOLUTION_EULER, sizeof( STR_ODE_SOLVER_METHOD_HIGH_RESOLUTION_EULER )) == 0 ) {
  678. pCntxt->args.fOdeSolverHighResolutionEuler = TRUE;
  679. }
  680. else if( strncmp( &argv[argc][2], STR_ODE_SOLVER_METHOD_ADAPTIVE_EULER, sizeof( STR_ODE_SOLVER_METHOD_ADAPTIVE_EULER )) == 0 ) {
  681. pCntxt->args.fOdeSolverAdaptiveEuler = TRUE;
  682. }
  683. else {
  684. printf( "ERROR: Parameter error, invalid ODE solver method\n" );
  685. exitProgram( pCntxt );
  686. }
  687. return;
  688. }
  689. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  690. // Set model parameters depending on the neuron type
  691. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  692. void processOPT_N( CNTXT* pCntxt, int argc, char** argv )
  693. {
  694. if( strncmp( &argv[argc][2], STR_NEURON_TYPE_RS, sizeof( STR_NEURON_TYPE_RS )) == 0 ) {
  695. pCntxt->args.neuronType = NEURON_TYPE_RS;
  696. strncpy( pCntxt->neuronTypeName, RS_TYPENAME, sizeof( RS_TYPENAME ));
  697. pCntxt->neuronParam_A = RS_A;
  698. pCntxt->neuronParam_B = RS_B;
  699. pCntxt->neuronParam_C = RS_C;
  700. pCntxt->neuronParam_D = RS_D;
  701. pCntxt->neuronParam_THR = RS_THR;
  702. pCntxt->neuronParam_I_EXT = RS_I_EXT;
  703. pCntxt->neuronParam_V_INIT = RS_V_INIT;
  704. pCntxt->neuronParam_U_INIT = RS_U_INIT;
  705. }
  706. else if( strncmp( &argv[argc][2], STR_NEURON_TYPE_IB, sizeof( STR_NEURON_TYPE_IB )) == 0 ) {
  707. pCntxt->args.neuronType = NEURON_TYPE_IB;
  708. strncpy( pCntxt->neuronTypeName, IB_TYPENAME, sizeof( IB_TYPENAME ));
  709. pCntxt->neuronParam_A = IB_A;
  710. pCntxt->neuronParam_B = IB_B;
  711. pCntxt->neuronParam_C = IB_C;
  712. pCntxt->neuronParam_D = IB_D;
  713. pCntxt->neuronParam_THR = IB_THR;
  714. pCntxt->neuronParam_I_EXT = IB_I_EXT;
  715. pCntxt->neuronParam_V_INIT = IB_V_INIT;
  716. pCntxt->neuronParam_U_INIT = IB_U_INIT;
  717. }
  718. else if( strncmp( &argv[argc][2], STR_NEURON_TYPE_CH, sizeof( STR_NEURON_TYPE_CH )) == 0 ) {
  719. pCntxt->args.neuronType = NEURON_TYPE_CH;
  720. strncpy( pCntxt->neuronTypeName, CH_TYPENAME, sizeof( CH_TYPENAME ));
  721. pCntxt->neuronParam_A = CH_A;
  722. pCntxt->neuronParam_B = CH_B;
  723. pCntxt->neuronParam_C = CH_C;
  724. pCntxt->neuronParam_D = CH_D;
  725. pCntxt->neuronParam_THR = CH_THR;
  726. pCntxt->neuronParam_I_EXT = CH_I_EXT;
  727. pCntxt->neuronParam_V_INIT = CH_V_INIT;
  728. pCntxt->neuronParam_U_INIT = CH_U_INIT;
  729. }
  730. else if( strncmp( &argv[argc][2], STR_NEURON_TYPE_FS, sizeof( STR_NEURON_TYPE_FS )) == 0 ) {
  731. pCntxt->args.neuronType = NEURON_TYPE_FS;
  732. strncpy( pCntxt->neuronTypeName, FS_TYPENAME, sizeof( FS_TYPENAME ));
  733. pCntxt->neuronParam_A = FS_A;
  734. pCntxt->neuronParam_B = FS_B;
  735. pCntxt->neuronParam_C = FS_C;
  736. pCntxt->neuronParam_D = FS_D;
  737. pCntxt->neuronParam_THR = FS_THR;
  738. pCntxt->neuronParam_I_EXT = FS_I_EXT;
  739. pCntxt->neuronParam_V_INIT = FS_V_INIT;
  740. pCntxt->neuronParam_U_INIT = FS_U_INIT;
  741. }
  742. else if( strncmp( &argv[argc][2], STR_NEURON_TYPE_TC, sizeof( STR_NEURON_TYPE_TC )) == 0 ) {
  743. pCntxt->args.neuronType = NEURON_TYPE_TC;
  744. strncpy( pCntxt->neuronTypeName, TC_TYPENAME, sizeof( TC_TYPENAME ));
  745. pCntxt->neuronParam_A = TC_A;
  746. pCntxt->neuronParam_B = TC_B;
  747. pCntxt->neuronParam_C = TC_C;
  748. pCntxt->neuronParam_D = TC_D;
  749. pCntxt->neuronParam_THR = TC_THR;
  750. pCntxt->neuronParam_I_EXT = TC_I_EXT;
  751. pCntxt->neuronParam_V_INIT = TC_V_INIT;
  752. pCntxt->neuronParam_U_INIT = TC_U_INIT;
  753. }
  754. else if( strncmp( &argv[argc][2], STR_NEURON_TYPE_RZ, sizeof( STR_NEURON_TYPE_RZ )) == 0 ) {
  755. pCntxt->args.neuronType = NEURON_TYPE_RZ;
  756. strncpy( pCntxt->neuronTypeName, RZ_TYPENAME, sizeof( RZ_TYPENAME ));
  757. pCntxt->neuronParam_A = RZ_A;
  758. pCntxt->neuronParam_B = RZ_B;
  759. pCntxt->neuronParam_C = RZ_C;
  760. pCntxt->neuronParam_D = RZ_D;
  761. pCntxt->neuronParam_THR = RZ_THR;
  762. pCntxt->neuronParam_I_EXT = RZ_I_EXT;
  763. pCntxt->neuronParam_V_INIT = RZ_V_INIT;
  764. pCntxt->neuronParam_U_INIT = RZ_U_INIT;
  765. }
  766. else if( strncmp( &argv[argc][2], STR_NEURON_TYPE_LTS, sizeof( STR_NEURON_TYPE_LTS )) == 0 ) {
  767. pCntxt->args.neuronType = NEURON_TYPE_LTS;
  768. strncpy( pCntxt->neuronTypeName, LTS_TYPENAME, sizeof( LTS_TYPENAME ));
  769. pCntxt->neuronParam_A = LTS_A;
  770. pCntxt->neuronParam_B = LTS_B;
  771. pCntxt->neuronParam_C = LTS_C;
  772. pCntxt->neuronParam_D = LTS_D;
  773. pCntxt->neuronParam_THR = LTS_THR;
  774. pCntxt->neuronParam_I_EXT = LTS_I_EXT;
  775. pCntxt->neuronParam_V_INIT = LTS_V_INIT;
  776. pCntxt->neuronParam_U_INIT = LTS_U_INIT;
  777. }
  778. else {
  779. printf( "ERROR: Failed to set neuron type and neuron type properties\n" );
  780. exitProgram( pCntxt );
  781. }
  782. return;
  783. }