How to open result (MS Windows OS only)#

This tutorial demonstrates how to open and review results using workflow method.

Prerequisites#

Perform imports#

[1]:
import os
from pathlib import Path

from ansys.speos.core import Project, Speos, launcher
from ansys.speos.core.kernel.client import (
    default_docker_channel,
)
from ansys.speos.core.simulation import SimulationDirect

Define constants#

Constants help ensure consistency and avoid repetition throughout the example.

[2]:
HOSTNAME = "localhost"
GRPC_PORT = 50098  # Be sure the Speos GRPC Server has been started on this port.
FILE_NAME = "LG_50M_Colorimetric_short.sv5"
RESULT_NAME = "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
USE_DOCKER = True  # Set to False if you're running this example locally as a Notebook.
USE_GPU = False

Model Setup#

Load assets#

The assets used to run this example are available in the PySpeos repository on GitHub.

Note: Make sure you have downloaded simulation assets and set assets_data_path to point to the assets folder.

[3]:
if USE_DOCKER:  # Running on the remote server.
    assets_data_path = Path("/app") / "assets"
else:
    assets_data_path = Path("/path/to/your/download/assets/directory")

Connect to the RPC Server#

This Python client connects to a server where the Speos engine is running as a service. In this example, the server and client are the same machine.

[4]:
if USE_DOCKER:
    speos = Speos(channel=default_docker_channel())
else:
    speos = launcher.launch_local_speos_rpc_server(port=GRPC_PORT)
/home/runner/work/pyspeos/pyspeos/.venv/lib/python3.10/site-packages/ansys/tools/common/cyberchannel.py:187: UserWarning: Starting gRPC client without TLS on localhost:50098. This is INSECURE. Consider using a secure connection.
  warn(f"Starting gRPC client without TLS on {target}. This is INSECURE. Consider using a secure connection.")

Create project from a Speos file#

The Project class is instantiated by passing a Speos instance and the name of the Speos project file.

[5]:
p = Project(
    speos=speos,
    path=str(assets_data_path / FILE_NAME / FILE_NAME),
)
print(p)
/home/runner/work/pyspeos/pyspeos/.venv/lib/python3.10/site-packages/ansys/speos/core/project.py:719: UserWarning: The pySpeos feature : FaceStub.read_batch needs a Speos Version of 2025 R2 SP0 or higher.
  f_data_list = face_db.read_batch(refs=f_links)
/home/runner/work/pyspeos/pyspeos/.venv/lib/python3.10/site-packages/ansys/speos/core/project.py:825: UserWarning: The pySpeos feature : SourceSurface needs a Speos Version of 2025 R2 SP0 or higher.
  src_feat = SourceSurface(
/home/runner/work/pyspeos/pyspeos/.venv/lib/python3.10/site-packages/ansys/speos/core/project.py:883: UserWarning: The pySpeos feature : SimulationDirect needs a Speos Version of 2025 R2 SP0 or higher.
  sim_feat = SimulationDirect(
{
    "name": "LG_50M_Colorimetric_short",
    "description": "From /app/assets/LG_50M_Colorimetric_short.sv5/LG_50M_Colorimetric_short.sv5",
    "part_guid": "3b1a84f8-deb3-4217-9349-88a05d99e643",
    "sources": [
        {
            "name": "Dom Source 2 (0) in SOURCE2",
            "metadata": {
                "UniqueId": "be636d4b-17db-4a13-b39c-edb11a739474"
            },
            "source_guid": "641f0c74-eb98-4f9e-85ec-3231264176ef",
            "description": "",
            "source": {
                "name": "Dom Source 2 (0) in SOURCE2",
                "surface": {
                    "radiant_flux": {
                        "radiant_value": 6.590041607465698
                    },
                    "intensity_guid": "245a4622-02ee-41a6-bb69-ba060262ba8f",
                    "exitance_constant": {
                        "geo_paths": [
                            {
                                "geo_path": "Solid Body in SOURCE2:2920204960/Face in SOURCE2:222",
                                "reverse_normal": false
                            }
                        ]
                    },
                    "spectrum_guid": "58c0bde8-25f7-4c39-9403-1a69e2e3ee22",
                    "intensity": {
                        "cos": {
                            "N": 1.0,
                            "total_angle": 180.0
                        },
                        "name": "",
                        "description": "",
                        "metadata": {}
                    },
                    "spectrum": {
                        "library": {
                            "file_uri": "/app/assets/LG_50M_Colorimetric_short.sv5/Red Spectrum.spectrum"
                        },
                        "name": "",
                        "description": "",
                        "metadata": {}
                    }
                },
                "description": "",
                "metadata": {}
            }
        },
        {
            "name": "Surface Source (0) in SOURCE1",
            "metadata": {
                "UniqueId": "258f4e77-3c78-4a85-a721-40909080e628"
            },
            "source_guid": "de0ba282-932d-4a56-9fbc-42ac450aec2d",
            "description": "",
            "source": {
                "name": "Surface Source (0) in SOURCE1",
                "surface": {
                    "radiant_flux": {
                        "radiant_value": 9.290411220389682
                    },
                    "intensity_guid": "7fadcf8a-e81d-4fda-b335-0eb69fefbc7c",
                    "exitance_constant": {
                        "geo_paths": [
                            {
                                "geo_path": "Solid Body in SOURCE1:2494956811/Face in SOURCE1:187",
                                "reverse_normal": false
                            }
                        ]
                    },
                    "spectrum_guid": "2bfeeb83-597b-4f5a-a841-b6e0de68c2e2",
                    "intensity": {
                        "cos": {
                            "N": 1.0,
                            "total_angle": 180.0
                        },
                        "name": "",
                        "description": "",
                        "metadata": {}
                    },
                    "spectrum": {
                        "library": {
                            "file_uri": "/app/assets/LG_50M_Colorimetric_short.sv5/Blue Spectrum.spectrum"
                        },
                        "name": "",
                        "description": "",
                        "metadata": {}
                    }
                },
                "description": "",
                "metadata": {}
            }
        }
    ],
    "sensors": [
        {
            "name": "Dom Irradiance Sensor (0)",
            "metadata": {
                "UniqueId": "107be00e-9bb6-4d5f-84ef-419ab5f5eaec"
            },
            "sensor_guid": "d09d06a1-c926-4bcc-8d48-b4da38b2b51e",
            "result_file_name": "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0)",
            "description": "",
            "sensor": {
                "irradiance_sensor_template": {
                    "sensor_type_colorimetric": {
                        "wavelengths_range": {
                            "w_start": 400.0,
                            "w_end": 700.0,
                            "w_sampling": 25
                        }
                    },
                    "illuminance_type_planar": {},
                    "dimensions": {
                        "x_start": -20.0,
                        "x_end": 20.0,
                        "x_sampling": 500,
                        "y_start": -20.0,
                        "y_end": 20.0,
                        "y_sampling": 500
                    },
                    "axis_system": [
                        -42.0,
                        2.0,
                        5.0,
                        0.0,
                        1.0,
                        0.0,
                        0.0,
                        0.0,
                        -1.0,
                        -1.0,
                        0.0,
                        0.0
                    ],
                    "layer_type_source": {},
                    "integration_direction": [
                        1.0,
                        -0.0,
                        -0.0
                    ],
                    "ray_file_type": "RayFileNone"
                },
                "name": "Dom Irradiance Sensor (0)",
                "description": "",
                "metadata": {}
            }
        }
    ],
    "simulations": [
        {
            "name": "ASSEMBLY1.DS (0)",
            "metadata": {
                "UniqueId": "4b5bf643-b53e-4a87-a665-fd00ea5fc701"
            },
            "simulation_guid": "b88f9826-baa9-4087-ae1a-6c7a93327a01",
            "sensor_paths": [
                "Dom Irradiance Sensor (0)"
            ],
            "source_paths": [
                "Dom Source 2 (0) in SOURCE2",
                "Surface Source (0) in SOURCE1"
            ],
            "description": "",
            "simulation": {
                "direct_mc_simulation_template": {
                    "geom_distance_tolerance": 0.05,
                    "max_impact": 100,
                    "weight": {
                        "minimum_energy_percentage": 0.005
                    },
                    "dispersion": true,
                    "colorimetric_standard": "CIE_1931",
                    "fast_transmission_gathering": false,
                    "ambient_material_uri": ""
                },
                "name": "ASSEMBLY1.DS (0)",
                "metadata": {},
                "description": "",
                "scene_guid": "b6ea0241-ea85-4b2e-99fb-5373e28896d9",
                "simulation_path": "ASSEMBLY1.DS (0)",
                "job_type": "CPU"
            }
        }
    ],
    "materials": [
        {
            "name": "Material.1",
            "metadata": {
                "UniqueId": "0ba776e0-1fea-4845-b1ea-6274b1687749"
            },
            "geometries": {
                "geo_paths": [
                    "Solid Body in GUIDE:1379760262/Face in GUIDE:169"
                ]
            },
            "sop_guid": "4e0b4851-35ca-4efa-bffd-ac69d485c7e3",
            "description": "",
            "sop_guids": [],
            "sop": {
                "mirror": {
                    "reflectance": 100.0
                },
                "name": "",
                "description": "",
                "metadata": {}
            }
        },
        {
            "name": "Material.2",
            "metadata": {
                "UniqueId": "798ac196-ceec-4ce3-8b8d-0d77da27e67d"
            },
            "vop_guid": "1132b514-f955-4aee-bd2c-41a3e54ebc5d",
            "geometries": {
                "geo_paths": [
                    "Solid Body in SOURCE2:2920204960",
                    "Solid Body in SOURCE1:2494956811"
                ]
            },
            "sop_guid": "4e0b4851-35ca-4efa-bffd-ac69d485c7e3",
            "description": "",
            "sop_guids": [],
            "vop": {
                "opaque": {},
                "name": "",
                "description": "",
                "metadata": {}
            },
            "sop": {
                "mirror": {
                    "reflectance": 100.0
                },
                "name": "",
                "description": "",
                "metadata": {}
            }
        },
        {
            "name": "Material.3",
            "metadata": {
                "UniqueId": "79944c29-591d-4ce5-b766-e386f145d401"
            },
            "vop_guid": "314edc3b-ceb6-45b0-8fa1-aa1e0ec37ecb",
            "geometries": {
                "geo_paths": [
                    "Solid Body in GUIDE:1379760262"
                ]
            },
            "sop_guid": "57e2e523-5779-4fb5-827f-702a11e74aa1",
            "description": "",
            "sop_guids": [],
            "vop": {
                "optic": {
                    "index": 1.4,
                    "constringence": 60.0,
                    "absorption": 0.0
                },
                "name": "",
                "description": "",
                "metadata": {}
            },
            "sop": {
                "optical_polished": {},
                "name": "",
                "description": "",
                "metadata": {}
            }
        },
        {
            "name": "Material.4",
            "metadata": {
                "UniqueId": "8b4f11a7-7164-43fb-a3b2-35149ae4e61a"
            },
            "vop_guid": "7e3959f5-a09f-4016-b94e-d4a87ccd707f",
            "description": "",
            "sop_guids": [],
            "vop": {
                "optic": {
                    "index": 1.0,
                    "absorption": 0.0
                },
                "name": "",
                "description": "",
                "metadata": {}
            }
        }
    ],
    "metadata": {},
    "scenes": []
}

Retrieve the simulation feature#

Use the method Project.find() to retrieve an instance of the SimulationDirect feature.

[6]:
sim = p.find(name=".*", name_regex=True, feature_type=SimulationDirect)[0]

Run simulation#

The simulation can be run using either the CPU or with GPU acceleration. The following cell shows how Python is used to assign the appropriate method to run_sim.

[7]:
run_sim = sim.compute_GPU if USE_GPU else sim.compute_CPU
results = run_sim()  # run the simulation
print(results)
[upload_response {
  info {
    uri: "f3ec9d39-2f0b-4f1c-82a9-915ced3aa5e8"
    file_name: "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
    file_size: 2150371
  }
  upload_duration {
    nanos: 3209931
  }
}
, upload_response {
  info {
    uri: "55bdf8af-96bf-410e-b013-19eee175f113"
    file_name: "ASSEMBLY1.DS (0).html"
    file_size: 645002
  }
  upload_duration {
    nanos: 1077425
  }
}
]

Postprocessing#

Open the results (MS Windows OS only):#

Display one result as image.

A full path can be given, or the name of the result.

[8]:
if os.name == "nt":  # Are we running on Windows OS?
    from ansys.speos.core.workflow.open_result import open_result_image

    open_result_image(simulation_feature=sim, result_name=RESULT_NAME)

Display the image#

Display one result in a result viewer.

A full path can be given, or the name of the result.

[9]:
if os.name == "nt":
    from ansys.speos.core.workflow.open_result import open_result_in_viewer

    open_result_in_viewer(
        simulation_feature=sim,
        result_name=RESULT_NAME,
    )
speos.close()
[9]:
True