1: // 2: // Heccer : a compartmental solver that implements efficient Crank-Nicolson 3: // integration for neuronal models. 4: // 5: 6: ////////////////////////////////////////////////////////////////////////////// 7: //' 8: //' Heccer : testbed C implementation 9: //' 10: //' Copyright (C) 2006-2008 Hugo Cornelis 11: //' 12: //' functional ideas .. Hugo Cornelis, hugo.cornelis@gmail.com 13: //' 14: //' coding ............ Hugo Cornelis, hugo.cornelis@gmail.com 15: //' 16: ////////////////////////////////////////////////////////////////////////////// 17: 18: 19: #include <stdio.h> 20: 21: #include "../../heccer/callout.h" 22: #include "../../heccer/compartment.h" 23: #include "../../heccer/heccer.h" 24: 25: 26: struct Compartment compSoma = 27: { 28: //m administrative overhead 29: 30: { 31: //m type of structure 32: 33: MATH_TYPE_Compartment, 34: }, 35: 36: //m index of parent compartment, -1 for none 37: 38: -1, 39: 40: /* //m first mechanism */ 41: 42: /* NULL, */ 43: 44: /* //m number of mechanisms */ 45: 46: /* 0, */ 47: 48: //m descriptive values, alphabetical order 49: 50: /* double dCm; */ 51: 52: 4.57537e-11, // unscaled 0.0164, 53: 54: /* double dEm; */ 55: 56: -0.08, 57: 58: /* double dInitVm; */ 59: 60: -0.068, 61: 62: /* double dInject; */ 63: 64: 0, 65: 66: /* double dRa; */ 67: 68: 360502, // unscaled 2.5, 69: 70: /* double dRm; */ 71: 72: 3.58441e+08, // unscaled 1 73: }; 74: 75: 76: struct InternalResults pirSoma = 77: { 78: //m membrane potential for this compartment 79: 80: 0.0, 81: }; 82: 83: 84: struct ExternalResults perSoma = 85: { 86: //m external conductance, this is just an example 87: 88: 10.0, 89: 90: //m external current, another example 91: 92: 10.0, 93: }; 94: 95: 96: ExternalFunction pefInjector; 97: 98: 99: //s a state describing structure that is external to heccer 100: 101: struct ExternalState 102: { 103: //m the number of times the external callout has been called by 104: //m heccer. 105: 106: int iSteps; 107: }; 108: 109: struct ExternalState esSimulation = 110: { 111: 0, 112: }; 113: 114: struct Callout callSoma = 115: { 116: { 117: //m type of structure 118: 119: MATH_TYPE_CallOut_conductance_current, 120: }, 121: 122: //m external alien data 123: 124: &esSimulation, 125: 126: //m internal results 127: 128: &pirSoma, 129: 130: //m external results 131: 132: &perSoma, 133: 134: //m external function 135: 136: pefInjector, 137: }; 138: 139: 140: int piC2m[] = 141: { 142: 1, 143: -1, 144: }; 145: 146: 147: struct MathComponentArray mca = 148: { 149: //m number of math components 150: 151: 1, 152: 153: //m math component data 154: 155: &callSoma.mc, 156: 157: //m math component index, initialize to NULL 158: 159: NULL, 160: 161: }; 162: 163: 164: struct Intermediary inter = 165: { 166: //m compartment array 167: 168: 1, 169: 170: &compSoma, 171: 172: //m all other mathematical components 173: 174: &mca, 175: 176: //m compartment 2 first mechanism number 177: 178: piC2m, 179: }; 180: 181: 182: int pefInjector(struct Callout *pco, struct Heccer *pheccer, struct InternalResults *pir, struct ExternalResults *per) 183: { 184: //- set default result 185: 186: int iResult = 0; 187: 188: //- you can use pco->pvAlien to figure out the external state 189: 190: //- to do this, define you own private external state structure, see above 191: 192: //- access the external state structure using pco->pvAlien 193: 194: struct ExternalState *pes; 195: 196: pes = (struct ExternalState *)pco->pvAlien; 197: 198: //- and use it at your own convenience, we use it here to track 199: //- the number of steps the callout has been called. 200: 201: pes->iSteps++; 202: 203: //- set conductance and current according to the number of steps 204: 205: per->dConductance = 0.0; 206: 207: if (pes->iSteps > 2 && pes->iSteps < 9) 208: { 209: per->dCurrent = 5e-10; 210: } 211: else 212: { 213: per->dCurrent = 0.0; 214: } 215: 216: //- give some feedback for testing purposes 217: 218: fprintf(stdout, "The pefInjector callout injected %g current, and added %g conductance, at step %i\n", per->dCurrent, per->dConductance, pes->iSteps); 219: fprintf(stdout, "The pefInjector callout is advancing to time %g\n", pheccer->dTime); 220: 221: //- return result 222: 223: return(iResult); 224: } 225: 226: 227: #include "main.c" 228: 229: 230: