Skip to content

Commit acedeaf

Browse files
committed
Density
1 parent 4834d8f commit acedeaf

File tree

8 files changed

+70
-18
lines changed

8 files changed

+70
-18
lines changed

Editor/src/ch/zhaw/simulation/gui/codeditor/FormulaEditorDialog.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import ch.zhaw.simulation.model.flow.element.SimulationContainerData;
1616
import ch.zhaw.simulation.model.flow.element.SimulationParameterData;
1717
import ch.zhaw.simulation.model.xy.DensityData;
18+
import ch.zhaw.simulation.model.xy.MesoData;
1819
import ch.zhaw.simulation.sysintegration.Sysintegration;
1920

2021
public class FormulaEditorDialog extends BDialog {
@@ -53,6 +54,8 @@ public void setData(NamedFormulaData data, Vector<DensityData> density) {
5354
title += " - Formel";
5455
} else if (data instanceof FlowValveData) {
5556
title += " - Fluss";
57+
} else if (data instanceof MesoData.MesoDataFormula) {
58+
title += " - Bewegung";
5659
} else {
5760
System.err.println("Unknonwn Type in FormularEditorDialog: " + data.getClass());
5861
}

Editor/src/ch/zhaw/simulation/gui/codeditor/FormulaEditorPanel.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class FormulaEditorPanel extends JPanel {
5656

5757
private String value;
5858

59-
private Parser parser = new Parser();
59+
private Parser parser;
6060

6161
private NamedFormulaData data;
6262

@@ -80,7 +80,7 @@ public FormulaEditorPanel(Sysintegration sys, AbstractSimulationModel<?> model,
8080
this.model = model;
8181
this.additionalVars = addiditonalVars;
8282
this.autosaveFormula = autosaveFormula;
83-
this.library = new FormulaLibraryPanel(parser);
83+
this.library = new FormulaLibraryPanel();
8484
this.library.addActionListener(new ActionListener() {
8585

8686
@Override
@@ -250,7 +250,8 @@ public void setData(NamedFormulaData data, Vector<DensityData> density) {
250250
value = data.getFormula();
251251
this.data = data;
252252

253-
this.parser.enableGradient(density);
253+
this.parser = new Parser(density);
254+
this.library.setParser(this.parser);
254255

255256
text.setText(data.getFormula());
256257

@@ -304,10 +305,6 @@ private Constant[] getConst() {
304305
return parser.getConst();
305306
}
306307

307-
public Parser getParser() {
308-
return parser;
309-
}
310-
311308
public void dispose() {
312309
if (checkTimer != null) {
313310
checkTimer.cancel();

Editor/src/ch/zhaw/simulation/gui/codeditor/library/FormulaLibraryPanel.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.swing.JTree;
1313
import javax.swing.event.TreeSelectionEvent;
1414
import javax.swing.event.TreeSelectionListener;
15+
import javax.swing.tree.DefaultTreeModel;
1516
import javax.swing.tree.TreePath;
1617

1718
import butti.javalibs.listener.ListenerList;
@@ -28,13 +29,13 @@ public class FormulaLibraryPanel extends JPanel {
2829

2930
private ListenerList listener = new ListenerList();
3031

31-
public FormulaLibraryPanel(Parser parser) {
32+
public FormulaLibraryPanel() {
3233
setLayout(new BorderLayout());
33-
tree = new JTree(new LibraryRootNode(parser));
34+
tree = new JTree();
3435

3536
tree.setRootVisible(false);
3637
tree.setShowsRootHandles(true);
37-
38+
3839
tree.addTreeSelectionListener(new TreeSelectionListener() {
3940

4041
@Override
@@ -97,4 +98,7 @@ public void removeActionListener(ActionListener l) {
9798
listener.removeListener(l);
9899
}
99100

101+
public void setParser(Parser parser) {
102+
tree.setModel(new DefaultTreeModel(new LibraryRootNode(parser)));
103+
}
100104
}

ExternLibraries/lib/B-Lib.jar

251 Bytes
Binary file not shown.

Simulation/src/ch/zhaw/simulation/dialog/mathoverview/MathOverview.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public MathOverview(Window parent) {
1616
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
1717
setTitle("Matheüberblick");
1818

19-
Parser parser = new Parser();
20-
parser.enableGradient(new Vector<DensityData>());
21-
FormulaLibraryPanel library = new FormulaLibraryPanel(parser);
19+
Parser parser = new Parser(new Vector<DensityData>());
20+
FormulaLibraryPanel library = new FormulaLibraryPanel();
21+
library.setParser(parser);
2222

2323
add(library);
2424

SimulationDiagram/src/ch/zhaw/simulation/diagram/tableview/SimulationTableModel.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
public class SimulationTableModel extends AbstractTableModel {
1212
private static final long serialVersionUID = 1L;
1313
private SimulationSerie[] data;
14+
private SimulationSerie timeSerie;
15+
1416
private int rowCount = 0;
1517

1618
public SimulationTableModel(SimulationCollection series) {
@@ -48,11 +50,25 @@ public boolean isCellEditable(int rowIndex, int columnIndex) {
4850
@Override
4951
public Object getValueAt(int rowIndex, int columnIndex) {
5052
if (columnIndex == 0) {
51-
return data[0].getData().get(rowIndex).time;
53+
if (timeSerie.getData().size() > rowIndex) {
54+
return timeSerie.getData().get(rowIndex).time;
55+
} else {
56+
return "";
57+
}
58+
}
59+
60+
if (data.length <= columnIndex - 1) {
61+
return "";
5262
}
5363

54-
Vector<SimulationEntry> row = data[columnIndex - 1].getData();
64+
SimulationSerie serie = data[columnIndex - 1];
65+
66+
if(serie.isConstValue()) {
67+
return serie.getConstValue();
68+
}
5569

70+
Vector<SimulationEntry> row = serie.getData();
71+
5672
if (rowIndex >= row.size()) {
5773
return ""; // No simulation Data
5874
}
@@ -63,9 +79,15 @@ public Object getValueAt(int rowIndex, int columnIndex) {
6379
public void setSeries(SimulationCollection series) {
6480
data = series.getSeries();
6581
rowCount = 0;
66-
if (data.length > 0) {
67-
rowCount = data[0].getData().size();
82+
83+
for (SimulationSerie d : data) {
84+
int s = d.getData().size();
85+
if (rowCount < s) {
86+
rowCount = s;
87+
timeSerie = d;
88+
}
6889
}
90+
6991
fireTableStructureChanged();
7092
}
7193
}

SimulationParser/src/ch/zhaw/simulation/math/Parser.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@ public class Parser {
2626

2727
private Function[] functionlist;
2828
private Constant[] constlist;
29+
private Vector<DensityData> density;
2930

3031
public Parser() {
32+
this(null);
33+
}
34+
35+
public Parser(Vector<DensityData> density) {
36+
this.density = density;
3137
newParser();
3238
}
3339

3440
public void enableGradient(Vector<DensityData> density) {
41+
this.density = density;
42+
applyDensity();
43+
}
44+
45+
private void applyDensity() {
3546
jep.removeFunction("grad");
3647

3748
if (density != null) {
@@ -51,6 +62,8 @@ private void newParser() {
5162
// jep.addComplex();
5263
jep.getSymbolTable().remove("x");
5364

65+
applyDensity();
66+
5467
// Add all functions from JEP to functionlist[]
5568
Vector<Function> functionlist = new Vector<Function>();
5669
for (Entry<String, PostfixMathCommandI> e : jep.getFunctionTable().entrySet()) {

SimulationPlugin.Intern/src/ch/zhaw/simulation/sim/intern/rungekutta/RungeKuttaSimulation.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,26 @@ protected SimulationCollection simulate() throws CompilerError, ParseException,
5454
for (SimulationContainerData c : model.getSimulationContainer()) {
5555
((SimulationAttachment) c.attachment).tmp = new TmpContainerValues();
5656
}
57+
58+
this.time = 0;
59+
60+
// time=0, initialvalue for containers
61+
for (SimulationContainerData c : model.getSimulationContainer()) {
62+
Object v = ((SimulationContainerAttachment) c.attachment).calc(this.time, this.dt);
63+
((SimulationAttachment) c.attachment).serie.add(time, v);
64+
}
65+
66+
calcParameters();
5767

58-
for (time = dt; time < endTime && !isCancelled(); time += dt) {
68+
while (time < endTime && !isCancelled()) {
5969
setProgress((int) (time / endTime * 100));
6070
calcFlowValues1();
6171
calcFlowValues2();
6272
calcFlowValues3();
6373
calcFlowValues4();
74+
75+
time += dt;
76+
6477
calcContainers();
6578
calcParameters();
6679

0 commit comments

Comments
 (0)