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
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]:
speos = Speos(host=HOSTNAME, port=GRPC_PORT)
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)
{
"name": "LG_50M_Colorimetric_short",
"description": "From /app/assets/LG_50M_Colorimetric_short.sv5/LG_50M_Colorimetric_short.sv5",
"part_guid": "302bb80d-729e-46d6-b99e-4a6100c0ab90",
"sources": [
{
"name": "Dom Source 2 (0) in SOURCE2",
"metadata": {
"UniqueId": "d021e828-b7f0-4d30-b208-5e03bfae107c"
},
"source_guid": "a0705943-ca8b-44e7-8c62-dc857edff301",
"description": "",
"source": {
"name": "Dom Source 2 (0) in SOURCE2",
"surface": {
"radiant_flux": {
"radiant_value": 6.590041607465698
},
"intensity_guid": "4bf66417-aefb-4609-8992-0ef15bdd0c91",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "Solid Body in SOURCE2:2920204960/Face in SOURCE2:222",
"reverse_normal": false
}
]
},
"spectrum_guid": "a68a2941-d32d-40e3-88e7-7f224082385b",
"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": "d2490a2b-78ad-45ef-a69d-22b46ef8e59b"
},
"source_guid": "f1f25f38-b632-4462-9b2f-c17317a92bc1",
"description": "",
"source": {
"name": "Surface Source (0) in SOURCE1",
"surface": {
"radiant_flux": {
"radiant_value": 9.290411220389682
},
"intensity_guid": "f985f0b5-42e5-40f7-8665-1191a464e054",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "Solid Body in SOURCE1:2494956811/Face in SOURCE1:187",
"reverse_normal": false
}
]
},
"spectrum_guid": "596ea006-aeff-4263-95e8-e1aa611d2eb7",
"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": "3a8110fd-61e9-4414-be8b-fbba5d57388b"
},
"sensor_guid": "b47d0822-fe17-4473-abef-937d5222a220",
"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": "10f2c1b0-f544-498f-9bf8-f90e0788bdc4"
},
"simulation_guid": "b6774872-8c0f-469a-a8a6-439df0076308",
"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": "750b83fb-53c9-4e5a-8ad4-1ffa902ae363",
"simulation_path": "ASSEMBLY1.DS (0)",
"job_type": "CPU"
}
}
],
"materials": [
{
"name": "Material.1",
"metadata": {
"UniqueId": "5cc70fc1-58ec-44f9-8ee8-281755a7c418"
},
"sop_guids": [
"a67edf50-9d86-4478-9904-017686c2ce88"
],
"geometries": {
"geo_paths": [
"Solid Body in GUIDE:1379760262/Face in GUIDE:169"
]
},
"description": "",
"sops": [
{
"mirror": {
"reflectance": 100.0
},
"name": "",
"description": "",
"metadata": {}
}
]
},
{
"name": "Material.2",
"metadata": {
"UniqueId": "62236a24-9249-4a11-a83d-f788fba8b72d"
},
"vop_guid": "bc50b591-716c-4f6d-b95c-372762f6c5b4",
"sop_guids": [
"b53bb408-2263-49ef-b278-86f32d7c8f15"
],
"geometries": {
"geo_paths": [
"Solid Body in GUIDE:1379760262"
]
},
"description": "",
"vop": {
"optic": {
"index": 1.4,
"constringence": 60.0,
"absorption": 0.0
},
"name": "",
"description": "",
"metadata": {}
},
"sops": [
{
"optical_polished": {},
"name": "",
"description": "",
"metadata": {}
}
]
},
{
"name": "Material.3",
"metadata": {
"UniqueId": "6ed97630-224d-4a03-b67a-87aee539858f"
},
"vop_guid": "cb0deac3-e5f3-417c-995d-a418c6cbda65",
"sop_guids": [
"a67edf50-9d86-4478-9904-017686c2ce88"
],
"geometries": {
"geo_paths": [
"Solid Body in SOURCE2:2920204960",
"Solid Body in SOURCE1:2494956811"
]
},
"description": "",
"vop": {
"opaque": {},
"name": "",
"description": "",
"metadata": {}
},
"sops": [
{
"mirror": {
"reflectance": 100.0
},
"name": "",
"description": "",
"metadata": {}
}
]
},
{
"name": "Material.4",
"metadata": {
"UniqueId": "dbfe2bc7-31a8-43ca-8e00-a1f296bcd0ea"
},
"vop_guid": "84001481-eeb8-40ed-b603-6fbb89fae1d5",
"description": "",
"sop_guids": [],
"vop": {
"optic": {
"index": 1.0,
"absorption": 0.0
},
"name": "",
"description": "",
"metadata": {}
}
}
],
"metadata": {},
"scenes": []
}
/home/runner/work/pyspeos/pyspeos/.venv/lib/python3.10/site-packages/ansys/speos/core/project.py:698: 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:804: 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:861: UserWarning: The pySpeos feature : SimulationDirect needs a Speos Version of 2025 R2 SP0 or higher.
sim_feat = SimulationDirect(
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: "e2a81933-a1c3-4f3c-ab6d-c423ebc8395b"
file_name: "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
file_size: 2161828
}
upload_duration {
nanos: 2888268
}
}
, upload_response {
info {
uri: "dfd4d77b-83a8-45b8-a7ba-e504411a56b6"
file_name: "ASSEMBLY1.DS (0).html"
file_size: 647306
}
upload_duration {
nanos: 1170588
}
}
]
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