Prism example#
This tutorial demonstrates how to run a prism use case.
[1]:
import os
from pathlib import Path
from ansys.speos.core import Project, Speos
from ansys.speos.core.sensor import SensorIrradiance
from ansys.speos.core.simulation import SimulationDirect
# If using docker container
assets_data_path = Path("/app") / "assets"
# If using local server
# assets_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# assets_data_path = Path("path/to/downloaded/example/assets")
Create connection with speos rpc server#
[2]:
speos = Speos(host="localhost", port=50098)
Create project#
Load a project from .speos file.
[3]:
p = Project(speos=speos, path=str(assets_data_path / "Prism.speos" / "Prism.speos"))
print(p)
{
"name": "Prism",
"description": "From /app/assets/Prism.speos/Prism.speos",
"part_guid": "5ffea1dc-9da7-4d75-8457-4f160ec67bf5",
"sources": [
{
"name": "Surface.1:7758",
"metadata": {
"UniqueId": "f59b3af5-10fa-41fb-a28f-c10c4aaf87ba"
},
"source_guid": "e6dd774d-385b-4986-9122-f54455743bd6",
"description": "",
"source": {
"name": "Surface.1:7758",
"surface": {
"radiant_flux": {
"radiant_value": 8.346636625511586
},
"intensity_guid": "3e48f500-5343-4abc-b55d-1fd17da32bf2",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "SourceBody:1801986974/face.1:544289899",
"reverse_normal": false
}
]
},
"spectrum_guid": "86d3173b-c09a-4d6e-9485-ae27fbd0a4a0",
"intensity": {
"cos": {
"N": 1.0,
"total_angle": 0.1
},
"name": "",
"description": "",
"metadata": {}
},
"spectrum": {
"blackbody": {
"temperature": 5000.0
},
"name": "",
"description": "",
"metadata": {}
}
},
"description": "",
"metadata": {}
}
}
],
"sensors": [
{
"name": "Irradiance.1:564",
"metadata": {
"UniqueId": "0cdaa17f-e5c0-44a4-b9b9-07f7024e1518"
},
"sensor_guid": "87c077c5-6d2a-4d46-ba42-80ba92516d60",
"result_file_name": "Prism.Irradiance.1",
"description": "",
"sensor": {
"irradiance_sensor_template": {
"sensor_type_spectral": {
"wavelengths_range": {
"w_start": 380.0,
"w_end": 780.0,
"w_sampling": 41
}
},
"illuminance_type_planar": {},
"dimensions": {
"x_start": -20.0,
"x_end": 20.0,
"x_sampling": 400,
"y_start": -5.0,
"y_end": 5.0,
"y_sampling": 100
},
"axis_system": [
921.3551052231927,
0.0,
388.72197015239516,
-0.3887219701523952,
-0.0,
0.9213551052231927,
0.0,
1.0000000000000002,
0.0,
-0.9213551052231927,
0.0,
-0.3887219701523952
],
"layer_type_none": {},
"ray_file_type": "RayFileNone",
"integration_direction": []
},
"name": "Irradiance.1:564",
"description": "",
"metadata": {}
}
}
],
"simulations": [
{
"name": "Prism",
"metadata": {
"UniqueId": "08bceefc-4b64-44cd-b14a-891a751549c0"
},
"simulation_guid": "97e10924-22ec-41ef-9d3b-76e5e82437ce",
"sensor_paths": [
"Irradiance.1:564"
],
"source_paths": [
"Surface.1:7758"
],
"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": "Prism",
"metadata": {},
"description": "",
"scene_guid": "11ef1e84-e166-49d6-a077-97dd8feda3d9",
"simulation_path": "Prism",
"job_type": "CPU"
}
}
],
"materials": [
{
"name": "Material.1",
"metadata": {
"UniqueId": "1b19ffe7-facc-4ce9-839f-b45f856b00fc"
},
"sop_guids": [
"5c7dcff2-1c3d-48bf-81b4-7a9865ddb04a"
],
"geometries": {
"geo_paths": [
"SourceBody:1801986974/face.1:544289899",
"SourceBody:1801986974/face.1:2282175023",
"SourceBody:1801986974/face.1:2503270562",
"SourceBody:1801986974/face.1:2272456582",
"SourceBody:1801986974/face.1:1596341914",
"SourceBody:1801986974/face.1:387288686"
]
},
"description": "",
"sops": [
{
"mirror": {
"reflectance": 0.0
},
"name": "",
"description": "",
"metadata": {}
}
]
},
{
"name": "Material.2",
"metadata": {
"UniqueId": "1d94598e-e1a8-496a-b8bc-553126160982"
},
"vop_guid": "a272152c-8b74-471b-868e-34e761737299",
"sop_guids": [
"5ce91e5b-f768-46b9-8850-84af5fe2d751"
],
"geometries": {
"geo_paths": [
"PrismBody:1130610277"
]
},
"description": "",
"vop": {
"optic": {
"index": 1.5,
"absorption": 0.001,
"constringence": 60.0
},
"name": "",
"description": "",
"metadata": {}
},
"sops": [
{
"optical_polished": {},
"name": "",
"description": "",
"metadata": {}
}
]
},
{
"name": "Material.3",
"metadata": {
"UniqueId": "5bf4a1ea-5afe-45af-b1cc-20b96b46a002"
},
"sop_guids": [
"3f8852d9-3312-4ef8-8d69-cfd7e73c8d22"
],
"geometries": {
"geo_paths": [
"PrismBody:1130610277/face.1:242396665"
]
},
"description": "",
"sops": [
{
"library": {
"sop_file_uri": "/app/assets/Prism.speos/transparent_ad06-07cb-a92e-7815..scattering"
},
"name": "",
"description": "",
"metadata": {}
}
]
},
{
"name": "Material.4",
"metadata": {
"UniqueId": "6ed9596c-fcce-4d3b-a072-49428385f8e8"
},
"vop_guid": "b446a9bb-96d7-4d1a-aa86-560a19ecc2dc",
"description": "",
"sop_guids": [],
"vop": {
"optic": {
"index": 1.0,
"absorption": 0.0
},
"name": "",
"description": "",
"metadata": {}
}
}
],
"metadata": {},
"scenes": []
}
Preview.#
[4]:
p.preview()
Retrieve the simulation feature and open result#
Run the simulation
[5]:
sim_features = p.find(name="Prism", feature_type=SimulationDirect)
sim = sim_features[0]
sim.compute_CPU()
[5]:
[upload_response {
info {
uri: "5520d363-2e22-46ad-8b74-afefec731d53"
file_name: "Prism.Irradiance.1.xmp"
file_size: 1568610
}
upload_duration {
nanos: 3841564
}
}
, upload_response {
info {
uri: "9c3b51af-74e1-4665-997f-66d791180618"
file_name: "Prism.html"
file_size: 65356
}
upload_duration {
nanos: 224567
}
}
]
Use the open_result_image method to review the result
[6]:
if os.name == "nt":
from ansys.speos.core.workflow.open_result import open_result_image
open_result_image(simulation_feature=sim, result_name="Prism.Irradiance.1.xmp")
Work with sensor#
Retrieve the sensor feature.
Modify the sensor setting, e.g. set the spectral type, etc.
[7]:
irr_features = p.find(name=".*", name_regex=True, feature_type=SensorIrradiance)
irr = irr_features[0]
irr.set_type_spectral().set_wavelengths_range().set_start(500).set_end(600).set_sampling(11)
irr.commit()
[7]:
<ansys.speos.core.sensor.SensorIrradiance at 0x7fed1fd52410>
Re-run the simulation with new sensor definition#
[8]:
sim.compute_CPU()
if os.name == "nt":
open_result_image(simulation_feature=sim, result_name="Prism.Irradiance.1.xmp")