Skip to main content

A Python wrapper for Ansys System Coupling.

Project description

pyansys GH-CI MIT black

Overview

PySystemCoupling provides Pythonic access to Ansys System Coupling. Although this Ansys product exposes its own Python-based scripting and command line interface, it is embedded and based on a specific version of Python. In contrast, PySystemCoupling enables seamless use of System Coupling within the Python ecosystem, providing additional capabilities, including:

  • Ability to launch System Coupling using a local Ansys installation

  • Access to APIs to set up and solve coupled analyses

  • Full access to the System Coupling data model via a convenient and Pythonic interface

Installation

Install PySystemCoupling with this command:

pip install ansys-systemcoupling-core

Alternatively, clone and install PySystemCoupling in development mode with this code:

git clone https://github.com/pyansys/pysystem-coupling.git
cd pysystem-coupling
python -m pip install --upgrade pip
pip install -e .
pip install .[classesgen]
python scripts\generate_datamodel.py

Documentation and Issues

For more information, see the Documentation page.

Use the PySystemCoupling Issues page to post bug reports, questions and feature requests.

Usage

It is assumed that an Ansys installation is available and that this installation includes System Coupling and the participant products needed for the coupled analysis.

The System Coupling installation is found by examining the following environment variables in this order:

  • SYSC_ROOT

  • AWP_ROOT

  • AWP_ROOT231

If a variable is set but does not refer to a valid installation, PySystemCoupling fail at that point, rather than attempting to use the next variable.

In a standard user installation, the expectation is that only AWP_ROOT231 is set.

The System Coupling API is exposed to PySystemCoupling in two forms:

  • A documented interface based on concrete Python classes, following Pythonic conventions

  • A dynamic interface, undocumented in PySystemCoupling, that replicates the native System Coupling API

Both forms are strongly related to each other. A key difference in the Pythonic API is that naming is adjusted, in a generally predictable manner, to follow Python conventions. If you are already familiar with System Coupling, adjusting to this form, which is the recommended API, should be easy. However, if you are transitioning existing scripts, the native System Coupling API is made available as a convenience.

This example shows how to set up and solve an oscillating plate example in the Pythonic API. It uses Ansys Fluent as the CFD solver.

import ansys.systemcoupling.core as pysystemcoupling

syc = pysystemcoupling.launch()
setup = syc.setup
setup.add_participant(input_file="mapdl.scp")
setup.add_participant(input_file="fluent.scp")

## Create interfaces and data transfers by specifying participant regions

interface_name = "interface-1"
interface = setup.coupling_interface.create(interface_name)
interface.side["One"].coupling_participant = "MAPDL-1"
interface.side["One"].region_list = ["FSIN_1"]
interface.side["Two"].coupling_participant = "FLUENT-2"
interface.side["Two"].region_list = ["wall_deforming"]

# Use commands to add data transfers
force_transfer_name = setup.add_data_transfer(
    interface=interface_name,
    target_side="One",
    side_one_variable="FORC",
    side_two_variable="force",
)

disp_transfer_name = setup.add_data_transfer(
    interface=interface_name,
    target_side="Two",
    side_one_variable="INCD",
    side_two_variable="displacement",
)

# Change analysis duration and step size
setup.solution_control.time_step_size = "0.1 [s]"
setup.solution_control.end_time = "1.0 [s]"

# Set output control settings
setup.output_control.option = "StepInterval"
setup.output_control.output_frequency = 2

# Start streaming standard output from server
syc.start_output()

# Solve
solution = syc.solution
solution.solve()

The Pythonic API partitions commands via three high-level root attributes of the Session class: setup, solution, and case. The preceding example uses both the setup and solution attributes.

  • The setup attribute is the largest part of the API. It is where you find all commands related to populating the settings that define a coupled analysis. This attribute also provides direct access to the hierarchical data model.

  • The solution attribute is home to commands related to solving an analysis and examining the solution.

  • The case attribute, which is not used in the preceding example, provides all commands related to case file management and persistence.

While the preceding example uses the pysystemcoupling.launch() method to start the System Coupling server, alternatively, the server can be started in advance by calling command line arguments -m cosimgui --grpcport=<host:port> and pysystemcoupling.connect(host, port).

This next example shows how to set up the same analysis using the native System Coupling API. While the code here is less complete than the code shown previously, it should sufficiently illustrate the differences and connections between the two API forms.

import ansys.systemcoupling.core as pysystemcoupling

syc = pysystemcoupling.launch()
native_api = syc._native_api

native_api.AddParticipant(InputFile="mapdl.scp")
native_api.AddParticipant(InputFile="fluent.scp")

interface = native_api.CouplingInterface["interface-1"]
interface.Side["One"].CouplingParticipant = "MAPDL-1"
...

native_api.SolutionControl.TimeStepSize = "0.1 [s]"
...
syc.start_output()
native_api.Solve()

License

PySystemCoupling is licensed under the MIT license.

The ansys-systemcoupling-core package makes no commercial claim over Ansys whatsoever. It extends the functionality of Ansys System Coupling by adding a Python interface to the System Coupling service without changing the core behavior or license of the original software. Interactively controlling System Coupling via PySystemCoupling requires a local copy of System Coupling and licenses for all Ansys products involved in your coupled analysis.

To get a copy of Ansys, visit Ansys.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansys-systemcoupling-core-0.1.1.tar.gz (78.7 kB view details)

Uploaded Source

Built Distribution

ansys_systemcoupling_core-0.1.1-py3-none-any.whl (126.1 kB view details)

Uploaded Python 3

File details

Details for the file ansys-systemcoupling-core-0.1.1.tar.gz.

File metadata

File hashes

Hashes for ansys-systemcoupling-core-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cf7fa5e6af21cd5c746bc3b8b231c978765014d8bbe315f168af772131b8b582
MD5 f7007ad4e4afb52a2c7a3d5051f09f91
BLAKE2b-256 6e98ced050a22c18a1a6651f150f74c84b41b896e502092345be1d0bec28fcb5

See more details on using hashes here.

File details

Details for the file ansys_systemcoupling_core-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ansys_systemcoupling_core-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 875b00b09a450ef1d4493781bf2a923a533cbbf973bf500f720681fdc4cff5c2
MD5 d8f5b20583d4062383a705e662f0ab2a
BLAKE2b-256 6c05dd9c74bd2fc3a044fb0205b7d0ac72a0a3dd09ea263c4c162c0e25bf752d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page