Skip to content

Commit ca7b96a

Browse files
committed
Let simulators choose if they want to write to file (+filename).
1 parent 0924d2c commit ca7b96a

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

MOISCore/src/main/scala/ed/mois/core/storm/StormSim.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ abstract class StormSim {
4545
*/
4646
val printGnu = true
4747

48+
/**
49+
* Tells the simulator if data should be written to disk.
50+
*/
51+
val writeData = true
52+
53+
/**
54+
* The filename of the output data file.
55+
*/
56+
val fileName = "data.dat"
57+
4858
/**
4959
* Overwrite to define the model to be simulated.
5060
*/
@@ -77,8 +87,8 @@ abstract class StormSim {
7787
println(s"""Simulation '${model.title}' took ${time.toDouble / 1000} seconds and resulted in ${endSim.size} data vectors of size ${endSim.head._2.fields.size}.""")
7888

7989
// Logging
80-
if (!endSim.isEmpty) {
81-
loggingStrategy.writeStormData(model, endSim)
90+
if (!endSim.isEmpty && writeData) {
91+
loggingStrategy.writeStormData(fileName, model, endSim)
8292
}
8393

8494
println("Finished logging to disk, starting Gnuplot.")

MOISCore/src/main/scala/ed/mois/core/util/DataToFileWriter.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import scala.collection.immutable.TreeMap
1414
class DataToFileWriter {
1515
val fileName = "data.dat"
1616

17-
val clearOutput = Resource.fromOutputStream(new java.io.FileOutputStream(fileName))
18-
clearOutput.write("")
1917
val output: Output = Resource.fromFile("data.dat")
2018

2119
def writeDataHeader(dh: Array[String]) {
20+
val clearOutput = Resource.fromOutputStream(new java.io.FileOutputStream(fileName))
21+
clearOutput.write("")
2222
output.write("t " + dh.mkString(" ") + "\n")
2323
}
2424
def writeDataPoints(t0: Double, dps: Array[Any]) {
@@ -28,9 +28,9 @@ class DataToFileWriter {
2828
output.write(p._1 + " " + p._2.fields.map(_._2).mkString(" ") + "\n")
2929
}
3030

31-
def writeStormData(model: StormModel, d: TreeMap[Double, StormState[_]]) {
31+
def writeStormData(fileN: String, model: StormModel, d: TreeMap[Double, StormState[_]]) {
3232
for {
33-
outProcessor <- Resource.fromOutputStream(new java.io.FileOutputStream(fileName)).outputProcessor
33+
outProcessor <- Resource.fromOutputStream(new java.io.FileOutputStream(fileN)).outputProcessor
3434
out = outProcessor.asOutput
3535
} {
3636
// Write data header

MOISModels/src/main/scala/ed/mois/models/storm/SampleODESystem.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ object SampleODESimRunner extends App {
1919
val sim = new StormSim {
2020
override val simulationStrategy = () => new IndepTimeScaleStrategy(50.0, 0.05) {override val debug = false}
2121
val model = new SampleODEModel
22+
override val fileName = "sampleODE.dat"
2223
}
2324

2425
val results = sim.runSim

0 commit comments

Comments
 (0)