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": "5df123f0-33b6-411d-b13d-861ec33b5770",
"sources": [
{
"name": "Dom Source 2 (0) in SOURCE2",
"metadata": {
"UniqueId": "7f8565e9-6338-4924-81c3-bca8956146fb"
},
"source_guid": "88142aab-dc4b-463c-9a94-05882f4a9d03",
"description": "",
"source": {
"name": "Dom Source 2 (0) in SOURCE2",
"surface": {
"radiant_flux": {
"radiant_value": 6.590041607465698
},
"intensity_guid": "4c72c1aa-48e2-421a-9484-3e41d253bd3c",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "Solid Body in SOURCE2:2920204960/Face in SOURCE2:222",
"reverse_normal": false
}
]
},
"spectrum_guid": "7aff7972-718f-4a0b-90f8-401a4b6d0b62",
"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": "4e945bc4-521b-4464-a75b-9100578bd17f"
},
"source_guid": "537d5984-f983-4c9a-9324-5e75e49ba785",
"description": "",
"source": {
"name": "Surface Source (0) in SOURCE1",
"surface": {
"radiant_flux": {
"radiant_value": 9.290411220389682
},
"intensity_guid": "d2b54d79-244b-423a-9e78-2633e10fb418",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "Solid Body in SOURCE1:2494956811/Face in SOURCE1:187",
"reverse_normal": false
}
]
},
"spectrum_guid": "af416086-c1b8-4df9-86de-8f5dbc505a0a",
"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": "6b98b1ce-3029-4517-9a53-445911a1a2f6"
},
"sensor_guid": "b840a1f5-41ac-4b4a-869c-027406faaa58",
"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": "95f96277-0838-4255-8418-3090592864f3"
},
"simulation_guid": "d2db9673-27f0-4e1b-9359-fec859b5c6d5",
"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": "31af90df-c4c7-42f9-a0c0-a54937e22a1e",
"simulation_path": "ASSEMBLY1.DS (0)",
"job_type": "CPU"
}
}
],
"materials": [
{
"name": "Material.1",
"metadata": {
"UniqueId": "f9b09e5f-2a62-40a5-86dc-2b70a06fa89e"
},
"sop_guids": [
"c5816ef8-b673-4bf5-a9b4-ef8619ef9bbd"
],
"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": "9901b012-45e1-4b33-b669-620fc630fa4c"
},
"vop_guid": "7e81075b-b79f-4f72-8a5d-58d7ee7bba4a",
"sop_guids": [
"dfe0d466-fa33-4d49-8823-909aac5797bf"
],
"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": "ba473d9a-562b-48a4-9ae9-253fddaa7f1f"
},
"vop_guid": "92f308e0-9066-46b1-88ba-22e2526dc6f7",
"sop_guids": [
"c5816ef8-b673-4bf5-a9b4-ef8619ef9bbd"
],
"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": "b4d99365-8a50-4eaa-bdfc-0007efcb03ab"
},
"vop_guid": "2f61d39d-0e39-4bff-8921-d9364d78e1bf",
"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: "f075cee1-5fc0-44ce-b4d9-86e76ce3f99d"
file_name: "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
file_size: 2156925
}
upload_duration {
nanos: 2816131
}
}
, upload_response {
info {
uri: "02491ec1-359e-41de-98fe-4421b826ce30"
file_name: "ASSEMBLY1.DS (0).html"
file_size: 645246
}
upload_duration {
nanos: 948581
}
}
]
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,
)