What is the source of the ID of the selected geometry?
Hello!
I'm doing an easy steady state thermal simulation analysis and record it to mechanical script. By this repo I chose the remote session way to run it on HPC cluster to play pre process and solve. It successed for me. What I want to get is how the selected geometry ID is converted from an .stp geometry file?
Here are the specific steps I did:
Version
Ansys Mechanical 2023R1
What I did
record the whole simulation
import the .stp geometry file (a pan with a heating wire on the bottom);
generate the mesh;
add heat flow analysis of steady state thermal on the face where the heating wire is in contact with the bottom of the ;
add convert analysis of steady state thermal on the body;
do the solution about temperature.
I recorded all the steps, and got the script like here:
'''NOTE : All workflows will not be recorded, as recording is under development.''' geometry_import_12 = DataModel.GetObjectById(12) geometry_import_12.Import(r"C:\workspace\AnsysPanAPP\AnsysPanModel.stp") # Primary Source! with Transaction(True): body_28 = DataModel.GetObjectById(28) body_28.Material = "47139dc2-7f90-4271-bb9e-b55e52970f4e" ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM mesh_14 = Model.Mesh mesh_14.ElementSize = Quantity(1, "mm") mesh_14.GenerateMesh() sizing_39 = mesh_14.AddSizing() selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [828] sizing_39.Location = selection sizing_39.ElementSize = Quantity(0.5, "mm") analysis_20 = DataModel.GetObjectById(20) heat_flow_42 = analysis_20.AddHeatFlow() convection_43 = analysis_20.AddConvection() selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [796] heat_flow_42.Location = selection heat_flow_42.Magnitude.Output.SetDiscreteValue(0, Quantity(500, "W")) selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [477] convection_43.Location = selection convection_43.FilmCoefficient.Output.SetDiscreteValue(0, Quantity(5e-4, "W mm^-1 mm^-1 C^-1")) solution_21 = DataModel.GetObjectById(21) temperature_result_46 = solution_21.AddTemperature()
convert it to PyMechanical way
I modify some of the script and add it to a simple workflow based on PyMechanical like this
import ansys.mechanical.core as pymechanical wb_path = "/es01/home/zssoftware/Ansys/Ansys2023r1_gr/v231/aisol/.workbench" print("wb_path", wb_path) mechanical = pymechanical.launch_mechanical(exec_file=wb_path, verbose_mechanical=True, batch=True, loglevel="DEBUG", log_file=True, log_mechanical="pymechanical") print("mechanical launch success: ", mechanical) project_directory = mechanical.project_directory print(f"project directory = {project_directory}") 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_preferences.ProcessSurfaces = False #geo_import_preferences.ProcessNamedSelections = True #geo_import_preferences.NamedSelectionKey = "" 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="/es01/home/yuansuan/test_case/wanghao/ansys-231-pre-process/AnsysPanModel.stp") ) # mesh mechanical.run_python_script(""" mesh_14 = Model.Mesh mesh_14.ElementSize = Quantity(1, "mm") mesh_14.GenerateMesh() sizing_39 = mesh_14.AddSizing() selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [828] sizing_39.Location = selection sizing_39.ElementSize = Quantity(0.5, "mm") """ ) # add steadyStateThermalAnalysis mechanical.run_python_script(""" state_thermal_analysis = Model.AddSteadyStateThermalAnalysis() heat_flow_42 = state_thermal_analysis.AddHeatFlow() selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [796] 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(5e-4, "W mm^-1 mm^-1 C^-1")) state_thermal_analysis.Solution.AddTemperature() state_thermal_analysis.WriteInputFile("/es01/home/yuansuan/test_case/wanghao/ansys-231-pre-process/wanghao_test.dat") """) except Exception as e: print("An error occurred while running the Python script:", e) finally: print("exit mechanical instance") mechanical.exit() It runs good so that I can get the .dat file for my next step to do the solve.
Related infos
the pan looks like:
the raw pan.stp file are attached
What I want to know
I want to know the source of selection id.
Is it pointing at the geometry body(face / line or etc.)?
Is there any way that I can get the id at the very begining? Or is the selection id could mapped to the information of .stp file?
Or any idea about how could I get the seletion id in other ways?
Sorry for the long text to read and too many questions.
It's really important for me. Hope for some help!
Answers
-
Hi @wanghao , thanks for taking this to the forum. For traceability, just want to note that this was initially asked here.
The recording will show the ids of the geometry because it has no other way of identifying the faces, edges, etc that you have scoped. However, it is needed to modify these, because from a user perspective there is no way to know the ids, and if the geometry changes the ids will change too. The most robust way is to use Named Selections. See this post as an example.0 -
Hi @Pernelle Marone-Hitz , so glad to get your reply
I am actually focusing on finding a way to find the correspondence between the geometry in the .stp file and the geometry in ansys model. I'm not sure if my expression is correct and understandable.
I can get the all vertex coordinates from ansys and .stp. They can correspond one to one. This seems could establish a mapping relationship.Is there any more infos about ansys model geometry and .stp? Or can I get the processing of .stp geometry files after they are imported into ansys, that is, how they are turned into a list of IDs in ansys?
Thanks again! Feel sorry for my poor english haha. May cause the misunderstanding.
0 -
I'm afraid there isn't any information you can get about how the file is read. As you mentioned, coordinates will not change, but we have no control of how the ids are handled. I wouldn't recommended basing any scripts on ids or such, rather, create Named Selections. If you have some good filtering criteria you can even script the creation of Worksheet Named Selections.
0 -
Thanks for your reply and suggestion!
1