file:/local_home/local_home/hugo/neurospaces_project/heccer/source/c/snapshots/0/integrators/heccer/neurospaces/heccer.c (Mon Jun 16 00:03:06 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 <neurospaces/importedfile.h>
20: #include <neurospaces/parsersupport.h>
21: #include <neurospaces/pidinstack.h>
22:
23: #include "heccer/addressing.h"
24: #include "heccer/heccer.h"
25: #include "heccer/neurospaces/segments.h"
26: #include "heccer/neurospaces/heccer.h"
27:
28:
29: int HeccerConstruct(struct Heccer *pheccer, void *pvNeurospaces, char *pcModel, void *pvEventDistributor)
30: {
31: //- the event_distributor is an event_distributor
32:
33: struct EventDistributor *ped = (struct EventDistributor *)pvEventDistributor;
34:
35: pheccer->ped = ped;
36:
37: //- the service core is neurospaces
38:
39: struct Neurospaces *pneuro = (struct Neurospaces *)pvNeurospaces;
40:
41: //- set default result : ok
42:
43: int iResult = 1;
44:
45: //- lookup the model
46:
47: struct PidinStack *ppistModel = PidinStackParse(pcModel);
48:
49: if (!ppistModel)
50: {
51: fprintf(stderr, "HeccerConstruct: cannot parse model name %s\n", pcModel);
52:
53: return(FALSE);
54: }
55:
56: //- allocate the translation service structures
57:
58: struct TranslationServiceData *ptsd
59: = (struct TranslationServiceData *)calloc(1, sizeof(struct TranslationServiceData));
60:
61: struct TranslationService *pts
62: = (struct TranslationService *)calloc(1, sizeof(struct TranslationService));
63:
64: pts->ptsd = ptsd;
65:
66: pts->ptsd->pneuro = pneuro;
67:
68: //- allocate pidin stack pointing to root
69:
70: struct PidinStack *ppistRoot = PidinStackCalloc();
71:
72: if (!ppistRoot)
73: {
74: fprintf(stderr, "HeccerConstruct: cannot allocate a root context for %s\n", pcModel);
75:
76: return(FALSE);
77: }
78:
79: PidinStackSetRooted(ppistRoot);
80:
81: //! gosh, I had to do the same hack when integrating neurospaces
82: //! with genesis2/hsolve.
83:
84: struct ParserContext *pacRoot = pneuro->pacRootContext;
85:
86: struct ImportedFile *pifRoot
87: = ParserContextGetImportedFile(pacRoot);
88:
89: //! depending on how the linking is done, there can be multiple
90: //! instances of neurospaces around. The following is a hack to
91: //! enforce the singleton (a bit)
92:
93: /* fprintf(stdout, "HeccerConstruct(): root import is %p\n", ImportedFileGetRootImport()); */
94:
95: ImportedFileSetRootImport(pifRoot);
96:
97: /* fprintf(stdout, "HeccerConstruct(): root import is %p\n", ImportedFileGetRootImport()); */
98:
99: //- update caches
100:
101: struct symtab_HSolveListElement *phsleRoot
102: = PidinStackLookupTopSymbol(ppistRoot);
103:
104: ptsd->ppistRoot = ppistRoot;
105:
106: ptsd->phsleRoot = phsleRoot;
107:
108: //- set model
109:
110: struct symtab_HSolveListElement *phsleModel
111: = PidinStackLookupTopSymbol(ppistModel);
112:
113: ptsd->iModel = PidinStackToSerial(ppistModel);
114:
115: if (ptsd->iModel == INT_MAX)
116: {
117: //! don't care about memory leak right now, consider this
118: //! right now as a fatal crash
119:
120: fprintf(stderr, "HeccerConstruct: cannot find model %s\n", pcModel);
121:
122: return(FALSE);
123: }
124:
125: if (!HeccerNeurospacesSegments2Compartments(pts))
126: {
127: //! don't care about memory leak right now, consider this
128: //! right now as a fatal crash
129:
130: fprintf(stderr, "HeccerConstruct: compartment initialization failed for %s\n", pcModel);
131:
132: return(FALSE);
133: }
134:
135: if (!HeccerNeurospacesMechanisms2MathComponents(pts))
136: {
137: //! don't care about memory leak right now, consider this
138: //! right now as a fatal crash
139:
140: fprintf(stderr, "HeccerConstruct: mechanism initialization failed for %s\n", pcModel);
141:
142: return(FALSE);
143: }
144:
145: //- set service structures
146:
147: pheccer->pts = pts;
148:
149: //- initialize the range of the intermediary, for the addressing
150: //- function
151:
152: //! note: closed interval, would probably be better to use a halve
153: //! open interval.
154:
155: pheccer->inter.iSerialStart = ADDRESSING_NEUROSPACES_2_HECCER(ptsd->iModel);
156:
157: pheccer->inter.iSerialEnd = ADDRESSING_NEUROSPACES_2_HECCER(ptsd->iModel + SymbolGetPrincipalNumOfSuccessors(phsleModel));
158:
159: //- free allocated data
160:
161: PidinStackFree(ppistModel);
162:
163: //- return result
164:
165: return(iResult);
166: }
167:
168:
169:
Generated by Xrefactory version 2.0.14 on Thu Jul 24 22:41:20 2008