Skip to content

Commit 8ae6c5b

Browse files
cainjajacob-evarts
andauthored
Add graph logging with bonus command settings changes (#181)
* added example for settings * added output example for graph * spotless * added graph serializer and output saver * docstrings * minor linter changes * i should fix my autoformatter * added getters for site edge variables * some extra docstrings I missed * Remove nutrients command * cleaned up saveGraphComponents to just saveComponenets for layer saver in future * abstract save method * Update src/arcade/core/sim/output/OutputSaver.java Co-authored-by: Jacob Evarts <[email protected]> --------- Co-authored-by: Jacob Evarts <[email protected]>
1 parent 980b39c commit 8ae6c5b

File tree

13 files changed

+300
-52
lines changed

13 files changed

+300
-52
lines changed

src/arcade/core/ARCADE.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public abstract class ARCADE {
5656
/** Version number. */
5757
public static final String VERSION = loadVersion();
5858

59+
/** Command line settings for ARCADE simulation. */
60+
protected MiniBox settings = new MiniBox();
61+
5962
/**
6063
* Gets the resource relative to the location of the class.
6164
*
@@ -139,13 +142,13 @@ public static void main(String[] args) throws Exception {
139142
Box parameters = arcade.loadParameters(args[0]);
140143

141144
// Parse arguments from command line.
142-
MiniBox settings = arcade.parseArguments(args, commands);
145+
arcade.settings = arcade.parseArguments(args, commands);
143146

144147
// Build series
145-
ArrayList<Series> series = arcade.buildSeries(parameters, settings);
148+
ArrayList<Series> series = arcade.buildSeries(parameters);
146149

147150
// Run series.
148-
arcade.runSeries(series, settings);
151+
arcade.runSeries(series);
149152
}
150153

151154
/**
@@ -264,11 +267,9 @@ MiniBox parseArguments(String[] args, Box commands) {
264267
* Builds series based on setup file.
265268
*
266269
* @param parameters a container of default parameter values
267-
* @param settings a container of parsed arguments
268270
* @return a list of {@link Series} instances
269271
*/
270-
ArrayList<Series> buildSeries(Box parameters, MiniBox settings)
271-
throws IOException, SAXException {
272+
ArrayList<Series> buildSeries(Box parameters) throws IOException, SAXException {
272273
String setupFile = settings.get("SETUP_FILE");
273274
String snapshotPath = settings.get("SNAPSHOT_PATH");
274275
boolean isVis = settings.contains("VIS");
@@ -288,9 +289,8 @@ ArrayList<Series> buildSeries(Box parameters, MiniBox settings)
288289
* valid series in the list are run.
289290
*
290291
* @param series the list of {@link Series} instances
291-
* @param settings a container of parsed arguments
292292
*/
293-
void runSeries(ArrayList<Series> series, MiniBox settings) throws Exception {
293+
void runSeries(ArrayList<Series> series) throws Exception {
294294
boolean isVis = settings.contains("VIS");
295295
String loadPath = settings.get("LOAD_PATH");
296296
boolean loadCells = settings.contains("LOAD_CELLS");

src/arcade/core/sim/output/OutputSaver.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
*/
2929
public abstract class OutputSaver implements Steppable {
3030
/** Logger for {@code OutputSaver}. */
31-
private static final Logger LOGGER = Logger.getLogger(OutputSaver.class.getName());
31+
protected static final Logger LOGGER = Logger.getLogger(OutputSaver.class.getName());
3232

3333
/** Number of elements to format in output string. */
34-
private static final int FORMAT_ELEMENTS = 6;
34+
protected static final int FORMAT_ELEMENTS = 6;
3535

3636
/** JSON representation. */
37-
final Gson gson;
37+
protected final Gson gson;
3838

3939
/** {@link arcade.core.sim.Series} instance. */
4040
final Series series;
@@ -43,7 +43,7 @@ public abstract class OutputSaver implements Steppable {
4343
public String prefix;
4444

4545
/** {@link arcade.core.sim.Simulation} instance. */
46-
Simulation sim;
46+
protected Simulation sim;
4747

4848
/**
4949
* Creates an {@code OutputSaver} for the series.
@@ -109,6 +109,15 @@ public void saveLocations(int tick) {
109109
@Override
110110
public void step(SimState simstate) {
111111
int tick = (int) simstate.schedule.getTime();
112+
save(tick);
113+
}
114+
115+
/**
116+
* Saves the relevant data.
117+
*
118+
* @param tick the simulation tick
119+
*/
120+
public void save(int tick) {
112121
saveCells(tick);
113122
saveLocations(tick);
114123
}

src/arcade/patch/PatchARCADE.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public OutputLoader getLoader(Series series) {
3131

3232
@Override
3333
public OutputSaver getSaver(Series series) {
34-
return new PatchOutputSaver(series);
34+
PatchOutputSaver saver = new PatchOutputSaver(series);
35+
saver.saveGraph = settings.contains("SAVE_GRAPH");
36+
return saver;
3537
}
3638
}

src/arcade/patch/command.patch.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<commands>
2+
<switch id="SAVE_GRAPH" short="g" long="graph" help="Save the GRAPH output files" />
23
</commands>

src/arcade/patch/env/component/PatchComponentSitesGraph.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ public boolean getRoot() {
436436
public double getPressure() {
437437
return pressure;
438438
}
439+
440+
/**
441+
* Get the oxygen partial pressure of the node.
442+
*
443+
* @return the node oxygen partial pressure
444+
*/
445+
public double getOxygen() {
446+
return oxygen;
447+
}
439448
}
440449

441450
/**
@@ -534,6 +543,15 @@ public int getSign() {
534543
return type.category.sign;
535544
}
536545

546+
/**
547+
* Gets the type of the edge.
548+
*
549+
* @return the edge type
550+
*/
551+
public String getType() {
552+
return type.toString();
553+
}
554+
537555
/**
538556
* Get the radius of the edge.
539557
*
@@ -543,6 +561,15 @@ public double getRadius() {
543561
return radius;
544562
}
545563

564+
/**
565+
* Get the length of the edge.
566+
*
567+
* @return the edge length
568+
*/
569+
public double getLength() {
570+
return length;
571+
}
572+
546573
/**
547574
* Get the wall thickness of the edge.
548575
*
@@ -551,6 +578,33 @@ public double getRadius() {
551578
public double getWall() {
552579
return wall;
553580
}
581+
582+
/**
583+
* Get the shear stress of the edge.
584+
*
585+
* @return the edge shear stress
586+
*/
587+
public double getShear() {
588+
return shear;
589+
}
590+
591+
/**
592+
* Get the circumferential stress of the edge.
593+
*
594+
* @return the edge circumferential stress
595+
*/
596+
public double getCircum() {
597+
return circum;
598+
}
599+
600+
/**
601+
* Get the volumetric flow rate of the edge.
602+
*
603+
* @return the edge volumetric flow rate
604+
*/
605+
public double getFlow() {
606+
return flow;
607+
}
554608
}
555609

556610
/**

src/arcade/patch/env/component/PatchComponentSitesGraphFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ enum Border {
4242
}
4343

4444
/** Edge types. */
45-
enum EdgeType {
45+
public enum EdgeType {
4646
/** Code for arteriole edge type. */
4747
ARTERIOLE(EdgeCategory.ARTERY),
4848

src/arcade/patch/sim/PatchSimulation.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.HashMap;
55
import java.util.HashSet;
6+
import java.util.Set;
67
import sim.engine.Schedule;
78
import sim.engine.SimState;
89
import arcade.core.agent.action.Action;
@@ -147,6 +148,15 @@ public final Component getComponent(String key) {
147148
return components.get(key);
148149
}
149150

151+
/**
152+
* Gets the set of keys for the component hash set.
153+
*
154+
* @return the set of component keys
155+
*/
156+
public Set<String> getComponentKeys() {
157+
return components.keySet();
158+
}
159+
150160
/**
151161
* Called at the start of the simulation to set up agents and environment and schedule actions
152162
* and components as needed.
@@ -354,8 +364,7 @@ public void doOutput(boolean isScheduled) {
354364
series.saver.schedule(schedule, series.getInterval());
355365
} else {
356366
int tick = (int) schedule.getTime() + 1;
357-
series.saver.saveCells(tick);
358-
series.saver.saveLocations(tick);
367+
series.saver.save(tick);
359368
}
360369
}
361370
}

src/arcade/patch/sim/output/PatchOutputSaver.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package arcade.patch.sim.output;
22

33
import com.google.gson.Gson;
4+
import sim.engine.SimState;
5+
import arcade.core.env.component.Component;
46
import arcade.core.sim.Series;
57
import arcade.core.sim.output.OutputSaver;
8+
import arcade.patch.env.component.PatchComponentSitesGraph;
9+
import arcade.patch.sim.PatchSimulation;
610

711
/** Custom saver for patch-specific serialization. */
812
public final class PatchOutputSaver extends OutputSaver {
13+
14+
/** {@code true} to save graph components, {@code false} otherwise. */
15+
public boolean saveGraph;
16+
917
/**
1018
* Creates an {@code PatchOutputSaver} for the series.
1119
*
@@ -19,4 +27,38 @@ public PatchOutputSaver(Series series) {
1927
protected Gson makeGSON() {
2028
return PatchOutputSerializer.makeGSON();
2129
}
30+
31+
/**
32+
* Save a list of {@link arcade.patch.env.component.PatchComponentSitesGraph} to a JSON.
33+
*
34+
* @param tick the simulation tick
35+
*/
36+
public void saveComponents(int tick) {
37+
for (String componentKey : ((PatchSimulation) sim).getComponentKeys()) {
38+
Component component = sim.getComponent(componentKey);
39+
if (component instanceof PatchComponentSitesGraph && saveGraph) {
40+
String json =
41+
gson.toJson(
42+
(PatchComponentSitesGraph) component,
43+
PatchComponentSitesGraph.class);
44+
String path = prefix + String.format("_%06d." + componentKey + ".GRAPH.json", tick);
45+
write(path, format(json, FORMAT_ELEMENTS));
46+
}
47+
}
48+
}
49+
50+
@Override
51+
public void save(int tick) {
52+
super.save(tick);
53+
if (saveGraph) {
54+
saveComponents(tick);
55+
}
56+
}
57+
58+
@Override
59+
public void step(SimState simstate) {
60+
super.step(simstate);
61+
int tick = (int) simstate.schedule.getTime();
62+
save(tick);
63+
}
2264
}

0 commit comments

Comments
 (0)