@@ -96,13 +96,21 @@ def display_image(image_name):
9696# ---------------
9797# Import geometry which is generated with pyansys-geometry
9898#
99- 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 )
99+ try :
100+ geometry_path = Path (OUTPUT_DIR , "pcb.pmdb" )
101+ geometry_import_group = Model .GeometryImportGroup
102+ geometry_import = geometry_import_group .AddGeometryImport ()
103+ geometry_import_format = (
104+ Ansys .Mechanical .DataModel .Enums .GeometryImportPreference .Format .Automatic
105+ )
106+ geometry_import_preferences = Ansys .ACT .Mechanical .Utilities .GeometryImportPreferences ()
107+ geometry_import_preferences .ProcessNamedSelections = True
108+ geometry_import .Import (str (geometry_path ), geometry_import_format , geometry_import_preferences )
109+ except Exception as e :
110+ print (f"An error occurred during geometry import: with path { geometry_path } , error: { e } " )
111+ finally :
112+ app .save_as (os .path .join (OUTPUT_DIR , "geo.mechdb" ), overwrite = True )
113+
106114
107115# Plot geometry
108116if GRAPHICS_BOOL :
@@ -114,100 +122,100 @@ def display_image(image_name):
114122# -----------------------
115123#
116124
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 )
125+ # ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS
126+
127+ # # Create named selection for all bodies
128+ # bodies = Model.Geometry.GetChildren(DataModelObjectCategory.Body, True)
129+ # body_ids = [bd.GetGeoBody().Id for bd in bodies]
130+ # selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
131+ # selection.Ids = body_ids
132+ # ns1 = Model.AddNamedSelection()
133+ # ns1.Name = "all_bodies"
134+ # ns1.Location = selection
135+
136+ # # Create named selection for all except substrate
137+ # substrate_id = [bd.GetGeoBody().Id for bd in bodies if bd.Name.endswith("substrate")]
138+ # except_substrate_id = list(set(body_ids) - set(substrate_id))
139+
140+ # selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
141+ # selection.Ids = except_substrate_id
142+ # ns2 = Model.AddNamedSelection()
143+ # ns2.Name = "all_except_board"
144+ # ns2.Location = selection
145+
146+ # # ##############################################################################
147+ # # Meshing
148+ # # -------
149+ # #
150+ # mesh = Model.Mesh
151+ # mesh.GenerateMesh()
152+
153+ # # Export mesh image
154+ # ExtAPI.Graphics.Camera.SetFit()
155+ # ExtAPI.Graphics.ExportImage(
156+ # os.path.join(OUTPUT_DIR, "mesh.png"), image_export_format, settings_720p
157+ # )
158+
159+ # # Display the mesh
160+ # if GRAPHICS_BOOL:
161+ # display_image("mesh.png")
162+
163+
164+ # # ##############################################################################
165+ # # Analysis
166+ # # --------
167+ # # Setup steady state thermal analysis
168+
169+ # steady = Model.AddSteadyStateThermalAnalysis()
170+ # transient = Model.AddTransientThermalAnalysis()
171+
172+ # internal_heat_generation = steady.AddInternalHeatGeneration()
173+ # NSall = ExtAPI.DataModel.Project.Model.NamedSelections.GetChildren[
174+ # Ansys.ACT.Automation.Mechanical.NamedSelection
175+ # ](True)
176+ # ic6 = [i for i in NSall if i.Name == "ic-6"][0]
177+ # internal_heat_generation.Location = ic6
178+ # internal_heat_generation.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, "W m^-1 m^-1 m^-1"))
179+
180+ # all_bodies = [i for i in NSall if i.Name == "all_bodies"][0]
181+ # convection = steady.AddConvection()
182+ # convection.Location = all_bodies
183+ # convection.FilmCoefficient.Output.DiscreteValues = [Quantity("5[W m^-2 C^-1]")]
184+
185+ # steady_solution = steady.Solution
186+ # temperature_result = steady_solution.AddTemperature()
187+ # steady_solution.Solve(True)
188+
189+ # # Transient analysis setup
190+ # initial_condition = transient.InitialConditions[0]
191+ # initial_condition.InitialTemperature = InitialTemperatureType.NonUniform
192+ # initial_condition.InitialEnvironment = steady
193+
194+ # transient_analysis_settings = transient.AnalysisSettings
195+ # transient_analysis_settings.StepEndTime = Quantity(200, "sec")
196+
197+ # internal_heat_generation2 = transient.AddInternalHeatGeneration()
198+
199+ # ic1 = [i for i in NSall if i.Name == "ic-1"][0]
200+ # internal_heat_generation2.Location = ic1
201+ # internal_heat_generation2.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, "W m^-1 m^-1 m^-1"))
202+
203+ # # ##############################################################################
204+ # # Add result objects
205+ # # ------------------
206+ # #
207+ # transient_solution = transient.Solution
208+ # transient_temperature_result = transient_solution.AddTemperature()
209+ # temperature_probe1 = transient_solution.AddTemperatureProbe()
210+ # temperature_probe1.GeometryLocation = ic6
211+ # temperature_probe2 = transient_solution.AddTemperatureProbe()
212+ # temperature_probe2.GeometryLocation = ic1
213+
214+ # # ##############################################################################
215+ # # Solve
216+ # # -----
217+ # #
218+ # transient_solution.Solve(True)
211219
212220###############################################################################
213221# Save files and close Mechanical
0 commit comments