From 818b1a86645357c810c131872fc58958f9d1c658 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 20 Jun 2024 11:02:45 -0500 Subject: [PATCH 01/25] add geometry workflow and requirements --- geometry-mechanical-dpf/01_geometry.py | 196 ++++++++++++++++++ geometry-mechanical-dpf/requirements_24.1.txt | 5 + geometry-mechanical-dpf/requirements_24.2.txt | 5 + 3 files changed, 206 insertions(+) create mode 100644 geometry-mechanical-dpf/01_geometry.py create mode 100644 geometry-mechanical-dpf/requirements_24.1.txt create mode 100644 geometry-mechanical-dpf/requirements_24.2.txt diff --git a/geometry-mechanical-dpf/01_geometry.py b/geometry-mechanical-dpf/01_geometry.py new file mode 100644 index 00000000..36e89f1a --- /dev/null +++ b/geometry-mechanical-dpf/01_geometry.py @@ -0,0 +1,196 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os +from pathlib import Path + +from ansys.geometry.core import launch_modeler +from ansys.geometry.core.connection import GEOMETRY_SERVICE_DOCKER_IMAGE, GeometryContainers +from ansys.geometry.core.designer import DesignFileFormat +from ansys.geometry.core.math import Plane, Point2D, Point3D, UnitVector3D +from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS +from ansys.geometry.core.sketch import Sketch + +# Check env vars to see which image to launch +# +# --- ONLY FOR WORKFLOW RUNS --- +image = None +if "ANSYS_GEOMETRY_RELEASE" in os.environ: + image_tag = os.environ["ANSYS_GEOMETRY_RELEASE"] + for geom_services in GeometryContainers: + if image_tag == f"{GEOMETRY_SERVICE_DOCKER_IMAGE}:{geom_services.value[2]}": + print(f"Using {image_tag} image") + image = geom_services + break + +# -- Parameters -- +# +GRAPHICS_BOOL = False # Set to True to display the mesh +OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory + +# -- Start a modeler session -- +# +modeler = launch_modeler(image=image) +print(modeler) + +# -- Create and plot a sketch -- +# +# Define default length units +DEFAULT_UNITS.LENGTH = UNITS.cm + +# Define the radius of holes in pcb +pcb_hole_radius = 1 + + +# Create PCB Substrate +sketch_substrate = Sketch() +sketch_substrate.segment(Point2D([5, 0]), Point2D([122, 0])).arc_to_point( + Point2D([127, 5]), Point2D([122, 5]) +).segment_to_point(Point2D([127, 135])).arc_to_point( + Point2D([122, 140]), Point2D([122, 135]) +).segment_to_point( + Point2D([5, 140]) +).arc_to_point( + Point2D([0, 135]), Point2D([5, 135]) +).segment_to_point( + Point2D([0, 5]) +).arc_to_point( + Point2D([5, 0]), Point2D([5, 5]) +).circle( + Point2D([6.35, 6.35]), radius=3.94 / 2 +).circle( + Point2D([127 - 6.35, 6.35]), radius=3.94 / 2 +).circle( + Point2D([127 - 6.35, 140 - 6.35]), radius=3.94 / 2 +).circle( + Point2D([6.35, 140 - 6.35]), radius=3.94 / 2 +) +substrate_height = 1.575 +plane = Plane( + origin=Point3D([0, 0, substrate_height]), + direction_x=[1, 0, 0], + direction_y=[0, 1, 0], +) + +# creat IC +sketch_IC = Sketch(plane) +sketch_IC.box(Point2D([62 / 2 + 7.5, 51 / 2 + 5]), 15, 10) + +# create capacitor sketch +sketch_capacitor = Sketch(plane=plane) +sketch_capacitor.circle(center=Point2D([95, 104]), radius=4.4) + +# create ic +sketch_ic_7 = Sketch(plane=plane) +sketch_ic_7.box(Point2D([25, 108]), 18, 24) + +# create ic +sketch_ic_8 = Sketch(plane=plane) +sketch_ic_8.box(Point2D([21, 59]), 10, 18) + + +sketch = Sketch() +( + sketch.segment(start=Point2D([-4, 5]), end=Point2D([4, 5])) + .segment_to_point(end=Point2D([4, -5])) + .segment_to_point(end=Point2D([-4, -5])) + .segment_to_point(end=Point2D([-4, 5])) + .box( + center=Point2D([0, 0]), + width=Distance(3), + height=Distance(3), + ) + .circle(center=Point2D([3, 4]), radius=outer_hole_radius) + .circle(center=Point2D([-3, -4]), radius=outer_hole_radius) + .circle(center=Point2D([-3, 4]), radius=outer_hole_radius) + .circle(center=Point2D([3, -4]), radius=outer_hole_radius) +) + +# -- Perform some modeling operations -- +# +# Now that the sketch is ready to be extruded, perform some modeling operations, +# including creating the design, creating the body directly on the design, and +# plotting the body. + +# Start by creating the Design +design = modeler.create_design("pcb_design") + +# Create a all necessary components for pcb +component = design.add_component("PCB") +component.extrude_sketch("substrate", sketch_substrate, distance=substrate_height) +ic_1 = component.extrude_sketch("ic-1", sketch_IC, distance=4.5) + +ic_2 = ic_1.copy(parent=component, name="ic-2") +ic_2.translate(direction=UnitVector3D([1, 0, 0]), distance=17) + +ic_3 = ic_1.copy(parent=component, name="ic-3") +ic_3.translate(direction=UnitVector3D([0, 1, 0]), distance=17) + +ic_4 = ic_2.copy(parent=component, name="ic-4") +ic_4.translate(direction=UnitVector3D([1, 0, 0]), distance=17) + +ic_5 = ic_2.copy(parent=component, name="ic-5") +ic_5.translate(direction=UnitVector3D([0, 1, 0]), distance=17) + +ic_6 = ic_5.copy(parent=component, name="ic-6") +ic_6.translate(direction=UnitVector3D([1, 0, 0]), distance=17) + +ic_7 = component.extrude_sketch("ic-7", sketch=sketch_ic_7, distance=2) +ic_8 = component.extrude_sketch("ic-8", sketch=sketch_ic_8, distance=2) + + +capacitor_1 = component.extrude_sketch("capacitor_1", sketch_capacitor, distance=20) +capacitor_2 = capacitor_1.copy(parent=component, name="capacitor_2") +capacitor_2.translate(direction=UnitVector3D([0, 1, 0]), distance=-20) +capacitor_3 = capacitor_1.copy(parent=component, name="capacitor_3") +capacitor_3.translate(direction=UnitVector3D([0, 1, 0]), distance=-40) +capacitor_4 = capacitor_1.copy(parent=component, name="capacitor_4") +capacitor_4.translate(direction=UnitVector3D([0, 1, 0]), distance=-60) + +# Create named selections +for body in component.bodies: + design.create_named_selection(name=body.name, bodies=[body]) + +# Plot the the entire geometry +if GRAPHICS_BOOL: + component.plot() + +# -- Export file -- +# +# Once modeling operations are finalized, you can export files +# in different formats. For the formats supported by DMS, see the +# ``DesignFileFormat`` class in the ``Design`` module documentation. +# +# Export files in PMDB format for Mechanical. + +# Download the design in FMD format +OUTPUT_DIR.mkdir(exist_ok=True) +download_file = Path(OUTPUT_DIR, "pcb.pmdb") +design.download(file_location=download_file, format=DesignFileFormat.PMDB) + +# -- Close session -- +# +# When you finish interacting with your modeling service, you should close the active +# server session. This frees resources wherever the service is running. +# +# Close the server session. +modeler.close() diff --git a/geometry-mechanical-dpf/requirements_24.1.txt b/geometry-mechanical-dpf/requirements_24.1.txt new file mode 100644 index 00000000..8f224e92 --- /dev/null +++ b/geometry-mechanical-dpf/requirements_24.1.txt @@ -0,0 +1,5 @@ +ansys-geometry-core[all]==0.6.0 +ansys-mechanical-core==0.11.0 +ansys-mechanical-core[viz]==0.11.0 +ansys-dpf-core==0.12.2 +ansys-dpf-core[plotting]==0.12.2 diff --git a/geometry-mechanical-dpf/requirements_24.2.txt b/geometry-mechanical-dpf/requirements_24.2.txt new file mode 100644 index 00000000..1466024e --- /dev/null +++ b/geometry-mechanical-dpf/requirements_24.2.txt @@ -0,0 +1,5 @@ +ansys-geometry-core[all]==0.6.0 +ansys-mechanical-core==0.11.0 +ansys-mechanical-core[viz]==0.11.0 +ansys-dpf-core==0.12.2 +ansys-dpf-core[plotting]==0.12.2 \ No newline at end of file From c9e1285051e306a29a68053f4ea2c291b507fd1a Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 20 Jun 2024 11:22:25 -0500 Subject: [PATCH 02/25] add pymechanical workflow --- geometry-mechanical-dpf/02_mechanical.py | 194 +++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 geometry-mechanical-dpf/02_mechanical.py diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py new file mode 100644 index 00000000..3da55054 --- /dev/null +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -0,0 +1,194 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os +from pathlib import Path + +import ansys.mechanical.core as mech +from matplotlib import image as mpimg +from matplotlib import pyplot as plt + +# -- Start PyMechanical app -- +# +app = mech.App(version=242) +app.update_globals(globals()) +print(app) + +# -- Parameters -- +# +GRAPHICS_BOOL = False # Set to True to display the mesh +OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory + + +def display_image(image_name): + plt.figure(figsize=(16, 9)) + plt.imshow(mpimg.imread(os.path.join(OUTPUT_DIR, image_name))) + plt.xticks([]) + plt.yticks([]) + plt.axis("off") + plt.show() + + +# -- Configure graphics for image export -- +# +ExtAPI.Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso) +ExtAPI.Graphics.Camera.SetFit() +image_export_format = GraphicsImageExportFormat.PNG +settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() +settings_720p.Resolution = GraphicsResolutionType.EnhancedResolution +settings_720p.Background = GraphicsBackgroundType.White +settings_720p.Width = 1280 +settings_720p.Height = 720 +settings_720p.CurrentGraphicsDisplay = False + +# -- Import geometry -- +# +# Reads geometry file and displa +geometry_path = modeling_file = Path(OUTPUT_DIR, "pcb.mechdb") +geometry_import_group = Model.GeometryImportGroup +geometry_import = geometry_import_group.AddGeometryImport() +geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic +geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences() +geometry_import_preferences.ProcessNamedSelections = True +geometry_import.Import(geometry_path, geometry_import_format, geometry_import_preferences) + +# Plot the the entire geometry +if GRAPHICS_BOOL: + app.plot() + +# -- Setup steady steate and transient analysis -- +# +steady = Model.AddSteadyStateThermalAnalysis() +transient = Model.AddTransientThermalAnalysis() + +ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS + +# Create named selection for all bodies +bodies = Model.Geometry.GetChildren(DataModelObjectCategory.Body, True) +body_ids = [bd.GetGeoBody().Id for bd in bodies] +selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) +selection.Ids = body_ids +ns1 = Model.AddNamedSelection() +ns1.Name = "all_bodies" +ns1.Location = selection + +# Create named selection for all except substrate +NSall = ExtAPI.DataModel.Project.Model.NamedSelections.GetChildren[ + Ansys.ACT.Automation.Mechanical.NamedSelection +](True) +substrate_id = [bd.GetGeoBody().Id for bd in bodies if bd.Name.endswith("substrate")] +except_substrate_id = list(set(body_ids) - set(substrate_id)) + +selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) +selection.Ids = except_substrate_id +ns2 = Model.AddNamedSelection() +ns2.Name = "all_except_board" +ns2.Location = selection + +# -- Meshing -- +# +mesh = Model.Mesh + +# automatic_method = mesh.AddAutomaticMethod() +# NSall = ExtAPI.DataModel.Project.Model.NamedSelections.GetChildren[ +# Ansys.ACT.Automation.Mechanical.NamedSelection +# ](True) +# all_bodies = [i for i in NSall if i.Name == "all_bodies"][0] +# automatic_method.Location = all_bodies +# automatic_method.Method = MethodType.MultiZone + +# addsizing1 = mesh.AddSizing() +# all_bodies_except_board = [i for i in NSall if i.Name == "all_except_board"][0] +# addsizing1.Location = all_bodies_except_board +# addsizing1.ElementSize = Quantity(0.0009, "m") + +# addsizing2 = mesh.AddSizing() +# board = [i for i in NSall if i.Name == "substrate"][0] +# addsizing2.Location = board +# addsizing2.ElementSize = Quantity(0.002, "m") +mesh.GenerateMesh() + +# Export mesh image +ExtAPI.Graphics.Camera.SetFit() +ExtAPI.Graphics.ExportImage( + os.path.join(OUTPUT_DIR, "mesh.png"), image_export_format, settings_720p +) + +# Display the mesh +if GRAPHICS_BOOL: + display_image("mesh.png") + + +# -- Analysis -- +# +# Steady state thermal analysis setup +internal_heat_generation = steady.AddInternalHeatGeneration() +NSall = ExtAPI.DataModel.Project.Model.NamedSelections.GetChildren[ + Ansys.ACT.Automation.Mechanical.NamedSelection +](True) +ic6 = [i for i in NSall if i.Name == "ic-6"][0] +internal_heat_generation.Location = ic6 +internal_heat_generation.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, "W m^-1 m^-1 m^-1")) + +all_bodies = [i for i in NSall if i.Name == "all_bodies"][0] +convection = steady.AddConvection() +convection.Location = all_bodies +convection.FilmCoefficient.Output.DiscreteValues = [Quantity("5[W m^-2 C^-1]")] # not quite correct + +steady_solution = steady.Solution +temperature_result = steady_solution.AddTemperature() +steady_solution.Solve(True) + +# Transient analysis setup +initial_condition = steady_solution.Children[0] +initial_condition.InitialTemperature = InitialTemperatureType.NonUniform +initial_condition.InitialEnvironment = steady + +ansys_analysis_settings = transient.AnalysisSettings +ansys_analysis_settings.StepEndTime = Quantity(200, "sec") + +internal_heat_generation2 = transient.AddInternalHeatGeneration() + +ic1 = [i for i in NSall if i.Name == "ic-1"][0] +internal_heat_generation2.Location = ic1 +internal_heat_generation2.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, "W m^-1 m^-1 m^-1")) + +# -- Add result objects for post processing -- +# +transient_solution = transient.Solution +transient_temperature_result = transient_solution.AddTemperature() +temperature_probe1 = transient_solution.AddTemperatureProbe() +temperature_probe1.GeometryLocation = ic6 +temperature_probe2 = transient_solution.AddTemperatureProbe() +temperature_probe2.GeometryLocation = ic1 + +# -- Solve -- +# +transient_solution.Solve(True) + + +# -- Save files and close mechanical -- +# +# Mechanical file (mechdb) containes results files for each analysis +app.save(os.path.join(OUTPUT_DIR, "pcb.mechdb")) +project_directory = ExtAPI.DataModel.Project.ProjectDirectory +app.exit() From 05289966ccfaafdb59c675c5c884e84882cca929 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 20 Jun 2024 11:31:23 -0500 Subject: [PATCH 03/25] dpf workflow --- geometry-mechanical-dpf/03_dpf.py | 102 ++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 geometry-mechanical-dpf/03_dpf.py diff --git a/geometry-mechanical-dpf/03_dpf.py b/geometry-mechanical-dpf/03_dpf.py new file mode 100644 index 00000000..84a1f498 --- /dev/null +++ b/geometry-mechanical-dpf/03_dpf.py @@ -0,0 +1,102 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os +from pathlib import Path + +from ansys.dpf import core as dpf + +# -- Parameters -- +# +GRAPHICS_BOOL = False # Set to True to display the mesh +OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory + + +# -- Finding necessary files for dpf -- +# +def find_files(directory, extension): + rst_files = [] + for root, _, files in os.walk(directory): + for file in files: + if file.endswith(extension): + rst_files.append(os.path.join(root, file)) + return rst_files + + +extension_to_find = ".rth" + +# Mechanical poject directory +project_directory = os.path.join(OUTPUT_DIR, "pcb_Mech_Files") + +steady_state_rth_file = find_files( + os.path.join(project_directory, "SteadyStateThermal"), extension_to_find +) +transient_rth_file = find_files( + os.path.join(project_directory, "TransientThermal"), extension_to_find +) + +if steady_state_rth_file and transient_rth_file: + print(f"Found {extension_to_find} files.") +else: + print("No .rst files found.") + +print(steady_state_rth_file) +print(transient_rth_file) + +# -- DPF workflow -- +# +# Result precision +decimal_precision = 6 + + +# -- Steady state thermal results -- +# +# Create model +path = steady_state_rth_file[0] +my_data_sources = dpf.DataSources() +my_data_sources.set_result_file_path(path) +my_data_sources.add_file_path(path) +my_model = dpf.Model(path) + +# Get temperature distribution +temp = my_model.results.temperature.on_last_time_freq.eval()[0] + +# Plot the the temperature for ic-6 +if GRAPHICS_BOOL: + temp.plot() + +# -- Transien thermal results -- +# +# Create model + +path = transient_rth_file[0] +my_data_sources = dpf.DataSources() +my_data_sources.set_result_file_path(path) +my_data_sources.add_file_path(path) +my_model = dpf.Model(path) + +# Get temperature distribution +temp = my_model.results.temperature.on_last_time_freq.eval()[0] + +# Plot the the temperature for ic-1 +if GRAPHICS_BOOL: + temp.plot() From 4632cd17afd999f6bc816761f6db7716e32ab909 Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:16:50 -0500 Subject: [PATCH 04/25] Apply suggestions from code review Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- geometry-mechanical-dpf/01_geometry.py | 2 +- geometry-mechanical-dpf/requirements_24.1.txt | 2 -- geometry-mechanical-dpf/requirements_24.2.txt | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/geometry-mechanical-dpf/01_geometry.py b/geometry-mechanical-dpf/01_geometry.py index 36e89f1a..620a636f 100644 --- a/geometry-mechanical-dpf/01_geometry.py +++ b/geometry-mechanical-dpf/01_geometry.py @@ -172,7 +172,7 @@ # Plot the the entire geometry if GRAPHICS_BOOL: - component.plot() + design.plot() # -- Export file -- # diff --git a/geometry-mechanical-dpf/requirements_24.1.txt b/geometry-mechanical-dpf/requirements_24.1.txt index 8f224e92..de66ac32 100644 --- a/geometry-mechanical-dpf/requirements_24.1.txt +++ b/geometry-mechanical-dpf/requirements_24.1.txt @@ -1,5 +1,3 @@ ansys-geometry-core[all]==0.6.0 -ansys-mechanical-core==0.11.0 ansys-mechanical-core[viz]==0.11.0 -ansys-dpf-core==0.12.2 ansys-dpf-core[plotting]==0.12.2 diff --git a/geometry-mechanical-dpf/requirements_24.2.txt b/geometry-mechanical-dpf/requirements_24.2.txt index 1466024e..b3de4827 100644 --- a/geometry-mechanical-dpf/requirements_24.2.txt +++ b/geometry-mechanical-dpf/requirements_24.2.txt @@ -1,5 +1,3 @@ ansys-geometry-core[all]==0.6.0 -ansys-mechanical-core==0.11.0 ansys-mechanical-core[viz]==0.11.0 -ansys-dpf-core==0.12.2 ansys-dpf-core[plotting]==0.12.2 \ No newline at end of file From 76f90734e575dc5daf00887cb583cd4b90cec2ca Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 20 Jun 2024 12:27:46 -0500 Subject: [PATCH 05/25] reformat --- geometry-mechanical-dpf/01_geometry.py | 33 ++++++++++-------------- geometry-mechanical-dpf/02_mechanical.py | 2 +- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/geometry-mechanical-dpf/01_geometry.py b/geometry-mechanical-dpf/01_geometry.py index 620a636f..218a057c 100644 --- a/geometry-mechanical-dpf/01_geometry.py +++ b/geometry-mechanical-dpf/01_geometry.py @@ -63,26 +63,19 @@ # Create PCB Substrate sketch_substrate = Sketch() -sketch_substrate.segment(Point2D([5, 0]), Point2D([122, 0])).arc_to_point( - Point2D([127, 5]), Point2D([122, 5]) -).segment_to_point(Point2D([127, 135])).arc_to_point( - Point2D([122, 140]), Point2D([122, 135]) -).segment_to_point( - Point2D([5, 140]) -).arc_to_point( - Point2D([0, 135]), Point2D([5, 135]) -).segment_to_point( - Point2D([0, 5]) -).arc_to_point( - Point2D([5, 0]), Point2D([5, 5]) -).circle( - Point2D([6.35, 6.35]), radius=3.94 / 2 -).circle( - Point2D([127 - 6.35, 6.35]), radius=3.94 / 2 -).circle( - Point2D([127 - 6.35, 140 - 6.35]), radius=3.94 / 2 -).circle( - Point2D([6.35, 140 - 6.35]), radius=3.94 / 2 +( + sketch_substrate.segment(Point2D([5, 0]), Point2D([122, 0])) + .arc_to_point(Point2D([127, 5]), Point2D([122, 5])) + .segment_to_point(Point2D([127, 135])) + .arc_to_point(Point2D([122, 140]), Point2D([122, 135])) + .segment_to_point(Point2D([5, 140])) + .arc_to_point(Point2D([0, 135]), Point2D([5, 135])) + .segment_to_point(Point2D([0, 5])) + .arc_to_point(Point2D([5, 0]), Point2D([5, 5])) + .circle(Point2D([6.35, 6.35]), radius=3.94 / 2) + .circle(Point2D([127 - 6.35, 6.35]), radius=3.94 / 2) + .circle(Point2D([127 - 6.35, 140 - 6.35]), radius=3.94 / 2) + .circle(Point2D([6.35, 140 - 6.35]), radius=3.94 / 2) ) substrate_height = 1.575 plane = Plane( diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 3da55054..83d4fee1 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -152,7 +152,7 @@ def display_image(image_name): all_bodies = [i for i in NSall if i.Name == "all_bodies"][0] convection = steady.AddConvection() convection.Location = all_bodies -convection.FilmCoefficient.Output.DiscreteValues = [Quantity("5[W m^-2 C^-1]")] # not quite correct +convection.FilmCoefficient.Output.DiscreteValues = [Quantity("5[W m^-2 C^-1]")] steady_solution = steady.Solution temperature_result = steady_solution.AddTemperature() From 50e929e03d5591f3fc758b74cdcb6ac74b96fec2 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 20 Jun 2024 15:40:32 -0500 Subject: [PATCH 06/25] update geometry cicd --- .github/workflows/geometry-mechanical-dpf.yml | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 .github/workflows/geometry-mechanical-dpf.yml diff --git a/.github/workflows/geometry-mechanical-dpf.yml b/.github/workflows/geometry-mechanical-dpf.yml new file mode 100644 index 00000000..d4f654ec --- /dev/null +++ b/.github/workflows/geometry-mechanical-dpf.yml @@ -0,0 +1,134 @@ +name: Geometry Mesh Workflow + +on: + push: + branches: + - main + pull_request: + paths: + - 'geometry-mechanical-dpf/**' + +env: + MAIN_PYTHON_VERSION: '3.12' + GEOMETRY_DOCKER_IMAGE: 'ghcr.io/ansys/geometry' + MECHANICAL_DOCKER_IMAGE: 'ghcr.io/ansys/mechanical' + ANSRV_GEO_PORT: 700 + ANSRV_GEO_LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }} + ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER )}} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + geometry: + name: Geometry + runs-on: [self-hosted, Windows, pyansys-workflows] + strategy: + fail-fast: false + matrix: + ansys-release: [24.1, 24.2] + steps: + + - name: Checkout code + uses: actions/checkout@v4 + with: + sparse-checkout: 'geometry-mechanical-dpf' + + - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.MAIN_PYTHON_VERSION }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m venv .venv + .venv/Scripts/activate + pip install -r geometry-mechanical-dpf/requirements_${{ matrix.ansys-release }}.txt + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download (if needed) and run Geometry service container + run: | + docker pull ${{ env.GEOMETRY_DOCKER_IMAGE }}:windows-${{ matrix.ansys-release }} + + - name: Run the PyAnsys Geometry script + env: + ANSYS_GEOMETERY_RELEASE: ${{ env.GEOMETRY_DOCKER_IMAGE }}:windows-${{ matrix.ansys-release }} + run: | + .venv/Scripts/activate + python geometry-mechanical-dpf/01_geometry.py + + - name: Store the outputs + uses: actions/upload-artifact@v4 + with: + name: geometry-outputs-${{ matrix.ansys-release }} + path: geometry-mechanical-dpf/outputs + + - name: Stop any remaining containers + if: always() + run: | + $dockerContainers = docker ps -a -q + if (-not [string]::IsNullOrEmpty($dockerContainers)) { + docker stop $dockerContainers + docker rm $dockerContainers + } + + mech-dpf: + name: Mechanical - Dpf + runs-on: ubuntu-latest + needs: geometry + strategy: + fail-fast: false + matrix: + ansys-release: [24.1.0, 24.2] + steps: + + - name: Checkout code + uses: actions/checkout@v4 + with: + sparse-checkout: 'geometry-mechanical-dpf' + + - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.MAIN_PYTHON_VERSION }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r geometry-mechanical-dpf/requirements_${{ matrix.ansys-release }}.txt + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download PRIME service container + run: docker pull ${{ env.PRIME_DOCKER_IMAGE }}:${{ matrix.ansys-release }} + + - name: Check out the geometry outputs + uses: actions/download-artifact@v4 + with: + name: geometry-outputs-${{ matrix.ansys-release }} + path: geometry-mechanical-dpf/outputs + + - name: Run the PyPrimeMesh script + env: + PYPRIMEMESH_IMAGE_TAG: ${{ matrix.ansys-release }} + run: | + python geometry-mechanical-dpf/02_mesh.py + + - name: Store the outputs + uses: actions/upload-artifact@v4 + with: + name: prime-outputs-${{ matrix.ansys-release }} + path: geometry-mechanical-dpf/outputs From 3bb9df68266598180907f631fde485835e424097 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 09:44:51 -0500 Subject: [PATCH 07/25] fix dependencies --- geometry-mechanical-dpf/requirements_24.1.txt | 2 +- geometry-mechanical-dpf/requirements_24.2.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/geometry-mechanical-dpf/requirements_24.1.txt b/geometry-mechanical-dpf/requirements_24.1.txt index de66ac32..75029106 100644 --- a/geometry-mechanical-dpf/requirements_24.1.txt +++ b/geometry-mechanical-dpf/requirements_24.1.txt @@ -1,3 +1,3 @@ ansys-geometry-core[all]==0.6.0 -ansys-mechanical-core[viz]==0.11.0 +ansys-mechanical-core==0.11.0 ansys-dpf-core[plotting]==0.12.2 diff --git a/geometry-mechanical-dpf/requirements_24.2.txt b/geometry-mechanical-dpf/requirements_24.2.txt index b3de4827..854332fa 100644 --- a/geometry-mechanical-dpf/requirements_24.2.txt +++ b/geometry-mechanical-dpf/requirements_24.2.txt @@ -1,3 +1,3 @@ ansys-geometry-core[all]==0.6.0 -ansys-mechanical-core[viz]==0.11.0 +ansys-mechanical-core==0.11.0 ansys-dpf-core[plotting]==0.12.2 \ No newline at end of file From 9dbdee0bde16daf5f1b70df06589f1056d62bbec Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 09:45:38 -0500 Subject: [PATCH 08/25] remove version --- geometry-mechanical-dpf/02_mechanical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 83d4fee1..de7a928f 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -29,7 +29,7 @@ # -- Start PyMechanical app -- # -app = mech.App(version=242) +app = mech.App() app.update_globals(globals()) print(app) From ffbc829262c3195953e437abb47f33a789f4416d Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 10:11:34 -0500 Subject: [PATCH 09/25] fix geo script --- geometry-mechanical-dpf/01_geometry.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/geometry-mechanical-dpf/01_geometry.py b/geometry-mechanical-dpf/01_geometry.py index 218a057c..646c0894 100644 --- a/geometry-mechanical-dpf/01_geometry.py +++ b/geometry-mechanical-dpf/01_geometry.py @@ -100,24 +100,6 @@ sketch_ic_8 = Sketch(plane=plane) sketch_ic_8.box(Point2D([21, 59]), 10, 18) - -sketch = Sketch() -( - sketch.segment(start=Point2D([-4, 5]), end=Point2D([4, 5])) - .segment_to_point(end=Point2D([4, -5])) - .segment_to_point(end=Point2D([-4, -5])) - .segment_to_point(end=Point2D([-4, 5])) - .box( - center=Point2D([0, 0]), - width=Distance(3), - height=Distance(3), - ) - .circle(center=Point2D([3, 4]), radius=outer_hole_radius) - .circle(center=Point2D([-3, -4]), radius=outer_hole_radius) - .circle(center=Point2D([-3, 4]), radius=outer_hole_radius) - .circle(center=Point2D([3, -4]), radius=outer_hole_radius) -) - # -- Perform some modeling operations -- # # Now that the sketch is ready to be extruded, perform some modeling operations, From 2cfb942947d032fc86333b1f183a00f678e23ad1 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 10:28:17 -0500 Subject: [PATCH 10/25] add mechanical image --- .github/workflows/geometry-mechanical-dpf.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/geometry-mechanical-dpf.yml b/.github/workflows/geometry-mechanical-dpf.yml index d4f654ec..d8f3c3c1 100644 --- a/.github/workflows/geometry-mechanical-dpf.yml +++ b/.github/workflows/geometry-mechanical-dpf.yml @@ -87,7 +87,10 @@ jobs: strategy: fail-fast: false matrix: - ansys-release: [24.1.0, 24.2] + ansys-release: [24.1.0, 24.2.0] + container: + image: 'ghcr.io/ansys/mechanical:${{ matrix.ansys-release }}' + options: --entrypoint /bin/bash steps: - name: Checkout code @@ -95,10 +98,14 @@ jobs: with: sparse-checkout: 'geometry-mechanical-dpf' - - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} - uses: actions/setup-python@v5 - with: - python-version: ${{ env.MAIN_PYTHON_VERSION }} + - name: Set up Python + run: | + apt update + apt install --reinstall ca-certificates + apt install software-properties-common -y + add-apt-repository ppa:deadsnakes/ppa -y + apt install -y python${{ env.MAIN_PYTHON_VERSION }} python${{ env.MAIN_PYTHON_VERSION }}-venv + python${{ env.MAIN_PYTHON_VERSION }} -m venv /env - name: Install dependencies run: | From 5bffcaff8c8e2503aa3aa3fb293ca28ca7609d7e Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 10:37:00 -0500 Subject: [PATCH 11/25] mechanical cicd --- .github/workflows/geometry-mechanical-dpf.yml | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/geometry-mechanical-dpf.yml b/.github/workflows/geometry-mechanical-dpf.yml index d8f3c3c1..349e9e7a 100644 --- a/.github/workflows/geometry-mechanical-dpf.yml +++ b/.github/workflows/geometry-mechanical-dpf.yml @@ -87,9 +87,9 @@ jobs: strategy: fail-fast: false matrix: - ansys-release: [24.1.0, 24.2.0] + ansys-release: [24.1, 24.2] container: - image: 'ghcr.io/ansys/mechanical:${{ matrix.ansys-release }}' + image: 'ghcr.io/ansys/mechanical:${{ matrix.ansys-release }}.0' options: --entrypoint /bin/bash steps: @@ -109,30 +109,25 @@ jobs: - name: Install dependencies run: | + . /env/bin/activate python -m pip install --upgrade pip pip install -r geometry-mechanical-dpf/requirements_${{ matrix.ansys-release }}.txt - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Download PRIME service container - run: docker pull ${{ env.PRIME_DOCKER_IMAGE }}:${{ matrix.ansys-release }} - - name: Check out the geometry outputs uses: actions/download-artifact@v4 with: name: geometry-outputs-${{ matrix.ansys-release }} path: geometry-mechanical-dpf/outputs - - name: Run the PyPrimeMesh script + - name: Run the PyPyMechanical script env: - PYPRIMEMESH_IMAGE_TAG: ${{ matrix.ansys-release }} + NUM_CORES: 1 + LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }} + ANSYS_WORKBENCH_LOGGING_CONSOLE: 0 + ANSYS_WORKBENCH_LOGGING: 0 + ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 2 run: | - python geometry-mechanical-dpf/02_mesh.py + xvfb-run mechanical-env python geometry-mechanical-dpf/02_mechanical.py - name: Store the outputs uses: actions/upload-artifact@v4 From 84c8286c88c7d0812397ac8c9eb7ed4a3764d549 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 10:55:08 -0500 Subject: [PATCH 12/25] activate venv --- .github/workflows/geometry-mechanical-dpf.yml | 1 + geometry-mechanical-dpf/02_mechanical.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/geometry-mechanical-dpf.yml b/.github/workflows/geometry-mechanical-dpf.yml index 349e9e7a..8268e3f5 100644 --- a/.github/workflows/geometry-mechanical-dpf.yml +++ b/.github/workflows/geometry-mechanical-dpf.yml @@ -127,6 +127,7 @@ jobs: ANSYS_WORKBENCH_LOGGING: 0 ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 2 run: | + . /env/bin/activate xvfb-run mechanical-env python geometry-mechanical-dpf/02_mechanical.py - name: Store the outputs diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index de7a928f..43d835cf 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -30,7 +30,7 @@ # -- Start PyMechanical app -- # app = mech.App() -app.update_globals(globals()) +globals().update(mech.global_variables(app, True)) print(app) # -- Parameters -- @@ -63,7 +63,7 @@ def display_image(image_name): # -- Import geometry -- # # Reads geometry file and displa -geometry_path = modeling_file = Path(OUTPUT_DIR, "pcb.mechdb") +geometry_path = Path(OUTPUT_DIR, "pcb.pmdb") geometry_import_group = Model.GeometryImportGroup geometry_import = geometry_import_group.AddGeometryImport() geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic From 96e950707aaa928aca659dfcb78d0000299d6a83 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 11:39:17 -0500 Subject: [PATCH 13/25] change path type for mechanical --- geometry-mechanical-dpf/02_mechanical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 43d835cf..c71ad898 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -37,7 +37,7 @@ # GRAPHICS_BOOL = False # Set to True to display the mesh OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory - +CWD = os.getcwd() def display_image(image_name): plt.figure(figsize=(16, 9)) @@ -63,7 +63,7 @@ def display_image(image_name): # -- Import geometry -- # # Reads geometry file and displa -geometry_path = Path(OUTPUT_DIR, "pcb.pmdb") +geometry_path = os.path.join(CWD, "outputs", "pcb.pmdb") geometry_import_group = Model.GeometryImportGroup geometry_import = geometry_import_group.AddGeometryImport() geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic From 342d57cf471c43485b5cdaa09182cdaff54a4f80 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 12:06:00 -0500 Subject: [PATCH 14/25] print paths --- geometry-mechanical-dpf/02_mechanical.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index c71ad898..661d4c64 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -38,6 +38,8 @@ GRAPHICS_BOOL = False # Set to True to display the mesh OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory CWD = os.getcwd() +print(OUTPUT_DIR) +print(CWD) def display_image(image_name): plt.figure(figsize=(16, 9)) From 2c4046c55bbb25e99452978ba833714a6a1c0a4d Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 12:58:42 -0500 Subject: [PATCH 15/25] us os instead of pathlib --- geometry-mechanical-dpf/02_mechanical.py | 8 +++----- geometry-mechanical-dpf/03_dpf.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 661d4c64..35ac4049 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -21,7 +21,6 @@ # SOFTWARE. import os -from pathlib import Path import ansys.mechanical.core as mech from matplotlib import image as mpimg @@ -36,10 +35,9 @@ # -- Parameters -- # GRAPHICS_BOOL = False # Set to True to display the mesh -OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory CWD = os.getcwd() -print(OUTPUT_DIR) -print(CWD) +OUTPUT_DIR = os.path.join(CWD, "geometry-mechanical-dpf" "outputs") # Output directory + def display_image(image_name): plt.figure(figsize=(16, 9)) @@ -65,7 +63,7 @@ def display_image(image_name): # -- Import geometry -- # # Reads geometry file and displa -geometry_path = os.path.join(CWD, "outputs", "pcb.pmdb") +geometry_path = os.path.join(OUTPUT_DIR, "pcb.pmdb") geometry_import_group = Model.GeometryImportGroup geometry_import = geometry_import_group.AddGeometryImport() geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic diff --git a/geometry-mechanical-dpf/03_dpf.py b/geometry-mechanical-dpf/03_dpf.py index 84a1f498..96da3bfc 100644 --- a/geometry-mechanical-dpf/03_dpf.py +++ b/geometry-mechanical-dpf/03_dpf.py @@ -71,11 +71,11 @@ def find_files(directory, extension): # -- Steady state thermal results -- # # Create model -path = steady_state_rth_file[0] +steady_state_result_file_path = steady_state_rth_file[0] my_data_sources = dpf.DataSources() -my_data_sources.set_result_file_path(path) -my_data_sources.add_file_path(path) -my_model = dpf.Model(path) +my_data_sources.set_result_file_path(steady_state_result_file_path) +my_data_sources.add_file_path(steady_state_result_file_path) +my_model = dpf.Model(steady_state_result_file_path) # Get temperature distribution temp = my_model.results.temperature.on_last_time_freq.eval()[0] @@ -88,11 +88,11 @@ def find_files(directory, extension): # # Create model -path = transient_rth_file[0] +transient_result_file_path = transient_rth_file[0] my_data_sources = dpf.DataSources() -my_data_sources.set_result_file_path(path) -my_data_sources.add_file_path(path) -my_model = dpf.Model(path) +my_data_sources.set_result_file_path(transient_result_file_path) +my_data_sources.add_file_path(transient_result_file_path) +my_model = dpf.Model(transient_result_file_path) # Get temperature distribution temp = my_model.results.temperature.on_last_time_freq.eval()[0] From ddba5cec9c480f7a084b3bca94a1921554ebd496 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 15:44:15 -0500 Subject: [PATCH 16/25] update geometry path as str --- geometry-mechanical-dpf/02_mechanical.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 35ac4049..506d39b8 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -21,6 +21,7 @@ # SOFTWARE. import os +from pathlib import Path import ansys.mechanical.core as mech from matplotlib import image as mpimg @@ -35,8 +36,7 @@ # -- Parameters -- # GRAPHICS_BOOL = False # Set to True to display the mesh -CWD = os.getcwd() -OUTPUT_DIR = os.path.join(CWD, "geometry-mechanical-dpf" "outputs") # Output directory +OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory def display_image(image_name): @@ -62,16 +62,16 @@ def display_image(image_name): # -- Import geometry -- # -# Reads geometry file and displa -geometry_path = os.path.join(OUTPUT_DIR, "pcb.pmdb") +# Import geometry +geometry_path = Path(OUTPUT_DIR, "pcb.pmdb") geometry_import_group = Model.GeometryImportGroup geometry_import = geometry_import_group.AddGeometryImport() geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences() geometry_import_preferences.ProcessNamedSelections = True -geometry_import.Import(geometry_path, geometry_import_format, geometry_import_preferences) +geometry_import.Import(str(geometry_path), geometry_import_format, geometry_import_preferences) -# Plot the the entire geometry +# Plot geometry if GRAPHICS_BOOL: app.plot() From 0520d7cfe672b28378b8e6cb09ddd4735d7613b1 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 16:11:51 -0500 Subject: [PATCH 17/25] update runner --- .github/workflows/geometry-mechanical-dpf.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/geometry-mechanical-dpf.yml b/.github/workflows/geometry-mechanical-dpf.yml index 8268e3f5..9f0428bf 100644 --- a/.github/workflows/geometry-mechanical-dpf.yml +++ b/.github/workflows/geometry-mechanical-dpf.yml @@ -82,7 +82,7 @@ jobs: mech-dpf: name: Mechanical - Dpf - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8-cores needs: geometry strategy: fail-fast: false From 21ba56e96ef04feceb610a3a094e26895a827d63 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 17:15:00 -0500 Subject: [PATCH 18/25] always pass pymechanical run --- .github/workflows/geometry-mechanical-dpf.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/geometry-mechanical-dpf.yml b/.github/workflows/geometry-mechanical-dpf.yml index 9f0428bf..9e6dea84 100644 --- a/.github/workflows/geometry-mechanical-dpf.yml +++ b/.github/workflows/geometry-mechanical-dpf.yml @@ -122,13 +122,23 @@ jobs: - name: Run the PyPyMechanical script env: NUM_CORES: 1 - LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }} ANSYS_WORKBENCH_LOGGING_CONSOLE: 0 ANSYS_WORKBENCH_LOGGING: 0 ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 2 run: | . /env/bin/activate - xvfb-run mechanical-env python geometry-mechanical-dpf/02_mechanical.py + xvfb-run mechanical-env python geometry-mechanical-dpf/02_mechanical.py > pymechlogs${{ matrix.ansys-release }}.txt 2>&1 || true + cat pymechlogs${{ matrix.ansys-release }}.txt + + # - name: Run the PyDPF script + # env: + # NUM_CORES: 1 + # ANSYS_WORKBENCH_LOGGING_CONSOLE: 0 + # ANSYS_WORKBENCH_LOGGING: 0 + # ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 2 + # run: | + # . /env/bin/activate + # python geometry-mechanical-dpf/03_dpf.py - name: Store the outputs uses: actions/upload-artifact@v4 From 11f8f98960b70249b8426e488d756d68e8e9aad7 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 17:59:08 -0500 Subject: [PATCH 19/25] version from cicd env --- geometry-mechanical-dpf/02_mechanical.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 506d39b8..38907157 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -27,9 +27,18 @@ from matplotlib import image as mpimg from matplotlib import pyplot as plt +# Check env vars to see which image to launch +# +# --- ONLY FOR WORKFLOW RUNS --- +version = None +if "ANSYS_GEOMETRY_RELEASE" in os.environ: + image_tag = os.environ["ANSYS_GEOMETRY_RELEASE"] + version = int(image_tag.replace(".", "")) + + # -- Start PyMechanical app -- # -app = mech.App() +app = mech.App(version=version) globals().update(mech.global_variables(app, True)) print(app) From 7b9ae47d66c955cb2da32ecf42a63b679ffc2799 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 18:40:27 -0500 Subject: [PATCH 20/25] dpf workflow --- .github/workflows/geometry-mechanical-dpf.yml | 19 ++++++++----------- geometry-mechanical-dpf/02_mechanical.py | 5 +++-- geometry-mechanical-dpf/03_dpf.py | 19 ++++++------------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/.github/workflows/geometry-mechanical-dpf.yml b/.github/workflows/geometry-mechanical-dpf.yml index 9e6dea84..c586fb53 100644 --- a/.github/workflows/geometry-mechanical-dpf.yml +++ b/.github/workflows/geometry-mechanical-dpf.yml @@ -119,29 +119,26 @@ jobs: name: geometry-outputs-${{ matrix.ansys-release }} path: geometry-mechanical-dpf/outputs - - name: Run the PyPyMechanical script + - name: Run the PyMechanical script env: NUM_CORES: 1 ANSYS_WORKBENCH_LOGGING_CONSOLE: 0 ANSYS_WORKBENCH_LOGGING: 0 ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 2 + ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} run: | . /env/bin/activate xvfb-run mechanical-env python geometry-mechanical-dpf/02_mechanical.py > pymechlogs${{ matrix.ansys-release }}.txt 2>&1 || true cat pymechlogs${{ matrix.ansys-release }}.txt - # - name: Run the PyDPF script - # env: - # NUM_CORES: 1 - # ANSYS_WORKBENCH_LOGGING_CONSOLE: 0 - # ANSYS_WORKBENCH_LOGGING: 0 - # ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 2 - # run: | - # . /env/bin/activate - # python geometry-mechanical-dpf/03_dpf.py + - name: Run the PyDPF script + run: | + . /env/bin/activate + xvfb-run python geometry-mechanical-dpf/03_dpf.py > pydpflogs${{ matrix.ansys-release }}.txt 2>&1 || true + cat pydpflogs${{ matrix.ansys-release }}.txt - name: Store the outputs uses: actions/upload-artifact@v4 with: - name: prime-outputs-${{ matrix.ansys-release }} + name: pymechanical-dpf-outputs-${{ matrix.ansys-release }} path: geometry-mechanical-dpf/outputs diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 38907157..3618c4fb 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -31,10 +31,11 @@ # # --- ONLY FOR WORKFLOW RUNS --- version = None -if "ANSYS_GEOMETRY_RELEASE" in os.environ: - image_tag = os.environ["ANSYS_GEOMETRY_RELEASE"] +if "ANSYS_MECHANICAL_RELEASE" in os.environ: + image_tag = os.environ["ANSYS_MECHANICAL_RELEASE"] version = int(image_tag.replace(".", "")) +print(version) # -- Start PyMechanical app -- # diff --git a/geometry-mechanical-dpf/03_dpf.py b/geometry-mechanical-dpf/03_dpf.py index 96da3bfc..045ffc9b 100644 --- a/geometry-mechanical-dpf/03_dpf.py +++ b/geometry-mechanical-dpf/03_dpf.py @@ -71,14 +71,11 @@ def find_files(directory, extension): # -- Steady state thermal results -- # # Create model -steady_state_result_file_path = steady_state_rth_file[0] -my_data_sources = dpf.DataSources() -my_data_sources.set_result_file_path(steady_state_result_file_path) -my_data_sources.add_file_path(steady_state_result_file_path) -my_model = dpf.Model(steady_state_result_file_path) +steady_state_model = dpf.Model(steady_state_rth_file[0]) +print(steady_state_model) # Get temperature distribution -temp = my_model.results.temperature.on_last_time_freq.eval()[0] +temp = steady_state_model.results.temperature.on_last_time_freq.eval()[0] # Plot the the temperature for ic-6 if GRAPHICS_BOOL: @@ -87,15 +84,11 @@ def find_files(directory, extension): # -- Transien thermal results -- # # Create model - -transient_result_file_path = transient_rth_file[0] -my_data_sources = dpf.DataSources() -my_data_sources.set_result_file_path(transient_result_file_path) -my_data_sources.add_file_path(transient_result_file_path) -my_model = dpf.Model(transient_result_file_path) +model = dpf.Model(transient_rth_file[0]) +print(steady_state_model) # Get temperature distribution -temp = my_model.results.temperature.on_last_time_freq.eval()[0] +temp = model.results.temperature.on_last_time_freq.eval()[0] # Plot the the temperature for ic-1 if GRAPHICS_BOOL: From 12f4abe6b7f64db7fc94652511e36aeb11652c5f Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 21 Jun 2024 19:03:58 -0500 Subject: [PATCH 21/25] final --- geometry-mechanical-dpf/02_mechanical.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 3618c4fb..aee1bfe6 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -35,8 +35,6 @@ image_tag = os.environ["ANSYS_MECHANICAL_RELEASE"] version = int(image_tag.replace(".", "")) -print(version) - # -- Start PyMechanical app -- # app = mech.App(version=version) From b3a422f729d4c9c827aeb4f3e50c076d3e084c1d Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Mon, 24 Jun 2024 08:54:17 +0200 Subject: [PATCH 22/25] Apply suggestions from code review Co-authored-by: Maxime Rey <87315832+MaxJPRey@users.noreply.github.com> --- geometry-mechanical-dpf/01_geometry.py | 4 ++-- geometry-mechanical-dpf/02_mechanical.py | 2 +- geometry-mechanical-dpf/03_dpf.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/geometry-mechanical-dpf/01_geometry.py b/geometry-mechanical-dpf/01_geometry.py index 646c0894..17824af8 100644 --- a/geometry-mechanical-dpf/01_geometry.py +++ b/geometry-mechanical-dpf/01_geometry.py @@ -84,7 +84,7 @@ direction_y=[0, 1, 0], ) -# creat IC +# create IC sketch_IC = Sketch(plane) sketch_IC.box(Point2D([62 / 2 + 7.5, 51 / 2 + 5]), 15, 10) @@ -109,7 +109,7 @@ # Start by creating the Design design = modeler.create_design("pcb_design") -# Create a all necessary components for pcb +# Create all necessary components for pcb component = design.add_component("PCB") component.extrude_sketch("substrate", sketch_substrate, distance=substrate_height) ic_1 = component.extrude_sketch("ic-1", sketch_IC, distance=4.5) diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index aee1bfe6..3ec34184 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -196,7 +196,7 @@ def display_image(image_name): # -- Save files and close mechanical -- # -# Mechanical file (mechdb) containes results files for each analysis +# Mechanical file (mechdb) contains results for each analysis app.save(os.path.join(OUTPUT_DIR, "pcb.mechdb")) project_directory = ExtAPI.DataModel.Project.ProjectDirectory app.exit() diff --git a/geometry-mechanical-dpf/03_dpf.py b/geometry-mechanical-dpf/03_dpf.py index 045ffc9b..008882c3 100644 --- a/geometry-mechanical-dpf/03_dpf.py +++ b/geometry-mechanical-dpf/03_dpf.py @@ -77,7 +77,7 @@ def find_files(directory, extension): # Get temperature distribution temp = steady_state_model.results.temperature.on_last_time_freq.eval()[0] -# Plot the the temperature for ic-6 +# Plot the temperature for ic-6 if GRAPHICS_BOOL: temp.plot() From b93c4b0bd79aada60d0a290e730fbf0ed8dbadfd Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Mon, 24 Jun 2024 08:06:57 -0500 Subject: [PATCH 23/25] Apply suggestions from code review Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .github/workflows/geometry-mechanical-dpf.yml | 2 +- geometry-mechanical-dpf/01_geometry.py | 1 - geometry-mechanical-dpf/02_mechanical.py | 19 ------------------- geometry-mechanical-dpf/03_dpf.py | 1 - 4 files changed, 1 insertion(+), 22 deletions(-) diff --git a/.github/workflows/geometry-mechanical-dpf.yml b/.github/workflows/geometry-mechanical-dpf.yml index c586fb53..5fbf0baa 100644 --- a/.github/workflows/geometry-mechanical-dpf.yml +++ b/.github/workflows/geometry-mechanical-dpf.yml @@ -1,4 +1,4 @@ -name: Geometry Mesh Workflow +name: Geometry Mechanical DPF Workflow on: push: diff --git a/geometry-mechanical-dpf/01_geometry.py b/geometry-mechanical-dpf/01_geometry.py index 17824af8..8bcc1502 100644 --- a/geometry-mechanical-dpf/01_geometry.py +++ b/geometry-mechanical-dpf/01_geometry.py @@ -60,7 +60,6 @@ # Define the radius of holes in pcb pcb_hole_radius = 1 - # Create PCB Substrate sketch_substrate = Sketch() ( diff --git a/geometry-mechanical-dpf/02_mechanical.py b/geometry-mechanical-dpf/02_mechanical.py index 3ec34184..b318d6d9 100644 --- a/geometry-mechanical-dpf/02_mechanical.py +++ b/geometry-mechanical-dpf/02_mechanical.py @@ -116,23 +116,6 @@ def display_image(image_name): # mesh = Model.Mesh -# automatic_method = mesh.AddAutomaticMethod() -# NSall = ExtAPI.DataModel.Project.Model.NamedSelections.GetChildren[ -# Ansys.ACT.Automation.Mechanical.NamedSelection -# ](True) -# all_bodies = [i for i in NSall if i.Name == "all_bodies"][0] -# automatic_method.Location = all_bodies -# automatic_method.Method = MethodType.MultiZone - -# addsizing1 = mesh.AddSizing() -# all_bodies_except_board = [i for i in NSall if i.Name == "all_except_board"][0] -# addsizing1.Location = all_bodies_except_board -# addsizing1.ElementSize = Quantity(0.0009, "m") - -# addsizing2 = mesh.AddSizing() -# board = [i for i in NSall if i.Name == "substrate"][0] -# addsizing2.Location = board -# addsizing2.ElementSize = Quantity(0.002, "m") mesh.GenerateMesh() # Export mesh image @@ -145,7 +128,6 @@ def display_image(image_name): if GRAPHICS_BOOL: display_image("mesh.png") - # -- Analysis -- # # Steady state thermal analysis setup @@ -193,7 +175,6 @@ def display_image(image_name): # transient_solution.Solve(True) - # -- Save files and close mechanical -- # # Mechanical file (mechdb) contains results for each analysis diff --git a/geometry-mechanical-dpf/03_dpf.py b/geometry-mechanical-dpf/03_dpf.py index 008882c3..5d400c94 100644 --- a/geometry-mechanical-dpf/03_dpf.py +++ b/geometry-mechanical-dpf/03_dpf.py @@ -67,7 +67,6 @@ def find_files(directory, extension): # Result precision decimal_precision = 6 - # -- Steady state thermal results -- # # Create model From 6555e787c7b5d1c091c5543f240f0730b272d360 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 24 Jun 2024 08:54:23 -0500 Subject: [PATCH 24/25] update readme --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 698aa5ee..0199f93d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,15 @@ for every part of the simulation process. The available workflows are: - For geometry: Ansys SpaceClaim / Ansys Discovery / Ansys Geometry Service - For meshing: Ansys Fluent Meshing - For simulation: Ansys Fluent Solver +- [Geometry, mechanical and dpf](./geometry-mechanical-dpf): this workflow demonstrates how to + create a printed circuit board (PCB) geometry, mesh, run steady state and transient thermal analysis, + and post-process using dpf. The geometry generated is a simple PCB with multiple chips. + The exported CAD file (PMDB format) is then imported inside Ansys Mechanical + to run a steady-state thermal analysis followed by transient analysis. + All temperature results in different chips are displayed using dpf. + - For geometry: Ansys SpaceClaim / Ansys Discovery / Ansys Geometry Service + - For simulation: Ansys Mechanical + - For post-procesing: Ansys Data Processing Framework ## How to run the workflows From 438a9745d8d572e739237f899af4aca91fe0c4a0 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:56:25 +0200 Subject: [PATCH 25/25] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0199f93d..f79fc936 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,12 @@ for every part of the simulation process. The available workflows are: - For geometry: Ansys SpaceClaim / Ansys Discovery / Ansys Geometry Service - For meshing: Ansys Fluent Meshing - For simulation: Ansys Fluent Solver -- [Geometry, mechanical and dpf](./geometry-mechanical-dpf): this workflow demonstrates how to +- [Geometry, mechanical and post-processing](./geometry-mechanical-dpf): this workflow demonstrates how to create a printed circuit board (PCB) geometry, mesh, run steady state and transient thermal analysis, - and post-process using dpf. The geometry generated is a simple PCB with multiple chips. + and post-process using DPF. The geometry generated is a simple PCB with multiple chips. The exported CAD file (PMDB format) is then imported inside Ansys Mechanical to run a steady-state thermal analysis followed by transient analysis. - All temperature results in different chips are displayed using dpf. + All temperature results in different chips are displayed using DPF. The involved Ansys products are: - For geometry: Ansys SpaceClaim / Ansys Discovery / Ansys Geometry Service - For simulation: Ansys Mechanical - For post-procesing: Ansys Data Processing Framework