NEST main@caf0ae8
 
Loading...
Searching...
No Matches
step_current_generator.h
Go to the documentation of this file.
1/*
2 * step_current_generator.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24#ifndef STEP_CURRENT_GENERATOR_H
25#define STEP_CURRENT_GENERATOR_H
26
27// C++ includes:
28#include <vector>
29
30// Includes from nestkernel:
31#include "connection.h"
32#include "device_node.h"
33#include "event.h"
34#include "nest_types.h"
35#include "ring_buffer.h"
36#include "stimulation_device.h"
38
39namespace nest
40{
41
42/* BeginUserDocs: device, generator
43
44Short description
45+++++++++++++++++
46
47Provide a piecewise constant DC input current
48
49Description
50+++++++++++
51
52The ``step_current_generator`` provides a piecewise constant DC input to the
53connected node(s). The amplitude of the current is changed at the
54specified times. The unit of the current is pA.
55
56If ``allow_offgrid_spikes`` is set false, times will be rounded to the
57nearest step if they are less than tic/2 from the step, otherwise NEST
58reports an error. If true, times are rounded to the nearest step if
59within tic/2 from the step, otherwise they are rounded up to the *end*
60of the step.
61
62Times of amplitude changes must be strictly increasing after conversion
63to simulation time steps. The option ``allow_offgrid_times`` may be
64useful, for example, if you are using randomized times for current changes
65which typically would not fall onto simulation time steps.
66
67.. include:: ../models/stimulation_device.rst
68
69amplitude_times
70 Times at which current changes (list of times in ms)
71
72amplitude_values
73 Amplitudes of step current current (list of currents in pA)
74
75allow_offgrid_times
76 Boolean indicating if offgrid times should be used (default: False)
77
78Set parameters from a stimulation backend
79~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80
81The parameters in this stimulation device can be updated with input
82coming from a stimulation backend. The data structure used for the
83update holds pairs of values in the form
84
85 [ (amplitude_times, amplitude_values), (amplitude_times, amplitude_values), ... ].
86
87Thus, the size of the data for the step_rate_generator needs to be even.
88
89Sends
90+++++
91
92CurrentEvent
93
94See also
95++++++++
96
97ac_generator, dc_generator, noise_generator
98
99Examples using this model
100+++++++++++++++++++++++++
101
102.. listexamples:: step_current_generator
103
104EndUserDocs */
105
106void register_step_current_generator( const std::string& name );
107
109{
110
111public:
114
116 bool local_receiver() const override;
117
118 size_t send_test_event( Node&, size_t, synindex, bool ) override;
119
120 using Node::handle;
122
123 void handle( DataLoggingRequest& ) override;
124
125 size_t handles_test_event( DataLoggingRequest&, size_t ) override;
126
127 void get_status( Dictionary& ) const override;
128 void set_status( const Dictionary& ) override;
129
130 void set_data_from_stimulation_backend( std::vector< double >& input_spikes ) override;
131
132 StimulationDevice::Type get_type() const override;
133
134private:
135 void init_state_() override;
136 void init_buffers_() override;
137 void pre_run_hook() override;
138
139 void update( Time const&, long, long ) override;
140
141 struct Buffers_;
142
147 {
149 std::vector< Time > amp_time_stamps_;
150
152 std::vector< double > amp_values_;
153
156
157 Parameters_();
159 Parameters_( const Parameters_& );
160 Parameters_& operator=( const Parameters_& p );
161
162 void get( Dictionary& ) const;
164 void set( const Dictionary&, Buffers_&, Node* );
165
172 Time validate_time_( double, const Time& );
173 };
174
175 // ------------------------------------------------------------
176
177 struct State_
178 {
179 double I_;
180
181 State_();
182 };
183
184 // ------------------------------------------------------------
185
186 // The next two classes need to be friends to access the State_ class/member
188 friend class UniversalDataLogger< step_current_generator >;
189
190 // ------------------------------------------------------------
191
201
202 // ------------------------------------------------------------
203
204 double
205 get_I_() const
206 {
207 return S_.I_;
208 }
209
210 // ------------------------------------------------------------
211
216};
217
218inline size_t
219step_current_generator::send_test_event( Node& target, size_t receptor_type, synindex syn_id, bool )
220{
222
223 CurrentEvent e;
224 e.set_sender( *this );
225
226 return target.handles_test_event( e, receptor_type );
227}
228
229inline size_t
231{
232 if ( receptor_type != 0 )
233 {
234 throw UnknownReceptorType( receptor_type, get_name() );
235 }
236 return B_.logger_.connect_logging_device( dlr, recordablesMap_ );
237}
238
239inline void
247
248inline void
250{
251 Parameters_ ptmp = P_; // temporary copy in case of errors
252 ptmp.set( d, B_, this ); // throws if BadProperty
253
254 // We now know that ptmp is consistent. We do not write it back
255 // to P_ before we are also sure that the properties to be set
256 // in the parent class are internally consistent.
258
259 // if we get here, temporaries contain consistent set of properties
260 P_ = ptmp;
261}
262
264inline bool
266{
267 return true;
268}
269
275} // namespace
276
277#endif /* #ifndef STEP_CURRENT_GENERATOR_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Event for electrical currents.
Definition event.h:569
Request data to be logged/logged data to be sent.
Definition event.h:636
Base class for all NEST network objects.
Definition node.h:99
std::string get_name() const
Return class name.
Definition node.cpp:105
Map names of recordables to data access functions.
Definition recordables_map.h:61
Base class for common properties of StimulationDevices.
Definition stimulation_device.h:154
void enforce_single_syn_type(synindex)
Throws IllegalConnection if synapse id differs from initial synapse id.
Definition stimulation_device.cpp:62
Type
Device type.
Definition stimulation_device.h:187
@ CURRENT_GENERATOR
Definition stimulation_device.h:188
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition stimulation_device.cpp:125
void get_status(Dictionary &d) const override
Export properties of the node by setting entries in the status dictionary.
Definition stimulation_device.cpp:168
Definition nest_time.h:135
Exception to be thrown if the specified receptor type does not exist in the node.
Definition exceptions.h:417
Definition step_current_generator.h:109
StimulationDevice::Type get_type() const override
Definition step_current_generator.h:271
step_current_generator()
Definition step_current_generator.cpp:224
Buffers_ B_
Definition step_current_generator.h:215
size_t send_test_event(Node &, size_t, synindex, bool) override
Send an event to the receiving_node passed as an argument.
Definition step_current_generator.h:219
size_t handles_test_event(DataLoggingRequest &, size_t) override
Definition step_current_generator.h:230
void handle(DataLoggingRequest &) override
Handler for universal data logging request.
Definition step_current_generator.cpp:317
void init_state_() override
Configure state variables depending on runtime information.
Definition step_current_generator.cpp:247
void init_buffers_() override
Configure persistent internal data structures.
Definition step_current_generator.cpp:253
friend class UniversalDataLogger< step_current_generator >
Definition step_current_generator.h:188
void get_status(Dictionary &) const override
Export properties of the node by setting entries in the status dictionary.
Definition step_current_generator.h:240
void set_data_from_stimulation_backend(std::vector< double > &input_spikes) override
Definition step_current_generator.cpp:326
Parameters_ P_
Definition step_current_generator.h:213
State_ S_
Definition step_current_generator.h:214
static RecordablesMap< step_current_generator > recordablesMap_
Definition step_current_generator.h:212
bool local_receiver() const override
Allow multimeter to connect to local instances.
Definition step_current_generator.h:265
double get_I_() const
Definition step_current_generator.h:205
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition step_current_generator.h:249
void update(Time const &, long, long) override
Advance the state of the node in time through the given interval.
Definition step_current_generator.cpp:275
void pre_run_hook() override
Re-calculate dependent parameters of the node.
Definition step_current_generator.cpp:263
virtual size_t handles_test_event(SpikeEvent &, size_t receptor_type)
Check if the node can handle a particular event and receptor type.
Definition node.cpp:271
virtual void handle(SpikeEvent &e)
Handle incoming spike events.
Definition node.cpp:265
const std::string recordables("recordables")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
void register_step_current_generator(const std::string &name)
Definition step_current_generator.cpp:35
size_t synindex
For enumerations of synapse types.
Definition nest_types.h:115
Definition step_current_generator.h:193
size_t idx_
index of current amplitude
Definition step_current_generator.h:194
UniversalDataLogger< step_current_generator > logger_
Definition step_current_generator.h:199
double amp_
current amplitude
Definition step_current_generator.h:195
Store independent parameters of the model.
Definition step_current_generator.h:147
Parameters_(const Parameters_ &, Buffers_ &)
void get(Dictionary &) const
Store current values in dictionary.
Definition step_current_generator.cpp:106
bool allow_offgrid_amp_times_
Allow and round up amplitude times not on steps.
Definition step_current_generator.h:155
void set(const Dictionary &, Buffers_ &, Node *)
Set values from dictionary.
Definition step_current_generator.cpp:164
Parameters_ & operator=(const Parameters_ &p)
Definition step_current_generator.cpp:68
std::vector< double > amp_values_
Amplitude values activated at given times.
Definition step_current_generator.h:152
std::vector< Time > amp_time_stamps_
Times of amplitude changes.
Definition step_current_generator.h:149
Parameters_()
Sets default parameter values.
Definition step_current_generator.cpp:53
Time validate_time_(double, const Time &)
Return time as Time object if valid, otherwise throw BadProperty.
Definition step_current_generator.cpp:120
Definition step_current_generator.h:178
double I_
Instantaneous current value; used for recording current.
Definition step_current_generator.h:179
State_()
Sets default parameter values.
Definition step_current_generator.cpp:82