Skip to content

Commit

Permalink
DOC: update documentation d0ee6ea
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPasMue committed Nov 27, 2024
0 parents commit 41594c8
Show file tree
Hide file tree
Showing 181 changed files with 26,636 additions and 0 deletions.
Empty file added .nojekyll
Empty file.
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workflows.docs.pyansys.com
241 changes: 241 additions & 0 deletions _downloads/0a558143ee4cb586897ad4681c808fd3/wf_gmd_02_mechanical.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Preparing the environment\nThis section is only necessary for workflow runs and docs generation. It checks\nthe environment variables to determine which image to use for the mechanical service.\nIf you are running this script outside of a workflow, you can ignore this section.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"version = None\nif \"ANSYS_MECHANICAL_RELEASE\" in os.environ:\n image_tag = os.environ[\"ANSYS_MECHANICAL_RELEASE\"]\n version = int(image_tag.replace(\".\", \"\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"GRAPHICS_BOOL = False # Set to True to display the graphics\nOUTPUT_DIR = Path(Path(__file__).parent, \"outputs\") # Output directory"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Start a PyMechanical app\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"app = mech.App(version=version)\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()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configure graphics for image export\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import geometry\nImport geometry which is generated with pyansys-geometry\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"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()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create named selections\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Meshing\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"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\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Analysis\nSetup steady state thermal analysis\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"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\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add result objects\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solve\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"transient_solution.Solve(True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save files and close Mechanical\nMechanical file (mechdb) contains results for each analysis\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"app.save(os.path.join(OUTPUT_DIR, \"pcb.mechdb\"))\nproject_directory = ExtAPI.DataModel.Project.ProjectDirectory\napp.exit()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit 41594c8

Please sign in to comment.