/*
 *  test_hh_psc_alpha_gap.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_hh_psc_alpha_gap - sli script for overall test of hh_psc_alpha_gap model 
    with gap_junction connection

    Synopsis: (test_hh_psc_alpha_gap) run -> compares response to current step with reference data 

    Description:
    test_hh_psc_alpha_gap.sli is an overall test of the hh_psc_alpha_gap model connected
    by gap_junction connection.

    Two neurons of whom one receives an constant input current of 200 pA are connected
    by gap_junction with an (unrealistic) high gap weight. The accurate functionality
    of the gap_junction feature is tested by measuring the membrane potential of the
    neuron without input current.
    
    Although 0.1 cannot be represented in the IEEE double data type, it
    is safe to simulate with a resolution (computation step size) of 0.1
    ms because by default nest is built with a timebase enabling exact
    representation of 0.1 ms.

    The expected output is documented at the end of 
    the script. 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.
    
    Author:  October 2015, Hahne
    SeeAlso: testsuite::test_gap_junction, hh_psc_alpha_gap, gap_junction
*/

(unittest) run
/unittest using

% The following test needs the model hh_psc_alpha_gap, so
% this test should only run if we have GSL
statusdict/have_gsl :: not
{
  exit_test_gracefully
}
if

0.1 /h Set

ResetKernel

0 << 
      /local_num_threads 1 
      /resolution h
      /use_wfr true
      /wfr_tol 0.0001
      /wfr_interpolation_order 3
      /wfr_max_iterations 10
      /wfr_comm_interval 1.0
    >> SetStatus
    
/hh_psc_alpha_gap Create /neuron1 Set
/hh_psc_alpha_gap Create /neuron2 Set

neuron1
<< 
  /I_e 200.
>> SetStatus

/voltmeter Create /vm Set
vm << /withtime true  /time_in_steps true /interval h >> SetStatus

[neuron1] [neuron2] 
<< /rule /one_to_one /make_symmetric true >> 
<< /model /gap_junction /weight 20.0 >>  Connect

vm neuron2     1.0 h Connect


20 Simulate

{                                             % reference data
 dup Transpose First /test_times Set         % times of reference 
                               
 vm [/events [/times /V_m]] get cva   % array of recorded data
  5 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:
% 
% The output send to std::cout is a superposition of 
% the output of the voltmeter.
%
% time (in steps)  voltage (in mV)
[
[ 1    -69.592 ]
[ 2    -69.559 ]
[ 3    -69.507 ]
[ 4    -69.439 ]
[ 5    -69.357 ]
[ 6    -69.264 ]
[ 7    -69.162 ]
[ 8    -69.051 ]
[ 9    -68.933 ]
[ 10   -68.809 ]
[ 11   -68.681 ]
[ 12   -68.548 ]
[ 13   -68.413 ]
[ 14   -68.276 ]
[ 15   -68.136 ] 
%
% ...
%
[ 117  -33.771 ]
[ 118  -24.103 ]
[ 119    8.7117 ]
[ 120   62.019 ]
[ 121   39.042 ]
[ 122   27.485 ]
[ 123   18.856 ]
[ 124   11.201 ]
[ 125    3.6210 ]
[ 126   -4.6956 ]
[ 127  -15.006 ]
[ 128  -29.464 ]
[ 129  -49.786 ]
[ 130  -71.323 ]
[ 131  -83.787 ]
% 
% ...
%   
[ 190  -71.023 ]
[ 191  -70.833 ]
[ 192  -70.647 ]
[ 193  -70.466 ]
[ 194  -70.289 ]
[ 195  -70.116 ]
[ 196  -69.948 ]
[ 197  -69.783 ]
[ 198  -69.622 ]
[ 199  -69.464 ]
]   

exch assert_or_die


