Skip to content

Commit 0c1cfcc

Browse files
pluAtAnsysplupyansys-ci-botpre-commit-ci[bot]echambla
authored
feat: add supporting virtual bsdf bench (#763)
## Description Develop pyspeos to connect to the recently developed VBB in Speos RPC. ## Issue linked VBB high demand #706 ## Checklist - [x] I have tested my changes locally. - [x] I have added necessary documentation or updated existing documentation. - [x] I have followed the coding style guidelines of this project. - [x] I have added appropriate tests (unit, integration, system). - [x] I have reviewed my changes before submitting this pull request. - [x] I have linked the issue or issues that are solved by the PR if any. - [x] I have assigned this PR to myself. - [x] I have made sure that the title of my PR follows [Conventional commits style](https://www.conventionalcommits.org/en/v1.0.0/#summary) (e.g. ``feat: add optical property``) - [x] I have agreed with the Contributor License Agreement ([CLA](https://developer.ansys.com/form/cla-acceptance)). --------- Co-authored-by: plu <plu@ansys.com> Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Elodie Chamblas <100407563+echambla@users.noreply.github.com> Co-authored-by: Stefan Thöne <86405327+StefanThoene@users.noreply.github.com>
1 parent 07f1a7c commit 0c1cfcc

File tree

7 files changed

+1774
-161
lines changed

7 files changed

+1774
-161
lines changed

doc/changelog.d/763.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add supporting virtual bsdf bench

doc/source/conf.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,36 @@ def copy_assets_to_output_dir(app: sphinx.application.Sphinx, exception: Excepti
295295
exception : Exception
296296
Exception encountered during the building of the documentation.
297297
"""
298-
if app.builder.name == "html":
299-
SOURCE_ASSETS = pathlib.Path(app.outdir) / "_static" / "assets" / "download"
300-
ASSETS_DIRECTORY = pathlib.Path(app.outdir).parent.parent.parent / "tests" / "assets"
301-
302-
logger.info("Extracting assets to output directory...")
303-
zip_path = pathlib.Path(shutil.make_archive("assets", "zip", ASSETS_DIRECTORY))
304-
zip_path = shutil.move(zip_path, SOURCE_ASSETS / zip_path.name)
305-
logger.info(f"Extracted assets to {zip_path}.")
306-
else:
307-
logger.info(f"Skip assets extraction with build {app.builder.name}.")
298+
if app.builder.name != "html":
299+
logger.info(
300+
"Skip assets extraction with build %s.",
301+
app.builder.name,
302+
)
303+
return
304+
305+
source_assets = pathlib.Path(app.outdir).parent.parent.parent / "tests" / "assets"
306+
307+
output_dir = pathlib.Path(app.outdir) / "_static" / "assets" / "download"
308+
309+
if not source_assets.exists():
310+
logger.warning(
311+
"Assets directory not found at %s; skipping asset packaging.",
312+
source_assets,
313+
)
314+
return
315+
316+
output_dir.mkdir(parents=True, exist_ok=True)
317+
318+
logger.info("Packaging assets for documentation output...")
319+
320+
archive_base = output_dir / "assets"
321+
zip_path = shutil.make_archive(
322+
base_name=str(archive_base),
323+
format="zip",
324+
root_dir=str(source_assets),
325+
)
326+
327+
logger.info("Assets packaged at %s.", zip_path)
308328

309329

310330
def remove_examples_from_source_dir(app: sphinx.application.Sphinx, exception: Exception):

examples/core/simulation.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
from ansys.speos.core.kernel.client import (
1818
default_docker_channel,
1919
)
20-
from ansys.speos.core.simulation import SimulationInteractive, SimulationInverse
20+
from ansys.speos.core.simulation import (
21+
SimulationInteractive,
22+
SimulationInverse,
23+
SimulationVirtualBSDF,
24+
)
2125

2226
# -
2327

@@ -132,9 +136,9 @@
132136
simulation2_direct = p.create_simulation(name="Simulation.2")
133137
simulation2_direct.set_ambient_material_file_uri(
134138
uri=str(assets_data_path / "AIR.material")
135-
).set_colorimetric_standard_CIE_1964().set_weight_none().set_geom_distance_tolerance(
136-
0.01
137-
).set_max_impact(200).set_dispersion(False)
139+
).set_colorimetric_standard_CIE_1964().set_weight_none().set_dispersion(False)
140+
simulation2_direct.geom_distance_tolerance = 0.01
141+
simulation2_direct.max_impact = 200
138142
simulation2_direct.set_sensor_paths([SENSOR_NAME]).set_source_paths([SOURCE_NAME]).commit()
139143
print(simulation2_direct)
140144

@@ -164,7 +168,7 @@
164168
#
165169
# Possibility to reset local values from the one available in the server.
166170

167-
simulation1.set_max_impact(1000) # adjust max impact but no commit
171+
simulation1.max_impact = 1000 # adjust max impact but no commit
168172
simulation1.reset() # reset -> this will apply the server value to the local value
169173
simulation1.delete() # delete (to display the local value with the below print)
170174
print(simulation1)
@@ -186,4 +190,27 @@
186190
simulation4.set_source_paths(source_paths=[SOURCE_NAME]).commit()
187191
print(simulation4)
188192

193+
# ### Virtual BSDF Bench simulation
194+
195+
# Change the material property from mirror to bsdf type
196+
opt_prop.set_surface_library(path=str(assets_data_path / "R_test.anisotropicbsdf")).commit()
197+
vbb = p.create_simulation(name="virtual_BSDF", feature_type=SimulationVirtualBSDF)
198+
vbb.axis_system = [
199+
0.36,
200+
1.73,
201+
2.0,
202+
1.0,
203+
0.0,
204+
0.0,
205+
0.0,
206+
1.0,
207+
0.0,
208+
0.0,
209+
0.0,
210+
1.0,
211+
] # change the coordinate VBSDF to body center
212+
vbb.commit()
213+
results = vbb.compute_CPU()
214+
print(results)
215+
189216
speos.close()

src/ansys/speos/core/project.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
SimulationDirect,
5353
SimulationInteractive,
5454
SimulationInverse,
55+
SimulationVirtualBSDF,
5556
)
5657
from ansys.speos.core.source import (
5758
SourceAmbientNaturalLight,
@@ -225,7 +226,8 @@ def create_source(
225226
)
226227
case _:
227228
msg = "Requested feature {} does not exist in supported list {}".format(
228-
feature_type, [SourceSurface, SourceLuminaire, SourceRayFile]
229+
feature_type,
230+
[SourceSurface, SourceLuminaire, SourceRayFile, SourceAmbientNaturalLight],
229231
)
230232
raise TypeError(msg)
231233
self._features.append(feature)
@@ -237,7 +239,7 @@ def create_simulation(
237239
description: str = "",
238240
feature_type: type = SimulationDirect,
239241
metadata: Optional[Mapping[str, str]] = None,
240-
) -> Union[SimulationDirect, SimulationInteractive, SimulationInverse]:
242+
) -> Union[SimulationDirect, SimulationInteractive, SimulationInverse, SimulationVirtualBSDF]:
241243
"""Create a new Simulation feature.
242244
243245
Parameters
@@ -261,7 +263,8 @@ def create_simulation(
261263
-------
262264
Union[ansys.speos.core.simulation.SimulationDirect,\
263265
ansys.speos.core.simulation.SimulationInteractive,\
264-
ansys.speos.core.simulation.SimulationInverse]
266+
ansys.speos.core.simulation.SimulationInverse, \
267+
ansys.speos.core.simulation.SimulationVirtualBSDF]
265268
Simulation class instance
266269
"""
267270
if metadata is None:
@@ -296,13 +299,21 @@ def create_simulation(
296299
description=description,
297300
metadata=metadata,
298301
)
302+
case "SimulationVirtualBSDF":
303+
feature = SimulationVirtualBSDF(
304+
project=self,
305+
name=name,
306+
description=description,
307+
metadata=metadata,
308+
)
299309
case _:
300310
msg = "Requested feature {} does not exist in supported list {}".format(
301311
feature_type,
302312
[
303313
SimulationDirect,
304314
SimulationInverse,
305315
SimulationInteractive,
316+
SimulationVirtualBSDF,
306317
],
307318
)
308319
raise TypeError(msg)
@@ -437,12 +448,15 @@ def find(
437448
SourceSurface,
438449
SourceLuminaire,
439450
SourceRayFile,
451+
SourceAmbientNaturalLight,
440452
SensorIrradiance,
441453
SensorRadiance,
442454
SensorCamera,
455+
Sensor3DIrradiance,
443456
SimulationDirect,
444457
SimulationInverse,
445458
SimulationInteractive,
459+
SimulationVirtualBSDF,
446460
part.Part,
447461
body.Body,
448462
face.Face,
@@ -466,12 +480,15 @@ def find(
466480
467481
Returns
468482
-------
469-
List[Union[ansys.speos.core.opt_prop.OptProp, ansys.speos.core.source.Surface, \
470-
ansys.speos.core.source.RayFile, ansys.speos.core.source.Luminaire, \
471-
ansys.speos.core.sensor.Camera, \
472-
ansys.speos.core.sensor.Radiance, ansys.speos.core.sensor.Irradiance, \
473-
ansys.speos.core.simulation.Direct, ansys.speos.core.simulation.Interactive, \
474-
ansys.speos.core.simulation.Inverse, ansys.speos.core.part.Part, \
483+
List[Union[ansys.speos.core.opt_prop.OptProp, ansys.speos.core.source.SourceSurface, \
484+
ansys.speos.core.source.SourceRayFile, ansys.speos.core.source.SourceLuminaire, \
485+
ansys.speos.core.source.SourceAmbientNaturalLight, ansys.speos.core.sensor.SensorCamera, \
486+
ansys.speos.core.sensor.SensorRadiance, ansys.speos.core.sensor.SensorIrradiance, \
487+
ansys.speos.core.sensor.Sensor3DIrradiance, \
488+
ansys.speos.core.simulation.SimulationVirtualBSDF, \
489+
ansys.speos.core.simulation.SimulationDirect, \
490+
ansys.speos.core.simulation.SimulationInteractive, \
491+
ansys.speos.core.simulation.SimulationInverse, ansys.speos.core.part.Part, \
475492
ansys.speos.core.body.Body, \
476493
ansys.speos.core.face.Face, ansys.speos.core.part.Part.SubPart]]
477494
Found features.
@@ -635,6 +652,11 @@ def _to_dict(self) -> dict:
635652
name=inside_dict["name"],
636653
feature_type=SimulationInteractive,
637654
)
655+
if len(sim_feat) == 0:
656+
sim_feat = self.find(
657+
name=inside_dict["name"],
658+
feature_type=SimulationVirtualBSDF,
659+
)
638660
sim_feat = sim_feat[0]
639661
if sim_feat.job_link is None:
640662
inside_dict["simulation_properties"] = (
@@ -878,6 +900,13 @@ def _fill_features(self):
878900
simulation_instance=sim_inst,
879901
default_values=False,
880902
)
903+
elif simulation_template_link.HasField("virtual_bsdf_bench_simulation_template"):
904+
sim_feat = SimulationVirtualBSDF(
905+
project=self,
906+
name=sim_inst.name,
907+
simulation_instance=sim_inst,
908+
default_values=False,
909+
)
881910
if sim_feat is not None:
882911
self._features.append(sim_feat)
883912

0 commit comments

Comments
 (0)