Workflow Parameter Sweep¶
Implement a parameter sweep using the built in Workflow capability.
To see an alternative example of a parameter sweep implemented using Python, see Python Parameter Sweep.
import mstar
import os
mstar.Initialize()
model = mstar.Load()
staticBody = model.AddComponent("Static")
tankGeo = staticBody.AddGeometry("Cylindrical Tank")
tankGeo.Get("Diameter").Value = 0.5
tankGeo.Get("Length").Value = 0.5
tankGeo.Get("End1").Value = "Flat"
tankGeo.Get("Baffle Width").Value = 0.05
simParams = model.GetSimParams()
movingBody = model.AddComponent("Moving")
globalVar = model.AddComponent("GlobalVariable")
miscScalar = model.AddComponent("MiscibleScalar")
impellerGeo = movingBody.AddGeometry("Rushton")
miscScalarGeo = miscScalar.AddGeometry("Cylinder")
simParams.Get("Run Time").Value = 180.0
impellerGeo.Get("Diameter").Value = 0.15
miscScalar.SetName("dye")
miscScalar.Get("Injection Time Span").Value = "Impulse"
miscScalar.Get("Injection Impulse Time").Value = 10.0
miscScalar.Get("Child Geometry Value").Value = "1.0"
miscScalarGeo.Get("Diameter").Value = 0.01
miscScalarGeo.Get("Length").Value = 0.01
miscScalarGeo.SetLocation(0.15, 0.45, 0.0)
globalVar.SetName("blendTime")
globalVar.Get("Data Source").Value = "Fluid"
globalVar.Get("Reduction").Value = "RelStdDev"
globalVar.Get("Code").Value = "value=dye;"
movingBody.Translate(0, 0.25, 0)
part = model.GetWorkFlowPartition()
sweep = part.AddParameterSweep()
sweepPropRotSpeed = sweep.AddProperty(movingBody.Get("Rotation Speed UDF"))
rpmvalues = [ 60, 80, 100, 120 ]
rpmStrValues = list(map(str, rpmvalues))
names = [ F"rpm={r}" for r in rpmStrValues ]
sweepPropRotSpeed.SetStringValues(rpmStrValues)
sweep.SetCaseNames(names)
model.Save("test-workflow-sweep.msb")
errs = sweep.Export("simpleWorkflowParamSweep")