Initial State¶
The initial state mapping can be modified through the API. An example is shown below.
Example
import mstar
mstar.Initialize()
model = mstar.Load()
model.AddComponent("Particles")
# Get simulation parameters object
sp = model.GetSimParams()
# Setting the properties that are visible in the normal property grid
sp.Get("State Mode").Value = "ExternalLoad"
sp.Get("Set Time From Init State").Value = True
# The following code implements what you would typically do through the GUI form
# Get the checkpoint mapping state. This object contains a list of the mapped fields
# You can interact with GetKeys(), GetItem(), SetItem()
state = sp.GetCheckPointMapState()
# Print all the keys that are available, tuples (name, type)
for key in state.GetKeys():
print (key)
# Get a specific item and change the Enabled value
# These items have a number of fields, GetName, GetType, GetEnabled, SetEnabled, etc
fluidItem = state.GetItem("Pressure", mstar.ChkVariableTypeEnum.Fluid)
fluidItem.SetEnabled(False)
# Get a particle mapping item. These have a few additional fields available
partItem = state.GetItem("Inertial_Particles", mstar.ChkVariableTypeEnum.Particle)
partItem.SetEnabled(True)
partItem.SetCopySize(False)
partItem.SetCopyVelocity(True)
partItem.SetInjectionTime(0.1)
# Set the item into the state object
state.SetItem(fluidItem)
state.SetItem(partItem)
# Set the state object on the Simulation Parameters
sp.SetCheckPointMapState(state)
# Set the checkpoint load path you want to use
sp.GetInitialStatePath().Value = "C:\\r\\0306-test\\out\\Checkpoint\\Time9.00022e+00"
# Set how the initial data will be referenced
sp.GetInitialStateOption().Value = "LocalRef"
# Save
model.Save("init state test.msb")
- class CheckPointMapper¶
- GetKeys()¶
Return a list of tuples of (name, type)
- GetItem(name, type)¶
Get an individual item by looking for the name and type
- Return type:
- SetItem(item)¶
- Parameters:
item (CheckPointMappedItem) – Updates the item in the mapping
- class CheckPointMappedItem¶
- GetName()¶
Return item name
- GetType()¶
Get Item type: Fluid, Particle, CustomVar, ScalarF, MovingBody, Unknown
- GetEnabled()¶
Get item enabled status
- SetEnabled()¶
Update item enabled status
- GetCopySize()¶
only available for Particle types
- GetCopyVelocity()¶
only available for Particle types
- GetInjectionTime()¶
only available for Particle types
- SetCopySize()¶
only available for Particle types
- SetCopyVelocity()¶
only available for Particle types
- SetInjectionTime()¶
only available for Particle types