-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrentClampAssignmentProcess.cpp
90 lines (63 loc) · 1.51 KB
/
CurrentClampAssignmentProcess.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "libecs.hpp"
#include "Process.hpp"
USE_LIBECS;
LIBECS_DM_CLASS( CurrentClampAssignmentProcess, Process )
{
public:
LIBECS_DM_OBJECT( CurrentClampAssignmentProcess, Process )
{
INHERIT_PROPERTIES( Process );
PROPERTYSLOT_SET_GET( Real, amplitude );
PROPERTYSLOT_SET_GET( Real, onset );
PROPERTYSLOT_SET_GET( Real, offset );
PROPERTYSLOT_SET_GET( Real, interval );
}
CurrentClampAssignmentProcess()
:
amplitude( 0.0 ),
onset( 10.0 ),
offset( 10.5 ),
interval( 300.0 )
{
// do nothing
}
SIMPLE_SET_GET_METHOD( Real, amplitude );
SIMPLE_SET_GET_METHOD( Real, onset );
SIMPLE_SET_GET_METHOD( Real, offset );
SIMPLE_SET_GET_METHOD( Real, interval );
virtual void initialize()
{
Process::initialize();
I = getVariableReference( "I" ).getVariable();
t = getVariableReference( "t" ).getVariable();
if ( onset >= t->getValue() ) {
_nextOnset = onset;
} else {
_nextOnset = onset + floor( ( t->getValue() - onset ) / interval ) * interval;
}
_nextOffset = _nextOnset + offset - onset;
}
virtual void fire()
{
_t = t->getValue();
if ( _t >= _nextOnset && _t <= _nextOffset ) {
I->setValue( amplitude );
} else I->setValue( 0.0 );
if ( _t >= _nextOffset ) {
_nextOnset += interval;
_nextOffset += interval;
}
}
protected:
Variable* I;
Variable* t;
Real amplitude;
Real onset;
Real offset;
Real interval;
private:
Real _t;
Real _nextOnset;
Real _nextOffset;
};
LIBECS_DM_INIT( CurrentClampAssignmentProcess, Process );