Closed sjhsbhqf closed 6 months ago
When I edit the relevant source code TUI_ 231.py
to the following:
class user_defined(TUIMenu):
"""
Enters the user-defined functions and scalars menu.
"""
def __init__(self, service, version, mode, path):
self._service = service
self._version = version
self._mode = mode
self._path = path
self.function_hooks = self.__class__.function_hooks(service, version, mode, path + ["function_hooks"])
self.real_gas_models = self.__class__.real_gas_models(service, version, mode, path + ["real_gas_models"])
super().__init__(service, version, mode, path)
def auto_compile_compiled_udfs(self, *args, **kwargs):
"""
For this Fluent session, specify whether to allow auto-compilation of compiled UDF when a case file (or settings file) is read.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/auto_compile_compiled_udfs").execute(*args, **kwargs)
def compiled_functions(self, *args, **kwargs):
"""
Opens user-defined function library.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/compiled_functions").execute(*args, **kwargs)
def use_built_in_compiler(self, *args, **kwargs):
"""
Enables/disables the use of a built-in compiler (Clang) when the define/user-defined/compiled-functions text command is used. This text command / compiler is available for Windows only, and is provided as part of the ANSYS Fluent installation. It is recommended that you enable this text command when the compiler you installed on your machine is an older version that is no longer supported. Note that the built-in compiler is used automatically if Fluent determines that you have not installed Microsoft Visual Studio or Clang on your computer, whether this text command is enabled or not.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/use_built_in_compiler").execute(*args, **kwargs)
def interpreted_functions(self, *args, **kwargs):
"""
Loads interpreted user-defined functions.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/interpreted_functions").execute(*args, **kwargs)
def execute_on_demand(self, *args, **kwargs):
"""
Executes UDFs on demand.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/execute_on_demand").execute(*args, **kwargs)
def user_defined_memory(self, *args, **kwargs):
"""
Allocates user-defined memory.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/user_defined_memory").execute(*args, **kwargs)
def user_defined_node_memory(self, *args, **kwargs):
"""
Allocate user-defined node memory.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/user_defined_node_memory").execute(*args, **kwargs)
def use_contributed_cpp(self, *args, **kwargs):
"""
Enable/disable use of cpp from the Fluent.Inc/contrib directory.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/use_contributed_cpp").execute(*args, **kwargs)
def fan_model(self, *args, **kwargs):
"""
Configures user-defined fan model.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/fan_model").execute(*args, **kwargs)
def one_D_coupling(self, *args, **kwargs):
"""
Load 1D library.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/one_D_coupling").execute(*args, **kwargs)
def user_defined_scalars(self, *args, **kwargs):
"""
Defines user-defined scalars.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/user_defined_scalars").execute(*args, **kwargs)
def enable_udf_on_gpu(self, *args, **kwargs):
"""
Compile UDFs with OpenCL support.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/enable_udf_on_gpu").execute(*args, **kwargs)
def compile_customized_addon_module(self, *args, **kwargs):
"""
Compile customized addon module?.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/compile_customized_addon_module").execute(*args, **kwargs)
class function_hooks(TUIMenu):
"""
Hooks up user-defined functions.
"""
def __init__(self, service, version, mode, path):
self._service = service
self._version = version
self._mode = mode
self._path = path
super().__init__(service, version, mode, path)
def adjust(self, *args, **kwargs):
"""
Hook the adjust macro.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/function_hooks/adjust").execute(*args, **kwargs)
def execute_at_end(self, *args, **kwargs):
"""
Hook the execute_at_end macro.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/function_hooks/execute_at_end").execute(*args, **kwargs)
def execute_at_exit(self, *args, **kwargs):
"""
Hook the execute_at_exit macro.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/function_hooks/execute_at_exit").execute(*args, **kwargs)
class real_gas_models(TUIMenu):
"""
Enters the real-gas menu to enable/configure real gas model.
"""
def __init__(self, service, version, mode, path):
self._service = service
self._version = version
self._mode = mode
self._path = path
super().__init__(service, version, mode, path)
def nist_real_gas_model(self, *args, **kwargs):
"""
Loads the NIST real-gas library.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/real_gas_models/nist_real_gas_model").execute(*args, **kwargs)
def nist_multispecies_real_gas_model(self, *args, **kwargs):
"""
Loads the NIST real-gas library.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/real_gas_models/nist_multispecies_real_gas_model").execute(*args, **kwargs)
def set_state(self, *args, **kwargs):
"""
Selects the state for NIST real gas model.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/real_gas_models/set_state").execute(*args, **kwargs)
def nist_settings(self, *args, **kwargs):
"""
Specifies the name and the location for the REFPROP library and fluid files.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/real_gas_models/nist_settings").execute(*args, **kwargs)
def user_defined_real_gas_model(self, *args, **kwargs):
"""
Loads the user-defined real-gas library.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/real_gas_models/user_defined_real_gas_model").execute(*args, **kwargs)
def user_defined_multispecies_real_gas_model(self, *args, **kwargs):
"""
Loads a user-defined multispecies real-gas library.
"""
return PyMenu(self._service, self._version, self._mode, "/define/user_defined/real_gas_models/user_defined_multispecies_real_gas_model").execute(*args, **kwargs)
It's very strange that I still get errors when running the codeοΌ
RuntimeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_6064\1045546776.py in <module>
----> 1 solver.tui.define.user_defined.function_hooks.execute_at_end('"execute_at_end::libudf"')
D:\Anaconda3\lib\site-packages\ansys\fluent\core\services\datamodel_tui.py in __getattribute__(self, name)
303 # some runtime submenus are generated as methods during codegen
304 path = self._path + [name]
--> 305 if PyMenu(
306 self._service, self._version, self._mode, path
307 ).get_child_names():
D:\Anaconda3\lib\site-packages\ansys\fluent\core\services\datamodel_tui.py in get_child_names(self, include_unavailable)
169 if include_unavailable:
170 request.args["include_unavailable"] = 1
--> 171 response = self._service.get_attribute_value(request)
172 return _convert_gvalue_to_value(response.value)
173
D:\Anaconda3\lib\site-packages\ansys\fluent\core\services\error_handler.py in func(*args, **kwargs)
13 return f(*args, **kwargs)
14 except grpc.RpcError as ex:
---> 15 raise RuntimeError(ex.details()) from None
16
17 return func
RuntimeError: menu not found
The tui command is: /define/user-defined/function-hooks/execute-at-end "execute-at-end::libudf"
The PyConsole way that it works is: solver.tui.define.user_defined.function_hooks("execute-at-end", '"execute-at-end::libudf"')
@mkundu1, these are my findings so far. Please have a look into it and suggest if the behavior can be updated. Thank you.
π Before submitting the issue
π Description of the bug
error message when execute
solver.tui.define.user_defined.function_hooks.execute_at_end('"execute_at_end::libudf"')
π Steps to reproduce
I want to implement the functionality of the TUI command below
TUI command
/define/user_defined/function_hooks/execute_at_end "execute_at_end::libudf"
According to the official documentation, the correct Python command is
But I got an error message
π» Which operating system are you using?
Windows
π Which ANSYS version are you using?
ANSYS 2021R1
π Which Python version are you using?
3.9
π¦ Installed packages