-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSource.m
More file actions
144 lines (136 loc) · 5.97 KB
/
Source.m
File metadata and controls
144 lines (136 loc) · 5.97 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
classdef Source < handle
%
% Source class is implemented for the PowerSystem Package and it's used for all active sources.
%
% Source( ps, busK, type, signal_type, amp, phase, freq )
% ps: Power System pointer
% busK: Source bus connection
% type: Must be a SourceTypes object: SourceTypes.(Voltage/Current)
% signal_type: String containing the source signal type (Sinoidal/Step)
% amp: Signal amplitude for all phases (column vector)
% phase: Phase for wave forms for all phases (column vector)
% freq: Frequency For wave forms for all phases (column vector)
%
%
properties(Access = public) % Use these parameters to control sinoidal amp/freq/phase or step amp values.
freq = 60.; % freq: The source frequency;
amp = 1.; % amp: The source amplitude;
phase = 0.; % phase: The source phase;
end
properties(GetAccess = public, SetAccess = protected) % Only Source and it childs can set these properties, but everyone can read them
injection = 0.; % injection: The source injection on the system;
injection_function = @(t) sin(2*pi*60*t); % injection_function: Unnamed function depend on time used to calculate the injection: @(t) 3*sin(2*pi*60*t+29/180*pi)
end
properties(Access = protected) % Only Source and it childs can set and see these properties
ps; % PowerSystem pointer
end
properties(GetAccess = public, SetAccess = private) % Only Source can set these properties, but everyone can read them
busK; % busK: Source bus connection
type = SourceTypes.Voltage; % type: Must be a SourceTypes object (Voltage/Current)
end
methods
function src = Source( ps, busK, type, signal_type, amp, phase, freq )
if nargin > 0
src.ps = ps;
end
if nargin > 1
src.busK = busK;
end
if nargin > 2
src.type = type;
end
if nargin > 3
if (isa(signal_type,'char')) % is the second argument a string?
if (strcmpi('sinoidal',signal_type)) % is it sinoidal?
if nargin < 8
if size(amp,1) == 1
src.amp=amp*ones(src.ps.topology,1);
elseif size(amp,1) == 3 & src.ps.topology == SysTopo.Triphasic
src.amp=amp;
else
error('PowerSystemPkg:Source','Problem setting source amplitude');
end
if size(freq,1) == 1
src.freq=freq*ones(src.ps.topology,1);
elseif size(freq,1) == 3 & src.ps.topology == SysTopo.Triphasic
src.freq=freq;
else
error('PowerSystemPkg:Source','Problem setting source frequency');
end
if size(phase,1) == 1 & src.ps.topology == SysTopo.Monophasic
src.phase=phase;
elseif size(phase,1) == 1 & src.ps.topology == SysTopo.Triphasic
src.phase=[phase;phase-120*pi/180;phase+120*pi/180];
elseif size(phase,1) == 3 & src.ps.topology == SysTopo.Triphasic
src.phase=phase;
else
error('PowerSystemPkg:Source','Problem setting source phase');
end
elseif nargin == 6
if size(amp,1) == 1
src.amp=amp*ones(src.ps.topology,1);
elseif size(amp,1) == 3 & src.ps.topology == SysTopo.Triphasic
src.amp=amp;
else
error('PowerSystemPkg:Source','Problem setting source amplitude');
end
src.freq=60.*ones(src.ps.topology,1);
if size(phase,1) == 1 & src.ps.topology == SysTopo.Monophasic
src.phase=phase;
elseif size(phase,1) == 1 & src.ps.topology == SysTopo.Triphasic
src.phase=[phase;phase-120*pi/180;phase+120*pi/180];
elseif size(phase,1) == 3 & src.ps.topology == SysTopo.Triphasic
src.phase=phase;
else
error('PowerSystemPkg:Source','Problem setting source phase');
end
elseif nargin == 5
if size(amp,1) == 1
src.amp=amp*ones(src.ps.topology,1);
elseif size(amp,1) == 3 & src.ps.topology == SysTopo.Triphasic
src.amp=amp;
else
error('PowerSystemPkg:Source','Problem setting source amplitude');
end
if src.ps.topology == SysTopo.Triphasic
src.phase=[0.;-120;+120];
src.freq=[60.;60.;60.];
else
src.phase=0.;
src.freq=60.;
end
else % if nargin == 4
if src.ps.topology == SysTopo.Triphasic
src.amp=[1.;1.;1];
src.phase=[0.;-120;+120];
src.freq=[60.;60.;60.];
else
src.amp=1.;
src.freq=60.;
src.phase=0.;
end
end % nargin
src.injection_function = @(t) src.amp.*sin(2*pi.*src.freq.*t + src.phase);
return;
elseif (strcmpi('step', signal_type)) % or step?
src.amp = arg3;
src.injection_function = @(t) src.amp;
else % if not... error:
error('PowerSystemPkg:Source','Signal type \"%s\" it not defined, use: sinoidal/step.',arg2);
end
elseif isa(signal_type,'function_handle');
src.injection_function = signal_type;
else
error('PowerSystemPkg:Source','Signal type input cannot be used.');
end % what type is the second argument?
end % nargin > 3
end % Constructor
function update(src)
% function update(src)
%
% This function updates the source injection for the system time
%
src.injection = src.injection_function(src.ps.currentTime);
end % update
end % methods
end