001: #!/usr/bin/perl -w
002: #!/usr/bin/perl -d:ptkdb -w
003: #
004: ##
005: ## Heccer : a compartmental solver that implements efficient Crank-Nicolson
006: ## integration for neuronal models.
007: ##
008: 
009: ##############################################################################
010: ##'
011: ##' Heccer : testbed C implementation
012: ##'
013: ##' Copyright (C) 2006-2007 Hugo Cornelis
014: ##'
015: ##' functional ideas ..  Hugo Cornelis, hugo.cornelis@gmail.com
016: ##'
017: ##' coding ............  Hugo Cornelis, hugo.cornelis@gmail.com
018: ##'
019: ##############################################################################
020: 
021: 
022: use strict;
023: 
024: 
025: BEGIN
026: {
027:     # during tests
028: 
029:     push @INC, '../glue/swig/perl';
030: 
031:     # during distcheck
032: 
033:     push @INC, '../../glue/swig/perl';
034: 
035:     # after installation
036: 
037:     push @INC, '/usr/local/glue/swig/perl';
038: }
039: 
040: 
041: BEGIN
042: {
043:     # for main during tests
044: 
045:     push @INC, './glue/swig/perl';
046: 
047:     # for main during distcheck
048: 
049:     push @INC, '../../tests/glue/swig/perl';
050: }
051: 
052: 
053: use Heccer;
054: 
055: 
056: # initialize compartments
057: 
058: my $compartments
059:     = [
060:        {
061:         dCm => 4.57537e-11,
062:         dEm => -0.08,
063:         dInitVm => -0.068,
064:         dInject => 0,
065:         dRa => 360502,
066:         dRm => 3.58441e+08,
067:         iParent => -1,
068:        },
069:        {
070:         dCm => 4.57537e-11,
071:         dEm => -0.08,
072:         dInitVm => -0.068,
073:         dInject => 0,
074:         dRa => 360502,
075:         dRm => 3.58441e+08,
076:         iParent => 0,
077:        },
078:        {
079:         dCm => 4.57537e-11,
080:         dEm => -0.08,
081:         dInitVm => -0.068,
082:         dInject => 0,
083:         dRa => 360502,
084:         dRm => 3.58441e+08,
085:         iParent => 1,
086:        },
087:        {
088:         dCm => 4.57537e-11,
089:         dEm => -0.08,
090:         dInitVm => -0.068,
091:         dInject => 0,
092:         dRa => 360502,
093:         dRm => 3.58441e+08,
094:         iParent => 0,
095:        },
096:       ];
097: 
098: # initialize intermediary
099: 
100: our $intermediary
101:     = Heccer::Intermediary->new
102:       (
103:        {
104:         comp2mech => [ 0, 0, 0, 0, -1],
105:         compartments => $compartments,
106:         iCompartments => 4,
107:        },
108:       );
109: 
110: 
111: # require 'main';
112: 
113: 
114: use Data::Dumper;
115: 
116: use Heccer;
117: 
118: 
119: our $config;
120: 
121: $config->{defaults}
122:     = {
123:        basal_activator_end => 0.3,
124:        basal_activator_start => 4e-5,
125:        interval_default_end => (0.05),
126:        interval_default_entries => 3000,
127:        interval_default_start => (-0.1),
128:        reporting_granularity => 1,
129:        steps => 10,
130:        tested_things => $SwiggableHeccer::HECCER_DUMP_ALL,
131:        time_step => (2e-5),
132:       };
133: 
134: # initialize options
135: 
136: my $options
137:     = Heccer::Options->new
138:       (
139:        {
140:         dBasalActivatorEnd => $config->{settings}->{basal_activator_end} || $config->{defaults}->{basal_activator_end},
141:         dBasalActivatorStart => $config->{settings}->{basal_activator_start} || $config->{defaults}->{basal_activator_start},
142:         dIntervalEnd => $config->{settings}->{interval_default_end} || $config->{defaults}->{interval_default_end},
143:         dIntervalStart => $config->{settings}->{interval_default_start} || $config->{defaults}->{interval_default_start},
144:         iIntervalEntries => $config->{settings}->{interval_default_entries} || $config->{defaults}->{interval_default_entries},
145:        },
146:       );
147: 
148: # instantiate heccer
149: 
150: our $intermediary;
151: 
152: my $heccer
153:     = Heccer->new
154:       (
155:        {
156:         dStep => $config->{settings}->{time_step} || $config->{defaults}->{time_step},
157:         intermediary => $intermediary,
158:         options => $options,
159:        },
160:       );
161: 
162: # build indices for optimization, compile to byte code
163: 
164: $heccer->compile();
165: 
166: # initiate values
167: 
168: $heccer->initiate();
169: 
170: # initial dump
171: 
172: print "Initiated\n";
173: 
174: $heccer->dump($config->{settings}->{tested_things} || $config->{defaults}->{tested_things});
175: 
176: # a couple of times
177: 
178: my $final_report = 0;
179: 
180: foreach my $i (0 .. ($config->{settings}->{steps} || $config->{defaults}->{steps}) - 1)
181: {
182:     # step
183: 
184:     $heccer->hecc();
185: 
186:     if (($i % ($config->{settings}->{reporting_granularity} || $config->{defaults}->{reporting_granularity})) == 0)
187:     {
188:         # dump
189: 
190:         print "-------\n";
191: 
192:         print "Iteration $i\n";
193: 
194:         $heccer->dump($config->{settings}->{tested_things} || $config->{defaults}->{tested_things});
195:     }
196:     else
197:     {
198:         $final_report = 1;
199:     }
200: }
201: 
202: if ($final_report)
203: {
204:     $heccer->dump();
205: }
206: 
207: 
208: 1;
209: 
210: 
211: