Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird performance of solution #1084

Open
2 tasks done
Sega7654 opened this issue Feb 6, 2025 · 2 comments
Open
2 tasks done

Weird performance of solution #1084

Sega7654 opened this issue Feb 6, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@Sega7654
Copy link

Sega7654 commented Feb 6, 2025

🔍 Before submitting the issue

  • I have searched among the existing issues
  • I am using a Python virtual environment

🐞 Description of the bug

I'm Gleb, master srudent in Centrale Lyon university. I'm working with student Ansys (version 2024 R2) license on a project. I'm developing a code (You can find my code with geometry in the attachments) with PyAnsys for optimization. And I got a problem with the code. In the code I created a project (which was launcing Ansys Mechanical in batch mode) in Ansys Mechanical, set up mesh, BC, loads and soltion. After solving my instance with 2 cores, I got this error (I put the whole solution report in the Annex):

"The element option SOLID186 was either not ordered with this Ansys
installation or the appropriate product was not selected for this
session. "

I did not specify the solid type and my mesh was with automatic method.

Also, by printing a project tree, I can see this:

├── Project
| ├── Model
| | ├── Geometry Imports (✓)
| | | ├── Geometry Import (✓)
| | ├── Geometry (✓)
| | | ├── import_from_CAD_test
| | | | ├── import_from_CAD_test\comp_3_circle
| | ├── Materials (✓)
| | | ├── Structural Steel (✓)
| | ├── Coordinate Systems (✓)
| | | ├── Global Coordinate System (✓)
| | ├── Remote Points (✓)
| | | ├── Internal Remote Point (✓)
| | ├── Mesh (✓)
| | | ├── Automatic Method (✓)
| | ├── Static Structural (⚡︎)
| | | ├── Analysis Settings (✓)
| | | ├── Fixed Support (✓)
| | | ├── Moment (✓)
| | | ├── Solution (✕)
| | | | ├── Solution Information (✕)
| | | | ├── Equivalent Stress (⚡︎)

As You can see, everyting is done, except the solution. And here is "strange" things according this problem:

  1. I was copy-pasting most of commands (obviously with specific correction like file path, BC/force place application and ect.) from the example, which I found of PyMechanical examples. And in this example, everything worked fine. The exmaple which I reffer is:

https://embedding.examples.mechanical.docs.pyansys.com/examples/01_basic/fracture_analysis_contact_debonding.html#sphx-glr-examples-01-basic-fracture-analysis-contact-debonding-py

  1. I saved my project, coded in Python (via Visual Studio Code in Jupiter notebook) and the opened in directly from Ansys Mechanical. There I can see the exactly same project tree with no solved solution. There,in Mechanical, I tried to solve it and it worked without any errors. I could clearly see my solutions.

With this, I want to ask for your help. Could You please say, what could be the problem? Is this a limitation of a Student verison of Ansys? If it is, what are other limitations? Why do the exampe woked, but my code did not?

Annex

The full solution report:

Ansys Mechanical Enterprise Academic Student

------------------------------------------------------------------
| |
| 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 2024 R2          LEGAL NOTICES          *
    

  •                                                         *
    
  • Copyright 1971-2024 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). *
  •                                                         *
    

2024 R2

Point Releases and Patches installed:

Ansys Service Pack 2024 R2.10483252
Discovery 2024 R2.10483252
Core WB Files 2024 R2.10483252
Ansys Dynamic Reporting 2024 R2.10483252
SpaceClaim 2024 R2.10483252
CFX (includes CFD-Post) 2024 R2.10483252
Chemkin 2024 R2.10483252
EnSight 2024 R2.10483252
FENSAP-ICE 2024 R2.10483252
Fluent (includes CFD-Post) 2024 R2.10483252
Polyflow (includes CFD-Post) 2024 R2.10483252
Forte (includes EnSight) 2024 R2.10483252
TurboGrid 2024 R2.10483252
ACIS Geometry Interface 2024 R2.10483252
AutoCAD Geometry Interface 2024 R2.10483252
Catia, Version 4 Geometry Interface 2024 R2.10483252
Catia, Version 5 Geometry Interface 2024 R2.10483252
Catia, Version 6 Geometry Interface 2024 R2.10483252
Creo Elements/Direct Modeling Geometry Interface 2024 R2.10483252
Creo Parametric Geometry Interface 2024 R2.10483252
Inventor Geometry Interface 2024 R2.10483252
JTOpen Geometry Interface 2024 R2.10483252
NX Geometry Interface 2024 R2.10483252
Parasolid Geometry Interface 2024 R2.10483252
Solid Edge Geometry Interface 2024 R2.10483252
SOLIDWORKS Geometry Interface 2024 R2.10483252
Speos 2024 R2.10483252
Aqwa 2024 R2.10483252
Autodyn 2024 R2.10483252
Material Calibration App 2024 R2.10483252
Customization Files for User Programmable Features 2024 R2.10483252
Mechanical Products 2024 R2.10483252
Motion 2024 R2.10483252
Academic Student 2024 R2.10483252

      *****  MAPDL COMMAND LINE ARGUMENTS  *****

BATCH MODE REQUESTED (-b) = NOLIST
INPUT FILE COPY MODE (-c) = COPY
DISTRIBUTED MEMORY PARALLEL REQUESTED
2 PARALLEL PROCESSES REQUESTED WITH SINGLE THREAD PER PROCESS
TOTAL OF 2 CORES REQUESTED
INPUT FILE NAME = C:\Users\miste\AppData\Local\Temp\AnsysMech0430\Project_Mech_Files\StaticStructural\dummy.dat
OUTPUT FILE NAME = C:\Users\miste\AppData\Local\Temp\AnsysMech0430\Project_Mech_Files\StaticStructural\solve.out
START-UP FILE MODE = NOREAD
STOP FILE MODE = NOREAD

RELEASE= 2024 R2 BUILD= 24.2 UP20240513 VERSION=WINDOWS x64
CURRENT JOBNAME=file0 15:29:55 FEB 05, 2025 CP= 0.000

PARAMETER _DS_PROGRESS = 999.0000000

/INPUT FILE= ds.dat LINE= 0

*** NOTE *** CP = 0.016 TIME= 15:29:55
The /CONFIG,NOELDB command is not valid in a distributed memory
parallel solution. Command is ignored.

*GET _WALLSTRT FROM ACTI ITEM=TIME WALL VALUE= 15.4986111

TITLE=
--Static Structural

ACT Extensions:
LSDYNA, 2024.2
5f463412-bd3e-484b-87e7-cbc0a665e474, wbex
/COM, ANSYSMotion, 2024.2
20180725-3f81-49eb-9f31-41364844c769, wbex

SET PARAMETER DIMENSIONS ON _WB_PROJECTSCRATCH_DIR
TYPE=STRI DIMENSIONS= 248 1 1

PARAMETER _WB_PROJECTSCRATCH_DIR(1) = C:\Users\miste\AppData\Local\Temp\AnsysMech0430\Project_Mech_Files\StaticStructural\

SET PARAMETER DIMENSIONS ON _WB_SOLVERFILES_DIR
TYPE=STRI DIMENSIONS= 248 1 1

PARAMETER _WB_SOLVERFILES_DIR(1) = C:\Users\miste\AppData\Local\Temp\AnsysMech0430\Project_Mech_Files\StaticStructural\

SET PARAMETER DIMENSIONS ON _WB_USERFILES_DIR
TYPE=STRI DIMENSIONS= 248 1 1

PARAMETER _WB_USERFILES_DIR(1) = C:\Users\miste\AppData\Local\Temp\AnsysMech0430\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 2024 R2 24.2 ***
Ansys Mechanical Enterprise Academic Student
01055371 VERSION=WINDOWS x64 15:29:55 FEB 05, 2025 CP= 0.016

--Static Structural

      ***** MAPDL ANALYSIS DEFINITION (PREP7) *****

*********** Nodes for the whole assembly ***********
*********** Nodes for all Remote Points ***********
*********** Elements for Body 1 'import_from_CAD_test\comp_3_circle' **********

*** ERROR *** CP = 0.016 TIME= 15:29:55
The element option SOLID186 was either not ordered with this Ansys
installation or the appropriate product was not selected for this
session.
Contact your Ansys support person for more information.

NUMBER OF WARNING MESSAGES ENCOUNTERED= 0
NUMBER OF ERROR MESSAGES ENCOUNTERED= 1

***** PROBLEM TERMINATED BY INDICATED ERROR(S) OR BY END OF INPUT DATA *****

+--------------------- M A P D L S T A T I S T I C S ------------------------+

Release: 2024 R2 Build: 24.2 Update: UP20240513 Platform: WINDOWS x64
Date Run: 02/05/2025 Time: 15:29 Process ID: 20808
Operating System: Windows 11 (Build: 22631)

Processor Model: AMD Ryzen 9 7940HS w/ Radeon 780M Graphics

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 20240304

Number of machines requested : 1
Total number of cores available : 16
Number of physical cores available : 8
Number of processes requested : 2
Number of threads per process requested : 1
Total number of cores requested : 2 (Distributed Memory Parallel)
MPI Type: INTELMPI
MPI Version: Intel(R) MPI Library 2021.11 for Windows* OS

GPU Acceleration: Not Requested

Job Name: file0
Input File: dummy.dat

Core Machine Name Working Directory

 0                        Sega   C:\Users\miste\AppData\Local\Temp\AnsysMech0430\Project_Mech_Files\StaticStructural
 1                        Sega   C:\Users\miste\AppData\Local\Temp\AnsysMech0430\Project_Mech_Files\StaticStructural

Latency time from master to core 1 = 2.458 microseconds

Communication speed from master to core 1 = 14374.27 MB/sec

Total CPU time for main thread : 0.0 seconds
Total CPU time summed for all threads : 0.1 seconds

Elapsed time spent obtaining a license : 0.4 seconds
Elapsed time spent pre-processing model (/PREP7) : 0.0 seconds
Elapsed time spent solution - preprocessing : 0.0 seconds
Elapsed time spent computing solution : 0.0 seconds
Elapsed time spent solution - postprocessing : 0.0 seconds
Elapsed time spent post-processing model (/POST1) : 0.0 seconds

Sum of disk space used on all processes : 0.0 MB

Sum of memory used on all processes : 40.0 MB
Sum of memory allocated on all processes : 2496.0 MB
Physical memory available : 31 GB
Total amount of I/O written to disk : 0.0 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 2024 R2 Build 24.2 UP20240513 WINDOWS x64
-----------------------------------------------------------------------------
Database Requested(-db) 1024 MB Scratch Memory Requested 1024 MB
Max Database Used(Master) 2 MB Max Scratch Used(Master) 32 MB
Max Database Used(Workers) 1 MB Max Scratch Used(Workers) 5 MB
Sum Database Used(All) 3 MB Sum Scratch Used(All) 37 MB
-----------------------------------------------------------------------------
CP Time (sec) = 0.062 Time = 15:29:56
Elapsed Time (sec) = 2.000 Date = 02/05/2025
-----------------------------------------------------------------------------

📝 Steps to reproduce

import os

from ansys.mechanical.core import launch_mechanical
from ansys.mechanical.core.examples import download_file
from matplotlib import image as mpimg
from matplotlib import pyplot as plt

from PIL import Image
from ansys.mechanical.core import App
from matplotlib.animation import FuncAnimation
mechanical = launch_mechanical(batch=True, cleanup_on_exit=False)
app = App()
app.update_globals(globals())

cwd = os.path.join(os.getcwd(), "out")

def display_image(image_name):
plt.figure(figsize=(16, 9))
plt.imshow(mpimg.imread(os.path.join(cwd, image_name)))
plt.xticks([])
plt.yticks([])
plt.axis("off")
plt.show()

Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)
Graphics.Camera.SetFit()
image_export_format = GraphicsImageExportFormat.PNG
settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()
settings_720p.Resolution = GraphicsResolutionType.EnhancedResolution
settings_720p.Background = GraphicsBackgroundType.White
settings_720p.Width = 1280
settings_720p.Height = 720
settings_720p.CurrentGraphicsDisplay = False
Graphics.Camera.Rotate(180, CameraAxisType.ScreenY)

'''NOTE : All workflows will not be recorded, as recording is under development.'''

#region Context Menu Action
geometry_import_group_11 = Model.GeometryImportGroup
geometry_import_19 = geometry_import_group_11.AddGeometryImport()
#endregion
#region Context Menu Action
geometry_import_19_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic
geometry_import_19_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()
geometry_import_19.Import(r"C:\Users\miste\Desktop\Python_Ansys_training\PyAnsysGeometry\ma_huynya\import_from_CAD_test.scdocx", geometry_import_19_format, geometry_import_19_preferences)
#endregion

GEOM = Model.Geometry
GEOM.Material = "Steel"

model_10 = Model
analysis_30 = model_10.AddStaticStructuralAnalysis()
ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS
STATIC_STRUCTURAL = DataModel.AnalysisByName("Static Structural")

ANALYSIS_SETTINGS = STATIC_STRUCTURAL.AnalysisSettings
SOLUTION = STATIC_STRUCTURAL.Solution
MESH = Model.Mesh
STATIC_STRUCTURAL.SolveConfiguration.SolveProcessSettings.MaxNumberOfCores = 2
ANALYSIS_SETTINGS.Activate()
ANALYSIS_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On
ANALYSIS_SETTINGS.DefineBy = TimeStepDefineByType.Substeps
ANALYSIS_SETTINGS.MaximumSubsteps = 100
ANALYSIS_SETTINGS.InitialSubsteps = 100
ANALYSIS_SETTINGS.MinimumSubsteps = 100
ANALYSIS_SETTINGS.LargeDeflection = True
MESH.Activate()
mesh_13 = Model.Mesh
automatic_method_27 = mesh_13.AddAutomaticMethod()

selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [4]
automatic_method_27.Location = selection
mesh_13.GenerateMesh()

STATIC_STRUCTURAL.Activate()
fixed_support_34 = STATIC_STRUCTURAL.AddFixedSupport()
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [7]
fixed_support_34.Location = selection
STATIC_STRUCTURAL.Activate()
moment_36 = STATIC_STRUCTURAL.AddMoment()
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [6]
moment_36.Location = selection
moment_36.Magnitude.Output.SetDiscreteValue(0, Quantity(500, "N mm"))

STATIC_STRUCTURAL.Activate()
STATIC_STRUCTURAL.Solution.Solve()
#STAT_STRUC_SS=SOLUTION.Status
SOLUTION.Activate()
#DIRECTIONAL_DEFORMATION = SOLUTION.AddDirectionalDeformation()
#DIRECTIONAL_DEFORMATION.NormalOrientation = NormalOrientationType.YAxis
#TOTAL_DEFORMATION = SOLUTION.AddTotalDeformation()
SOLUTION.AddEquivalentStress()
#DIRECTIONAL_DEFORMATION.NormalOrientation = NormalOrientationType.YAxis
def write_file_contents_to_console(path):
"""Write file contents to console."""
with open(path, "rt") as file:
for line in file:
print(line, end="")

solve_path = STATIC_STRUCTURAL.WorkingDir
solve_out_path = os.path.join(solve_path, "solve.out")
if solve_out_path:
write_file_contents_to_console(solve_out_path)
app.update_globals(globals())
app.print_tree()
#Tree.Activate([analysis_30])
STATIC_STRUCTURAL.Activate()

Graphics.Camera.SetFit()
Graphics.ExportImage(
os.path.join(cwd, "analysis_30.png"), image_export_format, settings_720p
)
display_image("analysis_30.png")
DataModel.Remove(geometry_import_19)
app.save(os.path.join(cwd, "save_test_2.mechdat"))
app.new()
mechanical.exit()

💻 Which operating system are you using?

Windows

📀 Which ANSYS version are you using?

Ansys R2 2024, Student version.

🐍 Which Python version are you using?

3.12

📦 Installed packages

Python 3.12.7

aiohappyeyeballs==2.4.4
aiohttp==3.11.11
aiosignal==1.3.2
ansys-api-dbu==0.3.6
ansys-api-geometry==0.4.16
ansys-api-mechanical==0.1.2
ansys-api-platform-instancemanagement==1.1.0
ansys-geometry-core==0.7.6
ansys-mechanical-core==0.11.11
ansys-mechanical-env==0.1.8
ansys-mechanical-stubs==0.1.5
ansys-platform-instancemanagement==1.1.2
ansys-pythonnet==3.1.0rc5
ansys-tools-path==0.7.1
ansys-tools-visualization-interface==0.7.0
anyio==4.8.0
appdirs==1.4.4
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==3.0.0
async-timeout==5.0.1
attrs==24.3.0
beartype==0.19.0
beautifulsoup4==4.12.3
bleach==6.2.0
certifi==2024.12.14
cffi==1.17.1
charset-normalizer==3.4.1
click==8.1.8
clr_loader==0.2.7.post0
colorama==0.4.6
comm==0.2.2
contourpy==1.3.1
cycler==0.12.1
debugpy==1.8.11
decorator==5.1.1
defusedxml==0.7.1
docker==7.1.0
exceptiongroup==1.2.2
executing==2.1.0
fastjsonschema==2.21.1
flexcache==0.3
flexparser==0.4
fonttools==4.55.3
fqdn==1.5.1
frozenlist==1.5.0
grpcio==1.67.1
grpcio-health-checking==1.67.1
idna==3.10
importlib_metadata==8.5.0
ipykernel==6.29.5
ipython==8.31.0
ipywidgets==8.1.5
isoduration==20.11.0
jedi==0.19.2
Jinja2==3.1.5
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
jupyter-events==0.11.0
jupyter_client==8.6.3
jupyter_core==5.7.2
jupyter_server==2.15.0
jupyter_server_proxy==4.4.0
jupyter_server_terminals==0.5.3
jupyterlab_pygments==0.3.0
jupyterlab_widgets==3.0.13
kiwisolver==1.4.8
MarkupSafe==3.0.2
matplotlib==3.10.0
matplotlib-inline==0.1.7
mistune==3.1.0
more-itertools==10.5.0
msgpack==1.1.0
multidict==6.1.0
nbclient==0.10.2
nbconvert==7.16.5
nbformat==5.10.4
nest-asyncio==1.6.0
numpy==2.2.1
overrides==7.7.0
packaging==24.2
pandocfilters==1.5.1
parso==0.8.4
pillow==11.1.0
Pint==0.24.4
platformdirs==4.3.6
pooch==1.8.2
prometheus_client==0.21.1
prompt_toolkit==3.0.48
propcache==0.2.1
protobuf==5.29.3
psutil==6.1.1
pure_eval==0.2.3
pycparser==2.22
Pygments==2.19.1
pyparsing==3.2.1
python-dateutil==2.9.0.post0
python-json-logger==3.2.1
pytz==2024.2
pyvista==0.44.2
pywin32==308
pywinpty==2.0.14
PyYAML==6.0.2
pyzmq==26.2.0
referencing==0.35.1
requests==2.32.3
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.22.3
scipy==1.15.1
scooby==0.10.0
semver==3.0.2
Send2Trash==1.8.3
simpervisor==1.0.0
six==1.17.0
sniffio==1.3.1
soupsieve==2.6
stack-data==0.6.3
terminado==0.18.1
threadpoolctl==3.5.0
tinycss2==1.4.0
tornado==6.4.2
tqdm==4.67.1
traitlets==5.14.3
trame==3.7.6
trame-client==3.5.1
trame-server==3.3.0
trame-vtk==2.8.14
trame-vuetify==2.8.0
types-python-dateutil==2.9.0.20241206
typing_extensions==4.12.2
tzdata==2024.2
uri-template==1.3.0
urllib3==2.3.0
usd-core==24.11
vtk==9.3.1
wcwidth==0.2.13
webcolors==24.11.1
webencodings==0.5.1
websocket-client==1.8.0
websockets==14.1
widgetsnbextension==4.0.13
wslink==2.2.2
yarl==1.18.3
zipp==3.21.0
@Sega7654 Sega7654 added the bug Something isn't working label Feb 6, 2025
@RobPasMue RobPasMue transferred this issue from ansys/pyansys Feb 6, 2025
@dipinknair
Copy link
Collaborator

@Sega7654, Hi Thanks for opening the issue. Could you please provide the geometry if possible? you can email to [email protected] with "PyMechanical issue #1084" in subject.

@dipinknair
Copy link
Collaborator

dipinknair commented Feb 10, 2025

@Sega7654 in your code you have used pymechanical remote and embedding and there are other inconsistencies. Geometry does not have Material where in code you are using it.


GEOM = Model.Geometry
GEOM.Material = "Steel"

Then at the end you are removing the geometry itself in code which is unnecessary.
In addition to that you are adding a equivalent stress after solution.Solve() call . Which means you need to call solution.EvaluatAllResults() after adding any result object.
I am pasting a modified script below and can you try this and let me know.

import os
from matplotlib import image as mpimg
from matplotlib import pyplot as plt

from ansys.mechanical.core import App
app = App(version=242)
app.update_globals(globals())

cwd = os.path.join(os.getcwd(), "out")

def display_image(image_name):
    plt.figure(figsize=(16, 9))
    plt.imshow(mpimg.imread(os.path.join(cwd, image_name)))
    plt.xticks([])
    plt.yticks([])
    plt.axis("off")
    plt.show()

Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)
Graphics.Camera.SetFit()
image_export_format = GraphicsImageExportFormat.PNG
settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()
settings_720p.Resolution = GraphicsResolutionType.EnhancedResolution
settings_720p.Background = GraphicsBackgroundType.White
settings_720p.Width = 1280
settings_720p.Height = 720
settings_720p.CurrentGraphicsDisplay = False
Graphics.Camera.Rotate(180, CameraAxisType.ScreenY)

geometry_import_group_11 = Model.GeometryImportGroup
geometry_import_19 = geometry_import_group_11.AddGeometryImport()

geometry_import_19_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic
geometry_import_19_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()
geometry_import_19.Import(r"C:\Users\miste\Desktop\Python_Ansys_training\PyAnsysGeometry\ma_huynya\import_from_CAD_test.scdocx", geometry_import_19_format, geometry_import_19_preferences)
#endregion

model_10 = Model
analysis_30 = model_10.AddStaticStructuralAnalysis()
ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS
STATIC_STRUCTURAL = DataModel.AnalysisByName("Static Structural")

ANALYSIS_SETTINGS = STATIC_STRUCTURAL.AnalysisSettings
SOLUTION = STATIC_STRUCTURAL.Solution
MESH = Model.Mesh
STATIC_STRUCTURAL.SolveConfiguration.SolveProcessSettings.MaxNumberOfCores = 2
ANALYSIS_SETTINGS.Activate()
ANALYSIS_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On
ANALYSIS_SETTINGS.DefineBy = TimeStepDefineByType.Substeps
ANALYSIS_SETTINGS.MaximumSubsteps = 100
ANALYSIS_SETTINGS.InitialSubsteps = 100
ANALYSIS_SETTINGS.MinimumSubsteps = 100
ANALYSIS_SETTINGS.LargeDeflection = True
MESH.Activate()
mesh_13 = Model.Mesh
automatic_method_27 = mesh_13.AddAutomaticMethod()

selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [4]
automatic_method_27.Location = selection
mesh_13.GenerateMesh()

STATIC_STRUCTURAL.Activate()
fixed_support_34 = STATIC_STRUCTURAL.AddFixedSupport()
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [7]
fixed_support_34.Location = selection
STATIC_STRUCTURAL.Activate()
moment_36 = STATIC_STRUCTURAL.AddMoment()
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [6]
moment_36.Location = selection
moment_36.Magnitude.Output.SetDiscreteValue(0, Quantity(500, "N mm"))

STATIC_STRUCTURAL.Activate()
STATIC_STRUCTURAL.Solution.Solve(True)
#STAT_STRUC_SS=SOLUTION.Status
SOLUTION.Activate()
#DIRECTIONAL_DEFORMATION = SOLUTION.AddDirectionalDeformation()
#DIRECTIONAL_DEFORMATION.NormalOrientation = NormalOrientationType.YAxis
#TOTAL_DEFORMATION = SOLUTION.AddTotalDeformation()
SOLUTION.AddEquivalentStress()
#DIRECTIONAL_DEFORMATION.NormalOrientation = NormalOrientationType.YAxis
SOLUTION.EvaluateAllResults()

def write_file_contents_to_console(path):
    """Write file contents to console."""
    with open(path, "rt") as file:
        for line in file:
            print(line, end="")

solve_path = STATIC_STRUCTURAL.WorkingDir
solve_out_path = os.path.join(solve_path, "solve.out")
if solve_out_path:
    write_file_contents_to_console(solve_out_path)

STATIC_STRUCTURAL.Activate()

Graphics.Camera.SetFit()
Graphics.ExportImage(
os.path.join(cwd, "analysis_30.png"), image_export_format, settings_720p
)
display_image("analysis_30.png")
#DataModel.Remove(geometry_import_19)
app.save(os.path.join(cwd, "save_test_2.mechdb"))

Let me know what errors you are seeing after running this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants