Scripted Pre-processing

Attention

This capability is currently under development as of July 2021. Supported in M-Star versions 3.2.14+

Overview

M-Star supports pre-processing via a python interface. The current supported actions are summarized as follows –

  • Change property values

  • Export solver case files

  • Load/save *.msb files

Installation

M-Star python is compatible with Miniconda3 with Python 3.9, installer version 4.9.2.

Follow the Miniconda installation instructions – https://conda.io/projects/conda/en/latest/user-guide/install/index.html

Start a new command prompt with the conda environment. For more information on how to get started, see the conda documentation – https://conda.io/projects/conda/en/latest/user-guide/getting-started.html

Example

The below example is comprised of a python script and a bash script that sets up the environment and executes the script. To run the example, copy this code into new files and create an example msb file called “simulation.msb” using the built-in agitated test example case.

test.py:

import sys
import os
import mstar

mstar.set_verbose()

# checkout license
mstar.get_license()

# load msb file into the variable 'm'
m = mstar.load(r"simulation.msb")

# Get the fluid model
fm = m.get("Single Phase Model")

# Show the density
print("Density = ", fm.get("Density"))

# change the density
print("-- Setting density")
fm.set("Density", 1200.0)
print("Density = ", fm.get("Density"))

# Save the msb document as a new file
caseDir = r"python-test"

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

fn2 = os.path.join(caseDir, r"saved_by_python.msb")
print ("-- Saving document;", fn2)
m.save(fn2)

# Export the solver case files
print ("-- Exporting case: ", caseDir)
m.export(caseDir)

run.sh:

# Source the M-Star environment
source ~/3.2.14/mstar.sh

# Setup the M-Star license
export mstar_LICENSE=mymstar.lic

# Add the lib directory to your python module search path
export PYTHONPATH=~/3.2.14/lib

# run the script
python test.py