Commit 58d34eef authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Minor refactor for command handling.

parent cd18e59a
package exastencils.visualization.ir.visit
import scala.collection.mutable.ListBuffer
import exastencils.base.ir._
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.config.Knowledge
import exastencils.datastructures.Transformation.OutputType
import exastencils.field.ir.IR_FieldCollection
import exastencils.visualization.ir.visit.IR_VisItGlobals._
import exastencils.visualization.ir.visit.IR_VisItUtil._
case class IR_VisItCommandHandling(cmd : IR_Expression) extends IR_Statement with IR_Expandable {
def step() = {
IR_IfCondition(
stringEquals(cmd, "step"),
ListBuffer[IR_Statement](
IR_FunctionCall(IR_LeveledInternalFunctionReference("simulate_timestep", Knowledge.maxLevel, IR_UnitDatatype)),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
IR_IfCondition(
updatePlots,
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots"))))))
)
}
def stop() = {
IR_IfCondition(stringEquals(cmd, "stop"),
IR_Assignment(runMode, IR_BooleanConstant(false)))
}
def run() = {
IR_IfCondition(stringEquals(cmd, "run"),
IR_Assignment(runMode, IR_BooleanConstant(true)))
}
def toggleUpdates() = {
IR_IfCondition(stringEquals(cmd, "toggle updates"),
IR_Assignment(updatePlots, IR_Negation(updatePlots)))
}
def toggleLevel() = {
IR_IfCondition(
stringEquals(cmd, "toggle level"),
ListBuffer[IR_Statement](
IR_Assignment(curLevel, modulo(curLevel - Knowledge.minLevel - 1, Knowledge.numLevels) + Knowledge.minLevel),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots")))))
}
def toggleSlot() = {
IR_IfCondition(
stringEquals(cmd, "toggle slot"),
ListBuffer[IR_Statement](
IR_Assignment(curSlot, (curSlot + 1) Mod IR_FieldCollection.objects.map(_.numSlots).max),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots")))))
}
override def expand() : OutputType = {
var stmts = ListBuffer[IR_Statement](step(), stop(), run(), toggleUpdates())
// only register level switches when necessary
if (isMultiLeveled)
stmts += toggleLevel()
// only register slot switch when necessary
if (isMultiSlotted)
stmts += toggleSlot()
stmts
}
}
......@@ -2,75 +2,19 @@ package exastencils.visualization.ir.visit
import scala.collection.mutable.ListBuffer
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir._
import exastencils.config.Knowledge
import exastencils.field.ir.IR_FieldCollection
import exastencils.visualization.ir.visit.IR_VisItGlobals._
/// IR_VisItControlCommandCallback
// implement functionality for the control buttons on the GUI
case class IR_VisItControlCommandCallback() extends IR_VisItFuturePlainFunction {
import exastencils.visualization.ir.visit.IR_VisItUtil._
override def generateFct() : IR_PlainFunction = {
val fctBody = ListBuffer[IR_Statement]()
val cmd = IR_VariableAccess("cmd", IR_SpecialDatatype("const char*"))
fctBody += IR_IfCondition(
stringEquals(cmd, "step"),
ListBuffer[IR_Statement](
IR_FunctionCall(IR_LeveledInternalFunctionReference("simulate_timestep", Knowledge.maxLevel, IR_UnitDatatype)),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
IR_IfCondition(
updatePlots,
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots"))))))
)
fctBody += IR_IfCondition(
stringEquals(cmd, "stop"),
IR_Assignment(runMode, IR_BooleanConstant(false))
)
fctBody += IR_IfCondition(
stringEquals(cmd, "run"),
IR_Assignment(runMode, IR_BooleanConstant(true))
)
fctBody += IR_IfCondition(
stringEquals(cmd, "toggle updates"),
IR_Assignment(updatePlots, IR_Negation(updatePlots))
)
// only register level switches when necessary
if (isMultiLeveled) {
fctBody += IR_IfCondition(
stringEquals(cmd, "toggle level"),
ListBuffer[IR_Statement](
IR_Assignment(curLevel, modulo(curLevel - Knowledge.minLevel - 1, Knowledge.numLevels) + Knowledge.minLevel),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots"))))
)
}
// only register slot switch when necessary
if (isMultiSlotted) {
fctBody += IR_IfCondition(
stringEquals(cmd, "toggle slot"),
ListBuffer[IR_Statement](
IR_Assignment(curSlot, (curSlot + 1) Mod IR_FieldCollection.objects.map(_.numSlots).max),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots"))))
)
}
fctBody += IR_VisItCommandHandling(cmd)
IR_PlainFunction(
name,
......
......@@ -5,7 +5,6 @@ import scala.collection.mutable.ListBuffer
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir._
import exastencils.config._
import exastencils.field.ir.IR_FieldCollection
import exastencils.parallelization.api.mpi._
import exastencils.visualization.ir.visit.IR_VisItGlobals._
......@@ -88,34 +87,7 @@ case class IR_VisItMainloop() extends IR_VisItFuturePlainFunction {
}
// process console inputs
consoleInputBody += IR_IfCondition(
stringEquals(command, "step"),
ListBuffer[IR_Statement](
IR_FunctionCall(IR_LeveledInternalFunctionReference("simulate_timestep", Knowledge.maxLevel, IR_UnitDatatype)),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
IR_IfCondition(
updatePlots,
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots")))))))
consoleInputBody += IR_IfCondition(
stringEquals(command, "stop"),
IR_Assignment(runMode, IR_BooleanConstant(false))
)
consoleInputBody += IR_IfCondition(
stringEquals(command, "run"),
IR_Assignment(runMode, IR_BooleanConstant(true))
)
consoleInputBody += IR_IfCondition(
stringEquals(command, "toggle updates"),
IR_Assignment(updatePlots, IR_Negation(updatePlots))
)
consoleInputBody += IR_VisItCommandHandling(command)
// scaling: only used for curvilinear meshes
if (Knowledge.dimensionality == 1 || Knowledge.dimensionality == 2) {
val strToReal = if (Knowledge.useDblPrecision) "std::stod" else "std::stof"
......@@ -133,31 +105,6 @@ case class IR_VisItMainloop() extends IR_VisItFuturePlainFunction {
)
)
}
if (isMultiLeveled) {
consoleInputBody += IR_IfCondition(
stringEquals(command, "toggle level"),
ListBuffer[IR_Statement](
IR_Assignment(curLevel, modulo(curLevel - Knowledge.minLevel - 1, Knowledge.numLevels) + Knowledge.minLevel),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots")))))
}
if (isMultiSlotted) {
consoleInputBody += IR_IfCondition(
stringEquals(command, "toggle slot"),
ListBuffer[IR_Statement](
IR_Assignment(curSlot, (curSlot + 1) Mod IR_FieldCollection.objects.map(_.numSlots).max),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots"))))
)
}
consoleInputBody += IR_ArrayFree(command)
whileBody += IR_IfCondition(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment