/*
 *  test_iaf_psc_exp_multisynapse.sli
 *
 *  This file is part of NEST.
 *
 *  Copyright (C) 2004 The NEST Initiative
 *
 *  NEST is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  NEST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/* BeginDocumentation
   Name: testsuite::test_iaf_psc_exp_multisynapse - sli script for the multisynapse model

   Synopsis: (test_iaf_psc_exp_multisynapse) run

   Description:
   This test creates a multisynapse neuron and first checks if time constants
   can be set correctly. 
   Afterwards a neuron with four synaptic time constants with different weights and delays 
   is simulated and the resulting membrane potential values after the income of one spike  
   are checked against analytically obtained values.
   The textual output of the voltmeter documented in this file can be regenerated 
   by setting adding /to_screen true to the SetStatus call of vm below.
  
   SeeAlso: testsuite::test_iaf_psc_alpha_multisynapse, iaf_psc_exp_multisynapse

   FirstVersion: April 2013
   Author: Hannah Bos
 */


(unittest) run
/unittest using

0.1 /h Set

ResetKernel

0 << 
      /local_num_threads 1 
      /resolution h
  >> SetStatus

/taus       [2. 20. 60. 100.] def
/delays     [7. 5. 2. 1. ] def % ms
/weights    [30. 50. 20. 10.] def
/spike_time 0.1 def
/dt         0.1 def

/iaf_psc_exp_multisynapse Create /npost Set
npost << /tau_syn taus >> SetStatus

npost GetStatus /tau_syn get
taus eq assert_or_die

/voltmeter Create /vm Set
vm << /withtime true  /time_in_steps true /interval h /to_screen false >> SetStatus
   
/spike_generator Create /sg Set
sg << /spike_times [spike_time] >> SetStatus

[ weights delays [ 4 ] Range ]
{
  /receptor Set
  /delay Set
  /weight Set
  [sg] [npost] /one_to_one << /weight weight /delay delay /receptor_type receptor >> Connect
} ScanThread


vm npost 1.0 h Connect

8 ms Simulate


{                                            % reference data
 dup Transpose First /test_times Set         % times of reference 
                               
 vm [/events [/times /V_m]] get cva   % array of recorded data
  6 ToUnitTestPrecision                      % to precision of reference
  Transpose                                  % all recorded tuples
  {First test_times exch MemberQ } Select    % those with reference
 eq                                          % compare
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
% Expected output of this program: 
%
% time (in steps)  voltage (in mV)
[
[ 1       -70      ] % <----- Spike time
[ 2       -70      ] 
[ 3       -70      ]
[ 4       -70      ]
[ 5       -70      ]
[ 6       -70      ]
[ 7       -70      ]
[ 8       -70      ]
[ 9       -70      ]
[ 10      -70      ]
[ 11      -70      ] % <----- The spike arrives at the first synapse but has not yet effected the snynaptic current and membrane potential.
[ 12      -69.9960 ] % <-
[ 13      -69.9921 ] %   |
[ 14      -69.9882 ] %   |
[ 15      -69.9843 ] %    --- the effect of the synaptic current is visible in the membrane potential
%
% ...
%
[ 20      -69.9657 ] %<----- The spike arrives at the second synapse but has not yet effected the snynaptic current and membrane potential.
[ 21      -69.9621 ] %<-
[ 22      -69.9506 ] %  |
[ 23      -69.9392 ] %  |
[ 24      -69.928  ] %   --- the effect of the two synaptic currents is visible in the membrane potential
[ 25      -69.9169 ] %
%
% ...
%
[ 50      -69.6771 ] %<----- The spike arrives at the third synapse but has not yet effected the snynaptic current and membrane potential.
[ 51      -69.6689 ] %<-
[ 52      -69.641  ] %  |
[ 53      -69.6134 ] %  |
[ 54      -69.5863 ] %   --- the effect of the three synaptic currents is visible in the membrane potential
[ 55      -69.5595 ] %
%
% ...
%
[ 70      -69.2011 ] %<----- The spike arrives at the fourth synapse but has not yet effected the snynaptic current and membrane potential.
[ 71      -69.18   ] %<-
[ 72      -69.1474 ] %  |
[ 73      -69.1159 ] %  |
[ 74      -69.0854 ] %   --- the effect of the four synaptic currents is visible in the membrane potential
[ 75      -69.0557 ] %
]                       
%                         
%

exch assert_or_die

endusing
