Update PCB Modeling Properties#

This example demonstrates how to connect to the Sherlock gRPC service, import a project, and configure PCB modeling properties for various analysis types.

Description#

Sherlock allows you to configure PCB modeling properties for multiple analysis types. This script performs the following steps: - Connect to the Sherlock service. - Import a project. - Configure PCB modeling properties for several analysis types.

Connect to Sherlock#

Connect to the Sherlock service and ensure proper initialization.

sherlock = launcher.connect(port=9092, timeout=10, transport_mode="wnua")
Traceback (most recent call last):
  File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\examples\04-analyses\update_pcb_modeling_properties.py", line 72, in <module>
    sherlock = launcher.connect(port=9092, timeout=10, transport_mode="wnua")
  File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\launcher.py", line 324, in connect
    raise e
  File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\launcher.py", line 306, in connect
    _wait_for_sherlock_grpc_ready(channel, timeout)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\launcher.py", line 395, in _wait_for_sherlock_grpc_ready
    raise SherlockConnectionError(message="Error starting gRPC service")
ansys.sherlock.core.errors.SherlockConnectionError: gRPC connection error: Error starting gRPC service

Delete Project#

Delete the project if it already exists.

try:
    sherlock.project.delete_project("Test")
    print("Project deleted successfully.")
except Exception:
    pass

Import Tutorial Project#

Import the tutorial project zip archive from the Sherlock tutorial directory.

try:
    sherlock.project.import_project_zip_archive(
        project="Test",
        category="Demos",
        archive_file=os.path.join(get_sherlock_tutorial_path(), "Auto Relay Project.zip"),
    )
    print("Tutorial project imported successfully.")
except SherlockImportProjectZipArchiveError as e:
    print("Error importing project zip archive.")

Update PCB Modeling Properties#

Configure PCB modeling properties for various analysis types.

try:
    analysis_type = SherlockAnalysisService_pb2.UpdatePcbModelingPropsRequest.Analysis.AnalysisType
    material_model = (
        SherlockAnalysisService_pb2.UpdatePcbModelingPropsRequest.Analysis.PcbMaterialModel
    )
    pcb_model_type = SherlockAnalysisService_pb2.UpdatePcbModelingPropsRequest.Analysis.PcbModelType

    harmonic_vibe = analysis_type.HarmonicVibe
    natural_freq = analysis_type.NaturalFreq
    ict_analysis = analysis_type.ICTAnalysis
    mechanical_shock = analysis_type.MechanicalShock
    random_vibe = analysis_type.RandomVibe
    thermal_mech = analysis_type.ThermalMech
    bonded = pcb_model_type.Bonded
    uniform = material_model.Uniform
    layered = material_model.Layered
    layered_elements = material_model.LayeredElements
    uniform_elements = material_model.UniformElements
    solid_shell = SherlockAnalysisService_pb2.ElementOrder.SolidShell

    sherlock.analysis.update_pcb_modeling_props(
        project="Test",
        cca_names=["Auto Relay"],
        analyses=[(harmonic_vibe, bonded, True, uniform, solid_shell, 6, "mm", 3, "mm", True)],
    )
    sherlock.analysis.update_pcb_modeling_props(
        project="Test",
        cca_names=["Auto Relay"],
        analyses=[(natural_freq, bonded, True, uniform, solid_shell, 6, "mm", 3, "mm", True)],
    )
    sherlock.analysis.update_pcb_modeling_props(
        project="Test",
        cca_names=["Auto Relay"],
        analyses=[(ict_analysis, bonded, True, uniform, solid_shell, 6, "mm", 3, "mm", True)],
    )
    sherlock.analysis.update_pcb_modeling_props(
        project="Test",
        cca_names=["Auto Relay"],
        analyses=[(mechanical_shock, bonded, True, layered, solid_shell, 6, "mm", 3, "mm", True)],
    )
    sherlock.analysis.update_pcb_modeling_props(
        project="Test",
        cca_names=["Auto Relay"],
        analyses=[
            (
                random_vibe,
                bonded,
                True,
                layered_elements,
                5,
                solid_shell,
                6,
                "mm",
                3,
                "mm",
                True,
            )
        ],
    )
    sherlock.analysis.update_pcb_modeling_props(
        project="Test",
        cca_names=["Auto Relay"],
        analyses=[
            (
                thermal_mech,
                bonded,
                True,
                uniform_elements,
                5,
                solid_shell,
                6,
                "mm",
                3,
                "mm",
                True,
            )
        ],
    )
    print("PCB modeling properties updated successfully.")
except SherlockUpdatePcbModelingPropsError as e:
    print("Error updating PCB modeling properties.")

Total running time of the script: (0 minutes 10.018 seconds)