ansys / pyfluent

Pythonic interface to Ansys Fluent
https://fluent.docs.pyansys.com
MIT License
273 stars 40 forks source link

Enhanced PyFluent search #2745

Closed seanpearsonuk closed 5 months ago

seanpearsonuk commented 6 months ago

Current capabilities:

>>> import ansys.fluent.core as pf
>>> help(pf.search)
Help on function search in module ansys.fluent.core.utils.search:

search(word: str, match_whole_word: bool = False, match_case: bool = False, version: Optional[str] = None, search_root: Optional[Any] = None)
    Search for a word through the Fluent's object hierarchy.

    Parameters
    ----------
    word : str
        The word to search for.
    match_whole_word : bool, optional
        Whether to match whole word, by default False
    match_case : bool, optional
        Whether to match case, by default False
    version : str, optional
        Fluent version to search in, by default None in which case
        it will search in the latest version for which codegen was run.
    search_root : Any, optional
        The root object within which the search will be performed,
        can be a session object or any API object within a session,
        by default None in which case it will search everything.

    Examples
    --------
    >>> import ansys.fluent.core as pyfluent
    >>> pyfluent.search("geometry")
    <meshing_session>.tui.file.import_.cad_geometry (Command)
    <meshing_session>.tui.display.update_scene.select_geometry (Command)
    <meshing_session>.meshing.ImportGeometry (Command)
    <meshing_session>.meshing.LoadCADGeometry (Command)
    <solver_session>.tui.solve.initialize.compute_defaults.geometry (Command)
    <solver_session>.tui.report.reference_values.compute.geometry (Command)
    <solver_session>.tui.define.geometry (Command)
    <solver_session>.tui.mesh.geometry (Object)
    <solver_session>.setup.boundary_conditions.geometry["<name>"] (Object)
    <solver_session>.setup.geometry (Object)
    <solver_session>.solution.report_definitions.surface["<name>"].geometry (Parameter)
    <solver_session>.solution.report_definitions.volume["<name>"].geometry (Parameter)
    <solver_session>.results.graphics.mesh["<name>"].geometry (Parameter)
    <solver_session>.results.graphics.contour["<name>"].geometry (Parameter)

How might this be made more powerful? In general, it could be more like a search engine search. We can incorporate:

For the first two listed items at least, we found that the sematch Python library looked very promising in terms of its documented capabilities. Unfortunately, it is discontinued since Python 2.

We should research the ecosystem for libraries to support the above objectives.

seanpearsonuk commented 5 months ago

@hpohekar Please could you reply with the documented search() function signature that we all designed today? You could show it to the wider group for discussion tomorrow.

hpohekar commented 5 months ago
def search(
    search_string: str,
    language: Optional[str] = None,
    wildcard: bool = False,
    exact: bool = False,
    match_case=True,
):
    """Search for a word through the Fluent's object hierarchy.

    Parameters
    ----------
    search_string: str
        The word to search for. Semantic search is default.
    language: str
        The language for the semantic search. English is default for the semantic search.
        'albanian':'als', 'arabic':'arb', 'bulgarian':'bul', 'chinese_simplified':'cmn', 'chinese_traditional':'qcn',
        'danish':'dan', 'greek':'ell', 'english':'eng', 'persian':'fas', 'finnish':'fin', 'french':'fra',
        'hebrew':'heb', 'croatian':'hrv', 'icelandic':'isl', 'italian':'ita', 'japanese':'jpn', 'catalan':'cat',
        'basque':'eus', 'galicain':'glg', 'spanish':'spa', 'indonesian':'ind', 'malay':'zsm', 'dutch':'nld',
        'polish':'pol', 'portuguese':'por', 'romanian':'ron', 'lithuanian':'lit', 'slovak':'slk', 'slovene':'slv',
        'swedish':'swe', 'thai':'tha'
    wildcard: bool
        Whether to use wildcard pattern. If ``True`` will match wildcard pattern based on ``fnmatch`` module and
        will turn off semantic matching.
    exact: bool
        Whether to get exact match. If ``True`` will match exact string and will turn off semantic matching.
    match_case: bool
        Whether to match case. If ``False`` will match case-insensitive case.

    Examples
    ----------
    >>> import ansys.fluent.core as pyfluent
    >>> pyfluent.search("iterate")
    >>> pyfluent.search("iter*", wildcard=True)
    >>> pyfluent.search("*iter", wildcard=True)
    >>> pyfluent.search('读', 'cmn')   # search 'read' in Chinese
    The most similar API objects are:
    <solver_session>.file.read (Command)
    <solver_session>.file.import_.read (Command)
    <solver_session>.mesh.surface_mesh.read (Command)
    <solver_session>.tui.display.display_states.read (Command)
    <meshing_session>.tui.display.display_states.read (Command)
    """
seanpearsonuk commented 5 months ago

@hpohekar Thanks.

hpohekar commented 5 months ago

@seanpearsonuk

The examples that use wildcards will require wildcard=True. - Yes

The doc seems truncated on the right. - No. We have arranged it in the way to show all supported languages.

Are those the languages supported by the underlying API you are using? - Yes.

seanpearsonuk commented 5 months ago

@seanpearsonuk

The examples that use wildcards will require wildcard=True. - Yes

The doc seems truncated on the right. - No. We have arranged it in the way to show all supported languages.

Are those the languages supported by the underlying API you are using? - Yes.

Yes, it was rendering badly for me earlier, hence the truncation, but it is gone now. I mentioned the wildcard=True because this will be discussed via examples. I will update the examples.