#!/bin/bash

# =========================================================================
# OpenFOAM Grid Validation Study Case Updater Script
# =========================================================================

TEMPLATE_DIR="master_system_files"

PARENT_DIRS=(
    "grid3_Uniform_coarse"
    "grid2_Uniform_medium"
    "grid1_Uniform_fine"
)

if [ ! -d "$TEMPLATE_DIR" ]; then
    echo "ERROR: Template directory '$TEMPLATE_DIR' not found!"
    echo "Please create it and place controlDict, fvSchemes, and fvSolution inside."
    exit 1
fi

echo "Starting dictionary update..."
echo "---------------------------------------------------"

for parent in "${PARENT_DIRS[@]}"; do
    if [ -d "$parent" ]; then
        echo "Scanning $parent..."

        cp -f "$TEMPLATE_DIR/controlDict" "$parent/system/controlDict"
        cp -f "$TEMPLATE_DIR/fvSchemes"   "$parent/system/fvSchemes"
        cp -f "$TEMPLATE_DIR/fvSolution"  "$parent/system/fvSolution"

        echo "---------------------------------------------------"
    else
        echo "WARNING: Parent directory $parent not found. Skipping."
    fi
done

echo "Update complete! All cases have the new dictionary files."
