-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathBusGrpMapBldr.java
More file actions
171 lines (152 loc) · 4.28 KB
/
BusGrpMapBldr.java
File metadata and controls
171 lines (152 loc) · 4.28 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.powerdata.openpa;
/*
* Copyright (c) 2016, PowerData Corporation, Incremental Systems Corporation
* All rights reserved.
* Licensed under the BSD-3 Clause License.
* See full license at https://powerdata.github.io/openpa/LICENSE.md
*/
import java.lang.ref.WeakReference;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.List;
import com.powerdata.openpa.impl.BasicGroupIndex;
import com.powerdata.openpa.tools.LinkNet;
/**
* Build a bus group map based on device connectivity
* @author chris@powerdata.com
*
*/
public class BusGrpMapBldr
{
PALists _model;
LinkNet _lnet;
int _nbus;
int _nbr = 0;
BusRefIndex _bri;
public BusGrpMapBldr(PALists model) throws PAModelException
{
_model = model;
_lnet = new LinkNet();
_nbus = model.getBuses().size();
_lnet.ensureCapacity(_nbus-1, 0);
_lnet.addBuses(0, _nbus);
_bri = BusRefIndex.CreateFromConnectivityBuses(model);
}
public BusGrpMapBldr addSwitches() throws PAModelException
{
addDev(_model.getSwitches(), d -> incSW(d));
return this;
}
@FunctionalInterface
interface T2DevPredicate<T extends TwoTermDev>
{
boolean test(T d) throws PAModelException;
}
<T extends TwoTermDev> void addDev(TwoTermDevListIfc<T> list, T2DevPredicate<T> p) throws PAModelException
{
int n = list.size();
_nbr += n;
_lnet.ensureCapacity(0, _nbr);
BusRefIndex.TwoTerm tt = _bri.get2TBus(list);
int[] frm = tt.getFromBus(), to = tt.getToBus();
for(int i=0; i < n; ++i)
{
if (p.test(list.get(i)))
_lnet.addBranch(frm[i], to[i]);
}
}
public BusGrpMapBldr addLines() throws PAModelException
{
addDev(_model.getLines(), d -> incLN(d));
return this;
}
public BusGrpMapBldr addSeriesReac() throws PAModelException
{
addDev(_model.getSeriesReactors(), d -> incSR(d));
return this;
}
public BusGrpMapBldr addSeriesCap() throws PAModelException
{
addDev(_model.getSeriesCapacitors(), d -> incSC(d));
return this;
}
public BusGrpMapBldr addTransformers() throws PAModelException
{
addDev(_model.getTransformers(), d -> incTX(d));
return this;
}
public BusGrpMapBldr addPhaseShifters() throws PAModelException
{
addDev(_model.getPhaseShifters(), d -> incPS(d));
return this;
}
public BusGrpMapBldr addTwoTermDCLines() throws PAModelException
{
addDev(_model.getTwoTermDCLines(), d -> incD2(d));
return this;
}
public BusGrpMapBldr addAll() throws PAModelException
{
addSwitches();
addLines();
addSeriesReac();
addSeriesCap();
addTransformers();
addPhaseShifters();
addTwoTermDCLines();
return this;
}
/** subclass to define which objects get included, default to all */
protected boolean incSW(Switch d) throws PAModelException {return true;}
/** subclass to define which objects get included, default to all */
protected boolean incLN(Line d) throws PAModelException {return true;}
/** subclass to define which objects get included, default to all */
protected boolean incSR(SeriesReac d) throws PAModelException {return true;}
/** subclass to define which objects get included, default to all */
protected boolean incSC(SeriesCap d) throws PAModelException {return true;}
/** subclass to define which objects get included, default to all */
protected boolean incTX(Transformer d) throws PAModelException {return true;}
/** subclass to define which objects get included, default to all */
protected boolean incPS(PhaseShifter d) throws PAModelException {return true;}
/** subclass to define which objects get included, default to all */
protected boolean incD2(TwoTermDCLine d) throws PAModelException {return true;}
public GroupIndex getMap()
{
int[][] grps = _lnet.findGroups();
return new BBusGrpMap(grps, _nbus);
}
static class FixedGrpMap extends AbstractList<int[]>
{
int[][] _grps;
FixedGrpMap(int[][] grps)
{
_grps = grps;
}
@Override
public int[] get(int index)
{
return _grps[index];
}
@Override
public int size()
{
return _grps.length;
}
};
static class BBusGrpMap extends BasicGroupIndex
{
public BBusGrpMap(int[][] grps, int nbus)
{
List<int[]> fm = new FixedGrpMap(grps);
_grps = new WeakReference<>(fm);
_ngrp = grps.length;
_map = new int[nbus];
Arrays.fill(_map, -1);
for(int ig = 0; ig < _ngrp; ++ig)
{
for(int b : grps[ig])
_map[b] = ig;
}
}
}
}