Skip to main content
Version: 0.3.0

Python and MDO frameworks

Scirocco connects to optimization frameworks through Philote, a framework-neutral standard for running an analysis as a remote discipline. Two small servers host the C++ code. Any framework with a Philote client can drive them, and both return analytic partials along with their outputs.

The examples on these pages are written in Python with OpenMDAO, using the philote-mdo client to wrap each server as an OpenMDAO component. The servers' inputs, outputs, and partials are the same from any Philote client, so the examples carry over to other frameworks.

ServerPortInputsOutputs
scirocco_server50051x, alpha, Re, Macl, cd, cm
scirocco_kulfan_server50052cst_upper, cst_lowerx, smoothness_upper, smoothness_lower

The geometry server turns CST coefficients into panel coordinates x; the analysis server turns x into forces. You can swap the geometry server for any component that produces x.

Set up​

  1. Start both servers. The quickest way is the published Docker images, which need no compiler or C++ dependencies:

    docker run -d --rm --name scirocco -p 50051:50051 chrislupp/scirocco:0.3.0
    docker run -d --rm --name scirocco-kulfan -p 50052:50052 chrislupp/scirocco-kulfan:0.3.0

    Stop them later with docker stop scirocco scirocco-kulfan.

    To build the servers yourself instead, follow Installation › Philote servers, then start each in its own terminal:

    scirocco/build-philote/src/philote/scirocco_kulfan_server localhost:50052
    scirocco/build-philote/src/philote/scirocco_server localhost:50051
  2. Get the examples and install the Python packages in a virtual environment:

    git clone https://github.com/chrislupp/Scirocco.git
    cd Scirocco
    python3.12 -m venv .venv
    source .venv/bin/activate
    python -m pip install -r examples/tutorials/requirements.txt

    This pins philote-mdo==0.8.0, which must match the server's Philote version.

Run one analysis​

python examples/tutorials/quickstart.py

The script connects the two servers as in this N2 diagram. Components sit on the diagonal, and each circle marks data passed from the component in its row to the one in its column: circles above the diagonal pass data forward, circles below it feed data back. Hover over or tap a circle to see the variables it carries.

CST geometryAnalysis

It builds this model, using OpenMDAO as the framework. Here its constants, which live in tutorial_airfoil.py, are written inline:

import grpc
import numpy as np
import openmdao.api as om
from philote_mdo.openmdao import RemoteExplicitComponent

npanel = 100

problem = om.Problem()
problem.model.add_subsystem(
"geometry",
RemoteExplicitComponent(
channel=grpc.insecure_channel("localhost:50052"),
n_cst_upper=6,
n_cst_lower=6,
te_upper=0.00063,
te_lower=-0.00063,
npanel=npanel,
),
promotes_inputs=["cst_upper", "cst_lower"],
promotes_outputs=["x"],
)
problem.model.add_subsystem(
"analysis",
RemoteExplicitComponent(
channel=grpc.insecure_channel("localhost:50051"),
naca="0012", # initializes the remote solver
npanel=npanel,
),
promotes_inputs=["x"],
)

problem.setup()

# A CST fit to NACA 0012. Use the same values on both surfaces.
cst_0012 = np.array([
0.1706635358053721, 0.15626369325824663, 0.1546327069833401,
0.14462202838023833, 0.13318428664336585, 0.15537328876198608,
])
problem.set_val("cst_upper", cst_0012)
problem.set_val("cst_lower", cst_0012)
problem.set_val("analysis.alpha", 4.0, units="deg")
problem.set_val("analysis.Re", 0.0) # zero selects inviscid analysis
problem.set_val("analysis.Ma", 0.0)

problem.run_model()

print(f"Cl = {problem.get_val('analysis.cl')[0]:.8f}")
print(f"Cd = {problem.get_val('analysis.cd')[0]:.3e}")
print(f"Cm = {problem.get_val('analysis.cm')[0]:.8f}")
Cl = 0.48270391
Cd = 0.000e+00
Cm = -0.00569190

Expect Cl between 0.47 and 0.50; the last digits vary with compiler and platform. Drag is zero because this run is inviscid. If it fails, see Troubleshooting.

The naca option only initializes the analysis server and fixes its panel count. The shape it actually analyzes is whatever arrives on x, here from the CST server.

Native Python client​

philote-mdo also has a native Python client that calls a server directly, with no framework. This runs the same model by hand, passing the geometry server's x to the analysis server:

import grpc
import numpy as np
from philote_mdo.general import ExplicitClient

npanel = 100

def connect(address, options):
client = ExplicitClient(grpc.insecure_channel(address))
client.send_options(options)
client.run_setup()
client.get_variable_definitions()
client.get_partials_definitions()
return client

geometry = connect("localhost:50052", {
"n_cst_upper": 6, "n_cst_lower": 6,
"te_upper": 0.00063, "te_lower": -0.00063, "npanel": npanel,
})
analysis = connect("localhost:50051", {"naca": "0012", "npanel": npanel})

cst_0012 = np.array([
0.1706635358053721, 0.15626369325824663, 0.1546327069833401,
0.14462202838023833, 0.13318428664336585, 0.15537328876198608,
])
x = geometry.run_compute({"cst_upper": cst_0012, "cst_lower": cst_0012})["x"]
inputs = {"x": x, "alpha": np.array([4.0]), "Re": np.array([0.0]), "Ma": np.array([0.0])}

forces = analysis.run_compute(inputs)
print(f"Cl = {forces['cl'][0]:.8f}")

partials = analysis.run_compute_partials(inputs)
print(f"dCd/dx has {partials['cd', 'x'].size} entries")
Cl = 0.48270391
dCd/dx has 202 entries

run_compute_partials returns the analytic partials, keyed by output and input. Chaining them through the geometry, as a framework would, is up to you.

Tutorials​

Each tutorial changes one thing about this model. The complete scripts are in examples/tutorials and run in CI.