Skip to content

Commit

Permalink
Merge pull request #663 from appukuttan-shailesh/record-stim
Browse files Browse the repository at this point in the history
Fixes #658: Implements recording of current generated by stimulating devices
  • Loading branch information
heplesser authored Apr 18, 2017
2 parents 81b640f + db50220 commit c0cb633
Show file tree
Hide file tree
Showing 14 changed files with 723 additions and 20 deletions.
70 changes: 69 additions & 1 deletion models/ac_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,26 @@
// Includes from nestkernel:
#include "event_delivery_manager_impl.h"
#include "kernel_manager.h"
#include "universal_data_logger_impl.h"

// Includes from sli:
#include "dict.h"
#include "dictutils.h"
#include "doubledatum.h"
#include "integerdatum.h"

namespace nest
{
RecordablesMap< ac_generator > ac_generator::recordablesMap_;

template <>
void
RecordablesMap< ac_generator >::create()
{
insert_( Name( names::I ), &ac_generator::get_I_ );
}
}

/* ----------------------------------------------------------------
* Default constructors defining default parameters and state
* ---------------------------------------------------------------- */
Expand All @@ -50,12 +63,46 @@ nest::ac_generator::Parameters_::Parameters_()
{
}

nest::ac_generator::Parameters_::Parameters_( const Parameters_& p )
: amp_( p.amp_ )
, offset_( p.offset_ )
, freq_( p.freq_ )
, phi_deg_( p.phi_deg_ )
{
}

nest::ac_generator::Parameters_& nest::ac_generator::Parameters_::operator=(
const Parameters_& p )
{
if ( this == &p )
{
return *this;
}

amp_ = p.amp_;
offset_ = p.offset_;
freq_ = p.freq_;
phi_deg_ = p.phi_deg_;

return *this;
}

nest::ac_generator::State_::State_()
: y_0_( 0.0 )
, y_1_( 0.0 ) // pA
, I_( 0.0 ) // pA
{
}

nest::ac_generator::Buffers_::Buffers_( ac_generator& n )
: logger_( n )
{
}

nest::ac_generator::Buffers_::Buffers_( const Buffers_&, ac_generator& n )
: logger_( n )
{
}

/* ----------------------------------------------------------------
* Parameter extraction and manipulation functions
Expand Down Expand Up @@ -96,14 +143,17 @@ nest::ac_generator::ac_generator()
, device_()
, P_()
, S_()
, B_( *this )
{
recordablesMap_.create();
}

nest::ac_generator::ac_generator( const ac_generator& n )
: Node( n )
, device_( n.device_ )
, P_( n.P_ )
, S_( n.S_ )
, B_( n.B_, *this )
{
}

Expand All @@ -125,11 +175,14 @@ void
nest::ac_generator::init_buffers_()
{
device_.init_buffers();
B_.logger_.reset();
}

void
nest::ac_generator::calibrate()
{
B_.logger_.init();

device_.calibrate();

const double h = Time::get_resolution().get_ms();
Expand All @@ -153,18 +206,33 @@ nest::ac_generator::calibrate()
void
nest::ac_generator::update( Time const& origin, const long from, const long to )
{
assert(
to >= 0 && ( delay ) from < kernel().connection_manager.get_min_delay() );
assert( from < to );

long start = origin.get_steps();

CurrentEvent ce;
for ( long lag = from; lag < to; ++lag )
{
S_.I_ = 0.0;

if ( device_.is_active( Time::step( start + lag ) ) )
{
const double y_0 = S_.y_0_;
S_.y_0_ = V_.A_00_ * y_0 + V_.A_01_ * S_.y_1_;
S_.y_1_ = V_.A_10_ * y_0 + V_.A_11_ * S_.y_1_;
ce.set_current( S_.y_1_ + P_.offset_ );
S_.I_ = S_.y_1_ + P_.offset_;

ce.set_current( S_.I_ );
kernel().event_delivery_manager.send( *this, ce, lag );
}
B_.logger_.record_data( origin.get_steps() + lag );
}
}

void
nest::ac_generator::handle( DataLoggingRequest& e )
{
B_.logger_.handle( e );
}
57 changes: 56 additions & 1 deletion models/ac_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "nest_types.h"
#include "node.h"
#include "stimulating_device.h"
#include "universal_data_logger.h"

/* BeginDocumentation
Name: ac_generator - provides AC input current
Expand Down Expand Up @@ -76,9 +77,23 @@ class ac_generator : public Node

port send_test_event( Node&, rport, synindex, bool );

using Node::handle;
using Node::handles_test_event;

void handle( DataLoggingRequest& );

port handles_test_event( DataLoggingRequest&, rport );

void get_status( DictionaryDatum& ) const;
void set_status( const DictionaryDatum& );

//! Allow multimeter to connect to local instances
bool
local_receiver() const
{
return true;
}

private:
void init_state_( const Node& );
void init_buffers_();
Expand All @@ -97,9 +112,11 @@ class ac_generator : public Node
double phi_deg_; //!< Phase of sine current (0-360 deg)

Parameters_(); //!< Sets default parameter values
Parameters_( const Parameters_& );
Parameters_& operator=( const Parameters_& p );

void get( DictionaryDatum& ) const; //!< Store current values in dictionary
void set( const DictionaryDatum& ); //!< Set values from dicitonary
void set( const DictionaryDatum& ); //!< Set values from dictionary
};

// ------------------------------------------------------------
Expand All @@ -108,6 +125,8 @@ class ac_generator : public Node
{
double y_0_;
double y_1_;
double I_; //!< Instantaneous current value; used for recording current
//!< Required to handle current values when device is inactive

State_(); //!< Sets default parameter values

Expand All @@ -116,6 +135,24 @@ class ac_generator : public Node

// ------------------------------------------------------------

// The next two classes need to be friends to access the State_ class/member
friend class RecordablesMap< ac_generator >;
friend class UniversalDataLogger< ac_generator >;

// ------------------------------------------------------------

/**
* Buffers of the model.
*/
struct Buffers_
{
Buffers_( ac_generator& );
Buffers_( const Buffers_&, ac_generator& );
UniversalDataLogger< ac_generator > logger_;
};

// ------------------------------------------------------------

struct Variables_
{
double omega_; //!< Angelfrequency i rad/s
Expand All @@ -128,12 +165,20 @@ class ac_generator : public Node
double A_11_;
};

double
get_I_() const
{
return S_.I_;
}

// ------------------------------------------------------------

StimulatingDevice< CurrentEvent > device_;
static RecordablesMap< ac_generator > recordablesMap_;
Parameters_ P_;
State_ S_;
Variables_ V_;
Buffers_ B_;
};

inline port
Expand All @@ -150,6 +195,16 @@ ac_generator::send_test_event( Node& target,
return target.handles_test_event( e, receptor_type );
}

inline port
ac_generator::handles_test_event( DataLoggingRequest& dlr, rport receptor_type )
{
if ( receptor_type != 0 )
{
throw UnknownReceptorType( receptor_type, get_name() );
}
return B_.logger_.connect_logging_device( dlr, recordablesMap_ );
}

inline void
ac_generator::get_status( DictionaryDatum& d ) const
{
Expand Down
68 changes: 68 additions & 0 deletions models/dc_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@
// Includes from nestkernel:
#include "event_delivery_manager_impl.h"
#include "kernel_manager.h"
#include "universal_data_logger_impl.h"

// Includes from sli:
#include "dict.h"
#include "dictutils.h"
#include "doubledatum.h"
#include "integerdatum.h"

namespace nest
{
RecordablesMap< dc_generator > dc_generator::recordablesMap_;

template <>
void
RecordablesMap< dc_generator >::create()
{
insert_( Name( names::I ), &dc_generator::get_I_ );
}
}

/* ----------------------------------------------------------------
* Default constructors defining default parameter
Expand All @@ -42,6 +54,39 @@ nest::dc_generator::Parameters_::Parameters_()
{
}

nest::dc_generator::Parameters_::Parameters_( const Parameters_& p )
: amp_( p.amp_ )
{
}

nest::dc_generator::Parameters_& nest::dc_generator::Parameters_::operator=(
const Parameters_& p )
{
if ( this == &p )
{
return *this;
}

amp_ = p.amp_;

return *this;
}

nest::dc_generator::State_::State_()
: I_( 0.0 ) // pA
{
}


nest::dc_generator::Buffers_::Buffers_( dc_generator& n )
: logger_( n )
{
}

nest::dc_generator::Buffers_::Buffers_( const Buffers_&, dc_generator& n )
: logger_( n )
{
}

/* ----------------------------------------------------------------
* Parameter extraction and manipulation functions
Expand All @@ -68,13 +113,18 @@ nest::dc_generator::dc_generator()
: Node()
, device_()
, P_()
, S_()
, B_( *this )
{
recordablesMap_.create();
}

nest::dc_generator::dc_generator( const dc_generator& n )
: Node( n )
, device_( n.device_ )
, P_( n.P_ )
, S_( n.S_ )
, B_( n.B_, *this )
{
}

Expand All @@ -89,17 +139,21 @@ nest::dc_generator::init_state_( const Node& proto )
const dc_generator& pr = downcast< dc_generator >( proto );

device_.init_state( pr.device_ );
S_ = pr.S_;
}

void
nest::dc_generator::init_buffers_()
{
device_.init_buffers();
B_.logger_.reset();
}

void
nest::dc_generator::calibrate()
{
B_.logger_.init();

device_.calibrate();
}

Expand All @@ -111,15 +165,29 @@ nest::dc_generator::calibrate()
void
nest::dc_generator::update( Time const& origin, const long from, const long to )
{
assert(
to >= 0 && ( delay ) from < kernel().connection_manager.get_min_delay() );
assert( from < to );

long start = origin.get_steps();

CurrentEvent ce;
ce.set_current( P_.amp_ );
for ( long offs = from; offs < to; ++offs )
{
S_.I_ = 0.0;

if ( device_.is_active( Time::step( start + offs ) ) )
{
S_.I_ = P_.amp_;
kernel().event_delivery_manager.send( *this, ce, offs );
}
B_.logger_.record_data( origin.get_steps() + offs );
}
}

void
nest::dc_generator::handle( DataLoggingRequest& e )
{
B_.logger_.handle( e );
}
Loading

0 comments on commit c0cb633

Please sign in to comment.