file:/local_home/local_home/hugo/neurospaces_project/heccer/source/c/snapshots/0/intermediary.c        (Mon Jun 16 00:04:16 2008 )        HOME


   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 <stdlib.h>
  20: 
  21: #include "heccer/compartment.h"
  22: #include "heccer/intermediary.h"
  23: 
  24: 
  25: /// **************************************************************************
  26: ///
  27: /// SHORT: HeccerIntermediaryBuildIndex()
  28: ///
  29: /// ARGS.:
  30: ///
  31: ///     pheccer...: a heccer.
  32: ///
  33: /// RTN..: int
  34: ///
  35: ///     success of operation.
  36: ///
  37: /// DESCR: Index intermediary mechanism structures.
  38: ///
  39: ///     The index can afterwards be used for lookups, see
  40: ///     HeccerMechanismLookup().
  41: ///
  42: /// **************************************************************************
  43: 
  44: int HeccerIntermediaryBuildIndex(struct Heccer *pheccer)
  45: {
  46:     //- set default result : success
  47: 
  48:     int iResult = TRUE;
  49: 
  50:     //- no mechanisms
  51: 
  52:     if (!pheccer->inter.pmca)
  53:     {
  54:         //- no index
  55: 
  56:         return(iResult);
  57:     }
  58: 
  59:     //- set default result : start of mechanisms
  60: 
  61:     struct MathComponent *pmc = (struct MathComponent *)pheccer->inter.pmca->pmc;
  62: 
  63:     //- allocate the index
  64: 
  65:     struct MathComponent **ppmcIndex
  66:         = (struct MathComponent **)calloc(pheccer->inter.pmca->iMathComponents, sizeof(struct MathComponent *));
  67: 
  68:     if (!ppmcIndex)
  69:     {
  70:         return(FALSE);
  71:     }
  72: 
  73:     pheccer->inter.pmca->ppmcIndex = ppmcIndex;
  74: 
  75:     //- loop over all mechanisms
  76: 
  77:     int i;
  78: 
  79:     for (i = 0 ; i < pheccer->inter.pmca->iMathComponents ; i++)
  80:     {
  81:         //- initialize the index
  82: 
  83:         ppmcIndex[i] = pmc;
  84: 
  85:         //- look at mechanism type
  86: 
  87:         int iType = pmc->iType;
  88: 
  89:         switch (iType)
  90:         {
  91:             //- for a callout
  92: 
  93:         case MATH_TYPE_CallOut_conductance_current:
  94:         {
  95:             //- get type specific data
  96: 
  97:             struct Callout *pcall = (struct Callout *)pmc;
  98: 
  99:             pmc = MathComponentNext(&pcall->mc);
 100: 
 101:             break;
 102:         }
 103: 
 104:         //- for a spring mass equation
 105: 
 106:         case MATH_TYPE_ChannelSpringMass:
 107:         {
 108:             //- get type specific data
 109: 
 110:             struct ChannelSpringMass * pcsm = (struct ChannelSpringMass *)pmc;
 111: 
 112:             pmc = MathComponentNext(&pcsm->mc);
 113: 
 114:             break;
 115:         }
 116: 
 117:         //- for a nernst operation with internal variable concentration
 118: 
 119:         case MATH_TYPE_InternalNernst:
 120:         {
 121:             //- get type specific data
 122: 
 123:             struct InternalNernst * pin = (struct InternalNernst *)pmc;
 124: 
 125:             pmc = MathComponentNext(&pin->mc);
 126: 
 127:             break;
 128:         }
 129: 
 130:         //- for a channel with only activation
 131: 
 132:         case MATH_TYPE_ChannelAct:
 133:         {
 134:             //- get type specific data
 135: 
 136:             struct ChannelAct *pca = (struct ChannelAct *)pmc;
 137: 
 138:             pmc = MathComponentNext(&pca->mc);
 139: 
 140:             break;
 141:         }
 142: 
 143:         //- for an regular channel with activation and inactivation
 144: 
 145:         case MATH_TYPE_ChannelActInact:
 146:         {
 147:             //- get type specific data
 148: 
 149:             struct ChannelActInact *pcai = (struct ChannelActInact *)pmc;
 150: 
 151:             pmc = MathComponentNext(&pcai->mc);
 152: 
 153:             break;
 154:         }
 155: 
 156:         //- for a channel with a potential and a concentration dependence
 157: 
 158:         case MATH_TYPE_ChannelActConc:
 159:         {
 160:             //- get type specific data
 161: 
 162:             struct ChannelActConc *pcac = (struct ChannelActConc *)pmc;
 163: 
 164:             pmc = MathComponentNext(&pcac->mc);
 165: 
 166:             break;
 167:         }
 168: 
 169:         //- for a channel given with steady state and a stepped time constant
 170: 
 171:         case MATH_TYPE_ChannelSteadyStateSteppedTau:
 172:         {
 173:             //- get type specific data
 174: 
 175:             struct ChannelSteadyStateSteppedTau *pcsst = (struct ChannelSteadyStateSteppedTau *)pmc;
 176: 
 177:             pmc = MathComponentNext(&pcsst->mc);
 178: 
 179:             break;
 180:         }
 181: 
 182:         //- for a channel given with steady state and a stepped time constant
 183: 
 184:         case MATH_TYPE_ChannelPersistentSteadyStateDualTau:
 185:         {
 186:             //- get type specific data
 187: 
 188:             struct ChannelPersistentSteadyStateDualTau *pcpsdt = (struct ChannelPersistentSteadyStateDualTau *)pmc;
 189: 
 190:             pmc = MathComponentNext(&pcpsdt->mc);
 191: 
 192:             break;
 193:         }
 194: 
 195:         //- for a persistent channel given with steady state and a time constant
 196: 
 197:         case MATH_TYPE_ChannelPersistentSteadyStateTau:
 198:         {
 199:             //- get type specific data
 200: 
 201:             struct ChannelPersistentSteadyStateTau *pcpst = (struct ChannelPersistentSteadyStateTau *)pmc;
 202: 
 203:             pmc = MathComponentNext(&pcpst->mc);
 204: 
 205:             break;
 206:         }
 207: 
 208:         //- for an exponential decaying variable
 209: 
 210:         case MATH_TYPE_ExponentialDecay:
 211:         {
 212:             //- get type specific data
 213: 
 214:             struct ExponentialDecay *pexdec = (struct ExponentialDecay *)pmc;
 215: 
 216:             pmc = MathComponentNext(&pexdec->mc);
 217: 
 218:             break;
 219:         }
 220:         case MATH_TYPE_SpikeGenerator:
 221:         {
 222:             //- get type specific data
 223: 
 224:             struct SpikeGenerator *psg = (struct SpikeGenerator *)pmc;
 225: 
 226:             pmc = MathComponentNext(&psg->mc);
 227: 
 228:             break;
 229:         }
 230:         default:
 231:         {
 232:             //t HeccerError(number, message, varargs);
 233: 
 234:             fprintf
 235:                 (stderr,
 236:                  "Heccer the hecc : unknown pmc->iType (%i)\n", iType);
 237:             break;
 238:         }
 239:         }
 240:     }
 241: 
 242:     //- return result
 243: 
 244:     return(iResult);
 245: }
 246: 
 247: 
 248: /// **************************************************************************
 249: ///
 250: /// SHORT: HeccerIntermediaryDump()
 251: ///
 252: /// ARGS.:
 253: ///
 254: ///     pinter.....: heccer intermediary.
 255: ///     pfile......: stdio file.
 256: ///     iSelection.: selection to dump.
 257: ///
 258: /// RTN..: int
 259: ///
 260: ///     success of operation.
 261: ///
 262: /// DESCR: Dump intermediary functions.
 263: ///
 264: /// **************************************************************************
 265: 
 266: int
 267: HeccerIntermediaryDump
 268: (struct Intermediary *pinter, FILE *pfile, int iSelection)
 269: {
 270:     //- set default result : ok
 271: 
 272:     int iResult = TRUE;
 273: 
 274:     int iCompartments = pinter->iCompartments;
 275: 
 276:     //- number of compartments
 277: 
 278:     if (iSelection & HECCER_DUMP_INTERMEDIARY_SUMMARY)
 279:     {
 280:         fprintf(pfile, "Intermediary (iCompartments) : (%i)\n", iCompartments);
 281:     }
 282: 
 283:     //- loop over compartment array
 284: 
 285:     struct Compartment *pcomp = pinter->pcomp;
 286: 
 287:     int i;
 288: 
 289:     for (i = 0 ; i < iCompartments ; i++)
 290:     {
 291:         //- dump compartment
 292: 
 293:         iResult = iResult && HeccerCompartmentDump(&pcomp[i], pfile, iSelection);
 294:     }
 295: 
 296:     //t mechanisms
 297: 
 298:     //- return result
 299: 
 300:     return(iResult);
 301: }
 302: 
 303: 
 304: /// **************************************************************************
 305: ///
 306: /// SHORT: HeccerIntermediaryLookup()
 307: ///
 308: /// ARGS.:
 309: ///
 310: ///     pheccer...: a heccer.
 311: ///     i.........: math component number to lookup.
 312: ///
 313: /// RTN..: struct MathComponent *
 314: ///
 315: ///     math component structure, NULL for failure.
 316: ///
 317: /// DESCR: Lookup the math component structure with the given number.
 318: ///
 319: ///     First call HeccerIntermediaryBuildIndex().
 320: ///
 321: /// NOTE.:
 322: ///
 323: ///     This function should be renamed to _mechanism_, instead of
 324: ///     _intermediary_.
 325: ///
 326: /// **************************************************************************
 327: 
 328: struct MathComponent *
 329: HeccerIntermediaryLookup(struct Heccer *pheccer, int i)
 330: {
 331:     //- set default result : not found
 332: 
 333:     struct MathComponent *pmcResult = NULL;
 334: 
 335:     //- if mechanisms indexed
 336: 
 337:     if (pheccer->inter.pmca
 338:         && pheccer->inter.pmca->ppmcIndex)
 339:     {
 340:         //- use the index
 341: 
 342:         pmcResult = pheccer->inter.pmca->ppmcIndex[i];
 343:     }
 344: 
 345:     //- return result
 346: 
 347:     return(pmcResult);
 348: }
 349: 
 350: 
 351: 








































Generated by Xrefactory version 2.0.14 on Thu Jul 24 22:41:20 2008