Note
Go to the end to download the full example code.
Remote & Embedding Example#
This code, which uses the same example, first demonstrates how to use a remote session and then demonstrates how to use an embedding instance.
Remote Session#
Download required files#
Download the required files. Print the file paths for the geometry file and script file.
import os
from ansys.mechanical.core import launch_mechanical
from ansys.mechanical.core.examples import download_file
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding")
print(f"Downloaded the geometry file to: {geometry_path}")
script_file_path = download_file("remote_script.py", "pymechanical", "embedding")
print(f"Downloaded the script file to: {script_file_path}")
Downloaded the geometry file to: /github/home/.local/share/ansys_mechanical_core/examples/Valve.pmdb
Downloaded the script file to: /github/home/.local/share/ansys_mechanical_core/examples/remote_script.py
Launch Mechanical#
Launch a new Mechanical session in batch, setting cleanup_on_exit
to
False
. To close this Mechanical session when finished, this example
must call the mechanical.exit()
method.
import os
from ansys.mechanical.core import launch_mechanical
# Launch mechanical
mechanical = launch_mechanical(batch=True, loglevel="DEBUG")
print(mechanical)
Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44
Initialize variable for workflow#
Set the part_file_path
variable on the server for later use.
Make this variable compatible for Windows, Linux, and Docker containers.
project_directory = mechanical.project_directory
print(f"project directory = {project_directory}")
# Upload the file to the project directory.
mechanical.upload(file_name=geometry_path, file_location_destination=project_directory)
# Build the path relative to project directory.
base_name = os.path.basename(geometry_path)
combined_path = os.path.join(project_directory, base_name)
part_file_path = combined_path.replace("\\", "\\\\")
mechanical.run_python_script(f"part_file_path='{part_file_path}'")
# Verify the path
result = mechanical.run_python_script("part_file_path")
print(f"part_file_path on server: {result}")
project directory = /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/
Uploading Valve.pmdb to dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/.: 0%| | 0.00/774k [00:00<?, ?B/s]
Uploading Valve.pmdb to dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/.: 100%|██████████| 774k/774k [00:00<00:00, 300MB/s]
part_file_path on server: /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/Valve.pmdb
Run mechanical automation script#
Run remote_script.py in the mechanical remote session.
mechanical.run_python_script_from_file(script_file_path)
''
Get list of generated files#
list_files = mechanical.list_files()
for file in list_files:
print(file)
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file.mechdb
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/Total Deformation.txt
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/Equivalent Stress.txt
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/.mech_lock
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.cnd
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/MatML.xml
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/CAERep.xml
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.aapresults
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/CAERepOutput.xml
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.mntr
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/solve.out
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.DSP
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.rst
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/ds.dat
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file0.err
Write the file contents to console#
Download files back to local working directory#
dest_dir = "download"
dest_dir = os.path.join(os.getcwd(), dest_dir)
for file in list_files:
downloaded = mechanical.download(file, target_dir=dest_dir)
if file.endswith(".out"):
print("contents of ", downloaded, " : ")
write_file_contents_to_console(downloaded[0], number_lines=-1)
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file.mechdb to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.mechdb: 0%| | 0.00/7.31M [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file.mechdb to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.mechdb: 100%|██████████| 7.31M/7.31M [00:00<00:00, 224MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/Total Deformation.txt to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/Total Deformation.txt: 0%| | 0.00/483k [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/Total Deformation.txt to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/Total Deformation.txt: 100%|██████████| 483k/483k [00:00<00:00, 681MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/Equivalent Stress.txt to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/Equivalent Stress.txt: 0%| | 0.00/485k [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/Equivalent Stress.txt to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/Equivalent Stress.txt: 100%|██████████| 485k/485k [00:00<00:00, 443MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/.mech_lock to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/.mech_lock: 0%| | 0.00/17.0 [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/.mech_lock to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/.mech_lock: 100%|██████████| 17.0/17.0 [00:00<00:00, 63.4kB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.cnd to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.cnd: 0%| | 0.00/5.48k [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.cnd to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.cnd: 100%|██████████| 5.48k/5.48k [00:00<00:00, 26.3MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/MatML.xml to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/MatML.xml: 0%| | 0.00/23.3k [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/MatML.xml to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/MatML.xml: 100%|██████████| 23.3k/23.3k [00:00<00:00, 83.0MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/CAERep.xml to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/CAERep.xml: 0%| | 0.00/28.1k [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/CAERep.xml to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/CAERep.xml: 100%|██████████| 28.1k/28.1k [00:00<00:00, 171MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.aapresults to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.aapresults: 0%| | 0.00/110 [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.aapresults to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.aapresults: 100%|██████████| 110/110 [00:00<00:00, 152kB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/CAERepOutput.xml to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/CAERepOutput.xml: 0%| | 0.00/862 [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/CAERepOutput.xml to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/CAERepOutput.xml: 100%|██████████| 862/862 [00:00<00:00, 3.44MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.mntr to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.mntr: 0%| | 0.00/809 [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.mntr to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.mntr: 100%|██████████| 809/809 [00:00<00:00, 3.70MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/solve.out to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/solve.out: 0%| | 0.00/36.0k [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/solve.out to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/solve.out: 100%|██████████| 36.0k/36.0k [00:00<00:00, 178MB/s]
contents of ['/__w/pymechanical/pymechanical/examples/embedding_n_remote/download/solve.out'] :
Ansys Mechanical Enterprise
*------------------------------------------------------------------*
| |
| W E L C O M E T O T H E A N S Y S (R) P R O G R A M |
| |
*------------------------------------------------------------------*
***************************************************************
* ANSYS MAPDL 2025 R1 LEGAL NOTICES *
***************************************************************
* *
* Copyright 1971-2025 Ansys, Inc. All rights reserved. *
* Unauthorized use, distribution or duplication is *
* prohibited. *
* *
* Ansys is a registered trademark of Ansys, Inc. or its *
* subsidiaries in the United States or other countries. *
* See the Ansys, Inc. online documentation or the Ansys, Inc. *
* documentation CD or online help for the complete Legal *
* Notice. *
* *
***************************************************************
* *
* THIS ANSYS SOFTWARE PRODUCT AND PROGRAM DOCUMENTATION *
* INCLUDE TRADE SECRETS AND CONFIDENTIAL AND PROPRIETARY *
* PRODUCTS OF ANSYS, INC., ITS SUBSIDIARIES, OR LICENSORS. *
* The software products and documentation are furnished by *
* Ansys, Inc. or its subsidiaries under a software license *
* agreement that contains provisions concerning *
* non-disclosure, copying, length and nature of use, *
* compliance with exporting laws, warranties, disclaimers, *
* limitations of liability, and remedies, and other *
* provisions. The software products and documentation may be *
* used, disclosed, transferred, or copied only in accordance *
* with the terms and conditions of that software license *
* agreement. *
* *
* Ansys, Inc. is a UL registered *
* ISO 9001:2015 company. *
* *
***************************************************************
* *
* This product is subject to U.S. laws governing export and *
* re-export. *
* *
* For U.S. Government users, except as specifically granted *
* by the Ansys, Inc. software license agreement, the use, *
* duplication, or disclosure by the United States Government *
* is subject to restrictions stated in the Ansys, Inc. *
* software license agreement and FAR 12.212 (for non-DOD *
* licenses). *
* *
***************************************************************
*------------------------------------------------------------------*
| Ansys Product Improvement |
| |
| Ansys Product Improvement Program helps improve Ansys |
| products. Participating in this program is like filling out a |
| survey. Without interrupting your work, the software reports |
| anonymous usage information such as errors, machine and |
| solver statistics, features used, etc. to Ansys. We never |
| use the data to identify or contact you. |
| The data does NOT contain: |
| - Any personally identifiable information including names, |
| IP addresses, file names, part names, etc. |
| - Any information about your geometry or design specific |
| inputs. |
| You can stop participation at any time. To change your |
| selection go to Help >> Ansys Product Improvement Program |
| in the GUI. |
| For more information about the Ansys Privacy Policy, please |
| check: http://www.ansys.com/privacy |
| |
*------------------------------------------------------------------*
2025 R1
Point Releases and Patches installed:
Ansys, Inc. License Manager 2025 R1
LS-DYNA 2025 R1
Core WB Files 2025 R1
Mechanical Products 2025 R1
***** MAPDL COMMAND LINE ARGUMENTS *****
BATCH MODE REQUESTED (-b) = NOLIST
INPUT FILE COPY MODE (-c) = COPY
DISTRIBUTED MEMORY PARALLEL REQUESTED
4 PARALLEL PROCESSES REQUESTED WITH SINGLE THREAD PER PROCESS
TOTAL OF 4 CORES REQUESTED
INPUT FILE NAME = /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural/dummy.dat
OUTPUT FILE NAME = /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural/solve.out
START-UP FILE MODE = NOREAD
STOP FILE MODE = NOREAD
RELEASE= 2025 R1 BUILD= 25.1 UP20241202 VERSION=LINUX x64
CURRENT JOBNAME=file0 20:14:06 MAR 10, 2025 CP= 0.239
PARAMETER _DS_PROGRESS = 999.0000000
/INPUT FILE= ds.dat LINE= 0
*** NOTE *** CP = 0.344 TIME= 20:14:06
The /CONFIG,NOELDB command is not valid in a distributed memory
parallel solution. Command is ignored.
*GET _WALLSTRT FROM ACTI ITEM=TIME WALL VALUE= 20.2350000
TITLE=
--Static Structural
ACT Extensions:
LSDYNA, 2025.1
5f463412-bd3e-484b-87e7-cbc0a665e474, wbex
SET PARAMETER DIMENSIONS ON _WB_PROJECTSCRATCH_DIR
TYPE=STRI DIMENSIONS= 248 1 1
PARAMETER _WB_PROJECTSCRATCH_DIR(1) = /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural/
SET PARAMETER DIMENSIONS ON _WB_SOLVERFILES_DIR
TYPE=STRI DIMENSIONS= 248 1 1
PARAMETER _WB_SOLVERFILES_DIR(1) = /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural/
SET PARAMETER DIMENSIONS ON _WB_USERFILES_DIR
TYPE=STRI DIMENSIONS= 248 1 1
PARAMETER _WB_USERFILES_DIR(1) = /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/UserFiles/
--- Data in consistent MKS units. See Solving Units in the help system for more
MKS UNITS SPECIFIED FOR INTERNAL
LENGTH (l) = METER (M)
MASS (M) = KILOGRAM (KG)
TIME (t) = SECOND (SEC)
TEMPERATURE (T) = CELSIUS (C)
TOFFSET = 273.0
CHARGE (Q) = COULOMB
FORCE (f) = NEWTON (N) (KG-M/SEC2)
HEAT = JOULE (N-M)
PRESSURE = PASCAL (NEWTON/M**2)
ENERGY (W) = JOULE (N-M)
POWER (P) = WATT (N-M/SEC)
CURRENT (i) = AMPERE (COULOMBS/SEC)
CAPACITANCE (C) = FARAD
INDUCTANCE (L) = HENRY
MAGNETIC FLUX = WEBER
RESISTANCE (R) = OHM
ELECTRIC POTENTIAL = VOLT
INPUT UNITS ARE ALSO SET TO MKS
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2025 R1 25.1 ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 20:14:06 MAR 10, 2025 CP= 0.347
--Static Structural
***** MAPDL ANALYSIS DEFINITION (PREP7) *****
*********** Nodes for the whole assembly ***********
*********** Elements for Body 1 'Connector\Solid1' ***********
*********** Elements for Body 2 'Right_elbow\Solid1' ***********
*********** Elements for Body 3 'Left_elbow\Solid1' ***********
*********** Send User Defined Coordinate System(s) ***********
*********** Set Reference Temperature ***********
*********** Send Materials ***********
*********** Create Contact "Contact Region" ***********
Real Constant Set For Above Contact Is 5 & 4
*********** Create Contact "Contact Region 2" ***********
Real Constant Set For Above Contact Is 7 & 6
*********** Send Named Selection as Node Component ***********
*********** Send Named Selection as Node Component ***********
*********** Send Named Selection as Node Component ***********
*********** Fixed Supports ***********
********* Frictionless Supports X *********
********* Frictionless Supports Z *********
*********** Node Rotations ***********
*********** Define Pressure Using Surface Effect Elements "Pressure" **********
***** ROUTINE COMPLETED ***** CP = 0.769
--- Number of total nodes = 26882
--- Number of contact elements = 3294
--- Number of spring elements = 0
--- Number of bearing elements = 0
--- Number of solid elements = 14427
--- Number of condensed parts = 0
--- Number of total elements = 17721
*GET _WALLBSOL FROM ACTI ITEM=TIME WALL VALUE= 20.2350000
****************************************************************************
************************* SOLUTION ********************************
****************************************************************************
***** MAPDL SOLUTION ROUTINE *****
PERFORM A STATIC ANALYSIS
THIS WILL BE A NEW ANALYSIS
PARAMETER _THICKRATIO = 0.3330000000
USE SPARSE MATRIX DIRECT SOLVER
CONTACT INFORMATION PRINTOUT LEVEL 1
CHECK INITIAL OPEN/CLOSED STATUS OF SELECTED CONTACT ELEMENTS
AND LIST DETAILED CONTACT PAIR INFORMATION
SPLIT CONTACT SURFACES AT SOLVE PHASE
NUMBER OF SPLITTING TBD BY PROGRAM
DO NOT COMBINE ELEMENT MATRIX FILES (.emat) AFTER DISTRIBUTED PARALLEL SOLUTION
DO NOT COMBINE ELEMENT SAVE DATA FILES (.esav) AFTER DISTRIBUTED PARALLEL SOLUTION
NLDIAG: Nonlinear diagnostics CONT option is set to ON.
Writing frequency : each ITERATION.
DO NOT SAVE ANY RESTART FILES AT ALL
****************************************************
******************* SOLVE FOR LS 1 OF 1 ****************
SELECT FOR ITEM=TYPE COMPONENT=
IN RANGE 8 TO 8 STEP 1
1694 ELEMENTS (OF 17721 DEFINED) SELECTED BY ESEL COMMAND.
SELECT ALL NODES HAVING ANY ELEMENT IN ELEMENT SET.
3556 NODES (OF 26882 DEFINED) SELECTED FROM
1694 SELECTED ELEMENTS BY NSLE COMMAND.
GENERATE SURFACE LOAD PRES ON SURFACE DEFINED BY ALL SELECTED NODES
SET ACCORDING TO TABLE PARAMETER = _LOADVARI56
NUMBER OF PRES ELEMENT FACE LOADS STORED = 1694
ALL SELECT FOR ITEM=NODE COMPONENT=
IN RANGE 1 TO 26882 STEP 1
26882 NODES (OF 26882 DEFINED) SELECTED BY NSEL COMMAND.
ALL SELECT FOR ITEM=ELEM COMPONENT=
IN RANGE 1 TO 25061 STEP 1
17721 ELEMENTS (OF 17721 DEFINED) SELECTED BY ESEL COMMAND.
ALL SELECT FOR ITEM=ELEM COMPONENT=
IN RANGE 1 TO 25061 STEP 1
17721 ELEMENTS (OF 17721 DEFINED) SELECTED BY ESEL COMMAND.
PRINTOUT RESUMED BY /GOP
USE 1 SUBSTEPS INITIALLY THIS LOAD STEP FOR ALL DEGREES OF FREEDOM
FOR AUTOMATIC TIME STEPPING:
USE 1 SUBSTEPS AS A MAXIMUM
USE 1 SUBSTEPS AS A MINIMUM
TIME= 1.0000
ERASE THE CURRENT DATABASE OUTPUT CONTROL TABLE.
WRITE ALL ITEMS TO THE DATABASE WITH A FREQUENCY OF NONE
FOR ALL APPLICABLE ENTITIES
WRITE NSOL ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
WRITE RSOL ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
WRITE EANG ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
WRITE ETMP ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
WRITE VENG ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
WRITE STRS ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
WRITE EPEL ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
WRITE EPPL ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
WRITE CONT ITEMS TO THE DATABASE WITH A FREQUENCY OF ALL
FOR ALL APPLICABLE ENTITIES
*GET ANSINTER_ FROM ACTI ITEM=INT VALUE= 0.00000000
*IF ANSINTER_ ( = 0.00000 ) NE
0 ( = 0.00000 ) THEN
*ENDIF
*** NOTE *** CP = 0.943 TIME= 20:14:06
The automatic domain decomposition logic has selected the MESH domain
decomposition method with 4 processes per solution.
***** MAPDL SOLVE COMMAND *****
*** WARNING *** CP = 1.030 TIME= 20:14:06
Element shape checking is currently inactive. Issue SHPP,ON or
SHPP,WARN to reactivate, if desired.
*** NOTE *** CP = 1.139 TIME= 20:14:06
The model data was checked and warning messages were found.
Please review output or errors file (
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural/fil
le0.err ) for these warning messages.
*** SELECTION OF ELEMENT TECHNOLOGIES FOR APPLICABLE ELEMENTS ***
--- GIVE SUGGESTIONS AND RESET THE KEY OPTIONS ---
ELEMENT TYPE 1 IS SOLID187. IT IS NOT ASSOCIATED WITH FULLY INCOMPRESSIBLE
HYPERELASTIC MATERIALS. NO SUGGESTION IS AVAILABLE AND NO RESETTING IS NEEDED.
ELEMENT TYPE 2 IS SOLID187. IT IS NOT ASSOCIATED WITH FULLY INCOMPRESSIBLE
HYPERELASTIC MATERIALS. NO SUGGESTION IS AVAILABLE AND NO RESETTING IS NEEDED.
ELEMENT TYPE 3 IS SOLID187. IT IS NOT ASSOCIATED WITH FULLY INCOMPRESSIBLE
HYPERELASTIC MATERIALS. NO SUGGESTION IS AVAILABLE AND NO RESETTING IS NEEDED.
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2025 R1 25.1 ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 20:14:06 MAR 10, 2025 CP= 1.151
--Static Structural
S O L U T I O N O P T I O N S
PROBLEM DIMENSIONALITY. . . . . . . . . . . . .3-D
DEGREES OF FREEDOM. . . . . . UX UY UZ
ANALYSIS TYPE . . . . . . . . . . . . . . . . .STATIC (STEADY-STATE)
OFFSET TEMPERATURE FROM ABSOLUTE ZERO . . . . . 273.15
EQUATION SOLVER OPTION. . . . . . . . . . . . .SPARSE
GLOBALLY ASSEMBLED MATRIX . . . . . . . . . . .SYMMETRIC
*** WARNING *** CP = 1.193 TIME= 20:14:06
Material number 8 (used by element 23368) should normally have at least
one MP or one TB type command associated with it. Output of energy by
material may not be available.
*** NOTE *** CP = 1.251 TIME= 20:14:06
The step data was checked and warning messages were found.
Please review output or errors file (
/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural/fil
le0.err ) for these warning messages.
*** NOTE *** CP = 1.251 TIME= 20:14:06
The conditions for direct assembly have been met. No .emat or .erot
files will be produced.
TRIM CONTACT/TARGET SURFACE
START TRIMMING SMALL/BONDED CONTACT PAIRS FOR DMP RUN.
400 CONTACT ELEMENTS & 400 TARGET ELEMENTS ARE DELETED DUE TO TRIMMING LOGIC.
2 CONTACT PAIRS ARE REMOVED.
CHECK INITIAL OPEN/CLOSED STATUS OF SELECTED CONTACT ELEMENTS
AND LIST DETAILED CONTACT PAIR INFORMATION
*** NOTE *** CP = 2.458 TIME= 20:14:07
The maximum number of contact elements in any single contact pair is
200, which is smaller than the optimal domain size of 926 elements for
the given number of CPU domains (4). Therefore, no contact pairs are
being split by the CNCH,DMP logic.
*** NOTE *** CP = 2.930 TIME= 20:14:07
Deformable-deformable contact pair identified by real constant set 5
and contact element type 4 has been set up.
Auto surface constraint is built
Contact algorithm: MPC based approach
*** NOTE *** CP = 2.930 TIME= 20:14:07
Contact related postprocess items (ETABLE, pressure ...) are not
available.
Contact detection at: nodal point (normal to target surface)
MPC will be built internally to handle bonded contact.
Average contact surface length 0.14033E-01
Average contact pair depth 0.82697E-02
Average target surface length 0.13762E-01
Default pinball region factor PINB 0.25000
The resulting pinball region 0.20674E-02
Default target edge extension factor TOLS 2.0000
Initial penetration/gap is excluded.
Bonded contact (always) is defined.
*** NOTE *** CP = 2.931 TIME= 20:14:07
Max. Initial penetration 8.326672685E-17 was detected between contact
element 22262 and target element 21953.
****************************************
*** NOTE *** CP = 2.931 TIME= 20:14:07
Deformable-deformable contact pair identified by real constant set 7
and contact element type 6 has been set up.
Auto surface constraint is built
Contact algorithm: MPC based approach
*** NOTE *** CP = 2.931 TIME= 20:14:07
Contact related postprocess items (ETABLE, pressure ...) are not
available.
Contact detection at: nodal point (normal to target surface)
MPC will be built internally to handle bonded contact.
Average contact surface length 0.14121E-01
Average contact pair depth 0.81425E-02
Average target surface length 0.13762E-01
Default pinball region factor PINB 0.25000
The resulting pinball region 0.20356E-02
Default target edge extension factor TOLS 2.0000
Initial penetration/gap is excluded.
Bonded contact (always) is defined.
*** NOTE *** CP = 2.931 TIME= 20:14:07
Max. Initial penetration 8.326672685E-17 was detected between contact
element 22977 and target element 22681.
****************************************
D I S T R I B U T E D D O M A I N D E C O M P O S E R
...Number of elements: 16921
...Number of nodes: 26882
...Decompose to 4 CPU domains
...Element load balance ratio = 1.020
L O A D S T E P O P T I O N S
LOAD STEP NUMBER. . . . . . . . . . . . . . . . 1
TIME AT END OF THE LOAD STEP. . . . . . . . . . 1.0000
NUMBER OF SUBSTEPS. . . . . . . . . . . . . . . 1
STEP CHANGE BOUNDARY CONDITIONS . . . . . . . . NO
PRINT OUTPUT CONTROLS . . . . . . . . . . . . .NO PRINTOUT
DATABASE OUTPUT CONTROLS
ITEM FREQUENCY COMPONENT
ALL NONE
NSOL ALL
RSOL ALL
EANG ALL
ETMP ALL
VENG ALL
STRS ALL
EPEL ALL
EPPL ALL
CONT ALL
SOLUTION MONITORING INFO IS WRITTEN TO FILE= file.mntr
*** NOTE *** CP = 4.029 TIME= 20:14:07
Deformable-deformable contact pair identified by real constant set 5
and contact element type 4 has been set up.
Auto surface constraint is built
Contact algorithm: MPC based approach
*** NOTE *** CP = 4.030 TIME= 20:14:07
Contact related postprocess items (ETABLE, pressure ...) are not
available.
Contact detection at: nodal point (normal to target surface)
MPC will be built internally to handle bonded contact.
Average contact surface length 0.14033E-01
Average contact pair depth 0.82697E-02
Average target surface length 0.13762E-01
Default pinball region factor PINB 0.25000
The resulting pinball region 0.20674E-02
Default target edge extension factor TOLS 2.0000
Initial penetration/gap is excluded.
Bonded contact (always) is defined.
*** NOTE *** CP = 4.030 TIME= 20:14:07
Max. Initial penetration 8.326672685E-17 was detected between contact
element 22262 and target element 21953.
****************************************
The FEA model contains 0 external CE equations and 2829 internal CE
equations.
*************************************************
SUMMARY FOR CONTACT PAIR IDENTIFIED BY REAL CONSTANT SET 5
Max. Penetration of 0 has been detected between contact element 22168
and target element 21830.
Max. Geometrical gap of 8.326672685E-17 has been detected between
contact element 22235 and target element 21774.
Max. Geometrical penetration of -8.326672685E-17 has been detected
between contact element 22235 and target element 21774.
For total 200 contact elements, there are 200 elements are in contact.
There are 200 elements are in sticking.
Max. Pinball distance 2.067419789E-03.
One of the contact searching regions contains at least 20 target
elements.
*************************************************
*********** PRECISE MASS SUMMARY ***********
TOTAL RIGID BODY MASS MATRIX ABOUT ORIGIN
Translational mass | Coupled translational/rotational mass
138.29 0.0000 0.0000 | 0.0000 -56.537 30.296
0.0000 138.29 0.0000 | 56.537 0.0000 0.73844E-02
0.0000 0.0000 138.29 | -30.296 -0.73844E-02 0.0000
------------------------------------------ | ------------------------------------------
| Rotational mass (inertia)
| 31.211 0.16359E-02 0.31000E-02
| 0.16359E-02 27.754 -12.386
| 0.31000E-02 -12.386 11.103
TOTAL MASS = 138.29
The mass principal axes coincide with the global Cartesian axes
CENTER OF MASS (X,Y,Z)= 0.53397E-04 -0.21907 -0.40882
TOTAL INERTIA ABOUT CENTER OF MASS
1.4604 0.18127E-04 0.81110E-04
0.18127E-04 4.6403 0.19281E-05
0.81110E-04 0.19281E-05 4.4656
The inertia principal axes coincide with the global Cartesian axes
*** MASS SUMMARY BY ELEMENT TYPE ***
TYPE MASS
1 100.182
2 19.0548
3 19.0556
Range of element maximum matrix coefficients in global coordinates
Maximum = 2.93408494E+10 at element 11441.
Minimum = 518803319 at element 2355.
*** ELEMENT MATRIX FORMULATION TIMES
TYPE NUMBER ENAME TOTAL CP AVE CP
1 8724 SOLID187 0.430 0.000049
2 2759 SOLID187 0.137 0.000050
3 2944 SOLID187 0.150 0.000051
4 200 CONTA174 0.046 0.000231
5 200 TARGE170 0.001 0.000004
6 200 CONTA174 0.047 0.000234
7 200 TARGE170 0.001 0.000004
8 1694 SURF154 0.058 0.000034
Time at end of element matrix formulation CP = 4.39649105.
DISTRIBUTED SPARSE MATRIX DIRECT SOLVER.
Number of equations = 76728, Maximum wavefront = 465
Memory allocated on only this MPI rank (rank 0)
-------------------------------------------------------------------
Equation solver memory allocated = 104.604 MB
Equation solver memory required for in-core mode = 100.392 MB
Equation solver memory required for out-of-core mode = 43.231 MB
Total (solver and non-solver) memory allocated = 830.139 MB
Total memory summed across all MPI ranks on this machines
-------------------------------------------------------------------
Equation solver memory allocated = 419.477 MB
Equation solver memory required for in-core mode = 402.170 MB
Equation solver memory required for out-of-core mode = 158.276 MB
Total (solver and non-solver) memory allocated = 2176.790 MB
*** NOTE *** CP = 4.595 TIME= 20:14:08
The Distributed Sparse Matrix Solver is currently running in the
in-core memory mode. This memory mode uses the most amount of memory
in order to avoid using the hard drive as much as possible, which most
often results in the fastest solution time. This mode is recommended
if enough physical memory is present to accommodate all of the solver
data.
curEqn= 19193 totEqn= 19193 Job CP sec= 4.737
Factor Done= 100% Factor Wall sec= 0.263 rate= 20.6 GFlops
Distributed sparse solver maximum pivot= 2.775534833E+10 at node 3047
UX.
Distributed sparse solver minimum pivot= 243125111 at node 20937 UY.
Distributed sparse solver minimum pivot in absolute value= 243125111 at
node 20937 UY.
*** ELEMENT RESULT CALCULATION TIMES
TYPE NUMBER ENAME TOTAL CP AVE CP
1 8724 SOLID187 0.380 0.000044
2 2759 SOLID187 0.127 0.000046
3 2944 SOLID187 0.127 0.000043
4 200 CONTA174 0.004 0.000021
6 200 CONTA174 0.004 0.000019
8 1694 SURF154 0.046 0.000027
*** NODAL LOAD CALCULATION TIMES
TYPE NUMBER ENAME TOTAL CP AVE CP
1 8724 SOLID187 0.139 0.000016
2 2759 SOLID187 0.046 0.000017
3 2944 SOLID187 0.046 0.000015
4 200 CONTA174 0.001 0.000003
6 200 CONTA174 0.001 0.000003
8 1694 SURF154 0.006 0.000004
*** LOAD STEP 1 SUBSTEP 1 COMPLETED. CUM ITER = 1
*** TIME = 1.00000 TIME INC = 1.00000 NEW TRIANG MATRIX
*** MAPDL BINARY FILE STATISTICS
BUFFER SIZE USED= 16384
4.875 MB WRITTEN ON ELEMENT SAVED DATA FILE: file0.esav
12.688 MB WRITTEN ON ASSEMBLED MATRIX FILE: file0.full
2.938 MB WRITTEN ON RESULTS FILE: file0.rst
*************** Write FE CONNECTORS *********
WRITE OUT CONSTRAINT EQUATIONS TO FILE= file.ce
****************************************************
*************** FINISHED SOLVE FOR LS 1 *************
*GET _WALLASOL FROM ACTI ITEM=TIME WALL VALUE= 20.2355556
PRINTOUT RESUMED BY /GOP
FINISH SOLUTION PROCESSING
***** ROUTINE COMPLETED ***** CP = 5.822
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2025 R1 25.1 ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 20:14:09 MAR 10, 2025 CP= 5.831
--Static Structural
***** MAPDL RESULTS INTERPRETATION (POST1) *****
*** NOTE *** CP = 5.831 TIME= 20:14:09
Reading results into the database (SET command) will update the current
displacement and force boundary conditions in the database with the
values from the results file for that load set. Note that any
subsequent solutions will use these values unless action is taken to
either SAVE the current values or not overwrite them (/EXIT,NOSAVE).
Set Encoding of XML File to:ISO-8859-1
Set Output of XML File to:
PARM, , , , , , , , , , , ,
, , , , , , ,
DATABASE WRITTEN ON FILE parm.xml
EXIT THE MAPDL POST1 DATABASE PROCESSOR
***** ROUTINE COMPLETED ***** CP = 5.835
PRINTOUT RESUMED BY /GOP
*GET _WALLDONE FROM ACTI ITEM=TIME WALL VALUE= 20.2358333
PARAMETER _PREPTIME = 0.000000000
PARAMETER _SOLVTIME = 2.000000000
PARAMETER _POSTTIME = 1.000000000
PARAMETER _TOTALTIM = 3.000000000
*GET _DLBRATIO FROM ACTI ITEM=SOLU DLBR VALUE= 1.02028986
*GET _COMBTIME FROM ACTI ITEM=SOLU COMB VALUE= 0.594620391E-01
*GET _SSMODE FROM ACTI ITEM=SOLU SSMM VALUE= 2.00000000
*GET _NDOFS FROM ACTI ITEM=SOLU NDOF VALUE= 76728.0000
*GET _SOL_END_TIME FROM ACTI ITEM=SET TIME VALUE= 1.00000000
*IF _sol_end_time ( = 1.00000 ) EQ
1.000000 ( = 1.00000 ) THEN
/FCLEAN COMMAND REMOVING ALL LOCAL FILES
*ENDIF
--- Total number of nodes = 26882
--- Total number of elements = 16921
--- Element load balance ratio = 1.02028986
--- Time to combine distributed files = 5.94620391E-02
--- Sparse memory mode = 2
--- Number of DOF = 76728
EXIT MAPDL WITHOUT SAVING DATABASE
NUMBER OF WARNING MESSAGES ENCOUNTERED= 2
NUMBER OF ERROR MESSAGES ENCOUNTERED= 0
+--------------------- M A P D L S T A T I S T I C S ------------------------+
Release: 2025 R1 Build: 25.1 Update: UP20241202 Platform: LINUX x64
Date Run: 03/10/2025 Time: 20:14 Process ID: 16021
Operating System: Ubuntu 20.04.6 LTS
Processor Model: AMD EPYC 7763 64-Core Processor
Compiler: Intel(R) Fortran Compiler Classic Version 2021.9 (Build: 20230302)
Intel(R) C/C++ Compiler Classic Version 2021.9 (Build: 20230302)
AOCL-BLAS 4.2.1 Build 20240303
Number of machines requested : 1
Total number of cores available : 8
Number of physical cores available : 4
Number of processes requested : 4
Number of threads per process requested : 1
Total number of cores requested : 4 (Distributed Memory Parallel)
MPI Type: OPENMPI
MPI Version: Open MPI v4.0.5
GPU Acceleration: Not Requested
Job Name: file0
Input File: dummy.dat
Core Machine Name Working Directory
-----------------------------------------------------
0 218e6b81880e /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural
1 218e6b81880e /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural
2 218e6b81880e /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural
3 218e6b81880e /tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/StaticStructural
Latency time from master to core 1 = 2.016 microseconds
Latency time from master to core 2 = 1.963 microseconds
Latency time from master to core 3 = 2.000 microseconds
Communication speed from master to core 1 = 16613.94 MB/sec
Communication speed from master to core 2 = 8834.42 MB/sec
Communication speed from master to core 3 = 17986.73 MB/sec
Total CPU time for main thread : 2.7 seconds
Total CPU time summed for all threads : 6.4 seconds
Elapsed time spent obtaining a license : 0.4 seconds
Elapsed time spent pre-processing model (/PREP7) : 0.1 seconds
Elapsed time spent solution - preprocessing : 0.7 seconds
Elapsed time spent computing solution : 1.3 seconds
Elapsed time spent solution - postprocessing : 0.1 seconds
Elapsed time spent post-processing model (/POST1) : 0.0 seconds
Equation solver used : Sparse (symmetric)
Equation solver computational rate : 85.5 Gflops
Equation solver effective I/O rate : 30.2 GB/sec
Sum of disk space used on all processes : 78.5 MB
Sum of memory used on all processes : 588.0 MB
Sum of memory allocated on all processes : 3072.0 MB
Physical memory available : 31 GB
Total amount of I/O written to disk : 0.1 GB
Total amount of I/O read from disk : 0.0 GB
+------------------ E N D M A P D L S T A T I S T I C S -------------------+
*-----------------------------------------------------------------------------*
| |
| RUN COMPLETED |
| |
|-----------------------------------------------------------------------------|
| |
| Ansys MAPDL 2025 R1 Build 25.1 UP20241202 LINUX x64 |
| |
|-----------------------------------------------------------------------------|
| |
| Database Requested(-db) 1024 MB Scratch Memory Requested 1024 MB |
| Max Database Used(Master) 23 MB Max Scratch Used(Master) 152 MB |
| Max Database Used(Workers) 1 MB Max Scratch Used(Workers) 139 MB |
| Sum Database Used(All) 26 MB Sum Scratch Used(All) 562 MB |
| |
|-----------------------------------------------------------------------------|
| |
| CP Time (sec) = 6.450 Time = 20:14:09 |
| Elapsed Time (sec) = 5.000 Date = 03/10/2025 |
| |
*-----------------------------------------------------------------------------*
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.DSP to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.DSP: 0%| | 0.00/3.20k [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.DSP to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.DSP: 100%|██████████| 3.20k/3.20k [00:00<00:00, 10.3MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.rst to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.rst: 0%| | 0.00/9.75M [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file.rst to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file.rst: 100%|██████████| 9.75M/9.75M [00:00<00:00, 243MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/ds.dat to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/ds.dat: 0%| | 0.00/4.85M [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/ds.dat to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/ds.dat: 100%|██████████| 4.85M/4.85M [00:00<00:00, 68.1MB/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file0.err to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file0.err: 0%| | 0.00/601 [00:00<?, ?B/s]
Downloading dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMechF9E1/Project_Mech_Files/file_Mech_Files/StaticStructural/file0.err to /__w/pymechanical/pymechanical/examples/embedding_n_remote/download/file0.err: 100%|██████████| 601/601 [00:00<00:00, 2.79MB/s]
Exit remote session#
Close the Mechanical instance.
mechanical.exit()
Embedded Instance#
Download the geometry file#
Download Valve.pmdb.
import os
import ansys.mechanical.core as mech
from ansys.mechanical.core.examples import download_file
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding")
print(f"Downloaded the geometry file to: {geometry_path}")
Downloaded the geometry file to: /github/home/.local/share/ansys_mechanical_core/examples/Valve.pmdb
Embed Mechanical and set global variables#
Find the mechanical installation path & version. Open an embedded instance of Mechanical and set global variables.
app = mech.App(globals=globals())
print(app)
Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:251
Software build date: 11/27/2024 09:34:44
Add Static Analysis#
Add static analysis to the Model.
analysis = Model.AddStaticStructuralAnalysis()
Import geometry#
geometry_file = geometry_path
geometry_import = Model.GeometryImportGroup.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_file, geometry_import_format, geometry_import_preferences)
Assign material#
matAssignment = Model.Materials.AddMaterialAssignment()
tempSel = ExtAPI.SelectionManager.CreateSelectionInfo(
Ansys.ACT.Interfaces.Common.SelectionTypeEnum.GeometryEntities
)
bodies = [
body
for body in ExtAPI.DataModel.Project.Model.Geometry.GetChildren(
Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body, True
)
]
geobodies = [body.GetGeoBody() for body in bodies]
ids = System.Collections.Generic.List[System.Int32]()
[ids.Add(item.Id) for item in geobodies]
tempSel.Ids = ids
matAssignment.Location = tempSel
matAssignment.Material = "Structural Steel"
Define mesh settings#
mesh = Model.Mesh
mesh.ElementSize = Quantity("25 [mm]")
mesh.GenerateMesh()
Define boundary conditions#
fixedSupport = analysis.AddFixedSupport()
fixedSupport.Location = ExtAPI.DataModel.GetObjectsByName("NSFixedSupportFaces")[0]
frictionlessSupport = analysis.AddFrictionlessSupport()
frictionlessSupport.Location = ExtAPI.DataModel.GetObjectsByName("NSFrictionlessSupportFaces")[0]
pressure = analysis.AddPressure()
pressure.Location = ExtAPI.DataModel.GetObjectsByName("NSInsideFaces")[0]
inputs_quantities = [Quantity("0 [s]"), Quantity("1 [s]")]
output_quantities = [Quantity("0 [Pa]"), Quantity("15 [MPa]")]
inputs_quantities_2 = System.Collections.Generic.List[Ansys.Core.Units.Quantity]()
[inputs_quantities_2.Add(item) for item in inputs_quantities]
output_quantities_2 = System.Collections.Generic.List[Ansys.Core.Units.Quantity]()
[output_quantities_2.Add(item) for item in output_quantities]
pressure.Magnitude.Inputs[0].DiscreteValues = inputs_quantities_2
pressure.Magnitude.Output.DiscreteValues = output_quantities_2
Solve model#
Model.Solve(True)
solution = analysis.Solution
assert solution.Status == SolutionStatusType.Done
Add results#
solution.AddTotalDeformation()
solution.AddEquivalentStress()
solution.EvaluateAllResults()
Save model#
project_directory = ExtAPI.DataModel.Project.ProjectDirectory
print(f"project directory = {project_directory}")
ExtAPI.DataModel.Project.SaveAs(os.path.join(project_directory, "file.mechdb"))
project directory = /tmp/ANSYS.root.1/AnsysMech80C8/Project_Mech_Files/
Export result values to a text file#
fileExtension = r".txt"
results = solution.GetChildren(
Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Result, True
)
for result in results:
fileName = str(result.Name)
print(f"filename: {fileName}")
path = os.path.join(project_directory, fileName + fileExtension)
print(path)
result.ExportToTextFile(f"{path}")
print("Exported Text file Contents", path)
try:
write_file_contents_to_console(path, number_lines=20)
except:
print(os.listdir(project_directory))
app.close()
filename: Total Deformation
/tmp/ANSYS.root.1/AnsysMech80C8/Project_Mech_Files/Total Deformation.txt
Exported Text file Contents /tmp/ANSYS.root.1/AnsysMech80C8/Project_Mech_Files/Total Deformation.txt
Node Number Total Deformation (m)
1 1.1786e-006
2 1.1015e-006
3 1.0662e-006
4 1.0798e-006
5 1.1524e-006
6 1.241e-006
7 1.308e-006
8 1.2688e-006
9 1.4669e-005
10 1.5032e-005
11 1.6031e-005
12 1.5765e-005
13 1.4444e-005
14 1.5636e-005
15 1.6308e-005
16 1.5222e-005
17 3.6434e-006
18 3.9094e-006
19 3.6741e-006
filename: Equivalent Stress
/tmp/ANSYS.root.1/AnsysMech80C8/Project_Mech_Files/Equivalent Stress.txt
Exported Text file Contents /tmp/ANSYS.root.1/AnsysMech80C8/Project_Mech_Files/Equivalent Stress.txt
Node Number Equivalent (von-Mises) Stress (Pa)
1 4.3522e+006
2 4.672e+006
3 5.3414e+006
4 5.5663e+006
5 4.6071e+006
6 4.1819e+006
7 2.9398e+006
8 3.3957e+006
9 2.5717e+007
10 3.4526e+007
11 2.5966e+007
12 3.5308e+007
13 5.1995e+007
14 1.0062e+007
15 4.1414e+007
16 9.695e+006
17 1.4154e+007
18 4.3282e+007
19 1.2958e+007
Total running time of the script: (1 minutes 4.205 seconds)