-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCluster.m
More file actions
129 lines (101 loc) · 3.67 KB
/
Cluster.m
File metadata and controls
129 lines (101 loc) · 3.67 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
%% Cluster Class
% Defines a generic container that holds SolarCell or Cluster objects
% Objects stored in cluster are electrically in series
classdef Cluster < handle
properties
id uint32 % Numerical ID of cluster
name % String containing cluster name
color % Color code in array view
size = 0 % Number of stored objects
SolarObjects = {} % Cells array containing SolarCell or Cluster
IoptMax = 0 % Sets limit on minimization functions
viVector
parentId = 0 % ID of parent container
bypassPresent = 0 % 1 if bypass diode in parallel with container
fullyDefined = 1 % Not important for this, mimics SolarCell
end
methods
function AddObject(obj, item)
if item.fullyDefined
obj.size = obj.size + 1;
obj.SolarObjects{obj.size} = item;
obj.SolarObjects{obj.size}.parentId = obj.id;
obj.IoptMax = max(obj.IoptMax, item.IoptMax);
end
end
function RemoveObject(obj, idx)
if idx <= obj.size
obj.SolarObjects{idx}.parentId = 0;
obj.SolarObjects(idx) = [];
obj.size = obj.size - 1;
end
end
function GenerateCurve(obj, li, zen, azm)
obj.viVector = zeros(1, 11001);
% Generate vector for each object
for i = 1:obj.size
obj.SolarObjects{i}.GenerateCurve(li, zen, azm);
end
% viVector is sum of vectors of stored objects
for i = 1:obj.size
obj.viVector = obj.viVector + obj.SolarObjects{i}.viVector;
end
% Add parallel ideal diode
if obj.bypassPresent
obj.viVector = obj.viVector .* (obj.viVector >= 0);
obj.viVector = obj.viVector .* ~isinf(obj.viVector);
end
end
% Returns current given voltage
function I = GetCurrent(obj, V)
[~, idx] = min(abs(obj.viVector - V));
I = obj.IdxtoI(idx);
end
% Returns voltage given current
function V = GetVoltage(obj, I)
idx = obj.ItoIdx(I);
V = obj.viVector(idx);
end
% Returns open-circuit voltage
function Voc = GetVoc(obj)
Voc = obj.GetVoltage(0);
end
% Returns short-circuit current
function Isc = GetIsc(obj)
Isc = obj.GetCurrent(0);
end
% Returns power given voltage
function P = GetPowerV(obj, V)
P = V .* obj.GetCurrent(V);
P = P .* ~(isinf(P));
end
% Returns power given current
function P = GetPowerI(obj, I)
P = I .* obj.GetVoltage(I);
P = P .* ~(isinf(P));
end
% Returns electrical parameters at the maximum power point
function [Vmpp, Impp, Pmpp] = GetMPP(obj)
Impp = fminbnd(@(I)obj.GetPowerI(I) * (-1), 0, obj.IoptMax);
Vmpp = obj.GetVoltage(Impp);
Pmpp = Impp * Vmpp;
end
end
methods (Static)
% Class constructor function
function obj = CreateCluster(id, name, color)
obj = Cluster;
obj.id = id;
obj.name = name;
obj.color = color;
end
% Convert current (A) to index
function idx = ItoIdx(I)
idx = floor((I + 1) * 1000 + 1);
end
% Convert index to current (A)
function I = IdxtoI(idx)
I = (idx - 1) / 1000 - 1;
end
end
end