How notforgetwyn/codex-openfoam works
1. What this repository is
- FoamDesk is a desktop CFD client for OpenFOAM, not a web app.
- The hard boundary is between the PySide6/Qt GUI and the local OpenFOAM runtime in the same WSL/Linux environment.
- The app’s job is to wrap the OpenFOAM workflow: geometry, mesh, solver setup, execution, diagnostics, results, and reporting.
2. Top-level architecture
- The code is organized into four main layers under src/foamdesk:
- app/: startup and dependency wiring
- ui/: Qt windows, tabs, and visualization widgets
- services/: application use-cases and file/process orchestration
- integrations/: external-system integration, mainly OpenFOAM
- domain/: shared data models
- This is a classic UI → service → integration → filesystem/process flow.
3. Application bootstrap and lifecycle
- src/foamdesk/app/main.py and bootstrap.py are the entrypoint and composition root.
- StartupWindow and MainWindow define the user flow: project selection first, then the main case workspace.
- The startup layer appears to assemble services and hand them into the UI rather than letting UI code instantiate OpenFOAM logic directly.
4. UI subsystem
- src/foamdesk/ui/ is split by responsibility:
- main_window.py is the central shell
- main_window_*_logic.py files separate feature behavior for project, geometry, parameters, results, and settings
- draw_geometry_tab.py handles geometry authoring
- visualization_widgets.py contains the 3D/plot display widgets
- theme.py centralizes styling
- This suggests the UI is a feature-based Qt shell with isolated logic modules instead of one monolithic window class.
5. Service layer as the main orchestration boundary
- services/ contains the real application workflows:
- project_service.py for project/case management
- geometry_import_service.py for STL/geometry ingestion
- case_parameter_service.py and settings_service.py for case dictionary/config state
- result_index_service.py for discovering OpenFOAM result folders and time steps
- residual_plot_service.py and log_metric_service.py for solver-quality signals
- log_diagnostic_service.py for translating raw OpenFOAM logs into user-facing diagnoses
- metric_export_service.py and report_export_service.py for exports
- openfoam_vtk_service.py for loading simulation outputs into visualization-ready data
- These services are the key architectural boundary between UI actions and filesystem/OpenFOAM side effects.
6. OpenFOAM integration
- src/foamdesk/integrations/openfoam/environment.py is the main integration point for the external runtime.
- The README indicates commands are run locally via bash -lc / OpenFOAM bashrc sourcing, inside the same WSL/Linux environment.
- This is important architecturally: FoamDesk does not call a remote API; it shells out to the installed OpenFOAM toolchain and works against generated case directories.
7. Domain and case data
- domain/models.py holds the core data structures shared across UI and services.
- The application is case-centric: each project contains one or more OpenFOAM cases, and each case owns its geometry, dictionaries, logs, and results.
- The data model likely captures project metadata, case parameters, geometry placement, solver selection, and result indexing.
8. Filesystem as the primary persistence layer
- The app is built around a local workspace model, not a database.
- Runtime state lives in project/case directories: generated dictionaries, solver inputs, logs, result folders, and exported artifacts.
- The checked-in assets/test_geometries/ folder provides sample STL/CSV geometry inputs for development and testing.
- Files like foamdesk_run.log, foamdesk_debug.log, and report.md show the repo also produces operational artifacts and exportable reports.
9. Geometry and preprocessing flow
- Geometry can come from CSV-based primitives or imported STL meshes.
- The preprocessing path centers on generating OpenFOAM-ready geometry and mesh setup, including snappyHexMeshDict, then running blockMesh, snappyHexMesh, and checkMesh.
- The design implies a clear split between geometry authoring/import and mesh-generation orchestration.
10. Results and visualization flow
- Result handling is split into:
- indexing available OpenFOAM output
- loading field data
- rendering in embedded 3D widgets
- plotting residuals and metrics
- The README and services suggest the visualization stack uses VTK for 3D field data and Matplotlib for residual/metric plots.
- This is an internal post-processing boundary: the app does not rely on ParaView as its primary UI.
11. Diagnostics and reporting
- Raw solver output is not just displayed; it is parsed for common OpenFOAM failure modes and converted into Chinese-language guidance.
- Reporting is a separate export path, likely turning selected plots/images and run metadata into Markdown or image assets.
- This makes logs, metrics, and report generation a distinct subsystem rather than a UI-only feature.
12. Testing and quality boundaries
- tests/unit/ focuses on service and integration behavior, especially:
- environment setup
- project/case management
- log diagnostics
- metric extraction/export
- result indexing
- residual plotting
- VTK loading
- That test shape reinforces the architecture: most logic is expected to be in services and integration adapters, not in the UI.
13. Relevant technology footprint
- Core runtime: Python 3
- Desktop UI: PySide6 / Qt
- Numerical/data handling: NumPy, SciPy
- 2D plotting: Matplotlib
- 3D field/result handling: VTK
- Execution environment: WSL/Linux with local OpenFOAM installation
- Persistence: filesystem + local JSON/config-like artifacts, not a server or database
14. How to draw the system
- Draw the UI as the entry point on top.
- Put a central service layer beneath it with project, geometry, case-parameter, result, diagnostic, and export services.
- Draw OpenFOAM integration as a separate boundary below services, reached via local process execution.
- Show the filesystem/workspace as the main storage backend for cases, generated dictionaries, logs, and results.
- Add a side path from result services into VTK/Matplotlib-based visualization and report export.
Main entry points: main_window_results_logic.py Results Logic · models.py Models · main_window.py Main Window · environment.py OpenFOAM Env
Components 22
App
Startup and dependency wiring
UI
Qt windows, tabs, and visualization
- Startup · Project selection and initial flow
src/foamdesk/ui/startup_window.py - Main Window · Primary case workspace shell
src/foamdesk/ui/main_window.py - Geometry Tab · Geometry authoring and import entry
src/foamdesk/ui/draw_geometry_tab.py - Viz Widgets · 3D and plotting displays
src/foamdesk/ui/visualization_widgets.py - Project Logic · Project and case actions
src/foamdesk/ui/main_window_project_logic.py - Geometry Logic · Geometry workflow actions
src/foamdesk/ui/main_window_geometry_logic.py - Parameters Logic · Case parameter and settings actions
src/foamdesk/ui/main_window_parameters_logic.py - Results Logic · Results inspection and export actions
src/foamdesk/ui/main_window_results_logic.py - Physics Logic · Physics and settings actions
src/foamdesk/ui/main_window_settings_physics_logic.py
Services
Workflow orchestration and file/process use cases
- Project Service · Project and case lifecycle
src/foamdesk/services/project_service.py - Geometry Import · STL and primitive geometry ingestion
src/foamdesk/services/geometry_import_service.py - Case Params · Case dictionaries and parameter state
src/foamdesk/services/case_parameter_service.py - Result Index · Discovers result folders and time steps
src/foamdesk/services/result_index_service.py - Diagnostics · Parses solver logs into guidance
src/foamdesk/services/log_diagnostic_service.py - Metric Export · Exports solver metrics
src/foamdesk/services/metric_export_service.py - Report Export · Builds report artifacts
src/foamdesk/services/report_export_service.py - VTK Loader · Loads field data for visualization
src/foamdesk/services/openfoam_vtk_service.py
Integrations
External runtime adapters
- OpenFOAM Env · Local bash-sourced OpenFOAM execution
src/foamdesk/integrations/openfoam/environment.py
Workspace
Local case files and generated artifacts
- Workspace Files · Cases, dictionaries, logs, results, exports
Connections 40
- Main → Bootstrap: starts · Launches composition root
- Bootstrap → Startup: creates · Builds initial UI flow
- Bootstrap → Main Window: injects · Provides services to main shell
- Startup → Project Logic: selects project · Project selection and case entry
- Main Window → Project Logic: hosts · Project and case actions
- Main Window → Geometry Logic: hosts · Geometry workflow actions
- Main Window → Parameters Logic: hosts · Parameter and settings actions
- Main Window → Results Logic: hosts · Results and export actions
- Main Window → Physics Logic: hosts · Physics and settings actions
- Geometry Logic → Geometry Tab: drives · Geometry authoring UI
- Results Logic → Viz Widgets: renders · 3D and plot presentation
- Project Logic → Project Service: uses · Project lifecycle orchestration
- Geometry Logic → Geometry Import: uses · Imports and prepares geometry
- Parameters Logic → Case Params: uses · Case parameter editing
- Results Logic → Result Index: uses · Finds available outputs
- Results Logic → Diagnostics: uses · Turns logs into diagnostics
- Results Logic → Metric Export: uses · Exports metric data
- Results Logic → Report Export: uses · Exports report artifacts
- Results Logic → VTK Loader: uses · Loads simulation fields
- Project Service → Models: reads/writes · Shares case and project state
- Geometry Import → Models: reads/writes · Shares geometry state
- Case Params → Models: reads/writes · Shares case parameter state
- Result Index → Models: reads/writes · Uses case metadata for discovery
- Diagnostics → Models: reads · Interprets runs in domain terms
- Metric Export → Models: reads · Exports case metrics
- Report Export → Models: reads · Builds reports from case data
- VTK Loader → Models: reads · Maps case outputs to field data
- Project Service → Workspace Files: manages · Creates and opens project folders
- Geometry Import → Workspace Files: writes · Generates geometry and mesh inputs
- Case Params → Workspace Files: writes · Persists OpenFOAM dictionaries
- Result Index → Workspace Files: scans · Discovers result directories and times
- Diagnostics → Workspace Files: reads · Consumes solver logs
- Metric Export → Workspace Files: writes · Exports metrics files
- Report Export → Workspace Files: writes · Creates report artifacts
- VTK Loader → Workspace Files: reads · Loads result files
- Geometry Import → OpenFOAM Env: executes · Runs OpenFOAM mesh tools locally
- Case Params → OpenFOAM Env: executes · Writes and validates case setup
- Result Index → OpenFOAM Env: queries · Inspects runtime output layout
- Diagnostics → OpenFOAM Env: parses · Reads solver command output
- VTK Loader → OpenFOAM Env: loads via · Uses OpenFOAM result conventions