.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\gallery_examples\01-project-configuration\add_modeling_region.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_examples_01-project-configuration_add_modeling_region.py: .. _ref_add_modeling_region: ====================================== Add Modeling Regions for PCB Analysis ====================================== This example demonstrates how to use the Sherlock gRPC service to: - Import a project. - Add modeling regions to a PCB model. - Define different region shapes like polygonal, rectangular, circular, and slot shapes. - Configure PCB and trace model properties for simulation. Description ----------- Connect to the Sherlock gRPC service, import a project, and create modeling regions with different shapes for a PCB analysis. The script shows how to configure the modeling region shapes, PCB modeling properties, and trace modeling properties for each region. .. GENERATED FROM PYTHON SOURCE LINES 40-58 .. code-block:: Python import os from examples.examples_globals import get_sherlock_tutorial_path from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import ( SherlockAddModelingRegionError, SherlockImportProjectZipArchiveError, ) from ansys.sherlock.core.types.layer_types import ( CircularShape, PolygonalShape, RectangularShape, SlotShape, ) .. GENERATED FROM PYTHON SOURCE LINES 60-63 Connect to Sherlock =================== Connect to the Sherlock service and ensure proper initialization. .. GENERATED FROM PYTHON SOURCE LINES 63-66 .. code-block:: Python sherlock = launcher.connect(port=9092, timeout=10) .. GENERATED FROM PYTHON SOURCE LINES 67-70 Delete Project ============== Delete the project if it already exists. .. GENERATED FROM PYTHON SOURCE LINES 70-77 .. code-block:: Python try: sherlock.project.delete_project("Test") print("Project deleted successfully.") except Exception: pass .. GENERATED FROM PYTHON SOURCE LINES 78-81 Import Tutorial Project ======================= Import the tutorial project zip archive from the Sherlock tutorial directory. .. GENERATED FROM PYTHON SOURCE LINES 81-92 .. code-block:: Python 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(f"Error importing project zip archive: {e}") .. GENERATED FROM PYTHON SOURCE LINES 93-96 Create Modeling Regions ======================= Define different shapes (polygonal, rectangular, circular, and slot) for modeling regions. .. GENERATED FROM PYTHON SOURCE LINES 96-211 .. code-block:: Python try: # Define coordinates and dimensions U9_x = 0.0 # X-Coordinate in mm. U9_y = 19.05 # Y-Coordinate in mm. U9_package_length = 27.0 # Package Length in mm. U9_package_width = 27.0 # Package Width in mm. tolerance = 2.0 # Dimension Tolerance in mm. x_min = U9_x - (U9_package_width / 2) - tolerance x_max = U9_x + (U9_package_width / 2) + tolerance y_min = U9_y - (U9_package_length / 2) - tolerance y_max = U9_y + (U9_package_length / 2) + tolerance # Define the region shapes polygonal_shape = PolygonalShape(points=[(0, 0), (0, 6.35), (9.77, 0)], rotation=87.8) rectangular_shape = RectangularShape( length=U9_package_length, width=U9_package_width, center_x=U9_x, center_y=U9_y, rotation=0.0 ) slot_shape = SlotShape( length=5.0, width=5.0, node_count=6, center_x=U9_x, center_y=U9_y, rotation=0.0 ) circular_shape = CircularShape( diameter=5.0, node_count=4, center_x=0.0, center_y=0.0, rotation=30.0 ) # Create the modeling regions modeling_regions = [ { "cca_name": "Auto Relay", "region_id": "Region001", "region_units": "mm", "model_mode": "Enabled", "shape": polygonal_shape, "pcb_model_props": { "export_model_type": "Sherlock", "elem_order": "First_Order", "max_mesh_size": 0.5, "max_mesh_size_units": "mm", "quads_preferred": True, }, "trace_model_props": { "trace_model_type": "Enabled", "elem_order": "Second_Order", "trace_mesh_size": 0.3, "trace_mesh_size_units": "mm", }, }, { "cca_name": "Auto Relay", "region_id": "Region002", "region_units": "mm", "model_mode": "Enabled", "shape": rectangular_shape, "pcb_model_props": { "export_model_type": "Sherlock", "elem_order": "First_Order", "max_mesh_size": 0.5, "max_mesh_size_units": "mm", "quads_preferred": True, }, "trace_model_props": { "trace_model_type": "Enabled", "elem_order": "Second_Order", "trace_mesh_size": 0.3, "trace_mesh_size_units": "mm", }, }, { "cca_name": "Auto Relay", "region_id": "Region003", "region_units": "mm", "model_mode": "Enabled", "shape": circular_shape, "pcb_model_props": { "export_model_type": "Sherlock", "elem_order": "First_Order", "max_mesh_size": 0.5, "max_mesh_size_units": "mm", "quads_preferred": True, }, "trace_model_props": { "trace_model_type": "Enabled", "elem_order": "Second_Order", "trace_mesh_size": 0.3, "trace_mesh_size_units": "mm", }, }, { "cca_name": "Auto Relay", "region_id": "Region004", "region_units": "mm", "model_mode": "Enabled", "shape": slot_shape, "pcb_model_props": { "export_model_type": "Sherlock", "elem_order": "First_Order", "max_mesh_size": 0.5, "max_mesh_size_units": "mm", "quads_preferred": True, }, "trace_model_props": { "trace_model_type": "Enabled", "elem_order": "Second_Order", "trace_mesh_size": 0.3, "trace_mesh_size_units": "mm", }, }, ] # Add modeling regions to the project sherlock.layer.add_modeling_region("Test", modeling_regions) print("Modeling regions added successfully.") except SherlockAddModelingRegionError as e: print(f"Error adding modeling regions: {e}") .. _sphx_glr_download_examples_gallery_examples_01-project-configuration_add_modeling_region.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: add_modeling_region.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: add_modeling_region.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: add_modeling_region.zip `