Skip to content

Improve Clarity and Modernization of _Observing Events_ Example Code #3876

Open
@seanpearsonuk

Description

@seanpearsonuk

This issue pertains to the Observing Events example in the PyFluent documentation.

Current Example Code:

@execute_in_event_loop_threadsafe
def initialize_call_back(session, event_info: SolutionInitializedEventInfo | DataLoadedEventInfo):
    pyvista_windows_manager.refresh_windows(session.id, ["contour-1", "contour-2"])
    matplot_windows_manager.refresh_windows("", ["residual"])

callback_init_id = solver.events.register_callback(SolverEvent.SOLUTION_INITIALIZED, initialize_call_back)

Proposed Improvements:

  1. Avoid referencing old-style visualization interactions.

    • The example currently references pyvista_windows_manager and matplot_windows_manager, which may not align with the modern API direction. If visualization is necessary in the example, consider a more generic, high-level approach.
  2. Rename initialize_call_back() for clarity.

    • The function name should describe its purpose. A more intuitive name, such as refresh_windows(), would improve readability.
  3. Use callback= explicitly in register_callback().

    • Instead of solver.events.register_callback(SolverEvent.SOLUTION_INITIALIZED, initialize_call_back), write:
      solver.events.register_callback(SolverEvent.SOLUTION_INITIALIZED, callback=refresh_windows)
    • This makes it clearer that the second argument is the callback function.
  4. Remove callback_init_id if unused.

    • Since callback_init_id is not used after assignment, it should be omitted to avoid confusion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationDocumentation related (improving, adding, etc)

    Type

    No type

    Projects

    Status

    2025 Q2 Apr - Jun

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions