Skip to content

Commit 49634ef

Browse files
committed
geo import
1 parent f83f323 commit 49634ef

File tree

2 files changed

+126
-100
lines changed

2 files changed

+126
-100
lines changed

.github/workflows/geometry-mechanical-dpf.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ jobs:
177177
# ANSYS_WORKBENCH_LOGGING_CONSOLE: 0
178178
# ANSYS_WORKBENCH_LOGGING: 0
179179
ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 0
180+
PYTHONUNBUFFERED: 1
180181
run: |
181182
. /.venv/bin/activate
182183
xvfb-run mechanical-env python geometry-mechanical-dpf/wf_gmd_02_mechanical.py > pymechlogs${{ matrix.ansys-release }}.txt 2>&1 || true
@@ -237,6 +238,7 @@ jobs:
237238
with:
238239
name: geometry-mechanical-dpf-docs
239240
path: |
241+
outputs/
240242
doc/_build/
241243
doc/source/examples/geometry-mechanical-dpf/
242244
overwrite: true

geometry-mechanical-dpf/wf_gmd_02_mechanical.py

Lines changed: 124 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,36 @@ def display_image(image_name):
9797
# Import geometry which is generated with pyansys-geometry
9898
#
9999
geometry_path = Path(OUTPUT_DIR, "pcb.pmdb")
100-
geometry_import_group = Model.GeometryImportGroup
101-
geometry_import = geometry_import_group.AddGeometryImport()
102-
geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic
103-
geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()
104-
geometry_import_preferences.ProcessNamedSelections = True
105-
geometry_import.Import(str(geometry_path), geometry_import_format, geometry_import_preferences)
100+
101+
print("^" * 40)
102+
print("Importing geometry from:", geometry_path)
103+
print("^" * 40)
104+
105+
print("^" * 40)
106+
print("Importing string geometry from:", str(geometry_path))
107+
print("^" * 40)
108+
109+
try:
110+
geometry_path = Path(OUTPUT_DIR, "pcb.pmdb")
111+
geometry_import_group = Model.GeometryImportGroup
112+
geometry_import = geometry_import_group.AddGeometryImport()
113+
geometry_import_format = (
114+
Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic
115+
)
116+
geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()
117+
geometry_import_preferences.ProcessNamedSelections = True
118+
geometry_import_preferences.NamedSelectionKey = ""
119+
print("^" * 40)
120+
print("starting import...")
121+
print("^" * 40)
122+
123+
geometry_import.Import(str(geometry_path), geometry_import_format, geometry_import_preferences)
124+
print("geometry imported successfully.")
125+
except Exception as e:
126+
print(f"An error occurred during geometry import: with path {geometry_path}, error: {e}")
127+
finally:
128+
app.save_as(os.path.join(OUTPUT_DIR, "geo.mechdb"), overwrite=True)
129+
106130

107131
# Plot geometry
108132
if GRAPHICS_BOOL:
@@ -114,100 +138,100 @@ def display_image(image_name):
114138
# -----------------------
115139
#
116140

117-
ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS
118-
119-
# Create named selection for all bodies
120-
bodies = Model.Geometry.GetChildren(DataModelObjectCategory.Body, True)
121-
body_ids = [bd.GetGeoBody().Id for bd in bodies]
122-
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
123-
selection.Ids = body_ids
124-
ns1 = Model.AddNamedSelection()
125-
ns1.Name = "all_bodies"
126-
ns1.Location = selection
127-
128-
# Create named selection for all except substrate
129-
substrate_id = [bd.GetGeoBody().Id for bd in bodies if bd.Name.endswith("substrate")]
130-
except_substrate_id = list(set(body_ids) - set(substrate_id))
131-
132-
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
133-
selection.Ids = except_substrate_id
134-
ns2 = Model.AddNamedSelection()
135-
ns2.Name = "all_except_board"
136-
ns2.Location = selection
137-
138-
###############################################################################
139-
# Meshing
140-
# -------
141-
#
142-
mesh = Model.Mesh
143-
mesh.GenerateMesh()
144-
145-
# Export mesh image
146-
ExtAPI.Graphics.Camera.SetFit()
147-
ExtAPI.Graphics.ExportImage(
148-
os.path.join(OUTPUT_DIR, "mesh.png"), image_export_format, settings_720p
149-
)
150-
151-
# Display the mesh
152-
if GRAPHICS_BOOL:
153-
display_image("mesh.png")
154-
155-
156-
###############################################################################
157-
# Analysis
158-
# --------
159-
# Setup steady state thermal analysis
160-
161-
steady = Model.AddSteadyStateThermalAnalysis()
162-
transient = Model.AddTransientThermalAnalysis()
163-
164-
internal_heat_generation = steady.AddInternalHeatGeneration()
165-
NSall = ExtAPI.DataModel.Project.Model.NamedSelections.GetChildren[
166-
Ansys.ACT.Automation.Mechanical.NamedSelection
167-
](True)
168-
ic6 = [i for i in NSall if i.Name == "ic-6"][0]
169-
internal_heat_generation.Location = ic6
170-
internal_heat_generation.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, "W m^-1 m^-1 m^-1"))
171-
172-
all_bodies = [i for i in NSall if i.Name == "all_bodies"][0]
173-
convection = steady.AddConvection()
174-
convection.Location = all_bodies
175-
convection.FilmCoefficient.Output.DiscreteValues = [Quantity("5[W m^-2 C^-1]")]
176-
177-
steady_solution = steady.Solution
178-
temperature_result = steady_solution.AddTemperature()
179-
steady_solution.Solve(True)
180-
181-
# Transient analysis setup
182-
initial_condition = transient.InitialConditions[0]
183-
initial_condition.InitialTemperature = InitialTemperatureType.NonUniform
184-
initial_condition.InitialEnvironment = steady
185-
186-
transient_analysis_settings = transient.AnalysisSettings
187-
transient_analysis_settings.StepEndTime = Quantity(200, "sec")
188-
189-
internal_heat_generation2 = transient.AddInternalHeatGeneration()
190-
191-
ic1 = [i for i in NSall if i.Name == "ic-1"][0]
192-
internal_heat_generation2.Location = ic1
193-
internal_heat_generation2.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, "W m^-1 m^-1 m^-1"))
194-
195-
###############################################################################
196-
# Add result objects
197-
# ------------------
198-
#
199-
transient_solution = transient.Solution
200-
transient_temperature_result = transient_solution.AddTemperature()
201-
temperature_probe1 = transient_solution.AddTemperatureProbe()
202-
temperature_probe1.GeometryLocation = ic6
203-
temperature_probe2 = transient_solution.AddTemperatureProbe()
204-
temperature_probe2.GeometryLocation = ic1
205-
206-
###############################################################################
207-
# Solve
208-
# -----
209-
#
210-
transient_solution.Solve(True)
141+
# ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS
142+
143+
# # Create named selection for all bodies
144+
# bodies = Model.Geometry.GetChildren(DataModelObjectCategory.Body, True)
145+
# body_ids = [bd.GetGeoBody().Id for bd in bodies]
146+
# selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
147+
# selection.Ids = body_ids
148+
# ns1 = Model.AddNamedSelection()
149+
# ns1.Name = "all_bodies"
150+
# ns1.Location = selection
151+
152+
# # Create named selection for all except substrate
153+
# substrate_id = [bd.GetGeoBody().Id for bd in bodies if bd.Name.endswith("substrate")]
154+
# except_substrate_id = list(set(body_ids) - set(substrate_id))
155+
156+
# selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
157+
# selection.Ids = except_substrate_id
158+
# ns2 = Model.AddNamedSelection()
159+
# ns2.Name = "all_except_board"
160+
# ns2.Location = selection
161+
162+
# ###############################################################################
163+
# # Meshing
164+
# # -------
165+
# #
166+
# mesh = Model.Mesh
167+
# mesh.GenerateMesh()
168+
169+
# # Export mesh image
170+
# ExtAPI.Graphics.Camera.SetFit()
171+
# ExtAPI.Graphics.ExportImage(
172+
# os.path.join(OUTPUT_DIR, "mesh.png"), image_export_format, settings_720p
173+
# )
174+
175+
# # Display the mesh
176+
# if GRAPHICS_BOOL:
177+
# display_image("mesh.png")
178+
179+
180+
# ###############################################################################
181+
# # Analysis
182+
# # --------
183+
# # Setup steady state thermal analysis
184+
185+
# steady = Model.AddSteadyStateThermalAnalysis()
186+
# transient = Model.AddTransientThermalAnalysis()
187+
188+
# internal_heat_generation = steady.AddInternalHeatGeneration()
189+
# NSall = ExtAPI.DataModel.Project.Model.NamedSelections.GetChildren[
190+
# Ansys.ACT.Automation.Mechanical.NamedSelection
191+
# ](True)
192+
# ic6 = [i for i in NSall if i.Name == "ic-6"][0]
193+
# internal_heat_generation.Location = ic6
194+
# internal_heat_generation.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, "W m^-1 m^-1 m^-1"))
195+
196+
# all_bodies = [i for i in NSall if i.Name == "all_bodies"][0]
197+
# convection = steady.AddConvection()
198+
# convection.Location = all_bodies
199+
# convection.FilmCoefficient.Output.DiscreteValues = [Quantity("5[W m^-2 C^-1]")]
200+
201+
# steady_solution = steady.Solution
202+
# temperature_result = steady_solution.AddTemperature()
203+
# steady_solution.Solve(True)
204+
205+
# # Transient analysis setup
206+
# initial_condition = transient.InitialConditions[0]
207+
# initial_condition.InitialTemperature = InitialTemperatureType.NonUniform
208+
# initial_condition.InitialEnvironment = steady
209+
210+
# transient_analysis_settings = transient.AnalysisSettings
211+
# transient_analysis_settings.StepEndTime = Quantity(200, "sec")
212+
213+
# internal_heat_generation2 = transient.AddInternalHeatGeneration()
214+
215+
# ic1 = [i for i in NSall if i.Name == "ic-1"][0]
216+
# internal_heat_generation2.Location = ic1
217+
# internal_heat_generation2.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, "W m^-1 m^-1 m^-1"))
218+
219+
# ###############################################################################
220+
# # Add result objects
221+
# # ------------------
222+
# #
223+
# transient_solution = transient.Solution
224+
# transient_temperature_result = transient_solution.AddTemperature()
225+
# temperature_probe1 = transient_solution.AddTemperatureProbe()
226+
# temperature_probe1.GeometryLocation = ic6
227+
# temperature_probe2 = transient_solution.AddTemperatureProbe()
228+
# temperature_probe2.GeometryLocation = ic1
229+
230+
# ###############################################################################
231+
# # Solve
232+
# # -----
233+
# #
234+
# transient_solution.Solve(True)
211235

212236
###############################################################################
213237
# Save files and close Mechanical

0 commit comments

Comments
 (0)