Skip to content

Commit

Permalink
Let simulators choose if they want to write to file (+filename).
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikbucher committed Aug 31, 2013
1 parent 0924d2c commit ca7b96a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 12 additions & 2 deletions MOISCore/src/main/scala/ed/mois/core/storm/StormSim.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ abstract class StormSim {
*/
val printGnu = true

/**
* Tells the simulator if data should be written to disk.
*/
val writeData = true

/**
* The filename of the output data file.
*/
val fileName = "data.dat"

/**
* Overwrite to define the model to be simulated.
*/
Expand Down Expand Up @@ -77,8 +87,8 @@ abstract class StormSim {
println(s"""Simulation '${model.title}' took ${time.toDouble / 1000} seconds and resulted in ${endSim.size} data vectors of size ${endSim.head._2.fields.size}.""")

// Logging
if (!endSim.isEmpty) {
loggingStrategy.writeStormData(model, endSim)
if (!endSim.isEmpty && writeData) {
loggingStrategy.writeStormData(fileName, model, endSim)
}

println("Finished logging to disk, starting Gnuplot.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import scala.collection.immutable.TreeMap
class DataToFileWriter {
val fileName = "data.dat"

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

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

def writeStormData(model: StormModel, d: TreeMap[Double, StormState[_]]) {
def writeStormData(fileN: String, model: StormModel, d: TreeMap[Double, StormState[_]]) {
for {
outProcessor <- Resource.fromOutputStream(new java.io.FileOutputStream(fileName)).outputProcessor
outProcessor <- Resource.fromOutputStream(new java.io.FileOutputStream(fileN)).outputProcessor
out = outProcessor.asOutput
} {
// Write data header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object SampleODESimRunner extends App {
val sim = new StormSim {
override val simulationStrategy = () => new IndepTimeScaleStrategy(50.0, 0.05) {override val debug = false}
val model = new SampleODEModel
override val fileName = "sampleODE.dat"
}

val results = sim.runSim
Expand Down

0 comments on commit ca7b96a

Please sign in to comment.