Skip to content

Commit 1421037

Browse files
committed
DOC: update documentation b44b500
0 parents  commit 1421037

207 files changed

Lines changed: 35503 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.nojekyll

Whitespace-only changes.

CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workflows.docs.pyansys.com
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n\n# Mechanical - Thermal analysis\n\nThis examples performs meshing, steady-state and transient thermal analysis of PCB.\nObjective of this example is to study or examine resulting temperatures caused by\nthe heat developed in chips.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"import os\nfrom pathlib import Path\n\nimport ansys.mechanical.core as mech\nfrom matplotlib import image as mpimg\nfrom matplotlib import pyplot as plt"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"## Parameters for the script\nThe following parameters are used to control the script execution. You can\nmodify these parameters to suit your needs.\n\n\n"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {
32+
"collapsed": false
33+
},
34+
"outputs": [],
35+
"source": [
36+
"GRAPHICS_BOOL = False # Set to True to display the graphics\nOUTPUT_DIR = Path(Path(__file__).parent, \"outputs\") # Output directory"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"## Start a PyMechanical app\n\n\n"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"metadata": {
50+
"collapsed": false
51+
},
52+
"outputs": [],
53+
"source": [
54+
"app = mech.App()\napp.update_globals(globals())\nprint(app)\n\n\ndef display_image(image_name):\n plt.figure(figsize=(16, 9))\n plt.imshow(mpimg.imread(os.path.join(OUTPUT_DIR, image_name)))\n plt.xticks([])\n plt.yticks([])\n plt.axis(\"off\")\n plt.show()"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"## Configure graphics for image export\n\n\n"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {
68+
"collapsed": false
69+
},
70+
"outputs": [],
71+
"source": [
72+
"ExtAPI.Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)\nExtAPI.Graphics.Camera.SetFit()\nimage_export_format = GraphicsImageExportFormat.PNG\nsettings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()\nsettings_720p.Resolution = GraphicsResolutionType.EnhancedResolution\nsettings_720p.Background = GraphicsBackgroundType.White\nsettings_720p.Width = 1280\nsettings_720p.Height = 720\nsettings_720p.CurrentGraphicsDisplay = False"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"## Import geometry\nImport geometry which is generated with pyansys-geometry\n\n\n"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {
86+
"collapsed": false
87+
},
88+
"outputs": [],
89+
"source": [
90+
"geometry_path = Path(OUTPUT_DIR, \"pcb.pmdb\")\ngeometry_import_group = Model.GeometryImportGroup\ngeometry_import = geometry_import_group.AddGeometryImport()\ngeometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic\ngeometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()\ngeometry_import_preferences.ProcessNamedSelections = True\ngeometry_import.Import(str(geometry_path), geometry_import_format, geometry_import_preferences)\n\n# Plot geometry\nif GRAPHICS_BOOL:\n app.plot()"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"metadata": {},
96+
"source": [
97+
"## Create named selections\n\n\n"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {
104+
"collapsed": false
105+
},
106+
"outputs": [],
107+
"source": [
108+
"ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS\n\n# Create named selection for all bodies\nbodies = Model.Geometry.GetChildren(DataModelObjectCategory.Body, True)\nbody_ids = [bd.GetGeoBody().Id for bd in bodies]\nselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)\nselection.Ids = body_ids\nns1 = Model.AddNamedSelection()\nns1.Name = \"all_bodies\"\nns1.Location = selection\n\n# Create named selection for all except substrate\nsubstrate_id = [bd.GetGeoBody().Id for bd in bodies if bd.Name.endswith(\"substrate\")]\nexcept_substrate_id = list(set(body_ids) - set(substrate_id))\n\nselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)\nselection.Ids = except_substrate_id\nns2 = Model.AddNamedSelection()\nns2.Name = \"all_except_board\"\nns2.Location = selection"
109+
]
110+
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"## Meshing\n\n\n"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"metadata": {
122+
"collapsed": false
123+
},
124+
"outputs": [],
125+
"source": [
126+
"mesh = Model.Mesh\nmesh.GenerateMesh()\n\n# Export mesh image\nExtAPI.Graphics.Camera.SetFit()\nExtAPI.Graphics.ExportImage(\n os.path.join(OUTPUT_DIR, \"mesh.png\"), image_export_format, settings_720p\n)\n\n# Display the mesh\nif GRAPHICS_BOOL:\n display_image(\"mesh.png\")"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"metadata": {},
132+
"source": [
133+
"## Analysis\nSetup steady state thermal analysis\n\n"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {
140+
"collapsed": false
141+
},
142+
"outputs": [],
143+
"source": [
144+
"steady = Model.AddSteadyStateThermalAnalysis()\ntransient = Model.AddTransientThermalAnalysis()\n\ninternal_heat_generation = steady.AddInternalHeatGeneration()\nNSall = ExtAPI.DataModel.Project.Model.NamedSelections.GetChildren[\n Ansys.ACT.Automation.Mechanical.NamedSelection\n](True)\nic6 = [i for i in NSall if i.Name == \"ic-6\"][0]\ninternal_heat_generation.Location = ic6\ninternal_heat_generation.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, \"W m^-1 m^-1 m^-1\"))\n\nall_bodies = [i for i in NSall if i.Name == \"all_bodies\"][0]\nconvection = steady.AddConvection()\nconvection.Location = all_bodies\nconvection.FilmCoefficient.Output.DiscreteValues = [Quantity(\"5[W m^-2 C^-1]\")]\n\nsteady_solution = steady.Solution\ntemperature_result = steady_solution.AddTemperature()\nsteady_solution.Solve(True)\n\n# Transient analysis setup\ninitial_condition = transient.InitialConditions[0]\ninitial_condition.InitialTemperature = InitialTemperatureType.NonUniform\ninitial_condition.InitialEnvironment = steady\n\ntransient_analysis_settings = transient.AnalysisSettings\ntransient_analysis_settings.StepEndTime = Quantity(200, \"sec\")\n\ninternal_heat_generation2 = transient.AddInternalHeatGeneration()\n\nic1 = [i for i in NSall if i.Name == \"ic-1\"][0]\ninternal_heat_generation2.Location = ic1\ninternal_heat_generation2.Magnitude.Output.SetDiscreteValue(0, Quantity(5e7, \"W m^-1 m^-1 m^-1\"))"
145+
]
146+
},
147+
{
148+
"cell_type": "markdown",
149+
"metadata": {},
150+
"source": [
151+
"## Add result objects\n\n\n"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {
158+
"collapsed": false
159+
},
160+
"outputs": [],
161+
"source": [
162+
"transient_solution = transient.Solution\ntransient_temperature_result = transient_solution.AddTemperature()\ntemperature_probe1 = transient_solution.AddTemperatureProbe()\ntemperature_probe1.GeometryLocation = ic6\ntemperature_probe2 = transient_solution.AddTemperatureProbe()\ntemperature_probe2.GeometryLocation = ic1"
163+
]
164+
},
165+
{
166+
"cell_type": "markdown",
167+
"metadata": {},
168+
"source": [
169+
"## Solve\n\n\n"
170+
]
171+
},
172+
{
173+
"cell_type": "code",
174+
"execution_count": null,
175+
"metadata": {
176+
"collapsed": false
177+
},
178+
"outputs": [],
179+
"source": [
180+
"transient_solution.Solve(True)"
181+
]
182+
},
183+
{
184+
"cell_type": "markdown",
185+
"metadata": {},
186+
"source": [
187+
"## Save files and close Mechanical\nMechanical file (mechdb) contains results for each analysis\n\n\n"
188+
]
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": null,
193+
"metadata": {
194+
"collapsed": false
195+
},
196+
"outputs": [],
197+
"source": [
198+
"app.save(os.path.join(OUTPUT_DIR, \"pcb.mechdb\"))\nproject_directory = ExtAPI.DataModel.Project.ProjectDirectory\napp.exit()"
199+
]
200+
}
201+
],
202+
"metadata": {
203+
"kernelspec": {
204+
"display_name": "Python 3",
205+
"language": "python",
206+
"name": "python3"
207+
},
208+
"language_info": {
209+
"codemirror_mode": {
210+
"name": "ipython",
211+
"version": 3
212+
},
213+
"file_extension": ".py",
214+
"mimetype": "text/x-python",
215+
"name": "python",
216+
"nbconvert_exporter": "python",
217+
"pygments_lexer": "ipython3",
218+
"version": "3.12.9"
219+
}
220+
},
221+
"nbformat": 4,
222+
"nbformat_minor": 0
223+
}

0 commit comments

Comments
 (0)