ansys / pymechanical

Pythonic interface to Ansys Mechanical ™
https://mechanical.docs.pyansys.com/
MIT License
34 stars 17 forks source link

Pymechanical on Linux- Solver Error #694

Closed CollinsJnr-001 closed 4 months ago

CollinsJnr-001 commented 5 months ago

🔍 Before submitting the issue

🐞 Description of the bug

I am trying to run a simple modal analysis using Pymechanical remote session on a Linux HPC.

I have all packages installed, and when I run the code it gets to the solve line and displays an error.

Running Solver : /opt/apps/testapps/el7/software/staging/ANSYS/2023R2/v232/aisol/../ansys/bin/ansys232 -b nolist -s noread -i dummy.dat -o solve.out -dis -np 50 -p ansys /opt/apps/testapps/el7/software/staging/ANSYS/2023R2/v232/aisol/.workbench: line 271: 1288 Killed $Pgm $Args CRITICAL - - logging - handle_exception - Uncaught exception Traceback (most recent call last): File "/Testing.py", line 28, in output = mechanical.run_python_script( File "/envs/Pyansys/lib/python3.10/site-packages/ansys/mechanical/core/mechanical.py", line 981, in run_python_script result_as_string = self.__call_run_python_script( File "/envs/Pyansys/lib/python3.10/site-packages/ansys/mechanical/core/mechanical.py", line 1702, in call_run_python_script for runscript_response in self._stub.RunPythonScript(request): File "/envs/Pyansys/lib/python3.10/site-packages/grpc/_channel.py", line 542, in next__ return self._next() File "/envs/Pyansys/lib/python3.10/site-packages/grpc/_channel.py", line 968, in _next raise self grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with: status = StatusCode.UNAVAILABLE details = "Socket closed" debug_error_string = "UNKNOWN:Error received from peer {grpc_message:"Socket closed", grpc_status:14, created_time:"2024-04-11T10:03:41.086670992+01:00"}"

📝 Steps to reproduce

import os

from ansys.mechanical.core import launch_mechanical from ansys.mechanical.core.examples import download_file

geometry_path = download_file("example_01_geometry.agdb", "pymechanical", "00_basic") print(f"Downloaded the geometry file to: {geometry_path}")

mechanical = launch_mechanical(batch=True, cleanup_on_exit = True, exec_file = '/ANSYS/2023R2/v232/aisol/.workbench') print(mechanical)

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}")

output = mechanical.run_python_script( """ import json

Section 1: Read geometry information

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_preferences.ProcessNamedSelections = True geometry_import_19_preferences.ProcessCoordinateSystems = True

geometry_import_19.Import(part_file_path, geometry_import_19_format, geometry_import_19_preferences)

Model.AddStaticStructuralAnalysis() STAT_STRUC = Model.Analyses[0] CS_GRP = Model.CoordinateSystems ANALYSIS_SETTINGS = STAT_STRUC.Children[0] SOLN= STAT_STRUC.Solution

Section 2: Set up the unit system.

ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS ExtAPI.Application.ActiveAngleUnit = AngleUnitType.Radian

Section 3: Define named selection and coordinate system.

NS1 = Model.NamedSelections.Children[0] NS2 = Model.NamedSelections.Children[1] NS3 = Model.NamedSelections.Children[2] NS4 = Model.NamedSelections.Children[3] GCS = CS_GRP.Children[0] LCS1 = CS_GRP.Children[1]

Section 4: Define remote point.

RMPT_GRP = Model.RemotePoints RMPT_1 = RMPT_GRP.AddRemotePoint() RMPT_1.Location = NS1 RMPT_1.XCoordinate=Quantity("7 [m]") RMPT_1.YCoordinate=Quantity("0 [m]") RMPT_1.ZCoordinate=Quantity("0 [m]")

Section 5: Define mesh settings.

MSH = Model.Mesh MSH.ElementSize =Quantity("0.5 [m]") MSH.GenerateMesh()

Section 6: Define boundary conditions.
Insert fixed support.

FIX_SUP = STAT_STRUC.AddFixedSupport() FIX_SUP.Location = NS2

Insert frictionless support.

FRIC_SUP = STAT_STRUC.AddFrictionlessSupport() FRIC_SUP.Location = NS3

Section 7: Define remote force.

REM_FRC1 = STAT_STRUC.AddRemoteForce() REM_FRC1.Location = RMPT_1 REM_FRC1.DefineBy =LoadDefineBy.Components REM_FRC1.XComponent.Output.DiscreteValues = [Quantity("1e10 [N]")]

Section 8: Define thermal condition.

THERM_COND = STAT_STRUC.AddThermalCondition() THERM_COND.Location = NS4 THERM_COND.Magnitude.Output.DefinitionType=VariableDefinitionType.Formula THERM_COND.Magnitude.Output.Formula="50*(20+z)" THERM_COND.XYZFunctionCoordinateSystem=LCS1 THERM_COND.RangeMinimum=Quantity("-20 [m]") THERM_COND.RangeMaximum=Quantity("1 [m]")

Section 9: Insert directional deformation.

DIR_DEF = STAT_STRUC.Solution.AddDirectionalDeformation() DIR_DEF.Location = NS1 DIR_DEF.NormalOrientation =NormalOrientationType.XAxis

Section 10: Add total deformation and force reaction probe.

TOT_DEF = STAT_STRUC.Solution.AddTotalDeformation()

Add force reaction.

FRC_REAC_PROBE = STAT_STRUC.Solution.AddForceReaction() FRC_REAC_PROBE.BoundaryConditionSelection = FIX_SUP FRC_REAC_PROBE.ResultSelection =ProbeDisplayFilter.XAxis

Section 11: Solve and get the results.
Solve static analysis.

STAT_STRUC.Solution.Solve(True)

dir_deformation_details = { "Minimum": str(DIR_DEF.Minimum), "Maximum": str(DIR_DEF.Maximum), "Average": str(DIR_DEF.Average), }

json.dumps(dir_deformation_details) """ ) print(output)

def get_solve_out_path(mechanical): solve_out_path = "" for file_path in mechanical.list_files(): if file_path.find("solve.out") != -1: solve_out_path = file_path break

return solve_out_path

def write_file_contents_to_console(path): with open(path, "rt") as file: for line in file: print(line, end="")

solve_out_path = get_solve_out_path(mechanical)

if solve_out_path != "": current_working_directory = os.getcwd()

local_file_path_list = mechanical.download(
    solve_out_path, target_dir=current_working_directory
)
solve_out_local_path = local_file_path_list[0]
print(f"Local solve.out path : {solve_out_local_path}")

write_file_contents_to_console(solve_out_local_path)

os.remove(solve_out_local_path)

mechanical.exit()

💻 Which operating system are you using?

Linux

📀 Which ANSYS version are you using?

v232

🐍 Which Python version are you using?

3.10

📦 Installed packages

ansys-api-mechanical==0.1.1
ansys-api-platform-instancemanagement==1.0.0
ansys-mechanical-core==0.10.9
ansys-mechanical-env==0.1.5
ansys-platform-instancemanagement==1.1.2
ansys-pythonnet==3.1.0rc3
ansys-tools-path==0.5.1
appdirs==1.4.4
Bottleneck @ file:///croot/bottleneck_1707864210935/work
cffi==1.16.0
click==8.1.7
clr-loader==0.2.6
contourpy==1.2.1
cycler==0.12.1
fonttools==4.51.0
grpcio==1.62.1
importlib_metadata==7.1.0
kiwisolver==1.4.5
matplotlib==3.8.4
mkl-fft @ file:///croot/mkl_fft_1695058164594/work
mkl-random @ file:///croot/mkl_random_1695059800811/work
mkl-service==2.4.0
numexpr @ file:///croot/numexpr_1696515281613/work
numpy @ file:///croot/numpy_and_numpy_base_1708638617955/work/dist/numpy-1.26.4-cp310-cp310-linux_x86_64.whl#sha256=d8cd837ed43e87f77e6efaa08e8de927ca030a1c9c5d04624432d6fb9a74a5ee
packaging==24.0
pandas @ file:///croot/pandas_1709590491089/work/dist/pandas-2.2.1-cp310-cp310-linux_x86_64.whl#sha256=af0f237a7f090add6f15eb4b5d0fd2d9d8ded4cfe6979b18563580353c113c9f
pillow==10.3.0
platformdirs==4.2.0
protobuf==4.25.3
pycparser==2.22
pyparsing==3.1.2
python-dateutil @ file:///tmp/build/80754af9/python-dateutil_1626374649649/work
pytz @ file:///croot/pytz_1695131579487/work
scipy @ file:///croot/scipy_1710947333060/work/dist/scipy-1.12.0-cp310-cp310-linux_x86_64.whl#sha256=91bbd4c153610fb62d9555167f7bd4b7ae21086e636bd8b4c5db75d57d04ea05
simplejson==3.19.2
six @ file:///tmp/build/80754af9/six_1644875935023/work
tqdm==4.66.2
tzdata @ file:///croot/python-tzdata_1690578112552/work
zipp==3.18.1
dipinknair commented 5 months ago

Hi @CollinsJnr-001

Its a syntax issue. Please modify

geometry_import_19_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.
Format.Automatic

either to

geometry_import_19_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.\
Format.Automatic

or

geometry_import_19_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic

Also if you are getting issue with part_file_path = combined_path.replace("\", "\\") use part_file_path = combined_path.replace("\\", "\\\\")

CollinsJnr-001 commented 5 months ago

Hi @CollinsJnr-001

Its a syntax issue. Please modify

geometry_import_19_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.
Format.Automatic

either to

geometry_import_19_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.\
Format.Automatic

or

geometry_import_19_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic

Also if you are getting issue with part_file_path = combined_path.replace("\", "\\") use part_file_path = combined_path.replace("\\", "\\\\")

@dipinknair

Thank you; those are syntax problems. It seems Github formatter tempered with the code I pasted, but the original code has all those corrections.

The error I have is beyond just syntax

Please try the code with those modification

CollinsJnr-001 commented 5 months ago

@dipinknair

This is exactly one of the example in Pymechanical documentation, which you can find in link below

https://examples.mechanical.docs.pyansys.com/examples/00_basic/example_01_simple_structural_solve.html#sphx-glr-examples-00-basic-example-01-simple-structural-solve-py

CollinsJnr-001 commented 5 months ago

Hey @dipinknair

I wanted to check in to see if you've experienced the same problem as I did and if you found a way around.

Thank you.

dipinknair commented 5 months ago

@CollinsJnr-001 Hi , Could you please download the file using download option from here image https://github.com/ansys/example-data/blob/master/pymechanical/00_basic/example_01_geometry.agdb

then please modify your geometry path `geometry_path = r"<>.agdb" where you saved your file and try .

I am unable to replicate the issue in Linux with 232

CollinsJnr-001 commented 5 months ago

@dipinknair

Can you try this, I also had the same error running this

Find geometry here: The Python code is also in the google drive, in case there is a fomatting problem.

import ansys.mechanical.core as pymech

mechanical = pymech.launch_mechanical(batch = True, cleanup_on_exit= True) print(mechanical) project_directory = mechanical.project_directory print(f'Project Directory = {project_directory}') #obtain working project directory of ansys mechnaical instance

Modal Analysis

mechanical.run_python_script( """ import os

Import function

geometry_import_group = Model.GeometryImportGroup geometry_import = geometry_import_group.AddGeometryImport()

Import Geometry

geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences() geometry_import.Import(r"Cantilever Beam.x_t", geometry_import_format, geometry_import_preferences)

Set Geometry Material

material_assignment = Model.Materials.AddMaterialAssignment() material_assignment.Material = "Structural Steel" sel = ExtAPI.SelectionManager.CreateSelectionInfo(Ansys.ACT.Interfaces.Common.SelectionTypeEnum.GeometryEntities) sel.Ids = [body.GetGeoBody().Id for body in Model.Geometry.GetChildren(Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body, True)] material_assignment.Location = sel

Set mesh Element size

mesh = Model.Mesh mesh.ElementSize = Quantity(0.0025, "m")

Generate Mesh

mesh.GenerateMesh()

View Mesh Quality

mesh.MeshMetric = MeshMetricType.ElementQuality

Add Modal Analysis

region Toolbar Action

model = Model modal_analysis = model.AddModalAnalysis() modal_analysis_settings = DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.AnalysisSettings.ANSYSAnalysisSettings)

Set Number of Modes

modal_analysis_settings = DataModel.GetObjectById(modal_analysis_settings[0].ObjectId) num_mode = 10 modal_analysis_settings.MaximumModesToFind = num_mode

Add Fixed End

fixed_support = modal_analysis.AddFixedSupport()

Select fixed end surface

selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [29] fixed_support.Location = selection

Run Modal Analysis

modal_analysis.Solve(True) modal_analysis_solution = DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.Solution) """) mechanical.clear() mechanical.exit(force= True)

dipinknair commented 5 months ago

@CollinsJnr-001 Did that download directly from github work for you ? You can check opening the geometry file directly from either workbench or Mechanical to check if the issue is with geometry or not. pymech.launch_mechanical(batch = False, cleanup_on_exit= True) if you disable batch then you can see the process interactively.

CollinsJnr-001 commented 5 months ago

@dipinknair Thank you I don't think it is a geometry problem. I have tried different simulation using the Pymechanical on the linux HPC and I get the same error.

The geometry and every other part of the code works nicely but the solve line (Model.Solve(True)) always gives that error.

You can try the example I just shared for modal analysis. I still get the same error message.

Hope fully you will see the error in the new example since it is much more simpler

CollinsJnr-001 commented 5 months ago

@dipinknair

Just to add, these examples ran very smoothly on my local Windows computer.

The problem is running it on Linux HPC

dipinknair commented 5 months ago

@CollinsJnr-001 test.zip

Could you please run this test.pywith proper path to geometry with below command from your venv we are basically running the script in batchmode to check if HPC is solving without pymechanical.

ansys-mechanical -r 232 -i .\test.py --exit

What is the Linux HPC platform? It can be because of not having all dependencies installed.

CollinsJnr-001 commented 5 months ago

@dipinknair Thank you

I got this error

CRITICAL - - logging - handle_exception - Uncaught exception Traceback (most recent call last): File "/users/.conda/envs/Pyansys/bin/ansys-mechanical", line 8, in sys.exit(cli()) File "/users/.conda/envs/Pyansys/lib/python3.10/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) File "/users/.conda/envs/Pyansys/lib/python3.10/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) File "/users/.conda/envs/Pyansys/lib/python3.10/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) File "/users/.conda/envs/Pyansys/lib/python3.10/site-packages/click/core.py", line 783, in invoke return __callback(args, *kwargs) File "/users/.conda/envs/Pyansys/lib/python3.10/site-packages/ansys/mechanical/core/run.py", line 191, in cli version = int(_version 10) ValueError: invalid literal for int() with base 10: ''

Linux HPC Platform: CentOS 7

dipinknair commented 5 months ago

sorry I missed this, since the path of Ansys installation is different from the default path that ansys.tools.path looks for getting Mechanical, you have to save the path first. for that please use first try running find-mechanical if that does not return any version or path please use below. save-ansys-path --name mechanical /user/username/v232/aisol/.workbench (provide absolute path to your .workbench)

then run ansys-mechanical -r 232 -i .\test.py --exit.

Let me know how it goes.

CollinsJnr-001 commented 5 months ago

@dipinknair same error message

dipinknair commented 5 months ago

@dipinknair same error message

@CollinsJnr-001 What did you get when you run find-mechanical ?

CollinsJnr-001 commented 5 months ago

@dipinknair same error message

@CollinsJnr-001 What did you get when you run find-mechanical ?

@dipinknair 232 /opt/apps/testapps/el7/software/staging/ANSYS/2023R2/v232/aisol

dipinknair commented 5 months ago

Hi @CollinsJnr-001 , Thanks for trying that. This is an issue with ansys.tools.path and pymechanical. so work around is once you save the version then dont use the version arg with ansys-mechanical use ansys-mechanical -i .\test.py --exit

note: Hope you already executed save-ansys-path --name mechanical /opt/apps/testapps/el7/software/staging/ANSYS/2023R2/v232/aisol/.workbench

CollinsJnr-001 commented 5 months ago

@dipinknair This is the result after running the code:

/users/.conda/envs/Pyansys/lib/python3.10/site-packages/click/core.py:783: UserWarning: Please ensure ExtAPI.Application.Close() is at the end of your script. Without this command, Batch mode will not terminate. return __callback(*args, **kwargs) Starting Ansys Mechanical version 2023R2 in Batch mode...

I guess HPC is solving without pymechanical.

What could then be the source of the problem?

dipinknair commented 5 months ago

@CollinsJnr-001 if you wait long enough to solve the model you should be seeing this log


Starting Ansys Mechanical version 2023R2 in Batch mode...
AnsMeshingServer, compiled May 30 2023 07:02:06, DS Mesher, Mon Apr 15 11:09:08 2024
AnsMeshingServer, okay, Mon Apr 15 11:09:09 2024
AnsMeshingServer, compiled May 30 2023 07:02:06, DS Mesher, Mon Apr 15 11:09:08 2024
AnsMeshingServer, okay, Mon Apr 15 11:09:09 2024
AnsMeshingServer, compiled May 30 2023 07:02:06, DS Mesher, Mon Apr 15 11:09:08 2024
AnsMeshingServer, okay, Mon Apr 15 11:09:09 2024
AnsMeshingServer, compiled May 30 2023 07:02:06, DS Mesher, Mon Apr 15 11:09:08 2024
AnsMeshingServer, okay, Mon Apr 15 11:09:09 2024
('**********', 'Solve completed', '**********')
('solve status = ', 'Done')
exit code: 0
exit code: 255
exit code: 255
exit code: 255
exit code: 255

please let me know if you are able to see solve status.

dipinknair commented 4 months ago

@CollinsJnr-001 any updates ?

CollinsJnr-001 commented 4 months ago

@dipinknair

Unfortunately, it keeps running with no results.

In many cases, it ran until my session timed out and then terminated with no results.

I also tried to run the script in Ansys mechanical GUI, but it didn't run successfully.

dipinknair commented 4 months ago

@dipinknair

Unfortunately, it keeps running with no results.

In many cases, it ran until my session timed out and then terminated with no results.

I also tried to run the script in Ansys mechanical GUI, but it didn't run successfully.

Since you were not able to run even in Mechanical GUI under scripting, it might be some other issue not releated to Mechancial. You can reachout here https://discuss.ansys.com/categories/structures .

You can add debug print statement and check on what line exactly it fails. if you want to see more logs please run the script like below ANSYS_WORKBENCH_LOGGING=1 ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL=0 ANSYS_WORKBENCH_LOGGING_CONSOLE=1 ansys-mechanical -i .\test.py --exit > log.txt 2>&1 please do share the log file here.

CollinsJnr-001 commented 4 months ago

log.txt

@dipinknair

This is the log after session time out

dipinknair commented 4 months ago

@CollinsJnr-001 I dont see any issue with pymechanical. It might be because of lacking some prerequisite. Please check this https://mechanical.docs.pyansys.com/version/stable/getting_started/wsl.html#install-the-centos7-wsl-distribution Try installing these and give it a try again.

dipinknair commented 4 months ago

@CollinsJnr-001 If you think this discussion solve the issue, please close this one or else this will be closed soon.

CollinsJnr-001 commented 4 months ago

@dipinknair Thank you for your help.

Hopefully, I will find the root of the problem.