How epic-model/epic works
Based on our review of the complete file tree and the README, it’s clear that EPIC – “Elliptical Parcel-in-Cell” – is a scientific simulation tool written mostly in Fortran (with MPI support for parallelism) and complemented by Python scripts for analysis and visualization. Its purpose is to simulate parcel-based (likely fluid or atmospheric) processes in both 2D and 3D, while offering comprehensive configuration, diagnostic, and testing capabilities.
Project Type & Purpose
• This is a high-performance scientific simulation tool with a focus on parcel-in-cell methods.
• Its modules compute physical fields, manage parcel data, perform FFTs, and use MPI-based parallelization to simulate and analyze 2D/3D models.
• Additionally, there is extensive support for configuration, unit-testing, postprocessing (analysis), and visualization via Python.
Main Architectural Components
A. Build & Deployment Infrastructure:
• Autotools files (configure.ac, Makefile.am, m4 scripts) are used to manage the build process.
• The “dependencies” directory lists external libraries (HDF5, NetCDF, Scalasca, SCORE-P) that are integrated into the build.
B. Simulation Core:
• The “src” directory contains the heart of the computing kernels.
• Within src/2d and src/3d you find simulation drivers (epic2d.f90 and epic3d.f90) that integrate different sub-modules.
• Modules for fields and parcels are clearly separated, each with diagnostics, netCDF I/O, and other support.
• There’s an FFT subcomponent (src/fft) that handles spectral methods.
• The “stepper” subdirectories (in both 2d and 3d) implement time-stepping methods (e.g., rk4 variants).
• Utility modules (src/utils) encapsulate various support algorithms, numerical utilities, and physics subroutines.
C. Parallel Communication and MPI Integration:
• The “src/mpi” directory contains MPI-specific implementations (MPI environment, collectives, data types, communication utilities).
• These components ensure that the simulation scales across processing cores.
D. Physics Models:
• The “models” directory (with distinct 2d and 3d subdirectories) provides various physical model implementations (e.g., robert, taylor-green, beltrami).
• This layer abstracts the actual physical processes and numerical models that are plugged into the simulation core.
E. Additional Modules:
• “analyse”: Contains modules for performing post hoc analysis on 2D and 3D simulation results (likely generating specialized diagnostics).
• “merging_standalone”: Provides an independent example or test case for parcel merging using standalone approaches.
• “run-script”: Includes scripts to launch simulations using specific configurations (template.config, epic-run.py).
F. Data I/O Layer:
• The “src/netcdf” directory handles reading/writing simulation data in the NetCDF format.
• Configuration and example files (in examples and docs/manual) indicate how simulation runs are controlled.
G. Post-Processing and Visualization:
• “python-scripts” contains Python-based tools for plotting, animation, and diagnostics (using libraries like Matplotlib, Bokeh, etc.).
• These tools likely act as consumers of the netCDF output produced by the simulation, offering visualization and further analysis.
H. Testing and Quality Assurance:
• “unit-tests”, “mpi-tests”, and “time_step_tests” collectively cover a comprehensive suite for verifying simulation correctness.
• They target a variety of components – from MPI data handling to numerical accuracy in FFT computations and parcel physics.
I. Documentation & Examples:
• “docs” and “examples” provide the user manual, installation instructions, and sample configuration files which are critical for understanding runtime behavior.
Relationships and Data Flow
• Input Components: The simulation is configured via input files and templates (found in examples and run-script). These are fed into a configuration manager that sets up the simulation parameters.
• Simulation Core: The central engine (EPIC) uses the scientific models (from the “models” folder) and computation modules (in “src”, “fft”, and “mpi”) to perform simulations.
• I/O: Simulation results are written in NetCDF format which then serves as input for analysis.
• Post-Processing: Separate analysis components (Fortran-based in “analyse” and Python-based visualization in “python-scripts”) take simulation output and generate diagnostics, plots, or animations.
• Testing: At each stage, dedicated tests (unit-tests, mpi-tests) check computational integrity and parallel behavior.
• Build/Deployment: The autotools setup manages compilation and linking of all components with their dependencies.
Important Architectural Patterns & Design Principles
• Modularity: Careful separation of concerns by splitting simulation kernels, physical models, MPI utilities, and post-processing tools into dedicated directories.
• Layering: Clear layers for configuration input, computational core, I/O, and analysis.
• Reusability: Many modules (e.g., in src/utils and src/mpi) are designed to be reusable across both 2D and 3D simulations.
• Parallelism: MPI is deeply integrated as a first-class citizen allowing distributed computation.
• Testing Driven: A rich set of unit and integration tests ensures the simulation’s reliability on different system layers.