pyemsol API Reference#

This page documents the public API for users of the Python package pyemsol. Functions callable from Python are not listed here if they are reserved for internal integration with eMotorSolution or EMSOptimizer.

General Usage Rules#

  • Pass a JSON-compatible dict / list / str / bool / int / float / None composed only of built-in Python types as inputJson. NumPy arrays, NumPy scalars, and tuples cannot be passed directly to this API.

  • Running multiple analyses concurrently in the same process is not supported. Use separate processes for parallel parameter surveys.

  • Check the result of update APIs that return bool. Always end iterative analyses with finalize(), and end external step analyses with close() or a with statement.

  • For input-data details, see Input Control Files.

Choosing an API#

  • Run an analysis once: run(input_json, run_directory)

  • Iterate while updating conditions: initialize() → update APIs → solve() → finalize()

  • Supply values from an external system at each time: with CoupledSession(...) → repeat step()

Single-Run and Iterative Analyses#

run(inputJson, run_directory) → dict#

Runs one analysis without changing the input and returns results equivalent to output.json as a dict. Do not combine initialize(), solve(), or finalize() before or after run().

initialize(inputJson, run_directory) → dict#

Initializes the internal state for iterative analysis and returns design element information when a design domain is present. After initialize() succeeds, call finalize() exactly once, including when an exception occurs.

solve() → dict#

Runs an analysis using the current initialized conditions and returns the results. It can be called repeatedly after update APIs.

finalize() → int#

Ends iterative analysis and releases internal resources. The current return value on normal completion is 0.

design_space = pyemsol.initialize(input_json, str(model_dir))
try:
    # 必要に応じて入力を更新する
    output = pyemsol.solve()
finally:
    pyemsol.finalize()

Updates During Iterative Analysis#

update_Time_Function(inputJson) → bool#

Updates a Time Function based on an existing TIME_ID in 18_Time_Function. Returns False when the corresponding block is absent.

update_properties_in_design_domain(inputJson) → bool#

Updates 16_Material_Properties for materials initialized as a design domain. Pass either the complete input JSON or a dictionary containing 16_1_3D_Element_Properties.

For examples, see Examples and Showcase.

External Mesh Morphing Integration#

The input/output specification and constraints for CoupledSession, static volume meshes, and coordinate payloads used with an external mesh morphing tool are described in External Mesh Morphing Integration. Check the schema version, coordinate system, and supported-model constraints before use.

Compatibility APIs for Existing Scripts#

The following module-level APIs are provided for existing code. Use CoupledSession in new code.

  • prepare_step_calculation(inputJson, run_directory) -> dict

  • step_calculation() -> int

  • step_calculation(time, delta_time, inputs={}, deformation=None) -> dict

  • describe_coupling_ports() -> dict

  • describe_deformation() -> dict

  • describe_deformation_mesh() -> dict

  • close() -> dict

Information#

version() → dict#

Returns version information.