# -*- coding: utf-8 -*-
# Authors: Theodor Droschl, Lukas Maier
# Affiliation: Graz University of Technology, Institute of Process and Particle Engineering
# license: GNU Lesser General Public License v3.0
# Justfile for LIGGGHTS 2D Particle-Surface Simulation

# Default target
default: run

# Single simulation runs
run:
    @echo "Running LIGGGHTS simulation with dynamic templates..."
    @cd scripts/simulation && ./run_tripod_simulation_dynamic.sh
    @grep -A 5 "Finished calculating properties of template" scripts/simulation/log.liggghts | tail -6 > post/tripod_properties_mc.txt
    @python3 scripts/analysis/extract_properties.py

# Multiple simulation runs
multi-run:
    @echo "Running multiple LIGGGHTS simulations with dynamic templates..."
    @cd scripts/simulation && ./run_multiple_simulations_dynamic.sh

# Template and geometry generation
templates:
    @echo "Generating dynamic tripod templates..."
    @python3 scripts/generation/generate_dynamic_templates.py

wall-vtk:
    @echo "Creating wall VTK file..."
    @python3 scripts/generation/create_wall_vtk.py

# Combined targets
full: run

full-multi: multi-run

# Clean targets
clean:
    @echo "Cleaning output files..."
    @rm -rf post/
    @rm -f *.png
    @rm -f log.liggghts
    @rm -f restart_*.data
    @rm -f tripod_template*.txt
    @rm -f tripod_distribution.liggghts
    @rm -f tripod_templates.liggghts
    @echo "Clean completed."

clean-all: clean
    @echo "Cleaning all results including multiple runs..."
    @rm -rf results/multiple_runs_results/final_configs/
    @rm -rf results/multiple_runs_results/logs/
    @rm -rf results/multiple_runs_results/post_data/
    @rm -f results/multiple_runs_results/*.txt
    @rm -rf templates/
    @rm -f scripts/simulation/log.liggghts
    @rm -f scripts/simulation/restart_*.data
    @find results/multiple_runs_results/ -name "run_*" -type d -exec rm -rf {} + 2>/dev/null || true
    @echo "Deep clean completed."

# Show project structure
structure:
    @echo "Project Structure:"
    @tree -I '__pycache__|*.pyc' || find . -type d | head -20

# Show help
help:
    @echo "LIGGGHTS 2D Particle-Surface Simulation"
    @echo "======================================="
    @echo ""
    @echo "Simulation targets:"
    @echo "  run              - Run single LIGGGHTS simulation with dynamic templates"
    @echo "  multi-run        - Run multiple simulations (100 runs) with dynamic templates"
    @echo ""
    @echo "Generation targets:"
    @echo "  templates        - Generate dynamic tripod templates with distribution"
    @echo "  wall-vtk         - Create wall geometry VTK file"
    @echo ""
    @echo "Combined targets:"
    @echo "  full             - Run single simulation"
    @echo "  full-multi       - Run multiple simulations"
    @echo ""
    @echo "Cleaning targets:"
    @echo "  clean            - Remove basic output files"
    @echo "  clean-all        - Remove all output files including multiple runs"
    @echo ""
    @echo "Utility targets:"
    @echo "  structure        - Show project directory structure"
    @echo "  help             - Show this help message"
    @echo ""
    @echo "Requirements:"
    @echo "  - LIGGGHTS installed and in PATH"
    @echo "  - Python 3 with numpy (for validation scripts)"
    @echo ""
    @echo "Example usage:"
    @echo "  just run                 # Single simulation with dynamic templates"
    @echo "  just multi-run           # 100 simulations for statistics"
    @echo "  just full-multi          # Complete workflow with multiple runs"
    @echo "  just clean-all           # Clean everything"