Error when AddMaterialAssignment in Linux Ansys Workbench 2023R1

wanghao
wanghao Member Posts: 27
10 Comments Name Dropper
**
edited April 28 in Structures

Hi, there.
I'm faceing a problem when using pyMechanical to do pre-process in Linux by Ansys Workbench 2023R1. Here is my script.

    mechanical = pymechanical.launch_mechanical(exec_file=workbench_path,
                                                verbose_mechanical=True,
                                                batch=True,
                                                loglevel="DEBUG",
                                                log_file=True,
                                                log_mechanical="pymechanical")
    print("mechanical launch success: ", mechanical)

    try:
        # import geometry file
        GEO_IMPORT_SCRIPT = """
geo_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic
geo_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()
geo_import = Model.GeometryImportGroup.AddGeometryImport()
geo_import.Import("{geo_path:s}", geo_import_format, geo_import_preferences)
    """
        mechanical.run_python_script(
            GEO_IMPORT_SCRIPT.format(geo_path=geo_path))

        # add analysis process
        RUN_COMMAND = """
import time

ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM

# import material
cmd = \"""
library0 = EngData.OpenLibrary(Name="General Materials", Source="General_Materials.xml")
system0 = GetSystem(Name="SYS")
engineeringData0 = system0.GetContainer(ComponentName="Engineering Data")
matl0 = engineeringData0.ImportMaterial(Name="Gray Cast Iron", Source="General_Materials.xml")
\"""

ExtAPI.Application.ScriptByName('journaling').ExecuteCommand(cmd)
ExtAPI.DataModel.Project.Model.RefreshMaterials()

# set material to body by DataModel.GetObjectsByName()
# with Transaction(True):
#     body_26 = DataModel.GetObjectsByName("Component1|Solid111")[0]
#     body_26.Material = "Gray Cast Iron"

# set material to body by material assignment
# ma0 = ExtAPI.DataModel.Project.Model.Materials.AddMaterialAssignment()
# ma0.Material = "Gray Cast Iron"
#selection0 = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
# selection0.Ids = [477]
# ma0.Location = selection0

mesh_14 = Model.Mesh
mesh_14.ElementSize = Quantity(1, "mm")
mesh_14.GenerateMesh()

state_thermal_analysis = Model.AddSteadyStateThermalAnalysis()
heat_flow_42 = state_thermal_analysis.AddHeatFlow()
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [777]
heat_flow_42.Location = selection
heat_flow_42.Magnitude.Output.SetDiscreteValue(0, Quantity(500, "W"))

convection_43 = state_thermal_analysis.AddConvection()
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [477]
convection_43.Location = selection
convection_43.FilmCoefficient.Output.SetDiscreteValue(0, Quantity(0.0005, "W mm^-1 mm^-1 C^-1"))

state_thermal_analysis.Solution.AddTemperature()
# generate dat file
state_thermal_analysis.WriteInputFile("{work_dir:s}/ds.dat")

"""
        mechanical.run_python_script(
            RUN_COMMAND.format(work_dir=work_dir)
        )

I tried two different ways to set material to specific body. Both works good on Windows but only the way that set material to body by DataModel.GetObjectsByName() works on Linux. Ansys Workbench version are all 2023R1. The way that set material to body by material assignment Linux shows the error like below:

INFO - GRPC_127.0.0.1:10000 -  mechanical - log_info - Mechanical connection is treated as local.
DEBUG - GRPC_127.0.0.1:10000 -  mechanical - log_debug - timetout:120 n_attempts:5 attempt_timeout=24.0
DEBUG - GRPC_127.0.0.1:10000 -  mechanical - log_debug - Connection attempt 1 with attempt timeout 24.0s
Initialize() started
Initialize() done
DEBUG - GRPC_127.0.0.1:10000 -  mechanical - log_debug - Connection attempt 2 with attempt timeout 24.0s
DEBUG - GRPC_127.0.0.1:10000 -  mechanical - log_debug - Established a connection to the Mechanical gRPC server.
INFO - GRPC_127.0.0.1:10000 -  mechanical - log_info - Waiting for Mechanical to be ready. Maximum wait time: 24.0s
INFO - GRPC_127.0.0.1:10000 -  mechanical - log_info - Mechanical is ready. It took 0 seconds to verify.
DEBUG - GRPC_127.0.0.1:10000 -  mechanical - log_debug - Connection attempt 2 succeeded.
INFO - GRPC_127.0.0.1:10000 -  mechanical - log_info - Mechanical is ready to accept grpc calls
mechanical launch success:  Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:231
Software build date:Sat Nov 26 20:15:28 2022
An error occurred while running the Python script: <_MultiThreadedRendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = ""
        debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"", grpc_status:2, created_time:"2024-04-26T10:41:55.42219409+08:00"}"
>
exit mechanical instance
DEBUG - GRPC_127.0.0.1:10000 -  mechanical - log_debug - In shutdown.
DEBUG - GRPC_127.0.0.1:10000 -  mechanical - log_debug - Shutting down...
DEBUG - GRPC_127.0.0.1:10000 -  mechanical - log_debug - No PyPIM cleanup is needed.
INFO - GRPC_127.0.0.1:10000 -  mechanical - log_info - Shutdown has finished.

Comments

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 85
    10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member
    ✭✭✭✭

    @wanghao Are you sure that this works in standalone mechanical on windows?

  • wanghao
    wanghao Member Posts: 27
    10 Comments Name Dropper
    **

    @Rajesh Meena
    Yep I'm sure. It works on windows but not work on linux by set material to body by material assignment

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 85
    10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member
    ✭✭✭✭

    @wanghao Is this resolved? How do you start the Pymechancial grpc server?