Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# CHANGELOG

## 2026-02-18

### Added

* Matter distribution selector for Janus initialization:
* `Core + halo`
* `Random mix`
* `Split on X`
* `Positive Ratio` parameter for random matter assignment.
* `Core + halo` extra-density slider:
* `Extra negative density inside core` in `[0, 1]`
* Batch simulation mode in executable:
* `--batch-steps N`
* `--snapshots K`
* `--output-dir DIR`
* `--config FILE` (load one config line)
* `--batch-config FILE` (run one simulation per line)
* Final snapshot export from multiple camera angles in batch mode.
* Run helper scripts:
* `run_sim.sh`
* `run_batch.sh`
* `run_batch.sh --batch-config batch_configs/example.batchcfg`
* `run_batch.sh` automatically uses root `batch_jobs.cfg` when present
* In-app batch export UI:
* set config output path
* append current `SIMCFG` line directly from the menu
* Root-level batch job template file: `batch_jobs.cfg`
* Camera preset in config lines:
* `camera_view=isometric|top`
* Root-level interactive startup config file: `simulation.cfg`

### Changed

* Rendering color convention aligned with Janus interpretation:
* positive/regular mass rendered in blue
* negative mass rendered in red
* Janus post-process shader simplified to preserve star channel data.
* Core+halo star assignment logic updated to match model:
* positive stars initialized in core sphere (`Type Diameter`)
* halo stars initialized as negative (outside core)
* `Extra negative density inside core` controls core negative injection in `[0, 1]`
* Startup logs now print assigned counts (`stars+`, `stars-`, `core`, `halo`).
* Restart logs now print full one-line configs (`SIMCFG key=value ...`) for copy/paste into batch files.

### Performance

* OpenCL command queue is initialized once and reused.
* Per-frame scalar parameters are now updated in existing OpenCL buffers.
* Removed unnecessary per-frame acceleration readback from GPU to CPU.
* OpenGL VBO is no longer reallocated every frame.
* Star type data is uploaded once at initialization/restart.
* Integer star type vertex attribute now uses `glVertexAttribIPointer`.

### Usage

Interactive run:

```bash
./build/Galaxy_simulation
bash run_sim.sh
```

Batch run:

```bash
./build/Galaxy_simulation --batch-steps 5000 --snapshots 4 --output-dir outputs/run_001
bash run_batch.sh 5000 4 outputs/run_001
bash run_batch.sh --batch-config batch_configs/example.batchcfg
```

### Validation checklist

* Build succeeds: `bash unix_run.sh`.
* Positive stars appear blue, negative stars appear red.
* Batch run generates `snapshot_*.png` in output directory.
* Runtime improves versus previous version for same star count and parameters.

### Known limitation

* Batch mode still requires an OpenGL/X11 context (not true headless yet).
278 changes: 272 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ This repository contains the source code of an n-body type simulation using GPU
* **[📋 Summary](#-summary)**
* **[🎥 Video](#-video)**
* **[✨ Features](#-features)**
* **[🐧 Build on Linux](#-build-on-linux)**
* **[🛠️ Install](#%EF%B8%8F-install)**
* [🦴 Skeleton project install](#-skeleton-project-install)
* [📦 Additionnal dependencies](#-additionnal-dependencies)
* [📦 Dependencies](#-dependencies)
* [▶️ Build](#%EF%B8%8F-build)
* [🚀 Run](#-run)
* [⚙️ Janus + Performance Update](#%EF%B8%8F-janus--performance-update)
* [🧪 Batch Experiment Workflow](#-batch-experiment-workflow)
* [✅ Validate Optimized Runs](#-validate-optimized-runs)
* [☁️ Cloud VM](#%EF%B8%8F-cloud-vm)
* [🧩 Troubleshooting](#-troubleshooting)
* **[📝 Changes](#-changes)**
* **[🧪 Simulation variants](#-simulation-variants)**
* **[🗓️ Releases](#%EF%B8%8F-releases)**
* **[🧪 Tests](#-tests)**
* **[🙏 Credits](#-credits)**
Expand Down Expand Up @@ -68,17 +77,274 @@ Here is a video explaining how the algorithm works : [<u>**Simuler 1 000 000 de

<br/>

# 🐧 Build on Linux

```bash
bash unix_run.sh
```

This script:

* initializes/upgrades git submodules (`--init --recursive`)
* configures CMake with `Unix Makefiles`
* uses the OpenCL include/library shipped in this repository
* builds the executable in `./build`

<br/>

# 🛠️ Install

## 🦴 Skeleton project install
## 📦 Dependencies

On Debian/Ubuntu:

```bash
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
libglew-dev \
freeglut3-dev \
ocl-icd-opencl-dev
```

On Arch Linux:

```bash
sudo pacman -S --needed \
base-devel \
cmake \
glew \
freeglut \
opencl-headers \
ocl-icd \
clinfo
```

Install at least one OpenCL implementation:

CPU fallback:

```bash
sudo pacman -S --needed pocl
```

NVIDIA GPU:

```bash
sudo pacman -S --needed opencl-nvidia
```

## ▶️ Build

If you clone for the first time:

```bash
git clone --recurse-submodules https://github.com/angeluriot/Galaxy_simulation.git
cd Galaxy_simulation
```

Then build:

```bash
bash unix_run.sh
```

## 🚀 Run

```bash
./build/Galaxy_simulation
```

Shortcut:

```bash
bash run_sim.sh
```

Default root config for normal (interactive) simulation:

* `simulation.cfg`
* when you run `bash run_sim.sh` with no extra arguments, this file is loaded automatically
* set `camera_view=top` in `simulation.cfg` for top-down startup

Batch run (compute N steps, then export final snapshots from multiple angles):

```bash
./build/Galaxy_simulation --batch-steps 2000 --snapshots 4 --output-dir outputs
```

Shortcut:

```bash
bash run_batch.sh 2000 4 outputs
```

Batch file (each line = one simulation job):

```bash
bash run_batch.sh --batch-config batch_configs/example.batchcfg
```

Default root config:

```bash
bash run_batch.sh
```

If `batch_jobs.cfg` exists at repository root, `run_batch.sh` uses it automatically.

## ⚙️ Janus + Performance Update

This branch includes:

* Janus star typing with explicit matter distributions:
* `Core + halo` (positive center, negative outer region)
* `Random mix` (positive ratio slider)
* `Split on X` (two spatial halves)
* `Core + halo` negative density control:
* `Extra negative density inside core` in `[0, 1]`
* `0`: core fully positive
* `1`: core fully negative
* in `Core + halo` mode: halo stars are always negative
* Janus force multipliers:
* `Negative Attraction Constant`
* `Repulsion Constant`
* Color convention:
* Positive/regular mass: **blue**
* Negative mass: **red**
* Performance optimizations:
* Reuse OpenCL command queue
* Reuse scalar OpenCL buffers and update them in-place
* Remove unnecessary per-frame acceleration readback
* Avoid per-frame OpenGL VBO reallocation
* Upload star type data only at initialization/restart

## 🧪 Batch Experiment Workflow

Use batch mode when you want to simulate many frames and only inspect final results:

```bash
./build/Galaxy_simulation --batch-steps 10000 --snapshots 6 --output-dir outputs/run_001
```

Run many jobs from one file (line-by-line):

This repository is based on my [**Graphics skeleton project**](https://github.com/angeluriot/Graphics_skeleton), so go see its [**install**](https://github.com/angeluriot/Graphics_skeleton#install) part first.
```bash
./build/Galaxy_simulation --batch-config batch_configs/example.batchcfg
```

Root-level default batch file:

```bash
./build/Galaxy_simulation --batch-config batch_jobs.cfg
```

Batch file format:

* each non-comment line is one job
* each line is `key=value` tokens
* lines can start with `SIMCFG`
* recommended keys per line:
* simulation: `simulation_type step smoothing_length interaction_rate nb_stars galaxy_diameter galaxy_thickness galaxies_distance stars_speed black_hole_mass negative_attraction_constant repulsion_constant matter_distribution type_diameter positive_ratio core_extra_negative_density camera_view`
* batch: `batch_steps snapshots output_dir`
* `camera_view` values:
* `isometric` (default)
* `top` (top-down start view)

Recommended workflow:

1. Start interactive mode (`./build/Galaxy_simulation`) and tune settings until the setup is close to your target physics.
2. Click `Restart` after changing any setting under `Applies after restart`.
3. In the menu, use `Batch config export`:
* set output file path (default: `batch_configs/user.batchcfg`)
* click `Append current SIMCFG to file`
4. Repeat for each setup you want to queue.
5. Run the whole file with:
```bash
bash run_batch.sh --batch-config batch_configs/user.batchcfg
```
6. Compare the exported snapshots across runs.

Choosing initial parameters:

* `Core + halo`:
* `Type Diameter` defines the positive core sphere.
* outside that sphere is halo and always negative.
* `Extra negative density inside core` injects negative stars into the core (`0` to `1`).
* start around `type_diameter = 0.4 * galaxy_diameter` and extra density `0.1`, then sweep.
* `Random mix`:
* use `Positive Ratio` (for example `0.2`, `0.5`, `0.8`) to test segregation behavior.
* `Split on X`:
* good for interface-instability tests.
* For reduced-particle experiments:
* decrease `nb_stars`
* compensate dynamics with `Negative Attraction Constant` and `Repulsion Constant`
* keep `step` and `smoothing_length` stable while you tune force multipliers.

## ✅ Validate Optimized Runs

Before launching cloud runs, validate local behavior:

1. Build and run:
```bash
bash unix_run.sh
./build/Galaxy_simulation
```
2. Confirm expected visuals:
* positive stars are blue
* negative stars are red
3. Confirm initialization counts in terminal logs:
* `[Init] stars+=... stars-=... core=... halo=...`
* this lets you verify the real positive/negative assignment for each restart
* a copy/paste one-line config is printed as:
`SIMCFG key=value ...`
4. Confirm batch export:
```bash
./build/Galaxy_simulation --batch-steps 2000 --snapshots 4 --output-dir outputs/check
```
5. Compare timing at same parameters before/after optimization.

Notes:

* Batch mode still needs an OpenGL/X11 context on Linux.
* For server VMs without display, use a virtual display (for example `xvfb`) or add a future true headless mode.

## ☁️ Cloud VM

For remote runs when your local machine is limited:

* setup VM dependencies + build: `bash cloud/setup_ubuntu_vm.sh`
* run interactive mode over VNC: `VNC_PASSWORD='change_me' bash cloud/start_live_vnc.sh`
* run headless batch: `bash cloud/run_headless_batch.sh --batch-config batch_configs/example.batchcfg`
* run queued batch files: `bash cloud/process_batch_queue.sh`

Full guide: [`cloud/README.md`](cloud/README.md)

## 📝 Changes

Detailed change log: see [`CHANGE.md`](CHANGE.md).

## 🧩 Troubleshooting

* `Could not find SFML`: make sure submodules are present (`git submodule update --init --recursive`).
* `Could NOT find OpenCL`: use `bash unix_run.sh` (it passes the required OpenCL paths).
* `No platforms found!`: OpenCL loader is present but no OpenCL driver ICD is installed.
On Arch Linux:
`sudo pacman -S --needed pocl` (CPU fallback) or install the NVIDIA-matching OpenCL package (for example `opencl-nvidia-580xx` for 580xx drivers).
Verify with `clinfo`: `Number of platforms` must be at least `1`.
* `Failed to open X11 display`: run from a desktop session with a valid `DISPLAY` variable.

<br/>

## 📦 Additionnal dependencies
# 🧪 Simulation variants

Then, you will also need the [**OpenCL**](https://www.khronos.org/opencl/) library.
* Add different star types at random in proportion.
* Add different star types from a diameter threshold (current modification).
* Select matter distribution in-app:
* `Core + halo`: positive core, negative halo
* `Random mix`: random positive/negative based on ratio
* `Split on X`: one half positive, one half negative

<br/>

Expand Down
5 changes: 5 additions & 0 deletions batch_configs/example.batchcfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Each non-comment line is one simulation job.
# You can copy/paste SIMCFG lines printed by the app and edit batch_* keys.

SIMCFG simulation_type=Galaxy step=0.001000 smoothing_length=1.000000 interaction_rate=0.050000 nb_stars=30000 galaxy_diameter=100.000000 galaxy_thickness=5.000000 galaxies_distance=75.000000 stars_speed=20.000000 black_hole_mass=1000.000000 negative_attraction_constant=1.000000 repulsion_constant=1.000000 matter_distribution=CoreHalo type_diameter=40.000000 positive_ratio=0.500000 core_extra_negative_density=0.000000 camera_view=isometric batch_steps=3000 snapshots=4 output_dir=outputs/run_core_clean
SIMCFG simulation_type=Galaxy step=0.001000 smoothing_length=1.000000 interaction_rate=0.050000 nb_stars=30000 galaxy_diameter=100.000000 galaxy_thickness=5.000000 galaxies_distance=75.000000 stars_speed=20.000000 black_hole_mass=1000.000000 negative_attraction_constant=1.000000 repulsion_constant=1.000000 matter_distribution=CoreHalo type_diameter=40.000000 positive_ratio=0.500000 core_extra_negative_density=0.200000 camera_view=top batch_steps=3000 snapshots=4 output_dir=outputs/run_core_mixed
1 change: 1 addition & 0 deletions batch_configs/user.batchcfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SIMCFG simulation_type=Galaxy step=0.001000 smoothing_length=1.000000 interaction_rate=0.050000 nb_stars=20000 galaxy_diameter=100.000000 galaxy_thickness=5.000000 galaxies_distance=75.000000 stars_speed=20.000000 black_hole_mass=1000.000000 negative_attraction_constant=1.000000 repulsion_constant=1.000000 matter_distribution=CoreHalo type_diameter=50.000000 positive_ratio=0.500000 core_extra_negative_density=0.000000 batch_steps=2000 snapshots=4 output_dir=outputs
6 changes: 6 additions & 0 deletions batch_jobs.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Galaxy simulation batch jobs
# One simulation per line. Copy/paste SIMCFG lines from terminal or menu export.
# Keys:
# simulation_type step smoothing_length interaction_rate nb_stars galaxy_diameter galaxy_thickness galaxies_distance stars_speed black_hole_mass negative_attraction_constant repulsion_constant matter_distribution type_diameter positive_ratio core_extra_negative_density camera_view batch_steps snapshots output_dir

SIMCFG simulation_type=Galaxy step=0.001000 smoothing_length=1.000000 interaction_rate=0.050000 nb_stars=30000 galaxy_diameter=100.000000 galaxy_thickness=5.000000 galaxies_distance=75.000000 stars_speed=20.000000 black_hole_mass=1000.000000 negative_attraction_constant=1.000000 repulsion_constant=1.000000 matter_distribution=CoreHalo type_diameter=40.000000 positive_ratio=0.500000 core_extra_negative_density=0.000000 camera_view=top batch_steps=3000 snapshots=4 output_dir=outputs/run_001
Loading