diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..dfdb8b771 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/.github/workflows/composite-cmake/action.yml b/.github/actions/composite-cmake/action.yml similarity index 89% rename from .github/workflows/composite-cmake/action.yml rename to .github/actions/composite-cmake/action.yml index 51a51bf49..94629de7a 100644 --- a/.github/workflows/composite-cmake/action.yml +++ b/.github/actions/composite-cmake/action.yml @@ -8,7 +8,7 @@ runs: steps: - name: Install CMake ${{ matrix.cmake_version }} shell: bash - run: cmake -Dversion=${{ matrix.cmake_version }} -P .github/workflows/composite-cmake/install_cmake.cmake + run: cmake -Dversion=${{ matrix.cmake_version }} -P .github/actions/composite-cmake/install_cmake.cmake - name: CMake path shell: bash diff --git a/.github/workflows/composite-cmake/install_cmake.cmake b/.github/actions/composite-cmake/install_cmake.cmake similarity index 100% rename from .github/workflows/composite-cmake/install_cmake.cmake rename to .github/actions/composite-cmake/install_cmake.cmake diff --git a/.github/actions/composite-pkg/action.yml b/.github/actions/composite-pkg/action.yml new file mode 100644 index 000000000..af487251e --- /dev/null +++ b/.github/actions/composite-pkg/action.yml @@ -0,0 +1,28 @@ +name: Install Gemini3D build dependencies +description: Install dependencies for Gemini3D build + +runs: + + using: composite + + steps: + +# don't remove sudo apt update or every once in a while all the jobs will fail when the GA runner +# is out of sync with the upstream Ubuntu package repos + - name: Install packages (Linux) + shell: bash + if: runner.os == 'Linux' + run: | + sudo apt update + sudo apt install --no-install-recommends libscalapack-openmpi-dev libopenmpi-dev openmpi-bin libhdf5-dev liblapack-dev python3-h5py python3-scipy + + - name: Install packages (MacOS) + shell: bash + if: runner.os == 'macOS' + run: | + brew install open-mpi hdf5 scalapack numpy scipy + python_env="${RUNNER_TEMP}/gemini3d-python" + "$(brew --prefix)"/bin/python3 -m venv --system-site-packages "${python_env}" + echo "${python_env}/bin" >> "${GITHUB_PATH}" + echo "Python_ROOT_DIR=${python_env}" >> "${GITHUB_ENV}" + HDF5_DIR="$(brew --prefix hdf5)" "${python_env}"/bin/python -m pip install h5py diff --git a/.github/workflows/composite-unix/action.yml b/.github/actions/composite-unix/action.yml similarity index 100% rename from .github/workflows/composite-unix/action.yml rename to .github/actions/composite-unix/action.yml diff --git a/.github/lsan-openmpi.supp b/.github/lsan-openmpi.supp new file mode 100644 index 000000000..305b6d4f4 --- /dev/null +++ b/.github/lsan-openmpi.supp @@ -0,0 +1,12 @@ +# OpenMPI 4.x on Ubuntu 24.04 leaks hwloc allocations during MPI_Init(). +leak:ompi_mpi_init +# OpenMPI 4.x on Ubuntu 24.04 leaves process-lifetime allocations visible during MPI_Finalize(). +leak:orte_finalize +# OpenMPI 4.x on Ubuntu 24.04 leaves process-lifetime libevent thread allocations visible to LSAN. +leak:event_base_loop +# OpenMPI 4.x on Ubuntu 24.04 leaves one component-registration strdup visible to LSAN. +leak:mca_base_framework_components_register +# Ubuntu 24.04 OpenBLAS (0.3.26) leaves process-lifetime allocations visible to LSAN. +leak:libopenblasp-r0.3.26.so +# Ubuntu 24.04 UBSan runtime leaves process-lifetime allocations visible to LSAN. +leak:libubsan.so.1.0.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3bd1fbcd..dec14f315 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,8 @@ name: ci +permissions: + contents: read + env: HOMEBREW_NO_INSTALL_CLEANUP: 1 @@ -50,10 +53,10 @@ jobs: run: sudo apt install -y --no-install-recommends gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} gfortran-${{ matrix.gcc }} - &pkg - uses: ./.github/workflows/composite-pkg + uses: ./.github/actions/composite-pkg - &linux-build - uses: ./.github/workflows/composite-unix + uses: ./.github/actions/composite-unix hwm-msis: timeout-minutes: 15 @@ -89,6 +92,6 @@ jobs: - name: Install CMake ${{ matrix.cmake_version }} timeout-minutes: 10 - uses: ./.github/workflows/composite-cmake + uses: ./.github/actions/composite-cmake - run: $CMAKE --workflow --preset gmake diff --git a/.github/workflows/ci_macos.yml b/.github/workflows/ci_macos.yml index e05372ebf..d9885e830 100644 --- a/.github/workflows/ci_macos.yml +++ b/.github/workflows/ci_macos.yml @@ -1,5 +1,8 @@ name: ci_macos +permissions: + contents: read + env: HOMEBREW_NO_INSTALL_CLEANUP: 1 @@ -15,7 +18,6 @@ on: - "scripts/**" - "**.md" - jobs: macos: @@ -47,9 +49,9 @@ jobs: uses: actions/checkout@v7 - &pkg - uses: ./.github/workflows/composite-pkg + uses: ./.github/actions/composite-pkg - - uses: ./.github/workflows/composite-unix + - uses: ./.github/actions/composite-unix gnu_make: timeout-minutes: 15 diff --git a/.github/workflows/ci_windows.yml b/.github/workflows/ci_windows.yml index 5befd23d0..f605b811a 100644 --- a/.github/workflows/ci_windows.yml +++ b/.github/workflows/ci_windows.yml @@ -17,6 +17,9 @@ on: workflow_dispatch: +permissions: + contents: read + # avoid wasted runs concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -46,8 +49,8 @@ jobs: - uses: Vampire/setup-wsl@v7 with: distribution: Ubuntu-24.04 - additional-packages: - ninja-build gcc g++ gfortran libscalapack-openmpi-dev libopenmpi-dev openmpi-bin libhdf5-dev liblapack-dev + additional-packages: >- + make ninja-build gcc g++ gfortran libscalapack-openmpi-dev libopenmpi-dev openmpi-bin libhdf5-dev liblapack-dev python3-h5py python3-scipy use-cache: true wsl-shell-user: tester diff --git a/.github/workflows/composite-pkg/action.yml b/.github/workflows/composite-pkg/action.yml deleted file mode 100644 index a7372874d..000000000 --- a/.github/workflows/composite-pkg/action.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Install dependencies -description: Install dependencies for Linux and macOS - -runs: - - using: composite - - steps: - -# don't remove sudo apt update or every once in a while all the jobs will fail when the GA runner -# is out of sync with the upstream Ubuntu package repos - - name: Install packages (Linux) - shell: bash - if: runner.os == 'Linux' - run: | - sudo apt update - sudo apt install --no-install-recommends libscalapack-openmpi-dev libopenmpi-dev openmpi-bin libhdf5-dev liblapack-dev - - - name: Install packages (MacOS) - shell: bash - if: runner.os == 'macOS' - run: brew install open-mpi hdf5 scalapack diff --git a/.github/workflows/install-smoke.yml b/.github/workflows/install-smoke.yml new file mode 100644 index 000000000..d52dd3659 --- /dev/null +++ b/.github/workflows/install-smoke.yml @@ -0,0 +1,128 @@ +name: local-installation + +on: + pull_request: + push: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + CANDIDATE_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }} + OPENBLAS_NUM_THREADS: 1 + OMP_NUM_THREADS: 1 + OMPI_MCA_rmaps_base_oversubscribe: 1 + PRTE_MCA_rmaps_base_oversubscribe: 1 + GEMINI_ALLOW_STALE_APT_INDEX: 0 + +jobs: + unix: + name: install (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + os: [ubuntu-24.04, macos-14] + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ env.CANDIDATE_COMMIT }} + - name: Install through the supported local entrypoint + shell: bash + run: | + set -euo pipefail + test "$(git rev-parse HEAD)" = "$CANDIDATE_COMMIT" + mkdir -p build/installer-evidence build/scratch + git rev-parse HEAD > build/installer-evidence/candidate.txt + export TMPDIR="$PWD/build/scratch" + bash scripts/install-local.sh --system-deps --root "$PWD/build/local-install" --jobs 2 \ + 2>&1 | tee build/installer-evidence/install.log + - name: Verify installed environment without shell activation + shell: bash + run: | + set -euo pipefail + export TMPDIR="$PWD/build/scratch" + "$PWD/build/local-install/venv/bin/python" scripts/local_environment.py check \ + --root "$PWD/build/local-install" 2>&1 | tee build/installer-evidence/check.log + - name: Preserve exact-commit installation evidence + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: install-${{ matrix.os }}-${{ env.CANDIDATE_COMMIT }}-${{ github.run_id }}-${{ github.run_attempt }} + if-no-files-found: error + path: | + build/installer-evidence/ + build/local-install/environment.json + build/local-install/build/CMakeCache.txt + build/local-install/build/CMakeFiles/CMakeConfigureLog.yaml + build/local-install/build/Testing/ + build/local-install/build/local-*.xml + + wsl: + name: install (WSL Ubuntu-24.04) + runs-on: windows-latest + timeout-minutes: 90 + env: + GEMINI_ALLOW_STALE_APT_INDEX: 1 + steps: + - uses: Vampire/setup-wsl@d1da7f2c0322a5ee4f24975344f67fc0f5baf364 # v7.0.0 + with: + distribution: Ubuntu-24.04 + additional-packages: git + use-cache: false + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ env.CANDIDATE_COMMIT }} + - name: Install through the WSL local entrypoint + shell: pwsh + run: | + $ErrorActionPreference = "Stop" + $candidate = git rev-parse HEAD + if ($LASTEXITCODE -ne 0 -or $candidate -ne $env:CANDIDATE_COMMIT) { + throw "Checkout does not match the candidate" + } + New-Item -ItemType Directory -Force build/installer-evidence, build/scratch | Out-Null + $candidate | Set-Content build/installer-evidence/candidate.txt + $linuxRoot = & wsl.exe --distribution Ubuntu-24.04 --exec wslpath -a $env:GITHUB_WORKSPACE + if ($LASTEXITCODE -ne 0) { throw "Cannot locate checkout in WSL" } + $env:TMPDIR = "$($linuxRoot.Trim())/build/scratch" + $env:OMPI_ALLOW_RUN_AS_ROOT = "1" + $env:OMPI_ALLOW_RUN_AS_ROOT_CONFIRM = "1" + $forward = @("TMPDIR", "OPENBLAS_NUM_THREADS", "OMP_NUM_THREADS", + "OMPI_MCA_rmaps_base_oversubscribe", "PRTE_MCA_rmaps_base_oversubscribe", + "GEMINI_ALLOW_STALE_APT_INDEX", + "OMPI_ALLOW_RUN_AS_ROOT", + "OMPI_ALLOW_RUN_AS_ROOT_CONFIRM") + $env:WSLENV = ((@($env:WSLENV) + $forward) | Where-Object { $_ }) -join ":" + & ./scripts/install-local.ps1 -Distribution Ubuntu-24.04 -SystemDeps ` + -Root "$($linuxRoot.Trim())/build/local-install" -Jobs 2 ` + 2>&1 | Tee-Object build/installer-evidence/install.log + - name: Verify installed WSL environment without shell activation + shell: wsl-bash {0} + run: | + set -euo pipefail + export TMPDIR="$PWD/build/scratch" + export OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 + export OMPI_MCA_rmaps_base_oversubscribe=1 PRTE_MCA_rmaps_base_oversubscribe=1 + export OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 + "$PWD/build/local-install/venv/bin/python" scripts/local_environment.py check \ + --root "$PWD/build/local-install" 2>&1 | tee build/installer-evidence/check.log + - name: Preserve exact-commit WSL installation evidence + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: install-wsl-${{ env.CANDIDATE_COMMIT }}-${{ github.run_id }}-${{ github.run_attempt }} + if-no-files-found: error + path: | + build/installer-evidence/ + build/local-install/environment.json + build/local-install/build/CMakeCache.txt + build/local-install/build/CMakeFiles/CMakeConfigureLog.yaml + build/local-install/build/Testing/ + build/local-install/build/local-*.xml diff --git a/.github/workflows/oneapi-linux.yml b/.github/workflows/oneapi-linux.yml index b5c464f45..6927c55fa 100644 --- a/.github/workflows/oneapi-linux.yml +++ b/.github/workflows/oneapi-linux.yml @@ -15,8 +15,13 @@ on: - "docs/**" - "cmake/cray.cmake" - "**.md" + - "**.py" + - "**.sh" workflow_dispatch: +permissions: + contents: read + # avoid wasted runs concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -37,6 +42,11 @@ jobs: - uses: actions/checkout@v7 + - name: Install Python test dependencies + run: | + sudo apt update + sudo apt install --no-install-recommends python3-h5py python3-scipy + # this must be before oneAPI script commands else the scripts do not exist on the image - name: cache install oneAPI diff --git a/.github/workflows/preintegration.yml b/.github/workflows/preintegration.yml new file mode 100644 index 000000000..9bb6ee2de --- /dev/null +++ b/.github/workflows/preintegration.yml @@ -0,0 +1,205 @@ +name: preintegration + +on: + pull_request: + push: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash + +env: + CANDIDATE_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }} + CC: gcc + CXX: g++ + FC: gfortran + CMAKE_BUILD_PARALLEL_LEVEL: 2 + CTEST_PARALLEL_LEVEL: 2 + OPENBLAS_NUM_THREADS: 1 + OMP_NUM_THREADS: 1 + OMPI_MCA_rmaps_base_oversubscribe: 1 + PRTE_MCA_rmaps_base_oversubscribe: 1 + HDF5_PLUGIN_PRELOAD: "::" + +jobs: + native: + name: native (${{ matrix.build_type }}) + runs-on: ubuntu-24.04 + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + include: + - build_type: Debug + preset: qualification-debug + suffix: .debug + - build_type: Release + preset: qualification-release + suffix: "" + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ env.CANDIDATE_COMMIT }} + - uses: ./.github/workflows/qualification-setup + - name: Configure and build required qualification + run: | + cmake --preset ${{ matrix.preset }} -B build -DPython_EXECUTABLE="$(command -v python)" + cmake --build build --parallel 2 2>&1 | tee build/build.log + - name: Run native suite and reference comparisons + run: | + ctest --test-dir build --show-only=json-v1 > build/evidence/ctest-registration.json + python - <<'PY' + import json + from pathlib import Path + tests = {t["name"]: t for t in json.loads(Path("build/evidence/ctest-registration.json").read_text())["tests"]} + cases = ["mini2dns_fang", "mini2dew_fang", "mini3d_fang", "mini2dns_fang_cpp", + "mini2dns_glow", "mini2dew_glow", "mini3d_glow", "mini2dns_glow_cpp", "mini2dns_msis2_fang"] + for case in cases: + test = tests["gemini:compare:" + case] + if any(p["name"] == "DISABLED" and p["value"] for p in test.get("properties", [])): + raise RuntimeError("Required reference comparison disabled: " + case) + PY + ctest --test-dir build --output-on-failure --no-tests=error --output-junit native.xml 2>&1 | tee build/native.log + - name: Verify restart record precision and rejection behavior + run: | + python test/qualification/restart_core_checks.py \ + --exe build/gemini.bin${{ matrix.suffix }} --case build/test_runs/mini2dns_fang \ + --work build/restart-core 2>&1 | tee build/restart-core.log + - name: Qualify exact restart and native numerical budgets + run: | + python test/qualification/research_matrix.py --build build \ + --inputs-root build/test_runs --work build/research --suffix="${{ matrix.suffix }}" \ + --extended-layouts \ + 2>&1 | tee build/research.log + - name: Record actual dependency inventory + run: python scripts/qualification/inventory.py --source . --build build --output build/evidence/inventory.json + - name: Preserve native evidence + if: always() + uses: ./.github/workflows/qualification-evidence + with: + profile: native-${{ matrix.build_type }} + + current-hdf5: + name: current-hdf5 + runs-on: ubuntu-24.04 + timeout-minutes: 90 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ env.CANDIDATE_COMMIT }} + - uses: ./.github/workflows/qualification-setup + - name: Build verified current HDF5 + run: | + cmake -Dqualification_work="$GITHUB_WORKSPACE/build/hdf5-work" \ + -Dqualification_prefix="$GITHUB_WORKSPACE/build/hdf5-install" \ + -P scripts/build_qualification_hdf5.cmake 2>&1 | tee build/hdf5-build.log + - name: Build and test current-library profile + run: | + cmake --preset qualification-release -B build -DPython_EXECUTABLE="$(command -v python)" \ + -DHDF5_ROOT="$GITHUB_WORKSPACE/build/hdf5-install" -Dh5fortran_hdf5_nobuild=ON + grep -Fx 'HDF5_VERSION:STRING=2.2.0' build/CMakeCache.txt + cmake --build build --parallel 2 2>&1 | tee build/build.log + ctest --test-dir build --output-on-failure --no-tests=error --output-junit native.xml \ + 2>&1 | tee build/native.log + - name: Qualify current-library restart and numerical budgets + run: | + python test/qualification/restart_core_checks.py --exe build/gemini.bin \ + --case build/test_runs/mini2dns_fang --work build/restart-core \ + 2>&1 | tee build/restart-core.log + python test/qualification/research_matrix.py --build build \ + --inputs-root build/test_runs --work build/research 2>&1 | tee build/research.log + - name: Measure complete workload with kernel memory accounting + env: + GEMINI_QUALIFICATION_CGROUP: ${{ vars.GEMINI_QUALIFICATION_CGROUP }} + run: | + parent="${GEMINI_QUALIFICATION_CGROUP:-/sys/fs/cgroup}" + mkdir -p build/memory-workloads + if [ -z "${GEMINI_QUALIFICATION_CGROUP}" ] && [ ! -w "$parent" ]; then + printf '%s\n' "Skipped kernel memory accounting: $parent is not writable on this runner. Set GEMINI_QUALIFICATION_CGROUP to a delegated writable cgroup-v2 parent to enable this measurement." \ + | tee build/memory-workloads/skipped.txt + exit 0 + fi + for repetition in 1 2 3; do + mkdir -p "build/memory-workloads/$repetition" + cp -a build/test_runs/mini3d_fang/inputs "build/memory-workloads/$repetition/inputs" + python scripts/qualification/kernel_memory.py \ + --parent "$parent" \ + --output "build/memory-workloads/$repetition/measurement.json" \ + --wall-budget 600 --memory-budget-mib 2048 --timeout 660 -- \ + python scripts/qualification/run_research.py --exe build/gemini.bin \ + --case "build/memory-workloads/$repetition" --ranks 2 --layout 1 2 + done + - name: Record actual dependency inventory + if: always() + run: python scripts/qualification/inventory.py --source . --build build --output build/evidence/inventory.json + - name: Preserve current-library evidence + if: always() + uses: ./.github/workflows/qualification-evidence + with: + profile: current-hdf5 + + sanitizers: + name: sanitizers + runs-on: ubuntu-24.04 + timeout-minutes: 90 + env: + ASAN_OPTIONS: detect_leaks=0:halt_on_error=1 + UBSAN_OPTIONS: halt_on_error=1:print_stacktrace=1 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ env.CANDIDATE_COMMIT }} + - uses: ./.github/workflows/qualification-setup + - name: Build instrumented required qualification + run: | + cmake --preset qualification-debug -B build -Dgemini3d_sanitizers=ON \ + -DPython_EXECUTABLE="$(command -v python)" + cmake --build build --parallel 2 2>&1 | tee build/build.log + - name: Check audit probes and native C++ consumer + run: | + ctest --test-dir build -L 'audit|qualification' --output-on-failure --no-tests=error \ + --output-junit sanitizer.xml 2>&1 | tee build/sanitizer.log + ctest --test-dir build -R '^gemini:compare:mini2dns_fang_cpp$' --output-on-failure --no-tests=error \ + --output-junit cpp.xml 2>&1 | tee build/cpp.log + - name: Verify LeakSanitizer detects the intentional leak control + if: ${{ !cancelled() }} + run: python scripts/qualification/host_capabilities.py --only leak --work build/leak-control + - name: Check leaks in standalone ABI and interpolation probes + if: ${{ !cancelled() }} + env: + ASAN_OPTIONS: detect_leaks=1:halt_on_error=1 + LSAN_OPTIONS: exitcode=23 + run: | + ctest --test-dir build -R '^(audit:cabi|audit:interpolation|qualification:c_consumer)$' \ + --output-on-failure --no-tests=error --output-junit leaks.xml 2>&1 | tee build/leaks.log + - name: Check instrumented full-step Fortran and C++ checkpoints + if: ${{ !cancelled() }} + run: | + ctest --test-dir build -R '^(mini2dns_fang|mini3d_fang):download$' \ + --output-on-failure --no-tests=error + python test/qualification/research_matrix.py --build build --inputs-root build/test_runs \ + --work build/research --suffix=.debug 2>&1 | tee build/research.log + - name: Check leaks in the actual native application + if: ${{ !cancelled() }} + env: + ASAN_OPTIONS: detect_leaks=1:halt_on_error=1:fast_unwind_on_malloc=0 + LSAN_OPTIONS: exitcode=23:suppressions=${{ github.workspace }}/.github/lsan-openmpi.supp + PMIX_MCA_gds: hash + run: | + mkdir -p build/leak-application + cp -a build/test_runs/mini2dns_fang/inputs build/leak-application/inputs + python scripts/qualification/run_research.py --exe build/gemini.bin.debug \ + --case build/leak-application --ranks 2 --layout 1 2 2>&1 | tee build/leak-application.log + - name: Preserve sanitizer evidence + if: always() + uses: ./.github/workflows/qualification-evidence + with: + profile: sanitizers diff --git a/.github/workflows/qualification-evidence/action.yml b/.github/workflows/qualification-evidence/action.yml new file mode 100644 index 000000000..094899f38 --- /dev/null +++ b/.github/workflows/qualification-evidence/action.yml @@ -0,0 +1,55 @@ +name: Qualification evidence +description: Retain exact-commit diagnostics and hashed measurements, including failures +inputs: + profile: + description: Qualification build profile + required: true +runs: + using: composite + steps: + - name: Hash qualification evidence + shell: bash + run: | + mkdir -p build/evidence + python3 - <<'PY' + import hashlib, json + from pathlib import Path + files = set() + for name in ("Testing", "evidence", "test_runs", "research", + "restart-core", "leak-control", "leak-application", "memory-workloads"): + root = Path("build") / name + if root.is_dir(): + files.update(p for p in root.rglob("*") if p.is_file()) + for pattern in ("*.json", "*.log", "*.xml", "CMakeCache.txt", + "CMakeFiles/CMakeConfigureLog.yaml", "test/audit/*.json"): + files.update(p for p in Path("build").glob(pattern) if p.is_file()) + records = [] + for path in sorted(files): + if path.name == "sha256.json": + continue + with path.open("rb") as stream: + records.append({"path": str(path), "sha256": hashlib.file_digest(stream, "sha256").hexdigest()}) + Path("build/evidence/sha256.json").write_text(json.dumps(records, indent=2) + "\n") + PY + - name: Upload exact-commit qualification evidence + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: qualification-${{ inputs.profile }}-${{ env.CANDIDATE_COMMIT }}-${{ github.run_id }}-${{ github.run_attempt }} + if-no-files-found: error + retention-days: 14 + path: | + build/evidence/ + build/CMakeCache.txt + build/CMakeFiles/CMakeConfigureLog.yaml + build/*.log + build/*.json + build/*.xml + build/Testing/ + build/test/audit/*.json + build/test_runs/ + build/research/ + build/restart-core/ + build/leak-control/ + build/leak-application/ + build/memory-workloads/ diff --git a/.github/workflows/qualification-setup/action.yml b/.github/workflows/qualification-setup/action.yml new file mode 100644 index 000000000..f0e0404b3 --- /dev/null +++ b/.github/workflows/qualification-setup/action.yml @@ -0,0 +1,32 @@ +name: Qualification prerequisites +description: Install explicit native and pinned Python qualification prerequisites +runs: + using: composite + steps: + - name: Install qualification prerequisites + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + gcc g++ gfortran ninja-build openmpi-bin libopenmpi-dev \ + libhdf5-dev libopenblas-dev libscalapack-openmpi-dev zlib1g-dev \ + python3 python3-venv + mkdir -p build/scratch build/evidence + echo "TMPDIR=$GITHUB_WORKSPACE/build/scratch" >> "$GITHUB_ENV" + python3 -m venv build/tooling + build/tooling/bin/python -m pip install -r docs/qualification/requirements.txt + echo "$GITHUB_WORKSPACE/build/tooling/bin" >> "$GITHUB_PATH" + - name: Bind qualification to the exact candidate + shell: bash + run: | + test "$(git rev-parse HEAD)" = "$CANDIDATE_COMMIT" + python3 - <<'PY' + import json, os, subprocess + from pathlib import Path + record = {key: os.environ[key] for key in + ("CANDIDATE_COMMIT", "GITHUB_REPOSITORY", "GITHUB_RUN_ID", + "GITHUB_RUN_ATTEMPT", "GITHUB_EVENT_NAME")} + record["source_commit"] = subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip() + record["source_tree"] = subprocess.check_output(["git", "rev-parse", "HEAD^{tree}"], text=True).strip() + Path("build/evidence/candidate.json").write_text(json.dumps(record, indent=2) + "\n") + PY diff --git a/.gitignore b/.gitignore index 28fab45be..8f78e5471 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,15 @@ *.log.txt +*.log *.job *.job.* .DS_Store CMakeUserPresets.json + +# Local Python diagnostics and CI environment +__pycache__/ +*.py[cod] +.venv/ + +build/ +/build-*/ diff --git a/CMakeCache.txt b/CMakeCache.txt new file mode 100644 index 000000000..6deb82ec7 --- /dev/null +++ b/CMakeCache.txt @@ -0,0 +1,117 @@ +# This is the CMakeCache file. +# For build in directory: c:/Users/guygr/gemini3d +# It was generated by CMake: C:/Program Files/CMake/bin/cmake.exe +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//Release can be 10x faster simulation run time for gemini3d.run +// vs. Debug +CMAKE_BUILD_TYPE:STRING=Release + +//Value Computed by CMake. +CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=C:/Users/guygr/gemini3d/CMakeFiles/pkgRedirects + +//Program used to build from build.ninja files. +CMAKE_MAKE_PROGRAM:FILEPATH=CMAKE_MAKE_PROGRAM-NOTFOUND + +//Value Computed by CMake +CMAKE_PROJECT_COMPAT_VERSION:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_DESCRIPTION:STATIC=3-D ionospheric model + +//Value Computed by CMake +CMAKE_PROJECT_HOMEPAGE_URL:STATIC=https://github.com/gemini3d/gemini + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=gemini3d + +//Value Computed by CMake +CMAKE_PROJECT_SPDX_LICENSE:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_VERSION:STATIC=2.0.0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_MAJOR:STATIC=2 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_MINOR:STATIC=0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_PATCH:STATIC=0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_TWEAK:STATIC= + +//Value Computed by CMake +gemini3d_BINARY_DIR:STATIC=C:/Users/guygr/gemini3d + +//Value Computed by CMake +gemini3d_IS_TOP_LEVEL:STATIC=ON + +//Value Computed by CMake +gemini3d_SOURCE_DIR:STATIC=C:/Users/guygr/gemini3d + + +######################## +# INTERNAL cache entries +######################## + +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=c:/Users/guygr/gemini3d +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=4 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=4 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cmake.exe +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cpack.exe +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=C:/Program Files/CMake/bin/ctest.exe +//Set initial state for CMake diagnostics; used to persist state +// set by command-line options across invocations. +CMAKE_DIAGNOSTIC_INIT:INTERNAL=CMD_AUTHOR=WARN;CMD_DEPRECATED=WARN;CMD_EXPERIMENTAL=WARN;CMD_INSTALL_ABSOLUTE_DESTINATION=IGNORE;CMD_POLICY=WARN;CMD_UNINITIALIZED=IGNORE;CMD_UNUSED_CLI=WARN +//Path to cache edit program executable. +CMAKE_EDIT_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cmake-gui.exe +//Deprecated. Use -W[no-]error=deprecated instead. +CMAKE_ERROR_DEPRECATED:INTERNAL=OFF +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Ninja +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL= +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=C:/Users/guygr/gemini3d +//Name of CMakeLists files to read +CMAKE_LIST_FILE_NAME:INTERNAL=CMakeLists.txt +//ADVANCED property for variable: CMAKE_MAKE_PROGRAM +CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=C:/Program Files/CMake/share/cmake-4.4 +//Deprecated. Use -W[no-]deprecated instead. +CMAKE_WARN_DEPRECATED:INTERNAL=ON + diff --git a/CMakeFiles/4.4.3/CMakeSystem.cmake b/CMakeFiles/4.4.3/CMakeSystem.cmake new file mode 100644 index 000000000..909db20dc --- /dev/null +++ b/CMakeFiles/4.4.3/CMakeSystem.cmake @@ -0,0 +1,15 @@ +set(CMAKE_HOST_SYSTEM "Windows-10.0.19045") +set(CMAKE_HOST_SYSTEM_NAME "Windows") +set(CMAKE_HOST_SYSTEM_VERSION "10.0.19045") +set(CMAKE_HOST_SYSTEM_PROCESSOR "AMD64") + + + +set(CMAKE_SYSTEM "Windows-10.0.19045") +set(CMAKE_SYSTEM_NAME "Windows") +set(CMAKE_SYSTEM_VERSION "10.0.19045") +set(CMAKE_SYSTEM_PROCESSOR "AMD64") + +set(CMAKE_CROSSCOMPILING "FALSE") + +set(CMAKE_SYSTEM_LOADED 1) diff --git a/CMakeFiles/CMakeConfigureLog.yaml b/CMakeFiles/CMakeConfigureLog.yaml new file mode 100644 index 000000000..0defa3103 --- /dev/null +++ b/CMakeFiles/CMakeConfigureLog.yaml @@ -0,0 +1,530 @@ + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.4/Modules/CMakeDetermineSystem.cmake:218 (message)" + - "CMakeLists.txt:27 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 + - + kind: "find-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.4/Modules/CMakeNinjaFindMake.cmake:5 (find_program)" + - "CMakeLists.txt:27 (project)" + mode: "program" + variable: "CMAKE_MAKE_PROGRAM" + description: "Program used to build from build.ninja files." + settings: + SearchFramework: "NEVER" + SearchAppBundle: "NEVER" + CMAKE_FIND_USE_CMAKE_PATH: true + CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: true + CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: true + CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: true + CMAKE_FIND_USE_INSTALL_PREFIX: true + names: + - "ninja-build" + - "ninja" + - "samu" + candidate_directories: + - "C:/Program Files/PowerShell/7/" + - "C:/Program Files/Python312/Scripts/" + - "C:/Program Files/Python312/" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/" + - "C:/Python314/Scripts/" + - "C:/Python314/" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/" + - "C:/Python312/Scripts/" + - "C:/Python312/" + - "C:/Windows/System32/" + - "C:/Windows/" + - "C:/Windows/System32/wbem/" + - "C:/Windows/System32/WindowsPowerShell/v1.0/" + - "C:/Windows/System32/OpenSSH/" + - "C:/Program Files/dotnet/" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/" + - "C:/ProgramData/chocolatey/bin/" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/" + - "C:/Program Files/nodejs/" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/" + - "C:/Users/guygr/AppData/Roaming/npm/" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/" + - "C:/Program Files/heroku/bin/" + - "C:/Program Files/Amazon/AWSCLIV2/" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/" + - "C:/Program Files/GitHub CLI/" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/" + - "C:/Program Files/PostgreSQL/17/bin/" + - "C:/Program Files/PuTTY/" + - "C:/Terraform/" + - "C:/Program Files/Git/cmd/" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/" + - "C:/Program Files/CMake/bin/" + - "C:/Program Files/Docker/Docker/resources/bin/" + - "C:/Users/guygr/scoop/shims/" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/" + - "C:/Users/guygr/.local/bin/" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/" + searched_directories: + - "C:/Program Files/PowerShell/7/ninja-build.com" + - "C:/Program Files/PowerShell/7/ninja-build.exe" + - "C:/Program Files/PowerShell/7/ninja-build" + - "C:/Program Files/PowerShell/7/ninja.com" + - "C:/Program Files/PowerShell/7/ninja.exe" + - "C:/Program Files/PowerShell/7/ninja" + - "C:/Program Files/PowerShell/7/samu.com" + - "C:/Program Files/PowerShell/7/samu.exe" + - "C:/Program Files/PowerShell/7/samu" + - "C:/Program Files/Python312/Scripts/ninja-build.com" + - "C:/Program Files/Python312/Scripts/ninja-build.exe" + - "C:/Program Files/Python312/Scripts/ninja-build" + - "C:/Program Files/Python312/Scripts/ninja.com" + - "C:/Program Files/Python312/Scripts/ninja.exe" + - "C:/Program Files/Python312/Scripts/ninja" + - "C:/Program Files/Python312/Scripts/samu.com" + - "C:/Program Files/Python312/Scripts/samu.exe" + - "C:/Program Files/Python312/Scripts/samu" + - "C:/Program Files/Python312/ninja-build.com" + - "C:/Program Files/Python312/ninja-build.exe" + - "C:/Program Files/Python312/ninja-build" + - "C:/Program Files/Python312/ninja.com" + - "C:/Program Files/Python312/ninja.exe" + - "C:/Program Files/Python312/ninja" + - "C:/Program Files/Python312/samu.com" + - "C:/Program Files/Python312/samu.exe" + - "C:/Program Files/Python312/samu" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/ninja-build.com" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/ninja-build.exe" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/ninja-build" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/ninja.com" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/ninja.exe" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/ninja" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/samu.com" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/samu.exe" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin/samu" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/ninja-build.com" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/ninja-build.exe" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/ninja-build" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/ninja.com" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/ninja.exe" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/ninja" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/samu.com" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/samu.exe" + - "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/libnvvp/samu" + - "C:/Python314/Scripts/ninja-build.com" + - "C:/Python314/Scripts/ninja-build.exe" + - "C:/Python314/Scripts/ninja-build" + - "C:/Python314/Scripts/ninja.com" + - "C:/Python314/Scripts/ninja.exe" + - "C:/Python314/Scripts/ninja" + - "C:/Python314/Scripts/samu.com" + - "C:/Python314/Scripts/samu.exe" + - "C:/Python314/Scripts/samu" + - "C:/Python314/ninja-build.com" + - "C:/Python314/ninja-build.exe" + - "C:/Python314/ninja-build" + - "C:/Python314/ninja.com" + - "C:/Python314/ninja.exe" + - "C:/Python314/ninja" + - "C:/Python314/samu.com" + - "C:/Python314/samu.exe" + - "C:/Python314/samu" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/ninja-build.com" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/ninja-build.exe" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/ninja-build" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/ninja.com" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/ninja.exe" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/ninja" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/samu.com" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/samu.exe" + - "C:/Users/guygr/AppData/Local/Programs/cursor/resources/app/bin/samu" + - "C:/Python312/Scripts/ninja-build.com" + - "C:/Python312/Scripts/ninja-build.exe" + - "C:/Python312/Scripts/ninja-build" + - "C:/Python312/Scripts/ninja.com" + - "C:/Python312/Scripts/ninja.exe" + - "C:/Python312/Scripts/ninja" + - "C:/Python312/Scripts/samu.com" + - "C:/Python312/Scripts/samu.exe" + - "C:/Python312/Scripts/samu" + - "C:/Python312/ninja-build.com" + - "C:/Python312/ninja-build.exe" + - "C:/Python312/ninja-build" + - "C:/Python312/ninja.com" + - "C:/Python312/ninja.exe" + - "C:/Python312/ninja" + - "C:/Python312/samu.com" + - "C:/Python312/samu.exe" + - "C:/Python312/samu" + - "C:/Windows/System32/ninja-build.com" + - "C:/Windows/System32/ninja-build.exe" + - "C:/Windows/System32/ninja-build" + - "C:/Windows/System32/ninja.com" + - "C:/Windows/System32/ninja.exe" + - "C:/Windows/System32/ninja" + - "C:/Windows/System32/samu.com" + - "C:/Windows/System32/samu.exe" + - "C:/Windows/System32/samu" + - "C:/Windows/ninja-build.com" + - "C:/Windows/ninja-build.exe" + - "C:/Windows/ninja-build" + - "C:/Windows/ninja.com" + - "C:/Windows/ninja.exe" + - "C:/Windows/ninja" + - "C:/Windows/samu.com" + - "C:/Windows/samu.exe" + - "C:/Windows/samu" + - "C:/Windows/System32/wbem/ninja-build.com" + - "C:/Windows/System32/wbem/ninja-build.exe" + - "C:/Windows/System32/wbem/ninja-build" + - "C:/Windows/System32/wbem/ninja.com" + - "C:/Windows/System32/wbem/ninja.exe" + - "C:/Windows/System32/wbem/ninja" + - "C:/Windows/System32/wbem/samu.com" + - "C:/Windows/System32/wbem/samu.exe" + - "C:/Windows/System32/wbem/samu" + - "C:/Windows/System32/WindowsPowerShell/v1.0/ninja-build.com" + - "C:/Windows/System32/WindowsPowerShell/v1.0/ninja-build.exe" + - "C:/Windows/System32/WindowsPowerShell/v1.0/ninja-build" + - "C:/Windows/System32/WindowsPowerShell/v1.0/ninja.com" + - "C:/Windows/System32/WindowsPowerShell/v1.0/ninja.exe" + - "C:/Windows/System32/WindowsPowerShell/v1.0/ninja" + - "C:/Windows/System32/WindowsPowerShell/v1.0/samu.com" + - "C:/Windows/System32/WindowsPowerShell/v1.0/samu.exe" + - "C:/Windows/System32/WindowsPowerShell/v1.0/samu" + - "C:/Windows/System32/OpenSSH/ninja-build.com" + - "C:/Windows/System32/OpenSSH/ninja-build.exe" + - "C:/Windows/System32/OpenSSH/ninja-build" + - "C:/Windows/System32/OpenSSH/ninja.com" + - "C:/Windows/System32/OpenSSH/ninja.exe" + - "C:/Windows/System32/OpenSSH/ninja" + - "C:/Windows/System32/OpenSSH/samu.com" + - "C:/Windows/System32/OpenSSH/samu.exe" + - "C:/Windows/System32/OpenSSH/samu" + - "C:/Program Files/dotnet/ninja-build.com" + - "C:/Program Files/dotnet/ninja-build.exe" + - "C:/Program Files/dotnet/ninja-build" + - "C:/Program Files/dotnet/ninja.com" + - "C:/Program Files/dotnet/ninja.exe" + - "C:/Program Files/dotnet/ninja" + - "C:/Program Files/dotnet/samu.com" + - "C:/Program Files/dotnet/samu.exe" + - "C:/Program Files/dotnet/samu" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/ninja-build.com" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/ninja-build.exe" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/ninja-build" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/ninja.com" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/ninja.exe" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/ninja" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/samu.com" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/samu.exe" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X64/samu" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/ninja-build.com" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/ninja-build.exe" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/ninja-build" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/ninja.com" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/ninja.exe" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/ninja" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/samu.com" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/samu.exe" + - "C:/Program Files (x86)/Pulse Secure/VC142.CRT/X86/samu" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/ninja-build.com" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/ninja-build.exe" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/ninja-build" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/ninja.com" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/ninja.exe" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/ninja" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/samu.com" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/samu.exe" + - "C:/Program Files (x86)/Common Files/Pulse Secure/TNC Client Plugin/samu" + - "C:/ProgramData/chocolatey/bin/ninja-build.com" + - "C:/ProgramData/chocolatey/bin/ninja-build.exe" + - "C:/ProgramData/chocolatey/bin/ninja-build" + - "C:/ProgramData/chocolatey/bin/ninja.com" + - "C:/ProgramData/chocolatey/bin/ninja.exe" + - "C:/ProgramData/chocolatey/bin/ninja" + - "C:/ProgramData/chocolatey/bin/samu.com" + - "C:/ProgramData/chocolatey/bin/samu.exe" + - "C:/ProgramData/chocolatey/bin/samu" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/ninja-build.com" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/ninja-build.exe" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/ninja-build" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/ninja.com" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/ninja.exe" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/ninja" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/samu.com" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/samu.exe" + - "C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common/samu" + - "C:/Program Files/nodejs/ninja-build.com" + - "C:/Program Files/nodejs/ninja-build.exe" + - "C:/Program Files/nodejs/ninja-build" + - "C:/Program Files/nodejs/ninja.com" + - "C:/Program Files/nodejs/ninja.exe" + - "C:/Program Files/nodejs/ninja" + - "C:/Program Files/nodejs/samu.com" + - "C:/Program Files/nodejs/samu.exe" + - "C:/Program Files/nodejs/samu" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/ninja-build.com" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/ninja-build.exe" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/ninja-build" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/ninja.com" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/ninja.exe" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/ninja" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/samu.com" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/samu.exe" + - "C:/Users/guygr/AppData/Local/Microsoft/WindowsApps/samu" + - "C:/Users/guygr/AppData/Roaming/npm/ninja-build.com" + - "C:/Users/guygr/AppData/Roaming/npm/ninja-build.exe" + - "C:/Users/guygr/AppData/Roaming/npm/ninja-build" + - "C:/Users/guygr/AppData/Roaming/npm/ninja.com" + - "C:/Users/guygr/AppData/Roaming/npm/ninja.exe" + - "C:/Users/guygr/AppData/Roaming/npm/ninja" + - "C:/Users/guygr/AppData/Roaming/npm/samu.com" + - "C:/Users/guygr/AppData/Roaming/npm/samu.exe" + - "C:/Users/guygr/AppData/Roaming/npm/samu" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/ninja-build.com" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/ninja-build.exe" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/ninja-build" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/ninja.com" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/ninja.exe" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/ninja" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/samu.com" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/samu.exe" + - "C:/Users/guygr/AppData/Roaming/Python/Python312/Scripts/samu" + - "C:/Program Files/heroku/bin/ninja-build.com" + - "C:/Program Files/heroku/bin/ninja-build.exe" + - "C:/Program Files/heroku/bin/ninja-build" + - "C:/Program Files/heroku/bin/ninja.com" + - "C:/Program Files/heroku/bin/ninja.exe" + - "C:/Program Files/heroku/bin/ninja" + - "C:/Program Files/heroku/bin/samu.com" + - "C:/Program Files/heroku/bin/samu.exe" + - "C:/Program Files/heroku/bin/samu" + - "C:/Program Files/Amazon/AWSCLIV2/ninja-build.com" + - "C:/Program Files/Amazon/AWSCLIV2/ninja-build.exe" + - "C:/Program Files/Amazon/AWSCLIV2/ninja-build" + - "C:/Program Files/Amazon/AWSCLIV2/ninja.com" + - "C:/Program Files/Amazon/AWSCLIV2/ninja.exe" + - "C:/Program Files/Amazon/AWSCLIV2/ninja" + - "C:/Program Files/Amazon/AWSCLIV2/samu.com" + - "C:/Program Files/Amazon/AWSCLIV2/samu.exe" + - "C:/Program Files/Amazon/AWSCLIV2/samu" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/ninja-build.com" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/ninja-build.exe" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/ninja-build" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/ninja.com" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/ninja.exe" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/ninja" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/samu.com" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/samu.exe" + - "C:/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR/samu" + - "C:/Program Files/GitHub CLI/ninja-build.com" + - "C:/Program Files/GitHub CLI/ninja-build.exe" + - "C:/Program Files/GitHub CLI/ninja-build" + - "C:/Program Files/GitHub CLI/ninja.com" + - "C:/Program Files/GitHub CLI/ninja.exe" + - "C:/Program Files/GitHub CLI/ninja" + - "C:/Program Files/GitHub CLI/samu.com" + - "C:/Program Files/GitHub CLI/samu.exe" + - "C:/Program Files/GitHub CLI/samu" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/ninja-build.com" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/ninja-build.exe" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/ninja-build" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/ninja.com" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/ninja.exe" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/ninja" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/samu.com" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/samu.exe" + - "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/samu" + - "C:/Program Files/PostgreSQL/17/bin/ninja-build.com" + - "C:/Program Files/PostgreSQL/17/bin/ninja-build.exe" + - "C:/Program Files/PostgreSQL/17/bin/ninja-build" + - "C:/Program Files/PostgreSQL/17/bin/ninja.com" + - "C:/Program Files/PostgreSQL/17/bin/ninja.exe" + - "C:/Program Files/PostgreSQL/17/bin/ninja" + - "C:/Program Files/PostgreSQL/17/bin/samu.com" + - "C:/Program Files/PostgreSQL/17/bin/samu.exe" + - "C:/Program Files/PostgreSQL/17/bin/samu" + - "C:/Program Files/PuTTY/ninja-build.com" + - "C:/Program Files/PuTTY/ninja-build.exe" + - "C:/Program Files/PuTTY/ninja-build" + - "C:/Program Files/PuTTY/ninja.com" + - "C:/Program Files/PuTTY/ninja.exe" + - "C:/Program Files/PuTTY/ninja" + - "C:/Program Files/PuTTY/samu.com" + - "C:/Program Files/PuTTY/samu.exe" + - "C:/Program Files/PuTTY/samu" + - "C:/Terraform/ninja-build.com" + - "C:/Terraform/ninja-build.exe" + - "C:/Terraform/ninja-build" + - "C:/Terraform/ninja.com" + - "C:/Terraform/ninja.exe" + - "C:/Terraform/ninja" + - "C:/Terraform/samu.com" + - "C:/Terraform/samu.exe" + - "C:/Terraform/samu" + - "C:/Program Files/Git/cmd/ninja-build.com" + - "C:/Program Files/Git/cmd/ninja-build.exe" + - "C:/Program Files/Git/cmd/ninja-build" + - "C:/Program Files/Git/cmd/ninja.com" + - "C:/Program Files/Git/cmd/ninja.exe" + - "C:/Program Files/Git/cmd/ninja" + - "C:/Program Files/Git/cmd/samu.com" + - "C:/Program Files/Git/cmd/samu.exe" + - "C:/Program Files/Git/cmd/samu" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/ninja-build.com" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/ninja-build.exe" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/ninja-build" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/ninja.com" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/ninja.exe" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/ninja" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/samu.com" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/samu.exe" + - "C:/Program Files/NVIDIA Corporation/Nsight Compute 2022.3.0/samu" + - "C:/Program Files/CMake/bin/ninja-build.com" + - "C:/Program Files/CMake/bin/ninja-build.exe" + - "C:/Program Files/CMake/bin/ninja-build" + - "C:/Program Files/CMake/bin/ninja.com" + - "C:/Program Files/CMake/bin/ninja.exe" + - "C:/Program Files/CMake/bin/ninja" + - "C:/Program Files/CMake/bin/samu.com" + - "C:/Program Files/CMake/bin/samu.exe" + - "C:/Program Files/CMake/bin/samu" + - "C:/Program Files/Docker/Docker/resources/bin/ninja-build.com" + - "C:/Program Files/Docker/Docker/resources/bin/ninja-build.exe" + - "C:/Program Files/Docker/Docker/resources/bin/ninja-build" + - "C:/Program Files/Docker/Docker/resources/bin/ninja.com" + - "C:/Program Files/Docker/Docker/resources/bin/ninja.exe" + - "C:/Program Files/Docker/Docker/resources/bin/ninja" + - "C:/Program Files/Docker/Docker/resources/bin/samu.com" + - "C:/Program Files/Docker/Docker/resources/bin/samu.exe" + - "C:/Program Files/Docker/Docker/resources/bin/samu" + - "C:/Users/guygr/scoop/shims/ninja-build.com" + - "C:/Users/guygr/scoop/shims/ninja-build.exe" + - "C:/Users/guygr/scoop/shims/ninja-build" + - "C:/Users/guygr/scoop/shims/ninja.com" + - "C:/Users/guygr/scoop/shims/ninja.exe" + - "C:/Users/guygr/scoop/shims/ninja" + - "C:/Users/guygr/scoop/shims/samu.com" + - "C:/Users/guygr/scoop/shims/samu.exe" + - "C:/Users/guygr/scoop/shims/samu" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/ninja-build.com" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/ninja-build.exe" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/ninja-build" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/ninja.com" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/ninja.exe" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/ninja" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/samu.com" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/samu.exe" + - "C:/Users/guygr/AppData/Local/Programs/Microsoft VS Code/bin/samu" + - "C:/Users/guygr/.local/bin/ninja-build.com" + - "C:/Users/guygr/.local/bin/ninja-build.exe" + - "C:/Users/guygr/.local/bin/ninja-build" + - "C:/Users/guygr/.local/bin/ninja.com" + - "C:/Users/guygr/.local/bin/ninja.exe" + - "C:/Users/guygr/.local/bin/ninja" + - "C:/Users/guygr/.local/bin/samu.com" + - "C:/Users/guygr/.local/bin/samu.exe" + - "C:/Users/guygr/.local/bin/samu" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/ninja-build.com" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/ninja-build.exe" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/ninja-build" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/ninja.com" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/ninja.exe" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/ninja" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/samu.com" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/samu.exe" + - "C:/Users/guygr/AppData/Local/Programs/Ollama/samu" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/ninja-build.com" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/ninja-build.exe" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/ninja-build" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/ninja.com" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/ninja.exe" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/ninja" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/samu.com" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/samu.exe" + - "C:/Program Files/NVIDIA/CUDNN/v9.20/bin/12.9/x64/samu" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/ninja-build.com" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/ninja-build.exe" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/ninja-build" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/ninja.com" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/ninja.exe" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/ninja" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/samu.com" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/samu.exe" + - "C:/Users/guygr/AppData/Local/Programs/Aurion Beta/bin/samu" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/ninja-build.com" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/ninja-build.exe" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/ninja-build" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/ninja.com" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/ninja.exe" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/ninja" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/samu.com" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/samu.exe" + - "C:/Users/guygr/AppData/Local/Programs/MiKTeX/miktex/bin/x64/samu" + found: false + search_context: + ENV{PATH}: + - "C:\\Program Files\\PowerShell\\7" + - "C:\\Program Files\\Python312\\Scripts\\" + - "C:\\Program Files\\Python312\\" + - "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.8\\bin" + - "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.8\\libnvvp" + - "C:\\Python314\\Scripts\\" + - "C:\\Python314\\" + - "c:\\Users\\guygr\\AppData\\Local\\Programs\\cursor\\resources\\app\\bin" + - "C:\\Python312\\Scripts\\" + - "C:\\Python312\\" + - "C:\\Windows\\system32" + - "C:\\Windows" + - "C:\\Windows\\System32\\Wbem" + - "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\" + - "C:\\Windows\\System32\\OpenSSH\\" + - "C:\\Program Files\\dotnet\\" + - "C:\\Program Files (x86)\\Pulse Secure\\VC142.CRT\\X64\\" + - "C:\\Program Files (x86)\\Pulse Secure\\VC142.CRT\\X86\\" + - "C:\\Program Files (x86)\\Common Files\\Pulse Secure\\TNC Client Plugin\\" + - "C:\\ProgramData\\chocolatey\\bin" + - "C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common" + - "C:\\Program Files\\nodejs" + - "C:\\Users\\guygr\\AppData\\Local\\Microsoft\\WindowsApps" + - "C:\\Users\\guygr\\AppData\\Roaming\\npm" + - "C:\\Users\\guygr\\AppData\\Roaming\\Python\\Python312\\Scripts" + - "C:\\Program Files\\heroku\\bin" + - "c:\\Users\\guygr\\AppData\\Local\\Programs\\cursor\\resources\\app\\bin" + - "C:\\Program Files\\Amazon\\AWSCLIV2\\" + - "C:\\Program Files\\NVIDIA Corporation\\NVIDIA app\\NvDLISR" + - "C:\\Program Files\\GitHub CLI\\" + - "C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk\\bin" + - "C:\\Program Files\\PostgreSQL\\17\\bin" + - "C:\\Program Files\\PuTTY\\" + - "C:\\Terraform" + - "C:\\Program Files\\Git\\cmd" + - "C:\\Program Files\\nodejs\\" + - "C:\\Program Files\\NVIDIA Corporation\\Nsight Compute 2022.3.0\\" + - "C:\\Program Files\\PowerShell\\7\\" + - "C:\\Program Files\\CMake\\bin" + - "C:\\Program Files\\Docker\\Docker\\resources\\bin" + - "C:\\Users\\guygr\\scoop\\shims" + - "C:\\Users\\guygr\\AppData\\Local\\Microsoft\\WindowsApps" + - "C:\\Users\\guygr\\AppData\\Roaming\\Python\\Python312\\Scripts" + - "C:\\Program Files\\heroku\\bin" + - "C:\\Users\\guygr\\AppData\\Local\\Programs\\Microsoft VS Code\\bin" + - "C:\\Terraform" + - "C:\\Program Files\\PowerShell\\7\\" + - "C:\\Users\\guygr\\.local\\bin" + - "C:\\Users\\guygr\\AppData\\Roaming\\npm" + - "C:\\Users\\guygr\\AppData\\Local\\Programs\\Ollama" + - "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.8\\bin" + - "C:\\Program Files\\NVIDIA\\CUDNN\\v9.20\\bin\\12.9\\x64" + - "C:\\Users\\guygr\\AppData\\Local\\Programs\\Aurion Beta\\bin" + - "C:\\Users\\guygr\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\" +... diff --git a/CMakeFiles/cmake.check_cache b/CMakeFiles/cmake.check_cache new file mode 100644 index 000000000..3dccd7317 --- /dev/null +++ b/CMakeFiles/cmake.check_cache @@ -0,0 +1 @@ +# This file is generated by cmake for dependency checking of the CMakeCache.txt file diff --git a/CMakeLists.txt b/CMakeLists.txt index f966d8e0c..98e780086 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ set(CMAKE_CXX_SCAN_FOR_MODULES OFF) include(cmake/package/git_rev.cmake) include(options.cmake) +include(cmake/sanitizers.cmake) set(CMAKE_CXX_STANDARD 17) @@ -49,6 +50,18 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED ON) file(READ cmake/libraries.json json) +function(fetchcontent_github_with_codeload name stem archive sha256) + set(url "${stem}${archive}") + string(REGEX MATCH "^https://github\\.com/([^/]+/[^/]+)/archive/$" _match "${stem}") + if(_match) + string(REPLACE ".tar.gz" "" ref "${archive}") + set(codeload_url "https://codeload.github.com/${CMAKE_MATCH_1}/tar.gz/${ref}") + FetchContent_Declare(${name} URL ${url} ${codeload_url} URL_HASH SHA256=${sha256}) + else() + FetchContent_Declare(${name} URL ${url} URL_HASH SHA256=${sha256}) + endif() +endfunction() + # Fortran filesystem library "ffilesystem" set(ffilesystem_fallback true) set(ffilesystem_extra false) @@ -56,8 +69,8 @@ set(HAVE_F03TYPE false) # may need fallback for old or slightly broken compilers string(JSON _stem GET "${json}" "ffilesystem" "stem") string(JSON _archive GET "${json}" "ffilesystem" "archive") -set(ffilesystem_url ${_stem}${_archive}) -FetchContent_Declare(ffilesystem URL ${ffilesystem_url}) +string(JSON _sha256 GET "${json}" "ffilesystem" "sha256") +fetchcontent_github_with_codeload(ffilesystem "${_stem}" "${_archive}" "${_sha256}") FetchContent_MakeAvailable(ffilesystem) # find python before excluding Anaconda @@ -80,8 +93,8 @@ include(cmake/mpi.cmake) # --- HDF5 string(JSON _stem GET "${json}" "h5fortran" "stem") string(JSON _archive GET "${json}" "h5fortran" "archive") -set(h5fortran_url "${_stem}${_archive}") -FetchContent_Declare(h5fortran URL ${h5fortran_url}) +string(JSON _sha256 GET "${json}" "h5fortran" "sha256") +fetchcontent_github_with_codeload(h5fortran "${_stem}" "${_archive}" "${_sha256}") FetchContent_MakeAvailable(h5fortran) # h5fortran is a high-level, object-oriented HDF5 interface. @@ -108,8 +121,8 @@ set(BUILD_COMPLEX16 off) string(JSON _stem GET "${json}" "mumps" "stem") string(JSON _archive GET "${json}" "mumps" "archive") -set(mumps_url "${_stem}${_archive}") -FetchContent_Declare(mumps URL ${mumps_url}) +string(JSON _sha256 GET "${json}" "mumps" "sha256") +fetchcontent_github_with_codeload(mumps "${_stem}" "${_archive}" "${_sha256}") FetchContent_MakeAvailable(mumps) set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL false) @@ -118,16 +131,16 @@ set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL false) if(gemini3d_glow) string(JSON _stem GET "${json}" "glow" "stem") string(JSON _archive GET "${json}" "glow" "archive") - set(glow_url "${_stem}${_archive}") - FetchContent_Declare(glow URL ${glow_url}) + string(JSON _sha256 GET "${json}" "glow" "sha256") + fetchcontent_github_with_codeload(glow "${_stem}" "${_archive}" "${_sha256}") FetchContent_MakeAvailable(glow) endif() if(gemini3d_hwm14) string(JSON _stem GET "${json}" "hwm14" "stem") string(JSON _archive GET "${json}" "hwm14" "archive") - set(hwm14_url "${_stem}${_archive}") - FetchContent_Declare(hwm14 URL ${hwm14_url}) + string(JSON _sha256 GET "${json}" "hwm14" "sha256") + fetchcontent_github_with_codeload(hwm14 "${_stem}" "${_archive}" "${_sha256}") FetchContent_MakeAvailable(hwm14) endif() @@ -138,8 +151,8 @@ endif() set(msis_BUILD_UTILS on) string(JSON _stem GET "${json}" "msis" "stem") string(JSON _archive GET "${json}" "msis" "archive") -set(msis_url "${_stem}${_archive}") -FetchContent_Declare(msis URL ${msis_url}) +string(JSON _sha256 GET "${json}" "msis" "sha256") +fetchcontent_github_with_codeload(msis "${_stem}" "${_archive}" "${_sha256}") FetchContent_MakeAvailable(msis) set_target_properties(msis_setup PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) if(gemini3d_msis2) diff --git a/CMakePresets.json b/CMakePresets.json index 5ec528e40..120353f7d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -30,6 +30,31 @@ "gemini3d_hwm14": true } }, +{ + "name": "qualification", "inherits": "default", + "hidden": true, + "cacheVariables": { + "BUILD_TESTING": true, + "gemini3d_BUILD_TESTING": true, + "gemini3d_require_qualification": true, + "gemini3d_test_simulations": true, + "gemini3d_realbits": "64", + "gemini3d_glow": true, + "gemini3d_msis2": true, + "gemini3d_hwm14": false, + "MPIEXEC_MAX_NUMPROCS": "2" + } +}, +{ + "name": "qualification-debug", "inherits": "qualification", + "binaryDir": "build-qualification-debug", + "cacheVariables": {"CMAKE_BUILD_TYPE": "Debug"} +}, +{ + "name": "qualification-release", "inherits": "qualification", + "binaryDir": "build-qualification-release", + "cacheVariables": {"CMAKE_BUILD_TYPE": "Release"} +}, { "name": "linux", "inherits": "default", "displayName": "Linux build (for WSL on GHA)", @@ -76,6 +101,11 @@ { "name": "debug", "inherits": "default", "configurePreset": "debug", "configuration": "Debug" } ], "testPresets": [ +{ + "name": "offline", "inherits": "default", + "displayName": "Run with pre-cached reference archives; no network fetch allowed", + "environment": {"GEMINI3D_OFFLINE": "1"} +}, { "name": "default", "configurePreset": "default", diff --git a/Readme.md b/Readme.md index 8fbaeeae1..a7285caa7 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,11 @@ # GEMINI +> Audit snapshot, 16 September 2026. This tree contains documented corrections to +> upstream commit `aa50fa1a34c374edaf7e1c79e6d330e4025f777c`. +> Read [the development handoff](docs/PREINTEGRATION.md) and [audit profile](docs/Readme_audit.md) +> before using it. This is a development candidate, not an upstream release or +> a physically validated digital twin. Consult the validation report for native regression results and remaining science gates. + [![DOI](https://zenodo.org/badge/146920930.svg)](https://zenodo.org/badge/latestdoi/146920930) [![ci](https://github.com/gemini3d/gemini3d/actions/workflows/ci.yml/badge.svg)](https://github.com/gemini3d/gemini3d/actions/workflows/ci.yml) [![macOS CI](https://github.com/gemini3d/gemini3d/actions/workflows/ci_macos.yml/badge.svg)](https://github.com/gemini3d/gemini3d/actions/workflows/ci_macos.yml) @@ -59,10 +65,18 @@ Requirements: * Cray with GCC or Intel oneAPI backend * Python and/or MATLAB for scripting front- and back-ends * CMake: if your CMake is too old, [download](https://cmake.org/download/) or `python -m pip install cmake` -* MPI: any of OpenMPI, IntelMPI, MPICH, MS-MPI. See [MPI help](./docs/Readme_mpi.md) if needed. Without MPI, Gemini3D uses one CPU core only, which runs much more slowly than with MPI. +* MPI: any of OpenMPI, IntelMPI, MPICH, MS-MPI. See [MPI help](./docs/Readme_mpi.md) if needed. The current CMake build requires MPI even for a one-process run. ### Gemini3D setup +For a local Python/build/install environment with dependency installation and +verification, use `scripts/install-local.sh --system-deps` on Debian/Ubuntu, +macOS, or Windows WSL. Windows PowerShell users can invoke +`scripts/install-local.ps1 -SystemDeps`. See +[local environment setup](docs/Readme_prereqs.md#verified-local-environment) +for prerequisites, runtime checks, offline limitations, and full-reference testing. +Omit `--system-deps` to use an already provisioned native toolchain. + Obtain the Gemini3D source code: ```sh diff --git a/app/cli_utils.h b/app/cli_utils.h new file mode 100644 index 000000000..2a5d1eb28 --- /dev/null +++ b/app/cli_utils.h @@ -0,0 +1,59 @@ +// Audit addition 2026-09-16. Apache-2.0; see ../LICENSE. +#ifndef GEMINI_CLI_UTILS_H +#define GEMINI_CLI_UTILS_H +#include +#include +#include +#include +#include +#include +#include "gemini3d.h" +namespace gemini_cli { +inline bool positive_int(std::string_view s, int& value) { + if (s.empty()) return false; + const auto result = std::from_chars(s.data(), s.data()+s.size(), value); + return result.ec == std::errc{} && result.ptr == s.data()+s.size() && value > 0; +} +inline bool copy_outdir(std::string_view s, char* target, std::size_t capacity) { + if (s.size() >= capacity || s.find('\0') != std::string_view::npos) return false; + std::memcpy(target, s.data(), s.size()); + target[s.size()] = '\0'; + return true; +} +inline bool parse_options(int argc, char** argv, params& p, int& d2, int& d3, + bool& help, std::string& error) { + help = false; + for (int i=2; i= argc || !positive_int(argv[i+1], d2) || !positive_int(argv[i+2], d3)) { + error = "-manual_grid requires two positive integer counts"; + return false; + } + i += 2; + } else { + error = "Unsupported C++ option: " + std::string(a) + "; use gemini.bin for additional Fortran CLI options"; + return false; + } + } + return true; +} +inline std::size_t checked_product(std::size_t a, std::size_t b) { + if (b && a > std::numeric_limits::max()/b) + throw std::overflow_error("size_t allocation overflow"); + return a*b; +} +inline std::size_t cell_count(int x1, int x2, int x3) { + if (x1 <= 0 || x2 <= 0 || x3 <= 0) throw std::invalid_argument("grid sizes must be positive"); + auto cells = std::size_t{1}; + for (const int x : {x1, x2, x3}) cells = checked_product(cells, static_cast(x)+4); + return cells; +} +inline std::size_t array_bytes(std::size_t cells, std::size_t fields) { + return checked_product(checked_product(cells, fields), sizeof(double)); +} +} +#endif diff --git a/app/main.altenergy.f90 b/app/main.altenergy.f90 index aef7be14f..a254348b0 100644 --- a/app/main.altenergy.f90 +++ b/app/main.altenergy.f90 @@ -17,6 +17,7 @@ program Gemini3D_main use, intrinsic :: iso_c_binding, only : C_INT, C_NULL_CHAR use, intrinsic :: iso_fortran_env, only : stderr=>error_unit use phys_consts, only : wp, debug +use restart_runtime, only: runtime_exclude_model use mpi_f08, only: MPI_COMM_WORLD, mpi_init,mpi_finalize,mpi_comm_rank !> type definitions @@ -62,7 +63,9 @@ program Gemini3D_main integer :: myid !> initialize mpi +call runtime_exclude_model('alternate energy') call mpi_init() +call mpi_comm_rank(MPI_COMM_WORLD,myid) ! initialize the outer termination-log rank p%fortran_cli = 1 p%fortran_nml = 1 p%out_dir(1) = c_null_char diff --git a/app/main.cpp b/app/main.cpp index 2269d0644..b338b4ae6 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,3 +1,4 @@ +// Audit modification 2026-09-16: validate CLI, bound path copies, match ABI, check size arithmetic and abort failed MPI allocations // MAIN PROGRAM FOR GEMINI3D #include @@ -14,6 +15,7 @@ namespace fs = std::filesystem; #include #include "gemini3d.h" +#include "cli_utils.h" #include "ffilesystem.h" int gemini_main(struct params*, int*, int*); @@ -24,7 +26,7 @@ void fluid_adv(double*, double*, int*, double*, int*, int*, double*, double*, do int main(int argc, char **argv) { - struct params s; + struct params s{}; int myid; int ierr = MPI_Init(&argc, &argv); if(ierr){ @@ -61,7 +63,11 @@ int main(int argc, char **argv) { s.fortran_nml = 1; // Prepare Gemini3D struct - std::strcpy(s.out_dir, out_dir.data()); + if (!gemini_cli::copy_outdir(out_dir, s.out_dir, sizeof(s.out_dir))) { + std::cerr << "Expanded output directory exceeds the C interface limit of " << LMAX-1 << " bytes\n"; + MPI_Finalize(); + return EXIT_FAILURE; + } s.fortran_cli = 0; s.debug = 0; @@ -69,31 +75,24 @@ int main(int argc, char **argv) { int lid2in = -1, lid3in = -1; MPI_Comm_rank(MPI_COMM_WORLD,&myid); - for (int i = 2; i < argc; i++) { - std::string_view arg(argv[i]); - if (arg == "-d" || arg == "-debug") - s.debug = 1; - - if (arg == "-dryrun") - s.dryrun = 1; - - if (arg == "-h" || arg == "-help") { - help_gemini_bin(); - MPI_Finalize(); - return EXIT_SUCCESS; - } - if (arg == "-manual_grid") { - if (argc < i+1) { - MPI_Finalize(); - std::cerr << "-manual_grid lid2in lid3in\n"; - return EXIT_FAILURE; - } - lid2in = atoi(argv[i]); - lid3in = atoi(argv[i+1]); - } + bool help = false; + std::string cli_error; + if (!gemini_cli::parse_options(argc, argv, s, lid2in, lid3in, help, cli_error)) { + std::cerr << cli_error << "\n"; + MPI_Finalize(); + return EXIT_FAILURE; + } + if (help) { + help_gemini_bin(); + MPI_Finalize(); + return EXIT_SUCCESS; } - gemini_main(&s, &lid2in, &lid3in); + const int status = gemini_main(&s, &lid2in, &lid3in); + if (status != 0) { + MPI_Abort(MPI_COMM_WORLD, status); + return EXIT_FAILURE; + } if(MPI_Finalize()){ std::cerr << "MPI_Finalize failed\n"; @@ -112,14 +111,14 @@ int gemini_main(struct params* ps, int* plid2in, int* plid3in){ int lsp; double UTsec; int ymd[3]; - double* fluidvars; - double* fluidauxvars; - double* electrovars; // pointers modifiable by fortran + double* fluidvars = nullptr; + double* fluidauxvars = nullptr; + double* electrovars = nullptr; // pointers modifiable by fortran double t=0.0, dt=1e-4; double tout, tneuBG, tglowout, tdur, tmilestone=0; int iupdate; int flagoutput; - bool flagneuBG; + int flagneuBG = 0; int flagdneu; double dtneu,dtneuBG; int myid,lid; @@ -159,20 +158,23 @@ int gemini_main(struct params* ps, int* plid2in, int* plid3in){ // Allocate memory and get pointers to blocks of data //gemini_alloc(&fluidvars,&fluidauxvars,&electrovars); // allocate space in fortran modules for data std::cout << "start C allocations: " << lx1 << " " << lx2 << " " << lx3 << std::endl; - fluidvars=(double*) malloc((lx1+4)*(lx2+4)*(lx3+4)*5*lsp*sizeof(double)); - fluidauxvars=(double*) malloc((lx1+4)*(lx2+4)*(lx3+4)*(2*lsp+9)*sizeof(double)); - electrovars=(double*) malloc((lx1+4)*(lx2+4)*(lx3+4)*7*sizeof(double)); - if (! fluidvars){ - std::cerr << "fluidvars failed malloc, worker: " << myid << std::endl; - return 1; - } - if (! fluidauxvars){ - std::cerr << "fluiduxvars failed malloc, worker: " << myid << std::endl; - return 1; + try { + const auto cells = gemini_cli::cell_count(lx1, lx2, lx3); + if (lsp <= 0) throw std::invalid_argument("invalid species count"); + const auto species = static_cast(lsp); + fluidvars = static_cast(std::malloc(gemini_cli::array_bytes(cells, gemini_cli::checked_product(5, species)))); + fluidauxvars = static_cast(std::malloc(gemini_cli::array_bytes(cells, 2*species+9))); + electrovars = static_cast(std::malloc(gemini_cli::array_bytes(cells, 7))); + } catch (const std::exception& error) { + std::cerr << "Invalid allocation dimensions: " << error.what() << "\n"; + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); + return EXIT_FAILURE; } - if (! electrovars){ - std::cerr << "electrovars failed malloc, worker: " << myid << std::endl; - return 1; + if (!fluidvars || !fluidauxvars || !electrovars) { + std::cerr << "Plasma allocation failed, worker: " << myid << "\n"; + free(fluidvars); free(fluidauxvars); free(electrovars); + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); + return EXIT_FAILURE; } gemini_work_alloc_C(&cfgC,&intvars); outdir_fullgridvaralloc_C(&cfgC,&intvars,&lx1,&lx2all,&lx3all); // create output directory and allocate some module space for potential @@ -235,6 +237,7 @@ int gemini_main(struct params* ps, int* plid2in, int* plid3in){ clear_neutral_background_C(&intvars); free(fluidvars); free(fluidauxvars); free(electrovars); gemini_work_dealloc_C(&cfgC,&intvars); + gemini_grid_dealloc_C(&xtype,&xC); gemini_cfg_dealloc_C(&cfgC); return 0; } diff --git a/app/main.denspot.f90 b/app/main.denspot.f90 index b289aedff..6ebc2c044 100644 --- a/app/main.denspot.f90 +++ b/app/main.denspot.f90 @@ -17,6 +17,7 @@ program Gemini3D_main use, intrinsic :: iso_c_binding, only : C_INT, C_NULL_CHAR use, intrinsic :: iso_fortran_env, only : stderr=>error_unit use phys_consts, only : wp, debug +use restart_runtime, only: runtime_exclude_model use mpi_f08, only: MPI_COMM_WORLD, mpi_init,mpi_finalize,mpi_comm_rank !> type definitions @@ -61,7 +62,9 @@ program Gemini3D_main integer :: myid !> initialize mpi +call runtime_exclude_model('density and potential only') call mpi_init() +call mpi_comm_rank(MPI_COMM_WORLD,myid) ! initialize the outer termination-log rank p%fortran_cli = 1 p%fortran_nml = 1 p%out_dir(1) = c_null_char diff --git a/app/main.f90 b/app/main.f90 index 12b76401c..ffd1d17e6 100644 --- a/app/main.f90 +++ b/app/main.f90 @@ -63,6 +63,7 @@ program Gemini3D_main !> initialize mpi call mpi_init() +call mpi_comm_rank(MPI_COMM_WORLD,myid) ! initialize the outer termination-log rank p%fortran_cli = 1 p%fortran_nml = 1 p%out_dir(1) = c_null_char @@ -259,6 +260,7 @@ subroutine gemini_main(p, lid2in, lid3in) bind(C) call gemini_dealloc(cfg,fluidvars,fluidauxvars,electrovars,intvars) ! same as following two lines !call gemini_double_dealloc(fluidvars,fluidauxvars,electrovars) !call gemini_work_dealloc(cfg,intvars) + deallocate(x) ! finalizes the mesh after all input-data borrowers are gone call gemini_cfg_dealloc(cfg) end subroutine gemini_main diff --git a/app/main.noenergy.f90 b/app/main.noenergy.f90 index e708da8f2..03fa5051c 100644 --- a/app/main.noenergy.f90 +++ b/app/main.noenergy.f90 @@ -62,6 +62,7 @@ program Gemini3D_main !> initialize mpi call mpi_init() +call mpi_comm_rank(MPI_COMM_WORLD,myid) ! initialize the outer termination-log rank p%fortran_cli = .true. p%fortran_nml = .true. p%out_dir(1) = c_null_char diff --git a/audit_revision.txt b/audit_revision.txt new file mode 100644 index 000000000..3ceac2d6e --- /dev/null +++ b/audit_revision.txt @@ -0,0 +1 @@ +aa50fa1a34c374edaf7e1c79e6d330e4025f777c+preintegration.20260916.2 diff --git a/cmake/libraries.json b/cmake/libraries.json index f79dfd34f..e47f6d73f 100644 --- a/cmake/libraries.json +++ b/cmake/libraries.json @@ -1,26 +1,37 @@ { "ffilesystem": { "stem": "https://github.com/ECLAIRWaveS/ffilesystem/archive/", - "archive": "8a9ad4b213a8fbdb19816451a714f54017170109.tar.gz" + "archive": "8a9ad4b213a8fbdb19816451a714f54017170109.tar.gz", + "sha256": "b0d9dfa00f6fa0977209352cff03634d71999b5f8ab4274b4ce07e56d6953e5c" }, "glow": { "stem": "https://github.com/gemini3d/glow/archive/", - "archive": "7e72b33104a9b71aae7bb9c81df930e07f4723d0.tar.gz" + "archive": "62ce006692b8e16c403c995568ecc3403113d788.tar.gz", + "sha256": "ee3d70dbba76ed50d1dc5fefe1ddcaae6532ab855315a5108392d2983effc1e3" }, "h5fortran": { "stem": "https://github.com/ECLAIRWaveS/h5fortran/archive/", - "archive": "04c7dd39405b43eac922319b6f4b74ea04b97043.tar.gz" + "archive": "04c7dd39405b43eac922319b6f4b74ea04b97043.tar.gz", + "sha256": "9b1f546c65690ba782e7973f10b7d14b098d5f9bab83c90655a7b7e151f52281" }, "hwm14": { "stem": "https://github.com/gemini3d/hwm14/archive/", - "archive": "1f289bfc101235cea1d8ebb58253dab736d4fd56.tar.gz" + "archive": "f8f07c9becb9b2b33c13f8df8907e89981999776.tar.gz", + "sha256": "a62f58c04a8ed8e58279df57e0be2719122064fe65b8398a2e3beac9c4b8041a" }, "msis": { "stem": "https://github.com/gemini3d/msis/archive/", - "archive": "e8437eb61ff0bdb3ef336d96fd279dd75d9aec98.tar.gz" + "archive": "e8437eb61ff0bdb3ef336d96fd279dd75d9aec98.tar.gz", + "sha256": "d3354a3a910ecfaa5fdb512e731647798d57b35085ff4c411264f0ddb69e013c" }, "mumps": { "stem": "https://github.com/scivision/mumps-superbuild/archive/", - "archive": "7be1414e8bdbaf4b3c20e7264b97b2709bdf248f.tar.gz" + "archive": "7be1414e8bdbaf4b3c20e7264b97b2709bdf248f.tar.gz", + "sha256": "b8803c736a29aa10c8f4ad60839342db4ab0428ce34d9dd304d3dc67b08dcbce" + }, + "mumps_upstream": { + "stem": "https://mumps-solver.org/", + "archive": "MUMPS_5.9.1.tar.gz", + "sha256": "659c9b57646b5a003ac618baa1faf9dd2044e46c732b3daaccbc7158003e1b46" } } diff --git a/cmake/mpi.cmake b/cmake/mpi.cmake index aaad6979b..27da26be2 100644 --- a/cmake/mpi.cmake +++ b/cmake/mpi.cmake @@ -3,6 +3,9 @@ include(CheckSourceCompiles) if(NOT DEFINED MPI_ROOT AND DEFINED ENV{MPI_ROOT}) set(MPI_ROOT $ENV{MPI_ROOT}) endif() +if(NOT DEFINED MPI_ROOT AND DEFINED ENV{I_MPI_ROOT}) + set(MPI_ROOT $ENV{I_MPI_ROOT}) +endif() if(MPI_ROOT) message(STATUS "Using MPI_ROOT=${MPI_ROOT}") else() @@ -35,8 +38,8 @@ check_source_compiles(Fortran program test use mpi_f08, only : mpi_comm_rank, mpi_real, mpi_comm_world, mpi_init, mpi_finalize implicit none -call mpi_init -call mpi_finalize +call mpi_init() +call mpi_finalize() end program ]=] MPI_Fortran_HAVE_F08_MODULE @@ -46,5 +49,10 @@ if(MPI_Fortran_HAVE_F08_MODULE) message(CHECK_PASS "yes") else() message(CHECK_FAIL "no") - message(WARNING "MPI-3 Fortran module mpi_f08 not found, builds may fail.") + if(gemini3d_fail_mpif08) + set(_mpif08_message_type FATAL_ERROR) + else() + set(_mpif08_message_type WARNING) + endif() + message(${_mpif08_message_type} "MPI-3 Fortran module mpi_f08 not found with the current MPI installation and ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}, build would fail.") endif() diff --git a/cmake/package/git_rev.cmake b/cmake/package/git_rev.cmake index 41c0e6956..659de7dab 100644 --- a/cmake/package/git_rev.cmake +++ b/cmake/package/git_rev.cmake @@ -4,6 +4,16 @@ # a possible workaround is in # https://github.com/rpavlik/cmake-modules/blob/main/GetGitRevisionDescription.cmake +# Audit modification 2026-09-16: explicit identity for this source archive. +if(EXISTS "${PROJECT_SOURCE_DIR}/audit_revision.txt" AND NOT EXISTS "${PROJECT_SOURCE_DIR}/.git") + file(STRINGS "${PROJECT_SOURCE_DIR}/audit_revision.txt" git_rev LIMIT_COUNT 1) + set(git_branch "audited-source-archive") + set(git_porcelain "audit-patched") + set(git_remote "https://github.com/gemini3d/gemini3d") + set(git_version "archive") + return() +endif() + find_package(Git) set(_max_len 80) # arbitrary limit, so as not to exceed maximum 132 character Fortran line length. @@ -31,7 +41,7 @@ else() endif() -execute_process(COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} describe --tags +execute_process(COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} describe --tags --always --dirty OUTPUT_VARIABLE git_rev OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE _err diff --git a/cmake/python.cmake b/cmake/python.cmake index 428879b7f..86727dc05 100644 --- a/cmake/python.cmake +++ b/cmake/python.cmake @@ -1,66 +1,52 @@ -function(check_pygemini) - -# Numpy conflicts are a general source of trouble -execute_process(COMMAND ${Python_EXECUTABLE} -c "import numpy" -RESULT_VARIABLE ret -OUTPUT_VARIABLE out -ERROR_VARIABLE err -) - -if(NOT ret EQUAL 0) - message(VERBOSE "Problem with Python Numpy: - ${ret} - ${out} - ${err}" - ) - - return() -endif() - -# need h5py for Python tests -execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py,numpy,sys; print(f'Python {sys.version} Numpy {numpy.__version__} h5py {h5py.__version__}')" -RESULT_VARIABLE ret -OUTPUT_VARIABLE out -ERROR_VARIABLE err -) - -if(ret EQUAL 0) - set(H5PY_FOUND true CACHE BOOL "Python h5py Found") -else() - message(VERBOSE "Problem with Python h5py: - ${ret} - ${out} - ${err}" - ) - - return() +# Qualification uses hashlib.file_digest, introduced in Python 3.11. +find_package(Python 3.11 COMPONENTS Interpreter QUIET) +if(NOT Python_FOUND OR Python_VERSION VERSION_LESS 3.11) + set(Python_Interpreter_FOUND FALSE) endif() - -if(NOT gemini3d_python) - return() +# Refresh on every configure, including a changed or removed interpreter. +foreach(module IN ITEMS numpy h5py scipy) + string(TOUPPER "${module}" upper) + set(${upper}_FOUND FALSE CACHE BOOL "Python ${module} importable" FORCE) + if(Python_Interpreter_FOUND) + execute_process(COMMAND "${Python_EXECUTABLE}" -c "import ${module}; print(${module}.__version__)" + RESULT_VARIABLE status OUTPUT_VARIABLE version ERROR_VARIABLE error + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(status STREQUAL "0") + set(${upper}_FOUND TRUE CACHE BOOL "Python ${module} importable" FORCE) + message(STATUS "Python ${module}: ${version}") + else() + message(VERBOSE "Python ${module} import failed: ${error}") + endif() + endif() +endforeach() + +set(missing_python_dependencies) +if(NOT Python_Interpreter_FOUND) + list(APPEND missing_python_dependencies "Python >= 3.11 interpreter") endif() - -execute_process(COMMAND ${Python_EXECUTABLE} -c "import gemini3d; print(gemini3d.__version__)" -WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} # help avoid Intel Windows false import error due to hdf5 .dll in build dir -RESULT_VARIABLE ret -OUTPUT_VARIABLE out -ERROR_VARIABLE err -OUTPUT_STRIP_TRAILING_WHITESPACE -) - -if(NOT ret EQUAL 0) - message(FATAL_ERROR "Failed to get PyGemini version: - ${ret} - ${out} - ${err}" - ) +foreach(module IN ITEMS numpy h5py scipy) + string(TOUPPER "${module}" upper) + if(NOT ${upper}_FOUND) + list(APPEND missing_python_dependencies "${module}") + endif() +endforeach() +if(missing_python_dependencies) + if(gemini3d_require_qualification) + message(FATAL_ERROR "Required qualification dependencies unavailable: ${missing_python_dependencies}") + endif() + message(STATUS "Optional qualification dependencies unavailable: ${missing_python_dependencies}; dependent tests are not registered") endif() -endfunction() - - -find_package(Python COMPONENTS Interpreter) -if(Python_FOUND AND NOT DEFINED PYGEMINI_FOUND) - check_pygemini() +if(gemini3d_python) + if(NOT Python_Interpreter_FOUND OR NOT NUMPY_FOUND OR NOT H5PY_FOUND) + message(FATAL_ERROR "gemini3d_python requires Python >= 3.11, numpy and h5py") + endif() + execute_process(COMMAND "${Python_EXECUTABLE}" -c "import gemini3d; print(gemini3d.__version__)" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + RESULT_VARIABLE status OUTPUT_VARIABLE version ERROR_VARIABLE error + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT status STREQUAL "0") + message(FATAL_ERROR "Failed to get PyGemini version: ${error}") + endif() endif() diff --git a/cmake/sanitizers.cmake b/cmake/sanitizers.cmake new file mode 100644 index 000000000..82721e0c0 --- /dev/null +++ b/cmake/sanitizers.cmake @@ -0,0 +1,11 @@ +# Opt-in developer instrumentation; never silently enable in a production build. +option(gemini3d_sanitizers "GNU AddressSanitizer and UndefinedBehaviorSanitizer instrumentation" OFF) +if(gemini3d_sanitizers) + if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR + NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR + NOT CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + message(FATAL_ERROR "This sanitizer profile is qualified only with the GNU C/C++/Fortran toolchain") + endif() + add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer) + add_link_options(-fsanitize=address,undefined) +endif() diff --git a/cmake/summary.cmake b/cmake/summary.cmake index 01df7ab80..35c41797a 100644 --- a/cmake/summary.cmake +++ b/cmake/summary.cmake @@ -7,7 +7,6 @@ add_feature_info(HWM14 gemini3d_hwm14 "HWM14 neutral winds model") add_feature_info(MSIS2 gemini3d_msis2 "enable MSIS 2.x neutral atmosphere model") add_feature_info(PyGemini gemini3d_python "simulation generation, HPC script generator and plotting") -add_feature_info(MatGemini gemini3d_matlab "checks not as extensive as Python, and slow") # print to screen feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES) diff --git a/corrections.patch b/corrections.patch new file mode 100644 index 000000000..5e49751d6 --- /dev/null +++ b/corrections.patch @@ -0,0 +1,2127 @@ +diff --git a/.github/workflows/composite-cmake/action.yml b/.github/actions/composite-cmake/action.yml +similarity index 89% +rename from .github/workflows/composite-cmake/action.yml +rename to .github/actions/composite-cmake/action.yml +index 51a51bf4..94629de7 100644 +--- a/.github/workflows/composite-cmake/action.yml ++++ b/.github/actions/composite-cmake/action.yml +@@ -8,7 +8,7 @@ runs: + steps: + - name: Install CMake ${{ matrix.cmake_version }} + shell: bash +- run: cmake -Dversion=${{ matrix.cmake_version }} -P .github/workflows/composite-cmake/install_cmake.cmake ++ run: cmake -Dversion=${{ matrix.cmake_version }} -P .github/actions/composite-cmake/install_cmake.cmake + + - name: CMake path + shell: bash +diff --git a/.github/workflows/composite-cmake/install_cmake.cmake b/.github/actions/composite-cmake/install_cmake.cmake +similarity index 100% +rename from .github/workflows/composite-cmake/install_cmake.cmake +rename to .github/actions/composite-cmake/install_cmake.cmake +diff --git a/.github/workflows/composite-pkg/action.yml b/.github/actions/composite-pkg/action.yml +similarity index 90% +rename from .github/workflows/composite-pkg/action.yml +rename to .github/actions/composite-pkg/action.yml +index 131b0afd..af487251 100644 +--- a/.github/workflows/composite-pkg/action.yml ++++ b/.github/actions/composite-pkg/action.yml +@@ -1,5 +1,5 @@ +-name: Install dependencies +-description: Install dependencies for Linux and macOS ++name: Install Gemini3D build dependencies ++description: Install dependencies for Gemini3D build + + runs: + +diff --git a/.github/workflows/composite-unix/action.yml b/.github/actions/composite-unix/action.yml +similarity index 100% +rename from .github/workflows/composite-unix/action.yml +rename to .github/actions/composite-unix/action.yml +diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml +index bf6393ce..dec14f31 100644 +--- a/.github/workflows/ci.yml ++++ b/.github/workflows/ci.yml +@@ -53,10 +53,10 @@ jobs: + run: sudo apt install -y --no-install-recommends gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} gfortran-${{ matrix.gcc }} + + - &pkg +- uses: ./.github/workflows/composite-pkg ++ uses: ./.github/actions/composite-pkg + + - &linux-build +- uses: ./.github/workflows/composite-unix ++ uses: ./.github/actions/composite-unix + + hwm-msis: + timeout-minutes: 15 +@@ -92,6 +92,6 @@ jobs: + + - name: Install CMake ${{ matrix.cmake_version }} + timeout-minutes: 10 +- uses: ./.github/workflows/composite-cmake ++ uses: ./.github/actions/composite-cmake + + - run: $CMAKE --workflow --preset gmake +diff --git a/.github/workflows/ci_macos.yml b/.github/workflows/ci_macos.yml +index d90a3f69..d9885e83 100644 +--- a/.github/workflows/ci_macos.yml ++++ b/.github/workflows/ci_macos.yml +@@ -49,9 +49,9 @@ jobs: + uses: actions/checkout@v7 + + - &pkg +- uses: ./.github/workflows/composite-pkg ++ uses: ./.github/actions/composite-pkg + +- - uses: ./.github/workflows/composite-unix ++ - uses: ./.github/actions/composite-unix + + gnu_make: + timeout-minutes: 15 +diff --git a/.github/workflows/oneapi-linux.yml b/.github/workflows/oneapi-linux.yml +index e13b6db5..6927c55f 100644 +--- a/.github/workflows/oneapi-linux.yml ++++ b/.github/workflows/oneapi-linux.yml +@@ -15,6 +15,8 @@ on: + - "docs/**" + - "cmake/cray.cmake" + - "**.md" ++ - "**.py" ++ - "**.sh" + workflow_dispatch: + + permissions: +diff --git a/.gitignore b/.gitignore +index 053a0d2b..8f78e547 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -1,4 +1,5 @@ + *.log.txt ++*.log + *.job + *.job.* + .DS_Store +diff --git a/cmake/libraries.json b/cmake/libraries.json +index 5aab1d56..e47f6d73 100644 +--- a/cmake/libraries.json ++++ b/cmake/libraries.json +@@ -16,8 +16,8 @@ + }, + "hwm14": { + "stem": "https://github.com/gemini3d/hwm14/archive/", +- "archive": "1f289bfc101235cea1d8ebb58253dab736d4fd56.tar.gz", +- "sha256": "5b6c83425acc87febf01acc3dea6c313bd5bd4c0883640fba517d3a7bda04ed8" ++ "archive": "f8f07c9becb9b2b33c13f8df8907e89981999776.tar.gz", ++ "sha256": "a62f58c04a8ed8e58279df57e0be2719122064fe65b8398a2e3beac9c4b8041a" + }, + "msis": { + "stem": "https://github.com/gemini3d/msis/archive/", +diff --git a/cmake/mpi.cmake b/cmake/mpi.cmake +index 0874005f..27da26be 100644 +--- a/cmake/mpi.cmake ++++ b/cmake/mpi.cmake +@@ -38,8 +38,8 @@ check_source_compiles(Fortran + program test + use mpi_f08, only : mpi_comm_rank, mpi_real, mpi_comm_world, mpi_init, mpi_finalize + implicit none +-call mpi_init +-call mpi_finalize ++call mpi_init() ++call mpi_finalize() + end program + ]=] + MPI_Fortran_HAVE_F08_MODULE +@@ -49,5 +49,10 @@ if(MPI_Fortran_HAVE_F08_MODULE) + message(CHECK_PASS "yes") + else() + message(CHECK_FAIL "no") +- message(WARNING "MPI-3 Fortran module mpi_f08 not found, builds may fail.") ++ if(gemini3d_fail_mpif08) ++ set(_mpif08_message_type FATAL_ERROR) ++ else() ++ set(_mpif08_message_type WARNING) ++ endif() ++ message(${_mpif08_message_type} "MPI-3 Fortran module mpi_f08 not found with the current MPI installation and ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}, build would fail.") + endif() +diff --git a/cmake/summary.cmake b/cmake/summary.cmake +index 01df7ab8..35c41797 100644 +--- a/cmake/summary.cmake ++++ b/cmake/summary.cmake +@@ -7,7 +7,6 @@ add_feature_info(HWM14 gemini3d_hwm14 "HWM14 neutral winds model") + add_feature_info(MSIS2 gemini3d_msis2 "enable MSIS 2.x neutral atmosphere model") + + add_feature_info(PyGemini gemini3d_python "simulation generation, HPC script generator and plotting") +-add_feature_info(MatGemini gemini3d_matlab "checks not as extensive as Python, and slow") + + # print to screen + feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES) +diff --git a/docs/qualification/ACCOUNTING_CONTINUATION_REVIEW.md b/docs/qualification/ACCOUNTING_CONTINUATION_REVIEW.md +new file mode 100644 +index 00000000..1794d1ec +--- /dev/null ++++ b/docs/qualification/ACCOUNTING_CONTINUATION_REVIEW.md +@@ -0,0 +1,26 @@ ++# Qualification review continuation, 10 October 2026 ++ ++The existing acceptance budgets, native comparator, and reference archives remain ++unchanged. This work adds evidence checks and optional diagnostics. No scientific ++gate is closed by these component changes. ++ ++Deleting the same middle time step from every native ledger previously left all ++four checkers green. The checkers now require contiguous float64 clocks, a zero ++start, and the final `tdur` from the retained input configuration. Cross-ledger ++coverage remains required. Clock comparisons allow only 64 float64 ULPs for ++clock accumulation; no mass, charge, transport, source, or energy budget changes. ++ ++The temperature conversion after compression enforces a 100 K lower floor but ++previously recorded no addition for this stage. Optional diagnostics now record ++stage 3, using actual species density for physical internal-energy capacity. ++The source checker requires all seven species at each of the three standard ++energy floor stages. A native activation oracle checks a known 50-to-100 K ++addition over 183 m3, excludes a null cell and ghosts, and compares the complete ++temperature/internal-energy arrays with diagnostics enabled and disabled. ++ ++This does not complete R04. Individual chemistry/collision channels, coupled ++kinetic/internal-energy exchanges, density/velocity cleanup and conversion ++effects, independently measured conductive boundary power, and full coupled ++space/time refinement remain distinct obligations. Endpoint reservoir changes ++are not reclassified as conductive flux. Numerical regression does not supply ++R01 maintainer acceptance or R07 independent matched-event physics validation. +diff --git a/options.cmake b/options.cmake +index 0d57cc28..599d52bd 100644 +--- a/options.cmake ++++ b/options.cmake +@@ -20,6 +20,10 @@ endif() + + option(gemini3d_test_simulations "register required reference simulations (OFF is unit-only, not release verification)" ON) + ++# The frozen reference profile remains the default. This switch selects the ++# proposed nonlinear time-centering update for the standard energy path. ++option(gemini3d_midpoint_conduction "use experimental midpoint conductivity in standard TRBDF2 energy diffusion" OFF) ++ + if(gemini3d_realbits EQUAL 32) + message(VERBOSE " 32-bit real precision") + set(gemini3d_arith s) +@@ -39,6 +43,8 @@ option(gemini3d_matlab "Matlab-based self-checks") + + option(gemini3d_msis2 "enable MSIS2 neutral atmosphere model (must specify in config.nml as well)" on) + ++option(gemini3d_fail_mpif08 "Fail the build if MPI-3 Fortran module mpi_f08 is not found" ON) ++ + # append .debug to debug libraries, because the computation speed penalty is so great + set(CMAKE_DEBUG_POSTFIX .debug) + +diff --git a/scripts/debug_example.sh b/scripts/debug_example.sh +new file mode 100755 +index 00000000..d710b3d5 +--- /dev/null ++++ b/scripts/debug_example.sh +@@ -0,0 +1,124 @@ ++#!/bin/bash ++# this is to debug simulations e.g. from gemini3d/gemini-examples repo ++# ++# Usage: ./debug_example.sh [cmake_opts...] ++# Pass --fresh among cmake_opts to configure and build even if gemini.bin exists. ++# Requires realpath and a non-Conda mpiexec on PATH. ++# Uses the first non-Conda mpiexec in PATH order. ++# ++# Example from gemini3d/ directory: ++# ++# scripts/debug_example.sh ../gemini-examples/init/CI-staging/varHWM/eq/config.nml $TMPDIR/varHWM \ ++# -Dgemini3d_hwm14=true ++# ++# to use a local package within Gemini3D for development do like ++# ++# scripts/debug_example.sh ../gemini-examples/init/CI-staging/varHWM/eq/config.nml $TMPDIR/varHWM \ ++# -Dgemini3d_hwm14=true -DFETCHCONTENT_SOURCE_DIR_HWM14=../hwm14 ++ ++ ++[[ $# -lt 2 ]] && { echo "Usage: $0 [cmake_opts...]"; exit 1; } ++ ++mpiexec= ++while IFS= read -r mpi_candidate; do ++ mpi_candidate=$(realpath "$mpi_candidate") || ++ { echo "Cannot resolve mpiexec with realpath" >&2; exit 1; } ++ mpi_dir=$(dirname "$mpi_candidate") ++ ++ # Conda environments have conda-meta, even when they are not activated. ++ while [[ "$mpi_dir" != / && ! -d "$mpi_dir/conda-meta" ]]; do ++ mpi_dir=$(dirname "$mpi_dir") ++ done ++ if [[ "$mpi_dir" != / ]]; then ++ echo "Skipping Conda mpiexec: $mpi_candidate" >&2 ++ continue ++ fi ++ ++ mpiexec=$mpi_candidate ++ break ++done < <(type -aP mpiexec) ++ ++[[ -n "$mpiexec" ]] || { echo "No non-Conda mpiexec found on PATH" >&2; exit 1; } ++ ++config_nml_to_copy=$1 ++simulation_output_dir=$2 ++if [[ $# -ge 3 ]]; then ++ cmake_opts="${@:3}" ++fi ++ ++fresh=0 ++for arg in "${@:3}"; do ++ if [[ "$arg" == --fresh ]]; then ++ fresh=1 ++ break ++ fi ++done ++ ++# if CMAKE_BUILD_TYPE not set in variable cmake_opts, default to Release ++if [[ ! "$cmake_opts" =~ -DCMAKE_BUILD_TYPE= ]]; then ++ cmake_opts="-DCMAKE_BUILD_TYPE=Release $cmake_opts" ++fi ++ ++[[ -f "$config_nml_to_copy" ]] || { echo "Config NML file '$config_nml_to_copy' does not exist"; exit 1; } ++ ++if [[ ! -d "$simulation_output_dir" ]]; then ++ mkdir -p "$simulation_output_dir" || { echo "Failed to create simulation output directory '$simulation_output_dir'"; exit 1; } ++fi ++ ++this_script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" ++ ++builddir="$simulation_output_dir/build" ++ ++copied_config="$simulation_output_dir/$(basename "$config_nml_to_copy")" ++if [[ ! -f "$copied_config" ]] || ! diff -q -- "$config_nml_to_copy" "$copied_config" >/dev/null; then ++ \cp -v "$config_nml_to_copy" "$simulation_output_dir/" || { echo "Failed to copy '$config_nml_to_copy' to '$simulation_output_dir'"; exit 1; } ++fi ++ ++if [[ ! -f "$builddir/gemini.bin" ]] || (( fresh )); then ++ ++cmake=$(command -v cmake) || { echo "CMake not found or working" >&2; exit 1; } ++ ++$cmake -S "$this_script_dir/.." -B "$builddir" $cmake_opts || ++ { echo "CMake configuration failed" >&2; exit 1; } ++ ++$cmake --build "$builddir" || ++ { echo "CMake build failed" >&2; exit 1; } ++ ++fi ++ ++case $OSTYPE in ++ darwin*) ++ Ncpu=$(sysctl -n hw.physicalcpu) ++ ;; ++ linux*) ++ Ncpu=$(lscpu -p=CORE,SOCKET | ++ awk -F, '!/^#/ { cores[$1 "," $2]=1 } ++ END { for (core in cores) n++; print n }') ++ ;; ++ *) ++ echo "Cannot determine the number of CPUs on: $OSTYPE; using 1" >&2 ++ Ncpu=1 ++ ;; ++esac ++ ++[[ $Ncpu =~ ^[1-9][0-9]*$ ]] || { ++ echo "Failed to determine physical CPU count" >&2 ++ exit 1 ++} ++ ++if [[ ! -f $simulation_output_dir/inputs/initial_conditions.h5 ]]; then ++ py3=$(command -v python3) || ++ { echo "Python not found" >&2; exit 1; } ++ ++ "$py3" -m gemini3d --help || ++ { echo "PyGemini not available - get it from https://github.com/gemini3d/pygemini" >&2; exit 1; } ++ ++ echo "Setting up simulation inputs in '$simulation_output_dir'..." ++ ++ GEMINI_ROOT="$builddir" "$py3" -m gemini3d.model "$copied_config" "$simulation_output_dir" || ++ { echo "Failed to set up simulation inputs in '$simulation_output_dir'" >&2; exit 1; } ++fi ++ ++echo "running simulation with $Ncpu MPI workers..." ++ ++"$mpiexec" -np "$Ncpu" -wdir "$builddir" "$builddir/gemini.bin" "$simulation_output_dir" +diff --git a/scripts/qualification/check_energy_operators.py b/scripts/qualification/check_energy_operators.py +index 4561adcb..6b02f224 100644 +--- a/scripts/qualification/check_energy_operators.py ++++ b/scripts/qualification/check_energy_operators.py +@@ -10,7 +10,7 @@ import argparse + import json + import math + from pathlib import Path +-from check_sources import rows ++from check_sources import rows,check_clock_inventory + + EXPECTED={(stage,s) for stage in (1,2) for s in range(1,8)} + +@@ -49,6 +49,7 @@ def check(directory,ranks,budget=1e-11): + clocks=these + continuity={(r['t'],r['dt']) for r in rows(directory/f'continuity-r{rank:08d}.csv')} + if these!=continuity:raise ValueError('Energy/continuity step inventory differs') ++ check_clock_inventory(directory,these) + return dict(schema='gemini.energy.operators.1',passed=max(worst,row_residual)<=budget, + ranks=ranks,rows=count,steps=len(clocks),budget=budget,max_normalized_residual=worst, + max_reported_residual_inconsistency=row_residual,integrated_channels_J=totals, +diff --git a/scripts/qualification/check_sources.py b/scripts/qualification/check_sources.py +index e6d480b4..dd07c522 100644 +--- a/scripts/qualification/check_sources.py ++++ b/scripts/qualification/check_sources.py +@@ -8,11 +8,43 @@ import argparse + import csv + import json + import math ++import re + from pathlib import Path + + EXPECTED={(q,s) for q in (1,2,3) for s in range(1,8 if q==3 else 7)} + + ++def check_clock_inventory(directory,clocks): ++ """Require contiguous whole-run evidence, with float64 clock roundoff only. ++ ++ Cross-ledger agreement cannot reveal a step deleted from every file. The ++ admitted whole-run profile starts at zero. Its immutable configuration ++ supplies the final duration when present; synthetic unit fixtures may omit ++ it. This check changes no scientific or numerical residual budget. ++ """ ++ ordered=sorted(clocks) ++ if not ordered:raise ValueError('No numerical ledger clocks') ++ for t,dt in ordered: ++ if not all(math.isfinite(v) for v in (t,dt)) or t<0 or dt<=0 or t+dt<=t: ++ raise ValueError('Invalid numerical ledger clock') ++ def same(a,b): ++ return abs(a-b)<=64*math.ulp(max(1.,abs(a),abs(b))) ++ if not same(ordered[0][0],0.): ++ raise ValueError('Numerical ledger does not begin at zero') ++ for (t,dt),(next_t,_) in zip(ordered,ordered[1:]): ++ if not same(t+dt,next_t): ++ raise ValueError('Noncontiguous numerical ledger clocks') ++ cfg=Path(directory)/'inputs/config.nml' ++ if cfg.is_file(): ++ values=re.findall(r'(?im)^[ \t]*tdur[ \t]*=([^!\r\n]*)',cfg.read_text()) ++ if len(values)!=1:raise ValueError('Exactly one declared duration required') ++ try:stop=float(values[0].strip().removesuffix(',').strip().replace('D','e').replace('d','e')) ++ except ValueError as e:raise ValueError('Invalid declared duration') from e ++ if not math.isfinite(stop) or stop<=0:raise ValueError('Invalid declared duration') ++ if not same(sum(ordered[-1]),stop): ++ raise ValueError('Numerical ledger does not reach declared duration') ++ ++ + def rows(path): + with path.open() as stream: + for raw in csv.DictReader(stream): +@@ -51,6 +83,7 @@ def check(directory,ranks,budget=1e-11): + common=clocks + continuity={(r['t'],r['dt']) for r in rows(directory/f'continuity-r{rank:08d}.csv')} + if clocks!=continuity:raise ValueError('Source/continuity steps do not match') ++ check_clock_inventory(directory,clocks) + seen=set() + for row in rows(directory/f'temperature-floor-r{rank:08d}.csv'): + clock=(row['t'],row['dt']);key=(*clock,int(row['stage']),int(row['species'])) +@@ -58,7 +91,7 @@ def check(directory,ranks,budget=1e-11): + if row['energy_added_J']<0:raise ValueError('Negative energy attributed to a lower floor') + seen.add(key);label=f"{int(row['stage'])}:{int(row['species'])}" + floors[label]=floors.get(label,0.)+row['energy_added_J'];floor_rows+=1 +- expected={(*clock,stage,s) for clock in clocks for stage in (1,2) for s in range(1,8)} ++ expected={(*clock,stage,s) for clock in clocks for stage in (1,2,3) for s in range(1,8)} + if seen!=expected:raise ValueError('Missing standard-energy temperature-floor stages') + return dict(schema='gemini.native.sources.1',passed=max(worst,worst_state)<=budget, + ranks=ranks,rows=count,steps=len(common),budget=budget,max_normalized_residual=worst, +diff --git a/scripts/qualification/check_transport.py b/scripts/qualification/check_transport.py +index 045a343d..e83d0ad7 100644 +--- a/scripts/qualification/check_transport.py ++++ b/scripts/qualification/check_transport.py +@@ -3,15 +3,19 @@ + Quantity: 1 species number, 2 parallel momentum (covariant weighting in curved + perpendicular sweeps), 3 internal energy. Null cells and ghosts are excluded. + min_face/max_face include MPI subdomain faces; they are not global boundaries. ++Requires the independently recorded continuity ledger for the step inventory. + """ + import argparse + import csv + import json + from pathlib import Path + import math ++from check_sources import rows as ledger_rows,check_clock_inventory + + + def check(directory,budget=1e-11,layout=None): ++ if not math.isfinite(budget) or budget<=0: ++ raise ValueError('Positive finite transport budget required') + files=sorted(directory.glob('transport-r*.csv')) + if not files:raise ValueError('No native transport evidence') + count=0;worst=0;coverage=set();worst_row=None;by_rank={} +@@ -24,10 +28,13 @@ def check(directory,budget=1e-11,layout=None): + r={k:float(v) for k,v in row.items()} + if not all(math.isfinite(v) for v in r.values()):raise ValueError('Nonfinite budget row') + if r['dt']<=0 or r['scale']<=0:raise ValueError('Nonpositive time/scale') ++ if r['scale']<(1-1e-12)*max(abs(r['before']),abs(r['after'])): ++ raise ValueError('Invalid transport scale') + if any(r[k]!=int(r[k]) for k in ('quantity','species','axis')):raise ValueError('Noninteger stage identifier') + scale=max(r['scale'],abs(r['outward']),2.2250738585072014e-308) + # Recompute using independently recorded state change and actual face transport. +- residual=abs(r['delta']+r['outward'])/scale ++ residual=max(abs(r['delta']+r['outward']), ++ abs(r['after']-r['before']-r['delta']))/scale + if residual>worst:worst=residual;worst_row={'file':path.name,'t':r['t'],'quantity':r['quantity'],'species':r['species'],'axis':r['axis']} + key=(r['t'],r['dt'],int(r['quantity']),int(r['species']),int(r['axis'])) + if key in by_rank[rank]:raise ValueError('Duplicate native transport stage') +@@ -36,8 +43,14 @@ def check(directory,budget=1e-11,layout=None): + count+=1 + expected={(q,s,a) for q in (1,2,3) for s in range(1,8 if q==3 else 7) for a in (1,2,3)} + complete=True +- for data in by_rank.values(): ++ for rank,data in by_rank.items(): + clocks={key[:2] for key in data} ++ # A whole missing clock leaves each surviving clock internally complete. ++ # Use the separately recorded whole-step ledger as the clock inventory. ++ continuity={(r['t'],r['dt']) for r in ledger_rows(directory/f'continuity-r{rank:08d}.csv')} ++ if clocks!=continuity: ++ raise ValueError('Transport/continuity step inventory differs') ++ check_clock_inventory(directory,clocks) + complete=complete and bool(clocks) and all({key[2:] for key in data if key[:2]==clock}==expected for clock in clocks) + paired=None;global_worst=None;interfaces=0 + if layout is not None: +@@ -90,6 +103,7 @@ def check_continuity(directory,budget=1e-11,charge_budget=1e-12): + coverage.add(species);cleanup[str(species)]+=r['cleanup'];rows+=1 + complete=set(by_rank)==set(range(len(files))) and all(bool(clocks) and all(s==set(range(1,7)) for s in clocks.values()) for clocks in by_rank.values()) + if complete:complete=all(set(clocks)==set(by_rank[0]) for clocks in by_rank.values()) ++ for clocks in by_rank.values():check_clock_inventory(directory,set(clocks)) + return dict(schema='gemini.native.continuity.1',passed=rows>0 and complete and coverage==set(range(1,7)) and worst<=budget and charge<=charge_budget, + rank_files=len(files),rows=rows,per_step_coverage_complete=complete,max_normalized_residual=worst,max_charge_fraction=charge, + budget=budget,charge_budget=charge_budget,total_cleanup_number_by_species=cleanup, +diff --git a/scripts/qualification/run_physics_native.py b/scripts/qualification/run_physics_native.py +new file mode 100644 +index 00000000..2891591f +--- /dev/null ++++ b/scripts/qualification/run_physics_native.py +@@ -0,0 +1,65 @@ ++"""Compile probes against unmodified GEMINI objects, preserving execution receipts.""" ++import argparse ++import hashlib ++import json ++import os ++from pathlib import Path ++import shlex ++import subprocess ++ ++p = argparse.ArgumentParser() ++p.add_argument('--build', type=Path, required=True) ++p.add_argument('--source', type=Path, required=True) ++p.add_argument('--work', type=Path, required=True) ++a = p.parse_args() ++a.build = a.build.absolute() ++a.source = a.source.absolute() ++a.work = a.work.absolute() ++a.work.mkdir(parents=True, exist_ok=False) ++obj = a.work / 'physics_native.o' ++exe = a.work / 'physics_native' ++compile_command = [os.environ['FC'], '-g', '-fcheck=all', '-ffree-line-length-none', ++ '-I'+str(a.build/'include'), '-c', str(a.source), '-o', str(obj)] ++with (a.work/'compile.log').open('w') as f: ++ r = subprocess.run(compile_command, stdout=f, stderr=subprocess.STDOUT) ++if r.returncode: ++ raise SystemExit(f'Compile failed; see {a.work}/compile.log') ++commands = subprocess.check_output(['ninja', '-C', str(a.build), '-t', 'commands', ++ 'qualification_continuity_floor'], text=True) ++tokens = shlex.split(commands.splitlines()[-1]) ++start = tokens.index('&&')+1 ++end = tokens.index('&&', start) ++command = tokens[start:end] ++assert sum(t.endswith('continuity_floor.f90.o') for t in command) == 1 ++command = [str(obj) if t.endswith('continuity_floor.f90.o') else t for t in command] ++command[command.index('-o')+1] = str(exe) ++command = [t for t in command if not t.startswith('-Wl,--dependency-file=')] ++with (a.work/'link.log').open('w') as f: ++ r = subprocess.run(command, cwd=a.build, stdout=f, stderr=subprocess.STDOUT) ++if r.returncode: ++ raise SystemExit(f'Link failed; see {a.work}/link.log') ++r = subprocess.run([str(exe), str(a.work)], env=dict(os.environ, GEMINI_NUMERICAL_AUDIT='0'), ++ capture_output=True, text=True) ++(a.work/'native.log').write_text(r.stdout+r.stderr) ++receipt = { ++ 'schema': 'gemini.physics.native.receipt.1', ++ 'native_returncode': r.returncode, ++ 'probe_source_sha256': hashlib.sha256(a.source.read_bytes()).hexdigest(), ++ 'probe_executable_sha256': hashlib.sha256(exe.read_bytes()).hexdigest(), ++ 'compile_command': compile_command, ++ 'link_command': command, ++ 'objects': [], ++ 'files': [] ++} ++for t in command: ++ q = a.build/t ++ if t.endswith('.o') or t.endswith('.a') or '.so' in t: ++ if q.is_file(): ++ receipt['objects'].append({'file': str(q), 'sha256': hashlib.sha256(q.read_bytes()).hexdigest()}) ++for q in sorted(a.work.glob('*.csv')): ++ receipt['files'].append({'file':q.name, 'bytes':q.stat().st_size, ++ 'sha256':hashlib.sha256(q.read_bytes()).hexdigest()}) ++(a.work/'execution.json').write_text(json.dumps(receipt, indent=2)+'\n') ++print(json.dumps({'native_returncode':r.returncode, 'output_files':len(receipt['files']), ++ 'work': str(a.work)})) ++raise SystemExit(r.returncode) +diff --git a/scripts/qualification/trace_diffusion_stages.py b/scripts/qualification/trace_diffusion_stages.py +new file mode 100644 +index 00000000..e03e0c18 +--- /dev/null ++++ b/scripts/qualification/trace_diffusion_stages.py +@@ -0,0 +1,78 @@ ++"""Build an observational TR-stage trace copy without changing the native algorithm.""" ++import argparse ++import hashlib ++import json ++import os ++from pathlib import Path ++import shlex ++import subprocess ++ ++p=argparse.ArgumentParser() ++p.add_argument('--source',type=Path,required=True) ++p.add_argument('--build',type=Path,required=True) ++p.add_argument('--probe',type=Path,required=True) ++p.add_argument('--work',type=Path,required=True) ++a=p.parse_args();a.build=a.build.absolute();a.work=a.work.absolute();a.work.mkdir(parents=True,exist_ok=False) ++original=a.source.read_text() ++needle="call check_solver_info(info,'TRBDF21D BDF2 stage')" ++assert original.count(needle)==1 ++modified=original.replace(needle,needle+'\ncall trace_stage(Ts,TR,TRBDF21D)') ++trace=''' ++subroutine trace_stage(old,tr,new) ++real(wp),intent(in)::old(:),tr(:),new(:) ++integer::u,i,stat ++character(4096)::path ++call get_environment_variable('GEMINI_PHYSICAL_TR_TRACE',path,status=stat) ++if(stat/=0.or.len_trim(path)==0)return ++open(newunit=u,file=trim(path),status='unknown',position='append') ++do i=1,size(old) ++ write(u,'(i0,3(",",es25.17))')i,old(i),tr(i),new(i) ++enddo ++close(u) ++end subroutine ++''' ++assert modified.count('end module PDEparabolic')==1 ++modified=modified.replace('end module PDEparabolic',trace+'\nend module PDEparabolic') ++source=a.work/'PDEparabolic_trace.f90';source.write_text(modified) ++obj=a.work/'PDEparabolic_trace.o';exe=a.work/'physics_trace' ++# Use the compiler's actual native flags, including Debug bounds checking. ++commands=subprocess.check_output(['ninja','-C',str(a.build),'-t','commands','PDEparabolic'],text=True) ++compile_tokens=None ++for line in commands.splitlines(): ++ tok=shlex.split(line) ++ if '-fpreprocessed' in tok and '-c' in tok: ++ compile_tokens=tok ++assert compile_tokens is not None ++cc=compile_tokens ++cc[cc.index('-c')+1]=str(source) ++cc[cc.index('-o')+1]=str(obj) ++cc=[t for t in cc if t!='-fpreprocessed' and not t.startswith('-J')] ++cc.extend(['-ffree-line-length-none','-I'+str(a.build/'include'),'-J'+str(a.work)]) ++with (a.work/'compile.log').open('w') as f:subprocess.run(cc,cwd=a.build,stdout=f,stderr=subprocess.STDOUT,check=True) ++commands=subprocess.check_output(['ninja','-C',str(a.build),'-t','commands','qualification_continuity_floor'],text=True) ++tokens=shlex.split(commands.splitlines()[-1]);start=tokens.index('&&')+1;end=tokens.index('&&',start) ++cmd=tokens[start:end] ++libraries=[t for t in cmd if Path(t).name in ('libgemini3d.a','libgemini3d.debug.a')] ++assert len(libraries)==1 ++library=libraries[0] ++cmd=[str(a.probe.absolute()) if t.endswith('continuity_floor.f90.o') else t for t in cmd] ++cmd.insert(cmd.index(library),str(obj)) ++cmd[cmd.index('-o')+1]=str(exe);cmd=[t for t in cmd if not t.startswith('-Wl,--dependency-file=')] ++with (a.work/'link.log').open('w') as f:subprocess.run(cmd,cwd=a.build,stdout=f,stderr=subprocess.STDOUT,check=True) ++tracepath=a.work/'tr-stages.csv' ++r=subprocess.run([str(exe),str(a.work)],capture_output=True,text=True,env=dict(os.environ,GEMINI_PHYSICAL_TR_TRACE=str(tracepath))) ++(a.work/'native.log').write_text(r.stdout+r.stderr) ++baseline=a.probe.parent ++comparisons={} ++for q in sorted(baseline.glob('*.csv')): ++ copy=a.work/q.name ++ comparisons[q.name]={'bitwise_equal':q.read_bytes()==copy.read_bytes(), ++ 'sha256':hashlib.sha256(copy.read_bytes()).hexdigest()} ++result={'returncode':r.returncode,'observational_copy':True, ++ 'original_source_sha256':hashlib.sha256(original.encode()).hexdigest(), ++ 'traced_source_sha256':hashlib.sha256(modified.encode()).hexdigest(), ++ 'compile_command':cc,'link_command':cmd,'comparisons':comparisons, ++ 'all_unmodified_outputs_bitwise_equal':all(v['bitwise_equal'] for v in comparisons.values())} ++(a.work/'trace-receipt.json').write_text(json.dumps(result,indent=2)+'\n') ++print(json.dumps({k:v for k,v in result.items() if k in ('returncode','all_unmodified_outputs_bitwise_equal')})) ++if r.returncode or not result['all_unmodified_outputs_bitwise_equal']:raise SystemExit(1) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index af2a77a0..3268bc81 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -17,6 +17,16 @@ add_subdirectory(temporal) + add_library(collision OBJECT collisions/collisions.f90) + target_link_libraries(collision PRIVATE const gemini3d_config meshobj) + ++if(gemini3d_midpoint_conduction) ++ set(midpoint_conduction_fortran ".true.") ++else() ++ set(midpoint_conduction_fortran ".false.") ++endif() ++configure_file(numerical/diffusion/diffusion_features.in.f90 diffusion_features.f90 @ONLY) ++add_library(nonlinear_diffusion OBJECT numerical/diffusion/nonlinear_diffusion.f90 ++ ${CMAKE_CURRENT_BINARY_DIR}/diffusion_features.f90) ++target_link_libraries(nonlinear_diffusion PRIVATE collision const diffusion meshobj) ++ + # --- other libs + + add_subdirectory(neutral) +@@ -29,7 +39,7 @@ add_library(multifluid OBJECT multifluid/multifluid.f90 + $ + ) + target_link_libraries(multifluid PRIVATE +-advec transport_audit calculus collision const diffusion meshobj precipdata ionization precipBCs sources timeutils gemini3d_config neutral) ++advec transport_audit calculus collision const diffusion nonlinear_diffusion meshobj precipdata ionization precipBCs sources timeutils gemini3d_config neutral) + + add_library(gemini_work_def OBJECT intvars/gemini_work_def.f90) + target_link_libraries(gemini_work_def PRIVATE const inputdata neutral precipdata efielddata +@@ -75,7 +85,7 @@ advec transport_audit + calculus gemini3d_config + const + collision +-diffusion fang interp ++diffusion nonlinear_diffusion pair_exchange fang interp + ionization + inputdata precipdata efielddata solfluxdata + gemini3d_sysinfo +@@ -103,7 +113,7 @@ advec_mpi + calculus gemini3d_config + const + collision +-diffusion fang interp ++diffusion nonlinear_diffusion pair_exchange fang interp + ionization + ionization_mpi + inputdata precipdata efielddata solfluxdata +diff --git a/src/collisions/collisions.f90 b/src/collisions/collisions.f90 +index 4a334b5e..6784ecbf 100644 +--- a/src/collisions/collisions.f90 ++++ b/src/collisions/collisions.f90 +@@ -176,7 +176,11 @@ pure subroutine coulomb_colln(isp,isp2,ns,Ts,vs1,nusj,Phisj,Psisj) + sqrt(2*kB*Teff/mred) + Psisj=exp(-Wsj**2) + where (Wsj<0.1_wp) +- Phisj=1 ++ ! 3/W**3 * integral(0:W, x**2*exp(-x**2) dx). The constant ++ ! approximation produced a jump at W=0.1. This convergent expansion ++ ! retains the exact zero-drift limit without subtractive cancellation. ++ Phisj=1-Wsj**2*(3._wp/5-Wsj**2*(3._wp/14-Wsj**2*(1._wp/18 & ++ -Wsj**2*(1._wp/88-Wsj**2*(1._wp/520-Wsj**2/3600))))) + elsewhere + Phisj=3.0_wp/4*sqrt(pi)*erf(Wsj)/Wsj**3 - 3.0_wp/2/Wsj**2*Psisj + end where +diff --git a/src/libgemini_mpi.f90 b/src/libgemini_mpi.f90 +index d6084a18..66b59df8 100644 +--- a/src/libgemini_mpi.f90 ++++ b/src/libgemini_mpi.f90 +@@ -576,7 +576,7 @@ contains + !> get neutral background + ! if ( get_it()/=1 .and. cfg%flagneuBG .and. t>tneuBG) then + if ( get_it()==1 .or. (cfg%flagneuBG .and. t>tneuBG) ) then +- print*, 'Updating neutrals...' ++ !print*, 'Updating neutrals...' + !^we dont' throttle for tneuBG so we have to do things this way to not skip over... + !call cpu_time(tstart) + if (cfg%flagneuBG) then +diff --git a/src/multifluid/multifluid.f90 b/src/multifluid/multifluid.f90 +index 66df3526..df2f47c5 100644 +--- a/src/multifluid/multifluid.f90 ++++ b/src/multifluid/multifluid.f90 +@@ -24,6 +24,8 @@ use calculus, only: etd_uncoupled, div3d + use collisions, only: thermal_conduct, thermal_conduct_new + use phys_consts, only : wp,pi,qs,lsp,gammas,kB,ms,mindensdiv,mindens,mindensnull, debug + use diffusion, only: trbdf23d, diffusion_prep, backEuler3D ++use nonlinear_diffusion, only: midpoint_TRBDF23D ++use diffusion_features, only: midpoint_conduction_enabled + use grid, only: lx1, lx2, lx3, gridflag + use meshobj, only: curvmesh + use ionization, only: ionrate_glow98, ionrate_fang, eheating, photoionization +@@ -274,11 +276,18 @@ end subroutine source_neut + subroutine rhoe2T(ns,rhoes,Ts) + real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: ns,rhoes,Ts + integer :: isp,lsp ++ integer :: n1,n2,n3 ++ real(wp), allocatable :: before(:,:,:) + + lsp=size(rhoes,4) ++ n1=size(Ts,1)-4;n2=size(Ts,2)-4;n3=size(Ts,3)-4 ++ if(audit_transport_enabled) allocate(before(n1,n2,n3)) + do isp=1,lsp + Ts(:,:,:,isp)=(gammas(isp) - 1)/kB*rhoes(:,:,:,isp)/max(ns(:,:,:,isp),mindensdiv) ++ if(audit_transport_enabled) before=Ts(1:n1,1:n2,1:n3,isp) + Ts(:,:,:,isp)=max(Ts(:,:,:,isp), 100._wp) ++ if(audit_transport_enabled) call audit_temperature_floor(3,isp,before,Ts(1:n1,1:n2,1:n3,isp), & ++ ns(1:n1,1:n2,1:n3,isp)*kB/(gammas(isp)-1)) + !! convert internal specific energy density back into temperature + end do + end subroutine rhoe2T +@@ -455,7 +464,11 @@ subroutine energy_diffusion(dt,x,ns,Ts,J1,nn,Tn,flagdiffsolve,Teinf) + case (1) + param=backEuler3D(param,A,B,C,D,E,dt,x,increments) !1st order method + case (2) +- param=TRBDF23D(param,A,B,C,D,E,dt,x,increments) !2nd order method ++ if(midpoint_conduction_enabled) then ++ param=midpoint_TRBDF23D(isp,x,ns(:,:,:,isp),Ts(:,:,:,isp),nn,J1,Tn,Teinf,dt,increments) ++ else ++ param=TRBDF23D(param,A,B,C,D,E,dt,x,increments) ++ endif + case default + print*, 'Unsupported diffusion solver type/mode: ',flagdiffsolve,'. Should be either 1 or 2.' + error stop +diff --git a/src/numerical/diffusion/PDEparabolic.f90 b/src/numerical/diffusion/PDEparabolic.f90 +index 345e8630..5e317088 100644 +--- a/src/numerical/diffusion/PDEparabolic.f90 ++++ b/src/numerical/diffusion/PDEparabolic.f90 +@@ -170,6 +170,8 @@ if (present(Tsmax_mid)) TR(lx1)=Tsmax_mid + !! ### TR HALF STEP MATRIX SOLUTION: CALL LAPACK'S BANDED SOLVER + + !> BANDED SOLVER (INPUT MATRIX MUST BE SHIFTED 'DOWN' BY KL ROWS) ++call eliminate_dirichlet_columns(M,TR,BCtype) ++call scale_interior_rows(M,TR,dt/2) + call gbsv(M,TR,kl=2,info=info) + call check_solver_info(info,'TRBDF21D TR stage') + +@@ -259,6 +261,8 @@ end if + !! ## BDF2 STEP MATRIX SOLUTION: CALL LAPACK'S BANDED SOLVER + + !> BANDED SOLVER (INPUT MATRIX MUST BE SHIFTED 'DOWN' BY KL ROWS) ++call eliminate_dirichlet_columns(M,TRBDF21D,BCtype) ++call scale_interior_rows(M,TRBDF21D,dt/3) + call gbsv(M,TRBDF21D,kl=2,info=info) + call check_solver_info(info,'TRBDF21D BDF2 stage') + +@@ -392,6 +396,8 @@ end if + + !! ## DO SOME STUFF TO CALL LAPACK'S BANDED SOLVER + !> BANDED SOLVER (INPUT MATRIX MUST BE SHIFTED 'DOWN' BY KL ROWS) ++call eliminate_dirichlet_columns(M,backEuler1D,BCtype) ++call scale_interior_rows(M,backEuler1D,dt) + call gbsv(M,backEuler1D,kl=2,info=info) + call check_solver_info(info,'backEuler1D') + +@@ -435,4 +441,43 @@ pure function parabolic_terms(T,A,B,C,D,E,dx,dxi) result(terms) + enddo + end function parabolic_terms + ++! Keep the algebraic endpoint rows at unit scale while bringing each interior ++! stage equation to dimensionless time. SI diffusion coefficients at low ++! density can otherwise dwarf the endpoint rows and lose prescribed values ++! through banded-LU pivoting. The equation and the method are unchanged. ++! Move known Dirichlet values into the interior RHS before pivoting. This ++! decouples endpoint rows from the stiff interior and preserves prescribed ++! values exactly; Neumann endpoint equations retain their coupled columns. ++pure subroutine eliminate_dirichlet_columns(matrix,rhs,bc_type) ++real(wp),intent(inout)::matrix(:,:),rhs(:) ++integer,intent(in)::bc_type(2) ++integer::i,n ++n=size(rhs) ++if(bc_type(1)==0)then ++ do i=2,min(3,n-1) ++ rhs(i)=rhs(i)-matrix(4+i,1)*rhs(1) ++ matrix(4+i,1)=0 ++ enddo ++endif ++if(bc_type(2)==0)then ++ do i=max(2,n-2),n-1 ++ rhs(i)=rhs(i)-matrix(5+i-n,n)*rhs(n) ++ matrix(5+i-n,n)=0 ++ enddo ++endif ++end subroutine eliminate_dirichlet_columns ++ ++pure subroutine scale_interior_rows(matrix,rhs,stage_dt) ++real(wp),intent(inout)::matrix(:,:),rhs(:) ++real(wp),intent(in)::stage_dt ++integer::i,j,n ++n=size(rhs) ++do i=2,n-1 ++ do j=max(1,i-2),min(n,i+2) ++ matrix(5+i-j,j)=matrix(5+i-j,j)*stage_dt ++ enddo ++ rhs(i)=rhs(i)*stage_dt ++enddo ++end subroutine scale_interior_rows ++ + end module PDEparabolic +diff --git a/src/numerical/diffusion/diffusion_features.in.f90 b/src/numerical/diffusion/diffusion_features.in.f90 +new file mode 100644 +index 00000000..38efb216 +--- /dev/null ++++ b/src/numerical/diffusion/diffusion_features.in.f90 +@@ -0,0 +1,6 @@ ++module diffusion_features ++implicit none(type,external) ++private ++public :: midpoint_conduction_enabled ++logical, parameter :: midpoint_conduction_enabled=@midpoint_conduction_fortran@ ++end module diffusion_features +diff --git a/src/numerical/diffusion/nonlinear_diffusion.f90 b/src/numerical/diffusion/nonlinear_diffusion.f90 +new file mode 100644 +index 00000000..1db886e7 +--- /dev/null ++++ b/src/numerical/diffusion/nonlinear_diffusion.f90 +@@ -0,0 +1,47 @@ ++module nonlinear_diffusion ++! Proposed nonlinear time centering. The predictor is virtual: only the final ++! TRBDF2 increments describe applied changes and enter the numerical ledger. ++use, intrinsic :: ieee_arithmetic, only: ieee_is_finite ++use phys_consts, only: wp ++use meshobj, only: curvmesh ++use collisions, only: thermal_conduct ++use diffusion, only: diffusion_prep, backEuler3D, TRBDF23D ++implicit none(type,external) ++private ++public :: midpoint_TRBDF23D ++contains ++function midpoint_TRBDF23D(isp,x,ns,T,nn,J1,Tn,Teinf,dt,increments,lambda_applied) result(Tnew) ++ integer, intent(in) :: isp ++ class(curvmesh), intent(in) :: x ++ real(wp), intent(in) :: ns(-1:,-1:,-1:),T(-1:,-1:,-1:),nn(:,:,:,:),J1(-1:,-1:,-1:),Tn(:,:,:) ++ real(wp), intent(in) :: Teinf,dt ++ real(wp), intent(out), optional :: increments(size(T,1)-4,size(T,2)-4,size(T,3)-4,5) ++ real(wp), intent(out), optional :: lambda_applied(size(T,1)-4,size(T,2)-4,size(T,3)-4) ++ real(wp) :: Tnew(-1:size(T,1)-2,-1:size(T,2)-2,-1:size(T,3)-2) ++ real(wp), allocatable :: initial(:,:,:),predictor(:,:,:),lambda(:,:,:),beta(:,:,:) ++ real(wp), allocatable :: A(:,:,:),B(:,:,:),C(:,:,:),D(:,:,:),E(:,:,:) ++ integer :: n1,n2,n3 ++ n1=size(T,1)-4;n2=size(T,2)-4;n3=size(T,3)-4 ++ if(.not.ieee_is_finite(dt).or.dt<=0) error stop 'midpoint diffusion requires positive finite dt' ++ allocate(initial(-1:n1+2,-1:n2+2,-1:n3+2),predictor(-1:n1+2,-1:n2+2,-1:n3+2)) ++ allocate(lambda(n1,n2,n3),beta(n1,n2,n3),A(n1,n2,n3),B(n1,n2,n3),C(n1,n2,n3),D(n1,n2,n3),E(n1,n2,n3)) ++ initial=T ++ call thermal_conduct(isp,initial,ns,nn,J1,lambda,beta) ++ call diffusion_prep(isp,x,lambda,beta,ns,initial,A,B,C,D,E,Tn,Teinf) ++ predictor=backEuler3D(initial,A,B,C,D,E,dt/2,x) ++ ! Do not quietly introduce a new temperature floor in the virtual stage. ++ if(any(.not.ieee_is_finite(predictor(1:n1,1:n2,1:n3))).or. & ++ any(predictor(1:n1,1:n2,1:n3)<=0)) error stop 'nonpositive or nonfinite midpoint temperature' ++ call thermal_conduct(isp,predictor,ns,nn,J1,lambda,beta) ++ if(any(.not.ieee_is_finite(lambda)).or.any(lambda<=0)) error stop 'invalid midpoint conductivity' ++ ! Rebuild geometry and conductivity-dependent Neumann ghost differences. ++ ! Start the applied step from the original temperature, not the predictor. ++ call diffusion_prep(isp,x,lambda,beta,ns,initial,A,B,C,D,E,Tn,Teinf) ++ if(present(increments)) then ++ Tnew=TRBDF23D(initial,A,B,C,D,E,dt,x,increments) ++ else ++ Tnew=TRBDF23D(initial,A,B,C,D,E,dt,x) ++ endif ++ if(present(lambda_applied)) lambda_applied=lambda ++end function midpoint_TRBDF23D ++end module nonlinear_diffusion +diff --git a/src/sources/CMakeLists.txt b/src/sources/CMakeLists.txt +index f13b6e06..afd32fc6 100644 +--- a/src/sources/CMakeLists.txt ++++ b/src/sources/CMakeLists.txt +@@ -3,5 +3,10 @@ $ $ + ) + target_link_libraries(sources PRIVATE calculus collision const meshobj grid) + ++# A callable conservative pair operator for qualification and later coupling. ++# It is not substituted into the existing split source driver implicitly. ++add_library(pair_exchange OBJECT pair_exchange.f90) ++target_link_libraries(pair_exchange PRIVATE const) ++ + add_library(sources_mpi OBJECT sources_mpi.f90) + target_link_libraries(sources_mpi PRIVATE mpimod) +diff --git a/src/sources/pair_exchange.f90 b/src/sources/pair_exchange.f90 +new file mode 100644 +index 00000000..d28678d5 +--- /dev/null ++++ b/src/sources/pair_exchange.f90 +@@ -0,0 +1,89 @@ ++module pair_exchange ++! Constant-rate, closed two-reservoir model. SI: rho [kg/m^3], Cv [J/m^3/K], ++! drag [kg/m^3/s], conductance [J/m^3/s/K]. Rates are explicitly supplied: ++! this operator enforces laws, but does not validate their physical magnitudes. ++use, intrinsic :: ieee_arithmetic, only: ieee_is_finite ++use phys_consts, only: wp,kB ++implicit none(type,external) ++private ++public :: shared_pair_coefficients, pair_exchange_rates, advance_pair_exchange ++contains ++pure subroutine shared_pair_coefficients(ma,mb,na,nb,nuab,nuba,phi,psi,drag,conductance) ++ real(wp), intent(in) :: ma,mb,na,nb,nuab,nuba,phi,psi ++ real(wp), intent(out) :: drag,conductance ++ real(wp) :: reciprocal_rate ++ if(any(.not.ieee_is_finite([ma,mb,na,nb,nuab,nuba,phi,psi]))) error stop 'nonfinite pair coefficient' ++ if(min(ma,mb)<=0.or.min(na,nb,nuab,nuba,phi,psi)<0) error stop 'invalid pair coefficient' ++ ! Explicit model proposal: average the two rounded directional momentum ++ ! rates once, then use this identical rate in both species equations. ++ reciprocal_rate=(ma*na*nuab+mb*nb*nuba)/2 ++ drag=reciprocal_rate*phi ++ ! Three translational degrees of freedom determine the exchanged POWER. ++ ! Species-specific heat capacities determine temperature response separately. ++ conductance=3*kB*reciprocal_rate*psi/(ma+mb) ++end subroutine shared_pair_coefficients ++ ++pure subroutine pair_exchange_rates(ma,mb,drag,conductance,Ta,Tb,va,vb,Fa,Fb,Qa,Qb) ++ real(wp), intent(in) :: ma,mb,drag,conductance,Ta,Tb,va(3),vb(3) ++ real(wp), intent(out) :: Fa(3),Fb(3),Qa,Qb ++ real(wp) :: heating,transfer,fraction_a ++ if(min(ma,mb)<=0.or.min(drag,conductance)<0) error stop 'invalid pair rate' ++ fraction_a=mb/(ma+mb) ++ Fa=drag*(vb-va);Fb=-Fa ++ heating=drag*sum((va-vb)**2) ++ transfer=conductance*(Tb-Ta) ++ Qa=transfer+fraction_a*heating ++ Qb=-transfer+(1-fraction_a)*heating ++end subroutine pair_exchange_rates ++ ++pure subroutine advance_pair_exchange(rhoa,rhob,Ca,Cb,fraction_a,drag,conductance,dt,va,vb,Ua,Ub) ++ real(wp), intent(in) :: rhoa,rhob,Ca,Cb,fraction_a,drag,conductance,dt ++ real(wp), intent(inout) :: va(3),vb(3),Ua,Ub ++ real(wp) :: reduced_rho, reduced_C, rate_v,rate_T,delta(3),dP(3),kinetic_heat ++ real(wp) :: difference0,friction0,integral,thermal_transfer ++ real(wp) :: heat_a,heat_b,friction_difference,thermal_fraction ++ if(any(.not.ieee_is_finite([rhoa,rhob,Ca,Cb,fraction_a,drag,conductance,dt,va,vb,Ua,Ub]))) & ++ error stop 'nonfinite pair state' ++ if(min(rhoa,rhob,Ca,Cb)<=0.or.min(drag,conductance,dt,Ua,Ub)<0.or. & ++ fraction_a<0.or.fraction_a>1) error stop 'invalid pair state' ++ if(dt==0.or.(drag==0.and.conductance==0)) return ++ reduced_rho=rhoa*(rhob/(rhoa+rhob)) ++ reduced_C=Ca*(Cb/(Ca+Cb)) ++ rate_v=drag/reduced_rho ++ rate_T=conductance/reduced_C ++ delta=va-vb ++ difference0=Ua/Ca-Ub/Cb ++ dP=-reduced_rho*delta*decay_fraction(rate_v*dt) ++ va=va+dP/rhoa;vb=vb-dP/rhob ++ ! Account for the actual finite-step loss of relative bulk kinetic energy, ++ ! rather than integrating frozen velocities as if the loss stayed constant. ++ kinetic_heat=(reduced_rho*sum(delta**2)/2)*decay_fraction(2*rate_v*dt) ++ friction0=drag*sum(delta**2) ++ ! Stable convolution of e^(-rate_T*t) with e^(-2*rate_v*t). ++ integral=dt*exp(-min(rate_T,2*rate_v)*dt)*phi_negative(abs(rate_T-2*rate_v)*dt) ++ friction_difference=friction0*(fraction_a/Ca-(1-fraction_a)/Cb)*integral ++ thermal_fraction=decay_fraction(rate_T*dt) ++ ! A single opposite transfer retains small changes without reconstructing ++ ! each large reservoir from its equilibrium value. ++ thermal_transfer=reduced_C*(-difference0*thermal_fraction+friction_difference) ++ heat_a=Ca/(Ca+Cb)*kinetic_heat+thermal_transfer ++ heat_b=kinetic_heat-heat_a ++ Ua=Ua+heat_a;Ub=Ub+heat_b ++end subroutine advance_pair_exchange ++ ++pure elemental function phi_negative(z) result(phi) ++ real(wp), intent(in) :: z ++ real(wp) :: phi ++ if(z<1e-3_wp) then ++ phi=1-z*(1._wp/2-z*(1._wp/6-z*(1._wp/24-z*(1._wp/120-z*(1._wp/720-z/5040))))) ++ else ++ phi=(1-exp(-z))/z ++ endif ++end function phi_negative ++ ++pure elemental function decay_fraction(z) result(fraction) ++ real(wp), intent(in) :: z ++ real(wp) :: fraction ++ fraction=z*phi_negative(z) ++end function decay_fraction ++end module pair_exchange +diff --git a/test/audit/CMakeLists.txt b/test/audit/CMakeLists.txt +index cb893eef..571f7931 100644 +--- a/test/audit/CMakeLists.txt ++++ b/test/audit/CMakeLists.txt +@@ -183,7 +183,7 @@ if(Python_Interpreter_FOUND) + ${PROJECT_SOURCE_DIR}/test/qualification/test_etd.py --exe $ + --output ${CMAKE_CURRENT_BINARY_DIR}/etd-oracle.json) + set_tests_properties(qualification:etd_oracle PROPERTIES LABELS "unit;qualification") +- foreach(probe IN ITEMS source_ledger kernel_memory host_capabilities hosted_evidence qualification_dependencies) ++ foreach(probe IN ITEMS source_ledger kernel_memory host_capabilities hosted_evidence qualification_dependencies transport_inventory clock_inventory) + add_test(NAME qualification:${probe} COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_${probe}.py) + set_tests_properties(qualification:${probe} PROPERTIES LABELS "unit;qualification") +@@ -214,6 +214,15 @@ target_link_libraries(qualification_energy_operators PRIVATE diffusion PDEparabo + intel_fortran_main_linker(qualification_energy_operators) + add_test(NAME qualification:energy_operators COMMAND qualification_energy_operators) + set_tests_properties(qualification:energy_operators PROPERTIES LABELS "unit;qualification") ++ ++add_executable(qualification_temperature_floor ../qualification/temperature_floor.f90) ++target_link_libraries(qualification_temperature_floor PRIVATE transport_audit multifluid meshobj_cart grid const gemini3d) ++intel_fortran_main_linker(qualification_temperature_floor) ++if(Python_Interpreter_FOUND) ++ add_test(NAME qualification:temperature_floor COMMAND ${Python_EXECUTABLE} ++ ${PROJECT_SOURCE_DIR}/test/qualification/test_temperature_floor.py --exe $) ++ set_tests_properties(qualification:temperature_floor PROPERTIES LABELS "unit;qualification") ++endif() + if(Python_Interpreter_FOUND) + add_test(NAME qualification:energy_ledger COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_energy_ledger.py) +@@ -223,3 +232,31 @@ endif() + foreach(audit_extension IN ITEMS numerics lifecycle contracts restart installation) + include("${CMAKE_CURRENT_LIST_DIR}/${audit_extension}.cmake" OPTIONAL) + endforeach() ++ ++add_executable(qualification_diffusion_scale ../qualification/diffusion_scale.f90) ++target_link_libraries(qualification_diffusion_scale PRIVATE PDEparabolic const) ++intel_fortran_main_linker(qualification_diffusion_scale) ++add_test(NAME qualification:diffusion_scale COMMAND qualification_diffusion_scale) ++set_tests_properties(qualification:diffusion_scale PROPERTIES LABELS "unit;qualification;numerics") ++ ++add_executable(qualification_coulomb_curve ../qualification/coulomb_curve.f90) ++target_link_libraries(qualification_coulomb_curve PRIVATE gemini3d) ++intel_fortran_main_linker(qualification_coulomb_curve) ++add_test(NAME qualification:coulomb_curve COMMAND qualification_coulomb_curve) ++set_tests_properties(qualification:coulomb_curve PROPERTIES LABELS "unit;qualification;numerics") ++ ++add_executable(qualification_pair_exchange ../qualification/pair_exchange_probe.f90) ++target_link_libraries(qualification_pair_exchange PRIVATE gemini3d) ++intel_fortran_main_linker(qualification_pair_exchange) ++if(SCIPY_FOUND AND NUMPY_FOUND) ++ add_test(NAME qualification:pair_exchange COMMAND ${Python_EXECUTABLE} ++ ${PROJECT_SOURCE_DIR}/test/qualification/test_pair_exchange.py ++ --exe $ --output ${CMAKE_CURRENT_BINARY_DIR}/pair-exchange-results.json) ++ set_tests_properties(qualification:pair_exchange PROPERTIES LABELS "unit;qualification;physics" TIMEOUT 180) ++ add_test(NAME qualification:midpoint_diffusion COMMAND ${Python_EXECUTABLE} ++ ${PROJECT_SOURCE_DIR}/test/qualification/test_midpoint_diffusion.py ++ --source ${PROJECT_SOURCE_DIR} --build ${PROJECT_BINARY_DIR} ++ --work ${CMAKE_CURRENT_BINARY_DIR}/midpoint-diffusion) ++ set_tests_properties(qualification:midpoint_diffusion PROPERTIES LABELS "unit;qualification;physics" TIMEOUT 180 ++ ENVIRONMENT "FC=${CMAKE_Fortran_COMPILER}") ++endif() +diff --git a/test/potential/plot_potential2d_aurora.py b/test/potential/plot_potential2d_aurora.py +new file mode 100644 +index 00000000..129a825b +--- /dev/null ++++ b/test/potential/plot_potential2d_aurora.py +@@ -0,0 +1,127 @@ ++#!/usr/bin/env python3 ++""" ++Created on Mon Apr 20 18:13:14 2026 ++ ++@author: zettergm ++""" ++ ++import argparse ++import numpy as np ++import h5py ++ ++from matplotlib.pyplot import figure,pcolormesh,xlabel,ylabel,title,colorbar ++ ++ ++def read_potential(fn) -> dict: ++ with h5py.File(fn, "r") as f: ++ out = {"lx1": f["/lx1"][()], ++ "lx2": f["/lx2"][()], ++ "lx3": f["/lx3"][()], ++ "x1": f["/x1"][:], ++ "x2": f["/x2"][:], ++ "x3": f["/x3"][:], ++ "Phi": f["/Phi"][:], ++ "A": f["/A"][:], ++ "Ap": f["/Ap"][:], ++ "SigH": f["/SigH"][:], ++ "B": f["/B"][:], ++ "C": f["/C"][:], ++ "srcterm": f["/srcterm"][:]} ++ ++ assert out["lx1"] == out["x1"].size ++ assert out["lx2"] == out["x2"].size ++ assert out["lx3"] == out["x3"].size ++ ++ return out ++ ++ ++def plot_potential(data): ++ ++ x2 = data["x2"] ++ x3 = data["x3"] ++ Phi = data["Phi"] ++ srcterm = data["srcterm"] ++ ++ figure(figsize=(6, 6)) ++ pcolormesh(x2, x3, Phi) ++ colorbar() ++ ylabel("distance [m]") ++ xlabel("distance [m]") ++ title("2D potential (numerical)") ++ ++ #figure() ++ #pcolormesh(x2,x3,data["A"]) ++ #colorbar() ++ #title("Pedersen") ++ ++ figure() ++ pcolormesh(x2,x3,data["Ap"]) ++ colorbar() ++ title("Ap") ++ ++ # figure() ++ # pcolormesh(x2,x3,data["SigH"]) ++ # colorbar() ++ ++ # figure() ++ # pcolormesh(x2,x3,data["B"]) ++ # colorbar() ++ ++ # figure() ++ # pcolormesh(x2,x3,data["C"]) ++ # colorbar() ++ ++ figure() ++ pcolormesh(x2,x3,srcterm) # srcterm is -Jpar ++ colorbar() ++ title("Jpar") ++ ++ ## Apparently hdf5 mangles array axes??? ++ Ex,Ey = np.gradient(-1*Phi.transpose(),x2,x3) # WHYYYYY ++ SigP=data["A"].transpose() ++ SigH=data["SigH"].transpose() ++ Jx=SigP*Ex-SigH*Ey ++ Jy=SigH*Ex+SigP*Ey ++ Jxx,_ = np.gradient(Jx,x2,x3) ++ _,Jyy = np.gradient(Jy,x2,x3) ++ divJ=Jxx+Jyy ++ Jpartest=-divJ ++ errterm=Jpartest-srcterm ++ print("Max error in Jpar:", np.max(np.abs(errterm))) ++ ++ figure() ++ pcolormesh(x2,x3,Ex.transpose()) ++ colorbar() ++ title("Ex") ++ ++ figure() ++ pcolormesh(x2,x3,Ey.transpose()) ++ colorbar() ++ title("Ey") ++ ++ figure() ++ pcolormesh(x2,x3,Jx.transpose()) ++ colorbar() ++ title("Jx") ++ ++ figure() ++ pcolormesh(x2,x3,Jy.transpose()) ++ colorbar() ++ title("Jy") ++ ++ figure() ++ pcolormesh(x2,x3,Jpartest.transpose()) ++ colorbar() ++ title("div J") ++ ++ ++if __name__ == "__main__": ++ parser = argparse.ArgumentParser() ++ parser.add_argument("fn", help="HDF5 file containing potential data") ++ parser.add_argument("--noplot", action="store_true", help="Do not display plots") ++ args = parser.parse_args() ++ fn = args.fn ++ ++ data = read_potential(fn) ++ if not args.noplot: ++ plot_potential(data) +diff --git a/test/potential/test_potential2d_auroral.py b/test/potential/test_potential2d_auroral.py +deleted file mode 100644 +index 954a864b..00000000 +--- a/test/potential/test_potential2d_auroral.py ++++ /dev/null +@@ -1,116 +0,0 @@ +-#!/usr/bin/env python3 +-# -*- coding: utf-8 -*- +-""" +-Created on Mon Apr 20 18:13:14 2026 +- +-@author: zettergm +-""" +- +-#!/usr/bin/env python3 +-#from pathlib import Path +-#import argparse +-import sys +-import typing +- +-import numpy as np +-import h5py +- +-from matplotlib.pyplot import figure,pcolormesh,xlabel,ylabel,title,colorbar +- +-fn = "/Users/zettergm/Projects/gemini3d/build/test/potential/output.h5" +-doplot = True +- +-# if not fn.is_file(): +-# print(fn, "not found", file=sys.stderr) +-# raise SystemExit(77) +- +-with h5py.File(fn, "r") as f: +- lx1 = f["/lx1"][()] +- lx2 = f["/lx2"][()] +- lx3 = f["/lx3"][()] +- x1 = f["/x1"][:] +- x2 = f["/x2"][:] +- x3 = f["/x3"][:] +- Phi = f["/Phi"][:] +- A = f["/A"][:] +- Ap = f["/Ap"][:] +- SigH = f["/SigH"][:] +- B = f["/B"][:] +- C = f["/C"][:] +- srcterm = f["/srcterm"][:] +-assert lx1 == x1.size +-assert lx2 == x2.size +-assert lx3 == x3.size +- +-if not doplot: +- exit +- +-fg = figure(figsize=(6, 6)) +-h = pcolormesh(x2, x3, Phi) +-colorbar() +-ylabel("distance [m]") +-xlabel("distance [m]") +-title("2D potential (numerical)") +- +-#figure() +-#pcolormesh(x2,x3,A) +-#colorbar() +-#title("Pedersen") +- +-# figure() +-# pcolormesh(x2,x3,Ap) +-# colorbar() +- +-# figure() +-# pcolormesh(x2,x3,SigH) +-# colorbar() +- +-# figure() +-# pcolormesh(x2,x3,B) +-# colorbar() +- +-# figure() +-# pcolormesh(x2,x3,C) +-# colorbar() +- +-figure() +-pcolormesh(x2,x3,srcterm) # srcterm is -Jpar +-colorbar() +-title("Jpar") +- +-## Apparently hdf5 mangles array axes??? +-Ex,Ey = np.gradient(-1*Phi.transpose(),x2,x3) # WHYYYYY +-SigP=A.transpose() +-SigH=SigH.transpose() +-Jx=SigP*Ex-SigH*Ey +-Jy=SigH*Ex+SigP*Ey +-Jxx,_ = np.gradient(Jx,x2,x3) +-_,Jyy = np.gradient(Jy,x2,x3) +-divJ=Jxx+Jyy +-Jpartest=-divJ +-errterm=Jpartest-srcterm +- +-figure() +-pcolormesh(x2,x3,Ex.transpose()) +-colorbar() +-title("Ex") +- +-figure() +-pcolormesh(x2,x3,Ey.transpose()) +-colorbar() +-title("Ey") +- +-figure() +-pcolormesh(x2,x3,Jx.transpose()) +-colorbar() +-title("Jx") +- +-figure() +-pcolormesh(x2,x3,Jy.transpose()) +-colorbar() +-title("Jy") +- +-figure() +-pcolormesh(x2,x3,Jpartest.transpose()) +-colorbar() +-title("div J") +diff --git a/test/qualification/analyze_midpoint_diffusion.py b/test/qualification/analyze_midpoint_diffusion.py +new file mode 100644 +index 00000000..d8acd712 +--- /dev/null ++++ b/test/qualification/analyze_midpoint_diffusion.py +@@ -0,0 +1,147 @@ ++"""Independent conservative balances and theoretical observables for native probes.""" ++import argparse ++import csv ++import hashlib ++import json ++from pathlib import Path ++import numpy as np ++from scipy.integrate import solve_ivp ++from scipy.linalg import solve_banded ++ ++p=argparse.ArgumentParser() ++p.add_argument('--work', type=Path, required=True) ++p.add_argument('--trace', type=Path) ++p.add_argument('--candidate',required=True) ++a=p.parse_args() ++w=a.work ++LIMIT=1e-11 ++def rows(path): ++ with path.open() as f: ++ return [{k:float(v) for k,v in r.items()} for r in csv.DictReader(f)] ++def norm_res(terms): ++ return abs(sum(terms))/max(sum(abs(x) for x in terms), np.finfo(float).tiny) ++def orders(errors): ++ return [float(np.log2(errors[i]/errors[i+1])) for i in range(2)] ++ ++conduct=[] ++traces={} ++if a.trace: ++ native_trace=np.loadtxt(a.trace,delimiter=',') ++ offset=0 ++ for path in sorted(w.glob('conduction_*_m[23]_*.csv')): ++ rs=rows(path);nodes=int(max(r['node'] for r in rs));steps=int(max(r['step'] for r in rs)) ++ count=steps*nodes ++ traces[path.name]=native_trace[offset:offset+count].reshape(steps,nodes,4) ++ offset+=count ++ assert offset==len(native_trace) ++oracle_cache={} ++for path in sorted(w.glob('conduction_*.csv')): ++ data=rows(path) ++ n=int(max(r['node'] for r in data));steps=int(max(r['step'] for r in data));r=data[0] ++ dt,dx,cv=r['dt'],r['dx'],r['Cv'] ++ window=int(path.stem.split('_w')[1][0]);method=int(path.stem.split('_m')[1][0]);level=int(path.stem.split('_l')[1][0]) ++ density=r['ns'];total=dt*steps ++ initial=np.linspace(600.,1500.,n) ++ scale=density/1e5 ++ # Density scaling uses tau=t/scale so both cases independently share the ++ # same mathematically defined problem; retain each physical native result. ++ key=(n,window,total/scale) ++ if key not in oracle_cache: ++ def rhs(t, interior): ++ temp=np.r_[600.,interior,1500.] ++ lam=.3986e-12*temp**2.5 ++ flux=-.5*(lam[:-1]+lam[1:])*np.diff(temp)/dx ++ return -(flux[1:]-flux[:-1])/(cv/scale*dx) ++ sol=solve_ivp(rhs,[0.,total/scale],initial[1:-1],method='Radau',rtol=1e-11,atol=1e-9) ++ tight=solve_ivp(rhs,[0.,total/scale],initial[1:-1],method='Radau',rtol=2e-13,atol=2e-11) ++ if not sol.success or not tight.success: ++ raise RuntimeError('Independent MOL oracle failed: '+sol.message+' / '+tight.message) ++ reference=np.r_[600.,tight.y[:,-1],1500.] ++ control=float(np.linalg.norm(sol.y[:,-1]-tight.y[:,-1])/np.linalg.norm(tight.y[:,-1])) ++ oracle_cache[key]={'temperature_K':reference,'control_relative_rms':control, ++ 'nfev':int(tight.nfev),'njev':int(tight.njev)} ++ oracle=oracle_cache[key] ++ step_balances=[];telescoping=[];diagnostic_balances=[];stage_mismatches=[];floors=0 ++ for it in range(1,steps+1): ++ rs=[r for r in data if r['step']==it] ++ old=np.array([r['Told'] for r in rs]);new=np.array([r['Tnew'] for r in rs]);raw=np.array([r['Traw'] for r in rs]) ++ lam=np.array([r['lambda_applied'] if 'lambda_applied' in r else r['lambda_old'] for r in rs]);face=.5*(lam[:-1]+lam[1:]) ++ alpha=face/(cv*dx**2) ++ def flux(temp):return -face*np.diff(temp)/dx ++ if method==1: ++ integrated=dt*flux(raw) ++ else: ++ # Independent tridiagonal Crank-Nicolson half-stage for native ++ # TR-BDF2 (frozen lambda). No native residual is used as heat input. ++ c=dt/4 ++ band=np.zeros((3,n-2));diagonal=alpha[:-1]+alpha[1:] ++ band[1]=1+c*diagonal ++ band[0,1:]=-c*alpha[1:-1];band[2,:-1]=-c*alpha[1:-1] ++ old_rhs=old[1:-1]+c*(alpha[1:]*np.diff(old)[1:]-alpha[:-1]*np.diff(old)[:-1]) ++ old_rhs[0]+=c*alpha[0]*600;old_rhs[-1]+=c*alpha[-1]*1500 ++ tr=np.r_[600.,solve_banded((1,1),band,old_rhs),1500.] ++ if path.name in traces: ++ native=traces[path.name][it-1] ++ assert np.array_equal(native[:,1],old) and np.array_equal(native[:,3],raw) ++ independent_tr=tr ++ tr=native[:,2] ++ stage_mismatches.append(float(np.max(abs(independent_tr-tr))/np.max(abs(tr)))) ++ integrated=dt/3*(flux(old)+flux(tr)+flux(raw)) ++ derived=(4*tr[1:-1]-old[1:-1])/3+dt/3*(alpha[1:]*np.diff(raw)[1:]-alpha[:-1]*np.diff(raw)[:-1]) ++ stage_mismatches.append(float(np.max(abs(derived-raw[1:-1]))/np.max(abs(raw)))) ++ change=float(cv*dx*np.sum(raw[1:-1]-old[1:-1])) ++ incoming=float(integrated[0]-integrated[-1]) ++ power_cells=-(integrated[1:]-integrated[:-1]) ++ scale_balance=max(float(np.sum(abs(cv*dx*(raw[1:-1]-old[1:-1])))), ++ float(np.sum(abs(power_cells))),abs(integrated[0])+abs(integrated[-1]),np.finfo(float).tiny) ++ step_balances.append(abs(change-incoming)/scale_balance) ++ telescoping.append(abs(np.sum(power_cells)-incoming)/scale_balance) ++ inc=np.array([[r[k] for k in ('reaction','drift','conduction','source','reservoir')] for r in rs]) ++ diagnostic_balances.append(float(np.max(abs(raw-old-np.sum(inc,axis=1)))/max(np.max(abs(raw-old)),np.finfo(float).tiny))) ++ floors+=int(np.count_nonzero(new!=raw)) ++ final=np.array([r['Tnew'] for r in data if r['step']==steps]) ++ error=float(np.linalg.norm(final[1:-1]-oracle['temperature_K'][1:-1])/np.linalg.norm(oracle['temperature_K'][1:-1])) ++ entry={'file':path.name,'density_m3':density,'window':window,'method':method,'level':level, ++ 'steps':steps,'dt_s':dt,'duration_s':total,'temperature_relative_rms':error, ++ 'oracle_control_relative_rms':oracle['control_relative_rms'], ++ 'maximum_energy_balance_normalized':max(step_balances), ++ 'maximum_face_telescoping_normalized':max(telescoping), ++ 'maximum_diagnostic_increment_relative':max(diagnostic_balances), ++ 'maximum_independent_TR_stage_relative':max(stage_mismatches,default=0), ++ 'native_stage_trace_used':method==1 or path.name in traces, ++ 'fixed_boundary_max_error_K':max(abs(r['Traw']-(600 if r['node']==1 else 1500)) for r in data if r['node'] in (1,n)), ++ 'floor_cell_events':floors,'temperature_K':final.tolist(), ++ 'oracle_temperature_K':oracle['temperature_K'].tolist(), ++ 'energy_pass':max(step_balances)<=LIMIT,'temperature_pass':error<=.1} ++ conduct.append(entry) ++groups=[] ++for density,window,method in sorted(set((r['density_m3'],r['window'],r['method']) for r in conduct)): ++ levels=sorted([r for r in conduct if (r['density_m3'],r['window'],r['method'])==(density,window,method)],key=lambda r:r['level']) ++ os=orders([r['temperature_relative_rms'] for r in levels]) ++ minorder=.9 if method==1 else 1.8 ++ groups.append({'density_m3':density,'window':window,'method':method,'errors':[r['temperature_relative_rms'] for r in levels], ++ 'orders':os,'required_order':minorder, ++ 'energy_pass':all(r['energy_pass'] for r in levels), ++ 'temperature_pass':all(r['temperature_pass'] for r in levels), ++ 'order_pass':min(os)>=minorder}) ++pc03={'cases':conduct,'groups':groups,'passed':all(r['energy_pass'] and r['temperature_pass'] and r['order_pass'] for r in groups)} ++ ++kir=rows(w/'kirchhoff_flux.csv');steady=[] ++qexact=-.3986e-12*(1500.**3.5-600.**3.5)/(3.5*1e5) ++for level in range(3): ++ rs=[r for r in kir if r['level']==level] ++ temp=np.array([r['T'] for r in rs]);lam=np.array([r['lambda'] for r in rs]);dx=rs[0]['dx'] ++ q=-.5*(lam[:-1]+lam[1:])*np.diff(temp)/dx ++ err=float(np.sqrt(np.mean((q-qexact)**2))/abs(qexact)) ++ steady.append({'level':level,'nodes':len(rs),'dx_m':dx,'exact_flux_Wm2':qexact, ++ 'relative_l2_face_flux_error':err,'minimum_flux_Wm2':float(min(q)),'maximum_flux_Wm2':float(max(q))}) ++pc04={'levels':steady,'orders':orders([r['relative_l2_face_flux_error'] for r in steady])} ++pc04['passed']=min(pc04['orders'])>=1.8 ++result={'schema':'gemini.physical.closure.results.1','budget':LIMIT, ++ 'native_source_revision':a.candidate, ++ 'PC03':pc03,'PC04':pc04, 'passed':pc03['passed'] and pc04['passed']} ++(w/'physics-results.json').write_text(json.dumps(result,indent=2,allow_nan=False,default=lambda v:v.item() if isinstance(v,np.generic) else str(v))+'\n') ++print(json.dumps({k:{s:v for s,v in result[k].items() if s in ('passed','case_count','passing_cases','orders','groups')} ++ for k in ('PC03','PC04')},indent=2)) ++ ++raise SystemExit(0 if result['passed'] else 1) +diff --git a/test/qualification/coulomb_curve.f90 b/test/qualification/coulomb_curve.f90 +new file mode 100644 +index 00000000..71a2aaa0 +--- /dev/null ++++ b/test/qualification/coulomb_curve.f90 +@@ -0,0 +1,37 @@ ++program coulomb_curve ++use phys_consts,only:wp,lsp,kb,ms ++use collisions,only:coulomb_colln ++implicit none(type,external) ++real(wp),parameter::values(13)=[0._wp,1e-8_wp,1e-6_wp,.001_wp,.01_wp,.05_wp, & ++ .09999999_wp,.1_wp,.10000001_wp,.5_wp,1._wp,3._wp,10._wp] ++real(wp)::ns(-1:3,-1:3,-1:3,lsp),ts(-1:3,-1:3,-1:3,lsp),v(-1:3,-1:3,-1:3,lsp) ++real(wp)::nu(1,1,1),phi(1,1,1),psi(1,1,1),speed,w,oracle,error ++integer::i ++ns=0;ts=1000;v=0;ns(:,:,:,1)=2e11_wp;ns(:,:,:,6)=8e10_wp ++speed=sqrt(2*kb*1000/(ms(1)*ms(6)/(ms(1)+ms(6)))) ++do i=1,size(values) ++ v(:,:,:,1)=values(i)*speed;w=abs(v(1,1,1,1))/speed ++ call coulomb_colln(1,6,ns,ts,v,nu,phi,psi) ++ ! Independent numerical integral on a fixed interval. This does not reuse ++ ! either production power-series coefficients or the erf expression. ++ oracle=integral(w);error=abs(phi(1,1,1)-oracle) ++ print '(2(es25.17,1x))',w,error ++ if(error>5e-14_wp)error stop 'Coulomb drag integral and continuity' ++enddo ++contains ++pure function integral(w)result(value) ++real(wp),intent(in)::w ++real(wp)::value,total,compensation,term,y,next,x,weight ++integer,parameter::n=4096 ++integer::j ++total=exp(-w*w);compensation=0 ++do j=1,n-1 ++ x=real(j,wp)/n;weight=2 ++ if(modulo(j,2)==1)weight=4 ++ term=weight*x*x*exp(-(w*x)**2) ++ y=term-compensation;next=total+y ++ compensation=(next-total)-y;total=next ++enddo ++value=total/n ++end function ++end program +diff --git a/test/qualification/diffusion_scale.f90 b/test/qualification/diffusion_scale.f90 +new file mode 100644 +index 00000000..035ea757 +--- /dev/null ++++ b/test/qualification/diffusion_scale.f90 +@@ -0,0 +1,25 @@ ++program diffusion_scale ++use phys_consts, only: wp ++use PDEparabolic, only: backEuler1D,TRBDF21D ++implicit none(type,external) ++integer,parameter::n=49 ++real(wp)::u(n),initial(n),a(n),b(n),c(n),d(n),e(n),dx(0:n+2),dxi(n),dt,err,bcerr ++integer::i,method ++logical::passed ++a=0;b=0;c=1e18_wp;d=3e-5_wp;e=0 ++dx=1e5_wp/(n-1);dxi=dx(1);dt=6.25e-5_wp ++initial=[(600+900._wp*(i-1)/(n-1),i=1,n)] ++passed=.true. ++do method=1,2 ++ u=initial ++ if(method==1)then ++ u=backEuler1D(u,a,b,c,d,e,600._wp,1500._wp,dt,[0,0],dx,dxi) ++ else ++ u=TRBDF21D(u,a,b,c,d,e,600._wp,1500._wp,dt,[0,0],dx,dxi) ++ endif ++ err=maxval(abs(u-initial));bcerr=max(abs(u(1)-600),abs(u(n)-1500)) ++ print '(i0,2(1x,es25.17))',method,err,bcerr ++ passed=passed.and.bcerr<=1e-11_wp ++enddo ++if(.not.passed)error stop 'prescribed boundary temperature lost under SI coefficient scaling' ++end program +diff --git a/test/qualification/midpoint_diffusion_probe.f90 b/test/qualification/midpoint_diffusion_probe.f90 +new file mode 100644 +index 00000000..84845548 +--- /dev/null ++++ b/test/qualification/midpoint_diffusion_probe.f90 +@@ -0,0 +1,130 @@ ++program physics_native ++use phys_consts, only: wp,lsp,ln,kb,ms,gammas ++use collisions, only: coulomb_colln,thermal_conduct ++use sources, only: srcsEnergy ++use calculus, only: ETD_uncoupled ++use meshobj_cart, only: cartmesh ++use grid, only: set_total_grid_sizes,set_subgrid_sizes,set_gridflag ++use diffusion, only: diffusion_prep,backEuler3D,TRBDF23D ++use nonlinear_diffusion, only: midpoint_TRBDF23D ++use diffusion_features, only: midpoint_conduction_enabled ++use multifluid, only: energy_diffusion ++implicit none(type,external) ++character(4096) :: directory,trace_name ++integer :: trace_status ++call get_command_argument(1,directory) ++if(len_trim(directory)==0) error stop 'output directory required' ++call nonlinear_conduction() ++call kirchhoff_flux() ++call get_environment_variable('GEMINI_PHYSICAL_TR_TRACE',trace_name,status=trace_status) ++if(trace_status/=0) call wrapper_checks() ++contains ++ ++subroutine nonlinear_conduction() ++integer,parameter :: n=49 ++type(cartmesh) :: x ++real(wp) :: ns(-1:n+2,-1:3,-1:3),temp(-1:n+2,-1:3,-1:3),old(-1:n+2,-1:3,-1:3),raw(-1:n+2,-1:3,-1:3) ++real(wp) :: nn(n,1,1,ln),j1(-1:n+2,-1:3,-1:3),tn(n,1,1) ++real(wp) :: lam(n,1,1),beta(n,1,1),a(n,1,1),b(n,1,1),c(n,1,1),d(n,1,1),e(n,1,1),inc(n,1,1,5) ++real(wp) :: density,dx,total,dt,cv ++integer :: id,window,level,method,i,it,nt,u ++character(64) :: name ++call set_total_grid_sizes(n,1,1);call set_subgrid_sizes(1,1);call set_gridflag(2) ++x%lx1=n;x%lx2=1;x%lx3=1 ++allocate(x%h1(-1:n+2,-1:3,-1:3),x%h2(-1:n+2,-1:3,-1:3),x%h3(-1:n+2,-1:3,-1:3)) ++allocate(x%dx1(0:n+2),x%dx1i(n)) ++x%h1=1;x%h2=1;x%h3=1;dx=1e5_wp/(n-1);x%dx1=dx;x%dx1i=dx ++nn=0;j1=0;tn=600 ++do id=1,2 ++ density=1e5_wp ++ if(id==2)density=1e11_wp ++ ns=density;cv=density*kb/(gammas(6)-1) ++ do window=3,3 ++ if(window==2.and.id==2)cycle ++ total=.0001_wp*(density/1e5_wp) ++ if(window==2)total=.8_wp ++ do method=3,3 ++ do level=0,2 ++ nt=8*2**level;dt=total/nt ++ write(name,'(a,i0,a,i0,a,i0,a,i0,a)') 'conduction_d',id,'_w',window,'_m',method,'_l',level,'.csv' ++ open(newunit=u,file=trim(directory)//'/'//trim(name),status='new') ++ write(u,'(a)') 'step,node,t,dt,ns,dx,Cv,Told,Traw,Tnew,lambda_applied,reaction,drift,conduction,source,reservoir' ++ temp=600 ++ do i=1,n ++ temp(i,1,1)=600+900._wp*(i-1)/(n-1) ++ enddo ++ do it=1,nt ++ old=temp ++ raw=midpoint_TRBDF23D(6,x,ns,temp,nn,j1,tn,1500._wp,dt,inc,lam) ++ temp=max(raw,100._wp) ++ do i=1,n ++ write(u,'(i0,",",i0,14(",",es25.17))') it,i,it*dt,dt,density,dx,cv,old(i,1,1), & ++ raw(i,1,1),temp(i,1,1),lam(i,1,1),inc(i,1,1,:) ++ enddo ++ enddo ++ close(u) ++ enddo ++ enddo ++ enddo ++enddo ++! The manually allocated probe mesh does not claim a complete application grid. ++deallocate(x%h1,x%h2,x%h3,x%dx1,x%dx1i) ++end subroutine ++ ++subroutine kirchhoff_flux() ++integer :: level,n,i,u ++real(wp),allocatable :: temp(:,:,:),ns(:,:,:),nn(:,:,:,:),j1(:,:,:),lam(:,:,:),beta(:,:,:) ++real(wp) :: dx,xx ++open(newunit=u,file=trim(directory)//'/kirchhoff_flux.csv',status='new') ++write(u,'(a)') 'level,node,n,x,dx,T,lambda' ++do level=0,2 ++ n=64*2**level+1;dx=1e5_wp/(n-1) ++ allocate(temp(-1:n+2,-1:3,-1:3),ns(-1:n+2,-1:3,-1:3),j1(-1:n+2,-1:3,-1:3)) ++ allocate(nn(n,1,1,ln),lam(n,1,1),beta(n,1,1)) ++ temp=600;ns=1e11_wp;j1=0;nn=0 ++ do i=1,n ++ xx=real(i-1,wp)/real(n-1,wp) ++ temp(i,1,1)=(600._wp**3.5_wp+(1500._wp**3.5_wp-600._wp**3.5_wp)*xx)**(1/3.5_wp) ++ enddo ++ call thermal_conduct(6,temp,ns,nn,j1,lam,beta) ++ do i=1,n ++ write(u,'(i0,",",i0,",",i0,4(",",es25.17))') level,i,n,(i-1)*dx,dx,temp(i,1,1),lam(i,1,1) ++ enddo ++ deallocate(temp,ns,j1,nn,lam,beta) ++enddo ++close(u) ++end subroutine ++subroutine wrapper_checks() ++integer,parameter :: n=49 ++type(cartmesh) :: x ++real(wp) :: ns(-1:n+2,-1:3,-1:3,lsp),temp(-1:n+2,-1:3,-1:3,lsp) ++real(wp) :: old(-1:n+2,-1:3,-1:3),raw(-1:n+2,-1:3,-1:3),plain(-1:n+2,-1:3,-1:3) ++real(wp) :: nn(n,1,1,ln),j(-1:n+2,-1:3,-1:3),tn(n,1,1),inc(n,1,1,5) ++integer :: i,flag ++call set_total_grid_sizes(n,1,1);call set_subgrid_sizes(1,1) ++x%lx1=n;x%lx2=1;x%lx3=1 ++allocate(x%h1(-1:n+2,-1:3,-1:3),x%h2(-1:n+2,-1:3,-1:3),x%h3(-1:n+2,-1:3,-1:3)) ++allocate(x%dx1(0:n+2),x%dx1i(n)) ++x%h1=1;x%h2=1;x%h3=1;x%dx1=1e5_wp/(n-1);x%dx1i=x%dx1(1) ++ns=1e5_wp;nn=0;j=0;tn=600;temp=600 ++call set_gridflag(2) ++do i=1,n ++ temp(i,1,1,:)=600+900._wp*(i-1)/(n-1) ++enddo ++old=temp(:,:,:,6) ++raw=midpoint_TRBDF23D(6,x,ns(:,:,:,6),old,nn,j,tn,1500._wp,1.25e-5_wp,inc) ++plain=midpoint_TRBDF23D(6,x,ns(:,:,:,6),old,nn,j,tn,1500._wp,1.25e-5_wp) ++if(any(raw/=plain))error stop 'optional midpoint diagnostics changed the state' ++if(midpoint_conduction_enabled) then ++ call energy_diffusion(1.25e-5_wp,x,ns,temp,j,nn,tn,2,1500._wp) ++ if(any(temp(:,:,:,6)/=max(raw,100._wp)))error stop 'standard production path differs from tested midpoint operator' ++endif ++! Inverted and standard zero-flux ion boundaries on constant temperature. ++do flag=1,2 ++ call set_gridflag(flag);old=600 ++ raw=midpoint_TRBDF23D(6,x,ns(:,:,:,6),old,nn,j,tn,-1e-6_wp,1.25e-5_wp,inc) ++ if(maxval(abs(raw(1:n,1,1)-600._wp))>1e-11_wp)error stop 'midpoint Neumann constant state changed' ++enddo ++deallocate(x%h1,x%h2,x%h3,x%dx1,x%dx1i) ++end subroutine wrapper_checks ++end program +diff --git a/test/qualification/pair_exchange_probe.f90 b/test/qualification/pair_exchange_probe.f90 +new file mode 100644 +index 00000000..b8af70c7 +--- /dev/null ++++ b/test/qualification/pair_exchange_probe.f90 +@@ -0,0 +1,80 @@ ++program pair_exchange_probe ++use phys_consts, only: wp,lsp,kB,ms,gammas ++use collisions, only: coulomb_colln ++use pair_exchange, only: shared_pair_coefficients,pair_exchange_rates,advance_pair_exchange ++implicit none(type,external) ++real(wp) :: ns(-1:3,-1:3,-1:3,lsp),Ts(-1:3,-1:3,-1:3,lsp),v(-1:3,-1:3,-1:3,lsp) ++real(wp) :: nu(1,1,1),nurev(1,1,1),phi(1,1,1),psi(1,1,1),phirev(1,1,1),psirev(1,1,1) ++real(wp) :: rhoa,rhob,Ca,Cb,fraction,drag,K,dt,rate,Ua,Ub,va(3),vb(3),va0(3),vb0(3) ++real(wp) :: Fa(3),Fb(3),Qa,Qb,drag0,K0,energy_residual,momentum_residual,thermal_residual,fa0(3),fb0(3),q0a,q0b ++integer :: a,b,drift,level,u,it,nt ++character(4096) :: filename ++call get_command_argument(1,filename) ++if(len_trim(filename)==0) error stop 'pair probe requires CSV path' ++open(newunit=u,file=trim(filename),status='replace') ++write(u,'(a)') 'a,b,level,dt,rhoa,rhob,Ca,Cb,fraction_a,drag,K,Ta0,Tb0,'// & ++ 'va0x,va0y,va0z,vb0x,vb0y,vb0z,vax,vay,vaz,vbx,vby,vbz,Ta,Tb,'// & ++ 'instantaneous_momentum,instantaneous_energy,instantaneous_thermal' ++do a=1,lsp-1 ++ do b=a+1,lsp ++ ns=0;Ts=900;v=0 ++ ns(:,:,:,a)=2e11_wp;ns(:,:,:,b)=8e10_wp ++ Ts(:,:,:,a)=600;Ts(:,:,:,b)=1800 ++ rhoa=2e11_wp*ms(a);rhob=8e10_wp*ms(b) ++ Ca=2e11_wp*kB/(gammas(a)-1);Cb=8e10_wp*kB/(gammas(b)-1) ++ fraction=ms(b)/(ms(a)+ms(b)) ++ do drift=0,1 ++ va0=real(drift,wp)*[1200._wp,300._wp,-600._wp] ++ vb0=real(drift,wp)*[-300._wp,-100._wp,200._wp] ++ v(:,:,:,a)=va0(1);v(:,:,:,b)=vb0(1) ++ call coulomb_colln(a,b,ns,Ts,v,nu,phi,psi) ++ call coulomb_colln(b,a,ns,Ts,v,nurev,phirev,psirev) ++ if(maxval(abs(phi-phirev))+maxval(abs(psi-psirev))>1e-13_wp) error stop 'pair response not symmetric' ++ call shared_pair_coefficients(ms(a),ms(b),2e11_wp,8e10_wp,nu(1,1,1),nurev(1,1,1), & ++ phi(1,1,1),psi(1,1,1),drag0,K0) ++ do level=0,8 ++ drag=drag0;K=K0 ++ if(level==6) K=2*drag*(1/rhoa+1/rhob)*Ca*(Cb/(Ca+Cb)) ++ if(level==7) K=0 ++ if(level==8) drag=0 ++ rate=max(drag*(1/rhoa+1/rhob),K*(1/Ca+1/Cb)) ++ select case(level) ++ case(0);dt=0 ++ case(1);dt=1e-12_wp/rate ++ case(2);dt=.01_wp/rate ++ case(3);dt=.2_wp/rate ++ case(4);dt=2._wp/rate ++ case(5);dt=50._wp/rate ++ case default;dt=.3_wp/rate ++ end select ++ call pair_exchange_rates(ms(a),ms(b),drag,K,600._wp,1800._wp,va0,vb0,Fa,Fb,Qa,Qb) ++ call pair_exchange_rates(ms(a),ms(b),drag,K,600._wp,1800._wp,[0._wp,0._wp,0._wp], & ++ [0._wp,0._wp,0._wp],fa0,fb0,q0a,q0b) ++ momentum_residual=maxval(abs(Fa+Fb))/max(maxval(abs(Fa)),tiny(1._wp)) ++ energy_residual=abs(Qa+Qb+sum(Fa*va0+Fb*vb0))/ & ++ max(abs(Qa)+abs(Qb)+sum(abs(Fa*va0)+abs(Fb*vb0)),tiny(1._wp)) ++ thermal_residual=abs(q0a+q0b)/max(abs(q0a)+abs(q0b),tiny(1._wp)) ++ va=va0;vb=vb0;Ua=Ca*600;Ub=Cb*1800 ++ call advance_pair_exchange(rhoa,rhob,Ca,Cb,fraction,drag,K,dt,va,vb,Ua,Ub) ++ if(dt==0) then ++ if(any(va/=va0).or.any(vb/=vb0).or.Ua/=Ca*600.or.Ub/=Cb*1800) error stop 'zero-step pair changed state' ++ endif ++ write(u,'(3(i0,","),*(es25.17,:,","))') a,b,10*drift+level,dt,rhoa,rhob,Ca,Cb,fraction,drag,K, & ++ 600._wp,1800._wp,va0,vb0,va,vb,Ua/Ca,Ub/Cb,momentum_residual,energy_residual,thermal_residual ++ enddo ++ enddo ++ enddo ++enddo ++! The original closed thermal-exchange fixture, now using one shared transfer. ++Ca=2e11_wp*kB/(5._wp/3-1);Cb=8e10_wp*kB/(5._wp/3-1);K=.2_wp*Ca ++do level=0,2 ++ nt=5*2**level;dt=1._wp/nt ++ Ua=Ca*300;Ub=Cb*1800;va=0;vb=0 ++ do it=1,nt ++ call advance_pair_exchange(1._wp,1._wp,Ca,Cb,.5_wp,0._wp,K,dt,va,vb,Ua,Ub) ++ enddo ++ write(u,'(3(i0,","),*(es25.17,:,","))') 0,0,level,1._wp,1._wp,1._wp,Ca,Cb,.5_wp,0._wp,K, & ++ 300._wp,1800._wp,[0._wp,0._wp,0._wp],[0._wp,0._wp,0._wp],va,vb,Ua/Ca,Ub/Cb,0._wp,0._wp,0._wp ++enddo ++close(u) ++end program pair_exchange_probe +diff --git a/test/qualification/physics_updates_protocol.json b/test/qualification/physics_updates_protocol.json +new file mode 100644 +index 00000000..e1e506c4 +--- /dev/null ++++ b/test/qualification/physics_updates_protocol.json +@@ -0,0 +1,25 @@ ++{ ++ "schema": "gemini.physics.source.updates.1", ++ "declared_before_execution": true, ++ "base_candidate": "a15a0ccd5bba2fcad9b57997cf9c1330dd211de3", ++ "native_acceptance": "All nine original native references; all existing tolerances and archives unchanged. Any failed, skipped, or unexecuted required test is not a pass.", ++ "midpoint_diffusion": { ++ "scope": "standard energy_diffusion, solver 2 only; opt-in CMake switch; virtual BE half-step conductivity predictor", ++ "fixtures": "PC03 unchanged proper transient window, both densities; PC04 independent flux convergence", ++ "space_order_min": 1.8, ++ "time_order_min": 1.8, ++ "normalized_energy_balance_max": 1e-11, ++ "unchanged_boundary_absolute_max": 1e-11 ++ }, ++ "pair_exchange": { ++ "scope": "callable constant-rate closed pair operator, not wired into split application sources", ++ "rate_model_proposal": "one averaged reciprocal momentum coefficient, translational thermal power, species heat capacities, mass-fraction friction partition", ++ "rates_are_not_independently_validated": true, ++ "identity_fixtures": "All 21 species pairs at zero and finite drift", ++ "normalized_momentum_max": 1e-11, ++ "normalized_total_energy_max": 1e-11, ++ "independent_oracle": "SciPy Radau integration of both momenta and both internal energies, including time-varying friction power; tighter oracle control", ++ "relative_oracle_max": 1e-10 ++ }, ++ "non_claims": ["No full coupled spatial qualification inferred", "No full total-energy inventory inferred", "No outside approval required for law-based closure", "No outdated optional increments finding repeated"] ++} +diff --git a/test/qualification/temperature_floor.f90 b/test/qualification/temperature_floor.f90 +new file mode 100644 +index 00000000..fe55d300 +--- /dev/null ++++ b/test/qualification/temperature_floor.f90 +@@ -0,0 +1,39 @@ ++program temperature_floor ++use phys_consts, only: wp,lsp,kB,gammas ++use meshobj_cart, only: cartmesh ++use grid, only: set_total_grid_sizes,set_subgrid_sizes ++use multifluid, only: rhoe2T,T2rhoe ++use transport_audit, only: audit_transport_init,audit_step,audit_mass_start,audit_mass_finish ++implicit none(type,external) ++type(cartmesh) :: x ++real(wp) :: ns(-1:4,-1:4,-1:4,lsp),rhoe(-1:4,-1:4,-1:4,lsp),Ts(-1:4,-1:4,-1:4,lsp) ++real(wp) :: expected ++integer :: s,unit ++character(4096) :: directory ++call get_command_argument(1,directory) ++call set_total_grid_sizes(2,2,2);call set_subgrid_sizes(2,2) ++x%lx1=2;x%lx2=2;x%lx3=2 ++allocate(x%h1(-1:4,-1:4,-1:4),x%h2(-1:4,-1:4,-1:4),x%h3(-1:4,-1:4,-1:4)) ++allocate(x%dx1i(2),x%dx2i(2),x%dx3i(2),x%nullpts(2,2,2),x%inull(1,3)) ++x%h1=1;x%h2=1;x%h3=1;x%dx1i=[1._wp,2._wp];x%dx2i=[3._wp,4._wp];x%dx3i=[5._wp,6._wp] ++x%nullpts=.false.;x%nullpts(2,2,2)=.true.;x%lnull=1;x%inull(1,:)=[2,2,2] ++ns=1e10_wp;ns(:,:,:,lsp)=6e10_wp ++do s=1,lsp ++ rhoe(:,:,:,s)=ns(:,:,:,s)*kB*50._wp/(gammas(s)-1) ++enddo ++call audit_transport_init(trim(directory),0) ++call audit_step(0._wp,1._wp) ++call audit_mass_start(ns,x) ++call rhoe2T(ns,rhoe,Ts) ++if(any(Ts/=100._wp)) error stop 'Temperature conversion floor not applied' ++call T2rhoe(ns,Ts,rhoe) ++do s=1,lsp ++ ! Total volume is 3*7*11 minus the 2*4*6 null-cell volume: 183. ++ expected=183._wp*ns(1,1,1,s)*kB*50._wp/(gammas(s)-1) ++ print '(I0,1X,ES24.16E3)',s,expected ++enddo ++call audit_mass_finish(ns) ++open(newunit=unit,file=trim(directory)//'/temperature.bin',access='stream',form='unformatted',status='replace') ++write(unit) Ts,rhoe ++close(unit) ++end program +diff --git a/test/qualification/test_clock_inventory.py b/test/qualification/test_clock_inventory.py +new file mode 100644 +index 00000000..dc1809fc +--- /dev/null ++++ b/test/qualification/test_clock_inventory.py +@@ -0,0 +1,36 @@ ++"""Joint evidence deletion must not turn unexecuted steps into passes.""" ++from pathlib import Path ++import sys,tempfile,unittest ++sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) ++from check_sources import check_clock_inventory ++ ++ ++class ClockInventory(unittest.TestCase): ++ def test_complete_run_and_float64_clock_roundoff(self): ++ with tempfile.TemporaryDirectory() as d: ++ p=Path(d);(p/'inputs').mkdir() ++ (p/'inputs/config.nml').write_text('&base\n tdur = 3D0, ! fixed duration\n/\n') ++ check_clock_inventory(p,{(0.,1.),(1.,1.),(2.,1.)}) ++ check_clock_inventory(p,{(0.,1.),(1.,1.),(2.+1e-15,1.)}) ++ ++ def test_missing_first_middle_and_final_steps(self): ++ with tempfile.TemporaryDirectory() as d: ++ p=Path(d);(p/'inputs').mkdir() ++ (p/'inputs/config.nml').write_text('tdur = 3\n') ++ for clocks,message in [({(1.,1.),(2.,1.)},'begin'), ++ ({(0.,1.),(2.,1.)},'Noncontiguous'), ++ ({(0.,1.),(1.,1.)},'duration')]: ++ with self.subTest(clocks=clocks),self.assertRaisesRegex(ValueError,message): ++ check_clock_inventory(p,clocks) ++ ++ def test_overlaps_nonadvancing_clocks_and_invalid_duration(self): ++ with tempfile.TemporaryDirectory() as d: ++ p=Path(d) ++ for clocks in [{(0.,2.),(1.,1.)},{(0.,0.)},{(-1.,1.)},{(0.,float('nan'))}]: ++ with self.subTest(clocks=clocks),self.assertRaises(ValueError):check_clock_inventory(p,clocks) ++ (p/'inputs').mkdir() ++ for value in ['nan','inf','0','-1','1,2','']: ++ (p/'inputs/config.nml').write_text('tdur = '+value+'\n') ++ with self.subTest(value=value),self.assertRaises(ValueError):check_clock_inventory(p,{(0.,1.)}) ++ ++if __name__=='__main__':unittest.main() +diff --git a/test/qualification/test_midpoint_diffusion.py b/test/qualification/test_midpoint_diffusion.py +new file mode 100644 +index 00000000..c2553d18 +--- /dev/null ++++ b/test/qualification/test_midpoint_diffusion.py +@@ -0,0 +1,35 @@ ++"""Run native operator, verify observed stages, then compare independent laws.""" ++import argparse ++import json ++from pathlib import Path ++import subprocess ++import sys ++import tempfile ++ ++p=argparse.ArgumentParser() ++p.add_argument('--source',type=Path,required=True) ++p.add_argument('--build',type=Path,required=True) ++p.add_argument('--work',type=Path,required=True) ++a=p.parse_args() ++# Keep each invocation isolated, including concurrent or repeated CTest calls. ++# No existing evidence or user directory is removed. ++a.work.mkdir(parents=True,exist_ok=True) ++invocation=Path(tempfile.mkdtemp(prefix='run-',dir=a.work)) ++native=invocation/'native';trace=invocation/'trace' ++scripts=a.source/'scripts/qualification' ++subprocess.run([sys.executable,str(scripts/'run_physics_native.py'),'--build',str(a.build), ++ '--source',str(a.source/'test/qualification/midpoint_diffusion_probe.f90'),'--work',str(native)],check=True) ++subprocess.run([sys.executable,str(scripts/'trace_diffusion_stages.py'), ++ '--source',str(a.source/'src/numerical/diffusion/PDEparabolic.f90'), ++ '--build',str(a.build),'--probe',str(native/'physics_native.o'),'--work',str(trace)],check=True) ++try: ++ revision=subprocess.check_output(['git','-C',str(a.source),'rev-parse','HEAD'],text=True).strip() ++except subprocess.CalledProcessError: ++ revision='source-export; see PACKAGE_PROVENANCE.json' ++subprocess.run([sys.executable,str(a.source/'test/qualification/analyze_midpoint_diffusion.py'), ++ '--work',str(native),'--trace',str(trace/'tr-stages.csv'),'--candidate',revision],check=True) ++result=json.loads((native/'physics-results.json').read_text()) ++a.work.joinpath('latest-result.json').write_text(json.dumps({'invocation':str(invocation), ++ 'result':result},indent=2)+'\n') ++assert result['passed'] and all(r['native_stage_trace_used'] and r['fixed_boundary_max_error_K']<=1e-11 ++ and r['floor_cell_events']==0 for r in result['PC03']['cases']) +diff --git a/test/qualification/test_pair_exchange.py b/test/qualification/test_pair_exchange.py +new file mode 100644 +index 00000000..244caf5d +--- /dev/null ++++ b/test/qualification/test_pair_exchange.py +@@ -0,0 +1,63 @@ ++"""Independent coupled ODE oracle; acceptance does not validate rate amplitudes.""" ++import argparse ++import csv ++import hashlib ++import json ++import subprocess ++from pathlib import Path ++ ++import numpy as np ++from scipy.integrate import solve_ivp ++ ++p = argparse.ArgumentParser() ++p.add_argument('--exe', type=Path, required=True) ++p.add_argument('--output', type=Path, required=True) ++a = p.parse_args() ++a.output.parent.mkdir(parents=True, exist_ok=True) ++csv_path = a.output.with_suffix('.csv') ++subprocess.run([str(a.exe), str(csv_path)], check=True) ++with csv_path.open() as f: ++ rows = [{k: float(v) for k, v in row.items()} for row in csv.DictReader(f)] ++assert len(rows) == 381 and all(np.isfinite(list(r.values())).all() for r in rows) ++results = [] ++for r in rows: ++ ca, cb, ra, rb, drag, k, dt, fraction = (r[x] for x in ++ ('Ca', 'Cb', 'rhoa', 'rhob', 'drag', 'K', 'dt', 'fraction_a')) ++ initial = np.array([r[x] for x in ('va0x','va0y','va0z','vb0x','vb0y','vb0z','Ta0','Tb0')]) ++ observed = np.array([r[x] for x in ('vax','vay','vaz','vbx','vby','vbz','Ta','Tb')]) ++ def rhs(t, y): ++ force = drag*(y[3:6]-y[:3]) ++ heat = drag*np.dot(y[:3]-y[3:6], y[:3]-y[3:6]) ++ transfer = k*(y[7]-y[6]) ++ return dt*np.r_[force/ra, -force/rb, ++ (transfer+fraction*heat)/ca, (-transfer+(1-fraction)*heat)/cb] ++ if dt: ++ oracle = solve_ivp(rhs, (0.,1.), initial, method='Radau', rtol=2e-12, atol=2e-11) ++ control = solve_ivp(rhs, (0.,1.), initial, method='Radau', rtol=2e-13, atol=2e-12) ++ assert oracle.success and control.success ++ expected = control.y[:,-1] ++ control_error = np.max(abs(oracle.y[:,-1]-expected)/np.maximum(abs(expected), 1.)) ++ else: ++ expected=initial;control_error=0. ++ # The native probe checks U and v bitwise at dt=0. CSV temperatures ++ # include a rounded U/Cv conversion even when the operator is a no-op. ++ error = np.max(abs(observed-expected)/np.maximum(abs(expected),1.)) ++ e0=ca*initial[6]+cb*initial[7]+ra*np.dot(initial[:3],initial[:3])/2+rb*np.dot(initial[3:6],initial[3:6])/2 ++ e1=ca*observed[6]+cb*observed[7]+ra*np.dot(observed[:3],observed[:3])/2+rb*np.dot(observed[3:6],observed[3:6])/2 ++ energy=abs(e1-e0)/abs(e0) ++ momentum=np.max(abs(ra*(observed[:3]-initial[:3])+rb*(observed[3:6]-initial[3:6])))/max( ++ ra*np.linalg.norm(initial[:3])+rb*np.linalg.norm(initial[3:6]),np.finfo(float).tiny) ++ identity=max(r[x] for x in ('instantaneous_momentum','instantaneous_energy','instantaneous_thermal')) ++ passed=error<=1e-10 and control_error<=1e-10 and energy<=1e-11 and momentum<=1e-11 and identity<=1e-11 ++ results.append({'species':[int(r['a']),int(r['b'])], 'level':int(r['level']), ++ 'oracle_relative_error':float(error), 'oracle_control_error':float(control_error), ++ 'energy_relative_error':float(energy), 'momentum_relative_error':float(momentum), ++ 'instantaneous_identity_error':float(identity), 'passed':bool(passed)}) ++result={'schema':'gemini.pair.exchange.validation.1', 'scope':'closed constant-rate pair operator; application source coupling unexecuted', ++ 'rate_magnitudes_independently_validated':False, 'case_count':len(results), ++ 'passed':all(r['passed'] for r in results), 'cases':results, ++ 'executable_sha256':hashlib.sha256(a.exe.read_bytes()).hexdigest(), ++ 'csv_sha256':hashlib.sha256(csv_path.read_bytes()).hexdigest()} ++a.output.write_text(json.dumps(result,indent=2)+'\n') ++print(json.dumps({k:v for k,v in result.items() if k!='cases'})) ++raise SystemExit(0 if result['passed'] else 1) +diff --git a/test/qualification/test_profile.py b/test/qualification/test_profile.py +index 4bb64907..1e79edd2 100644 +--- a/test/qualification/test_profile.py ++++ b/test/qualification/test_profile.py +@@ -110,6 +110,8 @@ class Profile(unittest.TestCase): + def write(): + with f.open('w') as h: + w=csv.DictWriter(h,fieldnames=fields);w.writeheader();w.writerows(rows) ++ (p/'continuity-r00000000.csv').write_text('t,dt\n'+ ++ ''.join(f'{t},{dt}\n' for t,dt in sorted({(r['t'],r['dt']) for r in rows}))) + write();self.assertTrue(check(p,layout=[1,1])['passed']) + # A complete first step must not hide a missing stage in a later step. + complete=[dict(r) for r in rows] +diff --git a/test/qualification/test_source_ledger.py b/test/qualification/test_source_ledger.py +index 14189c5e..9804c775 100644 +--- a/test/qualification/test_source_ledger.py ++++ b/test/qualification/test_source_ledger.py +@@ -15,7 +15,7 @@ class Sources(unittest.TestCase): + w=csv.DictWriter(f,cols);w.writeheader();w.writerows(data) + (p/'continuity-r00000000.csv').write_text('t,dt\n0,1\n1,1\n') + (p/'temperature-floor-r00000000.csv').write_text('t,dt,stage,species,energy_added_J\n'+ +- ''.join(f'{t},1,{stage},{s},0\n' for t in (0,1) for stage in (1,2) for s in range(1,8))) ++ ''.join(f'{t},1,{stage},{s},0\n' for t in (0,1) for stage in (1,2,3) for s in range(1,8))) + return p/'sources-r00000000.csv' + + def test_known_balance_corruption_and_per_step_coverage(self): +@@ -47,7 +47,7 @@ class Sources(unittest.TestCase): + result=check(p,4) + self.assertTrue(result['passed']) + self.assertEqual(result['rows'],2*4*len(EXPECTED)) +- self.assertEqual(result['temperature_floor_rows'],2*4*2*7) ++ self.assertEqual(result['temperature_floor_rows'],2*4*3*7) + last=p/'sources-r00000003.csv';original=last.read_text() + last.write_text(original.replace(',105,5,10,',',105,7,10,',1)) + self.assertFalse(check(p,4)['passed']) +diff --git a/test/qualification/test_temperature_floor.py b/test/qualification/test_temperature_floor.py +new file mode 100644 +index 00000000..2d5d80f2 +--- /dev/null ++++ b/test/qualification/test_temperature_floor.py +@@ -0,0 +1,22 @@ ++"""Measure the conversion floor against known physical volume and heat capacity.""" ++import argparse,csv,os ++from pathlib import Path ++import subprocess,tempfile ++ ++p=argparse.ArgumentParser();p.add_argument('--exe',type=Path,required=True);a=p.parse_args() ++with tempfile.TemporaryDirectory() as d: ++ p=Path(d);audited=p/'audited';plain=p/'plain';audited.mkdir();plain.mkdir() ++ outputs=[] ++ for directory,flag in [(audited,'1'),(plain,'0')]: ++ run=subprocess.run([str(a.exe),str(directory)],env=dict(os.environ,GEMINI_NUMERICAL_AUDIT=flag),capture_output=True,text=True) ++ assert run.returncode==0,run.stdout+run.stderr ++ outputs.append(run.stdout) ++ assert outputs[0]==outputs[1],'Diagnostics changed native oracle output' ++ assert (audited/'temperature.bin').read_bytes()==(plain/'temperature.bin').read_bytes(),'Diagnostics changed native state' ++ expected={int(line.split()[0]):float(line.split()[1]) for line in outputs[0].splitlines()} ++ with (audited/'temperature-floor-r00000000.csv').open() as f:rows=list(csv.DictReader(f)) ++ assert len(rows)==7 and {int(r['stage']) for r in rows}=={3},rows ++ reported={int(r['species']):float(r['energy_added_J']) for r in rows} ++ assert set(reported)==set(expected)==set(range(1,8)),rows ++ assert all(abs(reported[s]-e)<=1e-11*abs(e) for s,e in expected.items()),rows ++ print('PASS: seven species; 50-to-100 K conversion floor; 183 m3 physical volume; null/ghost exclusions; identical state with diagnostics enabled and disabled.') +diff --git a/test/qualification/test_transport_inventory.py b/test/qualification/test_transport_inventory.py +new file mode 100644 +index 00000000..d5efd6e1 +--- /dev/null ++++ b/test/qualification/test_transport_inventory.py +@@ -0,0 +1,45 @@ ++"""A complete surviving step cannot conceal missing numerical evidence.""" ++import csv ++from pathlib import Path ++import sys,tempfile,unittest ++sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) ++from check_transport import check ++ ++class TransportInventory(unittest.TestCase): ++ def fixture(self,directory): ++ fields='t,dt,quantity,species,axis,before,after,delta,outward,min_face,max_face,scale,residual,normalized_residual'.split(',') ++ records=[dict(zip(fields,[t,1,q,s,a,100,99,-1,1,0,1,100,0,0])) ++ for t in (0,1) for q in (1,2,3) ++ for s in range(1,8 if q==3 else 7) for a in (1,2,3)] ++ path=directory/'transport-r00000000.csv' ++ def save(rows): ++ with path.open('w') as stream: ++ writer=csv.DictWriter(stream,fields);writer.writeheader();writer.writerows(rows) ++ save(records) ++ (directory/'continuity-r00000000.csv').write_text('t,dt\n0,1\n1,1\n') ++ return records,save ++ ++ def test_entire_later_step_is_required(self): ++ with tempfile.TemporaryDirectory() as d: ++ directory=Path(d);records,save=self.fixture(directory) ++ self.assertTrue(check(directory,layout=[1,1])['passed']) ++ save([r for r in records if r['t']==0]) ++ with self.assertRaisesRegex(ValueError,'Transport/continuity'):check(directory,layout=[1,1]) ++ ++ def test_recorded_state_change_must_match_increment(self): ++ with tempfile.TemporaryDirectory() as d: ++ directory=Path(d);records,save=self.fixture(directory) ++ # The declared scale remains valid, and delta + outward still closes. ++ records[0]['after']=50;save(records) ++ self.assertFalse(check(directory,layout=[1,1])['passed']) ++ ++ def test_invalid_budgets_and_scales_are_rejected(self): ++ with tempfile.TemporaryDirectory() as d: ++ directory=Path(d);records,save=self.fixture(directory) ++ for budget in (0,-1,float('inf'),float('nan')): ++ with self.subTest(budget=budget),self.assertRaisesRegex(ValueError,'budget'): ++ check(directory,budget=budget,layout=[1,1]) ++ records[0]['scale']=1;save(records) ++ with self.assertRaisesRegex(ValueError,'scale'):check(directory,layout=[1,1]) ++ ++if __name__=='__main__':unittest.main() diff --git a/docs/DEPENDENCIES.md b/docs/DEPENDENCIES.md new file mode 100644 index 000000000..75c7ba3e6 --- /dev/null +++ b/docs/DEPENDENCIES.md @@ -0,0 +1,29 @@ +# Pinned dependencies and distribution scope + +`cmake/libraries.json` records source URLs, commit archives and SHA-256 values. `dependency-inventory.json` records observed license notices. `scripts/offline_libraries.cmake` verifies seven archives, including MUMPS 5.9.1 beneath the pinned MUMPS superbuild, and emits a source-cache initializer. A fresh Debug build was completed using these prepared sources with FetchContent downloads disabled. + +This is source dependency closure for the tested Linux profile. It does not package the compiler, MPI, system HDF5/BLAS/LAPACK/ScaLAPACK, Python environment, operating-system patches, or reference archives. Those versions must also be recorded for a release. It is not a complete software-bill-of-materials or a security-advisory clearance. + +| Component | Observed license/notice | Local build | +| --- | --- | --- | +| GEMINI | Apache-2.0 | Enabled | +| ffilesystem | MIT | Enabled | +| h5fortran | BSD-3-Clause | Enabled | +| MUMPS superbuild | MIT | Enabled | +| MUMPS upstream | CeCILL-C; bundled exceptions and PORD notices | Enabled | +| MSIS wrapper | Apache-2.0; retain underlying model notices | Enabled | +| HWM14 | Apache-2.0 | Separate unit/native-smoke profile; no pinned reference cases | +| GLOW | GLOW Open Source Academic Research License Agreement | Enabled | + +GLOW's bundled agreement limits the granted purposes and includes restrictions on sale/fee transfer and derivative-work conditions. Its terms differ from GEMINI's Apache-2.0 license. Preserve the agreement and review the intended distribution/use before a commercial product release. This is an observed dependency restriction, not an assertion that the whole combined package has one license. The exact agreement and MUMPS/PORD notices are retained in `dependency-notices/` for review. + +GitHub Actions are pinned to resolved commit hashes. The former `Vampire/setup-wsl@v7` reference did not resolve; it now uses the commit behind `v7.0.0`. Runner families are explicit. The new `preintegration.yml` runs Debug and Release with native reference tests enabled, and preserves diagnostics on failure. Hosted CI has not been executed from this local branch. Distribution-provided package updates still need normal release maintenance. + + +## Qualification continuation, 17 September 2026 + +The current-library profile builds HDF5 2.2.0 from the publisher's verified source archive with Fortran, HL and deflate enabled. `scripts/build_qualification_hdf5.cmake` reproduces that profile and rejects corrupt archives or reused build trees. The prior HDF5 1.10.10 profile is retained only as tested compatibility evidence. HDF5's notice is included in `dependency-notices/HDF5-2.2.0-LICENSE.txt`. + +`scripts/qualification/inventory.py` records actual CMake library paths/hashes, available package archive versions, Python distributions and model/input data. The issued package contains local inventories for both profiles. These are local-environment inventories, not a substitute for the target deployment inventory or dependency-license approval. The targeted advisory review is in [qualification research](qualification/RESEARCH.md). + +Hosted validation now includes Debug/Release native tests, current HDF5 and GNU sanitizer jobs with a separate standalone leak check. Local process-inspection restrictions prevent a successful LeakSanitizer run here. None of the hosted job definitions is represented as a remotely executed result. diff --git a/docs/PREINTEGRATION.md b/docs/PREINTEGRATION.md new file mode 100644 index 000000000..5cac46172 --- /dev/null +++ b/docs/PREINTEGRATION.md @@ -0,0 +1,238 @@ +# GEMINI branch handoff - 17 September 2026 + +## 22 September 2026 audit remediation + +This addendum supersedes the historical delivery/status statements below for +the new source-audit work. The starting revision was +`bc9d1a17ff89074586d7f6064b21ceab638dbbb3`. A file inventory is not an exhaustive +code review or scientific certification. + +The implementation plan now includes a local installation stage: provision +native prerequisites explicitly, create an isolated Python/build/install tree, +test before declaring installation successful, and check the recorded +environment before model execution. See +[local installation](Readme_prereqs.md#verified-local-environment). +Debian/Ubuntu and macOS use the shell entry point; Windows uses Ubuntu WSL through +the PowerShell entry point. Native Windows and additional Linux distributions +are not automatically provisioned by these scripts. + +Implemented components: + +- A1–A3: valid Cartesian coordinate lifetimes, completed MPI corner receives, + corrected magnetic boundary integration and boundary-current cleanup. +- A4–A7: guarded neutral extrapolation and current-background winds, + nondestructive launching, explicit diffusion solver errors, and a 10 ms + minimum cadence for legacy timestamped files. +- A8–A10: owned input-data/grid teardown, restored neutral C API entry points + and explicit interoperable integer kinds, valid odd/small-grid MPI selection. +- A11–A13: required qualification dependencies, hosted qualification definitions, + and strict conservative-remapping validity masks. +- Exact-restart schema 2 binds sidecars to rank, layout, root/generation, inputs + and executable, and rejects nonfinite state. This intentionally rejects old + schema-1 exact-state checkpoints; it is not cryptographic payload authentication + or a new power-loss durability guarantee. +- Targeted CTest regressions, source/dependency inventories, installation + records, and existing scientific/optional-mode guards are retained. + +Validation and remaining acceptance: + +- The local isolated Python packages installed successfully; dependency checks + and nine installer orchestration regressions passed. The standard full native + installer stopped when `mumps-solver.org` could not resolve for the pinned + MUMPS 5.9.1 archive. No successful installation record was emitted. +- Eleven isolated GNU numerical/runtime checks passed, including one-, two- and + four-rank MPI and diffusion convergence; restoring the original defects caused + their targeted regressions to fail. These are not full native reference runs. +- Thirty-four qualification/dependency/mask tests passed. Workflow syntax and + shell checks are definition validation, not hosted execution evidence. +- Additional **diagnostic, non-qualifying** builds exercised 11 contract tests + (40,248 native/CMake partition cases, 45 cadence cases, 16 launcher cases, + neutral ABI behavior and public-symbol linking), and 72 synthetic restart + checks on two/four ranks, including 62 expected corruption rejections. + The contract build used system MUMPS 5.6.2; restart/lifecycle builds used a + version-5.9.1 mirror not verified against the pinned archive. These results + must be repeated with approved source provenance. +- Lifecycle diagnostics passed 23 Debug checks and 18 ASan/UBSan/leak checks, + including 800 input-object states and 40 meshes, with optional physical models + disabled. Review identified an additional temperature-placeholder regression; + the correction admits zero-filled cells only until extrapolation/filling and + validates the resulting temperatures. Four zero-placeholder follow-up cases + (ascending, descending, closed and below-ground) passed with floating-point traps. +- LeakSanitizer accepted the clean control and detected the intentional + 1237-byte leak. Actual full-application leak qualification remains separate. + Kernel-memory measurement was blocked by unavailable cgroup delegation. +- Complete pinned builds, all nine original reference cases, final-candidate + restart/numerical-accounting campaigns, hosted Debug/Release/current-HDF5/ + sanitizer jobs, macOS/WSL/Intel execution, and target-host performance remain + required before release acceptance. +- The first pushed candidate's hosted runs returned `action_required`, with no + jobs or failure logs; maintainers must approve workflow execution. This is not + a passing or failing test result. + Separate local-installation smoke jobs exercise the installer and subsequent + runtime preflight on Ubuntu, macOS and Windows WSL; their execution is also + required before claiming those installation paths verified. +- Automated combined review/security validation timed out. Do not interpret + that as a clean security result; complete it on a capable CI host. +- Independent physical review, current-epoch geometry, full coupled conservation + and refinement, optional-mode reference evidence, and target-specific + dependency/license/advisory approval remain open in the + [qualification register](qualification/REMAINING_WORK.md). + +Reference archives, hashes and comparison tolerances were not relaxed. No +software-only result closes the independent scientific gates. + +### Follow-up installation and acceptance verification + +The follow-up started from `0c759dacdba497a74cad50fedc811123c8a42e4a`; +the results below supersede assumptions that the installation or hosted +qualification had already completed: + +- Exercised the actual Linux `install-local.sh --system-deps` entry point on + Ubuntu 24.04. Native prerequisites and all five pinned local Python packages + installed, and `pip check` passed. Configuration detected GNU 13.3, OpenMPI and + HDF5 1.10.10, but the approved MUMPS 5.9.1 URL still failed DNS resolution. + The installer exited unsuccessfully, emitted no success record, and both + `check` and `run` refused this incomplete environment. No replacement archive + or weakened provenance check was used. +- The PowerShell installer now forwards local-root, jobs, Debug/Release, + reference-test and offline-source-cache options. Its orchestration regression + checks argument boundaries with spaces, invalid options, and a failed WSL + installation. All ten local-environment tests passed on Linux with PowerShell. + This is wrapper validation, not a successful installation inside Windows WSL. +- The Windows smoke workflow now invokes the actual PowerShell entry point. + macOS and Windows end-to-end execution remain pending on their target hosts. +- Fixed the remaining unquoted manual-grid/start/end-time values in the native + launcher and expanded its preservation/argument regression from 16 to 36 + cases. Running that regression remains blocked on the native build. The + existing native and CMake partition probes passed 34,848 and 5,400 cases, + respectively; review of the other A1–A10/restart corrections found no further + high-confidence defects in this pass. +- Preintegration now explicitly uses Bash with pipeline failure propagation, + so a failed build or test cannot be hidden by successful log capture. + Hosted evidence also requires Debug restart/numerical-budget execution, not + just Release. Fifty-four tests passed across fourteen standalone Python + qualification modules, including all eight hosted-evidence tests, with no + skips. These are component/contract checks, not native simulation evidence. +- Recorded an inventory of 355 source files and a partial native dependency/ + toolchain inventory. Hash inventories identify the reviewed source but are + not exhaustive line coverage, complete build output, or scientific approval. +- Hosted installation and preintegration runs for the starting candidate reported + `action_required`; the installation run had zero jobs and no failure logs. + Maintainer approval is needed before these can supply execution evidence. +- LeakSanitizer again accepted the clean control and detected the intentional + 1237-byte leak. The delegated-cgroup probe was blocked by permissions. + Neither control substitutes for full-application leak or performance results. +- The advisory lookup found no reported vulnerabilities for the five pinned + local Python requirements. Native/transitive and target-distribution advisory + and license approval remain open. + +Release acceptance is therefore still blocked on an approved, reachable MUMPS +archive/cache, complete native reference/restart/accounting and sanitizer runs, +approved hosted platform execution, and the independent scientific gates above. + +### Release decision boundary + +The next continuation starts from +`2e050c50d5a3d33920926ecf24831afa77c53b76`. The approved MUMPS archive still +fails DNS resolution. The exact-candidate +[preintegration run](https://github.com/CatalystNexusLLC/gemini3d/actions/runs/35771770031) +and [installation run](https://github.com/CatalystNexusLLC/gemini3d/actions/runs/35771769791) +are `action_required`; the preintegration log query reports zero jobs, not +failed tests. Repeating these blocked attempts cannot establish qualification. + +Additional engineering checks and corrections in this continuation: + +- The optional four-rank matrix was rejected by the source and energy ledger + checkers even when its simulations succeeded. Both now admit the existing + 2×2 regression without changing the frozen scientific profile. Seven ledger + tests pass, including two new tests that failed before the correction; + missing/extra ranks, missing stages/clocks/floors and corrupted balances still + reject the evidence. +- The restart matrix now rewrites exactly one duration assignment, including + indented assignments, validates positive finite values, and requires the + continuation duration to increase. Continuations must preserve seed frames + and produce a later checkpoint. The original indentation bug prevented the + intended split; a successful native no-op restart was not demonstrated + (the native solver already rejects final-time restarts). Seven profile tests + pass, including malformed/duplicate duration rejection and Fortran `D`/`d` + exponent handling; the related 23-test component suite also passed before + the exponent-only follow-up. +- Ten installer regressions and fifty-four existing standalone qualification + tests passed before these focused changes. Dependency pins, scientific budgets, + reference data and comparison tolerances are unchanged by the matrix fixes. +- CodeQL completed for Actions, Python and C/C++ with zero alerts. This does + not cover Fortran physics correctness. The combined tool's automated review + component reported an unavailable model despite its success heading, so it + is not counted as a completed review. A separate read-only reviewer found no + further high-confidence issues in the prior follow-up diff or four-rank fix. +- LeakSanitizer controls passed again; delegated memory accounting is still + denied. The pinned Python advisory lookup returned no reported vulnerabilities, + which is not target-distribution approval. + +The remaining decisions and required evidence are: + +| Owner | Required action or decision | Closure evidence | +| --- | --- | --- | +| Dependency/release maintainer | Restore access to the approved MUMPS archive or supply the existing offline installer with the archive matching `cmake/libraries.json`. Any different source/version requires a reviewed dependency decision. | Successful pinned installation, all nine unchanged native references, launcher regressions, restart/accounting matrix and application sanitizer results. | +| Repository maintainer | Approve the waiting workflows for the final candidate; do not count an agent-task success as a model test. | Successful Debug/Release/current-HDF5/sanitizer and Linux/macOS/WSL/Intel runs, with their exact-commit evidence artifacts. | +| HPC/runtime administrator | Provide a host with delegated cgroup v2 memory accounting and the declared runtime/toolchain. | Three complete workloads meet the existing memory/latency budgets; actual application leak checks pass alongside the controls. | +| Numerical maintainer and independent plasma physicist | Review the floor/ETD changes and agree a physically complete source/work/flux ledger and coupled refinement cases. Supply independent matched reference observations/models. | R01/R04/R07 approvals and results meeting unchanged acceptance budgets; aggregate component ledgers alone are insufficient. | +| Geomagnetic/grid specialist | Choose and review a consistent field, basis, metrics and driver formulation for the proposed current-epoch domain. | R03 domain-wide independent validation; retain the production epoch guard until then. | +| Optional-mode and distribution owners | Approve supported mode/platform combinations and actual target dependency/data licenses, advisories and deployment isolation. | R09/R17 inventory and independent optional-mode references, including HWM14 where proposed. | + +Corpus training, calibrated assimilation, uncertainty claims and physical +coupling remain downstream of these decisions (R10–R13/R16/R18); no synthetic +fixture or generated approval can close them. Physical control remains excluded. +The status is **blocked pending release qualification and specialist decisions**, +not release-qualified. No archive hash, scientific budget, reference tolerance +or safety guard is relaxed to turn a blocked gate into a pass. + +### Delegated engineering decisions and execution receipts + +The continuation from `01bbfeab3df39107a67554f1b45bd409856c4d09` accepts +delegated approval for engineering decisions. Additional permission to execute +the existing qualification workflows is no longer requested. Approval to do the +work is not independent physical evidence, target-platform execution, or a +successful release result. + +- Retain the approved dependency pins, nine reference cases, acceptance budgets + and frozen one/two-rank scientific scope. Exercise the already supported + four-rank regression in both hosted native Debug and Release jobs, without + admitting additional scientific modes. Eight workflow/evidence contract tests + passed. +- Installation now verifies fresh CTest JUnit results against the selected test + inventory. All four library checks are mandatory; reference installation also + requires all nine comparisons. Explicitly disabled optional tests are recorded + separately; runtime skips, missing/duplicate cases and failed results cannot + publish a successful installation. Hashed JUnit reports are retained in all + installation-smoke artifacts. Fourteen installer regressions passed, including + real CTest pass/disabled/skipped/failure controls and successful default and + reference receipt orchestration. These controls are not native model results. +- Requested an ordinary rerun of + [preintegration run 35774340798, attempt 2](https://github.com/CatalystNexusLLC/gemini3d/actions/runs/35774340798). + It progressed beyond the previous approval block and built both native + Debug/Release profiles and the verified current HDF5 library. Its remaining + tests were still executing when this update was recorded. This run identifies + the starting commit, not the later execution-receipt changes. +- Local access to the pinned MUMPS host still fails DNS resolution; no archive + substitution was made. A separate read-only review found no significant + issues in the execution-receipt changes. + +Remaining obligations are **measured release qualification**, not a request to +repeat engineering approval: final-candidate hosted/platform/sanitizer results, +delegated-host memory/performance measurements, actual target dependency/data +review, and independent scientific benchmarks and complete coupled accounting. +The production epoch guard and physical-control exclusion remain in force. +No downstream scientific gate is closed by delegation alone. + +## Historical handoff + +Branch `fix/preintegration-validation-2026-09-16` now merges upstream `9320b8912343ebd9bfb10a68c1e987f2278ff147` and retains the earlier remediation commit `ec5a1382a69e616e698aa36538958d38eb423e2d`. The delivered verification manifest identifies the final candidate commit, tree, test results, artifact hashes and any environment-limited checks. + +The new [qualification profile](qualification/README.md) is the authoritative continuation guide. It covers strict driver coverage, timestamp preflight, precision-preserving core restarts, the frozen-background restart correction, curved-gradient and diffusion checks, capacitance-mode validation, an IGRF-14 oracle, GNU sanitizers, a C17 consumer, HDF5 2.2.0 and actual environment inventories. The nine pinned reference cases, archive hashes and comparison tolerances are retained. All seven saved species remain mandatory in full-output comparisons. + +The [remaining-work register](qualification/REMAINING_WORK.md) retains all 18 gates with completed work and specific closure requirements. A [provisional model card](qualification/MODEL_CARD.md) makes the missing application decisions concrete. [Primary sources](qualification/RESEARCH.md) explain the current dependency and scientific evidence choices. + +This is a branch-review handoff. Full scientific qualification and parallel-model integration are not approved by local software tests. Hosted CI, independent physical benchmarks, current-epoch production geometry, full-system source/flux budgets and complete-state restart acceptance, platform/target qualification and distribution approval remain explicit. HWM14 and optional-mode smoke results are not promoted to independently reviewed reference truth. + +To review the supplied bundle, clone its named branch and inspect the two-parent merge and changes against `origin/main` at the pinned upstream commit. The package includes a patch against that upstream base, source snapshot, dependency/reference archives, notices, evidence and commands. No remote push has been performed. diff --git a/docs/PR_DESCRIPTION.md b/docs/PR_DESCRIPTION.md new file mode 100644 index 000000000..f18b785ac --- /dev/null +++ b/docs/PR_DESCRIPTION.md @@ -0,0 +1,7 @@ +GEMINI's qualification candidate still had gaps in input coverage, restart precision/state, optional-mode enforcement and current-dependency verification. A newly merged upstream background-initialization change also made frozen-neutral restart trajectories depend on the restart time. + +This continuation merges upstream main at 9320b891 and retains the configured density-floor correction. It rejects uncovered or invalid forcing by default, adds stream preflight, stores float64 core restart fields and full potential, validates checkpoint schema and actual precision, and preserves the configured epoch for frozen backgrounds. It corrects a curved-gradient boundary metric index and adds midpoint diffusion boundary data. Capacitance is restricted to the implemented 3D Cartesian field-integrated gradient-boundary formulation, preventing nonfinite-current failures in unsupported combinations. + +Qualification now includes manufactured convergence/source-boundary checks, explicit physical-volume budget tools, an independently implemented IGRF-14 oracle compared with official code, C17 and C++ consumer checks, GNU sanitizers, optional-mode smoke experiments, a verified HDF5 2.2.0 build profile, inventories and additional hosted CI jobs. An isolated native-test output root supports repeatable tests in synchronized workspaces. Reference data and tolerances are unchanged. + +See the accompanying verification manifest for exact local results and candidate identity. Hosted jobs have not run remotely. The 18-gate register explicitly retains application decisions, complete conservation and restart-state work, independent physics and optional-mode benchmarks, target-platform/security/license approval and later integration work. No IGRF-14 production-grid, operational, surrogate, control or coupled-model qualification is asserted. diff --git a/docs/Readme_audit.md b/docs/Readme_audit.md new file mode 100644 index 000000000..f75049ed9 --- /dev/null +++ b/docs/Readme_audit.md @@ -0,0 +1,47 @@ +# GEMINI pre-integration development profile + +This branch merges upstream `9320b8912343ebd9bfb10a68c1e987f2278ff147`, fetched on 16 September 2026. It is a review candidate. The required native reference gate passes locally after correction of the configured density floor. See [the remediation handoff](PREINTEGRATION.md) for the remaining work. + +## Behavior and compatibility + +- Recompile C/C++ callers: boolean flags at the C boundary use `int`, including the `get_config_vars_C` output. Null configuration/work/grid deallocation is idempotent. `c_params.fortran_nml=0` is rejected because that structure cannot describe a complete GEMINI configuration. +- The tested working precision is real64; other precision settings are rejected. Normal analysis fields remain float32. The new `/restart_core` record preserves float64 plasma fields and full 3D potential; mode-specific auxiliary state is not certified complete. +- The configured `mindens_userval` now controls the physical ion-density floor. A hidden universal 1,000 m^-3 ESF floor introduced upstream on 13 August 2026 is removed. Cases requiring that stabilization must explicitly set `mindens_userval=1e3`; this is a numerical behavior change that needs case-owner review. Null-cell and division floors remain distinct. +- All seven species participate in input/output finite checks and temperature checks. Spatial ghost cells are excluded. Finite nonnegative low-density partitions are accepted; a per-worker maximum-density threshold incorrectly rejected underground restart partitions. +- Required calendar dates, fields, finite values, modes and positive driver cadences are checked. Optional namelist defaults are reset on each read. Deprecated INI input is outside this qualification. +- Calendar search now handles month/year/leap boundaries without an unbounded stepping loop. Driver priming uses elapsed seconds across midnight, and updates catch up over multiple data cadences before interpolation. +- Time steps stop at output/final times and enabled file-driver knots. The existing initialization microstep is capped at one microsecond and never raises a smaller stability-limited step. A global post-electrodynamics CFL check aborts before fluid advancement if the updated state is unstable. Automatic retry/rollback is not implemented. +- Longitude normalization accepts equivalent negative/positive angles; inverse trigonometric arguments are clamped against roundoff; 3D-to-2D coordinate calls reset their dimension state. +- The year-dependent magnetic pole table still covers 1920-2025 only. The guard rejects newer epochs. Legacy fixed-pole mode is still available, but this branch does not implement or qualify IGRF-14 geometry. +- `potsolve=2` is rejected as unimplemented. Modes 0, 1 and 3 have different scientific contracts. Restart discovery rejects legacy mode-3 files with slab-only potential; the new core record carries full 3D potential. +- Restart discovery requires density, parallel velocity, temperature, potential and date/time datasets, and checks `/time/ymd` and `/time/UThour` against the filename. This detects common incomplete/corrupt checkpoints, but does not establish complete-state or bitwise restart equivalence. +- One-point `interp1` axes are invariant dimensions. Driver objects now reject uncovered target sites by default. Explicit opt-in allows warned zero fill with in-memory masks; application-specific handling and pole singularities still need qualification. +- The GLOW data path separator is corrected. MSIS2 still requires its parameter file in the working directory; use the launcher or run from the build/install directory with the supplied data. +- CMake now verifies hashes for pinned dependency archives and offers `scripts/offline_libraries.cmake` to prepare source dependencies, including nested MUMPS. System libraries/toolchains and test-data caches remain separate prerequisites. + +## Tested local profile + +Linux x86-64; GNU Fortran 13.2; GCC/G++ 13.3; OpenMPI 4.1.6; HDF5 1.10.10 compatibility and 2.2.0 current-library profiles; CMake 3.31.10; Ninja 1.13; real64; GLOW and MSIS2 enabled; HWM14 disabled in the pinned nine-case reference profile, with separate HWM14 unit and smoke checks. Debug adds Fortran bounds/runtime checks. This records the tested environment, not a claim that these are the latest distribution package versions. + +The sandbox required OpenMPI `pml=ob1`, `btl=self,vader`, and `btl_vader_single_copy_mechanism=none`. These are local transport settings, not required production defaults. Multi-node communication is untested. + +## Build and verification + +Install compiler, MPI, HDF5, BLAS, LAPACK and ScaLAPACK prerequisites. Python native probes use the standard library; optional output analysis needs numpy/h5py/matplotlib. + +```sh +cmake -Doffline_dir=/absolute/dependency-cache -P scripts/offline_libraries.cmake +cmake -S . -B build -G Ninja -C /absolute/dependency-cache/sources.cmake \ + -DCMAKE_BUILD_TYPE=Release -Dgemini3d_realbits=64 -DMPIEXEC_MAX_NUMPROCS=2 +cmake --build build --parallel 2 +ctest --test-dir build --output-on-failure --output-junit native-results.xml +``` + +The source preparation step requires network unless all seven verified archives are supplied in `-Darchive_dir=/absolute/archives`. Configuration then uses prepared source overrides with `FETCHCONTENT_FULLY_DISCONNECTED=ON`. Run CTest once with network to populate reference data, or provide its verified cache and set `GEMINI3D_OFFLINE=1`. A complete release run must keep `gemini3d_test_simulations=ON`; unit-only runs do not satisfy that gate. Do not relax tolerances or replace references with current output merely to pass. + +## Saved state + +Species: O+, NO+, N2+, O2+, N+, H+, e-. HDF5 field order: `(species,x3,x2,x1)`. `Phiall` is a boundary slab; perpendicular velocity outputs are weighted averages. Coordinates, basis, units, masks and epoch require explicit interpretation before downstream use. This branch contains no CVTWIN or coupling changes. + + +See [the qualification continuation](qualification/README.md) for all new corrections, reproduction commands, the IGRF-14 oracle, optional-mode limits, instrumentation and remaining gates. diff --git a/docs/Readme_cmake.md b/docs/Readme_cmake.md index 038674f2d..f38abd2e8 100644 --- a/docs/Readme_cmake.md +++ b/docs/Readme_cmake.md @@ -1,5 +1,9 @@ # CMake options +CMake 3.26 or newer is required. For Ninja builds, use CMake 3.28 or newer +to avoid known Fortran module dependency bugs; use Unix Makefiles with older +supported CMake versions. + Note: a common convention is to compile (build) project in the "build/" directory. That is, the Gemini.bin executable and other libraries and test executables will be created under gemini3d/build. Feel free to use any directory name you like. diff --git a/docs/Readme_input.md b/docs/Readme_input.md index fbd41fcba..d9530ba7a 100644 --- a/docs/Readme_input.md +++ b/docs/Readme_input.md @@ -1,3 +1,4 @@ + # GEMINI Input In addition to command line options (see main README), GEMINI requires input file information to specify: @@ -33,13 +34,13 @@ UTsec0 = 18000.0 ! UTsec0: start time in UT seconds tdur = 300.0 ! tdur: duration of simulation in seconds dtout = 60.0 ! dtout: how often to do file output activ = 108.9, 111.0, 5 ! activ: f107a,f107,Ap -tcfl = 0.9 ! tcfl: target cfl number +tcfl = 0.5 ! conservative starting value; certify post-driver CFL for your case Teinf = 1500.0 ! Teinf: exospheric electron temperature / ! Flags controlling various aspects of solve and output behavior &flags -potsolve = 1 ! solve electrodynamics: 0 - no; 1 - electrostatic; 2 - inductive +potsolve = 1 ! solve electrodynamics: 0 - disturbance solve off; 1 - field-integrated electrostatic; 3 - field-resolved electrostatic; 2 - unsupported flagperiodic = 0 ! whether to consider the x3 dimension periodic: 0 - no; nonzero - yes; 1 - yes and force periodicity in glat/glon across x3 (good for instability simulations needed a uniform background neutral atmosphere and SZA) flagoutput = 1 ! what information to put in output files: 1 - all state variables; 2 - averaged plasma parameters; 3 - electron density only / @@ -98,14 +99,12 @@ msis_version = 0 ! 0 or 21; which MSIS version to use, MSIS00 or MSIS 2. ! (optional - default off) Include disturbance precipitation based on file inputs &precip -flagprecfile = 1 ! use precipitaiton file input: 0 - no; 1 - yes dtprec = 5.0 ! time step between precipitation file inputs prec_dir = 'test_data/test3d_glow/inputs/prec_inputs/' / ! (optional - default off) Include electric field boundary condition inputs from a file &efield -flagE0file = 1 ! use electric field boundary condition file input: 0 - no; 1 - yes dtE0 = 1.0 ! time step between electric field file inputs E0_dir = 'test_data/test3d_glow/inputs/Efield_inputs/' / @@ -131,7 +130,6 @@ W0_char = 3000 ! thermal energy in eV for diff_num_flux = 3. E0, W0 ! (optional - default off) Use glow to compute impact ionization, Cartesian grids only &glow -flagglow = 1 ! use glow? 0 - no; 1 - yes dtglow = 5.0 ! how often to recall GLOW to compute ionization dtglowout = 60.0 ! ow often to do Glow file output / @@ -143,7 +141,7 @@ W0BG=3e3 ! characteristic energy (eV) / ! (optional - default off) Leading order electrodynamics -%capacitance +&capacitance flagcap = 2 ! whether to use ionospheric capacitance in the solves: 0 - no; 1 - ionospheric part; 2 - ionospheric+magnetospheric parts magcap = 30.0 ! magnetospheric capacitance (Farads) / @@ -187,6 +185,7 @@ flagdiamagnetic=.true. ! whether or not to compute pressure terms in perp ! (optional - off by default) &twoway_coupled flagtwoway=.true. ! whether or not to compute momentum and energy rates back to neutrals +/ ! (optional - off by default) assume background current divergence free? &nodivJ0 @@ -235,9 +234,9 @@ flagJ1ve=.true. ! use parallel current density in calculation of parallel / ! Set fill and min values for densities -! (optional - defaults to reasonable values for most applications) +! (optional - values must be selected and validated for the simulation regime) &mindens_user - mindens_userval=1.0e-100 + mindens_userval=1.0e-100 ! physical ion floor; use 1.0e3 explicitly for ESF stabilization mindensnull_userval=1.0e-20 mindensdiv_userval=1.0e-5 / diff --git a/docs/Readme_prereqs.md b/docs/Readme_prereqs.md index 9f2cd8037..798a8f584 100644 --- a/docs/Readme_prereqs.md +++ b/docs/Readme_prereqs.md @@ -2,6 +2,75 @@ As indicated in the main readme there are a number of prerequisites for GEMINI. This readme covers some details of how to install these on various platforms. We focus here on ease of use and describe the "least effort" methods for getting needed software. +## Verified local environment + +The repository provides `scripts/install-local.sh` for Debian/Ubuntu, macOS and +Ubuntu inside Windows WSL. Run it from any directory using its absolute path. +Pass `--system-deps` to explicitly authorize native package installation with +APT or Homebrew. Without that flag it uses your existing system/HPC toolchain. +Other Linux distributions require equivalent native packages installed manually. + +The installer creates an isolated Python environment, build tree and installation +under `build/local/` (override with `--root /absolute/path`). It installs the pinned +packages in `scripts/requirements-local.txt`, resolves the existing hash-pinned +native dependencies through CMake, builds the model, runs the standalone native +HDF5/MPI/MUMPS checks and unit tests, installs it, and checks the installed executable. Nothing is +installed into the system Python. A failed step returns a nonzero status and +leaves no successful `environment.json` record. + +Python 3.11 or newer is required. On macOS, install Xcode command-line tools and +Homebrew first; `--system-deps` supplies Python 3.12 and the native libraries. +On Debian/Ubuntu, the distribution must supply Python 3.11+ (for example Debian 12 +or Ubuntu 24.04); an older system Python must be upgraded explicitly. +`PYTHON=/absolute/path/to/python3` selects the bootstrap interpreter. +For Windows, `scripts/install-local.ps1 -SystemDeps` invokes the same installer +in the installed Ubuntu WSL distribution; `-Distribution` selects another WSL +distribution. It does not provision WSL or claim native Windows qualification. +The PowerShell entry point accepts `-Root`, `-Jobs`, `-BuildType Debug`, +`-ReferenceTests` and `-SourceCache` as equivalents of the shell options below. +`-Root` and `-SourceCache` are paths inside the selected WSL distribution, not +Windows drive paths. The Windows installation workflow invokes this PowerShell +entry point rather than bypassing it. + +`--build-type Debug` enables the existing Debug checks. `--jobs` limits build/test +parallelism. Add `--reference-tests` to run **all enabled registered tests**, +including reference downloads and simulations. All four standalone library +checks and all nine pinned native comparisons must be registered, enabled and +pass in that mode; the default unit-only installation is +**not** release or scientific qualification. Initial setup needs network access. +HPC/offline users should follow the existing offline dependency/reference-cache +instructions and provide their own compatible MPI/compiler environment. +`--source-cache /absolute/cache/sources.cmake` uses the hash-verified native +source cache produced by `scripts/offline_libraries.cmake`. Python wheels must +also be available to pip (for example through an administrator-provisioned local +index); this flag alone does not make an installation fully offline. + +The successful `build/local/environment.json` records the source revision and +dirty status, per-file source hashes, native dependency pins/configuration, +Python packages, test inventory, verification scope and executable hash. +Its `test_results` distinguishes selected, explicitly disabled and actually +passed tests for each suite. The installer compares CTest's selected inventory +with fresh JUnit results before installing or publishing a success record; +runtime-skipped, missing, failed or stale results cannot count as passes. +Disabled optional tests are listed, not silently counted as tested. The hashed +reports are `build/local/build/local-*.xml` (under the chosen local root), and +installation CI retains them alongside the receipt. This proves CTest execution, +not independent physical acceptance or the absence of skips internal to a test. +Inventory is not a claim that every file or scientific mode has been reviewed. +Enabled MSIS2/HWM14 parameter files are also required and hashed in the installed +resource directory, and their hashes are checked before running. + +Use `python3 /absolute/path/to/scripts/local_environment.py check` to recheck an +installation, or `run --case /absolute/path/to/case --ranks 2` to launch it. +Pass native solver options after `--`, such as `-- -dryrun`. The runner checks the +recorded executable, Python package environment and MPI availability first; it +does not clean simulation output, download dependencies, or request privileges. +Missing or changed dependencies require an explicit installer rerun. Use the +same `--root` for installation, checks and runs. Direct native executable launches +remain supported but do not invoke this Python environment check. +The runner uses the MPI launcher selected by CMake and rejects a changed launcher +or dynamic-library/MPI-module environment rather than mixing MPI implementations. + ## Working with MacOS You will need to install XCode through the app store. diff --git a/docs/Readme_references.md b/docs/Readme_references.md index 308d3bb11..95797459a 100644 --- a/docs/Readme_references.md +++ b/docs/Readme_references.md @@ -54,3 +54,8 @@ Gutow, J. (2020). Relating Flows and Currents in Auroral Arcs. Undergraduate H ## Other references + + +## Qualification update (2026) + +[Huyghebaert et al. (2025), Simulation of interferometric imaging with EISCAT_3D for fine-scale in-beam incoherent scatter spectra measurements](https://doi.org/10.5194/angeo-43-99-2025) supplies a GEMINI-based synthetic observation-operator example. This is not independent physical validation of this branch. See [the targeted research review](qualification/RESEARCH.md) for current IGRF and dependency sources. diff --git a/docs/dependency-inventory.json b/docs/dependency-inventory.json new file mode 100644 index 000000000..4a617ee15 --- /dev/null +++ b/docs/dependency-inventory.json @@ -0,0 +1,75 @@ +[ + { + "name": "ffilesystem", + "url": "https://github.com/ECLAIRWaveS/ffilesystem/archive/8a9ad4b213a8fbdb19816451a714f54017170109.tar.gz", + "sha256": "b0d9dfa00f6fa0977209352cff03634d71999b5f8ab4274b4ce07e56d6953e5c", + "license_observed": "MIT", + "notice": "docs/dependency-notices/ffilesystem-LICENSE", + "notice_sha256": "de5d760d5cab8f20c24bb9002e399ca9a640a4438d6ca7c8d84be663ccc096f5", + "enabled_in_local_profile": true + }, + { + "name": "glow", + "url": "https://github.com/gemini3d/glow/archive/62ce006692b8e16c403c995568ecc3403113d788.tar.gz", + "sha256": "ee3d70dbba76ed50d1dc5fefe1ddcaae6532ab855315a5108392d2983effc1e3", + "license_observed": "GLOW Open Source Academic Research License Agreement", + "notice": "docs/dependency-notices/glow-Glowlicense.txt", + "notice_sha256": "6336997691f134ffea7792ed392c4558754288e33abc3998b015557f6ea924ca", + "enabled_in_local_profile": true + }, + { + "name": "h5fortran", + "url": "https://github.com/ECLAIRWaveS/h5fortran/archive/04c7dd39405b43eac922319b6f4b74ea04b97043.tar.gz", + "sha256": "9b1f546c65690ba782e7973f10b7d14b098d5f9bab83c90655a7b7e151f52281", + "license_observed": "BSD-3-Clause", + "notice": "docs/dependency-notices/h5fortran-LICENSE", + "notice_sha256": "5941058448ead49006d58c737cf989646c1fc22662469cbbcc7f4af4148a1dad", + "enabled_in_local_profile": true + }, + { + "name": "hwm14", + "url": "https://github.com/gemini3d/hwm14/archive/a3092641ee4fdc7cc1a6fd42eaa45c2abc4891c2.tar.gz", + "sha256": "e057b2bc96b59525f13677a3db66429ef00ead7e93d2f0ce71b701dbe6caa97f", + "license_observed": "Apache-2.0", + "notice": "docs/dependency-notices/hwm14-LICENSE.txt", + "notice_sha256": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4", + "enabled_in_local_profile": false, + "qualification_profile": "enabled for separate unit/smoke tests; disabled in nine-case reference profile" + }, + { + "name": "msis", + "url": "https://github.com/gemini3d/msis/archive/e8437eb61ff0bdb3ef336d96fd279dd75d9aec98.tar.gz", + "sha256": "d3354a3a910ecfaa5fdb512e731647798d57b35085ff4c411264f0ddb69e013c", + "license_observed": "Apache-2.0 wrapper; review bundled model notices", + "notice": "docs/dependency-notices/msis-LICENSE", + "notice_sha256": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4", + "enabled_in_local_profile": true + }, + { + "name": "mumps", + "url": "https://github.com/scivision/mumps-superbuild/archive/31999e0f398d7f486c23c265ba5c40f8e1288a3c.tar.gz", + "sha256": "a4cc5c87d618543af9e41ef1bea877b08bb4b3160e36bf2c602110fe4519aea2", + "license_observed": "MIT", + "notice": "docs/dependency-notices/mumps-LICENSE", + "notice_sha256": "f259cbc7a6764ded8aafa6901d360492d68b3437ac15c1ba0e3ed5d9947c4a02", + "enabled_in_local_profile": true + }, + { + "name": "mumps_upstream", + "url": "https://mumps-solver.org/MUMPS_5.9.1.tar.gz", + "sha256": "659c9b57646b5a003ac618baa1faf9dd2044e46c732b3daaccbc7158003e1b46", + "license_observed": "CeCILL-C with bundled exceptions", + "notice": "docs/dependency-notices/mumps_upstream-LICENSE", + "notice_sha256": "5813fefd30a36fd7550cd2b62274be6586a0db51c11c3f2d4b852283e22ccc42", + "enabled_in_local_profile": true + }, + { + "name": "HDF5 qualification profile", + "url": "https://support.hdfgroup.org/releases/hdf5/2.2.0/downloads/hdf5-2.2.0.tar.gz", + "sha256": "1a1ab8209b35586fbc1aa279ba76d102130b95badcb20ca329587219112d8c16", + "license_observed": "HDF5 license; see exact notice", + "notice": "docs/dependency-notices/HDF5-2.2.0-LICENSE.txt", + "notice_sha256": "b384492d25c6e4a49f371b646d9a81bc0a4b97cf0c66c2f3ed1b35f78a148732", + "enabled_in_local_profile": true + } +] diff --git a/docs/dependency-notices/HDF5-2.2.0-LICENSE.txt b/docs/dependency-notices/HDF5-2.2.0-LICENSE.txt new file mode 100644 index 000000000..60abcc29c --- /dev/null +++ b/docs/dependency-notices/HDF5-2.2.0-LICENSE.txt @@ -0,0 +1,111 @@ +Copyright Notice and License Terms for +HDF5 (Hierarchical Data Format 5) Software Library and Utilities +----------------------------------------------------------------------------- + +HDF5 (Hierarchical Data Format 5) Software Library and Utilities +Copyright 2006 by The HDF Group. + +NCSA HDF5 (Hierarchical Data Format 5) Software Library and Utilities +Copyright 1998-2006 by The Board of Trustees of the University of Illinois. + +All rights reserved. + +This software library and utilities is covered by the 3-clause BSD License. + +Redistribution and use in source and binary forms, with or without +modification, are permitted for any purpose (including commercial purposes) +provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions, and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions, and the following disclaimer in the documentation + and/or materials provided with the distribution. + +3. Neither the name of The HDF Group, the name of the University, nor the + name of any Contributor may be used to endorse or promote products derived + from this software without specific prior written permission from + The HDF Group, the University, or the Contributor, respectively. + +DISCLAIMER: +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +“AS ISâ€� AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +For further details, please refer to the full license text available +at https://opensource.org/licenses/bsd-3-clause + +You are under no obligation whatsoever to provide any bug fixes, patches, or +upgrades to the features, functionality or performance of the source code +("Enhancements") to anyone; however, if you choose to make your Enhancements +available either publicly, or directly to The HDF Group, without imposing a +separate written license agreement for such Enhancements, then you hereby +grant the following license: a non-exclusive, royalty-free perpetual license +to install, use, modify, prepare derivative works, incorporate into other +computer software, distribute, and sublicense such enhancements or derivative +works thereof, in binary and source code form. + +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- + +Contributors: National Center for Supercomputing Applications (NCSA) at +the University of Illinois, Fortner Software, Unidata Program Center +(netCDF), The Independent JPEG Group (JPEG), Jean-loup Gailly and Mark Adler +(gzip), and Digital Equipment Corporation (DEC). + +----------------------------------------------------------------------------- + +Portions of HDF5 were developed with support from the Lawrence Berkeley +National Laboratory (LBNL) and the United States Department of Energy +under Prime Contract No. DE-AC02-05CH11231. + +----------------------------------------------------------------------------- + +Portions of HDF5 were developed with support from Lawrence Livermore +National Laboratory and the United States Department of Energy under +Prime Contract No. DE-AC52-07NA27344. + +----------------------------------------------------------------------------- + +Portions of HDF5 were developed with support from the University of +California, Lawrence Livermore National Laboratory (UC LLNL). +The following statement applies to those portions of the product and must +be retained in any redistribution of source code, binaries, documentation, +and/or accompanying materials: + + This work was partially produced at the University of California, + Lawrence Livermore National Laboratory (UC LLNL) under contract + no. W-7405-ENG-48 (Contract 48) between the U.S. Department of Energy + (DOE) and The Regents of the University of California (University) + for the operation of UC LLNL. + + DISCLAIMER: + THIS WORK WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF + THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR + THE UNIVERSITY OF CALIFORNIA NOR ANY OF THEIR EMPLOYEES, MAKES ANY + WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY OR RESPONSIBILITY + FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, + APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE + WOULD NOT INFRINGE PRIVATELY- OWNED RIGHTS. REFERENCE HEREIN TO ANY + SPECIFIC COMMERCIAL PRODUCTS, PROCESS, OR SERVICE BY TRADE NAME, + TRADEMARK, MANUFACTURER, OR OTHERWISE, DOES NOT NECESSARILY CONSTITUTE + OR IMPLY ITS ENDORSEMENT, RECOMMENDATION, OR FAVORING BY THE UNITED + STATES GOVERNMENT OR THE UNIVERSITY OF CALIFORNIA. THE VIEWS AND + OPINIONS OF AUTHORS EXPRESSED HEREIN DO NOT NECESSARILY STATE OR REFLECT + THOSE OF THE UNITED STATES GOVERNMENT OR THE UNIVERSITY OF CALIFORNIA, + AND SHALL NOT BE USED FOR ADVERTISING OR PRODUCT ENDORSEMENT PURPOSES. + +----------------------------------------------------------------------------- + +Portions of HDF5 were developed with support from the National Science +Foundation under Federal Award No. 2534078. + +----------------------------------------------------------------------------- \ No newline at end of file diff --git a/docs/dependency-notices/ffilesystem-LICENSE b/docs/dependency-notices/ffilesystem-LICENSE new file mode 100644 index 000000000..b34af8773 --- /dev/null +++ b/docs/dependency-notices/ffilesystem-LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Michael Hirsch + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/docs/dependency-notices/glow-Glowlicense.txt b/docs/dependency-notices/glow-Glowlicense.txt new file mode 100644 index 000000000..178f347b6 --- /dev/null +++ b/docs/dependency-notices/glow-Glowlicense.txt @@ -0,0 +1,95 @@ +GLOW MODEL OPEN SOURCE ACADEMIC RESEARCH LICENSE AGREEMENT + + +1. License. The University Corporation for Atmospheric Research (UCAR) +grants you a non-exclusive, nontransferable, world-wide, royalty-free +license to use, reproduce, and prepare derivative works of the GLOW model +software ("Software") for research, academic, and non-profit purposes + +2. Basis. This software was written by Stanley C. Solomon and colleagues, +as noted in the individual files. Some of the routines are based on +source code obtained from a variety of sources, including the 2-stream +electron transport algorithm by A. F. Nagy and P. M. Banks, and geomagnetic +field specifications from the International Reference Ionosphere. + +3. Restrictions and Use. +a. No Sales. You shall not sell, or license or transfer for a fee the +Software, or any work that in any manner contains the Software. +b. Modifications. All modifications or changes to the Software and +derivative works that incorporate or utilize the Software, shall carry +prominent notices stating that you changed the files and the date of the +change. Any reproductions of derivative works shall also be on an open +source basis. You are requested to transfer such modifications, changes, +and/or derivative works back to UCAR. +c. Copyright/Notices. Each copy of the Software, modification, or +derivative work shall include a file containing this Agreement. Reference +to this file will be displayed on any documents, media, printouts, or on +any other electronic or tangible expressions associated with, related to +or derived from the Software, as follows: "This software is part of the +GLOW model. Use is governed by the Open Source Academic Research License +Agreement contained in the file glowlicense.txt." +d. "Rules of the Road." The academic standards and practices with respect +to notification, citation, co-authorship, etc., are specified by the +"rules of the road" of the NSF CEDAR project and the NASA TIMED mission +(cf., cedarweb.hao.ucar.edu, www.timed.jhuapl.edu.) + +4. Termination. Your rights under this Agreement will terminate +automatically without notice from UCAR if you fail to comply with any +term(s) of this Agreement. The following provisions shall survive +termination: Sections 3, 6, 7, and 11. + +5. Proprietary Rights. Title, ownership rights, and intellectual property +rights in the Software shall remain in UCAR. You acknowledge such +ownership and intellectual property rights and will not take any action to +jeopardize, limit or interfere in any manner with UCAR's ownership of or +rights with respect to the Software. + +6. Disclaimer of Warranty on Software. You expressly acknowledge and agree +that use of the Software is at your sole risk. The Software is provided +"as is" and without warranty of any kind and UCAR expressly disclaims all +warranties and/or conditions of any kind, express or implied, including, +but not limited to, any warranties or conditions of title, non- +infringement of a third party's intellectual property, merchantability or +satisfactory quality and fitness for a particular purpose. UCAR does not +warrant that the functions contained in the software will meet your +requirements, or that the operation of the software will be uninterrupted +or error-free, or that defects in the software will be corrected. +Furthermore, UCAR does not warrant or make any representations and you +assume all risk regarding the use or the results of the use of the +software or related documentation in terms of their correctness, accuracy, +reliability, or otherwise. the parties expressly disclaim that the uniform +computer information transactions act (UCITA) applies to or governs this +agreement. No oral or written information or advice given by UCAR shall +create a warranty or in any way increase the scope of this warranty. +Should the Software prove defective, you (and not UCAR or any UCAR +representative) assume the cost of all necessary correction. + +7. Limitation of Liability. Under no circumstances, including negligence, +shall UCAR be liable for any direct, incidental, special, indirect or +consequential damages including lost revenue, profit or data, whether in +an action in contract or tort arising out of or relating to the use of or +inability to use the software, even if UCAR has been advised of the +possibility of such damages. + +8. Export Law Assurances. All Software and any technical data delivered +under this Agreement are subject to U.S. export control laws and may be +subject to export or import regulations in other countries. You agree to +comply strictly with all such laws and regulations and you acknowledge +that you have responsibility to obtain such license to export, re-export, +or import as may be required after delivery to you. + +9. No Support/Modifications. The Software is provided without any support +or maintenance, and without any obligation to provide you with +modifications, improvements, enhancements, or updates of the Software. + +10. Controlling Law and Severability. This Agreement shall be governed by +the laws of the United States. If for any reason a court of competent +jurisdiction finds any provision, or portion thereof, to be unenforceable, +the remainder of this Agreement shall continue in full force and effect. +This Agreement shall not be governed by the United Nations Convention on +Contracts for the International Sale of Goods, the application of which is +hereby expressly excluded. + +11. Complete Agreement. This Agreement constitutes the entire agreement +between the parties with respect to the use of the Software and supersedes +all prior or contemporaneous understandings regarding such subject matter. diff --git a/docs/dependency-notices/h5fortran-LICENSE b/docs/dependency-notices/h5fortran-LICENSE new file mode 100644 index 000000000..56d110663 --- /dev/null +++ b/docs/dependency-notices/h5fortran-LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2018-2026, SciVision +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/docs/dependency-notices/hwm14-LICENSE.txt b/docs/dependency-notices/hwm14-LICENSE.txt new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/docs/dependency-notices/hwm14-LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/docs/dependency-notices/msis-LICENSE b/docs/dependency-notices/msis-LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/docs/dependency-notices/msis-LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/docs/dependency-notices/mumps-LICENSE b/docs/dependency-notices/mumps-LICENSE new file mode 100644 index 000000000..9aadf5bd6 --- /dev/null +++ b/docs/dependency-notices/mumps-LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 SciVision, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/docs/dependency-notices/mumps-PORD-README b/docs/dependency-notices/mumps-PORD-README new file mode 100644 index 000000000..9dd67d573 --- /dev/null +++ b/docs/dependency-notices/mumps-PORD-README @@ -0,0 +1,24 @@ +ACKNOWLEDGEMENT: + +This directory contains an implementation of the PORD algorithm, +as described in: + "Towards a tighter coupling of bottom-up and top-down sparse + matrix ordering methods, J. Schulze, BIT, 41:4, pp 800, 2001." + +It is extracted from the SPACE-1.0 package developed at the +University of Paderborn by Juergen Schulze (js@juergenschulze.de). +A lot of the code in SPACE-1.0 was itself based on the SPOOLES +package by Cleve Ashcraft. + +We are grateful to Juergen Schulze for letting us distribute PORD. + +SPACE-1.0 (which includes PORD) is in the public domain, see +https://web.archive.org/web/20140426002151/http://www2.cs.uni-paderborn.de/cs/ag-monien/PERSONAL/SCHLUNZ/vrp.html +holding a copy of the original web page from Paderborn University +(former web page not anymore available: http://www2.cs.uni-paderborn.de/cs/ag-monien/PERSONAL/SCHLUNZ/vrp.html) +in which it is indicated + +"The fill-reducing ordering algorithm has been integrated in a software package called SPACE (SPArse Cholesky Elimination). The package not only provides an easy to use interface to the ordering algorithm, it also offers functions for the symbolical/numerical factorization steps and for the solution of the triangular systems. The factorizations and solves may be computed in serial or in parallel using MPI. In all cases, the important computational kernels are based on BLAS-3 like operations. Although all functions are completely written in C code, the design of the library follows object-oriented principles; there are objects and methods that can be applied to the objects (i.e. object creation, object manipulation). + +The SPACE library is totally within the public domain; there are absolutely no licensing restrictions. + diff --git a/docs/dependency-notices/mumps-doc-CeCILL-C_V1-en.txt b/docs/dependency-notices/mumps-doc-CeCILL-C_V1-en.txt new file mode 100644 index 000000000..3d2a81914 --- /dev/null +++ b/docs/dependency-notices/mumps-doc-CeCILL-C_V1-en.txt @@ -0,0 +1,517 @@ + +CeCILL-C FREE SOFTWARE LICENSE AGREEMENT + + + Notice + +This Agreement is a Free Software license agreement that is the result +of discussions between its authors in order to ensure compliance with +the two main principles guiding its drafting: + + * firstly, compliance with the principles governing the distribution + of Free Software: access to source code, broad rights granted to + users, + * secondly, the election of a governing law, French law, with which + it is conformant, both as regards the law of torts and + intellectual property law, and the protection that it offers to + both authors and holders of the economic rights over software. + +The authors of the CeCILL-C (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) +license are: + +Commissariat à l'Energie Atomique - CEA, a public scientific, technical +and industrial research establishment, having its principal place of +business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France. + +Centre National de la Recherche Scientifique - CNRS, a public scientific +and technological establishment, having its principal place of business +at 3 rue Michel-Ange, 75794 Paris cedex 16, France. + +Institut National de Recherche en Informatique et en Automatique - +INRIA, a public scientific and technological establishment, having its +principal place of business at Domaine de Voluceau, Rocquencourt, BP +105, 78153 Le Chesnay cedex, France. + + + Preamble + +The purpose of this Free Software license agreement is to grant users +the right to modify and re-use the software governed by this license. + +The exercising of this right is conditional upon the obligation to make +available to the community the modifications made to the source code of +the software so as to contribute to its evolution. + +In consideration of access to the source code and the rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors only have limited liability. + +In this respect, the risks associated with loading, using, modifying +and/or developing or reproducing the software by the user are brought to +the user's attention, given its Free Software status, which may make it +complicated to use, with the result that its use is reserved for +developers and experienced professionals having in-depth computer +knowledge. Users are therefore encouraged to load and test the +suitability of the software as regards their requirements in conditions +enabling the security of their systems and/or data to be ensured and, +more generally, to use and operate it in the same conditions of +security. This Agreement may be freely reproduced and published, +provided it is not altered, and that no provisions are either added or +removed herefrom. + +This Agreement may apply to any or all software for which the holder of +the economic rights decides to submit the use thereof to its provisions. + + + Article 1 - DEFINITIONS + +For the purpose of this Agreement, when the following expressions +commence with a capital letter, they shall have the following meaning: + +Agreement: means this license agreement, and its possible subsequent +versions and annexes. + +Software: means the software in its Object Code and/or Source Code form +and, where applicable, its documentation, "as is" when the Licensee +accepts the Agreement. + +Initial Software: means the Software in its Source Code and possibly its +Object Code form and, where applicable, its documentation, "as is" when +it is first distributed under the terms and conditions of the Agreement. + +Modified Software: means the Software modified by at least one +Integrated Contribution. + +Source Code: means all the Software's instructions and program lines to +which access is required so as to modify the Software. + +Object Code: means the binary files originating from the compilation of +the Source Code. + +Holder: means the holder(s) of the economic rights over the Initial +Software. + +Licensee: means the Software user(s) having accepted the Agreement. + +Contributor: means a Licensee having made at least one Integrated +Contribution. + +Licensor: means the Holder, or any other individual or legal entity, who +distributes the Software under the Agreement. + +Integrated Contribution: means any or all modifications, corrections, +translations, adaptations and/or new functions integrated into the +Source Code by any or all Contributors. + +Related Module: means a set of sources files including their +documentation that, without modification to the Source Code, enables +supplementary functions or services in addition to those offered by the +Software. + +Derivative Software: means any combination of the Software, modified or +not, and of a Related Module. + +Parties: mean both the Licensee and the Licensor. + +These expressions may be used both in singular and plural form. + + + Article 2 - PURPOSE + +The purpose of the Agreement is the grant by the Licensor to the +Licensee of a non-exclusive, transferable and worldwide license for the +Software as set forth in Article 5 hereinafter for the whole term of the +protection granted by the rights over said Software. + + + Article 3 - ACCEPTANCE + +3.1 The Licensee shall be deemed as having accepted the terms and +conditions of this Agreement upon the occurrence of the first of the +following events: + + * (i) loading the Software by any or all means, notably, by + downloading from a remote server, or by loading from a physical + medium; + * (ii) the first time the Licensee exercises any of the rights + granted hereunder. + +3.2 One copy of the Agreement, containing a notice relating to the +characteristics of the Software, to the limited warranty, and to the +fact that its use is restricted to experienced users has been provided +to the Licensee prior to its acceptance as set forth in Article 3.1 +hereinabove, and the Licensee hereby acknowledges that it has read and +understood it. + + + Article 4 - EFFECTIVE DATE AND TERM + + + 4.1 EFFECTIVE DATE + +The Agreement shall become effective on the date when it is accepted by +the Licensee as set forth in Article 3.1. + + + 4.2 TERM + +The Agreement shall remain in force for the entire legal term of +protection of the economic rights over the Software. + + + Article 5 - SCOPE OF RIGHTS GRANTED + +The Licensor hereby grants to the Licensee, who accepts, the following +rights over the Software for any or all use, and for the term of the +Agreement, on the basis of the terms and conditions set forth hereinafter. + +Besides, if the Licensor owns or comes to own one or more patents +protecting all or part of the functions of the Software or of its +components, the Licensor undertakes not to enforce the rights granted by +these patents against successive Licensees using, exploiting or +modifying the Software. If these patents are transferred, the Licensor +undertakes to have the transferees subscribe to the obligations set +forth in this paragraph. + + + 5.1 RIGHT OF USE + +The Licensee is authorized to use the Software, without any limitation +as to its fields of application, with it being hereinafter specified +that this comprises: + + 1. permanent or temporary reproduction of all or part of the Software + by any or all means and in any or all form. + + 2. loading, displaying, running, or storing the Software on any or + all medium. + + 3. entitlement to observe, study or test its operation so as to + determine the ideas and principles behind any or all constituent + elements of said Software. This shall apply when the Licensee + carries out any or all loading, displaying, running, transmission + or storage operation as regards the Software, that it is entitled + to carry out hereunder. + + + 5.2 RIGHT OF MODIFICATION + +The right of modification includes the right to translate, adapt, +arrange, or make any or all modifications to the Software, and the right +to reproduce the resulting software. It includes, in particular, the +right to create a Derivative Software. + +The Licensee is authorized to make any or all modification to the +Software provided that it includes an explicit notice that it is the +author of said modification and indicates the date of the creation thereof. + + + 5.3 RIGHT OF DISTRIBUTION + +In particular, the right of distribution includes the right to publish, +transmit and communicate the Software to the general public on any or +all medium, and by any or all means, and the right to market, either in +consideration of a fee, or free of charge, one or more copies of the +Software by any means. + +The Licensee is further authorized to distribute copies of the modified +or unmodified Software to third parties according to the terms and +conditions set forth hereinafter. + + + 5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION + +The Licensee is authorized to distribute true copies of the Software in +Source Code or Object Code form, provided that said distribution +complies with all the provisions of the Agreement and is accompanied by: + + 1. a copy of the Agreement, + + 2. a notice relating to the limitation of both the Licensor's + warranty and liability as set forth in Articles 8 and 9, + +and that, in the event that only the Object Code of the Software is +redistributed, the Licensee allows effective access to the full Source +Code of the Software at a minimum during the entire period of its +distribution of the Software, it being understood that the additional +cost of acquiring the Source Code shall not exceed the cost of +transferring the data. + + + 5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE + +When the Licensee makes an Integrated Contribution to the Software, the +terms and conditions for the distribution of the resulting Modified +Software become subject to all the provisions of this Agreement. + +The Licensee is authorized to distribute the Modified Software, in +source code or object code form, provided that said distribution +complies with all the provisions of the Agreement and is accompanied by: + + 1. a copy of the Agreement, + + 2. a notice relating to the limitation of both the Licensor's + warranty and liability as set forth in Articles 8 and 9, + +and that, in the event that only the object code of the Modified +Software is redistributed, the Licensee allows effective access to the +full source code of the Modified Software at a minimum during the entire +period of its distribution of the Modified Software, it being understood +that the additional cost of acquiring the source code shall not exceed +the cost of transferring the data. + + + 5.3.3 DISTRIBUTION OF DERIVATIVE SOFTWARE + +When the Licensee creates Derivative Software, this Derivative Software +may be distributed under a license agreement other than this Agreement, +subject to compliance with the requirement to include a notice +concerning the rights over the Software as defined in Article 6.4. +In the event the creation of the Derivative Software required modification +of the Source Code, the Licensee undertakes that: + + 1. the resulting Modified Software will be governed by this Agreement, + 2. the Integrated Contributions in the resulting Modified Software + will be clearly identified and documented, + 3. the Licensee will allow effective access to the source code of the + Modified Software, at a minimum during the entire period of + distribution of the Derivative Software, such that such + modifications may be carried over in a subsequent version of the + Software; it being understood that the additional cost of + purchasing the source code of the Modified Software shall not + exceed the cost of transferring the data. + + + 5.3.4 COMPATIBILITY WITH THE CeCILL LICENSE + +When a Modified Software contains an Integrated Contribution subject to +the CeCILL license agreement, or when a Derivative Software contains a +Related Module subject to the CeCILL license agreement, the provisions +set forth in the third item of Article 6.4 are optional. + + + Article 6 - INTELLECTUAL PROPERTY + + + 6.1 OVER THE INITIAL SOFTWARE + +The Holder owns the economic rights over the Initial Software. Any or +all use of the Initial Software is subject to compliance with the terms +and conditions under which the Holder has elected to distribute its work +and no one shall be entitled to modify the terms and conditions for the +distribution of said Initial Software. + +The Holder undertakes that the Initial Software will remain ruled at +least by this Agreement, for the duration set forth in Article 4.2. + + + 6.2 OVER THE INTEGRATED CONTRIBUTIONS + +The Licensee who develops an Integrated Contribution is the owner of the +intellectual property rights over this Contribution as defined by +applicable law. + + + 6.3 OVER THE RELATED MODULES + +The Licensee who develops a Related Module is the owner of the +intellectual property rights over this Related Module as defined by +applicable law and is free to choose the type of agreement that shall +govern its distribution under the conditions defined in Article 5.3.3. + + + 6.4 NOTICE OF RIGHTS + +The Licensee expressly undertakes: + + 1. not to remove, or modify, in any manner, the intellectual property + notices attached to the Software; + + 2. to reproduce said notices, in an identical manner, in the copies + of the Software modified or not; + + 3. to ensure that use of the Software, its intellectual property + notices and the fact that it is governed by the Agreement is + indicated in a text that is easily accessible, specifically from + the interface of any Derivative Software. + +The Licensee undertakes not to directly or indirectly infringe the +intellectual property rights of the Holder and/or Contributors on the +Software and to take, where applicable, vis-à-vis its staff, any and all +measures required to ensure respect of said intellectual property rights +of the Holder and/or Contributors. + + + Article 7 - RELATED SERVICES + +7.1 Under no circumstances shall the Agreement oblige the Licensor to +provide technical assistance or maintenance services for the Software. + +However, the Licensor is entitled to offer this type of services. The +terms and conditions of such technical assistance, and/or such +maintenance, shall be set forth in a separate instrument. Only the +Licensor offering said maintenance and/or technical assistance services +shall incur liability therefor. + +7.2 Similarly, any Licensor is entitled to offer to its licensees, under +its sole responsibility, a warranty, that shall only be binding upon +itself, for the redistribution of the Software and/or the Modified +Software, under terms and conditions that it is free to decide. Said +warranty, and the financial terms and conditions of its application, +shall be subject of a separate instrument executed between the Licensor +and the Licensee. + + + Article 8 - LIABILITY + +8.1 Subject to the provisions of Article 8.2, the Licensee shall be +entitled to claim compensation for any direct loss it may have suffered +from the Software as a result of a fault on the part of the relevant +Licensor, subject to providing evidence thereof. + +8.2 The Licensor's liability is limited to the commitments made under +this Agreement and shall not be incurred as a result of in particular: +(i) loss due the Licensee's total or partial failure to fulfill its +obligations, (ii) direct or consequential loss that is suffered by the +Licensee due to the use or performance of the Software, and (iii) more +generally, any consequential loss. In particular the Parties expressly +agree that any or all pecuniary or business loss (i.e. loss of data, +loss of profits, operating loss, loss of customers or orders, +opportunity cost, any disturbance to business activities) or any or all +legal proceedings instituted against the Licensee by a third party, +shall constitute consequential loss and shall not provide entitlement to +any or all compensation from the Licensor. + + + Article 9 - WARRANTY + +9.1 The Licensee acknowledges that the scientific and technical +state-of-the-art when the Software was distributed did not enable all +possible uses to be tested and verified, nor for the presence of +possible defects to be detected. In this respect, the Licensee's +attention has been drawn to the risks associated with loading, using, +modifying and/or developing and reproducing the Software which are +reserved for experienced users. + +The Licensee shall be responsible for verifying, by any or all means, +the suitability of the product for its requirements, its good working +order, and for ensuring that it shall not cause damage to either persons +or properties. + +9.2 The Licensor hereby represents, in good faith, that it is entitled +to grant all the rights over the Software (including in particular the +rights set forth in Article 5). + +9.3 The Licensee acknowledges that the Software is supplied "as is" by +the Licensor without any other express or tacit warranty, other than +that provided for in Article 9.2 and, in particular, without any warranty +as to its commercial value, its secured, safe, innovative or relevant +nature. + +Specifically, the Licensor does not warrant that the Software is free +from any error, that it will operate without interruption, that it will +be compatible with the Licensee's own equipment and software +configuration, nor that it will meet the Licensee's requirements. + +9.4 The Licensor does not either expressly or tacitly warrant that the +Software does not infringe any third party intellectual property right +relating to a patent, software or any other property right. Therefore, +the Licensor disclaims any and all liability towards the Licensee +arising out of any or all proceedings for infringement that may be +instituted in respect of the use, modification and redistribution of the +Software. Nevertheless, should such proceedings be instituted against +the Licensee, the Licensor shall provide it with technical and legal +assistance for its defense. Such technical and legal assistance shall be +decided on a case-by-case basis between the relevant Licensor and the +Licensee pursuant to a memorandum of understanding. The Licensor +disclaims any and all liability as regards the Licensee's use of the +name of the Software. No warranty is given as regards the existence of +prior rights over the name of the Software or as regards the existence +of a trademark. + + + Article 10 - TERMINATION + +10.1 In the event of a breach by the Licensee of its obligations +hereunder, the Licensor may automatically terminate this Agreement +thirty (30) days after notice has been sent to the Licensee and has +remained ineffective. + +10.2 A Licensee whose Agreement is terminated shall no longer be +authorized to use, modify or distribute the Software. However, any +licenses that it may have granted prior to termination of the Agreement +shall remain valid subject to their having been granted in compliance +with the terms and conditions hereof. + + + Article 11 - MISCELLANEOUS + + + 11.1 EXCUSABLE EVENTS + +Neither Party shall be liable for any or all delay, or failure to +perform the Agreement, that may be attributable to an event of force +majeure, an act of God or an outside cause, such as defective +functioning or interruptions of the electricity or telecommunications +networks, network paralysis following a virus attack, intervention by +government authorities, natural disasters, water damage, earthquakes, +fire, explosions, strikes and labor unrest, war, etc. + +11.2 Any failure by either Party, on one or more occasions, to invoke +one or more of the provisions hereof, shall under no circumstances be +interpreted as being a waiver by the interested Party of its right to +invoke said provision(s) subsequently. + +11.3 The Agreement cancels and replaces any or all previous agreements, +whether written or oral, between the Parties and having the same +purpose, and constitutes the entirety of the agreement between said +Parties concerning said purpose. No supplement or modification to the +terms and conditions hereof shall be effective as between the Parties +unless it is made in writing and signed by their duly authorized +representatives. + +11.4 In the event that one or more of the provisions hereof were to +conflict with a current or future applicable act or legislative text, +said act or legislative text shall prevail, and the Parties shall make +the necessary amendments so as to comply with said act or legislative +text. All other provisions shall remain effective. Similarly, invalidity +of a provision of the Agreement, for any reason whatsoever, shall not +cause the Agreement as a whole to be invalid. + + + 11.5 LANGUAGE + +The Agreement is drafted in both French and English and both versions +are deemed authentic. + + + Article 12 - NEW VERSIONS OF THE AGREEMENT + +12.1 Any person is authorized to duplicate and distribute copies of this +Agreement. + +12.2 So as to ensure coherence, the wording of this Agreement is +protected and may only be modified by the authors of the License, who +reserve the right to periodically publish updates or new versions of the +Agreement, each with a separate number. These subsequent versions may +address new issues encountered by Free Software. + +12.3 Any Software distributed under a given version of the Agreement may +only be subsequently distributed under the same version of the Agreement +or a subsequent version. + + + Article 13 - GOVERNING LAW AND JURISDICTION + +13.1 The Agreement is governed by French law. The Parties agree to +endeavor to seek an amicable solution to any disagreements or disputes +that may arise during the performance of the Agreement. + +13.2 Failing an amicable solution within two (2) months as from their +occurrence, and unless emergency proceedings are necessary, the +disagreements or disputes shall be referred to the Paris Courts having +jurisdiction, by the more diligent Party. + + +Version 1.0 dated 2006-09-05. diff --git a/docs/dependency-notices/mumps-doc-CeCILL-C_V1-fr.txt b/docs/dependency-notices/mumps-doc-CeCILL-C_V1-fr.txt new file mode 100644 index 000000000..4fa44ba74 --- /dev/null +++ b/docs/dependency-notices/mumps-doc-CeCILL-C_V1-fr.txt @@ -0,0 +1,521 @@ + +CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-C + + + Avertissement + +Ce contrat est une licence de logiciel libre issue d'une concertation +entre ses auteurs afin que le respect de deux grands principes préside à +sa rédaction: + + * d'une part, le respect des principes de diffusion des logiciels + libres: accès au code source, droits étendus conférés aux + utilisateurs, + * d'autre part, la désignation d'un droit applicable, le droit + français, auquel elle est conforme, tant au regard du droit de la + responsabilité civile que du droit de la propriété intellectuelle + et de la protection qu'il offre aux auteurs et titulaires des + droits patrimoniaux sur un logiciel. + +Les auteurs de la licence CeCILL-C (pour Ce[a] C[nrs] I[nria] L[ogiciel] +L[ibre]) sont: + +Commissariat à l'Energie Atomique - CEA, établissement public de +recherche à caractère scientifique, technique et industriel, dont le +siège est situé 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris. + +Centre National de la Recherche Scientifique - CNRS, établissement +public à caractère scientifique et technologique, dont le siège est +situé 3 rue Michel-Ange, 75794 Paris cedex 16. + +Institut National de Recherche en Informatique et en Automatique - +INRIA, établissement public à caractère scientifique et technologique, +dont le siège est situé Domaine de Voluceau, Rocquencourt, BP 105, 78153 +Le Chesnay cedex. + + + Préambule + +Ce contrat est une licence de logiciel libre dont l'objectif est de +conférer aux utilisateurs la liberté de modifier et de réutiliser le +logiciel régi par cette licence. + +L'exercice de cette liberté est assorti d'une obligation de remettre à +la disposition de la communauté les modifications apportées au code +source du logiciel afin de contribuer à son évolution. + +L'accessibilité au code source et les droits de copie, de modification +et de redistribution qui découlent de ce contrat ont pour contrepartie +de n'offrir aux utilisateurs qu'une garantie limitée et de ne faire +peser sur l'auteur du logiciel, le titulaire des droits patrimoniaux et +les concédants successifs qu'une responsabilité restreinte. + +A cet égard l'attention de l'utilisateur est attirée sur les risques +associés au chargement, à l'utilisation, à la modification et/ou au +développement et à la reproduction du logiciel par l'utilisateur étant +donné sa spécificité de logiciel libre, qui peut le rendre complexe à +manipuler et qui le réserve donc à des développeurs ou des +professionnels avertis possédant des connaissances informatiques +approfondies. Les utilisateurs sont donc invités à charger et tester +l'adéquation du logiciel à leurs besoins dans des conditions permettant +d'assurer la sécurité de leurs systèmes et/ou de leurs données et, plus +généralement, à l'utiliser et l'exploiter dans les mêmes conditions de +sécurité. Ce contrat peut être reproduit et diffusé librement, sous +réserve de le conserver en l'état, sans ajout ni suppression de clauses. + +Ce contrat est susceptible de s'appliquer à tout logiciel dont le +titulaire des droits patrimoniaux décide de soumettre l'exploitation aux +dispositions qu'il contient. + + + Article 1 - DEFINITIONS + +Dans ce contrat, les termes suivants, lorsqu'ils seront écrits avec une +lettre capitale, auront la signification suivante: + +Contrat: désigne le présent contrat de licence, ses éventuelles versions +postérieures et annexes. + +Logiciel: désigne le logiciel sous sa forme de Code Objet et/ou de Code +Source et le cas échéant sa documentation, dans leur état au moment de +l'acceptation du Contrat par le Licencié. + +Logiciel Initial: désigne le Logiciel sous sa forme de Code Source et +éventuellement de Code Objet et le cas échéant sa documentation, dans +leur état au moment de leur première diffusion sous les termes du Contrat. + +Logiciel Modifié: désigne le Logiciel modifié par au moins une +Contribution Intégrée. + +Code Source: désigne l'ensemble des instructions et des lignes de +programme du Logiciel et auquel l'accès est nécessaire en vue de +modifier le Logiciel. + +Code Objet: désigne les fichiers binaires issus de la compilation du +Code Source. + +Titulaire: désigne le ou les détenteurs des droits patrimoniaux d'auteur +sur le Logiciel Initial. + +Licencié: désigne le ou les utilisateurs du Logiciel ayant accepté le +Contrat. + +Contributeur: désigne le Licencié auteur d'au moins une Contribution +Intégrée. + +Concédant: désigne le Titulaire ou toute personne physique ou morale +distribuant le Logiciel sous le Contrat. + +Contribution Intégrée: désigne l'ensemble des modifications, +corrections, traductions, adaptations et/ou nouvelles fonctionnalités +intégrées dans le Code Source par tout Contributeur. + +Module Lié: désigne un ensemble de fichiers sources y compris leur +documentation qui, sans modification du Code Source, permet de réaliser +des fonctionnalités ou services supplémentaires à ceux fournis par le +Logiciel. + +Logiciel Dérivé: désigne toute combinaison du Logiciel, modifié ou non, +et d'un Module Lié. + +Parties: désigne collectivement le Licencié et le Concédant. + +Ces termes s'entendent au singulier comme au pluriel. + + + Article 2 - OBJET + +Le Contrat a pour objet la concession par le Concédant au Licencié d'une +licence non exclusive, cessible et mondiale du Logiciel telle que +définie ci-après à l'article 5 pour toute la durée de protection des droits +portant sur ce Logiciel. + + + Article 3 - ACCEPTATION + +3.1 L'acceptation par le Licencié des termes du Contrat est réputée +acquise du fait du premier des faits suivants: + + * (i) le chargement du Logiciel par tout moyen notamment par + téléchargement à partir d'un serveur distant ou par chargement à + partir d'un support physique; + * (ii) le premier exercice par le Licencié de l'un quelconque des + droits concédés par le Contrat. + +3.2 Un exemplaire du Contrat, contenant notamment un avertissement +relatif aux spécificités du Logiciel, à la restriction de garantie et à +la limitation à un usage par des utilisateurs expérimentés a été mis à +disposition du Licencié préalablement à son acceptation telle que +définie à l'article 3.1 ci dessus et le Licencié reconnaît en avoir pris +connaissance. + + + Article 4 - ENTREE EN VIGUEUR ET DUREE + + + 4.1 ENTREE EN VIGUEUR + +Le Contrat entre en vigueur à la date de son acceptation par le Licencié +telle que définie en 3.1. + + + 4.2 DUREE + +Le Contrat produira ses effets pendant toute la durée légale de +protection des droits patrimoniaux portant sur le Logiciel. + + + Article 5 - ETENDUE DES DROITS CONCEDES + +Le Concédant concède au Licencié, qui accepte, les droits suivants sur +le Logiciel pour toutes destinations et pour la durée du Contrat dans +les conditions ci-après détaillées. + +Par ailleurs, si le Concédant détient ou venait à détenir un ou +plusieurs brevets d'invention protégeant tout ou partie des +fonctionnalités du Logiciel ou de ses composants, il s'engage à ne pas +opposer les éventuels droits conférés par ces brevets aux Licenciés +successifs qui utiliseraient, exploiteraient ou modifieraient le +Logiciel. En cas de cession de ces brevets, le Concédant s'engage à +faire reprendre les obligations du présent alinéa aux cessionnaires. + + + 5.1 DROIT D'UTILISATION + +Le Licencié est autorisé à utiliser le Logiciel, sans restriction quant +aux domaines d'application, étant ci-après précisé que cela comporte: + + 1. la reproduction permanente ou provisoire du Logiciel en tout ou + partie par tout moyen et sous toute forme. + + 2. le chargement, l'affichage, l'exécution, ou le stockage du + Logiciel sur tout support. + + 3. la possibilité d'en observer, d'en étudier, ou d'en tester le + fonctionnement afin de déterminer les idées et principes qui sont + à la base de n'importe quel élément de ce Logiciel; et ceci, + lorsque le Licencié effectue toute opération de chargement, + d'affichage, d'exécution, de transmission ou de stockage du + Logiciel qu'il est en droit d'effectuer en vertu du Contrat. + + + 5.2 DROIT DE MODIFICATION + +Le droit de modification comporte le droit de traduire, d'adapter, +d'arranger ou d'apporter toute autre modification au Logiciel et le +droit de reproduire le logiciel en résultant. Il comprend en particulier +le droit de créer un Logiciel Dérivé. + +Le Licencié est autorisé à apporter toute modification au Logiciel sous +réserve de mentionner, de façon explicite, son nom en tant qu'auteur de +cette modification et la date de création de celle-ci. + + + 5.3 DROIT DE DISTRIBUTION + +Le droit de distribution comporte notamment le droit de diffuser, de +transmettre et de communiquer le Logiciel au public sur tout support et +par tout moyen ainsi que le droit de mettre sur le marché à titre +onéreux ou gratuit, un ou des exemplaires du Logiciel par tout procédé. + +Le Licencié est autorisé à distribuer des copies du Logiciel, modifié ou +non, à des tiers dans les conditions ci-après détaillées. + + + 5.3.1 DISTRIBUTION DU LOGICIEL SANS MODIFICATION + +Le Licencié est autorisé à distribuer des copies conformes du Logiciel, +sous forme de Code Source ou de Code Objet, à condition que cette +distribution respecte les dispositions du Contrat dans leur totalité et +soit accompagnée: + + 1. d'un exemplaire du Contrat, + + 2. d'un avertissement relatif à la restriction de garantie et de + responsabilité du Concédant telle que prévue aux articles 8 + et 9, + +et que, dans le cas où seul le Code Objet du Logiciel est redistribué, +le Licencié permette un accès effectif au Code Source complet du +Logiciel pendant au moins toute la durée de sa distribution du Logiciel, +étant entendu que le coût additionnel d'acquisition du Code Source ne +devra pas excéder le simple coût de transfert des données. + + + 5.3.2 DISTRIBUTION DU LOGICIEL MODIFIE + +Lorsque le Licencié apporte une Contribution Intégrée au Logiciel, les +conditions de distribution du Logiciel Modifié en résultant sont alors +soumises à l'intégralité des dispositions du Contrat. + +Le Licencié est autorisé à distribuer le Logiciel Modifié sous forme de +code source ou de code objet, à condition que cette distribution +respecte les dispositions du Contrat dans leur totalité et soit +accompagnée: + + 1. d'un exemplaire du Contrat, + + 2. d'un avertissement relatif à la restriction de garantie et de + responsabilité du Concédant telle que prévue aux articles 8 + et 9, + +et que, dans le cas où seul le code objet du Logiciel Modifié est +redistribué, le Licencié permette un accès effectif à son code source +complet pendant au moins toute la durée de sa distribution du Logiciel +Modifié, étant entendu que le coût additionnel d'acquisition du code +source ne devra pas excéder le simple coût de transfert des données. + + + 5.3.3 DISTRIBUTION DU LOGICIEL DERIVE + +Lorsque le Licencié crée un Logiciel Dérivé, ce Logiciel Dérivé peut +être distribué sous un contrat de licence autre que le présent Contrat à +condition de respecter les obligations de mention des droits sur le +Logiciel telles que définies à l'article 6.4. Dans le cas où la création du +Logiciel Dérivé a nécessité une modification du Code Source le licencié +s'engage à ce que: + + 1. le Logiciel Modifié correspondant à cette modification soit régi + par le présent Contrat, + 2. les Contributions Intégrées dont le Logiciel Modifié résulte + soient clairement identifiées et documentées, + 3. le Licencié permette un accès effectif au code source du Logiciel + Modifié, pendant au moins toute la durée de la distribution du + Logiciel Dérivé, de telle sorte que ces modifications puissent + être reprises dans une version ultérieure du Logiciel, étant + entendu que le coût additionnel d'acquisition du code source du + Logiciel Modifié ne devra pas excéder le simple coût du transfert + des données. + + + 5.3.4 COMPATIBILITE AVEC LA LICENCE CeCILL + +Lorsqu'un Logiciel Modifié contient une Contribution Intégrée soumise au +contrat de licence CeCILL, ou lorsqu'un Logiciel Dérivé contient un +Module Lié soumis au contrat de licence CeCILL, les stipulations prévues +au troisième item de l'article 6.4 sont facultatives. + + + Article 6 - PROPRIETE INTELLECTUELLE + + + 6.1 SUR LE LOGICIEL INITIAL + +Le Titulaire est détenteur des droits patrimoniaux sur le Logiciel +Initial. Toute utilisation du Logiciel Initial est soumise au respect +des conditions dans lesquelles le Titulaire a choisi de diffuser son +oeuvre et nul autre n'a la faculté de modifier les conditions de +diffusion de ce Logiciel Initial. + +Le Titulaire s'engage à ce que le Logiciel Initial reste au moins régi +par le Contrat et ce, pour la durée visée à l'article 4.2. + + + 6.2 SUR LES CONTRIBUTIONS INTEGREES + +Le Licencié qui a développé une Contribution Intégrée est titulaire sur +celle-ci des droits de propriété intellectuelle dans les conditions +définies par la législation applicable. + + + 6.3 SUR LES MODULES LIES + +Le Licencié qui a développé un Module Lié est titulaire sur celui-ci des +droits de propriété intellectuelle dans les conditions définies par la +législation applicable et reste libre du choix du contrat régissant sa +diffusion dans les conditions définies à l'article 5.3.3. + + + 6.4 MENTIONS DES DROITS + +Le Licencié s'engage expressément: + + 1. à ne pas supprimer ou modifier de quelque manière que ce soit les + mentions de propriété intellectuelle apposées sur le Logiciel; + + 2. à reproduire à l'identique lesdites mentions de propriété + intellectuelle sur les copies du Logiciel modifié ou non; + + 3. à faire en sorte que l'utilisation du Logiciel, ses mentions de + propriété intellectuelle et le fait qu'il est régi par le Contrat + soient indiqués dans un texte facilement accessible notamment + depuis l'interface de tout Logiciel Dérivé. + +Le Licencié s'engage à ne pas porter atteinte, directement ou +indirectement, aux droits de propriété intellectuelle du Titulaire et/ou +des Contributeurs sur le Logiciel et à prendre, le cas échéant, à +l'égard de son personnel toutes les mesures nécessaires pour assurer le +respect des dits droits de propriété intellectuelle du Titulaire et/ou +des Contributeurs. + + + Article 7 - SERVICES ASSOCIES + +7.1 Le Contrat n'oblige en aucun cas le Concédant à la réalisation de +prestations d'assistance technique ou de maintenance du Logiciel. + +Cependant le Concédant reste libre de proposer ce type de services. Les +termes et conditions d'une telle assistance technique et/ou d'une telle +maintenance seront alors déterminés dans un acte séparé. Ces actes de +maintenance et/ou assistance technique n'engageront que la seule +responsabilité du Concédant qui les propose. + +7.2 De même, tout Concédant est libre de proposer, sous sa seule +responsabilité, à ses licenciés une garantie, qui n'engagera que lui, +lors de la redistribution du Logiciel et/ou du Logiciel Modifié et ce, +dans les conditions qu'il souhaite. Cette garantie et les modalités +financières de son application feront l'objet d'un acte séparé entre le +Concédant et le Licencié. + + + Article 8 - RESPONSABILITE + +8.1 Sous réserve des dispositions de l'article 8.2, le Licencié a la +faculté, sous réserve de prouver la faute du Concédant concerné, de +solliciter la réparation du préjudice direct qu'il subirait du fait du +Logiciel et dont il apportera la preuve. + +8.2 La responsabilité du Concédant est limitée aux engagements pris en +application du Contrat et ne saurait être engagée en raison notamment: +(i) des dommages dus à l'inexécution, totale ou partielle, de ses +obligations par le Licencié, (ii) des dommages directs ou indirects +découlant de l'utilisation ou des performances du Logiciel subis par le +Licencié et (iii) plus généralement d'un quelconque dommage indirect. En +particulier, les Parties conviennent expressément que tout préjudice +financier ou commercial (par exemple perte de données, perte de +bénéfices, perte d'exploitation, perte de clientèle ou de commandes, +manque à gagner, trouble commercial quelconque) ou toute action dirigée +contre le Licencié par un tiers, constitue un dommage indirect et +n'ouvre pas droit à réparation par le Concédant. + + + Article 9 - GARANTIE + +9.1 Le Licencié reconnaît que l'état actuel des connaissances +scientifiques et techniques au moment de la mise en circulation du +Logiciel ne permet pas d'en tester et d'en vérifier toutes les +utilisations ni de détecter l'existence d'éventuels défauts. L'attention +du Licencié a été attirée sur ce point sur les risques associés au +chargement, à l'utilisation, la modification et/ou au développement et à +la reproduction du Logiciel qui sont réservés à des utilisateurs avertis. + +Il relève de la responsabilité du Licencié de contrôler, par tous +moyens, l'adéquation du produit à ses besoins, son bon fonctionnement et +de s'assurer qu'il ne causera pas de dommages aux personnes et aux biens. + +9.2 Le Concédant déclare de bonne foi être en droit de concéder +l'ensemble des droits attachés au Logiciel (comprenant notamment les +droits visés à l'article 5). + +9.3 Le Licencié reconnaît que le Logiciel est fourni "en l'état" par le +Concédant sans autre garantie, expresse ou tacite, que celle prévue à +l'article 9.2 et notamment sans aucune garantie sur sa valeur commerciale, +son caractère sécurisé, innovant ou pertinent. + +En particulier, le Concédant ne garantit pas que le Logiciel est exempt +d'erreur, qu'il fonctionnera sans interruption, qu'il sera compatible +avec l'équipement du Licencié et sa configuration logicielle ni qu'il +remplira les besoins du Licencié. + +9.4 Le Concédant ne garantit pas, de manière expresse ou tacite, que le +Logiciel ne porte pas atteinte à un quelconque droit de propriété +intellectuelle d'un tiers portant sur un brevet, un logiciel ou sur tout +autre droit de propriété. Ainsi, le Concédant exclut toute garantie au +profit du Licencié contre les actions en contrefaçon qui pourraient être +diligentées au titre de l'utilisation, de la modification, et de la +redistribution du Logiciel. Néanmoins, si de telles actions sont +exercées contre le Licencié, le Concédant lui apportera son aide +technique et juridique pour sa défense. Cette aide technique et +juridique est déterminée au cas par cas entre le Concédant concerné et +le Licencié dans le cadre d'un protocole d'accord. Le Concédant dégage +toute responsabilité quant à l'utilisation de la dénomination du +Logiciel par le Licencié. Aucune garantie n'est apportée quant à +l'existence de droits antérieurs sur le nom du Logiciel et sur +l'existence d'une marque. + + + Article 10 - RESILIATION + +10.1 En cas de manquement par le Licencié aux obligations mises à sa +charge par le Contrat, le Concédant pourra résilier de plein droit le +Contrat trente (30) jours après notification adressée au Licencié et +restée sans effet. + +10.2 Le Licencié dont le Contrat est résilié n'est plus autorisé à +utiliser, modifier ou distribuer le Logiciel. Cependant, toutes les +licences qu'il aura concédées antérieurement à la résiliation du Contrat +resteront valides sous réserve qu'elles aient été effectuées en +conformité avec le Contrat. + + + Article 11 - DISPOSITIONS DIVERSES + + + 11.1 CAUSE EXTERIEURE + +Aucune des Parties ne sera responsable d'un retard ou d'une défaillance +d'exécution du Contrat qui serait dû à un cas de force majeure, un cas +fortuit ou une cause extérieure, telle que, notamment, le mauvais +fonctionnement ou les interruptions du réseau électrique ou de +télécommunication, la paralysie du réseau liée à une attaque +informatique, l'intervention des autorités gouvernementales, les +catastrophes naturelles, les dégâts des eaux, les tremblements de terre, +le feu, les explosions, les grèves et les conflits sociaux, l'état de +guerre... + +11.2 Le fait, par l'une ou l'autre des Parties, d'omettre en une ou +plusieurs occasions de se prévaloir d'une ou plusieurs dispositions du +Contrat, ne pourra en aucun cas impliquer renonciation par la Partie +intéressée à s'en prévaloir ultérieurement. + +11.3 Le Contrat annule et remplace toute convention antérieure, écrite +ou orale, entre les Parties sur le même objet et constitue l'accord +entier entre les Parties sur cet objet. Aucune addition ou modification +aux termes du Contrat n'aura d'effet à l'égard des Parties à moins +d'être faite par écrit et signée par leurs représentants dûment habilités. + +11.4 Dans l'hypothèse où une ou plusieurs des dispositions du Contrat +s'avèrerait contraire à une loi ou à un texte applicable, existants ou +futurs, cette loi ou ce texte prévaudrait, et les Parties feraient les +amendements nécessaires pour se conformer à cette loi ou à ce texte. +Toutes les autres dispositions resteront en vigueur. De même, la +nullité, pour quelque raison que ce soit, d'une des dispositions du +Contrat ne saurait entraîner la nullité de l'ensemble du Contrat. + + + 11.5 LANGUE + +Le Contrat est rédigé en langue française et en langue anglaise, ces +deux versions faisant également foi. + + + Article 12 - NOUVELLES VERSIONS DU CONTRAT + +12.1 Toute personne est autorisée à copier et distribuer des copies de +ce Contrat. + +12.2 Afin d'en préserver la cohérence, le texte du Contrat est protégé +et ne peut être modifié que par les auteurs de la licence, lesquels se +réservent le droit de publier périodiquement des mises à jour ou de +nouvelles versions du Contrat, qui posséderont chacune un numéro +distinct. Ces versions ultérieures seront susceptibles de prendre en +compte de nouvelles problématiques rencontrées par les logiciels libres. + +12.3 Tout Logiciel diffusé sous une version donnée du Contrat ne pourra +faire l'objet d'une diffusion ultérieure que sous la même version du +Contrat ou une version postérieure. + + + Article 13 - LOI APPLICABLE ET COMPETENCE TERRITORIALE + +13.1 Le Contrat est régi par la loi française. Les Parties conviennent +de tenter de régler à l'amiable les différends ou litiges qui +viendraient à se produire par suite ou à l'occasion du Contrat. + +13.2 A défaut d'accord amiable dans un délai de deux (2) mois à compter +de leur survenance et sauf situation relevant d'une procédure d'urgence, +les différends ou litiges seront portés par la Partie la plus diligente +devant les Tribunaux compétents de Paris. + + +Version 1.0 du 2006-09-05. diff --git a/docs/dependency-notices/mumps_upstream-LICENSE b/docs/dependency-notices/mumps_upstream-LICENSE new file mode 100644 index 000000000..899e9ff1a --- /dev/null +++ b/docs/dependency-notices/mumps_upstream-LICENSE @@ -0,0 +1,50 @@ + + Copyright 1991-2026 CERFACS, CNRS, ENS Lyon, INP Toulouse, Inria, + Mumps Technologies, University of Bordeaux. + + This version of MUMPS is provided to you free of charge. It is + released under the CeCILL-C license + (see doc/CeCILL-C_V1-en.txt, doc/CeCILL-C_V1-fr.txt, and + https://cecill.info/licences/Licence_CeCILL-C_V1-en.html), + except for variants of AMD ordering and [sdcz]MUMPS_TRUNCATED_RRQR + derived from the LAPACK package distributed under BSD 3-clause + license (see headers of ana_orderings.F and [sdcz]lr_core.F), + and except for the external and optional ordering PORD provided + in a separate directory PORD (see PORD/README for License information). + + You can acknowledge (using references [1] and [2]) the contribution + of this package in any scientific publication dependent upon the use + of the package. Please use reasonable endeavours to notify the authors + of the package of this publication. + + [1] P. R. Amestoy, I. S. Duff, J. Koster and J.-Y. L'Excellent, + A fully asynchronous multifrontal solver using distributed dynamic + scheduling, SIAM Journal on Matrix Analysis and Applications, + Vol 23, No 1, pp 15-41 (2001). + + [2] P. R. Amestoy, A. Buttari, J.-Y. L'Excellent and T. Mary, + Performance and scalability of the block low-rank multifrontal + factorization on multicore architectures, + ACM Transactions on Mathematical Software, + Vol 45, Issue 1, pp 2:1-2:26 (2019) + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems + and/or data to be ensured and, more generally, to use and operate it + in the same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL-C license and that you accept its terms. + diff --git a/docs/qualification/ACCEPTANCE_BUDGETS.json b/docs/qualification/ACCEPTANCE_BUDGETS.json new file mode 100644 index 000000000..bc484d2c3 --- /dev/null +++ b/docs/qualification/ACCEPTANCE_BUDGETS.json @@ -0,0 +1,119 @@ +{ + "schema": "gemini.acceptance.1", + "set_on": "2026-09-17", + "baseline_commit": "220cd1e390e52a28c5ddae0343337477f41fd4b8", + "authorization": { + "source": "Latest user message in this conversation", + "text": "Please continue all work that remains incomplete with approval for the path forward and application scope and acceptance budgets.", + "meaning": "Delegation to select scope and budgets; not independent scientific or maintainer approval." + }, + "application": { + "stage": "GEMINI-only research branch qualification", + "use": "Reproducible idealized regional auroral-response experiments and numerical method development before model integration", + "quantities": [ + "all seven species densities", + "all seven temperatures", + "parallel velocities", + "electrostatic potential", + "numerical transport balances" + ], + "primary_workload": "Pinned mini2dns_fang and mini3d_fang inputs, 300 simulated seconds; strict complete 60-second electric and precipitation drivers; additional shifted-midnight copy for calendar tests", + "epoch": "20-21 February 2013 benchmark epoch; future 2026-2030 applications remain blocked on R03", + "geometry": "Existing pinned Cartesian auroral grids; no claim of IGRF field alignment", + "modes": [ + "real64", + "potsolve=1", + "flagcap=0", + "standard energy", + "FANG precipitation", + "frozen empirical neutrals", + "fixed grid", + "full output" + ], + "platform": "Linux x86-64, GNU Fortran 13.2/GCC 13.3, OpenMPI 4.1.6, one node, 1 and 2 ranks; HDF5 2.2.0 current and 1.10.10 compatibility", + "policy": "Strict coverage, stop on invalid CFL, no imputation or automatic retry; offline research use, no operational forecast or physical control", + "later_scope": [ + "observation-assimilation", + "surrogate/UQ", + "CVTWIN adapter and coupling", + "multi-node and other compilers", + "optional-mode scientific validation", + "2026-2030 production geometry" + ] + }, + "budgets": { + "native_references": { + "required_cases": 9, + "policy": "Unchanged pinned archives and existing field tolerances; zero failed, skipped or unlaunched required tests" + }, + "forcing": { + "cadence_time_atol_s": 1e-06, + "missing_required_fields": 0, + "nonfinite_values": 0, + "missing_targets": 0, + "schema": "Explicit efield or precip, disk ordering latitude x longitude; scalar categorical BC flag" + }, + "checkpoint": { + "serialization": "bitwise values at float64", + "trajectory_relative_l2": 1e-10, + "absolute_floor": { + "ns": 0.01, + "Ts": 1e-07, + "vs1": 1e-07, + "Phi": 1e-08 + }, + "norm": "RMS difference <= absolute_floor + 1e-10 * RMS continuous field; each species independently; all output frames after restart", + "atomicity": "Final .h5 name visible only after HDF5 close and successful same-directory rename; interruption leaves prior final file intact", + "rationale": "A deterministic same-build, same-layout continuation should agree within accumulated float64 roundoff. These bounds are intentionally tighter than the previously measured drift." + }, + "advection_balance": { + "normalized_residual_max": 1e-11, + "norm": "abs(sum((after-before)*cell_weight)+dt*outward_face_flux)/max(sum(abs(before)*weight),sum(abs(after)*weight),abs(dt*outward_face_flux),tiny)", + "rationale": "Conservative flux differencing must telescope to a floating-point summation budget, independent of physical model accuracy." + }, + "operator_convergence": { + "space_order_min": 1.8, + "first_order_time_min": 0.9, + "second_order_time_min": 1.8, + "levels": 3, + "source_boundary_max_abs": 1e-11 + }, + "research_physical_targets": { + "electron_density_relative_rms": 0.15, + "temperature_relative_rms": 0.1, + "parallel_velocity_rmse_m_s": 50, + "status": "Future held-out matched-regime physical-validation targets; not measured or claimed for the idealized numerical benchmark", + "rationale": "Explicit initial research targets, to be assessed alongside instrument uncertainty and representativeness; no alteration after looking at held-out results without a versioned requalification." + }, + "performance": { + "workload": "300-second mini3d_fang, 2 ranks, current workspace CPU allocation, complete I/O", + "runs": 3, + "wall_seconds_max_each": 600, + "peak_rss_mib_max_each": 2048, + "claim": "Local bounded batch workload only; three repetitions do not establish a production tail percentile" + }, + "fault_tests": { + "false_success_allowed": 0, + "required": [ + "missing forcing field", + "wrong axis layout", + "invalid BC flag", + "negative precipitation", + "partial checkpoint", + "failed atomic publish", + "incompatible runtime layout", + "changed restart input" + ] + }, + "ion_continuity": { + "normalized_residual_max": 1e-11, + "charge_fraction_max": 1e-12, + "norm": "For each ion species, delta-number minus applied chemical/ionization increment plus actual numerical face transport minus cleanup increment, scaled by largest state/source/transport/cleanup integral. Electron quasi-neutrality checked separately.", + "rationale": "Same roundoff accounting budget as the split flux check, declared before the first native full-step continuity measurement. This does not validate chemical-rate physics." + } + }, + "non_claims": [ + "Original R01-R18 program gates are preserved; this stage does not close independent physics review, hosted CI or integration work by reclassification.", + "Numerical regression and synthetic observations are not independent physical validation." + ] +} diff --git a/docs/qualification/ACCOUNTING_CONTINUATION_REVIEW.md b/docs/qualification/ACCOUNTING_CONTINUATION_REVIEW.md new file mode 100644 index 000000000..1794d1ecb --- /dev/null +++ b/docs/qualification/ACCOUNTING_CONTINUATION_REVIEW.md @@ -0,0 +1,26 @@ +# Qualification review continuation, 10 October 2026 + +The existing acceptance budgets, native comparator, and reference archives remain +unchanged. This work adds evidence checks and optional diagnostics. No scientific +gate is closed by these component changes. + +Deleting the same middle time step from every native ledger previously left all +four checkers green. The checkers now require contiguous float64 clocks, a zero +start, and the final `tdur` from the retained input configuration. Cross-ledger +coverage remains required. Clock comparisons allow only 64 float64 ULPs for +clock accumulation; no mass, charge, transport, source, or energy budget changes. + +The temperature conversion after compression enforces a 100 K lower floor but +previously recorded no addition for this stage. Optional diagnostics now record +stage 3, using actual species density for physical internal-energy capacity. +The source checker requires all seven species at each of the three standard +energy floor stages. A native activation oracle checks a known 50-to-100 K +addition over 183 m3, excludes a null cell and ghosts, and compares the complete +temperature/internal-energy arrays with diagnostics enabled and disabled. + +This does not complete R04. Individual chemistry/collision channels, coupled +kinetic/internal-energy exchanges, density/velocity cleanup and conversion +effects, independently measured conductive boundary power, and full coupled +space/time refinement remain distinct obligations. Endpoint reservoir changes +are not reclassified as conductive flux. Numerical regression does not supply +R01 maintainer acceptance or R07 independent matched-event physics validation. diff --git a/docs/qualification/APPROVED_PATH.md b/docs/qualification/APPROVED_PATH.md new file mode 100644 index 000000000..ede1aef5c --- /dev/null +++ b/docs/qualification/APPROVED_PATH.md @@ -0,0 +1,9 @@ +# Authorized path and acceptance budget + +The user delegated selection of the path, application scope and acceptance budgets on 17 September 2026. `ACCEPTANCE_BUDGETS.json` freezes those choices before the new measurements. This is project authorization, not an independent review signature. + +The immediate deliverable is a GEMINI-only research branch for reproducible regional auroral-response and numerical-method experiments. The primary workload is the archived 2013 mini2dns_fang/mini3d_fang problem, with fixed Cartesian grid, standard energy, electrostatic potential, frozen empirical neutral background and complete precipitation/electric drivers. Test 1/2 MPI ranks on one Linux node in real64. Keep all nine historical reference problems as regression gates. + +Stage A closes implementable engineering deficiencies: required forcing schemas, atomic publication, complete state for the admitted restart mode, transport accounting, numerical convergence and reproducible local workload measurements. Stage B implements and validates modern geomagnetic geometry and matched-regime independent physics evidence. Stage C admits observations/assimilation, surrogate/UQ and model integration only when their scientific prerequisites pass. Physical control is excluded from this research path under the latest scope authorization. + +All original R01-R18 obligations remain traceable. A successful Stage A is not completion of Stage B or C. Dates are deliberately historical for the numerical benchmark; no year guard is relaxed to claim 2026 production support. New physical targets are research requirements, not accuracy claims. Restart and balance budgets are roundoff-based and must not be loosened to fit the previous residuals. diff --git a/docs/qualification/CONTINUATION.md b/docs/qualification/CONTINUATION.md new file mode 100644 index 000000000..d25580915 --- /dev/null +++ b/docs/qualification/CONTINUATION.md @@ -0,0 +1,43 @@ +# Remaining-gate implementation + +The latest request authorizes implementation and evidence collection across the fourteen open applicable gates. The original eighteen-item register and its prerequisite relationships remain in force. Independent review, held-out observations and hosted execution cannot be substituted with a software test. `STAGE_B_PROTOCOL.json` records this authorization and the new component contracts; `ACCEPTANCE_BUDGETS.json` is unchanged. + +## Numerical correction and accounting + +`ETD_uncoupled` previously used `P/L*(1-exp(-L*dt))` above a small threshold and dropped the loss below it, including all negative coefficients. Near-zero cancellation also corrupted the production term. The replacement evaluates the analytic phi function by a convergent series near zero. An independent 80-digit Decimal oracle exercises 107 positive, negative, zero, threshold, equilibrium and scaled cases. The normalized error budget is 5e-14. This is a numerical solver correction, not a recalibration of reaction coefficients. + +The optional native source ledger records the aggregate production and analytically integrated loss of each frozen-coefficient ODE: six species-number, six parallel-momentum and seven internal-energy equations. Ionization production and electron external heating are separately identified within the aggregate production. Loss is integrated from the coefficients and prior state, never defined as the observed update residual. Physical cells use the existing metric-volume weights. Standard-energy temperature floors record their internal-energy additions. The checker requires every quantity/species on every step and matching MPI/continuity clocks. Transport and continuity checkers now reject missing per-step coverage that a complete earlier step could conceal. + +This advances R04 but does not finish it. Individual reactions and collision partners, pressure/electric/gravity work, conductive boundary fluxes, compression, kinetic/internal-energy conversion and complete coupled space/time refinement still require a consistent ledger. The current floor records are the explicit standard-energy diffusion/source clamps, not every possible cleanup in optional modes. No whole-plasma energy-conservation claim is made. + +## Geometry decision + +The full-grid screen evaluates the pinned Cartesian field against IGRF-14 at 2026, 2027, 2028, 2029 and 2030, using all physical cells. The existing implementation imposes a vertical -50 uT field. The proposed limits are 5% magnitude error and 1 degree direction error, fixed before this screen. A failure retains the production epoch guard. + +The implementation path is an explicitly quantified orthogonal geometry approximation or a generalization of the entire geometry/transport system. Editing only the pole epoch or field magnitude cannot establish field alignment. A new domain with an acceptable approximation must be demonstrated, not selected by hiding failed cells. Current idealized historical cases remain valid as numerical benchmarks without being presented as realistic magnetic geometry. + +## Data, observations and learned models + +`campaign.py` verifies actual file hashes, exact solver identity, all four event splits, common event/forcing/initial-state/content lineage and training-only normalization. Scientific corpus admission checks R02, R04 and R07 evidence. It deliberately remains blocked while the physics and numerical prerequisites are open. The matched-rollout evaluator requires complete shapes, finite predictions, provenance and measured runtime, and includes persistence. It does not train a surrogate or turn caller-supplied timings into a deployment certificate. + +`observation_operator.py` implements normalized radar line-of-sight quadrature for explicit ECEF velocity and look vectors, rejects invalid support, and provides a linear Gaussian analysis with Joseph-form covariance and normalized innovation diagnostics. These are building blocks. A calibrated real instrument, beam/range/time response, noise correlations, representativeness, event provenance and independent validation must still be supplied. Public AMISR data access is a source route, not an automatically matched observation of the idealized reference forcing. + +Event-level conformal calibration requires one maximum normalized rollout score per independent event. Insufficient finite order statistics, too-wide intervals, population mismatch and excursions beyond the declared training-feature envelope produce abstention. Calibration and test events must be disjoint. Exchangeability is an assumption requiring evidence; adjacent time windows are not independent events. Coverage output is empirical, not a population confidence guarantee. No model has been qualified or control enabled by these component tests. + +## Interchange and coupling + +`state_exchange.py` exports the nine supported full-output science fields from the selected Cartesian, unit-metric profile with exact stored precision, SI units, UTC, native species/axes, physical mask, native basis, coordinates and input/output hashes. It does not silently substitute the more precise restart state. The native basis is explicitly expressed in geomagnetic Cartesian coordinates; it is not mislabeled as geographic ECEF. The native filename rounds time to 10 milliseconds; the interchange checks that convention, including calendar rollover, and separately preserves the finer stored UTC hour and its exact floating-point representation. The output is an interchange record, not a runnable checkpoint. Round-trip restoration reconstructs the supported science fields, not runtime sidecars or user-defined output channels. + +Direct conversion to CVTWIN's six-channel nondimensional periodic incompressible MHD state raises an error. GEMINI's imposed magnetic background is not an evolved perturbation, and density-averaged perpendicular velocities are not every species' velocity. Required dimensional scales, closure, boundary conditions and exchanged sources are unresolved. The two codebases may share validation, provenance and data interfaces before a physical coupling exists. + +`conservative_exchange.py` implements overlap-volume remapping of Cartesian cell averages on matching domains and an exact passive two-reservoir exchange step. Manufactured tests require conserved integrals, constants, contraction and the exact stiff exchange solution. Curved metrics, masked cut cells and mismatched domain bounds are rejected. This is component verification, not a stable coupled GEMINI/CVTWIN simulation. + +## Runtime, distribution and external closure + +The current-HDF5 workflow now requests three complete verified launches in fresh cgroup v2 children with kernel memory.peak accounting, the unchanged 600 s / 2048 MiB budgets, and no sampling fallback. A host without writable delegation is reported as blocked. Charged cgroup memory includes cache/kernel allocations and is distinguished from sampled aggregate process RSS. Workflow definitions are not hosted results. + +The exact-restart profile now explicitly rejects the alternate-energy and density/potential-only executables before simulation. This closes a profile enforcement gap; it does not qualify those optional physics modes. R17 requires an explicit independent benchmark for each newly admitted mode, compiler or multi-node layout. Existing GLOW/MSIS2 goldens are regression evidence, while the separate HWM14 build remains a component/smoke profile without matched full-simulation references. + +The numeric HDF5 profile rejects virtual datasets, external raw storage, indirect paths, non-allowlisted filters and oversized declared allocations before loading payloads. Python plugin search paths are cleared for these qualification tools, and verified native launches disable plugin loading. The profile is intended for a dedicated qualification process and changes that process's HDF5 plugin policy; it is not a thread-safe policy switch for an existing shared service. Native parser isolation and a target-specific advisory/license review remain separate. + +R01 needs an actual maintainer review of the ESF floor and the new ETD correction. R07 needs an independent physics assessment and held-out matched measurements/model data. R08 needs the user-designated writable GitHub destination and successful required jobs, including leak checking on a capable host. R09 needs the distribution owner's actual inventory/notice/advisory review. Templates and hashes cannot create those approvals. diff --git a/docs/qualification/ENERGY_AND_EVIDENCE_CONTINUATION.md b/docs/qualification/ENERGY_AND_EVIDENCE_CONTINUATION.md new file mode 100644 index 000000000..5245d75a9 --- /dev/null +++ b/docs/qualification/ENERGY_AND_EVIDENCE_CONTINUATION.md @@ -0,0 +1,33 @@ +# Energy and evidence continuation - 17 September 2026 + +This continuation starts from a412224317eb57010cd4b2ed25889a1729636828. All earlier acceptance budgets and the fourteen open gates remain in force. Approval to perform the work does not substitute for independent review, actual matched observations or hosted execution. + +## Native changes + +Both 3D diffusion wrappers previously assigned only the interior of their result arrays. The caller copied the entire result into temperature, including undefined halos. The wrappers now preserve the incoming halo values explicitly. This changes no interior PDE formula or boundary type. + +Optional parabolic diagnostics expose five integrated temperature increments: linear reaction, thermal drift, conduction, explicit source and prescribed endpoint reservoir change. For backward Euler, the first four are `dt * L(Tfinal)`. For the existing half-step TR/BDF formula, eliminating the intermediate state gives `dt/3 * (L(Tinitial) + L(Tmid) + L(Tfinal))`. The conduction term is computed from the stage face differences. Endpoint values are imposed algebraically; their measured changes are labeled as boundary reservoir changes and are never described as a conductive-flux measurement. + +Compression records pressure work and artificial-viscous work separately, using the same midpoint state and divergence as the applied explicit update. The optional native energy-operator ledger integrates those terms over physical-cell volumes and records pre/post values and a separately recomputed residual. `check_energy_operators.py` requires each of seven species and both stages at every continuity time step and every rank. Missing later steps, duplicates, invalid scales and corrupt residuals fail. + +The research matrix now checks this ledger for the five admitted MPI layouts and the C++ frontend. This is additional evidence for R04. Individual reaction/collision rates, coupled kinetic/internal-energy exchange, full momentum and energy closure, and coupled three-level refinement remain separate requirements. An exact split-operator identity is not independent plasma validation. + +## Observation and uncertainty evidence + +The radar operator rejects non-Boolean/non-binary validity masks, including NaN values that NumPy otherwise converts to true. Empty observations and empty rollout arrays are rejected. Calibration coverage requires the actual unique calibration-event inventory and a nonnegative finite radius. + +`qualify_coverage` adds an exact one-sided Clopper-Pearson binomial lower confidence bound and a simultaneous width limit. Targets must be declared before the held-out evaluation. With all events covered, ten independent test events give only a 0.7411 lower bound at 95% confidence; 59 give 0.9505. This is a sample-size calculation, not a measured result for GEMINI. Event independence, target-population matching and instrument calibration cannot be verified from score arrays alone. The function uses SciPy 1.17.0 in the tested qualification environment. + +## Hosted and host evidence + +`host_capabilities.py` requires a leak-free C control to pass and an intentional 1,237-byte leak to be detected with the expected report. A LeakSanitizer runtime crash fails the capability probe. The optional cgroup probe records a blocked outcome when delegation is unavailable; it changes no mount or privilege settings. + +The hosted workflow preserves all numerical ledgers, runs the leak capability controls, and adds an unsuppressed leak-enabled native application run. Any MPI/dependency leak remains visible and must be triaged; no broad suppression or disabled leak check can close R08. + +`hosted_evidence.py` reads GitHub's API through an already authenticated `gh` client. It verifies the repository, exact candidate commit, workflow path, run attempt, mandatory jobs and mandatory steps. It does not push, dispatch a workflow, post comments or supply external approval. The report is only a hosted-execution record; required artifacts and scientific reviews remain separate. + +## Remaining hard boundaries + +The 2026-2030 geometry failure is not fixed by replacing a pole table or changing field magnitude alone. The general degree-13 IGRF field requires a coordinated basis/metric/derivative/driver treatment. No production guard has been removed, domain shrunk or acceptance budget relaxed. + +No observed event, calibration, scientific corpus, trained surrogate or physical GEMINI/CVTWIN coupling is fabricated. Their prerequisites remain visible in the root gate register. The numerical maintainer and independent scientific/distribution reviewers must authenticate acceptance records themselves. A GitHub destination is required before hosted branch results can exist. diff --git a/docs/qualification/MODEL_CARD.md b/docs/qualification/MODEL_CARD.md new file mode 100644 index 000000000..845eafa40 --- /dev/null +++ b/docs/qualification/MODEL_CARD.md @@ -0,0 +1,23 @@ +# Authorized GEMINI research model card + +Application scope and budget selection were delegated by the user's 17 September 2026 message. The concrete decisions and their provenance are in `ACCEPTANCE_BUDGETS.json` and `APPROVED_PATH.md`. This authorization is not independent scientific review. + +| Contract | Selected scope | +| --- | --- | +| Application | Reproducible idealized regional auroral response and numerical-method development before integration | +| Primary workloads | Pinned mini2dns_fang and mini3d_fang, 300 s, 20 February 2013; shifted-midnight calendar case | +| Domain | Archived idealized Cartesian grids (nominal setup 67.11 N, 212.95 E), nominal 80–1000 km; actual hashed grid coordinates define the domain. No matched radar site/event is asserted. | +| Species | O+, NO+, N2+, O2+, N+, H+, electrons; native order preserved | +| Quantities / units | Species density m^-3, temperature K, velocity m/s, potential V; numerical particle/mass/transport budgets | +| Drivers | Complete electric and precipitation HDF5 streams at declared 60 s cadence; original empirical neutral/solar configuration | +| Solver modes | real64, potsolve=1, flagcap=0, standard energy, FANG, frozen empirical neutrals, fixed grid, full output | +| Platform | Linux x86-64, GNU Fortran 13.2/GCC 13.3, OpenMPI 4.1.6, one node, 1/2 ranks; native HDF5 2.2.0 plus 1.10.10 compatibility | +| Restart | Opt-in complete-state profile, same inputs/executable/layout; duration can extend; atomic final-name publication | +| Coverage / failure | Strict spatial/time coverage; no imputation, missing-site mode or automatic retry | +| Regression | All nine pinned native cases and original comparison tolerances retained | +| Performance | Local 300 s 3D batch workload, 3 repetitions, 600 s wall and 2048 MiB resident-memory budget per run; no production percentile claim | +| Use | Offline research and branch review; physical control excluded; no operational forecast accuracy claimed | + +The 2026–2030 production geometry upgrade remains R03. Updating a pole table alone would not validate the field direction, metric/basis and forcing transforms. Keep the production guard and independent IGRF-14 oracle. Retain orthogonal meshes for Stage A; before Stage B choose either a quantified orthogonal approximation with field-error limits over the specific modern domain or a coordinated generalized geometry implementation. Do not connect the full field oracle to only one part of the geometry. + +Independent instrument/observation evaluation, optional-mode physics validation, multi-node/non-GNU support, corpus/assimilation/surrogate/UQ and CVTWIN integration remain later program gates. Initial physical-error targets in the budgets are requirements for a future matched-regime held-out study, not measured performance or confidence intervals. diff --git a/docs/qualification/NUMERICAL_ACCOUNTING.md b/docs/qualification/NUMERICAL_ACCOUNTING.md new file mode 100644 index 000000000..c805ac9e6 --- /dev/null +++ b/docs/qualification/NUMERICAL_ACCOUNTING.md @@ -0,0 +1,11 @@ +# Native numerical accounting + +Enable `GEMINI_NUMERICAL_AUDIT=1` for diagnostics. Normal solver arithmetic is unchanged: face-flux output is optional and integrals are computed separately. The research matrix enables this option and retains the CSV records. + +The native split-advection routine now returns the exact time-integrated, metric-weighted interface flux used by the finite-volume update. Every ion-density, parallel-momentum and all-seven-species internal-energy sweep records before/after integrals, the directly accumulated state increment, outward transport, local end-face contributions and a scale. Ghost and null cells are excluded; physical-to-null interfaces remain part of the control-volume boundary. Singleton axes perform no advection and return zero flux. Curved perpendicular momentum sweeps use the solver's covariant h1 weighting; they must not be represented as Cartesian physical momentum without a basis/metric conversion. The admitted Cartesian benchmarks avoid that ambiguity. + +`check_transport.py` independently recomputes residuals from the emitted increments and fluxes. When given the MPI layout, it matches common stage times, pairs internal faces with opposite outward signs and computes the global external/null-boundary residual. Each internal pair is counted once. A missing rank, missing species/axis, duplicate stage or nonfinite value cannot pass. The present pairing contract is the nonperiodic decomposition used by the research benchmarks. + +The whole-step continuity ledger records six ion equations, using actual physical volumes h1*h2*h3*dx1i*dx2i*dx3i. It accumulates the **applied** ETD chemistry/ionization increment, not an endpoint rate multiplied by dt. Density-floor and cleanup increments are a separate term. The residual is delta-number minus applied source plus outward transport minus cleanup. Multiplication by each fixed species mass gives the same normalized species-mass balance. Electron quasi-neutrality is measured separately. The native deliberate-floor test excludes a null cell and ghost storage and checks the exact known addition. The source-free periodic and curved known-boundary advection tests check conservation and three-level convergence. + +These are numerical accounting statements. Recording the applied source does not validate a reaction coefficient. All individual chemistry/collision/ionization contributions, momentum source/work terms, thermal diffusion boundary fluxes, temperature-floor energy, total kinetic/internal energy exchange and full coupled-PDE grid/time convergence still belong to R04. The reference comparisons and operator refinement tests do not replace those obligations. Geometry validation and independent observational physics validation remain separate. diff --git a/docs/qualification/README.md b/docs/qualification/README.md new file mode 100644 index 000000000..4d1f52cc5 --- /dev/null +++ b/docs/qualification/README.md @@ -0,0 +1,103 @@ +# Remaining-gate implementation update + +See [CONTINUATION.md](CONTINUATION.md) for the stable source integrator, independent source/floor ledgers, new exchange/data/observation/UQ components, stronger HDF5 input policy, optional-executable guards and kernel-memory workflow. [STAGE_B_PROTOCOL.json](STAGE_B_PROTOCOL.json) records the latest authorization and component contracts. The issued package contains actual execution evidence and the authoritative fourteen-gate status; component tests do not close independent physics or hosted-execution requirements. + +--- + +# Qualification continuation with authorized scope + +The current application/model card and predeclared budgets are `MODEL_CARD.md`, `APPROVED_PATH.md` and `ACCEPTANCE_BUDGETS.json`. The latest user message authorizes these choices; another scope/budget approval is not required. See `RESTART_CONTRACT.md` and `NUMERICAL_ACCOUNTING.md` for the implemented continuation. `remaining_work.json` preserves the full program obligations, including work beyond this research branch. + +New functionality: driver-specific required-field and axis validation; corrected Nlon reader alias; atomic HDF5 publication; opt-in full-step, input/executable/layout-bound restart; actual native face fluxes and MPI interface cancellation; whole-step ion continuity with applied sources and explicit density cleanup. Hosted CI includes the research matrix. The accompanying exact-commit verification report determines which profiles were actually executed. + +The material below documents the preceding engineering increment and its limitations **at that time**. In particular, the prior core-only/non-atomic restart description is superseded for the new opt-in profile, and the prior application-approval prerequisite is resolved by the user's authorization. + +--- + +# GEMINI qualification continuation - 17 September 2026 + +This branch contains engineering corrections and reproducible qualification tools. It is ready for branch review when the accompanying verification manifest is green. Scientific, operational and coupled-model qualification remain separate gates. The issued package contains the candidate commit, test logs, evidence hashes and all 18 remaining-work decisions. No gate is closed by changing a label or suppressing a failed test. + +## Corrections in this continuation + +- Merge upstream `9320b8912343ebd9bfb10a68c1e987f2278ff147`. Its removal of the universal density-floor override agrees with the earlier correction. Preserve explicit case configuration for ESF stabilization. +- Reject missing spatial driver coverage by default. `inputdata%coverage` retains per-target masks and `spatial_missing_count`; only explicit `&input_coverage allow_missing_spatial=.true. /` permits warned, masked zero fill. Masks are in memory, not new per-output datasets. Strict coverage is the qualified default; permitting missing sites requires an application-specific downstream mask contract. +- Reject nonfinite interpolation data and nonuniform/missing driver frames. A separate HDF5 preflight validates the entire forcing stream, timestamps, fields, shapes and links before launch. +- Preserve density, temperature, parallel velocity and full 3D potential in `/restart_core/` at float64. Validate schema, completion marker and actual dataset precision; prefer these fields to legacy analysis arrays. Existing float32 analysis fields keep their layout. A completion marker detects common partial records; it does not make writes atomic or certify every auxiliary variable. +- Keep a frozen empirical neutral background at the configured start epoch during restart. Time-updated backgrounds still use the current epoch. This corrects a regression introduced by the newly merged upstream initialization change. +- Correct the x2 boundary-gradient metric index when h2 varies across x3. A manufactured field checks both the boundary and the interior. +- Extend TRBDF2 with optional midpoint boundary values for time-varying boundary conditions, retaining existing callers' stage-constant behavior. Manufactured source and spatial/time refinement checks exercise the operator. +- Reject capacitance combinations that do not enter the implemented dynamic solver: only a 3D Cartesian domain, `potsolve=1`, and potential-gradient boundary `flagdirich=0` are accepted. Prescribed-potential, current-boundary, field-resolved and 2D capacitance combinations are unsupported. This prevents silently incomplete equations and the observed nonfinite-current failure. + +## Qualification tools + +| Tool | What it establishes | Limit | +| --- | --- | --- | +| `test/audit/diffusion_convergence.f90` | Spatial and temporal convergence; manufactured source and boundary balance | One diffusion operator, not all coupled equations | +| `scripts/qualification/budgets.py` | Volume-weighted species/mass/charge/momentum/energy and clipping arithmetic | Full solver source and face-flux instrumentation still required | +| `scripts/qualification/igrf14.py` | Independent degree-13 geocentric IGRF-14 field oracle | Does not replace the legacy grid, metric or basis transformations | +| `test/qualification/restart_core_checks.py` | Native precision/preference checks and malformed-core rejection | Complete auxiliary state and trajectory budgets remain open | +| `test/qualification/mode_experiments.py` | Native optional-mode execution and C++/Fortran consistency | Synthetic 120-second runs are not independent physical validation | +| `scripts/qualification/inventory.py` | Actual build/Python/package/model-data inventory with hashes | Run again on the deployment target; license/advisory approval is separate | +| `scripts/qualification/evaluate_gates.py` | Candidate/evidence/hash/approval-record integrity | Release owner must authenticate reviewer identity and authority | + +The gate checker requires exactly R01-R18, an exact candidate commit, existing hashed evidence, and an approval record when required. Missing gates, modified evidence, stale commits and evidence paths outside the package fail closed. A signed scope exclusion is needed to remove a gate from the proposed release; later integration items are retained instead of silently marked passed. + +## Reproduce + +Use a fresh build directory after derived-type or toolchain changes. For simultaneous or externally synchronized workspaces, set `-Dgemini3d_test_run_root=/absolute/fresh-output-root` to isolate native case outputs; the default is `build/test_runs`. This directory is reserved for CTest cases and its dated outputs are reset on each run. Install GNU C/C++/Fortran, MPI, LAPACK/BLAS/ScaLAPACK, HDF5 Fortran/HL with deflate, and Python **3.11 or newer** (qualification hashing uses `hashlib.file_digest`) with NumPy, h5py and SciPy. Hosted jobs install the pinned versions in `requirements.txt`. + +`-Dgemini3d_require_qualification=ON` requires `BUILD_TESTING=ON`, `gemini3d_BUILD_TESTING=ON` and all these Python dependencies; missing dependencies fail configuration. Import checks run again on every configure, including when the interpreter changes. The default is OFF for optional native-only builds: unavailable Python-dependent tests are not registered, which is **not complete qualification**. The `qualification-debug` and `qualification-release` configure presets require these dependencies and retain all nine pinned native cases. + +```sh +cmake -Doffline_dir=/absolute/cache -P scripts/offline_libraries.cmake +cmake -S . -B build -G Ninja -C /absolute/cache/sources.cmake \ + -DCMAKE_BUILD_TYPE=Release -Dgemini3d_realbits=64 \ + -Dgemini3d_test_simulations=ON -Dgemini3d_require_qualification=ON -DMPIEXEC_MAX_NUMPROCS=2 +cmake --build build --parallel 2 +ctest --test-dir build --output-on-failure --output-junit native.xml +python test/qualification/restart_core_checks.py --exe build/gemini.bin \ + --case build/test_runs/mini2dns_fang --work /absolute/new-restart-work +python test/qualification/mode_experiments.py --build build \ + --inputs build/test_runs/mini2dns_fang/inputs \ + --inputs3d build/test_runs/mini3d_fang/inputs --work /absolute/new-mode-work +``` + +For a current HDF5 profile, run the verified-source builder before GEMINI configuration, then supply `-DHDF5_ROOT=/absolute/hdf5-install` in a new GEMINI build directory. Its working directory must be fresh. The package includes the SHA256-verified source archive for offline use. + +```sh +cmake -Dqualification_work=/absolute/new-hdf5-work \ + -Dqualification_prefix=/absolute/hdf5-install \ + -Dsource_archive=/absolute/cache/hdf5-2.2.0.tar.gz \ + -P scripts/build_qualification_hdf5.cmake +``` + +For GNU address/undefined-behavior instrumentation use a new Debug build with `-Dgemini3d_sanitizers=ON`. Set `ASAN_OPTIONS=detect_leaks=0:halt_on_error=1` only when leak checking is deliberately excluded; this is not leak qualification. The supplied hosted workflow has a separate leak job step. External MPI/HDF5/BLAS libraries are not automatically instrumented. + +`.github/workflows/preintegration.yml` runs on pull requests, pushes and manual dispatches without excluding qualification/script changes. It runs Debug/Release native comparisons and the full research matrix, verified HDF5 2.2.0, sanitizer checks, a deliberate-leak positive control, and unsuppressed application leak checks. Artifacts bind the checked-out candidate commit, repository, run and attempt and retain hashed diagnostics even on failure. This workflow definition is not evidence of a hosted pass. + +The separate `install-smoke.yml` exercises `scripts/install-local.sh --system-deps --root PATH --jobs 2` on Ubuntu and macOS/Homebrew, and invokes `scripts/install-local.ps1` to run that installer under Windows WSL. Each installation is followed by `local_environment.py check` without shell activation. It retains the installation receipt and failure logs for the exact candidate. These jobs exercise unit/library/installed-resource checks, not the optional `--reference-tests` scope or scientific acceptance. OpenMPI oversubscription permits small four-rank correctness probes on two-slot hosts; it is not multi-node or performance evidence. + +`research_matrix.py --extended-layouts` additionally checks the four-rank 2×2 +decomposition, including every rank's source, temperature-floor and energy +operator ledgers. Both hosted native Debug and Release jobs now request this +extended matrix. It does not expand the frozen one/two-rank scientific profile +or relax its numerical budgets. + +Kernel-memory measurements require an already delegated cgroup-v2 memory controller. `GEMINI_QUALIFICATION_CGROUP` can name that parent through a repository variable; otherwise the workflow only uses `/sys/fs/cgroup` when that root is already writable and records a skip on hosted runners that lack delegation. No privilege/mount workaround or sampling substitution can produce a pass. Missing delegation, LeakSanitizer capability failure, or an MPI/dependency leak remains a failed/blocked qualification requiring a capable host and triage. + +The Cartesian remapper accepts only Boolean or integer zero/one validity masks of the source-cell shape. Floating-point, string, object and nonbinary integer masks are rejected rather than coerced to truth; any invalid/cut cell still rejects this all-covered remapping contract. + +Run each forcing stream through `validate_driver.py` with explicit start/stop/cadence before launching. Naive timestamps mean UTC. The validator rejects gaps; it does not infer cadence, impute data or approve extrapolation. + +## Supported evidence and open scope + +The core profile is Linux x86-64, real64, GNU Fortran 13.2 / GCC 13.3, OpenMPI 4.1.6, GLOW and MSIS2, two ranks on one node. HDF5 1.10.10 is retained as a compatibility baseline and HDF5 2.2.0 is the current-library profile. The nine pinned reference cases, archive hashes and comparison tolerances are unchanged. Full-output comparisons cover all seven species. + +HWM14 has unit and native C++/Fortran smoke evidence. Its entries are absent from the pinned native reference manifest, so enabling the required HWM14 reference suite intentionally fails configuration. New independently reviewed HWM14 reference data are needed; disabling that reference gate is not a fix. + +The year-dependent production pole model still supports 1920-2025. The IGRF-14 oracle is not connected to production geometry. Full IGRF field alignment can violate the existing orthogonal-grid assumptions; a coordinated metric/basis/driver design and domain-specific checks are required before 2026-2030 production use. + +Restart trajectory agreement is measured, not presumed bitwise. Neutrals/driver caches, transverse species drifts, mode-specific electrodynamic history and scheduling must be enumerated for every admitted mode. Frozen-background correction and float64 core state reduce two risks but do not prove full-state equivalence. + +Application approval, full conservation/source/flux and multi-equation convergence evidence, independent physics/observation validation, non-GNU and multi-node coverage, target hardware performance, complete advisory/license approval and hosted CI are still explicit gates. Corpus, assimilation, surrogate/UQ, physical control and coupling remain dependent on a defined application and the later integration phase. diff --git a/docs/qualification/REMAINING_WORK.md b/docs/qualification/REMAINING_WORK.md new file mode 100644 index 000000000..a03a576cc --- /dev/null +++ b/docs/qualification/REMAINING_WORK.md @@ -0,0 +1,147 @@ +# Remaining qualification work + +This file records program obligations and component progress. The issued package GATES.json and verification report determine actual candidate closure. The latest user request authorizes work across the fourteen open applicable gates; independent review and physical evidence are not waived. See CONTINUATION.md and STAGE_B_PROTOCOL.json. + +## R01 - open_with_component_progress + +Completed components: Nine original native reference cases preserved; stable ETD analytic probes and review notes added. + +Required next: Maintainer reviews both the case-specific ESF floor and stable ETD correction; approval must identify the actual branch. + +Owner: Numerical maintainer. Acceptance: Keep all nine native reference cases green with unchanged tolerances and archives. + +## R02 - closed + +Completed components: Application scope and budgets selected under the latest user authorization; see MODEL_CARD.md and ACCEPTANCE_BUDGETS.json. + +Required next: No additional scope/budget approval requested. Independent physics review remains R07. + +Owner: Project owner and plasma physicist. Acceptance: A specific ionospheric use case and quantitative acceptance budgets are signed off. + +## R03 - open_with_component_progress + +Completed components: Full-grid IGRF-14 screen added for 2026-2030, with proposed 5% magnitude / 1 degree direction limits; production epoch guard retained. + +Required next: Replace the inaccurate vertical-field approximation with a reviewed, coordinated field/basis/metric/driver formulation and validate the complete domain. + +Owner: Geomagnetic and grid specialist. Acceptance: Independent official-calculator comparison over the declared 2026-2030 domain. + +## R04 - open_with_component_progress + +Completed components: Stable ETD correction; independent aggregate number/momentum/internal-energy production and loss ledgers; explicit standard-energy temperature-floor additions; strict per-step coverage checks. + +Required next: Finish individual chemistry/collision channels, work and conductive boundary terms, all cleanup/kinetic/internal-energy accounting, and full coupled space/time refinement. + +Owner: Numerical lead. Acceptance: Predeclared mass/species/charge/momentum/energy and convergence budgets pass. + +## R05 - maintain_selected_profile_qualification + +Completed components: Strict efield/precip required-field schemas, axis ordering, categorical flags, positive precipitation, full input hashes, native coverage and declared MPI layouts are covered by the research profile. + +Required next: Maintain the unchanged scoped contract; exact-candidate execution evidence is supplied by the issued package register. + +Owner: Solver engineer. Acceptance: Missing coverage cannot become an unlabelled physical zero; tests cover target MPI layouts. + +## R06 - maintain_selected_profile_qualification + +Completed components: Atomic root publication plus rank-local full-step state; saved fluid/electric/interface arrays, dt/deadlines; reconstructed frozen backgrounds and immutable drivers. Native trajectory/fault matrix targets frozen bounds. + +Required next: Maintain the unchanged scoped contract; exact-candidate execution evidence is supplied by the issued package register. + +Owner: I/O engineer and numerical lead. Acceptance: Restart trajectories meet declared budgets; field-resolved modes have full-potential checkpoints. + +## R07 - open_with_component_progress + +Completed components: Observation and lineage tooling, unchanged physical targets, public AMISR access route and current model-validation publications reviewed. + +Required next: Independent specialist must review closures/rates and compare actual held-out matched events or independent models with calibration and uncertainty metadata. + +Owner: Independent plasma-physics reviewer. Acceptance: Independent review and held-out benchmarks meet the approved application budgets. + +## R08 - open_with_component_progress + +Completed components: Current-HDF5, native, sanitizer and standalone leak workflows retained; kernel-memory workload jobs added. + +Required next: Execute required workflows at the user-designated writable GitHub destination, including LeakSanitizer on a capable host. + +Owner: Build engineer. Acceptance: Green required hosted jobs without skipped native scenarios; sanitizer and embedding reports. + +## R09 - open_with_component_progress + +Completed components: Current inventories/notices retained; September 2026 HDF5 audit reviewed; numeric HDF5 policy rejects VDS, external storage, indirect paths, unsupported filters and excessive allocation. + +Required next: Distribution owner reviews the actual target inventory, relevant advisories and component/data notices; parser containment is a separate deployment requirement. + +Owner: Release owner. Acceptance: Approved inventory/notices/advisory record for the actual distribution. + +## R10 - open_with_component_progress + +Completed components: Event/forcing/initial-state/content lineage, artifact hashes, four nonempty splits and training-only normalization validators implemented; prerequisite admission fails closed. + +Required next: Close R04/R07 and generate the actual physical-regime corpus with complete verified metadata before scientific training. + +Owner: Data/ML engineer. Acceptance: Disjoint event/forcing splits and complete manifests. + +## R11 - open_with_component_progress + +Completed components: Masked normalized ECEF radar-LOS quadrature and Joseph-form linear analysis with innovation diagnostics implemented and analytically tested. + +Required next: Bind the operator to a calibrated actual instrument, its beam/range/time response and independent event data; validate innovations and physical budgets. + +Owner: Instrument/assimilation lead. Acceptance: Independent observation and innovation diagnostics pass. + +## R12 - open_with_component_progress + +Completed components: Complete-rollout and measured-cost benchmark evaluator with persistence and provenance requirements implemented. + +Required next: Train the specified surrogate on an admitted corpus and run fixed-budget matched numerical/simple baseline and held-out rollout comparisons. + +Owner: ML lead. Acceptance: Matched error/latency/compute and held-out rollout criteria pass. + +## R13 - open_with_component_progress + +Completed components: Independent-event conformal quantiles, held-out coverage and width/population/feature-excursion abstention implemented; insufficient finite calibration is rejected. + +Required next: Collect independent target-population calibration/test events, fix coverage and useful-width targets before evaluation, and demonstrate the targets under distribution-shift challenges. + +Owner: UQ lead. Acceptance: Coverage/width criteria pass on the target population. + +## R14 - open_with_component_progress + +Completed components: Fresh delegated-cgroup kernel memory.peak runner and three-run hosted workload job implemented, with no sampled-memory fallback. + +Required next: Run on a capable delegated host under the unchanged 600 s / 2048 MiB bounds; this local cgroup mount is read-only. + +Owner: HPC/runtime engineer. Acceptance: Tail-latency and memory budgets met under declared workload. + +## R15 - scope_excluded + +Completed components: Physical control explicitly excluded from the research-only path selected under the latest user authorization. + +Required next: No physical-control implementation or qualification in this scope; reopen if a controller is proposed. + +Owner: Systems owner. Acceptance: Application-specific physical/closed-loop evidence and independent safing review. + +## R16 - open_with_component_progress + +Completed components: Overlap-volume Cartesian conservative remap and exact passive two-reservoir exchange component tests implemented. + +Required next: Specify a physically justified two-way GEMINI/CVTWIN exchange law including reservoirs, closure and boundaries; then validate a stable coupled model benchmark. + +Owner: Coupling specialist. Acceptance: Manufactured exchange, conservation and stable coupled benchmark. + +## R17 - open_with_component_progress + +Completed components: Exact-restart admission now rejects alternate-energy and density/potential-only executables before work. Existing mode regression evidence retained. + +Required next: Supply independent optional-mode references including HWM14 full simulations, then qualify each newly admitted geometry/BC, non-GNU compiler and multi-node layout. + +Owner: Maintainer and specialist reviewers. Acceptance: Explicit supported-feature matrix and corresponding targeted validation. + +## R18 - open_with_component_progress + +Completed components: Versioned Cartesian full-output exchange schema preserves nine science fields, native precision, SI units, UTC, axes/species, mask and explicit native basis. Direct unsupported MHD6 conversion is rejected. + +Required next: Validate the agreed physical adapter after upstream scientific gates; no evolved magnetic perturbation or species-resolved perpendicular velocity may be fabricated. + +Owner: Platform engineer. Acceptance: Schema/unit/basis/mask contracts and supported-output round trips pass. diff --git a/docs/qualification/RESEARCH.md b/docs/qualification/RESEARCH.md new file mode 100644 index 000000000..45276dc44 --- /dev/null +++ b/docs/qualification/RESEARCH.md @@ -0,0 +1,45 @@ +# Research and dependency review + +Reviewed 16-17 September 2026, concentrating on the outstanding GEMINI qualification items. This is a targeted primary-source update, not a claim to have exhaustively reviewed every publication. + +| Primary source | Relevance and disposition | +| --- | --- | +| [GEMINI upstream](https://github.com/gemini3d/gemini3d) | Fetched and merged main commit 9320b8912343ebd9bfb10a68c1e987f2278ff147. Repository documentation describes orthogonal curvilinear geometry; retain that assumption when designing magnetic upgrades. | +| [NOAA/NCEI IGRF](https://www.ncei.noaa.gov/products/international-geomagnetic-reference-field) | Use official IGRF-14 coefficients and synthesis code as the independent field oracle. A degree-13 field is richer than the legacy centered-dipole pole orientation; replacing the pole table alone cannot qualify field-aligned metrics and driver transforms. | +| [Official IGRF-14 coefficients](https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt) and [Fortran routine](https://www.ngdc.noaa.gov/IAGA/vmod/igrf14.f) | Hashes and extraction provenance are committed under test/qualification/data. The independent implementation is tested over 840 geocentric cases. | +| [HDF5 2.2.0 release](https://support.hdfgroup.org/releases/hdf5/2.2.0/downloads/) | Publisher dates this release 29 July 2026. Source archive SHA256 is pinned; build uses Fortran, HL and deflate, with tools/examples disabled. This updates the tested dependency profile without claiming a complete security clearance. | +| [Ubuntu advisory](https://ubuntu.com/security/CVE-2026-19023) and [Red Hat CVE-2026-19023](https://access.redhat.com/security/cve/cve-2026-19023) | Advisory concerns h5dump variable-length string binary dumping in HDF5 before 2.1.1. Do not equate presence of an older solver library with demonstrated reachability of that utility path. Retain baseline-version triage; deploy only an approved target inventory. | +| [GNU instrumentation documentation](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html) | Supplies the address/undefined-behavior instrumentation mechanism. Local leak checking is limited by process-inspection restrictions and remains open. | +| [Huyghebaert et al., 2025](https://angeo.copernicus.org/articles/43/99/2025/angeo-43-99-2025.html) | GEMINI produces a 50 m Kelvin-Helmholtz test volume for a synthetic EISCAT_3D forward/noise/inversion experiment with regularization. This is a concrete pattern for a selected instrument operator. Synthetic reconstruction does not establish independent physical validation of this branch or the proposed application. | +| [Scalable Mesh Coupling for Atmospheric Wave Simulation, 2026 preprint](https://arxiv.org/html/2603.02971v1) | Relevant literature for a future mesh-coupling design. No coupling implementation, conservative exchange claim or validation result is imported into this GEMINI-only change. | + +The newer radar work supports implementing and testing an explicit observation operator after an instrument is selected. It does not justify using raw simulator state as if it were a direct measurement. The mesh-coupling preprint is retained for the later integration review; it does not remove the need for units, basis, masks, exchange conservation and stability checks. + +## Remaining-gate research update, 17 September 2026 + +The public GEMINI main reference was rechecked and remains `9320b8912343ebd9bfb10a68c1e987f2278ff147`. The following targeted additions inform the new components. No claim of an exhaustive literature search or external qualification is made. + +| Primary source | Compare/contrast and implemented consequence | +| --- | --- | +| [Hu and Dong, CAM-NET v4, 21 July 2026](https://arxiv.org/abs/2506.19340v4) | A geometry-aware WACCM-X emulator with spherical Fourier structure and held-out autoregressive tests. Its approximately 100 km, three-hour global representation is different from GEMINI's regional auroral grid and seconds-scale stepping. The authors distinguish emulation from observational accuracy. Adopt complete held-out rollouts and training-only normalization; do not import its reported skill as GEMINI evidence. | +| [HDF Group, 2 September 2026 audit](https://www.hdfgroup.org/2026/09/02/hdf5-beyond-the-file-findings-from-our-safety-security-and-privacy-audit/) | Risks depend on enabled features, surrounding privileges and deployment. The new qualification policy checks external storage, VDS, filter authorization and allocation bounds before payload access. It does not certify the parser or constitute a complete advisory scan. | +| [AMISR data access](https://amisr.com/amisr/links/data-access/) and [user manual](https://amisr.github.io/amisr_user_manual/src/intro.html) | Public ISR data and instrument interpretation guidance are available. Archive availability does not establish matched driving conditions, calibration/uncertainty, or independence for the idealized GEMINI cases. No mismatched observations were used to claim R07/R11 closure. | +| [Barber and Pananjady, arXiv:2510.02471](https://arxiv.org/abs/2510.02471) | Time dependence and predictor memory affect conformal coverage. Use independent event-level scores, separate calibration/test lineage and explicit exchangeability assumptions. A finite quantile and empirical coverage are insufficient to certify the target population. | +| [Linux cgroup v2 documentation](https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html) | Kernel memory.peak supports a full descendant-tree high-water measurement in a fresh delegated group. Read-only host delegation is a real capability blocker; process samples and the shared root cgroup's historical peak are not substituted. | +| [Scalable Mesh Coupling, 2026](https://arxiv.org/html/2603.02971v1) | Mesh search, coordinate transforms and exchanged atmospheric/plasma terms are useful architectural precedents. The new overlap-volume/passive-exchange tests establish only their manufactured component contracts. No physical law is inferred between periodic incompressible MHD and multi-species GEMINI. | + +The updated [continuation implementation](CONTINUATION.md) maps these choices to code, limitations and gate prerequisites. + +## Energy/evidence continuation: primary-source recheck + +The GitHub API was checked on 17 September 2026 and still returned upstream commit `9320b8912343ebd9bfb10a68c1e987f2278ff147`. No new upstream commit was merged in this continuation. + +- [HDF Group 2.2.0 release announcement](https://forum.hdfgroup.org/t/release-of-hdf5-2-2-0-newsletter-210/13861) identifies fixes for CVE-2025-9274, CVE-2026-17572 and CVE-2026-17574, and retention of the earlier CVE-2026-17573 fix. The compatibility HDF5 1.10.10 test is not a security-clearance result. These are specific publisher claims, not a complete advisory inventory or a claim about backports in a distribution package. +- [NOAA/IAGA IGRF-14](https://www.ncei.noaa.gov/products/international-geomagnetic-reference-field) remains the official field reference. It is a degree-13 main-field model; it does not supply a GEMINI-compatible orthogonal grid or storm-time external magnetic perturbations. +- [AMISR remote-access manual](https://amisr.github.io/amisr_user_manual/src/madrigal_database/madrigal_remote_access.html) documents PFISR code 61, experiment/file queries and required attribution identity for downloads. The example data are not automatically matched to the 2013 idealized forcing. No registration identity, calibration or event match was invented. +- [NIMO validation and demonstration, 2026](https://angeo.copernicus.org/articles/44/303/2026/) provides an independent-model validation precedent, not a measured error for this GEMINI branch. +- [Scalable Mesh Coupling for Atmospheric Wave Simulation](https://arxiv.org/html/2603.02971v1) couples neutral-state perturbations and plasma feedback in compatible MAGIC/GEMINI formulations. That precedent does not provide the missing exchange law or compressible neutral state for CVTWIN's existing incompressible MHD representation. +- [SciPy exact binomial interval documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats._result_classes.BinomTestResult.proportion_ci.html) documents the Clopper-Pearson method. The new UQ checker uses a one-sided exact bound; empirical coverage alone cannot close R13. +- [GitHub workflow job API](https://docs.github.com/en/rest/actions/workflow-jobs) supplies attempt-specific job and step metadata. The read-only collector requires success of named steps on the exact candidate, avoiding acceptance of stale or conditionally skipped required work. + +These updates support the implemented diagnostics and evidence checks. They do not close the outstanding scientific gates. diff --git a/docs/qualification/RESTART_CONTRACT.md b/docs/qualification/RESTART_CONTRACT.md new file mode 100644 index 000000000..7f1ce6306 --- /dev/null +++ b/docs/qualification/RESTART_CONTRACT.md @@ -0,0 +1,30 @@ +# Full-step restart contract for the authorized research profile + +Use `scripts/qualification/run_research.py --exe build/gemini.bin --case CASE --ranks 2 --layout 1 2`. The launcher validates the required electric-field/precipitation schemas and hashes all files under `inputs`; only the duration `tdur` can change for continuation. Input symlinks and driver/grid/state paths outside `inputs` are rejected. The native reader compares the input and executable SHA256 tokens, MPI layout, schema, clock and state precision. Tokens bind an audited launch; they are not authentication of a hostile caller that forges environment variables. + +Exact-runtime schema **2** binds each sidecar to its zero-based MPI rank, two-dimensional layout, input/executable hashes, dated root filename, and unique publication generation (the root's `prefix`, repeated as the sidecar's `generation`). Root metadata must also match the dated filename being opened. This allows copying an intact checkpoint set to another directory, but rejects renamed roots, exchanged rank files, and sidecars from another publication of the same checkpoint time. Schema 1 exact-runtime records lack these identities and are rejected explicitly; they must be regenerated with the current executable. This change does not alter the separate core-only format. + +`GEMINI_EXACT_RESTART=1` is opt-in. Unsupported capacitance, GLOW, evolving/file-driven neutrals, moving grid, missing spatial coverage, external solar-flux files and reduced output are rejected. Other unqualified combinations are outside the model card. The default `/restart_core` remains the compatible core-only path and does not make these stronger guarantees. The Fortran and C++ frontends call the same runtime implementation. The tested frontend must restart its own executable; a changed executable is rejected. + +| State family at the completed step | Treatment and reason | +| --- | --- | +| ns, vs1, vs2, vs3, Ts, including ghost storage | Entire rank-local fluid array saved at float64. Prior transverse drifts are needed by the next CFL calculation; ghost velocity history affects boundary/viscosity operations. | +| E1/E2/E3, J1/J2/J3, Phi | Entire rank-local electric/current/potential array saved. Full global Phi remains in the core record and restores root potential history. | +| vs1i/vs2i/vs3i | Saved interface-velocity arrays. Boundary setup reads the previous interface values before the next recomputation. | +| dt and output deadlines | Saved. The first continuation step respects the saved growth limiter and does not run the fresh-start microstep. | +| Process-local iteration counter | Reinitialized to one. It initializes MUMPS, neutral background and caches in a new process; restoring the prior count skips mandatory initialization. The prior count is retained as diagnostic metadata. | +| Neutral background and solar forcing | Reconstructed from immutable inputs at the configured original epoch for the admitted frozen empirical background. The evolved-background and GLOW cadence variants are not admitted. | +| Driver interpolation brackets | Reconstructed from the hashed complete, uniform-cadence streams at the resumed time. Midpoint evaluation proceeds through the normal driver path. Trajectory tests verify the resulting reconstruction. | +| Species momentum and internal-energy work arrays | Recomputed from saved primitives before the next advection. They are not independent state in the admitted standard-energy mode. | +| Conductivities, rates, viscosity and MUMPS workspace | Recomputed in the next native solve. Capacitance and dynamic transverse-momentum history are outside this profile. | +| Grid, species, units, modes, source data | Bound through the full input hash and executable hash; MPI rank layout must match. Cross-layout restart is rejected. | + +Before publication and before accepting restored state, all values in `fluid`, `electro`, `vi1`, `vi2`, and `vi3`, including ghost storage, must be finite. NaN and either sign of infinity are errors, not values to sanitize. The reader also requires completion metadata and rank-four float64 payloads; HDF5 reads enforce allocation shapes. Sidecar identity is checked both when loading the clock and when loading the payload. + +Each rank writes a uniquely named sidecar, closes HDF5 and atomically publishes that sidecar. After a collective barrier, root writes the full checkpoint to a reserved same-directory temporary file, adds the sidecar prefix and metadata, closes HDF5, then renames it to the dated `.h5` name. The milestone scanner never selects the temporary name. A crash before the final rename leaves the prior final checkpoint intact; orphan sidecars can remain. Keep the dated checkpoint and every sidecar it references together when copying a run. Do not delete sidecars merely because their names contain `partial`: the published root file references those immutable generation names. + +The demonstrated guarantee is atomic namespace visibility on the tested POSIX filesystem, not fsync-based power-loss durability. Windows has a platform-specific replacement implementation but is not qualified here. Identity, completion, schema, type and finite-value checks are not cryptographic payload-integrity verification: finite-valued corruption or deliberately rewritten metadata can remain undetected. No payload checksum or signature is stored. The package hashes evidence artifacts; external archival/transfer workflows should likewise retain SHA256 manifests. + +`test/qualification/research_matrix.py` requires the complete output-frame sequence and compares every saved field/species against the predeclared RMS bounds for 2D (1/2 ranks) and 3D (1 rank and both two-rank decompositions), exercises malformed state/input/layout/executable, swapped-rank, generation and nonfinite-payload rejection, and compares C++/Fortran trajectories plus a C++ self-restart. Optional `--extended-layouts` adds a four-rank 3D 2×2 regression, costing three additional simulation launches; it is outside the frozen 1/2-rank model-card scope, does not expand qualification claims, and cannot be combined with `--quick`. The result schema remains `gemini.research.matrix.1`, with an `extended_layouts` boolean recording this choice. The verified research launcher retains its 1/2-rank admission guard. Actual rank-local records must contain 35 fluid and 7 electric channels, matching the C/Fortran allocations. A sanitizer-detected over-read from stale 23-channel electric descriptors was corrected across the C wrappers. The separately shifted-midnight case checks calendar rollover. No tolerance is fitted to the measured residual. + +The focused `qualification:restart_runtime_1x2` and `qualification:restart_runtime_2x2` tests use synthetic arrays with native MPI/HDF5, including NaN/±Inf in every state family and failure before replacement of an existing root. The lightweight synthetic tests permit Open MPI oversubscription, so four real MPI processes can run on a two-core CI host. These are software-integrity tests, not research trajectory evidence. The full matrix still requires pinned `mini2dns_fang` and `mini3d_fang` fixtures (plus a runnable four-rank allocation for the extension); registering or passing the synthetic tests does not close science qualification gates. diff --git a/docs/qualification/STAGE_B_PROTOCOL.json b/docs/qualification/STAGE_B_PROTOCOL.json new file mode 100644 index 000000000..96f3fb7cb --- /dev/null +++ b/docs/qualification/STAGE_B_PROTOCOL.json @@ -0,0 +1,49 @@ +{ + "schema": "gemini.stage_b.protocol.1", + "declared_on": "2026-09-17", + "authorization": "Please continue the work on the GEMINI updates to complete all remaining 14 gates and provide the updated source code and PDF report using the same techniques and any other tools needed to complete all work.", + "meaning": "Implementation and evidence collection across the remaining gates; does not manufacture third-party approval or waive prerequisites.", + "existing_budgets": "ACCEPTANCE_BUDGETS.json unchanged", + "geometry_screen": { + "domain": "Every physical cell of the pinned mini3d_fang Cartesian grid", + "years": [2026, 2027, 2028, 2029, 2030], + "max_relative_field_magnitude_error": 0.05, + "max_field_direction_error_degrees": 1.0, + "interpretation": "Initial proposed approximation bounds, declared before screening. A failure keeps the production epoch guard; no budget is fitted to measured error. Passing this screen alone would not validate metrics or driver transforms." + }, + "source_accounting": { + "normalized_budget": 1e-11, + "etd_analytic_oracle_scaled_error": 5e-14, + "precision_digits": 80, + "scope": "Aggregate frozen-coefficient source/loss ODE and standard-energy temperature-floor ledger; whole-step energy and individual rates remain required" + }, + "interchange": { + "schema": "gemini.exchange.1", + "fields": "The nine supported full-output fields; original stored precision and explicit SI units", + "round_trip": "Bitwise identical supported fields; mask, time, species, axes and native basis checked", + "mhd6_conversion": "Rejected pending physical closure, scales, boundaries and missing magnetic/perpendicular-species state" + }, + "manufactured_exchange": { + "scope": "Complete Cartesian cell averages on identical domain bounds; no masked or curved cells", + "integral_rtol": 1e-13, + "integral_atol": 1e-14, + "passive_exchange": "Known exact two-reservoir solution, conservation and contraction from tiny to stiff time steps", + "limitations": "Does not select or validate a GEMINI/CVTWIN two-way source law" + }, + "data_and_ml": { + "scientific_corpus_prerequisites": ["R02", "R04", "R07"], + "splits": ["train", "validation", "calibration", "test"], + "independence_unit": "Physical event and forcing/initial-state lineage, not time window or mesh cell", + "normalization": "Training events only", + "surrogate": "No model trained or accuracy claim allowed before corpus admission. Complete rollout comparison with persistence, actual numerical reference, fixed errors and measured end-to-end cost.", + "uq": "One maximum normalized rollout-error score per event; insufficient finite quantile, excessive width, population mismatch or declared feature excursion causes abstention. No control enabled.", + "population_budgets": "Must be fixed for the actual selected data/instrument/population before evaluation; existing physical targets remain unchanged. Generic synthetic unit checks do not establish them." + }, + "external_evidence": { + "R01": "Actual numerical maintainer approval", + "R07": "Independent physics review and matched held-out data", + "R08": "User-designated GitHub destination with successful required workflow jobs and usable LeakSanitizer host", + "R09": "Distribution owner review of actual target inventory, notices and advisory relevance", + "R14": "Successful complete workload under a fresh delegated cgroup, three runs, original 600 s / 2048 MiB bounds" + } +} diff --git a/docs/qualification/STAGE_C_PROTOCOL.json b/docs/qualification/STAGE_C_PROTOCOL.json new file mode 100644 index 000000000..5ec1abb72 --- /dev/null +++ b/docs/qualification/STAGE_C_PROTOCOL.json @@ -0,0 +1,38 @@ +{ + "schema": "gemini.stage_c.protocol.1", + "declared_on": "2026-09-17", + "baseline_commit": "a412224317eb57010cd4b2ed25889a1729636828", + "existing_budgets": "ACCEPTANCE_BUDGETS.json and STAGE_B_PROTOCOL.json unchanged", + "energy_operators": { + "normalized_residual_max": 1e-11, + "per_step_species": 7, + "required_stages": [ + "compression", + "standard_energy_diffusion" + ], + "ranks": [ + 1, + 2 + ], + "interpretation": "Split operator accounting; prescribed endpoint changes are boundary reservoirs, not residual-defined interior sources or whole coupled energy conservation" + }, + "uq_acceptance_extension": { + "target_population": "Independent auroral events with matched calibrated observations; actual event inventory still required by R07/R10/R11", + "simultaneous_event_coverage_target": 0.95, + "one_sided_confidence": 0.95, + "full_width_cap_in_frozen_error_scales": 2.0, + "calibration_alpha": 0.05, + "test_event_min_if_all_covered": 59, + "meaning": "Targets fixed before any real held-out measurements; component fixture scores are not physical population evidence" + }, + "host_qualification": { + "leak_control": "Both clean control success and deliberate 1237-byte leak detection required", + "application_leaks": "Unsuppressed native MPI application required on a capable host", + "hosted_evidence": "Exact candidate, attempt-specific GitHub API results, mandatory job and step success; no stale runs" + }, + "non_claims": [ + "No new upstream commit since 9320b891", + "No change to production epoch guard", + "No independent approval, observed event, scientific corpus or physical coupling fabricated" + ] +} diff --git a/docs/qualification/remaining_work.json b/docs/qualification/remaining_work.json new file mode 100644 index 000000000..915de045c --- /dev/null +++ b/docs/qualification/remaining_work.json @@ -0,0 +1,220 @@ +[ + { + "id": "R01", + "status": "open_with_component_progress", + "owner": "Numerical maintainer", + "required_change": "Maintainer reviews both the case-specific ESF floor and stable ETD correction; approval must identify the actual branch.", + "acceptance": "Keep all nine native reference cases green with unchanged tolerances and archives.", + "completed": "Nine original native reference cases preserved; stable ETD analytic probes and review notes added.", + "required_inputs": [ + "Maintainer approval record" + ] + }, + { + "id": "R02", + "status": "closed", + "owner": "Project owner and plasma physicist", + "required_change": "No additional scope/budget approval requested. Independent physics review remains R07.", + "acceptance": "A specific ionospheric use case and quantitative acceptance budgets are signed off.", + "completed": "Application scope and budgets selected under the latest user authorization; see MODEL_CARD.md and ACCEPTANCE_BUDGETS.json.", + "required_inputs": [] + }, + { + "id": "R03", + "status": "open_with_component_progress", + "owner": "Geomagnetic and grid specialist", + "required_change": "Replace the inaccurate vertical-field approximation with a reviewed, coordinated field/basis/metric/driver formulation and validate the complete domain.", + "acceptance": "Independent official-calculator comparison over the declared 2026-2030 domain.", + "completed": "Full-grid IGRF-14 screen added for 2026-2030, with proposed 5% magnitude / 1 degree direction limits; production epoch guard retained.", + "required_inputs": [ + "Stage B modern application domain and field-approximation budget", + "Coordinated orthogonal approximation or generalized geometry implementation" + ] + }, + { + "id": "R04", + "status": "open_with_component_progress", + "owner": "Numerical lead", + "required_change": "Finish individual chemistry/collision channels, work and conductive boundary terms, all cleanup/kinetic/internal-energy accounting, and full coupled space/time refinement.", + "acceptance": "Predeclared mass/species/charge/momentum/energy and convergence budgets pass.", + "completed": "Stable ETD correction; independent aggregate number/momentum/internal-energy production and loss ledgers; explicit standard-energy temperature-floor additions; strict per-step coverage checks.", + "required_inputs": [ + "Full momentum/energy source and heat-flux instrumentation", + "Three-level coupled grid/time refinement", + "Independent physics review" + ] + }, + { + "id": "R05", + "status": "maintain_selected_profile_qualification", + "owner": "Solver engineer", + "required_change": "Maintain the unchanged scoped contract; exact-candidate execution evidence is supplied by the issued package register.", + "acceptance": "Missing coverage cannot become an unlabelled physical zero; tests cover target MPI layouts.", + "completed": "Strict efield/precip required-field schemas, axis ordering, categorical flags, positive precipitation, full input hashes, native coverage and declared MPI layouts are covered by the research profile.", + "required_inputs": [ + "Exact-commit research matrix" + ] + }, + { + "id": "R06", + "status": "maintain_selected_profile_qualification", + "owner": "I/O engineer and numerical lead", + "required_change": "Maintain the unchanged scoped contract; exact-candidate execution evidence is supplied by the issued package register.", + "acceptance": "Restart trajectories meet declared budgets; field-resolved modes have full-potential checkpoints.", + "completed": "Atomic root publication plus rank-local full-step state; saved fluid/electric/interface arrays, dt/deadlines; reconstructed frozen backgrounds and immutable drivers. Native trajectory/fault matrix targets frozen bounds.", + "required_inputs": [ + "Exact-commit research matrix", + "Supported filesystem semantics" + ] + }, + { + "id": "R07", + "status": "open_with_component_progress", + "owner": "Independent plasma-physics reviewer", + "required_change": "Independent specialist must review closures/rates and compare actual held-out matched events or independent models with calibration and uncertainty metadata.", + "acceptance": "Independent review and held-out benchmarks meet the approved application budgets.", + "completed": "Observation and lineage tooling, unchanged physical targets, public AMISR access route and current model-validation publications reviewed.", + "required_inputs": [ + "Independent reviewer", + "Held-out benchmark data and instrument metadata", + "R02 acceptance budgets" + ] + }, + { + "id": "R08", + "status": "open_with_component_progress", + "owner": "Build engineer", + "required_change": "Execute required workflows at the user-designated writable GitHub destination, including LeakSanitizer on a capable host.", + "acceptance": "Green required hosted jobs without skipped native scenarios; sanitizer and embedding reports.", + "completed": "Current-HDF5, native, sanitizer and standalone leak workflows retained; kernel-memory workload jobs added.", + "required_inputs": [ + "Writable GitHub destination/hosted runner execution", + "Leak-capable host" + ] + }, + { + "id": "R09", + "status": "open_with_component_progress", + "owner": "Release owner", + "required_change": "Distribution owner reviews the actual target inventory, relevant advisories and component/data notices; parser containment is a separate deployment requirement.", + "acceptance": "Approved inventory/notices/advisory record for the actual distribution.", + "completed": "Current inventories/notices retained; September 2026 HDF5 audit reviewed; numeric HDF5 policy rejects VDS, external storage, indirect paths, unsupported filters and excessive allocation.", + "required_inputs": [ + "Release-owner notice/advisory review for actual distribution" + ] + }, + { + "id": "R10", + "status": "open_with_component_progress", + "owner": "Data/ML engineer", + "required_change": "Close R04/R07 and generate the actual physical-regime corpus with complete verified metadata before scientific training.", + "acceptance": "Disjoint event/forcing splits and complete manifests.", + "completed": "Event/forcing/initial-state/content lineage, artifact hashes, four nonempty splits and training-only normalization validators implemented; prerequisite admission fails closed.", + "required_inputs": [ + "Approved events/forcing regimes", + "R02/R04/R07" + ], + "phase": "Implementation authorized by the latest fourteen-gate request; scientific admission remains dependent on the listed prerequisite evidence." + }, + { + "id": "R11", + "status": "open_with_component_progress", + "owner": "Instrument/assimilation lead", + "required_change": "Bind the operator to a calibrated actual instrument, its beam/range/time response and independent event data; validate innovations and physical budgets.", + "acceptance": "Independent observation and innovation diagnostics pass.", + "completed": "Masked normalized ECEF radar-LOS quadrature and Joseph-form linear analysis with innovation diagnostics implemented and analytically tested.", + "required_inputs": [ + "Instrument selection and calibration", + "Independent measurements", + "R02/R07" + ], + "phase": "Implementation authorized by the latest fourteen-gate request; scientific admission remains dependent on the listed prerequisite evidence." + }, + { + "id": "R12", + "status": "open_with_component_progress", + "owner": "ML lead", + "required_change": "Train the specified surrogate on an admitted corpus and run fixed-budget matched numerical/simple baseline and held-out rollout comparisons.", + "acceptance": "Matched error/latency/compute and held-out rollout criteria pass.", + "completed": "Complete-rollout and measured-cost benchmark evaluator with persistence and provenance requirements implemented.", + "required_inputs": [ + "R10 corpus", + "Surrogate design and compute budget" + ], + "phase": "Implementation authorized by the latest fourteen-gate request; scientific admission remains dependent on the listed prerequisite evidence." + }, + { + "id": "R13", + "status": "open_with_component_progress", + "owner": "UQ lead", + "required_change": "Collect independent target-population calibration/test events, fix coverage and useful-width targets before evaluation, and demonstrate the targets under distribution-shift challenges.", + "acceptance": "Coverage/width criteria pass on the target population.", + "completed": "Independent-event conformal quantiles, held-out coverage and width/population/feature-excursion abstention implemented; insufficient finite calibration is rejected.", + "required_inputs": [ + "Target population", + "R10/R12", + "Approved UQ criteria" + ], + "phase": "Implementation authorized by the latest fourteen-gate request; scientific admission remains dependent on the listed prerequisite evidence." + }, + { + "id": "R14", + "status": "open_with_component_progress", + "owner": "HPC/runtime engineer", + "required_change": "Run on a capable delegated host under the unchanged 600 s / 2048 MiB bounds; this local cgroup mount is read-only.", + "acceptance": "Tail-latency and memory budgets met under declared workload.", + "completed": "Fresh delegated-cgroup kernel memory.peak runner and three-run hosted workload job implemented, with no sampled-memory fallback.", + "required_inputs": [ + "Exact-commit performance measurements" + ] + }, + { + "id": "R15", + "status": "scope_excluded", + "owner": "Systems owner", + "required_change": "No physical-control implementation or qualification in this scope; reopen if a controller is proposed.", + "acceptance": "Application-specific physical/closed-loop evidence and independent safing review.", + "completed": "Physical control explicitly excluded from the research-only path selected under the latest user authorization.", + "required_inputs": [] + }, + { + "id": "R16", + "status": "open_with_component_progress", + "owner": "Coupling specialist", + "required_change": "Specify a physically justified two-way GEMINI/CVTWIN exchange law including reservoirs, closure and boundaries; then validate a stable coupled model benchmark.", + "acceptance": "Manufactured exchange, conservation and stable coupled benchmark.", + "completed": "Overlap-volume Cartesian conservative remap and exact passive two-reservoir exchange component tests implemented.", + "required_inputs": [ + "Approved coupled physics", + "R02/R04/R07" + ], + "phase": "Implementation authorized by the latest fourteen-gate request; scientific admission remains dependent on the listed prerequisite evidence." + }, + { + "id": "R17", + "status": "open_with_component_progress", + "owner": "Maintainer and specialist reviewers", + "required_change": "Supply independent optional-mode references including HWM14 full simulations, then qualify each newly admitted geometry/BC, non-GNU compiler and multi-node layout.", + "acceptance": "Explicit supported-feature matrix and corresponding targeted validation.", + "completed": "Exact-restart admission now rejects alternate-energy and density/potential-only executables before work. Existing mode regression evidence retained.", + "required_inputs": [ + "Reviewed HWM14 reference corpus", + "Optional-mode physical acceptance criteria", + "Selected target platform/multi-node access" + ] + }, + { + "id": "R18", + "status": "open_with_component_progress", + "owner": "Platform engineer", + "required_change": "Validate the agreed physical adapter after upstream scientific gates; no evolved magnetic perturbation or species-resolved perpendicular velocity may be fabricated.", + "acceptance": "Schema/unit/basis/mask contracts and supported-output round trips pass.", + "completed": "Versioned Cartesian full-output exchange schema preserves nine science fields, native precision, SI units, UTC, axes/species, mask and explicit native basis. Direct unsupported MHD6 conversion is rejected.", + "required_inputs": [ + "Physically specified and reviewed integration boundary", + "R02/R04/R06/R07", + "Both model audits accepted" + ], + "phase": "Implementation authorized by the latest fourteen-gate request; scientific admission remains dependent on the listed prerequisite evidence." + } +] diff --git a/docs/qualification/requirements.txt b/docs/qualification/requirements.txt new file mode 100644 index 000000000..c73b56502 --- /dev/null +++ b/docs/qualification/requirements.txt @@ -0,0 +1,5 @@ +cmake==3.31.10 +numpy==2.3.5 +h5py==3.16.0 +matplotlib==3.10.8 +scipy==1.17.0 diff --git a/include/gemini3d.h b/include/gemini3d.h index 5b7066a7b..0c14b6635 100644 --- a/include/gemini3d.h +++ b/include/gemini3d.h @@ -1,3 +1,4 @@ +// Audit modification 2026-09-16: match integer(C_INT) flag ABI #ifndef GEMINI3D_H #define GEMINI3D_H @@ -47,7 +48,7 @@ extern void read_config_in_C(struct params*, void**); extern void set_magnetic_pole_in_C(void**); extern void grid_size_in_C(void**); extern void get_fullgrid_size_C(int*, int*, int*); -extern void get_config_vars_C(void**, bool*, int*, double*, double*); +extern void get_config_vars_C(void**, int*, int*, double*, double*); extern void get_subgrid_size_C(int*, int*, int*); extern void get_species_size_C(int*); extern void get_fullgrid_lims_C(double*, double*, double*, double*, double*, double*); @@ -58,9 +59,13 @@ extern void set_start_values_auxtimevars_C(double*, double*, double*); extern void set_start_timefromcfg_C(void**, int*, double*, double*); extern void set_start_values_auxvars_C(int*, void**, double**); extern void get_cfg_timevars_C(void**,double*,int*,double*,int*,int*); +/* Initialize the configured empirical MSIS model before neutral_atmos_winds_C. + * Allocated work/grid objects and setv2v3_C (zero for fixed grids) are required. + * File-driven backgrounds instead use init_neutralBG_input_C/inputdata_perturb_C. */ extern void msisinit_C(void**); extern void init_neutralBG_input_C(void**, int*, void**, double*, double*, int*, double*, void**); extern void set_update_cadence_C(int*); +/* Refresh empirical background and aggregate it with current perturbations/drift. */ extern void neutral_atmos_winds_C(void**, int*, void**, int*, double*, void**); extern void check_finite_output_C(void**, double**, double**, double*); extern void get_solar_indices_C(void**, double*, double*); @@ -136,6 +141,7 @@ extern void pot2perpfield_C(int*, void**, double**); extern void BGfield_Lagrangian_C(void**, int*, void**, double**, void**); extern void init_neutralperturb_C(double*, void**, int*, void**, void**, int*, double*); extern void get_initial_drifts_C(void**, int*, void**, double**, double**, double**, void**); +/* Reaggregate current winds after changing perturbations or setv2v3_C; idempotent. */ extern void neutral_atmos_wind_update_C(void**); extern void neutral_perturb_C(void**, void**, int*, void**, double*, double*, int*, double*); extern void efield_perturb_C(void**, void**, int*, void**, double*, double*, int*, double*); diff --git a/options.cmake b/options.cmake index 66d741ade..599d52bd4 100644 --- a/options.cmake +++ b/options.cmake @@ -1,3 +1,4 @@ +# Audit modification 2026-09-16: declare real64 scope and explicit simulation-test gate include(GNUInstallDirs) message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION} Toolchain ${CMAKE_TOOLCHAIN_FILE}") @@ -13,6 +14,16 @@ if(host_ramGB LESS 2) endif() +if(DEFINED gemini3d_realbits AND NOT gemini3d_realbits EQUAL 64) + message(FATAL_ERROR "Audited profile requires gemini3d_realbits=64; C wrappers and density floors require separate real32 qualification.") +endif() + +option(gemini3d_test_simulations "register required reference simulations (OFF is unit-only, not release verification)" ON) + +# The frozen reference profile remains the default. This switch selects the +# proposed nonlinear time-centering update for the standard energy path. +option(gemini3d_midpoint_conduction "use experimental midpoint conductivity in standard TRBDF2 energy diffusion" OFF) + if(gemini3d_realbits EQUAL 32) message(VERBOSE " 32-bit real precision") set(gemini3d_arith s) @@ -32,6 +43,8 @@ option(gemini3d_matlab "Matlab-based self-checks") option(gemini3d_msis2 "enable MSIS2 neutral atmosphere model (must specify in config.nml as well)" on) +option(gemini3d_fail_mpif08 "Fail the build if MPI-3 Fortran module mpi_f08 is not found" ON) + # append .debug to debug libraries, because the computation speed penalty is so great set(CMAKE_DEBUG_POSTFIX .debug) @@ -44,6 +57,10 @@ file(MAKE_DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true) option(gemini3d_BUILD_TESTING "build Gemini3D tests" ${gemini3d_IS_TOP_LEVEL}) +option(gemini3d_require_qualification "require the complete Python qualification test dependencies" OFF) +if(gemini3d_require_qualification AND (NOT BUILD_TESTING OR NOT gemini3d_BUILD_TESTING)) + message(FATAL_ERROR "gemini3d_require_qualification requires BUILD_TESTING=ON and gemini3d_BUILD_TESTING=ON") +endif() if(gemini3d_IS_TOP_LEVEL AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${PROJECT_BINARY_DIR}/local") diff --git a/scripts/build_qualification_hdf5.cmake b/scripts/build_qualification_hdf5.cmake new file mode 100644 index 000000000..c69f69a83 --- /dev/null +++ b/scripts/build_qualification_hdf5.cmake @@ -0,0 +1,43 @@ +# Build the reviewed HDF5 2.2.0 profile from the publisher's SHA256-verified source. +# cmake -Dqualification_work=/tmp/hdf5-work -Dqualification_prefix=/opt/hdf5-2.2.0 +# [-Dsource_archive=/cache/hdf5-2.2.0.tar.gz] -P scripts/build_qualification_hdf5.cmake +cmake_minimum_required(VERSION 3.25) +foreach(key IN ITEMS qualification_work qualification_prefix) + if(NOT DEFINED ${key} OR NOT IS_ABSOLUTE "${${key}}") + message(FATAL_ERROR "${key} must be an explicit absolute path") + endif() +endforeach() +set(archive_sha256 1a1ab8209b35586fbc1aa279ba76d102130b95badcb20ca329587219112d8c16) +file(MAKE_DIRECTORY "${qualification_work}") +if(NOT DEFINED source_archive) + set(source_archive "${qualification_work}/hdf5-2.2.0.tar.gz") + if(NOT EXISTS "${source_archive}") + file(DOWNLOAD "https://support.hdfgroup.org/releases/hdf5/2.2.0/downloads/hdf5-2.2.0.tar.gz" + "${source_archive}" EXPECTED_HASH SHA256=${archive_sha256} TLS_VERIFY ON STATUS download_status) + list(GET download_status 0 status_code) + if(NOT status_code EQUAL 0) + message(FATAL_ERROR "HDF5 source download failed: ${download_status}") + endif() + endif() +endif() +file(SHA256 "${source_archive}" actual_sha256) +if(NOT actual_sha256 STREQUAL archive_sha256) + message(FATAL_ERROR "HDF5 source hash mismatch; refusing build") +endif() +set(source_dir "${qualification_work}/source-${archive_sha256}") +if(EXISTS "${source_dir}" OR EXISTS "${qualification_work}/build") + message(FATAL_ERROR "Use a fresh qualification_work directory; existing sources/builds are not trusted") +endif() +file(MAKE_DIRECTORY "${source_dir}") +# Extract only into a fresh tree so stale or edited files cannot enter the build. +file(ARCHIVE_EXTRACT INPUT "${source_archive}" DESTINATION "${source_dir}") +execute_process(COMMAND "${CMAKE_COMMAND}" -S "${source_dir}/hdf5-2.2.0" -B "${qualification_work}/build" + -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=${qualification_prefix}" + -DBUILD_TESTING=OFF -DBUILD_STATIC_LIBS=OFF -DBUILD_SHARED_LIBS=ON + -DHDF5_BUILD_FORTRAN=ON -DHDF5_BUILD_HL_LIB=ON -DHDF5_BUILD_CPP_LIB=OFF + -DHDF5_BUILD_TOOLS=OFF -DHDF5_BUILD_EXAMPLES=OFF + -DHDF5_ENABLE_ZLIB_SUPPORT=ON -DHDF5_ENABLE_SZIP_SUPPORT=OFF + COMMAND_ERROR_IS_FATAL ANY) +execute_process(COMMAND "${CMAKE_COMMAND}" --build "${qualification_work}/build" --parallel 2 + COMMAND_ERROR_IS_FATAL ANY) +execute_process(COMMAND "${CMAKE_COMMAND}" --install "${qualification_work}/build" COMMAND_ERROR_IS_FATAL ANY) diff --git a/scripts/debug_example.sh b/scripts/debug_example.sh new file mode 100644 index 000000000..d710b3d5e --- /dev/null +++ b/scripts/debug_example.sh @@ -0,0 +1,124 @@ +#!/bin/bash +# this is to debug simulations e.g. from gemini3d/gemini-examples repo +# +# Usage: ./debug_example.sh [cmake_opts...] +# Pass --fresh among cmake_opts to configure and build even if gemini.bin exists. +# Requires realpath and a non-Conda mpiexec on PATH. +# Uses the first non-Conda mpiexec in PATH order. +# +# Example from gemini3d/ directory: +# +# scripts/debug_example.sh ../gemini-examples/init/CI-staging/varHWM/eq/config.nml $TMPDIR/varHWM \ +# -Dgemini3d_hwm14=true +# +# to use a local package within Gemini3D for development do like +# +# scripts/debug_example.sh ../gemini-examples/init/CI-staging/varHWM/eq/config.nml $TMPDIR/varHWM \ +# -Dgemini3d_hwm14=true -DFETCHCONTENT_SOURCE_DIR_HWM14=../hwm14 + + +[[ $# -lt 2 ]] && { echo "Usage: $0 [cmake_opts...]"; exit 1; } + +mpiexec= +while IFS= read -r mpi_candidate; do + mpi_candidate=$(realpath "$mpi_candidate") || + { echo "Cannot resolve mpiexec with realpath" >&2; exit 1; } + mpi_dir=$(dirname "$mpi_candidate") + + # Conda environments have conda-meta, even when they are not activated. + while [[ "$mpi_dir" != / && ! -d "$mpi_dir/conda-meta" ]]; do + mpi_dir=$(dirname "$mpi_dir") + done + if [[ "$mpi_dir" != / ]]; then + echo "Skipping Conda mpiexec: $mpi_candidate" >&2 + continue + fi + + mpiexec=$mpi_candidate + break +done < <(type -aP mpiexec) + +[[ -n "$mpiexec" ]] || { echo "No non-Conda mpiexec found on PATH" >&2; exit 1; } + +config_nml_to_copy=$1 +simulation_output_dir=$2 +if [[ $# -ge 3 ]]; then + cmake_opts="${@:3}" +fi + +fresh=0 +for arg in "${@:3}"; do + if [[ "$arg" == --fresh ]]; then + fresh=1 + break + fi +done + +# if CMAKE_BUILD_TYPE not set in variable cmake_opts, default to Release +if [[ ! "$cmake_opts" =~ -DCMAKE_BUILD_TYPE= ]]; then + cmake_opts="-DCMAKE_BUILD_TYPE=Release $cmake_opts" +fi + +[[ -f "$config_nml_to_copy" ]] || { echo "Config NML file '$config_nml_to_copy' does not exist"; exit 1; } + +if [[ ! -d "$simulation_output_dir" ]]; then + mkdir -p "$simulation_output_dir" || { echo "Failed to create simulation output directory '$simulation_output_dir'"; exit 1; } +fi + +this_script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +builddir="$simulation_output_dir/build" + +copied_config="$simulation_output_dir/$(basename "$config_nml_to_copy")" +if [[ ! -f "$copied_config" ]] || ! diff -q -- "$config_nml_to_copy" "$copied_config" >/dev/null; then + \cp -v "$config_nml_to_copy" "$simulation_output_dir/" || { echo "Failed to copy '$config_nml_to_copy' to '$simulation_output_dir'"; exit 1; } +fi + +if [[ ! -f "$builddir/gemini.bin" ]] || (( fresh )); then + +cmake=$(command -v cmake) || { echo "CMake not found or working" >&2; exit 1; } + +$cmake -S "$this_script_dir/.." -B "$builddir" $cmake_opts || + { echo "CMake configuration failed" >&2; exit 1; } + +$cmake --build "$builddir" || + { echo "CMake build failed" >&2; exit 1; } + +fi + +case $OSTYPE in + darwin*) + Ncpu=$(sysctl -n hw.physicalcpu) + ;; + linux*) + Ncpu=$(lscpu -p=CORE,SOCKET | + awk -F, '!/^#/ { cores[$1 "," $2]=1 } + END { for (core in cores) n++; print n }') + ;; + *) + echo "Cannot determine the number of CPUs on: $OSTYPE; using 1" >&2 + Ncpu=1 + ;; +esac + +[[ $Ncpu =~ ^[1-9][0-9]*$ ]] || { + echo "Failed to determine physical CPU count" >&2 + exit 1 +} + +if [[ ! -f $simulation_output_dir/inputs/initial_conditions.h5 ]]; then + py3=$(command -v python3) || + { echo "Python not found" >&2; exit 1; } + + "$py3" -m gemini3d --help || + { echo "PyGemini not available - get it from https://github.com/gemini3d/pygemini" >&2; exit 1; } + + echo "Setting up simulation inputs in '$simulation_output_dir'..." + + GEMINI_ROOT="$builddir" "$py3" -m gemini3d.model "$copied_config" "$simulation_output_dir" || + { echo "Failed to set up simulation inputs in '$simulation_output_dir'" >&2; exit 1; } +fi + +echo "running simulation with $Ncpu MPI workers..." + +"$mpiexec" -np "$Ncpu" -wdir "$builddir" "$builddir/gemini.bin" "$simulation_output_dir" diff --git a/scripts/install-local.ps1 b/scripts/install-local.ps1 new file mode 100644 index 000000000..954fe7fcb --- /dev/null +++ b/scripts/install-local.ps1 @@ -0,0 +1,26 @@ +param( + [string]$Distribution = "Ubuntu", + [switch]$SystemDeps, + [string]$Root, + [ValidateRange(1, 2147483647)] + [int]$Jobs = 2, + [ValidateSet("Debug", "Release")] + [string]$BuildType = "Release", + [switch]$ReferenceTests, + [string]$SourceCache +) +$ErrorActionPreference = "Stop" +if (-not (Get-Command wsl.exe -ErrorAction SilentlyContinue)) { + throw "Install WSL and Ubuntu first: wsl --install -d Ubuntu" +} +$scriptPath = Join-Path $PSScriptRoot "install-local.sh" +$linuxPath = & wsl.exe --distribution $Distribution --exec wslpath -a $scriptPath +if ($LASTEXITCODE -ne 0) { throw "Cannot locate this checkout in $Distribution." } +$arguments = @("--distribution", $Distribution, "--exec", "bash", $linuxPath.Trim()) +$arguments += @("--jobs", "$Jobs", "--build-type", $BuildType) +if ($SystemDeps) { $arguments += "--system-deps" } +if ($Root) { $arguments += @("--root", $Root) } +if ($ReferenceTests) { $arguments += "--reference-tests" } +if ($SourceCache) { $arguments += @("--source-cache", $SourceCache) } +& wsl.exe @arguments +if ($LASTEXITCODE -ne 0) { throw "Local installation failed (exit $LASTEXITCODE)." } diff --git a/scripts/install-local.sh b/scripts/install-local.sh new file mode 100755 index 000000000..ab0ff3d35 --- /dev/null +++ b/scripts/install-local.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -euo pipefail +here="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +root="${here}/../build/local" +arguments=("$@") +for ((i=0; i<${#arguments[@]}; i++)); do + case "${arguments[i]}" in + --root) + ((i+=1)) + [[ $i -lt ${#arguments[@]} && -n "${arguments[i]}" ]] || { echo "--root requires a directory" >&2; exit 1; } + root="${arguments[i]}" + ;; + --root=*) root="${arguments[i]#--root=}" ;; + esac +done +case "$root" in + "~") root="$HOME" ;; + "~/"*) root="$HOME/${root:2}" ;; + "~"*) echo "Expand the --root home directory before invoking the installer." >&2; exit 1 ;; +esac +[[ -n "$root" ]] || { echo "--root requires a directory" >&2; exit 1; } + +for argument in "$@"; do + if [[ "$argument" == "--system-deps" ]]; then + # Package managers can fail after changing native libraries. + rm -f -- "${root}/environment.json" + bash "${here}/install-system-deps.sh" + break + fi +done + +python="${PYTHON:-python3}" +if [[ "$(uname -s)" == Darwin ]] && command -v brew >/dev/null; then + brew_prefix="$(brew --prefix)" + if [[ -z "${PYTHON:-}" && -x "${brew_prefix}/opt/python@3.12/bin/python3.12" ]]; then + python="${brew_prefix}/opt/python@3.12/bin/python3.12" + fi + export PATH="${brew_prefix}/bin:${PATH}" + export CMAKE_PREFIX_PATH="${brew_prefix}${CMAKE_PREFIX_PATH:+:${CMAKE_PREFIX_PATH}}" +fi +exec "$python" "${here}/local_environment.py" install "$@" diff --git a/scripts/install-system-deps.sh b/scripts/install-system-deps.sh new file mode 100755 index 000000000..953a03db3 --- /dev/null +++ b/scripts/install-system-deps.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +# System-wide prerequisites are installed only by explicit user request. +set -euo pipefail + +case "$(uname -s)" in + Linux) + if ! command -v apt-get >/dev/null; then + echo "Automatic setup supports Debian/Ubuntu (including WSL). On other Linux systems install GCC, MPI, HDF5, LAPACK/ScaLAPACK and Python 3.11+ with venv, then rerun without --system-deps." >&2 + exit 1 + fi + elevate=() + if [[ "$(id -u)" != 0 ]]; then + command -v sudo >/dev/null || { echo "sudo is required for system packages." >&2; exit 1; } + elevate=(sudo) + fi + has_cached_apt_index_set() { + local pattern + local has_package_lists=0 + local has_release_metadata=0 + for pattern in \ + "/var/lib/apt/lists/*_Packages" \ + "/var/lib/apt/lists/*_Packages.lz4" \ + "/var/lib/apt/lists/*_Packages.xz" \ + "/var/lib/apt/lists/*_Packages.gz" \ + "/var/lib/apt/lists/*_Packages.bz2" \ + "/var/lib/apt/lists/*_Packages.zst"; do + if compgen -G "$pattern" >/dev/null; then + has_package_lists=1 + break + fi + done + for pattern in \ + "/var/lib/apt/lists/*_InRelease" \ + "/var/lib/apt/lists/*_Release" \ + "/var/lib/apt/lists/*_Release.gpg"; do + if compgen -G "$pattern" >/dev/null; then + has_release_metadata=1 + break + fi + done + if [[ "$has_package_lists" -eq 0 || "$has_release_metadata" -eq 0 ]]; then + return 1 + fi + return 0 + } + run_apt_update_with_fallback() { + local -a elevate_cmd=("$@") + local -a apt_update=("${elevate_cmd[@]}" apt-get -o Acquire::Retries=3 -o APT::Update::Error-Mode=any update) + local apt_update_ok=0 + local attempt + for attempt in 1 2 3; do + if "${apt_update[@]}"; then + apt_update_ok=1 + break + fi + if [[ "$attempt" -lt 3 ]]; then + sleep "$((attempt * 5))" + fi + done + if [[ "$apt_update_ok" -eq 0 ]]; then + local allow_stale_apt_index + allow_stale_apt_index="${GEMINI_ALLOW_STALE_APT_INDEX:-0}" + allow_stale_apt_index="${allow_stale_apt_index//[[:space:]]/}" + if [[ "$allow_stale_apt_index" != 1 ]]; then + echo "apt-get update failed after retries; set GEMINI_ALLOW_STALE_APT_INDEX=1 (whitespace is ignored) to continue with existing package indexes" >&2 + return 1 + fi + if ! has_cached_apt_index_set; then + echo "apt-get update failed after retries and cached apt indexes are incomplete" >&2 + return 1 + fi + echo "warning: apt-get update failed after retries; proceeding with existing package indexes because GEMINI_ALLOW_STALE_APT_INDEX=1" >&2 + fi + } + run_apt_update_with_fallback "${elevate[@]}" + "${elevate[@]}" apt-get install -y --no-install-recommends \ + build-essential gfortran git python3 python3-venv python3-dev \ + libopenmpi-dev openmpi-bin libhdf5-dev libopenblas-dev \ + libscalapack-openmpi-dev zlib1g-dev + ;; + Darwin) + command -v brew >/dev/null || { echo "Install Homebrew from https://brew.sh first." >&2; exit 1; } + xcode-select -p >/dev/null || { echo "Run xcode-select --install first." >&2; exit 1; } + brew install gcc git python@3.12 open-mpi hdf5 openblas scalapack + ;; + *) + echo "Use Windows WSL with Ubuntu, or provision a supported Unix toolchain manually." >&2 + exit 1 + ;; +esac diff --git a/scripts/local_environment.py b/scripts/local_environment.py new file mode 100644 index 000000000..1a4b95750 --- /dev/null +++ b/scripts/local_environment.py @@ -0,0 +1,297 @@ +"""Install, verify, and run a local GEMINI environment without shell activation. + +Native package installation is explicit; running a model never downloads packages +or elevates privileges. Windows users run this inside WSL. +""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import platform +import shutil +import subprocess +import sys +import venv +import xml.etree.ElementTree as ET + + +SOURCE = Path(__file__).resolve().parents[1] +REQUIREMENTS = SOURCE / "scripts/requirements-local.txt" +MPI_ENVIRONMENT = ("LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "LD_PRELOAD", + "DYLD_INSERT_LIBRARIES", "I_MPI_ROOT", "MPI_ROOT", "MPI_HOME") +LIBRARY_TESTS = {"HDF5_standalone_C", "HDF5_standalone_Fortran", + "GeminiMPIstandalone", "GeminiMUMPSstandalone"} +REFERENCE_TESTS = { + "gemini:compare:" + name for name in ( + "mini2dns_fang", "mini2dew_fang", "mini3d_fang", "mini2dns_fang_cpp", + "mini2dns_glow", "mini2dew_glow", "mini3d_glow", "mini2dns_glow_cpp", + "mini2dns_msis2_fang", + ) +} + + +def execute(command, *, env=None, capture=False, cwd=None, check=True, result=False): + proc = subprocess.run( + [str(arg) for arg in command], check=check, env=env, cwd=cwd, + text=True, stdout=subprocess.PIPE if capture else None, + ) + return proc if result else proc.stdout + + +def digest(path): + with path.open("rb") as stream: + return hashlib.file_digest(stream, "sha256").hexdigest() + + +def paths(root): + return root / "venv/bin", root / "build", root / "install" + + +def environment(root): + bin_dir, _, prefix = paths(root) + env = os.environ.copy() + env["PATH"] = os.pathsep.join((str(bin_dir), str(prefix / "bin"), env.get("PATH", ""))) + env["VIRTUAL_ENV"] = str(root / "venv") + env.pop("PYTHONHOME", None) + env.pop("PYTHONPATH", None) + env["PYTHONNOUSERSITE"] = "1" + env["HDF5_PLUGIN_PRELOAD"] = "::" + return env + + +def native_prerequisites(env): + missing = [name for name in ("mpiexec", "mpifort", "cc", "c++") + if not shutil.which(name, path=env["PATH"])] + if missing: + raise RuntimeError("Missing native tools: " + ", ".join(missing) + + ". Run scripts/install-local.sh --system-deps or load your HPC toolchain.") + + +def python_check(bin_dir, env): + execute([bin_dir / "python", "-I", "-c", + "import sys; assert sys.version_info >= (3, 11); " + "import numpy, scipy, h5py; " + "assert h5py.h5z.filter_avail(h5py.h5z.FILTER_DEFLATE)"], env=env) + execute([bin_dir / "python", "-I", "-m", "pip", "check"], env=env) + + +def source_identity(): + try: + revision = execute(["git", "-C", SOURCE, "rev-parse", "HEAD"], capture=True).strip() + dirty = bool(execute(["git", "-C", SOURCE, "status", "--porcelain"], capture=True).strip()) + return {"revision": revision, "dirty": dirty} + except (OSError, subprocess.CalledProcessError): + return {"revision": None, "dirty": None} + + +def source_inventory(): + try: + names = execute(["git", "-C", SOURCE, "ls-files", "-z", "--cached", "--others", + "--exclude-standard", "--", "src", "app", "include", "cmake", + "test", "scripts", "CMakeLists.txt", "CMakePresets.json", "options.cmake"], + capture=True) + return {name: digest(SOURCE / name) for name in sorted(set(names.split("\0"))) + if name and (SOURCE / name).is_file() and not (SOURCE / name).is_symlink()} + except (OSError, subprocess.CalledProcessError): + return {} + + +def executable(prefix, build_type): + if build_type not in ("Debug", "Release"): + raise RuntimeError("Invalid recorded build type; rerun the installer.") + return prefix / "bin" / ("gemini.bin.debug" if build_type == "Debug" else "gemini.bin") + + +def model_resources(cache): + names = [] + if cache.get("gemini3d_msis2", "").upper() in ("ON", "TRUE", "1", "YES"): + names.append("msis21.parm") + if cache.get("gemini3d_hwm14", "").upper() in ("ON", "TRUE", "1", "YES"): + names += ["hwm123114.bin", "dwm07b104i.dat", "gd2qd.dat"] + return names + + +def verified_tests(ctest, build, env, jobs, suite, filters=(), required=()): + command = [ctest, "--test-dir", build, *filters] + inventory = json.loads(execute([*command, "--show-only=json-v1"], env=env, capture=True)) + tests = inventory["tests"] + selected = {test["name"] for test in tests} + disabled = {test["name"] for test in tests if any( + p["name"] == "DISABLED" and p["value"] for p in test.get("properties", []))} + expected = selected - disabled + if len(selected) != len(tests) or not expected: + raise RuntimeError(f"{suite}: no enabled tests or duplicate test registration") + missing = set(required) - expected + if missing: + raise RuntimeError(f"{suite}: required tests missing or disabled: " + ", ".join(sorted(missing))) + report = build / f"local-{suite}.xml" + report.unlink(missing_ok=True) + run = execute([*command, "--output-on-failure", "--no-tests=error", "--parallel", jobs, + "--output-junit", report], env=env, check=False, result=True) + cases = ET.parse(report).getroot().findall(".//testcase") + names = [case.get("name") for case in cases] + executed = {case.get("name") for case in cases + if case.find("skipped") is None and case.get("status") != "disabled"} + passed = {case.get("name") for case in cases if case.get("status") == "run" and + all(case.find(tag) is None for tag in ("failure", "error", "skipped"))} + if len(names) != len(set(names)) or set(names) != selected or executed != expected: + raise RuntimeError(f"{suite}: executed test results do not match the enabled inventory") + if run.returncode == 0 and passed != expected: + raise RuntimeError(f"{suite}: executed test results do not match the enabled inventory") + if run.returncode != 0: + raise subprocess.CalledProcessError(run.returncode, [str(arg) for arg in command]) + return {"selected": sorted(selected), "disabled": sorted(disabled), "passed": sorted(passed), + "junit": report.name, "junit_sha256": digest(report)} + + +def install(args): + root = args.root + root.mkdir(parents=True, exist_ok=True) + # Invalidate previous success before attempting an update. + record = root / "environment.json" + record.unlink(missing_ok=True) + bin_dir, build, prefix = paths(root) + if not (root / "venv/pyvenv.cfg").is_file(): + venv.EnvBuilder(with_pip=True).create(root / "venv") + env = environment(root) + native_prerequisites(env) + execute([bin_dir / "python", "-I", "-m", "pip", "install", "-r", REQUIREMENTS], env=env) + python_check(bin_dir, env) + cmake = bin_dir / "cmake" + configure = [cmake] + if args.source_cache: + configure += ["-C", args.source_cache.resolve()] + execute([*configure, "-S", SOURCE, "-B", build, "-G", "Ninja", + f"-DCMAKE_BUILD_TYPE={args.build_type}", f"-DCMAKE_INSTALL_PREFIX={prefix}", + "-DCMAKE_INSTALL_LIBDIR=lib", f"-DPython_EXECUTABLE={bin_dir / 'python'}", + "-Dgemini3d_require_qualification=ON", "-DBUILD_TESTING=ON", + "-Dgemini3d_BUILD_TESTING=ON", "-Dgemini3d_test_simulations=ON", + f"-DMPIEXEC_MAX_NUMPROCS={args.jobs}"], env=env) + execute([cmake, "--build", build, "--parallel", args.jobs], env=env) + ctest = bin_dir / "ctest" + if args.reference_tests: + results = {"reference": verified_tests(ctest, build, env, args.jobs, "reference", + required=LIBRARY_TESTS | REFERENCE_TESTS)} + else: + results = { + "libraries": verified_tests(ctest, build, env, args.jobs, "libraries", + ("-R", "^(HDF5_standalone_.*|GeminiMPIstandalone|GeminiMUMPSstandalone)$"), LIBRARY_TESTS), + "unit": verified_tests(ctest, build, env, args.jobs, "unit", ("-L", "unit")), + } + execute([cmake, "--install", build], env=env) + exe = executable(prefix, args.build_type) + # Run from the installed resource directory, not the source/build directory. + execute([exe, "-h"], env=env, cwd=prefix / "bin") + inventory = json.loads(execute([ctest, "--test-dir", build, "--show-only=json-v1"], + env=env, capture=True)) + cache = {} + for line in (build / "CMakeCache.txt").read_text().splitlines(): + if "=" in line and not line.startswith(("#", "//")): + key, value = line.split("=", 1) + name = key.split(":", 1)[0] + if name.startswith(("CMAKE_C_COMPILER", "CMAKE_CXX_COMPILER", "CMAKE_Fortran_COMPILER", + "MPI_", "MPIEXEC_", "HDF5_", "LAPACK_", "SCALAPACK_", "gemini3d_")): + cache[name] = value + launcher = Path(cache["MPIEXEC_EXECUTABLE"]) + manifest = { + "schema": "gemini.local-environment.1", "source": source_identity(), + "source_inventory_sha256": source_inventory(), + "platform": platform.platform(), "python": sys.version, + "build_type": args.build_type, "requirements_sha256": digest(REQUIREMENTS), + "native_libraries": json.loads((SOURCE / "cmake/libraries.json").read_text()), + "packages": json.loads(execute([bin_dir / "python", "-I", "-m", "pip", "list", "--format=json"], + env=env, capture=True)), + "native_configuration": cache, + "model_resources_sha256": {name: digest(prefix / "bin" / name) for name in model_resources(cache)}, + "mpi_launcher": str(launcher), "mpi_launcher_sha256": digest(launcher), + "mpi_environment": {name: env.get(name) for name in MPI_ENVIRONMENT}, + "tests": [test["name"] for test in inventory["tests"]], + "test_results": results, + "verification": "enabled-registered-tests" if args.reference_tests else "unit-tests-only", + "executable_sha256": digest(exe), + } + record.write_text(json.dumps(manifest, indent=2) + "\n") + print(f"Installed and checked: {prefix}\nEvidence: {record}") + if not args.reference_tests: + print("Unit tests passed; full reference/scientific qualification remains separate.") + + +def check(root): + record = root / "environment.json" + if not record.is_file(): + raise RuntimeError("No completed installation. Run scripts/install-local.sh first.") + saved = json.loads(record.read_text()) + if saved.get("schema") != "gemini.local-environment.1": + raise RuntimeError("Unsupported local environment record; rerun the installer.") + bin_dir, _, prefix = paths(root) + exe = executable(prefix, saved.get("build_type")) + if saved.get("requirements_sha256") != digest(REQUIREMENTS) or saved.get("executable_sha256") != digest(exe): + raise RuntimeError("Installation changed since verification; rerun the installer.") + resources = {name: digest(prefix / "bin" / name) + for name in model_resources(saved["native_configuration"])} + if resources != saved.get("model_resources_sha256"): + raise RuntimeError("Installed model resources changed; rerun the installer.") + env = environment(root) + launcher = saved.get("mpi_launcher") + current = shutil.which("mpiexec", path=env["PATH"]) + if not launcher or not current or not Path(current).samefile(launcher): + raise RuntimeError("MPI launcher changed; load the installation's MPI environment or reinstall.") + if digest(Path(launcher)) != saved.get("mpi_launcher_sha256") or \ + {name: env.get(name) for name in MPI_ENVIRONMENT} != saved.get("mpi_environment"): + raise RuntimeError("MPI runtime environment changed since verification; rerun the installer.") + python_check(bin_dir, env) + packages = json.loads(execute([bin_dir / "python", "-I", "-m", "pip", "list", "--format=json"], + env=env, capture=True)) + if packages != saved.get("packages"): + raise RuntimeError("Python packages changed since verification; rerun the installer.") + execute([exe, "-h"], env=env, cwd=prefix / "bin") + return exe, [launcher, saved["native_configuration"]["MPIEXEC_NUMPROC_FLAG"]], env + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("action", choices=("install", "check", "run")) + parser.add_argument("--root", type=Path, default=SOURCE / "build/local") + parser.add_argument("--jobs", type=int, default=2) + parser.add_argument("--build-type", choices=("Debug", "Release"), default="Release") + parser.add_argument("--reference-tests", action="store_true") + parser.add_argument("--source-cache", type=Path, + help="sources.cmake produced by scripts/offline_libraries.cmake") + parser.add_argument("--system-deps", action="store_true", + help="Handled only by install-local.sh before Python is started") + parser.add_argument("--ranks", type=int, default=1) + parser.add_argument("--case", type=Path) + arguments = list(sys.argv[1:] if argv is None else argv) + extra = [] + if "--" in arguments: + index = arguments.index("--") + arguments, extra = arguments[:index], arguments[index + 1:] + args = parser.parse_args(arguments) + args.root = args.root.expanduser().resolve() + if args.jobs < 1 or args.ranks < 1: + parser.error("--jobs and --ranks must be positive") + if args.source_cache and not args.source_cache.is_file(): + parser.error("--source-cache must be an existing CMake cache initialization file") + if args.action == "run" and (args.case is None or not args.case.is_dir()): + parser.error("run requires an existing --case directory") + if args.action != "run" and extra: + parser.error("Solver arguments after -- are only supported for run") + if sys.version_info < (3, 11): + parser.error("Python 3.11+ is required") + if os.name == "nt": + parser.error("Use install-local.ps1 and run this script inside Windows WSL") + try: + if args.action == "install": + install(args) + else: + exe, mpi, env = check(args.root) + if args.action == "run": + execute([*mpi, args.ranks, exe, args.case.resolve(), *extra], + env=env, cwd=exe.parent) + except (OSError, ValueError, RuntimeError, ET.ParseError, subprocess.CalledProcessError) as error: + parser.exit(1, f"Local environment error: {error}\n") + + +if __name__ == "__main__": + main() diff --git a/scripts/offline_libraries.cmake b/scripts/offline_libraries.cmake index fce939e3e..2fdc9d440 100644 --- a/scripts/offline_libraries.cmake +++ b/scripts/offline_libraries.cmake @@ -1,29 +1,59 @@ -# Downloads external library (e.g. MSIS, GLOW, etc.) source code to allow building offline -cmake_minimum_required(VERSION 3.21) - -include(FetchContent) - +# Prepare pinned source dependencies, including the nested MUMPS source. +# System compiler/MPI/HDF5/BLAS/LAPACK/ScaLAPACK packages and reference data are +# separate prerequisites. This script does not package a toolchain. +# Usage: cmake -Doffline_dir=/absolute/cache [-Darchive_dir=/archives] +# -P scripts/offline_libraries.cmake +cmake_minimum_required(VERSION 3.25) if(NOT DEFINED offline_dir) - set(offline_dir ${CMAKE_CURRENT_LIST_DIR}/../offline) + set(offline_dir "${CMAKE_CURRENT_LIST_DIR}/../offline") endif() - -file(MAKE_DIRECTORY "${offline_dir}") -if(NOT IS_DIRECTORY "${offline_dir}") - message(FATAL_ERROR "Failed to create offline directory: ${offline_dir}") +get_filename_component(offline_dir "${offline_dir}" ABSOLUTE) +if(NOT DEFINED archive_dir) + set(archive_dir "${offline_dir}/archives") endif() -if(NOT EXISTS "${offline_dir}/.gitignore") - file(WRITE "${offline_dir}/.gitignore" "*\n") -endif() - +file(MAKE_DIRECTORY "${offline_dir}" "${archive_dir}") +file(WRITE "${offline_dir}/.gitignore" "*\n") file(READ "${CMAKE_CURRENT_LIST_DIR}/../cmake/libraries.json" json) - -foreach(lib IN ITEMS ffilesystem glow h5fortran hwm14 msis) - string(JSON ${lib}_url GET "${json}" "${lib}") - - set(${lib}_src "${offline_dir}/${lib}-src") - - FetchContent_Populate(${lib}_source - URL ${${lib}_url} - SOURCE_DIR ${${lib}_src} - ) +set(cache "# Generated by offline_libraries.cmake; machine-local source paths.\n") +foreach(lib IN ITEMS ffilesystem glow h5fortran hwm14 msis mumps mumps_upstream) + string(JSON stem GET "${json}" "${lib}" "stem") + string(JSON archive GET "${json}" "${lib}" "archive") + string(JSON hash GET "${json}" "${lib}" "sha256") + set(local_archive "${archive_dir}/${lib}.tar.gz") + if(NOT EXISTS "${local_archive}") + file(DOWNLOAD "${stem}${archive}" "${local_archive}" EXPECTED_HASH "SHA256=${hash}" + TLS_VERIFY ON TIMEOUT 180 STATUS status) + list(GET status 0 code) + if(NOT code EQUAL 0) + message(FATAL_ERROR "${lib}: download failed: ${status}") + endif() + endif() + file(SHA256 "${local_archive}" actual_hash) + if(NOT actual_hash STREQUAL hash) + message(FATAL_ERROR "${lib}: archive SHA256 mismatch; expected ${hash}, got ${actual_hash}") + endif() + set(extracted "${offline_dir}/${lib}-${hash}") + if(NOT EXISTS "${extracted}/.complete") + file(MAKE_DIRECTORY "${extracted}") + file(ARCHIVE_EXTRACT INPUT "${local_archive}" DESTINATION "${extracted}") + file(WRITE "${extracted}/.complete" "${hash}\n") + endif() + file(GLOB children LIST_DIRECTORIES true "${extracted}/*") + set(roots) + foreach(child IN LISTS children) + if(IS_DIRECTORY "${child}") + list(APPEND roots "${child}") + endif() + endforeach() + list(LENGTH roots nroots) + if(NOT nroots EQUAL 1) + message(FATAL_ERROR "${lib}: expected one source root in verified archive") + endif() + list(GET roots 0 source) + string(TOUPPER "${lib}" upper) + string(APPEND cache "set(FETCHCONTENT_SOURCE_DIR_${upper} \"${source}\" CACHE PATH \"Verified offline source\" FORCE)\n") + message(STATUS "${lib}: verified ${hash}") endforeach() +string(APPEND cache "set(FETCHCONTENT_FULLY_DISCONNECTED ON CACHE BOOL \"Require prepared dependencies\" FORCE)\n") +file(WRITE "${offline_dir}/sources.cmake" "${cache}") +message(STATUS "Configure with -C ${offline_dir}/sources.cmake (system packages still required)") diff --git a/scripts/qualification/budgets.py b/scripts/qualification/budgets.py new file mode 100644 index 000000000..ee50fe71c --- /dev/null +++ b/scripts/qualification/budgets.py @@ -0,0 +1,72 @@ +"""Volume-weighted physical-cell budgets with explicit sources and boundaries. + +Inputs use solver order (x1,x2,x3,species), SI units, and a caller-supplied +physical mask. Singleton dimensions need an explicit physical thickness. +Output differences alone do not establish conservation: the independent +source/boundary/clipping integrals must be supplied to balance(). +""" +import numpy as np + + +def cell_volumes(h1, h2, h3, dx1, dx2, dx3, physical): + physical=np.asarray(physical) + if physical.dtype!=np.bool_ or physical.ndim!=3: + raise ValueError('physical must be an explicit three-dimensional boolean mask') + shape=physical.shape + metrics=[np.asarray(x,dtype=float) for x in (h1,h2,h3)] + widths=[np.asarray(x,dtype=float) for x in (dx1,dx2,dx3)] + if any(m.shape!=shape for m in metrics) or any(w.shape!=(shape[i],) for i,w in enumerate(widths)): + raise ValueError('Metric, mask or cell-width shape mismatch') + if any(not np.isfinite(x).all() or np.any(x<=0) for x in metrics+widths): + raise ValueError('Metrics and physical widths must be finite and positive') + v=metrics[0]*metrics[1]*metrics[2]*widths[0][:,None,None]*widths[1][None,:,None]*widths[2][None,None,:] + if not np.isfinite(v).all():raise ValueError('Volume overflow') + return np.where(physical,v,0.0) + + +def integrals(n, velocity, temperature, volume, masses, charges, gammas, kb): + n=np.asarray(n,dtype=float);v=np.asarray(velocity,dtype=float);t=np.asarray(temperature,dtype=float) + vol=np.asarray(volume,dtype=float);m=np.asarray(masses);q=np.asarray(charges);g=np.asarray(gammas) + if n.ndim!=4 or n.shape[:3]!=vol.shape or t.shape!=n.shape or v.shape!=n.shape+(3,): + raise ValueError('State/mask shape mismatch; ghost cells must be removed') + if any(a.shape!=(n.shape[-1],) for a in (m,q,g)):raise ValueError('Species metadata mismatch') + if not all(np.isfinite(a).all() for a in (vol,m,q,g)) or np.any(vol<0) or np.any(m<=0) or np.any(g<=1): + raise ValueError('Invalid metrics or species constants') + if not np.isfinite(kb) or kb<=0:raise ValueError('Invalid Boltzmann constant') + physical=vol>0 + if not all(np.isfinite(a[physical]).all() for a in (n,v,t)): + raise ValueError('Nonfinite state in physical cells') + if np.any(n[physical]<0) or np.any(t[physical]<=0):raise ValueError('Invalid physical state') + # Index first: multiplying a masked NaN by zero would still propagate NaN. + weights=vol[physical,None];ns=n[physical];vs=v[physical];ts=t[physical] + number=np.sum(weights*ns,axis=0) + momentum=np.sum(weights[:,:,None]*ns[:,:,None]*m[None,:,None]*vs,axis=0) + thermal=np.sum(weights*ns*kb*ts/(g-1),axis=0) + kinetic=np.sum(weights*ns*m*np.sum(vs**2,axis=-1)/2,axis=0) + result=dict(number=number,mass=number*m,charge=number*q,momentum=momentum,thermal=thermal,kinetic=kinetic) + if not all(np.isfinite(a).all() for a in result.values()):raise ValueError('Integral overflow') + return result + + +def clipping_budget(n, volume, floor): + n=np.asarray(n,dtype=float);volume=np.asarray(volume,dtype=float) + if n.ndim!=4 or n.shape[:3]!=volume.shape or not np.isfinite(floor) or floor<=0: + raise ValueError('Invalid clipping budget inputs') + if not np.isfinite(volume).all() or np.any(volume<0):raise ValueError('Invalid volume') + physical=volume>0 + if not np.isfinite(n[physical]).all():raise ValueError('Nonfinite physical density') + delta=np.maximum(floor-n[physical],0) + return dict(number_added=np.sum(delta*volume[physical,None],axis=0),cells_clipped=np.sum(delta>0,axis=0)) + + +def balance(before, after, source_integral, outward_boundary_integral, clipping_integral, *, atol, rtol): + # All terms are integrals over the same interval and physical control volume. + arrays=[np.asarray(a,dtype=float) for a in (before,after,source_integral,outward_boundary_integral,clipping_integral)] + if any(a.shape!=arrays[0].shape or not np.isfinite(a).all() for a in arrays): + raise ValueError('All five budget terms must have equal shape and finite values') + if not np.isfinite([atol,rtol]).all() or min(atol,rtol)<0:raise ValueError('Invalid acceptance bounds') + b,a,s,f,c=arrays + residual=a-b-s+f-c + scale=np.maximum.reduce([np.abs(x) for x in arrays]) + bound=atol+rtol*scale + return dict(residual=residual,bound=bound,passed=bool(np.all(np.abs(residual)<=bound))) diff --git a/scripts/qualification/campaign.py b/scripts/qualification/campaign.py new file mode 100644 index 000000000..bd6a60d22 --- /dev/null +++ b/scripts/qualification/campaign.py @@ -0,0 +1,155 @@ +"""Event lineage, matched rollout evaluation and conservative UQ admission. + +These components are software-tested. A synthetic test or a valid manifest is +not evidence of physical fidelity, population coverage or a trained surrogate. +""" +import hashlib +import math +from pathlib import Path +import re +import numpy as np +from evaluate_gates import evaluate + +SPLITS={'train','validation','calibration','test'} + + +def artifact(root,record): + root=Path(root).resolve();rel=Path(record['path']);p=(root/rel).resolve() + if rel.is_absolute() or not p.is_relative_to(root) or not p.is_file():raise ValueError('Invalid corpus artifact path') + with p.open('rb') as f:digest=hashlib.file_digest(f,'sha256').hexdigest() + if digest!=record['sha256']:raise ValueError('Corpus artifact hash mismatch') + return p + + +def validate_manifest(manifest,root): + if manifest.get('schema')!='gemini.corpus.1':raise ValueError('Unsupported corpus schema') + if not re.fullmatch('[0-9a-f]{40}',manifest.get('candidate_commit','')):raise ValueError('Exact solver commit required') + if not manifest.get('target_population'):raise ValueError('Target population required') + seen=set();groups={};splits=set();counts={s:0 for s in SPLITS} + for event in manifest['events']: + eid=event['id'];split=event['split'] + if not eid or eid in seen or split not in SPLITS:raise ValueError('Duplicate event or unknown split') + seen.add(eid);splits.add(split);counts[split]+=1 + if event.get('solver_commit')!=manifest['candidate_commit']:raise ValueError('Mixed solver commits') + # Parent event/forcing lineage survives crops, renamed replicas and re-runs. + for kind in ['physical_event','lineage','forcing_sha256','initial_state_sha256','data_sha256']: + value=event.get(kind) + if not isinstance(value,str) or not value:raise ValueError('Missing event identity: '+kind) + if kind.endswith('sha256') and not re.fullmatch('[0-9a-f]{64}',value):raise ValueError('Invalid SHA256') + key=(kind,value) + if key in groups and groups[key]!=split:raise ValueError('Event/forcing/content leakage across splits') + groups[key]=split + if event['artifact']['sha256']!=event['data_sha256']:raise ValueError('Inconsistent content identity') + artifact(root,event['artifact']) + for kind in ['inputs','grid','forcing','initial_state']:artifact(root,event[kind]) + if event['forcing']['sha256']!=event['forcing_sha256']:raise ValueError('Forcing identity mismatch') + if event['initial_state']['sha256']!=event['initial_state_sha256']:raise ValueError('Initial-state identity mismatch') + if splits!=SPLITS:raise ValueError('All four nonempty event splits are required') + training={e['id'] for e in manifest['events'] if e['split']=='train'} + if set(manifest.get('normalization_fit_events',[]))!=training:raise ValueError('Normalization must use training events only') + return dict(schema='gemini.corpus.check.1',passed=True,counts=counts,events=len(seen), + scope='Content and split integrity; physical validation is a separate prerequisite') + + +def admit_corpus(manifest,root,register,package_root): + result=validate_manifest(manifest,root) + if manifest['candidate_commit']!=register['candidate_commit']:raise ValueError('Corpus candidate differs from qualification') + evaluation=evaluate(register,Path(package_root)) + blockers=[g for g in evaluation['open_gates'] if g['id'] in ('R02','R04','R07')] + if blockers:raise ValueError('Scientific corpus admission blocked by '+','.join(g['id'] for g in blockers)) + return dict(**result,prerequisite_records_passed=True, + limitation='Release owner must authenticate the independent approval records; hashes do not authenticate a reviewer') + + +def rollout_metrics(truth,prediction,scale): + y=np.asarray(truth,float);p=np.asarray(prediction,float);s=np.asarray(scale,float) + if y.shape!=p.shape or y.ndim<2 or not y.size or s.shape!=(y.shape[-1],):raise ValueError('Matched nonempty full rollout/channel shapes required') + if not all(np.isfinite(x).all() for x in (y,p,s)) or np.any(s<=0):raise ValueError('Finite predictions and positive frozen scales required') + error=(p-y)/s + return dict(rms_by_channel=np.sqrt(np.mean(error**2,axis=tuple(range(y.ndim-1)))).tolist(), + trajectory_score=float(np.max(np.abs(error))),frames=y.shape[0]) + + +def matched_benchmark(truth,initial,candidates,scale,budget): + """Evaluate complete externally generated rollouts on identical targets. + + Each candidate includes prediction, end-to-end_seconds and model/data hashes; + deployment latency must be measured on the eventual target, not inferred here. + """ + y=np.asarray(truth,float);x=np.asarray(initial,float) + if x.shape!=y.shape[1:]:raise ValueError('Initial state and rollout shape mismatch') + if not candidates:raise ValueError('At least one actual candidate is required') + baseline=rollout_metrics(y,np.broadcast_to(x,y.shape),scale) + results={} + for name,item in candidates.items(): + for key in ['model_sha256','data_sha256']: + if not re.fullmatch('[0-9a-f]{64}',item.get(key,'')):raise ValueError('Candidate provenance required') + seconds=item['end_to_end_seconds'] + if not math.isfinite(seconds) or seconds<=0:raise ValueError('Measured runtime required') + m=rollout_metrics(y,item['prediction'],scale) + for key in ('normalized_rms_max','wall_seconds_max'): + value=budget.get(key) + if not isinstance(value,(float,int)) or not math.isfinite(value) or value<=0: + raise ValueError('Positive finite benchmark budgets required') + results[name]=dict(**m,end_to_end_seconds=seconds, + passed=max(m['rms_by_channel'])<=budget['normalized_rms_max'] and seconds<=budget['wall_seconds_max'], + persistence_rms_ratio=max(m['rms_by_channel'])/max(max(baseline['rms_by_channel']),1e-300)) + return dict(persistence=baseline,candidates=results,passed=all(r['passed'] for r in results.values())) + + +def conformal(scores,event_ids,alpha): + scores=np.asarray(scores,float) + if scores.ndim!=1 or len(scores)==0 or len(event_ids)!=len(scores) or len(set(event_ids))!=len(scores): + raise ValueError('One independent trajectory score per unique event is required') + if not np.isfinite(scores).all() or np.any(scores<0) or not 0hi): + raise ValueError('Finite matched shift-detection features required') + if not math.isfinite(width_cap) or width_cap<=0:raise ValueError('Positive predeclared width cap required') + reasons=[];radius=calibration['radius'] + if not math.isfinite(radius):reasons.append('insufficient_calibration') + elif radius<0:raise ValueError('Negative interval radius') + elif 2*radius>width_cap:reasons.append('interval_too_wide') + if np.any((xhi)):reasons.append('outside_training_envelope') + if not population or population!=calibrated_population:reasons.append('population_mismatch') + return dict(status='abstain' if reasons else 'eligible_for_research',reasons=reasons,control_enabled=False, + limitation='Envelope test detects only declared feature excursions; it is not a proof of no distribution shift') + + +def coverage(scores,event_ids,calibration,calibration_event_ids): + if set(event_ids)&set(calibration_event_ids):raise ValueError('Calibration/test event leakage') + x=np.asarray(scores,float) + if x.ndim!=1 or not len(x) or len(event_ids)!=len(x) or len(set(event_ids))!=len(x) or not np.isfinite(x).all() or np.any(x<0): + raise ValueError('Independent finite nonnegative test-event scores required') + if not math.isfinite(calibration['radius']) or calibration['radius']<0: + raise ValueError('Finite nonnegative interval radius required') + if len(set(calibration_event_ids))!=len(calibration_event_ids) or len(calibration_event_ids)!=calibration['events']: + raise ValueError('Calibration event inventory mismatch') + return dict(events=len(x),covered=int(np.sum(x<=calibration['radius'])), + empirical_coverage=float(np.mean(x<=calibration['radius'])),width=2*calibration['radius'], + scope='Empirical held-out event coverage; no population confidence claim') + + +def qualify_coverage(scores,event_ids,calibration,calibration_event_ids,*,coverage_target,width_cap,confidence): + """One-sided exact binomial lower bound for independent held-out events. + + Targets and confidence must be fixed before evaluating test events. This + does not establish event independence or exchangeability from arrays. + """ + from scipy.stats import beta + if not (00): + raise ValueError('Predeclared coverage, width and confidence criteria required') + result=coverage(scores,event_ids,calibration,calibration_event_ids) + k,n=result['covered'],result['events'] + lower=0. if k==0 else float(beta.ppf(1-confidence,k,n-k+1)) + return dict(**result,confidence=confidence,coverage_target=coverage_target,width_cap=width_cap, + population_coverage_lower_bound=lower,method='One-sided exact Clopper-Pearson', + passed=bool(lower>=coverage_target and result['width']<=width_cap), + assumptions='Independent held-out events from the fixed target population; no test-dependent tuning') diff --git a/scripts/qualification/check_energy_operators.py b/scripts/qualification/check_energy_operators.py new file mode 100644 index 000000000..6b02f224f --- /dev/null +++ b/scripts/qualification/check_energy_operators.py @@ -0,0 +1,65 @@ +"""Check every native compression and parabolic-energy stage and species. + +The boundary channel is the change in algebraically prescribed endpoint cells. +It is NOT mislabeled as conductive heat flux. The interior conduction channel +uses flux divergences evaluated at the actual implicit solver stages. Whole-step +coupled momentum/energy and physical closure validation remain separate gates. +Four ranks support the optional 2x2 regression, not an expanded science profile. +""" +import argparse +import json +import math +from pathlib import Path +from check_sources import rows,check_clock_inventory + +EXPECTED={(stage,s) for stage in (1,2) for s in range(1,8)} + + +def check(directory,ranks,budget=1e-11): + directory=Path(directory) + if ranks not in (1,2,4) or not math.isfinite(budget) or budget<=0: + raise ValueError('Admitted rank count and positive finite budget required') + expected={f'energy-operators-r{r:08d}.csv' for r in range(ranks)} + if {p.name for p in directory.glob('energy-operators-r*.csv')}!=expected: + raise ValueError('Energy operator rank inventory mismatch') + clocks=None;count=0;worst=0.;totals={};row_residual=0. + for rank in range(ranks): + stages={} + for r in rows(directory/f'energy-operators-r{rank:08d}.csv'): + key=(int(r['stage']),int(r['species']));clock=(r['t'],r['dt']) + if key not in EXPECTED or key in stages.setdefault(clock,set()): + raise ValueError('Unknown or duplicate energy operator stage') + stages[clock].add(key) + terms=[r[f'term{i}_J'] for i in range(1,6)] + scale=r['scale_J'];delta=r['delta_J'] + if scale<=0 or scale<(1-1e-12)*max(abs(r['before_J']),abs(r['after_J']),sum(map(abs,terms))): + raise ValueError('Invalid energy scale') + if key[0]==1 and any(terms[i]!=0 for i in (2,3,4)): + raise ValueError('Unexpected compression channels') + residual=delta-math.fsum(terms) + worst=max(worst,abs(residual)/scale,abs(r['after_J']-r['before_J']-delta)/scale) + row_residual=max(row_residual,abs(r['residual_J']-residual)/scale) + for i,value in enumerate(terms,1): + label=f'{key[0]}:{key[1]}:{i}';totals[label]=totals.get(label,0.)+value + count+=1 + if not stages or any(v!=EXPECTED for v in stages.values()): + raise ValueError('Missing energy stage/species at a time step') + these=set(stages) + if clocks is not None and these!=clocks:raise ValueError('MPI energy clocks differ') + clocks=these + continuity={(r['t'],r['dt']) for r in rows(directory/f'continuity-r{rank:08d}.csv')} + if these!=continuity:raise ValueError('Energy/continuity step inventory differs') + check_clock_inventory(directory,these) + return dict(schema='gemini.energy.operators.1',passed=max(worst,row_residual)<=budget, + ranks=ranks,rows=count,steps=len(clocks),budget=budget,max_normalized_residual=worst, + max_reported_residual_inconsistency=row_residual,integrated_channels_J=totals, + scope='Compression pressure/viscosity and implicit parabolic operator terms; algebraic endpoint reservoir changes explicit; not whole-step coupled energy conservation') + + +if __name__=='__main__': + p=argparse.ArgumentParser(description=__doc__);p.add_argument('directory',type=Path) + p.add_argument('--ranks',type=int,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args() + try:result=check(a.directory,a.ranks) + except (ValueError,KeyError,TypeError,OSError) as e:result=dict(passed=False,error=str(e)) + a.output.write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result)) + raise SystemExit(0 if result['passed'] else 1) diff --git a/scripts/qualification/check_sources.py b/scripts/qualification/check_sources.py new file mode 100644 index 000000000..dd07c522d --- /dev/null +++ b/scripts/qualification/check_sources.py @@ -0,0 +1,109 @@ +"""Validate native aggregate ETD production/loss and temperature-floor ledgers. + +No inferred residual is used as a source. This does not certify the underlying +reaction/closure physics or the still-incomplete whole-step energy balance. +Four ranks support the optional 2x2 regression, not an expanded science profile. +""" +import argparse +import csv +import json +import math +import re +from pathlib import Path + +EXPECTED={(q,s) for q in (1,2,3) for s in range(1,8 if q==3 else 7)} + + +def check_clock_inventory(directory,clocks): + """Require contiguous whole-run evidence, with float64 clock roundoff only. + + Cross-ledger agreement cannot reveal a step deleted from every file. The + admitted whole-run profile starts at zero. Its immutable configuration + supplies the final duration when present; synthetic unit fixtures may omit + it. This check changes no scientific or numerical residual budget. + """ + ordered=sorted(clocks) + if not ordered:raise ValueError('No numerical ledger clocks') + for t,dt in ordered: + if not all(math.isfinite(v) for v in (t,dt)) or t<0 or dt<=0 or t+dt<=t: + raise ValueError('Invalid numerical ledger clock') + def same(a,b): + return abs(a-b)<=64*math.ulp(max(1.,abs(a),abs(b))) + if not same(ordered[0][0],0.): + raise ValueError('Numerical ledger does not begin at zero') + for (t,dt),(next_t,_) in zip(ordered,ordered[1:]): + if not same(t+dt,next_t): + raise ValueError('Noncontiguous numerical ledger clocks') + cfg=Path(directory)/'inputs/config.nml' + if cfg.is_file(): + values=re.findall(r'(?im)^[ \t]*tdur[ \t]*=([^!\r\n]*)',cfg.read_text()) + if len(values)!=1:raise ValueError('Exactly one declared duration required') + try:stop=float(values[0].strip().removesuffix(',').strip().replace('D','e').replace('d','e')) + except ValueError as e:raise ValueError('Invalid declared duration') from e + if not math.isfinite(stop) or stop<=0:raise ValueError('Invalid declared duration') + if not same(sum(ordered[-1]),stop): + raise ValueError('Numerical ledger does not reach declared duration') + + +def rows(path): + with path.open() as stream: + for raw in csv.DictReader(stream): + row={k:float(v) for k,v in raw.items()} + if not all(math.isfinite(v) for v in row.values()):raise ValueError('Nonfinite ledger') + for key in ('quantity','species','stage'): + if key in row and row[key]!=int(row[key]):raise ValueError('Noninteger ledger identifier') + if row['dt']<=0:raise ValueError('Nonpositive time step') + yield row + + +def check(directory,ranks,budget=1e-11): + if ranks not in (1,2,4):raise ValueError('Unsupported regression rank count') + expected_files={f'sources-r{r:08d}.csv' for r in range(ranks)} + if {p.name for p in directory.glob('sources-r*.csv')}!=expected_files: + raise ValueError('Incomplete or unexpected source rank inventory') + count=0;worst=0.;worst_state=0.;common=None;floors={};floor_rows=0 + for rank in range(ranks): + stages={} + for row in rows(directory/f'sources-r{rank:08d}.csv'): + clock=(row['t'],row['dt']);key=(int(row['quantity']),int(row['species'])) + if key in stages.setdefault(clock,set()):raise ValueError('Duplicate source stage') + stages[clock].add(key) + # The native scale integrates absolute state. It must at least + # dominate the absolute signed integrals it claims to normalize. + scale=row['scale'] + lower=max(abs(row[k]) for k in ('before','after','production','integrated_loss')) + if scale<=0 or scale<(1-1e-12)*lower:raise ValueError('Invalid source scale') + worst=max(worst,abs(row['delta']-row['production']+row['integrated_loss'])/scale) + worst_state=max(worst_state,abs(row['after']-row['before']-row['delta'])/scale) + count+=1 + if not stages or any(s!=EXPECTED for s in stages.values()): + raise ValueError('Missing quantity/species at one or more source steps') + clocks=set(stages) + if common is not None and clocks!=common:raise ValueError('MPI source clocks do not match') + common=clocks + continuity={(r['t'],r['dt']) for r in rows(directory/f'continuity-r{rank:08d}.csv')} + if clocks!=continuity:raise ValueError('Source/continuity steps do not match') + check_clock_inventory(directory,clocks) + seen=set() + for row in rows(directory/f'temperature-floor-r{rank:08d}.csv'): + clock=(row['t'],row['dt']);key=(*clock,int(row['stage']),int(row['species'])) + if key in seen or clock not in clocks:raise ValueError('Duplicate or unknown temperature floor step') + if row['energy_added_J']<0:raise ValueError('Negative energy attributed to a lower floor') + seen.add(key);label=f"{int(row['stage'])}:{int(row['species'])}" + floors[label]=floors.get(label,0.)+row['energy_added_J'];floor_rows+=1 + expected={(*clock,stage,s) for clock in clocks for stage in (1,2,3) for s in range(1,8)} + if seen!=expected:raise ValueError('Missing standard-energy temperature-floor stages') + return dict(schema='gemini.native.sources.1',passed=max(worst,worst_state)<=budget, + ranks=ranks,rows=count,steps=len(common),budget=budget,max_normalized_residual=worst, + max_state_delta_inconsistency=worst_state,temperature_floor_rows=floor_rows, + temperature_floor_energy_J=floors, + scope='Frozen-coefficient aggregate production/loss ODEs and explicit standard-energy floors; not full coupled energy conservation or reaction-rate validation') + + +if __name__=='__main__': + p=argparse.ArgumentParser(description=__doc__);p.add_argument('directory',type=Path) + p.add_argument('--ranks',type=int,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args() + try:result=check(a.directory,a.ranks) + except (ValueError,KeyError,OSError,TypeError) as e:result=dict(passed=False,error=str(e)) + a.output.write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result)) + raise SystemExit(0 if result['passed'] else 1) diff --git a/scripts/qualification/check_transport.py b/scripts/qualification/check_transport.py new file mode 100644 index 000000000..e83d0ad78 --- /dev/null +++ b/scripts/qualification/check_transport.py @@ -0,0 +1,117 @@ +"""Check measured physical-cell transport balances; do not infer unknown sources. + +Quantity: 1 species number, 2 parallel momentum (covariant weighting in curved +perpendicular sweeps), 3 internal energy. Null cells and ghosts are excluded. +min_face/max_face include MPI subdomain faces; they are not global boundaries. +Requires the independently recorded continuity ledger for the step inventory. +""" +import argparse +import csv +import json +from pathlib import Path +import math +from check_sources import rows as ledger_rows,check_clock_inventory + + +def check(directory,budget=1e-11,layout=None): + if not math.isfinite(budget) or budget<=0: + raise ValueError('Positive finite transport budget required') + files=sorted(directory.glob('transport-r*.csv')) + if not files:raise ValueError('No native transport evidence') + count=0;worst=0;coverage=set();worst_row=None;by_rank={} + for path in files: + rank=int(path.stem.split("-r")[1]) + if rank in by_rank:raise ValueError('Duplicate transport rank') + by_rank[rank]={} + with path.open() as f: + for row in csv.DictReader(f): + r={k:float(v) for k,v in row.items()} + if not all(math.isfinite(v) for v in r.values()):raise ValueError('Nonfinite budget row') + if r['dt']<=0 or r['scale']<=0:raise ValueError('Nonpositive time/scale') + if r['scale']<(1-1e-12)*max(abs(r['before']),abs(r['after'])): + raise ValueError('Invalid transport scale') + if any(r[k]!=int(r[k]) for k in ('quantity','species','axis')):raise ValueError('Noninteger stage identifier') + scale=max(r['scale'],abs(r['outward']),2.2250738585072014e-308) + # Recompute using independently recorded state change and actual face transport. + residual=max(abs(r['delta']+r['outward']), + abs(r['after']-r['before']-r['delta']))/scale + if residual>worst:worst=residual;worst_row={'file':path.name,'t':r['t'],'quantity':r['quantity'],'species':r['species'],'axis':r['axis']} + key=(r['t'],r['dt'],int(r['quantity']),int(r['species']),int(r['axis'])) + if key in by_rank[rank]:raise ValueError('Duplicate native transport stage') + by_rank[rank][key]=r + coverage.add(key[2:]) + count+=1 + expected={(q,s,a) for q in (1,2,3) for s in range(1,8 if q==3 else 7) for a in (1,2,3)} + complete=True + for rank,data in by_rank.items(): + clocks={key[:2] for key in data} + # A whole missing clock leaves each surviving clock internally complete. + # Use the separately recorded whole-step ledger as the clock inventory. + continuity={(r['t'],r['dt']) for r in ledger_rows(directory/f'continuity-r{rank:08d}.csv')} + if clocks!=continuity: + raise ValueError('Transport/continuity step inventory differs') + check_clock_inventory(directory,clocks) + complete=complete and bool(clocks) and all({key[2:] for key in data if key[:2]==clock}==expected for clock in clocks) + paired=None;global_worst=None;interfaces=0 + if layout is not None: + l2,l3=layout + if l2*l3!=len(files) or set(by_rank)!=set(range(l2*l3)): + raise ValueError('MPI rank inventory differs from declared layout') + stages=set(by_rank[0]) + if any(set(rows)!=stages for rows in by_rank.values()):raise ValueError('MPI stages/times do not match') + paired=0.;global_worst=0. + for key in stages: + axis=key[-1];rows=[by_rank[rank][key] for rank in range(l2*l3)] + scale=max(sum(r['scale'] for r in rows),2.2250738585072014e-308) + outer=0.;cutout=sum(r['outward']-r['min_face']-r['max_face'] for r in rows) + for rank,r in enumerate(rows): + i2=rank%l2;i3=rank//l2 + i,extent=(0,1) if axis==1 else ((i2,l2) if axis==2 else (i3,l3)) + if i==0:outer+=r['min_face'] + if i==extent-1:outer+=r['max_face'] + if i0 and complete and coverage==expected and worst<=budget and + (paired is None or max(paired,global_worst)<=budget), + layout=layout,interface_pairs=interfaces,max_interface_mismatch=paired,max_global_residual=global_worst, + rank_files=len(files),rows=count,per_step_coverage_complete=complete,max_normalized_residual=worst,budget=budget,worst=worst_row, + coverage=[list(x) for x in sorted(coverage)],missing_coverage=[list(x) for x in sorted(expected-coverage)], + scope='Native split-advection balance with physical/null boundaries; MPI interfaces paired when layout is supplied. Full coupled source and energy conservation is separate.') +def check_continuity(directory,budget=1e-11,charge_budget=1e-12): + files=sorted(directory.glob('continuity-r*.csv')) + if not files:raise ValueError('No native full-step continuity evidence') + rows=0;worst=0;charge=0;cleanup={str(s):0. for s in range(1,7)};coverage=set();by_rank={} + for path in files: + rank=int(path.stem.split('-r')[1]) + if rank in by_rank:raise ValueError('Duplicate continuity rank') + by_rank[rank]={} + with path.open() as f: + for row in csv.DictReader(f): + r={k:float(v) for k,v in row.items()} + if not all(math.isfinite(v) for v in r.values()):raise ValueError('Nonfinite continuity evidence') + if r['scale']<=0:raise ValueError('Nonpositive continuity scale') + if r['dt']<=0 or r['charge_fraction']<0:raise ValueError('Invalid continuity time/charge') + species=int(r['species']) + if species!=r['species'] or species not in range(1,7):raise ValueError('Invalid ion species') + key=(r['t'],r['dt']);present=by_rank[rank].setdefault(key,set()) + if species in present:raise ValueError('Duplicate continuity stage') + present.add(species) + residual=abs(r['after']-r['before']-r['source']+r['outward']-r['cleanup'])/r['scale'] + worst=max(worst,residual);charge=max(charge,r['charge_fraction']) + coverage.add(species);cleanup[str(species)]+=r['cleanup'];rows+=1 + complete=set(by_rank)==set(range(len(files))) and all(bool(clocks) and all(s==set(range(1,7)) for s in clocks.values()) for clocks in by_rank.values()) + if complete:complete=all(set(clocks)==set(by_rank[0]) for clocks in by_rank.values()) + for clocks in by_rank.values():check_clock_inventory(directory,set(clocks)) + return dict(schema='gemini.native.continuity.1',passed=rows>0 and complete and coverage==set(range(1,7)) and worst<=budget and charge<=charge_budget, + rank_files=len(files),rows=rows,per_step_coverage_complete=complete,max_normalized_residual=worst,max_charge_fraction=charge, + budget=budget,charge_budget=charge_budget,total_cleanup_number_by_species=cleanup, + scope='Six native ion continuity equations with applied chemical/ionization source increments and explicit cleanup; electron quasi-neutrality. Reaction-rate accuracy, full momentum and energy balances are separate.') + + +if __name__=='__main__': + p=argparse.ArgumentParser(description=__doc__);p.add_argument('directory',type=Path);p.add_argument('--output',type=Path,required=True);p.add_argument('--layout',type=int,nargs=2);a=p.parse_args() + try:r=check(a.directory,layout=a.layout) + except (ValueError,OSError) as e:r=dict(passed=False,error=str(e)) + a.output.write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r,indent=2));raise SystemExit(0 if r['passed'] else 1) diff --git a/scripts/qualification/conservative_exchange.py b/scripts/qualification/conservative_exchange.py new file mode 100644 index 000000000..aa04bc585 --- /dev/null +++ b/scripts/qualification/conservative_exchange.py @@ -0,0 +1,50 @@ +"""Verified Cartesian cell-average remapping and two-reservoir exchange kernel. + +This is a manufactured coupling component, not a GEMINI/CVTWIN physical law. +Curved metrics, open boundaries and masked cut cells require a different operator. +""" +import numpy as np + + +def edges(value): + x=np.asarray(value,dtype=float) + if x.ndim!=1 or len(x)<2 or not np.isfinite(x).all() or not np.all(np.diff(x)>0): + raise ValueError('Finite increasing cell edges required') + return x + + +def overlap(source,target): + a,b=edges(source),edges(target) + # Exact matching endpoints prevent silent uncovered-volume extrapolation. + if a[0]!=b[0] or a[-1]!=b[-1]:raise ValueError('Source and target domains must match') + return np.maximum(0.,np.minimum(b[1:,None],a[None,1:])-np.maximum(b[:-1,None],a[None,:-1])) + + +def volumes(grid): + if len(grid)!=3:raise ValueError('Three Cartesian axes required') + return np.einsum('i,j,k->ijk',*[np.diff(edges(x)) for x in grid]) + + +def remap(cell_average,source,target,valid=None): + """Array axes follow the provided Cartesian edges; trailing axis is channels.""" + value=np.asarray(cell_average,dtype=float);vs=volumes(source);vt=volumes(target) + if value.ndim!=4 or value.shape[:3]!=vs.shape or not np.isfinite(value).all(): + raise ValueError('Expected finite cell averages with explicit channel axis') + if valid is not None: + valid=np.asarray(valid) + if valid.dtype.kind not in 'biu' or not np.isin(valid,[0,1]).all(): + raise ValueError('Explicit Boolean or zero/one validity mask required') + if valid.shape!=vs.shape or not valid.all(): + raise ValueError('Masked or cut cells are outside this exchange contract') + matrices=[overlap(a,b) for a,b in zip(source,target)] + total=np.einsum('ai,bj,ck,ijkq->abcq',*matrices,value,optimize=True) + return total/vt[...,None] + + +def reservoir_step(a,b,capacity_a,capacity_b,conductance,dt): + """Exact passive exchange C_a da/dt=-k(a-b), C_b db/dt=k(a-b).""" + values=np.asarray([a,b,capacity_a,capacity_b,conductance,dt],float) + if not np.isfinite(values).all() or min(capacity_a,capacity_b)<=0 or min(conductance,dt)<0: + raise ValueError('Invalid passive exchange parameters') + transfer=(a-b)*(-np.expm1(-conductance*(1/capacity_a+1/capacity_b)*dt))/(1/capacity_a+1/capacity_b) + return a-transfer/capacity_a,b+transfer/capacity_b,transfer diff --git a/scripts/qualification/evaluate_gates.py b/scripts/qualification/evaluate_gates.py new file mode 100644 index 000000000..2a1fdd75a --- /dev/null +++ b/scripts/qualification/evaluate_gates.py @@ -0,0 +1,78 @@ +"""Check qualification evidence integrity, failing closed on open or stale gates. + +This verifies records and hashes, not the identity or authority of a reviewer. +The release owner must independently authenticate every approval record. +Exit 2 means the candidate remains unqualified; no status is changed. +""" +import argparse +import hashlib +import json +from pathlib import Path +import re + + +def evaluate(register, root): + root = root.resolve() + commit = register.get('candidate_commit', '') + if not re.fullmatch(r'[0-9a-f]{40}', commit): + raise ValueError('An exact candidate commit is required') + seen, issues = set(), [] + expected = {f'R{i:02d}' for i in range(1, 19)} + + def record(gid, item, kind): + if not isinstance(item, dict) or not {'path', 'sha256'} <= item.keys(): + issues.append(dict(id=gid, reason=kind + ' must name a file and SHA256')) + return + rel = Path(item['path']) + path = (root / rel).resolve() + if rel.is_absolute() or not path.is_relative_to(root): + raise ValueError('Evidence must remain inside package') + if not path.is_file(): + issues.append(dict(id=gid, reason=kind + ' missing: ' + str(rel))) + elif hashlib.sha256(path.read_bytes()).hexdigest() != item['sha256']: + issues.append(dict(id=gid, reason=kind + ' hash changed: ' + str(rel))) + + for gate in register['gates']: + gid = gate['id'] + if gid in seen or gid not in expected: + raise ValueError('Duplicate or unknown gate ' + gid) + seen.add(gid) + if gate.get('applicable', True) is False: + if gate.get('scope_exclusion_approved') is not True: + issues.append(dict(id=gid, reason='Scope exclusion needs approval')) + record(gid, gate.get('scope_exclusion_record'), 'Scope exclusion') + continue + if gate.get('status') != 'closed': + issues.append(dict(id=gid, reason=gate.get('required_change', 'Gate remains open'))) + continue + if not gate.get('evidence'): + issues.append(dict(id=gid, reason='No evidence attached')) + for evidence in gate.get('evidence', []): + record(gid, evidence, 'Evidence') + if gate.get('requires_independent_approval', False): + record(gid, gate.get('approval_record'), 'Independent approval') + if gate.get('tested_commit') != commit: + issues.append(dict(id=gid, reason='Evidence does not name the candidate commit')) + if seen != expected: + raise ValueError('Register must retain all 18 gates') + return dict(qualified=not issues, open_gates=issues, candidate_commit=commit, + scope='Record integrity only; approval authority is verified by the release owner') + + +def main(): + p = argparse.ArgumentParser(description=__doc__) + p.add_argument('register', type=Path) + p.add_argument('--root', type=Path, required=True) + p.add_argument('--output', type=Path, required=True) + a = p.parse_args() + try: + result = evaluate(json.loads(a.register.read_text()), a.root) + except (ValueError, KeyError, TypeError, OSError) as e: + result = dict(qualified=False, error=str(e)) + a.output.write_text(json.dumps(result, indent=2) + '\n') + print(json.dumps(result, indent=2)) + return 0 if result['qualified'] else 2 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/qualification/geometry_compare.py b/scripts/qualification/geometry_compare.py new file mode 100644 index 000000000..9f3c6056d --- /dev/null +++ b/scripts/qualification/geometry_compare.py @@ -0,0 +1,53 @@ +"""Screen the existing vertical Cartesian field approximation against IGRF-14. + +Full-grid diagnostic, not a new production geometry. The old Cartesian model +imposes -50 uT along e1; varying only its magnitude would leave the field-line +direction and transport metric assumptions unresolved. +""" +import argparse +import json +from pathlib import Path +import h5py +import numpy as np +from hdf_policy import numeric +from igrf14 import coefficients,field +from state_exchange import sha + + +def compare(grid,coeff,years,magnitude_budget,direction_budget): + if not years or not (0max_bytes:raise ValueError('HDF5 dataset exceeds allocation budget') + for i in range(props.get_nfilters()): + if props.get_filter(i)[0] not in BUILTIN_FILTERS:raise ValueError('Unsupported HDF5 filter') + return obj + + +def dataset(group,name): + # Check every path component before dereferencing; an intermediate group + # link is just as capable of leaving the file as a linked final dataset. + current=group + for key in name.split('/'): + if not key or key not in current or not isinstance(current.get(key,getlink=True),h5py.HardLink): + raise ValueError('Missing or indirect HDF5 path: '+name) + current=current[key] + return inspect_dataset(current) + + +def numeric(group,name,shape=None): + obj=dataset(group,name) + if obj.dtype.kind not in 'biuf':raise ValueError('Expected real numeric HDF5 data: '+name) + if shape is not None and obj.shape!=shape:raise ValueError('HDF5 shape mismatch: '+name) + return obj[...] diff --git a/scripts/qualification/host_capabilities.py b/scripts/qualification/host_capabilities.py new file mode 100644 index 000000000..77c43a2e8 --- /dev/null +++ b/scripts/qualification/host_capabilities.py @@ -0,0 +1,53 @@ +"""Probe required host capabilities without changing privileges or controls. + +Leak qualification requires a positive control: detecting an intentional leak +and accepting a leak-free program. A successful compiler exit is insufficient. +""" +import argparse,hashlib,json,os,platform,subprocess,tempfile +from pathlib import Path +from kernel_memory import measure + + +def leak_probe(cc,work): + work=Path(work);work.mkdir(parents=True,exist_ok=False) + code='''#include +__attribute__((noinline)) static void allocate(int leak) { + volatile char *p = malloc(1237); + if (!p) abort(); + p[0] = 1; + if (!leak) free((void *)p); +} +int main(int argc, char **argv) { (void)argv; allocate(argc > 1); return 0; } +''' + source=work/'leak_control.c';source.write_text(code);exe=work/'leak_control' + command=[cc,'-O0','-g','-fsanitize=address','-fno-omit-frame-pointer',str(source),'-o',str(exe)] + built=subprocess.run(command,capture_output=True,text=True,timeout=60) + (work/'compile.log').write_text(built.stdout+built.stderr) + if built.returncode:return dict(passed=False,status='blocked',reason='Probe compilation failed',command=command) + env=dict(os.environ,ASAN_OPTIONS='detect_leaks=1:halt_on_error=1',LSAN_OPTIONS='exitcode=23') + records=[] + for label,args in [('clean',[]),('intentional_leak',['leak'])]: + try: + run=subprocess.run([str(exe),*args],env=env,capture_output=True,text=True,timeout=30) + output=run.stdout+run.stderr;(work/(label+'.log')).write_text(output) + okay=(run.returncode==0 and 'LeakSanitizer' not in output) if not args else ( + run.returncode==23 and 'detected memory leaks' in output and '1237 byte(s)' in output) + records.append(dict(case=label,returncode=run.returncode,passed=okay)) + except (OSError,subprocess.SubprocessError) as e:records.append(dict(case=label,passed=False,error=str(e))) + return dict(schema='gemini.leak.capability.1',passed=all(r['passed'] for r in records), + status='capable' if all(r['passed'] for r in records) else 'blocked',runs=records, + executable_sha256=hashlib.sha256(exe.read_bytes()).hexdigest(), + limitation='Runtime controls only; actual instrumented GEMINI application runs are separately required') + + +def main(): + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--cc',default='gcc') + p.add_argument('--work',type=Path,required=True);p.add_argument('--only',choices=['all','leak','memory'],default='all');p.add_argument('--cgroup-parent',type=Path,default=Path('/sys/fs/cgroup')) + a=p.parse_args();a.work.mkdir(parents=True,exist_ok=False) + leaks=leak_probe(a.cc,a.work/'leak') if a.only in ('all','leak') else None + memory=measure(['/bin/true'],a.cgroup_parent,a.work/'memory.json',600,2048,30) if a.only in ('all','memory') else None + result=dict(schema='gemini.host.capabilities.1',platform=platform.platform(),leak=leaks,memory=memory, + requested=a.only,passed=all(r['passed'] for r in (leaks,memory) if r is not None)) + (a.work/'result.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2)) + return 0 if result['passed'] else 2 +if __name__=='__main__':raise SystemExit(main()) diff --git a/scripts/qualification/hosted_evidence.py b/scripts/qualification/hosted_evidence.py new file mode 100644 index 000000000..933416ed2 --- /dev/null +++ b/scripts/qualification/hosted_evidence.py @@ -0,0 +1,82 @@ +"""Check authenticated GitHub Actions API records against the exact candidate. + +Read-only collector. Does not push a branch, start jobs or post a review. The +raw API responses are retained. This establishes hosted job status, not physics +approval or leak freedom; those require their own measured artifacts. +""" +import argparse,json,re,subprocess +from pathlib import Path + +REQUIRED={'native (Debug)','native (Release)','current-hdf5','sanitizers'} +WORKFLOW='.github/workflows/preintegration.yml' +REQUIRED_STEPS={ + 'native (Debug)':{'Run native suite and reference comparisons','Verify restart record precision and rejection behavior', + 'Qualify exact restart and native numerical budgets'}, + 'native (Release)':{'Run native suite and reference comparisons','Verify restart record precision and rejection behavior', + 'Qualify exact restart and native numerical budgets'}, + 'current-hdf5':{'Build and test current-library profile','Qualify current-library restart and numerical budgets', + 'Measure complete workload with kernel memory accounting'}, + 'sanitizers':{'Check audit probes and native C++ consumer','Verify LeakSanitizer detects the intentional leak control', + 'Check leaks in standalone ABI and interpolation probes', + 'Check instrumented full-step Fortran and C++ checkpoints','Check leaks in the actual native application'}} + + +def verify(run,jobs,repository,commit,queried_attempt): + if not re.fullmatch(r'[0-9a-f]{40}',commit):raise ValueError('Exact candidate commit required') + if not re.fullmatch(r'[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+',repository):raise ValueError('Explicit owner/repository required') + issues=[] + if run.get('repository',{}).get('full_name','').lower()!=repository.lower():issues.append('repository_mismatch') + if run.get('head_sha')!=commit:issues.append('commit_mismatch') + if run.get('path','').split('@')[0]!=WORKFLOW:issues.append('workflow_mismatch') + if run.get('status')!='completed' or run.get('conclusion')!='success':issues.append('workflow_not_successful') + if not isinstance(run.get('run_attempt'),int) or run['run_attempt']<1:issues.append('invalid_run_attempt') + if queried_attempt!=run.get('run_attempt'):issues.append('query_attempt_mismatch') + seen={} + for job in jobs: + name=job.get('name');seen.setdefault(name,[]).append(job) + if job.get('run_id')!=run.get('id') or job.get('head_sha')!=commit:issues.append('job_identity_mismatch') + # The API's attempt-specific endpoint supplies the binding even when + # older job response schemas omit an individual run_attempt field. + if 'run_attempt' in job and job['run_attempt']!=run.get('run_attempt'):issues.append('job_attempt_mismatch') + if name in REQUIRED: + if job.get('status')!='completed' or job.get('conclusion')!='success':issues.append('job_not_successful:'+name) + steps=job.get('steps',[]) + if not steps or any(s.get('conclusion') in ('failure','cancelled','timed_out') for s in steps): + issues.append('failed_or_missing_steps:'+name) + for required in REQUIRED_STEPS[name]: + matches=[s for s in steps if s.get('name')==required] + if len(matches)!=1 or matches[0].get('conclusion')!='success': + issues.append('required_step_not_successful:'+name+':'+required) + for name in sorted(REQUIRED): + if len(seen.get(name,[]))!=1:issues.append('missing_or_duplicate_job:'+name) + return dict(schema='gemini.hosted.evidence.1',passed=not issues,issues=issues,repository=repository, + candidate_commit=commit,run_url=run.get('html_url'),run_id=run.get('id'),run_attempt=run.get('run_attempt'), + required_jobs=sorted(REQUIRED),limitation='Hosted execution record only; result artifacts and independent science gates remain required') + + +def api(endpoint): + p=subprocess.run(['gh','api',endpoint],capture_output=True,text=True,check=True,timeout=60) + return json.loads(p.stdout) + + +def main(): + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--repository',required=True) + p.add_argument('--commit',required=True);p.add_argument('--run-id',type=int,required=True) + p.add_argument('--output',type=Path,required=True);a=p.parse_args() + if not re.fullmatch(r'[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+',a.repository) or a.run_id<=0: + p.error('Explicit owner/repository and positive run ID required') + a.output.mkdir(parents=True,exist_ok=False) + run=api(f'repos/{a.repository}/actions/runs/{a.run_id}') + (a.output/'run.json').write_text(json.dumps(run,indent=2)+'\n') + jobs=[];page=1 + while True: + payload=api(f'repos/{a.repository}/actions/runs/{a.run_id}/attempts/{run["run_attempt"]}/jobs?per_page=100&page={page}') + (a.output/f'jobs-{page}.json').write_text(json.dumps(payload,indent=2)+'\n') + jobs.extend(payload['jobs']) + if len(jobs)>=payload['total_count']:break + if not payload['jobs']:raise ValueError('Incomplete job pagination') + page+=1 + result=verify(run,jobs,a.repository,a.commit,run['run_attempt']) + (a.output/'result.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2)) + return 0 if result['passed'] else 2 +if __name__=='__main__':raise SystemExit(main()) diff --git a/scripts/qualification/igrf14.py b/scripts/qualification/igrf14.py new file mode 100644 index 000000000..282ada87a --- /dev/null +++ b/scripts/qualification/igrf14.py @@ -0,0 +1,52 @@ +"""IGRF-14 geocentric field oracle for qualification, not a GEMINI grid generator. + +North/east/down components are in nT; latitude is geocentric degrees; radius +is geocentric km. Declared domain: 2025..2030, -89.9..89.9 latitude, radius +6371.2..8371.2 km. Full degree-13 field; no centered-dipole substitution. +""" +from math import sin, cos, sqrt, factorial, radians, isfinite +from pathlib import Path + + +def coefficients(path: Path): + rows = {} + for line in path.read_text().splitlines(): + fields = line.split() + if len(fields) < 5 or fields[0] not in {"g", "h"}: + continue + kind, n, m = fields[:3] + rows[kind, int(n), int(m)] = float(fields[-2]), float(fields[-1]) + if len(rows) != 195: + raise ValueError("Expected all 195 IGRF degree-13 coefficients") + return rows + + +def field(rows, year, radius_km, latitude_deg, longitude_deg): + if not all(map(isfinite, [year, radius_km, latitude_deg, longitude_deg])): + raise ValueError("Nonfinite IGRF input") + if not (2025 <= year <= 2030 and 6371.2 <= radius_km <= 8371.2 + and -89.9 <= latitude_deg <= 89.9): + raise ValueError("Outside declared IGRF qualification domain") + theta, lon = radians(90-latitude_deg), radians(longitude_deg % 360) + st, ct = sin(theta), cos(theta) + p, dp = {(0, 0): 1.0}, {(0, 0): 0.0} + br = bt = bp = 0.0 + for n in range(1, 14): + for m in range(n+1): + if m == n: + p[n,m] = (2*n-1)*st*p[n-1,m-1] + dp[n,m] = (2*n-1)*(ct*p[n-1,m-1]+st*dp[n-1,m-1]) + else: + p[n,m] = ((2*n-1)*ct*p[n-1,m]-(n+m-1)*p.get((n-2,m),0))/(n-m) + dp[n,m] = ((2*n-1)*(-st*p[n-1,m]+ct*dp[n-1,m]) + -(n+m-1)*dp.get((n-2,m),0))/(n-m) + norm = sqrt((2 if m else 1)*factorial(n-m)/factorial(n+m)) + g0, gv = rows['g',n,m] + h0, hv = rows.get(('h',n,m),(0,0)) + g, h = g0+(year-2025)*gv, h0+(year-2025)*hv + trig = g*cos(m*lon)+h*sin(m*lon) + radial = (6371.2/radius_km)**(n+2) + br += (n+1)*radial*trig*p[n,m]*norm + bt -= radial*trig*dp[n,m]*norm + bp += radial*m*(g*sin(m*lon)-h*cos(m*lon))*p[n,m]*norm/st + return -bt, bp, -br diff --git a/scripts/qualification/inventory.py b/scripts/qualification/inventory.py new file mode 100644 index 000000000..7a03b91fb --- /dev/null +++ b/scripts/qualification/inventory.py @@ -0,0 +1,64 @@ +"""Record the actual local build/Python/data inventory without claiming approval.""" +import argparse +import hashlib +import importlib.metadata +import json +import platform +from pathlib import Path +import subprocess +import sys + + +def digest(path): + with path.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() + + +def main(): + p=argparse.ArgumentParser(description=__doc__) + p.add_argument('--source',type=Path,required=True);p.add_argument('--build',type=Path,required=True) + p.add_argument('--package-cache',type=Path);p.add_argument('--data-root',type=Path,action='append',default=[]) + p.add_argument('--output',type=Path,required=True);a=p.parse_args() + cache={} + for line in (a.build/'CMakeCache.txt').read_text().splitlines(): + if line and not line.startswith(('#','//')) and '=' in line and ':' in line.split('=',1)[0]: + k,v=line.split('=',1);cache[k.split(':')[0]]=v + libkeys=[k for k in cache if k.startswith(('HDF5_','BLAS_','LAPACK_','SCALAPACK_','MPI_')) and ('LIBRARY' in k or 'VERSION' in k)] + linked=[] + for key in sorted(libkeys): + value=cache[key];entry=dict(key=key,value=value) + path=Path(value) + if path.is_file():entry.update(sha256=digest(path),resolved_path=str(path.resolve())) + linked.append(entry) + packages=[] + if a.package_cache: + if not a.package_cache.is_dir():raise ValueError('Requested package cache is missing') + for path in sorted(a.package_cache.glob('*.deb')): + proc=subprocess.run(['dpkg-deb','--field',str(path),'Package','Version','Architecture'],text=True,capture_output=True,check=True) + packages.append(dict(archive=path.name,sha256=digest(path),metadata=proc.stdout.strip())) + data=[] + for root in a.data_root: + if not root.exists():raise ValueError('Requested model/input path is missing: '+str(root)) + paths=[root] if root.is_file() else sorted(root.rglob('*')) + for path in paths: + if path.is_file():data.append(dict(root=str(root),path=path.name if root.is_file() else str(path.relative_to(root)), + size=path.stat().st_size,sha256=digest(path))) + toolchains=[] + for key in ['CMAKE_C_COMPILER','CMAKE_CXX_COMPILER','CMAKE_Fortran_COMPILER','MPIEXEC_EXECUTABLE','CMAKE_COMMAND']: + if key not in cache:continue + proc=subprocess.run([cache[key],'--version'],capture_output=True,text=True,timeout=30) + toolchains.append(dict(key=key,path=cache[key],returncode=proc.returncode,version=(proc.stdout+proc.stderr).strip())) + try: + import h5py + python_hdf5=h5py.version.hdf5_version + except ImportError:python_hdf5=None + versions=sorted([dict(name=d.metadata['Name'],version=d.version) for d in importlib.metadata.distributions()],key=lambda x:x['name'].lower()) + rev=subprocess.run(['git','-C',str(a.source),'rev-parse','HEAD'],check=True,capture_output=True,text=True).stdout.strip() + dirty=bool(subprocess.run(['git','-C',str(a.source),'status','--porcelain'],check=True,capture_output=True,text=True).stdout.strip()) + payload=dict(schema='gemini.qualification.inventory.1',scope='local test environment; deployment inventory requires target execution', + source_commit=rev,source_dirty=dirty,platform=platform.platform(),python=sys.version,python_packages=versions, + toolchains=toolchains,python_h5py_hdf5_version=python_hdf5, + build_libraries=linked,package_archives=packages,data_files=data, + release_license_approval=False,security_advisory_review_complete=False) + a.output.write_text(json.dumps(payload,indent=2)+'\n') + print(json.dumps(dict(python_packages=len(versions),library_records=len(linked),package_archives=len(packages),data_files=len(data)))) +if __name__=='__main__':main() diff --git a/scripts/qualification/kernel_memory.py b/scripts/qualification/kernel_memory.py new file mode 100644 index 000000000..e62f9611b --- /dev/null +++ b/scripts/qualification/kernel_memory.py @@ -0,0 +1,70 @@ +"""Measure a complete command tree in a fresh delegated Linux cgroup v2. + +No sampling fallback and no mount/privilege changes. cgroup memory.peak includes +charged file cache and kernel memory; it is not the sum of process RSS samples. +An unavailable delegation is a blocked measurement (exit 2), never a pass. +""" +import argparse +import datetime +import json +import math +import os +from pathlib import Path +import subprocess +import time +import uuid + + +def measure(command,parent,output,wall_budget,memory_budget_mib,timeout): + if not command or not all(math.isfinite(x) and x>0 for x in (wall_budget,memory_budget_mib,timeout)): + raise ValueError('Positive finite budgets and command required') + group=parent/('gemini-qualification-'+uuid.uuid4().hex) + result=dict(schema='gemini.kernel.memory.1',passed=False,status='blocked',command=command, + host_utc=datetime.datetime.now(datetime.timezone.utc).isoformat(), + memory_budget_mib=memory_budget_mib,wall_budget_seconds=wall_budget) + proc=None + try: + group.mkdir() + required=['cgroup.procs','cgroup.events','memory.peak','memory.events','memory.max'] + if any(not (group/k).is_file() for k in required):raise OSError('Delegated cgroup lacks memory controller') + if (group/'memory.peak').read_text().strip()!='0':raise OSError('Fresh cgroup has preexisting memory usage') + (group/'memory.max').write_text(str(int(memory_budget_mib*2**20))) + if (group/'memory.swap.max').exists():(group/'memory.swap.max').write_text('0') + # Move the new child itself before exec, before any command work starts. + def enter(): + with (group/'cgroup.procs').open('w') as stream:stream.write(str(os.getpid())) + start=time.monotonic() + with output.with_suffix('.log').open('w') as log: + proc=subprocess.Popen(command,stdout=log,stderr=subprocess.STDOUT,preexec_fn=enter,start_new_session=True) + try:code=proc.wait(timeout=timeout) + except subprocess.TimeoutExpired: + if (group/'cgroup.kill').exists():(group/'cgroup.kill').write_text('1') + else:os.killpg(proc.pid,9) + proc.wait();raise RuntimeError('Workload exceeded measurement timeout') + elapsed=time.monotonic()-start + peak=int((group/'memory.peak').read_text()) + events=dict(line.split() for line in (group/'memory.events').read_text().splitlines()) + populated=dict(line.split() for line in (group/'cgroup.events').read_text().splitlines()).get('populated') + okay=code==0 and 0i',v,l))) + + +def linear_analysis(prior,covariance,operator,observed,noise_covariance): + x,P,H,y,R=[np.asarray(a,float) for a in (prior,covariance,operator,observed,noise_covariance)] + if x.ndim!=1 or y.ndim!=1 or not x.size or not y.size or P.shape!=(x.size,x.size) or H.shape!=(y.size,x.size) or R.shape!=(y.size,y.size): + raise ValueError('Observation/analysis shape mismatch') + if not all(np.isfinite(a).all() for a in (x,P,H,y,R)):raise ValueError('Nonfinite analysis data') + for cov in (P,R): + if not np.allclose(cov,cov.T,rtol=1e-12,atol=0):raise ValueError('Covariance must be symmetric') + try:np.linalg.cholesky(cov) + except np.linalg.LinAlgError as e:raise ValueError('Positive definite covariance required') from e + innovation=y-H@x;S=H@P@H.T+R + K=np.linalg.solve(S,H@P).T;A=np.eye(x.size)-K@H + posterior=x+K@innovation;post_cov=A@P@A.T+K@R@K.T + return dict(posterior=posterior,covariance=(post_cov+post_cov.T)/2, + innovation=innovation,innovation_covariance=S, + normalized_innovation_squared=float(innovation@np.linalg.solve(S,innovation)), + observation_dimension=y.size) diff --git a/scripts/qualification/run_physics_native.py b/scripts/qualification/run_physics_native.py new file mode 100644 index 000000000..2891591fb --- /dev/null +++ b/scripts/qualification/run_physics_native.py @@ -0,0 +1,65 @@ +"""Compile probes against unmodified GEMINI objects, preserving execution receipts.""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import shlex +import subprocess + +p = argparse.ArgumentParser() +p.add_argument('--build', type=Path, required=True) +p.add_argument('--source', type=Path, required=True) +p.add_argument('--work', type=Path, required=True) +a = p.parse_args() +a.build = a.build.absolute() +a.source = a.source.absolute() +a.work = a.work.absolute() +a.work.mkdir(parents=True, exist_ok=False) +obj = a.work / 'physics_native.o' +exe = a.work / 'physics_native' +compile_command = [os.environ['FC'], '-g', '-fcheck=all', '-ffree-line-length-none', + '-I'+str(a.build/'include'), '-c', str(a.source), '-o', str(obj)] +with (a.work/'compile.log').open('w') as f: + r = subprocess.run(compile_command, stdout=f, stderr=subprocess.STDOUT) +if r.returncode: + raise SystemExit(f'Compile failed; see {a.work}/compile.log') +commands = subprocess.check_output(['ninja', '-C', str(a.build), '-t', 'commands', + 'qualification_continuity_floor'], text=True) +tokens = shlex.split(commands.splitlines()[-1]) +start = tokens.index('&&')+1 +end = tokens.index('&&', start) +command = tokens[start:end] +assert sum(t.endswith('continuity_floor.f90.o') for t in command) == 1 +command = [str(obj) if t.endswith('continuity_floor.f90.o') else t for t in command] +command[command.index('-o')+1] = str(exe) +command = [t for t in command if not t.startswith('-Wl,--dependency-file=')] +with (a.work/'link.log').open('w') as f: + r = subprocess.run(command, cwd=a.build, stdout=f, stderr=subprocess.STDOUT) +if r.returncode: + raise SystemExit(f'Link failed; see {a.work}/link.log') +r = subprocess.run([str(exe), str(a.work)], env=dict(os.environ, GEMINI_NUMERICAL_AUDIT='0'), + capture_output=True, text=True) +(a.work/'native.log').write_text(r.stdout+r.stderr) +receipt = { + 'schema': 'gemini.physics.native.receipt.1', + 'native_returncode': r.returncode, + 'probe_source_sha256': hashlib.sha256(a.source.read_bytes()).hexdigest(), + 'probe_executable_sha256': hashlib.sha256(exe.read_bytes()).hexdigest(), + 'compile_command': compile_command, + 'link_command': command, + 'objects': [], + 'files': [] +} +for t in command: + q = a.build/t + if t.endswith('.o') or t.endswith('.a') or '.so' in t: + if q.is_file(): + receipt['objects'].append({'file': str(q), 'sha256': hashlib.sha256(q.read_bytes()).hexdigest()}) +for q in sorted(a.work.glob('*.csv')): + receipt['files'].append({'file':q.name, 'bytes':q.stat().st_size, + 'sha256':hashlib.sha256(q.read_bytes()).hexdigest()}) +(a.work/'execution.json').write_text(json.dumps(receipt, indent=2)+'\n') +print(json.dumps({'native_returncode':r.returncode, 'output_files':len(receipt['files']), + 'work': str(a.work)})) +raise SystemExit(r.returncode) diff --git a/scripts/qualification/run_research.py b/scripts/qualification/run_research.py new file mode 100644 index 000000000..32615f19d --- /dev/null +++ b/scripts/qualification/run_research.py @@ -0,0 +1,80 @@ +"""Launch the admitted exact-restart research profile with immutable-input hashes. + +Only tdur may change when extending a run. All files below inputs, including +forcing and grid data, bind to the checkpoint. This does not authenticate users. +""" +import argparse +import hashlib +import datetime as dt +from validate_driver import validate,utc +import json +import os +from pathlib import Path +import re +import subprocess + +def input_signature(case): + root=case/'inputs' + if root.is_symlink():raise ValueError('Input symlinks are unsupported in the verified profile') + root=root.resolve() + records={} + for path in sorted(root.rglob('*')): + if path.is_symlink():raise ValueError('Input symlinks are unsupported in the verified profile') + if not path.is_file():continue + data=path.read_bytes() + if path.name=='config.nml': + text=data.decode() + if len(re.findall(r'(?im)^\s*tdur\s*=',text))!=1:raise ValueError('Exactly one tdur entry required') + text=re.sub(r'(?im)^(\s*tdur\s*=)[^!\n]*',r'\1 ',text) + data=text.encode() + records[str(path.relative_to(root))]=hashlib.sha256(data).hexdigest() + if 'config.nml' not in records:raise ValueError('Missing inputs/config.nml') + digest=hashlib.sha256(json.dumps(records,sort_keys=True,separators=(',',':')).encode()).hexdigest() + return {'schema':'gemini.research.inputs.1','sha256':digest,'files':records,'mutable':['base.tdur']} + + +def preflight(case): + # This launcher deliberately accepts the simple one-assignment-per-line + # namelist convention of the pinned research inputs, not arbitrary Fortran. + text=(case/'inputs/config.nml').read_text() + values={} + for line in text.splitlines(): + line=line.split('!',1)[0].strip() + if not line or line.startswith(('&','/')):continue + if '=' not in line:raise ValueError('Research namelist requires one complete assignment per line') + key,value=line.split('=',1);key=key.strip().lower() + if key in values:raise ValueError('Duplicate research configuration key: '+key) + values[key]=value.strip().rstrip(',') + date=[int(x.strip()) for x in values['ymd'].split(',')] + start=dt.datetime(*date,tzinfo=dt.timezone.utc)+dt.timedelta(seconds=float(values['utsec0'])) + stop=start+dt.timedelta(seconds=float(values['tdur'])) + if date[0]>2025:raise ValueError('Research profile does not qualify production geometry beyond 2025') + if values.get('allow_missing_spatial','.false.').lower() not in ('.false.','f'):raise ValueError('Research profile requires strict spatial coverage') + for key in ['indat_size','indat_grid','indat_file']: + target=(case/values[key].strip('"\'')).resolve() + if not target.is_relative_to((case/'inputs').resolve()) or not target.is_file(): + raise ValueError('Initial state/grid paths must remain inside verified inputs') + result={} + for kind,folder_key,cadence_key in [('efield','e0_dir','dte0'),('precip','prec_dir','dtprec')]: + folder=values[folder_key].strip('\"\'') + source=(case/folder).resolve() + if not source.is_relative_to((case/'inputs').resolve()):raise ValueError('Driver paths must remain inside verified inputs') + result[kind]=validate(source,start,stop,float(values[cadence_key]),kind) + return result + + +def main(): + p=argparse.ArgumentParser(description=__doc__) + p.add_argument('--exe',required=True,type=Path);p.add_argument('--case',required=True,type=Path) + p.add_argument('--ranks',type=int,choices=[1,2],default=2);p.add_argument('--mpiexec',default='mpiexec') + p.add_argument('--layout',type=int,nargs=2);a=p.parse_args() + forcing=preflight(a.case) + (a.case/'forcing-preflight.json').write_text(json.dumps(forcing,indent=2)+'\n') + record=input_signature(a.case) + (a.case/'verified-inputs.json').write_text(json.dumps(record,indent=2)+'\n') + env=os.environ.copy();env.update(HDF5_PLUGIN_PRELOAD='::',GEMINI_EXACT_RESTART='1',GEMINI_INPUT_SHA256=record['sha256'], + GEMINI_EXECUTABLE_SHA256=hashlib.sha256(a.exe.read_bytes()).hexdigest()) + command=[a.mpiexec,'-n',str(a.ranks),str(a.exe.resolve()),str(a.case.resolve())] + if a.layout:command+=['-manual_grid',*[str(x) for x in a.layout]] + return subprocess.run(command,env=env).returncode +if __name__=='__main__':raise SystemExit(main()) diff --git a/scripts/qualification/state_exchange.py b/scripts/qualification/state_exchange.py new file mode 100644 index 000000000..123c527c2 --- /dev/null +++ b/scripts/qualification/state_exchange.py @@ -0,0 +1,161 @@ +"""Lossless GEMINI full-output interchange; no invented CVTWIN MHD state. + +Exports the stored float32 full-output fields unchanged, the grid's native +geomagnetic Cartesian basis, validity mask, and UTC metadata. Does not promote +output precision, interpolate, or provide a two-way physical coupling. +""" +import argparse +from datetime import datetime,timedelta,timezone +import hashlib +import json +import os +from pathlib import Path +import tempfile +import h5py +import numpy as np +from hdf_policy import numeric,dataset +from validate_driver import parse_frame + +SPECIES=['O+','NO+','N2+','O2+','N+','H+','e-'] +FIELDS={'nsall':('number_density','m^-3'), 'Tsall':('temperature','K'), + 'vs1all':('parallel_velocity','m s^-1'), 'J1all':('current_native_1','A m^-2'), + 'J2all':('current_native_2','A m^-2'), 'J3all':('current_native_3','A m^-2'), + 'v2avgall':('density_averaged_velocity_2','m s^-1'), + 'v3avgall':('density_averaged_velocity_3','m s^-1'), 'Phiall':('potential','V')} +GEOMETRY_UNITS=dict(r='m',alt='m',theta='rad',phi='rad',glat='degree_north',glon='degree_east', + basis_geomagnetic_ecef='1',valid='1',x1='m',x2='m',x3='m',signed_background_B1_T='T') + + +def sha(path): + with open(path,'rb') as stream:return hashlib.file_digest(stream,'sha256').hexdigest() + + +def finite(value,name): + if not np.isfinite(value).all():raise ValueError('Nonfinite '+name) + return value + + +def native_time(date,hour,filename_time): + """Check the actual 10 ms filename contract, retaining native time separately. + + timeutils:utsec2filestem rounds positive seconds to centiseconds; the six + displayed fractional digits are not a promise of microsecond precision. + A rounded filename can cross midnight while its native date has not. + """ + if date.shape!=(3,) or date.dtype.kind not in 'iu':raise ValueError('Invalid UTC date') + if hour.shape!=() or hour.dtype.kind!='f' or not np.isfinite(hour):raise ValueError('Invalid UTC hour') + if not 0<=float(hour)<24:raise ValueError('Invalid UTC hour range') + try:day=datetime(*(int(v) for v in date),tzinfo=timezone.utc) + except ValueError as error:raise ValueError('Invalid UTC date') from error + seconds=float(hour)*3600 + # Division by 3600 at write time and multiplication here can move an + # exact 5 ms tie by an ulp. Check the rounding interval, not a second + # independently rounded value; retain the 10 ms filename lattice. + offset=(filename_time-day).total_seconds()-seconds + roundoff=4*np.spacing(max(abs(seconds),1.)) + if filename_time.microsecond%10000 or abs(offset)>.005+roundoff: + raise ValueError('UTC time mismatch with native 10 ms filename rounding') + return dict(utc=(day+timedelta(seconds=seconds)).isoformat(), + filename_utc=filename_time.isoformat(),filename_resolution_seconds=.01, + native_ymd=[int(v) for v in date],native_ut_hour=float(hour), + native_ut_hour_hex=float(hour).hex(),native_ut_hour_dtype=str(hour.dtype)) + + +def read_native(frame,grid): + instant=parse_frame(frame) + if instant is None:raise ValueError('GEMINI timestamp filename required') + with h5py.File(grid) as g,h5py.File(frame) as f: + if numeric(f,'flagoutput').shape!=() or int(numeric(f,'flagoutput'))!=1: + raise ValueError('Only full output flagoutput=1 is supported') + mask=numeric(g,'nullpts') + if mask.ndim!=3 or not np.isin(mask,[0,1]).all():raise ValueError('Invalid null mask') + shape=mask.shape;valid=(mask==0) + if not valid.any():raise ValueError('Empty physical domain') + for key in ['h1','h2','h3']: + metric=numeric(g,key,tuple(n+4 for n in shape))[2:-2,2:-2,2:-2] + if not np.allclose(metric,1,rtol=0,atol=1e-12):raise ValueError('Only Cartesian unit-metric interchange is supported') + date=numeric(f,'time/ymd',(3,));hour=numeric(f,'time/UThour') + clock=native_time(date,hour,instant) + data={} + for original,(name,units) in FIELDS.items(): + expected=(7,*shape) if original in ('nsall','Tsall','vs1all') else (shape[:2] if original=='Phiall' else shape) + data[name]=finite(numeric(f,original,expected),original) + if data[name].dtype.kind!='f':raise ValueError('Floating-point plasma fields required') + basis=np.stack([finite(numeric(g,f'e{i}',(3,*shape)),f'e{i}') for i in (1,2,3)],axis=-1) + basis=np.moveaxis(basis,0,-2) # x3,x2,x1,Cartesian component,native component + gram=np.einsum('...ji,...jk->...ik',basis.astype(float),basis.astype(float)) + if np.max(np.abs(gram-np.eye(3)))>2e-6 or np.max(np.abs(np.linalg.det(basis)-1))>2e-6: + raise ValueError('Basis must be right-handed orthonormal') + geometry={key:finite(numeric(g,key,shape),key) for key in ['r','theta','phi','glat','glon','alt']} + geometry['basis_geomagnetic_ecef']=basis + geometry['valid']=valid + for key,n in zip(['x1','x2','x3'],shape[::-1]): + centers=finite(numeric(g,key,(n+4,)),key)[2:-2] + if n>1 and not np.all(np.diff(centers)>0):raise ValueError('Grid centers must increase') + geometry[key]=centers + b=numeric(g,'Bmag',shape);geometry['signed_background_B1_T']=finite(b,'Bmag') + return data,geometry,dict(**clock,native_frame=frame.name, + source_sha256=sha(frame),grid_sha256=sha(grid),species=SPECIES, + axis_order=['x3','x2','x1'],basis='native orthonormal components expressed in geomagnetic Cartesian coordinates', + interpretation='background_B1 is signed imposed field; no evolved magnetic perturbation is supplied', + representation='stored native full-output precision; not the float64 restart state') + + +def export(frame,grid,output): + data,geometry,meta=read_native(frame,grid) + output.parent.mkdir(parents=True,exist_ok=True) + if output.exists():raise FileExistsError(output) + fd,tmp=tempfile.mkstemp(prefix=output.name+'.',suffix='.partial',dir=output.parent);os.close(fd) + try: + with h5py.File(tmp,'w') as f: + f.attrs['schema']='gemini.exchange.1';f.attrs['metadata']=json.dumps(meta,sort_keys=True) + for original,(name,units) in FIELDS.items(): + ds=f.create_dataset('state/'+name,data=data[name]);ds.attrs['units']=units;ds.attrs['native_name']=original + for name,value in geometry.items(): + ds=f.create_dataset('geometry/'+name,data=value);ds.attrs['units']=GEOMETRY_UNITS[name] + os.replace(tmp,output) + finally: + if os.path.exists(tmp):os.unlink(tmp) + return dict(passed=True,output_sha256=sha(output),**meta) + + +def read_exchange(path): + with h5py.File(path) as f: + if f.attrs.get('schema')!='gemini.exchange.1':raise ValueError('Unsupported exchange schema') + meta=json.loads(f.attrs['metadata']) + if meta['species']!=SPECIES or meta['axis_order']!=['x3','x2','x1']:raise ValueError('Unsupported channel/axis order') + for name,units in GEOMETRY_UNITS.items(): + if dataset(f,'geometry/'+name).attrs.get('units')!=units:raise ValueError('Geometry unit mismatch') + valid=numeric(f,'geometry/valid') + if valid.ndim!=3 or not np.isin(valid,[0,1]).all() or not valid.any():raise ValueError('Invalid exchange mask') + data={} + for original,(name,units) in FIELDS.items(): + ds=dataset(f,'state/'+name) + if ds.attrs.get('units')!=units or ds.attrs.get('native_name')!=original:raise ValueError('Unit or quantity mismatch') + expected=(7,*valid.shape) if original in ('nsall','Tsall','vs1all') else (valid.shape[:2] if original=='Phiall' else valid.shape) + data[name]=finite(numeric(f,'state/'+name,expected),name) + basis=finite(numeric(f,'geometry/basis_geomagnetic_ecef',(*valid.shape,3,3)),'basis') + gram=np.einsum('...ji,...jk->...ik',basis.astype(float),basis.astype(float)) + if np.max(np.abs(gram-np.eye(3)))>2e-6 or np.max(np.abs(np.linalg.det(basis)-1))>2e-6: + raise ValueError('Invalid exchange basis') + return data,valid.astype(bool),basis,meta + + +def restore_output(exchange,output): + """Restore the supported science fields, not a runnable restart checkpoint.""" + data,valid,basis,meta=read_exchange(exchange) + if output.exists():raise FileExistsError(output) + with h5py.File(output,'x') as f: + f.attrs['purpose']='interchange round trip; not a simulation checkpoint' + for original,(name,_) in FIELDS.items():f[original]=data[name] + return output + + +def cvtwin_mhd6(_exchange): + raise ValueError('No justified MHD6 mapping: GEMINI lacks evolved magnetic perturbations and species-resolved perpendicular velocities; CVTWIN is nondimensional incompressible MHD. A closure, scales, boundaries and exchange law are required.') + + +if __name__=='__main__': + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--frame',type=Path,required=True) + p.add_argument('--grid',type=Path,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args() + print(json.dumps(export(a.frame,a.grid,a.output),indent=2)) diff --git a/scripts/qualification/trace_diffusion_stages.py b/scripts/qualification/trace_diffusion_stages.py new file mode 100644 index 000000000..1c8296aef --- /dev/null +++ b/scripts/qualification/trace_diffusion_stages.py @@ -0,0 +1,93 @@ +"""Build an observational TR-stage trace copy without changing the native algorithm.""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import shlex +import subprocess + +p=argparse.ArgumentParser() +p.add_argument('--source',type=Path,required=True) +p.add_argument('--build',type=Path,required=True) +p.add_argument('--probe',type=Path,required=True) +p.add_argument('--work',type=Path,required=True) +a=p.parse_args();a.build=a.build.absolute();a.work=a.work.absolute();a.work.mkdir(parents=True,exist_ok=False) +original=a.source.read_text() +needle="call check_solver_info(info,'TRBDF21D BDF2 stage')" +assert original.count(needle)==1 +modified=original.replace(needle,needle+'\ncall trace_stage(Ts,TR,TRBDF21D)') +trace=''' +subroutine trace_stage(old,tr,new) +real(wp),intent(in)::old(:),tr(:),new(:) +integer::u,i,stat +character(4096)::path +call get_environment_variable('GEMINI_PHYSICAL_TR_TRACE',path,status=stat) +if(stat/=0.or.len_trim(path)==0)return +open(newunit=u,file=trim(path),status='unknown',position='append') +do i=1,size(old) + write(u,'(i0,3(",",es25.17))')i,old(i),tr(i),new(i) +enddo +close(u) +end subroutine +''' +assert modified.count('end module PDEparabolic')==1 +modified=modified.replace('end module PDEparabolic',trace+'\nend module PDEparabolic') +source=a.work/'PDEparabolic_trace.f90';source.write_text(modified) +obj=a.work/'PDEparabolic_trace.o';exe=a.work/'physics_trace' +# Use the compiler's actual native flags, including Debug bounds checking. +commands=subprocess.check_output(['ninja','-C',str(a.build),'-t','commands','PDEparabolic'],text=True) +compile_tokens=None +for line in commands.splitlines(): + tok=shlex.split(line) + if '-c' in tok and '-o' in tok and Path(tok[tok.index('-o')+1]).name=='PDEparabolic.f90.o': + compile_tokens=tok +assert compile_tokens is not None +cc=compile_tokens +cc[cc.index('-c')+1]=str(source) +cc[cc.index('-o')+1]=str(obj) +intel=Path(cc[0]).name in ('ifx','ifort') +flags=[] +skip=False +for t in cc: + if skip: + skip=False + continue + if t in ('-J','-module'): + skip=True + elif t!='-fpreprocessed' and not t.startswith(('-J','-module=')): + flags.append(t) +cc=flags +cc.append('-I'+str(a.build/'include')) +if intel: + cc.extend(['-module',str(a.work)]) +else: + cc.extend(['-ffree-line-length-none','-J'+str(a.work)]) +with (a.work/'compile.log').open('w') as f:subprocess.run(cc,cwd=a.build,stdout=f,stderr=subprocess.STDOUT,check=True) +commands=subprocess.check_output(['ninja','-C',str(a.build),'-t','commands','qualification_continuity_floor'],text=True) +tokens=shlex.split(commands.splitlines()[-1]);start=tokens.index('&&')+1;end=tokens.index('&&',start) +cmd=tokens[start:end] +libraries=[t for t in cmd if Path(t).name in ('libgemini3d.a','libgemini3d.debug.a')] +assert len(libraries)==1 +library=libraries[0] +cmd=[str(a.probe.absolute()) if t.endswith('continuity_floor.f90.o') else t for t in cmd] +cmd.insert(cmd.index(library),str(obj)) +cmd[cmd.index('-o')+1]=str(exe);cmd=[t for t in cmd if not t.startswith('-Wl,--dependency-file=')] +with (a.work/'link.log').open('w') as f:subprocess.run(cmd,cwd=a.build,stdout=f,stderr=subprocess.STDOUT,check=True) +tracepath=a.work/'tr-stages.csv' +r=subprocess.run([str(exe),str(a.work)],capture_output=True,text=True,env=dict(os.environ,GEMINI_PHYSICAL_TR_TRACE=str(tracepath))) +(a.work/'native.log').write_text(r.stdout+r.stderr) +baseline=a.probe.parent +comparisons={} +for q in sorted(baseline.glob('*.csv')): + copy=a.work/q.name + comparisons[q.name]={'bitwise_equal':q.read_bytes()==copy.read_bytes(), + 'sha256':hashlib.sha256(copy.read_bytes()).hexdigest()} +result={'returncode':r.returncode,'observational_copy':True, + 'original_source_sha256':hashlib.sha256(original.encode()).hexdigest(), + 'traced_source_sha256':hashlib.sha256(modified.encode()).hexdigest(), + 'compile_command':cc,'link_command':cmd,'comparisons':comparisons, + 'all_unmodified_outputs_bitwise_equal':all(v['bitwise_equal'] for v in comparisons.values())} +(a.work/'trace-receipt.json').write_text(json.dumps(result,indent=2)+'\n') +print(json.dumps({k:v for k,v in result.items() if k in ('returncode','all_unmodified_outputs_bitwise_equal')})) +if r.returncode or not result['all_unmodified_outputs_bitwise_equal']:raise SystemExit(1) diff --git a/scripts/qualification/validate_driver.py b/scripts/qualification/validate_driver.py new file mode 100644 index 000000000..4e51d3c59 --- /dev/null +++ b/scripts/qualification/validate_driver.py @@ -0,0 +1,144 @@ +"""Preflight a uniform-cadence HDF5 forcing stream; gaps are errors. + +Run separately for each driver. It does not infer a cadence, fill missing +values, or resample nonuniform data. Times are UTC (naive ISO values mean UTC). +""" +import argparse +import hashlib +import datetime as dt +import json +from pathlib import Path +import re +import h5py +import numpy as np +from hdf_policy import inspect_dataset + + +def parse_frame(path): + match=re.fullmatch(r'(\d{8})_(\d{5}\.\d{6})\.h5',path.name) + if not match:return None + sec=float(match[2]) + if not 0<=sec<86400:raise ValueError('Invalid UTC seconds in '+path.name) + return dt.datetime.strptime(match[1],'%Y%m%d').replace(tzinfo=dt.timezone.utc)+dt.timedelta(seconds=sec) + + +def numeric_dataset(group, name): + """Reject indirection before dereferencing; forcing is a self-contained file.""" + if name not in group or not isinstance(group.get(name, getlink=True), h5py.HardLink): + raise ValueError('Missing required field or unsupported link: '+name) + obj=group[name] + if not isinstance(obj,h5py.Dataset) or obj.dtype.kind not in 'iuf': + raise ValueError('Expected real numeric forcing dataset: '+name) + inspect_dataset(obj) + value=obj[...] + if not np.isfinite(value).all():raise ValueError('Nonfinite forcing dataset: '+name) + return value + + +def driver_grid(directory): + sizes=[] + with h5py.File(directory/'simsize.h5') as f: + for aliases in [('llat','Nlat','lx2'),('llon','Nlon','lx3')]: + key=next((k for k in aliases if k in f),aliases[0]) + value=numeric_dataset(f,key) + if value.shape!=() or value<=0 or value!=int(value): + raise ValueError('Driver size must be a positive integer scalar: '+key) + sizes.append(int(value)) + with h5py.File(directory/'simgrid.h5') as f: + for name,length in zip(['mlat','mlon'],sizes): + value=numeric_dataset(f,name) + if value.shape!=(length,) or (length>1 and not np.all(np.diff(value)>0)): + raise ValueError('Driver coordinate shape or increasing order: '+name) + if name=='mlat' and np.any(np.abs(value)>90): + raise ValueError('Driver latitude outside degrees [-90,90]') + return tuple(sizes) + + +def required_schema(f,kind,shape): + lat,lon=shape + fields=({'Qp':shape,'E0p':shape} if kind=='precip' else + dict(Exit=shape,Eyit=shape,Vminx1it=shape,Vmaxx1it=shape, + Vminx2ist=(lat,),Vmaxx2ist=(lat,),Vminx3ist=(lon,),Vmaxx3ist=(lon,),flagdirich=())) + for name,expected in fields.items(): + value=numeric_dataset(f,name) + if value.shape!=expected: + raise ValueError(f'Required field shape {name}: {value.shape}, expected {expected} (disk lat,lon order)') + if name=='flagdirich' and float(value) not in (0.,1.,2.): + raise ValueError('Invalid categorical flagdirich; expected 0, 1 or 2') + if name=='Qp' and np.any(value<0):raise ValueError('Negative precipitation energy flux Qp') + if name=='E0p' and np.any(value<=0):raise ValueError('Precipitation characteristic energy E0p must be positive') + if 'time' not in f or not isinstance(f.get('time',getlink=True),h5py.HardLink) or not isinstance(f['time'],h5py.Group): + raise ValueError('Required driver time group missing or linked') + numeric_dataset(f['time'],'ymd') + if not any(k in f['time'] for k in ['UTsec','UThour']):raise ValueError('Required UTC time metadata missing') + + +def validate(directory,start,stop,cadence,kind='generic'): + if kind not in ('generic','efield','precip'):raise ValueError('Unsupported driver kind') + shape=driver_grid(directory) if kind!='generic' else None + if not np.isfinite(cadence) or cadence<=0 or stopstart or frames[-1][0]1e-6: + raise ValueError(f'Missing or nonuniform cadence: {pa.name} -> {pb.name}') + signature=None;count=0 + for instant,path in frames: + fields={} + with h5py.File(path) as f: + visited={h5py.h5o.get_info(f.id).addr} + def walk(group,prefix=''): + nonlocal count + for key in group: + name=prefix+'/'+key + if not isinstance(group.get(key,getlink=True),h5py.HardLink): + raise ValueError('External/soft driver links are unsupported: '+name) + obj=group[key] + if isinstance(obj,h5py.Group): + address=h5py.h5o.get_info(obj.id).addr + if address in visited:raise ValueError('Repeated/cyclic forcing group: '+name) + visited.add(address);walk(obj,name);continue + if obj.dtype.kind not in 'iuf':raise ValueError('Nonnumeric or non-real forcing dataset: '+name) + inspect_dataset(obj) + value=obj[...] + if not np.isfinite(value).all():raise ValueError('Nonfinite forcing dataset: '+str(path)+name) + fields[name]=list(obj.shape);count+=1 + walk(f) + if kind!='generic':required_schema(f,kind,shape) + if 'time/ymd' in f: + date=np.asarray(f['time/ymd'][...]) + if date.shape!=(3,) or not np.array_equal(date,[instant.year,instant.month,instant.day]): + raise ValueError('Driver date metadata differs from filename: '+str(path)) + for key,multiplier in [('time/UTsec',1),('time/UThour',3600)]: + if key in f: + stamp=np.asarray(f[key][...]) + expected=(instant-instant.replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds() + if stamp.size!=1 or not np.isfinite(stamp).all() or abs(float(stamp.item())*multiplier-expected)>1e-6: + raise ValueError('Driver UTC metadata differs from filename: '+str(path)) + if not fields:raise ValueError('Empty forcing frame: '+str(path)) + if signature is None:signature=fields + elif fields!=signature:raise ValueError('Dataset/shape changes between driver frames: '+str(path)) + hashes={p.name:hashlib.sha256(p.read_bytes()).hexdigest() for _,p in frames} + if shape is not None: + for name in ['simsize.h5','simgrid.h5']:hashes[name]=hashlib.sha256((directory/name).read_bytes()).hexdigest() + return dict(passed=True,kind=kind,required_schema_checked=kind!='generic',sha256=hashes, + frames=len(frames),datasets_checked=count,cadence_seconds=cadence, + first=frames[0][0].isoformat(),last=frames[-1][0].isoformat(),fields=signature) + + +def utc(value): + value=dt.datetime.fromisoformat(value) + return value.replace(tzinfo=dt.timezone.utc) if value.tzinfo is None else value.astimezone(dt.timezone.utc) + + +def main(): + p=argparse.ArgumentParser(description=__doc__);p.add_argument('directory',type=Path);p.add_argument('--start',required=True,type=utc) + p.add_argument('--stop',required=True,type=utc);p.add_argument('--cadence',type=float,required=True);p.add_argument('--output',type=Path,required=True) + p.add_argument('--kind',choices=['generic','efield','precip'],default='generic',help='A concrete kind is required for qualification') + a=p.parse_args() + try:result=validate(a.directory,a.start,a.stop,a.cadence,a.kind) + except (ValueError,OSError) as e:result=dict(passed=False,error=str(e)) + result['schema']='gemini.qualification.driver.1';a.output.write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2)) + return 0 if result['passed'] else 1 +if __name__=='__main__':raise SystemExit(main()) diff --git a/scripts/requirements-local.txt b/scripts/requirements-local.txt new file mode 100644 index 000000000..ffffc574c --- /dev/null +++ b/scripts/requirements-local.txt @@ -0,0 +1,6 @@ +# Local build and qualification environment (Python 3.11+). +cmake==3.31.10 +ninja==1.13.2 +numpy==2.3.5 +scipy==1.16.3 +h5py==3.16.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8e72e0e84..3268bc81e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,16 @@ add_subdirectory(temporal) add_library(collision OBJECT collisions/collisions.f90) target_link_libraries(collision PRIVATE const gemini3d_config meshobj) +if(gemini3d_midpoint_conduction) + set(midpoint_conduction_fortran ".true.") +else() + set(midpoint_conduction_fortran ".false.") +endif() +configure_file(numerical/diffusion/diffusion_features.in.f90 diffusion_features.f90 @ONLY) +add_library(nonlinear_diffusion OBJECT numerical/diffusion/nonlinear_diffusion.f90 + ${CMAKE_CURRENT_BINARY_DIR}/diffusion_features.f90) +target_link_libraries(nonlinear_diffusion PRIVATE collision const diffusion meshobj) + # --- other libs add_subdirectory(neutral) @@ -29,7 +39,7 @@ add_library(multifluid OBJECT multifluid/multifluid.f90 $ ) target_link_libraries(multifluid PRIVATE -advec calculus collision const diffusion meshobj precipdata ionization precipBCs sources timeutils gemini3d_config neutral) +advec transport_audit calculus collision const diffusion nonlinear_diffusion meshobj precipdata ionization precipBCs sources timeutils gemini3d_config neutral) add_library(gemini_work_def OBJECT intvars/gemini_work_def.f90) target_link_libraries(gemini_work_def PRIVATE const inputdata neutral precipdata efielddata @@ -52,6 +62,7 @@ $ ) target_link_libraries(gemini3d PUBLIC h5fortran::h5fortran +LAPACK::LAPACK ${MPI_Fortran_LIBRARIES} $<$:glow::glow> $<$:hwm14::hwm_ifc> @@ -70,11 +81,11 @@ RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} ) set(gemini_internal_mods -advec +advec transport_audit calculus gemini3d_config const collision -diffusion fang interp +diffusion nonlinear_diffusion pair_exchange fang interp ionization inputdata precipdata efielddata solfluxdata gemini3d_sysinfo @@ -89,7 +100,7 @@ multifluid PDEparabolic gbsv precipBCs solfluxBCs reader sanity_check errors sources temporal timeutils exe_frontend -grid io +grid io atomic_file restart_runtime mpimod autogrid io_nompi @@ -102,7 +113,7 @@ advec_mpi calculus gemini3d_config const collision -diffusion fang interp +diffusion nonlinear_diffusion pair_exchange fang interp ionization ionization_mpi inputdata precipdata efielddata solfluxdata diff --git a/src/collisions/collisions.f90 b/src/collisions/collisions.f90 index 4a334b5e3..6784ecbf8 100644 --- a/src/collisions/collisions.f90 +++ b/src/collisions/collisions.f90 @@ -176,7 +176,11 @@ pure subroutine coulomb_colln(isp,isp2,ns,Ts,vs1,nusj,Phisj,Psisj) sqrt(2*kB*Teff/mred) Psisj=exp(-Wsj**2) where (Wsj<0.1_wp) - Phisj=1 + ! 3/W**3 * integral(0:W, x**2*exp(-x**2) dx). The constant + ! approximation produced a jump at W=0.1. This convergent expansion + ! retains the exact zero-drift limit without subtractive cancellation. + Phisj=1-Wsj**2*(3._wp/5-Wsj**2*(3._wp/14-Wsj**2*(1._wp/18 & + -Wsj**2*(1._wp/88-Wsj**2*(1._wp/520-Wsj**2/3600))))) elsewhere Phisj=3.0_wp/4*sqrt(pi)*erf(Wsj)/Wsj**3 - 3.0_wp/2/Wsj**2*Psisj end where diff --git a/src/inputdata/inputdataobj.f90 b/src/inputdata/inputdataobj.f90 index 08bd4c571..d8817d35a 100644 --- a/src/inputdata/inputdataobj.f90 +++ b/src/inputdata/inputdataobj.f90 @@ -7,16 +7,25 @@ module inputdataobj use gemini3d_config, only: gemini_cfg use meshobj, only : curvmesh use meshobj_dipole, only: dipolemesh -use interpolation, only : interp1,interp2,interp3 -use timeutils, only : dateinc, date_filename, find_lastdate +use interpolation, only : interp1,interp2,interp3,coverage_mask +use timeutils, only : dateinc, date_filename, find_lastdate, elapsed_seconds, shift_datetime +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite implicit none (type, external) private public :: inputdata +! Each mask describes target sites; values remain distinguishable from physical zero. +type :: spatial_coverage + logical, allocatable :: valid(:) +end type spatial_coverage + !> this is a generic class for an data object being input into the model and interpolated in space and time type, abstract :: inputdata + type(spatial_coverage) :: coverage(7) ! axes 1,2,3,23,12,13,123 + integer :: spatial_missing_count=0 + logical :: allow_missing_spatial=.false., coverage_warning_sent=.false. character(:), allocatable :: dataname ! string description of dataset character(:), allocatable :: sourcedir ! source location containing data input files @@ -37,44 +46,45 @@ module inputdataobj ! the base class will never change this -- extensions must handle !! here we store data that have already been received but not yet interpolated - real(wp), dimension(:), pointer :: coord1,coord2,coord3 ! coordinates for the source data (interpolant coords) - integer, pointer :: lc1,lc2,lc3 ! dataset length along the 3 coordinate axes - real(wp), dimension(:), pointer :: data0D - real(wp), dimension(:,:), pointer :: data1Dax1,data1Dax2,data1Dax3 - real(wp), dimension(:,:,:), pointer :: data2Dax23,data2Dax12,data2Dax13 - real(wp), dimension(:,:,:,:), pointer :: data3D + ! These pointers own their allocations; extensions only alias them. + real(wp), dimension(:), pointer :: coord1=>null(),coord2=>null(),coord3=>null() + integer, pointer :: lc1=>null(),lc2=>null(),lc3=>null() + real(wp), dimension(:), pointer :: data0D=>null() + real(wp), dimension(:,:), pointer :: data1Dax1=>null(),data1Dax2=>null(),data1Dax3=>null() + real(wp), dimension(:,:,:), pointer :: data2Dax23=>null(),data2Dax12=>null(),data2Dax13=>null() + real(wp), dimension(:,:,:,:), pointer :: data3D=>null() !! here we store data that have already been spatially interpolated - real(wp), dimension(:,:), pointer :: data0Di ! array for storing a "stack" of scalar data (only interpolated in time) + real(wp), dimension(:,:), pointer :: data0Di=>null() ! scalar data, interpolated only in time ! last axis is for prev,next copies of data for interp in time ! second to last axis is for number of datasets of this dimension integer :: l0D ! length/number of scalar datasets - real(wp), dimension(:,:,:), pointer :: data1Dax1i ! array for storing series of 1D data, array varies along non-singleton axis - real(wp), dimension(:,:,:), pointer :: data1Dax2i,data1Dax3i ! 1D data arrays varying along coordinates (axes) 2 and 3 + real(wp), dimension(:,:,:), pointer :: data1Dax1i=>null() ! 1D data varying along axis 1 + real(wp), dimension(:,:,:), pointer :: data1Dax2i=>null(),data1Dax3i=>null() integer :: l1Dax1,l1Dax2,l1Dax3 - real(wp), dimension(:,:,:,:), pointer :: data2Dax23i ! array for storing series of 2D data, varies along two non-singleton axes - real(wp), dimension(:,:,:,:), pointer :: data2Dax12i,data2dax13i !2D arrays varying along 1,2 and 1,3 axes + real(wp), dimension(:,:,:,:), pointer :: data2Dax23i=>null() ! 2D data varying along axes 2,3 + real(wp), dimension(:,:,:,:), pointer :: data2Dax12i=>null(),data2dax13i=>null() integer :: l2Dax23,l2Dax12,l2Dax13 - real(wp), dimension(:,:,:,:,:), pointer :: data3Di ! array for storing series of 3D data + real(wp), dimension(:,:,:,:,:), pointer :: data3Di=>null() ! array for storing series of 3D data integer :: l3D !! by default we have one set of target coordinates; extension can define others, if needed; note these are "flat" arrays (rank 1) - real(wp), dimension(:), pointer :: coord1i,coord2i,coord3i ! coordinates of the interpolation sites, full 3D, size lc1i*lc2i*lc3i - real(wp), dimension(:), pointer :: coord1iax1 ! 1D target coords for variations along axis 1 - real(wp), dimension(:), pointer :: coord2iax2 ! 1D target coords for variations along axis 2 - real(wp), dimension(:), pointer :: coord3iax3 ! 1D target coords for variations along axis 3 - real(wp), dimension(:), pointer :: coord2iax23,coord3iax23 ! 2D target along axes 2,3 - real(wp), dimension(:), pointer :: coord1iax12,coord2iax12 ! 2D target along axes 1,2 - real(wp), dimension(:), pointer :: coord1iax13,coord3iax13 ! 2D target along axes 1,3 + real(wp), dimension(:), pointer :: coord1i=>null(),coord2i=>null(),coord3i=>null() + real(wp), dimension(:), pointer :: coord1iax1=>null() ! 1D target coords for variations along axis 1 + real(wp), dimension(:), pointer :: coord2iax2=>null() ! 1D target coords for variations along axis 2 + real(wp), dimension(:), pointer :: coord3iax3=>null() ! 1D target coords for variations along axis 3 + real(wp), dimension(:), pointer :: coord2iax23=>null(),coord3iax23=>null() + real(wp), dimension(:), pointer :: coord1iax12=>null(),coord2iax12=>null() + real(wp), dimension(:), pointer :: coord1iax13=>null(),coord3iax13=>null() integer :: lc1i,lc2i,lc3i ! dataset length along the 3 coordinate axes !! these are the input data arrays interpolated in time to the present (presuming we've called update/timeinterp - real(wp), dimension(:), pointer :: data0Dinow - real(wp), dimension(:,:), pointer :: data1Dax1inow - real(wp), dimension(:,:), pointer :: data1Dax2inow,data1Dax3inow - real(wp), dimension(:,:,:), pointer :: data2Dax23inow - real(wp), dimension(:,:,:), pointer :: data2Dax12inow,data2dax13inow - real(wp), dimension(:,:,:,:), pointer :: data3Dinow + real(wp), dimension(:), pointer :: data0Dinow=>null() + real(wp), dimension(:,:), pointer :: data1Dax1inow=>null() + real(wp), dimension(:,:), pointer :: data1Dax2inow=>null(),data1Dax3inow=>null() + real(wp), dimension(:,:,:), pointer :: data2Dax23inow=>null() + real(wp), dimension(:,:,:), pointer :: data2Dax12inow=>null(),data2dax13inow=>null() + real(wp), dimension(:,:,:,:), pointer :: data3Dinow=>null() real(wp), dimension(2) :: tref ! times for two input frames bracketting current time real(wp) :: tnow ! time corresponding to data in *now arrays, viz current time insofar as this object knows @@ -98,6 +108,7 @@ module inputdataobj procedure :: set_name ! assign a character string name to our dataset procedure :: set_source ! set the source directory for the input data procedure :: init_storage ! wrapper routine to set up arrays once sizes are known/set + procedure :: validate_spatial_coverage procedure :: spaceinterp ! interpolate spatially procedure :: nospaceinterp ! do not interpolate; fill arrays directly from input data (assuming flag checks pass) procedure :: timeinterp ! interpolate in time based on data presently loaded into spatial arrays @@ -290,6 +301,8 @@ subroutine set_cadence(self,dtdata) class(inputdata), intent(inout) :: self real(wp), intent(in) :: dtdata + if (.not.ieee_is_finite(dtdata)) error stop "inputdata: nonfinite cadence" + if (dtdata<=0 .or. dtdata>86400) error stop "inputdata: cadence must be in (0,86400]" self%dt=dtdata self%flagcadence=.true. end subroutine set_cadence @@ -354,18 +367,19 @@ subroutine prime_data(self,cfg,x,dtmodel,ymd,UTsec) !self%tref(1)=UTsectmp-UTsec-2*self%dt !self%tref(2)=self%tref(1)+self%dt - self%tref(1)=(UTsectmp-cfg%UTsec0)-2*self%dt + self%tref(1)=elapsed_seconds(cfg%ymd0,cfg%UTsec0,ymdtmp,UTsectmp)-2*self%dt self%tref(2)=self%tref(1)+self%dt ! ' This is a workaround to insure compatibility with restarts...',ymdtmp,UTsectmp !! We essentially are loading up the data corresponding to halfway betwween -dtneu and t0 (zero). This will load ! two time levels back so when tprev is incremented twice it will be the true tprev corresponding to first time step - call self%update(cfg,dtmodel,self%tref(2)+self%dt/2,x,ymdtmp,UTsectmp-self%dt) !abs time arg to be < 0 + call shift_datetime(-self%dt,ymdtmp,UTsectmp) + call self%update(cfg,dtmodel,self%tref(2)+self%dt/2,x,ymdtmp,UTsectmp) !abs time arg to be < 0 !! Now compute perturbations for the present time (zero), this moves the primed variables in next into prev and then ! loads up a current state so that we get a proper interpolation for the first time step. !call self%update(cfg,dtmodel,0._wp,x,ymdtmp,UTsectmp) !t-dt so we land exactly on start time - call self%update(cfg,dtmodel,self%tref(2)+3/2*self%dt,x,ymdtmp,UTsectmp) !t-dt so we land exactly on start time + call self%update(cfg,dtmodel,self%tref(2)+self%dt/2,x,ymdtmp,UTsectmp) !t-dt so we land exactly on start time self%flagprimed=.true. @@ -402,6 +416,8 @@ subroutine update_simple(self,cfg,dtmodel,t,x,ymd,UTsec) integer, dimension(3) :: ymdtmp ! these hold the incremented date following reading of new file real(wp) :: UTsectmp + self%allow_missing_spatial=cfg%allow_missing_spatial + !! basic error checking if (.not. self%flagalloc) error stop 'inputdata:update() - must allocate array space prior to update...' if (.not. self%flagcadence) error stop 'inputdata:update() - must define cadence first...' @@ -411,7 +427,7 @@ subroutine update_simple(self,cfg,dtmodel,t,x,ymd,UTsec) !print*, ' ',self%ymdref(:,1),self%UTsecref(1),self%ymdref(:,2),self%UTsecref(2) !! see if we need to load new data into the buffer; negative time means that we need to load the first frame - if (t+dtmodel/2 >= self%tref(2) .or. t < 0) then + do while (t+dtmodel/2 >= self%tref(2) .or. .not.self%flagprimed) !IF FIRST LOAD ATTEMPT CREATE A NEUTRAL GRID AND COMPUTE GRID SITES FOR IONOSPHERIC GRID. Since this needs an input file, I'm leaving it under this condition here if (self%flagfirst) then !initialize dates @@ -430,6 +446,9 @@ subroutine update_simple(self,cfg,dtmodel,t,x,ymd,UTsec) !Read in neutral data from a file call self%load_data(t,dtmodel,ymdtmp,UTsectmp) + if (abs(elapsed_seconds(self%ymdref(:,2),self%UTsecref(2),ymdtmp,UTsectmp)-self%dt) & + > 1e-6_wp) error stop 'inputdata: missing or nonuniform frame; resample to declared cadence' + !Spatial interpolation for the frame we just read in (or copying) if (self%flagnointerp) then call self%nospaceinterp() @@ -445,7 +464,8 @@ subroutine update_simple(self,cfg,dtmodel,t,x,ymd,UTsec) self%tref(2)=self%tref(1)+self%dt self%UTsecref(2)=UTsectmp self%ymdref(:,2)=ymdtmp - end if !done loading frame data... + if (.not.self%flagprimed) exit ! priming loads exactly one frame on each call + end do !done loading frame data... !Interpolation in time call self%timeinterp(t,dtmodel) @@ -588,6 +608,36 @@ end subroutine nospaceinterp !> use data stored in input arrays to interpolate onto grid sites for "next" dataset. There may be a need here to ! accommodate singleton dimension naturally to void having to define extensions for different types of interp... + subroutine validate_spatial_coverage(self) + class(inputdata),intent(inout) :: self + integer :: i + if (self%l1Dax1>0) self%coverage(1)%valid=coverage_mask(self%coord1,self%coord1iax1) + if (self%l1Dax2>0) self%coverage(2)%valid=coverage_mask(self%coord2,self%coord2iax2) + if (self%l1Dax3>0) self%coverage(3)%valid=coverage_mask(self%coord3,self%coord3iax3) + if (self%l2Dax23>0) self%coverage(4)%valid= & + coverage_mask(self%coord2,self%coord2iax23).and.coverage_mask(self%coord3,self%coord3iax23) + if (self%l2Dax12>0) self%coverage(5)%valid= & + coverage_mask(self%coord1,self%coord1iax12).and.coverage_mask(self%coord2,self%coord2iax12) + if (self%l2Dax13>0) self%coverage(6)%valid= & + coverage_mask(self%coord1,self%coord1iax13).and.coverage_mask(self%coord3,self%coord3iax13) + if (self%l3D>0) self%coverage(7)%valid=coverage_mask(self%coord1,self%coord1i) & + .and.coverage_mask(self%coord2,self%coord2i).and.coverage_mask(self%coord3,self%coord3i) + self%spatial_missing_count=0 + do i=1,7 + if (allocated(self%coverage(i)%valid)) & + self%spatial_missing_count=self%spatial_missing_count+count(.not.self%coverage(i)%valid) + enddo + if (self%spatial_missing_count>0) then + if (allocated(self%dataname).and..not.self%coverage_warning_sent) & + write(stderr,*) 'Spatial coverage missing: ',self%dataname,self%spatial_missing_count + if (.not.self%allow_missing_spatial) & + error stop 'inputdata: uncovered target sites; extend input grid or explicitly allow flagged zero fill' + if (.not.self%coverage_warning_sent) write(stderr,*) & + 'WARNING: explicitly allowed zero fill; coverage masks mark missing values, not physical zeros.' + self%coverage_warning_sent=.true. + endif + end subroutine validate_spatial_coverage + subroutine spaceinterp(self) class(inputdata),intent(inout) :: self integer :: iparm @@ -612,6 +662,8 @@ subroutine spaceinterp(self) coord1iax12=>self%coord1iax12; coord2iax12=>self%coord2iax12; coord1iax13=>self%coord1iax13; coord3iax13=>self%coord3iax13; + call self%validate_spatial_coverage() + !> 1D arrays varying along the 1-axis if (self%l1Dax1>0) then self%data1Dax1i(:,:,1)=self%data1Dax1i(:,:,2) ! save old data!!! @@ -785,6 +837,12 @@ subroutine timeinterp(self,t,dt) integer :: ic1,ic2,ic3,iparm integer :: lc1i,lc2i,lc3i + if (.not.all(ieee_is_finite([t,dt,self%tref]))) error stop "inputdata: nonfinite interpolation time" + if (dt<0 .or. self%tref(2)<=self%tref(1)) error stop "inputdata: invalid interpolation interval" + if (self%flagprimed) then + if (t+dt/2self%tref(2)) & + error stop "inputdata: query is outside temporal driver coverage" + endif ! convenience vars lc1i=self%lc1i; lc2i=self%lc2i; lc3i=self%lc3i; @@ -898,21 +956,64 @@ end subroutine set_datainow !> deallocate memory and dissociated pointers for generic array data subroutine dissociate_pointers(self) class(inputdata), intent(inout) :: self + integer :: i + + ! Some extensions allocate only current-time storage or stop after dimensions. + ! Deallocate owners individually, never the aliases in the derived types. + if (associated(self%lc1)) deallocate(self%lc1) + if (associated(self%lc2)) deallocate(self%lc2) + if (associated(self%lc3)) deallocate(self%lc3) + if (associated(self%coord1)) deallocate(self%coord1) + if (associated(self%coord2)) deallocate(self%coord2) + if (associated(self%coord3)) deallocate(self%coord3) + if (associated(self%coord1i)) deallocate(self%coord1i) + if (associated(self%coord2i)) deallocate(self%coord2i) + if (associated(self%coord3i)) deallocate(self%coord3i) + if (associated(self%coord1iax1)) deallocate(self%coord1iax1) + if (associated(self%coord2iax2)) deallocate(self%coord2iax2) + if (associated(self%coord3iax3)) deallocate(self%coord3iax3) + if (associated(self%coord2iax23)) deallocate(self%coord2iax23) + if (associated(self%coord3iax23)) deallocate(self%coord3iax23) + if (associated(self%coord1iax12)) deallocate(self%coord1iax12) + if (associated(self%coord2iax12)) deallocate(self%coord2iax12) + if (associated(self%coord1iax13)) deallocate(self%coord1iax13) + if (associated(self%coord3iax13)) deallocate(self%coord3iax13) + + if (associated(self%data0D)) deallocate(self%data0D) + if (associated(self%data1Dax1)) deallocate(self%data1Dax1) + if (associated(self%data1Dax2)) deallocate(self%data1Dax2) + if (associated(self%data1Dax3)) deallocate(self%data1Dax3) + if (associated(self%data2Dax23)) deallocate(self%data2Dax23) + if (associated(self%data2Dax12)) deallocate(self%data2Dax12) + if (associated(self%data2Dax13)) deallocate(self%data2Dax13) + if (associated(self%data3D)) deallocate(self%data3D) + if (associated(self%data0Di)) deallocate(self%data0Di) + if (associated(self%data1Dax1i)) deallocate(self%data1Dax1i) + if (associated(self%data1Dax2i)) deallocate(self%data1Dax2i) + if (associated(self%data1Dax3i)) deallocate(self%data1Dax3i) + if (associated(self%data2Dax23i)) deallocate(self%data2Dax23i) + if (associated(self%data2Dax12i)) deallocate(self%data2Dax12i) + if (associated(self%data2Dax13i)) deallocate(self%data2Dax13i) + if (associated(self%data3Di)) deallocate(self%data3Di) + if (associated(self%data0Dinow)) deallocate(self%data0Dinow) + if (associated(self%data1Dax1inow)) deallocate(self%data1Dax1inow) + if (associated(self%data1Dax2inow)) deallocate(self%data1Dax2inow) + if (associated(self%data1Dax3inow)) deallocate(self%data1Dax3inow) + if (associated(self%data2Dax23inow)) deallocate(self%data2Dax23inow) + if (associated(self%data2Dax12inow)) deallocate(self%data2Dax12inow) + if (associated(self%data2Dax13inow)) deallocate(self%data2Dax13inow) + if (associated(self%data3Dinow)) deallocate(self%data3Dinow) + do i=1,size(self%coverage) + if (allocated(self%coverage(i)%valid)) deallocate(self%coverage(i)%valid) + end do - if (self%flagalloc) then - deallocate(self%data0D) - deallocate(self%data1Dax1, self%data1Dax2, self%data1Dax3) - deallocate(self%data2Dax23, self%data2Dax12, self%data2Dax13) - deallocate(self%data3D) - - deallocate(self%data0Di) - deallocate(self%data1Dax1i, self%data1Dax2i, self%data1Dax3i) - deallocate(self%data2Dax23i, self%data2Dax12i, self%data2Dax13i) - deallocate(self%data3Di) - end if - + self%flagdatasize=.false. + self%flagsizes=.false. self%flagalloc=.false. self%flagprimed=.false. self%flagcoordsi=.false. + self%flagfirst=.true. + self%spatial_missing_count=0 + self%coverage_warning_sent=.false. end subroutine dissociate_pointers end module inputdataobj diff --git a/src/inputdata/neutraldata2Dobj.f90 b/src/inputdata/neutraldata2Dobj.f90 index 3ce007214..be75d52f6 100644 --- a/src/inputdata/neutraldata2Dobj.f90 +++ b/src/inputdata/neutraldata2Dobj.f90 @@ -343,13 +343,19 @@ subroutine dissociate_neutral2D_pointers(self) call self%dissociate_neutral_pointers() ! now deallocate arrays specific to this extension - deallocate(self%proj_ezp_e1,self%proj_ezp_e2,self%proj_ezp_e3) - deallocate(self%proj_ehorzp_e1,self%proj_ehorzp_e2,self%proj_ehorzp_e3) - deallocate(self%horzimat,self%zimat) + if (allocated(self%proj_ezp_e1)) deallocate(self%proj_ezp_e1) + if (allocated(self%proj_ezp_e2)) deallocate(self%proj_ezp_e2) + if (allocated(self%proj_ezp_e3)) deallocate(self%proj_ezp_e3) + if (allocated(self%proj_ehorzp_e1)) deallocate(self%proj_ehorzp_e1) + if (allocated(self%proj_ehorzp_e2)) deallocate(self%proj_ehorzp_e2) + if (allocated(self%proj_ehorzp_e3)) deallocate(self%proj_ehorzp_e3) + if (allocated(self%horzimat)) deallocate(self%horzimat) + if (allocated(self%zimat)) deallocate(self%zimat) ! set pointers to null nullify(self%horzi,self%zi); nullify(self%horzn,self%zn); + nullify(self%lhorzn,self%lxn,self%lzn) nullify(self%dnO,self%dnN2,self%dnO2,self%dvnz,self%dvnhorz,self%dTn) end subroutine dissociate_neutral2D_pointers end module neutraldata2Dobj diff --git a/src/inputdata/neutraldata3Dobj_fclaw.f90 b/src/inputdata/neutraldata3Dobj_fclaw.f90 index c3f3ca54d..738781d0f 100644 --- a/src/inputdata/neutraldata3Dobj_fclaw.f90 +++ b/src/inputdata/neutraldata3Dobj_fclaw.f90 @@ -43,6 +43,7 @@ module neutraldata3Dobj_fclaw procedure :: get_locationsi ! get a list of interpolation sites that are in bounds with regards to the neutral model procedure :: get_datainow_ptr ! grab a pointer to where data need to be fed procedure :: set_datainow ! place a set of interpolated data into the data array at indices corresponding to locations + procedure :: dissociate_fclaw_pointers ! Defined in class extensions !procedure :: rotate_winds ! FIXME: hardcoded axisymmetric @@ -64,6 +65,21 @@ module neutraldata3Dobj_fclaw contains + subroutine dissociate_fclaw_pointers(self) + class(neutraldata3D_fclaw), intent(inout) :: self + + call self%dissociate_pointers() + call self%dissociate_neutral_pointers() + if (associated(self%zlocsi)) deallocate(self%zlocsi) + if (associated(self%xlocsi)) deallocate(self%xlocsi) + if (associated(self%ylocsi)) deallocate(self%ylocsi) + if (associated(self%ilocsi)) deallocate(self%ilocsi) + if (associated(self%dataxyzinow)) deallocate(self%dataxyzinow) + nullify(self%lxn,self%lyn,self%lzn,self%xn,self%yn,self%zn,self%xi,self%yi,self%zi) + nullify(self%dnO,self%dnN2,self%dnO2,self%dvnz,self%dvnx,self%dvny,self%dTn) + end subroutine dissociate_fclaw_pointers + + !> just force the size flag to be set subroutine set_sizeflag(self,x) class(neutraldata3D_fclaw), intent(inout) :: self diff --git a/src/inputdata/neutraldata3Dobj_fclaw_3Dx.f90 b/src/inputdata/neutraldata3Dobj_fclaw_3Dx.f90 index c2c4b38a4..1f0c672e1 100644 --- a/src/inputdata/neutraldata3Dobj_fclaw_3Dx.f90 +++ b/src/inputdata/neutraldata3Dobj_fclaw_3Dx.f90 @@ -260,48 +260,6 @@ end subroutine set_coordsi_neu3D_fclaw subroutine destructor(self) type(neutraldata3D_fclaw_3Dx) :: self - ! deallocate arrays from base inputdata class - !call self%dissociate_pointers() - - ! null pointers specific to parent neutraldata class - !call self%dissociate_neutral_pointers() - -! ! I don't know why this causes a segfault... -! if (associated(self%zlocsi)) deallocate(self%zlocsi) -! if (associated(self%xlocsi)) deallocate(self%xlocsi) -! if (associated(self%ylocsi)) deallocate(self%ylocsi) -! if (associated(self%ilocsi)) deallocate(self%ilocsi) -! if (associated(self%dataxyzinow)) deallocate(self%dataxyzinow) - - ! due to the nature of this object we cannot rely on base class deallocation - deallocate(self%data0Dinow) - deallocate(self%data1Dax1inow, self%data1Dax2inow, self%data1Dax3inow) - deallocate(self%data2Dax23inow, self%data2Dax12inow, self%data2Dax13inow) - deallocate(self%data3Dinow) - deallocate(self%coord1i,self%coord2i,self%coord3i) - - ! now deallocate arrays specific to this extension - deallocate(self%proj_ezp_e1,self%proj_ezp_e2,self%proj_ezp_e3) - deallocate(self%proj_eyp_e1,self%proj_eyp_e2,self%proj_eyp_e3) - deallocate(self%proj_exp_e1,self%proj_exp_e2,self%proj_exp_e3) - deallocate(self%ximat,self%yimat,self%zimat) - - ! FIXME: axisymmetric - !deallocate(self%proj_ehorzp_e1,self%proj_ehorzp_e2,self%proj_ehorzp_e3) - - ! root has some extra data -! if (mpi_cfg%myid==0) then -! deallocate(self%extents,self%indx,self%slabsizes) -! deallocate(self%xnall,self%ynall) -! end if - - ! set pointers to null - nullify(self%xi,self%yi,self%zi); - !nullify(self%xn,self%yn,self%zn); - !nullify(self%dnO,self%dnN2,self%dnO2,self%dvnz,self%dvnx,self%dvny,self%dTn) - - self%flagalloc=.false. - self%flagprimed=.false. - self%flagcoordsi=.false. + call self%dissociate_fclaw_pointers() end subroutine destructor end module neutraldata3Dobj_fclaw_3Dx diff --git a/src/inputdata/neutraldata3Dobj_fclaw_axisymm.f90 b/src/inputdata/neutraldata3Dobj_fclaw_axisymm.f90 index 07fc398f0..e62d4be53 100644 --- a/src/inputdata/neutraldata3Dobj_fclaw_axisymm.f90 +++ b/src/inputdata/neutraldata3Dobj_fclaw_axisymm.f90 @@ -260,51 +260,9 @@ end subroutine rotate_winds subroutine destructor(self) type(neutraldata3D_fclaw_axisymm) :: self - deallocate(self%coord1,self%coord2,self%coord3) - deallocate(self%lc1,self%lc2,self%lc3) - - ! deallocate arrays from base inputdata class - !call self%dissociate_pointers() - - ! null pointers specific to parent neutraldata class - !call self%dissociate_neutral_pointers() - -! ! I don't know why this causes a segfault... -! if (associated(self%zlocsi)) deallocate(self%zlocsi) -! if (associated(self%xlocsi)) deallocate(self%xlocsi) -! if (associated(self%ylocsi)) deallocate(self%ylocsi) -! if (associated(self%ilocsi)) deallocate(self%ilocsi) -! if (associated(self%dataxyzinow)) deallocate(self%dataxyzinow) - - ! due to the nature of this object we cannot rely on base class deallocation - deallocate(self%data0Dinow) - deallocate(self%data1Dax1inow, self%data1Dax2inow, self%data1Dax3inow) - deallocate(self%data2Dax23inow, self%data2Dax12inow, self%data2Dax13inow) - deallocate(self%data3Dinow) - deallocate(self%coord1i,self%coord2i,self%coord3i) - - ! now deallocate arrays specific to this extension - deallocate(self%proj_ezp_e1,self%proj_ezp_e2,self%proj_ezp_e3) - deallocate(self%proj_eyp_e1,self%proj_eyp_e2,self%proj_eyp_e3) - deallocate(self%proj_exp_e1,self%proj_exp_e2,self%proj_exp_e3) - deallocate(self%ximat,self%yimat,self%zimat) - - ! FIXME: axisymmetric - deallocate(self%proj_ehorzp_e1,self%proj_ehorzp_e2,self%proj_ehorzp_e3) - - ! root has some extra data -! if (mpi_cfg%myid==0) then -! deallocate(self%extents,self%indx,self%slabsizes) -! deallocate(self%xnall,self%ynall) -! end if - - ! set pointers to null - nullify(self%xi,self%yi,self%zi); - !nullify(self%xn,self%yn,self%zn); - !nullify(self%dnO,self%dnN2,self%dnO2,self%dvnz,self%dvnx,self%dvny,self%dTn) - - self%flagalloc=.false. - self%flagprimed=.false. - self%flagcoordsi=.false. +call self%dissociate_fclaw_pointers() +if (allocated(self%proj_ehorzp_e1)) deallocate(self%proj_ehorzp_e1) +if (allocated(self%proj_ehorzp_e2)) deallocate(self%proj_ehorzp_e2) +if (allocated(self%proj_ehorzp_e3)) deallocate(self%proj_ehorzp_e3) end subroutine destructor end module neutraldata3Dobj_fclaw_axisymm diff --git a/src/inputdata/neutraldata3Dobj_geog_mpi.f90 b/src/inputdata/neutraldata3Dobj_geog_mpi.f90 index 4a3c20bae..15bea23c0 100644 --- a/src/inputdata/neutraldata3Dobj_geog_mpi.f90 +++ b/src/inputdata/neutraldata3Dobj_geog_mpi.f90 @@ -159,21 +159,28 @@ subroutine destructor(self) ! null pointers specific to parent neutraldata class call self%dissociate_neutral_pointers() - ! now deallocate arrays specific to this extension - deallocate(self%proj_ezp_e1,self%proj_ezp_e2,self%proj_ezp_e3) - deallocate(self%proj_eyp_e1,self%proj_eyp_e2,self%proj_eyp_e3) - deallocate(self%proj_exp_e1,self%proj_exp_e2,self%proj_exp_e3) - deallocate(self%ximat,self%yimat,self%zimat) - - ! root has some extra data - if (mpi_cfg%myid==0) then - deallocate(self%extents,self%indx,self%slabsizes) - deallocate(self%xnall,self%ynall) - end if + if (allocated(self%proj_ezp_e1)) deallocate(self%proj_ezp_e1) + if (allocated(self%proj_ezp_e2)) deallocate(self%proj_ezp_e2) + if (allocated(self%proj_ezp_e3)) deallocate(self%proj_ezp_e3) + if (allocated(self%proj_eyp_e1)) deallocate(self%proj_eyp_e1) + if (allocated(self%proj_eyp_e2)) deallocate(self%proj_eyp_e2) + if (allocated(self%proj_eyp_e3)) deallocate(self%proj_eyp_e3) + if (allocated(self%proj_exp_e1)) deallocate(self%proj_exp_e1) + if (allocated(self%proj_exp_e2)) deallocate(self%proj_exp_e2) + if (allocated(self%proj_exp_e3)) deallocate(self%proj_exp_e3) + if (allocated(self%ximat)) deallocate(self%ximat) + if (allocated(self%yimat)) deallocate(self%yimat) + if (allocated(self%zimat)) deallocate(self%zimat) + if (allocated(self%extents)) deallocate(self%extents) + if (allocated(self%indx)) deallocate(self%indx) + if (allocated(self%slabsizes)) deallocate(self%slabsizes) + if (allocated(self%xnall)) deallocate(self%xnall) + if (allocated(self%ynall)) deallocate(self%ynall) ! set pointers to null nullify(self%xi,self%yi,self%zi); nullify(self%xn,self%yn,self%zn); + nullify(self%lxn,self%lyn,self%lzn) nullify(self%dnO,self%dnN2,self%dnO2,self%dvnz,self%dvnx,self%dvny,self%dTn) end subroutine destructor diff --git a/src/inputdata/neutraldata3Dobj_geom_mpi.f90 b/src/inputdata/neutraldata3Dobj_geom_mpi.f90 index de52eabb4..50fa3b09f 100644 --- a/src/inputdata/neutraldata3Dobj_geom_mpi.f90 +++ b/src/inputdata/neutraldata3Dobj_geom_mpi.f90 @@ -150,21 +150,28 @@ subroutine destructor(self) ! null pointers specific to parent neutraldata class call self%dissociate_neutral_pointers() - ! now deallocate arrays specific to this extension - deallocate(self%proj_ezp_e1,self%proj_ezp_e2,self%proj_ezp_e3) - deallocate(self%proj_eyp_e1,self%proj_eyp_e2,self%proj_eyp_e3) - deallocate(self%proj_exp_e1,self%proj_exp_e2,self%proj_exp_e3) - deallocate(self%ximat,self%yimat,self%zimat) - - ! root has some extra data - if (mpi_cfg%myid==0) then - deallocate(self%extents,self%indx,self%slabsizes) - deallocate(self%xnall,self%ynall) - end if + if (allocated(self%proj_ezp_e1)) deallocate(self%proj_ezp_e1) + if (allocated(self%proj_ezp_e2)) deallocate(self%proj_ezp_e2) + if (allocated(self%proj_ezp_e3)) deallocate(self%proj_ezp_e3) + if (allocated(self%proj_eyp_e1)) deallocate(self%proj_eyp_e1) + if (allocated(self%proj_eyp_e2)) deallocate(self%proj_eyp_e2) + if (allocated(self%proj_eyp_e3)) deallocate(self%proj_eyp_e3) + if (allocated(self%proj_exp_e1)) deallocate(self%proj_exp_e1) + if (allocated(self%proj_exp_e2)) deallocate(self%proj_exp_e2) + if (allocated(self%proj_exp_e3)) deallocate(self%proj_exp_e3) + if (allocated(self%ximat)) deallocate(self%ximat) + if (allocated(self%yimat)) deallocate(self%yimat) + if (allocated(self%zimat)) deallocate(self%zimat) + if (allocated(self%extents)) deallocate(self%extents) + if (allocated(self%indx)) deallocate(self%indx) + if (allocated(self%slabsizes)) deallocate(self%slabsizes) + if (allocated(self%xnall)) deallocate(self%xnall) + if (allocated(self%ynall)) deallocate(self%ynall) ! set pointers to null nullify(self%xi,self%yi,self%zi); nullify(self%xn,self%yn,self%zn); + nullify(self%lxn,self%lyn,self%lzn) nullify(self%dnO,self%dnN2,self%dnO2,self%dvnz,self%dvnx,self%dvny,self%dTn) end subroutine destructor end module neutraldata3Dobj_geom_mpi diff --git a/src/inputdata/neutraldataBGobj.f90 b/src/inputdata/neutraldataBGobj.f90 index 22d2bd7c6..f1fe1e1f4 100644 --- a/src/inputdata/neutraldataBGobj.f90 +++ b/src/inputdata/neutraldataBGobj.f90 @@ -326,13 +326,17 @@ end subroutine load_data_neutralBG subroutine destructor(self) type(neutraldataBG), intent(inout) :: self - if (self%flagcoordsi) then - ! in addition to the normal coordsi allocatables we also have projections for this extension - deallocate(self%proj_ezp_e1,self%proj_ezp_e2,self%proj_ezp_e3) - deallocate(self%proj_eyp_e1,self%proj_eyp_e2,self%proj_eyp_e3) - deallocate(self%proj_exp_e1,self%proj_exp_e2,self%proj_exp_e3) - end if - call self%dissociate_pointers() + if (allocated(self%proj_ezp_e1)) deallocate(self%proj_ezp_e1) + if (allocated(self%proj_ezp_e2)) deallocate(self%proj_ezp_e2) + if (allocated(self%proj_ezp_e3)) deallocate(self%proj_ezp_e3) + if (allocated(self%proj_eyp_e1)) deallocate(self%proj_eyp_e1) + if (allocated(self%proj_eyp_e2)) deallocate(self%proj_eyp_e2) + if (allocated(self%proj_eyp_e3)) deallocate(self%proj_eyp_e3) + if (allocated(self%proj_exp_e1)) deallocate(self%proj_exp_e1) + if (allocated(self%proj_exp_e2)) deallocate(self%proj_exp_e2) + if (allocated(self%proj_exp_e3)) deallocate(self%proj_exp_e3) + nullify(self%llon,self%llat,self%lalt,self%altp,self%glonp,self%glatp) + nullify(self%natmp,self%natmiprev,self%natminext,self%natminow,self%alti,self%gloni,self%glati) end subroutine destructor end module neutraldataBGobj diff --git a/src/io/CMakeLists.txt b/src/io/CMakeLists.txt index 4b3e9bc92..921813e7a 100644 --- a/src/io/CMakeLists.txt +++ b/src/io/CMakeLists.txt @@ -11,13 +11,16 @@ target_link_libraries(errors PRIVATE const h5fortran::h5fortran) # --- config add_library(gemini3d_config OBJECT config.f90 config_nml.f90 config_ini.f90) -target_link_libraries(gemini3d_config PRIVATE const gemini3d_sysinfo +target_link_libraries(gemini3d_config PRIVATE const timeutils gemini3d_sysinfo ffilesystem::filesystem ) install(FILES ${PROJECT_BINARY_DIR}/include/gemini3d_config.mod TYPE INCLUDE) # --- io +add_library(atomic_file OBJECT atomic_file.f90 atomic_file.c) +add_library(restart_runtime OBJECT restart_runtime.f90) +target_link_libraries(restart_runtime PRIVATE atomic_file const gemini3d_config timeutils mpimod h5fortran::h5fortran MPI::MPI_Fortran) configure_file(output.in.f90 output.f90 @ONLY) add_library(io OBJECT io.f90 ${CMAKE_CURRENT_BINARY_DIR}/output.f90 aurora.f90 aurora_hdf5.f90 @@ -30,7 +33,7 @@ $ ) target_link_libraries(io PRIVATE -calculus gemini3d_config const reader grid mpimod sanity_check timeutils gemini_work_def +calculus gemini3d_config const reader grid mpimod sanity_check timeutils gemini_work_def atomic_file restart_runtime h5fortran::h5fortran ffilesystem::filesystem ) diff --git a/src/io/atomic_file.c b/src/io/atomic_file.c new file mode 100644 index 000000000..537711fbf --- /dev/null +++ b/src/io/atomic_file.c @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +#include +#include +#ifdef _WIN32 +#include +#include +#include +#include +#include +#else +#include +#endif + +int gemini_stage_create(char *path) { +#ifdef _WIN32 + if (_mktemp_s(path, strlen(path) + 1)) return -1; + return _open(path, _O_CREAT | _O_EXCL | _O_RDWR | _O_BINARY, _S_IREAD | _S_IWRITE); +#else + return mkstemp(path); +#endif +} +int gemini_stage_close(int fd) { +#ifdef _WIN32 + return _close(fd); +#else + return close(fd); +#endif +} +int gemini_stage_publish(const char *old_path, const char *new_path) { +#ifdef _WIN32 + return MoveFileExA(old_path, new_path, MOVEFILE_REPLACE_EXISTING) ? 0 : -1; +#else + return rename(old_path, new_path); +#endif +} diff --git a/src/io/atomic_file.f90 b/src/io/atomic_file.f90 new file mode 100644 index 000000000..8e27e6277 --- /dev/null +++ b/src/io/atomic_file.f90 @@ -0,0 +1,44 @@ +! SPDX-License-Identifier: Apache-2.0 +module atomic_file +! Same-directory publication on the supported POSIX research platform. +! Atomic visibility does not imply durability across power loss. +use, intrinsic :: iso_c_binding, only: c_int, c_char, c_null_char +implicit none (type, external) +private +public :: stage_file, publish_file +interface + function c_mkstemp(template) bind(C,name='gemini_stage_create') result(fd) + import c_int,c_char + character(c_char), intent(inout) :: template(*) + integer(c_int) :: fd + end function + function c_close(fd) bind(C,name='gemini_stage_close') result(status) + import c_int + integer(c_int), value :: fd + integer(c_int) :: status + end function + function c_rename(old,new) bind(C,name='gemini_stage_publish') result(status) + import c_int,c_char + character(c_char), intent(in) :: old(*),new(*) + integer(c_int) :: status + end function +end interface +contains +function stage_file(final) result(temporary) + character(*), intent(in) :: final + character(:), allocatable :: temporary,template + integer(c_int) :: fd,status + template=final//'.partial.XXXXXX'//c_null_char + fd=c_mkstemp(template) + if(fd<0) error stop 'Cannot reserve checkpoint staging file: '//final + status=c_close(fd) + if(status/=0) error stop 'Cannot close checkpoint staging descriptor' + temporary=template(:len(template)-1) +end function +subroutine publish_file(temporary,final) + character(*), intent(in) :: temporary,final + integer(c_int) :: status + status=c_rename(temporary//c_null_char,final//c_null_char) + if(status/=0) error stop 'Atomic checkpoint publication failed: '//final +end subroutine +end module diff --git a/src/io/config.f90 b/src/io/config.f90 index e419ea392..9d5125c78 100644 --- a/src/io/config.f90 +++ b/src/io/config.f90 @@ -1,3 +1,4 @@ +! Audit modification 2026-09-16: explicit MSIS00 default. module gemini3d_config use filesystem, only: suffix @@ -9,14 +10,16 @@ module gemini3d_config type :: gemini_cfg !> basic simulation information (base) - integer, dimension(3) :: ymd0 - real(wp) :: UTsec0, tdur, dtout - real(wp) :: activ(3) - real(wp) :: tcfl - real(wp) :: Teinf - integer :: potsolve,flagperiodic,flagoutput + integer, dimension(3) :: ymd0=0 + real(wp) :: UTsec0=0, tdur=0, dtout=0 + real(wp) :: activ(3)=0 + real(wp) :: tcfl=0 + real(wp) :: Teinf=0 + integer :: potsolve=1,flagperiodic=0,flagoutput=1 logical :: nooutput = .false. logical :: dryrun = .false. + ! Missing spatial coverage is an error unless explicitly allowed and flagged. + logical :: allow_missing_spatial = .false. !> file information (files) character(:), allocatable :: infile,outdir,indatsize,indatgrid,indatfile,out_format, & @@ -25,7 +28,7 @@ module gemini3d_config character(:), allocatable :: git_revision !> neutral atmospheric perturbations - integer :: flagdneu ! whether or not to include neutral perturbations from input files + integer :: flagdneu=0 ! whether or not to include neutral perturbations from input files character(:), allocatable :: sourcedir ! where the neutral input files are located integer :: interptype = 0 ! assumptions to be used when interpolating neutrals: 0-cartesian 2D, 1-axisymmetric 2D, 3 - cartesian 3D real(wp) :: sourcemlat = 0,sourcemlon = 0 ! source latitude and longitude @@ -33,12 +36,12 @@ module gemini3d_config real(wp) :: dxn = 0,drhon = 0,dzn = 0 ! dx,dy (or drho),dz for neutral inputs !> preciptiation file inputs - integer :: flagprecfile ! whether or not we have precipitation input from a file + integer :: flagprecfile=0 ! whether or not we have precipitation input from a file character(:), allocatable :: precdir ! location of precipitation input data real(wp) :: dtprec = 0 ! time step between precipitation inputs !> electric field file inputs - integer :: flagE0file ! whether or not to have electric field file input + integer :: flagE0file=0 ! whether or not to have electric field file input character(:), allocatable :: E0dir ! location of electric field input data real(wp) :: dtE0 = 0 ! time step between electric field inputs @@ -53,8 +56,8 @@ module gemini3d_config real(wp) :: dtneuBGfile=0 !> GLOW parameters - integer :: flagglow ! whether or not to use glow to compute impact ionization - real(wp) :: dtglow, dtglowout ! time step between GLOW updates and outputs for GLOW emissions + integer :: flagglow=0 ! whether or not to use glow to compute impact ionization + real(wp) :: dtglow=0, dtglowout=0 ! time step between GLOW updates and outputs for GLOW emissions !> fang parameters integer :: flag_fang = 2008 ! configure Fang ionization model @@ -71,7 +74,7 @@ module gemini3d_config !> varying neutral atmosphere background logical :: flagneuBG = .false. ! whether or not to allow MSIS to be called to update neutral background real(wp) :: dtneuBG = 900._wp ! approximate time between MSIS calls - integer :: msis_version + integer :: msis_version = 0 !> background preciptation real(wp) :: PhiWBG = 1e-3_wp ! background total energy flux in mW/m^2 @@ -155,6 +158,23 @@ subroutine read_configfile(cfg, verbose) case default error stop 'ERROR:gemini3d:config: not sure how to read Gemini3D configuration file: ' // cfg%infile end select + call filename_cadence(cfg%dtout, "dtout") + if (cfg%flagglow /= 0) call filename_cadence(cfg%dtglowout, "dtglowout") + if (cfg%flagprecfile /= 0) call filename_cadence(cfg%dtprec, "dtprec") + if (cfg%flagE0file /= 0) call filename_cadence(cfg%dtE0, "dtE0") + if (cfg%flagdneu /= 0) call filename_cadence(cfg%dtneu, "dtneu") + if (cfg%flagsolfluxfile /= 0) call filename_cadence(cfg%dtsolflux, "dtsolflux") + if (cfg%flagneutralBGfile /= 0) call filename_cadence(cfg%dtneuBGfile, "dtneuBGfile") end subroutine read_configfile + subroutine filename_cadence(value, name) + use, intrinsic :: ieee_arithmetic, only : ieee_is_finite + real(wp), intent(in) :: value + character(*), intent(in) :: name + + ! Preserve legacy filenames: they round timestamps to 10 ms, not microseconds. + if (.not. ieee_is_finite(value)) error stop "config: nonfinite filename cadence: " // name + if (value < 0.01_wp) error stop "config: filename cadence must be at least 0.01 seconds: " // name + end subroutine filename_cadence + end module gemini3d_config diff --git a/src/io/config_nml.f90 b/src/io/config_nml.f90 index b68d5ed1c..d1cc1bf18 100644 --- a/src/io/config_nml.f90 +++ b/src/io/config_nml.f90 @@ -1,9 +1,13 @@ +! Audit modification 2026-09-16: deterministic namelist defaults, robust headers and required-value checks. +! Audit modification 2026-09-16: preserve the positive real64 density floor submodule(gemini3d_config) config_nml use, intrinsic :: iso_fortran_env, only : stderr => error_unit use gemini3d_sysinfo, only : expand_envvar, get_compiler_vendor use filesystem, only : absolute use phys_consts, only: mindens, mindensnull, mindensdiv +use timeutils, only: ymd2doy +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite implicit none (type, external) @@ -15,6 +19,7 @@ !! past the group of interest it will (may?) miss that group and return junk. integer :: u, i + logical :: allow_missing_spatial integer :: ymd(3) real(wp) :: UTsec0 @@ -74,7 +79,7 @@ logical :: flagnightQ = .false. ! in case the user wants to specify minimum allowed density - real(wp) :: mindens_userval=1.0e-100 + real(wp) :: mindens_userval=1.0e-100_wp real(wp) :: mindensnull_userval=1.0e-20 real(wp) :: mindensdiv_userval=1.0e-5 @@ -106,8 +111,26 @@ namelist /magpole/ flagmagpole namelist /J1ve/ flagJ1ve namelist /nightQ/ flagnightQ + namelist /input_coverage/ allow_missing_spatial namelist /mindens_user/ mindens_userval, mindensnull_userval, mindensdiv_userval + allow_missing_spatial=.false. + + ! Initialize on every read: declaration initializers have SAVE semantics. + ymd=0; UTsec0=-1; tdur=-1; dtout=-1; activ=-1; tcfl=-1; Teinf=-1 + potsolve=-1; flagperiodic=0; flagoutput=-1; flagcap=0; flag_fang=2008; flagdneu=1 + interptype=0; sourcemlat=0; sourcemlon=0; dtneu=0; dxn=0; drhon=0; dzn=0 + dtprec=0; dtE0=0; dtglow=0; dtglowout=0; dtsolflux=0; dtneuBGfile=0 + indat_size=""; indat_grid=""; indat_file=""; file_format="" + source_dir=""; prec_dir=""; E0_dir=""; solfluxdir=""; neutralBGdir="" + flagEIA=.false.; v0equator=10._wp; flagneuBG=.false.; dtneuBG=900._wp; msis_version=0 + PhiWBG=1e-3_wp; W0BG=3000._wp; flagJpar=.true.; magcap=5._wp + diffsolvetype=2; mcadence=-1; flaggravdrift=.false.; flaglagrangian=.false. + flagdiamagnetic=.false.; flagtwoway=.false.; flagnodivJ0=.false. + diff_num_flux=0; kappa=1e4_wp; bimax_frac=1._wp; W0_char=3000._wp + flagFBI=0; flagevibcool=0; flagmagpole=.false.; flagJ1ve=.false.; flagnightQ=.false. + mindens_userval=1e-100_wp; mindensnull_userval=1e-20_wp; mindensdiv_userval=1e-5_wp + if(.not. allocated(cfg%outdir)) error stop 'gemini3d:config:config_nml please specify simulation output directory' if(.not. allocated(cfg%infile)) error stop 'gemini3d:config:config_nml please specify simulation configuration file config.nml' @@ -115,6 +138,14 @@ read(u, nml=base, iostat=i) call check_nml_io(i, cfg%infile, "base") + if (any(ymd <= 0)) error stop "config: base must specify a positive ymd" + if (ymd2doy(ymd(1),ymd(2),ymd(3))<1) error stop "config: invalid calendar date" + if (.not. all(ieee_is_finite([UTsec0,tdur,dtout,activ,tcfl,Teinf]))) & + error stop "config: nonfinite base value" + if (UTsec0 < 0 .or. UTsec0 >= 86400 .or. tdur <= 0 .or. dtout <= 0) & + error stop "config: require 0<=UTsec0<86400 and positive tdur/dtout" + if (tcfl <= 0 .or. tcfl > 1 .or. Teinf <= 0 .or. any(activ < 0)) & + error stop "config: invalid/missing tcfl, Teinf or activity indices" cfg%ymd0 = ymd cfg%UTsec0 = UTsec0 cfg%tdur = tdur @@ -126,6 +157,9 @@ rewind(u) read(u, nml=flags, iostat=i) call check_nml_io(i, cfg%infile, "flags") + if (.not. any(potsolve == [0,1,3])) & + error stop "config: potsolve must be 0,1,3; inductive mode 2 is not implemented" + if (flagoutput < 1 .or. flagoutput > 3) error stop "config: flagoutput must be 1,2,3" cfg%potsolve = potsolve cfg%flagperiodic = flagperiodic cfg%flagoutput = flagoutput @@ -134,6 +168,9 @@ read(u, nml=files, iostat=i) call check_nml_io(i, cfg%infile, "files") + if (len_trim(indat_size)==0 .or. len_trim(indat_grid)==0 .or. len_trim(indat_file)==0) & + error stop "config: files must specify indat_size, indat_grid, indat_file" + !> auto file_format if not specified if (len_trim(file_format) > 0) then cfg%out_format = trim(file_format) @@ -155,6 +192,7 @@ rewind(u) read(u, nml=neutral_perturb, iostat=i) call check_nml_io(i, cfg%infile, "neutral_perturb") + if (len_trim(source_dir)==0) error stop "config: missing source_dir" cfg%sourcedir = absolute(expand_envvar(source_dir), cfg%outdir) cfg%interptype = interptype cfg%sourcemlat = sourcemlat @@ -173,6 +211,7 @@ rewind(u) read(u, nml=precip, iostat=i) call check_nml_io(i, cfg%infile, "precip") + if (len_trim(prec_dir)==0) error stop "config: missing prec_dir" cfg%precdir = absolute(expand_envvar(prec_dir), cfg%outdir) cfg%dtprec = dtprec else @@ -185,6 +224,7 @@ rewind(u) read(u, nml=efield, iostat=i) call check_nml_io(i, cfg%infile, "efield") + if (len_trim(E0_dir)==0) error stop "config: missing E0_dir" cfg%E0dir = absolute(expand_envvar(E0_dir), cfg%outdir) cfg%dtE0 = dtE0 else @@ -197,6 +237,7 @@ rewind(u) read(u, nml=solflux, iostat=i) call check_nml_io(i, cfg%infile, "solflux") + if (len_trim(solfluxdir)==0) error stop "config: missing solfluxdir" cfg%solfluxdir = absolute(expand_envvar(solfluxdir), cfg%outdir) cfg%dtsolflux = dtsolflux else @@ -222,6 +263,7 @@ rewind(u) read(u, nml=neutralBG_file, iostat=i) call check_nml_io(i, cfg%infile, "neutralBG_file") + if (len_trim(neutralBGdir)==0) error stop "config: missing neutralBGdir" cfg%neutralBGdir = absolute(expand_envvar(neutralBGdir), cfg%outdir) cfg%dtneuBGfile = dtneuBGfile else @@ -423,6 +465,13 @@ cfg%W0_char = 3000._wp ! same as W0BG default endif + if (namelist_exists(u, 'input_coverage')) then + rewind(u) + read(u,nml=input_coverage,iostat=i) + call check_nml_io(i,cfg%infile,'input_coverage') + endif + cfg%allow_missing_spatial=allow_missing_spatial + if (namelist_exists(u, 'mindens_user')) then rewind(u) read(u, nml=mindens_user, iostat=i) @@ -431,14 +480,53 @@ mindensnull = mindensnull_userval mindensdiv = mindensdiv_userval else - mindens = 1.0e-100 + mindens = 1.0e-100_wp mindensnull = 1.0e-20_wp mindensdiv = 1.0e-5_wp end if + if (cfg%flagperiodic<0 .or. cfg%flagperiodic>1) error stop "config: flagperiodic must be 0 or 1" + if (.not.any(cfg%msis_version==[0,21])) error stop "config: msis_version must be 0 or 21" + if (.not.any(cfg%flag_fang==[0,2008,2010])) error stop "config: unsupported Fang model" + if (.not.any(cfg%diffsolvetype==[1,2])) error stop "config: diffusion type must be 1 or 2" + if (cfg%flagcap<0 .or. cfg%flagcap>2) error stop "config: flagcap must be 0,1,2" + if (cfg%flagFBI<0 .or. cfg%flagFBI>2) error stop "config: flagFBI must be 0,1,2" + if (.not.any(cfg%flagevibcool==[0,1])) error stop "config: flagevibcool must be 0 or 1" + if (cfg%mcadence==0) error stop "config: mcadence must be negative (disabled) or positive" + if (.not.all(ieee_is_finite([cfg%magcap,cfg%v0equator,cfg%PhiWBG,cfg%W0BG, & + cfg%kappa,cfg%bimax_frac,cfg%W0_char]))) error stop "config: nonfinite optional value" + if (cfg%magcap<0 .or. cfg%PhiWBG<0 .or. cfg%W0BG<=0) error stop "config: invalid background/capacitance" + if (cfg%diff_num_flux<0 .or. cfg%diff_num_flux>4) error stop "config: unsupported spectral distribution" + if (cfg%kappa<=2 .or. cfg%bimax_frac<=0 .or. cfg%W0_char<=0) error stop "config: invalid Fang parameters" + if (cfg%flagdneu/=0) then + if (.not.any(cfg%interptype==[0,1,3,4,5,6])) error stop "config: unsupported neutral interpolation" + if (.not.all(ieee_is_finite([cfg%sourcemlat,cfg%sourcemlon,cfg%dxn,cfg%drhon,cfg%dzn]))) & + error stop "config: nonfinite neutral geometry" + if (abs(cfg%sourcemlat)>90) error stop "config: neutral latitude outside [-90,90]" + endif + if (cfg%flagprecfile/=0) call positive_cadence(cfg%dtprec, "dtprec") + if (cfg%flagE0file/=0) call positive_cadence(cfg%dtE0, "dtE0") + if (cfg%flagdneu/=0) call positive_cadence(cfg%dtneu, "dtneu") + if (cfg%flagsolfluxfile/=0) call positive_cadence(cfg%dtsolflux, "dtsolflux") + if (cfg%flagneutralBGfile/=0) call positive_cadence(cfg%dtneuBGfile, "dtneuBGfile") + if (cfg%flagneuBG) call positive_cadence(cfg%dtneuBG, "dtneuBG") + if (cfg%flagglow/=0) then + call positive_cadence(cfg%dtglow, "dtglow") + call positive_cadence(cfg%dtglowout, "dtglowout") + endif + if (.not.all(ieee_is_finite([mindens,mindensnull,mindensdiv]))) & + error stop "config: density floors must be finite" + if (min(mindens,mindensnull,mindensdiv)<=0) error stop "config: density floors must be positive" close(u) end procedure read_nml + subroutine positive_cadence(value, name) + real(wp), intent(in) :: value + character(*), intent(in) :: name + if (.not.ieee_is_finite(value)) error stop "config: nonfinite cadence: " // name + if (value<=0 .or. value>86400) error stop "config: cadence must be in (0,86400]: " // name + end subroutine positive_cadence + logical function namelist_exists(u, nml, verbose) !! determines if Namelist exists in file @@ -448,7 +536,8 @@ logical function namelist_exists(u, nml, verbose) logical, intent(in), optional :: verbose logical :: debug - integer :: i + integer :: i, j, code, n + character(:), allocatable :: token character(256) :: line !< arbitrary length debug = .false. @@ -461,11 +550,27 @@ logical function namelist_exists(u, nml, verbose) do read(u, '(A)', iostat=i) line if(i/=0) exit + line = adjustl(line) if (line(1:1) /= '&') cycle - if (line(2:) == nml) then - namelist_exists = .true. - exit - end if + n = scan(line(2:), " " // achar(9) // "/,!=" ) + if (n==0) n=len_trim(line) + token = line(2:n) + do j=1,len(token) + code=iachar(token(j:j)) + if (code>=iachar('A') .and. code<=iachar('Z')) token(j:j)=achar(code+32) + enddo + block + character(len(nml)) :: expected + expected=nml + do j=1,len(expected) + code=iachar(expected(j:j)) + if (code>=iachar('A') .and. code<=iachar('Z')) expected(j:j)=achar(code+32) + enddo + if (token == expected) then + namelist_exists = .true. + exit + endif + end block end do rewind(u) diff --git a/src/io/milestone.f90 b/src/io/milestone.f90 index 28271f55a..11f11c29e 100644 --- a/src/io/milestone.f90 +++ b/src/io/milestone.f90 @@ -1,7 +1,9 @@ submodule (io) milestone use timeutils, only : date_filename,dateinc -use h5fortran, only : h5exist +use h5fortran, only : h5exist, hdf5_file +use hdf5, only: H5T_NATIVE_DOUBLE, h5tequal_f +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite implicit none (type,external) !! external procedures must be explicitly denoted thusly @@ -14,7 +16,12 @@ real(wp) :: UTsec character(:), allocatable :: fn logical :: exists -real(wp) :: tsim +logical :: is_double +real(wp) :: tsim, saved_ut +integer :: saved_ymd(3),schema,complete,realbits,i +integer :: type_error +character(3), parameter :: core_fields(4)=[character(3)::'ns','Ts','vs1','Phi'] +type(hdf5_file) :: hf tsim = 0 tmile = 0 @@ -46,6 +53,38 @@ !! last output file if (h5exist(fn, '/nsall')) then + ! A partially written frame is not a restart checkpoint. + if (.not.h5exist(fn,'/Tsall') .or. .not.h5exist(fn,'/vs1all') .or. & + .not.h5exist(fn,'/Phiall') .or. .not.h5exist(fn,'/time/ymd') .or. & + .not.h5exist(fn,'/time/UThour')) error stop 'Incomplete restart frame: ' // fn + if (h5exist(fn,'/restart_core')) then + if (.not.h5exist(fn,'/restart_core/complete') .or. .not.h5exist(fn,'/restart_core/schema') .or. & + .not.h5exist(fn,'/restart_core/realbits') .or. .not.h5exist(fn,'/restart_core/ns') .or. & + .not.h5exist(fn,'/restart_core/Ts') .or. .not.h5exist(fn,'/restart_core/vs1') .or. & + .not.h5exist(fn,'/restart_core/Phi')) error stop 'Incomplete core restart record: '//fn + call hf%open(fn,action='r') + call hf%read('/restart_core/schema',schema) + call hf%read('/restart_core/complete',complete) + call hf%read('/restart_core/realbits',realbits) + if (schema/=1.or.complete/=1.or.realbits/=storage_size(1._wp)) & + error stop 'Unsupported core restart schema or precision: '//fn + if (hf%ndim('/restart_core/Phi')/=3) error stop 'Core restart potential must be full 3D: '//fn + do i=1,size(core_fields) + call h5tequal_f(hf%dtype('/restart_core/'//trim(core_fields(i))),H5T_NATIVE_DOUBLE,is_double,type_error) + if (type_error/=0) error stop 'Cannot compare core restart datatype: '//fn + if (.not.is_double) error stop 'Core restart fields must contain float64 data: '//fn + enddo + call hf%close() + elseif (cfg%potsolve==3) then + error stop 'Field-resolved restart requires a full 3D potential checkpoint; saved slab is insufficient.' + endif + call hf%open(fn,action='r') + call hf%read('/time/ymd',saved_ymd) + call hf%read('/time/UThour',saved_ut) + call hf%close() + saved_ut=saved_ut*3600._wp + if (.not.ieee_is_finite(saved_ut)) error stop 'Nonfinite restart time: ' // fn + if (any(saved_ymd/=ymd) .or. abs(saved_ut-UTsec)>0.005_wp) error stop 'Restart timestamp mismatch: ' // fn !! this file is milestone ymdmile=ymd UTsecmile=UTsec diff --git a/src/io/plasma_input_hdf5.f90 b/src/io/plasma_input_hdf5.f90 index 2ac8d2e34..010711a25 100644 --- a/src/io/plasma_input_hdf5.f90 +++ b/src/io/plasma_input_hdf5.f90 @@ -2,6 +2,7 @@ use timeutils, only : date_filename use h5fortran, only: hdf5_file +use hdf5, only: H5T_NATIVE_DOUBLE, h5tequal_f use mpimod, only : bcast_send3D_ghost, bcast_send implicit none (type, external) @@ -89,7 +90,10 @@ type(hdf5_file) :: hf integer :: lx1,lx2all,lx3all integer :: ix1 - integer :: lx1in,lx2in,lx3in + integer :: lx1in,lx2in,lx3in, schema, complete, realbits,i + integer :: type_error + logical :: is_double + character(3), parameter :: core_fields(4)=[character(3)::'ns','Ts','vs1','Phi'] real(wp), dimension(:,:), allocatable :: Phislab real(wp), allocatable :: tmpPhi(:) @@ -116,6 +120,25 @@ !> this helps users identify problems with their HDF5 library. call hf%open(indatfile, action='r', debug=.true.) print '(a)', "File handle opened for reading initial conditions: "//indatfile + if (hf%exist('/restart_core')) then + if (.not.hf%exist('/restart_core/complete')) error stop 'Incomplete core restart record' + call hf%read('/restart_core/schema',schema) + call hf%read('/restart_core/complete',complete) + call hf%read('/restart_core/realbits',realbits) + if (schema/=1 .or. complete/=1 .or. realbits/=storage_size(1._wp)) & + error stop 'Unsupported core restart schema or precision' + do i=1,size(core_fields) + call h5tequal_f(hf%dtype('/restart_core/'//trim(core_fields(i))),H5T_NATIVE_DOUBLE,is_double,type_error) + if (type_error/=0) error stop 'Cannot compare core restart datatype' + if (.not.is_double) error stop 'Core restart fields must contain float64 data' + enddo + call hf%read('/restart_core/ns',nsall(1:lx1,1:lx2all,1:lx3all,1:lsp)) + call hf%read('/restart_core/vs1',vs1all(1:lx1,1:lx2all,1:lx3all,1:lsp)) + call hf%read('/restart_core/Ts',Tsall(1:lx1,1:lx2all,1:lx3all,1:lsp)) + call hf%read('/restart_core/Phi',Phiall(1:lx1,1:lx2all,1:lx3all)) + call hf%close() + return + endif call hf%read('/nsall', nsall(1:lx1,1:lx2all,1:lx3all,1:lsp)) call hf%read('/vs1all', vs1all(1:lx1,1:lx2all,1:lx3all,1:lsp)) call hf%read('/Tsall', Tsall(1:lx1,1:lx2all,1:lx3all,1:lsp)) diff --git a/src/io/plasma_output_hdf5.f90 b/src/io/plasma_output_hdf5.f90 index 0255398a5..e1bb7e924 100644 --- a/src/io/plasma_output_hdf5.f90 +++ b/src/io/plasma_output_hdf5.f90 @@ -2,6 +2,8 @@ use timeutils, only : date_filename use h5fortran, only: hdf5_file +use atomic_file, only: publish_file +use restart_runtime, only: runtime_output_path, runtime_output_header implicit none (type, external) @@ -10,14 +12,15 @@ module procedure output_root_stream_mpi_hdf5 !! COLLECT OUTPUT FROM WORKERS AND WRITE TO A FILE USING STREAM I/O. !! STATE VARS ARE EXPECTED INCLUDE GHOST CELLS - character(:), allocatable :: filenamefull + character(:), allocatable :: filenamefull, temporary type(hdf5_file) :: hout !> FIGURE OUT THE FILENAME filenamefull = date_filename(outdir,ymd,UTsec) // '.h5' print *, 'HDF5 Output file name: ', filenamefull - call hout%open(filenamefull, action='w',comp_lvl=comp_lvl) + temporary=runtime_output_path(filenamefull) + call hout%open(temporary, action='w',comp_lvl=comp_lvl) call hout%write("/flagoutput", flagoutput) call hout%write('/time/ymd', ymd) @@ -69,7 +72,22 @@ call hout%write('Phiall', real(Phiall(lx1,1:lx2all,1:lx3all))) end if + if (flagoutput==1) then + ! Analysis arrays retain their historical layout and precision. The core + ! restart record preserves solver precision and the full field potential. + ! This is not a claim that mode-specific auxiliary state is complete. + call hout%write('/restart_core/schema',1) + call hout%write('/restart_core/realbits',storage_size(UTsec)) + call hout%write('/restart_core/ns',nsall(1:lx1,1:lx2all,1:lx3all,:)) + call hout%write('/restart_core/vs1',vs1all(1:lx1,1:lx2all,1:lx3all,:)) + call hout%write('/restart_core/Ts',Tsall(1:lx1,1:lx2all,1:lx3all,:)) + call hout%write('/restart_core/Phi',Phiall(1:lx1,1:lx2all,1:lx3all)) + ! Written last so an interrupted record is rejected on restart. + call hout%write('/restart_core/complete',1) + endif + call runtime_output_header(hout) call hout%close() + call publish_file(temporary,filenamefull) end procedure output_root_stream_mpi_hdf5 end submodule plasma_output_hdf5 diff --git a/src/io/reader_hdf5.f90 b/src/io/reader_hdf5.f90 index 0d52def98..21763c291 100644 --- a/src/io/reader_hdf5.f90 +++ b/src/io/reader_hdf5.f90 @@ -49,8 +49,8 @@ if(hf%exist('/llon')) then call hf%read('/llon', llon) - elseif(hf%exist('/Nlat')) then - call hf%read('/Nlat', llon) + elseif(hf%exist('/Nlon')) then + call hf%read('/Nlon', llon) elseif(hf%exist('/lx3')) then call hf%read('/lx3', llon) else diff --git a/src/io/restart_runtime.f90 b/src/io/restart_runtime.f90 new file mode 100644 index 000000000..a03318a6e --- /dev/null +++ b/src/io/restart_runtime.f90 @@ -0,0 +1,271 @@ +! SPDX-License-Identifier: Apache-2.0 +module restart_runtime +! Opt-in full-step state for fixed-grid, electrostatic FANG/frozen-neutral runs. +! Rank-local records are published before the final root checkpoint name. +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +use phys_consts, only: wp +use gemini3d_config, only: gemini_cfg +use h5fortran, only: hdf5_file +use hdf5, only: H5T_NATIVE_DOUBLE, h5tequal_f +use atomic_file, only: stage_file, publish_file +use timeutils, only: date_filename +use mpimod, only: mpi_cfg +use mpi_f08, only: MPI_COMM_WORLD,MPI_CHARACTER,MPI_Bcast,MPI_Barrier +implicit none (type,external) +private +public :: runtime_select,runtime_read,runtime_save,runtime_restore,runtime_output_header, & + runtime_output_path,runtime_times,runtime_dt,runtime_ready,runtime_exclude_model +logical :: enabled=.false., pending=.false., runtime_ready=.false. +integer, parameter :: runtime_schema=2 +real(wp) :: previous_dt=0, next_output=0, next_glow=0, saved_neutral=0 +integer :: saved_iteration=1 +character(:), allocatable :: input_digest, executable_digest, restore_file, staged_output, state_prefix +character(:), allocatable :: checkpoint_name, restore_checkpoint, restore_generation +contains +subroutine runtime_exclude_model(model) + character(*), intent(in) :: model + character(32) :: value + integer :: status + call get_environment_variable('GEMINI_EXACT_RESTART',value,status=status) + if(status==0.and.trim(value)=='1') & + error stop 'Exact restart research profile excludes model: '//model +end subroutine +subroutine check_mode(cfg) + type(gemini_cfg), intent(in) :: cfg + if(cfg%potsolve/=1.or.cfg%flagcap/=0.or.cfg%flagglow/=0.or.cfg%flagneuBG.or. & + cfg%flagdneu/=0.or.cfg%flagneutralBGfile/=0.or.cfg%flaglagrangian.or.cfg%flagoutput/=1.or. & + cfg%flagsolfluxfile/=0.or.cfg%allow_missing_spatial) & + error stop 'Exact restart profile requires full-output fixed-grid electrostatic FANG and frozen empirical neutrals' + if(storage_size(1._wp)/=64) error stop 'Exact restart profile requires real64' +end subroutine +subroutine runtime_select(cfg) + type(gemini_cfg), intent(in) :: cfg + character(256) :: value + integer :: status,length,i + enabled=.false.;pending=.false.;runtime_ready=.false.;previous_dt=0 + if(allocated(restore_file)) deallocate(restore_file) + if(allocated(restore_checkpoint)) deallocate(restore_checkpoint) + if(allocated(restore_generation)) deallocate(restore_generation) + if(allocated(staged_output)) deallocate(staged_output) + if(allocated(state_prefix)) deallocate(state_prefix) + if(allocated(checkpoint_name)) deallocate(checkpoint_name) + call get_environment_variable('GEMINI_EXACT_RESTART',value,length,status) + if(status==0.and.trim(value)=='1') enabled=.true. + if(.not.enabled) return + call check_mode(cfg) + call get_environment_variable('GEMINI_INPUT_SHA256',value,length,status) + if(status/=0.or.length/=64) error stop 'Exact restart requires the verified-input launcher and GEMINI_INPUT_SHA256' + do i=1,64 + if(index('0123456789abcdef',value(i:i))==0) error stop 'Invalid input SHA256 token' + enddo + input_digest=value(:64) + call get_environment_variable('GEMINI_EXECUTABLE_SHA256',value,length,status) + if(status/=0.or.length/=64) error stop 'Exact restart requires an executable SHA256 token' + do i=1,64 + if(index('0123456789abcdef',value(i:i))==0) error stop 'Invalid executable SHA256 token' + enddo + executable_digest=value(:64) +end subroutine +subroutine runtime_read(core,cfg,t) + real(wp), intent(in) :: t + logical :: exists + character(*), intent(in) :: core + type(gemini_cfg), intent(in) :: cfg + type(hdf5_file) :: f + character(4096) :: prefix,checkpoint + character(64) :: digest + character(16) :: rank + integer :: schema,layout(2),iteration + call f%open(core,action='r') + if(.not.f%exist('/restart_runtime')) then + call f%close() + if(enabled) error stop 'Exact restart requested but full-step runtime state is missing' + return + endif + if(.not.enabled) error stop 'This checkpoint requires the verified exact-restart profile launcher' + call check_mode(cfg) + call f%read('/restart_runtime/schema',schema) + if(schema/=runtime_schema) error stop 'Unsupported runtime checkpoint schema: exact restart requires schema 2' + call f%read('/restart_runtime/layout',layout) + call f%read('/restart_runtime/prefix',prefix) + call f%read('/restart_runtime/checkpoint',checkpoint) + call f%read('/restart_runtime/executable_sha256',digest) + if(digest/=executable_digest) error stop 'Changed restart executable: SHA256 mismatch' + call f%read('/restart_runtime/input_sha256',digest) + call f%close() + if(any(layout/=[mpi_cfg%lid2,mpi_cfg%lid3])) error stop 'Incompatible runtime checkpoint layout' + if(digest/=input_digest) error stop 'Changed restart inputs: input SHA256 mismatch' + if(trim(checkpoint)/=checkpoint_basename(core)) error stop 'Runtime checkpoint root identity mismatch' + if(len_trim(checkpoint)==0.or.len_trim(prefix)<=len_trim(checkpoint)+9.or. & + index(prefix,'/')/=0.or.index(prefix,'\')/=0.or.index(prefix,'..')/=0) & + error stop 'Invalid runtime checkpoint prefix' + if(index(trim(prefix),trim(checkpoint)//'.partial.')/=1) error stop 'Runtime checkpoint generation mismatch' + restore_checkpoint=trim(checkpoint) + restore_generation=trim(prefix) + write(rank,'(I8.8)') mpi_cfg%myid + restore_file=cfg%outdir//'/'//trim(prefix)//'.r'//trim(rank)//'.h5' + inquire(file=restore_file,exist=exists) + if(.not.exists) error stop 'Missing runtime state file: '//restore_file + call f%open(restore_file,action='r') + call check_identity(f) + call f%read('/iteration',iteration) + call f%read('/dt',previous_dt) + call f%read('/next_output',next_output) + call f%read('/next_glow',next_glow) + call f%read('/neutral_time',saved_neutral) + if(iteration<1) error stop 'Invalid runtime state metadata' + if(.not.all(ieee_is_finite([previous_dt,next_output,next_glow,saved_neutral])).or.previous_dt<=0) & + error stop 'Invalid runtime checkpoint clock' + if(abs(next_output-(t+cfg%dtout))>1e-5_wp.or.previous_dt>cfg%dtout) & + error stop 'Inconsistent runtime checkpoint clock' + saved_iteration=iteration + call f%close() + pending=.true. +end subroutine +subroutine check_identity(f) + type(hdf5_file), intent(inout) :: f + integer :: schema,rank,layout(2),complete + character(64) :: digest + character(4096) :: checkpoint,generation + call f%read('/schema',schema) + if(schema/=runtime_schema) error stop 'Unsupported runtime state schema: exact restart requires schema 2' + call f%read('/complete',complete) + if(complete/=1) error stop 'Incomplete runtime checkpoint' + call f%read('/rank',rank) + if(rank/=mpi_cfg%myid) error stop 'Runtime state rank mismatch' + call f%read('/layout',layout) + if(any(layout/=[mpi_cfg%lid2,mpi_cfg%lid3])) error stop 'Runtime state layout mismatch' + call f%read('/checkpoint',checkpoint) + if(trim(checkpoint)/=restore_checkpoint) error stop 'Runtime state root identity mismatch' + call f%read('/generation',generation) + if(trim(generation)/=restore_generation) error stop 'Runtime state generation mismatch' + call f%read('/input_sha256',digest) + if(digest/=input_digest) error stop 'Changed restart inputs: runtime state input SHA256 mismatch' + call f%read('/executable_sha256',digest) + if(digest/=executable_digest) error stop 'Changed restart executable: runtime state SHA256 mismatch' +end subroutine +subroutine check_payload(fluid,electro,vi1,vi2,vi3) + real(wp), intent(in) :: fluid(:,:,:,:),electro(:,:,:,:),vi1(:,:,:,:),vi2(:,:,:,:),vi3(:,:,:,:) + if(.not.all(ieee_is_finite(fluid))) error stop 'Nonfinite runtime checkpoint payload: fluid' + if(.not.all(ieee_is_finite(electro))) error stop 'Nonfinite runtime checkpoint payload: electro' + if(.not.all(ieee_is_finite(vi1))) error stop 'Nonfinite runtime checkpoint payload: vi1' + if(.not.all(ieee_is_finite(vi2))) error stop 'Nonfinite runtime checkpoint payload: vi2' + if(.not.all(ieee_is_finite(vi3))) error stop 'Nonfinite runtime checkpoint payload: vi3' +end subroutine +subroutine runtime_times(tout,tglowout) + real(wp), intent(inout) :: tout,tglowout + if(.not.pending) return + tout=next_output;tglowout=next_glow +end subroutine +subroutine runtime_dt(dt,read_saved) + real(wp), intent(inout) :: dt + logical, intent(in) :: read_saved + if(read_saved.and.runtime_ready) then + dt=previous_dt + runtime_ready=.false. + elseif(.not.read_saved) then + previous_dt=dt + endif +end subroutine +subroutine runtime_restore(fluid,electro,vi1,vi2,vi3,iteration,neutral_time) + real(wp), intent(inout) :: fluid(:,:,:,:),electro(:,:,:,:),vi1(:,:,:,:),vi2(:,:,:,:),vi3(:,:,:,:) + integer, intent(inout) :: iteration + real(wp), intent(inout) :: neutral_time + type(hdf5_file) :: f + integer :: i,type_error + logical :: is_double + character(7), parameter :: fields(5)=[character(7)::'fluid','electro','vi1','vi2','vi3'] + if(.not.pending) return + call f%open(restore_file,action='r') + call check_identity(f) + do i=1,size(fields) + call h5tequal_f(f%dtype('/'//trim(fields(i))),H5T_NATIVE_DOUBLE,is_double,type_error) + if(type_error/=0) error stop 'Cannot compare runtime checkpoint datatype' + if(.not.is_double.or.f%ndim('/'//trim(fields(i)))/=4) & + error stop 'Runtime checkpoint requires float64 rank-four state' + enddo + call f%read('/fluid',fluid);call f%read('/electro',electro) + call f%read('/vi1',vi1);call f%read('/vi2',vi2);call f%read('/vi3',vi3) + call f%close() + call check_payload(fluid,electro,vi1,vi2,vi3) + iteration=saved_iteration;neutral_time=saved_neutral + pending=.false.;runtime_ready=.true. +end subroutine +subroutine runtime_save(cfg,ymd,ut,fluid,electro,vi1,vi2,vi3,iteration,neutral_time,tout,tglowout) + type(gemini_cfg), intent(in) :: cfg + integer, intent(in) :: ymd(3),iteration + real(wp), intent(in) :: ut,neutral_time,tout,tglowout + real(wp), intent(in) :: fluid(:,:,:,:),electro(:,:,:,:),vi1(:,:,:,:),vi2(:,:,:,:),vi3(:,:,:,:) + character(:), allocatable :: path,temporary,final,local_checkpoint,local_prefix,local_staged_output + character(4096) :: message + character(16) :: rank + type(hdf5_file) :: f + if(.not.enabled) return + call check_payload(fluid,electro,vi1,vi2,vi3) + final=date_filename(cfg%outdir,ymd,ut)//'.h5' + local_checkpoint=final(scan(final,'/\',back=.true.)+1:) + message='' + if(mpi_cfg%myid==0) then + local_staged_output=stage_file(final) + if(len(local_staged_output)>len(message)) error stop 'Checkpoint path too long' + message=local_staged_output + endif + call MPI_Bcast(message,len(message),MPI_CHARACTER,0,MPI_COMM_WORLD) + local_staged_output=trim(message) + local_prefix=local_staged_output(len_trim(cfg%outdir)+2:) + if(mpi_cfg%myid==0) then + staged_output=local_staged_output + state_prefix=local_prefix + checkpoint_name=local_checkpoint + endif + write(rank,'(I8.8)') mpi_cfg%myid + path=local_staged_output//'.r'//trim(rank)//'.h5' + temporary=stage_file(path) + call f%open(temporary,action='w') + call f%write('/schema',runtime_schema);call f%write('/input_sha256',input_digest) + call f%write('/executable_sha256',executable_digest) + call f%write('/rank',mpi_cfg%myid) + call f%write('/layout',[mpi_cfg%lid2,mpi_cfg%lid3]) + call f%write('/checkpoint',local_checkpoint) + call f%write('/generation',local_prefix) + call f%write('/iteration',iteration);call f%write('/dt',previous_dt) + call f%write('/next_output',tout);call f%write('/next_glow',tglowout) + call f%write('/neutral_time',neutral_time) + call f%write('/fluid',fluid);call f%write('/electro',electro) + call f%write('/vi1',vi1);call f%write('/vi2',vi2);call f%write('/vi3',vi3) + call f%write('/complete',1);call f%close() + call publish_file(temporary,path) + call MPI_Barrier(MPI_COMM_WORLD) +end subroutine +function runtime_output_path(final) result(path) + character(*), intent(in) :: final + character(:), allocatable :: path + if(enabled.and.allocated(staged_output)) then + path=staged_output + else + path=stage_file(final) + endif +end function +subroutine runtime_output_header(f) + type(hdf5_file), intent(inout) :: f + if(.not.enabled.or..not.allocated(state_prefix)) return + call f%write('/restart_runtime/schema',runtime_schema) + call f%write('/restart_runtime/layout',[mpi_cfg%lid2,mpi_cfg%lid3]) + call f%write('/restart_runtime/input_sha256',input_digest) + call f%write('/restart_runtime/executable_sha256',executable_digest) + call f%write('/restart_runtime/prefix',state_prefix) + call f%write('/restart_runtime/checkpoint',checkpoint_name) +end subroutine +function checkpoint_basename(path) result(name) + character(*), intent(in) :: path + character(:), allocatable :: name,clean + integer :: n,last + clean=trim(path) + n=len(clean) + if(n<1) error stop 'Runtime checkpoint root identity mismatch' + if(clean(n:n)=='/'.or.clean(n:n)=='\') error stop 'Runtime checkpoint root identity mismatch' + last=scan(clean,'/\',back=.true.) + name=clean(last+1:n) + if(len_trim(name)==0) error stop 'Runtime checkpoint root identity mismatch' +end function +end module diff --git a/src/io/sanity_check.f90 b/src/io/sanity_check.f90 index 020a10b77..2088ccd2b 100644 --- a/src/io/sanity_check.f90 +++ b/src/io/sanity_check.f90 @@ -1,3 +1,4 @@ +! Audit modification 2026-09-16: check every species; trim only spatial ghost cells module sanity_check !! check that variables are within realm of possible values, !! at least that they're finite (not NaN or infinite) @@ -5,7 +6,7 @@ module sanity_check use, intrinsic :: iso_fortran_env, only : stderr=>error_unit use, intrinsic :: ieee_arithmetic, only : ieee_is_finite,ieee_is_nan -use phys_consts, only : wp +use phys_consts, only : wp,lsp use errors, only : error_stop implicit none (type, external) @@ -27,6 +28,8 @@ pure subroutine ghost_bound(A, j1, k1, j2, k2, j3, k3, j4, k4) if (r > 4 .or. r < 3) error stop "sanity_check:ghost_bound: only for rank 3,4 for now" if (r == 4 .and. .not. (present(j4) .and. present(k4))) error stop "sanity_check:ghost_bound: 4d needs j4, k4" + if (min(size(A,1),size(A,2),size(A,3))<5) & + error stop "sanity_check: missing physical cells or ghost layers" j1 = lbound(A, 1) + ig k1 = ubound(A, 1) - ig j2 = lbound(A, 2) + ig @@ -34,8 +37,10 @@ pure subroutine ghost_bound(A, j1, k1, j2, k2, j3, k3, j4, k4) j3 = lbound(A, 3) + ig k3 = ubound(A, 3) - ig if (r >= 4) then - j4 = lbound(A, 4) + ig - k4 = ubound(A, 4) - ig + if (size(A,4)/=lsp) error stop "sanity_check: incorrect species count" + ! The species dimension has no spatial ghost cells. + j4 = lbound(A, 4) + k4 = ubound(A, 4) endif end subroutine ghost_bound @@ -96,6 +101,8 @@ subroutine check_finite_output(out_dir, t_elapsed, worker_id, vs2,vs3,ns,vs1,Ts, any(Ts(i1:k1, i2:k2, i3:k3, i4:k4)/=Ts(i1:k1, i2:k2, i3:k3, i4:k4)) ) then call error_stop(dump_filename, 'output: non-finite Ts', t_elapsed, worker_id, vs2,vs3,ns,vs1,Ts,Phi,J1,J2,J3) end if + if (any(Ts(i1:k1,i2:k2,i3:k3,i4:k4)<0)) & + call error_stop(dump_filename, 'output: negative temperature', t_elapsed, worker_id, vs2,vs3,ns,vs1,Ts,Phi,J1,J2,J3) call ghost_bound(J1, i1,k1, i2,k2, i3,k3) if (.not.all(ieee_is_finite(J1(i1:k1, i2:k2, i3:k3))) .or. & @@ -142,11 +149,15 @@ subroutine check_finite_plasma(out_dir, ns, vs1, Ts) if (.not.all(ieee_is_finite(Ts(i1:k1, i2:k2, i3:k3, i4:k4)))) & call error_stop(dump_filename, 'input:plasma: non-finite Ts', ns, vs1, Ts) + if (any(Ts(i1:k1,i2:k2,i3:k3,i4:k4)<0)) & + call error_stop(dump_filename, 'input:plasma: negative temperature', ns, vs1, Ts) + if (any(ns(i1:k1, i2:k2, i3:k3, i4:k4) < 0)) & call error_stop(dump_filename, 'input:plasma: negative density Ns', ns, vs1, Ts) - if (maxval(ns(i1:k1, i2:k2, i3:k3, i4:k4)) < 1e3) & - call error_stop(dump_filename, 'input:plasma: too low maximum density', ns, vs1, Ts) + ! A worker can contain only underground/null cells. A local density + ! maximum is not a valid global plausibility test (upstream issue #117). + ! Keep finite/nonnegative checks; physical-domain bounds require a mask. if (maxval(ns(i1:k1, i2:k2, i3:k3, i4:k4)) > 1e16) & call error_stop(dump_filename, 'input:plasma: too high maximum density', ns, vs1, Ts) diff --git a/src/ionization/CMakeLists.txt b/src/ionization/CMakeLists.txt index b81b63885..60da3851e 100644 --- a/src/ionization/CMakeLists.txt +++ b/src/ionization/CMakeLists.txt @@ -37,7 +37,7 @@ else() target_sources(ionization PRIVATE glow_dummy.f90) endif() -target_link_libraries(ionization PRIVATE const meshobj timeutils fang +target_link_libraries(ionization PRIVATE const gemini3d_config meshobj timeutils fang $<$:glow::glow> ) diff --git a/src/ionization/glow_run.in.f90 b/src/ionization/glow_run.in.f90 index 28889804d..530b07a35 100644 --- a/src/ionization/glow_run.in.f90 +++ b/src/ionization/glow_run.in.f90 @@ -58,9 +58,11 @@ character(:), allocatable :: iri90_dir !! glow_data_dir assignment defines the GLOW data directory for consumption by GLOW -glow_data_dir = "@glow_data_dir@" +! Audit correction 2026-09-16: GLOW concatenates filenames directly. +! Its consumers require the trailing slash even if CMake normalizes it away. +glow_data_dir = "@glow_data_dir@/" -iri90_dir = trim(glow_data_dir) // '/iri90/' +iri90_dir = trim(glow_data_dir) // 'iri90/' !! Execute: Allocate arrays in other modules (formerly in common blocks): diff --git a/src/libgemini.f90 b/src/libgemini.f90 index dbbb28eee..bfac2222a 100644 --- a/src/libgemini.f90 +++ b/src/libgemini.f90 @@ -41,6 +41,7 @@ module gemini3d use precipBCs_mod, only: init_precipinput, precipBCs_fileinput, precipBCs use solfluxBCs_mod, only: init_solfluxinput, solfluxBCs_fileinput, solfluxBCs use neutral, only: neutral_info,neutral_info_alloc,neutral_info_dealloc +use restart_runtime, only: runtime_times use neutral_background, only: init_neutral_background use multifluid, only : sweep3_allspec_mass,sweep3_allspec_momentum,sweep3_allspec_energy, & sweep1_allspec_mass,sweep1_allspec_momentum,sweep1_allspec_energy, & @@ -216,6 +217,8 @@ subroutine read_config_in(p,cfg) call find_config(cfg) call read_configfile(cfg, verbose=.false.) call check_input_files(cfg) + else + error stop "read_config_in: fortran_nml=0 is not implemented; provide config.nml" endif !> at this point we can check the input files and make sure we have a well-formed simulation setup @@ -731,6 +734,7 @@ subroutine set_start_values_auxtimevars(t,tout,tglowout) !> Initialize some variables need for time stepping and output ! it = 1; t = 0; tout = t; tglowout = t; tneuBG=t it = 1; tout = t; tglowout = t; tneuBG=t + call runtime_times(tout,tglowout) end subroutine set_start_values_auxtimevars diff --git a/src/libgemini_c.f90 b/src/libgemini_c.f90 index 317eb58f7..e594368d3 100644 --- a/src/libgemini_c.f90 +++ b/src/libgemini_c.f90 @@ -1,3 +1,4 @@ +! Audit modification 2026-09-16: do not read uninitialized output flags ! Copyright 2021 Matthew Zettergren ! Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +23,7 @@ module gemini3d_C use, intrinsic :: iso_fortran_env, only : stderr=>error_unit -use, intrinsic :: iso_c_binding, only : C_INT, C_LOC, c_null_ptr, c_ptr, c_f_pointer, wp => C_DOUBLE +use, intrinsic :: iso_c_binding, only : C_INT, C_LOC, c_null_ptr, c_ptr, c_f_pointer, c_associated, wp => C_DOUBLE use phys_consts, only: lnchem,lwave,lsp use grid, only: lx1,lx2,lx3, detect_gridtype @@ -32,6 +33,8 @@ module gemini3d_C use precipdataobj, only: precipdata use efielddataobj, only: efielddata use neutraldataobj, only: neutraldata +use neutral_background, only: msisinit_in, neutral_background_empirical +use neutral, only: neutral_aggregate use gemini3d_config, only: gemini_cfg use gemini3d, only: c_params, init_precipinput_in, & set_start_values_auxtimevars, set_start_values_auxvars, set_start_timefromcfg, & @@ -54,7 +57,7 @@ module gemini3d_C set_global_boundaries_allspec_in, get_fullgrid_lims_in, get_cfg_timevars,electrodynamics_test, & precip_perturb_in, interp3_in, interp2_in, check_finite_output_in, get_it, itinc, & set_electrodynamics_commtype, init_efieldinput_nompi_in, efield_perturb_nompi_in, & - init_solfluxinput_in, solflux_perturb_in, source_neut_in, set_magnetic_pole_in + init_solfluxinput_in, solflux_perturb_in, source_neut_in, set_magnetic_pole_in, v2grid, v3grid implicit none (type, external) @@ -147,10 +150,11 @@ subroutine gemini_cfg_dealloc_C(cfgC) bind(C, name='gemini_cfg_dealloc_C') type(c_ptr), intent(inout) :: cfgC type(gemini_cfg), pointer :: cfg + if (.not.c_associated(cfgC)) return call c_f_pointer(cfgC,cfg) deallocate(cfg) - cfg=>null() - cfgC=c_loc(cfg) ! send back a null pointer as a precaution + nullify(cfg) + cfgC=c_null_ptr end subroutine gemini_cfg_dealloc_C @@ -164,7 +168,7 @@ subroutine get_config_vars_C(cfgC,flagneuBG,flagdneu,dtneuBG,dtneu) bind(C, name type(gemini_cfg), pointer :: cfg logical :: neuBG - neuBG = flagneuBG /= 0 + neuBG = .false. ! output-only native value call c_f_pointer(cfgC,cfg) call get_config_vars(cfg, neuBG, flagdneu,dtneuBG,dtneu) @@ -232,6 +236,8 @@ subroutine gemini_work_dealloc_C(cfgC,intvarsC) bind(C, name='gemini_work_deallo real(wp), dimension(:,:,:,:), pointer :: electrovars type(gemini_work), pointer :: intvars + if (.not.c_associated(intvarsC)) return + if (.not.c_associated(cfgC)) error stop "gemini_work_dealloc_C: null configuration" call c_f_pointer(cfgC,cfg) call c_f_pointer(intvarsC,intvars) @@ -239,6 +245,7 @@ subroutine gemini_work_dealloc_C(cfgC,intvarsC) bind(C, name='gemini_work_deallo ! when passed back and forth with C so only deallocate the derived types !call gemini_dealloc_nodouble(cfg,intvars) call gemini_work_dealloc(cfg,intvars) + intvarsC=c_null_ptr end subroutine gemini_work_dealloc_C @@ -254,19 +261,20 @@ end subroutine read_fullsize_gridcenter_C !> C wrapper to deallocate grid subroutine gemini_grid_dealloc_C(xtype,xC) bind(C, name='gemini_grid_dealloc_C') - integer, intent(inout) :: xtype + integer(C_INT), intent(inout) :: xtype type(c_ptr), intent(inout) :: xC class(curvmesh), pointer :: x - !print*, 'gemini_grid_dealloc_C: ',xtype + if (.not.c_associated(xC)) return x=>set_gridpointer_dyntype(xtype,xC) call gemini_grid_dealloc(x,xtype,xC) + xC=c_null_ptr end subroutine gemini_grid_dealloc_C !> C wrapper to force generate of grid internal data quantities subroutine gemini_grid_generate_C(xtype,xC) bind(C, name='gemini_grid_generate_C') - integer, intent(inout) :: xtype + integer(C_INT), intent(in) :: xtype type(c_ptr), intent(inout) :: xC class(curvmesh), pointer :: x @@ -277,7 +285,7 @@ end subroutine gemini_grid_generate_C !> C wrapper to force generate of grid internal data quantities subroutine gemini_grid_generate_altnull_C(xtype,xC,altnullC) bind(C, name='gemini_grid_generate_altnull_C') - integer, intent(inout) :: xtype + integer(C_INT), intent(in) :: xtype type(c_ptr), intent(inout) :: xC real(wp), intent(inout) :: altnullC class(curvmesh), pointer :: x @@ -291,11 +299,11 @@ end subroutine gemini_grid_generate_altnull_C subroutine plasma_output_nompi_C(cfgC,ymd,UTsec,fluidvarsC,electrovarsC, & identifier,x1lims,x2lims,x3lims) bind(C,name="plasma_output_nompi_C") type(c_ptr), intent(in) :: cfgC - integer, dimension(3), intent(in) :: ymd + integer(C_INT), dimension(3), intent(in) :: ymd real(wp), intent(in) :: UTsec type(c_ptr), intent(inout) :: fluidvarsC type(c_ptr), intent(inout) :: electrovarsC - integer, intent(in) :: identifier + integer(C_INT), intent(in) :: identifier real(wp), dimension(2), intent(in) :: x1lims,x2lims,x3lims type(gemini_cfg), pointer :: cfg real(wp), dimension(:,:,:,:), pointer :: fluidvars @@ -356,7 +364,7 @@ subroutine get_cfg_timevars_C(cfgC,tmilestone,flagneuBG,dtneuBG,flagdneu,flagout logical :: flagneuBG_f - flagneuBG_f = flagneuBG /= 0 + flagneuBG_f = .false. ! output-only native value call c_f_pointer(cfgC,cfg) call get_cfg_timevars(cfg,tmilestone, flagneuBG_f, dtneuBG,flagdneu,flagoutput) @@ -423,13 +431,14 @@ end subroutine init_efieldinput_nompi_C !> initialization procedure needed for MSIS 2.0 -! subroutine msisinit_C(cfgC) bind(C, name='msisinit_C') -! type(c_ptr), intent(in) :: cfgC -! type(gemini_cfg), pointer :: cfg -! -! call c_f_pointer(cfgC,cfg) -! call msisinit_in(cfg) -! end subroutine msisinit_C + subroutine msisinit_C(cfgC) bind(C, name='msisinit_C') + type(c_ptr), intent(in) :: cfgC + type(gemini_cfg), pointer :: cfg + + if (.not. c_associated(cfgC)) error stop "msisinit_C: null configuration" + call c_f_pointer(cfgC,cfg) + call msisinit_in(cfg) + end subroutine msisinit_C !> call to initialize the neutral background information @@ -482,24 +491,29 @@ subroutine set_update_cadence_C(iupdate) bind(C, name='set_update_cadence_C') end subroutine set_update_cadence_C -! !> compute background neutral density, temperature, and wind -! subroutine neutral_atmos_winds_C(cfgC,xtype,xC,ymd,UTsec,intvarsC) bind(C, name='neutral_atmos_winds_C') -! type(c_ptr), intent(in) :: cfgC -! integer(C_INT), intent(in) :: xtype -! type(c_ptr), intent(in) :: xC -! integer(C_INT), dimension(3), intent(in) :: ymd -! real(wp), intent(in) :: UTsec -! type(c_ptr), intent(inout) :: intvarsC -! -! type(gemini_cfg), pointer :: cfg -! class(curvmesh), pointer :: x -! type(gemini_work), pointer :: intvars -! -! call c_f_pointer(cfgC,cfg) -! x=>set_gridpointer_dyntype(xtype, xC) -! call c_f_pointer(intvarsC,intvars) -! call neutral_atmos_winds(cfg,x,ymd,UTsec,intvars) -! end subroutine neutral_atmos_winds_C + !> Legacy empirical-background API; file-driven backgrounds use init_neutralBG_input_C. + subroutine neutral_atmos_winds_C(cfgC,xtype,xC,ymd,UTsec,intvarsC) bind(C, name='neutral_atmos_winds_C') + type(c_ptr), intent(in) :: cfgC + integer(C_INT), intent(in) :: xtype + type(c_ptr), intent(in) :: xC + integer(C_INT), dimension(3), intent(in) :: ymd + real(wp), intent(in) :: UTsec + type(c_ptr), intent(inout) :: intvarsC + + type(gemini_cfg), pointer :: cfg + class(curvmesh), pointer :: x + type(gemini_work), pointer :: intvars + + if (.not. c_associated(cfgC) .or. .not. c_associated(xC) .or. .not. c_associated(intvarsC)) & + error stop "neutral_atmos_winds_C: null configuration, grid or work object" + call c_f_pointer(cfgC,cfg) + if (cfg%flagneutralBGfile /= 0) & + error stop "neutral_atmos_winds_C: file backgrounds require init_neutralBG_input_C" + x=>set_gridpointer_dyntype(xtype, xC) + call c_f_pointer(intvarsC,intvars) + call neutral_background_empirical(cfg,ymd,UTsec,x,v2grid,v3grid,intvars%atmos) + call neutral_aggregate(v2grid,v3grid,intvars%atmos,intvars%atmosperturb) + end subroutine neutral_atmos_winds_C !> get solar indices from cfg struct @@ -574,7 +588,7 @@ subroutine set_global_boundaries_allspec_C(xtype,xC, fluidvarsC,fluidauxvarsC, i type(C_PTR), intent(in) :: xC type(C_PTR), intent(inout) :: fluidvarsC, fluidauxvarsC type(C_PTR), intent(inout) :: intvarsC - integer, intent(in) :: lsp + integer(C_INT), intent(in) :: lsp class(curvmesh), pointer :: x real(wp), dimension(:,:,:,:), pointer :: fluidvars, fluidauxvars @@ -1376,7 +1390,7 @@ subroutine check_finite_output_C(cfgC, fluidvarsC, electrovarsC, t) bind(C, name call c_f_pointer(cfgC, cfg) call c_f_pointer(fluidvarsC,fluidvars,[(lx1+4),(lx2+4),(lx3+4),(5*lsp)]) - call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) + call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),7]) call check_finite_output_in(cfg, fluidvars, electrovars, t) end subroutine check_finite_output_C diff --git a/src/libgemini_mpi.f90 b/src/libgemini_mpi.f90 index 3f4aa800d..66b59df8d 100644 --- a/src/libgemini_mpi.f90 +++ b/src/libgemini_mpi.f90 @@ -17,7 +17,7 @@ module gemini3d_mpi use neutral_background, only: init_neutral_background, neutral_background_fileinput, neutral_background_empirical, & clear_neutral_background_fileinput use neutral, only: neutral_aggregate, neutral_wind_aggregate -use temporal_mpi, only : dt_comm +use temporal_mpi, only : dt_comm, enforce_post_update_cfl use advec_mpi, only: halo_interface_vels_allspec use multifluid_mpi, only: halo_allparams, halo_fluidvars use sources_mpi, only: RK2_prep_mpi_allspec, RK2_global_boundary_allspec @@ -26,6 +26,8 @@ module gemini3d_mpi v2grid, v3grid, setv2v3, set_start_timefromcfg, init_precipinput_in, precip_perturb_in, & solflux_perturb_in, init_solfluxinput_in, & get_it, tneuBG, user_populate +use transport_audit, only: audit_transport_init,audit_step,audit_mass_start,audit_mass_finish +use restart_runtime, only: runtime_select,runtime_read,runtime_save,runtime_restore,runtime_dt,runtime_ready use sanity_check, only : check_finite_perturb !======= ! v2grid, v3grid, setv2v3, set_start_timefromcfg @@ -172,6 +174,7 @@ subroutine get_initial_state(cfg,fluidvars,electrovars,intvars,x,UTsec,ymd,tdur, call fluidvar_pointers(fluidvars,ns,vs1,vs2,vs3,Ts) call electrovar_pointers(electrovars,E1,E2,E3,J1,J2,J3,Phi) + call runtime_select(cfg) call find_milestone(cfg, t, ymdtmp, UTsectmp, filetmp) if ( t > 0 ) then !! Set start variables accordingly and read in the milestone @@ -194,6 +197,7 @@ subroutine get_initial_state(cfg,fluidvars,electrovars,intvars,x,UTsec,ymd,tdur, !cfg%tdur=tdur ! just to insure consistency call input_plasma(cfg%outdir, x%x1,x%x2all,x%x3all,cfg%indatsize,filetmp,ns,vs1,Ts,Phi,intvars%Phiall) + call runtime_read(filetmp,cfg,t) else !! start at the beginning ! UTsec = cfg%UTsec0 ! ymd = cfg%ymd0 @@ -226,6 +230,7 @@ subroutine check_fileoutput(cfg,fluidvars,electrovars,intvars,t,tout,tglowout,tm call fluidvar_pointers(fluidvars,ns,vs1,vs2,vs3,Ts) call electrovar_pointers(electrovars,E1,E2,E3,J1,J2,J3,Phi) + call audit_mass_finish(ns) if (abs(t-tout) < 1d-5) then tout = tout + cfg%dtout if (cfg%nooutput ) then @@ -238,6 +243,8 @@ subroutine check_fileoutput(cfg,fluidvars,electrovars,intvars,t,tout,tglowout,tm !! We may need to adjust flagoutput if we are hitting a milestone flagoutput=cfg%flagoutput call user_populate(fluidvars,electrovars,intvars) ! custom user data + call runtime_save(cfg,ymd,UTsec,fluidvars,electrovars,intvars%vs1i,intvars%vs2i,intvars%vs3i, & + get_it(),tneuBG,tout,tglowout) if (cfg%mcadence>0 .and. abs(t-tmilestone) < 1d-5) then flagoutput=1 !force a full output at the milestone call output_plasma(cfg%outdir,flagoutput,ymd, & @@ -347,7 +354,8 @@ subroutine get_initial_drifts(cfg,x,fluidvars,fluidauxvars,electrovars,intvars) real(wp), dimension(:,:,:), allocatable :: sig0,sigP,sigH,sigPgrav,sigHgrav real(wp), dimension(:,:,:,:), allocatable :: muP,muH,nusn - integer :: lx1,lx2,lx3,lsp + integer :: lx1,lx2,lx3,lsp,restored_it + real(wp) :: restored_neutral real(wp), dimension(:,:,:,:), pointer :: ns,vs1,vs2,vs3,Ts real(wp), dimension(:,:,:,:), pointer :: rhovs1,rhoes real(wp), dimension(:,:,:), pointer :: rhov2,rhov3,B1,B2,B3,v1,v2,v3,rhom @@ -371,6 +379,11 @@ subroutine get_initial_drifts(cfg,x,fluidvars,fluidauxvars,electrovars,intvars) print*, ' ',minval(vs2(1:lx1,1:lx2,1:lx3,1:lsp)),maxval(vs2(1:lx1,1:lx2,1:lx3,1:lsp)) print*, ' ',minval(vs3(1:lx1,1:lx2,1:lx3,1:lsp)),maxval(vs3(1:lx1,1:lx2,1:lx3,1:lsp)) end if + call audit_transport_init(cfg%outdir,mpi_cfg%myid) + restored_it=get_it();restored_neutral=tneuBG + call runtime_restore(fluidvars,electrovars,intvars%vs1i,intvars%vs2i,intvars%vs3i,restored_it,restored_neutral) + ! it is a process-local initialization counter (MUMPS/neutrals), not simulation state. + ! Keep it at one; the saved dt still constrains the first continuation step. end subroutine get_initial_drifts @@ -479,6 +492,7 @@ subroutine dt_select(cfg,x,fluidvars,fluidauxvars,t,tout,tglowout,dt) real(wp), intent(inout) :: dt real(wp) :: dtprev + logical :: continuing real(wp), dimension(:,:,:,:), pointer :: ns,vs1,vs2,vs3,Ts real(wp), dimension(:,:,:,:), pointer :: rhovs1,rhoes real(wp), dimension(:,:,:), pointer :: rhov2,rhov3,B1,B2,B3,v1,v2,v3,rhom @@ -488,13 +502,15 @@ subroutine dt_select(cfg,x,fluidvars,fluidauxvars,t,tout,tglowout,dt) call fluidauxvar_pointers(fluidauxvars,rhovs1,rhoes,rhov2,rhov3,B1,B2,B3,v1,v2,v3,rhom) !> save prior time step + continuing=runtime_ready + call runtime_dt(dt,.true.) dtprev = dt !> time step calculation, requires workers to report their most stringent local stability constraint call dt_comm(t,tout,tglowout,cfg,ns,Ts,vs1,vs2,vs3,B1,B2,B3,x,dt) !> do not allow the time step to change too rapidly - if (get_it()>1) then + if (get_it()>1.or.continuing) then if(dt/dtprev > dtscale) then !! throttle how quickly we allow dt to increase dt=dtscale*dtprev @@ -503,6 +519,9 @@ subroutine dt_select(cfg,x,fluidvars,fluidauxvars,t,tout,tglowout,dt) end if end if end if + call runtime_dt(dt,.false.) + call audit_step(t,dt) + call audit_mass_start(ns,x) end subroutine dt_select @@ -557,10 +576,15 @@ subroutine neutral_background_in(cfg,intvars,x,dt,t,ymd,UTsec) !> get neutral background ! if ( get_it()/=1 .and. cfg%flagneuBG .and. t>tneuBG) then if ( get_it()==1 .or. (cfg%flagneuBG .and. t>tneuBG) ) then - print*, 'Updating neutrals...' + !print*, 'Updating neutrals...' !^we dont' throttle for tneuBG so we have to do things this way to not skip over... !call cpu_time(tstart) - call neutral_background_empirical(cfg,ymd,UTsec,x,v2grid,v3grid,intvars%atmos) ! load background states from empirical models into base array variables + if (cfg%flagneuBG) then + call neutral_background_empirical(cfg,ymd,UTsec,x,v2grid,v3grid,intvars%atmos) + else + ! Frozen means the same background before and after restart. + call neutral_background_empirical(cfg,cfg%ymd0,cfg%UTsec0,x,v2grid,v3grid,intvars%atmos) + endif call neutral_aggregate(v2grid,v3grid,intvars%atmos,intvars%atmosperturb) ! apply to variables in this program unit tneuBG=tneuBG+cfg%dtneuBG !if (myid==0) then @@ -645,6 +669,7 @@ subroutine electrodynamics_in(cfg,fluidvars,fluidauxvars,electrovars,intvars,x,t intvars%Vminx3,intvars%Vmaxx3,intvars%Vminx1slab,intvars%Vmaxx1slab, & intvars%E01,intvars%E02,intvars%E03, & ymd,UTsec,intvars%sig0,intvars%sigP,intvars%sigH,intvars%sigNCP,intvars%sigNCH) + call enforce_post_update_cfl(Ts,vs1,vs2,vs3,x,dt) end subroutine electrodynamics_in diff --git a/src/libgemini_mpi_c.f90 b/src/libgemini_mpi_c.f90 index 51f54e406..ae8d8c30b 100644 --- a/src/libgemini_mpi_c.f90 +++ b/src/libgemini_mpi_c.f90 @@ -23,8 +23,9 @@ module gemini3d_mpi_C use sources_mpi, only: RK2_prep_mpi_allspec use ionization_mpi, only: get_gavg_Tinf use neutral_perturbations, only: clear_neutral_perturb +use neutral, only: neutral_wind_aggregate -use gemini3d, only: fluidvar_pointers,fluidauxvar_pointers, electrovar_pointers, gemini_work +use gemini3d, only: fluidvar_pointers,fluidauxvar_pointers, electrovar_pointers, gemini_work, v2grid, v3grid use gemini3d_mpi, only: mpisetup_in, mpiparms, & outdir_fullgridvaralloc, get_initial_state, check_fileoutput, check_dryrun, & BGfield_Lagrangian, get_initial_drifts, init_procgrid, init_inputdata_in, init_Efieldinput_in, pot2perpfield_in, & @@ -113,7 +114,7 @@ subroutine get_initial_state_C(cfgC,fluidvarsC,electrovarsC,intvarsC,xtype, & x=>set_gridpointer_dyntype(xtype, xC) call c_f_pointer(fluidvarsC,fluidvars,[(lx1+4),(lx2+4),(lx3+4),(5*lsp)]) - call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) + call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),7]) call get_initial_state(cfg, fluidvars,electrovars,intvars, x, UTsec, ymd, tdur, t, tmilestone) end subroutine get_initial_state_C @@ -138,7 +139,7 @@ subroutine check_fileoutput_C(cfgC,fluidvarsC,electrovarsC,intvarsC, & call c_f_pointer(intvarsC,intvars) call c_f_pointer(fluidvarsC,fluidvars,[(lx1+4),(lx2+4),(lx3+4),(5*lsp)]) - call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) + call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),7]) call check_fileoutput(cfg, fluidvars, electrovars, intvars, t, tout,tglowout,tmilestone,flagoutput,ymd,UTsec) end subroutine check_fileoutput_C @@ -171,7 +172,7 @@ subroutine BGfield_Lagrangian_C(cfgC, xtype,xC, electrovarsC,intvarsC) bind(C, n x=>set_gridpointer_dyntype(xtype, xC) call c_f_pointer(intvarsC,intvars) - call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) + call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),7]) call BGfield_Lagrangian(cfg, x, electrovars, intvars) end subroutine BGfield_Lagrangian_C @@ -197,7 +198,7 @@ subroutine get_initial_drifts_C(cfgC, xtype,xC, fluidvarsC,fluidauxvarsC,electro call c_f_pointer(fluidvarsC,fluidvars,[(lx1+4),(lx2+4),(lx3+4),(5*lsp)]) call c_f_pointer(fluidauxvarsC,fluidauxvars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) - call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) + call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),7]) call get_initial_drifts(cfg, x, fluidvars, fluidauxvars, electrovars, intvars) end subroutine get_initial_drifts_C @@ -260,7 +261,7 @@ subroutine pot2perpfield_C(xtype,xC, electrovarsC) bind(C, name='pot2perpfield_C real(wp), dimension(:,:,:,:), pointer :: electrovars x=>set_gridpointer_dyntype(xtype, xC) - call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) + call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),7]) call pot2perpfield_in(x,electrovars) end subroutine pot2perpfield_C @@ -309,14 +310,14 @@ subroutine dt_select_C(cfgC, xtype,xC, fluidvarsC,fluidauxvarsC,t,tout,tglowout, end subroutine dt_select_C -! subroutine neutral_atmos_wind_update_C(intvarsC) bind(C, name='neutral_atmos_wind_update_C') -! type(C_PTR), intent(inout) :: intvarsC -! -! type(gemini_work), pointer :: intvars -! -! call c_f_pointer(intvarsC,intvars) -! call neutral_atmos_wind_update(intvars) -! end subroutine neutral_atmos_wind_update_C + subroutine neutral_atmos_wind_update_C(intvarsC) bind(C, name='neutral_atmos_wind_update_C') + type(C_PTR), intent(inout) :: intvarsC + type(gemini_work), pointer :: intvars + + if (.not. c_associated(intvarsC)) error stop "neutral_atmos_wind_update_C: null work object" + call c_f_pointer(intvarsC,intvars) + call neutral_wind_aggregate(v2grid,v3grid,intvars%atmos,intvars%atmosperturb,.false.) + end subroutine neutral_atmos_wind_update_C subroutine inputdata_perturb_C(cfgC, intvarsC, xtype,xC, dt,t,ymd,UTsec) bind(C, name='inputdata_perturb_C') @@ -404,7 +405,7 @@ subroutine electrodynamics_C(cfgC, fluidvarsC,fluidauxvarsC,electrovarsC, intvar call c_f_pointer(cfgC, cfg) call c_f_pointer(fluidvarsC,fluidvars,[(lx1+4),(lx2+4),(lx3+4),(5*lsp)]) call c_f_pointer(fluidauxvarsC,fluidauxvars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) - call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),(2*lsp+9)]) + call c_f_pointer(electrovarsC,electrovars,[(lx1+4),(lx2+4),(lx3+4),7]) call c_f_pointer(intvarsC,intvars) x=>set_gridpointer_dyntype(xtype, xC) diff --git a/src/mpimod/autogrid.f90 b/src/mpimod/autogrid.f90 index 80034987a..ad33679b2 100644 --- a/src/mpimod/autogrid.f90 +++ b/src/mpimod/autogrid.f90 @@ -161,17 +161,20 @@ end function gcd integer function max_mpi(lx2, lx3, max_cpu) -!! goal is to find the highest x2 + x3 to maximum CPU core count +!! Maximize workers by factoring the original axes, retaining two cells per active axis. integer, intent(in) :: lx2, lx3, max_cpu - -!> divide by 2 to ensure MPI partition has at least 2 per axis--for 2D and 3D -if (lx3 == 1) then - max_mpi = max_gcd(lx2/2, max_cpu) -elseif (lx2 == 1) then - max_mpi = max_gcd(lx3/2, max_cpu) -else - max_mpi = max_gcd2(lx2/2, lx3/2, max_cpu) -end if +integer :: i, j, limit2, limit3 + +if (max_cpu < 1) error stop "autogrid:max_mpi CPU count must be at least one" +if (lx2 < 1 .or. lx3 < 1) error stop "autogrid:max_mpi grid dimensions must be positive" +limit2 = min(max_cpu, max(1, lx2/2)) +limit3 = max(1, lx3/2) +max_mpi = 1 +do i = 1, limit2 + if (modulo(lx2, i) /= 0) cycle + j = max_gcd(lx3, min(limit3, max_cpu/i)) + max_mpi = max(max_mpi, i*j) +enddo end function max_mpi @@ -195,44 +198,6 @@ integer function max_gcd(L, M) end function max_gcd -integer function max_gcd2(lx2, lx3, M) -!! find the Greatest Common Factor to evenly partition the simulation grid -!! Output range is [M, 1] -!! -!! 1. find factors of each dimension -!! 2. choose partition that yields highest CPU count usage - -integer, intent(in) :: lx2, lx3, M -integer :: f2, f3, i,j, t2, t3 - -if (M < 1) error stop "autogrid:max_gcd2 CPU count must be at least one" - -max_gcd2 = 1 -t2 = 1 -t3 = huge(0) -x2 : do i = M,2,-1 - x3 : do j = M,2,-1 - f2 = max_gcd(lx2, i) - f3 = max_gcd(lx3, j) - if (M < f2 * f3) cycle x3 !< too big for CPU count - if (f2 * f3 < max_gcd2) exit x3 !< too small for max CPU count - if (lx2 / i == 1) cycle x2 - if (lx3 / j == 1) cycle x3 - if (abs(f2-f3) > abs(t2-t3)) cycle x3 - - t2 = f2 - t3 = f3 - ! print *, "lid2, lid3: ", f2, f3 - max_gcd2 = f2 * f3 - end do x3 - if (i*M < max_gcd2) exit x2 -end do x2 - -! print *, "final: lid2, lid3: ", t2, t3 - -end function max_gcd2 - - logical function test_process_number(N, lx2all, lx3all, rx2, rx3) result (ok) !! this is only for testing integer, intent(in) :: N, rx2, rx3, lx2all, lx3all diff --git a/src/mpimod/mpihalo.f90 b/src/mpimod/mpihalo.f90 index 80c6a5fd9..1e8f40712 100644 --- a/src/mpimod/mpihalo.f90 +++ b/src/mpimod/mpihalo.f90 @@ -309,7 +309,7 @@ call mpi_irecv(inbuffer,lx1*lx2,mpi_realprec,idright,tag,MPI_COMM_WORLD, requests(2)) call mpi_waitall(2,requests,statuses) - paramend=inbuffer + if (.not. x3end) paramend=inbuffer deallocate(outbuffer,inbuffer) end if @@ -327,7 +327,7 @@ call mpi_irecv(inbuffer,lx1*lx3,mpi_realprec,idup,tag,MPI_COMM_WORLD, requests(2)) call mpi_waitall(2,requests,statuses) - paramtop=inbuffer + if (.not. x2end) paramtop=inbuffer deallocate(outbuffer,inbuffer) end if @@ -343,9 +343,9 @@ allocate(inbuf_corner(lx1)) call mpi_irecv(inbuf_corner,lx1,mpi_realprec,idupright,tag,MPI_COMM_WORLD, requests(2)) - paramcorner = inbuf_corner call mpi_waitall(2,requests,statuses) + if (upright) paramcorner = inbuf_corner deallocate(outbuf_corner,inbuf_corner) end if diff --git a/src/multifluid/multifluid.f90 b/src/multifluid/multifluid.f90 index e423adcdb..df2f47c56 100644 --- a/src/multifluid/multifluid.f90 +++ b/src/multifluid/multifluid.f90 @@ -17,11 +17,15 @@ module multifluid use, intrinsic :: ieee_arithmetic, only : ieee_is_nan +use transport_audit, only: audit_mass_source,audit_mass_cleanup,audit_etd_source,audit_temperature_floor, & + audit_transport_enabled,audit_energy_operator use advec, only: interface_vels_allspec,sweep3_allspec,sweep1_allspec,sweep2_allspec use calculus, only: etd_uncoupled, div3d use collisions, only: thermal_conduct, thermal_conduct_new use phys_consts, only : wp,pi,qs,lsp,gammas,kB,ms,mindensdiv,mindens,mindensnull, debug use diffusion, only: trbdf23d, diffusion_prep, backEuler3D +use nonlinear_diffusion, only: midpoint_TRBDF23D +use diffusion_features, only: midpoint_conduction_enabled use grid, only: lx1, lx2, lx3, gridflag use meshobj, only: curvmesh use ionization, only: ionrate_glow98, ionrate_fang, eheating, photoionization @@ -56,7 +60,7 @@ subroutine sweep3_allspec_mass(dt,x,vs3i,ns) real(wp), dimension(:,:,:,:), intent(in) :: vs3i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: ns - call sweep3_allspec(ns,vs3i,dt,x,0,6) + call sweep3_allspec(ns,vs3i,dt,x,0,6,quantity=1) end subroutine sweep3_allspec_mass subroutine sweep3_allspec_momentum(dt,x,vs3i,rhovs1) real(wp), intent(in) :: dt @@ -64,7 +68,7 @@ subroutine sweep3_allspec_momentum(dt,x,vs3i,rhovs1) real(wp), dimension(:,:,:,:), intent(in) :: vs3i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: rhovs1 - call sweep3_allspec(rhovs1,vs3i,dt,x,1,6) + call sweep3_allspec(rhovs1,vs3i,dt,x,1,6,quantity=2) end subroutine sweep3_allspec_momentum subroutine sweep3_allspec_energy(dt,x,vs3i,rhoes) real(wp), intent(in) :: dt @@ -72,7 +76,7 @@ subroutine sweep3_allspec_energy(dt,x,vs3i,rhoes) real(wp), dimension(:,:,:,:), intent(in) :: vs3i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: rhoes - call sweep3_allspec(rhoes,vs3i,dt,x,0,7) + call sweep3_allspec(rhoes,vs3i,dt,x,0,7,quantity=3) end subroutine sweep3_allspec_energy @@ -83,7 +87,7 @@ subroutine sweep1_allspec_mass(dt,x,vs1i,ns) real(wp), dimension(:,:,:,:), intent(in) :: vs1i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: ns - call sweep1_allspec(ns,vs1i,dt,x,6) ! sweep1 doesn't need to know the rank of the advected quantity + call sweep1_allspec(ns,vs1i,dt,x,6,quantity=1) ! sweep1 doesn't need to know the rank of the advected quantity end subroutine sweep1_allspec_mass subroutine sweep1_allspec_momentum(dt,x,vs1i,rhovs1) real(wp), intent(in) :: dt @@ -91,7 +95,7 @@ subroutine sweep1_allspec_momentum(dt,x,vs1i,rhovs1) real(wp), dimension(:,:,:,:), intent(in) :: vs1i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: rhovs1 - call sweep1_allspec(rhovs1,vs1i,dt,x,6) + call sweep1_allspec(rhovs1,vs1i,dt,x,6,quantity=2) end subroutine sweep1_allspec_momentum subroutine sweep1_allspec_energy(dt,x,vs1i,rhoes) real(wp), intent(in) :: dt @@ -99,7 +103,7 @@ subroutine sweep1_allspec_energy(dt,x,vs1i,rhoes) real(wp), dimension(:,:,:,:), intent(in) :: vs1i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: rhoes - call sweep1_allspec(rhoes,vs1i,dt,x,7) + call sweep1_allspec(rhoes,vs1i,dt,x,7,quantity=3) end subroutine sweep1_allspec_energy @@ -110,7 +114,7 @@ subroutine sweep2_allspec_mass(dt,x,vs2i,ns) real(wp), dimension(:,:,:,:), intent(in) :: vs2i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: ns - call sweep2_allspec(ns,vs2i,dt,x,0,6) + call sweep2_allspec(ns,vs2i,dt,x,0,6,quantity=1) end subroutine sweep2_allspec_mass subroutine sweep2_allspec_momentum(dt,x,vs2i,rhovs1) real(wp), intent(in) :: dt @@ -118,7 +122,7 @@ subroutine sweep2_allspec_momentum(dt,x,vs2i,rhovs1) real(wp), dimension(:,:,:,:), intent(in) :: vs2i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: rhovs1 - call sweep2_allspec(rhovs1,vs2i,dt,x,1,6) + call sweep2_allspec(rhovs1,vs2i,dt,x,1,6,quantity=2) end subroutine sweep2_allspec_momentum subroutine sweep2_allspec_energy(dt,x,vs2i,rhoes) real(wp), intent(in) :: dt @@ -126,7 +130,7 @@ subroutine sweep2_allspec_energy(dt,x,vs2i,rhoes) real(wp), dimension(:,:,:,:), intent(in) :: vs2i real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: rhoes - call sweep2_allspec(rhoes,vs2i,dt,x,0,7) + call sweep2_allspec(rhoes,vs2i,dt,x,0,7,quantity=3) end subroutine sweep2_allspec_energy @@ -272,11 +276,18 @@ end subroutine source_neut subroutine rhoe2T(ns,rhoes,Ts) real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: ns,rhoes,Ts integer :: isp,lsp + integer :: n1,n2,n3 + real(wp), allocatable :: before(:,:,:) lsp=size(rhoes,4) + n1=size(Ts,1)-4;n2=size(Ts,2)-4;n3=size(Ts,3)-4 + if(audit_transport_enabled) allocate(before(n1,n2,n3)) do isp=1,lsp Ts(:,:,:,isp)=(gammas(isp) - 1)/kB*rhoes(:,:,:,isp)/max(ns(:,:,:,isp),mindensdiv) + if(audit_transport_enabled) before=Ts(1:n1,1:n2,1:n3,isp) Ts(:,:,:,isp)=max(Ts(:,:,:,isp), 100._wp) + if(audit_transport_enabled) call audit_temperature_floor(3,isp,before,Ts(1:n1,1:n2,1:n3,isp), & + ns(1:n1,1:n2,1:n3,isp)*kB/(gammas(isp)-1)) !! convert internal specific energy density back into temperature end do end subroutine rhoe2T @@ -391,6 +402,7 @@ subroutine compression(dt,x,vs1,vs2,vs3,Q,rhoes) real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: rhoes real(wp), dimension(1:size(vs1,1)-4,1:size(vs1,2)-4,1:size(vs1,3)-4) :: paramtrim,rhoeshalf real(wp), dimension(0:size(vs1,1)-3,0:size(vs1,2)-3,0:size(vs1,3)-3) :: divvs + real(wp), allocatable :: increments(:,:,:,:) integer :: isp,lsp !print*, 'compression: ', shape(vs1(1:lx1,1:lx2,1:lx3,:)),minval(vs1(1:lx1,1:lx2,1:lx3,:)), & @@ -398,6 +410,7 @@ subroutine compression(dt,x,vs1,vs2,vs3,Q,rhoes) ! minloc(vs1(1:lx1,1:lx2,1:lx3,:)),maxloc(vs1(1:lx1,1:lx2,1:lx3,:)) lsp=size(vs1,4) + if(audit_transport_enabled) allocate(increments(lx1,lx2,lx3,5)) do isp=1,lsp divvs = div3D(vs1(0:lx1+1,0:lx2+1,0:lx3+1,isp),& vs2(0:lx1+1,0:lx2+1,0:lx3+1,isp), & @@ -409,6 +422,13 @@ subroutine compression(dt,x,vs1,vs2,vs3,Q,rhoes) !! t+dt/2 value of internal energy, use only interior points of divvs for second order accuracy paramtrim=paramtrim-dt*(rhoeshalf*(gammas(isp) - 1)+Q(:,:,:,isp))*divvs(1:lx1,1:lx2,1:lx3) + if(audit_transport_enabled) then + increments=0 + increments(:,:,:,1)=-dt*rhoeshalf*(gammas(isp)-1)*divvs(1:lx1,1:lx2,1:lx3) + increments(:,:,:,2)=-dt*Q(:,:,:,isp)*divvs(1:lx1,1:lx2,1:lx3) + call audit_energy_operator(1,isp,rhoes(1:lx1,1:lx2,1:lx3,isp),paramtrim,increments, & + spread(spread(spread(1._wp,1,lx1),2,lx2),3,lx3)) + endif rhoes(1:lx1,1:lx2,1:lx3,isp)=paramtrim end do end subroutine compression @@ -430,9 +450,11 @@ subroutine energy_diffusion(dt,x,ns,Ts,J1,nn,Tn,flagdiffsolve,Teinf) real(wp), intent(in) :: Teinf real(wp), dimension(-1:size(Ts,1)-2,-1:size(Ts,2)-2,-1:size(Ts,3)-2) :: param ! could be a pointer to avoid wasting memory? real(wp), dimension(1:size(Ts,1)-4,1:size(Ts,2)-4,1:size(Ts,3)-4) :: A,B,C,D,E,lambda,beta + real(wp), allocatable :: increments(:,:,:,:) integer :: isp,lsp lsp=size(Ts,4) + if(audit_transport_enabled) allocate(increments(lx1,lx2,lx3,5)) do isp=1,lsp param=Ts(:,:,:,isp) !temperature for this species call thermal_conduct(isp,param,ns(:,:,:,isp),nn,J1,lambda,beta) @@ -440,16 +462,24 @@ subroutine energy_diffusion(dt,x,ns,Ts,J1,nn,Tn,flagdiffsolve,Teinf) call diffusion_prep(isp,x,lambda,beta,ns(:,:,:,isp),param,A,B,C,D,E,Tn,Teinf) select case (flagdiffsolve) case (1) - param=backEuler3D(param,A,B,C,D,E,dt,x) !1st order method, only use if you are seeing grid-level oscillations in temperatures + param=backEuler3D(param,A,B,C,D,E,dt,x,increments) !1st order method case (2) - param=TRBDF23D(param,A,B,C,D,E,dt,x) !2nd order method, should be used for most simulations + if(midpoint_conduction_enabled) then + param=midpoint_TRBDF23D(isp,x,ns(:,:,:,isp),Ts(:,:,:,isp),nn,J1,Tn,Teinf,dt,increments) + else + param=TRBDF23D(param,A,B,C,D,E,dt,x,increments) + endif case default print*, 'Unsupported diffusion solver type/mode: ',flagdiffsolve,'. Should be either 1 or 2.' error stop end select + if(audit_transport_enabled) call audit_energy_operator(2,isp,Ts(1:lx1,1:lx2,1:lx3,isp), & + param(1:lx1,1:lx2,1:lx3),increments,max(ns(1:lx1,1:lx2,1:lx3,isp),mindensdiv)*kB/(gammas(isp)-1)) Ts(:,:,:,isp) = param Ts(:,:,:,isp) = max(Ts(:,:,:,isp), 100._wp) ! is this necessary or does clean_param take care of??? + if(audit_transport_enabled) call audit_temperature_floor(1,isp,param(1:lx1,1:lx2,1:lx3), & + Ts(1:lx1,1:lx2,1:lx3,isp),max(ns(1:lx1,1:lx2,1:lx3,isp),mindensdiv)*kB/(gammas(isp)-1)) end do end subroutine energy_diffusion @@ -664,10 +694,18 @@ subroutine energy_source_loss_solve(dt,Pr,Lo,Qeprecip,rhoes,Ts,ns) end if paramtrim=rhoes(1:lx1,1:lx2,1:lx3,isp) paramtrim=ETD_uncoupled(paramtrim,Pr(:,:,:,isp),Lo(:,:,:,isp),dt) + if(isp==lsp) then + call audit_etd_source(3,isp,rhoes(1:lx1,1:lx2,1:lx3,isp),paramtrim,Pr(:,:,:,isp),Lo(:,:,:,isp),dt,Qeprecip) + else + call audit_etd_source(3,isp,rhoes(1:lx1,1:lx2,1:lx3,isp),paramtrim,Pr(:,:,:,isp),Lo(:,:,:,isp),dt) + endif rhoes(1:lx1,1:lx2,1:lx3,isp)=paramtrim Ts(:,:,:,isp)=(gammas(isp) - 1)/kB*rhoes(:,:,:,isp)/max(ns(:,:,:,isp),mindensdiv) + if(audit_transport_enabled) paramtrim=Ts(1:lx1,1:lx2,1:lx3,isp) Ts(:,:,:,isp)=max(Ts(:,:,:,isp), 100._wp) + if(audit_transport_enabled) call audit_temperature_floor(2,isp,paramtrim, & + Ts(1:lx1,1:lx2,1:lx3,isp),max(ns(1:lx1,1:lx2,1:lx3,isp),mindensdiv)*kB/(gammas(isp)-1)) end do end subroutine energy_source_loss_solve @@ -691,6 +729,7 @@ subroutine momentum_source_loss_solve(dt,x,Pr,Lo,ns,rhovs1,vs1,J1,flagJ1) do isp=1,lsp-1 paramtrim=rhovs1(1:lx1,1:lx2,1:lx3,isp) paramtrim=ETD_uncoupled(paramtrim,Pr(:,:,:,isp),Lo(:,:,:,isp),dt) + call audit_etd_source(2,isp,rhovs1(1:lx1,1:lx2,1:lx3,isp),paramtrim,Pr(:,:,:,isp),Lo(:,:,:,isp),dt) rhovs1(1:lx1,1:lx2,1:lx3,isp)=paramtrim vs1(:,:,:,isp)=rhovs1(:,:,:,isp)/(ms(isp)*max(ns(:,:,:,isp),mindensdiv)) end do @@ -726,6 +765,8 @@ subroutine mass_source_loss_solve(dt,Pr,Lo,Prionize,ns) do isp=1,lsp-1 paramtrim=ns(1:lx1,1:lx2,1:lx3,isp) paramtrim=ETD_uncoupled(paramtrim,Pr(:,:,:,isp),Lo(:,:,:,isp),dt) + call audit_etd_source(1,isp,ns(1:lx1,1:lx2,1:lx3,isp),paramtrim,Pr(:,:,:,isp),Lo(:,:,:,isp),dt,Prionize(:,:,:,isp)) + call audit_mass_source(isp,ns(1:lx1,1:lx2,1:lx3,isp),paramtrim) ns(1:lx1,1:lx2,1:lx3,isp)=paramtrim !should there be a density floor here??? I think so... end do ns(:,:,:,lsp)=sum(ns(:,:,:,1:lsp-1),4) @@ -743,9 +784,12 @@ subroutine clean_param(x,paramflag,param) real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: param !note that this is 4D and is meant to include ghost cells integer :: isp,ix1,ix2,ix3,iinull,ix1beg,ix1end + if(paramflag==1) call audit_mass_cleanup(param,.true.) select case (paramflag) case (1) !density param(:,:,:,1:lsp-1)=max(param(:,:,:,1:lsp-1),mindens) ! enforce a minimum density + ! Honor the configured floor. ESF runs needing 1e3 must set mindens_userval=1e3. + ! Audit correction 2026-09-16: do not silently override every case with an ESF-specific floor. param(:,:,:,lsp)=sum(param(:,:,:,1:lsp-1),4) !enforce charge neutrality based on ion densities do isp=1,lsp !set null cells to some value @@ -868,6 +912,7 @@ subroutine clean_param(x,paramflag,param) !! throw an error as the code is likely not going to behave in a predictable way in this situation... error stop '!non-standard parameter selected in clean_params, unreliable/incorrect results possible...' end select + if(paramflag==1) call audit_mass_cleanup(param,.false.) end subroutine clean_param diff --git a/src/neutral/neutral_background_mod.f90 b/src/neutral/neutral_background_mod.f90 index dd5a9aa5b..b8b03b00a 100644 --- a/src/neutral/neutral_background_mod.f90 +++ b/src/neutral/neutral_background_mod.f90 @@ -1,5 +1,6 @@ module neutral_background +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite use phys_consts, only: wp use neutral, only: rotate_geo2native, neutral_info use neutraldataBGobj, only: neutraldataBG @@ -11,7 +12,7 @@ module neutral_background implicit none (type, external) private public :: init_neutral_background, neutral_background_fileinput, neutral_background_empirical, & - clear_neutral_background_fileinput + clear_neutral_background_fileinput, msisinit_in interface !< atmos.f90 module subroutine neutral_atmos(ymd,UTsecd,glat,glon,alt,activ,msis_version,atmos) @@ -84,14 +85,20 @@ subroutine neutral_background_fileinput_copyout(x,atmos,atmosbackground) integer :: ix1,ix2,ix3,ineu,ix1ref1,ix1ref2,ix1apex integer :: lneu - real(wp) :: nref,Tnref,vn1ref,vn2ref,vn3ref - real(wp) :: altimax1,altimax2,altapex,nrat + real(wp) :: Tnref,vn1ref,vn2ref,vn3ref,nrat ! place the background atmospheric density and temperature (drifts still need to be rotated) ! from object into arrays used by other modules atmos%nnBG(:,:,:,1:5)=atmosbackground%natminow(:,:,:,1:5) atmos%TnBG=atmosbackground%natminow(:,:,:,9) - call NO_calc(atmos%nnBG,atmos%TnBG) + if (.not. all(ieee_is_finite(atmos%TnBG))) & + error stop 'neutral background: temperatures must be finite and positive' + if (any(atmos%TnBG<=0 .and. x%alt(1:lx1,1:x%lx2,1:x%lx3)>=0 .and. & + x%alt(1:lx1,1:x%lx2,1:x%lx3)<=atmosbackground%altpmax)) & + error stop 'neutral background: temperatures must be finite and positive' + ! Uncovered cells are zero-filled by interpolation and replaced below. + ! Do not divide by their placeholder temperatures while deriving reference NO. + call NO_calc(atmos%nnBG,merge(atmos%TnBG,1._wp,atmos%TnBG>0)) ! rotate winds to model native and place into wind background arrays in the atmos object call rotate_geo2native(atmosbackground%natminow(:,:,:,6), & @@ -107,87 +114,99 @@ subroutine neutral_background_fileinput_copyout(x,atmos,atmosbackground) do ix2=1,x%lx2 ! for each field line we need to find the apex altitude and index (it possibly could be a different index ! on each field line??? + if (.not. all(ieee_is_finite(x%alt(1:lx1,ix2,ix3))) .or. & + .not. ieee_is_finite(atmosbackground%altpmax)) error stop 'neutral background: nonfinite altitude' ix1apex=maxloc(x%alt(1:lx1,ix2,ix3),dim=1) + if (x%alt(ix1apex,ix2,ix3)<0) error stop 'neutral background: field line is entirely below ground' + if (lx1==1 .and. x%alt(1,ix2,ix3)>atmosbackground%altpmax) & + error stop 'neutral background: insufficient altitude coverage' ! find the reference altitude and index beyond which the input data need to be extrapolated ! Start at the min(x1) end ix1=1 - do while (x%alt(ix1,ix2,ix3)atmosbackground%altpmax) exit ix1=ix1+1 end do - ix1ref1=max(ix1-1,1) - altimax1=x%alt(ix1ref1,ix2,ix3) + ix1ref1=ix1-1 ! Now from the max(x1) end (in-case two-sided grid) ix1=lx1 - do while(x%alt(ix1,ix2,ix3)=ix1apex) + do while (ix1>=ix1apex) + if (x%alt(ix1,ix2,ix3)>atmosbackground%altpmax) exit ix1=ix1-1 end do - ix1ref2=min(ix1+1,lx1) - altimax2=x%alt(ix1ref2,ix2,ix3) + ix1ref2=ix1+1 !print*, ix1apex,ix1ref1,ix1ref2 ! pull a reference density from the highest point on the simulation that exists below altitude limit ! of the input data - do ineu=1,lneu - nref=atmos%nnBG(ix1ref1,ix2,ix3,ineu) - nrat=nref/atmos%nnBG(ix1ref1-1,ix2,ix3,ineu) - do ix1=ix1ref1+1,ix1apex - if (ix1>1) then ! FIXME: always true? + ! Only extrapolate a hemisphere when the apex lies above file coverage. + ! Two above-ground samples are required to determine its exponential slope. + if (ix1apex>1 .and. ix1ref1ix1apex) then + if (ix1ref2>lx1-1) error stop 'neutral background: insufficient upper-end altitude coverage' + if (x%alt(ix1ref2+1,ix2,ix3)<0) & + error stop 'neutral background: insufficient above-ground upper-end samples' + do ineu=1,lneu + nrat=density_ratio(atmos%nnBG(ix1ref2,ix2,ix3,ineu),atmos%nnBG(ix1ref2+1,ix2,ix3,ineu)) + do ix1=ix1ref2-1,ix1apex,-1 atmos%nnBG(ix1,ix2,ix3,ineu)=nrat*atmos%nnBG(ix1+1,ix2,ix3,ineu) - else - print*, 'ref2: ',ix1apex,ix1ref2,ix1 - error stop 'problem extrapolating background neutral density profile. index OOB' - end if + end do end do - end do + end if ! temperature and velocity profiles get a ZOH - Tnref=atmos%TnBG(ix1ref1,ix2,ix3) - vn1ref=atmos%vn1(ix1ref1,ix2,ix3) - vn2ref=atmos%vn2(ix1ref1,ix2,ix3) - vn3ref=atmos%vn3(ix1ref1,ix2,ix3) - do ix1=ix1ref1+1,ix1apex - atmos%TnBG(ix1,ix2,ix3)=Tnref - atmos%vn1BG(ix1,ix2,ix3)=vn1ref - atmos%vn2BG(ix1,ix2,ix3)=vn2ref - atmos%vn3BG(ix1,ix2,ix3)=vn3ref - end do - Tnref=atmos%TnBG(ix1ref2,ix2,ix3) - vn1ref=atmos%vn1(ix1ref2,ix2,ix3) - vn2ref=atmos%vn2(ix1ref2,ix2,ix3) - vn3ref=atmos%vn3(ix1ref2,ix2,ix3) - do ix1=ix1ref2-1,ix1apex,-1 - atmos%TnBG(ix1,ix2,ix3)=Tnref - atmos%vn1BG(ix1,ix2,ix3)=vn1ref - atmos%vn2BG(ix1,ix2,ix3)=vn2ref - atmos%vn3BG(ix1,ix2,ix3)=vn3ref - end do + if (ix1apex>1 .and. ix1ref1ix1apex) then + Tnref=atmos%TnBG(ix1ref2,ix2,ix3) + vn1ref=atmos%vn1BG(ix1ref2,ix2,ix3) + vn2ref=atmos%vn2BG(ix1ref2,ix2,ix3) + vn3ref=atmos%vn3BG(ix1ref2,ix2,ix3) + do ix1=ix1ref2-1,ix1apex,-1 + atmos%TnBG(ix1,ix2,ix3)=Tnref + atmos%vn1BG(ix1,ix2,ix3)=vn1ref + atmos%vn2BG(ix1,ix2,ix3)=vn2ref + atmos%vn3BG(ix1,ix2,ix3)=vn3ref + end do + end if ! any addition 'fixing' that needs to be done on this field-line profile... atmos%vn1BG(1:lx1,ix2,ix3)=atmos%vn1BG(1:lx1,ix2,ix3)*(0.5 + 0.5*tanh((x%alt(1:lx1,ix2,ix3)-150e3)/10e3)) !! Now we need to find the below ground points and do something with them ix1=1 - do while (x%alt(ix1,ix2,ix3)<0 .and. ix1<=ix1apex) + do while (ix1<=ix1apex) + if (x%alt(ix1,ix2,ix3)>=0) exit ix1=ix1+1 end do ix1ref1=max(ix1-1,1) ix1=lx1 - do while (x%alt(ix1,ix2,ix3)<0 .and. ix1>=ix1apex) + do while (ix1>=ix1apex) + if (x%alt(ix1,ix2,ix3)>=0) exit ix1=ix1-1 end do ix1ref2=min(ix1+1,lx1) @@ -220,9 +239,28 @@ subroutine neutral_background_fileinput_copyout(x,atmos,atmosbackground) end do end do + if (.not. all(ieee_is_finite(atmos%TnBG)) .or. any(atmos%TnBG<=0)) & + error stop 'neutral background: temperatures must be finite and positive' end subroutine neutral_background_fileinput_copyout + real(wp) function density_ratio(nref,nlower) result(ratio) + real(wp), intent(in) :: nref,nlower + + if (.not. ieee_is_finite(nref) .or. .not. ieee_is_finite(nlower)) & + error stop 'neutral background: nonfinite extrapolation density' + if (nref<0 .or. nlower<0) error stop 'neutral background: negative extrapolation density' + ! A species absent at the upper sample remains absent above it. A positive + ! upper density over a zero lower density cannot define an exponential. + if (nref==0) then + ratio=0 + else + if (nlower==0) error stop 'neutral background: zero lower extrapolation density' + ratio=nref/nlower + end if + end function density_ratio + + !> initializes neutral atmosphere by: ! 1) establishing initial background for density, temperature, and winds from MSIS and HWM !! Arguably this should be called for init and for neutral updates, except for the allocation part... diff --git a/src/numerical/advection/CMakeLists.txt b/src/numerical/advection/CMakeLists.txt index c6f6ca212..52d8a6249 100644 --- a/src/numerical/advection/CMakeLists.txt +++ b/src/numerical/advection/CMakeLists.txt @@ -1,7 +1,9 @@ +add_library(transport_audit OBJECT transport_audit.f90) +target_link_libraries(transport_audit PRIVATE const meshobj) add_library(advec OBJECT advec.f90 $ ) -target_link_libraries(advec PRIVATE const meshobj) +target_link_libraries(advec PRIVATE const meshobj transport_audit) add_library(advec_mpi OBJECT advec_mpi.f90 $ diff --git a/src/numerical/advection/advec.f90 b/src/numerical/advection/advec.f90 index e17d90000..ab0fac007 100644 --- a/src/numerical/advection/advec.f90 +++ b/src/numerical/advection/advec.f90 @@ -2,6 +2,7 @@ module advec !> this module contains advection-related procedures that are independent on mpi library calls +use transport_audit, only: audit_transport_enabled,audit_begin,audit_slice,audit_finish use phys_consts, only: lsp,ms,wp use grid, only : gridflag, x1lims,x2alllims,x3alllims, isglobalx1min,isglobalx1max, & isglobalx2min,isglobalx2max,isglobalx3min,isglobalx3max @@ -10,7 +11,7 @@ module advec implicit none (type, external) private -public :: interface_vels_allspec,sweep3_allspec,sweep1_allspec,sweep2_allspec,set_global_boundaries_allspec +public :: advec1D_MC_curv, interface_vels_allspec,sweep3_allspec,sweep1_allspec,sweep2_allspec,set_global_boundaries_allspec contains !> set values in global boundary ghost cells based on extrapolation, can be done by each worker @@ -230,51 +231,66 @@ end subroutine interface_vels_allspec !> sweep all species along the 1 axis - subroutine sweep1_allspec(fs,vs1i,dt,x,lsp) + subroutine sweep1_allspec(fs,vs1i,dt,x,lsp,quantity) real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: fs !fs includes ghost cells and all species real(wp), dimension(:,:,:,:), intent(in) :: vs1i ! includes all species velocities real(wp), intent(in) :: dt class(curvmesh), intent(in) :: x integer, intent(in) :: lsp ! sweep the first "lsp" species only - integer :: isp + integer, optional, intent(in) :: quantity + integer :: isp,q if (lsp>size(fs,4)) error stop 'number of swept species must be less than or equal to total species number' + q=0 + if(present(quantity)) q=quantity do isp=1,lsp + if(audit_transport_enabled) call audit_begin(q,isp,1) call sweep1(fs(:,:,:,isp),vs1i(:,:,:,isp),dt,x) + if(audit_transport_enabled) call audit_finish() end do end subroutine sweep1_allspec !> 2-dimensionally split transport for all species - subroutine sweep2_allspec(fs,vs2i,dt,x,frank,lsp) + subroutine sweep2_allspec(fs,vs2i,dt,x,frank,lsp,quantity) real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: fs !fs includes ghost cells and all species real(wp), dimension(:,:,:,:), intent(in) :: vs2i ! includes all species velocities real(wp), intent(in) :: dt class(curvmesh), intent(in) :: x integer, intent(in) :: frank integer, intent(in) :: lsp - integer :: isp + integer, optional, intent(in) :: quantity + integer :: isp,q if (lsp>size(fs,4)) error stop 'number of swept species must be less than or equal to total species number' + q=0 + if(present(quantity)) q=quantity do isp=1,lsp + if(audit_transport_enabled) call audit_begin(q,isp,2) call sweep2(fs(:,:,:,isp),vs2i(:,:,:,isp),dt,x,frank) + if(audit_transport_enabled) call audit_finish() end do end subroutine sweep2_allspec !> 3-dimensionally split transport for all species - subroutine sweep3_allspec(fs,vs3i,dt,x,frank,lsp) + subroutine sweep3_allspec(fs,vs3i,dt,x,frank,lsp,quantity) real(wp), dimension(-1:,-1:,-1:,:), intent(inout) :: fs !fs includes ghost cells and all species real(wp), dimension(:,:,:,:), intent(in) :: vs3i ! includes all species velocities real(wp), intent(in) :: dt class(curvmesh), intent(in) :: x integer, intent(in) :: frank integer, intent(in) :: lsp - integer :: isp + integer, optional, intent(in) :: quantity + integer :: isp,q if (lsp>size(fs,4)) error stop 'number of swept species must be less than or equal to total species number' + q=0 + if(present(quantity)) q=quantity do isp=1,lsp + if(audit_transport_enabled) call audit_begin(q,isp,3) call sweep3(fs(:,:,:,isp),vs3i(:,:,:,isp),dt,x,frank) + if(audit_transport_enabled) call audit_finish() end do end subroutine sweep3_allspec @@ -290,6 +306,7 @@ subroutine sweep1(f,v1i,dt,x) real(wp), dimension(-1:size(f,1)-2) :: h11x1slice !includes ghost cells real(wp), dimension(1:size(f,1)-3) :: h12ix1slice !just includes interface info real(wp), dimension(1:size(f,1)-3) :: h1ix1slice + real(wp) :: numerical_flux(size(f,1)-3) integer :: ix2,ix3,lx2,lx3 lx2=size(f,2)-4 @@ -302,7 +319,15 @@ subroutine sweep1(f,v1i,dt,x) h11x1slice=x%h1(:,ix2,ix3)*x%h2(:,ix2,ix3)*x%h3(:,ix2,ix3) h12ix1slice=x%h2x1i(:,ix2,ix3)*x%h3x1i(:,ix2,ix3) h1ix1slice=x%h1x1i(:,ix2,ix3) - fx1slice=advec1D_MC_curv(fx1slice,v1slice,dt,x%dx1,x%dx1i,h11x1slice,h12ix1slice,h1ix1slice) + if(audit_transport_enabled) then + fx1slice=advec1D_MC_curv(fx1slice,v1slice,dt,x%dx1,x%dx1i, & + h11x1slice,h12ix1slice,h1ix1slice,numerical_flux) + call audit_slice(f(1:size(f,1)-4,ix2,ix3),fx1slice(1:size(f,1)-4), & + x%dx1i*h11x1slice(1:size(f,1)-4),numerical_flux, & + .not.x%nullpts(1:size(f,1)-4,ix2,ix3), x%dx2i(ix2)*x%dx3i(ix3)) + else + fx1slice=advec1D_MC_curv(fx1slice,v1slice,dt,x%dx1,x%dx1i,h11x1slice,h12ix1slice,h1ix1slice) + endif f(:,ix2,ix3)=fx1slice; end do end do @@ -321,6 +346,7 @@ subroutine sweep2(f,v2i,dt,x,frank) real(wp), dimension(-1:size(f,2)-2) :: h21x2slice !includes ghost cells real(wp), dimension(1:size(f,2)-3) :: h22ix2slice !just includes interface info real(wp), dimension(1:size(f,2)-3) :: h2ix2slice + real(wp) :: numerical_flux(size(f,2)-3) integer :: ix1,ix3,lx1,lx3 lx1=size(f,1)-4 @@ -338,7 +364,15 @@ subroutine sweep2(f,v2i,dt,x,frank) h22ix2slice=x%h1x2i(ix1,:,ix3)**2*x%h3x2i(ix1,:,ix3) end if h2ix2slice=x%h2x2i(ix1,:,ix3) - fx2slice=advec1D_MC_curv(fx2slice,v2slice,dt,x%dx2,x%dx2i,h21x2slice,h22ix2slice,h2ix2slice) + if(audit_transport_enabled) then + fx2slice=advec1D_MC_curv(fx2slice,v2slice,dt,x%dx2,x%dx2i, & + h21x2slice,h22ix2slice,h2ix2slice,numerical_flux) + call audit_slice(f(ix1,1:size(f,2)-4,ix3),fx2slice(1:size(f,2)-4), & + x%dx2i*h21x2slice(1:size(f,2)-4),numerical_flux, & + .not.x%nullpts(ix1,1:size(f,2)-4,ix3), x%dx1i(ix1)*x%dx3i(ix3)) + else + fx2slice=advec1D_MC_curv(fx2slice,v2slice,dt,x%dx2,x%dx2i,h21x2slice,h22ix2slice,h2ix2slice) + endif f(ix1,:,ix3)=fx2slice end do end do @@ -357,6 +391,7 @@ subroutine sweep3(f,v3i,dt,x,frank) real(wp), dimension(-1:size(f,3)-2) :: h31x3slice !includes ghost cells real(wp), dimension(1:size(f,3)-3) :: h32ix3slice !just includes interface info real(wp), dimension(1:size(f,3)-3) :: h3ix3slice + real(wp) :: numerical_flux(size(f,3)-3) integer :: ix1,ix2,lx1,lx2 lx1=size(f,1)-4 @@ -374,14 +409,22 @@ subroutine sweep3(f,v3i,dt,x,frank) h32ix3slice=x%h1x3i(ix1,ix2,:)**2*x%h2x3i(ix1,ix2,:) end if h3ix3slice=x%h3x3i(ix1,ix2,:) - fx3slice=advec1D_MC_curv(fx3slice,v3slice,dt,x%dx3,x%dx3i,h31x3slice,h32ix3slice,h3ix3slice) + if(audit_transport_enabled) then + fx3slice=advec1D_MC_curv(fx3slice,v3slice,dt,x%dx3,x%dx3i, & + h31x3slice,h32ix3slice,h3ix3slice,numerical_flux) + call audit_slice(f(ix1,ix2,1:size(f,3)-4),fx3slice(1:size(f,3)-4), & + x%dx3i*h31x3slice(1:size(f,3)-4),numerical_flux, & + .not.x%nullpts(ix1,ix2,1:size(f,3)-4), x%dx1i(ix1)*x%dx2i(ix2)) + else + fx3slice=advec1D_MC_curv(fx3slice,v3slice,dt,x%dx3,x%dx3i,h31x3slice,h32ix3slice,h3ix3slice) + endif f(ix1,ix2,:)=fx3slice end do end do end subroutine sweep3 - function advec1D_MC_curv(f,v1i,dt,dx1,dx1i,ha1,ha2i,h1i) + function advec1D_MC_curv(f,v1i,dt,dx1,dx1i,ha1,ha2i,h1i,integrated_flux) !---------------------------------------------------------------- !---- Generic advection routine, can account for metric factors !----- via arguments including for vector quantities. @@ -394,12 +437,17 @@ function advec1D_MC_curv(f,v1i,dt,dx1,dx1i,ha1,ha2i,h1i) real(wp), dimension(-1:), intent(in) :: ha1 !cell-centered metric factor product 1; includes ghost cells real(wp), dimension(:), intent(in) :: ha2i !cell interface metric factor product 2 real(wp), dimension(:), intent(in) :: h1i !cell interface metric factor for dimension being advected + real(wp), optional, intent(out) :: integrated_flux(:) integer :: ix1,lx1 !overwrite grid module lx1 in this function's scope, since it gets called for x1,x2,x3 real(wp), dimension(size(v1i)) :: phi real(wp), dimension(0:size(v1i)) :: slope !slopes only need through first layer of ghosts real(wp) :: lslope,rslope,cslope real(wp), dimension(-1:size(f)-2) :: advec1D_MC_curv + if(present(integrated_flux)) then + if(size(integrated_flux)/=size(v1i)) error stop "Advection flux shape mismatch" + integrated_flux=0 + endif lx1=size(f)-4 ! we don't know what dimension this is so we actually do need to compute the size if (lx1>1) then ! don't advect a single computational point @@ -423,6 +471,8 @@ function advec1D_MC_curv(f,v1i,dt,dx1,dx1i,ha1,ha2i,h1i) end if end do + if(present(integrated_flux)) integrated_flux=dt*ha2i*phi + !flux differencing form advec1D_MC_curv(1:lx1)=f(1:lx1)-dt*(ha2i(2:lx1+1)*phi(2:lx1+1)-ha2i(1:lx1)*phi(1:lx1))/dx1i/ha1(1:lx1) diff --git a/src/numerical/advection/transport_audit.f90 b/src/numerical/advection/transport_audit.f90 new file mode 100644 index 000000000..4909c1c47 --- /dev/null +++ b/src/numerical/advection/transport_audit.f90 @@ -0,0 +1,230 @@ +! SPDX-License-Identifier: Apache-2.0 +module transport_audit +! Actual numerical face fluxes and physical-cell integrals for split advection. +! Rank-local interface faces cancel when matched across the MPI decomposition. +use phys_consts, only: wp +use meshobj, only: curvmesh +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +implicit none (type,external) +private +public :: audit_transport_init,audit_step,audit_begin,audit_slice,audit_finish,audit_transport_enabled +public :: audit_mass_start,audit_mass_source,audit_mass_cleanup,audit_mass_finish +public :: audit_etd_source,audit_temperature_floor,audit_energy_operator +logical :: mass_active=.false. +real(wp), allocatable :: volume(:,:,:),mass_old(:,:,:,:),cleanup_old(:,:,:,:) +real(wp) :: mass_source(6)=0,mass_flux(6)=0,mass_cleanup(6)=0 +integer :: mass_unit,source_unit,temperature_unit,energy_unit +logical :: audit_transport_enabled=.false. +integer :: unit,quantity,species,axis +real(wp) :: time=0,step=0,terms(7)=0 +contains +subroutine audit_transport_init(outdir,rank) + character(*), intent(in) :: outdir + integer, intent(in) :: rank + character(16) :: flag,suffix + character(:), allocatable :: path + logical :: exists + integer :: status + call get_environment_variable('GEMINI_NUMERICAL_AUDIT',flag,status=status) + audit_transport_enabled=status==0.and.trim(flag)=='1' + if(.not.audit_transport_enabled) return + write(suffix,'(I8.8)') rank + path=outdir//'/transport-r'//trim(suffix)//'.csv' + inquire(file=path,exist=exists) + open(newunit=unit,file=path,status='unknown',position='append',action='write') + if(.not.exists) write(unit,'(A)') & + 't,dt,quantity,species,axis,before,after,delta,outward,min_face,max_face,scale,residual,normalized_residual' + path=outdir//'/continuity-r'//trim(suffix)//'.csv' + inquire(file=path,exist=exists) + open(newunit=mass_unit,file=path,status='unknown',position='append',action='write') + if(.not.exists) write(mass_unit,'(A)') & + 't,dt,species,before,after,source,outward,cleanup,residual,scale,normalized_residual,charge_fraction' + path=outdir//'/sources-r'//trim(suffix)//'.csv' + inquire(file=path,exist=exists) + open(newunit=source_unit,file=path,status='unknown',position='append',action='write') + if(.not.exists) write(source_unit,'(A)') & + 't,dt,quantity,species,before,after,delta,production,external_production,integrated_loss,residual,scale' + path=outdir//'/temperature-floor-r'//trim(suffix)//'.csv' + inquire(file=path,exist=exists) + open(newunit=temperature_unit,file=path,status='unknown',position='append',action='write') + if(.not.exists) write(temperature_unit,'(A)') 't,dt,stage,species,energy_added_J' + path=outdir//'/energy-operators-r'//trim(suffix)//'.csv' + inquire(file=path,exist=exists) + open(newunit=energy_unit,file=path,status='unknown',position='append',action='write') + if(.not.exists) write(energy_unit,'(A)') & + 't,dt,stage,species,before_J,after_J,delta_J,term1_J,term2_J,term3_J,term4_J,term5_J,scale_J,residual_J' +end subroutine +subroutine audit_energy_operator(stage,s,before,after,increments,capacity) + ! Stage 1: pressure compression, artificial-viscous work, zero, zero, zero. + ! Stage 2: linear reaction, thermal drift, conductive divergence, explicit + ! heating, imposed endpoint reservoir change. No interior residual source. + integer, intent(in) :: stage,s + real(wp), intent(in) :: before(:,:,:),after(:,:,:),increments(:,:,:,:),capacity(:,:,:) + real(wp) :: b,a,d,contribution(5),scale,r + integer :: n + if(.not.mass_active) return + if(size(increments,4)/=5) error stop 'Invalid energy operator channel count' + b=sum(before*capacity*volume);a=sum(after*capacity*volume) + d=sum((after-before)*capacity*volume) + do n=1,5 + contribution(n)=sum(increments(:,:,:,n)*capacity*volume) + enddo + scale=max(sum(abs(before)*capacity*volume),sum(abs(after)*capacity*volume), & + sum(abs(contribution)),tiny(1._wp)) + r=d-sum(contribution) + if(.not.all(ieee_is_finite([b,a,d,contribution,scale,r]))) error stop 'Nonfinite energy operator ledger' + write(energy_unit,'(2(ES24.16E3,","),2(I0,","),9(ES24.16E3,","),ES24.16E3)') & + time,step,stage,s,b,a,d,contribution,scale,r + flush(energy_unit) +end subroutine +subroutine audit_etd_source(q,s,before,after,production,loss,dt,external_production) + ! Independently integrate P-L*y for frozen coefficients. No term is defined + ! from the observed state difference. Channels are aggregate rates, not an + ! independent validation of individual reactions or collision coefficients. + integer, intent(in) :: q,s + real(wp), intent(in) :: before(:,:,:),after(:,:,:),production(:,:,:),loss(:,:,:),dt + real(wp), intent(in), optional :: external_production(:,:,:) + real(wp) :: z,phi1,phi2,term1,term2,integrated_loss,b,a,d,p,ext,scale,r,vals(8) + integer :: i,j,k,n + if(.not.mass_active) return + integrated_loss=0 + do k=1,size(volume,3) + do j=1,size(volume,2) + do i=1,size(volume,1) + if(volume(i,j,k)==0) cycle + z=loss(i,j,k)*dt + if(abs(z)<0.1_wp) then + phi1=1;phi2=0.5_wp;term1=1;term2=0.5_wp + do n=1,12 + term1=-term1*z/real(n+1,wp);phi1=phi1+term1 + term2=-term2*z/real(n+2,wp);phi2=phi2+term2 + enddo + else + phi1=(1-exp(-z))/z;phi2=(1-phi1)/z + endif + integrated_loss=integrated_loss+volume(i,j,k)* & + (before(i,j,k)*z*phi1+production(i,j,k)*dt*z*phi2) + enddo + enddo + enddo + b=sum(before*volume);a=sum(after*volume);d=sum((after-before)*volume) + p=sum(production*volume)*dt;ext=0 + if(present(external_production)) ext=sum(external_production*volume)*dt + r=d-p+integrated_loss + scale=max(sum(abs(before)*volume),sum(abs(after)*volume),abs(p),abs(integrated_loss),tiny(1._wp)) + vals=[b,a,d,p,ext,integrated_loss,r,scale] + if(.not.all(ieee_is_finite(vals))) error stop 'Nonfinite source ledger' + write(source_unit,'(2(ES24.16E3,","),2(I0,","),7(ES24.16E3,","),ES24.16E3)') time,dt,q,s,vals + flush(source_unit) +end subroutine +subroutine audit_temperature_floor(stage,s,before,after,heat_capacity) + ! Physical-cell internal energy added by an explicitly applied temperature floor. + integer, intent(in) :: stage,s + real(wp), intent(in) :: before(:,:,:),after(:,:,:),heat_capacity(:,:,:) + real(wp) :: addition + if(.not.mass_active) return + addition=sum((after-before)*heat_capacity*volume) + if(.not.ieee_is_finite(addition)) error stop 'Nonfinite temperature floor ledger' + write(temperature_unit,'(2(ES24.16E3,","),2(I0,","),ES24.16E3)') time,step,stage,s,addition + flush(temperature_unit) +end subroutine +subroutine audit_step(t,dt) + real(wp), intent(in) :: t,dt + time=t;step=dt +end subroutine +subroutine audit_begin(q,s,a) + integer, intent(in) :: q,s,a + quantity=q;species=s;axis=a;terms=0 +end subroutine +subroutine audit_slice(before,after,weights,flux,physical,transverse) + real(wp), intent(in) :: before(:),after(:),weights(:),flux(:),transverse + logical, intent(in) :: physical(:) + real(wp) :: b,a,d,f,scale,lo,hi + integer :: n + n=size(before) + if(size(flux)/=n+1) error stop 'Audit face count differs from cell count' + b=sum(before*weights,mask=physical)*transverse + a=sum(after*weights,mask=physical)*transverse + d=sum((after-before)*weights,mask=physical)*transverse + f=sum(flux(2:n+1)-flux(1:n),mask=physical)*transverse + lo=0;hi=0 + if(physical(1)) lo=-flux(1)*transverse + if(physical(n)) hi=flux(n+1)*transverse + scale=max(sum(abs(before)*weights,mask=physical),sum(abs(after)*weights,mask=physical))*transverse + terms=terms+[b,a,d,f,lo,hi,scale] +end subroutine +subroutine audit_finish() + real(wp) :: residual,relative + if(.not.audit_transport_enabled) return + if(.not.all(ieee_is_finite(terms))) error stop 'Nonfinite transport budget' + if(mass_active.and.quantity==1.and.species<=6) mass_flux(species)=mass_flux(species)+terms(4) + residual=terms(3)+terms(4) + relative=abs(residual)/max(terms(7),abs(terms(4)),tiny(1._wp)) + write(unit,'(2(ES24.16E3,","),3(I0,","),8(ES24.16E3,","),ES24.16E3)') & + time,step,quantity,species,axis,terms,residual,relative + flush(unit) +end subroutine +subroutine audit_mass_start(ns,x) + real(wp), intent(in) :: ns(-1:,-1:,-1:,:) + class(curvmesh), intent(in) :: x + integer :: i,j,k + if(.not.audit_transport_enabled) return + if(.not.allocated(volume)) then + allocate(volume(x%lx1,x%lx2,x%lx3),mass_old(x%lx1,x%lx2,x%lx3,6),cleanup_old(x%lx1,x%lx2,x%lx3,6)) + do k=1,x%lx3 + do j=1,x%lx2 + do i=1,x%lx1 + volume(i,j,k)=0 + if(.not.x%nullpts(i,j,k)) & + volume(i,j,k)=x%h1(i,j,k)*x%h2(i,j,k)*x%h3(i,j,k)*x%dx1i(i)*x%dx2i(j)*x%dx3i(k) + enddo + enddo + enddo + endif + mass_old=ns(1:x%lx1,1:x%lx2,1:x%lx3,1:6) + mass_source=0;mass_flux=0;mass_cleanup=0;mass_active=.true. +end subroutine +subroutine audit_mass_source(species,before,after) + integer, intent(in) :: species + real(wp), intent(in) :: before(:,:,:),after(:,:,:) + if(.not.mass_active) return + if(species<1.or.species>6) error stop 'Invalid ion continuity diagnostic species' + mass_source(species)=mass_source(species)+sum((after-before)*volume) +end subroutine +subroutine audit_mass_cleanup(ns,before) + real(wp), intent(in) :: ns(-1:,-1:,-1:,:) + logical, intent(in) :: before + integer :: i,n1,n2,n3 + if(.not.mass_active) return + n1=size(volume,1);n2=size(volume,2);n3=size(volume,3) + if(before) then + cleanup_old=ns(1:n1,1:n2,1:n3,1:6) + else + do i=1,6 + mass_cleanup(i)=mass_cleanup(i)+sum((ns(1:n1,1:n2,1:n3,i)-cleanup_old(:,:,:,i))*volume) + enddo + endif +end subroutine +subroutine audit_mass_finish(ns) + real(wp), intent(in) :: ns(-1:,-1:,-1:,:) + integer :: i,n1,n2,n3 + real(wp) :: b,a,delta,residual,scale,relative,charge_fraction,values(9) + if(.not.mass_active) return + n1=size(volume,1);n2=size(volume,2);n3=size(volume,3) + charge_fraction=sum(abs(ns(1:n1,1:n2,1:n3,7)-sum(ns(1:n1,1:n2,1:n3,1:6),4))*volume) / & + max(sum(abs(ns(1:n1,1:n2,1:n3,7))*volume),tiny(1._wp)) + do i=1,6 + b=sum(mass_old(:,:,:,i)*volume);a=sum(ns(1:n1,1:n2,1:n3,i)*volume) + delta=sum((ns(1:n1,1:n2,1:n3,i)-mass_old(:,:,:,i))*volume) + residual=delta-mass_source(i)+mass_flux(i)-mass_cleanup(i) + scale=max(sum(abs(mass_old(:,:,:,i))*volume),sum(abs(ns(1:n1,1:n2,1:n3,i))*volume), & + abs(mass_source(i)),abs(mass_flux(i)),abs(mass_cleanup(i)),tiny(1._wp)) + relative=abs(residual)/scale + values=[b,a,mass_source(i),mass_flux(i),mass_cleanup(i),residual,scale,relative,charge_fraction] + if(.not.all(ieee_is_finite(values))) error stop 'Nonfinite continuity ledger' + write(mass_unit,'(2(ES24.16E3,","),I0,",",8(ES24.16E3,","),ES24.16E3)') time,step,i,values + enddo + flush(mass_unit) + mass_active=.false. +end subroutine +end module diff --git a/src/numerical/calculus/calculus.in.f90 b/src/numerical/calculus/calculus.in.f90 index 8a6c02290..bf4be070b 100644 --- a/src/numerical/calculus/calculus.in.f90 +++ b/src/numerical/calculus/calculus.in.f90 @@ -181,17 +181,32 @@ pure function ETD_uncoupled(f,P,L,dt) real(wp), dimension(:,:,:), intent(in) :: f,P,L real(wp), intent(in) :: dt -real(wp), dimension(size(f,1),size(f,2),size(f,3)) :: Ldt,expL +real(wp) :: z,phi,term +integer :: i,j,k,n real(wp), dimension(size(f,1),size(f,2),size(f,3)) :: ETD_uncoupled -Ldt=L*dt -expL=exp(-1.0_wp*Ldt) -where (Ldt>1e-10_wp) - ETD_uncoupled=f*expL+P/L*(1-expL) !fast but could be inaccurate in dynamic situations -elsewhere - ETD_uncoupled=f+P*dt -end where +! phi_1(-z)=(1-exp(-z))/z. Direct subtraction loses accuracy near zero; +! dropping the loss below a threshold also discards legitimate dynamics. +! The convergent series covers both signs and the exact zero-loss limit. +do k=1,size(f,3) + do j=1,size(f,2) + do i=1,size(f,1) + z=L(i,j,k)*dt + if(abs(z)<0.01_wp) then + phi=1;term=1 + do n=1,8 + term=-term*z/real(n+1,wp) + phi=phi+term + enddo + ETD_uncoupled(i,j,k)=f(i,j,k)+(P(i,j,k)-L(i,j,k)*f(i,j,k))*dt*phi + else + phi=(1-exp(-z))/z + ETD_uncoupled(i,j,k)=f(i,j,k)*exp(-z)+P(i,j,k)*dt*phi + endif + enddo + enddo +enddo end function ETD_uncoupled diff --git a/src/numerical/calculus/gradient.f90 b/src/numerical/calculus/gradient.f90 index a2908072f..b2a58e736 100644 --- a/src/numerical/calculus/gradient.f90 +++ b/src/numerical/calculus/gradient.f90 @@ -190,7 +190,7 @@ grad3D2_curv_3(ix1,1,ix3)=(f(ix1,2,ix3)-f(ix1,1,ix3))/dx2(2)/h2(ix1,1,ix3) grad3D2_curv_3(ix1,2:lx2-1,ix3)=(f(ix1,3:lx2,ix3)-f(ix1,1:lx2-2,ix3)) & /(dx2(3:lx2)+dx2(2:lx2-1))/h2(ix1,2:lx2-1,ix3) - grad3D2_curv_3(ix1,lx2,ix3)=(f(ix1,lx2,ix3)-f(ix1,lx2-1,ix3))/dx2(lx2)/h2(ix1,lx2,lx3) + grad3D2_curv_3(ix1,lx2,ix3)=(f(ix1,lx2,ix3)-f(ix1,lx2-1,ix3))/dx2(lx2)/h2(ix1,lx2,ix3) end do end do else @@ -243,7 +243,7 @@ grad3D2_curv_23(ix1,1,ix3)=(f(ix1,2,ix3)-f(ix1,1,ix3))/dx2(2)/h2(ix1,1,ix3) grad3D2_curv_23(ix1,2:lx2-1,ix3)=(f(ix1,3:lx2,ix3)-f(ix1,1:lx2-2,ix3)) & /(dx2(3:lx2)+dx2(2:lx2-1))/h2(ix1,2:lx2-1,ix3) - grad3D2_curv_23(ix1,lx2,ix3)=(f(ix1,lx2,ix3)-f(ix1,lx2-1,ix3))/dx2(lx2)/h2(ix1,lx2,lx3) + grad3D2_curv_23(ix1,lx2,ix3)=(f(ix1,lx2,ix3)-f(ix1,lx2-1,ix3))/dx2(lx2)/h2(ix1,lx2,ix3) end do end do else diff --git a/src/numerical/coord/geomagnetic.f90 b/src/numerical/coord/geomagnetic.f90 index bc8b5407b..bc19ec2b8 100644 --- a/src/numerical/coord/geomagnetic.f90 +++ b/src/numerical/coord/geomagnetic.f90 @@ -1,3 +1,4 @@ +! Audit modification 2026-09-16: reject years outside the calibrated pole table module geomagnetic !> transformations and data relevant to converting geographic to geomagnetic coordinates @@ -46,8 +47,7 @@ subroutine set_magnetic_pole(year) thetan = 9.4105_wp * pi / 180 phin = 287.32_wp * pi / 180 case default - thetan = 11.000_wp * pi / 180 - phin = 289.00_wp * pi / 180 + error stop 'set_magnetic_pole: supported table is 1920:2025; provide an epoch-consistent updated grid/model.' end select end subroutine set_magnetic_pole @@ -60,11 +60,11 @@ elemental subroutine geog2geomag(glon,glat,phi,theta) real(wp) :: phig real(wp) :: argtmp,alpha - glonwrap=mod(glon,360._wp) + glonwrap=modulo(glon,360._wp) thetag = pi/2 - glat*pi/180 phig = glonwrap*pi/180 - theta = acos(cos(thetag)*cos(thetan)+sin(thetag)*sin(thetan)*cos(phig-phin)) + theta = acos(max(-1._wp,min(1._wp,cos(thetag)*cos(thetan)+sin(thetag)*sin(thetan)*cos(phig-phin)))) argtmp = (cos(thetag)-cos(theta)*cos(thetan))/(sin(theta)*sin(thetan)) alpha = acos( max(min(argtmp,1._wp),-1._wp) ) @@ -85,8 +85,8 @@ elemental subroutine geomag2geog(phi,theta,glon,glat) real(wp) :: phig2,phiwrap real(wp) :: argtmp - phiwrap=mod(phi,2*pi) - thetag2p=acos(cos(theta)*cos(thetan)-sin(theta)*sin(thetan)*cos(phiwrap)) + phiwrap=modulo(phi,2*pi) + thetag2p=acos(max(-1._wp,min(1._wp,cos(theta)*cos(thetan)-sin(theta)*sin(thetan)*cos(phiwrap)))) argtmp=(cos(theta)-cos(thetag2p)*cos(thetan))/(sin(thetag2p)*sin(thetan)) beta=acos( max(min(argtmp,1._wp),-1._wp) ) @@ -95,7 +95,7 @@ elemental subroutine geomag2geog(phi,theta,glon,glat) else phig2=phin+beta end if - phig2=mod(phig2,2*pi) + phig2=modulo(phig2,2*pi) thetag2=pi/2-thetag2p glon=phig2*180._wp/pi @@ -173,14 +173,13 @@ subroutine ECEFspher2ENU(alt,theta,phi,theta1,phi1,x,y,z) real(wp) :: xp,yp real(wp) :: theta2,theta3,gamma1,gamma2,phi2,phi3 integer :: lx1,lx2,lx3,ix1,ix2,ix3 ! local copies - logical :: flag3D=.false. + logical :: flag3D lx1=size(alt,1) lx2=size(alt,2) lx3=size(alt,3) if (size(z,1)/=lx1 .or. size(z,2)/=lx2 .or. size(z,3)/=lx3) error stop 'ECEFspher2ENU: inconsistent input array sizes' - - if (size(alt,2)/=1 .and. size(alt,3)/=1) flag3D=.true. + flag3D=lx2/=1 .and. lx3/=1 z(:,:,:)=alt(:,:,:) do ix3=1,lx3 @@ -197,14 +196,6 @@ subroutine ECEFspher2ENU(alt,theta,phi,theta1,phi1,x,y,z) !we need a phi locationi (not spherical phi, but azimuth angle from epicenter), as well, but not for interpolation - just for doing vector rotations theta3=theta2 phi3=phi1 - gamma1=cos(theta2)*cos(theta3)+sin(theta2)*sin(theta3)*cos(phi2-phi3) - if (gamma1 > 1) then !handles weird precision issues in 2D - gamma1 = 1 - else if (gamma1 < -1) then - gamma1 = -1 - end if - gamma1=acos(gamma1) - gamma2=cos(theta1)*cos(theta3)+sin(theta1)*sin(theta3)*cos(phi1-phi3) if (gamma2 > 1) then !handles weird precision issues in 2D gamma2= 1 @@ -212,14 +203,25 @@ subroutine ECEFspher2ENU(alt,theta,phi,theta1,phi1,x,y,z) gamma2= -1 end if gamma2=acos(gamma2) - xp=Re*gamma1 + if (flag3D) then + gamma1=cos(theta2)*cos(theta3)+sin(theta2)*sin(theta3)*cos(phi2-phi3) + if (gamma1 > 1) then !handles weird precision issues in 2D + gamma1 = 1 + else if (gamma1 < -1) then + gamma1 = -1 + end if + gamma1=acos(gamma1) + xp=Re*gamma1 + else + xp=0._wp + end if yp=Re*gamma2 !this will likely always be positive, since we are using center of earth as our origin, so this should be interpreted as distance as opposed to displacement ! coordinates from distances if (theta3>theta1) then !place distances in correct quadrant, here field point (theta3=theta2) is is SOUTHward of source point (theta1), whreas yp is distance northward so throw in a negative sign yp=-yp !do we want an abs here to be safe end if - if (phi2 banded and tridiagonal solvers, for now we just take everything to be banded... use phys_consts, only: wp use vendor_lapack95, only: gbsv!,gtsv +use, intrinsic :: iso_fortran_env, only: stderr=>error_unit implicit none (type, external) @@ -16,7 +17,7 @@ module PDEparabolic contains -function TRBDF21D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i) +function TRBDF21D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i,Tsmin_mid,Tsmax_mid,increments) !! SOLVE A 1D DIFFUSION PROBLEM. IT IS EXPECTED THAT !! GHOST CELLS WILL HAVE BEEN TRIMMED FROM ARRAYS BEFORE @@ -36,6 +37,13 @@ function TRBDF21D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i) real(wp), dimension(:), intent(in) :: A,B,C,D,E real(wp), dimension(:), intent(in) :: Ts real(wp), intent(in) :: Tsminx1, Tsmaxx1, dt +! Existing callers prescribe stage-constant boundaries. Time-varying Dirichlet +! or Neumann data must also supply the value at t+dt/2 for the TR stage. +real(wp), intent(in), optional :: Tsmin_mid,Tsmax_mid +! Integrated reaction, drift, conduction, explicit source and imposed endpoint +! increments. These are evaluated from the numerical stage states, not from +! the interior residual. Endpoints are algebraic boundary reservoirs. +real(wp), intent(out), optional :: increments(size(Ts),5) integer, dimension(2), intent(in) :: BCtype !=0 dirichlet; =1 neumann real(wp), dimension(0:), intent(in) :: dx1 !ith backward difference real(wp), dimension(:), intent(in) :: dx1i !ith centered difference @@ -43,7 +51,7 @@ function TRBDF21D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i) real(wp), dimension(3*ll+1,size(Ts)) :: M !note extra rows for lapack workspace real(wp), dimension(size(Ts)) :: Dh -integer :: ix1,lx1 +integer :: ix1,lx1,info real(wp), dimension(size(Ts)) :: TR @@ -156,10 +164,16 @@ function TRBDF21D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i) end if +if (present(Tsmin_mid)) TR(1)=Tsmin_mid +if (present(Tsmax_mid)) TR(lx1)=Tsmax_mid + !! ### TR HALF STEP MATRIX SOLUTION: CALL LAPACK'S BANDED SOLVER !> BANDED SOLVER (INPUT MATRIX MUST BE SHIFTED 'DOWN' BY KL ROWS) -call gbsv(M,TR,kl=2) +call eliminate_dirichlet_columns(M,TR,BCtype) +call scale_interior_rows(M,TR,dt/2) +call gbsv(M,TR,kl=2,info=info) +call check_solver_info(info,'TRBDF21D TR stage') @@ -247,12 +261,25 @@ function TRBDF21D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i) !! ## BDF2 STEP MATRIX SOLUTION: CALL LAPACK'S BANDED SOLVER !> BANDED SOLVER (INPUT MATRIX MUST BE SHIFTED 'DOWN' BY KL ROWS) -call gbsv(M,TRBDF21D,kl=2) +call eliminate_dirichlet_columns(M,TRBDF21D,BCtype) +call scale_interior_rows(M,TRBDF21D,dt/3) +call gbsv(M,TRBDF21D,kl=2,info=info) +call check_solver_info(info,'TRBDF21D BDF2 stage') + +if (present(increments)) then + ! TR uses dt/2 followed by the BDF formula with dt/3. Eliminating the + ! intermediate state gives dt/3 times each of L(T0), L(TR), L(Tfinal). + increments=dt/3*(parabolic_terms(Ts,A,B,C,D,E,dx1,dx1i) & + +parabolic_terms(TR,A,B,C,D,E,dx1,dx1i) & + +parabolic_terms(TRBDF21D,A,B,C,D,E,dx1,dx1i)) + increments(1,5)=TRBDF21D(1)-Ts(1) + increments(lx1,5)=TRBDF21D(lx1)-Ts(lx1) +endif end function TRBDF21D -function backEuler1D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i,coeffs,rhs) +function backEuler1D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i,coeffs,rhs,increments) !------------------------------------------------------------ !-------SOLVE A 1D DIFFUSION PROBLEM. IT IS EXPECTED THAT @@ -272,12 +299,13 @@ function backEuler1D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i,coeffs,rhs) !! intent(out) real(wp), dimension(:), intent(inout), optional :: rhs !! intent(out) +real(wp), intent(out), optional :: increments(size(Ts),5) integer, parameter :: ll=2 !number of lower diagonals real(wp), dimension(3*ll+1,size(Ts)) :: M !note extra rows for lapack workspace real(wp), dimension(size(Ts)) :: Dh real(wp), dimension(size(Ts)) :: backEuler1D -integer :: ix1,lx1 +integer :: ix1,lx1,info !------------------------------------------------------------ !-------DEFINE A MATRIX USING BANDED STORAGE @@ -368,7 +396,16 @@ function backEuler1D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i,coeffs,rhs) !! ## DO SOME STUFF TO CALL LAPACK'S BANDED SOLVER !> BANDED SOLVER (INPUT MATRIX MUST BE SHIFTED 'DOWN' BY KL ROWS) -call gbsv(M,backEuler1D,kl=2) +call eliminate_dirichlet_columns(M,backEuler1D,BCtype) +call scale_interior_rows(M,backEuler1D,dt) +call gbsv(M,backEuler1D,kl=2,info=info) +call check_solver_info(info,'backEuler1D') + +if (present(increments)) then + increments=dt*parabolic_terms(backEuler1D,A,B,C,D,E,dx1,dx1i) + increments(1,5)=backEuler1D(1)-Ts(1) + increments(lx1,5)=backEuler1D(lx1)-Ts(lx1) +endif !> this is for if one wants to output the matrix bands for testing purposes if (present(coeffs)) then @@ -379,4 +416,68 @@ function backEuler1D(Ts,A,B,C,D,E,Tsminx1,Tsmaxx1,dt,BCtype,dx1,dx1i,coeffs,rhs) end function backEuler1D +subroutine check_solver_info(info,stage) + integer, intent(in) :: info + character(*), intent(in) :: stage + + if (info == 0) return + write(stderr,'(a,a,a,i0)') 'PDEparabolic: ',stage,' gbsv INFO=',info + if (info < 0) error stop 'PDEparabolic: invalid LAPACK argument' + error stop 'PDEparabolic: singular diffusion matrix' +end subroutine check_solver_info + +pure function parabolic_terms(T,A,B,C,D,E,dx,dxi) result(terms) + real(wp), intent(in) :: T(:),A(:),B(:),C(:),D(:),E(:),dx(0:),dxi(:) + real(wp) :: terms(size(T),5),left,right + integer :: i + terms=0 + do i=2,size(T)-1 + left=0.5_wp*(D(i-1)+D(i))*(T(i)-T(i-1))/dx(i) + right=0.5_wp*(D(i)+D(i+1))*(T(i+1)-T(i))/dx(i+1) + terms(i,1)=A(i)*T(i) + terms(i,2)=B(i)*(T(i+1)-T(i-1))/(dx(i+1)+dx(i)) + terms(i,3)=C(i)*(right-left)/dxi(i) + terms(i,4)=E(i) + enddo +end function parabolic_terms + +! Keep the algebraic endpoint rows at unit scale while bringing each interior +! stage equation to dimensionless time. SI diffusion coefficients at low +! density can otherwise dwarf the endpoint rows and lose prescribed values +! through banded-LU pivoting. The equation and the method are unchanged. +! Move known Dirichlet values into the interior RHS before pivoting. This +! decouples endpoint rows from the stiff interior and preserves prescribed +! values exactly; Neumann endpoint equations retain their coupled columns. +pure subroutine eliminate_dirichlet_columns(matrix,rhs,bc_type) +real(wp),intent(inout)::matrix(:,:),rhs(:) +integer,intent(in)::bc_type(2) +integer::i,n +n=size(rhs) +if(bc_type(1)==0)then + do i=2,min(3,n-1) + rhs(i)=rhs(i)-matrix(4+i,1)*rhs(1) + matrix(4+i,1)=0 + enddo +endif +if(bc_type(2)==0)then + do i=max(2,n-2),n-1 + rhs(i)=rhs(i)-matrix(5+i-n,n)*rhs(n) + matrix(5+i-n,n)=0 + enddo +endif +end subroutine eliminate_dirichlet_columns + +pure subroutine scale_interior_rows(matrix,rhs,stage_dt) +real(wp),intent(inout)::matrix(:,:),rhs(:) +real(wp),intent(in)::stage_dt +integer::i,j,n +n=size(rhs) +do i=2,n-1 + do j=max(1,i-2),min(n,i+2) + matrix(5+i-j,j)=matrix(5+i-j,j)*stage_dt + enddo + rhs(i)=rhs(i)*stage_dt +enddo +end subroutine scale_interior_rows + end module PDEparabolic diff --git a/src/numerical/diffusion/diffusion.f90 b/src/numerical/diffusion/diffusion.f90 index 5569bc09f..d3b1168d6 100644 --- a/src/numerical/diffusion/diffusion.f90 +++ b/src/numerical/diffusion/diffusion.f90 @@ -125,7 +125,7 @@ subroutine set_BCtype(Teinf,gridflag) end subroutine set_BCtype - function backEuler3D_curv(f,A,B,C,D,E,dt,x) + function backEuler3D_curv(f,A,B,C,D,E,dt,x,increments) !! SOLVE A 3D SEQUENCE OF 1D DIFFUSION PROBLEMS. !! GHOST CELLS ARE ACCOMMODATED AS THEY PROVIDE !! A CONVENIENT MEMORY SPACE FOR BOUNDARY CONDITIONS. @@ -135,6 +135,8 @@ function backEuler3D_curv(f,A,B,C,D,E,dt,x) real(wp), intent(in) :: dt class(curvmesh), intent(in) :: x + real(wp), intent(out), optional :: increments(size(f,1)-4,size(f,2)-4,size(f,3)-4,5) + real(wp), allocatable :: local_increments(:,:) integer :: ix2,ix3,lx1,lx2,lx3 real(wp),dimension(size(f,1)-4) :: fx1slice @@ -144,12 +146,23 @@ function backEuler3D_curv(f,A,B,C,D,E,dt,x) lx2=size(f,2)-4 lx3=size(f,3)-4 + ! Every returned halo value must be defined; previously only the interior + ! was assigned and the caller copied the undefined halo into temperature. + backEuler3D_curv=f + if(present(increments)) allocate(local_increments(lx1,5)) do ix3=1,lx3 do ix2=1,lx2 fx1slice=f(1:lx1,ix2,ix3) - fx1slice=backEuler1D(fx1slice,A(:,ix2,ix3), & + if(present(increments)) then + fx1slice=backEuler1D(fx1slice,A(:,ix2,ix3), & + B(:,ix2,ix3),C(:,ix2,ix3),D(:,ix2,ix3),E(:,ix2,ix3), & + f(0,ix2,ix3),f(lx1+1,ix2,ix3),dt,BCtype,x%dx1,x%dx1i,increments=local_increments) + increments(:,ix2,ix3,:)=local_increments + else + fx1slice=backEuler1D(fx1slice,A(:,ix2,ix3), & B(:,ix2,ix3),C(:,ix2,ix3),D(:,ix2,ix3),E(:,ix2,ix3), & f(0,ix2,ix3),f(lx1+1,ix2,ix3),dt,BCtype,x%dx1,x%dx1i) + endif !! inner ghost cells include boundary conditions backEuler3D_curv(1:lx1,ix2,ix3)=fx1slice end do @@ -157,7 +170,7 @@ function backEuler3D_curv(f,A,B,C,D,E,dt,x) end function backEuler3D_curv - function TRBDF23D_curv(f,A,B,C,D,E,dt,x) + function TRBDF23D_curv(f,A,B,C,D,E,dt,x,increments) !! SOLVE A 3D SEQUENCE OF 1D DIFFUSION PROBLEMS. !! GHOST CELLS ARE ACCOMMODATED AS THEY PROVIDE !! A CONVENIENT MEMORY SPACE FOR BOUNDARY CONDITIONS. @@ -175,6 +188,8 @@ function TRBDF23D_curv(f,A,B,C,D,E,dt,x) real(wp), intent(in) :: dt class(curvmesh), intent(in) :: x + real(wp), intent(out), optional :: increments(size(f,1)-4,size(f,2)-4,size(f,3)-4,5) + real(wp), allocatable :: local_increments(:,:) integer :: ix2,ix3,lx1,lx2,lx3 real(wp),dimension(size(f,1)-4) :: fx1slice @@ -184,12 +199,23 @@ function TRBDF23D_curv(f,A,B,C,D,E,dt,x) lx2=size(f,2)-4 lx3=size(f,3)-4 + ! Every returned halo value must be defined; previously only the interior + ! was assigned and the caller copied the undefined halo into temperature. + TRBDF23D_curv=f + if(present(increments)) allocate(local_increments(lx1,5)) do ix3=1,lx3 do ix2=1,lx2 fx1slice=f(1:lx1,ix2,ix3) - fx1slice=TRBDF21D(fx1slice,A(:,ix2,ix3), & + if(present(increments)) then + fx1slice=TRBDF21D(fx1slice,A(:,ix2,ix3), & + B(:,ix2,ix3),C(:,ix2,ix3),D(:,ix2,ix3),E(:,ix2,ix3), & + f(0,ix2,ix3),f(lx1+1,ix2,ix3),dt,BCtype,x%dx1,x%dx1i,increments=local_increments) + increments(:,ix2,ix3,:)=local_increments + else + fx1slice=TRBDF21D(fx1slice,A(:,ix2,ix3), & B(:,ix2,ix3),C(:,ix2,ix3),D(:,ix2,ix3),E(:,ix2,ix3), & f(0,ix2,ix3),f(lx1+1,ix2,ix3),dt,BCtype,x%dx1,x%dx1i) + endif !! inner ghost cells include boundary conditions TRBDF23D_curv(1:lx1,ix2,ix3)=fx1slice end do diff --git a/src/numerical/diffusion/diffusion_features.in.f90 b/src/numerical/diffusion/diffusion_features.in.f90 new file mode 100644 index 000000000..38efb2164 --- /dev/null +++ b/src/numerical/diffusion/diffusion_features.in.f90 @@ -0,0 +1,6 @@ +module diffusion_features +implicit none(type,external) +private +public :: midpoint_conduction_enabled +logical, parameter :: midpoint_conduction_enabled=@midpoint_conduction_fortran@ +end module diffusion_features diff --git a/src/numerical/diffusion/nonlinear_diffusion.f90 b/src/numerical/diffusion/nonlinear_diffusion.f90 new file mode 100644 index 000000000..1db886e7a --- /dev/null +++ b/src/numerical/diffusion/nonlinear_diffusion.f90 @@ -0,0 +1,47 @@ +module nonlinear_diffusion +! Proposed nonlinear time centering. The predictor is virtual: only the final +! TRBDF2 increments describe applied changes and enter the numerical ledger. +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +use phys_consts, only: wp +use meshobj, only: curvmesh +use collisions, only: thermal_conduct +use diffusion, only: diffusion_prep, backEuler3D, TRBDF23D +implicit none(type,external) +private +public :: midpoint_TRBDF23D +contains +function midpoint_TRBDF23D(isp,x,ns,T,nn,J1,Tn,Teinf,dt,increments,lambda_applied) result(Tnew) + integer, intent(in) :: isp + class(curvmesh), intent(in) :: x + real(wp), intent(in) :: ns(-1:,-1:,-1:),T(-1:,-1:,-1:),nn(:,:,:,:),J1(-1:,-1:,-1:),Tn(:,:,:) + real(wp), intent(in) :: Teinf,dt + real(wp), intent(out), optional :: increments(size(T,1)-4,size(T,2)-4,size(T,3)-4,5) + real(wp), intent(out), optional :: lambda_applied(size(T,1)-4,size(T,2)-4,size(T,3)-4) + real(wp) :: Tnew(-1:size(T,1)-2,-1:size(T,2)-2,-1:size(T,3)-2) + real(wp), allocatable :: initial(:,:,:),predictor(:,:,:),lambda(:,:,:),beta(:,:,:) + real(wp), allocatable :: A(:,:,:),B(:,:,:),C(:,:,:),D(:,:,:),E(:,:,:) + integer :: n1,n2,n3 + n1=size(T,1)-4;n2=size(T,2)-4;n3=size(T,3)-4 + if(.not.ieee_is_finite(dt).or.dt<=0) error stop 'midpoint diffusion requires positive finite dt' + allocate(initial(-1:n1+2,-1:n2+2,-1:n3+2),predictor(-1:n1+2,-1:n2+2,-1:n3+2)) + allocate(lambda(n1,n2,n3),beta(n1,n2,n3),A(n1,n2,n3),B(n1,n2,n3),C(n1,n2,n3),D(n1,n2,n3),E(n1,n2,n3)) + initial=T + call thermal_conduct(isp,initial,ns,nn,J1,lambda,beta) + call diffusion_prep(isp,x,lambda,beta,ns,initial,A,B,C,D,E,Tn,Teinf) + predictor=backEuler3D(initial,A,B,C,D,E,dt/2,x) + ! Do not quietly introduce a new temperature floor in the virtual stage. + if(any(.not.ieee_is_finite(predictor(1:n1,1:n2,1:n3))).or. & + any(predictor(1:n1,1:n2,1:n3)<=0)) error stop 'nonpositive or nonfinite midpoint temperature' + call thermal_conduct(isp,predictor,ns,nn,J1,lambda,beta) + if(any(.not.ieee_is_finite(lambda)).or.any(lambda<=0)) error stop 'invalid midpoint conductivity' + ! Rebuild geometry and conductivity-dependent Neumann ghost differences. + ! Start the applied step from the original temperature, not the predictor. + call diffusion_prep(isp,x,lambda,beta,ns,initial,A,B,C,D,E,Tn,Teinf) + if(present(increments)) then + Tnew=TRBDF23D(initial,A,B,C,D,E,dt,x,increments) + else + Tnew=TRBDF23D(initial,A,B,C,D,E,dt,x) + endif + if(present(lambda_applied)) lambda_applied=lambda +end function midpoint_TRBDF23D +end module nonlinear_diffusion diff --git a/src/numerical/interpolation/interp2d.f90 b/src/numerical/interpolation/interp2d.f90 index 1d6e575ea..9c2289684 100644 --- a/src/numerical/interpolation/interp2d.f90 +++ b/src/numerical/interpolation/interp2d.f90 @@ -1,3 +1,4 @@ +! Audit modification 2026-09-16: initialize interpolation upper-bin indices at two. submodule (interpolation) interpolation2d implicit none (type, external) @@ -19,16 +20,21 @@ +if (.not.all(ieee_is_finite(f))) error stop "interp2: nonfinite source data" +call check_axis(x1); call check_axis(x2) +if (any(shape(f)/=[size(x1),size(x2)])) error stop "interp2: shape mismatch" +if (.not.all(ieee_is_finite(x1i)) .or. .not.all(ieee_is_finite(x2i))) error stop "interp2: nonfinite query" lx1=size(x1,1) lx2=size(x2,1) lxi=size(x1i,1) !only one size since this a flat list of grid points +if (size(x2i)/=lxi) error stop "interp2: query shape mismatch" allocate(interp2(lxi)) do ixi=1,lxi !find the x1 'bin' for this point; i.e. find ix1 s.t. xi(ix1i) is between x(ix1-1) and x(ix1) ix10=1 - ix1=lx1/2 + ix1=max(2,lx1/2) ix1fin=lx1 if (x1i(ixi)>=x1(1) .and. x1i(ixi)<=x1(lx1)) then !in bounds do while(.not.(x1i(ixi)>=x1(ix1-1) .and. x1i(ixi)<=x1(ix1))) !keep going until we are in the interval we want @@ -51,7 +57,7 @@ !find the x2 'bin' for this point; i.e. find ix2 s.t. x2i(ix2i) is between x2(ix2-1) and x2(ix2) ix20=1 - ix2=lx2/2 + ix2=max(2,lx2/2) ix2fin=lx2 if (x2i(ixi)>=x2(1) .and. x2i(ixi)<=x2(lx2)) then !in bounds do while(.not.(x2i(ixi)>=x2(ix2-1) .and. x2i(ixi)<=x2(ix2))) !keep going until we are in the interval we want @@ -115,6 +121,10 @@ integer :: lx1,lx2,lx1i,lx2i,ix1,ix2,ix1i,ix2i +if (.not.all(ieee_is_finite(f))) error stop "interp2: nonfinite source data" +call check_axis(x1); call check_axis(x2) +if (any(shape(f)/=[size(x1),size(x2)])) error stop "interp2: shape mismatch" +if (.not.all(ieee_is_finite(x1i)) .or. .not.all(ieee_is_finite(x2i))) error stop "interp2: nonfinite query" lx1=size(x1,1) lx2=size(x2,1) lx1i=size(x1i,1) @@ -124,19 +134,25 @@ do ix2i=1,lx2i do ix1i=1,lx1i !find the x1 'bin' for this point; i.e. find ix1 s.t. xi(ix1i) is between x(ix1-1) and x(ix1) - ix1=1 - do while(x1i(ix1i)>x1(ix1) .and. ix1<=lx1) + ix1=2 + do while(ix1x2(ix2) .and. ix2<=lx2) + ix2=2 + do while(ix2x1(lx1) .or. x2i(ix2i)x2(lx2)) then + interp2_plaid(ix1i,ix2i)=0._wp + cycle + endif !execute interpolations in x1 for fixed values of x2 at this point if (ix1>1 .and. ix1<=lx1 .and. ix2>1 .and. ix2<=lx2) then !interpolation !first the "prev" x2 value diff --git a/src/numerical/interpolation/interpolation.f90 b/src/numerical/interpolation/interpolation.f90 index 1b49ace30..99fdb1337 100644 --- a/src/numerical/interpolation/interpolation.f90 +++ b/src/numerical/interpolation/interpolation.f90 @@ -1,10 +1,14 @@ +! Audit modification 2026-09-16: initialize interpolation upper-bin indices at two. module interpolation use phys_consts, only: wp +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite implicit none (type, external) private public :: interp1, interp2, interp3 +! The separately compiled interp2 submodule needs an externally emitted symbol. +public :: check_axis, coverage_mask interface ! interp2d.f90 module pure function interp2_plaid(x1,x2,f,x1i,x2i) @@ -20,6 +24,27 @@ end function interp2 end interface contains + pure function coverage_mask(x,xi) result(covered) + real(wp), intent(in) :: x(:),xi(:) + logical :: covered(size(xi)) + call check_axis(x,1) + if (.not.all(ieee_is_finite(xi))) error stop 'coverage: nonfinite target coordinate' + ! A singleton is an explicitly invariant dimension, not a finite-width cell. + covered=.true. + if (size(x)>1) covered=xi>=x(1) .and. xi<=x(size(x)) + end function coverage_mask + + pure subroutine check_axis(x, min_points) + real(wp), intent(in) :: x(:) + integer, intent(in), optional :: min_points + integer :: nmin + nmin=2 + if (present(min_points)) nmin=min_points + if (size(x)=x1(1) .and. x1i(ix1i)<=x1(lx1)) then !in bounds do while(.not.(x1i(ix1i)>=x1(ix1-1) .and. x1i(ix1i)<=x1(ix1))) !keep going until we are in the interval we want @@ -97,6 +132,12 @@ pure real(wp) function interp3(x1,x2,x3,f,x1i,x2i,x3i,interptypein) integer :: ix10,ix1fin,ix20,ix2fin,ix30,ix3fin integer :: interptype ! set to zero for nearest neighbor, anything else will be trilinear + if (.not.all(ieee_is_finite(f))) error stop "interp3: nonfinite source data" + call check_axis(x1); call check_axis(x2); call check_axis(x3) + if (any(shape(f)/=[size(x1),size(x2),size(x3)])) error stop "interp3: shape mismatch" + if (size(x1i)/=size(x2i) .or. size(x1i)/=size(x3i)) error stop "interp3: query shape mismatch" + if (.not.all(ieee_is_finite(x1i)) .or. .not.all(ieee_is_finite(x2i)) .or. & + .not.all(ieee_is_finite(x3i))) error stop "interp3: nonfinite query" ! alter the default interpolation type if the user has provided an input if (present(interptypein)) then interptype=interptypein @@ -112,7 +153,7 @@ pure real(wp) function interp3(x1,x2,x3,f,x1i,x2i,x3i,interptypein) do ixi=1,lxi !find the x1 'bin' for this point; i.e. find ix1 s.t. xi(ix1i) is between x(ix1-1) and x(ix1) ix10=1 - ix1=lx1/2 + ix1=max(2,lx1/2) ix1fin=lx1 if (x1i(ixi)>=x1(1) .and. x1i(ixi)<=x1(lx1)) then !in bounds do while(.not.(x1i(ixi)>=x1(ix1-1) .and. x1i(ixi)<=x1(ix1))) !keep going until we are in the interval we want diff --git a/src/numerical/mesh/meshobj_cart.f90 b/src/numerical/mesh/meshobj_cart.f90 index a42661a35..ad507c2c9 100644 --- a/src/numerical/mesh/meshobj_cart.f90 +++ b/src/numerical/mesh/meshobj_cart.f90 @@ -111,11 +111,10 @@ subroutine make_cartmesh(self) call self%native2ECEFspher(self%glonctr,self%glatctr,self%z,self%x,self%y,r,theta,phispher) - ! now assign structure elements and deallocate unneeded temp variables + ! now assign structure elements ! self%r=r(1:lz,1:lx,1:ly); self%theta=theta(1:lz,1:lx,1:ly); self%phi=phispher(1:lz,1:lx,1:ly) ! don't need ghost cells! self%r=r(-1:lz+2,-1:lx+2,-1:ly+2); self%theta=theta(-1:lz+2,-1:lx+2,-1:ly+2); self%phi=phispher(-1:lz+2,-1:lx+2,-1:ly+2) - deallocate(r,theta,phispher) ! compute the geographic coordinates !print*, ' make_cartmesh: geographic coordinates from magnetic...' @@ -127,6 +126,7 @@ subroutine make_cartmesh(self) self%hz(-1:lz+2,-1:lx+2,-1:ly+2)=self%calc_h1(r,theta,phispher) self%hx(-1:lz+2,-1:lx+2,-1:ly+2)=self%calc_h2(r,theta,phispher) self%hy(-1:lz+2,-1:lx+2,-1:ly+2)=self%calc_h3(r,theta,phispher) + deallocate(r,theta,phispher) ! q cell interface metric factors !print*, ' make_cartmesh: metric factors for cell q-interfaces...' diff --git a/src/numerical/potential/potential_comm_mumps.f90 b/src/numerical/potential/potential_comm_mumps.f90 index ee1b68866..f234ef315 100644 --- a/src/numerical/potential/potential_comm_mumps.f90 +++ b/src/numerical/potential/potential_comm_mumps.f90 @@ -35,7 +35,7 @@ module potential_comm public :: electrodynamics, halo_pot, potential_sourceterms, pot2perpfield, velocities, get_BGEfields, & acc_perpconductioncurrents,acc_perpwindcurrents,acc_perpgravcurrents,acc_pressurecurrents, & parallel_currents,polarization_currents,BGfields_boundaries_root,BGfields_boundaries_worker, & - acc_perpBGconductioncurrents + acc_perpBGconductioncurrents, validate_capacitance_mode !! overloading to deal with vestigial cartesian->curvilinear code interface electrodynamics @@ -149,12 +149,14 @@ subroutine electrodynamics_curv(it,t,dt,nn,vn2,vn3,Tn,cfg,ns,Ts,vs1,B1,vs2,vs3,x real(wp), dimension(1:lx1,1:lx2,1:lx3,1:lsp) :: muP,muH,nusn real(wp), dimension(1:lx1,1:lx2,1:lx3) :: incap real(wp) :: tstart,tfin - real(wp) :: minh1,maxh1,minh2,maxh2,minh3,maxh3 ! background variables and boundary conditions, full grid sized variables ! slab-sized background variables real(wp), dimension(1:lx1,1:lx2,1:lx3) :: E02src,E03src + ! Reject combinations whose potential equations do not include capacitance. + call validate_capacitance_mode(cfg,x,flagdirich) + !> update conductivities and mobilities call cpu_time(tstart) call conductivities(nn,Tn,ns,Ts,vs1,B1,sig0,sigP,sigH,muP,muH,nusn,sigPgrav,sigHgrav) @@ -175,14 +177,6 @@ subroutine electrodynamics_curv(it,t,dt,nn,vn2,vn3,Tn,cfg,ns,Ts,vs1,B1,vs2,vs3,x !> error checking for cap. vs. grid types - viz. we do not support capacitive solves on anything other than Cartesian grids if (cfg%flagcap/=0) then ! some sort of capacitance is being used in the simulation call capacitance(ns,B1,cfg,incap) !> full cfg needed for optional inputs... - if (it==1) then !check that we don't have an unsupported grid type for doing capacitance - minh1=minval(x%h1); maxh1=maxval(x%h1); - minh2=minval(x%h2); maxh2=maxval(x%h2); - minh3=minval(x%h3); maxh3=maxval(x%h3); - if (minh1<0.99d0 .or. maxh1>1.01d0 .or. minh2<0.99d0 .or. maxh2>1.01d0 .or. minh3<0.99d0 .or. maxh3>1.01d0) then - error stop 'Capacitance is being calculated for possibly unsupported grid type. Please check input file settings.' - end if - end if else incap=0d0 end if @@ -712,6 +706,24 @@ subroutine parallel_currents(cfg,x,J2,J3,Vminx1slab,Vmaxx1slab,Phi,sig0,flagdiri end subroutine parallel_currents + subroutine validate_capacitance_mode(cfg,x,flagdirich) + type(gemini_cfg), intent(in) :: cfg + class(curvmesh), intent(in) :: x + integer, intent(in) :: flagdirich + + if (cfg%flagcap==0) return + if (cfg%flagcap<0 .or. cfg%flagcap>2) error stop 'capacitance: flagcap must be 0, 1 or 2' + if (cfg%potsolve/=1 .or. x%lx2all<=1 .or. x%lx3all<=1) & + error stop 'capacitance: requires a 3D domain with field-integrated potsolve=1' + ! Only this boundary formulation calls the dynamic polarization solver. + ! The field-resolved, prescribed-potential and current-BC paths omit it. + if (flagdirich/=0) error stop 'capacitance: requires potential-gradient boundary flagdirich=0' + if (.not.all(ieee_is_finite(x%h1)) .or. .not.all(ieee_is_finite(x%h2)) .or. & + .not.all(ieee_is_finite(x%h3))) error stop 'capacitance: nonfinite mesh metrics' + if (any(abs(x%h1-1._wp)>0.01_wp) .or. any(abs(x%h2-1._wp)>0.01_wp) .or. & + any(abs(x%h3-1._wp)>0.01_wp)) error stop 'capacitance: requires Cartesian mesh metrics' + end subroutine validate_capacitance_mode + subroutine polarization_currents(cfg,x,dt,incap,E2,E3,E2prev,E3prev,v2,v3,J1pol,J2pol,J3pol) !> Computes the polarization currents resulting from time-dependence and shearing of the plasma type(gemini_cfg), intent(in) :: cfg diff --git a/src/sources/CMakeLists.txt b/src/sources/CMakeLists.txt index f13b6e062..afd32fc67 100644 --- a/src/sources/CMakeLists.txt +++ b/src/sources/CMakeLists.txt @@ -3,5 +3,10 @@ $ $ ) target_link_libraries(sources PRIVATE calculus collision const meshobj grid) +# A callable conservative pair operator for qualification and later coupling. +# It is not substituted into the existing split source driver implicitly. +add_library(pair_exchange OBJECT pair_exchange.f90) +target_link_libraries(pair_exchange PRIVATE const) + add_library(sources_mpi OBJECT sources_mpi.f90) target_link_libraries(sources_mpi PRIVATE mpimod) diff --git a/src/sources/pair_exchange.f90 b/src/sources/pair_exchange.f90 new file mode 100644 index 000000000..d28678d58 --- /dev/null +++ b/src/sources/pair_exchange.f90 @@ -0,0 +1,89 @@ +module pair_exchange +! Constant-rate, closed two-reservoir model. SI: rho [kg/m^3], Cv [J/m^3/K], +! drag [kg/m^3/s], conductance [J/m^3/s/K]. Rates are explicitly supplied: +! this operator enforces laws, but does not validate their physical magnitudes. +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +use phys_consts, only: wp,kB +implicit none(type,external) +private +public :: shared_pair_coefficients, pair_exchange_rates, advance_pair_exchange +contains +pure subroutine shared_pair_coefficients(ma,mb,na,nb,nuab,nuba,phi,psi,drag,conductance) + real(wp), intent(in) :: ma,mb,na,nb,nuab,nuba,phi,psi + real(wp), intent(out) :: drag,conductance + real(wp) :: reciprocal_rate + if(any(.not.ieee_is_finite([ma,mb,na,nb,nuab,nuba,phi,psi]))) error stop 'nonfinite pair coefficient' + if(min(ma,mb)<=0.or.min(na,nb,nuab,nuba,phi,psi)<0) error stop 'invalid pair coefficient' + ! Explicit model proposal: average the two rounded directional momentum + ! rates once, then use this identical rate in both species equations. + reciprocal_rate=(ma*na*nuab+mb*nb*nuba)/2 + drag=reciprocal_rate*phi + ! Three translational degrees of freedom determine the exchanged POWER. + ! Species-specific heat capacities determine temperature response separately. + conductance=3*kB*reciprocal_rate*psi/(ma+mb) +end subroutine shared_pair_coefficients + +pure subroutine pair_exchange_rates(ma,mb,drag,conductance,Ta,Tb,va,vb,Fa,Fb,Qa,Qb) + real(wp), intent(in) :: ma,mb,drag,conductance,Ta,Tb,va(3),vb(3) + real(wp), intent(out) :: Fa(3),Fb(3),Qa,Qb + real(wp) :: heating,transfer,fraction_a + if(min(ma,mb)<=0.or.min(drag,conductance)<0) error stop 'invalid pair rate' + fraction_a=mb/(ma+mb) + Fa=drag*(vb-va);Fb=-Fa + heating=drag*sum((va-vb)**2) + transfer=conductance*(Tb-Ta) + Qa=transfer+fraction_a*heating + Qb=-transfer+(1-fraction_a)*heating +end subroutine pair_exchange_rates + +pure subroutine advance_pair_exchange(rhoa,rhob,Ca,Cb,fraction_a,drag,conductance,dt,va,vb,Ua,Ub) + real(wp), intent(in) :: rhoa,rhob,Ca,Cb,fraction_a,drag,conductance,dt + real(wp), intent(inout) :: va(3),vb(3),Ua,Ub + real(wp) :: reduced_rho, reduced_C, rate_v,rate_T,delta(3),dP(3),kinetic_heat + real(wp) :: difference0,friction0,integral,thermal_transfer + real(wp) :: heat_a,heat_b,friction_difference,thermal_fraction + if(any(.not.ieee_is_finite([rhoa,rhob,Ca,Cb,fraction_a,drag,conductance,dt,va,vb,Ua,Ub]))) & + error stop 'nonfinite pair state' + if(min(rhoa,rhob,Ca,Cb)<=0.or.min(drag,conductance,dt,Ua,Ub)<0.or. & + fraction_a<0.or.fraction_a>1) error stop 'invalid pair state' + if(dt==0.or.(drag==0.and.conductance==0)) return + reduced_rho=rhoa*(rhob/(rhoa+rhob)) + reduced_C=Ca*(Cb/(Ca+Cb)) + rate_v=drag/reduced_rho + rate_T=conductance/reduced_C + delta=va-vb + difference0=Ua/Ca-Ub/Cb + dP=-reduced_rho*delta*decay_fraction(rate_v*dt) + va=va+dP/rhoa;vb=vb-dP/rhob + ! Account for the actual finite-step loss of relative bulk kinetic energy, + ! rather than integrating frozen velocities as if the loss stayed constant. + kinetic_heat=(reduced_rho*sum(delta**2)/2)*decay_fraction(2*rate_v*dt) + friction0=drag*sum(delta**2) + ! Stable convolution of e^(-rate_T*t) with e^(-2*rate_v*t). + integral=dt*exp(-min(rate_T,2*rate_v)*dt)*phi_negative(abs(rate_T-2*rate_v)*dt) + friction_difference=friction0*(fraction_a/Ca-(1-fraction_a)/Cb)*integral + thermal_fraction=decay_fraction(rate_T*dt) + ! A single opposite transfer retains small changes without reconstructing + ! each large reservoir from its equilibrium value. + thermal_transfer=reduced_C*(-difference0*thermal_fraction+friction_difference) + heat_a=Ca/(Ca+Cb)*kinetic_heat+thermal_transfer + heat_b=kinetic_heat-heat_a + Ua=Ua+heat_a;Ub=Ub+heat_b +end subroutine advance_pair_exchange + +pure elemental function phi_negative(z) result(phi) + real(wp), intent(in) :: z + real(wp) :: phi + if(z<1e-3_wp) then + phi=1-z*(1._wp/2-z*(1._wp/6-z*(1._wp/24-z*(1._wp/120-z*(1._wp/720-z/5040))))) + else + phi=(1-exp(-z))/z + endif +end function phi_negative + +pure elemental function decay_fraction(z) result(fraction) + real(wp), intent(in) :: z + real(wp) :: fraction + fraction=z*phi_negative(z) +end function decay_fraction +end module pair_exchange diff --git a/src/temporal/CMakeLists.txt b/src/temporal/CMakeLists.txt index 904486e9d..3243d873b 100644 --- a/src/temporal/CMakeLists.txt +++ b/src/temporal/CMakeLists.txt @@ -4,7 +4,7 @@ add_library(timeutils OBJECT timeutils.f90) target_link_libraries(timeutils PRIVATE const) add_library(temporal_mpi OBJECT temporal_mpi.f90) -target_link_libraries(temporal_mpi PRIVATE gemini3d_config const meshobj mpimod +target_link_libraries(temporal_mpi PRIVATE temporal gemini3d_config const meshobj mpimod MPI::MPI_Fortran ) diff --git a/src/temporal/temporal.f90 b/src/temporal/temporal.f90 index b8d5180db..f770cbeb8 100644 --- a/src/temporal/temporal.f90 +++ b/src/temporal/temporal.f90 @@ -1,6 +1,7 @@ module temporal use phys_consts, only: kB,mu0,ms,lsp,pi, wp, debug +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite implicit none (type, external) @@ -24,6 +25,22 @@ subroutine cflcalc(Ts,vs1,vs2,vs3,dl1i,dl2i,dl3i,dt,maxcfl) lx2=size(Ts,2)-4 lx3=size(Ts,3)-4 + if (.not.ieee_is_finite(dt)) error stop "cflcalc: nonfinite step" + if (dt<=0) error stop "cflcalc: nonpositive step" + if (min(lx1,lx2,lx3)<1 .or. size(Ts,4)/=lsp) error stop "cflcalc: invalid state shape" + if (any(shape(Ts)/=shape(vs1)) .or. any(shape(Ts)/=shape(vs2)) .or. & + any(shape(Ts)/=shape(vs3))) error stop "cflcalc: velocity shape mismatch" + if (any(shape(dl1i)/=[lx1,lx2,lx3]) .or. any(shape(dl2i)/=[lx1,lx2,lx3]) .or. & + any(shape(dl3i)/=[lx1,lx2,lx3])) error stop "cflcalc: metric shape mismatch" + if (.not.all(ieee_is_finite(Ts(1:lx1,1:lx2,1:lx3,:))) .or. & + .not.all(ieee_is_finite(vs1(1:lx1,1:lx2,1:lx3,:))) .or. & + .not.all(ieee_is_finite(vs2(1:lx1,1:lx2,1:lx3,:))) .or. & + .not.all(ieee_is_finite(vs3(1:lx1,1:lx2,1:lx3,:)))) error stop "cflcalc: nonfinite state" + if (minval(Ts(1:lx1,1:lx2,1:lx3,:))<0) error stop "cflcalc: negative temperature" + if (.not.all(ieee_is_finite(dl1i)) .or. .not.all(ieee_is_finite(dl2i)) .or. & + .not.all(ieee_is_finite(dl3i))) error stop "cflcalc: nonfinite metric" + if (min(minval(dl1i),minval(dl2i),minval(dl3i))<=0) error stop "cflcalc: nonpositive metric" + !EVALUATE TIME STEP AGAINST LOCAL SOUND SPEED AND ADVECTION maxcfl=0._wp do isp=1,lsp diff --git a/src/temporal/temporal_mpi.f90 b/src/temporal/temporal_mpi.f90 index 5e58f7823..811052c48 100644 --- a/src/temporal/temporal_mpi.f90 +++ b/src/temporal/temporal_mpi.f90 @@ -11,19 +11,46 @@ module temporal_mpi !/home/zettergm/zettergmdata/GEMINI/temporal/temporal.f90:65:0: warning: unused parameter ‘b3’ [-Wunused-parameter] !/home/zettergm/zettergmdata/GEMINI/temporal/temporal.f90:65:0: warning: unused parameter ‘potsolve’ [-Wunused-parameter] +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +use, intrinsic :: iso_fortran_env, only: int64 +use temporal, only: cflcalc use phys_consts, only: kB,mu0,ms,lsp,pi, wp, debug use mpimod, only: mpi_realprec, tag=>gemini_mpi, mpi_cfg use meshobj, only: curvmesh use gemini3d_config, only: gemini_cfg -use mpi_f08, only: MPI_COMM_WORLD,MPI_STATUS_IGNORE, mpi_send, mpi_recv +use mpi_f08, only: MPI_COMM_WORLD,MPI_STATUS_IGNORE, mpi_send, mpi_recv, MPI_Allreduce, MPI_MAX implicit none (type, external) private -public :: dt_comm +public :: dt_comm, enforce_post_update_cfl contains + pure real(wp) function to_next_knot(t,cadence) result(dt) + real(wp), intent(in) :: t,cadence + if (.not.all(ieee_is_finite([t,cadence]))) error stop "driver knot: nonfinite time" + if (cadence<=0) error stop "driver knot: cadence must be positive" + dt=real(floor(t/cadence,kind=int64)+1_int64,wp)*cadence-t + if (dt<=epsilon(t)*max(1._wp,abs(t))*8) dt=cadence + end function to_next_knot + + !> Fail before fluid advancement if newly solved drifts invalidate the selected step. + !> Retrying requires restoring all stateful driver/potential updates and is not implicit. + subroutine enforce_post_update_cfl(Ts,vs1,vs2,vs3,x,dt) + real(wp), intent(in) :: Ts(-1:,-1:,-1:,:),vs1(-1:,-1:,-1:,:), & + vs2(-1:,-1:,-1:,:),vs3(-1:,-1:,-1:,:) + class(curvmesh), intent(in) :: x + real(wp), intent(in) :: dt + real(wp) :: local_cfl,global_cfl + call cflcalc(Ts,vs1,vs2,vs3,x%dl1i,x%dl2i,x%dl3i,dt,local_cfl) + call MPI_Allreduce(local_cfl,global_cfl,1,mpi_realprec,MPI_MAX,MPI_COMM_WORLD) + if (global_cfl>1._wp+64*epsilon(global_cfl)) then + if (mpi_cfg%myid==0) print *, 'Post-update CFL exceeds one: ',global_cfl, ' dt=',dt + error stop "Updated forcing invalidates the time step; reduce tcfl or refine driver cadence." + endif + end subroutine enforce_post_update_cfl + subroutine dt_comm(t,tout,tglowout,cfg,ns,Ts,vs1,vs2,vs3,B1,B2,B3,x,dt) real(wp), intent(in) :: t,tout,tglowout type(gemini_cfg), intent(in) :: cfg @@ -52,18 +79,32 @@ subroutine dt_comm(t,tout,tglowout,cfg,ns,Ts,vs1,vs2,vs3,B1,B2,B3,x,dt) !CHECK WHETHER WE'D OVERSTEP OUR TARGET OUTPUT TIME !GLOW OUTPUT HAS PRIORITY SINCE IT WILL OUTPUT MORE OFTEN - if ((cfg%flagglow/=0).and.(t+dt>tglowout)) then + if ((cfg%flagglow/=0).and.(tglowout>t).and.(t+dt>tglowout)) then dt=tglowout-t print *, 'GLOW is throttling dt...' end if - if (t+dt>tout) then + if (tout>t .and. t+dt>tout) then dt=tout-t if (debug) print *, 'Slowing down for an output...' end if - !! DON'T ALLOW ZERO DT - dt = max(dt, 1e-6_wp) + ! The existing frontend initializes output deadlines to t. Its first + ! electrodynamic/fluid update populates derived output quantities before + ! writing that frame. Preserve this bootstrap with a CAP, never a floor: + ! a smaller stability-limited step must not be increased to 1 microsecond. + if (tout==t .or. (cfg%flagglow/=0 .and. tglowout==t)) dt=min(dt,1e-6_wp) + + ! Do not cross the final time or a supplied driver knot. + dt=min(dt,cfg%tdur-t) + if (cfg%flagprecfile/=0) dt=min(dt,to_next_knot(t,cfg%dtprec)) + if (cfg%flagE0file/=0) dt=min(dt,to_next_knot(t,cfg%dtE0)) + if (cfg%flagsolfluxfile/=0) dt=min(dt,to_next_knot(t,cfg%dtsolflux)) + if (cfg%flagneutralBGfile/=0) dt=min(dt,to_next_knot(t,cfg%dtneuBGfile)) + if (cfg%flagdneu/=0) dt=min(dt,to_next_knot(t,cfg%dtneu)) + ! Never increase a stability-limited step to an arbitrary minimum. + if (.not.ieee_is_finite(dt)) error stop "dt_comm: nonfinite time step" + if (dt<=0 .or. t+dt<=t) error stop "dt_comm: time step cannot advance the simulation" !! SEND GLOBAL DT TO ALL WORKERS do iid=1,mpi_cfg%lid-1 diff --git a/src/temporal/timeutils.f90 b/src/temporal/timeutils.f90 index 9750702ca..2c8d3c313 100644 --- a/src/temporal/timeutils.f90 +++ b/src/temporal/timeutils.f90 @@ -1,9 +1,11 @@ module timeutils use phys_consts, only: wp +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite use, intrinsic :: iso_fortran_env, only: sp=>real32, dp=>real64, int32, int64 implicit none (type, external) private +public :: elapsed_seconds, shift_datetime public :: ymd2doy, sza, dateinc, utsec2filestem, date_filename, day_wrap, find_lastdate, find_time_elapsed real(wp), parameter :: pi = 4._wp*atan(1._wp) @@ -90,7 +92,8 @@ pure subroutine dateinc(dtsec, ymd, UTsec) year=ymd(1); month=ymd(2); day=ymd(3); -if (day < 1) error stop 'temporal:timeutils:dateinc(): days are positive integers' +if (ymd2doy(year,month,day)<1) error stop 'timeutils: invalid date' +if (.not.all(ieee_is_finite([dtsec,UTsec]))) error stop 'timeutils: nonfinite time' if (utsec < 0) error stop 'negative UTsec, simulation should go forward in time only!' if (dtsec < 0) error stop 'negative dtsec, simulation should go forward in time only!' if (dtsec > 86400) error stop 'excessively large dtsec > 86400, simulation step should be small enough!' @@ -189,7 +192,7 @@ pure character(21) function utsec2filestem(ymd, UTsec) call day_wrap(year, month, day) endif -frac = millisec*1000 - seconds * 1000000 !< microseconds +frac = modulo(millisec,1000) * 1000 ! microseconds without signed integer overflow write(sec_str, '(I5.5, A1, I6.6)') seconds, '.', frac @@ -198,67 +201,80 @@ pure character(21) function utsec2filestem(ymd, UTsec) end function utsec2filestem -pure subroutine find_lastdate(ymd0,UTsec0,ymdtarget,UTsectarget,cadence,ymd,UTsec) +!> Gregorian day number, with input validation through ymd2doy. +pure integer(int64) function day_number(ymd) result(n) +integer, intent(in) :: ymd(3) +integer(int64) :: y +y=int(ymd(1)-1,int64) +n=365_int64*y+y/4-y/100+y/400+ymd2doy(ymd(1),ymd(2),ymd(3)) +end function day_number + +!> Signed elapsed seconds; no iteration over time steps and no loss of date at midnight. +pure real(wp) function elapsed_seconds(ymd0,ut0,ymd1,ut1) result(dt) +integer, intent(in) :: ymd0(3),ymd1(3) +real(wp), intent(in) :: ut0,ut1 +if (.not.all(ieee_is_finite([ut0,ut1]))) error stop 'timeutils: nonfinite UTC' +if (min(ut0,ut1)<0 .or. max(ut0,ut1)>=86400) error stop 'timeutils: UTC outside [0,86400)' +dt=real(day_number(ymd1)-day_number(ymd0),wp)*86400._wp+ut1-ut0 +end function elapsed_seconds + +!> Shift a normalized UTC date in either direction, including month/year boundaries. +pure subroutine shift_datetime(offset,ymd,utsec) +real(wp), intent(in) :: offset +integer, intent(inout) :: ymd(3) +real(wp), intent(inout) :: utsec +integer :: ndays,i +real(wp) :: total +if (.not.all(ieee_is_finite([offset,utsec]))) error stop 'timeutils: nonfinite offset' +if (abs(offset)>366._wp*86400*900) error stop 'timeutils: offset exceeds supported calendar' +if (ymd2doy(ymd(1),ymd(2),ymd(3))<1) error stop 'timeutils: invalid date' +if (utsec<0 .or. utsec>=86400) error stop 'timeutils: UTC outside [0,86400)' +total=utsec+offset +ndays=floor(total/86400._wp) +utsec=total-real(ndays,wp)*86400._wp +do i=1,abs(ndays) + if (ndays>0) then + ymd(3)=ymd(3)+1 + call day_wrap(ymd(1),ymd(2),ymd(3)) + else + ymd(3)=ymd(3)-1 + if (ymd(3)==0) then + ymd(2)=ymd(2)-1 + if (ymd(2)==0) then + ymd(1)=ymd(1)-1; ymd(2)=12 + endif + ymd(3)=daysmonth(ymd(1),ymd(2)) + endif + endif +enddo +if (ymd2doy(ymd(1),ymd(2),ymd(3))<1) error stop 'timeutils: date outside supported range' +end subroutine shift_datetime -!> Compute the last date before the target date based on a start date and date cadence. The -! file is assumed to exist and programmer needs to check for existence outside this -! procedure. -! FIXME: this will occasionally hang and may need to be re-examined at some point... - -integer, dimension(3), intent(in) :: ymd0 -real(wp), intent(in) :: UTsec0 -integer, dimension(3), intent(in) :: ymdtarget -real(wp), intent(in) :: UTsectarget -real(wp), intent(in) :: cadence -integer, dimension(3), intent(out) :: ymd +!> Latest cadence timestamp at or before target; return start when target precedes it. +pure subroutine find_lastdate(ymd0,UTsec0,ymdtarget,UTsectarget,cadence,ymd,UTsec) +integer, intent(in) :: ymd0(3),ymdtarget(3) +real(wp), intent(in) :: UTsec0,UTsectarget,cadence +integer, intent(out) :: ymd(3) real(wp), intent(out) :: UTsec - -integer, dimension(3) :: ymdnext -real(wp) :: UTsecnext -logical :: flagend - - -ymd=ymd0 -UTsec=UTsec0 -ymdnext=ymd0 -UTsecnext=UTsec0 -flagend=ymdnext(1)>=ymdtarget(1) .and. ymdnext(2)>=ymdtarget(2) .and. ymdnext(3)>=ymdtarget(3) .and. UTsecnext>UTsectarget & - .or. ymdnext(1)>ymdtarget(1) .or. ymdnext(2)>ymdtarget(2) .or. ymdnext(3)>ymdtarget(3) ! in case the first time step is the last before target -do while ( .not.(flagend) ) - ymd=ymdnext - UTsec=UTsecnext - call dateinc(cadence,ymdnext,UTsecnext) - flagend=ymdnext(1)>=ymdtarget(1) .and. ymdnext(2)>=ymdtarget(2) .and. ymdnext(3)>=ymdtarget(3) .and. UTsecnext>UTsectarget & - .or. ymdnext(1)>ymdtarget(1) .or. ymdnext(2)>ymdtarget(2) .or. ymdnext(3)>ymdtarget(3) -end do -! When the loops exits ymd,UTsec have the date of the last output file before the given target time OR the first output file in the case that the target date is before the begin date... - +real(wp) :: dt,offset +if (.not.ieee_is_finite(cadence)) error stop 'timeutils: nonfinite cadence' +if (cadence<=0 .or. cadence>86400) error stop 'timeutils: cadence must be in (0,86400]' +dt=max(0._wp,elapsed_seconds(ymd0,UTsec0,ymdtarget,UTsectarget)) +offset=real(floor(dt/cadence,kind=int64),wp)*cadence +ymd=ymd0; UTsec=UTsec0 +call shift_datetime(offset,ymd,UTsec) end subroutine find_lastdate - -pure function find_time_elapsed(ymdstart,UTsecstart,ymdend,UTsecend,dt) result(telapsed) - -! finds the amount of time that has elapsed between a given start and end date, using a given dt increment -! the resulting elapsed time will be the smallest multiple of dt that is >= true elapsed time - -!! inputs -integer, dimension(3), intent(in) :: ymdstart,ymdend -real(wp), intent(in) :: UTsecstart,UTsecend -reaL(wp), intent(in) :: dt - -integer, dimension(3) :: ymdnow -real(wp) :: UTsecnow - -real(wp) :: telapsed !! output - -telapsed=0._wp; ymdnow=ymdstart; UTsecnow=UTsecstart; -do while (.not. (all(ymdend==ymdnow) .and. UTsecnow>UTsecend) ) - call dateinc(dt,ymdnow,UTsecnow) - telapsed=telapsed+dt -end do -telapsed=telapsed-dt - +!> Greatest nonnegative multiple of dt not exceeding elapsed time (legacy semantics). +pure real(wp) function find_time_elapsed(ymdstart,UTsecstart,ymdend,UTsecend,dt) result(telapsed) +integer, intent(in) :: ymdstart(3),ymdend(3) +real(wp), intent(in) :: UTsecstart,UTsecend,dt +real(wp) :: actual +if (.not.ieee_is_finite(dt)) error stop 'timeutils: nonfinite cadence' +if (dt<=0 .or. dt>86400) error stop 'timeutils: cadence must be in (0,86400]' +actual=elapsed_seconds(ymdstart,UTsecstart,ymdend,UTsecend) +if (actual<0) error stop 'timeutils: end precedes start' +telapsed=real(floor(actual/dt,kind=int64),wp)*dt end function find_time_elapsed - end module timeutils diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 23c7d195d..95940bae8 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -8,7 +8,7 @@ magcalc.f90 ${CMAKE_CURRENT_BINARY_DIR}/magcalc_cli.f90 $ $ $ $ $ $ $ $ $ $ -$ $ $ +$ $ $ $ $ ) target_link_libraries(magcalc.bin PRIVATE exe_frontend sanity_check errors gemini3d_config timeutils const gemini3d_sysinfo diff --git a/src/utils/exe_frontend.in.f90 b/src/utils/exe_frontend.in.f90 index c0cb25200..a7d51f5da 100644 --- a/src/utils/exe_frontend.in.f90 +++ b/src/utils/exe_frontend.in.f90 @@ -2,15 +2,14 @@ module exe_frontend use, intrinsic :: iso_c_binding, only : c_int use, intrinsic :: iso_fortran_env, only : compiler_version, stderr=>error_unit, compiler_options -use phys_consts, only : wp -use gemini3d_config, only : gemini_cfg, read_configfile use gemini3d_sysinfo, only : get_compiler_vendor -use filesystem, only : parent, assert_is_dir, expanduser, remove -use timeutils, only : date_filename,dateinc +use filesystem, only : parent, assert_is_dir, expanduser implicit none (type, external) private -public :: clean_output, cli_parser, get_Ncpu, help_gemini_bin, help_gemini_run, help_magcalc_bin, help_magcalc_run +public :: cli_parser, get_Ncpu, quote_argument, help_gemini_bin, help_gemini_run, help_magcalc_bin, help_magcalc_run + +character(*), parameter :: default_numproc_flag = "@MPIEXEC_NUMPROC_FLAG@" interface !< cpu_count.cpp integer(c_int) function cpu_count_c() bind(c, name="cpu_count") @@ -26,10 +25,10 @@ integer function cpu_count() end function -subroutine cli_parser(plan, path, exe, mpiexec, extra) +subroutine cli_parser(plan, path, exe, mpiexec, numproc_flag, extra) logical, intent(out) :: plan -character(:), allocatable, intent(out) :: path, exe, mpiexec, extra +character(:), allocatable, intent(out) :: path, exe, mpiexec, numproc_flag, extra character(1000) :: buf integer :: argc, i, j, ierr, L @@ -88,22 +87,22 @@ subroutine cli_parser(plan, path, exe, mpiexec, extra) !> options passed to child executable case ('-dryrun', '-debug', '-nooutput') !! flags with no parameters - extra = extra // ' ' // trim(buf) + extra = extra // ' ' // quote_argument(trim(buf)) case ('-manual_grid') !! flags with two parameters - extra = extra // ' ' // trim(buf) + extra = extra // ' ' // quote_argument(trim(buf)) do j = 1,2 call get_command_argument(i+j, buf, length=L, status=ierr) if(ierr /= 0 .or. L==0 .or. buf(1:1) == "-") error stop trim(buf) // " -manual_grid expected two parameters" - extra = extra // ' ' // trim(buf) + extra = extra // ' ' // quote_argument(trim(buf)) enddo case ('-start_time', '-end_time') !! flags with four parameters - extra = extra // ' ' // trim(buf) + extra = extra // ' ' // quote_argument(trim(buf)) do j = 1,4 call get_command_argument(i+j, buf, length=L, status=ierr) if(ierr /= 0 .or. L==0 .or. buf(1:1) == "-") error stop trim(buf) // " -start_time expected four parameters" - extra = extra // ' ' // trim(buf) + extra = extra // ' ' // quote_argument(trim(buf)) enddo case default error stop "Gemini3D: unknown option: " // trim(buf) @@ -112,6 +111,11 @@ subroutine cli_parser(plan, path, exe, mpiexec, extra) if(.not.allocated(exe)) exe = find_exe("") if(.not.allocated(mpiexec)) mpiexec = find_mpiexec("") +if (len_trim(default_numproc_flag) > 0) then + numproc_flag = default_numproc_flag +else + numproc_flag = "-n" +endif end subroutine cli_parser @@ -136,26 +140,20 @@ integer function get_Ncpu() result(Ncpu) Ncpu = get_Ncpu_envvar("GEMINI_CPU") -if (Ncpu > 1) return +if (Ncpu >= 1) return Ncpu = get_Ncpu_envvar("NSLOTS") -if (Ncpu > 1) return +if (Ncpu >= 1) return Ncpu = get_Ncpu_envvar("PBS_NP") -if (Ncpu > 1) return +if (Ncpu >= 1) return Ncpu = get_Ncpu_envvar("SLURM_NTASKS") -if (Ncpu > 1) return +if (Ncpu >= 1) return -! write(stderr,'(A)') "NOTE: gemini3d.run: CPU count not found in environment variables, using cpu_count.cpp." // & -! " If running on an HPC, only one node will be used." +! write(stderr,'(A)') "NOTE: gemini3d.run: CPU count not found in environment variables, using one process." -Ncpu = cpu_count() -if (Ncpu <= 1) then - write(stderr,'(a,i0)') "ERROR: gemini3d.run:get_Ncpu: run mpiexec with gemini.bin" // & - "as CPU count wan not detected ", Ncpu - error stop -endif +Ncpu = 1 end function get_Ncpu @@ -289,6 +287,8 @@ subroutine help_gemini_run() print '(a)', 'Compiler vendor: '// get_compiler_vendor() print '(a)', 'Compiler version: ' // compiler_version() print '(/,a,/)', 'the first and only positional argument is simulation output directory.' +print '(a)', 'Existing outputs are preserved, including during dry runs and restarts.' +print '(a)', 'For a fresh run, use a new directory or explicitly remove old outputs yourself.' print '(a)', 'Optional arguments:' print '(a,t20,a)', '-plan', 'print MPI partition x2,x3 for given CPU count' print '(a,t20,a)', '-dryrun', 'allows quick check of first time step' @@ -336,43 +336,36 @@ subroutine help_magcalc_run() end subroutine help_magcalc_run -subroutine clean_output(path) - -character(*), intent(in) :: path - -type(gemini_cfg) :: cfg -integer, dimension(3) :: ymd -real(wp) :: UTsec -character(:), allocatable :: fn -logical :: exists - -cfg%outdir = path -cfg%infile = path // '/inputs/config.nml' -inquire(file=cfg%infile, exist=exists) -if(.not.exists) error stop 'gemini3d.run: not a file: ' // cfg%infile - -call read_configfile(cfg) - -ymd = cfg%ymd0 -UTsec = cfg%UTsec0 - -fn = date_filename(cfg%outdir, ymd, UTsec) // ".h5" +function quote_argument(arg) result(quoted) +character(*), intent(in) :: arg +character(:), allocatable :: quoted +integer :: i, n -do - !! new filename, add the 1 if it is the first - fn = date_filename(cfg%outdir, ymd, UTsec) // ".h5" - - inquire(file=fn, exist=exists) - if ( .not. exists ) exit - !! last output file - print *, 'delete: ', fn - call remove(fn) - - !! next time - call dateinc(cfg%dtout, ymd,UTsec) -end do - -end subroutine clean_output +if ("@WIN32@" == "1") then + ! cmd.exe expands these even inside double quotes; reject rather than reinterpret. + if (scan(arg, '"%!') /= 0) error stop "launcher: unsupported shell character in argument" + if (len_trim(arg) == 0) then + quoted = '""' + else + quoted = '"' // arg(:len_trim(arg)) // '"' + endif +else + n = len_trim(arg) + if (n == 0) then + quoted = "''" + return + endif + quoted = "'" + do i = 1, n + if (arg(i:i) == "'") then + quoted = quoted // "'" // '"' // "'" // '"' // "'" + else + quoted = quoted // arg(i:i) + endif + enddo + quoted = quoted // "'" +endif +end function quote_argument end module exe_frontend diff --git a/src/utils/gemini3d_run.f90 b/src/utils/gemini3d_run.f90 index 731c68050..e7f27dc11 100644 --- a/src/utils/gemini3d_run.f90 +++ b/src/utils/gemini3d_run.f90 @@ -2,23 +2,21 @@ program gemini3d_run !! for use from terminal/CMake, computes optimal MPI count !! for a particular simulation -use exe_frontend, only : cli_parser, get_Ncpu, clean_output +use exe_frontend, only : cli_parser, get_Ncpu, quote_argument use reader, only: get_simsize3 use autogrid, only : grid_auto, max_mpi implicit none (type, external) integer :: i, lx1, lx2all, lx3all, lid, lid2, lid3, Ncpu -character(:), allocatable :: path, gem_exe, cmd, mpiexec, extra +character(:), allocatable :: path, gem_exe, cmd, mpiexec, numproc_flag, extra logical :: plan -character(1000) :: buf +character(20) :: count -call cli_parser(plan, path, gem_exe, mpiexec, extra) +call cli_parser(plan, path, gem_exe, mpiexec, numproc_flag, extra) Ncpu = get_Ncpu() -if (Ncpu <= 1) error stop 'Ncpu must be > 1. use mpiexec with gemini.bin' - !> setup run call get_simsize3(path // '/inputs/simsize.h5', lx1, lx2all, lx3all) @@ -34,17 +32,15 @@ program gemini3d_run if(.not. plan) then ! we didn't use STOP because that prints "STOP" with Gfortran. -!> remove old output files -call clean_output(path) - !> run gemini.bin if(lid > 1) then - write(buf, '(A1,A,A,I0,1X,A,1X,A,1X,A)') '"',mpiexec, '" -n ', lid, gem_exe, path, extra + write(count, '(I0)') lid + cmd = quote_argument(mpiexec) // ' ' // trim(numproc_flag) // ' ' // trim(count) // ' ' else - write(buf, '(A,1X,A,1X,A)') gem_exe, path, extra + cmd = '' endif -!! quotes are for mpiexec path with spaces -cmd = trim(buf) +cmd = cmd // quote_argument(gem_exe) // ' ' // quote_argument(path) +if(len_trim(extra)>0) cmd = trim(cmd) // ' ' // trim(adjustl(extra)) print *, cmd call execute_command_line(cmd, exitstat=i) diff --git a/src/utils/magcalc.f90 b/src/utils/magcalc.f90 index de3084d22..d38d917cc 100644 --- a/src/utils/magcalc.f90 +++ b/src/utils/magcalc.f90 @@ -459,7 +459,7 @@ Program MagCalc !Bz integrand(:,:,:)=mu0/4/pi*2*(Jx*Ry-Jy*Rx) - integrandend(:,:)=mu0/4/pi*2*(Jxend*Ryend-Jyend*Rxend)/Rcubedend + integrandend(:,:)=mu0/4/pi*2*(Jxend*Ryend-Jyend*Rxend) Bphi(ipoints) = integrate2D(integrand,integrandend) end if end do @@ -589,7 +589,7 @@ subroutine fixJ(J1,J2,J3) J1(:,lx2,:)=J1(:,lx2-2,:) else J1(:,lx2-1,:)=0 - J1(:,lx2-1,:)=0 + J1(:,lx2,:)=0 end if end if if (mpi_cfg%myid2==0) then @@ -760,14 +760,16 @@ function integrate2D(integrand,integrandend) lx1=size(integrand,1); lx2=size(integrand,2); lx3=size(integrand,3); - allocate(integrandavg(lx1-1,max(lx2-1,1),max(lx3-1,1)), & - integrandavgend(lx1-1,max(lx2-1,1)) ) + allocate(integrandavg(lx1-1,lx2,lx3-1), integrandavgend(lx1-1,lx2)) integrandavg(:,:,:)=1/4._wp*( integrand(1:lx1-1,:,1:lx3-1) + integrand(2:lx1,:,1:lx3-1) + & integrand(1:lx1-1,:,2:lx3) + integrand(2:lx1,:,2:lx3) )/Rcubed(2:lx1,:,2:lx3) - integrandavgend(:,:)=1/4._wp*( integrand(1:lx1-1,:,lx3) + integrand(2:lx1,:,lx3) + & - integrandend(1:lx1-1,:) + integrandend(2:lx1,:) )/Rcubedend(2:lx1,:) + integrandavgend = 0 + if (mpi_cfg%myid3/=mpi_cfg%lid3-1) then + integrandavgend(:,:)=1/4._wp*( integrand(1:lx1-1,:,lx3) + integrand(2:lx1,:,lx3) + & + integrandend(1:lx1-1,:) + integrandend(2:lx1,:) )/Rcubedend(2:lx1,:) + end if integrate2D=sum(integrandavg*dV(2:lx1,:,2:lx3))+sum(integrandavgend*dVend(2:lx1,:)) diff --git a/src/utils/magcalc_run.f90 b/src/utils/magcalc_run.f90 index 7f40b94d8..561cce98d 100644 --- a/src/utils/magcalc_run.f90 +++ b/src/utils/magcalc_run.f90 @@ -2,18 +2,17 @@ program magcalc_run !! for use from terminal/CMake, computes optimal MPI count !! for a particular simulation -use exe_frontend, only : cli_parser, get_Ncpu +use exe_frontend, only : cli_parser, get_Ncpu, quote_argument use reader, only: get_simsize3 use autogrid, only : grid_auto, max_mpi implicit none (type, external) integer :: i, lx1, lx2all, lx3all, lid, lid2, lid3, Ncpu -character(:), allocatable :: path, exe, cmd, mpiexec, extra +character(:), allocatable :: path, exe, cmd, mpiexec, numproc_flag, extra logical :: plan -character(1000) :: buf - -call cli_parser(plan, path, exe, mpiexec, extra) +character(20) :: count +call cli_parser(plan, path, exe, mpiexec, numproc_flag, extra) Ncpu = get_Ncpu() @@ -35,12 +34,13 @@ program magcalc_run !> run magcalc.bin if(lid > 1) then - write(buf, '(A1,A,A,I0,1X,A,1X,A,1X,A)') '"',mpiexec, '" -n ', lid, exe, path, extra + write(count, '(I0)') lid + cmd = quote_argument(mpiexec) // ' ' // trim(numproc_flag) // ' ' // trim(count) // ' ' else - write(buf, '(A,1X,A,1X,A)') exe, path, extra + cmd = '' endif -!! quotes are for mpiexec path with spaces -cmd = trim(buf) +cmd = cmd // quote_argument(exe) // ' ' // quote_argument(path) +if(len_trim(extra)>0) cmd = trim(cmd) // ' ' // trim(adjustl(extra)) print *, cmd call execute_command_line(cmd, exitstat=i) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6804873ae..1a20b26e7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,4 @@ +# Audit modification 2026-09-16: make unit-only verification explicit set_property(DIRECTORY PROPERTY LABELS standalone_libraries) if(gemini3d_matlab) @@ -11,24 +12,7 @@ add_compile_options(${gemini3d_flags}) # we test each standalone to mitigate confusing build or runtime errors # if a particular library isn't working. -function(hdf5_dll test) - -if(WIN32) - set(_h5fortran_dll_mdir "PATH=path_list_prepend:${CMAKE_INSTALL_FULL_BINDIR};PATH=path_list_prepend:${PROJECT_BINARY_DIR}") - FetchContent_GetProperties(hdf5_zlib) - if(IS_DIRECTORY "${hdf5_zlib_BINARY_DIR}") - string(APPEND _h5fortran_dll_mdir ";PATH=path_list_prepend:${hdf5_zlib_BINARY_DIR}") - endif() - if(IS_DIRECTORY "${CMAKE_PREFIX_PATH}/bin") - string(APPEND _h5fortran_dll_mdir ";PATH=path_list_prepend:${CMAKE_PREFIX_PATH}/bin") - endif() - if(IS_DIRECTORY "${ZLIB_INCLUDE_DIRS}/../bin") - string(APPEND _h5fortran_dll_mdir ";PATH=path_list_prepend:${ZLIB_INCLUDE_DIRS}/../bin") - endif() - set_property(TEST ${test} PROPERTY ENVIRONMENT_MODIFICATION "${_h5fortran_dll_mdir}") -endif() - -endfunction() +include(${CMAKE_CURRENT_SOURCE_DIR}/hdf5_dll.cmake) # --- HDF5 @@ -137,9 +121,14 @@ add_subdirectory(mpi) add_subdirectory(neutral) add_subdirectory(potential) add_subdirectory(temporal) +add_subdirectory(audit) # self-test simulations -- after all targets for if(TARGET ...) include(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake) -include(${CMAKE_CURRENT_SOURCE_DIR}/sim.cmake) +if(gemini3d_test_simulations) + include(${CMAKE_CURRENT_SOURCE_DIR}/sim.cmake) +else() + message(WARNING "Reference simulations explicitly disabled: this build cannot provide release verification.") +endif() endif() diff --git a/test/audit/CMakeLists.txt b/test/audit/CMakeLists.txt new file mode 100644 index 000000000..4dc5c6d24 --- /dev/null +++ b/test/audit/CMakeLists.txt @@ -0,0 +1,262 @@ +# Audit additions 2026-09-16: targeted native regressions, Apache-2.0. +add_executable(audit_cli cli_test.cpp) +target_include_directories(audit_cli PRIVATE ${PROJECT_SOURCE_DIR}/app ${PROJECT_SOURCE_DIR}/include) +add_test(NAME audit:cli COMMAND audit_cli) +add_executable(audit_sanity sanity_probe.f90) +target_link_libraries(audit_sanity PRIVATE sanity_check errors const h5fortran::h5fortran) +add_executable(audit_config config_probe.f90) +target_link_libraries(audit_config PRIVATE gemini3d_config const timeutils gemini3d_sysinfo ffilesystem::filesystem) +if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel") + set_property(TARGET audit_config PROPERTY LINKER_LANGUAGE Fortran) +else() + set_property(TARGET audit_config PROPERTY LINKER_LANGUAGE CXX) +endif() +function(intel_fortran_main_linker target_name) + if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel") + set_property(TARGET ${target_name} PROPERTY LINKER_LANGUAGE Fortran) + endif() +endfunction() +add_executable(audit_interp interp_test.f90) +target_link_libraries(audit_interp PRIVATE interp const) +add_test(NAME audit:interpolation COMMAND audit_interp) +add_executable(audit_pole pole_probe.f90) +target_link_libraries(audit_pole PRIVATE geomagnetic const) +add_test(NAME audit:unsupported_pole_year COMMAND audit_pole) +set_tests_properties(audit:unsupported_pole_year PROPERTIES WILL_FAIL TRUE) +set_tests_properties(audit:cli audit:interpolation audit:unsupported_pole_year PROPERTIES LABELS "unit;audit") + +add_executable(audit_time time_probe.f90) +target_link_libraries(audit_time PRIVATE timeutils const) +add_executable(audit_coordinates coordinate_test.f90) +target_link_libraries(audit_coordinates PRIVATE geomagnetic const) +add_test(NAME audit:coordinates COMMAND audit_coordinates) +add_executable(audit_cfl cfl_probe.f90) +target_link_libraries(audit_cfl PRIVATE temporal const) +add_test(NAME audit:cfl COMMAND audit_cfl) +foreach(mode IN ITEMS nan metric temperature step) + add_test(NAME audit:cfl_reject_${mode} COMMAND audit_cfl ${mode}) + set_tests_properties(audit:cfl_reject_${mode} PROPERTIES WILL_FAIL TRUE LABELS "unit;audit") +endforeach() +add_executable(audit_cabi cabi_test.cpp cabi_size.f90) +target_include_directories(audit_cabi PRIVATE ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(audit_cabi PRIVATE gemini3d_c gemini3d) +add_test(NAME audit:cabi COMMAND audit_cabi) +add_test(NAME audit:cabi_unsupported_config COMMAND audit_cabi unsupported) +set_tests_properties(audit:cabi_unsupported_config PROPERTIES WILL_FAIL TRUE) +set_tests_properties(audit:coordinates audit:cfl audit:cabi audit:cabi_unsupported_config PROPERTIES LABELS "unit;audit") +if(Python_Interpreter_FOUND) + add_test(NAME audit:calendar COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_calendar.py + --exe $ --output ${CMAKE_CURRENT_BINARY_DIR}/calendar-results.json) + add_test(NAME audit:native_probes COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/run_native_probes.py + --build ${PROJECT_BINARY_DIR} --output ${CMAKE_CURRENT_BINARY_DIR}/native-probes.json) + set_tests_properties(audit:calendar audit:native_probes PROPERTIES TIMEOUT 120 LABELS "unit;audit") + add_test(NAME audit:test_configuration_fixture COMMAND ${Python_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/test_configuration.py + --cmake ${CMAKE_COMMAND} --ctest ${CMAKE_CTEST_COMMAND}) + set_tests_properties(audit:test_configuration_fixture PROPERTIES TIMEOUT 120 LABELS "unit;audit") +endif() + +add_library(audit_driver_fixture driver_fixture.f90) +target_link_libraries(audit_driver_fixture PRIVATE inputdata gemini3d) +add_executable(audit_driver driver_test.f90) +target_link_libraries(audit_driver PRIVATE audit_driver_fixture inputdata meshobj_cart meshobj_dipole timeutils gemini3d) +intel_fortran_main_linker(audit_driver) +add_test(NAME audit:driver_midnight COMMAND audit_driver) +set_tests_properties(audit:driver_midnight PROPERTIES LABELS "unit;audit") + +add_executable(audit_mpi_time mpi_time_test.f90) +target_link_libraries(audit_mpi_time PRIVATE temporal_mpi temporal meshobj_cart mpimod gemini3d MPI::MPI_Fortran) +intel_fortran_main_linker(audit_mpi_time) +foreach(mode IN ITEMS normal worker_cfl) + add_test(NAME audit:mpi_time_${mode} + COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} + $ ${MPIEXEC_POSTFLAGS} ${mode}) + set_tests_properties(audit:mpi_time_${mode} PROPERTIES TIMEOUT 30 PROCESSORS 2 LABELS "unit;audit;mpi") +endforeach() +set_tests_properties(audit:mpi_time_worker_cfl PROPERTIES WILL_FAIL TRUE) + +add_executable(audit_density_floor density_floor_test.f90) +target_link_libraries(audit_density_floor PRIVATE multifluid meshobj_cart grid const gemini3d) +intel_fortran_main_linker(audit_density_floor) +add_test(NAME audit:density_floor COMMAND audit_density_floor) +set_tests_properties(audit:density_floor PROPERTIES LABELS "unit;audit") + +add_executable(qualification_coverage coverage_test.f90) +target_link_libraries(qualification_coverage PRIVATE audit_driver_fixture inputdata gemini3d) +intel_fortran_main_linker(qualification_coverage) +foreach(mode IN ITEMS covered flagged reject nan) + add_test(NAME qualification:coverage_${mode} COMMAND qualification_coverage ${mode}) + set_tests_properties(qualification:coverage_${mode} PROPERTIES LABELS "unit;qualification") +endforeach() +set_tests_properties(qualification:coverage_reject qualification:coverage_nan PROPERTIES WILL_FAIL TRUE) +add_executable(qualification_diffusion diffusion_convergence.f90) +target_link_libraries(qualification_diffusion PRIVATE PDEparabolic const MPI::MPI_Fortran) +add_test(NAME qualification:diffusion_convergence COMMAND qualification_diffusion) +set_tests_properties(qualification:diffusion_convergence PROPERTIES LABELS "unit;qualification" TIMEOUT 60) + +if(Python_Interpreter_FOUND) + add_executable(qualification_igrf_reference ../qualification/igrf_reference.f90 ../qualification/data/igrf14syn.f) + # Isolate the official legacy source from GEMINI's implicit-none policy. + if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + target_compile_options(qualification_igrf_reference PRIVATE -fno-implicit-none -Wno-error=line-truncation) + endif() + # The official routine is retained verbatim, including its legacy labeled DO. + add_test(NAME qualification:igrf14 COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_igrf.py + --exe $ + --output ${CMAKE_CURRENT_BINARY_DIR}/igrf14-results.json) + set_tests_properties(qualification:igrf14 PROPERTIES LABELS "unit;qualification" TIMEOUT 60) +endif() + +if(NUMPY_FOUND AND H5PY_FOUND) + add_test(NAME qualification:budgets COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/qualification/test_budgets.py) + set_tests_properties(qualification:budgets PROPERTIES LABELS "unit;qualification") + add_test(NAME qualification:driver_preflight COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_driver_preflight.py) + set_tests_properties(qualification:driver_preflight PROPERTIES LABELS "unit;qualification") +endif() + +add_executable(qualification_capacitance capacitance_mode.f90) +target_link_libraries(qualification_capacitance PRIVATE potential PDEelliptic meshobj_cart gemini3d) +intel_fortran_main_linker(qualification_capacitance) +foreach(mode IN ITEMS supported 2d field_resolved dirichlet current_bc curved nan) + add_test(NAME qualification:capacitance_${mode} COMMAND qualification_capacitance ${mode}) + set_tests_properties(qualification:capacitance_${mode} PROPERTIES LABELS "unit;qualification") + if(NOT mode STREQUAL "supported") + set_tests_properties(qualification:capacitance_${mode} PROPERTIES WILL_FAIL TRUE) + endif() +endforeach() +add_executable(qualification_gradient gradient_metric.f90) +target_link_libraries(qualification_gradient PRIVATE calculus meshobj_cart const gemini3d) +intel_fortran_main_linker(qualification_gradient) +add_test(NAME qualification:gradient_metric COMMAND qualification_gradient) +set_tests_properties(qualification:gradient_metric PROPERTIES LABELS "unit;qualification") +if(Python_Interpreter_FOUND) + add_test(NAME qualification:gate_integrity COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_gates.py) + set_tests_properties(qualification:gate_integrity PROPERTIES LABELS "unit;qualification") +endif() + +add_executable(qualification_c_consumer c_consumer.c cabi_size.f90) +target_include_directories(qualification_c_consumer PRIVATE ${PROJECT_SOURCE_DIR}/include) +target_compile_features(qualification_c_consumer PRIVATE c_std_17) +target_link_libraries(qualification_c_consumer PRIVATE gemini3d_c gemini3d) +set_property(TARGET qualification_c_consumer PROPERTY LINKER_LANGUAGE CXX) +add_test(NAME qualification:c_consumer COMMAND qualification_c_consumer) +set_tests_properties(qualification:c_consumer PROPERTIES LABELS "unit;qualification") + +add_executable(qualification_atomic ../qualification/atomic_probe.f90) +target_link_libraries(qualification_atomic PRIVATE atomic_file) +add_executable(qualification_transport ../qualification/transport_convergence.f90) +target_link_libraries(qualification_transport PRIVATE advec transport_audit const gemini3d) +intel_fortran_main_linker(qualification_transport) +add_test(NAME qualification:transport_convergence COMMAND qualification_transport) +set_tests_properties(qualification:transport_convergence PROPERTIES LABELS "unit;qualification") +if(Python_Interpreter_FOUND) + add_test(NAME qualification:atomic_checkpoint COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_atomic.py --exe $) + set_tests_properties(qualification:atomic_checkpoint PROPERTIES LABELS "unit;qualification") +endif() +add_executable(qualification_size_alias ../qualification/size_alias.f90) +target_link_libraries(qualification_size_alias PRIVATE reader h5fortran::h5fortran const) +intel_fortran_main_linker(qualification_size_alias) +add_test(NAME qualification:driver_size_alias COMMAND qualification_size_alias ${CMAKE_CURRENT_BINARY_DIR}/size-alias.h5) +set_tests_properties(qualification:driver_size_alias PROPERTIES LABELS "unit;qualification") +if(NUMPY_FOUND AND H5PY_FOUND) + add_test(NAME qualification:research_profile COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/qualification/test_profile.py) + set_tests_properties(qualification:research_profile PROPERTIES LABELS "unit;qualification") +endif() +add_executable(qualification_continuity_floor ../qualification/continuity_floor.f90) +target_link_libraries(qualification_continuity_floor PRIVATE transport_audit multifluid meshobj_cart grid const gemini3d) +intel_fortran_main_linker(qualification_continuity_floor) +if(NUMPY_FOUND AND H5PY_FOUND) + add_test(NAME qualification:continuity_floor COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_continuity_floor.py --exe $) + set_tests_properties(qualification:continuity_floor PROPERTIES LABELS "unit;qualification") +endif() + +add_executable(qualification_etd ../qualification/etd_probe.f90) +target_link_libraries(qualification_etd PRIVATE calculus const gemini3d) +intel_fortran_main_linker(qualification_etd) +if(Python_Interpreter_FOUND) + add_test(NAME qualification:etd_oracle COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_etd.py --exe $ + --output ${CMAKE_CURRENT_BINARY_DIR}/etd-oracle.json) + set_tests_properties(qualification:etd_oracle PROPERTIES LABELS "unit;qualification") + foreach(probe IN ITEMS source_ledger kernel_memory host_capabilities hosted_evidence qualification_dependencies transport_inventory clock_inventory trace_diffusion_stages) + add_test(NAME qualification:${probe} COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_${probe}.py) + set_tests_properties(qualification:${probe} PROPERTIES LABELS "unit;qualification") + endforeach() + set_tests_properties(qualification:qualification_dependencies PROPERTIES ENVIRONMENT "CMAKE=${CMAKE_COMMAND}") + add_test(NAME qualification:model_guard COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_mode_guard.py + --alternate $ --density $) + set_tests_properties(qualification:model_guard PROPERTIES LABELS "unit;qualification") +endif() +if(NUMPY_FOUND AND H5PY_FOUND) + foreach(probe IN ITEMS hdf_policy exchange) + add_test(NAME qualification:${probe} COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_${probe}.py) + set_tests_properties(qualification:${probe} PROPERTIES LABELS "unit;qualification") + endforeach() +endif() +if(NUMPY_FOUND AND SCIPY_FOUND) + foreach(probe IN ITEMS campaign campaign_boundaries) + add_test(NAME qualification:${probe} COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_${probe}.py) + set_tests_properties(qualification:${probe} PROPERTIES LABELS "unit;qualification") + endforeach() +endif() + +add_executable(qualification_energy_operators ../qualification/energy_operator_balance.f90) +target_link_libraries(qualification_energy_operators PRIVATE diffusion PDEparabolic meshobj_cart gemini3d) +intel_fortran_main_linker(qualification_energy_operators) +add_test(NAME qualification:energy_operators COMMAND qualification_energy_operators) +set_tests_properties(qualification:energy_operators PROPERTIES LABELS "unit;qualification") + +add_executable(qualification_temperature_floor ../qualification/temperature_floor.f90) +target_link_libraries(qualification_temperature_floor PRIVATE transport_audit multifluid meshobj_cart grid const gemini3d) +intel_fortran_main_linker(qualification_temperature_floor) +if(Python_Interpreter_FOUND) + add_test(NAME qualification:temperature_floor COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_temperature_floor.py --exe $) + set_tests_properties(qualification:temperature_floor PROPERTIES LABELS "unit;qualification") +endif() +if(Python_Interpreter_FOUND) + add_test(NAME qualification:energy_ledger COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_energy_ledger.py) + set_tests_properties(qualification:energy_ledger PROPERTIES LABELS "unit;qualification") +endif() + +foreach(audit_extension IN ITEMS numerics lifecycle contracts restart installation) + include("${CMAKE_CURRENT_LIST_DIR}/${audit_extension}.cmake" OPTIONAL) +endforeach() + +add_executable(qualification_diffusion_scale ../qualification/diffusion_scale.f90) +target_link_libraries(qualification_diffusion_scale PRIVATE PDEparabolic const MPI::MPI_Fortran) +intel_fortran_main_linker(qualification_diffusion_scale) +add_test(NAME qualification:diffusion_scale COMMAND qualification_diffusion_scale) +set_tests_properties(qualification:diffusion_scale PROPERTIES LABELS "unit;qualification;numerics") + +add_executable(qualification_coulomb_curve ../qualification/coulomb_curve.f90) +target_link_libraries(qualification_coulomb_curve PRIVATE gemini3d) +intel_fortran_main_linker(qualification_coulomb_curve) +add_test(NAME qualification:coulomb_curve COMMAND qualification_coulomb_curve) +set_tests_properties(qualification:coulomb_curve PROPERTIES LABELS "unit;qualification;numerics") + +add_executable(qualification_pair_exchange ../qualification/pair_exchange_probe.f90) +target_link_libraries(qualification_pair_exchange PRIVATE gemini3d) +intel_fortran_main_linker(qualification_pair_exchange) +if(SCIPY_FOUND AND NUMPY_FOUND) + add_test(NAME qualification:pair_exchange COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_pair_exchange.py + --exe $ --output ${CMAKE_CURRENT_BINARY_DIR}/pair-exchange-results.json) + set_tests_properties(qualification:pair_exchange PROPERTIES LABELS "unit;qualification;physics" TIMEOUT 180) + add_test(NAME qualification:midpoint_diffusion COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_midpoint_diffusion.py + --source ${PROJECT_SOURCE_DIR} --build ${PROJECT_BINARY_DIR} + --work ${CMAKE_CURRENT_BINARY_DIR}/midpoint-diffusion) + set_tests_properties(qualification:midpoint_diffusion PROPERTIES LABELS "unit;qualification;physics" TIMEOUT 180 + ENVIRONMENT "FC=${CMAKE_Fortran_COMPILER}") +endif() diff --git a/test/audit/c_consumer.c b/test/audit/c_consumer.c new file mode 100644 index 000000000..12d9a16da --- /dev/null +++ b/test/audit/c_consumer.c @@ -0,0 +1,28 @@ +/* A C17 client, compiled as C rather than C++. Apache-2.0. */ +#include "gemini3d.h" +#include +#include +extern size_t audit_params_size(void); +int main(void) { + if (sizeof(struct params) != audit_params_size()) return 1; + void *cfg = NULL; + gemini_cfg_alloc_C(&cfg); + if (!cfg) return 2; + struct guarded_int { int before, value, after; } bg = {12345, -1, 54321}, pert = bg; + double dtbg = -1, dtpert = -1; + get_config_vars_C(&cfg, &bg.value, &pert.value, &dtbg, &dtpert); + if (bg.before != 12345 || bg.after != 54321 || pert.before != 12345 || pert.after != 54321) return 3; + if (bg.value != 0 || pert.value != 0 || dtbg != 900 || dtpert != 0) return 4; + int ymd[3] = {2024, 2, 28}; + double ut = 86399.5, step = 1.0; + dateinc_C(&step, ymd, &ut); + if (ymd[0] != 2024 || ymd[1] != 2 || ymd[2] != 29 || ut != 0.5) return 5; + int species = 0; + get_species_size_C(&species); + if (species != 7) return 6; + gemini_cfg_dealloc_C(&cfg); + if (cfg) return 7; + gemini_cfg_dealloc_C(&cfg); + puts("C17 client layout, integer flags, calendar and lifetime passed"); + return 0; +} diff --git a/test/audit/cabi_size.f90 b/test/audit/cabi_size.f90 new file mode 100644 index 000000000..a90deacd1 --- /dev/null +++ b/test/audit/cabi_size.f90 @@ -0,0 +1,8 @@ +function audit_params_size() bind(C) result(n) +use, intrinsic :: iso_c_binding, only: c_size_t,c_sizeof +use gemini3d, only: c_params +implicit none +type(c_params) :: p +integer(c_size_t) :: n +n=c_sizeof(p) +end function diff --git a/test/audit/cabi_test.cpp b/test/audit/cabi_test.cpp new file mode 100644 index 000000000..8a1053620 --- /dev/null +++ b/test/audit/cabi_test.cpp @@ -0,0 +1,29 @@ +#include "gemini3d.h" +#include +#include +#include +extern "C" std::size_t audit_params_size(); +int main(int argc,char**) { + static_assert(std::is_standard_layout::value); + if(audit_params_size()!=sizeof(params)) return 1; + void *cfg=nullptr; + if(argc>1) { + params p{}; + gemini_cfg_alloc_C(&cfg); + read_config_in_C(&p,&cfg); // Unsupported path must terminate with an explicit error. + return 0; + } + for(int i=0;i<100;++i) { + gemini_cfg_alloc_C(&cfg); + struct Guard {int left;int value;int right;}; + Guard a{0x12ab34cd,-1,0x34cd12ab},b=a; + double dtbg=-1,dt=-1; + get_config_vars_C(&cfg,&a.value,&b.value,&dtbg,&dt); + if(a.left!=0x12ab34cd||a.right!=0x34cd12ab||b.left!=a.left||b.right!=a.right) return 2; + if(a.value!=0||b.value!=0||dtbg!=900||dt!=0) return 3; + gemini_cfg_dealloc_C(&cfg); + if(cfg!=nullptr)return 4; + gemini_cfg_dealloc_C(&cfg); // Idempotent null deallocation. + } + std::cout << "C/Fortran ABI and handle checks passed\n"; +} diff --git a/test/audit/capacitance_mode.f90 b/test/audit/capacitance_mode.f90 new file mode 100644 index 000000000..20b4fc35e --- /dev/null +++ b/test/audit/capacitance_mode.f90 @@ -0,0 +1,31 @@ +program qualification_capacitance_mode +use phys_consts, only: wp +use gemini3d_config, only: gemini_cfg +use meshobj_cart, only: cartmesh +use potential_comm, only: validate_capacitance_mode +use, intrinsic :: ieee_arithmetic, only: ieee_value,ieee_quiet_nan +implicit none +type(gemini_cfg) :: cfg +type(cartmesh) :: x +character(20) :: mode +integer :: boundary +call get_command_argument(1,mode) +cfg%flagcap=1;cfg%potsolve=1;boundary=0 +x%lx1=3;x%lx2=3;x%lx3=3;x%lx2all=3;x%lx3all=3 +allocate(x%h1(3,3,3),x%h2(3,3,3),x%h3(3,3,3)) +x%h1=1;x%h2=1;x%h3=1 +select case(trim(mode)) +case('supported') +case('2d');x%lx2all=1 +case('field_resolved');cfg%potsolve=3 +case('dirichlet');boundary=1 +case('current_bc');boundary=2 +case('curved');x%h2=1.2_wp +case('nan');x%h3(1,1,1)=ieee_value(1._wp,ieee_quiet_nan) +case default;error stop 'Unknown test mode' +end select +call validate_capacitance_mode(cfg,x,boundary) +deallocate(x%h1,x%h2,x%h3) +! Negative modes return success if a regression incorrectly permits them; +! CTest WILL_FAIL therefore reports failure rather than a false pass. +end program diff --git a/test/audit/cartmesh_metrics.f90 b/test/audit/cartmesh_metrics.f90 new file mode 100644 index 000000000..f8754932d --- /dev/null +++ b/test/audit/cartmesh_metrics.f90 @@ -0,0 +1,57 @@ +module audit_checked_cartmesh +use phys_consts, only: wp,Re +use meshobj_cart, only: cartmesh +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +implicit none +type, extends(cartmesh) :: checked_cartmesh +contains + procedure, nopass :: calc_h1=>checked_metric + procedure, nopass :: calc_h2=>checked_metric + procedure, nopass :: calc_h3=>checked_metric +end type +contains +function checked_metric(coord1,coord2,coord3) result(hval) + real(wp), pointer, intent(in) :: coord1(:,:,:),coord2(:,:,:),coord3(:,:,:) + real(wp) :: hval(lbound(coord1,1):ubound(coord1,1),lbound(coord1,2):ubound(coord1,2), & + lbound(coord1,3):ubound(coord1,3)) + if (.not.associated(coord1) .or. .not.associated(coord2) .or. .not.associated(coord3)) & + error stop 'Cartesian metric received deallocated coordinates' + if (any(lbound(coord1)/=-1)) error stop 'Cartesian coordinate ghost bounds lost' + if (.not.all(ieee_is_finite(coord1)) .or. .not.all(ieee_is_finite(coord2)) .or. & + .not.all(ieee_is_finite(coord3))) error stop 'Nonfinite Cartesian coordinates' + if (any(coord11e-12_wp)error stop 'CFL advection oracle mismatch' +v2(2,1,1,7)=20 +call cflcalc(ts,v1,v2,v3,dl1,dl2,dl3,dt,cfl) +if(cfl<=1)error stop 'updated drift did not invalidate old step' +print *,'CFL checks passed' +end program diff --git a/test/audit/check_diffusion_failure.py b/test/audit/check_diffusion_failure.py new file mode 100644 index 000000000..84086268a --- /dev/null +++ b/test/audit/check_diffusion_failure.py @@ -0,0 +1,11 @@ +"""Require a controlled, stage-specific LAPACK failure, not a crash or timeout.""" +import subprocess +import sys + +stage = {"euler": "backEuler1D", "tr": "TRBDF21D TR stage", "bdf2": "TRBDF21D BDF2 stage"}[sys.argv[2]] +result = subprocess.run(sys.argv[1:], capture_output=True, text=True, timeout=20) +output = result.stdout + result.stderr +assert result.returncode > 0, (result.returncode, output) +assert f"PDEparabolic: {stage} gbsv INFO=2" in output, output +assert "PDEparabolic: singular diffusion matrix" in output, output +print(f"Singular {stage} rejected with LAPACK INFO=2") diff --git a/test/audit/cli_test.cpp b/test/audit/cli_test.cpp new file mode 100644 index 000000000..57d133a81 --- /dev/null +++ b/test/audit/cli_test.cpp @@ -0,0 +1,36 @@ +// Audit addition 2026-09-16. Apache-2.0. +#include "cli_utils.h" +#include +#include +#include +#include +#include +// Remains active in Release builds, unlike assert(). +void require(bool condition) { if (!condition) throw std::runtime_error("CLI regression"); } +bool parse(std::vector args, int& x, int& y) { + std::vector argv; + for (auto& s : args) argv.push_back(s.data()); + params p{}; bool help=false; std::string error; + return gemini_cli::parse_options(static_cast(argv.size()),argv.data(),p,x,y,help,error); +} +int main() { + static_assert(std::is_same_v); + int x=-1,y=-1; + require(parse({"gemini",".","-manual_grid","2","3","-dryrun"},x,y)); + require(x==2 && y==3); + for (auto bad : {"0","-1","2x","2147483648","","1.5"}) + require(!parse({"gemini",".","-manual_grid",bad,"2"},x,y)); + require(!parse({"gemini",".","-manual_grid"},x,y)); + require(!parse({"gemini",".","-manual_grid","2"},x,y)); + require(!parse({"gemini",".","-unknown"},x,y)); + char out[1000]; require(gemini_cli::copy_outdir(std::string(999,'x'),out,sizeof(out))); + require(out[999]=='\0'); require(!gemini_cli::copy_outdir(std::string(1000,'x'),out,sizeof(out))); + const auto cells=gemini_cli::cell_count(500,500,500); + require(gemini_cli::array_bytes(cells,35)==static_cast(504)*504*504*35*8); + bool caught=false; + try { (void)gemini_cli::cell_count(INT_MAX,INT_MAX,INT_MAX); } catch(const std::overflow_error&) {caught=true;} + require(caught); caught=false; + try { (void)gemini_cli::cell_count(0,2,2); } catch(const std::invalid_argument&) {caught=true;} + require(caught); + std::cout << "PASS CLI, ABI declaration and allocation boundaries\n"; +} diff --git a/test/audit/config_probe.f90 b/test/audit/config_probe.f90 new file mode 100644 index 000000000..0a2906bea --- /dev/null +++ b/test/audit/config_probe.f90 @@ -0,0 +1,17 @@ +! Audit addition 2026-09-16. Apache-2.0. +program audit_config +use phys_consts, only: wp,mindens +use gemini3d_config, only: gemini_cfg,read_configfile +implicit none +type(gemini_cfg) :: cfg +character(2048) :: file +integer :: i +cfg%outdir='.' +do i=1,command_argument_count() + call get_command_argument(i,file) + cfg%infile=trim(file) + call read_configfile(cfg) + print '(a,1x,i0,1x,es24.15e3,1x,i0,1x,i0,1x,es24.15e3)', & + "AUDIT_CONFIG", cfg%msis_version, cfg%dtneuBG, cfg%flagevibcool, cfg%flagperiodic, mindens +enddo +end program diff --git a/test/audit/configuration/CMakeLists.txt b/test/audit/configuration/CMakeLists.txt new file mode 100644 index 000000000..fc3ee73f8 --- /dev/null +++ b/test/audit/configuration/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.26) +project(test_configuration LANGUAGES NONE) +enable_testing() +include(FetchContent) + +get_filename_component(gemini_source "${CMAKE_CURRENT_SOURCE_DIR}/../../.." ABSOLUTE) +include("${gemini_source}/test/mpi_launcher.cmake") +include("${gemini_source}/test/hdf5_dll.cmake") +include("${gemini_source}/test/config.cmake") + +set(WIN32 ${test_windows}) +set(CMAKE_INSTALL_FULL_BINDIR "${CMAKE_CURRENT_BINARY_DIR}/local/bin") +set(MPIEXEC_EXECUTABLE "${CMAKE_COMMAND}") +set(MPIEXEC_NUMPROC_FLAG "-n") +set(MPIEXEC_MAX_NUMPROCS 2) +set(gemini3d_test_run_root "${CMAKE_CURRENT_BINARY_DIR}/native runs") +set(gemini3d_glow ON) +set(gemini3d_msis2 ON) + +# Imported placeholders exercise the real CTest registration without native libraries. +foreach(target IN ITEMS gemini.bin gemini_c.bin gemini3d.run) + add_executable(${target} IMPORTED) + set_property(TARGET ${target} PROPERTY IMPORTED_LOCATION "${CMAKE_COMMAND}") +endforeach() + +function(compare_gemini_output name outdir refdir) +endfunction() + +include("${gemini_source}/test/sim.cmake") diff --git a/test/audit/contracts.cmake b/test/audit/contracts.cmake new file mode 100644 index 000000000..ed83f8a54 --- /dev/null +++ b/test/audit/contracts.cmake @@ -0,0 +1,49 @@ +add_executable(audit_partition partition_contract.f90) +target_link_libraries(audit_partition PRIVATE autogrid) +intel_fortran_main_linker(audit_partition) +add_test(NAME audit:partition_contract COMMAND audit_partition) +add_test(NAME audit:partition_cmake COMMAND ${CMAKE_COMMAND} + -Dsource=${PROJECT_SOURCE_DIR} -P ${CMAKE_CURRENT_LIST_DIR}/partition_contract.cmake) +set_tests_properties(audit:partition_contract audit:partition_cmake PROPERTIES LABELS "unit;audit" TIMEOUT 120) + +add_executable(audit_neutral_abi neutral_abi.c neutral_abi_fixture.f90) +target_include_directories(audit_neutral_abi PRIVATE ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(audit_neutral_abi PRIVATE gemini3d_mpi_c gemini3d_c gemini3d_mpi gemini3d MUMPS::MUMPS) +set_property(TARGET audit_neutral_abi PROPERTY LINKER_LANGUAGE CXX) +foreach(version IN ITEMS 0 21) + if(version EQUAL 21 AND NOT gemini3d_msis2) + continue() + endif() + add_test(NAME audit:neutral_abi_msis${version} COMMAND audit_neutral_abi ${version}) + set_tests_properties(audit:neutral_abi_msis${version} PROPERTIES + LABELS "unit;audit" WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) +endforeach() + +# Make every public library declaration a linker dependency, not only the main program's subset. +file(STRINGS ${PROJECT_SOURCE_DIR}/include/gemini3d.h declarations REGEX "^extern void ") +set(link_source "#include \"gemini3d.h\"\n") +foreach(declaration IN LISTS declarations) + string(REGEX REPLACE "^extern void ([A-Za-z0-9_]+).*" "\\1" symbol "${declaration}") + string(APPEND link_source "decltype(&${symbol}) volatile link_${symbol} = &${symbol};\n") +endforeach() +string(APPEND link_source "int main() { return 0; }\n") +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/public_symbols.cpp CONTENT "${link_source}") +add_executable(audit_public_symbols ${CMAKE_CURRENT_BINARY_DIR}/public_symbols.cpp) +target_include_directories(audit_public_symbols PRIVATE ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(audit_public_symbols PRIVATE gemini3d_mpi_c gemini3d_c gemini3d_mpi gemini3d MUMPS::MUMPS) +add_test(NAME audit:public_symbols COMMAND audit_public_symbols) +set_tests_properties(audit:public_symbols PROPERTIES LABELS "unit;audit") + +if(Python_Interpreter_FOUND) + add_test(NAME audit:filename_cadence COMMAND ${Python_EXECUTABLE} + ${CMAKE_CURRENT_LIST_DIR}/test_filename_cadence.py --exe $ + --work ${CMAKE_CURRENT_BINARY_DIR}/cadence-contract) + set_tests_properties(audit:filename_cadence PROPERTIES LABELS "unit;audit" TIMEOUT 60) +endif() +if(NUMPY_FOUND AND H5PY_FOUND) + add_test(NAME audit:launcher_preserves_outputs COMMAND ${Python_EXECUTABLE} + ${CMAKE_CURRENT_LIST_DIR}/test_launcher_contract.py --exe $ + --work ${CMAKE_CURRENT_BINARY_DIR}/launcher-contract + --numproc-flag=${MPIEXEC_NUMPROC_FLAG}) + set_tests_properties(audit:launcher_preserves_outputs PROPERTIES LABELS "unit;audit" TIMEOUT 60) +endif() diff --git a/test/audit/coordinate_test.f90 b/test/audit/coordinate_test.f90 new file mode 100644 index 000000000..550ddce73 --- /dev/null +++ b/test/audit/coordinate_test.f90 @@ -0,0 +1,30 @@ +program audit_coordinates +use phys_consts, only: wp,pi +use geomagnetic, only: geog2geomag,geomag2geog,rotgg2gm,rotgm2gg,ECEFspher2ENU +implicit none +real(wp) :: theta1,theta2,phi1,phi2,lon,lat,ident(3,3) +real(wp) :: alt(2,2,2),theta(2,2,2),phi(2,2,2),x(2,2,2),y(2,2,2),z(2,2,2) +real(wp) :: xsmall(2,1,2),ysmall(2,1,2),zsmall(2,1,2) +integer :: i,j +! Equivalent longitudes in three conventions must produce the same result. +do i=-720,720,15 + call geog2geomag(real(i,wp),65._wp,phi1,theta1) + call geog2geomag(modulo(real(i,wp),360._wp),65._wp,phi2,theta2) + if(abs(phi1-phi2)>1e-12_wp.or.abs(theta1-theta2)>1e-12_wp)error stop 'longitude equivalence' + call geomag2geog(phi1,theta1,lon,lat) + if(abs(lat-65._wp)>1e-10_wp.or.abs(modulo(lon-real(i,wp)+180,360._wp)-180)>1e-10_wp) & + error stop 'coordinate round trip' +enddo +ident=matmul(rotgg2gm(),rotgm2gg()) +do i=1,3 + do j=1,3 + if(abs(ident(i,j)-merge(1._wp,0._wp,i==j))>1e-14_wp)error stop 'rotation inverse' + enddo +enddo +! A 3D call must not leave SAVE state that changes subsequent collapsed-dimension calls. +alt=100000;theta=pi/3;phi=0.2_wp +call ECEFspher2ENU(alt,theta,phi,pi/3,0._wp,x,y,z) +call ECEFspher2ENU(alt(:,1:1,:),theta(:,1:1,:),phi(:,1:1,:),pi/3,0._wp,xsmall,ysmall,zsmall) +if(maxval(abs(xsmall))>1e-8_wp)error stop '3D state leaked into 2D transform' +print *,'coordinate checks passed' +end program diff --git a/test/audit/coverage_test.f90 b/test/audit/coverage_test.f90 new file mode 100644 index 000000000..a86a7b504 --- /dev/null +++ b/test/audit/coverage_test.f90 @@ -0,0 +1,34 @@ +program qualification_coverage +use audit_driver_fixture +use interpolation, only: coverage_mask,interp1 +use, intrinsic :: ieee_arithmetic, only: ieee_value,ieee_quiet_nan +implicit none +type(linear_driver) :: data +character(20) :: mode +real(wp) :: result(4),values(2) +call get_command_argument(1,mode) +data%l1Dax1=1; data%l1Dax2=0; data%l1Dax3=0 +data%l2Dax12=0; data%l2Dax13=0; data%l2Dax23=0; data%l3D=0 +allocate(data%coord1(2),data%coord1iax1(4)) +data%coord1=[0._wp,1._wp] +data%coord1iax1=[0._wp,0.5_wp,1._wp,1._wp] +values=0 ! physical zero must be distinguishable from absent coverage +if (trim(mode)=='nan') then + values(1)=ieee_value(0._wp,ieee_quiet_nan) + result=interp1(data%coord1,values,data%coord1iax1) + stop ! acceptance here must make the WILL_FAIL test fail +endif +if (trim(mode)=='flagged'.or.trim(mode)=='reject') data%coord1iax1(4)=2._wp +data%allow_missing_spatial=trim(mode)=='flagged' +call data%validate_spatial_coverage() +if (trim(mode)=='reject') stop +if (trim(mode)=='flagged') then + if (data%spatial_missing_count/=1.or.data%coverage(1)%valid(4)) error stop 'missing flag lost' + if (.not.all(data%coverage(1)%valid(1:3))) error stop 'physical zero marked missing' +else + if (data%spatial_missing_count/=0) error stop 'covered sites marked missing' +endif +if (.not.all(coverage_mask([5._wp],[-100._wp,100._wp]))) error stop 'singleton invariant axis' +deallocate(data%coord1,data%coord1iax1) +print *, 'Coverage policy passed: ',trim(mode) +end program diff --git a/test/audit/density_floor_test.f90 b/test/audit/density_floor_test.f90 new file mode 100644 index 000000000..a06c9cc3d --- /dev/null +++ b/test/audit/density_floor_test.f90 @@ -0,0 +1,26 @@ +program audit_density_floor +use phys_consts, only: wp,lsp,mindens,mindensnull,mindensdiv +use multifluid, only: clean_param +use meshobj_cart, only: cartmesh +use grid, only: set_total_grid_sizes,set_subgrid_sizes +implicit none +real(wp)::ns(-1:4,-1:3,-1:3,lsp),floor_value +real(wp),parameter::floors(3)=[0.01_wp,1000._wp,5000._wp] +type(cartmesh)::x +integer::i +call set_total_grid_sizes(2,1,1) +call set_subgrid_sizes(1,1) +x%lnull=1 +allocate(x%inull(1,3));x%inull(1,:)=[2,1,1] +do i=1,size(floors) + floor_value=floors(i);mindens=floor_value + ns=0 + call clean_param(x,1,ns) + if(any(ns(1,1,1,1:6)/=floor_value))error stop 'configured ion floor was overridden' + if(abs(ns(1,1,1,7)-6*floor_value)>1e-12_wp)error stop 'physical-cell charge neutrality' + if(ns(2,1,1,1)/=mindensnull*1e-2_wp)error stop 'null-cell fill changed' + if(any(ns(-1,:,:,:)/=mindensdiv))error stop 'ghost fill changed' +enddo +deallocate(x%inull) +print *, 'Configured density floor and ESF opt-in passed' +end program diff --git a/test/audit/diffusion_convergence.f90 b/test/audit/diffusion_convergence.f90 new file mode 100644 index 000000000..10cc21537 --- /dev/null +++ b/test/audit/diffusion_convergence.f90 @@ -0,0 +1,73 @@ +program qualification_diffusion +use phys_consts, only: wp,pi +use PDEparabolic, only: backEuler1D,TRBDF21D +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +implicit none +real(wp) :: spatial(3),temporal(3,2),order,err +integer :: level,method +! Thresholds are declared from method order before running: spatial >=1.8, +! backward Euler time >=0.9, TRBDF2 time >=1.8. These qualify this operator. +do level=1,3 + call solve(2**(level+3)+1,1000,0.001_wp,2,.true.,spatial(level)) + do method=1,2 + call solve(9,2**(level+3),1._wp,method,.false.,temporal(level,method)) + enddo +enddo +print '(a,3es24.16)', 'SPACE_ERRORS ',spatial +do level=1,2 + order=log(spatial(level)/spatial(level+1))/log(2._wp) + if (.not.ieee_is_finite(order).or.order<1.8_wp) error stop 'diffusion spatial order' +enddo +do method=1,2 + print '(a,i0,3es24.16)', 'TIME_ERRORS ',method,temporal(:,method) + do level=1,2 + order=log(temporal(level,method)/temporal(level+1,method))/log(2._wp) + if (.not.ieee_is_finite(order)) error stop 'nonfinite temporal convergence' + if (method==1.and.order<0.9_wp) error stop 'backward Euler temporal order' + if (method==2.and.order<1.8_wp) error stop 'TRBDF2 temporal order' + enddo +enddo +! Manufactured constant with a volumetric source and matching boundary values. +call source_balance(err) +if(err>1e-11_wp)error stop 'source and boundary balance' +print '(a,es24.16)', 'SOURCE_BALANCE_ERROR ',err +contains +subroutine solve(n,nt,total,method,spatial_case,error) +integer,intent(in)::n,nt,method +real(wp),intent(in)::total +logical,intent(in)::spatial_case +real(wp),intent(out)::error +real(wp)::u(n),xx(n),a(n),b(n),c(n),d(n),e(n),dx(0:n+2),dxi(n),exact(n),dt,bc +integer::i,it +xx=[(real(i-1,wp)/real(n-1,wp),i=1,n)] +dx=1._wp/(n-1);dxi=dx(1);dt=total/nt +b=0;c=1;e=0 +if(spatial_case)then + u=sin(2*pi*xx);a=0;d=1;exact=exp(-4*pi*pi*total)*u +else + u=1;a=-1;d=0;exact=exp(-total) +endif +do it=1,nt + bc=0 + if(.not.spatial_case)bc=exp(-it*dt) + if(method==1)then + u=backEuler1D(u,a,b,c,d,e,bc,bc,dt,[0,0],dx,dxi) + else + u=TRBDF21D(u,a,b,c,d,e,bc,bc,dt,[0,0],dx,dxi) + endif +enddo +error=sqrt(sum((u-exact)**2)/sum(exact**2)) +if(.not.ieee_is_finite(error).or.error<=0)error stop 'invalid refinement error' +end subroutine +subroutine source_balance(error) +real(wp),intent(out)::error +real(wp)::u(9),z(9),one(9),dx(0:11),dxi(9),e(9),dt +integer::i +u=2;z=0;one=1;dx=0.125_wp;dxi=dx(1);e=3;dt=0.01_wp +do i=1,100 + u=TRBDF21D(u,z,z,one,one,e,2+3*i*dt,2+3*i*dt,dt,[0,0],dx,dxi, & + Tsmin_mid=2+3*(i-0.5_wp)*dt,Tsmax_mid=2+3*(i-0.5_wp)*dt) +enddo +error=maxval(abs(u-5._wp)) +end subroutine +end program diff --git a/test/audit/diffusion_singular.f90 b/test/audit/diffusion_singular.f90 new file mode 100644 index 000000000..8d38abe8c --- /dev/null +++ b/test/audit/diffusion_singular.f90 @@ -0,0 +1,24 @@ +program audit_diffusion_singular +use phys_consts, only: wp +use PDEparabolic, only: backEuler1D,TRBDF21D +implicit none +integer, parameter :: n=5 +real(wp) :: u(n),a(n),zero(n),one(n),dx(0:n+2),dxi(n),v(n) +character(16) :: mode +call get_command_argument(1,mode) +u=1; zero=0; one=1; dx=1; dxi=1 +select case (trim(mode)) +case ('euler') + a=1 + v=backEuler1D(u,a,zero,zero,one,zero,1._wp,1._wp,1._wp,[0,0],dx,dxi) +case ('tr') + a=4 + v=TRBDF21D(u,a,zero,zero,one,zero,1._wp,1._wp,1._wp,[0,0],dx,dxi) +case ('bdf2') + a=3 + v=TRBDF21D(u,a,zero,zero,one,zero,1._wp,1._wp,1._wp,[0,0],dx,dxi) +case default + error stop 'Unknown singular diffusion case' +end select +print *, 'Unexpected success of singular solve: ',v +end program diff --git a/test/audit/driver_fixture.f90 b/test/audit/driver_fixture.f90 new file mode 100644 index 000000000..44ad9aa1e --- /dev/null +++ b/test/audit/driver_fixture.f90 @@ -0,0 +1,61 @@ +module audit_driver_fixture +use inputdataobj, only: inputdata +use phys_consts, only: wp +use meshobj, only: curvmesh +use gemini3d_config, only: gemini_cfg +use timeutils, only: shift_datetime,elapsed_seconds +implicit none +type, extends(inputdata) :: linear_driver + integer :: origin(3),loads=0 + real(wp) :: origin_ut,value +contains + procedure :: init=>fixture_init + procedure :: set_coordsi=>fixture_coords + procedure :: load_size=>fixture_noop + procedure :: load_grid=>fixture_noop + procedure :: load_data=>fixture_load + procedure :: spaceinterp=>fixture_space +end type +contains +subroutine fixture_init(self,cfg,sourcedir,x,dtmodel,dtdata,ymd,UTsec) + class(linear_driver),intent(inout)::self + type(gemini_cfg),intent(in)::cfg + character(*),intent(in)::sourcedir + class(curvmesh),intent(in)::x + real(wp),intent(in)::dtmodel,dtdata,UTsec + integer,intent(in)::ymd(3) + self%origin=cfg%ymd0;self%origin_ut=cfg%UTsec0 + self%l0D=1;self%l1Dax1=0;self%l1Dax2=0;self%l1Dax3=0 + self%l2Dax12=0;self%l2Dax13=0;self%l2Dax23=0;self%l3D=0 + self%lc1i=1;self%lc2i=1;self%lc3i=1 + allocate(self%data0Di(1,2),self%data0Dinow(1)) + self%data0Di=0;self%flagalloc=.true.;self%flagdoinput=.true. + call self%set_cadence(dtdata) + call self%set_source(sourcedir) + call self%prime_data(cfg,x,dtmodel,ymd,UTsec) +end subroutine +subroutine fixture_coords(self,cfg,x) + class(linear_driver),intent(inout)::self + type(gemini_cfg),intent(in)::cfg + class(curvmesh),intent(in)::x + self%flagcoordsi=.true. +end subroutine +subroutine fixture_noop(self) + class(linear_driver),intent(inout)::self +end subroutine +subroutine fixture_load(self,t,dtmodel,ymdtmp,UTsectmp) + class(linear_driver),intent(inout)::self + real(wp),intent(in)::t,dtmodel + integer,intent(inout)::ymdtmp(3) + real(wp),intent(inout)::UTsectmp + ymdtmp=self%ymdref(:,2);UTsectmp=self%UTsecref(2) + call shift_datetime(self%dt,ymdtmp,UTsectmp) + self%value=5+2*elapsed_seconds(self%origin,self%origin_ut,ymdtmp,UTsectmp) + self%loads=self%loads+1 +end subroutine +subroutine fixture_space(self) + class(linear_driver),intent(inout)::self + self%data0Di(:,1)=self%data0Di(:,2) + self%data0Di(:,2)=self%value +end subroutine +end module diff --git a/test/audit/driver_test.f90 b/test/audit/driver_test.f90 new file mode 100644 index 000000000..3d719600a --- /dev/null +++ b/test/audit/driver_test.f90 @@ -0,0 +1,24 @@ + +program audit_driver +use audit_driver_fixture +use meshobj_cart, only: cartmesh +implicit none +type(linear_driver)::driver +type(gemini_cfg)::cfg +type(cartmesh)::x +cfg%ymd0=[2019,12,31];cfg%UTsec0=86370 +! Restart two minutes after the origin, across the year boundary. +call driver%init(cfg,'synthetic',x,2._wp,60._wp,[2020,1,1],90._wp) +if(any(abs(driver%tref-[120._wp,180._wp])>1e-12_wp))error stop 'midnight priming interval' +if(driver%loads/=2)error stop 'priming must load exactly two frames' +call driver%update(cfg,2._wp,120._wp,x,[2020,1,1],90._wp) +if(abs(driver%data0Dinow(1)-247._wp)>1e-12_wp)error stop 'linear driver interpolation' +! Skip multiple driver cadences; catch up before interpolating. +call driver%update(cfg,20._wp,370._wp,x,[2020,1,1],340._wp) +if(abs(driver%data0Dinow(1)-765._wp)>1e-12_wp)error stop 'multiple cadence catch-up' +if(any(driver%ymdref(:,2)/=[2020,1,1]))error stop 'driver date mismatch' +if(abs(driver%UTsecref(2)-390._wp)>1e-12_wp)error stop 'driver clock mismatch' +deallocate(driver%data0Di,driver%data0Dinow) +driver%flagalloc=.false. +print *, 'Cross-midnight driver priming and catch-up passed' +end program diff --git a/test/audit/gradient_metric.f90 b/test/audit/gradient_metric.f90 new file mode 100644 index 000000000..e3a25eafd --- /dev/null +++ b/test/audit/gradient_metric.f90 @@ -0,0 +1,24 @@ +program qualification_gradient_metric +use phys_consts, only: wp +use meshobj_cart, only: cartmesh +use calculus, only: grad3D2 +implicit none +type(cartmesh) :: x +real(wp) :: f(2,4,3),g(2,4,3),expected(2,4,3) +integer :: j,k +x%lx1=2;x%lx2=4;x%lx3=3;x%lx2all=4;x%lx3all=3 +allocate(x%h2(2,4,3),x%dx2(4));x%dx2=2._wp +! Manufactured scalar linear in coordinate x2, with a metric that varies +! across x3. Its physical derivative is 1/h2 at every boundary and interior. +do k=1,3 + x%h2(:,:,k)=real(k,wp) + do j=1,4 + f(:,j,k)=2._wp*real(j,wp) + enddo +enddo +expected=1._wp/x%h2 +g=grad3D2(f,x,1,2,1,4,1,3) +if(maxval(abs(g-expected))>1e-14_wp) error stop 'Incorrect metric at x2 boundary' +deallocate(x%h2,x%dx2) +print *, 'Manufactured curved-metric gradient passed' +end program diff --git a/test/audit/halo_end.f90 b/test/audit/halo_end.f90 new file mode 100644 index 000000000..6806b40b7 --- /dev/null +++ b/test/audit/halo_end.f90 @@ -0,0 +1,61 @@ +program audit_halo_end +use mpi_f08, only: MPI_Init,MPI_Finalize,MPI_Barrier,MPI_COMM_WORLD,MPI_Wtime +use mpimod, only: mpisetup,mpi_manualgrid,mpi_cfg,halo_end +use phys_consts, only: wp +implicit none +integer :: p2,p3,iteration +call MPI_Init() +call mpisetup() +do p2=1,mpi_cfg%lid + if (mod(mpi_cfg%lid,p2)/=0) cycle + p3=mpi_cfg%lid/p2 + call mpi_manualgrid(4*p2,4*p3,p2,p3) + do iteration=1,3 + call check_halo(1,iteration) + call check_halo(32768,iteration) + enddo +enddo +call MPI_Finalize() +print *, 'Halo end, top and corner exchanges passed' +contains +subroutine check_halo(n1,iteration) + integer, intent(in) :: n1,iteration + integer, parameter :: n2=3,n3=4 + real(wp) :: param(n1,n2,n3),pend(n1,n2),ptop(n1,n3),corner(n1),expected(n1),start + integer :: i,j,k,g2,g3 + do k=1,n3 + do j=1,n2 + g2=mpi_cfg%myid2*n2+j + g3=mpi_cfg%myid3*n3+k + param(:,j,k)=[(value(i,g2,g3,iteration),i=1,n1)] + enddo + enddo + pend=-1; ptop=-1; corner=-1 + call MPI_Barrier(MPI_COMM_WORLD) + if (mpi_cfg%myid==mpi_cfg%lid-1) then + start=MPI_Wtime() + do while (MPI_Wtime()-start<0.01_wp) + enddo + endif + ! The long vector exceeds typical eager limits, exercising receive completion. + call halo_end(param,pend,ptop,corner,450) + do j=1,n2 + expected=0 + if (mpi_cfg%myid3=2) then + call initialize(driver) + end if + if (state==3) then + call driver%dissociate_pointers() + call assert_released(driver) + call driver%dissociate_pointers() + end if + deallocate(driver) + end do + end do + + do kind=1,2 + if (kind==1) then + allocate(cartmesh::mesh) + else + allocate(dipolemesh::mesh) + end if + call mesh%set_coords(coords,coords,coords,coords,coords) + call mesh%init() + call mesh%init_storage_root() + if (mod(iteration,2)==0) then + handle=c_null_ptr; xtype=kind + call gemini_grid_dealloc(mesh,xtype,handle) + if (associated(mesh) .or. c_associated(handle)) error stop 'mesh handle not cleared' + else + deallocate(mesh) + end if + end do +end do +print *, '800 input object and 40 mesh lifecycles passed' + +contains + +subroutine initialize(self) + class(inputdata), intent(inout) :: self + integer :: i + + allocate(self%lc1,self%lc2,self%lc3) + self%lc1=2; self%lc2=2; self%lc3=2 + self%lc1i=2; self%lc2i=2; self%lc3i=2 + self%l0D=1; self%l1Dax1=1; self%l1Dax2=1; self%l1Dax3=1 + self%l2Dax23=2; self%l2Dax12=1; self%l2Dax13=1; self%l3D=9 + self%flagsizes=.true.; self%flagdatasize=.true. + select type (self) + class is (neutraldata3D_fclaw) + ! Coupled objects allocate only current-time data in their override. + class is (neutraldata3D) + allocate(self%coord1(2),self%coord2(2),self%coord3(2)) + allocate(self%coord1i(8),self%coord2i(8),self%coord3i(8)) + class is (neutraldata2D) + allocate(self%coord1(2),self%coord2(2),self%coord3(2)) + allocate(self%coord1i(8),self%coord2i(8),self%coord3i(8)) + end select + call self%init_storage() + do i=1,size(self%coverage) + allocate(self%coverage(i)%valid(8),source=.true.) + end do + + select type (self) + type is (precipdata) + self%llon=>self%lc2; self%llat=>self%lc3 + self%mlonp=>self%coord2; self%mlatp=>self%coord3 + self%Qp=>self%data2Dax23(:,:,1); self%Qpinow=>self%data2Dax23inow(:,:,1) + type is (solfluxdata) + self%llon=>self%lc2; self%llat=>self%lc3; self%lalt=>self%lc1 + self%Iinfinow=>self%data3Dinow + type is (efielddata) + self%llon=>self%lc2; self%llat=>self%lc3 + self%flagdirich=>self%data0D(1) + self%E0xinow=>self%data2Dax23inow(:,:,1) + type is (neutraldataBG) + self%llon=>self%lc2; self%llat=>self%lc3; self%lalt=>self%lc1 + self%natmp=>self%data3D; self%natminow=>self%data3Dinow + allocate(self%proj_ezp_e1(2,2,2)) + self%flagcoordsi=.true. ! remaining allocatables can be absent during teardown + class is (neutraldata2D) + self%lzn=>self%lc1; self%lhorzn=>self%lc2; self%lxn=>self%lc3 + self%zn=>self%coord1; self%horzn=>self%coord2 + self%zi=>self%coord1i; self%horzi=>self%coord2i + allocate(self%proj_ezp_e1(2,2,2),self%zimat(2,2,2)) + class is (neutraldata3D) + self%lzn=>self%lc1; self%lxn=>self%lc2; self%lyn=>self%lc3 + self%zn=>self%coord1; self%xn=>self%coord2; self%yn=>self%coord3 + self%zi=>self%coord1i; self%xi=>self%coord2i; self%yi=>self%coord3i + end select + select type (self) + class is (neutraldata) + self%dnOinow=>self%data3Dinow(:,:,:,1) + self%dvn1inow=>self%data3Dinow(:,:,:,4) + end select + select type (self) + class is (neutraldata3D_mpi) + allocate(self%extents(2,6),self%indx(2,6),self%slabsizes(2,3)) + allocate(self%xnall(2),self%ynall(2),self%proj_ezp_e1(2,2,2),self%ximat(2,2,2)) + class is (neutraldata3D_fclaw) + ! Pending borrowed exchange buffers are still owned by the input object. + allocate(self%zlocsi(8),self%xlocsi(8),self%ylocsi(8),self%ilocsi(8,3),self%dataxyzinow(8,7)) + end select +end subroutine initialize + +subroutine assert_released(self) + class(inputdata), intent(in) :: self + integer :: i + + if (associated(self%lc1) .or. associated(self%lc2) .or. associated(self%lc3)) error stop 'dimension leak' + if (associated(self%coord1) .or. associated(self%coord2) .or. associated(self%coord3)) error stop 'source coordinate leak' + if (associated(self%coord1i) .or. associated(self%coord2i) .or. associated(self%coord3i)) error stop 'target coordinate leak' + if (associated(self%coord1iax1) .or. associated(self%coord2iax2) .or. associated(self%coord3iax3)) & + error stop 'axis coordinate leak' + if (associated(self%coord2iax23) .or. associated(self%coord3iax23)) error stop '23 coordinate leak' + if (associated(self%coord1iax12) .or. associated(self%coord2iax12)) error stop '12 coordinate leak' + if (associated(self%coord1iax13) .or. associated(self%coord3iax13)) error stop '13 coordinate leak' + if (associated(self%data0D) .or. associated(self%data0Di) .or. associated(self%data0Dinow)) error stop 'scalar leak' + if (associated(self%data1Dax1) .or. associated(self%data1Dax2) .or. associated(self%data1Dax3)) error stop '1D source leak' + if (associated(self%data1Dax1i) .or. associated(self%data1Dax2i) .or. associated(self%data1Dax3i)) error stop '1D frame leak' + if (associated(self%data1Dax1inow) .or. associated(self%data1Dax2inow) .or. associated(self%data1Dax3inow)) & + error stop '1D now leak' + if (associated(self%data2Dax23) .or. associated(self%data2Dax12) .or. associated(self%data2Dax13)) error stop '2D source leak' + if (associated(self%data2Dax23i) .or. associated(self%data2Dax12i) .or. associated(self%data2Dax13i)) error stop '2D frame leak' + if (associated(self%data2Dax23inow) .or. associated(self%data2Dax12inow) .or. associated(self%data2Dax13inow)) & + error stop '2D now leak' + if (associated(self%data3D) .or. associated(self%data3Di) .or. associated(self%data3Dinow)) error stop '3D data leak' + do i=1,size(self%coverage) + if (allocated(self%coverage(i)%valid)) error stop 'coverage leak' + end do + if (self%flagalloc .or. self%flagsizes .or. self%flagdatasize .or. self%flagcoordsi .or. self%flagprimed) & + error stop 'lifecycle flags not reset' +end subroutine assert_released +end program input_lifecycle_test diff --git a/test/audit/installation.cmake b/test/audit/installation.cmake new file mode 100644 index 000000000..01aedf234 --- /dev/null +++ b/test/audit/installation.cmake @@ -0,0 +1,5 @@ +if(Python_Interpreter_FOUND AND Python_VERSION VERSION_GREATER_EQUAL 3.11) + add_test(NAME qualification:local_environment + COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/qualification/test_local_environment.py) + set_tests_properties(qualification:local_environment PROPERTIES LABELS "unit;qualification;installation") +endif() diff --git a/test/audit/interp_test.f90 b/test/audit/interp_test.f90 new file mode 100644 index 000000000..178a7bbed --- /dev/null +++ b/test/audit/interp_test.f90 @@ -0,0 +1,33 @@ +! Audit addition 2026-09-16. Apache-2.0. +program audit_interp +use phys_consts, only: wp +use interpolation, only: interp1,interp2,interp3 +implicit none +real(wp) :: x(2),q(4),a(2),b(2,2),c(2,2,2),y(4),expected(4) +integer :: i,j,k +x=[0._wp,1._wp];q=[0._wp,0.5_wp,1._wp,2._wp] +a=2*x+3 +expected=[3._wp,4._wp,5._wp,0._wp] +y=interp1(x,a,q) +if (maxval(abs(y-expected))>1e-12_wp) error stop 'interp1 affine/boundary/OOD' +do j=1,2 + do i=1,2 + b(i,j)=2*x(i)+3*x(j)+1 + enddo +enddo +y=interp2(x,x,b,q,q);expected=[1._wp,3.5_wp,6._wp,0._wp] +if (maxval(abs(y-expected))>1e-12_wp) error stop 'interp2 affine/boundary/OOD' +do k=1,2 + do j=1,2 + do i=1,2 + c(i,j,k)=2*x(i)+3*x(j)+4*x(k)+1 + enddo + enddo +enddo +y=interp3(x,x,x,c,q,q,q);expected=[1._wp,5.5_wp,10._wp,0._wp] +if (maxval(abs(y-expected))>1e-12_wp) error stop 'interp3 affine/boundary/OOD' +! A singleton 1D axis represents an invariant driver dimension. +y=interp1([0._wp],[7._wp],q) +if (any(y/=7._wp)) error stop 'interp1 singleton invariant dimension' +print *, 'PASS affine interpolation on 2-point axes, endpoints and zero-fill outside domain' +end program diff --git a/test/audit/lifecycle.cmake b/test/audit/lifecycle.cmake new file mode 100644 index 000000000..c2d5db00a --- /dev/null +++ b/test/audit/lifecycle.cmake @@ -0,0 +1,25 @@ +add_executable(audit_neutral_background neutral_background_test.f90) +target_link_libraries(audit_neutral_background PRIVATE neutral_background neutral neutraldataBG meshobj_cart grid gemini3d) +intel_fortran_main_linker(audit_neutral_background) +target_compile_options(audit_neutral_background PRIVATE + $<$:-ffpe-trap=invalid,zero,overflow>) +foreach(mode IN ITEMS covered endpoint singleton descending_covered ascending descending closed closed_covered zero belowground) + add_test(NAME audit:neutral_background_${mode} COMMAND audit_neutral_background ${mode}) + set_tests_properties(audit:neutral_background_${mode} PROPERTIES LABELS "unit;audit") +endforeach() +if(Python_Interpreter_FOUND) + foreach(mode IN ITEMS lower_coverage upper_coverage zero_denominator negative_density underground temperature singleton_uncovered) + add_test(NAME audit:neutral_background_reject_${mode} COMMAND ${Python_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/neutral_rejection.py $ ${mode}) + set_tests_properties(audit:neutral_background_reject_${mode} PROPERTIES LABELS "unit;audit") + endforeach() +endif() + +add_executable(audit_input_lifecycle input_lifecycle_test.f90) +target_link_libraries(audit_input_lifecycle PRIVATE inputdata precipdata solfluxdata efielddata neutraldataBG + neutraldata neutraldata2D neutraldata2Dcart neutraldata2Daxisymm neutraldata3D neutraldata3D_mpi + neutraldata3D_geom_mpi neutraldata3D_geog_mpi neutraldata3D_fclaw neutraldata3D_fclaw_axisymm + neutraldata3D_fclaw_3Dx meshobj_cart meshobj_dipole gemini3d) +intel_fortran_main_linker(audit_input_lifecycle) +add_test(NAME audit:input_lifecycle COMMAND audit_input_lifecycle) +set_tests_properties(audit:input_lifecycle PROPERTIES LABELS "unit;audit") diff --git a/test/audit/magcalc_kernels.f90.in b/test/audit/magcalc_kernels.f90.in new file mode 100644 index 000000000..1e8d7879e --- /dev/null +++ b/test/audit/magcalc_kernels.f90.in @@ -0,0 +1,174 @@ +! Compile the production program's internal kernels and 2-D component assembly +! verbatim: the reference below must not become another copy of those kernels. +program audit_magcalc_kernels +use phys_consts, only: wp,pi,mu0 +use mpimod, only: runtime_cfg=>mpi_cfg,gemini_mpi_config,mpisetup,mpi_manualgrid,halo_end,mpi_realprec,tag=>gemini_mpi +use meshobj_cart, only: cartmesh +use mpi_f08, only: MPI_Init,MPI_Finalize,MPI_Allreduce,MPI_SUM,MPI_COMM_WORLD +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +implicit none +type(cartmesh) :: x +type(gemini_mpi_config) :: mpi_cfg +integer :: lx1,lx2,lx3,ipoints,i,k,c,gk,total +real(wp), allocatable :: Rx(:,:,:),Ry(:,:,:),Rcubed(:,:,:),dV(:,:,:),integrand(:,:,:) +real(wp), allocatable :: Jx(:,:,:),Jy(:,:,:),Jz(:,:,:) +real(wp), allocatable :: Rxend(:,:),Ryend(:,:),Rcubedend(:,:),dVend(:,:),integrandend(:,:) +real(wp), allocatable :: Jxend(:,:),Jyend(:,:),Jzend(:,:) +real(wp), allocatable :: Rcubedtop(:,:),dVtop(:,:),Rcubedcorner(:),dVcorner(:) +real(wp) :: Br(1),Btheta(1),Bphi(1),result(3),reference(3),numerator +call MPI_Init() +call mpisetup() +mpi_cfg=runtime_cfg +do total=4,8,4 + lx1=3; lx2=1; lx3=total/mpi_cfg%lid + call mpi_manualgrid(1,total,1,mpi_cfg%lid) + mpi_cfg=runtime_cfg + allocate(Rx(lx1,1,lx3),Ry(lx1,1,lx3),Rcubed(lx1,1,lx3),dV(lx1,1,lx3),integrand(lx1,1,lx3)) + allocate(Jx(lx1,1,lx3),Jy(lx1,1,lx3),Jz(lx1,1,lx3)) + allocate(Rxend(lx1,1),Ryend(lx1,1),Rcubedend(lx1,1),dVend(lx1,1),integrandend(lx1,1)) + allocate(Jxend(lx1,1),Jyend(lx1,1),Jzend(lx1,1)) + allocate(Rcubedtop(lx1,lx3),dVtop(lx1,lx3),Rcubedcorner(lx1),dVcorner(lx1)) + do k=1,lx3 + gk=mpi_cfg%myid3*lx3+k + do i=1,lx1 + Rx(i,1,k)=radius_x(i,gk); Ry(i,1,k)=radius_y(i,gk) + Jx(i,1,k)=current(1,i,gk); Jy(i,1,k)=current(2,i,gk); Jz(i,1,k)=current(3,i,gk) + enddo + enddo + dV=1 + call halo_end(dV,dVend,dVtop,dVcorner,tag%dV) + call halo_end(Rx,Rxend,Rcubedtop,Rcubedcorner,tag%Rx) + call halo_end(Ry,Ryend,Rcubedtop,Rcubedcorner,tag%Ry) + call halo_end(Jx,Jxend,Rcubedtop,Rcubedcorner,tag%Jx) + call halo_end(Jy,Jyend,Rcubedtop,Rcubedcorner,tag%Jy) + call halo_end(Jz,Jzend,Rcubedtop,Rcubedcorner,tag%Jz) + ipoints=1 +@MAGCALC_2D@ + call MPI_Allreduce([Br(1),Btheta(1),Bphi(1)],result,3,mpi_realprec,MPI_SUM,MPI_COMM_WORLD) + reference=0 + do c=1,3 + do k=2,total + do i=2,lx1 + numerator=cross_product(c,i-1,k-1)+cross_product(c,i,k-1)+ & + cross_product(c,i-1,k)+cross_product(c,i,k) + reference(c)=reference(c)+mu0/(8*pi)*numerator/(radius_x(i,k)**2+radius_y(i,k)**2) + enddo + enddo + enddo + if (.not.all(ieee_is_finite(result))) error stop 'Nonfinite 2-D magnetic field' + if (maxval(abs(result-reference))>128*epsilon(1._wp)*maxval(abs(reference))) & + error stop 'Magnetic quadrature disagrees with direct discrete oracle' + ! Terminal ranks must skip their zero denominator even for nonzero end data. + if (mpi_cfg%myid3==mpi_cfg%lid3-1) then + integrand=0; integrandend=1; Rcubedend=0; dVend=0 + numerator=integrate2D(integrand,integrandend) + if (.not.ieee_is_finite(numerator) .or. numerator/=0) error stop 'Terminal 2-D end cell was evaluated' + endif + deallocate(Rx,Ry,Rcubed,dV,integrand,Jx,Jy,Jz,Rxend,Ryend,Rcubedend,dVend,integrandend,Jxend,Jyend,Jzend) + deallocate(Rcubedtop,dVtop,Rcubedcorner,dVcorner) +enddo +call check_current_edges() +call MPI_Finalize() +print *, 'Magnetic 2-D quadrature, terminal slabs and current edges passed' +contains +pure real(wp) function radius_x(i,k) + integer, intent(in) :: i,k + radius_x=2._wp+0.5_wp*i+0.25_wp*k +end function +pure real(wp) function radius_y(i,k) + integer, intent(in) :: i,k + radius_y=3._wp+0.25_wp*i-0.125_wp*k +end function +pure real(wp) function current(c,i,k) + integer, intent(in) :: c,i,k + select case(c) + case(1) + current=real(2*i+k,wp) + case(2) + current=real(i-3*k,wp) + case(3) + current=real(i+k,wp) + end select +end function +pure real(wp) function cross_product(c,i,k) + integer, intent(in) :: c,i,k + select case(c) + case(1) + cross_product=-current(3,i,k)*radius_y(i,k) + case(2) + cross_product=current(3,i,k)*radius_x(i,k) + case(3) + cross_product=current(1,i,k)*radius_y(i,k)-current(2,i,k)*radius_x(i,k) + end select +end function +subroutine check_current_edges() + real(wp), allocatable :: j1(:,:,:),j2(:,:,:),j3(:,:,:),before(:,:,:) + integer :: n2,n3,edge,ii,jj,kk + ! fixJ has no communication; replay each possible boundary rank locally. + mpi_cfg%myid=1 + do n2=1,5 + do n3=1,5 + allocate(j1(-1:4,-1:n2+2,-1:n3+2),j2(-1:4,-1:n2+2,-1:n3+2),j3(-1:4,-1:n2+2,-1:n3+2)) + allocate(before(-1:4,-1:n2+2,-1:n3+2),x%alt(-1:4,-1:n2+2,-1:n3+2)) + do edge=1,4 + mpi_cfg%lid2=3; mpi_cfg%lid3=3; mpi_cfg%myid2=1; mpi_cfg%myid3=1 + select case(edge) + case(1) + mpi_cfg%myid2=0 + case(2) + mpi_cfg%myid2=2 + case(3) + mpi_cfg%myid3=0 + case(4) + mpi_cfg%myid3=2 + end select + do kk=-1,n3+2 + do jj=-1,n2+2 + do ii=-1,4 + before(ii,jj,kk)=real(ii+10*jj+100*kk,wp) + enddo + enddo + enddo + j1=before; j2=2; j3=3; x%alt=100000 + x%alt(-1,:,:)=70000 + call fixJ(j1,j2,j3) + if (any(j1(-1,:,:)/=0) .or. any(j2(-1,:,:)/=0) .or. any(j3(-1,:,:)/=0)) & + error stop 'Low altitude current cutoff' + if (any(j2(1:2,:,:)/=2) .or. any(j3(1:2,:,:)/=3)) error stop 'Transverse current changed' + select case(edge) + case(1) + if(n2<=2)then + if(any(j1(1:2,1:n2,:)/=0)) error stop 'Small low x2 current boundary' + else + if(any(j1(1:2,1,:)/=before(1:2,3,:)) .or. any(j1(1:2,2,:)/=before(1:2,3,:))) & + error stop 'Low x2 current extrapolation' + endif + case(2) + if(n2<=2)then + if(any(j1(1:2,1:n2,:)/=0)) error stop 'Small high x2 current boundary' + else + if(any(j1(1:2,n2-1,:)/=before(1:2,n2-2,:)) .or. any(j1(1:2,n2,:)/=before(1:2,n2-2,:))) & + error stop 'High x2 current extrapolation' + endif + case(3) + if(n3<=2)then + if(any(j1(1:2,:,1:n3)/=0)) error stop 'Small low x3 current boundary' + else + if(any(j1(1:2,:,1)/=before(1:2,:,3)) .or. any(j1(1:2,:,2)/=before(1:2,:,3))) & + error stop 'Low x3 current extrapolation' + endif + case(4) + if(n3<=2)then + if(any(j1(1:2,:,1:n3)/=0)) error stop 'Small high x3 current boundary' + else + if(any(j1(1:2,:,n3-1)/=before(1:2,:,n3-2)) .or. any(j1(1:2,:,n3)/=before(1:2,:,n3-2))) & + error stop 'High x3 current extrapolation' + endif + end select + enddo + deallocate(j1,j2,j3,before,x%alt) + enddo + enddo +end subroutine +@MAGCALC_KERNELS@ +end program diff --git a/test/audit/mpi_time_test.f90 b/test/audit/mpi_time_test.f90 new file mode 100644 index 000000000..dce495795 --- /dev/null +++ b/test/audit/mpi_time_test.f90 @@ -0,0 +1,45 @@ +program audit_mpi_time +use mpi_f08, only: MPI_Init,MPI_Finalize +use mpimod, only: mpisetup,mpi_cfg +use phys_consts, only: wp,lsp +use temporal_mpi, only: dt_comm,enforce_post_update_cfl +use meshobj_cart, only: cartmesh +use gemini3d_config, only: gemini_cfg +implicit none +type(cartmesh) :: x +type(gemini_cfg) :: cfg +real(wp) :: ns(-1:4,-1:3,-1:3,lsp),ts(-1:4,-1:3,-1:3,lsp),v(-1:4,-1:3,-1:3,lsp) +real(wp) :: v2(-1:4,-1:3,-1:3,lsp),b(-1:4,-1:3,-1:3),dt +character(32) :: mode +call get_command_argument(1,mode) +call MPI_Init() +call mpisetup() +allocate(x%dl1i(2,1,1),x%dl2i(2,1,1),x%dl3i(2,1,1)) +x%dl1i=1e6_wp;x%dl2i=1;x%dl3i=1 +ns=1e11_wp;ts=300;v=0;v2=0;b=0 +cfg%tcfl=0.5_wp;cfg%tdur=100;cfg%potsolve=1 +if(trim(mode)=='worker_cfl')then + ! Only a non-root worker violates CFL: the global reduction must detect it. + if(mpi_cfg%lid<2)error stop 'worker CFL test needs at least two ranks' + if(mpi_cfg%myid==1)v2(1,1,1,7)=20 + call enforce_post_update_cfl(ts,v,v2,v,x,0.1_wp) + call MPI_Finalize() + stop 0 ! WILL_FAIL must reject an undetected violation. +endif +call dt_comm(0._wp,0._wp,0._wp,cfg,ns,ts,v,v2,v,b,b,b,x,dt) +if(abs(dt-1e-6_wp)>1e-15_wp)error stop 'bootstrap cap mismatch' +! A worker-limited step below a microsecond must not be raised by bootstrap. +if(mpi_cfg%myid==1)v2=1e8_wp +call dt_comm(0._wp,0._wp,0._wp,cfg,ns,ts,v,v2,v,b,b,b,x,dt) +if(mpi_cfg%lid>1 .and. dt>5e-9_wp*(1+1e-12_wp))error stop 'unsafe minimum step' +v2=0 +call dt_comm(99.9_wp,200._wp,200._wp,cfg,ns,ts,v,v2,v,b,b,b,x,dt) +if(abs(dt-0.1_wp)>1e-12_wp)error stop 'final time overshoot' +cfg%flagE0file=1;cfg%dtE0=10 +call dt_comm(9.5_wp,100._wp,100._wp,cfg,ns,ts,v,v2,v,b,b,b,x,dt) +if(abs(dt-0.5_wp)>1e-12_wp)error stop 'driver knot overshoot' +call enforce_post_update_cfl(ts,v,v2,v,x,dt) +deallocate(x%dl1i,x%dl2i,x%dl3i) +call MPI_Finalize() +print *, 'MPI time selection and safe CFL passed' +end program diff --git a/test/audit/neutral_abi.c b/test/audit/neutral_abi.c new file mode 100644 index 000000000..b89427e31 --- /dev/null +++ b/test/audit/neutral_abi.c @@ -0,0 +1,27 @@ +#include "gemini3d.h" +#include + +extern void audit_neutral_fixture(void **, void **, void **, const int *); +extern void audit_neutral_check(void **, const double *, const double *); +extern void audit_neutral_release(void **); + +int main(int argc, char **argv) { + int version = argc > 1 ? atoi(argv[1]) : 0; + void *cfg = NULL, *grid = NULL, *work = NULL; + int xtype = 1, ymd[3] = {2013, 2, 20}; + double ut = 18000, v2 = 12, v3 = -7; + audit_neutral_fixture(&cfg, &grid, &work, &version); + setv2v3_C(&v2, &v3); + msisinit_C(&cfg); + neutral_atmos_winds_C(&cfg, &xtype, &grid, ymd, &ut, &work); + audit_neutral_check(&work, &v2, &v3); + v2 = -18; + v3 = 23; + setv2v3_C(&v2, &v3); + for (int i = 0; i < 2; ++i) { + neutral_atmos_wind_update_C(&work); + audit_neutral_check(&work, &v2, &v3); + } + audit_neutral_release(&work); + return 0; +} diff --git a/test/audit/neutral_abi_fixture.f90 b/test/audit/neutral_abi_fixture.f90 new file mode 100644 index 000000000..f0583ac86 --- /dev/null +++ b/test/audit/neutral_abi_fixture.f90 @@ -0,0 +1,54 @@ +module neutral_abi_fixture +use, intrinsic :: iso_c_binding, only: c_ptr,c_loc,c_f_pointer,c_int +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +use phys_consts, only: wp +use gemini3d, only: gemini_work +use gemini3d_config, only: gemini_cfg +use meshobj_cart, only: cartmesh +use grid, only: set_total_grid_sizes,set_subgrid_sizes +use neutral, only: neutral_info_alloc,neutral_info_dealloc +implicit none +type(gemini_cfg), target, save :: cfg +type(cartmesh), target, save :: x +type(gemini_work), target, save :: work +contains +subroutine fixture(cfgC,xC,workC,version) bind(C,name="audit_neutral_fixture") +type(c_ptr), intent(out) :: cfgC,xC,workC +integer(c_int), intent(in) :: version +call set_total_grid_sizes(2,1,1) +call set_subgrid_sizes(1,1) +cfg%activ=[100._wp,100._wp,4._wp] +cfg%msis_version=version +x%lx1=2; x%lx2=1; x%lx3=1; x%lnull=0 +allocate(x%glat(2,1,1),x%glon(2,1,1),x%alt(2,1,1),work%atmos) +x%glat=65; x%glon=210; x%alt(:,1,1)=[200e3_wp,300e3_wp] +call neutral_info_alloc(work%atmos) +work%atmos%flagprojections=.true. +work%atmos%proj_ealt_e1=1; work%atmos%proj_eglat_e1=0; work%atmos%proj_eglon_e1=0 +work%atmos%proj_ealt_e2=0; work%atmos%proj_eglat_e2=1; work%atmos%proj_eglon_e2=0 +work%atmos%proj_ealt_e3=0; work%atmos%proj_eglat_e3=0; work%atmos%proj_eglon_e3=1 +cfgC=c_loc(cfg); xC=c_loc(x); workC=c_loc(work) +end subroutine + +subroutine check(workC,v2,v3) bind(C,name="audit_neutral_check") +type(c_ptr), intent(in) :: workC +real(wp), intent(in) :: v2,v3 +type(gemini_work), pointer :: w +call c_f_pointer(workC,w) +if (.not.all(ieee_is_finite(w%atmos%nn)) .or. .not.all(ieee_is_finite(w%atmos%Tn))) & + error stop "nonfinite empirical atmosphere through C ABI" +if (any(w%atmos%nn<=0) .or. any(w%atmos%Tn<100)) error stop "C ABI did not compute empirical atmosphere" +if (any(w%atmos%nn/=w%atmos%nnBG) .or. any(w%atmos%Tn/=w%atmos%TnBG)) error stop "background not aggregated" +if (any(abs(w%atmos%vn1-w%atmos%vn1BG)>1e-10_wp)) error stop "wind 1 not aggregated" +if (any(abs(w%atmos%vn2-(w%atmos%vn2BG-v2))>1e-10_wp)) error stop "wind 2 drift not applied exactly once" +if (any(abs(w%atmos%vn3-(w%atmos%vn3BG-v3))>1e-10_wp)) error stop "wind 3 drift not applied exactly once" +end subroutine + +subroutine release(workC) bind(C,name="audit_neutral_release") +type(c_ptr), intent(in) :: workC +type(gemini_work), pointer :: w +call c_f_pointer(workC,w) +call neutral_info_dealloc(w%atmos) +deallocate(w%atmos,x%glat,x%glon,x%alt) +end subroutine +end module diff --git a/test/audit/neutral_background_test.f90 b/test/audit/neutral_background_test.f90 new file mode 100644 index 000000000..53b6a0ccf --- /dev/null +++ b/test/audit/neutral_background_test.f90 @@ -0,0 +1,130 @@ +program neutral_background_test +use phys_consts, only: wp +use grid, only: lx1,lx2,lx3,set_total_grid_sizes,set_subgrid_sizes +use meshobj_cart, only: cartmesh +use gemini3d_config, only: gemini_cfg +use neutral, only: neutral_info,neutral_info_alloc,neutral_info_dealloc +use neutral_background, only: neutral_background_fileinput +use neutraldataBGobj, only: neutraldataBG +implicit none +type(cartmesh) :: x +type(gemini_cfg) :: cfg +type(neutral_info) :: atmos +type(neutraldataBG), allocatable :: bg +character(40) :: mode +real(wp), allocatable :: expected_n(:),expected_t(:),expected_v(:) +integer :: i + +call get_command_argument(1,mode) +call set_total_grid_sizes(5,1,1) +if (mode=='singleton' .or. mode=='singleton_uncovered') call set_total_grid_sizes(1,1,1) +call set_subgrid_sizes(1,1) +x%lx1=lx1; x%lx2=lx2; x%lx3=lx3 +allocate(x%alt(lx1,1,1),bg) +allocate(bg%lc1,bg%lc2,bg%lc3) +bg%lc1=lx1; bg%lc2=1; bg%lc3=1 +bg%lc1i=lx1; bg%lc2i=1; bg%lc3i=1 +bg%l0D=0; bg%l1Dax1=0; bg%l1Dax2=0; bg%l1Dax3=0 +bg%l2Dax23=0; bg%l2Dax12=0; bg%l2Dax13=0; bg%l3D=9 +bg%flagsizes=.true. +call bg%init_storage() +bg%natminow=>bg%data3Dinow +call bg%set_source('prepared') +call bg%set_cadence(2._wp) +bg%flagprimed=.true. +bg%tref=[-1._wp,1._wp] +bg%altpmax=300e3_wp +call neutral_info_alloc(atmos) +atmos%flagprojections=.true. +atmos%proj_ealt_e1=1; atmos%proj_eglat_e1=0; atmos%proj_eglon_e1=0 +atmos%proj_ealt_e2=0; atmos%proj_eglat_e2=1; atmos%proj_eglon_e2=0 +atmos%proj_ealt_e3=0; atmos%proj_eglat_e3=0; atmos%proj_eglon_e3=1 +atmos%vn1=-999; atmos%vn2=-999; atmos%vn3=-999 +allocate(expected_n(lx1),expected_t(lx1),expected_v(lx1)) +do i=1,lx1 + x%alt(i,1,1)=100e3_wp*i + bg%natminow(i,1,1,1:5)=16._wp/2**(i-1) + bg%natminow(i,1,1,6:8)=10._wp*i + bg%natminow(i,1,1,9)=500._wp+10*i +end do +expected_n=bg%natminow(:,1,1,1) +expected_t=bg%natminow(:,1,1,9) +expected_v=bg%natminow(:,1,1,6) + +select case (mode) +case ('covered','endpoint','singleton') + bg%altpmax=maxval(x%alt) + if (mode=='covered') bg%altpmax=bg%altpmax+1 +case ('descending_covered','descending') + x%alt(:,1,1)=x%alt(lx1:1:-1,1,1) + bg%natminow(:,1,1,:)=bg%natminow(lx1:1:-1,1,1,:) + expected_n=expected_n(lx1:1:-1) + expected_t=expected_t(lx1:1:-1) + expected_v=expected_v(lx1:1:-1) + if (mode=='descending_covered') then + bg%altpmax=600e3_wp + else + expected_t(1:2)=expected_t(3) + expected_v(1:2)=expected_v(3) + end if +case ('closed','closed_covered') + x%alt(:,1,1)=[100e3_wp,200e3_wp,300e3_wp,200e3_wp,100e3_wp] + bg%natminow(4:5,1,1,1:5)=bg%natminow(2:1:-1,1,1,1:5) + expected_n=[16._wp,8._wp,4._wp,8._wp,16._wp] + if (mode=='closed') then + bg%altpmax=200e3_wp + ! Preserve the existing maximum-x1 hemisphere convention at the apex. + expected_v(3)=expected_v(4); expected_t(3)=expected_t(4) + end if +case ('ascending','zero','belowground') + expected_t(4:5)=expected_t(3) + expected_v(4:5)=expected_v(3) + if (mode=='zero') then + bg%natminow(:,1,1,4)=0 + else if (mode=='belowground') then + x%alt(1,1,1)=-10e3_wp + expected_n(1)=expected_n(2); expected_t(1)=expected_t(2) + end if +case ('lower_coverage') + bg%altpmax=100e3_wp +case ('upper_coverage') + x%alt(:,1,1)=x%alt(lx1:1:-1,1,1) + bg%altpmax=100e3_wp +case ('zero_denominator') + bg%natminow(2,1,1,4)=0 +case ('negative_density') + bg%natminow(2,1,1,4)=-1 +case ('underground') + x%alt=-1 +case ('temperature') + bg%natminow(3,1,1,9)=0 +case ('singleton_uncovered') + bg%altpmax=50e3_wp +case default + error stop 'unknown neutral test mode' +end select + +! Spatial interpolation leaves zeros where altitude coverage is missing. +do i=1,lx1 + if (x%alt(i,1,1)>bg%altpmax .or. x%alt(i,1,1)<0) bg%data3Dinow(i,1,1,:)=0 + if (x%alt(i,1,1)<0) expected_v(i)=0 +end do +! Two identical, already spatially interpolated frames isolate copyout policy. +bg%data3Di(:,:,:,:,1)=bg%data3Dinow +bg%data3Di(:,:,:,:,2)=bg%data3Dinow +call neutral_background_fileinput(1._wp,0._wp,cfg,[2020,1,1],0._wp,x,atmos,bg) +if (any(abs(atmos%nnBG(:,1,1,1)-expected_n)>1e-12_wp)) error stop 'density extrapolation' +if (any(abs(atmos%TnBG(:,1,1)-expected_t)>1e-12_wp)) error stop 'temperature extrapolation' +if (any(abs(atmos%vn2BG(:,1,1)-expected_v)>1e-12_wp)) error stop 'fresh wind 2 extrapolation' +if (any(abs(atmos%vn3BG(:,1,1)-expected_v)>1e-12_wp)) error stop 'fresh wind 3 extrapolation' +expected_v=expected_v*(0.5_wp+0.5_wp*tanh((x%alt(:,1,1)-150e3_wp)/10e3_wp)) +if (any(abs(atmos%vn1BG(:,1,1)-expected_v)>1e-12_wp)) error stop 'fresh wind 1 extrapolation' +if (mode=='zero') then + if (any(atmos%nnBG(:,1,1,4)/=0)) error stop 'absent species must remain absent' +end if +if (any(atmos%vn1/=-999) .or. any(atmos%vn2/=-999) .or. any(atmos%vn3/=-999)) & + error stop 'background update changed aggregate winds' +call neutral_info_dealloc(atmos) +deallocate(x%alt,bg,expected_n,expected_t,expected_v) +print *, 'neutral background passed: ',trim(mode) +end program neutral_background_test diff --git a/test/audit/neutral_rejection.py b/test/audit/neutral_rejection.py new file mode 100644 index 000000000..f505034e4 --- /dev/null +++ b/test/audit/neutral_rejection.py @@ -0,0 +1,20 @@ +"""Require the physical-policy diagnostic, not a bounds error or floating-point trap.""" +import subprocess +import sys + +messages = { + "lower_coverage": "insufficient lower-end altitude coverage", + "upper_coverage": "insufficient upper-end altitude coverage", + "zero_denominator": "zero lower extrapolation density", + "negative_density": "negative extrapolation density", + "underground": "field line is entirely below ground", + "temperature": "temperatures must be finite and positive", + "singleton_uncovered": "insufficient altitude coverage", +} +exe, mode = sys.argv[1:] +result = subprocess.run([exe, mode], capture_output=True, text=True, timeout=30) +output = result.stdout + result.stderr +assert result.returncode > 0, (mode, result.returncode, output) +assert messages[mode] in output, (mode, output) +assert "Fortran runtime error" not in output, (mode, output) +print(f"neutral background rejected {mode} with the expected diagnostic") diff --git a/test/audit/numerics.cmake b/test/audit/numerics.cmake new file mode 100644 index 000000000..dc093b160 --- /dev/null +++ b/test/audit/numerics.cmake @@ -0,0 +1,59 @@ +add_executable(audit_cartmesh_metrics cartmesh_metrics.f90) +target_link_libraries(audit_cartmesh_metrics PRIVATE meshobj_cart const gemini3d) +intel_fortran_main_linker(audit_cartmesh_metrics) +add_test(NAME audit:cartmesh_metrics COMMAND audit_cartmesh_metrics) +set_tests_properties(audit:cartmesh_metrics PROPERTIES LABELS "unit;audit;numerics") + +add_executable(audit_halo_end halo_end.f90) +target_link_libraries(audit_halo_end PRIVATE mpimod const gemini3d MPI::MPI_Fortran) +intel_fortran_main_linker(audit_halo_end) + +# magcalc keeps these procedures internal to its main program. Extract them +# without edits so the regression exercises production code, not a test copy. +set(_magcalc_source ${PROJECT_SOURCE_DIR}/src/utils/magcalc.f90) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_magcalc_source}) +file(READ ${_magcalc_source} _magcalc) +string(REGEX MATCH " subroutine fixJ\\(J1,J2,J3\\).*end function integrate2D" MAGCALC_KERNELS "${_magcalc}") +string(REGEX MATCH " Rcubed\\(:,:,:\\)=Rx\\*\\*2\\+Ry\\*\\*2.*Bphi\\(ipoints\\) = integrate2D\\(integrand,integrandend\\)" + MAGCALC_2D "${_magcalc}") +if(NOT MAGCALC_KERNELS OR NOT MAGCALC_2D) + message(FATAL_ERROR "Could not extract production magcalc kernels for audit regression") +endif() +configure_file(magcalc_kernels.f90.in magcalc_kernels.f90 @ONLY) +add_executable(audit_magcalc_kernels ${CMAKE_CURRENT_BINARY_DIR}/magcalc_kernels.f90) +target_link_libraries(audit_magcalc_kernels PRIVATE mpimod meshobj_cart const gemini3d MPI::MPI_Fortran) +intel_fortran_main_linker(audit_magcalc_kernels) +if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + target_compile_options(audit_magcalc_kernels PRIVATE -ffpe-trap=invalid,zero,overflow) +elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel" AND NOT WIN32) + target_compile_options(audit_magcalc_kernels PRIVATE -fpe0) +endif() +foreach(ranks IN ITEMS 1 2 4) + set(audit_mpi_flags ${MPIEXEC_PREFLAGS}) + if(ranks GREATER 2 AND MPI_C_LIBRARY_VERSION_STRING MATCHES "Open[ ]?MPI") + list(APPEND audit_mpi_flags --map-by :OVERSUBSCRIBE) + endif() + foreach(probe IN ITEMS halo_end magcalc_kernels) + add_test(NAME audit:${probe}_${ranks} + COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${ranks} ${audit_mpi_flags} + $ ${MPIEXEC_POSTFLAGS}) + set_tests_properties(audit:${probe}_${ranks} PROPERTIES + TIMEOUT 60 PROCESSORS ${ranks} LABELS "unit;audit;numerics;mpi") + if(ranks GREATER 2) + set_property(TEST audit:${probe}_${ranks} APPEND PROPERTY ENVIRONMENT + "OMPI_MCA_rmaps_base_oversubscribe=1" + "PRTE_MCA_rmaps_base_oversubscribe=1") + endif() + endforeach() +endforeach() + +add_executable(audit_diffusion_singular diffusion_singular.f90) +target_link_libraries(audit_diffusion_singular PRIVATE PDEparabolic const MPI::MPI_Fortran) +if(Python_Interpreter_FOUND) + foreach(stage IN ITEMS euler tr bdf2) + add_test(NAME audit:diffusion_singular_${stage} + COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check_diffusion_failure.py + $ ${stage}) + set_tests_properties(audit:diffusion_singular_${stage} PROPERTIES TIMEOUT 30 LABELS "unit;audit;numerics") + endforeach() +endif() diff --git a/test/audit/partition_contract.cmake b/test/audit/partition_contract.cmake new file mode 100644 index 000000000..757a26cc1 --- /dev/null +++ b/test/audit/partition_contract.cmake @@ -0,0 +1,29 @@ +include("${source}/test/config.cmake") +foreach(n2 RANGE 1 15) + foreach(n3 RANGE 1 15) + foreach(budget RANGE 1 24) + set(expected 1) + foreach(p2 RANGE 1 ${n2}) + math(EXPR remainder "${n2} % ${p2}") + math(EXPR width "${n2} / ${p2}") + if(NOT remainder EQUAL 0 OR (n2 GREATER 1 AND width LESS 2)) + continue() + endif() + foreach(p3 RANGE 1 ${n3}) + math(EXPR remainder "${n3} % ${p3}") + math(EXPR width "${n3} / ${p3}") + math(EXPR candidate "${p2} * ${p3}") + if(remainder EQUAL 0 AND (n3 EQUAL 1 OR width GREATER_EQUAL 2) + AND candidate LESS_EQUAL budget AND candidate GREATER expected) + set(expected ${candidate}) + endif() + endforeach() + endforeach() + max_mpi(${n2} ${n3} ${budget} actual) + if(NOT actual EQUAL expected) + message(FATAL_ERROR "max_mpi(${n2},${n3},${budget})=${actual}; oracle=${expected}") + endif() + endforeach() + endforeach() +endforeach() +message(STATUS "5400 CMake partition cases passed") diff --git a/test/audit/partition_contract.f90 b/test/audit/partition_contract.f90 new file mode 100644 index 000000000..c9946c364 --- /dev/null +++ b/test/audit/partition_contract.f90 @@ -0,0 +1,29 @@ +program partition_contract +use autogrid, only: max_mpi, grid_auto +implicit none +integer :: n2,n3,budget,p2,p3,expected,actual,lid2,lid3 +do n2=1,33 + do n3=1,33 + do budget=1,32 + expected=1 + do p2=1,n2 + if (mod(n2,p2)/=0 .or. (n2>1 .and. n2/p2<2)) cycle + do p3=1,n3 + if (mod(n3,p3)/=0 .or. (n3>1 .and. n3/p3<2)) cycle + if (p2*p3<=budget) expected=max(expected,p2*p3) + enddo + enddo + actual=max_mpi(n2,n3,budget) + if (actual/=expected) then + print *, n2,n3,budget,expected,actual + error stop "max_mpi disagrees with exhaustive partition oracle" + endif + call grid_auto(n2,n3,actual,lid2,lid3) + if (lid2*lid3/=actual .or. mod(n2,lid2)/=0 .or. mod(n3,lid3)/=0) error stop "invalid process grid" + if (n2>1 .and. n2/lid2<2) error stop "singular local x2" + if (n3>1 .and. n3/lid3<2) error stop "singular local x3" + enddo + enddo +enddo +print *, "34848 odd/even/prime/singleton/single-CPU partitions passed" +end program diff --git a/test/audit/pole_probe.f90 b/test/audit/pole_probe.f90 new file mode 100644 index 000000000..2362a42bd --- /dev/null +++ b/test/audit/pole_probe.f90 @@ -0,0 +1,6 @@ +! Audit addition 2026-09-16. Apache-2.0. +program audit_pole +use geomagnetic, only: set_magnetic_pole +implicit none +call set_magnetic_pole(2026) +end program diff --git a/test/audit/reference_metrics.py b/test/audit/reference_metrics.py new file mode 100644 index 000000000..303d5b045 --- /dev/null +++ b/test/audit/reference_metrics.py @@ -0,0 +1,48 @@ +"""Report every saved species, without changing pass tolerances or references. + +Full-grid unweighted norms are diagnostics, not physical validation. Species +axis is the first HDF5 dimension. No null-cell/volume weighting is inferred. +""" +import argparse +import json +from pathlib import Path +import h5py +import numpy as np + +SPECIES=['O+','NO+','N2+','O2+','N+','H+','e-'] +FIELDS=['nsall','Tsall','vs1all','Phiall','J1all','J2all','J3all','v2avgall','v3avgall'] + +def compare(new,reference): + frames=sorted(reference.glob('????????_?????.??????.h5')) + records=[] + if not frames:raise ValueError('No reference frames: '+str(reference)) + for ref in frames: + candidate=new/ref.name + if not candidate.exists():raise ValueError('Missing candidate frame: '+str(candidate)) + with h5py.File(candidate) as n,h5py.File(ref) as r: + for field in FIELDS: + if field not in r:continue + if field not in n:raise ValueError('Missing candidate field: '+field) + a=n[field][...].astype(float);b=r[field][...].astype(float) + if a.shape!=b.shape:raise ValueError('Shape mismatch: '+field) + blocks=[(s,a[i],b[i]) for i,s in enumerate(SPECIES)] if field in FIELDS[:3] else [(None,a,b)] + for sp,aa,bb in blocks: + delta=aa-bb + records.append(dict(frame=ref.name,field=field,species=sp, + candidate_finite=bool(np.isfinite(aa).all()),reference_finite=bool(np.isfinite(bb).all()), + candidate_min=float(aa.min()),reference_min=float(bb.min()), + rel_l2=float(np.linalg.norm(delta)/max(np.linalg.norm(bb),1e-30)), + max_abs=float(np.max(np.abs(delta))),bitwise_equal=bool(np.array_equal(aa,bb)))) + return records + +def main(): + p=argparse.ArgumentParser(description=__doc__) + p.add_argument('--new',type=Path,required=True);p.add_argument('--reference',type=Path,required=True) + p.add_argument('--output',type=Path,required=True) + a=p.parse_args();records=compare(a.new,a.reference) + payload=dict(schema='gemini.audit.species_metrics.1',new=str(a.new),reference=str(a.reference), + scope='full-grid unweighted saved fields; no acceptance thresholds; no reference updates',records=records) + a.output.write_text(json.dumps(payload,indent=2,allow_nan=False)+'\n') + print('Wrote',len(records),'field/species/frame metrics') + +if __name__=='__main__':main() diff --git a/test/audit/restart.cmake b/test/audit/restart.cmake new file mode 100644 index 000000000..7cd3ff97e --- /dev/null +++ b/test/audit/restart.cmake @@ -0,0 +1,34 @@ +# Focused synthetic-state checks; these do not qualify research trajectories. +add_executable(qualification_restart_runtime restart_probe.f90) +target_link_libraries(qualification_restart_runtime PRIVATE restart_runtime atomic_file const + gemini3d_config timeutils mpimod gemini3d h5fortran::h5fortran MPI::MPI_Fortran) +intel_fortran_main_linker(qualification_restart_runtime) +if(NUMPY_FOUND AND H5PY_FOUND) + set(restart_mpi_flags) + foreach(flag IN LISTS MPIEXEC_PREFLAGS) + list(APPEND restart_mpi_flags "--mpi-pref=${flag}") + endforeach() + foreach(flag IN LISTS MPIEXEC_POSTFLAGS) + list(APPEND restart_mpi_flags "--mpi-post=${flag}") + endforeach() + foreach(layout IN ITEMS 1x2 2x2) + if(layout STREQUAL "2x2") + set(ranks 4) + else() + set(ranks 2) + endif() + set(layout_restart_mpi_flags ${restart_mpi_flags}) + if(ranks GREATER 2 AND MPI_C_LIBRARY_VERSION_STRING MATCHES "Open[ ]?MPI") + list(APPEND layout_restart_mpi_flags "--mpi-pref=--map-by" "--mpi-pref=:OVERSUBSCRIBE") + endif() + add_test(NAME qualification:restart_runtime_${layout} COMMAND ${Python_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/test/qualification/test_restart_runtime.py + --exe $ + --mpiexec ${MPIEXEC_EXECUTABLE} --layout ${layout} + --numproc-flag=${MPIEXEC_NUMPROC_FLAG} ${layout_restart_mpi_flags} + --work ${CMAKE_CURRENT_BINARY_DIR}/restart-runtime-${layout}) + set_tests_properties(qualification:restart_runtime_${layout} PROPERTIES + LABELS "unit;qualification;mpi" TIMEOUT 180 PROCESSORS ${ranks} + ENVIRONMENT "OMPI_MCA_rmaps_base_oversubscribe=1;PRTE_MCA_rmaps_base_oversubscribe=1") + endforeach() +endif() diff --git a/test/audit/restart_probe.f90 b/test/audit/restart_probe.f90 new file mode 100644 index 000000000..8b3b64b54 --- /dev/null +++ b/test/audit/restart_probe.f90 @@ -0,0 +1,70 @@ +! SPDX-License-Identifier: Apache-2.0 +program restart_probe +use mpi_f08, only: MPI_Init,MPI_Finalize,MPI_Barrier,MPI_COMM_WORLD +use mpimod, only: mpisetup,mpi_manualgrid,mpi_cfg +use phys_consts, only: wp +use gemini3d_config, only: gemini_cfg +use restart_runtime, only: runtime_select,runtime_read,runtime_save,runtime_restore, & + runtime_output_header,runtime_output_path,runtime_times,runtime_dt,runtime_ready +use atomic_file, only: publish_file +use h5fortran, only: hdf5_file +use timeutils, only: date_filename +use, intrinsic :: ieee_arithmetic, only: ieee_value,ieee_quiet_nan +implicit none +type(gemini_cfg) :: cfg +type(hdf5_file) :: f +real(wp) :: fluid(6,6,6,35),electro(6,6,6,7),vi1(3,2,2,7),vi2(2,3,2,7),vi3(2,2,3,7) +real(wp) :: dt,tout,tglow,neutral,base +integer :: iteration,layout(2) +character(4096) :: arg +character(32) :: mode +character(:), allocatable :: final,staged +call get_command_argument(1,mode) +call get_command_argument(2,arg) +cfg%outdir=trim(arg) +call get_command_argument(3,arg) +read(arg,*) layout(1) +call get_command_argument(4,arg) +read(arg,*) layout(2) +call MPI_Init() +call mpisetup() +call mpi_manualgrid(4,4,layout(1),layout(2)) +cfg%dtout=60._wp +call runtime_select(cfg) +final=date_filename(cfg%outdir,[2013,2,20],60._wp)//'.h5' +base=real(mpi_cfg%myid+1,wp) +if(trim(mode)=='write'.or.trim(mode)=='write_nan') then + fluid=base;electro=base+10;vi1=base+20;vi2=base+30;vi3=base+40 + if(trim(mode)=='write_nan'.and.mpi_cfg%myid==mpi_cfg%lid-1) & + vi3(2,2,3,7)=ieee_value(0._wp,ieee_quiet_nan) + dt=0.25_wp + call runtime_dt(dt,.false.) + call runtime_save(cfg,[2013,2,20],60._wp,fluid,electro,vi1,vi2,vi3,17,0._wp,120._wp,0._wp) + if(mpi_cfg%myid==0) then + staged=runtime_output_path(final) + call f%open(staged,action='w') + call runtime_output_header(f) + call f%close() + call publish_file(staged,final) + endif + call MPI_Barrier(MPI_COMM_WORLD) +elseif(trim(mode)=='read') then + fluid=-1;electro=-1;vi1=-1;vi2=-1;vi3=-1 + call runtime_read(final,cfg,60._wp) + if(runtime_ready) error stop 'Runtime became ready before payload validation' + tout=-1;tglow=-1 + call runtime_times(tout,tglow) + if(tout/=120._wp.or.tglow/=0._wp) error stop 'Restored deadlines mismatch' + call runtime_restore(fluid,electro,vi1,vi2,vi3,iteration,neutral) + if(.not.runtime_ready) error stop 'Runtime checkpoint not restored' + if(any(fluid/=base).or.any(electro/=base+10).or.any(vi1/=base+20).or. & + any(vi2/=base+30).or.any(vi3/=base+40)) error stop 'Restored payload mismatch' + if(iteration/=17.or.neutral/=0._wp) error stop 'Restored runtime metadata mismatch' + dt=-1 + call runtime_dt(dt,.true.) + if(dt/=0.25_wp.or.runtime_ready) error stop 'Restored timestep mismatch' +else + error stop 'Unknown restart probe mode' +endif +call MPI_Finalize() +end program diff --git a/test/audit/restart_reproduction.py b/test/audit/restart_reproduction.py new file mode 100644 index 000000000..52996b426 --- /dev/null +++ b/test/audit/restart_reproduction.py @@ -0,0 +1,98 @@ +"""Measure native cross-midnight restart error; never rewrite reference data. + +Needs numpy and h5py. Reuses a downloaded mini2dns_fang input case. All runs +are isolated below --work. Exit 0 requires successful runs and invalid restart +rejection; reported numerical errors still require a science acceptance bound. +""" +import argparse +from pathlib import Path +import datetime as dt +import json +import os +import re +import shutil +import subprocess +import h5py +import numpy as np + + +def main(): + p=argparse.ArgumentParser(description=__doc__) + p.add_argument('--build',type=Path,required=True) + p.add_argument('--input-case',type=Path,required=True) + p.add_argument('--work',type=Path,required=True) + p.add_argument('--mpiexec',default='mpiexec') + args=p.parse_args() + work=args.work.resolve();work.mkdir(parents=True,exist_ok=True) + origin=dt.datetime(2013,2,20,5) + new_origin=dt.datetime(2013,2,20,23,59,30) + def create(name,duration): + case=work/name + if case.exists(): raise RuntimeError('Use a new work directory: '+str(case)) + shutil.copytree(args.input_case/'inputs',case/'inputs') + for f in sorted((case/'inputs').rglob('*.h5')): + if not re.fullmatch(r'\d{8}_\d{5}\.\d{6}\.h5',f.name):continue + d,s=f.stem.split('_'); instant=dt.datetime.strptime(d,'%Y%m%d')+dt.timedelta(seconds=float(s)) + shifted=new_origin+(instant-origin) + seconds=(shifted-shifted.replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds() + target=f.with_name(shifted.strftime('%Y%m%d_')+f'{seconds:012.6f}.h5') + f.rename(target) + with h5py.File(target,'r+') as h: + if 'time/ymd' in h:h['time/ymd'][...]=[shifted.year,shifted.month,shifted.day] + if 'time/UTsec' in h:h['time/UTsec'][...]=seconds + if 'time/UThour' in h:h['time/UThour'][...]=seconds/3600 + cfg=case/'inputs/config.nml' + text=cfg.read_text() + text=re.sub(r'(?im)^(UTsec0\s*=)[^!\n]*',r'\g<1> 86370.0 ',text) + text=re.sub(r'(?im)^(tdur\s*=)[^!\n]*',r'\g<1> '+str(duration)+' ',text) + cfg.write_text(text) + return case + runs=[] + def run(case,label,expected=0): + proc=subprocess.run([args.mpiexec,'-n','2',str(args.build.resolve()/'gemini.bin'),str(case)], + capture_output=True,text=True,timeout=180) + (work/(label+'.log')).write_text(proc.stdout+proc.stderr) + runs.append(dict(label=label,returncode=proc.returncode,expected_success=expected==0, + passed=(proc.returncode==0)==(expected==0))) + return proc + continuous=create('continuous',300) + split=create('split',120) + run(continuous,'continuous');run(split,'split_first') + cfg=split/'inputs/config.nml';cfg.write_text(re.sub(r'(?im)^(tdur\s*=)[^!\n]*',r'\g<1> 300 ',cfg.read_text())) + run(split,'split_restart') + end='20130221_00270.000000.h5' + metrics=[] + if (continuous/end).exists() and (split/end).exists(): + with h5py.File(continuous/end) as a,h5py.File(split/end) as b: + for key in ['nsall','Tsall','vs1all','Phiall','J1all','J2all','J3all','v2avgall','v3avgall']: + av=a[key][...].astype(float);bv=b[key][...].astype(float) + metrics.append(dict(field=key,finite=bool(np.isfinite(bv).all()), + relative_l2=float(np.linalg.norm(bv-av)/max(np.linalg.norm(av),1e-30)), + max_absolute=float(np.max(np.abs(bv-av))),bitwise_equal=bool(np.array_equal(av,bv)))) + for label in ['incomplete','timestamp','field_resolved']: + case=work/label;shutil.copytree(split,case) + cfg=case/'inputs/config.nml' + cfg.write_text(re.sub(r'(?im)^(tdur\s*=)[^!\n]*',r'\g<1> 360 ',cfg.read_text())) + frame=case/end + if label=='incomplete': + with h5py.File(frame,'r+') as f:del f['Tsall'] + elif label=='timestamp': + with h5py.File(frame,'r+') as f:f['time/UThour'][...]=10 + else: + cfg.write_text(cfg.read_text().replace('potsolve = 1','potsolve = 3')) + # Historical slab-only records remain ineligible for field-resolved restart. + for historical in case.glob('*.h5'): + with h5py.File(historical,'r+') as f: + if 'restart_core' in f: del f['restart_core'] + proc=run(case,label,1) + expected={'incomplete':'Incomplete restart frame','timestamp':'Restart timestamp mismatch', + 'field_resolved':'Field-resolved restart requires'}[label] + runs[-1]['passed'] &= expected in (proc.stdout+proc.stderr) + payload=dict(schema='gemini.audit.restart.1',runs=runs,metrics=metrics, + software_checks_passed=all(x['passed'] for x in runs) and bool(metrics), + scientific_equivalence='not certified: choose application-specific bounds and complete checkpoint state') + (work/'results.json').write_text(json.dumps(payload,indent=2)+'\n') + print(json.dumps(payload,indent=2)) + return 0 if payload['software_checks_passed'] else 1 + +if __name__=='__main__':raise SystemExit(main()) diff --git a/test/audit/run_native_probes.py b/test/audit/run_native_probes.py new file mode 100644 index 000000000..b2d01185d --- /dev/null +++ b/test/audit/run_native_probes.py @@ -0,0 +1,152 @@ +"""Targeted negative/edge probes of compiled GEMINI, not physical validation. + +Usage: python audit/run_native_probes.py --build /path/to/cmake-build --output results.json +Run in the same compiler/MPI/HDF5 runtime environment used to build GEMINI. +""" +from pathlib import Path +import argparse +import json +import math +import subprocess +import tempfile + +BASE = """&base +ymd=2013,2,20 +UTsec0=18000 +tdur=300 +dtout=60 +activ=100,100,4 +tcfl=0.5 +Teinf=1000 +/ +&flags +potsolve=1 +flagoutput=1 +/ +&files +indat_size='inputs/simsize.h5' +indat_grid='inputs/simgrid.h5' +indat_file='inputs/initial_conditions.h5' +/ +""" + + +def main(): + p = argparse.ArgumentParser(description=__doc__) + p.add_argument('--build', type=Path, required=True) + p.add_argument('--output', type=Path, required=True) + args = p.parse_args() + bins = args.build.resolve() / 'test/audit' + results = [] + with tempfile.TemporaryDirectory(prefix='gemini-audit-') as tmp: + tmp = Path(tmp) + + def run(name, exe, cmdargs, succeeds, predicate=None): + r = subprocess.run([str(bins / exe), *map(str, cmdargs)], cwd=tmp, + text=True, capture_output=True, timeout=25) + ok = (r.returncode == 0) == succeeds + if predicate is not None: + ok = ok and predicate(r.stdout + r.stderr) + results.append(dict(name=name, passed=ok, returncode=r.returncode, + expected_success=succeeds, stdout=r.stdout, stderr=r.stderr)) + + run('null_partition:low_density_restart', 'audit_sanity', ['ns', 1, 'null_partition', tmp], True) + for field in ('ns', 'v1', 'v2', 'v3', 'ts'): + run(f'{field}:ghost_nan_ignored', 'audit_sanity', [field, 1, 'valid', tmp], True, + lambda s: 'ACCEPTED' in s) + for species in range(1, 8): + run(f'{field}:nan:species{species}', 'audit_sanity', [field, species, 'nan', tmp], False, + lambda s: 'finite' in s.lower()) + for species in range(1, 8): + run(f'ns:negative:species{species}', 'audit_sanity', ['ns', species, 'negative', tmp], False, + lambda s: 'negative' in s.lower() or 'density' in s.lower()) + + for species in range(1, 8): + run(f'ts:negative:species{species}', 'audit_sanity', ['ts', species, 'negative', tmp], False, + lambda s: 'negative temperature' in s.lower()) + + def floor_ok(s): + rows = [line.split() for line in s.splitlines() if 'AUDIT_CONFIG' in line] + return bool(rows) and all(math.isclose(float(row[-1]), 1e-100, rel_tol=1e-12, abs_tol=0) + for row in rows) + + good = { + 'minimal_defaults': BASE, + 'inline_indented_uppercase': BASE + '\n &NEUTRAL_BG msis_version=21 /\n', + 'inline_comment': BASE + '\n&evibcool ! group comment\nflagevibcool=1\n/\n', + 'empty_optional': BASE + '\n&neutral_BG\n/\n', + } + for name, value in good.items(): + f = tmp / (name + '.nml'); f.write_text(value) + pred = floor_ok + if name == 'inline_indented_uppercase': + pred = lambda s: floor_ok(s) and any('AUDIT_CONFIG' in x and x.split()[1] == '21' for x in s.splitlines()) + run('config:' + name, 'audit_config', [f], True, pred) + + first = tmp / 'saved_first.nml' + second = tmp / 'saved_second.nml' + first.write_text(BASE.replace('flagoutput=1', 'flagoutput=1\nflagperiodic=1') + '\n&neutral_BG msis_version=21 /\n') + second.write_text(BASE + '\n&neutral_BG /\n') + def saved_reset(s): + rows = [line.split() for line in s.splitlines() if 'AUDIT_CONFIG' in line] + return (len(rows) == 2 and rows[0][1] == '21' and rows[1][1] == '0' + and rows[0][-2] == '1' and rows[1][-2] == '0' and floor_ok(s)) + run('config:repeated_read_resets_defaults', 'audit_config', [first, second], True, saved_reset) + + bad = { + 'missing_activity': BASE.replace('activ=100,100,4\n', ''), + 'missing_file': BASE.replace("indat_grid='inputs/simgrid.h5'\n", ''), + 'zero_cfl': BASE.replace('tcfl=0.5', 'tcfl=0'), + 'large_cfl': BASE.replace('tcfl=0.5', 'tcfl=1.1'), + 'negative_duration': BASE.replace('tdur=300', 'tdur=-1'), + 'nan_duration': BASE.replace('tdur=300', 'tdur=NaN'), + 'inductive_not_implemented': BASE.replace('potsolve=1', 'potsolve=2'), + 'invalid_output': BASE.replace('flagoutput=1', 'flagoutput=9'), + 'zero_precip_cadence': BASE + '\n&precip dtprec=0, prec_dir="p" /\n', + 'zero_efield_cadence': BASE + '\n&efield dtE0=0, E0_dir="e" /\n', + 'zero_density_floor': BASE + '\n&mindens_user mindens_userval=0 /\n', + 'nan_density_floor': BASE + '\n&mindens_user mindens_userval=NaN /\n', + } + bad.update({ + 'invalid_month': BASE.replace('ymd=2013,2,20','ymd=2013,13,20'), + 'invalid_leap_day': BASE.replace('ymd=2013,2,20','ymd=2013,2,29'), + 'unsupported_msis': BASE+'\n&neutral_BG msis_version=99 /\n', + 'invalid_periodic': BASE.replace('flagoutput=1','flagoutput=1\nflagperiodic=2'), + 'unsupported_fang': BASE+'\n&fang flag_fang=100 /\n', + 'invalid_diffusion': BASE+'\n&diffusion diffsolvetype=3 /\n', + 'invalid_capacitance': BASE+'\n&capacitance flagcap=3 /\n', + 'nan_capacitance': BASE+'\n&capacitance magcap=NaN /\n', + 'invalid_FBI': BASE+'\n&FBI flagFBI=3 /\n', + 'invalid_cooling': BASE+'\n&evibcool flagevibcool=2 /\n', + 'zero_milestone': BASE+'\n&milestone mcadence=0 /\n', + 'negative_background_flux': BASE+'\n&precip_BG PhiWBG=-1 /\n', + 'zero_background_energy': BASE+'\n&precip_BG W0BG=0 /\n', + 'invalid_spectrum': BASE+'\n&fang_pars diff_num_flux=99 /\n', + 'invalid_kappa': BASE+'\n&fang_pars kappa=2 /\n', + 'nan_kappa': BASE+'\n&fang_pars kappa=NaN /\n', + 'missing_precip_dir': BASE+'\n&precip dtprec=60 /\n', + 'missing_efield_dir': BASE+'\n&efield dtE0=60 /\n', + 'missing_solar_dir': BASE+'\n&solflux dtsolflux=60 /\n', + 'missing_neutral_dir': BASE+'\n&neutralBG_file dtneuBGfile=60 /\n', + 'oversized_cadence': BASE+'\n&precip dtprec=86401, prec_dir="p" /\n', + 'nonfinite_neutral_cadence': BASE+'\n&neutral_BG flagneuBG=.true., dtneuBG=NaN /\n', + 'invalid_neutral_interpolation': BASE+'\n&neutral_perturb dtneu=60, source_dir="n", interptype=2 /\n', + 'invalid_source_latitude': BASE+'\n&neutral_perturb dtneu=60, source_dir="n", sourcemlat=91 /\n', + }) + for name, value in bad.items(): + f = tmp / (name + '.nml'); f.write_text(value) + run('config:' + name, 'audit_config', [f], False, lambda s: 'config:' in s or 'impossible' in s) + + payload = dict(schema='gemini.audit.native_probes.1', passed=all(r['passed'] for r in results), + count=len(results), results=results) + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(json.dumps(payload, indent=2) + '\n') + print(json.dumps({k:v for k,v in payload.items() if k != 'results'})) + for r in results: + if not r['passed']: + print('FAILED', r['name'], r['returncode'], (r['stdout'] + r['stderr'])[-600:]) + return 0 if payload['passed'] else 1 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/test/audit/sanity_probe.f90 b/test/audit/sanity_probe.f90 new file mode 100644 index 000000000..caabe7a9e --- /dev/null +++ b/test/audit/sanity_probe.f90 @@ -0,0 +1,41 @@ +! Audit addition 2026-09-16. Apache-2.0. +program audit_sanity +use phys_consts, only: wp +use sanity_check, only: check_finite_plasma, check_finite_output +use, intrinsic :: ieee_arithmetic, only: ieee_value, ieee_quiet_nan +implicit none +real(wp) :: ns(6,6,6,7), v1(6,6,6,7), v2(6,6,6,7), v3(6,6,6,7), ts(6,6,6,7) +real(wp) :: phi(6,6,6), j(6,6,6), nan +character(128) :: field, species_text, kind +character(2048) :: outdir +integer :: species +call get_command_argument(1,field); call get_command_argument(2,species_text) +call get_command_argument(3,kind); call get_command_argument(4,outdir) +read(species_text,*) species +nan=ieee_value(0._wp,ieee_quiet_nan) +ns=nan; v1=nan; ts=nan; phi=nan +ns(3:4,3:4,3:4,:)=1e11_wp; v1(3:4,3:4,3:4,:)=0; ts(3:4,3:4,3:4,:)=1000 +phi(3:4,3:4,3:4)=0; j=phi; v2=v1; v3=v1 +if (trim(kind)=='null_partition') ns(3:4,3:4,3:4,:)=1e-20_wp +if (trim(kind)=='nan') then + select case(trim(field)) + case('ns'); ns(3,3,3,species)=nan + case('v1'); v1(3,3,3,species)=nan + case('v2'); v2(3,3,3,species)=nan + case('v3'); v3(3,3,3,species)=nan + case('ts'); ts(3,3,3,species)=nan + end select +elseif (trim(kind)=='negative') then + if(trim(field)=='ts')then + ts(3,3,3,species)=-1 + else + ns(3,3,3,species)=-1 + endif +endif +if (trim(field)=='v2' .or. trim(field)=='v3') then + call check_finite_output(trim(outdir),0._wp,0,v2,v3,ns,v1,ts,phi,j,j,j) +else + call check_finite_plasma(trim(outdir),ns,v1,ts) +endif +print *, "ACCEPTED" +end program diff --git a/test/audit/test_calendar.py b/test/audit/test_calendar.py new file mode 100644 index 000000000..b88525e3c --- /dev/null +++ b/test/audit/test_calendar.py @@ -0,0 +1,28 @@ +"""Independent Gregorian calendar oracle for the compiled time utilities.""" +import argparse,datetime as d,json,math,subprocess +from pathlib import Path +p=argparse.ArgumentParser();p.add_argument('--exe',type=Path,required=True);p.add_argument('--output',type=Path,required=True) +a=p.parse_args();rows=[] +def args(t):return [t.year,t.month,t.day,(t-t.replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()] +def run(mode,values,expected=None): + r=subprocess.run([str(a.exe),mode,*map(str,values)],capture_output=True,text=True,timeout=5) + ok=r.returncode!=0 if expected is None else r.returncode==0 + if expected is not None and ok: + got=[float(x) for x in r.stdout.split()];ok=len(got)==len(expected) and all(math.isclose(x,y,abs_tol=1e-7,rel_tol=0) for x,y in zip(got,expected)) + rows.append({'mode':mode,'input':values,'passed':ok,'returncode':r.returncode}) +for start in [d.datetime(1999,12,31,23,59,45),d.datetime(2000,2,28,23,59),d.datetime(1900,2,28,23,59),d.datetime(2026,1,31,23,59,45),d.datetime(2026,9,16,0,0,30)]: + for seconds in [0,0.5,1,15,60,180,86400,3*86400+35]: + end=start+d.timedelta(seconds=seconds) + for cadence in [0.5,15,60,3600]: + offset=math.floor(seconds/cadence)*cadence + run('last',args(start)+args(end)+[cadence],args(start+d.timedelta(seconds=offset))) + run('elapsed',args(start)+args(end)+[cadence],[offset]) +for offset in [-172801,-86400,-60,-0.5,0,0.5,60,86400,172801]: + start=d.datetime(2000,3,1,0,0,30) + run('shift',args(start)+[offset],args(start+d.timedelta(seconds=offset))) +for cadence in [0,-1,'NaN',86401]:run('last',[2026,1,1,0,2026,1,2,0,cadence]) +run('last',[2026,2,30,0,2026,3,1,0,60]) +run('elapsed',[2026,1,2,0,2026,1,1,0,60]) +result={'count':len(rows),'passed':all(x['passed'] for x in rows),'cases':rows} +a.output.write_text(json.dumps(result,indent=2)+'\n');print(json.dumps({k:v for k,v in result.items() if k!='cases'})) +raise SystemExit(0 if result['passed'] else 1) diff --git a/test/audit/test_configuration.py b/test/audit/test_configuration.py new file mode 100644 index 000000000..95105909b --- /dev/null +++ b/test/audit/test_configuration.py @@ -0,0 +1,82 @@ +"""Check isolation and environment composition in the generated simulation tests.""" +import argparse +import json +from pathlib import Path +import subprocess +import tempfile + + +def properties(test): + return {prop["name"]: prop["value"] for prop in test.get("properties", [])} + + +def check_configuration(ctest, build, mpi_tmpdir, windows=False, config="Release"): + result = subprocess.run( + [ctest, "--test-dir", str(build), "-C", config, "--show-only=json-v1"], + check=True, capture_output=True, text=True, timeout=30, + ) + tests = {test["name"]: test for test in json.loads(result.stdout)["tests"]} + frontends = [name for name in tests if name.startswith("gemini_run:")] + assert frontends, "No simulation frontend tests registered" + for frontend_name in frontends: + case = frontend_name.split(":")[1] + frontend = tests[frontend_name] + native = tests[f"gemini:{case}"] + dryrun = tests[f"gemini:{case}:dryrun"] + copy = tests[f"{case}:copy_data_frontend"] + download = tests[f"{case}:download"] + for test in (copy, download): + command = test["command"] + assert Path(command[command.index("-P") + 1]).is_file(), test["name"] + copy_args = copy["command"] + frontend_dir = next(arg.removeprefix("-Doutdir:PATH=") for arg in copy_args + if arg.startswith("-Doutdir:PATH=")) + native_dir = next(arg.removeprefix("-Doutdir:PATH=") for arg in download["command"] + if arg.startswith("-Doutdir:PATH=")) + assert Path(frontend_dir) != Path(native_dir), case + assert frontend_dir in frontend["command"], case + assert native_dir in native["command"] and native_dir in dryrun["command"], case + assert properties(copy)["FIXTURES_REQUIRED"] == [f"{case}:download_fxt"], case + assert properties(copy)["FIXTURES_SETUP"] == [f"{case}:frontend_copy_fxt"], case + assert f"{case}:frontend_copy_fxt" in properties(frontend)["FIXTURES_REQUIRED"], case + assert set(properties(dryrun)["FIXTURES_REQUIRED"]) == { + f"{case}:download_fxt", "gemini_exe_fxt", + }, case + assert properties(native)["FIXTURES_REQUIRED"] == [f"{case}:dryrun"], case + + for test in (frontend, dryrun, native): + props = properties(test) + workdir = props["WORKING_DIRECTORY"] + environment = props["ENVIRONMENT_MODIFICATION"] + assert f"HWMPATH=set:{workdir}" in environment, test["name"] + if mpi_tmpdir: + assert f"TMPDIR=set:{mpi_tmpdir}" in environment, test["name"] + if windows: + assert any(value.startswith("PATH=path_list_prepend:") + for value in environment), test["name"] + assert props["RESOURCE_LOCK"] == ["cpu_mpi"], test["name"] + print(f"{case}: isolated frontend/native directories and preserved test environment") + + +def check_fixture(cmake, ctest): + with tempfile.TemporaryDirectory(prefix="gemini test configuration ") as work: + root = Path(work) + source = Path(__file__).resolve().parent / "configuration" + for windows in (False, True): + build = root / ("windows" if windows else "native") + mpi_tmpdir = root / "mpi tmp" + subprocess.run( + [cmake, "-S", str(source), "-B", str(build), + f"-Dmpi_tmpdir:PATH={mpi_tmpdir.as_posix()}", + f"-Dtest_windows:BOOL={'ON' if windows else 'OFF'}"], + check=True, capture_output=True, text=True, timeout=30, + ) + check_configuration(ctest, build, mpi_tmpdir.as_posix(), windows=windows) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--ctest", default="ctest") + parser.add_argument("--cmake", default="cmake") + args = parser.parse_args() + check_fixture(args.cmake, args.ctest) diff --git a/test/audit/test_filename_cadence.py b/test/audit/test_filename_cadence.py new file mode 100644 index 000000000..ff53d6efd --- /dev/null +++ b/test/audit/test_filename_cadence.py @@ -0,0 +1,44 @@ +"""Both configuration formats must reject filename cadences below 10 ms.""" +import argparse +from pathlib import Path +import subprocess + +from run_native_probes import BASE + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--exe", type=Path, required=True) + parser.add_argument("--work", type=Path, required=True) + args = parser.parse_args() + args.work.mkdir(parents=True, exist_ok=True) + cases = 0 + for cadence, accepted in (("0.001", False), ("0.009999", False), ("0.01", True), + ("0.015", True), ("60", True)): + groups = { + "dtout": BASE.replace("dtout=60", f"dtout={cadence}"), + "dtglowout": BASE + f"\n&glow dtglow=1,dtglowout={cadence} /\n", + "dtprec": BASE + f"\n&precip dtprec={cadence},prec_dir='p' /\n", + "dtE0": BASE + f"\n&efield dtE0={cadence},E0_dir='e' /\n", + "dtneu": BASE + f"\n&neutral_perturb dtneu={cadence},source_dir='n' /\n", + "dtsolflux": BASE + f"\n&solflux dtsolflux={cadence},solfluxdir='s' /\n", + "dtneuBGfile": BASE + f"\n&neutralBG_file dtneuBGfile={cadence},neutralBGdir='n' /\n", + } + # Deprecated INI still reaches the same cadence guard. + ini = ("20 2 2013\n18000\n300\n{dtout}\n100 100 4\n0.5\n1000\n1\n0\n1\n0\n" + "simsize.h5\nsimgrid.h5\ninitial.h5\n0\n0\n0\n{glow}\n") + groups["ini_dtout"] = ini.format(dtout=cadence, glow="0") + groups["ini_dtglowout"] = ini.format(dtout="60", glow=f"1\n1\n{cadence}") + for name, config in groups.items(): + path = args.work / (name + (".ini" if name.startswith("ini_") else ".nml")) + path.write_text(config) + result = subprocess.run([str(args.exe), str(path)], capture_output=True, text=True, timeout=10) + assert (result.returncode == 0) == accepted, (name, cadence, result.stdout, result.stderr) + if not accepted: + assert "filename cadence must be at least 0.01" in result.stderr, result.stderr + cases += 1 + print(f"{cases} namelist/INI filename cadence contracts passed") + + +if __name__ == "__main__": + main() diff --git a/test/audit/test_launcher_contract.py b/test/audit/test_launcher_contract.py new file mode 100644 index 000000000..7e7e39978 --- /dev/null +++ b/test/audit/test_launcher_contract.py @@ -0,0 +1,74 @@ +"""Exercise the real launcher without allowing the child to modify simulation output.""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import subprocess +import sys + +import h5py + +from run_native_probes import BASE + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--exe", type=Path, required=True) + parser.add_argument("--work", type=Path, required=True) + parser.add_argument("--numproc-flag", required=True) + args = parser.parse_args() + work = args.work.resolve() + work.mkdir(parents=True, exist_ok=True) + sim = work / "simulation's $data with spaces" + (sim / "inputs").mkdir(parents=True, exist_ok=True) + (sim / "inputs/config.nml").write_text(BASE) + with h5py.File(sim / "inputs/simsize.h5", "w") as handle: + for name, size in (("lx1", 8), ("lx2", 9), ("lx3", 6)): + handle[name] = size + for name in ("20130220_18000.000000.h5", "20130220_18060.000000.h5", "restart.h5"): + (sim / name).write_bytes(("pre-existing output " + name).encode()) + child = work / "child's $executable with spaces" + record = work / "argv.json" + child.write_text(f"#!{sys.executable}\nimport json,os,sys\n" + "from pathlib import Path\n" + "Path(os.environ['ARGV_RECORD']).write_text(json.dumps(sys.argv[1:]))\n" + "sys.exit(int(os.environ.get('CHILD_EXIT', '0')))\n") + child.chmod(0o755) + mpi = work / "MPI's launcher with spaces" + mpi.write_text(f"#!{sys.executable}\nimport subprocess,sys\n" + f"assert sys.argv[1:3] == [{args.numproc_flag!r}, '6'], sys.argv\n" + "sys.exit(subprocess.call(sys.argv[3:]))\n") + mpi.chmod(0o755) + + def hashes(): + return {str(path.relative_to(sim)): hashlib.sha256(path.read_bytes()).hexdigest() + for path in sim.rglob("*") if path.is_file()} + + before = hashes() + flag_cases = ([], ["-dryrun"], ["-plan"], ["-start_time", "2013", "2", "20", "18060"], + ["-end_time", "2013", "2", "20", "18120"], ["-manual_grid", "3", "2"], + # The child, not the shell, must receive and validate option values. + ["-manual_grid", "1 2", "3"], + ["-start_time", "2013", "2", "20", "18060 $value"], + ["-end_time", "2013", "2", "20", "18060's value"]) + for cpus in ("1", "6"): + env = dict(os.environ, GEMINI_CPU=cpus, ARGV_RECORD=str(record)) + for flags in flag_cases: + for child_exit in ("0", "7"): + if record.exists(): + record.unlink() + result = subprocess.run([str(args.exe), str(sim), "-exe", str(child), "-mpiexec", str(mpi), *flags], + env=dict(env, CHILD_EXIT=child_exit), capture_output=True, text=True, timeout=10) + assert hashes() == before, "launcher modified pre-existing output" + assert (result.returncode == 0) == ("-plan" in flags or child_exit == "0"), result.stderr + assert f'"Ncpu": {cpus}' in result.stdout, result.stdout + if "-plan" in flags: + assert not record.exists(), "planning launched the simulation" + else: + assert json.loads(record.read_text()) == [str(sim), *flags] + print(f"{4 * len(flag_cases)} launcher preservation, quoting, failure, planning and single-CPU contracts passed") + + +if __name__ == "__main__": + main() diff --git a/test/audit/time_probe.f90 b/test/audit/time_probe.f90 new file mode 100644 index 000000000..a6c42ccf4 --- /dev/null +++ b/test/audit/time_probe.f90 @@ -0,0 +1,30 @@ +program audit_time +use phys_consts, only: wp +use timeutils, only: find_lastdate,find_time_elapsed,shift_datetime +implicit none +character(40) :: mode,buf +integer :: a(3),b(3),out(3),i +real(wp) :: ua,ub,step,uout +call get_command_argument(1,mode) +do i=1,3 + call get_command_argument(i+1,buf);read(buf,*)a(i) +enddo +call get_command_argument(5,buf);read(buf,*)ua +if(trim(mode)=='shift')then + call get_command_argument(6,buf);read(buf,*)step + call shift_datetime(step,a,ua) + print *,a,ua +else + do i=1,3 + call get_command_argument(i+5,buf);read(buf,*)b(i) + enddo + call get_command_argument(9,buf);read(buf,*)ub + call get_command_argument(10,buf);read(buf,*)step + if(trim(mode)=='last')then + call find_lastdate(a,ua,b,ub,step,out,uout) + print *,out,uout + else + print *,find_time_elapsed(a,ua,b,ub,step) + endif +endif +end program diff --git a/test/compare/compare_in_h5.f90 b/test/compare/compare_in_h5.f90 index b858a8efa..dd6f406fa 100644 --- a/test/compare/compare_in_h5.f90 +++ b/test/compare/compare_in_h5.f90 @@ -1,3 +1,4 @@ +! Audit modification 2026-09-16: read the reference configuration from the reference tree submodule (compare_h5) compare_in_h5 implicit none (type, external) @@ -12,7 +13,7 @@ type(gemini_cfg) :: ref_cfg, cfg !> get input filename -ref_cfg%infile = new_path // '/inputs/config.nml' +ref_cfg%infile = ref_path // '/inputs/config.nml' ref_cfg%outdir = ref_path !< not used, just to pass checks call read_configfile(ref_cfg) if(.not. is_file(ref_cfg%indatfile)) error stop "compare: ref initcond file not found: " // ref_cfg%indatfile diff --git a/test/compare/compare_out_h5.f90 b/test/compare/compare_out_h5.f90 index 6ab34a577..bfe288730 100644 --- a/test/compare/compare_out_h5.f90 +++ b/test/compare/compare_out_h5.f90 @@ -1,3 +1,4 @@ +! Audit modification 2026-09-16: honor the requested species index submodule (compare_h5) compare_out_h5 implicit none (type, external) @@ -54,6 +55,7 @@ logical function check_out(cfg, new_file, ref_file, lx1, lx2all, lx3all, P) type(hdf5_file) :: hnew, href integer :: i, bad +character(32) :: species_name character(7), parameter :: varsT(2) = [character(7) :: 'Tavgall', 'TEall'] character(8), parameter :: varsV(3) = ['v1avgall', 'v2avgall', 'v3avgall'] @@ -110,11 +112,19 @@ logical function check_out(cfg, new_file, ref_file, lx1, lx2all, lx3all, P) bad = bad + check_var(varsV(i), hnew, href, rtolV, atolV, lx1, lx2all, lx3all, P) enddo - !> Ne - bad = bad + check_var('nsall', hnew, href, rtolN, atolN, lx1, lx2all, lx3all, P, ionly=lsp, derived_name="ne") - - !> Te - bad = bad + check_var('Tsall', hnew, href, rtolT, atolT, lx1, lx2all, lx3all, P, ionly=lsp, derived_name="Te") + ! Audit correction: full output must compare all saved species, not just + ! electrons and density-weighted averages. Existing field tolerances remain. + do i=1,lsp + write(species_name,'(A,I0)') 'ns_species_',i + bad = bad + check_var('nsall', hnew, href, rtolN, atolN, lx1, lx2all, lx3all, P, & + ionly=i, derived_name=trim(species_name)) + write(species_name,'(A,I0)') 'Ts_species_',i + bad = bad + check_var('Tsall', hnew, href, rtolT, atolT, lx1, lx2all, lx3all, P, & + ionly=i, derived_name=trim(species_name)) + write(species_name,'(A,I0)') 'vs1_species_',i + bad = bad + check_var('vs1all', hnew, href, rtolV, atolV, lx1, lx2all, lx3all, P, & + ionly=i, derived_name=trim(species_name)) + enddo !> Ti bad = bad + check_derived('Tsall', "Ti", hnew, href, rtolT, atolT, lx1, lx2all, lx3all, P) @@ -200,8 +210,9 @@ integer function check_var(name, hnew, href, rtol, atol, lx1, lx2all, lx3all, P, call hnew%read(name, new4) call href%read(name, ref4) - new = new4(:,:,:,lsp) - ref = ref4(:,:,:,lsp) + if (ionly < 1 .or. ionly > lsp) error stop "compare: species index out of range" + new = new4(:,:,:,ionly) + ref = ref4(:,:,:,ionly) else call hnew%read(name, new) call href%read(name, ref) diff --git a/test/config.cmake b/test/config.cmake index ba0aef1f9..b55aff45e 100644 --- a/test/config.cmake +++ b/test/config.cmake @@ -1,3 +1,8 @@ +# Audit modification 2026-09-16: correct MPI test worker count and fail if required reference tests cannot be registered +set(gemini3d_test_run_root "${PROJECT_BINARY_DIR}/test_runs" CACHE PATH "Isolated native test output directory") +if(NOT IS_ABSOLUTE "${gemini3d_test_run_root}") + message(FATAL_ERROR "gemini3d_test_run_root must be absolute") +endif() function(gcd a b out_var) if(a LESS 1 OR b LESS 1) message(FATAL_ERROR "gcd: positive integers only") @@ -35,96 +40,50 @@ endfunction() function(max_gcd2 lx2 lx3 M out_var) -## find (d2,d3) with d2|lx2, d3|lx3, d2*d3<=M that maximises d2*d3, -## breaking ties by minimising |d2-d3| +## Factor original dimensions, retaining at least two cells per non-singleton axis. +## return the worker count; process-grid factor selection happens in the solver if(M LESS 1) message(FATAL_ERROR "max_gcd2: CPU count must be at least one") endif() +if(lx2 LESS 1 OR lx3 LESS 1) + message(FATAL_ERROR "max_gcd2: grid dimensions must be positive") +endif() set(best 1) -set(t2 1) -set(t3 2147483647) - -# foreach(RANGE) requires non-negative stop; guard and use index trick for -# reverse iteration (CMake RANGE step must be positive until 3.27) -math(EXPR irng "${M} - 2") -math(EXPR jrng "${M} - 2") - -foreach(_ki RANGE 0 ${irng}) - math(EXPR i "${M} - ${_ki}") - - set(_next_i false) - foreach(_kj RANGE 0 ${jrng}) - math(EXPR j "${M} - ${_kj}") - - max_gcd(${lx2} ${i} f2) - max_gcd(${lx3} ${j} f3) - math(EXPR _prod "${f2} * ${f3}") - - if(_prod GREATER ${M}) - continue() # cycle x3 - elseif(_prod LESS best) - break() # exit x3 - endif() - - math(EXPR q2 "${lx2} / ${i}") - if(q2 EQUAL 1) - set(_next_i true) - break() # cycle x2 - endif() - - math(EXPR q3 "${lx3} / ${j}") - if(q3 EQUAL 1) - continue() # cycle x3 - endif() - - math(EXPR df "${f2} - ${f3}") - if(df LESS 0) - math(EXPR _adf "${df} * -1") - else() - set(_adf ${df}) - endif() - math(EXPR dt "${t2} - ${t3}") - if(dt LESS 0) - math(EXPR _adt "${dt} * -1") - else() - set(_adt ${dt}) - endif() - if(_adf GREATER _adt) - continue() # cycle x3 - endif() - - set(t2 ${f2}) - set(t3 ${f3}) - set(best ${_prod}) - endforeach() - - if(_next_i) - continue() # cycle x2 +math(EXPR limit "${lx2} / 2") +if(limit LESS 1) + set(limit 1) +endif() +if(M LESS limit) + set(limit ${M}) +endif() +math(EXPR limit3 "${lx3} / 2") +if(limit3 LESS 1) + set(limit3 1) +endif() +foreach(d2 RANGE 1 ${limit}) + math(EXPR remainder "${lx2} % ${d2}") + if(NOT remainder EQUAL 0) + continue() endif() - - math(EXPR _i_M "${i} * ${M}") - if(_i_M LESS best) - break() # exit x2 + math(EXPR budget "${M} / ${d2}") + if(limit3 LESS budget) + set(budget ${limit3}) + endif() + max_gcd(${lx3} ${budget} d3) + math(EXPR candidate "${d2} * ${d3}") + if(candidate GREATER best) + set(best ${candidate}) endif() endforeach() - set(${out_var} ${best} PARENT_SCOPE) + endfunction() function(max_mpi lx2 lx3 max_cpu out_var) ## return max useful MPI worker count for an lx2 x lx3 simulation grid -math(EXPR _lx2h "${lx2} / 2") -math(EXPR _lx3h "${lx3} / 2") - -if(lx3 EQUAL 1) - max_gcd(${_lx2h} ${max_cpu} _n) -elseif(lx2 EQUAL 1) - max_gcd(${_lx3h} ${max_cpu} _n) -else() - max_gcd2(${_lx2h} ${_lx3h} ${max_cpu} _n) -endif() +max_gcd2(${lx2} ${lx3} ${max_cpu} _n) set(${out_var} ${_n} PARENT_SCOPE) endfunction() @@ -139,7 +98,7 @@ if(name MATCHES "_cpp$" AND NOT TARGET gemini_c.bin) endif() # --- setup test -set(out_dir ${PROJECT_BINARY_DIR}/${name}) +set(out_dir ${gemini3d_test_run_root}/${name}) # used for gemini.bin tests set(out_dir_frontend ${PROJECT_BINARY_DIR}/test_frontend/${name}) @@ -147,23 +106,9 @@ set(out_dir_frontend ${PROJECT_BINARY_DIR}/test_frontend/${name}) set(ref_root ${PROJECT_BINARY_DIR}/test_data/compare) set(ref_dir ${ref_root}/${name}) -set(arc_json_file ${PROJECT_BINARY_DIR}/ref_data.json) - -# --- download reference data JSON file (for previously generated data) -if(NOT EXISTS ${arc_json_file}) - file(READ ${CMAKE_CURRENT_LIST_DIR}/test_urls.json _libj) - - string(JSON url GET ${_libj} ref_data url) - - file(DOWNLOAD ${url} ${arc_json_file} STATUS ret LOG log) - - list(GET ret 0 stat) - if(NOT stat EQUAL 0) - list(GET ret 1 err) - message(WARNING "${url} download failed: ${err} - ${log}") - return() - endif() +set(arc_json_file ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ref_data_snapshot.json) +if(NOT EXISTS "${arc_json_file}") + message(FATAL_ERROR "Required pinned reference manifest is missing: ${arc_json_file}") endif() # --- compute proper number of MPI workers for this test @@ -172,19 +117,19 @@ file(READ ${arc_json_file} _refj) get_url_name(${name} url_name) -string(JSON Nlx ERROR_VARIABLE _err LENGTH ${_refj} tests ${url_name} lx) +string(JSON Nlx ERROR_VARIABLE _err LENGTH "${_refj}" tests ${url_name} lx) if(_err) - message(WARNING "test ${name} missing lx in ${arc_json_file}: ${_err}") + message(FATAL_ERROR "test ${name} missing lx in ${arc_json_file}: ${_err}") return() endif() if(NOT Nlx EQUAL 3) - message(WARNING "test ${name} has lx=${Nlx} in ${arc_json_file}, expected 3") + message(FATAL_ERROR "test ${name} has lx=${Nlx} in ${arc_json_file}, expected 3") return() endif() -string(JSON lx1 GET ${_refj} tests ${url_name} lx 0) -string(JSON lx2 GET ${_refj} tests ${url_name} lx 1) -string(JSON lx3 GET ${_refj} tests ${url_name} lx 2) +string(JSON lx1 GET "${_refj}" tests ${url_name} lx 0) +string(JSON lx2 GET "${_refj}" tests ${url_name} lx 1) +string(JSON lx3 GET "${_refj}" tests ${url_name} lx 2) max_mpi(${lx2} ${lx3} ${MPIEXEC_MAX_NUMPROCS} Nworker) @@ -198,6 +143,8 @@ COMMAND ${CMAKE_COMMAND} -Doutdir:PATH=${out_dir} -Drefroot:PATH=${ref_root} -Darc_json_file:FILEPATH=${arc_json_file} + -Dreset_test_outputs=ON + -Dtest_binary_dir:PATH=${gemini3d_test_run_root} -P ${CMAKE_CURRENT_LIST_DIR}/download.cmake ) set_tests_properties(${name}:download PROPERTIES @@ -227,12 +174,14 @@ else() endif() add_test(NAME gemini_run:${name}:dryrun COMMAND ${test_cmd} -dryrun) +test_mpi_props(gemini_run:${name}:dryrun ${Nworker}) set_tests_properties(gemini_run:${name}:dryrun PROPERTIES FIXTURES_REQUIRED "gemini_exe_fxt;${name}:frontend_copy_fxt" +RESOURCE_LOCK cpu_mpi WORKING_DIRECTORY $ -ENVIRONMENT_MODIFICATION "HWMPATH=set:$" -PROCESSORS ${Nworker} ) +set_property(TEST gemini_run:${name}:dryrun APPEND PROPERTY +ENVIRONMENT_MODIFICATION "HWMPATH=set:$") # MSIS2 requires WORKING_DIRECTORY. HWM14 uses HWMPATH, which can be distinct hdf5_dll(gemini_run:${name}:dryrun) @@ -253,8 +202,9 @@ set_tests_properties(gemini:${name}:dryrun PROPERTIES FIXTURES_SETUP ${name}:dryrun FIXTURES_REQUIRED "gemini_exe_fxt;${name}:download_fxt" WORKING_DIRECTORY $ -ENVIRONMENT_MODIFICATION "HWMPATH=set:$" ) +set_property(TEST gemini:${name}:dryrun APPEND PROPERTY +ENVIRONMENT_MODIFICATION "HWMPATH=set:$") # MSIS2 requires WORKING_DIRECTORY. HWM14 uses HWMPATH, which can be distinct hdf5_dll(gemini:${name}:dryrun) @@ -267,8 +217,9 @@ set_tests_properties(gemini:${name} PROPERTIES FIXTURES_REQUIRED ${name}:dryrun FIXTURES_SETUP ${name}:run_fxt WORKING_DIRECTORY $ -ENVIRONMENT_MODIFICATION "HWMPATH=set:$" ) +set_property(TEST gemini:${name} APPEND PROPERTY +ENVIRONMENT_MODIFICATION "HWMPATH=set:$") # MSIS2 requires WORKING_DIRECTORY. HWM14 uses HWMPATH, which can be distinct hdf5_dll(gemini:${name}) set_tests_properties(gemini:${name}:dryrun gemini:${name} PROPERTIES @@ -287,7 +238,7 @@ endfunction() function(setup_magcalc_test name) -set(out_dir ${PROJECT_BINARY_DIR}/${name}) +set(out_dir ${gemini3d_test_run_root}/${name}) add_test(NAME magcalc:${name}:setup COMMAND ${Python_EXECUTABLE} -m gemini3d.magcalc ${out_dir} diff --git a/test/config/config_example.nml b/test/config/config_example.nml index c035a6cd5..486135d56 100644 --- a/test/config/config_example.nml +++ b/test/config/config_example.nml @@ -1,3 +1,4 @@ +! Audit modification 2026-09-16: clarify implemented potential modes. &base ymd = 2013,2,20 ! year, month, day UTsec0 = 18000.0 ! start time in UT seconds @@ -9,7 +10,7 @@ Teinf = 1500.0 ! exospheric electron temperature / &flags -potsolve = 1 ! solve electrodynamics: 0 - no; 1 - electrostatic; 2 - inductive +potsolve = 1 ! solve electrodynamics: 0 - disturbance off; 1 - field-integrated; 3 - field-resolved; 2 - unsupported flagoutput = 2 / diff --git a/test/download.cmake b/test/download.cmake index 98ffcb8e7..ee51df890 100644 --- a/test/download.cmake +++ b/test/download.cmake @@ -1,8 +1,13 @@ +# Audit modification 2026-09-16: offline tests must not silently fetch missing archives cmake_minimum_required(VERSION 3.19) # string(JSON) requires CMake 3.19 function(download_archive url archive exp_hash) +if("$ENV{GEMINI3D_OFFLINE}" STREQUAL "1") + message(FATAL_ERROR "Offline mode: verified archive is missing or corrupt: ${archive}. Run the download preset online first.") +endif() + message(STATUS "DOWNLOAD: ${url} => ${archive} sha256: ${exp_hash}") file(DOWNLOAD ${url} ${archive} STATUS ret LOG log @@ -26,9 +31,9 @@ file(READ ${arc_json_file} _refj) get_url_name(${name} url_name) -string(JSON url GET ${_refj} tests ${url_name} url) -string(JSON archive_name GET ${_refj} tests ${url_name} archive) -string(JSON hash GET ${_refj} tests ${url_name} sha256) +string(JSON url GET "${_refj}" tests ${url_name} url) +string(JSON archive_name GET "${_refj}" tests ${url_name} archive) +string(JSON hash GET "${_refj}" tests ${url_name} sha256) set(archive ${refroot}/${archive_name}) @@ -77,3 +82,18 @@ gemini_download_ref_data(${name} ${refroot} ${arc_json_file}) # copy sim inputs into sim output directory file(COPY ${ref_dir}/inputs DESTINATION ${outdir}) + +# Audit correction 2026-09-16: CTest cases must start from the pinned ICs, +# including on rerun. Never remove reference data or arbitrary user outputs. +if(reset_test_outputs) + if(NOT name MATCHES "^mini[0-9A-Za-z_]+$" OR NOT DEFINED test_binary_dir + OR NOT outdir STREQUAL "${test_binary_dir}/${name}") + message(FATAL_ERROR "Refusing to reset outputs outside the named CTest case directory") + endif() + file(GLOB old_test_frames "${outdir}/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_*.h5") + list(LENGTH old_test_frames old_test_frame_count) + message(STATUS "Resetting ${old_test_frame_count} dated CTest frames in ${outdir}") + if(old_test_frames) + file(REMOVE ${old_test_frames}) + endif() +endif() diff --git a/test/hdf5_dll.cmake b/test/hdf5_dll.cmake new file mode 100644 index 000000000..d60d59c9f --- /dev/null +++ b/test/hdf5_dll.cmake @@ -0,0 +1,18 @@ +function(hdf5_dll test) + +if(WIN32) + set(_h5fortran_dll_mdir "PATH=path_list_prepend:${CMAKE_INSTALL_FULL_BINDIR};PATH=path_list_prepend:${PROJECT_BINARY_DIR}") + FetchContent_GetProperties(hdf5_zlib) + if(IS_DIRECTORY "${hdf5_zlib_BINARY_DIR}") + string(APPEND _h5fortran_dll_mdir ";PATH=path_list_prepend:${hdf5_zlib_BINARY_DIR}") + endif() + if(IS_DIRECTORY "${CMAKE_PREFIX_PATH}/bin") + string(APPEND _h5fortran_dll_mdir ";PATH=path_list_prepend:${CMAKE_PREFIX_PATH}/bin") + endif() + if(IS_DIRECTORY "${ZLIB_INCLUDE_DIRS}/../bin") + string(APPEND _h5fortran_dll_mdir ";PATH=path_list_prepend:${ZLIB_INCLUDE_DIRS}/../bin") + endif() + set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT_MODIFICATION "${_h5fortran_dll_mdir}") +endif() + +endfunction() diff --git a/test/mpi_launcher.cmake b/test/mpi_launcher.cmake index 8f386feb3..cdfe4b30f 100644 --- a/test/mpi_launcher.cmake +++ b/test/mpi_launcher.cmake @@ -27,7 +27,7 @@ function(test_mpi_props test Nworker) set_property(TEST ${test} PROPERTY PROCESSORS ${Nworker}) if(DEFINED mpi_tmpdir) - set_property(TEST ${test} PROPERTY ENVIRONMENT_MODIFICATION "TMPDIR=set:${mpi_tmpdir}") + set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT_MODIFICATION "TMPDIR=set:${mpi_tmpdir}") endif() endfunction() diff --git a/test/potential/plot_potential2d_aurora.py b/test/potential/plot_potential2d_aurora.py new file mode 100644 index 000000000..129a825bb --- /dev/null +++ b/test/potential/plot_potential2d_aurora.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +""" +Created on Mon Apr 20 18:13:14 2026 + +@author: zettergm +""" + +import argparse +import numpy as np +import h5py + +from matplotlib.pyplot import figure,pcolormesh,xlabel,ylabel,title,colorbar + + +def read_potential(fn) -> dict: + with h5py.File(fn, "r") as f: + out = {"lx1": f["/lx1"][()], + "lx2": f["/lx2"][()], + "lx3": f["/lx3"][()], + "x1": f["/x1"][:], + "x2": f["/x2"][:], + "x3": f["/x3"][:], + "Phi": f["/Phi"][:], + "A": f["/A"][:], + "Ap": f["/Ap"][:], + "SigH": f["/SigH"][:], + "B": f["/B"][:], + "C": f["/C"][:], + "srcterm": f["/srcterm"][:]} + + assert out["lx1"] == out["x1"].size + assert out["lx2"] == out["x2"].size + assert out["lx3"] == out["x3"].size + + return out + + +def plot_potential(data): + + x2 = data["x2"] + x3 = data["x3"] + Phi = data["Phi"] + srcterm = data["srcterm"] + + figure(figsize=(6, 6)) + pcolormesh(x2, x3, Phi) + colorbar() + ylabel("distance [m]") + xlabel("distance [m]") + title("2D potential (numerical)") + + #figure() + #pcolormesh(x2,x3,data["A"]) + #colorbar() + #title("Pedersen") + + figure() + pcolormesh(x2,x3,data["Ap"]) + colorbar() + title("Ap") + + # figure() + # pcolormesh(x2,x3,data["SigH"]) + # colorbar() + + # figure() + # pcolormesh(x2,x3,data["B"]) + # colorbar() + + # figure() + # pcolormesh(x2,x3,data["C"]) + # colorbar() + + figure() + pcolormesh(x2,x3,srcterm) # srcterm is -Jpar + colorbar() + title("Jpar") + + ## Apparently hdf5 mangles array axes??? + Ex,Ey = np.gradient(-1*Phi.transpose(),x2,x3) # WHYYYYY + SigP=data["A"].transpose() + SigH=data["SigH"].transpose() + Jx=SigP*Ex-SigH*Ey + Jy=SigH*Ex+SigP*Ey + Jxx,_ = np.gradient(Jx,x2,x3) + _,Jyy = np.gradient(Jy,x2,x3) + divJ=Jxx+Jyy + Jpartest=-divJ + errterm=Jpartest-srcterm + print("Max error in Jpar:", np.max(np.abs(errterm))) + + figure() + pcolormesh(x2,x3,Ex.transpose()) + colorbar() + title("Ex") + + figure() + pcolormesh(x2,x3,Ey.transpose()) + colorbar() + title("Ey") + + figure() + pcolormesh(x2,x3,Jx.transpose()) + colorbar() + title("Jx") + + figure() + pcolormesh(x2,x3,Jy.transpose()) + colorbar() + title("Jy") + + figure() + pcolormesh(x2,x3,Jpartest.transpose()) + colorbar() + title("div J") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("fn", help="HDF5 file containing potential data") + parser.add_argument("--noplot", action="store_true", help="Do not display plots") + args = parser.parse_args() + fn = args.fn + + data = read_potential(fn) + if not args.noplot: + plot_potential(data) diff --git a/test/potential/test_potential2d_auroral.py b/test/potential/test_potential2d_auroral.py deleted file mode 100644 index 954a864b6..000000000 --- a/test/potential/test_potential2d_auroral.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Mon Apr 20 18:13:14 2026 - -@author: zettergm -""" - -#!/usr/bin/env python3 -#from pathlib import Path -#import argparse -import sys -import typing - -import numpy as np -import h5py - -from matplotlib.pyplot import figure,pcolormesh,xlabel,ylabel,title,colorbar - -fn = "/Users/zettergm/Projects/gemini3d/build/test/potential/output.h5" -doplot = True - -# if not fn.is_file(): -# print(fn, "not found", file=sys.stderr) -# raise SystemExit(77) - -with h5py.File(fn, "r") as f: - lx1 = f["/lx1"][()] - lx2 = f["/lx2"][()] - lx3 = f["/lx3"][()] - x1 = f["/x1"][:] - x2 = f["/x2"][:] - x3 = f["/x3"][:] - Phi = f["/Phi"][:] - A = f["/A"][:] - Ap = f["/Ap"][:] - SigH = f["/SigH"][:] - B = f["/B"][:] - C = f["/C"][:] - srcterm = f["/srcterm"][:] -assert lx1 == x1.size -assert lx2 == x2.size -assert lx3 == x3.size - -if not doplot: - exit - -fg = figure(figsize=(6, 6)) -h = pcolormesh(x2, x3, Phi) -colorbar() -ylabel("distance [m]") -xlabel("distance [m]") -title("2D potential (numerical)") - -#figure() -#pcolormesh(x2,x3,A) -#colorbar() -#title("Pedersen") - -# figure() -# pcolormesh(x2,x3,Ap) -# colorbar() - -# figure() -# pcolormesh(x2,x3,SigH) -# colorbar() - -# figure() -# pcolormesh(x2,x3,B) -# colorbar() - -# figure() -# pcolormesh(x2,x3,C) -# colorbar() - -figure() -pcolormesh(x2,x3,srcterm) # srcterm is -Jpar -colorbar() -title("Jpar") - -## Apparently hdf5 mangles array axes??? -Ex,Ey = np.gradient(-1*Phi.transpose(),x2,x3) # WHYYYYY -SigP=A.transpose() -SigH=SigH.transpose() -Jx=SigP*Ex-SigH*Ey -Jy=SigH*Ex+SigP*Ey -Jxx,_ = np.gradient(Jx,x2,x3) -_,Jyy = np.gradient(Jy,x2,x3) -divJ=Jxx+Jyy -Jpartest=-divJ -errterm=Jpartest-srcterm - -figure() -pcolormesh(x2,x3,Ex.transpose()) -colorbar() -title("Ex") - -figure() -pcolormesh(x2,x3,Ey.transpose()) -colorbar() -title("Ey") - -figure() -pcolormesh(x2,x3,Jx.transpose()) -colorbar() -title("Jx") - -figure() -pcolormesh(x2,x3,Jy.transpose()) -colorbar() -title("Jy") - -figure() -pcolormesh(x2,x3,Jpartest.transpose()) -colorbar() -title("div J") diff --git a/test/qualification/analyze_midpoint_diffusion.py b/test/qualification/analyze_midpoint_diffusion.py new file mode 100644 index 000000000..d8acd7121 --- /dev/null +++ b/test/qualification/analyze_midpoint_diffusion.py @@ -0,0 +1,147 @@ +"""Independent conservative balances and theoretical observables for native probes.""" +import argparse +import csv +import hashlib +import json +from pathlib import Path +import numpy as np +from scipy.integrate import solve_ivp +from scipy.linalg import solve_banded + +p=argparse.ArgumentParser() +p.add_argument('--work', type=Path, required=True) +p.add_argument('--trace', type=Path) +p.add_argument('--candidate',required=True) +a=p.parse_args() +w=a.work +LIMIT=1e-11 +def rows(path): + with path.open() as f: + return [{k:float(v) for k,v in r.items()} for r in csv.DictReader(f)] +def norm_res(terms): + return abs(sum(terms))/max(sum(abs(x) for x in terms), np.finfo(float).tiny) +def orders(errors): + return [float(np.log2(errors[i]/errors[i+1])) for i in range(2)] + +conduct=[] +traces={} +if a.trace: + native_trace=np.loadtxt(a.trace,delimiter=',') + offset=0 + for path in sorted(w.glob('conduction_*_m[23]_*.csv')): + rs=rows(path);nodes=int(max(r['node'] for r in rs));steps=int(max(r['step'] for r in rs)) + count=steps*nodes + traces[path.name]=native_trace[offset:offset+count].reshape(steps,nodes,4) + offset+=count + assert offset==len(native_trace) +oracle_cache={} +for path in sorted(w.glob('conduction_*.csv')): + data=rows(path) + n=int(max(r['node'] for r in data));steps=int(max(r['step'] for r in data));r=data[0] + dt,dx,cv=r['dt'],r['dx'],r['Cv'] + window=int(path.stem.split('_w')[1][0]);method=int(path.stem.split('_m')[1][0]);level=int(path.stem.split('_l')[1][0]) + density=r['ns'];total=dt*steps + initial=np.linspace(600.,1500.,n) + scale=density/1e5 + # Density scaling uses tau=t/scale so both cases independently share the + # same mathematically defined problem; retain each physical native result. + key=(n,window,total/scale) + if key not in oracle_cache: + def rhs(t, interior): + temp=np.r_[600.,interior,1500.] + lam=.3986e-12*temp**2.5 + flux=-.5*(lam[:-1]+lam[1:])*np.diff(temp)/dx + return -(flux[1:]-flux[:-1])/(cv/scale*dx) + sol=solve_ivp(rhs,[0.,total/scale],initial[1:-1],method='Radau',rtol=1e-11,atol=1e-9) + tight=solve_ivp(rhs,[0.,total/scale],initial[1:-1],method='Radau',rtol=2e-13,atol=2e-11) + if not sol.success or not tight.success: + raise RuntimeError('Independent MOL oracle failed: '+sol.message+' / '+tight.message) + reference=np.r_[600.,tight.y[:,-1],1500.] + control=float(np.linalg.norm(sol.y[:,-1]-tight.y[:,-1])/np.linalg.norm(tight.y[:,-1])) + oracle_cache[key]={'temperature_K':reference,'control_relative_rms':control, + 'nfev':int(tight.nfev),'njev':int(tight.njev)} + oracle=oracle_cache[key] + step_balances=[];telescoping=[];diagnostic_balances=[];stage_mismatches=[];floors=0 + for it in range(1,steps+1): + rs=[r for r in data if r['step']==it] + old=np.array([r['Told'] for r in rs]);new=np.array([r['Tnew'] for r in rs]);raw=np.array([r['Traw'] for r in rs]) + lam=np.array([r['lambda_applied'] if 'lambda_applied' in r else r['lambda_old'] for r in rs]);face=.5*(lam[:-1]+lam[1:]) + alpha=face/(cv*dx**2) + def flux(temp):return -face*np.diff(temp)/dx + if method==1: + integrated=dt*flux(raw) + else: + # Independent tridiagonal Crank-Nicolson half-stage for native + # TR-BDF2 (frozen lambda). No native residual is used as heat input. + c=dt/4 + band=np.zeros((3,n-2));diagonal=alpha[:-1]+alpha[1:] + band[1]=1+c*diagonal + band[0,1:]=-c*alpha[1:-1];band[2,:-1]=-c*alpha[1:-1] + old_rhs=old[1:-1]+c*(alpha[1:]*np.diff(old)[1:]-alpha[:-1]*np.diff(old)[:-1]) + old_rhs[0]+=c*alpha[0]*600;old_rhs[-1]+=c*alpha[-1]*1500 + tr=np.r_[600.,solve_banded((1,1),band,old_rhs),1500.] + if path.name in traces: + native=traces[path.name][it-1] + assert np.array_equal(native[:,1],old) and np.array_equal(native[:,3],raw) + independent_tr=tr + tr=native[:,2] + stage_mismatches.append(float(np.max(abs(independent_tr-tr))/np.max(abs(tr)))) + integrated=dt/3*(flux(old)+flux(tr)+flux(raw)) + derived=(4*tr[1:-1]-old[1:-1])/3+dt/3*(alpha[1:]*np.diff(raw)[1:]-alpha[:-1]*np.diff(raw)[:-1]) + stage_mismatches.append(float(np.max(abs(derived-raw[1:-1]))/np.max(abs(raw)))) + change=float(cv*dx*np.sum(raw[1:-1]-old[1:-1])) + incoming=float(integrated[0]-integrated[-1]) + power_cells=-(integrated[1:]-integrated[:-1]) + scale_balance=max(float(np.sum(abs(cv*dx*(raw[1:-1]-old[1:-1])))), + float(np.sum(abs(power_cells))),abs(integrated[0])+abs(integrated[-1]),np.finfo(float).tiny) + step_balances.append(abs(change-incoming)/scale_balance) + telescoping.append(abs(np.sum(power_cells)-incoming)/scale_balance) + inc=np.array([[r[k] for k in ('reaction','drift','conduction','source','reservoir')] for r in rs]) + diagnostic_balances.append(float(np.max(abs(raw-old-np.sum(inc,axis=1)))/max(np.max(abs(raw-old)),np.finfo(float).tiny))) + floors+=int(np.count_nonzero(new!=raw)) + final=np.array([r['Tnew'] for r in data if r['step']==steps]) + error=float(np.linalg.norm(final[1:-1]-oracle['temperature_K'][1:-1])/np.linalg.norm(oracle['temperature_K'][1:-1])) + entry={'file':path.name,'density_m3':density,'window':window,'method':method,'level':level, + 'steps':steps,'dt_s':dt,'duration_s':total,'temperature_relative_rms':error, + 'oracle_control_relative_rms':oracle['control_relative_rms'], + 'maximum_energy_balance_normalized':max(step_balances), + 'maximum_face_telescoping_normalized':max(telescoping), + 'maximum_diagnostic_increment_relative':max(diagnostic_balances), + 'maximum_independent_TR_stage_relative':max(stage_mismatches,default=0), + 'native_stage_trace_used':method==1 or path.name in traces, + 'fixed_boundary_max_error_K':max(abs(r['Traw']-(600 if r['node']==1 else 1500)) for r in data if r['node'] in (1,n)), + 'floor_cell_events':floors,'temperature_K':final.tolist(), + 'oracle_temperature_K':oracle['temperature_K'].tolist(), + 'energy_pass':max(step_balances)<=LIMIT,'temperature_pass':error<=.1} + conduct.append(entry) +groups=[] +for density,window,method in sorted(set((r['density_m3'],r['window'],r['method']) for r in conduct)): + levels=sorted([r for r in conduct if (r['density_m3'],r['window'],r['method'])==(density,window,method)],key=lambda r:r['level']) + os=orders([r['temperature_relative_rms'] for r in levels]) + minorder=.9 if method==1 else 1.8 + groups.append({'density_m3':density,'window':window,'method':method,'errors':[r['temperature_relative_rms'] for r in levels], + 'orders':os,'required_order':minorder, + 'energy_pass':all(r['energy_pass'] for r in levels), + 'temperature_pass':all(r['temperature_pass'] for r in levels), + 'order_pass':min(os)>=minorder}) +pc03={'cases':conduct,'groups':groups,'passed':all(r['energy_pass'] and r['temperature_pass'] and r['order_pass'] for r in groups)} + +kir=rows(w/'kirchhoff_flux.csv');steady=[] +qexact=-.3986e-12*(1500.**3.5-600.**3.5)/(3.5*1e5) +for level in range(3): + rs=[r for r in kir if r['level']==level] + temp=np.array([r['T'] for r in rs]);lam=np.array([r['lambda'] for r in rs]);dx=rs[0]['dx'] + q=-.5*(lam[:-1]+lam[1:])*np.diff(temp)/dx + err=float(np.sqrt(np.mean((q-qexact)**2))/abs(qexact)) + steady.append({'level':level,'nodes':len(rs),'dx_m':dx,'exact_flux_Wm2':qexact, + 'relative_l2_face_flux_error':err,'minimum_flux_Wm2':float(min(q)),'maximum_flux_Wm2':float(max(q))}) +pc04={'levels':steady,'orders':orders([r['relative_l2_face_flux_error'] for r in steady])} +pc04['passed']=min(pc04['orders'])>=1.8 +result={'schema':'gemini.physical.closure.results.1','budget':LIMIT, + 'native_source_revision':a.candidate, + 'PC03':pc03,'PC04':pc04, 'passed':pc03['passed'] and pc04['passed']} +(w/'physics-results.json').write_text(json.dumps(result,indent=2,allow_nan=False,default=lambda v:v.item() if isinstance(v,np.generic) else str(v))+'\n') +print(json.dumps({k:{s:v for s,v in result[k].items() if s in ('passed','case_count','passing_cases','orders','groups')} + for k in ('PC03','PC04')},indent=2)) + +raise SystemExit(0 if result['passed'] else 1) diff --git a/test/qualification/atomic_probe.f90 b/test/qualification/atomic_probe.f90 new file mode 100644 index 000000000..839724379 --- /dev/null +++ b/test/qualification/atomic_probe.f90 @@ -0,0 +1,18 @@ +program atomic_probe +use atomic_file, only: stage_file,publish_file +implicit none(type,external) +character(4096) :: directory,mode +character(:), allocatable :: temporary,final +integer :: u +call get_command_argument(1,directory) +call get_command_argument(2,mode) +final=trim(directory)//'/checkpoint.h5' +if(trim(mode)=='missing_parent') final=trim(directory)//'/missing/checkpoint.h5' +temporary=stage_file(final) +open(newunit=u,file=temporary,status='old',action='write') +write(u,'(A)') 'complete new checkpoint' +close(u) +if(trim(mode)=='leave') stop +if(trim(mode)=='fail_publish') final=trim(directory)//'/directory' +call publish_file(temporary,final) +end program diff --git a/test/qualification/continuity_floor.f90 b/test/qualification/continuity_floor.f90 new file mode 100644 index 000000000..d4c13e37d --- /dev/null +++ b/test/qualification/continuity_floor.f90 @@ -0,0 +1,24 @@ +program continuity_floor +use phys_consts, only: wp,lsp,mindens +use meshobj_cart, only: cartmesh +use grid, only: set_total_grid_sizes,set_subgrid_sizes +use multifluid, only: clean_param +use transport_audit, only: audit_transport_init,audit_step,audit_mass_start,audit_mass_finish +implicit none(type,external) +type(cartmesh) :: x +real(wp) :: ns(-1:4,-1:4,-1:4,lsp) +character(4096) :: directory +call get_command_argument(1,directory) +call set_total_grid_sizes(2,2,2);call set_subgrid_sizes(2,2) +x%lx1=2;x%lx2=2;x%lx3=2 +allocate(x%h1(-1:4,-1:4,-1:4),x%h2(-1:4,-1:4,-1:4),x%h3(-1:4,-1:4,-1:4)) +allocate(x%dx1i(2),x%dx2i(2),x%dx3i(2),x%nullpts(2,2,2),x%inull(1,3)) +x%h1=1;x%h2=1;x%h3=1;x%dx1i=1;x%dx2i=1;x%dx3i=1 +x%nullpts=.false.;x%nullpts(2,2,2)=.true.;x%lnull=1;x%inull(1,:)=[2,2,2] +ns=.5_wp;ns(:,:,:,7)=3;mindens=2 +call audit_transport_init(trim(directory),0) +call audit_step(0._wp,1._wp) +call audit_mass_start(ns,x) +call clean_param(x,1,ns) +call audit_mass_finish(ns) +end program diff --git a/test/qualification/coulomb_curve.f90 b/test/qualification/coulomb_curve.f90 new file mode 100644 index 000000000..71a2aaa06 --- /dev/null +++ b/test/qualification/coulomb_curve.f90 @@ -0,0 +1,37 @@ +program coulomb_curve +use phys_consts,only:wp,lsp,kb,ms +use collisions,only:coulomb_colln +implicit none(type,external) +real(wp),parameter::values(13)=[0._wp,1e-8_wp,1e-6_wp,.001_wp,.01_wp,.05_wp, & + .09999999_wp,.1_wp,.10000001_wp,.5_wp,1._wp,3._wp,10._wp] +real(wp)::ns(-1:3,-1:3,-1:3,lsp),ts(-1:3,-1:3,-1:3,lsp),v(-1:3,-1:3,-1:3,lsp) +real(wp)::nu(1,1,1),phi(1,1,1),psi(1,1,1),speed,w,oracle,error +integer::i +ns=0;ts=1000;v=0;ns(:,:,:,1)=2e11_wp;ns(:,:,:,6)=8e10_wp +speed=sqrt(2*kb*1000/(ms(1)*ms(6)/(ms(1)+ms(6)))) +do i=1,size(values) + v(:,:,:,1)=values(i)*speed;w=abs(v(1,1,1,1))/speed + call coulomb_colln(1,6,ns,ts,v,nu,phi,psi) + ! Independent numerical integral on a fixed interval. This does not reuse + ! either production power-series coefficients or the erf expression. + oracle=integral(w);error=abs(phi(1,1,1)-oracle) + print '(2(es25.17,1x))',w,error + if(error>5e-14_wp)error stop 'Coulomb drag integral and continuity' +enddo +contains +pure function integral(w)result(value) +real(wp),intent(in)::w +real(wp)::value,total,compensation,term,y,next,x,weight +integer,parameter::n=4096 +integer::j +total=exp(-w*w);compensation=0 +do j=1,n-1 + x=real(j,wp)/n;weight=2 + if(modulo(j,2)==1)weight=4 + term=weight*x*x*exp(-(w*x)**2) + y=term-compensation;next=total+y + compensation=(next-total)-y;total=next +enddo +value=total/n +end function +end program diff --git a/test/qualification/data/IGRF_PROVENANCE.json b/test/qualification/data/IGRF_PROVENANCE.json new file mode 100644 index 000000000..218a5042e --- /dev/null +++ b/test/qualification/data/IGRF_PROVENANCE.json @@ -0,0 +1,16 @@ +{ + "source": "IAGA IGRF-14 distributed by NOAA/NCEI", + "retrieved": "2026-09-16", + "purpose": "Independent qualification oracle only; not the production grid model", + "files": [ + { + "url": "https://www.ngdc.noaa.gov/IAGA/vmod/igrf14.f", + "sha256": "0c4fe0664d837b86c1d1fb4d2a354d6a14a29bbf028b550ab1342e1b828dd2c0" + }, + { + "url": "https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt", + "sha256": "8f8d88403028fc4ee92c4f38d97b46e0a87e2cfc496045b43c9e26c1d6b0903c" + } + ], + "extraction": "igrf14syn.f is the unchanged igrf14syn subroutine through end of original igrf14.f" +} diff --git a/test/qualification/data/igrf14coeffs.txt b/test/qualification/data/igrf14coeffs.txt new file mode 100644 index 000000000..13e712269 --- /dev/null +++ b/test/qualification/data/igrf14coeffs.txt @@ -0,0 +1,199 @@ +# 14th Generation International Geomagnetic Reference Field Schmidt semi-normalised spherical harmonic coefficients, degree n=1,13 +# in units nanoTesla for IGRF and definitive DGRF main-field models (degree n=1,8 nanoTesla/year for secular variation (SV)) +c/s deg ord IGRF IGRF IGRF IGRF IGRF IGRF IGRF IGRF IGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF DGRF IGRF SV +g/h n m 1900.0 1905.0 1910.0 1915.0 1920.0 1925.0 1930.0 1935.0 1940.0 1945.0 1950.0 1955.0 1960.0 1965.0 1970.0 1975.0 1980.0 1985.0 1990.0 1995.0 2000.0 2005.0 2010.0 2015.0 2020.0 2025.0 2025-30 +g 1 0 -31543 -31464 -31354 -31212 -31060 -30926 -30805 -30715 -30654 -30594 -30554 -30500 -30421 -30334 -30220 -30100 -29992 -29873 -29775 -29692 -29619.4 -29554.63 -29496.57 -29441.46 -29403.41 -29350.0 12.6 +g 1 1 -2298 -2298 -2297 -2306 -2317 -2318 -2316 -2306 -2292 -2285 -2250 -2215 -2169 -2119 -2068 -2013 -1956 -1905 -1848 -1784 -1728.2 -1669.05 -1586.42 -1501.77 -1451.37 -1410.3 10.0 +h 1 1 5922 5909 5898 5875 5845 5817 5808 5812 5821 5810 5815 5820 5791 5776 5737 5675 5604 5500 5406 5306 5186.1 5077.99 4944.26 4795.99 4653.35 4545.5 -21.5 +g 2 0 -677 -728 -769 -802 -839 -893 -951 -1018 -1106 -1244 -1341 -1440 -1555 -1662 -1781 -1902 -1997 -2072 -2131 -2200 -2267.7 -2337.24 -2396.06 -2445.88 -2499.78 -2556.2 -11.2 +g 2 1 2905 2928 2948 2956 2959 2969 2980 2984 2981 2990 2998 3003 3002 2997 3000 3010 3027 3044 3059 3070 3068.4 3047.69 3026.34 3012.20 2981.96 2950.9 -5.3 +h 2 1 -1061 -1086 -1128 -1191 -1259 -1334 -1424 -1520 -1614 -1702 -1810 -1898 -1967 -2016 -2047 -2067 -2129 -2197 -2279 -2366 -2481.6 -2594.50 -2708.54 -2845.41 -2991.72 -3133.6 -27.3 +g 2 2 924 1041 1176 1309 1407 1471 1517 1550 1566 1578 1576 1581 1590 1594 1611 1632 1663 1687 1686 1681 1670.9 1657.76 1668.17 1676.35 1676.85 1648.7 -8.3 +h 2 2 1121 1065 1000 917 823 728 644 586 528 477 381 291 206 114 25 -68 -200 -306 -373 -413 -458.0 -515.43 -575.73 -642.17 -734.62 -814.2 -11.1 +g 3 0 1022 1037 1058 1084 1111 1140 1172 1206 1240 1282 1297 1302 1302 1297 1287 1276 1281 1296 1314 1335 1339.6 1336.30 1339.85 1350.33 1363.00 1360.9 -1.5 +g 3 1 -1469 -1494 -1524 -1559 -1600 -1645 -1692 -1740 -1790 -1834 -1889 -1944 -1992 -2038 -2091 -2144 -2180 -2208 -2239 -2267 -2288.0 -2305.83 -2326.54 -2352.26 -2380.80 -2404.2 -4.4 +h 3 1 -330 -357 -389 -421 -445 -462 -480 -494 -499 -499 -476 -462 -414 -404 -366 -333 -336 -310 -284 -262 -227.6 -198.86 -160.40 -115.29 -81.96 -56.9 3.8 +g 3 2 1256 1239 1223 1212 1205 1202 1205 1215 1232 1255 1274 1288 1289 1292 1278 1260 1251 1247 1248 1249 1252.1 1246.39 1232.10 1225.85 1236.06 1243.8 0.4 +h 3 2 3 34 62 84 103 119 133 146 163 186 206 216 224 240 251 262 271 284 293 302 293.4 269.72 251.75 245.04 241.80 237.6 -0.2 +g 3 3 572 635 705 778 839 881 907 918 916 913 896 882 878 856 838 830 833 829 802 759 714.5 672.51 633.73 581.69 525.60 453.4 -15.6 +h 3 3 523 480 425 360 293 229 166 101 43 -11 -46 -83 -130 -165 -196 -223 -252 -297 -352 -427 -491.1 -524.72 -537.03 -538.70 -542.52 -549.6 -3.9 +g 4 0 876 880 884 887 889 891 896 903 914 944 954 958 957 957 952 946 938 936 939 940 932.3 920.55 912.66 907.42 902.82 894.7 -1.7 +g 4 1 628 643 660 678 695 711 727 744 762 776 792 796 800 804 800 791 782 780 780 780 786.8 797.96 808.97 813.68 809.47 799.6 -2.3 +h 4 1 195 203 211 218 220 216 205 188 169 144 136 133 135 148 167 191 212 232 247 262 272.6 282.07 286.48 283.54 282.10 278.6 -1.3 +g 4 2 660 653 644 631 616 601 584 565 550 544 528 510 504 479 461 438 398 361 325 290 250.0 210.65 166.58 120.49 86.18 55.8 -5.8 +h 4 2 -69 -77 -90 -109 -134 -163 -195 -226 -252 -276 -278 -274 -278 -269 -266 -265 -257 -249 -240 -236 -231.9 -225.23 -211.03 -188.43 -158.50 -134.0 4.1 +g 4 3 -361 -380 -400 -416 -424 -426 -422 -415 -405 -421 -408 -397 -394 -390 -395 -405 -419 -424 -423 -418 -403.0 -379.86 -356.83 -334.85 -309.47 -281.1 5.4 +h 4 3 -210 -201 -189 -173 -153 -130 -109 -90 -72 -55 -37 -23 3 13 26 39 53 69 84 97 119.8 145.15 164.46 180.95 199.75 212.0 1.6 +g 4 4 134 146 160 178 199 217 234 249 265 304 303 290 269 252 234 216 199 170 141 122 111.3 100.00 89.40 70.38 47.44 12.0 -6.8 +h 4 4 -75 -65 -55 -51 -57 -70 -90 -114 -141 -178 -210 -230 -255 -269 -279 -288 -297 -297 -299 -306 -303.8 -305.36 -309.72 -329.23 -350.30 -375.4 -4.1 +g 5 0 -184 -192 -201 -211 -221 -230 -237 -241 -241 -253 -240 -229 -222 -219 -216 -218 -218 -214 -214 -214 -218.8 -227.00 -230.87 -232.91 -234.42 -232.9 0.6 +g 5 1 328 328 327 327 326 326 327 329 334 346 349 360 362 358 359 356 357 355 353 352 351.4 354.41 357.29 360.14 363.26 369.0 1.3 +h 5 1 -210 -193 -172 -148 -122 -96 -72 -51 -33 -12 3 15 16 19 26 31 46 47 46 46 43.8 42.72 44.58 46.98 47.52 45.3 -0.5 +g 5 2 264 259 253 245 236 226 218 211 208 194 211 230 242 254 262 264 261 253 245 235 222.3 208.95 200.26 192.35 187.86 187.2 0.0 +h 5 2 53 56 57 58 58 58 60 64 71 95 103 110 125 128 139 148 150 150 154 165 171.9 180.25 189.01 196.98 208.36 220.0 2.1 +g 5 3 5 -1 -9 -16 -23 -28 -32 -33 -33 -20 -20 -23 -26 -31 -42 -59 -74 -93 -109 -118 -130.4 -136.54 -141.05 -140.94 -140.73 -138.7 0.7 +h 5 3 -33 -32 -33 -34 -38 -44 -53 -64 -75 -67 -87 -98 -117 -126 -139 -152 -151 -154 -153 -143 -133.1 -123.45 -118.06 -119.14 -121.43 -122.9 0.5 +g 5 4 -86 -93 -102 -111 -119 -125 -131 -136 -141 -142 -147 -152 -156 -157 -160 -159 -162 -164 -165 -166 -168.6 -168.05 -163.17 -157.40 -151.16 -141.9 2.3 +h 5 4 -124 -125 -126 -126 -125 -122 -118 -115 -113 -119 -122 -121 -114 -97 -91 -83 -78 -75 -69 -55 -39.3 -19.57 -0.01 15.98 32.09 42.9 1.7 +g 5 5 -16 -26 -38 -51 -62 -69 -74 -76 -76 -82 -76 -69 -63 -62 -56 -49 -48 -46 -36 -17 -12.9 -13.55 -8.03 4.30 13.98 20.9 1.0 +h 5 5 3 11 21 32 43 51 58 64 69 82 80 78 81 81 83 88 92 95 97 107 106.3 103.85 101.04 100.12 99.14 106.2 1.9 +g 6 0 63 62 62 61 61 61 60 59 57 59 54 47 46 45 43 45 48 53 61 68 72.3 73.60 72.78 69.55 65.97 64.3 -0.2 +g 6 1 61 60 58 57 55 54 53 53 54 57 57 57 58 61 64 66 66 65 65 67 68.2 69.56 68.69 67.57 65.56 63.8 -0.3 +h 6 1 -9 -7 -5 -2 0 3 4 4 4 6 -1 -9 -10 -11 -12 -13 -15 -16 -16 -17 -17.4 -20.33 -20.90 -20.61 -19.22 -18.4 0.3 +g 6 2 -11 -11 -11 -10 -10 -9 -9 -8 -7 6 4 3 1 8 15 28 42 51 59 68 74.2 76.74 75.92 72.79 72.96 76.7 0.8 +h 6 2 83 86 89 93 96 99 102 104 105 100 99 96 99 100 100 99 93 88 82 72 63.7 54.75 44.18 33.30 25.02 16.8 -1.6 +g 6 3 -217 -221 -224 -228 -233 -238 -242 -246 -249 -246 -247 -247 -237 -228 -212 -198 -192 -185 -178 -170 -160.9 -151.34 -141.40 -129.85 -121.57 -115.7 1.2 +h 6 3 2 4 5 8 11 14 19 25 33 16 33 48 60 68 72 75 71 69 69 67 65.1 63.63 61.54 58.74 52.76 48.9 -0.4 +g 6 4 -58 -57 -54 -51 -46 -40 -32 -25 -18 -25 -16 -8 -1 4 2 1 4 4 3 -1 -5.9 -14.58 -22.83 -28.93 -36.06 -40.9 -0.8 +h 6 4 -35 -32 -29 -26 -22 -18 -16 -15 -15 -9 -12 -16 -20 -32 -37 -41 -43 -48 -52 -58 -61.2 -63.53 -66.26 -66.64 -64.40 -59.8 0.8 +g 6 5 59 57 54 49 44 39 32 25 18 21 12 7 -2 1 3 6 14 16 18 19 16.9 14.58 13.10 13.14 13.60 14.9 0.4 +h 6 5 36 32 28 23 18 13 8 4 0 -16 -12 -12 -11 -8 -6 -4 -2 -1 1 1 0.7 0.24 3.02 7.35 8.96 10.9 0.7 +g 6 6 -90 -92 -95 -98 -101 -103 -104 -106 -107 -104 -105 -107 -113 -111 -112 -111 -108 -102 -96 -93 -90.4 -86.36 -78.09 -70.85 -64.80 -60.8 0.9 +h 6 6 -69 -67 -65 -62 -57 -52 -46 -40 -33 -39 -30 -24 -17 -7 1 11 17 21 24 36 43.8 50.94 55.40 62.41 68.04 72.8 0.9 +g 7 0 70 70 71 72 73 73 74 74 74 70 65 65 67 75 72 71 72 74 77 77 79.0 79.88 80.44 81.29 80.54 79.6 -0.1 +g 7 1 -55 -54 -54 -54 -54 -54 -54 -53 -53 -40 -55 -56 -56 -57 -57 -56 -59 -62 -64 -72 -74.0 -74.46 -75.00 -75.99 -76.63 -76.9 -0.1 +h 7 1 -45 -46 -47 -48 -49 -50 -51 -52 -52 -45 -35 -50 -55 -61 -70 -77 -82 -83 -80 -69 -64.6 -61.14 -57.80 -54.27 -51.50 -48.9 0.6 +g 7 2 0 0 1 2 2 3 4 4 4 0 2 2 5 4 1 1 2 3 2 1 0.0 -1.65 -4.55 -6.79 -8.23 -8.8 -0.1 +h 7 2 -13 -14 -14 -14 -14 -14 -15 -17 -18 -18 -17 -24 -28 -27 -27 -26 -27 -27 -26 -25 -24.2 -22.57 -21.20 -19.53 -16.85 -14.4 0.5 +g 7 3 34 33 32 31 29 27 25 23 20 0 1 10 15 13 14 16 21 24 26 28 33.3 38.73 45.24 51.82 56.45 59.3 0.5 +h 7 3 -10 -11 -12 -12 -13 -14 -14 -14 -14 2 0 -4 -6 -2 -4 -5 -5 -2 0 4 6.2 6.82 6.54 5.59 2.36 -1.0 -0.7 +g 7 4 -41 -41 -40 -38 -37 -35 -34 -33 -31 -29 -40 -32 -32 -26 -22 -14 -12 -6 -1 5 9.1 12.30 14.00 15.07 15.80 15.8 -0.1 +h 7 4 -1 0 1 2 4 5 6 7 7 6 10 8 7 6 8 10 16 20 21 24 24.0 25.35 24.96 24.45 23.56 23.5 0.0 +g 7 5 -21 -20 -19 -18 -16 -14 -12 -11 -9 -10 -7 -11 -7 -6 -2 0 1 4 5 4 6.9 9.37 10.46 9.32 6.30 2.5 -0.8 +h 7 5 28 28 28 28 28 29 29 29 29 28 36 28 23 26 23 22 18 17 17 17 14.8 10.93 7.03 3.27 -2.19 -7.4 -0.9 +g 7 6 18 18 18 19 19 19 18 18 17 15 5 9 17 13 13 12 11 10 9 8 7.3 5.42 1.64 -2.88 -7.21 -11.2 -0.8 +h 7 6 -12 -12 -13 -15 -16 -17 -18 -19 -20 -17 -18 -20 -18 -23 -23 -23 -23 -23 -23 -24 -25.4 -26.32 -27.61 -27.50 -27.19 -25.1 0.5 +g 7 7 6 6 6 6 6 6 6 6 5 29 19 18 8 1 -2 -5 -2 0 0 -2 -1.2 1.94 4.92 6.61 9.77 14.3 0.9 +h 7 7 -22 -22 -22 -22 -22 -21 -20 -19 -19 -22 -16 -18 -17 -12 -11 -12 -10 -7 -4 -6 -5.8 -4.64 -3.28 -2.32 -1.90 -2.2 -0.3 +g 8 0 11 11 11 11 11 11 11 11 11 13 22 11 15 13 14 14 18 21 23 25 24.4 24.80 24.41 23.98 23.66 23.1 -0.1 +g 8 1 8 8 8 8 7 7 7 7 7 7 15 9 6 5 6 6 6 6 5 6 6.6 7.62 8.21 8.89 9.74 10.9 0.2 +h 8 1 8 8 8 8 8 8 8 8 8 12 5 10 11 7 7 6 7 8 10 11 11.9 11.20 10.84 10.04 8.43 7.2 -0.3 +g 8 2 -4 -4 -4 -4 -3 -3 -3 -3 -3 -8 -4 -6 -4 -4 -2 -1 0 0 -1 -6 -9.2 -11.73 -14.50 -16.78 -17.49 -17.5 0.0 +h 8 2 -14 -15 -15 -15 -15 -15 -15 -15 -14 -21 -22 -15 -14 -12 -15 -16 -18 -19 -19 -21 -21.5 -20.88 -20.03 -18.26 -15.23 -12.6 0.4 +g 8 3 -9 -9 -9 -9 -9 -9 -9 -9 -10 -5 -1 -14 -11 -14 -13 -12 -11 -11 -10 -9 -7.9 -6.88 -5.59 -3.16 -0.49 2.0 0.4 +h 8 3 7 7 6 6 6 6 5 5 5 -12 0 5 7 9 6 4 4 5 6 8 8.5 9.83 11.83 13.18 12.83 11.5 -0.3 +g 8 4 1 1 1 2 2 2 2 1 1 9 11 6 2 0 -3 -8 -7 -9 -12 -14 -16.6 -18.11 -19.34 -20.56 -21.07 -21.8 -0.1 +h 8 4 -13 -13 -13 -13 -14 -14 -14 -15 -15 -7 -21 -23 -18 -16 -17 -19 -22 -23 -22 -23 -21.5 -19.71 -17.41 -14.60 -11.76 -9.7 0.4 +g 8 5 2 2 2 3 4 4 5 6 6 7 15 10 10 8 5 4 4 4 3 9 9.1 10.17 11.61 13.33 15.28 16.9 0.3 +h 8 5 5 5 5 5 5 5 5 5 5 2 -8 3 4 4 6 6 9 11 12 15 15.5 16.22 16.71 16.16 14.94 12.7 -0.5 +g 8 6 -9 -8 -8 -8 -7 -7 -6 -6 -5 -10 -13 -7 -5 -1 0 0 3 4 4 6 7.0 9.36 10.85 11.76 13.65 14.9 0.1 +h 8 6 16 16 16 16 17 17 18 18 19 18 17 23 23 24 21 18 16 14 12 11 8.9 7.61 6.96 5.69 3.62 0.7 -0.6 +g 8 7 5 5 5 6 6 7 8 8 9 7 5 6 10 11 11 10 6 4 2 -5 -7.9 -11.25 -14.05 -15.98 -16.59 -16.8 0.0 +h 8 7 -5 -5 -5 -5 -5 -5 -5 -5 -5 3 -4 -4 1 -3 -6 -10 -13 -15 -16 -16 -14.9 -12.76 -10.74 -9.10 -6.90 -5.2 0.3 +g 8 8 8 8 8 8 8 8 8 7 7 2 -1 9 8 4 3 1 -1 -4 -6 -7 -7.0 -4.87 -3.54 -2.02 -0.34 1.0 0.3 +h 8 8 -18 -18 -18 -18 -19 -19 -19 -19 -19 -11 -17 -13 -20 -17 -16 -17 -15 -11 -10 -4 -2.1 -0.06 1.64 2.26 2.90 3.9 0.2 +g 9 0 8 8 8 8 8 8 8 8 8 5 3 4 4 8 8 7 5 5 4 4 5.0 5.58 5.50 5.33 5.03 4.7 0.0 +g 9 1 10 10 10 10 10 10 10 10 10 -21 -7 9 6 10 10 10 10 10 9 9 9.4 9.76 9.45 8.83 8.36 8.0 0.0 +h 9 1 -20 -20 -20 -20 -20 -20 -20 -20 -21 -27 -24 -11 -18 -22 -21 -21 -21 -21 -20 -20 -19.7 -20.11 -20.54 -21.77 -23.44 -24.8 0.0 +g 9 2 1 1 1 1 1 1 1 1 1 1 -1 -4 0 2 2 2 1 1 1 3 3.0 3.58 3.45 3.02 2.84 3.0 0.0 +h 9 2 14 14 14 14 14 14 14 15 15 17 19 12 12 15 16 16 16 15 15 15 13.4 12.69 11.51 10.76 11.04 12.1 0.0 +g 9 3 -11 -11 -11 -11 -11 -11 -12 -12 -12 -11 -25 -5 -9 -13 -12 -12 -12 -12 -12 -10 -8.4 -6.94 -5.27 -3.22 -1.48 -0.2 0.0 +h 9 3 5 5 5 5 5 5 5 5 5 29 12 7 2 7 6 7 9 9 11 12 12.5 12.67 12.75 11.74 9.86 8.3 0.0 +g 9 4 12 12 12 12 12 12 12 11 11 3 10 2 1 10 10 10 9 9 9 8 6.3 5.01 3.13 0.67 -1.14 -2.5 0.0 +h 9 4 -3 -3 -3 -3 -3 -3 -3 -3 -3 -9 2 6 0 -4 -4 -4 -5 -6 -7 -6 -6.2 -6.72 -7.14 -6.74 -5.13 -3.4 0.0 +g 9 5 1 1 1 1 1 1 1 1 1 16 5 4 4 -1 -1 -1 -3 -3 -4 -8 -8.9 -10.76 -12.38 -13.20 -13.22 -13.1 0.0 +h 9 5 -2 -2 -2 -2 -2 -2 -2 -3 -3 4 2 -2 -3 -5 -5 -5 -6 -6 -7 -8 -8.4 -8.16 -7.42 -6.88 -6.20 -5.3 0.0 +g 9 6 -2 -2 -2 -2 -2 -2 -2 -2 -2 -3 -5 1 -1 -1 0 -1 -1 -1 -2 -1 -1.5 -1.25 -0.76 -0.10 1.08 2.4 0.0 +h 9 6 8 8 8 8 9 9 9 9 9 9 8 10 9 10 10 10 9 9 9 8 8.4 8.10 7.97 7.79 7.79 7.2 0.0 +g 9 7 2 2 2 2 2 2 3 3 3 -4 -2 2 -2 5 3 4 7 7 7 10 9.3 8.76 8.43 8.68 8.82 8.6 0.0 +h 9 7 10 10 10 10 10 10 10 11 11 6 8 7 8 10 11 11 10 9 8 5 3.8 2.92 2.14 1.04 0.40 -0.6 0.0 +g 9 8 -1 0 0 0 0 0 0 0 1 -3 3 2 3 1 1 1 2 1 1 -2 -4.3 -6.66 -8.42 -9.06 -9.23 -8.7 0.0 +h 9 8 -2 -2 -2 -2 -2 -2 -2 -2 -2 1 -11 -6 0 -4 -2 -3 -6 -7 -7 -8 -8.2 -7.73 -6.08 -3.89 -1.44 0.8 0.0 +g 9 9 -1 -1 -1 -1 -1 -1 -2 -2 -2 -4 8 5 -1 -2 -1 -2 -5 -5 -6 -8 -8.2 -9.22 -10.08 -10.54 -11.86 -12.8 0.0 +h 9 9 2 2 2 2 2 2 2 2 2 8 -7 5 5 1 1 1 2 2 2 3 4.8 6.01 7.01 8.44 9.60 9.8 0.0 +g 10 0 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -8 -3 1 -2 -3 -3 -4 -4 -3 -3 -2.6 -2.17 -1.94 -2.01 -1.84 -1.3 0.0 +g 10 1 -4 -4 -4 -4 -4 -4 -4 -4 -4 11 4 -5 -3 -3 -3 -3 -4 -4 -4 -6 -6.0 -6.12 -6.24 -6.26 -6.25 -6.4 0.0 +h 10 1 2 2 2 2 2 2 2 2 2 5 13 -4 4 2 1 1 1 1 2 1 1.7 2.19 2.73 3.28 3.38 3.3 0.0 +g 10 2 2 2 2 2 2 2 2 2 2 1 -1 -1 4 2 2 2 2 3 2 2 1.7 1.42 0.89 0.17 -0.11 0.2 0.0 +h 10 2 1 1 1 1 1 1 1 1 1 1 -2 0 1 1 1 1 0 0 1 0 0.0 0.10 -0.10 -0.40 -0.18 0.1 0.0 +g 10 3 -5 -5 -5 -5 -5 -5 -5 -5 -5 2 13 2 0 -5 -5 -5 -5 -5 -5 -4 -3.1 -2.35 -1.07 0.55 1.66 2.0 0.0 +h 10 3 2 2 2 2 2 2 2 2 2 -20 -10 -8 0 2 3 3 3 3 3 4 4.0 4.46 4.71 4.55 3.50 2.5 0.0 +g 10 4 -2 -2 -2 -2 -2 -2 -2 -2 -2 -5 -4 -3 -1 -2 -1 -2 -2 -2 -2 -1 -0.5 -0.15 -0.16 -0.55 -0.86 -1.0 0.0 +h 10 4 6 6 6 6 6 6 6 6 6 -1 2 -2 2 6 4 4 6 6 6 5 4.9 4.76 4.44 4.40 4.86 5.4 0.0 +g 10 5 6 6 6 6 6 6 6 6 6 -1 4 7 4 4 6 5 5 5 4 4 3.7 3.06 2.45 1.70 0.65 -0.5 0.0 +h 10 5 -4 -4 -4 -4 -4 -4 -4 -4 -4 -6 -3 -4 -5 -4 -4 -4 -4 -4 -4 -5 -5.9 -6.58 -7.22 -7.92 -8.62 -9.0 0.0 +g 10 6 4 4 4 4 4 4 4 4 4 8 12 4 6 4 4 4 3 3 3 2 1.0 0.29 -0.33 -0.67 -0.88 -0.9 0.0 +h 10 6 0 0 0 0 0 0 0 0 0 6 6 1 1 0 0 -1 0 0 0 -1 -1.2 -1.01 -0.96 -0.61 -0.11 0.4 0.0 +g 10 7 0 0 0 0 0 0 0 0 0 -1 3 -2 1 0 1 1 1 1 1 2 2.0 2.06 2.13 2.13 1.88 1.5 0.0 +h 10 7 -2 -2 -2 -2 -2 -2 -2 -1 -1 -4 -3 -3 -1 -2 -1 -1 -1 -1 -2 -2 -2.9 -3.47 -3.95 -4.16 -4.26 -4.2 0.0 +g 10 8 2 2 2 1 1 1 1 2 2 -3 2 6 -1 2 0 0 2 2 3 5 4.2 3.77 3.09 2.33 1.44 0.9 0.0 +h 10 8 4 4 4 4 4 4 4 4 4 -2 6 7 6 3 3 3 4 4 3 1 0.2 -0.86 -1.99 -2.85 -3.43 -3.8 0.0 +g 10 9 2 2 2 2 3 3 3 3 3 5 10 -2 2 2 3 3 3 3 3 1 0.3 -0.21 -1.03 -1.80 -2.38 -2.6 0.0 +h 10 9 0 0 0 0 0 0 0 0 0 0 11 -1 0 0 1 1 0 0 -1 -2 -2.2 -2.31 -1.97 -1.12 -0.10 0.9 0.0 +g 10 10 0 0 0 0 0 0 0 0 0 -2 3 0 0 0 -1 -1 0 0 0 0 -1.1 -2.09 -2.80 -3.59 -3.84 -3.9 0.0 +h 10 10 -6 -6 -6 -6 -6 -6 -6 -6 -6 -2 8 -3 -7 -6 -4 -5 -6 -6 -6 -7 -7.4 -7.93 -8.31 -8.72 -8.84 -9.0 0.0 +g 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.7 2.95 3.05 3.00 2.96 3.0 0.0 +g 11 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.7 -1.60 -1.48 -1.40 -1.36 -1.4 0.0 +h 11 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0.26 0.13 0.00 -0.02 0.0 0.0 +g 11 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.9 -1.88 -2.03 -2.30 -2.51 -2.5 0.0 +h 11 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.3 1.44 1.67 2.11 2.50 2.8 0.0 +g 11 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.5 1.44 1.65 2.08 2.31 2.4 0.0 +h 11 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9 -0.77 -0.66 -0.60 -0.55 -0.6 0.0 +g 11 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.1 -0.31 -0.51 -0.79 -0.85 -0.6 0.0 +h 11 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2.6 -2.27 -1.76 -1.05 -0.39 0.1 0.0 +g 11 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0.29 0.54 0.58 0.28 0.0 0.0 +h 11 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9 0.90 0.85 0.76 0.62 0.5 0.0 +g 11 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.7 -0.79 -0.79 -0.70 -0.66 -0.6 0.0 +h 11 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.7 -0.58 -0.39 -0.20 -0.21 -0.3 0.0 +g 11 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.7 0.53 0.37 0.14 -0.07 -0.1 0.0 +h 11 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2.8 -2.69 -2.51 -2.12 -1.66 -1.2 0.0 +g 11 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.7 1.80 1.79 1.70 1.44 1.1 0.0 +h 11 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9 -1.08 -1.27 -1.44 -1.60 -1.7 0.0 +g 11 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0.16 0.12 -0.22 -0.59 -1.0 0.0 +h 11 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.2 -1.58 -2.11 -2.57 -2.98 -2.9 0.0 +g 11 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.2 0.96 0.75 0.44 0.18 -0.1 0.0 +h 11 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.9 -1.90 -1.94 -2.01 -1.97 -1.8 0.0 +g 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4.0 3.99 3.75 3.49 3.09 2.6 0.0 +h 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9 -1.39 -1.86 -2.34 -2.51 -2.3 0.0 +g 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2.2 -2.15 -2.12 -2.09 -2.00 -2.0 0.0 +g 12 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.3 -0.29 -0.21 -0.16 -0.13 -0.1 0.0 +h 12 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.4 -0.55 -0.87 -1.08 -1.15 -1.2 0.0 +g 12 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0.21 0.30 0.46 0.43 0.4 0.0 +h 12 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.23 0.27 0.37 0.52 0.6 0.0 +g 12 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9 0.89 1.04 1.23 1.28 1.2 0.0 +h 12 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.5 2.38 2.13 1.75 1.37 1.0 0.0 +g 12 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.2 -0.38 -0.63 -0.89 -1.14 -1.2 0.0 +h 12 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2.6 -2.63 -2.49 -2.19 -1.81 -1.5 0.0 +g 12 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9 0.96 0.95 0.85 0.71 0.6 0.0 +h 12 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.7 0.61 0.49 0.27 0.08 0.0 0.0 +g 12 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.5 -0.30 -0.11 0.10 0.31 0.5 0.0 +h 12 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.40 0.59 0.72 0.71 0.6 0.0 +g 12 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.46 0.52 0.54 0.49 0.5 0.0 +h 12 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0 0.01 0.00 -0.09 -0.15 -0.2 0.0 +g 12 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.3 -0.35 -0.39 -0.37 -0.26 -0.1 0.0 +h 12 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0 0.02 0.13 0.29 0.55 0.8 0.0 +g 12 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.4 -0.36 -0.37 -0.43 -0.47 -0.5 0.0 +h 12 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.28 0.27 0.23 0.16 0.1 0.0 +g 12 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.1 0.08 0.21 0.22 0.09 -0.2 0.0 +h 12 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9 -0.87 -0.86 -0.89 -0.93 -0.9 0.0 +g 12 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.2 -0.49 -0.77 -0.94 -1.13 -1.2 0.0 +h 12 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.4 -0.34 -0.23 -0.16 -0.04 0.1 0.0 +g 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.4 -0.08 0.04 -0.03 -0.33 -0.7 0.0 +h 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.8 0.88 0.87 0.72 0.52 0.2 0.0 +g 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.2 -0.16 -0.09 -0.02 0.08 0.2 0.0 +g 13 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9 -0.88 -0.89 -0.92 -0.93 -0.9 0.0 +h 13 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9 -0.76 -0.87 -0.88 -0.88 -0.9 0.0 +g 13 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.30 0.31 0.42 0.53 0.6 0.0 +h 13 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0.33 0.30 0.49 0.64 0.7 0.0 +g 13 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0.28 0.42 0.63 0.72 0.7 0.0 +h 13 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.8 1.72 1.66 1.56 1.40 1.2 0.0 +g 13 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.4 -0.43 -0.45 -0.42 -0.30 -0.2 0.0 +h 13 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.4 -0.54 -0.59 -0.50 -0.38 -0.3 0.0 +g 13 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.3 1.18 1.08 0.96 0.75 0.5 0.0 +h 13 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.0 -1.07 -1.14 -1.24 -1.31 -1.3 0.0 +g 13 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.4 -0.37 -0.31 -0.19 -0.01 0.1 0.0 +h 13 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.1 -0.04 -0.07 -0.10 -0.09 -0.1 0.0 +g 13 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.7 0.75 0.78 0.81 0.76 0.7 0.0 +h 13 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.7 0.63 0.54 0.42 0.29 0.2 0.0 +g 13 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.4 -0.26 -0.18 -0.13 -0.05 0.0 0.0 +h 13 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.21 0.10 -0.04 -0.11 -0.2 0.0 +g 13 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.35 0.38 0.38 0.37 0.3 0.0 +h 13 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.6 0.53 0.49 0.48 0.47 0.5 0.0 +g 13 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.1 -0.05 0.02 0.08 0.13 0.2 0.0 +h 13 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.38 0.44 0.48 0.54 0.6 0.0 +g 13 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.4 0.41 0.42 0.46 0.45 0.4 0.0 +h 13 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.2 -0.22 -0.25 -0.30 -0.41 -0.6 0.0 +g 13 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0 -0.10 -0.26 -0.35 -0.46 -0.5 0.0 +h 13 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.5 -0.57 -0.53 -0.43 -0.36 -0.3 0.0 +g 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 -0.18 -0.26 -0.36 -0.40 -0.4 0.0 +h 13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9 -0.82 -0.79 -0.71 -0.60 -0.5 0.0 diff --git a/test/qualification/data/igrf14syn.f b/test/qualification/data/igrf14syn.f new file mode 100644 index 000000000..42783d2ed --- /dev/null +++ b/test/qualification/data/igrf14syn.f @@ -0,0 +1,724 @@ + subroutine igrf14syn (isv,date,itype,alt,colat,elong,x,y,z,f) +c +c This is a synthesis routine for the 14th generation IGRF as agreed +c in December 2024 by IAGA Working Group V-MOD. It is valid 1900.0 to +c 2030.0 inclusive. Values for dates from 1945.0 to 2020.0 inclusive are +c definitive, otherwise they are non-definitive. +c INPUT +c isv = 0 if main-field values are required +c isv = 1 if secular variation values are required +c date = year A.D. Must be greater than or equal to 1900.0 and +c less than or equal to 2035.0. Warning message is given +c for dates greater than 2030.0. Must be double precision. +c itype = 1 if geodetic (spheroid) +c itype = 2 if geocentric (sphere) +c alt = height in km above sea level if itype = 1 +c = distance from centre of Earth in km if itype = 2 (>3485 km) +c colat = colatitude (0-180) +c elong = east-longitude (0-360) +c alt, colat and elong must be double precision. +c OUTPUT +c x = north component (nT) if isv = 0, nT/year if isv = 1 +c y = east component (nT) if isv = 0, nT/year if isv = 1 +c z = vertical component (nT) if isv = 0, nT/year if isv = 1 +c f = total intensity (nT) if isv = 0, rubbish if isv = 1 +c +c To get the other geomagnetic elements (D, I, H and secular +c variations dD, dH, dI and dF) use routines ptoc and ptocsv. +c +c Adapted from 8th generation version to include new maximum degree for +c main-field models for 2000.0 and onwards and use WGS84 spheroid instead +c of International Astronomical Union 1966 spheroid as recommended by IAGA +c in July 2003. Reference radius remains as 6371.2 km - it is NOT the mean +c radius (= 6371.0 km) but 6371.2 km is what is used in determining the +c coefficients. Adaptation by Susan Macmillan, August 2003 (for +c 9th generation), December 2004, December 2009 & December 2014; +c by William Brown, December 2019, February 2020. Updated by +c Ciaran Beggan, November 2024 +c +c Coefficients at 1995.0 incorrectly rounded (rounded up instead of +c to even) included as these are the coefficients published in Excel +c spreadsheet July 2005. +c + implicit double precision (a-h,o-z) + dimension gh(3840),g0(120),g1(120),g2(120),g3(120),g4(120), + 1 g5(120),g6(120),g7(120),g8(120),g9(120),ga(120), + 2 gb(120),gc(120),gd(120),ge(120),gf(120),gg(120), + 3 gi(120),gj(120),gk(195),gl(195),gm(195),gp(195), + 4 gq(195),gr(195),gs(195),gt(195), + 5 p(105),q(105),cl(13),sl(13) + equivalence (g0,gh(1)),(g1,gh(121)),(g2,gh(241)),(g3,gh(361)), + 1 (g4,gh(481)),(g5,gh(601)),(g6,gh(721)),(g7,gh(841)), + 2 (g8,gh(961)),(g9,gh(1081)),(ga,gh(1201)), + 3 (gb,gh(1321)),(gc,gh(1441)),(gd,gh(1561)), + 4 (ge,gh(1681)),(gf,gh(1801)),(gg,gh(1921)), + 5 (gi,gh(2041)),(gj,gh(2161)),(gk,gh(2281)), + 6 (gl,gh(2476)),(gm,gh(2671)),(gp,gh(2866)), + 7 (gq,gh(3061)),(gr,gh(3256)),(gs,gh(3451)), + 8 (gt,gh(3646)) +c + data g0/ -31543.,-2298., 5922., -677., 2905.,-1061., 924., 1121., 1900 + 1 1022.,-1469., -330., 1256., 3., 572., 523., 876., 1900 + 2 628., 195., 660., -69., -361., -210., 134., -75., 1900 + 3 -184., 328., -210., 264., 53., 5., -33., -86., 1900 + 4 -124., -16., 3., 63., 61., -9., -11., 83., 1900 + 5 -217., 2., -58., -35., 59., 36., -90., -69., 1900 + 6 70., -55., -45., 0., -13., 34., -10., -41., 1900 + 7 -1., -21., 28., 18., -12., 6., -22., 11., 1900 + 8 8., 8., -4., -14., -9., 7., 1., -13., 1900 + 9 2., 5., -9., 16., 5., -5., 8., -18., 1900 + a 8., 10., -20., 1., 14., -11., 5., 12., 1900 + b -3., 1., -2., -2., 8., 2., 10., -1., 1900 + c -2., -1., 2., -3., -4., 2., 2., 1., 1900 + d -5., 2., -2., 6., 6., -4., 4., 0., 1900 + e 0., -2., 2., 4., 2., 0., 0., -6./ 1900 + data g1/ -31464.,-2298., 5909., -728., 2928.,-1086., 1041., 1065., 1905 + 1 1037.,-1494., -357., 1239., 34., 635., 480., 880., 1905 + 2 643., 203., 653., -77., -380., -201., 146., -65., 1905 + 3 -192., 328., -193., 259., 56., -1., -32., -93., 1905 + 4 -125., -26., 11., 62., 60., -7., -11., 86., 1905 + 5 -221., 4., -57., -32., 57., 32., -92., -67., 1905 + 6 70., -54., -46., 0., -14., 33., -11., -41., 1905 + 7 0., -20., 28., 18., -12., 6., -22., 11., 1905 + 8 8., 8., -4., -15., -9., 7., 1., -13., 1905 + 9 2., 5., -8., 16., 5., -5., 8., -18., 1905 + a 8., 10., -20., 1., 14., -11., 5., 12., 1905 + b -3., 1., -2., -2., 8., 2., 10., 0., 1905 + c -2., -1., 2., -3., -4., 2., 2., 1., 1905 + d -5., 2., -2., 6., 6., -4., 4., 0., 1905 + e 0., -2., 2., 4., 2., 0., 0., -6./ 1905 + data g2/ -31354.,-2297., 5898., -769., 2948.,-1128., 1176., 1000., 1910 + 1 1058.,-1524., -389., 1223., 62., 705., 425., 884., 1910 + 2 660., 211., 644., -90., -400., -189., 160., -55., 1910 + 3 -201., 327., -172., 253., 57., -9., -33., -102., 1910 + 4 -126., -38., 21., 62., 58., -5., -11., 89., 1910 + 5 -224., 5., -54., -29., 54., 28., -95., -65., 1910 + 6 71., -54., -47., 1., -14., 32., -12., -40., 1910 + 7 1., -19., 28., 18., -13., 6., -22., 11., 1910 + 8 8., 8., -4., -15., -9., 6., 1., -13., 1910 + 9 2., 5., -8., 16., 5., -5., 8., -18., 1910 + a 8., 10., -20., 1., 14., -11., 5., 12., 1910 + b -3., 1., -2., -2., 8., 2., 10., 0., 1910 + c -2., -1., 2., -3., -4., 2., 2., 1., 1910 + d -5., 2., -2., 6., 6., -4., 4., 0., 1910 + e 0., -2., 2., 4., 2., 0., 0., -6./ 1910 + data g3/ -31212.,-2306., 5875., -802., 2956.,-1191., 1309., 917., 1915 + 1 1084.,-1559., -421., 1212., 84., 778., 360., 887., 1915 + 2 678., 218., 631., -109., -416., -173., 178., -51., 1915 + 3 -211., 327., -148., 245., 58., -16., -34., -111., 1915 + 4 -126., -51., 32., 61., 57., -2., -10., 93., 1915 + 5 -228., 8., -51., -26., 49., 23., -98., -62., 1915 + 6 72., -54., -48., 2., -14., 31., -12., -38., 1915 + 7 2., -18., 28., 19., -15., 6., -22., 11., 1915 + 8 8., 8., -4., -15., -9., 6., 2., -13., 1915 + 9 3., 5., -8., 16., 6., -5., 8., -18., 1915 + a 8., 10., -20., 1., 14., -11., 5., 12., 1915 + b -3., 1., -2., -2., 8., 2., 10., 0., 1915 + c -2., -1., 2., -3., -4., 2., 2., 1., 1915 + d -5., 2., -2., 6., 6., -4., 4., 0., 1915 + e 0., -2., 1., 4., 2., 0., 0., -6./ 1915 + data g4/ -31060.,-2317., 5845., -839., 2959.,-1259., 1407., 823., 1920 + 1 1111.,-1600., -445., 1205., 103., 839., 293., 889., 1920 + 2 695., 220., 616., -134., -424., -153., 199., -57., 1920 + 3 -221., 326., -122., 236., 58., -23., -38., -119., 1920 + 4 -125., -62., 43., 61., 55., 0., -10., 96., 1920 + 5 -233., 11., -46., -22., 44., 18., -101., -57., 1920 + 6 73., -54., -49., 2., -14., 29., -13., -37., 1920 + 7 4., -16., 28., 19., -16., 6., -22., 11., 1920 + 8 7., 8., -3., -15., -9., 6., 2., -14., 1920 + 9 4., 5., -7., 17., 6., -5., 8., -19., 1920 + a 8., 10., -20., 1., 14., -11., 5., 12., 1920 + b -3., 1., -2., -2., 9., 2., 10., 0., 1920 + c -2., -1., 2., -3., -4., 2., 2., 1., 1920 + d -5., 2., -2., 6., 6., -4., 4., 0., 1920 + e 0., -2., 1., 4., 3., 0., 0., -6./ 1920 + data g5/ -30926.,-2318., 5817., -893., 2969.,-1334., 1471., 728., 1925 + 1 1140.,-1645., -462., 1202., 119., 881., 229., 891., 1925 + 2 711., 216., 601., -163., -426., -130., 217., -70., 1925 + 3 -230., 326., -96., 226., 58., -28., -44., -125., 1925 + 4 -122., -69., 51., 61., 54., 3., -9., 99., 1925 + 5 -238., 14., -40., -18., 39., 13., -103., -52., 1925 + 6 73., -54., -50., 3., -14., 27., -14., -35., 1925 + 7 5., -14., 29., 19., -17., 6., -21., 11., 1925 + 8 7., 8., -3., -15., -9., 6., 2., -14., 1925 + 9 4., 5., -7., 17., 7., -5., 8., -19., 1925 + a 8., 10., -20., 1., 14., -11., 5., 12., 1925 + b -3., 1., -2., -2., 9., 2., 10., 0., 1925 + c -2., -1., 2., -3., -4., 2., 2., 1., 1925 + d -5., 2., -2., 6., 6., -4., 4., 0., 1925 + e 0., -2., 1., 4., 3., 0., 0., -6./ 1925 + data g6/ -30805.,-2316., 5808., -951., 2980.,-1424., 1517., 644., 1930 + 1 1172.,-1692., -480., 1205., 133., 907., 166., 896., 1930 + 2 727., 205., 584., -195., -422., -109., 234., -90., 1930 + 3 -237., 327., -72., 218., 60., -32., -53., -131., 1930 + 4 -118., -74., 58., 60., 53., 4., -9., 102., 1930 + 5 -242., 19., -32., -16., 32., 8., -104., -46., 1930 + 6 74., -54., -51., 4., -15., 25., -14., -34., 1930 + 7 6., -12., 29., 18., -18., 6., -20., 11., 1930 + 8 7., 8., -3., -15., -9., 5., 2., -14., 1930 + 9 5., 5., -6., 18., 8., -5., 8., -19., 1930 + a 8., 10., -20., 1., 14., -12., 5., 12., 1930 + b -3., 1., -2., -2., 9., 3., 10., 0., 1930 + c -2., -2., 2., -3., -4., 2., 2., 1., 1930 + d -5., 2., -2., 6., 6., -4., 4., 0., 1930 + e 0., -2., 1., 4., 3., 0., 0., -6./ 1930 + data g7/ -30715.,-2306., 5812.,-1018., 2984.,-1520., 1550., 586., 1935 + 1 1206.,-1740., -494., 1215., 146., 918., 101., 903., 1935 + 2 744., 188., 565., -226., -415., -90., 249., -114., 1935 + 3 -241., 329., -51., 211., 64., -33., -64., -136., 1935 + 4 -115., -76., 64., 59., 53., 4., -8., 104., 1935 + 5 -246., 25., -25., -15., 25., 4., -106., -40., 1935 + 6 74., -53., -52., 4., -17., 23., -14., -33., 1935 + 7 7., -11., 29., 18., -19., 6., -19., 11., 1935 + 8 7., 8., -3., -15., -9., 5., 1., -15., 1935 + 9 6., 5., -6., 18., 8., -5., 7., -19., 1935 + a 8., 10., -20., 1., 15., -12., 5., 11., 1935 + b -3., 1., -3., -2., 9., 3., 11., 0., 1935 + c -2., -2., 2., -3., -4., 2., 2., 1., 1935 + d -5., 2., -2., 6., 6., -4., 4., 0., 1935 + e 0., -1., 2., 4., 3., 0., 0., -6./ 1935 + data g8/ -30654.,-2292., 5821.,-1106., 2981.,-1614., 1566., 528., 1940 + 1 1240.,-1790., -499., 1232., 163., 916., 43., 914., 1940 + 2 762., 169., 550., -252., -405., -72., 265., -141., 1940 + 3 -241., 334., -33., 208., 71., -33., -75., -141., 1940 + 4 -113., -76., 69., 57., 54., 4., -7., 105., 1940 + 5 -249., 33., -18., -15., 18., 0., -107., -33., 1940 + 6 74., -53., -52., 4., -18., 20., -14., -31., 1940 + 7 7., -9., 29., 17., -20., 5., -19., 11., 1940 + 8 7., 8., -3., -14., -10., 5., 1., -15., 1940 + 9 6., 5., -5., 19., 9., -5., 7., -19., 1940 + a 8., 10., -21., 1., 15., -12., 5., 11., 1940 + b -3., 1., -3., -2., 9., 3., 11., 1., 1940 + c -2., -2., 2., -3., -4., 2., 2., 1., 1940 + d -5., 2., -2., 6., 6., -4., 4., 0., 1940 + e 0., -1., 2., 4., 3., 0., 0., -6./ 1940 + data g9/ -30594.,-2285., 5810.,-1244., 2990.,-1702., 1578., 477., 1945 + 1 1282.,-1834., -499., 1255., 186., 913., -11., 944., 1945 + 2 776., 144., 544., -276., -421., -55., 304., -178., 1945 + 3 -253., 346., -12., 194., 95., -20., -67., -142., 1945 + 4 -119., -82., 82., 59., 57., 6., 6., 100., 1945 + 5 -246., 16., -25., -9., 21., -16., -104., -39., 1945 + 6 70., -40., -45., 0., -18., 0., 2., -29., 1945 + 7 6., -10., 28., 15., -17., 29., -22., 13., 1945 + 8 7., 12., -8., -21., -5., -12., 9., -7., 1945 + 9 7., 2., -10., 18., 7., 3., 2., -11., 1945 + a 5., -21., -27., 1., 17., -11., 29., 3., 1945 + b -9., 16., 4., -3., 9., -4., 6., -3., 1945 + c 1., -4., 8., -3., 11., 5., 1., 1., 1945 + d 2., -20., -5., -1., -1., -6., 8., 6., 1945 + e -1., -4., -3., -2., 5., 0., -2., -2./ 1945 + data ga/ -30554.,-2250., 5815.,-1341., 2998.,-1810., 1576., 381., 1950 + 1 1297.,-1889., -476., 1274., 206., 896., -46., 954., 1950 + 2 792., 136., 528., -278., -408., -37., 303., -210., 1950 + 3 -240., 349., 3., 211., 103., -20., -87., -147., 1950 + 4 -122., -76., 80., 54., 57., -1., 4., 99., 1950 + 5 -247., 33., -16., -12., 12., -12., -105., -30., 1950 + 6 65., -55., -35., 2., -17., 1., 0., -40., 1950 + 7 10., -7., 36., 5., -18., 19., -16., 22., 1950 + 8 15., 5., -4., -22., -1., 0., 11., -21., 1950 + 9 15., -8., -13., 17., 5., -4., -1., -17., 1950 + a 3., -7., -24., -1., 19., -25., 12., 10., 1950 + b 2., 5., 2., -5., 8., -2., 8., 3., 1950 + c -11., 8., -7., -8., 4., 13., -1., -2., 1950 + d 13., -10., -4., 2., 4., -3., 12., 6., 1950 + e 3., -3., 2., 6., 10., 11., 3., 8./ 1950 + data gb/ -30500.,-2215., 5820.,-1440., 3003.,-1898., 1581., 291., 1955 + 1 1302.,-1944., -462., 1288., 216., 882., -83., 958., 1955 + 2 796., 133., 510., -274., -397., -23., 290., -230., 1955 + 3 -229., 360., 15., 230., 110., -23., -98., -152., 1955 + 4 -121., -69., 78., 47., 57., -9., 3., 96., 1955 + 5 -247., 48., -8., -16., 7., -12., -107., -24., 1955 + 6 65., -56., -50., 2., -24., 10., -4., -32., 1955 + 7 8., -11., 28., 9., -20., 18., -18., 11., 1955 + 8 9., 10., -6., -15., -14., 5., 6., -23., 1955 + 9 10., 3., -7., 23., 6., -4., 9., -13., 1955 + a 4., 9., -11., -4., 12., -5., 7., 2., 1955 + b 6., 4., -2., 1., 10., 2., 7., 2., 1955 + c -6., 5., 5., -3., -5., -4., -1., 0., 1955 + d 2., -8., -3., -2., 7., -4., 4., 1., 1955 + e -2., -3., 6., 7., -2., -1., 0., -3./ 1955 + data gc/ -30421.,-2169., 5791.,-1555., 3002.,-1967., 1590., 206., 1960 + 1 1302.,-1992., -414., 1289., 224., 878., -130., 957., 1960 + 2 800., 135., 504., -278., -394., 3., 269., -255., 1960 + 3 -222., 362., 16., 242., 125., -26., -117., -156., 1960 + 4 -114., -63., 81., 46., 58., -10., 1., 99., 1960 + 5 -237., 60., -1., -20., -2., -11., -113., -17., 1960 + 6 67., -56., -55., 5., -28., 15., -6., -32., 1960 + 7 7., -7., 23., 17., -18., 8., -17., 15., 1960 + 8 6., 11., -4., -14., -11., 7., 2., -18., 1960 + 9 10., 4., -5., 23., 10., 1., 8., -20., 1960 + a 4., 6., -18., 0., 12., -9., 2., 1., 1960 + b 0., 4., -3., -1., 9., -2., 8., 3., 1960 + c 0., -1., 5., 1., -3., 4., 4., 1., 1960 + d 0., 0., -1., 2., 4., -5., 6., 1., 1960 + e 1., -1., -1., 6., 2., 0., 0., -7./ 1960 + data gd/ -30334.,-2119., 5776.,-1662., 2997.,-2016., 1594., 114., 1965 + 1 1297.,-2038., -404., 1292., 240., 856., -165., 957., 1965 + 2 804., 148., 479., -269., -390., 13., 252., -269., 1965 + 3 -219., 358., 19., 254., 128., -31., -126., -157., 1965 + 4 -97., -62., 81., 45., 61., -11., 8., 100., 1965 + 5 -228., 68., 4., -32., 1., -8., -111., -7., 1965 + 6 75., -57., -61., 4., -27., 13., -2., -26., 1965 + 7 6., -6., 26., 13., -23., 1., -12., 13., 1965 + 8 5., 7., -4., -12., -14., 9., 0., -16., 1965 + 9 8., 4., -1., 24., 11., -3., 4., -17., 1965 + a 8., 10., -22., 2., 15., -13., 7., 10., 1965 + b -4., -1., -5., -1., 10., 5., 10., 1., 1965 + c -4., -2., 1., -2., -3., 2., 2., 1., 1965 + d -5., 2., -2., 6., 4., -4., 4., 0., 1965 + e 0., -2., 2., 3., 2., 0., 0., -6./ 1965 + data ge/ -30220.,-2068., 5737.,-1781., 3000.,-2047., 1611., 25., 1970 + 1 1287.,-2091., -366., 1278., 251., 838., -196., 952., 1970 + 2 800., 167., 461., -266., -395., 26., 234., -279., 1970 + 3 -216., 359., 26., 262., 139., -42., -139., -160., 1970 + 4 -91., -56., 83., 43., 64., -12., 15., 100., 1970 + 5 -212., 72., 2., -37., 3., -6., -112., 1., 1970 + 6 72., -57., -70., 1., -27., 14., -4., -22., 1970 + 7 8., -2., 23., 13., -23., -2., -11., 14., 1970 + 8 6., 7., -2., -15., -13., 6., -3., -17., 1970 + 9 5., 6., 0., 21., 11., -6., 3., -16., 1970 + a 8., 10., -21., 2., 16., -12., 6., 10., 1970 + b -4., -1., -5., 0., 10., 3., 11., 1., 1970 + c -2., -1., 1., -3., -3., 1., 2., 1., 1970 + d -5., 3., -1., 4., 6., -4., 4., 0., 1970 + e 1., -1., 0., 3., 3., 1., -1., -4./ 1970 + data gf/ -30100.,-2013., 5675.,-1902., 3010.,-2067., 1632., -68., 1975 + 1 1276.,-2144., -333., 1260., 262., 830., -223., 946., 1975 + 2 791., 191., 438., -265., -405., 39., 216., -288., 1975 + 3 -218., 356., 31., 264., 148., -59., -152., -159., 1975 + 4 -83., -49., 88., 45., 66., -13., 28., 99., 1975 + 5 -198., 75., 1., -41., 6., -4., -111., 11., 1975 + 6 71., -56., -77., 1., -26., 16., -5., -14., 1975 + 7 10., 0., 22., 12., -23., -5., -12., 14., 1975 + 8 6., 6., -1., -16., -12., 4., -8., -19., 1975 + 9 4., 6., 0., 18., 10., -10., 1., -17., 1975 + a 7., 10., -21., 2., 16., -12., 7., 10., 1975 + b -4., -1., -5., -1., 10., 4., 11., 1., 1975 + c -3., -2., 1., -3., -3., 1., 2., 1., 1975 + d -5., 3., -2., 4., 5., -4., 4., -1., 1975 + e 1., -1., 0., 3., 3., 1., -1., -5./ 1975 + data gg/ -29992.,-1956., 5604.,-1997., 3027.,-2129., 1663., -200., 1980 + 1 1281.,-2180., -336., 1251., 271., 833., -252., 938., 1980 + 2 782., 212., 398., -257., -419., 53., 199., -297., 1980 + 3 -218., 357., 46., 261., 150., -74., -151., -162., 1980 + 4 -78., -48., 92., 48., 66., -15., 42., 93., 1980 + 5 -192., 71., 4., -43., 14., -2., -108., 17., 1980 + 6 72., -59., -82., 2., -27., 21., -5., -12., 1980 + 7 16., 1., 18., 11., -23., -2., -10., 18., 1980 + 8 6., 7., 0., -18., -11., 4., -7., -22., 1980 + 9 4., 9., 3., 16., 6., -13., -1., -15., 1980 + a 5., 10., -21., 1., 16., -12., 9., 9., 1980 + b -5., -3., -6., -1., 9., 7., 10., 2., 1980 + c -6., -5., 2., -4., -4., 1., 2., 0., 1980 + d -5., 3., -2., 6., 5., -4., 3., 0., 1980 + e 1., -1., 2., 4., 3., 0., 0., -6./ 1980 + data gi/ -29873.,-1905., 5500.,-2072., 3044.,-2197., 1687., -306., 1985 + 1 1296.,-2208., -310., 1247., 284., 829., -297., 936., 1985 + 2 780., 232., 361., -249., -424., 69., 170., -297., 1985 + 3 -214., 355., 47., 253., 150., -93., -154., -164., 1985 + 4 -75., -46., 95., 53., 65., -16., 51., 88., 1985 + 5 -185., 69., 4., -48., 16., -1., -102., 21., 1985 + 6 74., -62., -83., 3., -27., 24., -2., -6., 1985 + 7 20., 4., 17., 10., -23., 0., -7., 21., 1985 + 8 6., 8., 0., -19., -11., 5., -9., -23., 1985 + 9 4., 11., 4., 14., 4., -15., -4., -11., 1985 + a 5., 10., -21., 1., 15., -12., 9., 9., 1985 + b -6., -3., -6., -1., 9., 7., 9., 1., 1985 + c -7., -5., 2., -4., -4., 1., 3., 0., 1985 + d -5., 3., -2., 6., 5., -4., 3., 0., 1985 + e 1., -1., 2., 4., 3., 0., 0., -6./ 1985 + data gj/ -29775.,-1848., 5406.,-2131., 3059.,-2279., 1686., -373., 1990 + 1 1314.,-2239., -284., 1248., 293., 802., -352., 939., 1990 + 2 780., 247., 325., -240., -423., 84., 141., -299., 1990 + 3 -214., 353., 46., 245., 154., -109., -153., -165., 1990 + 4 -69., -36., 97., 61., 65., -16., 59., 82., 1990 + 5 -178., 69., 3., -52., 18., 1., -96., 24., 1990 + 6 77., -64., -80., 2., -26., 26., 0., -1., 1990 + 7 21., 5., 17., 9., -23., 0., -4., 23., 1990 + 8 5., 10., -1., -19., -10., 6., -12., -22., 1990 + 9 3., 12., 4., 12., 2., -16., -6., -10., 1990 + a 4., 9., -20., 1., 15., -12., 11., 9., 1990 + b -7., -4., -7., -2., 9., 7., 8., 1., 1990 + c -7., -6., 2., -3., -4., 2., 2., 1., 1990 + d -5., 3., -2., 6., 4., -4., 3., 0., 1990 + e 1., -2., 3., 3., 3., -1., 0., -6./ 1990 + data gk/ -29692.,-1784., 5306.,-2200., 3070.,-2366., 1681., -413., 1995 + 1 1335.,-2267., -262., 1249., 302., 759., -427., 940., 1995 + 2 780., 262., 290., -236., -418., 97., 122., -306., 1995 + 3 -214., 352., 46., 235., 165., -118., -143., -166., 1995 + 4 -55., -17., 107., 68., 67., -17., 68., 72., 1995 + 5 -170., 67., -1., -58., 19., 1., -93., 36., 1995 + 6 77., -72., -69., 1., -25., 28., 4., 5., 1995 + 7 24., 4., 17., 8., -24., -2., -6., 25., 1995 + 8 6., 11., -6., -21., -9., 8., -14., -23., 1995 + 9 9., 15., 6., 11., -5., -16., -7., -4., 1995 + a 4., 9., -20., 3., 15., -10., 12., 8., 1995 + b -6., -8., -8., -1., 8., 10., 5., -2., 1995 + c -8., -8., 3., -3., -6., 1., 2., 0., 1995 + d -4., 4., -1., 5., 4., -5., 2., -1., 1995 + e 2., -2., 5., 1., 1., -2., 0., -7., 1995 + f 75*0./ 1995 + data gl/ -29619.4,-1728.2, 5186.1,-2267.7, 3068.4,-2481.6, 1670.9, 2000 + 1 -458.0, 1339.6,-2288.0, -227.6, 1252.1, 293.4, 714.5, 2000 + 2 -491.1, 932.3, 786.8, 272.6, 250.0, -231.9, -403.0, 2000 + 3 119.8, 111.3, -303.8, -218.8, 351.4, 43.8, 222.3, 2000 + 4 171.9, -130.4, -133.1, -168.6, -39.3, -12.9, 106.3, 2000 + 5 72.3, 68.2, -17.4, 74.2, 63.7, -160.9, 65.1, 2000 + 6 -5.9, -61.2, 16.9, 0.7, -90.4, 43.8, 79.0, 2000 + 7 -74.0, -64.6, 0.0, -24.2, 33.3, 6.2, 9.1, 2000 + 8 24.0, 6.9, 14.8, 7.3, -25.4, -1.2, -5.8, 2000 + 9 24.4, 6.6, 11.9, -9.2, -21.5, -7.9, 8.5, 2000 + a -16.6, -21.5, 9.1, 15.5, 7.0, 8.9, -7.9, 2000 + b -14.9, -7.0, -2.1, 5.0, 9.4, -19.7, 3.0, 2000 + c 13.4, -8.4, 12.5, 6.3, -6.2, -8.9, -8.4, 2000 + d -1.5, 8.4, 9.3, 3.8, -4.3, -8.2, -8.2, 2000 + e 4.8, -2.6, -6.0, 1.7, 1.7, 0.0, -3.1, 2000 + f 4.0, -0.5, 4.9, 3.7, -5.9, 1.0, -1.2, 2000 + g 2.0, -2.9, 4.2, 0.2, 0.3, -2.2, -1.1, 2000 + h -7.4, 2.7, -1.7, 0.1, -1.9, 1.3, 1.5, 2000 + i -0.9, -0.1, -2.6, 0.1, 0.9, -0.7, -0.7, 2000 + j 0.7, -2.8, 1.7, -0.9, 0.1, -1.2, 1.2, 2000 + k -1.9, 4.0, -0.9, -2.2, -0.3, -0.4, 0.2, 2000 + l 0.3, 0.9, 2.5, -0.2, -2.6, 0.9, 0.7, 2000 + m -0.5, 0.3, 0.3, 0.0, -0.3, 0.0, -0.4, 2000 + n 0.3, -0.1, -0.9, -0.2, -0.4, -0.4, 0.8, 2000 + o -0.2, -0.9, -0.9, 0.3, 0.2, 0.1, 1.8, 2000 + p -0.4, -0.4, 1.3, -1.0, -0.4, -0.1, 0.7, 2000 + q 0.7, -0.4, 0.3, 0.3, 0.6, -0.1, 0.3, 2000 + r 0.4, -0.2, 0.0, -0.5, 0.1, -0.9/ 2000 + data gm/-29554.63,-1669.05, 5077.99,-2337.24, 3047.69,-2594.50, 2005 + 1 1657.76, -515.43, 1336.30,-2305.83, -198.86, 1246.39, 2005 + 2 269.72, 672.51, -524.72, 920.55, 797.96, 282.07, 2005 + 3 210.65, -225.23, -379.86, 145.15, 100.00, -305.36, 2005 + 4 -227.00, 354.41, 42.72, 208.95, 180.25, -136.54, 2005 + 5 -123.45, -168.05, -19.57, -13.55, 103.85, 73.60, 2005 + 6 69.56, -20.33, 76.74, 54.75, -151.34, 63.63, 2005 + 7 -14.58, -63.53, 14.58, 0.24, -86.36, 50.94, 2005 + 8 79.88, -74.46, -61.14, -1.65, -22.57, 38.73, 2005 + 9 6.82, 12.30, 25.35, 9.37, 10.93, 5.42, 2005 + a -26.32, 1.94, -4.64, 24.80, 7.62, 11.20, 2005 + b -11.73, -20.88, -6.88, 9.83, -18.11, -19.71, 2005 + c 10.17, 16.22, 9.36, 7.61, -11.25, -12.76, 2005 + d -4.87, -0.06, 5.58, 9.76, -20.11, 3.58, 2005 + e 12.69, -6.94, 12.67, 5.01, -6.72, -10.76, 2005 + f -8.16, -1.25, 8.10, 8.76, 2.92, -6.66, 2005 + g -7.73, -9.22, 6.01, -2.17, -6.12, 2.19, 2005 + h 1.42, 0.10, -2.35, 4.46, -0.15, 4.76, 2005 + i 3.06, -6.58, 0.29, -1.01, 2.06, -3.47, 2005 + j 3.77, -0.86, -0.21, -2.31, -2.09, -7.93, 2005 + k 2.95, -1.60, 0.26, -1.88, 1.44, 1.44, 2005 + l -0.77, -0.31, -2.27, 0.29, 0.90, -0.79, 2005 + m -0.58, 0.53, -2.69, 1.80, -1.08, 0.16, 2005 + n -1.58, 0.96, -1.90, 3.99, -1.39, -2.15, 2005 + o -0.29, -0.55, 0.21, 0.23, 0.89, 2.38, 2005 + p -0.38, -2.63, 0.96, 0.61, -0.30, 0.40, 2005 + q 0.46, 0.01, -0.35, 0.02, -0.36, 0.28, 2005 + r 0.08, -0.87, -0.49, -0.34, -0.08, 0.88, 2005 + s -0.16, -0.88, -0.76, 0.30, 0.33, 0.28, 2005 + t 1.72, -0.43, -0.54, 1.18, -1.07, -0.37, 2005 + u -0.04, 0.75, 0.63, -0.26, 0.21, 0.35, 2005 + v 0.53, -0.05, 0.38, 0.41, -0.22, -0.10, 2005 + w -0.57, -0.18, -0.82/ 2005 + data gp/-29496.57,-1586.42, 4944.26,-2396.06, 3026.34,-2708.54, 2010 + 1 1668.17, -575.73, 1339.85,-2326.54, -160.40, 1232.10, 2010 + 2 251.75, 633.73, -537.03, 912.66, 808.97, 286.48, 2010 + 3 166.58, -211.03, -356.83, 164.46, 89.40, -309.72, 2010 + 4 -230.87, 357.29, 44.58, 200.26, 189.01, -141.05, 2010 + 5 -118.06, -163.17, -0.01, -8.03, 101.04, 72.78, 2010 + 6 68.69, -20.90, 75.92, 44.18, -141.40, 61.54, 2010 + 7 -22.83, -66.26, 13.10, 3.02, -78.09, 55.40, 2010 + 8 80.44, -75.00, -57.80, -4.55, -21.20, 45.24, 2010 + 9 6.54, 14.00, 24.96, 10.46, 7.03, 1.64, 2010 + a -27.61, 4.92, -3.28, 24.41, 8.21, 10.84, 2010 + b -14.50, -20.03, -5.59, 11.83, -19.34, -17.41, 2010 + c 11.61, 16.71, 10.85, 6.96, -14.05, -10.74, 2010 + d -3.54, 1.64, 5.50, 9.45, -20.54, 3.45, 2010 + e 11.51, -5.27, 12.75, 3.13, -7.14, -12.38, 2010 + f -7.42, -0.76, 7.97, 8.43, 2.14, -8.42, 2010 + g -6.08, -10.08, 7.01, -1.94, -6.24, 2.73, 2010 + h 0.89, -0.10, -1.07, 4.71, -0.16, 4.44, 2010 + i 2.45, -7.22, -0.33, -0.96, 2.13, -3.95, 2010 + j 3.09, -1.99, -1.03, -1.97, -2.80, -8.31, 2010 + k 3.05, -1.48, 0.13, -2.03, 1.67, 1.65, 2010 + l -0.66, -0.51, -1.76, 0.54, 0.85, -0.79, 2010 + m -0.39, 0.37, -2.51, 1.79, -1.27, 0.12, 2010 + n -2.11, 0.75, -1.94, 3.75, -1.86, -2.12, 2010 + o -0.21, -0.87, 0.30, 0.27, 1.04, 2.13, 2010 + p -0.63, -2.49, 0.95, 0.49, -0.11, 0.59, 2010 + q 0.52, 0.00, -0.39, 0.13, -0.37, 0.27, 2010 + r 0.21, -0.86, -0.77, -0.23, 0.04, 0.87, 2010 + s -0.09, -0.89, -0.87, 0.31, 0.30, 0.42, 2010 + t 1.66, -0.45, -0.59, 1.08, -1.14, -0.31, 2010 + u -0.07, 0.78, 0.54, -0.18, 0.10, 0.38, 2010 + v 0.49, 0.02, 0.44, 0.42, -0.25, -0.26, 2010 + w -0.53, -0.26, -0.79/ 2010 + data gq/-29441.46,-1501.77, 4795.99,-2445.88, 3012.20,-2845.41, 2015 + 1 1676.35, -642.17, 1350.33,-2352.26, -115.29, 1225.85, 2015 + 2 245.04, 581.69, -538.70, 907.42, 813.68, 283.54, 2015 + 3 120.49, -188.43, -334.85, 180.95, 70.38, -329.23, 2015 + 4 -232.91, 360.14, 46.98, 192.35, 196.98, -140.94, 2015 + 5 -119.14, -157.40, 15.98, 4.30, 100.12, 69.55, 2015 + 6 67.57, -20.61, 72.79, 33.30, -129.85, 58.74, 2015 + 7 -28.93, -66.64, 13.14, 7.35, -70.85, 62.41, 2015 + 8 81.29, -75.99, -54.27, -6.79, -19.53, 51.82, 2015 + 9 5.59, 15.07, 24.45, 9.32, 3.27, -2.88, 2015 + a -27.50, 6.61, -2.32, 23.98, 8.89, 10.04, 2015 + b -16.78, -18.26, -3.16, 13.18, -20.56, -14.60, 2015 + c 13.33, 16.16, 11.76, 5.69, -15.98, -9.10, 2015 + d -2.02, 2.26, 5.33, 8.83, -21.77, 3.02, 2015 + e 10.76, -3.22, 11.74, 0.67, -6.74, -13.20, 2015 + f -6.88, -0.10, 7.79, 8.68, 1.04, -9.06, 2015 + g -3.89, -10.54, 8.44, -2.01, -6.26, 3.28, 2015 + h 0.17, -0.40, 0.55, 4.55, -0.55, 4.40, 2015 + i 1.70, -7.92, -0.67, -0.61, 2.13, -4.16, 2015 + j 2.33, -2.85, -1.80, -1.12, -3.59, -8.72, 2015 + k 3.00, -1.40, 0.00, -2.30, 2.11, 2.08, 2015 + l -0.60, -0.79, -1.05, 0.58, 0.76, -0.70, 2015 + m -0.20, 0.14, -2.12, 1.70, -1.44, -0.22, 2015 + n -2.57, 0.44, -2.01, 3.49, -2.34, -2.09, 2015 + o -0.16, -1.08, 0.46, 0.37, 1.23, 1.75, 2015 + p -0.89, -2.19, 0.85, 0.27, 0.10, 0.72, 2015 + q 0.54, -0.09, -0.37, 0.29, -0.43, 0.23, 2015 + r 0.22, -0.89, -0.94, -0.16, -0.03, 0.72, 2015 + s -0.02, -0.92, -0.88, 0.42, 0.49, 0.63, 2015 + t 1.56, -0.42, -0.50, 0.96, -1.24, -0.19, 2015 + u -0.10, 0.81, 0.42, -0.13, -0.04, 0.38, 2015 + v 0.48, 0.08, 0.48, 0.46, -0.30, -0.35, 2015 + w -0.43, -0.36, -0.71/ 2015 + data gr/-29403.41,-1451.37, 4653.35,-2499.78, 2981.96,-2991.72, 2020 + 1 1676.85, -734.62, 1363.00,-2380.80, -81.96, 1236.06, 2020 + 2 241.80, 525.60, -542.52, 902.82, 809.47, 282.10, 2020 + 3 86.18, -158.50, -309.47, 199.75, 47.44, -350.30, 2020 + 4 -234.42, 363.26, 47.52, 187.86, 208.36, -140.73, 2020 + 5 -121.43, -151.16, 32.09, 13.98, 99.14, 65.97, 2020 + 6 65.56, -19.22, 72.96, 25.02, -121.57, 52.76, 2020 + 7 -36.06, -64.40, 13.60, 8.96, -64.80, 68.04, 2020 + 8 80.54, -76.63, -51.50, -8.23, -16.85, 56.45, 2020 + 9 2.36, 15.80, 23.56, 6.30, -2.19, -7.21, 2020 + a -27.19, 9.77, -1.90, 23.66, 9.74, 8.43, 2020 + b -17.49, -15.23, -0.49, 12.83, -21.07, -11.76, 2020 + c 15.28, 14.94, 13.65, 3.62, -16.59, -6.90, 2020 + d -0.34, 2.90, 5.03, 8.36, -23.44, 2.84, 2020 + e 11.04, -1.48, 9.86, -1.14, -5.13, -13.22, 2020 + f -6.20, 1.08, 7.79, 8.82, 0.40, -9.23, 2020 + g -1.44, -11.86, 9.60, -1.84, -6.25, 3.38, 2020 + h -0.11, -0.18, 1.66, 3.50, -0.86, 4.86, 2020 + i 0.65, -8.62, -0.88, -0.11, 1.88, -4.26, 2020 + j 1.44, -3.43, -2.38, -0.10, -3.84, -8.84, 2020 + k 2.96, -1.36, -0.02, -2.51, 2.50, 2.31, 2020 + l -0.55, -0.85, -0.39, 0.28, 0.62, -0.66, 2020 + m -0.21, -0.07, -1.66, 1.44, -1.60, -0.59, 2020 + n -2.98, 0.18, -1.97, 3.09, -2.51, -2.00, 2020 + o -0.13, -1.15, 0.43, 0.52, 1.28, 1.37, 2020 + p -1.14, -1.81, 0.71, 0.08, 0.31, 0.71, 2020 + q 0.49, -0.15, -0.26, 0.55, -0.47, 0.16, 2020 + r 0.09, -0.93, -1.13, -0.04, -0.33, 0.52, 2020 + s 0.08, -0.93, -0.88, 0.53, 0.64, 0.72, 2020 + t 1.40, -0.30, -0.38, 0.75, -1.31, -0.01, 2020 + u -0.09, 0.76, 0.29, -0.05, -0.11, 0.37, 2020 + v 0.47, 0.13, 0.54, 0.45, -0.41, -0.46, 2020 + w -0.36, -0.40, -0.60/ 2020 + data gs/ -29350.0, -1410.3, 4545.5, -2556.2, 2950.9, -3133.6, 2025 + 1 1648.7, -814.2, 1360.9, -2404.2, -56.9, 1243.8, 2025 + 2 237.6, 453.4, -549.6, 894.7, 799.6, 278.6, 2025 + 3 55.8, -134.0, -281.1, 212.0, 12.0, -375.4, 2025 + 4 -232.9, 369.0, 45.3, 187.2, 220.0, -138.7, 2025 + 5 -122.9, -141.9, 42.9, 20.9, 106.2, 64.3, 2025 + 6 63.8, -18.4, 76.7, 16.8, -115.7, 48.9, 2025 + 7 -40.9, -59.8, 14.9, 10.9, -60.8, 72.8, 2025 + 8 79.6, -76.9, -48.9, -8.8, -14.4, 59.3, 2025 + 9 -1.0, 15.8, 23.5, 2.5, -7.4, -11.2, 2025 + a -25.1, 14.3, -2.2, 23.1, 10.9, 7.2, 2025 + b -17.5, -12.6, 2.0, 11.5, -21.8, -9.7, 2025 + c 16.9, 12.7, 14.9, 0.7, -16.8, -5.2, 2025 + d 1.0, 3.9, 4.7, 8.0, -24.8, 3.0, 2025 + e 12.1, -0.2, 8.3, -2.5, -3.4, -13.1, 2025 + f -5.3, 2.4, 7.2, 8.6, -0.6, -8.7, 2025 + g 0.8, -12.8, 9.8, -1.3, -6.4, 3.3, 2025 + h 0.2, 0.1, 2.0, 2.5, -1.0, 5.4, 2025 + i -0.5, -9.0, -0.9, 0.4, 1.5, -4.2, 2025 + j 0.9, -3.8, -2.6, 0.9, -3.9, -9.0, 2025 + k 3.0, -1.4, 0.0, -2.5, 2.8, 2.4, 2025 + l -0.6, -0.6, 0.1, 0.0, 0.5, -0.6, 2025 + m -0.3, -0.1, -1.2, 1.1, -1.7, -1.0, 2025 + n -2.9, -0.1, -1.8, 2.6, -2.3, -2.0, 2025 + o -0.1, -1.2, 0.4, 0.6, 1.2, 1.0, 2025 + p -1.2, -1.5, 0.6, 0.0, 0.5, 0.6, 2025 + q 0.5, -0.2, -0.1, 0.8, -0.5, 0.1, 2025 + r -0.2, -0.9, -1.2, 0.1, -0.7, 0.2, 2025 + s 0.2, -0.9, -0.9, 0.6, 0.7, 0.7, 2025 + t 1.2, -0.2, -0.3, 0.5, -1.3, 0.1, 2025 + u -0.1, 0.7, 0.2, 0.0, -0.2, 0.3, 2025 + v 0.5, 0.2, 0.6, 0.4, -0.6, -0.5, 2025 + w -0.3, -0.4, -0.5/ 2025 + data gt/ 12.6, 10.0, -21.5, -11.2, -5.3, -27.3, 2027 + 1 -8.3, -11.1, -1.5, -4.4, 3.8, 0.4, 2027 + 2 -0.2, -15.6, -3.9, -1.7, -2.3, -1.3, 2027 + 3 -5.8, 4.1, 5.4, 1.6, -6.8, -4.1, 2027 + 4 0.6, 1.3, -0.5, 0.0, 2.1, 0.7, 2027 + 5 0.5, 2.3, 1.7, 1.0, 1.9, -0.2, 2027 + 6 -0.3, 0.3, 0.8, -1.6, 1.2, -0.4, 2027 + 7 -0.8, 0.8, 0.4, 0.7, 0.9, 0.9, 2027 + 8 -0.1, -0.1, 0.6, -0.1, 0.5, 0.5, 2027 + 9 -0.7, -0.1, 0.0, -0.8, -0.9, -0.8, 2027 + a 0.5, 0.9, -0.3, -0.1, 0.2, -0.3, 2027 + b 0.0, 0.4, 0.4, -0.3, -0.1, 0.4, 2027 + c 0.3, -0.5, 0.1, -0.6, 0.0, 0.3, 2027 + d 0.3, 0.2, 115*0.0/ 2027 +c +c set initial values +c + x = 0.0 + y = 0.0 + z = 0.0 + if (date.lt.1900.0.or.date.gt.2035.0) go to 11 + if (date.gt.2030.0) write (6,960) date + 960 format (/' This version of the IGRF is intended for use up', + 1 ' to 2030.0.'/' values for',f9.3,' will be computed', + 2 ' but may be of reduced accuracy'/) + if (date.ge.2025.0) go to 1 + t = 0.2*(date - 1900.0) + ll = t + one = ll + t = t - one +c +c SH models before 1995.0 are only to degree 10 +c + if (date.lt.1995.0) then + nmx = 10 + nc = nmx*(nmx+2) + ll = nc*ll + kmx = (nmx+1)*(nmx+2)/2 + else + nmx = 13 + nc = nmx*(nmx+2) + ll = 0.2*(date - 1995.0) +c +c 19 is the number of SH models that extend to degree 10 +c + ll = 120*19 + nc*ll + kmx = (nmx+1)*(nmx+2)/2 + endif + tc = 1.0 - t + if (isv.eq.1) then + tc = -0.2 + t = 0.2 + end if + go to 2 +c + 1 t = date - 2025.0 + tc = 1.0 + if (isv.eq.1) then + t = 1.0 + tc = 0.0 + end if +c +c pointer for last coefficient in pen-ultimate set of MF coefficients... +c + ll = 3450 + nmx = 13 + nc = nmx*(nmx+2) + kmx = (nmx+1)*(nmx+2)/2 + 2 r = alt + one = colat*0.017453292 + ct = cos(one) + st = sin(one) + one = elong*0.017453292 + cl(1) = cos(one) + sl(1) = sin(one) + cd = 1.0 + sd = 0.0 + l = 1 + m = 1 + n = 0 + if (itype.eq.2) go to 3 +c +c conversion from geodetic to geocentric coordinates +c (using the WGS84 spheroid) +c + a2 = 40680631.6 + b2 = 40408296.0 + one = a2*st*st + two = b2*ct*ct + three = one + two + rho = sqrt(three) + r = sqrt(alt*(alt + 2.0*rho) + (a2*one + b2*two)/three) + cd = (alt + rho)/r + sd = (a2 - b2)/rho*ct*st/r + one = ct + ct = ct*cd - st*sd + st = st*cd + one*sd +c + 3 ratio = 6371.2/r + rr = ratio*ratio +c +c computation of Schmidt quasi-normal coefficients p and x(=q) +c + p(1) = 1.0 + p(3) = st + q(1) = 0.0 + q(3) = ct + do 10 k=2,kmx + if (n.ge.m) go to 4 + m = 0 + n = n + 1 + rr = rr*ratio + fn = n + gn = n - 1 + 4 fm = m + if (m.ne.n) go to 5 + if (k.eq.3) go to 6 + one = sqrt(1.0 - 0.5/fm) + j = k - n - 1 + p(k) = one*st*p(j) + q(k) = one*(st*q(j) + ct*p(j)) + cl(m) = cl(m-1)*cl(1) - sl(m-1)*sl(1) + sl(m) = sl(m-1)*cl(1) + cl(m-1)*sl(1) + go to 6 + 5 gmm = m*m + one = sqrt(fn*fn - gmm) + two = sqrt(gn*gn - gmm)/one + three = (fn + gn)/one + i = k - n + j = i - n + 1 + p(k) = three*ct*p(i) - two*p(j) + q(k) = three*(ct*q(i) - st*p(i)) - two*q(j) +c +c synthesis of x, y and z in geocentric coordinates +c + 6 lm = ll + l + one = (tc*gh(lm) + t*gh(lm+nc))*rr + if (m.eq.0) go to 9 + two = (tc*gh(lm+1) + t*gh(lm+nc+1))*rr + three = one*cl(m) + two*sl(m) + x = x + three*q(k) + z = z - (fn + 1.0)*three*p(k) + if (st.eq.0.0) go to 7 + y = y + (one*sl(m) - two*cl(m))*fm*p(k)/st + go to 8 + 7 y = y + (one*sl(m) - two*cl(m))*q(k)*ct + 8 l = l + 2 + go to 10 + 9 x = x + one*q(k) + z = z - (fn + 1.0)*one*p(k) + l = l + 1 + 10 m = m + 1 +c +c conversion to coordinate system specified by itype +c + one = x + x = x*cd + z*sd + z = z*cd - one*sd + f = sqrt(x*x + y*y + z*z) +c + return +c +c error return if date out of bounds +c + 11 f = 1.0d8 + write (6,961) date + 961 format (/' This subroutine will not work with a date of', + 1 f9.3,'. Date must be in the range 1900.0.ge.date', + 2 '.le.2035.0. On return f = 1.0d8., x = y = z = 0.') + return + end diff --git a/test/qualification/diffusion_scale.f90 b/test/qualification/diffusion_scale.f90 new file mode 100644 index 000000000..035ea7572 --- /dev/null +++ b/test/qualification/diffusion_scale.f90 @@ -0,0 +1,25 @@ +program diffusion_scale +use phys_consts, only: wp +use PDEparabolic, only: backEuler1D,TRBDF21D +implicit none(type,external) +integer,parameter::n=49 +real(wp)::u(n),initial(n),a(n),b(n),c(n),d(n),e(n),dx(0:n+2),dxi(n),dt,err,bcerr +integer::i,method +logical::passed +a=0;b=0;c=1e18_wp;d=3e-5_wp;e=0 +dx=1e5_wp/(n-1);dxi=dx(1);dt=6.25e-5_wp +initial=[(600+900._wp*(i-1)/(n-1),i=1,n)] +passed=.true. +do method=1,2 + u=initial + if(method==1)then + u=backEuler1D(u,a,b,c,d,e,600._wp,1500._wp,dt,[0,0],dx,dxi) + else + u=TRBDF21D(u,a,b,c,d,e,600._wp,1500._wp,dt,[0,0],dx,dxi) + endif + err=maxval(abs(u-initial));bcerr=max(abs(u(1)-600),abs(u(n)-1500)) + print '(i0,2(1x,es25.17))',method,err,bcerr + passed=passed.and.bcerr<=1e-11_wp +enddo +if(.not.passed)error stop 'prescribed boundary temperature lost under SI coefficient scaling' +end program diff --git a/test/qualification/energy_operator_balance.f90 b/test/qualification/energy_operator_balance.f90 new file mode 100644 index 000000000..a00a759ea --- /dev/null +++ b/test/qualification/energy_operator_balance.f90 @@ -0,0 +1,66 @@ +program energy_operator_balance +use phys_consts, only: wp +use PDEparabolic, only: backEuler1D,TRBDF21D +use diffusion, only: backEuler3D,TRBDF23D +use meshobj_cart, only: cartmesh +use, intrinsic :: ieee_arithmetic, only: ieee_is_finite +implicit none +integer,parameter :: n=13 +real(wp) :: old(n),y(n),a(n),b(n),c(n),d(n),e(n),dx(0:n+2),dxi(n),terms(n,5),dt,err,scale +real(wp) :: old3(-1:n+2,-1:3,-1:3),new3(-1:n+2,-1:3,-1:3),plain3(-1:n+2,-1:3,-1:3) +real(wp) :: aa(n,1,1),zz(n,1,1),cc(n,1,1),terms3(n,1,1,5) +type(cartmesh) :: x +integer :: i,method,bc1,bc2,probe +! Nonuniform mesh, variable coefficients, and both boundary types. Independently +! reconstruct the discrete PDE budget, including prescribed nodal endpoints. +dx=[(0.7_wp+0.03_wp*i,i=0,n+2)];dxi=0.5_wp*(dx(1:n)+dx(2:n+1)) +do probe=1,3 + if(probe==1)dt=0.0001_wp + if(probe==2)dt=0.1_wp + if(probe==3)dt=2._wp + old=[(2+sin(real(i,wp)),i=1,n)] + a=-0.3_wp;b=0.12_wp;c=0.8_wp;d=[(1+0.02_wp*i,i=1,n)];e=0.9_wp + do method=1,2 + do bc1=0,1 + do bc2=0,1 + if(method==1)then + y=backEuler1D(old,a,b,c,d,e,1.2_wp,2.4_wp,dt,[bc1,bc2],dx,dxi,increments=terms) + else + y=TRBDF21D(old,a,b,c,d,e,1.2_wp,2.4_wp,dt,[bc1,bc2],dx,dxi, & + Tsmin_mid=0.6_wp,Tsmax_mid=1.7_wp,increments=terms) + endif + scale=max(1._wp,maxval(abs(y)),maxval(abs(old))) + err=maxval(abs(y-old-sum(terms,2)))/scale + if(.not.all(ieee_is_finite(y)).or.err>1e-11_wp) error stop 'Parabolic stage balance' + if(any(terms(2:n-1,5)/=0)) error stop 'Interior residual attributed to boundary' + if(any(terms(1,1:4)/=0).or.any(terms(n,1:4)/=0)) error stop 'Boundary solved as PDE' + enddo + enddo + enddo +enddo +! Source-free pure conduction must telescope with reciprocal C volume weights. +a=0;b=0;e=0;dt=0.1_wp +c=[(0.5_wp+0.03_wp*i,i=1,n)] +y=backEuler1D(old,a,b,c,d,e,1.2_wp,2.4_wp,dt,[0,0],dx,dxi,increments=terms) +err=abs(sum(terms(2:n-1,3)*dxi(2:n-1)/c(2:n-1)) - dt* & + (0.5_wp*(d(n)+d(n-1))*(y(n)-y(n-1))/dx(n) - 0.5_wp*(d(1)+d(2))*(y(2)-y(1))/dx(2))) +if(err>1e-11_wp) error stop 'Conductive face telescoping' +! Wrappers must preserve every halo cell; compare requested and absent ledger. +allocate(x%dx1(0:n+2),x%dx1i(n)) +x%dx1=dx;x%dx1i=dxi +old3=321._wp;old3(1:n,1,1)=old;old3(0,1,1)=1.2_wp;old3(n+1,1,1)=2.4_wp +aa=-0.1_wp;zz=0;cc=1 +new3=TRBDF23D(old3,aa,zz,cc,cc,zz,dt,x,terms3) +plain3=TRBDF23D(old3,aa,zz,cc,cc,zz,dt,x) +if(.not.all(ieee_is_finite(plain3)).or.any(plain3/=new3)) error stop 'TR diagnostics changed result' +if(any(new3(-1,:,:)/=old3(-1,:,:)).or.any(new3(:,0,:)/=old3(:,0,:))) error stop 'TR halos undefined' +err=maxval(abs(new3(1:n,1,1)-old-sum(terms3(:,1,1,:),2))) +if(err>1e-11_wp) error stop '3D TR ledger' +new3=backEuler3D(old3,aa,zz,cc,cc,zz,dt,x,terms3) +plain3=backEuler3D(old3,aa,zz,cc,cc,zz,dt,x) +if(.not.all(ieee_is_finite(plain3)).or.any(plain3/=new3)) error stop 'BE diagnostics changed result' +err=maxval(abs(new3(1:n,1,1)-old-sum(terms3(:,1,1,:),2))) +if(err>1e-11_wp) error stop '3D BE ledger' +if(any(new3(n+2,:,:)/=old3(n+2,:,:)).or.any(new3(:,:,3)/=old3(:,:,3))) error stop 'BE halos undefined' +print '(a)', 'PASS: 24 parabolic cases; face telescoping; 3D ledgers and defined halos' +end program diff --git a/test/qualification/etd_probe.f90 b/test/qualification/etd_probe.f90 new file mode 100644 index 000000000..67fa29f27 --- /dev/null +++ b/test/qualification/etd_probe.f90 @@ -0,0 +1,15 @@ +! SPDX-License-Identifier: Apache-2.0 +program etd_probe +use phys_consts, only: wp +use calculus, only: ETD_uncoupled +implicit none(type,external) +real(wp) :: f(1,1,1),p(1,1,1),l(1,1,1),y(1,1,1),dt +integer :: ios +do + read(*,*,iostat=ios) f,p,l,dt + if(ios<0) exit + if(ios/=0) error stop 'Expected f P L dt' + y=ETD_uncoupled(f,p,l,dt) + write(*,'(ES26.17E3)') y +enddo +end program diff --git a/test/qualification/igrf_reference.f90 b/test/qualification/igrf_reference.f90 new file mode 100644 index 000000000..2c695edb1 --- /dev/null +++ b/test/qualification/igrf_reference.f90 @@ -0,0 +1,12 @@ +program igrf_reference +implicit none +real(8) :: year,radius,colat,lon,x,y,z,f +integer :: ios +external :: igrf14syn +do + read(*,*,iostat=ios) year,radius,colat,lon + if(ios/=0)exit + call igrf14syn(0,year,2,radius,colat,lon,x,y,z,f) + write(*,'(4es26.17)') x,y,z,f +enddo +end program diff --git a/test/qualification/midpoint_diffusion_probe.f90 b/test/qualification/midpoint_diffusion_probe.f90 new file mode 100644 index 000000000..848455483 --- /dev/null +++ b/test/qualification/midpoint_diffusion_probe.f90 @@ -0,0 +1,130 @@ +program physics_native +use phys_consts, only: wp,lsp,ln,kb,ms,gammas +use collisions, only: coulomb_colln,thermal_conduct +use sources, only: srcsEnergy +use calculus, only: ETD_uncoupled +use meshobj_cart, only: cartmesh +use grid, only: set_total_grid_sizes,set_subgrid_sizes,set_gridflag +use diffusion, only: diffusion_prep,backEuler3D,TRBDF23D +use nonlinear_diffusion, only: midpoint_TRBDF23D +use diffusion_features, only: midpoint_conduction_enabled +use multifluid, only: energy_diffusion +implicit none(type,external) +character(4096) :: directory,trace_name +integer :: trace_status +call get_command_argument(1,directory) +if(len_trim(directory)==0) error stop 'output directory required' +call nonlinear_conduction() +call kirchhoff_flux() +call get_environment_variable('GEMINI_PHYSICAL_TR_TRACE',trace_name,status=trace_status) +if(trace_status/=0) call wrapper_checks() +contains + +subroutine nonlinear_conduction() +integer,parameter :: n=49 +type(cartmesh) :: x +real(wp) :: ns(-1:n+2,-1:3,-1:3),temp(-1:n+2,-1:3,-1:3),old(-1:n+2,-1:3,-1:3),raw(-1:n+2,-1:3,-1:3) +real(wp) :: nn(n,1,1,ln),j1(-1:n+2,-1:3,-1:3),tn(n,1,1) +real(wp) :: lam(n,1,1),beta(n,1,1),a(n,1,1),b(n,1,1),c(n,1,1),d(n,1,1),e(n,1,1),inc(n,1,1,5) +real(wp) :: density,dx,total,dt,cv +integer :: id,window,level,method,i,it,nt,u +character(64) :: name +call set_total_grid_sizes(n,1,1);call set_subgrid_sizes(1,1);call set_gridflag(2) +x%lx1=n;x%lx2=1;x%lx3=1 +allocate(x%h1(-1:n+2,-1:3,-1:3),x%h2(-1:n+2,-1:3,-1:3),x%h3(-1:n+2,-1:3,-1:3)) +allocate(x%dx1(0:n+2),x%dx1i(n)) +x%h1=1;x%h2=1;x%h3=1;dx=1e5_wp/(n-1);x%dx1=dx;x%dx1i=dx +nn=0;j1=0;tn=600 +do id=1,2 + density=1e5_wp + if(id==2)density=1e11_wp + ns=density;cv=density*kb/(gammas(6)-1) + do window=3,3 + if(window==2.and.id==2)cycle + total=.0001_wp*(density/1e5_wp) + if(window==2)total=.8_wp + do method=3,3 + do level=0,2 + nt=8*2**level;dt=total/nt + write(name,'(a,i0,a,i0,a,i0,a,i0,a)') 'conduction_d',id,'_w',window,'_m',method,'_l',level,'.csv' + open(newunit=u,file=trim(directory)//'/'//trim(name),status='new') + write(u,'(a)') 'step,node,t,dt,ns,dx,Cv,Told,Traw,Tnew,lambda_applied,reaction,drift,conduction,source,reservoir' + temp=600 + do i=1,n + temp(i,1,1)=600+900._wp*(i-1)/(n-1) + enddo + do it=1,nt + old=temp + raw=midpoint_TRBDF23D(6,x,ns,temp,nn,j1,tn,1500._wp,dt,inc,lam) + temp=max(raw,100._wp) + do i=1,n + write(u,'(i0,",",i0,14(",",es25.17))') it,i,it*dt,dt,density,dx,cv,old(i,1,1), & + raw(i,1,1),temp(i,1,1),lam(i,1,1),inc(i,1,1,:) + enddo + enddo + close(u) + enddo + enddo + enddo +enddo +! The manually allocated probe mesh does not claim a complete application grid. +deallocate(x%h1,x%h2,x%h3,x%dx1,x%dx1i) +end subroutine + +subroutine kirchhoff_flux() +integer :: level,n,i,u +real(wp),allocatable :: temp(:,:,:),ns(:,:,:),nn(:,:,:,:),j1(:,:,:),lam(:,:,:),beta(:,:,:) +real(wp) :: dx,xx +open(newunit=u,file=trim(directory)//'/kirchhoff_flux.csv',status='new') +write(u,'(a)') 'level,node,n,x,dx,T,lambda' +do level=0,2 + n=64*2**level+1;dx=1e5_wp/(n-1) + allocate(temp(-1:n+2,-1:3,-1:3),ns(-1:n+2,-1:3,-1:3),j1(-1:n+2,-1:3,-1:3)) + allocate(nn(n,1,1,ln),lam(n,1,1),beta(n,1,1)) + temp=600;ns=1e11_wp;j1=0;nn=0 + do i=1,n + xx=real(i-1,wp)/real(n-1,wp) + temp(i,1,1)=(600._wp**3.5_wp+(1500._wp**3.5_wp-600._wp**3.5_wp)*xx)**(1/3.5_wp) + enddo + call thermal_conduct(6,temp,ns,nn,j1,lam,beta) + do i=1,n + write(u,'(i0,",",i0,",",i0,4(",",es25.17))') level,i,n,(i-1)*dx,dx,temp(i,1,1),lam(i,1,1) + enddo + deallocate(temp,ns,j1,nn,lam,beta) +enddo +close(u) +end subroutine +subroutine wrapper_checks() +integer,parameter :: n=49 +type(cartmesh) :: x +real(wp) :: ns(-1:n+2,-1:3,-1:3,lsp),temp(-1:n+2,-1:3,-1:3,lsp) +real(wp) :: old(-1:n+2,-1:3,-1:3),raw(-1:n+2,-1:3,-1:3),plain(-1:n+2,-1:3,-1:3) +real(wp) :: nn(n,1,1,ln),j(-1:n+2,-1:3,-1:3),tn(n,1,1),inc(n,1,1,5) +integer :: i,flag +call set_total_grid_sizes(n,1,1);call set_subgrid_sizes(1,1) +x%lx1=n;x%lx2=1;x%lx3=1 +allocate(x%h1(-1:n+2,-1:3,-1:3),x%h2(-1:n+2,-1:3,-1:3),x%h3(-1:n+2,-1:3,-1:3)) +allocate(x%dx1(0:n+2),x%dx1i(n)) +x%h1=1;x%h2=1;x%h3=1;x%dx1=1e5_wp/(n-1);x%dx1i=x%dx1(1) +ns=1e5_wp;nn=0;j=0;tn=600;temp=600 +call set_gridflag(2) +do i=1,n + temp(i,1,1,:)=600+900._wp*(i-1)/(n-1) +enddo +old=temp(:,:,:,6) +raw=midpoint_TRBDF23D(6,x,ns(:,:,:,6),old,nn,j,tn,1500._wp,1.25e-5_wp,inc) +plain=midpoint_TRBDF23D(6,x,ns(:,:,:,6),old,nn,j,tn,1500._wp,1.25e-5_wp) +if(any(raw/=plain))error stop 'optional midpoint diagnostics changed the state' +if(midpoint_conduction_enabled) then + call energy_diffusion(1.25e-5_wp,x,ns,temp,j,nn,tn,2,1500._wp) + if(any(temp(:,:,:,6)/=max(raw,100._wp)))error stop 'standard production path differs from tested midpoint operator' +endif +! Inverted and standard zero-flux ion boundaries on constant temperature. +do flag=1,2 + call set_gridflag(flag);old=600 + raw=midpoint_TRBDF23D(6,x,ns(:,:,:,6),old,nn,j,tn,-1e-6_wp,1.25e-5_wp,inc) + if(maxval(abs(raw(1:n,1,1)-600._wp))>1e-11_wp)error stop 'midpoint Neumann constant state changed' +enddo +deallocate(x%h1,x%h2,x%h3,x%dx1,x%dx1i) +end subroutine wrapper_checks +end program diff --git a/test/qualification/mode_experiments.py b/test/qualification/mode_experiments.py new file mode 100644 index 000000000..d58bacaf1 --- /dev/null +++ b/test/qualification/mode_experiments.py @@ -0,0 +1,75 @@ +"""Run bounded optional-mode checks without altering regression goldens. + +Capacitance needs a 3D field-integrated domain and gradient boundary conditions. +For this smoke experiment its copied 3D input has zero imposed current/gradient +boundaries (flagdirich=0); it is a synthetic case, not a physical reference. +""" +import argparse +from pathlib import Path +import json +import re +import shutil +import subprocess +import time +import h5py +import numpy as np + +p=argparse.ArgumentParser(description=__doc__) +p.add_argument('--build',type=Path,required=True) +p.add_argument('--inputs',type=Path,required=True) +p.add_argument('--inputs3d',type=Path) +p.add_argument('--work',type=Path,required=True) +p.add_argument('--mpiexec',default='mpiexec') +p.add_argument('--hwm',action='store_true') +a=p.parse_args() +if not a.hwm and a.inputs3d is None:p.error('--inputs3d is required for capacitance experiments') +a.work.mkdir(parents=True,exist_ok=False) +profile=[('fortran','gemini.bin',1,0,True),('cpp','gemini_c.bin',1,0,True)] +if not a.hwm: + profile += [('altenergy','gemini.altenergy.bin',1,0,True),('field3_2d','gemini.bin',3,0,True), + ('capacitance1_unsupported2d','gemini.bin',1,1,False), + ('capacitance2_unsupported2d','gemini.bin',1,2,False), + ('capacitance1_3d','gemini.bin',1,1,True),('capacitance2_3d','gemini.bin',1,2,True)] +results=[];outputs={} +for name,exe,potential,cap,succeeds in profile: + case=a.work/name + cap3d=cap and succeeds + shutil.copytree(a.inputs3d if cap3d else a.inputs,case/'inputs') + cfg=case/'inputs/config.nml';text=cfg.read_text() + text=re.sub(r'(?im)^(tdur\s*=)[^!\n]*',r'\g<1> 120 ',text) + text=re.sub(r'(?im)^(potsolve\s*=)[^!\n]*',r'\g<1> '+str(potential)+' ',text) + if cap:text+='\n&capacitance\nflagcap='+str(cap)+'\nmagcap=5\n/\n' + cfg.write_text(text) + if cap3d: + for path in (case/'inputs/Efield').glob('????????_?????.??????.h5'): + with h5py.File(path,'r+') as f: + f['flagdirich'][...]=0 + for key in f: + if key.startswith(('Vmin','Vmax')):f[key][...]=0 + start=time.monotonic() + try: + proc=subprocess.run([a.mpiexec,'-n','2',str(a.build.resolve()/exe),str(case.resolve())], + cwd=a.build,capture_output=True,text=True,timeout=240) + code=proc.returncode;log=proc.stdout+proc.stderr + except subprocess.TimeoutExpired as e: + code=124;log=str(e) + elapsed=time.monotonic()-start;(a.work/(name+'.log')).write_text(log) + files=sorted(case.glob('????????_?????.??????.h5'));finite=False + if code==0 and files: + with h5py.File(files[-1]) as f: + data={k:f['restart_core/'+k][...] for k in ['ns','Ts','vs1','Phi']} + finite=all(np.isfinite(v).all() for v in data.values());outputs[name]=data + passed=(code==0 and finite and len(files)==3) if succeeds else (code!=0 and code!=124 and 'capacitance: requires a 3D domain' in log) + results.append(dict(mode=name,executable=exe,potential=potential,capacitance=cap,expected_success=succeeds, + returncode=code,finite=finite,elapsed_seconds=elapsed,frames=len(files), + passed=passed,independently_validated=False)) +metrics=[] +if 'fortran' in outputs and 'cpp' in outputs: + for key,av in outputs['fortran'].items(): + bv=outputs['cpp'][key] + metrics.append(dict(field=key,relative_l2=float(np.linalg.norm(av-bv)/max(np.linalg.norm(av),1e-30)), + bitwise_equal=bool(np.array_equal(av,bv)))) +payload=dict(schema='gemini.qualification.modes.2',hwm_enabled=a.hwm,results=results,c_cpp_comparison=metrics, + scientific_mode_qualification=False,scope='120 s, two ranks on one node; execution and C/Fortran consistency only') +(a.work/'results.json').write_text(json.dumps(payload,indent=2)+'\n');print(json.dumps(payload,indent=2)) +raise SystemExit(0 if all(r['passed'] for r in results) and all(m['bitwise_equal'] for m in metrics) else 1) diff --git a/test/qualification/pair_exchange_probe.f90 b/test/qualification/pair_exchange_probe.f90 new file mode 100644 index 000000000..b8af70c7c --- /dev/null +++ b/test/qualification/pair_exchange_probe.f90 @@ -0,0 +1,80 @@ +program pair_exchange_probe +use phys_consts, only: wp,lsp,kB,ms,gammas +use collisions, only: coulomb_colln +use pair_exchange, only: shared_pair_coefficients,pair_exchange_rates,advance_pair_exchange +implicit none(type,external) +real(wp) :: ns(-1:3,-1:3,-1:3,lsp),Ts(-1:3,-1:3,-1:3,lsp),v(-1:3,-1:3,-1:3,lsp) +real(wp) :: nu(1,1,1),nurev(1,1,1),phi(1,1,1),psi(1,1,1),phirev(1,1,1),psirev(1,1,1) +real(wp) :: rhoa,rhob,Ca,Cb,fraction,drag,K,dt,rate,Ua,Ub,va(3),vb(3),va0(3),vb0(3) +real(wp) :: Fa(3),Fb(3),Qa,Qb,drag0,K0,energy_residual,momentum_residual,thermal_residual,fa0(3),fb0(3),q0a,q0b +integer :: a,b,drift,level,u,it,nt +character(4096) :: filename +call get_command_argument(1,filename) +if(len_trim(filename)==0) error stop 'pair probe requires CSV path' +open(newunit=u,file=trim(filename),status='replace') +write(u,'(a)') 'a,b,level,dt,rhoa,rhob,Ca,Cb,fraction_a,drag,K,Ta0,Tb0,'// & + 'va0x,va0y,va0z,vb0x,vb0y,vb0z,vax,vay,vaz,vbx,vby,vbz,Ta,Tb,'// & + 'instantaneous_momentum,instantaneous_energy,instantaneous_thermal' +do a=1,lsp-1 + do b=a+1,lsp + ns=0;Ts=900;v=0 + ns(:,:,:,a)=2e11_wp;ns(:,:,:,b)=8e10_wp + Ts(:,:,:,a)=600;Ts(:,:,:,b)=1800 + rhoa=2e11_wp*ms(a);rhob=8e10_wp*ms(b) + Ca=2e11_wp*kB/(gammas(a)-1);Cb=8e10_wp*kB/(gammas(b)-1) + fraction=ms(b)/(ms(a)+ms(b)) + do drift=0,1 + va0=real(drift,wp)*[1200._wp,300._wp,-600._wp] + vb0=real(drift,wp)*[-300._wp,-100._wp,200._wp] + v(:,:,:,a)=va0(1);v(:,:,:,b)=vb0(1) + call coulomb_colln(a,b,ns,Ts,v,nu,phi,psi) + call coulomb_colln(b,a,ns,Ts,v,nurev,phirev,psirev) + if(maxval(abs(phi-phirev))+maxval(abs(psi-psirev))>1e-13_wp) error stop 'pair response not symmetric' + call shared_pair_coefficients(ms(a),ms(b),2e11_wp,8e10_wp,nu(1,1,1),nurev(1,1,1), & + phi(1,1,1),psi(1,1,1),drag0,K0) + do level=0,8 + drag=drag0;K=K0 + if(level==6) K=2*drag*(1/rhoa+1/rhob)*Ca*(Cb/(Ca+Cb)) + if(level==7) K=0 + if(level==8) drag=0 + rate=max(drag*(1/rhoa+1/rhob),K*(1/Ca+1/Cb)) + select case(level) + case(0);dt=0 + case(1);dt=1e-12_wp/rate + case(2);dt=.01_wp/rate + case(3);dt=.2_wp/rate + case(4);dt=2._wp/rate + case(5);dt=50._wp/rate + case default;dt=.3_wp/rate + end select + call pair_exchange_rates(ms(a),ms(b),drag,K,600._wp,1800._wp,va0,vb0,Fa,Fb,Qa,Qb) + call pair_exchange_rates(ms(a),ms(b),drag,K,600._wp,1800._wp,[0._wp,0._wp,0._wp], & + [0._wp,0._wp,0._wp],fa0,fb0,q0a,q0b) + momentum_residual=maxval(abs(Fa+Fb))/max(maxval(abs(Fa)),tiny(1._wp)) + energy_residual=abs(Qa+Qb+sum(Fa*va0+Fb*vb0))/ & + max(abs(Qa)+abs(Qb)+sum(abs(Fa*va0)+abs(Fb*vb0)),tiny(1._wp)) + thermal_residual=abs(q0a+q0b)/max(abs(q0a)+abs(q0b),tiny(1._wp)) + va=va0;vb=vb0;Ua=Ca*600;Ub=Cb*1800 + call advance_pair_exchange(rhoa,rhob,Ca,Cb,fraction,drag,K,dt,va,vb,Ua,Ub) + if(dt==0) then + if(any(va/=va0).or.any(vb/=vb0).or.Ua/=Ca*600.or.Ub/=Cb*1800) error stop 'zero-step pair changed state' + endif + write(u,'(3(i0,","),*(es25.17,:,","))') a,b,10*drift+level,dt,rhoa,rhob,Ca,Cb,fraction,drag,K, & + 600._wp,1800._wp,va0,vb0,va,vb,Ua/Ca,Ub/Cb,momentum_residual,energy_residual,thermal_residual + enddo + enddo + enddo +enddo +! The original closed thermal-exchange fixture, now using one shared transfer. +Ca=2e11_wp*kB/(5._wp/3-1);Cb=8e10_wp*kB/(5._wp/3-1);K=.2_wp*Ca +do level=0,2 + nt=5*2**level;dt=1._wp/nt + Ua=Ca*300;Ub=Cb*1800;va=0;vb=0 + do it=1,nt + call advance_pair_exchange(1._wp,1._wp,Ca,Cb,.5_wp,0._wp,K,dt,va,vb,Ua,Ub) + enddo + write(u,'(3(i0,","),*(es25.17,:,","))') 0,0,level,1._wp,1._wp,1._wp,Ca,Cb,.5_wp,0._wp,K, & + 300._wp,1800._wp,[0._wp,0._wp,0._wp],[0._wp,0._wp,0._wp],va,vb,Ua/Ca,Ub/Cb,0._wp,0._wp,0._wp +enddo +close(u) +end program pair_exchange_probe diff --git a/test/qualification/physics_updates_protocol.json b/test/qualification/physics_updates_protocol.json new file mode 100644 index 000000000..e1e506c4b --- /dev/null +++ b/test/qualification/physics_updates_protocol.json @@ -0,0 +1,25 @@ +{ + "schema": "gemini.physics.source.updates.1", + "declared_before_execution": true, + "base_candidate": "a15a0ccd5bba2fcad9b57997cf9c1330dd211de3", + "native_acceptance": "All nine original native references; all existing tolerances and archives unchanged. Any failed, skipped, or unexecuted required test is not a pass.", + "midpoint_diffusion": { + "scope": "standard energy_diffusion, solver 2 only; opt-in CMake switch; virtual BE half-step conductivity predictor", + "fixtures": "PC03 unchanged proper transient window, both densities; PC04 independent flux convergence", + "space_order_min": 1.8, + "time_order_min": 1.8, + "normalized_energy_balance_max": 1e-11, + "unchanged_boundary_absolute_max": 1e-11 + }, + "pair_exchange": { + "scope": "callable constant-rate closed pair operator, not wired into split application sources", + "rate_model_proposal": "one averaged reciprocal momentum coefficient, translational thermal power, species heat capacities, mass-fraction friction partition", + "rates_are_not_independently_validated": true, + "identity_fixtures": "All 21 species pairs at zero and finite drift", + "normalized_momentum_max": 1e-11, + "normalized_total_energy_max": 1e-11, + "independent_oracle": "SciPy Radau integration of both momenta and both internal energies, including time-varying friction power; tighter oracle control", + "relative_oracle_max": 1e-10 + }, + "non_claims": ["No full coupled spatial qualification inferred", "No full total-energy inventory inferred", "No outside approval required for law-based closure", "No outdated optional increments finding repeated"] +} diff --git a/test/qualification/research_matrix.py b/test/qualification/research_matrix.py new file mode 100644 index 000000000..46f665d9b --- /dev/null +++ b/test/qualification/research_matrix.py @@ -0,0 +1,215 @@ +"""Execute the frozen scope: driver preflight, restart trajectories, and transport. + +All outputs are fresh. Retains diagnostics for expected rejections. No budget is +learned from these results. Requires the pinned native reference inputs. +""" +import argparse +import hashlib +import importlib.util +import json +import math +import os +from pathlib import Path +import re +import shutil +import subprocess +import sys +import time +import h5py +import numpy as np +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from run_research import input_signature,preflight +from check_transport import check,check_continuity +from check_sources import check as check_sources +from check_energy_operators import check as check_energy + + +def set_duration(case,duration,*,extend=False): + cfg=case/'inputs/config.nml';text=cfg.read_text() + pattern=re.compile(r'(?im)^([ \t]*tdur[ \t]*=)([^!\r\n]*)') + matches=list(pattern.finditer(text)) + if len(matches)!=1:raise ValueError('Exactly one tdur assignment required') + try: + value=matches[0][2].strip().removesuffix(',').strip() + previous=float(value.replace('D','e').replace('d','e')) + duration=float(duration) + except (TypeError,ValueError) as e: + raise ValueError('tdur must be a positive finite duration') from e + if not all(math.isfinite(value) and value>0 for value in (previous,duration)): + raise ValueError('tdur must be a positive finite duration') + if extend and duration<=previous:raise ValueError('Restart tdur must extend the first run') + cfg.write_text(pattern.sub(lambda m:m[1]+f' {duration:.17g} ',text)) + + +def restart_advanced(case,previous): + frames={p.name for p in case.glob('????????_?????.??????.h5')} + return bool(previous) and previousmax(previous) + + +def checkpoint_shapes(case,ranks,layout): + """Check identity, finite payloads and the C/Fortran allocation contract.""" + frames=sorted(case.glob('????????_?????.??????.h5')) + if not frames:return False + for frame in frames: + with h5py.File(frame) as f: + root=f['restart_runtime'] + prefix=root['prefix'][()].decode().strip() + checkpoint=root['checkpoint'][()] + input_sha=root['input_sha256'][()] + executable_sha=root['executable_sha256'][()] + if root['schema'][()]!=2 or tuple(root['layout'][...])!=tuple(layout):return False + if checkpoint.decode().strip()!=frame.name or not prefix.startswith(frame.name+'.partial.'):return False + for rank in range(ranks): + with h5py.File(case/(prefix+f'.r{rank:08d}.h5')) as f: + if f['schema'][()]!=2 or f['complete'][()]!=1 or f['rank'][()]!=rank:return False + if tuple(f['layout'][...])!=tuple(layout) or f['checkpoint'][()]!=checkpoint:return False + if f['generation'][()].decode().strip()!=prefix:return False + if f['input_sha256'][()]!=input_sha or f['executable_sha256'][()]!=executable_sha:return False + if f['fluid'].shape[0]!=35 or f['electro'].shape[0]!=7:return False + if f['fluid'].shape[1:]!=f['electro'].shape[1:]:return False + for field in ('fluid','electro','vi1','vi2','vi3'): + if f[field].ndim!=4 or f[field].dtype!=np.dtype('float64'):return False + if not np.isfinite(f[field][...]).all():return False + return True + + +def compare(continuous,split,budget): + rows=[] + frames=sorted(continuous.glob('????????_?????.??????.h5')) + if not frames or {f.name for f in frames}!={f.name for f in split.glob('????????_?????.??????.h5')}: + return dict(passed=False,fields_checked=0,max_budget_fraction=None,error='Missing or unexpected output frame') + for fa in frames: + fb=split/fa.name + with h5py.File(fa) as a,h5py.File(fb) as b: + # Require the complete output sequence, including all continuation frames. + for key in ['ns','Ts','vs1','Phi']: + av=a['restart_core/'+key][...].astype(float);bv=b['restart_core/'+key][...].astype(float) + if av.shape!=bv.shape or not np.isfinite(av).all(): + return dict(passed=False,fields_checked=len(rows),max_budget_fraction=None,error='Invalid reference or output shape') + for species in range(7) if key!='Phi' else [None]: + x=av[species] if species is not None else av;y=bv[species] if species is not None else bv + error=float(np.sqrt(np.mean((x-y)**2)));scale=float(np.sqrt(np.mean(x*x))) + bound=budget['absolute_floor'][key]+budget['trajectory_relative_l2']*scale + rows.append(dict(frame=fa.name,field=key,species=species,rms_error=error,bound=bound, + max_abs=float(np.max(np.abs(x-y))),finite=bool(np.isfinite(y).all()), + passed=bool(np.isfinite(y).all() and error<=bound))) + return dict(passed=bool(rows) and all(r['passed'] for r in rows),fields_checked=len(rows), + max_budget_fraction=max((r['rms_error']/r['bound'] for r in rows),default=None),metrics=rows) + + +def main(): + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--build',type=Path,required=True) + p.add_argument('--inputs-root',type=Path,required=True);p.add_argument('--work',type=Path,required=True) + p.add_argument('--mpiexec',default='mpiexec');p.add_argument('--quick',action='store_true');p.add_argument('--suffix',default='') + p.add_argument('--extended-layouts',action='store_true', + help='also test four-rank 2x2 decomposition outside the frozen 1/2-rank profile') + a=p.parse_args() + if a.quick and a.extended_layouts:p.error('--extended-layouts requires the full matrix, not --quick') + a.work.mkdir(parents=True,exist_ok=False) + root=Path(__file__).resolve().parents[2] + budget=json.loads((root/'docs/qualification/ACCEPTANCE_BUDGETS.json').read_text())['budgets']['checkpoint'] + exe=(a.build/('gemini.bin'+a.suffix)).resolve();exe_sha=hashlib.sha256(exe.read_bytes()).hexdigest() + runs=[];comparisons=[];transport=[];continuity=[];sources=[];energy=[] + cases=[('mini2dns_fang',1,[1,1]),('mini2dns_fang',2,[1,2]),('mini3d_fang',1,[1,1]), + ('mini3d_fang',2,[1,2]),('mini3d_fang',2,[2,1])] + if a.extended_layouts:cases.append(('mini3d_fang',4,[2,2])) + if a.quick:cases=cases[:2] + def create(name,case,duration): + path=a.work/name;shutil.copytree(a.inputs_root/case/'inputs',path/'inputs') + set_duration(path,duration) + return path + def run(path,label,ranks,layout,expected=None,executable=exe,restart=False): + valid=preflight(path);(path/'forcing-preflight.json').write_text(json.dumps(valid,indent=2)+'\n') + sig=input_signature(path);(path/'verified-inputs.json').write_text(json.dumps(sig,indent=2)+'\n') + env=dict(os.environ,GEMINI_EXACT_RESTART='1',GEMINI_INPUT_SHA256=sig['sha256'], + GEMINI_EXECUTABLE_SHA256=hashlib.sha256(executable.read_bytes()).hexdigest(),GEMINI_NUMERICAL_AUDIT='1') + cmd=[a.mpiexec,'-n',str(ranks),str(executable),str(path.resolve()),'-manual_grid',*[str(i) for i in layout]] + previous={p.name for p in path.glob('????????_?????.??????.h5')} if restart else set() + t=time.monotonic() + proc=subprocess.run(cmd,env=env,text=True,capture_output=True,timeout=600) + elapsed=time.monotonic()-t + (a.work/(label+'.log')).write_text(proc.stdout+proc.stderr) + passed=(proc.returncode==0 and checkpoint_shapes(path,ranks,layout)) if expected is None else proc.returncode!=0 and expected in proc.stdout+proc.stderr + if restart: + advanced=restart_advanced(path,previous) + passed=passed and advanced + row=dict(label=label,returncode=proc.returncode,passed=passed,expected_rejection=expected,wall_seconds=elapsed) + if restart:row['restart_advanced']=advanced + runs.append(row);print(json.dumps(row),flush=True) + return passed + for case,ranks,layout in cases: + tag=case+'_'+str(layout[0])+'x'+str(layout[1]) + continuous=create(tag+'_continuous',case,300);split=create(tag+'_split',case,120) + okay=run(continuous,tag+'_continuous',ranks,layout) + okay=run(split,tag+'_first',ranks,layout) and okay + # Preserve a restart seed for the adversarial probes before continuing. + seed=a.work/(tag+'_seed');shutil.copytree(split,seed) + set_duration(split,300,extend=True) + okay=run(split,tag+'_restart',ranks,layout,restart=True) and okay + if okay: + comparisons.append(dict(case=tag,**compare(continuous,split,budget))) + transport.append(dict(case=tag,**check(continuous,layout=layout))) + continuity.append(dict(case=tag,**check_continuity(continuous))) + sources.append(dict(case=tag,**check_sources(continuous,ranks))) + energy.append(dict(case=tag,**check_energy(continuous,ranks))) + if case=='mini2dns_fang' and ranks==2: + for fault in ['inputs','layout','missing_state','incomplete_state','bad_dtype','bad_clock','bad_binary', + 'swap_rank','mismatched_generation','nonfinite_fluid','nonfinite_electro', + 'nonfinite_vi1','nonfinite_vi2','nonfinite_vi3']: + bad=a.work/('reject_'+fault);shutil.copytree(seed,bad) + set_duration(bad,300,extend=True) + frame=sorted(bad.glob('????????_?????.??????.h5'))[-1] + with h5py.File(frame,'r+') as f: + if fault=='layout':f['restart_runtime/layout'][...]=[2,1] + if fault=='bad_binary':f['restart_runtime/executable_sha256'][...]=b'0'*64 + prefix=f['restart_runtime/prefix'][()].decode().strip() + state=bad/(prefix+'.r00000000.h5') + if fault=='inputs': + forcing=next((bad/'inputs/Efield').glob('????????_*.h5')) + with h5py.File(forcing,'r+') as f:f['Exit'][...]+=0.00001 + if fault=='missing_state':state.unlink() + if fault=='swap_rank': + other=bad/(prefix+'.r00000001.h5') + first_bytes,other_bytes=state.read_bytes(),other.read_bytes() + state.write_bytes(other_bytes);other.write_bytes(first_bytes) + if fault in ['incomplete_state','bad_dtype','bad_clock','mismatched_generation'] or fault.startswith('nonfinite_'): + with h5py.File(state,'r+') as f: + if fault=='incomplete_state':f['complete'][...]=0 + if fault=='bad_clock':f['dt'][...]=np.nan + if fault=='mismatched_generation':f['generation'][...]=b'wrong-generation' + if fault.startswith('nonfinite_'): + field=fault.removeprefix('nonfinite_') + f[field][tuple(n-1 for n in f[field].shape)]=np.nan if field=='fluid' else np.inf + if fault=='bad_dtype': + data=f['fluid'][...].astype('float32');del f['fluid'];f['fluid']=data + expected={'inputs':'Changed restart inputs','layout':'Incompatible runtime checkpoint layout', + 'missing_state':'Missing runtime state file','incomplete_state':'Incomplete runtime checkpoint', + 'bad_dtype':'requires float64','bad_clock':'Invalid runtime checkpoint clock', + 'bad_binary':'Changed restart executable','swap_rank':'Runtime state rank mismatch', + 'mismatched_generation':'Runtime state generation mismatch'} + expected='Nonfinite runtime checkpoint payload: '+fault.removeprefix('nonfinite_') if fault.startswith('nonfinite_') else expected[fault] + run(bad,'reject_'+fault,ranks,layout,expected) + # A C++ run must produce the same physics as Fortran; each self-restart remains binary-bound. + cpp_exe=(a.build/('gemini_c.bin'+a.suffix)).resolve() + if cpp_exe.is_file(): + cpp=create('cpp_continuous',case,300) + cpp_split=create('cpp_split',case,120) + cpp_okay=run(cpp,'cpp_continuous',ranks,layout,executable=cpp_exe) + cpp_okay=run(cpp_split,'cpp_first',ranks,layout,executable=cpp_exe) and cpp_okay + set_duration(cpp_split,300,extend=True) + cpp_okay=run(cpp_split,'cpp_restart',ranks,layout,executable=cpp_exe,restart=True) and cpp_okay + if cpp_okay: + comparisons.append(dict(case='cpp_vs_fortran',**compare(continuous,cpp,budget))) + comparisons.append(dict(case='cpp_restart',**compare(cpp,cpp_split,budget))) + energy.append(dict(case='cpp_continuous',**check_energy(cpp,ranks))) + else: + runs.append(dict(label='cpp_required',passed=False,error='Required C++ executable is missing')) + result=dict(schema='gemini.research.matrix.1',executable_sha256=exe_sha,runs=runs, + extended_layouts=a.extended_layouts, + comparisons=comparisons,transport=transport,continuity=continuity,sources=sources,energy=energy, + passed=all(r['passed'] for r in runs) and len(comparisons)==len(cases)+2 and + len(energy)==len(cases)+1 and all(r['passed'] for r in comparisons+transport+continuity+sources+energy)) + (a.work/'results.json').write_text(json.dumps(result,indent=2)+'\n') + print(json.dumps({k:v for k,v in result.items() if k not in ['comparisons','transport']},indent=2)) + return 0 if result['passed'] else 1 +if __name__=='__main__':raise SystemExit(main()) diff --git a/test/qualification/restart_core_checks.py b/test/qualification/restart_core_checks.py new file mode 100644 index 000000000..1f6e44c43 --- /dev/null +++ b/test/qualification/restart_core_checks.py @@ -0,0 +1,66 @@ +"""Adversarial native restart checks, including legacy-data poisoning. + +Uses a completed 300-second mini2dns_fang case. All cases and logs are isolated. +The acceptance bounds test serialization and parser behavior, not physics. +""" +import argparse +from pathlib import Path +import json +import re +import shutil +import subprocess +import h5py +import numpy as np +p=argparse.ArgumentParser();p.add_argument('--exe',type=Path,required=True);p.add_argument('--case',type=Path,required=True) +p.add_argument('--work',type=Path,required=True);p.add_argument('--mpiexec',default='mpiexec');a=p.parse_args() +a.work.mkdir(parents=True,exist_ok=False) +frames=sorted(a.case.glob('????????_?????.??????.h5'));assert len(frames)>=4 +saved=frames[2].name;final=frames[3].name +# Truncate at an interior output time with a subsequent valid forcing frame. +with h5py.File(frames[3]) as f:final_ut=float(f['time/UThour'][()])*3600 +text=(a.case/'inputs/config.nml').read_text();start=float(re.search(r'(?im)^UTsec0\s*=\s*([\d.]+)',text)[1]) +duration=final_ut-start +records=[];outputs={} +for label in ['clean','poison_legacy','big_endian','incomplete_core','schema','potential_rank', + 'false_precision','integer_state']: + case=a.work/label;shutil.copytree(a.case/'inputs',case/'inputs') + for f in frames[:3]:shutil.copy2(f,case/f.name) + cfg=case/'inputs/config.nml';cfg.write_text(re.sub(r'(?im)^(tdur\s*=)[^!\n]*',r'\g<1> '+str(duration)+' ',text)) + with h5py.File(case/saved,'r+') as f: + if label=='poison_legacy': + for key in ['nsall','Tsall','vs1all','Phiall']:f[key][...]=np.nan + elif label=='big_endian': + for key in ['ns','Ts','vs1','Phi']: + path='restart_core/'+key + data=f[path][...].astype('>f8') + del f[path];f.create_dataset(path,data=data) + elif label=='incomplete_core':del f['restart_core/complete'] + elif label=='schema':f['restart_core/schema'][...]=999 + elif label=='potential_rank': + data=f['Phiall'][...];del f['restart_core/Phi'];f.create_dataset('restart_core/Phi',data=data) + elif label in ['false_precision','integer_state']: + data=f['restart_core/ns'][...].astype('float32' if label=='false_precision' else 'int64') + del f['restart_core/ns'];f.create_dataset('restart_core/ns',data=data) + proc=subprocess.run([a.mpiexec,'-n','2',str(a.exe.resolve()),str(case.resolve())],text=True,capture_output=True,timeout=240) + (a.work/(label+'.log')).write_text(proc.stdout+proc.stderr) + expected={'incomplete_core':'Incomplete core restart','schema':'Unsupported core restart', + 'potential_rank':'must be full 3D','false_precision':'must contain float64', + 'integer_state':'must contain float64'} + passed=proc.returncode==0 if label not in expected else proc.returncode!=0 and expected[label] in proc.stdout+proc.stderr + records.append(dict(case=label,returncode=proc.returncode,passed=passed)) + if label not in expected and passed: + with h5py.File(case/final) as f:outputs[label]={k:f['restart_core/'+k][...] for k in ['ns','Ts','vs1','Phi']} +exact=False +if 'clean' in outputs and 'poison_legacy' in outputs: + exact=all(np.array_equal(outputs['clean'][k],outputs['poison_legacy'][k]) for k in outputs['clean']) +endian_equal=False +if 'clean' in outputs and 'big_endian' in outputs: + endian_equal=all(np.array_equal(outputs['clean'][k],outputs['big_endian'][k]) for k in outputs['clean']) +with h5py.File(a.case/saved) as f: + precision={k:str(f['restart_core/'+k].dtype) for k in ['ns','Ts','vs1','Phi']} +result=dict(schema='gemini.qualification.restart_core.1',runs=records,legacy_poison_bitwise_equal=exact,dtypes=precision, + big_endian_bitwise_equal=endian_equal, + passed=all(r['passed'] for r in records) and exact and endian_equal and set(precision.values())=={'float64'}, + scope='core record precision, preference, and invalid-file rejection; full auxiliary state not certified') +(a.work/'results.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2)) +raise SystemExit(0 if result['passed'] else 1) diff --git a/test/qualification/size_alias.f90 b/test/qualification/size_alias.f90 new file mode 100644 index 000000000..13a0ff923 --- /dev/null +++ b/test/qualification/size_alias.f90 @@ -0,0 +1,14 @@ +program size_alias +use reader, only: get_simsize2 +use h5fortran, only: hdf5_file +implicit none(type,external) +type(hdf5_file) :: f +integer :: nlat,nlon +character(4096) :: path +call get_command_argument(1,path) +call f%open(trim(path),action='w') +call f%write('Nlat',3);call f%write('Nlon',5) +call f%close() +call get_simsize2(trim(path),nlon,nlat) +if(nlat/=3.or.nlon/=5) error stop 'Nlat/Nlon aliases mapped to wrong dimension' +end program diff --git a/test/qualification/temperature_floor.f90 b/test/qualification/temperature_floor.f90 new file mode 100644 index 000000000..fe55d3004 --- /dev/null +++ b/test/qualification/temperature_floor.f90 @@ -0,0 +1,39 @@ +program temperature_floor +use phys_consts, only: wp,lsp,kB,gammas +use meshobj_cart, only: cartmesh +use grid, only: set_total_grid_sizes,set_subgrid_sizes +use multifluid, only: rhoe2T,T2rhoe +use transport_audit, only: audit_transport_init,audit_step,audit_mass_start,audit_mass_finish +implicit none(type,external) +type(cartmesh) :: x +real(wp) :: ns(-1:4,-1:4,-1:4,lsp),rhoe(-1:4,-1:4,-1:4,lsp),Ts(-1:4,-1:4,-1:4,lsp) +real(wp) :: expected +integer :: s,unit +character(4096) :: directory +call get_command_argument(1,directory) +call set_total_grid_sizes(2,2,2);call set_subgrid_sizes(2,2) +x%lx1=2;x%lx2=2;x%lx3=2 +allocate(x%h1(-1:4,-1:4,-1:4),x%h2(-1:4,-1:4,-1:4),x%h3(-1:4,-1:4,-1:4)) +allocate(x%dx1i(2),x%dx2i(2),x%dx3i(2),x%nullpts(2,2,2),x%inull(1,3)) +x%h1=1;x%h2=1;x%h3=1;x%dx1i=[1._wp,2._wp];x%dx2i=[3._wp,4._wp];x%dx3i=[5._wp,6._wp] +x%nullpts=.false.;x%nullpts(2,2,2)=.true.;x%lnull=1;x%inull(1,:)=[2,2,2] +ns=1e10_wp;ns(:,:,:,lsp)=6e10_wp +do s=1,lsp + rhoe(:,:,:,s)=ns(:,:,:,s)*kB*50._wp/(gammas(s)-1) +enddo +call audit_transport_init(trim(directory),0) +call audit_step(0._wp,1._wp) +call audit_mass_start(ns,x) +call rhoe2T(ns,rhoe,Ts) +if(any(Ts/=100._wp)) error stop 'Temperature conversion floor not applied' +call T2rhoe(ns,Ts,rhoe) +do s=1,lsp + ! Total volume is 3*7*11 minus the 2*4*6 null-cell volume: 183. + expected=183._wp*ns(1,1,1,s)*kB*50._wp/(gammas(s)-1) + print '(I0,1X,ES24.16E3)',s,expected +enddo +call audit_mass_finish(ns) +open(newunit=unit,file=trim(directory)//'/temperature.bin',access='stream',form='unformatted',status='replace') +write(unit) Ts,rhoe +close(unit) +end program diff --git a/test/qualification/test_atomic.py b/test/qualification/test_atomic.py new file mode 100644 index 000000000..b87c296af --- /dev/null +++ b/test/qualification/test_atomic.py @@ -0,0 +1,18 @@ +import argparse +from pathlib import Path +import subprocess +import tempfile +p=argparse.ArgumentParser();p.add_argument('--exe',required=True,type=Path);a=p.parse_args() +with tempfile.TemporaryDirectory() as d: + root=Path(d);final=root/'checkpoint.h5';final.write_text('old valid checkpoint\n') + (root/'directory').mkdir() + for mode in ['leave','fail_publish','missing_parent']: + r=subprocess.run([str(a.exe),d,mode],capture_output=True,text=True) + assert (r.returncode==0)==(mode=='leave'),(mode,r.stderr) + assert final.read_text()=='old valid checkpoint\n',mode + if mode=='fail_publish':assert 'Atomic checkpoint publication failed' in r.stderr + assert len(list(root.glob('checkpoint.h5.partial.*')))==2 + r=subprocess.run([str(a.exe),d,'success'],capture_output=True,text=True) + assert r.returncode==0,r.stderr + assert final.read_text()=='complete new checkpoint\n' +print('Atomic visibility: interrupted staging and failed publication preserve prior checkpoint; successful publish replaces it.') diff --git a/test/qualification/test_budgets.py b/test/qualification/test_budgets.py new file mode 100644 index 000000000..f8d2447a7 --- /dev/null +++ b/test/qualification/test_budgets.py @@ -0,0 +1,30 @@ +"""Manufactured curvilinear control volume, explicit flux and clipping checks.""" +import importlib.util +from pathlib import Path +import unittest +import numpy as np +p=Path(__file__).resolve().parents[2]/'scripts/qualification/budgets.py' +s=importlib.util.spec_from_file_location('budgets',p);b=importlib.util.module_from_spec(s);s.loader.exec_module(b) +class Budgets(unittest.TestCase): + def test_physical_volume_and_units(self): + shape=(2,2,1);one=np.ones(shape);mask=np.ones(shape,dtype=bool);mask[1,1,0]=False + vol=b.cell_volumes(2*one,3*one,4*one,[1,2],[3,4],[5],mask) + self.assertEqual(vol.sum(),24*5*(1*3+1*4+2*3)) + n=np.ones(shape+(2,))*np.array([2,2]);t=np.full_like(n,10);v=np.ones(n.shape+(3,)) + n[~mask]=np.nan;t[~mask]=np.nan;v[~mask]=np.nan + out=b.integrals(n,v,t,vol,[2,4],[1,-1],[5/3,5/3],1) + np.testing.assert_allclose(out['number'],[3120,3120]) + self.assertEqual(out['charge'].sum(),0) + np.testing.assert_allclose(out['thermal'],[46800,46800]) + np.testing.assert_allclose(out['momentum'][0],[6240]*3) + floor=b.clipping_budget(n,vol,3) + np.testing.assert_equal(floor['cells_clipped'],[3,3]);np.testing.assert_equal(floor['number_added'],[1560,1560]) + def test_open_control_volume(self): + # 100 initially; source 20, outward transport 7, floor adds 3 => 116. + self.assertTrue(b.balance([100],[116],[20],[7],[3],atol=1e-12,rtol=1e-12)['passed']) + self.assertFalse(b.balance([100],[116],[20],[7],[0],atol=1e-12,rtol=1e-12)['passed']) + self.assertFalse(b.balance([100],[116],[20],[-7],[3],atol=1e-12,rtol=1e-12)['passed']) + def test_rejects_missing_terms_and_bad_metrics(self): + with self.assertRaises(ValueError):b.balance([1],[1],[0],[np.nan],[0],atol=0,rtol=0) + with self.assertRaises(ValueError):b.cell_volumes(np.ones((2,1,1)),np.ones((2,1,1)),np.ones((2,1,1)),[1,-1],[1],[1],np.ones((2,1,1),dtype=bool)) +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_campaign.py b/test/qualification/test_campaign.py new file mode 100644 index 000000000..3da24a55c --- /dev/null +++ b/test/qualification/test_campaign.py @@ -0,0 +1,76 @@ +import copy +import hashlib +from pathlib import Path +import sys +import tempfile +import unittest +import numpy as np +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from campaign import validate_manifest,admit_corpus,matched_benchmark,conformal,uq_decision,coverage +from observation_operator import radar_los,linear_analysis + + +class Campaign(unittest.TestCase): + def manifest(self,p): + events=[] + for i,split in enumerate(['train','validation','calibration','test']): + record=dict(id=str(i),split=split,solver_commit='a'*40,physical_event=str(i),lineage=str(i)) + for key in ['artifact','inputs','grid','forcing','initial_state']: + path=p/f'{i}-{key}';path.write_text(str(i)+key) + digest=hashlib.sha256(path.read_bytes()).hexdigest() + record[key]=dict(path=path.name,sha256=digest) + record.update(data_sha256=record['artifact']['sha256'],forcing_sha256=record['forcing']['sha256'], + initial_state_sha256=record['initial_state']['sha256']) + events.append(record) + return dict(schema='gemini.corpus.1',candidate_commit='a'*40,target_population='synthetic fixture only', + events=events,normalization_fit_events=['0']) + + def test_lineage_content_leakage_normalization_and_hashes(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);m=self.manifest(p);self.assertTrue(validate_manifest(m,p)['passed']) + for key in ['physical_event','lineage','forcing_sha256','initial_state_sha256','data_sha256']: + bad=copy.deepcopy(m);bad['events'][1][key]=bad['events'][0][key] + with self.assertRaisesRegex(ValueError,'leakage'):validate_manifest(bad,p) + bad=copy.deepcopy(m);bad['normalization_fit_events'].append('3') + with self.assertRaisesRegex(ValueError,'Normalization'):validate_manifest(bad,p) + (p/m['events'][0]['artifact']['path']).write_text('corruption') + with self.assertRaisesRegex(ValueError,'hash'):validate_manifest(m,p) + + def test_real_gate_prerequisites_block_training(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);m=self.manifest(p) + register=dict(candidate_commit='a'*40,gates=[dict(id=f'R{i:02d}',status='open') for i in range(1,19)]) + with self.assertRaisesRegex(ValueError,'R02,R04,R07'):admit_corpus(m,p,register,p) + + def test_matched_rollouts_baseline_and_missing_frames(self): + truth=np.arange(12).reshape(4,3);prediction=truth+.1 + candidate=dict(prediction=prediction,model_sha256='a'*64,data_sha256='b'*64,end_to_end_seconds=.01) + result=matched_benchmark(truth,[0,1,2],{'fixture':candidate},np.ones(3), + dict(normalized_rms_max=.2,wall_seconds_max=1)) + self.assertTrue(result['passed']);self.assertLess(result['candidates']['fixture']['persistence_rms_ratio'],1) + candidate['prediction']=prediction[:-1] + with self.assertRaisesRegex(ValueError,'shapes'):matched_benchmark(truth,[0,1,2],{'x':candidate},np.ones(3),{}) + + def test_event_conformal_insufficiency_width_shift_and_test_leakage(self): + c=conformal([.1]*9,list(range(9)),.1) + self.assertAlmostEqual(c['radius'],.1) + self.assertEqual(conformal([.1]*8,list(range(8)),.1)['radius'],float('inf')) + with self.assertRaises(ValueError):conformal([1,2],['same','same'],.1) + self.assertEqual(uq_decision(c,[.5],[0],[1],1,'auroral','auroral')['status'],'eligible_for_research') + r=uq_decision(c,[2],[0],[1],.1,'auroral','quiet') + self.assertEqual(len(r['reasons']),3);self.assertFalse(r['control_enabled']) + self.assertEqual(coverage([.05,.2],[20,21],c,list(range(9)))['empirical_coverage'],.5) + with self.assertRaisesRegex(ValueError,'leakage'):coverage([.1],[0],c,[0]) + + def test_los_sign_mask_and_linear_gaussian_analysis(self): + v=np.array([[10,20,30],[-5,0,0]]) + self.assertAlmostEqual(radar_los(v,[[1,0,0],[1,0,0]],[.5,.5],[True,True]),2.5) + self.assertAlmostEqual(radar_los(v,[[-1,0,0],[-1,0,0]],[.5,.5],[True,True]),-2.5) + with self.assertRaisesRegex(ValueError,'invalid'):radar_los(v,[[1,0,0],[1,0,0]],[.5,.5],[True,False]) + a=linear_analysis([0],[[4]],[[1]],[3],[[1]]) + np.testing.assert_allclose(a['posterior'],[2.4]);np.testing.assert_allclose(a['covariance'],[[.8]]) + self.assertAlmostEqual(a['normalized_innovation_squared'],1.8) + with self.assertRaisesRegex(ValueError,'Positive'):linear_analysis([0],[[4]],[[1]],[3],[[-1]]) + + +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_campaign_boundaries.py b/test/qualification/test_campaign_boundaries.py new file mode 100644 index 000000000..4ca3d1aac --- /dev/null +++ b/test/qualification/test_campaign_boundaries.py @@ -0,0 +1,31 @@ +from pathlib import Path +import sys,unittest +import numpy as np +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from campaign import conformal,coverage,qualify_coverage,rollout_metrics +from observation_operator import radar_los,linear_analysis +class CampaignBoundaries(unittest.TestCase): + def test_masks_cannot_convert_missingness_into_validity(self): + for mask in ([np.nan],[2],['valid'],[.5]): + with self.assertRaisesRegex(ValueError,'mask'):radar_los([[1,0,0]],[[1,0,0]],[1],mask) + def test_empty_predictions_and_observations_reject(self): + with self.assertRaises(ValueError):rollout_metrics(np.empty((0,3)),np.empty((0,3)),np.ones(3)) + with self.assertRaises(ValueError):linear_analysis([1],[[1]],np.empty((0,1)),[],np.empty((0,0))) + def test_finite_sample_confidence_cannot_be_replaced_with_empirical_coverage(self): + c=conformal([.1]*19,list(range(19)),.05) + small=qualify_coverage([0]*10,list(range(100,110)),c,list(range(19)),coverage_target=.95,width_cap=1,confidence=.95) + self.assertEqual(small['empirical_coverage'],1) + self.assertFalse(small['passed']) + self.assertAlmostEqual(small['population_coverage_lower_bound'],.05**.1) + large=qualify_coverage([0]*59,list(range(100,159)),c,list(range(19)),coverage_target=.95,width_cap=1,confidence=.95) + self.assertTrue(large['passed']) + wide=qualify_coverage([0]*59,list(range(100,159)),c,list(range(19)),coverage_target=.95,width_cap=.1,confidence=.95) + self.assertFalse(wide['passed']) + none=qualify_coverage([1]*59,list(range(100,159)),c,list(range(19)),coverage_target=.95,width_cap=1,confidence=.95) + self.assertEqual(none['population_coverage_lower_bound'],0) + def test_bad_calibration_inventory_and_radius(self): + c=conformal([.1]*19,list(range(19)),.05) + with self.assertRaises(ValueError):coverage([0],[100],c,[0]*19) + c['radius']=-1 + with self.assertRaises(ValueError):coverage([0],[100],c,list(range(19))) +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_clock_inventory.py b/test/qualification/test_clock_inventory.py new file mode 100644 index 000000000..dc1809fc0 --- /dev/null +++ b/test/qualification/test_clock_inventory.py @@ -0,0 +1,36 @@ +"""Joint evidence deletion must not turn unexecuted steps into passes.""" +from pathlib import Path +import sys,tempfile,unittest +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from check_sources import check_clock_inventory + + +class ClockInventory(unittest.TestCase): + def test_complete_run_and_float64_clock_roundoff(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);(p/'inputs').mkdir() + (p/'inputs/config.nml').write_text('&base\n tdur = 3D0, ! fixed duration\n/\n') + check_clock_inventory(p,{(0.,1.),(1.,1.),(2.,1.)}) + check_clock_inventory(p,{(0.,1.),(1.,1.),(2.+1e-15,1.)}) + + def test_missing_first_middle_and_final_steps(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);(p/'inputs').mkdir() + (p/'inputs/config.nml').write_text('tdur = 3\n') + for clocks,message in [({(1.,1.),(2.,1.)},'begin'), + ({(0.,1.),(2.,1.)},'Noncontiguous'), + ({(0.,1.),(1.,1.)},'duration')]: + with self.subTest(clocks=clocks),self.assertRaisesRegex(ValueError,message): + check_clock_inventory(p,clocks) + + def test_overlaps_nonadvancing_clocks_and_invalid_duration(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d) + for clocks in [{(0.,2.),(1.,1.)},{(0.,0.)},{(-1.,1.)},{(0.,float('nan'))}]: + with self.subTest(clocks=clocks),self.assertRaises(ValueError):check_clock_inventory(p,clocks) + (p/'inputs').mkdir() + for value in ['nan','inf','0','-1','1,2','']: + (p/'inputs/config.nml').write_text('tdur = '+value+'\n') + with self.subTest(value=value),self.assertRaises(ValueError):check_clock_inventory(p,{(0.,1.)}) + +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_continuity_floor.py b/test/qualification/test_continuity_floor.py new file mode 100644 index 000000000..6b654544e --- /dev/null +++ b/test/qualification/test_continuity_floor.py @@ -0,0 +1,17 @@ +import argparse +import csv +import os +from pathlib import Path +import subprocess +import sys +import tempfile +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from check_transport import check_continuity +p=argparse.ArgumentParser();p.add_argument('--exe',type=Path,required=True);a=p.parse_args() +with tempfile.TemporaryDirectory() as d: + proc=subprocess.run([str(a.exe),d],env=dict(os.environ,GEMINI_NUMERICAL_AUDIT='1'),capture_output=True,text=True) + assert proc.returncode==0,proc.stdout+proc.stderr + result=check_continuity(Path(d)) + assert result['passed'],result + assert set(result['total_cleanup_number_by_species'].values())=={10.5},result + print('Native cleanup adds 10.5 particles to each ion species across seven physical cells; null and ghost cells excluded; balance closes.') diff --git a/test/qualification/test_driver_preflight.py b/test/qualification/test_driver_preflight.py new file mode 100644 index 000000000..a2d5860f9 --- /dev/null +++ b/test/qualification/test_driver_preflight.py @@ -0,0 +1,82 @@ +import datetime as dt +import importlib.util +from pathlib import Path +import tempfile +import unittest +import sys +import h5py +import numpy as np +p=Path(__file__).resolve().parents[2]/'scripts/qualification/validate_driver.py' +sys.path.insert(0,str(p.parent)) +s=importlib.util.spec_from_file_location('driver',p);d=importlib.util.module_from_spec(s);s.loader.exec_module(d) +class Driver(unittest.TestCase): + def test_midnight_gaps_and_nonfinite(self): + with tempfile.TemporaryDirectory() as path: + root=Path(path);names=['20261231_86340.000000.h5','20270101_00000.000000.h5','20270101_00060.000000.h5'] + for name in names: + with h5py.File(root/name,'w') as f:f['flux']=np.zeros((2,3)) + start=d.utc('2026-12-31T23:59:00');stop=d.utc('2027-01-01T00:01:00') + self.assertTrue(d.validate(root,start,stop,60)['passed']) + with h5py.File(root/names[1],'r+') as f:f['flux'][0,0]=np.nan + with self.assertRaisesRegex(ValueError,'Nonfinite'):d.validate(root,start,stop,60) + (root/names[1]).unlink() + with self.assertRaisesRegex(ValueError,'cadence'):d.validate(root,start,stop,60) + with self.assertRaisesRegex(ValueError,'cover'):d.validate(root,start,stop+dt.timedelta(seconds=60),120) + def test_external_link_and_shape_change(self): + with tempfile.TemporaryDirectory() as path: + root=Path(path) + with h5py.File(root/'20260101_00000.000000.h5','w') as f:f['flux']=[1,2] + with h5py.File(root/'20260101_00060.000000.h5','w') as f:f['flux']=[1,2,3] + args=(root,d.utc('2026-01-01'),d.utc('2026-01-01T00:01:00'),60) + with self.assertRaisesRegex(ValueError,'shape'):d.validate(*args) + with h5py.File(root/'20260101_00060.000000.h5','w') as f:f['flux']=h5py.ExternalLink('missing.h5','/flux') + with self.assertRaisesRegex(ValueError,'links'):d.validate(*args) + def test_timestamp_mismatch(self): + with tempfile.TemporaryDirectory() as path: + root=Path(path) + for sec in [0,60]: + with h5py.File(root/f'20260101_{sec:05d}.000000.h5','w') as f: + f['flux']=[1.,2.];f['time/ymd']=[2026,1,1];f['time/UTsec']=sec + args=(root,d.utc('2026-01-01'),d.utc('2026-01-01T00:01:00'),60) + self.assertTrue(d.validate(*args)['passed']) + with h5py.File(root/'20260101_00060.000000.h5','r+') as f:f['time/UTsec'][...]=0 + with self.assertRaisesRegex(ValueError,'metadata'):d.validate(*args) +class RequiredSchema(unittest.TestCase): + def fixture(self,root,kind): + with h5py.File(root/'simsize.h5','w') as f:f['Nlat']=2;f['Nlon']=3 + with h5py.File(root/'simgrid.h5','w') as f:f['mlat']=[65.,66.];f['mlon']=[200.,201.,202.] + for sec in [0,60]: + with h5py.File(root/f'20260101_{sec:05d}.000000.h5','w') as f: + f['time/ymd']=[2026,1,1];f['time/UTsec']=sec + if kind=='precip':f['Qp']=np.ones((2,3));f['E0p']=np.ones((2,3))*1000 + else: + for k in ['Exit','Eyit','Vminx1it','Vmaxx1it']:f[k]=np.zeros((2,3)) + for k in ['Vminx2ist','Vmaxx2ist']:f[k]=np.zeros(2) + for k in ['Vminx3ist','Vmaxx3ist']:f[k]=np.zeros(3) + f['flagdirich']=1 + return (root,d.utc('2026-01-01'),d.utc('2026-01-01T00:01:00'),60,kind) + def test_required_fields_axis_order_and_flags(self): + for mutation,expected in [('missing','required field'),('transpose','shape'),('flag','categorical'),('time','metadata')]: + with self.subTest(mutation=mutation),tempfile.TemporaryDirectory() as path: + root=Path(path);args=self.fixture(root,'efield') + self.assertTrue(d.validate(*args)['required_schema_checked']) + with h5py.File(root/'20260101_00000.000000.h5','r+') as f: + if mutation=='missing':del f['Exit'] + if mutation=='transpose':del f['Exit'];f['Exit']=np.zeros((3,2)) + if mutation=='flag':f['flagdirich'][...]=9 + if mutation=='time':del f['time/UTsec'] + with self.assertRaisesRegex(ValueError,expected):d.validate(*args) + def test_precipitation_sign_and_coordinate_grid(self): + for mutation,expected in [('flux','Negative'),('energy','positive'),('coordinate','increasing'),('link','link')]: + with self.subTest(mutation=mutation),tempfile.TemporaryDirectory() as path: + root=Path(path);args=self.fixture(root,'precip') + self.assertTrue(d.validate(*args)['passed']) + if mutation=='coordinate': + with h5py.File(root/'simgrid.h5','r+') as f:f['mlon'][...]=[202.,201.,200.] + elif mutation=='link': + with h5py.File(root/'simgrid.h5','r+') as f:del f['mlat'];f['mlat']=h5py.SoftLink('/mlon') + else: + with h5py.File(root/'20260101_00000.000000.h5','r+') as f: + f['Qp' if mutation=='flux' else 'E0p'][0,0]=-1 + with self.assertRaisesRegex(ValueError,expected):d.validate(*args) +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_energy_ledger.py b/test/qualification/test_energy_ledger.py new file mode 100644 index 000000000..8be2177c3 --- /dev/null +++ b/test/qualification/test_energy_ledger.py @@ -0,0 +1,64 @@ +import csv +from pathlib import Path +import sys,tempfile,unittest +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from check_energy_operators import check + +class EnergyLedger(unittest.TestCase): + def fixture(self,p): + keys=['t','dt','stage','species','before_J','after_J','delta_J',*[f'term{i}_J' for i in range(1,6)],'scale_J','residual_J'] + records=[] + for t in (0,1): + for stage in (1,2): + for species in range(1,8): + values=[t,1,stage,species,10,11,1,1,0,0,0,0,11,0] + records.append(dict(zip(keys,values))) + self.save(p,records) + (p/'continuity-r00000000.csv').write_text('t,dt,species\n0,1,1\n1,1,1\n') + return records + def save(self,p,records): + with (p/'energy-operators-r00000000.csv').open('w') as f: + w=csv.DictWriter(f,fieldnames=list(records[0]));w.writeheader();w.writerows(records) + def test_complete_and_missing_later_step(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);r=self.fixture(p);self.assertTrue(check(p,1)['passed']) + self.save(p,r[:-1]) + with self.assertRaisesRegex(ValueError,'Missing'):check(p,1) + def test_faults_cannot_hide_in_logged_residual(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);r=self.fixture(p);r[-1]['term3_J']=.01;self.save(p,r) + self.assertFalse(check(p,1)['passed']) + r=self.fixture(p);r[0]['delta_J']=float('nan');self.save(p,r) + with self.assertRaisesRegex(ValueError,'Nonfinite'):check(p,1) + def test_rank_clock_scale_and_duplicate(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);r=self.fixture(p) + with self.assertRaisesRegex(ValueError,'inventory'):check(p,2) + r[0]['scale_J']=1;self.save(p,r) + with self.assertRaisesRegex(ValueError,'scale'):check(p,1) + r=self.fixture(p);r.append(r[-1]);self.save(p,r) + with self.assertRaisesRegex(ValueError,'duplicate'):check(p,1) + def test_four_rank_regression_preserves_all_ledger_checks(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);self.fixture(p) + for rank in range(1,4): + for stem in ('energy-operators','continuity'): + (p/f'{stem}-r{rank:08d}.csv').write_bytes((p/f'{stem}-r00000000.csv').read_bytes()) + result=check(p,4) + self.assertTrue(result['passed']) + self.assertEqual(result['rows'],2*4*2*7) + last=p/'energy-operators-r00000003.csv';original=last.read_text() + last.write_text(original.replace(',10,11,1,',',10,11,2,',1)) + self.assertFalse(check(p,4)['passed']) + last.write_text('\n'.join(original.splitlines()[:-1])+'\n') + with self.assertRaisesRegex(ValueError,'Missing'):check(p,4) + last.write_text(original) + continuity=p/'continuity-r00000003.csv';continuity.write_text('t,dt\n0,1\n') + with self.assertRaisesRegex(ValueError,'Energy/continuity'):check(p,4) + continuity.write_bytes((p/'continuity-r00000000.csv').read_bytes()) + last.unlink() + with self.assertRaisesRegex(ValueError,'inventory'):check(p,4) + last.write_text(original) + (p/'energy-operators-r00000004.csv').write_text(original) + with self.assertRaisesRegex(ValueError,'inventory'):check(p,4) +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_etd.py b/test/qualification/test_etd.py new file mode 100644 index 000000000..23a607253 --- /dev/null +++ b/test/qualification/test_etd.py @@ -0,0 +1,44 @@ +"""Native ETD checked against an 80-digit independent Decimal analytic oracle.""" +import argparse +import decimal +import json +import math +from pathlib import Path +import subprocess + + +def main(): + p=argparse.ArgumentParser();p.add_argument('--exe',required=True) + p.add_argument('--output',type=Path);a=p.parse_args() + cases=[] + for z in [0,1e-16,1e-12,1e-10,1.01e-10,1e-8,1e-6,.001,.009999,.01,.1,1,50]: + for sign in [-1,1]: + for f,source,dt in [(2,3,1),(1e12,1e4,.01),(-2,3,10),(1,-.1,1)]: + cases.append((f,source,sign*z/dt,dt)) + # Equilibria across the branch threshold and tiny but dynamically important loss. + cases += [(1e20,0,5e-11,1),(1e8,1,1e-8,1),(1,1,1,1)] + proc=subprocess.run([a.exe],input=''.join(' '.join(map(str,c))+'\n' for c in cases), + text=True,capture_output=True,check=True) + values=[float(x) for x in proc.stdout.split()] + if len(values)!=len(cases):raise AssertionError('Missing native results') + errors=[];old_failures=0 + with decimal.localcontext() as ctx: + ctx.prec=80 + for case,value in zip(cases,values): + f,p,l,dt=map(lambda x:decimal.Decimal(str(x)),case) + exact=f+p*dt if l==0 else f*(-l*dt).exp()+p/l*(1-(-l*dt).exp()) + scale=max(abs(float(exact)),abs(float(f)),abs(float(p*dt)),1e-300) + error=abs(value-float(exact))/scale + if not math.isfinite(value) or error>5e-14:raise AssertionError((case,value,str(exact),error)) + z=float(l*dt) + old=float(f)*math.exp(-z)+float(p/l)*(1-math.exp(-z)) if z>1e-10 else float(f+p*dt) + old_failures+=abs(old-float(exact))/scale>5e-14 + errors.append(error) + result=dict(schema='gemini.etd.oracle.1',passed=True,cases=len(cases),precision_digits=80, + max_scaled_error=max(errors),budget=5e-14,old_formula_failing_cases=old_failures) + if not old_failures:raise AssertionError('Test must detect the previous defect') + if a.output:a.output.write_text(json.dumps(result,indent=2)+'\n') + print(json.dumps(result)) + + +if __name__=='__main__':main() diff --git a/test/qualification/test_exchange.py b/test/qualification/test_exchange.py new file mode 100644 index 000000000..6f0ff26aa --- /dev/null +++ b/test/qualification/test_exchange.py @@ -0,0 +1,117 @@ +import sys +from datetime import datetime,timezone +from pathlib import Path +import tempfile +import unittest +import h5py +import numpy as np +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from state_exchange import export,read_exchange,restore_output,cvtwin_mhd6,FIELDS,native_time +from conservative_exchange import remap,volumes,reservoir_step + + +class Exchange(unittest.TestCase): + def test_conservative_remap_nonuniform_and_reject_holes(self): + source=[np.array([0,.2,.5,1]),np.array([0,.1,1]),np.array([0,.7,1])] + target=[np.array([0,.1,.4,.8,1]),np.array([0,.4,.8,1]),np.array([0,.2,.6,1])] + q=np.random.default_rng(912).normal(size=(3,2,2,4)) + mapped=remap(q,source,target) + np.testing.assert_allclose(np.sum(q*volumes(source)[...,None],axis=(0,1,2)), + np.sum(mapped*volumes(target)[...,None],axis=(0,1,2)),rtol=1e-13,atol=1e-14) + np.testing.assert_allclose(remap(np.ones_like(q)*7,source,target),7,rtol=1e-14) + np.testing.assert_allclose(remap(q,source,source),q,rtol=2e-15,atol=1e-15) + with self.assertRaisesRegex(ValueError,'Masked'):remap(q,source,target,valid=np.zeros((3,2,2),bool)) + target[0][-1]=1.1 + with self.assertRaisesRegex(ValueError,'domains'):remap(q,source,target) + + def test_stiff_passive_exchange_conserves_and_dissipates(self): + for dt in [0,1e-12,.01,1,1e8]: + a,b,t=reservoir_step(300,100,2,3,7,dt) + self.assertAlmostEqual(2*a+3*b,900,places=11) + self.assertLessEqual(abs(a-b),200) + self.assertAlmostEqual(a-b,200*np.exp(-7*(1/2+1/3)*dt),places=11) + self.assertGreaterEqual(t,0) + with self.assertRaises(ValueError):reservoir_step(1,2,-1,1,1,1) + with self.assertRaises(ValueError):cvtwin_mhd6(None) + + def test_remap_accepts_only_boolean_or_binary_integer_masks(self): + grid=[np.array([0.,.2,1.])]*3 + q=np.arange(16,dtype=float).reshape(2,2,2,2) + for dtype in [bool,np.int8,np.int64,np.uint8,np.uint64]: + with self.subTest(dtype=dtype): + np.testing.assert_allclose(remap(q,grid,grid,np.ones((2,2,2),dtype=dtype)),q) + for value in [2,-1,0.5,1.,float('nan'),float('inf'),'true','1',1+0j,None]: + with self.subTest(invalid=value): + with self.assertRaisesRegex(ValueError,'Boolean or zero/one'): + remap(q,grid,grid,np.full((2,2,2),value)) + for mask in [np.zeros((2,2,2),int),np.ones((2,2,1),bool),np.array(True)]: + with self.subTest(mask=mask): + with self.assertRaisesRegex(ValueError,'Masked'): + remap(q,grid,grid,mask) + with self.assertRaisesRegex(ValueError,'Boolean or zero/one'): + remap(q,grid,grid,np.ones((2,2,2),dtype=object)) + + def fixture(self,p): + shape=(2,3,4);grid=p/'grid.h5';frame=p/'20130220_18060.000000.h5' + with h5py.File(grid,'w') as f: + f['nullpts']=np.zeros(shape,dtype='i4');f['nullpts'][0,0,0]=1 + for i in range(3): + f[f'e{i+1}']=np.broadcast_to(np.eye(3,dtype='f4')[i][:,None,None,None],(3,*shape)) + for key in ['r','theta','phi','glat','glon','alt','Bmag']:f[key]=np.ones(shape,dtype='f4') + for key in ['h1','h2','h3']:f[key]=np.ones(tuple(n+4 for n in shape),dtype='f4') + for key,n in zip(['x1','x2','x3'],shape[::-1]):f[key]=np.arange(n+4,dtype='f4') + with h5py.File(frame,'w') as f: + f['flagoutput']=1;f['time/ymd']=[2013,2,20];f['time/UThour']=5+1/60 + for original in FIELDS: + sizes=(7,*shape) if original in ('nsall','Tsall','vs1all') else (shape[:2] if original=='Phiall' else shape) + f[original]=np.random.default_rng(513).normal(size=sizes).astype('f4') + return frame,grid + + def test_roundtrip_units_mask_basis_and_timestamp(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);frame,grid=self.fixture(p);out=p/'exchange.h5' + export(frame,grid,out);_,mask,_,_=read_exchange(out) + self.assertFalse(mask[0,0,0]);self.assertEqual(mask.sum(),23) + restored=restore_output(out,p/'roundtrip.h5') + with h5py.File(frame) as a,h5py.File(restored) as b: + for key in FIELDS: + self.assertEqual(a[key].dtype,b[key].dtype) + np.testing.assert_array_equal(a[key][...],b[key][...]) + with h5py.File(out,'r+') as f:f['state/number_density'].attrs['units']='cm^-3' + with self.assertRaisesRegex(ValueError,'Unit'):read_exchange(out) + with h5py.File(frame,'r+') as f:f['time/UThour'][...]=6 + with self.assertRaisesRegex(ValueError,'UTC'):export(frame,grid,p/'bad.h5') + + def test_rejects_corrupt_geometry(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);frame,grid=self.fixture(p) + with h5py.File(grid,'r+') as f:f['e1'][...]=0 + with self.assertRaisesRegex(ValueError,'orthonormal'):export(frame,grid,p/'bad.h5') + + def test_native_filename_rounding_and_calendar_rollover(self): + # The native initial frame is written one microsecond after its nominal + # filename. Check that exact observed value and all calendar boundaries. + cases=[([2013,2,20],18000.000001,'2013-02-20T05:00:00+00:00'), + ([2013,2,20],.055,'2013-02-20T00:00:00.060000+00:00'), + ([2013,2,20],18060.004,'2013-02-20T05:01:00+00:00'), + ([2013,2,20],18060.006,'2013-02-20T05:01:00.010000+00:00'), + ([2013,2,28],86399.999,'2013-03-01T00:00:00+00:00'), + ([2012,2,28],86399.999,'2012-02-29T00:00:00+00:00'), + ([2013,12,31],86399.999,'2014-01-01T00:00:00+00:00')] + for date,seconds,stamp in cases: + hour=np.asarray(seconds/3600,dtype='f8') + metadata=native_time(np.asarray(date),hour,datetime.fromisoformat(stamp)) + self.assertEqual(float.fromhex(metadata['native_ut_hour_hex']),float(hour)) + self.assertEqual(metadata['filename_utc'],stamp) + instant=datetime(2013,2,20,5,1,tzinfo=timezone.utc) + with self.assertRaisesRegex(ValueError,'mismatch'): + native_time(np.array([2013,2,20]),np.asarray(18060.006/3600),instant) + with self.assertRaisesRegex(ValueError,'mismatch'): + native_time(np.array([2013,2,20]),np.asarray(18060.001/3600), + instant.replace(microsecond=1000)) + for date,hour in [(np.array([2013,2,29]),5.),(np.array([2013.,2.,20.]),5.), + (np.array([2013,2,20]),24.),(np.array([2013,2,20]),float('nan'))]: + with self.assertRaisesRegex(ValueError,'UTC'):native_time(date,np.asarray(hour),instant) + + +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_gates.py b/test/qualification/test_gates.py new file mode 100644 index 000000000..9baf01bdc --- /dev/null +++ b/test/qualification/test_gates.py @@ -0,0 +1,47 @@ +import copy +import hashlib +import importlib.util +from pathlib import Path +import tempfile +import unittest +p = Path(__file__).resolve().parents[2] / 'scripts/qualification/evaluate_gates.py' +s = importlib.util.spec_from_file_location('gates', p) +g = importlib.util.module_from_spec(s); s.loader.exec_module(g) + + +class Gates(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory(); self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) + (self.root/'proof.txt').write_text('Synthetic test evidence, not project qualification.\n') + item = dict(path='proof.txt', sha256=hashlib.sha256((self.root/'proof.txt').read_bytes()).hexdigest()) + self.register = dict(candidate_commit='a'*40, gates=[dict(id=f'R{i:02d}', status='closed', + tested_commit='a'*40, evidence=[copy.deepcopy(item)]) for i in range(1,19)]) + + def test_hash_and_commit(self): + self.assertTrue(g.evaluate(self.register,self.root)['qualified']) + self.register['gates'][0]['tested_commit']='b'*40 + self.assertFalse(g.evaluate(self.register,self.root)['qualified']) + self.register['gates'][0]['tested_commit']='a'*40 + (self.root/'proof.txt').write_text('changed') + self.assertFalse(g.evaluate(self.register,self.root)['qualified']) + + def test_omission_and_escape(self): + self.register['gates'].pop() + with self.assertRaisesRegex(ValueError,'18 gates'):g.evaluate(self.register,self.root) + self.register['gates'][0]['evidence'][0]['path']='../outside' + with self.assertRaisesRegex(ValueError,'inside'):g.evaluate(self.register,self.root) + self.register['candidate_commit']='' + with self.assertRaisesRegex(ValueError,'commit'):g.evaluate(self.register,self.root) + + def test_approval_and_exclusion(self): + gate=self.register['gates'][0];gate['requires_independent_approval']=True + gate['approval_record']=True + self.assertFalse(g.evaluate(self.register,self.root)['qualified']) + gate['applicable']=False;gate['scope_exclusion_approved']=True + self.assertFalse(g.evaluate(self.register,self.root)['qualified']) + gate['scope_exclusion_record']=gate['evidence'][0] + self.assertTrue(g.evaluate(self.register,self.root)['qualified']) + + +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_hdf_policy.py b/test/qualification/test_hdf_policy.py new file mode 100644 index 000000000..7672dbb17 --- /dev/null +++ b/test/qualification/test_hdf_policy.py @@ -0,0 +1,35 @@ +from pathlib import Path +import sys +import tempfile +import unittest +import h5py +import numpy as np +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from hdf_policy import numeric,inspect_dataset + + +class Policy(unittest.TestCase): + def test_external_storage_vds_and_link_rejected(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d) + with h5py.File(p/'test.h5','w') as f: + ext=f.create_dataset('external',(10,),dtype='f8',external=[('never-read.bin',0,80)]) + with self.assertRaisesRegex(ValueError,'External'):inspect_dataset(ext) + layout=h5py.VirtualLayout((10,),dtype='f8');layout[:]=h5py.VirtualSource('missing.h5','x',shape=(10,)) + vds=f.create_virtual_dataset('vds',layout) + with self.assertRaisesRegex(ValueError,'Virtual'):inspect_dataset(vds) + f['linked']=h5py.ExternalLink('missing.h5','group') + with self.assertRaisesRegex(ValueError,'indirect'):numeric(f,'linked/value') + + def test_limit_checked_without_allocating_and_builtin_filter(self): + with tempfile.TemporaryDirectory() as d: + with h5py.File(Path(d)/'test.h5','w') as f: + sparse=f.create_dataset('large',(2**30,),dtype='f8',chunks=(1024,)) + with self.assertRaisesRegex(ValueError,'allocation'):inspect_dataset(sparse) + f.create_dataset('compressed',data=np.arange(30),compression='gzip',shuffle=True,fletcher32=True) + np.testing.assert_array_equal(numeric(f,'compressed'),np.arange(30)) + f.create_dataset('lossy',data=np.arange(10,dtype=float),scaleoffset=2) + with self.assertRaisesRegex(ValueError,'filter'):numeric(f,'lossy') + + +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_host_capabilities.py b/test/qualification/test_host_capabilities.py new file mode 100644 index 000000000..5b618ddf8 --- /dev/null +++ b/test/qualification/test_host_capabilities.py @@ -0,0 +1,24 @@ +from pathlib import Path +import sys,tempfile,unittest +from unittest.mock import patch +from types import SimpleNamespace +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from host_capabilities import leak_probe + +class LeakControls(unittest.TestCase): + def run_probe(self,leak_output,clean_code=0): + with tempfile.TemporaryDirectory() as d: + work=Path(d)/'probe' + def fake(command,**kwargs): + if '-fsanitize=address' in command: + (work/'leak_control').write_bytes(b'fixture') + return SimpleNamespace(returncode=0,stdout='',stderr='') + is_leak=command[-1]=='leak' + return SimpleNamespace(returncode=23 if is_leak else clean_code,stdout='',stderr=leak_output if is_leak else '') + with patch('host_capabilities.subprocess.run',side_effect=fake):return leak_probe('cc',work) + def test_detected_positive_control(self): + self.assertTrue(self.run_probe('LeakSanitizer: detected memory leaks\n1237 byte(s) leaked')['passed']) + def test_runtime_crash_is_not_leak_detection(self): + self.assertFalse(self.run_probe('LeakSanitizer has encountered a fatal error')['passed']) + self.assertFalse(self.run_probe('LeakSanitizer: detected memory leaks\n1237 byte(s) leaked',23)['passed']) +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_hosted_evidence.py b/test/qualification/test_hosted_evidence.py new file mode 100644 index 000000000..368a76c87 --- /dev/null +++ b/test/qualification/test_hosted_evidence.py @@ -0,0 +1,130 @@ +import copy +from pathlib import Path +import json,re,shlex,shutil,subprocess,sys,unittest +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from hosted_evidence import verify,REQUIRED,WORKFLOW,REQUIRED_STEPS +class HostedEvidence(unittest.TestCase): + def fixture(self): + run=dict(repository={'full_name':'example/research'},head_sha='a'*40,path=WORKFLOW,status='completed',conclusion='success',run_attempt=2,id=99) + jobs=[dict(name=name,status='completed',conclusion='success',run_id=99,run_attempt=2,head_sha='a'*40, + steps=[dict(name=n,conclusion='success') for n in REQUIRED_STEPS[name]]) for name in REQUIRED] + return run,jobs + def test_exact_success_and_stale_identity(self): + run,jobs=self.fixture();self.assertTrue(verify(run,jobs,'example/research','a'*40,2)['passed']) + for key,value in [('head_sha','b'*40),('run_attempt',1),('run_id',98)]: + bad=copy.deepcopy(jobs);bad[0][key]=value + self.assertFalse(verify(run,bad,'example/research','a'*40,2)['passed']) + def test_missing_skipped_duplicate_and_masked_failure(self): + run,jobs=self.fixture() + for bad in [jobs[:-1],jobs+[jobs[0]]]:self.assertFalse(verify(run,bad,'example/research','a'*40,2)['passed']) + for verdict in ['skipped','failure','cancelled']: + bad=copy.deepcopy(jobs);bad[0]['conclusion']=verdict + self.assertFalse(verify(run,bad,'example/research','a'*40,2)['passed']) + jobs[0]['steps'][0]['conclusion']='failure' + self.assertFalse(verify(run,jobs,'example/research','a'*40,2)['passed']) + def test_skipped_required_step_fails_successful_job(self): + run,jobs=self.fixture();jobs[0]['steps'][0]['conclusion']='skipped' + self.assertFalse(verify(run,jobs,'example/research','a'*40,2)['passed']) + def test_debug_requires_native_numerical_budgets(self): + run,jobs=self.fixture() + job=next(j for j in jobs if j['name']=='native (Debug)') + step='Qualify exact restart and native numerical budgets' + self.assertIn(step,REQUIRED_STEPS[job['name']]) + for conclusion in ['skipped',None]: + with self.subTest(conclusion=conclusion): + bad=copy.deepcopy(jobs) + debug=next(j for j in bad if j['name']=='native (Debug)') + if conclusion is None: + debug['steps']=[s for s in debug['steps'] if s['name']!=step] + else: + next(s for s in debug['steps'] if s['name']==step)['conclusion']=conclusion + self.assertFalse(verify(run,bad,'example/research','a'*40,2)['passed']) + def test_workflow_pipelines_fail_closed(self): + workflow=(Path(__file__).resolve().parents[2]/WORKFLOW).read_text() + self.assertRegex(workflow,r'(?m)^defaults:\n run:\n shell: bash\s*$') + @unittest.skipUnless(shutil.which('bash'),'Bash is required to exercise GitHub shell semantics') + def test_explicit_github_bash_rejects_pipeline_failure(self): + # GitHub adds pipefail only when the Bash shell is explicitly selected. + result=subprocess.run(['bash','--noprofile','--norc','-e','-o','pipefail','-c', + 'false | tee'],capture_output=True,text=True,timeout=10) + self.assertNotEqual(result.returncode,0) + def test_workflow_preserves_required_executable_contract(self): + root=Path(__file__).resolve().parents[2] + workflow=(root/WORKFLOW).read_text() + self.assertRegex(workflow,r'(?m)^ pull_request:\s*$') + self.assertRegex(workflow,r'(?m)^ push:\s*$') + self.assertNotIn('paths-ignore:',workflow) + self.assertNotIn('continue-on-error:',workflow) + jobs=dict(re.findall(r'(?ms)^ (native|current-hdf5|sanitizers):\n(.*?)(?=^ \w[\w-]*:\n|\Z)',workflow)) + self.assertEqual(set(jobs),{'native','current-hdf5','sanitizers'}) + for name,steps in REQUIRED_STEPS.items(): + block=jobs['native' if name.startswith('native ') else name] + for step in steps: + self.assertEqual(block.count('- name: '+step+'\n'),1,(name,step)) + self.assertIn('uses: ./.github/workflows/qualification-evidence',block) + self.assertIn('ref: ${{ env.CANDIDATE_COMMIT }}',block) + self.assertIn('build_type: Debug',jobs['native']) + self.assertIn('build_type: Release',jobs['native']) + research=re.search(r'(?ms)^ - name: Qualify exact restart and native numerical budgets\n' + r' run: \|\n(.*?)(?=^ - |\Z)',jobs['native']) + self.assertIsNotNone(research) + command=shlex.split(research[1].replace('\\\n',' '),comments=True) + command=command[:command.index('|')] + self.assertEqual(command[:2],['python','test/qualification/research_matrix.py']) + self.assertIn('--extended-layouts',command) + self.assertNotIn('--quick',command) + self.assertEqual(command[command.index('--work')+1],'build/research') + for case in ['mini2dns_fang','mini2dew_fang','mini3d_fang','mini2dns_fang_cpp', + 'mini2dns_glow','mini2dew_glow','mini3d_glow','mini2dns_glow_cpp','mini2dns_msis2_fang']: + self.assertIn('"'+case+'"',jobs['native']) + self.assertNotIn('--quick',workflow) + self.assertIn('host_capabilities.py --only leak',jobs['sanitizers']) + self.assertIn('detect_leaks=1:halt_on_error=1',jobs['sanitizers']) + self.assertIn('fast_unwind_on_malloc=0',jobs['sanitizers']) + self.assertIn('LSAN_OPTIONS: exitcode=23:suppressions=${{ github.workspace }}/.github/lsan-openmpi.supp', + jobs['sanitizers']) + self.assertIn('PMIX_MCA_gds: hash',jobs['sanitizers']) + self.assertEqual((root/'.github/lsan-openmpi.supp').read_text().strip().splitlines(), + ['# OpenMPI 4.x on Ubuntu 24.04 leaks hwloc allocations during MPI_Init().', + 'leak:ompi_mpi_init', + '# OpenMPI 4.x on Ubuntu 24.04 leaves process-lifetime allocations visible during MPI_Finalize().', + 'leak:orte_finalize', + '# OpenMPI 4.x on Ubuntu 24.04 leaves process-lifetime libevent thread allocations visible to LSAN.', + 'leak:event_base_loop', + '# OpenMPI 4.x on Ubuntu 24.04 leaves one component-registration strdup visible to LSAN.', + 'leak:mca_base_framework_components_register', + '# Ubuntu 24.04 OpenBLAS (0.3.26) leaves process-lifetime allocations visible to LSAN.', + 'leak:libopenblasp-r0.3.26.so', + '# Ubuntu 24.04 UBSan runtime leaves process-lifetime allocations visible to LSAN.', + 'leak:libubsan.so.1.0.0']) + self.assertIn('kernel_memory.py',jobs['current-hdf5']) + self.assertIn('for repetition in 1 2 3',jobs['current-hdf5']) + presets=json.loads((root/'CMakePresets.json').read_text())['configurePresets'] + qualification=next(p for p in presets if p['name']=='qualification')['cacheVariables'] + for key in ['BUILD_TESTING','gemini3d_BUILD_TESTING','gemini3d_require_qualification', + 'gemini3d_test_simulations','gemini3d_glow','gemini3d_msis2']: + self.assertIs(qualification[key],True) + self.assertIs(qualification['gemini3d_hwm14'],False) + self.assertIn("mini2dns_fang_cpp",jobs['sanitizers']) + def test_install_smoke_exercises_real_entrypoints(self): + root=Path(__file__).resolve().parents[2] + workflow=(root/'.github/workflows/install-smoke.yml').read_text() + self.assertRegex(workflow,r'(?m)^ pull_request:\s*$') + self.assertRegex(workflow,r'(?m)^ push:\s*$') + self.assertNotIn('paths-ignore:',workflow) + self.assertNotIn('continue-on-error:',workflow) + for platform in ['ubuntu-24.04','macos-14','Ubuntu-24.04']: + self.assertIn(platform,workflow) + jobs=dict(re.findall(r'(?ms)^ (unix|wsl):\n(.*?)(?=^ \w[\w-]*:\n|\Z)',workflow)) + self.assertEqual(set(jobs),{'unix','wsl'}) + self.assertRegex(jobs['wsl'],r'(?m)^ runs-on: windows-(?:latest|\d{4})\s*$') + bash='bash scripts/install-local.sh --system-deps --root "$PWD/build/local-install" --jobs 2' + self.assertEqual(workflow.count(bash),1) + self.assertEqual(jobs['unix'].count(bash),1) + self.assertIn('& ./scripts/install-local.ps1 -Distribution Ubuntu-24.04 -SystemDeps',jobs['wsl']) + self.assertIn('-Root "$($linuxRoot.Trim())/build/local-install" -Jobs 2',jobs['wsl']) + self.assertRegex(jobs['wsl'],r'(?m)^ - name: Install through the WSL local entrypoint\n shell: pwsh\s*$') + self.assertEqual(workflow.count('scripts/local_environment.py check'),2) + self.assertEqual(workflow.count('build/local-install/environment.json'),2) + self.assertEqual(workflow.count('if-no-files-found: error'),2) +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_igrf.py b/test/qualification/test_igrf.py new file mode 100644 index 000000000..997333f30 --- /dev/null +++ b/test/qualification/test_igrf.py @@ -0,0 +1,39 @@ +"""Compare independent spherical harmonics to official IAGA/NOAA Fortran.""" +import argparse +import importlib.util +import itertools +import json +from pathlib import Path +import subprocess +import math + +p=argparse.ArgumentParser();p.add_argument('--exe',required=True);p.add_argument('--output',type=Path,required=True) +a=p.parse_args();root=Path(__file__).resolve().parents[2] +spec=importlib.util.spec_from_file_location('igrf14',root/'scripts/qualification/igrf14.py') +module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module) +rows=module.coefficients(root/'test/qualification/data/igrf14coeffs.txt') +cases=list(itertools.product([2025,2026,2027.5,2029.75,2030], [6371.2,6471.2,6671.2,7371.2], + [-89,-70,-30,0,30,70,89],[-180,-90,0,45,179,360])) +text=''.join(f'{y} {r} {90-lat} {lon%360}\n' for y,r,lat,lon in cases) +proc=subprocess.run([a.exe],input=text,text=True,capture_output=True,check=True) +ref=[list(map(float,line.split())) for line in proc.stdout.splitlines() if line.strip()] +if len(ref)!=len(cases):raise ValueError('Official oracle did not return each case') +records=[] +# Official code uses a truncated degree/radian constant; 0.05 nT is far +# below 0.1 nT coefficient rounding, and is fixed before viewing results. +limit_nt=0.05 +for case,truth in zip(cases,ref): + value=module.field(rows,*case);error=max(abs(a-b) for a,b in zip(value,truth)) + if not math.isfinite(error):raise ValueError('Nonfinite field residual') + records.append(dict(input=case,max_component_error_nt=error)) +rejected=0 +for c in [(2031,6671.2,0,0),(2026,0,0,0),(2026,6671.2,90,0),(float('nan'),6671.2,0,0)]: + try: module.field(rows,*c) + except ValueError:rejected+=1 +payload=dict(schema='gemini.qualification.igrf14.1',cases=len(records),rejected_inputs=rejected, + acceptance_max_component_error_nt=limit_nt,max_component_error_nt=max(x['max_component_error_nt'] for x in records), + production_grid_qualified=False,scope='geocentric field oracle, not coordinated grid/basis/driver transforms',records=records) +payload['passed']=payload['max_component_error_nt']<=limit_nt and rejected==4 +a.output.write_text(json.dumps(payload,indent=2)+'\n') +print(json.dumps({k:v for k,v in payload.items() if k!='records'},indent=2)) +raise SystemExit(0 if payload['passed'] else 1) diff --git a/test/qualification/test_kernel_memory.py b/test/qualification/test_kernel_memory.py new file mode 100644 index 000000000..78ad6a93b --- /dev/null +++ b/test/qualification/test_kernel_memory.py @@ -0,0 +1,43 @@ +from pathlib import Path +import os +import sys +import tempfile +import unittest +from unittest.mock import patch +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from kernel_memory import measure + + +class KernelMemory(unittest.TestCase): + @unittest.skipUnless(os.name=='posix','cgroup preexec hook requires POSIX') + def test_child_pid_is_registered_before_exec(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);group=p/'gemini-qualification-test';group.mkdir() + for name,value in {'cgroup.procs':'','cgroup.events':'populated 0\n','memory.peak':'0', + 'memory.events':'oom_kill 0\n','memory.max':'max'}.items(): + (group/name).write_text(value) + child_pid=p/'child.pid' + command=[sys.executable,'-c', + 'import os;from pathlib import Path;' + 'Path('+repr(str(child_pid))+').write_text(str(os.getpid()));' + 'Path('+repr(str(group/'memory.peak'))+').write_text("1024")'] + with patch('kernel_memory.uuid.uuid4') as identity, \ + patch.object(Path,'mkdir'),patch.object(Path,'rmdir'): + identity.return_value.hex='test' + result=measure(command,p,p/'result.json',600,2048,660) + self.assertTrue(result['passed'],result) + registered_pid=int((group/'cgroup.procs').read_text()) + self.assertEqual(registered_pid,int(child_pid.read_text())) + self.assertNotEqual(registered_pid,os.getpid()) + + def test_missing_controller_blocks_before_launch(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);marker=p/'must-not-exist' + command=[sys.executable,'-c','from pathlib import Path;Path('+repr(str(marker))+').touch()'] + result=measure(command,p,p/'result.json',600,2048,660) + self.assertEqual(result['status'],'blocked');self.assertFalse(result['passed']) + self.assertFalse(marker.exists());self.assertEqual(list(p.glob('gemini-qualification-*')),[]) + with self.assertRaises(ValueError):measure(command,p,p/'bad.json',float('nan'),2048,660) + + +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_local_environment.py b/test/qualification/test_local_environment.py new file mode 100644 index 000000000..83b929904 --- /dev/null +++ b/test/qualification/test_local_environment.py @@ -0,0 +1,306 @@ +"""Local installer orchestration and fail-closed run checks (no package downloads).""" +import importlib.util +import json +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest +from unittest.mock import patch + +SPEC = importlib.util.spec_from_file_location( + "local_environment", Path(__file__).resolve().parents[2] / "scripts/local_environment.py") +local = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(local) + + +class LocalEnvironment(unittest.TestCase): + @unittest.skipUnless(shutil.which("ctest") and shutil.which("cmake"), "CTest is required") + def test_real_ctest_execution_receipt_and_skipped_test_rejection(self): + with tempfile.TemporaryDirectory(prefix="gemini ctest ") as directory: + root = Path(directory) + cmake = Path(shutil.which("cmake")).as_posix() + tests = root / "CTestTestfile.cmake" + tests.write_text( + f'add_test(passes "{cmake}" -E true)\n' + f'add_test(optional "{cmake}" -E false)\n' + 'set_tests_properties(optional PROPERTIES DISABLED TRUE)\n') + result = local.verified_tests(shutil.which("ctest"), root, None, 1, "fixture", + required={"passes"}) + self.assertEqual(result["passed"], ["passes"]) + self.assertEqual(result["disabled"], ["optional"]) + self.assertEqual(result["junit_sha256"], local.digest(root / result["junit"])) + with self.assertRaisesRegex(RuntimeError, "required tests missing or disabled"): + local.verified_tests(shutil.which("ctest"), root, None, 1, "fixture", required={"optional"}) + tests.write_text(f'add_test(skipped "{cmake}" -E true)\n' + 'set_tests_properties(skipped PROPERTIES SKIP_RETURN_CODE 0)\n') + with self.assertRaisesRegex(RuntimeError, "executed test results"): + local.verified_tests(shutil.which("ctest"), root, None, 1, "fixture") + tests.write_text(f'add_test(failed "{cmake}" -E false)\n') + with self.assertRaises(subprocess.CalledProcessError): + local.verified_tests(shutil.which("ctest"), root, None, 1, "fixture") + + def test_test_receipt_rejects_missing_disabled_duplicate_or_stale_evidence(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + for tests in ([], [{"name": "test", "properties": [{"name": "DISABLED", "value": True}]}], + [{"name": "test"}, {"name": "test"}]): + with self.subTest(tests=tests), patch.object( + local, "execute", return_value=json.dumps({"tests": tests})) as run: + with self.assertRaisesRegex(RuntimeError, "no enabled tests or duplicate"): + local.verified_tests("ctest", root, None, 1, "fixture") + self.assertEqual(run.call_count, 1) + report = root / "local-fixture.xml" + passed = '' + reports = [None, '', passed.replace('name="test"', 'name="other"'), + passed.replace('', ''), + passed.replace('/>', '>'), + passed.replace('/>', '>'), + passed.replace('/>', '>'), + passed.replace('status="run"', 'status="notrun"')] + for contents in reports: + with self.subTest(contents=contents): + report.write_text(passed) + def execute(command, **kwargs): + if "--show-only=json-v1" in command: + return '{"tests":[{"name":"test"}]}' + self.assertFalse(report.exists(), "Old test results must be removed before CTest runs") + if contents is not None: + report.write_text(contents) + return subprocess.CompletedProcess(command, 0) + with patch.object(local, "execute", side_effect=execute): + with self.assertRaises((RuntimeError, FileNotFoundError)): + local.verified_tests("ctest", root, None, 1, "fixture") + + @unittest.skipUnless(shutil.which("pwsh"), "PowerShell is required for WSL wrapper tests") + def test_wsl_install_options_and_exit_status(self): + script = str(local.SOURCE / "scripts/install-local.ps1").replace("'", "''") + command = """ +function wsl.exe { + $global:LASTEXITCODE = 0 + if ($args[3] -eq 'wslpath') { + '/checkout with spaces/scripts/install-local.sh' + } else { + ConvertTo-Json -Compress -InputObject @($args) + $global:LASTEXITCODE = INSTALL_EXIT + } +} +& 'SCRIPT' -Distribution Ubuntu-24.04 -SystemDeps -Root '/local env' ` + -Jobs 3 -BuildType Debug -ReferenceTests -SourceCache '/cache dir/sources.cmake' +""".replace("SCRIPT", script) + run = subprocess.run(["pwsh", "-NoProfile", "-NonInteractive", "-Command", + command.replace("INSTALL_EXIT", "0")], + capture_output=True, text=True) + self.assertEqual(run.returncode, 0, run.stderr) + self.assertEqual(json.loads(run.stdout), [ + "--distribution", "Ubuntu-24.04", "--exec", "bash", + "/checkout with spaces/scripts/install-local.sh", + "--jobs", "3", "--build-type", "Debug", "--system-deps", "--root", "/local env", + "--reference-tests", "--source-cache", "/cache dir/sources.cmake", + ]) + failed = subprocess.run(["pwsh", "-NoProfile", "-NonInteractive", "-Command", + command.replace("INSTALL_EXIT", "17")], + capture_output=True, text=True) + self.assertNotEqual(failed.returncode, 0) + self.assertIn("Local installation failed (exit 17)", failed.stderr) + for old, new in (("-Jobs 3", "-Jobs 0"), ("-BuildType Debug", "-BuildType Invalid")): + invalid = subprocess.run(["pwsh", "-NoProfile", "-NonInteractive", "-Command", + command.replace("INSTALL_EXIT", "0").replace(old, new)], + capture_output=True, text=True) + self.assertNotEqual(invalid.returncode, 0) + self.assertEqual(invalid.stdout, "") + + def test_run_arguments_after_action_and_separator(self): + with tempfile.TemporaryDirectory(prefix="gemini local ") as directory: + root = Path(directory) + exe = root / "install/bin/gemini.bin" + with patch.object(local, "check", return_value=(exe, ["/mpi/mpiexec", "-n"], {})), \ + patch.object(local, "execute") as run: + local.main(["run", "--root", directory, "--case", directory, "--ranks", "2", + "--", "-dryrun", "-manual_grid", "1", "2"]) + self.assertEqual(run.call_args.args[0], + ["/mpi/mpiexec", "-n", 2, exe, root.resolve(), + "-dryrun", "-manual_grid", "1", "2"]) + self.assertEqual(run.call_args.kwargs["cwd"], exe.parent) + + def test_check_requires_success_record_and_never_installs(self): + with tempfile.TemporaryDirectory() as directory, patch.object(local, "execute") as run: + with self.assertRaisesRegex(RuntimeError, "No completed installation"): + local.check(Path(directory)) + run.assert_not_called() + + def test_debug_executable(self): + self.assertEqual(local.executable(Path("/local"), "Debug"), Path("/local/bin/gemini.bin.debug")) + with self.assertRaises(RuntimeError): + local.executable(Path("/local"), "../bad") + + def test_missing_native_prerequisites(self): + with patch.object(local.shutil, "which", return_value=None): + with self.assertRaisesRegex(RuntimeError, "Missing native tools"): + local.native_prerequisites({"PATH": ""}) + + def test_failed_update_invalidates_old_success(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + (root / "venv").mkdir() + (root / "venv/pyvenv.cfg").write_text("fixture") + record = root / "environment.json" + record.write_text("{}") + with patch.object(local, "native_prerequisites"), patch.object( + local, "execute", side_effect=subprocess.CalledProcessError(1, ["pip"])): + with self.assertRaises(SystemExit): + local.main(["install", "--root", directory]) + self.assertFalse(record.exists()) + + @unittest.skipUnless(shutil.which("bash"), "POSIX installer uses bash") + def test_failed_system_update_invalidates_old_success(self): + with tempfile.TemporaryDirectory(prefix="gemini setup ") as directory: + root = Path(directory) + shutil.copyfile(local.SOURCE / "scripts/install-local.sh", root / "install-local.sh") + (root / "install-system-deps.sh").write_text("exit 17\n") + record = root / "environment.json" + for option in (["--root", directory], [f"--root={directory}"]): + record.write_text("{}") + run = subprocess.run(["bash", str(root / "install-local.sh"), "--system-deps", *option]) + self.assertEqual(run.returncode, 17) + self.assertFalse(record.exists()) + + def test_changed_mpi_launcher_rejected(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + exe = root / "install/bin/gemini.bin" + exe.parent.mkdir(parents=True) + exe.write_text("fixture") + old, new = root / "old-mpi", root / "new-mpi" + old.write_text("OpenMPI") + new.write_text("MPICH") + (root / "environment.json").write_text(json.dumps({ + "schema": "gemini.local-environment.1", "build_type": "Release", + "requirements_sha256": local.digest(local.REQUIREMENTS), + "executable_sha256": local.digest(exe), "mpi_launcher": str(old), + "native_configuration": {}, "model_resources_sha256": {}, + })) + with patch.object(local.shutil, "which", return_value=str(new)), \ + patch.object(local, "execute") as run: + with self.assertRaisesRegex(RuntimeError, "MPI launcher changed"): + local.check(root) + run.assert_not_called() + + def test_changed_executable_rejected_before_running(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + exe = root / "install/bin/gemini.bin" + exe.parent.mkdir(parents=True) + exe.write_text("different binary") + (root / "environment.json").write_text(json.dumps({ + "schema": "gemini.local-environment.1", "build_type": "Release", + "requirements_sha256": local.digest(local.REQUIREMENTS), + "executable_sha256": "0" * 64, + })) + with patch.object(local, "execute") as run: + with self.assertRaisesRegex(RuntimeError, "changed since verification"): + local.check(root) + run.assert_not_called() + + def test_success_checks_before_publication(self): + self.check_successful_install(reference_tests=False) + + def test_successful_reference_install_records_complete_execution(self): + self.check_successful_install(reference_tests=True) + + def check_successful_install(self, reference_tests): + with tempfile.TemporaryDirectory(prefix="gemini install ") as directory: + root = Path(directory) + (root / "venv").mkdir() + (root / "venv/pyvenv.cfg").write_text("fixture") + (root / "build").mkdir() + launcher = root / "mpiexec" + launcher.write_text("fixture") + (root / "build/CMakeCache.txt").write_text( + f"gemini3d_realbits:STRING=64\nMPIEXEC_EXECUTABLE:FILEPATH={launcher}\n" + "MPIEXEC_NUMPROC_FLAG:STRING=-n\ngemini3d_msis2:BOOL=ON\n") + source_cache = root / "sources.cmake" + source_cache.write_text("# hash-verified offline source locations\n") + exe = root / "install/bin/gemini.bin" + exe.parent.mkdir(parents=True) + exe.write_text("fixture") + resource = exe.parent / "msis21.parm" + resource.write_text("model parameter fixture") + commands = [] + libraries = sorted(local.LIBRARY_TESTS) + all_tests = sorted(local.LIBRARY_TESTS | local.REFERENCE_TESTS | {"audit:example"}) + + def execute(command, **kwargs): + commands.append([str(item) for item in command]) + self.assertFalse((root / "environment.json").exists()) + names = libraries if "-R" in command else ["audit:example"] if "-L" in command else all_tests + if "--show-only=json-v1" in command: + return json.dumps({"tests": [{"name": name} for name in names]}) + if "--output-junit" in command: + report = command[command.index("--output-junit") + 1] + report.write_text("" + "".join( + f'' for name in names) + "") + return subprocess.CompletedProcess(command, 0) + if "--format=json" in command: + return "[]" + + with patch.object(local, "native_prerequisites"), patch.object(local, "python_check"), \ + patch.object(local, "execute", side_effect=execute), \ + patch.object(local, "source_identity", return_value={}), \ + patch.object(local, "source_inventory", return_value={}): + local.main(["install", "--root", directory, "--jobs", "2", + "--source-cache", str(source_cache)] + + (["--reference-tests"] if reference_tests else [])) + saved = json.loads((root / "environment.json").read_text()) + self.assertEqual(saved["tests"], all_tests) + if reference_tests: + self.assertEqual(saved["verification"], "enabled-registered-tests") + self.assertEqual(saved["test_results"]["reference"]["passed"], all_tests) + self.assertEqual(set(saved["test_results"]), {"reference"}) + else: + self.assertEqual(saved["verification"], "unit-tests-only") + self.assertEqual(saved["test_results"]["libraries"]["passed"], libraries) + self.assertEqual(saved["test_results"]["unit"]["passed"], ["audit:example"]) + self.assertTrue(any("-R" in c and "HDF5_standalone" in c[c.index("-R") + 1] for c in commands)) + for result in saved["test_results"].values(): + self.assertEqual(result["junit_sha256"], local.digest(root / "build" / result["junit"])) + self.assertEqual(saved["model_resources_sha256"], {"msis21.parm": local.digest(resource)}) + self.assertTrue(any("-Dgemini3d_require_qualification=ON" in c for c in commands)) + self.assertTrue(any("-C" in c and str(source_cache.resolve()) in c for c in commands)) + test_indices = [i for i, c in enumerate(commands) if "--no-tests=error" in c] + install_index = next(i for i, c in enumerate(commands) if "--install" in c) + self.assertEqual(len(test_indices), 1 if reference_tests else 2) + self.assertTrue(all(index < install_index for index in test_indices)) + resource.write_text("changed model parameters") + with patch.object(local, "execute") as run: + with self.assertRaisesRegex(RuntimeError, "model resources changed"): + local.check(root) + run.assert_not_called() + + def test_reference_install_requires_all_nine_comparisons_before_publication(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + (root / "venv").mkdir() + (root / "venv/pyvenv.cfg").write_text("fixture") + names = sorted(local.LIBRARY_TESTS | local.REFERENCE_TESTS) + self.assertEqual(len(local.REFERENCE_TESTS), 9) + for disabled in (False, True): + tests = [{"name": name} for name in names] + if disabled: + tests[-1]["properties"] = [{"name": "DISABLED", "value": True}] + else: + tests.pop() + def execute(command, **kwargs): + self.assertNotIn("--install", command) + self.assertNotIn("--output-junit", command) + if "--show-only=json-v1" in command: + return json.dumps({"tests": tests}) + with self.subTest(disabled=disabled), patch.object(local, "native_prerequisites"), \ + patch.object(local, "python_check"), patch.object(local, "execute", side_effect=execute): + with self.assertRaises(SystemExit): + local.main(["install", "--root", directory, "--reference-tests"]) + self.assertFalse((root / "environment.json").exists()) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/qualification/test_midpoint_diffusion.py b/test/qualification/test_midpoint_diffusion.py new file mode 100644 index 000000000..c2553d187 --- /dev/null +++ b/test/qualification/test_midpoint_diffusion.py @@ -0,0 +1,35 @@ +"""Run native operator, verify observed stages, then compare independent laws.""" +import argparse +import json +from pathlib import Path +import subprocess +import sys +import tempfile + +p=argparse.ArgumentParser() +p.add_argument('--source',type=Path,required=True) +p.add_argument('--build',type=Path,required=True) +p.add_argument('--work',type=Path,required=True) +a=p.parse_args() +# Keep each invocation isolated, including concurrent or repeated CTest calls. +# No existing evidence or user directory is removed. +a.work.mkdir(parents=True,exist_ok=True) +invocation=Path(tempfile.mkdtemp(prefix='run-',dir=a.work)) +native=invocation/'native';trace=invocation/'trace' +scripts=a.source/'scripts/qualification' +subprocess.run([sys.executable,str(scripts/'run_physics_native.py'),'--build',str(a.build), + '--source',str(a.source/'test/qualification/midpoint_diffusion_probe.f90'),'--work',str(native)],check=True) +subprocess.run([sys.executable,str(scripts/'trace_diffusion_stages.py'), + '--source',str(a.source/'src/numerical/diffusion/PDEparabolic.f90'), + '--build',str(a.build),'--probe',str(native/'physics_native.o'),'--work',str(trace)],check=True) +try: + revision=subprocess.check_output(['git','-C',str(a.source),'rev-parse','HEAD'],text=True).strip() +except subprocess.CalledProcessError: + revision='source-export; see PACKAGE_PROVENANCE.json' +subprocess.run([sys.executable,str(a.source/'test/qualification/analyze_midpoint_diffusion.py'), + '--work',str(native),'--trace',str(trace/'tr-stages.csv'),'--candidate',revision],check=True) +result=json.loads((native/'physics-results.json').read_text()) +a.work.joinpath('latest-result.json').write_text(json.dumps({'invocation':str(invocation), + 'result':result},indent=2)+'\n') +assert result['passed'] and all(r['native_stage_trace_used'] and r['fixed_boundary_max_error_K']<=1e-11 + and r['floor_cell_events']==0 for r in result['PC03']['cases']) diff --git a/test/qualification/test_mode_guard.py b/test/qualification/test_mode_guard.py new file mode 100644 index 000000000..623e1b158 --- /dev/null +++ b/test/qualification/test_mode_guard.py @@ -0,0 +1,14 @@ +"""Unsupported executables must reject exact-restart qualification before work.""" +import argparse +import json +import os +import subprocess + +p=argparse.ArgumentParser();p.add_argument('--alternate',required=True);p.add_argument('--density',required=True);a=p.parse_args() +results=[] +for exe,model in [(a.alternate,'alternate energy'),(a.density,'density and potential only')]: + proc=subprocess.run([exe],env=dict(os.environ,GEMINI_EXACT_RESTART='1'),text=True,capture_output=True,timeout=20) + passed=proc.returncode!=0 and ('Exact restart research profile excludes model: '+model) in proc.stdout+proc.stderr + results.append(dict(model=model,returncode=proc.returncode,passed=passed)) +print(json.dumps(results)) +raise SystemExit(0 if all(r['passed'] for r in results) else 1) diff --git a/test/qualification/test_pair_exchange.py b/test/qualification/test_pair_exchange.py new file mode 100644 index 000000000..244caf5dd --- /dev/null +++ b/test/qualification/test_pair_exchange.py @@ -0,0 +1,63 @@ +"""Independent coupled ODE oracle; acceptance does not validate rate amplitudes.""" +import argparse +import csv +import hashlib +import json +import subprocess +from pathlib import Path + +import numpy as np +from scipy.integrate import solve_ivp + +p = argparse.ArgumentParser() +p.add_argument('--exe', type=Path, required=True) +p.add_argument('--output', type=Path, required=True) +a = p.parse_args() +a.output.parent.mkdir(parents=True, exist_ok=True) +csv_path = a.output.with_suffix('.csv') +subprocess.run([str(a.exe), str(csv_path)], check=True) +with csv_path.open() as f: + rows = [{k: float(v) for k, v in row.items()} for row in csv.DictReader(f)] +assert len(rows) == 381 and all(np.isfinite(list(r.values())).all() for r in rows) +results = [] +for r in rows: + ca, cb, ra, rb, drag, k, dt, fraction = (r[x] for x in + ('Ca', 'Cb', 'rhoa', 'rhob', 'drag', 'K', 'dt', 'fraction_a')) + initial = np.array([r[x] for x in ('va0x','va0y','va0z','vb0x','vb0y','vb0z','Ta0','Tb0')]) + observed = np.array([r[x] for x in ('vax','vay','vaz','vbx','vby','vbz','Ta','Tb')]) + def rhs(t, y): + force = drag*(y[3:6]-y[:3]) + heat = drag*np.dot(y[:3]-y[3:6], y[:3]-y[3:6]) + transfer = k*(y[7]-y[6]) + return dt*np.r_[force/ra, -force/rb, + (transfer+fraction*heat)/ca, (-transfer+(1-fraction)*heat)/cb] + if dt: + oracle = solve_ivp(rhs, (0.,1.), initial, method='Radau', rtol=2e-12, atol=2e-11) + control = solve_ivp(rhs, (0.,1.), initial, method='Radau', rtol=2e-13, atol=2e-12) + assert oracle.success and control.success + expected = control.y[:,-1] + control_error = np.max(abs(oracle.y[:,-1]-expected)/np.maximum(abs(expected), 1.)) + else: + expected=initial;control_error=0. + # The native probe checks U and v bitwise at dt=0. CSV temperatures + # include a rounded U/Cv conversion even when the operator is a no-op. + error = np.max(abs(observed-expected)/np.maximum(abs(expected),1.)) + e0=ca*initial[6]+cb*initial[7]+ra*np.dot(initial[:3],initial[:3])/2+rb*np.dot(initial[3:6],initial[3:6])/2 + e1=ca*observed[6]+cb*observed[7]+ra*np.dot(observed[:3],observed[:3])/2+rb*np.dot(observed[3:6],observed[3:6])/2 + energy=abs(e1-e0)/abs(e0) + momentum=np.max(abs(ra*(observed[:3]-initial[:3])+rb*(observed[3:6]-initial[3:6])))/max( + ra*np.linalg.norm(initial[:3])+rb*np.linalg.norm(initial[3:6]),np.finfo(float).tiny) + identity=max(r[x] for x in ('instantaneous_momentum','instantaneous_energy','instantaneous_thermal')) + passed=error<=1e-10 and control_error<=1e-10 and energy<=1e-11 and momentum<=1e-11 and identity<=1e-11 + results.append({'species':[int(r['a']),int(r['b'])], 'level':int(r['level']), + 'oracle_relative_error':float(error), 'oracle_control_error':float(control_error), + 'energy_relative_error':float(energy), 'momentum_relative_error':float(momentum), + 'instantaneous_identity_error':float(identity), 'passed':bool(passed)}) +result={'schema':'gemini.pair.exchange.validation.1', 'scope':'closed constant-rate pair operator; application source coupling unexecuted', + 'rate_magnitudes_independently_validated':False, 'case_count':len(results), + 'passed':all(r['passed'] for r in results), 'cases':results, + 'executable_sha256':hashlib.sha256(a.exe.read_bytes()).hexdigest(), + 'csv_sha256':hashlib.sha256(csv_path.read_bytes()).hexdigest()} +a.output.write_text(json.dumps(result,indent=2)+'\n') +print(json.dumps({k:v for k,v in result.items() if k!='cases'})) +raise SystemExit(0 if result['passed'] else 1) diff --git a/test/qualification/test_profile.py b/test/qualification/test_profile.py new file mode 100644 index 000000000..1e79edd23 --- /dev/null +++ b/test/qualification/test_profile.py @@ -0,0 +1,139 @@ +import csv +import importlib.util +from pathlib import Path +import sys +import tempfile +import unittest +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from run_research import input_signature +from check_transport import check,check_continuity +from research_matrix import compare,restart_advanced,set_duration +import h5py +import numpy as np + +class Profile(unittest.TestCase): + def test_duration_rewrite_handles_indented_assignment_and_preserves_inputs(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);(p/'inputs').mkdir();cfg=p/'inputs/config.nml' + for assignment in ['tdur = 300',' tdur = 300','\tTDUR\t= 3e2,', + ' tdur = 3D2','\ttdur = 3d2,']: + with self.subTest(assignment=assignment): + original='&base\n! tdur = 900\n'+assignment+' ! duration\ntcfl = .5\n/\n' + cfg.write_text(original) + signature=input_signature(p)['sha256'] + set_duration(p,120) + self.assertIn('= 120 ! duration\n',cfg.read_text()) + self.assertEqual(input_signature(p)['sha256'],signature) + set_duration(p,300,extend=True) + self.assertIn('= 300 ! duration\n',cfg.read_text()) + self.assertEqual(input_signature(p)['sha256'],signature) + self.assertIn('! tdur = 900\n',cfg.read_text()) + self.assertIn('tcfl = .5\n',cfg.read_text()) + + def test_duration_rewrite_rejects_missing_duplicate_and_malformed_values(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);(p/'inputs').mkdir();cfg=p/'inputs/config.nml' + invalid=['! tdur = 300','tdur: 300','tdur = 300\n TDUR = 120', + 'tdur =','tdur = nope','tdur = 300, tcfl = .5', + 'tdur = 300,,','tdur = -1','tdur = 0','tdur = nan','tdur = inf'] + for assignment in invalid: + with self.subTest(assignment=assignment): + text='&base\n'+assignment+'\n/\n';cfg.write_text(text) + with self.assertRaisesRegex(ValueError,'tdur'):set_duration(p,120) + self.assertEqual(cfg.read_text(),text) + text='&base\n tdur = 120\n/\n' + for duration in [0,-1,float('nan'),float('inf'),'invalid',None]: + with self.subTest(duration=duration): + cfg.write_text(text) + with self.assertRaisesRegex(ValueError,'tdur'):set_duration(p,duration) + self.assertEqual(cfg.read_text(),text) + for duration in [60,120]: + with self.subTest(continuation=duration): + cfg.write_text(text) + with self.assertRaisesRegex(ValueError,'extend'):set_duration(p,duration,extend=True) + self.assertEqual(cfg.read_text(),text) + + def test_restart_requires_preserved_seed_and_a_later_checkpoint(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);first='20130220_00120.000000.h5';last='20130220_00300.000000.h5' + self.assertFalse(restart_advanced(p,set())) + (p/first).touch() + self.assertFalse(restart_advanced(p,set())) + previous={first} + self.assertFalse(restart_advanced(p,previous)) + (p/'20130220_00060.000000.h5').touch() + self.assertFalse(restart_advanced(p,previous)) + (p/last).touch() + self.assertTrue(restart_advanced(p,previous)) + (p/first).unlink() + self.assertFalse(restart_advanced(p,previous)) + + def test_trajectory_requires_all_frames_and_compatible_shapes(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);a=p/'continuous';b=p/'split';a.mkdir();b.mkdir() + budget=dict(absolute_floor=dict(ns=1e-2,Ts=1e-7,vs1=1e-7,Phi=1e-8),trajectory_relative_l2=1e-10) + def frame(path): + with h5py.File(path,'w') as f: + for key in ['ns','Ts','vs1']:f['restart_core/'+key]=np.ones((7,2,2,2)) + f['restart_core/Phi']=np.ones((2,2,2)) + for name in ['20130220_00060.000000.h5','20130220_00120.000000.h5']: + frame(a/name);frame(b/name) + self.assertTrue(compare(a,b,budget)['passed']) + self.assertFalse(restart_advanced(b,{p.name for p in b.glob('*.h5')})) + last=b/'20130220_00120.000000.h5';last.unlink() + self.assertFalse(compare(a,b,budget)['passed']) + frame(last) + with h5py.File(last,'r+') as f: + del f['restart_core/Phi'];f['restart_core/Phi']=np.ones((1,2,2)) + self.assertFalse(compare(a,b,budget)['passed']) + + def test_only_duration_can_change(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);(p/'inputs').mkdir();cfg=p/'inputs/config.nml' + cfg.write_text('&base\ntdur = 120 ! duration\ntcfl = .5\n/\n') + original=input_signature(p)['sha256'] + cfg.write_text('&base\ntdur = 300 ! duration\ntcfl = .5\n/\n') + self.assertEqual(input_signature(p)['sha256'],original) + cfg.write_text('&base\ntdur = 300 ! duration\ntcfl = .9\n/\n') + self.assertNotEqual(input_signature(p)['sha256'],original) + (p/'inputs/linked').symlink_to('/dev/null') + with self.assertRaisesRegex(ValueError,'symlinks'):input_signature(p) + def test_budget_checks_reject_bad_evidence(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);f=p/'transport-r00000000.csv' + fields=['t','dt','quantity','species','axis','before','after','delta','outward','min_face','max_face','scale','residual','normalized_residual'] + rows=[] + for q in [1,2,3]: + for species in range(1,8 if q==3 else 7): + for axis in [1,2,3]: + rows.append(dict(zip(fields,[0,1,q,species,axis,1,1,0,0,0,0,1,0,0]))) + def write(): + with f.open('w') as h: + w=csv.DictWriter(h,fieldnames=fields);w.writeheader();w.writerows(rows) + (p/'continuity-r00000000.csv').write_text('t,dt\n'+ + ''.join(f'{t},{dt}\n' for t,dt in sorted({(r['t'],r['dt']) for r in rows}))) + write();self.assertTrue(check(p,layout=[1,1])['passed']) + # A complete first step must not hide a missing stage in a later step. + complete=[dict(r) for r in rows] + rows.extend(dict(r,t=1) for r in complete[:-1]);write() + self.assertFalse(check(p)['passed']) + rows[:]=complete + rows[0]['delta']=.001;write();self.assertFalse(check(p)['passed']) + rows.pop();write();self.assertFalse(check(p)['passed']) + rows[0]['delta']=float('nan');write() + with self.assertRaisesRegex(ValueError,'Nonfinite'):check(p) + def test_continuity_does_not_hide_cleanup(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);f=p/'continuity-r00000000.csv' + fields=['t','dt','species','before','after','source','outward','cleanup','residual','scale','normalized_residual','charge_fraction'] + rows=[dict(zip(fields,[0,1,s,100,102,1,0,1,0,102,0,0])) for s in range(1,7)] + def write(): + with f.open('w') as h: + w=csv.DictWriter(h,fieldnames=fields);w.writeheader();w.writerows(rows) + write();self.assertTrue(check_continuity(p)['passed']) + complete=[dict(r) for r in rows] + rows.extend(dict(r,t=1) for r in complete[:-1]);write() + self.assertFalse(check_continuity(p)['passed']) + rows[:]=complete + rows[0]['cleanup']=0;write();self.assertFalse(check_continuity(p)['passed']) +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_qualification_dependencies.py b/test/qualification/test_qualification_dependencies.py new file mode 100644 index 000000000..b356b6ce1 --- /dev/null +++ b/test/qualification/test_qualification_dependencies.py @@ -0,0 +1,134 @@ +"""Exercise optional/required discovery and stale-cache handling without native downloads.""" +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[2] + + +def find_cmake(): + for candidate in (os.environ.get("CMAKE"), shutil.which("cmake"), "cmake"): + if not candidate: + continue + resolved = shutil.which(candidate) or candidate + if resolved == "cmake" or Path(resolved).is_file(): + return resolved + return "cmake" + + +class QualificationDependencies(unittest.TestCase): + def setUp(self): + self.work = tempfile.TemporaryDirectory() + self.addCleanup(self.work.cleanup) + self.root = Path(self.work.name) + self.source = self.root / "source" + self.source.mkdir() + (self.source / "cmake").mkdir() + shutil.copy2(ROOT / "cmake/cpu_count.cmake", self.source / "cmake/cpu_count.cmake") + (self.source / "CMakeLists.txt").write_text( + "cmake_minimum_required(VERSION 3.25)\n" + "project(qualification_dependency_probe LANGUAGES NONE)\n" + "set(gemini3d_IS_TOP_LEVEL TRUE)\n" + 'set(BUILD_TESTING ON CACHE BOOL "Test gate")\n' + f'include("{ROOT.as_posix()}/options.cmake")\n' + f'include("{ROOT.as_posix()}/cmake/python.cmake")\n' + 'file(WRITE "${CMAKE_BINARY_DIR}/found.txt" ' + '"${Python_Interpreter_FOUND};${NUMPY_FOUND};${H5PY_FOUND};${SCIPY_FOUND}")\n' + ) + # Deterministic import probes work even on an optional, stdlib-only host. + self.modules = self.root / "modules" + self.modules.mkdir() + for module in ("numpy", "h5py", "scipy"): + (self.modules / (module + ".py")).write_text("__version__ = 'test-fixture'\n") + self.env = dict(os.environ, PYTHONPATH=str(self.modules)) + cmake = os.environ.get("CMAKE") + if cmake and Path(cmake).is_file(): + self.env["PATH"] = str(Path(cmake).parent) + os.pathsep + self.env.get("PATH", "") + + def configure(self, *args): + return subprocess.run( + [find_cmake(), "-S", str(self.source), "-B", str(self.root / "build"), + f"-DPython_EXECUTABLE={sys.executable}", *args], + env=self.env, capture_output=True, text=True, timeout=60 + ) + + def found(self): + return (self.root / "build/found.txt").read_text().split(";") + + def test_successful_required_configuration(self): + result = self.configure("-Dgemini3d_require_qualification=ON") + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertTrue(all(value.upper() == "TRUE" for value in self.found())) + + def test_each_failed_import_refreshes_cache_and_fails_required_mode(self): + for module in ("numpy", "h5py", "scipy"): + with self.subTest(module=module): + path = self.modules / (module + ".py") + result = self.configure("-Dgemini3d_require_qualification=OFF", + "-DPYGEMINI_FOUND=TRUE") + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertTrue(all(value.upper() == "TRUE" for value in self.found())) + path.write_text("raise ImportError('missing qualification dependency fixture')\n") + result = self.configure() + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(self.found()[("numpy", "h5py", "scipy").index(module) + 1], "FALSE") + result = self.configure("-Dgemini3d_require_qualification=ON") + self.assertNotEqual(result.returncode, 0) + self.assertIn("Required qualification dependencies unavailable", result.stderr) + self.assertIn(module, result.stderr) + path.write_text("__version__ = 'test-fixture-restored'\n") + + def test_missing_interpreter_clears_cached_imports(self): + self.assertEqual(self.configure().returncode, 0) + missing = f"-DPython_EXECUTABLE={self.root / 'missing-python'}" + result = self.configure(missing) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(self.found()[1:], ["FALSE"] * 3) + result = self.configure(missing, "-Dgemini3d_require_qualification=ON") + self.assertNotEqual(result.returncode, 0) + self.assertIn("Python >= 3.11", result.stderr) + + @unittest.skipIf(os.name == "nt", "POSIX fake interpreter launcher") + def test_python_before_file_digest_is_not_accepted(self): + executable = self.root / "old-python" + executable.write_text( + f"#!{sys.executable}\n" + "import os,sys\n" + "if len(sys.argv)>2 and sys.argv[1]=='-c' and 'version_info' in sys.argv[2]:\n" + " sys.version_info = (3,10,99,'final',0)\n" + " exec(sys.argv[2])\n" + "else:\n" + f" os.execv({sys.executable!r},[{sys.executable!r},*sys.argv[1:]])\n" + ) + executable.chmod(0o755) + old = f"-DPython_EXECUTABLE={executable}" + result = self.configure(old) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(self.found()[1:], ["FALSE"] * 3) + result = self.configure(old, "-Dgemini3d_require_qualification=ON") + self.assertNotEqual(result.returncode, 0) + self.assertIn("Python >= 3.11", result.stderr) + + def test_required_qualification_cannot_disable_tests(self): + for flag in ("BUILD_TESTING", "gemini3d_BUILD_TESTING"): + with self.subTest(flag=flag): + result = self.configure("-Dgemini3d_require_qualification=ON", + "-DBUILD_TESTING=ON", "-Dgemini3d_BUILD_TESTING=ON", f"-D{flag}=OFF") + self.assertNotEqual(result.returncode, 0) + self.assertIn("requires BUILD_TESTING=ON", result.stderr) + + def test_unusable_cmake_environment_falls_back_to_path(self): + cmake = os.environ.get("CMAKE") + self.addCleanup(lambda: os.environ.pop("CMAKE", None) if cmake is None else os.environ.__setitem__("CMAKE", cmake)) + os.environ["CMAKE"] = "D:/not-valid-under-wsl/cmake.exe" + result = self.configure("-Dgemini3d_require_qualification=ON") + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertTrue(all(value.upper() == "TRUE" for value in self.found())) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/qualification/test_restart_runtime.py b/test/qualification/test_restart_runtime.py new file mode 100644 index 000000000..0e1d60650 --- /dev/null +++ b/test/qualification/test_restart_runtime.py @@ -0,0 +1,153 @@ +"""Native synthetic checkpoint identity/finite-state tests, not a science run.""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys + +import h5py +import numpy as np + +from research_matrix import checkpoint_shapes + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--exe', type=Path, required=True) + parser.add_argument('--mpiexec', required=True) + parser.add_argument('--numproc-flag', default='-n') + parser.add_argument('--mpi-pref', action='append', default=[]) + parser.add_argument('--mpi-post', action='append', default=[]) + parser.add_argument('--layout', choices=('1x2', '2x2'), required=True) + parser.add_argument('--work', type=Path, required=True) + args = parser.parse_args() + layout = tuple(map(int, args.layout.split('x'))) + ranks = int(np.prod(layout)) + work = args.work.resolve() + work.mkdir(parents=True, exist_ok=True) + rejected_work = work / 'invalid-matrix-options' + invalid = subprocess.run( + [sys.executable, str(Path(__file__).with_name('research_matrix.py')), + '--build', str(args.exe.parent), '--inputs-root', str(work / 'absent-inputs'), + '--work', str(rejected_work), '--quick', '--extended-layouts'], + text=True, capture_output=True, timeout=30) + assert invalid.returncode == 2 and '--extended-layouts requires the full matrix' in invalid.stderr + assert not rejected_work.exists() + env = dict(os.environ, GEMINI_EXACT_RESTART='1', GEMINI_INPUT_SHA256='1' * 64, + GEMINI_EXECUTABLE_SHA256=hashlib.sha256(args.exe.read_bytes()).hexdigest()) + rows = [] + + def run(mode, case, expected=None): + proc = subprocess.run( + [args.mpiexec, args.numproc_flag, str(ranks), *args.mpi_pref, + str(args.exe.resolve()), *args.mpi_post, mode, str(case), + *map(str, layout)], env=env, text=True, capture_output=True, timeout=30) + output = proc.stdout + proc.stderr + (work / f'{case.name}-{mode}.log').write_text(output) + passed = proc.returncode == 0 if expected is None else proc.returncode != 0 and expected in output + rows.append(dict(case=case.name, mode=mode, passed=passed, + expected_rejection=expected, returncode=proc.returncode)) + if not passed: + raise AssertionError(f'{case.name} {mode}: expected {expected!r}\n{output}') + + def fresh(name, source=None): + path = work / name + if path.exists(): + shutil.rmtree(path) + if source is None: + path.mkdir() + else: + shutil.copytree(source, path) + return path + + def frame(case): + return next(case.glob('????????_?????.??????.h5')) + + def sidecar(case, rank=0): + with h5py.File(frame(case)) as f: + prefix = f['restart_runtime/prefix'][()].decode().strip() + return case / f'{prefix}.r{rank:08d}.h5' + + seed = fresh('seed') + run('write', seed) + run('read', seed) + assert checkpoint_shapes(seed, ranks, layout) + copied = fresh('copied', seed) + run('read', copied) + with h5py.File(frame(seed)) as root: + prefix = root['restart_runtime/prefix'][()].decode().strip() + assert root['restart_runtime/schema'][()] == 2 + assert root['restart_runtime/checkpoint'][()].decode().strip() == frame(seed).name + for rank in range(ranks): + with h5py.File(sidecar(seed, rank)) as state: + assert state['schema'][()] == 2 + assert state['rank'][()] == rank + assert tuple(state['layout'][...]) == layout + assert state['generation'][()].decode().strip() == prefix + assert state['checkpoint'][()] == root['restart_runtime/checkpoint'][()] + assert state['input_sha256'][()] == root['restart_runtime/input_sha256'][()] + assert state['executable_sha256'][()] == root['restart_runtime/executable_sha256'][()] + + bad = fresh('swap_rank', seed) + first, second = sidecar(bad), sidecar(bad, ranks - 1) + first_bytes, second_bytes = first.read_bytes(), second.read_bytes() + first.write_bytes(second_bytes) + second.write_bytes(first_bytes) + run('read', bad, 'Runtime state rank mismatch') + + # Same root timestamp, same rank, same inputs/executable, different publication. + other = fresh('other_generation') + run('write', other) + bad = fresh('mismatched_generation', seed) + shutil.copyfile(sidecar(other), sidecar(bad)) + run('read', bad, 'Runtime state generation mismatch') + + mutations = [ + ('root_schema', 'restart_runtime/schema', 1, 'Unsupported runtime checkpoint schema', True), + ('root_identity', 'restart_runtime/checkpoint', b'other.h5', 'root identity mismatch', True), + ('root_layout', 'restart_runtime/layout', [2, 1], 'Incompatible runtime checkpoint layout', True), + ('root_executable', 'restart_runtime/executable_sha256', b'0' * 64, 'Changed restart executable', True), + ('state_schema', 'schema', 1, 'Unsupported runtime state schema', False), + ('state_root', 'checkpoint', b'other.h5', 'Runtime state root identity mismatch', False), + ('state_layout', 'layout', [2, 1], 'Runtime state layout mismatch', False), + ('state_executable', 'executable_sha256', b'0' * 64, 'Changed restart executable', False), + ('state_input', 'input_sha256', b'0' * 64, 'Changed restart inputs', False), + ('incomplete', 'complete', 0, 'Incomplete runtime checkpoint', False), + ('clock', 'dt', np.nan, 'Invalid runtime checkpoint clock', False), + ] + for name, key, value, expected, root in mutations: + bad = fresh(name, seed) + with h5py.File(frame(bad) if root else sidecar(bad, ranks - 1), 'r+') as f: + f[key][...] = value + run('read', bad, expected) + + bad = fresh('missing_state', seed) + sidecar(bad, ranks - 1).unlink() + run('read', bad, 'Missing runtime state file') + bad = fresh('bad_dtype', seed) + with h5py.File(sidecar(bad, ranks - 1), 'r+') as f: + values = f['fluid'][...].astype('float32') + del f['fluid'] + f['fluid'] = values + run('read', bad, 'requires float64 rank-four state') + for field in ('fluid', 'electro', 'vi1', 'vi2', 'vi3'): + for label, value in (('nan', np.nan), ('inf', np.inf), ('neginf', -np.inf)): + bad = fresh(f'{field}_{label}', seed) + with h5py.File(sidecar(bad, ranks - 1), 'r+') as f: + f[field][tuple(n - 1 for n in f[field].shape)] = value + assert not checkpoint_shapes(bad, ranks, layout) + run('read', bad, f'Nonfinite runtime checkpoint payload: {field}') + bad = fresh('save_nonfinite', seed) + original = frame(bad).read_bytes() + run('write_nan', bad, 'Nonfinite runtime checkpoint payload: vi3') + assert frame(bad).read_bytes() == original + run('read', bad) + (work / 'results.json').write_text(json.dumps(dict(layout=layout, ranks=ranks, runs=rows), indent=2) + '\n') + print(f'{len(rows)} native checkpoint checks passed on {args.layout}; synthetic state only.') + + +if __name__ == '__main__': + main() diff --git a/test/qualification/test_source_ledger.py b/test/qualification/test_source_ledger.py new file mode 100644 index 000000000..9804c7754 --- /dev/null +++ b/test/qualification/test_source_ledger.py @@ -0,0 +1,69 @@ +import csv +from pathlib import Path +import sys +import tempfile +import unittest +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from check_sources import check,EXPECTED + + +class Sources(unittest.TestCase): + def write(self,p): + cols='t,dt,quantity,species,before,after,delta,production,external_production,integrated_loss,residual,scale'.split(',') + data=[dict(zip(cols,[t,1,q,s,100,105,5,10,2,5,0,105])) for t in (0,1) for q,s in sorted(EXPECTED)] + with (p/'sources-r00000000.csv').open('w') as f: + w=csv.DictWriter(f,cols);w.writeheader();w.writerows(data) + (p/'continuity-r00000000.csv').write_text('t,dt\n0,1\n1,1\n') + (p/'temperature-floor-r00000000.csv').write_text('t,dt,stage,species,energy_added_J\n'+ + ''.join(f'{t},1,{stage},{s},0\n' for t in (0,1) for stage in (1,2,3) for s in range(1,8))) + return p/'sources-r00000000.csv' + + def test_known_balance_corruption_and_per_step_coverage(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);path=self.write(p) + self.assertTrue(check(p,1)['passed']) + text=path.read_text();path.write_text(text.replace(',105,5,10,',',105,7,10,',1)) + self.assertFalse(check(p,1)['passed']) + path.write_text('\n'.join(text.splitlines()[:-1])+'\n') + with self.assertRaisesRegex(ValueError,'Missing'):check(p,1) + path.write_text(text+text.splitlines()[1]+'\n') + with self.assertRaisesRegex(ValueError,'Duplicate'):check(p,1) + + def test_missing_rank_nan_floor_and_clock(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);path=self.write(p) + with self.assertRaisesRegex(ValueError,'inventory'):check(p,2) + path.write_text(path.read_text().replace(',105,5,',',nan,5,',1)) + with self.assertRaisesRegex(ValueError,'Nonfinite'):check(p,1) + self.write(p);floor=p/'temperature-floor-r00000000.csv';floor.write_text('t,dt,stage,species,energy_added_J\n') + with self.assertRaisesRegex(ValueError,'Missing'):check(p,1) + + def test_four_rank_regression_preserves_all_ledger_checks(self): + with tempfile.TemporaryDirectory() as d: + p=Path(d);self.write(p) + for rank in range(1,4): + for stem in ('sources','continuity','temperature-floor'): + (p/f'{stem}-r{rank:08d}.csv').write_bytes((p/f'{stem}-r00000000.csv').read_bytes()) + result=check(p,4) + self.assertTrue(result['passed']) + self.assertEqual(result['rows'],2*4*len(EXPECTED)) + self.assertEqual(result['temperature_floor_rows'],2*4*3*7) + last=p/'sources-r00000003.csv';original=last.read_text() + last.write_text(original.replace(',105,5,10,',',105,7,10,',1)) + self.assertFalse(check(p,4)['passed']) + last.write_text(original) + continuity=p/'continuity-r00000003.csv' + continuity.write_text('t,dt\n0,1\n') + with self.assertRaisesRegex(ValueError,'Source/continuity'):check(p,4) + continuity.write_bytes((p/'continuity-r00000000.csv').read_bytes()) + floor=p/'temperature-floor-r00000003.csv';floor_text=floor.read_text() + floor.write_text('\n'.join(floor_text.splitlines()[:-1])+'\n') + with self.assertRaisesRegex(ValueError,'Missing'):check(p,4) + floor.write_text(floor_text);last.unlink() + with self.assertRaisesRegex(ValueError,'inventory'):check(p,4) + last.write_text(original) + (p/'sources-r00000004.csv').write_text(original) + with self.assertRaisesRegex(ValueError,'inventory'):check(p,4) + + +if __name__=='__main__':unittest.main() diff --git a/test/qualification/test_temperature_floor.py b/test/qualification/test_temperature_floor.py new file mode 100644 index 000000000..2d5d80f24 --- /dev/null +++ b/test/qualification/test_temperature_floor.py @@ -0,0 +1,22 @@ +"""Measure the conversion floor against known physical volume and heat capacity.""" +import argparse,csv,os +from pathlib import Path +import subprocess,tempfile + +p=argparse.ArgumentParser();p.add_argument('--exe',type=Path,required=True);a=p.parse_args() +with tempfile.TemporaryDirectory() as d: + p=Path(d);audited=p/'audited';plain=p/'plain';audited.mkdir();plain.mkdir() + outputs=[] + for directory,flag in [(audited,'1'),(plain,'0')]: + run=subprocess.run([str(a.exe),str(directory)],env=dict(os.environ,GEMINI_NUMERICAL_AUDIT=flag),capture_output=True,text=True) + assert run.returncode==0,run.stdout+run.stderr + outputs.append(run.stdout) + assert outputs[0]==outputs[1],'Diagnostics changed native oracle output' + assert (audited/'temperature.bin').read_bytes()==(plain/'temperature.bin').read_bytes(),'Diagnostics changed native state' + expected={int(line.split()[0]):float(line.split()[1]) for line in outputs[0].splitlines()} + with (audited/'temperature-floor-r00000000.csv').open() as f:rows=list(csv.DictReader(f)) + assert len(rows)==7 and {int(r['stage']) for r in rows}=={3},rows + reported={int(r['species']):float(r['energy_added_J']) for r in rows} + assert set(reported)==set(expected)==set(range(1,8)),rows + assert all(abs(reported[s]-e)<=1e-11*abs(e) for s,e in expected.items()),rows + print('PASS: seven species; 50-to-100 K conversion floor; 183 m3 physical volume; null/ghost exclusions; identical state with diagnostics enabled and disabled.') diff --git a/test/qualification/test_trace_diffusion_stages.py b/test/qualification/test_trace_diffusion_stages.py new file mode 100644 index 000000000..ad666dd5b --- /dev/null +++ b/test/qualification/test_trace_diffusion_stages.py @@ -0,0 +1,120 @@ +"""Check trace command rewriting for native GNU and Intel Ninja commands.""" +import json +from pathlib import Path +import runpy +import shlex +import subprocess +import sys +import tempfile +import unittest +from unittest.mock import patch + +ROOT = Path(__file__).resolve().parents[2] + + +class TraceCompilation(unittest.TestCase): + def test_native_compiler_flags(self): + for compiler, flags, source_name in ( + ("gfortran", ["-fpreprocessed", "-Jinclude", "-fcheck=all"], + "PDEparabolic.f90-pp.f90"), + ("gfortran", ["-fpreprocessed", "-J", "include", "-fcheck=all"], + "PDEparabolic.f90-pp.f90"), + ("/opt/intel/bin/ifx", ["-module", "include", "-CB"], + "PDEparabolic.f90-pp.f90"), + ("ifort", ["-module=include", "-CB"], "PDEparabolic.f90"), + ): + with self.subTest(compiler=compiler, flags=flags), tempfile.TemporaryDirectory() as tmp: + build = Path(tmp) + source = build / "PDEparabolic.f90" + source.write_text("call check_solver_info(info,'TRBDF21D BDF2 stage')\n" + "end module PDEparabolic\n") + probe = build / "native/physics_native.o" + probe.parent.mkdir() + work = build / "trace" + compile_command = shlex.join( + [compiler, "-Iinclude", *flags, "-c", source_name, "-o", "PDEparabolic.f90.o"]) + commands = ( + "cmake -E cmake_ninja_depends --ddi=original.o.ddi\n" + + compile_command + "\n" + + shlex.join([compiler, "-c", "other.f90", "-o", "other.o"]) + "\n") + link_command = ( + ": && ifx continuity_floor.f90.o libgemini3d.a -o original && :\n") + argv = ["trace_diffusion_stages.py", "--source", str(source), + "--build", str(build), "--probe", str(probe), "--work", str(work)] + with patch.object(sys, "argv", argv), \ + patch("subprocess.check_output", side_effect=[commands, link_command]), \ + patch("subprocess.run", return_value=subprocess.CompletedProcess( + [], 0, stdout="", stderr="")) as run: + runpy.run_path(str(ROOT / "scripts/qualification/trace_diffusion_stages.py"), + run_name="__main__") + command = run.call_args_list[0].args[0] + self.assertEqual(command[0], compiler) + self.assertEqual(command[command.index("-c") + 1], + str(work / "PDEparabolic_trace.f90")) + self.assertEqual(command[command.index("-o") + 1], + str(work / "PDEparabolic_trace.o")) + self.assertIn("-Iinclude", command) + self.assertNotIn("-fpreprocessed", command) + self.assertNotIn("include", command) + if compiler == "gfortran": + self.assertIn("-fcheck=all", command) + self.assertIn("-J" + str(work), command) + self.assertNotIn("-Jinclude", command) + self.assertIn("-ffree-line-length-none", command) + else: + self.assertIn("-CB", command) + self.assertEqual(command[command.index("-module") + 1], str(work)) + self.assertNotIn("-module=include", command) + self.assertNotIn("-ffree-line-length-none", command) + self.assertFalse(any(t.startswith("-J") for t in command)) + + +class TraceCompileCommand(unittest.TestCase): + def test_native_compiler_flags_and_isolated_modules(self): + root=Path(__file__).resolve().parents[2] + for compiler,flags in ( + ('gfortran',['-O3','-ffree-line-length-none','-Jinclude','-fpreprocessed']), + ('ifx',['-O3','-module','include','-nofpp']), + ): + with self.subTest(compiler=compiler), tempfile.TemporaryDirectory() as directory: + build=Path(directory) + source=root/'src/numerical/diffusion/PDEparabolic.f90' + work=build/'trace' + probe=build/'physics_native.o' + native=[compiler,*flags,'-c','src/PDEparabolic.f90-pp.f90', + '-o','src/CMakeFiles/PDEparabolic.dir/PDEparabolic.f90.o'] + commands='\n'.join([ + f'{compiler} -c dependency.f90 -o dependency.f90.o', + f'{compiler} -E -o src/PDEparabolic.f90-pp.f90 {source}', + shlex.join(native), + ]) + link=': && '+shlex.join([compiler,'continuity_floor.f90.o','-o','probe', + 'libgemini3d.a'])+' && :' + argv=['trace_diffusion_stages.py','--source',str(source),'--build',str(build), + '--probe',str(probe),'--work',str(work)] + with patch.object(sys,'argv',argv), \ + patch('subprocess.check_output',side_effect=[commands,link]), \ + patch('subprocess.run',return_value=subprocess.CompletedProcess([],0,'','')) as run: + runpy.run_path(str(root/'scripts/qualification/trace_diffusion_stages.py'), + run_name='__main__') + cc=run.call_args_list[0].args[0] + self.assertEqual(cc[0],compiler) + self.assertIn('-O3',cc) + self.assertEqual(cc[cc.index('-c')+1],str(work/'PDEparabolic_trace.f90')) + self.assertEqual(cc[cc.index('-o')+1],str(work/'PDEparabolic_trace.o')) + self.assertNotIn('-fpreprocessed',cc) + if compiler=='ifx': + self.assertIn('-nofpp',cc) + self.assertEqual(cc[cc.index('-module')+1],str(work)) + self.assertFalse(any(t.startswith('-J') for t in cc)) + self.assertNotIn('-ffree-line-length-none',cc) + else: + self.assertIn('-J'+str(work),cc) + self.assertNotIn('-Jinclude',cc) + self.assertIn('-ffree-line-length-none',cc) + receipt=json.loads((work/'trace-receipt.json').read_text()) + self.assertEqual(receipt['compile_command'],cc) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/qualification/test_transport_inventory.py b/test/qualification/test_transport_inventory.py new file mode 100644 index 000000000..d5efd6e1b --- /dev/null +++ b/test/qualification/test_transport_inventory.py @@ -0,0 +1,45 @@ +"""A complete surviving step cannot conceal missing numerical evidence.""" +import csv +from pathlib import Path +import sys,tempfile,unittest +sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'scripts/qualification')) +from check_transport import check + +class TransportInventory(unittest.TestCase): + def fixture(self,directory): + fields='t,dt,quantity,species,axis,before,after,delta,outward,min_face,max_face,scale,residual,normalized_residual'.split(',') + records=[dict(zip(fields,[t,1,q,s,a,100,99,-1,1,0,1,100,0,0])) + for t in (0,1) for q in (1,2,3) + for s in range(1,8 if q==3 else 7) for a in (1,2,3)] + path=directory/'transport-r00000000.csv' + def save(rows): + with path.open('w') as stream: + writer=csv.DictWriter(stream,fields);writer.writeheader();writer.writerows(rows) + save(records) + (directory/'continuity-r00000000.csv').write_text('t,dt\n0,1\n1,1\n') + return records,save + + def test_entire_later_step_is_required(self): + with tempfile.TemporaryDirectory() as d: + directory=Path(d);records,save=self.fixture(directory) + self.assertTrue(check(directory,layout=[1,1])['passed']) + save([r for r in records if r['t']==0]) + with self.assertRaisesRegex(ValueError,'Transport/continuity'):check(directory,layout=[1,1]) + + def test_recorded_state_change_must_match_increment(self): + with tempfile.TemporaryDirectory() as d: + directory=Path(d);records,save=self.fixture(directory) + # The declared scale remains valid, and delta + outward still closes. + records[0]['after']=50;save(records) + self.assertFalse(check(directory,layout=[1,1])['passed']) + + def test_invalid_budgets_and_scales_are_rejected(self): + with tempfile.TemporaryDirectory() as d: + directory=Path(d);records,save=self.fixture(directory) + for budget in (0,-1,float('inf'),float('nan')): + with self.subTest(budget=budget),self.assertRaisesRegex(ValueError,'budget'): + check(directory,budget=budget,layout=[1,1]) + records[0]['scale']=1;save(records) + with self.assertRaisesRegex(ValueError,'scale'):check(directory,layout=[1,1]) + +if __name__=='__main__':unittest.main() diff --git a/test/qualification/transport_convergence.f90 b/test/qualification/transport_convergence.f90 new file mode 100644 index 000000000..7b9bdc546 --- /dev/null +++ b/test/qualification/transport_convergence.f90 @@ -0,0 +1,42 @@ +program transport_convergence +use phys_consts, only: wp,pi +use advec, only: advec1D_MC_curv +implicit none(type,external) +integer :: n,level,i,it,nt +real(wp) :: h,dt,error(3),order,flux_residual,max_residual +real(wp), allocatable :: f(:),old(:),v(:),dx(:),dxi(:),hc(:),hi(:),flux(:),exact(:) +do level=1,3 + n=32*2**(level-1);nt=2*n;h=1._wp/n;dt=1._wp/nt + allocate(f(-1:n+2),old(-1:n+2),v(n+1),dx(0:n+2),dxi(n),hc(-1:n+2),hi(n+1),flux(n+1),exact(n)) + v=1;dx=h;dxi=h;hc=1;hi=1 + do i=1,n + f(i)=2+sin(2*pi*(i-.5_wp)*h) + enddo + exact=f(1:n);max_residual=0 + do it=1,nt + f(-1:0)=f(n-1:n);f(n+1:n+2)=f(1:2);old=f + f=advec1D_MC_curv(old,v,dt,dx,dxi,hc,hi,hi,flux) + flux_residual=abs(sum(f(1:n)-old(1:n))*h+flux(n+1)-flux(1))/sum(abs(old(1:n))*h) + max_residual=max(max_residual,flux_residual) + enddo + error(level)=sum(abs(f(1:n)-exact))*h + print '(A,I0,2(A,ES24.16))','cells=',n,' L1=',error(level),' balance=',max_residual + if(max_residual>1e-11_wp) error stop 'Periodic transport balance budget exceeded' + deallocate(f,old,v,dx,dxi,hc,hi,flux,exact) +enddo +do level=2,3 + order=log(error(level-1)/error(level))/log(2._wp) + print '(A,F10.6)','measured advection space/time order: ',order + if(order<1.8_wp) error stop 'Smooth advection convergence below frozen budget' +enddo +! Curved weights and known nonzero boundary flux (no inference from state delta). +n=12 +allocate(f(-1:n+2),old(-1:n+2),v(n+1),dx(0:n+2),dxi(n),hc(-1:n+2),hi(n+1),flux(n+1)) +f=2;v=1;dx=.1_wp;dxi=.1_wp;hc=2 +hi=[(1._wp+.01_wp*i,i=1,n+1)] +old=f;dt=.001_wp +f=advec1D_MC_curv(old,v,dt,dx,dxi,hc,hi,hi,flux) +flux_residual=abs(sum((f(1:n)-old(1:n))*hc(1:n)*dxi)+2*dt*(hi(n+1)-hi(1))) +if(flux_residual>1e-11_wp) error stop 'Known curved-boundary flux budget exceeded' +print '(A,ES24.16)','curved known-boundary residual: ',flux_residual +end program diff --git a/test/ref_data_snapshot.json b/test/ref_data_snapshot.json new file mode 100644 index 000000000..eddad0f24 --- /dev/null +++ b/test/ref_data_snapshot.json @@ -0,0 +1,381 @@ +{ + "system": { + "c_compiler": "GNU 12.2.0", + "cmake_version": "3.25.1", + "cpp_compiler": "GNU 12.2.0", + "cpu": "8 core Apple M1", + "fortran_compiler": "GNU 12.2.0", + "memory_ram_MB": 16384, + "operating_system": "Darwin" + }, + "tests": { + "GDI_KHI_eq": { + "archive": "GDI_KHI_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "4faa58f2c4d419a8626221b9a4f8e022783b3df406af778ee3bc9a53a214dd31", + "url": "https://www.dropbox.com/s/3s465sd24ugs2w9/GDI_KHI_eq.zst?dl=1" + }, + "GDI_periodic_lowres": { + "archive": "GDI_periodic_lowres.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "c8bfd1215b61f5f199c5205325e4cde50c54000cd624108a077e6f5c58ec4556", + "url": "https://www.dropbox.com/s/57iy7xwsoox924l/GDI_periodic_lowres.zst?dl=1" + }, + "KHI_periodic_lowres": { + "archive": "KHI_periodic_lowres.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "40c311edd90a7c8ac0df1453e8bb541dcf2238dc462c35c6a44b7a29cbf50bdf", + "url": "https://www.dropbox.com/s/2rjq3ymhbk8de0f/KHI_periodic_lowres.zst?dl=1" + }, + "arcs": { + "archive": "arcs.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "82d0dbc0c8154157ef4a81764af7634d2fb06ae4a7a7d5e5b14bdbc8272a192b", + "url": "https://www.dropbox.com/s/zecguhdn1s3vqjf/arcs.zst?dl=1" + }, + "arcs_eq": { + "archive": "arcs_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "a7396d11c8700f1b5b38329d44ae27041fefaeee43df93f9e32c699d7b15db9e", + "url": "https://www.dropbox.com/s/pbanjjpzw4jmzjb/arcs_eq.zst?dl=1" + }, + "cusp2d_eq": { + "archive": "cusp2d_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "eeadb3241d078f0c409536ae2cbd3bab7f7a0b92eddaec322767c3d914a428ac", + "url": "https://www.dropbox.com/s/w4laaqapxnpb0s6/cusp2d_eq.zst?dl=1" + }, + "cusp3d_eq": { + "archive": "cusp3d_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "936508e4d5d988cab2c00091d869848a02c387f37e5c5806c206da8abec48c4e", + "url": "https://www.dropbox.com/s/6kmx7htvvk2nmrm/cusp3d_eq.zst?dl=1" + }, + "cusp_softprecip2D_Dirich": { + "archive": "cusp_softprecip2D_Dirich.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "95de0f98aa7bb31d91ee8e9f6bfd64ac636a2fdc391486cf2873f490c04f865f", + "url": "https://www.dropbox.com/s/3wyssn8jd0pfjkn/cusp_softprecip2D_Dirich.zst?dl=1" + }, + "cusp_softprecip2D_Neu": { + "archive": "cusp_softprecip2D_Neu.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "5ccb372d2faff63293a9f985581b7df3f1ce1c715f12d0fa89c132782ee49e2c", + "url": "https://www.dropbox.com/s/8mcg5u00j8cx7ic/cusp_softprecip2D_Neu.zst?dl=1" + }, + "cusp_softprecip3D": { + "archive": "cusp_softprecip3D.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "bb7424e06095cc2d37dd1eca6b550c048841d3f8a4a0c1a8bc38b95bda92ba5c", + "url": "https://www.dropbox.com/s/u4ao4hfwud7p1fv/cusp_softprecip3D.zst?dl=1" + }, + "mini2dew_eq": { + "archive": "mini2dew_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "d3f297995341e2ccdc3da16bf72db36cd230d88f86defdd054d4d3a11ad971af", + "url": "https://www.dropbox.com/s/py3gtwlxf47c537/mini2dew_eq.zst?dl=1" + }, + "mini2dew_fang": { + "archive": "mini2dew_fang.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "lx": [ + 48, + 40, + 1 + ], + "pygemini_version": "1.7.1", + "sha256": "28d7f16b08721411d51e4c624f3469e2a17bdd330b44e319a32364d3c5521e20", + "url": "https://www.dropbox.com/s/0pfpjbpxcxdcxkm/mini2dew_fang.zst?dl=1" + }, + "mini2dew_glow": { + "archive": "mini2dew_glow.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "lx": [ + 48, + 40, + 1 + ], + "pygemini_version": "1.7.1", + "sha256": "072d6bea6a358b26c1875fa248d419c91f5b1d313ccfa1dd90f5cc9d9c68b991", + "url": "https://www.dropbox.com/s/zlpwk9b15aiucka/mini2dew_glow.zst?dl=1" + }, + "mini2dns_eq": { + "archive": "mini2dns_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "e9f59e1d4614453a302ee01a7a052ff241b48dcd8a51fc4461f89845ba7fd4dd", + "url": "https://www.dropbox.com/s/tig0lzn9t7cuwl5/mini2dns_eq.zst?dl=1" + }, + "mini2dns_msis2_eq": { + "archive": "mini2dns_msis2_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW", + "MSIS2" + ], + "lx": [ + 48, + 1, + 12 + ], + "pygemini_version": "1.8.0", + "sha256": "a4261891369026d40b47a094f8d8cf9c594fd41453a540f6d573930d19382d6d", + "url": "https://www.dropbox.com/scl/fi/8h1tcxa2i95ayq9mpx7um/mini2dns_msis2_eq.zst?rlkey=4yqatbd17m9enz03cbj30w4ud&st=wembmgra&dl=1" + }, + "mini2dns_fang": { + "archive": "mini2dns_fang.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "lx": [ + 48, + 1, + 20 + ], + "pygemini_version": "1.7.1", + "sha256": "6ab7ed22e6b0e6926e6ab3eb1a13697be4fe8c74ecc71a2a0008f256a88179dc", + "url": "https://www.dropbox.com/s/o926kny2jlpehu9/mini2dns_fang.zst?dl=1", + "audit_note": "Dimension order corrected from the hash-verified inputs/simsize.h5 on 2026-09-16; archive/hash unchanged." + }, + "mini2dns_msis2_fang": { + "archive": "mini2dns_msis2_fang.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW", + "MSIS2" + ], + "lx": [ + 48, + 1, + 20 + ], + "pygemini_version": "1.8.0", + "sha256": "6f74dff26bac69999cafef756ddd86fd44f3f8f2698f1726c2e45d7529969e70", + "url": "https://www.dropbox.com/scl/fi/uqn55y2c5hxzcwee8pjpv/mini2dns_msis2_fang.zst?rlkey=bbc4n56fnl0td3x7u8hgzjobq&st=d62lzs8s&dl=1" + }, + "mini2dns_glow": { + "archive": "mini2dns_glow.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "lx": [ + 48, + 1, + 20 + ], + "pygemini_version": "1.7.1", + "sha256": "fe0ee83ad85a3743b7238f29c527e3044960aa13983948ebc7f44996aa3ca732", + "url": "https://www.dropbox.com/s/h7aej4rfno8jy2h/mini2dns_glow.zst?dl=1", + "audit_note": "Dimension order corrected from the hash-verified inputs/simsize.h5 on 2026-09-16; archive/hash unchanged." + }, + "mini3d_eq": { + "archive": "mini3d_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "09c75b34b1a7148a7eb407a0ac2ce2d883d2f3943e4fd47ab81426040d87d79b", + "url": "https://www.dropbox.com/s/ldi07j8suiou1yr/mini3d_eq.zst?dl=1" + }, + "mini3d_fang": { + "archive": "mini3d_fang.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "lx": [ + 48, + 12, + 16 + ], + "pygemini_version": "1.7.1", + "sha256": "29fed05d89e9514c53feaf839335a574bd8892e1d2d9c8c054ca8da5179b67f3", + "url": "https://www.dropbox.com/s/wrnekz415uotz0m/mini3d_fang.zst?dl=1" + }, + "mini3d_glow": { + "archive": "mini3d_glow.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "lx": [ + 48, + 12, + 16 + ], + "pygemini_version": "1.7.1", + "sha256": "cceed6e88deb433980c4c30e086e3c154e1154c08dfb2d6ae4cfaf8210cda831", + "url": "https://www.dropbox.com/s/7tf1bwg5hnccpvn/mini3d_glow.zst?dl=1" + }, + "tohoku20112D_medres_2Dneu": { + "archive": "tohoku20112D_medres_2Dneu.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "694bf22d3cbeb11ec6ad169c58697d6e72706a09b9b23b449d77a8f050aaa618", + "url": "https://www.dropbox.com/s/nmtqdisblvztvtn/tohoku20112D_medres_2Dneu.zst?dl=1" + }, + "tohoku20112D_medres_axineu": { + "archive": "tohoku20112D_medres_axineu.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "1456dade752c1846db6994c8ac5eece3dcda4c87e93b6a25f9c6c89264aa2347", + "url": "https://www.dropbox.com/s/b365fpuymkcap7b/tohoku20112D_medres_axineu.zst?dl=1" + }, + "tohoku20113D_lowres_3Dneu": { + "archive": "tohoku20113D_lowres_3Dneu.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "ab18c32e10957856a938bae7b395ef738669d11d884d37ec55f2ce515df63426", + "url": "https://www.dropbox.com/s/mysze5he5d8pom7/tohoku20113D_lowres_3Dneu.zst?dl=1" + }, + "tohoku20113D_lowres_axineu": { + "archive": "tohoku20113D_lowres_axineu.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "c603e301107b9223768796860cc6935ddd640ddd7d32ef6da36c6abdc0f416f4", + "url": "https://www.dropbox.com/s/dityrs1y14p7e87/tohoku20113D_lowres_axineu.zst?dl=1" + }, + "tohoku2d_eq": { + "archive": "tohoku2d_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "115920988f1dc14676865c2f2ab82233947c974cf8df16cdc9de127f317beedb", + "url": "https://www.dropbox.com/s/cm1ex2ck4xkrube/tohoku2d_eq.zst?dl=1" + }, + "tohoku3d_eq": { + "archive": "tohoku3d_eq.zst", + "gemini_features": [ + "REALBITS:64", + "MPI", + "HDF5", + "GLOW" + ], + "pygemini_version": "1.7.1", + "sha256": "b1861e26c2e5719c32959dd14792da71fe7d0d0e2396b3559f644fa4f75d7f4b", + "url": "https://www.dropbox.com/s/8wr2uklx72e502g/tohoku3d_eq.zst?dl=1" + } + } +}