Python Parameter Sweep

Generate a parameter sweep over impeller RPM

To see an alternative example of a parameter sweep implemented using built-in workflow capability, see Workflow 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)

rpmvalues = [
    60, 80, 100, 120
]

for v in rpmvalues:
    movingBody.Get("Rotation Speed UDF").ValueFloat = v
    casename = F"RotationSpeed={v}"
    casedir = os.path.join("simpleParamSweep", casename)

    if not os.path.isdir(casedir):
        os.makedirs(casedir)

    print (F"Exporting case: {casedir}")
    model.Export(casedir)
    model.Save(os.path.join(casedir, F"{casename}.msb"))