Closed CollinsJnr-001 closed 4 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("\\", "\\\\")
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("\", "\\")
usepart_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
@dipinknair
This is exactly one of the example in Pymechanical documentation, which you can find in link below
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.
@CollinsJnr-001 Hi , Could you please download the file using download
option from here
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
@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
mechanical.run_python_script( """ import os
geometry_import_group = Model.GeometryImportGroup geometry_import = geometry_import_group.AddGeometryImport()
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)
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
mesh = Model.Mesh mesh.ElementSize = Quantity(0.0025, "m")
mesh.GenerateMesh()
mesh.MeshMetric = MeshMetricType.ElementQuality
model = Model modal_analysis = model.AddModalAnalysis() modal_analysis_settings = DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.AnalysisSettings.ANSYSAnalysisSettings)
modal_analysis_settings = DataModel.GetObjectById(modal_analysis_settings[0].ObjectId) num_mode = 10 modal_analysis_settings.MaximumModesToFind = num_mode
fixed_support = modal_analysis.AddFixedSupport()
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [29] fixed_support.Location = selection
modal_analysis.Solve(True) modal_analysis_solution = DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.Solution) """) mechanical.clear() mechanical.exit(force= True)
@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.
@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
@dipinknair
Just to add, these examples ran very smoothly on my local Windows computer.
The problem is running it on Linux HPC
@CollinsJnr-001 test.zip
Could you please run this test.py
with 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.
@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
Linux HPC Platform: CentOS 7
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.
@dipinknair same error message
@dipinknair same error message
@CollinsJnr-001
What did you get when you run find-mechanical
?
@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
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
@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?
@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.
@CollinsJnr-001 any updates ?
@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
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 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.
@CollinsJnr-001 If you think this discussion solve the issue, please close this one or else this will be closed soon.
@dipinknair Thank you for your help.
Hopefully, I will find the root of the problem.
🔍 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
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()
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