/
SimulationResult.java
198 lines (168 loc) · 5.67 KB
/
SimulationResult.java
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* jspice is distributed under the GNU General Public License version 3
* and is also available under alternative licenses negotiated directly
* with Knowm, Inc.
*
* Copyright (c) 2016-2017 Knowm Inc. www.knowm.org
*
* Knowm, Inc. holds copyright
* and/or sufficient licenses to all components of the jspice
* package, and therefore can grant, at its sole discretion, the ability
* for companies, individuals, or organizations to create proprietary or
* open source (even if not GPL) modules which may be dynamically linked at
* runtime with the portions of jspice which fall under our
* copyright/license umbrella, or are distributed under more flexible
* licenses than GPL.
*
* The 'Knowm' name and logos are trademarks owned by Knowm, Inc.
*
* If you have any questions regarding our licensing policy, please
* contact us at `contact@knowm.org`.
*/
package org.knowm.jspice.simulate;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class SimulationResult {
private final String xDataLabel;
private final String yDataLabel;
private final Map<String, SimulationPlotData> simulationDataMap;
/**
* Constructor
*
* @param xDataLabel
* @param yDataLabel
* @param simulationDataMap
*/ public SimulationResult(String xDataLabel, String yDataLabel, Map<String, SimulationPlotData> simulationDataMap) {
this.xDataLabel = xDataLabel;
this.yDataLabel = yDataLabel;
this.simulationDataMap = simulationDataMap;
}
public String getxDataLabel() {
return xDataLabel;
}
public String getyDataLabel() {
return yDataLabel;
}
public Map<String, SimulationPlotData> getSimulationPlotDataMap() {
return simulationDataMap;
}
@Override
public String toString() {
String returnString = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();
sb.append("SimulationResult");
sb.append(returnString);
sb.append("xDataLabel=" + xDataLabel);
sb.append(returnString);
sb.append("yDataLabel=" + yDataLabel);
sb.append(returnString);
for (Entry<String, SimulationPlotData> entrySet : simulationDataMap.entrySet()) {
String observableValueID = entrySet.getKey();
SimulationPlotData timeSeriesData = entrySet.getValue();
sb.append("observableValueID=" + observableValueID);
sb.append(returnString);
sb.append("timeSeriesData=" + timeSeriesData);
sb.append(returnString);
}
return sb.toString();
}
public String toXyceString() {
int count = 0;
StringBuilder sb = new StringBuilder();
String returnString = System.getProperty("line.separator");
sb.append("Index");
sb.append("\t");
sb.append("Time");
sb.append("\t");
for (Entry<String, SimulationPlotData> entrySet : simulationDataMap.entrySet()) {
sb.append(entrySet.getKey());
sb.append("\t");
}
sb.append(returnString);
List<Number> xData = simulationDataMap.values().iterator().next().getxData();
do {
sb.append(count);
sb.append("\t");
sb.append(xData.get(count));
sb.append("\t");
for (Entry<String, SimulationPlotData> entrySet : simulationDataMap.entrySet()) {
sb.append(entrySet.getValue().getyData().get(count));
sb.append("\t");
}
sb.append(returnString);
} while (++count < xData.size());
sb.append("End of JSpice Simulation");
return sb.toString();
}
public String toXyceRawString(String sourceFile) {
int count = 0;
StringBuilder sb = new StringBuilder();
Date today = Calendar.getInstance().getTime();
List<Number> xData = simulationDataMap.values().iterator().next().getxData();
String returnString = System.getProperty("line.separator");
sb.append("Title: " + sourceFile);
sb.append(returnString);
sb.append("Date: " + today.toString());
sb.append(returnString);
sb.append("Plotname: Transient Analysis");
sb.append(returnString);
sb.append("Flags: real");
sb.append(returnString);
sb.append("No. Variables: ");
sb.append(simulationDataMap.values().size()+1);
sb.append(returnString);
sb.append("No. Points: ");
sb.append(xData.size());
sb.append(returnString);
sb.append("Variables:");
sb.append(returnString);
// plot data labels
sb.append("\t0\tTime\ttime");
sb.append(returnString);
count = 1;
for (Entry<String, SimulationPlotData> entrySet : simulationDataMap.entrySet()) {
// 0 Time time
// 1 I(VPR1) current
// 2 V(VIN) voltage
// ...
String label = entrySet.getKey();
sb.append("\t");
sb.append(count);
sb.append("\t");
sb.append(label);
sb.append("\t");
// data type
if (label.startsWith("I")) {
sb.append("current");
} else if (label.startsWith("V")) {
sb.append("voltage");
} else if (label.startsWith("R")) {
sb.append("resistance");
}
count++;
sb.append(returnString);
}
sb.append("Values:");
sb.append(returnString);
// write first time datum followed by Y-data values
count = 0;
do {
sb.append(count);
sb.append("\t");
sb.append(xData.get(count));
sb.append(returnString);
for (Entry<String, SimulationPlotData> entrySet : simulationDataMap.entrySet()) {
String label = entrySet.getKey();
sb.append("\t");
sb.append(entrySet.getValue().getyData().get(count));
sb.append(returnString);
}
sb.append(returnString);
} while (++count < xData.size());
//sb.append("End of JSpice Simulation");
return sb.toString();
}
}