diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 7e4edc2dc36..1355dc2f647 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -9,6 +9,7 @@ pr: jobs: - job: + # FIXME remove unused variables variables: BLASPP_HOME: '/usr/local' CEI_SUDO: 'sudo' @@ -16,29 +17,29 @@ jobs: CMAKE_GENERATOR: 'Ninja' FFTW_HOME: '/usr' LAPACKPP_HOME: '/usr/local' - OMP_NUM_THREADS: 1 WARPX_CI_CCACHE: 'TRUE' - WARPX_CI_NUM_MAKE_JOBS: 2 - WARPX_CI_OPENPMD: 'TRUE' - WARPX_CI_TMP: '/tmp/ci' + #WARPX_OPENPMD: 'TRUE' strategy: matrix: - cartesian1d: - WARPX_CI_REGULAR_CARTESIAN_1D: 'TRUE' - WARPX_CI_PSATD: 'FALSE' - cartesian2d: - WARPX_CI_REGULAR_CARTESIAN_2D: 'TRUE' - cartesian3d: - WARPX_CI_REGULAR_CARTESIAN_3D: 'TRUE' - single_precision: - WARPX_CI_SINGLE_PRECISION: 'TRUE' - rz_or_nompi: - WARPX_CI_RZ_OR_NOMPI: 'TRUE' - qed: - WARPX_CI_QED: 'TRUE' - embedded_boundary: - WARPX_CI_EB: 'TRUE' + # Cartesian 1D + cartesian_1d: + WARPX_CMAKE_FLAGS: -DWarpX_DIMS=1 -DWarpX_FFT=ON -DWarpX_PYTHON=ON + # Cartesian 2D + cartesian_2d: + WARPX_CMAKE_FLAGS: -DWarpX_DIMS=2 -DWarpX_FFT=ON -DWarpX_PYTHON=ON + # Cartesian 3D + cartesian_3d: + WARPX_CMAKE_FLAGS: -DWarpX_DIMS=3 -DWarpX_FFT=ON -DWarpX_PYTHON=ON + WARPX_HEFFTE: 'TRUE' + # Cylindrical RZ + cylindrical_rz: + WARPX_CMAKE_FLAGS: -DWarpX_DIMS=RZ -DWarpX_FFT=ON -DWarpX_PYTHON=ON + WARPX_RZ_FFT: 'TRUE' + # single precision + #single_precision: + # WARPX_CMAKE_FLAGS: -DWarpX_DIMS='1;2;3;RZ' -DWarpX_FFT=ON -DWarpX_PYTHON=ON -DWarpX_PRECISION=SINGLE + # WARPX_RZ_FFT: 'TRUE' # default: 60; maximum: 360 timeoutInMinutes: 240 @@ -50,9 +51,8 @@ jobs: - task: Cache@2 continueOnError: true inputs: - key: 'Ccache | "$(System.JobName)" | .azure-pipelines.yml | cmake/dependencies/AMReX.cmake | run_test.sh' + key: 'Ccache | "$(System.JobName)" | .azure-pipelines.yml | cmake/dependencies/AMReX.cmake' restoreKeys: | - Ccache | "$(System.JobName)" | .azure-pipelines.yml | cmake/dependencies/AMReX.cmake | run_test.sh Ccache | "$(System.JobName)" | .azure-pipelines.yml | cmake/dependencies/AMReX.cmake Ccache | "$(System.JobName)" | .azure-pipelines.yml path: /home/vsts/.ccache @@ -62,9 +62,8 @@ jobs: - task: Cache@2 continueOnError: true inputs: - key: 'Python3 | "$(System.JobName)" | .azure-pipelines.yml | run_test.sh' + key: 'Python3 | "$(System.JobName)" | .azure-pipelines.yml' restoreKeys: | - Python3 | "$(System.JobName)" | .azure-pipelines.yml | run_test.sh Python3 | "$(System.JobName)" | .azure-pipelines.yml path: /home/vsts/.local/lib/python3.8 cacheHitVar: PYTHON38_CACHE_RESTORED @@ -82,6 +81,8 @@ jobs: python3 python3-pandas python3-pip python3-venv python3-setuptools libblas-dev liblapack-dev ccache --set-config=max_size=10.0G python3 -m pip install --upgrade pip + python3 -m pip install --upgrade build + python3 -m pip install --upgrade packaging python3 -m pip install --upgrade setuptools python3 -m pip install --upgrade wheel python3 -m pip install --upgrade virtualenv @@ -91,24 +92,48 @@ jobs: export PATH="$HOME/.local/bin:$PATH" sudo curl -L -o /usr/local/bin/cmake-easyinstall https://raw.githubusercontent.com/ax3l/cmake-easyinstall/main/cmake-easyinstall sudo chmod a+x /usr/local/bin/cmake-easyinstall - if [ "${WARPX_CI_OPENPMD:-FALSE}" == "TRUE" ]; then - cmake-easyinstall --prefix=/usr/local \ - git+https://github.com/openPMD/openPMD-api.git@0.14.3 \ - -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DopenPMD_USE_PYTHON=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI_TOOLS=OFF - python3 -m pip install --upgrade openpmd-api - fi - if [[ "${WARPX_CI_RZ_OR_NOMPI:-FALSE}" == "TRUE" ]]; then - cmake-easyinstall --prefix=/usr/local git+https://github.com/icl-utk-edu/blaspp.git \ + #if [ "${WARPX_OPENPMD:-FALSE}" == "TRUE" ]; then + # cmake-easyinstall --prefix=/usr/local \ + # git+https://github.com/openPMD/openPMD-api.git@0.14.3 \ + # -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + # -DCMAKE_VERBOSE_MAKEFILE=ON \ + # -DopenPMD_USE_PYTHON=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI_TOOLS=OFF + # #python3 -m pip install --upgrade openpmd-api + #fi + if [ "${WARPX_RZ_FFT:-FALSE}" == "TRUE" ]; then + # BLAS++ + cmake-easyinstall --prefix=/usr/local \ + git+https://github.com/icl-utk-edu/blaspp.git \ -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ -DCMAKE_CXX_STANDARD=17 \ -Duse_openmp=OFF -Dbuild_tests=OFF -DCMAKE_VERBOSE_MAKEFILE=ON - cmake-easyinstall --prefix=/usr/local git+https://github.com/icl-utk-edu/lapackpp.git \ - -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ - -DCMAKE_CXX_STANDARD=17 \ + # LAPACK++ + cmake-easyinstall --prefix=/usr/local \ + git+https://github.com/icl-utk-edu/lapackpp.git \ + -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + -DCMAKE_CXX_STANDARD=17 \ -Duse_cmake_find_lapack=ON -Dbuild_tests=OFF -DCMAKE_VERBOSE_MAKEFILE=ON fi + if [ "${WARPX_HEFFTE:-FALSE}" == "TRUE" ]; then + cmake-easyinstall --prefix=/usr/local git+https://github.com/icl-utk-edu/heffte.git@v2.4.0 \ + -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + -DCMAKE_CXX_STANDARD=17 -DHeffte_ENABLE_DOXYGEN=OFF \ + -DHeffte_ENABLE_FFTW=ON -DHeffte_ENABLE_TESTING=OFF \ + -DHeffte_ENABLE_CUDA=OFF -DHeffte_ENABLE_ROCM=OFF \ + -DHeffte_ENABLE_ONEAPI=OFF -DHeffte_ENABLE_MKL=OFF \ + -DHeffte_ENABLE_PYTHON=OFF -DHeffte_ENABLE_FORTRAN=OFF \ + -DHeffte_ENABLE_MAGMA=OFF \ + -DCMAKE_VERBOSE_MAKEFILE=ON + fi + # Python modules required for test analysis + python3 -m pip install --upgrade -r Regression/requirements.txt + python3 -m pip cache purge + # external repositories required for test analysis + cd .. + git clone --depth 1 https://github.com/ECP-WarpX/warpx-data.git + # TODO select only specific datasets? + git clone --depth 1 https://github.com/openPMD/openPMD-example-datasets.git + cd - rm -rf ${CEI_TMP} df -h displayName: 'Install dependencies' @@ -116,7 +141,23 @@ jobs: - bash: | set -eu -o pipefail df -h - ./run_test.sh - rm -rf ${WARPX_CI_TMP} + + # configure + export AMReX_CMAKE_FLAGS="-DAMReX_ASSERTIONS=ON -DAMReX_TESTING=ON" + cmake -S . -B build \ + ${AMReX_CMAKE_FLAGS} \ + ${WARPX_CMAKE_FLAGS} \ + -DWarpX_TEST_CLEANUP=ON \ + -DWarpX_TEST_FPETRAP=ON + + # build + cmake --build build -j 2 df -h - displayName: 'Build & test' + displayName: 'Build' + + - bash: | + set -eu -o pipefail + + # run tests (exclude pytest.AMReX when running Python tests) + ctest --test-dir build --output-on-failure -E AMReX + displayName: 'Test' diff --git a/.github/workflows/clang_sanitizers.yml b/.github/workflows/clang_sanitizers.yml new file mode 100644 index 00000000000..119a893eb72 --- /dev/null +++ b/.github/workflows/clang_sanitizers.yml @@ -0,0 +1,162 @@ +name: 🧴 clang sanitizers + +on: [push, pull_request] + +concurrency: + group: ${{ github.ref }}-${{ github.head_ref }}-clangsanitizers + cancel-in-progress: true + +jobs: + build_UB_sanitizer: + name: Clang UB sanitizer + runs-on: ubuntu-22.04 + container: ubuntu:23.10 + if: github.event.pull_request.draft == false + env: + CC: clang + CXX: clang++ + # On CI for this test, Ninja is slower than the default: + #CMAKE_GENERATOR: Ninja + steps: + - uses: actions/checkout@v4 + - name: install dependencies + run: | + .github/workflows/dependencies/clang17.sh + - name: CCache Cache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} + restore-keys: | + ccache-${{ github.workflow }}-${{ github.job }}-git- + - name: build WarpX + run: | + export CCACHE_COMPRESS=1 + export CCACHE_COMPRESSLEVEL=10 + export CCACHE_MAXSIZE=100M + ccache -z + + export CXX=$(which clang++-17) + export CC=$(which clang-17) + export CXXFLAGS="-fsanitize=undefined,address,pointer-compare -fno-sanitize-recover=all" + + cmake -S . -B build \ + -GNinja \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DWarpX_DIMS="RZ;1;2;3" \ + -DWarpX_FFT=ON \ + -DWarpX_QED=ON \ + -DWarpX_QED_TABLE_GEN=ON \ + -DWarpX_OPENPMD=ON \ + -DWarpX_PRECISION=SINGLE \ + -DWarpX_PARTICLE_PRECISION=SINGLE + cmake --build build -j 4 + + ccache -s + du -hs ~/.cache/ccache + + - name: run with UB sanitizer + run: | + + # We need these two lines because these tests run inside a docker container + export OMPI_ALLOW_RUN_AS_ROOT=1 + export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 + + export OMP_NUM_THREADS=2 + + #MPI implementations often leak memory + export "ASAN_OPTIONS=detect_leaks=0" + + mpirun -n 2 ./build/bin/warpx.rz Examples/Physics_applications/laser_acceleration/inputs_base_rz + mpirun -n 2 ./build/bin/warpx.1d Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration + mpirun -n 2 ./build/bin/warpx.2d Examples/Physics_applications/laser_acceleration/inputs_base_2d + mpirun -n 2 ./build/bin/warpx.3d Examples/Physics_applications/laser_acceleration/inputs_base_3d + + build_thread_sanitizer: + name: Clang thread sanitizer + runs-on: ubuntu-22.04 + container: ubuntu:23.10 + if: github.event.pull_request.draft == false + env: + CC: clang + CXX: clang++ + # On CI for this test, Ninja is slower than the default: + #CMAKE_GENERATOR: Ninja + steps: + - uses: actions/checkout@v4 + - name: install dependencies + run: | + .github/workflows/dependencies/clang17.sh + - name: CCache Cache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} + restore-keys: | + ccache-${{ github.workflow }}-${{ github.job }}-git- + - name: build WarpX + run: | + export CCACHE_COMPRESS=1 + export CCACHE_COMPRESSLEVEL=10 + export CCACHE_MAXSIZE=100M + ccache -z + + export CXX=$(which clang++-17) + export CC=$(which clang-17) + export CXXFLAGS="-fsanitize=thread" + + cmake -S . -B build \ + -GNinja \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DWarpX_DIMS="RZ;1;2;3" \ + -DWarpX_FFT=ON \ + -DWarpX_QED=ON \ + -DWarpX_QED_TABLE_GEN=ON \ + -DWarpX_OPENPMD=ON \ + -DWarpX_EB=OFF \ + -DWarpX_PRECISION=DOUBLE \ + -DWarpX_PARTICLE_PRECISION=DOUBLE + cmake --build build -j 4 + + cmake -S . -B build_EB \ + -GNinja \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DWarpX_DIMS="2" \ + -DWarpX_FFT=ON \ + -DWarpX_QED=ON \ + -DWarpX_QED_TABLE_GEN=ON \ + -DWarpX_OPENPMD=ON \ + -DWarpX_EB=ON \ + -DWarpX_PRECISION=DOUBLE \ + -DWarpX_PARTICLE_PRECISION=DOUBLE + cmake --build build_EB -j 4 + + ccache -s + du -hs ~/.cache/ccache + + - name: run with thread sanitizer + run: | + export PMIX_MCA_gds=hash + export TSAN_OPTIONS='ignore_noninstrumented_modules=1' + export ARCHER_OPTIONS="verbose=1" + + # We need these two lines because these tests run inside a docker container + export OMPI_ALLOW_RUN_AS_ROOT=1 + export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 + + export OMP_NUM_THREADS=2 + + mpirun -n 2 ./build/bin/warpx.rz Examples/Physics_applications/laser_acceleration/inputs_base_rz warpx.serialize_initial_conditions = 0 + mpirun -n 2 ./build/bin/warpx.1d Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration warpx.serialize_initial_conditions = 0 + mpirun -n 2 ./build/bin/warpx.2d Examples/Physics_applications/laser_acceleration/inputs_base_2d warpx.serialize_initial_conditions = 0 + mpirun -n 2 ./build/bin/warpx.3d Examples/Physics_applications/laser_acceleration/inputs_base_3d warpx.serialize_initial_conditions = 0 + + git clone https://github.com/ECP-WarpX/warpx-data ../warpx-data + cd Examples/Tests/embedded_circle + + ulimit -c unlimited + + mpirun -n 2 ../../../build_EB/bin/warpx.2d inputs_test_2d_embedded_circle warpx.serialize_initial_conditions = 0 diff --git a/.github/workflows/clang_tidy.yml b/.github/workflows/clang_tidy.yml index 28b46b52530..5a4f83f01f1 100644 --- a/.github/workflows/clang_tidy.yml +++ b/.github/workflows/clang_tidy.yml @@ -13,6 +13,7 @@ jobs: dim: [1, 2, RZ, 3] name: clang-tidy-${{ matrix.dim }}D runs-on: ubuntu-22.04 + timeout-minutes: 180 if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v4 @@ -59,18 +60,3 @@ jobs: ccache -s du -hs ~/.cache/ccache - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 diff --git a/.github/workflows/cleanup-cache-postpr.yml b/.github/workflows/cleanup-cache-postpr.yml index 9a2ffb0f61a..5e9a70cd5a4 100644 --- a/.github/workflows/cleanup-cache-postpr.yml +++ b/.github/workflows/cleanup-cache-postpr.yml @@ -23,8 +23,11 @@ jobs: REPO=${{ github.repository }} - gh run download ${{ github.event.workflow_run.id }} -n pr_number - pr_number=`cat pr_number.txt` + # For debugging cat ${GITHUB_EVENT_PATH} to see the payload. + + pr_head_sha=${{ github.event.workflow_run.head_sha }} + pr_number=$(gh pr list --state all --search $pr_head_sha --json number --jq '.[0].number') + echo "Post-PR cache cleanup for PR ${pr_number}" BRANCH=refs/pull/${pr_number}/merge # Setting this to not fail the workflow while deleting cache keys. diff --git a/.github/workflows/cleanup-cache.yml b/.github/workflows/cleanup-cache.yml index bd1a518acf4..c71a48cdad8 100644 --- a/.github/workflows/cleanup-cache.yml +++ b/.github/workflows/cleanup-cache.yml @@ -2,7 +2,7 @@ name: CleanUpCache on: workflow_run: - workflows: [🧹 clang-tidy, 🔍 CodeQL, 🐧 CUDA, 🐧 HIP, 🐧 Intel, 🍏 macOS, 🐧 OpenMP] + workflows: [🧴 clang sanitizers, 🧹 clang-tidy, 🔍 CodeQL, 🐧 CUDA, 🐧 HIP, 🐧 Intel, 🍏 macOS, 🐧 OpenMP] types: - completed @@ -29,9 +29,12 @@ jobs: # Triggering workflow run name (e.g., LinuxClang) WORKFLOW_NAME="${{ github.event.workflow_run.name }}" + # For debugging, cat ${GITHUB_EVENT_PATH} to see the payload. + if [[ $EVENT == "pull_request" ]]; then - gh run download ${{ github.event.workflow_run.id }} -n pr_number - pr_number=`cat pr_number.txt` + pr_head_sha=${{ github.event.workflow_run.head_sha }} + pr_number=$(gh pr list --search $pr_head_sha --json number --jq '.[0].number') + echo "Clean up cache for PR ${pr_number}" BRANCH=refs/pull/${pr_number}/merge else BRANCH=refs/heads/${{ github.event.workflow_run.head_branch }} @@ -54,6 +57,7 @@ jobs: IFS=$'\n' for j in $cached_jobs do + # Delete all entries except the last used one old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "${j}-git-" --sort last-used | cut -f 1 | tail -n +2) for k in $old_keys do diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index bc0bee545cc..5c36b9d9f21 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -110,18 +110,3 @@ jobs: uses: github/codeql-action/upload-sarif@v3 with: sarif_file: sarif-results/${{ matrix.language }}.sarif - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index c2ec9aaa763..a1e7f5affda 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -43,6 +43,11 @@ jobs: export CEI_SUDO="sudo" export CEI_TMP="/tmp/cei" + + export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} + export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:${LD_LIBRARY_PATH} + which nvcc || echo "nvcc not in PATH!" + cmake-easyinstall --prefix=/usr/local \ git+https://github.com/openPMD/openPMD-api.git@0.15.1 \ -DopenPMD_USE_PYTHON=OFF \ @@ -51,6 +56,16 @@ jobs: -DBUILD_CLI_TOOLS=OFF \ -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ -DCMAKE_VERBOSE_MAKEFILE=ON + cmake-easyinstall --prefix=/usr/local \ + git+https://github.com/icl-utk-edu/heffte.git@v2.4.0 \ + -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + -DCMAKE_CXX_STANDARD=17 -DHeffte_ENABLE_DOXYGEN=OFF \ + -DHeffte_ENABLE_FFTW=OFF -DHeffte_ENABLE_TESTING=OFF \ + -DHeffte_ENABLE_CUDA=ON -DHeffte_ENABLE_ROCM=OFF \ + -DHeffte_ENABLE_ONEAPI=OFF -DHeffte_ENABLE_MKL=OFF \ + -DHeffte_ENABLE_PYTHON=OFF -DHeffte_ENABLE_FORTRAN=OFF \ + -DHeffte_ENABLE_MAGMA=OFF \ + -DCMAKE_VERBOSE_MAKEFILE=ON - name: build WarpX run: | export CCACHE_COMPRESS=1 @@ -71,6 +86,7 @@ jobs: -DWarpX_openpmd_internal=OFF \ -DWarpX_PRECISION=SINGLE \ -DWarpX_FFT=ON \ + -DWarpX_HEFFTE=ON \ -DAMReX_CUDA_ERROR_CROSS_EXECUTION_SPACE_CALL=ON \ -DAMReX_CUDA_ERROR_CAPTURE_THIS=ON cmake --build build_sp -j 4 @@ -115,7 +131,7 @@ jobs: which nvcc || echo "nvcc not in PATH!" git clone https://github.com/AMReX-Codes/amrex.git ../amrex - cd ../amrex && git checkout --detach 0c3273f5e591815909180f8ffaf5b793cabbf9bc && cd - + cd ../amrex && git checkout --detach 028638564f7be0694b9898f8d4088cdbf9a6f9f5 && cd - make COMP=gcc QED=FALSE USE_MPI=TRUE USE_GPU=TRUE USE_OMP=FALSE USE_FFT=TRUE USE_CCACHE=TRUE -j 4 ccache -s @@ -187,18 +203,3 @@ jobs: ccache -s du -hs ~/.cache/ccache - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 diff --git a/.github/workflows/dependencies/clang17.sh b/.github/workflows/dependencies/clang17.sh new file mode 100755 index 00000000000..d208a9f3f3b --- /dev/null +++ b/.github/workflows/dependencies/clang17.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# +# Copyright 2024 The WarpX Community +# +# License: BSD-3-Clause-LBNL +# Authors: Luca Fedeli + +set -eu -o pipefail + +# This dependency file is currently used within a docker container, +# which does not come with sudo. +apt-get -qqq update +apt-get -y install sudo + +# `man apt.conf`: +# Number of retries to perform. If this is non-zero APT will retry +# failed files the given number of times. +echo 'Acquire::Retries "3";' | sudo tee /etc/apt/apt.conf.d/80-retries + +# This dependency file is currently used within a docker container, +# which does not come (among others) with wget, xz-utils, curl, git, +# ccache, and pkg-config pre-installed. +sudo apt-get -qqq update +sudo apt-get install -y \ + cmake \ + clang-17 \ + clang-tidy-17 \ + libblas-dev \ + libc++-17-dev \ + libboost-math-dev \ + libfftw3-dev \ + libfftw3-mpi-dev \ + libhdf5-openmpi-dev \ + liblapack-dev \ + libopenmpi-dev \ + libomp-17-dev \ + ninja-build \ + wget \ + xz-utils \ + curl \ + git \ + ccache \ + pkg-config + +# Use clang 17 +export CXX=$(which clang++-17) +export CC=$(which clang-17) + +# cmake-easyinstall +# +sudo curl -L -o /usr/local/bin/cmake-easyinstall https://raw.githubusercontent.com/ax3l/cmake-easyinstall/main/cmake-easyinstall +sudo chmod a+x /usr/local/bin/cmake-easyinstall +export CEI_SUDO="sudo" +export CEI_TMP="/tmp/cei" + +# BLAS++ & LAPACK++ +cmake-easyinstall \ + --prefix=/usr/local \ + git+https://github.com/icl-utk-edu/blaspp.git \ + -Duse_openmp=OFF \ + -Dbuild_tests=OFF \ + -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + -DCMAKE_VERBOSE_MAKEFILE=ON + +cmake-easyinstall \ + --prefix=/usr/local \ + git+https://github.com/icl-utk-edu/lapackpp.git \ + -Duse_cmake_find_lapack=ON \ + -Dbuild_tests=OFF \ + -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + -DCMAKE_VERBOSE_MAKEFILE=ON diff --git a/.github/workflows/dependencies/hip.sh b/.github/workflows/dependencies/hip.sh index ae897786acd..2a1b4d090bc 100755 --- a/.github/workflows/dependencies/hip.sh +++ b/.github/workflows/dependencies/hip.sh @@ -65,6 +65,13 @@ source /etc/profile.d/rocm.sh hipcc --version which clang which clang++ +export CXX=$(which clang++) +export CC=$(which clang) + +# "mpic++ --showme" forgets open-pal in Ubuntu 20.04 + OpenMPI 4.0.3 +# https://bugs.launchpad.net/ubuntu/+source/openmpi/+bug/1941786 +# https://github.com/open-mpi/ompi/issues/9317 +export LDFLAGS="-lopen-pal" # cmake-easyinstall # @@ -72,3 +79,16 @@ sudo curl -L -o /usr/local/bin/cmake-easyinstall https://raw.githubusercontent.c sudo chmod a+x /usr/local/bin/cmake-easyinstall export CEI_SUDO="sudo" export CEI_TMP="/tmp/cei" + +# heFFTe +# +cmake-easyinstall --prefix=/usr/local \ + git+https://github.com/icl-utk-edu/heffte.git@v2.4.0 \ + -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + -DCMAKE_CXX_STANDARD=17 -DHeffte_ENABLE_DOXYGEN=OFF \ + -DHeffte_ENABLE_FFTW=OFF -DHeffte_ENABLE_TESTING=OFF \ + -DHeffte_ENABLE_CUDA=OFF -DHeffte_ENABLE_ROCM=ON \ + -DHeffte_ENABLE_ONEAPI=OFF -DHeffte_ENABLE_MKL=OFF \ + -DHeffte_ENABLE_PYTHON=OFF -DHeffte_ENABLE_FORTRAN=OFF \ + -DHeffte_ENABLE_MAGMA=OFF \ + -DCMAKE_VERBOSE_MAKEFILE=ON diff --git a/.github/workflows/hip.yml b/.github/workflows/hip.yml index 0f6710b1405..ba537e776d4 100644 --- a/.github/workflows/hip.yml +++ b/.github/workflows/hip.yml @@ -55,7 +55,8 @@ jobs: -DWarpX_MPI=ON \ -DWarpX_OPENPMD=ON \ -DWarpX_PRECISION=SINGLE \ - -DWarpX_FFT=ON + -DWarpX_FFT=ON \ + -DWarpX_HEFFTE=ON cmake --build build_sp -j 4 export WARPX_MPI=OFF @@ -115,7 +116,8 @@ jobs: -DWarpX_MPI=ON \ -DWarpX_OPENPMD=ON \ -DWarpX_PRECISION=DOUBLE \ - -DWarpX_FFT=ON + -DWarpX_FFT=ON \ + -DWarpX_HEFFTE=ON cmake --build build_2d -j 4 export WARPX_MPI=OFF @@ -125,18 +127,3 @@ jobs: ccache -s du -hs ~/.cache/ccache - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 diff --git a/.github/workflows/insitu.yml b/.github/workflows/insitu.yml index 42923d3df8e..35f16842935 100644 --- a/.github/workflows/insitu.yml +++ b/.github/workflows/insitu.yml @@ -17,10 +17,13 @@ jobs: CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code -Wno-error=pass-failed" CMAKE_GENERATOR: Ninja CMAKE_PREFIX_PATH: /root/install/sensei/v4.0.0/lib64/cmake + OMP_NUM_THREADS: 1 container: image: senseiinsitu/ci:fedora35-amrex-20220613 steps: - uses: actions/checkout@v4 + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v2 - name: Configure run: | cmake -S . -B build \ @@ -38,6 +41,7 @@ jobs: CXX: g++ CC: gcc CMAKE_PREFIX_PATH: /ascent/install/lib/cmake/ + OMP_NUM_THREADS: 1 container: image: alpinedav/ascent:0.9.2 steps: @@ -54,10 +58,10 @@ jobs: cmake --build build -j 4 - name: Test run: | - cp Examples/Physics_applications/laser_acceleration/inputs_3d . + cp Examples/Physics_applications/laser_acceleration/inputs_base_3d . cp Examples/Physics_applications/laser_acceleration/3d_ascent_actions.yaml ascent_actions.yaml mpiexec -n 2 ./build/bin/warpx.3d \ - inputs_3d \ + inputs_base_3d \ max_step = 40 \ diag1.intervals = 30:40:10 \ diag1.format = ascent @@ -68,3 +72,58 @@ jobs: *.png conduit_* if-no-files-found: error + + catalyst: + name: Catalyst + runs-on: ubuntu-22.04 + if: github.event.pull_request.draft == false + env: + CXX: g++ + CC: gcc + CMAKE_PREFIX_PATH: "/opt/conduit:/opt/catalyst" + CATALYST_DEBUG: 1 + CATALYST_IMPLEMENTATION_PATHS: /opt/paraview/lib/catalyst + OMP_NUM_THREADS: 1 + + # Container build scripts: + # https://gitlab.kitware.com/christos.tsolakis/catalyst-amrex-docker-images + container: + image: kitware/paraview:ci-catalyst-amrex-warpx-20240828 + steps: + - uses: actions/checkout@v4 + - name: Configure + run: | + cmake -S . -B build \ + -DWarpX_DIMS="2;3" \ + -DWarpX_CATALYST=ON + - name: Build + run: | + cmake --build build -j 10 + - name: 2D Test + run: | + cp Examples/Tests/field_ionization/inputs_test_2d_ionization_lab . + cp Examples/Tests/field_ionization/catalyst_pipeline.py . + mpiexec -n 2 ./build/bin/warpx.2d \ + inputs_test_2d_ionization_lab \ + catalyst.script_paths = catalyst_pipeline.py\ + catalyst.implementation = paraview\ + diag1.intervals = 16\ + diag1.species = "electrons ions"\ + diag1.format = catalyst + - name: 3D Test + run: | + cp Examples/Tests/electrostatic_sphere/inputs_base_3d . + cp Examples/Tests/electrostatic_sphere/catalyst_pipeline.py . + mpiexec -n 2 ./build/bin/warpx.3d \ + inputs_base_3d \ + catalyst.script_paths = catalyst_pipeline.py \ + catalyst.implementation = paraview \ + diagnostics.diags_names = diag1 \ + diag1.format = catalyst\ + diag1.intervals = 3 + - uses: actions/upload-artifact@v4 + with: + name: catalyst-test-artifacts + path: | + datasets/*.png + if-no-files-found: error diff --git a/.github/workflows/intel.yml b/.github/workflows/intel.yml index 3b1d6b546a4..4d0b9ebe9c6 100644 --- a/.github/workflows/intel.yml +++ b/.github/workflows/intel.yml @@ -115,7 +115,7 @@ jobs: cmake -S . -B build_sp \ -DCMAKE_CXX_FLAGS_RELEASE="-O1 -DNDEBUG" \ -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DWarpX_EB=ON \ + -DWarpX_EB=OFF \ -DWarpX_PYTHON=ON \ -DWarpX_MPI=OFF \ -DWarpX_OPENPMD=ON \ @@ -132,7 +132,7 @@ jobs: source /opt/intel/oneapi/setvars.sh set -e export OMP_NUM_THREADS=2 - Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py + Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_picmi.py build_dpcc: name: oneAPI DPC++ SP @@ -194,18 +194,3 @@ jobs: # python3 -m pip install --upgrade build packaging setuptools wheel # PYWARPX_LIB_DIR=$PWD/build_sp/lib/site-packages/pywarpx/ python3 -m pip wheel . # python3 -m pip install *.whl - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 00ac8f06b5d..596920a3911 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -60,7 +60,7 @@ jobs: cmake -S . -B build_dp \ -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DWarpX_EB=ON \ + -DWarpX_EB=OFF \ -DWarpX_OPENPMD=ON \ -DWarpX_openpmd_internal=OFF cmake --build build_dp -j 3 @@ -68,7 +68,7 @@ jobs: cmake -S . -B build_sp \ -DCMAKE_VERBOSE_MAKEFILE=ON \ -DPython_EXECUTABLE=$(which python3) \ - -DWarpX_EB=ON \ + -DWarpX_EB=OFF \ -DWarpX_PYTHON=ON \ -DWarpX_OPENPMD=ON \ -DWarpX_openpmd_internal=OFF \ @@ -84,19 +84,4 @@ jobs: source py-venv/bin/activate export OMP_NUM_THREADS=1 - mpirun -n 2 Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 + mpirun -n 2 Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_picmi.py diff --git a/.github/workflows/post-pr.yml b/.github/workflows/post-pr.yml index 2768ef376cc..5f0b1534970 100644 --- a/.github/workflows/post-pr.yml +++ b/.github/workflows/post-pr.yml @@ -4,17 +4,13 @@ on: types: - closed +# This workflow does not have the permission to clean up cache for PRs +# originated from a fork. The purpose here is to trigger a workflow_run +# cleanup-cache-postpr.yml that has the right permission. + jobs: - cleanup: + noop: runs-on: ubuntu-latest steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 + - name: No OP + run: echo "This workflow is going to trigger CleanUpCachePostPR." diff --git a/.github/workflows/scripts/checkQEDTableGenerator.sh b/.github/workflows/scripts/checkQEDTableGenerator.sh index e14a7a2d6f2..a773015c6c7 100755 --- a/.github/workflows/scripts/checkQEDTableGenerator.sh +++ b/.github/workflows/scripts/checkQEDTableGenerator.sh @@ -29,7 +29,7 @@ export OMP_NUM_THREADS=2 # Generate QED lookup tables using WarpX # ./build/bin/warpx.2d \ - ./Examples/Tests/qed/quantum_synchrotron/inputs_2d \ + ./Examples/Tests/qed/inputs_test_2d_qed_quantum_sync \ qed_bw.lookup_table_mode = "generate" \ qed_bw.tab_dndt_chi_min = 0.01 \ qed_bw.tab_dndt_chi_max = 100.0 \ @@ -70,7 +70,7 @@ diff qs_table_dndt qs_table_tool_dndt # Run a WarpX simulation using the lookup tables generated by the external tool # ./build/bin/warpx.2d \ - ./Examples/Tests/qed/quantum_synchrotron/inputs_2d \ + ./Examples/Tests/qed/inputs_test_2d_qed_quantum_sync \ qed_bw.lookup_table_mode = "load" \ qed_bw.load_table_from = "bw_table_tool" \ qed_qs.lookup_table_mode = "load" \ diff --git a/.github/workflows/source.yml b/.github/workflows/source.yml index a1c29416b3e..7a2086cfdff 100644 --- a/.github/workflows/source.yml +++ b/.github/workflows/source.yml @@ -25,12 +25,8 @@ jobs: run: .github/workflows/source/hasTabs - name: End-of-Line whitespaces run: .github/workflows/source/hasEOLwhiteSpace - - name: Proper file names in Examples - run: .github/workflows/source/wrongFileNameInExamples - - name: Examples are tested - run: .github/workflows/source/inputsNotTested - - name: Check that the test matrix for CI includes all tests - run: .github/workflows/source/test_ci_matrix.sh + - name: Check test input files + run: .github/workflows/source/check_inputs.py - name: Doxygen run: | sudo apt-get install -y --no-install-recommends doxygen diff --git a/.github/workflows/source/check_inputs.py b/.github/workflows/source/check_inputs.py new file mode 100755 index 00000000000..84ea70cba60 --- /dev/null +++ b/.github/workflows/source/check_inputs.py @@ -0,0 +1,109 @@ +#! /usr/bin/env python3 + +import os +import re +import sys + +# mandatory prefixes for test names +testname_prefix = ["test_1d_", "test_2d_", "test_3d_", "test_rz_"] + +# collect all test names and test input filenames from CMakeLists.txt files +tests = [] +# walk through all files under Examples/, including subdirectories +for dirpath, dirnames, filenames in os.walk(top="./Examples"): + # loop over CMakeLists.txt files + for name in [filename for filename in filenames if filename == "CMakeLists.txt"]: + filepath = os.path.join(dirpath, name) + # open CMakeLists.txt file + with open(filepath) as f: + # loop over lines of CMakeLists.txt + for line in f: + # strip leading whitespaces + line = line.lstrip() + # find lines where 'add_warpx_test' is called + if re.match("add_warpx_test", line): + # strip leading whitespaces, remove end-of-line comments + testname = next(f).lstrip().split(" ")[0] + # skip lines related to other function arguments + # NOTE: update range call to reflect changes + # in the interface of 'add_warpx_test' + for _ in range(2): # skip over: dims, nprocs + next(f) + # strip leading whitespaces, remove end-of-line comments + testinput = next(f).lstrip().split(" ")[0] + # some Python input scripts are quoted + # to account for command-line arguments: + # strip initial quotation mark from string + if testinput.startswith('"'): + testinput = re.sub('"', "", testinput) + # extract filename from path + testinput = os.path.split(testinput)[1] + tests.append( + {"name": testname, "input": testinput, "path": filepath} + ) + +# check consistency of test names and test input filenames +print("\nCheck that test names and input names are correct...") +wrong_testname = False +wrong_testinput = False +for test in tests: + testname = test["name"].rstrip() + testinput = test["input"].rstrip() + testpath = test["path"].rstrip() + if not testname.startswith(tuple(testname_prefix)): + print(f"Wrong test name: {testname}") + print(f"(from {testpath})") + wrong_testname = True + # PICMI tests + if "picmi" in testname: + if not testname.endswith("_picmi") and not testname.endswith("_picmi_restart"): + print(f"Wrong test name: {testname}") + print(f"(from {testpath})") + wrong_testname = True + # restart tests + if "restart" in testname: + if not testname.endswith("_restart"): + print(f"Wrong test name: {testname}") + print(f"(from {testpath})") + wrong_testname = True + # test input file names + if ( + not testinput == f"inputs_{testname}" + and not testinput == f"inputs_{testname}.py" + ): + # we may be running a base input file/script or a restart PICMI test + if not testinput.startswith("inputs_base") and not testinput.endswith( + "_picmi.py" + ): + print(f"Wrong input name: {testinput}") + print(f"(from {testpath})") + wrong_testinput = True + +if wrong_testname: + print(f"NOTE: Test names must start with one of {testname_prefix}.") + print(" Test names must end with '_restart' for restart tests.") + print(" Test names must end with '_picmi' for PICMI tests.") +if wrong_testinput: + print("NOTE: Test input names must start with 'inputs_' followed by the test name.") + print(" Test input names must end with '.py' for PICMI tests.") + +# check that all input files in Examples/ are tested +print("\nCheck that all test input files are tested...") +missing_input = False +# walk through all files under Examples/, including subdirectories +for dirpath, dirnames, filenames in os.walk(top="./Examples"): + # loop over files starting with "inputs_test_" + for name in [ + filename for filename in filenames if filename.startswith("inputs_test_") + ]: + if name not in [test["input"] for test in tests]: + print(f"Input not tested: {os.path.join(dirpath, name)}") + missing_input = True + +if missing_input: + print("NOTE: All test input files must be tested.\n") +else: + print() + +if wrong_testname or wrong_testinput or missing_input: + sys.exit("FAILED\n") diff --git a/.github/workflows/source/ci_matrix.py b/.github/workflows/source/ci_matrix.py deleted file mode 100644 index 79f4d878c5d..00000000000 --- a/.github/workflows/source/ci_matrix.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python - -# Concatenation of tests in each of the 6 elements in CI matrix -f = open('./ci_matrix_elements.txt') ; matrix_elements = f.readlines() ; f.close() -# All tests read by prepare_file_ci.py -f = open('./ci_all_tests.txt') ; all_tests = f.readlines() ; f.close() - -# Now let's make sure these two are equal - -# Remove these elements from both lists, as they are are not test names -elements_to_remove = ['[main]\n', '[AMReX]\n', '[source]\n', '[extra-PICSAR]\n'] -for element in elements_to_remove: - for x in range(matrix_elements.count(element)): - matrix_elements.remove(element) - for x in range(all_tests.count(element)): - all_tests.remove(element) - -# Sort lists, and make sure they are equal -matrix_elements.sort() -all_tests.sort() -print("Tests in matrix, but not in initial list (typically if a test is done twice):") -print(list(set(matrix_elements) - set(all_tests))) -print("Tests in initial list but not in the matrix:") -print(list(set(all_tests) - set(matrix_elements))) - -assert( matrix_elements == all_tests ) diff --git a/.github/workflows/source/inputsNotTested b/.github/workflows/source/inputsNotTested deleted file mode 100755 index 497d322a610..00000000000 --- a/.github/workflows/source/inputsNotTested +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -# Search input files in Examples/ and verify if all input files are tested - -set -eu -o pipefail - -ok=0 - -for file in $(find Examples -type f) -do - # Name of file without path - filename=$(basename $file) - # If file is an input file - if [[ ${filename:0:6 } =~ inputs ]] || - [[ ${filename:0:12} =~ PICMI_inputs ]] - then - cr=$'$' - file_cr="$file$cr" - # Search file name in test list - string_match=$(grep -m1 "$file_cr" Regression/WarpX-tests.ini || echo "") - # If match is empty, inputs examples is not tested - if [[ -z $string_match ]] - then - echo "$file is not tested!" - ok=1 - fi - fi -done - -if [ $ok -ne 0 ] -then - echo "" - echo "All files in Examples that start with one of" - echo " - inputs" - echo " - PICMI_inputs" - echo "must have an automated test." - echo "Please add a test in Regression/WarpX-tests.ini" - echo "for all files listed above." -fi - -exit $ok diff --git a/.github/workflows/source/makeMakefileForClangTidy.py b/.github/workflows/source/makeMakefileForClangTidy.py index 07809187dbd..13460b9e548 100755 --- a/.github/workflows/source/makeMakefileForClangTidy.py +++ b/.github/workflows/source/makeMakefileForClangTidy.py @@ -14,40 +14,49 @@ def makeMakefileForClangTidy(argv): parser = argparse.ArgumentParser() - parser.add_argument("--input", - help="Ccache log file", - default="ccache.log.txt") - parser.add_argument("--identifier", - help="Unique identifier for finding compilation line in the log file", - default="WarpX/Source") + parser.add_argument("--input", help="Ccache log file", default="ccache.log.txt") + parser.add_argument( + "--identifier", + help="Unique identifier for finding compilation line in the log file", + default="WarpX/Source", + ) # We assume WarpX/Source can be used as an identifier to distinguish # WarpX code from amrex, openMPD, and cmake's temporary files like # build/CMakeFiles/CMakeScratch/TryCompile-hw3x4m/test_mpi.cpp - parser.add_argument("--output", - help="Make file for clang-tidy", - default="clang-tidy-ccache-misses.mak") + parser.add_argument( + "--output", + help="Make file for clang-tidy", + default="clang-tidy-ccache-misses.mak", + ) args = parser.parse_args() fin = open(args.input, "r") fout = open(args.output, "w") fout.write("CLANG_TIDY ?= clang-tidy\n") - fout.write("override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++\n") + fout.write( + "override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++\n" + ) fout.write("\n") fout.write(".SECONDEXPANSION:\n") fout.write("clang-tidy: $$(all_targets)\n") fout.write("\t@echo SUCCESS\n\n") - exe_re = re.compile(r" Executing .*? (-.*{}.*) -c .* -o .* (\S*)".format(args.identifier)) + exe_re = re.compile( + r" Executing .*? (-.*{}.*) -c .* -o .* (\S*)".format(args.identifier) + ) count = 0 for line in fin.readlines(): ret_exe_re = exe_re.search(line) - if (ret_exe_re): + if ret_exe_re: fout.write("target_{}: {}\n".format(count, ret_exe_re.group(2))) - fout.write("\t$(CLANG_TIDY) $(CLANG_TIDY_ARGS) $< -- {}\n".format - (ret_exe_re.group(1))) + fout.write( + "\t$(CLANG_TIDY) $(CLANG_TIDY_ARGS) $< -- {}\n".format( + ret_exe_re.group(1) + ) + ) fout.write("\ttouch target_{}\n\n".format(count)) count = count + 1 @@ -61,5 +70,6 @@ def makeMakefileForClangTidy(argv): fout.close() fin.close() + if __name__ == "__main__": makeMakefileForClangTidy(sys.argv) diff --git a/.github/workflows/source/test_ci_matrix.sh b/.github/workflows/source/test_ci_matrix.sh deleted file mode 100755 index 62903b66e45..00000000000 --- a/.github/workflows/source/test_ci_matrix.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -set -eu -o pipefail - -cp .github/workflows/source/ci_matrix.py Regression/ -cd Regression/ - -# Put the name of all CI tests into a text file -python prepare_file_ci.py -grep "^\[" ci-tests.ini > ci_all_tests.txt - - -export WARPX_CI_PSATD=TRUE - -# Concatenate the names of all elements in CI matrix into another test file -WARPX_CI_REGULAR_CARTESIAN_1D=TRUE python prepare_file_ci.py -grep "^\[" ci-tests.ini > ci_matrix_elements.txt -WARPX_CI_REGULAR_CARTESIAN_2D=TRUE python prepare_file_ci.py -grep "^\[" ci-tests.ini >> ci_matrix_elements.txt -WARPX_CI_REGULAR_CARTESIAN_3D=TRUE python prepare_file_ci.py -grep "^\[" ci-tests.ini >> ci_matrix_elements.txt -WARPX_CI_SINGLE_PRECISION=TRUE python prepare_file_ci.py -grep "^\[" ci-tests.ini >> ci_matrix_elements.txt -WARPX_CI_RZ_OR_NOMPI=TRUE python prepare_file_ci.py -grep "^\[" ci-tests.ini >> ci_matrix_elements.txt -WARPX_CI_QED=TRUE python prepare_file_ci.py -grep "^\[" ci-tests.ini >> ci_matrix_elements.txt -WARPX_CI_EB=TRUE python prepare_file_ci.py -grep "^\[" ci-tests.ini >> ci_matrix_elements.txt - -# Check that the resulting lists are equal -{ - python ci_matrix.py && - rm ci_all_tests.txt ci_matrix_elements.txt ci_matrix.py && - echo "test passed" && - exit 0 -} || { - rm ci_all_tests.txt ci_matrix_elements.txt ci_matrix.py && - echo "tests failed" && - exit 1 -} diff --git a/.github/workflows/source/wrongFileNameInExamples b/.github/workflows/source/wrongFileNameInExamples deleted file mode 100755 index 0de69d69c9c..00000000000 --- a/.github/workflows/source/wrongFileNameInExamples +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# -# Search inside Examples/ and check that file names start with -# inputs -# PICMI_inputs -# analysis -# README - -set -eu -o pipefail - -ok=0 -files=() - -for pathtofile in $(find Examples -type f) -do - file=$(basename $pathtofile) - if [[ ${file:0:6 } != inputs ]] && - [[ ${file:0:12} != PICMI_inputs ]] && - [[ ${file:0:8 } != analysis ]] && - [[ ${file: -4} != yaml ]] && - [[ ${file:0:4 } != plot ]] && - [[ ${file:0:6 } != README ]] - then - files+=($file) - echo "$pathtofile does not have a proper name!" - ok=1 - fi -done - -if [ $ok -ne 0 ] -then - echo "" - echo "Files in Examples/ must start with one of:" - echo " - inputs : for WarpX input files" - echo " - PICMI_inputs : for PICMI-compliant input scripts" - echo " - analysis : for scripts testing the accuracy of a test" - echo " - *.yaml : for third-party input, e.g. Ascent in situ visualization" - echo " - README : for readme files" - echo "" - echo "Please rename the file(s) to comply, or move to another folder" -fi - -exit $ok diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 9f4953b7a98..68d2b2156e9 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -39,8 +39,8 @@ jobs: -DWarpX_MPI=OFF \ -DWarpX_QED=OFF cmake --build build -j 4 - ./build/bin/warpx.3d Examples/Physics_applications/laser_acceleration/inputs_3d - ./build/bin/warpx.rz Examples/Physics_applications/laser_acceleration/inputs_rz + ./build/bin/warpx.3d Examples/Physics_applications/laser_acceleration/inputs_base_3d + ./build/bin/warpx.rz Examples/Physics_applications/laser_acceleration/inputs_base_rz ccache -s du -hs ~/.cache/ccache @@ -82,8 +82,8 @@ jobs: -DWarpX_QED_TOOLS=ON cmake --build build -j 4 - ./build/bin/warpx.1d Examples/Physics_applications/laser_acceleration/inputs_1d - ./build/bin/warpx.2d Examples/Physics_applications/laser_acceleration/inputs_2d + ./build/bin/warpx.1d Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration + ./build/bin/warpx.2d Examples/Physics_applications/laser_acceleration/inputs_base_2d ccache -s du -hs ~/.cache/ccache @@ -133,8 +133,8 @@ jobs: -DWarpX_QED_TABLE_GEN=ON cmake --build build -j 4 - ./build/bin/warpx.3d Examples/Physics_applications/laser_acceleration/inputs_3d - ./build/bin/warpx.rz Examples/Physics_applications/laser_acceleration/inputs_rz + ./build/bin/warpx.3d Examples/Physics_applications/laser_acceleration/inputs_base_3d + ./build/bin/warpx.rz Examples/Physics_applications/laser_acceleration/inputs_base_rz ccache -s du -hs ~/.cache/ccache @@ -210,7 +210,6 @@ jobs: cmake -S . -B build \ -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DWarpX_APP=OFF \ -DWarpX_FFT=ON \ -DWarpX_PYTHON=ON \ -DWarpX_QED_TABLE_GEN=ON @@ -222,74 +221,4 @@ jobs: - name: run pywarpx run: | export OMP_NUM_THREADS=1 - mpirun -n 2 Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py - - build_UB_sanitizer: - name: Clang UB sanitizer - runs-on: ubuntu-22.04 - if: github.event.pull_request.draft == false - env: - CC: clang - CXX: clang++ - # On CI for this test, Ninja is slower than the default: - #CMAKE_GENERATOR: Ninja - steps: - - uses: actions/checkout@v4 - - name: install dependencies - run: | - .github/workflows/dependencies/clang15.sh - - name: CCache Cache - uses: actions/cache@v4 - with: - path: ~/.cache/ccache - key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} - restore-keys: | - ccache-${{ github.workflow }}-${{ github.job }}-git- - - name: build WarpX - run: | - export CCACHE_COMPRESS=1 - export CCACHE_COMPRESSLEVEL=10 - export CCACHE_MAXSIZE=100M - ccache -z - - export CXX=$(which clang++-15) - export CC=$(which clang-15) - export CXXFLAGS="-fsanitize=undefined -fno-sanitize-recover=all" - - cmake -S . -B build \ - -GNinja \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DWarpX_DIMS="RZ;1;2;3" \ - -DWarpX_FFT=ON \ - -DWarpX_QED=ON \ - -DWarpX_QED_TABLE_GEN=ON \ - -DWarpX_OPENPMD=ON \ - -DWarpX_PRECISION=SINGLE \ - -DWarpX_PARTICLE_PRECISION=SINGLE - cmake --build build -j 4 - - ccache -s - du -hs ~/.cache/ccache - - - name: run with UB sanitizer - run: | - export OMP_NUM_THREADS=2 - mpirun -n 2 ./build/bin/warpx.rz Examples/Physics_applications/laser_acceleration/inputs_rz - mpirun -n 2 ./build/bin/warpx.1d Examples/Physics_applications/laser_acceleration/inputs_1d - mpirun -n 2 ./build/bin/warpx.2d Examples/Physics_applications/laser_acceleration/inputs_2d - mpirun -n 2 ./build/bin/warpx.3d Examples/Physics_applications/laser_acceleration/inputs_3d - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 + mpirun -n 2 Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_picmi.py diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2ef74cdb7f9..d6030743524 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -54,7 +54,7 @@ jobs: run: | $env:PATH += ';C:/Program Files (x86)/WarpX/bin/' - python3 Examples\Tests\gaussian_beam\PICMI_inputs_gaussian_beam.py + python3 Examples/Tests/gaussian_beam/inputs_test_3d_gaussian_beam_picmi.py # JSON writes are currently very slow (50min) with MSVC # --diagformat=openpmd @@ -91,7 +91,7 @@ jobs: -DCMAKE_BUILD_TYPE=Release ^ -DCMAKE_VERBOSE_MAKEFILE=ON ^ -DWarpX_COMPUTE=OMP ^ - -DWarpX_EB=ON ^ + -DWarpX_EB=OFF ^ -DWarpX_PYTHON=ON ^ -DWarpX_MPI=OFF ^ -DWarpX_OPENPMD=ON @@ -118,5 +118,5 @@ jobs: call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\vc\Auxiliary\build\vcvarsall.bat" x64 set "PATH=C:/Program Files (x86)/WarpX/bin/;%PATH%" - python3 Examples\Tests\gaussian_beam\PICMI_inputs_gaussian_beam.py --diagformat=openpmd + python3 Examples/Tests/gaussian_beam/inputs_test_3d_gaussian_beam_picmi.py --diagformat=openpmd if errorlevel 1 exit 1 diff --git a/.gitignore b/.gitignore index 4fa65351331..094fee87efc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ Python/pywarpx/libwarpx*.so d/ f/ o/ -build/ +build*/ tmp_build_dir/ test_dir test_dir/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cef24aed2cc..1b668d5931e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -66,44 +66,16 @@ repos: # C++ formatting # clang-format -# Autoremoves unused Python imports -- repo: https://github.com/hadialqattan/pycln - rev: v2.4.0 +# Python: Ruff linter & formatter +# https://docs.astral.sh/ruff/ +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.5 hooks: - - id: pycln - name: pycln (python) - -# Sorts Python imports according to PEP8 -# https://www.python.org/dev/peps/pep-0008/#imports -- repo: https://github.com/pycqa/isort - rev: 5.13.2 - hooks: - - id: isort - name: isort (python) - args: ['--profile black'] - -# Python: Flake8 (checks only, does this support auto-fixes?) -#- repo: https://github.com/PyCQA/flake8 -# rev: 4.0.1 -# hooks: -# - id: flake8 -# additional_dependencies: &flake8_dependencies -# - flake8-bugbear -# - pep8-naming -# exclude: ^(docs/.*|tools/.*)$ -# Alternatively: use autopep8? - -# Python Formatting -#- repo: https://github.com/psf/black -# rev: 21.10b0 # Keep in sync with blacken-docs -# hooks: -# - id: black -#- repo: https://github.com/asottile/blacken-docs -# rev: v1.11.0 -# hooks: -# - id: blacken-docs -# additional_dependencies: -# - black==21.10b0 # keep in sync with black hook + # Run the linter + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + # Run the formatter + - id: ruff-format # Jupyter Notebooks: clean up all cell outputs - repo: https://github.com/roy-ht/pre-commit-jupyter diff --git a/.zenodo.json b/.zenodo.json index a2c9b443f99..d753e33d017 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -39,7 +39,7 @@ "name": "Blelly, Aurore" }, { - "affiliation": "Lawrence Livermore National Laboratory", + "affiliation": "Helion Energy, Inc.", "name": "Clark, Stephen Eric", "orcid": "0000-0002-0117-776X" }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c81a057131..3b4e9199f53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Preamble #################################################################### # -cmake_minimum_required(VERSION 3.20.0) -project(WarpX VERSION 24.07) +cmake_minimum_required(VERSION 3.24.0) +project(WarpX VERSION 24.09) include(${WarpX_SOURCE_DIR}/cmake/WarpXFunctions.cmake) @@ -29,13 +29,6 @@ if(POLICY CMP0104) cmake_policy(SET CMP0104 OLD) endif() -# We use simple syntax in cmake_dependent_option, so we are compatible with the -# extended syntax in CMake 3.22+ -# https://cmake.org/cmake/help/v3.22/policy/CMP0127.html -if(POLICY CMP0127) - cmake_policy(SET CMP0127 NEW) -endif() - # C++ Standard in Superbuilds ################################################# # @@ -74,7 +67,8 @@ set_default_install_dirs() include(CMakeDependentOption) option(WarpX_APP "Build the WarpX executable application" ON) option(WarpX_ASCENT "Ascent in situ diagnostics" OFF) -option(WarpX_EB "Embedded boundary support" OFF) +option(WarpX_CATALYST "Catalyst in situ diagnostics" OFF) +option(WarpX_EB "Embedded boundary support" ON) option(WarpX_LIB "Build WarpX as a library" OFF) option(WarpX_MPI "Multi-node support (message-passing)" ON) option(WarpX_OPENPMD "openPMD I/O (HDF5, ADIOS)" ON) @@ -88,6 +82,14 @@ option(WarpX_QED_TABLE_GEN "QED table generation (requires PICSAR and Boost)" option(WarpX_QED_TOOLS "Build external tool to generate QED lookup tables (requires PICSAR and Boost)" OFF) +# Advanced option to automatically clean up CI test directories +option(WarpX_TEST_CLEANUP "Clean up CI test directories" OFF) +mark_as_advanced(WarpX_TEST_CLEANUP) + +# Advanced option to run CI tests with FPE-trapping runtime parameters +option(WarpX_TEST_FPETRAP "Run CI tests with FPE-trapping runtime parameters" OFF) +mark_as_advanced(WarpX_TEST_FPETRAP) + set(WarpX_DIMS_VALUES 1 2 3 RZ) set(WarpX_DIMS 3 CACHE STRING "Simulation dimensionality <1;2;3;RZ>") list(REMOVE_DUPLICATES WarpX_DIMS) @@ -194,7 +196,7 @@ if(WarpX_HEFFTE) endif() # this defined the variable BUILD_TESTING which is ON by default -#include(CTest) +include(CTest) # Dependencies ################################################################ @@ -711,7 +713,9 @@ endforeach() # pip helpers for the pywarpx package ######################################### # if(WarpX_PYTHON) - set(PYINSTALLOPTIONS "" CACHE STRING + set(PY_PIP_OPTIONS "-v" CACHE STRING + "Additional parameters to pass to `pip`") + set(PY_PIP_INSTALL_OPTIONS "" CACHE STRING "Additional parameters to pass to `pip install`") # ensure all targets are built before we package them in a wheel @@ -735,7 +739,7 @@ if(WarpX_PYTHON) ${CMAKE_COMMAND} -E rm -f -r warpx-whl COMMAND ${CMAKE_COMMAND} -E env PYWARPX_LIB_DIR=$ - ${Python_EXECUTABLE} -m pip wheel -v --no-build-isolation --no-deps --wheel-dir=warpx-whl ${WarpX_SOURCE_DIR} + ${Python_EXECUTABLE} -m pip ${PY_PIP_OPTIONS} wheel --no-build-isolation --no-deps --wheel-dir=warpx-whl ${WarpX_SOURCE_DIR} WORKING_DIRECTORY ${WarpX_BINARY_DIR} DEPENDS @@ -749,7 +753,7 @@ if(WarpX_PYTHON) set(pyWarpX_REQUIREMENT_FILE "requirements.txt") endif() add_custom_target(${WarpX_CUSTOM_TARGET_PREFIX}pip_install_requirements - ${Python_EXECUTABLE} -m pip install ${PYINSTALLOPTIONS} -r "${WarpX_SOURCE_DIR}/${pyWarpX_REQUIREMENT_FILE}" + ${Python_EXECUTABLE} -m pip ${PY_PIP_OPTIONS} install ${PY_PIP_INSTALL_OPTIONS} -r "${WarpX_SOURCE_DIR}/${pyWarpX_REQUIREMENT_FILE}" WORKING_DIRECTORY ${WarpX_BINARY_DIR} ) @@ -766,7 +770,7 @@ if(WarpX_PYTHON) # because otherwise pip would also force reinstall all dependencies. add_custom_target(${WarpX_CUSTOM_TARGET_PREFIX}pip_install ${CMAKE_COMMAND} -E env WARPX_MPI=${WarpX_MPI} - ${Python_EXECUTABLE} -m pip install --force-reinstall --no-index --no-deps ${PYINSTALLOPTIONS} --find-links=warpx-whl pywarpx + ${Python_EXECUTABLE} -m pip ${PY_PIP_OPTIONS} install --force-reinstall --no-index --no-deps ${PY_PIP_INSTALL_OPTIONS} --find-links=warpx-whl pywarpx WORKING_DIRECTORY ${WarpX_BINARY_DIR} DEPENDS @@ -779,7 +783,7 @@ if(WarpX_PYTHON) # this is for package managers only add_custom_target(${WarpX_CUSTOM_TARGET_PREFIX}pip_install_nodeps ${CMAKE_COMMAND} -E env WARPX_MPI=${WarpX_MPI} - ${Python_EXECUTABLE} -m pip install --force-reinstall --no-index --no-deps ${PYINSTALLOPTIONS} --find-links=warpx-whl pywarpx + ${Python_EXECUTABLE} -m pip ${PY_PIP_OPTIONS} install --force-reinstall --no-index --no-deps ${PY_PIP_INSTALL_OPTIONS} --find-links=warpx-whl pywarpx WORKING_DIRECTORY ${WarpX_BINARY_DIR} DEPENDS @@ -791,12 +795,12 @@ endif() # Tests ####################################################################### # - -#if(BUILD_TESTING) -# enable_testing() -# -# add_test(...) -#endif() +if(BUILD_TESTING) + enable_testing() + if(WarpX_APP OR WarpX_PYTHON) + add_subdirectory(Examples) + endif() +endif() # Status Summary for Build Options ############################################ diff --git a/Docs/requirements.txt b/Docs/requirements.txt index 1ce1ee6c1a0..a8c2af0e474 100644 --- a/Docs/requirements.txt +++ b/Docs/requirements.txt @@ -13,7 +13,7 @@ openpmd-viewer # for checksumAPI # PICMI API docs # note: keep in sync with version in ../requirements.txt -picmistandard==0.29.0 +picmistandard==0.30.0 # for development against an unreleased PICMI version, use: # picmistandard @ git+https://github.com/picmi-standard/picmi.git#subdirectory=PICMI_Python diff --git a/Docs/source/acknowledge_us.rst b/Docs/source/acknowledge_us.rst index b01ebf00a39..8c9b8dcf15c 100644 --- a/Docs/source/acknowledge_us.rst +++ b/Docs/source/acknowledge_us.rst @@ -53,6 +53,11 @@ Prior WarpX references If your project uses a specific algorithm or component, please consider citing the respective publications in addition. +- Shapoval O, Zoni E, Lehe R, Thévenet M, and Vay J-L. + **Pseudospectral particle-in-cell formulation with arbitrary charge and current-density time dependencies for the modeling of relativistic plasmas**. + Physical Review E **110**, 025206, 2024. + `DOI:10.1103/PhysRevE.110.025206 `__ + - Sandberg R T, Lehe R, Mitchell C E, Garten M, Myers A, Qiang J, Vay J-L and Huebl A. **Synthesizing Particle-in-Cell Simulations Through Learning and GPU Computing for Hybrid Particle Accelerator Beamlines**. Proc. of Platform for Advanced Scientific Computing (PASC'24), *PASC24 Best Paper Award*, 2024. diff --git a/Docs/source/acknowledgements.rst b/Docs/source/acknowledgements.rst index 14877839294..6d2529705d0 100644 --- a/Docs/source/acknowledgements.rst +++ b/Docs/source/acknowledgements.rst @@ -3,13 +3,18 @@ Funding and Acknowledgements ============================ -WarpX is supported by the Exascale Computing Project (17-SC-20-SC), a collaborative effort of two U.S. Department of Energy organizations (Office of Science and the National Nuclear Security Administration) responsible for the planning and preparation of a capable exascale ecosystem, including software, applications, hardware, advanced system engineering, and early testbed platforms, in support of the nation's exascale computing imperative. +WarpX is hosted by the High Performance Computing Foundation (HPSF). +If your organization wants to help steer the evolution of the HPC software ecosystem, visit `hpsf.io `__ and consider joining! WarpX is supported by the CAMPA collaboration, a project of the U.S. Department of Energy, Office of Science, Office of Advanced Scientific Computing Research and Office of High Energy Physics, Scientific Discovery through Advanced Computing (SciDAC) program. -ABLASTR seed development is supported by the Laboratory Directed Research and Development Program of Lawrence Berkeley National Laboratory under U.S. Department of Energy Contract No. DE-AC02-05CH11231. +WarpX is supported by the KISMET project, a project of the U.S. Department of Energy, Office of Science, Office of Advanced Scientific Computing Research and Office of Fusion Energy Science, Scientific Discovery through Advanced Computing (SciDAC) program. CEA-LIDYL actively contributes to the co-development of WarpX. As part of this initiative, WarpX also receives funding from the French National Research Agency (ANR - Plasm-On-Chip), the Horizon H2020 program and CEA. +WarpX was supported by the Exascale Computing Project (17-SC-20-SC), a collaborative effort of two U.S. Department of Energy organizations (Office of Science and the National Nuclear Security Administration) responsible for the planning and preparation of a capable exascale ecosystem, including software, applications, hardware, advanced system engineering, and early testbed platforms, in support of the nation's exascale computing imperative. + +ABLASTR seed development was supported by the Laboratory Directed Research and Development Program of Lawrence Berkeley National Laboratory under U.S. Department of Energy Contract No. DE-AC02-05CH11231. + We acknowledge all the contributors and users of the WarpX community who participate to the code quality with valuable code improvement and important feedback. diff --git a/Docs/source/conf.py b/Docs/source/conf.py index 7997b1e338c..9dfda6346f9 100644 --- a/Docs/source/conf.py +++ b/Docs/source/conf.py @@ -31,10 +31,12 @@ import urllib.request import pybtex.plugin -import sphinx_rtd_theme +import sphinx_rtd_theme # noqa from pybtex.style.formatting.unsrt import Style as UnsrtStyle -sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../Regression/Checksum')) +module_path = os.path.dirname(os.path.abspath(__file__)) +checksum_path = os.path.join(module_path, "../../Regression/Checksum") +sys.path.insert(0, checksum_path) # -- General configuration ------------------------------------------------ @@ -46,21 +48,22 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.mathjax', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'sphinx_copybutton', - 'sphinx_design', - 'breathe', - 'sphinxcontrib.bibtex' - ] + "sphinx.ext.autodoc", + "sphinx.ext.mathjax", + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", + "sphinx_copybutton", + "sphinx_design", + "breathe", + "sphinxcontrib.bibtex", +] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # Relative path to bibliography file, bibliography style -bibtex_bibfiles = ['latex_theory/allbibs.bib', 'refs.bib'] +bibtex_bibfiles = ["latex_theory/allbibs.bib", "refs.bib"] + # An brief introduction to custom BibTex formatting can be found in the Sphinx documentation: # https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#bibtex-custom-formatting @@ -77,42 +80,43 @@ def __init__(self, *args, **kwargs): # This option makes the given names of an author abbreviated to just initials. # Example: "Jean-Luc" becomes "J.-L." # Set 'abbreviate_names' to True before calling the superclass (BaseStyle class) initializer - kwargs['abbreviate_names'] = True + kwargs["abbreviate_names"] = True super().__init__(*args, **kwargs) -pybtex.plugin.register_plugin('pybtex.style.formatting', 'warpxbibstyle', WarpXBibStyle) -bibtex_default_style = 'warpxbibstyle' +pybtex.plugin.register_plugin("pybtex.style.formatting", "warpxbibstyle", WarpXBibStyle) + +bibtex_default_style = "warpxbibstyle" # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'WarpX' -copyright = '2017-2021, WarpX collaboration' -author = 'WarpX collaboration' +project = "WarpX" +copyright = "2017-2021, WarpX collaboration" +author = "WarpX collaboration" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'24.07' +version = "24.08" # The full version, including alpha/beta/rc tags. -release = u'24.07' +release = "24.08" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = 'en' +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -120,7 +124,7 @@ def __init__(self, *args, **kwargs): exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -131,14 +135,16 @@ def __init__(self, *args, **kwargs): # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" numfig = True math_eqref_format = "{number}" -numfig_format = {'figure': 'Fig. %s', - 'table': 'Table %s', - 'code-block': 'Listing %s', - 'section': 'Section %s'} +numfig_format = { + "figure": "Fig. %s", + "table": "Table %s", + "code-block": "Listing %s", + "section": "Section %s", +} # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -149,16 +155,16 @@ def __init__(self, *args, **kwargs): # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] html_css_files = [ - 'custom.css', + "custom.css", ] # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. -htmlhelp_basename = 'WarpXdoc' +htmlhelp_basename = "WarpXdoc" # -- Options for LaTeX output --------------------------------------------- @@ -167,15 +173,12 @@ def __init__(self, *args, **kwargs): # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # # 'preamble': '', - # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -185,8 +188,7 @@ def __init__(self, *args, **kwargs): # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'WarpX.tex', 'WarpX Documentation', - 'WarpX collaboration', 'manual'), + (master_doc, "WarpX.tex", "WarpX Documentation", "WarpX collaboration", "manual"), ] @@ -194,10 +196,7 @@ def __init__(self, *args, **kwargs): # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'warpx', 'WarpX Documentation', - [author], 1) -] +man_pages = [(master_doc, "warpx", "WarpX Documentation", [author], 1)] # -- Options for Texinfo output ------------------------------------------- @@ -206,40 +205,44 @@ def __init__(self, *args, **kwargs): # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'WarpX', 'WarpX Documentation', - author, 'WarpX', 'WarpX is an advanced electromagnetic Particle-In-Cell code.', - 'Miscellaneous'), + ( + master_doc, + "WarpX", + "WarpX Documentation", + author, + "WarpX", + "WarpX is an advanced electromagnetic Particle-In-Cell code.", + "Miscellaneous", + ), ] - - # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://amrex-codes.github.io/': None} +intersphinx_mapping = {"https://amrex-codes.github.io/": None} # Setup the breathe extension -breathe_projects = { - "WarpX": "../doxyxml/" -} +breathe_projects = {"WarpX": "../doxyxml/"} breathe_default_project = "WarpX" # Tell sphinx what the primary language being documented is. -primary_domain = 'cpp' +primary_domain = "cpp" # Tell sphinx what the pygments highlight language should be. -highlight_language = 'cpp' +highlight_language = "cpp" # Download AMReX & openPMD-api Doxygen Tagfile to interlink Doxygen docs -url = 'https://amrex-codes.github.io/amrex/docs_xml/doxygen/amrex-doxygen-web.tag.xml' -urllib.request.urlretrieve(url, '../amrex-doxygen-web.tag.xml') +url = "https://amrex-codes.github.io/amrex/docs_xml/doxygen/amrex-doxygen-web.tag.xml" +urllib.request.urlretrieve(url, "../amrex-doxygen-web.tag.xml") -url = 'https://openpmd-api.readthedocs.io/en/latest/_static/doxyhtml/openpmd-api-doxygen-web.tag.xml' -urllib.request.urlretrieve(url, '../openpmd-api-doxygen-web.tag.xml') +url = "https://openpmd-api.readthedocs.io/en/latest/_static/doxyhtml/openpmd-api-doxygen-web.tag.xml" +urllib.request.urlretrieve(url, "../openpmd-api-doxygen-web.tag.xml") # Build Doxygen -subprocess.call('cd ../; doxygen;' - 'mkdir -p source/_static;' - 'cp -r doxyhtml source/_static/;' - 'cp warpx-doxygen-web.tag.xml source/_static/doxyhtml/', - shell=True) +subprocess.call( + "cd ../; doxygen;" + "mkdir -p source/_static;" + "cp -r doxyhtml source/_static/;" + "cp warpx-doxygen-web.tag.xml source/_static/doxyhtml/", + shell=True, +) suppress_warnings = ["bibtex.duplicate_label"] diff --git a/Docs/source/dataanalysis/catalyst.rst b/Docs/source/dataanalysis/catalyst.rst new file mode 100644 index 00000000000..97e634c5c6a --- /dev/null +++ b/Docs/source/dataanalysis/catalyst.rst @@ -0,0 +1,135 @@ +.. _visualization-catalyst: + +In situ Visualization with Catalyst 2 +===================================== +Catalyst 2 (further referred to as just Catalyst) is a lightweight in-situ visualization and analysis framework API developed for simulations and other scientific data producers. It has a lightweight implementation +(or **stub**) and an SDK to develop custom implementations of Catalyst. ParaView comes with its own implementation (known as **ParaView Catalyst**) for leveraging ParaView's +visualization and analysis capabilities, which is what this document will focus on. + + +Enabling Catalyst +----------------- +In order to use Catalyst with WarpX, we need to ensure that we will be using the same version of +conduit across all libraries i.e Catalyst, AMReX and ParaView. One way to achieve this is to +build conduit externally and use it for compiling all the above packages. +This ensures compatibility when passing conduit nodes between WarpX and ParaView. + +First, we build +`Conduit `_ and then +build `Catalyst 2 `_ +using the conduit library created in the previous step. +The latter can be achieved by adding the installation path of conduit to the environmental +variable `CMAKE_PREFIX_PATH` and setting `CATALYST_WITH_EXTERNAL_CONDUIT=ON` during the configuration step of Catalyst. + +Then we build ParaView master (on a commit after 2024.07.01, tested on ``4ef351a54ff747ef7169e2e52e77d9703a9dfa77``) following the developer instructions provided +`here `__ . +A representative set of options for a headless ParaView installation is provided +`here `__ +Afterward, WarpX must be built with ``WarpX_CATALYST=ON``. +Also, make sure to provide the installed paths of Conduit and Catalyst via +`CMAKE_PREFIX_PATH` before configuring WarpX. + +Inputs File Configuration +------------------------- +Once WarpX has been compiled with Catalyst support, it will need to be enabled and configured at runtime. +This is done using our usual inputs file (read with ``amrex::ParmParse``). +The supported parameters are part of the :ref:`FullDiagnostics ` with ``.format`` parameter set to ``catalyst``. + +In addition to configuring the diagnostics, the following parameters must be included: + * ``catalyst.script_paths``: The locations of the pipeline scripts, separated by either a colon or semicolon (e.g. ``/path/to/script1.py;/path/to/script2.py``). + * ``catalyst.implementation`` (default ``paraview``): The name of the implementation being used (case sensitive). + * ``catalyst.implementation_search_paths``: The locations to search for the given implementation. The specific file being searched for will be ``catalyst_{implementation}.so``. + +The latter two can also be given via the environmental variables +`CATALYST_IMPLEMENTATION_NAME` and `CATALYST_IMPLEMENTATION_PATHS` +respectively. + +Because the scripts and implementations are global, Catalyst does not benefit from nor differentiate between multiple diagnostics. + + +Visualization/Analysis Pipeline Configuration +--------------------------------------------- +Catalyst uses the files specified in ``catalyst.script_paths`` to run all analysis. + +The following script, :code:`simple_catalyst_pipeline.py`, automatically detects the type of data for both the mesh and particles, then creates an extractor for them. In most +cases, these will be saved as ``.VTPC`` files which can be read with the ``XML Partitioned Dataset Collection Reader``. + +.. literalinclude:: catalyst/catalyst_simple_pipeline.py + :language: python + :caption: You can copy this file from ``Docs/source/dataanalysis/catalyst/catalyst_simple_pipeline.py``. + + + +For the case of ParaView Catalyst, pipelines are run with ParaView's included ``pvbatch`` executable and use the ``paraview`` library to modify the data. While pipeline scripts +could be written manually, this is not advised for anything beyond the script above. It is much more practical to use ParaView's built in ``Save Catalyst State`` button. + +The process for creating a pipeline is as follows: + 1. Run at least one step of simulation and save the data in a ParaView compatible format, then open it in ParaView. + 2. Set up the desired scene, including filters, camera and views, and extractors. + 3. Press ``Save Catalyst State``, or the multicolored flask icon in the top left corner, and save it to a desired location. + 4. Open the script and replace the used producer with ``PVTrivialProducer``, setting the ``registrationName`` to either ``mesh`` or ``particles`` based on what data is used. + +As an example for step four, here are a few lines from a script directly exported from ParaView: + +.. code-block:: python + + # create a new 'XML Image Data Reader' + meshdatavti = XMLImageDataReader(registrationName='meshdata.vti', FileName=['/path/to/meshdata.vti']) + meshdatavti.CellArrayStatus = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez'] + meshdatavti.TimeArray = 'None' + + # Calculator sample filter + calculator1 = Calculator(registrationName='Calculator1', Input=meshdatavti) + calculator1.AttributeType = 'Cell Data' + calculator1.ResultArrayName = 'BField' + calculator1.Function = 'sqrt(Bx^2 + By^2 + Bz^2)' + +In order to use it with the mesh data coming from the simulation, the above code would be changed to: + +.. code-block:: python + + # create the producer + meshdata = PVTrivialProducer(registrationName='mesh') + meshdata.CellArrayStatus = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez'] + meshdata.TimeArray = 'None' + + # Calculator sample filter + calculator1 = Calculator(registrationName='Calculator1', Input=meshdata) + calculator1.AttributeType = 'Cell Data' + calculator1.ResultArrayName = 'BField' + calculator1.Function = 'sqrt(Bx^2 + By^2 + Bz^2)' + +Steps one is advised so that proper scaling and framing can be done, however in certain cases it may not be possible. If this is the case, a dummy object can be used instead +(such as a wavelet or geometric shape scaled appropriately) and the rest of the steps can be followed as usual. + +Replay +------ +Catalyst 2.0 supports generating binary data dumps for the conduit nodes passed to each ``catalyst_`` call at each iteration. This allows to debug/adapt catalyst scripts without having to rerun the simulation each time. + +To generate the data dumps one must first set the environmental variable ``CATALYST_DATA_DUMP_DIRECTORY`` to the path where the dumps should be saved. Then, run the simulation as normal but replace ``catalyst.implementation=stub`` either in the calling script of WarpX or as an additional argument. + +This will run the simulation and write the conduit nodes under ``CATALYST_DATA_DUMP_DIRECTORY``. + +Afterward, one can replay the generated nodes by setting up the `CATALYST_IMPLEMENTATION_*` variables for the `catalyst_replay` executable (which can be found in the catalyst build directory) appropriately. For example: + +.. code-block:: bash + + # dump conduit nodes + export CATALYST_DATA_DUMP_DIRECTORY=./raw_data + mpiexec -n N /bin/warpx.2d ./inputs_2d catalyst.script_paths=catalyst_pipeline.py catalyst.implementation="stub" + # validate that files have been written + ls ./raw_data/ + ... many files of the format XXXX.conduit_bin.Y.Z + + # replay them + export CATALYST_IMPLEMENTATION_NAME=paraview + export CATALYST_IMPLEMENTATION_PATHS=/lib/catalyst + export CATALYST_IMPLEMENTATION_PREFER_ENV=YES + export CATALYST_DEBUG=1 # optional but helps to make sure the right paths are used + export PYTHONPATH=${PYTHONPATH}/$(pwd) # or the path containing catalyst_pipeline.py in general + # N needs to be the same as when we generated the dump + mpiexec -n N /bin/catalyst_replay ./raw_data + # check extractor output e.g + ls ./datasets/ + +For more information see the documentation for catalyst replay `here `__ . diff --git a/Docs/source/dataanalysis/catalyst/catalyst_simple_pipeline.py b/Docs/source/dataanalysis/catalyst/catalyst_simple_pipeline.py new file mode 100644 index 00000000000..c74b5d3206d --- /dev/null +++ b/Docs/source/dataanalysis/catalyst/catalyst_simple_pipeline.py @@ -0,0 +1,101 @@ +from paraview import catalyst +from paraview.simple import * # noqa: F403 + + +# Helper function +def create_data_extractor(data_node, filename="Dataset"): + """Creates a data extractor that saves `data_node` to a datafile named `filename`. + The filetype is chosen based on the type of `data_note`. + + Note: no rendering is performed by such an extractor. The data are + written directly to a file via VTK. + """ + VTK_TYPES = [ + "vtkImageData", + "vtkRectilinearGrid", + "vtkStructuredGrid", + "vtkPolyData", + "vtkUnstructuredGrid", + "vtkUniformGridAMR", + "vtkMultiBlockDataSet", + "vtkPartitionedDataSet", + "vtkPartitionedDataSetCollection", + "vtkHyperTreeGrid", + ] + FILE_ASSOCIATIONS = [ + "VTI", + "VTR", + "VTS", + "VTP", + "VTU", + "VTH", + "VTM", + "VTPD", + "VTPC", + "HTG", + ] + clientside_data = data_node.GetClientSideObject().GetOutputDataObject( + 0 + ) # Gets the dataobject from the default output port + + # Loop is required because .IsA() detects valid classes that inherit from the VTK_TYPES + for i, vtk_type in enumerate(VTK_TYPES): + if clientside_data.IsA(vtk_type): + filetype = FILE_ASSOCIATIONS[i] + extractor = CreateExtractor( + filetype, data_node, registrationName=f"_{filetype}" + ) + extractor.Writer.FileName = filename + "_{timestep:}" + f".{filetype}" + return extractor + + raise RuntimeError(f"Unsupported data type: {clientside_data.GetClassName()}") + + +# Camera settings +paraview.simple._DisableFirstRenderCameraReset() # Prevents the camera from being shown + +# Options +options = catalyst.Options() + +options.CatalystLiveTrigger = "TimeStep" # "Python", "TimeStep", "TimeValue" +options.EnableCatalystLive = 0 # 0 (disabled), 1 (enabled) +if options.EnableCatalystLive == 1: + options.CatalystLiveURL = "localhost:22222" # localhost:22222 is default + +options.ExtractsOutputDirectory = "datasets" # Base for where all files are saved +options.GenerateCinemaSpecification = 0 # 0 (disabled), 1 (enabled), generates additional descriptor files for cinema exports +options.GlobalTrigger = "TimeStep" # "Python", "TimeStep", "TimeValue" + +meshSource = PVTrivialProducer( + registrationName="mesh" +) # "mesh" is the node where the mesh data is stored +create_extractor(meshSource, filename="meshdata") +particleSource = PVTrivialProducer( + registrationName="particles" +) # "particles" is the node where particle data is stored +create_extractor(particleSource, filename="particledata") + + +# Called on catalyst initialize (after Cxx side initialize) +def catalyst_initialize(): + return + + +# Called on catalyst execute (after Cxx side update) +def catalyst_execute(info): + print(f"Time: {info.time}, Timestep: {info.timestep}, Cycle: {info.cycle}") + return + + +# Callback if global trigger is set to "Python" +def is_activated(controller): + return True + + +# Called on catalyst finalize (after Cxx side finalize) +def catalyst_finalize(): + return + + +if __name__ == "__main__": + paraview.simple.SaveExtractsUsingCatalystOptions(options) diff --git a/Docs/source/dataanalysis/formats.rst b/Docs/source/dataanalysis/formats.rst index a7836d41fef..12b85cadfbb 100644 --- a/Docs/source/dataanalysis/formats.rst +++ b/Docs/source/dataanalysis/formats.rst @@ -41,8 +41,9 @@ files to disk). .. toctree:: :maxdepth: 1 - sensei ascent + catalyst + sensei If you like the 3D rendering of laser wakefield acceleration on the WarpX documentation front page (which is diff --git a/Docs/source/dataanalysis/paraview.rst b/Docs/source/dataanalysis/paraview.rst index 4c90f7179b3..939a23008a8 100644 --- a/Docs/source/dataanalysis/paraview.rst +++ b/Docs/source/dataanalysis/paraview.rst @@ -54,3 +54,9 @@ Plotfiles (AMReX) ParaView also supports visualizing AMReX plotfiles. Please see `the AMReX documentation `__ for more details. + + +In Situ Analysis with Catalyst 2 +-------------------------------- + +Continue reading :ref:`here `. diff --git a/Docs/source/developers/checksum.rst b/Docs/source/developers/checksum.rst index 81d16809d50..2452d074ba1 100644 --- a/Docs/source/developers/checksum.rst +++ b/Docs/source/developers/checksum.rst @@ -65,6 +65,21 @@ Since this will automatically change the JSON file stored on the repo, make a se git add .json git commit -m "reset benchmark for because ..." --author="Tools " +Automated reset of a list of test benchmarks +-------------------------------------------- + +If you set the environment variable ``export CHECKSUM_RESET=ON`` before running tests that are compared against existing benchmarks, the test analysis will reset the benchmarks to the new values, skipping the comparison. + +With `CTest `__ (coming soon), select the test(s) to reset by `name `__ or `label `__. + +.. code-block:: bash + + # regex filter: matched names + CHECKSUM_RESET=ON ctest --test-dir build -R "Langmuir_multi|LaserAcceleration" + + # ... check and commit changes ... + + Reset a benchmark from the Azure pipeline output on Github ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/Docs/source/developers/developers.rst b/Docs/source/developers/developers.rst index aa2e6196377..222f665b563 100644 --- a/Docs/source/developers/developers.rst +++ b/Docs/source/developers/developers.rst @@ -15,7 +15,6 @@ Implementation Details initialization diagnostics moving_window - qed portability warning_logger python diff --git a/Docs/source/developers/particles.rst b/Docs/source/developers/particles.rst index 53a0090b5c9..37260d1ed64 100644 --- a/Docs/source/developers/particles.rst +++ b/Docs/source/developers/particles.rst @@ -160,7 +160,7 @@ Attribute name ``int``/``real`` Description Default when they were created. ================== ================ ================================= ============== -A Python example that adds runtime options can be found in :download:`Examples/Tests/particle_data_python <../../../Examples/Tests/particle_data_python/PICMI_inputs_prev_pos_2d.py>` +A Python example that adds runtime options can be found in :download:`Examples/Tests/particle_data_python <../../../Examples/Tests/particle_data_python/inputs_test_2d_prev_positions_picmi.py>` .. note:: diff --git a/Docs/source/developers/testing.rst b/Docs/source/developers/testing.rst index c6a09d970df..5bbc7d0fef4 100644 --- a/Docs/source/developers/testing.rst +++ b/Docs/source/developers/testing.rst @@ -3,7 +3,7 @@ Testing the code ================ -When adding a new feature, you want to make sure that (i) you did not break the existing code and (ii) your contribution gives correct results. While existing capabilities are tested regularly remotely (when commits are pushed to an open PR on CI, and every night on local clusters), it can also be useful to run tests on your custom input file. This section details how to use both automated and custom tests. +When adding a new feature, you want to make sure that (i) you did not break the existing code and (ii) your contribution gives correct results. While the code is tested regularly remotely (on the cloud when commits are pushed to an open PR, and every night on local clusters), it can also be useful to run tests on your custom input file. This section details how to use both automated and custom tests. Continuous Integration in WarpX ------------------------------- @@ -11,31 +11,14 @@ Continuous Integration in WarpX Configuration ^^^^^^^^^^^^^ -Our regression tests are using the suite published and documented at `AMReX-Codes/regression_testing `__. +Our regression tests are run with `CTest `__, an executable that comes with CMake. -Most of the configuration of our regression tests happens in ``Regression/Warpx-tests.ini``. -We slightly modify this file in ``Regression/prepare_file_ci.py``. +The test suite is ready to run once you have configured and built WarpX with CMake, following the instructions that you find in our :ref:`Users ` or :ref:`Developers ` sections. -For example, if you like to change the compiler to compilation to build on Nvidia GPUs, modify this block to add ``-DWarpX_COMPUTE=CUDA``: +A test that requires a build option that was not configured and built will be skipped automatically. For example, if you configure and build WarpX in 1D only, any test of dimensionality other than 1D, which would require WarpX to be configured and built in the corresponding dimensionality, will be skipped automatically. -.. code-block:: ini - - [source] - dir = /home/regtester/AMReX_RegTesting/warpx - branch = development - cmakeSetupOpts = -DAMReX_ASSERTIONS=ON -DAMReX_TESTING=ON -DWarpX_COMPUTE=CUDA - -We also support changing compilation options via the usual :ref:`build environment variables `. -For instance, compiling with ``clang++ -Werror`` would be: - -.. code-block:: sh - - export CXX=$(which clang++) - export CXXFLAGS="-Werror" - - -Run Pre-Commit Tests Locally ----------------------------- +How to run pre-commit tests locally +----------------------------------- When proposing code changes to Warpx, we perform a couple of automated stylistic and correctness checks on the code change. You can run those locally before you push to save some time, install them once like this: @@ -47,97 +30,165 @@ You can run those locally before you push to save some time, install them once l See `pre-commit.com `__ and our ``.pre-commit-config.yaml`` file in the repository for more details. +How to run automated tests locally +---------------------------------- + +Once your new feature is ready, there are ways to check that you did not break anything. +WarpX has automated tests running every time a commit is pushed to an open pull request. +The input files and scripts used by the automated tests can be found in the `Examples `__ directory, either under `Physics_applications `__ or `Tests `__. + +For easier debugging, it can be convenient to run the tests on your local machine by executing CTest as illustrated in the examples below (where we assume that WarpX was configured and built in the directory ``build``): + +* List tests available for the current build options: + + .. code-block:: sh + + ctest --test-dir build -N + +* Run tests available for the current build options: + + .. code-block:: sh + + ctest --test-dir build + +* Run tests available for the current build options in parallel (while preserving existing dependencies between tests): + + .. code-block:: sh + + ctest --test-dir build -j 2 + +* Run tests available for the current build options and output anything outputted by the test program if the test should fail: + + .. code-block:: sh + + ctest --test-dir build --output-on-failure + +* Run tests available for the current build options with verbose output: -Run the test suite locally + .. code-block:: sh + + ctest --test-dir build --verbose + +* Run tests matching the regular expression ``laser_acceleration``: + + .. code-block:: sh + + ctest --test-dir build -R laser_acceleration + +* Run tests except those matching the regular expression ``laser_acceleration``: + + .. code-block:: sh + + ctest --test-dir build -E laser_acceleration + +* Sometimes two or more tests share a large number of input parameters and differ by a small set of options. + Such tests typically also share a base string in their names. + For example, you can find three different tests named ``test_3d_langmuir_multi``, ``test_3d_langmuir_multi_nodal`` and ``test_3d_langmuir_multi_picmi``. + In such a case, if you wish to run the test ``test_3d_langmuir_multi`` only, this can be done again with the ``-R`` regular `expression filter `__ via + + .. code-block:: sh + + ctest --test-dir build -R "test_3d_langmuir_multi\..*" + + Note that filtering with ``-R "test_3d_langmuir_multi"`` would include the additional tests that have the same substring in their name and would not be sufficient to isolate a single test. + Note also that the escaping ``\.`` in the regular expression is necessary in order to take into account the fact that each test is automatically appended with the strings ``.run``, ``.analysis`` and possibly ``.cleanup``. + +* Run only tests not labeled with the ``slow`` label: + + .. code-block:: sh + + ctest --test-dir build -LE slow + +Once the execution of CTest is completed, you can find all files associated with each test in its corresponding directory under ``build/bin/``. +For example, if you run the single test ``test_3d_laser_acceleration``, you can find all files associated with this test in the directory ``build/bin/test_3d_laser_acceleration/``. + +If you modify the code base locally and want to assess the effects of your code changes on the automated tests, you need to first rebuild WarpX including your code changes and then rerun CTest. + +How to add automated tests -------------------------- -Once your new feature is ready, there are ways to check that you did not break anything. -WarpX has automated tests running every time a commit is added to an open pull request. -The list of automated tests is defined in `./Regression/WarpX-tests.ini `__. +As mentioned above, the input files and scripts used by the automated tests can be found in the `Examples `__ directory, either under `Physics_applications `__ or `Tests `__. -For easier debugging, it can be convenient to run the tests on your local machine by executing the script -`./run_test.sh `__ from WarpX's root folder, as illustrated in the examples below: +Each test directory must contain a file named ``CMakeLists.txt`` where all tests associated with the input files and scripts in that directory must be listed. -.. code-block:: sh +A new test can be added by adding a corresponding entry in ``CMakeLists.txt`` as illustrated in the examples below: - # Example: - # run all tests defined in ./Regression/WarpX-tests.ini - ./run_test.sh +* Add the **regular test** ``test_1d_laser_acceleration``: - # Example: - # run only the test named 'pml_x_yee' - ./run_test.sh pml_x_yee + .. code-block:: cmake - # Example: - # run only the tests named 'pml_x_yee', 'pml_x_ckc' and 'pml_x_psatd' - ./run_test.sh pml_x_yee pml_x_ckc pml_x_psatd + add_warpx_test( + test_1d_laser_acceleration # name + 1 # dims + 2 # nprocs + inputs_test_1d_laser_acceleration # inputs + analysis.py # analysis + diags/diag1000100 # output (plotfile) + OFF # dependency + ) -Note that the script `./run_test.sh `__ runs the tests with the exact same compile-time options and runtime options used to run the tests remotely. +* Add the **PICMI test** ``test_2d_laser_acceleration_picmi``: -Moreover, the script `./run_test.sh `__ compiles all the executables that are necessary in order to run the chosen tests. -The default number of threads allotted for compiling is set with ``numMakeJobs = 8`` in `./Regression/WarpX-tests.ini `__. -However, when running the tests on a local machine, it is usually possible and convenient to allot more threads for compiling, in order to speed up the builds. -This can be accomplished by setting the environment variable ``WARPX_CI_NUM_MAKE_JOBS``, with the preferred number of threads that fits your local machine, e.g. ``export WARPX_CI_NUM_MAKE_JOBS=16`` (or less if your machine is smaller). -On public CI, we overwrite the value to ``WARPX_CI_NUM_MAKE_JOBS=2``, in order to avoid overloading the available remote resources. -Note that this will not change the number of threads used to run each test, but only the number of threads used to compile each executable necessary to run the tests. + .. code-block:: cmake -Once the execution of `./run_test.sh `__ is completed, you can find all the relevant files associated with each test in one single directory. -For example, if you run the single test ``pml_x_yee``, as shown above, on 04/30/2021, you can find all relevant files in the directory ``./test_dir/rt-WarpX/WarpX-tests/2021-04-30/pml_x_yee/``. -The content of this directory will look like the following (possibly including backtraces if the test crashed at runtime): + add_warpx_test( + test_2d_laser_acceleration_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_acceleration_picmi.py # inputs + analysis.py # analysis + diags/diag1000100 # output (plotfile) + OFF # dependency + ) -.. code-block:: sh +* Add the **restart test** ``test_3d_laser_acceleration_restart``: + + .. code-block:: cmake + + add_warpx_test( + test_3d_laser_acceleration_restart # name + 3 # dims + 2 # nprocs + inputs_test_3d_laser_acceleration_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000100 # output (plotfile) + test_3d_laser_acceleration # dependency + ) - $ ls ./test_dir/rt-WarpX/WarpX-tests/2021-04-30/pml_x_yee/ - analysis_pml_yee.py # Python analysis script - inputs_2d # input file - main2d.gnu.TEST.TPROF.MTMPI.OMP.QED.ex # executable - pml_x_yee.analysis.out # Python analysis output - pml_x_yee.err.out # error output - pml_x_yee.make.out # build output - pml_x_yee_plt00000/ # data output (initialization) - pml_x_yee_plt00300/ # data output (last time step) - pml_x_yee.run.out # test output + Note that the restart has an explicit dependency, namely it can run only provided that the original test, from which the restart checkpoint files will be read, runs first. +* A more complex example. Add the **PICMI test** ``test_rz_laser_acceleration_picmi``, with custom command-line arguments ``--test`` and ``dir``, and openPMD time series output: -Add a test to the suite ------------------------ + .. code-block:: cmake -There are three steps to follow to add a new automated test (illustrated here for PML boundary conditions): + add_warpx_test( + test_rz_laser_acceleration_picmi # name + RZ # dims + 2 # nprocs + "inputs_test_rz_laser_acceleration_picmi.py --test --dir 1" # inputs + analysis.py # analysis + diags/diag1/ # output (openPMD time series) + OFF # dependency + ) -* An input file for your test, in folder `Example/Tests/...`. For the PML test, the input file is at ``Examples/Tests/pml/inputs_2d``. You can also re-use an existing input file (even better!) and pass specific parameters at runtime (see below). -* A Python script that reads simulation output and tests correctness versus theory or calibrated results. For the PML test, see ``Examples/Tests/pml/analysis_pml_yee.py``. It typically ends with Python statement ``assert( error<0.01 )``. -* If you need a new Python package dependency for testing, add it in ``Regression/requirements.txt`` -* Add an entry to ``Regression/WarpX-tests.ini``, so that a WarpX simulation runs your test in the continuous integration process, and the Python script is executed to assess the correctness. For the PML test, the entry is +If you need a new Python package dependency for testing, please add it in `Regression/requirements.txt `__. -.. code-block:: +Sometimes two or more tests share a large number of input parameters. The shared input parameters can be collected in a "base" input file that can be passed as a runtime parameter in the actual test input files through the parameter ``FILE``. - [pml_x_yee] - buildDir = . - inputFile = Examples/Tests/pml/inputs2d - runtime_params = warpx.do_dynamic_scheduling=0 algo.maxwell_solver=yee - dim = 2 - addToCompileString = - cmakeSetupOpts = -DWarpX_DIMS=2 - restartTest = 0 - useMPI = 1 - numprocs = 2 - useOMP = 1 - numthreads = 1 - compileTest = 0 - doVis = 0 - analysisRoutine = Examples/Tests/pml/analysis_pml_yee.py +Naming conventions for automated tests +-------------------------------------- -If you re-use an existing input file, you can add arguments to ``runtime_params``, like ``runtime_params = amr.max_level=1 amr.n_cell=32 512 max_step=100 plasma_e.zmin=-200.e-6``. +Note that we currently obey the following snake\_case naming conventions for test names and test input files (which make automation tasks easier, e.g., parsing visually, parsing through code, sorting alphabetically, filtering tests in CTest via ``-R``, etc.): -.. note:: +#. **Regular test names** start with the string ``test_1d_``, ``test_2d_``, ``test_3d_`` or ``test_rz_``, followed by a string that is descriptive of the test. For example, ``test_3d_laser_acceleration``. - If you added ``analysisRoutine = Examples/analysis_default_regression.py``, then run the new test case locally and add the :ref:`checksum ` file for the expected output. +#. **PICMI test names** start with the string ``test_1d_``, ``test_2d_``, ``test_3d_`` or ``test_rz_``, followed by a string that is descriptive of the test, and end with the string ``_picmi``. For example, ``test_3d_laser_acceleration_picmi``. -.. note:: +#. **Restart test names** end with the string ``_restart``. For example, ``test_3d_laser_acceleration_restart``. - We run those tests on our continuous integration services, which at the moment only have 2 virtual CPU cores. - Thus, make sure that the product of ``numprocs`` and ``numthreads`` for a test is ``<=2``. +#. **Test input files** start with the string ``inputs_`` followed by the test name. For example, ``inputs_test_3d_laser_acceleration`` or ``inputs_test_3d_laser_acceleration_picmi.py`` or ``inputs_test_3d_laser_acceleration_restart``. +#. **Base input files** (that is, files collecting input parameters shared between two or more tests) are typically named ``inputs_base_1d``, ``inputs_base_2d``, ``inputs_base_3d`` or ``inputs_base_rz``, possibly followed by additional strings if need be. Useful tool for plotfile comparison: ``fcompare`` ------------------------------------------------- diff --git a/Docs/source/highlights.rst b/Docs/source/highlights.rst index 7baec74d606..66570644bdc 100644 --- a/Docs/source/highlights.rst +++ b/Docs/source/highlights.rst @@ -14,6 +14,11 @@ Plasma-Based Acceleration Scientific works in laser-plasma and beam-plasma acceleration. +#. Shrock JE, Rockafellow E, Miao B, Le M, Hollinger RC, Wang S, Gonsalves AJ, Picksley A, Rocca JJ, and Milchberg HM + **Guided Mode Evolution and Ionization Injection in Meter-Scale Multi-GeV Laser Wakefield Accelerators**. + Phys. Rev. Lett. **133**, 045002, 2024 + `DOI:10.1103/PhysRevLett.133.045002 `__ + #. Ross AJ, Chappell J, van de Wetering JJ, Cowley J, Archer E, Bourgeois N, Corner L, Emerson DR, Feder L, Gu XJ, Jakobsson O, Jones H, Picksley A, Reid L, Wang W, Walczak R, Hooker SM. **Resonant excitation of plasma waves in a plasma channel**. Phys. Rev. Research **6**, L022001, 2024 @@ -80,6 +85,11 @@ Laser-Plasma Interaction Scientific works in laser-ion acceleration and laser-matter interaction. +#. Garten M, Bulanov S S, Hakimi S, Obst-Huebl L, Mitchell C E, Schroeder C B, Esarey E, Geddes C G R, Vay J-L, Huebl A. + **Laser-plasma ion beam booster based on hollow-channel magnetic vortex acceleration**. + Physical Review Research **6**, 033148, 2024. + `DOI:10.1103/PhysRevResearch.6.033148 `__ + #. Knight B, Gautam C, Stoner C, Egner B, Smith J, Orban C, Manfredi J, Frische K, Dexter M, Chowdhury E, Patnaik A (2023). **Detailed Characterization of a kHz-rate Laser-Driven Fusion at a Thin Liquid Sheet with a Neutron Detection Suite**. High Power Laser Science and Engineering, 1-13, 2023. @@ -136,8 +146,8 @@ Scientific works in astrophysical plasma modeling. #. Klion H, Jambunathan R, Rowan ME, Yang E, Willcox D, Vay J-L, Lehe R, Myers A, Huebl A, Zhang W. **Particle-in-Cell simulations of relativistic magnetic reconnection with advanced Maxwell solver algorithms**. - arXiv pre-print, 2023. - `DOI:10.48550/arXiv.2304.10566 `__ + The Astrophysical Journal **952** 8, 2023. + `DOI:10.3847/1538-4357/acd75b `__ Microelectronics @@ -168,8 +178,13 @@ Scientific works in High-Performance Computing, applied mathematics and numerics Please see :ref:`this section `. -Nuclear Fusion - Magnetically Confined Plasmas -********************************************** +Nuclear Fusion and Plasma Confinement +************************************* + +#. Affolter M., Thompson R., Hepner S., Hayes E. C., Podolsky V., Borghei M., Carlsson J., Gargone A., Merthe D., McKee E., Langtry R., + **The Orbitron: A crossed-field device for co-confinement of high energy ions and electrons**. + AIP Advances **14**, 085025, 2024. + `DOI:10.1063/5.0201470 `__ #. Nicks B. S., Putvinski S. and Tajima T. **Stabilization of the Alfvén-ion cyclotron instability through short plasmas: Fully kinetic simulations in a high-beta regime**. @@ -180,3 +195,16 @@ Nuclear Fusion - Magnetically Confined Plasmas **Accelerated kinetic model for global macro stability studies of high-beta fusion reactors**. Physics of Plasmas **30**, 122508, 2023. `DOI:10.1063/5.0178288 `__ + +Plasma Thrusters and Electric Propulsion +**************************************** + +#. Xie L., Luo X., Zhou Z. and Zhao Y., + **Effect of plasma initialization on 3D PIC simulation of Hall thruster azimuthal instability**. + Physica Scripta, **99**, 095602, 2024. + `DOI:10.1088/1402-4896/ad69e5 `__ + +#. Marks T. A. and Gorodetsky A. A., + **Hall thruster simulations in WarpX**. + 38th International Electric Propulsion Conference, Toulouse, France, 2024. + `DOI:10.7302/234915 `__ diff --git a/Docs/source/index.rst b/Docs/source/index.rst index 89bc2e417cb..9668620976a 100644 --- a/Docs/source/index.rst +++ b/Docs/source/index.rst @@ -3,7 +3,7 @@ WarpX ----- -WarpX is an advanced, time-based, **electromagnetic & electrostatic Particle-In-Cell** code. +WarpX is an advanced **electromagnetic & electrostatic Particle-In-Cell** code. It supports many features including: @@ -111,8 +111,7 @@ Theory theory/amr theory/boundary_conditions theory/boosted_frame - theory/input_output - theory/collisions + theory/multiphysics_extensions theory/kinetic_fluid_hybrid_model theory/cold_fluid_model @@ -140,7 +139,6 @@ Maintenance :hidden: maintenance/release - maintenance/performance_tests Epilogue -------- diff --git a/Docs/source/install/cmake.rst b/Docs/source/install/cmake.rst index fde927c10e1..60d9eecc2b4 100644 --- a/Docs/source/install/cmake.rst +++ b/Docs/source/install/cmake.rst @@ -83,12 +83,12 @@ CMake Option Default & Values Descr ``CMAKE_BUILD_TYPE`` RelWithDebInfo/**Release**/Debug `Type of build, symbols & optimizations `__ ``CMAKE_INSTALL_PREFIX`` system-dependent path `Install path prefix `__ ``CMAKE_VERBOSE_MAKEFILE`` ON/**OFF** `Print all compiler commands to the terminal during build `__ -``PYINSTALLOPTIONS`` Additional options for ``pip install``, e.g., ``-v --user`` ``WarpX_APP`` **ON**/OFF Build the WarpX executable application ``WarpX_ASCENT`` ON/**OFF** Ascent in situ visualization +``WarpX_CATALYST`` ON/**OFF** Catalyst in situ visualization ``WarpX_COMPUTE`` NOACC/**OMP**/CUDA/SYCL/HIP On-node, accelerated computing backend ``WarpX_DIMS`` **3**/2/1/RZ Simulation dimensionality. Use ``"1;2;RZ;3"`` for all. -``WarpX_EB`` ON/**OFF** Embedded boundary support (not supported in RZ yet) +``WarpX_EB`` **ON**/OFF Embedded boundary support (not supported in RZ yet) ``WarpX_IPO`` ON/**OFF** Compile WarpX with interprocedural optimization (aka LTO) ``WarpX_LIB`` ON/**OFF** Build WarpX as a library, e.g., for PICMI Python ``WarpX_MPI`` **ON**/OFF Multi-node support (message-passing) @@ -104,6 +104,9 @@ CMake Option Default & Values Descr ``WarpX_QED_TOOLS`` ON/**OFF** Build external tool to generate QED lookup tables (requires PICSAR and Boost) ``WarpX_QED_TABLES_GEN_OMP`` **AUTO**/ON/OFF Enables OpenMP support for QED lookup tables generation ``WarpX_SENSEI`` ON/**OFF** SENSEI in situ visualization +``Python_EXECUTABLE`` (newest found) Path to Python executable +``PY_PIP_OPTIONS`` ``-v`` Additional options for ``pip``, e.g., ``-vvv`` +``PY_PIP_INSTALL_OPTIONS`` Additional options for ``pip install``, e.g., ``--user`` ============================= ============================================ ========================================================= WarpX can be configured in further detail with options from AMReX, which are documented in the AMReX manual: @@ -239,7 +242,7 @@ Developers could now change the WarpX source code and then call the build line a .. tip:: If you do *not* develop with :ref:`a user-level package manager `, e.g., because you rely on a HPC system's environment modules, then consider to set up a virtual environment via `Python venv `__. - Otherwise, without a virtual environment, you likely need to add the CMake option ``-DPYINSTALLOPTIONS="--user"``. + Otherwise, without a virtual environment, you likely need to add the CMake option ``-DPY_PIP_INSTALL_OPTIONS="--user"``. .. _building-pip-python: @@ -266,7 +269,7 @@ Environment Variable Default & Values Descr ============================= ============================================ ================================================================ ``WARPX_COMPUTE`` NOACC/**OMP**/CUDA/SYCL/HIP On-node, accelerated computing backend ``WARPX_DIMS`` ``"1;2;3;RZ"`` Simulation dimensionalities (semicolon-separated list) -``WARPX_EB`` ON/**OFF** Embedded boundary support (not supported in RZ yet) +``WARPX_EB`` **ON**/OFF Embedded boundary support (not supported in RZ yet) ``WARPX_MPI`` ON/**OFF** Multi-node support (message-passing) ``WARPX_OPENPMD`` **ON**/OFF openPMD I/O (HDF5, ADIOS) ``WARPX_PRECISION`` SINGLE/**DOUBLE** Floating point precision (single/double) diff --git a/Docs/source/install/dependencies.rst b/Docs/source/install/dependencies.rst index 3bab32b7502..72c599ae2bd 100644 --- a/Docs/source/install/dependencies.rst +++ b/Docs/source/install/dependencies.rst @@ -7,7 +7,7 @@ WarpX depends on the following popular third party software. Please see installation instructions below. - a mature `C++17 `__ compiler, e.g., GCC 8.4+, Clang 7, NVCC 11.0, MSVC 19.15 or newer -- `CMake 3.20.0+ `__ +- `CMake 3.24.0+ `__ - `Git 2.18+ `__ - `AMReX `__: we automatically download and compile a copy of AMReX - `PICSAR `__: we automatically download and compile a copy of PICSAR @@ -28,7 +28,7 @@ Optional dependencies include: - `FFTW3 `__: for spectral solver (PSATD or IGF) support when running on CPU or SYCL - also needs the ``pkg-config`` tool on Unix -- `heFFTe 2.4.0+ `__: for multi-node spectral solver (IGF) support - `BLAS++ `__ and `LAPACK++ `__: for spectral solver (PSATD) support in RZ geometry - `Boost 1.66.0+ `__: for QED lookup tables generation support - `openPMD-api 0.15.1+ `__: we automatically download and compile a copy of openPMD-api for openPMD I/O support @@ -81,7 +81,7 @@ Conda (Linux/macOS/Windows) .. code-block:: bash - conda create -n warpx-cpu-mpich-dev -c conda-forge blaspp boost ccache cmake compilers git lapackpp "openpmd-api=*=mpi_mpich*" openpmd-viewer python make numpy pandas scipy yt "fftw=*=mpi_mpich*" pkg-config matplotlib mamba mpich mpi4py ninja pip virtualenv + conda create -n warpx-cpu-mpich-dev -c conda-forge blaspp boost ccache cmake compilers git "heffte=*=mpi_mpich*" lapackpp "openpmd-api=*=mpi_mpich*" openpmd-viewer python make numpy pandas scipy yt "fftw=*=mpi_mpich*" pkg-config matplotlib mamba mpich mpi4py ninja pip virtualenv conda activate warpx-cpu-mpich-dev # compile WarpX with -DWarpX_MPI=ON @@ -228,7 +228,7 @@ The `Advanced Package Tool (APT) ` .. code-block:: bash sudo apt update - sudo apt install build-essential ccache cmake g++ git libfftw3-mpi-dev libfftw3-dev libhdf5-openmpi-dev libopenmpi-dev pkg-config python3 python3-matplotlib python3-mpi4py python3-numpy python3-pandas python3-pip python3-scipy python3-venv + sudo apt install build-essential ccache cmake g++ git libfftw3-mpi-dev libfftw3-dev libhdf5-openmpi-dev libopenmpi-dev pkg-config python3 python3-dev python3-matplotlib python3-mpi4py python3-numpy python3-pandas python3-pip python3-scipy python3-venv # optional: # for CUDA, either install @@ -244,7 +244,7 @@ The `Advanced Package Tool (APT) ` .. code-block:: bash sudo apt update - sudo apt install build-essential ccache cmake g++ git libfftw3-dev libfftw3-dev libhdf5-dev pkg-config python3 python3-matplotlib python3-numpy python3-pandas python3-pip python3-scipy python3-venv + sudo apt install build-essential ccache cmake g++ git libfftw3-dev libfftw3-dev libhdf5-dev pkg-config python3 python3-dev python3-matplotlib python3-numpy python3-pandas python3-pip python3-scipy python3-venv # optional: # for CUDA, either install diff --git a/Docs/source/install/hpc.rst b/Docs/source/install/hpc.rst index 5efdeae39a8..af4c0fe3e61 100644 --- a/Docs/source/install/hpc.rst +++ b/Docs/source/install/hpc.rst @@ -36,6 +36,7 @@ This section documents quick-start guides for a selection of supercomputers that hpc/crusher hpc/frontier hpc/fugaku + hpc/greatlakes hpc/hpc3 hpc/juwels hpc/karolina @@ -46,12 +47,12 @@ This section documents quick-start guides for a selection of supercomputers that hpc/lxplus hpc/ookami hpc/perlmutter + hpc/pitzer hpc/polaris hpc/quartz - hpc/spock hpc/summit hpc/taurus - hpc/greatlakes + hpc/tioga .. tip:: diff --git a/Docs/source/install/hpc/lxplus.rst b/Docs/source/install/hpc/lxplus.rst index 5bd8a3c9795..fc1e5d4286d 100644 --- a/Docs/source/install/hpc/lxplus.rst +++ b/Docs/source/install/hpc/lxplus.rst @@ -44,7 +44,7 @@ The easiest way to install the dependencies is to use the pre-prepared ``warpx.p .. code-block:: bash - cp $WORK/warpx/WarpX/Tools/machines/lxplus-cern/lxplus_warpx.profile.example $WORK/lxplus_warpx.profile + cp $WORK/warpx/Tools/machines/lxplus-cern/lxplus_warpx.profile.example $WORK/lxplus_warpx.profile source $WORK/lxplus_warpx.profile When doing this one can directly skip to the :ref:`Building WarpX ` section. diff --git a/Docs/source/install/hpc/pitzer.rst b/Docs/source/install/hpc/pitzer.rst new file mode 100644 index 00000000000..4f1e53bc309 --- /dev/null +++ b/Docs/source/install/hpc/pitzer.rst @@ -0,0 +1,274 @@ +.. _building-pitzer: + +Pitzer (OSC) +============ + +The `Pitzer cluster `__ is located at the Ohio Supercomputer Center (OSC). It is currently the main CPU/GPU cluster at OSC. However, the `Cardinal cluster `__ is soon going to take over Pitzer to become the next major CPU/GPU cluster at OSC in the second half of 2024. A list of all OSC clusters can be found `here `__. + +The Pitzer cluster offers a variety of partitions suitable for different computational needs, including GPU nodes, CPU nodes, and nodes with large memory capacities. For more information on the specifications and capabilities of these partitions, visit the `Ohio Supercomputer Center's Pitzer page `__. + +Introduction +------------ + +If you are new to this system, **please see the following resources**: + +* `Pitzer user guide `__ +* Batch system: `Slurm `__ +* `Jupyter service `__ +* `Filesystems `__: + + * ``$HOME``: per-user directory, use only for inputs, source, and scripts; backed up (500GB) + * ``/fs/ess``: per-project storage directory, use for long-term storage of data and analysis; backed up (1-5TB) + * ``/fs/scratch``: per-project production directory; fast I/O for parallel jobs; not backed up (100TB) + +.. _building-pitzer-preparation: + +Preparation +----------- + +Use the following commands to download the WarpX source code: + +.. code-block:: bash + + git clone https://github.com/ECP-WarpX/WarpX.git $HOME/src/warpx + +On Pitzer, you can run either on GPU nodes with V100 GPUs or CPU nodes. + +.. tab-set:: + + .. tab-item:: V100 GPUs + + We use system software modules, add environment hints and further dependencies via the file ``$HOME/pitzer_v100_warpx.profile``. + Create it now: + + .. code-block:: bash + + cp $HOME/src/warpx/Tools/machines/pitzer-osc/pitzer_v100_warpx.profile.example $HOME/pitzer_v100_warpx.profile + + .. dropdown:: Script Details + :color: light + :icon: info + :animate: fade-in-slide-down + + .. literalinclude:: ../../../../Tools/machines/pitzer-osc/pitzer_v100_warpx.profile.example + :language: bash + + Edit the 2nd line of this script, which sets the ``export proj=""`` variable. + For example, if you are member of the project ``pas2024``, then run ``nano $HOME/pitzer_v100_warpx.profile`` and edit line 2 to read: + + .. code-block:: bash + + export proj="pas2024" + + Exit the ``nano`` editor with ``Ctrl`` + ``O`` (save) and then ``Ctrl`` + ``X`` (exit). + + .. important:: + + Now, and as the first step on future logins to pitzer, activate these environment settings: + + .. code-block:: bash + + source $HOME/pitzer_v100_warpx.profile + + Finally, since pitzer does not yet provide software modules for some of our dependencies, install them once: + + .. code-block:: bash + + bash $HOME/src/warpx/Tools/machines/pitzer-osc/install_v100_dependencies.sh + + .. dropdown:: Script Details + :color: light + :icon: info + :animate: fade-in-slide-down + + .. literalinclude:: ../../../../Tools/machines/pitzer-osc/install_v100_dependencies.sh + :language: bash + + + .. tab-item:: CPU Nodes + + We use system software modules, add environment hints and further dependencies via the file ``$HOME/pitzer_cpu_warpx.profile``. + Create it now: + + .. code-block:: bash + + cp $HOME/src/warpx/Tools/machines/pitzer-osc/pitzer_cpu_warpx.profile.example $HOME/pitzer_cpu_warpx.profile + + .. dropdown:: Script Details + :color: light + :icon: info + :animate: fade-in-slide-down + + .. literalinclude:: ../../../../Tools/machines/pitzer-osc/pitzer_cpu_warpx.profile.example + :language: bash + + Edit the 2nd line of this script, which sets the ``export proj=""`` variable. + For example, if you are member of the project ``pas2024``, then run ``nano $HOME/pitzer_cpu_warpx.profile`` and edit line 2 to read: + + .. code-block:: bash + + export proj="pas2024" + + Exit the ``nano`` editor with ``Ctrl`` + ``O`` (save) and then ``Ctrl`` + ``X`` (exit). + + .. important:: + + Now, and as the first step on future logins to pitzer, activate these environment settings: + + .. code-block:: bash + + source $HOME/pitzer_cpu_warpx.profile + + Finally, since pitzer does not yet provide software modules for some of our dependencies, install them once: + + .. code-block:: bash + + bash $HOME/src/warpx/Tools/machines/pitzer-osc/install_cpu_dependencies.sh + + .. dropdown:: Script Details + :color: light + :icon: info + :animate: fade-in-slide-down + + .. literalinclude:: ../../../../Tools/machines/pitzer-osc/install_cpu_dependencies.sh + :language: bash + + +.. _building-pitzer-compilation: + +Compilation +----------- + +Use the following :ref:`cmake commands ` to compile the application executable: + +.. tab-set:: + .. tab-item:: V100 GPUs + + .. code-block:: bash + + cd $HOME/src/warpx + rm -rf build_v100 + + cmake -S . -B build_v100 -DWarpX_COMPUTE=CUDA -DWarpX_FFT=ON -DWarpX_QED_TABLE_GEN=ON -DWarpX_DIMS="1;2;RZ;3" + cmake --build build_v100 -j 48 + + The WarpX application executables are now in ``$HOME/src/warpx/build_v100/bin/``. Additionally, the following commands will install WarpX as a Python module: + + .. code-block:: bash + + cd $HOME/src/warpx + rm -rf build_v100_py + + cmake -S . -B build_v100_py -DWarpX_COMPUTE=CUDA -DWarpX_FFT=ON -DWarpX_QED_TABLE_GEN=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_DIMS="1;2;RZ;3" + cmake --build build_v100_py -j 48 --target pip_install + + .. tab-item:: CPU Nodes + + .. code-block:: bash + + cd $HOME/src/warpx + rm -rf build + + cmake -S . -B build -DWarpX_FFT=ON -DWarpX_QED_TABLE_GEN=ON -DWarpX_DIMS="1;2;RZ;3" + cmake --build build -j 48 + + The WarpX application executables are now in ``$HOME/src/warpx/build/bin/``. Additionally, the following commands will install WarpX as a Python module: + + .. code-block:: bash + + cd $HOME/src/warpx + rm -rf build_py + + cmake -S . -B build_py -DWarpX_FFT=ON -DWarpX_QED_TABLE_GEN=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_DIMS="1;2;RZ;3" + cmake --build build_py -j 48 --target pip_install + +Now, you can :ref:`submit Pitzer compute jobs ` for WarpX :ref:`Python (PICMI) scripts ` (:ref:`example scripts `). Or, you can use the WarpX executables to submit Pitzer jobs (:ref:`example inputs `). For executables, you can reference their location in your :ref:`job script ` or copy them to a location in ``/scratch``. + +.. _building-pitzer-update: + +Update WarpX & Dependencies +--------------------------- + +If you already installed WarpX in the past and want to update it, start by getting the latest source code: + +.. code-block:: bash + + cd $HOME/src/warpx + + # read the output of this command - does it look ok? + git status + + # get the latest WarpX source code + git fetch + git pull + + # read the output of these commands - do they look ok? + git status + git log # press q to exit + +And, if needed, + +- :ref:`update the pitzer_cpu_warpx.profile file `, +- log out and into the system, activate the now updated environment profile as usual, +- :ref:`execute the dependency install scripts `. + +As a last step, clean the build directory ``rm -rf $HOME/src/warpx/build_*`` and rebuild WarpX. + +.. _running-pitzer: + +Running +------- + +.. tab-set:: + + .. tab-item:: V100 GPUs + + Pitzer's GPU partition includes: + + - 32 nodes, each equipped with two V100 (16GB) GPUs. + - 42 nodes, each with two V100 (32GB) GPUs. + - 4 large memory nodes, each with quad V100 (32GB) GPUs. + + To run a WarpX simulation on the GPU nodes, use the batch script provided below. Adjust the ``-N`` parameter in the script to match the number of nodes you intend to use. Each node in this partition supports running one MPI rank per GPU. + + .. literalinclude:: ../../../../Tools/machines/pitzer-osc/pitzer_v100.sbatch + :language: bash + :caption: Copy this file from ``$HOME/src/warpx/Tools/machines/pitzer-osc/pitzer_v100.sbatch``. + + After preparing your script, submit your job with the following command: + + .. code-block:: bash + + sbatch pitzer_v100.sbatch + + .. tab-item:: CPU Nodes + + For CPU-based computations, Pitzer offers: + + - 224 nodes, each with dual Intel Xeon Gold 6148 CPUs and 192 GB RAM. + - 340 nodes, each with dual Intel Xeon Platinum 8268 CPUs and 192 GB RAM. + - 16 large memory nodes. + + To submit a job to the CPU partition, use the provided batch script. Ensure you have copied the script to your working directory. + + .. literalinclude:: ../../../../Tools/machines/pitzer-osc/pitzer_cpu.sbatch + :language: bash + :caption: Copy this file from ``$HOME/src/warpx/Tools/machines/pitzer-osc/pitzer_cpu.sbatch``. + + Submit your job with: + + .. code-block:: bash + + sbatch pitzer_cpu.sbatch + +.. _post-processing-osc: + +Post-Processing +--------------- + +For post-processing, many users prefer to use the online `Jupyter service `__ (`documentation `__) that is directly connected to the cluster's fast filesystem. + +.. note:: + + This section is a stub and contributions are welcome. + We can document further details, e.g., which recommended post-processing Python software to install or how to customize Jupyter kernels here. diff --git a/Docs/source/install/hpc/spock.rst b/Docs/source/install/hpc/spock.rst deleted file mode 100644 index 144257289f1..00000000000 --- a/Docs/source/install/hpc/spock.rst +++ /dev/null @@ -1,96 +0,0 @@ -.. _building-spock: - -Spock (OLCF) -============= - -The `Spock cluster `_ is located at OLCF. - - -Introduction ------------- - -If you are new to this system, **please see the following resources**: - -* `Spock user guide `_ -* Batch system: `Slurm `_ -* `Production directories `_: - - * ``$PROJWORK/$proj/``: shared with all members of a project (recommended) - * ``$MEMBERWORK/$proj/``: single user (usually smaller quota) - * ``$WORLDWORK/$proj/``: shared with all users - * Note that the ``$HOME`` directory is mounted as read-only on compute nodes. - That means you cannot run in your ``$HOME``. - - -Installation ------------- - -Use the following commands to download the WarpX source code and switch to the correct branch: - -.. code-block:: bash - - git clone https://github.com/ECP-WarpX/WarpX.git $HOME/src/warpx - -We use the following modules and environments on the system (``$HOME/spock_warpx.profile``). - -.. literalinclude:: ../../../../Tools/machines/spock-olcf/spock_warpx.profile.example - :language: bash - :caption: You can copy this file from ``Tools/machines/spock-olcf/spock_warpx.profile.example``. - -We recommend to store the above lines in a file, such as ``$HOME/spock_warpx.profile``, and load it into your shell after a login: - -.. code-block:: bash - - source $HOME/spock_warpx.profile - - -Then, ``cd`` into the directory ``$HOME/src/warpx`` and use the following commands to compile: - -.. code-block:: bash - - cd $HOME/src/warpx - rm -rf build - - cmake -S . -B build -DWarpX_DIMS="1;2;3" -DWarpX_COMPUTE=HIP -DWarpX_FFT=ON -DAMReX_AMD_ARCH=gfx908 -DMPI_CXX_COMPILER=$(which CC) -DMPI_C_COMPILER=$(which cc) -DMPI_COMPILER_FLAGS="--cray-print-opts=all" - cmake --build build -j 10 - -The general :ref:`cmake compile-time options ` apply as usual. - -**That's it!** -A 3D WarpX executable is now in ``build/bin/`` and :ref:`can be run ` with a :ref:`3D example inputs file `. -Most people execute the binary directly or copy it out to a location in ``$PROJWORK/$proj/``. - - -.. _running-cpp-spock: - -Running -------- - -.. _running-cpp-spock-MI100-GPUs: - -MI100 GPUs (32 GB) -^^^^^^^^^^^^^^^^^^ - -After requesting an interactive node with the ``getNode`` alias above, run a simulation like this, here using 4 MPI ranks: - -.. code-block:: bash - - srun -n 4 -c 2 --ntasks-per-node=4 ./warpx inputs - -Or in non-interactive runs started with ``sbatch``: - -.. literalinclude:: ../../../../Tools/machines/spock-olcf/spock_mi100.sbatch - :language: bash - :caption: You can copy this file from ``Tools/machines/spock-olcf/spock_mi100.sbatch``. - -We can currently use up to ``4`` nodes with ``4`` GPUs each (maximum: ``-N 4 -n 16``). - - -.. _post-processing-spock: - -Post-Processing ---------------- - -For post-processing, most users use Python via OLCFs's `Jupyter service `__ (`Docs `__). - -Please follow the same guidance as for :ref:`OLCF Summit post-processing `. diff --git a/Docs/source/install/hpc/tioga.rst b/Docs/source/install/hpc/tioga.rst new file mode 100644 index 00000000000..2599d6d8ac4 --- /dev/null +++ b/Docs/source/install/hpc/tioga.rst @@ -0,0 +1,210 @@ +.. _building-tioga: + +Tioga (LLNL) +============ + +The `Tioga AMD GPU cluster `__ is located at LLNL. +It is equipped with two nodes that have each four AMD MI300A APUs. +Tioga is an LLNL El Capitan Early Access System. + +There are also "conventional" MI250X GPUs on Tioga nodes, which we did not yet document. +El Capitan will use MI300A GPUs. + + +Introduction +------------ + +If you are new to this system, **please see the following resources**: + +* `LLNL user account `__ (login required) +* `Tioga user guide `__ +* Batch system: `Flux with Slurm Wrappers `__ +* `Jupyter service `__ (`documentation `__, login required) +* `Production directories `__: + + * ``/p/lustre1/${USER}``: personal directory on the parallel filesystem (also: ``lustre2``) + * Note that the ``$HOME`` directory and the ``/usr/workspace/${USER}`` space are NFS mounted and *not* suitable for production quality data generation. + + +Login +----- + +.. code-block:: bash + + ssh tioga.llnl.gov + +To use the available MI300A nodes (currently two), request one via + +.. code-block:: bash + + salloc -N 1 -p mi300a -t 30:0 + + +.. _building-tioga-preparation: + +Preparation +----------- + +Use the following commands to download the WarpX source code: + +.. code-block:: bash + + git clone https://github.com/ECP-WarpX/WarpX.git /p/lustre1/${USER}/tioga/src/warpx + +We use system software modules, add environment hints and further dependencies via the file ``$HOME/tioga_mi300a_warpx.profile``. +Create it now: + +.. code-block:: bash + + cp /p/lustre1/${USER}/tioga/src/warpx/Tools/machines/tioga-llnl/tioga_mi300a_warpx.profile.example $HOME/tioga_mi300a_warpx.profile + +.. dropdown:: Script Details + :color: light + :icon: info + :animate: fade-in-slide-down + + .. literalinclude:: ../../../../Tools/machines/tioga-llnl/tioga_mi300a_warpx.profile.example + :language: bash + +Edit the 2nd line of this script, which sets the ``export proj=""`` variable. +**Currently, this is unused and can be kept empty.** +Once project allocation becomes required, e.g., if you are member of the project ``abcde``, then run ``vi $HOME/tioga_mi300a_warpx.profile``. +Enter the edit mode by typing ``i`` and edit line 2 to read: + +.. code-block:: bash + + export proj="abcde" + +Exit the ``vi`` editor with ``Esc`` and then type ``:wq`` (write & quit). + +.. important:: + + Now, and as the first step on future logins to Tioga, activate these environment settings: + + .. code-block:: bash + + source $HOME/tioga_mi300a_warpx.profile + +Finally, since Tioga does not yet provide software modules for some of our dependencies, install them once: + + + .. code-block:: bash + + bash /p/lustre1/${USER}/tioga/src/warpx/Tools/machines/tioga-llnl/install_mi300a_dependencies.sh + source /p/lustre1/${USER}/tioga/warpx/mi300a/gpu/venvs/warpx-trioga-mi300a/bin/activate + + .. dropdown:: Script Details + :color: light + :icon: info + :animate: fade-in-slide-down + + .. literalinclude:: ../../../../Tools/machines/tioga-llnl/install_mi300a_dependencies.sh + :language: bash + + .. dropdown:: AI/ML Dependencies (Optional) + :animate: fade-in-slide-down + + If you plan to run AI/ML workflows depending on PyTorch et al., run the next step as well. + This will take a while and should be skipped if not needed. + + .. code-block:: bash + + bash /p/lustre1/${USER}/tioga/src/warpx/Tools/machines/tioga-llnl/install_mi300a_ml.sh + + .. dropdown:: Script Details + :color: light + :icon: info + :animate: fade-in-slide-down + + .. literalinclude:: ../../../../Tools/machines/tioga-llnl/install_mi300a_ml.sh + :language: bash + + +.. _building-tioga-compilation: + +Compilation +----------- + +Use the following :ref:`cmake commands ` to compile the application executable: + +.. code-block:: bash + + cd /p/lustre1/${USER}/tioga/src/warpx + + cmake --fresh -S . -B build_tioga -DWarpX_COMPUTE=HIP -DWarpX_FFT=ON -DWarpX_DIMS="1;2;RZ;3" + cmake --build build_tioga -j 24 + +The WarpX application executables are now in ``/p/lustre1/${USER}/tioga/src/warpx/build_tioga/bin/``. +Additionally, the following commands will install WarpX as a Python module: + +.. code-block:: bash + + cmake --fresh -S . -B build_tioga_py -DWarpX_COMPUTE=HIP -DWarpX_FFT=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_DIMS="1;2;RZ;3" + cmake --build build_tioga_py -j 24 --target pip_install + +Now, you can :ref:`submit tioga compute jobs ` for WarpX :ref:`Python (PICMI) scripts ` (:ref:`example scripts `). +Or, you can use the WarpX executables to submit tioga jobs (:ref:`example inputs `). +For executables, you can reference their location in your :ref:`job script ` or copy them to a location in ``$PROJWORK/$proj/``. + + +.. _building-tioga-update: + +Update WarpX & Dependencies +--------------------------- + +If you already installed WarpX in the past and want to update it, start by getting the latest source code: + +.. code-block:: bash + + cd /p/lustre1/${USER}/tioga/src/warpx + + # read the output of this command - does it look ok? + git status + + # get the latest WarpX source code + git fetch + git pull + + # read the output of these commands - do they look ok? + git status + git log # press q to exit + +And, if needed, + +- :ref:`update the tioga_mi300a_warpx.profile file `, +- log out and into the system, activate the now updated environment profile as usual, +- :ref:`execute the dependency install scripts `. + +As a last step :ref:`rebuild WarpX `. + + +.. _running-cpp-tioga: + +Running +------- + +.. _running-cpp-tioga-MI300A-APUs: + +MI300A APUs (128GB) +^^^^^^^^^^^^^^^^^^^ + +The batch script below can be used to run a WarpX simulation on 1 node with 4 APUs on the supercomputer Tioga at LLNL. +Replace descriptions between chevrons ``<>`` by relevant values, for instance ```` could be ``plasma_mirror_inputs``. +WarpX runs with one MPI rank per GPU. + +Note that we append these non-default runtime options: + +* ``amrex.use_gpu_aware_mpi=1``: make use of fast APU to APU MPI communications +* ``amrex.the_arena_init_size=1``: avoid overallocating memory that is *shared* on APUs between CPU & GPU + +.. literalinclude:: ../../../../Tools/machines/tioga-llnl/tioga_mi300a.sbatch + :language: bash + :caption: You can copy this file from ``Tools/machines/tioga-llnl/tioga_mi300a.sbatch``. + +To run a simulation, copy the lines above to a file ``tioga_mi300a.sbatch`` and run + +.. code-block:: bash + + sbatch tioga_mi300a.sbatch + +to submit the job. diff --git a/Docs/source/latex_theory/allbibs.bib b/Docs/source/latex_theory/allbibs.bib index b3475c5a81b..e44ab5cf112 100644 --- a/Docs/source/latex_theory/allbibs.bib +++ b/Docs/source/latex_theory/allbibs.bib @@ -2187,3 +2187,60 @@ @book{godfrey1985iprop title = {{The IPROP Three-Dimensional Beam Propagation Code}}, year = {1985} } + +@article{shapovalPRE2024, +author = {Shapoval, Olga and Zoni, Edoardo and Lehe, Remi and Thevenet, Maxence and Vay, Jean-Luc}, +doi = {10.1103/PhysRevE.110.025206}, +issue = {2}, +journal = {Phys. Rev. E}, +month = {Aug}, +numpages = {19}, +pages = {025206}, +publisher = {American Physical Society}, +title = {{Pseudospectral particle-in-cell formulation with arbitrary charge and current-density time dependencies for the modeling of relativistic plasmas}}, +url = {https://link.aps.org/doi/10.1103/PhysRevE.110.025206}, +volume = {110}, +year = {2024} +} + +@article{Ammosov1986, +title = {Tunnel ionization of complex atoms and of atomic ions in an alternating electromagnetic field}, +volume = {64}, +issn = {0044-4510}, +doi = {10.1117/12.938695}, +number = {December 1986}, +journal = {Sov. Phys. JETP}, +author = {Ammosov, M. V. and Delone, N. B. and Krainov, V. P.}, +year = {1986}, +pmid = {22232002}, +note = {ISBN: 0892526998}, +pages = {1191--1194}, +} + + +@article{zhang_empirical_2014, +title = {Empirical formula for over-barrier strong-field ionization}, +volume = {90}, +issn = {1050-2947, 1094-1622}, +doi = {10.1103/PhysRevA.90.043410}, +language = {en}, +number = {4}, +journal = {Physical Review A}, +author = {Zhang, Qingbin and Lan, Pengfei and Lu, Peixiang}, +month = oct, +year = {2014}, +pages = {043410}, +} + + +@book{Mulser2010, +title = {High {Power} {Laser}-{Matter} {Interaction}}, +volume = {238}, +isbn = {978-3-540-50669-0}, +publisher = {Springer Berlin Heidelberg}, +author = {Mulser, Peter and Bauer, Dieter}, +year = {2010}, +pmid = {25246403}, +doi = {10.1007/978-3-540-46065-7}, +note = {Series Title: Springer Tracts in Modern Physics}, +} diff --git a/Docs/source/maintenance/performance_tests.rst b/Docs/source/maintenance/performance_tests.rst deleted file mode 100644 index 8b902297ccb..00000000000 --- a/Docs/source/maintenance/performance_tests.rst +++ /dev/null @@ -1,135 +0,0 @@ -.. _developers-performance_tests: - -Automated performance tests -=========================== - -WarpX has automated performance test scripts, which run weak scalings for various tests on a weekly basis. The results are stored in the `perf_logs repo `_ and plots of the performance history can be found on `this page `_. - -These performance tests run automatically, so they need to do ``git`` operations etc. For this reason, they need a separate clone of the source repos, so they don't conflict with one's usual operations. This is typically in a sub-directory in the ``$HOME``, with variable ``$AUTOMATED_PERF_TESTS`` pointing to it. Similarly, a directory is needed to run the simulations and store the results. By default, it is ``$SCRATCH/performance_warpx``. - -The test runs a weak scaling (1,2,8,64,256,512 nodes) for 6 different tests ``Tools/PerformanceTests/automated_test_{1,2,3,4,5,6}_*``, gathered in 1 batch job per number of nodes to avoid submitting too many jobs. - -Setup on Summit @ OLCF ----------------------- - -Here is an example setup for Summit: - -.. code-block:: sh - - # I put the next three lines in $HOME/my_bashrc.sh - export proj=aph114 # project for job submission - export AUTOMATED_PERF_TESTS=$HOME/AUTOMATED_PERF_TESTS/ - export SCRATCH=/gpfs/alpine/scratch/$(whoami)/$proj/ - - mkdir $HOME/AUTOMATED_PERF_TESTS - cd $AUTOMATED_PERF_TESTS - git clone https://github.com/ECP-WarpX/WarpX.git warpx - git clone https://github.com/ECP-WarpX/picsar.git - git clone https://github.com/AMReX-Codes/amrex.git - git clone https://github.com/ECP-WarpX/perf_logs.git - -Then, in ``$AUTOMATED_PERF_TESTS``, create a file ``run_automated_performance_tests_512.sh`` with the following content: - -.. code-block:: sh - - #!/bin/bash -l - #BSUB -P APH114 - #BSUB -W 00:15 - #BSUB -nnodes 1 - #BSUB -J PERFTEST - #BSUB -e err_automated_tests.txt - #BSUB -o out_automated_tests.txt - - module load nano - module load cmake/3.20.2 - module load gcc/9.3.0 - module load cuda/11.0.3 - module load blaspp/2021.04.01 - module load lapackpp/2021.04.00 - module load boost/1.76.0 - module load adios2/2.7.1 - module load hdf5/1.12.2 - - module unload darshan-runtime - - export AMREX_CUDA_ARCH=7.0 - export CC=$(which gcc) - export CXX=$(which g++) - export FC=$(which gfortran) - export CUDACXX=$(which nvcc) - export CUDAHOSTCXX=$(which g++) - - # Make sure all dependencies are installed and loaded - cd $HOME - module load python/3.8.10 - module load freetype/2.10.4 # matplotlib - module load openblas/0.3.5-omp - export BLAS=$OLCF_OPENBLAS_ROOT/lib/libopenblas.so - export LAPACK=$OLCF_OPENBLAS_ROOT/lib/libopenblas.so - python3 -m pip install --user --upgrade pip - python3 -m pip install --user virtualenv - python3 -m venv $HOME/sw/venvs/warpx-perftest - source $HOME/sw/venvs/warpx-perftest/bin/activate - # While setting up the performance tests for the first time, - # execute the lines above this comment and then the commented - # lines below this comment once, before submission. - # The commented lines take too long for the job script. - #python3 -m pip install --upgrade pip - #python3 -m pip install --upgrade build packaging setuptools wheel - #python3 -m pip install --upgrade cython - #python3 -m pip install --upgrade numpy - #python3 -m pip install --upgrade markupsafe - #python3 -m pip install --upgrade pandas - #python3 -m pip install --upgrade matplotlib==3.2.2 # does not try to build freetype itself - #python3 -m pip install --upgrade bokeh - #python3 -m pip install --upgrade gitpython - #python3 -m pip install --upgrade tables - - # Run the performance test suite - cd $AUTOMATED_PERF_TESTS/warpx/Tools/PerformanceTests/ - python run_automated.py --n_node_list='1,2,8,64,256,512' --automated - - # submit next week's job - cd $AUTOMATED_PERF_TESTS/ - next_date=`date -d "+7 days" '+%Y:%m:%d:%H:%M'` - bsub -b $next_date ./run_automated_performance_tests_512.sh - -Then, running - -.. code-block:: sh - - bsub run_automated_performance_tests_512.sh - -will submit this job once, and all the following ones. It will: - - - Create directory ``$SCRATCH/performance_warpx`` if doesn't exist. - - Create 1 sub-directory per week per number of nodes (1,2,8,64,256,512). - - Submit one job per number of nodes. It will run 6 different tests, each twice (to detect fluctuations). - - Submit an analysis job, that will read the results ONLY AFTER all runs are finished. This uses the dependency feature of the batch system. - - This job reads the Tiny Profiler output for each run, and stores the results in a pandas file at the hdf5 format. - - Execute ``write_csv.py`` from the ``perf_logs`` repo to append a csv and a hdf5 file with the new results. - - Commit the results (but DO NOT PUSH YET) - -Then, the user periodically has to - -.. code-block:: sh - - cd $AUTOMATED_PERF_TESTS/perf_logs - git pull # to get updates from someone else, or from another supercomputer - git push - -This will update the database but not the online plots. For this, you need to periodically run something like - -.. code-block:: sh - - cd $AUTOMATED_PERF_TESTS/perf_logs - git pull - python generate_index_html.py - git add -u - git commit -m "upload new html page" - git push - -Setup on Cori @ NERSC ---------------------- - -Still to be written! diff --git a/Docs/source/theory/boosted_frame.rst b/Docs/source/theory/boosted_frame.rst index ea1f662bd30..04c30bedc98 100644 --- a/Docs/source/theory/boosted_frame.rst +++ b/Docs/source/theory/boosted_frame.rst @@ -12,7 +12,21 @@ The simulations of plasma accelerators from first principles are extremely compu A first principle simulation of a short driver beam (laser or charged particles) propagating through a plasma that is orders of magnitude longer necessitates a very large number of time steps. Recasting the simulation in a frame of reference that is moving close to the speed of light in the direction of the driver beam leads to simulating a driver beam that appears longer propagating through a plasma that appears shorter than in the laboratory. Thus, this relativistic transformation of space and time reduces the disparity of scales, and thereby the number of time steps to complete the simulation, by orders of magnitude. -Even using a moving window, however, a full PIC simulation of a plasma accelerator can be extraordinarily demanding computationally, as many time steps are needed to resolve the crossing of the short driver beam with the plasma column. As it turns out, choosing an optimal frame of reference that travels close to the speed of light in the direction of the laser or particle beam (as opposed to the usual choice of the laboratory frame) enables speedups by orders of magnitude :cite:p:`bf-Vayprl07,bf-Vaypop2011`. This is a result of the properties of Lorentz contraction and dilation of space and time. In the frame of the laboratory, a very short driver (laser or particle) beam propagates through a much longer plasma column, necessitating millions to tens of millions of time steps for parameters in the range of the BELLA or FACET-II experiments. As sketched in :numref:`fig_Boosted_frame`, in a frame moving with the driver beam in the plasma at velocity :math:`v=\beta c` (where :math:`c` is the speed of light in vacuum), the beam length is now elongated by :math:`\approx(1+\beta)\gamma` while the plasma contracts by :math:`\gamma` (where :math:`\gamma=1/\sqrt{1-\beta^2}` is the relativistic factor associated with the frame velocity). The number of time steps that is needed to simulate a “longer” beam through a “shorter” plasma is now reduced by up to :math:`\approx(1+\beta) \gamma^2` (a detailed derivation of the speedup is given below). +Even using a moving window, however, a full PIC simulation of a plasma accelerator can be extraordinarily demanding computationally, as many time steps are needed to resolve the crossing of the short driver beam with the plasma column. +As it turns out, choosing an optimal frame of reference that travels close to the speed of light in the direction of the laser or particle beam (as opposed to the usual choice of the laboratory frame) enables speedups by orders of magnitude :cite:p:`bf-Vayprl07,bf-Vaypop2011`. +This is a result of the properties of Lorentz contraction and dilation of space and time. +In the frame of the laboratory, a very short driver (laser or particle) beam propagates through a much longer plasma column, necessitating millions to tens of millions of time steps for parameters in the range of the BELLA or FACET-II experiments. +As sketched in :numref:`fig_Boosted_frame`, in a frame moving with the driver beam in the plasma at velocity :math:`v=\beta c` (where :math:`c` is the speed of light in vacuum), the beam length is now elongated by :math:`\approx(1+\beta)\gamma` while the plasma contracts by :math:`\gamma` (where :math:`\gamma=1/\sqrt{1-\beta^2}` is the relativistic factor associated with the frame velocity) +The number of time steps that is needed to simulate a “longer” beam through a “shorter” plasma is now reduced by up to :math:`\approx(1+\beta) \gamma^2` (a detailed derivation of the speedup is given below). + +.. note:: + + For additional reading on inputs and outputs in boosted frame simulations, consider the following pages: + + .. toctree:: + :maxdepth: 1 + + boosted_frame/input_output The modeling of a plasma acceleration stage in a boosted frame involves the fully electromagnetic modeling of a plasma propagating at near the speed of light, for which Numerical Cerenkov diff --git a/Docs/source/theory/Input_output.png b/Docs/source/theory/boosted_frame/Input_output.png similarity index 100% rename from Docs/source/theory/Input_output.png rename to Docs/source/theory/boosted_frame/Input_output.png diff --git a/Docs/source/theory/input_output.rst b/Docs/source/theory/boosted_frame/input_output.rst similarity index 99% rename from Docs/source/theory/input_output.rst rename to Docs/source/theory/boosted_frame/input_output.rst index 21a5f5c8d2c..f47915116df 100644 --- a/Docs/source/theory/input_output.rst +++ b/Docs/source/theory/boosted_frame/input_output.rst @@ -1,4 +1,4 @@ -.. _theory-io: +.. _boosted_frame-io: Inputs and Outputs ================== diff --git a/Docs/source/theory/kinetic_fluid_hybrid_model.rst b/Docs/source/theory/kinetic_fluid_hybrid_model.rst index b4f494d8382..f764ce4e02b 100644 --- a/Docs/source/theory/kinetic_fluid_hybrid_model.rst +++ b/Docs/source/theory/kinetic_fluid_hybrid_model.rst @@ -46,7 +46,7 @@ integrating over velocity), also called the generalized Ohm's law, is given by: .. math:: - en_e\vec{E} = \frac{m}{e}\frac{\partial \vec{J}_e}{\partial t} + \frac{m}{e^2}\left( \vec{U}_e\cdot\nabla \right) \vec{J}_e - \nabla\cdot {\overleftrightarrow P}_e - \vec{J}_e\times\vec{B}+\vec{R}_e + en_e\vec{E} = \frac{m}{e}\frac{\partial \vec{J}_e}{\partial t} + \frac{m}{e}\left( \vec{U}_e\cdot\nabla \right) \vec{J}_e - \nabla\cdot {\overleftrightarrow P}_e - \vec{J}_e\times\vec{B}+\vec{R}_e where :math:`\vec{U}_e = \vec{J}_e/(en_e)` is the electron fluid velocity, :math:`{\overleftrightarrow P}_e` is the electron pressure tensor and @@ -64,7 +64,7 @@ Plugging this back into the generalized Ohm' law gives: \left(en_e +\frac{m}{e\mu_0}\nabla\times\nabla\times\right)\vec{E} =& - \frac{m}{e}\left( \frac{\partial\vec{J}_{ext}}{\partial t} + \sum_{s\neq e}\frac{\partial\vec{J}_s}{\partial t} \right) \\ - &+ \frac{m}{e^2}\left( \vec{U}_e\cdot\nabla \right) \vec{J}_e - \nabla\cdot {\overleftrightarrow P}_e - \vec{J}_e\times\vec{B}+\vec{R}_e. + &+ \frac{m}{e}\left( \vec{U}_e\cdot\nabla \right) \vec{J}_e - \nabla\cdot {\overleftrightarrow P}_e - \vec{J}_e\times\vec{B}+\vec{R}_e. If we now further assume electrons are inertialess (i.e. :math:`m=0`), the above equation simplifies to, diff --git a/Docs/source/theory/collisions.rst b/Docs/source/theory/multiphysics/collisions.rst similarity index 97% rename from Docs/source/theory/collisions.rst rename to Docs/source/theory/multiphysics/collisions.rst index 52e36521125..08485345a13 100644 --- a/Docs/source/theory/collisions.rst +++ b/Docs/source/theory/multiphysics/collisions.rst @@ -1,4 +1,4 @@ -.. _theory-collisions: +.. _multiphysics-collisions: Collisions ========== @@ -8,7 +8,7 @@ including collisions between kinetic particles (Coulomb collisions, DSMC, nuclear fusion) as well as collisions between kinetic particles and a fixed (i.e. non-evolving) background species (MCC, background stopping). -.. _theory-collisions-mcc: +.. _multiphysics-collisions-mcc: Background Monte Carlo Collisions (MCC) --------------------------------------- @@ -45,14 +45,14 @@ where :math:`u` is the speed of the particle as tracked in WarpX (i.e. :math:`u = \gamma v` with :math:`v` the particle speed), while :math:`m` and :math:`M` are the rest masses of the simulation and background species, respectively. The Lorentz factor is defined in the usual way, -:math:`\gamma \def \sqrt{1 + u^2/c^2}`. Note that if :math:`\gamma\to1` the above +:math:`\gamma \equiv \sqrt{1 + u^2/c^2}`. Note that if :math:`\gamma\to1` the above expression reduces to the classical equation :math:`E_{coll} = \frac{1}{2}\frac{Mm}{M+m} u^2`. The collision cross-sections for all scattering processes are evaluated at the energy as calculated above. Once a particle is selected for a specific collision process, that process determines how the particle is scattered as outlined below. -.. _theory-collisions-dsmc: +.. _multiphysics-collisions-dsmc: Direct Simulation Monte Carlo (DSMC) ------------------------------------ diff --git a/Docs/source/theory/multiphysics/ionization.rst b/Docs/source/theory/multiphysics/ionization.rst new file mode 100644 index 00000000000..5003872b1a1 --- /dev/null +++ b/Docs/source/theory/multiphysics/ionization.rst @@ -0,0 +1,73 @@ +.. _multiphysics-ionization: + +Ionization +========== + +Field Ionization +---------------- + +Under the influence of a sufficiently strong external electric field atoms become ionized. +Particularly the dynamics of interactions between ultra-high intensity laser pulses and matter, e.g., Laser-Plasma Acceleration (LPA) with ionization injection, or Laser-Plasma Interactions with solid density targets (LPI) can depend on field ionization dynamics as well. + +WarpX models field ionization based on a description of the Ammosov-Delone-Krainov model:cite:p:`mpion-Ammosov1986` following :cite:t:`mpion-ChenPRSTAB13`. + +Implementation Details and Assumptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. note:: + + The current implementation makes the following assumptions + + * Energy for ionization processes is not removed from the electromagnetic fields + * Only one single-level ionization process can occur per macroparticle and time step + * Ionization happens at the beginning of the PIC loop before the field solve + * Angular momentum quantum number :math:`l = 0` and magnetic quantum number :math:`m = 0` + +The model implements the following equations (assumptions to :math:`l` and :math:`m` have already been applied). + +The electric field amplitude is calculated in the particle's frame of reference. + +.. math:: + + \begin{aligned} + \vec{E}_\mathrm{dc} &= \sqrt{ - \frac{1}{\mathrm{c}^2} \left( \vec{u} \cdot \vec{E} \right)^2 + + \left( \gamma \vec{E} + \vec{u} \times \vec{B} \right)^2 } + \\ + \gamma &= \sqrt{1 + \frac{\vec{u}^2}{\mathrm{c}^2}} + \end{aligned} + +Here, :math:`\vec{u} = (u_x, u_y, u_z)` is the momentum normalized to the particle mass, :math:`u_i = (\beta \gamma)_i \mathrm{c}`. +:math:`E_\mathrm{dc} = |\vec{E}_\mathrm{dc}|` is the DC-field in the frame of the particle. + +.. math:: + + \begin{aligned} + P &= 1 - \mathrm{e}^{-W\mathrm{d}\tau/\gamma} + \\ + W &= \omega_\mathrm{a} \mathcal{C}^2_{n^* l^*} \frac{U_\mathrm{ion}}{2 U_H} + \left[ 2 \frac{E_\mathrm{a}}{E_\mathrm{dc}} \left( \frac{U_\mathrm{ion}}{U_\mathrm{H}} \right)^{3/2} \right]^{2n^*-1} + \times \exp\left[ - \frac{2}{3} \frac{E_\mathrm{a}}{E_\mathrm{dc}} \left( \frac{U_\mathrm{ion}}{U_\mathrm{H}} \right)^{3/2} \right] + \\ + \mathcal{C}^2_{n^* l^*} &= \frac{2^{2n^*}}{n^* \Gamma(n^* + l^* + 1) \Gamma(n^* - l^*)} + \end{aligned} + +where :math:`\mathrm{d}\tau` is the simulation timestep, which is divided by the particle :math:`\gamma` to account for time dilation. The quantities are: :math:`\omega_\mathrm{a}`, the atomic unit frequency, :math:`U_\mathrm{ion}`, the ionization potential, :math:`U_\mathrm{H}`, Hydrogen ground state ionization potential, :math:`E_\mathrm{a}`, the atomic unit electric field, :math:`n^* = Z \sqrt{U_\mathrm{H}/U_\mathrm{ion}}`, the effective principal quantum number (*Attention!* :math:`Z` is the ionization state *after ionization*.) , :math:`l^* = n_0^* - 1`, the effective orbital quantum number. + +Empirical Extension to Over-the-Barrier Regime for Hydrogen +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +For hydrogen, WarpX offers the modified empirical ADK extension to the Over-the-Barrier (OTB) published in :cite:t:`mpion-zhang_empirical_2014` Eq. (8) (note there is a typo in the paper and there should not be a minus sign in Eq. 8). + +.. math:: + + W_\mathrm{M} = \exp\left[ a_1 \frac{E^2}{E_\mathrm{b}} + a_2 \frac{E}{E_\mathrm{b}} + a_3 \right] W_\mathrm{ADK} + +The parameters :math:`a_1` through :math:`a_3` are independent of :math:`E` and can be found in the same reference. :math:`E_\mathrm{b}` is the classical Barrier Suppresion Ionization (BSI) field strength :math:`E_\mathrm{b} = U_\mathrm{ion}^2 / (4 Z)` given here in atomic units (AU). For a detailed description of conversion between unit systems consider the book by :cite:t:`mpion-Mulser2010`. + +Testing +^^^^^^^ + +* `Testing the field ionization module <../../../../en/latest/usage/examples/field_ionization/README.html>`_. + +.. bibliography:: + :keyprefix: mpion- diff --git a/Docs/source/developers/qed.rst b/Docs/source/theory/multiphysics/qed.rst similarity index 86% rename from Docs/source/developers/qed.rst rename to Docs/source/theory/multiphysics/qed.rst index f509d6ea386..3e961bb2898 100644 --- a/Docs/source/developers/qed.rst +++ b/Docs/source/theory/multiphysics/qed.rst @@ -1,7 +1,7 @@ -.. _developers-qed: +.. _multiphysics-qed: -QED -==================== +Quantum Electrodynamics (QED) +============================= Quantum synchrotron ------------------- @@ -28,7 +28,8 @@ electron-positron pairs can be created in vacuum in the function ``MultiParticleContainer::doQEDSchwinger`` in turn calls the function ``filterCreateTransformFromFAB``: -.. doxygenfunction:: filterCreateTransformFromFAB(DstTile&, DstTile&, const amrex::Box, const FABs&, const Index, const Index, FilterFunc&&, CreateFunc1&&, CreateFunc2&&, TransFunc&&) +Filter Create Transform Function +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``filterCreateTransformFromFAB`` proceeds in three steps. In the filter phase, we loop on every cell and calculate the number of physical pairs created within diff --git a/Docs/source/theory/multiphysics_extensions.rst b/Docs/source/theory/multiphysics_extensions.rst new file mode 100644 index 00000000000..6c9ab040ef2 --- /dev/null +++ b/Docs/source/theory/multiphysics_extensions.rst @@ -0,0 +1,13 @@ +.. _theory-multiphysics: + +Multi-Physics Extensions +======================== + +WarpX includes various extensions to the traditional PIC loop which enable it to model additional physics. + +.. toctree:: + :maxdepth: 1 + + multiphysics/collisions + multiphysics/ionization + multiphysics/qed diff --git a/Docs/source/theory/pic.rst b/Docs/source/theory/pic.rst index 820cdba50e6..8356ba9f0f8 100644 --- a/Docs/source/theory/pic.rst +++ b/Docs/source/theory/pic.rst @@ -434,6 +434,83 @@ of this model can be found in the section .. _current_deposition: +Pseudo Spectral Analytical Time Domain with arbitrary charge and current-density time dependencies (PSATD-JRhom) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In :cite:`pt-shapovalPRE2024` we introduce a formulation of the particle-in-cell (PIC) method for the modeling of relativistic plasmas, which leverages the ability of the pseudo-spectral analytical time-domain solver (PSATD) to handle arbitrary time dependencies of the charge and current densities during one PIC cycle (up to second-order polynomial dependencies here). +The formulation is applied to a modified set of Maxwell's equations, which in Fourier space reads + +.. math:: + + \begin{align} + \frac{\partial\boldsymbol{\widetilde{E}}}{\partial t} & = i\boldsymbol{k}\times\boldsymbol{\widetilde{B}}-\boldsymbol{\widetilde{J}} + i\boldsymbol{k}{\widetilde{F}} \,, \\ + \frac{\partial\boldsymbol{\widetilde{B}}}{\partial t} & = -i\boldsymbol{k}\times\boldsymbol{\widetilde{E}} \,, \\ + \frac{\partial{\widetilde{F}}}{\partial t} & = i\boldsymbol{k}\cdot\boldsymbol{\widetilde{E}} - \widetilde{\rho} \,. + \end{align} + +Here, in addition to the usual Maxwell-Faraday and Ampere-Maxwell equations, the system contains an extra equation for the scalar field :math:`\widetilde{F}`, which propagates deviations to Gauss' law (if Gauss' law is verified in the PIC simulation, :math:`\widetilde{F}=0` and the modified Maxwell’s equations reduce to the standard Maxwell's equations). +These additional terms were introduced in :cite:p:`pt-Vayfed1996,pt-Munzjcp2000` from the potential formulation in the Lorenz gauge and used as a propagative divergence cleaning procedure, as an alternative to the Langdon-Marder :cite:p:`pt-Langdoncpc92,pt-Marderjcp87` diffusive procedures. +The above-mentioned earlier works :cite:p:`pt-Vayfed1996,pt-Munzjcp2000` considered this formulation in the context of the standard PIC method using FDTD discretization, while the PSATD-JRhom method introduced in :cite:`pt-shapovalPRE2024` exploits the PSATD discretization of the modified Maxwell's equations. +In contrast to the standard PSATD algorithm :cite:p:`pt-VayJCP2013`, where :math:`\boldsymbol{\widetilde{J}}` is assumed to be constant in time and :math:`\widetilde{\rho}` is assumed to be linear in time, within a given time step :math:`\Delta t`, the PSATD-JRhom provides more general time dependencies for :math:`\boldsymbol{\widetilde{J}}` and :math:`\widetilde{\rho}` within one timestep, which can be divided into :math:`m` subintervals of equal size :math:`\delta t = \Delta t/m`. +During these subintervals, :math:`\boldsymbol{\widetilde{J}}` and :math:`\widetilde{\rho}` are considered to be either **piecewise constant** (macro-particles deposit their density in the middle of each time subinterval), **piecewise linear** (macro-particles deposit their density at the edge of each time subinterval), or **piecewise quadratic** (macro-particles deposit their density at the edge of each time subinterval) in time. + +.. _fig-psatd_jrhom: + +.. figure:: https://gist.githubusercontent.com/oshapoval/88a73cada764364ad4ffce13563cedf1/raw/697ce1897cde0416bebdde8f1c1e8fcf859cb419/psatd_jrhom.png + :alt: figure not found, caption only + + Diagrams illustrating various time dependencies of the current density :math:`\boldsymbol{\widetilde{J}}` and charge density :math:`\widetilde{\rho}` for constant/linear (CL), both constant (CC), linear (LL) and quadratic (QQ) dependencies with :math:`m` subintervals: (first column) :math:`m=1`, (second) :math:`m=2` and (third) :math:`m=4`. CL1 corresponds to the standard PSATD PIC method. The triangle and circle glyphs represent the times at which the macroparticles deposit :math:`\boldsymbol{\widetilde{J}}` and :math:`\widetilde{\rho}` on the grid, respectively. The dashed and solid lines represent the assumed time dependency of :math:`\boldsymbol{\widetilde{J}}` and :math:`\widetilde{\rho}` within one time step, when integrating the Maxwell equations analytically. + +Using the piecewise definition of :math:`\widetilde{\rho}` and :math:`\boldsymbol{\widetilde{J}}`, the modified Maxwell's equations can be integrated analytically over one time step :math:`\Delta t`, i.e., from :math:`t=n\Delta t` to :math:`t=(n+1)\Delta t`. +In practice, this is done by sequentially integrating these equations over each subinterval :math:`\ell \in [0,m-1]`. +The final discretized equations write as: + +.. math:: + + \begin{align} + \begin{split} + \boldsymbol{\widetilde{E}}^{n+(\ell+1)/m} & = C{\boldsymbol{\widetilde{J}}}^{n+\ell/m}+ic^2\frac{S}{ck}\boldsymbol{k}\times{\boldsymbol{\widetilde{J}}}^{n+\ell/m}+ic^2\frac{S}{ck}\widetilde{F}^{n+\ell/m}\boldsymbol{k} \\ + &\quad + \frac{1}{\varepsilon_0 ck}\left(Y_3\boldsymbol{a_J} + Y_2\boldsymbol{b_J} - S\boldsymbol{c_J}\right) + + \frac{ic^2}{\varepsilon_0 c^2k^2}\left({Y_1}a_{\rho}-Y_{5}b_{\rho}-Y_{4}c_{\rho}\right)\boldsymbol{k}, + \end{split} + \\[4pt] + \begin{split} + \boldsymbol{\widetilde{B}}^{n+(\ell+1)/m} & = C {\boldsymbol{\widetilde{B}}}^{n+\ell/m}-i\frac{S}{ck}\boldsymbol{k}\times{\boldsymbol{\widetilde{E}}}^{n+\ell/m} - \frac{i}{\varepsilon_0 c^2k^2}\boldsymbol{k}\times\left(Y_1\boldsymbol{a_J} -Y_5\boldsymbol{b_J} -Y_4\boldsymbol{c_J} \right), + \end{split} + \\[4pt] + \begin{split} + \widetilde{F}^{n+(\ell+1)/m} & = C \widetilde{F}^{n+\ell/m}+i\frac{S}{ck}\boldsymbol{k} \cdot {\boldsymbol{\widetilde{E}}}^{n+\ell/m}+\frac{i}{\varepsilon_0 c^2k^2}\boldsymbol{k}\cdot\left(Y_1\boldsymbol{a_J}-Y_5\boldsymbol{b_J}-Y_4\boldsymbol{c_J}\right) \\ + &\quad + \frac{1}{\varepsilon_0 ck}\left({Y_3}a_{\rho}+{Y_2}b_{\rho}-Sc_{\rho}\right), + \end{split} + \end{align} + +where + +.. math:: + + \begin{aligned} + C &= \cos(ck\delta t), \ S = \sin(ck\delta t), + \\ + Y_1 & = \frac{(1-C)(8-c^2k^2\delta t^2)-4Sck\delta t}{2 c^2 k^2 \delta t^2}, + \\ + Y_2 & = \frac{2(C-1)+ S ck\delta t }{2 ck\delta t}, + \\ + Y_3 & = \frac{S(8- c^2k^2\delta t^2 ) - 4ck\delta t(1+C)}{2c^2 k^2 \delta t^2}, + \\ + Y_4 &= (1-C), \ Y_5 = \frac{(1+C) ck\delta t - 2S}{2ck \delta t}. + \end{aligned} + +Here, :math:`\boldsymbol{a_J}, \boldsymbol{b_J}, \boldsymbol{c_J}, a_{\rho}, b_{\rho}, c_{\rho}` are polynomial coefficients based on the time dependencies of the current and charge densities, as shown in the following table: + +.. _fig-j_rho_table: + +.. figure:: + https://gist.githubusercontent.com/oshapoval/88a73cada764364ad4ffce13563cedf1/raw/ebc249f8e875a952c65a5319fd523821baccfd5a/j_rho_table.png + :alt: figure not found, caption only + + Polynomial coefficients based on the time dependency of the current and charge densities :math:`{\boldsymbol{\widetilde{J}}}(t)` and :math:`\widetilde{\rho}(t)` over one time subinterval, :math:`\delta t = \Delta t/m`. + +Detailed analysis and tests revealed that, under certain conditions, the formulation can expand the range of numerical parameters under which PIC simulations are stable and accurate when modeling relativistic plasmas, such as, e.g., plasma-based particle accelerators. + Current deposition ------------------ diff --git a/Docs/source/usage/examples.rst b/Docs/source/usage/examples.rst index 0492372b4e6..f1bd2ec4266 100644 --- a/Docs/source/usage/examples.rst +++ b/Docs/source/usage/examples.rst @@ -43,7 +43,7 @@ Particle Accelerator & Beam Physics :maxdepth: 1 examples/gaussian_beam/README.rst - examples/beam-beam_collision/README.rst + examples/beam_beam_collision/README.rst High Energy Astrophysical Plasma Physics @@ -101,7 +101,7 @@ examples below were generated at that time. .. toctree:: :maxdepth: 1 - examples/ohm_solver_EM_modes/README.rst + examples/ohm_solver_em_modes/README.rst examples/ohm_solver_ion_beam_instability/README.rst examples/ohm_solver_ion_Landau_damping/README.rst @@ -127,16 +127,21 @@ Manipulating fields via Python An example of using Python to access the simulation charge density, solve the Poisson equation (using ``superLU``) and write the resulting electrostatic potential back to the simulation is given in the input file below. This example uses the ``fields.py`` module included in the ``pywarpx`` library. -* :download:`Direct Poisson solver example <../../../Examples/Physics_applications/capacitive_discharge/PICMI_inputs_2d.py>` +* :download:`Direct Poisson solver example <../../../Examples/Physics_applications/capacitive_discharge/inputs_test_2d_background_mcc_picmi.py>` An example of initializing the fields by accessing their data through Python, advancing the simulation for a chosen number of time steps, and plotting the fields again through Python. The simulation runs with 128 regular cells, 8 guard cells, and 10 PML cells, in each direction. Moreover, it uses div(E) and div(B) cleaning both in the regular grid and in the PML and initializes all available electromagnetic fields (E,B,F,G) identically. -* :download:`Unit pulse with PML <../../../Examples/Tests/python_wrappers/PICMI_inputs_2d.py>` +* :download:`Unit pulse with PML <../../../Examples/Tests/python_wrappers/inputs_test_2d_python_wrappers_picmi.py>` Many Further Examples, Demos and Tests -------------------------------------- +.. toctree:: + :maxdepth: 1 + + examples/field_ionization/README.rst + WarpX runs over 200 integration tests on a variety of modeling cases, which validate and demonstrate its functionality. Please see the `Examples/Tests/ `__ directory for many more examples. diff --git a/Docs/source/usage/examples/beam-beam_collision b/Docs/source/usage/examples/beam-beam_collision deleted file mode 120000 index 8c6ac6b30b1..00000000000 --- a/Docs/source/usage/examples/beam-beam_collision +++ /dev/null @@ -1 +0,0 @@ -../../../../Examples/Physics_applications/beam-beam_collision \ No newline at end of file diff --git a/Docs/source/usage/examples/beam_beam_collision b/Docs/source/usage/examples/beam_beam_collision new file mode 120000 index 00000000000..2f46224fd8b --- /dev/null +++ b/Docs/source/usage/examples/beam_beam_collision @@ -0,0 +1 @@ +../../../../Examples/Physics_applications/beam_beam_collision/ \ No newline at end of file diff --git a/Docs/source/usage/examples/field_ionization b/Docs/source/usage/examples/field_ionization new file mode 120000 index 00000000000..b1c3e38dab2 --- /dev/null +++ b/Docs/source/usage/examples/field_ionization @@ -0,0 +1 @@ +../../../../Examples/Tests/field_ionization/ \ No newline at end of file diff --git a/Docs/source/usage/examples/ohm_solver_EM_modes b/Docs/source/usage/examples/ohm_solver_EM_modes deleted file mode 120000 index 485be7241ae..00000000000 --- a/Docs/source/usage/examples/ohm_solver_EM_modes +++ /dev/null @@ -1 +0,0 @@ -../../../../Examples/Tests/ohm_solver_EM_modes \ No newline at end of file diff --git a/Docs/source/usage/examples/ohm_solver_em_modes b/Docs/source/usage/examples/ohm_solver_em_modes new file mode 120000 index 00000000000..03214170a1f --- /dev/null +++ b/Docs/source/usage/examples/ohm_solver_em_modes @@ -0,0 +1 @@ +../../../../Examples/Tests/ohm_solver_em_modes/ \ No newline at end of file diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 4a8c4be0b5f..86ab7594c5f 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -590,14 +590,15 @@ In WarpX, the embedded boundary can be defined in either of two ways: A function of `x`, `y`, `z` that defines the surface of the embedded boundary. That surface lies where the function value is 0 ; the physics simulation area is where the function value is negative ; - the interior of the embeddded boundary is where the function value is positive. + the interior of the embedded boundary is where the function value is positive. - **From an STL file:** In that case, you will need to set the following parameters in the input file. * ``eb2.stl_file`` (`string`) - The path to an STL file. In addition, you also need to set ``eb2.geom_type = stl``, - in order for the file to be read by WarpX. + The path to an `STL file `__. + In addition, you also need to set ``eb2.geom_type = stl``, in order for the file to be read by WarpX. + `See the AMReX documentation for more details `__. Whether the embedded boundary is defined with an analytical function or an STL file, you can additionally define the electric potential at the embedded boundary with an analytical function: @@ -733,6 +734,14 @@ Distribution across MPI ranks and parallelization * ``warpx.do_dynamic_scheduling`` (`0` or `1`) optional (default `1`) Whether to activate OpenMP dynamic scheduling. +* ``warpx.roundrobin_sfc`` (`0` or `1`) optional (default `0`) + Whether to use AMReX's RRSFS strategy for making DistributionMapping to + override the default space filling curve (SFC) strategy. If this is + enabled, the round robin method is used to distribute Boxes ordered by + SFC. This could potentially mitigate the load imbalance issue during + initialization by avoiding putting neighboring boxes on the same + process. + .. _running-cpp-parameters-parser: Math parser and user-defined constants @@ -812,7 +821,7 @@ Particle initialization * ``particles.rigid_injected_species`` (`strings`, separated by spaces) List of species injected using the rigid injection method. The rigid injection method is useful when injecting a relativistic particle beam in boosted-frame - simulations; see the :ref:`input-output section ` for more details. + simulations; see the :ref:`input-output section ` for more details. For species injected using this method, particles are translated along the `+z` axis with constant velocity as long as their ``z`` coordinate verifies ``zzinject_plane``, @@ -1944,7 +1953,7 @@ Collision models ---------------- WarpX provides several particle collision models, using varying degrees of approximation. -Details about the collision models can be found in the :ref:`theory section `. +Details about the collision models can be found in the :ref:`theory section `. * ``collisions.collision_names`` (`strings`, separated by spaces) The name of each collision type. @@ -1967,10 +1976,10 @@ Details about the collision models can be found in the :ref:`theory section .species_type = 'deuterium'``) - ``dsmc`` for pair-wise, non-Coulomb collisions between kinetic species. This is a "direct simulation Monte Carlo" treatment of collisions between - kinetic species. See :ref:`DSMC section `. + kinetic species. See :ref:`DSMC section `. - ``background_mcc`` for collisions between particles and a neutral background. This is a relativistic Monte Carlo treatment for particles colliding - with a neutral background gas. See :ref:`MCC section `. + with a neutral background gas. See :ref:`MCC section `. - ``background_stopping`` for slowing of ions due to collisions with electrons or ions. This implements the approximate formulae as derived in Introduction to Plasma Physics, from Goldston and Rutherford, section 14.2. @@ -2494,6 +2503,10 @@ Additional parameters to propagate (at the speed of light) to the boundaries of the simulation domain, where it can be absorbed. +* ``warpx.do_divb_cleaning_external`` (`0` or `1` ; default: 0) + Whether to use projection method to scrub B field divergence in externally + loaded fields. This is automatically turned on if external B fields are loaded. + * ``warpx.do_subcycling`` (`0` or `1`; default: 0) Whether or not to use sub-cycling. Different refinement levels have a different cell size, which results in different Courant–Friedrichs–Lewy @@ -3435,6 +3448,40 @@ Reduced Diagnostics For 1D-Z, :math:`x`-related and :math:`y`-related quantities are not outputted. RZ geometry is not supported yet. +* ``DifferentialLuminosity`` + This type computes the differential luminosity between two species, defined as: + + .. math:: + + \frac{d\mathcal{L}}{d\mathcal{E}^*}(\mathcal{E}^*, t) = \int_0^t dt'\int d\boldsymbol{x}\,d\boldsymbol{p}_1 d\boldsymbol{p}_2\; + \sqrt{ |\boldsymbol{v}_1 - \boldsymbol{v}_2|^2 - |\boldsymbol{v}_1\times\boldsymbol{v}_2|^2/c^2} \\ f_1(\boldsymbol{x}, \boldsymbol{p}_1, t')f_2(\boldsymbol{x}, \boldsymbol{p}_2, t') \delta(\mathcal{E}^* - \mathcal{E}^*(\boldsymbol{p}_1, \boldsymbol{p}_2)) + + where :math:`\mathcal{E}^*(\boldsymbol{p}_1, \boldsymbol{p}_2) = \sqrt{m_1^2c^4 + m_2^2c^4 + 2(m_1 m_2 c^4 + \gamma_1 \gamma_2 - \boldsymbol{p}_1\cdot\boldsymbol{p}_2 c^2)}` is the energy in the center-of-mass frame, + and :math:`f_i` is the distribution function of species :math:`i`. Note that, if :math:`\sigma^*(\mathcal{E}^*)` + is the center-of-mass cross-section of a given collision process, then + :math:`\int d\mathcal{E}^* \frac{d\mathcal{L}}{d\mathcal{E}^*} (\mathcal{E}^*, t)\sigma^*(\mathcal{E}^*)` + gives the total number of collisions of that process (from the beginning of the simulation up until time :math:`t`). + + The differential luminosity is given in units of :math:`\text{m}^{-2}.\text{eV}^{-1}`. For collider-relevant WarpX simulations + involving two crossing, high-energy beams of particles, the differential luminosity in :math:`\text{s}^{-1}.\text{m}^{-2}.\text{eV}^{-1}` + can be obtained by multiplying the above differential luminosity by the expected repetition rate of the beams. + + In practice, the above expression of the differential luminosity is evaluated over discrete bins in energy :math:`\mathcal{E}^*`, + and by summing over macroparticles. + + * ``.species`` (`list of two strings`) + The names of the two species for which the differential luminosity is computed. + + * ``.bin_number`` (`int` > 0) + The number of bins in energy :math:`\mathcal{E}^*` + + * ``.bin_max`` (`float`, in eV) + The minimum value of :math:`\mathcal{E}^*` for which the differential luminosity is computed. + + * ``.bin_min`` (`float`, in eV) + The maximum value of :math:`\mathcal{E}^*` for which the differential luminosity is computed. + * ``.intervals`` (`string`) Using the `Intervals Parser`_ syntax, this string defines the timesteps at which reduced diagnostics are written to file. diff --git a/Docs/source/usage/pwfa.rst b/Docs/source/usage/pwfa.rst index 5119184089c..1d3481b5589 100644 --- a/Docs/source/usage/pwfa.rst +++ b/Docs/source/usage/pwfa.rst @@ -5,7 +5,7 @@ In-Depth: PWFA As described in the :doc:`../theory/intro`, one of the key applications of the WarpX exascale computing platform is in modelling future, compact and economic plasma-based accelerators. In this section we describe the simulation setup of a realistic *electron beam driven plasma wakefield accelerator* (PWFA) configuration. -For illustration purposes the setup can be explored with **WarpX** using the example input file :download:`PWFA <../../../Examples/Physics_applications/plasma_acceleration/inputs_2d_boost>`. +For illustration purposes the setup can be explored with **WarpX** using the example input file :download:`PWFA <../../../Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_boosted>`. The simulation setup consists of 4 particle species: drive beam (driver), witness beam (beam), plasma electrons (plasma_e), and plasma ions (plasma_p). The species physical parameters are summarized in the following table. diff --git a/Docs/source/usage/python.rst b/Docs/source/usage/python.rst index 4d53b311764..38b0a31d7f3 100644 --- a/Docs/source/usage/python.rst +++ b/Docs/source/usage/python.rst @@ -53,6 +53,30 @@ Field solvers define the updates of electric and magnetic fields. .. autoclass:: pywarpx.picmi.ElectrostaticSolver +Object that allows smoothing of fields. + +.. autoclass:: pywarpx.picmi.BinomialSmoother + +Evolve Schemes +-------------- + +These define the scheme use to evolve the fields and particles. +An instance of one of these would be passed as the `evolve_scheme` into the `Simulation`. + +.. autoclass:: pywarpx.picmi.ExplicitEvolveScheme + +.. autoclass:: pywarpx.picmi.ThetaImplicitEMEvolveScheme + +.. autoclass:: pywarpx.picmi.SemiImplicitEMEvolveScheme + +There are several support classes use to specify components of the evolve schemes + +.. autoclass:: pywarpx.picmi.PicardNonlinearSolver + +.. autoclass:: pywarpx.picmi.NewtonNonlinearSolver + +.. autoclass:: pywarpx.picmi.GMRESLinearSolver + Constants --------- diff --git a/Docs/source/usage/workflows/ml_materials/create_dataset.py b/Docs/source/usage/workflows/ml_materials/create_dataset.py index ecd182c8802..aefae201617 100644 --- a/Docs/source/usage/workflows/ml_materials/create_dataset.py +++ b/Docs/source/usage/workflows/ml_materials/create_dataset.py @@ -19,28 +19,31 @@ c = 2.998e8 ############### + def sanitize_dir_strings(*dir_strings): - """append '/' to a string for concatenation in building up file tree descriptions - """ + """append '/' to a string for concatenation in building up file tree descriptions""" dir_strings = list(dir_strings) for ii, dir_string in enumerate(dir_strings): - if dir_string[-1] != '/': - dir_strings[ii] = dir_string + '/' + if dir_string[-1] != "/": + dir_strings[ii] = dir_string + "/" return dir_strings + def download_and_unzip(url, data_dir): request.urlretrieve(url, data_dir) - with zipfile.ZipFile(data_dir, 'r') as zip_dataset: + with zipfile.ZipFile(data_dir, "r") as zip_dataset: zip_dataset.extractall() -def create_source_target_data(data_dir, - species, - source_index=0, - target_index=-1, - survivor_select_index=-1, - particle_selection=None - ): + +def create_source_target_data( + data_dir, + species, + source_index=0, + target_index=-1, + survivor_select_index=-1, + particle_selection=None, +): """Create dataset from openPMD files Parameters @@ -60,35 +63,38 @@ def create_source_target_data(data_dir, target_stds: 6 element array of source particle coordinate standard deviations relevant times: 2 element array of source and target times """ - data_dir, = sanitize_dir_strings(data_dir) + (data_dir,) = sanitize_dir_strings(data_dir) data_path = data_dir - print('loading openPMD data from', data_path) + print("loading openPMD data from", data_path) ts = OpenPMDTimeSeries(data_path) relevant_times = [ts.t[source_index], ts.t[target_index]] # Manual: Particle tracking START iteration = ts.iterations[survivor_select_index] - pt = ParticleTracker( ts, - species=species, - iteration=iteration, - select=particle_selection) + pt = ParticleTracker( + ts, species=species, iteration=iteration, select=particle_selection + ) # Manual: Particle tracking END #### create normalized source, target data sets #### - print('creating data sets') + print("creating data sets") # Manual: Load openPMD START iteration = ts.iterations[source_index] - source_data = ts.get_particle(species=species, - iteration=iteration, - var_list=['x','y','z','ux','uy','uz'], - select=pt) + source_data = ts.get_particle( + species=species, + iteration=iteration, + var_list=["x", "y", "z", "ux", "uy", "uz"], + select=pt, + ) iteration = ts.iterations[target_index] - target_data = ts.get_particle(species=species, - iteration=iteration, - var_list=['x','y','z','ux','uy','uz'], - select=pt) + target_data = ts.get_particle( + species=species, + iteration=iteration, + var_list=["x", "y", "z", "ux", "uy", "uz"], + select=pt, + ) # Manual: Load openPMD END # Manual: Normalization START @@ -114,51 +120,75 @@ def create_source_target_data(data_dir, target_data = torch.tensor(np.column_stack(target_data)) # Manual: Format data END - return source_data, source_means, source_stds, target_data, target_means, target_stds, relevant_times + return ( + source_data, + source_means, + source_stds, + target_data, + target_means, + target_stds, + relevant_times, + ) -def save_warpx_surrogate_data(dataset_fullpath_filename, - diag_dir, - species, - training_frac, - batch_size, - source_index, - target_index, - survivor_select_index, - particle_selection=None - ): +def save_warpx_surrogate_data( + dataset_fullpath_filename, + diag_dir, + species, + training_frac, + batch_size, + source_index, + target_index, + survivor_select_index, + particle_selection=None, +): source_target_data = create_source_target_data( data_dir=diag_dir, species=species, source_index=source_index, target_index=target_index, survivor_select_index=survivor_select_index, - particle_selection=particle_selection + particle_selection=particle_selection, ) - source_data, source_means, source_stds, target_data, target_means, target_stds, times = source_target_data + ( + source_data, + source_means, + source_stds, + target_data, + target_means, + target_stds, + times, + ) = source_target_data # Manual: Save dataset START - full_dataset = torch.utils.data.TensorDataset(source_data.float(), target_data.float()) + full_dataset = torch.utils.data.TensorDataset( + source_data.float(), target_data.float() + ) n_samples = full_dataset.tensors[0].size(0) - n_train = int(training_frac*n_samples) + n_train = int(training_frac * n_samples) n_test = n_samples - n_train - train_data, test_data = torch.utils.data.random_split(full_dataset, [n_train, n_test]) - - torch.save({'dataset':full_dataset, - 'train_indices':train_data.indices, - 'test_indices':test_data.indices, - 'source_means':source_means, - 'source_stds':source_stds, - 'target_means':target_means, - 'target_stds':target_stds, - 'times':times, - }, - dataset_fullpath_filename - ) + train_data, test_data = torch.utils.data.random_split( + full_dataset, [n_train, n_test] + ) + + torch.save( + { + "dataset": full_dataset, + "train_indices": train_data.indices, + "test_indices": test_data.indices, + "source_means": source_means, + "source_stds": source_stds, + "target_means": target_means, + "target_stds": target_stds, + "times": times, + }, + dataset_fullpath_filename, + ) # Manual: Save dataset END + ######## end utility functions ############# ######## start dataset creation ############ @@ -171,38 +201,40 @@ def save_warpx_surrogate_data(dataset_fullpath_filename, source_index = 0 target_index = 1 survivor_select_index = 1 -batch_size=1200 +batch_size = 1200 training_frac = 0.7 -os.makedirs('datasets', exist_ok=True) +os.makedirs("datasets", exist_ok=True) # improve stage 0 dataset stage_i = 0 -select = {'z':[0.280025, None]} -species = f'beam_stage_{stage_i}' -dataset_filename = f'dataset_{species}.pt' -dataset_file = 'datasets/' + dataset_filename -save_warpx_surrogate_data(dataset_fullpath_filename=dataset_file, - diag_dir=data_dir, - species=species, - training_frac=training_frac, - batch_size=batch_size, - source_index=source_index, - target_index=target_index, - survivor_select_index=survivor_select_index, - particle_selection=select - ) - -for stage_i in range(1,15): - species = f'beam_stage_{stage_i}' - dataset_filename = f'dataset_{species}.pt' - dataset_file = 'datasets/' + dataset_filename - save_warpx_surrogate_data(dataset_fullpath_filename=dataset_file, - diag_dir=data_dir, - species=species, - training_frac=training_frac, - batch_size=batch_size, - source_index=source_index, - target_index=target_index, - survivor_select_index=survivor_select_index - ) +select = {"z": [0.280025, None]} +species = f"beam_stage_{stage_i}" +dataset_filename = f"dataset_{species}.pt" +dataset_file = "datasets/" + dataset_filename +save_warpx_surrogate_data( + dataset_fullpath_filename=dataset_file, + diag_dir=data_dir, + species=species, + training_frac=training_frac, + batch_size=batch_size, + source_index=source_index, + target_index=target_index, + survivor_select_index=survivor_select_index, + particle_selection=select, +) + +for stage_i in range(1, 15): + species = f"beam_stage_{stage_i}" + dataset_filename = f"dataset_{species}.pt" + dataset_file = "datasets/" + dataset_filename + save_warpx_surrogate_data( + dataset_fullpath_filename=dataset_file, + diag_dir=data_dir, + species=species, + training_frac=training_frac, + batch_size=batch_size, + source_index=source_index, + target_index=target_index, + survivor_select_index=survivor_select_index, + ) diff --git a/Docs/source/usage/workflows/ml_materials/neural_network_classes.py b/Docs/source/usage/workflows/ml_materials/neural_network_classes.py index 58b51a1d364..91090ffae3d 100644 --- a/Docs/source/usage/workflows/ml_materials/neural_network_classes.py +++ b/Docs/source/usage/workflows/ml_materials/neural_network_classes.py @@ -16,11 +16,13 @@ class ActivationType(Enum): """ Activation class provides an enumeration type for the supported activation layers """ + ReLU = 1 Tanh = 2 PReLU = 3 Sigmoid = 4 + def get_enum_type(type_to_test, EnumClass): """ Returns the enumeration type associated to type_to_test in EnumClass @@ -42,28 +44,25 @@ def get_enum_type(type_to_test, EnumClass): raise Exception("unsupported type entered") - class ConnectedNN(nn.Module): """ ConnectedNN is a class of fully connected neural networks """ + def __init__(self, layers): super().__init__() self.stack = nn.Sequential(*layers) + def forward(self, x): return self.stack(x) + class OneActNN(ConnectedNN): """ OneActNN is class of fully connected neural networks admitting only one activation function """ - def __init__(self, - n_in, - n_out, - n_hidden_nodes, - n_hidden_layers, - act): + def __init__(self, n_in, n_out, n_hidden_nodes, n_hidden_layers, act): self.n_in = n_in self.n_out = n_out self.n_hidden_layers = n_hidden_layers @@ -84,7 +83,7 @@ def __init__(self, layers += [nn.Sigmoid()] if ii < self.n_hidden_layers - 1: - layers += [nn.Linear(self.n_hidden_nodes,self.n_hidden_nodes)] + layers += [nn.Linear(self.n_hidden_nodes, self.n_hidden_nodes)] layers += [nn.Linear(self.n_hidden_nodes, self.n_out)] diff --git a/Docs/source/usage/workflows/ml_materials/run_warpx_training.py b/Docs/source/usage/workflows/ml_materials/run_warpx_training.py index 054c1b4cfc0..9e6b5682ec7 100644 --- a/Docs/source/usage/workflows/ml_materials/run_warpx_training.py +++ b/Docs/source/usage/workflows/ml_materials/run_warpx_training.py @@ -13,66 +13,68 @@ ep0 = picmi.constants.ep0 # Number of cells -dim = '3' +dim = "3" nx = ny = 128 -nz = 35328 #17664 #8832 -if dim == 'rz': - nr = nx//2 +nz = 35328 # 17664 #8832 +if dim == "rz": + nr = nx // 2 # Computational domain -rmin = 0. -rmax = 128e-6 +rmin = 0.0 +rmax = 128e-6 zmin = -180e-6 -zmax = 0. +zmax = 0.0 # Number of processes for static load balancing # Check with your submit script -num_procs = [1, 1, 64*4] -if dim == 'rz': +num_procs = [1, 1, 64 * 4] +if dim == "rz": num_procs = [1, 64] # Number of time steps -gamma_boost = 60. -beta_boost = np.sqrt(1.-gamma_boost**-2) +gamma_boost = 60.0 +beta_boost = np.sqrt(1.0 - gamma_boost**-2) # Create grid -if dim == 'rz': +if dim == "rz": grid = picmi.CylindricalGrid( number_of_cells=[nr, nz], guard_cells=[32, 32], n_azimuthal_modes=2, lower_bound=[rmin, zmin], upper_bound=[rmax, zmax], - lower_boundary_conditions=['none', 'damped'], - upper_boundary_conditions=['none', 'damped'], - lower_boundary_conditions_particles=['absorbing', 'absorbing'], - upper_boundary_conditions_particles=['absorbing', 'absorbing'], - moving_window_velocity=[0., c], + lower_boundary_conditions=["none", "damped"], + upper_boundary_conditions=["none", "damped"], + lower_boundary_conditions_particles=["absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing"], + moving_window_velocity=[0.0, c], warpx_max_grid_size=256, - warpx_blocking_factor=64) + warpx_blocking_factor=64, + ) else: grid = picmi.Cartesian3DGrid( number_of_cells=[nx, ny, nz], guard_cells=[11, 11, 12], lower_bound=[-rmax, -rmax, zmin], upper_bound=[rmax, rmax, zmax], - lower_boundary_conditions=['periodic', 'periodic', 'damped'], - upper_boundary_conditions=['periodic', 'periodic', 'damped'], - lower_boundary_conditions_particles=['periodic', 'periodic', 'absorbing'], - upper_boundary_conditions_particles=['periodic', 'periodic', 'absorbing'], - moving_window_velocity=[0., 0., c], + lower_boundary_conditions=["periodic", "periodic", "damped"], + upper_boundary_conditions=["periodic", "periodic", "damped"], + lower_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + upper_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + moving_window_velocity=[0.0, 0.0, c], warpx_max_grid_size=256, - warpx_blocking_factor=32) + warpx_blocking_factor=32, + ) # plasma region -plasma_rlim = 100.e-6 +plasma_rlim = 100.0e-6 N_stage = 15 L_plasma_bulk = 0.28 -L_ramp = 1.e-9 +L_ramp = 1.0e-9 L_ramp_up = L_ramp L_ramp_down = L_ramp -L_stage = L_plasma_bulk + 2*L_ramp +L_stage = L_plasma_bulk + 2 * L_ramp # focusing # lens external fields @@ -80,124 +82,144 @@ lens_focal_length = 0.015 lens_width = 0.003 -stage_spacing = L_plasma_bulk + 2*lens_focal_length - -def get_species_of_accelerator_stage(stage_idx, stage_zmin, stage_zmax, - stage_xmin=-plasma_rlim, stage_xmax=plasma_rlim, - stage_ymin=-plasma_rlim, stage_ymax=plasma_rlim, - Lplus = L_ramp_up, Lp = L_plasma_bulk, - Lminus = L_ramp_down): +stage_spacing = L_plasma_bulk + 2 * lens_focal_length + + +def get_species_of_accelerator_stage( + stage_idx, + stage_zmin, + stage_zmax, + stage_xmin=-plasma_rlim, + stage_xmax=plasma_rlim, + stage_ymin=-plasma_rlim, + stage_ymax=plasma_rlim, + Lplus=L_ramp_up, + Lp=L_plasma_bulk, + Lminus=L_ramp_down, +): # Parabolic density profile n0 = 1.7e23 - Rc = 40.e-6 + Rc = 40.0e-6 Lstage = Lplus + Lp + Lminus - if not np.isclose(stage_zmax-stage_zmin, Lstage): - print('Warning: zmax disagrees with stage length') + if not np.isclose(stage_zmax - stage_zmin, Lstage): + print("Warning: zmax disagrees with stage length") parabolic_distribution = picmi.AnalyticDistribution( - density_expression= - f'n0*(1.+4.*(x**2+y**2)/(kp**2*Rc**4))*(0.5*(1.-cos(pi*(z-{stage_zmin})/Lplus)))*((z-{stage_zmin})=Lplus)*((z-{stage_zmin})<(Lplus+Lp))' \ - + f'+n0*(1.+4.*(x**2+y**2)/(kp**2*Rc**4))*(0.5*(1.+cos(pi*((z-{stage_zmin})-Lplus-Lp)/Lminus)))*((z-{stage_zmin})>=(Lplus+Lp))*((z-{stage_zmin})<(Lplus+Lp+Lminus))', + density_expression=f"n0*(1.+4.*(x**2+y**2)/(kp**2*Rc**4))*(0.5*(1.-cos(pi*(z-{stage_zmin})/Lplus)))*((z-{stage_zmin})=Lplus)*((z-{stage_zmin})<(Lplus+Lp))" + + f"+n0*(1.+4.*(x**2+y**2)/(kp**2*Rc**4))*(0.5*(1.+cos(pi*((z-{stage_zmin})-Lplus-Lp)/Lminus)))*((z-{stage_zmin})>=(Lplus+Lp))*((z-{stage_zmin})<(Lplus+Lp+Lminus))", pi=3.141592653589793, n0=n0, - kp=q_e/c*math.sqrt(n0/(m_e*ep0)), + kp=q_e / c * math.sqrt(n0 / (m_e * ep0)), Rc=Rc, Lplus=Lplus, Lp=Lp, Lminus=Lminus, lower_bound=[stage_xmin, stage_ymin, stage_zmin], upper_bound=[stage_xmax, stage_ymax, stage_zmax], - fill_in=True) + fill_in=True, + ) electrons = picmi.Species( - particle_type='electron', - name=f'electrons{stage_idx}', - initial_distribution=parabolic_distribution) + particle_type="electron", + name=f"electrons{stage_idx}", + initial_distribution=parabolic_distribution, + ) ions = picmi.Species( - particle_type='proton', - name=f'ions{stage_idx}', - initial_distribution=parabolic_distribution) + particle_type="proton", + name=f"ions{stage_idx}", + initial_distribution=parabolic_distribution, + ) return electrons, ions + species_list = [] for i_stage in range(1): # Add plasma zmin_stage = i_stage * stage_spacing zmax_stage = zmin_stage + L_stage - electrons, ions = get_species_of_accelerator_stage(i_stage+1, zmin_stage, zmax_stage) + electrons, ions = get_species_of_accelerator_stage( + i_stage + 1, zmin_stage, zmax_stage + ) species_list.append(electrons) species_list.append(ions) # add beam to species_list -beam_charge = -10.e-15 # in Coulombs +beam_charge = -10.0e-15 # in Coulombs N_beam_particles = int(1e6) -beam_centroid_z = -107.e-6 -beam_rms_z = 2.e-6 +beam_centroid_z = -107.0e-6 +beam_rms_z = 2.0e-6 beam_gammas = [1960 + 13246 * i_stage for i_stage in range(N_stage)] -#beam_gammas = [1957, 15188, 28432, 41678, 54926, 68174, 81423,94672, 107922,121171] # From 3D run +# beam_gammas = [1957, 15188, 28432, 41678, 54926, 68174, 81423,94672, 107922,121171] # From 3D run beams = [] for i_stage in range(N_stage): beam_gamma = beam_gammas[i_stage] sigma_gamma = 0.06 * beam_gamma gaussian_distribution = picmi.GaussianBunchDistribution( - n_physical_particles= abs(beam_charge) / q_e, - rms_bunch_size=[2.e-6, 2.e-6, beam_rms_z], - rms_velocity=[8*c, 8*c, sigma_gamma*c], - centroid_position=[0., 0., beam_centroid_z], - centroid_velocity=[0., 0., beam_gamma*c], + n_physical_particles=abs(beam_charge) / q_e, + rms_bunch_size=[2.0e-6, 2.0e-6, beam_rms_z], + rms_velocity=[8 * c, 8 * c, sigma_gamma * c], + centroid_position=[0.0, 0.0, beam_centroid_z], + centroid_velocity=[0.0, 0.0, beam_gamma * c], ) beam = picmi.Species( - particle_type='electron', - name=f'beam_stage_{i_stage}', - initial_distribution= gaussian_distribution + particle_type="electron", + name=f"beam_stage_{i_stage}", + initial_distribution=gaussian_distribution, ) beams.append(beam) # Laser antenna_z = -1e-9 profile_t_peak = 1.46764864e-13 + + def get_laser(antenna_z, profile_t_peak, fill_in=True): - profile_focal_distance = 0. + profile_focal_distance = 0.0 laser = picmi.GaussianLaser( wavelength=0.8e-06, waist=36e-06, duration=7.33841e-14, - focal_position=[0., 0., profile_focal_distance + antenna_z], - centroid_position=[0., 0., antenna_z - c*profile_t_peak], - propagation_direction=[0., 0., 1.], - polarization_direction=[0., 1., 0.], + focal_position=[0.0, 0.0, profile_focal_distance + antenna_z], + centroid_position=[0.0, 0.0, antenna_z - c * profile_t_peak], + propagation_direction=[0.0, 0.0, 1.0], + polarization_direction=[0.0, 1.0, 0.0], a0=2.36, - fill_in=fill_in) + fill_in=fill_in, + ) laser_antenna = picmi.LaserAntenna( - position=[0., 0., antenna_z], - normal_vector=[0., 0., 1.]) + position=[0.0, 0.0, antenna_z], normal_vector=[0.0, 0.0, 1.0] + ) return (laser, laser_antenna) + + lasers = [] for i_stage in range(1): fill_in = True if i_stage == 0: fill_in = False lasers.append( - get_laser(antenna_z + i_stage*stage_spacing, - profile_t_peak + i_stage*stage_spacing/c, - fill_in) + get_laser( + antenna_z + i_stage * stage_spacing, + profile_t_peak + i_stage * stage_spacing / c, + fill_in, + ) ) # Electromagnetic solver -psatd_algo = 'multij' -if psatd_algo == 'galilean': - galilean_velocity = [0.,0.] if dim=='3' else [0.] - galilean_velocity += [-c*beta_boost] +psatd_algo = "multij" +if psatd_algo == "galilean": + galilean_velocity = [0.0, 0.0] if dim == "3" else [0.0] + galilean_velocity += [-c * beta_boost] n_pass_z = 1 do_multiJ = None - do_multi_J_n_depositions=None + do_multi_J_n_depositions = None J_in_time = None current_correction = True divE_cleaning = False -elif psatd_algo == 'multij': +elif psatd_algo == "multij": n_pass_z = 4 galilean_velocity = None do_multiJ = True @@ -206,21 +228,23 @@ def get_laser(antenna_z, profile_t_peak, fill_in=True): current_correction = False divE_cleaning = True else: - raise Exception(f'PSATD algorithm \'{psatd_algo}\' is not recognized!\n'\ - 'Valid options are \'multiJ\' or \'galilean\'.') -if dim == 'rz': + raise Exception( + f"PSATD algorithm '{psatd_algo}' is not recognized!\n" + "Valid options are 'multiJ' or 'galilean'." + ) +if dim == "rz": stencil_order = [8, 16] - smoother = picmi.BinomialSmoother(n_pass=[1,n_pass_z]) - grid_type = 'collocated' + smoother = picmi.BinomialSmoother(n_pass=[1, n_pass_z]) + grid_type = "collocated" else: stencil_order = [8, 8, 16] - smoother = picmi.BinomialSmoother(n_pass=[1,1,n_pass_z]) - grid_type = 'hybrid' + smoother = picmi.BinomialSmoother(n_pass=[1, 1, n_pass_z]) + grid_type = "hybrid" solver = picmi.ElectromagneticSolver( grid=grid, - method='PSATD', + method="PSATD", cfl=0.9999, source_smoother=smoother, stencil_order=stencil_order, @@ -228,63 +252,68 @@ def get_laser(antenna_z, profile_t_peak, fill_in=True): warpx_psatd_update_with_rho=True, warpx_current_correction=current_correction, divE_cleaning=divE_cleaning, - warpx_psatd_J_in_time=J_in_time - ) + warpx_psatd_J_in_time=J_in_time, +) # Diagnostics -diag_field_list = ['B', 'E', 'J', 'rho'] -diag_particle_list = ['weighting','position','momentum'] -coarse_btd_end = int((L_plasma_bulk+0.001+stage_spacing*(N_stage-1))*100000) -stage_end_snapshots=[f'{int((L_plasma_bulk+stage_spacing*ii)*100000)}:{int((L_plasma_bulk+stage_spacing*ii)*100000+50)}:5' for ii in range(1)] +diag_field_list = ["B", "E", "J", "rho"] +diag_particle_list = ["weighting", "position", "momentum"] +coarse_btd_end = int((L_plasma_bulk + 0.001 + stage_spacing * (N_stage - 1)) * 100000) +stage_end_snapshots = [ + f"{int((L_plasma_bulk+stage_spacing*ii)*100000)}:{int((L_plasma_bulk+stage_spacing*ii)*100000+50)}:5" + for ii in range(1) +] btd_particle_diag = picmi.LabFrameParticleDiagnostic( - name='lab_particle_diags', + name="lab_particle_diags", species=beams, grid=grid, - num_snapshots=25*N_stage, - #warpx_intervals=', '.join([f':{coarse_btd_end}:1000']+stage_end_snapshots), - warpx_intervals=', '.join(['0:0']+stage_end_snapshots), - dt_snapshots=0.00001/c, + num_snapshots=25 * N_stage, + # warpx_intervals=', '.join([f':{coarse_btd_end}:1000']+stage_end_snapshots), + warpx_intervals=", ".join(["0:0"] + stage_end_snapshots), + dt_snapshots=0.00001 / c, data_list=diag_particle_list, - write_dir='lab_particle_diags', - warpx_format='openpmd', - warpx_openpmd_backend='bp') + write_dir="lab_particle_diags", + warpx_format="openpmd", + warpx_openpmd_backend="bp", +) btd_field_diag = picmi.LabFrameFieldDiagnostic( - name='lab_field_diags', + name="lab_field_diags", grid=grid, - num_snapshots=25*N_stage, - dt_snapshots=stage_spacing/25/c, + num_snapshots=25 * N_stage, + dt_snapshots=stage_spacing / 25 / c, data_list=diag_field_list, - warpx_lower_bound=[-128.e-6, 0.e-6, -180.e-6], - warpx_upper_bound=[128.e-6, 0.e-6, 0.], - write_dir='lab_field_diags', - warpx_format='openpmd', - warpx_openpmd_backend='bp') + warpx_lower_bound=[-128.0e-6, 0.0e-6, -180.0e-6], + warpx_upper_bound=[128.0e-6, 0.0e-6, 0.0], + write_dir="lab_field_diags", + warpx_format="openpmd", + warpx_openpmd_backend="bp", +) field_diag = picmi.FieldDiagnostic( - name='field_diags', + name="field_diags", data_list=diag_field_list, grid=grid, period=100, - write_dir='field_diags', - lower_bound=[-128.e-6, 0.e-6, -180.e-6], - upper_bound=[128.e-6, 0.e-6, 0.], - warpx_format='openpmd', - warpx_openpmd_backend='h5') + write_dir="field_diags", + lower_bound=[-128.0e-6, 0.0e-6, -180.0e-6], + upper_bound=[128.0e-6, 0.0e-6, 0.0], + warpx_format="openpmd", + warpx_openpmd_backend="h5", +) particle_diag = picmi.ParticleDiagnostic( - name='particle_diags', + name="particle_diags", species=beams, period=100, - write_dir='particle_diags', - warpx_format='openpmd', - warpx_openpmd_backend='h5') + write_dir="particle_diags", + warpx_format="openpmd", + warpx_openpmd_backend="h5", +) beamrel_red_diag = picmi.ReducedDiagnostic( - diag_type='BeamRelevant', - name='beamrel', - species=beam, - period=1) + diag_type="BeamRelevant", name="beamrel", species=beam, period=1 +) # Set up simulation sim = picmi.Simulation( @@ -292,40 +321,42 @@ def get_laser(antenna_z, profile_t_peak, fill_in=True): warpx_numprocs=num_procs, warpx_compute_max_step_from_btd=True, verbose=2, - particle_shape='cubic', + particle_shape="cubic", gamma_boost=gamma_boost, - warpx_charge_deposition_algo='standard', - warpx_current_deposition_algo='direct', - warpx_field_gathering_algo='momentum-conserving', - warpx_particle_pusher_algo='vay', + warpx_charge_deposition_algo="standard", + warpx_current_deposition_algo="direct", + warpx_field_gathering_algo="momentum-conserving", + warpx_particle_pusher_algo="vay", warpx_amrex_the_arena_is_managed=False, warpx_amrex_use_gpu_aware_mpi=True, warpx_do_multi_J=do_multiJ, warpx_do_multi_J_n_depositions=do_multi_J_n_depositions, warpx_grid_type=grid_type, # default: 2 for staggered grids, 8 for hybrid grids - warpx_field_centering_order=[16,16,16], + warpx_field_centering_order=[16, 16, 16], # only for hybrid grids, default: 8 - warpx_current_centering_order=[16,16,16] - ) + warpx_current_centering_order=[16, 16, 16], +) for species in species_list: - if dim=='rz': - n_macroparticle_per_cell=[2,4,2] + if dim == "rz": + n_macroparticle_per_cell = [2, 4, 2] else: - n_macroparticle_per_cell=[2,2,2] + n_macroparticle_per_cell = [2, 2, 2] sim.add_species( species, - layout=picmi.GriddedLayout(grid=grid, - n_macroparticle_per_cell=n_macroparticle_per_cell) + layout=picmi.GriddedLayout( + grid=grid, n_macroparticle_per_cell=n_macroparticle_per_cell + ), ) for i_stage in range(N_stage): sim.add_species_through_plane( species=beams[i_stage], layout=picmi.PseudoRandomLayout(grid=grid, n_macroparticles=N_beam_particles), - injection_plane_position=0., - injection_plane_normal_vector=[0.,0.,1.]) + injection_plane_position=0.0, + injection_plane_normal_vector=[0.0, 0.0, 1.0], + ) for i_stage in range(1): # Add laser @@ -334,14 +365,14 @@ def get_laser(antenna_z, profile_t_peak, fill_in=True): # Add diagnostics sim.add_diagnostic(btd_particle_diag) -#sim.add_diagnostic(btd_field_diag) -#sim.add_diagnostic(field_diag) -#sim.add_diagnostic(particle_diag) +# sim.add_diagnostic(btd_field_diag) +# sim.add_diagnostic(field_diag) +# sim.add_diagnostic(particle_diag) # Add reduced diagnostic sim.add_diagnostic(beamrel_red_diag) -sim.write_input_file(f'inputs_training_{N_stage}_stages') +sim.write_input_file(f"inputs_training_{N_stage}_stages") # Advance simulation until last time step sim.step() diff --git a/Docs/source/usage/workflows/ml_materials/train.py b/Docs/source/usage/workflows/ml_materials/train.py index 4de11b9c99e..957a652e0c4 100644 --- a/Docs/source/usage/workflows/ml_materials/train.py +++ b/Docs/source/usage/workflows/ml_materials/train.py @@ -18,7 +18,7 @@ ############# set model parameters ################# stage_i = 0 -species = f'beam_stage_{stage_i}' +species = f"beam_stage_{stage_i}" source_index = 0 target_index = 1 survivor_select_index = 1 @@ -35,36 +35,52 @@ n_hidden_nodes = 20 n_hidden_layers = 3 -activation_type = 'ReLU' +activation_type = "ReLU" -device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') -print(f'device={device}') +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") +print(f"device={device}") #################### load dataset ################ -dataset_filename = f'dataset_{species}.pt' -dataset_file = 'datasets/' + dataset_filename +dataset_filename = f"dataset_{species}.pt" +dataset_file = "datasets/" + dataset_filename print(f"trying to load dataset+test-train split in {dataset_file}") dataset_with_indices = torch.load(dataset_file) -train_data = torch.utils.data.dataset.Subset(dataset_with_indices['dataset'], dataset_with_indices['train_indices']) -test_data = torch.utils.data.dataset.Subset(dataset_with_indices['dataset'], dataset_with_indices['test_indices']) -source_data = dataset_with_indices['dataset'] -source_means = dataset_with_indices['source_means'] -source_stds = dataset_with_indices['source_stds'] -target_means = dataset_with_indices['target_means'] -target_stds = dataset_with_indices['target_stds'] +train_data = torch.utils.data.dataset.Subset( + dataset_with_indices["dataset"], dataset_with_indices["train_indices"] +) +test_data = torch.utils.data.dataset.Subset( + dataset_with_indices["dataset"], dataset_with_indices["test_indices"] +) +source_data = dataset_with_indices["dataset"] +source_means = dataset_with_indices["source_means"] +source_stds = dataset_with_indices["source_stds"] +target_means = dataset_with_indices["target_means"] +target_stds = dataset_with_indices["target_stds"] print("able to load data and test/train split") ###### move data to device (GPU) if available ######## -source_device = train_data.dataset.tensors[0].to(device) # equivalently, test_data.tensors[0].to(device) +source_device = train_data.dataset.tensors[0].to( + device +) # equivalently, test_data.tensors[0].to(device) target_device = train_data.dataset.tensors[1].to(device) -full_dataset_device = torch.utils.data.TensorDataset(source_device.float(), target_device.float()) - -train_data_device = torch.utils.data.dataset.Subset(full_dataset_device, train_data.indices) -test_data_device = torch.utils.data.dataset.Subset(full_dataset_device, test_data.indices) - -train_loader_device = torch.utils.data.DataLoader(train_data_device, batch_size=batch_size, shuffle=True) -test_loader_device = torch.utils.data.DataLoader(test_data_device, batch_size=batch_size, shuffle=True) +full_dataset_device = torch.utils.data.TensorDataset( + source_device.float(), target_device.float() +) + +train_data_device = torch.utils.data.dataset.Subset( + full_dataset_device, train_data.indices +) +test_data_device = torch.utils.data.dataset.Subset( + full_dataset_device, test_data.indices +) + +train_loader_device = torch.utils.data.DataLoader( + train_data_device, batch_size=batch_size, shuffle=True +) +test_loader_device = torch.utils.data.DataLoader( + test_data_device, batch_size=batch_size, shuffle=True +) test_source_device = test_data_device.dataset.tensors[0] test_target_device = test_data_device.dataset.tensors[1] @@ -74,53 +90,61 @@ ###### create model ########### -model = mynn.OneActNN(n_in = n_in, - n_out = n_out, - n_hidden_nodes=n_hidden_nodes, - n_hidden_layers = n_hidden_layers, - act=activation_type - ) +model = mynn.OneActNN( + n_in=n_in, + n_out=n_out, + n_hidden_nodes=n_hidden_nodes, + n_hidden_layers=n_hidden_layers, + act=activation_type, +) training_time = 0 train_loss_list = [] test_loss_list = [] -model.to(device=device); +model.to(device=device) + ########## train and test functions #### # Manual: Train function START def train(model, optimizer, train_loader, loss_fun): model.train() - total_loss = 0. + total_loss = 0.0 for batch_idx, (data, target) in enumerate(train_loader): - #evaluate network with data + # evaluate network with data output = model(data) - #compute loss - # sum the differences squared, take mean afterward - loss = loss_fun(output, target,reduction='sum') - #backpropagation: step optimizer and reset gradients + # compute loss + # sum the differences squared, take mean afterward + loss = loss_fun(output, target, reduction="sum") + # backpropagation: step optimizer and reset gradients loss.backward() optimizer.step() optimizer.zero_grad() total_loss += loss.item() return total_loss + + # Manual: Train function END + def test(model, test_loader, loss_fun): model.eval() - total_loss = 0. + total_loss = 0.0 with torch.no_grad(): for batch_idx, (data, target) in enumerate(test_loader): output = model(data) - total_loss += loss_fun(output, target, reduction='sum').item() + total_loss += loss_fun(output, target, reduction="sum").item() return total_loss + # Manual: Test function START def test_dataset(model, test_source, test_target, loss_fun): model.eval() with torch.no_grad(): output = model(test_source) - return loss_fun(output, test_target, reduction='sum').item() + return loss_fun(output, test_target, reduction="sum").item() + + # Manual: Test function END ######## training loop ######## @@ -134,33 +158,47 @@ def test_dataset(model, test_source, test_target, loss_fun): for epoch in range(n_epochs): if do_print: t1 = time.time() - ave_train_loss = train(model, optimizer, train_loader_device, loss_fun) / data_dim / training_set_size - ave_test_loss = test_dataset(model, test_source_device, test_target_device, loss_fun) / data_dim / training_set_size + ave_train_loss = ( + train(model, optimizer, train_loader_device, loss_fun) + / data_dim + / training_set_size + ) + ave_test_loss = ( + test_dataset(model, test_source_device, test_target_device, loss_fun) + / data_dim + / training_set_size + ) train_loss_list.append(ave_train_loss) test_loss_list.append(ave_test_loss) if do_print: t2 = time.time() - print('Train Epoch: {:04d} \tTrain Loss: {:.6f} \tTest Loss: {:.6f}, this epoch: {:.3f} s'.format( - epoch + 1, ave_train_loss, ave_test_loss, t2-t1)) + print( + "Train Epoch: {:04d} \tTrain Loss: {:.6f} \tTest Loss: {:.6f}, this epoch: {:.3f} s".format( + epoch + 1, ave_train_loss, ave_test_loss, t2 - t1 + ) + ) # Manual: Training loop END t4 = time.time() -print(f'total training time: {t4-t3:.3f}s') +print(f"total training time: {t4-t3:.3f}s") ######### save model ######### -os.makedirs('models', exist_ok=True) +os.makedirs("models", exist_ok=True) # Manual: Save model START -model.to(device='cpu') -torch.save({ - 'n_hidden_layers':n_hidden_layers, - 'n_hidden_nodes':n_hidden_nodes, - 'activation':activation_type, - 'model_state_dict': model.state_dict(), - 'optimizer_state_dict': optimizer.state_dict(), - 'train_loss_list': train_loss_list, - 'test_loss_list': test_loss_list, - 'training_time': training_time, - }, f'models/{species}_model.pt') +model.to(device="cpu") +torch.save( + { + "n_hidden_layers": n_hidden_layers, + "n_hidden_nodes": n_hidden_nodes, + "activation": activation_type, + "model_state_dict": model.state_dict(), + "optimizer_state_dict": optimizer.state_dict(), + "train_loss_list": train_loss_list, + "test_loss_list": test_loss_list, + "training_time": training_time, + }, + f"models/{species}_model.pt", +) # Manual: Save model END diff --git a/Docs/source/usage/workflows/ml_materials/visualize.py b/Docs/source/usage/workflows/ml_materials/visualize.py index 920efe29909..38bce78a91d 100644 --- a/Docs/source/usage/workflows/ml_materials/visualize.py +++ b/Docs/source/usage/workflows/ml_materials/visualize.py @@ -18,67 +18,70 @@ # open model file stage_i = 0 -species = f'beam_stage_{stage_i}' -model_data = torch.load(f'models/{species}_model.pt',map_location=torch.device('cpu')) +species = f"beam_stage_{stage_i}" +model_data = torch.load(f"models/{species}_model.pt", map_location=torch.device("cpu")) data_dim = 6 n_in = data_dim n_out = data_dim -n_hidden_layers = model_data['n_hidden_layers'] -n_hidden_nodes = model_data['n_hidden_nodes'] -activation_type = model_data['activation'] -train_loss_list = model_data['train_loss_list'] -test_loss_list = model_data['test_loss_list'] -training_time = model_data['training_time'] +n_hidden_layers = model_data["n_hidden_layers"] +n_hidden_nodes = model_data["n_hidden_nodes"] +activation_type = model_data["activation"] +train_loss_list = model_data["train_loss_list"] +test_loss_list = model_data["test_loss_list"] +training_time = model_data["training_time"] loss_fun = F.mse_loss n_epochs = len(train_loss_list) -train_counter = np.arange(n_epochs)+1 +train_counter = np.arange(n_epochs) + 1 test_counter = train_counter do_log_plot = False fig, ax = plt.subplots() if do_log_plot: - ax.semilogy(train_counter, train_loss_list, '.-',color='blue',label='training loss') - ax.semilogy(test_counter, test_loss_list, color='green',label='testing loss') + ax.semilogy( + train_counter, train_loss_list, ".-", color="blue", label="training loss" + ) + ax.semilogy(test_counter, test_loss_list, color="green", label="testing loss") else: - ax.plot(train_counter, train_loss_list, '.-',color='blue',label='training loss') - ax.plot(test_counter, test_loss_list, color='green',label='testing loss') -ax.set_xlabel('number of epochs seen') -ax.set_ylabel(' loss') + ax.plot(train_counter, train_loss_list, ".-", color="blue", label="training loss") + ax.plot(test_counter, test_loss_list, color="green", label="testing loss") +ax.set_xlabel("number of epochs seen") +ax.set_ylabel(" loss") ax.legend() -fig_dir = 'figures/' -ax.set_title(f'final test error = {test_loss_list[-1]:.3e} ') +fig_dir = "figures/" +ax.set_title(f"final test error = {test_loss_list[-1]:.3e} ") ax.grid() plt.tight_layout() -plt.savefig(f'{species}_training_testing_error.png') +plt.savefig(f"{species}_training_testing_error.png") ######### plot phase space comparison ####### -device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') -print(f'device={device}') - -model = mynn.OneActNN(n_in = n_in, - n_out = n_out, - n_hidden_nodes=n_hidden_nodes, - n_hidden_layers = n_hidden_layers, - act = activation_type - ) -model.load_state_dict(model_data['model_state_dict']) -model.to(device=device); +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") +print(f"device={device}") + +model = mynn.OneActNN( + n_in=n_in, + n_out=n_out, + n_hidden_nodes=n_hidden_nodes, + n_hidden_layers=n_hidden_layers, + act=activation_type, +) +model.load_state_dict(model_data["model_state_dict"]) +model.to(device=device) ###### load model data ############### -dataset_filename = f'dataset_{species}.pt' -dataset_dir = 'datasets/' +dataset_filename = f"dataset_{species}.pt" +dataset_dir = "datasets/" model_input_data = torch.load(dataset_dir + dataset_filename) -dataset = model_input_data['dataset'] -train_indices = model_input_data['train_indices'] -test_indices = model_input_data['test_indices'] -source_means = model_input_data['source_means'] -source_stds = model_input_data['source_stds'] -target_means = model_input_data['target_means'] -target_stds = model_input_data['target_stds'] -source_time, target_time = model_input_data['times'] +dataset = model_input_data["dataset"] +train_indices = model_input_data["train_indices"] +test_indices = model_input_data["test_indices"] +source_means = model_input_data["source_means"] +source_stds = model_input_data["source_stds"] +target_means = model_input_data["target_means"] +target_stds = model_input_data["target_stds"] +source_time, target_time = model_input_data["times"] source = dataset.tensors[0] @@ -86,7 +89,7 @@ test_source_device = test_source.to(device) with torch.no_grad(): evaluation_device = model(test_source_device.float()) -eval_cpu = evaluation_device.to('cpu') +eval_cpu = evaluation_device.to("cpu") target = dataset.tensors[1] test_target = target[test_indices] @@ -95,64 +98,89 @@ eval_cpu_si = eval_cpu * target_stds + target_means target_mu = np.copy(target_si) eval_cpu_mu = np.copy(eval_cpu_si) -target_mu[:,2] -= c*target_time -eval_cpu_mu[:,2] -= c*target_time -target_mu[:,:3] *= 1e6 -eval_cpu_mu[:,:3] *= 1e6 +target_mu[:, 2] -= c * target_time +eval_cpu_mu[:, 2] -= c * target_time +target_mu[:, :3] *= 1e6 +eval_cpu_mu[:, :3] *= 1e6 - -loss_tensor = torch.sum(loss_fun(eval_cpu, - test_target, - reduction='none'), - axis=1)/6 +loss_tensor = torch.sum(loss_fun(eval_cpu, test_target, reduction="none"), axis=1) / 6 loss_array = loss_tensor.detach().numpy() tinds = np.nonzero(loss_array > 0.0)[0] skip = 10 plt.figure() -fig, axT = plt.subplots(3,3) -axes_label = {0:r'x [$\mu$m]', 1:r'y [$\mu$m]', 2:r'z - %.2f cm [$\mu$m]'%(c*target_time),3:r'$p_x$',4:r'$p_y$',5:r'$p_z$'} -xy_inds = [(0,1),(2,0),(2,1)] +fig, axT = plt.subplots(3, 3) +axes_label = { + 0: r"x [$\mu$m]", + 1: r"y [$\mu$m]", + 2: r"z - %.2f cm [$\mu$m]" % (c * target_time), + 3: r"$p_x$", + 4: r"$p_y$", + 5: r"$p_z$", +} +xy_inds = [(0, 1), (2, 0), (2, 1)] + + def set_axes(ax, indx, indy): - ax.scatter(target_mu[::skip,indx],target_mu[::skip,indy],s=8,c='k', label='simulation') - ax.scatter(eval_cpu_mu[::skip,indx],eval_cpu_mu[::skip,indy],marker='*',c=loss_array[::skip],s=0.02, label='surrogate',cmap='YlOrRd') + ax.scatter( + target_mu[::skip, indx], target_mu[::skip, indy], s=8, c="k", label="simulation" + ) + ax.scatter( + eval_cpu_mu[::skip, indx], + eval_cpu_mu[::skip, indy], + marker="*", + c=loss_array[::skip], + s=0.02, + label="surrogate", + cmap="YlOrRd", + ) ax.set_xlabel(axes_label[indx]) ax.set_ylabel(axes_label[indy]) # return for ii in range(3): - ax = axT[0,ii] - indx,indy = xy_inds[ii] - set_axes(ax,indx,indy) + ax = axT[0, ii] + indx, indy = xy_inds[ii] + set_axes(ax, indx, indy) for ii in range(2): - indx,indy = xy_inds[ii] - ax = axT[1,ii] - set_axes(ax,indx+3,indy+3) + indx, indy = xy_inds[ii] + ax = axT[1, ii] + set_axes(ax, indx + 3, indy + 3) for ii in range(3): - ax = axT[2,ii] + ax = axT[2, ii] indx = ii - indy = ii+3 + indy = ii + 3 set_axes(ax, indx, indy) -ax = axT[1,2] +ax = axT[1, 2] indx = 5 indy = 4 -ax.scatter(target_mu[::skip,indx],target_mu[::skip,indy],s=8,c='k', label='simulation') -evalplt = ax.scatter(eval_cpu_mu[::skip,indx],eval_cpu_mu[::skip,indy],marker='*',c=loss_array[::skip],s=2, label='surrogate',cmap='YlOrRd') +ax.scatter( + target_mu[::skip, indx], target_mu[::skip, indy], s=8, c="k", label="simulation" +) +evalplt = ax.scatter( + eval_cpu_mu[::skip, indx], + eval_cpu_mu[::skip, indy], + marker="*", + c=loss_array[::skip], + s=2, + label="surrogate", + cmap="YlOrRd", +) ax.set_xlabel(axes_label[indx]) ax.set_ylabel(axes_label[indy]) cb = plt.colorbar(evalplt, ax=ax) -cb.set_label('MSE loss') +cb.set_label("MSE loss") -fig.suptitle(f'stage {stage_i} prediction') +fig.suptitle(f"stage {stage_i} prediction") plt.tight_layout() -plt.savefig(f'{species}_model_evaluation.png') +plt.savefig(f"{species}_model_evaluation.png") diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt new file mode 100644 index 00000000000..fe1da3d08e6 --- /dev/null +++ b/Examples/CMakeLists.txt @@ -0,0 +1,240 @@ +# Configuration ############################################################### +# +if(WarpX_MPI) + # OpenMPI root guard: https://github.com/open-mpi/ompi/issues/4451 + if("$ENV{USER}" STREQUAL "root") + # calling even --help as root will abort and warn on stderr + execute_process( + COMMAND ${MPIEXEC_EXECUTABLE} --help + ERROR_VARIABLE MPIEXEC_HELP_TEXT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(${MPIEXEC_HELP_TEXT} MATCHES "^.*allow-run-as-root.*$") + set(MPI_ALLOW_ROOT --allow-run-as-root) + endif() + endif() +endif() + +# Add a WarpX test set (with sub-tests) +# +# name: unique name of this test +# dims: 1,2,RZ,3 +# nprocs: 1 or 2 (maybe refactor later on to just depend on WarpX_MPI) +# inputs: inputs file or PICMI script, WarpX_MPI decides w/ or w/o MPI +# analysis: analysis script, always run without MPI +# output: output file(s) to analyze +# dependency: name of base test that must run first +# +function(add_warpx_test + name + dims + nprocs + inputs + analysis + output + dependency +) + # cannot run MPI tests w/o MPI build + if(nprocs GREATER_EQUAL 2 AND NOT WarpX_MPI) + message(WARNING "${name}: cannot run MPI tests without MPI build") + return() + endif() + + # cannot run tests with unsupported geometry + if(NOT dims IN_LIST WarpX_DIMS) + return() + endif() + + # cannot run tests with unfulfilled dependencies + if(dependency AND NOT TEST ${dependency}.run) + return() + endif() + + # set dimension suffix + warpx_set_suffix_dims(SD ${dims}) + + # make a unique run directory + file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name}) + set(THIS_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name}) + + # get input file/script and optional command-line arguments + separate_arguments(INPUTS_LIST UNIX_COMMAND "${inputs}") + list(GET INPUTS_LIST 0 INPUTS_FILE) + list(LENGTH INPUTS_LIST INPUTS_LIST_LENGTH) + if(INPUTS_LIST_LENGTH GREATER 1) + list(SUBLIST INPUTS_LIST 1 -1 INPUTS_ARGS) + list(JOIN INPUTS_ARGS " " INPUTS_ARGS) + else() + set(INPUTS_ARGS "") + endif() + + # get analysis script and optional command-line arguments + separate_arguments(ANALYSIS_LIST UNIX_COMMAND "${analysis}") + list(GET ANALYSIS_LIST 0 ANALYSIS_FILE) + cmake_path(SET ANALYSIS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${ANALYSIS_FILE}") + # TODO Enable lines below to handle command-line arguments + #list(LENGTH ANALYSIS_LIST ANALYSIS_LIST_LENGTH) + #if(ANALYSIS_LIST_LENGTH GREATER 1) + # list(SUBLIST ANALYSIS_LIST 1 -1 ANALYSIS_ARGS) + # list(JOIN ANALYSIS_ARGS " " ANALYSIS_ARGS) + #else() + # set(ANALYSIS_ARGS "") + #endif() + + # Python test? + set(python OFF) + if(${INPUTS_FILE} MATCHES ".*\.py$") + set(python ON) + cmake_path(SET INPUTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${INPUTS_FILE}") + endif() + + # cannot run Python tests w/o Python support + if(python AND NOT WarpX_PYTHON) + return() + endif() + + # set MPI executable + set(THIS_MPI_TEST_EXE + ${MPIEXEC_EXECUTABLE} + ${MPI_ALLOW_ROOT} + ${MPIEXEC_NUMPROC_FLAG} ${nprocs} + ${MPIEXEC_POSTFLAGS} + ${MPIEXEC_PREFLAGS} + ) + + # set Python executable + if(python) + set(THIS_Python_EXE ${Python_EXECUTABLE}) + else() + set(THIS_Python_EXE "") + endif() + + # test run + if(python) + # for argparse, do not pass command-line arguments as one quoted string + separate_arguments(INPUTS_ARGS UNIX_COMMAND "${INPUTS_ARGS}") + add_test( + NAME ${name}.run + COMMAND + ${THIS_MPI_TEST_EXE} + ${THIS_Python_EXE} + ${INPUTS_FILE} + ${INPUTS_ARGS} + WORKING_DIRECTORY ${THIS_WORKING_DIR} + ) + # FIXME Use helper function to handle Windows exceptions + set_property(TEST ${name}.run APPEND PROPERTY ENVIRONMENT "PYTHONPATH=$ENV{PYTHONPATH}:${CMAKE_PYTHON_OUTPUT_DIRECTORY}") + else() + # TODO Use these for Python tests too + set(runtime_params + "amrex.abort_on_unused_inputs = 1" + "amrex.throw_exception = 1" + "warpx.always_warn_immediately = 1" + "warpx.do_dynamic_scheduling = 0" + "warpx.serialize_initial_conditions = 1" + # FIXME should go before input file + #"warpx.abort_on_warning_threshold = low" + ) + set(runtime_params_fpetrap "") + if(WarpX_TEST_FPETRAP) + set(runtime_params_fpetrap + "amrex.fpe_trap_invalid = 1" + "amrex.fpe_trap_overflow = 1" + "amrex.fpe_trap_zero = 1" + ) + endif() + add_test( + NAME ${name}.run + COMMAND + ${THIS_MPI_TEST_EXE} + $ + ${INPUTS_FILE} + ${runtime_params} + ${runtime_params_fpetrap} + ${INPUTS_ARGS} + WORKING_DIRECTORY ${THIS_WORKING_DIR} + ) + endif() + + # AMReX ParmParse prefix: FILE = + set_property(TEST ${name}.run APPEND PROPERTY ENVIRONMENT "AMREX_INPUTS_FILE_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/") + + # run all tests with 1 OpenMP thread by default + set_property(TEST ${name}.run APPEND PROPERTY ENVIRONMENT "OMP_NUM_THREADS=1") + + if(python OR WIN32) + set(THIS_Python_SCRIPT_EXE ${Python_EXECUTABLE}) + else() + set(THIS_Python_SCRIPT_EXE "") + endif() + + # test analysis + if(analysis) + add_test( + NAME ${name}.analysis + COMMAND + ${THIS_Python_SCRIPT_EXE} ${ANALYSIS_FILE} + ${output} + WORKING_DIRECTORY ${THIS_WORKING_DIR} + ) + # test analysis depends on test run + set_property(TEST ${name}.analysis APPEND PROPERTY DEPENDS "${name}.run") + # FIXME Use helper function to handle Windows exceptions + set(PYTHONPATH "$ENV{PYTHONPATH}:${CMAKE_PYTHON_OUTPUT_DIRECTORY}") + # add paths for custom Python modules + set(PYTHONPATH "${PYTHONPATH}:${WarpX_SOURCE_DIR}/Regression/Checksum") + set(PYTHONPATH "${PYTHONPATH}:${WarpX_SOURCE_DIR}/Regression/PostProcessingUtils") + set(PYTHONPATH "${PYTHONPATH}:${WarpX_SOURCE_DIR}/Tools/Parser") + set(PYTHONPATH "${PYTHONPATH}:${WarpX_SOURCE_DIR}/Tools/PostProcessing") + set_property(TEST ${name}.analysis APPEND PROPERTY ENVIRONMENT "PYTHONPATH=${PYTHONPATH}") + endif() + + # CI: remove test directory after run + if(WarpX_TEST_CLEANUP) + add_test( + NAME ${name}.cleanup + COMMAND ${CMAKE_COMMAND} -E rm -rf ${THIS_WORKING_DIR} + ) + # test cleanup depends on test run + set_property(TEST ${name}.cleanup APPEND PROPERTY DEPENDS "${name}.run") + if(analysis) + # test cleanup depends on test analysis + set_property(TEST ${name}.cleanup APPEND PROPERTY DEPENDS "${name}.analysis") + endif() + endif() + + # Do we depend on another test? + if(dependency) + # current test depends on dependency test run (and analysis) + set_property(TEST ${name}.run APPEND PROPERTY DEPENDS "${dependency}.run") + if(analysis) + set_property(TEST ${name}.run APPEND PROPERTY DEPENDS "${dependency}.analysis") + endif() + if(WarpX_TEST_CLEANUP) + # do not clean up dependency test before current test is completed + set_property(TEST ${dependency}.cleanup APPEND PROPERTY DEPENDS "${name}.cleanup") + endif() + endif() +endfunction() + +# Add a CTest label to a WarpX test set. +# +# Labeling it here will add the label to the run test, its analysis and its cleanup. +# +# name: unique name of this test +# label: ctest LABELS property value to be added +# +function(label_warpx_test name label) + set(_test_names "${name}.run;${name}.analysis;${name}.cleanup") + foreach(_test_name IN LISTS _test_names) + if(TEST ${_test_name}) + set_property(TEST ${_test_name} APPEND PROPERTY LABELS "${label}") + endif() + endforeach() +endfunction() + +# Add tests (alphabetical order) ############################################## +# + +add_subdirectory(Tests) +add_subdirectory(Physics_applications) diff --git a/Examples/Physics_applications/CMakeLists.txt b/Examples/Physics_applications/CMakeLists.txt new file mode 100644 index 00000000000..e4f8565a140 --- /dev/null +++ b/Examples/Physics_applications/CMakeLists.txt @@ -0,0 +1,11 @@ +# Add tests (alphabetical order) ############################################## +# + +add_subdirectory(beam_beam_collision) +add_subdirectory(capacitive_discharge) +add_subdirectory(laser_acceleration) +add_subdirectory(laser_ion) +add_subdirectory(plasma_acceleration) +add_subdirectory(plasma_mirror) +add_subdirectory(spacecraft_charging) +add_subdirectory(uniform_plasma) diff --git a/Examples/Physics_applications/beam-beam_collision/README.rst b/Examples/Physics_applications/beam-beam_collision/README.rst deleted file mode 100644 index 559a81277db..00000000000 --- a/Examples/Physics_applications/beam-beam_collision/README.rst +++ /dev/null @@ -1,70 +0,0 @@ -.. _examples-beam-beam_collision: - -Beam-beam collision -==================== - -This example shows how to simulate the collision between two ultra-relativistic particle beams. -This is representative of what happens at the interaction point of a linear collider. -We consider a right-propagating electron bunch colliding against a left-propagating positron bunch. - -We turn on the Quantum Synchrotron QED module for photon emission (also known as beamstrahlung in the collider community) and -the Breit-Wheeler QED module for the generation of electron-positron pairs (also known as coherent pair generation in the collider community). - -To solve for the electromagnetic field we use the nodal version of the electrostatic relativistic solver. -This solver computes the average velocity of each species, and solves the corresponding relativistic Poisson equation (see the WarpX documentation for `warpx.do_electrostatic = relativistic` for more detail). This solver accurately reproduced the subtle cancellation that occur for some component of the ``E + v x B`` terms which are crucial in simulations of relativistic particles. - - -This example is based on the following paper :cite:t:`ex-Yakimenko2019`. - - -Run ---- - -The PICMI input file is not available for this example yet. - -For `MPI-parallel `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. - -.. literalinclude:: inputs - :language: ini - :caption: You can copy this file from ``Examples/Physics_applications/beam-beam_collision/inputs``. - - -Visualize ---------- - -The figure below shows the number of photons emitted per beam particle (left) and the number of secondary pairs generated per beam particle (right). - -We compare different results: -* (red) simplified WarpX simulation as the example stored in the directory ``/Examples/Physics_applications/beam-beam_collision``; -* (blue) large-scale WarpX simulation (high resolution and ad hoc generated tables ; -* (black) literature results from :cite:t:`ex-Yakimenko2019`. - -The small-scale simulation has been performed with a resolution of ``nx = 64, ny = 64, nz = 128`` grid cells, while the large-scale one has a much higher resolution of ``nx = 512, ny = 512, nz = 1024``. Moreover, the large-scale simulation uses dedicated QED lookup tables instead of the builtin tables. To generate the tables within WarpX, the code must be compiled with the flag ``-DWarpX_QED_TABLE_GEN=ON``. For the large-scale simulation we have used the following options: - -.. code-block:: ini - - qed_qs.lookup_table_mode = generate - qed_bw.lookup_table_mode = generate - qed_qs.tab_dndt_chi_min=1e-3 - qed_qs.tab_dndt_chi_max=2e3 - qed_qs.tab_dndt_how_many=512 - qed_qs.tab_em_chi_min=1e-3 - qed_qs.tab_em_chi_max=2e3 - qed_qs.tab_em_chi_how_many=512 - qed_qs.tab_em_frac_how_many=512 - qed_qs.tab_em_frac_min=1e-12 - qed_qs.save_table_in=my_qs_table.txt - qed_bw.tab_dndt_chi_min=1e-2 - qed_bw.tab_dndt_chi_max=2e3 - qed_bw.tab_dndt_how_many=512 - qed_bw.tab_pair_chi_min=1e-2 - qed_bw.tab_pair_chi_max=2e3 - qed_bw.tab_pair_chi_how_many=512 - qed_bw.tab_pair_frac_how_many=512 - qed_bw.save_table_in=my_bw_table.txt - -.. figure:: https://user-images.githubusercontent.com/17280419/291749626-aa61fff2-e6d2-45a3-80ee-84b2851ea0bf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTEiLCJleHAiOjE3MDMwMzQzNTEsIm5iZiI6MTcwMzAzNDA1MSwicGF0aCI6Ii8xNzI4MDQxOS8yOTE3NDk2MjYtYWE2MWZmZjItZTZkMi00NWEzLTgwZWUtODRiMjg1MWVhMGJmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFJV05KWUFYNENTVkVINTNBJTJGMjAyMzEyMjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjMxMjIwVDAxMDA1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFiYzY2MGQyYzIyZGIzYzUxOWI3MzNjZTk5ZDM1YzgyNmY4ZDYxOGRlZjAyZTIwNTAyMTc3NTgwN2Q0YjEwNGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.I96LQpjqmFXirPDVnBlFQIkCuenR6IuOSY0OIIQvtCo - :alt: Beam-beam collision benchmark against :cite:t:`ex-Yakimenko2019`. - :width: 100% - - Beam-beam collision benchmark against :cite:t:`ex-Yakimenko2019`. diff --git a/Examples/Physics_applications/beam_beam_collision/CMakeLists.txt b/Examples/Physics_applications/beam_beam_collision/CMakeLists.txt new file mode 100644 index 00000000000..09e96f04d7f --- /dev/null +++ b/Examples/Physics_applications/beam_beam_collision/CMakeLists.txt @@ -0,0 +1,13 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_beam_beam_collision # name + 3 # dims + 2 # nprocs + inputs_test_3d_beam_beam_collision # inputs + analysis_default_openpmd_regression.py # analysis + diags/diag1/ # output + OFF # dependency +) +label_warpx_test(test_3d_beam_beam_collision slow) diff --git a/Examples/Physics_applications/beam_beam_collision/README.rst b/Examples/Physics_applications/beam_beam_collision/README.rst new file mode 100644 index 00000000000..28fdc1ee70e --- /dev/null +++ b/Examples/Physics_applications/beam_beam_collision/README.rst @@ -0,0 +1,111 @@ +.. _examples-beam-beam_collision: + +Beam-beam collision +==================== + +This example shows how to simulate the collision between two ultra-relativistic particle beams. +This is representative of what happens at the interaction point of a linear collider. +We consider a right-propagating electron bunch colliding against a left-propagating positron bunch. + +We turn on the Quantum Synchrotron QED module for photon emission (also known as beamstrahlung in the collider community) and +the Breit-Wheeler QED module for the generation of electron-positron pairs (also known as coherent pair generation in the collider community). + +To solve for the electromagnetic field we use the nodal version of the electrostatic relativistic solver. +This solver computes the average velocity of each species, and solves the corresponding relativistic Poisson equation (see the WarpX documentation for `warpx.do_electrostatic = relativistic` for more detail). +This solver accurately reproduces the subtle cancellation that occur for some component of ``E + v x B``, which are crucial in simulations of relativistic particles. + + +This example is based on the following paper :cite:t:`ex-Yakimenko2019`. + + +Run +--- + +The PICMI input file is not available for this example yet. + +For `MPI-parallel `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. + +.. literalinclude:: inputs_test_3d_beam_beam_collision + :language: ini + :caption: You can copy this file from ``Examples/Physics_applications/beam_beam_collision/inputs_test_3d_beam_beam_collision``. + + +Visualize +--------- + +The figure below shows the number of photons emitted per beam particle (left) and the number of secondary pairs generated per beam particle (right). + +We compare different results for the reduced diagnostics with the literature: +* (red) simplified WarpX simulation as the example stored in the directory ``/Examples/Physics_applications/beam-beam_collision``; +* (blue) large-scale WarpX simulation (high resolution and ad hoc generated tables ; +* (black) literature results from :cite:t:`ex-Yakimenko2019`. + +The small-scale simulation has been performed with a resolution of ``nx = 64, ny = 64, nz = 64`` grid cells, while the large-scale one has a much higher resolution of ``nx = 512, ny = 512, nz = 1024``. +Moreover, the large-scale simulation uses dedicated QED lookup tables instead of the builtin tables. +To generate the tables within WarpX, the code must be compiled with the flag ``-DWarpX_QED_TABLE_GEN=ON``. +For the large-scale simulation we have used the following options: + +.. code-block:: ini + + qed_qs.lookup_table_mode = generate + qed_bw.lookup_table_mode = generate + qed_qs.tab_dndt_chi_min=1e-3 + qed_qs.tab_dndt_chi_max=2e3 + qed_qs.tab_dndt_how_many=512 + qed_qs.tab_em_chi_min=1e-3 + qed_qs.tab_em_chi_max=2e3 + qed_qs.tab_em_chi_how_many=512 + qed_qs.tab_em_frac_how_many=512 + qed_qs.tab_em_frac_min=1e-12 + qed_qs.save_table_in=my_qs_table.txt + qed_bw.tab_dndt_chi_min=1e-2 + qed_bw.tab_dndt_chi_max=2e3 + qed_bw.tab_dndt_how_many=512 + qed_bw.tab_pair_chi_min=1e-2 + qed_bw.tab_pair_chi_max=2e3 + qed_bw.tab_pair_chi_how_many=512 + qed_bw.tab_pair_frac_how_many=512 + qed_bw.save_table_in=my_bw_table.txt + + +.. figure:: https://gist.github.com/user-attachments/assets/2dd43782-d039-4faa-9d27-e3cf8fb17352 + :alt: Beam-beam collision benchmark against :cite:t:`ex-Yakimenko2019`. + :width: 100% + + Beam-beam collision benchmark against :cite:t:`ex-Yakimenko2019`. + + +Below are two visualizations scripts that provide examples to graph the field and reduced diagnostics. +They are available in the ``Examples/Physics_applications/beam-beam_collision/`` folder and can be run as simply as ``python3 plot_fields.py`` and ``python3 plot_reduced.py``. + +.. tab-set:: + + .. tab-item:: Field Diagnostics + + This script visualizes the evolution of the fields (:math:`|E|, |B|, \rho`) during the collision between the two ultra-relativistic lepton beams. + The magnitude of E and B and the charge densities of the primary beams and of the secondary pairs are sliced along either one of the two transverse coordinates (:math:`x` and :math:`y`). + + .. literalinclude:: plot_fields.py + :language: python3 + :caption: You can copy this file from ``Examples/Physics_applications/beam-beam_collision/plot_fields.py``. + + .. figure:: https://gist.github.com/user-attachments/assets/04c9c0ec-b580-446f-a11a-437c1b244a41 + :alt: Slice across :math:`x` of different fields (:math:`|E|, |B|, \rho`) at timestep 45, in the middle of the collision. + :width: 100% + + Slice across :math:`x` of different fields (:math:`|E|, |B|, \rho`) at timestep 45, in the middle of the collision. + + + .. tab-item:: Reduced Diagnostics + + A similar script to the one below was used to produce the image showing the benchmark against :cite:t:`ex-Yakimenko2019`. + + .. literalinclude:: plot_reduced.py + :language: python3 + :caption: You can copy this file from ``Examples/Physics_applications/beam-beam_collision/plot_reduced.py``. + + .. figure:: https://gist.github.com/user-attachments/assets/c280490a-f1f2-4329-ad3c-46817d245dc1 + :alt: Photon and pair production rates in time throughout the collision. + :width: 100% + + Photon and pair production rates in time throughout the collision. diff --git a/Examples/Physics_applications/beam_beam_collision/analysis_default_openpmd_regression.py b/Examples/Physics_applications/beam_beam_collision/analysis_default_openpmd_regression.py new file mode 120000 index 00000000000..73e5ec47001 --- /dev/null +++ b/Examples/Physics_applications/beam_beam_collision/analysis_default_openpmd_regression.py @@ -0,0 +1 @@ +../../analysis_default_openpmd_regression.py \ No newline at end of file diff --git a/Examples/Physics_applications/beam-beam_collision/inputs b/Examples/Physics_applications/beam_beam_collision/inputs_test_3d_beam_beam_collision similarity index 99% rename from Examples/Physics_applications/beam-beam_collision/inputs rename to Examples/Physics_applications/beam_beam_collision/inputs_test_3d_beam_beam_collision index 488e997f895..d0cf3cd7ebf 100644 --- a/Examples/Physics_applications/beam-beam_collision/inputs +++ b/Examples/Physics_applications/beam_beam_collision/inputs_test_3d_beam_beam_collision @@ -27,8 +27,7 @@ my_constants.Lz = 180.0*clight/omegab # for a full scale simulation use: nx, ny, nz = 512, 512, 1024 my_constants.nx = 64 my_constants.ny = 64 -my_constants.nz = 128 - +my_constants.nz = 64 # TIME my_constants.T = 0.7*Lz/clight @@ -212,7 +211,7 @@ warpx.do_qed_schwinger = 0. # FULL diagnostics.diags_names = diag1 -diag1.intervals = 0 +diag1.intervals = 15 diag1.diag_type = Full diag1.write_species = 1 diag1.fields_to_plot = Ex Ey Ez Bx By Bz rho_beam1 rho_beam2 rho_ele1 rho_pos1 rho_ele2 rho_pos2 diff --git a/Examples/Physics_applications/beam_beam_collision/plot_fields.py b/Examples/Physics_applications/beam_beam_collision/plot_fields.py new file mode 100644 index 00000000000..a7ddb2d13e9 --- /dev/null +++ b/Examples/Physics_applications/beam_beam_collision/plot_fields.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python3 + +import matplotlib.pyplot as plt +import numpy as np +from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable +from openpmd_viewer import OpenPMDTimeSeries + +plt.rcParams.update({"font.size": 16}) + +series = OpenPMDTimeSeries("./diags/diag1") +steps = series.iterations + + +for slice_axis in ["x", "y"]: # slice the fields along x and y + for n in steps: # loop through the available timesteps + fig, ax = plt.subplots( + ncols=2, nrows=2, figsize=(10, 6), dpi=300, sharex=True, sharey=True + ) + + # get E field + Ex, info = series.get_field( + field="E", coord="x", iteration=n, plot=False, slice_across=slice_axis + ) + Ey, info = series.get_field( + field="E", coord="y", iteration=n, plot=False, slice_across=slice_axis + ) + Ez, info = series.get_field( + field="E", coord="z", iteration=n, plot=False, slice_across=slice_axis + ) + # get B field + Bx, info = series.get_field( + field="B", coord="x", iteration=n, plot=False, slice_across=slice_axis + ) + By, info = series.get_field( + field="B", coord="y", iteration=n, plot=False, slice_across=slice_axis + ) + Bz, info = series.get_field( + field="B", coord="z", iteration=n, plot=False, slice_across=slice_axis + ) + # get charge densities + rho_beam1, info = series.get_field( + field="rho_beam1", iteration=n, plot=False, slice_across=slice_axis + ) + rho_beam2, info = series.get_field( + field="rho_beam2", iteration=n, plot=False, slice_across=slice_axis + ) + rho_ele1, info = series.get_field( + field="rho_ele1", iteration=n, plot=False, slice_across=slice_axis + ) + rho_pos1, info = series.get_field( + field="rho_pos1", iteration=n, plot=False, slice_across=slice_axis + ) + rho_ele2, info = series.get_field( + field="rho_ele2", iteration=n, plot=False, slice_across=slice_axis + ) + rho_pos2, info = series.get_field( + field="rho_pos2", iteration=n, plot=False, slice_across=slice_axis + ) + + xmin = info.z.min() + xmax = info.z.max() + xlabel = "z [m]" + + if slice_axis == "x": + ymin = info.y.min() + ymax = info.y.max() + ylabel = "y [m]" + elif slice_axis == "y": + ymin = info.x.min() + ymax = info.x.max() + ylabel = "x [m]" + + # plot E magnitude + Emag = np.sqrt(Ex**2 + Ey**2 + Ez**2) + im = ax[0, 0].imshow( + np.transpose(Emag), + cmap="seismic", + extent=[xmin, xmax, ymin, ymax], + vmin=0, + vmax=np.max(np.abs(Emag)), + ) + ax[0, 0].set_title("E [V/m]") + divider = make_axes_locatable(ax[0, 0]) + cax = divider.append_axes("right", size="5%", pad=0.05) + fig.colorbar(im, cax=cax, orientation="vertical") + + # plot B magnitude + Bmag = np.sqrt(Bx**2 + By**2 + Bz**2) + im = ax[1, 0].imshow( + np.transpose(Bmag), + cmap="seismic", + extent=[xmin, xmax, ymin, ymax], + vmin=0, + vmax=np.max(np.abs(Bmag)), + ) + ax[1, 0].set_title("B [T]") + divider = make_axes_locatable(ax[1, 0]) + cax = divider.append_axes("right", size="5%", pad=0.05) + fig.colorbar(im, cax=cax, orientation="vertical") + + # plot beam densities + rho_beams = rho_beam1 + rho_beam2 + im = ax[0, 1].imshow( + np.transpose(rho_beams), + cmap="seismic", + extent=[xmin, xmax, ymin, ymax], + vmin=-np.max(np.abs(rho_beams)), + vmax=np.max(np.abs(rho_beams)), + ) + ax[0, 1].set_title(r"$\rho$ beams [C/m$^3$]") + divider = make_axes_locatable(ax[0, 1]) + cax = divider.append_axes("right", size="5%", pad=0.05) + fig.colorbar(im, cax=cax, orientation="vertical") + + # plot secondary densities + rho2 = rho_ele1 + rho_pos1 + rho_ele2 + rho_pos2 + im = ax[1, 1].imshow( + np.transpose(rho2), + cmap="seismic", + extent=[xmin, xmax, ymin, ymax], + vmin=-np.max(np.abs(rho2)), + vmax=np.max(np.abs(rho2)), + ) + ax[1, 1].set_title(r"$\rho$ secondaries [C/m$^3$]") + divider = make_axes_locatable(ax[1, 1]) + cax = divider.append_axes("right", size="5%", pad=0.05) + fig.colorbar(im, cax=cax, orientation="vertical") + + for a in ax[-1, :].reshape(-1): + a.set_xlabel(xlabel) + for a in ax[:, 0].reshape(-1): + a.set_ylabel(ylabel) + + fig.suptitle(f"Iteration = {n}, time [s] = {series.current_t}", fontsize=20) + plt.tight_layout() + + image_file_name = "FIELDS_" + slice_axis + f"_{n:03d}.png" + plt.savefig(image_file_name, dpi=100, bbox_inches="tight") + plt.close() diff --git a/Examples/Physics_applications/beam_beam_collision/plot_reduced.py b/Examples/Physics_applications/beam_beam_collision/plot_reduced.py new file mode 100644 index 00000000000..3f59f975519 --- /dev/null +++ b/Examples/Physics_applications/beam_beam_collision/plot_reduced.py @@ -0,0 +1,48 @@ +import matplotlib.pyplot as plt +import numpy as np +import pandas as pd +from scipy.constants import c, nano, physical_constants + +r_e = physical_constants["classical electron radius"][0] +my_dpi = 300 +sigmaz = 10 * nano + +fig, ax = plt.subplots( + ncols=2, nrows=1, figsize=(2000.0 / my_dpi, 1000.0 / my_dpi), dpi=my_dpi +) + +rdir = "./diags/reducedfiles/" + +df_cr = pd.read_csv(f"{rdir}" + "ColliderRelevant_beam1_beam2.txt", sep=" ", header=0) +df_pn = pd.read_csv(f"{rdir}" + "ParticleNumber.txt", sep=" ", header=0) + + +times = df_cr[[col for col in df_cr.columns if "]time" in col]].to_numpy() +steps = df_cr[[col for col in df_cr.columns if "]step" in col]].to_numpy() + +x = df_cr[[col for col in df_cr.columns if "]dL_dt" in col]].to_numpy() +coll_index = np.argmax(x) +coll_time = times[coll_index] + +# number of photons per beam particle +np1 = df_pn[[col for col in df_pn.columns if "]pho1_weight" in col]].to_numpy() +np2 = df_pn[[col for col in df_pn.columns if "]pho2_weight" in col]].to_numpy() +Ne = df_pn[[col for col in df_pn.columns if "]beam1_weight" in col]].to_numpy()[0] +Np = df_pn[[col for col in df_pn.columns if "]beam2_weight" in col]].to_numpy()[0] + +ax[0].plot((times - coll_time) / (sigmaz / c), (np1 + np2) / (Ne + Np), lw=2) +ax[0].set_title(r"photon number/beam particle") + +# number of NLBW particles per beam particle +e1 = df_pn[[col for col in df_pn.columns if "]ele1_weight" in col]].to_numpy() +e2 = df_pn[[col for col in df_pn.columns if "]ele2_weight" in col]].to_numpy() + +ax[1].plot((times - coll_time) / (sigmaz / c), (e1 + e2) / (Ne + Np), lw=2) +ax[1].set_title(r"NLBW particles/beam particle") + +for a in ax.reshape(-1): + a.set_xlabel(r"time [$\sigma_z/c$]") +image_file_name = "reduced.png" +plt.tight_layout() +plt.savefig(image_file_name, dpi=300, bbox_inches="tight") +plt.close("all") diff --git a/Examples/Physics_applications/capacitive_discharge/CMakeLists.txt b/Examples/Physics_applications/capacitive_discharge/CMakeLists.txt new file mode 100644 index 00000000000..5af1d0a0664 --- /dev/null +++ b/Examples/Physics_applications/capacitive_discharge/CMakeLists.txt @@ -0,0 +1,53 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_background_mcc_picmi # name + 1 # dims + 2 # nprocs + "inputs_base_1d_picmi.py --test --pythonsolver" # inputs + analysis_1d.py # analysis + diags/diag1000050 # output + OFF # dependency +) + +add_warpx_test( + test_1d_dsmc_picmi # name + 1 # dims + 2 # nprocs + "inputs_base_1d_picmi.py --test --dsmc" # inputs + analysis_dsmc.py # analysis + diags/diag1000050 # output + OFF # dependency +) + +add_warpx_test( + test_2d_background_mcc # name + 2 # dims + 2 # nprocs + inputs_test_2d_background_mcc # inputs + analysis_default_regression.py # analysis + diags/diag1000050 # output + OFF # dependency +) + +# FIXME: can we make this a single precision for now? +#add_warpx_test( +# test_2d_background_mcc_dp_psp # name +# 2 # dims +# 2 # nprocs +## inputs_test_2d_background_mcc_dp_psp # inputs +# analysis_default_regression.py # analysis +# diags/diag1000050 # output +# OFF # dependency +#) + +add_warpx_test( + test_2d_background_mcc_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_background_mcc_picmi.py # inputs + analysis_2d.py # analysis + diags/diag1000050 # output + OFF # dependency +) diff --git a/Examples/Physics_applications/capacitive_discharge/README.rst b/Examples/Physics_applications/capacitive_discharge/README.rst index 708b4528cd5..13b6b3010b3 100644 --- a/Examples/Physics_applications/capacitive_discharge/README.rst +++ b/Examples/Physics_applications/capacitive_discharge/README.rst @@ -22,17 +22,17 @@ The implementation has been tested against the benchmark results from :cite:t:`e Run --- -The 1D PICMI input file can be used to reproduce the results from Turner et al. for a given case, ``N`` from 1 to 4, by executing ``python3 PICMI_inputs_1d.py -n N``, e.g., +The 1D PICMI input file can be used to reproduce the results from Turner et al. for a given case, ``N`` from 1 to 4, by executing ``python3 inputs_base_1d_picmi.py -n N``, e.g., .. code-block:: bash - python3 PICMI_inputs_1d.py -n 1 + python3 inputs_base_1d_picmi.py -n 1 For `MPI-parallel `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. -.. literalinclude:: PICMI_inputs_1d.py +.. literalinclude:: inputs_base_1d_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py``. + :caption: You can copy this file from ``Examples/Physics_applications/capacitive_discharge/inputs_base_1d_picmi.py``. Analyze diff --git a/Examples/Physics_applications/capacitive_discharge/analysis_1d.py b/Examples/Physics_applications/capacitive_discharge/analysis_1d.py index 29b5272d8b1..82d98c38210 100755 --- a/Examples/Physics_applications/capacitive_discharge/analysis_1d.py +++ b/Examples/Physics_applications/capacitive_discharge/analysis_1d.py @@ -4,6 +4,7 @@ import numpy as np +# fmt: off ref_density = np.array([ 1.27989677e+14, 2.23601330e+14, 2.55400265e+14, 2.55664972e+14, 2.55806841e+14, 2.55806052e+14, 2.55815865e+14, 2.55755151e+14, @@ -39,7 +40,8 @@ 2.56041610e+14, 2.56041551e+14, 2.56088641e+14, 2.23853646e+14, 1.27580207e+14 ]) +# fmt: on -density_data = np.load( 'ion_density_case_1.npy' ) +density_data = np.load("ion_density_case_1.npy") print(repr(density_data)) assert np.allclose(density_data, ref_density) diff --git a/Examples/Physics_applications/capacitive_discharge/analysis_2d.py b/Examples/Physics_applications/capacitive_discharge/analysis_2d.py index 472758ec63b..f52f69f4bf4 100755 --- a/Examples/Physics_applications/capacitive_discharge/analysis_2d.py +++ b/Examples/Physics_applications/capacitive_discharge/analysis_2d.py @@ -2,18 +2,17 @@ # Copyright 2021 Modern Electron -# This script checks that the PICMI_inputs_2d.py run more-or-less matches the +# This script checks that the inputs_test_2d_background_mcc_picmi.py run more-or-less matches the # results from the non-PICMI run. The PICMI run is using an external Poisson # solver that directly solves the Poisson equation using matrix inversion # rather than the iterative approach from the MLMG solver. import sys -sys.path.append('../../../../warpx/Regression/Checksum/') +sys.path.append("../../../../warpx/Regression/Checksum/") import checksumAPI my_check = checksumAPI.evaluate_checksum( - 'background_mcc', 'Python_background_mcc_plt000050', - do_particles=True, rtol=5e-3 + "test_2d_background_mcc", "diags/diag1000050", do_particles=True, rtol=5e-3 ) diff --git a/Examples/Physics_applications/capacitive_discharge/analysis_default_regression.py b/Examples/Physics_applications/capacitive_discharge/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Physics_applications/capacitive_discharge/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py b/Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py index 4c46b9e3f10..505521fc1ca 100755 --- a/Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py +++ b/Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py @@ -7,7 +7,7 @@ import numpy as np -sys.path.append('../../../../warpx/Regression/Checksum/') +sys.path.append("../../../../warpx/Regression/Checksum/") import checksumAPI @@ -17,42 +17,44 @@ my_check = checksumAPI.evaluate_checksum(test_name, fn, do_particles=True) +# fmt: off ref_density = np.array([ - 1.27943881e+14, 2.23583097e+14, 2.55396716e+14, 2.55673406e+14, - 2.55827566e+14, 2.55803446e+14, 2.55798707e+14, 2.55748961e+14, - 2.55906413e+14, 2.56063991e+14, 2.55937018e+14, 2.55841390e+14, - 2.55917724e+14, 2.55988641e+14, 2.56052050e+14, 2.56285151e+14, - 2.56647960e+14, 2.56756264e+14, 2.56430158e+14, 2.56117493e+14, - 2.56065302e+14, 2.56265220e+14, 2.56328575e+14, 2.56031495e+14, - 2.56123757e+14, 2.56431173e+14, 2.56385320e+14, 2.56391170e+14, - 2.56561177e+14, 2.56513926e+14, 2.56332201e+14, 2.56252442e+14, - 2.56238982e+14, 2.56216498e+14, 2.56461281e+14, 2.56863199e+14, - 2.56908100e+14, 2.56926112e+14, 2.57001641e+14, 2.56735963e+14, - 2.56315358e+14, 2.56137028e+14, 2.56101418e+14, 2.56276827e+14, - 2.56425668e+14, 2.56181798e+14, 2.56044925e+14, 2.56330387e+14, - 2.56623150e+14, 2.56445316e+14, 2.56292750e+14, 2.56440918e+14, - 2.56433406e+14, 2.56186982e+14, 2.56236390e+14, 2.56469557e+14, - 2.56349704e+14, 2.56487457e+14, 2.56771823e+14, 2.56614683e+14, - 2.56552210e+14, 2.56850291e+14, 2.56783396e+14, 2.56483187e+14, - 2.56510868e+14, 2.56490408e+14, 2.56656042e+14, 2.56820924e+14, - 2.56640314e+14, 2.56465063e+14, 2.56510264e+14, 2.56917331e+14, - 2.57228490e+14, 2.56960593e+14, 2.56587911e+14, 2.56672682e+14, - 2.56774414e+14, 2.56548335e+14, 2.56225540e+14, 2.56079693e+14, - 2.56062796e+14, 2.56054612e+14, 2.56028683e+14, 2.56068820e+14, - 2.56380975e+14, 2.56654914e+14, 2.56776792e+14, 2.56983661e+14, - 2.56989477e+14, 2.56646250e+14, 2.56589639e+14, 2.56946205e+14, - 2.57091201e+14, 2.56913590e+14, 2.56513535e+14, 2.56122597e+14, - 2.56176340e+14, 2.56808001e+14, 2.57239393e+14, 2.56845066e+14, - 2.56662482e+14, 2.56862583e+14, 2.56518922e+14, 2.56155531e+14, - 2.56362794e+14, 2.57203564e+14, 2.57737938e+14, 2.57252026e+14, - 2.56859277e+14, 2.56658995e+14, 2.56357364e+14, 2.56393454e+14, - 2.56714308e+14, 2.57042200e+14, 2.57551087e+14, 2.57502490e+14, - 2.56641118e+14, 2.56401115e+14, 2.56644629e+14, 2.56673096e+14, - 2.56534659e+14, 2.56357745e+14, 2.56455309e+14, 2.56586850e+14, - 2.56442415e+14, 2.56335971e+14, 2.56411429e+14, 2.24109018e+14, - 1.27678869e+14 + 1.27942709e+14, 2.23579371e+14, 2.55384387e+14, 2.55660663e+14, + 2.55830911e+14, 2.55814337e+14, 2.55798906e+14, 2.55744891e+14, + 2.55915585e+14, 2.56083194e+14, 2.55942354e+14, 2.55833026e+14, + 2.56036175e+14, 2.56234141e+14, 2.56196179e+14, 2.56146141e+14, + 2.56168022e+14, 2.56216909e+14, 2.56119961e+14, 2.56065167e+14, + 2.56194764e+14, 2.56416398e+14, 2.56465239e+14, 2.56234337e+14, + 2.56234503e+14, 2.56316003e+14, 2.56175023e+14, 2.56030269e+14, + 2.56189301e+14, 2.56286379e+14, 2.56130396e+14, 2.56295225e+14, + 2.56474082e+14, 2.56340375e+14, 2.56350864e+14, 2.56462330e+14, + 2.56469391e+14, 2.56412726e+14, 2.56241788e+14, 2.56355650e+14, + 2.56650599e+14, 2.56674748e+14, 2.56642480e+14, 2.56823508e+14, + 2.57025029e+14, 2.57110614e+14, 2.57042364e+14, 2.56950884e+14, + 2.57051822e+14, 2.56952148e+14, 2.56684016e+14, 2.56481130e+14, + 2.56277073e+14, 2.56065774e+14, 2.56190033e+14, 2.56411074e+14, + 2.56202418e+14, 2.56128368e+14, 2.56227002e+14, 2.56083004e+14, + 2.56056768e+14, 2.56343831e+14, 2.56443659e+14, 2.56280541e+14, + 2.56191572e+14, 2.56147304e+14, 2.56342794e+14, 2.56735473e+14, + 2.56994680e+14, 2.56901500e+14, 2.56527131e+14, 2.56490824e+14, + 2.56614730e+14, 2.56382744e+14, 2.56588214e+14, 2.57160270e+14, + 2.57230435e+14, 2.57116530e+14, 2.57065771e+14, 2.57236507e+14, + 2.57112865e+14, 2.56540177e+14, 2.56416828e+14, 2.56648954e+14, + 2.56625594e+14, 2.56411003e+14, 2.56523754e+14, 2.56841108e+14, + 2.56856368e+14, 2.56757912e+14, 2.56895134e+14, 2.57144419e+14, + 2.57001944e+14, 2.56371759e+14, 2.56179404e+14, 2.56541905e+14, + 2.56715727e+14, 2.56851681e+14, 2.57114458e+14, 2.57001739e+14, + 2.56825690e+14, 2.56879682e+14, 2.56699673e+14, 2.56532841e+14, + 2.56479582e+14, 2.56630989e+14, 2.56885996e+14, 2.56694637e+14, + 2.56250819e+14, 2.56045278e+14, 2.56366075e+14, 2.56693733e+14, + 2.56618530e+14, 2.56580918e+14, 2.56812781e+14, 2.56754216e+14, + 2.56444736e+14, 2.56473391e+14, 2.56538398e+14, 2.56626551e+14, + 2.56471950e+14, 2.56274969e+14, 2.56489423e+14, 2.56645266e+14, + 2.56611124e+14, 2.56344324e+14, 2.56244156e+14, 2.24183727e+14, + 1.27909856e+14 ]) +# fmt: on -density_data = np.load( 'ion_density_case_1.npy' ) +density_data = np.load("ion_density_case_1.npy") print(repr(density_data)) assert np.allclose(density_data, ref_density) diff --git a/Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py b/Examples/Physics_applications/capacitive_discharge/inputs_base_1d_picmi.py similarity index 73% rename from Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py rename to Examples/Physics_applications/capacitive_discharge/inputs_base_1d_picmi.py index 8b58790d2e6..3de88f3b3cb 100644 --- a/Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py +++ b/Examples/Physics_applications/capacitive_discharge/inputs_base_1d_picmi.py @@ -12,14 +12,15 @@ from scipy.sparse import linalg as sla from pywarpx import callbacks, fields, libwarpx, particle_containers, picmi +from pywarpx.LoadThirdParty import load_cupy constants = picmi.constants class PoissonSolver1D(picmi.ElectrostaticSolver): """This solver is maintained as an example of the use of Python callbacks. - However, it is not necessarily needed since the 1D code has the direct tridiagonal - solver implemented.""" + However, it is not necessarily needed since the 1D code has the direct tridiagonal + solver implemented.""" def __init__(self, grid, **kwargs): """Direct solver for the Poisson equation using superLU. This solver is @@ -31,11 +32,13 @@ def __init__(self, grid, **kwargs): """ # Sanity check that this solver is appropriate to use if not isinstance(grid, picmi.Cartesian1DGrid): - raise RuntimeError('Direct solver can only be used on a 1D grid.') + raise RuntimeError("Direct solver can only be used on a 1D grid.") super(PoissonSolver1D, self).__init__( - grid=grid, method=kwargs.pop('method', 'Multigrid'), - required_precision=1, **kwargs + grid=grid, + method=kwargs.pop("method", "Multigrid"), + required_precision=1, + **kwargs, ) def solver_initialize_inputs(self): @@ -65,7 +68,7 @@ def solver_initialize_inputs(self): self.nxguardphi = 1 self.nzguardphi = 1 - self.phi = np.zeros(self.nz + 1 + 2*self.nzguardphi) + self.phi = np.zeros(self.nz + 1 + 2 * self.nzguardphi) self.decompose_matrix() @@ -107,10 +110,8 @@ def solve(self): left_voltage = 0.0 right_voltage = eval( - self.right_voltage, { - 't': self.sim.extension.warpx.gett_new(0), - 'sin': np.sin, 'pi': np.pi - } + self.right_voltage, + {"t": self.sim.extension.warpx.gett_new(0), "sin": np.sin, "pi": np.pi}, ) # Construct b vector @@ -123,31 +124,31 @@ def solve(self): phi = self.lu.solve(b) - self.phi[self.nzguardphi:-self.nzguardphi] = phi + self.phi[self.nzguardphi : -self.nzguardphi] = phi - self.phi[:self.nzguardphi] = left_voltage - self.phi[-self.nzguardphi:] = right_voltage + self.phi[: self.nzguardphi] = left_voltage + self.phi[-self.nzguardphi :] = right_voltage class CapacitiveDischargeExample(object): - '''The following runs a simulation of a parallel plate capacitor seeded + """The following runs a simulation of a parallel plate capacitor seeded with a plasma in the spacing between the plates. A time varying voltage is applied across the capacitor. The groups of 4 values below correspond to the 4 cases simulated by Turner et al. (2013) in their benchmarks of PIC-MCC codes. - ''' + """ - gap = 0.067 # m + gap = 0.067 # m - freq = 13.56e6 # Hz - voltage = [450.0, 200.0, 150.0, 120.0] # V + freq = 13.56e6 # Hz + voltage = [450.0, 200.0, 150.0, 120.0] # V - gas_density = [9.64e20, 32.1e20, 96.4e20, 321e20] # m^-3 - gas_temp = 300.0 # K - m_ion = 6.67e-27 # kg + gas_density = [9.64e20, 32.1e20, 96.4e20, 321e20] # m^-3 + gas_temp = 300.0 # K + m_ion = 6.67e-27 # kg - plasma_density = [2.56e14, 5.12e14, 5.12e14, 3.84e14] # m^-3 - elec_temp = 30000.0 # K + plasma_density = [2.56e14, 5.12e14, 5.12e14, 3.84e14] # m^-3 + elec_temp = 30000.0 # K seed_nppc = 16 * np.array([32, 16, 8, 4]) @@ -205,10 +206,10 @@ def setup_run(self): warpx_max_grid_size=128, lower_bound=[0], upper_bound=[self.gap], - lower_boundary_conditions=['dirichlet'], - upper_boundary_conditions=['dirichlet'], - lower_boundary_conditions_particles=['absorbing'], - upper_boundary_conditions_particles=['absorbing'], + lower_boundary_conditions=["dirichlet"], + upper_boundary_conditions=["dirichlet"], + lower_boundary_conditions_particles=["absorbing"], + upper_boundary_conditions_particles=["absorbing"], warpx_potential_hi_z=self.voltage, ) @@ -227,85 +228,93 @@ def setup_run(self): ####################################################################### self.electrons = picmi.Species( - particle_type='electron', name='electrons', + particle_type="electron", + name="electrons", initial_distribution=picmi.UniformDistribution( density=self.plasma_density, - rms_velocity=[np.sqrt(constants.kb * self.elec_temp / constants.m_e)]*3, - ) + rms_velocity=[np.sqrt(constants.kb * self.elec_temp / constants.m_e)] + * 3, + ), ) self.ions = picmi.Species( - particle_type='He', name='he_ions', - charge='q_e', mass=self.m_ion, + particle_type="He", + name="he_ions", + charge="q_e", + mass=self.m_ion, initial_distribution=picmi.UniformDistribution( density=self.plasma_density, - rms_velocity=[np.sqrt(constants.kb * self.gas_temp / self.m_ion)]*3, - ) + rms_velocity=[np.sqrt(constants.kb * self.gas_temp / self.m_ion)] * 3, + ), ) if self.dsmc: self.neutrals = picmi.Species( - particle_type='He', name='neutrals', - charge=0, mass=self.m_ion, + particle_type="He", + name="neutrals", + charge=0, + mass=self.m_ion, warpx_reflection_model_zlo=1.0, warpx_reflection_model_zhi=1.0, warpx_do_resampling=True, - warpx_resampling_trigger_max_avg_ppc=int(self.seed_nppc*1.5), + warpx_resampling_trigger_max_avg_ppc=int(self.seed_nppc * 1.5), initial_distribution=picmi.UniformDistribution( density=self.gas_density, - rms_velocity=[np.sqrt(constants.kb * self.gas_temp / self.m_ion)]*3, - ) + rms_velocity=[np.sqrt(constants.kb * self.gas_temp / self.m_ion)] + * 3, + ), ) ####################################################################### # Collision initialization # ####################################################################### - cross_sec_direc = '../../../../warpx-data/MCC_cross_sections/He/' + cross_sec_direc = "../../../../warpx-data/MCC_cross_sections/He/" electron_colls = picmi.MCCCollisions( - name='coll_elec', + name="coll_elec", species=self.electrons, background_density=self.gas_density, background_temperature=self.gas_temp, background_mass=self.ions.mass, ndt=self.mcc_subcycling_steps, scattering_processes={ - 'elastic' : { - 'cross_section' : cross_sec_direc+'electron_scattering.dat' + "elastic": { + "cross_section": cross_sec_direc + "electron_scattering.dat" }, - 'excitation1' : { - 'cross_section': cross_sec_direc+'excitation_1.dat', - 'energy' : 19.82 + "excitation1": { + "cross_section": cross_sec_direc + "excitation_1.dat", + "energy": 19.82, }, - 'excitation2' : { - 'cross_section': cross_sec_direc+'excitation_2.dat', - 'energy' : 20.61 + "excitation2": { + "cross_section": cross_sec_direc + "excitation_2.dat", + "energy": 20.61, }, - 'ionization' : { - 'cross_section' : cross_sec_direc+'ionization.dat', - 'energy' : 24.55, - 'species' : self.ions + "ionization": { + "cross_section": cross_sec_direc + "ionization.dat", + "energy": 24.55, + "species": self.ions, }, - } + }, ) - ion_scattering_processes={ - 'elastic': {'cross_section': cross_sec_direc+'ion_scattering.dat'}, - 'back': {'cross_section': cross_sec_direc+'ion_back_scatter.dat'}, + ion_scattering_processes = { + "elastic": {"cross_section": cross_sec_direc + "ion_scattering.dat"}, + "back": {"cross_section": cross_sec_direc + "ion_back_scatter.dat"}, # 'charge_exchange': {'cross_section': cross_sec_direc+'charge_exchange.dat'} } if self.dsmc: ion_colls = picmi.DSMCCollisions( - name='coll_ion', + name="coll_ion", species=[self.ions, self.neutrals], - ndt=5, scattering_processes=ion_scattering_processes + ndt=5, + scattering_processes=ion_scattering_processes, ) else: ion_colls = picmi.MCCCollisions( - name='coll_ion', + name="coll_ion", species=self.ions, background_density=self.gas_density, background_temperature=self.gas_temp, ndt=self.mcc_subcycling_steps, - scattering_processes=ion_scattering_processes + scattering_processes=ion_scattering_processes, ) ####################################################################### @@ -317,28 +326,28 @@ def setup_run(self): time_step_size=self.dt, max_steps=self.max_steps, warpx_collisions=[electron_colls, ion_colls], - verbose=self.test + verbose=self.test, ) self.solver.sim = self.sim self.sim.add_species( self.electrons, - layout = picmi.GriddedLayout( + layout=picmi.GriddedLayout( n_macroparticle_per_cell=[self.seed_nppc], grid=self.grid - ) + ), ) self.sim.add_species( self.ions, - layout = picmi.GriddedLayout( + layout=picmi.GriddedLayout( n_macroparticle_per_cell=[self.seed_nppc], grid=self.grid - ) + ), ) if self.dsmc: self.sim.add_species( self.neutrals, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[self.seed_nppc//2], grid=self.grid - ) + layout=picmi.GriddedLayout( + n_macroparticle_per_cell=[self.seed_nppc // 2], grid=self.grid + ), ) self.solver.sim_ext = self.sim.extension @@ -350,31 +359,19 @@ def setup_run(self): # Add diagnostics for the CI test to be happy # ####################################################################### - if self.dsmc: - file_prefix = 'Python_dsmc_1d_plt' - else: - if self.pythonsolver: - file_prefix = 'Python_background_mcc_1d_plt' - else: - file_prefix = 'Python_background_mcc_1d_tridiag_plt' - species = [self.electrons, self.ions] if self.dsmc: species.append(self.neutrals) particle_diag = picmi.ParticleDiagnostic( species=species, - name='diag1', + name="diag1", period=0, - write_dir='.', - warpx_file_prefix=file_prefix ) field_diag = picmi.FieldDiagnostic( - name='diag1', + name="diag1", grid=self.grid, period=0, - data_list=['rho_electrons', 'rho_he_ions'], - write_dir='.', - warpx_file_prefix=file_prefix + data_list=["rho_electrons", "rho_he_ions"], ) self.sim.add_diagnostic(particle_diag) self.sim.add_diagnostic(field_diag) @@ -387,7 +384,7 @@ def rethermalize_neutrals(self): if step % 1000 != 10: return - if not hasattr(self, 'neutral_cont'): + if not hasattr(self, "neutral_cont"): self.neutral_cont = particle_containers.ParticleContainerWrapper( self.neutrals.name ) @@ -396,23 +393,24 @@ def rethermalize_neutrals(self): uy_arrays = self.neutral_cont.uyp uz_arrays = self.neutral_cont.uzp + xp, _ = load_cupy() + vel_std = np.sqrt(constants.kb * self.gas_temp / self.m_ion) for ii in range(len(ux_arrays)): nps = len(ux_arrays[ii]) - ux_arrays[ii][:] = vel_std * self.rng.normal(size=nps) - uy_arrays[ii][:] = vel_std * self.rng.normal(size=nps) - uz_arrays[ii][:] = vel_std * self.rng.normal(size=nps) + ux_arrays[ii][:] = xp.array(vel_std * self.rng.normal(size=nps)) + uy_arrays[ii][:] = xp.array(vel_std * self.rng.normal(size=nps)) + uz_arrays[ii][:] = xp.array(vel_std * self.rng.normal(size=nps)) def _get_rho_ions(self): # deposit the ion density in rho_fp - he_ions_wrapper = particle_containers.ParticleContainerWrapper('he_ions') + he_ions_wrapper = particle_containers.ParticleContainerWrapper("he_ions") he_ions_wrapper.deposit_charge_density(level=0) rho_data = self.rho_wrapper[...] self.ion_density_array += rho_data / constants.q_e / self.diag_steps def run_sim(self): - self.sim.step(self.max_steps - self.diag_steps) self.rho_wrapper = fields.RhoFPWrapper(0, False) @@ -422,15 +420,15 @@ def run_sim(self): if self.pythonsolver: # confirm that the external solver was run - assert hasattr(self.solver, 'phi') + assert hasattr(self.solver, "phi") if libwarpx.amr.ParallelDescriptor.MyProc() == 0: - np.save(f'ion_density_case_{self.n+1}.npy', self.ion_density_array) + np.save(f"ion_density_case_{self.n+1}.npy", self.ion_density_array) # query the particle z-coordinates if this is run during CI testing # to cover that functionality if self.test: - he_ions_wrapper = particle_containers.ParticleContainerWrapper('he_ions') + he_ions_wrapper = particle_containers.ParticleContainerWrapper("he_ions") nparts = he_ions_wrapper.get_particle_count(local=True) z_coords = np.concatenate(he_ions_wrapper.zp) assert len(z_coords) == nparts @@ -443,28 +441,31 @@ def run_sim(self): parser = argparse.ArgumentParser() parser.add_argument( - '-t', '--test', help='toggle whether this script is run as a short CI test', - action='store_true', + "-t", + "--test", + help="toggle whether this script is run as a short CI test", + action="store_true", ) parser.add_argument( - '-n', help='Test number to run (1 to 4)', required=False, type=int, - default=1 + "-n", help="Test number to run (1 to 4)", required=False, type=int, default=1 ) parser.add_argument( - '--pythonsolver', help='toggle whether to use the Python level solver', - action='store_true' + "--pythonsolver", + help="toggle whether to use the Python level solver", + action="store_true", ) parser.add_argument( - '--dsmc', help='toggle whether to use DSMC for ions in place of MCC', - action='store_true' + "--dsmc", + help="toggle whether to use DSMC for ions in place of MCC", + action="store_true", ) args, left = parser.parse_known_args() -sys.argv = sys.argv[:1]+left +sys.argv = sys.argv[:1] + left if args.n < 1 or args.n > 4: - raise AttributeError('Test number must be an integer from 1 to 4.') + raise AttributeError("Test number must be an integer from 1 to 4.") run = CapacitiveDischargeExample( - n=args.n-1, test=args.test, pythonsolver=args.pythonsolver, dsmc=args.dsmc + n=args.n - 1, test=args.test, pythonsolver=args.pythonsolver, dsmc=args.dsmc ) run.run_sim() diff --git a/Examples/Physics_applications/capacitive_discharge/inputs_2d b/Examples/Physics_applications/capacitive_discharge/inputs_test_2d_background_mcc similarity index 98% rename from Examples/Physics_applications/capacitive_discharge/inputs_2d rename to Examples/Physics_applications/capacitive_discharge/inputs_test_2d_background_mcc index 2b11fd12978..e42e531c9e2 100644 --- a/Examples/Physics_applications/capacitive_discharge/inputs_2d +++ b/Examples/Physics_applications/capacitive_discharge/inputs_test_2d_background_mcc @@ -13,6 +13,7 @@ warpx.const_dt = 1.0/(400*freq) warpx.do_electrostatic = labframe warpx.self_fields_required_precision = 1e-06 warpx.use_filter = 0 +warpx.abort_on_warning_threshold = high amr.n_cell = 128 8 amr.max_grid_size = 128 diff --git a/Examples/Physics_applications/capacitive_discharge/PICMI_inputs_2d.py b/Examples/Physics_applications/capacitive_discharge/inputs_test_2d_background_mcc_picmi.py similarity index 63% rename from Examples/Physics_applications/capacitive_discharge/PICMI_inputs_2d.py rename to Examples/Physics_applications/capacitive_discharge/inputs_test_2d_background_mcc_picmi.py index 65baabba605..7879239d5ce 100755 --- a/Examples/Physics_applications/capacitive_discharge/PICMI_inputs_2d.py +++ b/Examples/Physics_applications/capacitive_discharge/inputs_test_2d_background_mcc_picmi.py @@ -17,19 +17,19 @@ # physics parameters ########################## -D_CA = 0.067 # m +D_CA = 0.067 # m -N_INERT = 9.64e20 # m^-3 -T_INERT = 300.0 # K +N_INERT = 9.64e20 # m^-3 +T_INERT = 300.0 # K -FREQ = 13.56e6 # Hz +FREQ = 13.56e6 # Hz VOLTAGE = 450.0 -M_ION = 6.67e-27 # kg +M_ION = 6.67e-27 # kg -PLASMA_DENSITY = 2.56e14 # m^-3 -T_ELEC = 30000.0 # K +PLASMA_DENSITY = 2.56e14 # m^-3 +T_ELEC = 30000.0 # K DT = 1.0 / (400 * FREQ) @@ -57,8 +57,8 @@ # using superLU decomposition ############################# -class PoissonSolverPseudo1D(picmi.ElectrostaticSolver): +class PoissonSolverPseudo1D(picmi.ElectrostaticSolver): def __init__(self, grid, **kwargs): """Direct solver for the Poisson equation using superLU. This solver is useful for pseudo 1D cases i.e. diode simulations with small x extent. @@ -68,16 +68,17 @@ def __init__(self, grid, **kwargs): solver will be installed. """ super(PoissonSolverPseudo1D, self).__init__( - grid=grid, method=kwargs.pop('method', 'Multigrid'), - required_precision=1, **kwargs + grid=grid, + method=kwargs.pop("method", "Multigrid"), + required_precision=1, + **kwargs, ) self.rho_wrapper = None self.phi_wrapper = None self.time_sum = 0.0 def solver_initialize_inputs(self): - """Grab geometrical quantities from the grid. - """ + """Grab geometrical quantities from the grid.""" self.right_voltage = self.grid.potential_xmax # set WarpX boundary potentials to None since we will handle it @@ -97,7 +98,7 @@ def solver_initialize_inputs(self): self.dz = (self.grid.upper_bound[1] - self.grid.lower_bound[1]) / self.nz if not np.isclose(self.dx, self.dz): - raise RuntimeError('Direct solver requires dx = dz.') + raise RuntimeError("Direct solver requires dx = dz.") self.nxguardrho = 2 self.nzguardrho = 2 @@ -105,8 +106,7 @@ def solver_initialize_inputs(self): self.nzguardphi = 1 self.phi = np.zeros( - (self.nx + 1 + 2*self.nxguardphi, - self.nz + 1 + 2*self.nzguardphi) + (self.nx + 1 + 2 * self.nxguardphi, self.nz + 1 + 2 * self.nzguardphi) ) self.decompose_matrix() @@ -120,24 +120,22 @@ def decompose_matrix(self): self.nzsolve = self.nz + 3 # Set up the computation matrix in order to solve A*phi = rho - A = np.zeros( - (self.nzsolve*self.nxsolve, self.nzsolve*self.nxsolve) - ) + A = np.zeros((self.nzsolve * self.nxsolve, self.nzsolve * self.nxsolve)) kk = 0 for ii in range(self.nxsolve): for jj in range(self.nzsolve): temp = np.zeros((self.nxsolve, self.nzsolve)) if ii == 0 or ii == self.nxsolve - 1: - temp[ii, jj] = 1. + temp[ii, jj] = 1.0 elif ii == 1: temp[ii, jj] = -2.0 - temp[ii-1, jj] = 1.0 - temp[ii+1, jj] = 1.0 + temp[ii - 1, jj] = 1.0 + temp[ii + 1, jj] = 1.0 elif ii == self.nxsolve - 2: temp[ii, jj] = -2.0 - temp[ii+1, jj] = 1.0 - temp[ii-1, jj] = 1.0 + temp[ii + 1, jj] = 1.0 + temp[ii - 1, jj] = 1.0 elif jj == 0: temp[ii, jj] = 1.0 temp[ii, -3] = -1.0 @@ -146,10 +144,10 @@ def decompose_matrix(self): temp[ii, 2] = -1.0 else: temp[ii, jj] = -4.0 - temp[ii, jj+1] = 1.0 - temp[ii, jj-1] = 1.0 - temp[ii-1, jj] = 1.0 - temp[ii+1, jj] = 1.0 + temp[ii, jj + 1] = 1.0 + temp[ii, jj - 1] = 1.0 + temp[ii - 1, jj] = 1.0 + temp[ii + 1, jj] = 1.0 A[kk] = temp.flatten() kk += 1 @@ -177,18 +175,21 @@ def solve(self): calculating phi from rho.""" right_voltage = eval( self.right_voltage, - {'t': sim.extension.warpx.gett_new(0), 'sin': np.sin, 'pi': np.pi} + {"t": sim.extension.warpx.gett_new(0), "sin": np.sin, "pi": np.pi}, ) left_voltage = 0.0 - rho = -self.rho_data[ - self.nxguardrho:-self.nxguardrho, self.nzguardrho:-self.nzguardrho - ] / constants.ep0 + rho = ( + -self.rho_data[ + self.nxguardrho : -self.nxguardrho, self.nzguardrho : -self.nzguardrho + ] + / constants.ep0 + ) # Construct b vector nx, nz = np.shape(rho) - source = np.zeros((nx, nz+2), dtype=np.float32) - source[:,1:-1] = rho * self.dx**2 + source = np.zeros((nx, nz + 2), dtype=np.float32) + source[:, 1:-1] = rho * self.dx**2 source[0] = left_voltage source[-1] = right_voltage @@ -197,16 +198,17 @@ def solve(self): b = source.flatten() flat_phi = self.lu.solve(b) - self.phi[self.nxguardphi:-self.nxguardphi] = ( - flat_phi.reshape(np.shape(source)) + self.phi[self.nxguardphi : -self.nxguardphi] = flat_phi.reshape( + np.shape(source) ) - self.phi[:self.nxguardphi] = left_voltage - self.phi[-self.nxguardphi:] = right_voltage + self.phi[: self.nxguardphi] = left_voltage + self.phi[-self.nxguardphi :] = right_voltage # the electrostatic solver in WarpX keeps the ghost cell values as 0 - self.phi[:,:self.nzguardphi] = 0 - self.phi[:,-self.nzguardphi:] = 0 + self.phi[:, : self.nzguardphi] = 0 + self.phi[:, -self.nzguardphi :] = 0 + ########################## # physics components @@ -216,73 +218,67 @@ def solve(self): v_rms_ion = np.sqrt(constants.kb * T_INERT / M_ION) uniform_plasma_elec = picmi.UniformDistribution( - density = PLASMA_DENSITY, - upper_bound = [None] * 3, - rms_velocity = [v_rms_elec] * 3, - directed_velocity = [0.] * 3 + density=PLASMA_DENSITY, + upper_bound=[None] * 3, + rms_velocity=[v_rms_elec] * 3, + directed_velocity=[0.0] * 3, ) uniform_plasma_ion = picmi.UniformDistribution( - density = PLASMA_DENSITY, - upper_bound = [None] * 3, - rms_velocity = [v_rms_ion] * 3, - directed_velocity = [0.] * 3 + density=PLASMA_DENSITY, + upper_bound=[None] * 3, + rms_velocity=[v_rms_ion] * 3, + directed_velocity=[0.0] * 3, ) electrons = picmi.Species( - particle_type='electron', name='electrons', - initial_distribution=uniform_plasma_elec + particle_type="electron", name="electrons", initial_distribution=uniform_plasma_elec ) ions = picmi.Species( - particle_type='He', name='he_ions', - charge='q_e', - initial_distribution=uniform_plasma_ion + particle_type="He", + name="he_ions", + charge="q_e", + initial_distribution=uniform_plasma_ion, ) # MCC collisions -cross_sec_direc = '../../../../warpx-data/MCC_cross_sections/He/' +cross_sec_direc = "../../../../warpx-data/MCC_cross_sections/He/" mcc_electrons = picmi.MCCCollisions( - name='coll_elec', + name="coll_elec", species=electrons, background_density=N_INERT, background_temperature=T_INERT, background_mass=ions.mass, scattering_processes={ - 'elastic' : { - 'cross_section' : cross_sec_direc+'electron_scattering.dat' - }, - 'excitation1' : { - 'cross_section': cross_sec_direc+'excitation_1.dat', - 'energy' : 19.82 + "elastic": {"cross_section": cross_sec_direc + "electron_scattering.dat"}, + "excitation1": { + "cross_section": cross_sec_direc + "excitation_1.dat", + "energy": 19.82, }, - 'excitation2' : { - 'cross_section': cross_sec_direc+'excitation_2.dat', - 'energy' : 20.61 + "excitation2": { + "cross_section": cross_sec_direc + "excitation_2.dat", + "energy": 20.61, }, - 'ionization' : { - 'cross_section' : cross_sec_direc+'ionization.dat', - 'energy' : 24.55, - 'species' : ions + "ionization": { + "cross_section": cross_sec_direc + "ionization.dat", + "energy": 24.55, + "species": ions, }, - } + }, ) mcc_ions = picmi.MCCCollisions( - name='coll_ion', + name="coll_ion", species=ions, background_density=N_INERT, background_temperature=T_INERT, scattering_processes={ - 'elastic' : { - 'cross_section' : cross_sec_direc+'ion_scattering.dat' - }, - 'back' : { - 'cross_section' : cross_sec_direc+'ion_back_scatter.dat' - }, + "elastic": {"cross_section": cross_sec_direc + "ion_scattering.dat"}, + "back": {"cross_section": cross_sec_direc + "ion_back_scatter.dat"}, # 'charge_exchange' : { # 'cross_section' : cross_sec_direc+'charge_exchange.dat' # } - } + }, ) ########################## @@ -290,17 +286,17 @@ def solve(self): ########################## grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, ny], + number_of_cells=[nx, ny], warpx_max_grid_size=128, - lower_bound = [xmin, ymin], - upper_bound = [xmax, ymax], - bc_xmin = 'dirichlet', - bc_xmax = 'dirichlet', - bc_ymin = 'periodic', - bc_ymax = 'periodic', - warpx_potential_hi_x = "%.1f*sin(2*pi*%.5e*t)" % (VOLTAGE, FREQ), - lower_boundary_conditions_particles=['absorbing', 'periodic'], - upper_boundary_conditions_particles=['absorbing', 'periodic'] + lower_bound=[xmin, ymin], + upper_bound=[xmax, ymax], + bc_xmin="dirichlet", + bc_xmax="dirichlet", + bc_ymin="periodic", + bc_ymax="periodic", + warpx_potential_hi_x="%.1f*sin(2*pi*%.5e*t)" % (VOLTAGE, FREQ), + lower_boundary_conditions_particles=["absorbing", "periodic"], + upper_boundary_conditions_particles=["absorbing", "periodic"], ) # solver = picmi.ElectrostaticSolver( @@ -313,18 +309,14 @@ def solve(self): ########################## particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = diagnostic_intervals, - write_dir = '.', - warpx_file_prefix = 'Python_background_mcc_plt' + name="diag1", + period=diagnostic_intervals, ) field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = diagnostic_intervals, - data_list = ['rho_electrons', 'rho_he_ions'], - write_dir = '.', - warpx_file_prefix = 'Python_background_mcc_plt' + name="diag1", + grid=grid, + period=diagnostic_intervals, + data_list=["rho_electrons", "rho_he_ions"], ) ########################## @@ -332,23 +324,23 @@ def solve(self): ########################## sim = picmi.Simulation( - solver = solver, - time_step_size = DT, - max_steps = max_steps, - warpx_collisions=[mcc_electrons, mcc_ions] + solver=solver, + time_step_size=DT, + max_steps=max_steps, + warpx_collisions=[mcc_electrons, mcc_ions], ) sim.add_species( electrons, - layout = picmi.GriddedLayout( + layout=picmi.GriddedLayout( n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid - ) + ), ) sim.add_species( ions, - layout = picmi.GriddedLayout( + layout=picmi.GriddedLayout( n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid - ) + ), ) sim.add_diagnostic(particle_diag) @@ -361,4 +353,4 @@ def solve(self): sim.step(max_steps) # confirm that the external solver was run -assert hasattr(solver, 'phi') +assert hasattr(solver, "phi") diff --git a/Examples/Physics_applications/laser_acceleration/CMakeLists.txt b/Examples/Physics_applications/laser_acceleration/CMakeLists.txt new file mode 100644 index 00000000000..46e97a53d54 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/CMakeLists.txt @@ -0,0 +1,134 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_laser_acceleration # name + 1 # dims + 2 # nprocs + inputs_test_1d_laser_acceleration # inputs + analysis_default_regression.py # analysis + diags/diag1000100 # output + OFF # dependency +) + +add_warpx_test( + test_1d_laser_acceleration_fluid_boosted # name + 1 # dims + 2 # nprocs + inputs_test_1d_laser_acceleration_fluid_boosted # inputs + analysis_1d_fluid_boosted.py # analysis + diags/diag1000001 # output + OFF # dependency +) +label_warpx_test(test_1d_laser_acceleration_fluid_boosted slow) + +add_warpx_test( + test_1d_laser_acceleration_picmi # name + 1 # dims + 2 # nprocs + inputs_test_1d_laser_acceleration_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000100 # output + OFF # dependency +) + +add_warpx_test( + test_2d_laser_acceleration_boosted # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_acceleration_boosted # inputs + analysis_default_regression.py # analysis + diags/diag1000002 # output + OFF # dependency +) + +add_warpx_test( + test_2d_laser_acceleration_mr # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_acceleration_mr # inputs + analysis_default_regression.py # analysis + diags/diag1000200 # output + OFF # dependency +) + +add_warpx_test( + test_2d_laser_acceleration_mr_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_acceleration_mr_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000200 # output + OFF # dependency +) + +add_warpx_test( + test_2d_refined_injection # name + 2 # dims + 2 # nprocs + inputs_test_2d_refined_injection # inputs + analysis_refined_injection.py # analysis + diags/diag1000200 # output + OFF # dependency +) + +add_warpx_test( + test_3d_laser_acceleration # name + 3 # dims + 2 # nprocs + inputs_test_3d_laser_acceleration # inputs + analysis_default_openpmd_regression.py # analysis + diags/diag1/ # output + OFF # dependency +) + +add_warpx_test( + test_3d_laser_acceleration_picmi # name + 3 # dims + 2 # nprocs + inputs_test_3d_laser_acceleration_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000100 # output + OFF # dependency +) + +add_warpx_test( + test_3d_laser_acceleration_single_precision_comms # name + 3 # dims + 2 # nprocs + inputs_test_3d_laser_acceleration_single_precision_comms # inputs + analysis_default_openpmd_regression.py # analysis + diags/diag1/ # output + OFF # dependency +) + +add_warpx_test( + test_rz_laser_acceleration # name + RZ # dims + 2 # nprocs + inputs_test_rz_laser_acceleration # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +add_warpx_test( + test_rz_laser_acceleration_opmd # name + RZ # dims + 2 # nprocs + inputs_test_rz_laser_acceleration_opmd # inputs + analysis_openpmd_rz.py # analysis + diags/diag1/ # output + OFF # dependency +) + +add_warpx_test( + test_rz_laser_acceleration_picmi # name + RZ # dims + 2 # nprocs + inputs_test_rz_laser_acceleration_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) +label_warpx_test(test_rz_laser_acceleration_picmi slow) diff --git a/Examples/Physics_applications/laser_acceleration/PICMI_inputs_1d.py b/Examples/Physics_applications/laser_acceleration/PICMI_inputs_1d.py deleted file mode 100755 index d8bdddfaca6..00000000000 --- a/Examples/Physics_applications/laser_acceleration/PICMI_inputs_1d.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -# Physical constants -c = picmi.constants.c -q_e = picmi.constants.q_e - -# Number of time steps -max_steps = 100 - -# Number of cells -nz = 256 - -# Physical domain -zmin = -56e-06 -zmax = 12e-06 - -# Domain decomposition -max_grid_size = 64 -blocking_factor = 32 - -# Create grid -grid = picmi.Cartesian1DGrid( - number_of_cells = [nz], - lower_bound = [zmin], - upper_bound = [zmax], - lower_boundary_conditions = ['dirichlet'], - upper_boundary_conditions = ['dirichlet'], - lower_boundary_conditions_particles = ['absorbing'], - upper_boundary_conditions_particles = ['absorbing'], - moving_window_velocity = [c], - warpx_max_grid_size = max_grid_size, - warpx_blocking_factor = blocking_factor) - -# Particles: plasma electrons -plasma_density = 2e23 -plasma_xmin = None -plasma_ymin = None -plasma_zmin = 10e-06 -plasma_xmax = None -plasma_ymax = None -plasma_zmax = None -uniform_distribution = picmi.UniformDistribution( - density = plasma_density, - lower_bound = [plasma_xmin, plasma_ymin, plasma_zmin], - upper_bound = [plasma_xmax, plasma_ymax, plasma_zmax], - fill_in = True) -electrons = picmi.Species( - particle_type = 'electron', - name = 'electrons', - initial_distribution = uniform_distribution) - -# Laser -e_max = 16e12 -position_z = 9e-06 -profile_t_peak = 30.e-15 -profile_focal_distance = 100e-06 -laser = picmi.GaussianLaser( - wavelength = 0.8e-06, - waist = 5e-06, - duration = 15e-15, - focal_position = [0, 0, profile_focal_distance + position_z], - centroid_position = [0, 0, position_z - c*profile_t_peak], - propagation_direction = [0, 0, 1], - polarization_direction = [0, 1, 0], - E0 = e_max, - fill_in = False) -laser_antenna = picmi.LaserAntenna( - position = [0., 0., position_z], - normal_vector = [0, 0, 1]) - -# Electromagnetic solver -solver = picmi.ElectromagneticSolver( - grid = grid, - method = 'Yee', - cfl = 0.9, - divE_cleaning = 0) - -# Diagnostics -diag_field_list = ['B', 'E', 'J', 'rho'] -particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 100, - write_dir = '.', - warpx_file_prefix = 'Python_LaserAcceleration_1d_plt') -field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 100, - data_list = diag_field_list, - write_dir = '.', - warpx_file_prefix = 'Python_LaserAcceleration_1d_plt') - -# Set up simulation -sim = picmi.Simulation( - solver = solver, - max_steps = max_steps, - verbose = 1, - particle_shape = 'cubic', - warpx_use_filter = 1, - warpx_serialize_initial_conditions = 1, - warpx_do_dynamic_scheduling = 0) - -# Add plasma electrons -sim.add_species( - electrons, - layout = picmi.GriddedLayout(grid = grid, n_macroparticle_per_cell = [10])) - -# Add laser -sim.add_laser( - laser, - injection_method = laser_antenna) - -# Add diagnostics -sim.add_diagnostic(particle_diag) -sim.add_diagnostic(field_diag) - -# Write input file that can be used to run with the compiled version -sim.write_input_file(file_name = 'inputs_1d_picmi') - -# Initialize inputs and WarpX instance -sim.initialize_inputs() -sim.initialize_warpx() - -# Advance simulation until last time step -sim.step(max_steps) diff --git a/Examples/Physics_applications/laser_acceleration/PICMI_inputs_2d.py b/Examples/Physics_applications/laser_acceleration/PICMI_inputs_2d.py deleted file mode 100755 index b50e16bfc0a..00000000000 --- a/Examples/Physics_applications/laser_acceleration/PICMI_inputs_2d.py +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -# Physical constants -c = picmi.constants.c -q_e = picmi.constants.q_e - -# Number of time steps -max_steps = 200 - -# Number of cells -nx = 64 -nz = 512 - -# Physical domain -xmin = -30e-06 -xmax = 30e-06 -zmin = -56e-06 -zmax = 12e-06 -xmin_refined = -5e-06 -xmax_refined = 5e-06 -zmin_refined = -35e-06 -zmax_refined = -25e-06 - -# Domain decomposition -max_grid_size = 64 -blocking_factor = 32 - -# Create grid -grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, nz], - lower_bound = [xmin, zmin], - upper_bound = [xmax, zmax], - lower_boundary_conditions = ['open', 'open'], - upper_boundary_conditions = ['open', 'open'], - lower_boundary_conditions_particles = ['absorbing', 'absorbing'], - upper_boundary_conditions_particles = ['absorbing', 'absorbing'], - moving_window_velocity = [0., c], - warpx_max_grid_size = max_grid_size, - warpx_blocking_factor = blocking_factor, - refined_regions = [[1, [xmin_refined, zmin_refined], [xmax_refined, zmax_refined]]]) - -# Particles: plasma electrons -plasma_density = 2e23 -plasma_xmin = -20e-06 -plasma_ymin = None -plasma_zmin = 10e-06 -plasma_xmax = 20e-06 -plasma_ymax = None -plasma_zmax = None -uniform_distribution = picmi.UniformDistribution( - density = plasma_density, - lower_bound = [plasma_xmin, plasma_ymin, plasma_zmin], - upper_bound = [plasma_xmax, plasma_ymax, plasma_zmax], - fill_in = True) -electrons = picmi.Species( - particle_type = 'electron', - name = 'electrons', - initial_distribution = uniform_distribution) - -# Particles: beam electrons -q_tot = 1e-12 -x_m = 0. -y_m = 0. -z_m = -28e-06 -x_rms = 0.5e-06 -y_rms = 0.5e-06 -z_rms = 0.5e-06 -ux_m = 0. -uy_m = 0. -uz_m = 500. -ux_th = 2. -uy_th = 2. -uz_th = 50. -gaussian_bunch_distribution = picmi.GaussianBunchDistribution( - n_physical_particles = q_tot / q_e, - rms_bunch_size = [x_rms, y_rms, z_rms], - rms_velocity = [c*ux_th, c*uy_th, c*uz_th], - centroid_position = [x_m, y_m, z_m], - centroid_velocity = [c*ux_m, c*uy_m, c*uz_m]) -beam = picmi.Species( - particle_type = 'electron', - name = 'beam', - initial_distribution = gaussian_bunch_distribution) - -# Laser -e_max = 16e12 -position_z = 9e-06 -profile_t_peak = 30.e-15 -profile_focal_distance = 100e-06 -laser = picmi.GaussianLaser( - wavelength = 0.8e-06, - waist = 5e-06, - duration = 15e-15, - focal_position = [0, 0, profile_focal_distance + position_z], - centroid_position = [0, 0, position_z - c*profile_t_peak], - propagation_direction = [0, 0, 1], - polarization_direction = [0, 1, 0], - E0 = e_max, - fill_in = False) -laser_antenna = picmi.LaserAntenna( - position = [0., 0., position_z], - normal_vector = [0, 0, 1]) - -# Electromagnetic solver -solver = picmi.ElectromagneticSolver( - grid = grid, - method = 'Yee', - cfl = 1., - divE_cleaning = 0) - -# Diagnostics -diag_field_list = ['B', 'E', 'J', 'rho'] -particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 200, - write_dir = '.', - warpx_file_prefix = 'Python_LaserAccelerationMR_plt') -field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 200, - data_list = diag_field_list, - write_dir = '.', - warpx_file_prefix = 'Python_LaserAccelerationMR_plt') - -# Set up simulation -sim = picmi.Simulation( - solver = solver, - max_steps = max_steps, - verbose = 1, - particle_shape = 'cubic', - warpx_use_filter = 1, - warpx_serialize_initial_conditions = 1) - -# Add plasma electrons -sim.add_species( - electrons, - layout = picmi.GriddedLayout(grid = grid, n_macroparticle_per_cell = [1, 1, 1])) - -# Add beam electrons -sim.add_species( - beam, - layout = picmi.PseudoRandomLayout(grid = grid, n_macroparticles = 100)) - -# Add laser -sim.add_laser( - laser, - injection_method = laser_antenna) - -# Add diagnostics -sim.add_diagnostic(particle_diag) -sim.add_diagnostic(field_diag) - -# Write input file that can be used to run with the compiled version -sim.write_input_file(file_name = 'inputs_2d_picmi') - -# Initialize inputs and WarpX instance -sim.initialize_inputs() -sim.initialize_warpx() - -# Advance simulation until last time step -sim.step(max_steps) diff --git a/Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py b/Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py deleted file mode 100755 index 13bf492e203..00000000000 --- a/Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -# Physical constants -c = picmi.constants.c -q_e = picmi.constants.q_e - -# Number of time steps -max_steps = 100 - -# Number of cells -nx = 32 -ny = 32 -nz = 256 - -# Physical domain -xmin = -30e-06 -xmax = 30e-06 -ymin = -30e-06 -ymax = 30e-06 -zmin = -56e-06 -zmax = 12e-06 - -# Domain decomposition -max_grid_size = 64 -blocking_factor = 32 - -# Create grid -grid = picmi.Cartesian3DGrid( - number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = ['periodic', 'periodic', 'dirichlet'], - upper_boundary_conditions = ['periodic', 'periodic', 'dirichlet'], - lower_boundary_conditions_particles = ['periodic', 'periodic', 'absorbing'], - upper_boundary_conditions_particles = ['periodic', 'periodic', 'absorbing'], - moving_window_velocity = [0., 0., c], - warpx_max_grid_size = max_grid_size, - warpx_blocking_factor = blocking_factor) - -# Particles: plasma electrons -plasma_density = 2e23 -plasma_xmin = -20e-06 -plasma_ymin = -20e-06 -plasma_zmin = 0 -plasma_xmax = 20e-06 -plasma_ymax = 20e-06 -plasma_zmax = None -uniform_distribution = picmi.UniformDistribution( - density = plasma_density, - lower_bound = [plasma_xmin, plasma_ymin, plasma_zmin], - upper_bound = [plasma_xmax, plasma_ymax, plasma_zmax], - fill_in = True) -electrons = picmi.Species( - particle_type = 'electron', - name = 'electrons', - initial_distribution = uniform_distribution, - warpx_add_int_attributes = {'regionofinterest': "(z>12.0e-6) * (z<13.0e-6)"}, - warpx_add_real_attributes = {'initialenergy': "ux*ux + uy*uy + uz*uz"}) - -# Particles: beam electrons -q_tot = 1e-12 -x_m = 0. -y_m = 0. -z_m = -28e-06 -x_rms = 0.5e-06 -y_rms = 0.5e-06 -z_rms = 0.5e-06 -ux_m = 0. -uy_m = 0. -uz_m = 500. -ux_th = 2. -uy_th = 2. -uz_th = 50. -gaussian_bunch_distribution = picmi.GaussianBunchDistribution( - n_physical_particles = q_tot / q_e, - rms_bunch_size = [x_rms, y_rms, z_rms], - rms_velocity = [c*ux_th, c*uy_th, c*uz_th], - centroid_position = [x_m, y_m, z_m], - centroid_velocity = [c*ux_m, c*uy_m, c*uz_m]) -beam = picmi.Species( - particle_type = 'electron', - name = 'beam', - initial_distribution = gaussian_bunch_distribution) - -# Laser -e_max = 16e12 -position_z = 9e-06 -profile_t_peak = 30.e-15 -profile_focal_distance = 100e-06 -laser = picmi.GaussianLaser( - wavelength = 0.8e-06, - waist = 5e-06, - duration = 15e-15, - focal_position = [0, 0, profile_focal_distance + position_z], - centroid_position = [0, 0, position_z - c*profile_t_peak], - propagation_direction = [0, 0, 1], - polarization_direction = [0, 1, 0], - E0 = e_max, - fill_in = False) -laser_antenna = picmi.LaserAntenna( - position = [0., 0., position_z], - normal_vector = [0, 0, 1]) - -# Electromagnetic solver -solver = picmi.ElectromagneticSolver( - grid = grid, - method = 'Yee', - cfl = 1., - divE_cleaning = 0) - -# Diagnostics -diag_field_list = ['B', 'E', 'J', 'rho'] -particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 100, - write_dir = '.', - warpx_file_prefix = 'Python_LaserAcceleration_plt') -field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 100, - data_list = diag_field_list, - write_dir = '.', - warpx_file_prefix = 'Python_LaserAcceleration_plt') - -# Set up simulation -sim = picmi.Simulation( - solver = solver, - max_steps = max_steps, - verbose = 1, - particle_shape = 'cubic', - warpx_use_filter = 1, - warpx_serialize_initial_conditions = 1, - warpx_do_dynamic_scheduling = 0) - -# Add plasma electrons -sim.add_species( - electrons, - layout = picmi.GriddedLayout(grid = grid, n_macroparticle_per_cell = [1, 1, 1])) - -# Add beam electrons -sim.add_species( - beam, - layout = picmi.PseudoRandomLayout(grid = grid, n_macroparticles = 100)) - -# Add laser -sim.add_laser( - laser, - injection_method = laser_antenna) - -# Add diagnostics -sim.add_diagnostic(particle_diag) -sim.add_diagnostic(field_diag) - -# Write input file that can be used to run with the compiled version -sim.write_input_file(file_name = 'inputs_3d_picmi') - -# Initialize inputs and WarpX instance -sim.initialize_inputs() -sim.initialize_warpx() - -# Advance simulation until last time step -sim.step(max_steps) diff --git a/Examples/Physics_applications/laser_acceleration/PICMI_inputs_rz.py b/Examples/Physics_applications/laser_acceleration/PICMI_inputs_rz.py deleted file mode 100755 index 7f09db8d6b3..00000000000 --- a/Examples/Physics_applications/laser_acceleration/PICMI_inputs_rz.py +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -# Physical constants -c = picmi.constants.c -q_e = picmi.constants.q_e - -# Number of time steps -max_steps = 10 - -# Number of cells -nr = 64 -nz = 512 - -# Physical domain -rmin = 0 -rmax = 30e-06 -zmin = -56e-06 -zmax = 12e-06 - -# Domain decomposition -max_grid_size = 64 -blocking_factor = 32 - -# Create grid -grid = picmi.CylindricalGrid( - number_of_cells = [nr, nz], - n_azimuthal_modes = 2, - lower_bound = [rmin, zmin], - upper_bound = [rmax, zmax], - lower_boundary_conditions = ['none', 'dirichlet'], - upper_boundary_conditions = ['dirichlet', 'dirichlet'], - lower_boundary_conditions_particles = ['none', 'absorbing'], - upper_boundary_conditions_particles = ['absorbing', 'absorbing'], - moving_window_velocity = [0., c], - warpx_max_grid_size = max_grid_size, - warpx_blocking_factor = blocking_factor) - -# Particles: plasma electrons -plasma_density = 2e23 -plasma_xmin = -20e-06 -plasma_ymin = None -plasma_zmin = 10e-06 -plasma_xmax = 20e-06 -plasma_ymax = None -plasma_zmax = None -uniform_distribution = picmi.UniformDistribution( - density = plasma_density, - lower_bound = [plasma_xmin, plasma_ymin, plasma_zmin], - upper_bound = [plasma_xmax, plasma_ymax, plasma_zmax], - fill_in = True) -electrons = picmi.Species( - particle_type = 'electron', - name = 'electrons', - initial_distribution = uniform_distribution) - -# Particles: beam electrons -q_tot = 1e-12 -x_m = 0. -y_m = 0. -z_m = -28e-06 -x_rms = 0.5e-06 -y_rms = 0.5e-06 -z_rms = 0.5e-06 -ux_m = 0. -uy_m = 0. -uz_m = 500. -ux_th = 2. -uy_th = 2. -uz_th = 50. -gaussian_bunch_distribution = picmi.GaussianBunchDistribution( - n_physical_particles = q_tot / q_e, - rms_bunch_size = [x_rms, y_rms, z_rms], - rms_velocity = [c*ux_th, c*uy_th, c*uz_th], - centroid_position = [x_m, y_m, z_m], - centroid_velocity = [c*ux_m, c*uy_m, c*uz_m]) -beam = picmi.Species( - particle_type = 'electron', - name = 'beam', - initial_distribution = gaussian_bunch_distribution) - -# Laser -e_max = 16e12 -position_z = 9e-06 -profile_t_peak = 30.e-15 -profile_focal_distance = 100e-06 -laser = picmi.GaussianLaser( - wavelength = 0.8e-06, - waist = 5e-06, - duration = 15e-15, - focal_position = [0, 0, profile_focal_distance + position_z], - centroid_position = [0, 0, position_z - c*profile_t_peak], - propagation_direction = [0, 0, 1], - polarization_direction = [0, 1, 0], - E0 = e_max, - fill_in = False) -laser_antenna = picmi.LaserAntenna( - position = [0., 0., position_z], - normal_vector = [0, 0, 1]) - -# Electromagnetic solver -solver = picmi.ElectromagneticSolver( - grid = grid, - method = 'Yee', - cfl = 1., - divE_cleaning = 0) - -# Diagnostics -diag_field_list = ['B', 'E', 'J', 'rho'] -field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 10, - data_list = diag_field_list, - warpx_dump_rz_modes = 1, - write_dir = '.', - warpx_file_prefix = 'Python_LaserAccelerationRZ_plt') -diag_particle_list = ['weighting', 'momentum'] -particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 10, - species = [electrons, beam], - data_list = diag_particle_list, - write_dir = '.', - warpx_file_prefix = 'Python_LaserAccelerationRZ_plt') - -# Set up simulation -sim = picmi.Simulation( - solver = solver, - max_steps = max_steps, - verbose = 1, - particle_shape = 'cubic', - warpx_use_filter = 0) - -# Add plasma electrons -sim.add_species( - electrons, - layout = picmi.GriddedLayout(grid = grid, n_macroparticle_per_cell = [1, 4, 1])) - -# Add beam electrons -sim.add_species( - beam, - layout = picmi.PseudoRandomLayout(grid = grid, n_macroparticles = 100)) - -# Add laser -sim.add_laser( - laser, - injection_method = laser_antenna) - -# Add diagnostics -sim.add_diagnostic(field_diag) -sim.add_diagnostic(particle_diag) - -# Write input file that can be used to run with the compiled version -sim.write_input_file(file_name = 'inputs_rz_picmi') - -# Initialize inputs and WarpX instance -sim.initialize_inputs() -sim.initialize_warpx() - -# Advance simulation until last time step -sim.step(max_steps) diff --git a/Examples/Physics_applications/laser_acceleration/README.rst b/Examples/Physics_applications/laser_acceleration/README.rst index 0ba3b5382f2..66de28de7a7 100644 --- a/Examples/Physics_applications/laser_acceleration/README.rst +++ b/Examples/Physics_applications/laser_acceleration/README.rst @@ -24,43 +24,43 @@ For `MPI-parallel `__ runs, prefix these lines with ` This example can be run **either** as: - * **Python** script: ``python3 PICMI_inputs_3d.py`` or - * WarpX **executable** using an input file: ``warpx.3d inputs_3d max_step=400`` + * **Python** script: ``python3 inputs_test_3d_laser_acceleration_picmi.py`` or + * WarpX **executable** using an input file: ``warpx.3d inputs_test_3d_laser_acceleration max_step=400`` .. tab-set:: .. tab-item:: Python: Script - .. literalinclude:: PICMI_inputs_3d.py + .. literalinclude:: inputs_test_3d_laser_acceleration_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py``. + :caption: You can copy this file from ``Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_picmi.py``. .. tab-item:: Executable: Input File - .. literalinclude:: inputs_3d + .. literalinclude:: inputs_test_3d_laser_acceleration :language: ini - :caption: You can copy this file from ``Examples/Physics_applications/laser_acceleration/inputs_3d``. + :caption: You can copy this file from ``Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration``. .. tab-item:: RZ This example can be run **either** as: - * **Python** script: ``python3 PICMI_inputs_rz.py`` or - * WarpX **executable** using an input file: ``warpx.rz inputs_3d max_step=400`` + * **Python** script: ``python3 inputs_test_rz_laser_acceleration_picmi.py`` or + * WarpX **executable** using an input file: ``warpx.rz inputs_test_rz_laser_acceleration max_step=400`` .. tab-set:: .. tab-item:: Python: Script - .. literalinclude:: PICMI_inputs_rz.py + .. literalinclude:: inputs_test_rz_laser_acceleration_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Physics_applications/laser_acceleration/PICMI_inputs_rz.py``. + :caption: You can copy this file from ``Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration_picmi.py``. .. tab-item:: Executable: Input File - .. literalinclude:: inputs_rz + .. literalinclude:: inputs_test_rz_laser_acceleration :language: ini - :caption: You can copy this file from ``Examples/Physics_applications/laser_acceleration/inputs_rz``. + :caption: You can copy this file from ``Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration``. Analyze ------- diff --git a/Examples/Physics_applications/laser_acceleration/analysis_1d_fluid_boosted.py b/Examples/Physics_applications/laser_acceleration/analysis_1d_fluid_boosted.py new file mode 100755 index 00000000000..934d298c6b7 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/analysis_1d_fluid_boosted.py @@ -0,0 +1,192 @@ +#!/usr/bin/env python3 + +# Copyright 2019-2023 Grant Johnson, Remi Lehe +# +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL +# +# This is a script that analyses the simulation results from +# the script `inputs_1d`. This simulates a 1D WFA with Pondermotive Envelope: +# REF: (Equations 20-23) https://journals.aps.org/rmp/pdf/10.1103/RevModPhys.81.1229 +import os +import sys + +import matplotlib + +matplotlib.use("Agg") +import matplotlib.pyplot as plt +import yt + +yt.funcs.mylog.setLevel(50) + +import numpy as np +from scipy.constants import c, e, epsilon_0, m_e + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# this will be the name of the plot file +fn = sys.argv[1] + +# Parameters (these parameters must match the parameters in `inputs.multi.rt`) +n0 = 20.0e23 +# Plasma frequency +wp = np.sqrt((n0 * e**2) / (m_e * epsilon_0)) +kp = wp / c +tau = 15.0e-15 +a0 = 2.491668 +e = -e # Electrons +lambda_laser = 0.8e-6 + +zmin = -20e-6 +zmax = 100.0e-6 +Nz = 4864 + +# Compute the theory + +# Call the ode solver +from scipy.integrate import odeint + + +# ODE Function +def odefcn(phi, xi, kp, a0, c, tau, xi_0, lambda_laser): + phi1, phi2 = phi + a_sq = ( + a0**2 + * np.exp(-2 * (xi - xi_0) ** 2 / (c**2 * tau**2)) + * np.sin(2 * np.pi * (xi - xi_0) / lambda_laser) ** 2 + ) + dphi1_dxi = phi2 + dphi2_dxi = kp**2 * ((1 + a_sq) / (2 * (1 + phi1) ** 2) - 0.5) + return [dphi1_dxi, dphi2_dxi] + + +# Call odeint to solve the ODE +xi_span = [-20e-6, 100e-6] +xi_0 = 0e-6 +phi0 = [0.0, 0.0] +dxi = (zmax - zmin) / Nz +xi = zmin + dxi * (0.5 + np.arange(Nz)) +phi = odeint(odefcn, phi0, xi, args=(kp, a0, c, tau, xi_0, lambda_laser)) + +# Change array direction to match the simulations +xi = -xi[::-1] +phi = phi[::-1] +xi_0 = -0e-6 +phi2 = phi[:, 0] +Ez = -phi[:, 1] + +# Compute the derived quantities +a_sq = ( + a0**2 + * np.exp(-2 * (xi - xi_0) ** 2 / (c**2 * tau**2)) + * np.sin(2 * np.pi * (xi - xi_0) / lambda_laser) ** 2 +) +gamma_perp_sq = 1 + a_sq +n = n0 * (gamma_perp_sq + (1 + phi2) ** 2) / (2 * (1 + phi2) ** 2) +uz = (gamma_perp_sq - (1 + phi2) ** 2) / (2 * (1 + phi2)) +gamma = (gamma_perp_sq + (1 + phi2) ** 2) / (2 * (1 + phi2)) + +# Theory Components [convert to si] +uz *= c +J_th = np.multiply(np.divide(uz, gamma), n) +J_th *= e +rho_th = e * n +E_th = Ez +E_th *= (m_e * c * c) / e +V_th = np.divide(uz, gamma) +V_th /= c +# Remove the ions +rho_th = rho_th - e * n0 + +# Dictate which region to compare solutions over (cuttoff 0's from BTD extra) +min_i = 200 +max_i = 4864 + +# Read the file +ds = yt.load(fn) +t0 = ds.current_time.to_value() +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +# Check the validity of the fields +error_rel = 0 +for field in ["Ez"]: + E_sim = data[("mesh", field)].to_ndarray()[:, 0, 0] + # E_th = get_theoretical_field(field, t0) + max_error = ( + abs(E_sim[min_i:max_i] - E_th[min_i:max_i]).max() / abs(E_th[min_i:max_i]).max() + ) + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) + +# Check the validity of the currents +for field in ["Jz"]: + J_sim = data[("mesh", field)].to_ndarray()[:, 0, 0] + # J_th = get_theoretical_J_field(field, t0) + max_error = ( + abs(J_sim[min_i:max_i] - J_th[min_i:max_i]).max() / abs(J_th[min_i:max_i]).max() + ) + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) + +# Check the validity of the charge +for field in ["rho"]: + rho_sim = data[("boxlib", field)].to_ndarray()[:, 0, 0] + # rho_th = get_theoretical_rho_field(field, t0) + max_error = ( + abs(rho_sim[min_i:max_i] - rho_th[min_i:max_i]).max() + / abs(rho_th[min_i:max_i]).max() + ) + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) + +V_sim = np.divide(J_sim, rho_sim) +V_sim /= c + +# Create a figure with 2 rows and 2 columns +fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12, 8)) + +# Titles and labels +titles = ["Ez", "rho", "Jz", "Vz/c"] +xlabel = r"Xi" +ylabel = ["Ez", "rho", "Jz", "Vz/c"] + +# Plotting loop +for i in range(3): + ax = axes[i // 2, i % 2] # Get the current subplot + + # Plot theoretical data + ax.plot(xi, [E_th, rho_th, J_th, V_th][i], label="Theoretical") + + # Plot simulated data + ax.plot(xi, [E_sim, rho_sim, J_sim, V_sim][i], label="Simulated") + + # Set titles and labels + ax.set_title(f"{titles[i]} vs Xi") + ax.set_xlabel(xlabel) + ax.set_ylabel(ylabel[i]) + + # Add legend + ax.legend() + +# Adjust subplot layout +plt.tight_layout() + +# Save the figure +plt.savefig("wfa_fluid_nonlinear_1d_analysis.png") + +plt.show() + + +tolerance_rel = 0.30 + +print("error_rel : " + str(error_rel)) +print("tolerance_rel: " + str(tolerance_rel)) + +assert error_rel < tolerance_rel + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Physics_applications/laser_acceleration/analysis_1d_fluids.py b/Examples/Physics_applications/laser_acceleration/analysis_1d_fluids.py deleted file mode 100755 index a33b82ebc02..00000000000 --- a/Examples/Physics_applications/laser_acceleration/analysis_1d_fluids.py +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2019-2023 Grant Johnson, Remi Lehe -# -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL -# -# This is a script that analyses the simulation results from -# the script `inputs_1d`. This simulates a 1D WFA with Pondermotive Envelope: -# REF: (Equations 20-23) https://journals.aps.org/rmp/pdf/10.1103/RevModPhys.81.1229 -import os -import sys - -import matplotlib - -matplotlib.use('Agg') -import matplotlib.pyplot as plt -import yt - -yt.funcs.mylog.setLevel(50) - -import numpy as np -from scipy.constants import c, e, epsilon_0, m_e - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -# this will be the name of the plot file -fn = sys.argv[1] - -# Parameters (these parameters must match the parameters in `inputs.multi.rt`) -n0 = 20.e23 -# Plasma frequency -wp = np.sqrt((n0*e**2)/(m_e*epsilon_0)) -kp = wp/c -tau = 15.e-15 -a0 = 2.491668 -e = -e #Electrons -lambda_laser = 0.8e-6 - -zmin = -20e-6; zmax = 100.e-6; Nz = 10240 - -# Compute the theory - -# Call the ode solver -from scipy.integrate import odeint - - -# ODE Function -def odefcn(phi, xi, kp, a0, c, tau, xi_0, lambda_laser): - phi1, phi2 = phi - a_sq = a0**2 * np.exp(-2 * (xi - xi_0)**2 / (c**2 * tau**2))*np.sin(2*np.pi*(xi - xi_0)/lambda_laser)**2 - dphi1_dxi = phi2 - dphi2_dxi = kp**2 * ((1 + a_sq) / (2 * (1 + phi1)**2) - 0.5) - return [dphi1_dxi, dphi2_dxi] - -# Call odeint to solve the ODE -xi_span = [-20e-6, 100e-6] -xi_0 = 0e-6 -phi0 = [0.0, 0.0] -dxi = (zmax-zmin)/Nz -xi = zmin + dxi*( 0.5 + np.arange(Nz) ) -phi = odeint(odefcn, phi0, xi, args=(kp, a0, c, tau, xi_0, lambda_laser)) - -# Change array direction to match the simulations -xi = -xi[::-1] -phi = phi[::-1] -xi_0 = -0e-6 -phi2 = phi[:, 0] -Ez = -phi[:, 1] - -# Compute the derived quantities -a_sq = a0**2 * np.exp(-2 * (xi - xi_0)**2 / (c**2 * tau**2)) *np.sin(2*np.pi*(xi - xi_0)/lambda_laser)**2 -gamma_perp_sq = 1 + a_sq -n = n0 * (gamma_perp_sq + (1 + phi2)**2) / (2 * (1 + phi2)**2) -uz = (gamma_perp_sq - (1 + phi2)**2) / (2 * (1 + phi2)) -gamma = (gamma_perp_sq + (1 + phi2)**2) / (2 * (1 + phi2)) - -# Theory Components [convert to si] -uz *= c -J_th = np.multiply( np.divide(uz,gamma), n ) -J_th *= e -rho_th = e*n -E_th = Ez -E_th *= ((m_e*c*c)/e) -V_th = np.divide(uz,gamma) -V_th /= c -# Remove the ions -rho_th = rho_th - e*n0 - -# Dictate which region to compare solutions over -# (Currently this is the full domain) -min_i = 0 -max_i = 10240 - -# Read the file -ds = yt.load(fn) -t0 = ds.current_time.to_value() -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) -# Check the validity of the fields -error_rel = 0 -for field in ['Ez']: - E_sim = data[('mesh',field)].to_ndarray()[:,0,0] - #E_th = get_theoretical_field(field, t0) - max_error = abs(E_sim[min_i:max_i]-E_th[min_i:max_i]).max()/abs(E_th[min_i:max_i]).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) - -# Check the validity of the currents -for field in ['Jz']: - J_sim = data[('mesh',field)].to_ndarray()[:,0,0] - #J_th = get_theoretical_J_field(field, t0) - max_error = abs(J_sim[min_i:max_i]-J_th[min_i:max_i]).max()/abs(J_th[min_i:max_i]).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) - -# Check the validity of the charge -for field in ['rho']: - rho_sim = data[('boxlib',field)].to_ndarray()[:,0,0] - #rho_th = get_theoretical_rho_field(field, t0) - max_error = abs(rho_sim[min_i:max_i]-rho_th[min_i:max_i]).max()/abs(rho_th[min_i:max_i]).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) - -V_sim = np.divide(J_sim,rho_sim) -V_sim /= c - -# Create a figure with 2 rows and 2 columns -fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12, 8)) - -# Titles and labels -titles = ['Ez', 'rho', 'Jz', 'Vz/c'] -xlabel = r'Xi' -ylabel = ['Ez', 'rho', 'Jz', 'Vz/c'] - -# Plotting loop -for i in range(3): - ax = axes[i // 2, i % 2] # Get the current subplot - - # Plot theoretical data - ax.plot(xi, [E_th, rho_th, J_th, V_th][i], label='Theoretical') - - # Plot simulated data - ax.plot(xi, [E_sim, rho_sim, J_sim, V_sim][i], label='Simulated') - - # Set titles and labels - ax.set_title(f'{titles[i]} vs Xi') - ax.set_xlabel(xlabel) - ax.set_ylabel(ylabel[i]) - - # Add legend - ax.legend() - -# Adjust subplot layout -plt.tight_layout() - -# Save the figure -plt.savefig('wfa_fluid_nonlinear_1d_analysis.png') - -plt.show() - - -tolerance_rel = 0.20 - -print("error_rel : " + str(error_rel)) -print("tolerance_rel: " + str(tolerance_rel)) - -assert( error_rel < tolerance_rel ) - -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Physics_applications/laser_acceleration/analysis_1d_fluids_boosted.py b/Examples/Physics_applications/laser_acceleration/analysis_1d_fluids_boosted.py deleted file mode 100755 index 30301996921..00000000000 --- a/Examples/Physics_applications/laser_acceleration/analysis_1d_fluids_boosted.py +++ /dev/null @@ -1,173 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2019-2023 Grant Johnson, Remi Lehe -# -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL -# -# This is a script that analyses the simulation results from -# the script `inputs_1d`. This simulates a 1D WFA with Pondermotive Envelope: -# REF: (Equations 20-23) https://journals.aps.org/rmp/pdf/10.1103/RevModPhys.81.1229 -import os -import sys - -import matplotlib - -matplotlib.use('Agg') -import matplotlib.pyplot as plt -import yt - -yt.funcs.mylog.setLevel(50) - -import numpy as np -from scipy.constants import c, e, epsilon_0, m_e - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -# this will be the name of the plot file -fn = sys.argv[1] - -# Parameters (these parameters must match the parameters in `inputs.multi.rt`) -n0 = 20.e23 -# Plasma frequency -wp = np.sqrt((n0*e**2)/(m_e*epsilon_0)) -kp = wp/c -tau = 15.e-15 -a0 = 2.491668 -e = -e #Electrons -lambda_laser = 0.8e-6 - -zmin = -20e-6; zmax = 100.e-6; Nz = 4864 - -# Compute the theory - -# Call the ode solver -from scipy.integrate import odeint - - -# ODE Function -def odefcn(phi, xi, kp, a0, c, tau, xi_0, lambda_laser): - phi1, phi2 = phi - a_sq = a0**2 * np.exp(-2 * (xi - xi_0)**2 / (c**2 * tau**2))*np.sin(2*np.pi*(xi - xi_0)/lambda_laser)**2 - dphi1_dxi = phi2 - dphi2_dxi = kp**2 * ((1 + a_sq) / (2 * (1 + phi1)**2) - 0.5) - return [dphi1_dxi, dphi2_dxi] - -# Call odeint to solve the ODE -xi_span = [-20e-6, 100e-6] -xi_0 = 0e-6 -phi0 = [0.0, 0.0] -dxi = (zmax-zmin)/Nz -xi = zmin + dxi*( 0.5 + np.arange(Nz) ) -phi = odeint(odefcn, phi0, xi, args=(kp, a0, c, tau, xi_0, lambda_laser)) - -# Change array direction to match the simulations -xi = -xi[::-1] -phi = phi[::-1] -xi_0 = -0e-6 -phi2 = phi[:, 0] -Ez = -phi[:, 1] - -# Compute the derived quantities -a_sq = a0**2 * np.exp(-2 * (xi - xi_0)**2 / (c**2 * tau**2)) *np.sin(2*np.pi*(xi - xi_0)/lambda_laser)**2 -gamma_perp_sq = 1 + a_sq -n = n0 * (gamma_perp_sq + (1 + phi2)**2) / (2 * (1 + phi2)**2) -uz = (gamma_perp_sq - (1 + phi2)**2) / (2 * (1 + phi2)) -gamma = (gamma_perp_sq + (1 + phi2)**2) / (2 * (1 + phi2)) - -# Theory Components [convert to si] -uz *= c -J_th = np.multiply( np.divide(uz,gamma), n ) -J_th *= e -rho_th = e*n -E_th = Ez -E_th *= ((m_e*c*c)/e) -V_th = np.divide(uz,gamma) -V_th /= c -# Remove the ions -rho_th = rho_th - e*n0 - -# Dictate which region to compare solutions over (cuttoff 0's from BTD extra) -min_i = 200 -max_i = 4864 - -# Read the file -ds = yt.load(fn) -t0 = ds.current_time.to_value() -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) -# Check the validity of the fields -error_rel = 0 -for field in ['Ez']: - E_sim = data[('mesh',field)].to_ndarray()[:,0,0] - #E_th = get_theoretical_field(field, t0) - max_error = abs(E_sim[min_i:max_i]-E_th[min_i:max_i]).max()/abs(E_th[min_i:max_i]).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) - -# Check the validity of the currents -for field in ['Jz']: - J_sim = data[('mesh',field)].to_ndarray()[:,0,0] - #J_th = get_theoretical_J_field(field, t0) - max_error = abs(J_sim[min_i:max_i]-J_th[min_i:max_i]).max()/abs(J_th[min_i:max_i]).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) - -# Check the validity of the charge -for field in ['rho']: - rho_sim = data[('boxlib',field)].to_ndarray()[:,0,0] - #rho_th = get_theoretical_rho_field(field, t0) - max_error = abs(rho_sim[min_i:max_i]-rho_th[min_i:max_i]).max()/abs(rho_th[min_i:max_i]).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) - -V_sim = np.divide(J_sim,rho_sim) -V_sim /= c - -# Create a figure with 2 rows and 2 columns -fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12, 8)) - -# Titles and labels -titles = ['Ez', 'rho', 'Jz', 'Vz/c'] -xlabel = r'Xi' -ylabel = ['Ez', 'rho', 'Jz', 'Vz/c'] - -# Plotting loop -for i in range(3): - ax = axes[i // 2, i % 2] # Get the current subplot - - # Plot theoretical data - ax.plot(xi, [E_th, rho_th, J_th, V_th][i], label='Theoretical') - - # Plot simulated data - ax.plot(xi, [E_sim, rho_sim, J_sim, V_sim][i], label='Simulated') - - # Set titles and labels - ax.set_title(f'{titles[i]} vs Xi') - ax.set_xlabel(xlabel) - ax.set_ylabel(ylabel[i]) - - # Add legend - ax.legend() - -# Adjust subplot layout -plt.tight_layout() - -# Save the figure -plt.savefig('wfa_fluid_nonlinear_1d_analysis.png') - -plt.show() - - -tolerance_rel = 0.30 - -print("error_rel : " + str(error_rel)) -print("tolerance_rel: " + str(tolerance_rel)) - -assert( error_rel < tolerance_rel ) - -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Physics_applications/laser_acceleration/analysis_default_openpmd_regression.py b/Examples/Physics_applications/laser_acceleration/analysis_default_openpmd_regression.py new file mode 120000 index 00000000000..73e5ec47001 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/analysis_default_openpmd_regression.py @@ -0,0 +1 @@ +../../analysis_default_openpmd_regression.py \ No newline at end of file diff --git a/Examples/Physics_applications/laser_acceleration/analysis_default_regression.py b/Examples/Physics_applications/laser_acceleration/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Physics_applications/laser_acceleration/analysis_openpmd_rz.py b/Examples/Physics_applications/laser_acceleration/analysis_openpmd_rz.py new file mode 100755 index 00000000000..f136ffeb1d4 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/analysis_openpmd_rz.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 + +import sys + +import numpy as np +import openpmd_api as io + +filename = sys.argv[1] +series = io.Series(f"{filename}/openpmd_%T.h5", io.Access.read_only) + +assert len(series.iterations) == 3, "improper number of iterations stored" + +ii = series.iterations[20] + +assert len(ii.meshes) == 8, "improper number of meshes" + +# select j_t +jt = ii.meshes["j"]["t"] + +# this is in C (Python) order; r is the fastest varying index +(Nm, Nz, Nr) = jt.shape + +assert ( + Nm == 3 +), "Wrong number of angular modes stored or possible incorrect ordering when flushed" +assert ( + Nr == 64 +), "Wrong number of radial points stored or possible incorrect ordering when flushed" +assert ( + Nz == 512 +), "Wrong number of z points stored or possible incorrect ordering when flushed" + +assert ii.meshes["part_per_grid"][io.Mesh_Record_Component.SCALAR].shape == [ + 512, + 64, +], "problem with part_per_grid" +assert ii.meshes["rho_electrons"][io.Mesh_Record_Component.SCALAR].shape == [ + 3, + 512, + 64, +], "problem with rho_electrons" + + +### test that openpmd+RZ +### 1. creates rho per species correctly +### 2. orders these appropriately +rhoe_mesh = ii.meshes["rho_electrons"] +rhob_mesh = ii.meshes["rho_beam"] +dz, dr = rhoe_mesh.grid_spacing +zmin, rmin = rhoe_mesh.grid_global_offset + +rhoe = rhoe_mesh[io.Mesh_Record_Component.SCALAR][:] +rhob = rhob_mesh[io.Mesh_Record_Component.SCALAR][:] +series.flush() +nm, nz, nr = rhoe.shape +zlist = zmin + dz * np.arange(nz) +rhoe0 = rhoe[0] # 0 mode +rhob0 = rhob[0] # 0 mode + +electron_meanz = np.sum(np.dot(zlist, rhoe0)) / np.sum(rhoe0) +beam_meanz = np.sum(np.dot(zlist, rhob0)) / np.sum(rhob0) + +assert ( + (electron_meanz > 0) and (beam_meanz < 0) +), "problem with openPMD+RZ. Maybe openPMD+RZ mixed up the order of rho_ diagnostics?" diff --git a/Examples/Physics_applications/laser_acceleration/analysis_refined_injection.py b/Examples/Physics_applications/laser_acceleration/analysis_refined_injection.py index a66c838fe9d..bc7fac15247 100755 --- a/Examples/Physics_applications/laser_acceleration/analysis_refined_injection.py +++ b/Examples/Physics_applications/laser_acceleration/analysis_refined_injection.py @@ -15,9 +15,8 @@ import yt yt.funcs.mylog.setLevel(50) -import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -28,7 +27,7 @@ # count the number of particles ad = ds.all_data() -np = ad['electrons', 'particle_id'].size +ps = ad["electrons", "particle_id"].size # the number of coarse particle streams n_coarse = 10 @@ -46,19 +45,19 @@ # Refined only transversely. Longitudinal spacing between particles in each stream is the same in both coarse and fine regions rr_longitudinal = 1 -np_expected = (n_coarse + n_fine*rr_longitudinal)*(n_0 + n_move) +np_expected = (n_coarse + n_fine * rr_longitudinal) * (n_0 + n_move) -assert( np == np_expected ) +assert ps == np_expected # Test uniformity of rho, by taking a slice of rho that # crosses the edge of the refined injection region # (but is ahead of the mesh refinement patch) ds.force_periodicity() ad = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -rho = ad['rho'].to_ndarray().squeeze() +rho = ad["rho"].to_ndarray().squeeze() rho_slice = rho[13:51, 475] # Test uniformity up to 0.5% relative variation -assert( rho_slice.std() < 0.005*abs(rho_slice.mean()) ) +assert rho_slice.std() < 0.005 * abs(rho_slice.mean()) test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Physics_applications/laser_acceleration/inputs_1d_fluids b/Examples/Physics_applications/laser_acceleration/inputs_1d_fluids deleted file mode 100644 index 73fa6b7283f..00000000000 --- a/Examples/Physics_applications/laser_acceleration/inputs_1d_fluids +++ /dev/null @@ -1,72 +0,0 @@ -################################# -####### GENERAL PARAMETERS ###### -################################# -max_step = 40000 -amr.n_cell = 10240 -amr.max_grid_size = 512 # maximum size of each AMReX box, used to decompose the domain -amr.blocking_factor = 512 # minimum size of each AMReX box, used to decompose the domain -geometry.dims = 1 -geometry.prob_lo = -120.e-6 # physical domain -geometry.prob_hi = 0.e-6 -amr.max_level = 0 # Maximum level in hierarchy (1 might be unstable, >1 is not supported) - -################################# -####### Boundary condition ###### -################################# -boundary.field_lo = pec -boundary.field_hi = pec - -################################# -############ NUMERICS ########### -################################# -warpx.verbose = 1 -warpx.do_dive_cleaning = 0 -warpx.use_filter = 0 -warpx.cfl = 0.45 #Fluid CFL < 0.5 -warpx.do_moving_window = 1 -warpx.moving_window_dir = z -warpx.moving_window_v = 1.0 # units of speed of light -warpx.do_dynamic_scheduling = 0 -warpx.serialize_initial_conditions = 1 - -################################# -############ PLASMA ############# -################################# -fluids.species_names = electrons ions - -electrons.species_type = electron -electrons.profile = parse_density_function -electrons.density_function(x,y,z) = "1.0e10 + 20.e23*((z*5.e4 + -0.5)*(z>10.e-6)*(z<30.e-6)) + 20.e23*((z>30.e-6))" -electrons.momentum_distribution_type = "at_rest" - -ions.charge = q_e -ions.mass = m_p -ions.profile = parse_density_function -ions.density_function(x,y,z) = "1.0e10 + 20.e23*((z*5.e4 + -0.5)*(z>10.e-6)*(z<30.e-6)) + 20.e23*((z>30.e-6))" -ions.momentum_distribution_type = "at_rest" - -# Order of particle shape factors -algo.particle_shape = 3 - -################################# -############ LASER ############## -################################# -lasers.names = laser1 -laser1.profile = Gaussian -laser1.position = 0. 0. -11.e-6 # This point is on the laser plane -laser1.direction = 0. 0. 1. # The plane normal direction -laser1.polarization = 0. 1. 0. # The main polarization vector -laser1.e_max = 10.e12 # Maximum amplitude of the laser field (in V/m) -laser1.profile_waist = 5.e-6 # The waist of the laser (in m) -laser1.profile_duration = 15.e-15 # The duration of the laser (in s) -laser1.profile_t_peak = 30.e-15 # Time at which the laser reaches its peak (in s) -laser1.profile_focal_distance = 100.e-6 # Focal distance from the antenna (in m) -laser1.wavelength = 0.8e-6 # The wavelength of the laser (in m) - -# Diagnostics -diagnostics.diags_names = diag1 - -# LAB -diag1.intervals = 20000 -diag1.diag_type = Full -diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz rho diff --git a/Examples/Physics_applications/laser_acceleration/inputs_2d b/Examples/Physics_applications/laser_acceleration/inputs_base_2d similarity index 100% rename from Examples/Physics_applications/laser_acceleration/inputs_2d rename to Examples/Physics_applications/laser_acceleration/inputs_base_2d diff --git a/Examples/Physics_applications/laser_acceleration/inputs_3d b/Examples/Physics_applications/laser_acceleration/inputs_base_3d similarity index 100% rename from Examples/Physics_applications/laser_acceleration/inputs_3d rename to Examples/Physics_applications/laser_acceleration/inputs_base_3d diff --git a/Examples/Physics_applications/laser_acceleration/inputs_rz b/Examples/Physics_applications/laser_acceleration/inputs_base_rz similarity index 100% rename from Examples/Physics_applications/laser_acceleration/inputs_rz rename to Examples/Physics_applications/laser_acceleration/inputs_base_rz diff --git a/Examples/Physics_applications/laser_acceleration/inputs_1d b/Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration similarity index 100% rename from Examples/Physics_applications/laser_acceleration/inputs_1d rename to Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration diff --git a/Examples/Physics_applications/laser_acceleration/inputs_1d_fluids_boosted b/Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration_fluid_boosted similarity index 100% rename from Examples/Physics_applications/laser_acceleration/inputs_1d_fluids_boosted rename to Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration_fluid_boosted diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration_picmi.py b/Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration_picmi.py new file mode 100755 index 00000000000..b7b86b47821 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_1d_laser_acceleration_picmi.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# Physical constants +c = picmi.constants.c +q_e = picmi.constants.q_e + +# Number of time steps +max_steps = 100 + +# Number of cells +nz = 256 + +# Physical domain +zmin = -56e-06 +zmax = 12e-06 + +# Domain decomposition +max_grid_size = 64 +blocking_factor = 32 + +# Create grid +grid = picmi.Cartesian1DGrid( + number_of_cells=[nz], + lower_bound=[zmin], + upper_bound=[zmax], + lower_boundary_conditions=["dirichlet"], + upper_boundary_conditions=["dirichlet"], + lower_boundary_conditions_particles=["absorbing"], + upper_boundary_conditions_particles=["absorbing"], + moving_window_velocity=[c], + warpx_max_grid_size=max_grid_size, + warpx_blocking_factor=blocking_factor, +) + +# Particles: plasma electrons +plasma_density = 2e23 +plasma_xmin = None +plasma_ymin = None +plasma_zmin = 10e-06 +plasma_xmax = None +plasma_ymax = None +plasma_zmax = None +uniform_distribution = picmi.UniformDistribution( + density=plasma_density, + lower_bound=[plasma_xmin, plasma_ymin, plasma_zmin], + upper_bound=[plasma_xmax, plasma_ymax, plasma_zmax], + fill_in=True, +) +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=uniform_distribution, +) + +# Laser +e_max = 16e12 +position_z = 9e-06 +profile_t_peak = 30.0e-15 +profile_focal_distance = 100e-06 +laser = picmi.GaussianLaser( + wavelength=0.8e-06, + waist=5e-06, + duration=15e-15, + focal_position=[0, 0, profile_focal_distance + position_z], + centroid_position=[0, 0, position_z - c * profile_t_peak], + propagation_direction=[0, 0, 1], + polarization_direction=[0, 1, 0], + E0=e_max, + fill_in=False, +) +laser_antenna = picmi.LaserAntenna( + position=[0.0, 0.0, position_z], normal_vector=[0, 0, 1] +) + +# Electromagnetic solver +solver = picmi.ElectromagneticSolver(grid=grid, method="Yee", cfl=0.9, divE_cleaning=0) + +# Diagnostics +diag_field_list = ["B", "E", "J", "rho"] +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=100, +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=100, + data_list=diag_field_list, +) + +# Set up simulation +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + particle_shape="cubic", + warpx_use_filter=1, + warpx_serialize_initial_conditions=1, + warpx_do_dynamic_scheduling=0, +) + +# Add plasma electrons +sim.add_species( + electrons, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[10]) +) + +# Add laser +sim.add_laser(laser, injection_method=laser_antenna) + +# Add diagnostics +sim.add_diagnostic(particle_diag) +sim.add_diagnostic(field_diag) + +# Write input file that can be used to run with the compiled version +sim.write_input_file(file_name="inputs_1d_picmi") + +# Initialize inputs and WarpX instance +sim.initialize_inputs() +sim.initialize_warpx() + +# Advance simulation until last time step +sim.step(max_steps) diff --git a/Examples/Physics_applications/laser_acceleration/inputs_2d_boost b/Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_boosted similarity index 98% rename from Examples/Physics_applications/laser_acceleration/inputs_2d_boost rename to Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_boosted index c2aa92c3634..1997054e885 100644 --- a/Examples/Physics_applications/laser_acceleration/inputs_2d_boost +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_boosted @@ -1,9 +1,9 @@ ################################# ######### BOX PARAMETERS ######## ################################# -max_step = 2700 +max_step = 300 #2700 # stop_time = 1.9e-12 -amr.n_cell = 128 1024 +amr.n_cell = 64 512 #128 1024 amr.max_grid_size = 64 amr.blocking_factor = 32 amr.max_level = 0 diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_mr b/Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_mr new file mode 100644 index 00000000000..5a98fa590ee --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_mr @@ -0,0 +1,2 @@ +# base input parameters +FILE = inputs_base_2d diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_mr_picmi.py b/Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_mr_picmi.py new file mode 100755 index 00000000000..8d112c0ac09 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_2d_laser_acceleration_mr_picmi.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# Physical constants +c = picmi.constants.c +q_e = picmi.constants.q_e + +# Number of time steps +max_steps = 200 + +# Number of cells +nx = 64 +nz = 512 + +# Physical domain +xmin = -30e-06 +xmax = 30e-06 +zmin = -56e-06 +zmax = 12e-06 +xmin_refined = -5e-06 +xmax_refined = 5e-06 +zmin_refined = -35e-06 +zmax_refined = -25e-06 + +# Domain decomposition +max_grid_size = 64 +blocking_factor = 32 + +# Create grid +grid = picmi.Cartesian2DGrid( + number_of_cells=[nx, nz], + lower_bound=[xmin, zmin], + upper_bound=[xmax, zmax], + lower_boundary_conditions=["open", "open"], + upper_boundary_conditions=["open", "open"], + lower_boundary_conditions_particles=["absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing"], + moving_window_velocity=[0.0, c], + warpx_max_grid_size=max_grid_size, + warpx_blocking_factor=blocking_factor, + refined_regions=[[1, [xmin_refined, zmin_refined], [xmax_refined, zmax_refined]]], +) + +# Particles: plasma electrons +plasma_density = 2e23 +plasma_xmin = -20e-06 +plasma_ymin = None +plasma_zmin = 10e-06 +plasma_xmax = 20e-06 +plasma_ymax = None +plasma_zmax = None +uniform_distribution = picmi.UniformDistribution( + density=plasma_density, + lower_bound=[plasma_xmin, plasma_ymin, plasma_zmin], + upper_bound=[plasma_xmax, plasma_ymax, plasma_zmax], + fill_in=True, +) +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=uniform_distribution, +) + +# Particles: beam electrons +q_tot = 1e-12 +x_m = 0.0 +y_m = 0.0 +z_m = -28e-06 +x_rms = 0.5e-06 +y_rms = 0.5e-06 +z_rms = 0.5e-06 +ux_m = 0.0 +uy_m = 0.0 +uz_m = 500.0 +ux_th = 2.0 +uy_th = 2.0 +uz_th = 50.0 +gaussian_bunch_distribution = picmi.GaussianBunchDistribution( + n_physical_particles=q_tot / q_e, + rms_bunch_size=[x_rms, y_rms, z_rms], + rms_velocity=[c * ux_th, c * uy_th, c * uz_th], + centroid_position=[x_m, y_m, z_m], + centroid_velocity=[c * ux_m, c * uy_m, c * uz_m], +) +beam = picmi.Species( + particle_type="electron", + name="beam", + initial_distribution=gaussian_bunch_distribution, +) + +# Laser +e_max = 16e12 +position_z = 9e-06 +profile_t_peak = 30.0e-15 +profile_focal_distance = 100e-06 +laser = picmi.GaussianLaser( + wavelength=0.8e-06, + waist=5e-06, + duration=15e-15, + focal_position=[0, 0, profile_focal_distance + position_z], + centroid_position=[0, 0, position_z - c * profile_t_peak], + propagation_direction=[0, 0, 1], + polarization_direction=[0, 1, 0], + E0=e_max, + fill_in=False, +) +laser_antenna = picmi.LaserAntenna( + position=[0.0, 0.0, position_z], normal_vector=[0, 0, 1] +) + +# Electromagnetic solver +solver = picmi.ElectromagneticSolver(grid=grid, method="Yee", cfl=1.0, divE_cleaning=0) + +# Diagnostics +diag_field_list = ["B", "E", "J", "rho"] +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=200, +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=200, + data_list=diag_field_list, +) + +# Set up simulation +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + particle_shape="cubic", + warpx_use_filter=1, + warpx_serialize_initial_conditions=1, +) + +# Add plasma electrons +sim.add_species( + electrons, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[1, 1, 1]) +) + +# Add beam electrons +sim.add_species(beam, layout=picmi.PseudoRandomLayout(grid=grid, n_macroparticles=100)) + +# Add laser +sim.add_laser(laser, injection_method=laser_antenna) + +# Add diagnostics +sim.add_diagnostic(particle_diag) +sim.add_diagnostic(field_diag) + +# Write input file that can be used to run with the compiled version +sim.write_input_file(file_name="inputs_2d_picmi") + +# Initialize inputs and WarpX instance +sim.initialize_inputs() +sim.initialize_warpx() + +# Advance simulation until last time step +sim.step(max_steps) diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_2d_refined_injection b/Examples/Physics_applications/laser_acceleration/inputs_test_2d_refined_injection new file mode 100644 index 00000000000..ed836e87e6b --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_2d_refined_injection @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +amr.ref_ratio_vect = 2 1 +warpx.refine_plasma = 1 diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration b/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration new file mode 100644 index 00000000000..7665a846eef --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration @@ -0,0 +1,2 @@ +# base input parameters +FILE = inputs_base_3d diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_picmi.py b/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_picmi.py new file mode 100755 index 00000000000..999c92600e2 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_picmi.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# Physical constants +c = picmi.constants.c +q_e = picmi.constants.q_e + +# Number of time steps +max_steps = 100 + +# Number of cells +nx = 32 +ny = 32 +nz = 256 + +# Physical domain +xmin = -30e-06 +xmax = 30e-06 +ymin = -30e-06 +ymax = 30e-06 +zmin = -56e-06 +zmax = 12e-06 + +# Domain decomposition +max_grid_size = 64 +blocking_factor = 32 + +# Create grid +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["periodic", "periodic", "dirichlet"], + upper_boundary_conditions=["periodic", "periodic", "dirichlet"], + lower_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + upper_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + moving_window_velocity=[0.0, 0.0, c], + warpx_max_grid_size=max_grid_size, + warpx_blocking_factor=blocking_factor, +) + +# Particles: plasma electrons +plasma_density = 2e23 +plasma_xmin = -20e-06 +plasma_ymin = -20e-06 +plasma_zmin = 0 +plasma_xmax = 20e-06 +plasma_ymax = 20e-06 +plasma_zmax = None +uniform_distribution = picmi.UniformDistribution( + density=plasma_density, + lower_bound=[plasma_xmin, plasma_ymin, plasma_zmin], + upper_bound=[plasma_xmax, plasma_ymax, plasma_zmax], + fill_in=True, +) +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=uniform_distribution, + warpx_add_int_attributes={"regionofinterest": "(z>12.0e-6) * (z<13.0e-6)"}, + warpx_add_real_attributes={"initialenergy": "ux*ux + uy*uy + uz*uz"}, +) + +# Particles: beam electrons +q_tot = 1e-12 +x_m = 0.0 +y_m = 0.0 +z_m = -28e-06 +x_rms = 0.5e-06 +y_rms = 0.5e-06 +z_rms = 0.5e-06 +ux_m = 0.0 +uy_m = 0.0 +uz_m = 500.0 +ux_th = 2.0 +uy_th = 2.0 +uz_th = 50.0 +gaussian_bunch_distribution = picmi.GaussianBunchDistribution( + n_physical_particles=q_tot / q_e, + rms_bunch_size=[x_rms, y_rms, z_rms], + rms_velocity=[c * ux_th, c * uy_th, c * uz_th], + centroid_position=[x_m, y_m, z_m], + centroid_velocity=[c * ux_m, c * uy_m, c * uz_m], +) +beam = picmi.Species( + particle_type="electron", + name="beam", + initial_distribution=gaussian_bunch_distribution, +) + +# Laser +e_max = 16e12 +position_z = 9e-06 +profile_t_peak = 30.0e-15 +profile_focal_distance = 100e-06 +laser = picmi.GaussianLaser( + wavelength=0.8e-06, + waist=5e-06, + duration=15e-15, + focal_position=[0, 0, profile_focal_distance + position_z], + centroid_position=[0, 0, position_z - c * profile_t_peak], + propagation_direction=[0, 0, 1], + polarization_direction=[0, 1, 0], + E0=e_max, + fill_in=False, +) +laser_antenna = picmi.LaserAntenna( + position=[0.0, 0.0, position_z], normal_vector=[0, 0, 1] +) + +# Electromagnetic solver +solver = picmi.ElectromagneticSolver(grid=grid, method="Yee", cfl=1.0, divE_cleaning=0) + +# Diagnostics +diag_field_list = ["B", "E", "J", "rho"] +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=100, +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=100, + data_list=diag_field_list, +) + +# Set up simulation +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + particle_shape="cubic", + warpx_use_filter=1, + warpx_serialize_initial_conditions=1, + warpx_do_dynamic_scheduling=0, +) + +# Add plasma electrons +sim.add_species( + electrons, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[1, 1, 1]) +) + +# Add beam electrons +sim.add_species(beam, layout=picmi.PseudoRandomLayout(grid=grid, n_macroparticles=100)) + +# Add laser +sim.add_laser(laser, injection_method=laser_antenna) + +# Add diagnostics +sim.add_diagnostic(particle_diag) +sim.add_diagnostic(field_diag) + +# Write input file that can be used to run with the compiled version +sim.write_input_file(file_name="inputs_3d_picmi") + +# Initialize inputs and WarpX instance +sim.initialize_inputs() +sim.initialize_warpx() + +# Advance simulation until last time step +sim.step(max_steps) diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_single_precision_comms b/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_single_precision_comms new file mode 100644 index 00000000000..99155ed0ecc --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_3d_laser_acceleration_single_precision_comms @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +warpx.do_single_precision_comms = 1 diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration b/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration new file mode 100644 index 00000000000..5879688b00a --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_rz + +# test input parameters +diag1.dump_rz_modes = 1 +warpx.abort_on_warning_threshold = high diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration_opmd b/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration_opmd new file mode 100644 index 00000000000..16a84950996 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration_opmd @@ -0,0 +1,9 @@ +# base input parameters +FILE = inputs_base_rz + +# test input parameters +diag1.fields_to_plot = Er Bt Bz jr jt jz rho part_per_cell part_per_grid rho_beam rho_electrons +diag1.format = openpmd +diag1.openpmd_backend = h5 +max_step = 20 +warpx.abort_on_warning_threshold = high diff --git a/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration_picmi.py b/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration_picmi.py new file mode 100755 index 00000000000..cfbf9879ed4 --- /dev/null +++ b/Examples/Physics_applications/laser_acceleration/inputs_test_rz_laser_acceleration_picmi.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# Physical constants +c = picmi.constants.c +q_e = picmi.constants.q_e + +# Number of time steps +max_steps = 10 + +# Number of cells +nr = 64 +nz = 512 + +# Physical domain +rmin = 0 +rmax = 30e-06 +zmin = -56e-06 +zmax = 12e-06 + +# Domain decomposition +max_grid_size = 64 +blocking_factor = 32 + +# Create grid +grid = picmi.CylindricalGrid( + number_of_cells=[nr, nz], + n_azimuthal_modes=2, + lower_bound=[rmin, zmin], + upper_bound=[rmax, zmax], + lower_boundary_conditions=["none", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["none", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing"], + moving_window_velocity=[0.0, c], + warpx_max_grid_size=max_grid_size, + warpx_blocking_factor=blocking_factor, +) + +# Particles: plasma electrons +plasma_density = 2e23 +plasma_xmin = -20e-06 +plasma_ymin = None +plasma_zmin = 10e-06 +plasma_xmax = 20e-06 +plasma_ymax = None +plasma_zmax = None +uniform_distribution = picmi.UniformDistribution( + density=plasma_density, + lower_bound=[plasma_xmin, plasma_ymin, plasma_zmin], + upper_bound=[plasma_xmax, plasma_ymax, plasma_zmax], + fill_in=True, +) +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=uniform_distribution, +) + +# Particles: beam electrons +q_tot = 1e-12 +x_m = 0.0 +y_m = 0.0 +z_m = -28e-06 +x_rms = 0.5e-06 +y_rms = 0.5e-06 +z_rms = 0.5e-06 +ux_m = 0.0 +uy_m = 0.0 +uz_m = 500.0 +ux_th = 2.0 +uy_th = 2.0 +uz_th = 50.0 +gaussian_bunch_distribution = picmi.GaussianBunchDistribution( + n_physical_particles=q_tot / q_e, + rms_bunch_size=[x_rms, y_rms, z_rms], + rms_velocity=[c * ux_th, c * uy_th, c * uz_th], + centroid_position=[x_m, y_m, z_m], + centroid_velocity=[c * ux_m, c * uy_m, c * uz_m], +) +beam = picmi.Species( + particle_type="electron", + name="beam", + initial_distribution=gaussian_bunch_distribution, +) + +# Laser +e_max = 16e12 +position_z = 9e-06 +profile_t_peak = 30.0e-15 +profile_focal_distance = 100e-06 +laser = picmi.GaussianLaser( + wavelength=0.8e-06, + waist=5e-06, + duration=15e-15, + focal_position=[0, 0, profile_focal_distance + position_z], + centroid_position=[0, 0, position_z - c * profile_t_peak], + propagation_direction=[0, 0, 1], + polarization_direction=[0, 1, 0], + E0=e_max, + fill_in=False, +) +laser_antenna = picmi.LaserAntenna( + position=[0.0, 0.0, position_z], normal_vector=[0, 0, 1] +) + +# Electromagnetic solver +solver = picmi.ElectromagneticSolver(grid=grid, method="Yee", cfl=1.0, divE_cleaning=0) + +# Diagnostics +diag_field_list = ["B", "E", "J", "rho"] +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=10, + data_list=diag_field_list, + warpx_dump_rz_modes=1, +) +diag_particle_list = ["weighting", "momentum"] +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=10, + species=[electrons, beam], + data_list=diag_particle_list, +) + +# Set up simulation +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + particle_shape="cubic", + warpx_use_filter=0, +) + +# Add plasma electrons +sim.add_species( + electrons, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[1, 4, 1]) +) + +# Add beam electrons +sim.add_species(beam, layout=picmi.PseudoRandomLayout(grid=grid, n_macroparticles=100)) + +# Add laser +sim.add_laser(laser, injection_method=laser_antenna) + +# Add diagnostics +sim.add_diagnostic(field_diag) +sim.add_diagnostic(particle_diag) + +# Write input file that can be used to run with the compiled version +sim.write_input_file(file_name="inputs_rz_picmi") + +# Initialize inputs and WarpX instance +sim.initialize_inputs() +sim.initialize_warpx() + +# Advance simulation until last time step +sim.step(max_steps) diff --git a/Examples/Physics_applications/laser_acceleration/plot_3d.py b/Examples/Physics_applications/laser_acceleration/plot_3d.py index 00222ff43c8..34e3770726b 100755 --- a/Examples/Physics_applications/laser_acceleration/plot_3d.py +++ b/Examples/Physics_applications/laser_acceleration/plot_3d.py @@ -36,5 +36,6 @@ def plot_lwfa(): fig.tight_layout() plt.show() + if __name__ == "__main__": plot_lwfa() diff --git a/Examples/Physics_applications/laser_ion/CMakeLists.txt b/Examples/Physics_applications/laser_ion/CMakeLists.txt new file mode 100644 index 00000000000..f05203de0e8 --- /dev/null +++ b/Examples/Physics_applications/laser_ion/CMakeLists.txt @@ -0,0 +1,22 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_laser_ion_acc # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_ion_acc # inputs + analysis_default_openpmd_regression.py # analysis + diags/diag1/ # output + OFF # dependency +) + +add_warpx_test( + test_2d_laser_ion_acc_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_ion_acc_picmi.py # inputs + analysis_default_openpmd_regression.py # analysis + diags/diag1/ # output + OFF # dependency +) diff --git a/Examples/Physics_applications/laser_ion/README.rst b/Examples/Physics_applications/laser_ion/README.rst index 29862a30518..e55cf6889d4 100644 --- a/Examples/Physics_applications/laser_ion/README.rst +++ b/Examples/Physics_applications/laser_ion/README.rst @@ -21,8 +21,8 @@ Run This example can be run **either** as: -* **Python** script: ``mpiexec -n 2 python3 PICMI_inputs_2d.py`` or -* WarpX **executable** using an input file: ``mpiexec -n 2 warpx.2d inputs_2d`` +* **Python** script: ``mpiexec -n 2 python3 inputs_test_2d_laser_ion_acc_picmi.py`` or +* WarpX **executable** using an input file: ``mpiexec -n 2 warpx.2d inputs_test_2d_laser_ion_acc`` .. tip:: @@ -35,16 +35,16 @@ This example can be run **either** as: .. tab-item:: Python: Script - .. literalinclude:: PICMI_inputs_2d.py + .. literalinclude:: inputs_test_2d_laser_ion_acc_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Physics_applications/laser_ion/PICMI_inputs_2d.py``. + :caption: You can copy this file from ``Examples/Physics_applications/laser_ion/inputs_test_2d_laser_ion_acc_picmi.py``. .. tab-item:: Executable: Input File - .. literalinclude:: inputs_2d + .. literalinclude:: inputs_test_2d_laser_ion_acc :language: ini - :caption: You can copy this file from ``Examples/Physics_applications/laser_ion/inputs_2d``. + :caption: You can copy this file from ``Examples/Physics_applications/laser_ion/inputs_test_2d_laser_ion_acc``. Analyze ------- diff --git a/Examples/Physics_applications/laser_ion/analysis_default_openpmd_regression.py b/Examples/Physics_applications/laser_ion/analysis_default_openpmd_regression.py new file mode 120000 index 00000000000..73e5ec47001 --- /dev/null +++ b/Examples/Physics_applications/laser_ion/analysis_default_openpmd_regression.py @@ -0,0 +1 @@ +../../analysis_default_openpmd_regression.py \ No newline at end of file diff --git a/Examples/Physics_applications/laser_ion/analysis_histogram_2D.py b/Examples/Physics_applications/laser_ion/analysis_histogram_2D.py index a262a2373e5..06d3bb42c8e 100644 --- a/Examples/Physics_applications/laser_ion/analysis_histogram_2D.py +++ b/Examples/Physics_applications/laser_ion/analysis_histogram_2D.py @@ -9,24 +9,29 @@ import numpy as np from openpmd_viewer import OpenPMDTimeSeries -parser = argparse.ArgumentParser(description='Process a 2D histogram name and an integer.') +parser = argparse.ArgumentParser( + description="Process a 2D histogram name and an integer." +) parser.add_argument("hist2D", help="Folder name of the reduced diagnostic.") -parser.add_argument("iter", help="Iteration number of the simulation that is plotted. Enter a number from the list of iterations or 'All' if you want all plots.") +parser.add_argument( + "iter", + help="Iteration number of the simulation that is plotted. Enter a number from the list of iterations or 'All' if you want all plots.", +) args = parser.parse_args() -path = 'diags/reducedfiles/' + args.hist2D +path = "diags/reducedfiles/" + args.hist2D ts = OpenPMDTimeSeries(path) it = ts.iterations data, info = ts.get_field(field="data", iteration=0, plot=True) -print('The available iterations of the simulation are:', it) -print('The axes of the histogram are (0: ordinate ; 1: abscissa):', info.axes) -print('The data shape is:', data.shape) +print("The available iterations of the simulation are:", it) +print("The axes of the histogram are (0: ordinate ; 1: abscissa):", info.axes) +print("The data shape is:", data.shape) # Add the simulation time to the title once this information # is available in the "info" FieldMetaInformation object. -if args.iter == 'All' : +if args.iter == "All": for it_idx, i in enumerate(it): plt.figure() data, info = ts.get_field(field="data", iteration=i, plot=False) @@ -35,14 +40,20 @@ ordinate_name = info.axes[0] # This might be 'z' or something else ordinate_values = getattr(info, ordinate_name, None) - plt.pcolormesh(abscissa_values/1e-6, ordinate_values, data, norm=colors.LogNorm(), rasterized=True) + plt.pcolormesh( + abscissa_values / 1e-6, + ordinate_values, + data, + norm=colors.LogNorm(), + rasterized=True, + ) plt.title(args.hist2D + f" Time: {ts.t[it_idx]:.2e} s (Iteration: {i:d})") - plt.xlabel(info.axes[1]+r' ($\mu$m)') - plt.ylabel(info.axes[0]+r' ($m_\mathrm{species} c$)') + plt.xlabel(info.axes[1] + r" ($\mu$m)") + plt.ylabel(info.axes[0] + r" ($m_\mathrm{species} c$)") plt.colorbar() plt.tight_layout() - plt.savefig('Histogram_2D_' + args.hist2D + '_iteration_' + str(i) + '.png') -else : + plt.savefig("Histogram_2D_" + args.hist2D + "_iteration_" + str(i) + ".png") +else: i = int(args.iter) it_idx = np.where(i == it)[0][0] plt.figure() @@ -52,10 +63,16 @@ ordinate_name = info.axes[0] # This might be 'z' or something else ordinate_values = getattr(info, ordinate_name, None) - plt.pcolormesh(abscissa_values/1e-6, ordinate_values, data, norm=colors.LogNorm(), rasterized=True) + plt.pcolormesh( + abscissa_values / 1e-6, + ordinate_values, + data, + norm=colors.LogNorm(), + rasterized=True, + ) plt.title(args.hist2D + f" Time: {ts.t[it_idx]:.2e} s (Iteration: {i:d})") - plt.xlabel(info.axes[1]+r' ($\mu$m)') - plt.ylabel(info.axes[0]+r' ($m_\mathrm{species} c$)') + plt.xlabel(info.axes[1] + r" ($\mu$m)") + plt.ylabel(info.axes[0] + r" ($m_\mathrm{species} c$)") plt.colorbar() plt.tight_layout() - plt.savefig('Histogram_2D_' + args.hist2D + '_iteration_' + str(i) + '.png') + plt.savefig("Histogram_2D_" + args.hist2D + "_iteration_" + str(i) + ".png") diff --git a/Examples/Physics_applications/laser_ion/inputs_2d b/Examples/Physics_applications/laser_ion/inputs_test_2d_laser_ion_acc similarity index 100% rename from Examples/Physics_applications/laser_ion/inputs_2d rename to Examples/Physics_applications/laser_ion/inputs_test_2d_laser_ion_acc diff --git a/Examples/Physics_applications/laser_ion/PICMI_inputs_2d.py b/Examples/Physics_applications/laser_ion/inputs_test_2d_laser_ion_acc_picmi.py similarity index 67% rename from Examples/Physics_applications/laser_ion/PICMI_inputs_2d.py rename to Examples/Physics_applications/laser_ion/inputs_test_2d_laser_ion_acc_picmi.py index 9f7a2aacfca..04f9111ec5f 100755 --- a/Examples/Physics_applications/laser_ion/PICMI_inputs_2d.py +++ b/Examples/Physics_applications/laser_ion/inputs_test_2d_laser_ion_acc_picmi.py @@ -15,8 +15,8 @@ # proper resolution for 30 n_c (dx<=3.33nm) incl. acc. length # (>=6x V100) # --> choose larger `max_grid_size` and `blocking_factor` for 1 to 8 grids per GPU accordingly -#nx = 7488 -#nz = 14720 +# nx = 7488 +# nz = 14720 # Number of cells nx = 384 @@ -37,12 +37,13 @@ number_of_cells=[nx, nz], lower_bound=[xmin, zmin], upper_bound=[xmax, zmax], - lower_boundary_conditions=['open', 'open'], - upper_boundary_conditions=['open', 'open'], - lower_boundary_conditions_particles=['absorbing', 'absorbing'], - upper_boundary_conditions_particles=['absorbing', 'absorbing'], + lower_boundary_conditions=["open", "open"], + upper_boundary_conditions=["open", "open"], + lower_boundary_conditions_particles=["absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing"], warpx_max_grid_size=max_grid_size, - warpx_blocking_factor=blocking_factor) + warpx_blocking_factor=blocking_factor, +) # Particles: plasma parameters # critical plasma density @@ -61,7 +62,9 @@ preplasma_Lcut = 2.0e-6 # [m] hard cutoff from surface plasma_r0 = 2.5e-6 # [m] radius or half-thickness plasma_eps_z = 0.05e-6 # [m] small offset in z to make zmin, zmax interval larger than 2*(r0 + Lcut) -plasma_creation_limit_z = plasma_r0 + preplasma_Lcut + plasma_eps_z # [m] upper limit in z for particle creation +plasma_creation_limit_z = ( + plasma_r0 + preplasma_Lcut + plasma_eps_z +) # [m] upper limit in z for particle creation plasma_xmin = None plasma_ymin = None @@ -70,17 +73,17 @@ plasma_ymax = None plasma_zmax = plasma_creation_limit_z -density_expression_str = f'{plasma_density}*((abs(z)<={plasma_r0}) + (abs(z)<{plasma_r0}+{preplasma_Lcut}) * (abs(z)>{plasma_r0}) * exp(-(abs(z)-{plasma_r0})/{preplasma_L}))' +density_expression_str = f"{plasma_density}*((abs(z)<={plasma_r0}) + (abs(z)<{plasma_r0}+{preplasma_Lcut}) * (abs(z)>{plasma_r0}) * exp(-(abs(z)-{plasma_r0})/{preplasma_L}))" slab_with_ramp_dist_hydrogen = picmi.AnalyticDistribution( density_expression=density_expression_str, lower_bound=[plasma_xmin, plasma_ymin, plasma_zmin], - upper_bound=[plasma_xmax, plasma_ymax, plasma_zmax] + upper_bound=[plasma_xmax, plasma_ymax, plasma_zmax], ) # thermal velocity spread for electrons in gamma*beta -ux_th = .01 -uz_th = .01 +ux_th = 0.01 +uz_th = 0.01 slab_with_ramp_dist_electrons = picmi.AnalyticDistribution( density_expression=density_expression_str, @@ -88,20 +91,20 @@ upper_bound=[plasma_xmax, plasma_ymax, plasma_zmax], # if `momentum_expressions` and `momentum_spread_expressions` are unset, # a Gaussian momentum distribution is assumed given that `rms_velocity` has any non-zero elements - rms_velocity=[c*ux_th, 0., c*uz_th] # thermal velocity spread in m/s + rms_velocity=[c * ux_th, 0.0, c * uz_th], # thermal velocity spread in m/s ) electrons = picmi.Species( - particle_type='electron', - name='electrons', + particle_type="electron", + name="electrons", initial_distribution=slab_with_ramp_dist_electrons, ) hydrogen = picmi.Species( - particle_type='proton', - name='hydrogen', + particle_type="proton", + name="hydrogen", initial_distribution=slab_with_ramp_dist_hydrogen, - warpx_add_real_attributes = {"orig_x": "x", "orig_z": "z"} + warpx_add_real_attributes={"orig_x": "x", "orig_z": "z"}, ) # Laser @@ -109,182 +112,182 @@ # a0 = 16, lambda_0 = 0.8mu -> e_max = 64.22 TV/m e_max = 64.22e12 position_z = -4.0e-06 -profile_t_peak = 50.e-15 +profile_t_peak = 50.0e-15 profile_focal_distance = 4.0e-06 laser = picmi.GaussianLaser( wavelength=0.8e-06, - waist=4.e-06, - duration=30.e-15, + waist=4.0e-06, + duration=30.0e-15, focal_position=[0, 0, profile_focal_distance + position_z], centroid_position=[0, 0, position_z - c * profile_t_peak], propagation_direction=[0, 0, 1], polarization_direction=[1, 0, 0], E0=e_max, - fill_in=False) + fill_in=False, +) laser_antenna = picmi.LaserAntenna( - position=[0., 0., position_z], - normal_vector=[0, 0, 1]) + position=[0.0, 0.0, position_z], normal_vector=[0, 0, 1] +) # Electromagnetic solver solver = picmi.ElectromagneticSolver( grid=grid, - method='Yee', + method="Yee", cfl=0.999, divE_cleaning=0, - #warpx_pml_ncell=10 + # warpx_pml_ncell=10 ) # Diagnostics particle_diag = picmi.ParticleDiagnostic( - name='Python_LaserIonAcc2d_plt', + name="diag1", period=100, - write_dir='./diags', - warpx_format='openpmd', - warpx_openpmd_backend='h5', + warpx_format="openpmd", + warpx_openpmd_backend="h5", # demonstration of a spatial and momentum filter - warpx_plot_filter_function='(uz>=0) * (x<1.0e-6) * (x>-1.0e-6)' + warpx_plot_filter_function="(uz>=0) * (x<1.0e-6) * (x>-1.0e-6)", ) # reduce resolution of output fields coarsening_ratio = [4, 4] ncell_field = [] -for (ncell_comp, cr) in zip([nx,nz], coarsening_ratio): - ncell_field.append(int(ncell_comp/cr)) +for ncell_comp, cr in zip([nx, nz], coarsening_ratio): + ncell_field.append(int(ncell_comp / cr)) field_diag = picmi.FieldDiagnostic( - name='Python_LaserIonAcc2d_plt', + name="diag1", grid=grid, period=100, number_of_cells=ncell_field, - data_list=['B', 'E', 'J', 'rho', 'rho_electrons', 'rho_hydrogen'], - write_dir='./diags', - warpx_format='openpmd', - warpx_openpmd_backend='h5' + data_list=["B", "E", "J", "rho", "rho_electrons", "rho_hydrogen"], + warpx_format="openpmd", + warpx_openpmd_backend="h5", ) particle_fw_diag = picmi.ParticleDiagnostic( - name='openPMDfw', + name="openPMDfw", period=100, - write_dir='./diags', - warpx_format='openpmd', - warpx_openpmd_backend='h5', - warpx_plot_filter_function='(uz>=0) * (x<1.0e-6) * (x>-1.0e-6)' + warpx_format="openpmd", + warpx_openpmd_backend="h5", + warpx_plot_filter_function="(uz>=0) * (x<1.0e-6) * (x>-1.0e-6)", ) particle_bw_diag = picmi.ParticleDiagnostic( - name='openPMDbw', + name="openPMDbw", period=100, - write_dir='./diags', - warpx_format='openpmd', - warpx_openpmd_backend='h5', - warpx_plot_filter_function='(uz<0)' + warpx_format="openpmd", + warpx_openpmd_backend="h5", + warpx_plot_filter_function="(uz<0)", ) # histograms with 2.0 degree acceptance angle in fw direction # 2 deg * pi / 180 : 0.03490658503 rad # half-angle +/- : 0.017453292515 rad histuH_rdiag = picmi.ReducedDiagnostic( - diag_type='ParticleHistogram', - name='histuH', + diag_type="ParticleHistogram", + name="histuH", period=100, species=hydrogen, bin_number=1000, bin_min=0.0, bin_max=0.474, # 100 MeV protons - histogram_function='u2=ux*ux+uy*uy+uz*uz; if(u2>0, sqrt(u2), 0.0)', - filter_function='u2=ux*ux+uy*uy+uz*uz; if(u2>0, abs(acos(uz / sqrt(u2))) <= 0.017453, 0)') + histogram_function="u2=ux*ux+uy*uy+uz*uz; if(u2>0, sqrt(u2), 0.0)", + filter_function="u2=ux*ux+uy*uy+uz*uz; if(u2>0, abs(acos(uz / sqrt(u2))) <= 0.017453, 0)", +) histue_rdiag = picmi.ReducedDiagnostic( - diag_type='ParticleHistogram', - name='histue', + diag_type="ParticleHistogram", + name="histue", period=100, species=electrons, bin_number=1000, bin_min=0.0, bin_max=197.0, # 100 MeV electrons - histogram_function='u2=ux*ux+uy*uy+uz*uz; if(u2>0, sqrt(u2), 0.0)', - filter_function='u2=ux*ux+uy*uy+uz*uz; if(u2>0, abs(acos(uz / sqrt(u2))) <= 0.017453, 0)') + histogram_function="u2=ux*ux+uy*uy+uz*uz; if(u2>0, sqrt(u2), 0.0)", + filter_function="u2=ux*ux+uy*uy+uz*uz; if(u2>0, abs(acos(uz / sqrt(u2))) <= 0.017453, 0)", +) # just a test entry to make sure that the histogram filter is purely optional: # this one just records uz of all hydrogen ions, independent of their pointing histuzAll_rdiag = picmi.ReducedDiagnostic( - diag_type='ParticleHistogram', - name='histuzAll', + diag_type="ParticleHistogram", + name="histuzAll", period=100, species=hydrogen, bin_number=1000, bin_min=-0.474, bin_max=0.474, - histogram_function='uz') + histogram_function="uz", +) field_probe_z_rdiag = picmi.ReducedDiagnostic( - diag_type='FieldProbe', - name='FieldProbe_Z', + diag_type="FieldProbe", + name="FieldProbe_Z", period=100, integrate=0, - probe_geometry='Line', + probe_geometry="Line", x_probe=0.0, z_probe=-5.0e-6, x1_probe=0.0, z1_probe=25.0e-6, - resolution=3712) + resolution=3712, +) field_probe_scat_point_rdiag = picmi.ReducedDiagnostic( - diag_type='FieldProbe', - name='FieldProbe_ScatPoint', + diag_type="FieldProbe", + name="FieldProbe_ScatPoint", period=1, integrate=0, - probe_geometry='Point', + probe_geometry="Point", x_probe=0.0, - z_probe=15.0e-6) + z_probe=15.0e-6, +) field_probe_scat_line_rdiag = picmi.ReducedDiagnostic( - diag_type='FieldProbe', - name='FieldProbe_ScatLine', + diag_type="FieldProbe", + name="FieldProbe_ScatLine", period=100, integrate=1, - probe_geometry='Line', + probe_geometry="Line", x_probe=-2.5e-6, z_probe=15.0e-6, x1_probe=2.5e-6, z1_probe=15e-6, - resolution=201) + resolution=201, +) load_balance_costs_rdiag = picmi.ReducedDiagnostic( - diag_type='LoadBalanceCosts', - name='LBC', - period=100) + diag_type="LoadBalanceCosts", name="LBC", period=100 +) # Set up simulation sim = picmi.Simulation( solver=solver, max_time=stop_time, # need to remove `max_step` to run this far verbose=1, - particle_shape='cubic', + particle_shape="cubic", warpx_numprocs=[1, 2], # deactivate `numprocs` for dynamic load balancing warpx_use_filter=1, warpx_load_balance_intervals=100, - warpx_load_balance_costs_update='heuristic' + warpx_load_balance_costs_update="heuristic", ) # Add plasma electrons sim.add_species( electrons, - layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[2,2]) + layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[2, 2]), # for more realistic simulations, try to avoid that macro-particles represent more than 1 n_c - #layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[4,8]) + # layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[4,8]) ) # Add hydrogen ions sim.add_species( hydrogen, - layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[2,2]) + layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[2, 2]), # for more realistic simulations, try to avoid that macro-particles represent more than 1 n_c - #layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[4,8]) + # layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[4,8]) ) # Add laser -sim.add_laser( - laser, - injection_method=laser_antenna) +sim.add_laser(laser, injection_method=laser_antenna) # Add full diagnostics sim.add_diagnostic(particle_diag) @@ -302,7 +305,7 @@ # TODO: make ParticleHistogram2D available # Write input file that can be used to run with the compiled version -sim.write_input_file(file_name='inputs_2d_picmi') +sim.write_input_file(file_name="inputs_2d_picmi") # Initialize inputs and WarpX instance sim.initialize_inputs() diff --git a/Examples/Physics_applications/laser_ion/plot_2d.py b/Examples/Physics_applications/laser_ion/plot_2d.py index 736203e85ea..f8a3b05d8a3 100644 --- a/Examples/Physics_applications/laser_ion/plot_2d.py +++ b/Examples/Physics_applications/laser_ion/plot_2d.py @@ -21,7 +21,8 @@ from matplotlib.colors import TwoSlopeNorm from openpmd_viewer import OpenPMDTimeSeries -plt.rcParams.update({'font.size':16}) +plt.rcParams.update({"font.size": 16}) + def create_analysis_dir(directory): if not os.path.exists(directory): @@ -40,7 +41,9 @@ def visualize_density_iteration(ts, iteration, out_dir): # Physics parameters lambda_L = 800e-9 # Laser wavelength in meters omega_L = 2 * np.pi * sc.c / lambda_L # Laser frequency in seconds - n_c = sc.m_e * sc.epsilon_0 * omega_L**2 / sc.elementary_charge**2 # Critical plasma density in meters^(-3) + n_c = ( + sc.m_e * sc.epsilon_0 * omega_L**2 / sc.elementary_charge**2 + ) # Critical plasma density in meters^(-3) micron = 1e-6 # Simulation parameters @@ -66,24 +69,49 @@ def visualize_density_iteration(ts, iteration, out_dir): # Plotting # Electron density - im0 = axs[0].pcolormesh(zax[::nr]/micron, xax[::nr]/micron, -rho_e.T[::nr, ::nr], - vmin=0, vmax=n_max, cmap="Reds", rasterized=True) + im0 = axs[0].pcolormesh( + zax[::nr] / micron, + xax[::nr] / micron, + -rho_e.T[::nr, ::nr], + vmin=0, + vmax=n_max, + cmap="Reds", + rasterized=True, + ) plt.colorbar(im0, ax=axs[0], label=r"$n_\mathrm{\,e}\ (n_\mathrm{c})$") # Hydrogen density - im1 = axs[1].pcolormesh(zax[::nr]/micron, xax[::nr]/micron, rho_d.T[::nr, ::nr], - vmin=0, vmax=n_max, cmap="Blues", rasterized=True) + im1 = axs[1].pcolormesh( + zax[::nr] / micron, + xax[::nr] / micron, + rho_d.T[::nr, ::nr], + vmin=0, + vmax=n_max, + cmap="Blues", + rasterized=True, + ) plt.colorbar(im1, ax=axs[1], label=r"$n_\mathrm{\,H}\ (n_\mathrm{c})$") # Masked electron density - divnorm = TwoSlopeNorm(vmin=-7., vcenter=0., vmax=2) + divnorm = TwoSlopeNorm(vmin=-7.0, vcenter=0.0, vmax=2) masked_data = np.ma.masked_where(rho_e.T == 0, rho_e.T) my_cmap = plt.cm.PiYG_r.copy() - my_cmap.set_bad(color='black') - im2 = axs[2].pcolormesh(zax[::nr]/micron, xax[::nr]/micron, np.log(-masked_data[::nr, ::nr]), - norm=divnorm, cmap=my_cmap, rasterized=True) - plt.colorbar(im2, ax=axs[2], ticks=[-6, -3, 0, 1, 2], extend='both', - label=r"$\log n_\mathrm{\,e}\ (n_\mathrm{c})$") + my_cmap.set_bad(color="black") + im2 = axs[2].pcolormesh( + zax[::nr] / micron, + xax[::nr] / micron, + np.log(-masked_data[::nr, ::nr]), + norm=divnorm, + cmap=my_cmap, + rasterized=True, + ) + plt.colorbar( + im2, + ax=axs[2], + ticks=[-6, -3, 0, 1, 2], + extend="both", + label=r"$\log n_\mathrm{\,e}\ (n_\mathrm{c})$", + ) # Axis labels and title for ax in axs: @@ -98,8 +126,8 @@ def visualize_density_iteration(ts, iteration, out_dir): plt.savefig(f"{out_dir}/densities_{it:06d}.png") -def visualize_field_iteration(ts, iteration, out_dir): +def visualize_field_iteration(ts, iteration, out_dir): # Additional parameters nr = 1 # Number to decrease resolution micron = 1e-6 @@ -110,35 +138,50 @@ def visualize_field_iteration(ts, iteration, out_dir): time = ts.t[ii] Ex, Ex_info = ts.get_field(field="E", coord="x", iteration=it) - Exmax = np.max(np.abs([np.min(Ex),np.max(Ex)])) + Exmax = np.max(np.abs([np.min(Ex), np.max(Ex)])) By, By_info = ts.get_field(field="B", coord="y", iteration=it) - Bymax = np.max(np.abs([np.min(By),np.max(By)])) + Bymax = np.max(np.abs([np.min(By), np.max(By)])) Ez, Ez_info = ts.get_field(field="E", coord="z", iteration=it) - Ezmax = np.max(np.abs([np.min(Ez),np.max(Ez)])) + Ezmax = np.max(np.abs([np.min(Ez), np.max(Ez)])) # Axes setup - fig,axs = plt.subplots(3, 1, figsize=(5, 8)) + fig, axs = plt.subplots(3, 1, figsize=(5, 8)) xax, zax = Ex_info.x, Ex_info.z # Plotting im0 = axs[0].pcolormesh( - zax[::nr]/micron,xax[::nr]/micron,Ex.T[::nr,::nr], - vmin=-Exmax, vmax=Exmax, - cmap="RdBu", rasterized=True) + zax[::nr] / micron, + xax[::nr] / micron, + Ex.T[::nr, ::nr], + vmin=-Exmax, + vmax=Exmax, + cmap="RdBu", + rasterized=True, + ) - plt.colorbar(im0,ax=axs[00], label=r"$E_x$ (V/m)") + plt.colorbar(im0, ax=axs[00], label=r"$E_x$ (V/m)") im1 = axs[1].pcolormesh( - zax[::nr]/micron,xax[::nr]/micron,By.T[::nr,::nr], - vmin=-Bymax, vmax=Bymax, - cmap="RdBu", rasterized=True) - plt.colorbar(im1,ax=axs[1], label=r"$B_y$ (T)") + zax[::nr] / micron, + xax[::nr] / micron, + By.T[::nr, ::nr], + vmin=-Bymax, + vmax=Bymax, + cmap="RdBu", + rasterized=True, + ) + plt.colorbar(im1, ax=axs[1], label=r"$B_y$ (T)") im2 = axs[2].pcolormesh( - zax[::nr]/micron,xax[::nr]/micron,Ez.T[::nr,::nr], - vmin=-Ezmax, vmax=Ezmax, - cmap="RdBu", rasterized=True) - plt.colorbar(im2,ax=axs[2],label=r"$E_z$ (V/m)") + zax[::nr] / micron, + xax[::nr] / micron, + Ez.T[::nr, ::nr], + vmin=-Ezmax, + vmax=Ezmax, + cmap="RdBu", + rasterized=True, + ) + plt.colorbar(im2, ax=axs[2], label=r"$E_z$ (V/m)") # Axis labels and title for ax in axs: @@ -153,42 +196,48 @@ def visualize_field_iteration(ts, iteration, out_dir): plt.savefig(f"{out_dir}/fields_{it:06d}.png") -def visualize_particle_histogram_iteration(diag_name="histuH", species="hydrogen", iteration=1000, out_dir="./analysis"): +def visualize_particle_histogram_iteration( + diag_name="histuH", species="hydrogen", iteration=1000, out_dir="./analysis" +): it = iteration if species == "hydrogen": # proton rest energy in eV - mc2 = sc.m_p/sc.electron_volt * sc.c**2 + mc2 = sc.m_p / sc.electron_volt * sc.c**2 elif species == "electron": - mc2 = sc.m_e/sc.electron_volt * sc.c**2 + mc2 = sc.m_e / sc.electron_volt * sc.c**2 else: - raise NotImplementedError("The only implemented presets for this analysis script are `electron` or `hydrogen`.") + raise NotImplementedError( + "The only implemented presets for this analysis script are `electron` or `hydrogen`." + ) - fs = 1.e-15 - MeV = 1.e6 + fs = 1.0e-15 + MeV = 1.0e6 - df = pd.read_csv(f"./diags/reducedfiles/{diag_name}.txt",delimiter=r'\s+') + df = pd.read_csv(f"./diags/reducedfiles/{diag_name}.txt", delimiter=r"\s+") # the columns look like this: # #[0]step() [1]time(s) [2]bin1=0.000220() [3]bin2=0.000660() [4]bin3=0.001100() # matches words, strings surrounded by " ' ", dots, minus signs and e for scientific notation in numbers - nested_list = [re.findall(r"[\w'\.]+",col) for col in df.columns] + nested_list = [re.findall(r"[\w'\.]+", col) for col in df.columns] - index = pd.MultiIndex.from_tuples(nested_list, names=('column#', 'name', 'bin value')) + index = pd.MultiIndex.from_tuples( + nested_list, names=("column#", "name", "bin value") + ) - df.columns = (index) + df.columns = index steps = df.values[:, 0].astype(int) ii = np.where(steps == it)[0][0] time = df.values[:, 1] data = df.values[:, 2:] edge_vals = np.array([float(row[2]) for row in df.columns[2:]]) - edges_MeV = (np.sqrt(edge_vals**2 + 1)-1) * mc2 / MeV + edges_MeV = (np.sqrt(edge_vals**2 + 1) - 1) * mc2 / MeV time_fs = time / fs - fig,ax = plt.subplots(1,1) + fig, ax = plt.subplots(1, 1) ax.plot(edges_MeV, data[ii, :]) ax.set_yscale("log") @@ -202,17 +251,42 @@ def visualize_particle_histogram_iteration(diag_name="histuH", species="hydrogen if __name__ == "__main__": - # Argument parsing - parser = argparse.ArgumentParser(description='Visualize Laser-Ion Accelerator Densities and Fields') - parser.add_argument('-d', '--diag_dir', type=str, default='./diags/diag1', help='Directory containing density and field diagnostics') - parser.add_argument('-i', '--iteration', type=int, default=None, help='Specific iteration to visualize') - parser.add_argument('-hn', '--histogram_name', type=str, default='histuH', help='Name of histogram diagnostic to visualize') - parser.add_argument('-hs', '--histogram_species', type=str, default='hydrogen', help='Particle species in the visualized histogram diagnostic') + parser = argparse.ArgumentParser( + description="Visualize Laser-Ion Accelerator Densities and Fields" + ) + parser.add_argument( + "-d", + "--diag_dir", + type=str, + default="./diags/diag1", + help="Directory containing density and field diagnostics", + ) + parser.add_argument( + "-i", + "--iteration", + type=int, + default=None, + help="Specific iteration to visualize", + ) + parser.add_argument( + "-hn", + "--histogram_name", + type=str, + default="histuH", + help="Name of histogram diagnostic to visualize", + ) + parser.add_argument( + "-hs", + "--histogram_species", + type=str, + default="hydrogen", + help="Particle species in the visualized histogram diagnostic", + ) args = parser.parse_args() # Create analysis directory - analysis_dir = 'analysis' + analysis_dir = "analysis" create_analysis_dir(analysis_dir) # Loading the time series @@ -221,9 +295,13 @@ def visualize_particle_histogram_iteration(diag_name="histuH", species="hydrogen if args.iteration is not None: visualize_density_iteration(ts, args.iteration, analysis_dir) visualize_field_iteration(ts, args.iteration, analysis_dir) - visualize_particle_histogram_iteration(args.histogram_name, args.histogram_species, args.iteration, analysis_dir) + visualize_particle_histogram_iteration( + args.histogram_name, args.histogram_species, args.iteration, analysis_dir + ) else: for it in ts.iterations: visualize_density_iteration(ts, it, analysis_dir) visualize_field_iteration(ts, it, analysis_dir) - visualize_particle_histogram_iteration(args.histogram_name, args.histogram_species, it, analysis_dir) + visualize_particle_histogram_iteration( + args.histogram_name, args.histogram_species, it, analysis_dir + ) diff --git a/Examples/Physics_applications/plasma_acceleration/CMakeLists.txt b/Examples/Physics_applications/plasma_acceleration/CMakeLists.txt new file mode 100644 index 00000000000..00a0f80b457 --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/CMakeLists.txt @@ -0,0 +1,82 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_plasma_acceleration_picmi # name + 1 # dims + 2 # nprocs + inputs_test_1d_plasma_acceleration_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1001000 # output + OFF # dependency +) + +add_warpx_test( + test_2d_plasma_acceleration_boosted # name + 2 # dims + 2 # nprocs + inputs_test_2d_plasma_acceleration_boosted # inputs + analysis_default_regression.py # analysis + diags/diag1000020 # output + OFF # dependency +) + +add_warpx_test( + test_2d_plasma_acceleration_mr # name + 2 # dims + 2 # nprocs + inputs_test_2d_plasma_acceleration_mr # inputs + analysis_default_regression.py # analysis + diags/diag1000400 # output + OFF # dependency +) + +add_warpx_test( + test_2d_plasma_acceleration_mr_momentum_conserving # name + 2 # dims + 2 # nprocs + inputs_test_2d_plasma_acceleration_mr_momentum_conserving # inputs + analysis_default_regression.py # analysis + diags/diag1000400 # output + OFF # dependency +) + +add_warpx_test( + test_3d_plasma_acceleration_boosted # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_acceleration_boosted # inputs + analysis_default_regression.py # analysis + diags/diag1000005 # output + OFF # dependency +) + +add_warpx_test( + test_3d_plasma_acceleration_boosted_hybrid # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_acceleration_boosted_hybrid # inputs + analysis_default_regression.py # analysis + diags/diag1000025 # output + OFF # dependency +) + +add_warpx_test( + test_3d_plasma_acceleration_mr_picmi # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_acceleration_mr_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000002 # output + OFF # dependency +) + +add_warpx_test( + test_3d_plasma_acceleration_picmi # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_acceleration_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) diff --git a/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration.py b/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration.py deleted file mode 100755 index 296aea48b35..00000000000 --- a/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -#from warp import picmi - -constants = picmi.constants - -nx = 64 -ny = 64 -nz = 64 - -xmin = -200.e-6 -xmax = +200.e-6 -ymin = -200.e-6 -ymax = +200.e-6 -zmin = -200.e-6 -zmax = +200.e-6 - -moving_window_velocity = [0., 0., constants.c] - -number_per_cell_each_dim = [2, 2, 1] - -max_steps = 10 - -grid = picmi.Cartesian3DGrid(number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = ['periodic', 'periodic', 'open'], - upper_boundary_conditions = ['periodic', 'periodic', 'open'], - lower_boundary_conditions_particles = ['periodic', 'periodic', 'absorbing'], - upper_boundary_conditions_particles = ['periodic', 'periodic', 'absorbing'], - moving_window_velocity = moving_window_velocity, - warpx_max_grid_size=32) - -solver = picmi.ElectromagneticSolver(grid=grid, cfl=1) - -beam_distribution = picmi.UniformDistribution(density = 1.e23, - lower_bound = [-20.e-6, -20.e-6, -150.e-6], - upper_bound = [+20.e-6, +20.e-6, -100.e-6], - directed_velocity = [0., 0., 1.e9]) - -plasma_distribution = picmi.UniformDistribution(density = 1.e22, - lower_bound = [-200.e-6, -200.e-6, 0.], - upper_bound = [+200.e-6, +200.e-6, None], - fill_in = True) - -beam = picmi.Species(particle_type='electron', name='beam', initial_distribution=beam_distribution) -plasma = picmi.Species(particle_type='electron', name='plasma', initial_distribution=plasma_distribution) - -sim = picmi.Simulation(solver = solver, - max_steps = max_steps, - verbose = 1, - warpx_current_deposition_algo = 'esirkepov', - warpx_use_filter = 0) - -sim.add_species(beam, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim)) -sim.add_species(plasma, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim)) - -field_diag = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = max_steps, - data_list = ['Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz', 'part_per_cell'], - write_dir = '.', - warpx_file_prefix = 'Python_PlasmaAcceleration_plt') - -part_diag = picmi.ParticleDiagnostic(name = 'diag1', - period = max_steps, - species = [beam, plasma], - data_list = ['ux', 'uy', 'uz', 'weighting']) - -sim.add_diagnostic(field_diag) -sim.add_diagnostic(part_diag) - -# write_inputs will create an inputs file that can be used to run -# with the compiled version. -#sim.write_input_file(file_name = 'inputs_from_PICMI') - -# Alternatively, sim.step will run WarpX, controlling it from Python -sim.step() diff --git a/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_1d.py b/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_1d.py deleted file mode 100755 index 27f7236204e..00000000000 --- a/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_1d.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -#from warp import picmi - -constants = picmi.constants - -nz = 64 - -zmin = -200.e-6 -zmax = +200.e-6 - -moving_window_velocity = [constants.c] - -number_per_cell_each_dim = [10] - -max_steps = 1000 - -grid = picmi.Cartesian1DGrid(number_of_cells = [nz], - lower_bound = [zmin], - upper_bound = [zmax], - lower_boundary_conditions = ['dirichlet'], - upper_boundary_conditions = ['dirichlet'], - lower_boundary_conditions_particles = ['absorbing'], - upper_boundary_conditions_particles = ['absorbing'], - moving_window_velocity = moving_window_velocity, - warpx_max_grid_size=32) - -solver = picmi.ElectromagneticSolver(grid=grid, cfl=0.999) - -beam_distribution = picmi.UniformDistribution(density = 1.e23, - lower_bound = [None, None, -150.e-6], - upper_bound = [None, None, -100.e-6], - directed_velocity = [0., 0., 1.e9]) - -plasma_distribution = picmi.UniformDistribution(density = 1.e22, - lower_bound = [None, None, 0.], - upper_bound = [None, None, None], - fill_in = True) - -beam = picmi.Species(particle_type='electron', name='beam', initial_distribution=beam_distribution) -plasma = picmi.Species(particle_type='electron', name='plasma', initial_distribution=plasma_distribution) - -sim = picmi.Simulation(solver = solver, - max_steps = max_steps, - verbose = 1, - warpx_current_deposition_algo = 'esirkepov', - warpx_use_filter = 0) - -sim.add_species(beam, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim)) -sim.add_species(plasma, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim)) - -field_diag = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = max_steps, - data_list = ['Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz', 'part_per_cell'], - write_dir = '.', - warpx_file_prefix = 'Python_PlasmaAcceleration1d_plt') - -part_diag = picmi.ParticleDiagnostic(name = 'diag1', - period = max_steps, - species = [beam, plasma], - data_list = ['ux', 'uy', 'uz', 'weighting']) - -sim.add_diagnostic(field_diag) -sim.add_diagnostic(part_diag) - -# write_inputs will create an inputs file that can be used to run -# with the compiled version. -#sim.write_input_file(file_name = 'inputs_from_PICMI') - -# Alternatively, sim.step will run WarpX, controlling it from Python -sim.step() diff --git a/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_mr.py b/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_mr.py deleted file mode 100755 index 52a9729a1fb..00000000000 --- a/Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_mr.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -#from warp import picmi - -constants = picmi.constants - -nx = 64 -ny = 64 -nz = 64 - -xmin = -200.e-6 -xmax = +200.e-6 -ymin = -200.e-6 -ymax = +200.e-6 -zmin = -200.e-6 -zmax = +200.e-6 - -moving_window_velocity = [0., 0., constants.c] - -number_per_cell_each_dim = [4, 4, 4] - -grid = picmi.Cartesian3DGrid(number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = ['periodic', 'periodic', 'open'], - upper_boundary_conditions = ['periodic', 'periodic', 'open'], - lower_boundary_conditions_particles = ['periodic', 'periodic', 'absorbing'], - upper_boundary_conditions_particles = ['periodic', 'periodic', 'absorbing'], - moving_window_velocity = moving_window_velocity, - #refined_regions = [[1, [-25e-6, -25e-6, -200.e-6], [25e-6, 25e-6, 200.e-6]]], # as argument - warpx_max_grid_size=128, warpx_blocking_factor=16) - -# --- As a separate function call (instead of refined_regions argument) -grid.add_refined_region(level = 1, - lo = [-25e-6, -25e-6, -200.e-6], - hi = [25e-6, 25e-6, 200.e-6]) - -solver = picmi.ElectromagneticSolver(grid=grid, cfl=1, - warpx_pml_ncell = 10) - -beam_distribution = picmi.UniformDistribution(density = 1.e23, - lower_bound = [-20.e-6, -20.e-6, -150.e-6], - upper_bound = [+20.e-6, +20.e-6, -100.e-6], - directed_velocity = [0., 0., 1.e9]) - -plasma_distribution = picmi.UniformDistribution(density = 1.e22, - lower_bound = [-200.e-6, -200.e-6, 0.], - upper_bound = [+200.e-6, +200.e-6, None], - fill_in = True) - -beam = picmi.Species(particle_type='electron', name='beam', initial_distribution=beam_distribution) -plasma = picmi.Species(particle_type='electron', name='plasma', initial_distribution=plasma_distribution) - -sim = picmi.Simulation(solver = solver, - max_steps = 2, - verbose = 1, - warpx_current_deposition_algo = 'esirkepov', - warpx_use_filter = 0) - -sim.add_species(beam, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim)) -sim.add_species(plasma, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim)) - -field_diag = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = 2, - data_list = ['Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz', 'part_per_cell'], - write_dir = '.', - warpx_file_prefix = 'Python_PlasmaAccelerationMR_plt') - -part_diag = picmi.ParticleDiagnostic(name = 'diag1', - period = 2, - species = [beam, plasma], - data_list = ['ux', 'uy', 'uz', 'weighting']) - -sim.add_diagnostic(field_diag) -sim.add_diagnostic(part_diag) - -# write_inputs will create an inputs file that can be used to run -# with the compiled version. -#sim.write_input_file(file_name = 'inputs_from_PICMI.mr') - -# Alternatively, sim.step will run WarpX, controlling it from Python -sim.step() diff --git a/Examples/Physics_applications/plasma_acceleration/README.rst b/Examples/Physics_applications/plasma_acceleration/README.rst index d5775e93aa8..0c1b1819cab 100644 --- a/Examples/Physics_applications/plasma_acceleration/README.rst +++ b/Examples/Physics_applications/plasma_acceleration/README.rst @@ -16,7 +16,7 @@ In the Beam, Plasma & Accelerator Simulation Toolkit (BLAST), `HiPACE++ `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. @@ -35,17 +35,17 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. note:: - TODO: This input file should use the boosted frame method, like the ``inputs_3d_boost`` file. + TODO: This input file should use the boosted frame method, like the ``inputs_test_3d_plasma_acceleration_boosted`` file. - .. literalinclude:: PICMI_inputs_plasma_acceleration.py + .. literalinclude:: inputs_test_3d_plasma_acceleration_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration.py``. + :caption: You can copy this file from ``Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_picmi.py``. .. tab-item:: Executable: Input File - .. literalinclude:: inputs_3d_boost + .. literalinclude:: inputs_test_3d_plasma_acceleration_boosted :language: ini - :caption: You can copy this file from ``Examples/Physics_applications/plasma_acceleration/inputs_3d_boost``. + :caption: You can copy this file from ``Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_boosted``. Analyze ------- diff --git a/Examples/Physics_applications/plasma_acceleration/analysis_default_regression.py b/Examples/Physics_applications/plasma_acceleration/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_2d b/Examples/Physics_applications/plasma_acceleration/inputs_base_2d similarity index 96% rename from Examples/Physics_applications/plasma_acceleration/inputs_2d rename to Examples/Physics_applications/plasma_acceleration/inputs_base_2d index 7e11ae7b3de..769e1ebce37 100644 --- a/Examples/Physics_applications/plasma_acceleration/inputs_2d +++ b/Examples/Physics_applications/plasma_acceleration/inputs_base_2d @@ -1,11 +1,12 @@ ################################# ####### GENERAL PARAMETERS ###### ################################# -stop_time = 3.7e-12 -amr.n_cell = 64 128 +#stop_time = 3.7e-12 +max_step = 400 +amr.n_cell = 32 512 #64 128 amr.max_grid_size = 128 amr.blocking_factor = 32 -amr.max_level = 0 +amr.max_level = 1 geometry.dims = 2 geometry.prob_lo = -125.e-6 -149.e-6 geometry.prob_hi = 125.e-6 1.e-6 diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_3d_boost b/Examples/Physics_applications/plasma_acceleration/inputs_base_3d similarity index 99% rename from Examples/Physics_applications/plasma_acceleration/inputs_3d_boost rename to Examples/Physics_applications/plasma_acceleration/inputs_base_3d index 2264872ec43..66debc4f99f 100644 --- a/Examples/Physics_applications/plasma_acceleration/inputs_3d_boost +++ b/Examples/Physics_applications/plasma_acceleration/inputs_base_3d @@ -2,7 +2,7 @@ ####### GENERAL PARAMETERS ###### ################################# stop_time = 3.93151387287e-11 -amr.n_cell = 32 32 256 +amr.n_cell = 64 64 128 #32 32 256 amr.max_grid_size = 64 amr.blocking_factor = 32 amr.max_level = 0 diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_test_1d_plasma_acceleration_picmi.py b/Examples/Physics_applications/plasma_acceleration/inputs_test_1d_plasma_acceleration_picmi.py new file mode 100755 index 00000000000..4bde8cb1343 --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/inputs_test_1d_plasma_acceleration_picmi.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# from warp import picmi + +constants = picmi.constants + +nz = 64 + +zmin = -200.0e-6 +zmax = +200.0e-6 + +moving_window_velocity = [constants.c] + +number_per_cell_each_dim = [10] + +max_steps = 1000 + +grid = picmi.Cartesian1DGrid( + number_of_cells=[nz], + lower_bound=[zmin], + upper_bound=[zmax], + lower_boundary_conditions=["dirichlet"], + upper_boundary_conditions=["dirichlet"], + lower_boundary_conditions_particles=["absorbing"], + upper_boundary_conditions_particles=["absorbing"], + moving_window_velocity=moving_window_velocity, + warpx_max_grid_size=32, +) + +solver = picmi.ElectromagneticSolver(grid=grid, cfl=0.999) + +beam_distribution = picmi.UniformDistribution( + density=1.0e23, + lower_bound=[None, None, -150.0e-6], + upper_bound=[None, None, -100.0e-6], + directed_velocity=[0.0, 0.0, 1.0e9], +) + +plasma_distribution = picmi.UniformDistribution( + density=1.0e22, + lower_bound=[None, None, 0.0], + upper_bound=[None, None, None], + fill_in=True, +) + +beam = picmi.Species( + particle_type="electron", name="beam", initial_distribution=beam_distribution +) +plasma = picmi.Species( + particle_type="electron", name="plasma", initial_distribution=plasma_distribution +) + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + warpx_current_deposition_algo="esirkepov", + warpx_use_filter=0, +) + +sim.add_species( + beam, + layout=picmi.GriddedLayout( + grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim + ), +) +sim.add_species( + plasma, + layout=picmi.GriddedLayout( + grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim + ), +) + +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=max_steps, + data_list=["Ex", "Ey", "Ez", "Jx", "Jy", "Jz", "part_per_cell"], +) + +part_diag = picmi.ParticleDiagnostic( + name="diag1", + period=max_steps, + species=[beam, plasma], + data_list=["ux", "uy", "uz", "weighting"], +) + +sim.add_diagnostic(field_diag) +sim.add_diagnostic(part_diag) + +# write_inputs will create an inputs file that can be used to run +# with the compiled version. +# sim.write_input_file(file_name = 'inputs_from_PICMI') + +# Alternatively, sim.step will run WarpX, controlling it from Python +sim.step() diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_2d_boost b/Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_boosted similarity index 98% rename from Examples/Physics_applications/plasma_acceleration/inputs_2d_boost rename to Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_boosted index 76dcd3ee286..5d65649353c 100644 --- a/Examples/Physics_applications/plasma_acceleration/inputs_2d_boost +++ b/Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_boosted @@ -1,8 +1,8 @@ ################################# ####### GENERAL PARAMETERS ###### ################################# -max_step = 2500 -amr.n_cell = 64 640 +max_step = 20 #2500 +amr.n_cell = 64 256 #64 640 amr.max_grid_size = 128 amr.blocking_factor = 32 amr.max_level = 0 diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_mr b/Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_mr new file mode 100644 index 00000000000..5a98fa590ee --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_mr @@ -0,0 +1,2 @@ +# base input parameters +FILE = inputs_base_2d diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_mr_momentum_conserving b/Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_mr_momentum_conserving new file mode 100644 index 00000000000..c21068325a0 --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/inputs_test_2d_plasma_acceleration_mr_momentum_conserving @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.field_gathering = momentum-conserving diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_boosted b/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_boosted new file mode 100644 index 00000000000..62abe8e9df8 --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_boosted @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +max_step = 5 diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_boosted_hybrid b/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_boosted_hybrid new file mode 100644 index 00000000000..3c085b64b1b --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_boosted_hybrid @@ -0,0 +1,7 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +max_step = 25 +warpx.do_current_centering = 0 +warpx.grid_type = hybrid diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_mr_picmi.py b/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_mr_picmi.py new file mode 100755 index 00000000000..9eb640ade95 --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_mr_picmi.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# from warp import picmi + +constants = picmi.constants + +nx = 64 +ny = 64 +nz = 64 + +xmin = -200.0e-6 +xmax = +200.0e-6 +ymin = -200.0e-6 +ymax = +200.0e-6 +zmin = -200.0e-6 +zmax = +200.0e-6 + +moving_window_velocity = [0.0, 0.0, constants.c] + +number_per_cell_each_dim = [4, 4, 4] + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["periodic", "periodic", "open"], + upper_boundary_conditions=["periodic", "periodic", "open"], + lower_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + upper_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + moving_window_velocity=moving_window_velocity, + # refined_regions = [[1, [-25e-6, -25e-6, -200.e-6], [25e-6, 25e-6, 200.e-6]]], # as argument + warpx_max_grid_size=128, + warpx_blocking_factor=16, +) + +# --- As a separate function call (instead of refined_regions argument) +grid.add_refined_region( + level=1, lo=[-25e-6, -25e-6, -200.0e-6], hi=[25e-6, 25e-6, 200.0e-6] +) + +solver = picmi.ElectromagneticSolver(grid=grid, cfl=1, warpx_pml_ncell=10) + +beam_distribution = picmi.UniformDistribution( + density=1.0e23, + lower_bound=[-20.0e-6, -20.0e-6, -150.0e-6], + upper_bound=[+20.0e-6, +20.0e-6, -100.0e-6], + directed_velocity=[0.0, 0.0, 1.0e9], +) + +plasma_distribution = picmi.UniformDistribution( + density=1.0e22, + lower_bound=[-200.0e-6, -200.0e-6, 0.0], + upper_bound=[+200.0e-6, +200.0e-6, None], + fill_in=True, +) + +beam = picmi.Species( + particle_type="electron", name="beam", initial_distribution=beam_distribution +) +plasma = picmi.Species( + particle_type="electron", name="plasma", initial_distribution=plasma_distribution +) + +sim = picmi.Simulation( + solver=solver, + max_steps=2, + verbose=1, + warpx_current_deposition_algo="esirkepov", + warpx_use_filter=0, +) + +sim.add_species( + beam, + layout=picmi.GriddedLayout( + grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim + ), +) +sim.add_species( + plasma, + layout=picmi.GriddedLayout( + grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim + ), +) + +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=2, + data_list=["Ex", "Ey", "Ez", "Jx", "Jy", "Jz", "part_per_cell"], +) + +part_diag = picmi.ParticleDiagnostic( + name="diag1", + period=2, + species=[beam, plasma], + data_list=["ux", "uy", "uz", "weighting"], +) + +sim.add_diagnostic(field_diag) +sim.add_diagnostic(part_diag) + +# write_inputs will create an inputs file that can be used to run +# with the compiled version. +# sim.write_input_file(file_name = 'inputs_from_PICMI.mr') + +# Alternatively, sim.step will run WarpX, controlling it from Python +sim.step() diff --git a/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_picmi.py b/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_picmi.py new file mode 100755 index 00000000000..d5b99dbed97 --- /dev/null +++ b/Examples/Physics_applications/plasma_acceleration/inputs_test_3d_plasma_acceleration_picmi.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# from warp import picmi + +constants = picmi.constants + +nx = 64 +ny = 64 +nz = 64 + +xmin = -200.0e-6 +xmax = +200.0e-6 +ymin = -200.0e-6 +ymax = +200.0e-6 +zmin = -200.0e-6 +zmax = +200.0e-6 + +moving_window_velocity = [0.0, 0.0, constants.c] + +number_per_cell_each_dim = [2, 2, 1] + +max_steps = 10 + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["periodic", "periodic", "open"], + upper_boundary_conditions=["periodic", "periodic", "open"], + lower_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + upper_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + moving_window_velocity=moving_window_velocity, + warpx_max_grid_size=32, +) + +solver = picmi.ElectromagneticSolver(grid=grid, cfl=1) + +beam_distribution = picmi.UniformDistribution( + density=1.0e23, + lower_bound=[-20.0e-6, -20.0e-6, -150.0e-6], + upper_bound=[+20.0e-6, +20.0e-6, -100.0e-6], + directed_velocity=[0.0, 0.0, 1.0e9], +) + +plasma_distribution = picmi.UniformDistribution( + density=1.0e22, + lower_bound=[-200.0e-6, -200.0e-6, 0.0], + upper_bound=[+200.0e-6, +200.0e-6, None], + fill_in=True, +) + +beam = picmi.Species( + particle_type="electron", name="beam", initial_distribution=beam_distribution +) +plasma = picmi.Species( + particle_type="electron", name="plasma", initial_distribution=plasma_distribution +) + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + warpx_current_deposition_algo="esirkepov", + warpx_use_filter=0, +) + +sim.add_species( + beam, + layout=picmi.GriddedLayout( + grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim + ), +) +sim.add_species( + plasma, + layout=picmi.GriddedLayout( + grid=grid, n_macroparticle_per_cell=number_per_cell_each_dim + ), +) + +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=max_steps, + data_list=["Ex", "Ey", "Ez", "Jx", "Jy", "Jz", "part_per_cell"], +) + +part_diag = picmi.ParticleDiagnostic( + name="diag1", + period=max_steps, + species=[beam, plasma], + data_list=["ux", "uy", "uz", "weighting"], +) + +sim.add_diagnostic(field_diag) +sim.add_diagnostic(part_diag) + +# write_inputs will create an inputs file that can be used to run +# with the compiled version. +# sim.write_input_file(file_name = 'inputs_from_PICMI') + +# Alternatively, sim.step will run WarpX, controlling it from Python +sim.step() diff --git a/Examples/Physics_applications/plasma_mirror/CMakeLists.txt b/Examples/Physics_applications/plasma_mirror/CMakeLists.txt new file mode 100644 index 00000000000..073245f758a --- /dev/null +++ b/Examples/Physics_applications/plasma_mirror/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_plasma_mirror # name + 2 # dims + 2 # nprocs + inputs_test_2d_plasma_mirror # inputs + analysis_default_regression.py # analysis + diags/diag1000020 # output + OFF # dependency +) diff --git a/Examples/Physics_applications/plasma_mirror/README.rst b/Examples/Physics_applications/plasma_mirror/README.rst index 8741db09699..56f1da7db46 100644 --- a/Examples/Physics_applications/plasma_mirror/README.rst +++ b/Examples/Physics_applications/plasma_mirror/README.rst @@ -33,9 +33,9 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. tab-item:: Executable: Input File - .. literalinclude:: inputs_2d + .. literalinclude:: inputs_test_2d_plasma_mirror :language: ini - :caption: You can copy this file from ``Examples/Physics_applications/plasma_mirror/inputs_2d``. + :caption: You can copy this file from ``Examples/Physics_applications/plasma_mirror/inputs_test_2d_plasma_mirror``. Analyze diff --git a/Examples/Physics_applications/plasma_mirror/analysis_default_regression.py b/Examples/Physics_applications/plasma_mirror/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Physics_applications/plasma_mirror/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Physics_applications/plasma_mirror/inputs_2d b/Examples/Physics_applications/plasma_mirror/inputs_test_2d_plasma_mirror similarity index 98% rename from Examples/Physics_applications/plasma_mirror/inputs_2d rename to Examples/Physics_applications/plasma_mirror/inputs_test_2d_plasma_mirror index 714af80affe..c2c67fe928c 100644 --- a/Examples/Physics_applications/plasma_mirror/inputs_2d +++ b/Examples/Physics_applications/plasma_mirror/inputs_test_2d_plasma_mirror @@ -1,8 +1,8 @@ ################################# ####### GENERAL PARAMETERS ###### ################################# -max_step = 1000 -amr.n_cell = 1024 512 +max_step = 20 #1000 +amr.n_cell = 256 128 #1024 512 amr.max_grid_size = 128 amr.blocking_factor = 32 amr.max_level = 0 diff --git a/Examples/Physics_applications/spacecraft_charging/CMakeLists.txt b/Examples/Physics_applications/spacecraft_charging/CMakeLists.txt new file mode 100644 index 00000000000..95349e525cc --- /dev/null +++ b/Examples/Physics_applications/spacecraft_charging/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) +add_warpx_test( + test_rz_spacecraft_charging_picmi # name + RZ # dims + 2 # nprocs + inputs_test_rz_spacecraft_charging_picmi.py # inputs + analysis.py # analysis + diags/diag1/ # output + OFF # dependency +) +endif() diff --git a/Examples/Physics_applications/spacecraft_charging/analysis.py b/Examples/Physics_applications/spacecraft_charging/analysis.py index ef75fd1a10a..8819c435fb7 100755 --- a/Examples/Physics_applications/spacecraft_charging/analysis.py +++ b/Examples/Physics_applications/spacecraft_charging/analysis.py @@ -6,7 +6,7 @@ thermal plasma. The potential on the spacecraft decreases over the time to reach an equilibrium floating potential. -An input Python file PICMI_inputs_rz.py is used. +An input Python file inputs_test_rz_spacecraft_charging_picmi.py is used. The test will check the curve fitting parameters v0 and tau defined by the following exponential function: phi(t)=v0(1-exp(-t/tau)) @@ -22,57 +22,59 @@ from scipy.optimize import curve_fit yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Open plotfile specified in command line filename = sys.argv[1] test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename, output_format='openpmd') +checksumAPI.evaluate_checksum(test_name, filename, output_format="openpmd") -ts = OpenPMDTimeSeries('./spacecraft_charging_plt') +ts = OpenPMDTimeSeries(filename) dt = 1.27e-8 -t=[] -phi=[] +t = [] +phi = [] it = ts.iterations for i in it: - phi_i = ts.get_field('phi',iteration=i,plot=False) + phi_i = ts.get_field("phi", iteration=i, plot=False) # Find the minimum value among all grids for this iteration phi_min = np.min(phi_i[0]) phi.append(phi_min) - t.append(dt*i) + t.append(dt * i) def func(x, v0, tau): - - return v0 * (1-np.exp(-np.array(x) / tau)) - + return v0 * (1 - np.exp(-np.array(x) / tau)) popt, pcov = curve_fit(func, t, phi) -plt.plot(t,phi, label='modelisation') -plt.plot(t, func(t, *popt), 'r-',label='fit: v0=%5.3f, tau=%5.9f' % (popt[0], popt[1])) +plt.plot(t, phi, label="modelisation") +plt.plot(t, func(t, *popt), "r-", label="fit: v0=%5.3f, tau=%5.9f" % (popt[0], popt[1])) plt.legend() -plt.savefig('min_phi_analysis.png') +plt.savefig("min_phi_analysis.png") -print('fit parameters between the min(phi) curve over the time and the function v0(1-exp(-t/tau)):') -print('v0=%5.3f, tau=%5.9f' % (popt[0], popt[1])) +print( + "fit parameters between the min(phi) curve over the time and the function v0(1-exp(-t/tau)):" +) +print("v0=%5.3f, tau=%5.9f" % (popt[0], popt[1])) -tolerance_v0=0.04 -tolerance_tau=0.04 -print("tolerance for v0 = "+ str(tolerance_v0 *100) + '%') -print("tolerance for tau = "+ str(tolerance_tau*100) + '%') +tolerance_v0 = 0.04 +tolerance_tau = 0.04 +print("tolerance for v0 = " + str(tolerance_v0 * 100) + "%") +print("tolerance for tau = " + str(tolerance_tau * 100) + "%") -mean_v0=-151.347 -mean_tau=0.000004351 +mean_v0 = -151.347 +mean_tau = 0.000004351 -diff_v0=np.abs((popt[0]-mean_v0)/mean_v0) -diff_tau=np.abs((popt[1]-mean_tau)/mean_tau) +diff_v0 = np.abs((popt[0] - mean_v0) / mean_v0) +diff_tau = np.abs((popt[1] - mean_tau) / mean_tau) -print("percentage error for v0 = "+ str(diff_v0 *100) + '%') -print("percentage error for tau = "+ str(diff_tau*100) + '%') +print("percentage error for v0 = " + str(diff_v0 * 100) + "%") +print("percentage error for tau = " + str(diff_tau * 100) + "%") -assert (diff_v0 < tolerance_v0) and (diff_tau < tolerance_tau), 'Test spacecraft_charging did not pass' +assert (diff_v0 < tolerance_v0) and ( + diff_tau < tolerance_tau +), "Test spacecraft_charging did not pass" diff --git a/Examples/Physics_applications/spacecraft_charging/PICMI_inputs_rz.py b/Examples/Physics_applications/spacecraft_charging/inputs_test_rz_spacecraft_charging_picmi.py similarity index 55% rename from Examples/Physics_applications/spacecraft_charging/PICMI_inputs_rz.py rename to Examples/Physics_applications/spacecraft_charging/inputs_test_rz_spacecraft_charging_picmi.py index 5b57b59fbe3..e3bc888f600 100644 --- a/Examples/Physics_applications/spacecraft_charging/PICMI_inputs_rz.py +++ b/Examples/Physics_applications/spacecraft_charging/inputs_test_rz_spacecraft_charging_picmi.py @@ -29,9 +29,10 @@ class SpaceChargeFieldCorrector(object): correct field around the spacecraft, at each timestep (taking into account the charge that has been collected on the spacecraft) """ + def __init__(self): self.saved_first_iteration_fields = False - self.spacecraft_potential = 1. # Initial voltage: 1V + self.spacecraft_potential = 1.0 # Initial voltage: 1V self.spacecraft_capacitance = None def correct_space_charge_fields(self, q=None): @@ -49,23 +50,25 @@ def correct_space_charge_fields(self, q=None): # Correct fields so as to recover the actual charge Er = ExWrapper(include_ghosts=True) - Er[...] += (q - q_v)*self.normalized_Er + Er[...] += (q - q_v) * self.normalized_Er Ez = EzWrapper(include_ghosts=True) - Ez[...] += (q - q_v)*self.normalized_Ez + Ez[...] += (q - q_v) * self.normalized_Ez phi = PhiFPWrapper(include_ghosts=True) - phi[...] += (q - q_v)*self.normalized_phi - self.spacecraft_potential += (q - q_v)*self.spacecraft_capacitance - sim.extension.warpx.set_potential_on_eb( "%f" %self.spacecraft_potential ) - print('Setting potential to %f' %self.spacecraft_potential) + phi[...] += (q - q_v) * self.normalized_phi + self.spacecraft_potential += (q - q_v) * self.spacecraft_capacitance + sim.extension.warpx.set_potential_on_eb("%f" % self.spacecraft_potential) + print("Setting potential to %f" % self.spacecraft_potential) # Confirm that the charge on the spacecraft is now correct compute_virtual_charge_on_spacecraft() - def save_normalized_vacuum_Efields(self,): + def save_normalized_vacuum_Efields( + self, + ): # Compute the charge that WarpX thinks there is on the spacecraft # from phi and rho after the Poisson solver q_v = compute_virtual_charge_on_spacecraft() - self.spacecraft_capacitance = 1./q_v # the potential was set to 1V + self.spacecraft_capacitance = 1.0 / q_v # the potential was set to 1V # Check that this iteration corresponded to a vacuum solve rho = RhoFPWrapper(include_ghosts=False) @@ -73,15 +76,15 @@ def save_normalized_vacuum_Efields(self,): # In principle, we should check that `rho` is exactly 0 # However, due to machine precision errors when adding the charge # of ions and electrons, this can be slightly different than 0 - assert np.all( abs(rho[...]) < 1.e-11 ) + assert np.all(abs(rho[...]) < 1.0e-11) # Record fields - Er = ExWrapper(include_ghosts=True)[:,:] - self.normalized_Er = Er[...] /q_v - Ez = EzWrapper(include_ghosts=True)[:,:] - self.normalized_Ez = Ez[...] /q_v - phi = PhiFPWrapper(include_ghosts=True)[:,:] - self.normalized_phi = phi[...] /q_v + Er = ExWrapper(include_ghosts=True)[:, :] + self.normalized_Er = Er[...] / q_v + Ez = EzWrapper(include_ghosts=True)[:, :] + self.normalized_Ez = Ez[...] / q_v + phi = PhiFPWrapper(include_ghosts=True)[:, :] + self.normalized_phi = phi[...] / q_v self.saved_first_iteration_fields = True self.correct_space_charge_fields(q=0) @@ -95,33 +98,39 @@ def compute_virtual_charge_on_spacecraft(): that WarpX thinks there should be on the spacecraft. """ # Get global array for the whole domain (across MPI ranks) - phi = PhiFPWrapper(include_ghosts=False)[:,:] - rho = RhoFPWrapper(include_ghosts=False)[:,:] + phi = PhiFPWrapper(include_ghosts=False)[:, :] + rho = RhoFPWrapper(include_ghosts=False)[:, :] # Check that this codes correspond to the global size of the box - assert phi.shape == (nr+1, nz+1) - assert rho.shape == (nr+1, nz+1) + assert phi.shape == (nr + 1, nz + 1) + assert rho.shape == (nr + 1, nz + 1) dr, dz = sim.extension.warpx.Geom(lev=0).data().CellSize() # Compute integral of grad phi over surfaces of the domain - r = np.linspace(rmin, rmax, len(phi), endpoint=False) + (rmax - rmin) / (2 * len(phi)) #shift of the r points because the derivaties are calculated in the middle - face_z0 = 2 * np.pi * 1./dz * ( (phi[:,0]-phi[:,1]) * r ).sum() * dr #here I am assuming that phi is a numpy array that can handle elementwise mult - face_zend = 2 * np.pi * 1./dz * ( (phi[:,-1]-phi[:,-2]) * r ).sum() * dr - face_rend = 2 * np.pi * 1./dr*((phi[-1,:]-phi[-2,:]) * rmax).sum() * dz + r = np.linspace(rmin, rmax, len(phi), endpoint=False) + (rmax - rmin) / ( + 2 * len(phi) + ) # shift of the r points because the derivaties are calculated in the middle + face_z0 = ( + 2 * np.pi * 1.0 / dz * ((phi[:, 0] - phi[:, 1]) * r).sum() * dr + ) # here I am assuming that phi is a numpy array that can handle elementwise mult + face_zend = 2 * np.pi * 1.0 / dz * ((phi[:, -1] - phi[:, -2]) * r).sum() * dr + face_rend = 2 * np.pi * 1.0 / dr * ((phi[-1, :] - phi[-2, :]) * rmax).sum() * dz grad_phi_integral = face_z0 + face_zend + face_rend # Compute integral of rho over volume of the domain # (i.e. total charge of the plasma particles) - rho_integral = (rho[1:nr-1,1:nz-1] * r[1:nr-1,np.newaxis]).sum()*dr*dz + rho_integral = ( + (rho[1 : nr - 1, 1 : nz - 1] * r[1 : nr - 1, np.newaxis]).sum() * dr * dz + ) # Due to an oddity in WarpX (which will probably be solved later) # we need to multiply `rho` by `-epsilon_0` to get the correct charge - rho_integral *= 2 * np.pi * -scc.epsilon_0 #does this oddity still exist? + rho_integral *= 2 * np.pi * -scc.epsilon_0 # does this oddity still exist? # Compute charge of the spacecraft, based on Gauss theorem - q_spacecraft = - rho_integral - scc.epsilon_0 * grad_phi_integral - print('Virtual charge on the spacecraft: %e' %q_spacecraft) + q_spacecraft = -rho_integral - scc.epsilon_0 * grad_phi_integral + print("Virtual charge on the spacecraft: %e" % q_spacecraft) return q_spacecraft @@ -131,19 +140,19 @@ def compute_actual_charge_on_spacecraft(): by counting how many electrons and protons were collected by the WarpX embedded boundary (EB) """ - charge = {'electrons': -scc.e, 'protons': scc.e} + charge = {"electrons": -scc.e, "protons": scc.e} q_spacecraft = 0 particle_buffer = ParticleBoundaryBufferWrapper() for species in charge.keys(): - weights = particle_buffer.get_particle_boundary_buffer(species, 'eb', 'w', 0) + weights = particle_buffer.get_particle_boundary_buffer(species, "eb", "w", 0) sum_weights_over_tiles = sum([w.sum() for w in weights]) # Reduce across all MPI ranks ntot = float(mpi.COMM_WORLD.allreduce(sum_weights_over_tiles, op=mpi.SUM)) - print('Total number of %s collected on spacecraft: %e'%(species, ntot)) + print("Total number of %s collected on spacecraft: %e" % (species, ntot)) q_spacecraft += ntot * charge[species] - print('Actual charge on the spacecraft: %e' %q_spacecraft) + print("Actual charge on the spacecraft: %e" % q_spacecraft) return q_spacecraft @@ -151,7 +160,7 @@ def compute_actual_charge_on_spacecraft(): # numerics parameters ########################## -dt=1.27e-8 +dt = 1.27e-8 # --- Nb time steps max_steps = 1000 @@ -159,54 +168,62 @@ def compute_actual_charge_on_spacecraft(): # --- grid nr = 40 -nz= 80 +nz = 80 rmin = 0.0 rmax = 3 zmin = -3 zmax = 3 -number_per_cell =5 -number_per_cell_each_dim = [10,1, 1] +number_per_cell = 5 +number_per_cell_each_dim = [10, 1, 1] ########################## # physics components ########################## -n = 7.0e9 #plasma density #particles/m^3 -Te = 85 #Electron temp in eV -Ti = 0.05 * Te #Ion temp in eV -qe = picmi.constants.q_e #elementary charge -m_e = picmi.constants.m_e #electron mass -m_i = 1836.0 * m_e #mass of ion +n = 7.0e9 # plasma density #particles/m^3 +Te = 85 # Electron temp in eV +Ti = 0.05 * Te # Ion temp in eV +qe = picmi.constants.q_e # elementary charge +m_e = picmi.constants.m_e # electron mass +m_i = 1836.0 * m_e # mass of ion v_eth = (qe * Te / m_e) ** 0.5 v_pth = (qe * Ti / m_i) ** 0.5 # nothing to change in the distribution function? -e_dist = picmi.UniformDistribution(density = n, rms_velocity=[v_eth, v_eth, v_eth] ) +e_dist = picmi.UniformDistribution(density=n, rms_velocity=[v_eth, v_eth, v_eth]) e_dist2 = picmi.UniformFluxDistribution( - flux=n*v_eth/(2*np.pi)**.5, # Flux for Gaussian with vmean=0 + flux=n * v_eth / (2 * np.pi) ** 0.5, # Flux for Gaussian with vmean=0 surface_flux_position=3, - flux_direction=-1, flux_normal_axis='r', + flux_direction=-1, + flux_normal_axis="r", gaussian_flux_momentum_distribution=True, - rms_velocity=[v_eth, v_eth, v_eth] ) -electrons = picmi.Species(particle_type='electron', - name='electrons', - initial_distribution=[e_dist,e_dist2], - warpx_save_particles_at_eb=1) + rms_velocity=[v_eth, v_eth, v_eth], +) +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=[e_dist, e_dist2], + warpx_save_particles_at_eb=1, +) -p_dist = picmi.UniformDistribution(density = n, rms_velocity=[v_pth, v_pth, v_pth] ) +p_dist = picmi.UniformDistribution(density=n, rms_velocity=[v_pth, v_pth, v_pth]) p_dist2 = picmi.UniformFluxDistribution( - flux=n*v_pth/(2*np.pi)**.5, # Flux for Gaussian with vmean=0 + flux=n * v_pth / (2 * np.pi) ** 0.5, # Flux for Gaussian with vmean=0 surface_flux_position=3, - flux_direction=-1, flux_normal_axis='r', + flux_direction=-1, + flux_normal_axis="r", gaussian_flux_momentum_distribution=True, - rms_velocity=[v_pth, v_pth, v_pth] ) -protons = picmi.Species(particle_type='proton', - name='protons', - initial_distribution=[p_dist,p_dist2], - warpx_save_particles_at_eb=1) + rms_velocity=[v_pth, v_pth, v_pth], +) +protons = picmi.Species( + particle_type="proton", + name="protons", + initial_distribution=[p_dist, p_dist2], + warpx_save_particles_at_eb=1, +) ########################## @@ -214,25 +231,24 @@ def compute_actual_charge_on_spacecraft(): ########################## grid = picmi.CylindricalGrid( - number_of_cells = [nr, nz], - n_azimuthal_modes = 1, - lower_bound = [rmin, zmin], - upper_bound = [rmax, zmax], - lower_boundary_conditions = ['none', 'dirichlet'], - upper_boundary_conditions = ['dirichlet', 'dirichlet'], - lower_boundary_conditions_particles = ['none', 'reflecting'], - upper_boundary_conditions_particles = ['absorbing', 'reflecting'] + number_of_cells=[nr, nz], + n_azimuthal_modes=1, + lower_bound=[rmin, zmin], + upper_bound=[rmax, zmax], + lower_boundary_conditions=["none", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["none", "reflecting"], + upper_boundary_conditions_particles=["absorbing", "reflecting"], ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', - warpx_absolute_tolerance=1e-7 + grid=grid, method="Multigrid", warpx_absolute_tolerance=1e-7 ) embedded_boundary = picmi.EmbeddedBoundary( implicit_function="-(x**2+y**2+z**2-radius**2)", - potential=1., # arbitrary value ; this will be corrected by a callback function - radius = 0.3277 + potential=1.0, # arbitrary value ; this will be corrected by a callback function + radius=0.3277, ) @@ -241,22 +257,25 @@ def compute_actual_charge_on_spacecraft(): ########################## field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = diagnostic_interval, - data_list = ['Er', 'Ez', 'phi', 'rho', - 'rho_electrons', 'rho_protons'], - warpx_format = 'openpmd', - write_dir = '.', - warpx_file_prefix = 'spacecraft_charging_plt' + name="diag1", + grid=grid, + period=diagnostic_interval, + data_list=["Er", "Ez", "phi", "rho", "rho_electrons", "rho_protons"], + warpx_format="openpmd", +) + +part_diag = picmi.ParticleDiagnostic( + name="diag1", + period=diagnostic_interval, + species=[electrons, protons], + warpx_format="openpmd", ) -part_diag = picmi.ParticleDiagnostic(name = 'diag1', - period = diagnostic_interval, - species = [electrons, protons], - warpx_format = 'openpmd', - write_dir = '.', - warpx_file_prefix = 'spacecraft_charging_plt' +part_scraping_boundary_diag = picmi.ParticleBoundaryScrapingDiagnostic( + name="diag2", + period=-1, # only at the end, because we also use the buffers in this test + species=[electrons, protons], + warpx_format="openpmd", ) ########################## @@ -264,26 +283,25 @@ def compute_actual_charge_on_spacecraft(): ########################## sim = picmi.Simulation( - solver = solver, - time_step_size = dt, - max_steps = max_steps, + solver=solver, + time_step_size=dt, + max_steps=max_steps, warpx_embedded_boundary=embedded_boundary, warpx_amrex_the_arena_is_managed=1, - warpx_random_seed=1 + warpx_random_seed=1, ) -layout1=picmi.GriddedLayout(n_macroparticle_per_cell=number_per_cell_each_dim, - grid=grid) -layout2=picmi.PseudoRandomLayout(n_macroparticles_per_cell=number_per_cell, - grid=grid) -sim.add_species(electrons, - layout = [layout1,layout2]) +layout1 = picmi.GriddedLayout( + n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid +) +layout2 = picmi.PseudoRandomLayout(n_macroparticles_per_cell=number_per_cell, grid=grid) +sim.add_species(electrons, layout=[layout1, layout2]) -sim.add_species(protons, - layout = [layout1,layout2]) +sim.add_species(protons, layout=[layout1, layout2]) sim.add_diagnostic(field_diag) sim.add_diagnostic(part_diag) +sim.add_diagnostic(part_scraping_boundary_diag) ########################## # simulation run @@ -291,7 +309,7 @@ def compute_actual_charge_on_spacecraft(): spc = SpaceChargeFieldCorrector() -installafterInitEsolve( spc.save_normalized_vacuum_Efields ) -installafterEsolve( spc.correct_space_charge_fields ) +installafterInitEsolve(spc.save_normalized_vacuum_Efields) +installafterEsolve(spc.correct_space_charge_fields) sim.step(max_steps) diff --git a/Examples/Physics_applications/uniform_plasma/CMakeLists.txt b/Examples/Physics_applications/uniform_plasma/CMakeLists.txt new file mode 100644 index 00000000000..79dec989c1f --- /dev/null +++ b/Examples/Physics_applications/uniform_plasma/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_uniform_plasma # name + 2 # dims + 2 # nprocs + inputs_test_2d_uniform_plasma # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +add_warpx_test( + test_3d_uniform_plasma # name + 3 # dims + 2 # nprocs + inputs_test_3d_uniform_plasma # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +add_warpx_test( + test_3d_uniform_plasma_restart # name + 3 # dims + 2 # nprocs + inputs_test_3d_uniform_plasma_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000010 # output + test_3d_uniform_plasma # dependency +) diff --git a/Examples/Physics_applications/uniform_plasma/README.rst b/Examples/Physics_applications/uniform_plasma/README.rst index 50d132712c6..04a0fb4555c 100644 --- a/Examples/Physics_applications/uniform_plasma/README.rst +++ b/Examples/Physics_applications/uniform_plasma/README.rst @@ -21,15 +21,15 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. note:: - TODO: This input file should be created following the ``inputs_3d`` file. + TODO: This input file should be created following the ``inputs_test_3d_uniform_plasma`` file. .. tab-item:: Executable: Input File - This example can be run **either** as WarpX **executable** using an input file: ``warpx.3d inputs_3d`` + This example can be run **either** as WarpX **executable** using an input file: ``warpx.3d inputs_test_3d_uniform_plasma`` - .. literalinclude:: inputs_3d + .. literalinclude:: inputs_test_3d_uniform_plasma :language: ini - :caption: You can copy this file from ``usage/examples/lwfa/inputs_3d``. + :caption: You can copy this file from ``usage/examples/lwfa/inputs_test_3d_uniform_plasma``. .. tab-item:: 2D @@ -39,15 +39,15 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. note:: - TODO: This input file should be created following the ``inputs_2d`` file. + TODO: This input file should be created following the ``inputs_test_2d_uniform_plasma`` file. .. tab-item:: Executable: Input File - This example can be run **either** as WarpX **executable** using an input file: ``warpx.2d inputs_2d`` + This example can be run **either** as WarpX **executable** using an input file: ``warpx.2d inputs_test_2d_uniform_plasma`` - .. literalinclude:: inputs_2d + .. literalinclude:: inputs_test_2d_uniform_plasma :language: ini - :caption: You can copy this file from ``usage/examples/lwfa/inputs_2d``. + :caption: You can copy this file from ``usage/examples/lwfa/inputs_test_2d_uniform_plasma``. Analyze ------- diff --git a/Examples/Physics_applications/uniform_plasma/analysis_default_regression.py b/Examples/Physics_applications/uniform_plasma/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Physics_applications/uniform_plasma/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Physics_applications/uniform_plasma/analysis_default_restart.py b/Examples/Physics_applications/uniform_plasma/analysis_default_restart.py new file mode 120000 index 00000000000..0459986eebc --- /dev/null +++ b/Examples/Physics_applications/uniform_plasma/analysis_default_restart.py @@ -0,0 +1 @@ +../../analysis_default_restart.py \ No newline at end of file diff --git a/Examples/Physics_applications/uniform_plasma/inputs_3d b/Examples/Physics_applications/uniform_plasma/inputs_base_3d similarity index 100% rename from Examples/Physics_applications/uniform_plasma/inputs_3d rename to Examples/Physics_applications/uniform_plasma/inputs_base_3d diff --git a/Examples/Physics_applications/uniform_plasma/inputs_2d b/Examples/Physics_applications/uniform_plasma/inputs_test_2d_uniform_plasma similarity index 100% rename from Examples/Physics_applications/uniform_plasma/inputs_2d rename to Examples/Physics_applications/uniform_plasma/inputs_test_2d_uniform_plasma diff --git a/Examples/Physics_applications/uniform_plasma/inputs_test_3d_uniform_plasma b/Examples/Physics_applications/uniform_plasma/inputs_test_3d_uniform_plasma new file mode 100644 index 00000000000..7665a846eef --- /dev/null +++ b/Examples/Physics_applications/uniform_plasma/inputs_test_3d_uniform_plasma @@ -0,0 +1,2 @@ +# base input parameters +FILE = inputs_base_3d diff --git a/Examples/Physics_applications/uniform_plasma/inputs_test_3d_uniform_plasma_restart b/Examples/Physics_applications/uniform_plasma/inputs_test_3d_uniform_plasma_restart new file mode 100644 index 00000000000..4711ece3843 --- /dev/null +++ b/Examples/Physics_applications/uniform_plasma/inputs_test_3d_uniform_plasma_restart @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_test_3d_uniform_plasma + +# test input parameters +amr.restart = "../test_3d_uniform_plasma/diags/chk000006" diff --git a/Examples/Tests/AcceleratorLattice/analysis.py b/Examples/Tests/AcceleratorLattice/analysis.py deleted file mode 100755 index 5f3de4543d6..00000000000 --- a/Examples/Tests/AcceleratorLattice/analysis.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2022 David Grote -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - - -""" -This script tests the quad lattice -The input file sets up a series of quadrupoles and propagates two particles through them. -One particle is in the X plane, the other the Y plane. -The final positions are compared to the analytic solutions. -The motion is slow enough that relativistic effects are ignored. -""" - -import os -import sys - -import numpy as np -import yt -from scipy.constants import c, e, m_e - -yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -filename = sys.argv[1] -ds = yt.load( filename ) -ad = ds.all_data() - -gamma_boost = float(ds.parameters.get('warpx.gamma_boost', 1.)) -uz_boost = np.sqrt(gamma_boost*gamma_boost - 1.)*c - -# Fetch the final particle position -xx_sim = ad['electron', 'particle_position_x'].v[0] -zz_sim = ad['electron', 'particle_position_z'].v[0] -ux_sim = ad['electron', 'particle_momentum_x'].v[0]/m_e - -if gamma_boost > 1.: - # The simulation data is in the boosted frame. - # Transform the z position to the lab frame. - time = ds.current_time.value - zz_sim = gamma_boost*zz_sim + uz_boost*time; - -# Fetch the quadrupole lattice data -quad_starts = [] -quad_lengths = [] -quad_strengths_E = [] -z_location = 0. -def read_lattice(rootname, z_location): - lattice_elements = ds.parameters.get(f'{rootname}.elements').split() - for element in lattice_elements: - element_type = ds.parameters.get(f'{element}.type') - if element_type == 'drift': - length = float(ds.parameters.get(f'{element}.ds')) - z_location += length - elif element_type == 'quad': - length = float(ds.parameters.get(f'{element}.ds')) - quad_starts.append(z_location) - quad_lengths.append(length) - quad_strengths_E.append(float(ds.parameters.get(f'{element}.dEdx'))) - z_location += length - elif element_type == 'line': - z_location = read_lattice(element, z_location) - return z_location - -read_lattice('lattice', z_location) - -# Fetch the initial position of the particle -x0 = [float(x) for x in ds.parameters.get('electron.single_particle_pos').split()] -ux0 = [float(x)*c for x in ds.parameters.get('electron.single_particle_u').split()] - -xx = x0[0] -zz = x0[2] -ux = ux0[0] -uz = ux0[2] - -gamma = np.sqrt(uz**2/c**2 + 1.) -vz = uz/gamma - -def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength): - """Use analytic solution of a particle with a transverse dependent field""" - kb0 = np.sqrt(e/(m_e*gamma*vz0**2)*abs(lens_strength)) - if lens_strength >= 0.: - x1 = x0*np.cos(kb0*lens_length) + (vx0/vz0)/kb0*np.sin(kb0*lens_length) - vx1 = vz0*(-kb0*x0*np.sin(kb0*lens_length) + (vx0/vz0)*np.cos(kb0*lens_length)) - else: - x1 = x0*np.cosh(kb0*lens_length) + (vx0/vz0)/kb0*np.sinh(kb0*lens_length) - vx1 = vz0*(+kb0*x0*np.sinh(kb0*lens_length) + (vx0/vz0)*np.cosh(kb0*lens_length)) - return x1, vx1 - -# Integrate the particle using the analytic solution -for i in range(len(quad_starts)): - z_lens = quad_starts[i] - vx = ux/gamma - dt = (z_lens - zz)/vz - xx = xx + dt*vx - xx, vx = applylens(xx, vx, vz, gamma, quad_lengths[i], quad_strengths_E[i]) - ux = gamma*vx - zz = z_lens + quad_lengths[i] - -dt = (zz_sim - zz)/vz -vx = ux/gamma -xx = xx + dt*vx - -# Compare the analytic to the simulated final values -print(f'Error in x position is {abs(np.abs((xx - xx_sim)/xx))}, which should be < 0.01') -print(f'Error in x velocity is {abs(np.abs((ux - ux_sim)/ux))}, which should be < 0.002') - -assert abs(np.abs((xx - xx_sim)/xx)) < 0.01, Exception('error in x particle position') -assert abs(np.abs((ux - ux_sim)/ux)) < 0.002, Exception('error in x particle velocity') - -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/CMakeLists.txt b/Examples/Tests/CMakeLists.txt new file mode 100644 index 00000000000..6fea9368e78 --- /dev/null +++ b/Examples/Tests/CMakeLists.txt @@ -0,0 +1,78 @@ +# Add tests (alphabetical order) ############################################## +# + +add_subdirectory(accelerator_lattice) +add_subdirectory(boosted_diags) +add_subdirectory(boundaries) +add_subdirectory(btd_rz) +add_subdirectory(collider_relevant_diags) +add_subdirectory(collision) +add_subdirectory(diff_lumi_diag) +add_subdirectory(divb_cleaning) +add_subdirectory(dive_cleaning) +add_subdirectory(electrostatic_dirichlet_bc) +add_subdirectory(electrostatic_sphere) +add_subdirectory(electrostatic_sphere_eb) +add_subdirectory(embedded_boundary_cube) +add_subdirectory(embedded_boundary_diffraction) +add_subdirectory(embedded_boundary_python_api) +add_subdirectory(embedded_boundary_rotated_cube) +add_subdirectory(embedded_circle) +add_subdirectory(energy_conserving_thermal_plasma) +add_subdirectory(field_probe) +add_subdirectory(flux_injection) +add_subdirectory(gaussian_beam) +add_subdirectory(implicit) +add_subdirectory(initial_distribution) +add_subdirectory(initial_plasma_profile) +add_subdirectory(field_ionization) +add_subdirectory(ion_stopping) +add_subdirectory(langmuir) +add_subdirectory(langmuir_fluids) +add_subdirectory(larmor) +add_subdirectory(laser_injection) +add_subdirectory(laser_injection_from_file) +add_subdirectory(laser_on_fine) +add_subdirectory(load_external_field) +add_subdirectory(magnetostatic_eb) +add_subdirectory(maxwell_hybrid_qed) +add_subdirectory(nci_fdtd_stability) +add_subdirectory(nci_psatd_stability) +add_subdirectory(nodal_electrostatic) +add_subdirectory(nuclear_fusion) +add_subdirectory(ohm_solver_em_modes) +add_subdirectory(ohm_solver_ion_beam_instability) +add_subdirectory(ohm_solver_ion_Landau_damping) +add_subdirectory(ohm_solver_magnetic_reconnection) +add_subdirectory(open_bc_poisson_solver) +add_subdirectory(particle_boundary_interaction) +add_subdirectory(particle_boundary_process) +add_subdirectory(particle_boundary_scrape) +add_subdirectory(particle_data_python) +add_subdirectory(particle_fields_diags) +add_subdirectory(particle_pusher) +add_subdirectory(particle_thermal_boundary) +add_subdirectory(particles_in_pml) +add_subdirectory(pass_mpi_communicator) +add_subdirectory(pec) +add_subdirectory(photon_pusher) +add_subdirectory(plasma_lens) +add_subdirectory(pml) +add_subdirectory(point_of_contact_eb) +add_subdirectory(projection_divb_cleaner) +add_subdirectory(python_wrappers) +add_subdirectory(qed) +add_subdirectory(radiation_reaction) +add_subdirectory(reduced_diags) +add_subdirectory(relativistic_space_charge_initialization) +add_subdirectory(repelling_particles) +add_subdirectory(resampling) +add_subdirectory(restart) +add_subdirectory(restart_eb) +add_subdirectory(rigid_injection) +add_subdirectory(scraping) +add_subdirectory(silver_mueller) +add_subdirectory(single_particle) +add_subdirectory(space_charge_initialization) +add_subdirectory(subcycling) +add_subdirectory(vay_deposition) diff --git a/Examples/Tests/LoadExternalField/PICMI_inputs_3d_grid_fields.py b/Examples/Tests/LoadExternalField/PICMI_inputs_3d_grid_fields.py deleted file mode 100644 index d128d9c10e0..00000000000 --- a/Examples/Tests/LoadExternalField/PICMI_inputs_3d_grid_fields.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python3 -# -# --- Input file for loading initial field from openPMD file. - -from pywarpx import picmi - -constants = picmi.constants - -################################# -####### GENERAL PARAMETERS ###### -################################# - -max_steps = 300 - -max_grid_size = 40 -nx = max_grid_size -ny = max_grid_size -nz = max_grid_size - -xmin = -1 -xmax = 1 -ymin = xmin -ymax = xmax -zmin = 0 -zmax = 5 - -number_per_cell = 200 - -################################# -############ NUMERICS ########### -################################# - -verbose = 1 -dt = 4.4e-7 -use_filter = 0 - -# Order of particle shape factors -particle_shape = 1 - -################################# -############ PLASMA ############# -################################# - -ion_dist = picmi.ParticleListDistribution( - x=0.0, - y=0.2, - z=2.5, - ux=9.5e-05*constants.c, - uy=0.0*constants.c, - uz=1.34e-4*constants.c, - weight=1.0 - ) - -ions = picmi.Species( - particle_type='H', - name='proton', charge='q_e',mass="m_p", - warpx_do_not_deposit=1, - initial_distribution=ion_dist - ) - -################################# -######## INITIAL FIELD ########## -################################# - -initial_field = picmi.LoadInitialField( - read_fields_from_path="../../../../openPMD-example-datasets/example-femm-3d.h5", - load_E=False - ) - -################################# -###### GRID AND SOLVER ########## -################################# - -grid = picmi.Cartesian3DGrid( - number_of_cells=[nx, ny, nz], - warpx_max_grid_size=max_grid_size, - lower_bound=[xmin, ymin, zmin], - upper_bound=[xmax, ymax, zmax], - lower_boundary_conditions=['dirichlet', 'dirichlet', 'dirichlet'], - upper_boundary_conditions=['dirichlet', 'dirichlet', 'dirichlet'], - lower_boundary_conditions_particles=['absorbing', 'absorbing', 'absorbing'], - upper_boundary_conditions_particles=['absorbing', 'absorbing', 'absorbing'] - ) -solver = picmi.ElectrostaticSolver(grid=grid) - -################################# -######### DIAGNOSTICS ########### -################################# - -particle_diag = picmi.ParticleDiagnostic( - name='diag1', - period=300, - species=[ions], - data_list = ['ux', 'uy', 'uz', 'x', 'y', 'z', 'weighting'], - write_dir='.', - warpx_file_prefix='Python_LoadExternalGridField3D_plt' - ) -field_diag = picmi.FieldDiagnostic( - name='diag1', - grid=grid, - period=300, - data_list = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], - write_dir='.', - warpx_file_prefix='Python_LoadExternalGridField3D_plt' - ) - -################################# -####### SIMULATION SETUP ######## -################################# - -sim = picmi.Simulation( - solver=solver, - max_steps=max_steps, - verbose=verbose, - warpx_serialize_initial_conditions=False, - warpx_grid_type='collocated', - warpx_do_dynamic_scheduling=False, - warpx_use_filter=use_filter, - time_step_size=dt, - particle_shape=particle_shape - ) - -sim.add_applied_field(initial_field) - -sim.add_species( - ions, - layout=picmi.PseudoRandomLayout( - n_macroparticles_per_cell=number_per_cell, grid=grid - ) - ) - -sim.add_diagnostic(field_diag) -sim.add_diagnostic(particle_diag) - -################################# -##### SIMULATION EXECUTION ###### -################################# - -#sim.write_input_file('PICMI_inputs_3d') -sim.step(max_steps) diff --git a/Examples/Tests/LoadExternalField/PICMI_inputs_3d_particle_fields.py b/Examples/Tests/LoadExternalField/PICMI_inputs_3d_particle_fields.py deleted file mode 100644 index 7bf7c5a084c..00000000000 --- a/Examples/Tests/LoadExternalField/PICMI_inputs_3d_particle_fields.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python3 -# -# --- Input file for loading initial field from openPMD file. - -from pywarpx import picmi - -constants = picmi.constants - -################################# -####### GENERAL PARAMETERS ###### -################################# - -max_steps = 300 - -max_grid_size = 40 -nx = max_grid_size -ny = max_grid_size -nz = max_grid_size - -xmin = -1 -xmax = 1 -ymin = xmin -ymax = xmax -zmin = 0 -zmax = 5 - -number_per_cell = 200 - -################################# -############ NUMERICS ########### -################################# - -verbose = 1 -dt = 4.4e-7 -use_filter = 0 - -# Order of particle shape factors -particle_shape = 1 - -################################# -############ PLASMA ############# -################################# - -ion_dist = picmi.ParticleListDistribution( - x=0.0, - y=0.2, - z=2.5, - ux=9.5e-05*constants.c, - uy=0.0*constants.c, - uz=1.34e-4*constants.c, - weight=1.0 - ) - -ions = picmi.Species( - particle_type='H', - name='proton', charge='q_e',mass="m_p", - warpx_do_not_deposit=1, - initial_distribution=ion_dist - ) - -################################# -######## INITIAL FIELD ########## -################################# - -applied_field = picmi.LoadAppliedField( - read_fields_from_path="../../../../openPMD-example-datasets/example-femm-3d.h5", - load_E=False - ) - -################################# -###### GRID AND SOLVER ########## -################################# - -grid = picmi.Cartesian3DGrid( - number_of_cells=[nx, ny, nz], - warpx_max_grid_size=max_grid_size, - lower_bound=[xmin, ymin, zmin], - upper_bound=[xmax, ymax, zmax], - lower_boundary_conditions=['dirichlet', 'dirichlet', 'dirichlet'], - upper_boundary_conditions=['dirichlet', 'dirichlet', 'dirichlet'], - lower_boundary_conditions_particles=['absorbing', 'absorbing', 'absorbing'], - upper_boundary_conditions_particles=['absorbing', 'absorbing', 'absorbing'] - ) -solver = picmi.ElectrostaticSolver(grid=grid) - -################################# -######### DIAGNOSTICS ########### -################################# - -particle_diag = picmi.ParticleDiagnostic( - name='diag1', - period=300, - species=[ions], - data_list = ['ux', 'uy', 'uz', 'x', 'y', 'z', 'weighting'], - write_dir='.', - warpx_file_prefix='Python_LoadExternalParticleField3D_plt' - ) -field_diag = picmi.FieldDiagnostic( - name='diag1', - grid=grid, - period=300, - data_list = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], - write_dir='.', - warpx_file_prefix='Python_LoadExternalParticleField3D_plt' - ) - -################################# -####### SIMULATION SETUP ######## -################################# - -sim = picmi.Simulation( - solver=solver, - max_steps=max_steps, - verbose=verbose, - warpx_serialize_initial_conditions=False, - warpx_grid_type='collocated', - warpx_do_dynamic_scheduling=False, - warpx_use_filter=use_filter, - time_step_size=dt, - particle_shape=particle_shape - ) - -sim.add_applied_field(applied_field) - -sim.add_species( - ions, - layout=picmi.PseudoRandomLayout( - n_macroparticles_per_cell=number_per_cell, grid=grid - ) - ) - -sim.add_diagnostic(field_diag) -sim.add_diagnostic(particle_diag) - -################################# -##### SIMULATION EXECUTION ###### -################################# - -#sim.write_input_file('PICMI_inputs_3d') -sim.step(max_steps) diff --git a/Examples/Tests/accelerator_lattice/CMakeLists.txt b/Examples/Tests/accelerator_lattice/CMakeLists.txt new file mode 100644 index 00000000000..f3a28d30d4a --- /dev/null +++ b/Examples/Tests/accelerator_lattice/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_hard_edged_quadrupoles # name + 3 # dims + 2 # nprocs + inputs_test_3d_hard_edged_quadrupoles # inputs + analysis.py # analysis + diags/diag1000050 # output + OFF # dependency +) + +add_warpx_test( + test_3d_hard_edged_quadrupoles_boosted # name + 3 # dims + 2 # nprocs + inputs_test_3d_hard_edged_quadrupoles_boosted # inputs + analysis.py # analysis + diags/diag1000050 # output + OFF # dependency +) + +add_warpx_test( + test_3d_hard_edged_quadrupoles_moving # name + 3 # dims + 2 # nprocs + inputs_test_3d_hard_edged_quadrupoles_moving # inputs + analysis.py # analysis + diags/diag1000050 # output + OFF # dependency +) diff --git a/Examples/Tests/accelerator_lattice/analysis.py b/Examples/Tests/accelerator_lattice/analysis.py new file mode 100755 index 00000000000..6f76fd86855 --- /dev/null +++ b/Examples/Tests/accelerator_lattice/analysis.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 + +# Copyright 2022 David Grote +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +""" +This script tests the quad lattice +The input file sets up a series of quadrupoles and propagates two particles through them. +One particle is in the X plane, the other the Y plane. +The final positions are compared to the analytic solutions. +The motion is slow enough that relativistic effects are ignored. +""" + +import os +import sys + +import numpy as np +import yt +from scipy.constants import c, e, m_e + +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +filename = sys.argv[1] +ds = yt.load(filename) +ad = ds.all_data() + +gamma_boost = float(ds.parameters.get("warpx.gamma_boost", 1.0)) +uz_boost = np.sqrt(gamma_boost * gamma_boost - 1.0) * c + +# Fetch the final particle position +xx_sim = ad["electron", "particle_position_x"].v[0] +zz_sim = ad["electron", "particle_position_z"].v[0] +ux_sim = ad["electron", "particle_momentum_x"].v[0] / m_e + +if gamma_boost > 1.0: + # The simulation data is in the boosted frame. + # Transform the z position to the lab frame. + time = ds.current_time.value + zz_sim = gamma_boost * zz_sim + uz_boost * time + +# Fetch the quadrupole lattice data +quad_starts = [] +quad_lengths = [] +quad_strengths_E = [] +z_location = 0.0 + + +def read_lattice(rootname, z_location): + lattice_elements = ds.parameters.get(f"{rootname}.elements").split() + for element in lattice_elements: + element_type = ds.parameters.get(f"{element}.type") + if element_type == "drift": + length = float(ds.parameters.get(f"{element}.ds")) + z_location += length + elif element_type == "quad": + length = float(ds.parameters.get(f"{element}.ds")) + quad_starts.append(z_location) + quad_lengths.append(length) + quad_strengths_E.append(float(ds.parameters.get(f"{element}.dEdx"))) + z_location += length + elif element_type == "line": + z_location = read_lattice(element, z_location) + return z_location + + +read_lattice("lattice", z_location) + +# Fetch the initial position of the particle +x0 = [float(x) for x in ds.parameters.get("electron.single_particle_pos").split()] +ux0 = [float(x) * c for x in ds.parameters.get("electron.single_particle_u").split()] + +xx = x0[0] +zz = x0[2] +ux = ux0[0] +uz = ux0[2] + +gamma = np.sqrt(uz**2 / c**2 + 1.0) +vz = uz / gamma + + +def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength): + """Use analytic solution of a particle with a transverse dependent field""" + kb0 = np.sqrt(e / (m_e * gamma * vz0**2) * abs(lens_strength)) + if lens_strength >= 0.0: + x1 = x0 * np.cos(kb0 * lens_length) + (vx0 / vz0) / kb0 * np.sin( + kb0 * lens_length + ) + vx1 = vz0 * ( + -kb0 * x0 * np.sin(kb0 * lens_length) + + (vx0 / vz0) * np.cos(kb0 * lens_length) + ) + else: + x1 = x0 * np.cosh(kb0 * lens_length) + (vx0 / vz0) / kb0 * np.sinh( + kb0 * lens_length + ) + vx1 = vz0 * ( + +kb0 * x0 * np.sinh(kb0 * lens_length) + + (vx0 / vz0) * np.cosh(kb0 * lens_length) + ) + return x1, vx1 + + +# Integrate the particle using the analytic solution +for i in range(len(quad_starts)): + z_lens = quad_starts[i] + vx = ux / gamma + dt = (z_lens - zz) / vz + xx = xx + dt * vx + xx, vx = applylens(xx, vx, vz, gamma, quad_lengths[i], quad_strengths_E[i]) + ux = gamma * vx + zz = z_lens + quad_lengths[i] + +dt = (zz_sim - zz) / vz +vx = ux / gamma +xx = xx + dt * vx + +# Compare the analytic to the simulated final values +print(f"Error in x position is {abs(np.abs((xx - xx_sim)/xx))}, which should be < 0.01") +print( + f"Error in x velocity is {abs(np.abs((ux - ux_sim)/ux))}, which should be < 0.002" +) + +assert abs(np.abs((xx - xx_sim) / xx)) < 0.01, Exception("error in x particle position") +assert abs(np.abs((ux - ux_sim) / ux)) < 0.002, Exception( + "error in x particle velocity" +) + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/AcceleratorLattice/inputs_quad_3d b/Examples/Tests/accelerator_lattice/inputs_test_3d_hard_edged_quadrupoles similarity index 100% rename from Examples/Tests/AcceleratorLattice/inputs_quad_3d rename to Examples/Tests/accelerator_lattice/inputs_test_3d_hard_edged_quadrupoles diff --git a/Examples/Tests/AcceleratorLattice/inputs_quad_boosted_3d b/Examples/Tests/accelerator_lattice/inputs_test_3d_hard_edged_quadrupoles_boosted similarity index 100% rename from Examples/Tests/AcceleratorLattice/inputs_quad_boosted_3d rename to Examples/Tests/accelerator_lattice/inputs_test_3d_hard_edged_quadrupoles_boosted diff --git a/Examples/Tests/AcceleratorLattice/inputs_quad_moving_3d b/Examples/Tests/accelerator_lattice/inputs_test_3d_hard_edged_quadrupoles_moving similarity index 100% rename from Examples/Tests/AcceleratorLattice/inputs_quad_moving_3d rename to Examples/Tests/accelerator_lattice/inputs_test_3d_hard_edged_quadrupoles_moving diff --git a/Examples/Tests/boosted_diags/CMakeLists.txt b/Examples/Tests/boosted_diags/CMakeLists.txt new file mode 100644 index 00000000000..8deb7f2bee2 --- /dev/null +++ b/Examples/Tests/boosted_diags/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_laser_acceleration_btd # name + 3 # dims + 2 # nprocs + inputs_test_3d_laser_acceleration_btd # inputs + analysis.py # analysis + diags/diag1000003 # output + OFF # dependency +) diff --git a/Examples/Tests/boosted_diags/analysis.py b/Examples/Tests/boosted_diags/analysis.py index 2b21184dc3d..62956133af6 100755 --- a/Examples/Tests/boosted_diags/analysis.py +++ b/Examples/Tests/boosted_diags/analysis.py @@ -7,14 +7,14 @@ # License: BSD-3-Clause-LBNL -''' +""" Analysis script of a WarpX simulation in a boosted frame. The simulation runs in a boosted frame, and the analysis is done in the lab frame, i.e., on the back-transformed diagnostics for the full 3D simulation and an x-z slice at y=y_center. The field-data, Ez, along z, at (x_center,y_center,:) is compared between the full back-transformed diagnostic and the reduced diagnostic (i.e., x-z slice) . -''' +""" import os import sys @@ -26,7 +26,7 @@ yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] @@ -38,23 +38,22 @@ # Read data from new back-transformed diagnostics (plotfile) ds_plotfile = yt.load(filename) data = ds_plotfile.covering_grid( - level=0, - left_edge=ds_plotfile.domain_left_edge, - dims=ds_plotfile.domain_dimensions) -Ez_plotfile = data[('mesh', 'Ez')].to_ndarray() + level=0, left_edge=ds_plotfile.domain_left_edge, dims=ds_plotfile.domain_dimensions +) +Ez_plotfile = data[("mesh", "Ez")].to_ndarray() # Read data from new back-transformed diagnostics (openPMD) series = io.Series("./diags/diag2/openpmd_%T.h5", io.Access.read_only) ds_openpmd = series.iterations[3] -Ez_openpmd = ds_openpmd.meshes['E']['z'].load_chunk() +Ez_openpmd = ds_openpmd.meshes["E"]["z"].load_chunk() Ez_openpmd = Ez_openpmd.transpose() series.flush() # Compare arrays to check consistency between new BTD formats (plotfile and openPMD) -assert(np.allclose(Ez_plotfile, Ez_openpmd, rtol=rtol, atol=atol)) +assert np.allclose(Ez_plotfile, Ez_openpmd, rtol=rtol, atol=atol) # Check that particle random sub-selection has been applied -ts = OpenPMDTimeSeries('./diags/diag2/') -w, = ts.get_particle(['w'], species='beam', iteration=3) +ts = OpenPMDTimeSeries("./diags/diag2/") +(w,) = ts.get_particle(["w"], species="beam", iteration=3) assert (400 < len(w)) & (len(w) < 600) test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/boosted_diags/inputs_3d b/Examples/Tests/boosted_diags/inputs_test_3d_laser_acceleration_btd similarity index 100% rename from Examples/Tests/boosted_diags/inputs_3d rename to Examples/Tests/boosted_diags/inputs_test_3d_laser_acceleration_btd diff --git a/Examples/Tests/boundaries/CMakeLists.txt b/Examples/Tests/boundaries/CMakeLists.txt new file mode 100644 index 00000000000..fccd45e2ebf --- /dev/null +++ b/Examples/Tests/boundaries/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_particle_boundaries # name + 3 # dims + 2 # nprocs + inputs_test_3d_particle_boundaries # inputs + analysis.py # analysis + diags/diag1000008 # output + OFF # dependency +) diff --git a/Examples/Tests/boundaries/analysis.py b/Examples/Tests/boundaries/analysis.py index 9c108b16196..be76a728a1f 100755 --- a/Examples/Tests/boundaries/analysis.py +++ b/Examples/Tests/boundaries/analysis.py @@ -22,21 +22,21 @@ from scipy.constants import c, m_e yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # The min and max size of the box along the three axis. -dmin = -1. -dmax = +1. +dmin = -1.0 +dmax = +1.0 # Open plotfile specified in command line filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) ad = ds.all_data() time = ds.current_time.to_value() -filename0 = filename[:-5] + '00000' -ds0 = yt.load( filename0 ) +filename0 = filename[:-5] + "00000" +ds0 = yt.load(filename0) ad0 = ds0.all_data() # Read in the particle initial values and the current values. @@ -44,42 +44,44 @@ # differently in the diagnostic files. # For the absorbing particles, an extra particle was added that won't be absorbed # so that there will be something to read in here. -r_id0 = ad0['reflecting_particles', 'particle_id'].v -a_id0 = ad0['absorbing_particles', 'particle_id'].v -p_id0 = ad0['periodic_particles', 'particle_id'].v - -xx0 = ad0['reflecting_particles', 'particle_position_x'].v[np.argsort(r_id0)] -zz0 = ad0['periodic_particles', 'particle_position_z'].v[np.argsort(p_id0)] - -ux0 = ad0['reflecting_particles', 'particle_momentum_x'].v[np.argsort(r_id0)]/m_e/c -uz0 = ad0['periodic_particles', 'particle_momentum_z'].v[np.argsort(p_id0)]/m_e/c -gx0 = np.sqrt(1. + ux0**2) -gz0 = np.sqrt(1. + uz0**2) -vx0 = ux0/gx0*c -vz0 = uz0/gz0*c - -r_id = ad['reflecting_particles', 'particle_id'].v -a_id = ad['absorbing_particles', 'particle_id'].v -p_id = ad['periodic_particles', 'particle_id'].v - -xx = ad['reflecting_particles', 'particle_position_x'].v[np.argsort(r_id)] -zz = ad['periodic_particles', 'particle_position_z'].v[np.argsort(p_id)] - -ux = ad['reflecting_particles', 'particle_momentum_x'].v[np.argsort(r_id)]/m_e/c -uz = ad['periodic_particles', 'particle_momentum_z'].v[np.argsort(p_id)]/m_e/c -gx = np.sqrt(1. + ux**2) -gz = np.sqrt(1. + uz**2) -vx = ux/gx*c -vz = uz/gz*c +r_id0 = ad0["reflecting_particles", "particle_id"].v +a_id0 = ad0["absorbing_particles", "particle_id"].v +p_id0 = ad0["periodic_particles", "particle_id"].v + +xx0 = ad0["reflecting_particles", "particle_position_x"].v[np.argsort(r_id0)] +zz0 = ad0["periodic_particles", "particle_position_z"].v[np.argsort(p_id0)] + +ux0 = ad0["reflecting_particles", "particle_momentum_x"].v[np.argsort(r_id0)] / m_e / c +uz0 = ad0["periodic_particles", "particle_momentum_z"].v[np.argsort(p_id0)] / m_e / c +gx0 = np.sqrt(1.0 + ux0**2) +gz0 = np.sqrt(1.0 + uz0**2) +vx0 = ux0 / gx0 * c +vz0 = uz0 / gz0 * c + +r_id = ad["reflecting_particles", "particle_id"].v +a_id = ad["absorbing_particles", "particle_id"].v +p_id = ad["periodic_particles", "particle_id"].v + +xx = ad["reflecting_particles", "particle_position_x"].v[np.argsort(r_id)] +zz = ad["periodic_particles", "particle_position_z"].v[np.argsort(p_id)] + +ux = ad["reflecting_particles", "particle_momentum_x"].v[np.argsort(r_id)] / m_e / c +uz = ad["periodic_particles", "particle_momentum_z"].v[np.argsort(p_id)] / m_e / c +gx = np.sqrt(1.0 + ux**2) +gz = np.sqrt(1.0 + uz**2) +vx = ux / gx * c +vz = uz / gz * c + def do_reflect(x): if x < dmin: - return 2.*dmin - x + return 2.0 * dmin - x elif x > dmax: - return 2.*dmax - x + return 2.0 * dmax - x else: return x + def do_periodic(x): if x < dmin: return x + (dmax - dmin) @@ -88,21 +90,26 @@ def do_periodic(x): else: return x + # Calculate the analytic value of the current particle locations and # apply the appropriate boundary conditions. -xxa = xx0 + vx0*time +xxa = xx0 + vx0 * time xxa[0] = do_reflect(xxa[0]) xxa[1] = do_reflect(xxa[1]) -zza = zz0 + vz0*time +zza = zz0 + vz0 * time zza[0] = do_periodic(zza[0]) zza[1] = do_periodic(zza[1]) -assert (len(a_id) == 1), 'Absorbing particles not absorbed' -assert (np.all(vx == -vx0)), 'Reflecting particle velocity not correct' -assert (np.all(vz == +vz0)), 'Periodic particle velocity not correct' -assert (np.all(np.abs((xx - xxa)/xx) < 1.e-15)), 'Reflecting particle position not correct' -assert (np.all(np.abs((zz - zza)/zz) < 1.e-15)), 'Periodic particle position not correct' +assert len(a_id) == 1, "Absorbing particles not absorbed" +assert np.all(vx == -vx0), "Reflecting particle velocity not correct" +assert np.all(vz == +vz0), "Periodic particle velocity not correct" +assert np.all( + np.abs((xx - xxa) / xx) < 1.0e-15 +), "Reflecting particle position not correct" +assert np.all( + np.abs((zz - zza) / zz) < 1.0e-15 +), "Periodic particle position not correct" test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/boundaries/inputs_3d b/Examples/Tests/boundaries/inputs_test_3d_particle_boundaries similarity index 100% rename from Examples/Tests/boundaries/inputs_3d rename to Examples/Tests/boundaries/inputs_test_3d_particle_boundaries diff --git a/Examples/Tests/btd_rz/CMakeLists.txt b/Examples/Tests/btd_rz/CMakeLists.txt new file mode 100644 index 00000000000..6a85f653c65 --- /dev/null +++ b/Examples/Tests/btd_rz/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_rz_btd # name + RZ # dims + 2 # nprocs + inputs_test_rz_btd # inputs + analysis.py # analysis + diags/diag1000289 # output + OFF # dependency +) diff --git a/Examples/Tests/btd_rz/analysis_BTD_laser_antenna.py b/Examples/Tests/btd_rz/analysis.py similarity index 51% rename from Examples/Tests/btd_rz/analysis_BTD_laser_antenna.py rename to Examples/Tests/btd_rz/analysis.py index e2f174d6e29..5002b4c80b3 100755 --- a/Examples/Tests/btd_rz/analysis_BTD_laser_antenna.py +++ b/Examples/Tests/btd_rz/analysis.py @@ -16,49 +16,47 @@ from scipy.constants import c, e, m_e from scipy.optimize import curve_fit -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -def gaussian_laser( z, a0, z0_phase, z0_prop, ctau, lambda0 ): +def gaussian_laser(z, a0, z0_phase, z0_prop, ctau, lambda0): """ Returns a Gaussian laser profile """ - k0 = 2*np.pi/lambda0 - E0 = a0*m_e*c**2*k0/e - return( E0*np.exp( - (z-z0_prop)**2/ctau**2 ) \ - *np.cos( k0*(z-z0_phase) ) ) + k0 = 2 * np.pi / lambda0 + E0 = a0 * m_e * c**2 * k0 / e + return E0 * np.exp(-((z - z0_prop) ** 2) / ctau**2) * np.cos(k0 * (z - z0_phase)) + # Fit the on-axis profile to extract the phase (a.k.a. CEP) def fit_function(z, z0_phase): - return( gaussian_laser( z, a0, z0_phase, - z0_b+Lprop_b, ctau0, lambda0 ) ) + return gaussian_laser(z, a0, z0_phase, z0_b + Lprop_b, ctau0, lambda0) + plotfile = sys.argv[1] # The values must be consistent with the values provided in the simulation input -t_current = 80e-15 # Time of the snapshot1 -c = 299792458; -z0_antenna = -1.e-6 # position of laser -lambda0 = 0.8e-6 # wavelength of the signal -tau0 = 10e-15 # duration of the signal +t_current = 80e-15 # Time of the snapshot1 +z0_antenna = -1.0e-6 # position of laser +lambda0 = 0.8e-6 # wavelength of the signal +tau0 = 10e-15 # duration of the signal ctau0 = tau0 * c -a0 = 15 # amplitude -t_peak = 20e-15 # Time at which laser reaches its peak -Lprop_b = c*t_current +a0 = 15 # amplitude +t_peak = 20e-15 # Time at which laser reaches its peak +Lprop_b = c * t_current z0_b = z0_antenna - c * t_peak -ts = OpenPMDTimeSeries('./diags/back_rz') -Ex, info = ts.get_field('E', 'x', iteration=1, slice_across='r') +ts = OpenPMDTimeSeries("./diags/back_rz") +Ex, info = ts.get_field("E", "x", iteration=1, slice_across="r") -fit_result = curve_fit( fit_function, info.z, Ex, - p0=np.array([z0_b+Lprop_b]) ) +fit_result = curve_fit(fit_function, info.z, Ex, p0=np.array([z0_b + Lprop_b])) z0_fit = fit_result[0] -Ex_fit = gaussian_laser( info.z, a0, z0_fit, z0_b+Lprop_b, ctau0, lambda0) +Ex_fit = gaussian_laser(info.z, a0, z0_fit, z0_b + Lprop_b, ctau0, lambda0) ## Check that the a0 agrees within 5% of the predicted value -assert np.allclose( Ex, Ex_fit, atol=0.18*Ex.max() ) +assert np.allclose(Ex, Ex_fit, atol=0.18 * Ex.max()) # Checksum regression analysis test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/btd_rz/inputs_rz_z_boosted_BTD b/Examples/Tests/btd_rz/inputs_test_rz_btd similarity index 100% rename from Examples/Tests/btd_rz/inputs_rz_z_boosted_BTD rename to Examples/Tests/btd_rz/inputs_test_rz_btd diff --git a/Examples/Tests/collider_relevant_diags/CMakeLists.txt b/Examples/Tests/collider_relevant_diags/CMakeLists.txt new file mode 100644 index 00000000000..338f66970bc --- /dev/null +++ b/Examples/Tests/collider_relevant_diags/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_collider_diagnostics # name + 3 # dims + 2 # nprocs + inputs_test_3d_collider_diagnostics # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/collider_relevant_diags/analysis.py b/Examples/Tests/collider_relevant_diags/analysis.py new file mode 100755 index 00000000000..f6eb9de124f --- /dev/null +++ b/Examples/Tests/collider_relevant_diags/analysis.py @@ -0,0 +1,186 @@ +#!/usr/bin/env python3 + +import os +import sys + +import numpy as np +import openpmd_api as io +import pandas as pd +from scipy.constants import c, e, hbar, m_e + +sys.path.append("../../../../warpx/Regression/Checksum/") +import checksumAPI + +sys.path.append("../../../../warpx/Tools/Parser/") +from input_file_parser import parse_input_file + +E_crit = m_e**2 * c**3 / (e * hbar) +B_crit = m_e**2 * c**2 / (e * hbar) + + +def chi(ux, uy, uz, Ex, Ey, Ez, Bx, By, Bz): + gamma = np.sqrt(1.0 + ux**2 + uy**2 + uz**2) + vx = ux / gamma * c + vy = uy / gamma * c + vz = uz / gamma * c + tmp1x = Ex + vy * Bz - vz * By + tmp1y = Ey - vx * Bz + vz * Bx + tmp1z = Ez + vx * By - vy * Bx + tmp2 = (Ex * vx + Ey * vy + Ez * vz) / c + chi = gamma / E_crit * np.sqrt(tmp1x**2 + tmp1y**2 + tmp1z**2 - tmp2**2) + return chi + + +def dL_dt(): + series = io.Series("diags/diag2/openpmd_%T.h5", io.Access.read_only) + iterations = np.asarray(series.iterations) + lumi = [] + for n, ts in enumerate(iterations): + it = series.iterations[ts] + rho1 = it.meshes["rho_beam_e"] + dV = np.prod(rho1.grid_spacing) + rho1 = it.meshes["rho_beam_e"][io.Mesh_Record_Component.SCALAR].load_chunk() + rho2 = it.meshes["rho_beam_p"][io.Mesh_Record_Component.SCALAR].load_chunk() + beam_e_charge = it.particles["beam_e"]["charge"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + beam_p_charge = it.particles["beam_p"]["charge"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + q1 = beam_e_charge[0] + if not np.all(beam_e_charge == q1): + sys.exit("beam_e particles do not have the same charge") + q2 = beam_p_charge[0] + if not np.all(beam_p_charge == q2): + sys.exit("beam_p particles do not have the same charge") + series.flush() + n1 = rho1 / q1 + n2 = rho2 / q2 + ln = 2 * np.sum(n1 * n2) * dV * c + lumi.append(ln) + return lumi + + +input_dict = parse_input_file("warpx_used_inputs") +Ex, Ey, Ez = [float(w) for w in input_dict["particles.E_external_particle"]] +Bx, By, Bz = [float(w) for w in input_dict["particles.B_external_particle"]] + +CollDiagFname = "diags/reducedfiles/ColliderRelevant_beam_e_beam_p.txt" +df = pd.read_csv(CollDiagFname, sep=" ", header=0) + +for species in ["beam_p", "beam_e"]: + ux1, ux2, ux3 = [float(w) for w in input_dict[f"{species}.multiple_particles_ux"]] + uy1, uy2, uy3 = [float(w) for w in input_dict[f"{species}.multiple_particles_uy"]] + uz1, uz2, uz3 = [float(w) for w in input_dict[f"{species}.multiple_particles_uz"]] + + x = np.array([float(w) for w in input_dict[f"{species}.multiple_particles_pos_x"]]) + y = np.array([float(w) for w in input_dict[f"{species}.multiple_particles_pos_y"]]) + + w = np.array([float(w) for w in input_dict[f"{species}.multiple_particles_weight"]]) + + CHI_ANALYTICAL = np.array( + [ + chi(ux1, uy1, uz1, Ex, Ey, Ez, Bx, By, Bz), + chi(ux2, uy2, uz2, Ex, Ey, Ez, Bx, By, Bz), + chi(ux3, uy3, uz3, Ex, Ey, Ez, Bx, By, Bz), + ] + ) + THETAX = np.array( + [np.arctan2(ux1, uz1), np.arctan2(ux2, uz2), np.arctan2(ux3, uz3)] + ) + THETAY = np.array( + [np.arctan2(uy1, uz1), np.arctan2(uy2, uz2), np.arctan2(uy3, uz3)] + ) + + # CHI MAX + fname = f"diags/reducedfiles/ParticleExtrema_{species}.txt" + chimax_pe = np.loadtxt(fname)[:, 19] + chimax_cr = df[ + [col for col in df.columns if f"chi_max_{species}" in col] + ].to_numpy() + assert np.allclose(np.max(CHI_ANALYTICAL), chimax_cr, rtol=1e-8) + assert np.allclose(chimax_pe, chimax_cr, rtol=1e-8) + + # CHI MIN + fname = f"diags/reducedfiles/ParticleExtrema_{species}.txt" + chimin_pe = np.loadtxt(fname)[:, 18] + chimin_cr = df[ + [col for col in df.columns if f"chi_min_{species}" in col] + ].to_numpy() + assert np.allclose(np.min(CHI_ANALYTICAL), chimin_cr, rtol=1e-8) + assert np.allclose(chimin_pe, chimin_cr, rtol=1e-8) + + # CHI AVERAGE + chiave_cr = df[ + [col for col in df.columns if f"chi_ave_{species}" in col] + ].to_numpy() + assert np.allclose(np.average(CHI_ANALYTICAL, weights=w), chiave_cr, rtol=1e-8) + + # X AVE STD + x_ave_cr = df[[col for col in df.columns if f"]x_ave_{species}" in col]].to_numpy() + x_std_cr = df[[col for col in df.columns if f"]x_std_{species}" in col]].to_numpy() + x_ave = np.average(x, weights=w) + x_std = np.sqrt(np.average((x - x_ave) ** 2, weights=w)) + assert np.allclose(x_ave, x_ave_cr, rtol=1e-8) + assert np.allclose(x_std, x_std_cr, rtol=1e-8) + + # Y AVE STD + y_ave_cr = df[[col for col in df.columns if f"]y_ave_{species}" in col]].to_numpy() + y_std_cr = df[[col for col in df.columns if f"]y_std_{species}" in col]].to_numpy() + y_ave = np.average(y, weights=w) + y_std = np.sqrt(np.average((y - y_ave) ** 2, weights=w)) + assert np.allclose(y_ave, y_ave_cr, rtol=1e-8) + assert np.allclose(y_std, y_std_cr, rtol=1e-8) + + # THETA X MIN AVE MAX STD + thetax_min_cr = df[ + [col for col in df.columns if f"theta_x_min_{species}" in col] + ].to_numpy() + thetax_ave_cr = df[ + [col for col in df.columns if f"theta_x_ave_{species}" in col] + ].to_numpy() + thetax_max_cr = df[ + [col for col in df.columns if f"theta_x_max_{species}" in col] + ].to_numpy() + thetax_std_cr = df[ + [col for col in df.columns if f"theta_x_std_{species}" in col] + ].to_numpy() + thetax_min = np.min(THETAX) + thetax_ave = np.average(THETAX, weights=w) + thetax_max = np.max(THETAX) + thetax_std = np.sqrt(np.average((THETAX - thetax_ave) ** 2, weights=w)) + assert np.allclose(thetax_min, thetax_min_cr, rtol=1e-8) + assert np.allclose(thetax_ave, thetax_ave_cr, rtol=1e-8) + assert np.allclose(thetax_max, thetax_max_cr, rtol=1e-8) + assert np.allclose(thetax_std, thetax_std_cr, rtol=1e-8) + + # THETA Y MIN AVE MAX STD + thetay_min_cr = df[ + [col for col in df.columns if f"theta_y_min_{species}" in col] + ].to_numpy() + thetay_ave_cr = df[ + [col for col in df.columns if f"theta_y_ave_{species}" in col] + ].to_numpy() + thetay_max_cr = df[ + [col for col in df.columns if f"theta_y_max_{species}" in col] + ].to_numpy() + thetay_std_cr = df[ + [col for col in df.columns if f"theta_y_std_{species}" in col] + ].to_numpy() + thetay_min = np.min(THETAY) + thetay_ave = np.average(THETAY, weights=w) + thetay_max = np.max(THETAY) + thetay_std = np.sqrt(np.average((THETAY - thetay_ave) ** 2, weights=w)) + assert np.allclose(thetay_min, thetay_min_cr, rtol=1e-8) + assert np.allclose(thetay_ave, thetay_ave_cr, rtol=1e-8) + assert np.allclose(thetay_max, thetay_max_cr, rtol=1e-8) + assert np.allclose(thetay_std, thetay_std_cr, rtol=1e-8) + + # dL/dt + dL_dt_cr = df[[col for col in df.columns if "dL_dt" in col]].to_numpy() + assert np.allclose(dL_dt_cr, dL_dt(), rtol=1e-8) + +# Checksum analysis +plotfile = sys.argv[1] +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, plotfile) diff --git a/Examples/Tests/collider_relevant_diags/analysis_multiple_particles.py b/Examples/Tests/collider_relevant_diags/analysis_multiple_particles.py deleted file mode 100755 index b23bb69d52c..00000000000 --- a/Examples/Tests/collider_relevant_diags/analysis_multiple_particles.py +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -import numpy as np -import openpmd_api as io -import pandas as pd -from scipy.constants import c, e, hbar, m_e - -sys.path.append('../../../../warpx/Regression/Checksum/') -import checksumAPI - -sys.path.append('../../../../warpx/Tools/Parser/') -from input_file_parser import parse_input_file - -E_crit = m_e**2*c**3/(e*hbar) -B_crit = m_e**2*c**2/(e*hbar) - -def chi(ux, uy, uz, Ex, Ey, Ez, Bx, By, Bz): - gamma = np.sqrt(1.+ux**2+uy**2+uz**2) - vx = ux / gamma * c - vy = uy / gamma * c - vz = uz / gamma * c - tmp1x = Ex + vy*Bz - vz*By - tmp1y = Ey - vx*Bz + vz*Bx - tmp1z = Ez + vx*By - vy*Bx - tmp2 = (Ex*vx + Ey*vy + Ez*vz)/c - chi = gamma/E_crit*np.sqrt(tmp1x**2+tmp1y**2+tmp1z**2 - tmp2**2) - return chi - -def dL_dt(): - series = io.Series("diags/diag2/openpmd_%T.h5",io.Access.read_only) - iterations = np.asarray(series.iterations) - lumi = [] - for n,ts in enumerate(iterations): - it = series.iterations[ts] - rho1 = it.meshes["rho_beam_e"] - dV = np.prod(rho1.grid_spacing) - rho1 = it.meshes["rho_beam_e"][io.Mesh_Record_Component.SCALAR].load_chunk() - rho2 = it.meshes["rho_beam_p"][io.Mesh_Record_Component.SCALAR].load_chunk() - beam_e_charge = it.particles["beam_e"]["charge"][io.Mesh_Record_Component.SCALAR].load_chunk() - beam_p_charge = it.particles["beam_p"]["charge"][io.Mesh_Record_Component.SCALAR].load_chunk() - q1 = beam_e_charge[0] - if not np.all(beam_e_charge == q1): - sys.exit('beam_e particles do not have the same charge') - q2 = beam_p_charge[0] - if not np.all(beam_p_charge == q2): - sys.exit('beam_p particles do not have the same charge') - series.flush() - n1 = rho1/q1 - n2 = rho2/q2 - l = 2*np.sum(n1*n2)*dV*c - lumi.append(l) - return lumi - -input_dict = parse_input_file('inputs_3d_multiple_particles') -Ex, Ey, Ez = [float(w) for w in input_dict['particles.E_external_particle']] -Bx, By, Bz = [float(w) for w in input_dict['particles.B_external_particle']] - -CollDiagFname='diags/reducedfiles/ColliderRelevant_beam_e_beam_p.txt' -df = pd.read_csv(CollDiagFname, sep=" ", header=0) - -for species in ['beam_p', 'beam_e']: - - ux1, ux2, ux3 = [float(w) for w in input_dict[f'{species}.multiple_particles_ux']] - uy1, uy2, uy3 = [float(w) for w in input_dict[f'{species}.multiple_particles_uy']] - uz1, uz2, uz3 = [float(w) for w in input_dict[f'{species}.multiple_particles_uz']] - - x = np.array([float(w) for w in input_dict[f'{species}.multiple_particles_pos_x']]) - y = np.array([float(w) for w in input_dict[f'{species}.multiple_particles_pos_y']]) - - w = np.array([float(w) for w in input_dict[f'{species}.multiple_particles_weight']]) - - CHI_ANALYTICAL = np.array([chi(ux1, uy1, uz1, Ex, Ey, Ez, Bx, By, Bz), - chi(ux2, uy2, uz2, Ex, Ey, Ez, Bx, By, Bz), - chi(ux3, uy3, uz3, Ex, Ey, Ez, Bx, By, Bz)]) - THETAX = np.array([np.arctan2(ux1, uz1), np.arctan2(ux2, uz2), np.arctan2(ux3, uz3)]) - THETAY = np.array([np.arctan2(uy1, uz1), np.arctan2(uy2, uz2), np.arctan2(uy3, uz3)]) - - # CHI MAX - fname=f'diags/reducedfiles/ParticleExtrema_{species}.txt' - chimax_pe = np.loadtxt(fname)[:,19] - chimax_cr = df[[col for col in df.columns if f'chi_max_{species}' in col]].to_numpy() - assert np.allclose(np.max(CHI_ANALYTICAL), chimax_cr, rtol=1e-8) - assert np.allclose(chimax_pe, chimax_cr, rtol=1e-8) - - # CHI MIN - fname=f'diags/reducedfiles/ParticleExtrema_{species}.txt' - chimin_pe = np.loadtxt(fname)[:,18] - chimin_cr = df[[col for col in df.columns if f'chi_min_{species}' in col]].to_numpy() - assert np.allclose(np.min(CHI_ANALYTICAL), chimin_cr, rtol=1e-8) - assert np.allclose(chimin_pe, chimin_cr, rtol=1e-8) - - # CHI AVERAGE - chiave_cr = df[[col for col in df.columns if f'chi_ave_{species}' in col]].to_numpy() - assert np.allclose(np.average(CHI_ANALYTICAL, weights=w), chiave_cr, rtol=1e-8) - - # X AVE STD - x_ave_cr = df[[col for col in df.columns if f']x_ave_{species}' in col]].to_numpy() - x_std_cr = df[[col for col in df.columns if f']x_std_{species}' in col]].to_numpy() - x_ave = np.average(x, weights=w) - x_std = np.sqrt(np.average((x-x_ave)**2, weights=w)) - assert np.allclose(x_ave, x_ave_cr, rtol=1e-8) - assert np.allclose(x_std, x_std_cr, rtol=1e-8) - - # Y AVE STD - y_ave_cr = df[[col for col in df.columns if f']y_ave_{species}' in col]].to_numpy() - y_std_cr = df[[col for col in df.columns if f']y_std_{species}' in col]].to_numpy() - y_ave = np.average(y, weights=w) - y_std = np.sqrt(np.average((y-y_ave)**2, weights=w)) - assert np.allclose(y_ave, y_ave_cr, rtol=1e-8) - assert np.allclose(y_std, y_std_cr, rtol=1e-8) - - # THETA X MIN AVE MAX STD - thetax_min_cr = df[[col for col in df.columns if f'theta_x_min_{species}' in col]].to_numpy() - thetax_ave_cr = df[[col for col in df.columns if f'theta_x_ave_{species}' in col]].to_numpy() - thetax_max_cr = df[[col for col in df.columns if f'theta_x_max_{species}' in col]].to_numpy() - thetax_std_cr = df[[col for col in df.columns if f'theta_x_std_{species}' in col]].to_numpy() - thetax_min = np.min(THETAX) - thetax_ave = np.average(THETAX, weights=w) - thetax_max = np.max(THETAX) - thetax_std = np.sqrt(np.average((THETAX-thetax_ave)**2, weights=w)) - assert np.allclose(thetax_min, thetax_min_cr, rtol=1e-8) - assert np.allclose(thetax_ave, thetax_ave_cr, rtol=1e-8) - assert np.allclose(thetax_max, thetax_max_cr, rtol=1e-8) - assert np.allclose(thetax_std, thetax_std_cr, rtol=1e-8) - - # THETA Y MIN AVE MAX STD - thetay_min_cr = df[[col for col in df.columns if f'theta_y_min_{species}' in col]].to_numpy() - thetay_ave_cr = df[[col for col in df.columns if f'theta_y_ave_{species}' in col]].to_numpy() - thetay_max_cr = df[[col for col in df.columns if f'theta_y_max_{species}' in col]].to_numpy() - thetay_std_cr = df[[col for col in df.columns if f'theta_y_std_{species}' in col]].to_numpy() - thetay_min = np.min(THETAY) - thetay_ave = np.average(THETAY, weights=w) - thetay_max = np.max(THETAY) - thetay_std = np.sqrt(np.average((THETAY-thetay_ave)**2, weights=w)) - assert np.allclose(thetay_min, thetay_min_cr, rtol=1e-8) - assert np.allclose(thetay_ave, thetay_ave_cr, rtol=1e-8) - assert np.allclose(thetay_max, thetay_max_cr, rtol=1e-8) - assert np.allclose(thetay_std, thetay_std_cr, rtol=1e-8) - - # dL/dt - dL_dt_cr = df[[col for col in df.columns if 'dL_dt' in col]].to_numpy() - assert np.allclose(dL_dt_cr, dL_dt(), rtol=1e-8) - -# Checksum analysis -plotfile = sys.argv[1] -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, plotfile) diff --git a/Examples/Tests/collider_relevant_diags/inputs_3d_multiple_particles b/Examples/Tests/collider_relevant_diags/inputs_test_3d_collider_diagnostics similarity index 99% rename from Examples/Tests/collider_relevant_diags/inputs_3d_multiple_particles rename to Examples/Tests/collider_relevant_diags/inputs_test_3d_collider_diagnostics index 1efc68c33b0..d88e0b767d6 100644 --- a/Examples/Tests/collider_relevant_diags/inputs_3d_multiple_particles +++ b/Examples/Tests/collider_relevant_diags/inputs_test_3d_collider_diagnostics @@ -18,6 +18,7 @@ geometry.prob_lo = 0 0 0 geometry.prob_hi = 8 8 8 particles.do_tiling = 0 warpx.use_filter = 0 +warpx.abort_on_warning_threshold = high ################################# ######## BOUNDARY CONDITION ##### diff --git a/Examples/Tests/collision/CMakeLists.txt b/Examples/Tests/collision/CMakeLists.txt new file mode 100644 index 00000000000..36f8a1cb1d6 --- /dev/null +++ b/Examples/Tests/collision/CMakeLists.txt @@ -0,0 +1,62 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_collision_z # name + 1 # dims + 2 # nprocs + inputs_test_1d_collision_z # inputs + analysis_collision_1d.py # analysis + diags/diag1000600 # output + OFF # dependency +) + +add_warpx_test( + test_2d_collision_xz # name + 2 # dims + 1 # nprocs + inputs_test_2d_collision_xz # inputs + analysis_collision_2d.py # analysis + diags/diag1000150 # output + OFF # dependency +) + +add_warpx_test( + test_2d_collision_xz_picmi # name + 2 # dims + 1 # nprocs + inputs_test_2d_collision_xz_picmi.py # inputs + analysis_collision_2d.py # analysis + diags/diag1000150 # output + OFF # dependency +) + +add_warpx_test( + test_3d_collision_iso # name + 3 # dims + 1 # nprocs + inputs_test_3d_collision_iso # inputs + analysis_collision_3d_isotropization.py # analysis + diags/diag1000100 # output + OFF # dependency +) + +add_warpx_test( + test_3d_collision_xyz # name + 3 # dims + 1 # nprocs + inputs_test_3d_collision_xyz # inputs + analysis_collision_3d.py # analysis + diags/diag1000150 # output + OFF # dependency +) + +add_warpx_test( + test_rz_collision # name + RZ # dims + 1 # nprocs + inputs_test_rz_collision # inputs + analysis_collision_rz.py # analysis + diags/diag1000150 # output + OFF # dependency +) diff --git a/Examples/Tests/collision/analysis_collision_1d.py b/Examples/Tests/collision/analysis_collision_1d.py new file mode 100755 index 00000000000..1888696953e --- /dev/null +++ b/Examples/Tests/collision/analysis_collision_1d.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python3 + +# Copyright 2024 Justin Angus +# +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL +# +# This is a script that analyses the simulation results from the script `inputs_1d`. +# run locally: python analysis_vandb_1d.py diags/diag1000600/ +# +# This is a 1D intra-species Coulomb scattering relaxation test consisting +# of a low-density population streaming into a higher density population at rest. +# Both populations belong to the same carbon12 ion species. +# See test T1b from JCP 413 (2020) by D. Higginson, et al. +# +import os +import sys + +import numpy as np +import yt +from scipy.constants import e + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# this will be the name of the plot file +last_fn = sys.argv[1] +ds = yt.load(last_fn) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) + +# carbon 12 ion (mass = 12*amu - 6*me) +mass = 1.992100316897910e-26 + +# Separate macroparticles from group A (low weight) and group B (high weight) +# by sorting based on weight +sorted_indices = data["ions", "particle_weight"].argsort() +sorted_wp = data["ions", "particle_weight"][sorted_indices].value +sorted_px = data["ions", "particle_momentum_x"][sorted_indices].value +sorted_py = data["ions", "particle_momentum_y"][sorted_indices].value +sorted_pz = data["ions", "particle_momentum_z"][sorted_indices].value + +# Find the index 'Npmin' that separates macroparticles from group A and group B +Np = len(sorted_wp) +wpmin = sorted_wp.min() +wpmax = sorted_wp.max() +for i in range(len(sorted_wp)): + if sorted_wp[i] > wpmin: + Npmin = i + break + +NpA = Npmin +wpA = wpmin +NpB = Np - Npmin +wpB = wpmax +NpAs = 0 +NpAe = Npmin +NpBs = Npmin +NpBe = Np + +############# + +sorted_px_sum = np.abs(sorted_px).sum() +sorted_py_sum = np.abs(sorted_py).sum() +sorted_pz_sum = np.abs(sorted_pz).sum() +sorted_wp_sum = np.abs(sorted_wp).sum() + +# compute mean velocities +wAtot = wpA * NpA +wBtot = wpB * NpB + +uBx = uBy = uBz = 0.0 +for i in range(NpBs, NpBe): + uBx += wpB * sorted_px[i] + uBy += wpB * sorted_py[i] + uBz += wpB * sorted_pz[i] +uBx /= mass * wBtot # [m/s] +uBy /= mass * wBtot # [m/s] +uBz /= mass * wBtot # [m/s] + +uAx = uAy = uAz = 0.0 +for i in range(NpAs, NpAe): + uAx += wpA * sorted_px[i] + uAy += wpA * sorted_py[i] + uAz += wpA * sorted_pz[i] +uAx /= mass * wAtot # [m/s] +uAy /= mass * wAtot # [m/s] +uAz /= mass * wAtot # [m/s] + +# compute temperatures +TBx = TBy = TBz = 0.0 +for i in range(NpBs, NpBe): + TBx += wpB * (sorted_px[i] / mass - uBx) ** 2 + TBy += wpB * (sorted_py[i] / mass - uBy) ** 2 + TBz += wpB * (sorted_pz[i] / mass - uBz) ** 2 +TBx *= mass / (e * wBtot) +TBy *= mass / (e * wBtot) +TBz *= mass / (e * wBtot) + +TAx = TAy = TAz = 0.0 +for i in range(NpAs, NpAe): + TAx += wpA * (sorted_px[i] / mass - uAx) ** 2 + TAy += wpA * (sorted_py[i] / mass - uAy) ** 2 + TAz += wpA * (sorted_pz[i] / mass - uAz) ** 2 +TAx *= mass / (e * wAtot) +TAy *= mass / (e * wAtot) +TAz *= mass / (e * wAtot) + +TApar = TAz +TAperp = (TAx + TAy) / 2.0 +TA = (TAx + TAy + TAz) / 3.0 + +TBpar = TBz +TBperp = (TBx + TBy) / 2.0 +TB = (TBx + TBy + TBz) / 3.0 + +TApar_30ps_soln = 6.15e3 # TA parallel solution at t = 30 ps +error = np.abs(TApar - TApar_30ps_soln) / TApar_30ps_soln +tolerance = 0.02 +print("TApar at 30ps error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, last_fn) diff --git a/Examples/Tests/collision/analysis_collision_2d.py b/Examples/Tests/collision/analysis_collision_2d.py index 29482909b2e..7e1d74001a3 100755 --- a/Examples/Tests/collision/analysis_collision_2d.py +++ b/Examples/Tests/collision/analysis_collision_2d.py @@ -26,16 +26,17 @@ import glob import math import os -import re import sys import numpy import post_processing_utils import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI +test_name = os.path.split(os.getcwd())[1] + tolerance = 0.001 ng = 64 @@ -43,7 +44,7 @@ ni = ng * 200 np = ne + ni -c = 299792458.0 +c = 299792458.0 me = 9.10938356e-31 mi = me * 5.0 @@ -51,48 +52,52 @@ ## fit. # exponential fit coefficients -a = 0.04330638981264072 +a = 0.04330638981264072 b = -0.11588277796546632 last_fn = sys.argv[1] -# Remove trailing '/' from file name, if necessary -last_fn.rstrip('/') -# Find last iteration in file name, such as 'test_name_plt000001' (last_it = '000001') -last_it = re.search('\d+', last_fn).group() -# Find output prefix in file name, such as 'test_name_plt000001' (prefix = 'test_name_plt') -prefix = last_fn[:-len(last_it)] +if last_fn[-1] == "/": + last_fn = last_fn[:-1] +last_it = last_fn[-6:] # i.e., 000150 +prefix = last_fn[:-6] # i.e., diags/diag1 + # Collect all output files in fn_list (names match pattern prefix + arbitrary number) -fn_list = glob.glob(prefix + '*[0-9]') +fn_list = glob.glob(prefix + "*[0-9]") + +print(last_fn) +print(last_it) +print(prefix) +print(fn_list) error = 0.0 nt = 0 for fn in fn_list: # load file - ds = yt.load( fn ) - ad = ds.all_data() - px = ad[('all', 'particle_momentum_x')].to_ndarray() + ds = yt.load(fn) + ad = ds.all_data() + px = ad[("all", "particle_momentum_x")].to_ndarray() # get time index j j = int(fn[-5:]) # compute error - vxe = numpy.mean(px[ 0:ne])/me/c - vxi = numpy.mean(px[ne:np])/mi/c + vxe = numpy.mean(px[0:ne]) / me / c + vxi = numpy.mean(px[ne:np]) / mi / c vxd = vxe - vxi - fit = a*math.exp(b*j) - error = error + abs(fit-vxd) + fit = a * math.exp(b * j) + error = error + abs(fit - vxd) nt = nt + 1 error = error / nt -print('error = ', error) -print('tolerance = ', tolerance) -assert(error < tolerance) +print("error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance # The second part of the analysis is not done for the Python test # since the particle filter function is not accessible from PICMI yet -if "Python" in last_fn: +if "picmi" in test_name: exit() -## In the second past of the test, we verify that the diagnostic particle filter function works as +## In the second part of the test, we verify that the diagnostic particle filter function works as ## expected. For this, we only use the last simulation timestep. dim = "2d" @@ -100,18 +105,20 @@ parser_filter_fn = "diags/diag_parser_filter" + last_it parser_filter_expression = "(x>200) * (z<200) * (px-3*pz>0)" -post_processing_utils.check_particle_filter(last_fn, parser_filter_fn, parser_filter_expression, - dim, species_name) +post_processing_utils.check_particle_filter( + last_fn, parser_filter_fn, parser_filter_expression, dim, species_name +) uniform_filter_fn = "diags/diag_uniform_filter" + last_it uniform_filter_expression = "ids%6 == 0" -post_processing_utils.check_particle_filter(last_fn, uniform_filter_fn, uniform_filter_expression, - dim, species_name) +post_processing_utils.check_particle_filter( + last_fn, uniform_filter_fn, uniform_filter_expression, dim, species_name +) random_filter_fn = "diags/diag_random_filter" + last_it random_fraction = 0.77 -post_processing_utils.check_random_filter(last_fn, random_filter_fn, random_fraction, - dim, species_name) +post_processing_utils.check_random_filter( + last_fn, random_filter_fn, random_fraction, dim, species_name +) -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, fn) +checksumAPI.evaluate_checksum(test_name, last_fn) diff --git a/Examples/Tests/collision/analysis_collision_3d.py b/Examples/Tests/collision/analysis_collision_3d.py index 86a434caab2..0a1b016a227 100755 --- a/Examples/Tests/collision/analysis_collision_3d.py +++ b/Examples/Tests/collision/analysis_collision_3d.py @@ -26,14 +26,13 @@ import glob import math import os -import re import sys import numpy import post_processing_utils import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI tolerance = 0.001 @@ -43,7 +42,7 @@ ni = ng * 200 np = ne + ni -c = 299792458.0 +c = 299792458.0 me = 9.10938356e-31 mi = me * 5.0 @@ -51,45 +50,44 @@ ## fit. # exponential fit coefficients -a = 0.041817463099883 +a = 0.041817463099883 b = -0.083851393560288 last_fn = sys.argv[1] -# Remove trailing '/' from file name, if necessary -last_fn.rstrip('/') -# Find last iteration in file name, such as 'test_name_plt000001' (last_it = '000001') -last_it = re.search('\d+', last_fn).group() -# Find output prefix in file name, such as 'test_name_plt000001' (prefix = 'test_name_plt') -prefix = last_fn[:-len(last_it)] +if last_fn[-1] == "/": + last_fn = last_fn[:-1] +last_it = last_fn[-6:] # i.e., 000150 +prefix = last_fn[:-6] # i.e., diags/diag1 + # Collect all output files in fn_list (names match pattern prefix + arbitrary number) -fn_list = glob.glob(prefix + '*[0-9]') +fn_list = glob.glob(prefix + "*[0-9]") error = 0.0 nt = 0 for fn in fn_list: # load file - ds = yt.load( fn ) - ad = ds.all_data() - pxe = ad['electron', 'particle_momentum_x'].to_ndarray() - pxi = ad['ion', 'particle_momentum_x'].to_ndarray() + ds = yt.load(fn) + ad = ds.all_data() + pxe = ad["electron", "particle_momentum_x"].to_ndarray() + pxi = ad["ion", "particle_momentum_x"].to_ndarray() # get time index j j = int(fn[-5:]) # compute error - vxe = numpy.mean(pxe)/me/c - vxi = numpy.mean(pxi)/mi/c + vxe = numpy.mean(pxe) / me / c + vxi = numpy.mean(pxi) / mi / c vxd = vxe - vxi - fit = a*math.exp(b*j) - error = error + abs(fit-vxd) + fit = a * math.exp(b * j) + error = error + abs(fit - vxd) nt = nt + 1 error = error / nt -print('error = ', error) -print('tolerance = ', tolerance) -assert(error < tolerance) +print("error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance -## In the second past of the test, we verify that the diagnostic particle filter function works as +## In the second part of the test, we verify that the diagnostic particle filter function works as ## expected. For this, we only use the last simulation timestep. dim = "3d" @@ -97,18 +95,21 @@ parser_filter_fn = "diags/diag_parser_filter" + last_it parser_filter_expression = "(px*py*pz < 0) * (np.sqrt(x**2+y**2+z**2)<100)" -post_processing_utils.check_particle_filter(last_fn, parser_filter_fn, parser_filter_expression, - dim, species_name) +post_processing_utils.check_particle_filter( + last_fn, parser_filter_fn, parser_filter_expression, dim, species_name +) uniform_filter_fn = "diags/diag_uniform_filter" + last_it uniform_filter_expression = "ids%11 == 0" -post_processing_utils.check_particle_filter(last_fn, uniform_filter_fn, uniform_filter_expression, - dim, species_name) +post_processing_utils.check_particle_filter( + last_fn, uniform_filter_fn, uniform_filter_expression, dim, species_name +) random_filter_fn = "diags/diag_random_filter" + last_it random_fraction = 0.88 -post_processing_utils.check_random_filter(last_fn, random_filter_fn, random_fraction, - dim, species_name) +post_processing_utils.check_random_filter( + last_fn, random_filter_fn, random_fraction, dim, species_name +) test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, fn) +checksumAPI.evaluate_checksum(test_name, last_fn) diff --git a/Examples/Tests/collision/analysis_collision_3d_isotropization.py b/Examples/Tests/collision/analysis_collision_3d_isotropization.py index ba029760e8b..6386ce74812 100755 --- a/Examples/Tests/collision/analysis_collision_3d_isotropization.py +++ b/Examples/Tests/collision/analysis_collision_3d_isotropization.py @@ -18,7 +18,7 @@ import scipy.constants as sc import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI e = sc.e @@ -29,34 +29,40 @@ dt = 1.4e-17 ne = 1.116e28 log = 2.0 -T_par = 5.62*e -T_per = 5.1*e +T_par = 5.62 * e +T_per = 5.1 * e -A = 1.0 - T_per/T_par -mu = (e**4*ne*log/(8.0*pi**1.5*ep0**2*m**0.5*T_par**1.5) - *A**(-2)*(-3.0+(3.0-A)*np.arctanh(A**0.5)/A**0.5)) +A = 1.0 - T_per / T_par +mu = ( + e**4 + * ne + * log + / (8.0 * pi**1.5 * ep0**2 * m**0.5 * T_par**1.5) + * A ** (-2) + * (-3.0 + (3.0 - A) * np.arctanh(A**0.5) / A**0.5) +) fn = sys.argv[1] ds = yt.load(fn) ad = ds.all_data() -vx = ad['electron', 'particle_momentum_x'].to_ndarray()/m -vy = ad['electron', 'particle_momentum_y'].to_ndarray()/m -Tx = np.mean(vx**2)*m/e -Ty = np.mean(vy**2)*m/e +vx = ad["electron", "particle_momentum_x"].to_ndarray() / m +vy = ad["electron", "particle_momentum_y"].to_ndarray() / m +Tx = np.mean(vx**2) * m / e +Ty = np.mean(vy**2) * m / e nt = 100 Tx0 = T_par Ty0 = T_per -for _ in range(nt-1): - Tx0 = Tx0 + dt*mu*(Ty0-Tx0)*2.0 - Ty0 = Ty0 + dt*mu*(Tx0-Ty0) +for _ in range(nt - 1): + Tx0 = Tx0 + dt * mu * (Ty0 - Tx0) * 2.0 + Ty0 = Ty0 + dt * mu * (Tx0 - Ty0) tolerance = 0.05 -error = np.maximum(abs(Tx-Tx0/e)/Tx, abs(Ty-Ty0/e)/Ty) +error = np.maximum(abs(Tx - Tx0 / e) / Tx, abs(Ty - Ty0 / e) / Ty) -print(f'error = {error}') -print(f'tolerance = {tolerance}') -assert(error < tolerance) +print(f"error = {error}") +print(f"tolerance = {tolerance}") +assert error < tolerance test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/collision/analysis_collision_rz.py b/Examples/Tests/collision/analysis_collision_rz.py index b206b2eba7b..168d8a8a7cf 100755 --- a/Examples/Tests/collision/analysis_collision_rz.py +++ b/Examples/Tests/collision/analysis_collision_rz.py @@ -23,36 +23,37 @@ import numpy as np import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI tolerance = 1.0e-15 last_fn = sys.argv[1] -if (last_fn[-1] == "/"): last_fn = last_fn[:-1] +if last_fn[-1] == "/": + last_fn = last_fn[:-1] fn_list = glob(last_fn[:-5] + "?????") for fn in fn_list: # get time index j j = int(fn[-5:]) - if j==0: + if j == 0: # load file - ds = yt.load( fn ) + ds = yt.load(fn) ad = ds.all_data() - px1 = ad['particle_momentum_x'].to_ndarray() - py1 = ad['particle_momentum_y'].to_ndarray() - if j==150: + px1 = ad["particle_momentum_x"].to_ndarray() + py1 = ad["particle_momentum_y"].to_ndarray() + if j == 150: # load file - ds = yt.load( fn ) + ds = yt.load(fn) ad = ds.all_data() - px2 = ad['particle_momentum_x'].to_ndarray() - py2 = ad['particle_momentum_y'].to_ndarray() + px2 = ad["particle_momentum_x"].to_ndarray() + py2 = ad["particle_momentum_y"].to_ndarray() -error = np.max( abs(px1-px2)+abs(py1-py2) ) +error = np.max(abs(px1 - px2) + abs(py1 - py2)) -print('error = ', error) -print('tolerance = ', tolerance) -assert(error < tolerance) +print("error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, fn, do_particles=False) +checksumAPI.evaluate_checksum(test_name, last_fn, do_particles=False) diff --git a/Examples/Tests/collision/inputs_test_1d_collision_z b/Examples/Tests/collision/inputs_test_1d_collision_z new file mode 100644 index 00000000000..b2de17192ae --- /dev/null +++ b/Examples/Tests/collision/inputs_test_1d_collision_z @@ -0,0 +1,90 @@ +################################# +########## CONSTANTS ############ +################################# + +my_constants.nA = 1.e25 # m^-3 +my_constants.NpA = 400 # m^-3 +my_constants.UA = 6.55e5 # m/s +my_constants.TA = 500. # eV +# +my_constants.nB = 1.e26 # m^-3 +my_constants.NpB = 400 # m^-3 +my_constants.UB = 0. # m/s +my_constants.TB = 500. # eV +# +my_constants.q_c12 = 6.*q_e +my_constants.m_c12 = 12.*m_u - 6.*m_e + +################################# +####### GENERAL PARAMETERS ###### +################################# +max_step = 600 +amr.n_cell = 180 +amr.max_level = 0 +amr.blocking_factor = 4 +geometry.dims = 1 +geometry.prob_lo = 0. +geometry.prob_hi = 0.01 + +################################# +###### Boundary Condition ####### +################################# +boundary.field_lo = periodic +boundary.field_hi = periodic + +################################# +############ NUMERICS ########### +################################# +warpx.serialize_initial_conditions = 1 +warpx.verbose = 1 +warpx.const_dt = 0.05e-12 +warpx.use_filter = 0 + +# Do not evolve the E and B fields +algo.maxwell_solver = none + +# Order of particle shape factors +algo.particle_shape = 1 + +################################# +############ PLASMA ############# +################################# +particles.species_names = ions + +ions.charge = q_c12 +ions.mass = m_c12 +ions.do_not_deposit = 1 + +ions.injection_sources = groupA groupB + +ions.groupA.injection_style = "NUniformPerCell" +ions.groupA.num_particles_per_cell_each_dim = NpA +ions.groupA.profile = constant +ions.groupA.density = nA # number per m^3 +ions.groupA.momentum_distribution_type = "gaussian" +ions.groupA.uz_m = UA/clight +ions.groupA.ux_th = sqrt(TA*q_e/m_c12)/clight +ions.groupA.uy_th = sqrt(TA*q_e/m_c12)/clight +ions.groupA.uz_th = sqrt(TA*q_e/m_c12)/clight + +ions.groupB.injection_style = "NUniformPerCell" +ions.groupB.num_particles_per_cell_each_dim = NpB +ions.groupB.profile = constant +ions.groupB.density = nB # number per m^3 +ions.groupB.momentum_distribution_type = "gaussian" +ions.groupB.uz_m = UB/clight +ions.groupB.ux_th = sqrt(TB*q_e/m_c12)/clight +ions.groupB.uy_th = sqrt(TB*q_e/m_c12)/clight +ions.groupB.uz_th = sqrt(TB*q_e/m_c12)/clight + +################################# +############ COLLISION ########## +################################# +collisions.collision_names = collision1 +collision1.species = ions ions +collision1.CoulombLog = 10.0 + +# Diagnostics +diagnostics.diags_names = diag1 +diag1.intervals = 600 +diag1.diag_type = Full diff --git a/Examples/Tests/collision/inputs_2d b/Examples/Tests/collision/inputs_test_2d_collision_xz similarity index 100% rename from Examples/Tests/collision/inputs_2d rename to Examples/Tests/collision/inputs_test_2d_collision_xz diff --git a/Examples/Tests/collision/PICMI_inputs_2d.py b/Examples/Tests/collision/inputs_test_2d_collision_xz_picmi.py similarity index 70% rename from Examples/Tests/collision/PICMI_inputs_2d.py rename to Examples/Tests/collision/inputs_test_2d_collision_xz_picmi.py index 99e217b0afc..7bc83a1e801 100755 --- a/Examples/Tests/collision/PICMI_inputs_2d.py +++ b/Examples/Tests/collision/inputs_test_2d_collision_xz_picmi.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # # --- Input file for binary Coulomb collision testing. This input script -# --- runs the same test as inputs_2d but via Python, therefore the input +# --- runs the same test as inputs_test_2d_collision_xz but via Python, therefore the input # --- values where directly copied from inputs_2d. from pywarpx import picmi @@ -25,8 +25,8 @@ ymax = xmax plasma_density = 1e21 -elec_rms_velocity = 0.044237441120300*constants.c -ion_rms_velocity = 0.006256118919701*constants.c +elec_rms_velocity = 0.044237441120300 * constants.c +ion_rms_velocity = 0.006256118919701 * constants.c number_per_cell = 200 ################################# @@ -45,26 +45,28 @@ elec_dist = picmi.UniformDistribution( density=plasma_density, - rms_velocity=[elec_rms_velocity]*3, - directed_velocity=[elec_rms_velocity, 0., 0.] + rms_velocity=[elec_rms_velocity] * 3, + directed_velocity=[elec_rms_velocity, 0.0, 0.0], ) ion_dist = picmi.UniformDistribution( density=plasma_density, - rms_velocity=[ion_rms_velocity]*3, + rms_velocity=[ion_rms_velocity] * 3, ) electrons = picmi.Species( - particle_type='electron', name='electron', + particle_type="electron", + name="electron", warpx_do_not_deposit=1, initial_distribution=elec_dist, ) ions = picmi.Species( - particle_type='H', - name='ion', charge='q_e', + particle_type="H", + name="ion", + charge="q_e", mass="5*m_e", warpx_do_not_deposit=1, - initial_distribution=ion_dist + initial_distribution=ion_dist, ) ################################# @@ -72,19 +74,13 @@ ################################# collision1 = picmi.CoulombCollisions( - name='collisions1', - species=[electrons, ions], - CoulombLog=15.9 + name="collisions1", species=[electrons, ions], CoulombLog=15.9 ) collision2 = picmi.CoulombCollisions( - name='collisions2', - species=[electrons, electrons], - CoulombLog=15.9 + name="collisions2", species=[electrons, electrons], CoulombLog=15.9 ) collision3 = picmi.CoulombCollisions( - name='collisions3', - species=[ions, ions], - CoulombLog=15.9 + name="collisions3", species=[ions, ions], CoulombLog=15.9 ) ################################# @@ -97,8 +93,8 @@ warpx_blocking_factor=max_grid_size, lower_bound=[xmin, ymin], upper_bound=[xmax, ymax], - lower_boundary_conditions=['periodic', 'periodic'], - upper_boundary_conditions=['periodic', 'periodic'], + lower_boundary_conditions=["periodic", "periodic"], + upper_boundary_conditions=["periodic", "periodic"], ) solver = picmi.ElectromagneticSolver(grid=grid, cfl=cfl) @@ -106,19 +102,12 @@ ######### DIAGNOSTICS ########### ################################# -particle_diag = picmi.ParticleDiagnostic( - name='diag1', - period=10, - write_dir='.', - warpx_file_prefix='Python_collisionXZ_plt' -) +particle_diag = picmi.ParticleDiagnostic(name="diag1", period=10) field_diag = picmi.FieldDiagnostic( - name='diag1', + name="diag1", grid=grid, period=10, data_list=[], - write_dir='.', - warpx_file_prefix='Python_collisionXZ_plt' ) ################################# @@ -130,20 +119,20 @@ max_steps=max_steps, verbose=verbose, warpx_serialize_initial_conditions=serialize_initial_conditions, - warpx_collisions=[collision1, collision2, collision3] + warpx_collisions=[collision1, collision2, collision3], ) sim.add_species( electrons, layout=picmi.PseudoRandomLayout( n_macroparticles_per_cell=number_per_cell, grid=grid - ) + ), ) sim.add_species( ions, layout=picmi.PseudoRandomLayout( n_macroparticles_per_cell=number_per_cell, grid=grid - ) + ), ) sim.add_diagnostic(particle_diag) @@ -153,5 +142,5 @@ ##### SIMULATION EXECUTION ###### ################################# -#sim.write_input_file('PICMI_inputs_2d') +# sim.write_input_file('inputs_test_2d_collision_xz') sim.step(max_steps) diff --git a/Examples/Tests/collision/inputs_3d_isotropization b/Examples/Tests/collision/inputs_test_3d_collision_iso similarity index 100% rename from Examples/Tests/collision/inputs_3d_isotropization rename to Examples/Tests/collision/inputs_test_3d_collision_iso diff --git a/Examples/Tests/collision/inputs_3d b/Examples/Tests/collision/inputs_test_3d_collision_xyz similarity index 100% rename from Examples/Tests/collision/inputs_3d rename to Examples/Tests/collision/inputs_test_3d_collision_xyz diff --git a/Examples/Tests/collision/inputs_rz b/Examples/Tests/collision/inputs_test_rz_collision similarity index 100% rename from Examples/Tests/collision/inputs_rz rename to Examples/Tests/collision/inputs_test_rz_collision diff --git a/Examples/Tests/diff_lumi_diag/CMakeLists.txt b/Examples/Tests/diff_lumi_diag/CMakeLists.txt new file mode 100644 index 00000000000..1651d74115e --- /dev/null +++ b/Examples/Tests/diff_lumi_diag/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_diff_lumi_diag # name + 3 # dims + 2 # nprocs + inputs_test_3d_diff_lumi_diag # inputs + analysis.py # analysis + diags/diag1000080 # output + OFF # dependency +) diff --git a/Examples/Tests/diff_lumi_diag/analysis.py b/Examples/Tests/diff_lumi_diag/analysis.py new file mode 100755 index 00000000000..ef573fc4863 --- /dev/null +++ b/Examples/Tests/diff_lumi_diag/analysis.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# This test checks the differential luminosity of the beam-beam interaction +# in the case of two Gaussian beams crossing rigidly at the interaction point. +# The beams have a Gaussian distribution both in energy and in transverse positions. +# In that case, the differential luminosity can be calculated analytically. + +import os +import sys + +import numpy as np +from read_raw_data import read_reduced_diags_histogram + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# Extract the differential luminosity from the file +_, _, E_bin, bin_data = read_reduced_diags_histogram( + "./diags/reducedfiles/DifferentialLuminosity_beam1_beam2.txt" +) +dL_dE_sim = bin_data[-1] # Differential luminosity at the end of the simulation + +# Beam parameters +N = 1.2e10 +E_beam = 125e9 # in eV +sigma_x = 500e-9 +sigma_y = 10e-9 + +# Compute the analytical differential luminosity for 2 Gaussian beams +sigma_E1 = 0.02 * E_beam +sigma_E2 = 0.03 * E_beam +sigma_E = np.sqrt( + sigma_E1**2 + sigma_E2**2 +) # Expected width of the differential luminosity +dL_dE_th = ( + N**2 + / (2 * (2 * np.pi) ** 1.5 * sigma_x * sigma_y * sigma_E) + * np.exp(-((E_bin - 2 * E_beam) ** 2) / (2 * sigma_E**2)) +) + +# Check that the simulation result and analytical result match +error = abs(dL_dE_sim - dL_dE_th).max() / abs(dL_dE_th).max() +tol = 1e-2 +print("Relative error: ", error) +print("Tolerance: ", tol) +assert error < tol + +# Get name of the test +fn = sys.argv[1] +test_name = os.path.split(os.getcwd())[1] + +# Run checksum regression test +checksumAPI.evaluate_checksum(test_name, fn, rtol=1e-2) diff --git a/Examples/Tests/diff_lumi_diag/inputs_test_3d_diff_lumi_diag b/Examples/Tests/diff_lumi_diag/inputs_test_3d_diff_lumi_diag new file mode 100644 index 00000000000..e8854937b6e --- /dev/null +++ b/Examples/Tests/diff_lumi_diag/inputs_test_3d_diff_lumi_diag @@ -0,0 +1,126 @@ +################################# +########## MY CONSTANTS ######### +################################# +my_constants.mc2_eV = m_e*clight*clight/q_e + +# BEAMS +my_constants.beam_energy_eV = 125.e9 +my_constants.beam_gamma = beam_energy_eV/(mc2_eV) +my_constants.beam_charge = 1.2e10*q_e +my_constants.sigmax = 500e-9 +my_constants.sigmay = 10e-9 +my_constants.sigmaz = 300e-3 +my_constants.muz = -4*sigmaz +my_constants.nmacropart = 2e5 + +# BOX +my_constants.Lx = 8*sigmax +my_constants.Ly = 8*sigmay +my_constants.Lz = 16*sigmaz + +my_constants.nx = 64 +my_constants.ny = 64 +my_constants.nz = 128 + +# TIME +my_constants.T = 0.5*Lz/clight +my_constants.dt = sigmaz/clight/10. + +################################# +####### GENERAL PARAMETERS ###### +################################# +stop_time = T +amr.n_cell = nx ny nz +amr.max_grid_size = 128 +amr.blocking_factor = 2 +amr.max_level = 0 +geometry.dims = 3 +geometry.prob_lo = -0.5*Lx -0.5*Ly -0.5*Lz +geometry.prob_hi = 0.5*Lx 0.5*Ly 0.5*Lz + +################################# +######## BOUNDARY CONDITION ##### +################################# +boundary.field_lo = open open open +boundary.field_hi = open open open +boundary.particle_lo = Absorbing Absorbing Absorbing +boundary.particle_hi = Absorbing Absorbing Absorbing + +################################# +############ NUMERICS ########### +################################# +warpx.do_electrostatic = relativistic +warpx.const_dt = dt +warpx.grid_type = collocated +algo.particle_shape = 3 +algo.load_balance_intervals=100 +algo.particle_pusher = vay +warpx.poisson_solver = fft + +################################# +########### PARTICLES ########### +################################# +particles.species_names = beam1 beam2 + +beam1.species_type = electron +beam1.injection_style = gaussian_beam +beam1.x_rms = sigmax +beam1.y_rms = sigmay +beam1.z_rms = sigmaz +beam1.x_m = 0 +beam1.y_m = 0 +beam1.z_m = muz +beam1.npart = nmacropart +beam1.q_tot = -beam_charge +beam1.z_cut = 4 +beam1.momentum_distribution_type = gaussian +beam1.uz_m = beam_gamma +beam1.uy_m = 0.0 +beam1.ux_m = 0.0 +beam1.ux_th = 0 +beam1.uy_th = 0 +beam1.uz_th = 0.02*beam_gamma +beam1.do_not_deposit = 1 + +beam2.species_type = positron +beam2.injection_style = gaussian_beam +beam2.x_rms = sigmax +beam2.y_rms = sigmay +beam2.z_rms = sigmaz +beam2.x_m = 0 +beam2.y_m = 0 +beam2.z_m = -muz +beam2.npart = nmacropart +beam2.q_tot = beam_charge +beam2.z_cut = 4 +beam2.momentum_distribution_type = gaussian +beam2.uz_m = -beam_gamma +beam2.uy_m = 0.0 +beam2.ux_m = 0.0 +beam2.ux_th = 0 +beam2.uy_th = 0 +beam2.uz_th = 0.03*beam_gamma +beam2.do_not_deposit = 1 + +################################# +######### DIAGNOSTICS ########### +################################# +# FULL +diagnostics.diags_names = diag1 + +diag1.intervals = 1 +diag1.diag_type = Full +diag1.write_species = 1 +diag1.fields_to_plot = rho_beam1 rho_beam2 +diag1.dump_last_timestep = 1 +diag1.species = beam1 beam2 + +# REDUCED +warpx.reduced_diags_names = DifferentialLuminosity_beam1_beam2 + +DifferentialLuminosity_beam1_beam2.type = DifferentialLuminosity +DifferentialLuminosity_beam1_beam2.intervals = 5 +DifferentialLuminosity_beam1_beam2.species = beam1 beam2 +DifferentialLuminosity_beam1_beam2.bin_number = 128 +DifferentialLuminosity_beam1_beam2.bin_max = 2.1*beam_energy_eV +DifferentialLuminosity_beam1_beam2.bin_min = 1.9*beam_energy_eV diff --git a/Examples/Tests/divb_cleaning/CMakeLists.txt b/Examples/Tests/divb_cleaning/CMakeLists.txt new file mode 100644 index 00000000000..d4aae31472e --- /dev/null +++ b/Examples/Tests/divb_cleaning/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_divb_cleaning # name + 3 # dims + 2 # nprocs + inputs_test_3d_divb_cleaning # inputs + analysis.py # analysis + diags/diag1000400 # output + OFF # dependency +) diff --git a/Examples/Tests/divb_cleaning/analysis.py b/Examples/Tests/divb_cleaning/analysis.py index a3523218ca6..e534e5b0d59 100755 --- a/Examples/Tests/divb_cleaning/analysis.py +++ b/Examples/Tests/divb_cleaning/analysis.py @@ -8,7 +8,7 @@ import sys -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import os import numpy as np @@ -24,17 +24,23 @@ fn = sys.argv[1] # Load yt data -ds_old = yt.load('divb_cleaning_3d_plt000398') -ds_mid = yt.load('divb_cleaning_3d_plt000399') -ds_new = yt.load(fn) # this is the last plotfile - -ad_old = ds_old.covering_grid(level = 0, left_edge = ds_old.domain_left_edge, dims = ds_old.domain_dimensions) -ad_mid = ds_mid.covering_grid(level = 0, left_edge = ds_mid.domain_left_edge, dims = ds_mid.domain_dimensions) -ad_new = ds_new.covering_grid(level = 0, left_edge = ds_new.domain_left_edge, dims = ds_new.domain_dimensions) - -G_old = ad_old['boxlib', 'G'].v.squeeze() -G_new = ad_new['boxlib', 'G'].v.squeeze() -divB = ad_mid['boxlib', 'divB'].v.squeeze() +ds_old = yt.load("diags/diag1000398") +ds_mid = yt.load("diags/diag1000399") +ds_new = yt.load(fn) # this is the last plotfile + +ad_old = ds_old.covering_grid( + level=0, left_edge=ds_old.domain_left_edge, dims=ds_old.domain_dimensions +) +ad_mid = ds_mid.covering_grid( + level=0, left_edge=ds_mid.domain_left_edge, dims=ds_mid.domain_dimensions +) +ad_new = ds_new.covering_grid( + level=0, left_edge=ds_new.domain_left_edge, dims=ds_new.domain_dimensions +) + +G_old = ad_old["boxlib", "G"].v.squeeze() +G_new = ad_new["boxlib", "G"].v.squeeze() +divB = ad_mid["boxlib", "divB"].v.squeeze() # Check max norm of error on c2 * div(B) = dG/dt # (the time interval between old and new is 2*dt) @@ -45,11 +51,11 @@ rel_error = np.amax(abs(x - y)) / np.amax(abs(y)) tolerance = 1e-1 -assert(rel_error < tolerance) +assert rel_error < tolerance test_name = os.path.split(os.getcwd())[1] -if re.search('single_precision', fn): - checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, rtol=1.0e-3) else: checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/divb_cleaning/inputs_3d b/Examples/Tests/divb_cleaning/inputs_test_3d_divb_cleaning similarity index 100% rename from Examples/Tests/divb_cleaning/inputs_3d rename to Examples/Tests/divb_cleaning/inputs_test_3d_divb_cleaning diff --git a/Examples/Tests/dive_cleaning/CMakeLists.txt b/Examples/Tests/dive_cleaning/CMakeLists.txt new file mode 100644 index 00000000000..c23c2aef539 --- /dev/null +++ b/Examples/Tests/dive_cleaning/CMakeLists.txt @@ -0,0 +1,22 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_dive_cleaning # name + 2 # dims + 2 # nprocs + inputs_test_2d_dive_cleaning # inputs + analysis.py # analysis + diags/diag1000128 # output + OFF # dependency +) + +add_warpx_test( + test_3d_dive_cleaning # name + 3 # dims + 2 # nprocs + inputs_test_3d_dive_cleaning # inputs + analysis.py # analysis + diags/diag1000128 # output + OFF # dependency +) diff --git a/Examples/Tests/dive_cleaning/analysis.py b/Examples/Tests/dive_cleaning/analysis.py index a9b52455baa..9d92767fa05 100755 --- a/Examples/Tests/dive_cleaning/analysis.py +++ b/Examples/Tests/dive_cleaning/analysis.py @@ -14,11 +14,12 @@ This script verifies that the field at the end of the simulation corresponds to the theoretical field of a Gaussian beam. """ + import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np import scipy.constants as scc @@ -28,88 +29,101 @@ yt.funcs.mylog.setLevel(0) # Parameters from the Simulation -Qtot = -1.e-20 -r0 = 2.e-6 +Qtot = -1.0e-20 +r0 = 2.0e-6 # Open data file filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. -if 'force_periodicity' in dir(ds): ds.force_periodicity() +if "force_periodicity" in dir(ds): + ds.force_periodicity() # Extract data -ad0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) +ad0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) Ex_array = ad0[("mesh", "Ex")].to_ndarray().squeeze() if ds.dimensionality == 2: # Rename the z dimension as y, so as to make this script work for 2d and 3d Ey_array = ad0[("mesh", "Ez")].to_ndarray().squeeze() - E_array = ( Ex_array**2 + Ey_array**2 )**.5 + E_array = (Ex_array**2 + Ey_array**2) ** 0.5 relative_tolerance = 0.1 elif ds.dimensionality == 3: Ey_array = ad0[("mesh", "Ey")].to_ndarray() Ez_array = ad0[("mesh", "Ez")].to_ndarray() - E_array = ( Ex_array**2 + Ey_array**2 + Ez_array**2 )**.5 + E_array = (Ex_array**2 + Ey_array**2 + Ez_array**2) ** 0.5 relative_tolerance = 0.165 # Extract grid coordinates -Nx, Ny, Nz = ds.domain_dimensions +Nx, Ny, Nz = ds.domain_dimensions xmin, ymin, zmin = ds.domain_left_edge.v Lx, Ly, Lz = ds.domain_width.v -x = xmin + Lx/Nx*(0.5+np.arange(Nx)) -y = ymin + Ly/Ny*(0.5+np.arange(Ny)) -z = zmin + Lz/Nz*(0.5+np.arange(Nz)) +x = xmin + Lx / Nx * (0.5 + np.arange(Nx)) +y = ymin + Ly / Ny * (0.5 + np.arange(Ny)) +z = zmin + Lz / Nz * (0.5 + np.arange(Nz)) # Compute theoretical field if ds.dimensionality == 2: - x_2d, y_2d = np.meshgrid(x, y, indexing='ij') + x_2d, y_2d = np.meshgrid(x, y, indexing="ij") r2 = x_2d**2 + y_2d**2 - factor = (Qtot/r0)/(2*np.pi*scc.epsilon_0*r2) * (1-np.exp(-r2/(2*r0**2))) + factor = ( + (Qtot / r0) / (2 * np.pi * scc.epsilon_0 * r2) * (1 - np.exp(-r2 / (2 * r0**2))) + ) Ex_th = x_2d * factor Ey_th = y_2d * factor - E_th = ( Ex_th**2 + Ey_th**2 )**.5 + E_th = (Ex_th**2 + Ey_th**2) ** 0.5 elif ds.dimensionality == 3: - x_2d, y_2d, z_2d = np.meshgrid(x, y, z, indexing='ij') + x_2d, y_2d, z_2d = np.meshgrid(x, y, z, indexing="ij") r2 = x_2d**2 + y_2d**2 + z_2d**2 - factor = Qtot/(4*np.pi*scc.epsilon_0*r2**1.5) * gammainc(3./2, r2/(2.*r0**2)) - Ex_th = factor*x_2d - Ey_th = factor*y_2d - Ez_th = factor*z_2d - E_th = ( Ex_th**2 + Ey_th**2 + Ez_th**2 )**.5 + factor = ( + Qtot + / (4 * np.pi * scc.epsilon_0 * r2**1.5) + * gammainc(3.0 / 2, r2 / (2.0 * r0**2)) + ) + Ex_th = factor * x_2d + Ey_th = factor * y_2d + Ez_th = factor * z_2d + E_th = (Ex_th**2 + Ey_th**2 + Ez_th**2) ** 0.5 + # Plot theory and data def make_2d(arr): if arr.ndim == 3: - return arr[:,:,Nz//2] + return arr[:, :, Nz // 2] else: return arr -plt.figure(figsize=(10,10)) + + +plt.figure(figsize=(10, 10)) plt.subplot(221) -plt.title('E: Theory') +plt.title("E: Theory") plt.imshow(make_2d(E_th)) plt.colorbar() plt.subplot(222) -plt.title('E: Simulation') +plt.title("E: Simulation") plt.imshow(make_2d(E_array)) plt.colorbar() plt.subplot(223) -plt.title('E: Diff') -plt.imshow(make_2d(E_th-E_array)) +plt.title("E: Diff") +plt.imshow(make_2d(E_th - E_array)) plt.colorbar() plt.subplot(224) -plt.title('E: Relative diff') -plt.imshow(make_2d((E_th-E_array)/E_th)) +plt.title("E: Relative diff") +plt.imshow(make_2d((E_th - E_array) / E_th)) plt.colorbar() -plt.savefig('Comparison.png') +plt.savefig("Comparison.png") + # Automatically check the results def check(E, E_th, label): - print( 'Relative error in %s: %.3f'%( - label, abs(E-E_th).max()/E_th.max())) - assert np.allclose( E, E_th, atol=relative_tolerance*E_th.max() ) + print("Relative error in %s: %.3f" % (label, abs(E - E_th).max() / E_th.max())) + assert np.allclose(E, E_th, atol=relative_tolerance * E_th.max()) + -check( Ex_array, Ex_th, 'Ex' ) -check( Ey_array, Ey_th, 'Ey' ) +check(Ex_array, Ex_th, "Ex") +check(Ey_array, Ey_th, "Ey") if ds.dimensionality == 3: - check( Ez_array, Ez_th, 'Ez' ) + check(Ez_array, Ez_th, "Ez") diff --git a/Examples/Tests/dive_cleaning/inputs_test_2d_dive_cleaning b/Examples/Tests/dive_cleaning/inputs_test_2d_dive_cleaning new file mode 100644 index 00000000000..48cabee4495 --- /dev/null +++ b/Examples/Tests/dive_cleaning/inputs_test_2d_dive_cleaning @@ -0,0 +1,35 @@ +max_step = 128 +amr.n_cell = 64 64 +amr.max_grid_size = 32 +amr.max_level = 0 + +geometry.prob_lo = -50.e-6 -50.e-6 +geometry.prob_hi = 50.e-6 50.e-6 +geometry.dims = 2 + +boundary.field_lo = pml pml +boundary.field_hi = pml pml + +warpx.do_dive_cleaning = 1 +warpx.use_filter = 0 + +# Order of particle shape factors +algo.particle_shape = 1 + +particles.species_names = beam +beam.charge = -q_e +beam.mass = 1.e30 +beam.injection_style = "gaussian_beam" +beam.x_rms = 2.e-6 +beam.y_rms = 2.e-6 +beam.z_rms = 2.e-6 +beam.x_m = 0. +beam.y_m = 0. +beam.z_m = 0.e-6 +beam.npart = 20000 +beam.q_tot = -1.e-20 +beam.momentum_distribution_type = "at_rest" + +diagnostics.diags_names = diag1 +diag1.intervals = 8 +diag1.diag_type = Full diff --git a/Examples/Tests/dive_cleaning/inputs_3d b/Examples/Tests/dive_cleaning/inputs_test_3d_dive_cleaning similarity index 100% rename from Examples/Tests/dive_cleaning/inputs_3d rename to Examples/Tests/dive_cleaning/inputs_test_3d_dive_cleaning index c3f83ddbdd9..3f22a2206cf 100644 --- a/Examples/Tests/dive_cleaning/inputs_3d +++ b/Examples/Tests/dive_cleaning/inputs_test_3d_dive_cleaning @@ -3,9 +3,9 @@ amr.n_cell = 64 64 64 amr.max_grid_size = 32 amr.max_level = 0 -geometry.dims = 3 geometry.prob_lo = -50.e-6 -50.e-6 -50.e-6 geometry.prob_hi = 50.e-6 50.e-6 50.e-6 +geometry.dims = 3 boundary.field_lo = pml pml pml boundary.field_hi = pml pml pml diff --git a/Examples/Tests/electrostatic_dirichlet_bc/CMakeLists.txt b/Examples/Tests/electrostatic_dirichlet_bc/CMakeLists.txt new file mode 100644 index 00000000000..1325d1a6bf5 --- /dev/null +++ b/Examples/Tests/electrostatic_dirichlet_bc/CMakeLists.txt @@ -0,0 +1,22 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_dirichlet_bc # name + 2 # dims + 2 # nprocs + inputs_test_2d_dirichlet_bc # inputs + analysis.py # analysis + diags/diag1000100 # output + OFF # dependency +) + +add_warpx_test( + test_2d_dirichlet_bc_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_dirichlet_bc_picmi.py # inputs + analysis.py # analysis + diags/diag1000100 # output + OFF # dependency +) diff --git a/Examples/Tests/electrostatic_dirichlet_bc/analysis.py b/Examples/Tests/electrostatic_dirichlet_bc/analysis.py index eae2f17243c..82fe061c3a8 100755 --- a/Examples/Tests/electrostatic_dirichlet_bc/analysis.py +++ b/Examples/Tests/electrostatic_dirichlet_bc/analysis.py @@ -18,9 +18,7 @@ import numpy as np import yt -files = sorted(glob.glob('dirichletbc_plt*'))[1:] -if len(files) == 0: - files = sorted(glob.glob('Python_dirichletbc_plt*'))[1:] +files = sorted(glob.glob("diags/diag1*"))[1:] assert len(files) > 0 times = np.ones(len(files)) @@ -28,15 +26,13 @@ potentials_hi = np.zeros(len(files)) for ii, file in enumerate(files): - ds = yt.load( file ) - times[ii] = ( - ds.current_time.item() - ) + ds = yt.load(file) + times[ii] = ds.current_time.item() data = ds.covering_grid( level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions ) - potentials_lo[ii] = np.mean(data['phi'].to_ndarray()[0]) - potentials_hi[ii] = np.mean(data['phi'].to_ndarray()[-1]) + potentials_lo[ii] = np.mean(data["phi"].to_ndarray()[0]) + potentials_hi[ii] = np.mean(data["phi"].to_ndarray()[-1]) expected_potentials_lo = 150.0 * np.sin(2.0 * np.pi * 6.78e6 * times) expected_potentials_hi = 450.0 * np.sin(2.0 * np.pi * 13.56e6 * times) diff --git a/Examples/Tests/electrostatic_dirichlet_bc/inputs_2d b/Examples/Tests/electrostatic_dirichlet_bc/inputs_test_2d_dirichlet_bc similarity index 93% rename from Examples/Tests/electrostatic_dirichlet_bc/inputs_2d rename to Examples/Tests/electrostatic_dirichlet_bc/inputs_test_2d_dirichlet_bc index d501dac7d0c..46b00819926 100644 --- a/Examples/Tests/electrostatic_dirichlet_bc/inputs_2d +++ b/Examples/Tests/electrostatic_dirichlet_bc/inputs_test_2d_dirichlet_bc @@ -1,5 +1,6 @@ max_step = 100 warpx.verbose = 0 +warpx.abort_on_warning_threshold = medium warpx.const_dt = 7.5e-10 warpx.do_electrostatic = labframe warpx.self_fields_required_precision = 1e-06 diff --git a/Examples/Tests/electrostatic_dirichlet_bc/PICMI_inputs_2d.py b/Examples/Tests/electrostatic_dirichlet_bc/inputs_test_2d_dirichlet_bc_picmi.py similarity index 51% rename from Examples/Tests/electrostatic_dirichlet_bc/PICMI_inputs_2d.py rename to Examples/Tests/electrostatic_dirichlet_bc/inputs_test_2d_dirichlet_bc_picmi.py index e4dd530c3bc..0c30e84d781 100755 --- a/Examples/Tests/electrostatic_dirichlet_bc/PICMI_inputs_2d.py +++ b/Examples/Tests/electrostatic_dirichlet_bc/inputs_test_2d_dirichlet_bc_picmi.py @@ -36,21 +36,21 @@ ########################## grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, ny], - lower_bound = [xmin, ymin], - upper_bound = [xmax, ymax], - lower_boundary_conditions = ['dirichlet', 'periodic'], - upper_boundary_conditions = ['dirichlet', 'periodic'], - lower_boundary_conditions_particles = ['absorbing', 'periodic'], - upper_boundary_conditions_particles = ['absorbing', 'periodic'], - warpx_potential_lo_x = V_xmin, - warpx_potential_hi_x = V_xmax, - moving_window_velocity = None, - warpx_max_grid_size = 32 + number_of_cells=[nx, ny], + lower_bound=[xmin, ymin], + upper_bound=[xmax, ymax], + lower_boundary_conditions=["dirichlet", "periodic"], + upper_boundary_conditions=["dirichlet", "periodic"], + lower_boundary_conditions_particles=["absorbing", "periodic"], + upper_boundary_conditions_particles=["absorbing", "periodic"], + warpx_potential_lo_x=V_xmin, + warpx_potential_hi_x=V_xmax, + moving_window_velocity=None, + warpx_max_grid_size=32, ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-6 + grid=grid, method="Multigrid", required_precision=1e-6 ) @@ -58,19 +58,12 @@ # diagnostics ########################## -particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 4, - write_dir = '.', - warpx_file_prefix = 'Python_dirichletbc_plt' -) +particle_diag = picmi.ParticleDiagnostic(name="diag1", period=4) field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 4, - data_list = ['phi'], - write_dir = '.', - warpx_file_prefix = 'Python_dirichletbc_plt' + name="diag1", + grid=grid, + period=4, + data_list=["phi"], ) ########################## @@ -78,11 +71,11 @@ ########################## sim = picmi.Simulation( - solver = solver, - time_step_size = dt, - max_steps = max_steps, - particle_shape = None, - verbose = 0 + solver=solver, + time_step_size=dt, + max_steps=max_steps, + particle_shape=None, + verbose=0, ) sim.add_diagnostic(particle_diag) @@ -94,7 +87,7 @@ # write_inputs will create an inputs file that can be used to run # with the compiled version. -#sim.write_input_file(file_name = 'inputs_from_PICMI') +# sim.write_input_file(file_name = 'inputs_from_PICMI') # Alternatively, sim.step will run WarpX, controlling it from Python sim.step(max_steps) diff --git a/Examples/Tests/electrostatic_sphere/CMakeLists.txt b/Examples/Tests/electrostatic_sphere/CMakeLists.txt new file mode 100644 index 00000000000..41a151b7884 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere/CMakeLists.txt @@ -0,0 +1,52 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_electrostatic_sphere # name + 3 # dims + 2 # nprocs + inputs_test_3d_electrostatic_sphere # inputs + analysis_electrostatic_sphere.py # analysis + diags/diag1000030 # output + OFF # dependency +) + +add_warpx_test( + test_3d_electrostatic_sphere_lab_frame # name + 3 # dims + 2 # nprocs + inputs_test_3d_electrostatic_sphere_lab_frame # inputs + analysis_electrostatic_sphere.py # analysis + diags/diag1000030 # output + OFF # dependency +) + +add_warpx_test( + test_3d_electrostatic_sphere_lab_frame_mr_emass_10 # name + 3 # dims + 2 # nprocs + inputs_test_3d_electrostatic_sphere_lab_frame_mr_emass_10 # inputs + analysis_electrostatic_sphere.py # analysis + diags/diag1000002 # output + OFF # dependency +) + +add_warpx_test( + test_3d_electrostatic_sphere_rel_nodal # name + 3 # dims + 2 # nprocs + inputs_test_3d_electrostatic_sphere_rel_nodal # inputs + analysis_electrostatic_sphere.py # analysis + diags/diag1000030 # output + OFF # dependency +) + +add_warpx_test( + test_rz_electrostatic_sphere # name + RZ # dims + 2 # nprocs + inputs_test_rz_electrostatic_sphere # inputs + analysis_electrostatic_sphere.py # analysis + diags/diag1000030 # output + OFF # dependency +) diff --git a/Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py b/Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py index e63a3f02ba8..33842058b0b 100755 --- a/Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py +++ b/Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py @@ -17,6 +17,7 @@ known analytic solution. While the radius r(t) is not analytically known, its inverse t(r) can be solved for exactly. """ + import os import re import sys @@ -27,53 +28,55 @@ from scipy.constants import c from scipy.optimize import fsolve -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI yt.funcs.mylog.setLevel(0) # Open plotfile specified in command line +test_name = os.path.split(os.getcwd())[1] filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) t_max = ds.current_time.item() # time of simulation # Parse test name and check if particle_shape = 4 is used -emass_10 = True if re.search('emass_10', filename) else False +emass_10 = True if re.search("emass_10", test_name) else False if emass_10: l2_tolerance = 0.096 m_e = 10 else: l2_tolerance = 0.05 - m_e = 9.10938356e-31 #Electron mass in kg + m_e = 9.10938356e-31 # Electron mass in kg ndims = np.count_nonzero(ds.domain_dimensions > 1) if ndims == 2: - xmin, zmin = [float(x) for x in ds.parameters.get('geometry.prob_lo').split()] - xmax, zmax = [float(x) for x in ds.parameters.get('geometry.prob_hi').split()] - nx, nz = [int(n) for n in ds.parameters['amr.n_cell'].split()] + xmin, zmin = [float(x) for x in ds.parameters.get("geometry.prob_lo").split()] + xmax, zmax = [float(x) for x in ds.parameters.get("geometry.prob_hi").split()] + nx, nz = [int(n) for n in ds.parameters["amr.n_cell"].split()] ymin, ymax = xmin, xmax ny = nx else: - xmin, ymin, zmin = [float(x) for x in ds.parameters.get('geometry.prob_lo').split()] - xmax, ymax, zmax = [float(x) for x in ds.parameters.get('geometry.prob_hi').split()] - nx, ny, nz = [int(n) for n in ds.parameters['amr.n_cell'].split()] + xmin, ymin, zmin = [float(x) for x in ds.parameters.get("geometry.prob_lo").split()] + xmax, ymax, zmax = [float(x) for x in ds.parameters.get("geometry.prob_hi").split()] + nx, ny, nz = [int(n) for n in ds.parameters["amr.n_cell"].split()] -dx = (xmax - xmin)/nx -dy = (ymax - ymin)/ny -dz = (zmax - zmin)/nz +dx = (xmax - xmin) / nx +dy = (ymax - ymin) / ny +dz = (zmax - zmin) / nz # Grid location of the axis -ix0 = round((0. - xmin)/dx) -iy0 = round((0. - ymin)/dy) -iz0 = round((0. - zmin)/dz) +ix0 = round((0.0 - xmin) / dx) +iy0 = round((0.0 - ymin) / dy) +iz0 = round((0.0 - zmin) / dz) # Constants -eps_0 = 8.8541878128e-12 #Vacuum Permittivity in C/(V*m) -q_e = -1.60217662e-19 #Electron charge in C -pi = np.pi #Circular constant of the universe -r_0 = 0.1 #Initial radius of sphere -q_tot = -1e-15 #Total charge of sphere in C +eps_0 = 8.8541878128e-12 # Vacuum Permittivity in C/(V*m) +q_e = -1.60217662e-19 # Electron charge in C +pi = np.pi # Circular constant of the universe +r_0 = 0.1 # Initial radius of sphere +q_tot = -1e-15 # Total charge of sphere in C + # Define functions for exact forms of v(r), t(r), Er(r) with r as the radius of # the sphere. The sphere starts with initial radius r_0 and this radius expands @@ -84,44 +87,61 @@ # r(0) = r_0, r'(0) = 0, and a = q_e*q_tot/(4*pi*eps_0*m_e) # # The E was calculated at the end of the last time step -v_exact = lambda r: np.sqrt((q_e*q_tot)/(2*pi*m_e*eps_0)*(1/r_0-1/r)) -t_exact = lambda r: np.sqrt(r_0**3*2*pi*m_e*eps_0/(q_e*q_tot)) \ - * (np.sqrt(r/r_0-1)*np.sqrt(r/r_0) \ - + np.log(np.sqrt(r/r_0-1)+np.sqrt(r/r_0))) -func = lambda rho: t_exact(rho) - t_max #Objective function to find r(t_max) -r_end = fsolve(func,r_0)[0] #Numerically solve for r(t_max) -E_exact = lambda r: np.sign(r)*(q_tot/(4*pi*eps_0*r**2)*(abs(r)>=r_end) \ - + q_tot*abs(r)/(4*pi*eps_0*r_end**3)*(abs(r)= r_end) + + q_tot * abs(r) / (4 * pi * eps_0 * r_end**3) * (abs(r) < r_end) + ) + # Load data pertaining to fields -data = ds.covering_grid(level=0, - left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) # Extract the E field along the axes # if ndims == 2: -if ds.parameters['geometry.dims'] == 'RZ': - Ex = data[('boxlib','Er')].to_ndarray() - Ex_axis = Ex[:,iz0,0] +if ds.parameters["geometry.dims"] == "RZ": + Ex = data[("boxlib", "Er")].to_ndarray() + Ex_axis = Ex[:, iz0, 0] Ey_axis = Ex_axis - Ez = data[('boxlib','Ez')].to_ndarray() - Ez_axis = Ez[ix0,:,0] + Ez = data[("boxlib", "Ez")].to_ndarray() + Ez_axis = Ez[ix0, :, 0] else: - Ex = data[('mesh','Ex')].to_ndarray() - Ex_axis = Ex[:,iy0,iz0] - Ey = data[('mesh','Ey')].to_ndarray() - Ey_axis = Ey[ix0,:,iz0] - Ez = data[('mesh','Ez')].to_ndarray() - Ez_axis = Ez[ix0,iy0,:] + Ex = data[("mesh", "Ex")].to_ndarray() + Ex_axis = Ex[:, iy0, iz0] + Ey = data[("mesh", "Ey")].to_ndarray() + Ey_axis = Ey[ix0, :, iz0] + Ez = data[("mesh", "Ez")].to_ndarray() + Ez_axis = Ez[ix0, iy0, :] + def calculate_error(E_axis, xmin, dx, nx): # Compute cell centers for grid - x_cell_centers = np.linspace(xmin+dx/2.,xmax-dx/2.,nx) + x_cell_centers = np.linspace(xmin + dx / 2.0, xmax - dx / 2.0, nx) # Extract subgrid away from boundary (exact solution assumes infinite/open # domain but WarpX solution assumes perfect conducting walls) - ix1 = round((xmin/2. - xmin)/dx) - ix2 = round((xmax/2. - xmin)/dx) + ix1 = round((xmin / 2.0 - xmin) / dx) + ix2 = round((xmax / 2.0 - xmin) / dx) x_sub_grid = x_cell_centers[ix1:ix2] # Exact solution of field along Cartesian axes @@ -131,37 +151,47 @@ def calculate_error(E_axis, xmin, dx, nx): E_grid = E_axis[ix1:ix2] # Define approximate L2 norm error between exact and numerical solutions - L2_error = (np.sqrt(sum((E_exact_grid - E_grid)**2)) - / np.sqrt(sum((E_exact_grid)**2))) + L2_error = np.sqrt(sum((E_exact_grid - E_grid) ** 2)) / np.sqrt( + sum((E_exact_grid) ** 2) + ) return L2_error + L2_error_x = calculate_error(Ex_axis, xmin, dx, nx) L2_error_y = calculate_error(Ey_axis, ymin, dy, ny) L2_error_z = calculate_error(Ez_axis, zmin, dz, nz) -print("L2 error along x-axis = %s" %L2_error_x) -print("L2 error along y-axis = %s" %L2_error_y) -print("L2 error along z-axis = %s" %L2_error_z) +print("L2 error along x-axis = %s" % L2_error_x) +print("L2 error along y-axis = %s" % L2_error_y) +print("L2 error along z-axis = %s" % L2_error_z) assert L2_error_x < l2_tolerance assert L2_error_y < l2_tolerance assert L2_error_z < l2_tolerance + # Check conservation of energy def return_energies(iteration): - ux, uy, uz, phi, m, q, w = ts.get_particle(['ux', 'uy', 'uz', 'phi', 'mass', 'charge', 'w'], iteration=iteration) - E_kinetic = (w*m*c**2 * (np.sqrt(1 + ux**2 + uy**2 + uz**2) - 1)).sum() - E_potential = 0.5*(w*q*phi).sum() # potential energy of particles in their own space-charge field: includes factor 1/2 + ux, uy, uz, phi, m, q, w = ts.get_particle( + ["ux", "uy", "uz", "phi", "mass", "charge", "w"], iteration=iteration + ) + E_kinetic = (w * m * c**2 * (np.sqrt(1 + ux**2 + uy**2 + uz**2) - 1)).sum() + E_potential = ( + 0.5 * (w * q * phi).sum() + ) # potential energy of particles in their own space-charge field: includes factor 1/2 return E_kinetic, E_potential -ts = OpenPMDTimeSeries('./diags/diag2') -if 'phi' in ts.avail_record_components['electron']: + + +ts = OpenPMDTimeSeries("./diags/diag2") +if "phi" in ts.avail_record_components["electron"]: # phi is only available when this script is run with the labframe poisson solver - print('Checking conservation of energy') + print("Checking conservation of energy") Ek_i, Ep_i = return_energies(0) Ek_f, Ep_f = return_energies(30) - assert Ep_f < 0.7*Ep_i # Check that potential energy changes significantly - assert abs( (Ek_i + Ep_i) - (Ek_f + Ep_f) ) < 0.003 * (Ek_i + Ep_i) # Check conservation of energy + assert Ep_f < 0.7 * Ep_i # Check that potential energy changes significantly + assert abs((Ek_i + Ep_i) - (Ek_f + Ep_f)) < 0.003 * ( + Ek_i + Ep_i + ) # Check conservation of energy # Checksum regression analysis -test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/electrostatic_sphere/catalyst_pipeline.py b/Examples/Tests/electrostatic_sphere/catalyst_pipeline.py new file mode 100644 index 00000000000..f0c55fa4e11 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere/catalyst_pipeline.py @@ -0,0 +1,241 @@ +# script-version: 2.0 +# Catalyst state generated using paraview version 5.11.1-1332-ga0a402a54e +# and validated with 5.12 +import paraview + +paraview.compatibility.major = 5 +paraview.compatibility.minor = 12 + +#### import the simple module from the paraview +from paraview.simple import * # noqa: F403 + +#### disable automatic camera reset on 'Show' +paraview.simple._DisableFirstRenderCameraReset() + +# ---------------------------------------------------------------- +# setup views used in the visualization +# ---------------------------------------------------------------- + +# Create a new 'Render View' +renderView1 = CreateView("RenderView") +renderView1.ViewSize = [889, 820] +renderView1.AxesGrid = "Grid Axes 3D Actor" +renderView1.OrientationAxesVisibility = 0 +renderView1.StereoType = "Crystal Eyes" +renderView1.CameraPosition = [ + 0.537460346333711, + -0.7885714264869157, + 0.47540803206975096, +] +renderView1.CameraFocalPoint = [ + -0.002360633658114411, + -0.0033755520058871905, + -0.0028772574955099155, +] +renderView1.CameraViewUp = [ + -0.010196376455648859, + 0.5150674559093057, + 0.8570889975786005, +] +renderView1.CameraFocalDisk = 1.0 +renderView1.CameraParallelScale = 0.8660254037844386 +renderView1.LegendGrid = "Legend Grid Actor" +renderView1.UseColorPaletteForBackground = 0 +renderView1.Background = [0.08627450980392157, 0.06274509803921569, 0.11372549019607843] + +SetActiveView(None) + +# ---------------------------------------------------------------- +# setup view layouts +# ---------------------------------------------------------------- + +# create new layout object 'Layout #1' +layout1 = CreateLayout(name="Layout #1") +layout1.AssignView(0, renderView1) +layout1.SetSize(889, 820) + +# ---------------------------------------------------------------- +# restore active view +# ---------------------------------------------------------------- +SetActiveView(renderView1) + +# ---------------------------------------------------------------- +# setup the data processing pipelines +# ---------------------------------------------------------------- + +# create a new 'XML Partitioned Dataset Collection Reader' +mesh = PVTrivialProducer(registrationName="mesh") + +# create a new 'Calculator' +calculator1 = Calculator(registrationName="Calculator1", Input=mesh) +calculator1.AttributeType = "Cell Data" +calculator1.ResultArrayName = "E" +calculator1.Function = "sqrt(Ex^2 + Ey^2 + Ez^2)" + +# create a new 'Threshold' +threshold1 = Threshold(registrationName="Threshold1", Input=calculator1) +threshold1.Scalars = ["CELLS", "E"] +threshold1.LowerThreshold = 0.00014553574512481541 +threshold1.UpperThreshold = 0.00033841915322276836 + +# create a new 'Clip' +clip1 = Clip(registrationName="Clip1", Input=threshold1) +clip1.ClipType = "Plane" +clip1.HyperTreeGridClipper = "Plane" +clip1.Scalars = ["CELLS", "E"] +clip1.Value = 0.00034051798664982454 + +# ---------------------------------------------------------------- +# setup the visualization in view 'renderView1' +# ---------------------------------------------------------------- + +# show data from clip1 +clip1Display = Show(clip1, renderView1, "UnstructuredGridRepresentation") + +# get 2D transfer function for 'E' +eTF2D = GetTransferFunction2D("E") +eTF2D.ScalarRangeInitialized = 1 +eTF2D.Range = [2.7209191271959258e-08, 0.00033841915322276836, 0.0, 1.0] + +# get color transfer function/color map for 'E' +eLUT = GetColorTransferFunction("E") +eLUT.TransferFunction2D = eTF2D +eLUT.RGBPoints = [ + 0.00014565122778316538, + 0.23137254902, + 0.298039215686, + 0.752941176471, + 0.0002596781039235302, + 0.865, + 0.865, + 0.865, + 0.00037370498006389504, + 0.705882352941, + 0.0156862745098, + 0.149019607843, +] +eLUT.ScalarRangeInitialized = 1.0 + +# get opacity transfer function/opacity map for 'E' +ePWF = GetOpacityTransferFunction("E") +ePWF.Points = [ + 0.00014565122778316538, + 0.0, + 0.5, + 0.0, + 0.00037370498006389504, + 1.0, + 0.5, + 0.0, +] +ePWF.ScalarRangeInitialized = 1 + +# trace defaults for the display properties. +clip1Display.Representation = "Surface" +clip1Display.ColorArrayName = ["CELLS", "E"] +clip1Display.LookupTable = eLUT +clip1Display.SelectTCoordArray = "None" +clip1Display.SelectNormalArray = "None" +clip1Display.SelectTangentArray = "None" +clip1Display.OSPRayScaleFunction = "Piecewise Function" +clip1Display.Assembly = "Hierarchy" +clip1Display.SelectOrientationVectors = "None" +clip1Display.ScaleFactor = 0.078125 +clip1Display.SelectScaleArray = "E" +clip1Display.GlyphType = "Arrow" +clip1Display.GlyphTableIndexArray = "E" +clip1Display.GaussianRadius = 0.00390625 +clip1Display.SetScaleArray = [None, ""] +clip1Display.ScaleTransferFunction = "Piecewise Function" +clip1Display.OpacityArray = [None, ""] +clip1Display.OpacityTransferFunction = "Piecewise Function" +clip1Display.DataAxesGrid = "Grid Axes Representation" +clip1Display.PolarAxes = "Polar Axes Representation" +clip1Display.ScalarOpacityFunction = ePWF +clip1Display.ScalarOpacityUnitDistance = 0.03870829665815266 +clip1Display.OpacityArrayName = ["CELLS", "E"] +clip1Display.SelectInputVectors = [None, ""] +clip1Display.WriteLog = "" + +# setup the color legend parameters for each legend in this view + +# get color legend/bar for eLUT in view renderView1 +eLUTColorBar = GetScalarBar(eLUT, renderView1) +eLUTColorBar.WindowLocation = "Any Location" +eLUTColorBar.Position = [0.7840269966254219, 0.3353658536585365] +eLUTColorBar.Title = "E" +eLUTColorBar.ComponentTitle = "" +eLUTColorBar.ScalarBarLength = 0.3300000000000001 + +# set color bar visibility +eLUTColorBar.Visibility = 1 + +# show color legend +clip1Display.SetScalarBarVisibility(renderView1, True) + +# ---------------------------------------------------------------- +# setup color maps and opacity maps used in the visualization +# note: the Get..() functions create a new object, if needed +# ---------------------------------------------------------------- + +# ---------------------------------------------------------------- +# setup animation scene, tracks and keyframes +# note: the Get..() functions create a new object, if needed +# ---------------------------------------------------------------- + +# get time animation track +timeAnimationCue1 = GetTimeTrack() + +# initialize the animation scene + +# get the time-keeper +timeKeeper1 = GetTimeKeeper() + +# initialize the timekeeper + +# initialize the animation track + +# get animation scene +animationScene1 = GetAnimationScene() + +# initialize the animation scene +animationScene1.ViewModules = renderView1 +animationScene1.Cues = timeAnimationCue1 +animationScene1.AnimationTime = 3.000000000000001e-05 +animationScene1.EndTime = 3.000000000000001e-05 +animationScene1.PlayMode = "Snap To TimeSteps" + +# ---------------------------------------------------------------- +# setup extractors +# ---------------------------------------------------------------- + +# create extractor +pNG1 = CreateExtractor("PNG", renderView1, registrationName="PNG1") +# trace defaults for the extractor. +pNG1.Trigger = "Time Step" + +# init the 'PNG' selected for 'Writer' +pNG1.Writer.FileName = "RenderView1_{timestep:06d}{camera}.png" +pNG1.Writer.ImageResolution = [889, 820] +pNG1.Writer.Format = "PNG" + +# ---------------------------------------------------------------- +# restore active source +# ---------------------------------------------------------------- +SetActiveSource(threshold1) + +# ------------------------------------------------------------------------------ +# Catalyst options +# ------------------------------------------------------------------------------ +from paraview import catalyst + +options = catalyst.Options() +options.GlobalTrigger = "Time Step" +options.CatalystLiveTrigger = "Time Step" + +if __name__ == "__main__": + from paraview.simple import SaveExtractsUsingCatalystOptions + + # Code for non in-situ environments; if executing in post-processing + # i.e. non-Catalyst mode, let's generate extracts using Catalyst options + SaveExtractsUsingCatalystOptions(options) diff --git a/Examples/Tests/electrostatic_sphere/inputs_3d b/Examples/Tests/electrostatic_sphere/inputs_base_3d similarity index 100% rename from Examples/Tests/electrostatic_sphere/inputs_3d rename to Examples/Tests/electrostatic_sphere/inputs_base_3d diff --git a/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere b/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere new file mode 100644 index 00000000000..d89395e9d74 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_lab_frame b/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_lab_frame new file mode 100644 index 00000000000..da97ae8afe7 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_lab_frame @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +diag2.electron.variables = x y z ux uy uz w phi +warpx.do_electrostatic = labframe diff --git a/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_lab_frame_mr_emass_10 b/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_lab_frame_mr_emass_10 new file mode 100644 index 00000000000..481cc65f030 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_lab_frame_mr_emass_10 @@ -0,0 +1,13 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +amr.max_level = 1 +amr.ref_ratio_vect = 2 2 2 +diag2.electron.variables = x y z ux uy uz w +electron.mass = 10 +max_step = 2 +warpx.abort_on_warning_threshold = medium +warpx.do_electrostatic = labframe +warpx.fine_tag_hi = 0.5 0.5 0.5 +warpx.fine_tag_lo = -0.5 -0.5 -0.5 diff --git a/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_rel_nodal b/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_rel_nodal new file mode 100644 index 00000000000..96bff8aa9c7 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere/inputs_test_3d_electrostatic_sphere_rel_nodal @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +warpx.abort_on_warning_threshold = medium +warpx.grid_type = collocated diff --git a/Examples/Tests/electrostatic_sphere/inputs_rz b/Examples/Tests/electrostatic_sphere/inputs_test_rz_electrostatic_sphere similarity index 96% rename from Examples/Tests/electrostatic_sphere/inputs_rz rename to Examples/Tests/electrostatic_sphere/inputs_test_rz_electrostatic_sphere index 2b6151e6d8c..a1c71c58fc3 100644 --- a/Examples/Tests/electrostatic_sphere/inputs_rz +++ b/Examples/Tests/electrostatic_sphere/inputs_test_rz_electrostatic_sphere @@ -11,6 +11,7 @@ boundary.field_hi = pec pec warpx.const_dt = 1e-6 warpx.do_electrostatic = labframe warpx.use_filter = 0 +warpx.abort_on_warning_threshold = medium particles.species_names = electron diff --git a/Examples/Tests/electrostatic_sphere_eb/CMakeLists.txt b/Examples/Tests/electrostatic_sphere_eb/CMakeLists.txt new file mode 100644 index 00000000000..7f7b1389119 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere_eb/CMakeLists.txt @@ -0,0 +1,62 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_3d_electrostatic_sphere_eb # name + 3 # dims + 2 # nprocs + inputs_test_3d_electrostatic_sphere_eb # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_3d_electrostatic_sphere_eb_mixed_bc # name + 3 # dims + 2 # nprocs + inputs_test_3d_electrostatic_sphere_eb_mixed_bc # inputs + analysis_default_regression.py # analysis + diags/diag1000001 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_3d_electrostatic_sphere_eb_picmi # name + 3 # dims + 2 # nprocs + inputs_test_3d_electrostatic_sphere_eb_picmi.py # inputs + analysis.py # analysis + diags/diag1000002 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_rz_electrostatic_sphere_eb # name + RZ # dims + 2 # nprocs + inputs_test_rz_electrostatic_sphere_eb # inputs + analysis_rz.py # analysis + diags/diag1000001 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_rz_electrostatic_sphere_eb_mr # name + RZ # dims + 2 # nprocs + inputs_test_rz_electrostatic_sphere_eb_mr # inputs + analysis_rz_mr.py # analysis + diags/diag1/ # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/electrostatic_sphere_eb/PICMI_inputs_3d.py b/Examples/Tests/electrostatic_sphere_eb/PICMI_inputs_3d.py deleted file mode 100755 index 55fbc87bd9e..00000000000 --- a/Examples/Tests/electrostatic_sphere_eb/PICMI_inputs_3d.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -########################## -# physics parameters -########################## - -V_domain_boundary = 0.0 -V_embedded_boundary = 1.0 - - -########################## -# numerics parameters -########################## - -dt = 1e-6 - -# --- Nb time steps - -max_steps = 2 - -# --- grid - -nx = 64 -ny = 64 -nz = 64 - -xmin = -0.5 -xmax = 0.5 -ymin = -0.5 -ymax = 0.5 -zmin = -0.5 -zmax = 0.5 - - -########################## -# numerics components -########################## - -grid = picmi.Cartesian3DGrid( - number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = ['dirichlet', 'dirichlet', 'dirichlet'], - upper_boundary_conditions = ['dirichlet', 'dirichlet', 'dirichlet'], - lower_boundary_conditions_particles = ['absorbing', 'absorbing', 'absorbing'], - upper_boundary_conditions_particles = ['absorbing', 'absorbing', 'absorbing'], - warpx_potential_lo_x = V_domain_boundary, - warpx_potential_hi_x = V_domain_boundary, - warpx_potential_lo_y = V_domain_boundary, - warpx_potential_hi_y = V_domain_boundary, - warpx_potential_lo_z = V_domain_boundary, - warpx_potential_hi_z = V_domain_boundary, - warpx_blocking_factor=8, - warpx_max_grid_size = 128 -) - -solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-7 -) - -embedded_boundary = picmi.EmbeddedBoundary( - implicit_function="-(x**2+y**2+z**2-radius**2)", - potential=V_embedded_boundary, - radius = 0.1 -) - -########################## -# diagnostics -########################## - -particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 1, - write_dir = '.', - warpx_file_prefix = 'Python_ElectrostaticSphereEB_plt' -) -field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 1, - data_list = ['Ex', 'Ey', 'Ez', 'phi', 'rho'], - write_dir = '.', - warpx_file_prefix = 'Python_ElectrostaticSphereEB_plt' -) - -reduced_diag = picmi.ReducedDiagnostic( - diag_type = 'ChargeOnEB', - name = 'eb_charge', - period = 1) - -reduced_diag_one_eighth = picmi.ReducedDiagnostic( - diag_type = 'ChargeOnEB', - name = 'eb_charge_one_eighth', - weighting_function = '(x>0)*(y>0)*(z>0)', - period = 1) - -########################## -# simulation setup -########################## - -sim = picmi.Simulation( - solver = solver, - time_step_size = dt, - max_steps = max_steps, - warpx_embedded_boundary=embedded_boundary, - warpx_field_gathering_algo='momentum-conserving' -) - -sim.add_diagnostic(particle_diag) -sim.add_diagnostic(field_diag) -sim.add_diagnostic(reduced_diag) -sim.add_diagnostic(reduced_diag_one_eighth) - -########################## -# simulation run -########################## - -sim.step(1) - -sim.extension.warpx.set_potential_on_eb("2.") - -sim.step(1) diff --git a/Examples/Tests/electrostatic_sphere_eb/analysis.py b/Examples/Tests/electrostatic_sphere_eb/analysis.py index bf2725616b5..71b3bfa3aa5 100755 --- a/Examples/Tests/electrostatic_sphere_eb/analysis.py +++ b/Examples/Tests/electrostatic_sphere_eb/analysis.py @@ -7,7 +7,7 @@ import os import sys -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Check reduced diagnostics for charge on EB @@ -15,19 +15,19 @@ from scipy.constants import epsilon_0 # Theoretical charge on the embedded boundary, for sphere at potential phi_0 -phi_0 = 1. # V -R = 0.1 # m -q_th = 4*np.pi*epsilon_0*phi_0*R -print('Theoretical charge: ', q_th) - -data = np.loadtxt('diags/reducedfiles/eb_charge.txt') -q_sim = data[1,2] -print('Simulation charge: ', q_sim) -assert abs((q_sim-q_th)/q_th) < 0.06 - -data_eighth = np.loadtxt('diags/reducedfiles/eb_charge_one_eighth.txt') -q_sim_eighth = data_eighth[1,2] -assert abs((q_sim_eighth-q_th/8)/(q_th/8)) < 0.06 +phi_0 = 1.0 # V +R = 0.1 # m +q_th = 4 * np.pi * epsilon_0 * phi_0 * R +print("Theoretical charge: ", q_th) + +data = np.loadtxt("diags/reducedfiles/eb_charge.txt") +q_sim = data[1, 2] +print("Simulation charge: ", q_sim) +assert abs((q_sim - q_th) / q_th) < 0.06 + +data_eighth = np.loadtxt("diags/reducedfiles/eb_charge_one_eighth.txt") +q_sim_eighth = data_eighth[1, 2] +assert abs((q_sim_eighth - q_th / 8) / (q_th / 8)) < 0.06 filename = sys.argv[1] test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/electrostatic_sphere_eb/analysis_default_regression.py b/Examples/Tests/electrostatic_sphere_eb/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere_eb/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/electrostatic_sphere_eb/analysis_rz.py b/Examples/Tests/electrostatic_sphere_eb/analysis_rz.py index 18aba4322f0..b33f19488d0 100755 --- a/Examples/Tests/electrostatic_sphere_eb/analysis_rz.py +++ b/Examples/Tests/electrostatic_sphere_eb/analysis_rz.py @@ -23,47 +23,49 @@ import yt from unyt import m -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI tolerance = 0.0041 fn = sys.argv[1] -ds = yt.load( fn ) +ds = yt.load(fn) -all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -phi = all_data_level_0['boxlib', 'phi'].v.squeeze() -Er = all_data_level_0['boxlib', 'Er'].v.squeeze() +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +phi = all_data_level_0["boxlib", "phi"].v.squeeze() +Er = all_data_level_0["boxlib", "Er"].v.squeeze() -Dx = ds.domain_width/ds.domain_dimensions +Dx = ds.domain_width / ds.domain_dimensions dr = Dx[0] rmin = ds.domain_left_edge[0] rmax = ds.domain_right_edge[0] nr = phi.shape[0] -r = np.linspace(rmin+dr/2.,rmax-dr/2.,nr) -B = 1.0/np.log(0.1/0.5) -A = -B*np.log(0.5) +r = np.linspace(rmin + dr / 2.0, rmax - dr / 2.0, nr) +B = 1.0 / np.log(0.1 / 0.5) +A = -B * np.log(0.5) err = 0.0 errmax_phi = 0.0 errmax_Er = 0.0 for i in range(len(r)): # outside EB and last cutcell - if r[i] > 0.1*m + dr: - phi_theory = A+B*np.log(r[i]) - Er_theory = -B/float(r[i]) - err = abs( phi_theory - phi[i,:] ).max() / phi_theory - if err>errmax_phi: + if r[i] > 0.1 * m + dr: + phi_theory = A + B * np.log(r[i]) + Er_theory = -B / float(r[i]) + err = abs(phi_theory - phi[i, :]).max() / phi_theory + if err > errmax_phi: errmax_phi = err - err = abs( Er_theory - Er[i,:] ).max() / Er_theory + err = abs(Er_theory - Er[i, :]).max() / Er_theory # Exclude the last inaccurate interpolation. - if err>errmax_Er and i errmax_Er and i < len(r) - 1: errmax_Er = err -print('max error of phi = ', errmax_phi) -print('max error of Er = ', errmax_Er) -print('tolerance = ', tolerance) -assert(errmax_phi= (0.1 + dr))) + rmax = -1 + r = r[rmin:rmax] + phi_sim = phi_sim[:, rmin:rmax] + Er_sim = Er_sim[:, rmin:rmax] + + phi_theory = A + B * np.log(r) + phi_theory = np.tile(phi_theory, (phi_sim.shape[0], 1)) + phi_error = np.max(np.abs(phi_theory - phi_sim) / np.abs(phi_theory)) + + Er_theory = -B / r + Er_theory = np.tile(Er_theory, (Er_sim.shape[0], 1)) + Er_error = np.max(np.abs(Er_theory - Er_sim) / np.abs(Er_theory)) + + print(f"max error of phi[lev={level}]: {phi_error}") + print(f"max error of Er[lev={level}]: {Er_error}") + assert phi_error < tolerance + assert Er_error < tolerance + + +ts = OpenPMDTimeSeries(fn) +level_fields = [field for field in ts.avail_fields if "lvl" in field] +nlevels = 0 if level_fields == [] else int(level_fields[-1][-1]) +for level in range(nlevels + 1): + get_error_per_lev(ts, level) + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, fn, output_format="openpmd") diff --git a/Examples/Tests/electrostatic_sphere_eb/inputs_3d b/Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb similarity index 96% rename from Examples/Tests/electrostatic_sphere_eb/inputs_3d rename to Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb index 13ad42da070..f738e1c5d3a 100644 --- a/Examples/Tests/electrostatic_sphere_eb/inputs_3d +++ b/Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb @@ -20,6 +20,7 @@ warpx.do_electrostatic = labframe warpx.eb_implicit_function = "-(x**2+y**2+z**2-0.1**2)" warpx.eb_potential(x,y,z,t) = "1." warpx.self_fields_required_precision = 1.e-7 +warpx.abort_on_warning_threshold = medium algo.field_gathering = momentum-conserving diff --git a/Examples/Tests/electrostatic_sphere_eb/inputs_3d_mixed_BCs b/Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb_mixed_bc similarity index 94% rename from Examples/Tests/electrostatic_sphere_eb/inputs_3d_mixed_BCs rename to Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb_mixed_bc index 0c1b9130ded..de2c0d0646c 100644 --- a/Examples/Tests/electrostatic_sphere_eb/inputs_3d_mixed_BCs +++ b/Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb_mixed_bc @@ -17,6 +17,7 @@ warpx.do_electrostatic = labframe warpx.eb_implicit_function = "-(x**2+y**2+z**2-0.3**2)" warpx.eb_potential(x,y,z,t) = "1." warpx.self_fields_required_precision = 1.e-7 +warpx.abort_on_warning_threshold = medium algo.field_gathering = momentum-conserving diff --git a/Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb_picmi.py b/Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb_picmi.py new file mode 100755 index 00000000000..37d280e77d2 --- /dev/null +++ b/Examples/Tests/electrostatic_sphere_eb/inputs_test_3d_electrostatic_sphere_eb_picmi.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +########################## +# physics parameters +########################## + +V_domain_boundary = 0.0 +V_embedded_boundary = 1.0 + + +########################## +# numerics parameters +########################## + +dt = 1e-6 + +# --- Nb time steps + +max_steps = 2 + +# --- grid + +nx = 64 +ny = 64 +nz = 64 + +xmin = -0.5 +xmax = 0.5 +ymin = -0.5 +ymax = 0.5 +zmin = -0.5 +zmax = 0.5 + + +########################## +# numerics components +########################## + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], + warpx_potential_lo_x=V_domain_boundary, + warpx_potential_hi_x=V_domain_boundary, + warpx_potential_lo_y=V_domain_boundary, + warpx_potential_hi_y=V_domain_boundary, + warpx_potential_lo_z=V_domain_boundary, + warpx_potential_hi_z=V_domain_boundary, + warpx_blocking_factor=8, + warpx_max_grid_size=128, +) + +solver = picmi.ElectrostaticSolver( + grid=grid, method="Multigrid", required_precision=1e-7 +) + +embedded_boundary = picmi.EmbeddedBoundary( + implicit_function="-(x**2+y**2+z**2-radius**2)", + potential=V_embedded_boundary, + radius=0.1, +) + +########################## +# diagnostics +########################## + +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=1, +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=1, + data_list=["Ex", "Ey", "Ez", "phi", "rho"], +) + +reduced_diag = picmi.ReducedDiagnostic( + diag_type="ChargeOnEB", name="eb_charge", period=1 +) + +reduced_diag_one_eighth = picmi.ReducedDiagnostic( + diag_type="ChargeOnEB", + name="eb_charge_one_eighth", + weighting_function="(x>0)*(y>0)*(z>0)", + period=1, +) + +########################## +# simulation setup +########################## + +sim = picmi.Simulation( + solver=solver, + time_step_size=dt, + max_steps=max_steps, + warpx_embedded_boundary=embedded_boundary, + warpx_field_gathering_algo="momentum-conserving", +) + +sim.add_diagnostic(particle_diag) +sim.add_diagnostic(field_diag) +sim.add_diagnostic(reduced_diag) +sim.add_diagnostic(reduced_diag_one_eighth) + +########################## +# simulation run +########################## + +sim.step(1) + +sim.extension.warpx.set_potential_on_eb("2.") + +sim.step(1) diff --git a/Examples/Tests/electrostatic_sphere_eb/inputs_rz b/Examples/Tests/electrostatic_sphere_eb/inputs_test_rz_electrostatic_sphere_eb similarity index 94% rename from Examples/Tests/electrostatic_sphere_eb/inputs_rz rename to Examples/Tests/electrostatic_sphere_eb/inputs_test_rz_electrostatic_sphere_eb index 28ebadb1cc7..8ace9cd9b4a 100644 --- a/Examples/Tests/electrostatic_sphere_eb/inputs_rz +++ b/Examples/Tests/electrostatic_sphere_eb/inputs_test_rz_electrostatic_sphere_eb @@ -20,6 +20,7 @@ warpx.do_electrostatic = labframe warpx.eb_implicit_function = "-(x**2-0.1**2)" warpx.eb_potential(x,y,z,t) = "1." warpx.self_fields_required_precision = 1.e-7 +warpx.abort_on_warning_threshold = medium algo.field_gathering = momentum-conserving diff --git a/Examples/Tests/electrostatic_sphere_eb/inputs_rz_mr b/Examples/Tests/electrostatic_sphere_eb/inputs_test_rz_electrostatic_sphere_eb_mr similarity index 89% rename from Examples/Tests/electrostatic_sphere_eb/inputs_rz_mr rename to Examples/Tests/electrostatic_sphere_eb/inputs_test_rz_electrostatic_sphere_eb_mr index 3bea63d76fb..d984ba35b5d 100644 --- a/Examples/Tests/electrostatic_sphere_eb/inputs_rz_mr +++ b/Examples/Tests/electrostatic_sphere_eb/inputs_test_rz_electrostatic_sphere_eb_mr @@ -6,6 +6,7 @@ max_step = 1 amr.n_cell = 64 64 amr.blocking_factor = 8 amr.max_grid_size = 128 +amr.ref_ratio_vect = 2 2 2 boundary.field_lo = none periodic boundary.field_hi = pec periodic boundary.potential_lo_x = 0 @@ -23,6 +24,7 @@ warpx.do_electrostatic = labframe warpx.eb_implicit_function = "-(x**2-0.1**2)" warpx.eb_potential(x,y,z,t) = "1." warpx.self_fields_required_precision = 1.e-7 +warpx.abort_on_warning_threshold = medium algo.field_gathering = momentum-conserving @@ -30,3 +32,4 @@ diagnostics.diags_names = diag1 diag1.intervals = 1 diag1.diag_type = Full diag1.fields_to_plot = Er phi +diag1.format = openpmd diff --git a/Examples/Tests/embedded_boundary_cube/CMakeLists.txt b/Examples/Tests/embedded_boundary_cube/CMakeLists.txt new file mode 100644 index 00000000000..0044ed04ec8 --- /dev/null +++ b/Examples/Tests/embedded_boundary_cube/CMakeLists.txt @@ -0,0 +1,38 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_2d_embedded_boundary_cube # name + 2 # dims + 1 # nprocs + inputs_test_2d_embedded_boundary_cube # inputs + analysis_fields_2d.py # analysis + diags/diag1000114 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_3d_embedded_boundary_cube # name + 3 # dims + 1 # nprocs + inputs_test_3d_embedded_boundary_cube # inputs + analysis_fields.py # analysis + diags/diag1000208 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_3d_embedded_boundary_cube_macroscopic # name + 3 # dims + 1 # nprocs + inputs_test_3d_embedded_boundary_cube_macroscopic # inputs + analysis_fields.py # analysis + diags/diag1000208 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/embedded_boundary_cube/analysis_fields.py b/Examples/Tests/embedded_boundary_cube/analysis_fields.py index dc6af9d57d2..49da1a76edd 100755 --- a/Examples/Tests/embedded_boundary_cube/analysis_fields.py +++ b/Examples/Tests/embedded_boundary_cube/analysis_fields.py @@ -8,7 +8,7 @@ import yt from scipy.constants import c, mu_0, pi -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # This is a script that analyses the simulation results from @@ -23,12 +23,14 @@ # $$ k_y = \frac{n\pi}{L}$$ # $$ k_z = \frac{p\pi}{L}$$ +test_name = os.path.split(os.getcwd())[1] + hi = [0.8, 0.8, 0.8] lo = [-0.8, -0.8, -0.8] ncells = [48, 48, 48] -dx = (hi[0] - lo[0])/ncells[0] -dy = (hi[1] - lo[1])/ncells[1] -dz = (hi[2] - lo[2])/ncells[2] +dx = (hi[0] - lo[0]) / ncells[0] +dy = (hi[1] - lo[1]) / ncells[1] +dz = (hi[2] - lo[2]) / ncells[2] m = 0 n = 1 p = 1 @@ -40,17 +42,19 @@ # Open the right plot file filename = sys.argv[1] ds = yt.load(filename) -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) # Parse test name and check whether this use the macroscopic solver # (i.e. solving the equation in a dielectric) -macroscopic = True if re.search( 'macroscopic', filename ) else False +macroscopic = True if re.search("macroscopic", test_name) else False # Calculate frequency of the mode oscillation -omega = np.sqrt( h_2 ) * c +omega = np.sqrt(h_2) * c if macroscopic: # Relative permittivity used in this test: epsilon_r = 1.5 - omega *= 1./np.sqrt(1.5) + omega *= 1.0 / np.sqrt(1.5) t = ds.current_time.to_value() @@ -61,40 +65,49 @@ for i in range(ncells[0]): for j in range(ncells[1]): for k in range(ncells[2]): - x = i*dx + lo[0] - y = (j+0.5)*dy + lo[1] - z = k*dz + lo[2] - - By_th[i, j, k] = -2/h_2*mu_0*(n * pi/Ly)*(p * pi/Lz) * (np.cos(m * pi/Lx * (x - Lx/2)) * - np.sin(n * pi/Ly * (y - Ly/2)) * - np.cos(p * pi/Lz * (z - Lz/2)) * - (-Lx/2 <= x < Lx/2) * - (-Ly/2 <= y < Ly/2) * - (-Lz/2 <= z < Lz/2) * - np.cos(omega * t)) - - x = i*dx + lo[0] - y = j*dy + lo[1] - z = (k+0.5)*dz + lo[2] - Bz_th[i, j, k] = mu_0*(np.cos(m * pi/Lx * (x - Lx/2)) * - np.cos(n * pi/Ly * (y - Ly/2)) * - np.sin(p * pi/Lz * (z - Lz/2)) * - (-Lx/2 <= x < Lx/2) * - (-Ly/2 <= y < Ly/2) * - (-Lz/2 <= z < Lz/2) * - np.cos(omega * t)) + x = i * dx + lo[0] + y = (j + 0.5) * dy + lo[1] + z = k * dz + lo[2] + + By_th[i, j, k] = ( + -2 + / h_2 + * mu_0 + * (n * pi / Ly) + * (p * pi / Lz) + * ( + np.cos(m * pi / Lx * (x - Lx / 2)) + * np.sin(n * pi / Ly * (y - Ly / 2)) + * np.cos(p * pi / Lz * (z - Lz / 2)) + * (-Lx / 2 <= x < Lx / 2) + * (-Ly / 2 <= y < Ly / 2) + * (-Lz / 2 <= z < Lz / 2) + * np.cos(omega * t) + ) + ) + + x = i * dx + lo[0] + y = j * dy + lo[1] + z = (k + 0.5) * dz + lo[2] + Bz_th[i, j, k] = mu_0 * ( + np.cos(m * pi / Lx * (x - Lx / 2)) + * np.cos(n * pi / Ly * (y - Ly / 2)) + * np.sin(p * pi / Lz * (z - Lz / 2)) + * (-Lx / 2 <= x < Lx / 2) + * (-Ly / 2 <= y < Ly / 2) + * (-Lz / 2 <= z < Lz / 2) + * np.cos(omega * t) + ) rel_tol_err = 1e-1 # Compute relative l^2 error on By -By_sim = data[('mesh','By')].to_ndarray() -rel_err_y = np.sqrt( np.sum(np.square(By_sim - By_th)) / np.sum(np.square(By_th))) -assert(rel_err_y < rel_tol_err) +By_sim = data[("mesh", "By")].to_ndarray() +rel_err_y = np.sqrt(np.sum(np.square(By_sim - By_th)) / np.sum(np.square(By_th))) +assert rel_err_y < rel_tol_err # Compute relative l^2 error on Bz -Bz_sim = data[('mesh','Bz')].to_ndarray() -rel_err_z = np.sqrt( np.sum(np.square(Bz_sim - Bz_th)) / np.sum(np.square(Bz_th))) -assert(rel_err_z < rel_tol_err) - -test_name = os.path.split(os.getcwd())[1] +Bz_sim = data[("mesh", "Bz")].to_ndarray() +rel_err_z = np.sqrt(np.sum(np.square(Bz_sim - Bz_th)) / np.sum(np.square(Bz_th))) +assert rel_err_z < rel_tol_err checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/embedded_boundary_cube/analysis_fields_2d.py b/Examples/Tests/embedded_boundary_cube/analysis_fields_2d.py index 8faa299025e..70a5b7d46c5 100755 --- a/Examples/Tests/embedded_boundary_cube/analysis_fields_2d.py +++ b/Examples/Tests/embedded_boundary_cube/analysis_fields_2d.py @@ -7,7 +7,7 @@ import yt from scipy.constants import c, mu_0, pi -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # This is a script that analyses the simulation results from @@ -32,7 +32,9 @@ # Open the right plot file filename = sys.argv[1] ds = yt.load(filename) -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) t = ds.current_time.to_value() @@ -40,24 +42,26 @@ By_th = np.zeros(ncells) for i in range(ncells[0]): for j in range(ncells[1]): - x = (i+0.5) * dx + lo[0] - z = (j+0.5) * dz + lo[1] + x = (i + 0.5) * dx + lo[0] + z = (j + 0.5) * dz + lo[1] - By_th[i, j, 0] = mu_0 * (np.cos(m * pi / Lx * (x - Lx / 2)) * - np.cos(n * pi / Lz * (z - Lz / 2)) * - (-Lx / 2 <= x < Lx / 2) * - (-Lz / 2 <= z < Lz / 2) * - np.cos(np.pi / Lx * c * t)) + By_th[i, j, 0] = mu_0 * ( + np.cos(m * pi / Lx * (x - Lx / 2)) + * np.cos(n * pi / Lz * (z - Lz / 2)) + * (-Lx / 2 <= x < Lx / 2) + * (-Lz / 2 <= z < Lz / 2) + * np.cos(np.pi / Lx * c * t) + ) rel_tol_err = 1e-3 # Compute relative l^2 error on By -By_sim = data['By'].to_ndarray() +By_sim = data["By"].to_ndarray() rel_err_y = np.sqrt(np.sum(np.square(By_sim - By_th)) / np.sum(np.square(By_th))) -assert (rel_err_y < rel_tol_err) +assert rel_err_y < rel_tol_err # Compute relative l^2 error on Ey -Ey_sim = data['Ey'].to_ndarray() -rel_err_y = np.sqrt(np.sum(np.square(Ey_sim/c - By_th)) / np.sum(np.square(By_th))) +Ey_sim = data["Ey"].to_ndarray() +rel_err_y = np.sqrt(np.sum(np.square(Ey_sim / c - By_th)) / np.sum(np.square(By_th))) test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/embedded_boundary_cube/inputs_3d b/Examples/Tests/embedded_boundary_cube/inputs_base_3d similarity index 97% rename from Examples/Tests/embedded_boundary_cube/inputs_3d rename to Examples/Tests/embedded_boundary_cube/inputs_base_3d index 61eb1192e04..9710701d871 100644 --- a/Examples/Tests/embedded_boundary_cube/inputs_3d +++ b/Examples/Tests/embedded_boundary_cube/inputs_base_3d @@ -7,6 +7,7 @@ geometry.dims = 3 geometry.prob_lo = -0.8 -0.8 -0.8 geometry.prob_hi = 0.8 0.8 0.8 warpx.cfl = 1 +warpx.abort_on_warning_threshold = medium boundary.field_lo = pec pec pec boundary.field_hi = pec pec pec diff --git a/Examples/Tests/embedded_boundary_cube/inputs_2d b/Examples/Tests/embedded_boundary_cube/inputs_test_2d_embedded_boundary_cube similarity index 97% rename from Examples/Tests/embedded_boundary_cube/inputs_2d rename to Examples/Tests/embedded_boundary_cube/inputs_test_2d_embedded_boundary_cube index 372e0dc0340..684325dc030 100644 --- a/Examples/Tests/embedded_boundary_cube/inputs_2d +++ b/Examples/Tests/embedded_boundary_cube/inputs_test_2d_embedded_boundary_cube @@ -7,6 +7,7 @@ geometry.dims = 2 geometry.prob_lo = -0.8 -0.8 geometry.prob_hi = 0.8 0.8 warpx.cfl = 1 +warpx.abort_on_warning_threshold = medium boundary.field_lo = pec pec boundary.field_hi = pec pec diff --git a/Examples/Tests/embedded_boundary_cube/inputs_test_3d_embedded_boundary_cube b/Examples/Tests/embedded_boundary_cube/inputs_test_3d_embedded_boundary_cube new file mode 100644 index 00000000000..9d612bd62da --- /dev/null +++ b/Examples/Tests/embedded_boundary_cube/inputs_test_3d_embedded_boundary_cube @@ -0,0 +1,2 @@ +# base inpute parameters +FILE = inputs_base_3d diff --git a/Examples/Tests/embedded_boundary_cube/inputs_test_3d_embedded_boundary_cube_macroscopic b/Examples/Tests/embedded_boundary_cube/inputs_test_3d_embedded_boundary_cube_macroscopic new file mode 100644 index 00000000000..1bcb49dec54 --- /dev/null +++ b/Examples/Tests/embedded_boundary_cube/inputs_test_3d_embedded_boundary_cube_macroscopic @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.em_solver_medium = macroscopic +macroscopic.epsilon = 1.5*8.8541878128e-12 +macroscopic.mu = 1.25663706212e-06 +macroscopic.sigma = 0 diff --git a/Examples/Tests/embedded_boundary_diffraction/CMakeLists.txt b/Examples/Tests/embedded_boundary_diffraction/CMakeLists.txt new file mode 100644 index 00000000000..6297cf1fa5c --- /dev/null +++ b/Examples/Tests/embedded_boundary_diffraction/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_rz_embedded_boundary_diffraction # name + RZ # dims + 2 # nprocs + inputs_test_rz_embedded_boundary_diffraction # inputs + analysis_fields.py # analysis + diags/diag1/ # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/embedded_boundary_diffraction/analysis_fields.py b/Examples/Tests/embedded_boundary_diffraction/analysis_fields.py index da344f332a1..84dfacbb505 100755 --- a/Examples/Tests/embedded_boundary_diffraction/analysis_fields.py +++ b/Examples/Tests/embedded_boundary_diffraction/analysis_fields.py @@ -6,6 +6,7 @@ occurs along the angle given by the theoretical Airy pattern, i.e. theta_diffraction = 1.22 * lambda / d """ + import os import sys @@ -13,29 +14,34 @@ from openpmd_viewer import OpenPMDTimeSeries from scipy.ndimage import gaussian_filter1d -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -ts = OpenPMDTimeSeries('./EmbeddedBoundaryDiffraction_plt/') +filename = sys.argv[1] +ts = OpenPMDTimeSeries(filename) # Extract the intensity as a function of r and z -Ex, info = ts.get_field('E', 'x', iteration=300) -I = gaussian_filter1d(Ex**2, sigma=5, axis=0) # Extract intensity by averaging E^2 over wavelength -irmax = np.argmax( I, axis=-1) +Ex, info = ts.get_field("E", "x", iteration=300) +In = gaussian_filter1d( + Ex**2, sigma=5, axis=0 +) # Extract intensity by averaging E^2 over wavelength +irmax = np.argmax(In, axis=-1) + # Find the radius of the first minimum, as a function of z def r_first_minimum(iz): - ir = len(info.r)//2 - while I[iz, ir+1] < I[iz, ir]: + ir = len(info.r) // 2 + while In[iz, ir + 1] < In[iz, ir]: ir += 1 return info.r[ir] -r = np.array([ r_first_minimum(iz) for iz in range(len(info.z)) ]) + + +r = np.array([r_first_minimum(iz) for iz in range(len(info.z))]) # Check that this corresponds to the prediction from the Airy pattern -theta_diffraction = np.arcsin(1.22*0.1/0.4)/2 -assert np.all( abs(r[50:] - theta_diffraction*info.z[50:]) < 0.03 ) +theta_diffraction = np.arcsin(1.22 * 0.1 / 0.4) / 2 +assert np.all(abs(r[50:] - theta_diffraction * info.z[50:]) < 0.03) # Open the right plot file -filename = sys.argv[1] test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename, output_format='openpmd') +checksumAPI.evaluate_checksum(test_name, filename, output_format="openpmd") diff --git a/Examples/Tests/embedded_boundary_diffraction/inputs_rz b/Examples/Tests/embedded_boundary_diffraction/inputs_test_rz_embedded_boundary_diffraction similarity index 100% rename from Examples/Tests/embedded_boundary_diffraction/inputs_rz rename to Examples/Tests/embedded_boundary_diffraction/inputs_test_rz_embedded_boundary_diffraction diff --git a/Examples/Tests/embedded_boundary_python_api/CMakeLists.txt b/Examples/Tests/embedded_boundary_python_api/CMakeLists.txt new file mode 100644 index 00000000000..fe820c76f22 --- /dev/null +++ b/Examples/Tests/embedded_boundary_python_api/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_3d_embedded_boundary_picmi # name + 3 # dims + 1 # nprocs + inputs_test_3d_embedded_boundary_picmi.py # inputs + analysis.py # analysis + diags/diag1000002 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/embedded_boundary_python_api/PICMI_inputs_EB_API.py b/Examples/Tests/embedded_boundary_python_api/PICMI_inputs_EB_API.py deleted file mode 100755 index faec3ed4668..00000000000 --- a/Examples/Tests/embedded_boundary_python_api/PICMI_inputs_EB_API.py +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env python3 -import numpy as np - -from pywarpx import fields, picmi - -max_steps = 1 -unit = 1e-3 - -################################## -# Define the mesh -################################## -# mesh cells per direction -nx = 64 -ny = 64 -nz = 64 - -# mesh bounds for domain -xmin = -32*unit -xmax = 32*unit -ymin = -32*unit -ymax = 32*unit -zmin = -32*unit -zmax = 32*unit - -########################## -# numerics components -########################## -lower_boundary_conditions = ['open', 'dirichlet', 'periodic'] -upper_boundary_conditions = ['open', 'dirichlet', 'periodic'] - -grid = picmi.Cartesian3DGrid( - number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = lower_boundary_conditions, - upper_boundary_conditions = upper_boundary_conditions, - lower_boundary_conditions_particles = ['absorbing', 'absorbing', 'periodic'], - upper_boundary_conditions_particles = ['absorbing', 'absorbing', 'periodic'], - moving_window_velocity = None, - warpx_max_grid_size = 64 -) - - -flag_correct_div = False - -solver = picmi.ElectromagneticSolver(grid=grid, method='Yee', cfl=1.) - -n_cavity=30 -L_cavity = n_cavity*unit - -embedded_boundary = picmi.EmbeddedBoundary( - implicit_function="max(max(max(x-L_cavity/2,-L_cavity/2-x),max(y-L_cavity/2,-L_cavity/2-y)),max(z-L_cavity/2,-L_cavity/2-z))", - L_cavity=L_cavity -) - - -########################## -# diagnostics -########################## - -particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 1, - write_dir = '.', - warpx_file_prefix = "embedded_boundary_python_API_plt" -) -field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 1, - data_list = ['Ex'], - write_dir = '.', - warpx_file_prefix = "embedded_boundary_python_API_plt" -) - -########################## -# simulation setup -########################## - -sim = picmi.Simulation( - solver = solver, - max_steps = max_steps, - warpx_embedded_boundary=embedded_boundary, - verbose = 1 -) - -sim.add_diagnostic(particle_diag) -sim.add_diagnostic(field_diag) - -sim.initialize_inputs() - -sim.step(1) - -edge_lengths_x = fields.EdgeLengthsxWrapper() -edge_lengths_y = fields.EdgeLengthsyWrapper() -edge_lengths_z = fields.EdgeLengthszWrapper() -face_areas_x = fields.FaceAreasxWrapper() -face_areas_y = fields.FaceAreasyWrapper() -face_areas_z = fields.FaceAreaszWrapper() - -print("======== Testing the wrappers of m_edge_lengths =========") - -ly_slice_x = edge_lengths_y[nx//2,:,:] -lz_slice_x = edge_lengths_z[nx//2,:,:] - -n_edge_y_lo = (ny - 30)//2 -n_edge_y_hi = ny - (ny - 30)//2 -n_edge_z_lo = (nz - 30)//2 -n_edge_z_hi = nz - (nz - 30)//2 - -perimeter_slice_x = (np.sum(ly_slice_x[n_edge_y_lo:n_edge_y_hi, n_edge_z_lo+1]) + - np.sum(ly_slice_x[n_edge_y_lo:n_edge_y_hi, n_edge_z_hi-1]) + - np.sum(lz_slice_x[n_edge_y_lo+1, n_edge_z_lo:n_edge_z_hi]) + - np.sum(lz_slice_x[n_edge_y_hi-1, n_edge_z_lo:n_edge_z_hi])) - -perimeter_slice_x_true = L_cavity*4 - -print("Perimeter of the middle x-slice:", perimeter_slice_x) -assert np.isclose(perimeter_slice_x, perimeter_slice_x_true, rtol=1e-05, atol=1e-08) - - -lx_slice_y = edge_lengths_x[:,ny//2,:] -lz_slice_y = edge_lengths_z[:,ny//2,:] - -n_edge_x_lo = (nx - 30)//2 -n_edge_x_hi = nx - (nx - 30)//2 -n_edge_z_lo = (nz - 30)//2 -n_edge_z_hi = nz - (nz - 30)//2 - -perimeter_slice_y = (np.sum(lx_slice_y[n_edge_x_lo:n_edge_x_hi, n_edge_z_lo+1]) + - np.sum(lx_slice_y[n_edge_x_lo:n_edge_x_hi, n_edge_z_hi-1]) + - np.sum(lz_slice_y[n_edge_x_lo+1, n_edge_z_lo:n_edge_z_hi]) + - np.sum(lz_slice_y[n_edge_x_hi-1, n_edge_z_lo:n_edge_z_hi])) - -perimeter_slice_y_true = L_cavity*4 - - -print("Perimeter of the middle y-slice:", perimeter_slice_y) -assert np.isclose(perimeter_slice_y, perimeter_slice_y_true, rtol=1e-05, atol=1e-08) - - -lx_slice_z = edge_lengths_x[:,:,nz//2] -ly_slice_z = edge_lengths_y[:,:,nz//2] - -n_edge_x_lo = (nx - 30)//2 -n_edge_x_hi = nx - (nx - 30)//2 -n_edge_y_lo = (ny - 30)//2 -n_edge_y_hi = ny - (ny - 30)//2 - -perimeter_slice_z = (np.sum(lx_slice_z[n_edge_x_lo:n_edge_x_hi, n_edge_y_lo+1]) + - np.sum(lx_slice_z[n_edge_x_lo:n_edge_x_hi, n_edge_y_hi-1]) + - np.sum(ly_slice_z[n_edge_x_lo+1, n_edge_y_lo:n_edge_y_hi]) + - np.sum(ly_slice_z[n_edge_x_hi-1, n_edge_y_lo:n_edge_y_hi])) - -perimeter_slice_z_true = L_cavity*4 - -print("Perimeter of the middle z-slice:", perimeter_slice_z) -assert np.isclose(perimeter_slice_z, perimeter_slice_z_true, rtol=1e-05, atol=1e-08) - -print("======== Testing the wrappers of m_face_areas =========") - -Sx_slice = np.sum(face_areas_x[nx//2,:,:]) -dx = (xmax-xmin)/nx -Ax = dx*dx -Sx_slice_true = L_cavity*L_cavity - 2*Ax -print("Area of the middle x-slice:", Sx_slice) -assert np.isclose(Sx_slice, Sx_slice_true, rtol=1e-05, atol=1e-08) - -Sy_slice = np.sum(face_areas_y[:,ny//2,:]) -dy = (ymax-ymin)/ny -Ay = dy*dy -Sy_slice_true = L_cavity*L_cavity - 2*Ay -print("Area of the middle y-slice:", Sx_slice) -assert np.isclose(Sy_slice, Sy_slice_true, rtol=1e-05, atol=1e-08) - -Sz_slice = np.sum(face_areas_z[:,:,nz//2]) -dz = (zmax-zmin)/nz -Az = dz*dz -Sz_slice_true = L_cavity*L_cavity - 2*Az -print("Area of the middle z-slice:", Sz_slice) -assert np.isclose(Sz_slice, Sz_slice_true, rtol=1e-05, atol=1e-08) - -sim.step(1) diff --git a/Examples/Tests/embedded_boundary_python_api/inputs_test_3d_embedded_boundary_picmi.py b/Examples/Tests/embedded_boundary_python_api/inputs_test_3d_embedded_boundary_picmi.py new file mode 100755 index 00000000000..80ce483f2c7 --- /dev/null +++ b/Examples/Tests/embedded_boundary_python_api/inputs_test_3d_embedded_boundary_picmi.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python3 +import numpy as np + +from pywarpx import fields, picmi + +max_steps = 1 +unit = 1e-3 + +################################## +# Define the mesh +################################## +# mesh cells per direction +nx = 64 +ny = 64 +nz = 64 + +# mesh bounds for domain +xmin = -32 * unit +xmax = 32 * unit +ymin = -32 * unit +ymax = 32 * unit +zmin = -32 * unit +zmax = 32 * unit + +########################## +# numerics components +########################## +lower_boundary_conditions = ["open", "dirichlet", "periodic"] +upper_boundary_conditions = ["open", "dirichlet", "periodic"] + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=lower_boundary_conditions, + upper_boundary_conditions=upper_boundary_conditions, + lower_boundary_conditions_particles=["absorbing", "absorbing", "periodic"], + upper_boundary_conditions_particles=["absorbing", "absorbing", "periodic"], + moving_window_velocity=None, + warpx_max_grid_size=64, +) + + +flag_correct_div = False + +solver = picmi.ElectromagneticSolver(grid=grid, method="Yee", cfl=1.0) + +n_cavity = 30 +L_cavity = n_cavity * unit + +embedded_boundary = picmi.EmbeddedBoundary( + implicit_function="max(max(max(x-L_cavity/2,-L_cavity/2-x),max(y-L_cavity/2,-L_cavity/2-y)),max(z-L_cavity/2,-L_cavity/2-z))", + L_cavity=L_cavity, +) + + +########################## +# diagnostics +########################## + +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=1, +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=1, + data_list=["Ex"], +) + +########################## +# simulation setup +########################## + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + warpx_embedded_boundary=embedded_boundary, + verbose=1, +) + +sim.add_diagnostic(particle_diag) +sim.add_diagnostic(field_diag) + +sim.initialize_inputs() + +sim.step(1) + +edge_lengths_x = fields.EdgeLengthsxWrapper() +edge_lengths_y = fields.EdgeLengthsyWrapper() +edge_lengths_z = fields.EdgeLengthszWrapper() +face_areas_x = fields.FaceAreasxWrapper() +face_areas_y = fields.FaceAreasyWrapper() +face_areas_z = fields.FaceAreaszWrapper() + +print("======== Testing the wrappers of m_edge_lengths =========") + +ly_slice_x = edge_lengths_y[nx // 2, :, :] +lz_slice_x = edge_lengths_z[nx // 2, :, :] + +n_edge_y_lo = (ny - 30) // 2 +n_edge_y_hi = ny - (ny - 30) // 2 +n_edge_z_lo = (nz - 30) // 2 +n_edge_z_hi = nz - (nz - 30) // 2 + +perimeter_slice_x = ( + np.sum(ly_slice_x[n_edge_y_lo:n_edge_y_hi, n_edge_z_lo + 1]) + + np.sum(ly_slice_x[n_edge_y_lo:n_edge_y_hi, n_edge_z_hi - 1]) + + np.sum(lz_slice_x[n_edge_y_lo + 1, n_edge_z_lo:n_edge_z_hi]) + + np.sum(lz_slice_x[n_edge_y_hi - 1, n_edge_z_lo:n_edge_z_hi]) +) + +perimeter_slice_x_true = L_cavity * 4 + +print("Perimeter of the middle x-slice:", perimeter_slice_x) +assert np.isclose(perimeter_slice_x, perimeter_slice_x_true, rtol=1e-05, atol=1e-08) + + +lx_slice_y = edge_lengths_x[:, ny // 2, :] +lz_slice_y = edge_lengths_z[:, ny // 2, :] + +n_edge_x_lo = (nx - 30) // 2 +n_edge_x_hi = nx - (nx - 30) // 2 +n_edge_z_lo = (nz - 30) // 2 +n_edge_z_hi = nz - (nz - 30) // 2 + +perimeter_slice_y = ( + np.sum(lx_slice_y[n_edge_x_lo:n_edge_x_hi, n_edge_z_lo + 1]) + + np.sum(lx_slice_y[n_edge_x_lo:n_edge_x_hi, n_edge_z_hi - 1]) + + np.sum(lz_slice_y[n_edge_x_lo + 1, n_edge_z_lo:n_edge_z_hi]) + + np.sum(lz_slice_y[n_edge_x_hi - 1, n_edge_z_lo:n_edge_z_hi]) +) + +perimeter_slice_y_true = L_cavity * 4 + + +print("Perimeter of the middle y-slice:", perimeter_slice_y) +assert np.isclose(perimeter_slice_y, perimeter_slice_y_true, rtol=1e-05, atol=1e-08) + + +lx_slice_z = edge_lengths_x[:, :, nz // 2] +ly_slice_z = edge_lengths_y[:, :, nz // 2] + +n_edge_x_lo = (nx - 30) // 2 +n_edge_x_hi = nx - (nx - 30) // 2 +n_edge_y_lo = (ny - 30) // 2 +n_edge_y_hi = ny - (ny - 30) // 2 + +perimeter_slice_z = ( + np.sum(lx_slice_z[n_edge_x_lo:n_edge_x_hi, n_edge_y_lo + 1]) + + np.sum(lx_slice_z[n_edge_x_lo:n_edge_x_hi, n_edge_y_hi - 1]) + + np.sum(ly_slice_z[n_edge_x_lo + 1, n_edge_y_lo:n_edge_y_hi]) + + np.sum(ly_slice_z[n_edge_x_hi - 1, n_edge_y_lo:n_edge_y_hi]) +) + +perimeter_slice_z_true = L_cavity * 4 + +print("Perimeter of the middle z-slice:", perimeter_slice_z) +assert np.isclose(perimeter_slice_z, perimeter_slice_z_true, rtol=1e-05, atol=1e-08) + +print("======== Testing the wrappers of m_face_areas =========") + +Sx_slice = np.sum(face_areas_x[nx // 2, :, :]) +dx = (xmax - xmin) / nx +Ax = dx * dx +Sx_slice_true = L_cavity * L_cavity - 2 * Ax +print("Area of the middle x-slice:", Sx_slice) +assert np.isclose(Sx_slice, Sx_slice_true, rtol=1e-05, atol=1e-08) + +Sy_slice = np.sum(face_areas_y[:, ny // 2, :]) +dy = (ymax - ymin) / ny +Ay = dy * dy +Sy_slice_true = L_cavity * L_cavity - 2 * Ay +print("Area of the middle y-slice:", Sx_slice) +assert np.isclose(Sy_slice, Sy_slice_true, rtol=1e-05, atol=1e-08) + +Sz_slice = np.sum(face_areas_z[:, :, nz // 2]) +dz = (zmax - zmin) / nz +Az = dz * dz +Sz_slice_true = L_cavity * L_cavity - 2 * Az +print("Area of the middle z-slice:", Sz_slice) +assert np.isclose(Sz_slice, Sz_slice_true, rtol=1e-05, atol=1e-08) + +sim.step(1) diff --git a/Examples/Tests/embedded_boundary_rotated_cube/CMakeLists.txt b/Examples/Tests/embedded_boundary_rotated_cube/CMakeLists.txt new file mode 100644 index 00000000000..fcfe97905d8 --- /dev/null +++ b/Examples/Tests/embedded_boundary_rotated_cube/CMakeLists.txt @@ -0,0 +1,26 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_2d_embedded_boundary_rotated_cube # name + 2 # dims + 1 # nprocs + inputs_test_2d_embedded_boundary_rotated_cube # inputs + analysis_fields_2d.py # analysis + diags/diag1000068 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_3d_embedded_boundary_rotated_cube # name + 3 # dims + 1 # nprocs + inputs_test_3d_embedded_boundary_rotated_cube # inputs + analysis_fields_3d.py # analysis + diags/diag1000111 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields.py b/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields.py deleted file mode 100755 index e849958468f..00000000000 --- a/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2021 Lorenzo Giacomel -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - - -import os -import sys - -import numpy as np -import yt -from scipy.constants import c, mu_0, pi - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -# This is a script that analyses the simulation results from -# the script `inputs_3d`. This simulates a TMmnp mode in a PEC cubic resonator rotated by pi/8. -# The magnetic field in the simulation is given (in theory) by: -# $$ B_x = \frac{-2\mu}{h^2}\, k_x k_z \sin(k_x x)\cos(k_y y)\cos(k_z z)\cos( \omega_p t)$$ -# $$ B_y = \frac{-2\mu}{h^2}\, k_y k_z \cos(k_x x)\sin(k_y y)\cos(k_z z)\cos( \omega_p t)$$ -# $$ B_z = \cos(k_x x)\cos(k_y y)\sin(k_z z)\sin( \omega_p t)$$ -# with -# $$ h^2 = k_x^2 + k_y^2 + k_z^2$$ -# $$ k_x = \frac{m\pi}{L}$$ -# $$ k_y = \frac{n\pi}{L}$$ -# $$ k_z = \frac{p\pi}{L}$$ - -hi = [0.8, 0.8, 0.8] -lo = [-0.8, -0.8, -0.8] -m = 0 -n = 1 -p = 1 -Lx = 1 -Ly = 1 -Lz = 1 -h_2 = (m * pi / Lx) ** 2 + (n * pi / Ly) ** 2 + (p * pi / Lz) ** 2 -theta = np.pi/6 - -# Open the right plot file -filename = sys.argv[1] -ds = yt.load(filename) -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - -t = ds.current_time.to_value() - -rel_tol_err = 1e-2 -my_grid = ds.index.grids[0] - -By_sim = my_grid['raw', 'By_fp'].squeeze().v -Bz_sim = my_grid['raw', 'Bz_fp'].squeeze().v - -ncells = np.array(np.shape(By_sim[:, :, :, 0])) -dx = (hi[0] - lo[0])/ncells[0] -dy = (hi[1] - lo[1])/ncells[1] -dz = (hi[2] - lo[2])/ncells[2] - -# Compute the analytic solution -Bx_th = np.zeros(ncells) -By_th = np.zeros(ncells) -Bz_th = np.zeros(ncells) -for i in range(ncells[0]): - for j in range(ncells[1]): - for k in range(ncells[2]): - x0 = (i+0.5)*dx + lo[0] - y0 = j*dy + lo[1] - z0 = (k+0.5)*dz + lo[2] - - x = x0 - y = y0*np.cos(-theta)-z0*np.sin(-theta) - z = y0*np.sin(-theta)+z0*np.cos(-theta) - By = -2/h_2*mu_0*(n * pi/Ly)*(p * pi/Lz) * (np.cos(m * pi/Lx * (x - Lx/2)) * - np.sin(n * pi/Ly * (y - Ly/2)) * - np.cos(p * pi/Lz * (z - Lz/2)) * - np.cos(np.sqrt(2) * - np.pi / Lx * c * t)) - - Bz = mu_0*(np.cos(m * pi/Lx * (x - Lx/2)) * - np.cos(n * pi/Ly * (y - Ly/2)) * - np.sin(p * pi/Lz * (z - Lz/2)) * - np.cos(np.sqrt(2) * np.pi / Lx * c * t)) - - By_th[i, j, k] = (By*np.cos(theta) - Bz*np.sin(theta))*(By_sim[i, j, k, 0] != 0) - - x0 = (i+0.5)*dx + lo[0] - y0 = (j+0.5)*dy + lo[1] - z0 = k*dz + lo[2] - - x = x0 - y = y0*np.cos(-theta)-z0*np.sin(-theta) - z = y0*np.sin(-theta)+z0*np.cos(-theta) - - By = -2/h_2*mu_0*(n * pi/Ly)*(p * pi/Lz) * (np.cos(m * pi/Lx * (x - Lx/2)) * - np.sin(n * pi/Ly * (y - Ly/2)) * - np.cos(p * pi/Lz * (z - Lz/2)) * - np.cos(np.sqrt(2) * - np.pi / Lx * c * t)) - - Bz = mu_0*(np.cos(m * pi/Lx * (x - Lx/2)) * - np.cos(n * pi/Ly * (y - Ly/2)) * - np.sin(p * pi/Lz * (z - Lz/2)) * - np.cos(np.sqrt(2) * np.pi / Lx * c * t)) - - Bz_th[i, j, k] = (By*np.sin(theta) + Bz*np.cos(theta))*(Bz_sim[i, j, k, 0] != 0) - - -# Compute relative l^2 error on By -rel_err_y = np.sqrt( np.sum(np.square(By_sim[:, :, :, 0] - By_th)) / np.sum(np.square(By_th))) -assert(rel_err_y < rel_tol_err) -# Compute relative l^2 error on Bz -rel_err_z = np.sqrt( np.sum(np.square(Bz_sim[:, :, :, 0] - Bz_th)) / np.sum(np.square(Bz_th))) -assert(rel_err_z < rel_tol_err) - -test_name = os.path.split(os.getcwd())[1] - -checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields_2d.py b/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields_2d.py index dcdbc83a729..6f3904e8764 100755 --- a/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields_2d.py +++ b/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields_2d.py @@ -7,7 +7,7 @@ import yt from scipy.constants import c, mu_0, pi -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # This is a script that analyses the simulation results from @@ -32,14 +32,16 @@ # Open the right plot file filename = sys.argv[1] ds = yt.load(filename) -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) my_grid = ds.index.grids[0] -By_sim = my_grid['By'].squeeze().v +By_sim = my_grid["By"].squeeze().v t = ds.current_time.to_value() -theta = np.pi/8 +theta = np.pi / 8 # Compute the analytic solution By_th = np.zeros(ncells) @@ -47,18 +49,24 @@ for j in range(ncells[1]): x = i * dx + lo[0] z = j * dz + lo[1] - xr = x*np.cos(-theta) + z*np.sin(-theta) - zr = -x*np.sin(-theta) + z*np.cos(-theta) + xr = x * np.cos(-theta) + z * np.sin(-theta) + zr = -x * np.sin(-theta) + z * np.cos(-theta) - By_th[i, j] = mu_0 * (np.cos(m * pi / Lx * (xr - Lx / 2)) * - np.cos(n * pi / Lz * (zr - Lz / 2)) * - np.cos(np.pi / Lx * c * t))*(By_sim[i, j] != 0) + By_th[i, j] = ( + mu_0 + * ( + np.cos(m * pi / Lx * (xr - Lx / 2)) + * np.cos(n * pi / Lz * (zr - Lz / 2)) + * np.cos(np.pi / Lx * c * t) + ) + * (By_sim[i, j] != 0) + ) rel_tol_err = 1e-1 # Compute relative l^2 error on By rel_err_y = np.sqrt(np.sum(np.square(By_sim - By_th)) / np.sum(np.square(By_th))) -assert (rel_err_y < rel_tol_err) +assert rel_err_y < rel_tol_err test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields_3d.py b/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields_3d.py new file mode 100755 index 00000000000..968ebe395a5 --- /dev/null +++ b/Examples/Tests/embedded_boundary_rotated_cube/analysis_fields_3d.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python3 + +# Copyright 2021 Lorenzo Giacomel +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +import os +import sys + +import numpy as np +import yt +from scipy.constants import c, mu_0, pi + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# This is a script that analyses the simulation results from +# the script `inputs_3d`. This simulates a TMmnp mode in a PEC cubic resonator rotated by pi/8. +# The magnetic field in the simulation is given (in theory) by: +# $$ B_x = \frac{-2\mu}{h^2}\, k_x k_z \sin(k_x x)\cos(k_y y)\cos(k_z z)\cos( \omega_p t)$$ +# $$ B_y = \frac{-2\mu}{h^2}\, k_y k_z \cos(k_x x)\sin(k_y y)\cos(k_z z)\cos( \omega_p t)$$ +# $$ B_z = \cos(k_x x)\cos(k_y y)\sin(k_z z)\sin( \omega_p t)$$ +# with +# $$ h^2 = k_x^2 + k_y^2 + k_z^2$$ +# $$ k_x = \frac{m\pi}{L}$$ +# $$ k_y = \frac{n\pi}{L}$$ +# $$ k_z = \frac{p\pi}{L}$$ + +hi = [0.8, 0.8, 0.8] +lo = [-0.8, -0.8, -0.8] +m = 0 +n = 1 +p = 1 +Lx = 1 +Ly = 1 +Lz = 1 +h_2 = (m * pi / Lx) ** 2 + (n * pi / Ly) ** 2 + (p * pi / Lz) ** 2 +theta = np.pi / 6 + +# Open the right plot file +filename = sys.argv[1] +ds = yt.load(filename) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) + +t = ds.current_time.to_value() + +rel_tol_err = 1e-2 +my_grid = ds.index.grids[0] + +By_sim = my_grid["raw", "By_fp"].squeeze().v +Bz_sim = my_grid["raw", "Bz_fp"].squeeze().v + +ncells = np.array(np.shape(By_sim[:, :, :, 0])) +dx = (hi[0] - lo[0]) / ncells[0] +dy = (hi[1] - lo[1]) / ncells[1] +dz = (hi[2] - lo[2]) / ncells[2] + +# Compute the analytic solution +Bx_th = np.zeros(ncells) +By_th = np.zeros(ncells) +Bz_th = np.zeros(ncells) +for i in range(ncells[0]): + for j in range(ncells[1]): + for k in range(ncells[2]): + x0 = (i + 0.5) * dx + lo[0] + y0 = j * dy + lo[1] + z0 = (k + 0.5) * dz + lo[2] + + x = x0 + y = y0 * np.cos(-theta) - z0 * np.sin(-theta) + z = y0 * np.sin(-theta) + z0 * np.cos(-theta) + By = ( + -2 + / h_2 + * mu_0 + * (n * pi / Ly) + * (p * pi / Lz) + * ( + np.cos(m * pi / Lx * (x - Lx / 2)) + * np.sin(n * pi / Ly * (y - Ly / 2)) + * np.cos(p * pi / Lz * (z - Lz / 2)) + * np.cos(np.sqrt(2) * np.pi / Lx * c * t) + ) + ) + + Bz = mu_0 * ( + np.cos(m * pi / Lx * (x - Lx / 2)) + * np.cos(n * pi / Ly * (y - Ly / 2)) + * np.sin(p * pi / Lz * (z - Lz / 2)) + * np.cos(np.sqrt(2) * np.pi / Lx * c * t) + ) + + By_th[i, j, k] = (By * np.cos(theta) - Bz * np.sin(theta)) * ( + By_sim[i, j, k, 0] != 0 + ) + + x0 = (i + 0.5) * dx + lo[0] + y0 = (j + 0.5) * dy + lo[1] + z0 = k * dz + lo[2] + + x = x0 + y = y0 * np.cos(-theta) - z0 * np.sin(-theta) + z = y0 * np.sin(-theta) + z0 * np.cos(-theta) + + By = ( + -2 + / h_2 + * mu_0 + * (n * pi / Ly) + * (p * pi / Lz) + * ( + np.cos(m * pi / Lx * (x - Lx / 2)) + * np.sin(n * pi / Ly * (y - Ly / 2)) + * np.cos(p * pi / Lz * (z - Lz / 2)) + * np.cos(np.sqrt(2) * np.pi / Lx * c * t) + ) + ) + + Bz = mu_0 * ( + np.cos(m * pi / Lx * (x - Lx / 2)) + * np.cos(n * pi / Ly * (y - Ly / 2)) + * np.sin(p * pi / Lz * (z - Lz / 2)) + * np.cos(np.sqrt(2) * np.pi / Lx * c * t) + ) + + Bz_th[i, j, k] = (By * np.sin(theta) + Bz * np.cos(theta)) * ( + Bz_sim[i, j, k, 0] != 0 + ) + + +# Compute relative l^2 error on By +rel_err_y = np.sqrt( + np.sum(np.square(By_sim[:, :, :, 0] - By_th)) / np.sum(np.square(By_th)) +) +assert rel_err_y < rel_tol_err +# Compute relative l^2 error on Bz +rel_err_z = np.sqrt( + np.sum(np.square(Bz_sim[:, :, :, 0] - Bz_th)) / np.sum(np.square(Bz_th)) +) +assert rel_err_z < rel_tol_err + +test_name = os.path.split(os.getcwd())[1] + +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/embedded_boundary_rotated_cube/inputs_2d b/Examples/Tests/embedded_boundary_rotated_cube/inputs_test_2d_embedded_boundary_rotated_cube similarity index 96% rename from Examples/Tests/embedded_boundary_rotated_cube/inputs_2d rename to Examples/Tests/embedded_boundary_rotated_cube/inputs_test_2d_embedded_boundary_rotated_cube index e7e03168824..24fb2938c2d 100644 --- a/Examples/Tests/embedded_boundary_rotated_cube/inputs_2d +++ b/Examples/Tests/embedded_boundary_rotated_cube/inputs_test_2d_embedded_boundary_rotated_cube @@ -7,6 +7,7 @@ geometry.dims = 2 geometry.prob_lo = -0.8 -0.8 geometry.prob_hi = 0.8 0.8 warpx.cfl = 1 +warpx.abort_on_warning_threshold = medium boundary.field_lo = pec pec boundary.field_hi = pec pec diff --git a/Examples/Tests/embedded_boundary_rotated_cube/inputs_3d b/Examples/Tests/embedded_boundary_rotated_cube/inputs_test_3d_embedded_boundary_rotated_cube similarity index 98% rename from Examples/Tests/embedded_boundary_rotated_cube/inputs_3d rename to Examples/Tests/embedded_boundary_rotated_cube/inputs_test_3d_embedded_boundary_rotated_cube index 77e259e8975..faefeec2206 100644 --- a/Examples/Tests/embedded_boundary_rotated_cube/inputs_3d +++ b/Examples/Tests/embedded_boundary_rotated_cube/inputs_test_3d_embedded_boundary_rotated_cube @@ -7,6 +7,7 @@ geometry.dims = 3 geometry.prob_lo = -0.8 -0.8 -0.8 geometry.prob_hi = 0.8 0.8 0.8 warpx.cfl = 1 +warpx.abort_on_warning_threshold = medium boundary.field_lo = pec pec pec boundary.field_hi = pec pec pec diff --git a/Examples/Tests/embedded_circle/CMakeLists.txt b/Examples/Tests/embedded_circle/CMakeLists.txt new file mode 100644 index 00000000000..4b9ee426569 --- /dev/null +++ b/Examples/Tests/embedded_circle/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_2d_embedded_circle # name + 2 # dims + 2 # nprocs + inputs_test_2d_embedded_circle # inputs + analysis.py # analysis + diags/diag1000011 + OFF # dependency + ) +endif() diff --git a/Examples/Tests/embedded_circle/analysis.py b/Examples/Tests/embedded_circle/analysis.py index 6401b47bb90..569ca40dce4 100755 --- a/Examples/Tests/embedded_circle/analysis.py +++ b/Examples/Tests/embedded_circle/analysis.py @@ -3,7 +3,7 @@ import os import sys -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file diff --git a/Examples/Tests/embedded_circle/inputs_2d b/Examples/Tests/embedded_circle/inputs_test_2d_embedded_circle similarity index 100% rename from Examples/Tests/embedded_circle/inputs_2d rename to Examples/Tests/embedded_circle/inputs_test_2d_embedded_circle diff --git a/Examples/Tests/energy_conserving_thermal_plasma/CMakeLists.txt b/Examples/Tests/energy_conserving_thermal_plasma/CMakeLists.txt new file mode 100644 index 00000000000..c89d439b75e --- /dev/null +++ b/Examples/Tests/energy_conserving_thermal_plasma/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_energy_conserving_thermal_plasma # name + 2 # dims + 2 # nprocs + inputs_test_2d_energy_conserving_thermal_plasma # inputs + analysis.py # analysis + diags/diag1000500 # output + OFF # dependency +) diff --git a/Examples/Tests/energy_conserving_thermal_plasma/analysis.py b/Examples/Tests/energy_conserving_thermal_plasma/analysis.py index 43e9b6d9822..4cf7b4ff4e6 100755 --- a/Examples/Tests/energy_conserving_thermal_plasma/analysis.py +++ b/Examples/Tests/energy_conserving_thermal_plasma/analysis.py @@ -17,21 +17,21 @@ import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file fn = sys.argv[1] # Get energy as a function of time, from reduced diagnostics -EFdata = np.genfromtxt('./diags/reducedfiles/EF.txt') # Field energy -EPdata = np.genfromtxt('./diags/reducedfiles/EP.txt') # Particle energy -field_energy = EFdata[:,2] -particle_energy = EPdata[:,2] +EFdata = np.genfromtxt("./diags/reducedfiles/EF.txt") # Field energy +EPdata = np.genfromtxt("./diags/reducedfiles/EP.txt") # Particle energy +field_energy = EFdata[:, 2] +particle_energy = EPdata[:, 2] E = field_energy + particle_energy -print(abs(E-E[0])/E[0]) +print(abs(E - E[0]) / E[0]) # Check that the energy is conserved to 0.3% -assert np.all( abs(E-E[0])/E[0] < 0.003 ) +assert np.all(abs(E - E[0]) / E[0] < 0.003) # Checksum test test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/energy_conserving_thermal_plasma/inputs_2d_electrostatic b/Examples/Tests/energy_conserving_thermal_plasma/inputs_test_2d_energy_conserving_thermal_plasma similarity index 100% rename from Examples/Tests/energy_conserving_thermal_plasma/inputs_2d_electrostatic rename to Examples/Tests/energy_conserving_thermal_plasma/inputs_test_2d_energy_conserving_thermal_plasma diff --git a/Examples/Tests/field_ionization/CMakeLists.txt b/Examples/Tests/field_ionization/CMakeLists.txt new file mode 100644 index 00000000000..9154173ac5f --- /dev/null +++ b/Examples/Tests/field_ionization/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_ionization_boost # name + 2 # dims + 2 # nprocs + inputs_test_2d_ionization_boost # inputs + analysis.py # analysis + diags/diag1000420 # output + OFF # dependency +) + +add_warpx_test( + test_2d_ionization_lab # name + 2 # dims + 2 # nprocs + inputs_test_2d_ionization_lab # inputs + analysis.py # analysis + diags/diag1001600 # output + OFF # dependency +) + +add_warpx_test( + test_2d_ionization_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_ionization_picmi.py # inputs + analysis.py # analysis + diags/diag1001600 # output + OFF # dependency +) diff --git a/Examples/Tests/field_ionization/README.rst b/Examples/Tests/field_ionization/README.rst new file mode 100644 index 00000000000..c2f11ed1a40 --- /dev/null +++ b/Examples/Tests/field_ionization/README.rst @@ -0,0 +1,59 @@ +.. _examples-tests-field_ionization: + +Field Ionization +================ + +Run Test +-------- + +For `MPI-parallel `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. + +.. tab-set:: + + .. tab-item:: lab frame + + This example can be run **either** as: + + * **Python** script: ``python3 inputs_test_2d_ionization_picmi.py`` or + * WarpX **executable** using an input file: ``warpx.2d inputs_test_2d_ionization_lab max_step=1600`` + + .. tab-set:: + + .. tab-item:: Python: Script + + .. literalinclude:: inputs_test_2d_ionization_picmi.py + :language: python3 + :caption: You can copy this file from ``Examples/Tests/field_ionization/inputs_test_2d_ionization_picmi.py``. + + .. tab-item:: Executable: Input File + + .. literalinclude:: inputs_test_2d_ionization_lab + :language: ini + :caption: You can copy this file from ``Examples/Tests/field_ionization/inputs_test_2d_ionization_lab``. + + .. tab-item:: boosted frame + + This example can be run as: + + * WarpX **executable** using an input file: ``warpx.2d inputs_test_2d_ionization_boost max_step=420`` + + .. literalinclude:: inputs_test_2d_ionization_boost + :language: ini + :caption: You can copy this file from ``Examples/Tests/field_ionization/inputs_test_2d_ionization_boost``. + +Analyze +------- + +.. dropdown:: Script ``analysis.py`` + + .. literalinclude:: analysis.py + :language: python3 + :caption: You can copy this file from ``Examples/Tests/field_ionization/analysis.py``. + +Visualize +--------- + +.. figure:: https://gist.githubusercontent.com/johvandewetering/48d092c003915f1d1689b507caa2865b/raw/29f5d12ed77831047ca12f456a07dbf3b99770d5/image_ionization.png + :alt: Electric field of the laser pulse with (top) ions with ionization levels and (bottom) ionized electrons. + + Electric field of the laser pulse with (top) ions with ionization levels and (bottom) ionized electrons. diff --git a/Examples/Tests/ionization/analysis_ionization.py b/Examples/Tests/field_ionization/analysis.py similarity index 53% rename from Examples/Tests/ionization/analysis_ionization.py rename to Examples/Tests/field_ionization/analysis.py index 90657915b50..62d3f839941 100755 --- a/Examples/Tests/ionization/analysis_ionization.py +++ b/Examples/Tests/field_ionization/analysis.py @@ -25,17 +25,17 @@ import yt yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Open plotfile specified in command line, and get ion's ionization level. filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) ad = ds.all_data() -ilev = ad['ions', 'particle_ionizationLevel'].v +ilev = ad["ions", "particle_ionizationLevel"].v # Fraction of Nitrogen ions that are N5+. -N5_fraction = ilev[ilev == 5].size/float(ilev.size) +N5_fraction = ilev[ilev == 5].size / float(ilev.size) print("Number of ions: " + str(ilev.size)) print("Number of N5+ : " + str(ilev[ilev == 5].size)) @@ -44,63 +44,68 @@ do_plot = False if do_plot: import matplotlib.pyplot as plt - all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) - F = all_data_level_0['boxlib', 'Ex'].v.squeeze() - extent = [ ds.domain_left_edge[1], ds.domain_right_edge[1], - ds.domain_left_edge[0], ds.domain_right_edge[0] ] + + all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions + ) + F = all_data_level_0["boxlib", "Ex"].v.squeeze() + extent = [ + ds.domain_left_edge[1], + ds.domain_right_edge[1], + ds.domain_left_edge[0], + ds.domain_right_edge[0], + ] ad = ds.all_data() # Plot ions with ionization levels - species = 'ions' - xi = ad[species, 'particle_position_x'].v - zi = ad[species, 'particle_position_y'].v - ii = ad[species, 'particle_ionizationLevel'].v - plt.figure(figsize=(10,10)) + species = "ions" + xi = ad[species, "particle_position_x"].v + zi = ad[species, "particle_position_y"].v + ii = ad[species, "particle_ionizationLevel"].v + plt.figure(figsize=(10, 10)) plt.subplot(211) - plt.imshow(np.abs(F), extent=extent, aspect='auto', - cmap='magma', origin='default') + plt.imshow(np.abs(F), extent=extent, aspect="auto", cmap="magma", origin="default") plt.colorbar() - for lev in range(int(np.max(ii)+1)): - select = (ii == lev) - plt.scatter(zi[select],xi[select],s=.2, - label='ionization level: ' + str(lev)) + for lev in range(int(np.max(ii) + 1)): + select = ii == lev + plt.scatter( + zi[select], xi[select], s=0.2, label="ionization level: " + str(lev) + ) plt.legend() plt.title("abs(Ex) (V/m) and ions") plt.xlabel("z (m)") plt.ylabel("x (m)") plt.subplot(212) - plt.imshow(np.abs(F), extent=extent, aspect='auto', - cmap='magma', origin='default') + plt.imshow(np.abs(F), extent=extent, aspect="auto", cmap="magma", origin="default") plt.colorbar() # Plot electrons - species = 'electrons' + species = "electrons" if species in [x[0] for x in ds.field_list]: - xe = ad[species, 'particle_position_x'].v - ze = ad[species, 'particle_position_y'].v - plt.scatter(ze,xe,s=.1,c='r',label='electrons') + xe = ad[species, "particle_position_x"].v + ze = ad[species, "particle_position_y"].v + plt.scatter(ze, xe, s=0.1, c="r", label="electrons") plt.title("abs(Ex) (V/m) and electrons") plt.xlabel("z (m)") plt.ylabel("x (m)") - plt.savefig("image_ionization.pdf", bbox_inches='tight') + plt.savefig("image_ionization.pdf", bbox_inches="tight") -error_rel = abs(N5_fraction-0.32) / 0.32 +error_rel = abs(N5_fraction - 0.32) / 0.32 tolerance_rel = 0.07 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel # Check that the user runtime component (if it exists) worked as expected try: - orig_z = ad['electrons', 'particle_orig_z'].v + orig_z = ad["electrons", "particle_orig_z"].v print(f"orig_z: min = {np.min(orig_z)}, max = {np.max(orig_z)}") - assert np.all( (orig_z > 0.0) & (orig_z < 1.5e-5) ) - print('particle_orig_z has reasonable values') + assert np.all((orig_z > 0.0) & (orig_z < 1.5e-5)) + print("particle_orig_z has reasonable values") except yt.utilities.exceptions.YTFieldNotFound: - pass # The backtransformed diagnostic version of the test does not have orig_z + pass # The backtransformed diagnostic version of the test does not have orig_z test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/field_ionization/catalyst_pipeline.py b/Examples/Tests/field_ionization/catalyst_pipeline.py new file mode 100644 index 00000000000..321a23f4053 --- /dev/null +++ b/Examples/Tests/field_ionization/catalyst_pipeline.py @@ -0,0 +1,403 @@ +# script-version: 2.0 +# Catalyst state generated using paraview version 5.11.1-1332-ga0a402a54e +# and validated with paraview 5.12,1 +import paraview + +paraview.compatibility.major = 5 +paraview.compatibility.minor = 12 + +#### import the simple module from the paraview +from paraview.simple import * # noqa: F403 + +#### disable automatic camera reset on 'Show' +paraview.simple._DisableFirstRenderCameraReset() + +# ---------------------------------------------------------------- +# setup views used in the visualization +# ---------------------------------------------------------------- + +# Create a new 'Render View' +renderView1 = CreateView("RenderView") +renderView1.ViewSize = [889, 820] +renderView1.InteractionMode = "2D" +renderView1.AxesGrid = "Grid Axes 3D Actor" +renderView1.CenterOfRotation = [5.125578491129211e-06, 5.125219398642561e-06, 0.0] +renderView1.StereoType = "Crystal Eyes" +renderView1.CameraPosition = [ + -3.2986377960746266e-08, + 1.2519774889107966e-05, + 6.655318906751408e-05, +] +renderView1.CameraFocalPoint = [-3.2986377960746266e-08, 1.2519774889107966e-05, 0.0] +renderView1.CameraFocalDisk = 1.0 +renderView1.CameraParallelScale = 9.246257677588838e-06 +renderView1.LegendGrid = "Legend Grid Actor" +renderView1.UseColorPaletteForBackground = 0 +renderView1.Background = [0.13725490196078433, 0.1450980392156863, 0.17647058823529413] + +SetActiveView(None) + +# ---------------------------------------------------------------- +# setup view layouts +# ---------------------------------------------------------------- + +# create new layout object 'Layout #1' +layout1 = CreateLayout(name="Layout #1") +layout1.AssignView(0, renderView1) +layout1.SetSize(889, 820) + +# ---------------------------------------------------------------- +# restore active view +# ---------------------------------------------------------------- +SetActiveView(renderView1) + +# ---------------------------------------------------------------- +# setup the data processing pipelines +# ---------------------------------------------------------------- + +# create a new 'XML Partitioned Dataset Collection Reader' +particles = PVTrivialProducer(registrationName="particles") + +# create a new 'Clip' +clip1 = Clip(registrationName="Clip1", Input=particles) +clip1.ClipType = "Plane" +clip1.HyperTreeGridClipper = "Plane" +clip1.Scalars = ["CELLS", "particle_electrons_cpu"] +clip1.Value = -396581.0 +clip1.Invert = 0 + +# init the 'Plane' selected for 'ClipType' +clip1.ClipType.Origin = [5.12557849112921e-06, 5.02521939864256e-06, 0.0] +clip1.ClipType.Normal = [0.0, 1.0, 0.0] + +# init the 'Plane' selected for 'HyperTreeGridClipper' +clip1.HyperTreeGridClipper.Origin = [5.12557849112921e-06, 5.12521939864256e-06, 0.0] + +# ---------------------------------------------------------------- +# setup the visualization in view 'renderView1' +# ---------------------------------------------------------------- + +# show data from clip1 +clip1Display = Show(clip1, renderView1, "UnstructuredGridRepresentation") + +# get 2D transfer function for 'particle_electrons_ux' +particle_electrons_uxTF2D = GetTransferFunction2D("particle_electrons_ux") +particle_electrons_uxTF2D.ScalarRangeInitialized = 1 +particle_electrons_uxTF2D.Range = [-719020005.8608257, 713207105.8017796, 0.0, 1.0] + +# get color transfer function/color map for 'particle_electrons_ux' +particle_electrons_uxLUT = GetColorTransferFunction("particle_electrons_ux") +particle_electrons_uxLUT.TransferFunction2D = particle_electrons_uxTF2D +particle_electrons_uxLUT.RGBPoints = [ + -813777010.3574873, + 0.0862745098039216, + 0.00392156862745098, + 0.298039215686275, + -764496926.60325, + 0.113725, + 0.0235294, + 0.45098, + -723569500.3656244, + 0.105882, + 0.0509804, + 0.509804, + -695170821.8676349, + 0.0392157, + 0.0392157, + 0.560784, + -667607367.8918439, + 0.0313725, + 0.0980392, + 0.6, + -640879233.4148993, + 0.0431373, + 0.164706, + 0.639216, + -602457575.7205275, + 0.054902, + 0.243137, + 0.678431, + -551506980.3332543, + 0.054902, + 0.317647, + 0.709804, + -488862937.3087116, + 0.0509804, + 0.396078, + 0.741176, + -448248678.177614, + 0.0392157, + 0.466667, + 0.768627, + -407634419.0465164, + 0.0313725, + 0.537255, + 0.788235, + -365245168.54020303, + 0.0313725, + 0.615686, + 0.811765, + -321811973.7593288, + 0.0235294, + 0.709804, + 0.831373, + -278378684.00181174, + 0.0509804, + 0.8, + 0.85098, + -242462794.85069358, + 0.0705882, + 0.854902, + 0.870588, + -209052579.2661966, + 0.262745, + 0.901961, + 0.862745, + -179818676.24599826, + 0.423529, + 0.941176, + 0.87451, + -134714937.4440689, + 0.572549, + 0.964706, + 0.835294, + -104645714.92502928, + 0.658824, + 0.980392, + 0.843137, + -82929117.53459203, + 0.764706, + 0.980392, + 0.866667, + -59542023.61142123, + 0.827451, + 0.980392, + 0.886275, + -13603012.798971772, + 0.913725, + 0.988235, + 0.937255, + 596326.4500254393, + 1.0, + 1.0, + 0.972549019607843, + 14795665.69902289, + 0.988235, + 0.980392, + 0.870588, + 35677038.567251325, + 0.992156862745098, + 0.972549019607843, + 0.803921568627451, + 51546874.348982334, + 0.992157, + 0.964706, + 0.713725, + 78275008.82592702, + 0.988235, + 0.956863, + 0.643137, + 120872979.08459747, + 0.980392, + 0.917647, + 0.509804, + 156788963.21235335, + 0.968627, + 0.87451, + 0.407843, + 193540171.8623129, + 0.94902, + 0.823529, + 0.321569, + 220268306.3392564, + 0.929412, + 0.776471, + 0.278431, + 259525283.53246915, + 0.909804, + 0.717647, + 0.235294, + 294605948.1613816, + 0.890196, + 0.658824, + 0.196078, + 323422245.31323636, + 0.878431, + 0.619608, + 0.168627, + 364036504.4443337, + 0.870588, + 0.54902, + 0.156863, + 404650763.575431, + 0.85098, + 0.47451, + 0.145098, + 445265022.7065283, + 0.831373, + 0.411765, + 0.133333, + 485879281.83762586, + 0.811765, + 0.345098, + 0.113725, + 526493540.9687232, + 0.788235, + 0.266667, + 0.0941176, + 567107800.0998205, + 0.741176, + 0.184314, + 0.0745098, + 607722059.2309178, + 0.690196, + 0.12549, + 0.0627451, + 648336318.3620149, + 0.619608, + 0.0627451, + 0.0431373, + 686340409.4987272, + 0.54902, + 0.027451, + 0.0705882, + 719750596.8870386, + 0.470588, + 0.0156863, + 0.0901961, + 757337055.2873727, + 0.4, + 0.00392157, + 0.101961, + 810793354.8864042, + 0.188235294117647, + 0.0, + 0.0705882352941176, +] +particle_electrons_uxLUT.ColorSpace = "Lab" +particle_electrons_uxLUT.NanOpacity = 0.0 +particle_electrons_uxLUT.ScalarRangeInitialized = 1.0 + +# get opacity transfer function/opacity map for 'particle_electrons_ux' +particle_electrons_uxPWF = GetOpacityTransferFunction("particle_electrons_ux") +particle_electrons_uxPWF.Points = [ + -813777010.3574873, + 0.0, + 0.5, + 0.0, + 810793354.8864042, + 1.0, + 0.5, + 0.0, +] +particle_electrons_uxPWF.ScalarRangeInitialized = 1 + +# trace defaults for the display properties. +clip1Display.Representation = "Surface" +clip1Display.ColorArrayName = ["CELLS", "particle_electrons_ux"] +clip1Display.LookupTable = particle_electrons_uxLUT +clip1Display.SelectTCoordArray = "None" +clip1Display.SelectNormalArray = "None" +clip1Display.SelectTangentArray = "None" +clip1Display.OSPRayScaleFunction = "Piecewise Function" +clip1Display.Assembly = "Hierarchy" +clip1Display.SelectOrientationVectors = "None" +clip1Display.ScaleFactor = 2.0093934867816264e-06 +clip1Display.SelectScaleArray = "None" +clip1Display.GlyphType = "Arrow" +clip1Display.GlyphTableIndexArray = "None" +clip1Display.GaussianRadius = 1.0046967433908131e-07 +clip1Display.SetScaleArray = [None, ""] +clip1Display.ScaleTransferFunction = "Piecewise Function" +clip1Display.OpacityArray = [None, ""] +clip1Display.OpacityTransferFunction = "Piecewise Function" +clip1Display.DataAxesGrid = "Grid Axes Representation" +clip1Display.PolarAxes = "Polar Axes Representation" +clip1Display.ScalarOpacityFunction = particle_electrons_uxPWF +clip1Display.ScalarOpacityUnitDistance = 6.795294978934044e-07 +clip1Display.OpacityArrayName = ["CELLS", "particle_electrons_cpu"] +clip1Display.SelectInputVectors = [None, ""] +clip1Display.WriteLog = "" + +# setup the color legend parameters for each legend in this view + +# get color legend/bar for particle_electrons_uxLUT in view renderView1 +particle_electrons_uxLUTColorBar = GetScalarBar(particle_electrons_uxLUT, renderView1) +particle_electrons_uxLUTColorBar.WindowLocation = "Any Location" +particle_electrons_uxLUTColorBar.Position = [0.7817772778402697, 0.5853658536585366] +particle_electrons_uxLUTColorBar.Title = "particle_electrons_ux" +particle_electrons_uxLUTColorBar.ComponentTitle = "" +particle_electrons_uxLUTColorBar.ScalarBarLength = 0.32999999999999985 + +# set color bar visibility +particle_electrons_uxLUTColorBar.Visibility = 1 + +# show color legend +clip1Display.SetScalarBarVisibility(renderView1, True) + +# ---------------------------------------------------------------- +# setup color maps and opacity maps used in the visualization +# note: the Get..() functions create a new object, if needed +# ---------------------------------------------------------------- + +# ---------------------------------------------------------------- +# setup animation scene, tracks and keyframes +# note: the Get..() functions create a new object, if needed +# ---------------------------------------------------------------- + +# get time animation track +timeAnimationCue1 = GetTimeTrack() + +# initialize the animation scene + +# get the time-keeper +timeKeeper1 = GetTimeKeeper() + +# initialize the timekeeper + +# initialize the animation track + +# get animation scene +animationScene1 = GetAnimationScene() + +# initialize the animation scene +animationScene1.ViewModules = renderView1 +animationScene1.Cues = timeAnimationCue1 +animationScene1.AnimationTime = 1.3329221244118056e-13 +animationScene1.EndTime = 1.3329221244118056e-13 +animationScene1.PlayMode = "Snap To TimeSteps" + +# ---------------------------------------------------------------- +# setup extractors +# ---------------------------------------------------------------- + +# create extractor +pNG1 = CreateExtractor("PNG", renderView1, registrationName="PNG1") +# trace defaults for the extractor. +pNG1.Trigger = "Time Step" + +# init the 'PNG' selected for 'Writer' +pNG1.Writer.FileName = "RenderView1_{timestep:06d}{camera}.png" +pNG1.Writer.ImageResolution = [889, 820] +pNG1.Writer.Format = "PNG" + +# ---------------------------------------------------------------- +# restore active source +# ---------------------------------------------------------------- +SetActiveSource(pNG1) + +# ------------------------------------------------------------------------------ +# Catalyst options +# ------------------------------------------------------------------------------ +from paraview import catalyst + +options = catalyst.Options() +options.GlobalTrigger = "Time Step" +options.CatalystLiveTrigger = "Time Step" + +if __name__ == "__main__": + from paraview.simple import SaveExtractsUsingCatalystOptions + + # Code for non in-situ environments; if executing in post-processing + # i.e. non-Catalyst mode, let's generate extracts using Catalyst options + SaveExtractsUsingCatalystOptions(options) diff --git a/Examples/Tests/ionization/inputs_2d_bf_rt b/Examples/Tests/field_ionization/inputs_test_2d_ionization_boost similarity index 100% rename from Examples/Tests/ionization/inputs_2d_bf_rt rename to Examples/Tests/field_ionization/inputs_test_2d_ionization_boost diff --git a/Examples/Tests/ionization/inputs_2d_rt b/Examples/Tests/field_ionization/inputs_test_2d_ionization_lab similarity index 100% rename from Examples/Tests/ionization/inputs_2d_rt rename to Examples/Tests/field_ionization/inputs_test_2d_ionization_lab diff --git a/Examples/Tests/field_ionization/inputs_test_2d_ionization_picmi.py b/Examples/Tests/field_ionization/inputs_test_2d_ionization_picmi.py new file mode 100644 index 00000000000..6d1d485cc8c --- /dev/null +++ b/Examples/Tests/field_ionization/inputs_test_2d_ionization_picmi.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# Physical constants +c = picmi.constants.c + +# Number of time steps +max_steps = 1600 + +# Number of cells +nx = 16 +nz = 800 + +# Physical domain +xmin = -5e-06 +xmax = 5e-06 +zmin = 0e-06 +zmax = 20e-06 + +# Domain decomposition +max_grid_size = 64 +blocking_factor = 16 + +# Create grid +grid = picmi.Cartesian2DGrid( + number_of_cells=[nx, nz], + lower_bound=[xmin, zmin], + upper_bound=[xmax, zmax], + lower_boundary_conditions=["periodic", "open"], + upper_boundary_conditions=["periodic", "open"], + warpx_max_grid_size=max_grid_size, + warpx_blocking_factor=blocking_factor, +) + +# Particles: electrons and ions +ions_density = 1 +ions_xmin = None +ions_ymin = None +ions_zmin = 5e-06 +ions_xmax = None +ions_ymax = None +ions_zmax = 15e-06 +uniform_distribution = picmi.UniformDistribution( + density=ions_density, + lower_bound=[ions_xmin, ions_ymin, ions_zmin], + upper_bound=[ions_xmax, ions_ymax, ions_zmax], + fill_in=True, +) +electrons = picmi.Species( + particle_type="electron", + name="electrons", + warpx_add_real_attributes={"orig_z": "z"}, +) +ions = picmi.Species( + particle_type="N", + name="ions", + charge_state=2, + initial_distribution=uniform_distribution, + warpx_add_real_attributes={"orig_z": "z"}, +) + +# Field ionization +nitrogen_ionization = picmi.FieldIonization( + model="ADK", # Ammosov-Delone-Krainov model + ionized_species=ions, + product_species=electrons, +) + +# Laser +position_z = 3e-06 +profile_t_peak = 60.0e-15 +laser = picmi.GaussianLaser( + wavelength=0.8e-06, + waist=1e10, + duration=26.685e-15, + focal_position=[0, 0, position_z], + centroid_position=[0, 0, position_z - c * profile_t_peak], + propagation_direction=[0, 0, 1], + polarization_direction=[1, 0, 0], + a0=1.8, + fill_in=False, +) +laser_antenna = picmi.LaserAntenna( + position=[0.0, 0.0, position_z], normal_vector=[0, 0, 1] +) + +# Electromagnetic solver +solver = picmi.ElectromagneticSolver(grid=grid, method="CKC", cfl=0.999) + +# Diagnostics +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=10000, + species=[electrons, ions], + data_list=["ux", "uy", "uz", "x", "z", "weighting", "orig_z"], +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=10000, + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez", "Jx", "Jy", "Jz"], +) + +# Set up simulation +sim = picmi.Simulation( + solver=solver, max_steps=max_steps, particle_shape="linear", warpx_use_filter=0 +) + +# Add electrons and ions +sim.add_species( + electrons, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[0, 0, 0]) +) +sim.add_species( + ions, layout=picmi.GriddedLayout(grid=grid, n_macroparticle_per_cell=[2, 1, 1]) +) + +# Add field ionization +sim.add_interaction(nitrogen_ionization) + +# Add laser +sim.add_laser(laser, injection_method=laser_antenna) + +# Add diagnostics +sim.add_diagnostic(particle_diag) +sim.add_diagnostic(field_diag) + +# Write input file that can be used to run with the compiled version +sim.write_input_file(file_name="inputs_2d_picmi") + +# Initialize inputs and WarpX instance +sim.initialize_inputs() +sim.initialize_warpx() + +# Advance simulation until last time step +sim.step(max_steps) diff --git a/Examples/Tests/field_probe/CMakeLists.txt b/Examples/Tests/field_probe/CMakeLists.txt new file mode 100644 index 00000000000..bbddbd7839e --- /dev/null +++ b/Examples/Tests/field_probe/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_2d_field_probe # name + 2 # dims + 2 # nprocs + inputs_test_2d_field_probe # inputs + analysis.py # analysis + diags/diag1000544 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/field_probe/analysis_field_probe.py b/Examples/Tests/field_probe/analysis.py similarity index 79% rename from Examples/Tests/field_probe/analysis_field_probe.py rename to Examples/Tests/field_probe/analysis.py index e167942d77c..57085fb7cdc 100755 --- a/Examples/Tests/field_probe/analysis_field_probe.py +++ b/Examples/Tests/field_probe/analysis.py @@ -17,27 +17,31 @@ test will check if the detected EM flux matches expected values, which can be solved analytically. """ + import numpy as np import pandas as pd filename = "diags/reducedfiles/FP_line.txt" # Open data file -df = pd.read_csv(filename, sep=' ') -df = df.sort_values(by=['[2]part_x_lev0-(m)']) +df = pd.read_csv(filename, sep=" ") +df = df.sort_values(by=["[2]part_x_lev0-(m)"]) # Select position and Intensity of timestep 500 -x = df.query('`[0]step()` == 500')['[2]part_x_lev0-(m)'] -S = df.query('`[0]step()` == 500')['[11]part_S_lev0-(W*s/m^2)'] +x = df.query("`[0]step()` == 500")["[2]part_x_lev0-(m)"] +S = df.query("`[0]step()` == 500")["[11]part_S_lev0-(W*s/m^2)"] xvals = x.to_numpy() svals = S.to_numpy() # Default intensity is highest measured value for plane # wave interacting with single slit I_0 = np.max(S) -def I_envelope (x, lam = 0.2e-6, a = 0.3e-6, D = 1.7e-6): + + +def I_envelope(x, lam=0.2e-6, a=0.3e-6, D=1.7e-6): arg = np.pi * a / lam * np.sin(np.arctan(x / D)) - return np.sinc( arg / np.pi )**2 + return np.sinc(arg / np.pi) ** 2 + # Count non-outlier values away from simulation boundaries counter = np.arange(60, 140, 2) @@ -47,11 +51,11 @@ def I_envelope (x, lam = 0.2e-6, a = 0.3e-6, D = 1.7e-6): for a in counter: b = I_0 * I_envelope(xvals[a]) c = svals[a] - error += abs((c-b)/b) * 100.0 + error += abs((c - b) / b) * 100.0 averror = error / (len(counter) - 1) # average error range set at 2.5% if averror > 2.5: - print('Average error greater than 2.5%') + print("Average error greater than 2.5%") assert averror < 2.5 diff --git a/Examples/Tests/field_probe/inputs_2d b/Examples/Tests/field_probe/inputs_test_2d_field_probe similarity index 100% rename from Examples/Tests/field_probe/inputs_2d rename to Examples/Tests/field_probe/inputs_test_2d_field_probe diff --git a/Examples/Tests/flux_injection/CMakeLists.txt b/Examples/Tests/flux_injection/CMakeLists.txt new file mode 100644 index 00000000000..d09b83d7618 --- /dev/null +++ b/Examples/Tests/flux_injection/CMakeLists.txt @@ -0,0 +1,22 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_flux_injection # name + 3 # dims + 2 # nprocs + inputs_test_3d_flux_injection # inputs + analysis_flux_injection_3d.py # analysis + diags/diag1000002 # output + OFF # dependency +) + +add_warpx_test( + test_rz_flux_injection # name + RZ # dims + 2 # nprocs + inputs_test_rz_flux_injection # inputs + analysis_flux_injection_rz.py # analysis + diags/diag1000120 # output + OFF # dependency +) diff --git a/Examples/Tests/flux_injection/analysis_flux_injection_3d.py b/Examples/Tests/flux_injection/analysis_flux_injection_3d.py index d0271f6aa94..3840bb72e74 100755 --- a/Examples/Tests/flux_injection/analysis_flux_injection_3d.py +++ b/Examples/Tests/flux_injection/analysis_flux_injection_3d.py @@ -20,6 +20,7 @@ velocity distribution (Gaussian or Gaussian-flux depending on the direction of space) """ + import os import re import sys @@ -30,21 +31,21 @@ from scipy.constants import c, m_e, m_p from scipy.special import erf -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI yt.funcs.mylog.setLevel(0) # Open plotfile specified in command line fn = sys.argv[1] -ds = yt.load( fn ) +ds = yt.load(fn) ad = ds.all_data() t_max = ds.current_time.item() # time of simulation # Total number of electrons expected: # Simulation parameters determine the total number of particles emitted (Ntot) -flux = 1. # in m^-2.s^-1, from the input script -emission_surface = 8*8 # in m^2 +flux = 1.0 # in m^-2.s^-1, from the input script +emission_surface = 8 * 8 # in m^2 Ntot = flux * emission_surface * t_max # Parameters of the histogram @@ -53,92 +54,103 @@ # Define function that histogram and check the data + def gaussian_dist(u, u_th): - return 1./((2*np.pi)**.5*u_th) * np.exp(-u**2/(2*u_th**2) ) + return 1.0 / ((2 * np.pi) ** 0.5 * u_th) * np.exp(-(u**2) / (2 * u_th**2)) + def gaussian_flux_dist(u, u_th, u_m): - normalization_factor = u_th**2 * np.exp(-u_m**2/(2*u_th**2)) + (np.pi/2)**.5*u_m*u_th * (1 + erf(u_m/(2**.5*u_th))) - result = 1./normalization_factor * np.where( u>0, u * np.exp(-(u-u_m)**2/(2*u_th**2)), 0 ) + normalization_factor = u_th**2 * np.exp(-(u_m**2) / (2 * u_th**2)) + ( + np.pi / 2 + ) ** 0.5 * u_m * u_th * (1 + erf(u_m / (2**0.5 * u_th))) + result = ( + 1.0 + / normalization_factor + * np.where(u > 0, u * np.exp(-((u - u_m) ** 2) / (2 * u_th**2)), 0) + ) return result -def compare_gaussian(u, w, u_th, label=''): - du = (hist_range[1]-hist_range[0])/hist_bins - w_hist, u_hist = np.histogram(u, bins=hist_bins, weights=w/du, range=hist_range) - u_hist = 0.5*(u_hist[1:]+u_hist[:-1]) - w_th = Ntot*gaussian_dist(u_hist, u_th) - plt.plot( u_hist, w_hist, label=label+': simulation' ) - plt.plot( u_hist, w_th, '--', label=label+': theory' ) - assert np.allclose( w_hist, w_th, atol=0.07*w_th.max() ) - -def compare_gaussian_flux(u, w, u_th, u_m, label=''): - du = (hist_range[1]-hist_range[0])/hist_bins - w_hist, u_hist = np.histogram(u, bins=hist_bins, weights=w/du, range=hist_range) - u_hist = 0.5*(u_hist[1:]+u_hist[:-1]) - w_th = Ntot*gaussian_flux_dist(u_hist, u_th, u_m) - plt.plot( u_hist, w_hist, label=label+': simulation' ) - plt.plot( u_hist, w_th, '--', label=label+': theory' ) - assert np.allclose( w_hist, w_th, atol=0.05*w_th.max() ) + +def compare_gaussian(u, w, u_th, label=""): + du = (hist_range[1] - hist_range[0]) / hist_bins + w_hist, u_hist = np.histogram(u, bins=hist_bins, weights=w / du, range=hist_range) + u_hist = 0.5 * (u_hist[1:] + u_hist[:-1]) + w_th = Ntot * gaussian_dist(u_hist, u_th) + plt.plot(u_hist, w_hist, label=label + ": simulation") + plt.plot(u_hist, w_th, "--", label=label + ": theory") + assert np.allclose(w_hist, w_th, atol=0.07 * w_th.max()) + + +def compare_gaussian_flux(u, w, u_th, u_m, label=""): + du = (hist_range[1] - hist_range[0]) / hist_bins + w_hist, u_hist = np.histogram(u, bins=hist_bins, weights=w / du, range=hist_range) + u_hist = 0.5 * (u_hist[1:] + u_hist[:-1]) + w_th = Ntot * gaussian_flux_dist(u_hist, u_th, u_m) + plt.plot(u_hist, w_hist, label=label + ": simulation") + plt.plot(u_hist, w_th, "--", label=label + ": theory") + assert np.allclose(w_hist, w_th, atol=0.05 * w_th.max()) + # Load data and perform check -plt.figure(figsize=(8,7)) +plt.figure(figsize=(8, 7)) plt.subplot(221) -plt.title('Electrons u_m=0.07') +plt.title("Electrons u_m=0.07") -ux = ad['electron','particle_momentum_x'].to_ndarray()/(m_e*c) -uy = ad['electron','particle_momentum_y'].to_ndarray()/(m_e*c) -uz = ad['electron','particle_momentum_z'].to_ndarray()/(m_e*c) -w = ad['electron', 'particle_weight'].to_ndarray() +ux = ad["electron", "particle_momentum_x"].to_ndarray() / (m_e * c) +uy = ad["electron", "particle_momentum_y"].to_ndarray() / (m_e * c) +uz = ad["electron", "particle_momentum_z"].to_ndarray() / (m_e * c) +w = ad["electron", "particle_weight"].to_ndarray() -compare_gaussian(ux, w, u_th=0.1, label='u_x') -compare_gaussian_flux(uy, w, u_th=0.1, u_m=0.07, label='u_y') -compare_gaussian(uz, w, u_th=0.1, label='u_z') +compare_gaussian(ux, w, u_th=0.1, label="u_x") +compare_gaussian_flux(uy, w, u_th=0.1, u_m=0.07, label="u_y") +compare_gaussian(uz, w, u_th=0.1, label="u_z") plt.subplot(223) -plt.title('Protons u_m=0.05') +plt.title("Protons u_m=0.05") -ux = ad['proton','particle_momentum_x'].to_ndarray()/(m_p*c) -uy = ad['proton','particle_momentum_y'].to_ndarray()/(m_p*c) -uz = ad['proton','particle_momentum_z'].to_ndarray()/(m_p*c) -w = ad['proton', 'particle_weight'].to_ndarray() +ux = ad["proton", "particle_momentum_x"].to_ndarray() / (m_p * c) +uy = ad["proton", "particle_momentum_y"].to_ndarray() / (m_p * c) +uz = ad["proton", "particle_momentum_z"].to_ndarray() / (m_p * c) +w = ad["proton", "particle_weight"].to_ndarray() -compare_gaussian_flux(-ux, w, u_th=0.1, u_m=0.05, label='u_x') -compare_gaussian(uy, w, u_th=0.1, label='u_y') -compare_gaussian(uz, w, u_th=0.1, label='u_z') +compare_gaussian_flux(-ux, w, u_th=0.1, u_m=0.05, label="u_x") +compare_gaussian(uy, w, u_th=0.1, label="u_y") +compare_gaussian(uz, w, u_th=0.1, label="u_z") plt.subplot(222) -plt.title('Electrons u_m=-0.07') +plt.title("Electrons u_m=-0.07") -ux = ad['electron_negative','particle_momentum_x'].to_ndarray()/(m_e*c) -uy = ad['electron_negative','particle_momentum_y'].to_ndarray()/(m_e*c) -uz = ad['electron_negative','particle_momentum_z'].to_ndarray()/(m_e*c) -w = ad['electron_negative', 'particle_weight'].to_ndarray() +ux = ad["electron_negative", "particle_momentum_x"].to_ndarray() / (m_e * c) +uy = ad["electron_negative", "particle_momentum_y"].to_ndarray() / (m_e * c) +uz = ad["electron_negative", "particle_momentum_z"].to_ndarray() / (m_e * c) +w = ad["electron_negative", "particle_weight"].to_ndarray() -compare_gaussian(ux, w, u_th=0.1, label='u_x') -compare_gaussian(uy, w, u_th=0.1, label='u_y') -compare_gaussian_flux(uz, w, u_th=0.1, u_m=-0.07, label='u_z') +compare_gaussian(ux, w, u_th=0.1, label="u_x") +compare_gaussian(uy, w, u_th=0.1, label="u_y") +compare_gaussian_flux(uz, w, u_th=0.1, u_m=-0.07, label="u_z") plt.legend(loc=(1.02, 0.5)) plt.subplot(224) -plt.title('Protons u_m=-0.05') +plt.title("Protons u_m=-0.05") -ux = ad['proton_negative','particle_momentum_x'].to_ndarray()/(m_p*c) -uy = ad['proton_negative','particle_momentum_y'].to_ndarray()/(m_p*c) -uz = ad['proton_negative','particle_momentum_z'].to_ndarray()/(m_p*c) -w = ad['proton_negative', 'particle_weight'].to_ndarray() +ux = ad["proton_negative", "particle_momentum_x"].to_ndarray() / (m_p * c) +uy = ad["proton_negative", "particle_momentum_y"].to_ndarray() / (m_p * c) +uz = ad["proton_negative", "particle_momentum_z"].to_ndarray() / (m_p * c) +w = ad["proton_negative", "particle_weight"].to_ndarray() -compare_gaussian(ux, w, u_th=0.1, label='u_x') -compare_gaussian(uy, w, u_th=0.1, label='u_y') -compare_gaussian_flux(-uz, w, u_th=0.1, u_m=-0.05, label='u_z') -#plt.legend(loc=0) +compare_gaussian(ux, w, u_th=0.1, label="u_x") +compare_gaussian(uy, w, u_th=0.1, label="u_y") +compare_gaussian_flux(-uz, w, u_th=0.1, u_m=-0.05, label="u_z") +# plt.legend(loc=0) plt.tight_layout() -plt.savefig('Distribution.png') +plt.savefig("Distribution.png") # Verify checksum test_name = os.path.split(os.getcwd())[1] -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, rtol=1.0e-3) else: checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/flux_injection/analysis_flux_injection_rz.py b/Examples/Tests/flux_injection/analysis_flux_injection_rz.py index 8ec944c715d..ad73fdb47af 100755 --- a/Examples/Tests/flux_injection/analysis_flux_injection_rz.py +++ b/Examples/Tests/flux_injection/analysis_flux_injection_rz.py @@ -24,6 +24,7 @@ velocity was along the azimuthal direction.) - The total number of electrons corresponds to the expected flux. """ + import os import re import sys @@ -31,35 +32,35 @@ import numpy as np import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI yt.funcs.mylog.setLevel(0) # Open plotfile specified in command line fn = sys.argv[1] -ds = yt.load( fn ) +ds = yt.load(fn) t_max = ds.current_time.item() # time of simulation # Total number of electrons expected: -flux = 1. # in m^-2.s^-1, from the input script -emission_surface = 0.8 # in m^2, +flux = 1.0 # in m^-2.s^-1, from the input script +emission_surface = 0.8 # in m^2, # given that xmin = 1.5, xmax = 1.9, zmin = -1.0, zmax = 1. n_tot = flux * emission_surface * t_max # Read particle data ad = ds.all_data() -r = ad['particle_position_x'].to_ndarray() # Corresponds to the radial coordinate in RZ -w = ad['particle_weight'].to_ndarray() +r = ad["particle_position_x"].to_ndarray() # Corresponds to the radial coordinate in RZ +w = ad["particle_weight"].to_ndarray() # Check that the number of particles matches the expected one -assert np.allclose( w.sum(), n_tot, rtol=0.05 ) +assert np.allclose(w.sum(), n_tot, rtol=0.05) # Check that the particles are at the right radius -assert np.all( (r >= 1.48) & (r <=1.92) ) +assert np.all((r >= 1.48) & (r <= 1.92)) test_name = os.path.split(os.getcwd())[1] -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, rtol=1.0e-3) else: checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/flux_injection/inputs_3d b/Examples/Tests/flux_injection/inputs_test_3d_flux_injection similarity index 100% rename from Examples/Tests/flux_injection/inputs_3d rename to Examples/Tests/flux_injection/inputs_test_3d_flux_injection diff --git a/Examples/Tests/flux_injection/inputs_rz b/Examples/Tests/flux_injection/inputs_test_rz_flux_injection similarity index 100% rename from Examples/Tests/flux_injection/inputs_rz rename to Examples/Tests/flux_injection/inputs_test_rz_flux_injection diff --git a/Examples/Tests/gaussian_beam/CMakeLists.txt b/Examples/Tests/gaussian_beam/CMakeLists.txt new file mode 100644 index 00000000000..ae0cf57ed15 --- /dev/null +++ b/Examples/Tests/gaussian_beam/CMakeLists.txt @@ -0,0 +1,22 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_focusing_gaussian_beam # name + 3 # dims + 2 # nprocs + inputs_test_3d_focusing_gaussian_beam # inputs + analysis.py # analysis + diags/diag1000000 # output + OFF # dependency +) + +add_warpx_test( + test_3d_gaussian_beam_picmi # name + 3 # dims + 2 # nprocs + inputs_test_3d_gaussian_beam_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) diff --git a/Examples/Tests/gaussian_beam/PICMI_inputs_gaussian_beam.py b/Examples/Tests/gaussian_beam/PICMI_inputs_gaussian_beam.py deleted file mode 100755 index b9d06034394..00000000000 --- a/Examples/Tests/gaussian_beam/PICMI_inputs_gaussian_beam.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python3 - -#from warp import picmi -import argparse - -from pywarpx import picmi - -parser = argparse.ArgumentParser(description="Gaussian beam PICMI example") - -parser.add_argument('--diagformat', type=str, - help='Format of the full diagnostics (plotfile, openpmd, ascent, sensei, ...)', - default='plotfile') -parser.add_argument('--fields_to_plot', type=str, - help='List of fields to write to diagnostics', - default=['E', 'B', 'J', 'part_per_cell'], - nargs = '*') - -args = parser.parse_args() - -constants = picmi.constants - -nx = 32 -ny = 32 -nz = 32 - -xmin = -2. -xmax = +2. -ymin = -2. -ymax = +2. -zmin = -2. -zmax = +2. - -number_sim_particles = 32768 -total_charge = 8.010883097437485e-07 - -beam_rms_size = 0.25 -electron_beam_divergence = -0.04*constants.c - -em_order = 3 - -grid = picmi.Cartesian3DGrid(number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = ['periodic', 'periodic', 'open'], - upper_boundary_conditions = ['periodic', 'periodic', 'open'], - lower_boundary_conditions_particles = ['periodic', 'periodic', 'absorbing'], - upper_boundary_conditions_particles = ['periodic', 'periodic', 'absorbing'], - warpx_max_grid_size=16) - -solver = picmi.ElectromagneticSolver(grid = grid, - cfl = 1., - stencil_order=[em_order,em_order,em_order]) - -electron_beam = picmi.GaussianBunchDistribution(n_physical_particles = total_charge/constants.q_e, - rms_bunch_size = [beam_rms_size, beam_rms_size, beam_rms_size], - velocity_divergence = [electron_beam_divergence, electron_beam_divergence, electron_beam_divergence]) - -proton_beam = picmi.GaussianBunchDistribution(n_physical_particles = total_charge/constants.q_e, - rms_bunch_size = [beam_rms_size, beam_rms_size, beam_rms_size]) - -electrons = picmi.Species(particle_type='electron', name='electrons', initial_distribution=electron_beam) -protons = picmi.Species(particle_type='proton', name='protons', initial_distribution=proton_beam) - -field_diag1 = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = 10, - data_list = args.fields_to_plot, - warpx_format = args.diagformat, - write_dir = '.', - warpx_file_prefix = 'Python_gaussian_beam_plt') - -part_diag1 = picmi.ParticleDiagnostic(name = 'diag1', - period = 10, - species = [electrons, protons], - data_list = ['weighting', 'momentum'], - warpx_format = args.diagformat) - -sim = picmi.Simulation(solver = solver, - max_steps = 10, - verbose = 1, - warpx_current_deposition_algo = 'direct', - warpx_use_filter = 0) - -sim.add_species(electrons, layout=picmi.PseudoRandomLayout(n_macroparticles=number_sim_particles)) -sim.add_species(protons, layout=picmi.PseudoRandomLayout(n_macroparticles=number_sim_particles)) - -sim.add_diagnostic(field_diag1) -sim.add_diagnostic(part_diag1) - -# write_inputs will create an inputs file that can be used to run -# with the compiled version. -#sim.write_input_file(file_name = 'inputs_from_PICMI') - -# Alternatively, sim.step will run WarpX, controlling it from Python -sim.step() diff --git a/Examples/Tests/gaussian_beam/README.rst b/Examples/Tests/gaussian_beam/README.rst index bfca2bb2398..e3baf9842c2 100644 --- a/Examples/Tests/gaussian_beam/README.rst +++ b/Examples/Tests/gaussian_beam/README.rst @@ -11,7 +11,7 @@ Run This example can be run **either** as: -* **Python** script: ``python3 PICMI_inputs_gaussian_beam.py`` or +* **Python** script: ``python3 inputs_test_3d_gaussian_beam_picmi.py`` or * WarpX **executable** using an input file: (*TODO*) For `MPI-parallel `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. @@ -20,15 +20,15 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. tab-item:: Python: Script - .. literalinclude:: PICMI_inputs_gaussian_beam.py + .. literalinclude:: inputs_test_3d_gaussian_beam_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/gaussian_beam/PICMI_inputs_gaussian_beam.py``. + :caption: You can copy this file from ``Examples/Tests/gaussian_beam/inputs_test_3d_gaussian_beam_picmi.py``. .. tab-item:: Executable: Input File .. note:: - TODO: This input file should be created following the ``PICMI_inputs_gaussian_beam.py`` file. + TODO: This input file should be created following the ``inputs_test_3d_gaussian_beam_picmi.py`` file. Analyze diff --git a/Examples/Tests/gaussian_beam/analysis.py b/Examples/Tests/gaussian_beam/analysis.py new file mode 100755 index 00000000000..c2318d0cb7d --- /dev/null +++ b/Examples/Tests/gaussian_beam/analysis.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +# Copyright 2024 Arianna Formenti +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +import os +import sys + +import numpy as np +from scipy.constants import c, eV, m_e, micro, nano + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") + +import checksumAPI +from openpmd_viewer import OpenPMDTimeSeries + +GeV = 1e9 * eV +energy = 125.0 * GeV +gamma = energy / (m_e * c**2) +sigmax = 516.0 * nano +sigmay = 7.7 * nano +sigmaz = 300.0 * micro +nz = 256 +Lz = 20 * sigmaz +gridz = np.linspace(-0.5 * Lz, 0.5 * Lz, nz) +tol = gridz[1] - gridz[0] +emitx = 50 * micro +emity = 20 * nano +focal_distance = 4 * sigmaz + + +def s(z, sigma0, emit): + """The theoretical size of a focusing beam (in the absence of space charge), + at position z, given its emittance and size at focus.""" + return np.sqrt(sigma0**2 + emit**2 * (z - focal_distance) ** 2 / sigma0**2) + + +filename = sys.argv[1] + +ts = OpenPMDTimeSeries("./diags/openpmd/") + +( + x, + y, + z, + w, +) = ts.get_particle(["x", "y", "z", "w"], species="beam1", iteration=0, plot=False) + +imin = np.argmin(np.sqrt((gridz + 0.8 * focal_distance) ** 2)) +imax = np.argmin(np.sqrt((gridz - 0.8 * focal_distance) ** 2)) + +sx, sy = [], [] +# Compute the size of the beam in each z slice +subgrid = gridz[imin:imax] +for d in subgrid: + i = np.sqrt((z - d) ** 2) < tol + if np.sum(i) != 0: + mux = np.average(x[i], weights=w[i]) + muy = np.average(y[i], weights=w[i]) + sx.append(np.sqrt(np.average((x[i] - mux) ** 2, weights=w[i]))) + sy.append(np.sqrt(np.average((y[i] - muy) ** 2, weights=w[i]))) + +# Theoretical prediction for the size of the beam in each z slice +sx_theory = s(subgrid, sigmax, emitx / gamma) +sy_theory = s(subgrid, sigmay, emity / gamma) + +assert np.allclose(sx, sx_theory, rtol=0.051, atol=0) +assert np.allclose(sy, sy_theory, rtol=0.038, atol=0) + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/gaussian_beam/analysis_default_regression.py b/Examples/Tests/gaussian_beam/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/gaussian_beam/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/gaussian_beam/analysis_focusing_beam.py b/Examples/Tests/gaussian_beam/analysis_focusing_beam.py deleted file mode 100755 index 4a5fa3b927b..00000000000 --- a/Examples/Tests/gaussian_beam/analysis_focusing_beam.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2024 Arianna Formenti -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - - -import os -import sys - -import numpy as np -from scipy.constants import c, eV, m_e, micro, nano - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') - -import checksumAPI -from openpmd_viewer import OpenPMDTimeSeries - -GeV=1e9*eV -energy = 125.*GeV -gamma = energy/(m_e*c**2) -sigmax = 516.0*nano -sigmay = 7.7*nano -sigmaz = 300.*micro -nz = 256 -Lz = 20*sigmaz -gridz = np.linspace(-0.5*Lz, 0.5*Lz, nz) -tol = gridz[1] - gridz[0] -emitx = 50*micro -emity = 20*nano -focal_distance = 4*sigmaz - -def s(z, sigma0, emit): - '''The theoretical size of a focusing beam (in the absence of space charge), - at position z, given its emittance and size at focus.''' - return np.sqrt(sigma0**2 + emit**2 * (z - focal_distance)**2 / sigma0**2) - -filename = sys.argv[1] - -ts = OpenPMDTimeSeries('./diags/openpmd/') - -x, y, z, w, = ts.get_particle( ['x', 'y', 'z', 'w'], species='beam1', iteration=0, plot=False) - -imin = np.argmin(np.sqrt((gridz+0.8*focal_distance)**2)) -imax = np.argmin(np.sqrt((gridz-0.8*focal_distance)**2)) - -sx, sy = [], [] -# Compute the size of the beam in each z slice -subgrid = gridz[imin:imax] -for d in subgrid: - i = np.sqrt((z - d)**2) < tol - if (np.sum(i)!=0): - mux = np.average(x[i], weights=w[i]) - muy = np.average(y[i], weights=w[i]) - sx.append(np.sqrt(np.average((x[i]-mux)**2, weights=w[i]))) - sy.append(np.sqrt(np.average((y[i]-muy)**2, weights=w[i]))) - -# Theoretical prediction for the size of the beam in each z slice -sx_theory = s(subgrid, sigmax, emitx/gamma) -sy_theory = s(subgrid, sigmay, emity/gamma) - -assert(np.allclose(sx, sx_theory, rtol=0.051, atol=0)) -assert(np.allclose(sy, sy_theory, rtol=0.038, atol=0)) - -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/gaussian_beam/inputs_focusing_beam b/Examples/Tests/gaussian_beam/inputs_test_3d_focusing_gaussian_beam similarity index 100% rename from Examples/Tests/gaussian_beam/inputs_focusing_beam rename to Examples/Tests/gaussian_beam/inputs_test_3d_focusing_gaussian_beam diff --git a/Examples/Tests/gaussian_beam/inputs_test_3d_gaussian_beam_picmi.py b/Examples/Tests/gaussian_beam/inputs_test_3d_gaussian_beam_picmi.py new file mode 100755 index 00000000000..cd169110f8a --- /dev/null +++ b/Examples/Tests/gaussian_beam/inputs_test_3d_gaussian_beam_picmi.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 + +# from warp import picmi +import argparse + +from pywarpx import picmi + +parser = argparse.ArgumentParser(description="Gaussian beam PICMI example") + +parser.add_argument( + "--diagformat", + type=str, + help="Format of the full diagnostics (plotfile, openpmd, ascent, sensei, ...)", + default="plotfile", +) +parser.add_argument( + "--fields_to_plot", + type=str, + help="List of fields to write to diagnostics", + default=["E", "B", "J", "part_per_cell"], + nargs="*", +) + +args = parser.parse_args() + +constants = picmi.constants + +nx = 32 +ny = 32 +nz = 32 + +xmin = -2.0 +xmax = +2.0 +ymin = -2.0 +ymax = +2.0 +zmin = -2.0 +zmax = +2.0 + +number_sim_particles = 32768 +total_charge = 8.010883097437485e-07 + +beam_rms_size = 0.25 +electron_beam_divergence = -0.04 * constants.c + +em_order = 3 + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["periodic", "periodic", "open"], + upper_boundary_conditions=["periodic", "periodic", "open"], + lower_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + upper_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + warpx_max_grid_size=16, +) + +solver = picmi.ElectromagneticSolver( + grid=grid, cfl=1.0, stencil_order=[em_order, em_order, em_order] +) + +electron_beam = picmi.GaussianBunchDistribution( + n_physical_particles=total_charge / constants.q_e, + rms_bunch_size=[beam_rms_size, beam_rms_size, beam_rms_size], + velocity_divergence=[ + electron_beam_divergence, + electron_beam_divergence, + electron_beam_divergence, + ], +) + +proton_beam = picmi.GaussianBunchDistribution( + n_physical_particles=total_charge / constants.q_e, + rms_bunch_size=[beam_rms_size, beam_rms_size, beam_rms_size], +) + +electrons = picmi.Species( + particle_type="electron", name="electrons", initial_distribution=electron_beam +) +protons = picmi.Species( + particle_type="proton", name="protons", initial_distribution=proton_beam +) + +field_diag1 = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=10, + data_list=args.fields_to_plot, + warpx_format=args.diagformat, +) + +part_diag1 = picmi.ParticleDiagnostic( + name="diag1", + period=10, + species=[electrons, protons], + data_list=["weighting", "momentum"], + warpx_format=args.diagformat, +) + +sim = picmi.Simulation( + solver=solver, + max_steps=10, + verbose=1, + warpx_current_deposition_algo="direct", + warpx_use_filter=0, +) + +sim.add_species( + electrons, layout=picmi.PseudoRandomLayout(n_macroparticles=number_sim_particles) +) +sim.add_species( + protons, layout=picmi.PseudoRandomLayout(n_macroparticles=number_sim_particles) +) + +sim.add_diagnostic(field_diag1) +sim.add_diagnostic(part_diag1) + +# write_inputs will create an inputs file that can be used to run +# with the compiled version. +# sim.write_input_file(file_name = 'inputs_from_PICMI') + +# Alternatively, sim.step will run WarpX, controlling it from Python +sim.step() diff --git a/Examples/Tests/implicit/CMakeLists.txt b/Examples/Tests/implicit/CMakeLists.txt new file mode 100644 index 00000000000..dabd4de66b8 --- /dev/null +++ b/Examples/Tests/implicit/CMakeLists.txt @@ -0,0 +1,42 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_semi_implicit_picard # name + 1 # dims + 2 # nprocs + inputs_test_1d_semi_implicit_picard # inputs + analysis_1d.py # analysis + diags/diag1000100 # output + OFF # dependency +) + +add_warpx_test( + test_1d_theta_implicit_picard # name + 1 # dims + 2 # nprocs + inputs_test_1d_theta_implicit_picard # inputs + analysis_1d.py # analysis + diags/diag1000100 # output + OFF # dependency +) + +add_warpx_test( + test_2d_theta_implicit_jfnk_vandb # name + 2 # dims + 2 # nprocs + inputs_test_2d_theta_implicit_jfnk_vandb # inputs + analysis_vandb_jfnk_2d.py # analysis + diags/diag1000020 # output + OFF # dependency +) + +add_warpx_test( + test_2d_theta_implicit_jfnk_vandb_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_theta_implicit_jfnk_vandb_picmi.py # inputs + analysis_vandb_jfnk_2d.py # analysis + diags/diag1000020 # output + OFF # dependency +) diff --git a/Examples/Tests/Implicit/analysis_1d.py b/Examples/Tests/implicit/analysis_1d.py similarity index 57% rename from Examples/Tests/Implicit/analysis_1d.py rename to Examples/Tests/implicit/analysis_1d.py index 0e20b925df5..bbbbb8db9b2 100755 --- a/Examples/Tests/Implicit/analysis_1d.py +++ b/Examples/Tests/implicit/analysis_1d.py @@ -15,30 +15,31 @@ import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file fn = sys.argv[1] -field_energy = np.loadtxt('diags/reducedfiles/field_energy.txt', skiprows=1) -particle_energy = np.loadtxt('diags/reducedfiles/particle_energy.txt', skiprows=1) +field_energy = np.loadtxt("diags/reducedfiles/field_energy.txt", skiprows=1) +particle_energy = np.loadtxt("diags/reducedfiles/particle_energy.txt", skiprows=1) -total_energy = field_energy[:,2] + particle_energy[:,2] +total_energy = field_energy[:, 2] + particle_energy[:, 2] -delta_E = (total_energy - total_energy[0])/total_energy[0] +delta_E = (total_energy - total_energy[0]) / total_energy[0] max_delta_E = np.abs(delta_E).max() -if re.match('SemiImplicitPicard_1d', fn): +test_name = os.path.split(os.getcwd())[1] +if re.match("test_1d_semi_implicit_picard", test_name): tolerance_rel = 2.5e-5 -elif re.match('ThetaImplicitPicard_1d', fn): +elif re.match("test_1d_theta_implicit_picard", test_name): # This case should have near machine precision conservation of energy - tolerance_rel = 1.e-14 + tolerance_rel = 1.0e-14 print(f"max change in energy: {max_delta_E}") print(f"tolerance: {tolerance_rel}") -assert( max_delta_E < tolerance_rel ) +assert max_delta_E < tolerance_rel test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/Implicit/analysis_vandb_jfnk_2d.py b/Examples/Tests/implicit/analysis_vandb_jfnk_2d.py similarity index 61% rename from Examples/Tests/Implicit/analysis_vandb_jfnk_2d.py rename to Examples/Tests/implicit/analysis_vandb_jfnk_2d.py index 85faab61fcc..3c962eb91ea 100755 --- a/Examples/Tests/Implicit/analysis_vandb_jfnk_2d.py +++ b/Examples/Tests/implicit/analysis_vandb_jfnk_2d.py @@ -17,52 +17,54 @@ import yt from scipy.constants import e, epsilon_0 -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file fn = sys.argv[1] -field_energy = np.loadtxt('diags/reducedfiles/field_energy.txt', skiprows=1) -particle_energy = np.loadtxt('diags/reducedfiles/particle_energy.txt', skiprows=1) +field_energy = np.loadtxt("diags/reducedfiles/field_energy.txt", skiprows=1) +particle_energy = np.loadtxt("diags/reducedfiles/particle_energy.txt", skiprows=1) -total_energy = field_energy[:,2] + particle_energy[:,2] +total_energy = field_energy[:, 2] + particle_energy[:, 2] -delta_E = (total_energy - total_energy[0])/total_energy[0] +delta_E = (total_energy - total_energy[0]) / total_energy[0] max_delta_E = np.abs(delta_E).max() # This case should have near machine precision conservation of energy -tolerance_rel_energy = 2.e-14 -tolerance_rel_charge = 2.e-15 +tolerance_rel_energy = 2.0e-14 +tolerance_rel_charge = 2.0e-15 print(f"max change in energy: {max_delta_E}") print(f"tolerance: {tolerance_rel_energy}") -assert( max_delta_E < tolerance_rel_energy ) +assert max_delta_E < tolerance_rel_energy # check for machine precision conservation of charge density -n0 = 1.e30 +n0 = 1.0e30 pltdir = sys.argv[1] ds = yt.load(pltdir) -data = ds.covering_grid(level = 0, left_edge = ds.domain_left_edge, dims = ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) -divE = data['boxlib', 'divE'].value -rho = data['boxlib', 'rho'].value +divE = data["boxlib", "divE"].value +rho = data["boxlib", "rho"].value # compute local error in Gauss's law -drho = (rho - epsilon_0*divE)/e/n0 +drho = (rho - epsilon_0 * divE) / e / n0 # compute RMS on in error on the grid nX = drho.shape[0] nZ = drho.shape[1] -drho2_avg = (drho**2).sum()/(nX*nZ) +drho2_avg = (drho**2).sum() / (nX * nZ) drho_rms = np.sqrt(drho2_avg) print(f"rms error in charge conservation: {drho_rms}") print(f"tolerance: {tolerance_rel_charge}") -assert( drho_rms < tolerance_rel_charge ) +assert drho_rms < tolerance_rel_charge test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/Implicit/inputs_1d_semiimplicit b/Examples/Tests/implicit/inputs_test_1d_semi_implicit_picard similarity index 97% rename from Examples/Tests/Implicit/inputs_1d_semiimplicit rename to Examples/Tests/implicit/inputs_test_1d_semi_implicit_picard index 07460e08be8..8ef0304bebb 100644 --- a/Examples/Tests/Implicit/inputs_1d_semiimplicit +++ b/Examples/Tests/implicit/inputs_test_1d_semi_implicit_picard @@ -17,6 +17,7 @@ my_constants.dt = 0.1/wpe # time step size, s max_step = 100 amr.n_cell = nz +amr.max_grid_size = 32 amr.max_level = 0 geometry.dims = 1 @@ -31,6 +32,7 @@ boundary.particle_hi = periodic ############ NUMERICS ########### ################################# +warpx.abort_on_warning_threshold = high warpx.verbose = 1 warpx.const_dt = dt algo.evolve_scheme = semi_implicit_em diff --git a/Examples/Tests/Implicit/inputs_1d b/Examples/Tests/implicit/inputs_test_1d_theta_implicit_picard similarity index 97% rename from Examples/Tests/Implicit/inputs_1d rename to Examples/Tests/implicit/inputs_test_1d_theta_implicit_picard index 3e57689b723..2ed4d746708 100644 --- a/Examples/Tests/Implicit/inputs_1d +++ b/Examples/Tests/implicit/inputs_test_1d_theta_implicit_picard @@ -17,6 +17,7 @@ my_constants.dt = 0.1/wpe # time step size, s max_step = 100 amr.n_cell = nz +amr.max_grid_size = 32 amr.max_level = 0 geometry.dims = 1 @@ -31,6 +32,7 @@ boundary.particle_hi = periodic ############ NUMERICS ########### ################################# +warpx.abort_on_warning_threshold = high warpx.verbose = 1 warpx.const_dt = dt algo.evolve_scheme = theta_implicit_em diff --git a/Examples/Tests/Implicit/inputs_vandb_jfnk_2d b/Examples/Tests/implicit/inputs_test_2d_theta_implicit_jfnk_vandb similarity index 98% rename from Examples/Tests/Implicit/inputs_vandb_jfnk_2d rename to Examples/Tests/implicit/inputs_test_2d_theta_implicit_jfnk_vandb index 393a9d90330..0cdf2ebe40d 100644 --- a/Examples/Tests/Implicit/inputs_vandb_jfnk_2d +++ b/Examples/Tests/implicit/inputs_test_2d_theta_implicit_jfnk_vandb @@ -31,6 +31,7 @@ boundary.field_hi = periodic periodic ################################# ############ NUMERICS ########### ################################# +warpx.abort_on_warning_threshold = high warpx.serialize_initial_conditions = 1 warpx.verbose = 1 warpx.const_dt = dt diff --git a/Examples/Tests/implicit/inputs_test_2d_theta_implicit_jfnk_vandb_picmi.py b/Examples/Tests/implicit/inputs_test_2d_theta_implicit_jfnk_vandb_picmi.py new file mode 100755 index 00000000000..8fa29127a7f --- /dev/null +++ b/Examples/Tests/implicit/inputs_test_2d_theta_implicit_jfnk_vandb_picmi.py @@ -0,0 +1,175 @@ +#!/usr/bin/env python3 +# +# --- Tests the python interface to the Implicit solver + +import numpy as np + +from pywarpx import picmi + +constants = picmi.constants + +########################## +# physics parameters +########################## + +n0 = 1.0e30 # m^-3 +Ti = 100.0 # eV +Te = 100.0 # eV +wpe = constants.q_e * np.sqrt(n0 / (constants.m_e * constants.ep0)) +de0 = constants.c / wpe +nppcz = 10 # number of particles/cell in z +dt = 0.1 / wpe # s + +vthe = np.sqrt(Te * constants.q_e / constants.m_e) +vthi = np.sqrt(Ti * constants.q_e / constants.m_p) + +########################## +# numerics parameters +########################## + +# --- Number of time steps +max_steps = 20 +diagnostic_intervals = "::20" + +# --- Grid +nx = 40 +ny = 40 + +xmin = 0.0 +ymin = 0.0 +xmax = 10.0 * de0 +ymax = 10.0 * de0 + +number_per_cell_each_dim = [nppcz, nppcz] + +########################## +# physics components +########################## + +electrons_uniform_plasma = picmi.UniformDistribution( + density=n0, rms_velocity=[vthe, vthe, vthe] +) + +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=electrons_uniform_plasma, +) + +protons_uniform_plasma = picmi.UniformDistribution( + density=n0, rms_velocity=[vthi, vthi, vthi] +) + +protons = picmi.Species( + particle_type="proton", name="protons", initial_distribution=protons_uniform_plasma +) + +########################## +# numerics components +########################## + +grid = picmi.Cartesian2DGrid( + number_of_cells=[nx, ny], + lower_bound=[xmin, ymin], + upper_bound=[xmax, ymax], + lower_boundary_conditions=["periodic", "periodic"], + upper_boundary_conditions=["periodic", "periodic"], + warpx_max_grid_size=8, + warpx_blocking_factor=8, +) + +solver = picmi.ElectromagneticSolver(grid=grid, method="Yee") + +GMRES_solver = picmi.GMRESLinearSolver( + verbose_int=2, + max_iterations=1000, + relative_tolerance=1.0e-8, + absolute_tolerance=0.0, +) + +newton_solver = picmi.NewtonNonlinearSolver( + verbose=True, + max_iterations=20, + relative_tolerance=1.0e-12, + absolute_tolerance=0.0, + require_convergence=False, + linear_solver=GMRES_solver, + max_particle_iterations=21, + particle_tolerance=1.0e-12, +) + +evolve_scheme = picmi.ThetaImplicitEMEvolveScheme( + theta=0.5, nonlinear_solver=newton_solver +) + +########################## +# diagnostics +########################## + +field_diag1 = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=diagnostic_intervals, + data_list=["Ex", "Ey", "Ez", "Bx", "By", "Bz", "Jx", "Jy", "Jz", "rho", "divE"], +) + +part_diag1 = picmi.ParticleDiagnostic( + name="diag1", + period=diagnostic_intervals, + species=[electrons, protons], + data_list=["weighting", "position", "momentum"], +) + +particle_energy_diag = picmi.ReducedDiagnostic( + diag_type="ParticleEnergy", name="particle_energy", period=1 +) + +field_energy_diag = picmi.ReducedDiagnostic( + diag_type="FieldEnergy", name="field_energy", period=1 +) + +########################## +# simulation setup +########################## + +sim = picmi.Simulation( + solver=solver, + particle_shape=2, + time_step_size=dt, + max_steps=max_steps, + verbose=1, + warpx_evolve_scheme=evolve_scheme, + warpx_current_deposition_algo="villasenor", + warpx_particle_pusher_algo="boris", + warpx_serialize_initial_conditions=1, + warpx_use_filter=0, +) + +sim.add_species( + electrons, + layout=picmi.GriddedLayout( + n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid + ), +) +sim.add_species( + protons, + layout=picmi.GriddedLayout( + n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid + ), +) + +sim.add_diagnostic(field_diag1) +sim.add_diagnostic(part_diag1) +sim.add_diagnostic(particle_energy_diag) +sim.add_diagnostic(field_energy_diag) + +########################## +# simulation run +########################## + +# write_inputs will create an inputs file that can be used to run +# with the compiled version. +sim.write_input_file(file_name="inputs2d_from_PICMI") + +# Alternatively, sim.step will run WarpX, controlling it from Python +sim.step() diff --git a/Examples/Tests/initial_distribution/CMakeLists.txt b/Examples/Tests/initial_distribution/CMakeLists.txt new file mode 100644 index 00000000000..04af9708cb2 --- /dev/null +++ b/Examples/Tests/initial_distribution/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_initial_distribution # name + 3 # dims + 1 # nprocs + inputs_test_3d_initial_distribution # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/initial_distribution/analysis_distribution.py b/Examples/Tests/initial_distribution/analysis.py similarity index 58% rename from Examples/Tests/initial_distribution/analysis_distribution.py rename to Examples/Tests/initial_distribution/analysis.py index 5a3774133db..6d23c5da1e4 100755 --- a/Examples/Tests/initial_distribution/analysis_distribution.py +++ b/Examples/Tests/initial_distribution/analysis.py @@ -26,18 +26,18 @@ import scipy.special as scs from read_raw_data import read_reduced_diags, read_reduced_diags_histogram -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] # print tolerance tolerance = 0.02 -print('Tolerance:', tolerance) +print("Tolerance:", tolerance) -#=============================== +# =============================== # gaussian and maxwell-boltzmann -#=============================== +# =============================== # load data bin_value, h1x = read_reduced_diags_histogram("h1x.txt")[2:] @@ -49,31 +49,46 @@ # parameters of theory u_rms = 0.01 -gamma = np.sqrt(1.0+u_rms*u_rms) +gamma = np.sqrt(1.0 + u_rms * u_rms) v_rms = u_rms / gamma * scc.c -n = 1.0e21 -V = 8.0 -db = 0.0016 +n = 1.0e21 +V = 8.0 +db = 0.0016 # compute the analytical solution -f = n*V*scc.c*db*np.exp(-0.5*(bin_value*scc.c/v_rms)**2)/(v_rms*np.sqrt(2.0*scc.pi)) +f = ( + n + * V + * scc.c + * db + * np.exp(-0.5 * (bin_value * scc.c / v_rms) ** 2) + / (v_rms * np.sqrt(2.0 * scc.pi)) +) f_peak = np.amax(f) # compute error # note that parameters are chosen such that gaussian and # maxwell-boltzmann distributions are identical -f1_error = np.sum(np.abs(f-h1x)+np.abs(f-h1y)+np.abs(f-h1z))/bin_value.size / f_peak -f2_error = np.sum(np.abs(f-h2x)+np.abs(f-h2y)+np.abs(f-h2z))/bin_value.size / f_peak - -print('Gaussian distribution difference:', f1_error) -print('Maxwell-Boltzmann distribution difference:', f2_error) - -assert(f1_error < tolerance) -assert(f2_error < tolerance) - -#================ +f1_error = ( + np.sum(np.abs(f - h1x) + np.abs(f - h1y) + np.abs(f - h1z)) + / bin_value.size + / f_peak +) +f2_error = ( + np.sum(np.abs(f - h2x) + np.abs(f - h2y) + np.abs(f - h2z)) + / bin_value.size + / f_peak +) + +print("Gaussian distribution difference:", f1_error) +print("Maxwell-Boltzmann distribution difference:", f2_error) + +assert f1_error < tolerance +assert f2_error < tolerance + +# ================ # maxwell-juttner -#================ +# ================ # load data bin_value, bin_data = read_reduced_diags_histogram("h3.txt")[2:] @@ -81,80 +96,106 @@ # parameters of theory theta = 1.0 -K2 = scs.kn(2,1.0/theta) -n = 1.0e21 -V = 8.0 -db = 0.22 +K2 = scs.kn(2, 1.0 / theta) +n = 1.0e21 +V = 8.0 +db = 0.22 # compute the analytical solution -f = n*V*db * bin_value**2 * np.sqrt(1.0-1.0/bin_value**2) / \ - (theta*K2) * np.exp(-bin_value/theta) +f = ( + n + * V + * db + * bin_value**2 + * np.sqrt(1.0 - 1.0 / bin_value**2) + / (theta * K2) + * np.exp(-bin_value / theta) +) f_peak = np.amax(f) # analytical solution for the filtered histogram: we just filter out gamma values < 5.5 -f_filtered = f*(bin_value > 5.5) +f_filtered = f * (bin_value > 5.5) # compute error -f3_error = np.sum( np.abs(f-bin_data) + np.abs(f_filtered-bin_data_filtered) ) \ - / bin_value.size / f_peak +f3_error = ( + np.sum(np.abs(f - bin_data) + np.abs(f_filtered - bin_data_filtered)) + / bin_value.size + / f_peak +) -print('Maxwell-Juttner distribution difference:', f3_error) +print("Maxwell-Juttner distribution difference:", f3_error) -assert(f3_error < tolerance) +assert f3_error < tolerance -#============== +# ============== # gaussian beam -#============== +# ============== # load data bin_value, h4x = read_reduced_diags_histogram("h4x.txt")[2:] h4y = read_reduced_diags_histogram("h4y.txt")[3] h4z = read_reduced_diags_histogram("h4z.txt")[3] _, bmmntr = read_reduced_diags("bmmntr.txt") -charge = bmmntr['charge'][0] +charge = bmmntr["charge"][0] # parameters of theory x_rms = 0.25 -z_cut = 2. +z_cut = 2.0 q_tot = -1.0e-20 -q_e = -1.602176634e-19 -npart = q_tot/q_e -db = bin_value[1]-bin_value[0] +q_e = -1.602176634e-19 +npart = q_tot / q_e +db = bin_value[1] - bin_value[0] # compute the analytical solution -f_xy = npart*db * np.exp(-0.5*(bin_value/x_rms)**2)/(x_rms*np.sqrt(2.0*scc.pi)) * scs.erf(z_cut/np.sqrt(2.)) -f_z = npart*db * np.exp(-0.5*(bin_value/x_rms)**2)/(x_rms*np.sqrt(2.0*scc.pi)) -f_z[ np.absolute(bin_value) > z_cut * x_rms ] = 0. +f_xy = ( + npart + * db + * np.exp(-0.5 * (bin_value / x_rms) ** 2) + / (x_rms * np.sqrt(2.0 * scc.pi)) + * scs.erf(z_cut / np.sqrt(2.0)) +) +f_z = ( + npart + * db + * np.exp(-0.5 * (bin_value / x_rms) ** 2) + / (x_rms * np.sqrt(2.0 * scc.pi)) +) +f_z[np.absolute(bin_value) > z_cut * x_rms] = 0.0 f_peak = np.amax(f_z) -q_tot_cut = q_tot * scs.erf(z_cut/np.sqrt(2.)) +q_tot_cut = q_tot * scs.erf(z_cut / np.sqrt(2.0)) # compute error -f4_error = np.sum(np.abs(f_xy-h4x)+np.abs(f_xy-h4y)+np.abs(f_z-h4z))/bin_value.size / f_peak +f4_error = ( + np.sum(np.abs(f_xy - h4x) + np.abs(f_xy - h4y) + np.abs(f_z - h4z)) + / bin_value.size + / f_peak +) charge_error = np.abs((q_tot_cut - charge) / q_tot) do_plot = False if do_plot: import matplotlib.pyplot as plt + plt.figure() plt.subplot(121) - plt.plot(bin_value, f_xy, '+-', label='ref') - plt.plot(bin_value, h4x, '+--', label='sim') + plt.plot(bin_value, f_xy, "+-", label="ref") + plt.plot(bin_value, h4x, "+--", label="sim") plt.legend() plt.subplot(122) - plt.plot(bin_value, f_z, '+-', label='ref') - plt.plot(bin_value, h4z, '+--', label='sim') + plt.plot(bin_value, f_z, "+-", label="ref") + plt.plot(bin_value, h4z, "+--", label="sim") plt.legend() - plt.savefig('toto.pdf', bbox_inches='tight') + plt.savefig("toto.pdf", bbox_inches="tight") -print('Gaussian position distribution difference:', f4_error) -assert(f4_error < tolerance) +print("Gaussian position distribution difference:", f4_error) +assert f4_error < tolerance -print('Relative beam charge difference:', charge_error) -assert(charge_error < tolerance) +print("Relative beam charge difference:", charge_error) +assert charge_error < tolerance -#============================================= +# ============================================= # maxwell-juttner with temperature from parser -#============================================= +# ============================================= # load data bin_value, bin_data_neg = read_reduced_diags_histogram("h5_neg.txt")[2:] @@ -164,32 +205,49 @@ # _neg denotes where x<0, _pos where x>0 theta_neg = 1.0 theta_pos = 2.0 -K2_neg = scs.kn(2,1.0/theta_neg) -K2_pos = scs.kn(2,1.0/theta_pos) -n = 1.0e21 -V = 8.0 / 2 # because each of these are for half the domain -db = 0.22 +K2_neg = scs.kn(2, 1.0 / theta_neg) +K2_pos = scs.kn(2, 1.0 / theta_pos) +n = 1.0e21 +V = 8.0 / 2 # because each of these are for half the domain +db = 0.22 # compute the analytical solution for each half of the domain -f_neg = n*V*db * bin_value**2 * np.sqrt(1.0-1.0/bin_value**2) / \ - (theta_neg*K2_neg) * np.exp(-bin_value/theta_neg) +f_neg = ( + n + * V + * db + * bin_value**2 + * np.sqrt(1.0 - 1.0 / bin_value**2) + / (theta_neg * K2_neg) + * np.exp(-bin_value / theta_neg) +) f_neg_peak = np.amax(f_neg) -f_pos = n*V*db * bin_value**2 * np.sqrt(1.0-1.0/bin_value**2) / \ - (theta_pos*K2_pos) * np.exp(-bin_value/theta_pos) +f_pos = ( + n + * V + * db + * bin_value**2 + * np.sqrt(1.0 - 1.0 / bin_value**2) + / (theta_pos * K2_pos) + * np.exp(-bin_value / theta_pos) +) f_pos_peak = np.amax(f_pos) f_peak = max(f_neg_peak, f_pos_peak) # compute error -f5_error = np.sum( np.abs(f_neg-bin_data_neg) + np.abs(f_pos-bin_data_pos) ) \ - / bin_value.size / f_peak +f5_error = ( + np.sum(np.abs(f_neg - bin_data_neg) + np.abs(f_pos - bin_data_pos)) + / bin_value.size + / f_peak +) -print('Maxwell-Juttner parser temperature difference:', f5_error) +print("Maxwell-Juttner parser temperature difference:", f5_error) -assert(f5_error < tolerance) +assert f5_error < tolerance -#============================================== +# ============================================== # maxwell-boltzmann with constant bulk velocity -#============================================== +# ============================================== # load data bin_value_g, bin_data_g = read_reduced_diags_histogram("h6.txt")[2:] @@ -197,14 +255,14 @@ # Expected values for beta and u = beta*gamma beta_const = 0.2 -g_const = 1. / np.sqrt(1. - beta_const * beta_const) +g_const = 1.0 / np.sqrt(1.0 - beta_const * beta_const) uy_const = beta_const * g_const g_bin_size = 0.004 -g_bin_min = 1. +g_bin_min = 1.0 uy_bin_size = 0.04 -uy_bin_min = -1. -V = 8.0 # volume in m^3 -n = 1.0e21 # number density in 1/m^3 +uy_bin_min = -1.0 +V = 8.0 # volume in m^3 +n = 1.0e21 # number density in 1/m^3 f_g = np.zeros_like(bin_value_g) i_g = int(np.floor((g_const - g_bin_min) / g_bin_size)) @@ -215,16 +273,19 @@ i_uy = int(np.floor((-uy_const - uy_bin_min) / uy_bin_size)) f_uy[i_uy] = n * V -f6_error = np.sum(np.abs(f_g - bin_data_g) + np.abs(f_uy - bin_data_uy)) \ - / bin_value_g.size / f_peak +f6_error = ( + np.sum(np.abs(f_g - bin_data_g) + np.abs(f_uy - bin_data_uy)) + / bin_value_g.size + / f_peak +) -print('Maxwell-Boltzmann constant velocity difference:', f6_error) +print("Maxwell-Boltzmann constant velocity difference:", f6_error) -assert(f6_error < tolerance) +assert f6_error < tolerance -#============================================ +# ============================================ # maxwell-boltzmann with parser bulk velocity -#============================================ +# ============================================ # load data bin_value_g, bin_data_g = read_reduced_diags_histogram("h7.txt")[2:] @@ -233,14 +294,14 @@ # Expected values for beta and u = beta*gamma beta_const = 0.2 -g_const = 1. / np.sqrt(1. - beta_const * beta_const) +g_const = 1.0 / np.sqrt(1.0 - beta_const * beta_const) uy_const = beta_const * g_const g_bin_size = 0.004 -g_bin_min = 1. +g_bin_min = 1.0 uy_bin_size = 0.04 -uy_bin_min = -1. -V = 8.0 # volume in m^3 -n = 1.0e21 # number density in 1/m^3 +uy_bin_min = -1.0 +V = 8.0 # volume in m^3 +n = 1.0e21 # number density in 1/m^3 f_g = np.zeros_like(bin_value_g) i_g = int(np.floor((g_const - g_bin_min) / g_bin_size)) @@ -249,23 +310,30 @@ f_uy_neg = np.zeros_like(bin_value_uy) i_uy_neg = int(np.floor((uy_const - uy_bin_min) / uy_bin_size)) -f_uy_neg[i_uy_neg] = n * V / 2. +f_uy_neg[i_uy_neg] = n * V / 2.0 f_uy_pos = np.zeros_like(bin_value_uy) i_uy_pos = int(np.floor((-uy_const - uy_bin_min) / uy_bin_size)) -f_uy_pos[i_uy_pos] = n * V / 2. +f_uy_pos[i_uy_pos] = n * V / 2.0 -f7_error = np.sum(np.abs(f_g - bin_data_g) + np.abs(f_uy_pos - bin_data_uy_pos) \ - + np.abs(f_uy_neg - bin_data_uy_neg)) / bin_value_g.size / f_peak +f7_error = ( + np.sum( + np.abs(f_g - bin_data_g) + + np.abs(f_uy_pos - bin_data_uy_pos) + + np.abs(f_uy_neg - bin_data_uy_neg) + ) + / bin_value_g.size + / f_peak +) -print('Maxwell-Boltzmann parser velocity difference:', f7_error) +print("Maxwell-Boltzmann parser velocity difference:", f7_error) -assert(f7_error < tolerance) +assert f7_error < tolerance -#============================================ +# ============================================ # Cuboid distribution in momentum space -#============================================ +# ============================================ bin_value_x, h8x = read_reduced_diags_histogram("h8x.txt")[2:] bin_value_y, h8y = read_reduced_diags_histogram("h8y.txt")[2:] @@ -284,6 +352,7 @@ # Distributions along the three momentum axes are independent: # we can test them separately + # This counts the number of bins where we expect the distribution to be nonzero def nonzero_bins(bins, low, high): # Bin with nonzero distribution is defined when b_{i+1} > u_min & b_i < u_max @@ -292,7 +361,8 @@ def nonzero_bins(bins, low, high): db = bins[1] - bins[0] loweredges = bins - 0.5 * db upperedges = bins + 0.5 * db - return ((upperedges > low) & (loweredges < high)) + return (upperedges > low) & (loweredges < high) + # Function that checks the validity of the histogram. # We have to call it for each of the axis @@ -313,7 +383,7 @@ def check_validity_uniform(bins, histogram, u_min, u_max, Ntrials=1000): # u_max = u_min (i.e. a delta distribution) if Nbins == 1: # In this case the result should be exact - assert( (histogram[nzbins].item() - 1) < 1e-8 ) + assert (histogram[nzbins].item() - 1) < 1e-8 return @@ -324,7 +394,9 @@ def check_validity_uniform(bins, histogram, u_min, u_max, Ntrials=1000): # Filling a given bin is a binomial process, so we basically test each histogram with the # expected average value to be (x - mu) < 3 sigma - probability = (np.clip(upperedges, u_min, u_max) - np.clip(loweredges, u_min, u_max)) / (u_max - u_min) + probability = ( + np.clip(upperedges, u_min, u_max) - np.clip(loweredges, u_min, u_max) + ) / (u_max - u_min) variance = probability * (1 - probability) nzprob = probability[nzbins] nzhist = histogram[nzbins] @@ -335,6 +407,7 @@ def check_validity_uniform(bins, histogram, u_min, u_max, Ntrials=1000): assert np.all(normalizedvariable < 3 * samplesigma) + # Test the distribution at every time step # (this assumes that no interaction is happening) for timestep in range(len(h8x)): @@ -342,32 +415,41 @@ def check_validity_uniform(bins, histogram, u_min, u_max, Ntrials=1000): check_validity_uniform(bin_value_y, h8y[timestep] / N0, uy_min, uy_max) check_validity_uniform(bin_value_z, h8z[timestep] / N0, uz_min, uz_max) -#================================================= +# ================================================= # Gaussian with parser mean and standard deviation -#================================================= +# ================================================= # load data bin_value_ux, bin_data_ux = read_reduced_diags_histogram("h9x.txt")[2:] bin_value_uy, bin_data_uy = read_reduced_diags_histogram("h9y.txt")[2:] bin_value_uz, bin_data_uz = read_reduced_diags_histogram("h9z.txt")[2:] -def Gaussian(mean, sigma, u): - V = 8.0 # volume in m^3 - n = 1.0e21 # number density in 1/m^3 - return (n*V/(sigma*np.sqrt(2.*np.pi)))*np.exp(-(u - mean)**2/(2.*sigma**2)) - -du = 2./50 -f_ux = Gaussian(0.1 , 0.2 , bin_value_ux)*du -f_uy = Gaussian(0.12, 0.21, bin_value_uy)*du -f_uz = Gaussian(0.14, 0.22, bin_value_uz)*du -f9_error = np.sum(np.abs(f_ux - bin_data_ux)/f_ux.max() - +np.abs(f_uy - bin_data_uy)/f_ux.max() - +np.abs(f_uz - bin_data_uz)/f_uz.max()) / bin_value_ux.size - -print('gaussian_parse_momentum_function velocity difference:', f9_error) - -assert(f9_error < tolerance) +def Gaussian(mean, sigma, u): + V = 8.0 # volume in m^3 + n = 1.0e21 # number density in 1/m^3 + return (n * V / (sigma * np.sqrt(2.0 * np.pi))) * np.exp( + -((u - mean) ** 2) / (2.0 * sigma**2) + ) + + +du = 2.0 / 50 +f_ux = Gaussian(0.1, 0.2, bin_value_ux) * du +f_uy = Gaussian(0.12, 0.21, bin_value_uy) * du +f_uz = Gaussian(0.14, 0.22, bin_value_uz) * du + +f9_error = ( + np.sum( + np.abs(f_ux - bin_data_ux) / f_ux.max() + + np.abs(f_uy - bin_data_uy) / f_ux.max() + + np.abs(f_uz - bin_data_uz) / f_uz.max() + ) + / bin_value_ux.size +) + +print("gaussian_parse_momentum_function velocity difference:", f9_error) + +assert f9_error < tolerance test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/initial_distribution/inputs b/Examples/Tests/initial_distribution/inputs_test_3d_initial_distribution similarity index 100% rename from Examples/Tests/initial_distribution/inputs rename to Examples/Tests/initial_distribution/inputs_test_3d_initial_distribution diff --git a/Examples/Tests/initial_plasma_profile/CMakeLists.txt b/Examples/Tests/initial_plasma_profile/CMakeLists.txt new file mode 100644 index 00000000000..eb45e64dfab --- /dev/null +++ b/Examples/Tests/initial_plasma_profile/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_parabolic_channel_initialization # name + 2 # dims + 2 # nprocs + inputs_test_2d_parabolic_channel_initialization # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/initial_plasma_profile/analysis.py b/Examples/Tests/initial_plasma_profile/analysis.py index b8cfaad1048..f5fc75ee578 100755 --- a/Examples/Tests/initial_plasma_profile/analysis.py +++ b/Examples/Tests/initial_plasma_profile/analysis.py @@ -13,7 +13,7 @@ yt.funcs.mylog.setLevel(50) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Name of the plotfile diff --git a/Examples/Tests/initial_plasma_profile/inputs b/Examples/Tests/initial_plasma_profile/inputs_test_2d_parabolic_channel_initialization similarity index 100% rename from Examples/Tests/initial_plasma_profile/inputs rename to Examples/Tests/initial_plasma_profile/inputs_test_2d_parabolic_channel_initialization diff --git a/Examples/Tests/ion_stopping/CMakeLists.txt b/Examples/Tests/ion_stopping/CMakeLists.txt new file mode 100644 index 00000000000..83e15287e18 --- /dev/null +++ b/Examples/Tests/ion_stopping/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_ion_stopping # name + 3 # dims + 1 # nprocs + inputs_test_3d_ion_stopping # inputs + analysis.py # analysis + diags/diag1000010 # output + OFF # dependency +) diff --git a/Examples/Tests/ion_stopping/analysis.py b/Examples/Tests/ion_stopping/analysis.py new file mode 100755 index 00000000000..e343bd23fdd --- /dev/null +++ b/Examples/Tests/ion_stopping/analysis.py @@ -0,0 +1,198 @@ +#!/usr/bin/env python3 + +# Copyright 2022 David Grote +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +# This script tests the ion stopping model. +# It uses the same stopping power formula that +# is used in the C++ to check the resulting +# particle energies. + +import os +import sys + +import numpy as np +import yt +from scipy.constants import e, epsilon_0, k, m_e, m_p + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# Define constants using the WarpX names for the evals below +q_e = e +kb = k + +# Tolerance on the error in the final energy (in eV) +tolerance = 1.0e-7 + +last_filename = sys.argv[1] +last_it = 10 + + +def stopping_from_electrons(ne, Te, Zb, ion_mass): + """Calculate the coefficient in equation 14.13 from + "Introduction to Plasma Physics", Goldston and Rutherford. + ne: electron density + Te: electron temperature (eV) + Zb: ion charge state + ion_mass: (kg) + """ + vthe = np.sqrt(3.0 * Te * e / m_e) + wpe = np.sqrt(ne * e**2 / (epsilon_0 * m_e)) + lambdadb = vthe / wpe + loglambda = np.log((12.0 * np.pi / Zb) * (ne * lambdadb**3)) + # Goldston's equation 14.13 + dEdt = ( + -np.sqrt(2.0) + * ne + * Zb**2 + * e**4 + * np.sqrt(m_e) + * loglambda + / (6.0 * np.pi**1.5 * epsilon_0**2 * ion_mass * (Te * e) ** 1.5) + ) + return dEdt + + +def stopping_from_ions(dt, ni, Ti, mi, Zi, Zb, ion_mass, ion_energy): + """ + ni: background ion density + Ti: background ion temperature (eV) + mi: background ion mass + Zi: background ion charge state + Zb: ion charge state + ion_mass: (kg) + ion_energy: (eV) + """ + vthi = np.sqrt(3.0 * Ti * e / mi) + wpi = np.sqrt(ni * e**2 / (epsilon_0 * mi)) + lambdadb = vthi / wpi + loglambda = np.log((12.0 * np.pi / Zb) * (ni * lambdadb**3)) + alpha = ( + np.sqrt(2.0) + * ni + * Zi**2 + * Zb**2 + * e**4 + * np.sqrt(ion_mass) + * loglambda + / (8.0 * np.pi * epsilon_0**2 * mi) + ) + f1 = np.clip((ion_energy * e) ** (3.0 / 2.0) - 3.0 / 2.0 * alpha * dt, 0.0, None) + ion_energy = (f1) ** (2.0 / 3.0) / e + return ion_energy + + +# Fetch background parameters and initial particle data +ds0 = yt.load("diags/diag1000000") +ad0 = ds0.all_data() + +Zb = 1.0 # Ion charge state + +ne = float(ds0.parameters["stopping_on_electrons_constant.background_density"]) +Te = ( + eval(ds0.parameters["stopping_on_electrons_constant.background_temperature"]) + * kb + / e +) +ion_mass12 = m_p + +mi = eval(ds0.parameters["stopping_on_ions_constant.background_mass"]) +Zi = float(ds0.parameters["stopping_on_ions_constant.background_charge_state"]) +ni = float(ds0.parameters["stopping_on_ions_constant.background_density"]) +Ti = eval(ds0.parameters["stopping_on_ions_constant.background_temperature"]) * kb / e +ion_mass34 = 4.0 * m_p + +# For ions1, the background parameters are constants +vx = ad0[("ions1", "particle_momentum_x")].to_ndarray() / ion_mass12 +vy = ad0[("ions1", "particle_momentum_y")].to_ndarray() / ion_mass12 +vz = ad0[("ions1", "particle_momentum_z")].to_ndarray() / ion_mass12 +EE1 = 0.5 * ion_mass12 * (vx**2 + vy**2 + vz**2) / e + +# For ions2, the background parameters are parsed +xx = ad0[("ions2", "particle_position_x")].to_ndarray() / ion_mass12 +yy = ad0[("ions2", "particle_position_y")].to_ndarray() / ion_mass12 +ne2 = np.where(xx > 0.0, 1.0e20, 1.0e21) +Te2 = np.where(yy > 0.0, 1.0, 2.0) + +vx = ad0[("ions2", "particle_momentum_x")].to_ndarray() / ion_mass12 +vy = ad0[("ions2", "particle_momentum_y")].to_ndarray() / ion_mass12 +vz = ad0[("ions2", "particle_momentum_z")].to_ndarray() / ion_mass12 +EE2 = 0.5 * ion_mass12 * (vx**2 + vy**2 + vz**2) / e + +# For ions3, the background parameters are constants +vx = ad0[("ions3", "particle_momentum_x")].to_ndarray() / ion_mass34 +vy = ad0[("ions3", "particle_momentum_y")].to_ndarray() / ion_mass34 +vz = ad0[("ions3", "particle_momentum_z")].to_ndarray() / ion_mass34 +EE3 = 0.5 * ion_mass34 * (vx**2 + vy**2 + vz**2) / e + +# For ions4, the background parameters are parsed +xx = ad0[("ions4", "particle_position_x")].to_ndarray() / ion_mass34 +yy = ad0[("ions4", "particle_position_y")].to_ndarray() / ion_mass34 +ni4 = np.where(xx > 0.0, 1.0e20, 1.0e21) +Ti4 = np.where(yy > 0.0, 0.05, 0.10) + +vx = ad0[("ions4", "particle_momentum_x")].to_ndarray() / ion_mass34 +vy = ad0[("ions4", "particle_momentum_y")].to_ndarray() / ion_mass34 +vz = ad0[("ions4", "particle_momentum_z")].to_ndarray() / ion_mass34 +EE4 = 0.5 * ion_mass34 * (vx**2 + vy**2 + vz**2) / e + + +ds = yt.load(last_filename) +ad = ds.all_data() +dt = ds.current_time.to_value() / last_it + +# Step through the same number of time steps +a_EE1 = EE1 +a_EE2 = EE2 +a_EE3 = EE3 +a_EE4 = EE4 +for it in range(last_it): + dEdt1 = stopping_from_electrons(ne, Te, Zb, ion_mass12) + a_EE1 *= np.exp(dEdt1 * dt) + dEdt2 = stopping_from_electrons(ne2, Te2, Zb, ion_mass12) + a_EE2 *= np.exp(dEdt2 * dt) + a_EE3 = stopping_from_ions(dt, ni, Ti, mi, Zi, Zb, ion_mass34, a_EE3) + a_EE4 = stopping_from_ions(dt, ni4, Ti4, mi, Zi, Zb, ion_mass34, a_EE4) + +# Fetch the final particle data +vx = ad[("ions1", "particle_momentum_x")].to_ndarray() / ion_mass12 +vy = ad[("ions1", "particle_momentum_y")].to_ndarray() / ion_mass12 +vz = ad[("ions1", "particle_momentum_z")].to_ndarray() / ion_mass12 +EE1 = 0.5 * ion_mass12 * (vx**2 + vy**2 + vz**2) / e + +vx = ad[("ions2", "particle_momentum_x")].to_ndarray() / ion_mass12 +vy = ad[("ions2", "particle_momentum_y")].to_ndarray() / ion_mass12 +vz = ad[("ions2", "particle_momentum_z")].to_ndarray() / ion_mass12 +EE2 = 0.5 * ion_mass12 * (vx**2 + vy**2 + vz**2) / e + +vx = ad[("ions3", "particle_momentum_x")].to_ndarray() / ion_mass34 +vy = ad[("ions3", "particle_momentum_y")].to_ndarray() / ion_mass34 +vz = ad[("ions3", "particle_momentum_z")].to_ndarray() / ion_mass34 +EE3 = 0.5 * ion_mass34 * (vx**2 + vy**2 + vz**2) / e + +vx = ad[("ions4", "particle_momentum_x")].to_ndarray() / ion_mass34 +vy = ad[("ions4", "particle_momentum_y")].to_ndarray() / ion_mass34 +vz = ad[("ions4", "particle_momentum_z")].to_ndarray() / ion_mass34 +EE4 = 0.5 * ion_mass34 * (vx**2 + vy**2 + vz**2) / e + +error1 = np.abs(EE1 - a_EE1) +error2 = np.abs(EE2 - a_EE2) +error3 = np.abs(EE3 - a_EE3) +error4 = np.abs(EE4 - a_EE4) +print("stopping on electrons error with constant = ", error1) +print("stopping on electrons error with parsed = ", error2) +print("stopping on ions error with constant = ", error3) +print("stopping on ions error with parsed = ", error4) +print("tolerance = ", tolerance) + +assert np.all(error1 < tolerance) +assert np.all(error2 < tolerance) +assert np.all(error3 < tolerance) +assert np.all(error4 < tolerance) + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, last_filename) diff --git a/Examples/Tests/ion_stopping/analysis_ion_stopping.py b/Examples/Tests/ion_stopping/analysis_ion_stopping.py deleted file mode 100755 index d7774c14d6b..00000000000 --- a/Examples/Tests/ion_stopping/analysis_ion_stopping.py +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2022 David Grote -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -# This script tests the ion stopping model. -# It uses the same stopping power formula that -# is used in the C++ to check the resulting -# particle energies. - -import os -import re -import sys - -import numpy as np -import yt -from scipy.constants import e, epsilon_0, k, m_e, m_p - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -# Define constants using the WarpX names for the evals below -q_e = e -kb = k - -# Tolerance on the error in the final energy (in eV) -tolerance = 1.e-7 - -last_filename = sys.argv[1] - -# Remove trailing '/' from file name, if necessary -last_filename.rstrip('/') -# Find last iteration in file name, such as 'test_name_plt000001' (last_it = '000001') -last_it = re.search('\d+$', last_filename).group() -# Find output prefix in file name, such as 'test_name_plt000001' (prefix = 'test_name_plt') -prefix = last_filename[:-len(last_it)] - -def stopping_from_electrons(ne, Te, Zb, ion_mass): - """Calculate the coefficient in equation 14.13 from - "Introduction to Plasma Physics", Goldston and Rutherford. - ne: electron density - Te: electron temperature (eV) - Zb: ion charge state - ion_mass: (kg) - """ - vthe = np.sqrt(3.*Te*e/m_e) - wpe = np.sqrt(ne*e**2/(epsilon_0*m_e)) - lambdadb = vthe/wpe - loglambda = np.log((12.*np.pi/Zb)*(ne*lambdadb**3)) - # Goldston's equation 14.13 - dEdt = - np.sqrt(2.)*ne*Zb**2*e**4*np.sqrt(m_e)*loglambda/(6.*np.pi**1.5*epsilon_0**2*ion_mass*(Te*e)**1.5) - return dEdt - -def stopping_from_ions(dt, ni, Ti, mi, Zi, Zb, ion_mass, ion_energy): - """ - ni: background ion density - Ti: background ion temperature (eV) - mi: background ion mass - Zi: background ion charge state - Zb: ion charge state - ion_mass: (kg) - ion_energy: (eV) - """ - vthi = np.sqrt(3.*Ti*e/mi) - wpi = np.sqrt(ni*e**2/(epsilon_0*mi)) - lambdadb = vthi/wpi - loglambda = np.log((12.*np.pi/Zb)*(ni*lambdadb**3)) - alpha = np.sqrt(2.)*ni*Zi**2*Zb**2*e**4*np.sqrt(ion_mass)*loglambda/(8.*np.pi*epsilon_0**2*mi) - f1 = np.clip((ion_energy*e)**(3./2.) - 3./2.*alpha*dt, 0., None) - ion_energy = (f1)**(2./3.)/e - return ion_energy - -# Fetch background parameters and initial particle data -ds0 = yt.load(f'{prefix}{len(last_it)*"0"}') -ad0 = ds0.all_data() - -Zb = 1. # Ion charge state - -ne = float(ds0.parameters['stopping_on_electrons_constant.background_density']) -Te = eval(ds0.parameters['stopping_on_electrons_constant.background_temperature'])*kb/e -ion_mass12 = m_p - -mi = eval(ds0.parameters['stopping_on_ions_constant.background_mass']) -Zi = float(ds0.parameters['stopping_on_ions_constant.background_charge_state']) -ni = float(ds0.parameters['stopping_on_ions_constant.background_density']) -Ti = eval(ds0.parameters['stopping_on_ions_constant.background_temperature'])*kb/e -ion_mass34 = 4.*m_p - -# For ions1, the background parameters are constants -vx = ad0[('ions1', 'particle_momentum_x')].to_ndarray()/ion_mass12 -vy = ad0[('ions1', 'particle_momentum_y')].to_ndarray()/ion_mass12 -vz = ad0[('ions1', 'particle_momentum_z')].to_ndarray()/ion_mass12 -EE1 = 0.5*ion_mass12*(vx**2 + vy**2 + vz**2)/e - -# For ions2, the background parameters are parsed -xx = ad0[('ions2', 'particle_position_x')].to_ndarray()/ion_mass12 -yy = ad0[('ions2', 'particle_position_y')].to_ndarray()/ion_mass12 -ne2 = np.where(xx > 0., 1.e20, 1.e21) -Te2 = np.where(yy > 0., 1., 2.) - -vx = ad0[('ions2', 'particle_momentum_x')].to_ndarray()/ion_mass12 -vy = ad0[('ions2', 'particle_momentum_y')].to_ndarray()/ion_mass12 -vz = ad0[('ions2', 'particle_momentum_z')].to_ndarray()/ion_mass12 -EE2 = 0.5*ion_mass12*(vx**2 + vy**2 + vz**2)/e - -# For ions3, the background parameters are constants -vx = ad0[('ions3', 'particle_momentum_x')].to_ndarray()/ion_mass34 -vy = ad0[('ions3', 'particle_momentum_y')].to_ndarray()/ion_mass34 -vz = ad0[('ions3', 'particle_momentum_z')].to_ndarray()/ion_mass34 -EE3 = 0.5*ion_mass34*(vx**2 + vy**2 + vz**2)/e - -# For ions4, the background parameters are parsed -xx = ad0[('ions4', 'particle_position_x')].to_ndarray()/ion_mass34 -yy = ad0[('ions4', 'particle_position_y')].to_ndarray()/ion_mass34 -ni4 = np.where(xx > 0., 1.e20, 1.e21) -Ti4 = np.where(yy > 0., 0.05, 0.10) - -vx = ad0[('ions4', 'particle_momentum_x')].to_ndarray()/ion_mass34 -vy = ad0[('ions4', 'particle_momentum_y')].to_ndarray()/ion_mass34 -vz = ad0[('ions4', 'particle_momentum_z')].to_ndarray()/ion_mass34 -EE4 = 0.5*ion_mass34*(vx**2 + vy**2 + vz**2)/e - - -ds = yt.load(last_filename) -ad = ds.all_data() -dt = ds.current_time.to_value()/int(last_it) - -# Step through the same number of time steps -a_EE1 = EE1 -a_EE2 = EE2 -a_EE3 = EE3 -a_EE4 = EE4 -for it in range(int(last_it)): - dEdt1 = stopping_from_electrons(ne, Te, Zb, ion_mass12) - a_EE1 *= np.exp(dEdt1*dt) - dEdt2 = stopping_from_electrons(ne2, Te2, Zb, ion_mass12) - a_EE2 *= np.exp(dEdt2*dt) - a_EE3 = stopping_from_ions(dt, ni, Ti, mi, Zi, Zb, ion_mass34, a_EE3) - a_EE4 = stopping_from_ions(dt, ni4, Ti4, mi, Zi, Zb, ion_mass34, a_EE4) - -# Fetch the final particle data -vx = ad[('ions1', 'particle_momentum_x')].to_ndarray()/ion_mass12 -vy = ad[('ions1', 'particle_momentum_y')].to_ndarray()/ion_mass12 -vz = ad[('ions1', 'particle_momentum_z')].to_ndarray()/ion_mass12 -EE1 = 0.5*ion_mass12*(vx**2 + vy**2 + vz**2)/e - -vx = ad[('ions2', 'particle_momentum_x')].to_ndarray()/ion_mass12 -vy = ad[('ions2', 'particle_momentum_y')].to_ndarray()/ion_mass12 -vz = ad[('ions2', 'particle_momentum_z')].to_ndarray()/ion_mass12 -EE2 = 0.5*ion_mass12*(vx**2 + vy**2 + vz**2)/e - -vx = ad[('ions3', 'particle_momentum_x')].to_ndarray()/ion_mass34 -vy = ad[('ions3', 'particle_momentum_y')].to_ndarray()/ion_mass34 -vz = ad[('ions3', 'particle_momentum_z')].to_ndarray()/ion_mass34 -EE3 = 0.5*ion_mass34*(vx**2 + vy**2 + vz**2)/e - -vx = ad[('ions4', 'particle_momentum_x')].to_ndarray()/ion_mass34 -vy = ad[('ions4', 'particle_momentum_y')].to_ndarray()/ion_mass34 -vz = ad[('ions4', 'particle_momentum_z')].to_ndarray()/ion_mass34 -EE4 = 0.5*ion_mass34*(vx**2 + vy**2 + vz**2)/e - -error1 = np.abs(EE1 - a_EE1) -error2 = np.abs(EE2 - a_EE2) -error3 = np.abs(EE3 - a_EE3) -error4 = np.abs(EE4 - a_EE4) -print('stopping on electrons error with constant = ', error1) -print('stopping on electrons error with parsed = ', error2) -print('stopping on ions error with constant = ', error3) -print('stopping on ions error with parsed = ', error4) -print('tolerance = ', tolerance) - -assert np.all(error1 < tolerance) -assert np.all(error2 < tolerance) -assert np.all(error3 < tolerance) -assert np.all(error4 < tolerance) - -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, last_filename) diff --git a/Examples/Tests/ion_stopping/inputs_3d b/Examples/Tests/ion_stopping/inputs_test_3d_ion_stopping similarity index 99% rename from Examples/Tests/ion_stopping/inputs_3d rename to Examples/Tests/ion_stopping/inputs_test_3d_ion_stopping index 291e1ca0a9e..93b59bbde4a 100644 --- a/Examples/Tests/ion_stopping/inputs_3d +++ b/Examples/Tests/ion_stopping/inputs_test_3d_ion_stopping @@ -14,6 +14,7 @@ boundary.field_hi = periodic periodic periodic boundary.particle_lo = periodic periodic periodic boundary.particle_hi = periodic periodic periodic algo.particle_shape = 1 +warpx.cfl = 0.7 particles.species_names = ions1 ions2 ions3 ions4 diff --git a/Examples/Tests/ionization/PICMI_inputs_2d.py b/Examples/Tests/ionization/PICMI_inputs_2d.py deleted file mode 100644 index 802bf5435ac..00000000000 --- a/Examples/Tests/ionization/PICMI_inputs_2d.py +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -# Physical constants -c = picmi.constants.c - -# Number of time steps -max_steps = 1600 - -# Number of cells -nx = 16 -nz = 800 - -# Physical domain -xmin = -5e-06 -xmax = 5e-06 -zmin = 0e-06 -zmax = 20e-06 - -# Domain decomposition -max_grid_size = 64 -blocking_factor = 16 - -# Create grid -grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, nz], - lower_bound = [xmin, zmin], - upper_bound = [xmax, zmax], - lower_boundary_conditions = ['periodic', 'open'], - upper_boundary_conditions = ['periodic', 'open'], - warpx_max_grid_size = max_grid_size, - warpx_blocking_factor = blocking_factor) - -# Particles: electrons and ions -ions_density = 1 -ions_xmin = None -ions_ymin = None -ions_zmin = 5e-06 -ions_xmax = None -ions_ymax = None -ions_zmax = 15e-06 -uniform_distribution = picmi.UniformDistribution( - density = ions_density, - lower_bound = [ions_xmin, ions_ymin, ions_zmin], - upper_bound = [ions_xmax, ions_ymax, ions_zmax], - fill_in = True) -electrons = picmi.Species( - particle_type = 'electron', - name = 'electrons', - warpx_add_real_attributes = {'orig_z': 'z'}) -ions = picmi.Species( - particle_type = 'N', - name = 'ions', - charge_state = 2, - initial_distribution = uniform_distribution, - warpx_add_real_attributes = {'orig_z': 'z'}) - -# Field ionization -nitrogen_ionization = picmi.FieldIonization( - model = "ADK", # Ammosov-Delone-Krainov model - ionized_species = ions, - product_species = electrons) - -# Laser -position_z = 3e-06 -profile_t_peak = 60.e-15 -laser = picmi.GaussianLaser( - wavelength = 0.8e-06, - waist = 1e10, - duration = 26.685e-15, - focal_position = [0, 0, position_z], - centroid_position = [0, 0, position_z - c*profile_t_peak], - propagation_direction = [0, 0, 1], - polarization_direction = [1, 0, 0], - a0 = 1.8, - fill_in = False) -laser_antenna = picmi.LaserAntenna( - position = [0., 0., position_z], - normal_vector = [0, 0, 1]) - -# Electromagnetic solver -solver = picmi.ElectromagneticSolver( - grid = grid, - method = 'CKC', - cfl = 0.999) - -# Diagnostics -particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 10000, - species = [electrons, ions], - data_list = ['ux', 'uy', 'uz', 'x', 'z', 'weighting', 'orig_z'], - write_dir = '.', - warpx_file_prefix = 'Python_ionization_plt') -field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 10000, - data_list = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], - write_dir = '.', - warpx_file_prefix = 'Python_ionization_plt') - -# Set up simulation -sim = picmi.Simulation( - solver = solver, - max_steps = max_steps, - particle_shape = 'linear', - warpx_use_filter = 0) - -# Add electrons and ions -sim.add_species( - electrons, - layout = picmi.GriddedLayout(grid = grid, n_macroparticle_per_cell = [0, 0, 0])) -sim.add_species( - ions, - layout = picmi.GriddedLayout(grid = grid, n_macroparticle_per_cell = [2, 1, 1])) - -# Add field ionization -sim.add_interaction(nitrogen_ionization) - -# Add laser -sim.add_laser( - laser, - injection_method = laser_antenna) - -# Add diagnostics -sim.add_diagnostic(particle_diag) -sim.add_diagnostic(field_diag) - -# Write input file that can be used to run with the compiled version -sim.write_input_file(file_name = 'inputs_2d_picmi') - -# Initialize inputs and WarpX instance -sim.initialize_inputs() -sim.initialize_warpx() - -# Advance simulation until last time step -sim.step(max_steps) diff --git a/Examples/Tests/langmuir/CMakeLists.txt b/Examples/Tests/langmuir/CMakeLists.txt new file mode 100644 index 00000000000..b259083c695 --- /dev/null +++ b/Examples/Tests/langmuir/CMakeLists.txt @@ -0,0 +1,411 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_langmuir_multi # name + 1 # dims + 2 # nprocs + inputs_test_1d_langmuir_multi # inputs + analysis_1d.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +add_warpx_test( + test_2d_langmuir_multi # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +add_warpx_test( + test_2d_langmuir_multi_mr # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_mr # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +add_warpx_test( + test_2d_langmuir_multi_mr_anisotropic # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_mr_anisotropic # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +add_warpx_test( + test_2d_langmuir_multi_mr_momentum_conserving # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_mr_momentum_conserving # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_mr_psatd # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_mr_psatd # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +add_warpx_test( + test_2d_langmuir_multi_nodal # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_nodal # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +add_warpx_test( + test_2d_langmuir_multi_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000040 # output + OFF # dependency +) + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_psatd # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_current_correction # name + 2 # dims + 1 # nprocs + inputs_test_2d_langmuir_multi_psatd_current_correction # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_current_correction_nodal # name + 2 # dims + 1 # nprocs + inputs_test_2d_langmuir_multi_psatd_current_correction_nodal # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_momentum_conserving # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_psatd_momentum_conserving # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_multiJ # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_psatd_multiJ # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_multiJ_nodal # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_psatd_multiJ_nodal # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_nodal # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_multi_psatd_nodal # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_vay_deposition # name + 2 # dims + 1 # nprocs + inputs_test_2d_langmuir_multi_psatd_vay_deposition # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_vay_deposition_nodal # name + 2 # dims + 1 # nprocs + inputs_test_2d_langmuir_multi_psatd_vay_deposition_nodal # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_langmuir_multi_psatd_vay_deposition_particle_shape_4 # name + 2 # dims + 1 # nprocs + inputs_test_2d_langmuir_multi_psatd_vay_deposition_particle_shape_4 # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +add_warpx_test( + test_3d_langmuir_multi # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_multi # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency +) + +add_warpx_test( + test_3d_langmuir_multi_nodal # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_multi_nodal # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency +) + +add_warpx_test( + test_3d_langmuir_multi_picmi # name + 3 # dims + 1 # nprocs + inputs_test_3d_langmuir_multi_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000040 # output + OFF # dependency +) + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_multi_psatd # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_current_correction # name + 3 # dims + 1 # nprocs + inputs_test_3d_langmuir_multi_psatd_current_correction # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_current_correction_nodal # name + 3 # dims + 1 # nprocs + inputs_test_3d_langmuir_multi_psatd_current_correction_nodal # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_div_cleaning # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_multi_psatd_div_cleaning # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_momentum_conserving # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_multi_psatd_momentum_conserving # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_multiJ # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_multi_psatd_multiJ # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_multiJ_nodal # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_multi_psatd_multiJ_nodal # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_nodal # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_multi_psatd_nodal # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_vay_deposition # name + 3 # dims + 1 # nprocs + inputs_test_3d_langmuir_multi_psatd_vay_deposition # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_langmuir_multi_psatd_vay_deposition_nodal # name + 3 # dims + 1 # nprocs + inputs_test_3d_langmuir_multi_psatd_vay_deposition_nodal # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency + ) + label_warpx_test(test_3d_langmuir_multi_psatd_vay_deposition_nodal slow) +endif() + +add_warpx_test( + test_rz_langmuir_multi # name + RZ # dims + 2 # nprocs + inputs_test_rz_langmuir_multi # inputs + analysis_rz.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +add_warpx_test( + test_rz_langmuir_multi_picmi # name + RZ # dims + 2 # nprocs + inputs_test_rz_langmuir_multi_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000040 # output + OFF # dependency +) + +if(WarpX_FFT) + add_warpx_test( + test_rz_langmuir_multi_psatd # name + RZ # dims + 2 # nprocs + inputs_test_rz_langmuir_multi_psatd # inputs + analysis_rz.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_rz_langmuir_multi_psatd_current_correction # name + RZ # dims + 1 # nprocs + inputs_test_rz_langmuir_multi_psatd_current_correction # inputs + analysis_rz.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_rz_langmuir_multi_psatd_multiJ # name + RZ # dims + 2 # nprocs + inputs_test_rz_langmuir_multi_psatd_multiJ # inputs + analysis_rz.py # analysis + diags/diag1000080 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/langmuir/PICMI_inputs_2d.py b/Examples/Tests/langmuir/PICMI_inputs_2d.py deleted file mode 100755 index 4b9c3ac300f..00000000000 --- a/Examples/Tests/langmuir/PICMI_inputs_2d.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python3 -# -# --- Simple example of Langmuir oscillations in a uniform plasma -# --- in two dimensions - -from pywarpx import picmi - -constants = picmi.constants - -########################## -# physics parameters -########################## - -plasma_density = 1.e25 -plasma_xmin = 0. -plasma_x_velocity = 0.1*constants.c - -########################## -# numerics parameters -########################## - -# --- Number of time steps -max_steps = 40 -diagnostic_intervals = "::10" - -# --- Grid -nx = 64 -ny = 64 - -xmin = -20.e-6 -ymin = -20.e-6 -xmax = +20.e-6 -ymax = +20.e-6 - -number_per_cell_each_dim = [2,2] - -########################## -# physics components -########################## - -uniform_plasma = picmi.UniformDistribution(density = 1.e25, - upper_bound = [0., None, None], - directed_velocity = [0.1*constants.c, 0., 0.]) - -electrons = picmi.Species(particle_type='electron', name='electrons', initial_distribution=uniform_plasma) - -########################## -# numerics components -########################## - -grid = picmi.Cartesian2DGrid(number_of_cells = [nx, ny], - lower_bound = [xmin, ymin], - upper_bound = [xmax, ymax], - lower_boundary_conditions = ['periodic', 'periodic'], - upper_boundary_conditions = ['periodic', 'periodic'], - moving_window_velocity = [0., 0., 0.], - warpx_max_grid_size = 32) - -solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.) - -########################## -# diagnostics -########################## - -field_diag1 = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = diagnostic_intervals, - data_list = ['Ex', 'Jx'], - write_dir = '.', - warpx_file_prefix = 'Python_Langmuir_2d_plt') - -part_diag1 = picmi.ParticleDiagnostic(name = 'diag1', - period = diagnostic_intervals, - species = [electrons], - data_list = ['weighting', 'ux']) - -########################## -# simulation setup -########################## - -sim = picmi.Simulation(solver = solver, - max_steps = max_steps, - verbose = 1, - warpx_current_deposition_algo = 'direct', - warpx_use_filter = 0) - -sim.add_species(electrons, - layout = picmi.GriddedLayout(n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid)) - -sim.add_diagnostic(field_diag1) -sim.add_diagnostic(part_diag1) - -########################## -# simulation run -########################## - -# write_inputs will create an inputs file that can be used to run -# with the compiled version. -sim.write_input_file(file_name = 'inputs2d_from_PICMI') - -# Alternatively, sim.step will run WarpX, controlling it from Python -sim.step() diff --git a/Examples/Tests/langmuir/PICMI_inputs_3d.py b/Examples/Tests/langmuir/PICMI_inputs_3d.py deleted file mode 100755 index 180180f5f45..00000000000 --- a/Examples/Tests/langmuir/PICMI_inputs_3d.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python3 -# -# --- Simple example of Langmuir oscillations in a uniform plasma - -from pywarpx import picmi - -constants = picmi.constants - -########################## -# physics parameters -########################## - -plasma_density = 1.e25 -plasma_xmin = 0. -plasma_x_velocity = 0.1*constants.c - -########################## -# numerics parameters -########################## - -# --- Number of time steps -max_steps = 40 -diagnostic_interval = 10 - -# --- Grid -nx = 64 -ny = 64 -nz = 64 - -xmin = -20.e-6 -ymin = -20.e-6 -zmin = -20.e-6 -xmax = +20.e-6 -ymax = +20.e-6 -zmax = +20.e-6 - -number_per_cell_each_dim = [2,2,2] - -########################## -# physics components -########################## - -uniform_plasma = picmi.UniformDistribution(density = 1.e25, - upper_bound = [0., None, None], - directed_velocity = [0.1*constants.c, 0., 0.]) - -electrons = picmi.Species(particle_type='electron', name='electrons', initial_distribution=uniform_plasma) - -########################## -# numerics components -########################## - -grid = picmi.Cartesian3DGrid(number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = ['periodic', 'periodic', 'periodic'], - upper_boundary_conditions = ['periodic', 'periodic', 'periodic'], - moving_window_velocity = [0., 0., 0.], - warpx_max_grid_size = 32) - -solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.) - -########################## -# diagnostics -########################## - -field_diag1 = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = diagnostic_interval, - data_list = ['Ex', 'Jx'], - write_dir = '.', - warpx_file_prefix = 'Python_Langmuir_plt') - -part_diag1 = picmi.ParticleDiagnostic(name = 'diag1', - period = diagnostic_interval, - species = [electrons], - data_list = ['weighting', 'ux']) - -########################## -# simulation setup -########################## - -sim = picmi.Simulation(solver = solver, - max_steps = max_steps, - verbose = 1, - warpx_current_deposition_algo = 'direct') - -sim.add_species(electrons, - layout = picmi.GriddedLayout(n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid)) - -sim.add_diagnostic(field_diag1) -sim.add_diagnostic(part_diag1) - -########################## -# simulation run -########################## - -# write_inputs will create an inputs file that can be used to run -# with the compiled version. -#sim.write_input_file(file_name = 'inputs_from_PICMI') - -# Alternatively, sim.step will run WarpX, controlling it from Python -sim.step() diff --git a/Examples/Tests/langmuir/PICMI_inputs_rz.py b/Examples/Tests/langmuir/PICMI_inputs_rz.py deleted file mode 100755 index 8da03b00469..00000000000 --- a/Examples/Tests/langmuir/PICMI_inputs_rz.py +++ /dev/null @@ -1,238 +0,0 @@ -#!/usr/bin/env python3 -# -# This is a script that analyses the multimode simulation results. -# This simulates a RZ multimode periodic plasma wave. -# The electric field from the simulation is compared to the analytic value - -import matplotlib - -matplotlib.use('Agg') -import matplotlib.pyplot as plt -import numpy as np - -from pywarpx import fields, picmi - -constants = picmi.constants - -########################## -# physics parameters -########################## - -density = 2.e24 -epsilon0 = 0.001*constants.c -epsilon1 = 0.001*constants.c -epsilon2 = 0.001*constants.c -w0 = 5.e-6 -n_osc_z = 3 - -# Plasma frequency -wp = np.sqrt((density*constants.q_e**2)/(constants.m_e*constants.ep0)) -kp = wp/constants.c - -########################## -# numerics parameters -########################## - -nr = 64 -nz = 200 - -rmin = 0.e0 -zmin = 0.e0 -rmax = +20.e-6 -zmax = +40.e-6 - -# Wave vector of the wave -k0 = 2.*np.pi*n_osc_z/(zmax - zmin) - -diagnostic_intervals = 40 - -########################## -# physics components -########################## - -uniform_plasma = picmi.UniformDistribution(density = density, - upper_bound = [+18e-6, +18e-6, None], - directed_velocity = [0., 0., 0.]) - -momentum_expressions = ["""+ epsilon0/kp*2*x/w0**2*exp(-(x**2+y**2)/w0**2)*sin(k0*z) - - epsilon1/kp*2/w0*exp(-(x**2+y**2)/w0**2)*sin(k0*z) - + epsilon1/kp*4*x**2/w0**3*exp(-(x**2+y**2)/w0**2)*sin(k0*z) - - epsilon2/kp*8*x/w0**2*exp(-(x**2+y**2)/w0**2)*sin(k0*z) - + epsilon2/kp*8*x*(x**2-y**2)/w0**4*exp(-(x**2+y**2)/w0**2)*sin(k0*z)""", - """+ epsilon0/kp*2*y/w0**2*exp(-(x**2+y**2)/w0**2)*sin(k0*z) - + epsilon1/kp*4*x*y/w0**3*exp(-(x**2+y**2)/w0**2)*sin(k0*z) - + epsilon2/kp*8*y/w0**2*exp(-(x**2+y**2)/w0**2)*sin(k0*z) - + epsilon2/kp*8*y*(x**2-y**2)/w0**4*exp(-(x**2+y**2)/w0**2)*sin(k0*z)""", - """- epsilon0/kp*k0*exp(-(x**2+y**2)/w0**2)*cos(k0*z) - - epsilon1/kp*k0*2*x/w0*exp(-(x**2+y**2)/w0**2)*cos(k0*z) - - epsilon2/kp*k0*4*(x**2-y**2)/w0**2*exp(-(x**2+y**2)/w0**2)*cos(k0*z)"""] - -analytic_plasma = picmi.AnalyticDistribution(density_expression = density, - upper_bound = [+18e-6, +18e-6, None], - epsilon0 = epsilon0, - epsilon1 = epsilon1, - epsilon2 = epsilon2, - kp = kp, - k0 = k0, - w0 = w0, - momentum_expressions = momentum_expressions) - -electrons = picmi.Species(particle_type='electron', name='electrons', initial_distribution=analytic_plasma) -protons = picmi.Species(particle_type='proton', name='protons', initial_distribution=uniform_plasma) - -########################## -# numerics components -########################## - -grid = picmi.CylindricalGrid(number_of_cells = [nr, nz], - n_azimuthal_modes = 3, - lower_bound = [rmin, zmin], - upper_bound = [rmax, zmax], - lower_boundary_conditions = ['none', 'periodic'], - upper_boundary_conditions = ['none', 'periodic'], - lower_boundary_conditions_particles = ['none', 'periodic'], - upper_boundary_conditions_particles = ['absorbing', 'periodic'], - moving_window_velocity = [0.,0.], - warpx_max_grid_size=64) - -solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.) - -########################## -# diagnostics -########################## - -field_diag1 = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = diagnostic_intervals, - data_list = ['Er', 'Ez', 'Bt', 'Jr', 'Jz', 'part_per_cell'], - write_dir = '.', - warpx_file_prefix = 'Python_Langmuir_rz_multimode_plt') - -part_diag1 = picmi.ParticleDiagnostic(name = 'diag1', - period = diagnostic_intervals, - species = [electrons], - data_list = ['weighting', 'momentum']) - -########################## -# simulation setup -########################## - -sim = picmi.Simulation(solver = solver, - max_steps = 40, - verbose = 1, - warpx_current_deposition_algo = 'esirkepov', - warpx_field_gathering_algo = 'energy-conserving', - warpx_particle_pusher_algo = 'boris', - warpx_use_filter = 0) - -sim.add_species(electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[2,16,2], grid=grid)) -sim.add_species(protons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[2,16,2], grid=grid)) - -sim.add_diagnostic(field_diag1) -sim.add_diagnostic(part_diag1) - -########################## -# simulation run -########################## - -# write_inputs will create an inputs file that can be used to run -# with the compiled version. -#sim.write_input_file(file_name='inputsrz_from_PICMI') - -# Alternatively, sim.step will run WarpX, controlling it from Python -sim.step() - - -# Below is WarpX specific code to check the results. - -def calcEr( z, r, k0, w0, wp, t, epsilons) : - """ - Return the radial electric field as an array - of the same length as z and r, in the half-plane theta=0 - """ - Er_array = ( - epsilons[0] * constants.m_e*constants.c/constants.q_e * 2*r/w0**2 * - np.exp( -r**2/w0**2 ) * np.sin( k0*z ) * np.sin( wp*t ) - - epsilons[1] * constants.m_e*constants.c/constants.q_e * 2/w0 * - np.exp( -r**2/w0**2 ) * np.sin( k0*z ) * np.sin( wp*t ) - + epsilons[1] * constants.m_e*constants.c/constants.q_e * 4*r**2/w0**3 * - np.exp( -r**2/w0**2 ) * np.sin( k0*z ) * np.sin( wp*t ) - - epsilons[2] * constants.m_e*constants.c/constants.q_e * 8*r/w0**2 * - np.exp( -r**2/w0**2 ) * np.sin( k0*z ) * np.sin( wp*t ) - + epsilons[2] * constants.m_e*constants.c/constants.q_e * 8*r**3/w0**4 * - np.exp( -r**2/w0**2 ) * np.sin( k0*z ) * np.sin( wp*t )) - return( Er_array ) - -def calcEz( z, r, k0, w0, wp, t, epsilons) : - """ - Return the longitudinal electric field as an array - of the same length as z and r, in the half-plane theta=0 - """ - Ez_array = ( - - epsilons[0] * constants.m_e*constants.c/constants.q_e * k0 * - np.exp( -r**2/w0**2 ) * np.cos( k0*z ) * np.sin( wp*t ) - - epsilons[1] * constants.m_e*constants.c/constants.q_e * k0 * 2*r/w0 * - np.exp( -r**2/w0**2 ) * np.cos( k0*z ) * np.sin( wp*t ) - - epsilons[2] * constants.m_e*constants.c/constants.q_e * k0 * 4*r**2/w0**2 * - np.exp( -r**2/w0**2 ) * np.cos( k0*z ) * np.sin( wp*t )) - return( Ez_array ) - -# Current time of the simulation -t0 = sim.extension.warpx.gett_new(0) - -# Get the raw field data. Note that these are the real and imaginary -# parts of the fields for each azimuthal mode. -Ex_sim_wrap = fields.ExWrapper() -Ez_sim_wrap = fields.EzWrapper() -Ex_sim_modes = Ex_sim_wrap[...] -Ez_sim_modes = Ez_sim_wrap[...] - -rr_Er = Ex_sim_wrap.mesh('r') -zz_Er = Ex_sim_wrap.mesh('z') -rr_Ez = Ez_sim_wrap.mesh('r') -zz_Ez = Ez_sim_wrap.mesh('z') - -rr_Er = rr_Er[:,np.newaxis]*np.ones(zz_Er.shape[0])[np.newaxis,:] -zz_Er = zz_Er[np.newaxis,:]*np.ones(rr_Er.shape[0])[:,np.newaxis] -rr_Ez = rr_Ez[:,np.newaxis]*np.ones(zz_Ez.shape[0])[np.newaxis,:] -zz_Ez = zz_Ez[np.newaxis,:]*np.ones(rr_Ez.shape[0])[:,np.newaxis] - -# Sum the real components to get the field along x-axis (theta = 0) -Er_sim = Ex_sim_modes[:,:,0] + np.sum(Ex_sim_modes[:,:,1::2], axis=2) -Ez_sim = Ez_sim_modes[:,:,0] + np.sum(Ez_sim_modes[:,:,1::2], axis=2) - -# The analytical solutions -Er_th = calcEr(zz_Er, rr_Er, k0, w0, wp, t0, [epsilon0, epsilon1, epsilon2]) -Ez_th = calcEz(zz_Ez, rr_Ez, k0, w0, wp, t0, [epsilon0, epsilon1, epsilon2]) - -max_error_Er = abs(Er_sim - Er_th).max()/abs(Er_th).max() -max_error_Ez = abs(Ez_sim - Ez_th).max()/abs(Ez_th).max() -print("Max error Er %e"%max_error_Er) -print("Max error Ez %e"%max_error_Ez) - -# Plot the last field from the loop (Er at iteration 40) -fig, ax = plt.subplots(3) -im = ax[0].imshow( Er_sim, aspect='auto', origin='lower' ) -fig.colorbar(im, ax=ax[0], orientation='vertical') -ax[0].set_title('Er, last iteration (simulation)') -ax[1].imshow( Er_th, aspect='auto', origin='lower' ) -fig.colorbar(im, ax=ax[1], orientation='vertical') -ax[1].set_title('Er, last iteration (theory)') -im = ax[2].imshow( (Er_sim - Er_th)/abs(Er_th).max(), aspect='auto', origin='lower' ) -fig.colorbar(im, ax=ax[2], orientation='vertical') -ax[2].set_title('Er, last iteration (difference)') -plt.savefig('langmuir_multi_rz_multimode_analysis_Er.png') - -fig, ax = plt.subplots(3) -im = ax[0].imshow( Ez_sim, aspect='auto', origin='lower' ) -fig.colorbar(im, ax=ax[0], orientation='vertical') -ax[0].set_title('Ez, last iteration (simulation)') -ax[1].imshow( Ez_th, aspect='auto', origin='lower' ) -fig.colorbar(im, ax=ax[1], orientation='vertical') -ax[1].set_title('Ez, last iteration (theory)') -im = ax[2].imshow( (Ez_sim - Ez_th)/abs(Ez_th).max(), aspect='auto', origin='lower' ) -fig.colorbar(im, ax=ax[2], orientation='vertical') -ax[2].set_title('Ez, last iteration (difference)') -plt.savefig('langmuir_multi_rz_multimode_analysis_Ez.png') - -assert max(max_error_Er, max_error_Ez) < 0.02 diff --git a/Examples/Tests/langmuir/README.rst b/Examples/Tests/langmuir/README.rst index 60c0018744c..4748f428dc1 100644 --- a/Examples/Tests/langmuir/README.rst +++ b/Examples/Tests/langmuir/README.rst @@ -23,19 +23,19 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. tab-item:: Python: Script - This example can be run as a **Python** script: ``python3 PICMI_inputs_3d.py``. + This example can be run as a **Python** script: ``python3 inputs_test_3d_langmuir_multi_picmi.py``. - .. literalinclude:: PICMI_inputs_3d.py + .. literalinclude:: inputs_test_3d_langmuir_multi_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/langmuir/PICMI_inputs_3d.py``. + :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_picmi.py``. .. tab-item:: Executable: Input File - This example can be run as WarpX **executable** using an input file: ``warpx.3d inputs_3d`` + This example can be run as WarpX **executable** using an input file: ``warpx.3d inputs_test_3d_langmuir_multi`` - .. literalinclude:: inputs_3d + .. literalinclude:: inputs_test_3d_langmuir_multi :language: ini - :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_3d``. + :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_test_3d_langmuir_multi``. .. tab-item:: 2D @@ -43,19 +43,19 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. tab-item:: Python: Script - This example can be run as a **Python** script: ``python3 PICMI_inputs_2d.py``. + This example can be run as a **Python** script: ``python3 inputs_test_2d_langmuir_multi_picmi.py``. - .. literalinclude:: PICMI_inputs_2d.py + .. literalinclude:: inputs_test_2d_langmuir_multi_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/langmuir/PICMI_inputs_2d.py``. + :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_picmi.py``. .. tab-item:: Executable: Input File - This example can be run as WarpX **executable** using an input file: ``warpx.2d inputs_2d`` + This example can be run as WarpX **executable** using an input file: ``warpx.2d inputs_test_2d_langmuir_multi`` - .. literalinclude:: inputs_2d + .. literalinclude:: inputs_test_2d_langmuir_multi :language: ini - :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_2d``. + :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_test_2d_langmuir_multi``. .. tab-item:: RZ @@ -64,19 +64,19 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. tab-item:: Python: Script - This example can be run as a **Python** script: ``python3 PICMI_inputs_rz.py``. + This example can be run as a **Python** script: ``python3 inputs_test_rz_langmuir_multi_picmi.py``. - .. literalinclude:: PICMI_inputs_rz.py + .. literalinclude:: inputs_test_rz_langmuir_multi_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/langmuir/PICMI_inputs_rz.py``. + :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_picmi.py``. .. tab-item:: Executable: Input File - This example can be run as WarpX **executable** using an input file: ``warpx.rz inputs_rz`` + This example can be run as WarpX **executable** using an input file: ``warpx.rz inputs_test_rz_langmuir_multi`` - .. literalinclude:: inputs_rz + .. literalinclude:: inputs_test_rz_langmuir_multi :language: ini - :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_rz``. + :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_test_rz_langmuir_multi``. .. tab-item:: 1D @@ -87,15 +87,15 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. note:: - TODO: This input file should be created, like the ``inputs_1d`` file. + TODO: This input file should be created, like the ``inputs_test_1d_langmuir_multi`` file. .. tab-item:: Executable: Input File - This example can be run as WarpX **executable** using an input file: ``warpx.1d inputs_1d`` + This example can be run as WarpX **executable** using an input file: ``warpx.1d inputs_test_1d_langmuir_multi`` - .. literalinclude:: inputs_1d + .. literalinclude:: inputs_test_1d_langmuir_multi :language: ini - :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_1d``. + :caption: You can copy this file from ``Examples/Tests/langmuir/inputs_test_1d_langmuir_multi``. Analyze diff --git a/Examples/Tests/langmuir/analysis_1d.py b/Examples/Tests/langmuir/analysis_1d.py index 7b05fac6643..d041ca03b36 100755 --- a/Examples/Tests/langmuir/analysis_1d.py +++ b/Examples/Tests/langmuir/analysis_1d.py @@ -17,7 +17,7 @@ import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import yt @@ -26,94 +26,104 @@ import numpy as np from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI +# test name +test_name = os.path.split(os.getcwd())[1] + # this will be the name of the plot file fn = sys.argv[1] # Parse test name and check if current correction (psatd.current_correction=1) is applied -current_correction = True if re.search( 'current_correction', fn ) else False +current_correction = True if re.search("current_correction", test_name) else False # Parse test name and check if Vay current deposition (algo.current_deposition=vay) is used -vay_deposition = True if re.search( 'Vay_deposition', fn ) else False +vay_deposition = True if re.search("vay_deposition", test_name) else False # Parameters (these parameters must match the parameters in `inputs.multi.rt`) epsilon = 0.01 -n = 4.e24 +n = 4.0e24 n_osc_z = 2 -zmin = -20e-6; zmax = 20.e-6; Nz = 128 +zmin = -20e-6 +zmax = 20.0e-6 +Nz = 128 # Wave vector of the wave -kz = 2.*np.pi*n_osc_z/(zmax-zmin) +kz = 2.0 * np.pi * n_osc_z / (zmax - zmin) # Plasma frequency -wp = np.sqrt((n*e**2)/(m_e*epsilon_0)) +wp = np.sqrt((n * e**2) / (m_e * epsilon_0)) + +k = {"Ez": kz} +cos = {"Ez": (1, 1, 0)} -k = {'Ez':kz} -cos = {'Ez':(1,1,0)} -def get_contribution( is_cos, k ): - du = (zmax-zmin)/Nz - u = zmin + du*( 0.5 + np.arange(Nz) ) +def get_contribution(is_cos, k): + du = (zmax - zmin) / Nz + u = zmin + du * (0.5 + np.arange(Nz)) if is_cos == 1: - return( np.cos(k*u) ) + return np.cos(k * u) else: - return( np.sin(k*u) ) + return np.sin(k * u) -def get_theoretical_field( field, t ): - amplitude = epsilon * (m_e*c**2*k[field])/e * np.sin(wp*t) + +def get_theoretical_field(field, t): + amplitude = epsilon * (m_e * c**2 * k[field]) / e * np.sin(wp * t) cos_flag = cos[field] - z_contribution = get_contribution( cos_flag[2], kz ) + z_contribution = get_contribution(cos_flag[2], kz) E = amplitude * z_contribution - return( E ) + return E + # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) # Check the validity of the fields error_rel = 0 -for field in ['Ez']: - E_sim = data[('mesh',field)].to_ndarray()[:,0,0] +for field in ["Ez"]: + E_sim = data[("mesh", field)].to_ndarray()[:, 0, 0] E_th = get_theoretical_field(field, t0) - max_error = abs(E_sim-E_th).max()/abs(E_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(E_sim - E_th).max() / abs(E_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Plot the last field from the loop (Ez at iteration 80) -plt.subplot2grid( (1,2), (0,0) ) -plt.plot( E_sim ) -#plt.colorbar() -plt.title('Ez, last iteration\n(simulation)') -plt.subplot2grid( (1,2), (0,1) ) -plt.plot( E_th ) -#plt.colorbar() -plt.title('Ez, last iteration\n(theory)') +plt.subplot2grid((1, 2), (0, 0)) +plt.plot(E_sim) +# plt.colorbar() +plt.title("Ez, last iteration\n(simulation)") +plt.subplot2grid((1, 2), (0, 1)) +plt.plot(E_th) +# plt.colorbar() +plt.title("Ez, last iteration\n(theory)") plt.tight_layout() -plt.savefig('langmuir_multi_1d_analysis.png') +plt.savefig("langmuir_multi_1d_analysis.png") tolerance_rel = 0.05 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel # Check relative L-infinity spatial norm of rho/epsilon_0 - div(E) when # current correction (psatd.do_current_correction=1) is applied or when # Vay current deposition (algo.current_deposition=vay) is used if current_correction or vay_deposition: - rho = data[('boxlib','rho')].to_ndarray() - divE = data[('boxlib','divE')].to_ndarray() - error_rel = np.amax( np.abs( divE - rho/epsilon_0 ) ) / np.amax( np.abs( rho/epsilon_0 ) ) - tolerance = 1.e-9 + rho = data[("boxlib", "rho")].to_ndarray() + divE = data[("boxlib", "divE")].to_ndarray() + error_rel = np.amax(np.abs(divE - rho / epsilon_0)) / np.amax( + np.abs(rho / epsilon_0) + ) + tolerance = 1.0e-9 print("Check charge conservation:") print("error_rel = {}".format(error_rel)) print("tolerance = {}".format(tolerance)) - assert( error_rel < tolerance ) + assert error_rel < tolerance -test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/langmuir/analysis_2d.py b/Examples/Tests/langmuir/analysis_2d.py index 94f97ca6de8..ac98354c73b 100755 --- a/Examples/Tests/langmuir/analysis_2d.py +++ b/Examples/Tests/langmuir/analysis_2d.py @@ -26,99 +26,117 @@ import numpy as np from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI +# test name +test_name = os.path.split(os.getcwd())[1] + # this will be the name of the plot file fn = sys.argv[1] # Parse test name and check if current correction (psatd.current_correction=1) is applied -current_correction = True if re.search( 'current_correction', fn ) else False +current_correction = True if re.search("current_correction", test_name) else False # Parse test name and check if Vay current deposition (algo.current_deposition=vay) is used -vay_deposition = True if re.search( 'Vay_deposition', fn ) else False +vay_deposition = True if re.search("vay_deposition", test_name) else False # Parse test name and check if particle_shape = 4 is used -particle_shape_4 = True if re.search('particle_shape_4', fn) else False +particle_shape_4 = True if re.search("particle_shape_4", test_name) else False -# Parameters (these parameters must match the parameters in `inputs.multi.rt`) +# Parameters (must match the parameters in the inputs) +# FIXME read these parameters from warpx_used_inputs epsilon = 0.01 -n = 4.e24 +n = 4.0e24 n_osc_x = 2 n_osc_z = 2 -xmin = -20e-6; xmax = 20.e-6; Nx = 128 -zmin = -20e-6; zmax = 20.e-6; Nz = 128 +xmin = -20e-6 +xmax = 20.0e-6 +Nx = 128 +zmin = -20e-6 +zmax = 20.0e-6 +Nz = 128 # Wave vector of the wave -kx = 2.*np.pi*n_osc_x/(xmax-xmin) -kz = 2.*np.pi*n_osc_z/(zmax-zmin) +kx = 2.0 * np.pi * n_osc_x / (xmax - xmin) +kz = 2.0 * np.pi * n_osc_z / (zmax - zmin) # Plasma frequency -wp = np.sqrt((n*e**2)/(m_e*epsilon_0)) +wp = np.sqrt((n * e**2) / (m_e * epsilon_0)) + +k = {"Ex": kx, "Ez": kz} +cos = {"Ex": (0, 1, 1), "Ez": (1, 1, 0)} -k = {'Ex':kx, 'Ez':kz} -cos = {'Ex': (0,1,1), 'Ez':(1,1,0)} -def get_contribution( is_cos, k ): - du = (xmax-xmin)/Nx - u = xmin + du*( 0.5 + np.arange(Nx) ) +def get_contribution(is_cos, k): + du = (xmax - xmin) / Nx + u = xmin + du * (0.5 + np.arange(Nx)) if is_cos == 1: - return( np.cos(k*u) ) + return np.cos(k * u) else: - return( np.sin(k*u) ) + return np.sin(k * u) -def get_theoretical_field( field, t ): - amplitude = epsilon * (m_e*c**2*k[field])/e * np.sin(wp*t) + +def get_theoretical_field(field, t): + amplitude = epsilon * (m_e * c**2 * k[field]) / e * np.sin(wp * t) cos_flag = cos[field] - x_contribution = get_contribution( cos_flag[0], kx ) - z_contribution = get_contribution( cos_flag[2], kz ) + x_contribution = get_contribution(cos_flag[0], kx) + z_contribution = get_contribution(cos_flag[2], kz) + + E = amplitude * x_contribution[:, np.newaxis] * z_contribution[np.newaxis, :] - E = amplitude * x_contribution[:, np.newaxis ] \ - * z_contribution[np.newaxis, :] + return E - return( E ) # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level = 0, left_edge = ds.domain_left_edge, dims = ds.domain_dimensions) -edge = np.array([(ds.domain_left_edge[1]).item(), (ds.domain_right_edge[1]).item(), \ - (ds.domain_left_edge[0]).item(), (ds.domain_right_edge[0]).item()]) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +edge = np.array( + [ + (ds.domain_left_edge[1]).item(), + (ds.domain_right_edge[1]).item(), + (ds.domain_left_edge[0]).item(), + (ds.domain_right_edge[0]).item(), + ] +) # Check the validity of the fields error_rel = 0 -for field in ['Ex', 'Ez']: - E_sim = data[('mesh',field)].to_ndarray()[:,:,0] +for field in ["Ex", "Ez"]: + E_sim = data[("mesh", field)].to_ndarray()[:, :, 0] E_th = get_theoretical_field(field, t0) - max_error = abs(E_sim-E_th).max()/abs(E_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(E_sim - E_th).max() / abs(E_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Plot the last field from the loop (Ez at iteration 40) -fig, (ax1, ax2) = plt.subplots(1, 2, dpi = 100) +fig, (ax1, ax2) = plt.subplots(1, 2, dpi=100) # First plot vmin = E_sim.min() vmax = E_sim.max() -cax1 = make_axes_locatable(ax1).append_axes('right', size = '5%', pad = '5%') -im1 = ax1.imshow(E_sim, origin = 'lower', extent = edge, vmin = vmin, vmax = vmax) -cb1 = fig.colorbar(im1, cax = cax1) -ax1.set_xlabel(r'$z$') -ax1.set_ylabel(r'$x$') -ax1.set_title(r'$E_z$ (sim)') +cax1 = make_axes_locatable(ax1).append_axes("right", size="5%", pad="5%") +im1 = ax1.imshow(E_sim, origin="lower", extent=edge, vmin=vmin, vmax=vmax) +cb1 = fig.colorbar(im1, cax=cax1) +ax1.set_xlabel(r"$z$") +ax1.set_ylabel(r"$x$") +ax1.set_title(r"$E_z$ (sim)") # Second plot vmin = E_th.min() vmax = E_th.max() -cax2 = make_axes_locatable(ax2).append_axes('right', size = '5%', pad = '5%') -im2 = ax2.imshow(E_th, origin = 'lower', extent = edge, vmin = vmin, vmax = vmax) -cb2 = fig.colorbar(im2, cax = cax2) -ax2.set_xlabel(r'$z$') -ax2.set_ylabel(r'$x$') -ax2.set_title(r'$E_z$ (theory)') +cax2 = make_axes_locatable(ax2).append_axes("right", size="5%", pad="5%") +im2 = ax2.imshow(E_th, origin="lower", extent=edge, vmin=vmin, vmax=vmax) +cb2 = fig.colorbar(im2, cax=cax2) +ax2.set_xlabel(r"$z$") +ax2.set_ylabel(r"$x$") +ax2.set_title(r"$E_z$ (theory)") # Save figure fig.tight_layout() -fig.savefig('Langmuir_multi_2d_analysis.png', dpi = 200) +fig.savefig("Langmuir_multi_2d_analysis.png", dpi=200) if particle_shape_4: -# lower fidelity, due to smoothing + # lower fidelity, due to smoothing tolerance_rel = 0.07 else: tolerance_rel = 0.05 @@ -126,7 +144,7 @@ def get_theoretical_field( field, t ): print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel # Check relative L-infinity spatial norm of rho/epsilon_0 - div(E) # with current correction (and periodic single box option) or with Vay current deposition @@ -135,13 +153,14 @@ def get_theoretical_field( field, t ): elif vay_deposition: tolerance = 1e-3 if current_correction or vay_deposition: - rho = data[('boxlib','rho')].to_ndarray() - divE = data[('boxlib','divE')].to_ndarray() - error_rel = np.amax( np.abs( divE - rho/epsilon_0 ) ) / np.amax( np.abs( rho/epsilon_0 ) ) + rho = data[("boxlib", "rho")].to_ndarray() + divE = data[("boxlib", "divE")].to_ndarray() + error_rel = np.amax(np.abs(divE - rho / epsilon_0)) / np.amax( + np.abs(rho / epsilon_0) + ) print("Check charge conservation:") print("error_rel = {}".format(error_rel)) print("tolerance = {}".format(tolerance)) - assert( error_rel < tolerance ) + assert error_rel < tolerance -test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/langmuir/analysis_3d.py b/Examples/Tests/langmuir/analysis_3d.py index 68334f506ff..9f4b2cc1f93 100755 --- a/Examples/Tests/langmuir/analysis_3d.py +++ b/Examples/Tests/langmuir/analysis_3d.py @@ -26,128 +26,142 @@ import numpy as np from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI +# test name +test_name = os.path.split(os.getcwd())[1] + # this will be the name of the plot file fn = sys.argv[1] # Parse test name and check if current correction (psatd.current_correction=1) is applied -current_correction = True if re.search( 'current_correction', fn ) else False +current_correction = True if re.search("current_correction", test_name) else False # Parse test name and check if Vay current deposition (algo.current_deposition=vay) is used -vay_deposition = True if re.search( 'Vay_deposition', fn ) else False +vay_deposition = True if re.search("vay_deposition", test_name) else False # Parse test name and check if div(E)/div(B) cleaning (warpx.do_div_cleaning=1) is used -div_cleaning = True if re.search('div_cleaning', fn) else False +div_cleaning = True if re.search("div_cleaning", test_name) else False # Parameters (these parameters must match the parameters in `inputs.multi.rt`) epsilon = 0.01 -n = 4.e24 +n = 4.0e24 n_osc_x = 2 n_osc_y = 2 n_osc_z = 2 -lo = [-20.e-6, -20.e-6, -20.e-6] -hi = [ 20.e-6, 20.e-6, 20.e-6] +lo = [-20.0e-6, -20.0e-6, -20.0e-6] +hi = [20.0e-6, 20.0e-6, 20.0e-6] Ncell = [64, 64, 64] # Wave vector of the wave -kx = 2.*np.pi*n_osc_x/(hi[0]-lo[0]) -ky = 2.*np.pi*n_osc_y/(hi[1]-lo[1]) -kz = 2.*np.pi*n_osc_z/(hi[2]-lo[2]) +kx = 2.0 * np.pi * n_osc_x / (hi[0] - lo[0]) +ky = 2.0 * np.pi * n_osc_y / (hi[1] - lo[1]) +kz = 2.0 * np.pi * n_osc_z / (hi[2] - lo[2]) # Plasma frequency -wp = np.sqrt((n*e**2)/(m_e*epsilon_0)) +wp = np.sqrt((n * e**2) / (m_e * epsilon_0)) + +k = {"Ex": kx, "Ey": ky, "Ez": kz} +cos = {"Ex": (0, 1, 1), "Ey": (1, 0, 1), "Ez": (1, 1, 0)} -k = {'Ex':kx, 'Ey':ky, 'Ez':kz} -cos = {'Ex': (0,1,1), 'Ey':(1,0,1), 'Ez':(1,1,0)} -def get_contribution( is_cos, k, idim ): - du = (hi[idim]-lo[idim])/Ncell[idim] - u = lo[idim] + du*( 0.5 + np.arange(Ncell[idim]) ) +def get_contribution(is_cos, k, idim): + du = (hi[idim] - lo[idim]) / Ncell[idim] + u = lo[idim] + du * (0.5 + np.arange(Ncell[idim])) if is_cos[idim] == 1: - return( np.cos(k*u) ) + return np.cos(k * u) else: - return( np.sin(k*u) ) + return np.sin(k * u) -def get_theoretical_field( field, t ): - amplitude = epsilon * (m_e*c**2*k[field])/e * np.sin(wp*t) + +def get_theoretical_field(field, t): + amplitude = epsilon * (m_e * c**2 * k[field]) / e * np.sin(wp * t) cos_flag = cos[field] - x_contribution = get_contribution( cos_flag, kx, 0 ) - y_contribution = get_contribution( cos_flag, ky, 1 ) - z_contribution = get_contribution( cos_flag, kz, 2 ) + x_contribution = get_contribution(cos_flag, kx, 0) + y_contribution = get_contribution(cos_flag, ky, 1) + z_contribution = get_contribution(cos_flag, kz, 2) + + E = ( + amplitude + * x_contribution[:, np.newaxis, np.newaxis] + * y_contribution[np.newaxis, :, np.newaxis] + * z_contribution[np.newaxis, np.newaxis, :] + ) - E = amplitude * x_contribution[:, np.newaxis, np.newaxis] \ - * y_contribution[np.newaxis, :, np.newaxis] \ - * z_contribution[np.newaxis, np.newaxis, :] + return E - return( E ) # Read the file ds = yt.load(fn) # Check that the particle selective output worked: -species = 'electrons' -print('ds.field_list', ds.field_list) -for field in ['particle_weight', - 'particle_momentum_x']: - print('assert that this is in ds.field_list', (species, field)) +species = "electrons" +print("ds.field_list", ds.field_list) +for field in ["particle_weight", "particle_momentum_x"]: + print("assert that this is in ds.field_list", (species, field)) assert (species, field) in ds.field_list -for field in ['particle_momentum_y', - 'particle_momentum_z']: - print('assert that this is NOT in ds.field_list', (species, field)) +for field in ["particle_momentum_y", "particle_momentum_z"]: + print("assert that this is NOT in ds.field_list", (species, field)) assert (species, field) not in ds.field_list -species = 'positrons' -for field in ['particle_momentum_x', - 'particle_momentum_y']: - print('assert that this is NOT in ds.field_list', (species, field)) +species = "positrons" +for field in ["particle_momentum_x", "particle_momentum_y"]: + print("assert that this is NOT in ds.field_list", (species, field)) assert (species, field) not in ds.field_list t0 = ds.current_time.to_value() -data = ds.covering_grid(level = 0, left_edge = ds.domain_left_edge, dims = ds.domain_dimensions) -edge = np.array([(ds.domain_left_edge[2]).item(), (ds.domain_right_edge[2]).item(), \ - (ds.domain_left_edge[0]).item(), (ds.domain_right_edge[0]).item()]) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +edge = np.array( + [ + (ds.domain_left_edge[2]).item(), + (ds.domain_right_edge[2]).item(), + (ds.domain_left_edge[0]).item(), + (ds.domain_right_edge[0]).item(), + ] +) # Check the validity of the fields error_rel = 0 -for field in ['Ex', 'Ey', 'Ez']: - E_sim = data[('mesh',field)].to_ndarray() +for field in ["Ex", "Ey", "Ez"]: + E_sim = data[("mesh", field)].to_ndarray() E_th = get_theoretical_field(field, t0) - max_error = abs(E_sim-E_th).max()/abs(E_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(E_sim - E_th).max() / abs(E_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Plot the last field from the loop (Ez at iteration 40) -fig, (ax1, ax2) = plt.subplots(1, 2, dpi = 100) +fig, (ax1, ax2) = plt.subplots(1, 2, dpi=100) # First plot (slice at y=0) -E_plot = E_sim[:,Ncell[1]//2+1,:] +E_plot = E_sim[:, Ncell[1] // 2 + 1, :] vmin = E_plot.min() vmax = E_plot.max() -cax1 = make_axes_locatable(ax1).append_axes('right', size = '5%', pad = '5%') -im1 = ax1.imshow(E_plot, origin = 'lower', extent = edge, vmin = vmin, vmax = vmax) -cb1 = fig.colorbar(im1, cax = cax1) -ax1.set_xlabel(r'$z$') -ax1.set_ylabel(r'$x$') -ax1.set_title(r'$E_z$ (sim)') +cax1 = make_axes_locatable(ax1).append_axes("right", size="5%", pad="5%") +im1 = ax1.imshow(E_plot, origin="lower", extent=edge, vmin=vmin, vmax=vmax) +cb1 = fig.colorbar(im1, cax=cax1) +ax1.set_xlabel(r"$z$") +ax1.set_ylabel(r"$x$") +ax1.set_title(r"$E_z$ (sim)") # Second plot (slice at y=0) -E_plot = E_th[:,Ncell[1]//2+1,:] +E_plot = E_th[:, Ncell[1] // 2 + 1, :] vmin = E_plot.min() vmax = E_plot.max() -cax2 = make_axes_locatable(ax2).append_axes('right', size = '5%', pad = '5%') -im2 = ax2.imshow(E_plot, origin = 'lower', extent = edge, vmin = vmin, vmax = vmax) -cb2 = fig.colorbar(im2, cax = cax2) -ax2.set_xlabel(r'$z$') -ax2.set_ylabel(r'$x$') -ax2.set_title(r'$E_z$ (theory)') +cax2 = make_axes_locatable(ax2).append_axes("right", size="5%", pad="5%") +im2 = ax2.imshow(E_plot, origin="lower", extent=edge, vmin=vmin, vmax=vmax) +cb2 = fig.colorbar(im2, cax=cax2) +ax2.set_xlabel(r"$z$") +ax2.set_ylabel(r"$x$") +ax2.set_title(r"$E_z$ (theory)") # Save figure fig.tight_layout() -fig.savefig('Langmuir_multi_analysis.png', dpi = 200) +fig.savefig("Langmuir_multi_analysis.png", dpi=200) tolerance_rel = 5e-2 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel # Check relative L-infinity spatial norm of rho/epsilon_0 - div(E) # with current correction (and periodic single box option) or with Vay current deposition @@ -156,43 +170,49 @@ def get_theoretical_field( field, t ): elif vay_deposition: tolerance = 1e-3 if current_correction or vay_deposition: - rho = data[('boxlib','rho')].to_ndarray() - divE = data[('boxlib','divE')].to_ndarray() - error_rel = np.amax( np.abs( divE - rho/epsilon_0 ) ) / np.amax( np.abs( rho/epsilon_0 ) ) + rho = data[("boxlib", "rho")].to_ndarray() + divE = data[("boxlib", "divE")].to_ndarray() + error_rel = np.amax(np.abs(divE - rho / epsilon_0)) / np.amax( + np.abs(rho / epsilon_0) + ) print("Check charge conservation:") print("error_rel = {}".format(error_rel)) print("tolerance = {}".format(tolerance)) - assert( error_rel < tolerance ) + assert error_rel < tolerance if div_cleaning: - ds_old = yt.load('Langmuir_multi_psatd_div_cleaning_plt000038') - ds_mid = yt.load('Langmuir_multi_psatd_div_cleaning_plt000039') - ds_new = yt.load(fn) # this is the last plotfile - - ad_old = ds_old.covering_grid(level = 0, left_edge = ds_old.domain_left_edge, dims = ds_old.domain_dimensions) - ad_mid = ds_mid.covering_grid(level = 0, left_edge = ds_mid.domain_left_edge, dims = ds_mid.domain_dimensions) - ad_new = ds_new.covering_grid(level = 0, left_edge = ds_new.domain_left_edge, dims = ds_new.domain_dimensions) - - rho = ad_mid['rho'].v.squeeze() - divE = ad_mid['divE'].v.squeeze() - F_old = ad_old['F'].v.squeeze() - F_new = ad_new['F'].v.squeeze() + ds_old = yt.load("diags/diag1000038") + ds_mid = yt.load("diags/diag1000039") + ds_new = yt.load(fn) # this is the last plotfile + + ad_old = ds_old.covering_grid( + level=0, left_edge=ds_old.domain_left_edge, dims=ds_old.domain_dimensions + ) + ad_mid = ds_mid.covering_grid( + level=0, left_edge=ds_mid.domain_left_edge, dims=ds_mid.domain_dimensions + ) + ad_new = ds_new.covering_grid( + level=0, left_edge=ds_new.domain_left_edge, dims=ds_new.domain_dimensions + ) + + rho = ad_mid["rho"].v.squeeze() + divE = ad_mid["divE"].v.squeeze() + F_old = ad_old["F"].v.squeeze() + F_new = ad_new["F"].v.squeeze() # Check max norm of error on dF/dt = div(E) - rho/epsilon_0 # (the time interval between the old and new data is 2*dt) dt = 1.203645751e-15 x = F_new - F_old - y = (divE - rho/epsilon_0) * 2 * dt + y = (divE - rho / epsilon_0) * 2 * dt error_rel = np.amax(np.abs(x - y)) / np.amax(np.abs(y)) tolerance = 1e-2 print("Check div(E) cleaning:") print("error_rel = {}".format(error_rel)) print("tolerance = {}".format(tolerance)) - assert(error_rel < tolerance) - -test_name = os.path.split(os.getcwd())[1] + assert error_rel < tolerance -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3) +if re.search("single_precision", test_name): + checksumAPI.evaluate_checksum(test_name, fn, rtol=1.0e-3) else: checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/langmuir/analysis_default_regression.py b/Examples/Tests/langmuir/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/langmuir/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/langmuir/analysis_rz.py b/Examples/Tests/langmuir/analysis_rz.py index e5ae2194123..dd26fd29db7 100755 --- a/Examples/Tests/langmuir/analysis_rz.py +++ b/Examples/Tests/langmuir/analysis_rz.py @@ -19,7 +19,7 @@ import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import yt @@ -29,89 +29,114 @@ import post_processing_utils from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file fn = sys.argv[1] +# test name test_name = os.path.split(os.getcwd())[1] # Parse test name and check if current correction (psatd.current_correction) is applied -current_correction = True if re.search('current_correction', fn) else False +current_correction = True if re.search("current_correction", test_name) else False # Parameters (these parameters must match the parameters in `inputs.multi.rz.rt`) epsilon = 0.01 -n = 2.e24 -w0 = 5.e-6 +n = 2.0e24 +w0 = 5.0e-6 n_osc_z = 2 -rmin = 0e-6; rmax = 20.e-6; Nr = 64 -zmin = -20e-6; zmax = 20.e-6; Nz = 128 +rmin = 0e-6 +rmax = 20.0e-6 +Nr = 64 +zmin = -20e-6 +zmax = 20.0e-6 +Nz = 128 # Wave vector of the wave -k0 = 2.*np.pi*n_osc_z/(zmax-zmin) +k0 = 2.0 * np.pi * n_osc_z / (zmax - zmin) # Plasma frequency -wp = np.sqrt((n*e**2)/(m_e*epsilon_0)) -kp = wp/c +wp = np.sqrt((n * e**2) / (m_e * epsilon_0)) +kp = wp / c -def Er( z, r, epsilon, k0, w0, wp, t) : + +def Er(z, r, epsilon, k0, w0, wp, t): """ Return the radial electric field as an array of the same length as z and r, in the half-plane theta=0 """ - Er_array = \ - epsilon * m_e*c**2/e * 2*r/w0**2 * \ - np.exp( -r**2/w0**2 ) * np.sin( k0*z ) * np.sin( wp*t ) - return( Er_array ) - -def Ez( z, r, epsilon, k0, w0, wp, t) : + Er_array = ( + epsilon + * m_e + * c**2 + / e + * 2 + * r + / w0**2 + * np.exp(-(r**2) / w0**2) + * np.sin(k0 * z) + * np.sin(wp * t) + ) + return Er_array + + +def Ez(z, r, epsilon, k0, w0, wp, t): """ Return the longitudinal electric field as an array of the same length as z and r, in the half-plane theta=0 """ - Ez_array = \ - - epsilon * m_e*c**2/e * k0 * \ - np.exp( -r**2/w0**2 ) * np.cos( k0*z ) * np.sin( wp*t ) - return( Ez_array ) + Ez_array = ( + -epsilon + * m_e + * c**2 + / e + * k0 + * np.exp(-(r**2) / w0**2) + * np.cos(k0 * z) + * np.sin(wp * t) + ) + return Ez_array + # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) # Get cell centered coordinates -dr = (rmax - rmin)/Nr -dz = (zmax - zmin)/Nz -coords = np.indices([Nr, Nz],'d') -rr = rmin + (coords[0] + 0.5)*dr -zz = zmin + (coords[1] + 0.5)*dz +dr = (rmax - rmin) / Nr +dz = (zmax - zmin) / Nz +coords = np.indices([Nr, Nz], "d") +rr = rmin + (coords[0] + 0.5) * dr +zz = zmin + (coords[1] + 0.5) * dz # Check the validity of the fields overall_max_error = 0 -Er_sim = data[('boxlib','Er')].to_ndarray()[:,:,0] +Er_sim = data[("boxlib", "Er")].to_ndarray()[:, :, 0] Er_th = Er(zz, rr, epsilon, k0, w0, wp, t0) -max_error = abs(Er_sim-Er_th).max()/abs(Er_th).max() -print('Er: Max error: %.2e' %(max_error)) -overall_max_error = max( overall_max_error, max_error ) +max_error = abs(Er_sim - Er_th).max() / abs(Er_th).max() +print("Er: Max error: %.2e" % (max_error)) +overall_max_error = max(overall_max_error, max_error) -Ez_sim = data[('boxlib','Ez')].to_ndarray()[:,:,0] +Ez_sim = data[("boxlib", "Ez")].to_ndarray()[:, :, 0] Ez_th = Ez(zz, rr, epsilon, k0, w0, wp, t0) -max_error = abs(Ez_sim-Ez_th).max()/abs(Ez_th).max() -print('Ez: Max error: %.2e' %(max_error)) -overall_max_error = max( overall_max_error, max_error ) +max_error = abs(Ez_sim - Ez_th).max() / abs(Ez_th).max() +print("Ez: Max error: %.2e" % (max_error)) +overall_max_error = max(overall_max_error, max_error) # Plot the last field from the loop (Ez at iteration 40) -plt.subplot2grid( (1,2), (0,0) ) -plt.imshow( Ez_sim ) +plt.subplot2grid((1, 2), (0, 0)) +plt.imshow(Ez_sim) plt.colorbar() -plt.title('Ez, last iteration\n(simulation)') -plt.subplot2grid( (1,2), (0,1) ) -plt.imshow( Ez_th ) +plt.title("Ez, last iteration\n(simulation)") +plt.subplot2grid((1, 2), (0, 1)) +plt.imshow(Ez_th) plt.colorbar() -plt.title('Ez, last iteration\n(theory)') +plt.title("Ez, last iteration\n(theory)") plt.tight_layout() -plt.savefig(test_name+'_analysis.png') +plt.savefig(test_name + "_analysis.png") error_rel = overall_max_error @@ -120,18 +145,18 @@ def Ez( z, r, epsilon, k0, w0, wp, t) : print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel # Check charge conservation (relative L-infinity norm of error) with current correction if current_correction: - divE = data[('boxlib','divE')].to_ndarray() - rho = data[('boxlib','rho')].to_ndarray() / epsilon_0 + divE = data[("boxlib", "divE")].to_ndarray() + rho = data[("boxlib", "rho")].to_ndarray() / epsilon_0 error_rel = np.amax(np.abs(divE - rho)) / max(np.amax(divE), np.amax(rho)) - tolerance = 1.e-9 + tolerance = 1.0e-9 print("Check charge conservation:") print("error_rel = {}".format(error_rel)) print("tolerance = {}".format(tolerance)) - assert( error_rel < tolerance ) + assert error_rel < tolerance ## In the final past of the test, we verify that the diagnostic particle filter function works as @@ -142,17 +167,20 @@ def Ez( z, r, epsilon, k0, w0, wp, t) : parser_filter_fn = "diags/diag_parser_filter000080" parser_filter_expression = "(py-pz < 0) * (r<10e-6) * (z > 0)" -post_processing_utils.check_particle_filter(fn, parser_filter_fn, parser_filter_expression, - dim, species_name) +post_processing_utils.check_particle_filter( + fn, parser_filter_fn, parser_filter_expression, dim, species_name +) uniform_filter_fn = "diags/diag_uniform_filter000080" uniform_filter_expression = "ids%3 == 0" -post_processing_utils.check_particle_filter(fn, uniform_filter_fn, uniform_filter_expression, - dim, species_name) +post_processing_utils.check_particle_filter( + fn, uniform_filter_fn, uniform_filter_expression, dim, species_name +) random_filter_fn = "diags/diag_random_filter000080" random_fraction = 0.66 -post_processing_utils.check_random_filter(fn, random_filter_fn, random_fraction, - dim, species_name) +post_processing_utils.check_random_filter( + fn, random_filter_fn, random_fraction, dim, species_name +) checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/langmuir/inputs_2d b/Examples/Tests/langmuir/inputs_base_2d similarity index 100% rename from Examples/Tests/langmuir/inputs_2d rename to Examples/Tests/langmuir/inputs_base_2d diff --git a/Examples/Tests/langmuir/inputs_3d b/Examples/Tests/langmuir/inputs_base_3d similarity index 100% rename from Examples/Tests/langmuir/inputs_3d rename to Examples/Tests/langmuir/inputs_base_3d diff --git a/Examples/Tests/langmuir/inputs_rz b/Examples/Tests/langmuir/inputs_base_rz similarity index 100% rename from Examples/Tests/langmuir/inputs_rz rename to Examples/Tests/langmuir/inputs_base_rz diff --git a/Examples/Tests/langmuir/inputs_1d b/Examples/Tests/langmuir/inputs_test_1d_langmuir_multi similarity index 95% rename from Examples/Tests/langmuir/inputs_1d rename to Examples/Tests/langmuir/inputs_test_1d_langmuir_multi index af1cf367553..e2fd1da4b94 100644 --- a/Examples/Tests/langmuir/inputs_1d +++ b/Examples/Tests/langmuir/inputs_test_1d_langmuir_multi @@ -27,6 +27,7 @@ warpx.verbose = 1 # Algorithms algo.field_gathering = energy-conserving +algo.current_deposition = esirkepov warpx.use_filter = 0 # Order of particle shape factors @@ -79,6 +80,8 @@ positrons.momentum_function_uz(x,y,z) = "-epsilon * k/kp * cos(k*x) * cos(k*y) * diagnostics.diags_names = diag1 openpmd diag1.intervals = 40 diag1.diag_type = Full +diag1.electrons.variables = z w ux uy uz +diag1.positrons.variables = z w ux uy uz openpmd.intervals = 40 openpmd.diag_type = Full diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi new file mode 100644 index 00000000000..df0189acd91 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi @@ -0,0 +1,7 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.current_deposition = direct +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr new file mode 100644 index 00000000000..8adf73023be --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr @@ -0,0 +1,12 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = ckc +amr.max_level = 1 +amr.ref_ratio = 4 +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.fine_tag_hi = 10.e-6 10.e-6 +warpx.fine_tag_lo = -10.e-6 -10.e-6 +warpx.use_filter = 1 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_anisotropic b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_anisotropic new file mode 100644 index 00000000000..047943373c0 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_anisotropic @@ -0,0 +1,12 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = ckc +amr.max_level = 1 +amr.ref_ratio_vect = 4 2 +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.fine_tag_hi = 10.e-6 10.e-6 +warpx.fine_tag_lo = -10.e-6 -10.e-6 +warpx.use_filter = 1 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_momentum_conserving b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_momentum_conserving new file mode 100644 index 00000000000..201f19f32c2 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_momentum_conserving @@ -0,0 +1,13 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.field_gathering = momentum-conserving +algo.maxwell_solver = ckc +amr.max_level = 1 +amr.ref_ratio = 4 +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.use_filter = 1 +warpx.fine_tag_lo = -10.e-6 -10.e-6 +warpx.fine_tag_hi = 10.e-6 10.e-6 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_psatd b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_psatd new file mode 100644 index 00000000000..cf95a07e2fc --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_mr_psatd @@ -0,0 +1,14 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = psatd +amr.max_level = 1 +amr.ref_ratio = 4 +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium +warpx.fine_tag_hi = 10.e-6 10.e-6 +warpx.fine_tag_lo = -10.e-6 -10.e-6 +warpx.use_filter = 1 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_nodal b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_nodal new file mode 100644 index 00000000000..99d952d79d9 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_nodal @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.current_deposition = direct +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_picmi.py b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_picmi.py new file mode 100755 index 00000000000..dc7fa3a2ba7 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_picmi.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +# +# --- Simple example of Langmuir oscillations in a uniform plasma +# --- in two dimensions + +from pywarpx import picmi + +constants = picmi.constants + +########################## +# physics parameters +########################## + +plasma_density = 1.0e25 +plasma_xmin = 0.0 +plasma_x_velocity = 0.1 * constants.c + +########################## +# numerics parameters +########################## + +# --- Number of time steps +max_steps = 40 +diagnostic_intervals = "::10" + +# --- Grid +nx = 64 +ny = 64 + +xmin = -20.0e-6 +ymin = -20.0e-6 +xmax = +20.0e-6 +ymax = +20.0e-6 + +number_per_cell_each_dim = [2, 2] + +########################## +# physics components +########################## + +uniform_plasma = picmi.UniformDistribution( + density=1.0e25, + upper_bound=[0.0, None, None], + directed_velocity=[0.1 * constants.c, 0.0, 0.0], +) + +electrons = picmi.Species( + particle_type="electron", name="electrons", initial_distribution=uniform_plasma +) + +########################## +# numerics components +########################## + +grid = picmi.Cartesian2DGrid( + number_of_cells=[nx, ny], + lower_bound=[xmin, ymin], + upper_bound=[xmax, ymax], + lower_boundary_conditions=["periodic", "periodic"], + upper_boundary_conditions=["periodic", "periodic"], + moving_window_velocity=[0.0, 0.0, 0.0], + warpx_max_grid_size=32, +) + +solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.0) + +########################## +# diagnostics +########################## + +field_diag1 = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=diagnostic_intervals, + data_list=["Ex", "Jx"], +) + +part_diag1 = picmi.ParticleDiagnostic( + name="diag1", + period=diagnostic_intervals, + species=[electrons], + data_list=["weighting", "ux"], +) + +########################## +# simulation setup +########################## + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + warpx_current_deposition_algo="direct", + warpx_use_filter=0, +) + +sim.add_species( + electrons, + layout=picmi.GriddedLayout( + n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid + ), +) + +sim.add_diagnostic(field_diag1) +sim.add_diagnostic(part_diag1) + +########################## +# simulation run +########################## + +# write_inputs will create an inputs file that can be used to run +# with the compiled version. +sim.write_input_file(file_name="inputs2d_from_PICMI") + +# Alternatively, sim.step will run WarpX, controlling it from Python +sim.step() diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd new file mode 100644 index 00000000000..2386f9e462f --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd @@ -0,0 +1,11 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = psatd +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7071067811865475 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_current_correction b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_current_correction new file mode 100644 index 00000000000..c56572ac957 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_current_correction @@ -0,0 +1,13 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.current_deposition = esirkepov +algo.maxwell_solver = psatd +amr.max_grid_size = 128 +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 1 +warpx.cfl = 0.7071067811865475 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_current_correction_nodal b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_current_correction_nodal new file mode 100644 index 00000000000..5359d8703f3 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_current_correction_nodal @@ -0,0 +1,14 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +amr.max_grid_size = 128 +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 1 +warpx.cfl = 0.7071067811865475 +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_momentum_conserving b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_momentum_conserving new file mode 100644 index 00000000000..694f65fe233 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_momentum_conserving @@ -0,0 +1,12 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.field_gathering = momentum-conserving +algo.maxwell_solver = psatd +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7071067811865475 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_multiJ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_multiJ new file mode 100644 index 00000000000..793f077b0f7 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_multiJ @@ -0,0 +1,12 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = psatd +psatd.J_in_time = linear +psatd.solution_type = first-order +psatd.update_with_rho = 1 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7071067811865475 +warpx.do_multi_J = 1 +warpx.do_multi_J_n_depositions = 2 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_multiJ_nodal b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_multiJ_nodal new file mode 100644 index 00000000000..573337abb76 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_multiJ_nodal @@ -0,0 +1,13 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = psatd +psatd.J_in_time = linear +psatd.solution_type = first-order +psatd.update_with_rho = 1 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7071067811865475 +warpx.do_multi_J = 1 +warpx.do_multi_J_n_depositions = 2 +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_nodal b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_nodal new file mode 100644 index 00000000000..8f02d4f8aae --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_nodal @@ -0,0 +1,13 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7071067811865475 +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition new file mode 100644 index 00000000000..209e48e10e6 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition @@ -0,0 +1,11 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.current_deposition = vay +algo.maxwell_solver = psatd +amr.max_grid_size = 128 +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.cfl = 0.7071067811865475 diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition_nodal b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition_nodal new file mode 100644 index 00000000000..d327c1b37b2 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition_nodal @@ -0,0 +1,12 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.current_deposition = vay +algo.maxwell_solver = psatd +amr.max_grid_size = 128 +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.cfl = 0.7071067811865475 +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition_particle_shape_4 b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition_particle_shape_4 new file mode 100644 index 00000000000..fc5d780cef1 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_2d_langmuir_multi_psatd_vay_deposition_particle_shape_4 @@ -0,0 +1,12 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.current_deposition = vay +algo.maxwell_solver = psatd +algo.particle_shape = 4 +amr.max_grid_size = 128 +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.cfl = 0.7071067811865475 diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi new file mode 100644 index 00000000000..7665a846eef --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi @@ -0,0 +1,2 @@ +# base input parameters +FILE = inputs_base_3d diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_nodal b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_nodal new file mode 100644 index 00000000000..9620cd97f33 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_nodal @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = direct +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_picmi.py b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_picmi.py new file mode 100755 index 00000000000..11ea1843e27 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_picmi.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +# +# --- Simple example of Langmuir oscillations in a uniform plasma + +from pywarpx import picmi + +constants = picmi.constants + +########################## +# physics parameters +########################## + +plasma_density = 1.0e25 +plasma_xmin = 0.0 +plasma_x_velocity = 0.1 * constants.c + +########################## +# numerics parameters +########################## + +# --- Number of time steps +max_steps = 40 +diagnostic_interval = 10 + +# --- Grid +nx = 64 +ny = 64 +nz = 64 + +xmin = -20.0e-6 +ymin = -20.0e-6 +zmin = -20.0e-6 +xmax = +20.0e-6 +ymax = +20.0e-6 +zmax = +20.0e-6 + +number_per_cell_each_dim = [2, 2, 2] + +########################## +# physics components +########################## + +uniform_plasma = picmi.UniformDistribution( + density=1.0e25, + upper_bound=[0.0, None, None], + directed_velocity=[0.1 * constants.c, 0.0, 0.0], +) + +electrons = picmi.Species( + particle_type="electron", name="electrons", initial_distribution=uniform_plasma +) + +########################## +# numerics components +########################## + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["periodic", "periodic", "periodic"], + upper_boundary_conditions=["periodic", "periodic", "periodic"], + moving_window_velocity=[0.0, 0.0, 0.0], + warpx_max_grid_size=32, +) + +solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.0) + +########################## +# diagnostics +########################## + +field_diag1 = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=diagnostic_interval, + data_list=["Ex", "Jx"], +) + +part_diag1 = picmi.ParticleDiagnostic( + name="diag1", + period=diagnostic_interval, + species=[electrons], + data_list=["weighting", "ux"], +) + +########################## +# simulation setup +########################## + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + warpx_current_deposition_algo="direct", +) + +sim.add_species( + electrons, + layout=picmi.GriddedLayout( + n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid + ), +) + +sim.add_diagnostic(field_diag1) +sim.add_diagnostic(part_diag1) + +########################## +# simulation run +########################## + +# write_inputs will create an inputs file that can be used to run +# with the compiled version. +# sim.write_input_file(file_name = 'inputs_from_PICMI') + +# Alternatively, sim.step will run WarpX, controlling it from Python +sim.step() diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd new file mode 100644 index 00000000000..427de2993b1 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.maxwell_solver = psatd +warpx.cfl = 0.5773502691896258 diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_current_correction b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_current_correction new file mode 100644 index 00000000000..86f33d131ce --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_current_correction @@ -0,0 +1,10 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = esirkepov +algo.maxwell_solver = psatd +diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz part_per_cell rho divE +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 1 +warpx.cfl = 0.5773502691896258 diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_current_correction_nodal b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_current_correction_nodal new file mode 100644 index 00000000000..7f67b9100b2 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_current_correction_nodal @@ -0,0 +1,11 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz part_per_cell rho divE +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 1 +warpx.cfl = 0.5773502691896258 +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_div_cleaning b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_div_cleaning new file mode 100644 index 00000000000..d372b789336 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_div_cleaning @@ -0,0 +1,13 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +diag1.intervals = 0, 38:40:1 +diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz part_per_cell rho divE F +psatd.update_with_rho = 1 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.5773502691896258 +warpx.do_dive_cleaning = 1 +warpx.do_divb_cleaning = 1 diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_momentum_conserving b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_momentum_conserving new file mode 100644 index 00000000000..15a4c7d6985 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_momentum_conserving @@ -0,0 +1,7 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.field_gathering = momentum-conserving +algo.maxwell_solver = psatd +warpx.cfl = 0.5773502691896258 diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_multiJ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_multiJ new file mode 100644 index 00000000000..e1cd25cd93d --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_multiJ @@ -0,0 +1,13 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +warpx.cfl = 0.5773502691896258 +warpx.do_multi_J = 1 +warpx.do_multi_J_n_depositions = 2 +psatd.J_in_time = linear +psatd.solution_type = first-order +psatd.update_with_rho = 1 +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_multiJ_nodal b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_multiJ_nodal new file mode 100644 index 00000000000..4a828d2e8b5 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_multiJ_nodal @@ -0,0 +1,14 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +psatd.J_in_time = linear +psatd.solution_type = first-order +psatd.update_with_rho = 1 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.5773502691896258 +warpx.do_multi_J = 1 +warpx.do_multi_J_n_depositions = 2 +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_nodal b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_nodal new file mode 100644 index 00000000000..fd03e00968a --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_nodal @@ -0,0 +1,10 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.5773502691896258 +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_vay_deposition b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_vay_deposition new file mode 100644 index 00000000000..5e2ffa9d407 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_vay_deposition @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = vay +algo.maxwell_solver = psatd +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE +warpx.cfl = 0.5773502691896258 diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_vay_deposition_nodal b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_vay_deposition_nodal new file mode 100644 index 00000000000..df311b0fb3c --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_vay_deposition_nodal @@ -0,0 +1,9 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.current_deposition = vay +algo.maxwell_solver = psatd +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE +warpx.cfl = 0.5773502691896258 +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi new file mode 100644 index 00000000000..45665b67266 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi @@ -0,0 +1,7 @@ +# base input parameters +FILE = inputs_base_rz + +# test input parameters +diag1.dump_rz_modes = 0 +diag1.electrons.variables = x y z w ux uy uz +diag1.ions.variables = x y z w ux uy uz diff --git a/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_picmi.py b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_picmi.py new file mode 100755 index 00000000000..24eedd703d2 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_picmi.py @@ -0,0 +1,327 @@ +#!/usr/bin/env python3 +# +# This is a script that analyses the multimode simulation results. +# This simulates a RZ multimode periodic plasma wave. +# The electric field from the simulation is compared to the analytic value + +import matplotlib + +matplotlib.use("Agg") +import matplotlib.pyplot as plt +import numpy as np + +from pywarpx import fields, picmi + +constants = picmi.constants + +########################## +# physics parameters +########################## + +density = 2.0e24 +epsilon0 = 0.001 * constants.c +epsilon1 = 0.001 * constants.c +epsilon2 = 0.001 * constants.c +w0 = 5.0e-6 +n_osc_z = 3 + +# Plasma frequency +wp = np.sqrt((density * constants.q_e**2) / (constants.m_e * constants.ep0)) +kp = wp / constants.c + +########################## +# numerics parameters +########################## + +nr = 64 +nz = 200 + +rmin = 0.0e0 +zmin = 0.0e0 +rmax = +20.0e-6 +zmax = +40.0e-6 + +# Wave vector of the wave +k0 = 2.0 * np.pi * n_osc_z / (zmax - zmin) + +diagnostic_intervals = 40 + +########################## +# physics components +########################## + +uniform_plasma = picmi.UniformDistribution( + density=density, + upper_bound=[+18e-6, +18e-6, None], + directed_velocity=[0.0, 0.0, 0.0], +) + +momentum_expressions = [ + """+ epsilon0/kp*2*x/w0**2*exp(-(x**2+y**2)/w0**2)*sin(k0*z) + - epsilon1/kp*2/w0*exp(-(x**2+y**2)/w0**2)*sin(k0*z) + + epsilon1/kp*4*x**2/w0**3*exp(-(x**2+y**2)/w0**2)*sin(k0*z) + - epsilon2/kp*8*x/w0**2*exp(-(x**2+y**2)/w0**2)*sin(k0*z) + + epsilon2/kp*8*x*(x**2-y**2)/w0**4*exp(-(x**2+y**2)/w0**2)*sin(k0*z)""", + """+ epsilon0/kp*2*y/w0**2*exp(-(x**2+y**2)/w0**2)*sin(k0*z) + + epsilon1/kp*4*x*y/w0**3*exp(-(x**2+y**2)/w0**2)*sin(k0*z) + + epsilon2/kp*8*y/w0**2*exp(-(x**2+y**2)/w0**2)*sin(k0*z) + + epsilon2/kp*8*y*(x**2-y**2)/w0**4*exp(-(x**2+y**2)/w0**2)*sin(k0*z)""", + """- epsilon0/kp*k0*exp(-(x**2+y**2)/w0**2)*cos(k0*z) + - epsilon1/kp*k0*2*x/w0*exp(-(x**2+y**2)/w0**2)*cos(k0*z) + - epsilon2/kp*k0*4*(x**2-y**2)/w0**2*exp(-(x**2+y**2)/w0**2)*cos(k0*z)""", +] + +analytic_plasma = picmi.AnalyticDistribution( + density_expression=density, + upper_bound=[+18e-6, +18e-6, None], + epsilon0=epsilon0, + epsilon1=epsilon1, + epsilon2=epsilon2, + kp=kp, + k0=k0, + w0=w0, + momentum_expressions=momentum_expressions, +) + +electrons = picmi.Species( + particle_type="electron", name="electrons", initial_distribution=analytic_plasma +) +protons = picmi.Species( + particle_type="proton", name="protons", initial_distribution=uniform_plasma +) + +########################## +# numerics components +########################## + +grid = picmi.CylindricalGrid( + number_of_cells=[nr, nz], + n_azimuthal_modes=3, + lower_bound=[rmin, zmin], + upper_bound=[rmax, zmax], + lower_boundary_conditions=["none", "periodic"], + upper_boundary_conditions=["none", "periodic"], + lower_boundary_conditions_particles=["none", "periodic"], + upper_boundary_conditions_particles=["absorbing", "periodic"], + moving_window_velocity=[0.0, 0.0], + warpx_max_grid_size=64, +) + +solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.0) + +########################## +# diagnostics +########################## + +field_diag1 = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=diagnostic_intervals, + data_list=["Er", "Ez", "Bt", "Jr", "Jz", "part_per_cell"], +) + +part_diag1 = picmi.ParticleDiagnostic( + name="diag1", + period=diagnostic_intervals, + species=[electrons], + data_list=["weighting", "momentum"], +) + +########################## +# simulation setup +########################## + +sim = picmi.Simulation( + solver=solver, + max_steps=40, + verbose=1, + warpx_current_deposition_algo="esirkepov", + warpx_field_gathering_algo="energy-conserving", + warpx_particle_pusher_algo="boris", + warpx_use_filter=0, +) + +sim.add_species( + electrons, + layout=picmi.GriddedLayout(n_macroparticle_per_cell=[2, 16, 2], grid=grid), +) +sim.add_species( + protons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[2, 16, 2], grid=grid) +) + +sim.add_diagnostic(field_diag1) +sim.add_diagnostic(part_diag1) + +########################## +# simulation run +########################## + +# write_inputs will create an inputs file that can be used to run +# with the compiled version. +# sim.write_input_file(file_name='inputsrz_from_PICMI') + +# Alternatively, sim.step will run WarpX, controlling it from Python +sim.step() + + +# Below is WarpX specific code to check the results. + + +def calcEr(z, r, k0, w0, wp, t, epsilons): + """ + Return the radial electric field as an array + of the same length as z and r, in the half-plane theta=0 + """ + Er_array = ( + epsilons[0] + * constants.m_e + * constants.c + / constants.q_e + * 2 + * r + / w0**2 + * np.exp(-(r**2) / w0**2) + * np.sin(k0 * z) + * np.sin(wp * t) + - epsilons[1] + * constants.m_e + * constants.c + / constants.q_e + * 2 + / w0 + * np.exp(-(r**2) / w0**2) + * np.sin(k0 * z) + * np.sin(wp * t) + + epsilons[1] + * constants.m_e + * constants.c + / constants.q_e + * 4 + * r**2 + / w0**3 + * np.exp(-(r**2) / w0**2) + * np.sin(k0 * z) + * np.sin(wp * t) + - epsilons[2] + * constants.m_e + * constants.c + / constants.q_e + * 8 + * r + / w0**2 + * np.exp(-(r**2) / w0**2) + * np.sin(k0 * z) + * np.sin(wp * t) + + epsilons[2] + * constants.m_e + * constants.c + / constants.q_e + * 8 + * r**3 + / w0**4 + * np.exp(-(r**2) / w0**2) + * np.sin(k0 * z) + * np.sin(wp * t) + ) + return Er_array + + +def calcEz(z, r, k0, w0, wp, t, epsilons): + """ + Return the longitudinal electric field as an array + of the same length as z and r, in the half-plane theta=0 + """ + Ez_array = ( + -epsilons[0] + * constants.m_e + * constants.c + / constants.q_e + * k0 + * np.exp(-(r**2) / w0**2) + * np.cos(k0 * z) + * np.sin(wp * t) + - epsilons[1] + * constants.m_e + * constants.c + / constants.q_e + * k0 + * 2 + * r + / w0 + * np.exp(-(r**2) / w0**2) + * np.cos(k0 * z) + * np.sin(wp * t) + - epsilons[2] + * constants.m_e + * constants.c + / constants.q_e + * k0 + * 4 + * r**2 + / w0**2 + * np.exp(-(r**2) / w0**2) + * np.cos(k0 * z) + * np.sin(wp * t) + ) + return Ez_array + + +# Current time of the simulation +t0 = sim.extension.warpx.gett_new(0) + +# Get the raw field data. Note that these are the real and imaginary +# parts of the fields for each azimuthal mode. +Ex_sim_wrap = fields.ExWrapper() +Ez_sim_wrap = fields.EzWrapper() +Ex_sim_modes = Ex_sim_wrap[...] +Ez_sim_modes = Ez_sim_wrap[...] + +rr_Er = Ex_sim_wrap.mesh("r") +zz_Er = Ex_sim_wrap.mesh("z") +rr_Ez = Ez_sim_wrap.mesh("r") +zz_Ez = Ez_sim_wrap.mesh("z") + +rr_Er = rr_Er[:, np.newaxis] * np.ones(zz_Er.shape[0])[np.newaxis, :] +zz_Er = zz_Er[np.newaxis, :] * np.ones(rr_Er.shape[0])[:, np.newaxis] +rr_Ez = rr_Ez[:, np.newaxis] * np.ones(zz_Ez.shape[0])[np.newaxis, :] +zz_Ez = zz_Ez[np.newaxis, :] * np.ones(rr_Ez.shape[0])[:, np.newaxis] + +# Sum the real components to get the field along x-axis (theta = 0) +Er_sim = Ex_sim_modes[:, :, 0] + np.sum(Ex_sim_modes[:, :, 1::2], axis=2) +Ez_sim = Ez_sim_modes[:, :, 0] + np.sum(Ez_sim_modes[:, :, 1::2], axis=2) + +# The analytical solutions +Er_th = calcEr(zz_Er, rr_Er, k0, w0, wp, t0, [epsilon0, epsilon1, epsilon2]) +Ez_th = calcEz(zz_Ez, rr_Ez, k0, w0, wp, t0, [epsilon0, epsilon1, epsilon2]) + +max_error_Er = abs(Er_sim - Er_th).max() / abs(Er_th).max() +max_error_Ez = abs(Ez_sim - Ez_th).max() / abs(Ez_th).max() +print("Max error Er %e" % max_error_Er) +print("Max error Ez %e" % max_error_Ez) + +# Plot the last field from the loop (Er at iteration 40) +fig, ax = plt.subplots(3) +im = ax[0].imshow(Er_sim, aspect="auto", origin="lower") +fig.colorbar(im, ax=ax[0], orientation="vertical") +ax[0].set_title("Er, last iteration (simulation)") +ax[1].imshow(Er_th, aspect="auto", origin="lower") +fig.colorbar(im, ax=ax[1], orientation="vertical") +ax[1].set_title("Er, last iteration (theory)") +im = ax[2].imshow((Er_sim - Er_th) / abs(Er_th).max(), aspect="auto", origin="lower") +fig.colorbar(im, ax=ax[2], orientation="vertical") +ax[2].set_title("Er, last iteration (difference)") +plt.savefig("langmuir_multi_rz_multimode_analysis_Er.png") + +fig, ax = plt.subplots(3) +im = ax[0].imshow(Ez_sim, aspect="auto", origin="lower") +fig.colorbar(im, ax=ax[0], orientation="vertical") +ax[0].set_title("Ez, last iteration (simulation)") +ax[1].imshow(Ez_th, aspect="auto", origin="lower") +fig.colorbar(im, ax=ax[1], orientation="vertical") +ax[1].set_title("Ez, last iteration (theory)") +im = ax[2].imshow((Ez_sim - Ez_th) / abs(Ez_th).max(), aspect="auto", origin="lower") +fig.colorbar(im, ax=ax[2], orientation="vertical") +ax[2].set_title("Ez, last iteration (difference)") +plt.savefig("langmuir_multi_rz_multimode_analysis_Ez.png") + +assert max(max_error_Er, max_error_Ez) < 0.02 diff --git a/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd new file mode 100644 index 00000000000..5537335629d --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd @@ -0,0 +1,15 @@ +# base input parameters +FILE = inputs_base_rz + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +diag1.dump_rz_modes = 0 +diag1.electrons.variables = x y z w ux uy uz +diag1.ions.variables = x y z w ux uy uz +electrons.random_theta = 0 +ions.random_theta = 0 +psatd.current_correction = 0 +psatd.update_with_rho = 1 +warpx.abort_on_warning_threshold = medium +warpx.do_dive_cleaning = 0 diff --git a/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd_current_correction b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd_current_correction new file mode 100644 index 00000000000..fac41cea4cd --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd_current_correction @@ -0,0 +1,16 @@ +# base input parameters +FILE = inputs_base_rz + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +amr.max_grid_size = 128 +diag1.dump_rz_modes = 0 +diag1.electrons.variables = x y z w ux uy uz +diag1.fields_to_plot = jr jz Er Ez Bt rho divE +diag1.ions.variables = x y z w ux uy uz +electrons.random_theta = 0 +ions.random_theta = 0 +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 1 +warpx.do_dive_cleaning = 0 diff --git a/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd_multiJ b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd_multiJ new file mode 100644 index 00000000000..0ff617af8eb --- /dev/null +++ b/Examples/Tests/langmuir/inputs_test_rz_langmuir_multi_psatd_multiJ @@ -0,0 +1,22 @@ +# base input parameters +FILE = inputs_base_rz + +# test input parameters +algo.current_deposition = direct +algo.maxwell_solver = psatd +amr.max_grid_size = 32 +diag1.dump_rz_modes = 0 +diag1.electrons.variables = x y z w ux uy uz +diag1.ions.variables = x y z w ux uy uz +electrons.num_particles_per_cell_each_dim = 2 4 2 +electrons.random_theta = 0 +ions.num_particles_per_cell_each_dim = 2 4 2 +ions.random_theta = 0 +psatd.current_correction = 0 +psatd.update_with_rho = 1 +warpx.abort_on_warning_threshold = medium +warpx.do_dive_cleaning = 0 +warpx.do_multi_J = 1 +warpx.do_multi_J_n_depositions = 4 +warpx.n_rz_azimuthal_modes = 2 +warpx.use_filter = 1 diff --git a/Examples/Tests/langmuir_fluids/CMakeLists.txt b/Examples/Tests/langmuir_fluids/CMakeLists.txt new file mode 100644 index 00000000000..054e9c80d3a --- /dev/null +++ b/Examples/Tests/langmuir_fluids/CMakeLists.txt @@ -0,0 +1,42 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_langmuir_fluid # name + 1 # dims + 2 # nprocs + inputs_test_1d_langmuir_fluid # inputs + analysis_1d.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +add_warpx_test( + test_2d_langmuir_fluid # name + 2 # dims + 2 # nprocs + inputs_test_2d_langmuir_fluid # inputs + analysis_2d.py # analysis + diags/diag1000080 # output + OFF # dependency +) + +add_warpx_test( + test_3d_langmuir_fluid # name + 3 # dims + 2 # nprocs + inputs_test_3d_langmuir_fluid # inputs + analysis_3d.py # analysis + diags/diag1000040 # output + OFF # dependency +) + +add_warpx_test( + test_rz_langmuir_fluid # name + RZ # dims + 2 # nprocs + inputs_test_rz_langmuir_fluid # inputs + analysis_rz.py # analysis + diags/diag1000080 # output + OFF # dependency +) diff --git a/Examples/Tests/langmuir_fluids/analysis_1d.py b/Examples/Tests/langmuir_fluids/analysis_1d.py index 2d1a8f69d1d..fa4566b6173 100755 --- a/Examples/Tests/langmuir_fluids/analysis_1d.py +++ b/Examples/Tests/langmuir_fluids/analysis_1d.py @@ -16,7 +16,7 @@ import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import yt @@ -25,7 +25,7 @@ import numpy as np from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -33,105 +33,120 @@ # Parameters (these parameters must match the parameters in `inputs.multi.rt`) epsilon = 0.01 -n = 4.e24 +n = 4.0e24 n_osc_z = 2 -zmin = -20e-6; zmax = 20.e-6; Nz = 128 +zmin = -20e-6 +zmax = 20.0e-6 +Nz = 128 # Wave vector of the wave -kz = 2.*np.pi*n_osc_z/(zmax-zmin) +kz = 2.0 * np.pi * n_osc_z / (zmax - zmin) # Plasma frequency -wp = np.sqrt((n*e**2)/(m_e*epsilon_0)) +wp = np.sqrt((n * e**2) / (m_e * epsilon_0)) -k = {'Ez':kz,'Jz':kz} -cos = {'Ez':(1,1,0), 'Jz':(1,1,0)} -cos_rho = {'rho': (1,1,1)} +k = {"Ez": kz, "Jz": kz} +cos = {"Ez": (1, 1, 0), "Jz": (1, 1, 0)} +cos_rho = {"rho": (1, 1, 1)} -def get_contribution( is_cos, k ): - du = (zmax-zmin)/Nz - u = zmin + du*( 0.5 + np.arange(Nz) ) + +def get_contribution(is_cos, k): + du = (zmax - zmin) / Nz + u = zmin + du * (0.5 + np.arange(Nz)) if is_cos == 1: - return( np.cos(k*u) ) + return np.cos(k * u) else: - return( np.sin(k*u) ) + return np.sin(k * u) + -def get_theoretical_field( field, t ): - amplitude = epsilon * (m_e*c**2*k[field])/e * np.sin(wp*t) +def get_theoretical_field(field, t): + amplitude = epsilon * (m_e * c**2 * k[field]) / e * np.sin(wp * t) cos_flag = cos[field] - z_contribution = get_contribution( cos_flag[2], kz ) + z_contribution = get_contribution(cos_flag[2], kz) E = amplitude * z_contribution - return( E ) + return E + -def get_theoretical_J_field( field, t ): +def get_theoretical_J_field(field, t): # wpdt/2 accounts for the Yee halfstep offset of the current - dt = t / 80 # SPECIFIC to config parameters! - amplitude = - epsilon_0 * wp * epsilon * (m_e*c**2*k[field])/e * np.cos(wp*t-wp*dt/2) + dt = t / 80 # SPECIFIC to config parameters! + amplitude = ( + -epsilon_0 + * wp + * epsilon + * (m_e * c**2 * k[field]) + / e + * np.cos(wp * t - wp * dt / 2) + ) cos_flag = cos[field] - z_contribution = get_contribution( cos_flag[2], kz ) + z_contribution = get_contribution(cos_flag[2], kz) - J = amplitude * z_contribution + J = amplitude * z_contribution - return( J ) + return J -def get_theoretical_rho_field( field, t ): - amplitude = epsilon_0 * epsilon * (m_e*c**2*(kz*kz))/e * np.sin(wp*t) + +def get_theoretical_rho_field(field, t): + amplitude = epsilon_0 * epsilon * (m_e * c**2 * (kz * kz)) / e * np.sin(wp * t) cos_flag = cos_rho[field] - z_contribution = get_contribution( cos_flag[2], kz) + z_contribution = get_contribution(cos_flag[2], kz) rho = amplitude * z_contribution - return( rho ) + return rho + # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) # Check the validity of the fields error_rel = 0 -for field in ['Ez']: - E_sim = data[('mesh',field)].to_ndarray()[:,0,0] +for field in ["Ez"]: + E_sim = data[("mesh", field)].to_ndarray()[:, 0, 0] E_th = get_theoretical_field(field, t0) - max_error = abs(E_sim-E_th).max()/abs(E_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(E_sim - E_th).max() / abs(E_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Check the validity of the currents -for field in ['Jz']: - J_sim = data[('mesh',field)].to_ndarray()[:,0,0] +for field in ["Jz"]: + J_sim = data[("mesh", field)].to_ndarray()[:, 0, 0] J_th = get_theoretical_J_field(field, t0) - max_error = abs(J_sim-J_th).max()/abs(J_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(J_sim - J_th).max() / abs(J_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Check the validity of the charge -for field in ['rho']: - rho_sim = data[('boxlib',field)].to_ndarray()[:,0,0] +for field in ["rho"]: + rho_sim = data[("boxlib", field)].to_ndarray()[:, 0, 0] rho_th = get_theoretical_rho_field(field, t0) - max_error = abs(rho_sim-rho_th).max()/abs(rho_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(rho_sim - rho_th).max() / abs(rho_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Plot the last field from the loop (Ez at iteration 80) -plt.subplot2grid( (1,2), (0,0) ) -plt.plot( E_sim ) -#plt.colorbar() -plt.title('Ez, last iteration\n(simulation)') -plt.subplot2grid( (1,2), (0,1) ) -plt.plot( E_th ) -#plt.colorbar() -plt.title('Ez, last iteration\n(theory)') +plt.subplot2grid((1, 2), (0, 0)) +plt.plot(E_sim) +# plt.colorbar() +plt.title("Ez, last iteration\n(simulation)") +plt.subplot2grid((1, 2), (0, 1)) +plt.plot(E_th) +# plt.colorbar() +plt.title("Ez, last iteration\n(theory)") plt.tight_layout() -plt.savefig('langmuir_fluid_multi_1d_analysis.png') +plt.savefig("langmuir_fluid_multi_1d_analysis.png") tolerance_rel = 0.05 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/langmuir_fluids/analysis_2d.py b/Examples/Tests/langmuir_fluids/analysis_2d.py index f7244f87137..d7ecca986e4 100755 --- a/Examples/Tests/langmuir_fluids/analysis_2d.py +++ b/Examples/Tests/langmuir_fluids/analysis_2d.py @@ -25,7 +25,7 @@ import numpy as np from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -33,127 +33,150 @@ # Parameters (these parameters must match the parameters in `inputs.multi.rt`) epsilon = 0.01 -n = 4.e24 +n = 4.0e24 n_osc_x = 2 n_osc_z = 2 -xmin = -20e-6; xmax = 20.e-6; Nx = 128 -zmin = -20e-6; zmax = 20.e-6; Nz = 128 +xmin = -20e-6 +xmax = 20.0e-6 +Nx = 128 +zmin = -20e-6 +zmax = 20.0e-6 +Nz = 128 # Wave vector of the wave -kx = 2.*np.pi*n_osc_x/(xmax-xmin) -kz = 2.*np.pi*n_osc_z/(zmax-zmin) +kx = 2.0 * np.pi * n_osc_x / (xmax - xmin) +kz = 2.0 * np.pi * n_osc_z / (zmax - zmin) # Plasma frequency -wp = np.sqrt((n*e**2)/(m_e*epsilon_0)) +wp = np.sqrt((n * e**2) / (m_e * epsilon_0)) -k = {'Ex':kx, 'Ez':kz, 'Jx':kx, 'Jz':kz} -cos = {'Ex': (0,1,1), 'Ez':(1,1,0),'Jx': (0,1,1), 'Jz':(1,1,0)} -cos_rho = {'rho': (1,1,1)} +k = {"Ex": kx, "Ez": kz, "Jx": kx, "Jz": kz} +cos = {"Ex": (0, 1, 1), "Ez": (1, 1, 0), "Jx": (0, 1, 1), "Jz": (1, 1, 0)} +cos_rho = {"rho": (1, 1, 1)} -def get_contribution( is_cos, k ): - du = (xmax-xmin)/Nx - u = xmin + du*( 0.5 + np.arange(Nx) ) + +def get_contribution(is_cos, k): + du = (xmax - xmin) / Nx + u = xmin + du * (0.5 + np.arange(Nx)) if is_cos == 1: - return( np.cos(k*u) ) + return np.cos(k * u) else: - return( np.sin(k*u) ) + return np.sin(k * u) + -def get_theoretical_field( field, t ): - amplitude = epsilon * (m_e*c**2*k[field])/e * np.sin(wp*t) +def get_theoretical_field(field, t): + amplitude = epsilon * (m_e * c**2 * k[field]) / e * np.sin(wp * t) cos_flag = cos[field] - x_contribution = get_contribution( cos_flag[0], kx ) - z_contribution = get_contribution( cos_flag[2], kz ) + x_contribution = get_contribution(cos_flag[0], kx) + z_contribution = get_contribution(cos_flag[2], kz) + + E = amplitude * x_contribution[:, np.newaxis] * z_contribution[np.newaxis, :] - E = amplitude * x_contribution[:, np.newaxis ] \ - * z_contribution[np.newaxis, :] + return E - return( E ) -def get_theoretical_J_field( field, t ): +def get_theoretical_J_field(field, t): # wpdt/2 accounts for the Yee halfstep offset of the current - dt = t / 40 # SPECIFIC to config parameters! - amplitude = - epsilon_0 * wp * epsilon * (m_e*c**2*k[field])/e * np.cos(wp*t-wp*dt/2) + dt = t / 40 # SPECIFIC to config parameters! + amplitude = ( + -epsilon_0 + * wp + * epsilon + * (m_e * c**2 * k[field]) + / e + * np.cos(wp * t - wp * dt / 2) + ) cos_flag = cos[field] - x_contribution = get_contribution( cos_flag[0], kx ) - z_contribution = get_contribution( cos_flag[2], kz ) + x_contribution = get_contribution(cos_flag[0], kx) + z_contribution = get_contribution(cos_flag[2], kz) - J = amplitude * x_contribution[:, np.newaxis] \ - * z_contribution[np.newaxis, :] + J = amplitude * x_contribution[:, np.newaxis] * z_contribution[np.newaxis, :] - return( J ) + return J -def get_theoretical_rho_field( field, t ): - amplitude = epsilon_0 * epsilon * (m_e*c**2*(kx*kx+kz*kz))/e * np.sin(wp*t) + +def get_theoretical_rho_field(field, t): + amplitude = ( + epsilon_0 * epsilon * (m_e * c**2 * (kx * kx + kz * kz)) / e * np.sin(wp * t) + ) cos_flag = cos_rho[field] - x_contribution = get_contribution( cos_flag[0], kx ) - z_contribution = get_contribution( cos_flag[2], kz ) + x_contribution = get_contribution(cos_flag[0], kx) + z_contribution = get_contribution(cos_flag[2], kz) + + rho = amplitude * x_contribution[:, np.newaxis] * z_contribution[np.newaxis, :] - rho = amplitude * x_contribution[:, np.newaxis] \ - * z_contribution[ np.newaxis, :] + return rho - return( rho ) # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level = 0, left_edge = ds.domain_left_edge, dims = ds.domain_dimensions) -edge = np.array([(ds.domain_left_edge[1]).item(), (ds.domain_right_edge[1]).item(), \ - (ds.domain_left_edge[0]).item(), (ds.domain_right_edge[0]).item()]) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +edge = np.array( + [ + (ds.domain_left_edge[1]).item(), + (ds.domain_right_edge[1]).item(), + (ds.domain_left_edge[0]).item(), + (ds.domain_right_edge[0]).item(), + ] +) # Check the validity of the fields error_rel = 0 -for field in ['Ex', 'Ez']: - E_sim = data[('mesh',field)].to_ndarray()[:,:,0] +for field in ["Ex", "Ez"]: + E_sim = data[("mesh", field)].to_ndarray()[:, :, 0] E_th = get_theoretical_field(field, t0) - max_error = abs(E_sim-E_th).max()/abs(E_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(E_sim - E_th).max() / abs(E_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Check the validity of the currents -for field in ['Jx', 'Jz']: - J_sim = data[('mesh',field)].to_ndarray()[:,:,0] +for field in ["Jx", "Jz"]: + J_sim = data[("mesh", field)].to_ndarray()[:, :, 0] J_th = get_theoretical_J_field(field, t0) - max_error = abs(J_sim-J_th).max()/abs(J_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(J_sim - J_th).max() / abs(J_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Check the validity of the charge -for field in ['rho']: - rho_sim = data[('boxlib',field)].to_ndarray()[:,:,0] +for field in ["rho"]: + rho_sim = data[("boxlib", field)].to_ndarray()[:, :, 0] rho_th = get_theoretical_rho_field(field, t0) - max_error = abs(rho_sim-rho_th).max()/abs(rho_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(rho_sim - rho_th).max() / abs(rho_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Plot the last field from the loop (Ez at iteration 40) -fig, (ax1, ax2) = plt.subplots(1, 2, dpi = 100) +fig, (ax1, ax2) = plt.subplots(1, 2, dpi=100) # First plot vmin = E_sim.min() vmax = E_sim.max() -cax1 = make_axes_locatable(ax1).append_axes('right', size = '5%', pad = '5%') -im1 = ax1.imshow(E_sim, origin = 'lower', extent = edge, vmin = vmin, vmax = vmax) -cb1 = fig.colorbar(im1, cax = cax1) -ax1.set_xlabel(r'$z$') -ax1.set_ylabel(r'$x$') -ax1.set_title(r'$E_z$ (sim)') +cax1 = make_axes_locatable(ax1).append_axes("right", size="5%", pad="5%") +im1 = ax1.imshow(E_sim, origin="lower", extent=edge, vmin=vmin, vmax=vmax) +cb1 = fig.colorbar(im1, cax=cax1) +ax1.set_xlabel(r"$z$") +ax1.set_ylabel(r"$x$") +ax1.set_title(r"$E_z$ (sim)") # Second plot vmin = E_th.min() vmax = E_th.max() -cax2 = make_axes_locatable(ax2).append_axes('right', size = '5%', pad = '5%') -im2 = ax2.imshow(E_th, origin = 'lower', extent = edge, vmin = vmin, vmax = vmax) -cb2 = fig.colorbar(im2, cax = cax2) -ax2.set_xlabel(r'$z$') -ax2.set_ylabel(r'$x$') -ax2.set_title(r'$E_z$ (theory)') +cax2 = make_axes_locatable(ax2).append_axes("right", size="5%", pad="5%") +im2 = ax2.imshow(E_th, origin="lower", extent=edge, vmin=vmin, vmax=vmax) +cb2 = fig.colorbar(im2, cax=cax2) +ax2.set_xlabel(r"$z$") +ax2.set_ylabel(r"$x$") +ax2.set_title(r"$E_z$ (theory)") # Save figure fig.tight_layout() -fig.savefig('Langmuir_fluid_multi_2d_analysis.png', dpi = 200) +fig.savefig("Langmuir_fluid_multi_2d_analysis.png", dpi=200) tolerance_rel = 0.05 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/langmuir_fluids/analysis_3d.py b/Examples/Tests/langmuir_fluids/analysis_3d.py index 686907f103a..321b528b6cb 100755 --- a/Examples/Tests/langmuir_fluids/analysis_3d.py +++ b/Examples/Tests/langmuir_fluids/analysis_3d.py @@ -26,7 +26,7 @@ import numpy as np from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -34,146 +34,188 @@ # Parameters (these parameters must match the parameters in `inputs.multi.rt`) epsilon = 0.01 -n = 4.e24 +n = 4.0e24 n_osc_x = 2 n_osc_y = 2 n_osc_z = 2 -lo = [-20.e-6, -20.e-6, -20.e-6] -hi = [ 20.e-6, 20.e-6, 20.e-6] +lo = [-20.0e-6, -20.0e-6, -20.0e-6] +hi = [20.0e-6, 20.0e-6, 20.0e-6] Ncell = [64, 64, 64] # Wave vector of the wave -kx = 2.*np.pi*n_osc_x/(hi[0]-lo[0]) -ky = 2.*np.pi*n_osc_y/(hi[1]-lo[1]) -kz = 2.*np.pi*n_osc_z/(hi[2]-lo[2]) +kx = 2.0 * np.pi * n_osc_x / (hi[0] - lo[0]) +ky = 2.0 * np.pi * n_osc_y / (hi[1] - lo[1]) +kz = 2.0 * np.pi * n_osc_z / (hi[2] - lo[2]) # Plasma frequency -wp = np.sqrt((n*e**2)/(m_e*epsilon_0)) - -k = {'Ex':kx, 'Ey':ky, 'Ez':kz, 'Jx':kx, 'Jy':ky, 'Jz':kz} -cos = {'Ex': (0,1,1), 'Ey':(1,0,1), 'Ez':(1,1,0),'Jx': (0,1,1), 'Jy':(1,0,1), 'Jz':(1,1,0)} -cos_rho = {'rho': (1,1,1)} - -def get_contribution( is_cos, k, idim ): - du = (hi[idim]-lo[idim])/Ncell[idim] - u = lo[idim] + du*( 0.5 + np.arange(Ncell[idim]) ) +wp = np.sqrt((n * e**2) / (m_e * epsilon_0)) + +k = {"Ex": kx, "Ey": ky, "Ez": kz, "Jx": kx, "Jy": ky, "Jz": kz} +cos = { + "Ex": (0, 1, 1), + "Ey": (1, 0, 1), + "Ez": (1, 1, 0), + "Jx": (0, 1, 1), + "Jy": (1, 0, 1), + "Jz": (1, 1, 0), +} +cos_rho = {"rho": (1, 1, 1)} + + +def get_contribution(is_cos, k, idim): + du = (hi[idim] - lo[idim]) / Ncell[idim] + u = lo[idim] + du * (0.5 + np.arange(Ncell[idim])) if is_cos[idim] == 1: - return( np.cos(k*u) ) + return np.cos(k * u) else: - return( np.sin(k*u) ) + return np.sin(k * u) -def get_theoretical_field( field, t ): - amplitude = epsilon * (m_e*c**2*k[field])/e * np.sin(wp*t) + +def get_theoretical_field(field, t): + amplitude = epsilon * (m_e * c**2 * k[field]) / e * np.sin(wp * t) cos_flag = cos[field] - x_contribution = get_contribution( cos_flag, kx, 0 ) - y_contribution = get_contribution( cos_flag, ky, 1 ) - z_contribution = get_contribution( cos_flag, kz, 2 ) + x_contribution = get_contribution(cos_flag, kx, 0) + y_contribution = get_contribution(cos_flag, ky, 1) + z_contribution = get_contribution(cos_flag, kz, 2) + + E = ( + amplitude + * x_contribution[:, np.newaxis, np.newaxis] + * y_contribution[np.newaxis, :, np.newaxis] + * z_contribution[np.newaxis, np.newaxis, :] + ) - E = amplitude * x_contribution[:, np.newaxis, np.newaxis] \ - * y_contribution[np.newaxis, :, np.newaxis] \ - * z_contribution[np.newaxis, np.newaxis, :] + return E - return( E ) -def get_theoretical_J_field( field, t ): +def get_theoretical_J_field(field, t): # wpdt/2 accounts for the Yee halfstep offset of the current - dt = t / 40 # SPECIFIC to config parameters! - amplitude = - epsilon_0 * wp * epsilon * (m_e*c**2*k[field])/e * np.cos(wp*t-wp*dt/2) + dt = t / 40 # SPECIFIC to config parameters! + amplitude = ( + -epsilon_0 + * wp + * epsilon + * (m_e * c**2 * k[field]) + / e + * np.cos(wp * t - wp * dt / 2) + ) cos_flag = cos[field] - x_contribution = get_contribution( cos_flag, kx, 0 ) - y_contribution = get_contribution( cos_flag, ky, 1 ) - z_contribution = get_contribution( cos_flag, kz, 2 ) - - J = amplitude * x_contribution[:, np.newaxis, np.newaxis] \ - * y_contribution[np.newaxis, :, np.newaxis] \ - * z_contribution[np.newaxis, np.newaxis, :] - - return( J ) - -def get_theoretical_rho_field( field, t ): - amplitude = epsilon_0 * epsilon * (m_e*c**2*(kx*kx+ky*ky+kz*kz))/e * np.sin(wp*t) + x_contribution = get_contribution(cos_flag, kx, 0) + y_contribution = get_contribution(cos_flag, ky, 1) + z_contribution = get_contribution(cos_flag, kz, 2) + + J = ( + amplitude + * x_contribution[:, np.newaxis, np.newaxis] + * y_contribution[np.newaxis, :, np.newaxis] + * z_contribution[np.newaxis, np.newaxis, :] + ) + + return J + + +def get_theoretical_rho_field(field, t): + amplitude = ( + epsilon_0 + * epsilon + * (m_e * c**2 * (kx * kx + ky * ky + kz * kz)) + / e + * np.sin(wp * t) + ) cos_flag = cos_rho[field] - x_contribution = get_contribution( cos_flag, kx, 0 ) - y_contribution = get_contribution( cos_flag, ky, 1 ) - z_contribution = get_contribution( cos_flag, kz, 2 ) + x_contribution = get_contribution(cos_flag, kx, 0) + y_contribution = get_contribution(cos_flag, ky, 1) + z_contribution = get_contribution(cos_flag, kz, 2) + + rho = ( + amplitude + * x_contribution[:, np.newaxis, np.newaxis] + * y_contribution[np.newaxis, :, np.newaxis] + * z_contribution[np.newaxis, np.newaxis, :] + ) - rho = amplitude * x_contribution[:, np.newaxis, np.newaxis] \ - * y_contribution[np.newaxis, :, np.newaxis] \ - * z_contribution[np.newaxis, np.newaxis, :] + return rho - return( rho ) # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level = 0, left_edge = ds.domain_left_edge, dims = ds.domain_dimensions) -edge = np.array([(ds.domain_left_edge[2]).item(), (ds.domain_right_edge[2]).item(), \ - (ds.domain_left_edge[0]).item(), (ds.domain_right_edge[0]).item()]) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +edge = np.array( + [ + (ds.domain_left_edge[2]).item(), + (ds.domain_right_edge[2]).item(), + (ds.domain_left_edge[0]).item(), + (ds.domain_right_edge[0]).item(), + ] +) # Check the validity of the fields error_rel = 0 -for field in ['Ex', 'Ey', 'Ez']: - E_sim = data[('mesh',field)].to_ndarray() +for field in ["Ex", "Ey", "Ez"]: + E_sim = data[("mesh", field)].to_ndarray() E_th = get_theoretical_field(field, t0) - max_error = abs(E_sim-E_th).max()/abs(E_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(E_sim - E_th).max() / abs(E_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Check the validity of the currents -for field in ['Jx', 'Jy', 'Jz']: - J_sim = data[('mesh',field)].to_ndarray() +for field in ["Jx", "Jy", "Jz"]: + J_sim = data[("mesh", field)].to_ndarray() J_th = get_theoretical_J_field(field, t0) - max_error = abs(J_sim-J_th).max()/abs(J_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(J_sim - J_th).max() / abs(J_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Check the validity of the charge -for field in ['rho']: - rho_sim = data[('boxlib',field)].to_ndarray() +for field in ["rho"]: + rho_sim = data[("boxlib", field)].to_ndarray() rho_th = get_theoretical_rho_field(field, t0) - max_error = abs(rho_sim-rho_th).max()/abs(rho_th).max() - print('%s: Max error: %.2e' %(field,max_error)) - error_rel = max( error_rel, max_error ) + max_error = abs(rho_sim - rho_th).max() / abs(rho_th).max() + print("%s: Max error: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) # Plot the last field from the loop (Ez at iteration 40) -fig, (ax1, ax2) = plt.subplots(1, 2, dpi = 100) +fig, (ax1, ax2) = plt.subplots(1, 2, dpi=100) # First plot (slice at y=0) -E_plot = E_sim[:,Ncell[1]//2+1,:] +E_plot = E_sim[:, Ncell[1] // 2 + 1, :] vmin = E_plot.min() vmax = E_plot.max() -cax1 = make_axes_locatable(ax1).append_axes('right', size = '5%', pad = '5%') -im1 = ax1.imshow(E_plot, origin = 'lower', extent = edge, vmin = vmin, vmax = vmax) -cb1 = fig.colorbar(im1, cax = cax1) -ax1.set_xlabel(r'$z$') -ax1.set_ylabel(r'$x$') -ax1.set_title(r'$E_z$ (sim)') +cax1 = make_axes_locatable(ax1).append_axes("right", size="5%", pad="5%") +im1 = ax1.imshow(E_plot, origin="lower", extent=edge, vmin=vmin, vmax=vmax) +cb1 = fig.colorbar(im1, cax=cax1) +ax1.set_xlabel(r"$z$") +ax1.set_ylabel(r"$x$") +ax1.set_title(r"$E_z$ (sim)") # Second plot (slice at y=0) -E_plot = E_th[:,Ncell[1]//2+1,:] +E_plot = E_th[:, Ncell[1] // 2 + 1, :] vmin = E_plot.min() vmax = E_plot.max() -cax2 = make_axes_locatable(ax2).append_axes('right', size = '5%', pad = '5%') -im2 = ax2.imshow(E_plot, origin = 'lower', extent = edge, vmin = vmin, vmax = vmax) -cb2 = fig.colorbar(im2, cax = cax2) -ax2.set_xlabel(r'$z$') -ax2.set_ylabel(r'$x$') -ax2.set_title(r'$E_z$ (theory)') +cax2 = make_axes_locatable(ax2).append_axes("right", size="5%", pad="5%") +im2 = ax2.imshow(E_plot, origin="lower", extent=edge, vmin=vmin, vmax=vmax) +cb2 = fig.colorbar(im2, cax=cax2) +ax2.set_xlabel(r"$z$") +ax2.set_ylabel(r"$x$") +ax2.set_title(r"$E_z$ (theory)") # Save figure fig.tight_layout() -fig.savefig('Langmuir_fluid_multi_analysis.png', dpi = 200) +fig.savefig("Langmuir_fluid_multi_analysis.png", dpi=200) tolerance_rel = 5e-2 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, rtol=1.0e-3) else: checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/langmuir_fluids/analysis_rz.py b/Examples/Tests/langmuir_fluids/analysis_rz.py index 108d054e75a..f629ddc6626 100755 --- a/Examples/Tests/langmuir_fluids/analysis_rz.py +++ b/Examples/Tests/langmuir_fluids/analysis_rz.py @@ -19,7 +19,7 @@ import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import yt @@ -28,7 +28,7 @@ import numpy as np from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -37,130 +37,185 @@ test_name = os.path.split(os.getcwd())[1] # Parse test name and check if current correction (psatd.current_correction) is applied -current_correction = True if re.search('current_correction', fn) else False +current_correction = True if re.search("current_correction", fn) else False # Parameters (these parameters must match the parameters in `inputs.multi.rz.rt`) epsilon = 0.01 -n = 2.e24 -w0 = 5.e-6 +n = 2.0e24 +w0 = 5.0e-6 n_osc_z = 2 -rmin = 0e-6; rmax = 20.e-6; Nr = 64 -zmin = -20e-6; zmax = 20.e-6; Nz = 128 +rmin = 0e-6 +rmax = 20.0e-6 +Nr = 64 +zmin = -20e-6 +zmax = 20.0e-6 +Nz = 128 # Wave vector of the wave -k0 = 2.*np.pi*n_osc_z/(zmax-zmin) +k0 = 2.0 * np.pi * n_osc_z / (zmax - zmin) # Plasma frequency -wp = np.sqrt((n*e**2)/(m_e*epsilon_0)) -kp = wp/c +wp = np.sqrt((n * e**2) / (m_e * epsilon_0)) +kp = wp / c -def Er( z, r, epsilon, k0, w0, wp, t) : + +def Er(z, r, epsilon, k0, w0, wp, t): """ Return the radial electric field as an array of the same length as z and r, in the half-plane theta=0 """ - Er_array = \ - epsilon * m_e*c**2/e * 2*r/w0**2 * \ - np.exp( -r**2/w0**2 ) * np.sin( k0*z ) * np.sin( wp*t ) - return( Er_array ) - -def Ez( z, r, epsilon, k0, w0, wp, t) : + Er_array = ( + epsilon + * m_e + * c**2 + / e + * 2 + * r + / w0**2 + * np.exp(-(r**2) / w0**2) + * np.sin(k0 * z) + * np.sin(wp * t) + ) + return Er_array + + +def Ez(z, r, epsilon, k0, w0, wp, t): """ Return the longitudinal electric field as an array of the same length as z and r, in the half-plane theta=0 """ - Ez_array = \ - - epsilon * m_e*c**2/e * k0 * \ - np.exp( -r**2/w0**2 ) * np.cos( k0*z ) * np.sin( wp*t ) - return( Ez_array ) - -def Jr( z, r, epsilon, k0, w0, wp, t) : + Ez_array = ( + -epsilon + * m_e + * c**2 + / e + * k0 + * np.exp(-(r**2) / w0**2) + * np.cos(k0 * z) + * np.sin(wp * t) + ) + return Ez_array + + +def Jr(z, r, epsilon, k0, w0, wp, t): """ Return the radial current density as an array of the same length as z and r, in the half-plane theta=0 """ - dt = t / 80 # SPECIFIC to config parameters! - Jr_array = \ - - epsilon_0 * epsilon * m_e*c**2/e * 2*r/w0**2 * \ - np.exp( -r**2/w0**2 ) * np.sin( k0*z ) * np.cos( wp*t -wp*dt/2) * wp #phase_error = wp*dt/2 - return( Jr_array ) - -def Jz( z, r, epsilon, k0, w0, wp, t) : + dt = t / 80 # SPECIFIC to config parameters! + Jr_array = ( + -epsilon_0 + * epsilon + * m_e + * c**2 + / e + * 2 + * r + / w0**2 + * np.exp(-(r**2) / w0**2) + * np.sin(k0 * z) + * np.cos(wp * t - wp * dt / 2) + * wp + ) # phase_error = wp*dt/2 + return Jr_array + + +def Jz(z, r, epsilon, k0, w0, wp, t): """ Return the longitudinal current density as an array of the same length as z and r, in the half-plane theta=0 """ - dt = t / 80 # SPECIFIC to config parameters! - Jz_array = \ - epsilon_0 * epsilon * m_e*c**2/e * k0 * \ - np.exp( -r**2/w0**2 ) * np.cos( k0*z ) * np.cos( wp*t -wp*dt/2) * wp #phase_error = wp*dt/2 - return( Jz_array ) - -def rho( z, r, epsilon, k0, w0, wp, t) : + dt = t / 80 # SPECIFIC to config parameters! + Jz_array = ( + epsilon_0 + * epsilon + * m_e + * c**2 + / e + * k0 + * np.exp(-(r**2) / w0**2) + * np.cos(k0 * z) + * np.cos(wp * t - wp * dt / 2) + * wp + ) # phase_error = wp*dt/2 + return Jz_array + + +def rho(z, r, epsilon, k0, w0, wp, t): """ Return the charge density as an array of the same length as z and r, in the half-plane theta=0 """ - rho_array = \ - epsilon_0 * epsilon * m_e*c**2/e * np.sin( wp*t ) * np.sin( k0*z ) * np.exp( -r**2/w0**2 ) * \ - ((4.0/(w0**2))*(1 - (r**2)/(w0**2)) + k0**2) - return( rho_array ) + rho_array = ( + epsilon_0 + * epsilon + * m_e + * c**2 + / e + * np.sin(wp * t) + * np.sin(k0 * z) + * np.exp(-(r**2) / w0**2) + * ((4.0 / (w0**2)) * (1 - (r**2) / (w0**2)) + k0**2) + ) + return rho_array + # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) # Get cell centered coordinates -dr = (rmax - rmin)/Nr -dz = (zmax - zmin)/Nz -coords = np.indices([Nr, Nz],'d') -rr = rmin + (coords[0] + 0.5)*dr -zz = zmin + (coords[1] + 0.5)*dz +dr = (rmax - rmin) / Nr +dz = (zmax - zmin) / Nz +coords = np.indices([Nr, Nz], "d") +rr = rmin + (coords[0] + 0.5) * dr +zz = zmin + (coords[1] + 0.5) * dz # Check the validity of the fields overall_max_error = 0 -Er_sim = data[('boxlib','Er')].to_ndarray()[:,:,0] +Er_sim = data[("boxlib", "Er")].to_ndarray()[:, :, 0] Er_th = Er(zz, rr, epsilon, k0, w0, wp, t0) -max_error = abs(Er_sim-Er_th).max()/abs(Er_th).max() -print('Er: Max error: %.2e' %(max_error)) -overall_max_error = max( overall_max_error, max_error ) +max_error = abs(Er_sim - Er_th).max() / abs(Er_th).max() +print("Er: Max error: %.2e" % (max_error)) +overall_max_error = max(overall_max_error, max_error) -Ez_sim = data[('boxlib','Ez')].to_ndarray()[:,:,0] +Ez_sim = data[("boxlib", "Ez")].to_ndarray()[:, :, 0] Ez_th = Ez(zz, rr, epsilon, k0, w0, wp, t0) -max_error = abs(Ez_sim-Ez_th).max()/abs(Ez_th).max() -print('Ez: Max error: %.2e' %(max_error)) -overall_max_error = max( overall_max_error, max_error ) +max_error = abs(Ez_sim - Ez_th).max() / abs(Ez_th).max() +print("Ez: Max error: %.2e" % (max_error)) +overall_max_error = max(overall_max_error, max_error) -Jr_sim = data[('boxlib','jr')].to_ndarray()[:,:,0] +Jr_sim = data[("boxlib", "jr")].to_ndarray()[:, :, 0] Jr_th = Jr(zz, rr, epsilon, k0, w0, wp, t0) -max_error = abs(Jr_sim-Jr_th).max()/abs(Jr_th).max() -print('Jr: Max error: %.2e' %(max_error)) -overall_max_error = max( overall_max_error, max_error ) +max_error = abs(Jr_sim - Jr_th).max() / abs(Jr_th).max() +print("Jr: Max error: %.2e" % (max_error)) +overall_max_error = max(overall_max_error, max_error) -Jz_sim = data[('boxlib','jz')].to_ndarray()[:,:,0] +Jz_sim = data[("boxlib", "jz")].to_ndarray()[:, :, 0] Jz_th = Jz(zz, rr, epsilon, k0, w0, wp, t0) -max_error = abs(Jz_sim-Jz_th).max()/abs(Jz_th).max() -print('Jz: Max error: %.2e' %(max_error)) -overall_max_error = max( overall_max_error, max_error ) +max_error = abs(Jz_sim - Jz_th).max() / abs(Jz_th).max() +print("Jz: Max error: %.2e" % (max_error)) +overall_max_error = max(overall_max_error, max_error) -rho_sim = data[('boxlib','rho')].to_ndarray()[:,:,0] +rho_sim = data[("boxlib", "rho")].to_ndarray()[:, :, 0] rho_th = rho(zz, rr, epsilon, k0, w0, wp, t0) -max_error = abs(rho_sim-rho_th).max()/abs(rho_th).max() -print('rho: Max error: %.2e' %(max_error)) -overall_max_error = max( overall_max_error, max_error ) +max_error = abs(rho_sim - rho_th).max() / abs(rho_th).max() +print("rho: Max error: %.2e" % (max_error)) +overall_max_error = max(overall_max_error, max_error) # Plot the last field from the loop (Ez at iteration 40) -plt.subplot2grid( (1,2), (0,0) ) -plt.imshow( Ez_sim ) +plt.subplot2grid((1, 2), (0, 0)) +plt.imshow(Ez_sim) plt.colorbar() -plt.title('Ez, last iteration\n(simulation)') -plt.subplot2grid( (1,2), (0,1) ) -plt.imshow( Ez_th ) +plt.title("Ez, last iteration\n(simulation)") +plt.subplot2grid((1, 2), (0, 1)) +plt.imshow(Ez_th) plt.colorbar() -plt.title('Ez, last iteration\n(theory)') +plt.title("Ez, last iteration\n(theory)") plt.tight_layout() -plt.savefig(test_name+'_analysis.png') +plt.savefig(test_name + "_analysis.png") error_rel = overall_max_error @@ -169,6 +224,6 @@ def rho( z, r, epsilon, k0, w0, wp, t) : print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/langmuir_fluids/inputs_1d b/Examples/Tests/langmuir_fluids/inputs_test_1d_langmuir_fluid similarity index 100% rename from Examples/Tests/langmuir_fluids/inputs_1d rename to Examples/Tests/langmuir_fluids/inputs_test_1d_langmuir_fluid diff --git a/Examples/Tests/langmuir_fluids/inputs_2d b/Examples/Tests/langmuir_fluids/inputs_test_2d_langmuir_fluid similarity index 100% rename from Examples/Tests/langmuir_fluids/inputs_2d rename to Examples/Tests/langmuir_fluids/inputs_test_2d_langmuir_fluid diff --git a/Examples/Tests/langmuir_fluids/inputs_3d b/Examples/Tests/langmuir_fluids/inputs_test_3d_langmuir_fluid similarity index 100% rename from Examples/Tests/langmuir_fluids/inputs_3d rename to Examples/Tests/langmuir_fluids/inputs_test_3d_langmuir_fluid diff --git a/Examples/Tests/langmuir_fluids/inputs_rz b/Examples/Tests/langmuir_fluids/inputs_test_rz_langmuir_fluid similarity index 100% rename from Examples/Tests/langmuir_fluids/inputs_rz rename to Examples/Tests/langmuir_fluids/inputs_test_rz_langmuir_fluid diff --git a/Examples/Tests/larmor/CMakeLists.txt b/Examples/Tests/larmor/CMakeLists.txt new file mode 100644 index 00000000000..6a3368a4fca --- /dev/null +++ b/Examples/Tests/larmor/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_larmor # name + 2 # dims + 2 # nprocs + inputs_test_2d_larmor # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) diff --git a/Examples/Tests/larmor/analysis_default_regression.py b/Examples/Tests/larmor/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/larmor/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/larmor/inputs_2d_mr b/Examples/Tests/larmor/inputs_test_2d_larmor similarity index 99% rename from Examples/Tests/larmor/inputs_2d_mr rename to Examples/Tests/larmor/inputs_test_2d_larmor index 5d7af3d67a4..76e4f76ee22 100644 --- a/Examples/Tests/larmor/inputs_2d_mr +++ b/Examples/Tests/larmor/inputs_test_2d_larmor @@ -1,5 +1,5 @@ # Maximum number of time steps -max_step = 400 +max_step = 10 # number of grid points amr.n_cell = 64 64 diff --git a/Examples/Tests/laser_injection/CMakeLists.txt b/Examples/Tests/laser_injection/CMakeLists.txt new file mode 100644 index 00000000000..cec027deb70 --- /dev/null +++ b/Examples/Tests/laser_injection/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_laser_injection # name + 1 # dims + 2 # nprocs + inputs_test_1d_laser_injection # inputs + analysis_1d.py # analysis + diags/diag1000240 # output + OFF # dependency +) + +add_warpx_test( + test_2d_laser_injection # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_injection # inputs + analysis_2d.py # analysis + diags/diag1000240 # output + OFF # dependency +) + +add_warpx_test( + test_3d_laser_injection # name + 3 # dims + 2 # nprocs + inputs_test_3d_laser_injection # inputs + analysis_3d.py # analysis + diags/diag1000020 # output + OFF # dependency +) diff --git a/Examples/Tests/laser_injection/analysis_1d.py b/Examples/Tests/laser_injection/analysis_1d.py index 5aca707ff3a..9215125427d 100755 --- a/Examples/Tests/laser_injection/analysis_1d.py +++ b/Examples/Tests/laser_injection/analysis_1d.py @@ -18,12 +18,12 @@ import matplotlib import yt -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np from scipy.signal import hilbert -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Maximum acceptable error for this test @@ -33,102 +33,114 @@ small_num = 1.0e-8 # Physical parameters -um = 1.e-6 -fs = 1.e-15 +um = 1.0e-6 +fs = 1.0e-15 c = 299792458 # Parameters of the gaussian beam -wavelength = 1.*um -w0 = 5.*um -tt = 10.*fs -t_c = 24.*fs +wavelength = 1.0 * um +w0 = 5.0 * um +tt = 10.0 * fs +t_c = 24.0 * fs E_max = 4e12 # laser direction -dir_vector = np.array([0,0,1.0]) +dir_vector = np.array([0, 0, 1.0]) dir_vector /= np.linalg.norm(dir_vector) # polarization vector -pol_vector = np.array([1.0,1.0,0.0]) +pol_vector = np.array([1.0, 1.0, 0.0]) pol_vector /= np.linalg.norm(pol_vector) + # Calculates the envelope of a Gaussian beam -def gauss_env(T,Z): - '''Function to compute the theory for the envelope - ''' - inv_tau2 = 1./tt/tt - exp_arg = - inv_tau2 / c/c * (Z-T*c)*(Z-T*c) +def gauss_env(T, Z): + """Function to compute the theory for the envelope""" + inv_tau2 = 1.0 / tt / tt + exp_arg = -inv_tau2 / c / c * (Z - T * c) * (Z - T * c) return E_max * np.real(np.exp(exp_arg)) + # Checks envelope and central frequency for a given laser component -def check_component(data, component, t_env_theory, coeff,Z,dz): +def check_component(data, component, t_env_theory, coeff, Z, dz): print("*** Checking " + component + " ***") - field = data['boxlib', component].v.squeeze() + field = data["boxlib", component].v.squeeze() env = abs(hilbert(field)) - env_theory = t_env_theory*np.abs(coeff) + env_theory = t_env_theory * np.abs(coeff) # Plot results - fig = plt.figure(figsize=(12,6)) + fig = plt.figure(figsize=(12, 6)) ax1 = fig.add_subplot(221) - ax1.set_title('PIC field') - ax1.plot(Z,field) + ax1.set_title("PIC field") + ax1.plot(Z, field) ax2 = fig.add_subplot(222) - ax2.set_title('PIC envelope') - ax2.plot(Z,env) + ax2.set_title("PIC envelope") + ax2.plot(Z, env) ax3 = fig.add_subplot(223) - ax3.set_title('Theory envelope') - ax3.plot(Z,env_theory, label="theory") - ax3.plot(Z,env, label="simulation") + ax3.set_title("Theory envelope") + ax3.plot(Z, env_theory, label="theory") + ax3.plot(Z, env, label="simulation") ax3.legend(loc="upper right") ax4 = fig.add_subplot(224) - ax4.set_title('Difference') - ax4.plot(Z,env-env_theory) + ax4.set_title("Difference") + ax4.plot(Z, env - env_theory) plt.tight_layout() - plt.savefig("plt_" + component + ".png", bbox_inches='tight') + plt.savefig("plt_" + component + ".png", bbox_inches="tight") - if(np.abs(coeff) < small_num): + if np.abs(coeff) < small_num: is_field_zero = np.sum(np.abs(env)) < small_num - if is_field_zero : + if is_field_zero: print("[OK] Field component expected to be 0 is ~ 0") - else : + else: print("[FAIL] Field component expected to be 0 is NOT ~ 0") - assert(is_field_zero) + assert is_field_zero print("******\n") return fft_field = np.fft.fft(field) - freq_cols = np.fft.fftfreq(fft_field.shape[0],dz/c) + freq_cols = np.fft.fftfreq(fft_field.shape[0], dz / c) pos_max = np.unravel_index(np.abs(fft_field).argmax(), fft_field.shape) freq = np.abs(freq_cols[pos_max[0]]) - exp_freq = c/wavelength + exp_freq = c / wavelength - relative_error_freq = np.abs(freq-exp_freq)/exp_freq + relative_error_freq = np.abs(freq - exp_freq) / exp_freq is_freq_ok = relative_error_freq < relative_error_threshold - if is_freq_ok : - print("[OK] Relative error frequency: {:6.3f} %".format(relative_error_freq*100)) - else : - print("[FAIL] Relative error frequency: {:6.3f} %".format(relative_error_freq*100)) - assert(is_freq_ok) + if is_freq_ok: + print( + "[OK] Relative error frequency: {:6.3f} %".format(relative_error_freq * 100) + ) + else: + print( + "[FAIL] Relative error frequency: {:6.3f} %".format( + relative_error_freq * 100 + ) + ) + assert is_freq_ok print("******\n") - relative_error_env = np.sum(np.abs(env-env_theory)) / np.sum(np.abs(env_theory)) + relative_error_env = np.sum(np.abs(env - env_theory)) / np.sum(np.abs(env_theory)) is_env_ok = relative_error_env < relative_error_threshold - if is_env_ok : - print("[OK] Relative error envelope: {:6.3f} %".format(relative_error_env*100)) - else : - print("[FAIL] Relative error envelope: {:6.3f} %".format(relative_error_env*100)) - assert(is_env_ok) + if is_env_ok: + print( + "[OK] Relative error envelope: {:6.3f} %".format(relative_error_env * 100) + ) + else: + print( + "[FAIL] Relative error envelope: {:6.3f} %".format(relative_error_env * 100) + ) + assert is_env_ok + def check_laser(filename): ds = yt.load(filename) @@ -136,20 +148,26 @@ def check_laser(filename): # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. - if 'force_periodicity' in dir(ds): ds.force_periodicity() + if "force_periodicity" in dir(ds): + ds.force_periodicity() z = np.linspace( - ds.domain_left_edge[0].v, - ds.domain_right_edge[0].v, - ds.domain_dimensions[0]) + ds.domain_left_edge[0].v, ds.domain_right_edge[0].v, ds.domain_dimensions[0] + ) - dz = (ds.domain_right_edge[0].v-ds.domain_left_edge[0].v)/(ds.domain_dimensions[0]-1) + dz = (ds.domain_right_edge[0].v - ds.domain_left_edge[0].v) / ( + ds.domain_dimensions[0] - 1 + ) # Compute the theory for envelope - env_theory = gauss_env(+t_c-ds.current_time.to_value(),z)+gauss_env(-t_c+ds.current_time.to_value(),z) + env_theory = gauss_env(+t_c - ds.current_time.to_value(), z) + gauss_env( + -t_c + ds.current_time.to_value(), z + ) # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) + all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions + ) b_vector = np.cross(dir_vector, pol_vector) @@ -160,12 +178,14 @@ def check_laser(filename): pol_vector[2], b_vector[0], b_vector[1], - b_vector[2]] + b_vector[2], + ] - field_facts = [1, 1, 1, 1/c, 1/c, 1/c] + field_facts = [1, 1, 1, 1 / c, 1 / c, 1 / c] for comp, coeff, field_fact in zip(components, coeffs, field_facts): - check_component(all_data_level_0, comp, field_fact*env_theory, coeff, z, dz) + check_component(all_data_level_0, comp, field_fact * env_theory, coeff, z, dz) + def main(): filename_end = sys.argv[1] @@ -175,5 +195,6 @@ def main(): test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename_end) + if __name__ == "__main__": main() diff --git a/Examples/Tests/laser_injection/analysis_2d.py b/Examples/Tests/laser_injection/analysis_2d.py index 4424fe134bc..c6548e8be1d 100755 --- a/Examples/Tests/laser_injection/analysis_2d.py +++ b/Examples/Tests/laser_injection/analysis_2d.py @@ -22,14 +22,14 @@ import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np import yt from mpl_toolkits.axes_grid1 import make_axes_locatable from scipy.signal import hilbert -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Maximum acceptable error for this test @@ -39,147 +39,166 @@ small_num = 1.0e-8 # Physical parameters -um = 1.e-6 -fs = 1.e-15 +um = 1.0e-6 +fs = 1.0e-15 c = 299792458 # Parameters of the gaussian beam -wavelength = 1.*um -w0 = 5.*um -tt = 10.*fs -x_c = 10.*um -t_c = 24.*fs +wavelength = 1.0 * um +w0 = 5.0 * um +tt = 10.0 * fs +x_c = 10.0 * um +t_c = 24.0 * fs # foc_dist = 13.109*um (not actually used) E_max = 4e12 # laser direction -dir_vector = np.array([2.,0,1.0]) +dir_vector = np.array([2.0, 0, 1.0]) dir_vector /= np.linalg.norm(dir_vector) -rot_angle = np.arctan(dir_vector[2]/dir_vector[0]) +rot_angle = np.arctan(dir_vector[2] / dir_vector[0]) # polarization vector -pol_vector = np.array([1.0,1.0,-2.0]) +pol_vector = np.array([1.0, 1.0, -2.0]) pol_vector /= np.linalg.norm(pol_vector) + # Calculates the envelope of a Gaussian beam -def gauss_env(T,XX,ZZ): - '''Function to compute the theory for the envelope - ''' +def gauss_env(T, XX, ZZ): + """Function to compute the theory for the envelope""" - Z = np.cos(rot_angle)*(XX-x_c) + np.sin(rot_angle)*ZZ - X = -np.sin(rot_angle)*(XX-x_c) + np.cos(rot_angle)*ZZ + Z = np.cos(rot_angle) * (XX - x_c) + np.sin(rot_angle) * ZZ + X = -np.sin(rot_angle) * (XX - x_c) + np.cos(rot_angle) * ZZ - inv_tau2 = 1./tt/tt - inv_w_2 = 1.0/(w0*w0) - exp_arg = - (X*X)*inv_w_2 - inv_tau2 / c/c * (Z-T*c)*(Z-T*c) + inv_tau2 = 1.0 / tt / tt + inv_w_2 = 1.0 / (w0 * w0) + exp_arg = -(X * X) * inv_w_2 - inv_tau2 / c / c * (Z - T * c) * (Z - T * c) return E_max * np.real(np.exp(exp_arg)) + # Checks envelope and central frequency for a given laser component -def check_component(data, component, t_env_theory, coeff, X,Z,dx,dz): +def check_component(data, component, t_env_theory, coeff, X, Z, dx, dz): print("*** Checking " + component + " ***") - field = data['boxlib', component].v.squeeze() + field = data["boxlib", component].v.squeeze() env = abs(hilbert(field)) - env_theory = t_env_theory*np.abs(coeff) + env_theory = t_env_theory * np.abs(coeff) # Plot results - fig = plt.figure(figsize=(12,6)) - - ax1 = fig.add_subplot(221, aspect='equal') - ax1.set_title('PIC field') - p1 = ax1.pcolormesh(X,Z,field) - cax1 = make_axes_locatable(ax1).append_axes('right', size='5%', pad=0.05) - fig.colorbar(p1, cax=cax1, orientation='vertical') - - ax2 = fig.add_subplot(222, aspect='equal') - ax2.set_title('PIC envelope') - p2 = ax2.pcolormesh(X,Z,env) - cax2 = make_axes_locatable(ax2).append_axes('right', size='5%', pad=0.05) - fig.colorbar(p2, cax=cax2, orientation='vertical') - - ax3 = fig.add_subplot(223, aspect='equal') - ax3.set_title('Theory envelope') - p3 = ax3.pcolormesh(X,Z,env_theory) - cax3 = make_axes_locatable(ax3).append_axes('right', size='5%', pad=0.05) - fig.colorbar(p3, cax=cax3, orientation='vertical') - - ax4 = fig.add_subplot(224, aspect='equal') - ax4.set_title('Difference') - p4 = ax4.pcolormesh(X,Z,env-env_theory) - cax4 = make_axes_locatable(ax4).append_axes('right', size='5%', pad=0.05) - fig.colorbar(p4, cax=cax4, orientation='vertical') + fig = plt.figure(figsize=(12, 6)) + + ax1 = fig.add_subplot(221, aspect="equal") + ax1.set_title("PIC field") + p1 = ax1.pcolormesh(X, Z, field) + cax1 = make_axes_locatable(ax1).append_axes("right", size="5%", pad=0.05) + fig.colorbar(p1, cax=cax1, orientation="vertical") + + ax2 = fig.add_subplot(222, aspect="equal") + ax2.set_title("PIC envelope") + p2 = ax2.pcolormesh(X, Z, env) + cax2 = make_axes_locatable(ax2).append_axes("right", size="5%", pad=0.05) + fig.colorbar(p2, cax=cax2, orientation="vertical") + + ax3 = fig.add_subplot(223, aspect="equal") + ax3.set_title("Theory envelope") + p3 = ax3.pcolormesh(X, Z, env_theory) + cax3 = make_axes_locatable(ax3).append_axes("right", size="5%", pad=0.05) + fig.colorbar(p3, cax=cax3, orientation="vertical") + + ax4 = fig.add_subplot(224, aspect="equal") + ax4.set_title("Difference") + p4 = ax4.pcolormesh(X, Z, env - env_theory) + cax4 = make_axes_locatable(ax4).append_axes("right", size="5%", pad=0.05) + fig.colorbar(p4, cax=cax4, orientation="vertical") plt.tight_layout() - plt.savefig("plt_" + component + ".png", bbox_inches='tight') + plt.savefig("plt_" + component + ".png", bbox_inches="tight") - if(np.abs(coeff) < small_num): + if np.abs(coeff) < small_num: is_field_zero = np.sum(np.abs(env)) < small_num - if is_field_zero : + if is_field_zero: print("[OK] Field component expected to be 0 is ~ 0") - else : + else: print("[FAIL] Field component expected to be 0 is NOT ~ 0") - assert(is_field_zero) + assert is_field_zero print("******\n") return - relative_error_env = np.sum(np.abs(env-env_theory)) / np.sum(np.abs(env_theory)) + relative_error_env = np.sum(np.abs(env - env_theory)) / np.sum(np.abs(env_theory)) is_env_ok = relative_error_env < relative_error_threshold - if is_env_ok : - print("[OK] Relative error envelope: {:6.3f} %".format(relative_error_env*100)) - else : - print("[FAIL] Relative error envelope: {:6.3f} %".format(relative_error_env*100)) - assert(is_env_ok) + if is_env_ok: + print( + "[OK] Relative error envelope: {:6.3f} %".format(relative_error_env * 100) + ) + else: + print( + "[FAIL] Relative error envelope: {:6.3f} %".format(relative_error_env * 100) + ) + assert is_env_ok fft_field = np.fft.fft2(field) - freq_rows = np.fft.fftfreq(fft_field.shape[0],dx/c) - freq_cols = np.fft.fftfreq(fft_field.shape[1],dz/c) + freq_rows = np.fft.fftfreq(fft_field.shape[0], dx / c) + freq_cols = np.fft.fftfreq(fft_field.shape[1], dz / c) pos_max = np.unravel_index(np.abs(fft_field).argmax(), fft_field.shape) - freq = np.sqrt((freq_rows[pos_max[0]])**2 + (freq_cols[pos_max[1]]**2)) - exp_freq = c/wavelength + freq = np.sqrt((freq_rows[pos_max[0]]) ** 2 + (freq_cols[pos_max[1]] ** 2)) + exp_freq = c / wavelength - relative_error_freq = np.abs(freq-exp_freq)/exp_freq + relative_error_freq = np.abs(freq - exp_freq) / exp_freq is_freq_ok = relative_error_freq < relative_error_threshold - if is_freq_ok : - print("[OK] Relative error frequency: {:6.3f} %".format(relative_error_freq*100)) - else : - print("[FAIL] Relative error frequency: {:6.3f} %".format(relative_error_freq*100)) - assert(is_freq_ok) + if is_freq_ok: + print( + "[OK] Relative error frequency: {:6.3f} %".format(relative_error_freq * 100) + ) + else: + print( + "[FAIL] Relative error frequency: {:6.3f} %".format( + relative_error_freq * 100 + ) + ) + assert is_freq_ok print("******\n") + def check_laser(filename): ds = yt.load(filename) # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. - if 'force_periodicity' in dir(ds): ds.force_periodicity() + if "force_periodicity" in dir(ds): + ds.force_periodicity() x = np.linspace( - ds.domain_left_edge[0].v, - ds.domain_right_edge[0].v, - ds.domain_dimensions[0]) + ds.domain_left_edge[0].v, ds.domain_right_edge[0].v, ds.domain_dimensions[0] + ) - dx = (ds.domain_right_edge[0].v-ds.domain_left_edge[0].v)/(ds.domain_dimensions[0]-1) + dx = (ds.domain_right_edge[0].v - ds.domain_left_edge[0].v) / ( + ds.domain_dimensions[0] - 1 + ) z = np.linspace( - ds.domain_left_edge[1].v, - ds.domain_right_edge[1].v, - ds.domain_dimensions[1]) + ds.domain_left_edge[1].v, ds.domain_right_edge[1].v, ds.domain_dimensions[1] + ) - dz = (ds.domain_right_edge[1].v-ds.domain_left_edge[1].v)/(ds.domain_dimensions[1]-1) + dz = (ds.domain_right_edge[1].v - ds.domain_left_edge[1].v) / ( + ds.domain_dimensions[1] - 1 + ) - X, Z = np.meshgrid(x, z, indexing='ij') + X, Z = np.meshgrid(x, z, indexing="ij") # Compute the theory for envelope - env_theory = gauss_env(+t_c-ds.current_time.to_value(),X,Z)+gauss_env(-t_c+ds.current_time.to_value(),X,Z) + env_theory = gauss_env(+t_c - ds.current_time.to_value(), X, Z) + gauss_env( + -t_c + ds.current_time.to_value(), X, Z + ) # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) + all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions + ) b_vector = np.cross(dir_vector, pol_vector) @@ -190,12 +209,16 @@ def check_laser(filename): pol_vector[2], b_vector[0], b_vector[1], - b_vector[2]] + b_vector[2], + ] - field_facts = [1, 1, 1, 1/c, 1/c, 1/c] + field_facts = [1, 1, 1, 1 / c, 1 / c, 1 / c] for comp, coeff, field_fact in zip(components, coeffs, field_facts): - check_component(all_data_level_0, comp, field_fact*env_theory, coeff, X, Z, dx, dz) + check_component( + all_data_level_0, comp, field_fact * env_theory, coeff, X, Z, dx, dz + ) + def main(): filename_end = sys.argv[1] @@ -205,5 +228,6 @@ def main(): test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename_end) + if __name__ == "__main__": main() diff --git a/Examples/Tests/laser_injection/analysis_laser.py b/Examples/Tests/laser_injection/analysis_3d.py similarity index 83% rename from Examples/Tests/laser_injection/analysis_laser.py rename to Examples/Tests/laser_injection/analysis_3d.py index 8dde8d6e96d..bf2a03e342c 100755 --- a/Examples/Tests/laser_injection/analysis_laser.py +++ b/Examples/Tests/laser_injection/analysis_3d.py @@ -13,11 +13,11 @@ import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -25,7 +25,7 @@ # you can save an image to be displayed on the website t = np.arange(0.0, 2.0, 0.01) -s = 1 + np.sin(2*np.pi*t) +s = 1 + np.sin(2 * np.pi * t) plt.plot(t, s) plt.savefig("laser_analysis.png") diff --git a/Examples/Tests/laser_injection/inputs_1d_rt b/Examples/Tests/laser_injection/inputs_test_1d_laser_injection similarity index 100% rename from Examples/Tests/laser_injection/inputs_1d_rt rename to Examples/Tests/laser_injection/inputs_test_1d_laser_injection diff --git a/Examples/Tests/laser_injection/inputs_2d_rt b/Examples/Tests/laser_injection/inputs_test_2d_laser_injection similarity index 100% rename from Examples/Tests/laser_injection/inputs_2d_rt rename to Examples/Tests/laser_injection/inputs_test_2d_laser_injection diff --git a/Examples/Tests/laser_injection/inputs_3d_rt b/Examples/Tests/laser_injection/inputs_test_3d_laser_injection similarity index 99% rename from Examples/Tests/laser_injection/inputs_3d_rt rename to Examples/Tests/laser_injection/inputs_test_3d_laser_injection index 72464f86aaf..250a0160881 100644 --- a/Examples/Tests/laser_injection/inputs_3d_rt +++ b/Examples/Tests/laser_injection/inputs_test_3d_laser_injection @@ -1,5 +1,5 @@ # Maximum number of time steps -max_step = 1000 +max_step = 20 # number of grid points amr.n_cell = 32 32 240 diff --git a/Examples/Tests/laser_injection_from_file/CMakeLists.txt b/Examples/Tests/laser_injection_from_file/CMakeLists.txt new file mode 100644 index 00000000000..4b4024b9029 --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/CMakeLists.txt @@ -0,0 +1,142 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_laser_injection_from_lasy_file_prepare # name + 1 # dims + 1 # nprocs + inputs_test_1d_laser_injection_from_lasy_file_prepare.py # inputs + OFF # analysis + OFF # output + OFF # dependency +) + +add_warpx_test( + test_1d_laser_injection_from_lasy_file # name + 1 # dims + 1 # nprocs + inputs_test_1d_laser_injection_from_lasy_file # inputs + analysis_1d.py # analysis + diags/diag1000251 # output + test_1d_laser_injection_from_lasy_file_prepare # dependency +) + +add_warpx_test( + test_1d_laser_injection_from_lasy_file_boost_prepare # name + 1 # dims + 1 # nprocs + inputs_test_1d_laser_injection_from_lasy_file_boost_prepare.py # inputs + OFF # analysis + OFF # output + OFF # dependency +) + +add_warpx_test( + test_1d_laser_injection_from_lasy_file_boost # name + 1 # dims + 1 # nprocs + inputs_test_1d_laser_injection_from_lasy_file_boost # inputs + analysis_1d_boost.py # analysis + diags/diag1000001 # output + test_1d_laser_injection_from_lasy_file_boost_prepare # dependency +) + +add_warpx_test( + test_2d_laser_injection_from_binary_file_prepare # name + 2 # dims + 1 # nprocs + inputs_test_2d_laser_injection_from_binary_file_prepare.py # inputs + OFF # analysis + OFF # output + OFF # dependency +) + +add_warpx_test( + test_2d_laser_injection_from_binary_file # name + 2 # dims + 1 # nprocs + inputs_test_2d_laser_injection_from_binary_file # inputs + analysis_2d_binary.py # analysis + diags/diag1000250 # output + test_2d_laser_injection_from_binary_file_prepare # dependency +) + +add_warpx_test( + test_2d_laser_injection_from_lasy_file_prepare # name + 2 # dims + 1 # nprocs + inputs_test_2d_laser_injection_from_lasy_file_prepare.py # inputs + OFF # analysis + OFF # output + OFF # dependency +) + +add_warpx_test( + test_2d_laser_injection_from_lasy_file # name + 2 # dims + 1 # nprocs + inputs_test_2d_laser_injection_from_lasy_file # inputs + analysis_2d.py # analysis + diags/diag1000251 # output + test_2d_laser_injection_from_lasy_file_prepare # dependency +) + +add_warpx_test( + test_3d_laser_injection_from_lasy_file_prepare # name + 3 # dims + 1 # nprocs + inputs_test_3d_laser_injection_from_lasy_file_prepare.py # inputs + OFF # analysis + OFF # output + OFF # dependency +) + +add_warpx_test( + test_3d_laser_injection_from_lasy_file # name + 3 # dims + 1 # nprocs + inputs_test_3d_laser_injection_from_lasy_file # inputs + analysis_3d.py # analysis + diags/diag1000251 # output + test_3d_laser_injection_from_lasy_file_prepare # dependency +) + +add_warpx_test( + test_rz_laser_injection_from_lasy_file_prepare # name + RZ # dims + 1 # nprocs + inputs_test_rz_laser_injection_from_lasy_file_prepare.py # inputs + OFF # analysis + OFF # output + OFF # dependency +) + +add_warpx_test( + test_rz_laser_injection_from_lasy_file # name + RZ # dims + 1 # nprocs + inputs_test_rz_laser_injection_from_lasy_file # inputs + analysis_rz.py # analysis + diags/diag1000252 # output + test_rz_laser_injection_from_lasy_file_prepare # dependency +) + +add_warpx_test( + test_rz_laser_injection_from_RZ_lasy_file_prepare # name + RZ # dims + 1 # nprocs + inputs_test_rz_laser_injection_from_RZ_lasy_file_prepare.py # inputs + OFF # analysis + OFF # output + OFF # dependency +) + +add_warpx_test( + test_rz_laser_injection_from_RZ_lasy_file # name + RZ # dims + 1 # nprocs + inputs_test_rz_laser_injection_from_RZ_lasy_file # inputs + analysis_from_RZ_file.py # analysis + diags/diag1000612 # output + test_rz_laser_injection_from_RZ_lasy_file_prepare # dependency +) diff --git a/Examples/Tests/laser_injection_from_file/analysis_1d.py b/Examples/Tests/laser_injection_from_file/analysis_1d.py index a595a912858..1b5f209cb91 100755 --- a/Examples/Tests/laser_injection_from_file/analysis_1d.py +++ b/Examples/Tests/laser_injection_from_file/analysis_1d.py @@ -9,138 +9,109 @@ # This file is part of the WarpX automated test suite. It is used to test the -# injection of a laser pulse from an external lasy file. -# -# - Generate an input lasy file with a gaussian laser pulse. -# - Run the WarpX simulation for time T, when the pulse is fully injected +# injection of a laser pulse from an external lasy file: # - Compute the theory for laser envelope at time T # - Compare theory and simulation in 1D, for both envelope and central frequency -import glob import os import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np +import yt from scipy.constants import c, epsilon_0 from scipy.signal import hilbert -import yt ; yt.funcs.mylog.setLevel(50) +yt.funcs.mylog.setLevel(50) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -#Maximum acceptable error for this test +# Maximum acceptable error for this test relative_error_threshold = 0.065 -#Physical parameters -um = 1.e-6 -fs = 1.e-15 -c = 299792458 +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 -#Parameters of the gaussian beam -wavelength = 1.*um -w0 = 12.*um -tt = 10.*fs -t_c = 20.*fs +# Parameters of the gaussian beam +wavelength = 1.0 * um +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs laser_energy = 1.0 -E_max = np.sqrt( 2*(2/np.pi)**(3/2)*laser_energy / (epsilon_0*w0**2*c*tt) ) +E_max = np.sqrt( + 2 * (2 / np.pi) ** (3 / 2) * laser_energy / (epsilon_0 * w0**2 * c * tt) +) + # Function for the envelope -def gauss_env(T,Z): +def gauss_env(T, Z): # Function to compute the theory for the envelope - inv_tau2 = 1./tt/tt - exp_arg = - inv_tau2 / c/c * (Z-T*c)*(Z-T*c) + inv_tau2 = 1.0 / tt / tt + exp_arg = -inv_tau2 / c / c * (Z - T * c) * (Z - T * c) return E_max * np.real(np.exp(exp_arg)) -def do_analysis(fname, compname, steps): - ds = yt.load(fname) - dt = ds.current_time.to_value()/steps - - z = np.linspace( - ds.domain_left_edge[0].v, - ds.domain_right_edge[0].v, - ds.domain_dimensions[0]) - - # Compute the theory for envelope - env_theory = gauss_env(+t_c-ds.current_time.to_value(), z)+gauss_env(-t_c+ds.current_time.to_value(),z) - - # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - F_laser = all_data_level_0['boxlib', 'Ey'].v.squeeze() - env = abs(hilbert(F_laser)) - - # Plot results - plt.figure(figsize=(8,8)) - plt.subplot(221) - plt.title('PIC field') - plt.plot(z, F_laser) - plt.subplot(222) - plt.title('PIC envelope') - plt.plot(z, env) - plt.subplot(223) - plt.title('Theory envelope') - plt.plot(z,env_theory) - plt.subplot(224) - plt.title('Difference') - plt.plot(z,env-env_theory) - - plt.tight_layout() - plt.savefig(compname, bbox_inches='tight') - - relative_error_env = np.sum(np.abs(env-env_theory)) / np.sum(np.abs(env)) - print("Relative error envelope: ", relative_error_env) - assert(relative_error_env < relative_error_threshold) - - fft_F_laser = np.fft.fftn(F_laser) - - freq_z = np.fft.fftfreq(F_laser.shape[0],dt) - - pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) - - freq = np.abs(freq_z[pos_max[0]]) - exp_freq = c/wavelength - relative_error_freq = np.abs(freq-exp_freq)/exp_freq - print("Relative error frequency: ", relative_error_freq) - assert(relative_error_freq < relative_error_threshold) - - - -def launch_analysis(executable): - os.system("./" + executable + " inputs.1d_test diag1.file_prefix=diags/plotfiles/plt") - do_analysis("diags/plotfiles/plt000251/", "comp_unf.pdf", 251) - - -def main() : - - from lasy.laser import Laser - from lasy.profiles import GaussianProfile - - # Create a laser using lasy - pol = (1, 0) - profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) - dim = "xyt" - lo = (-25e-6, -25e-6, -20e-15) - hi = (+25e-6, +25e-6, +20e-15) - npoints = (100, 100, 100) - laser = Laser(dim, lo, hi, npoints, profile) - laser.normalize(laser_energy, kind="energy") - laser.write_to_file("gaussianlaser3d") - executables = glob.glob("*.ex") - if len(executables) == 1 : - launch_analysis(executables[0]) - else : - assert(False) - - # Do the checksum test - filename_end = "diags/plotfiles/plt000251/" - test_name = os.path.split(os.getcwd())[1] - checksumAPI.evaluate_checksum(test_name, filename_end) - print('Passed') - -if __name__ == "__main__": - main() + +filename = sys.argv[1] +compname = "comp_unf.pdf" +steps = 251 +ds = yt.load(filename) +dt = ds.current_time.to_value() / steps + +z = np.linspace( + ds.domain_left_edge[0].v, ds.domain_right_edge[0].v, ds.domain_dimensions[0] +) + +# Compute the theory for envelope +env_theory = gauss_env(+t_c - ds.current_time.to_value(), z) + gauss_env( + -t_c + ds.current_time.to_value(), z +) + +# Read laser field in PIC simulation, and compute envelope +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +F_laser = all_data_level_0["boxlib", "Ey"].v.squeeze() +env = abs(hilbert(F_laser)) + +# Plot results +plt.figure(figsize=(8, 8)) +plt.subplot(221) +plt.title("PIC field") +plt.plot(z, F_laser) +plt.subplot(222) +plt.title("PIC envelope") +plt.plot(z, env) +plt.subplot(223) +plt.title("Theory envelope") +plt.plot(z, env_theory) +plt.subplot(224) +plt.title("Difference") +plt.plot(z, env - env_theory) + +plt.tight_layout() +plt.savefig(compname, bbox_inches="tight") + +relative_error_env = np.sum(np.abs(env - env_theory)) / np.sum(np.abs(env)) +print("Relative error envelope: ", relative_error_env) +assert relative_error_env < relative_error_threshold + +fft_F_laser = np.fft.fftn(F_laser) + +freq_z = np.fft.fftfreq(F_laser.shape[0], dt) + +pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) + +freq = np.abs(freq_z[pos_max[0]]) +exp_freq = c / wavelength +relative_error_freq = np.abs(freq - exp_freq) / exp_freq +print("Relative error frequency: ", relative_error_freq) +assert relative_error_freq < relative_error_threshold + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/laser_injection_from_file/analysis_1d_boost.py b/Examples/Tests/laser_injection_from_file/analysis_1d_boost.py index 1fcc46d54d3..89c0ea3c57c 100755 --- a/Examples/Tests/laser_injection_from_file/analysis_1d_boost.py +++ b/Examples/Tests/laser_injection_from_file/analysis_1d_boost.py @@ -9,139 +9,110 @@ # This file is part of the WarpX automated test suite. It is used to test the -# injection of a laser pulse from an external lasy file. -# -# - Generate an input lasy file with a gaussian laser pulse. -# - Run the WarpX simulation for time T, when the pulse is fully injected +# injection of a laser pulse from an external lasy file: # - Compute the theory for laser envelope at time T # - Compare theory and simulation in 1D, for both envelope and central frequency -import glob import os import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np +import yt from scipy.constants import c, epsilon_0 from scipy.signal import hilbert -import yt ; yt.funcs.mylog.setLevel(50) +yt.funcs.mylog.setLevel(50) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -#Maximum acceptable error for this test +# Maximum acceptable error for this test relative_error_threshold = 0.065 -#Physical parameters -um = 1.e-6 -fs = 1.e-15 -c = 299792458 +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 -#Parameters of the gaussian beam -wavelength = 1.*um -w0 = 12.*um -tt = 10.*fs -t_c = 20.*fs +# Parameters of the gaussian beam +wavelength = 1.0 * um +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs laser_energy = 1.0 -E_max = np.sqrt( 2*(2/np.pi)**(3/2)*laser_energy / (epsilon_0*w0**2*c*tt) ) +E_max = np.sqrt( + 2 * (2 / np.pi) ** (3 / 2) * laser_energy / (epsilon_0 * w0**2 * c * tt) +) + # Function for the envelope -def gauss_env(T,Z): +def gauss_env(T, Z): # Function to compute the theory for the envelope - inv_tau2 = 1./tt/tt - exp_arg = - inv_tau2 / c/c * (Z-T*c)*(Z-T*c) + inv_tau2 = 1.0 / tt / tt + exp_arg = -inv_tau2 / c / c * (Z - T * c) * (Z - T * c) return E_max * np.real(np.exp(exp_arg)) -def do_analysis(fname, compname): - ds = yt.load(fname) - dz = (ds.domain_right_edge[0].v-ds.domain_left_edge[0].v)/ds.domain_dimensions[0] - dt = dz/c - - z = np.linspace( - ds.domain_left_edge[0].v, - ds.domain_right_edge[0].v, - ds.domain_dimensions[0]) - - # Compute the theory for envelope - env_theory = gauss_env(+t_c-ds.current_time.to_value(), z)+gauss_env(-t_c+ds.current_time.to_value(),z) - - # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - F_laser = all_data_level_0['boxlib', 'Ey'].v.squeeze() - env = abs(hilbert(F_laser)) - - # Plot results - plt.figure(figsize=(8,8)) - plt.subplot(221) - plt.title('PIC field') - plt.plot(z, F_laser) - plt.subplot(222) - plt.title('PIC envelope') - plt.plot(z, env) - plt.subplot(223) - plt.title('Theory envelope') - plt.plot(z,env_theory) - plt.subplot(224) - plt.title('Difference') - plt.plot(z,env-env_theory) - - plt.tight_layout() - plt.savefig(compname, bbox_inches='tight') - - relative_error_env = np.sum(np.abs(env-env_theory)) / np.sum(np.abs(env)) - print("Relative error envelope: ", relative_error_env) - assert(relative_error_env < relative_error_threshold) - - fft_F_laser = np.fft.fftn(F_laser) - - freq_z = np.fft.fftfreq(F_laser.shape[0],dt) - - pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) - - freq = np.abs(freq_z[pos_max[0]]) - exp_freq = c/wavelength - relative_error_freq = np.abs(freq-exp_freq)/exp_freq - print("Relative error frequency: ", relative_error_freq) - assert(relative_error_freq < relative_error_threshold) - - - -def launch_analysis(executable): - os.system("./" + executable + " inputs.1d_boost_test diag1.file_prefix=diags/plotfiles/plt") - do_analysis("diags/plotfiles/plt000001/", "comp_unf.pdf") - - -def main() : - - from lasy.laser import Laser - from lasy.profiles import GaussianProfile - - # Create a laser using lasy - pol = (1, 0) - profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) - dim = "xyt" - lo = (-25e-6, -25e-6, -20e-15) - hi = (+25e-6, +25e-6, +20e-15) - npoints = (100, 100, 100) - laser = Laser(dim, lo, hi, npoints, profile) - laser.normalize(laser_energy, kind="energy") - laser.write_to_file("gaussianlaser3d") - executables = glob.glob("*.ex") - if len(executables) == 1 : - launch_analysis(executables[0]) - else : - assert(False) - - # Do the checksum test - filename_end = "diags/plotfiles/plt000001/" - test_name = os.path.split(os.getcwd())[1] - checksumAPI.evaluate_checksum(test_name, filename_end) - print('Passed') - -if __name__ == "__main__": - main() + +filename = sys.argv[1] +compname = "comp_unf.pdf" +ds = yt.load(filename) +dz = (ds.domain_right_edge[0].v - ds.domain_left_edge[0].v) / ds.domain_dimensions[0] +dt = dz / c + +z = np.linspace( + ds.domain_left_edge[0].v, ds.domain_right_edge[0].v, ds.domain_dimensions[0] +) + +# Compute the theory for envelope +env_theory = gauss_env(+t_c - ds.current_time.to_value(), z) + gauss_env( + -t_c + ds.current_time.to_value(), z +) + +# Read laser field in PIC simulation, and compute envelope +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +F_laser = all_data_level_0["boxlib", "Ey"].v.squeeze() +env = abs(hilbert(F_laser)) + +# Plot results +plt.figure(figsize=(8, 8)) +plt.subplot(221) +plt.title("PIC field") +plt.plot(z, F_laser) +plt.subplot(222) +plt.title("PIC envelope") +plt.plot(z, env) +plt.subplot(223) +plt.title("Theory envelope") +plt.plot(z, env_theory) +plt.subplot(224) +plt.title("Difference") +plt.plot(z, env - env_theory) + +plt.tight_layout() +plt.savefig(compname, bbox_inches="tight") + +relative_error_env = np.sum(np.abs(env - env_theory)) / np.sum(np.abs(env)) +print("Relative error envelope: ", relative_error_env) +assert relative_error_env < relative_error_threshold + +fft_F_laser = np.fft.fftn(F_laser) + +freq_z = np.fft.fftfreq(F_laser.shape[0], dt) + +pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) + +freq = np.abs(freq_z[pos_max[0]]) +exp_freq = c / wavelength +relative_error_freq = np.abs(freq - exp_freq) / exp_freq +print("Relative error frequency: ", relative_error_freq) +assert relative_error_freq < relative_error_threshold + +# Do the checksum test +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/laser_injection_from_file/analysis_2d.py b/Examples/Tests/laser_injection_from_file/analysis_2d.py index 23b7e12dbcd..ab5649e968f 100755 --- a/Examples/Tests/laser_injection_from_file/analysis_2d.py +++ b/Examples/Tests/laser_injection_from_file/analysis_2d.py @@ -9,156 +9,135 @@ # This file is part of the WarpX automated test suite. It is used to test the -# injection of a laser pulse from an external lasy file. -# -# - Generate an input lasy file with a gaussian laser pulse. -# - Run the WarpX simulation for time T, when the pulse is fully injected +# injection of a laser pulse from an external lasy file: # - Compute the theory for laser envelope at time T # - Compare theory and simulation in 2D, for both envelope and central frequency -import glob import os import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np +import yt from scipy.constants import c, epsilon_0 from scipy.signal import hilbert -import yt ; yt.funcs.mylog.setLevel(50) +yt.funcs.mylog.setLevel(50) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -#Maximum acceptable error for this test +# Maximum acceptable error for this test relative_error_threshold = 0.065 -#Physical parameters -um = 1.e-6 -fs = 1.e-15 -c = 299792458 +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 -#Parameters of the gaussian beam -wavelength = 1.*um -w0 = 12.*um -tt = 10.*fs -t_c = 20.*fs +# Parameters of the gaussian beam +wavelength = 1.0 * um +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs laser_energy = 1.0 -E_max = np.sqrt( 2*(2/np.pi)**(3/2)*laser_energy / (epsilon_0*w0**2*c*tt) ) +E_max = np.sqrt( + 2 * (2 / np.pi) ** (3 / 2) * laser_energy / (epsilon_0 * w0**2 * c * tt) +) + # Function for the envelope def gauss_env(T, X, Y, Z): # Function to compute the theory for the envelope - inv_tau2 = 1./tt/tt - inv_w_2 = 1.0/(w0*w0) - exp_arg = - (X*X)*inv_w_2 - (Y*Y)*inv_w_2- inv_tau2 / c/c * (Z-T*c)*(Z-T*c) + inv_tau2 = 1.0 / tt / tt + inv_w_2 = 1.0 / (w0 * w0) + exp_arg = ( + -(X * X) * inv_w_2 + - (Y * Y) * inv_w_2 + - inv_tau2 / c / c * (Z - T * c) * (Z - T * c) + ) return E_max * np.real(np.exp(exp_arg)) -def do_analysis(fname, compname, steps): - ds = yt.load(fname) - dt = ds.current_time.to_value()/steps - - # Define 3D meshes - x = np.linspace( - ds.domain_left_edge[0], - ds.domain_right_edge[0], - ds.domain_dimensions[0]).v - y = np.linspace( - ds.domain_left_edge[1], - ds.domain_right_edge[1], - ds.domain_dimensions[1]).v - z = np.linspace( - ds.domain_left_edge[ds.dimensionality-1], - ds.domain_right_edge[ds.dimensionality-1], - ds.domain_dimensions[ds.dimensionality-1]).v - X, Y, Z = np.meshgrid(x, y, z, sparse=False, indexing='ij') - - # Compute the theory for envelope - env_theory = gauss_env(+t_c-ds.current_time.to_value(), X,Y,Z)+gauss_env(-t_c+ds.current_time.to_value(), X,Y,Z) - - # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - F_laser = all_data_level_0['boxlib', 'Ey'].v.squeeze() - env = abs(hilbert(F_laser)) - extent = [ds.domain_left_edge[ds.dimensionality-1], ds.domain_right_edge[ds.dimensionality-1], - ds.domain_left_edge[0], ds.domain_right_edge[0] ] - env_theory_slice= env_theory[:,env_theory.shape[1]//2, :] - - # Plot results - plt.figure(figsize=(8,6)) - plt.subplot(221) - plt.title('PIC field') - plt.imshow(F_laser, extent=extent) - plt.colorbar() - plt.subplot(222) - plt.title('PIC envelope') - plt.imshow(env, extent=extent) - plt.colorbar() - plt.subplot(223) - plt.title('Theory envelope') - plt.imshow(env_theory_slice, extent=extent) - plt.colorbar() - plt.subplot(224) - plt.title('Difference') - plt.imshow(env-env_theory_slice, extent=extent) - plt.colorbar() - plt.tight_layout() - plt.savefig(compname, bbox_inches='tight') - - relative_error_env = np.sum(np.abs(env-env_theory_slice)) / np.sum(np.abs(env)) - print("Relative error envelope: ", relative_error_env) - assert(relative_error_env < relative_error_threshold) - - fft_F_laser = np.fft.fftn(F_laser) - - freq_x = np.fft.fftfreq(F_laser.shape[0],dt) - freq_z = np.fft.fftfreq(F_laser.shape[1],dt) - - pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) - - freq = np.sqrt((freq_x[pos_max[0]])**2 + (freq_z[pos_max[1]])**2) - exp_freq = c/wavelength - relative_error_freq = np.abs(freq-exp_freq)/exp_freq - print("Relative error frequency: ", relative_error_freq) - assert(relative_error_freq < relative_error_threshold) - - - -def launch_analysis(executable): - os.system("./" + executable + " inputs.2d_test diag1.file_prefix=diags/plotfiles/plt") - do_analysis("diags/plotfiles/plt000251/", "comp_unf.pdf", 251) - - -def main() : - - from lasy.laser import Laser - from lasy.profiles import GaussianProfile - - # Create a laser using lasy - pol = (1, 0) - profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) - dim = "xyt" - lo = (-25e-6, -25e-6, -20e-15) - hi = (+25e-6, +25e-6, +20e-15) - npoints = (100, 100, 100) - laser = Laser(dim, lo, hi, npoints, profile) - laser.normalize(laser_energy, kind="energy") - laser.write_to_file("gaussianlaser3d") - executables = glob.glob("*.ex") - if len(executables) == 1 : - launch_analysis(executables[0]) - else : - assert(False) - - # Do the checksum test - filename_end = "diags/plotfiles/plt000251/" - test_name = os.path.split(os.getcwd())[1] - checksumAPI.evaluate_checksum(test_name, filename_end) - print('Passed') - -if __name__ == "__main__": - main() + +filename = sys.argv[1] +compname = "comp_unf.pdf" +steps = 251 +ds = yt.load(filename) +dt = ds.current_time.to_value() / steps + +# Define 3D meshes +x = np.linspace( + ds.domain_left_edge[0], ds.domain_right_edge[0], ds.domain_dimensions[0] +).v +y = np.linspace( + ds.domain_left_edge[1], ds.domain_right_edge[1], ds.domain_dimensions[1] +).v +z = np.linspace( + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_dimensions[ds.dimensionality - 1], +).v +X, Y, Z = np.meshgrid(x, y, z, sparse=False, indexing="ij") + +# Compute the theory for envelope +env_theory = gauss_env(+t_c - ds.current_time.to_value(), X, Y, Z) + gauss_env( + -t_c + ds.current_time.to_value(), X, Y, Z +) + +# Read laser field in PIC simulation, and compute envelope +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +F_laser = all_data_level_0["boxlib", "Ey"].v.squeeze() +env = abs(hilbert(F_laser)) +extent = [ + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_left_edge[0], + ds.domain_right_edge[0], +] +env_theory_slice = env_theory[:, env_theory.shape[1] // 2, :] + +# Plot results +plt.figure(figsize=(8, 6)) +plt.subplot(221) +plt.title("PIC field") +plt.imshow(F_laser, extent=extent) +plt.colorbar() +plt.subplot(222) +plt.title("PIC envelope") +plt.imshow(env, extent=extent) +plt.colorbar() +plt.subplot(223) +plt.title("Theory envelope") +plt.imshow(env_theory_slice, extent=extent) +plt.colorbar() +plt.subplot(224) +plt.title("Difference") +plt.imshow(env - env_theory_slice, extent=extent) +plt.colorbar() +plt.tight_layout() +plt.savefig(compname, bbox_inches="tight") + +relative_error_env = np.sum(np.abs(env - env_theory_slice)) / np.sum(np.abs(env)) +print("Relative error envelope: ", relative_error_env) +assert relative_error_env < relative_error_threshold + +fft_F_laser = np.fft.fftn(F_laser) + +freq_x = np.fft.fftfreq(F_laser.shape[0], dt) +freq_z = np.fft.fftfreq(F_laser.shape[1], dt) + +pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) + +freq = np.sqrt((freq_x[pos_max[0]]) ** 2 + (freq_z[pos_max[1]]) ** 2) +exp_freq = c / wavelength +relative_error_freq = np.abs(freq - exp_freq) / exp_freq +print("Relative error frequency: ", relative_error_freq) +assert relative_error_freq < relative_error_threshold + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/laser_injection_from_file/analysis_2d_binary.py b/Examples/Tests/laser_injection_from_file/analysis_2d_binary.py index c5bdd84d023..bcb13bba410 100755 --- a/Examples/Tests/laser_injection_from_file/analysis_2d_binary.py +++ b/Examples/Tests/laser_injection_from_file/analysis_2d_binary.py @@ -9,207 +9,142 @@ # This file is part of the WarpX automated test suite. It is used to test the -# injection of a laser pulse from an external binary file. -# -# - Generate an input binary file with a gaussian laser pulse. -# - Run the WarpX simulation for time T, when the pulse is fully injected +# injection of a laser pulse from an external binary file: # - Compute the theory for laser envelope at time T # - Compare theory and simulation in 2D, for both envelope and central frequency -import glob import os import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np +import yt from scipy.signal import hilbert -import yt ; yt.funcs.mylog.setLevel(50) +yt.funcs.mylog.setLevel(50) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -#Maximum acceptable error for this test +# Maximum acceptable error for this test relative_error_threshold = 0.065 -#Physical parameters -um = 1.e-6 -fs = 1.e-15 +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 c = 299792458 -#Parameters of the gaussian beam -wavelength = 1.*um -w0 = 6.*um -tt = 10.*fs -x_c = 0.*um -t_c = 20.*fs -foc_dist = 10*um +# Parameters of the gaussian beam +wavelength = 1.0 * um +w0 = 6.0 * um +tt = 10.0 * fs +x_c = 0.0 * um +t_c = 20.0 * fs +foc_dist = 10 * um E_max = 1e12 -rot_angle = -np.pi/4.0 +rot_angle = -np.pi / 4.0 -#Parameters of the tx grid -x_l = -12.0*um -x_r = 12.0*um +# Parameters of the tx grid +x_l = -12.0 * um +x_r = 12.0 * um x_points = 480 -t_l = 0.0*fs -t_r = 40.0*fs +t_l = 0.0 * fs +t_r = 40.0 * fs t_points = 400 tcoords = np.linspace(t_l, t_r, t_points) xcoords = np.linspace(x_l, x_r, x_points) -def gauss(T,X,Y,opt): - """Compute the electric field for a Gaussian laser pulse. - This is used to write the binary input file. - """ - - k0 = 2.0*np.pi/wavelength - inv_tau2 = 1./tt/tt - osc_phase = k0*c*(T-t_c) - - diff_factor = 1.0 + 1.0j* foc_dist * 2/(k0*w0*w0) - inv_w_2 = 1.0/(w0*w0*diff_factor) - - pre_fact = np.exp(1.0j * osc_phase) - - if opt == '3d': - pre_fact = pre_fact/diff_factor - else: - pre_fact = pre_fact/np.sqrt(diff_factor) - - exp_arg = - (X*X + Y*Y)*inv_w_2 - inv_tau2 * (T-t_c)*(T-t_c) - - return np.real(pre_fact * np.exp(exp_arg)) # Function for the envelope -def gauss_env(T,XX,ZZ): - '''Function to compute the theory for the envelope - ''' +def gauss_env(T, XX, ZZ): + """Function to compute the theory for the envelope""" - X = np.cos(rot_angle)*XX + np.sin(rot_angle)*ZZ - Z = -np.sin(rot_angle)*XX + np.cos(rot_angle)*ZZ + X = np.cos(rot_angle) * XX + np.sin(rot_angle) * ZZ + Z = -np.sin(rot_angle) * XX + np.cos(rot_angle) * ZZ - inv_tau2 = 1./tt/tt - inv_w_2 = 1.0/(w0*w0) - exp_arg = - (X*X)*inv_w_2 - inv_tau2 / c/c * (Z-T*c)*(Z-T*c) + inv_tau2 = 1.0 / tt / tt + inv_w_2 = 1.0 / (w0 * w0) + exp_arg = -(X * X) * inv_w_2 - inv_tau2 / c / c * (Z - T * c) * (Z - T * c) return E_max * np.real(np.exp(exp_arg)) -def write_file(fname, x, y, t, E): - """ For a given filename fname, space coordinates x and y, time coordinate t - and field E, write a WarpX-compatible input binary file containing the - profile of the laser pulse. This function should be used in the case - of a uniform spatio-temporal mesh - """ - - with open(fname, 'wb') as file: - flag_unif = 1 - file.write(flag_unif.to_bytes(1, byteorder='little')) - file.write((len(t)).to_bytes(4, byteorder='little', signed=False)) - file.write((len(x)).to_bytes(4, byteorder='little', signed=False)) - file.write((len(y)).to_bytes(4, byteorder='little', signed=False)) - file.write(t[0].tobytes()) - file.write(t[-1].tobytes()) - file.write(x[0].tobytes()) - file.write(x[-1].tobytes()) - if len(y) == 1 : - file.write(y[0].tobytes()) - else : - file.write(y[0].tobytes()) - file.write(y[-1].tobytes()) - file.write(E.tobytes()) - -def create_gaussian_2d(): - T, X, Y = np.meshgrid(tcoords, xcoords, np.array([0.0]), indexing='ij') - E_t = gauss(T,X,Y,'2d') - write_file("gauss_2d", xcoords, np.array([0.0]), tcoords, E_t) - -def do_analysis(fname, compname, steps): - ds = yt.load(fname) - - dt = ds.current_time.to_value()/steps - - # Define 2D meshes - x = np.linspace( - ds.domain_left_edge[0], - ds.domain_right_edge[0], - ds.domain_dimensions[0]).v - z = np.linspace( - ds.domain_left_edge[ds.dimensionality-1], - ds.domain_right_edge[ds.dimensionality-1], - ds.domain_dimensions[ds.dimensionality-1]).v - X, Z = np.meshgrid(x, z, sparse=False, indexing='ij') - - # Compute the theory for envelope - env_theory = gauss_env(+t_c-ds.current_time.to_value(), X,Z)+gauss_env(-t_c+ds.current_time.to_value(), X,Z) - - # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - F_laser = all_data_level_0['boxlib', 'Ey'].v.squeeze() - env = abs(hilbert(F_laser)) - extent = [ds.domain_left_edge[ds.dimensionality-1], ds.domain_right_edge[ds.dimensionality-1], - ds.domain_left_edge[0], ds.domain_right_edge[0] ] - - # Plot results - plt.figure(figsize=(8,6)) - plt.subplot(221) - plt.title('PIC field') - plt.imshow(F_laser, extent=extent) - plt.colorbar() - plt.subplot(222) - plt.title('PIC envelope') - plt.imshow(env, extent=extent) - plt.colorbar() - plt.subplot(223) - plt.title('Theory envelope') - plt.imshow(env_theory, extent=extent) - plt.colorbar() - plt.subplot(224) - plt.title('Difference') - plt.imshow(env-env_theory, extent=extent) - plt.colorbar() - plt.tight_layout() - plt.savefig(compname, bbox_inches='tight') - - relative_error_env = np.sum(np.abs(env-env_theory)) / np.sum(np.abs(env)) - print("Relative error envelope: ", relative_error_env) - assert(relative_error_env < relative_error_threshold) - - fft_F_laser = np.fft.fft2(F_laser) - - freq_rows = np.fft.fftfreq(F_laser.shape[0],dt) - freq_cols = np.fft.fftfreq(F_laser.shape[1],dt) - - pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) - - freq = np.sqrt((freq_rows[pos_max[0]])**2 + (freq_cols[pos_max[1]]**2)) - exp_freq = c/wavelength - - relative_error_freq = np.abs(freq-exp_freq)/exp_freq - print("Relative error frequency: ", relative_error_freq) - assert(relative_error_freq < relative_error_threshold) - - - -def launch_analysis(executable): - create_gaussian_2d() - os.system("./" + executable + " inputs.2d_test_binary diag1.file_prefix=diags/plotfiles/plt") - do_analysis("diags/plotfiles/plt000250/", "comp_unf.pdf", 250) - - -def main() : - executables = glob.glob("*.ex") - if len(executables) == 1 : - launch_analysis(executables[0]) - else : - assert(False) - - # Do the checksum test - filename_end = "diags/plotfiles/plt000250/" - test_name = "LaserInjectionFromBINARYFile" - checksumAPI.evaluate_checksum(test_name, filename_end) - print('Passed') - -if __name__ == "__main__": - main() + +filename = sys.argv[1] +compname = "comp_unf.pdf" +steps = 250 +ds = yt.load(filename) + +dt = ds.current_time.to_value() / steps + +# Define 2D meshes +x = np.linspace( + ds.domain_left_edge[0], ds.domain_right_edge[0], ds.domain_dimensions[0] +).v +z = np.linspace( + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_dimensions[ds.dimensionality - 1], +).v +X, Z = np.meshgrid(x, z, sparse=False, indexing="ij") + +# Compute the theory for envelope +env_theory = gauss_env(+t_c - ds.current_time.to_value(), X, Z) + gauss_env( + -t_c + ds.current_time.to_value(), X, Z +) + +# Read laser field in PIC simulation, and compute envelope +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +F_laser = all_data_level_0["boxlib", "Ey"].v.squeeze() +env = abs(hilbert(F_laser)) +extent = [ + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_left_edge[0], + ds.domain_right_edge[0], +] + +# Plot results +plt.figure(figsize=(8, 6)) +plt.subplot(221) +plt.title("PIC field") +plt.imshow(F_laser, extent=extent) +plt.colorbar() +plt.subplot(222) +plt.title("PIC envelope") +plt.imshow(env, extent=extent) +plt.colorbar() +plt.subplot(223) +plt.title("Theory envelope") +plt.imshow(env_theory, extent=extent) +plt.colorbar() +plt.subplot(224) +plt.title("Difference") +plt.imshow(env - env_theory, extent=extent) +plt.colorbar() +plt.tight_layout() +plt.savefig(compname, bbox_inches="tight") + +relative_error_env = np.sum(np.abs(env - env_theory)) / np.sum(np.abs(env)) +print("Relative error envelope: ", relative_error_env) +assert relative_error_env < relative_error_threshold + +fft_F_laser = np.fft.fft2(F_laser) + +freq_rows = np.fft.fftfreq(F_laser.shape[0], dt) +freq_cols = np.fft.fftfreq(F_laser.shape[1], dt) + +pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) + +freq = np.sqrt((freq_rows[pos_max[0]]) ** 2 + (freq_cols[pos_max[1]] ** 2)) +exp_freq = c / wavelength + +relative_error_freq = np.abs(freq - exp_freq) / exp_freq +print("Relative error frequency: ", relative_error_freq) +assert relative_error_freq < relative_error_threshold + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/laser_injection_from_file/analysis_3d.py b/Examples/Tests/laser_injection_from_file/analysis_3d.py index a66f761b9b1..7d30af28639 100755 --- a/Examples/Tests/laser_injection_from_file/analysis_3d.py +++ b/Examples/Tests/laser_injection_from_file/analysis_3d.py @@ -9,160 +9,141 @@ # This file is part of the WarpX automated test suite. It is used to test the -# injection of a laser pulse from an external lasy file. -# -# - Generate an input lasy file with a gaussian laser pulse. -# - Run the WarpX simulation for time T, when the pulse is fully injected +# injection of a laser pulse from an external lasy file: # - Compute the theory for laser envelope at time T # - Compare theory and simulation in 3D, for both envelope and central frequency -import glob import os import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np +import yt from scipy.constants import c, epsilon_0 from scipy.signal import hilbert -import yt ; yt.funcs.mylog.setLevel(50) +yt.funcs.mylog.setLevel(50) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -#Maximum acceptable error for this test +# Maximum acceptable error for this test relative_error_threshold = 0.065 -#Physical parameters -um = 1.e-6 -fs = 1.e-15 -c = 299792458 +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 -#Parameters of the gaussian beam -wavelength = 1.*um -w0 = 12.*um -tt = 10.*fs -t_c = 20.*fs +# Parameters of the gaussian beam +wavelength = 1.0 * um +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs laser_energy = 1.0 -E_max = np.sqrt( 2*(2/np.pi)**(3/2)*laser_energy / (epsilon_0*w0**2*c*tt) ) +E_max = np.sqrt( + 2 * (2 / np.pi) ** (3 / 2) * laser_energy / (epsilon_0 * w0**2 * c * tt) +) + # Function for the envelope def gauss_env(T, X, Y, Z): # Function to compute the theory for the envelope - inv_tau2 = 1./tt/tt - inv_w_2 = 1.0/(w0*w0) - exp_arg = - (X*X)*inv_w_2 - (Y*Y)*inv_w_2- inv_tau2 / c/c * (Z-T*c)*(Z-T*c) + inv_tau2 = 1.0 / tt / tt + inv_w_2 = 1.0 / (w0 * w0) + exp_arg = ( + -(X * X) * inv_w_2 + - (Y * Y) * inv_w_2 + - inv_tau2 / c / c * (Z - T * c) * (Z - T * c) + ) return E_max * np.real(np.exp(exp_arg)) -def do_analysis(fname, compname, steps): - ds = yt.load(fname) - dt = ds.current_time.to_value()/steps - - # Define 3D meshes - x = np.linspace( - ds.domain_left_edge[0], - ds.domain_right_edge[0], - ds.domain_dimensions[0]).v - y = np.linspace( - ds.domain_left_edge[1], - ds.domain_right_edge[1], - ds.domain_dimensions[1]).v - z = np.linspace( - ds.domain_left_edge[ds.dimensionality-1], - ds.domain_right_edge[ds.dimensionality-1], - ds.domain_dimensions[ds.dimensionality-1]).v - X, Y, Z = np.meshgrid(x, y, z, sparse=False, indexing='ij') - - # Compute the theory for envelope - env_theory = gauss_env(+t_c-ds.current_time.to_value(), X,Y,Z)+gauss_env(-t_c+ds.current_time.to_value(), X,Y,Z) - - # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - F_laser = all_data_level_0['boxlib', 'Ey'].v.squeeze() - env = abs(hilbert(F_laser)) - extent = [ds.domain_left_edge[ds.dimensionality-1], ds.domain_right_edge[ds.dimensionality-1], - ds.domain_left_edge[0], ds.domain_right_edge[0] ] - - F_slice= F_laser[:,F_laser.shape[1]//2, :] - env_slice= env[:,env.shape[1]//2, :] - env_theory_slice= env_theory[:,env_theory.shape[1]//2, :] - - # Plot results - plt.figure(figsize=(8,6)) - plt.subplot(221) - plt.title('PIC field') - plt.imshow(F_slice, extent=extent) - plt.colorbar() - plt.subplot(222) - plt.title('PIC envelope') - plt.imshow(env_slice, extent=extent) - plt.colorbar() - plt.subplot(223) - plt.title('Theory envelope') - plt.imshow(env_theory_slice, extent=extent) - plt.colorbar() - plt.subplot(224) - plt.title('Difference') - plt.imshow(env_slice-env_theory_slice, extent=extent) - plt.colorbar() - plt.tight_layout() - plt.savefig(compname, bbox_inches='tight') - - relative_error_env = np.sum(np.abs(env-env_theory)) / np.sum(np.abs(env)) - print("Relative error envelope: ", relative_error_env) - assert(relative_error_env < relative_error_threshold) - - fft_F_laser = np.fft.fftn(F_laser) - - freq_x = np.fft.fftfreq(F_laser.shape[0],dt) - freq_y = np.fft.fftfreq(F_laser.shape[1],dt) - freq_z = np.fft.fftfreq(F_laser.shape[2],dt) - - pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) - - freq = np.sqrt((freq_x[pos_max[0]])**2 + (freq_y[pos_max[1]]**2) + (freq_z[pos_max[2]])**2) - exp_freq = c/wavelength - relative_error_freq = np.abs(freq-exp_freq)/exp_freq - print("Relative error frequency: ", relative_error_freq) - assert(relative_error_freq < relative_error_threshold) - - - -def launch_analysis(executable): - os.system("./" + executable + " inputs.3d_test diag1.file_prefix=diags/plotfiles/plt") - do_analysis("diags/plotfiles/plt000251/", "comp_unf.pdf", 251) - - -def main() : - - from lasy.laser import Laser - from lasy.profiles import GaussianProfile - - # Create a laser using lasy - pol = (1, 0) - profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) - dim = "xyt" - lo = (-25e-6, -25e-6, -20e-15) - hi = (+25e-6, +25e-6, +20e-15) - npoints = (100, 100, 100) - laser = Laser(dim, lo, hi, npoints, profile) - laser.normalize(laser_energy, kind="energy") - laser.write_to_file("gaussianlaser3d") - executables = glob.glob("*.ex") - if len(executables) == 1 : - launch_analysis(executables[0]) - else : - assert(False) - - # Do the checksum test - filename_end = "diags/plotfiles/plt000251/" - test_name = os.path.split(os.getcwd())[1] - checksumAPI.evaluate_checksum(test_name, filename_end) - print('Passed') - -if __name__ == "__main__": - main() + +filename = sys.argv[1] +compname = "comp_unf.pdf" +steps = 251 +ds = yt.load(filename) +dt = ds.current_time.to_value() / steps + +# Define 3D meshes +x = np.linspace( + ds.domain_left_edge[0], ds.domain_right_edge[0], ds.domain_dimensions[0] +).v +y = np.linspace( + ds.domain_left_edge[1], ds.domain_right_edge[1], ds.domain_dimensions[1] +).v +z = np.linspace( + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_dimensions[ds.dimensionality - 1], +).v +X, Y, Z = np.meshgrid(x, y, z, sparse=False, indexing="ij") + +# Compute the theory for envelope +env_theory = gauss_env(+t_c - ds.current_time.to_value(), X, Y, Z) + gauss_env( + -t_c + ds.current_time.to_value(), X, Y, Z +) + +# Read laser field in PIC simulation, and compute envelope +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +F_laser = all_data_level_0["boxlib", "Ey"].v.squeeze() +env = abs(hilbert(F_laser)) +extent = [ + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_left_edge[0], + ds.domain_right_edge[0], +] + +F_slice = F_laser[:, F_laser.shape[1] // 2, :] +env_slice = env[:, env.shape[1] // 2, :] +env_theory_slice = env_theory[:, env_theory.shape[1] // 2, :] + +# Plot results +plt.figure(figsize=(8, 6)) +plt.subplot(221) +plt.title("PIC field") +plt.imshow(F_slice, extent=extent) +plt.colorbar() +plt.subplot(222) +plt.title("PIC envelope") +plt.imshow(env_slice, extent=extent) +plt.colorbar() +plt.subplot(223) +plt.title("Theory envelope") +plt.imshow(env_theory_slice, extent=extent) +plt.colorbar() +plt.subplot(224) +plt.title("Difference") +plt.imshow(env_slice - env_theory_slice, extent=extent) +plt.colorbar() +plt.tight_layout() +plt.savefig(compname, bbox_inches="tight") + +relative_error_env = np.sum(np.abs(env - env_theory)) / np.sum(np.abs(env)) +print("Relative error envelope: ", relative_error_env) +assert relative_error_env < relative_error_threshold + +fft_F_laser = np.fft.fftn(F_laser) + +freq_x = np.fft.fftfreq(F_laser.shape[0], dt) +freq_y = np.fft.fftfreq(F_laser.shape[1], dt) +freq_z = np.fft.fftfreq(F_laser.shape[2], dt) + +pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) + +freq = np.sqrt( + (freq_x[pos_max[0]]) ** 2 + (freq_y[pos_max[1]] ** 2) + (freq_z[pos_max[2]]) ** 2 +) +exp_freq = c / wavelength +relative_error_freq = np.abs(freq - exp_freq) / exp_freq +print("Relative error frequency: ", relative_error_freq) +assert relative_error_freq < relative_error_threshold + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/laser_injection_from_file/analysis_RZ.py b/Examples/Tests/laser_injection_from_file/analysis_RZ.py deleted file mode 100755 index 3667a1d9419..00000000000 --- a/Examples/Tests/laser_injection_from_file/analysis_RZ.py +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli -# Remi Lehe, Ilian Kara-Mostefa -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - - -# This file is part of the WarpX automated test suite. It is used to test the -# injection of a laser pulse from an external lasy file. -# -# - Generate an input lasy file with a gaussian laser pulse. -# - Run the WarpX simulation for time T, when the pulse is fully injected -# - Compute the theory for laser envelope at time T -# - Compare theory and simulation in RZ, for both envelope and central frequency - -import glob -import os -import sys - -import matplotlib - -matplotlib.use('Agg') -import matplotlib.pyplot as plt -import numpy as np -from scipy.constants import c, epsilon_0 -from scipy.signal import hilbert - -import yt ; yt.funcs.mylog.setLevel(50) - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -#Maximum acceptable error for this test -relative_error_threshold = 0.065 - -#Physical parameters -um = 1.e-6 -fs = 1.e-15 -c = 299792458 - -#Parameters of the gaussian beam -wavelength = 1.*um -w0 = 12.*um -tt = 10.*fs -t_c = 20.*fs - -laser_energy = 1.0 -E_max = np.sqrt( 2*(2/np.pi)**(3/2)*laser_energy / (epsilon_0*w0**2*c*tt) ) - -# Function for the envelope -def gauss_env(T, X, Y, Z): - # Function to compute the theory for the envelope - inv_tau2 = 1./tt/tt - inv_w_2 = 1.0/(w0*w0) - exp_arg = - (X*X)*inv_w_2 - (Y*Y)*inv_w_2- inv_tau2 / c/c * (Z-T*c)*(Z-T*c) - return E_max * np.real(np.exp(exp_arg)) - -def do_analysis(fname, compname, steps): - ds = yt.load(fname) - dt = ds.current_time.to_value()/steps - - # Define 3D meshes - x = np.linspace( - ds.domain_left_edge[0], - ds.domain_right_edge[0], - ds.domain_dimensions[0]).v - y = np.linspace( - ds.domain_left_edge[1], - ds.domain_right_edge[1], - ds.domain_dimensions[1]).v - z = np.linspace( - ds.domain_left_edge[ds.dimensionality-1], - ds.domain_right_edge[ds.dimensionality-1], - ds.domain_dimensions[ds.dimensionality-1]).v - X, Y, Z = np.meshgrid(x, y, z, sparse=False, indexing='ij') - - # Compute the theory for envelope - env_theory = gauss_env(+t_c-ds.current_time.to_value(), X,Y,Z)+gauss_env(-t_c+ds.current_time.to_value(), X,Y,Z) - - # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - F_laser = all_data_level_0['boxlib', 'Et'].v.squeeze() - env = abs(hilbert(F_laser)) - extent = [ds.domain_left_edge[ds.dimensionality-1], ds.domain_right_edge[ds.dimensionality-1], - ds.domain_left_edge[0], ds.domain_right_edge[0] ] - - env_theory_slice= env_theory[:,env_theory.shape[1]//2, :] - - # Plot results - plt.figure(figsize=(8,6)) - plt.subplot(221) - plt.title('PIC field') - plt.imshow(F_laser, extent=extent) - plt.colorbar() - plt.subplot(222) - plt.title('PIC envelope') - plt.imshow(env, extent=extent) - plt.colorbar() - plt.subplot(223) - plt.title('Theory envelope') - plt.imshow(env_theory_slice, extent=extent) - plt.colorbar() - plt.subplot(224) - plt.title('Difference') - plt.imshow(env-env_theory_slice, extent=extent) - plt.colorbar() - plt.tight_layout() - plt.savefig(compname, bbox_inches='tight') - - relative_error_env = np.sum(np.abs(env-env_theory_slice)) / np.sum(np.abs(env)) - print("Relative error envelope: ", relative_error_env) - assert(relative_error_env < relative_error_threshold) - - fft_F_laser = np.fft.fftn(F_laser) - - freq_x = np.fft.fftfreq(F_laser.shape[0],dt) - freq_z = np.fft.fftfreq(F_laser.shape[1],dt) - - pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) - - freq = np.sqrt((freq_x[pos_max[0]])**2 + (freq_z[pos_max[1]])**2) - exp_freq = c/wavelength - relative_error_freq = np.abs(freq-exp_freq)/exp_freq - print("Relative error frequency: ", relative_error_freq) - assert(relative_error_freq < relative_error_threshold) - - - -def launch_analysis(executable): - os.system("./" + executable + " inputs.RZ_test diag1.file_prefix=diags/plotfiles/plt") - do_analysis("diags/plotfiles/plt000252/", "comp_unf.pdf", 252) - - -def main() : - - from lasy.laser import Laser - from lasy.profiles import GaussianProfile - - # Create a laser using lasy - pol = (1, 0) - profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) - dim = "xyt" - lo = (-25e-6, -25e-6, -20e-15) - hi = (+25e-6, +25e-6, +20e-15) - npoints = (100, 100, 100) - laser = Laser(dim, lo, hi, npoints, profile) - laser.normalize(laser_energy, kind="energy") - laser.write_to_file("gaussianlaser3d") - executables = glob.glob("*.ex") - if len(executables) == 1 : - launch_analysis(executables[0]) - else : - assert(False) - - # Do the checksum test - filename_end = "diags/plotfiles/plt000252/" - test_name = os.path.split(os.getcwd())[1] - checksumAPI.evaluate_checksum(test_name, filename_end) - print('Passed') - -if __name__ == "__main__": - main() diff --git a/Examples/Tests/laser_injection_from_file/analysis_from_RZ_file.py b/Examples/Tests/laser_injection_from_file/analysis_from_RZ_file.py index 44bbd00a7f4..72575da96b4 100755 --- a/Examples/Tests/laser_injection_from_file/analysis_from_RZ_file.py +++ b/Examples/Tests/laser_injection_from_file/analysis_from_RZ_file.py @@ -9,174 +9,143 @@ # This file is part of the WarpX automated test suite. It is used to test the -# injection of a laser pulse from an external lasy file. -# -# - Generate an input lasy file with a Laguerre Gaussian laser pulse. -# - Run the WarpX simulation for time T, when the pulse is fully injected +# injection of a laser pulse from an external lasy file: # - Compute the theory for laser envelope at time T # - Compare theory and simulation in RZ, for both envelope and central frequency -import glob import os import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np +import yt from scipy.constants import c, epsilon_0 from scipy.signal import hilbert from scipy.special import genlaguerre -import yt ; yt.funcs.mylog.setLevel(50) +yt.funcs.mylog.setLevel(50) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -#Maximum acceptable error for this test +# Maximum acceptable error for this test relative_error_threshold = 0.065 -#Physical parameters -um = 1.e-6 -fs = 1.e-15 -c = 299792458 +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 -#Parameters of the Laguerre Gaussian beam -wavelength = 1.*um -w0 = 12.*um -tt = 10.*fs -t_c = 20.*fs +# Parameters of the Laguerre Gaussian beam +wavelength = 1.0 * um +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs laser_energy = 1.0 -E_max = np.sqrt( 2*(2/np.pi)**(3/2)*laser_energy / (epsilon_0*w0**2*c*tt) ) +E_max = np.sqrt( + 2 * (2 / np.pi) ** (3 / 2) * laser_energy / (epsilon_0 * w0**2 * c * tt) +) + # Function for the envelope def laguerre_env(T, X, Y, Z, p, m): - if m>0: - complex_position= X -1j * Y + if m > 0: + complex_position = X - 1j * Y else: - complex_position= X +1j * Y - inv_w0_2 = 1.0/(w0**2) - inv_tau2 = 1.0/(tt**2) + complex_position = X + 1j * Y + inv_w0_2 = 1.0 / (w0**2) + inv_tau2 = 1.0 / (tt**2) radius = abs(complex_position) - scaled_rad_squared = (radius**2)*inv_w0_2 + scaled_rad_squared = (radius**2) * inv_w0_2 envelope = ( - ( np.sqrt(2) * complex_position / w0 )** m - * genlaguerre(p, m)(2 * scaled_rad_squared) - * np.exp(-scaled_rad_squared) - * np.exp(-( inv_tau2 / (c**2) ) * (Z-T*c)**2) - ) + (np.sqrt(2) * complex_position / w0) ** m + * genlaguerre(p, m)(2 * scaled_rad_squared) + * np.exp(-scaled_rad_squared) + * np.exp(-(inv_tau2 / (c**2)) * (Z - T * c) ** 2) + ) return E_max * np.real(envelope) -def do_analysis(fname, compname, steps): - ds = yt.load(fname) - dt = ds.current_time.to_value()/steps - - # Define 3D meshes - x = np.linspace( - ds.domain_left_edge[0], - ds.domain_right_edge[0], - ds.domain_dimensions[0]).v - y = np.linspace( - ds.domain_left_edge[1], - ds.domain_right_edge[1], - ds.domain_dimensions[1]).v - z = np.linspace( - ds.domain_left_edge[ds.dimensionality-1], - ds.domain_right_edge[ds.dimensionality-1], - ds.domain_dimensions[ds.dimensionality-1]).v - X, Y, Z = np.meshgrid(x, y, z, sparse=False, indexing='ij') - - # Compute the theory for envelope - env_theory = laguerre_env(+t_c-ds.current_time.to_value(), X,Y,Z,p=0,m=1)+laguerre_env(-t_c+ds.current_time.to_value(), X,Y,Z,p=0,m=1) - - # Read laser field in PIC simulation, and compute envelope - all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - F_laser = all_data_level_0['boxlib', 'Et'].v.squeeze() - env = abs(hilbert(F_laser)) - extent = [ds.domain_left_edge[ds.dimensionality-1], ds.domain_right_edge[ds.dimensionality-1], - ds.domain_left_edge[0], ds.domain_right_edge[0] ] - - env_theory_slice= env_theory[:,env_theory.shape[1]//2, :] - - # Plot results - plt.figure(figsize=(8,6)) - plt.subplot(221) - plt.title('PIC field') - plt.imshow(F_laser, extent=extent) - plt.colorbar() - plt.subplot(222) - plt.title('PIC envelope') - plt.imshow(env, extent=extent) - plt.colorbar() - plt.subplot(223) - plt.title('Theory envelope') - plt.imshow(env_theory_slice, extent=extent) - plt.colorbar() - plt.subplot(224) - plt.title('Difference') - plt.imshow(env-env_theory_slice, extent=extent) - plt.colorbar() - plt.tight_layout() - plt.savefig(compname, bbox_inches='tight') - - relative_error_env = np.sum(np.abs(env-env_theory_slice)) / np.sum(np.abs(env)) - print("Relative error envelope: ", relative_error_env) - assert(relative_error_env < relative_error_threshold) - - fft_F_laser = np.fft.fftn(F_laser) - - freq_x = np.fft.fftfreq(F_laser.shape[0],dt) - freq_z = np.fft.fftfreq(F_laser.shape[1],dt) - - pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) - - freq = np.sqrt((freq_x[pos_max[0]])**2 + (freq_z[pos_max[1]])**2) - exp_freq = c/wavelength - relative_error_freq = np.abs(freq-exp_freq)/exp_freq - print("Relative error frequency: ", relative_error_freq) - assert(relative_error_freq < relative_error_threshold) - - - -def launch_analysis(executable): - os.system("./" + executable + " inputs.from_RZ_file_test diag1.file_prefix=diags/plotfiles/plt") - do_analysis("diags/plotfiles/plt000612/", "comp_unf.pdf", 612) - - -def main() : - - from lasy.laser import Laser - from lasy.profiles import CombinedLongitudinalTransverseProfile, GaussianProfile - from lasy.profiles.longitudinal import GaussianLongitudinalProfile - from lasy.profiles.transverse import LaguerreGaussianTransverseProfile - - # Create a Laguerre Gaussian laser in RZ geometry using lasy - pol = (1, 0) - profile = CombinedLongitudinalTransverseProfile( - wavelength,pol,laser_energy, - GaussianLongitudinalProfile(wavelength, tt, t_peak=0), - LaguerreGaussianTransverseProfile(w0, p=0, m=1), - ) - dim = "rt" - lo = (0e-6, -20e-15) - hi = (+25e-6, +20e-15) - npoints = (100,100) - laser = Laser(dim, lo, hi, npoints, profile, n_azimuthal_modes=2) - laser.normalize(laser_energy, kind="energy") - laser.write_to_file("laguerrelaserRZ") - executables = glob.glob("*.ex") - if len(executables) == 1 : - launch_analysis(executables[0]) - else : - assert(False) - - # Do the checksum test - filename_end = "diags/plotfiles/plt000612/" - test_name = "LaserInjectionFromRZLASYFile" - checksumAPI.evaluate_checksum(test_name, filename_end) - print('Passed') - -if __name__ == "__main__": - main() + +filename = sys.argv[1] +compname = "comp_unf.pdf" +steps = 612 +ds = yt.load(filename) +dt = ds.current_time.to_value() / steps + +# Define 3D meshes +x = np.linspace( + ds.domain_left_edge[0], ds.domain_right_edge[0], ds.domain_dimensions[0] +).v +y = np.linspace( + ds.domain_left_edge[1], ds.domain_right_edge[1], ds.domain_dimensions[1] +).v +z = np.linspace( + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_dimensions[ds.dimensionality - 1], +).v +X, Y, Z = np.meshgrid(x, y, z, sparse=False, indexing="ij") + +# Compute the theory for envelope +env_theory = laguerre_env( + +t_c - ds.current_time.to_value(), X, Y, Z, p=0, m=1 +) + laguerre_env(-t_c + ds.current_time.to_value(), X, Y, Z, p=0, m=1) + +# Read laser field in PIC simulation, and compute envelope +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +F_laser = all_data_level_0["boxlib", "Et"].v.squeeze() +env = abs(hilbert(F_laser)) +extent = [ + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_left_edge[0], + ds.domain_right_edge[0], +] + +env_theory_slice = env_theory[:, env_theory.shape[1] // 2, :] + +# Plot results +plt.figure(figsize=(8, 6)) +plt.subplot(221) +plt.title("PIC field") +plt.imshow(F_laser, extent=extent) +plt.colorbar() +plt.subplot(222) +plt.title("PIC envelope") +plt.imshow(env, extent=extent) +plt.colorbar() +plt.subplot(223) +plt.title("Theory envelope") +plt.imshow(env_theory_slice, extent=extent) +plt.colorbar() +plt.subplot(224) +plt.title("Difference") +plt.imshow(env - env_theory_slice, extent=extent) +plt.colorbar() +plt.tight_layout() +plt.savefig(compname, bbox_inches="tight") + +relative_error_env = np.sum(np.abs(env - env_theory_slice)) / np.sum(np.abs(env)) +print("Relative error envelope: ", relative_error_env) +assert relative_error_env < relative_error_threshold + +fft_F_laser = np.fft.fftn(F_laser) + +freq_x = np.fft.fftfreq(F_laser.shape[0], dt) +freq_z = np.fft.fftfreq(F_laser.shape[1], dt) + +pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) + +freq = np.sqrt((freq_x[pos_max[0]]) ** 2 + (freq_z[pos_max[1]]) ** 2) +exp_freq = c / wavelength +relative_error_freq = np.abs(freq - exp_freq) / exp_freq +print("Relative error frequency: ", relative_error_freq) +assert relative_error_freq < relative_error_threshold + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/laser_injection_from_file/analysis_rz.py b/Examples/Tests/laser_injection_from_file/analysis_rz.py new file mode 100755 index 00000000000..90e392bcf25 --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/analysis_rz.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli +# Remi Lehe, Ilian Kara-Mostefa +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +# This file is part of the WarpX automated test suite. It is used to test the +# injection of a laser pulse from an external lasy file: +# - Compute the theory for laser envelope at time T +# - Compare theory and simulation in RZ, for both envelope and central frequency + +import os +import sys + +import matplotlib + +matplotlib.use("Agg") +import matplotlib.pyplot as plt +import numpy as np +import yt +from scipy.constants import c, epsilon_0 +from scipy.signal import hilbert + +yt.funcs.mylog.setLevel(50) + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# Maximum acceptable error for this test +relative_error_threshold = 0.065 + +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 + +# Parameters of the gaussian beam +wavelength = 1.0 * um +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs + +laser_energy = 1.0 +E_max = np.sqrt( + 2 * (2 / np.pi) ** (3 / 2) * laser_energy / (epsilon_0 * w0**2 * c * tt) +) + + +# Function for the envelope +def gauss_env(T, X, Y, Z): + # Function to compute the theory for the envelope + inv_tau2 = 1.0 / tt / tt + inv_w_2 = 1.0 / (w0 * w0) + exp_arg = ( + -(X * X) * inv_w_2 + - (Y * Y) * inv_w_2 + - inv_tau2 / c / c * (Z - T * c) * (Z - T * c) + ) + return E_max * np.real(np.exp(exp_arg)) + + +filename = sys.argv[1] +compname = "comp_unf.pdf" +steps = 252 +ds = yt.load(filename) +dt = ds.current_time.to_value() / steps + +# Define 3D meshes +x = np.linspace( + ds.domain_left_edge[0], ds.domain_right_edge[0], ds.domain_dimensions[0] +).v +y = np.linspace( + ds.domain_left_edge[1], ds.domain_right_edge[1], ds.domain_dimensions[1] +).v +z = np.linspace( + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_dimensions[ds.dimensionality - 1], +).v +X, Y, Z = np.meshgrid(x, y, z, sparse=False, indexing="ij") + +# Compute the theory for envelope +env_theory = gauss_env(+t_c - ds.current_time.to_value(), X, Y, Z) + gauss_env( + -t_c + ds.current_time.to_value(), X, Y, Z +) + +# Read laser field in PIC simulation, and compute envelope +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +F_laser = all_data_level_0["boxlib", "Et"].v.squeeze() +env = abs(hilbert(F_laser)) +extent = [ + ds.domain_left_edge[ds.dimensionality - 1], + ds.domain_right_edge[ds.dimensionality - 1], + ds.domain_left_edge[0], + ds.domain_right_edge[0], +] + +env_theory_slice = env_theory[:, env_theory.shape[1] // 2, :] + +# Plot results +plt.figure(figsize=(8, 6)) +plt.subplot(221) +plt.title("PIC field") +plt.imshow(F_laser, extent=extent) +plt.colorbar() +plt.subplot(222) +plt.title("PIC envelope") +plt.imshow(env, extent=extent) +plt.colorbar() +plt.subplot(223) +plt.title("Theory envelope") +plt.imshow(env_theory_slice, extent=extent) +plt.colorbar() +plt.subplot(224) +plt.title("Difference") +plt.imshow(env - env_theory_slice, extent=extent) +plt.colorbar() +plt.tight_layout() +plt.savefig(compname, bbox_inches="tight") + +relative_error_env = np.sum(np.abs(env - env_theory_slice)) / np.sum(np.abs(env)) +print("Relative error envelope: ", relative_error_env) +assert relative_error_env < relative_error_threshold + +fft_F_laser = np.fft.fftn(F_laser) + +freq_x = np.fft.fftfreq(F_laser.shape[0], dt) +freq_z = np.fft.fftfreq(F_laser.shape[1], dt) + +pos_max = np.unravel_index(np.abs(fft_F_laser).argmax(), fft_F_laser.shape) + +freq = np.sqrt((freq_x[pos_max[0]]) ** 2 + (freq_z[pos_max[1]]) ** 2) +exp_freq = c / wavelength +relative_error_freq = np.abs(freq - exp_freq) / exp_freq +print("Relative error frequency: ", relative_error_freq) +assert relative_error_freq < relative_error_threshold + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/laser_injection_from_file/inputs.1d_test b/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file similarity index 93% rename from Examples/Tests/laser_injection_from_file/inputs.1d_test rename to Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file index 6124b4552a2..1510a8df4c3 100644 --- a/Examples/Tests/laser_injection_from_file/inputs.1d_test +++ b/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file @@ -40,7 +40,7 @@ lasy_laser.e_max = 1.e14 # Maximum amplitude of the laser field (i lasy_laser.wavelength = 1.0e-6 # The wavelength of the laser (in meters) lasy_laser.profile = from_file lasy_laser.time_chunk_size = 50 -lasy_laser.lasy_file_name = "gaussianlaser3d_00000.h5" +lasy_laser.lasy_file_name = "../test_1d_laser_injection_from_lasy_file_prepare/diags/gaussian_laser_3d_00000.h5" lasy_laser.delay = 0.0 # Diagnostics diff --git a/Examples/Tests/laser_injection_from_file/inputs.1d_boost_test b/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_boost similarity index 93% rename from Examples/Tests/laser_injection_from_file/inputs.1d_boost_test rename to Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_boost index adfde819531..d118ce85ae5 100644 --- a/Examples/Tests/laser_injection_from_file/inputs.1d_boost_test +++ b/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_boost @@ -47,7 +47,7 @@ lasy_laser.e_max = 1.e14 # Maximum amplitude of the laser field (i lasy_laser.wavelength = 1.0e-6 # The wavelength of the laser (in meters) lasy_laser.profile = from_file lasy_laser.time_chunk_size = 50 -lasy_laser.lasy_file_name = "gaussianlaser3d_00000.h5" +lasy_laser.lasy_file_name = "../test_1d_laser_injection_from_lasy_file_boost_prepare/diags/gaussian_laser_3d_00000.h5" lasy_laser.delay = 0.0 # Diagnostics diff --git a/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_boost_prepare.py b/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_boost_prepare.py new file mode 100755 index 00000000000..f71b87d5fc8 --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_boost_prepare.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli +# Remi Lehe, Ilian Kara-Mostefa +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +# This file is part of the WarpX automated test suite. It is used to test the +# injection of a laser pulse from an external lasy file: +# - Generate an input lasy file with a gaussian laser pulse. + +from lasy.laser import Laser +from lasy.profiles import GaussianProfile + +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 + +# Parameters of the Gaussian beam +wavelength = 1.0 * um +pol = (1, 0) +laser_energy = 1.0 +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs + +# Create a laser using lasy +profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) +dim = "xyt" +lo = (-25e-6, -25e-6, -20e-15) +hi = (+25e-6, +25e-6, +20e-15) +npoints = (100, 100, 100) +laser = Laser(dim, lo, hi, npoints, profile) +laser.normalize(laser_energy, kind="energy") +laser.write_to_file("gaussian_laser_3d") diff --git a/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_prepare.py b/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_prepare.py new file mode 100755 index 00000000000..902b0c47210 --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/inputs_test_1d_laser_injection_from_lasy_file_prepare.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli +# Remi Lehe, Ilian Kara-Mostefa +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +# This file is part of the WarpX automated test suite. It is used to test the +# injection of a laser pulse from an external lasy file: +# - Generate an input lasy file with a gaussian laser pulse. + +from lasy.laser import Laser +from lasy.profiles import GaussianProfile + +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 + +# Parameters of the Gaussian beam +wavelength = 1.0 * um +pol = (1, 0) +laser_energy = 1.0 +w0 = 12.0 * um +tt = 10.0 * fs + +# Create a laser using lasy +profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) +dim = "xyt" +lo = (-25e-6, -25e-6, -20e-15) +hi = (+25e-6, +25e-6, +20e-15) +npoints = (100, 100, 100) +laser = Laser(dim, lo, hi, npoints, profile) +laser.normalize(laser_energy, kind="energy") +laser.write_to_file("gaussian_laser_3d") diff --git a/Examples/Tests/laser_injection_from_file/inputs.2d_test_binary b/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_binary_file similarity index 94% rename from Examples/Tests/laser_injection_from_file/inputs.2d_test_binary rename to Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_binary_file index fdb19f406ca..022da5b0e29 100644 --- a/Examples/Tests/laser_injection_from_file/inputs.2d_test_binary +++ b/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_binary_file @@ -40,7 +40,7 @@ binary_laser.polarization = 0. 1. 0. # The main polarization vector binary_laser.e_max = 1.e12 # Maximum amplitude of the laser field (in V/m) binary_laser.wavelength = 1.0e-6 # The wavelength of the laser (in meters) binary_laser.profile = from_file -binary_laser.binary_file_name = "gauss_2d" +binary_laser.binary_file_name = "../test_2d_laser_injection_from_binary_file_prepare/gauss_2d" binary_laser.time_chunk_size = 50 binary_laser.delay = 0.0 diff --git a/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_binary_file_prepare.py b/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_binary_file_prepare.py new file mode 100755 index 00000000000..d8fe2236ae0 --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_binary_file_prepare.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli +# Remi Lehe, Ilian Kara-Mostefa +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +# This file is part of the WarpX automated test suite. It is used to test the +# injection of a laser pulse from an external binary file: +# - Generate an input binary file with a gaussian laser pulse. + +import sys + +import matplotlib + +matplotlib.use("Agg") +import numpy as np +import yt + +yt.funcs.mylog.setLevel(50) + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") + +# Maximum acceptable error for this test +relative_error_threshold = 0.065 + +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 +c = 299792458 + +# Parameters of the gaussian beam +wavelength = 1.0 * um +w0 = 6.0 * um +tt = 10.0 * fs +x_c = 0.0 * um +t_c = 20.0 * fs +foc_dist = 10 * um +E_max = 1e12 +rot_angle = -np.pi / 4.0 + +# Parameters of the tx grid +x_l = -12.0 * um +x_r = 12.0 * um +x_points = 480 +t_l = 0.0 * fs +t_r = 40.0 * fs +t_points = 400 +tcoords = np.linspace(t_l, t_r, t_points) +xcoords = np.linspace(x_l, x_r, x_points) + + +def gauss(T, X, Y, opt): + """Compute the electric field for a Gaussian laser pulse. + This is used to write the binary input file. + """ + + k0 = 2.0 * np.pi / wavelength + inv_tau2 = 1.0 / tt / tt + osc_phase = k0 * c * (T - t_c) + + diff_factor = 1.0 + 1.0j * foc_dist * 2 / (k0 * w0 * w0) + inv_w_2 = 1.0 / (w0 * w0 * diff_factor) + + pre_fact = np.exp(1.0j * osc_phase) + + if opt == "3d": + pre_fact = pre_fact / diff_factor + else: + pre_fact = pre_fact / np.sqrt(diff_factor) + + exp_arg = -(X * X + Y * Y) * inv_w_2 - inv_tau2 * (T - t_c) * (T - t_c) + + return np.real(pre_fact * np.exp(exp_arg)) + + +def write_file(fname, x, y, t, E): + """For a given filename fname, space coordinates x and y, time coordinate t + and field E, write a WarpX-compatible input binary file containing the + profile of the laser pulse. This function should be used in the case + of a uniform spatio-temporal mesh + """ + + with open(fname, "wb") as file: + flag_unif = 1 + file.write(flag_unif.to_bytes(1, byteorder="little")) + file.write((len(t)).to_bytes(4, byteorder="little", signed=False)) + file.write((len(x)).to_bytes(4, byteorder="little", signed=False)) + file.write((len(y)).to_bytes(4, byteorder="little", signed=False)) + file.write(t[0].tobytes()) + file.write(t[-1].tobytes()) + file.write(x[0].tobytes()) + file.write(x[-1].tobytes()) + if len(y) == 1: + file.write(y[0].tobytes()) + else: + file.write(y[0].tobytes()) + file.write(y[-1].tobytes()) + file.write(E.tobytes()) + + +T, X, Y = np.meshgrid(tcoords, xcoords, np.array([0.0]), indexing="ij") +E_t = gauss(T, X, Y, "2d") +write_file("gauss_2d", xcoords, np.array([0.0]), tcoords, E_t) diff --git a/Examples/Tests/laser_injection_from_file/inputs.2d_test b/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_lasy_file similarity index 93% rename from Examples/Tests/laser_injection_from_file/inputs.2d_test rename to Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_lasy_file index a3003a4978d..f6a0693a5bd 100644 --- a/Examples/Tests/laser_injection_from_file/inputs.2d_test +++ b/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_lasy_file @@ -40,7 +40,7 @@ lasy_laser.e_max = 1.e14 # Maximum amplitude of the laser field (i lasy_laser.wavelength = 1.0e-6 # The wavelength of the laser (in meters) lasy_laser.profile = from_file lasy_laser.time_chunk_size = 50 -lasy_laser.lasy_file_name = "gaussianlaser3d_00000.h5" +lasy_laser.lasy_file_name = "../test_2d_laser_injection_from_lasy_file_prepare/diags/gaussian_laser_3d_00000.h5" lasy_laser.delay = 0.0 # Diagnostics diff --git a/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_lasy_file_prepare.py b/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_lasy_file_prepare.py new file mode 100755 index 00000000000..f71b87d5fc8 --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/inputs_test_2d_laser_injection_from_lasy_file_prepare.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli +# Remi Lehe, Ilian Kara-Mostefa +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +# This file is part of the WarpX automated test suite. It is used to test the +# injection of a laser pulse from an external lasy file: +# - Generate an input lasy file with a gaussian laser pulse. + +from lasy.laser import Laser +from lasy.profiles import GaussianProfile + +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 + +# Parameters of the Gaussian beam +wavelength = 1.0 * um +pol = (1, 0) +laser_energy = 1.0 +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs + +# Create a laser using lasy +profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) +dim = "xyt" +lo = (-25e-6, -25e-6, -20e-15) +hi = (+25e-6, +25e-6, +20e-15) +npoints = (100, 100, 100) +laser = Laser(dim, lo, hi, npoints, profile) +laser.normalize(laser_energy, kind="energy") +laser.write_to_file("gaussian_laser_3d") diff --git a/Examples/Tests/laser_injection_from_file/inputs.3d_test b/Examples/Tests/laser_injection_from_file/inputs_test_3d_laser_injection_from_lasy_file similarity index 93% rename from Examples/Tests/laser_injection_from_file/inputs.3d_test rename to Examples/Tests/laser_injection_from_file/inputs_test_3d_laser_injection_from_lasy_file index e3096bf92d9..534ea729886 100644 --- a/Examples/Tests/laser_injection_from_file/inputs.3d_test +++ b/Examples/Tests/laser_injection_from_file/inputs_test_3d_laser_injection_from_lasy_file @@ -40,7 +40,7 @@ lasy_laser.e_max = 1.e14 # Maximum amplitude of the laser field (i lasy_laser.wavelength = 1.0e-6 # The wavelength of the laser (in meters) lasy_laser.profile = from_file lasy_laser.time_chunk_size = 50 -lasy_laser.lasy_file_name = "gaussianlaser3d_00000.h5" +lasy_laser.lasy_file_name = "../test_3d_laser_injection_from_lasy_file_prepare/diags/gaussian_laser_3d_00000.h5" lasy_laser.delay = 0.0 # Diagnostics diff --git a/Examples/Tests/laser_injection_from_file/inputs_test_3d_laser_injection_from_lasy_file_prepare.py b/Examples/Tests/laser_injection_from_file/inputs_test_3d_laser_injection_from_lasy_file_prepare.py new file mode 100755 index 00000000000..410dcd2c36e --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/inputs_test_3d_laser_injection_from_lasy_file_prepare.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli +# Remi Lehe, Ilian Kara-Mostefa +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +# This file is part of the WarpX automated test suite. It is used to test the +# injection of a laser pulse from an external lasy file: +# - Generate an input lasy file with a gaussian laser pulse. + +from lasy.laser import Laser +from lasy.profiles import GaussianProfile + +# Maximum acceptable error for this test +relative_error_threshold = 0.065 + +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 + +# Parameters of the Gaussian beam +wavelength = 1.0 * um +pol = (1, 0) +laser_energy = 1.0 +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs + +# Create a laser using lasy +profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) +dim = "xyt" +lo = (-25e-6, -25e-6, -20e-15) +hi = (+25e-6, +25e-6, +20e-15) +npoints = (100, 100, 100) +laser = Laser(dim, lo, hi, npoints, profile) +laser.normalize(laser_energy, kind="energy") +laser.write_to_file("gaussian_laser_3d") diff --git a/Examples/Tests/laser_injection_from_file/inputs.from_RZ_file_test b/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_RZ_lasy_file similarity index 93% rename from Examples/Tests/laser_injection_from_file/inputs.from_RZ_file_test rename to Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_RZ_lasy_file index ca50430c21a..a4c87d244fc 100644 --- a/Examples/Tests/laser_injection_from_file/inputs.from_RZ_file_test +++ b/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_RZ_lasy_file @@ -40,7 +40,7 @@ lasy_RZ_laser.e_max = 1.e14 # Maximum amplitude of the laser field lasy_RZ_laser.wavelength = 1.0e-6 # The wavelength of the laser (in meters) lasy_RZ_laser.profile = from_file lasy_RZ_laser.time_chunk_size = 50 -lasy_RZ_laser.lasy_file_name = "laguerrelaserRZ_00000.h5" +lasy_RZ_laser.lasy_file_name = "../test_rz_laser_injection_from_RZ_lasy_file_prepare/diags/laguerre_laser_RZ_00000.h5" lasy_RZ_laser.delay = 0.0 # Diagnostics diff --git a/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_RZ_lasy_file_prepare.py b/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_RZ_lasy_file_prepare.py new file mode 100755 index 00000000000..1a1dfabe86e --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_RZ_lasy_file_prepare.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli +# Remi Lehe, Ilian Kara-Mostefa +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +# This file is part of the WarpX automated test suite. It is used to test the +# injection of a laser pulse from an external lasy file: +# - Generate an input lasy file with a Laguerre Gaussian laser pulse. + +from lasy.laser import Laser +from lasy.profiles import CombinedLongitudinalTransverseProfile +from lasy.profiles.longitudinal import GaussianLongitudinalProfile +from lasy.profiles.transverse import LaguerreGaussianTransverseProfile + +# Maximum acceptable error for this test +relative_error_threshold = 0.065 + +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 + +# Parameters of the Laguerre Gaussian beam +wavelength = 1.0 * um +pol = (1, 0) +laser_energy = 1.0 +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs + +# Create a Laguerre Gaussian laser in RZ geometry using lasy +profile = CombinedLongitudinalTransverseProfile( + wavelength, + pol, + laser_energy, + GaussianLongitudinalProfile(wavelength, tt, t_peak=0), + LaguerreGaussianTransverseProfile(w0, p=0, m=1), +) +dim = "rt" +lo = (0e-6, -20e-15) +hi = (+25e-6, +20e-15) +npoints = (100, 100) +laser = Laser(dim, lo, hi, npoints, profile, n_azimuthal_modes=2) +laser.normalize(laser_energy, kind="energy") +laser.write_to_file("laguerre_laser_RZ") diff --git a/Examples/Tests/laser_injection_from_file/inputs.RZ_test b/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_lasy_file similarity index 93% rename from Examples/Tests/laser_injection_from_file/inputs.RZ_test rename to Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_lasy_file index fe5bb675212..cc7100afb9d 100644 --- a/Examples/Tests/laser_injection_from_file/inputs.RZ_test +++ b/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_lasy_file @@ -41,7 +41,7 @@ lasy_laser.e_max = 1.e14 # Maximum amplitude of the laser field (i lasy_laser.wavelength = 1.0e-6 # The wavelength of the laser (in meters) lasy_laser.profile = from_file lasy_laser.time_chunk_size = 50 -lasy_laser.lasy_file_name = "gaussianlaser3d_00000.h5" +lasy_laser.lasy_file_name = "../test_rz_laser_injection_from_lasy_file_prepare/diags/gaussian_laser_3d_00000.h5" lasy_laser.delay = 0.0 # Diagnostics diff --git a/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_lasy_file_prepare.py b/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_lasy_file_prepare.py new file mode 100755 index 00000000000..410dcd2c36e --- /dev/null +++ b/Examples/Tests/laser_injection_from_file/inputs_test_rz_laser_injection_from_lasy_file_prepare.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Andrew Myers, Axel Huebl, Luca Fedeli +# Remi Lehe, Ilian Kara-Mostefa +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + + +# This file is part of the WarpX automated test suite. It is used to test the +# injection of a laser pulse from an external lasy file: +# - Generate an input lasy file with a gaussian laser pulse. + +from lasy.laser import Laser +from lasy.profiles import GaussianProfile + +# Maximum acceptable error for this test +relative_error_threshold = 0.065 + +# Physical parameters +um = 1.0e-6 +fs = 1.0e-15 + +# Parameters of the Gaussian beam +wavelength = 1.0 * um +pol = (1, 0) +laser_energy = 1.0 +w0 = 12.0 * um +tt = 10.0 * fs +t_c = 20.0 * fs + +# Create a laser using lasy +profile = GaussianProfile(wavelength, pol, laser_energy, w0, tt, t_peak=0) +dim = "xyt" +lo = (-25e-6, -25e-6, -20e-15) +hi = (+25e-6, +25e-6, +20e-15) +npoints = (100, 100, 100) +laser = Laser(dim, lo, hi, npoints, profile) +laser.normalize(laser_energy, kind="energy") +laser.write_to_file("gaussian_laser_3d") diff --git a/Examples/Tests/laser_on_fine/CMakeLists.txt b/Examples/Tests/laser_on_fine/CMakeLists.txt new file mode 100644 index 00000000000..479374137df --- /dev/null +++ b/Examples/Tests/laser_on_fine/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_laser_on_fine # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_on_fine # inputs + analysis_default_regression.py # analysis + diags/diag1000050 # output + OFF # dependency +) diff --git a/Examples/Tests/laser_on_fine/analysis_default_regression.py b/Examples/Tests/laser_on_fine/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/laser_on_fine/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/laser_on_fine/inputs_2d b/Examples/Tests/laser_on_fine/inputs_test_2d_laser_on_fine similarity index 99% rename from Examples/Tests/laser_on_fine/inputs_2d rename to Examples/Tests/laser_on_fine/inputs_test_2d_laser_on_fine index 1ffbfcb7e09..61c10e81f3e 100644 --- a/Examples/Tests/laser_on_fine/inputs_2d +++ b/Examples/Tests/laser_on_fine/inputs_test_2d_laser_on_fine @@ -1,5 +1,5 @@ # Maximum number of time steps -max_step = 500 +max_step = 50 # number of grid points amr.n_cell = 64 64 diff --git a/Examples/Tests/load_external_field/CMakeLists.txt b/Examples/Tests/load_external_field/CMakeLists.txt new file mode 100644 index 00000000000..0713dc877df --- /dev/null +++ b/Examples/Tests/load_external_field/CMakeLists.txt @@ -0,0 +1,62 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_load_external_field_grid_picmi # name + 3 # dims + 1 # nprocs + inputs_test_3d_load_external_field_grid_picmi.py # inputs + analysis_3d.py # analysis + diags/diag1000300 # output + OFF # dependency +) + +add_warpx_test( + test_3d_load_external_field_particle_picmi # name + 3 # dims + 1 # nprocs + inputs_test_3d_load_external_field_particle_picmi.py # inputs + analysis_3d.py # analysis + diags/diag1000300 # output + OFF # dependency +) + +add_warpx_test( + test_rz_load_external_field_grid # name + RZ # dims + 1 # nprocs + inputs_test_rz_load_external_field_grid # inputs + analysis_rz.py # analysis + diags/diag1000300 # output + OFF # dependency +) + +add_warpx_test( + test_rz_load_external_field_grid_restart # name + RZ # dims + 1 # nprocs + inputs_test_rz_load_external_field_grid_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000300 # output + test_rz_load_external_field_grid # dependency +) + +add_warpx_test( + test_rz_load_external_field_particles # name + RZ # dims + 1 # nprocs + inputs_test_rz_load_external_field_particles # inputs + analysis_rz.py # analysis + diags/diag1000300 # output + OFF # dependency +) + +add_warpx_test( + test_rz_load_external_field_particles_restart # name + RZ # dims + 1 # nprocs + inputs_test_rz_load_external_field_particles_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000300 # output + test_rz_load_external_field_particles # dependency +) diff --git a/Examples/Tests/LoadExternalField/analysis_3d.py b/Examples/Tests/load_external_field/analysis_3d.py similarity index 66% rename from Examples/Tests/LoadExternalField/analysis_3d.py rename to Examples/Tests/load_external_field/analysis_3d.py index 0539448f873..0865584d683 100755 --- a/Examples/Tests/LoadExternalField/analysis_3d.py +++ b/Examples/Tests/load_external_field/analysis_3d.py @@ -22,7 +22,7 @@ import numpy as np import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI tolerance = 1.0e-8 @@ -32,17 +32,17 @@ filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) ad = ds.all_data() -x = ad['proton','particle_position_x'].to_ndarray() -y = ad['proton','particle_position_y'].to_ndarray() -z = ad['proton','particle_position_z'].to_ndarray() +x = ad["proton", "particle_position_x"].to_ndarray() +y = ad["proton", "particle_position_y"].to_ndarray() +z = ad["proton", "particle_position_z"].to_ndarray() -error = np.min(np.sqrt((x-x0)**2+(y-y0)**2+(z-z0)**2)) +error = np.min(np.sqrt((x - x0) ** 2 + (y - y0) ** 2 + (z - z0) ** 2)) -print('error = ', error) -print('tolerance = ', tolerance) -assert(error < tolerance) +print("error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/load_external_field/analysis_default_restart.py b/Examples/Tests/load_external_field/analysis_default_restart.py new file mode 120000 index 00000000000..0459986eebc --- /dev/null +++ b/Examples/Tests/load_external_field/analysis_default_restart.py @@ -0,0 +1 @@ +../../analysis_default_restart.py \ No newline at end of file diff --git a/Examples/Tests/LoadExternalField/analysis_rz.py b/Examples/Tests/load_external_field/analysis_rz.py similarity index 69% rename from Examples/Tests/LoadExternalField/analysis_rz.py rename to Examples/Tests/load_external_field/analysis_rz.py index fd82fbbdac6..75d9c084718 100755 --- a/Examples/Tests/LoadExternalField/analysis_rz.py +++ b/Examples/Tests/load_external_field/analysis_rz.py @@ -22,7 +22,7 @@ import numpy as np import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI tolerance = 1.0e-8 @@ -30,16 +30,16 @@ z0 = 4.3632492 filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) ad = ds.all_data() -r = ad['proton','particle_position_x'].to_ndarray() -z = ad['proton','particle_position_y'].to_ndarray() +r = ad["proton", "particle_position_x"].to_ndarray() +z = ad["proton", "particle_position_y"].to_ndarray() -error = np.min(np.sqrt((r-r0)**2+(z-z0)**2)) +error = np.min(np.sqrt((r - r0) ** 2 + (z - z0) ** 2)) -print('error = ', error) -print('tolerance = ', tolerance) -assert(error < tolerance) +print("error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/load_external_field/inputs_test_3d_load_external_field_grid_picmi.py b/Examples/Tests/load_external_field/inputs_test_3d_load_external_field_grid_picmi.py new file mode 100644 index 00000000000..ee24fb667cf --- /dev/null +++ b/Examples/Tests/load_external_field/inputs_test_3d_load_external_field_grid_picmi.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python3 +# +# --- Input file for loading initial field from openPMD file. + +from pywarpx import picmi + +constants = picmi.constants + +################################# +####### GENERAL PARAMETERS ###### +################################# + +max_steps = 300 + +max_grid_size = 40 +nx = max_grid_size +ny = max_grid_size +nz = max_grid_size + +xmin = -1 +xmax = 1 +ymin = xmin +ymax = xmax +zmin = 0 +zmax = 5 + +number_per_cell = 200 + +################################# +############ NUMERICS ########### +################################# + +verbose = 1 +dt = 4.4e-7 +use_filter = 0 + +# Order of particle shape factors +particle_shape = 1 + +################################# +############ PLASMA ############# +################################# + +ion_dist = picmi.ParticleListDistribution( + x=0.0, + y=0.2, + z=2.5, + ux=9.5e-05 * constants.c, + uy=0.0 * constants.c, + uz=1.34e-4 * constants.c, + weight=1.0, +) + +ions = picmi.Species( + particle_type="H", + name="proton", + charge="q_e", + mass="m_p", + warpx_do_not_deposit=1, + initial_distribution=ion_dist, +) + +################################# +######## INITIAL FIELD ########## +################################# + +initial_field = picmi.LoadInitialField( + read_fields_from_path="../../../../openPMD-example-datasets/example-femm-3d.h5", + load_E=False, +) + +################################# +###### GRID AND SOLVER ########## +################################# + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + warpx_max_grid_size=max_grid_size, + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], +) +solver = picmi.ElectrostaticSolver(grid=grid) + +################################# +######### DIAGNOSTICS ########### +################################# + +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=300, + species=[ions], + data_list=["ux", "uy", "uz", "x", "y", "z", "weighting"], +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=300, + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez", "Jx", "Jy", "Jz"], +) + +################################# +####### SIMULATION SETUP ######## +################################# + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=verbose, + warpx_serialize_initial_conditions=False, + warpx_grid_type="collocated", + warpx_do_dynamic_scheduling=False, + warpx_use_filter=use_filter, + time_step_size=dt, + particle_shape=particle_shape, +) + +sim.add_applied_field(initial_field) + +sim.add_species( + ions, + layout=picmi.PseudoRandomLayout( + n_macroparticles_per_cell=number_per_cell, grid=grid + ), +) + +sim.add_diagnostic(field_diag) +sim.add_diagnostic(particle_diag) + +################################# +##### SIMULATION EXECUTION ###### +################################# + +# sim.write_input_file('inputs_test_3d_load_external_field_grid') +sim.step(max_steps) diff --git a/Examples/Tests/load_external_field/inputs_test_3d_load_external_field_particle_picmi.py b/Examples/Tests/load_external_field/inputs_test_3d_load_external_field_particle_picmi.py new file mode 100644 index 00000000000..75977a01729 --- /dev/null +++ b/Examples/Tests/load_external_field/inputs_test_3d_load_external_field_particle_picmi.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python3 +# +# --- Input file for loading initial field from openPMD file. + +from pywarpx import picmi + +constants = picmi.constants + +################################# +####### GENERAL PARAMETERS ###### +################################# + +max_steps = 300 + +max_grid_size = 40 +nx = max_grid_size +ny = max_grid_size +nz = max_grid_size + +xmin = -1 +xmax = 1 +ymin = xmin +ymax = xmax +zmin = 0 +zmax = 5 + +number_per_cell = 200 + +################################# +############ NUMERICS ########### +################################# + +verbose = 1 +dt = 4.4e-7 +use_filter = 0 + +# Order of particle shape factors +particle_shape = 1 + +################################# +############ PLASMA ############# +################################# + +ion_dist = picmi.ParticleListDistribution( + x=0.0, + y=0.2, + z=2.5, + ux=9.5e-05 * constants.c, + uy=0.0 * constants.c, + uz=1.34e-4 * constants.c, + weight=1.0, +) + +ions = picmi.Species( + particle_type="H", + name="proton", + charge="q_e", + mass="m_p", + warpx_do_not_deposit=1, + initial_distribution=ion_dist, +) + +################################# +######## INITIAL FIELD ########## +################################# + +applied_field = picmi.LoadAppliedField( + read_fields_from_path="../../../../openPMD-example-datasets/example-femm-3d.h5", + load_E=False, +) + +################################# +###### GRID AND SOLVER ########## +################################# + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + warpx_max_grid_size=max_grid_size, + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], +) +solver = picmi.ElectrostaticSolver(grid=grid) + +################################# +######### DIAGNOSTICS ########### +################################# + +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=300, + species=[ions], + data_list=["ux", "uy", "uz", "x", "y", "z", "weighting"], +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=300, + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez", "Jx", "Jy", "Jz"], +) + +################################# +####### SIMULATION SETUP ######## +################################# + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=verbose, + warpx_serialize_initial_conditions=False, + warpx_grid_type="collocated", + warpx_do_dynamic_scheduling=False, + warpx_use_filter=use_filter, + time_step_size=dt, + particle_shape=particle_shape, +) + +sim.add_applied_field(applied_field) + +sim.add_species( + ions, + layout=picmi.PseudoRandomLayout( + n_macroparticles_per_cell=number_per_cell, grid=grid + ), +) + +sim.add_diagnostic(field_diag) +sim.add_diagnostic(particle_diag) + +################################# +##### SIMULATION EXECUTION ###### +################################# + +# sim.write_input_file('inputs_test_3d_load_external_field_particle') +sim.step(max_steps) diff --git a/Examples/Tests/LoadExternalField/inputs_rz_grid_fields b/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_grid similarity index 97% rename from Examples/Tests/LoadExternalField/inputs_rz_grid_fields rename to Examples/Tests/load_external_field/inputs_test_rz_load_external_field_grid index 2e22ca299ea..f986add7bf5 100644 --- a/Examples/Tests/LoadExternalField/inputs_rz_grid_fields +++ b/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_grid @@ -1,3 +1,4 @@ +warpx.abort_on_warning_threshold = medium warpx.serialize_initial_conditions = 0 warpx.do_dynamic_scheduling = 0 particles.do_tiling = 0 diff --git a/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_grid_restart b/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_grid_restart new file mode 100644 index 00000000000..ed31e697e25 --- /dev/null +++ b/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_grid_restart @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_test_rz_load_external_field_grid + +# test input parameters +amr.restart = "../test_rz_load_external_field_grid/diags/chk000150" diff --git a/Examples/Tests/LoadExternalField/inputs_rz_particle_fields b/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_particles similarity index 97% rename from Examples/Tests/LoadExternalField/inputs_rz_particle_fields rename to Examples/Tests/load_external_field/inputs_test_rz_load_external_field_particles index b76d4cb7efc..e725ed588b0 100644 --- a/Examples/Tests/LoadExternalField/inputs_rz_particle_fields +++ b/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_particles @@ -1,3 +1,4 @@ +warpx.abort_on_warning_threshold = medium warpx.serialize_initial_conditions = 0 warpx.do_dynamic_scheduling = 0 particles.do_tiling = 0 diff --git a/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_particles_restart b/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_particles_restart new file mode 100644 index 00000000000..7e20f87d6d2 --- /dev/null +++ b/Examples/Tests/load_external_field/inputs_test_rz_load_external_field_particles_restart @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_test_rz_load_external_field_particles + +# test input parameters +amr.restart = "../test_rz_load_external_field_particles/diags/chk000150" diff --git a/Examples/Tests/magnetostatic_eb/CMakeLists.txt b/Examples/Tests/magnetostatic_eb/CMakeLists.txt new file mode 100644 index 00000000000..3eb2da03136 --- /dev/null +++ b/Examples/Tests/magnetostatic_eb/CMakeLists.txt @@ -0,0 +1,38 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_3d_magnetostatic_eb # name + 3 # dims + 1 # nprocs + inputs_test_3d_magnetostatic_eb # inputs + analysis_default_regression.py # analysis + diags/diag1000001 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_3d_magnetostatic_eb_picmi # name + 3 # dims + 1 # nprocs + inputs_test_3d_magnetostatic_eb_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000001 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_rz_magnetostatic_eb_picmi # name + RZ # dims + 1 # nprocs + inputs_test_rz_magnetostatic_eb_picmi.py # inputs + analysis_rz.py # analysis + diags/diag1000001 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/magnetostatic_eb/analysis_default_regression.py b/Examples/Tests/magnetostatic_eb/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/magnetostatic_eb/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/magnetostatic_eb/analysis_rz.py b/Examples/Tests/magnetostatic_eb/analysis_rz.py index 00c270e597c..05aa4a3fe47 100755 --- a/Examples/Tests/magnetostatic_eb/analysis_rz.py +++ b/Examples/Tests/magnetostatic_eb/analysis_rz.py @@ -4,7 +4,7 @@ import re import sys -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -14,7 +14,7 @@ test_name = os.path.split(os.getcwd())[1] # Run checksum regression test -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, rtol=2.e-6, do_particles=False) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, rtol=2.0e-6, do_particles=False) else: checksumAPI.evaluate_checksum(test_name, fn, do_particles=False) diff --git a/Examples/Tests/magnetostatic_eb/inputs_3d b/Examples/Tests/magnetostatic_eb/inputs_test_3d_magnetostatic_eb similarity index 96% rename from Examples/Tests/magnetostatic_eb/inputs_3d rename to Examples/Tests/magnetostatic_eb/inputs_test_3d_magnetostatic_eb index 60617f7d392..73ff14dc8a4 100644 --- a/Examples/Tests/magnetostatic_eb/inputs_3d +++ b/Examples/Tests/magnetostatic_eb/inputs_test_3d_magnetostatic_eb @@ -48,4 +48,3 @@ diag1.diag_type = Full diag1.format = plotfile diag1.intervals = 1 diag1.fields_to_plot = Az Bx By Ex Ey jz phi rho -diag1.file_prefix = ./magnetostatic_eb_3d_mr_plt diff --git a/Examples/Tests/magnetostatic_eb/PICMI_inputs_3d.py b/Examples/Tests/magnetostatic_eb/inputs_test_3d_magnetostatic_eb_picmi.py similarity index 52% rename from Examples/Tests/magnetostatic_eb/PICMI_inputs_3d.py rename to Examples/Tests/magnetostatic_eb/inputs_test_3d_magnetostatic_eb_picmi.py index 8f205724563..d3c35daf261 100755 --- a/Examples/Tests/magnetostatic_eb/PICMI_inputs_3d.py +++ b/Examples/Tests/magnetostatic_eb/inputs_test_3d_magnetostatic_eb_picmi.py @@ -22,7 +22,7 @@ import matplotlib -matplotlib.use('agg') +matplotlib.use("agg") import matplotlib.pyplot as plt import numpy as np @@ -57,7 +57,7 @@ xmax = 0.25 ymin = -0.25 ymax = 0.25 -zmin = 0. +zmin = 0.0 zmax = 1.0 ########################## @@ -65,20 +65,24 @@ ########################## grid = picmi.Cartesian3DGrid( - number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = ['neumann', 'neumann', 'dirichlet'], - upper_boundary_conditions = ['neumann', 'neumann', 'neumann'], - lower_boundary_conditions_particles = ['absorbing', 'absorbing', 'absorbing'], - upper_boundary_conditions_particles = ['absorbing', 'absorbing', 'absorbing'], - warpx_potential_lo_z = V_domain_boundary, + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["neumann", "neumann", "dirichlet"], + upper_boundary_conditions=["neumann", "neumann", "neumann"], + lower_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], + warpx_potential_lo_z=V_domain_boundary, warpx_blocking_factor=8, - warpx_max_grid_size = 32 + warpx_max_grid_size=32, ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-7,warpx_magnetostatic=True,warpx_self_fields_verbosity=3 + grid=grid, + method="Multigrid", + required_precision=1e-7, + warpx_magnetostatic=True, + warpx_self_fields_verbosity=3, ) r_pipe = 0.2 @@ -86,46 +90,59 @@ embedded_boundary = picmi.EmbeddedBoundary( implicit_function="(x**2+y**2-radius**2)", potential=V_embedded_boundary, - radius = r_pipe + radius=r_pipe, ) # Beam Current Density current = 1000 # A -beam_r = 0.1 # m +beam_r = 0.1 # m -J = current/(np.pi * beam_r**2) -beam_gamma = 10. -vz = con.c*np.sqrt(1. - 1./beam_gamma**2) -n0 = J/(con.e*vz) +J = current / (np.pi * beam_r**2) +beam_gamma = 10.0 +vz = con.c * np.sqrt(1.0 - 1.0 / beam_gamma**2) +n0 = J / (con.e * vz) beam_dist = picmi.AnalyticDistribution( - density_expression='((x**2+y**2)= beam_r and r < r_pipe: - er = -current / (2.*np.pi*r*con.epsilon_0*vz) + er = -current / (2.0 * np.pi * r * con.epsilon_0 * vz) else: er = np.zeros_like(r) return er + # compare to region from 0.5*zmax to 0.9*zmax -z_idx = ((z_vec >= 0.5*zmax) & (z_vec < 0.9*zmax)) +z_idx = (z_vec >= 0.5 * zmax) & (z_vec < 0.9 * zmax) Ex_dat = Ex[...] Ey_dat = Ey[...] -Ex_mean = Ex_dat[:,:,z_idx].mean(axis=2).T -Ey_mean = Ey_dat[:,:,z_idx].mean(axis=2).T +Ex_mean = Ex_dat[:, :, z_idx].mean(axis=2).T +Ey_mean = Ey_dat[:, :, z_idx].mean(axis=2).T Ex_nodal = Ex_mean Ey_nodal = Ey_mean -XM, YM = np.meshgrid(x_vec, y_vec, indexing='xy') +XM, YM = np.meshgrid(x_vec, y_vec, indexing="xy") RM = np.sqrt(XM**2 + YM**2) -THM = np.arctan2(YM,XM) +THM = np.arctan2(YM, XM) Er_mean = np.cos(THM) * Ex_nodal + np.sin(THM) * Ey_nodal r_vec = np.sqrt(x_vec**2 + y_vec**2) -r_idx = (RM < 0.95*r_pipe) +r_idx = RM < 0.95 * r_pipe r_sub = RM[r_idx] plt.figure(1) plt.plot(r_vec, Er_an(r_vec)) -plt.plot(RM.flatten(), Er_mean.flatten(), '.') -plt.legend(['Analytical', 'Electrostatic']) +plt.plot(RM.flatten(), Er_mean.flatten(), ".") +plt.legend(["Analytical", "Electrostatic"]) -er_err = np.abs(Er_mean[r_idx] - Er_an(r_sub)).max()/np.abs(Er_an(r_sub)).max() +er_err = np.abs(Er_mean[r_idx] - Er_an(r_sub)).max() / np.abs(Er_an(r_sub)).max() -plt.ylabel('$E_r$ (V/m)') -plt.xlabel('r (m)') -plt.title("Max % Error: {} %".format(er_err*100.)) +plt.ylabel("$E_r$ (V/m)") +plt.xlabel("r (m)") +plt.title("Max % Error: {} %".format(er_err * 100.0)) plt.tight_layout() -plt.savefig('er_3d.png') +plt.savefig("er_3d.png") -assert (er_err < 0.05), "Er Max Error increased above 5%" +assert er_err < 0.05, "Er Max Error increased above 5%" ######################## # Check B field @@ -221,66 +240,68 @@ def Er_an(r): Bx = fields.BxWrapper() By = fields.ByWrapper() -x_vec = Bx.mesh('x') -y_vec = Bx.mesh('y') -z_vec = Bx.mesh('z') +x_vec = Bx.mesh("x") +y_vec = Bx.mesh("y") +z_vec = Bx.mesh("z") dx = x_vec[1] - x_vec[0] dy = y_vec[1] - y_vec[0] -x_vec = x_vec + dx/2. -y_vec = y_vec + dy/2. +x_vec = x_vec + dx / 2.0 +y_vec = y_vec + dy / 2.0 + @np.vectorize def Bt_an(r): if r < beam_r: - bt = -current * r * con.mu_0 / (2.*np.pi*beam_r**2) + bt = -current * r * con.mu_0 / (2.0 * np.pi * beam_r**2) elif r >= beam_r and r < r_pipe: - bt = -current * con.mu_0 / (2.*np.pi*r) + bt = -current * con.mu_0 / (2.0 * np.pi * r) else: bt = np.zeros_like(r) return bt + # compare to region from 0.25*zmax to 0.75*zmax -z_idx = ((z_vec >= 0.25*zmax) & (z_vec < 0.75*zmax)) +z_idx = (z_vec >= 0.25 * zmax) & (z_vec < 0.75 * zmax) z_sub = z_vec[z_idx] Bx_dat = Bx[...] By_dat = By[...] -Bx_mean = Bx_dat[:,:,z_idx].mean(axis=2).T -By_mean = By_dat[:,:,z_idx].mean(axis=2).T +Bx_mean = Bx_dat[:, :, z_idx].mean(axis=2).T +By_mean = By_dat[:, :, z_idx].mean(axis=2).T # Interpolate B mesh to nodal points excluding last mesh point -Bx_nodal = (Bx_mean[:-1,1:] + Bx_mean[:-1,:-1])/2. -By_nodal = (By_mean[:-1,:-1] + By_mean[1:,:-1])/2. +Bx_nodal = (Bx_mean[:-1, 1:] + Bx_mean[:-1, :-1]) / 2.0 +By_nodal = (By_mean[:-1, :-1] + By_mean[1:, :-1]) / 2.0 x_vec = x_vec[:-1] y_vec = y_vec[:-1] -XM, YM = np.meshgrid(x_vec, y_vec, indexing='xy') +XM, YM = np.meshgrid(x_vec, y_vec, indexing="xy") RM = np.sqrt(XM**2 + YM**2) -THM = np.arctan2(YM,XM) +THM = np.arctan2(YM, XM) -Bt_mean = - np.sin(THM) * Bx_nodal + np.cos(THM) * By_nodal +Bt_mean = -np.sin(THM) * Bx_nodal + np.cos(THM) * By_nodal r_vec = np.sqrt(x_vec**2 + y_vec**2) -r_idx = (RM < 0.95*r_pipe) +r_idx = RM < 0.95 * r_pipe r_sub = RM[r_idx] plt.figure(2) plt.plot(r_vec, Bt_an(r_vec)) -plt.plot(RM[r_idx].flatten(), Bt_mean[r_idx].flatten(), '.') -plt.legend(['Analytical', 'Magnetostatic']) +plt.plot(RM[r_idx].flatten(), Bt_mean[r_idx].flatten(), ".") +plt.legend(["Analytical", "Magnetostatic"]) -bt_err = np.abs(Bt_mean[r_idx] - Bt_an(r_sub)).max()/np.abs(Bt_an(r_sub)).max() +bt_err = np.abs(Bt_mean[r_idx] - Bt_an(r_sub)).max() / np.abs(Bt_an(r_sub)).max() -plt.ylabel('$B_{\Theta}$ (T)') -plt.xlabel('r (m)') -plt.title("Max % Error: {} %".format(bt_err*100.)) +plt.ylabel("$B_{\Theta}$ (T)") +plt.xlabel("r (m)") +plt.title("Max % Error: {} %".format(bt_err * 100.0)) plt.tight_layout() -plt.savefig('bt_3d.png') +plt.savefig("bt_3d.png") -assert (bt_err < 0.05), "Bt Max Error increased above 5%" +assert bt_err < 0.05, "Bt Max Error increased above 5%" diff --git a/Examples/Tests/magnetostatic_eb/PICMI_inputs_rz.py b/Examples/Tests/magnetostatic_eb/inputs_test_rz_magnetostatic_eb_picmi.py similarity index 53% rename from Examples/Tests/magnetostatic_eb/PICMI_inputs_rz.py rename to Examples/Tests/magnetostatic_eb/inputs_test_rz_magnetostatic_eb_picmi.py index e46f561f538..d0f1787a5a2 100755 --- a/Examples/Tests/magnetostatic_eb/PICMI_inputs_rz.py +++ b/Examples/Tests/magnetostatic_eb/inputs_test_rz_magnetostatic_eb_picmi.py @@ -22,7 +22,7 @@ import matplotlib -matplotlib.use('agg') +matplotlib.use("agg") import matplotlib.pyplot as plt import numpy as np @@ -51,10 +51,10 @@ nr = 128 nz = 128 -rmin = 0. +rmin = 0.0 rmax = 0.25 -zmin = 0. +zmin = 0.0 zmax = 1 r_pipe = 0.2 @@ -64,65 +64,70 @@ ########################## grid = picmi.CylindricalGrid( - number_of_cells = [nr, nz], - lower_bound = [rmin, zmin], - upper_bound = [rmax, zmax], - lower_boundary_conditions = ['none', 'dirichlet'], - upper_boundary_conditions = ['neumann', 'neumann'], - lower_boundary_conditions_particles = ['none', 'absorbing'], - upper_boundary_conditions_particles = ['absorbing', 'absorbing'], - warpx_potential_lo_z = V_domain_boundary, + number_of_cells=[nr, nz], + lower_bound=[rmin, zmin], + upper_bound=[rmax, zmax], + lower_boundary_conditions=["none", "dirichlet"], + upper_boundary_conditions=["neumann", "neumann"], + lower_boundary_conditions_particles=["none", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing"], + warpx_potential_lo_z=V_domain_boundary, warpx_blocking_factor=8, - warpx_max_grid_size = 32 + warpx_max_grid_size=32, ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-7,warpx_magnetostatic=True,warpx_self_fields_verbosity=3 + grid=grid, + method="Multigrid", + required_precision=1e-7, + warpx_magnetostatic=True, + warpx_self_fields_verbosity=3, ) embedded_boundary = picmi.EmbeddedBoundary( implicit_function="(x**2+y**2-radius**2)", potential=V_embedded_boundary, - radius = r_pipe + radius=r_pipe, ) # Beam Current Density current = 1000 # A -beam_r = 0.1 # m +beam_r = 0.1 # m -J = current/(np.pi * beam_r**2) -beam_gamma = 10. -vz = con.c*np.sqrt(1. - 1./beam_gamma**2) -n0 = J/(con.e*vz) +J = current / (np.pi * beam_r**2) +beam_gamma = 10.0 +vz = con.c * np.sqrt(1.0 - 1.0 / beam_gamma**2) +n0 = J / (con.e * vz) beam_dist = picmi.AnalyticDistribution( - density_expression='((x**2+y**2)= beam_r and r < r_pipe: - er = -current / (2.*np.pi*r*con.epsilon_0*vz) + er = -current / (2.0 * np.pi * r * con.epsilon_0 * vz) else: er = np.zeros_like(r) return er + # compare to region from 0.5*zmax to 0.9*zmax -z_idx = ((z_vec >= 0.5*zmax) & (z_vec < 0.9*zmax)) +z_idx = (z_vec >= 0.5 * zmax) & (z_vec < 0.9 * zmax) Er_dat = Er[...] -r_idx = (r_vec < 0.95*r_pipe) +r_idx = r_vec < 0.95 * r_pipe r_sub = r_vec[r_idx] # Average Er along z_sub -Er_mean = Er_dat[:,z_idx].mean(axis=1) +Er_mean = Er_dat[:, z_idx].mean(axis=1) plt.figure(1) plt.plot(r_vec, Er_an(r_vec)) -plt.plot(r_vec, Er_mean,'--') -plt.legend(['Analytical', 'Electrostatic']) +plt.plot(r_vec, Er_mean, "--") +plt.legend(["Analytical", "Electrostatic"]) -er_err = np.abs(Er_mean[r_idx] - Er_an(r_sub)).max()/np.abs(Er_an(r_sub)).max() +er_err = np.abs(Er_mean[r_idx] - Er_an(r_sub)).max() / np.abs(Er_an(r_sub)).max() -plt.ylabel('$E_r$ (V/m)') -plt.xlabel('r (m)') -plt.title("Max % Error: {} %".format(er_err*100.)) +plt.ylabel("$E_r$ (V/m)") +plt.xlabel("r (m)") +plt.title("Max % Error: {} %".format(er_err * 100.0)) plt.tight_layout() -plt.savefig('er_rz.png') +plt.savefig("er_rz.png") -assert (er_err < 0.02), "Er Error increased above 2%" +assert er_err < 0.02, "Er Error increased above 2%" ######################## # Check B field @@ -202,45 +209,47 @@ def Er_an(r): Bth = fields.ByWrapper() -r_vec = Bth.mesh('r') -z_vec = Bth.mesh('z') +r_vec = Bth.mesh("r") +z_vec = Bth.mesh("z") + +dr = r_vec[1] - r_vec[0] +r_vec = r_vec + dr / 2.0 -dr = r_vec[1]-r_vec[0] -r_vec = r_vec + dr/2. @np.vectorize def Bth_an(r): if r < beam_r: - bt = -current * r * con.mu_0 / (2.*np.pi*beam_r**2) + bt = -current * r * con.mu_0 / (2.0 * np.pi * beam_r**2) elif r >= beam_r and r < r_pipe: - bt = -current * con.mu_0 / (2.*np.pi*r) + bt = -current * con.mu_0 / (2.0 * np.pi * r) else: bt = np.zeros_like(r) return bt + # compare to region from 0.25*zmax to 0.75*zmax -z_idx = ((z_vec >= 0.25*zmax) & (z_vec < 0.75*zmax)) +z_idx = (z_vec >= 0.25 * zmax) & (z_vec < 0.75 * zmax) z_sub = z_vec[z_idx] Bth_dat = Bth[...] -r_idx = (r_vec < 0.95*r_pipe) +r_idx = r_vec < 0.95 * r_pipe r_sub = r_vec[r_idx] # Average Bth along z_idx -Bth_mean = Bth_dat[:,z_idx].mean(axis=1) +Bth_mean = Bth_dat[:, z_idx].mean(axis=1) plt.figure(2) plt.plot(r_vec, Bth_an(r_vec)) -plt.plot(r_vec, Bth_mean,'--') -plt.legend(['Analytical', 'Magnetostatic']) +plt.plot(r_vec, Bth_mean, "--") +plt.legend(["Analytical", "Magnetostatic"]) -bth_err = np.abs(Bth_mean[r_idx] - Bth_an(r_sub)).max()/np.abs(Bth_an(r_sub)).max() +bth_err = np.abs(Bth_mean[r_idx] - Bth_an(r_sub)).max() / np.abs(Bth_an(r_sub)).max() -plt.ylabel('$B_{\Theta}$ (T)') -plt.xlabel('r (m)') -plt.title("Max % Error: {} %".format(bth_err*100.)) +plt.ylabel("$B_{\Theta}$ (T)") +plt.xlabel("r (m)") +plt.title("Max % Error: {} %".format(bth_err * 100.0)) plt.tight_layout() -plt.savefig('bth_rz.png') +plt.savefig("bth_rz.png") -assert (bth_err < 0.02), "Bth Error increased above 2%" +assert bth_err < 0.02, "Bth Error increased above 2%" diff --git a/Examples/Tests/maxwell_hybrid_qed/CMakeLists.txt b/Examples/Tests/maxwell_hybrid_qed/CMakeLists.txt new file mode 100644 index 00000000000..2c65c0a6ecb --- /dev/null +++ b/Examples/Tests/maxwell_hybrid_qed/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_FFT) + add_warpx_test( + test_2d_maxwell_hybrid_qed_solver # name + 2 # dims + 2 # nprocs + inputs_test_2d_maxwell_hybrid_qed_solver # inputs + analysis.py # analysis + diags/diag1000300 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/maxwell_hybrid_qed/analysis.py b/Examples/Tests/maxwell_hybrid_qed/analysis.py new file mode 100755 index 00000000000..88142362372 --- /dev/null +++ b/Examples/Tests/maxwell_hybrid_qed/analysis.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +# Copyright 2019-2020 Axel Huebl, Glenn Richardson, Maxence Thevenet +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +import sys + +import numpy as np +import scipy.constants as scc +import yt + +yt.funcs.mylog.setLevel(0) + +# Static electric field and quantum parameters, from the input file. +Es = 1.0e5 +xi = 1.0e-23 + +# Load dataset and get laser field +dsQED = yt.load(sys.argv[1]) +QED_all_data_level_0 = dsQED.covering_grid( + level=0, left_edge=(dsQED.domain_left_edge), dims=dsQED.domain_dimensions +) +EyQED_2d = QED_all_data_level_0["boxlib", "Ey"].v.squeeze() + +# Extract 1D lineout of the laser field +EyQED = EyQED_2d[EyQED_2d.shape[0] // 2, :] + +# Longitudinal resolution +dz = dsQED.domain_width[1].v / dsQED.domain_dimensions[1] + +# Initial position of the laser pulse max (from input file) +z_start = 0.0 +# Final position of the laser pulse max (from plotfile) +z_end = dsQED.domain_left_edge[1].v + np.argmax(EyQED) * dz +# Compute phase velocity and compare with theory +phase_velocity_pic = (z_end - z_start) / dsQED.current_time.v +phase_velocity_theory = scc.c / np.sqrt( + (1.0 + 12.0 * xi * Es**2 / scc.epsilon_0) / (1.0 + 4.0 * xi * Es**2 / scc.epsilon_0) +) +error_percent = ( + 100.0 * np.abs(phase_velocity_pic - phase_velocity_theory) / phase_velocity_theory +) + +# Print and assert correctness +print("Simulation velocity: " + str(phase_velocity_pic)) +print("Theory velocity : " + str(phase_velocity_theory)) +print("error (%) : " + str(error_percent)) +print( + "Theoretical difference between with/without QED (%): " + + str(100 * np.abs(phase_velocity_theory - scc.c) / scc.c) +) +assert error_percent < 1.25 diff --git a/Examples/Tests/maxwell_hybrid_qed/analysis_Maxwell_QED_Hybrid.py b/Examples/Tests/maxwell_hybrid_qed/analysis_Maxwell_QED_Hybrid.py deleted file mode 100755 index e74e9c524b9..00000000000 --- a/Examples/Tests/maxwell_hybrid_qed/analysis_Maxwell_QED_Hybrid.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2019-2020 Axel Huebl, Glenn Richardson, Maxence Thevenet -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import sys - -import numpy as np -import scipy.constants as scc - -import yt ; yt.funcs.mylog.setLevel(0) - -# Static electric field and quantum parameters, from the input file. -Es = 1.0e5 -xi = 1.0e-23 - -# Load dataset and get laser field -dsQED = yt.load(sys.argv[1]) -QED_all_data_level_0 = dsQED.covering_grid(level=0,left_edge=(dsQED.domain_left_edge), - dims=dsQED.domain_dimensions) -EyQED_2d = QED_all_data_level_0['boxlib', 'Ey'].v.squeeze() - -# Extract 1D lineout of the laser field -EyQED = EyQED_2d[EyQED_2d.shape[0]//2,:] - -# Longitudinal resolution -dz = dsQED.domain_width[1].v/dsQED.domain_dimensions[1] - -# Initial position of the laser pulse max (from input file) -z_start = 0. -# Final position of the laser pulse max (from plotfile) -z_end = dsQED.domain_left_edge[1].v + np.argmax(EyQED) * dz -# Compute phase velocity and compare with theory -phase_velocity_pic = (z_end-z_start)/dsQED.current_time.v -phase_velocity_theory = scc.c/np.sqrt((1.+12.*xi*Es**2/scc.epsilon_0)/(1.+4.*xi*Es**2/scc.epsilon_0)) -error_percent = 100.*np.abs(phase_velocity_pic-phase_velocity_theory)/phase_velocity_theory - -# Print and assert correctness -print('Simulation velocity: ' + str(phase_velocity_pic)) -print('Theory velocity : ' + str(phase_velocity_theory)) -print('error (%) : ' + str(error_percent) ) -print('Theoretical difference between with/without QED (%): ' + str(100*np.abs(phase_velocity_theory-scc.c)/scc.c)) -assert( error_percent < 1.25 ) diff --git a/Examples/Tests/maxwell_hybrid_qed/inputs_2d b/Examples/Tests/maxwell_hybrid_qed/inputs_test_2d_maxwell_hybrid_qed_solver similarity index 98% rename from Examples/Tests/maxwell_hybrid_qed/inputs_2d rename to Examples/Tests/maxwell_hybrid_qed/inputs_test_2d_maxwell_hybrid_qed_solver index 2baa72c0990..8e1091c91e2 100644 --- a/Examples/Tests/maxwell_hybrid_qed/inputs_2d +++ b/Examples/Tests/maxwell_hybrid_qed/inputs_test_2d_maxwell_hybrid_qed_solver @@ -24,7 +24,7 @@ boundary.field_hi = periodic periodic algo.maxwell_solver = psatd warpx.verbose = 0 warpx.use_filter = 1 -warpx.cfl = 1. +warpx.cfl = 0.7071067811865475 warpx.use_hybrid_QED = 1 ################################# diff --git a/Examples/Tests/nci_fdtd_stability/CMakeLists.txt b/Examples/Tests/nci_fdtd_stability/CMakeLists.txt new file mode 100644 index 00000000000..e58e5bfb58f --- /dev/null +++ b/Examples/Tests/nci_fdtd_stability/CMakeLists.txt @@ -0,0 +1,22 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_nci_corrector # name + 2 # dims + 2 # nprocs + inputs_test_2d_nci_corrector # inputs + analysis_ncicorr.py # analysis + diags/diag1000600 # output + OFF # dependency +) + +add_warpx_test( + test_2d_nci_corrector_mr # name + 2 # dims + 2 # nprocs + inputs_test_2d_nci_corrector_mr # inputs + analysis_ncicorr.py # analysis + diags/diag1000600 # output + OFF # dependency +) diff --git a/Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py b/Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py index 118b03fed89..7bfa47f3164 100755 --- a/Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py +++ b/Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py @@ -18,35 +18,37 @@ yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI fn = sys.argv[1] -use_MR = re.search( 'nci_correctorMR', fn ) != None +use_MR = re.search("nci_correctorMR", fn) is not None if use_MR: - energy_corrector_off = 5.e32 - energy_threshold = 1.e28 + energy_corrector_off = 5.0e32 + energy_threshold = 1.0e28 else: energy_corrector_off = 1.5e26 - energy_threshold = 1.e24 + energy_threshold = 1.0e24 # Check EB energy after 1000 timesteps filename = sys.argv[1] -ds = yt.load( filename ) -ad0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -ex = ad0['boxlib', 'Ex'].v -ez = ad0['boxlib', 'Ez'].v -by = ad0['boxlib', 'By'].v -energy = np.sum(ex**2 + ez**2 + scc.c**2*by**2) - -print("use_MR: %s" %use_MR) -print("energy if corrector off (from benchmark): %s" %energy_corrector_off) -print("energy threshold (from benchmark): %s" %energy_threshold) -print("energy from this run: %s" %energy) - -assert( energy < energy_threshold ) +ds = yt.load(filename) +ad0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +ex = ad0["boxlib", "Ex"].v +ez = ad0["boxlib", "Ez"].v +by = ad0["boxlib", "By"].v +energy = np.sum(ex**2 + ez**2 + scc.c**2 * by**2) + +print("use_MR: %s" % use_MR) +print("energy if corrector off (from benchmark): %s" % energy_corrector_off) +print("energy threshold (from benchmark): %s" % energy_threshold) +print("energy from this run: %s" % energy) + +assert energy < energy_threshold test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/nci_fdtd_stability/inputs_2d b/Examples/Tests/nci_fdtd_stability/inputs_base_2d similarity index 100% rename from Examples/Tests/nci_fdtd_stability/inputs_2d rename to Examples/Tests/nci_fdtd_stability/inputs_base_2d diff --git a/Examples/Tests/nci_fdtd_stability/inputs_test_2d_nci_corrector b/Examples/Tests/nci_fdtd_stability/inputs_test_2d_nci_corrector new file mode 100644 index 00000000000..83d537fd856 --- /dev/null +++ b/Examples/Tests/nci_fdtd_stability/inputs_test_2d_nci_corrector @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +amr.max_level = 0 +particles.use_fdtd_nci_corr = 1 diff --git a/Examples/Tests/nci_fdtd_stability/inputs_test_2d_nci_corrector_mr b/Examples/Tests/nci_fdtd_stability/inputs_test_2d_nci_corrector_mr new file mode 100644 index 00000000000..0f53af0443a --- /dev/null +++ b/Examples/Tests/nci_fdtd_stability/inputs_test_2d_nci_corrector_mr @@ -0,0 +1,9 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +amr.max_level = 1 +amr.n_cell = 64 64 +particles.use_fdtd_nci_corr = 1 +warpx.fine_tag_hi = 20.e-6 20.e-6 +warpx.fine_tag_lo = -20.e-6 -20.e-6 diff --git a/Examples/Tests/nci_psatd_stability/CMakeLists.txt b/Examples/Tests/nci_psatd_stability/CMakeLists.txt new file mode 100644 index 00000000000..f2b4ceae8ba --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/CMakeLists.txt @@ -0,0 +1,207 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_FFT) + add_warpx_test( + test_2d_averaged_galilean_psatd # name + 2 # dims + 1 # nprocs + inputs_test_2d_averaged_galilean_psatd # inputs + analysis_galilean.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_averaged_galilean_psatd_hybrid # name + 2 # dims + 2 # nprocs + inputs_test_2d_averaged_galilean_psatd_hybrid # inputs + analysis_galilean.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_comoving_psatd_hybrid # name + 2 # dims + 2 # nprocs + inputs_test_2d_comoving_psatd_hybrid # inputs + analysis_default_regression.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_galilean_psatd # name + 2 # dims + 1 # nprocs + inputs_test_2d_galilean_psatd # inputs + analysis_galilean.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_galilean_psatd_current_correction # name + 2 # dims + 2 # nprocs + inputs_test_2d_galilean_psatd_current_correction # inputs + analysis_galilean.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_galilean_psatd_current_correction_psb # name + 2 # dims + 1 # nprocs + inputs_test_2d_galilean_psatd_current_correction_psb # inputs + analysis_galilean.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_galilean_psatd_hybrid # name + 2 # dims + 2 # nprocs + inputs_test_2d_galilean_psatd_hybrid # inputs + analysis_default_regression.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_averaged_galilean_psatd # name + 3 # dims + 2 # nprocs + inputs_test_3d_averaged_galilean_psatd # inputs + analysis_galilean.py # analysis + diags/diag1000160 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_averaged_galilean_psatd_hybrid # name + 3 # dims + 2 # nprocs + inputs_test_3d_averaged_galilean_psatd_hybrid # inputs + analysis_galilean.py # analysis + diags/diag1000160 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_galilean_psatd # name + 3 # dims + 2 # nprocs + inputs_test_3d_galilean_psatd # inputs + analysis_galilean.py # analysis + diags/diag1000300 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_galilean_psatd_current_correction # name + 3 # dims + 2 # nprocs + inputs_test_3d_galilean_psatd_current_correction # inputs + analysis_galilean.py # analysis + diags/diag1000300 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_galilean_psatd_current_correction_psb # name + 3 # dims + 1 # nprocs + inputs_test_3d_galilean_psatd_current_correction_psb # inputs + analysis_galilean.py # analysis + diags/diag1000300 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_uniform_plasma_multiJ # name + 3 # dims + 2 # nprocs + inputs_test_3d_uniform_plasma_multiJ # inputs + analysis_multiJ.py # analysis + diags/diag1000300 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_rz_galilean_psatd # name + RZ # dims + 1 # nprocs + inputs_test_rz_galilean_psatd # inputs + analysis_galilean.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_rz_galilean_psatd_current_correction # name + RZ # dims + 2 # nprocs + inputs_test_rz_galilean_psatd_current_correction # inputs + analysis_galilean.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_rz_galilean_psatd_current_correction_psb # name + RZ # dims + 1 # nprocs + inputs_test_rz_galilean_psatd_current_correction_psb # inputs + analysis_galilean.py # analysis + diags/diag1000400 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_rz_multiJ_psatd # name + RZ # dims + 2 # nprocs + inputs_test_rz_multiJ_psatd # inputs + analysis_default_regression.py # analysis + diags/diag1000025 # output + OFF # dependency + ) + label_warpx_test(test_rz_multiJ_psatd slow) +endif() diff --git a/Examples/Tests/nci_psatd_stability/analysis_default_regression.py b/Examples/Tests/nci_psatd_stability/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/nci_psatd_stability/analysis_galilean.py b/Examples/Tests/nci_psatd_stability/analysis_galilean.py index 666d240da8f..40c74ecc5bf 100755 --- a/Examples/Tests/nci_psatd_stability/analysis_galilean.py +++ b/Examples/Tests/nci_psatd_stability/analysis_galilean.py @@ -12,15 +12,17 @@ In both cases, the reference energy corresponds to unstable results due to NCI (suppressed by the Galilean PSATD method, without or with averaging, respectively). """ + import os import re import sys import numpy as np import scipy.constants as scc +import yt -import yt ; yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] @@ -29,18 +31,19 @@ current_correction = False time_averaging = False periodic_single_box = False -warpx_used_inputs = open('./warpx_used_inputs', 'r').read() -if re.search('geometry.dims\s*=\s*2', warpx_used_inputs): - dims = '2D' -elif re.search('geometry.dims\s*=\s*RZ', warpx_used_inputs): - dims = 'RZ' -elif re.search('geometry.dims\s*=\s*3', warpx_used_inputs): - dims = '3D' -if re.search('psatd.current_correction\s*=\s*1', warpx_used_inputs): +with open("./warpx_used_inputs", "r") as f: + warpx_used_inputs = f.read() +if re.search("geometry.dims\s*=\s*2", warpx_used_inputs): + dims = "2D" +elif re.search("geometry.dims\s*=\s*RZ", warpx_used_inputs): + dims = "RZ" +elif re.search("geometry.dims\s*=\s*3", warpx_used_inputs): + dims = "3D" +if re.search("psatd.current_correction\s*=\s*1", warpx_used_inputs): current_correction = True -if re.search('psatd.do_time_averaging\s*=\s*1', warpx_used_inputs): +if re.search("psatd.do_time_averaging\s*=\s*1", warpx_used_inputs): time_averaging = True -if re.search('psatd.periodic_single_box_fft\s*=\s*1', warpx_used_inputs): +if re.search("psatd.periodic_single_box_fft\s*=\s*1", warpx_used_inputs): periodic_single_box = True ds = yt.load(filename) @@ -48,21 +51,24 @@ # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. -if 'force_periodicity' in dir(ds): ds.force_periodicity() +if "force_periodicity" in dir(ds): + ds.force_periodicity() -all_data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -if dims == 'RZ': - Ex = all_data['boxlib', 'Er'].squeeze().v - Ey = all_data['boxlib', 'Et'].squeeze().v +all_data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +if dims == "RZ": + Ex = all_data["boxlib", "Er"].squeeze().v + Ey = all_data["boxlib", "Et"].squeeze().v else: - Ex = all_data['boxlib', 'Ex'].squeeze().v - Ey = all_data['boxlib', 'Ey'].squeeze().v -Ez = all_data['boxlib', 'Ez'].squeeze().v + Ex = all_data["boxlib", "Ex"].squeeze().v + Ey = all_data["boxlib", "Ey"].squeeze().v +Ez = all_data["boxlib", "Ez"].squeeze().v # Set reference energy values, and tolerances for numerical stability and charge conservation tol_energy = 1e-8 tol_charge = 1e-9 -if dims == '2D': +if dims == "2D": if not current_correction: energy_ref = 35657.41657683263 if current_correction and periodic_single_box: @@ -74,7 +80,7 @@ if time_averaging: energy_ref = 26208.04843478073 tol_energy = 1e-6 -elif dims == 'RZ': +elif dims == "RZ": if not current_correction: energy_ref = 191002.6526271543 if current_correction and periodic_single_box: @@ -82,7 +88,7 @@ if current_correction and not periodic_single_box: energy_ref = 511671.4108624746 tol_charge = 3e-4 -elif dims == '3D': +elif dims == "3D": if not current_correction: energy_ref = 661285.098907683 if current_correction and periodic_single_box: @@ -95,22 +101,22 @@ tol_energy = 1e-4 # Check numerical stability by comparing electric field energy to reference energy -energy = np.sum(scc.epsilon_0/2*(Ex**2+Ey**2+Ez**2)) +energy = np.sum(scc.epsilon_0 / 2 * (Ex**2 + Ey**2 + Ez**2)) err_energy = energy / energy_ref -print('\nCheck numerical stability:') -print(f'err_energy = {err_energy}') -print(f'tol_energy = {tol_energy}') -assert(err_energy < tol_energy) +print("\nCheck numerical stability:") +print(f"err_energy = {err_energy}") +print(f"tol_energy = {tol_energy}") +assert err_energy < tol_energy # Check charge conservation (relative L-infinity norm of error) with current correction if current_correction: - divE = all_data['boxlib', 'divE'].squeeze().v - rho = all_data['boxlib', 'rho' ].squeeze().v / scc.epsilon_0 + divE = all_data["boxlib", "divE"].squeeze().v + rho = all_data["boxlib", "rho"].squeeze().v / scc.epsilon_0 err_charge = np.amax(np.abs(divE - rho)) / max(np.amax(divE), np.amax(rho)) - print('\nCheck charge conservation:') - print(f'err_charge = {err_charge}') - print(f'tol_charge = {tol_charge}') - assert(err_charge < tol_charge) + print("\nCheck charge conservation:") + print(f"err_charge = {err_charge}") + print(f"tol_charge = {tol_charge}") + assert err_charge < tol_charge test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename, rtol=1.e-8) +checksumAPI.evaluate_checksum(test_name, filename, rtol=1.0e-8) diff --git a/Examples/Tests/nci_psatd_stability/analysis_multiJ.py b/Examples/Tests/nci_psatd_stability/analysis_multiJ.py index 1c68b114c1a..2a438d5d22e 100755 --- a/Examples/Tests/nci_psatd_stability/analysis_multiJ.py +++ b/Examples/Tests/nci_psatd_stability/analysis_multiJ.py @@ -9,14 +9,16 @@ energy corresponds to unstable results due to NCI (suppressed by the use of both J and rho constant in time, and with divergence cleaning). """ + import os import sys import numpy as np import scipy.constants as scc +import yt -import yt ; yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] @@ -26,24 +28,27 @@ # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. -if 'force_periodicity' in dir(ds): ds.force_periodicity() +if "force_periodicity" in dir(ds): + ds.force_periodicity() -all_data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -Ex = all_data['boxlib', 'Ex'].squeeze().v -Ey = all_data['boxlib', 'Ey'].squeeze().v -Ez = all_data['boxlib', 'Ez'].squeeze().v +all_data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Ex = all_data["boxlib", "Ex"].squeeze().v +Ey = all_data["boxlib", "Ey"].squeeze().v +Ez = all_data["boxlib", "Ez"].squeeze().v # Set reference energy values, and tolerances for numerical stability and charge conservation tol_energy = 1e-8 energy_ref = 66e6 # Check numerical stability by comparing electric field energy to reference energy -energy = np.sum(scc.epsilon_0/2*(Ex**2+Ey**2+Ez**2)) +energy = np.sum(scc.epsilon_0 / 2 * (Ex**2 + Ey**2 + Ez**2)) err_energy = energy / energy_ref -print('\nCheck numerical stability:') -print(f'err_energy = {err_energy}') -print(f'tol_energy = {tol_energy}') -assert(err_energy < tol_energy) +print("\nCheck numerical stability:") +print(f"err_energy = {err_energy}") +print(f"tol_energy = {tol_energy}") +assert err_energy < tol_energy test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/nci_psatd_stability/inputs_2d b/Examples/Tests/nci_psatd_stability/inputs_base_2d similarity index 100% rename from Examples/Tests/nci_psatd_stability/inputs_2d rename to Examples/Tests/nci_psatd_stability/inputs_base_2d diff --git a/Examples/Tests/nci_psatd_stability/inputs_avg_2d b/Examples/Tests/nci_psatd_stability/inputs_base_2d_averaged similarity index 100% rename from Examples/Tests/nci_psatd_stability/inputs_avg_2d rename to Examples/Tests/nci_psatd_stability/inputs_base_2d_averaged diff --git a/Examples/Tests/nci_psatd_stability/inputs_3d b/Examples/Tests/nci_psatd_stability/inputs_base_3d similarity index 100% rename from Examples/Tests/nci_psatd_stability/inputs_3d rename to Examples/Tests/nci_psatd_stability/inputs_base_3d diff --git a/Examples/Tests/nci_psatd_stability/inputs_avg_3d b/Examples/Tests/nci_psatd_stability/inputs_base_3d_averaged similarity index 100% rename from Examples/Tests/nci_psatd_stability/inputs_avg_3d rename to Examples/Tests/nci_psatd_stability/inputs_base_3d_averaged diff --git a/Examples/Tests/nci_psatd_stability/inputs_rz b/Examples/Tests/nci_psatd_stability/inputs_base_rz similarity index 100% rename from Examples/Tests/nci_psatd_stability/inputs_rz rename to Examples/Tests/nci_psatd_stability/inputs_base_rz diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_2d_averaged_galilean_psatd b/Examples/Tests/nci_psatd_stability/inputs_test_2d_averaged_galilean_psatd new file mode 100644 index 00000000000..62f93dbd473 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_2d_averaged_galilean_psatd @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_2d_averaged + +# test input parameters +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_2d_averaged_galilean_psatd_hybrid b/Examples/Tests/nci_psatd_stability/inputs_test_2d_averaged_galilean_psatd_hybrid new file mode 100644 index 00000000000..0ef3668b103 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_2d_averaged_galilean_psatd_hybrid @@ -0,0 +1,9 @@ +# base input parameters +FILE = inputs_base_2d_averaged + +# test input parameters +amr.max_grid_size_x = 128 +amr.max_grid_size_y = 64 +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium +warpx.grid_type = hybrid diff --git a/Examples/Tests/comoving/inputs_2d_hybrid b/Examples/Tests/nci_psatd_stability/inputs_test_2d_comoving_psatd_hybrid similarity index 97% rename from Examples/Tests/comoving/inputs_2d_hybrid rename to Examples/Tests/nci_psatd_stability/inputs_test_2d_comoving_psatd_hybrid index 393e18d2077..32b155cf0b6 100644 --- a/Examples/Tests/comoving/inputs_2d_hybrid +++ b/Examples/Tests/nci_psatd_stability/inputs_test_2d_comoving_psatd_hybrid @@ -23,6 +23,7 @@ algo.particle_pusher = vay algo.particle_shape = 3 psatd.use_default_v_comoving = 1 +psatd.current_correction = 0 warpx.cfl = 1. @@ -40,6 +41,7 @@ warpx.use_filter = 1 warpx.serialize_initial_conditions = 1 warpx.verbose = 1 +warpx.abort_on_warning_threshold = medium particles.species_names = electrons ions beam particles.use_fdtd_nci_corr = 0 diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd b/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd new file mode 100644 index 00000000000..caebf987434 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_2d + +# test input paramters +algo.current_deposition = direct +psatd.current_correction = 0 +warpx.grid_type = collocated +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_current_correction b/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_current_correction new file mode 100644 index 00000000000..177cf7bcd0c --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_current_correction @@ -0,0 +1,10 @@ +# base input parameters +FILE = inputs_base_2d + +# test input paramters +amr.blocking_factor = 64 +amr.max_grid_size = 64 +diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz rho divE +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 0 +psatd.update_with_rho = 0 diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_current_correction_psb b/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_current_correction_psb new file mode 100644 index 00000000000..437059d6bd8 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_current_correction_psb @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_2d + +# test input paramters +diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz rho divE +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 1 +psatd.update_with_rho = 0 diff --git a/Examples/Tests/nci_psatd_stability/inputs_2d_hybrid b/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_hybrid similarity index 97% rename from Examples/Tests/nci_psatd_stability/inputs_2d_hybrid rename to Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_hybrid index 90dfd58c4ae..501c964353f 100644 --- a/Examples/Tests/nci_psatd_stability/inputs_2d_hybrid +++ b/Examples/Tests/nci_psatd_stability/inputs_test_2d_galilean_psatd_hybrid @@ -21,6 +21,7 @@ algo.particle_pusher = vay algo.particle_shape = 3 psatd.use_default_v_galilean = 1 +psatd.current_correction = 0 warpx.cfl = 1. @@ -38,6 +39,7 @@ warpx.use_filter = 1 warpx.serialize_initial_conditions = 1 warpx.verbose = 1 +warpx.abort_on_warning_threshold = medium particles.species_names = electrons ions beam particles.use_fdtd_nci_corr = 0 diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_3d_averaged_galilean_psatd b/Examples/Tests/nci_psatd_stability/inputs_test_3d_averaged_galilean_psatd new file mode 100644 index 00000000000..7c978874145 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_3d_averaged_galilean_psatd @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_3d_averaged + +# test input parameters +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_3d_averaged_galilean_psatd_hybrid b/Examples/Tests/nci_psatd_stability/inputs_test_3d_averaged_galilean_psatd_hybrid new file mode 100644 index 00000000000..4996f476854 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_3d_averaged_galilean_psatd_hybrid @@ -0,0 +1,7 @@ +# base input parameters +FILE = inputs_base_3d_averaged + +# test input parameters +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium +warpx.grid_type = hybrid diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd b/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd new file mode 100644 index 00000000000..3ec82981aea --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd @@ -0,0 +1,7 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +psatd.current_correction = 0 +psatd.v_galilean = 0. 0. 0.99498743710662 +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd_current_correction b/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd_current_correction new file mode 100644 index 00000000000..8b596c9a633 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd_current_correction @@ -0,0 +1,10 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz rho divE +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 0 +psatd.update_with_rho = 0 +psatd.v_galilean = 0. 0. 0.99498743710662 +warpx.numprocs = 1 1 2 diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd_current_correction_psb b/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd_current_correction_psb new file mode 100644 index 00000000000..87ce1b7ed92 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_3d_galilean_psatd_current_correction_psb @@ -0,0 +1,10 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz rho divE +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 1 +psatd.v_galilean = 0. 0. 0.99498743710662 +psatd.update_with_rho = 0 +warpx.numprocs = 1 1 1 diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_3d_uniform_plasma_multiJ b/Examples/Tests/nci_psatd_stability/inputs_test_3d_uniform_plasma_multiJ new file mode 100644 index 00000000000..70e9c5e992c --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_3d_uniform_plasma_multiJ @@ -0,0 +1,13 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +diag1.fields_to_plot = Bx By Bz divE Ex Ey Ez F G jx jy jz rho +psatd.J_in_time = constant +psatd.rho_in_time = constant +psatd.solution_type = first-order +warpx.abort_on_warning_threshold = medium +warpx.do_divb_cleaning = 1 +warpx.do_dive_cleaning = 1 +warpx.do_multi_J = 1 +warpx.do_multi_J_n_depositions = 1 diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd b/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd new file mode 100644 index 00000000000..30bcfc160cf --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_rz + +# test input paramters +electrons.random_theta = 0 +ions.random_theta = 0 +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd_current_correction b/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd_current_correction new file mode 100644 index 00000000000..378535e12bc --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd_current_correction @@ -0,0 +1,10 @@ +# base input parameters +FILE = inputs_base_rz + +# test input paramters +amr.blocking_factor = 32 +amr.max_grid_size = 32 +electrons.random_theta = 0 +ions.random_theta = 0 +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 0 diff --git a/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd_current_correction_psb b/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd_current_correction_psb new file mode 100644 index 00000000000..6eb35754a90 --- /dev/null +++ b/Examples/Tests/nci_psatd_stability/inputs_test_rz_galilean_psatd_current_correction_psb @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_rz + +# test input paramters +electrons.random_theta = 0 +ions.random_theta = 0 +psatd.current_correction = 1 +psatd.periodic_single_box_fft = 1 diff --git a/Examples/Tests/multi_j/inputs_rz b/Examples/Tests/nci_psatd_stability/inputs_test_rz_multiJ_psatd similarity index 95% rename from Examples/Tests/multi_j/inputs_rz rename to Examples/Tests/nci_psatd_stability/inputs_test_rz_multiJ_psatd index dd440d60667..6350b9aee51 100644 --- a/Examples/Tests/multi_j/inputs_rz +++ b/Examples/Tests/nci_psatd_stability/inputs_test_rz_multiJ_psatd @@ -1,8 +1,8 @@ # Iterations -max_step = 50 +max_step = 25 # Domain -amr.n_cell = 64 128 +amr.n_cell = 32 64 amr.max_level = 0 warpx.numprocs = 1 2 @@ -28,6 +28,7 @@ warpx.moving_window_v = 1. warpx.n_rz_azimuthal_modes = 1 warpx.use_filter = 1 warpx.verbose = 1 +warpx.abort_on_warning_threshold = medium warpx.cfl = 1. #warpx.gamma_boost = 1. @@ -42,6 +43,7 @@ psatd.do_time_averaging = 1 # PSATD psatd.update_with_rho = 1 #psatd.v_galilean = 0. 0. -0.9373391857121336 +psatd.J_in_time = linear # Particles @@ -113,7 +115,7 @@ plasma_p.do_continuous_injection = 1 # Diagnostics diagnostics.diags_names = diag1 -diag1.intervals = 50 +diag1.intervals = 25 diag1.diag_type = Full diag1.fields_to_plot = Er Ez Bt jr jz rho rho_driver rho_plasma_e rho_plasma_p diag1.species = driver plasma_e plasma_p diff --git a/Examples/Tests/nodal_electrostatic/CMakeLists.txt b/Examples/Tests/nodal_electrostatic/CMakeLists.txt new file mode 100644 index 00000000000..a6b3f5b0102 --- /dev/null +++ b/Examples/Tests/nodal_electrostatic/CMakeLists.txt @@ -0,0 +1,13 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_nodal_electrostatic_solver # name + 3 # dims + 1 # nprocs + inputs_test_3d_nodal_electrostatic_solver # inputs + analysis.py # analysis + diags/diag1000010 # output + OFF # dependency +) +label_warpx_test(test_3d_nodal_electrostatic_solver slow) diff --git a/Examples/Tests/nodal_electrostatic/analysis_3d.py b/Examples/Tests/nodal_electrostatic/analysis.py similarity index 59% rename from Examples/Tests/nodal_electrostatic/analysis_3d.py rename to Examples/Tests/nodal_electrostatic/analysis.py index 79a2bfdae20..c8725ce5d95 100755 --- a/Examples/Tests/nodal_electrostatic/analysis_3d.py +++ b/Examples/Tests/nodal_electrostatic/analysis.py @@ -5,21 +5,21 @@ import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file fn = sys.argv[1] # check that the maximum chi value is small -fname = 'diags/reducedfiles/ParticleExtrema_beam_p.txt' -chi_max = np.loadtxt(fname)[:,19] +fname = "diags/reducedfiles/ParticleExtrema_beam_p.txt" +chi_max = np.loadtxt(fname)[:, 19] assert np.all(chi_max < 2e-8) # check that no photons have been produced -fname = 'diags/reducedfiles/ParticleNumber.txt' -pho_num = np.loadtxt(fname)[:,7] -assert(pho_num.all()==0.) +fname = "diags/reducedfiles/ParticleNumber.txt" +pho_num = np.loadtxt(fname)[:, 7] +assert pho_num.all() == 0.0 # Checksum regression analysis test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/nodal_electrostatic/inputs_3d b/Examples/Tests/nodal_electrostatic/inputs_test_3d_nodal_electrostatic_solver similarity index 98% rename from Examples/Tests/nodal_electrostatic/inputs_3d rename to Examples/Tests/nodal_electrostatic/inputs_test_3d_nodal_electrostatic_solver index 91732a2c8ff..f1fd206eee3 100644 --- a/Examples/Tests/nodal_electrostatic/inputs_3d +++ b/Examples/Tests/nodal_electrostatic/inputs_test_3d_nodal_electrostatic_solver @@ -35,6 +35,7 @@ boundary.field_hi = PEC PEC PEC warpx.do_electrostatic = relativistic warpx.const_dt = dt warpx.grid_type = collocated +warpx.abort_on_warning_threshold = high algo.particle_pusher = vay algo.particle_shape = 3 diff --git a/Examples/Tests/nuclear_fusion/CMakeLists.txt b/Examples/Tests/nuclear_fusion/CMakeLists.txt new file mode 100644 index 00000000000..c3ee8848e59 --- /dev/null +++ b/Examples/Tests/nuclear_fusion/CMakeLists.txt @@ -0,0 +1,62 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_proton_boron_fusion # name + 2 # dims + 2 # nprocs + inputs_test_2d_proton_boron_fusion # inputs + analysis_proton_boron_fusion.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_3d_deuterium_deuterium_fusion # name + 3 # dims + 2 # nprocs + inputs_test_3d_deuterium_deuterium_fusion # inputs + analysis_two_product_fusion.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_3d_deuterium_deuterium_fusion_intraspecies # name + 3 # dims + 1 # nprocs + inputs_test_3d_deuterium_deuterium_fusion_intraspecies # inputs + analysis_deuterium_deuterium_3d_intraspecies.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +add_warpx_test( + test_3d_deuterium_tritium_fusion # name + 3 # dims + 2 # nprocs + inputs_test_3d_deuterium_tritium_fusion # inputs + analysis_two_product_fusion.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_3d_proton_boron_fusion # name + 3 # dims + 2 # nprocs + inputs_test_3d_proton_boron_fusion # inputs + analysis_proton_boron_fusion.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_rz_deuterium_tritium_fusion # name + RZ # dims + 2 # nprocs + inputs_test_rz_deuterium_tritium_fusion # inputs + analysis_two_product_fusion.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/nuclear_fusion/analysis_deuterium_deuterium_3d_intraspecies.py b/Examples/Tests/nuclear_fusion/analysis_deuterium_deuterium_3d_intraspecies.py index 858df0b26a6..22de371090c 100755 --- a/Examples/Tests/nuclear_fusion/analysis_deuterium_deuterium_3d_intraspecies.py +++ b/Examples/Tests/nuclear_fusion/analysis_deuterium_deuterium_3d_intraspecies.py @@ -28,28 +28,28 @@ import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Name of the plotfile fn = sys.argv[1] # Load data from reduced diagnostics (physical time and neutron weights) -time = np.loadtxt('./reduced_diags/particle_number.txt', usecols=1) -neutron = np.loadtxt('./reduced_diags/particle_number.txt', usecols=9) +time = np.loadtxt("./reduced_diags/particle_number.txt", usecols=1) +neutron = np.loadtxt("./reduced_diags/particle_number.txt", usecols=9) # Compute reactivity in units of cm^3/s as in equation (61) of [1] -dY_dt = np.abs(neutron[-1]-neutron[0])/(time[-1]-time[0]) -delta_ij = 1 # reactants of the same species -nD = 1e26 # density in 1/m^3 -V = (2e-3)**3 # simulation volume in m^3 -sigma = dY_dt*(1+delta_ij)/(nD**2)/V*(1e2)**3 +dY_dt = np.abs(neutron[-1] - neutron[0]) / (time[-1] - time[0]) +delta_ij = 1 # reactants of the same species +nD = 1e26 # density in 1/m^3 +V = (2e-3) ** 3 # simulation volume in m^3 +sigma = dY_dt * (1 + delta_ij) / (nD**2) / V * (1e2) ** 3 sigma_th = 2.603e-18 -error = np.abs(sigma-sigma_th)/sigma_th +error = np.abs(sigma - sigma_th) / sigma_th tolerance = 2e-2 -print('error = ', error) -print('tolerance = ', tolerance) +print("error = ", error) +print("tolerance = ", tolerance) assert error < tolerance # Compare checksums with benchmark diff --git a/Examples/Tests/nuclear_fusion/analysis_proton_boron_fusion.py b/Examples/Tests/nuclear_fusion/analysis_proton_boron_fusion.py index 543eb62484a..25e898c05be 100755 --- a/Examples/Tests/nuclear_fusion/analysis_proton_boron_fusion.py +++ b/Examples/Tests/nuclear_fusion/analysis_proton_boron_fusion.py @@ -6,11 +6,12 @@ # License: BSD-3-Clause-LBNL import os +import re import sys import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI import numpy as np import scipy.constants as scc @@ -59,28 +60,32 @@ ## Please be aware that the relative tolerances are often set empirically in this analysis script, ## so it would not be surprising that some tolerances need to be increased in the future. -default_tol = 1.e-12 # Default relative tolerance +default_tol = 1.0e-12 # Default relative tolerance ## Some physical parameters -keV_to_Joule = scc.e*1e3 -MeV_to_Joule = scc.e*1e6 -barn_to_square_meter = 1.e-28 -m_p = 1.00782503223*scc.m_u # Proton mass -m_b = 11.00930536*scc.m_u # Boron 11 mass -m_reduced = m_p*m_b/(m_p+m_b) -m_a = 4.00260325413*scc.m_u # Alpha mass -m_be = 7.94748*scc.m_p # Beryllium 8 mass -Z_boron = 5. -Z_proton = 1. -E_Gamow = (Z_boron*Z_proton*np.pi*scc.fine_structure)**2*2.*m_reduced*scc.c**2 -E_Gamow_MeV = E_Gamow/MeV_to_Joule -E_Gamow_keV = E_Gamow/keV_to_Joule -E_fusion = 8.59009*MeV_to_Joule # Energy released during p + B -> alpha + Be -E_decay = 0.0918984*MeV_to_Joule # Energy released during Be -> 2*alpha -E_fusion_total = E_fusion + E_decay # Energy released during p + B -> 3*alpha +keV_to_Joule = scc.e * 1e3 +MeV_to_Joule = scc.e * 1e6 +barn_to_square_meter = 1.0e-28 +m_p = 1.00782503223 * scc.m_u # Proton mass +m_b = 11.00930536 * scc.m_u # Boron 11 mass +m_reduced = m_p * m_b / (m_p + m_b) +m_a = 4.00260325413 * scc.m_u # Alpha (He4) mass +m_be = (8.0053095729 + 0.00325283863) * scc.m_u # Be8* mass (3.03 MeV ex. state) +Z_boron = 5.0 +Z_proton = 1.0 +E_Gamow = ( + (Z_boron * Z_proton * np.pi * scc.fine_structure) ** 2 * 2.0 * m_reduced * scc.c**2 +) +E_Gamow_MeV = E_Gamow / MeV_to_Joule +E_Gamow_keV = E_Gamow / keV_to_Joule +E_fusion = 5.55610759 * MeV_to_Joule # Energy released during p + B -> alpha + Be* +E_decay = 3.12600414 * MeV_to_Joule # Energy released during Be* -> 2*alpha +E_fusion_total = E_fusion + E_decay # Energy released during p + B -> 3*alpha ## Checks whether this is the 2D or the 3D test -is_2D = "2D" in sys.argv[1] +with open("./warpx_used_inputs") as warpx_used_inputs: + is_2D = re.search("geometry.dims\s*=\s*2", warpx_used_inputs.read()) +warpx_used_inputs.close() ## Some numerical parameters for this test size_x = 8 @@ -89,44 +94,48 @@ else: size_y = 8 size_z = 16 -dV_total = size_x*size_y*size_z # Total simulation volume +dV_total = size_x * size_y * size_z # Total simulation volume # Volume of a slice corresponding to a single cell in the z direction. In tests 1 and 2, all the # particles of a given species in the same slice have the exact same momentum -dV_slice = size_x*size_y +dV_slice = size_x * size_y if is_2D: - dt = 1./(scc.c*np.sqrt(2.)) + dt = 1.0 / (scc.c * np.sqrt(2.0)) yt_z_string = "particle_position_y" - nppcell_1 = 10000*8 - nppcell_2 = 900*8 + nppcell_1 = 10000 * 8 + nppcell_2 = 900 * 8 else: - dt = 1./(scc.c*np.sqrt(3.)) + dt = 1.0 / (scc.c * np.sqrt(3.0)) yt_z_string = "particle_position_z" nppcell_1 = 10000 nppcell_2 = 900 # In test 1 and 2, the energy in cells number i (in z direction) is typically Energy_step * i**2 -Energy_step = 22.*keV_to_Joule +Energy_step = 22.0 * keV_to_Joule -def is_close(val1, val2, rtol=default_tol, atol=0.): + +def is_close(val1, val2, rtol=default_tol, atol=0.0): ## Wrapper around numpy.isclose, used to override the default tolerances. return np.isclose(val1, val2, rtol=rtol, atol=atol) + def add_existing_species_to_dict(yt_ad, data_dict, species_name, prefix, suffix): - data_dict[prefix+"_px_"+suffix] = yt_ad[species_name, "particle_momentum_x"].v - data_dict[prefix+"_py_"+suffix] = yt_ad[species_name, "particle_momentum_y"].v - data_dict[prefix+"_pz_"+suffix] = yt_ad[species_name, "particle_momentum_z"].v - data_dict[prefix+"_w_"+suffix] = yt_ad[species_name, "particle_weight"].v - data_dict[prefix+"_id_"+suffix] = yt_ad[species_name, "particle_id"].v - data_dict[prefix+"_cpu_"+suffix] = yt_ad[species_name, "particle_cpu"].v - data_dict[prefix+"_z_"+suffix] = yt_ad[species_name, yt_z_string].v + data_dict[prefix + "_px_" + suffix] = yt_ad[species_name, "particle_momentum_x"].v + data_dict[prefix + "_py_" + suffix] = yt_ad[species_name, "particle_momentum_y"].v + data_dict[prefix + "_pz_" + suffix] = yt_ad[species_name, "particle_momentum_z"].v + data_dict[prefix + "_w_" + suffix] = yt_ad[species_name, "particle_weight"].v + data_dict[prefix + "_id_" + suffix] = yt_ad[species_name, "particle_id"].v + data_dict[prefix + "_cpu_" + suffix] = yt_ad[species_name, "particle_cpu"].v + data_dict[prefix + "_z_" + suffix] = yt_ad[species_name, yt_z_string].v + def add_empty_species_to_dict(data_dict, species_name, prefix, suffix): - data_dict[prefix+"_px_"+suffix] = np.empty(0) - data_dict[prefix+"_py_"+suffix] = np.empty(0) - data_dict[prefix+"_pz_"+suffix] = np.empty(0) - data_dict[prefix+"_w_"+suffix] = np.empty(0) - data_dict[prefix+"_id_"+suffix] = np.empty(0) - data_dict[prefix+"_cpu_"+suffix] = np.empty(0) - data_dict[prefix+"_z_"+suffix] = np.empty(0) + data_dict[prefix + "_px_" + suffix] = np.empty(0) + data_dict[prefix + "_py_" + suffix] = np.empty(0) + data_dict[prefix + "_pz_" + suffix] = np.empty(0) + data_dict[prefix + "_w_" + suffix] = np.empty(0) + data_dict[prefix + "_id_" + suffix] = np.empty(0) + data_dict[prefix + "_cpu_" + suffix] = np.empty(0) + data_dict[prefix + "_z_" + suffix] = np.empty(0) + def add_species_to_dict(yt_ad, data_dict, species_name, prefix, suffix): try: @@ -138,65 +147,79 @@ def add_species_to_dict(yt_ad, data_dict, species_name, prefix, suffix): ## entirely fuses into alphas. add_empty_species_to_dict(data_dict, species_name, prefix, suffix) + def check_particle_number_conservation(data): total_w_proton_start = np.sum(data["proton_w_start"]) - total_w_proton_end = np.sum(data["proton_w_end"]) - total_w_boron_start = np.sum(data["boron_w_start"]) - total_w_boron_end = np.sum(data["boron_w_end"]) + total_w_proton_end = np.sum(data["proton_w_end"]) + total_w_boron_start = np.sum(data["boron_w_start"]) + total_w_boron_end = np.sum(data["boron_w_end"]) consumed_proton = total_w_proton_start - total_w_proton_end - consumed_boron = total_w_boron_start - total_w_boron_end - created_alpha = np.sum(data["alpha_w_end"]) - assert(consumed_proton >= 0.) - assert(consumed_boron >= 0.) - assert(created_alpha >= 0.) + consumed_boron = total_w_boron_start - total_w_boron_end + created_alpha = np.sum(data["alpha_w_end"]) + assert consumed_proton >= 0.0 + assert consumed_boron >= 0.0 + assert created_alpha >= 0.0 ## Check that number of consumed proton and consumed boron are equal assert_scale = max(total_w_proton_start, total_w_boron_start) - assert(is_close(consumed_proton, consumed_boron, rtol = 0., atol = default_tol*assert_scale)) + assert is_close( + consumed_proton, consumed_boron, rtol=0.0, atol=default_tol * assert_scale + ) ## Check that number of consumed particles corresponds to number of produced alpha ## Factor 3 is here because each nuclear fusion reaction produces 3 alphas - assert(is_close(total_w_proton_start, total_w_proton_end + created_alpha/3.)) - assert(is_close(total_w_boron_start, total_w_boron_end + created_alpha/3.)) + assert is_close(total_w_proton_start, total_w_proton_end + created_alpha / 3.0) + assert is_close(total_w_boron_start, total_w_boron_end + created_alpha / 3.0) + def compute_energy_array(data, species_name, suffix, m): ## Relativistic computation of kinetic energy for a given species - psq_array = data[species_name+'_px_'+suffix]**2 + data[species_name+'_py_'+suffix]**2 + \ - data[species_name+'_pz_'+suffix]**2 - rest_energy = m*scc.c**2 - return np.sqrt(psq_array*scc.c**2 + rest_energy**2) - rest_energy + psq_array = ( + data[species_name + "_px_" + suffix] ** 2 + + data[species_name + "_py_" + suffix] ** 2 + + data[species_name + "_pz_" + suffix] ** 2 + ) + rest_energy = m * scc.c**2 + return np.sqrt(psq_array * scc.c**2 + rest_energy**2) - rest_energy + def check_energy_conservation(data): proton_energy_start = compute_energy_array(data, "proton", "start", m_p) - proton_energy_end = compute_energy_array(data, "proton", "end", m_p) - boron_energy_start = compute_energy_array(data, "boron", "start", m_b) - boron_energy_end = compute_energy_array(data, "boron", "end", m_b) - alpha_energy_end = compute_energy_array(data, "alpha", "end", m_a) - total_energy_start = np.sum(proton_energy_start*data["proton_w_start"]) + \ - np.sum(boron_energy_start*data["boron_w_start"]) - total_energy_end = np.sum(proton_energy_end*data["proton_w_end"]) + \ - np.sum(boron_energy_end*data["boron_w_end"]) + \ - np.sum(alpha_energy_end*data["alpha_w_end"]) + proton_energy_end = compute_energy_array(data, "proton", "end", m_p) + boron_energy_start = compute_energy_array(data, "boron", "start", m_b) + boron_energy_end = compute_energy_array(data, "boron", "end", m_b) + alpha_energy_end = compute_energy_array(data, "alpha", "end", m_a) + total_energy_start = np.sum(proton_energy_start * data["proton_w_start"]) + np.sum( + boron_energy_start * data["boron_w_start"] + ) + total_energy_end = ( + np.sum(proton_energy_end * data["proton_w_end"]) + + np.sum(boron_energy_end * data["boron_w_end"]) + + np.sum(alpha_energy_end * data["alpha_w_end"]) + ) ## Factor 3 is here because each nuclear fusion reaction produces 3 alphas - n_fusion_reaction = np.sum(data["alpha_w_end"])/3. - assert(is_close(total_energy_end, - total_energy_start + n_fusion_reaction*E_fusion_total, - rtol = 1.e-8)) + n_fusion_reaction = np.sum(data["alpha_w_end"]) / 3.0 + assert is_close( + total_energy_end, + total_energy_start + n_fusion_reaction * E_fusion_total, + rtol=1.0e-8, + ) + def check_momentum_conservation(data): - proton_total_px_start = np.sum(data["proton_px_start"]*data["proton_w_start"]) - proton_total_py_start = np.sum(data["proton_py_start"]*data["proton_w_start"]) - proton_total_pz_start = np.sum(data["proton_pz_start"]*data["proton_w_start"]) - proton_total_px_end = np.sum(data["proton_px_end"]*data["proton_w_end"]) - proton_total_py_end = np.sum(data["proton_py_end"]*data["proton_w_end"]) - proton_total_pz_end = np.sum(data["proton_pz_end"]*data["proton_w_end"]) - boron_total_px_start = np.sum(data["boron_px_start"]*data["boron_w_start"]) - boron_total_py_start = np.sum(data["boron_py_start"]*data["boron_w_start"]) - boron_total_pz_start = np.sum(data["boron_pz_start"]*data["boron_w_start"]) - boron_total_px_end = np.sum(data["boron_px_end"]*data["boron_w_end"]) - boron_total_py_end = np.sum(data["boron_py_end"]*data["boron_w_end"]) - boron_total_pz_end = np.sum(data["boron_pz_end"]*data["boron_w_end"]) - alpha_total_px_end = np.sum(data["alpha_px_end"]*data["alpha_w_end"]) - alpha_total_py_end = np.sum(data["alpha_py_end"]*data["alpha_w_end"]) - alpha_total_pz_end = np.sum(data["alpha_pz_end"]*data["alpha_w_end"]) + proton_total_px_start = np.sum(data["proton_px_start"] * data["proton_w_start"]) + proton_total_py_start = np.sum(data["proton_py_start"] * data["proton_w_start"]) + proton_total_pz_start = np.sum(data["proton_pz_start"] * data["proton_w_start"]) + proton_total_px_end = np.sum(data["proton_px_end"] * data["proton_w_end"]) + proton_total_py_end = np.sum(data["proton_py_end"] * data["proton_w_end"]) + proton_total_pz_end = np.sum(data["proton_pz_end"] * data["proton_w_end"]) + boron_total_px_start = np.sum(data["boron_px_start"] * data["boron_w_start"]) + boron_total_py_start = np.sum(data["boron_py_start"] * data["boron_w_start"]) + boron_total_pz_start = np.sum(data["boron_pz_start"] * data["boron_w_start"]) + boron_total_px_end = np.sum(data["boron_px_end"] * data["boron_w_end"]) + boron_total_py_end = np.sum(data["boron_py_end"] * data["boron_w_end"]) + boron_total_pz_end = np.sum(data["boron_pz_end"] * data["boron_w_end"]) + alpha_total_px_end = np.sum(data["alpha_px_end"] * data["alpha_w_end"]) + alpha_total_py_end = np.sum(data["alpha_py_end"] * data["alpha_w_end"]) + alpha_total_pz_end = np.sum(data["alpha_pz_end"] * data["alpha_w_end"]) total_px_start = proton_total_px_start + boron_total_px_start total_py_start = proton_total_py_start + boron_total_py_start total_pz_start = proton_total_pz_start + boron_total_pz_start @@ -204,42 +227,45 @@ def check_momentum_conservation(data): total_py_end = proton_total_py_end + boron_total_py_end + alpha_total_py_end total_pz_end = proton_total_pz_end + boron_total_pz_end + alpha_total_pz_end ## Absolute tolerance is needed because sometimes the initial momentum is exactly 0 - assert(is_close(total_px_start, total_px_end, atol=1.e-15)) - assert(is_close(total_py_start, total_py_end, atol=1.e-15)) - assert(is_close(total_pz_start, total_pz_end, atol=1.e-15)) + assert is_close(total_px_start, total_px_end, atol=1.0e-15) + assert is_close(total_py_start, total_py_end, atol=1.0e-15) + assert is_close(total_pz_start, total_pz_end, atol=1.0e-15) + def check_id(data): ## Check that all created particles have unique id + cpu identifier (two particles with ## different cpu can have the same id) - complex_id = data["alpha_id_end"] + 1j*data["alpha_cpu_end"] - assert(complex_id.shape == np.unique(complex_id).shape) + complex_id = data["alpha_id_end"] + 1j * data["alpha_cpu_end"] + assert complex_id.shape == np.unique(complex_id).shape + def basic_product_particles_check(data): ## For each nuclear fusion reaction in the code, we create 6 alpha macroparticles. So the ## total number of alpha macroparticles must be a multiple of 6. num_alpha = data["alpha_w_end"].shape[0] - assert(num_alpha%6 == 0) + assert num_alpha % 6 == 0 ## The weight of the 6 macroparticles coming from a single fusion event should be the same. ## We verify this here. - assert(np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][1::6])) - assert(np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][2::6])) - assert(np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][3::6])) - assert(np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][4::6])) - assert(np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][5::6])) + assert np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][1::6]) + assert np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][2::6]) + assert np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][3::6]) + assert np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][4::6]) + assert np.array_equal(data["alpha_w_end"][::6], data["alpha_w_end"][5::6]) ## When we create 6 macroparticles, the first has the exact same momentum as the second, the ## third has the same as the fourth and the fifth has the same as the sixth. We verify this ## here - assert(np.array_equal(data["alpha_px_end"][::6], data["alpha_px_end"][1::6])) - assert(np.array_equal(data["alpha_py_end"][::6], data["alpha_py_end"][1::6])) - assert(np.array_equal(data["alpha_pz_end"][::6], data["alpha_pz_end"][1::6])) - assert(np.array_equal(data["alpha_px_end"][2::6], data["alpha_px_end"][3::6])) - assert(np.array_equal(data["alpha_py_end"][2::6], data["alpha_py_end"][3::6])) - assert(np.array_equal(data["alpha_pz_end"][2::6], data["alpha_pz_end"][3::6])) - assert(np.array_equal(data["alpha_px_end"][4::6], data["alpha_px_end"][5::6])) - assert(np.array_equal(data["alpha_py_end"][4::6], data["alpha_py_end"][5::6])) - assert(np.array_equal(data["alpha_pz_end"][4::6], data["alpha_pz_end"][5::6])) + assert np.array_equal(data["alpha_px_end"][::6], data["alpha_px_end"][1::6]) + assert np.array_equal(data["alpha_py_end"][::6], data["alpha_py_end"][1::6]) + assert np.array_equal(data["alpha_pz_end"][::6], data["alpha_pz_end"][1::6]) + assert np.array_equal(data["alpha_px_end"][2::6], data["alpha_px_end"][3::6]) + assert np.array_equal(data["alpha_py_end"][2::6], data["alpha_py_end"][3::6]) + assert np.array_equal(data["alpha_pz_end"][2::6], data["alpha_pz_end"][3::6]) + assert np.array_equal(data["alpha_px_end"][4::6], data["alpha_px_end"][5::6]) + assert np.array_equal(data["alpha_py_end"][4::6], data["alpha_py_end"][5::6]) + assert np.array_equal(data["alpha_pz_end"][4::6], data["alpha_pz_end"][5::6]) + def generic_check(data): check_particle_number_conservation(data) @@ -248,39 +274,43 @@ def generic_check(data): check_id(data) basic_product_particles_check(data) + def check_isotropy(data, relative_tolerance): ## Checks that the alpha particles are emitted isotropically - average_px_sq = np.average(data["alpha_px_end"]*data["alpha_px_end"]) - average_py_sq = np.average(data["alpha_py_end"]*data["alpha_py_end"]) - average_pz_sq = np.average(data["alpha_pz_end"]*data["alpha_pz_end"]) - assert(is_close(average_px_sq, average_py_sq, rtol = relative_tolerance)) - assert(is_close(average_px_sq, average_pz_sq, rtol = relative_tolerance)) + average_px_sq = np.average(data["alpha_px_end"] * data["alpha_px_end"]) + average_py_sq = np.average(data["alpha_py_end"] * data["alpha_py_end"]) + average_pz_sq = np.average(data["alpha_pz_end"] * data["alpha_pz_end"]) + assert is_close(average_px_sq, average_py_sq, rtol=relative_tolerance) + assert is_close(average_px_sq, average_pz_sq, rtol=relative_tolerance) + def astrophysical_factor_lowE(E): ## E is in keV ## Returns astrophysical factor in MeV b using the low energy fit in the range E < 400 keV ## described in equation (3) of A. Tentori and F. Belloni, Nuclear Fusion, 63, 086001 (2023) - C0 = 197. + C0 = 197.0 C1 = 0.269 C2 = 2.54e-4 AL = 1.82e4 - EL = 148. + EL = 148.0 dEL = 2.35 - return C0 + C1*E + C2*E**2 + AL/((E-EL)**2 + dEL**2) + return C0 + C1 * E + C2 * E**2 + AL / ((E - EL) ** 2 + dEL**2) + def astrophysical_factor_midE(E): ## E is in keV ## Returns astrophysical factor in MeV b using the mid energy fit in the range ## 400 keV < E < 668 keV described in equation (4) of A. Tentori and F. Belloni, ## Nuclear Fusion, 63, 086001 (2023) - D0 = 346. - D1 = 150. + D0 = 346.0 + D1 = 150.0 D2 = -59.9 D5 = -0.460 - E_400 = 400. - E_100 = 100. - E_norm = (E - E_400)/E_100 - return D0 + D1*E_norm + D2*E_norm**2 + D5*E_norm**5 + E_400 = 400.0 + E_100 = 100.0 + E_norm = (E - E_400) / E_100 + return D0 + D1 * E_norm + D2 * E_norm**2 + D5 * E_norm**5 + def astrophysical_factor_highE(E): ## E is in keV @@ -292,27 +322,36 @@ def astrophysical_factor_highE(E): A2 = 1.36e6 A3 = 3.71e6 E0 = 640.9 - E1 = 1211. - E2 = 2340. - E3 = 3294. + E1 = 1211.0 + E2 = 2340.0 + E3 = 3294.0 dE0 = 85.5 - dE1 = 414. - dE2 = 221. - dE3 = 351. + dE1 = 414.0 + dE2 = 221.0 + dE3 = 351.0 B = 0.381 - return A0/((E-E0)**2 + dE0**2) + A1/((E-E1)**2 + dE1**2) + \ - A2/((E-E2)**2 + dE2**2) + A3/((E-E3)**2 + dE3**2) + B + return ( + A0 / ((E - E0) ** 2 + dE0**2) + + A1 / ((E - E1) ** 2 + dE1**2) + + A2 / ((E - E2) ** 2 + dE2**2) + + A3 / ((E - E3) ** 2 + dE3**2) + + B + ) + def astrophysical_factor(E): ## E is in keV ## Returns astrophysical factor in MeV b using the fits described in A. Tentori ## and F. Belloni, Nuclear Fusion, 63, 086001 (2023) conditions = [E <= 400, E <= 668, E > 668] - choices = [astrophysical_factor_lowE(E), - astrophysical_factor_midE(E), - astrophysical_factor_highE(E)] + choices = [ + astrophysical_factor_lowE(E), + astrophysical_factor_midE(E), + astrophysical_factor_highE(E), + ] return np.select(conditions, choices) + def pb_cross_section_buck_fit(E): ## E is in MeV ## Returns cross section in b using a power law fit of the data presented in Buck et al., @@ -321,52 +360,75 @@ def pb_cross_section_buck_fit(E): ## Cross section at E = E_start_fit = 3.5 MeV cross_section_start_fit = 0.01277998 slope_fit = -2.661840717596765 - return cross_section_start_fit*(E/E_start_fit)**slope_fit + return cross_section_start_fit * (E / E_start_fit) ** slope_fit + def pb_cross_section(E): ## E is in keV ## Returns cross section in b using the fits described in A. Tentori and F. Belloni, ## Nucl. Fusion, 63, 086001 (2023) for E < 9.76 MeV otherwise returns a power law fit ## of the data in Buck et al., Nuclear Physics A, 398(2), 189-202 (1983) - E_MeV = E/1.e3 + E_MeV = E / 1.0e3 conditions = [E <= 9760, E > 9760] - choices = [astrophysical_factor(E)/E_MeV * np.exp(-np.sqrt(E_Gamow_MeV / E_MeV)), - pb_cross_section_buck_fit(E_MeV)] + choices = [ + astrophysical_factor(E) / E_MeV * np.exp(-np.sqrt(E_Gamow_MeV / E_MeV)), + pb_cross_section_buck_fit(E_MeV), + ] return np.select(conditions, choices) + def E_com_to_p_sq_com(m1, m2, E): ## E is the total (kinetic+mass) energy of a two particle (with mass m1 and m2) system in ## its center of mass frame, in J. ## Returns the square norm of the momentum of each particle in that frame. - E_ratio = E/((m1+m2)*scc.c**2) - return m1*m2*scc.c**2 * (E_ratio**2 - 1) + (m1-m2)**2*scc.c**2/4 * (E_ratio - 1./E_ratio)**2 + E_ratio = E / ((m1 + m2) * scc.c**2) + return ( + m1 * m2 * scc.c**2 * (E_ratio**2 - 1) + + (m1 - m2) ** 2 * scc.c**2 / 4 * (E_ratio - 1.0 / E_ratio) ** 2 + ) + def compute_relative_v_com(E): ## E is the kinetic energy of proton+boron in the center of mass frame, in keV ## Returns the relative velocity between proton and boron in this frame, in m/s - E_J = E*keV_to_Joule + (m_p + m_b)*scc.c**2 + E_J = E * keV_to_Joule + (m_p + m_b) * scc.c**2 p_sq = E_com_to_p_sq_com(m_p, m_b, E_J) p = np.sqrt(p_sq) - gamma_p = np.sqrt(1. + p_sq / (m_p*scc.c)**2) - gamma_b = np.sqrt(1. + p_sq / (m_b*scc.c)**2) - v_p = p/(gamma_p*m_p) - v_b = p/(gamma_b*m_b) - return v_p+v_b + gamma_p = np.sqrt(1.0 + p_sq / (m_p * scc.c) ** 2) + gamma_b = np.sqrt(1.0 + p_sq / (m_b * scc.c) ** 2) + v_p = p / (gamma_p * m_p) + v_b = p / (gamma_b * m_b) + return v_p + v_b + def expected_alpha_weight_com(E_com, proton_density, boron_density, dV, dt): ## Computes expected number of produced alpha particles as a function of energy E_com in the ## center of mass frame. E_com is in keV. - assert(np.all(E_com>=0)) + assert np.all(E_com >= 0) ## Case E_com == 0 is handled manually to avoid division by zero conditions = [E_com == 0, E_com > 0] ## Necessary to avoid division by 0 warning when pb_cross_section is evaluated - E_com_never_zero = np.clip(E_com, 1.e-15, None) - choices = [0., pb_cross_section(E_com_never_zero)*compute_relative_v_com(E_com_never_zero)] + E_com_never_zero = np.clip(E_com, 1.0e-15, None) + choices = [ + 0.0, + pb_cross_section(E_com_never_zero) * compute_relative_v_com(E_com_never_zero), + ] sigma_times_vrel = np.select(conditions, choices) ## Factor 3 is here because each fusion reaction produces 3 alphas - return 3.*proton_density*boron_density*sigma_times_vrel*barn_to_square_meter*dV*dt - -def check_macroparticle_number(data, fusion_probability_target_value, num_pair_per_cell): + return ( + 3.0 + * proton_density + * boron_density + * sigma_times_vrel + * barn_to_square_meter + * dV + * dt + ) + + +def check_macroparticle_number( + data, fusion_probability_target_value, num_pair_per_cell +): ## Checks that the number of macroparticles is as expected for the first and second tests ## The first slice 0 < z < 1 does not contribute to alpha creation @@ -374,65 +436,84 @@ def check_macroparticle_number(data, fusion_probability_target_value, num_pair_p ## In these tests, the fusion_multiplier is so high that the fusion probability per pair is ## equal to the parameter fusion_probability_target_value fusion_probability_per_pair = fusion_probability_target_value - expected_fusion_number = numcells*num_pair_per_cell*fusion_probability_per_pair + expected_fusion_number = numcells * num_pair_per_cell * fusion_probability_per_pair ## Each fusion event produces 6 alpha macroparticles - expected_macroparticle_number = 6.*expected_fusion_number - std_macroparticle_number = 6.*np.sqrt(expected_fusion_number) + expected_macroparticle_number = 6.0 * expected_fusion_number + std_macroparticle_number = 6.0 * np.sqrt(expected_fusion_number) actual_macroparticle_number = data["alpha_w_end"].shape[0] # 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions - assert(is_close(actual_macroparticle_number, expected_macroparticle_number, rtol = 0., - atol = 5.*std_macroparticle_number)) + assert is_close( + actual_macroparticle_number, + expected_macroparticle_number, + rtol=0.0, + atol=5.0 * std_macroparticle_number, + ) ## used in subsequent function return expected_fusion_number + def p_sq_boron_frame_to_E_COM_frame(p_proton_sq): # Takes the proton square norm of the momentum in the boron rest frame and returns the total # kinetic energy in the center of mass frame. Everything is in SI units. # Total (kinetic + mass) energy in lab frame - E_lab = np.sqrt(p_proton_sq*scc.c**2 + (m_p*scc.c**2)**2) + m_b*scc.c**2 + E_lab = np.sqrt(p_proton_sq * scc.c**2 + (m_p * scc.c**2) ** 2) + m_b * scc.c**2 # Use invariant E**2 - p**2c**2 of 4-momentum norm to compute energy in center of mass frame - E_com = np.sqrt(E_lab**2 - p_proton_sq*scc.c**2) + E_com = np.sqrt(E_lab**2 - p_proton_sq * scc.c**2) # Corresponding kinetic energy - E_com_kin = E_com - (m_b+m_p)*scc.c**2 - return E_com_kin*(p_proton_sq>0.) + E_com_kin = E_com - (m_b + m_p) * scc.c**2 + return E_com_kin * (p_proton_sq > 0.0) + def p_sq_to_kinetic_energy(p_sq, m): ## Returns the kinetic energy of a particle as a function of its squared momentum. ## Everything is in SI units. - return np.sqrt(p_sq*scc.c**2 + (m*scc.c**2)**2) - (m*scc.c**2) + return np.sqrt(p_sq * scc.c**2 + (m * scc.c**2) ** 2) - (m * scc.c**2) + def compute_E_com1(data): ## Computes kinetic energy (in Joule) in the center of frame for the first test ## Square norm of the momentum of proton/boron as a function of cell number in z direction - p_sq = 2.*m_reduced*(Energy_step*np.arange(size_z)**2) + p_sq = 2.0 * m_reduced * (Energy_step * np.arange(size_z) ** 2) return p_sq_to_kinetic_energy(p_sq, m_b) + p_sq_to_kinetic_energy(p_sq, m_p) + def compute_E_com2(data): ## Computes kinetic energy (in Joule) in the center of frame for the second test ## Square norm of the momentum of the proton as a function of cell number in z direction - p_proton_sq = 2.*m_p*(Energy_step*np.arange(size_z)**2) + p_proton_sq = 2.0 * m_p * (Energy_step * np.arange(size_z) ** 2) return p_sq_boron_frame_to_E_COM_frame(p_proton_sq) -def check_alpha_yield(data, expected_fusion_number, E_com, proton_density, boron_density): + +def check_alpha_yield( + data, expected_fusion_number, E_com, proton_density, boron_density +): ## Checks that the fusion yield is as expected for the first and second tests. ## Proton and boron densities are in m^-3. - alpha_weight_theory = expected_alpha_weight_com(E_com/keV_to_Joule, proton_density, - boron_density, dV_slice, dt) - alpha_weight_simulation = np.histogram(data["alpha_z_end"], bins=size_z, range=(0, size_z), - weights = data["alpha_w_end"])[0] + alpha_weight_theory = expected_alpha_weight_com( + E_com / keV_to_Joule, proton_density, boron_density, dV_slice, dt + ) + alpha_weight_simulation = np.histogram( + data["alpha_z_end"], bins=size_z, range=(0, size_z), weights=data["alpha_w_end"] + )[0] ## -1 is here because the first slice 0 < z < 1 does not contribute to alpha creation - expected_fusion_number_per_slice = expected_fusion_number/(size_z-1) - relative_std_alpha_weight = 1./np.sqrt(expected_fusion_number_per_slice) + expected_fusion_number_per_slice = expected_fusion_number / (size_z - 1) + relative_std_alpha_weight = 1.0 / np.sqrt(expected_fusion_number_per_slice) # 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions - assert(np.all(is_close(alpha_weight_theory, alpha_weight_simulation, - rtol = 5.*relative_std_alpha_weight))) + assert np.all( + is_close( + alpha_weight_theory, + alpha_weight_simulation, + rtol=5.0 * relative_std_alpha_weight, + ) + ) + def check_initial_energy1(data, E_com): ## In WarpX, the initial momentum of the alphas is computed assuming that the fusion process @@ -461,7 +542,7 @@ def check_initial_energy1(data, E_com): E_kinetic_com_before = E_com[slice_number] ## Total (kinetic + mass) energy in the lab frame after ## proton + boron 11 -> alpha + beryllium 8 - E_total_com_after = E_kinetic_com_before + E_fusion + (m_a + m_be)*scc.c**2 + E_total_com_after = E_kinetic_com_before + E_fusion + (m_a + m_be) * scc.c**2 ## Corresponding momentum norm squared of alpha1/beryllium p_sq_after = E_com_to_p_sq_com(m_a, m_be, E_total_com_after) ## Corresponding kinetic energy for alpha1 @@ -475,16 +556,21 @@ def check_initial_energy1(data, E_com): ## corresponds to an alpha emitted exactly in the (opposite) direction of the beryllium ## in the center of mass frame. This calculation involves solving a polynomial equation of ## order 2 in p_alpha23. - max_p_alpha23 = 0.5*(np.sqrt(p_sq_after) + \ - np.sqrt(4*m_a*energy_alpha2_plus_3_theory - p_sq_after)) - min_p_alpha23 = 0.5*(np.sqrt(p_sq_after) - \ - np.sqrt(4*m_a*energy_alpha2_plus_3_theory - p_sq_after)) - max_energy_alpha23 = max_p_alpha23**2/(2.*m_a) - min_energy_alpha23 = min_p_alpha23**2/(2.*m_a) + max_p_alpha23 = 0.5 * ( + np.sqrt(p_sq_after) + + np.sqrt(4 * m_a * energy_alpha2_plus_3_theory - p_sq_after) + ) + min_p_alpha23 = 0.5 * ( + np.sqrt(p_sq_after) + - np.sqrt(4 * m_a * energy_alpha2_plus_3_theory - p_sq_after) + ) + max_energy_alpha23 = max_p_alpha23**2 / (2.0 * m_a) + min_energy_alpha23 = min_p_alpha23**2 / (2.0 * m_a) ## Get the energy of all alphas in the slice - energy_alpha_slice = energy_alpha_simulation[(z_alpha >= slice_number)* \ - (z_alpha < (slice_number + 1))] + energy_alpha_slice = energy_alpha_simulation[ + (z_alpha >= slice_number) * (z_alpha < (slice_number + 1)) + ] ## Energy of alphas1 (here, first macroparticle of each fusion event) in the slice energy_alpha1_simulation = energy_alpha_slice[::6] ## Energy of alphas2 (here, third macroparticle of each fusion event) in the slice @@ -492,11 +578,25 @@ def check_initial_energy1(data, E_com): ## Energy of alphas3 (here, fifth macroparticle of each fusion event) in the slice energy_alpha3_simulation = energy_alpha_slice[4::6] - assert(np.all(is_close(energy_alpha1_simulation, energy_alpha1_theory, rtol=5.e-8))) - assert(is_close(np.amax(energy_alpha2_simulation), max_energy_alpha23, rtol=1.e-2)) - assert(is_close(np.amin(energy_alpha2_simulation), min_energy_alpha23, rtol=1.e-2)) - assert(is_close(np.amax(energy_alpha3_simulation), max_energy_alpha23, rtol=1.e-2)) - assert(is_close(np.amin(energy_alpha3_simulation), min_energy_alpha23, rtol=1.e-2)) + assert np.all( + is_close(energy_alpha1_simulation, energy_alpha1_theory, rtol=5.0e-8) + ) + ## Check that the max / min value are comparable to the analytical value + ## The minimum value is checked to be within 20 keV of the analytical value + ## The maximum value is checked to be within 1% of the analytical value + assert is_close( + np.amax(energy_alpha2_simulation), max_energy_alpha23, rtol=1.0e-2 + ) + assert is_close( + np.amin(energy_alpha2_simulation), min_energy_alpha23, atol=3.218e-15 + ) + assert is_close( + np.amax(energy_alpha3_simulation), max_energy_alpha23, rtol=1.0e-2 + ) + assert is_close( + np.amin(energy_alpha3_simulation), min_energy_alpha23, atol=3.218e-15 + ) + def check_initial_energy2(data): ## In WarpX, the initial momentum of the alphas is computed assuming that the fusion process @@ -523,9 +623,9 @@ def check_initial_energy2(data): for slice_number in range(1, size_z): ## For simplicity, all the calculations in this function are done nonrelativistically ## Proton kinetic energy in the lab frame before fusion - E_proton_nonrelativistic = Energy_step*slice_number**2 + E_proton_nonrelativistic = Energy_step * slice_number**2 ## Corresponding square norm of proton momentum - p_proton_sq = 2.*m_p*E_proton_nonrelativistic + p_proton_sq = 2.0 * m_p * E_proton_nonrelativistic ## Kinetic energy in the lab frame after ## proton + boron 11 -> alpha + beryllium 8 E_after_fusion = E_proton_nonrelativistic + E_fusion @@ -534,21 +634,29 @@ def check_initial_energy2(data): ## calculation is done by noting that the maximum (minimum) energy corresponds to an alpha ## emitted exactly in the (opposite) direction of the proton in the lab frame. This ## calculation involves solving a polynomial equation of order 2 in p_alpha1. - max_p_alpha1 = (m_a/m_be*np.sqrt(p_proton_sq) + \ - np.sqrt(-m_a/m_be*p_proton_sq + 2.*E_after_fusion*m_a*(m_a/m_be + 1.))) / \ - (m_a/m_be + 1.) - min_p_alpha1 = (m_a/m_be*np.sqrt(p_proton_sq) - \ - np.sqrt(-m_a/m_be*p_proton_sq + 2.*E_after_fusion*m_a*(m_a/m_be + 1.))) / \ - (m_a/m_be + 1.) - max_energy_alpha1 = max_p_alpha1**2/(2*m_a) - min_energy_alpha1 = min_p_alpha1**2/(2*m_a) + max_p_alpha1 = ( + m_a / m_be * np.sqrt(p_proton_sq) + + np.sqrt( + -m_a / m_be * p_proton_sq + + 2.0 * E_after_fusion * m_a * (m_a / m_be + 1.0) + ) + ) / (m_a / m_be + 1.0) + min_p_alpha1 = ( + m_a / m_be * np.sqrt(p_proton_sq) + - np.sqrt( + -m_a / m_be * p_proton_sq + + 2.0 * E_after_fusion * m_a * (m_a / m_be + 1.0) + ) + ) / (m_a / m_be + 1.0) + max_energy_alpha1 = max_p_alpha1**2 / (2 * m_a) + min_energy_alpha1 = min_p_alpha1**2 / (2 * m_a) ## Corresponding max/min kinetic energy of Beryllium in the lab frame max_E_beryllium = E_after_fusion - min_energy_alpha1 min_E_beryllium = E_after_fusion - max_energy_alpha1 ## Corresponding max/min momentum square of Beryllium in the lab frame - max_p_sq_beryllium = 2.*m_be*max_E_beryllium - min_p_sq_beryllium = 2.*m_be*min_E_beryllium + max_p_sq_beryllium = 2.0 * m_be * max_E_beryllium + min_p_sq_beryllium = 2.0 * m_be * min_E_beryllium ## Corresponding max/min kinetic energy in the lab frame for alpha2 + alpha3 after ## Beryllium decay max_energy_alpha2_plus_3 = max_E_beryllium + E_decay @@ -559,16 +667,21 @@ def check_initial_energy2(data): ## to an alpha emitted exactly in the (opposite) direction of a beryllium with energy ## max_E_beryllium (min_E_beryllium). This calculation involves solving a polynomial ## equation of order 2 in p_alpha23. - max_p_alpha23 = 0.5*(np.sqrt(max_p_sq_beryllium) + \ - np.sqrt(4*m_a*max_energy_alpha2_plus_3 - max_p_sq_beryllium)) - min_p_alpha23 = 0.5*(np.sqrt(min_p_sq_beryllium) - \ - np.sqrt(4*m_a*min_energy_alpha2_plus_3 - min_p_sq_beryllium)) - max_energy_alpha23 = max_p_alpha23**2/(2*m_a) - min_energy_alpha23 = min_p_alpha23**2/(2*m_a) + max_p_alpha23 = 0.5 * ( + np.sqrt(max_p_sq_beryllium) + + np.sqrt(4 * m_a * max_energy_alpha2_plus_3 - max_p_sq_beryllium) + ) + min_p_alpha23 = 0.5 * ( + np.sqrt(min_p_sq_beryllium) + - np.sqrt(4 * m_a * min_energy_alpha2_plus_3 - min_p_sq_beryllium) + ) + max_energy_alpha23 = max_p_alpha23**2 / (2 * m_a) + min_energy_alpha23 = min_p_alpha23**2 / (2 * m_a) ## Get the energy of all alphas in the slice - energy_alpha_slice = energy_alpha_simulation[(z_alpha >= slice_number)* \ - (z_alpha < (slice_number + 1))] + energy_alpha_slice = energy_alpha_simulation[ + (z_alpha >= slice_number) * (z_alpha < (slice_number + 1)) + ] ## Energy of alphas1 (here, first macroparticle of each fusion event) in the slice energy_alpha1_simulation = energy_alpha_slice[::6] ## Energy of alphas2 (here, third macroparticle of each fusion event) in the slice @@ -576,48 +689,73 @@ def check_initial_energy2(data): ## Energy of alphas3 (here, fifth macroparticle of each fusion event) in the slice energy_alpha3_simulation = energy_alpha_slice[4::6] - assert(is_close(np.amax(energy_alpha1_simulation), max_energy_alpha1, rtol=1.e-2)) - assert(is_close(np.amin(energy_alpha1_simulation), min_energy_alpha1, rtol=1.e-2)) - ## Tolerance is quite high below because we don't have a lot of alphas to produce good + assert is_close( + np.amax(energy_alpha1_simulation), max_energy_alpha1, rtol=1.0e-2 + ) + assert is_close( + np.amin(energy_alpha1_simulation), min_energy_alpha1, rtol=1.0e-2 + ) + ## Check that the max / min value are comparable to the analytical value + ## The minimum value is checked to be within 200 keV of the analytical value + ## The maximum value is checked to be within 5% of the analytical value + ## Tolerance is quite high because we don't have a lot of alphas to produce good ## statistics and an event like alpha1 emitted exactly in direction of proton & alpha2 ## emitted exactly in direction opposite to Beryllium is somewhat rare. - assert(is_close(np.amax(energy_alpha2_simulation), max_energy_alpha23, rtol=2.5e-1)) - assert(is_close(np.amin(energy_alpha2_simulation), min_energy_alpha23, rtol=2.5e-1)) - assert(is_close(np.amax(energy_alpha3_simulation), max_energy_alpha23, rtol=2.5e-1)) - assert(is_close(np.amin(energy_alpha3_simulation), min_energy_alpha23, rtol=2.5e-1)) + assert is_close( + np.amax(energy_alpha2_simulation), max_energy_alpha23, rtol=5e-2 + ) + assert is_close( + np.amin(energy_alpha2_simulation), min_energy_alpha23, atol=3.218e-14 + ) + assert is_close( + np.amax(energy_alpha3_simulation), max_energy_alpha23, rtol=5e-2 + ) + assert is_close( + np.amin(energy_alpha3_simulation), min_energy_alpha23, atol=3.218e-14 + ) + def check_xy_isotropy(data): ## Checks that the alpha particles are emitted isotropically in x and y - average_px_sq = np.average(data["alpha_px_end"]*data["alpha_px_end"]) - average_py_sq = np.average(data["alpha_py_end"]*data["alpha_py_end"]) - average_pz_sq = np.average(data["alpha_pz_end"]*data["alpha_pz_end"]) - assert(is_close(average_px_sq, average_py_sq, rtol = 5.e-2)) - assert(average_pz_sq > average_px_sq) - assert(average_pz_sq > average_py_sq) + average_px_sq = np.average(data["alpha_px_end"] * data["alpha_px_end"]) + average_py_sq = np.average(data["alpha_py_end"] * data["alpha_py_end"]) + average_pz_sq = np.average(data["alpha_pz_end"] * data["alpha_pz_end"]) + assert is_close(average_px_sq, average_py_sq, rtol=5.0e-2) + assert average_pz_sq > average_px_sq + assert average_pz_sq > average_py_sq + def sigmav_thermal_fit_lowE_nonresonant(T): ## Temperature T is in keV ## Returns the nonresonant average of cross section multiplied by relative velocity in m^3/s, ## in the range T <= 70 keV, as described by equations 10-14 of A. Tentori and F. Belloni, ## Nuclear Fusion, 63, 086001 (2023). - E0 = (E_Gamow_keV/4.)**(1./3.) * T**(2./3.) - DE0 = 4.*np.sqrt(T*E0/3.) - C0 = 197.*1.e3 - C1 = 0.269*1.e3 - C2 = 2.54e-4*1.e3 - tau = 3.*E0/T - Seff = C0*(1.+5./(12.*tau)) + C1*(E0+35./36.*T) + C2*(E0**2 + 89./36.*E0*T) + E0 = (E_Gamow_keV / 4.0) ** (1.0 / 3.0) * T ** (2.0 / 3.0) + DE0 = 4.0 * np.sqrt(T * E0 / 3.0) + C0 = 197.0 * 1.0e3 + C1 = 0.269 * 1.0e3 + C2 = 2.54e-4 * 1.0e3 + tau = 3.0 * E0 / T + Seff = ( + C0 * (1.0 + 5.0 / (12.0 * tau)) + + C1 * (E0 + 35.0 / 36.0 * T) + + C2 * (E0**2 + 89.0 / 36.0 * E0 * T) + ) ## nonresonant sigma times vrel, in barn meter per second - sigmav_nr_bmps = np.sqrt(2*T*keV_to_Joule/m_reduced) * DE0*Seff/T**2 * np.exp(-tau) + sigmav_nr_bmps = ( + np.sqrt(2 * T * keV_to_Joule / m_reduced) * DE0 * Seff / T**2 * np.exp(-tau) + ) ## Return result in cubic meter per second - return sigmav_nr_bmps*barn_to_square_meter + return sigmav_nr_bmps * barn_to_square_meter + def sigmav_thermal_fit_lowE_resonant(T): ## Temperature T is in keV ## Returns the resonant average of cross section multiplied by relative velocity in m^3/s, ## in the range T <= 70 keV, as described by equation 15 of A. Tentori and F. Belloni, ## Nuclear Fusion, 63, 086001 (2023). - return 5.41e-21 * np.exp(-148./T) / T**(3./2.) + return 5.41e-21 * np.exp(-148.0 / T) / T ** (3.0 / 2.0) + def sigmav_thermal_fit_lowE(T): ## Temperature T is in keV @@ -626,90 +764,105 @@ def sigmav_thermal_fit_lowE(T): ## The fits are valid for T <= 70 keV. return sigmav_thermal_fit_lowE_nonresonant(T) + sigmav_thermal_fit_lowE_resonant(T) + def expected_alpha_thermal(T, proton_density, boron_density, dV, dt): ## Computes the expected number of produced alpha particles when the protons and borons follow ## a Maxwellian distribution with a temperature T, in keV. This uses the thermal fits described ## in A. Tentori and F. Belloni, Nuclear Fusion, 63, 086001 (2023). ## The fit used here is only valid in the range T <= 70 keV. - assert((T >=0) and (T<=70)) + assert (T >= 0) and (T <= 70) sigma_times_vrel = sigmav_thermal_fit_lowE(T) ## Factor 3 is here because each fusion event produces 3 alphas. - return 3.*proton_density*boron_density*sigma_times_vrel*dV*dt + return 3.0 * proton_density * boron_density * sigma_times_vrel * dV * dt + def check_thermal_alpha_yield(data): ## Checks that the number of alpha particles in test3 is as expected - Temperature = 44. # keV - proton_density = 1.e28 # m^-3 - boron_density = 5.e28 # m^-3 + Temperature = 44.0 # keV + proton_density = 1.0e28 # m^-3 + boron_density = 5.0e28 # m^-3 - alpha_weight_theory = expected_alpha_thermal(Temperature, proton_density, boron_density, - dV_total, dt) + alpha_weight_theory = expected_alpha_thermal( + Temperature, proton_density, boron_density, dV_total, dt + ) alpha_weight_simulation = np.sum(data["alpha_w_end"]) - assert(is_close(alpha_weight_theory, alpha_weight_simulation, rtol = 2.e-1)) + assert is_close(alpha_weight_theory, alpha_weight_simulation, rtol=2.0e-1) + def boron_remains(data): ## Checks whether there remains boron macroparticles at the end of the test n_boron_left = data["boron_w_end"].shape[0] - return (n_boron_left > 0) + return n_boron_left > 0 + def specific_check1(data): - check_isotropy(data, relative_tolerance = 3.e-2) - expected_fusion_number = check_macroparticle_number(data, - fusion_probability_target_value = 0.002, - num_pair_per_cell = nppcell_1) + check_isotropy(data, relative_tolerance=3.0e-2) + expected_fusion_number = check_macroparticle_number( + data, fusion_probability_target_value=0.002, num_pair_per_cell=nppcell_1 + ) E_com = compute_E_com1(data) - check_alpha_yield(data, expected_fusion_number, E_com, proton_density = 1., - boron_density = 1.) + check_alpha_yield( + data, expected_fusion_number, E_com, proton_density=1.0, boron_density=1.0 + ) check_initial_energy1(data, E_com) + def specific_check2(data): check_xy_isotropy(data) ## Only 900 particles pairs per cell here because we ignore the 10% of protons that are at rest - expected_fusion_number = check_macroparticle_number(data, - fusion_probability_target_value = 0.02, - num_pair_per_cell = nppcell_2) + expected_fusion_number = check_macroparticle_number( + data, fusion_probability_target_value=0.02, num_pair_per_cell=nppcell_2 + ) E_com = compute_E_com2(data) - check_alpha_yield(data, expected_fusion_number, E_com, proton_density = 1.e20, - boron_density = 1.e26) + check_alpha_yield( + data, expected_fusion_number, E_com, proton_density=1.0e20, boron_density=1.0e26 + ) check_initial_energy2(data) + def specific_check3(data): - check_isotropy(data, relative_tolerance = 1.e-1) + check_isotropy(data, relative_tolerance=1.0e-1) check_thermal_alpha_yield(data) + def specific_check4(data): ## In test 4, the boron initial density is so small that all borons should have fused within a ## timestep dt. We thus assert that no boron remains at the end of the simulation. - assert(not boron_remains(data)) + assert not boron_remains(data) + def specific_check5(data): ## Test 5 is similar to test 4, expect that the parameter fusion_probability_threshold is ## increased to the point that we should severely underestimate the fusion yield. Consequently, ## there should still be borons at the end of the test, which we verify here. - assert(boron_remains(data)) + assert boron_remains(data) + def check_charge_conservation(rho_start, rho_end): - assert(np.all(is_close(rho_start, rho_end, rtol=2.e-11))) + assert np.all(is_close(rho_start, rho_end, rtol=2.0e-11)) + def main(): filename_end = sys.argv[1] - filename_start = filename_end[:-4] + '0000' + filename_start = filename_end[:-4] + "0000" ds_end = yt.load(filename_end) ds_start = yt.load(filename_start) ad_end = ds_end.all_data() ad_start = ds_start.all_data() - field_data_end = ds_end.covering_grid(level=0, left_edge=ds_end.domain_left_edge, - dims=ds_end.domain_dimensions) - field_data_start = ds_start.covering_grid(level=0, left_edge=ds_start.domain_left_edge, - dims=ds_start.domain_dimensions) + field_data_end = ds_end.covering_grid( + level=0, left_edge=ds_end.domain_left_edge, dims=ds_end.domain_dimensions + ) + field_data_start = ds_start.covering_grid( + level=0, left_edge=ds_start.domain_left_edge, dims=ds_start.domain_dimensions + ) ntests = 5 - for i in range(1, ntests+1): - proton_species = "proton"+str(i) - boron_species = "boron"+str(i) - alpha_species = "alpha"+str(i) + for i in range(1, ntests + 1): + proton_species = "proton" + str(i) + boron_species = "boron" + str(i) + alpha_species = "alpha" + str(i) data = {} add_species_to_dict(ad_start, data, proton_species, "proton", "start") add_species_to_dict(ad_start, data, boron_species, "boron", "start") @@ -721,7 +874,7 @@ def main(): generic_check(data) # Checks that are specific to test number i - eval("specific_check"+str(i)+"(data)") + eval("specific_check" + str(i) + "(data)") rho_start = field_data_start["rho"].to_ndarray() rho_end = field_data_end["rho"].to_ndarray() @@ -730,5 +883,6 @@ def main(): test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename_end) + if __name__ == "__main__": main() diff --git a/Examples/Tests/nuclear_fusion/analysis_two_product_fusion.py b/Examples/Tests/nuclear_fusion/analysis_two_product_fusion.py index ad8b7f70e10..be1fbb0702a 100755 --- a/Examples/Tests/nuclear_fusion/analysis_two_product_fusion.py +++ b/Examples/Tests/nuclear_fusion/analysis_two_product_fusion.py @@ -11,7 +11,7 @@ import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI import numpy as np import scipy.constants as scc @@ -46,46 +46,49 @@ ## Please be aware that the relative tolerances are often set empirically in this analysis script, ## so it would not be surprising that some tolerances need to be increased in the future. -default_tol = 1.e-12 # Default relative tolerance +default_tol = 1.0e-12 # Default relative tolerance ## Some physical parameters -keV_to_Joule = scc.e*1e3 -MeV_to_Joule = scc.e*1e6 -barn_to_square_meter = 1.e-28 +keV_to_Joule = scc.e * 1e3 +MeV_to_Joule = scc.e * 1e6 +barn_to_square_meter = 1.0e-28 ## Checks whether this is the 2D or the 3D test -warpx_used_inputs = open('./warpx_used_inputs', 'r').read() -if re.search('geometry.dims = RZ', warpx_used_inputs): +with open("./warpx_used_inputs", "r") as f: + warpx_used_inputs = f.read() +if re.search("geometry.dims = RZ", warpx_used_inputs): is_RZ = True else: is_RZ = False ## Check which kind of test we are doing: D+T or D+D # Define reactants and products -if re.search('tritium', warpx_used_inputs): +if re.search("tritium", warpx_used_inputs): # If tritium appears in the file, than this is the D+T test - reaction_type = 'DT' - reactant_species = ['deuterium', 'tritium'] - product_species = ['helium4', 'neutron'] + reaction_type = "DT" + reactant_species = ["deuterium", "tritium"] + product_species = ["helium4", "neutron"] ntests = 2 - E_fusion = 17.5893*MeV_to_Joule # Energy released during the fusion reaction + E_fusion = 17.5893 * MeV_to_Joule # Energy released during the fusion reaction else: # else, this is the D+D test - reaction_type = 'DD' - reactant_species = ['deuterium', 'hydrogen2'] - product_species = ['helium3', 'neutron'] + reaction_type = "DD" + reactant_species = ["deuterium", "hydrogen2"] + product_species = ["helium3", "neutron"] ntests = 1 - E_fusion = 3.268911e6*MeV_to_Joule + E_fusion = 3.268911e6 * MeV_to_Joule mass = { - 'deuterium': 2.01410177812*scc.m_u, - 'hydrogen2': 2.01410177812*scc.m_u, - 'tritium': 3.0160492779*scc.m_u, - 'helium3': 3.016029*scc.m_u, - 'helium4': 4.00260325413*scc.m_u, - 'neutron': 1.0013784193052508*scc.m_p + "deuterium": 2.01410177812 * scc.m_u, + "hydrogen2": 2.01410177812 * scc.m_u, + "tritium": 3.0160492779 * scc.m_u, + "helium3": 3.016029 * scc.m_u, + "helium4": 4.00260325413 * scc.m_u, + "neutron": 1.0013784193052508 * scc.m_p, } -m_reduced = np.product([mass[s] for s in reactant_species])/np.sum([mass[s] for s in reactant_species]) +m_reduced = np.product([mass[s] for s in reactant_species]) / np.sum( + [mass[s] for s in reactant_species] +) ## Some numerical parameters for this test size_x = 8 @@ -94,10 +97,10 @@ if is_RZ: dV_slice = np.pi * size_x**2 yt_z_string = "particle_position_y" - nppcell_1 = 10000*8 - nppcell_2 = 900*8 + nppcell_1 = 10000 * 8 + nppcell_2 = 900 * 8 else: - dV_slice = size_x*size_y + dV_slice = size_x * size_y yt_z_string = "particle_position_z" nppcell_1 = 10000 nppcell_2 = 900 @@ -105,29 +108,33 @@ # particles of a given species in the same slice have the exact same momentum # In test 1 and 2, the energy in cells number i (in z direction) is typically Energy_step * i**2 -Energy_step = 22.*keV_to_Joule +Energy_step = 22.0 * keV_to_Joule -def is_close(val1, val2, rtol=default_tol, atol=0.): + +def is_close(val1, val2, rtol=default_tol, atol=0.0): ## Wrapper around numpy.isclose, used to override the default tolerances. return np.isclose(val1, val2, rtol=rtol, atol=atol) + def add_existing_species_to_dict(yt_ad, data_dict, species_name, prefix, suffix): - data_dict[prefix+"_px_"+suffix] = yt_ad[species_name, "particle_momentum_x"].v - data_dict[prefix+"_py_"+suffix] = yt_ad[species_name, "particle_momentum_y"].v - data_dict[prefix+"_pz_"+suffix] = yt_ad[species_name, "particle_momentum_z"].v - data_dict[prefix+"_w_"+suffix] = yt_ad[species_name, "particle_weight"].v - data_dict[prefix+"_id_"+suffix] = yt_ad[species_name, "particle_id"].v - data_dict[prefix+"_cpu_"+suffix] = yt_ad[species_name, "particle_cpu"].v - data_dict[prefix+"_z_"+suffix] = yt_ad[species_name, yt_z_string].v + data_dict[prefix + "_px_" + suffix] = yt_ad[species_name, "particle_momentum_x"].v + data_dict[prefix + "_py_" + suffix] = yt_ad[species_name, "particle_momentum_y"].v + data_dict[prefix + "_pz_" + suffix] = yt_ad[species_name, "particle_momentum_z"].v + data_dict[prefix + "_w_" + suffix] = yt_ad[species_name, "particle_weight"].v + data_dict[prefix + "_id_" + suffix] = yt_ad[species_name, "particle_id"].v + data_dict[prefix + "_cpu_" + suffix] = yt_ad[species_name, "particle_cpu"].v + data_dict[prefix + "_z_" + suffix] = yt_ad[species_name, yt_z_string].v + def add_empty_species_to_dict(data_dict, species_name, prefix, suffix): - data_dict[prefix+"_px_"+suffix] = np.empty(0) - data_dict[prefix+"_py_"+suffix] = np.empty(0) - data_dict[prefix+"_pz_"+suffix] = np.empty(0) - data_dict[prefix+"_w_"+suffix] = np.empty(0) - data_dict[prefix+"_id_"+suffix] = np.empty(0) - data_dict[prefix+"_cpu_"+suffix] = np.empty(0) - data_dict[prefix+"_z_"+suffix] = np.empty(0) + data_dict[prefix + "_px_" + suffix] = np.empty(0) + data_dict[prefix + "_py_" + suffix] = np.empty(0) + data_dict[prefix + "_pz_" + suffix] = np.empty(0) + data_dict[prefix + "_w_" + suffix] = np.empty(0) + data_dict[prefix + "_id_" + suffix] = np.empty(0) + data_dict[prefix + "_cpu_" + suffix] = np.empty(0) + data_dict[prefix + "_z_" + suffix] = np.empty(0) + def add_species_to_dict(yt_ad, data_dict, species_name, prefix, suffix): try: @@ -138,47 +145,67 @@ def add_species_to_dict(yt_ad, data_dict, species_name, prefix, suffix): ## dictionnary. add_empty_species_to_dict(data_dict, species_name, prefix, suffix) + def check_particle_number_conservation(data): # Check consumption of reactants total_w_reactant1_start = np.sum(data[reactant_species[0] + "_w_start"]) - total_w_reactant1_end = np.sum(data[reactant_species[0] + "_w_end"]) + total_w_reactant1_end = np.sum(data[reactant_species[0] + "_w_end"]) total_w_reactant2_start = np.sum(data[reactant_species[1] + "_w_start"]) - total_w_reactant2_end = np.sum(data[reactant_species[1] + "_w_end"]) + total_w_reactant2_end = np.sum(data[reactant_species[1] + "_w_end"]) consumed_reactant1 = total_w_reactant1_start - total_w_reactant1_end consumed_reactant2 = total_w_reactant2_start - total_w_reactant2_end - assert(consumed_reactant1 >= 0.) - assert(consumed_reactant2 >= 0.) + assert consumed_reactant1 >= 0.0 + assert consumed_reactant2 >= 0.0 ## Check that number of consumed reactants are equal assert_scale = max(total_w_reactant1_start, total_w_reactant2_start) - assert(is_close(consumed_reactant1, consumed_reactant2, rtol = 0., atol = default_tol*assert_scale)) + assert is_close( + consumed_reactant1, + consumed_reactant2, + rtol=0.0, + atol=default_tol * assert_scale, + ) # That the number of products corresponds consumed particles for species_name in product_species: created_product = np.sum(data[species_name + "_w_end"]) - assert(created_product >= 0.) - assert(is_close(total_w_reactant1_start, total_w_reactant1_end + created_product)) - assert(is_close(total_w_reactant2_start, total_w_reactant2_end + created_product)) + assert created_product >= 0.0 + assert is_close( + total_w_reactant1_start, total_w_reactant1_end + created_product + ) + assert is_close( + total_w_reactant2_start, total_w_reactant2_end + created_product + ) + def compute_energy_array(data, species_name, suffix, m): ## Relativistic computation of kinetic energy for a given species - psq_array = data[species_name+'_px_'+suffix]**2 + data[species_name+'_py_'+suffix]**2 + \ - data[species_name+'_pz_'+suffix]**2 - rest_energy = m*scc.c**2 - return np.sqrt(psq_array*scc.c**2 + rest_energy**2) - rest_energy + psq_array = ( + data[species_name + "_px_" + suffix] ** 2 + + data[species_name + "_py_" + suffix] ** 2 + + data[species_name + "_pz_" + suffix] ** 2 + ) + rest_energy = m * scc.c**2 + return np.sqrt(psq_array * scc.c**2 + rest_energy**2) - rest_energy + def check_energy_conservation(data): total_energy_start = 0 for species_name in reactant_species: - total_energy_start += np.sum( data[species_name + "_w_start"] * \ - compute_energy_array(data, species_name, "start", mass[species_name]) ) + total_energy_start += np.sum( + data[species_name + "_w_start"] + * compute_energy_array(data, species_name, "start", mass[species_name]) + ) total_energy_end = 0 for species_name in product_species + reactant_species: - total_energy_end += np.sum( data[species_name + "_w_end"] * \ - compute_energy_array(data, species_name, "end", mass[species_name]) ) + total_energy_end += np.sum( + data[species_name + "_w_end"] + * compute_energy_array(data, species_name, "end", mass[species_name]) + ) n_fusion_reaction = np.sum(data[product_species[0] + "_w_end"]) - assert(is_close(total_energy_end, - total_energy_start + n_fusion_reaction*E_fusion, - rtol = 1.e-8)) + assert is_close( + total_energy_end, total_energy_start + n_fusion_reaction * E_fusion, rtol=1.0e-8 + ) + def check_momentum_conservation(data): total_px_start = 0 @@ -186,33 +213,43 @@ def check_momentum_conservation(data): total_pz_start = 0 for species_name in reactant_species: total_px_start += np.sum( - data[species_name+'_px_start'] * data[species_name+'_w_start']) + data[species_name + "_px_start"] * data[species_name + "_w_start"] + ) total_py_start += np.sum( - data[species_name+'_py_start'] * data[species_name+'_w_start']) + data[species_name + "_py_start"] * data[species_name + "_w_start"] + ) total_pz_start += np.sum( - data[species_name+'_pz_start'] * data[species_name+'_w_start']) + data[species_name + "_pz_start"] * data[species_name + "_w_start"] + ) total_px_end = 0 total_py_end = 0 total_pz_end = 0 for species_name in reactant_species + product_species: total_px_end += np.sum( - data[species_name+'_px_end'] * data[species_name+'_w_end']) + data[species_name + "_px_end"] * data[species_name + "_w_end"] + ) total_py_end += np.sum( - data[species_name+'_py_end'] * data[species_name+'_w_end']) + data[species_name + "_py_end"] * data[species_name + "_w_end"] + ) total_pz_end += np.sum( - data[species_name+'_pz_end'] * data[species_name+'_w_end']) + data[species_name + "_pz_end"] * data[species_name + "_w_end"] + ) ## Absolute tolerance is needed because sometimes the initial momentum is exactly 0 - assert(is_close(total_px_start, total_px_end, atol=1.e-15)) - assert(is_close(total_py_start, total_py_end, atol=1.e-15)) - assert(is_close(total_pz_start, total_pz_end, atol=1.e-15)) + assert is_close(total_px_start, total_px_end, atol=1.0e-15) + assert is_close(total_py_start, total_py_end, atol=1.0e-15) + assert is_close(total_pz_start, total_pz_end, atol=1.0e-15) + def check_id(data): ## Check that all created particles have unique id + cpu identifier (two particles with ## different cpu can have the same id) for species_name in product_species: - complex_id = data[species_name + "_id_end"] + 1j*data[species_name + "_cpu_end"] - assert(complex_id.shape == np.unique(complex_id).shape) + complex_id = ( + data[species_name + "_id_end"] + 1j * data[species_name + "_cpu_end"] + ) + assert complex_id.shape == np.unique(complex_id).shape + def generic_check(data): check_particle_number_conservation(data) @@ -220,110 +257,155 @@ def generic_check(data): check_momentum_conservation(data) check_id(data) + def check_isotropy(data, relative_tolerance): ## Checks that the product particles are emitted isotropically for species_name in product_species: - average_px_sq = np.average(data[species_name+"_px_end"]*data[species_name+"_px_end"]) - average_py_sq = np.average(data[species_name+"_py_end"]*data[species_name+"_py_end"]) - average_pz_sq = np.average(data[species_name+"_pz_end"]*data[species_name+"_pz_end"]) - assert(is_close(average_px_sq, average_py_sq, rtol = relative_tolerance)) - assert(is_close(average_px_sq, average_pz_sq, rtol = relative_tolerance)) + average_px_sq = np.average( + data[species_name + "_px_end"] * data[species_name + "_px_end"] + ) + average_py_sq = np.average( + data[species_name + "_py_end"] * data[species_name + "_py_end"] + ) + average_pz_sq = np.average( + data[species_name + "_pz_end"] * data[species_name + "_pz_end"] + ) + assert is_close(average_px_sq, average_py_sq, rtol=relative_tolerance) + assert is_close(average_px_sq, average_pz_sq, rtol=relative_tolerance) + def check_xy_isotropy(data): ## Checks that the product particles are emitted isotropically in x and y for species_name in product_species: - average_px_sq = np.average(data[species_name+"_px_end"]*data[species_name+"_px_end"]) - average_py_sq = np.average(data[species_name+"_py_end"]*data[species_name+"_py_end"]) - average_pz_sq = np.average(data[species_name+"_pz_end"]*data[species_name+"_pz_end"]) - assert(is_close(average_px_sq, average_py_sq, rtol = 5.e-2)) - assert(average_pz_sq > average_px_sq) - assert(average_pz_sq > average_py_sq) - -def cross_section( E_keV ): + average_px_sq = np.average( + data[species_name + "_px_end"] * data[species_name + "_px_end"] + ) + average_py_sq = np.average( + data[species_name + "_py_end"] * data[species_name + "_py_end"] + ) + average_pz_sq = np.average( + data[species_name + "_pz_end"] * data[species_name + "_pz_end"] + ) + assert is_close(average_px_sq, average_py_sq, rtol=5.0e-2) + assert average_pz_sq > average_px_sq + assert average_pz_sq > average_py_sq + + +def cross_section(E_keV): ## Returns cross section in b, using the analytical fits given ## in H.-S. Bosch and G.M. Hale 1992 Nucl. Fusion 32 611 - joule_to_keV = 1.e-3/scc.e - B_G = scc.pi * scc.alpha * np.sqrt( 2.*m_reduced * scc.c**2 * joule_to_keV ); - if reaction_type == 'DT': - A1 = 6.927e4; - A2 = 7.454e8; - A3 = 2.050e6; - A4 = 5.2002e4; - A5 = 0; - B1 = 6.38e1; - B2 = -9.95e-1; - B3 = 6.981e-5; - B4 = 1.728e-4; - elif reaction_type == 'DD': - A1 = 5.3701e4; - A2 = 3.3027e2; - A3 = -1.2706e-1; - A4 = 2.9327e-5; - A5 = -2.5151e-9; - B1 = 0; - B2 = 0; - B3 = 0; - B4 = 0; - - astrophysical_factor = (A1 + E_keV*(A2 + E_keV*(A3 + E_keV*(A4 + E_keV*A5)))) / (1 + E_keV*(B1 + E_keV*(B2 + E_keV*(B3 + E_keV*B4)))); - millibarn_to_barn = 1.e-3; - return millibarn_to_barn * astrophysical_factor/E_keV * np.exp(-B_G/np.sqrt(E_keV)) + joule_to_keV = 1.0e-3 / scc.e + B_G = scc.pi * scc.alpha * np.sqrt(2.0 * m_reduced * scc.c**2 * joule_to_keV) + if reaction_type == "DT": + A1 = 6.927e4 + A2 = 7.454e8 + A3 = 2.050e6 + A4 = 5.2002e4 + A5 = 0 + B1 = 6.38e1 + B2 = -9.95e-1 + B3 = 6.981e-5 + B4 = 1.728e-4 + elif reaction_type == "DD": + A1 = 5.3701e4 + A2 = 3.3027e2 + A3 = -1.2706e-1 + A4 = 2.9327e-5 + A5 = -2.5151e-9 + B1 = 0 + B2 = 0 + B3 = 0 + B4 = 0 + else: + raise RuntimeError(f"Reaction type '{reaction_type}' not implemented.") + + astrophysical_factor = ( + A1 + E_keV * (A2 + E_keV * (A3 + E_keV * (A4 + E_keV * A5))) + ) / (1 + E_keV * (B1 + E_keV * (B2 + E_keV * (B3 + E_keV * B4)))) + millibarn_to_barn = 1.0e-3 + return ( + millibarn_to_barn * astrophysical_factor / E_keV * np.exp(-B_G / np.sqrt(E_keV)) + ) + def E_com_to_p_sq_com(m1, m2, E): ## E is the total (kinetic+mass) energy of a two particle (with mass m1 and m2) system in ## its center of mass frame, in J. ## Returns the square norm of the momentum of each particle in that frame. - E_ratio = E/((m1+m2)*scc.c**2) - return m1*m2*scc.c**2 * (E_ratio**2 - 1) + (m1-m2)**2*scc.c**2/4 * (E_ratio - 1./E_ratio)**2 + E_ratio = E / ((m1 + m2) * scc.c**2) + return ( + m1 * m2 * scc.c**2 * (E_ratio**2 - 1) + + (m1 - m2) ** 2 * scc.c**2 / 4 * (E_ratio - 1.0 / E_ratio) ** 2 + ) + def compute_relative_v_com(E): ## E is the kinetic energy of reactants in the center of mass frame, in keV ## Returns the relative velocity between reactants in this frame, in m/s m0 = mass[reactant_species[0]] m1 = mass[reactant_species[1]] - E_J = E*keV_to_Joule + (m0 + m1)*scc.c**2 + E_J = E * keV_to_Joule + (m0 + m1) * scc.c**2 p_sq = E_com_to_p_sq_com(m0, m1, E_J) p = np.sqrt(p_sq) - gamma0 = np.sqrt(1. + p_sq / (m0*scc.c)**2) - gamma1 = np.sqrt(1. + p_sq / (m1*scc.c)**2) - v0 = p/(gamma0*m0) - v1 = p/(gamma1*m1) - return v0+v1 + gamma0 = np.sqrt(1.0 + p_sq / (m0 * scc.c) ** 2) + gamma1 = np.sqrt(1.0 + p_sq / (m1 * scc.c) ** 2) + v0 = p / (gamma0 * m0) + v1 = p / (gamma1 * m1) + return v0 + v1 + def expected_weight_com(E_com, reactant0_density, reactant1_density, dV, dt): ## Computes expected number of product particles as a function of energy E_com in the ## center of mass frame. E_com is in keV. - assert(np.all(E_com>=0)) + assert np.all(E_com >= 0) ## Case E_com == 0 is handled manually to avoid division by zero conditions = [E_com == 0, E_com > 0] ## Necessary to avoid division by 0 warning when pb_cross_section is evaluated - E_com_never_zero = np.clip(E_com, 1.e-15, None) - choices = [0., cross_section(E_com_never_zero)*compute_relative_v_com(E_com_never_zero)] + E_com_never_zero = np.clip(E_com, 1.0e-15, None) + choices = [ + 0.0, + cross_section(E_com_never_zero) * compute_relative_v_com(E_com_never_zero), + ] sigma_times_vrel = np.select(conditions, choices) - return reactant0_density*reactant1_density*sigma_times_vrel*barn_to_square_meter*dV*dt - -def check_macroparticle_number(data, fusion_probability_target_value, num_pair_per_cell): + return ( + reactant0_density + * reactant1_density + * sigma_times_vrel + * barn_to_square_meter + * dV + * dt + ) + + +def check_macroparticle_number( + data, fusion_probability_target_value, num_pair_per_cell +): ## Checks that the number of macroparticles is as expected for the first and second tests ## The first slice 0 < z < 1 does not contribute to alpha creation if is_RZ: - numcells = size_x*(size_z-1) + numcells = size_x * (size_z - 1) else: - numcells = size_x*size_y*(size_z-1) + numcells = size_x * size_y * (size_z - 1) ## In these tests, the fusion_multiplier is so high that the fusion probability per pair is ## equal to the parameter fusion_probability_target_value fusion_probability_per_pair = fusion_probability_target_value - expected_fusion_number = numcells*num_pair_per_cell*fusion_probability_per_pair - expected_macroparticle_number = 2*expected_fusion_number - std_macroparticle_number = 2*np.sqrt(expected_fusion_number) + expected_fusion_number = numcells * num_pair_per_cell * fusion_probability_per_pair + expected_macroparticle_number = 2 * expected_fusion_number + std_macroparticle_number = 2 * np.sqrt(expected_fusion_number) actual_macroparticle_number = data[product_species[0] + "_w_end"].shape[0] # 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions - assert(is_close(actual_macroparticle_number, expected_macroparticle_number, rtol = 0., - atol = 5.*std_macroparticle_number)) + assert is_close( + actual_macroparticle_number, + expected_macroparticle_number, + rtol=0.0, + atol=5.0 * std_macroparticle_number, + ) ## used in subsequent function return expected_fusion_number + def p_sq_reactant1_frame_to_E_COM_frame(p_reactant0_sq): # Takes the reactant0 square norm of the momentum in the reactant1 rest frame and returns the total # kinetic energy in the center of mass frame. Everything is in SI units. @@ -331,101 +413,143 @@ def p_sq_reactant1_frame_to_E_COM_frame(p_reactant0_sq): m1 = mass[reactant_species[1]] # Total (kinetic + mass) energy in lab frame - E_lab = np.sqrt(p_reactant0_sq*scc.c**2 + (m0*scc.c**2)**2) + m1*scc.c**2 + E_lab = np.sqrt(p_reactant0_sq * scc.c**2 + (m0 * scc.c**2) ** 2) + m1 * scc.c**2 # Use invariant E**2 - p**2c**2 of 4-momentum norm to compute energy in center of mass frame - E_com = np.sqrt(E_lab**2 - p_reactant0_sq*scc.c**2) + E_com = np.sqrt(E_lab**2 - p_reactant0_sq * scc.c**2) # Corresponding kinetic energy - E_com_kin = E_com - (m1+m0)*scc.c**2 - return E_com_kin*(p_reactant0_sq>0.) + E_com_kin = E_com - (m1 + m0) * scc.c**2 + return E_com_kin * (p_reactant0_sq > 0.0) + def p_sq_to_kinetic_energy(p_sq, m): ## Returns the kinetic energy of a particle as a function of its squared momentum. ## Everything is in SI units. - return np.sqrt(p_sq*scc.c**2 + (m*scc.c**2)**2) - (m*scc.c**2) + return np.sqrt(p_sq * scc.c**2 + (m * scc.c**2) ** 2) - (m * scc.c**2) + def compute_E_com1(data): ## Computes kinetic energy (in Joule) in the center of frame for the first test ## Square norm of the momentum of reactant as a function of cell number in z direction - p_sq = 2.*m_reduced*(Energy_step*np.arange(size_z)**2) + p_sq = 2.0 * m_reduced * (Energy_step * np.arange(size_z) ** 2) Ekin = 0 for species_name in reactant_species: - Ekin += p_sq_to_kinetic_energy( p_sq, mass[species_name] ) + Ekin += p_sq_to_kinetic_energy(p_sq, mass[species_name]) return Ekin + def compute_E_com2(data): ## Computes kinetic energy (in Joule) in the center of frame for the second test ## Square norm of the momentum of reactant0 as a function of cell number in z direction - p_reactant0_sq = 2.*mass[reactant_species[0]]*(Energy_step*np.arange(size_z)**2) + p_reactant0_sq = ( + 2.0 * mass[reactant_species[0]] * (Energy_step * np.arange(size_z) ** 2) + ) return p_sq_reactant1_frame_to_E_COM_frame(p_reactant0_sq) -def check_fusion_yield(data, expected_fusion_number, E_com, reactant0_density, reactant1_density, dt): + +def check_fusion_yield( + data, expected_fusion_number, E_com, reactant0_density, reactant1_density, dt +): ## Checks that the fusion yield is as expected for the first and second tests. - product_weight_theory = expected_weight_com(E_com/keV_to_Joule, - reactant0_density, reactant1_density, dV_slice, dt) + product_weight_theory = expected_weight_com( + E_com / keV_to_Joule, reactant0_density, reactant1_density, dV_slice, dt + ) for species_name in product_species: - product_weight_simulation = np.histogram(data[species_name+"_z_end"], - bins=size_z, range=(0, size_z), weights = data[species_name+"_w_end"])[0] + product_weight_simulation = np.histogram( + data[species_name + "_z_end"], + bins=size_z, + range=(0, size_z), + weights=data[species_name + "_w_end"], + )[0] ## -1 is here because the first slice 0 < z < 1 does not contribute to fusion - expected_fusion_number_per_slice = expected_fusion_number/(size_z-1) - relative_std_weight = 1./np.sqrt(expected_fusion_number_per_slice) + expected_fusion_number_per_slice = expected_fusion_number / (size_z - 1) + relative_std_weight = 1.0 / np.sqrt(expected_fusion_number_per_slice) # 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions - assert(np.all(is_close(product_weight_theory, product_weight_simulation, - rtol = 5.*relative_std_weight))) + assert np.all( + is_close( + product_weight_theory, + product_weight_simulation, + rtol=5.0 * relative_std_weight, + ) + ) + def specific_check1(data, dt): if not is_RZ: - check_isotropy(data, relative_tolerance = 3.e-2) - expected_fusion_number = check_macroparticle_number(data, - fusion_probability_target_value = 0.002, - num_pair_per_cell = nppcell_1) + check_isotropy(data, relative_tolerance=3.0e-2) + expected_fusion_number = check_macroparticle_number( + data, fusion_probability_target_value=0.002, num_pair_per_cell=nppcell_1 + ) E_com = compute_E_com1(data) - check_fusion_yield(data, expected_fusion_number, E_com, reactant0_density = 1., - reactant1_density = 1., dt=dt) + check_fusion_yield( + data, + expected_fusion_number, + E_com, + reactant0_density=1.0, + reactant1_density=1.0, + dt=dt, + ) + def specific_check2(data, dt): check_xy_isotropy(data) ## Only 900 particles pairs per cell here because we ignore the 10% of reactants that are at rest - expected_fusion_number = check_macroparticle_number(data, - fusion_probability_target_value = 0.02, - num_pair_per_cell = nppcell_2) + expected_fusion_number = check_macroparticle_number( + data, fusion_probability_target_value=0.02, num_pair_per_cell=nppcell_2 + ) E_com = compute_E_com2(data) - check_fusion_yield(data, expected_fusion_number, E_com, reactant0_density = 1.e20, - reactant1_density = 1.e26, dt=dt) + check_fusion_yield( + data, + expected_fusion_number, + E_com, + reactant0_density=1.0e20, + reactant1_density=1.0e26, + dt=dt, + ) + def check_charge_conservation(rho_start, rho_end): - assert(np.all(is_close(rho_start, rho_end, rtol=2.e-11))) + assert np.all(is_close(rho_start, rho_end, rtol=2.0e-11)) + def main(): filename_end = sys.argv[1] - filename_start = filename_end[:-4] + '0000' + filename_start = filename_end[:-4] + "0000" ds_end = yt.load(filename_end) ds_start = yt.load(filename_start) ad_end = ds_end.all_data() ad_start = ds_start.all_data() - dt = float(ds_end.current_time - ds_start.current_time) - field_data_end = ds_end.covering_grid(level=0, left_edge=ds_end.domain_left_edge, - dims=ds_end.domain_dimensions) - field_data_start = ds_start.covering_grid(level=0, left_edge=ds_start.domain_left_edge, - dims=ds_start.domain_dimensions) - - for i in range(1, ntests+1): + dt = float(ds_end.current_time - ds_start.current_time) # noqa + field_data_end = ds_end.covering_grid( + level=0, left_edge=ds_end.domain_left_edge, dims=ds_end.domain_dimensions + ) + field_data_start = ds_start.covering_grid( + level=0, left_edge=ds_start.domain_left_edge, dims=ds_start.domain_dimensions + ) + + for i in range(1, ntests + 1): data = {} for species_name in reactant_species: - add_species_to_dict(ad_start, data, species_name+'_'+str(i), species_name, "start") - add_species_to_dict(ad_end, data, species_name+'_'+str(i), species_name, "end") + add_species_to_dict( + ad_start, data, species_name + "_" + str(i), species_name, "start" + ) + add_species_to_dict( + ad_end, data, species_name + "_" + str(i), species_name, "end" + ) for species_name in product_species: - add_species_to_dict(ad_end, data, species_name+'_'+str(i), species_name, "end") + add_species_to_dict( + ad_end, data, species_name + "_" + str(i), species_name, "end" + ) # General checks that are performed for all tests generic_check(data) # Checks that are specific to test number i - eval("specific_check"+str(i)+"(data, dt)") + eval("specific_check" + str(i) + "(data, dt)") rho_start = field_data_start["rho"].to_ndarray() rho_end = field_data_end["rho"].to_ndarray() @@ -434,5 +558,6 @@ def main(): test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename_end) + if __name__ == "__main__": main() diff --git a/Examples/Tests/nuclear_fusion/inputs_proton_boron_2d b/Examples/Tests/nuclear_fusion/inputs_test_2d_proton_boron_fusion similarity index 100% rename from Examples/Tests/nuclear_fusion/inputs_proton_boron_2d rename to Examples/Tests/nuclear_fusion/inputs_test_2d_proton_boron_fusion diff --git a/Examples/Tests/nuclear_fusion/inputs_deuterium_deuterium_3d b/Examples/Tests/nuclear_fusion/inputs_test_3d_deuterium_deuterium_fusion similarity index 100% rename from Examples/Tests/nuclear_fusion/inputs_deuterium_deuterium_3d rename to Examples/Tests/nuclear_fusion/inputs_test_3d_deuterium_deuterium_fusion diff --git a/Examples/Tests/nuclear_fusion/inputs_deuterium_deuterium_3d_intraspecies b/Examples/Tests/nuclear_fusion/inputs_test_3d_deuterium_deuterium_fusion_intraspecies similarity index 100% rename from Examples/Tests/nuclear_fusion/inputs_deuterium_deuterium_3d_intraspecies rename to Examples/Tests/nuclear_fusion/inputs_test_3d_deuterium_deuterium_fusion_intraspecies diff --git a/Examples/Tests/nuclear_fusion/inputs_deuterium_tritium_3d b/Examples/Tests/nuclear_fusion/inputs_test_3d_deuterium_tritium_fusion similarity index 100% rename from Examples/Tests/nuclear_fusion/inputs_deuterium_tritium_3d rename to Examples/Tests/nuclear_fusion/inputs_test_3d_deuterium_tritium_fusion diff --git a/Examples/Tests/nuclear_fusion/inputs_proton_boron_3d b/Examples/Tests/nuclear_fusion/inputs_test_3d_proton_boron_fusion similarity index 100% rename from Examples/Tests/nuclear_fusion/inputs_proton_boron_3d rename to Examples/Tests/nuclear_fusion/inputs_test_3d_proton_boron_fusion diff --git a/Examples/Tests/nuclear_fusion/inputs_deuterium_tritium_rz b/Examples/Tests/nuclear_fusion/inputs_test_rz_deuterium_tritium_fusion similarity index 100% rename from Examples/Tests/nuclear_fusion/inputs_deuterium_tritium_rz rename to Examples/Tests/nuclear_fusion/inputs_test_rz_deuterium_tritium_fusion diff --git a/Examples/Tests/ohm_solver_EM_modes/analysis.py b/Examples/Tests/ohm_solver_EM_modes/analysis.py deleted file mode 100755 index ad832dc2f50..00000000000 --- a/Examples/Tests/ohm_solver_EM_modes/analysis.py +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env python3 -# -# --- Analysis script for the hybrid-PIC example producing EM modes. - -import dill -import matplotlib -import matplotlib.pyplot as plt -import numpy as np - -from pywarpx import picmi - -constants = picmi.constants - -matplotlib.rcParams.update({'font.size': 20}) - -# load simulation parameters -with open(f'sim_parameters.dpkl', 'rb') as f: - sim = dill.load(f) - -if sim.B_dir == 'z': - field_idx_dict = {'z': 4, 'Ez': 7, 'Bx': 8, 'By': 9} - data = np.loadtxt("diags/par_field_data.txt", skiprows=1) -else: - if sim.dim == 1: - field_idx_dict = {'z': 4, 'Ez': 7, 'Bx': 8, 'By': 9} - else: - field_idx_dict = {'z': 2, 'Ez': 3, 'Bx': 4, 'By': 5} - data = np.loadtxt("diags/perp_field_data.txt", skiprows=1) - -# step, t, z, Ez, Bx, By = raw_data.T -step = data[:,0] - -num_steps = len(np.unique(step)) - -# get the spatial resolution -resolution = len(np.where(step == 0)[0]) - 1 - -# reshape to separate spatial and time coordinates -sim_data = data.reshape((num_steps, resolution+1, data.shape[1])) - -z_grid = sim_data[1, :, field_idx_dict['z']] -idx = np.argsort(z_grid)[1:] -dz = np.mean(np.diff(z_grid[idx])) -dt = np.mean(np.diff(sim_data[:,0,1])) - -data = np.zeros((num_steps, resolution, 3)) -for i in range(num_steps): - data[i,:,0] = sim_data[i,idx,field_idx_dict['Bx']] - data[i,:,1] = sim_data[i,idx,field_idx_dict['By']] - data[i,:,2] = sim_data[i,idx,field_idx_dict['Ez']] - -print(f"Data file contains {num_steps} time snapshots.") -print(f"Spatial resolution is {resolution}") - -def get_analytic_R_mode(w): - return w / np.sqrt(1.0 + abs(w)) - -def get_analytic_L_mode(w): - return w / np.sqrt(1.0 - abs(w)) - -if sim.B_dir == 'z': - global_norm = ( - 1.0 / (2.0*constants.mu0) - / ((3.0/2)*sim.n_plasma*sim.T_plasma*constants.q_e) - ) -else: - global_norm = ( - constants.ep0 / 2.0 - / ((3.0/2)*sim.n_plasma*sim.T_plasma*constants.q_e) - ) - -if sim.B_dir == 'z': - Bl = (data[:, :, 0] + 1.0j * data[:, :, 1]) / np.sqrt(2.0) - field_kw = np.fft.fftshift(np.fft.fft2(Bl)) -else: - field_kw = np.fft.fftshift(np.fft.fft2(data[:, :, 2])) - -w_norm = sim.w_ci -if sim.B_dir == 'z': - k_norm = 1.0 / sim.l_i -else: - k_norm = 1.0 / sim.rho_i - -k = 2*np.pi * np.fft.fftshift(np.fft.fftfreq(resolution, dz)) / k_norm -w = 2*np.pi * np.fft.fftshift(np.fft.fftfreq(num_steps, dt)) / w_norm -w = -np.flipud(w) - -# aspect = (xmax-xmin)/(ymax-ymin) / aspect_true -extent = [k[0], k[-1], w[0], w[-1]] - -fig, ax1 = plt.subplots(1, 1, figsize=(10, 7.25)) - -if sim.B_dir == 'z' and sim.dim == 1: - vmin = -3 - vmax = 3.5 -else: - vmin = None - vmax = None - -im = ax1.imshow( - np.log10(np.abs(field_kw**2) * global_norm), extent=extent, - aspect="equal", cmap='inferno', vmin=vmin, vmax=vmax -) - -# Colorbars -fig.subplots_adjust(right=0.5) -cbar_ax = fig.add_axes([0.525, 0.15, 0.03, 0.7]) -fig.colorbar(im, cax=cbar_ax, orientation='vertical') - -#cbar_lab = r'$\log_{10}(\frac{|B_{R/L}|^2}{2\mu_0}\frac{2}{3n_0k_BT_e})$' -if sim.B_dir == 'z': - cbar_lab = r'$\log_{10}(\beta_{R/L})$' -else: - cbar_lab = r'$\log_{10}(\varepsilon_0|E_z|^2/(3n_0k_BT_e))$' -cbar_ax.set_ylabel(cbar_lab, rotation=270, labelpad=30) - -if sim.B_dir == 'z': - # plot the L mode - ax1.plot(get_analytic_L_mode(w), np.abs(w), c='limegreen', ls='--', lw=1.25, - label='L mode:\n'+r'$(kl_i)^2=\frac{(\omega/\Omega_i)^2}{1-\omega/\Omega_i}$') - # plot the R mode - ax1.plot(get_analytic_R_mode(w), -np.abs(w), c='limegreen', ls='-.', lw=1.25, - label='R mode:\n'+r'$(kl_i)^2=\frac{(\omega/\Omega_i)^2}{1+\omega/\Omega_i}$') - - ax1.plot(k,1.0+3.0*sim.v_ti/w_norm*k*k_norm, c='limegreen', ls=':', lw=1.25, label = r'$\omega = \Omega_i + 3v_{th,i} k$') - ax1.plot(k,1.0-3.0*sim.v_ti/w_norm*k*k_norm, c='limegreen', ls=':', lw=1.25) - -else: - # digitized values from Munoz et al. (2018) - x = [0.006781609195402272, 0.1321379310344828, 0.2671034482758621, 0.3743678160919539, 0.49689655172413794, 0.6143908045977011, 0.766022988505747, 0.885448275862069, 1.0321149425287355, 1.193862068965517, 1.4417701149425288, 1.7736781609195402] - y = [-0.033194664836814436, 0.5306857657503109, 1.100227301968521, 1.5713856842646996, 2.135780760818287, 2.675601492473303, 3.3477291246729854, 3.8469357121413563, 4.4317021915340735, 5.1079898786293265, 6.10275764463696, 7.310074194793499] - ax1.plot(x, y, c='limegreen', ls='-.', lw=1.5, label="X mode") - - x = [3.9732873563218387, 3.6515862068965514, 3.306275862068966, 2.895655172413793, 2.4318850574712645, 2.0747586206896553, 1.8520229885057473, 1.6589195402298849, 1.4594942528735633, 1.2911724137931033, 1.1551264367816092, 1.0335402298850576, 0.8961149425287356, 0.7419770114942528, 0.6141379310344828, 0.4913103448275862] - y = [1.1145945018655916, 1.1193978642192393, 1.1391259596002916, 1.162971222713042, 1.1986533430544237, 1.230389844319595, 1.2649997855641806, 1.3265857528841618, 1.3706737573444268, 1.4368486511986962, 1.4933310460179268, 1.5485268259210019, 1.6386327572157655, 1.7062658146416778, 1.7828194021529358, 1.8533687867221342] - ax1.plot(x, y, c='limegreen', ls=':', lw=2, label="Bernstein modes") - - x = [3.9669885057471266, 3.6533333333333333, 3.3213563218390805, 2.9646896551724136, 2.6106436781609195, 2.2797011494252875, 1.910919540229885, 1.6811724137931034, 1.4499540229885057, 1.2577011494252872, 1.081057471264368, 0.8791494252873564, 0.7153103448275862] - y = [2.2274306300124374, 2.2428271218424327, 2.272505039241755, 2.3084873697302397, 2.3586224642964364, 2.402667581592829, 2.513873997512545, 2.5859673199811297, 2.6586610627439207, 2.7352146502551786, 2.8161427284813656, 2.887850066475104, 2.9455761890466183] - ax1.plot(x, y, c='limegreen', ls=':', lw=2) - - x = [3.9764137931034487, 3.702022988505747, 3.459793103448276, 3.166712643678161, 2.8715862068965516, 2.5285057471264367, 2.2068505747126435, 1.9037011494252871, 1.6009885057471265, 1.3447816091954023, 1.1538850574712645, 0.9490114942528736] - y = [3.3231976669382854, 3.34875841660591, 3.378865205643951, 3.424454260839731, 3.474160483767209, 3.522194107303684, 3.6205343740618434, 3.7040356821203417, 3.785435519149119, 3.868851052879873, 3.9169704507440923, 3.952481022429987] - ax1.plot(x, y, c='limegreen', ls=':', lw=2) - - x = [3.953609195402299, 3.7670114942528734, 3.5917471264367817, 3.39735632183908, 3.1724137931034484, 2.9408045977011494, 2.685977011494253, 2.4593563218390804, 2.2203218390804595, 2.0158850574712646, 1.834183908045977, 1.6522758620689655, 1.4937471264367814, 1.3427586206896551, 1.2075402298850575] - y = [4.427971008277223, 4.458335120298495, 4.481579963117039, 4.495861388686366, 4.544581206844791, 4.587425483552773, 4.638160998413175, 4.698631899472488, 4.757987734271133, 4.813955483123902, 4.862332203971352, 4.892481880173264, 4.9247759145687695, 4.947934983059571, 4.953124329888064] - ax1.plot(x, y, c='limegreen', ls=':', lw=2) - -# ax1.legend(loc='upper left') -fig.legend(loc=7, fontsize=18) - -if sim.B_dir == 'z': - ax1.set_xlabel(r'$k l_i$') - ax1.set_title('$B_{R/L} = B_x \pm iB_y$') - fig.suptitle("Parallel EM modes") - ax1.set_xlim(-3, 3) - ax1.set_ylim(-6, 3) - dir_str = 'par' -else: - ax1.set_xlabel(r'$k \rho_i$') - ax1.set_title('$E_z(k, \omega)$') - fig.suptitle(f"Perpendicular EM modes (ion Bernstein) - {sim.dim}D") - ax1.set_xlim(-3, 3) - ax1.set_ylim(0, 8) - dir_str = 'perp' - -ax1.set_ylabel(r'$\omega / \Omega_i$') - -plt.savefig( - f"spectrum_{dir_str}_{sim.dim}d_{sim.substeps}_substeps_{sim.eta}_eta.png", - bbox_inches='tight' -) -if not sim.test: - plt.show() - -if sim.test: - import os - import sys - sys.path.insert(1, '../../../../warpx/Regression/Checksum/') - import checksumAPI - - # this will be the name of the plot file - fn = sys.argv[1] - test_name = os.path.split(os.getcwd())[1] - checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/ohm_solver_em_modes/CMakeLists.txt b/Examples/Tests/ohm_solver_em_modes/CMakeLists.txt new file mode 100644 index 00000000000..a08c321d88d --- /dev/null +++ b/Examples/Tests/ohm_solver_em_modes/CMakeLists.txt @@ -0,0 +1,23 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_ohm_solver_em_modes_picmi # name + 1 # dims + 2 # nprocs + "inputs_test_1d_ohm_solver_em_modes_picmi.py --test --dim 1 --bdir z" # inputs + analysis.py # analysis + diags/field_diag000250 # output + OFF # dependency +) + +add_warpx_test( + test_rz_ohm_solver_em_modes_picmi # name + RZ # dims + 2 # nprocs + "inputs_test_rz_ohm_solver_em_modes_picmi.py --test" # inputs + analysis_rz.py # analysis + diags/diag1000100 # output + OFF # dependency +) +label_warpx_test(test_rz_ohm_solver_em_modes_picmi slow) diff --git a/Examples/Tests/ohm_solver_EM_modes/README.rst b/Examples/Tests/ohm_solver_em_modes/README.rst similarity index 85% rename from Examples/Tests/ohm_solver_EM_modes/README.rst rename to Examples/Tests/ohm_solver_em_modes/README.rst index 034ee5815f0..24d95d2bcb8 100644 --- a/Examples/Tests/ohm_solver_EM_modes/README.rst +++ b/Examples/Tests/ohm_solver_em_modes/README.rst @@ -13,11 +13,11 @@ Run The same input script can be used for 1d, 2d or 3d Cartesian simulations as well as replicating either the parallel propagating or ion-Bernstein modes as indicated below. -.. dropdown:: Script ``PICMI_inputs.py`` +.. dropdown:: Script ``inputs_test_1d_ohm_solver_em_modes_picmi.py`` - .. literalinclude:: PICMI_inputs.py + .. literalinclude:: inputs_test_1d_ohm_solver_em_modes_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/ohm_solver_EM_modes/PICMI_inputs.py``. + :caption: You can copy this file from ``Examples/Tests/ohm_solver_EM_modes/inputs_test_1d_ohm_solver_em_modes_picmi.py``. For `MPI-parallel `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. @@ -29,7 +29,7 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. code-block:: bash - python3 PICMI_inputs.py -dim {1/2/3} --bdir z + python3 inputs_test_1d_ohm_solver_em_modes_picmi.py -dim {1/2/3} --bdir z .. tab-item:: Perpendicular propagating waves @@ -37,7 +37,7 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. code-block:: bash - python3 PICMI_inputs.py -dim {1/2/3} --bdir {x/y} + python3 inputs_test_1d_ohm_solver_em_modes_picmi.py -dim {1/2/3} --bdir {x/y} Analyze ------- @@ -82,17 +82,17 @@ Run The following script initializes a thermal plasma in a metallic cylinder with periodic boundaries at the cylinder ends. -.. dropdown:: Script ``PICMI_inputs_rz.py`` +.. dropdown:: Script ``inputs_test_rz_ohm_solver_em_modes_picmi.py`` - .. literalinclude:: PICMI_inputs_rz.py + .. literalinclude:: inputs_test_rz_ohm_solver_em_modes_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/ohm_solver_EM_modes/PICMI_inputs_rz.py``. + :caption: You can copy this file from ``Examples/Tests/ohm_solver_EM_modes/inputs_test_rz_ohm_solver_em_modes_picmi.py``. The example can be executed using: .. code-block:: bash - python3 PICMI_inputs_rz.py + python3 inputs_test_rz_ohm_solver_em_modes_picmi.py Analyze ------- diff --git a/Examples/Tests/ohm_solver_em_modes/analysis.py b/Examples/Tests/ohm_solver_em_modes/analysis.py new file mode 100755 index 00000000000..36869623ac4 --- /dev/null +++ b/Examples/Tests/ohm_solver_em_modes/analysis.py @@ -0,0 +1,361 @@ +#!/usr/bin/env python3 +# +# --- Analysis script for the hybrid-PIC example producing EM modes. + +import dill +import matplotlib +import matplotlib.pyplot as plt +import numpy as np + +from pywarpx import picmi + +constants = picmi.constants + +matplotlib.rcParams.update({"font.size": 20}) + +# load simulation parameters +with open("sim_parameters.dpkl", "rb") as f: + sim = dill.load(f) + +if sim.B_dir == "z": + field_idx_dict = {"z": 4, "Ez": 7, "Bx": 8, "By": 9} + data = np.loadtxt("diags/par_field_data.txt", skiprows=1) +else: + if sim.dim == 1: + field_idx_dict = {"z": 4, "Ez": 7, "Bx": 8, "By": 9} + else: + field_idx_dict = {"z": 2, "Ez": 3, "Bx": 4, "By": 5} + data = np.loadtxt("diags/perp_field_data.txt", skiprows=1) + +# step, t, z, Ez, Bx, By = raw_data.T +step = data[:, 0] + +num_steps = len(np.unique(step)) + +# get the spatial resolution +resolution = len(np.where(step == 0)[0]) - 1 + +# reshape to separate spatial and time coordinates +sim_data = data.reshape((num_steps, resolution + 1, data.shape[1])) + +z_grid = sim_data[1, :, field_idx_dict["z"]] +idx = np.argsort(z_grid)[1:] +dz = np.mean(np.diff(z_grid[idx])) +dt = np.mean(np.diff(sim_data[:, 0, 1])) + +data = np.zeros((num_steps, resolution, 3)) +for i in range(num_steps): + data[i, :, 0] = sim_data[i, idx, field_idx_dict["Bx"]] + data[i, :, 1] = sim_data[i, idx, field_idx_dict["By"]] + data[i, :, 2] = sim_data[i, idx, field_idx_dict["Ez"]] + +print(f"Data file contains {num_steps} time snapshots.") +print(f"Spatial resolution is {resolution}") + + +def get_analytic_R_mode(w): + return w / np.sqrt(1.0 + abs(w)) + + +def get_analytic_L_mode(w): + return w / np.sqrt(1.0 - abs(w)) + + +if sim.B_dir == "z": + global_norm = ( + 1.0 + / (2.0 * constants.mu0) + / ((3.0 / 2) * sim.n_plasma * sim.T_plasma * constants.q_e) + ) +else: + global_norm = ( + constants.ep0 / 2.0 / ((3.0 / 2) * sim.n_plasma * sim.T_plasma * constants.q_e) + ) + +if sim.B_dir == "z": + Bl = (data[:, :, 0] + 1.0j * data[:, :, 1]) / np.sqrt(2.0) + field_kw = np.fft.fftshift(np.fft.fft2(Bl)) +else: + field_kw = np.fft.fftshift(np.fft.fft2(data[:, :, 2])) + +w_norm = sim.w_ci +if sim.B_dir == "z": + k_norm = 1.0 / sim.l_i +else: + k_norm = 1.0 / sim.rho_i + +k = 2 * np.pi * np.fft.fftshift(np.fft.fftfreq(resolution, dz)) / k_norm +w = 2 * np.pi * np.fft.fftshift(np.fft.fftfreq(num_steps, dt)) / w_norm +w = -np.flipud(w) + +# aspect = (xmax-xmin)/(ymax-ymin) / aspect_true +extent = [k[0], k[-1], w[0], w[-1]] + +fig, ax1 = plt.subplots(1, 1, figsize=(10, 7.25)) + +if sim.B_dir == "z" and sim.dim == 1: + vmin = -3 + vmax = 3.5 +else: + vmin = None + vmax = None + +im = ax1.imshow( + np.log10(np.abs(field_kw**2) * global_norm), + extent=extent, + aspect="equal", + cmap="inferno", + vmin=vmin, + vmax=vmax, +) + +# Colorbars +fig.subplots_adjust(right=0.5) +cbar_ax = fig.add_axes([0.525, 0.15, 0.03, 0.7]) +fig.colorbar(im, cax=cbar_ax, orientation="vertical") + +# cbar_lab = r'$\log_{10}(\frac{|B_{R/L}|^2}{2\mu_0}\frac{2}{3n_0k_BT_e})$' +if sim.B_dir == "z": + cbar_lab = r"$\log_{10}(\beta_{R/L})$" +else: + cbar_lab = r"$\log_{10}(\varepsilon_0|E_z|^2/(3n_0k_BT_e))$" +cbar_ax.set_ylabel(cbar_lab, rotation=270, labelpad=30) + +if sim.B_dir == "z": + # plot the L mode + ax1.plot( + get_analytic_L_mode(w), + np.abs(w), + c="limegreen", + ls="--", + lw=1.25, + label="L mode:\n" + r"$(kl_i)^2=\frac{(\omega/\Omega_i)^2}{1-\omega/\Omega_i}$", + ) + # plot the R mode + ax1.plot( + get_analytic_R_mode(w), + -np.abs(w), + c="limegreen", + ls="-.", + lw=1.25, + label="R mode:\n" + r"$(kl_i)^2=\frac{(\omega/\Omega_i)^2}{1+\omega/\Omega_i}$", + ) + + ax1.plot( + k, + 1.0 + 3.0 * sim.v_ti / w_norm * k * k_norm, + c="limegreen", + ls=":", + lw=1.25, + label=r"$\omega = \Omega_i + 3v_{th,i} k$", + ) + ax1.plot( + k, 1.0 - 3.0 * sim.v_ti / w_norm * k * k_norm, c="limegreen", ls=":", lw=1.25 + ) + +else: + # digitized values from Munoz et al. (2018) + x = [ + 0.006781609195402272, + 0.1321379310344828, + 0.2671034482758621, + 0.3743678160919539, + 0.49689655172413794, + 0.6143908045977011, + 0.766022988505747, + 0.885448275862069, + 1.0321149425287355, + 1.193862068965517, + 1.4417701149425288, + 1.7736781609195402, + ] + y = [ + -0.033194664836814436, + 0.5306857657503109, + 1.100227301968521, + 1.5713856842646996, + 2.135780760818287, + 2.675601492473303, + 3.3477291246729854, + 3.8469357121413563, + 4.4317021915340735, + 5.1079898786293265, + 6.10275764463696, + 7.310074194793499, + ] + ax1.plot(x, y, c="limegreen", ls="-.", lw=1.5, label="X mode") + + x = [ + 3.9732873563218387, + 3.6515862068965514, + 3.306275862068966, + 2.895655172413793, + 2.4318850574712645, + 2.0747586206896553, + 1.8520229885057473, + 1.6589195402298849, + 1.4594942528735633, + 1.2911724137931033, + 1.1551264367816092, + 1.0335402298850576, + 0.8961149425287356, + 0.7419770114942528, + 0.6141379310344828, + 0.4913103448275862, + ] + y = [ + 1.1145945018655916, + 1.1193978642192393, + 1.1391259596002916, + 1.162971222713042, + 1.1986533430544237, + 1.230389844319595, + 1.2649997855641806, + 1.3265857528841618, + 1.3706737573444268, + 1.4368486511986962, + 1.4933310460179268, + 1.5485268259210019, + 1.6386327572157655, + 1.7062658146416778, + 1.7828194021529358, + 1.8533687867221342, + ] + ax1.plot(x, y, c="limegreen", ls=":", lw=2, label="Bernstein modes") + + x = [ + 3.9669885057471266, + 3.6533333333333333, + 3.3213563218390805, + 2.9646896551724136, + 2.6106436781609195, + 2.2797011494252875, + 1.910919540229885, + 1.6811724137931034, + 1.4499540229885057, + 1.2577011494252872, + 1.081057471264368, + 0.8791494252873564, + 0.7153103448275862, + ] + y = [ + 2.2274306300124374, + 2.2428271218424327, + 2.272505039241755, + 2.3084873697302397, + 2.3586224642964364, + 2.402667581592829, + 2.513873997512545, + 2.5859673199811297, + 2.6586610627439207, + 2.7352146502551786, + 2.8161427284813656, + 2.887850066475104, + 2.9455761890466183, + ] + ax1.plot(x, y, c="limegreen", ls=":", lw=2) + + x = [ + 3.9764137931034487, + 3.702022988505747, + 3.459793103448276, + 3.166712643678161, + 2.8715862068965516, + 2.5285057471264367, + 2.2068505747126435, + 1.9037011494252871, + 1.6009885057471265, + 1.3447816091954023, + 1.1538850574712645, + 0.9490114942528736, + ] + y = [ + 3.3231976669382854, + 3.34875841660591, + 3.378865205643951, + 3.424454260839731, + 3.474160483767209, + 3.522194107303684, + 3.6205343740618434, + 3.7040356821203417, + 3.785435519149119, + 3.868851052879873, + 3.9169704507440923, + 3.952481022429987, + ] + ax1.plot(x, y, c="limegreen", ls=":", lw=2) + + x = [ + 3.953609195402299, + 3.7670114942528734, + 3.5917471264367817, + 3.39735632183908, + 3.1724137931034484, + 2.9408045977011494, + 2.685977011494253, + 2.4593563218390804, + 2.2203218390804595, + 2.0158850574712646, + 1.834183908045977, + 1.6522758620689655, + 1.4937471264367814, + 1.3427586206896551, + 1.2075402298850575, + ] + y = [ + 4.427971008277223, + 4.458335120298495, + 4.481579963117039, + 4.495861388686366, + 4.544581206844791, + 4.587425483552773, + 4.638160998413175, + 4.698631899472488, + 4.757987734271133, + 4.813955483123902, + 4.862332203971352, + 4.892481880173264, + 4.9247759145687695, + 4.947934983059571, + 4.953124329888064, + ] + ax1.plot(x, y, c="limegreen", ls=":", lw=2) + +# ax1.legend(loc='upper left') +fig.legend(loc=7, fontsize=18) + +if sim.B_dir == "z": + ax1.set_xlabel(r"$k l_i$") + ax1.set_title("$B_{R/L} = B_x \pm iB_y$") + fig.suptitle("Parallel EM modes") + ax1.set_xlim(-3, 3) + ax1.set_ylim(-6, 3) + dir_str = "par" +else: + ax1.set_xlabel(r"$k \rho_i$") + ax1.set_title("$E_z(k, \omega)$") + fig.suptitle(f"Perpendicular EM modes (ion Bernstein) - {sim.dim}D") + ax1.set_xlim(-3, 3) + ax1.set_ylim(0, 8) + dir_str = "perp" + +ax1.set_ylabel(r"$\omega / \Omega_i$") + +plt.savefig( + f"spectrum_{dir_str}_{sim.dim}d_{sim.substeps}_substeps_{sim.eta}_eta.png", + bbox_inches="tight", +) +if not sim.test: + plt.show() + +if sim.test: + import os + import sys + + sys.path.insert(1, "../../../../warpx/Regression/Checksum/") + import checksumAPI + + # this will be the name of the plot file + fn = sys.argv[1] + test_name = os.path.split(os.getcwd())[1] + checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/ohm_solver_EM_modes/analysis_rz.py b/Examples/Tests/ohm_solver_em_modes/analysis_rz.py similarity index 58% rename from Examples/Tests/ohm_solver_EM_modes/analysis_rz.py rename to Examples/Tests/ohm_solver_em_modes/analysis_rz.py index 58e615c5332..4d5bc2aa016 100755 --- a/Examples/Tests/ohm_solver_EM_modes/analysis_rz.py +++ b/Examples/Tests/ohm_solver_em_modes/analysis_rz.py @@ -16,41 +16,43 @@ constants = picmi.constants # load simulation parameters -with open(f'sim_parameters.dpkl', 'rb') as f: +with open("sim_parameters.dpkl", "rb") as f: sim = dill.load(f) diag_dir = "diags/field_diags" ts = OpenPMDTimeSeries(diag_dir, check_all_files=True) + def transform_spatially(data_for_transform): # interpolate from regular r-grid to special r-grid interp = RegularGridInterpolator( - (info.z, info.r), data_for_transform, - method='linear' + (info.z, info.r), data_for_transform, method="linear" ) data_interp = interp((zg, rg)) # Applying manual hankel in r # Fmz = np.sum(proj*data_for_transform, axis=(2,3)) - Fmz = np.einsum('ijkl,kl->ij', proj, data_interp) + Fmz = np.einsum("ijkl,kl->ij", proj, data_interp) # Standard fourier in z Fmn = fft.fftshift(fft.fft(Fmz, axis=1), axes=1) return Fmn + def process(it): print(f"Processing iteration {it}", flush=True) - field, info = ts.get_field('E', 'y', iteration=it) + field, info = ts.get_field("E", "y", iteration=it) F_k = transform_spatially(field) return F_k + # grab the first iteration to get the grids -Bz, info = ts.get_field('B', 'z', iteration=0) +Bz, info = ts.get_field("B", "z", iteration=0) nr = len(info.r) nz = len(info.z) -nkr = 12 # number of radial modes to solve for +nkr = 12 # number of radial modes to solve for r_max = np.max(info.r) @@ -64,16 +66,19 @@ def process(it): r_modes = np.arange(nkr) A = ( - 4.0 * np.pi * r_max**2 / j_1M**2 - * j1(np.outer(jn_zeros(1, max(r_modes)+1)[r_modes], jn_zeros(1, nr)) / j_1M) - / jn(2 ,jn_zeros(1, nr))**2 + 4.0 + * np.pi + * r_max**2 + / j_1M**2 + * j1(np.outer(jn_zeros(1, max(r_modes) + 1)[r_modes], jn_zeros(1, nr)) / j_1M) + / jn(2, jn_zeros(1, nr)) ** 2 ) # No transformation for z B = np.identity(nz) # combine projection arrays -proj = np.einsum('ab,cd->acbd', A, B) +proj = np.einsum("ab,cd->acbd", A, B) results = np.zeros((len(ts.t), nkr, nz), dtype=complex) for ii, it in enumerate(ts.iterations): @@ -83,15 +88,12 @@ def process(it): F_kw = fft.fftshift(fft.fft(results, axis=0), axes=0) dz = info.z[1] - info.z[0] -kz = 2*np.pi*fft.fftshift(fft.fftfreq(F_kw[0].shape[1], dz)) +kz = 2 * np.pi * fft.fftshift(fft.fftfreq(F_kw[0].shape[1], dz)) dt = ts.iterations[1] - ts.iterations[0] -omega = 2*np.pi*fft.fftshift(fft.fftfreq(F_kw.shape[0], sim.dt*dt)) +omega = 2 * np.pi * fft.fftshift(fft.fftfreq(F_kw.shape[0], sim.dt * dt)) # Save data for future plotting purposes -np.savez( - "diags/spectrograms.npz", - F_kw=F_kw, dz=dz, kz=kz, dt=dt, omega=omega -) +np.savez("diags/spectrograms.npz", F_kw=F_kw, dz=dz, kz=kz, dt=dt, omega=omega) # plot the resulting dispersions k = np.linspace(0, 250, 500) @@ -108,59 +110,83 @@ def process(it): ax.set_title(f"m = {m}", fontsize=11) m -= 1 pm1 = ax.pcolormesh( - kz*sim.l_i, omega/sim.w_ci, - abs(F_kw[:, m, :])/np.max(abs(F_kw[:, m, :])), + kz * sim.l_i, + omega / sim.w_ci, + abs(F_kw[:, m, :]) / np.max(abs(F_kw[:, m, :])), norm=colors.LogNorm(vmin=vmin[ii], vmax=vmax), - cmap='inferno' + cmap="inferno", ) cb = fig.colorbar(pm1, ax=ax) - cb.set_label(r'Normalized $E_\theta(k_z, m, \omega)$') + cb.set_label(r"Normalized $E_\theta(k_z, m, \omega)$") # Get dispersion relation - see for example # T. Stix, Waves in Plasmas (American Inst. of Physics, 1992), Chap 6, Sec 2 - nu_m = jn_zeros(1, m+1)[-1] / sim.Lr + nu_m = jn_zeros(1, m + 1)[-1] / sim.Lr R2 = 0.5 * (nu_m**2 * (1.0 + kappa**2) + k**2 * (kappa**2 + 2.0)) P4 = k**2 * (nu_m**2 + k**2) omega_fast = sim.vA * np.sqrt(R2 + np.sqrt(R2**2 - P4)) omega_slow = sim.vA * np.sqrt(R2 - np.sqrt(R2**2 - P4)) # Upper right corner - ax.plot(k*sim.l_i, omega_fast/sim.w_ci, 'w--', label = f"$\omega_{{fast}}$") - ax.plot(k*sim.l_i, omega_slow/sim.w_ci, color='white', linestyle='--', label = f"$\omega_{{slow}}$") + ax.plot(k * sim.l_i, omega_fast / sim.w_ci, "w--", label="$\omega_{fast}$") + ax.plot( + k * sim.l_i, + omega_slow / sim.w_ci, + color="white", + linestyle="--", + label="$\omega_{slow}$", + ) # Thermal resonance - thermal_res = sim.w_ci + 3*sim.v_ti*k - ax.plot(k*sim.l_i, thermal_res/sim.w_ci, color='magenta', linestyle='--', label = "$\omega = \Omega_i + 3v_{th,i}k$") - ax.plot(-k*sim.l_i, thermal_res/sim.w_ci, color='magenta', linestyle='--', label = "") - thermal_res = sim.w_ci - 3*sim.v_ti*k - ax.plot(k*sim.l_i, thermal_res/sim.w_ci, color='magenta', linestyle='--', label = "$\omega = \Omega_i + 3v_{th,i}k$") - ax.plot(-k*sim.l_i, thermal_res/sim.w_ci, color='magenta', linestyle='--', label = "") + thermal_res = sim.w_ci + 3 * sim.v_ti * k + ax.plot( + k * sim.l_i, + thermal_res / sim.w_ci, + color="magenta", + linestyle="--", + label="$\omega = \Omega_i + 3v_{th,i}k$", + ) + ax.plot( + -k * sim.l_i, thermal_res / sim.w_ci, color="magenta", linestyle="--", label="" + ) + thermal_res = sim.w_ci - 3 * sim.v_ti * k + ax.plot( + k * sim.l_i, + thermal_res / sim.w_ci, + color="magenta", + linestyle="--", + label="$\omega = \Omega_i + 3v_{th,i}k$", + ) + ax.plot( + -k * sim.l_i, thermal_res / sim.w_ci, color="magenta", linestyle="--", label="" + ) for ax in axes.flatten(): ax.set_xlim(-1.75, 1.75) ax.set_ylim(0, 1.6) -axes[0, 0].set_ylabel('$\omega/\Omega_{ci}$') -axes[1, 0].set_ylabel('$\omega/\Omega_{ci}$') -axes[1, 0].set_xlabel('$k_zl_i$') -axes[1, 1].set_xlabel('$k_zl_i$') +axes[0, 0].set_ylabel("$\omega/\Omega_{ci}$") +axes[1, 0].set_ylabel("$\omega/\Omega_{ci}$") +axes[1, 0].set_xlabel("$k_zl_i$") +axes[1, 1].set_xlabel("$k_zl_i$") -plt.savefig('normal_modes_disp.png', dpi=600) +plt.savefig("normal_modes_disp.png", dpi=600) if not sim.test: plt.show() else: plt.close() # check if power spectrum sampling match earlier results - amps = np.abs(F_kw[2, 1, len(kz)//2-2:len(kz)//2+2]) + amps = np.abs(F_kw[2, 1, len(kz) // 2 - 2 : len(kz) // 2 + 2]) print("Amplitude sample: ", amps) assert np.allclose( - amps, np.array([ 61.02377286, 19.80026021, 100.47687017, 10.83331295]) + amps, np.array([61.02377286, 19.80026021, 100.47687017, 10.83331295]) ) if sim.test: import os import sys - sys.path.insert(1, '../../../../warpx/Regression/Checksum/') + + sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file diff --git a/Examples/Tests/ohm_solver_EM_modes/PICMI_inputs.py b/Examples/Tests/ohm_solver_em_modes/inputs_test_1d_ohm_solver_em_modes_picmi.py similarity index 75% rename from Examples/Tests/ohm_solver_EM_modes/PICMI_inputs.py rename to Examples/Tests/ohm_solver_em_modes/inputs_test_1d_ohm_solver_em_modes_picmi.py index ec67282fd88..ac0c2369c0e 100644 --- a/Examples/Tests/ohm_solver_EM_modes/PICMI_inputs.py +++ b/Examples/Tests/ohm_solver_em_modes/inputs_test_1d_ohm_solver_em_modes_picmi.py @@ -21,39 +21,37 @@ comm = mpi.COMM_WORLD -simulation = picmi.Simulation( - warpx_serialize_initial_conditions=True, - verbose=0 -) +simulation = picmi.Simulation(warpx_serialize_initial_conditions=True, verbose=0) class EMModes(object): - '''The following runs a simulation of an uniform plasma at a set + """The following runs a simulation of an uniform plasma at a set temperature (Te = Ti) with an external magnetic field applied in either the z-direction (parallel to domain) or x-direction (perpendicular to domain). The analysis script (in this same directory) analyzes the output field data for EM modes. This input is based on the EM modes tests as described by Munoz et al. (2018) and tests done by Scott Nicks at TAE Technologies. - ''' + """ + # Applied field parameters - B0 = 0.25 # Initial magnetic field strength (T) - beta = [0.01, 0.1] # Plasma beta, used to calculate temperature + B0 = 0.25 # Initial magnetic field strength (T) + beta = [0.01, 0.1] # Plasma beta, used to calculate temperature # Plasma species parameters - m_ion = [100.0, 400.0] # Ion mass (electron masses) - vA_over_c = [1e-4, 1e-3] # ratio of Alfven speed and the speed of light + m_ion = [100.0, 400.0] # Ion mass (electron masses) + vA_over_c = [1e-4, 1e-3] # ratio of Alfven speed and the speed of light # Spatial domain - Nz = [1024, 1920] # number of cells in z direction - Nx = 8 # number of cells in x (and y) direction for >1 dimensions + Nz = [1024, 1920] # number of cells in z direction + Nx = 8 # number of cells in x (and y) direction for >1 dimensions # Temporal domain (if not run as a CI test) - LT = 300.0 # Simulation temporal length (ion cyclotron periods) + LT = 300.0 # Simulation temporal length (ion cyclotron periods) # Numerical parameters - NPPC = [1024, 256, 64] # Seed number of particles per cell - DZ = 1.0 / 10.0 # Cell size (ion skin depths) - DT = [5e-3, 4e-3] # Time step (ion cyclotron periods) + NPPC = [1024, 256, 64] # Seed number of particles per cell + DZ = 1.0 / 10.0 # Cell size (ion skin depths) + DT = [5e-3, 4e-3] # Time step (ion cyclotron periods) # Plasma resistivity - used to dampen the mode excitation eta = [[1e-7, 1e-7], [1e-7, 1e-5], [1e-7, 1e-4]] @@ -68,7 +66,7 @@ def __init__(self, test, dim, B_dir, verbose): self.verbose = verbose or self.test # sanity check - assert (dim > 0 and dim < 4), f"{dim}-dimensions not a valid input" + assert dim > 0 and dim < 4, f"{dim}-dimensions not a valid input" # get simulation parameters from the defaults given the direction of # the initial B-field and the dimensionality @@ -89,11 +87,11 @@ def __init__(self, test, dim, B_dir, verbose): # if this is a test case run for only a small number of steps self.total_steps = 250 # output diagnostics 20 times per cyclotron period - self.diag_steps = int(1.0/20 / self.DT) + self.diag_steps = int(1.0 / 20 / self.DT) # dump all the current attributes to a dill pickle file if comm.rank == 0: - with open(f'sim_parameters.dpkl', 'wb') as f: + with open("sim_parameters.dpkl", "wb") as f: dill.dump(self, f) # print out plasma parameters @@ -125,12 +123,12 @@ def __init__(self, test, dim, B_dir, verbose): def get_simulation_parameters(self): """Pick appropriate parameters from the defaults given the direction of the B-field and the simulation dimensionality.""" - if self.B_dir == 'z': + if self.B_dir == "z": idx = 0 self.Bx = 0.0 self.By = 0.0 self.Bz = self.B0 - elif self.B_dir == 'y': + elif self.B_dir == "y": idx = 1 self.Bx = 0.0 self.By = self.B0 @@ -147,8 +145,8 @@ def get_simulation_parameters(self): self.Nz = self.Nz[idx] self.DT = self.DT[idx] - self.NPPC = self.NPPC[self.dim-1] - self.eta = self.eta[self.dim-1][idx] + self.NPPC = self.NPPC[self.dim - 1] + self.eta = self.eta[self.dim - 1][idx] def get_plasma_quantities(self): """Calculate various plasma parameters based on the simulation input.""" @@ -161,14 +159,12 @@ def get_plasma_quantities(self): # Alfven speed (m/s): vA = B / sqrt(mu0 * n * (M + m)) = c * omega_ci / w_pi self.vA = self.vA_over_c * constants.c - self.n_plasma = ( - (self.B0 / self.vA)**2 / (constants.mu0 * (self.M + constants.m_e)) + self.n_plasma = (self.B0 / self.vA) ** 2 / ( + constants.mu0 * (self.M + constants.m_e) ) # Ion plasma frequency (Hz) - self.w_pi = np.sqrt( - constants.q_e**2 * self.n_plasma / (self.M * constants.ep0) - ) + self.w_pi = np.sqrt(constants.q_e**2 * self.n_plasma / (self.M * constants.ep0)) # Skin depth (m) self.l_i = constants.c / self.w_pi @@ -177,7 +173,7 @@ def get_plasma_quantities(self): self.v_ti = np.sqrt(self.beta / 2.0) * self.vA # Temperature (eV) from thermal speed: v_ti = sqrt(kT / M) - self.T_plasma = self.v_ti**2 * self.M / constants.q_e # eV + self.T_plasma = self.v_ti**2 * self.M / constants.q_e # eV # Larmor radius (m) self.rho_i = self.v_ti / self.w_ci @@ -197,16 +193,16 @@ def setup_run(self): grid_object = picmi.Cartesian3DGrid self.grid = grid_object( - number_of_cells=[self.Nx, self.Nx, self.Nz][-self.dim:], + number_of_cells=[self.Nx, self.Nx, self.Nz][-self.dim :], warpx_max_grid_size=self.Nz, - lower_bound=[-self.Lx/2.0, -self.Lx/2.0, 0][-self.dim:], - upper_bound=[self.Lx/2.0, self.Lx/2.0, self.Lz][-self.dim:], - lower_boundary_conditions=['periodic']*self.dim, - upper_boundary_conditions=['periodic']*self.dim + lower_bound=[-self.Lx / 2.0, -self.Lx / 2.0, 0][-self.dim :], + upper_bound=[self.Lx / 2.0, self.Lx / 2.0, self.Lz][-self.dim :], + lower_boundary_conditions=["periodic"] * self.dim, + upper_boundary_conditions=["periodic"] * self.dim, ) simulation.time_step_size = self.dt simulation.max_steps = self.total_steps - simulation.current_deposition_algo = 'direct' + simulation.current_deposition_algo = "direct" simulation.particle_shape = 1 simulation.verbose = self.verbose @@ -216,15 +212,15 @@ def setup_run(self): self.solver = picmi.HybridPICSolver( grid=self.grid, - Te=self.T_plasma, n0=self.n_plasma, plasma_resistivity=self.eta, - substeps=self.substeps + Te=self.T_plasma, + n0=self.n_plasma, + plasma_resistivity=self.eta, + substeps=self.substeps, ) simulation.solver = self.solver B_ext = picmi.AnalyticInitialField( - Bx_expression=self.Bx, - By_expression=self.By, - Bz_expression=self.Bz + Bx_expression=self.Bx, By_expression=self.By, Bz_expression=self.Bz ) simulation.add_applied_field(B_ext) @@ -233,60 +229,58 @@ def setup_run(self): ####################################################################### self.ions = picmi.Species( - name='ions', charge='q_e', mass=self.M, + name="ions", + charge="q_e", + mass=self.M, initial_distribution=picmi.UniformDistribution( density=self.n_plasma, - rms_velocity=[self.v_ti]*3, - ) + rms_velocity=[self.v_ti] * 3, + ), ) simulation.add_species( self.ions, layout=picmi.PseudoRandomLayout( grid=self.grid, n_macroparticles_per_cell=self.NPPC - ) + ), ) ####################################################################### # Add diagnostics # ####################################################################### - if self.B_dir == 'z': - self.output_file_name = 'par_field_data.txt' + if self.B_dir == "z": + self.output_file_name = "par_field_data.txt" else: - self.output_file_name = 'perp_field_data.txt' + self.output_file_name = "perp_field_data.txt" if self.test: particle_diag = picmi.ParticleDiagnostic( - name='field_diag', + name="field_diag", period=self.total_steps, - write_dir='.', - warpx_file_prefix='Python_ohms_law_solver_EM_modes_1d_plt', # warpx_format = 'openpmd', # warpx_openpmd_backend = 'h5' ) simulation.add_diagnostic(particle_diag) field_diag = picmi.FieldDiagnostic( - name='field_diag', + name="field_diag", grid=self.grid, period=self.total_steps, - data_list=['B', 'E', 'J_displacement'], - write_dir='.', - warpx_file_prefix='Python_ohms_law_solver_EM_modes_1d_plt', + data_list=["B", "E", "J_displacement"], # warpx_format = 'openpmd', # warpx_openpmd_backend = 'h5' ) simulation.add_diagnostic(field_diag) - if self.B_dir == 'z' or self.dim == 1: + if self.B_dir == "z" or self.dim == 1: line_diag = picmi.ReducedDiagnostic( - diag_type='FieldProbe', - probe_geometry='Line', + diag_type="FieldProbe", + probe_geometry="Line", z_probe=0, z1_probe=self.Lz, resolution=self.Nz - 1, name=self.output_file_name[:-4], period=self.diag_steps, - path='diags/' + path="diags/", ) simulation.add_diagnostic(line_diag) else: @@ -297,10 +291,10 @@ def setup_run(self): except OSError: # diags directory already exists pass - with open(f"diags/{self.output_file_name}", 'w') as f: + with open(f"diags/{self.output_file_name}", "w") as f: f.write( - "[0]step() [1]time(s) [2]z_coord(m) " - "[3]Ez_lev0-(V/m) [4]Bx_lev0-(T) [5]By_lev0-(T)\n" + "[0]step() [1]time(s) [2]z_coord(m) " + "[3]Ez_lev0-(V/m) [4]Bx_lev0-(T) [5]By_lev0-(T)\n" ) ####################################################################### @@ -339,7 +333,7 @@ def _record_average_fields(self): Bx = np.mean(Bx_warpx[:-1], axis=(0, 1)) By = np.mean(By_warpx[:-1], axis=(0, 1)) - with open(f"diags/{self.output_file_name}", 'a') as f: + with open(f"diags/{self.output_file_name}", "a") as f: for ii in range(self.Nz): f.write( f"{step:05d} {t:.10e} {z_vals[ii]:.10e} {Ez[ii]:+.10e} " @@ -353,22 +347,29 @@ def _record_average_fields(self): parser = argparse.ArgumentParser() parser.add_argument( - '-t', '--test', help='toggle whether this script is run as a short CI test', - action='store_true', + "-t", + "--test", + help="toggle whether this script is run as a short CI test", + action="store_true", ) parser.add_argument( - '-d', '--dim', help='Simulation dimension', required=False, type=int, - default=1 + "-d", "--dim", help="Simulation dimension", required=False, type=int, default=1 ) parser.add_argument( - '--bdir', help='Direction of the B-field', required=False, - choices=['x', 'y', 'z'], default='z' + "--bdir", + help="Direction of the B-field", + required=False, + choices=["x", "y", "z"], + default="z", ) parser.add_argument( - '-v', '--verbose', help='Verbose output', action='store_true', + "-v", + "--verbose", + help="Verbose output", + action="store_true", ) args, left = parser.parse_known_args() -sys.argv = sys.argv[:1]+left +sys.argv = sys.argv[:1] + left run = EMModes(test=args.test, dim=args.dim, B_dir=args.bdir, verbose=args.verbose) simulation.step() diff --git a/Examples/Tests/ohm_solver_EM_modes/PICMI_inputs_rz.py b/Examples/Tests/ohm_solver_em_modes/inputs_test_rz_ohm_solver_em_modes_picmi.py similarity index 72% rename from Examples/Tests/ohm_solver_EM_modes/PICMI_inputs_rz.py rename to Examples/Tests/ohm_solver_em_modes/inputs_test_rz_ohm_solver_em_modes_picmi.py index 5bd1e3518f9..ba922dbdc9f 100644 --- a/Examples/Tests/ohm_solver_EM_modes/PICMI_inputs_rz.py +++ b/Examples/Tests/ohm_solver_em_modes/inputs_test_rz_ohm_solver_em_modes_picmi.py @@ -23,32 +23,33 @@ class CylindricalNormalModes(object): - '''The following runs a simulation of an uniform plasma at a set ion + """The following runs a simulation of an uniform plasma at a set ion temperature (and Te = 0) with an external magnetic field applied in the z-direction (parallel to domain). The analysis script (in this same directory) analyzes the output field data for EM modes. - ''' + """ + # Applied field parameters - B0 = 0.5 # Initial magnetic field strength (T) - beta = 0.01 # Plasma beta, used to calculate temperature + B0 = 0.5 # Initial magnetic field strength (T) + beta = 0.01 # Plasma beta, used to calculate temperature # Plasma species parameters - m_ion = 400.0 # Ion mass (electron masses) - vA_over_c = 5e-3 # ratio of Alfven speed and the speed of light + m_ion = 400.0 # Ion mass (electron masses) + vA_over_c = 5e-3 # ratio of Alfven speed and the speed of light # Spatial domain - Nz = 512 # number of cells in z direction - Nr = 128 # number of cells in r direction + Nz = 512 # number of cells in z direction + Nr = 128 # number of cells in r direction # Temporal domain (if not run as a CI test) - LT = 800.0 # Simulation temporal length (ion cyclotron periods) + LT = 800.0 # Simulation temporal length (ion cyclotron periods) # Numerical parameters - NPPC = 8000 # Seed number of particles per cell - DZ = 0.4 # Cell size (ion skin depths) - DR = 0.4 # Cell size (ion skin depths) - DT = 0.02 # Time step (ion cyclotron periods) + NPPC = 8000 # Seed number of particles per cell + DZ = 0.4 # Cell size (ion skin depths) + DR = 0.4 # Cell size (ion skin depths) + DT = 0.02 # Time step (ion cyclotron periods) # Plasma resistivity - used to dampen the mode excitation eta = 5e-4 @@ -82,7 +83,7 @@ def __init__(self, test, verbose): # dump all the current attributes to a dill pickle file if comm.rank == 0: - with open(f'sim_parameters.dpkl', 'wb') as f: + with open("sim_parameters.dpkl", "wb") as f: dill.dump(self, f) # print out plasma parameters @@ -106,7 +107,7 @@ def __init__(self, test, verbose): f"\tdt = {self.dt:.1e} s\n" f"\tdiag steps = {self.diag_steps:d}\n" f"\ttotal steps = {self.total_steps:d}\n", - flush=True + flush=True, ) self.setup_run() @@ -121,14 +122,12 @@ def get_plasma_quantities(self): # Alfven speed (m/s): vA = B / sqrt(mu0 * n * (M + m)) = c * omega_ci / w_pi self.vA = self.vA_over_c * constants.c - self.n_plasma = ( - (self.B0 / self.vA)**2 / (constants.mu0 * (self.M + constants.m_e)) + self.n_plasma = (self.B0 / self.vA) ** 2 / ( + constants.mu0 * (self.M + constants.m_e) ) # Ion plasma frequency (Hz) - self.w_pi = np.sqrt( - constants.q_e**2 * self.n_plasma / (self.M * constants.ep0) - ) + self.w_pi = np.sqrt(constants.q_e**2 * self.n_plasma / (self.M * constants.ep0)) # Skin depth (m) self.l_i = constants.c / self.w_pi @@ -137,7 +136,7 @@ def get_plasma_quantities(self): self.v_ti = np.sqrt(self.beta / 2.0) * self.vA # Temperature (eV) from thermal speed: v_ti = sqrt(kT / M) - self.T_plasma = self.v_ti**2 * self.M / constants.q_e # eV + self.T_plasma = self.v_ti**2 * self.M / constants.q_e # eV # Larmor radius (m) self.rho_i = self.v_ti / self.w_ci @@ -152,16 +151,16 @@ def setup_run(self): self.grid = picmi.CylindricalGrid( number_of_cells=[self.Nr, self.Nz], warpx_max_grid_size=self.Nz, - lower_bound=[0, -self.Lz/2.0], - upper_bound=[self.Lr, self.Lz/2.0], - lower_boundary_conditions = ['none', 'periodic'], - upper_boundary_conditions = ['dirichlet', 'periodic'], - lower_boundary_conditions_particles = ['none', 'periodic'], - upper_boundary_conditions_particles = ['reflecting', 'periodic'] + lower_bound=[0, -self.Lz / 2.0], + upper_bound=[self.Lr, self.Lz / 2.0], + lower_boundary_conditions=["none", "periodic"], + upper_boundary_conditions=["dirichlet", "periodic"], + lower_boundary_conditions_particles=["none", "periodic"], + upper_boundary_conditions_particles=["reflecting", "periodic"], ) simulation.time_step_size = self.dt simulation.max_steps = self.total_steps - simulation.current_deposition_algo = 'direct' + simulation.current_deposition_algo = "direct" simulation.particle_shape = 1 simulation.verbose = self.verbose @@ -171,15 +170,15 @@ def setup_run(self): self.solver = picmi.HybridPICSolver( grid=self.grid, - Te=0.0, n0=self.n_plasma, plasma_resistivity=self.eta, + Te=0.0, + n0=self.n_plasma, + plasma_resistivity=self.eta, substeps=self.substeps, - n_floor=self.n_plasma*0.05 + n_floor=self.n_plasma * 0.05, ) simulation.solver = self.solver - B_ext = picmi.AnalyticInitialField( - Bz_expression=self.B0 - ) + B_ext = picmi.AnalyticInitialField(Bz_expression=self.B0) simulation.add_applied_field(B_ext) ####################################################################### @@ -187,17 +186,19 @@ def setup_run(self): ####################################################################### self.ions = picmi.Species( - name='ions', charge='q_e', mass=self.M, + name="ions", + charge="q_e", + mass=self.M, initial_distribution=picmi.UniformDistribution( density=self.n_plasma, - rms_velocity=[self.v_ti]*3, - ) + rms_velocity=[self.v_ti] * 3, + ), ) simulation.add_species( self.ions, layout=picmi.PseudoRandomLayout( grid=self.grid, n_macroparticles_per_cell=self.NPPC - ) + ), ) ####################################################################### @@ -205,26 +206,24 @@ def setup_run(self): ####################################################################### field_diag = picmi.FieldDiagnostic( - name='field_diag', + name="field_diag", grid=self.grid, period=self.diag_steps, - data_list=['B', 'E'], - write_dir='diags', - warpx_file_prefix='field_diags', - warpx_format='openpmd', - warpx_openpmd_backend='h5', + data_list=["B", "E"], + write_dir="diags", + warpx_file_prefix="field_diags", + warpx_format="openpmd", + warpx_openpmd_backend="h5", ) simulation.add_diagnostic(field_diag) # add particle diagnostic for checksum if self.test: part_diag = picmi.ParticleDiagnostic( - name='diag1', + name="diag1", period=self.total_steps, species=[self.ions], - data_list=['ux', 'uy', 'uz', 'weighting'], - write_dir='.', - warpx_file_prefix='Python_ohms_law_solver_EM_modes_rz_plt' + data_list=["ux", "uy", "uz", "weighting"], ) simulation.add_diagnostic(part_diag) @@ -235,14 +234,19 @@ def setup_run(self): parser = argparse.ArgumentParser() parser.add_argument( - '-t', '--test', help='toggle whether this script is run as a short CI test', - action='store_true', + "-t", + "--test", + help="toggle whether this script is run as a short CI test", + action="store_true", ) parser.add_argument( - '-v', '--verbose', help='Verbose output', action='store_true', + "-v", + "--verbose", + help="Verbose output", + action="store_true", ) args, left = parser.parse_known_args() -sys.argv = sys.argv[:1]+left +sys.argv = sys.argv[:1] + left run = CylindricalNormalModes(test=args.test, verbose=args.verbose) simulation.step() diff --git a/Examples/Tests/ohm_solver_ion_Landau_damping/CMakeLists.txt b/Examples/Tests/ohm_solver_ion_Landau_damping/CMakeLists.txt new file mode 100644 index 00000000000..501b1ce2ced --- /dev/null +++ b/Examples/Tests/ohm_solver_ion_Landau_damping/CMakeLists.txt @@ -0,0 +1,13 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_ohm_solver_landau_damping_picmi # name + 2 # dims + 2 # nprocs + "inputs_test_2d_ohm_solver_landau_damping_picmi.py --test --dim 2 --temp_ratio 0.1" # inputs + analysis.py # analysis + diags/diag1000100 # output + OFF # dependency +) +label_warpx_test(test_2d_ohm_solver_landau_damping_picmi slow) diff --git a/Examples/Tests/ohm_solver_ion_Landau_damping/README.rst b/Examples/Tests/ohm_solver_ion_Landau_damping/README.rst index dd4f94b4edf..d54f4e16aa6 100644 --- a/Examples/Tests/ohm_solver_ion_Landau_damping/README.rst +++ b/Examples/Tests/ohm_solver_ion_Landau_damping/README.rst @@ -14,17 +14,17 @@ Run The same input script can be used for 1d, 2d or 3d simulations and to sweep different temperature ratios. -.. dropdown:: Script ``PICMI_inputs.py`` +.. dropdown:: Script ``inputs_test_2d_ohm_solver_landau_damping_picmi.py`` - .. literalinclude:: PICMI_inputs.py + .. literalinclude:: inputs_test_2d_ohm_solver_landau_damping_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/ohm_solver_ion_Landau_damping/PICMI_inputs.py``. + :caption: You can copy this file from ``Examples/Tests/ohm_solver_ion_Landau_damping/inputs_test_2d_ohm_solver_landau_damping_picmi.py``. For `MPI-parallel `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. .. code-block:: bash - python3 PICMI_inputs.py -dim {1/2/3} --temp_ratio {value} + python3 inputs_test_2d_ohm_solver_landau_damping_picmi.py -dim {1/2/3} --temp_ratio {value} Analyze ------- diff --git a/Examples/Tests/ohm_solver_ion_Landau_damping/analysis.py b/Examples/Tests/ohm_solver_ion_Landau_damping/analysis.py index ade7187ebe3..700ad68fe87 100755 --- a/Examples/Tests/ohm_solver_ion_Landau_damping/analysis.py +++ b/Examples/Tests/ohm_solver_ion_Landau_damping/analysis.py @@ -11,39 +11,56 @@ constants = picmi.constants -matplotlib.rcParams.update({'font.size': 20}) +matplotlib.rcParams.update({"font.size": 20}) # load simulation parameters -with open(f'sim_parameters.dpkl', 'rb') as f: +with open("sim_parameters.dpkl", "rb") as f: sim = dill.load(f) # theoretical damping rates were taken from Fig. 14b of Munoz et al. -theoretical_damping_rate = np.array([ - [0.09456706, 0.05113443], [0.09864177, 0.05847507], - [0.10339559, 0.0659153 ], [0.10747029, 0.07359366], - [0.11290323, 0.08256106], [0.11833616, 0.09262114], - [0.12580645, 0.10541121], [0.13327674, 0.11825558], - [0.14006791, 0.13203098], [0.14889643, 0.14600538], - [0.15772496, 0.16379615], [0.16791171, 0.18026693], - [0.17606112, 0.19650209], [0.18828523, 0.21522808], - [0.19983022, 0.23349062], [0.21273345, 0.25209216], - [0.22835314, 0.27877403], [0.24465195, 0.30098317], - [0.25959253, 0.32186286], [0.27657046, 0.34254601], - [0.29626486, 0.36983567], [0.3139219 , 0.38984826], - [0.33157895, 0.40897973], [0.35195246, 0.43526107], - [0.37368421, 0.45662113], [0.39745331, 0.47902942], - [0.44974533, 0.52973074], [0.50747029, 0.57743925], - [0.57334465, 0.63246726], [0.64193548, 0.67634255] -]) +theoretical_damping_rate = np.array( + [ + [0.09456706, 0.05113443], + [0.09864177, 0.05847507], + [0.10339559, 0.0659153], + [0.10747029, 0.07359366], + [0.11290323, 0.08256106], + [0.11833616, 0.09262114], + [0.12580645, 0.10541121], + [0.13327674, 0.11825558], + [0.14006791, 0.13203098], + [0.14889643, 0.14600538], + [0.15772496, 0.16379615], + [0.16791171, 0.18026693], + [0.17606112, 0.19650209], + [0.18828523, 0.21522808], + [0.19983022, 0.23349062], + [0.21273345, 0.25209216], + [0.22835314, 0.27877403], + [0.24465195, 0.30098317], + [0.25959253, 0.32186286], + [0.27657046, 0.34254601], + [0.29626486, 0.36983567], + [0.3139219, 0.38984826], + [0.33157895, 0.40897973], + [0.35195246, 0.43526107], + [0.37368421, 0.45662113], + [0.39745331, 0.47902942], + [0.44974533, 0.52973074], + [0.50747029, 0.57743925], + [0.57334465, 0.63246726], + [0.64193548, 0.67634255], + ] +) expected_gamma = np.interp( sim.T_ratio, theoretical_damping_rate[:, 0], theoretical_damping_rate[:, 1] ) data = np.loadtxt("diags/field_data.txt", skiprows=1) -field_idx_dict = {'z': 2, 'Ez': 3} +field_idx_dict = {"z": 2, "Ez": 3} -step = data[:,0] +step = data[:, 0] num_steps = len(np.unique(step)) @@ -51,16 +68,16 @@ resolution = len(np.where(step == 0)[0]) - 1 # reshape to separate spatial and time coordinates -sim_data = data.reshape((num_steps, resolution+1, data.shape[1])) +sim_data = data.reshape((num_steps, resolution + 1, data.shape[1])) -z_grid = sim_data[1, :, field_idx_dict['z']] +z_grid = sim_data[1, :, field_idx_dict["z"]] idx = np.argsort(z_grid)[1:] dz = np.mean(np.diff(z_grid[idx])) -dt = np.mean(np.diff(sim_data[:,0,1])) +dt = np.mean(np.diff(sim_data[:, 0, 1])) data = np.zeros((num_steps, resolution)) for i in range(num_steps): - data[i,:] = sim_data[i,idx,field_idx_dict['Ez']] + data[i, :] = sim_data[i, idx, field_idx_dict["Ez"]] print(f"Data file contains {num_steps} time snapshots.") print(f"Spatial resolution is {resolution}") @@ -72,23 +89,23 @@ # Plot the 4th Fourier mode fig, ax1 = plt.subplots(1, 1, figsize=(10, 5)) -t_points = np.arange(num_steps)*dt*t_norm +t_points = np.arange(num_steps) * dt * t_norm ax1.plot( - t_points, np.abs(field_kt[:, sim.m] / field_kt[0, sim.m]), 'r', - label=f'$T_i/T_e$ = {sim.T_ratio:.2f}' + t_points, + np.abs(field_kt[:, sim.m] / field_kt[0, sim.m]), + "r", + label=f"$T_i/T_e$ = {sim.T_ratio:.2f}", ) # Plot a line showing the expected damping rate t_points = t_points[np.where(t_points < 8)] -ax1.plot( - t_points, np.exp(-t_points*expected_gamma), 'k--', lw=2 -) +ax1.plot(t_points, np.exp(-t_points * expected_gamma), "k--", lw=2) ax1.grid() ax1.legend() -ax1.set_yscale('log') -ax1.set_ylabel('$|E_z|/E_0$') -ax1.set_xlabel('t $(k_mv_{th,i})$') +ax1.set_yscale("log") +ax1.set_ylabel("$|E_z|/E_0$") +ax1.set_xlabel("t $(k_mv_{th,i})$") ax1.set_xlim(0, 18) ax1.set_title(f"Ion Landau damping - {sim.dim}d") @@ -98,7 +115,8 @@ if sim.test: import os import sys - sys.path.insert(1, '../../../../warpx/Regression/Checksum/') + + sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file diff --git a/Examples/Tests/ohm_solver_ion_Landau_damping/PICMI_inputs.py b/Examples/Tests/ohm_solver_ion_Landau_damping/inputs_test_2d_ohm_solver_landau_damping_picmi.py similarity index 71% rename from Examples/Tests/ohm_solver_ion_Landau_damping/PICMI_inputs.py rename to Examples/Tests/ohm_solver_ion_Landau_damping/inputs_test_2d_ohm_solver_landau_damping_picmi.py index d4430502f42..7c1709d059f 100644 --- a/Examples/Tests/ohm_solver_ion_Landau_damping/PICMI_inputs.py +++ b/Examples/Tests/ohm_solver_ion_Landau_damping/inputs_test_2d_ohm_solver_landau_damping_picmi.py @@ -20,35 +20,33 @@ comm = mpi.COMM_WORLD -simulation = picmi.Simulation( - warpx_serialize_initial_conditions=True, - verbose=0 -) +simulation = picmi.Simulation(warpx_serialize_initial_conditions=True, verbose=0) class IonLandauDamping(object): - '''This input is based on the ion Landau damping test as described by + """This input is based on the ion Landau damping test as described by Munoz et al. (2018). - ''' + """ + # Applied field parameters - B0 = 0.1 # Initial magnetic field strength (T) - beta = 2.0 # Plasma beta, used to calculate temperature + B0 = 0.1 # Initial magnetic field strength (T) + beta = 2.0 # Plasma beta, used to calculate temperature # Plasma species parameters - m_ion = 100.0 # Ion mass (electron masses) - vA_over_c = 1e-3 # ratio of Alfven speed and the speed of light + m_ion = 100.0 # Ion mass (electron masses) + vA_over_c = 1e-3 # ratio of Alfven speed and the speed of light # Spatial domain - Nz = 256 # number of cells in z direction - Nx = 4 # number of cells in x (and y) direction for >1 dimensions + Nz = 256 # number of cells in z direction + Nx = 4 # number of cells in x (and y) direction for >1 dimensions # Temporal domain (if not run as a CI test) - LT = 40.0 # Simulation temporal length (ion cyclotron periods) + LT = 40.0 # Simulation temporal length (ion cyclotron periods) # Numerical parameters - NPPC = [8192, 4096, 1024] # Seed number of particles per cell - DZ = 1.0 / 6.0 # Cell size (ion skin depths) - DT = 1e-3 # Time step (ion cyclotron periods) + NPPC = [8192, 4096, 1024] # Seed number of particles per cell + DZ = 1.0 / 6.0 # Cell size (ion skin depths) + DT = 1e-3 # Time step (ion cyclotron periods) # density perturbation strength epsilon = 0.03 @@ -58,7 +56,6 @@ class IonLandauDamping(object): # Number of substeps used to update B substeps = 10 - def __init__(self, test, dim, m, T_ratio, verbose): """Get input parameters for the specific case desired.""" self.test = test @@ -68,7 +65,7 @@ def __init__(self, test, dim, m, T_ratio, verbose): self.verbose = verbose or self.test # sanity check - assert (dim > 0 and dim < 4), f"{dim}-dimensions not a valid input" + assert dim > 0 and dim < 4, f"{dim}-dimensions not a valid input" # calculate various plasma parameters based on the simulation input self.get_plasma_quantities() @@ -77,7 +74,7 @@ def __init__(self, test, dim, m, T_ratio, verbose): self.Lz = self.Nz * self.dz self.Lx = self.Nx * self.dz - diag_period = 1 / 16.0 # Output interval (ion cyclotron periods) + diag_period = 1 / 16.0 # Output interval (ion cyclotron periods) self.diag_steps = int(diag_period / self.DT) self.total_steps = int(np.ceil(self.LT / self.DT)) @@ -85,11 +82,11 @@ def __init__(self, test, dim, m, T_ratio, verbose): if self.test: self.total_steps = 100 - self.dt = self.DT / self.w_ci # self.DT * self.t_ci + self.dt = self.DT / self.w_ci # self.DT * self.t_ci # dump all the current attributes to a dill pickle file if comm.rank == 0: - with open('sim_parameters.dpkl', 'wb') as f: + with open("sim_parameters.dpkl", "wb") as f: dill.dump(self, f) # print out plasma parameters @@ -129,14 +126,12 @@ def get_plasma_quantities(self): # Alfven speed (m/s): vA = B / sqrt(mu0 * n * (M + m)) = c * omega_ci / w_pi self.vA = self.vA_over_c * constants.c - self.n_plasma = ( - (self.B0 / self.vA)**2 / (constants.mu0 * (self.M + constants.m_e)) + self.n_plasma = (self.B0 / self.vA) ** 2 / ( + constants.mu0 * (self.M + constants.m_e) ) # Ion plasma frequency (Hz) - self.w_pi = np.sqrt( - constants.q_e**2 * self.n_plasma / (self.M * constants.ep0) - ) + self.w_pi = np.sqrt(constants.q_e**2 * self.n_plasma / (self.M * constants.ep0)) # Skin depth (m) self.l_i = constants.c / self.w_pi @@ -145,7 +140,7 @@ def get_plasma_quantities(self): self.v_ti = np.sqrt(self.beta / 2.0) * self.vA # Temperature (eV) from thermal speed: v_ti = sqrt(kT / M) - self.T_plasma = self.v_ti**2 * self.M / constants.q_e # eV + self.T_plasma = self.v_ti**2 * self.M / constants.q_e # eV # Larmor radius (m) self.rho_i = self.v_ti / self.w_ci @@ -165,17 +160,17 @@ def setup_run(self): grid_object = picmi.Cartesian3DGrid self.grid = grid_object( - number_of_cells=[self.Nx, self.Nx, self.Nz][-self.dim:], + number_of_cells=[self.Nx, self.Nx, self.Nz][-self.dim :], warpx_max_grid_size=self.Nz, - lower_bound=[-self.Lx/2.0, -self.Lx/2.0, 0][-self.dim:], - upper_bound=[self.Lx/2.0, self.Lx/2.0, self.Lz][-self.dim:], - lower_boundary_conditions=['periodic']*self.dim, - upper_boundary_conditions=['periodic']*self.dim, - warpx_blocking_factor=4 + lower_bound=[-self.Lx / 2.0, -self.Lx / 2.0, 0][-self.dim :], + upper_bound=[self.Lx / 2.0, self.Lx / 2.0, self.Lz][-self.dim :], + lower_boundary_conditions=["periodic"] * self.dim, + upper_boundary_conditions=["periodic"] * self.dim, + warpx_blocking_factor=4, ) simulation.time_step_size = self.dt simulation.max_steps = self.total_steps - simulation.current_deposition_algo = 'direct' + simulation.current_deposition_algo = "direct" simulation.particle_shape = 1 simulation.verbose = self.verbose @@ -184,10 +179,12 @@ def setup_run(self): ####################################################################### self.solver = picmi.HybridPICSolver( - grid=self.grid, gamma=1.0, - Te=self.T_plasma/self.T_ratio, + grid=self.grid, + gamma=1.0, + Te=self.T_plasma / self.T_ratio, n0=self.n_plasma, - plasma_resistivity=self.eta, substeps=self.substeps + plasma_resistivity=self.eta, + substeps=self.substeps, ) simulation.solver = self.solver @@ -195,19 +192,21 @@ def setup_run(self): # Particle types setup # ####################################################################### - k_m = 2.0*np.pi*self.m / self.Lz + k_m = 2.0 * np.pi * self.m / self.Lz self.ions = picmi.Species( - name='ions', charge='q_e', mass=self.M, + name="ions", + charge="q_e", + mass=self.M, initial_distribution=picmi.AnalyticDistribution( density_expression=f"{self.n_plasma}*(1+{self.epsilon}*cos({k_m}*z))", - rms_velocity=[self.v_ti]*3 - ) + rms_velocity=[self.v_ti] * 3, + ), ) simulation.add_species( self.ions, layout=picmi.PseudoRandomLayout( - grid=self.grid, n_macroparticles_per_cell=self.NPPC[self.dim-1] - ) + grid=self.grid, n_macroparticles_per_cell=self.NPPC[self.dim - 1] + ), ) ####################################################################### @@ -218,25 +217,21 @@ def setup_run(self): if self.test: particle_diag = picmi.ParticleDiagnostic( - name='diag1', + name="diag1", period=100, - write_dir='.', species=[self.ions], - data_list = ['ux', 'uy', 'uz', 'x', 'z', 'weighting'], - warpx_file_prefix=f'Python_ohms_law_solver_landau_damping_{self.dim}d_plt', + data_list=["ux", "uy", "uz", "x", "z", "weighting"], ) simulation.add_diagnostic(particle_diag) field_diag = picmi.FieldDiagnostic( - name='diag1', + name="diag1", grid=self.grid, period=100, - write_dir='.', - data_list = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], - warpx_file_prefix=f'Python_ohms_law_solver_landau_damping_{self.dim}d_plt', + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez", "Jx", "Jy", "Jz"], ) simulation.add_diagnostic(field_diag) - self.output_file_name = 'field_data.txt' + self.output_file_name = "field_data.txt" # install a custom "reduced diagnostic" to save the average field callbacks.installafterEsolve(self._record_average_fields) try: @@ -244,7 +239,7 @@ def setup_run(self): except OSError: # diags directory already exists pass - with open(f"diags/{self.output_file_name}", 'w') as f: + with open(f"diags/{self.output_file_name}", "w") as f: f.write("[0]step() [1]time(s) [2]z_coord(m) [3]Ez_lev0-(V/m)\n") self.prev_time = time.time() @@ -259,9 +254,7 @@ def setup_run(self): simulation.initialize_warpx() # get ion particle container wrapper - self.ion_part_container = particle_containers.ParticleContainerWrapper( - 'ions' - ) + self.ion_part_container = particle_containers.ParticleContainerWrapper("ions") def text_diag(self): """Diagnostic function to print out timing data and particle numbers.""" @@ -275,12 +268,12 @@ def text_diag(self): step_rate = steps / wall_time status_dict = { - 'step': step, - 'nplive ions': self.ion_part_container.nps, - 'wall_time': wall_time, - 'step_rate': step_rate, + "step": step, + "nplive ions": self.ion_part_container.nps, + "wall_time": wall_time, + "step_rate": step_rate, "diag_steps": self.diag_steps, - 'iproc': None + "iproc": None, } diag_string = ( @@ -321,11 +314,9 @@ def _record_average_fields(self): else: Ez = np.mean(Ez_warpx, axis=(0, 1)) - with open(f"diags/{self.output_file_name}", 'a') as f: + with open(f"diags/{self.output_file_name}", "a") as f: for ii in range(self.Nz): - f.write( - f"{step:05d} {t:.10e} {z_vals[ii]:.10e} {Ez[ii]:+.10e}\n" - ) + f.write(f"{step:05d} {t:.10e} {z_vals[ii]:.10e} {Ez[ii]:+.10e}\n") ########################## @@ -334,29 +325,38 @@ def _record_average_fields(self): parser = argparse.ArgumentParser() parser.add_argument( - '-t', '--test', help='toggle whether this script is run as a short CI test', - action='store_true', + "-t", + "--test", + help="toggle whether this script is run as a short CI test", + action="store_true", ) parser.add_argument( - '-d', '--dim', help='Simulation dimension', required=False, type=int, - default=1 + "-d", "--dim", help="Simulation dimension", required=False, type=int, default=1 ) parser.add_argument( - '-m', help='Mode number to excite', required=False, type=int, - default=4 + "-m", help="Mode number to excite", required=False, type=int, default=4 ) parser.add_argument( - '--temp_ratio', help='Ratio of ion to electron temperature', required=False, - type=float, default=1.0/3 + "--temp_ratio", + help="Ratio of ion to electron temperature", + required=False, + type=float, + default=1.0 / 3, ) parser.add_argument( - '-v', '--verbose', help='Verbose output', action='store_true', + "-v", + "--verbose", + help="Verbose output", + action="store_true", ) args, left = parser.parse_known_args() -sys.argv = sys.argv[:1]+left +sys.argv = sys.argv[:1] + left run = IonLandauDamping( - test=args.test, dim=args.dim, m=args.m, T_ratio=args.temp_ratio, - verbose=args.verbose + test=args.test, + dim=args.dim, + m=args.m, + T_ratio=args.temp_ratio, + verbose=args.verbose, ) simulation.step() diff --git a/Examples/Tests/ohm_solver_ion_beam_instability/CMakeLists.txt b/Examples/Tests/ohm_solver_ion_beam_instability/CMakeLists.txt new file mode 100644 index 00000000000..81c6b0d41fd --- /dev/null +++ b/Examples/Tests/ohm_solver_ion_beam_instability/CMakeLists.txt @@ -0,0 +1,13 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_ohm_solver_ion_beam_picmi # name + 1 # dims + 2 # nprocs + "inputs_test_1d_ohm_solver_ion_beam_picmi.py --test --dim 1 --resonant" # inputs + analysis.py # analysis + diags/diag1002500 # output + OFF # dependency +) +label_warpx_test(test_1d_ohm_solver_ion_beam_picmi slow) diff --git a/Examples/Tests/ohm_solver_ion_beam_instability/README.rst b/Examples/Tests/ohm_solver_ion_beam_instability/README.rst index 59469cf4aa9..49b5f1ac0a0 100644 --- a/Examples/Tests/ohm_solver_ion_beam_instability/README.rst +++ b/Examples/Tests/ohm_solver_ion_beam_instability/README.rst @@ -13,11 +13,11 @@ Run The same input script can be used for 1d, 2d or 3d simulations as well as replicating either the resonant or non-resonant condition as indicated below. -.. dropdown:: Script ``PICMI_inputs.py`` +.. dropdown:: Script ``inputs_test_1d_ohm_solver_ion_beam_picmi.py`` - .. literalinclude:: PICMI_inputs.py + .. literalinclude:: inputs_test_1d_ohm_solver_ion_beam_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/ohm_solver_ion_beam_instability/PICMI_inputs.py``. + :caption: You can copy this file from ``Examples/Tests/ohm_solver_ion_beam_instability/inputs_test_1d_ohm_solver_ion_beam_picmi.py``. For `MPI-parallel `__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. @@ -29,7 +29,7 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. code-block:: bash - python3 PICMI_inputs.py -dim {1/2/3} --resonant + python3 inputs_test_1d_ohm_solver_ion_beam_picmi.py -dim {1/2/3} --resonant .. tab-item:: Non-resonant case @@ -37,7 +37,7 @@ For `MPI-parallel `__ runs, prefix these lines with ` .. code-block:: bash - python3 PICMI_inputs.py -dim {1/2/3} + python3 inputs_test_1d_ohm_solver_ion_beam_picmi.py -dim {1/2/3} Analyze ------- diff --git a/Examples/Tests/ohm_solver_ion_beam_instability/analysis.py b/Examples/Tests/ohm_solver_ion_beam_instability/analysis.py index 6a57b1c1046..5bd9db3d91d 100755 --- a/Examples/Tests/ohm_solver_ion_beam_instability/analysis.py +++ b/Examples/Tests/ohm_solver_ion_beam_instability/analysis.py @@ -12,24 +12,24 @@ constants = picmi.constants -matplotlib.rcParams.update({'font.size': 20}) +matplotlib.rcParams.update({"font.size": 20}) # load simulation parameters -with open(f'sim_parameters.dpkl', 'rb') as f: +with open("sim_parameters.dpkl", "rb") as f: sim = dill.load(f) if sim.resonant: - resonant_str = 'resonant' + resonant_str = "resonant" else: - resonant_str = 'non resonant' + resonant_str = "non resonant" data = np.loadtxt("diags/field_data.txt", skiprows=1) if sim.dim == 1: - field_idx_dict = {'z': 4, 'By': 8} + field_idx_dict = {"z": 4, "By": 8} else: - field_idx_dict = {'z': 2, 'By': 3} + field_idx_dict = {"z": 2, "By": 3} -step = data[:,0] +step = data[:, 0] num_steps = len(np.unique(step)) @@ -37,16 +37,16 @@ resolution = len(np.where(step == 0)[0]) - 1 # reshape to separate spatial and time coordinates -sim_data = data.reshape((num_steps, resolution+1, data.shape[1])) +sim_data = data.reshape((num_steps, resolution + 1, data.shape[1])) -z_grid = sim_data[1, :, field_idx_dict['z']] +z_grid = sim_data[1, :, field_idx_dict["z"]] idx = np.argsort(z_grid)[1:] dz = np.mean(np.diff(z_grid[idx])) -dt = np.mean(np.diff(sim_data[:,0,1])) +dt = np.mean(np.diff(sim_data[:, 0, 1])) data = np.zeros((num_steps, resolution)) for i in range(num_steps): - data[i,:] = sim_data[i,idx,field_idx_dict['By']] + data[i, :] = sim_data[i, idx, field_idx_dict["By"]] print(f"Data file contains {num_steps} time snapshots.") print(f"Spatial resolution is {resolution}") @@ -54,36 +54,48 @@ # Create the stack time plot fig, ax1 = plt.subplots(1, 1, figsize=(10, 5)) -max_val = np.max(np.abs(data[:,:]/sim.B0)) +max_val = np.max(np.abs(data[:, :] / sim.B0)) -extent = [0, sim.Lz/sim.l_i, 0, num_steps*dt*sim.w_ci] # num_steps*dt/sim.t_ci] +extent = [0, sim.Lz / sim.l_i, 0, num_steps * dt * sim.w_ci] # num_steps*dt/sim.t_ci] im = ax1.imshow( - data[:,:]/sim.B0, extent=extent, origin='lower', - cmap='seismic', vmin=-max_val, vmax=max_val, aspect="equal", + data[:, :] / sim.B0, + extent=extent, + origin="lower", + cmap="seismic", + vmin=-max_val, + vmax=max_val, + aspect="equal", ) # Colorbar fig.subplots_adjust(right=0.825) cbar_ax = fig.add_axes([0.85, 0.2, 0.03, 0.6]) -fig.colorbar(im, cax=cbar_ax, orientation='vertical', label='$B_y/B_0$') +fig.colorbar(im, cax=cbar_ax, orientation="vertical", label="$B_y/B_0$") ax1.set_xlabel("$x/l_i$") ax1.set_ylabel("$t \Omega_i$ (rad)") ax1.set_title(f"Ion beam R instability - {resonant_str} case") -plt.savefig(f"diags/ion_beam_R_instability_{resonant_str}_eta_{sim.eta}_substeps_{sim.substeps}.png") +plt.savefig( + f"diags/ion_beam_R_instability_{resonant_str}_eta_{sim.eta}_substeps_{sim.substeps}.png" +) plt.close() if sim.resonant: - # Plot the 4th, 5th and 6th Fourier modes field_kt = np.fft.fft(data[:, :], axis=1) - k = 2*np.pi * np.fft.fftfreq(resolution, dz) * sim.l_i + k = 2 * np.pi * np.fft.fftfreq(resolution, dz) * sim.l_i - t_grid = np.arange(num_steps)*dt*sim.w_ci - plt.plot(t_grid, np.abs(field_kt[:, 4] / sim.B0), 'r', label=f'm = 4, $kl_i={k[4]:.2f}$') - plt.plot(t_grid, np.abs(field_kt[:, 5] / sim.B0), 'b', label=f'm = 5, $kl_i={k[5]:.2f}$') - plt.plot(t_grid, np.abs(field_kt[:, 6] / sim.B0), 'k', label=f'm = 6, $kl_i={k[6]:.2f}$') + t_grid = np.arange(num_steps) * dt * sim.w_ci + plt.plot( + t_grid, np.abs(field_kt[:, 4] / sim.B0), "r", label=f"m = 4, $kl_i={k[4]:.2f}$" + ) + plt.plot( + t_grid, np.abs(field_kt[:, 5] / sim.B0), "b", label=f"m = 5, $kl_i={k[5]:.2f}$" + ) + plt.plot( + t_grid, np.abs(field_kt[:, 6] / sim.B0), "k", label=f"m = 6, $kl_i={k[6]:.2f}$" + ) # The theoretical growth rates for the 4th, 5th and 6th Fourier modes of # the By-field was obtained from Fig. 12a of Munoz et al. @@ -97,94 +109,117 @@ idx = np.where((t_grid > 10) & (t_grid < 40)) t_points = t_grid[idx] - A4 = np.exp(np.mean(np.log(np.abs(field_kt[idx, 4] / sim.B0)) - t_points*gamma4)) - plt.plot(t_points, A4*np.exp(t_points*gamma4), 'r--', lw=3) - A5 = np.exp(np.mean(np.log(np.abs(field_kt[idx, 5] / sim.B0)) - t_points*gamma5)) - plt.plot(t_points, A5*np.exp(t_points*gamma5), 'b--', lw=3) - A6 = np.exp(np.mean(np.log(np.abs(field_kt[idx, 6] / sim.B0)) - t_points*gamma6)) - plt.plot(t_points, A6*np.exp(t_points*gamma6), 'k--', lw=3) + A4 = np.exp(np.mean(np.log(np.abs(field_kt[idx, 4] / sim.B0)) - t_points * gamma4)) + plt.plot(t_points, A4 * np.exp(t_points * gamma4), "r--", lw=3) + A5 = np.exp(np.mean(np.log(np.abs(field_kt[idx, 5] / sim.B0)) - t_points * gamma5)) + plt.plot(t_points, A5 * np.exp(t_points * gamma5), "b--", lw=3) + A6 = np.exp(np.mean(np.log(np.abs(field_kt[idx, 6] / sim.B0)) - t_points * gamma6)) + plt.plot(t_points, A6 * np.exp(t_points * gamma6), "k--", lw=3) plt.grid() plt.legend() - plt.yscale('log') - plt.ylabel('$|B_y/B_0|$') - plt.xlabel('$t\Omega_i$ (rad)') + plt.yscale("log") + plt.ylabel("$|B_y/B_0|$") + plt.xlabel("$t\Omega_i$ (rad)") plt.tight_layout() - plt.savefig(f"diags/ion_beam_R_instability_{resonant_str}_eta_{sim.eta}_substeps_{sim.substeps}_low_modes.png") + plt.savefig( + f"diags/ion_beam_R_instability_{resonant_str}_eta_{sim.eta}_substeps_{sim.substeps}_low_modes.png" + ) plt.close() # check if the growth rate matches expectation - m4_rms_error = np.sqrt(np.mean( - (np.abs(field_kt[idx, 4] / sim.B0) - A4*np.exp(t_points*gamma4))**2 - )) - m5_rms_error = np.sqrt(np.mean( - (np.abs(field_kt[idx, 5] / sim.B0) - A5*np.exp(t_points*gamma5))**2 - )) - m6_rms_error = np.sqrt(np.mean( - (np.abs(field_kt[idx, 6] / sim.B0) - A6*np.exp(t_points*gamma6))**2 - )) + m4_rms_error = np.sqrt( + np.mean( + (np.abs(field_kt[idx, 4] / sim.B0) - A4 * np.exp(t_points * gamma4)) ** 2 + ) + ) + m5_rms_error = np.sqrt( + np.mean( + (np.abs(field_kt[idx, 5] / sim.B0) - A5 * np.exp(t_points * gamma5)) ** 2 + ) + ) + m6_rms_error = np.sqrt( + np.mean( + (np.abs(field_kt[idx, 6] / sim.B0) - A6 * np.exp(t_points * gamma6)) ** 2 + ) + ) print("Growth rate RMS errors:") print(f" m = 4: {m4_rms_error:.3e}") print(f" m = 5: {m5_rms_error:.3e}") print(f" m = 6: {m6_rms_error:.3e}") if not sim.test: - with h5py.File('diags/Python_hybrid_PIC_plt/openpmd_004000.h5', 'r') as data: + with h5py.File("diags/Python_hybrid_PIC_plt/openpmd_004000.h5", "r") as data: + timestep = str(np.squeeze([key for key in data["data"].keys()])) - timestep = str(np.squeeze([key for key in data['data'].keys()])) - - z = np.array(data['data'][timestep]['particles']['ions']['position']['z']) - vy = np.array(data['data'][timestep]['particles']['ions']['momentum']['y']) - w = np.array(data['data'][timestep]['particles']['ions']['weighting']) + z = np.array(data["data"][timestep]["particles"]["ions"]["position"]["z"]) + vy = np.array(data["data"][timestep]["particles"]["ions"]["momentum"]["y"]) + w = np.array(data["data"][timestep]["particles"]["ions"]["weighting"]) fig, ax1 = plt.subplots(1, 1, figsize=(10, 5)) im = ax1.hist2d( - z/sim.l_i, vy/sim.M/sim.vA, weights=w, density=True, - range=[[0, 250], [-10, 10]], bins=250, cmin=1e-5 + z / sim.l_i, + vy / sim.M / sim.vA, + weights=w, + density=True, + range=[[0, 250], [-10, 10]], + bins=250, + cmin=1e-5, ) # Colorbar fig.subplots_adjust(bottom=0.15, right=0.815) cbar_ax = fig.add_axes([0.83, 0.2, 0.03, 0.6]) - fig.colorbar(im[3], cax=cbar_ax, orientation='vertical', format='%.0e', label='$f(z, v_y)$') + fig.colorbar( + im[3], cax=cbar_ax, orientation="vertical", format="%.0e", label="$f(z, v_y)$" + ) ax1.set_xlabel("$x/l_i$") ax1.set_ylabel("$v_{y}/v_A$") ax1.set_title(f"Ion beam R instability - {resonant_str} case") - plt.savefig(f"diags/ion_beam_R_instability_{resonant_str}_eta_{sim.eta}_substeps_{sim.substeps}_core_phase_space.png") + plt.savefig( + f"diags/ion_beam_R_instability_{resonant_str}_eta_{sim.eta}_substeps_{sim.substeps}_core_phase_space.png" + ) plt.close() - with h5py.File('diags/Python_hybrid_PIC_plt/openpmd_004000.h5', 'r') as data: - - timestep = str(np.squeeze([key for key in data['data'].keys()])) + with h5py.File("diags/Python_hybrid_PIC_plt/openpmd_004000.h5", "r") as data: + timestep = str(np.squeeze([key for key in data["data"].keys()])) - z = np.array(data['data'][timestep]['particles']['beam_ions']['position']['z']) - vy = np.array(data['data'][timestep]['particles']['beam_ions']['momentum']['y']) - w = np.array(data['data'][timestep]['particles']['beam_ions']['weighting']) + z = np.array(data["data"][timestep]["particles"]["beam_ions"]["position"]["z"]) + vy = np.array(data["data"][timestep]["particles"]["beam_ions"]["momentum"]["y"]) + w = np.array(data["data"][timestep]["particles"]["beam_ions"]["weighting"]) fig, ax1 = plt.subplots(1, 1, figsize=(10, 5)) im = ax1.hist2d( - z/sim.l_i, vy/sim.M/sim.vA, weights=w, density=True, - range=[[0, 250], [-10, 10]], bins=250, cmin=1e-5 + z / sim.l_i, + vy / sim.M / sim.vA, + weights=w, + density=True, + range=[[0, 250], [-10, 10]], + bins=250, + cmin=1e-5, ) # Colorbar fig.subplots_adjust(bottom=0.15, right=0.815) cbar_ax = fig.add_axes([0.83, 0.2, 0.03, 0.6]) - fig.colorbar(im[3], cax=cbar_ax, orientation='vertical', format='%.0e', label='$f(z, v_y)$') + fig.colorbar( + im[3], cax=cbar_ax, orientation="vertical", format="%.0e", label="$f(z, v_y)$" + ) ax1.set_xlabel("$x/l_i$") ax1.set_ylabel("$v_{y}/v_A$") ax1.set_title(f"Ion beam R instability - {resonant_str} case") - plt.savefig(f"diags/ion_beam_R_instability_{resonant_str}_eta_{sim.eta}_substeps_{sim.substeps}_beam_phase_space.png") + plt.savefig( + f"diags/ion_beam_R_instability_{resonant_str}_eta_{sim.eta}_substeps_{sim.substeps}_beam_phase_space.png" + ) plt.show() if sim.test: - # physics based check - these error tolerances are not set from theory # but from the errors that were present when the test was created. If these # assert's fail, the full benchmark should be rerun (same as the test but @@ -199,7 +234,8 @@ # checksum check import os import sys - sys.path.insert(1, '../../../../warpx/Regression/Checksum/') + + sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file diff --git a/Examples/Tests/ohm_solver_ion_beam_instability/PICMI_inputs.py b/Examples/Tests/ohm_solver_ion_beam_instability/inputs_test_1d_ohm_solver_ion_beam_picmi.py similarity index 75% rename from Examples/Tests/ohm_solver_ion_beam_instability/PICMI_inputs.py rename to Examples/Tests/ohm_solver_ion_beam_instability/inputs_test_1d_ohm_solver_ion_beam_picmi.py index 4f8b5edcc3e..19569a04e5b 100644 --- a/Examples/Tests/ohm_solver_ion_beam_instability/PICMI_inputs.py +++ b/Examples/Tests/ohm_solver_ion_beam_instability/inputs_test_1d_ohm_solver_ion_beam_picmi.py @@ -21,35 +21,33 @@ comm = mpi.COMM_WORLD -simulation = picmi.Simulation( - warpx_serialize_initial_conditions=True, - verbose=0 -) +simulation = picmi.Simulation(warpx_serialize_initial_conditions=True, verbose=0) class HybridPICBeamInstability(object): - '''This input is based on the ion beam R instability test as described by + """This input is based on the ion beam R instability test as described by Munoz et al. (2018). - ''' + """ + # Applied field parameters - B0 = 0.25 # Initial magnetic field strength (T) - beta = 1.0 # Plasma beta, used to calculate temperature + B0 = 0.25 # Initial magnetic field strength (T) + beta = 1.0 # Plasma beta, used to calculate temperature # Plasma species parameters - m_ion = 100.0 # Ion mass (electron masses) - vA_over_c = 1e-4 # ratio of Alfven speed and the speed of light + m_ion = 100.0 # Ion mass (electron masses) + vA_over_c = 1e-4 # ratio of Alfven speed and the speed of light # Spatial domain - Nz = 1024 # number of cells in z direction - Nx = 8 # number of cells in x (and y) direction for >1 dimensions + Nz = 1024 # number of cells in z direction + Nx = 8 # number of cells in x (and y) direction for >1 dimensions # Temporal domain (if not run as a CI test) - LT = 120.0 # Simulation temporal length (ion cyclotron periods) + LT = 120.0 # Simulation temporal length (ion cyclotron periods) # Numerical parameters - NPPC = [1024, 256, 64] # Seed number of particles per cell - DZ = 1.0 / 4.0 # Cell size (ion skin depths) - DT = 0.01 # Time step (ion cyclotron periods) + NPPC = [1024, 256, 64] # Seed number of particles per cell + DZ = 1.0 / 4.0 # Cell size (ion skin depths) + DT = 0.01 # Time step (ion cyclotron periods) # Plasma resistivity - used to dampen the mode excitation eta = 1e-7 @@ -58,7 +56,7 @@ class HybridPICBeamInstability(object): # Beam parameters n_beam = [0.02, 0.1] - U_bc = 10.0 # relative drifts between beam and core in Alfven speeds + U_bc = 10.0 # relative drifts between beam and core in Alfven speeds def __init__(self, test, dim, resonant, verbose): """Get input parameters for the specific case desired.""" @@ -68,7 +66,7 @@ def __init__(self, test, dim, resonant, verbose): self.verbose = verbose or self.test # sanity check - assert (dim > 0 and dim < 4), f"{dim}-dimensions not a valid input" + assert dim > 0 and dim < 4, f"{dim}-dimensions not a valid input" # calculate various plasma parameters based on the simulation input self.get_plasma_quantities() @@ -92,7 +90,7 @@ def __init__(self, test, dim, resonant, verbose): self.volume = self.Lz self.N_cells = self.Nz - diag_period = 1 / 4.0 # Output interval (ion cyclotron periods) + diag_period = 1 / 4.0 # Output interval (ion cyclotron periods) self.diag_steps = int(diag_period / self.DT) # if this is a test case run for only 25 cyclotron periods @@ -105,7 +103,7 @@ def __init__(self, test, dim, resonant, verbose): # dump all the current attributes to a dill pickle file if comm.rank == 0: - with open('sim_parameters.dpkl', 'wb') as f: + with open("sim_parameters.dpkl", "wb") as f: dill.dump(self, f) # print out plasma parameters @@ -145,14 +143,12 @@ def get_plasma_quantities(self): # Alfven speed (m/s): vA = B / sqrt(mu0 * n * (M + m)) = c * omega_ci / w_pi self.vA = self.vA_over_c * constants.c - self.n_plasma = ( - (self.B0 / self.vA)**2 / (constants.mu0 * (self.M + constants.m_e)) + self.n_plasma = (self.B0 / self.vA) ** 2 / ( + constants.mu0 * (self.M + constants.m_e) ) # Ion plasma frequency (Hz) - self.w_pi = np.sqrt( - constants.q_e**2 * self.n_plasma / (self.M * constants.ep0) - ) + self.w_pi = np.sqrt(constants.q_e**2 * self.n_plasma / (self.M * constants.ep0)) # Skin depth (m) self.l_i = constants.c / self.w_pi @@ -161,7 +157,7 @@ def get_plasma_quantities(self): self.v_ti = np.sqrt(self.beta / 2.0) * self.vA # Temperature (eV) from thermal speed: v_ti = sqrt(kT / M) - self.T_plasma = self.v_ti**2 * self.M / constants.q_e # eV + self.T_plasma = self.v_ti**2 * self.M / constants.q_e # eV # Larmor radius (m) self.rho_i = self.v_ti / self.w_ci @@ -181,16 +177,16 @@ def setup_run(self): grid_object = picmi.Cartesian3DGrid self.grid = grid_object( - number_of_cells=[self.Nx, self.Nx, self.Nz][-self.dim:], + number_of_cells=[self.Nx, self.Nx, self.Nz][-self.dim :], warpx_max_grid_size=self.Nz, - lower_bound=[-self.Lx/2.0, -self.Lx/2.0, 0][-self.dim:], - upper_bound=[self.Lx/2.0, self.Lx/2.0, self.Lz][-self.dim:], - lower_boundary_conditions=['periodic']*self.dim, - upper_boundary_conditions=['periodic']*self.dim + lower_bound=[-self.Lx / 2.0, -self.Lx / 2.0, 0][-self.dim :], + upper_bound=[self.Lx / 2.0, self.Lx / 2.0, self.Lz][-self.dim :], + lower_boundary_conditions=["periodic"] * self.dim, + upper_boundary_conditions=["periodic"] * self.dim, ) simulation.time_step_size = self.dt simulation.max_steps = self.total_steps - simulation.current_deposition_algo = 'direct' + simulation.current_deposition_algo = "direct" simulation.particle_shape = 1 simulation.verbose = self.verbose @@ -199,17 +195,17 @@ def setup_run(self): ####################################################################### self.solver = picmi.HybridPICSolver( - grid=self.grid, gamma=1.0, - Te=self.T_plasma/10.0, - n0=self.n_plasma+self.n_beam, - plasma_resistivity=self.eta, substeps=self.substeps + grid=self.grid, + gamma=1.0, + Te=self.T_plasma / 10.0, + n0=self.n_plasma + self.n_beam, + plasma_resistivity=self.eta, + substeps=self.substeps, ) simulation.solver = self.solver B_ext = picmi.AnalyticInitialField( - Bx_expression=0.0, - By_expression=0.0, - Bz_expression=self.B0 + Bx_expression=0.0, By_expression=0.0, Bz_expression=self.B0 ) simulation.add_applied_field(B_ext) @@ -218,33 +214,36 @@ def setup_run(self): ####################################################################### self.ions = picmi.Species( - name='ions', charge='q_e', mass=self.M, + name="ions", + charge="q_e", + mass=self.M, initial_distribution=picmi.UniformDistribution( density=self.n_plasma, - rms_velocity=[self.v_ti]*3, - directed_velocity=[0, 0, self.u_c] - ) + rms_velocity=[self.v_ti] * 3, + directed_velocity=[0, 0, self.u_c], + ), ) simulation.add_species( self.ions, layout=picmi.PseudoRandomLayout( - grid=self.grid, n_macroparticles_per_cell=self.NPPC[self.dim-1] - ) + grid=self.grid, n_macroparticles_per_cell=self.NPPC[self.dim - 1] + ), ) self.beam_ions = picmi.Species( - name='beam_ions', charge='q_e', mass=self.M, + name="beam_ions", + charge="q_e", + mass=self.M, initial_distribution=picmi.UniformDistribution( density=self.n_beam, - rms_velocity=[self.v_ti]*3, - directed_velocity=[0, 0, self.u_beam] - ) + rms_velocity=[self.v_ti] * 3, + directed_velocity=[0, 0, self.u_beam], + ), ) simulation.add_species( self.beam_ions, layout=picmi.PseudoRandomLayout( - grid=self.grid, - n_macroparticles_per_cell=self.NPPC[self.dim-1]/2 - ) + grid=self.grid, n_macroparticles_per_cell=self.NPPC[self.dim - 1] / 2 + ), ) ####################################################################### @@ -256,48 +255,44 @@ def setup_run(self): if self.test: part_diag = picmi.ParticleDiagnostic( - name='diag1', + name="diag1", period=1250, species=[self.ions, self.beam_ions], - data_list = ['ux', 'uy', 'uz', 'z', 'weighting'], - write_dir='.', - warpx_file_prefix='Python_ohms_law_solver_ion_beam_1d_plt', + data_list=["ux", "uy", "uz", "z", "weighting"], ) simulation.add_diagnostic(part_diag) field_diag = picmi.FieldDiagnostic( - name='diag1', + name="diag1", grid=self.grid, period=1250, - data_list = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], - write_dir='.', - warpx_file_prefix='Python_ohms_law_solver_ion_beam_1d_plt', + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez", "Jx", "Jy", "Jz"], ) simulation.add_diagnostic(field_diag) # output the full particle data at t*w_ci = 40 step = int(40.0 / self.DT) parts_diag = picmi.ParticleDiagnostic( - name='parts_diag', + name="parts_diag", period=f"{step}:{step}", species=[self.ions, self.beam_ions], - write_dir='diags', - warpx_file_prefix='Python_hybrid_PIC_plt', - warpx_format = 'openpmd', - warpx_openpmd_backend = 'h5' + write_dir="diags", + warpx_file_prefix="Python_hybrid_PIC_plt", + warpx_format="openpmd", + warpx_openpmd_backend="h5", ) simulation.add_diagnostic(parts_diag) - self.output_file_name = 'field_data.txt' + self.output_file_name = "field_data.txt" if self.dim == 1: line_diag = picmi.ReducedDiagnostic( - diag_type='FieldProbe', - probe_geometry='Line', + diag_type="FieldProbe", + probe_geometry="Line", z_probe=0, z1_probe=self.Lz, resolution=self.Nz - 1, name=self.output_file_name[:-4], period=self.diag_steps, - path='diags/' + path="diags/", ) simulation.add_diagnostic(line_diag) else: @@ -308,10 +303,9 @@ def setup_run(self): except OSError: # diags directory already exists pass - with open(f"diags/{self.output_file_name}", 'w') as f: + with open(f"diags/{self.output_file_name}", "w") as f: f.write("[0]step() [1]time(s) [2]z_coord(m) [3]By_lev0-(T)\n") - ####################################################################### # Initialize simulation # ####################################################################### @@ -335,7 +329,7 @@ def _create_data_arrays(self): if libwarpx.amr.ParallelDescriptor.MyProc() == 0: # allocate arrays for storing energy values - self.energy_vals = np.zeros((self.total_steps//self.diag_steps, 4)) + self.energy_vals = np.zeros((self.total_steps // self.diag_steps, 4)) def text_diag(self): """Diagnostic function to print out timing data and particle numbers.""" @@ -352,13 +346,13 @@ def text_diag(self): step_rate = steps / wall_time status_dict = { - 'step': step, - 'nplive beam ions': self.ion_container_wrapper.nps, - 'nplive ions': self.beam_ion_container_wrapper.nps, - 'wall_time': wall_time, - 'step_rate': step_rate, + "step": step, + "nplive beam ions": self.ion_container_wrapper.nps, + "nplive ions": self.beam_ion_container_wrapper.nps, + "wall_time": wall_time, + "step_rate": step_rate, "diag_steps": self.diag_steps, - 'iproc': None + "iproc": None, } diag_string = ( @@ -401,7 +395,7 @@ def energy_diagnostic(self): self.energy_vals[idx, 3] = Eb_perp if step == self.total_steps: - np.save('diags/energies.npy', run.energy_vals) + np.save("diags/energies.npy", run.energy_vals) def _get_kinetic_energy(self, container_wrapper): """Utility function to retrieve the total kinetic energy in the @@ -445,11 +439,9 @@ def _record_average_fields(self): else: By = np.mean(By_warpx[:-1], axis=(0, 1)) - with open(f"diags/{self.output_file_name}", 'a') as f: + with open(f"diags/{self.output_file_name}", "a") as f: for ii in range(self.Nz): - f.write( - f"{step:05d} {t:.10e} {z_vals[ii]:.10e} {By[ii]:+.10e}\n" - ) + f.write(f"{step:05d} {t:.10e} {z_vals[ii]:.10e} {By[ii]:+.10e}\n") ########################## @@ -458,22 +450,29 @@ def _record_average_fields(self): parser = argparse.ArgumentParser() parser.add_argument( - '-t', '--test', help='toggle whether this script is run as a short CI test', - action='store_true', + "-t", + "--test", + help="toggle whether this script is run as a short CI test", + action="store_true", ) parser.add_argument( - '-d', '--dim', help='Simulation dimension', required=False, type=int, - default=1 + "-d", "--dim", help="Simulation dimension", required=False, type=int, default=1 ) parser.add_argument( - '-r', '--resonant', help='Run the resonant case', required=False, - action='store_true', + "-r", + "--resonant", + help="Run the resonant case", + required=False, + action="store_true", ) parser.add_argument( - '-v', '--verbose', help='Verbose output', action='store_true', + "-v", + "--verbose", + help="Verbose output", + action="store_true", ) args, left = parser.parse_known_args() -sys.argv = sys.argv[:1]+left +sys.argv = sys.argv[:1] + left run = HybridPICBeamInstability( test=args.test, dim=args.dim, resonant=args.resonant, verbose=args.verbose diff --git a/Examples/Tests/ohm_solver_magnetic_reconnection/CMakeLists.txt b/Examples/Tests/ohm_solver_magnetic_reconnection/CMakeLists.txt new file mode 100644 index 00000000000..cef47a7d95e --- /dev/null +++ b/Examples/Tests/ohm_solver_magnetic_reconnection/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_ohm_solver_magnetic_reconnection_picmi # name + 2 # dims + 2 # nprocs + "inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py --test" # inputs + analysis.py # analysis + diags/diag1000020 # output + OFF # dependency +) diff --git a/Examples/Tests/ohm_solver_magnetic_reconnection/README.rst b/Examples/Tests/ohm_solver_magnetic_reconnection/README.rst index 943b5bd0248..5181a6381d8 100644 --- a/Examples/Tests/ohm_solver_magnetic_reconnection/README.rst +++ b/Examples/Tests/ohm_solver_magnetic_reconnection/README.rst @@ -12,11 +12,11 @@ Run The following **Python** script configures and launches the simulation. -.. dropdown:: Script ``PICMI_inputs.py`` +.. dropdown:: Script ``inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py`` - .. literalinclude:: PICMI_inputs.py + .. literalinclude:: inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py :language: python3 - :caption: You can copy this file from ``Examples/Tests/ohm_solver_magnetic_reconnection/PICMI_inputs.py``. + :caption: You can copy this file from ``Examples/Tests/ohm_solver_magnetic_reconnection/inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py``. Running the full simulation should take about 4 hours if executed on 1 V100 GPU. For `MPI-parallel `__ runs, prefix these lines with @@ -24,7 +24,7 @@ For `MPI-parallel `__ runs, prefix these lines with .. code-block:: bash - python3 PICMI_inputs.py + python3 inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py Analyze ------- diff --git a/Examples/Tests/ohm_solver_magnetic_reconnection/analysis.py b/Examples/Tests/ohm_solver_magnetic_reconnection/analysis.py index 0fb1c05ae1a..93d574e5294 100755 --- a/Examples/Tests/ohm_solver_magnetic_reconnection/analysis.py +++ b/Examples/Tests/ohm_solver_magnetic_reconnection/analysis.py @@ -9,10 +9,10 @@ import numpy as np from matplotlib import colors -plt.rcParams.update({'font.size': 20}) +plt.rcParams.update({"font.size": 20}) # load simulation parameters -with open(f'sim_parameters.dpkl', 'rb') as f: +with open("sim_parameters.dpkl", "rb") as f: sim = dill.load(f) x_idx = 2 @@ -20,11 +20,11 @@ Ey_idx = 6 Bx_idx = 8 -plane_data = np.loadtxt(f'diags/plane.dat', skiprows=1) +plane_data = np.loadtxt("diags/plane.dat", skiprows=1) -steps = np.unique(plane_data[:,0]) +steps = np.unique(plane_data[:, 0]) num_steps = len(steps) -num_cells = plane_data.shape[0]//num_steps +num_cells = plane_data.shape[0] // num_steps plane_data = plane_data.reshape((num_steps, num_cells, plane_data.shape[1])) @@ -33,13 +33,13 @@ plt.plot( times / sim.t_ci, - np.mean(plane_data[:,:,Ey_idx], axis=1) / (sim.vA * sim.B0), - 'o-' + np.mean(plane_data[:, :, Ey_idx], axis=1) / (sim.vA * sim.B0), + "o-", ) plt.grid() -plt.xlabel(r'$t/\tau_{c,i}$') -plt.ylabel('$/v_AB_0$') +plt.xlabel(r"$t/\tau_{c,i}$") +plt.ylabel("$/v_AB_0$") plt.title("Reconnection rate") plt.tight_layout() plt.savefig("diags/reconnection_rate.png") @@ -52,10 +52,10 @@ fig, axes = plt.subplots(3, 1, sharex=True, figsize=(7, 9)) for ax in axes.flatten(): - ax.set_aspect('equal') - ax.set_ylabel('$z/l_i$') + ax.set_aspect("equal") + ax.set_ylabel("$z/l_i$") - axes[2].set_xlabel('$x/l_i$') + axes[2].set_xlabel("$x/l_i$") datafiles = sorted(glob.glob("diags/fields/*.npz")) num_steps = len(datafiles) @@ -63,47 +63,52 @@ data0 = np.load(datafiles[0]) sX = axes[0].imshow( - data0['Jy'].T, origin='lower', - norm=colors.TwoSlopeNorm(vmin=-0.6, vcenter=0., vmax=1.6), - extent=[0, sim.LX, -sim.LZ/2, sim.LZ/2], - cmap=plt.cm.RdYlBu_r + data0["Jy"].T, + origin="lower", + norm=colors.TwoSlopeNorm(vmin=-0.6, vcenter=0.0, vmax=1.6), + extent=[0, sim.LX, -sim.LZ / 2, sim.LZ / 2], + cmap=plt.cm.RdYlBu_r, ) # axes[0].set_ylim(-5, 5) - cb = plt.colorbar(sX, ax=axes[0], label='$J_y/J_0$') - cb.ax.set_yscale('linear') + cb = plt.colorbar(sX, ax=axes[0], label="$J_y/J_0$") + cb.ax.set_yscale("linear") cb.ax.set_yticks([-0.5, 0.0, 0.75, 1.5]) sY = axes[1].imshow( - data0['By'].T, origin='lower', extent=[0, sim.LX, -sim.LZ/2, sim.LZ/2], - cmap=plt.cm.plasma + data0["By"].T, + origin="lower", + extent=[0, sim.LX, -sim.LZ / 2, sim.LZ / 2], + cmap=plt.cm.plasma, ) # axes[1].set_ylim(-5, 5) - cb = plt.colorbar(sY, ax=axes[1], label='$B_y/B_0$') - cb.ax.set_yscale('linear') + cb = plt.colorbar(sY, ax=axes[1], label="$B_y/B_0$") + cb.ax.set_yscale("linear") sZ = axes[2].imshow( - data0['Bz'].T, origin='lower', extent=[0, sim.LX, -sim.LZ/2, sim.LZ/2], + data0["Bz"].T, + origin="lower", + extent=[0, sim.LX, -sim.LZ / 2, sim.LZ / 2], # norm=colors.TwoSlopeNorm(vmin=-0.02, vcenter=0., vmax=0.02), - cmap=plt.cm.RdBu + cmap=plt.cm.RdBu, ) - cb = plt.colorbar(sZ, ax=axes[2], label='$B_z/B_0$') - cb.ax.set_yscale('linear') + cb = plt.colorbar(sZ, ax=axes[2], label="$B_z/B_0$") + cb.ax.set_yscale("linear") # plot field lines - x_grid = np.linspace(0, sim.LX, data0['Bx'][:-1].shape[0]) - z_grid = np.linspace(-sim.LZ/2.0, sim.LZ/2.0, data0['Bx'].shape[1]) + x_grid = np.linspace(0, sim.LX, data0["Bx"][:-1].shape[0]) + z_grid = np.linspace(-sim.LZ / 2.0, sim.LZ / 2.0, data0["Bx"].shape[1]) n_lines = 10 start_x = np.zeros(n_lines) - start_x[:n_lines//2] = sim.LX - start_z = np.linspace(-sim.LZ/2.0*0.9, sim.LZ/2.0*0.9, n_lines) + start_x[: n_lines // 2] = sim.LX + start_z = np.linspace(-sim.LZ / 2.0 * 0.9, sim.LZ / 2.0 * 0.9, n_lines) step_size = 1.0 / 100.0 def get_field_lines(Bx, Bz): field_line_coords = [] Bx_interp = interpolate.interp2d(x_grid, z_grid, Bx[:-1].T) - Bz_interp = interpolate.interp2d(x_grid, z_grid, Bz[:,:-1].T) + Bz_interp = interpolate.interp2d(x_grid, z_grid, Bz[:, :-1].T) for kk, z in enumerate(start_z): path_x = [start_x[kk]] @@ -111,7 +116,7 @@ def get_field_lines(Bx, Bz): ii = 0 while ii < 10000: - ii+=1 + ii += 1 Bx = Bx_interp(path_x[-1], path_z[-1])[0] Bz = Bz_interp(path_x[-1], path_z[-1])[0] @@ -128,7 +133,12 @@ def get_field_lines(Bx, Bz): x_new = path_x[-1] + dx z_new = path_z[-1] + dz - if np.isnan(x_new) or x_new <= 0 or x_new > sim.LX or abs(z_new) > sim.LZ/2: + if ( + np.isnan(x_new) + or x_new <= 0 + or x_new > sim.LX + or abs(z_new) > sim.LZ / 2 + ): break path_x.append(x_new) @@ -138,44 +148,48 @@ def get_field_lines(Bx, Bz): return field_line_coords field_lines = [] - for path in get_field_lines(data0['Bx'], data0['Bz']): + for path in get_field_lines(data0["Bx"], data0["Bz"]): path_x = path[0] path_z = path[1] - l, = axes[2].plot(path_x, path_z, '--', color='k') + (ln,) = axes[2].plot(path_x, path_z, "--", color="k") # draws arrows on the field lines # if path_x[10] > path_x[0]: axes[2].arrow( - path_x[50], path_z[50], - path_x[250]-path_x[50], path_z[250]-path_z[50], - shape='full', length_includes_head=True, lw=0, head_width=1.0, - color='g' + path_x[50], + path_z[50], + path_x[250] - path_x[50], + path_z[250] - path_z[50], + shape="full", + length_includes_head=True, + lw=0, + head_width=1.0, + color="g", ) - field_lines.append(l) + field_lines.append(ln) def animate(i): data = np.load(datafiles[i]) - sX.set_array(data['Jy'].T) - sY.set_array(data['By'].T) - sZ.set_array(data['Bz'].T) - sZ.set_clim(-np.max(abs(data['Bz'])), np.max(abs(data['Bz']))) + sX.set_array(data["Jy"].T) + sY.set_array(data["By"].T) + sZ.set_array(data["Bz"].T) + sZ.set_clim(-np.max(abs(data["Bz"])), np.max(abs(data["Bz"]))) - for ii, path in enumerate(get_field_lines(data['Bx'], data['Bz'])): + for ii, path in enumerate(get_field_lines(data["Bx"], data["Bz"])): path_x = path[0] path_z = path[1] field_lines[ii].set_data(path_x, path_z) - anim = FuncAnimation( - fig, animate, frames=num_steps-1, repeat=True - ) + anim = FuncAnimation(fig, animate, frames=num_steps - 1, repeat=True) writervideo = FFMpegWriter(fps=14) - anim.save('diags/mag_reconnection.mp4', writer=writervideo) + anim.save("diags/mag_reconnection.mp4", writer=writervideo) if sim.test: import os import sys - sys.path.insert(1, '../../../../warpx/Regression/Checksum/') + + sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file diff --git a/Examples/Tests/ohm_solver_magnetic_reconnection/PICMI_inputs.py b/Examples/Tests/ohm_solver_magnetic_reconnection/inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py similarity index 75% rename from Examples/Tests/ohm_solver_magnetic_reconnection/PICMI_inputs.py rename to Examples/Tests/ohm_solver_magnetic_reconnection/inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py index 56173893b7f..4f13c76e208 100644 --- a/Examples/Tests/ohm_solver_magnetic_reconnection/PICMI_inputs.py +++ b/Examples/Tests/ohm_solver_magnetic_reconnection/inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py @@ -22,32 +22,28 @@ comm = mpi.COMM_WORLD -simulation = picmi.Simulation( - warpx_serialize_initial_conditions=True, - verbose=0 -) +simulation = picmi.Simulation(warpx_serialize_initial_conditions=True, verbose=0) class ForceFreeSheetReconnection(object): - # B0 is chosen with all other quantities scaled by it - B0 = 0.1 # Initial magnetic field strength (T) + B0 = 0.1 # Initial magnetic field strength (T) # Physical parameters - m_ion = 400.0 # Ion mass (electron masses) + m_ion = 400.0 # Ion mass (electron masses) beta_e = 0.1 - Bg = 0.3 # times B0 - guiding field - dB = 0.01 # times B0 - initial perturbation to seed reconnection + Bg = 0.3 # times B0 - guiding field + dB = 0.01 # times B0 - initial perturbation to seed reconnection - T_ratio = 5.0 # T_i / T_e + T_ratio = 5.0 # T_i / T_e # Domain parameters - LX = 40 # ion skin depths - LZ = 20 # ion skin depths + LX = 40 # ion skin depths + LZ = 20 # ion skin depths - LT = 50 # ion cyclotron periods - DT = 1e-3 # ion cyclotron periods + LT = 50 # ion cyclotron periods + DT = 1e-3 # ion cyclotron periods # Resolution parameters NX = 512 @@ -62,7 +58,6 @@ class ForceFreeSheetReconnection(object): substeps = 20 def __init__(self, test, verbose): - self.test = test self.verbose = verbose or self.test @@ -93,8 +88,7 @@ def __init__(self, test, verbose): f"*sin({np.pi/self.Lz}*z)" ) self.By = ( - f"sqrt({self.Bg**2 + self.B0**2}-" - f"({self.B0}*tanh(z*{1.0/self.l_i}))**2)" + f"sqrt({self.Bg**2 + self.B0**2}-" f"({self.B0}*tanh(z*{1.0/self.l_i}))**2)" ) self.Bz = f"{self.dB}*sin({2.0*np.pi/self.Lx}*x)*cos({np.pi/self.Lz}*z)" @@ -102,7 +96,7 @@ def __init__(self, test, verbose): # dump all the current attributes to a dill pickle file if comm.rank == 0: - with open(f'sim_parameters.dpkl', 'wb') as f: + with open("sim_parameters.dpkl", "wb") as f: dill.dump(self, f) # print out plasma parameters @@ -146,14 +140,10 @@ def get_plasma_quantities(self): self.w_pe = 2.0 * self.w_ce # calculate plasma density based on electron plasma frequency - self.n_plasma = ( - self.w_pe**2 * constants.m_e * constants.ep0 / constants.q_e**2 - ) + self.n_plasma = self.w_pe**2 * constants.m_e * constants.ep0 / constants.q_e**2 # Ion plasma frequency (Hz) - self.w_pi = np.sqrt( - constants.q_e**2 * self.n_plasma / (self.M * constants.ep0) - ) + self.w_pi = np.sqrt(constants.q_e**2 * self.n_plasma / (self.M * constants.ep0)) # Ion skin depth (m) self.l_i = constants.c / self.w_pi @@ -165,7 +155,9 @@ def get_plasma_quantities(self): # calculate Te based on beta self.Te = ( - self.beta_e * self.B0**2 / (2.0 * constants.mu0 * self.n_plasma) + self.beta_e + * self.B0**2 + / (2.0 * constants.mu0 * self.n_plasma) / constants.q_e ) self.Ti = self.Te * self.T_ratio @@ -190,17 +182,17 @@ def setup_run(self): # Create grid self.grid = picmi.Cartesian2DGrid( number_of_cells=[self.NX, self.NZ], - lower_bound=[-self.Lx/2.0, -self.Lz/2.0], - upper_bound=[self.Lx/2.0, self.Lz/2.0], - lower_boundary_conditions=['periodic', 'dirichlet'], - upper_boundary_conditions=['periodic', 'dirichlet'], - lower_boundary_conditions_particles=['periodic', 'reflecting'], - upper_boundary_conditions_particles=['periodic', 'reflecting'], - warpx_max_grid_size=self.NZ + lower_bound=[-self.Lx / 2.0, -self.Lz / 2.0], + upper_bound=[self.Lx / 2.0, self.Lz / 2.0], + lower_boundary_conditions=["periodic", "dirichlet"], + upper_boundary_conditions=["periodic", "dirichlet"], + lower_boundary_conditions_particles=["periodic", "reflecting"], + upper_boundary_conditions_particles=["periodic", "reflecting"], + warpx_max_grid_size=self.NZ, ) simulation.time_step_size = self.dt simulation.max_steps = self.total_steps - simulation.current_deposition_algo = 'direct' + simulation.current_deposition_algo = "direct" simulation.particle_shape = 1 simulation.use_filter = False simulation.verbose = self.verbose @@ -210,17 +202,18 @@ def setup_run(self): ####################################################################### self.solver = picmi.HybridPICSolver( - grid=self.grid, gamma=1.0, - Te=self.Te, n0=self.n_plasma, n_floor=0.1*self.n_plasma, - plasma_resistivity=self.eta*self.eta0, - substeps=self.substeps + grid=self.grid, + gamma=1.0, + Te=self.Te, + n0=self.n_plasma, + n_floor=0.1 * self.n_plasma, + plasma_resistivity=self.eta * self.eta0, + substeps=self.substeps, ) simulation.solver = self.solver B_ext = picmi.AnalyticInitialField( - Bx_expression=self.Bx, - By_expression=self.By, - Bz_expression=self.Bz + Bx_expression=self.Bx, By_expression=self.By, Bz_expression=self.Bz ) simulation.add_applied_field(B_ext) @@ -229,18 +222,19 @@ def setup_run(self): ####################################################################### self.ions = picmi.Species( - name='ions', charge='q_e', mass=self.M, + name="ions", + charge="q_e", + mass=self.M, initial_distribution=picmi.UniformDistribution( density=self.n_plasma, - rms_velocity=[self.vi_th]*3, - ) + rms_velocity=[self.vi_th] * 3, + ), ) simulation.add_species( self.ions, layout=picmi.PseudoRandomLayout( - grid=self.grid, - n_macroparticles_per_cell=self.NPPC - ) + grid=self.grid, n_macroparticles_per_cell=self.NPPC + ), ) ####################################################################### @@ -251,42 +245,40 @@ def setup_run(self): if self.test: particle_diag = picmi.ParticleDiagnostic( - name='diag1', + name="diag1", period=self.total_steps, - write_dir='.', species=[self.ions], - data_list=['ux', 'uy', 'uz', 'x', 'z', 'weighting'], - warpx_file_prefix='Python_ohms_law_solver_magnetic_reconnection_2d_plt', + data_list=["ux", "uy", "uz", "x", "z", "weighting"], # warpx_format='openpmd', # warpx_openpmd_backend='h5', ) simulation.add_diagnostic(particle_diag) field_diag = picmi.FieldDiagnostic( - name='diag1', + name="diag1", grid=self.grid, period=self.total_steps, - data_list=['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez'], - write_dir='.', - warpx_file_prefix='Python_ohms_law_solver_magnetic_reconnection_2d_plt', + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez"], # warpx_format='openpmd', # warpx_openpmd_backend='h5', ) simulation.add_diagnostic(field_diag) - # reduced diagnostics for reconnection rate calculation # create a 2 l_i box around the X-point on which to measure # magnetic flux changes plane = picmi.ReducedDiagnostic( diag_type="FieldProbe", - name='plane', + name="plane", period=self.diag_steps, - path='diags/', - extension='dat', - probe_geometry='Plane', + path="diags/", + extension="dat", + probe_geometry="Plane", resolution=60, - x_probe=0.0, z_probe=0.0, detector_radius=self.l_i, - target_up_x=0, target_up_z=1.0 + x_probe=0.0, + z_probe=0.0, + detector_radius=self.l_i, + target_up_x=0, + target_up_z=1.0, ) simulation.add_diagnostic(plane) @@ -304,13 +296,12 @@ def setup_run(self): simulation.initialize_warpx() def check_fields(self): - step = simulation.extension.warpx.getistep(lev=0) - 1 - if not (step == 1 or step%self.diag_steps == 0): + if not (step == 1 or step % self.diag_steps == 0): return - rho = fields.RhoFPWrapper(include_ghosts=False)[:,:] + rho = fields.RhoFPWrapper(include_ghosts=False)[:, :] Jiy = fields.JyFPWrapper(include_ghosts=False)[...] / self.J0 Jy = fields.JyFPAmpereWrapper(include_ghosts=False)[...] / self.J0 Bx = fields.BxFPWrapper(include_ghosts=False)[...] / self.B0 @@ -321,23 +312,29 @@ def check_fields(self): return # save the fields to file - with open(f"diags/fields/fields_{step:06d}.npz", 'wb') as f: + with open(f"diags/fields/fields_{step:06d}.npz", "wb") as f: np.savez(f, rho=rho, Jiy=Jiy, Jy=Jy, Bx=Bx, By=By, Bz=Bz) + ########################## # parse input parameters ########################## parser = argparse.ArgumentParser() parser.add_argument( - '-t', '--test', help='toggle whether this script is run as a short CI test', - action='store_true', + "-t", + "--test", + help="toggle whether this script is run as a short CI test", + action="store_true", ) parser.add_argument( - '-v', '--verbose', help='Verbose output', action='store_true', + "-v", + "--verbose", + help="Verbose output", + action="store_true", ) args, left = parser.parse_known_args() -sys.argv = sys.argv[:1]+left +sys.argv = sys.argv[:1] + left run = ForceFreeSheetReconnection(test=args.test, verbose=args.verbose) simulation.step() diff --git a/Examples/Tests/open_bc_poisson_solver/CMakeLists.txt b/Examples/Tests/open_bc_poisson_solver/CMakeLists.txt new file mode 100644 index 00000000000..c5ec4583da1 --- /dev/null +++ b/Examples/Tests/open_bc_poisson_solver/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_FFT) + add_warpx_test( + test_3d_open_bc_poisson_solver # name + 3 # dims + 2 # nprocs + inputs_test_3d_open_bc_poisson_solver # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/open_bc_poisson_solver/analysis.py b/Examples/Tests/open_bc_poisson_solver/analysis.py new file mode 100755 index 00000000000..8d5be875c7a --- /dev/null +++ b/Examples/Tests/open_bc_poisson_solver/analysis.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +import os +import sys + +import numpy as np +from openpmd_viewer import OpenPMDTimeSeries +from scipy.constants import epsilon_0, pi +from scipy.special import erf + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +sigmaz = 300e-6 +sigmax = 516e-9 +sigmay = 7.7e-9 +Q = -3.2e-9 + + +def w(z): + return np.exp(-(z**2)) * (1 + erf(1.0j * z)) + + +def evaluate_E(x, y, z): + """Basseti-Erskine formula https://cds.cern.ch/record/122227/files/198005132.pdf""" + den = np.sqrt(2 * (sigmax**2 - sigmay**2)) + arg1 = (x + 1j * y) / den + term1 = w(arg1) + arg2 = (x * sigmay / sigmax + 1j * y * sigmax / sigmay) / den + term2 = -np.exp(-(x**2) / (2 * sigmax**2) - y**2 / (2 * sigmay**2)) * w(arg2) + factor = ( + Q + / (2.0 * np.sqrt(2.0) * pi * epsilon_0 * sigmaz * den) + * np.exp(-(z**2) / (2 * sigmaz**2)) + ) + E_complex = factor * (term1 + term2) + return E_complex.imag, E_complex.real + + +fn = sys.argv[1] + +path = os.path.join("diags", "diag2") +ts = OpenPMDTimeSeries(path) + +Ex, info = ts.get_field(field="E", coord="x", iteration=0, plot=False) +Ey, info = ts.get_field(field="E", coord="y", iteration=0, plot=False) + +grid_x = info.x[1:-1] +grid_y = info.y[1:-1] +grid_z = info.z[1:-1] + +hnx = int(0.5 * len(grid_x)) +hny = int(0.5 * len(grid_y)) + +# Compare theoretical and WarpX Ex, Ey fields for every z +for k, z in enumerate(grid_z, start=1): + Ex_warpx = Ex[k, hny, 1:-1] + Ey_warpx = Ey[k, 1:-1, hnx] + + Ex_theory = evaluate_E(grid_x, 0.0, z)[0] + Ey_theory = evaluate_E(0.0, grid_y, z)[1] + + assert np.allclose(Ex_warpx, Ex_theory, rtol=0.032, atol=0) + assert np.allclose(Ey_warpx, Ey_theory, rtol=0.029, atol=0) + + +# Get name of the test +test_name = os.path.split(os.getcwd())[1] + +# Run checksum regression test +checksumAPI.evaluate_checksum(test_name, fn, rtol=1e-2) diff --git a/Examples/Tests/openbc_poisson_solver/inputs_3d b/Examples/Tests/open_bc_poisson_solver/inputs_test_3d_open_bc_poisson_solver similarity index 100% rename from Examples/Tests/openbc_poisson_solver/inputs_3d rename to Examples/Tests/open_bc_poisson_solver/inputs_test_3d_open_bc_poisson_solver diff --git a/Examples/Tests/openbc_poisson_solver/analysis.py b/Examples/Tests/openbc_poisson_solver/analysis.py deleted file mode 100755 index dc7b5dca8bd..00000000000 --- a/Examples/Tests/openbc_poisson_solver/analysis.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -import numpy as np -from openpmd_viewer import OpenPMDTimeSeries -from scipy.constants import epsilon_0, pi -from scipy.special import erf - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -sigmaz = 300e-6 -sigmax = 516e-9 -sigmay = 7.7e-9 -Q = -3.2e-9 - -def w(z): - return np.exp(-z**2) * ( 1 + erf(1.j*z) ) - -def evaluate_E(x, y, z): - ''' Basseti-Erskine formula https://cds.cern.ch/record/122227/files/198005132.pdf ''' - den = np.sqrt(2*(sigmax**2-sigmay**2)) - arg1 = (x+1j*y)/den - term1 = w(arg1) - arg2 = (x*sigmay/sigmax + 1j*y*sigmax/sigmay)/den - term2 = -np.exp(-x**2/(2*sigmax**2)-y**2/(2*sigmay**2))*w(arg2) - factor = Q/(2.*np.sqrt(2.)*pi*epsilon_0*sigmaz*den)*np.exp(-z**2/(2*sigmaz**2)) - E_complex = factor*(term1 + term2) - return E_complex.imag, E_complex.real - - -fn = sys.argv[1] - -path=os.path.join('diags', 'diag2') -ts = OpenPMDTimeSeries(path) - -Ex, info = ts.get_field(field='E', coord='x', iteration=0, plot=False) -Ey, info = ts.get_field(field='E', coord='y', iteration=0, plot=False) - -grid_x = info.x[1:-1] -grid_y = info.y[1:-1] -grid_z = info.z[1:-1] - -hnx = int(0.5*len(grid_x)) -hny = int(0.5*len(grid_y)) - -# Compare theoretical and WarpX Ex, Ey fields for every z -for k, z in enumerate(grid_z,start=1): - Ex_warpx = Ex[k,hny,1:-1] - Ey_warpx = Ey[k,1:-1,hnx] - - Ex_theory = evaluate_E(grid_x, 0., z)[0] - Ey_theory = evaluate_E(0., grid_y, z)[1] - - assert(np.allclose(Ex_warpx, Ex_theory, rtol=0.032, atol=0)) - assert(np.allclose(Ey_warpx, Ey_theory, rtol=0.029, atol=0)) - - -# Get name of the test -test_name = os.path.split(os.getcwd())[1] - -# Run checksum regression test -checksumAPI.evaluate_checksum(test_name, fn, rtol=1e-2) diff --git a/Examples/Tests/openpmd_rz/analysis_openpmd_rz.py b/Examples/Tests/openpmd_rz/analysis_openpmd_rz.py deleted file mode 100755 index 247c4ac61a0..00000000000 --- a/Examples/Tests/openpmd_rz/analysis_openpmd_rz.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 - -import numpy as np -import openpmd_api as io - -series = io.Series("LaserAccelerationRZ_opmd_plt/openpmd_%T.h5", io.Access.read_only) - -assert len(series.iterations) == 3, 'improper number of iterations stored' - -ii = series.iterations[20] - -assert len(ii.meshes) == 8, 'improper number of meshes' - -# select j_t -jt = ii.meshes['j']['t'] - -# this is in C (Python) order; r is the fastest varying index -(Nm, Nz, Nr) = jt.shape - -assert Nm == 3, 'Wrong number of angular modes stored or possible incorrect ordering when flushed' -assert Nr == 64, 'Wrong number of radial points stored or possible incorrect ordering when flushed' -assert Nz == 512, 'Wrong number of z points stored or possible incorrect ordering when flushed' - -assert ii.meshes['part_per_grid'][io.Mesh_Record_Component.SCALAR].shape == [512,64], 'problem with part_per_grid' -assert ii.meshes['rho_electrons'][io.Mesh_Record_Component.SCALAR].shape == [3, 512, 64], 'problem with rho_electrons' - - -### test that openpmd+RZ -### 1. creates rho per species correctly -### 2. orders these appropriately -rhoe_mesh = ii.meshes['rho_electrons'] -rhob_mesh = ii.meshes['rho_beam'] -dz, dr = rhoe_mesh.grid_spacing -zmin, rmin = rhoe_mesh.grid_global_offset - -rhoe = rhoe_mesh[io.Mesh_Record_Component.SCALAR][:] -rhob = rhob_mesh[io.Mesh_Record_Component.SCALAR][:] -series.flush() -nm, nz, nr = rhoe.shape -zlist = zmin + dz * np.arange(nz) -rhoe0 = rhoe[0] # 0 mode -rhob0 = rhob[0] # 0 mode - -electron_meanz = np.sum(np.dot(zlist, rhoe0))/ np.sum(rhoe0) -beam_meanz = np.sum(np.dot(zlist, rhob0))/ np.sum(rhob0) - -assert ((electron_meanz > 0) and (beam_meanz < 0)), 'problem with openPMD+RZ. Maybe openPMD+RZ mixed up the order of rho_ diagnostics?' diff --git a/Examples/Tests/particle_boundary_interaction/CMakeLists.txt b/Examples/Tests/particle_boundary_interaction/CMakeLists.txt new file mode 100644 index 00000000000..5bbb34c0d95 --- /dev/null +++ b/Examples/Tests/particle_boundary_interaction/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_rz_particle_boundary_interaction_picmi # name + RZ # dims + 2 # nprocs + inputs_test_rz_particle_boundary_interaction_picmi.py # inputs + analysis.py # analysis + diags/diag1/ # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/particle_boundary_interaction/PICMI_inputs_rz.py b/Examples/Tests/particle_boundary_interaction/PICMI_inputs_rz.py deleted file mode 100644 index df4a4579e2f..00000000000 --- a/Examples/Tests/particle_boundary_interaction/PICMI_inputs_rz.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env python3 -# @Eya Dammak supervised by @Remi Lehe, 2024 -# --- Input file for particle-boundary interaction testing in RZ. -# --- This input is a simple case of reflection -# --- of one electron on the surface of a sphere. -import numpy as np - -from pywarpx import callbacks, particle_containers, picmi - -########################## -# numerics parameters -########################## - -dt = 1.0e-11 - -# --- Nb time steps - -max_steps = 23 -diagnostic_interval = 1 - -# --- grid - -nr = 64 -nz= 64 - -rmin = 0.0 -rmax = 2 -zmin = -2 -zmax = 2 - -########################## -# numerics components -########################## - -grid = picmi.CylindricalGrid( - number_of_cells = [nr, nz], - n_azimuthal_modes = 1, - lower_bound = [rmin, zmin], - upper_bound = [rmax, zmax], - lower_boundary_conditions = ['none', 'dirichlet'], - upper_boundary_conditions = ['dirichlet', 'dirichlet'], - lower_boundary_conditions_particles = ['none', 'reflecting'], - upper_boundary_conditions_particles = ['absorbing', 'reflecting'] -) - - -solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', - warpx_absolute_tolerance=1e-7 -) - -embedded_boundary = picmi.EmbeddedBoundary( - implicit_function="-(x**2+y**2+z**2-radius**2)", - radius = 0.2 -) - -########################## -# physics components -########################## - -#one particle -e_dist=picmi.ParticleListDistribution(x=0.0, y=0.0, z=-0.25, ux=0.5e10, uy=0.0, uz=1.0e10, weight=1) - -electrons = picmi.Species( - particle_type='electron', name='electrons', initial_distribution=e_dist, warpx_save_particles_at_eb=1 -) - -########################## -# diagnostics -########################## - -field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = diagnostic_interval, - data_list = ['Er', 'Ez', 'phi', 'rho','rho_electrons'], - warpx_format = 'openpmd', - write_dir = '.', - warpx_file_prefix = 'particle_boundary_interaction_plt' -) - -part_diag = picmi.ParticleDiagnostic(name = 'diag1', - period = diagnostic_interval, - species = [electrons], - warpx_format = 'openpmd', - write_dir = '.', - warpx_file_prefix = 'particle_boundary_interaction_plt' -) - -########################## -# simulation setup -########################## - -sim = picmi.Simulation( - solver=solver, - time_step_size = dt, - max_steps = max_steps, - warpx_embedded_boundary=embedded_boundary, - warpx_amrex_the_arena_is_managed=1, -) - -sim.add_species( - electrons, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[10, 1, 1], grid=grid - ) -) -sim.add_diagnostic(part_diag) -sim.add_diagnostic(field_diag) - -sim.initialize_inputs() -sim.initialize_warpx() - -########################## -# python particle data access -########################## - -def concat( list_of_arrays ): - if len(list_of_arrays) == 0: - # Return a 1d array of size 0 - return np.empty(0) - else: - return np.concatenate( list_of_arrays ) - - -def mirror_reflection(): - buffer = particle_containers.ParticleBoundaryBufferWrapper() #boundary buffer - - #STEP 1: extract the different parameters of the boundary buffer (normal, time, position) - lev = 0 # level 0 (no mesh refinement here) - delta_t = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'deltaTimeScraped', lev)) - r = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'x', lev)) - theta = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'theta', lev)) - z = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'z', lev)) - x= r*np.cos(theta) #from RZ coordinates to 3D coordinates - y= r*np.sin(theta) - ux = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'ux', lev)) - uy = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'uy', lev)) - uz = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'uz', lev)) - w = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'w', lev)) - nx = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'nx', lev)) - ny = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'ny', lev)) - nz = concat(buffer.get_particle_boundary_buffer("electrons", 'eb', 'nz', lev)) - - #STEP 2: use these parameters to inject particle from the same position in the plasma - elect_pc = particle_containers.ParticleContainerWrapper('electrons') #general particle container - - ####this part is specific to the case of simple reflection. - un=ux*nx+uy*ny+uz*nz - ux_reflect=-2*un*nx+ux #for a "mirror reflection" u(sym)=-2(u.n)n+u - uy_reflect=-2*un*ny+uy - uz_reflect=-2*un*nz+uz - elect_pc.add_particles( - x=x + (dt-delta_t)*ux_reflect, y=y + (dt-delta_t)*uy_reflect, z=z + (dt-delta_t)*uz_reflect, - ux=ux_reflect, uy=uy_reflect, uz=uz_reflect, - w=w - ) #adds the particle in the general particle container at the next step - #### Can be modified depending on the model of interaction. - - buffer.clear_buffer() #reinitialise the boundary buffer - -callbacks.installafterstep(mirror_reflection) #mirror_reflection is called at the next step - # using the new particle container modified at the last step - -########################## -# simulation run -########################## - -sim.step(max_steps) #the whole process is done "max_steps" times diff --git a/Examples/Tests/particle_boundary_interaction/analysis.py b/Examples/Tests/particle_boundary_interaction/analysis.py index ff83cc1fed7..3b9d2f12b84 100755 --- a/Examples/Tests/particle_boundary_interaction/analysis.py +++ b/Examples/Tests/particle_boundary_interaction/analysis.py @@ -5,8 +5,9 @@ The sphere is centered on O and has a radius of 0.2 (EB) The electron is initially at: (0,0,-0.25) and moves with a velocity: (0.5e10,0,1.0e10) with a time step of 1e-11. -An input file PICMI_inputs_rz.py is used. +An input file inputs_test_rz_particle_boundary_interaction_picmi.py is used. """ + import os import sys @@ -15,37 +16,39 @@ from openpmd_viewer import OpenPMDTimeSeries yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Open plotfile specified in command line filename = sys.argv[1] test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename, output_format='openpmd') +checksumAPI.evaluate_checksum(test_name, filename, output_format="openpmd") -ts = OpenPMDTimeSeries('./particle_boundary_interaction_plt') +ts = OpenPMDTimeSeries(filename) -it=ts.iterations -x,y,z=ts.get_particle(['x','y','z'], species='electrons', iteration=it[-1]) +it = ts.iterations +x, y, z = ts.get_particle(["x", "y", "z"], species="electrons", iteration=it[-1]) # Analytical results calculated -x_analytic=0.03532 -y_analytic=0.00000 -z_analytic=-0.20531 +x_analytic = 0.03532 +y_analytic = 0.00000 +z_analytic = -0.20531 -print('NUMERICAL coordinates of the point of contact:') -print('x=%5.5f, y=%5.5f, z=%5.5f' % (x[0], y[0], z[0])) -print('\n') -print('ANALYTICAL coordinates of the point of contact:') -print('x=%5.5f, y=%5.5f, z=%5.5f' % (x_analytic, y_analytic, z_analytic)) +print("NUMERICAL coordinates of the point of contact:") +print("x=%5.5f, y=%5.5f, z=%5.5f" % (x[0], y[0], z[0])) +print("\n") +print("ANALYTICAL coordinates of the point of contact:") +print("x=%5.5f, y=%5.5f, z=%5.5f" % (x_analytic, y_analytic, z_analytic)) -tolerance=1e-5 +tolerance = 1e-5 -diff_x=np.abs((x[0]-x_analytic)/x_analytic) -diff_z=np.abs((z[0]-z_analytic)/z_analytic) +diff_x = np.abs((x[0] - x_analytic) / x_analytic) +diff_z = np.abs((z[0] - z_analytic) / z_analytic) -print('\n') -print("percentage error for x = %5.4f %%" %(diff_x *100)) -print("percentage error for z = %5.4f %%" %(diff_z *100)) +print("\n") +print("percentage error for x = %5.4f %%" % (diff_x * 100)) +print("percentage error for z = %5.4f %%" % (diff_z * 100)) -assert (diff_x < tolerance) and (y[0] < 1e-8) and (diff_z < tolerance), 'Test particle_boundary_interaction did not pass' +assert ( + (diff_x < tolerance) and (y[0] < 1e-8) and (diff_z < tolerance) +), "Test particle_boundary_interaction did not pass" diff --git a/Examples/Tests/particle_boundary_interaction/inputs_test_rz_particle_boundary_interaction_picmi.py b/Examples/Tests/particle_boundary_interaction/inputs_test_rz_particle_boundary_interaction_picmi.py new file mode 100644 index 00000000000..4b491ac6873 --- /dev/null +++ b/Examples/Tests/particle_boundary_interaction/inputs_test_rz_particle_boundary_interaction_picmi.py @@ -0,0 +1,179 @@ +#!/usr/bin/env python3 +# @Eya Dammak supervised by @Remi Lehe, 2024 +# --- Input file for particle-boundary interaction testing in RZ. +# --- This input is a simple case of reflection +# --- of one electron on the surface of a sphere. +import numpy as np + +from pywarpx import callbacks, particle_containers, picmi + +########################## +# numerics parameters +########################## + +dt = 1.0e-11 + +# --- Nb time steps + +max_steps = 23 +diagnostic_interval = 1 + +# --- grid + +nr = 64 +nz = 64 + +rmin = 0.0 +rmax = 2 +zmin = -2 +zmax = 2 + +########################## +# numerics components +########################## + +grid = picmi.CylindricalGrid( + number_of_cells=[nr, nz], + n_azimuthal_modes=1, + lower_bound=[rmin, zmin], + upper_bound=[rmax, zmax], + lower_boundary_conditions=["none", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["none", "reflecting"], + upper_boundary_conditions_particles=["absorbing", "reflecting"], +) + + +solver = picmi.ElectrostaticSolver( + grid=grid, method="Multigrid", warpx_absolute_tolerance=1e-7 +) + +embedded_boundary = picmi.EmbeddedBoundary( + implicit_function="-(x**2+y**2+z**2-radius**2)", radius=0.2 +) + +########################## +# physics components +########################## + +# one particle +e_dist = picmi.ParticleListDistribution( + x=0.0, y=0.0, z=-0.25, ux=0.5e10, uy=0.0, uz=1.0e10, weight=1 +) + +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=e_dist, + warpx_save_particles_at_eb=1, +) + +########################## +# diagnostics +########################## + +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=diagnostic_interval, + data_list=["Er", "Ez", "phi", "rho", "rho_electrons"], + warpx_format="openpmd", +) + +part_diag = picmi.ParticleDiagnostic( + name="diag1", + period=diagnostic_interval, + species=[electrons], + warpx_format="openpmd", +) + +########################## +# simulation setup +########################## + +sim = picmi.Simulation( + solver=solver, + time_step_size=dt, + max_steps=max_steps, + warpx_embedded_boundary=embedded_boundary, + warpx_amrex_the_arena_is_managed=1, +) + +sim.add_species( + electrons, + layout=picmi.GriddedLayout(n_macroparticle_per_cell=[10, 1, 1], grid=grid), +) +sim.add_diagnostic(part_diag) +sim.add_diagnostic(field_diag) + +sim.initialize_inputs() +sim.initialize_warpx() + +########################## +# python particle data access +########################## + + +def concat(list_of_arrays): + if len(list_of_arrays) == 0: + # Return a 1d array of size 0 + return np.empty(0) + else: + return np.concatenate(list_of_arrays) + + +def mirror_reflection(): + buffer = particle_containers.ParticleBoundaryBufferWrapper() # boundary buffer + + # STEP 1: extract the different parameters of the boundary buffer (normal, time, position) + lev = 0 # level 0 (no mesh refinement here) + delta_t = concat( + buffer.get_particle_boundary_buffer("electrons", "eb", "deltaTimeScraped", lev) + ) + r = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "x", lev)) + theta = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "theta", lev)) + z = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "z", lev)) + x = r * np.cos(theta) # from RZ coordinates to 3D coordinates + y = r * np.sin(theta) + ux = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "ux", lev)) + uy = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "uy", lev)) + uz = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "uz", lev)) + w = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "w", lev)) + nx = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "nx", lev)) + ny = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "ny", lev)) + nz = concat(buffer.get_particle_boundary_buffer("electrons", "eb", "nz", lev)) + + # STEP 2: use these parameters to inject particle from the same position in the plasma + elect_pc = particle_containers.ParticleContainerWrapper( + "electrons" + ) # general particle container + + ####this part is specific to the case of simple reflection. + un = ux * nx + uy * ny + uz * nz + ux_reflect = -2 * un * nx + ux # for a "mirror reflection" u(sym)=-2(u.n)n+u + uy_reflect = -2 * un * ny + uy + uz_reflect = -2 * un * nz + uz + elect_pc.add_particles( + x=x + (dt - delta_t) * ux_reflect, + y=y + (dt - delta_t) * uy_reflect, + z=z + (dt - delta_t) * uz_reflect, + ux=ux_reflect, + uy=uy_reflect, + uz=uz_reflect, + w=w, + ) # adds the particle in the general particle container at the next step + #### Can be modified depending on the model of interaction. + + buffer.clear_buffer() # reinitialise the boundary buffer + + +callbacks.installafterstep( + mirror_reflection +) # mirror_reflection is called at the next step +# using the new particle container modified at the last step + +########################## +# simulation run +########################## + +sim.step(max_steps) # the whole process is done "max_steps" times diff --git a/Examples/Tests/particle_boundary_process/CMakeLists.txt b/Examples/Tests/particle_boundary_process/CMakeLists.txt new file mode 100644 index 00000000000..a7081fe9090 --- /dev/null +++ b/Examples/Tests/particle_boundary_process/CMakeLists.txt @@ -0,0 +1,24 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_particle_reflection_picmi # name + 2 # dims + 1 # nprocs + inputs_test_2d_particle_reflection_picmi.py # inputs + analysis_reflection.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +if(WarpX_EB) + add_warpx_test( + test_3d_particle_absorption # name + 3 # dims + 2 # nprocs + inputs_test_3d_particle_absorption # inputs + analysis_absorption.py # analysis + diags/diag1000060 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/particle_boundary_process/analysis_absorption.py b/Examples/Tests/particle_boundary_process/analysis_absorption.py index 9029cc60214..fdde2622684 100755 --- a/Examples/Tests/particle_boundary_process/analysis_absorption.py +++ b/Examples/Tests/particle_boundary_process/analysis_absorption.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import sys + import yt # This test shoots a beam of electrons at cubic embedded boundary geometry @@ -9,11 +11,12 @@ # the problem domain yet. # all particles are still there -ds40 = yt.load("particle_absorption_plt000040") -np40 = ds40.index.particle_headers['electrons'].num_particles -assert(np40 == 612) +ds40 = yt.load("diags/diag1000040") +np40 = ds40.index.particle_headers["electrons"].num_particles +assert np40 == 612 # all particles have been removed -ds60 = yt.load("particle_absorption_plt000060") -np60 = ds60.index.particle_headers['electrons'].num_particles -assert(np60 == 0) +filename = sys.argv[1] +ds60 = yt.load(filename) +np60 = ds60.index.particle_headers["electrons"].num_particles +assert np60 == 0 diff --git a/Examples/Tests/particle_boundary_process/analysis_reflection.py b/Examples/Tests/particle_boundary_process/analysis_reflection.py index a6402976549..1187a58e75d 100755 --- a/Examples/Tests/particle_boundary_process/analysis_reflection.py +++ b/Examples/Tests/particle_boundary_process/analysis_reflection.py @@ -9,7 +9,7 @@ import yt -plotfile = 'Python_particle_reflection_plt000010' -ds = yt.load( plotfile ) # noqa +plotfile = "Python_particle_reflection_plt000010" +ds = yt.load(plotfile) # noqa assert True diff --git a/Examples/Tests/particle_boundary_process/PICMI_inputs_reflection.py b/Examples/Tests/particle_boundary_process/inputs_test_2d_particle_reflection_picmi.py similarity index 54% rename from Examples/Tests/particle_boundary_process/PICMI_inputs_reflection.py rename to Examples/Tests/particle_boundary_process/inputs_test_2d_particle_reflection_picmi.py index bb1ebd73082..0803bc05d59 100755 --- a/Examples/Tests/particle_boundary_process/PICMI_inputs_reflection.py +++ b/Examples/Tests/particle_boundary_process/inputs_test_2d_particle_reflection_picmi.py @@ -32,42 +32,45 @@ ########################## grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, nz], - lower_bound = [xmin, zmin], - upper_bound = [xmax, zmax], - lower_boundary_conditions = ['dirichlet', 'dirichlet'], - upper_boundary_conditions = ['dirichlet', 'dirichlet'], - lower_boundary_conditions_particles = ['open', 'absorbing'], - upper_boundary_conditions_particles = ['open', 'absorbing'], - warpx_max_grid_size = 32 + number_of_cells=[nx, nz], + lower_bound=[xmin, zmin], + upper_bound=[xmax, zmax], + lower_boundary_conditions=["dirichlet", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["open", "absorbing"], + upper_boundary_conditions_particles=["open", "absorbing"], + warpx_max_grid_size=32, ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-6, - warpx_self_fields_verbosity=0 + grid=grid, + method="Multigrid", + required_precision=1e-6, + warpx_self_fields_verbosity=0, ) -#embedded_boundary = picmi.EmbeddedBoundary( +# embedded_boundary = picmi.EmbeddedBoundary( # implicit_function="-max(max(x-12.5e-6,-12.5e-6-x),max(z+6.15e-5,-8.65e-5-z))" -#) +# ) ########################## # physics components ########################## uniform_plasma_elec = picmi.UniformDistribution( - density = 1e15, # number of electrons per m^3 - lower_bound = [-1e-5, -1e-5, -125e-6], - upper_bound = [1e-5, 1e-5, -120e-6], - directed_velocity = [0., 0., 5e6] # uth the std of the (unitless) momentum + density=1e15, # number of electrons per m^3 + lower_bound=[-1e-5, -1e-5, -125e-6], + upper_bound=[1e-5, 1e-5, -120e-6], + directed_velocity=[0.0, 0.0, 5e6], # uth the std of the (unitless) momentum ) electrons = picmi.Species( - particle_type='electron', name='electrons', + particle_type="electron", + name="electrons", initial_distribution=uniform_plasma_elec, warpx_save_particles_at_zhi=1, warpx_save_particles_at_zlo=1, - warpx_reflection_model_zhi="0.5" + warpx_reflection_model_zhi="0.5", ) ########################## @@ -75,18 +78,18 @@ ########################## particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 10, - write_dir = '.', - warpx_file_prefix = 'Python_particle_reflection_plt' + name="diag1", + period=10, + write_dir=".", + warpx_file_prefix="Python_particle_reflection_plt", ) field_diag = picmi.FieldDiagnostic( grid=grid, - name = 'diag1', - data_list=['E'], - period = 10, - write_dir = '.', - warpx_file_prefix = 'Python_particle_reflection_plt' + name="diag1", + data_list=["E"], + period=10, + write_dir=".", + warpx_file_prefix="Python_particle_reflection_plt", ) ########################## @@ -94,18 +97,15 @@ ########################## sim = picmi.Simulation( - solver = solver, - time_step_size = dt, - max_steps = max_steps, + solver=solver, + time_step_size=dt, + max_steps=max_steps, # warpx_embedded_boundary=embedded_boundary, - verbose = 1 + verbose=1, ) sim.add_species( - electrons, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[5, 2], grid=grid - ) + electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[5, 2], grid=grid) ) sim.add_diagnostic(particle_diag) sim.add_diagnostic(field_diag) @@ -123,20 +123,24 @@ buffer = particle_containers.ParticleBoundaryBufferWrapper() -n = buffer.get_particle_boundary_buffer_size("electrons", 'z_hi') +n = buffer.get_particle_boundary_buffer_size("electrons", "z_hi") print("Number of electrons in upper buffer:", n) assert n == 63 -n = buffer.get_particle_boundary_buffer_size("electrons", 'z_lo') +n = buffer.get_particle_boundary_buffer_size("electrons", "z_lo") print("Number of electrons in lower buffer:", n) assert n == 67 -scraped_steps = buffer.get_particle_boundary_buffer("electrons", 'z_hi', 'stepScraped', 0) +scraped_steps = buffer.get_particle_boundary_buffer( + "electrons", "z_hi", "stepScraped", 0 +) for arr in scraped_steps: # print(arr) assert all(arr == 4) -scraped_steps = buffer.get_particle_boundary_buffer("electrons", 'z_lo', 'stepScraped', 0) +scraped_steps = buffer.get_particle_boundary_buffer( + "electrons", "z_lo", "stepScraped", 0 +) for arr in scraped_steps: # print(arr) assert all(arr == 8) diff --git a/Examples/Tests/particle_boundary_process/inputs_absorption b/Examples/Tests/particle_boundary_process/inputs_test_3d_particle_absorption similarity index 100% rename from Examples/Tests/particle_boundary_process/inputs_absorption rename to Examples/Tests/particle_boundary_process/inputs_test_3d_particle_absorption diff --git a/Examples/Tests/particle_boundary_scrape/CMakeLists.txt b/Examples/Tests/particle_boundary_scrape/CMakeLists.txt new file mode 100644 index 00000000000..9b303afcc0f --- /dev/null +++ b/Examples/Tests/particle_boundary_scrape/CMakeLists.txt @@ -0,0 +1,26 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_3d_particle_scrape # name + 3 # dims + 2 # nprocs + inputs_test_3d_particle_scrape # inputs + analysis_scrape.py # analysis + diags/diag1000060 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_3d_particle_scrape_picmi # name + 3 # dims + 2 # nprocs + inputs_test_3d_particle_scrape_picmi.py # inputs + analysis_scrape.py # analysis + diags/diag1000060 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/particle_boundary_scrape/analysis_scrape.py b/Examples/Tests/particle_boundary_scrape/analysis_scrape.py index bf1de62bf0f..1b3a97da228 100755 --- a/Examples/Tests/particle_boundary_scrape/analysis_scrape.py +++ b/Examples/Tests/particle_boundary_scrape/analysis_scrape.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -from pathlib import Path + +import sys import yt @@ -11,19 +12,13 @@ # the problem domain yet. # all particles are still there -if Path("particle_scrape_plt000040").is_dir(): - filename = "particle_scrape_plt000040" -else: - filename = "Python_particle_scrape_plt000040" +filename = "diags/diag1000040" ds40 = yt.load(filename) -np40 = ds40.index.particle_headers['electrons'].num_particles -assert(np40 == 612) +np40 = ds40.index.particle_headers["electrons"].num_particles +assert np40 == 612 # all particles have been removed -if Path("particle_scrape_plt000060").is_dir(): - filename = "particle_scrape_plt000060" -else: - filename = "Python_particle_scrape_plt000060" +filename = sys.argv[1] ds60 = yt.load(filename) -np60 = ds60.index.particle_headers['electrons'].num_particles -assert(np60 == 0) +np60 = ds60.index.particle_headers["electrons"].num_particles +assert np60 == 0 diff --git a/Examples/Tests/particle_boundary_scrape/inputs_scrape b/Examples/Tests/particle_boundary_scrape/inputs_test_3d_particle_scrape similarity index 100% rename from Examples/Tests/particle_boundary_scrape/inputs_scrape rename to Examples/Tests/particle_boundary_scrape/inputs_test_3d_particle_scrape diff --git a/Examples/Tests/particle_boundary_scrape/PICMI_inputs_scrape.py b/Examples/Tests/particle_boundary_scrape/inputs_test_3d_particle_scrape_picmi.py similarity index 62% rename from Examples/Tests/particle_boundary_scrape/PICMI_inputs_scrape.py rename to Examples/Tests/particle_boundary_scrape/inputs_test_3d_particle_scrape_picmi.py index e5a9a58f597..1be71d4c397 100755 --- a/Examples/Tests/particle_boundary_scrape/PICMI_inputs_scrape.py +++ b/Examples/Tests/particle_boundary_scrape/inputs_test_3d_particle_scrape_picmi.py @@ -34,16 +34,22 @@ ########################## uniform_plasma_elec = picmi.UniformDistribution( - density = 1e23, # number of electrons per m^3 - lower_bound = [-1e-5, -1e-5, -149e-6], - upper_bound = [1e-5, 1e-5, -129e-6], - directed_velocity = [0., 0., 2000.*picmi.constants.c] # uth the std of the (unitless) momentum + density=1e23, # number of electrons per m^3 + lower_bound=[-1e-5, -1e-5, -149e-6], + upper_bound=[1e-5, 1e-5, -129e-6], + directed_velocity=[ + 0.0, + 0.0, + 2000.0 * picmi.constants.c, + ], # uth the std of the (unitless) momentum ) electrons = picmi.Species( - particle_type='electron', name='electrons', + particle_type="electron", + name="electrons", initial_distribution=uniform_plasma_elec, - warpx_save_particles_at_xhi=1, warpx_save_particles_at_eb=1 + warpx_save_particles_at_xhi=1, + warpx_save_particles_at_eb=1, ) ########################## @@ -51,19 +57,17 @@ ########################## grid = picmi.Cartesian3DGrid( - number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions=['none', 'none', 'none'], - upper_boundary_conditions=['none', 'none', 'none'], - lower_boundary_conditions_particles=['open', 'open', 'open'], - upper_boundary_conditions_particles=['open', 'open', 'open'], - warpx_max_grid_size = 32 + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["none", "none", "none"], + upper_boundary_conditions=["none", "none", "none"], + lower_boundary_conditions_particles=["open", "open", "open"], + upper_boundary_conditions_particles=["open", "open", "open"], + warpx_max_grid_size=32, ) -solver = picmi.ElectromagneticSolver( - grid=grid, cfl=cfl -) +solver = picmi.ElectromagneticSolver(grid=grid, cfl=cfl) embedded_boundary = picmi.EmbeddedBoundary( implicit_function="-max(max(max(x-12.5e-6,-12.5e-6-x),max(y-12.5e-6,-12.5e-6-y)),max(z-(-6.15e-5),-8.65e-5-z))" @@ -74,18 +78,14 @@ ########################## particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = diagnostic_intervals, - write_dir = '.', - warpx_file_prefix = 'Python_particle_scrape_plt' + name="diag1", + period=diagnostic_intervals, ) field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = diagnostic_intervals, - data_list = ['Ex', 'Ey', 'Ez', 'Bx', 'By', 'Bz'], - write_dir = '.', - warpx_file_prefix = 'Python_particle_scrape_plt' + name="diag1", + grid=grid, + period=diagnostic_intervals, + data_list=["Ex", "Ey", "Ez", "Bx", "By", "Bz"], ) ########################## @@ -93,19 +93,16 @@ ########################## sim = picmi.Simulation( - solver = solver, - max_steps = max_steps, + solver=solver, + max_steps=max_steps, warpx_embedded_boundary=embedded_boundary, verbose=True, warpx_load_balance_intervals=40, - warpx_load_balance_efficiency_ratio_threshold=0.9 + warpx_load_balance_efficiency_ratio_threshold=0.9, ) sim.add_species( - electrons, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[1, 1, 1], grid=grid - ) + electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[1, 1, 1], grid=grid) ) sim.add_diagnostic(particle_diag) @@ -129,22 +126,24 @@ particle_buffer = particle_containers.ParticleBoundaryBufferWrapper() -n = particle_buffer.get_particle_boundary_buffer_size("electrons", 'eb') +n = particle_buffer.get_particle_boundary_buffer_size("electrons", "eb") print(f"Number of electrons in buffer (proc #{my_id}): {n}") assert n == 612 -scraped_steps = particle_buffer.get_particle_boundary_buffer("electrons", 'eb', 'stepScraped', 0) +scraped_steps = particle_buffer.get_particle_boundary_buffer( + "electrons", "eb", "stepScraped", 0 +) for arr in scraped_steps: assert all(np.array(arr, copy=False) > 40) -weights = particle_buffer.get_particle_boundary_buffer("electrons", 'eb', 'w', 0) +weights = particle_buffer.get_particle_boundary_buffer("electrons", "eb", "w", 0) n = sum(len(arr) for arr in weights) print(f"Number of electrons in this proc's buffer (proc #{my_id}): {n}") -n_sum = mpi.COMM_WORLD.allreduce(n, op=mpi.SUM) +n_sum = mpi.COMM_WORLD.allreduce(n, op=mpi.SUM) assert n_sum == 612 particle_buffer.clear_buffer() # confirm that the buffer was cleared -n = particle_buffer.get_particle_boundary_buffer_size("electrons", 'eb') +n = particle_buffer.get_particle_boundary_buffer_size("electrons", "eb") print(f"Number of electrons in buffer (proc #{my_id}): {n}") assert n == 0 diff --git a/Examples/Tests/particle_data_python/CMakeLists.txt b/Examples/Tests/particle_data_python/CMakeLists.txt new file mode 100644 index 00000000000..e58fe72670a --- /dev/null +++ b/Examples/Tests/particle_data_python/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_particle_attr_access_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_particle_attr_access_picmi.py # inputs + analysis.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +add_warpx_test( + test_2d_particle_attr_access_unique_picmi # name + 2 # dims + 2 # nprocs + "inputs_test_2d_particle_attr_access_picmi.py --unique" # inputs + analysis.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +add_warpx_test( + test_2d_prev_positions_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_prev_positions_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) diff --git a/Examples/Tests/particle_data_python/analysis_default_regression.py b/Examples/Tests/particle_data_python/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/particle_data_python/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/particle_data_python/PICMI_inputs_2d.py b/Examples/Tests/particle_data_python/inputs_test_2d_particle_attr_access_picmi.py similarity index 57% rename from Examples/Tests/particle_data_python/PICMI_inputs_2d.py rename to Examples/Tests/particle_data_python/inputs_test_2d_particle_attr_access_picmi.py index 572871b8ed5..dbd29a43bc7 100755 --- a/Examples/Tests/particle_data_python/PICMI_inputs_2d.py +++ b/Examples/Tests/particle_data_python/inputs_test_2d_particle_attr_access_picmi.py @@ -9,8 +9,10 @@ # Create the parser and add the argument parser = argparse.ArgumentParser() parser.add_argument( - '-u', '--unique', action='store_true', - help="Whether injected particles should be treated as unique" + "-u", + "--unique", + action="store_true", + help="Whether injected particles should be treated as unique", ) # Parse the input @@ -42,65 +44,53 @@ ########################## grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, ny], - lower_bound = [xmin, ymin], - upper_bound = [xmax, ymax], - lower_boundary_conditions = ['dirichlet', 'periodic'], - upper_boundary_conditions = ['dirichlet', 'periodic'], - lower_boundary_conditions_particles = ['absorbing', 'periodic'], - upper_boundary_conditions_particles = ['absorbing', 'periodic'], - moving_window_velocity = None, - warpx_max_grid_size = 32 + number_of_cells=[nx, ny], + lower_bound=[xmin, ymin], + upper_bound=[xmax, ymax], + lower_boundary_conditions=["dirichlet", "periodic"], + upper_boundary_conditions=["dirichlet", "periodic"], + lower_boundary_conditions_particles=["absorbing", "periodic"], + upper_boundary_conditions_particles=["absorbing", "periodic"], + moving_window_velocity=None, + warpx_max_grid_size=32, ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-6, - warpx_self_fields_verbosity=0 + grid=grid, + method="Multigrid", + required_precision=1e-6, + warpx_self_fields_verbosity=0, ) ########################## # physics components ########################## -electrons = picmi.Species( - particle_type='electron', name='electrons' -) +electrons = picmi.Species(particle_type="electron", name="electrons") ########################## # diagnostics ########################## particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 10, - write_dir = '.', - warpx_file_prefix = f"Python_particle_attr_access_{'unique_' if args.unique else ''}plt" + name="diag1", + period=10, ) field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 10, - data_list = ['phi'], - write_dir = '.', - warpx_file_prefix = f"Python_particle_attr_access_{'unique_' if args.unique else ''}plt" + name="diag1", + grid=grid, + period=10, + data_list=["phi"], ) ########################## # simulation setup ########################## -sim = picmi.Simulation( - solver = solver, - time_step_size = dt, - max_steps = max_steps, - verbose = 1 -) +sim = picmi.Simulation(solver=solver, time_step_size=dt, max_steps=max_steps, verbose=1) sim.add_species( - electrons, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[0, 0], grid=grid - ) + electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[0, 0], grid=grid) ) sim.add_diagnostic(particle_diag) sim.add_diagnostic(field_diag) @@ -116,13 +106,13 @@ # below will be reproducible from run to run np.random.seed(30025025) -elec_wrapper = particle_containers.ParticleContainerWrapper('electrons') -elec_wrapper.add_real_comp('newPid') +elec_wrapper = particle_containers.ParticleContainerWrapper("electrons") +elec_wrapper.add_real_comp("newPid") my_id = libwarpx.amr.ParallelDescriptor.MyProc() -def add_particles(): +def add_particles(): nps = 10 * (my_id + 1) x = np.linspace(0.005, 0.025, nps) y = np.zeros(nps) @@ -134,11 +124,18 @@ def add_particles(): newPid = 5.0 elec_wrapper.add_particles( - x=x, y=y, z=z, ux=ux, uy=uy, uz=uz, - w=w, newPid=newPid, - unique_particles=args.unique + x=x, + y=y, + z=z, + ux=ux, + uy=uy, + uz=uz, + w=w, + newPid=newPid, + unique_particles=args.unique, ) + callbacks.installbeforestep(add_particles) ########################## @@ -152,11 +149,11 @@ def add_particles(): # are properly set ########################## -assert (elec_wrapper.nps == 270 / (2 - args.unique)) -assert (elec_wrapper.particle_container.get_comp_index('w') == 2) -assert (elec_wrapper.particle_container.get_comp_index('newPid') == 6) +assert elec_wrapper.nps == 270 / (2 - args.unique) +assert elec_wrapper.particle_container.get_comp_index("w") == 2 +assert elec_wrapper.particle_container.get_comp_index("newPid") == 6 -new_pid_vals = elec_wrapper.get_particle_real_arrays('newPid', 0) +new_pid_vals = elec_wrapper.get_particle_real_arrays("newPid", 0) for vals in new_pid_vals: assert np.allclose(vals, 5) diff --git a/Examples/Tests/particle_data_python/PICMI_inputs_prev_pos_2d.py b/Examples/Tests/particle_data_python/inputs_test_2d_prev_positions_picmi.py similarity index 52% rename from Examples/Tests/particle_data_python/PICMI_inputs_prev_pos_2d.py rename to Examples/Tests/particle_data_python/inputs_test_2d_prev_positions_picmi.py index 5de9879f0f8..2ad86ecea95 100755 --- a/Examples/Tests/particle_data_python/PICMI_inputs_prev_pos_2d.py +++ b/Examples/Tests/particle_data_python/inputs_test_2d_prev_positions_picmi.py @@ -34,20 +34,22 @@ ########################## grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, nz], - lower_bound = [xmin, zmin], - upper_bound = [xmax, zmax], - lower_boundary_conditions = ['dirichlet', 'periodic'], - upper_boundary_conditions = ['dirichlet', 'periodic'], - lower_boundary_conditions_particles = ['absorbing', 'periodic'], - upper_boundary_conditions_particles = ['absorbing', 'periodic'], - moving_window_velocity = None, - warpx_max_grid_size = 32 + number_of_cells=[nx, nz], + lower_bound=[xmin, zmin], + upper_bound=[xmax, zmax], + lower_boundary_conditions=["dirichlet", "periodic"], + upper_boundary_conditions=["dirichlet", "periodic"], + lower_boundary_conditions_particles=["absorbing", "periodic"], + upper_boundary_conditions_particles=["absorbing", "periodic"], + moving_window_velocity=None, + warpx_max_grid_size=32, ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-6, - warpx_self_fields_verbosity=0 + grid=grid, + method="Multigrid", + required_precision=1e-6, + warpx_self_fields_verbosity=0, ) ########################## @@ -55,16 +57,17 @@ ########################## uniform_plasma_elec = picmi.UniformDistribution( - density = 1e15, - upper_bound = [None] * 3, - rms_velocity = [np.sqrt(constants.kb * 1e3 / constants.m_e)] * 3, - directed_velocity = [0.] * 3 + density=1e15, + upper_bound=[None] * 3, + rms_velocity=[np.sqrt(constants.kb * 1e3 / constants.m_e)] * 3, + directed_velocity=[0.0] * 3, ) electrons = picmi.Species( - particle_type='electron', name='electrons', + particle_type="electron", + name="electrons", initial_distribution=uniform_plasma_elec, - warpx_save_previous_position=True + warpx_save_previous_position=True, ) ########################## @@ -72,36 +75,24 @@ ########################## part_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 10, + name="diag1", + period=10, species=[electrons], - write_dir = '.', - warpx_file_prefix = 'Python_prev_positions_plt' ) field_diag = picmi.FieldDiagnostic( - name = 'diag1', - data_list=['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], - period = 10, + name="diag1", + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez", "Jx", "Jy", "Jz"], + period=10, grid=grid, - write_dir = '.', - warpx_file_prefix = 'Python_prev_positions_plt' ) ########################## # simulation setup ########################## -sim = picmi.Simulation( - solver = solver, - time_step_size = dt, - max_steps = max_steps, - verbose = 1 -) +sim = picmi.Simulation(solver=solver, time_step_size=dt, max_steps=max_steps, verbose=1) sim.add_species( - electrons, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[1, 1], grid=grid - ) + electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[1, 1], grid=grid) ) sim.add_diagnostic(part_diag) sim.add_diagnostic(field_diag) @@ -116,16 +107,16 @@ # exist ########################## -elec_wrapper = particle_containers.ParticleContainerWrapper('electrons') +elec_wrapper = particle_containers.ParticleContainerWrapper("electrons") elec_count = elec_wrapper.nps # check that the runtime attributes have the right indices -assert (elec_wrapper.particle_container.get_comp_index('prev_x') == 6) -assert (elec_wrapper.particle_container.get_comp_index('prev_z') == 7) +assert elec_wrapper.particle_container.get_comp_index("prev_x") == 6 +assert elec_wrapper.particle_container.get_comp_index("prev_z") == 7 # sanity check that the prev_z values are reasonable and # that the correct number of values are returned -prev_z_vals = elec_wrapper.get_particle_real_arrays('prev_z', 0) +prev_z_vals = elec_wrapper.get_particle_real_arrays("prev_z", 0) running_count = 0 for z_vals in prev_z_vals: diff --git a/Examples/Tests/particle_fields_diags/CMakeLists.txt b/Examples/Tests/particle_fields_diags/CMakeLists.txt new file mode 100644 index 00000000000..a83818b6966 --- /dev/null +++ b/Examples/Tests/particle_fields_diags/CMakeLists.txt @@ -0,0 +1,23 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_particle_fields_diags # name + 3 # dims + 2 # nprocs + inputs_test_3d_particle_fields_diags # inputs + analysis_particle_diags.py # analysis + diags/diag1000200 # output + OFF # dependency +) + +# FIXME +#add_warpx_test( +# test_3d_particle_fields_diags_single_precision # name +# 3 # dims +# 2 # nprocs +## inputs_test_3d_particle_fields_diags # inputs +# analysis_particle_diags_single.py # analysis +# diags/diag1000200 # output +# OFF # dependency +#) diff --git a/Examples/Tests/particle_fields_diags/analysis_particle_diags.py b/Examples/Tests/particle_fields_diags/analysis_particle_diags.py index 3a77cbfc571..78ed9137e79 100755 --- a/Examples/Tests/particle_fields_diags/analysis_particle_diags.py +++ b/Examples/Tests/particle_fields_diags/analysis_particle_diags.py @@ -13,4 +13,4 @@ import analysis_particle_diags_impl as an -an.do_analysis(single_precision = False) +an.do_analysis(single_precision=False) diff --git a/Examples/Tests/particle_fields_diags/analysis_particle_diags_impl.py b/Examples/Tests/particle_fields_diags/analysis_particle_diags_impl.py index 5e54fc42d87..a7c84b05459 100755 --- a/Examples/Tests/particle_fields_diags/analysis_particle_diags_impl.py +++ b/Examples/Tests/particle_fields_diags/analysis_particle_diags_impl.py @@ -19,23 +19,25 @@ import yt from scipy.constants import c, e, m_e, m_p -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -def do_analysis(single_precision = False): +def do_analysis(single_precision=False): fn = sys.argv[1] ds = yt.load(fn) ad = ds.all_data() - ad0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) + ad0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions + ) - opmd = io.Series('diags/openpmd/openpmd_%T.h5', io.Access.read_only) + opmd = io.Series("diags/openpmd/openpmd_%T.h5", io.Access.read_only) opmd_i = opmd.iterations[200] - #-------------------------------------------------------------------------------------------------- + # -------------------------------------------------------------------------------------------------- # Part 1: get results from plotfiles (label '_yt') - #-------------------------------------------------------------------------------------------------- + # -------------------------------------------------------------------------------------------------- # Quantities computed from plotfiles values_yt = dict() @@ -44,11 +46,11 @@ def do_analysis(single_precision = False): dx = domain_size / ds.domain_dimensions # Electrons - x = ad['electrons', 'particle_position_x'].to_ndarray() - y = ad['electrons', 'particle_position_y'].to_ndarray() - z = ad['electrons', 'particle_position_z'].to_ndarray() - uz = ad['electrons', 'particle_momentum_z'].to_ndarray() / m_e / c - w = ad['electrons', 'particle_weight'].to_ndarray() + x = ad["electrons", "particle_position_x"].to_ndarray() + y = ad["electrons", "particle_position_y"].to_ndarray() + z = ad["electrons", "particle_position_z"].to_ndarray() + uz = ad["electrons", "particle_momentum_z"].to_ndarray() / m_e / c + w = ad["electrons", "particle_weight"].to_ndarray() filt = uz < 0 x_ind = ((x - ds.domain_left_edge[0].value) / dx[0]).astype(int) @@ -63,27 +65,27 @@ def do_analysis(single_precision = False): wavg_filt = np.zeros(ds.domain_dimensions) for i_p in range(len(x)): - zavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += z[i_p] * w[i_p] - uzavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += uz[i_p] * w[i_p] - zuzavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += z[i_p] * uz[i_p] * w[i_p] - wavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += w[i_p] - uzavg_filt[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += uz[i_p] * w[i_p] * filt[i_p] - wavg_filt[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += w[i_p] * filt[i_p] + zavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += z[i_p] * w[i_p] + uzavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += uz[i_p] * w[i_p] + zuzavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += z[i_p] * uz[i_p] * w[i_p] + wavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += w[i_p] + uzavg_filt[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += uz[i_p] * w[i_p] * filt[i_p] + wavg_filt[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += w[i_p] * filt[i_p] wavg_adj = np.where(wavg == 0, 1, wavg) wavg_filt_adj = np.where(wavg_filt == 0, 1, wavg_filt) - values_yt['electrons: zavg'] = zavg / wavg_adj - values_yt['electrons: uzavg'] = uzavg / wavg_adj - values_yt['electrons: zuzavg'] = zuzavg / wavg_adj - values_yt['electrons: uzavg_filt'] = uzavg_filt / wavg_filt_adj - values_yt['electrons: jz'] = e*uzavg + values_yt["electrons: zavg"] = zavg / wavg_adj + values_yt["electrons: uzavg"] = uzavg / wavg_adj + values_yt["electrons: zuzavg"] = zuzavg / wavg_adj + values_yt["electrons: uzavg_filt"] = uzavg_filt / wavg_filt_adj + values_yt["electrons: jz"] = e * uzavg # protons - x = ad['protons', 'particle_position_x'].to_ndarray() - y = ad['protons', 'particle_position_y'].to_ndarray() - z = ad['protons', 'particle_position_z'].to_ndarray() - uz = ad['protons', 'particle_momentum_z'].to_ndarray() / m_p / c - w = ad['protons', 'particle_weight'].to_ndarray() + x = ad["protons", "particle_position_x"].to_ndarray() + y = ad["protons", "particle_position_y"].to_ndarray() + z = ad["protons", "particle_position_z"].to_ndarray() + uz = ad["protons", "particle_momentum_z"].to_ndarray() / m_p / c + w = ad["protons", "particle_weight"].to_ndarray() filt = uz < 0 x_ind = ((x - ds.domain_left_edge[0].value) / dx[0]).astype(int) @@ -98,27 +100,27 @@ def do_analysis(single_precision = False): wavg_filt = np.zeros(ds.domain_dimensions) for i_p in range(len(x)): - zavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += z[i_p] * w[i_p] - uzavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += uz[i_p] * w[i_p] - zuzavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += z[i_p] * uz[i_p] * w[i_p] - wavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += w[i_p] - uzavg_filt[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += uz[i_p] * w[i_p] * filt[i_p] - wavg_filt[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += w[i_p] * filt[i_p] + zavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += z[i_p] * w[i_p] + uzavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += uz[i_p] * w[i_p] + zuzavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += z[i_p] * uz[i_p] * w[i_p] + wavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += w[i_p] + uzavg_filt[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += uz[i_p] * w[i_p] * filt[i_p] + wavg_filt[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += w[i_p] * filt[i_p] wavg_adj = np.where(wavg == 0, 1, wavg) wavg_filt_adj = np.where(wavg_filt == 0, 1, wavg_filt) - values_yt['protons: zavg'] = zavg / wavg_adj - values_yt['protons: uzavg'] = uzavg / wavg_adj - values_yt['protons: zuzavg'] = zuzavg / wavg_adj - values_yt['protons: uzavg_filt'] = uzavg_filt / wavg_filt_adj - values_yt['protons: jz'] = e*uzavg + values_yt["protons: zavg"] = zavg / wavg_adj + values_yt["protons: uzavg"] = uzavg / wavg_adj + values_yt["protons: zuzavg"] = zuzavg / wavg_adj + values_yt["protons: uzavg_filt"] = uzavg_filt / wavg_filt_adj + values_yt["protons: jz"] = e * uzavg # Photons (momentum in units of m_e c) - x = ad['photons', 'particle_position_x'].to_ndarray() - y = ad['photons', 'particle_position_y'].to_ndarray() - z = ad['photons', 'particle_position_z'].to_ndarray() - uz = ad['photons', 'particle_momentum_z'].to_ndarray() / m_e / c - w = ad['photons', 'particle_weight'].to_ndarray() + x = ad["photons", "particle_position_x"].to_ndarray() + y = ad["photons", "particle_position_y"].to_ndarray() + z = ad["photons", "particle_position_z"].to_ndarray() + uz = ad["photons", "particle_momentum_z"].to_ndarray() / m_e / c + w = ad["photons", "particle_weight"].to_ndarray() filt = uz < 0 x_ind = ((x - ds.domain_left_edge[0].value) / dx[0]).astype(int) @@ -133,72 +135,95 @@ def do_analysis(single_precision = False): wavg_filt = np.zeros(ds.domain_dimensions) for i_p in range(len(x)): - zavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += z[i_p] * w[i_p] - uzavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += uz[i_p] * w[i_p] - zuzavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += z[i_p] * uz[i_p] * w[i_p] - wavg[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += w[i_p] - uzavg_filt[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += uz[i_p] * w[i_p] * filt[i_p] - wavg_filt[x_ind[i_p],y_ind[i_p],z_ind[i_p]] += w[i_p] * filt[i_p] + zavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += z[i_p] * w[i_p] + uzavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += uz[i_p] * w[i_p] + zuzavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += z[i_p] * uz[i_p] * w[i_p] + wavg[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += w[i_p] + uzavg_filt[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += uz[i_p] * w[i_p] * filt[i_p] + wavg_filt[x_ind[i_p], y_ind[i_p], z_ind[i_p]] += w[i_p] * filt[i_p] wavg_adj = np.where(wavg == 0, 1, wavg) wavg_filt_adj = np.where(wavg_filt == 0, 1, wavg_filt) - values_yt['photons: zavg'] = zavg / wavg_adj - values_yt['photons: uzavg'] = uzavg / wavg_adj - values_yt['photons: zuzavg'] = zuzavg / wavg_adj - values_yt['photons: uzavg_filt'] = uzavg_filt / wavg_filt_adj - values_yt['photons: jz'] = e*uzavg - + values_yt["photons: zavg"] = zavg / wavg_adj + values_yt["photons: uzavg"] = uzavg / wavg_adj + values_yt["photons: zuzavg"] = zuzavg / wavg_adj + values_yt["photons: uzavg_filt"] = uzavg_filt / wavg_filt_adj + values_yt["photons: jz"] = e * uzavg values_rd = dict() # Load reduced particle diagnostic data from plotfiles - values_rd['electrons: zavg'] = ad0[('boxlib','z_electrons')] - values_rd['protons: zavg'] = ad0[('boxlib','z_protons')] - values_rd['photons: zavg'] = ad0[('boxlib','z_photons')] + values_rd["electrons: zavg"] = ad0[("boxlib", "z_electrons")] + values_rd["protons: zavg"] = ad0[("boxlib", "z_protons")] + values_rd["photons: zavg"] = ad0[("boxlib", "z_photons")] - values_rd['electrons: uzavg'] = ad0[('boxlib','uz_electrons')] - values_rd['protons: uzavg'] = ad0[('boxlib','uz_protons')] - values_rd['photons: uzavg'] = ad0[('boxlib','uz_photons')] + values_rd["electrons: uzavg"] = ad0[("boxlib", "uz_electrons")] + values_rd["protons: uzavg"] = ad0[("boxlib", "uz_protons")] + values_rd["photons: uzavg"] = ad0[("boxlib", "uz_photons")] - values_rd['electrons: zuzavg'] = ad0[('boxlib','zuz_electrons')] - values_rd['protons: zuzavg'] = ad0[('boxlib','zuz_protons')] - values_rd['photons: zuzavg'] = ad0[('boxlib','zuz_photons')] + values_rd["electrons: zuzavg"] = ad0[("boxlib", "zuz_electrons")] + values_rd["protons: zuzavg"] = ad0[("boxlib", "zuz_protons")] + values_rd["photons: zuzavg"] = ad0[("boxlib", "zuz_photons")] - values_rd['electrons: uzavg_filt'] = ad0[('boxlib','uz_filt_electrons')] - values_rd['protons: uzavg_filt'] = ad0[('boxlib','uz_filt_protons')] - values_rd['photons: uzavg_filt'] = ad0[('boxlib','uz_filt_photons')] + values_rd["electrons: uzavg_filt"] = ad0[("boxlib", "uz_filt_electrons")] + values_rd["protons: uzavg_filt"] = ad0[("boxlib", "uz_filt_protons")] + values_rd["photons: uzavg_filt"] = ad0[("boxlib", "uz_filt_photons")] - values_rd['electrons: jz'] = ad0[('boxlib','jz_electrons')] - values_rd['protons: jz'] = ad0[('boxlib','jz_protons')] - values_rd['photons: jz'] = ad0[('boxlib','jz_photons')] + values_rd["electrons: jz"] = ad0[("boxlib", "jz_electrons")] + values_rd["protons: jz"] = ad0[("boxlib", "jz_protons")] + values_rd["photons: jz"] = ad0[("boxlib", "jz_photons")] values_opmd = dict() # Load reduced particle diagnostic data from OPMD output - values_opmd['electrons: zavg'] = opmd_i.meshes['z_electrons'][io.Mesh_Record_Component.SCALAR].load_chunk() - values_opmd['protons: zavg'] = opmd_i.meshes['z_protons'][io.Mesh_Record_Component.SCALAR].load_chunk() - values_opmd['photons: zavg'] = opmd_i.meshes['z_photons'][io.Mesh_Record_Component.SCALAR].load_chunk() - - values_opmd['electrons: uzavg'] = opmd_i.meshes['uz_electrons'][io.Mesh_Record_Component.SCALAR].load_chunk() - values_opmd['protons: uzavg'] = opmd_i.meshes['uz_protons'][io.Mesh_Record_Component.SCALAR].load_chunk() - values_opmd['photons: uzavg'] = opmd_i.meshes['uz_photons'][io.Mesh_Record_Component.SCALAR].load_chunk() - - values_opmd['electrons: zuzavg'] = opmd_i.meshes['zuz_electrons'][io.Mesh_Record_Component.SCALAR].load_chunk() - values_opmd['protons: zuzavg'] = opmd_i.meshes['zuz_protons'][io.Mesh_Record_Component.SCALAR].load_chunk() - values_opmd['photons: zuzavg'] = opmd_i.meshes['zuz_photons'][io.Mesh_Record_Component.SCALAR].load_chunk() - - values_opmd['electrons: uzavg_filt'] = opmd_i.meshes['uz_filt_electrons'][io.Mesh_Record_Component.SCALAR].load_chunk() - values_opmd['protons: uzavg_filt'] = opmd_i.meshes['uz_filt_protons'][io.Mesh_Record_Component.SCALAR].load_chunk() - values_opmd['photons: uzavg_filt'] = opmd_i.meshes['uz_filt_photons'][io.Mesh_Record_Component.SCALAR].load_chunk() - - values_opmd['electrons: jz'] = opmd_i.meshes['j_electrons']['z'].load_chunk() - values_opmd['protons: jz'] = opmd_i.meshes['j_protons']['z'].load_chunk() - values_opmd['photons: jz'] = opmd_i.meshes['j_photons']['z'].load_chunk() + values_opmd["electrons: zavg"] = opmd_i.meshes["z_electrons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + values_opmd["protons: zavg"] = opmd_i.meshes["z_protons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + values_opmd["photons: zavg"] = opmd_i.meshes["z_photons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + + values_opmd["electrons: uzavg"] = opmd_i.meshes["uz_electrons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + values_opmd["protons: uzavg"] = opmd_i.meshes["uz_protons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + values_opmd["photons: uzavg"] = opmd_i.meshes["uz_photons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + + values_opmd["electrons: zuzavg"] = opmd_i.meshes["zuz_electrons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + values_opmd["protons: zuzavg"] = opmd_i.meshes["zuz_protons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + values_opmd["photons: zuzavg"] = opmd_i.meshes["zuz_photons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + + values_opmd["electrons: uzavg_filt"] = opmd_i.meshes["uz_filt_electrons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + values_opmd["protons: uzavg_filt"] = opmd_i.meshes["uz_filt_protons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + values_opmd["photons: uzavg_filt"] = opmd_i.meshes["uz_filt_photons"][ + io.Mesh_Record_Component.SCALAR + ].load_chunk() + + values_opmd["electrons: jz"] = opmd_i.meshes["j_electrons"]["z"].load_chunk() + values_opmd["protons: jz"] = opmd_i.meshes["j_protons"]["z"].load_chunk() + values_opmd["photons: jz"] = opmd_i.meshes["j_photons"]["z"].load_chunk() opmd.flush() del opmd - #-------------------------------------------------------------------------------------------------- + # -------------------------------------------------------------------------------------------------- # Part 3: compare values from plotfiles and diagnostics and print output - #-------------------------------------------------------------------------------------------------- + # -------------------------------------------------------------------------------------------------- error_plt = dict() error_opmd = dict() @@ -208,16 +233,20 @@ def do_analysis(single_precision = False): for k in values_yt.keys(): # check that the zeros line up, since we'll be ignoring them in the error calculation - assert(np.all((values_yt[k] == 0) == (values_rd[k] == 0))) - error_plt[k] = np.max(abs(values_yt[k] - values_rd[k])[values_yt[k] != 0] / abs(values_yt[k])[values_yt[k] != 0]) - print(k, 'relative error plotfile = ', error_plt[k]) - assert(error_plt[k] < tolerance) - assert(np.all((values_yt[k] == 0) == (values_opmd[k].T == 0))) - error_opmd[k] = np.max(abs(values_yt[k] - values_opmd[k].T)[values_yt[k] != 0] / abs(values_yt[k])[values_yt[k] != 0]) - assert(error_opmd[k] < tolerance) - print(k, 'relative error openPMD = ', error_opmd[k]) - - + assert np.all((values_yt[k] == 0) == (values_rd[k] == 0)) + error_plt[k] = np.max( + abs(values_yt[k] - values_rd[k])[values_yt[k] != 0] + / abs(values_yt[k])[values_yt[k] != 0] + ) + print(k, "relative error plotfile = ", error_plt[k]) + assert error_plt[k] < tolerance + assert np.all((values_yt[k] == 0) == (values_opmd[k].T == 0)) + error_opmd[k] = np.max( + abs(values_yt[k] - values_opmd[k].T)[values_yt[k] != 0] + / abs(values_yt[k])[values_yt[k] != 0] + ) + assert error_opmd[k] < tolerance + print(k, "relative error openPMD = ", error_opmd[k]) test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, fn, rtol=check_tolerance) diff --git a/Examples/Tests/particle_fields_diags/analysis_particle_diags_single.py b/Examples/Tests/particle_fields_diags/analysis_particle_diags_single.py index 56d98831e66..7efbe4e39d4 100755 --- a/Examples/Tests/particle_fields_diags/analysis_particle_diags_single.py +++ b/Examples/Tests/particle_fields_diags/analysis_particle_diags_single.py @@ -13,4 +13,4 @@ import analysis_particle_diags_impl as an -an.do_analysis(single_precision = True) +an.do_analysis(single_precision=True) diff --git a/Examples/Tests/particle_fields_diags/inputs b/Examples/Tests/particle_fields_diags/inputs_test_3d_particle_fields_diags similarity index 100% rename from Examples/Tests/particle_fields_diags/inputs rename to Examples/Tests/particle_fields_diags/inputs_test_3d_particle_fields_diags diff --git a/Examples/Tests/particle_pusher/CMakeLists.txt b/Examples/Tests/particle_pusher/CMakeLists.txt new file mode 100644 index 00000000000..3d8f1496587 --- /dev/null +++ b/Examples/Tests/particle_pusher/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_particle_pusher # name + 3 # dims + 1 # nprocs + inputs_test_3d_particle_pusher # inputs + analysis.py # analysis + diags/diag1010000 # output + OFF # dependency +) diff --git a/Examples/Tests/particle_pusher/analysis_pusher.py b/Examples/Tests/particle_pusher/analysis.py similarity index 76% rename from Examples/Tests/particle_pusher/analysis_pusher.py rename to Examples/Tests/particle_pusher/analysis.py index 0d9e3a743f0..acef0e819d3 100755 --- a/Examples/Tests/particle_pusher/analysis_pusher.py +++ b/Examples/Tests/particle_pusher/analysis.py @@ -27,19 +27,19 @@ import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI tolerance = 0.001 filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) ad = ds.all_data() -x = ad['particle_position_x'].to_ndarray() +x = ad["particle_position_x"].to_ndarray() -print('error = ', abs(x)) -print('tolerance = ', tolerance) -assert(abs(x) < tolerance) +print("error = ", abs(x)) +print("tolerance = ", tolerance) +assert abs(x) < tolerance test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/particle_pusher/inputs_3d b/Examples/Tests/particle_pusher/inputs_test_3d_particle_pusher similarity index 100% rename from Examples/Tests/particle_pusher/inputs_3d rename to Examples/Tests/particle_pusher/inputs_test_3d_particle_pusher diff --git a/Examples/Tests/particle_thermal_boundary/CMakeLists.txt b/Examples/Tests/particle_thermal_boundary/CMakeLists.txt new file mode 100644 index 00000000000..eeae6660e02 --- /dev/null +++ b/Examples/Tests/particle_thermal_boundary/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_particle_thermal_boundary # name + 2 # dims + 2 # nprocs + inputs_test_2d_particle_thermal_boundary # inputs + analysis.py # analysis + diags/diag1002000 # output + OFF # dependency +) diff --git a/Examples/Tests/particle_thermal_boundary/analysis_2d.py b/Examples/Tests/particle_thermal_boundary/analysis.py similarity index 58% rename from Examples/Tests/particle_thermal_boundary/analysis_2d.py rename to Examples/Tests/particle_thermal_boundary/analysis.py index db14479af2c..49f33b5b805 100755 --- a/Examples/Tests/particle_thermal_boundary/analysis_2d.py +++ b/Examples/Tests/particle_thermal_boundary/analysis.py @@ -19,19 +19,19 @@ import numpy as np -sys.path.insert(1,'../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -FE_rdiag = './diags/reducedfiles/EF.txt' -init_Fenergy = np.loadtxt(FE_rdiag)[1,2] -final_Fenergy = np.loadtxt(FE_rdiag)[-1,2] -assert(final_Fenergy/init_Fenergy < 40) -assert(final_Fenergy < 5.e-5) +FE_rdiag = "./diags/reducedfiles/EF.txt" +init_Fenergy = np.loadtxt(FE_rdiag)[1, 2] +final_Fenergy = np.loadtxt(FE_rdiag)[-1, 2] +assert final_Fenergy / init_Fenergy < 40 +assert final_Fenergy < 5.0e-5 -PE_rdiag = './diags/reducedfiles/EN.txt' -init_Penergy = np.loadtxt(PE_rdiag)[0,2] -final_Penergy = np.loadtxt(PE_rdiag)[-1,2] -assert( abs(final_Penergy - init_Penergy)/init_Penergy < 0.02) +PE_rdiag = "./diags/reducedfiles/EN.txt" +init_Penergy = np.loadtxt(PE_rdiag)[0, 2] +final_Penergy = np.loadtxt(PE_rdiag)[-1, 2] +assert abs(final_Penergy - init_Penergy) / init_Penergy < 0.02 filename = sys.argv[1] test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/particle_thermal_boundary/inputs_2d b/Examples/Tests/particle_thermal_boundary/inputs_test_2d_particle_thermal_boundary similarity index 100% rename from Examples/Tests/particle_thermal_boundary/inputs_2d rename to Examples/Tests/particle_thermal_boundary/inputs_test_2d_particle_thermal_boundary diff --git a/Examples/Tests/particles_in_pml/CMakeLists.txt b/Examples/Tests/particles_in_pml/CMakeLists.txt new file mode 100644 index 00000000000..fb539461ec2 --- /dev/null +++ b/Examples/Tests/particles_in_pml/CMakeLists.txt @@ -0,0 +1,43 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_particles_in_pml # name + 2 # dims + 2 # nprocs + inputs_test_2d_particles_in_pml # inputs + analysis_particles_in_pml.py # analysis + diags/diag1000180 # output + OFF # dependency +) + +add_warpx_test( + test_2d_particles_in_pml_mr # name + 2 # dims + 2 # nprocs + inputs_test_2d_particles_in_pml_mr # inputs + analysis_particles_in_pml.py # analysis + diags/diag1000300 # output + OFF # dependency +) + +add_warpx_test( + test_3d_particles_in_pml # name + 3 # dims + 2 # nprocs + inputs_test_3d_particles_in_pml # inputs + analysis_particles_in_pml.py # analysis + diags/diag1000120 # output + OFF # dependency +) + +add_warpx_test( + test_3d_particles_in_pml_mr # name + 3 # dims + 2 # nprocs + inputs_test_3d_particles_in_pml_mr # inputs + analysis_particles_in_pml.py # analysis + diags/diag1000200 # output + OFF # dependency +) +label_warpx_test(test_3d_particles_in_pml_mr slow) diff --git a/Examples/Tests/particles_in_pml/analysis_particles_in_pml.py b/Examples/Tests/particles_in_pml/analysis_particles_in_pml.py index 1d1a8959edd..df106976e78 100755 --- a/Examples/Tests/particles_in_pml/analysis_particles_in_pml.py +++ b/Examples/Tests/particles_in_pml/analysis_particles_in_pml.py @@ -17,21 +17,22 @@ PML, this test fails, since the particles leave a spurious charge, with associated fields, behind them. """ + import os import sys import yt yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Open plotfile specified in command line filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) # When extracting the fields, choose the right dimensions -dimensions = [ n_pts for n_pts in ds.domain_dimensions ] +dimensions = [n_pts for n_pts in ds.domain_dimensions] if ds.max_level == 1: dimensions[0] *= 2 dimensions[1] *= 2 @@ -39,12 +40,14 @@ dimensions[2] *= 2 # Check that the field is low enough -ad0 = ds.covering_grid(level=ds.max_level, left_edge=ds.domain_left_edge, dims=dimensions) -Ex_array = ad0[('mesh','Ex')].to_ndarray() -Ey_array = ad0[('mesh','Ey')].to_ndarray() -Ez_array = ad0[('mesh','Ez')].to_ndarray() +ad0 = ds.covering_grid( + level=ds.max_level, left_edge=ds.domain_left_edge, dims=dimensions +) +Ex_array = ad0[("mesh", "Ex")].to_ndarray() +Ey_array = ad0[("mesh", "Ey")].to_ndarray() +Ez_array = ad0[("mesh", "Ez")].to_ndarray() max_Efield = max(Ex_array.max(), Ey_array.max(), Ez_array.max()) -print( "max_Efield = %s" %max_Efield ) +print("max_Efield = %s" % max_Efield) # The field associated with the particle does not have # the same amplitude in 2d and 3d diff --git a/Examples/Tests/particles_in_pml/inputs_2d b/Examples/Tests/particles_in_pml/inputs_test_2d_particles_in_pml similarity index 100% rename from Examples/Tests/particles_in_pml/inputs_2d rename to Examples/Tests/particles_in_pml/inputs_test_2d_particles_in_pml diff --git a/Examples/Tests/particles_in_pml/inputs_mr_2d b/Examples/Tests/particles_in_pml/inputs_test_2d_particles_in_pml_mr similarity index 100% rename from Examples/Tests/particles_in_pml/inputs_mr_2d rename to Examples/Tests/particles_in_pml/inputs_test_2d_particles_in_pml_mr diff --git a/Examples/Tests/particles_in_pml/inputs_3d b/Examples/Tests/particles_in_pml/inputs_test_3d_particles_in_pml similarity index 100% rename from Examples/Tests/particles_in_pml/inputs_3d rename to Examples/Tests/particles_in_pml/inputs_test_3d_particles_in_pml diff --git a/Examples/Tests/particles_in_pml/inputs_mr_3d b/Examples/Tests/particles_in_pml/inputs_test_3d_particles_in_pml_mr similarity index 100% rename from Examples/Tests/particles_in_pml/inputs_mr_3d rename to Examples/Tests/particles_in_pml/inputs_test_3d_particles_in_pml_mr diff --git a/Examples/Tests/pass_mpi_communicator/CMakeLists.txt b/Examples/Tests/pass_mpi_communicator/CMakeLists.txt new file mode 100644 index 00000000000..ac60636b931 --- /dev/null +++ b/Examples/Tests/pass_mpi_communicator/CMakeLists.txt @@ -0,0 +1,16 @@ +# Add tests (alphabetical order) ############################################## +# + +# TODO +# - Enable in pyAMReX (https://github.com/AMReX-Codes/pyamrex/issues/163) +# - Enable related lines in input script +# - Enable analysis script +add_warpx_test( + test_2d_pass_mpi_comm_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_pass_mpi_comm_picmi.py # inputs + OFF #analysis.py # analysis + OFF # output + OFF # dependency +) diff --git a/Examples/Tests/pass_mpi_communicator/PICMI_inputs_2d.py b/Examples/Tests/pass_mpi_communicator/PICMI_inputs_2d.py deleted file mode 100755 index 66f259da2ef..00000000000 --- a/Examples/Tests/pass_mpi_communicator/PICMI_inputs_2d.py +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env python3 -# -# --- Test if MPI_communicator is correctly passed from Python to CPP -# --- This test should be run with MPI enabled -# --- Inputs taken from langmuir_2d. Runs 10 steps, and will check -# --- if the correct amount of processors are initialized in AMReX. - -from mpi4py import MPI - -from pywarpx import picmi - -constants = picmi.constants - -########################## -# MPI communicator setup -########################## - -# split processor 0 into separate communicator from others -comm_world = MPI.COMM_WORLD -rank = comm_world.Get_rank() -if rank == 0: - color = 0 -else: - color = 1 -new_comm = comm_world.Split(color) - -########################## -# physics parameters -########################## - -# different communicators will be passed different plasma density -plasma_density = [1.e18, 1.e19] -plasma_xmin = 0. -plasma_x_velocity = 0.1*constants.c - -########################## -# numerics parameters -########################## - -# --- Number of time steps -max_steps = 10 -diagnostic_intervals = "::10" - -# --- Grid -nx = 64 -ny = 64 - -xmin = -20.e-6 -ymin = -20.e-6 -xmax = +20.e-6 -ymax = +20.e-6 - -number_per_cell_each_dim = [2,2] - -########################## -# physics components -########################## - -uniform_plasma = picmi.UniformDistribution(density = plasma_density[color], - upper_bound = [0., None, None], - directed_velocity = [0.1*constants.c, 0., 0.]) - -electrons = picmi.Species(particle_type='electron', name='electrons', initial_distribution=uniform_plasma) - -########################## -# numerics components -########################## - -grid = picmi.Cartesian2DGrid(number_of_cells = [nx, ny], - lower_bound = [xmin, ymin], - upper_bound = [xmax, ymax], - lower_boundary_conditions = ['periodic', 'periodic'], - upper_boundary_conditions = ['periodic', 'periodic'], - moving_window_velocity = [0., 0., 0.], - warpx_max_grid_size = 32) - -solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.) - -########################## -# diagnostics -########################## - -field_diag = picmi.FieldDiagnostic(name = f'diag{color + 1}', - grid = grid, - period = diagnostic_intervals, - data_list = ['Ex', 'Jx'], - write_dir = '.', - warpx_file_prefix = f'Python_pass_mpi_comm_plt{color + 1}_') - -part_diag = picmi.ParticleDiagnostic(name = f'diag{color + 1}', - period = diagnostic_intervals, - species = [electrons], - data_list = ['weighting', 'ux']) - -########################## -# simulation setup -########################## - -sim = picmi.Simulation(solver = solver, - max_steps = max_steps, - verbose = 1, - warpx_current_deposition_algo = 'direct') - -sim.add_species(electrons, - layout = picmi.GriddedLayout(n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid)) - -sim.add_diagnostic(field_diag) -sim.add_diagnostic(part_diag) - -########################## -# simulation run -########################## - -# TODO: Enable in pyAMReX, then enable lines in PICMI_inputs_2d.py again -# https://github.com/AMReX-Codes/pyamrex/issues/163 - -#sim.step(max_steps, mpi_comm=new_comm) - -########################## -# test -########################## - -# NOTE: Some tests are done in this input PICMI file. These tests -# check that amrex initialized the correct amount of procs and -# that the procs ranks in amrex are correct. -# If any of these tests fail, the terminal will print that the -# program crashed. - -# TODO: Enable in pyAMReX, then enable lines in PICMI_inputs_2d.py again -# https://github.com/AMReX-Codes/pyamrex/issues/163 -#comm_world_size = comm_world.size -#new_comm_size = new_comm.size - -#if color == 0: -# # verify that communicator contains correct number of procs (1) -# assert sim.extension.getNProcs() == comm_world_size - 1 -# assert sim.extension.getNProcs() == new_comm_size - -#else: -# # verify that amrex initialized with 1 fewer proc than comm world -# assert sim.extension.getNProcs() == comm_world_size - 1 -# assert sim.extension.getNProcs() == new_comm_size - - # verify that amrex proc ranks are offset by -1 from - # world comm proc ranks -# assert libwarpx.amr.ParallelDescriptor.MyProc() == rank - 1 diff --git a/Examples/Tests/pass_mpi_communicator/analysis.py b/Examples/Tests/pass_mpi_communicator/analysis.py index 9a622943127..041687c4775 100755 --- a/Examples/Tests/pass_mpi_communicator/analysis.py +++ b/Examples/Tests/pass_mpi_communicator/analysis.py @@ -1,19 +1,19 @@ #!/usr/bin/env python3 # This is a script that analyses the simulation results from -# the script `PICMI_inputs_2d`. +# the script `inputs_test_2d_pass_mpi_comm_picmi.py`. import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import yt yt.funcs.mylog.setLevel(50) import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksum # this will be the name of the first plot file @@ -25,56 +25,56 @@ test_name2 = fn2[:-10] -checksum1 = checksum.Checksum(test_name1, fn1, do_fields=True, - do_particles=True) +checksum1 = checksum.Checksum(test_name1, fn1, do_fields=True, do_particles=True) -checksum2 = checksum.Checksum(test_name2, fn2, do_fields=True, - do_particles=True) +checksum2 = checksum.Checksum(test_name2, fn2, do_fields=True, do_particles=True) -rtol=1.e-9 -atol=1.e-40 +rtol = 1.0e-9 +atol = 1.0e-40 # Evaluate checksums against each other, adapted from # Checksum.evaluate() method # Dictionaries have same outer keys (levels, species)? -if (checksum1.data.keys() != checksum2.data.keys()): - print("ERROR: plotfile 1 and plotfile 2 checksums " - "have different outer keys:") +if checksum1.data.keys() != checksum2.data.keys(): + print("ERROR: plotfile 1 and plotfile 2 checksums " "have different outer keys:") print("Plot1: %s" % checksum1.data.keys()) print("Plot2: %s" % checksum2.data.keys()) sys.exit(1) # Dictionaries have same inner keys (field and particle quantities)? for key1 in checksum1.data.keys(): - if (checksum1.data[key1].keys() != checksum2.data[key1].keys()): - print("ERROR: plotfile 1 and plotfile 2 checksums have " - "different inner keys:") + if checksum1.data[key1].keys() != checksum2.data[key1].keys(): + print( + "ERROR: plotfile 1 and plotfile 2 checksums have " "different inner keys:" + ) print("Common outer keys: %s" % checksum2.data.keys()) - print("Plotfile 1 inner keys in %s: %s" - % (key1, checksum1.data[key1].keys())) - print("Plotfile 2 inner keys in %s: %s" - % (key1, checksum2.data[key1].keys())) + print("Plotfile 1 inner keys in %s: %s" % (key1, checksum1.data[key1].keys())) + print("Plotfile 2 inner keys in %s: %s" % (key1, checksum2.data[key1].keys())) sys.exit(1) # Dictionaries have same values? checksums_same = False for key1 in checksum1.data.keys(): for key2 in checksum1.data[key1].keys(): - passed = np.isclose(checksum2.data[key1][key2], - checksum1.data[key1][key2], - rtol=rtol, atol=atol) + passed = np.isclose( + checksum2.data[key1][key2], checksum1.data[key1][key2], rtol=rtol, atol=atol + ) # skip over these, since they will be the same if communicators # have same number of procs if key2 in ["particle_cpu", "particle_id", "particle_position_y"]: continue if passed: - print("ERROR: plotfile 1 and plotfile 2 checksums have " - "same values for key [%s,%s]" % (key1, key2)) - print("Plotfile 1: [%s,%s] %.15e" - % (key1, key2, checksum1.data[key1][key2])) - print("Plotfile 2: [%s,%s] %.15e" - % (key1, key2, checksum2.data[key1][key2])) + print( + "ERROR: plotfile 1 and plotfile 2 checksums have " + "same values for key [%s,%s]" % (key1, key2) + ) + print( + "Plotfile 1: [%s,%s] %.15e" % (key1, key2, checksum1.data[key1][key2]) + ) + print( + "Plotfile 2: [%s,%s] %.15e" % (key1, key2, checksum2.data[key1][key2]) + ) checksums_same = True if checksums_same: sys.exit(1) diff --git a/Examples/Tests/pass_mpi_communicator/inputs_test_2d_pass_mpi_comm_picmi.py b/Examples/Tests/pass_mpi_communicator/inputs_test_2d_pass_mpi_comm_picmi.py new file mode 100755 index 00000000000..c87a7a0045c --- /dev/null +++ b/Examples/Tests/pass_mpi_communicator/inputs_test_2d_pass_mpi_comm_picmi.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python3 +# +# --- Test if MPI_communicator is correctly passed from Python to CPP +# --- This test should be run with MPI enabled +# --- Inputs taken from langmuir_2d. Runs 10 steps, and will check +# --- if the correct amount of processors are initialized in AMReX. + +from mpi4py import MPI + +from pywarpx import picmi + +constants = picmi.constants + +########################## +# MPI communicator setup +########################## + +# split processor 0 into separate communicator from others +comm_world = MPI.COMM_WORLD +rank = comm_world.Get_rank() +if rank == 0: + color = 0 +else: + color = 1 +new_comm = comm_world.Split(color) + +########################## +# physics parameters +########################## + +# different communicators will be passed different plasma density +plasma_density = [1.0e18, 1.0e19] +plasma_xmin = 0.0 +plasma_x_velocity = 0.1 * constants.c + +########################## +# numerics parameters +########################## + +# --- Number of time steps +max_steps = 10 +diagnostic_intervals = "::10" + +# --- Grid +nx = 64 +ny = 64 + +xmin = -20.0e-6 +ymin = -20.0e-6 +xmax = +20.0e-6 +ymax = +20.0e-6 + +number_per_cell_each_dim = [2, 2] + +########################## +# physics components +########################## + +uniform_plasma = picmi.UniformDistribution( + density=plasma_density[color], + upper_bound=[0.0, None, None], + directed_velocity=[0.1 * constants.c, 0.0, 0.0], +) + +electrons = picmi.Species( + particle_type="electron", name="electrons", initial_distribution=uniform_plasma +) + +########################## +# numerics components +########################## + +grid = picmi.Cartesian2DGrid( + number_of_cells=[nx, ny], + lower_bound=[xmin, ymin], + upper_bound=[xmax, ymax], + lower_boundary_conditions=["periodic", "periodic"], + upper_boundary_conditions=["periodic", "periodic"], + moving_window_velocity=[0.0, 0.0, 0.0], + warpx_max_grid_size=32, +) + +solver = picmi.ElectromagneticSolver(grid=grid, cfl=1.0) + +########################## +# diagnostics +########################## + +field_diag = picmi.FieldDiagnostic( + name=f"diag{color + 1}", + grid=grid, + period=diagnostic_intervals, + data_list=["Ex", "Jx"], + warpx_file_prefix=f"Python_pass_mpi_comm_plt{color + 1}_", +) + +part_diag = picmi.ParticleDiagnostic( + name=f"diag{color + 1}", + period=diagnostic_intervals, + species=[electrons], + data_list=["weighting", "ux"], +) + +########################## +# simulation setup +########################## + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + warpx_current_deposition_algo="direct", +) + +sim.add_species( + electrons, + layout=picmi.GriddedLayout( + n_macroparticle_per_cell=number_per_cell_each_dim, grid=grid + ), +) + +sim.add_diagnostic(field_diag) +sim.add_diagnostic(part_diag) + +########################## +# simulation run +########################## + +# TODO: Enable in pyAMReX, then enable lines in inputs_test_2d_pass_mpi_comm_picmi.py again +# https://github.com/AMReX-Codes/pyamrex/issues/163 + +# sim.step(max_steps, mpi_comm=new_comm) + +########################## +# test +########################## + +# NOTE: Some tests are done in this input PICMI file. These tests +# check that amrex initialized the correct amount of procs and +# that the procs ranks in amrex are correct. +# If any of these tests fail, the terminal will print that the +# program crashed. + +# TODO: Enable in pyAMReX, then enable lines in inputs_test_2d_pass_mpi_comm_picmi.py again +# https://github.com/AMReX-Codes/pyamrex/issues/163 +# comm_world_size = comm_world.size +# new_comm_size = new_comm.size + +# if color == 0: +# # verify that communicator contains correct number of procs (1) +# assert sim.extension.getNProcs() == comm_world_size - 1 +# assert sim.extension.getNProcs() == new_comm_size + +# else: +# # verify that amrex initialized with 1 fewer proc than comm world +# assert sim.extension.getNProcs() == comm_world_size - 1 +# assert sim.extension.getNProcs() == new_comm_size + +# verify that amrex proc ranks are offset by -1 from +# world comm proc ranks +# assert libwarpx.amr.ParallelDescriptor.MyProc() == rank - 1 diff --git a/Examples/Tests/pec/CMakeLists.txt b/Examples/Tests/pec/CMakeLists.txt new file mode 100644 index 00000000000..ec710f7d919 --- /dev/null +++ b/Examples/Tests/pec/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_pec_field # name + 3 # dims + 2 # nprocs + inputs_test_3d_pec_field # inputs + analysis_pec.py # analysis + diags/diag1000125 # output + OFF # dependency +) + +add_warpx_test( + test_3d_pec_field_mr # name + 3 # dims + 2 # nprocs + inputs_test_3d_pec_field_mr # inputs + analysis_pec_mr.py # analysis + diags/diag1000125 # output + OFF # dependency +) + +add_warpx_test( + test_3d_pec_particle # name + 3 # dims + 2 # nprocs + inputs_test_3d_pec_particle # inputs + analysis_default_regression.py # analysis + diags/diag1000020 # output + OFF # dependency +) diff --git a/Examples/Tests/pec/analysis_default_regression.py b/Examples/Tests/pec/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/pec/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/pec/analysis_pec.py b/Examples/Tests/pec/analysis_pec.py index 841cc06ae22..12907bb7846 100755 --- a/Examples/Tests/pec/analysis_pec.py +++ b/Examples/Tests/pec/analysis_pec.py @@ -17,7 +17,7 @@ import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import yt @@ -25,50 +25,61 @@ import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file fn = sys.argv[1] # Parameters (these parameters must match the parameters in `inputs.multi.rt`) -Ey_in = 1.e5 -E_th = 2.0*Ey_in +Ey_in = 1.0e5 +E_th = 2.0 * Ey_in # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) -Ey_array = data[('mesh','Ey')].to_ndarray() +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Ey_array = data[("mesh", "Ey")].to_ndarray() max_Ey_sim = Ey_array.max() min_Ey_sim = Ey_array.min() -max_Ey_error = abs(max_Ey_sim-E_th)/abs(E_th) -min_Ey_error = abs(min_Ey_sim - (-E_th))/abs(E_th) -print('Ey_max is %s: Max Eth is %s : Max error for Ey_max: %.2e' %(max_Ey_sim,E_th,max_Ey_error)) -print('Ey_min is %s: Min Eth is %s : Max error for Ey_min: %.2e' %(min_Ey_sim,(-E_th), min_Ey_error)) -error_rel = 0. -max_Ey_error_rel = max( error_rel, max_Ey_error ) -min_Ey_error_rel = max( error_rel, min_Ey_error ) +max_Ey_error = abs(max_Ey_sim - E_th) / abs(E_th) +min_Ey_error = abs(min_Ey_sim - (-E_th)) / abs(E_th) +print( + "Ey_max is %s: Max Eth is %s : Max error for Ey_max: %.2e" + % (max_Ey_sim, E_th, max_Ey_error) +) +print( + "Ey_min is %s: Min Eth is %s : Max error for Ey_min: %.2e" + % (min_Ey_sim, (-E_th), min_Ey_error) +) +error_rel = 0.0 +max_Ey_error_rel = max(error_rel, max_Ey_error) +min_Ey_error_rel = max(error_rel, min_Ey_error) # Plot the last field from the loop (Ez at iteration 40) -field = 'Ey' +field = "Ey" xCell = ds.domain_dimensions[0] yCell = ds.domain_dimensions[1] zCell = ds.domain_dimensions[2] -z_array = data['z'].to_ndarray() - -plt.figure(figsize=(8,4)) -plt.plot(z_array[int(xCell/2),int(yCell/2),:]-z_array[int(xCell/2),int(yCell/2),int(zCell/2)],Ey_array[int(xCell/2),int(yCell/2),:]) +z_array = data["z"].to_ndarray() + +plt.figure(figsize=(8, 4)) +plt.plot( + z_array[int(xCell / 2), int(yCell / 2), :] + - z_array[int(xCell / 2), int(yCell / 2), int(zCell / 2)], + Ey_array[int(xCell / 2), int(yCell / 2), :], +) plt.ylim(-1.2e-3, 1.2e-3) plt.ylim(-2.2e5, 2.2e5) plt.xlim(-4.0e-6, 4.000001e-6) -plt.xticks(np.arange(-4.e-6,4.000001e-6, step=1e-6)) -plt.xlabel('z (m)') -plt.ylabel(field +' (V/m)') +plt.xticks(np.arange(-4.0e-6, 4.000001e-6, step=1e-6)) +plt.xlabel("z (m)") +plt.ylabel(field + " (V/m)") plt.tight_layout() -plt.savefig('Ey_pec_analysis.png') +plt.savefig("Ey_pec_analysis.png") tolerance_rel = 0.01 @@ -77,12 +88,12 @@ print("max_Ey_error_rel : " + str(max_Ey_error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( max_Ey_error_rel < tolerance_rel ) -assert( min_Ey_error_rel < tolerance_rel ) +assert max_Ey_error_rel < tolerance_rel +assert min_Ey_error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, rtol=1.0e-3) else: checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/pec/analysis_pec_mr.py b/Examples/Tests/pec/analysis_pec_mr.py index e8aab4dcd6f..8361246b8dd 100755 --- a/Examples/Tests/pec/analysis_pec_mr.py +++ b/Examples/Tests/pec/analysis_pec_mr.py @@ -17,7 +17,7 @@ import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import yt @@ -25,51 +25,62 @@ import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file fn = sys.argv[1] # Parameters (these parameters must match the parameters in `inputs.multi.rt`) -Ey_in = 1.e5 -E_th = 2.0*Ey_in +Ey_in = 1.0e5 +E_th = 2.0 * Ey_in # Read the file ds = yt.load(fn) t0 = ds.current_time.to_value() -data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) -Ey_array = data[('mesh','Ey')].to_ndarray() +data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Ey_array = data[("mesh", "Ey")].to_ndarray() max_Ey_sim = Ey_array.max() min_Ey_sim = Ey_array.min() -max_Ey_error = abs(max_Ey_sim-E_th)/abs(E_th) -min_Ey_error = abs(min_Ey_sim - (-E_th))/abs(E_th) -print('Ey_max is %s: Max Eth is %s : Max error for Ey_max: %.2e' %(max_Ey_sim,E_th,max_Ey_error)) -print('Ey_min is %s: Min Eth is %s : Max error for Ey_min: %.2e' %(min_Ey_sim,(-E_th), min_Ey_error)) -error_rel = 0. -max_Ey_error_rel = max( error_rel, max_Ey_error ) -min_Ey_error_rel = max( error_rel, min_Ey_error ) +max_Ey_error = abs(max_Ey_sim - E_th) / abs(E_th) +min_Ey_error = abs(min_Ey_sim - (-E_th)) / abs(E_th) +print( + "Ey_max is %s: Max Eth is %s : Max error for Ey_max: %.2e" + % (max_Ey_sim, E_th, max_Ey_error) +) +print( + "Ey_min is %s: Min Eth is %s : Max error for Ey_min: %.2e" + % (min_Ey_sim, (-E_th), min_Ey_error) +) +error_rel = 0.0 +max_Ey_error_rel = max(error_rel, max_Ey_error) +min_Ey_error_rel = max(error_rel, min_Ey_error) # Plot the last field from the loop (Ez at iteration 40) # Plot the last field from the loop (Ez at iteration 40) -field = 'Ey' +field = "Ey" xCell = ds.domain_dimensions[0] yCell = ds.domain_dimensions[1] zCell = ds.domain_dimensions[2] -z_array = data['z'].to_ndarray() - -plt.figure(figsize=(8,4)) -plt.plot(z_array[int(xCell/2),int(yCell/2),:]-z_array[int(xCell/2),int(yCell/2),int(zCell/2)],Ey_array[int(xCell/2),int(yCell/2),:]) +z_array = data["z"].to_ndarray() + +plt.figure(figsize=(8, 4)) +plt.plot( + z_array[int(xCell / 2), int(yCell / 2), :] + - z_array[int(xCell / 2), int(yCell / 2), int(zCell / 2)], + Ey_array[int(xCell / 2), int(yCell / 2), :], +) plt.ylim(-1.2e-3, 1.2e-3) plt.ylim(-2.2e5, 2.2e5) plt.xlim(-4.0e-6, 4.000001e-6) -plt.xticks(np.arange(-4.e-6,4.000001e-6, step=1e-6)) -plt.xlabel('z (m)') -plt.ylabel(field +' (V/m)') +plt.xticks(np.arange(-4.0e-6, 4.000001e-6, step=1e-6)) +plt.xlabel("z (m)") +plt.ylabel(field + " (V/m)") plt.tight_layout() -plt.savefig('Ey_pec_analysis_mr.png') +plt.savefig("Ey_pec_analysis_mr.png") tolerance_rel = 0.05 @@ -77,12 +88,12 @@ print("max_Ey_error_rel : " + str(max_Ey_error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( max_Ey_error_rel < tolerance_rel ) -assert( min_Ey_error_rel < tolerance_rel ) +assert max_Ey_error_rel < tolerance_rel +assert min_Ey_error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, rtol=1.0e-3) else: checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/pec/inputs_field_PEC_3d b/Examples/Tests/pec/inputs_test_3d_pec_field similarity index 100% rename from Examples/Tests/pec/inputs_field_PEC_3d rename to Examples/Tests/pec/inputs_test_3d_pec_field diff --git a/Examples/Tests/pec/inputs_field_PEC_mr_3d b/Examples/Tests/pec/inputs_test_3d_pec_field_mr similarity index 100% rename from Examples/Tests/pec/inputs_field_PEC_mr_3d rename to Examples/Tests/pec/inputs_test_3d_pec_field_mr diff --git a/Examples/Tests/pec/inputs_particle_PEC_3d b/Examples/Tests/pec/inputs_test_3d_pec_particle similarity index 100% rename from Examples/Tests/pec/inputs_particle_PEC_3d rename to Examples/Tests/pec/inputs_test_3d_pec_particle diff --git a/Examples/Tests/performance_tests/automated_test_1_uniform_rest_32ppc b/Examples/Tests/performance_tests/automated_test_1_uniform_rest_32ppc deleted file mode 120000 index 169abb79fde..00000000000 --- a/Examples/Tests/performance_tests/automated_test_1_uniform_rest_32ppc +++ /dev/null @@ -1 +0,0 @@ -../../../Tools/PerformanceTests/automated_test_1_uniform_rest_32ppc \ No newline at end of file diff --git a/Examples/Tests/performance_tests/automated_test_2_uniform_rest_1ppc b/Examples/Tests/performance_tests/automated_test_2_uniform_rest_1ppc deleted file mode 120000 index 5f6c6d2ed5d..00000000000 --- a/Examples/Tests/performance_tests/automated_test_2_uniform_rest_1ppc +++ /dev/null @@ -1 +0,0 @@ -../../../Tools/PerformanceTests/automated_test_2_uniform_rest_1ppc \ No newline at end of file diff --git a/Examples/Tests/performance_tests/automated_test_3_uniform_drift_4ppc b/Examples/Tests/performance_tests/automated_test_3_uniform_drift_4ppc deleted file mode 120000 index 0fe17ba03cb..00000000000 --- a/Examples/Tests/performance_tests/automated_test_3_uniform_drift_4ppc +++ /dev/null @@ -1 +0,0 @@ -../../../Tools/PerformanceTests/automated_test_3_uniform_drift_4ppc \ No newline at end of file diff --git a/Examples/Tests/performance_tests/automated_test_4_labdiags_2ppc b/Examples/Tests/performance_tests/automated_test_4_labdiags_2ppc deleted file mode 120000 index 1e67353c400..00000000000 --- a/Examples/Tests/performance_tests/automated_test_4_labdiags_2ppc +++ /dev/null @@ -1 +0,0 @@ -../../../Tools/PerformanceTests/automated_test_4_labdiags_2ppc \ No newline at end of file diff --git a/Examples/Tests/performance_tests/automated_test_5_loadimbalance b/Examples/Tests/performance_tests/automated_test_5_loadimbalance deleted file mode 120000 index 40734b2fe9b..00000000000 --- a/Examples/Tests/performance_tests/automated_test_5_loadimbalance +++ /dev/null @@ -1 +0,0 @@ -../../../Tools/PerformanceTests/automated_test_5_loadimbalance \ No newline at end of file diff --git a/Examples/Tests/performance_tests/automated_test_6_output_2ppc b/Examples/Tests/performance_tests/automated_test_6_output_2ppc deleted file mode 120000 index 4be041eb91e..00000000000 --- a/Examples/Tests/performance_tests/automated_test_6_output_2ppc +++ /dev/null @@ -1 +0,0 @@ -../../../Tools/PerformanceTests/automated_test_6_output_2ppc \ No newline at end of file diff --git a/Examples/Tests/photon_pusher/CMakeLists.txt b/Examples/Tests/photon_pusher/CMakeLists.txt new file mode 100644 index 00000000000..7926d8faeaf --- /dev/null +++ b/Examples/Tests/photon_pusher/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_photon_pusher # name + 3 # dims + 2 # nprocs + inputs_test_3d_photon_pusher # inputs + analysis.py # analysis + diags/diag1000050 # output + OFF # dependency +) diff --git a/Examples/Tests/photon_pusher/analysis.py b/Examples/Tests/photon_pusher/analysis.py new file mode 100755 index 00000000000..9135ad981ba --- /dev/null +++ b/Examples/Tests/photon_pusher/analysis.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python3 + +# Copyright 2019 Luca Fedeli, Maxence Thevenet, Weiqun Zhang +# +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +import os +import sys + +import numpy as np +import yt + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# This script checks if photons initialized with different momenta and +# different initial directions propagate along straight lines at the speed of +# light. The plotfile to be analyzed is passed as a command line argument. + +# If the script is run without a command line argument, it regenerates a new +# inputfile according to the initial conditions listed below. + + +# Physical constants +c = 299792458.0 +m_e = 9.1093837015e-31 +# ________________________________________ + +# Test cases +spec_names = [ + "p_xp_1", + "p_xn_1", + "p_yp_1", + "p_yn_1", + "p_zp_1", + "p_zn_1", + "p_dp_1", + "p_dn_1", + "p_xp_10", + "p_xn_10", + "p_yp_10", + "p_yn_10", + "p_zp_10", + "p_zn_10", + "p_dp_10", + "p_dn_10", +] +# photon momenta are in units of m_e c +mxp1 = np.array([1, 0.0, 0.0]) +mxn1 = np.array([-1, 0.0, 0.0]) +myp1 = np.array([0.0, 1, 0.0]) +myn1 = np.array([0.0, -1, 0.0]) +mzp1 = np.array([0.0, 0.0, 1]) +mzn1 = np.array([0.0, 0.0, -1]) +mdp1 = np.array([1, 1, 1]) +mdn1 = np.array([-1, -1, -1]) +mxp10 = np.array([10, 0.0, 0.0]) +mxn10 = np.array([-10, 0.0, 0.0]) +myp10 = np.array([0.0, 10, 0.0]) +myn10 = np.array([0.0, -10, 0.0]) +mzp10 = np.array([0.0, 0.0, 10]) +mzn10 = np.array([0.0, 0.0, -10]) +mdp10 = np.array([10, 10, 10]) +mdn10 = np.array([-10, -10, -10]) +gamma_beta_list = np.array( + [ + mxp1, + mxn1, + myp1, + myn1, + mzp1, + mzn1, + mdp1, + mdn1, + mxp10, + mxn10, + myp10, + myn10, + mzp10, + mzn10, + mdp10, + mdn10, + ] +) +init_pos = np.array([0.0, 0.0, 0.0]) +# ________________________________________ + +# Tolerance +tol_pos = 1.0e-14 +tol_mom = 0.0 # momentum should be conserved exactly +# ________________________________________ + +# Input filename +inputname = "inputs" +# ________________________________________ + + +# This function reads the WarpX plotfile given as the first command-line +# argument, and check if the position of each photon agrees with theory. +def check(): + filename = sys.argv[1] + data_set_end = yt.load(filename) + + sim_time = data_set_end.current_time.to_value() + + # expected positions list + ll = sim_time * c + answ_pos = init_pos + ll * gamma_beta_list / np.linalg.norm( + gamma_beta_list, axis=1, keepdims=True + ) + + # expected momenta list + answ_mom = m_e * c * gamma_beta_list # momenta don't change + + # simulation results + all_data = data_set_end.all_data() + res_pos = [ + np.array( + [ + all_data[sp, "particle_position_x"].v[0], + all_data[sp, "particle_position_y"].v[0], + all_data[sp, "particle_position_z"].v[0], + ] + ) + for sp in spec_names + ] + res_mom = [ + np.array( + [ + all_data[sp, "particle_momentum_x"].v[0], + all_data[sp, "particle_momentum_y"].v[0], + all_data[sp, "particle_momentum_z"].v[0], + ] + ) + for sp in spec_names + ] + + # check discrepancies + disc_pos = [ + np.linalg.norm(a - b) / np.linalg.norm(b) for a, b in zip(res_pos, answ_pos) + ] + disc_mom = [ + np.linalg.norm(a - b) / np.linalg.norm(b) for a, b in zip(res_mom, answ_mom) + ] + + print("max(disc_pos) = %s" % max(disc_pos)) + print("tol_pos = %s" % tol_pos) + print("max(disc_mom) = %s" % max(disc_mom)) + print("tol_mom = %s" % tol_mom) + + assert (max(disc_pos) <= tol_pos) and (max(disc_mom) <= tol_mom) + + test_name = os.path.split(os.getcwd())[1] + checksumAPI.evaluate_checksum(test_name, filename) + + +# This function generates the input file to test the photon pusher. +def generate(): + with open(inputname, "w") as f: + f.write("#Automatically generated inputfile\n") + f.write("#Run check.py without arguments to regenerate\n") + f.write("#\n\n") + f.write("max_step = 50\n") + f.write("amr.n_cell = 64 64 64\n") + f.write("amr.max_level = 0\n") + f.write("amr.blocking_factor = 8\n") + f.write("amr.max_grid_size = 8\n") + f.write("amr.plot_int = 1\n") + f.write("geometry.dims = 3\n") + f.write("boundary.field_lo = periodic periodic periodic\n") + f.write("boundary.field_hi = periodic periodic periodic\n") + f.write("geometry.prob_lo = -0.5e-6 -0.5e-6 -0.5e-6\n") + f.write("geometry.prob_hi = 0.5e-6 0.5e-6 0.5e-6\n") + f.write("algo.charge_deposition = standard\n") + f.write("algo.field_gathering = energy-conserving\n") + f.write("warpx.cfl = 1.0\n") + + f.write("particles.species_names = {}\n".format(" ".join(spec_names))) + f.write("particles.photon_species = {}\n".format(" ".join(spec_names))) + + f.write("\namr.plot_int = 50\n\n") + + for name in spec_names: + f.write("diag1.{}.variables = ux uy uz\n".format(name)) + + f.write("\n") + + data = zip(spec_names, gamma_beta_list) + for case in data: + name = case[0] + velx, vely, velz = case[1] + f.write("{}.species_type = photon\n".format(name)) + f.write('{}.injection_style = "SingleParticle"\n'.format(name)) + f.write( + "{}.single_particle_pos = {} {} {}\n".format( + name, init_pos[0], init_pos[1], init_pos[2] + ) + ) + f.write("{}.single_particle_u = {} {} {}\n".format(name, velx, vely, velz)) + f.write("{}.single_particle_weight = 1.0\n".format(name)) + f.write("\n") + + +def main(): + if len(sys.argv) < 2: + generate() + else: + check() + + +if __name__ == "__main__": + main() diff --git a/Examples/Tests/photon_pusher/analysis_photon_pusher.py b/Examples/Tests/photon_pusher/analysis_photon_pusher.py deleted file mode 100755 index 7518bd5adb0..00000000000 --- a/Examples/Tests/photon_pusher/analysis_photon_pusher.py +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2019 Luca Fedeli, Maxence Thevenet, Weiqun Zhang -# -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import os -import sys - -import numpy as np -import yt - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -#This script checks if photons initialized with different momenta and -#different initial directions propagate along straight lines at the speed of -#light. The plotfile to be analyzed is passed as a command line argument. - -#If the script is run without a command line argument, it regenerates a new -#inputfile according to the initial conditions listed below. - - -#Physical constants -c = 299792458. -m_e = 9.1093837015e-31 -#________________________________________ - -#Test cases -spec_names = ["p_xp_1", "p_xn_1", "p_yp_1", "p_yn_1", - "p_zp_1", "p_zn_1","p_dp_1", "p_dn_1", - "p_xp_10", "p_xn_10", "p_yp_10", "p_yn_10", - "p_zp_10", "p_zn_10", "p_dp_10", "p_dn_10"] -#photon momenta are in units of m_e c -mxp1 = np.array([1, 0.0, 0.0]) -mxn1 = np.array([-1, 0.0, 0.0]) -myp1 = np.array([0.0, 1, 0.0]) -myn1 = np.array([0.0, -1, 0.0]) -mzp1 = np.array([0.0, 0.0, 1]) -mzn1 = np.array([0.0, 0.0, -1]) -mdp1 = np.array([1, 1, 1]) -mdn1 = np.array([-1, -1, -1]) -mxp10 = np.array([10, 0.0, 0.0]) -mxn10 = np.array([-10, 0.0, 0.0]) -myp10 = np.array([0.0, 10, 0.0]) -myn10 = np.array([0.0, -10, 0.0]) -mzp10 = np.array([0.0, 0.0, 10]) -mzn10 = np.array([0.0, 0.0, -10]) -mdp10 = np.array([10, 10, 10]) -mdn10 = np.array([-10,-10, -10]) -gamma_beta_list = np.array([mxp1, mxn1, myp1, myn1, mzp1, mzn1, mdp1, mdn1, - mxp10, mxn10, myp10, myn10, mzp10, mzn10, mdp10, mdn10]) -init_pos = np.array([0.0, 0.0, 0.0]) -#________________________________________ - -#Tolerance -tol_pos = 1.0e-14; -tol_mom = 0.0; #momentum should be conserved exactly -#________________________________________ - -#Input filename -inputname = "inputs" -#________________________________________ - -# This function reads the WarpX plotfile given as the first command-line -# argument, and check if the position of each photon agrees with theory. -def check(): - filename = sys.argv[1] - data_set_end = yt.load(filename) - - sim_time = data_set_end.current_time.to_value() - - #expected positions list - ll = sim_time*c - answ_pos = init_pos + \ - ll*gamma_beta_list/np.linalg.norm(gamma_beta_list,axis=1, keepdims=True) - - #expected momenta list - answ_mom = m_e * c *gamma_beta_list #momenta don't change - - #simulation results - all_data = data_set_end.all_data() - res_pos = [np.array([ - all_data[sp, 'particle_position_x'].v[0], - all_data[sp, 'particle_position_y'].v[0], - all_data[sp, 'particle_position_z'].v[0]]) - for sp in spec_names] - res_mom = [np.array([ - all_data[sp, 'particle_momentum_x'].v[0], - all_data[sp, 'particle_momentum_y'].v[0], - all_data[sp, 'particle_momentum_z'].v[0]]) - for sp in spec_names] - - #check discrepancies - disc_pos = [np.linalg.norm(a-b)/np.linalg.norm(b) - for a,b in zip(res_pos, answ_pos)] - disc_mom = [np.linalg.norm(a-b)/np.linalg.norm(b) - for a,b in zip(res_mom, answ_mom)] - - print("max(disc_pos) = %s" %max(disc_pos)) - print("tol_pos = %s" %tol_pos) - print("max(disc_mom) = %s" %max(disc_mom)) - print("tol_mom = %s" %tol_mom) - - assert ((max(disc_pos) <= tol_pos) and (max(disc_mom) <= tol_mom)) - - test_name = os.path.split(os.getcwd())[1] - checksumAPI.evaluate_checksum(test_name, filename) - -# This function generates the input file to test the photon pusher. -def generate(): - with open(inputname,'w') as f: - f.write("#Automatically generated inputfile\n") - f.write("#Run check.py without arguments to regenerate\n") - f.write("#\n\n") - f.write("max_step = 50\n") - f.write("amr.n_cell = 64 64 64\n") - f.write("amr.max_level = 0\n") - f.write("amr.blocking_factor = 8\n") - f.write("amr.max_grid_size = 8\n") - f.write("amr.plot_int = 1\n") - f.write("geometry.dims = 3\n") - f.write("boundary.field_lo = periodic periodic periodic\n") - f.write("boundary.field_hi = periodic periodic periodic\n") - f.write("geometry.prob_lo = -0.5e-6 -0.5e-6 -0.5e-6\n") - f.write("geometry.prob_hi = 0.5e-6 0.5e-6 0.5e-6\n") - f.write("algo.charge_deposition = standard\n") - f.write("algo.field_gathering = energy-conserving\n") - f.write("warpx.cfl = 1.0\n") - - f.write("particles.species_names = {}\n".format(' '.join(spec_names))) - f.write("particles.photon_species = {}\n".format(' '.join(spec_names))) - - f.write("\namr.plot_int = 50\n\n") - - for name in spec_names: - f.write("diag1.{}.variables = ux uy uz\n".format(name)) - - f.write("\n") - - data = zip(spec_names, gamma_beta_list) - for case in data: - name = case[0] - velx, vely ,velz = case[1] - f.write("{}.species_type = photon\n".format(name)) - f.write('{}.injection_style = "SingleParticle"\n'.format(name)) - f.write("{}.single_particle_pos = {} {} {}\n". - format(name, init_pos[0], init_pos[1], init_pos[2])) - f.write("{}.single_particle_u = {} {} {}\n". - format(name, velx, vely, velz)) - f.write("{}.single_particle_weight = 1.0\n".format(name)) - f.write("\n".format(name)) - -def main(): - if (len(sys.argv) < 2): - generate() - else: - check() - -if __name__ == "__main__": - main() diff --git a/Examples/Tests/photon_pusher/inputs_3d b/Examples/Tests/photon_pusher/inputs_test_3d_photon_pusher similarity index 100% rename from Examples/Tests/photon_pusher/inputs_3d rename to Examples/Tests/photon_pusher/inputs_test_3d_photon_pusher diff --git a/Examples/Tests/plasma_lens/CMakeLists.txt b/Examples/Tests/plasma_lens/CMakeLists.txt new file mode 100644 index 00000000000..bc13ae433bc --- /dev/null +++ b/Examples/Tests/plasma_lens/CMakeLists.txt @@ -0,0 +1,52 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_plasma_lens # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_lens # inputs + analysis.py # analysis + diags/diag1000084 # output + OFF # dependency +) + +add_warpx_test( + test_3d_plasma_lens_boosted # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_lens_boosted # inputs + analysis.py # analysis + diags/diag1000084 # output + OFF # dependency +) + +add_warpx_test( + test_3d_plasma_lens_hard_edged # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_lens_hard_edged # inputs + analysis.py # analysis + diags/diag1000084 # output + OFF # dependency +) + +add_warpx_test( + test_3d_plasma_lens_picmi # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_lens_picmi.py # inputs + analysis.py # analysis + diags/diag1000084 # output + OFF # dependency +) + +add_warpx_test( + test_3d_plasma_lens_short # name + 3 # dims + 2 # nprocs + inputs_test_3d_plasma_lens_short # inputs + analysis.py # analysis + diags/diag1000084 # output + OFF # dependency +) diff --git a/Examples/Tests/plasma_lens/PICMI_inputs_3d.py b/Examples/Tests/plasma_lens/PICMI_inputs_3d.py deleted file mode 100644 index 50d222bbf36..00000000000 --- a/Examples/Tests/plasma_lens/PICMI_inputs_3d.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -# Physical constants -c = picmi.constants.c -q_e = picmi.constants.q_e - -# Number of time steps -max_steps = 84 - -# Number of cells -nx = 16 -ny = 16 -nz = 16 - -# Physical domain -xmin = -1. -xmax = 1. -ymin = -1. -ymax = 1. -zmin = 0. -zmax = 2. - -# Create grid -grid = picmi.Cartesian3DGrid(number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions = ['dirichlet', 'dirichlet', 'dirichlet'], - upper_boundary_conditions = ['dirichlet', 'dirichlet', 'dirichlet'], - lower_boundary_conditions_particles = ['absorbing', 'absorbing', 'absorbing'], - upper_boundary_conditions_particles = ['absorbing', 'absorbing', 'absorbing']) - -# Particles -vel_z = 0.5*c -offset_x_particle = picmi.ParticleListDistribution(x = [0.05], - y = [0.], - z = [0.05], - ux = [0.], - uy = [0.], - uz = [vel_z], - weight = [1.]) - -offset_y_particle = picmi.ParticleListDistribution(x = [0.], - y = [0.04], - z = [0.05], - ux = [0.], - uy = [0.], - uz = [vel_z], - weight = [1.]) - -electrons = picmi.Species(particle_type = 'electron', - name = 'electrons', - initial_distribution = [offset_x_particle, offset_y_particle]) - -# Plasma lenses -plasma_lenses = picmi.PlasmaLens(period = 0.5, - starts = [0.1, 0.11, 0.12, 0.13], - lengths = [0.1, 0.11, 0.12, 0.13], - strengths_E = [600000., 800000., 600000., 200000.], - strengths_B = [0.0, 0.0, 0.0, 0.0]) - -# Electromagnetic solver -solver = picmi.ElectromagneticSolver(grid = grid, - method = 'Yee', - cfl = 0.7) - -# Diagnostics -part_diag1 = picmi.ParticleDiagnostic(name = 'diag1', - period = max_steps, - species = [electrons], - data_list = ['ux', 'uy', 'uz', 'x', 'y', 'z'], - write_dir = '.', - warpx_file_prefix = 'Python_plasma_lens_plt') - -field_diag1 = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = max_steps, - data_list = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], - write_dir = '.', - warpx_file_prefix = 'Python_plasma_lens_plt') -# Set up simulation -sim = picmi.Simulation(solver = solver, - max_steps = max_steps, - verbose = 1, - particle_shape = 'linear', - warpx_serialize_initial_conditions = 1, - warpx_do_dynamic_scheduling = 0) - -# Add plasma electrons -sim.add_species(electrons, layout = None) - -# Add the plasma lenses -sim.add_applied_field(plasma_lenses) - -# Add diagnostics -sim.add_diagnostic(part_diag1) -sim.add_diagnostic(field_diag1) - -# Write input file that can be used to run with the compiled version -#sim.write_input_file(file_name = 'inputs_3d_picmi') - -# Advance simulation until last time step -sim.step(max_steps) diff --git a/Examples/Tests/plasma_lens/analysis.py b/Examples/Tests/plasma_lens/analysis.py index 212e71087f9..11e2a084ac5 100755 --- a/Examples/Tests/plasma_lens/analysis.py +++ b/Examples/Tests/plasma_lens/analysis.py @@ -16,6 +16,7 @@ """ import os +import re import sys import numpy as np @@ -23,93 +24,112 @@ from scipy.constants import c, e, m_e yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) ad = ds.all_data() # Get final position of the particles. # There are two particles, one moves in x, the other in y. # The particles may not be in order, so determine which is which # by looking at their max positions in the respective planes. -i0 = np.argmax(np.abs(ad['electrons', 'particle_position_x'].v)) -i1 = np.argmax(np.abs(ad['electrons', 'particle_position_y'].v)) +i0 = np.argmax(np.abs(ad["electrons", "particle_position_x"].v)) +i1 = np.argmax(np.abs(ad["electrons", "particle_position_y"].v)) -xx_sim = ad['electrons', 'particle_position_x'].v[i0] -yy_sim = ad['electrons', 'particle_position_y'].v[i1] -zz_sim0 = ad['electrons', 'particle_position_z'].v[i0] -zz_sim1 = ad['electrons', 'particle_position_z'].v[i1] +xx_sim = ad["electrons", "particle_position_x"].v[i0] +yy_sim = ad["electrons", "particle_position_y"].v[i1] +zz_sim0 = ad["electrons", "particle_position_z"].v[i0] +zz_sim1 = ad["electrons", "particle_position_z"].v[i1] -ux_sim = ad['electrons', 'particle_momentum_x'].v[i0]/m_e -uy_sim = ad['electrons', 'particle_momentum_y'].v[i1]/m_e +ux_sim = ad["electrons", "particle_momentum_x"].v[i0] / m_e +uy_sim = ad["electrons", "particle_momentum_y"].v[i1] / m_e -if 'warpx.gamma_boost' in ds.parameters: - gamma_boost = float(ds.parameters.get('warpx.gamma_boost')) - uz_boost = np.sqrt(gamma_boost*gamma_boost - 1.)*c +if "warpx.gamma_boost" in ds.parameters: + gamma_boost = float(ds.parameters.get("warpx.gamma_boost")) + uz_boost = np.sqrt(gamma_boost * gamma_boost - 1.0) * c time = ds.current_time.to_value() - zz_sim0 = gamma_boost*zz_sim0 + uz_boost*time - zz_sim1 = gamma_boost*zz_sim1 + uz_boost*time + zz_sim0 = gamma_boost * zz_sim0 + uz_boost * time + zz_sim1 = gamma_boost * zz_sim1 + uz_boost * time def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength): - kb0 = np.sqrt(e/(m_e*gamma*vz0**2)*lens_strength) - x1 = x0*np.cos(kb0*lens_length) + (vx0/vz0)/kb0*np.sin(kb0*lens_length) - vx1 = vz0*(-kb0*x0*np.sin(kb0*lens_length) + (vx0/vz0)*np.cos(kb0*lens_length)) + kb0 = np.sqrt(e / (m_e * gamma * vz0**2) * lens_strength) + x1 = x0 * np.cos(kb0 * lens_length) + (vx0 / vz0) / kb0 * np.sin(kb0 * lens_length) + vx1 = vz0 * ( + -kb0 * x0 * np.sin(kb0 * lens_length) + (vx0 / vz0) * np.cos(kb0 * lens_length) + ) return x1, vx1 + clight = c try: - vel_z = eval(ds.parameters.get('my_constants.vel_z')) + vel_z = eval(ds.parameters.get("my_constants.vel_z")) except TypeError: # vel_z is not saved in my_constants with the PICMI version - vel_z = 0.5*c - -if 'particles.repeated_plasma_lens_period' in ds.parameters: - plasma_lens_period = float(ds.parameters.get('particles.repeated_plasma_lens_period')) - plasma_lens_starts = [float(x) for x in ds.parameters.get('particles.repeated_plasma_lens_starts').split()] - plasma_lens_lengths = [float(x) for x in ds.parameters.get('particles.repeated_plasma_lens_lengths').split()] - plasma_lens_strengths_E = [eval(x) for x in ds.parameters.get('particles.repeated_plasma_lens_strengths_E').split()] - plasma_lens_strengths_B = [eval(x) for x in ds.parameters.get('particles.repeated_plasma_lens_strengths_B').split()] -elif 'lattice.elements' in ds.parameters: - lattice_elements = ds.parameters.get('lattice.elements').split() + vel_z = 0.5 * c + +if "particles.repeated_plasma_lens_period" in ds.parameters: + plasma_lens_period = float( + ds.parameters.get("particles.repeated_plasma_lens_period") + ) + plasma_lens_starts = [ + float(x) + for x in ds.parameters.get("particles.repeated_plasma_lens_starts").split() + ] + plasma_lens_lengths = [ + float(x) + for x in ds.parameters.get("particles.repeated_plasma_lens_lengths").split() + ] + plasma_lens_strengths_E = [ + eval(x) + for x in ds.parameters.get("particles.repeated_plasma_lens_strengths_E").split() + ] + plasma_lens_strengths_B = [ + eval(x) + for x in ds.parameters.get("particles.repeated_plasma_lens_strengths_B").split() + ] +elif "lattice.elements" in ds.parameters: + lattice_elements = ds.parameters.get("lattice.elements").split() plasma_lens_zstarts = [] plasma_lens_lengths = [] plasma_lens_strengths_E = [] - z_location = 0. + z_location = 0.0 for element in lattice_elements: - element_type = ds.parameters.get(f'{element}.type') - length = float(ds.parameters.get(f'{element}.ds')) - if element_type == 'plasmalens': + element_type = ds.parameters.get(f"{element}.type") + length = float(ds.parameters.get(f"{element}.ds")) + if element_type == "plasmalens": plasma_lens_zstarts.append(z_location) plasma_lens_lengths.append(length) - plasma_lens_strengths_E.append(float(ds.parameters.get(f'{element}.dEdx'))) + plasma_lens_strengths_E.append(float(ds.parameters.get(f"{element}.dEdx"))) z_location += length plasma_lens_period = 0.5 - plasma_lens_starts = plasma_lens_zstarts - plasma_lens_period*np.arange(len(plasma_lens_zstarts)) + plasma_lens_starts = plasma_lens_zstarts - plasma_lens_period * np.arange( + len(plasma_lens_zstarts) + ) plasma_lens_strengths_B = np.zeros(len(plasma_lens_zstarts)) try: # The picmi version - x0 = float(ds.parameters.get('electrons.dist0.multiple_particles_pos_x')) - y0 = float(ds.parameters.get('electrons.dist1.multiple_particles_pos_y')) - z0 = float(ds.parameters.get('electrons.dist0.multiple_particles_pos_z')) - ux0 = float(ds.parameters.get('electrons.dist0.multiple_particles_ux'))*c - uy0 = float(ds.parameters.get('electrons.dist1.multiple_particles_uy'))*c - uz0 = eval(ds.parameters.get('electrons.dist0.multiple_particles_uz'))*c + x0 = float(ds.parameters.get("electrons.dist0.multiple_particles_pos_x")) + y0 = float(ds.parameters.get("electrons.dist1.multiple_particles_pos_y")) + z0 = float(ds.parameters.get("electrons.dist0.multiple_particles_pos_z")) + ux0 = float(ds.parameters.get("electrons.dist0.multiple_particles_ux")) * c + uy0 = float(ds.parameters.get("electrons.dist1.multiple_particles_uy")) * c + uz0 = eval(ds.parameters.get("electrons.dist0.multiple_particles_uz")) * c except TypeError: # The inputs version - x0 = float(ds.parameters.get('electrons.multiple_particles_pos_x').split()[0]) - y0 = float(ds.parameters.get('electrons.multiple_particles_pos_y').split()[1]) - z0 = float(ds.parameters.get('electrons.multiple_particles_pos_z').split()[0]) - ux0 = float(ds.parameters.get('electrons.multiple_particles_ux').split()[0])*c - uy0 = float(ds.parameters.get('electrons.multiple_particles_uy').split()[1])*c - uz0 = eval(ds.parameters.get('electrons.multiple_particles_uz').split()[0])*c - -tt = 0. + x0 = float(ds.parameters.get("electrons.multiple_particles_pos_x").split()[0]) + y0 = float(ds.parameters.get("electrons.multiple_particles_pos_y").split()[1]) + z0 = float(ds.parameters.get("electrons.multiple_particles_pos_z").split()[0]) + ux0 = float(ds.parameters.get("electrons.multiple_particles_ux").split()[0]) * c + uy0 = float(ds.parameters.get("electrons.multiple_particles_uy").split()[1]) * c + uz0 = eval(ds.parameters.get("electrons.multiple_particles_uz").split()[0]) * c + +tt = 0.0 xx = x0 yy = y0 zz = z0 @@ -117,37 +137,41 @@ def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength): uy = uy0 uz = uz0 -gamma = np.sqrt(uz0**2/c**2 + 1.) -vz = uz/gamma +gamma = np.sqrt(uz0**2 / c**2 + 1.0) +vz = uz / gamma for i in range(len(plasma_lens_starts)): - z_lens = i*plasma_lens_period + plasma_lens_starts[i] - vx = ux/gamma - vy = uy/gamma - dt = (z_lens - zz)/vz + z_lens = i * plasma_lens_period + plasma_lens_starts[i] + vx = ux / gamma + vy = uy / gamma + dt = (z_lens - zz) / vz tt = tt + dt - xx = xx + dt*vx - yy = yy + dt*vy - lens_strength = plasma_lens_strengths_E[i] + plasma_lens_strengths_B[i]*vel_z + xx = xx + dt * vx + yy = yy + dt * vy + lens_strength = plasma_lens_strengths_E[i] + plasma_lens_strengths_B[i] * vel_z xx, vx = applylens(xx, vx, vz, gamma, plasma_lens_lengths[i], lens_strength) yy, vy = applylens(yy, vy, vz, gamma, plasma_lens_lengths[i], lens_strength) - dt = plasma_lens_lengths[i]/vz + dt = plasma_lens_lengths[i] / vz tt = tt + dt - ux = gamma*vx - uy = gamma*vy + ux = gamma * vx + uy = gamma * vy zz = z_lens + plasma_lens_lengths[i] -dt0 = (zz_sim0 - zz)/vz -dt1 = (zz_sim1 - zz)/vz -vx = ux/gamma -vy = uy/gamma -xx = xx + dt0*vx -yy = yy + dt1*vy - -print(f'Error in x position is {abs(np.abs((xx - xx_sim)/xx))}, which should be < 0.02') -print(f'Error in y position is {abs(np.abs((yy - yy_sim)/yy))}, which should be < 0.02') -print(f'Error in x velocity is {abs(np.abs((ux - ux_sim)/ux))}, which should be < 0.002') -print(f'Error in y velocity is {abs(np.abs((uy - uy_sim)/uy))}, which should be < 0.002') +dt0 = (zz_sim0 - zz) / vz +dt1 = (zz_sim1 - zz) / vz +vx = ux / gamma +vy = uy / gamma +xx = xx + dt0 * vx +yy = yy + dt1 * vy + +print(f"Error in x position is {abs(np.abs((xx - xx_sim)/xx))}, which should be < 0.02") +print(f"Error in y position is {abs(np.abs((yy - yy_sim)/yy))}, which should be < 0.02") +print( + f"Error in x velocity is {abs(np.abs((ux - ux_sim)/ux))}, which should be < 0.002" +) +print( + f"Error in y velocity is {abs(np.abs((uy - uy_sim)/uy))}, which should be < 0.002" +) if plasma_lens_lengths[0] < 0.01: # The shorter lens requires a larger tolerance since @@ -158,15 +182,21 @@ def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength): position_tolerance = 0.02 velocity_tolerance = 0.002 -assert abs(np.abs((xx - xx_sim)/xx)) < position_tolerance, Exception('error in x particle position') -assert abs(np.abs((yy - yy_sim)/yy)) < position_tolerance, Exception('error in y particle position') -assert abs(np.abs((ux - ux_sim)/ux)) < velocity_tolerance, Exception('error in x particle velocity') -assert abs(np.abs((uy - uy_sim)/uy)) < velocity_tolerance, Exception('error in y particle velocity') - +assert abs(np.abs((xx - xx_sim) / xx)) < position_tolerance, Exception( + "error in x particle position" +) +assert abs(np.abs((yy - yy_sim) / yy)) < position_tolerance, Exception( + "error in y particle position" +) +assert abs(np.abs((ux - ux_sim) / ux)) < velocity_tolerance, Exception( + "error in x particle velocity" +) +assert abs(np.abs((uy - uy_sim) / uy)) < velocity_tolerance, Exception( + "error in y particle velocity" +) + +# The PICMI and native input versions run the same test, so +# their results are compared to the same benchmark file test_name = os.path.split(os.getcwd())[1] -# The PICMI and native input versions of `inputs_3d` run the same test, so -# their results are compared to the same benchmark file. -if test_name == "Python_plasma_lens": - test_name = "Plasma_lens" - +test_name = re.sub("_picmi", "", test_name) checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/plasma_lens/inputs_3d b/Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens similarity index 100% rename from Examples/Tests/plasma_lens/inputs_3d rename to Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens diff --git a/Examples/Tests/plasma_lens/inputs_boosted_3d b/Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_boosted similarity index 100% rename from Examples/Tests/plasma_lens/inputs_boosted_3d rename to Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_boosted diff --git a/Examples/Tests/plasma_lens/inputs_lattice_3d b/Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_hard_edged similarity index 100% rename from Examples/Tests/plasma_lens/inputs_lattice_3d rename to Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_hard_edged diff --git a/Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_picmi.py b/Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_picmi.py new file mode 100644 index 00000000000..b9672e17e1a --- /dev/null +++ b/Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_picmi.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# Physical constants +c = picmi.constants.c +q_e = picmi.constants.q_e + +# Number of time steps +max_steps = 84 + +# Number of cells +nx = 16 +ny = 16 +nz = 16 + +# Physical domain +xmin = -1.0 +xmax = 1.0 +ymin = -1.0 +ymax = 1.0 +zmin = 0.0 +zmax = 2.0 + +# Create grid +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], +) + +# Particles +vel_z = 0.5 * c +offset_x_particle = picmi.ParticleListDistribution( + x=[0.05], y=[0.0], z=[0.05], ux=[0.0], uy=[0.0], uz=[vel_z], weight=[1.0] +) + +offset_y_particle = picmi.ParticleListDistribution( + x=[0.0], y=[0.04], z=[0.05], ux=[0.0], uy=[0.0], uz=[vel_z], weight=[1.0] +) + +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=[offset_x_particle, offset_y_particle], +) + +# Plasma lenses +plasma_lenses = picmi.PlasmaLens( + period=0.5, + starts=[0.1, 0.11, 0.12, 0.13], + lengths=[0.1, 0.11, 0.12, 0.13], + strengths_E=[600000.0, 800000.0, 600000.0, 200000.0], + strengths_B=[0.0, 0.0, 0.0, 0.0], +) + +# Electromagnetic solver +solver = picmi.ElectromagneticSolver(grid=grid, method="Yee", cfl=0.7) + +# Diagnostics +part_diag1 = picmi.ParticleDiagnostic( + name="diag1", + period=max_steps, + species=[electrons], + data_list=["ux", "uy", "uz", "x", "y", "z"], +) + +field_diag1 = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=max_steps, + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez", "Jx", "Jy", "Jz"], +) +# Set up simulation +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + particle_shape="linear", + warpx_serialize_initial_conditions=1, + warpx_do_dynamic_scheduling=0, +) + +# Add plasma electrons +sim.add_species(electrons, layout=None) + +# Add the plasma lenses +sim.add_applied_field(plasma_lenses) + +# Add diagnostics +sim.add_diagnostic(part_diag1) +sim.add_diagnostic(field_diag1) + +# Write input file that can be used to run with the compiled version +# sim.write_input_file(file_name = 'inputs_3d_picmi') + +# Advance simulation until last time step +sim.step(max_steps) diff --git a/Examples/Tests/plasma_lens/inputs_short_3d b/Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_short similarity index 100% rename from Examples/Tests/plasma_lens/inputs_short_3d rename to Examples/Tests/plasma_lens/inputs_test_3d_plasma_lens_short diff --git a/Examples/Tests/pml/CMakeLists.txt b/Examples/Tests/pml/CMakeLists.txt new file mode 100644 index 00000000000..c63412dc763 --- /dev/null +++ b/Examples/Tests/pml/CMakeLists.txt @@ -0,0 +1,92 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_pml_x_ckc # name + 2 # dims + 2 # nprocs + inputs_test_2d_pml_x_ckc # inputs + analysis_pml_ckc.py # analysis + diags/diag1000300 # output + OFF # dependency +) + +if(WarpX_FFT) + add_warpx_test( + test_2d_pml_x_galilean # name + 2 # dims + 2 # nprocs + inputs_test_2d_pml_x_galilean # inputs + analysis_pml_psatd.py # analysis + diags/diag1000300 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_pml_x_psatd # name + 2 # dims + 2 # nprocs + inputs_test_2d_pml_x_psatd # inputs + analysis_pml_psatd.py # analysis + diags/diag1000300 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_2d_pml_x_psatd_restart # name + 2 # dims + 2 # nprocs + inputs_test_2d_pml_x_psatd_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000300 # output + test_2d_pml_x_psatd # dependency + ) +endif() + +add_warpx_test( + test_2d_pml_x_yee # name + 2 # dims + 2 # nprocs + inputs_test_2d_pml_x_yee # inputs + analysis_pml_yee.py # analysis + diags/diag1000300 # output + OFF # dependency +) + +add_warpx_test( + test_2d_pml_x_yee_restart # name + 2 # dims + 2 # nprocs + inputs_test_2d_pml_x_yee_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000300 # output + test_2d_pml_x_yee # dependency +) + +if(WarpX_FFT) + add_warpx_test( + test_3d_pml_psatd_dive_divb_cleaning # name + 3 # dims + 2 # nprocs + inputs_test_3d_pml_psatd_dive_divb_cleaning # inputs + analysis_default_regression.py # analysis + diags/diag1000100 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_rz_pml_psatd # name + RZ # dims + 2 # nprocs + inputs_test_rz_pml_psatd # inputs + analysis_pml_psatd_rz.py # analysis + diags/diag1000500 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/pml/analysis_default_regression.py b/Examples/Tests/pml/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/pml/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/pml/analysis_default_restart.py b/Examples/Tests/pml/analysis_default_restart.py new file mode 120000 index 00000000000..0459986eebc --- /dev/null +++ b/Examples/Tests/pml/analysis_default_restart.py @@ -0,0 +1 @@ +../../analysis_default_restart.py \ No newline at end of file diff --git a/Examples/Tests/pml/analysis_pml_ckc.py b/Examples/Tests/pml/analysis_pml_ckc.py index c4b9d54647d..4e6bff076c7 100755 --- a/Examples/Tests/pml/analysis_pml_ckc.py +++ b/Examples/Tests/pml/analysis_pml_ckc.py @@ -13,9 +13,10 @@ import numpy as np import scipy.constants as scc +import yt -import yt ; yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] @@ -28,31 +29,33 @@ ########################## ### FINAL LASER ENERGY ### ########################## -ds = yt.load( filename ) -all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -Bx = all_data_level_0['boxlib', 'Bx'].v.squeeze() -By = all_data_level_0['boxlib', 'By'].v.squeeze() -Bz = all_data_level_0['boxlib', 'Bz'].v.squeeze() -Ex = all_data_level_0['boxlib', 'Ex'].v.squeeze() -Ey = all_data_level_0['boxlib', 'Ey'].v.squeeze() -Ez = all_data_level_0['boxlib', 'Ez'].v.squeeze() -energyE = np.sum(scc.epsilon_0/2*(Ex**2+Ey**2+Ez**2)) -energyB = np.sum(1./scc.mu_0/2*(Bx**2+By**2+Bz**2)) +ds = yt.load(filename) +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Bx = all_data_level_0["boxlib", "Bx"].v.squeeze() +By = all_data_level_0["boxlib", "By"].v.squeeze() +Bz = all_data_level_0["boxlib", "Bz"].v.squeeze() +Ex = all_data_level_0["boxlib", "Ex"].v.squeeze() +Ey = all_data_level_0["boxlib", "Ey"].v.squeeze() +Ez = all_data_level_0["boxlib", "Ez"].v.squeeze() +energyE = np.sum(scc.epsilon_0 / 2 * (Ex**2 + Ey**2 + Ez**2)) +energyB = np.sum(1.0 / scc.mu_0 / 2 * (Bx**2 + By**2 + Bz**2)) energy_end = energyE + energyB -Reflectivity = energy_end/energy_start +Reflectivity = energy_end / energy_start Reflectivity_theory = 1.8015e-06 -print("Reflectivity: %s" %Reflectivity) -print("Reflectivity_theory: %s" %Reflectivity_theory) +print("Reflectivity: %s" % Reflectivity) +print("Reflectivity_theory: %s" % Reflectivity_theory) -error_rel = abs(Reflectivity-Reflectivity_theory) / Reflectivity_theory -tolerance_rel = 5./100 +error_rel = abs(Reflectivity - Reflectivity_theory) / Reflectivity_theory +tolerance_rel = 5.0 / 100 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/pml/analysis_pml_psatd.py b/Examples/Tests/pml/analysis_pml_psatd.py index 50d0b2ac1c1..00b867857f9 100755 --- a/Examples/Tests/pml/analysis_pml_psatd.py +++ b/Examples/Tests/pml/analysis_pml_psatd.py @@ -13,32 +13,35 @@ import numpy as np import scipy.constants as scc +import yt -import yt ; yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] -galilean = True if re.search("galilean", filename) else False +cwd = os.getcwd() +filename_init = os.path.join(cwd, "diags/diag1000050") +galilean = True if re.search("galilean", cwd) else False # Initial laser energy (at iteration 50) if galilean: - filename_init = 'pml_x_galilean_plt000050' energy_start = 4.439376199524034e-08 else: - filename_init = 'pml_x_psatd_plt000050' energy_start = 7.282940107273505e-08 # Check consistency of field energy diagnostics with initial energy above ds = yt.load(filename_init) -all_data_level_0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -Bx = all_data_level_0['boxlib', 'Bx'].v.squeeze() -By = all_data_level_0['boxlib', 'By'].v.squeeze() -Bz = all_data_level_0['boxlib', 'Bz'].v.squeeze() -Ex = all_data_level_0['boxlib', 'Ex'].v.squeeze() -Ey = all_data_level_0['boxlib', 'Ey'].v.squeeze() -Ez = all_data_level_0['boxlib', 'Ez'].v.squeeze() +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Bx = all_data_level_0["boxlib", "Bx"].v.squeeze() +By = all_data_level_0["boxlib", "By"].v.squeeze() +Bz = all_data_level_0["boxlib", "Bz"].v.squeeze() +Ex = all_data_level_0["boxlib", "Ex"].v.squeeze() +Ey = all_data_level_0["boxlib", "Ey"].v.squeeze() +Ez = all_data_level_0["boxlib", "Ez"].v.squeeze() energyE = np.sum(0.5 * scc.epsilon_0 * (Ex**2 + Ey**2 + Ez**2)) energyB = np.sum(0.5 / scc.mu_0 * (Bx**2 + By**2 + Bz**2)) energy_start_diags = energyE + energyB @@ -47,17 +50,19 @@ print("energy_start expected = " + str(energy_start)) print("energy_start_diags = " + str(energy_start_diags)) print("relative error = " + str(error)) -assert (error < tolerance) +assert error < tolerance # Final laser energy ds = yt.load(filename) -all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -Bx = all_data_level_0['boxlib', 'Bx'].v.squeeze() -By = all_data_level_0['boxlib', 'By'].v.squeeze() -Bz = all_data_level_0['boxlib', 'Bz'].v.squeeze() -Ex = all_data_level_0['boxlib', 'Ex'].v.squeeze() -Ey = all_data_level_0['boxlib', 'Ey'].v.squeeze() -Ez = all_data_level_0['boxlib', 'Ez'].v.squeeze() +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Bx = all_data_level_0["boxlib", "Bx"].v.squeeze() +By = all_data_level_0["boxlib", "By"].v.squeeze() +Bz = all_data_level_0["boxlib", "Bz"].v.squeeze() +Ex = all_data_level_0["boxlib", "Ex"].v.squeeze() +Ey = all_data_level_0["boxlib", "Ey"].v.squeeze() +Ez = all_data_level_0["boxlib", "Ez"].v.squeeze() energyE = np.sum(0.5 * scc.epsilon_0 * (Ex**2 + Ey**2 + Ez**2)) energyB = np.sum(0.5 / scc.mu_0 * (Bx**2 + By**2 + Bz**2)) energy_end = energyE + energyB @@ -68,14 +73,7 @@ print("reflectivity = " + str(reflectivity)) print("reflectivity_max = " + str(reflectivity_max)) -assert(reflectivity < reflectivity_max) - -# Check restart data v. original data -sys.path.insert(0, '../../../../warpx/Examples/') -from analysis_default_restart import check_restart - -if not galilean: - check_restart(filename) +assert reflectivity < reflectivity_max test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/pml/analysis_pml_psatd_rz.py b/Examples/Tests/pml/analysis_pml_psatd_rz.py index d4f1ff42ae6..2d9d58734a1 100755 --- a/Examples/Tests/pml/analysis_pml_psatd_rz.py +++ b/Examples/Tests/pml/analysis_pml_psatd_rz.py @@ -15,6 +15,7 @@ most of the pulse escapes the radial boundary. If the PML fails, the pulse will remain with in the domain. """ + import os import sys @@ -22,33 +23,36 @@ import yt yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Open plotfile specified in command line filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. -if 'force_periodicity' in dir(ds): ds.force_periodicity() +if "force_periodicity" in dir(ds): + ds.force_periodicity() # Check that the field is low enough -ad0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -Ex_array = ad0['boxlib', 'Er'].to_ndarray() -Ez_array = ad0['boxlib', 'Ez'].to_ndarray() +ad0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Ex_array = ad0["boxlib", "Er"].to_ndarray() +Ez_array = ad0["boxlib", "Ez"].to_ndarray() max_Ex = np.abs(Ex_array).max() max_Ez = np.abs(Ez_array).max() -print( f'max Ex = {max_Ex}' ) -print( f'max Ez = {max_Ez}' ) +print(f"max Ex = {max_Ex}") +print(f"max Ez = {max_Ez}") max_Efield = max(max_Ex, max_Ez) # This tolerance was obtained empirically. As the simulation progresses, the field energy is leaking # out through PML so that the max field diminishes with time. When the PML is working properly, # the field level falls below 2 at the end of the simulation. -tolerance_abs = 2. -print('tolerance_abs: ' + str(tolerance_abs)) +tolerance_abs = 2.0 +print("tolerance_abs: " + str(tolerance_abs)) assert max_Efield < tolerance_abs test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/pml/analysis_pml_yee.py b/Examples/Tests/pml/analysis_pml_yee.py index f10b281c544..a24854af095 100755 --- a/Examples/Tests/pml/analysis_pml_yee.py +++ b/Examples/Tests/pml/analysis_pml_yee.py @@ -13,9 +13,10 @@ import numpy as np import scipy.constants as scc +import yt -import yt ; yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] @@ -28,37 +29,33 @@ ########################## ### FINAL LASER ENERGY ### ########################## -ds = yt.load( filename ) -all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -Bx = all_data_level_0['boxlib', 'Bx'].v.squeeze() -By = all_data_level_0['boxlib', 'By'].v.squeeze() -Bz = all_data_level_0['boxlib', 'Bz'].v.squeeze() -Ex = all_data_level_0['boxlib', 'Ex'].v.squeeze() -Ey = all_data_level_0['boxlib', 'Ey'].v.squeeze() -Ez = all_data_level_0['boxlib', 'Ez'].v.squeeze() -energyE = np.sum(scc.epsilon_0/2*(Ex**2+Ey**2+Ez**2)) -energyB = np.sum(1./scc.mu_0/2*(Bx**2+By**2+Bz**2)) +ds = yt.load(filename) +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Bx = all_data_level_0["boxlib", "Bx"].v.squeeze() +By = all_data_level_0["boxlib", "By"].v.squeeze() +Bz = all_data_level_0["boxlib", "Bz"].v.squeeze() +Ex = all_data_level_0["boxlib", "Ex"].v.squeeze() +Ey = all_data_level_0["boxlib", "Ey"].v.squeeze() +Ez = all_data_level_0["boxlib", "Ez"].v.squeeze() +energyE = np.sum(scc.epsilon_0 / 2 * (Ex**2 + Ey**2 + Ez**2)) +energyB = np.sum(1.0 / scc.mu_0 / 2 * (Bx**2 + By**2 + Bz**2)) energy_end = energyE + energyB -Reflectivity = energy_end/energy_start +Reflectivity = energy_end / energy_start Reflectivity_theory = 5.683000058954201e-07 -print("Reflectivity: %s" %Reflectivity) -print("Reflectivity_theory: %s" %Reflectivity_theory) +print("Reflectivity: %s" % Reflectivity) +print("Reflectivity_theory: %s" % Reflectivity_theory) -error_rel = abs(Reflectivity-Reflectivity_theory) / Reflectivity_theory -tolerance_rel = 5./100 +error_rel = abs(Reflectivity - Reflectivity_theory) / Reflectivity_theory +tolerance_rel = 5.0 / 100 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) - -# Check restart data v. original data -sys.path.insert(0, '../../../../warpx/Examples/') -from analysis_default_restart import check_restart - -check_restart(filename) +assert error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/pml/inputs_2d b/Examples/Tests/pml/inputs_base_2d similarity index 100% rename from Examples/Tests/pml/inputs_2d rename to Examples/Tests/pml/inputs_base_2d diff --git a/Examples/Tests/pml/inputs_test_2d_pml_x_ckc b/Examples/Tests/pml/inputs_test_2d_pml_x_ckc new file mode 100644 index 00000000000..f686674ae14 --- /dev/null +++ b/Examples/Tests/pml/inputs_test_2d_pml_x_ckc @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = ckc diff --git a/Examples/Tests/pml/inputs_test_2d_pml_x_galilean b/Examples/Tests/pml/inputs_test_2d_pml_x_galilean new file mode 100644 index 00000000000..34a9081a181 --- /dev/null +++ b/Examples/Tests/pml/inputs_test_2d_pml_x_galilean @@ -0,0 +1,14 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = psatd +diag1.fields_to_plot = Ex Ey Ez Bx By Bz rho divE +psatd.current_correction = 0 +psatd.update_with_rho = 1 +psatd.v_galilean = 0. 0. 0.99 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7071067811865475 +warpx.do_pml_divb_cleaning = 1 +warpx.do_pml_dive_cleaning = 1 +warpx.grid_type = collocated diff --git a/Examples/Tests/pml/inputs_test_2d_pml_x_psatd b/Examples/Tests/pml/inputs_test_2d_pml_x_psatd new file mode 100644 index 00000000000..191d5774530 --- /dev/null +++ b/Examples/Tests/pml/inputs_test_2d_pml_x_psatd @@ -0,0 +1,12 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = psatd +diag1.fields_to_plot = Ex Ey Ez Bx By Bz rho divE +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7071067811865475 +warpx.do_pml_divb_cleaning = 0 +warpx.do_pml_dive_cleaning = 0 +psatd.current_correction = 0 +psatd.update_with_rho = 1 diff --git a/Examples/Tests/pml/inputs_test_2d_pml_x_psatd_restart b/Examples/Tests/pml/inputs_test_2d_pml_x_psatd_restart new file mode 100644 index 00000000000..44b9be4494a --- /dev/null +++ b/Examples/Tests/pml/inputs_test_2d_pml_x_psatd_restart @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_test_2d_pml_x_psatd + +# test input parameters +amr.restart = "../test_2d_pml_x_psatd/diags/chk000150" diff --git a/Examples/Tests/pml/inputs_test_2d_pml_x_yee b/Examples/Tests/pml/inputs_test_2d_pml_x_yee new file mode 100644 index 00000000000..390cf079c16 --- /dev/null +++ b/Examples/Tests/pml/inputs_test_2d_pml_x_yee @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_2d + +# test input parameters +algo.maxwell_solver = yee diff --git a/Examples/Tests/pml/inputs_test_2d_pml_x_yee_restart b/Examples/Tests/pml/inputs_test_2d_pml_x_yee_restart new file mode 100644 index 00000000000..b626e3aa662 --- /dev/null +++ b/Examples/Tests/pml/inputs_test_2d_pml_x_yee_restart @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_test_2d_pml_x_yee + +# test input parameters +amr.restart = "../test_2d_pml_x_yee/diags/chk000150" diff --git a/Examples/Tests/pml/inputs_3d b/Examples/Tests/pml/inputs_test_3d_pml_psatd_dive_divb_cleaning similarity index 94% rename from Examples/Tests/pml/inputs_3d rename to Examples/Tests/pml/inputs_test_3d_pml_psatd_dive_divb_cleaning index e152afc7cc7..4e8c3c78329 100644 --- a/Examples/Tests/pml/inputs_3d +++ b/Examples/Tests/pml/inputs_test_3d_pml_psatd_dive_divb_cleaning @@ -14,12 +14,15 @@ boundary.field_lo = pml pml pml boundary.field_hi = pml pml pml # Numerical parameters +ablastr.fillboundary_always_sync = 1 +warpx.abort_on_warning_threshold = medium warpx.cfl = 1.0 warpx.grid_type = staggered warpx.do_dive_cleaning = 1 warpx.do_divb_cleaning = 1 warpx.do_pml_dive_cleaning = 1 warpx.do_pml_divb_cleaning = 1 +warpx.do_similar_dm_pml = 0 warpx.use_filter = 1 warpx.verbose = 1 diff --git a/Examples/Tests/pml/inputs_rz b/Examples/Tests/pml/inputs_test_rz_pml_psatd similarity index 93% rename from Examples/Tests/pml/inputs_rz rename to Examples/Tests/pml/inputs_test_rz_pml_psatd index f5e23fe0399..87b4d7a5b3f 100644 --- a/Examples/Tests/pml/inputs_rz +++ b/Examples/Tests/pml/inputs_test_rz_pml_psatd @@ -25,8 +25,11 @@ warpx.do_pml_in_domain = 0 ############ NUMERICS ########### ################################# algo.maxwell_solver = psatd +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7 warpx.use_filter = 0 algo.particle_shape = 1 +psatd.current_correction = 0 ################################# ############ PARTICLE ########### diff --git a/Examples/Tests/point_of_contact_EB/analysis.py b/Examples/Tests/point_of_contact_EB/analysis.py deleted file mode 100755 index 042fc811a62..00000000000 --- a/Examples/Tests/point_of_contact_EB/analysis.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python - -""" -This script tests the coordinates of the point of contact of an electron hitting a sphere in 3D. -It compares the numerical results with the analytical solutions. -The sphere is centered on O and has a radius of 0.2 (EB) -The electron is initially at: (-0.25,0,0) and moves with a normalized momentum: (1,0.5,0) -An input file PICMI_inputs_3d.py is used. -""" -import os -import sys - -import numpy as np -import yt -from openpmd_viewer import OpenPMDTimeSeries - -yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -# Open plotfile specified in command line -filename = sys.argv[1] -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename, output_format='openpmd') - -ts_scraping = OpenPMDTimeSeries('./diags/diag2/particles_at_eb/') - -it=ts_scraping.iterations -step_scraped, delta, x, y, z, nx, ny, nz=ts_scraping.get_particle( ['stepScraped','deltaTimeScraped','x','y','z', 'nx', 'ny', 'nz'], species='electron', iteration=it ) -delta_reduced=delta[0]*1e10 - -# Analytical results calculated -x_analytic=-0.1983 -y_analytic=0.02584 -z_analytic=0.0000 -nx_analytic=-0.99 -ny_analytic=0.13 -nz_analytic=0.0 - -#result obtained by analysis of simulations -step_ref=3 -delta_reduced_ref=0.59 - -print('NUMERICAL coordinates of the point of contact:') -print('step_scraped=%d, time_stamp=%5.4f e-10, x=%5.4f, y=%5.4f, z=%5.4f, nx=%5.4f, ny=%5.4f, nz=%5.4f' % (step_scraped[0],delta_reduced,x[0], y[0], z[0], nx[0], ny[0], nz[0])) -print('\n') -print('ANALYTICAL coordinates of the point of contact:') -print('step_scraped=%d, time_stamp=%5.4f e-10, x=%5.4f, y=%5.4f, z=%5.4f, nx=%5.4f, ny=%5.4f, nz=%5.4f' % (step_ref, delta_reduced_ref, x_analytic, y_analytic, z_analytic, nx_analytic, ny_analytic, nz_analytic)) - -tolerance=0.001 -tolerance_t=0.01 -tolerance_n=0.01 -print("tolerance = "+ str(tolerance *100) + '%') -print("tolerance for the time = "+ str(tolerance_t *100) + '%') -print("tolerance for the normal components = "+ str(tolerance_n *100) + '%') - -diff_step=np.abs((step_scraped[0]-step_ref)/step_ref) -diff_delta=np.abs((delta_reduced-delta_reduced_ref)/delta_reduced_ref) -diff_x=np.abs((x[0]-x_analytic)/x_analytic) -diff_y=np.abs((y[0]-y_analytic)/y_analytic) -diff_nx=np.abs((nx[0]-nx_analytic)/nx_analytic) -diff_ny=np.abs((ny[0]-ny_analytic)/ny_analytic) - -print("percentage error for x = %5.4f %%" %(diff_x *100)) -print("percentage error for y = %5.4f %%" %(diff_y *100)) -print("percentage error for nx = %5.2f %%" %(diff_nx *100)) -print("percentage error for ny = %5.2f %%" %(diff_ny *100)) -print("nz = %5.2f " %(nz[0])) - -assert (diff_x < tolerance) and (diff_y < tolerance) and (np.abs(z[0]) < 1e-8) and (diff_step < 1e-8) and (diff_delta < tolerance_t) and (diff_nx < tolerance_n) and (diff_ny < tolerance_n) and (np.abs(nz) < 1e-8) , 'Test point_of_contact did not pass' diff --git a/Examples/Tests/point_of_contact_eb/CMakeLists.txt b/Examples/Tests/point_of_contact_eb/CMakeLists.txt new file mode 100644 index 00000000000..b8d7ba1131f --- /dev/null +++ b/Examples/Tests/point_of_contact_eb/CMakeLists.txt @@ -0,0 +1,26 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_3d_point_of_contact_eb # name + 3 # dims + 2 # nprocs + inputs_test_3d_point_of_contact_eb # inputs + analysis.py # analysis + diags/diag1/ # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_rz_point_of_contact_eb # name + RZ # dims + 2 # nprocs + inputs_test_rz_point_of_contact_eb # inputs + analysis.py # analysis + diags/diag1/ # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/point_of_contact_eb/analysis.py b/Examples/Tests/point_of_contact_eb/analysis.py new file mode 100755 index 00000000000..3f42aa6eeca --- /dev/null +++ b/Examples/Tests/point_of_contact_eb/analysis.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python + +""" +This script tests the coordinates of the point of contact of an electron hitting a sphere in 3D. +It compares the numerical results with the analytical solutions. +The sphere is centered on O and has a radius of 0.2 (EB) +The electron is initially at: (-0.25,0,0) and moves with a normalized momentum: (1,0.5,0) +An input file inputs_test_3d_point_of_contact_eb is used. +""" + +import os +import sys + +import numpy as np +import yt +from openpmd_viewer import OpenPMDTimeSeries + +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# Open plotfile specified in command line +filename = sys.argv[1] +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename, output_format="openpmd") + +ts_scraping = OpenPMDTimeSeries("./diags/diag2/particles_at_eb/") + +it = ts_scraping.iterations +step_scraped, delta, x, y, z, nx, ny, nz = ts_scraping.get_particle( + ["stepScraped", "deltaTimeScraped", "x", "y", "z", "nx", "ny", "nz"], + species="electron", + iteration=it, +) +delta_reduced = delta[0] * 1e10 + +# Analytical results calculated +x_analytic = -0.1983 +y_analytic = 0.02584 +z_analytic = 0.0000 +nx_analytic = -0.99 +ny_analytic = 0.13 +nz_analytic = 0.0 + +# result obtained by analysis of simulations +step_ref = 3 +delta_reduced_ref = 0.59 + +print("NUMERICAL coordinates of the point of contact:") +print( + "step_scraped=%d, time_stamp=%5.4f e-10, x=%5.4f, y=%5.4f, z=%5.4f, nx=%5.4f, ny=%5.4f, nz=%5.4f" + % (step_scraped[0], delta_reduced, x[0], y[0], z[0], nx[0], ny[0], nz[0]) +) +print("\n") +print("ANALYTICAL coordinates of the point of contact:") +print( + "step_scraped=%d, time_stamp=%5.4f e-10, x=%5.4f, y=%5.4f, z=%5.4f, nx=%5.4f, ny=%5.4f, nz=%5.4f" + % ( + step_ref, + delta_reduced_ref, + x_analytic, + y_analytic, + z_analytic, + nx_analytic, + ny_analytic, + nz_analytic, + ) +) + +tolerance = 0.001 +tolerance_t = 0.01 +tolerance_n = 0.01 +print("tolerance = " + str(tolerance * 100) + "%") +print("tolerance for the time = " + str(tolerance_t * 100) + "%") +print("tolerance for the normal components = " + str(tolerance_n * 100) + "%") + +diff_step = np.abs((step_scraped[0] - step_ref) / step_ref) +diff_delta = np.abs((delta_reduced - delta_reduced_ref) / delta_reduced_ref) +diff_x = np.abs((x[0] - x_analytic) / x_analytic) +diff_y = np.abs((y[0] - y_analytic) / y_analytic) +diff_nx = np.abs((nx[0] - nx_analytic) / nx_analytic) +diff_ny = np.abs((ny[0] - ny_analytic) / ny_analytic) + +print("percentage error for x = %5.4f %%" % (diff_x * 100)) +print("percentage error for y = %5.4f %%" % (diff_y * 100)) +print("percentage error for nx = %5.2f %%" % (diff_nx * 100)) +print("percentage error for ny = %5.2f %%" % (diff_ny * 100)) +print("nz = %5.2f " % (nz[0])) + +assert ( + (diff_x < tolerance) + and (diff_y < tolerance) + and (np.abs(z[0]) < 1e-8) + and (diff_step < 1e-8) + and (diff_delta < tolerance_t) + and (diff_nx < tolerance_n) + and (diff_ny < tolerance_n) + and (np.abs(nz) < 1e-8) +), "Test point_of_contact did not pass" diff --git a/Examples/Tests/point_of_contact_EB/inputs_3d b/Examples/Tests/point_of_contact_eb/inputs_test_3d_point_of_contact_eb similarity index 100% rename from Examples/Tests/point_of_contact_EB/inputs_3d rename to Examples/Tests/point_of_contact_eb/inputs_test_3d_point_of_contact_eb diff --git a/Examples/Tests/point_of_contact_EB/inputs_rz b/Examples/Tests/point_of_contact_eb/inputs_test_rz_point_of_contact_eb similarity index 100% rename from Examples/Tests/point_of_contact_EB/inputs_rz rename to Examples/Tests/point_of_contact_eb/inputs_test_rz_point_of_contact_eb diff --git a/Examples/Tests/projection_divb_cleaner/CMakeLists.txt b/Examples/Tests/projection_divb_cleaner/CMakeLists.txt new file mode 100644 index 00000000000..307ae7656c5 --- /dev/null +++ b/Examples/Tests/projection_divb_cleaner/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_projection_divb_cleaner_callback_picmi # name + 3 # dims + 1 # nprocs + inputs_test_3d_projection_divb_cleaner_callback_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_3d_projection_divb_cleaner_picmi # name + 3 # dims + 1 # nprocs + inputs_test_3d_projection_divb_cleaner_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_rz_projection_divb_cleaner # name + RZ # dims + 1 # nprocs + inputs_test_rz_projection_divb_cleaner # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/projection_divb_cleaner/analysis.py b/Examples/Tests/projection_divb_cleaner/analysis.py new file mode 100755 index 00000000000..256d1929d06 --- /dev/null +++ b/Examples/Tests/projection_divb_cleaner/analysis.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 + +# Copyright 2022 Yinjian Zhao +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +# This test tests the external field loading feature. +# A magnetic mirror field is loaded, and a single particle +# in the mirror will be reflected by the magnetic mirror effect. +# At the end of the simulation, the position of the particle +# is compared with known correct results. + +# Possible errors: 6.235230443866285e-9 +# tolerance: 1.0e-8 +# Possible running time: 0.327827743 s + +import os +import sys + +import numpy as np +import yt + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +tolerance = 4e-3 + +filename = sys.argv[1] + +ds = yt.load(filename) +grid0 = ds.index.grids[0] + + +r_min = grid0.LeftEdge.v[0] +r_max = grid0.RightEdge.v[0] +nr = grid0.shape[0] +dri = 1 // grid0.dds.v[0] +ir = np.arange(nr) + +ru = 1.0 + 0.5 / (r_min * dri + ir + 0.5) +rd = 1.0 - 0.5 / (r_min * dri + ir + 0.5) + +z_min = grid0.LeftEdge.v[1] +z_max = grid0.RightEdge.v[1] +nz = grid0.shape[1] +dzi = 1.0 / grid0.dds.v[1] + +RU, ZU = np.meshgrid(ru, np.arange(nz), indexing="ij") +RD, ZD = np.meshgrid(rd, np.arange(nz), indexing="ij") + +dBrdr = ( + RU * grid0["raw", "Bx_aux"].v[:, :, 0, 1] + - RD * grid0["raw", "Bx_aux"].v[:, :, 0, 0] +) * dri +dBzdz = ( + grid0["raw", "Bz_aux"].v[:, :, 0, 1] - grid0["raw", "Bz_aux"].v[:, :, 0, 0] +) * dzi + +divB = dBrdr + dBzdz + +import matplotlib.pyplot as plt + +plt.imshow(np.log10(np.abs(divB[1:-1, 1:-1]))) +plt.title("log10(|div(B)|)") +plt.colorbar() +plt.savefig("divb.png") + +error = np.sqrt((divB[1:-1, 1:-1] ** 2).sum()) + +print("error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/projection_divb_cleaner/analysis_default_regression.py b/Examples/Tests/projection_divb_cleaner/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/projection_divb_cleaner/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/projection_divb_cleaner/inputs_test_3d_projection_divb_cleaner_callback_picmi.py b/Examples/Tests/projection_divb_cleaner/inputs_test_3d_projection_divb_cleaner_callback_picmi.py new file mode 100644 index 00000000000..e6eb7ecf904 --- /dev/null +++ b/Examples/Tests/projection_divb_cleaner/inputs_test_3d_projection_divb_cleaner_callback_picmi.py @@ -0,0 +1,244 @@ +#!/usr/bin/env python3 +# +# --- Input file for loading initial field from Python callback + +import numpy as np +import scipy.constants as con +from mpi4py import MPI as mpi +from scipy.special import ellipe, ellipk + +from pywarpx import fields, picmi + +constants = picmi.constants + +comm = mpi.COMM_WORLD + +simulation = picmi.Simulation(verbose=True) + + +def augment_vector(v): + d = v[1] - v[0] + vp = (v[1:] + v[:-1]) / 2.0 + vp = np.insert(vp, 0, vp[0] - d) + vp = np.append(vp, vp[-1] + d) + return vp + + +class CurrentLoop(object): + def __init__(self, **kw): + self.radius = kw.pop("radius") # (m) + self.z0 = kw.pop("z0", 0.0) # (m) Defines the middle of the current loop + self.B0 = kw.pop("B0", 1.0) # (T) Strength of field in middle of loop + + # Compute loop current to normalize the B field of the center of the current loop + # from the following on axis equation for Bz + + self.I = 2.0 * self.radius * self.B0 / con.mu_0 + + def psi(self, r, z): + # Convert to spherical coordinates + rho = np.sqrt(r**2 + (z - self.z0) ** 2) + theta = np.arctan2(r, z - self.z0) + + coeff = con.mu_0 * self.I / (4.0 * np.pi) + denom = self.radius**2 + rho**2 + 2.0 * self.radius * rho * np.sin(theta) + + k2 = 4.0 * self.radius * rho * np.sin(theta) / denom + 1e-12 + + term1 = 4.0 * self.radius / np.sqrt(denom) + term2 = ((2.0 - k2) * ellipk(k2) - 2.0 * ellipe(k2)) / k2 + + return coeff * term1 * term2 * r + + def __call__(self, xv, yv, zv, coord="x"): + # Generate B-field mesh + XMB, YMB, ZMB = np.meshgrid(xv, yv, zv, indexing="ij") + RMB = np.sqrt(XMB**2 + YMB**2) + + dx = xv[1] - xv[0] + dy = yv[1] - yv[0] + dz = zv[1] - zv[0] + + if coord == "x": + # Gradient is along z direction + zvp = augment_vector(zv) + + # A mesh, which will be reduced later after gradients taken + XMP, YMP, ZMP = np.meshgrid(xv, yv, zvp, indexing="ij") + RMP = np.sqrt(XMP**2 + YMP**2) + psi = self.psi(RMP, ZMP) + grad_psi_z = (psi[:, :, 1:] - psi[:, :, :-1]) / dz + + return -XMB * grad_psi_z / RMB**2 + elif coord == "y": + # Gradient is along z direction + zvp = augment_vector(zv) + + # Psi mesh, which will be reduced later after gradients taken + XMP, YMP, ZMP = np.meshgrid(xv, yv, zvp, indexing="ij") + RMP = np.sqrt(XMP**2 + YMP**2) + psi = self.psi(RMP, ZMP) + grad_psi_z = (psi[:, :, 1:] - psi[:, :, :-1]) / dz + + return -YMB * grad_psi_z / RMB**2 + elif coord == "z": + # Gradient is along x,y directions + xvp = augment_vector(xv) + + # Psi mesh, which will be reduced later after gradients taken + XMP, YMP, ZMP = np.meshgrid(xvp, yv, zv, indexing="ij") + RMP = np.sqrt(XMP**2 + YMP**2) + psi = self.psi(RMP, ZMP) + grad_psi_x = (psi[1:, :, :] - psi[:-1, :, :]) / dx + + yvp = augment_vector(yv) + + # Psi mesh, which will be reduced later after gradients taken + XMP, YMP, ZMP = np.meshgrid(xv, yvp, zv, indexing="ij") + RMP = np.sqrt(XMP**2 + YMP**2) + psi = self.psi(RMP, ZMP) + grad_psi_y = (psi[:, 1:, :] - psi[:, :-1, :]) / dy + + return (XMB * grad_psi_x + YMB * grad_psi_y) / RMB**2 + else: + error("coord must be x/y/z") + return None + + +class ProjectionDivCleanerTest(object): + # Spatial domain + Nx = 40 # number of cells in x direction + Ny = 40 # number of cells in y direction + Nz = 80 # number of cells in z direction + + MAX_GRID = 40 + BLOCKING_FACTOR = 8 + + # Numerical parameters + DT = 1e-9 # Time step + + def __init__(self): + """Get input parameters for the specific case desired.""" + + # output diagnostics 5 times per cyclotron period + self.diag_steps = 1 + self.total_steps = 1 + + self.Lx = 1.0 + self.Ly = 1.0 + self.Lz = 2.0 + + self.DX = self.Lx / self.Nx + self.DY = self.Ly / self.Ny + self.DZ = self.Lz / self.Nz + + self.dt = self.DT + + """Setup simulation components.""" + + ####################################################################### + # Set geometry and boundary conditions # + ####################################################################### + + self.grid = picmi.Cartesian3DGrid( + number_of_cells=[self.Nx, self.Ny, self.Nz], + warpx_max_grid_size_x=self.MAX_GRID, + warpx_max_grid_size_y=self.MAX_GRID, + warpx_max_grid_size_z=self.MAX_GRID, + warpx_blocking_factor=self.BLOCKING_FACTOR, + lower_bound=[-self.Lx / 2.0, -self.Ly / 2.0, -self.Lz / 2], + upper_bound=[self.Lx / 2.0, self.Ly / 2.0, self.Lz / 2.0], + lower_boundary_conditions=["periodic", "periodic", "neumann"], + upper_boundary_conditions=["periodic", "periodic", "neumann"], + lower_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + upper_boundary_conditions_particles=["periodic", "periodic", "absorbing"], + ) + simulation.time_step_size = self.dt + simulation.max_steps = self.total_steps + + ####################################################################### + # Field solver and external field # + ####################################################################### + + self.solver = picmi.ElectrostaticSolver(grid=self.grid) + simulation.solver = self.solver + + ####################################################################### + # Install Callbacks # + ####################################################################### + init_field = picmi.LoadInitialFieldFromPython( + load_from_python=load_current_ring, + warpx_do_divb_cleaning_external=True, + load_E=False, + ) + simulation.add_applied_field(init_field) + + ####################################################################### + # Add diagnostics # + ####################################################################### + + field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=self.grid, + period=self.diag_steps, + data_list=["B"], + warpx_format="plotfile", + ) + simulation.add_diagnostic(field_diag) + + comm.Barrier() + + # Initialize inputs and WarpX instance + simulation.initialize_inputs() + simulation.initialize_warpx() + + +def load_current_ring(): + curr_loop = CurrentLoop(radius=0.75) + + Bx = fields.BxFPExternalWrapper(include_ghosts=True) + By = fields.ByFPExternalWrapper(include_ghosts=True) + Bz = fields.BzFPExternalWrapper(include_ghosts=True) + + Bx[:, :, :] = curr_loop(Bx.mesh("x"), Bx.mesh("y"), Bx.mesh("z"), coord="x") + + By[:, :, :] = curr_loop(By.mesh("x"), By.mesh("y"), By.mesh("z"), coord="y") + + Bz[:, :, :] = curr_loop(Bz.mesh("x"), Bz.mesh("y"), Bz.mesh("z"), coord="z") + + comm.Barrier() + + +run = ProjectionDivCleanerTest() +simulation.step() + +############################################## +# Post load image generation and error check # +############################################## +Bxg = fields.BxWrapper(include_ghosts=True) +Byg = fields.ByWrapper(include_ghosts=True) +Bzg = fields.BzWrapper(include_ghosts=True) + +Bx_local = Bxg[:, :, :] +By_local = Byg[:, :, :] +Bz_local = Bzg[:, :, :] + +dBxdx = (Bx_local[1:, :, :] - Bx_local[:-1, :, :]) / run.DX +dBydy = (By_local[:, 1:, :] - By_local[:, :-1, :]) / run.DY +dBzdz = (Bz_local[:, :, 1:] - Bz_local[:, :, :-1]) / run.DZ + +divB = dBxdx + dBydy + dBzdz + +import matplotlib.pyplot as plt + +plt.imshow(np.log10(np.abs(divB[:, 24, :]))) +plt.title("log10(|div(B)|)") +plt.colorbar() +plt.savefig("divb.png") + +error = np.sqrt((divB[2:-2, 2:-2, 2:-2] ** 2).sum()) +tolerance = 1e-12 + +print("error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance diff --git a/Examples/Tests/projection_divb_cleaner/inputs_test_3d_projection_divb_cleaner_picmi.py b/Examples/Tests/projection_divb_cleaner/inputs_test_3d_projection_divb_cleaner_picmi.py new file mode 100644 index 00000000000..f4347f30e56 --- /dev/null +++ b/Examples/Tests/projection_divb_cleaner/inputs_test_3d_projection_divb_cleaner_picmi.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +# +# --- Input file for loading initial field from openPMD file. + +from pywarpx import picmi + +constants = picmi.constants + +import numpy as np +import yt + +################################# +####### GENERAL PARAMETERS ###### +################################# + +max_steps = 300 + +max_grid_size = 48 +nx = max_grid_size +ny = max_grid_size +nz = max_grid_size + +xmin = -1 +xmax = 1 +ymin = xmin +ymax = xmax +zmin = 0 +zmax = 5 + +################################# +############ NUMERICS ########### +################################# + +verbose = 1 +dt = 4.4e-7 +use_filter = 0 + +################################# +######## INITIAL FIELD ########## +################################# + +initial_field = picmi.LoadInitialField( + read_fields_from_path="../../../../openPMD-example-datasets/example-femm-3d.h5", + load_E=False, +) + +################################# +###### GRID AND SOLVER ########## +################################# + +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + warpx_max_grid_size=max_grid_size, + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + upper_boundary_conditions=["dirichlet", "dirichlet", "dirichlet"], + lower_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], + upper_boundary_conditions_particles=["absorbing", "absorbing", "absorbing"], +) +solver = picmi.ElectrostaticSolver(grid=grid) + +################################# +######### DIAGNOSTICS ########### +################################# + +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=1, + data_list=["Bx", "By", "Bz"], + warpx_plot_raw_fields=True, + warpx_plot_raw_fields_guards=True, +) + +################################# +####### SIMULATION SETUP ######## +################################# + +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=verbose, + warpx_serialize_initial_conditions=False, + warpx_do_dynamic_scheduling=False, + warpx_use_filter=use_filter, + time_step_size=dt, +) + +sim.add_applied_field(initial_field) + +sim.add_diagnostic(field_diag) + +# Initialize inputs and WarpX instance +sim.initialize_inputs() +sim.initialize_warpx() + +################################# +##### SIMULATION EXECUTION ###### +################################# + +sim.step(1) + +################################# +##### SIMULATION ANALYSIS ###### +################################# + +filename = "diags/diag1000001" + +ds = yt.load(filename) +grid0 = ds.index.grids[0] + +dBxdx = ( + grid0["raw", "Bx_aux"].v[:, :, :, 1] - grid0["raw", "Bx_aux"].v[:, :, :, 0] +) / grid0.dds.v[0] +dBydy = ( + grid0["raw", "By_aux"].v[:, :, :, 1] - grid0["raw", "By_aux"].v[:, :, :, 0] +) / grid0.dds.v[1] +dBzdz = ( + grid0["raw", "Bz_aux"].v[:, :, :, 1] - grid0["raw", "Bz_aux"].v[:, :, :, 0] +) / grid0.dds.v[2] + +divB = dBxdx + dBydy + dBzdz + +import matplotlib.pyplot as plt + +plt.imshow(np.log10(np.abs(divB[:, 24, :]))) +plt.title("log10(|div(B)|)") +plt.colorbar() +plt.savefig("divb.png") + +error = np.sqrt((divB[2:-2, 2:-2, 2:-2] ** 2).sum()) +tolerance = 1e-12 + +print("error = ", error) +print("tolerance = ", tolerance) +assert error < tolerance diff --git a/Examples/Tests/projection_divb_cleaner/inputs_test_rz_projection_divb_cleaner b/Examples/Tests/projection_divb_cleaner/inputs_test_rz_projection_divb_cleaner new file mode 100644 index 00000000000..3e8f69ee411 --- /dev/null +++ b/Examples/Tests/projection_divb_cleaner/inputs_test_rz_projection_divb_cleaner @@ -0,0 +1,50 @@ +warpx.serialize_initial_conditions = 0 +warpx.do_dynamic_scheduling = 0 +particles.do_tiling = 0 + +warpx.B_ext_grid_init_style = "read_from_file" +warpx.read_fields_from_path = "../../../../openPMD-example-datasets/example-femm-thetaMode.h5" + +warpx.do_electrostatic = labframe + +################################# +####### GENERAL PARAMETERS ###### +################################# +max_step = 1 +amr.n_cell = 32 64 +warpx.numprocs = 1 1 +amr.max_level = 0 +geometry.dims = RZ + +geometry.prob_lo = 0.0 0.0 +geometry.prob_hi = 1.0 5.0 + +################################# +###### Boundary Condition ####### +################################# +boundary.field_lo = none pec +boundary.field_hi = pec pec +boundary.potential_lo_x = 0 +boundary.potential_hi_x = 0 +boundary.potential_lo_y = 0 +boundary.potential_hi_y = 0 +boundary.potential_lo_z = 0 +boundary.potential_hi_z = 0 + +################################# +############ NUMERICS ########### +################################# +warpx.serialize_initial_conditions = 1 +warpx.verbose = 1 +warpx.const_dt = 4.40917904849092e-7 +warpx.use_filter = 0 +warpx.do_divb_cleaning_external = true + +# Diagnostics +diagnostics.diags_names = diag1 +diag1.intervals = 1 +diag1.diag_type = Full +diag1.fields_to_plot = Br Bt Bz +diag1.plot_raw_fields = true +diag1.plot_raw_fields_guards = true +diag1.format = plotfile diff --git a/Examples/Tests/python_wrappers/CMakeLists.txt b/Examples/Tests/python_wrappers/CMakeLists.txt new file mode 100644 index 00000000000..0045a181606 --- /dev/null +++ b/Examples/Tests/python_wrappers/CMakeLists.txt @@ -0,0 +1,14 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_FFT) + add_warpx_test( + test_2d_python_wrappers_picmi # name + 2 # dims + 2 # nprocs + inputs_test_2d_python_wrappers_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000100 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/python_wrappers/PICMI_inputs_2d.py b/Examples/Tests/python_wrappers/PICMI_inputs_2d.py deleted file mode 100755 index db1cc7dcad8..00000000000 --- a/Examples/Tests/python_wrappers/PICMI_inputs_2d.py +++ /dev/null @@ -1,301 +0,0 @@ -#!/usr/bin/env python3 - -import matplotlib.pyplot as plt -import numpy as np -from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable - -from pywarpx import picmi - -# Number of time steps -max_steps = 100 - -# Grid -nx = 128 -nz = 128 - -# Domain -xmin = 0.e-6 -zmin = 0.e-6 -xmax = 50.e-6 -zmax = 50.e-6 - -# Cell size -dx = (xmax - xmin) / nx -dz = (zmax - zmin) / nz - -# Domain decomposition -max_grid_size_x = 64 -max_grid_size_z = 64 - -# PML -nxpml = 10 -nzpml = 10 -field_boundary = ['open', 'open'] - -# Spectral order -nox = 8 -noz = 8 - -# Guard cells -nxg = 8 -nzg = 8 - -# Initialize grid -grid = picmi.Cartesian2DGrid(number_of_cells = [nx,nz], - lower_bound = [xmin,zmin], - upper_bound = [xmax,zmax], - lower_boundary_conditions = field_boundary, - upper_boundary_conditions = field_boundary, - guard_cells = [nxg,nzg], - moving_window_velocity = [0.,0.,0], - warpx_max_grid_size_x = max_grid_size_x, - warpx_max_grid_size_y = max_grid_size_z) - -# Initialize field solver -solver = picmi.ElectromagneticSolver(grid=grid, cfl=0.95, method='PSATD', - stencil_order = [nox,noz], - divE_cleaning = 1, - divB_cleaning = 1, - pml_divE_cleaning = 1, - pml_divB_cleaning = 1, - warpx_psatd_update_with_rho = True) - -# Initialize diagnostics -diag_field_list = ["E", "B"] -particle_diag = picmi.ParticleDiagnostic(name = 'diag1', - period = 10, - write_dir = '.', - warpx_file_prefix = 'Python_wrappers_plt', - data_list = diag_field_list) -field_diag = picmi.FieldDiagnostic(name = 'diag1', - grid = grid, - period = 10, - write_dir = '.', - warpx_file_prefix = 'Python_wrappers_plt', - data_list = diag_field_list) - -# Initialize simulation -sim = picmi.Simulation(solver = solver, - max_steps = max_steps, - verbose = 1, - particle_shape = 'cubic', - warpx_current_deposition_algo = 'direct', - warpx_particle_pusher_algo = 'boris', - warpx_field_gathering_algo = 'energy-conserving', - warpx_use_filter = 1) - -# Add diagnostics to simulation -sim.add_diagnostic(particle_diag) -sim.add_diagnostic(field_diag) - -# Write input file to run with compiled version -sim.write_input_file(file_name = 'inputs_2d') - -# Whether to include guard cells in data returned by Python wrappers -include_ghosts = 1 - -# Compute min and max of fields data -def compute_minmax(data): - vmax = np.abs(data).max() - vmin = -vmax - return vmin, vmax - -# Plot fields data either in valid domain or in PML -def plot_data(data, pml, title, name): - fig, ax = plt.subplots(nrows = 1, ncols = 1, gridspec_kw = dict(wspace = 0.5), figsize = [6,5]) - cax = make_axes_locatable(ax).append_axes('right', size='5%', pad='5%') - lw = 0.8 - ls = '--' - if pml: - # Draw PMLs and ghost regions - ax.axvline(x = 0 , linewidth = lw, linestyle = ls) - ax.axvline(x = 0+nxg , linewidth = lw, linestyle = ls) - ax.axvline(x = -nxpml , linewidth = lw, linestyle = ls) - ax.axvline(x = nx , linewidth = lw, linestyle = ls) - ax.axvline(x = nx-nxg , linewidth = lw, linestyle = ls) - ax.axvline(x = nx+nxpml, linewidth = lw, linestyle = ls) - ax.axhline(y = 0 , linewidth = lw, linestyle = ls) - ax.axhline(y = 0+nzg , linewidth = lw, linestyle = ls) - ax.axhline(y = -nzpml , linewidth = lw, linestyle = ls) - ax.axhline(y = nz , linewidth = lw, linestyle = ls) - ax.axhline(y = nz-nzg , linewidth = lw, linestyle = ls) - ax.axhline(y = nz+nzpml, linewidth = lw, linestyle = ls) - # Annotations - ax.annotate('PML', xy = (-nxpml//2,nz//2), rotation = 'vertical', ha = 'center', va = 'center') - ax.annotate('PML', xy = (nx+nxpml//2,nz//2), rotation = 'vertical', ha = 'center', va = 'center') - ax.annotate('PML', xy = (nx//2,-nzpml//2), rotation = 'horizontal', ha = 'center', va = 'center') - ax.annotate('PML', xy = (nx//2,nz+nzpml//2), rotation = 'horizontal', ha = 'center', va = 'center') - ax.annotate('PML ghost', xy = (nxg//2,nz//2), rotation = 'vertical', ha = 'center', va = 'center') - ax.annotate('PML ghost', xy = (-nxpml-nxg//2,nz//2), rotation = 'vertical', ha = 'center', va = 'center') - ax.annotate('PML ghost', xy = (nx-nxg//2,nz//2), rotation = 'vertical', ha = 'center', va = 'center') - ax.annotate('PML ghost', xy = (nx+nxpml+nxg//2,nz//2), rotation = 'vertical', ha = 'center', va = 'center') - ax.annotate('PML ghost', xy = (nx//2,nzg//2), rotation = 'horizontal', ha = 'center', va = 'center') - ax.annotate('PML ghost', xy = (nx//2,-nzpml-nzg//2), rotation = 'horizontal', ha = 'center', va = 'center') - ax.annotate('PML ghost', xy = (nx//2,nz-nzg//2), rotation = 'horizontal', ha = 'center', va = 'center') - ax.annotate('PML ghost', xy = (nx//2,nz+nzpml+nzg//2), rotation = 'horizontal', ha = 'center', va = 'center') - # Set extent and sliced data - extent = np.array([-nxg-nxpml, nx+nxpml+nxg, -nzg-nzpml, nz+nzpml+nzg]) - else: - # Draw ghost regions - ax.axvline(x = 0 , linewidth = lw, linestyle = ls) - ax.axvline(x = nx, linewidth = lw, linestyle = ls) - ax.axhline(y = 0 , linewidth = lw, linestyle = ls) - ax.axhline(y = nz, linewidth = lw, linestyle = ls) - # Annotations - ax.annotate('ghost', xy = (-nxg//2,nz//2), rotation = 'vertical', ha = 'center', va = 'center') - ax.annotate('ghost', xy = (nx+nxg//2,nz//2), rotation = 'vertical', ha = 'center', va = 'center') - ax.annotate('ghost', xy = (nx//2,-nzg//2), rotation = 'horizontal', ha = 'center', va = 'center') - ax.annotate('ghost', xy = (nx//2,nz+nzg//2), rotation = 'horizontal', ha = 'center', va = 'center') - # Set extent and sliced data - extent = np.array([-nxg, nx+nxg, -nzg, nz+nzg]) - X = data[:,:].transpose() - # Min and max for colorbar - vmin, vmax = compute_minmax(X) - # Display data as image - im = ax.imshow(X = X, origin = 'lower', extent = extent, vmin = vmin, vmax = vmax, cmap = 'seismic') - # Add colorbar to plot - fig.colorbar(im, cax = cax) - # Set label for x- and y-axis, set title - ax.set_xlabel('x') - ax.set_ylabel('z') - ax.set_title(title) - # Set plot title - suptitle = 'PML in (x,z), 4 grids 64 x 64' - plt.suptitle(suptitle) - # Save figure - figname = 'figure_' + name + '.png' - fig.savefig(figname, dpi = 100) - -# Initialize fields data (unit pulse) and apply smoothing -def init_data(data): - impulse_1d = np.array([1./4., 1./2., 1./4.]) - impulse = np.outer(impulse_1d, impulse_1d) - data[nx//2-1:nx//2+2,nz//2-1:nz//2+2] = impulse - -# Initialize inputs and WarpX instance -sim.initialize_inputs() -sim.initialize_warpx() - -# Get fields data using Python wrappers -import pywarpx.fields as pwxf - -Ex = pwxf.ExFPWrapper(include_ghosts = include_ghosts) -Ey = pwxf.EyFPWrapper(include_ghosts = include_ghosts) -Ez = pwxf.EzFPWrapper(include_ghosts = include_ghosts) -Bx = pwxf.BxFPWrapper(include_ghosts = include_ghosts) -By = pwxf.ByFPWrapper(include_ghosts = include_ghosts) -Bz = pwxf.BzFPWrapper(include_ghosts = include_ghosts) -F = pwxf.FFPWrapper(include_ghosts = include_ghosts) -G = pwxf.GFPWrapper(include_ghosts = include_ghosts) -Expml = pwxf.ExFPPMLWrapper(include_ghosts = include_ghosts) -Eypml = pwxf.EyFPPMLWrapper(include_ghosts = include_ghosts) -Ezpml = pwxf.EzFPPMLWrapper(include_ghosts = include_ghosts) -Bxpml = pwxf.BxFPPMLWrapper(include_ghosts = include_ghosts) -Bypml = pwxf.ByFPPMLWrapper(include_ghosts = include_ghosts) -Bzpml = pwxf.BzFPPMLWrapper(include_ghosts = include_ghosts) -Fpml = pwxf.FFPPMLWrapper(include_ghosts = include_ghosts) -Gpml = pwxf.GFPPMLWrapper(include_ghosts = include_ghosts) - -# Initialize fields data in valid domain -init_data(Ex) -init_data(Ey) -init_data(Ez) -init_data(Bx) -init_data(By) -init_data(Bz) -init_data(F) -init_data(G) - -# Advance simulation until last time step -sim.step(max_steps) - -# Plot E -plot_data(Ex, pml = False, title = 'Ex', name = 'Ex') -plot_data(Ey, pml = False, title = 'Ey', name = 'Ey') -plot_data(Ez, pml = False, title = 'Ez', name = 'Ez') - -# Plot B -plot_data(Bx, pml = False, title = 'Bx', name = 'Bx') -plot_data(By, pml = False, title = 'By', name = 'By') -plot_data(Bz, pml = False, title = 'Bz', name = 'Bz') - -# F and G -plot_data(F, pml = False, title = 'F', name = 'F') -plot_data(G, pml = False, title = 'G', name = 'G') - -# Plot E in PML -plot_data(Expml[:,:,0], pml = True, title = 'Exy in PML', name = 'Exy') -plot_data(Expml[:,:,1], pml = True, title = 'Exz in PML', name = 'Exz') -plot_data(Expml[:,:,2], pml = True, title = 'Exx in PML', name = 'Exx') -plot_data(Eypml[:,:,0], pml = True, title = 'Eyz in PML', name = 'Eyz') -plot_data(Eypml[:,:,1], pml = True, title = 'Eyx in PML', name = 'Eyx') -plot_data(Eypml[:,:,2], pml = True, title = 'Eyy in PML', name = 'Eyy') # zero -plot_data(Ezpml[:,:,0], pml = True, title = 'Ezx in PML', name = 'Ezx') -plot_data(Ezpml[:,:,1], pml = True, title = 'Ezy in PML', name = 'Ezy') # zero -plot_data(Ezpml[:,:,2], pml = True, title = 'Ezz in PML', name = 'Ezz') - -# Plot B in PML -plot_data(Bxpml[:,:,0], pml = True, title = 'Bxy in PML', name = 'Bxy') -plot_data(Bxpml[:,:,1], pml = True, title = 'Bxz in PML', name = 'Bxz') -plot_data(Bxpml[:,:,2], pml = True, title = 'Bxx in PML', name = 'Bxx') -plot_data(Bypml[:,:,0], pml = True, title = 'Byz in PML', name = 'Byz') -plot_data(Bypml[:,:,1], pml = True, title = 'Byx in PML', name = 'Byx') -plot_data(Bypml[:,:,2], pml = True, title = 'Byy in PML', name = 'Byy') # zero -plot_data(Bzpml[:,:,0], pml = True, title = 'Bzx in PML', name = 'Bzx') -plot_data(Bzpml[:,:,1], pml = True, title = 'Bzy in PML', name = 'Bzy') # zero -plot_data(Bzpml[:,:,2], pml = True, title = 'Bzz in PML', name = 'Bzz') - -# Plot F and G in PML -plot_data(Fpml[:,:,0], pml = True, title = 'Fx in PML', name = 'Fx') -plot_data(Fpml[:,:,1], pml = True, title = 'Fy in PML', name = 'Fy') -plot_data(Fpml[:,:,2], pml = True, title = 'Fz in PML', name = 'Fz') -plot_data(Gpml[:,:,0], pml = True, title = 'Gx in PML', name = 'Gx') -plot_data(Gpml[:,:,1], pml = True, title = 'Gy in PML', name = 'Gy') -plot_data(Gpml[:,:,2], pml = True, title = 'Gz in PML', name = 'Gz') - -# Check values with benchmarks (precomputed from the same Python arrays) -def check_values(benchmark, data, rtol, atol): - passed = np.allclose(benchmark, np.sum(np.abs(data[:,:])), rtol = rtol, atol = atol) - assert(passed) - -rtol = 5e-08 -atol = 1e-12 - -# E -check_values(1013263608.6369569, Ex[:,:], rtol, atol) -check_values(717278256.7957529 , Ey[:,:], rtol, atol) -check_values(717866566.5718911 , Ez[:,:], rtol, atol) -# B -check_values(3.0214509313437636, Bx[:,:], rtol, atol) -check_values(3.0242765102729985, By[:,:], rtol, atol) -check_values(3.0214509326970465, Bz[:,:], rtol, atol) -# F and G -check_values(3.0188584528062377, F[:,:], rtol, atol) -check_values(1013672631.8764204, G[:,:], rtol, atol) -# E in PML -check_values(364287936.1526477 , Expml[:,:,0], rtol, atol) -check_values(183582352.20753333, Expml[:,:,1], rtol, atol) -check_values(190065766.41491824, Expml[:,:,2], rtol, atol) -check_values(440581907.0828975 , Eypml[:,:,0], rtol, atol) -check_values(178117294.05871135, Eypml[:,:,1], rtol, atol) -check_values(0.0 , Eypml[:,:,2], rtol, atol) -check_values(430277101.26568377, Ezpml[:,:,0], rtol, atol) -check_values(0.0 , Ezpml[:,:,1], rtol, atol) -check_values(190919663.2167449 , Ezpml[:,:,2], rtol, atol) -# B in PML -check_values(1.0565189315366146 , Bxpml[:,:,0], rtol, atol) -check_values(0.46181913800643065, Bxpml[:,:,1], rtol, atol) -check_values(0.6849858305343736 , Bxpml[:,:,2], rtol, atol) -check_values(1.7228584190213505 , Bypml[:,:,0], rtol, atol) -check_values(0.47697332248020935, Bypml[:,:,1], rtol, atol) -check_values(0.0 , Bypml[:,:,2], rtol, atol) -check_values(1.518338068658267 , Bzpml[:,:,0], rtol, atol) -check_values(0.0 , Bzpml[:,:,1], rtol, atol) -check_values(0.6849858291863835 , Bzpml[:,:,2], rtol, atol) -# F and G in PML -check_values(1.7808748509425263, Fpml[:,:,0], rtol, atol) -check_values(0.0 , Fpml[:,:,1], rtol, atol) -check_values(0.4307845604625681, Fpml[:,:,2], rtol, atol) -check_values(536552745.42701197, Gpml[:,:,0], rtol, atol) -check_values(0.0 , Gpml[:,:,1], rtol, atol) -check_values(196016270.97767758, Gpml[:,:,2], rtol, atol) diff --git a/Examples/Tests/python_wrappers/analysis_default_regression.py b/Examples/Tests/python_wrappers/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/python_wrappers/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/python_wrappers/inputs_test_2d_python_wrappers_picmi.py b/Examples/Tests/python_wrappers/inputs_test_2d_python_wrappers_picmi.py new file mode 100755 index 00000000000..66917b4146b --- /dev/null +++ b/Examples/Tests/python_wrappers/inputs_test_2d_python_wrappers_picmi.py @@ -0,0 +1,417 @@ +#!/usr/bin/env python3 + +import matplotlib.pyplot as plt +import numpy as np +from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable + +from pywarpx import picmi + +# Number of time steps +max_steps = 100 + +# Grid +nx = 128 +nz = 128 + +# Domain +xmin = 0.0e-6 +zmin = 0.0e-6 +xmax = 50.0e-6 +zmax = 50.0e-6 + +# Cell size +dx = (xmax - xmin) / nx +dz = (zmax - zmin) / nz + +# Domain decomposition +max_grid_size_x = 64 +max_grid_size_z = 64 + +# PML +nxpml = 10 +nzpml = 10 +field_boundary = ["open", "open"] + +# Spectral order +nox = 8 +noz = 8 + +# Guard cells +nxg = 8 +nzg = 8 + +# Initialize grid +grid = picmi.Cartesian2DGrid( + number_of_cells=[nx, nz], + lower_bound=[xmin, zmin], + upper_bound=[xmax, zmax], + lower_boundary_conditions=field_boundary, + upper_boundary_conditions=field_boundary, + guard_cells=[nxg, nzg], + moving_window_velocity=[0.0, 0.0, 0], + warpx_max_grid_size_x=max_grid_size_x, + warpx_max_grid_size_y=max_grid_size_z, +) + +# Initialize field solver +solver = picmi.ElectromagneticSolver( + grid=grid, + cfl=0.95, + method="PSATD", + stencil_order=[nox, noz], + divE_cleaning=1, + divB_cleaning=1, + pml_divE_cleaning=1, + pml_divB_cleaning=1, + warpx_psatd_update_with_rho=True, +) + +# Initialize diagnostics +diag_field_list = ["E", "B"] +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=10, + data_list=diag_field_list, +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=10, + data_list=diag_field_list, +) + +# Initialize simulation +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + particle_shape="cubic", + warpx_current_deposition_algo="direct", + warpx_particle_pusher_algo="boris", + warpx_field_gathering_algo="energy-conserving", + warpx_use_filter=1, +) + +# Add diagnostics to simulation +sim.add_diagnostic(particle_diag) +sim.add_diagnostic(field_diag) + +# Write input file to run with compiled version +sim.write_input_file(file_name="inputs_2d") + +# Whether to include guard cells in data returned by Python wrappers +include_ghosts = 1 + + +# Compute min and max of fields data +def compute_minmax(data): + vmax = np.abs(data).max() + vmin = -vmax + return vmin, vmax + + +# Plot fields data either in valid domain or in PML +def plot_data(data, pml, title, name): + fig, ax = plt.subplots( + nrows=1, ncols=1, gridspec_kw=dict(wspace=0.5), figsize=[6, 5] + ) + cax = make_axes_locatable(ax).append_axes("right", size="5%", pad="5%") + lw = 0.8 + ls = "--" + if pml: + # Draw PMLs and ghost regions + ax.axvline(x=0, linewidth=lw, linestyle=ls) + ax.axvline(x=0 + nxg, linewidth=lw, linestyle=ls) + ax.axvline(x=-nxpml, linewidth=lw, linestyle=ls) + ax.axvline(x=nx, linewidth=lw, linestyle=ls) + ax.axvline(x=nx - nxg, linewidth=lw, linestyle=ls) + ax.axvline(x=nx + nxpml, linewidth=lw, linestyle=ls) + ax.axhline(y=0, linewidth=lw, linestyle=ls) + ax.axhline(y=0 + nzg, linewidth=lw, linestyle=ls) + ax.axhline(y=-nzpml, linewidth=lw, linestyle=ls) + ax.axhline(y=nz, linewidth=lw, linestyle=ls) + ax.axhline(y=nz - nzg, linewidth=lw, linestyle=ls) + ax.axhline(y=nz + nzpml, linewidth=lw, linestyle=ls) + # Annotations + ax.annotate( + "PML", + xy=(-nxpml // 2, nz // 2), + rotation="vertical", + ha="center", + va="center", + ) + ax.annotate( + "PML", + xy=(nx + nxpml // 2, nz // 2), + rotation="vertical", + ha="center", + va="center", + ) + ax.annotate( + "PML", + xy=(nx // 2, -nzpml // 2), + rotation="horizontal", + ha="center", + va="center", + ) + ax.annotate( + "PML", + xy=(nx // 2, nz + nzpml // 2), + rotation="horizontal", + ha="center", + va="center", + ) + ax.annotate( + "PML ghost", + xy=(nxg // 2, nz // 2), + rotation="vertical", + ha="center", + va="center", + ) + ax.annotate( + "PML ghost", + xy=(-nxpml - nxg // 2, nz // 2), + rotation="vertical", + ha="center", + va="center", + ) + ax.annotate( + "PML ghost", + xy=(nx - nxg // 2, nz // 2), + rotation="vertical", + ha="center", + va="center", + ) + ax.annotate( + "PML ghost", + xy=(nx + nxpml + nxg // 2, nz // 2), + rotation="vertical", + ha="center", + va="center", + ) + ax.annotate( + "PML ghost", + xy=(nx // 2, nzg // 2), + rotation="horizontal", + ha="center", + va="center", + ) + ax.annotate( + "PML ghost", + xy=(nx // 2, -nzpml - nzg // 2), + rotation="horizontal", + ha="center", + va="center", + ) + ax.annotate( + "PML ghost", + xy=(nx // 2, nz - nzg // 2), + rotation="horizontal", + ha="center", + va="center", + ) + ax.annotate( + "PML ghost", + xy=(nx // 2, nz + nzpml + nzg // 2), + rotation="horizontal", + ha="center", + va="center", + ) + # Set extent and sliced data + extent = np.array( + [-nxg - nxpml, nx + nxpml + nxg, -nzg - nzpml, nz + nzpml + nzg] + ) + else: + # Draw ghost regions + ax.axvline(x=0, linewidth=lw, linestyle=ls) + ax.axvline(x=nx, linewidth=lw, linestyle=ls) + ax.axhline(y=0, linewidth=lw, linestyle=ls) + ax.axhline(y=nz, linewidth=lw, linestyle=ls) + # Annotations + ax.annotate( + "ghost", + xy=(-nxg // 2, nz // 2), + rotation="vertical", + ha="center", + va="center", + ) + ax.annotate( + "ghost", + xy=(nx + nxg // 2, nz // 2), + rotation="vertical", + ha="center", + va="center", + ) + ax.annotate( + "ghost", + xy=(nx // 2, -nzg // 2), + rotation="horizontal", + ha="center", + va="center", + ) + ax.annotate( + "ghost", + xy=(nx // 2, nz + nzg // 2), + rotation="horizontal", + ha="center", + va="center", + ) + # Set extent and sliced data + extent = np.array([-nxg, nx + nxg, -nzg, nz + nzg]) + X = data[:, :].transpose() + # Min and max for colorbar + vmin, vmax = compute_minmax(X) + # Display data as image + im = ax.imshow( + X=X, origin="lower", extent=extent, vmin=vmin, vmax=vmax, cmap="seismic" + ) + # Add colorbar to plot + fig.colorbar(im, cax=cax) + # Set label for x- and y-axis, set title + ax.set_xlabel("x") + ax.set_ylabel("z") + ax.set_title(title) + # Set plot title + suptitle = "PML in (x,z), 4 grids 64 x 64" + plt.suptitle(suptitle) + # Save figure + figname = "figure_" + name + ".png" + fig.savefig(figname, dpi=100) + + +# Initialize fields data (unit pulse) and apply smoothing +def init_data(data): + impulse_1d = np.array([1.0 / 4.0, 1.0 / 2.0, 1.0 / 4.0]) + impulse = np.outer(impulse_1d, impulse_1d) + data[nx // 2 - 1 : nx // 2 + 2, nz // 2 - 1 : nz // 2 + 2] = impulse + + +# Initialize inputs and WarpX instance +sim.initialize_inputs() +sim.initialize_warpx() + +# Get fields data using Python wrappers +import pywarpx.fields as pwxf + +Ex = pwxf.ExFPWrapper(include_ghosts=include_ghosts) +Ey = pwxf.EyFPWrapper(include_ghosts=include_ghosts) +Ez = pwxf.EzFPWrapper(include_ghosts=include_ghosts) +Bx = pwxf.BxFPWrapper(include_ghosts=include_ghosts) +By = pwxf.ByFPWrapper(include_ghosts=include_ghosts) +Bz = pwxf.BzFPWrapper(include_ghosts=include_ghosts) +F = pwxf.FFPWrapper(include_ghosts=include_ghosts) +G = pwxf.GFPWrapper(include_ghosts=include_ghosts) +Expml = pwxf.ExFPPMLWrapper(include_ghosts=include_ghosts) +Eypml = pwxf.EyFPPMLWrapper(include_ghosts=include_ghosts) +Ezpml = pwxf.EzFPPMLWrapper(include_ghosts=include_ghosts) +Bxpml = pwxf.BxFPPMLWrapper(include_ghosts=include_ghosts) +Bypml = pwxf.ByFPPMLWrapper(include_ghosts=include_ghosts) +Bzpml = pwxf.BzFPPMLWrapper(include_ghosts=include_ghosts) +Fpml = pwxf.FFPPMLWrapper(include_ghosts=include_ghosts) +Gpml = pwxf.GFPPMLWrapper(include_ghosts=include_ghosts) + +# Initialize fields data in valid domain +init_data(Ex) +init_data(Ey) +init_data(Ez) +init_data(Bx) +init_data(By) +init_data(Bz) +init_data(F) +init_data(G) + +# Advance simulation until last time step +sim.step(max_steps) + +# Plot E +plot_data(Ex, pml=False, title="Ex", name="Ex") +plot_data(Ey, pml=False, title="Ey", name="Ey") +plot_data(Ez, pml=False, title="Ez", name="Ez") + +# Plot B +plot_data(Bx, pml=False, title="Bx", name="Bx") +plot_data(By, pml=False, title="By", name="By") +plot_data(Bz, pml=False, title="Bz", name="Bz") + +# F and G +plot_data(F, pml=False, title="F", name="F") +plot_data(G, pml=False, title="G", name="G") + +# Plot E in PML +plot_data(Expml[:, :, 0], pml=True, title="Exy in PML", name="Exy") +plot_data(Expml[:, :, 1], pml=True, title="Exz in PML", name="Exz") +plot_data(Expml[:, :, 2], pml=True, title="Exx in PML", name="Exx") +plot_data(Eypml[:, :, 0], pml=True, title="Eyz in PML", name="Eyz") +plot_data(Eypml[:, :, 1], pml=True, title="Eyx in PML", name="Eyx") +plot_data(Eypml[:, :, 2], pml=True, title="Eyy in PML", name="Eyy") # zero +plot_data(Ezpml[:, :, 0], pml=True, title="Ezx in PML", name="Ezx") +plot_data(Ezpml[:, :, 1], pml=True, title="Ezy in PML", name="Ezy") # zero +plot_data(Ezpml[:, :, 2], pml=True, title="Ezz in PML", name="Ezz") + +# Plot B in PML +plot_data(Bxpml[:, :, 0], pml=True, title="Bxy in PML", name="Bxy") +plot_data(Bxpml[:, :, 1], pml=True, title="Bxz in PML", name="Bxz") +plot_data(Bxpml[:, :, 2], pml=True, title="Bxx in PML", name="Bxx") +plot_data(Bypml[:, :, 0], pml=True, title="Byz in PML", name="Byz") +plot_data(Bypml[:, :, 1], pml=True, title="Byx in PML", name="Byx") +plot_data(Bypml[:, :, 2], pml=True, title="Byy in PML", name="Byy") # zero +plot_data(Bzpml[:, :, 0], pml=True, title="Bzx in PML", name="Bzx") +plot_data(Bzpml[:, :, 1], pml=True, title="Bzy in PML", name="Bzy") # zero +plot_data(Bzpml[:, :, 2], pml=True, title="Bzz in PML", name="Bzz") + +# Plot F and G in PML +plot_data(Fpml[:, :, 0], pml=True, title="Fx in PML", name="Fx") +plot_data(Fpml[:, :, 1], pml=True, title="Fy in PML", name="Fy") +plot_data(Fpml[:, :, 2], pml=True, title="Fz in PML", name="Fz") +plot_data(Gpml[:, :, 0], pml=True, title="Gx in PML", name="Gx") +plot_data(Gpml[:, :, 1], pml=True, title="Gy in PML", name="Gy") +plot_data(Gpml[:, :, 2], pml=True, title="Gz in PML", name="Gz") + + +# Check values with benchmarks (precomputed from the same Python arrays) +def check_values(benchmark, data, rtol, atol): + passed = np.allclose(benchmark, np.sum(np.abs(data[:, :])), rtol=rtol, atol=atol) + assert passed + + +rtol = 5e-08 +atol = 1e-12 + +# E +check_values(1013263608.6369569, Ex[:, :], rtol, atol) +check_values(717278256.7957529, Ey[:, :], rtol, atol) +check_values(717866566.5718911, Ez[:, :], rtol, atol) +# B +check_values(3.0214509313437636, Bx[:, :], rtol, atol) +check_values(3.0242765102729985, By[:, :], rtol, atol) +check_values(3.0214509326970465, Bz[:, :], rtol, atol) +# F and G +check_values(3.0188584528062377, F[:, :], rtol, atol) +check_values(1013672631.8764204, G[:, :], rtol, atol) +# E in PML +check_values(364287936.1526477, Expml[:, :, 0], rtol, atol) +check_values(183582352.20753333, Expml[:, :, 1], rtol, atol) +check_values(190065766.41491824, Expml[:, :, 2], rtol, atol) +check_values(440581907.0828975, Eypml[:, :, 0], rtol, atol) +check_values(178117294.05871135, Eypml[:, :, 1], rtol, atol) +check_values(0.0, Eypml[:, :, 2], rtol, atol) +check_values(430277101.26568377, Ezpml[:, :, 0], rtol, atol) +check_values(0.0, Ezpml[:, :, 1], rtol, atol) +check_values(190919663.2167449, Ezpml[:, :, 2], rtol, atol) +# B in PML +check_values(1.0565189315366146, Bxpml[:, :, 0], rtol, atol) +check_values(0.46181913800643065, Bxpml[:, :, 1], rtol, atol) +check_values(0.6849858305343736, Bxpml[:, :, 2], rtol, atol) +check_values(1.7228584190213505, Bypml[:, :, 0], rtol, atol) +check_values(0.47697332248020935, Bypml[:, :, 1], rtol, atol) +check_values(0.0, Bypml[:, :, 2], rtol, atol) +check_values(1.518338068658267, Bzpml[:, :, 0], rtol, atol) +check_values(0.0, Bzpml[:, :, 1], rtol, atol) +check_values(0.6849858291863835, Bzpml[:, :, 2], rtol, atol) +# F and G in PML +check_values(1.7808748509425263, Fpml[:, :, 0], rtol, atol) +check_values(0.0, Fpml[:, :, 1], rtol, atol) +check_values(0.4307845604625681, Fpml[:, :, 2], rtol, atol) +check_values(536552745.42701197, Gpml[:, :, 0], rtol, atol) +check_values(0.0, Gpml[:, :, 1], rtol, atol) +check_values(196016270.97767758, Gpml[:, :, 2], rtol, atol) diff --git a/Examples/Tests/qed/CMakeLists.txt b/Examples/Tests/qed/CMakeLists.txt new file mode 100644 index 00000000000..5dd786f26a1 --- /dev/null +++ b/Examples/Tests/qed/CMakeLists.txt @@ -0,0 +1,102 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_qed_breit_wheeler # name + 2 # dims + 2 # nprocs + inputs_test_2d_qed_breit_wheeler # inputs + analysis_breit_wheeler_yt.py # analysis + diags/diag1000002 # output + OFF # dependency +) + +add_warpx_test( + test_2d_qed_breit_wheeler_opmd # name + 2 # dims + 2 # nprocs + inputs_test_2d_qed_breit_wheeler_opmd # inputs + analysis_breit_wheeler_opmd.py # analysis + diags/diag1/ # output + OFF # dependency +) + +add_warpx_test( + test_2d_qed_quantum_sync # name + 2 # dims + 2 # nprocs + inputs_test_2d_qed_quantum_sync # inputs + analysis_quantum_sync.py # analysis + diags/diag1000002 # output + OFF # dependency +) + +add_warpx_test( + test_3d_qed_breit_wheeler # name + 3 # dims + 2 # nprocs + inputs_test_3d_qed_breit_wheeler # inputs + analysis_breit_wheeler_yt.py # analysis + diags/diag1000002 # output + OFF # dependency +) + +add_warpx_test( + test_3d_qed_breit_wheeler_opmd # name + 3 # dims + 2 # nprocs + inputs_test_3d_qed_breit_wheeler_opmd # inputs + analysis_breit_wheeler_opmd.py # analysis + diags/diag1/ # output + OFF # dependency +) + +add_warpx_test( + test_3d_qed_quantum_sync # name + 3 # dims + 2 # nprocs + inputs_test_3d_qed_quantum_sync # inputs + analysis_quantum_sync.py # analysis + diags/diag1000002 # output + OFF # dependency +) + +add_warpx_test( + test_3d_qed_schwinger_1 # name + 3 # dims + 2 # nprocs + inputs_test_3d_qed_schwinger_1 # inputs + analysis_schwinger.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_3d_qed_schwinger_2 # name + 3 # dims + 2 # nprocs + inputs_test_3d_qed_schwinger_2 # inputs + analysis_schwinger.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_3d_qed_schwinger_3 # name + 3 # dims + 2 # nprocs + inputs_test_3d_qed_schwinger_3 # inputs + analysis_schwinger.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_3d_qed_schwinger_4 # name + 3 # dims + 2 # nprocs + inputs_test_3d_qed_schwinger_4 # inputs + analysis_schwinger.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/qed/analysis_breit_wheeler_core.py b/Examples/Tests/qed/analysis_breit_wheeler_core.py new file mode 100755 index 00000000000..6f5441355e8 --- /dev/null +++ b/Examples/Tests/qed/analysis_breit_wheeler_core.py @@ -0,0 +1,328 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright 2019 Luca Fedeli, Maxence Thevenet +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +import matplotlib.pyplot as plt +import numpy as np +import scipy.integrate as integ +import scipy.special as spe +import scipy.stats as st + +# This script performs detailed checks of the Breit-Wheeler pair production process. +# Four populations of photons are initialized with different momenta in different +# directions in a background EM field (with non-zero components along each direction). +# Specifically the script checks that: +# +# - The expected number of generated pairs n_pairs is in agreement with theory +# (the maximum tolerated error is 5*sqrt(n_pairs) +# - The weight of the generated particles is equal to the weight of the photon +# - Momenta of the residual photons are still equal to the original momentum +# - The generated particles are emitted in the right direction +# - Total energy is conserved in each event +# - The energy distribution of the generated particles is in agreement with theory +# - The optical depths of the product species are correctly initialized (QED effects are +# enabled for product species too). +# +# More details on the theoretical formulas used in this script can be found in +# the Jupyter notebook picsar/src/multi_physics/QED_tests/validation/validation.ipynb +# +# References: +# 1) R. Duclous et al 2011 Plasma Phys. Control. Fusion 53 015009 +# 2) A. Gonoskov et al. 2015 Phys. Rev. E 92, 023305 +# 3) M. Lobet. PhD thesis "Effets radiatifs et d'electrodynamique +# quantique dans l'interaction laser-matiere ultra-relativiste" +# URL: https://tel.archives-ouvertes.fr/tel-01314224 + + +# Tolerances +tol = 1.0e-8 +tol_red = 2.0e-2 + +# Physical constants (from CODATA 2018, see: https://physics.nist.gov/cuu/Constants/index.html ) +me = 9.1093837015e-31 # electron mass +c = 299792458 # speed of light +hbar = 6.62607015e-34 / (2 * np.pi) # reduced Plank constant +fine_structure = 7.2973525693e-3 # fine structure constant +qe = 1.602176634e-19 # elementary charge +E_s = (me**2 * c**3) / (qe * hbar) # Schwinger E field +B_s = E_s / c # Schwinger B field + +mec = me * c +mec2 = mec * c +# ______________ + +# Initial parameters +spec_names_phot = ["p1", "p2", "p3", "p4"] +spec_names_ele = ["ele1", "ele2", "ele3", "ele4"] +spec_names_pos = ["pos1", "pos2", "pos3", "pos4"] +initial_momenta = [ + np.array([2000.0, 0, 0]) * mec, + np.array([0.0, 5000.0, 0.0]) * mec, + np.array([0.0, 0.0, 10000.0]) * mec, + np.array([57735.02691896, 57735.02691896, 57735.02691896]) * mec, +] +initial_particle_number = 1048576 + +E_f = np.array([-2433321316961438.0, 973328526784575.0, 1459992790176863.0]) +B_f = np.array([2857142.85714286, 4285714.28571428, 8571428.57142857]) + +NNS = [128, 128, 128, 128] # bins for energy distribution comparison. +# ______________ + + +# Returns all the species names and if they are photon species or not +def get_all_species_names_and_types(): + names = spec_names_phot + spec_names_ele + spec_names_pos + types = [True] * len(spec_names_phot) + [False] * ( + len(spec_names_ele) + len(spec_names_pos) + ) + return names, types + + +def calc_chi_gamma(p, E, B): + pnorm = np.linalg.norm(p) + v = c * (p / pnorm) + EpvvecB = E + np.cross(v, B) + vdotEoverc = np.dot(v, E) / c + ff = np.sqrt(np.dot(EpvvecB, EpvvecB) - np.dot(vdotEoverc, vdotEoverc)) + gamma_phot = pnorm / mec + return gamma_phot * ff / E_s + + +# Auxiliary functions +@np.vectorize +def BW_inner(x): + return integ.quad( + lambda s: np.sqrt(s) * spe.kv(1.0 / 3.0, 2.0 / 3.0 * s ** (3.0 / 2.0)), + x, + np.inf, + )[0] + + +def BW_X(chi_phot, chi_ele): + div = chi_ele * (chi_phot - chi_ele) + div = np.where(np.logical_and(chi_phot > chi_ele, chi_ele != 0), div, 1.0) + res = np.where( + np.logical_and(chi_phot > chi_ele, chi_ele != 0), + np.power(chi_phot / div, 2.0 / 3.0), + np.inf, + ) + return res + + +def BW_F(chi_phot, chi_ele): + X = BW_X(chi_phot, chi_ele) + res = np.where( + np.logical_or(chi_phot == chi_ele, chi_ele == 0), + 0.0, + BW_inner(X) + - (2.0 - chi_phot * X ** (3.0 / 2.0)) + * spe.kv(2.0 / 3.0, 2.0 / 3.0 * X ** (3.0 / 2.0)), + ) + return res + + +@np.vectorize +def BW_T(chi_phot): + coeff = 1.0 / (np.pi * np.sqrt(3.0) * (chi_phot**2)) + return coeff * integ.quad(lambda chi_ele: BW_F(chi_phot, chi_ele), 0, chi_phot)[0] + + +def small_diff(vv, val): + if val != 0.0: + return np.max(np.abs((vv - val) / val)) < tol + else: + return np.max(np.abs(vv)) < tol + + +# __________________ + + +# Breit-Wheeler total and differential cross sections +def BW_dN_dt(chi_phot, gamma_phot): + coeff_BW = fine_structure * me * c**2 / hbar + return coeff_BW * BW_T(chi_phot) * (chi_phot / gamma_phot) + + +def BW_d2N_dt_dchi(chi_phot, gamma_phot, chi_ele): + coeff_BW = fine_structure * me * c**2 / hbar + return coeff_BW * BW_F(chi_phot, chi_ele) * (gamma_phot / gamma_phot) + + +# __________________ + +# Individual tests + + +def check_number_of_pairs( + particle_data, + phot_name, + ele_name, + pos_name, + chi_phot, + gamma_phot, + dt, + particle_number, +): + dNBW_dt_theo = BW_dN_dt(chi_phot, gamma_phot) + expected_pairs = (1.0 - np.exp(-dNBW_dt_theo * dt)) * particle_number + expected_pairs_tolerance = 5.0 * np.sqrt(expected_pairs) + n_ele = len(particle_data[ele_name]["w"]) + n_pos = len(particle_data[pos_name]["w"]) + n_phot = len(particle_data[phot_name]["w"]) + n_lost = initial_particle_number - n_phot + assert (n_ele == n_pos) and (n_ele == n_lost) + assert np.abs(n_ele - expected_pairs) < expected_pairs_tolerance + print(" [OK] generated pair number is within expectations") + return n_lost + + +def check_weights(phot_data, ele_data, pos_data): + assert np.all(phot_data["w"] == phot_data["w"][0]) + assert np.all(ele_data["w"] == phot_data["w"][0]) + assert np.all(pos_data["w"] == phot_data["w"][0]) + print(" [OK] particles weights are the expected ones") + + +def check_momenta(phot_data, ele_data, pos_data, p0, p_ele, p_pos): + assert small_diff(phot_data["px"], p0[0]) + assert small_diff(phot_data["py"], p0[1]) + assert small_diff(phot_data["pz"], p0[2]) + print(" [OK] residual photons still have initial momentum") + + pdir = p0 / np.linalg.norm(p0) + assert small_diff(ele_data["px"] / p_ele, pdir[0]) + assert small_diff(ele_data["py"] / p_ele, pdir[1]) + assert small_diff(ele_data["pz"] / p_ele, pdir[2]) + assert small_diff(pos_data["px"] / p_pos, pdir[0]) + assert small_diff(pos_data["py"] / p_pos, pdir[1]) + assert small_diff(pos_data["pz"] / p_pos, pdir[2]) + print(" [OK] pairs move along the initial photon direction") + + +def check_energy(energy_phot, energy_ele, energy_pos): + # Sorting the arrays is required because electrons and positrons are not + # necessarily dumped in the same order. + s_energy_ele = np.sort(energy_ele) + is_energy_pos = np.sort(energy_pos)[::-1] + product_energy = s_energy_ele + is_energy_pos + assert small_diff(product_energy, energy_phot) + print(" [OK] energy is conserved in each event") + + +def check_opt_depths(phot_data, ele_data, pos_data): + data = (phot_data, ele_data, pos_data) + for dd in data: + # Remove the negative optical depths that correspond to photons that will decay into pairs + # at the beginning of the next timestep + loc, scale = st.expon.fit(dd["opt"][dd["opt"] > 0]) + assert np.abs(loc - 0) < tol_red + assert np.abs(scale - 1) < tol_red + print(" [OK] optical depth distributions are still exponential") + + +def check_energy_distrib( + energy_ele, energy_pos, gamma_phot, chi_phot, n_lost, NN, idx, do_plot=False +): + gamma_min = 1.0001 + gamma_max = gamma_phot - 1.0001 + h_gamma_ele, c_gamma = np.histogram( + energy_ele / mec2, bins=NN, range=[gamma_min, gamma_max] + ) + h_gamma_pos, _ = np.histogram( + energy_pos / mec2, bins=NN, range=[gamma_min, gamma_max] + ) + + cchi_part_min = chi_phot * (gamma_min - 1) / (gamma_phot - 2) + cchi_part_max = chi_phot * (gamma_max - 1) / (gamma_phot - 2) + + # Rudimentary integration over npoints for each bin + npoints = 20 + aux_chi = np.linspace(cchi_part_min, cchi_part_max, NN * npoints) + distrib = BW_d2N_dt_dchi(chi_phot, gamma_phot, aux_chi) + distrib = np.sum(distrib.reshape(-1, npoints), 1) + distrib = n_lost * distrib / np.sum(distrib) + + if do_plot: + # Visual comparison of distributions + c_gamma_centered = 0.5 * (c_gamma[1:] + c_gamma[:-1]) + plt.clf() + plt.xlabel("γ_particle") + plt.ylabel("N") + plt.title("χ_photon = {:f}".format(chi_phot)) + plt.plot(c_gamma_centered, distrib, label="theory") + plt.plot(c_gamma_centered, h_gamma_ele, label="BW electrons") + plt.plot(c_gamma_centered, h_gamma_pos, label="BW positrons") + plt.legend() + plt.savefig("case_{:d}".format(idx + 1)) + + discr_ele = np.abs(h_gamma_ele - distrib) + discr_pos = np.abs(h_gamma_pos - distrib) + max_discr = 5.0 * np.sqrt(distrib) + assert np.all(discr_ele < max_discr) + assert np.all(discr_pos < max_discr) + print(" [OK] energy distribution is within expectations") + + +# __________________ + + +def check(dt, particle_data): + for idx in range(4): + phot_name = spec_names_phot[idx] + ele_name = spec_names_ele[idx] + pos_name = spec_names_pos[idx] + p0 = initial_momenta[idx] + + p2_phot = p0[0] ** 2 + p0[1] ** 2 + p0[2] ** 2 + p_phot = np.sqrt(p2_phot) + energy_phot = p_phot * c + chi_phot = calc_chi_gamma(p0, E_f, B_f) + gamma_phot = np.linalg.norm(p0) / mec + + print("** Case {:d} **".format(idx + 1)) + print(" initial momentum: ", p0) + print(" quantum parameter: {:f}".format(chi_phot)) + print(" normalized photon energy: {:f}".format(gamma_phot)) + print(" timestep: {:f} fs".format(dt * 1e15)) + + phot_data = particle_data[phot_name] + ele_data = particle_data[ele_name] + pos_data = particle_data[pos_name] + + p2_ele = ele_data["px"] ** 2 + ele_data["py"] ** 2 + ele_data["pz"] ** 2 + p_ele = np.sqrt(p2_ele) + energy_ele = np.sqrt(1.0 + p2_ele / mec**2) * mec2 + p2_pos = pos_data["px"] ** 2 + pos_data["py"] ** 2 + pos_data["pz"] ** 2 + p_pos = np.sqrt(p2_pos) + energy_pos = np.sqrt(1.0 + p2_pos / mec**2) * mec2 + + n_lost = check_number_of_pairs( + particle_data, + phot_name, + ele_name, + pos_name, + chi_phot, + gamma_phot, + dt, + initial_particle_number, + ) + + check_weights(phot_data, ele_data, pos_data) + + check_momenta(phot_data, ele_data, pos_data, p0, p_ele, p_pos) + + check_energy(energy_phot, energy_ele, energy_pos) + + check_energy_distrib( + energy_ele, energy_pos, gamma_phot, chi_phot, n_lost, NNS[idx], idx + ) + + check_opt_depths(phot_data, ele_data, pos_data) + + print("*************\n") diff --git a/Examples/Tests/qed/breit_wheeler/analysis_opmd.py b/Examples/Tests/qed/analysis_breit_wheeler_opmd.py similarity index 69% rename from Examples/Tests/qed/breit_wheeler/analysis_opmd.py rename to Examples/Tests/qed/analysis_breit_wheeler_opmd.py index 2b1fbc7038b..25547eda438 100755 --- a/Examples/Tests/qed/breit_wheeler/analysis_opmd.py +++ b/Examples/Tests/qed/analysis_breit_wheeler_opmd.py @@ -9,30 +9,31 @@ import sys -import analysis_core as ac +import analysis_breit_wheeler_core as ac import openpmd_api as io -#sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -#import checksumAPI +# sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +# import checksumAPI # This script is a frontend for the analysis routines -# in analysis_core.py (please refer to this file for +# in analysis_breit_wheeler_core.py (please refer to this file for # a full description). It reads output files in openPMD # format and extracts the data needed for # the analysis routines. + def main(): print("Opening openPMD output") prefix = sys.argv[1] - series = io.Series(prefix+"/openpmd_%T.h5", io.Access.read_only) + series = io.Series(prefix + "/openpmd_%T.h5", io.Access.read_only) data_set_end = series.iterations[2] # get simulation time sim_time = data_set_end.time # no particles can be created on the first timestep so we have 2 timesteps in the test case, # with only the second one resulting in particle creation - dt = sim_time/2. + dt = sim_time / 2.0 # get particle data particle_data = {} @@ -46,12 +47,18 @@ def main(): px = data_set_end.particles[spec_name]["momentum"]["x"][:] py = data_set_end.particles[spec_name]["momentum"]["y"][:] pz = data_set_end.particles[spec_name]["momentum"]["z"][:] - w = data_set_end.particles[spec_name]["weighting"][io.Mesh_Record_Component.SCALAR][:] - - if is_photon : - opt = data_set_end.particles[spec_name]["opticalDepthBW"][io.Mesh_Record_Component.SCALAR][:] + w = data_set_end.particles[spec_name]["weighting"][ + io.Mesh_Record_Component.SCALAR + ][:] + + if is_photon: + opt = data_set_end.particles[spec_name]["opticalDepthBW"][ + io.Mesh_Record_Component.SCALAR + ][:] else: - opt = data_set_end.particles[spec_name]["opticalDepthQSR"][io.Mesh_Record_Component.SCALAR][:] + opt = data_set_end.particles[spec_name]["opticalDepthQSR"][ + io.Mesh_Record_Component.SCALAR + ][:] series.flush() @@ -65,8 +72,9 @@ def main(): ac.check(dt, particle_data) - #test_name = os.path.split(os.getcwd())[1] - #checksumAPI.evaluate_checksum(test_name, filename_end) + # test_name = os.path.split(os.getcwd())[1] + # checksumAPI.evaluate_checksum(test_name, filename_end) + if __name__ == "__main__": main() diff --git a/Examples/Tests/qed/breit_wheeler/analysis_yt.py b/Examples/Tests/qed/analysis_breit_wheeler_yt.py similarity index 69% rename from Examples/Tests/qed/breit_wheeler/analysis_yt.py rename to Examples/Tests/qed/analysis_breit_wheeler_yt.py index e8950419f25..9836e3e8894 100755 --- a/Examples/Tests/qed/breit_wheeler/analysis_yt.py +++ b/Examples/Tests/qed/analysis_breit_wheeler_yt.py @@ -12,16 +12,18 @@ import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import analysis_core as ac +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import analysis_breit_wheeler_core as ac import checksumAPI # This script is a frontend for the analysis routines -# in analysis_core.py (please refer to this file for +# in analysis_breit_wheeler_core.py (please refer to this file for # a full description). It reads output files in yt # format and extracts the data needed for # the analysis routines. yt + + def main(): print("Opening yt output") filename_end = sys.argv[1] @@ -31,7 +33,7 @@ def main(): sim_time = data_set_end.current_time.to_value() # no particles can be created on the first timestep so we have 2 timesteps in the test case, # with only the second one resulting in particle creation - dt = sim_time/2. + dt = sim_time / 2.0 # get particle data all_data_end = data_set_end.all_data() @@ -42,13 +44,13 @@ def main(): spec_name = spec_name_type[0] is_photon = spec_name_type[1] data = {} - data["px"] = all_data_end[spec_name,"particle_momentum_x"].v - data["py"] = all_data_end[spec_name,"particle_momentum_y"].v - data["pz"] = all_data_end[spec_name,"particle_momentum_z"].v - data["w"] = all_data_end[spec_name,"particle_weighting"].v + data["px"] = all_data_end[spec_name, "particle_momentum_x"].v + data["py"] = all_data_end[spec_name, "particle_momentum_y"].v + data["pz"] = all_data_end[spec_name, "particle_momentum_z"].v + data["w"] = all_data_end[spec_name, "particle_weighting"].v - if is_photon : - data["opt"] = all_data_end[spec_name, "particle_opticalDepthBW"].v + if is_photon: + data["opt"] = all_data_end[spec_name, "particle_opticalDepthBW"].v else: data["opt"] = all_data_end[spec_name, "particle_opticalDepthQSR"].v @@ -59,5 +61,6 @@ def main(): test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename_end) + if __name__ == "__main__": main() diff --git a/Examples/Tests/qed/analysis_quantum_sync.py b/Examples/Tests/qed/analysis_quantum_sync.py new file mode 100755 index 00000000000..cf60d2ee647 --- /dev/null +++ b/Examples/Tests/qed/analysis_quantum_sync.py @@ -0,0 +1,360 @@ +#!/usr/bin/env python3 + +# Copyright 2019 Luca Fedeli, Maxence Thevenet +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +# -*- coding: utf-8 -*- + +import os +import sys + +import numpy as np +import scipy.integrate as integ +import scipy.special as spe +import scipy.stats as st +import yt + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI +import matplotlib.pyplot as plt + +# This script performs detailed checks of the Quantum Synchrotron photon emission process. +# Two electron populations and two positron populations are initialized with different momenta in different +# directions in a background EM field (with non-zero components along each direction). +# Specifically the script checks that: +# +# - The expected number of generated photons n_phot is in agreement with theory. +# The maximum tolerated error is 5*sqrt(n_phot), except for the last 8 points, +# for which a higher tolerance is used (this is due to the fact that the resolution +# of the builtin table is quite limited). +# - The weight of the generated particles is equal to the weight of the photon +# - The generated particles are emitted in the right direction +# - The energy distribution of the generated particles is in agreement with theory +# - The optical depths of the product species are correctly initialized (QED effects are +# enabled for product species too). +# +# More details on the theoretical formulas used in this script can be found in +# the Jupyter notebook picsar/src/multi_physics/QED_tests/validation/validation.ipynb +# +# References: +# 1) R. Duclous et al 2011 Plasma Phys. Control. Fusion 53 015009 +# 2) A. Gonoskov et al. 2015 Phys. Rev. E 92, 023305 +# 3) M. Lobet. PhD thesis "Effets radiatifs et d'electrodynamique +# quantique dans l'interaction laser-matiere ultra-relativiste" +# URL: https://tel.archives-ouvertes.fr/tel-01314224 + + +# Tolerances +tol = 1.0e-8 +tol_red = 1.0e-2 + +# Physical constants (from CODATA 2018, see: https://physics.nist.gov/cuu/Constants/index.html ) +me = 9.1093837015e-31 # electron mass +c = 299792458 # speed of light +hbar = 6.62607015e-34 / (2 * np.pi) # reduced Plank constant +fine_structure = 7.2973525693e-3 # fine structure constant +qe = 1.602176634e-19 # elementary charge +E_s = (me**2 * c**3) / (qe * hbar) # Schwinger E field +B_s = E_s / c # Schwinger B field + +mec = me * c +mec2 = mec * c +# ______________ + +# Initial parameters +spec_names = ["p1", "p2", "p3", "p4"] +spec_names_phot = ["qsp_1", "qsp_2", "qsp_3", "qsp_4"] +initial_momenta = [ + np.array([10.0, 0, 0]) * mec, + np.array([0.0, 100.0, 0.0]) * mec, + np.array([0.0, 0.0, 1000.0]) * mec, + np.array([5773.502691896, 5773.502691896, 5773.502691896]) * mec, +] +csign = [-1, -1, 1, 1] +initial_particle_number = 1048576 + +E_f = np.array([-2433321316961438.0, 973328526784575.0, 1459992790176863.0]) +B_f = np.array([2857142.85714286, 4285714.28571428, 8571428.57142857]) + +NNS = [64, 64, 64, 64] # bins for energy distribution comparison. +# ______________ + + +def calc_chi_part(p, E, B): + gamma_part = np.sqrt(1.0 + np.dot(p, p) / mec**2) + v = p / (gamma_part * me) + EpvvecB = E + np.cross(v, B) + vdotEoverc = np.dot(v, E) / c + ff = np.sqrt(np.dot(EpvvecB, EpvvecB) - np.dot(vdotEoverc, vdotEoverc)) + return gamma_part * ff / E_s + + +# Auxiliary functions +@np.vectorize +def IC_inner_alternative(y): + def ff(x): + return ( + np.exp(-y * (1 + 4 * x**2 / 3) * np.sqrt(1 + x * x / 3)) + * (9 + 36 * x**2 + 16 * x**4) + / (3 + 4 * x**2) + / np.sqrt(1 + x**2 / 3) + ) + + # This integration may not converge in some cases, in which case a python warning message can + # be issued. This is probably not a significant issue for this test case and these warnings can + # be ignored. + return integ.quad(ff, 0, np.inf)[0] / np.sqrt(3) + + +def IC_Y(chi_ele, xi): + div = chi_ele * (1 - xi) + div = np.where(np.logical_and(xi < 1, chi_ele != 0), div, 1.0) + res = (2 / 3) * np.where(np.logical_and(xi < 1, chi_ele != 0), xi / div, np.inf) + return res + + +def IC_S(chi_ele, xi): + Y = IC_Y(chi_ele, xi) + coeff = np.sqrt(3) / 2.0 / np.pi + first = IC_inner_alternative(Y) + div = np.where(xi == 1, 1.0, 1.0 / (1 - xi)) + res = np.where( + np.logical_or(xi == 1, xi == 0), + 0.0, + coeff * xi * (first + (xi**2 * spe.kv(2.0 / 3.0, Y) * div)), + ) + return res + + +def IC_SXI(chi_ele, xi): + div = np.where(xi != 0, xi, 1.0) + return np.where(xi != 0, IC_S(chi_ele, xi) / div, np.inf) + + +@np.vectorize +def IC_G(chi_ele): + return integ.quad(lambda xi: IC_SXI(chi_ele, xi), 0, 1)[0] + + +def small_diff(vv, val): + if val != 0.0: + return np.max(np.abs((vv - val) / val)) < tol + else: + return np.max(np.abs(vv)) < tol + + +def boris(pp, dt, charge_sign): + econst = 0.5 * qe * dt * charge_sign / me + u = pp / (me) + u += econst * E_f + inv_gamma = 1 / np.sqrt(1 + np.dot(u, u) / c**2) + t = econst * B_f * inv_gamma + s = 2 * t / (1 + np.dot(t, t)) + u_p = u + np.cross(u, t) + u += np.cross(u_p, s) + u += econst * E_f + return u * me + + +# __________________ + + +# Quantum Synchrotron total and differential cross sections +def QS_dN_dt(chi_ele, gamma_ele): + coeff_IC = (2.0 / 3.0) * fine_structure * me * c**2 / hbar + return coeff_IC * IC_G(chi_ele) / gamma_ele + + +def QS_d2N_dt_dchi(chi, gamma_ele, chi_phot): + coeff_IC = (2.0 / 3.0) * fine_structure * me * c**2 / hbar + return coeff_IC * IC_S(chi, chi_phot / chi) / chi_phot / gamma_ele + + +# __________________ + + +# Get data for a species +def get_spec(ytdata, specname, is_photon): + px = ytdata[specname, "particle_momentum_x"].v + pz = ytdata[specname, "particle_momentum_z"].v + py = ytdata[specname, "particle_momentum_y"].v + + w = ytdata[specname, "particle_weighting"].v + + if is_photon: + opt = ytdata[specname, "particle_opticalDepthBW"].v + else: + opt = ytdata[specname, "particle_opticalDepthQSR"].v + + return {"px": px, "py": py, "pz": pz, "w": w, "opt": opt} + + +# Individual tests +def check_number_of_photons( + ytdataset, part_name, phot_name, chi_part, gamma_part, dt, particle_number +): + dNQS_dt_theo = QS_dN_dt(chi_part, gamma_part) + expected_photons = (1.0 - np.exp(-dNQS_dt_theo * dt)) * particle_number + expected_photons_tolerance = 5.0 * np.sqrt(expected_photons) + n_phot = ytdataset.particle_type_counts[phot_name] + assert np.abs(n_phot - expected_photons) < expected_photons_tolerance + print(" [OK] generated photons number is within expectations") + return n_phot + + +def check_weights(part_data, phot_data): + assert np.all(part_data["w"] == part_data["w"][0]) + assert np.all(phot_data["w"] == part_data["w"][0]) + print(" [OK] particles weights are the expected ones") + + +def check_momenta(phot_data, p_phot, p0): + pdir = p0 / np.linalg.norm(p0) + assert small_diff(phot_data["px"] / p_phot, pdir[0]) + assert small_diff(phot_data["py"] / p_phot, pdir[1]) + assert small_diff(phot_data["pz"] / p_phot, pdir[2]) + print(" [OK] photons move along the initial particle direction") + + +def check_opt_depths(part_data, phot_data): + data = (part_data, phot_data) + for dd in data: + # Remove the negative optical depths that will be + # reset at the beginning of the next timestep + loc, scale = st.expon.fit(dd["opt"][dd["opt"] > 0]) + assert np.abs(loc - 0) < tol_red + assert np.abs(scale - 1) < tol_red + print(" [OK] optical depth distributions are still exponential") + + +def check_energy_distrib( + gamma_phot, chi_part, gamma_part, n_phot, NN, idx, do_plot=False +): + gamma_phot_min = 1e-12 * gamma_part + gamma_phot_max = gamma_part + h_log_gamma_phot, c_gamma_phot = np.histogram( + gamma_phot, + bins=np.logspace(np.log10(gamma_phot_min), np.log10(gamma_phot_max), NN + 1), + ) + + cchi_phot_min = chi_part * (gamma_phot_min) / (gamma_part - 1) + cchi_phot_max = chi_part * (gamma_phot_max) / (gamma_part - 1) + + # Rudimentary integration over npoints for each bin + npoints = 20 + aux_chi = np.logspace( + np.log10(cchi_phot_min), np.log10(cchi_phot_max), NN * npoints + ) + distrib = QS_d2N_dt_dchi(chi_part, gamma_part, aux_chi) * aux_chi + distrib = np.sum(distrib.reshape(-1, npoints), 1) + distrib = n_phot * distrib / np.sum(distrib) + + if do_plot: + # Visual comparison of distributions + c_gamma_phot = np.exp( + 0.5 * (np.log(c_gamma_phot[1:]) + np.log(c_gamma_phot[:-1])) + ) + plt.clf() + + fig, (ax1, ax2) = plt.subplots(1, 2) + fig.suptitle("χ_particle = {:f}".format(chi_part)) + ax1.plot(c_gamma_phot, distrib, label="theory") + ax1.loglog(c_gamma_phot, h_log_gamma_phot, label="QSR photons") + ax1.set_xlim(1e-12 * (gamma_part - 1), gamma_part - 1) + ax1.set_ylim(1, 1e5) + ax2.plot(c_gamma_phot, distrib, label="theory") + ax2.semilogy(c_gamma_phot, h_log_gamma_phot, label="QSR photons") + ax2.set_ylim(1, 1e5) + ax2.set_xlim(1e-12 * (gamma_part - 1), gamma_part - 1) + ax1.set_xlabel("γ_photon") + ax1.set_xlabel("N") + ax2.set_xlabel("γ_photon") + ax2.set_xlabel("N") + plt.legend() + plt.savefig("case_{:d}".format(idx + 1)) + + discr = np.abs(h_log_gamma_phot - distrib) + + max_discr = np.sqrt(distrib) * 5.0 + # Use a higer tolerance for the last 8 points (this is due to limitations + # of the builtin table) + max_discr[-8:] *= 2.0 + assert np.all(discr < max_discr) + + print(" [OK] energy distribution is within expectations") + + +# __________________ + + +def check(): + filename_end = sys.argv[1] + data_set_end = yt.load(filename_end) + + sim_time = data_set_end.current_time.to_value() + # no particles can be created on the first timestep so we have 2 timesteps in the test case, + # with only the second one resulting in particle creation + dt = sim_time / 2.0 + + all_data_end = data_set_end.all_data() + + for idx in range(4): + part_name = spec_names[idx] + phot_name = spec_names_phot[idx] + t_pi = initial_momenta[idx] + pm = boris(t_pi, -dt * 0.5, csign[idx]) + p0 = boris(pm, dt * 1.0, csign[idx]) + + p2_part = p0[0] ** 2 + p0[1] ** 2 + p0[2] ** 2 + energy_part = np.sqrt(mec2**2 + p2_part * c**2) + gamma_part = energy_part / mec2 + chi_part = calc_chi_part(p0, E_f, B_f) + + print("** Case {:d} **".format(idx + 1)) + print(" initial momentum: ", t_pi) + print(" quantum parameter: {:f}".format(chi_part)) + print(" normalized particle energy: {:f}".format(gamma_part)) + print(" timestep: {:f} fs".format(dt * 1e15)) + + part_data_final = get_spec(all_data_end, part_name, is_photon=False) + phot_data = get_spec(all_data_end, phot_name, is_photon=True) + + p_phot = np.sqrt( + phot_data["px"] ** 2 + phot_data["py"] ** 2 + phot_data["pz"] ** 2 + ) + energy_phot = p_phot * c + gamma_phot = energy_phot / mec2 + + n_phot = check_number_of_photons( + data_set_end, + part_name, + phot_name, + chi_part, + gamma_part, + dt, + initial_particle_number, + ) + + check_weights(part_data_final, phot_data) + + check_momenta(phot_data, p_phot, p0) + + check_energy_distrib(gamma_phot, chi_part, gamma_part, n_phot, NNS[idx], idx) + + check_opt_depths(part_data_final, phot_data) + + print("*************\n") + + test_name = os.path.split(os.getcwd())[1] + checksumAPI.evaluate_checksum(test_name, filename_end) + + +def main(): + check() + + +if __name__ == "__main__": + main() diff --git a/Examples/Tests/qed/analysis_schwinger.py b/Examples/Tests/qed/analysis_schwinger.py new file mode 100755 index 00000000000..30a25e6a956 --- /dev/null +++ b/Examples/Tests/qed/analysis_schwinger.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Luca Fedeli, Neil Zaim +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +## This module is imported by each of the scripts used to analyze the Schwinger tests. + +## The pair production rate is calculated using the formula described in +## Bulanov, S. S., et al. Physical review letters 104.22 (2010): 220404. + +import os +import re +import sys + +import numpy as np +import yt + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +# define some parameters + +c = 299792458.0 +m_e = 9.1093837015e-31 +e = 1.602176634e-19 +hbar = 1.054571817e-34 +E_S = m_e**2 * c**3 / e / hbar # Schwinger field + +dV = (1.0e-6) ** 3 # total simulation volume +dt = 9.827726403e-17 +filename = sys.argv[1] + +Ex_test = 0.0 +Ey_test = 0.0 +Ez_test = 0.0 +Bx_test = 0.0 +By_test = 0.0 +Bz_test = 0.0 + +# Find which test we are doing +test_name = os.path.split(os.getcwd())[1] +test_number = re.search("qed_schwinger_([1234])", test_name).group(1) +if test_number == "1": + # First Schwinger test with "weak" EM field. No pair should be created. + Ex_test = 1.0e16 + Bx_test = 16792888.570516706 + By_test = 5256650.141557486 + Bz_test = 18363530.799561853 +elif test_number == "2": + # Second Schwinger test with stronger EM field. Many pairs are created and a Gaussian + # distribution is used to get the weights of the particles. This is the most sensitive test + # because the relative std is extremely low. + Ex_test = 1.0e18 + Bx_test = 1679288857.0516706 + By_test = 525665014.1557486 + Bz_test = 1836353079.9561853 + dV = dV / 2.0 # Schwinger is only activated in part of the simulation domain +elif test_number == "3": + # Third Schwinger test with intermediate electric field such that average created pair per cell + # is 1. A Poisson distribution is used to obtain the weights of the particles. + Ey_test = 1.090934525450495e17 +elif test_number == "4": + # Fourth Schwinger test with extremely strong EM field but with E and B perpendicular and nearly + # equal so that the pair production rate is fairly low. A Gaussian distribution is used in this + # case. + Ez_test = 2.5e20 + By_test = 833910140000.0 + dV = ( + dV * (3.0 / 4.0) ** 2.0 + ) # Schwinger is only activated in part of the simulation domain +else: + assert False + + +def calculate_rate(Ex, Ey, Ez, Bx, By, Bz): + ## Calculate theoretical pair production rate from EM field value + + E_squared = Ex**2 + Ey**2 + Ez**2 + H_squared = c**2 * (Bx**2 + By**2 + Bz**2) + + F = (E_squared - H_squared) / 2.0 + G = c * (Ex * Bx + Ey * By + Ez * Bz) + + epsilon = np.sqrt(np.sqrt(F**2 + G**2) + F) / E_S + eta = np.sqrt(np.sqrt(F**2 + G**2) - F) / E_S + + if epsilon != 0.0 and eta != 0.0: + return ( + e**2 + * E_S**2 + / 4.0 + / np.pi**2 + / c + / hbar**2 + * epsilon + * eta + / np.tanh(np.pi * eta / epsilon) + * np.exp(-np.pi / epsilon) + ) + elif epsilon == 0.0: + return 0.0 + else: + return ( + e**2 + * E_S**2 + / 4.0 + / np.pi**2 + / c + / hbar**2 + * epsilon**2 + / np.pi + * np.exp(-np.pi / epsilon) + ) + + +def do_analysis(Ex, Ey, Ez, Bx, By, Bz): + data_set = yt.load(filename) + + expected_total_physical_pairs_created = ( + dV * dt * calculate_rate(Ex, Ey, Ez, Bx, By, Bz) + ) + if expected_total_physical_pairs_created < 0.01: + np_ele = ( + data_set.particle_type_counts["ele_schwinger"] + if "ele_schwinger" in data_set.particle_type_counts.keys() + else 0 + ) + np_pos = ( + data_set.particle_type_counts["pos_schwinger"] + if "pos_schwinger" in data_set.particle_type_counts.keys() + else 0 + ) + assert np_ele == 0 and np_pos == 0 + ## Assert whether pairs are created or not. + + else: + all_data = data_set.all_data() + + ele_data = all_data["ele_schwinger", "particle_weight"] + pos_data = all_data["pos_schwinger", "particle_weight"] + + std_total_physical_pairs_created = np.sqrt( + expected_total_physical_pairs_created + ) + + # Sorting the arrays is required because electrons and positrons are not necessarily + # dumped in the same order. + assert np.array_equal(np.sort(ele_data), np.sort(pos_data)) + # 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions + error = np.abs(np.sum(ele_data) - expected_total_physical_pairs_created) + print( + "difference between expected and actual number of pairs created: " + + str(error) + ) + print("tolerance: " + str(5 * std_total_physical_pairs_created)) + assert error < 5 * std_total_physical_pairs_created + + +do_analysis(Ex_test, Ey_test, Ez_test, Bx_test, By_test, Bz_test) + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/qed/breit_wheeler/analysis_core.py b/Examples/Tests/qed/breit_wheeler/analysis_core.py deleted file mode 100755 index 61d928bf2cc..00000000000 --- a/Examples/Tests/qed/breit_wheeler/analysis_core.py +++ /dev/null @@ -1,271 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright 2019 Luca Fedeli, Maxence Thevenet -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import matplotlib.pyplot as plt -import numpy as np -import scipy.integrate as integ -import scipy.special as spe -import scipy.stats as st - -# This script performs detailed checks of the Breit-Wheeler pair production process. -# Four populations of photons are initialized with different momenta in different -# directions in a background EM field (with non-zero components along each direction). -# Specifically the script checks that: -# -# - The expected number of generated pairs n_pairs is in agreement with theory -# (the maximum tolerated error is 5*sqrt(n_pairs) -# - The weight of the generated particles is equal to the weight of the photon -# - Momenta of the residual photons are still equal to the original momentum -# - The generated particles are emitted in the right direction -# - Total energy is conserved in each event -# - The energy distribution of the generated particles is in agreement with theory -# - The optical depths of the product species are correctly initialized (QED effects are -# enabled for product species too). -# -# More details on the theoretical formulas used in this script can be found in -# the Jupyter notebook picsar/src/multi_physics/QED_tests/validation/validation.ipynb -# -# References: -# 1) R. Duclous et al 2011 Plasma Phys. Control. Fusion 53 015009 -# 2) A. Gonoskov et al. 2015 Phys. Rev. E 92, 023305 -# 3) M. Lobet. PhD thesis "Effets radiatifs et d'electrodynamique -# quantique dans l'interaction laser-matiere ultra-relativiste" -# URL: https://tel.archives-ouvertes.fr/tel-01314224 - - -# Tolerances -tol = 1.e-8 -tol_red = 2.e-2 - -# Physical constants (from CODATA 2018, see: https://physics.nist.gov/cuu/Constants/index.html ) -me = 9.1093837015e-31 #electron mass -c = 299792458 #speed of light -hbar = 6.62607015e-34/(2*np.pi) #reduced Plank constant -fine_structure = 7.2973525693e-3 #fine structure constant -qe = 1.602176634e-19#elementary charge -E_s = (me**2 * c**3)/(qe * hbar) #Schwinger E field -B_s = E_s/c #Schwinger B field - -mec = me*c -mec2 = mec*c -#______________ - -# Initial parameters -spec_names_phot = ["p1", "p2", "p3", "p4"] -spec_names_ele = ["ele1", "ele2", "ele3", "ele4"] -spec_names_pos = ["pos1", "pos2", "pos3", "pos4"] -initial_momenta = [ - np.array([2000.0,0,0])*mec, - np.array([0.0,5000.0,0.0])*mec, - np.array([0.0,0.0,10000.0])*mec, - np.array([57735.02691896, 57735.02691896, 57735.02691896])*mec -] -initial_particle_number = 1048576 - -E_f = np.array([-2433321316961438., 973328526784575., 1459992790176863.]) -B_f = np.array([2857142.85714286, 4285714.28571428, 8571428.57142857]) - -NNS = [128,128,128,128] #bins for energy distribution comparison. -#______________ - -#Returns all the species names and if they are photon species or not -def get_all_species_names_and_types(): - names = spec_names_phot + spec_names_ele + spec_names_pos - types = [True]*len(spec_names_phot) + [False]*(len(spec_names_ele)+len(spec_names_pos)) - return names, types - -def calc_chi_gamma(p, E, B): - pnorm = np.linalg.norm(p) - v = c*(p/pnorm) - EpvvecB = E + np.cross(v,B) - vdotEoverc = np.dot(v,E)/c - ff = np.sqrt(np.dot(EpvvecB,EpvvecB) - np.dot(vdotEoverc,vdotEoverc)) - gamma_phot = pnorm/mec - return gamma_phot*ff/E_s - -#Auxiliary functions -@np.vectorize -def BW_inner(x): - return integ.quad(lambda s: np.sqrt(s)*spe.kv(1./3., 2./3. * s**(3./2.)), x, np.inf)[0] - -def BW_X(chi_phot, chi_ele): - div = (chi_ele*(chi_phot-chi_ele)) - div = np.where(np.logical_and(chi_phot > chi_ele, chi_ele != 0), div, 1.0); - res = np.where(np.logical_and(chi_phot > chi_ele, chi_ele != 0), np.power(chi_phot/div, 2./3.), np.inf) - return res - -def BW_F(chi_phot, chi_ele): - X = BW_X(chi_phot, chi_ele) - res = np.where(np.logical_or(chi_phot == chi_ele, chi_ele == 0), 0.0, - BW_inner(X) - (2.0 - chi_phot* X**(3./2.))*spe.kv(2./3., 2./3. * X**(3./2.)) ) - return res - -@np.vectorize -def BW_T(chi_phot): - coeff = 1./(np.pi * np.sqrt(3.) * (chi_phot**2)) - return coeff*integ.quad(lambda chi_ele: BW_F(chi_phot, chi_ele), 0, chi_phot)[0] - -def small_diff(vv, val): - if(val != 0.0): - return np.max(np.abs((vv - val)/val)) < tol - else: - return np.max(np.abs(vv)) < tol -#__________________ - -# Breit-Wheeler total and differential cross sections -def BW_dN_dt(chi_phot, gamma_phot): - coeff_BW = fine_structure * me*c**2/hbar - return coeff_BW*BW_T(chi_phot)*(chi_phot/gamma_phot) - -def BW_d2N_dt_dchi(chi_phot, gamma_phot, chi_ele): - coeff_BW = fine_structure * me*c**2/hbar - return coeff_BW*BW_F(chi_phot, chi_ele)*(gamma_phot/gamma_phot) -#__________________ - -# Individual tests - -def check_number_of_pairs(particle_data, phot_name, ele_name, pos_name, chi_phot, gamma_phot, dt, particle_number): - dNBW_dt_theo = BW_dN_dt(chi_phot, gamma_phot) - expected_pairs = (1.-np.exp(-dNBW_dt_theo*dt))*particle_number - expected_pairs_tolerance = 5.0*np.sqrt(expected_pairs) - n_ele = len(particle_data[ele_name]["w"]) - n_pos = len(particle_data[pos_name]["w"]) - n_phot = len(particle_data[phot_name]["w"]) - n_lost = initial_particle_number-n_phot - assert((n_ele == n_pos) and (n_ele == n_lost)) - assert( np.abs(n_ele-expected_pairs) < expected_pairs_tolerance) - print(" [OK] generated pair number is within expectations") - return n_lost - -def check_weights(phot_data, ele_data, pos_data): - assert(np.all(phot_data["w"] == phot_data["w"][0])) - assert(np.all(ele_data["w"] == phot_data["w"][0])) - assert(np.all(pos_data["w"] == phot_data["w"][0])) - print(" [OK] particles weights are the expected ones") - -def check_momenta(phot_data, ele_data, pos_data, p0, p_ele, p_pos): - assert(small_diff(phot_data["px"], p0[0])) - assert(small_diff(phot_data["py"], p0[1])) - assert(small_diff(phot_data["pz"], p0[2])) - print(" [OK] residual photons still have initial momentum") - - pdir = p0/np.linalg.norm(p0) - assert(small_diff(ele_data["px"]/p_ele, pdir[0])) - assert(small_diff(ele_data["py"]/p_ele, pdir[1])) - assert(small_diff(ele_data["pz"]/p_ele, pdir[2])) - assert(small_diff(pos_data["px"]/p_pos, pdir[0])) - assert(small_diff(pos_data["py"]/p_pos, pdir[1])) - assert(small_diff(pos_data["pz"]/p_pos, pdir[2])) - print(" [OK] pairs move along the initial photon direction") - -def check_energy(energy_phot, energy_ele, energy_pos): - # Sorting the arrays is required because electrons and positrons are not - # necessarily dumped in the same order. - s_energy_ele = np.sort(energy_ele) - is_energy_pos = np.sort(energy_pos)[::-1] - product_energy = s_energy_ele + is_energy_pos - assert(small_diff(product_energy, energy_phot)) - print(" [OK] energy is conserved in each event") - -def check_opt_depths(phot_data, ele_data, pos_data): - data = (phot_data, ele_data, pos_data) - for dd in data: - # Remove the negative optical depths that correspond to photons that will decay into pairs - # at the beginning of the next timestep - loc, scale = st.expon.fit(dd["opt"][dd["opt"] > 0]) - assert( np.abs(loc - 0) < tol_red ) - assert( np.abs(scale - 1) < tol_red ) - print(" [OK] optical depth distributions are still exponential") - -def check_energy_distrib(energy_ele, energy_pos, gamma_phot, - chi_phot, n_lost, NN, idx, do_plot=False): - gamma_min = 1.0001 - gamma_max = gamma_phot-1.0001 - h_gamma_ele, c_gamma = np.histogram(energy_ele/mec2, bins=NN, range=[gamma_min,gamma_max]) - h_gamma_pos, _ = np.histogram(energy_pos/mec2, bins=NN, range=[gamma_min,gamma_max]) - - cchi_part_min = chi_phot*(gamma_min - 1)/(gamma_phot - 2) - cchi_part_max = chi_phot*(gamma_max - 1)/(gamma_phot - 2) - - #Rudimentary integration over npoints for each bin - npoints= 20 - aux_chi = np.linspace(cchi_part_min, cchi_part_max, NN*npoints) - distrib = BW_d2N_dt_dchi(chi_phot, gamma_phot, aux_chi) - distrib = np.sum(distrib.reshape(-1, npoints),1) - distrib = n_lost*distrib/np.sum(distrib) - - if do_plot : - # Visual comparison of distributions - c_gamma_centered = 0.5*(c_gamma[1:]+c_gamma[:-1]) - plt.clf() - plt.xlabel("γ_particle") - plt.ylabel("N") - plt.title("χ_photon = {:f}".format(chi_phot)) - plt.plot(c_gamma_centered, distrib,label="theory") - plt.plot(c_gamma_centered, h_gamma_ele,label="BW electrons") - plt.plot(c_gamma_centered, h_gamma_pos,label="BW positrons") - plt.legend() - plt.savefig("case_{:d}".format(idx+1)) - - discr_ele = np.abs(h_gamma_ele-distrib) - discr_pos = np.abs(h_gamma_pos-distrib) - max_discr = 5.0 * np.sqrt(distrib) - assert(np.all(discr_ele < max_discr)) - assert(np.all(discr_pos < max_discr)) - print(" [OK] energy distribution is within expectations") - -#__________________ - -def check(dt, particle_data): - - for idx in range(4): - phot_name = spec_names_phot[idx] - ele_name = spec_names_ele[idx] - pos_name = spec_names_pos[idx] - p0 = initial_momenta[idx] - - p2_phot = p0[0]**2 + p0[1]**2 + p0[2]**2 - p_phot = np.sqrt(p2_phot) - energy_phot = p_phot*c - chi_phot = calc_chi_gamma(p0, E_f, B_f) - gamma_phot = np.linalg.norm(p0)/mec - - print("** Case {:d} **".format(idx+1)) - print(" initial momentum: ", p0) - print(" quantum parameter: {:f}".format(chi_phot)) - print(" normalized photon energy: {:f}".format(gamma_phot)) - print(" timestep: {:f} fs".format(dt*1e15)) - - phot_data = particle_data[phot_name] - ele_data = particle_data[ele_name] - pos_data = particle_data[pos_name] - - p2_ele = ele_data["px"]**2 + ele_data["py"]**2 + ele_data["pz"]**2 - p_ele = np.sqrt(p2_ele) - energy_ele = np.sqrt(1.0 + p2_ele/mec**2 )*mec2 - p2_pos = pos_data["px"]**2 + pos_data["py"]**2 + pos_data["pz"]**2 - p_pos = np.sqrt(p2_pos) - energy_pos = np.sqrt(1.0 + p2_pos/mec**2 )*mec2 - - n_lost = check_number_of_pairs(particle_data, - phot_name, ele_name, pos_name, - chi_phot, gamma_phot, dt, - initial_particle_number) - - check_weights(phot_data, ele_data, pos_data) - - check_momenta(phot_data, ele_data, pos_data, p0, p_ele, p_pos) - - check_energy(energy_phot, energy_ele, energy_pos) - - check_energy_distrib(energy_ele, energy_pos, gamma_phot, chi_phot, n_lost, NNS[idx], idx) - - check_opt_depths(phot_data, ele_data, pos_data) - - print("*************\n") diff --git a/Examples/Tests/qed/breit_wheeler/inputs_2d b/Examples/Tests/qed/inputs_base_2d_breit_wheeler similarity index 99% rename from Examples/Tests/qed/breit_wheeler/inputs_2d rename to Examples/Tests/qed/inputs_base_2d_breit_wheeler index 857b3243ac6..201520966c2 100644 --- a/Examples/Tests/qed/breit_wheeler/inputs_2d +++ b/Examples/Tests/qed/inputs_base_2d_breit_wheeler @@ -28,6 +28,7 @@ warpx.do_dive_cleaning = 0 warpx.use_filter = 1 warpx.cfl = 1. # if 1., the time step is set to its CFL limit warpx.serialize_initial_conditions = 1 +warpx.abort_on_warning_threshold = high # Order of particle shape factors algo.particle_shape = 3 diff --git a/Examples/Tests/qed/breit_wheeler/inputs_3d b/Examples/Tests/qed/inputs_base_3d_breit_wheeler similarity index 100% rename from Examples/Tests/qed/breit_wheeler/inputs_3d rename to Examples/Tests/qed/inputs_base_3d_breit_wheeler diff --git a/Examples/Tests/qed/schwinger/inputs_3d_schwinger b/Examples/Tests/qed/inputs_base_3d_schwinger similarity index 100% rename from Examples/Tests/qed/schwinger/inputs_3d_schwinger rename to Examples/Tests/qed/inputs_base_3d_schwinger diff --git a/Examples/Tests/qed/inputs_test_2d_qed_breit_wheeler b/Examples/Tests/qed/inputs_test_2d_qed_breit_wheeler new file mode 100644 index 00000000000..53d3cf9e97c --- /dev/null +++ b/Examples/Tests/qed/inputs_test_2d_qed_breit_wheeler @@ -0,0 +1,2 @@ +# base input parameters +FILE = inputs_base_2d_breit_wheeler diff --git a/Examples/Tests/qed/inputs_test_2d_qed_breit_wheeler_opmd b/Examples/Tests/qed/inputs_test_2d_qed_breit_wheeler_opmd new file mode 100644 index 00000000000..7edecbcd0a3 --- /dev/null +++ b/Examples/Tests/qed/inputs_test_2d_qed_breit_wheeler_opmd @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_2d_breit_wheeler + +# test input parameters +diag1.format = openpmd +diag1.openpmd_backend = h5 diff --git a/Examples/Tests/qed/quantum_synchrotron/inputs_2d b/Examples/Tests/qed/inputs_test_2d_qed_quantum_sync similarity index 99% rename from Examples/Tests/qed/quantum_synchrotron/inputs_2d rename to Examples/Tests/qed/inputs_test_2d_qed_quantum_sync index 2ac2c782ccd..83d0cee16aa 100644 --- a/Examples/Tests/qed/quantum_synchrotron/inputs_2d +++ b/Examples/Tests/qed/inputs_test_2d_qed_quantum_sync @@ -28,6 +28,7 @@ warpx.do_dive_cleaning = 0 warpx.use_filter = 1 warpx.cfl = 1. # if 1., the time step is set to its CFL limit warpx.serialize_initial_conditions = 1 +warpx.abort_on_warning_threshold = high # Order of particle shape factors algo.particle_shape = 3 diff --git a/Examples/Tests/qed/inputs_test_3d_qed_breit_wheeler b/Examples/Tests/qed/inputs_test_3d_qed_breit_wheeler new file mode 100644 index 00000000000..2058dccb493 --- /dev/null +++ b/Examples/Tests/qed/inputs_test_3d_qed_breit_wheeler @@ -0,0 +1,2 @@ +# base input parameters +FILE = inputs_base_3d_breit_wheeler diff --git a/Examples/Tests/qed/inputs_test_3d_qed_breit_wheeler_opmd b/Examples/Tests/qed/inputs_test_3d_qed_breit_wheeler_opmd new file mode 100644 index 00000000000..78847d0a0d4 --- /dev/null +++ b/Examples/Tests/qed/inputs_test_3d_qed_breit_wheeler_opmd @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_3d_breit_wheeler + +# test input parameters +diag1.format = openpmd +diag1.openpmd_backend = h5 diff --git a/Examples/Tests/qed/quantum_synchrotron/inputs_3d b/Examples/Tests/qed/inputs_test_3d_qed_quantum_sync similarity index 99% rename from Examples/Tests/qed/quantum_synchrotron/inputs_3d rename to Examples/Tests/qed/inputs_test_3d_qed_quantum_sync index 429666ef938..87ffd746ec8 100644 --- a/Examples/Tests/qed/quantum_synchrotron/inputs_3d +++ b/Examples/Tests/qed/inputs_test_3d_qed_quantum_sync @@ -28,6 +28,7 @@ warpx.do_dive_cleaning = 0 warpx.use_filter = 1 warpx.cfl = 1. # if 1., the time step is set to its CFL limit warpx.serialize_initial_conditions = 1 +warpx.abort_on_warning_threshold = high # Order of particle shape factors algo.particle_shape = 3 diff --git a/Examples/Tests/qed/inputs_test_3d_qed_schwinger_1 b/Examples/Tests/qed/inputs_test_3d_qed_schwinger_1 new file mode 100644 index 00000000000..cfa0ca80845 --- /dev/null +++ b/Examples/Tests/qed/inputs_test_3d_qed_schwinger_1 @@ -0,0 +1,6 @@ +# base input parameters +FILE = inputs_base_3d_schwinger + +# test input parameters +warpx.B_external_grid = 16792888.570516706 5256650.141557486 18363530.799561853 +warpx.E_external_grid = 1.e16 0 0 diff --git a/Examples/Tests/qed/inputs_test_3d_qed_schwinger_2 b/Examples/Tests/qed/inputs_test_3d_qed_schwinger_2 new file mode 100644 index 00000000000..420e6bce31f --- /dev/null +++ b/Examples/Tests/qed/inputs_test_3d_qed_schwinger_2 @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_3d_schwinger + +# test input parameters +warpx.B_external_grid = 1679288857.0516706 525665014.1557486 1836353079.9561853 +warpx.E_external_grid = 1.e18 0 0 +qed_schwinger.xmin = -2.5e-7 +qed_schwinger.xmax = 2.49e-7 diff --git a/Examples/Tests/qed/inputs_test_3d_qed_schwinger_3 b/Examples/Tests/qed/inputs_test_3d_qed_schwinger_3 new file mode 100644 index 00000000000..e77ce567f32 --- /dev/null +++ b/Examples/Tests/qed/inputs_test_3d_qed_schwinger_3 @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_3d_schwinger + +# test input parameters +warpx.E_external_grid = 0 1.090934525450495e+17 0 diff --git a/Examples/Tests/qed/inputs_test_3d_qed_schwinger_4 b/Examples/Tests/qed/inputs_test_3d_qed_schwinger_4 new file mode 100644 index 00000000000..78454e8bb75 --- /dev/null +++ b/Examples/Tests/qed/inputs_test_3d_qed_schwinger_4 @@ -0,0 +1,8 @@ +# base input parameters +FILE = inputs_base_3d_schwinger + +# test input parameters +warpx.B_external_grid = 0 833910140000. 0 +warpx.E_external_grid = 0 0 2.5e+20 +qed_schwinger.ymin = -2.5e-7 +qed_schwinger.zmax = 2.49e-7 diff --git a/Examples/Tests/qed/quantum_synchrotron/analysis.py b/Examples/Tests/qed/quantum_synchrotron/analysis.py deleted file mode 100755 index ee6139f75c8..00000000000 --- a/Examples/Tests/qed/quantum_synchrotron/analysis.py +++ /dev/null @@ -1,309 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2019 Luca Fedeli, Maxence Thevenet -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -# -*- coding: utf-8 -*- - -import os -import sys - -import numpy as np -import scipy.integrate as integ -import scipy.special as spe -import scipy.stats as st -import yt - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI -import matplotlib.pyplot as plt - -# This script performs detailed checks of the Quantum Synchrotron photon emission process. -# Two electron populations and two positron populations are initialized with different momenta in different -# directions in a background EM field (with non-zero components along each direction). -# Specifically the script checks that: -# -# - The expected number of generated photons n_phot is in agreement with theory. -# The maximum tolerated error is 5*sqrt(n_phot), except for the last 8 points, -# for which a higher tolerance is used (this is due to the fact that the resolution -# of the builtin table is quite limited). -# - The weight of the generated particles is equal to the weight of the photon -# - The generated particles are emitted in the right direction -# - The energy distribution of the generated particles is in agreement with theory -# - The optical depths of the product species are correctly initialized (QED effects are -# enabled for product species too). -# -# More details on the theoretical formulas used in this script can be found in -# the Jupyter notebook picsar/src/multi_physics/QED_tests/validation/validation.ipynb -# -# References: -# 1) R. Duclous et al 2011 Plasma Phys. Control. Fusion 53 015009 -# 2) A. Gonoskov et al. 2015 Phys. Rev. E 92, 023305 -# 3) M. Lobet. PhD thesis "Effets radiatifs et d'electrodynamique -# quantique dans l'interaction laser-matiere ultra-relativiste" -# URL: https://tel.archives-ouvertes.fr/tel-01314224 - - -# Tolerances -tol = 1.e-8 -tol_red = 1.e-2 - -# Physical constants (from CODATA 2018, see: https://physics.nist.gov/cuu/Constants/index.html ) -me = 9.1093837015e-31 #electron mass -c = 299792458 #speed of light -hbar = 6.62607015e-34/(2*np.pi) #reduced Plank constant -fine_structure = 7.2973525693e-3 #fine structure constant -qe = 1.602176634e-19#elementary charge -E_s = (me**2 * c**3)/(qe * hbar) #Schwinger E field -B_s = E_s/c #Schwinger B field - -mec = me*c -mec2 = mec*c -#______________ - -# Initial parameters -spec_names = ["p1", "p2", "p3", "p4"] -spec_names_phot = ["qsp_1", "qsp_2", "qsp_3", "qsp_4"] -initial_momenta = [ - np.array([10.0,0,0])*mec, - np.array([0.0,100.0,0.0])*mec, - np.array([0.0,0.0,1000.0])*mec, - np.array([5773.502691896, 5773.502691896, 5773.502691896])*mec -] -csign = [-1,-1,1,1] -initial_particle_number = 1048576 - -E_f = np.array([-2433321316961438., 973328526784575., 1459992790176863.]) -B_f = np.array([2857142.85714286, 4285714.28571428, 8571428.57142857]) - -NNS = [64,64,64,64] #bins for energy distribution comparison. -#______________ - -def calc_chi_part(p, E, B): - gamma_part = np.sqrt(1.0 + np.dot(p,p)/mec**2) - v = p/(gamma_part*me) - EpvvecB = E + np.cross(v,B) - vdotEoverc = np.dot(v,E)/c - ff = np.sqrt(np.dot(EpvvecB,EpvvecB) - np.dot(vdotEoverc,vdotEoverc)) - return gamma_part*ff/E_s - -#Auxiliary functions -@np.vectorize -def IC_inner_alternative(y): - ff = lambda x : np.exp(-y*(1+(4*x**2)/3)*np.sqrt(1+x*x/3))*(9+36*x**2 + 16*x**4)/(3 + 4*x**2)/np.sqrt(1+(x**2)/3) - # This integration may not converge in some cases, in which case a python warning message can - # be issued. This is probably not a significant issue for this test case and these warnings can - # be ignored. - return integ.quad(ff, 0, np.inf)[0]/np.sqrt(3) - -def IC_Y(chi_ele, xi): - div = (chi_ele*(1-xi)) - div = np.where(np.logical_and(xi < 1, chi_ele != 0), div, 1.0) - res = (2/3)*np.where(np.logical_and(xi < 1, chi_ele != 0), xi/div, np.inf) - return res - -def IC_S(chi_ele, xi): - Y = IC_Y(chi_ele, xi) - coeff = np.sqrt(3)/2.0/np.pi - first = IC_inner_alternative(Y) - div = np.where(xi == 1, 1.0, 1.0/(1-xi) ) - res = np.where(np.logical_or(xi == 1, xi == 0), 0.0, - coeff*xi*( first + (xi**2 * spe.kv(2./3.,Y)*div ) ) ) - return res - -def IC_SXI(chi_ele, xi): - div = np.where(xi != 0, xi, 1.0) - return np.where(xi != 0, IC_S(chi_ele, xi)/div, np.inf) - -@np.vectorize -def IC_G(chi_ele): - return integ.quad(lambda xi: IC_SXI(chi_ele, xi), 0, 1)[0] - -def small_diff(vv, val): - if(val != 0.0): - return np.max(np.abs((vv - val)/val)) < tol - else: - return np.max(np.abs(vv)) < tol - -def boris(pp, dt, charge_sign): - econst = 0.5*qe*dt*charge_sign/me - u = pp/(me) - u += econst*E_f - inv_gamma = 1/np.sqrt(1 + np.dot(u,u)/c**2) - t = econst*B_f*inv_gamma - s = 2*t/(1 + np.dot(t,t)) - u_p = u + np.cross(u,t) - u += np.cross(u_p, s) - u += econst*E_f - return u *me -#__________________ - -# Quantum Synchrotron total and differential cross sections -def QS_dN_dt(chi_ele, gamma_ele): - coeff_IC = (2./3.) * fine_structure * me*c**2/hbar - return coeff_IC*IC_G(chi_ele)/gamma_ele - -def QS_d2N_dt_dchi(chi, gamma_ele, chi_phot): - coeff_IC = (2./3.) * fine_structure * me*c**2/hbar - return coeff_IC*IC_S(chi, chi_phot/chi)/chi_phot/gamma_ele -#__________________ - -# Get data for a species -def get_spec(ytdata, specname, is_photon): - px = ytdata[specname,"particle_momentum_x"].v - pz = ytdata[specname,"particle_momentum_z"].v - py = ytdata[specname,"particle_momentum_y"].v - - w = ytdata[specname,"particle_weighting"].v - - if (is_photon): - opt = ytdata[specname,"particle_opticalDepthBW"].v - else: - opt = ytdata[specname,"particle_opticalDepthQSR"].v - - return {"px" : px, "py" : py, "pz" : pz, "w" : w, "opt" : opt} - -# Individual tests -def check_number_of_photons(ytdataset, part_name, phot_name, chi_part, gamma_part, dt, particle_number): - dNQS_dt_theo = QS_dN_dt(chi_part, gamma_part) - expected_photons = (1.-np.exp(-dNQS_dt_theo*dt))*particle_number - expected_photons_tolerance = 5.0*np.sqrt(expected_photons) - n_phot = ytdataset.particle_type_counts[phot_name] - assert( np.abs(n_phot-expected_photons) < expected_photons_tolerance) - print(" [OK] generated photons number is within expectations") - return n_phot - -def check_weights(part_data, phot_data): - assert(np.all(part_data["w"] == part_data["w"][0])) - assert(np.all(phot_data["w"] == part_data["w"][0])) - print(" [OK] particles weights are the expected ones") - -def check_momenta(phot_data, p_phot, p0): - pdir = p0/np.linalg.norm(p0) - assert(small_diff(phot_data["px"]/p_phot, pdir[0])) - assert(small_diff(phot_data["py"]/p_phot, pdir[1])) - assert(small_diff(phot_data["pz"]/p_phot, pdir[2])) - print(" [OK] photons move along the initial particle direction") - -def check_opt_depths(part_data, phot_data): - data = (part_data, phot_data) - for dd in data: - # Remove the negative optical depths that will be - # reset at the beginning of the next timestep - loc, scale = st.expon.fit(dd["opt"][dd["opt"] > 0]) - assert( np.abs(loc - 0) < tol_red ) - assert( np.abs(scale - 1) < tol_red ) - print(" [OK] optical depth distributions are still exponential") - -def check_energy_distrib(gamma_phot, chi_part, - gamma_part, n_phot, NN, idx, do_plot=False): - gamma_phot_min = 1e-12*gamma_part - gamma_phot_max = gamma_part - h_log_gamma_phot, c_gamma_phot = np.histogram(gamma_phot, bins=np.logspace(np.log10(gamma_phot_min),np.log10(gamma_phot_max),NN+1)) - - cchi_phot_min = chi_part*(gamma_phot_min)/(gamma_part-1) - cchi_phot_max = chi_part*(gamma_phot_max)/(gamma_part-1) - - #Rudimentary integration over npoints for each bin - npoints= 20 - aux_chi = np.logspace(np.log10(cchi_phot_min),np.log10(cchi_phot_max), NN*npoints) - distrib = QS_d2N_dt_dchi(chi_part, gamma_part, aux_chi)*aux_chi - distrib = np.sum(distrib.reshape(-1, npoints),1) - distrib = n_phot*distrib/np.sum(distrib) - - if do_plot : - # Visual comparison of distributions - c_gamma_phot = np.exp(0.5*(np.log(c_gamma_phot[1:])+np.log(c_gamma_phot[:-1]))) - plt.clf() - - fig, (ax1, ax2) = plt.subplots(1, 2) - fig.suptitle("χ_particle = {:f}".format(chi_part)) - ax1.plot(c_gamma_phot, distrib,label="theory") - ax1.loglog(c_gamma_phot, h_log_gamma_phot,label="QSR photons") - ax1.set_xlim(1e-12*(gamma_part-1),gamma_part-1) - ax1.set_ylim(1,1e5) - ax2.plot(c_gamma_phot, distrib,label="theory") - ax2.semilogy(c_gamma_phot, h_log_gamma_phot,label="QSR photons") - ax2.set_ylim(1,1e5) - ax2.set_xlim(1e-12*(gamma_part-1),gamma_part-1) - ax1.set_xlabel("γ_photon") - ax1.set_xlabel("N") - ax2.set_xlabel("γ_photon") - ax2.set_xlabel("N") - plt.legend() - plt.savefig("case_{:d}".format(idx+1)) - - discr = np.abs(h_log_gamma_phot-distrib) - - max_discr = np.sqrt(distrib)*5.0 - # Use a higer tolerance for the last 8 points (this is due to limitations - # of the builtin table) - max_discr[-8:] *= 2.0 - assert(np.all( discr < max_discr )) - - print(" [OK] energy distribution is within expectations") - -#__________________ - -def check(): - filename_end = sys.argv[1] - data_set_end = yt.load(filename_end) - - sim_time = data_set_end.current_time.to_value() - # no particles can be created on the first timestep so we have 2 timesteps in the test case, - # with only the second one resulting in particle creation - dt = sim_time/2. - - all_data_end = data_set_end.all_data() - - for idx in range(4): - part_name = spec_names[idx] - phot_name = spec_names_phot[idx] - t_pi = initial_momenta[idx] - pm = boris(t_pi,-dt*0.5,csign[idx]) - p0 = boris(pm,dt*1.0,csign[idx]) - - p2_part = p0[0]**2 + p0[1]**2 + p0[2]**2 - energy_part = np.sqrt(mec2**2 + p2_part*c**2) - gamma_part = energy_part/mec2 - chi_part = calc_chi_part(p0, E_f, B_f) - - print("** Case {:d} **".format(idx+1)) - print(" initial momentum: ", t_pi) - print(" quantum parameter: {:f}".format(chi_part)) - print(" normalized particle energy: {:f}".format(gamma_part)) - print(" timestep: {:f} fs".format(dt*1e15)) - - part_data_final = get_spec(all_data_end, part_name, is_photon=False) - phot_data = get_spec(all_data_end, phot_name, is_photon=True) - - p_phot = np.sqrt(phot_data["px"]**2 + phot_data["py"]**2 + phot_data["pz"]**2) - energy_phot = p_phot*c - gamma_phot = energy_phot/mec2 - - n_phot = check_number_of_photons(data_set_end, - part_name, phot_name, - chi_part, gamma_part, dt, - initial_particle_number) - - check_weights(part_data_final, phot_data) - - check_momenta(phot_data, p_phot, p0) - - check_energy_distrib(gamma_phot, chi_part, gamma_part, n_phot, NNS[idx], idx) - - check_opt_depths(part_data_final, phot_data) - - print("*************\n") - - test_name = os.path.split(os.getcwd())[1] - checksumAPI.evaluate_checksum(test_name, filename_end) - -def main(): - check() - -if __name__ == "__main__": - main() diff --git a/Examples/Tests/qed/schwinger/analysis_schwinger.py b/Examples/Tests/qed/schwinger/analysis_schwinger.py deleted file mode 100755 index c93c920216f..00000000000 --- a/Examples/Tests/qed/schwinger/analysis_schwinger.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2020 Luca Fedeli, Neil Zaim -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -## This module is imported by each of the scripts used to analyze the Schwinger tests. - -## The pair production rate is calculated using the formula described in -## Bulanov, S. S., et al. Physical review letters 104.22 (2010): 220404. - -import os -import re -import sys - -import numpy as np -import yt - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -# define some parameters - -c = 299792458. -m_e = 9.1093837015e-31 -e =1.602176634e-19 -hbar = 1.054571817e-34 -E_S = m_e**2*c**3/e/hbar # Schwinger field - -dV = (1.e-6)**3 # total simulation volume -dt = 9.827726403e-17 -filename = sys.argv[1] - -Ex_test = 0. -Ey_test = 0. -Ez_test = 0. -Bx_test = 0. -By_test = 0. -Bz_test = 0. - -# Find which test we are doing -test_number = re.search( 'qed_schwinger([1234])', filename ).group(1) -if test_number == '1': - # First Schwinger test with "weak" EM field. No pair should be created. - Ex_test = 1.e16 - Bx_test = 16792888.570516706 - By_test = 5256650.141557486 - Bz_test = 18363530.799561853 -elif test_number == '2': - # Second Schwinger test with stronger EM field. Many pairs are created and a Gaussian - # distribution is used to get the weights of the particles. This is the most sensitive test - # because the relative std is extremely low. - Ex_test = 1.e18 - Bx_test = 1679288857.0516706 - By_test = 525665014.1557486 - Bz_test = 1836353079.9561853 - dV = dV/2. # Schwinger is only activated in part of the simulation domain -elif test_number == '3': - # Third Schwinger test with intermediate electric field such that average created pair per cell - # is 1. A Poisson distribution is used to obtain the weights of the particles. - Ey_test = 1.090934525450495e+17 -elif test_number == '4': - # Fourth Schwinger test with extremely strong EM field but with E and B perpendicular and nearly - # equal so that the pair production rate is fairly low. A Gaussian distribution is used in this - # case. - Ez_test = 2.5e+20 - By_test = 833910140000. - dV = dV*(3./4.)**2. # Schwinger is only activated in part of the simulation domain -else: - assert(False) - -def calculate_rate(Ex,Ey,Ez,Bx,By,Bz): -## Calculate theoretical pair production rate from EM field value - - E_squared = Ex**2 + Ey**2 + Ez**2 - H_squared = c**2*(Bx**2 + By**2 + Bz**2) - - F = (E_squared - H_squared)/2. - G = c*(Ex*Bx + Ey*By + Ez*Bz) - - epsilon = np.sqrt(np.sqrt(F**2+G**2)+F)/E_S - eta = np.sqrt(np.sqrt(F**2+G**2)-F)/E_S - - if(epsilon != 0. and eta != 0.): - return e**2*E_S**2/4./np.pi**2/c/hbar**2*epsilon*eta/np.tanh(np.pi*eta/epsilon)*np.exp(-np.pi/epsilon) - elif (epsilon == 0.): - return 0. - else: - return e**2*E_S**2/4./np.pi**2/c/hbar**2*epsilon**2/np.pi*np.exp(-np.pi/epsilon) - - -def do_analysis(Ex,Ey,Ez,Bx,By,Bz): - - data_set = yt.load(filename) - - expected_total_physical_pairs_created = dV*dt*calculate_rate(Ex,Ey,Ez,Bx,By,Bz) - if expected_total_physical_pairs_created < 0.01: - np_ele = data_set.particle_type_counts["ele_schwinger"] if \ - "ele_schwinger" in data_set.particle_type_counts.keys() else 0 - np_pos = data_set.particle_type_counts["pos_schwinger"] if \ - "pos_schwinger" in data_set.particle_type_counts.keys() else 0 - assert(np_ele == 0 and np_pos == 0) - ## Assert whether pairs are created or not. - - else: - all_data = data_set.all_data() - - ele_data = all_data["ele_schwinger",'particle_weight'] - pos_data = all_data["pos_schwinger",'particle_weight'] - - std_total_physical_pairs_created = np.sqrt(expected_total_physical_pairs_created) - - # Sorting the arrays is required because electrons and positrons are not necessarily - # dumped in the same order. - assert(np.array_equal(np.sort(ele_data),np.sort(pos_data))) - # 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions - error = np.abs(np.sum(ele_data)-expected_total_physical_pairs_created) - print("difference between expected and actual number of pairs created: " + str(error)) - print("tolerance: " + str(5*std_total_physical_pairs_created)) - assert(error<5*std_total_physical_pairs_created) - -do_analysis(Ex_test, Ey_test, Ez_test, Bx_test, By_test, Bz_test) - -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/radiation_reaction/CMakeLists.txt b/Examples/Tests/radiation_reaction/CMakeLists.txt new file mode 100644 index 00000000000..8696cf0f9b7 --- /dev/null +++ b/Examples/Tests/radiation_reaction/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_radiation_reaction # name + 3 # dims + 2 # nprocs + inputs_test_3d_radiation_reaction # inputs + analysis.py # analysis + diags/diag1000064 # output + OFF # dependency +) diff --git a/Examples/Tests/radiation_reaction/test_const_B_analytical/analysis_classicalRR.py b/Examples/Tests/radiation_reaction/analysis.py similarity index 64% rename from Examples/Tests/radiation_reaction/test_const_B_analytical/analysis_classicalRR.py rename to Examples/Tests/radiation_reaction/analysis.py index e123562fbe1..e24129d3e38 100755 --- a/Examples/Tests/radiation_reaction/test_const_B_analytical/analysis_classicalRR.py +++ b/Examples/Tests/radiation_reaction/analysis.py @@ -36,68 +36,70 @@ import numpy as np import yt -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI -#Input filename +# Input filename inputname = "inputs" -#________________________________________ +# ________________________________________ -#Physical constants -c = 299792458. +# Physical constants +c = 299792458.0 m_e = 9.1093837015e-31 q_0 = 1.602176634e-19 classical_electron_radius = 2.81794e-15 reference_length = 1.0e-6 very_small_dot_product = 1.0e-4 very_small_weight = 1.0e-8 -#________________________________________ +# ________________________________________ -#Sim box data +# Sim box data sim_size = 0.8e-6 resolution = 64 steps = 64 -init_pos = np.array([0.,0.,0.]) -#________________________________________ - -#Momentum vals -p_aux_0 = np.array([2.,3.,6.]) -p_aux_1 = np.array([1,0,0]) -p_aux_2 = np.array([0,1,0]) -Q, _ = np.linalg.qr(np.column_stack( [p_aux_0, p_aux_1, p_aux_2] )) #Gram-Schmidt -p_0 = -Q[:,0] -p_1 = -Q[:,1] -p_2 = -Q[:,2] - -p_vals = [50,200,1000] -#________________________________________ - -#Field val +init_pos = np.array([0.0, 0.0, 0.0]) +# ________________________________________ + +# Momentum vals +p_aux_0 = np.array([2.0, 3.0, 6.0]) +p_aux_1 = np.array([1, 0, 0]) +p_aux_2 = np.array([0, 1, 0]) +Q, _ = np.linalg.qr(np.column_stack([p_aux_0, p_aux_1, p_aux_2])) # Gram-Schmidt +p_0 = -Q[:, 0] +p_1 = -Q[:, 1] +p_2 = -Q[:, 2] + +p_vals = [50, 200, 1000] +# ________________________________________ + +# Field val B_val_norm = 300 -B_val = B_val_norm*m_e * 2.0 * np.pi * c /q_0/reference_length +B_val = B_val_norm * m_e * 2.0 * np.pi * c / q_0 / reference_length B = p_0 * B_val -#________________________________________ +# ________________________________________ -#Tolerance +# Tolerance tolerance_rel = 0.05 -#________________________________________ +# ________________________________________ -#tau_c -omega_c = q_0*B_val/m_e -t0 = (2./3.)*classical_electron_radius/c -tau_c = 1.0/omega_c/omega_c/t0 -#________________________________________ +# tau_c +omega_c = q_0 * B_val / m_e +t0 = (2.0 / 3.0) * classical_electron_radius / c +tau_c = 1.0 / omega_c / omega_c / t0 +# ________________________________________ -#Simulation case struct +# Simulation case struct class sim_case: def __init__(self, _name, _init_mom, _type): self.name = _name self.init_mom = _init_mom self.type = _type -#________________________________________ -#All cases + +# ________________________________________ + +# All cases cases = [ sim_case("ele_para0", p_0 * p_vals[2], "-q_e"), sim_case("ele_perp0", p_1 * p_vals[0], "-q_e"), @@ -105,21 +107,25 @@ def __init__(self, _name, _init_mom, _type): sim_case("ele_perp2", p_1 * p_vals[2], "-q_e"), sim_case("pos_perp2", p_1 * p_vals[2], "q_e"), ] -#________________________________________ +# ________________________________________ + + +# Auxiliary functions +def gamma(p): + return np.sqrt(1.0 + np.dot(p, p)) -#Auxiliary functions -def gamma(p) : - return np.sqrt(1.0 + np.dot(p,p)) def exp_res(cc, time): if np.all(np.linalg.norm(np.cross(cc.init_mom, B)) < very_small_dot_product): return gamma(cc.init_mom) - else : - tt = time/tau_c + else: + tt = time / tau_c g0 = gamma(cc.init_mom) - C = -0.5 * np.log((g0+1)/(g0-1)) - return 1.0/np.tanh(tt - C) -#________________________________________ + C = -0.5 * np.log((g0 + 1) / (g0 - 1)) + return 1.0 / np.tanh(tt - C) + + +# ________________________________________ def check(): @@ -128,35 +134,41 @@ def check(): sim_time = data_set_end.current_time.to_value() - #simulation results - all_data = data_set_end.all_data() + # simulation results + all_data = data_set_end.all_data() spec_names = [cc.name for cc in cases] - #All momenta - res_mom = np.array([np.array([ - all_data[sp, 'particle_momentum_x'].v[0], - all_data[sp, 'particle_momentum_y'].v[0], - all_data[sp, 'particle_momentum_z'].v[0]]) - for sp in spec_names]) + # All momenta + res_mom = np.array( + [ + np.array( + [ + all_data[sp, "particle_momentum_x"].v[0], + all_data[sp, "particle_momentum_y"].v[0], + all_data[sp, "particle_momentum_z"].v[0], + ] + ) + for sp in spec_names + ] + ) for cc in zip(cases, res_mom): - init_gamma = gamma(cc[0].init_mom) - end_gamma = gamma(cc[1]/m_e/c) + end_gamma = gamma(cc[1] / m_e / c) exp_gamma = exp_res(cc[0], sim_time) - error_rel = np.abs(end_gamma-exp_gamma)/exp_gamma + error_rel = np.abs(end_gamma - exp_gamma) / exp_gamma print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) - assert( error_rel < tolerance_rel ) + assert error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) -def generate(): - with open(inputname,'w') as f: +def generate(): + with open(inputname, "w") as f: f.write("#Automatically generated inputfile\n") f.write("#Run check.py without arguments to regenerate\n") f.write("#\n\n") @@ -188,21 +200,31 @@ def generate(): f.write("{}.charge = {}\n".format(cc.name, cc.type)) f.write("{}.mass = m_e\n".format(cc.name)) f.write('{}.injection_style = "SingleParticle"\n'.format(cc.name)) - f.write("{}.single_particle_pos = {} {} {}\n". - format(cc.name, init_pos[0], init_pos[1], init_pos[2])) - f.write("{}.single_particle_u = {} {} {}\n". - format(cc.name, cc.init_mom[0], cc.init_mom[1], cc.init_mom[2])) - f.write("{}.single_particle_weight = {}\n".format(cc.name, very_small_weight)) + f.write( + "{}.single_particle_pos = {} {} {}\n".format( + cc.name, init_pos[0], init_pos[1], init_pos[2] + ) + ) + f.write( + "{}.single_particle_u = {} {} {}\n".format( + cc.name, cc.init_mom[0], cc.init_mom[1], cc.init_mom[2] + ) + ) + f.write( + "{}.single_particle_weight = {}\n".format(cc.name, very_small_weight) + ) f.write("{}.do_classical_radiation_reaction = 1\n".format(cc.name)) f.write("\n") f.write("warpx.B_external_particle = {} {} {}\n".format(*B)) + def main(): - if (len(sys.argv) < 2): + if len(sys.argv) < 2: generate() else: check() + if __name__ == "__main__": main() diff --git a/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs_3d b/Examples/Tests/radiation_reaction/inputs_test_3d_radiation_reaction similarity index 100% rename from Examples/Tests/radiation_reaction/test_const_B_analytical/inputs_3d rename to Examples/Tests/radiation_reaction/inputs_test_3d_radiation_reaction diff --git a/Examples/Tests/reduced_diags/CMakeLists.txt b/Examples/Tests/reduced_diags/CMakeLists.txt new file mode 100644 index 00000000000..cd4f6392892 --- /dev/null +++ b/Examples/Tests/reduced_diags/CMakeLists.txt @@ -0,0 +1,54 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_reduced_diags # name + 3 # dims + 2 # nprocs + inputs_test_3d_reduced_diags # inputs + analysis_reduced_diags.py # analysis + diags/diag1000200 # output + OFF # dependency +) + +add_warpx_test( + test_3d_reduced_diags_load_balance_costs_heuristic # name + 3 # dims + 2 # nprocs + inputs_test_3d_reduced_diags_load_balance_costs_heuristic # inputs + analysis_reduced_diags_load_balance_costs.py # analysis + diags/diag1000003 # output + OFF # dependency +) + +add_warpx_test( + test_3d_reduced_diags_load_balance_costs_timers # name + 3 # dims + 2 # nprocs + inputs_test_3d_reduced_diags_load_balance_costs_timers # inputs + analysis_reduced_diags_load_balance_costs.py # analysis + diags/diag1000003 # output + OFF # dependency +) + +add_warpx_test( + test_3d_reduced_diags_load_balance_costs_timers_picmi # name + 3 # dims + 2 # nprocs + inputs_test_3d_reduced_diags_load_balance_costs_timers_picmi.py # inputs + analysis_reduced_diags_load_balance_costs.py # analysis + diags/diag1000003 # output + OFF # dependency +) + +if(WarpX_FFT) + add_warpx_test( + test_3d_reduced_diags_load_balance_costs_timers_psatd # name + 3 # dims + 2 # nprocs + inputs_test_3d_reduced_diags_load_balance_costs_timers_psatd # inputs + analysis_reduced_diags_load_balance_costs.py # analysis + diags/diag1000003 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/reduced_diags/PICMI_inputs_loadbalancecosts.py b/Examples/Tests/reduced_diags/PICMI_inputs_loadbalancecosts.py deleted file mode 100644 index 0583a6fe1d0..00000000000 --- a/Examples/Tests/reduced_diags/PICMI_inputs_loadbalancecosts.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python3 - -from pywarpx import picmi - -# Number of time steps -max_steps = 3 - -# Number of cells -nx = 128 -ny = 32 -nz = 128 - -# Physical domain -xmin = 0. -xmax = 4. -ymin = 0. -ymax = 4. -zmin = 0. -zmax = 4. - -# Create grid -grid = picmi.Cartesian3DGrid( - number_of_cells=[nx, ny, nz], - warpx_max_grid_size=32, - lower_bound=[xmin, ymin, zmin], - upper_bound=[xmax, ymax, zmax], - lower_boundary_conditions=['periodic', 'periodic', 'periodic'], - upper_boundary_conditions=['periodic', 'periodic', 'periodic'] -) - -# Electromagnetic solver -solver = picmi.ElectromagneticSolver( - grid=grid, - method='Yee', - cfl=0.99999 -) - -# Particles -electrons = picmi.Species( - particle_type='electron', - name='electrons', - initial_distribution=picmi.UniformDistribution( - density=1e14, - rms_velocity=[0]*3, - upper_bound=[xmax, ymax, 1.0] - ) -) -layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[1, 1, 1], grid=grid -) - -# Reduced diagnostic -reduced_diags = [] -reduced_diags.append(picmi.ReducedDiagnostic( - diag_type='LoadBalanceCosts', - period=1, - name='LBC' -)) - -reduced_diags.append(picmi.ReducedDiagnostic( - diag_type='FieldReduction', - period=1, - name='FR', - reduction_type='Maximum', - reduced_function = 'Ez' -)) - -reduced_diags.append(picmi.ReducedDiagnostic( - diag_type='ParticleHistogram', - period=1, - name='PH', - species = electrons, - bin_number = 10, - bin_min=0., - bin_max = xmax, - normalization = 'unity_particle_weight', - histogram_function = 'x' -)) - -# Diagnostic -particle_diag = picmi.ParticleDiagnostic( - name='diag1', - period=3, - species=[electrons], - data_list = ['ux', 'uy', 'uz', 'x', 'y', 'z', 'weighting'], - write_dir='.', - warpx_file_prefix='Python_reduced_diags_loadbalancecosts_timers_plt' -) -field_diag = picmi.FieldDiagnostic( - name='diag1', - grid=grid, - period=3, - data_list = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], - write_dir='.', - warpx_file_prefix='Python_reduced_diags_loadbalancecosts_timers_plt' -) - -# Set up simulation -sim = picmi.Simulation( - solver=solver, - max_steps=max_steps, - verbose=1, - particle_shape=1, - warpx_current_deposition_algo='esirkepov', - warpx_field_gathering_algo='energy-conserving', - warpx_load_balance_intervals=2 -) - -# Add species -sim.add_species(electrons, layout=layout) - -# Add reduced diagnostics -for reduced_diag in reduced_diags: - sim.add_diagnostic(reduced_diag) - -# Add diagnostics -sim.add_diagnostic(particle_diag) -sim.add_diagnostic(field_diag) - -# Advance simulation until last time step -# sim.write_input_file("test_input") -sim.step(max_steps) diff --git a/Examples/Tests/reduced_diags/analysis_reduced_diags.py b/Examples/Tests/reduced_diags/analysis_reduced_diags.py index 1885800376b..2972324e2ac 100755 --- a/Examples/Tests/reduced_diags/analysis_reduced_diags.py +++ b/Examples/Tests/reduced_diags/analysis_reduced_diags.py @@ -13,4 +13,4 @@ import analysis_reduced_diags_impl as an -an.do_analysis(single_precision = False) +an.do_analysis(single_precision=False) diff --git a/Examples/Tests/reduced_diags/analysis_reduced_diags_impl.py b/Examples/Tests/reduced_diags/analysis_reduced_diags_impl.py index 21359ed8171..64b726e5954 100755 --- a/Examples/Tests/reduced_diags/analysis_reduced_diags_impl.py +++ b/Examples/Tests/reduced_diags/analysis_reduced_diags_impl.py @@ -16,283 +16,348 @@ import numpy as np import yt -from scipy.constants import c +from scipy.constants import c, m_e, m_p from scipy.constants import epsilon_0 as eps0 -from scipy.constants import m_e, m_p from scipy.constants import mu_0 as mu0 -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # gamma threshold to switch between the relativistic expression of # the kinetic energy and its Taylor expansion. gamma_relativistic_threshold = 1.005 -def do_analysis(single_precision = False): + +def do_analysis(single_precision=False): fn = sys.argv[1] ds = yt.load(fn) ad = ds.all_data() - #-------------------------------------------------------------------------------------------------- + # -------------------------------------------------------------------------------------------------- # Part 1: get results from plotfiles (label '_yt') - #-------------------------------------------------------------------------------------------------- + # -------------------------------------------------------------------------------------------------- # Quantities computed from plotfiles values_yt = dict() # Electrons - px = ad['electrons', 'particle_momentum_x'].to_ndarray() - py = ad['electrons', 'particle_momentum_y'].to_ndarray() - pz = ad['electrons', 'particle_momentum_z'].to_ndarray() - w = ad['electrons', 'particle_weight'].to_ndarray() + px = ad["electrons", "particle_momentum_x"].to_ndarray() + py = ad["electrons", "particle_momentum_y"].to_ndarray() + pz = ad["electrons", "particle_momentum_z"].to_ndarray() + w = ad["electrons", "particle_weight"].to_ndarray() p2 = px**2 + py**2 + pz**2 # Accumulate particle energy, store number of particles and sum of weights - e_u2 = p2/(m_e**2 * c**2) + e_u2 = p2 / (m_e**2 * c**2) e_gamma = np.sqrt(1 + e_u2) - e_energy = (m_e * c**2)*np.where(e_gamma > gamma_relativistic_threshold, - e_gamma-1, - (e_u2)/2 - (e_u2**2)/8 + (e_u2**3)/16 - (e_u2**4)*(5/128) + (e_u2**5)*(7/256)) - values_yt['electrons: particle energy'] = np.sum(e_energy * w) - values_yt['electrons: particle momentum in x'] = np.sum(px * w) - values_yt['electrons: particle momentum in y'] = np.sum(py * w) - values_yt['electrons: particle momentum in z'] = np.sum(pz * w) - values_yt['electrons: number of particles'] = w.shape[0] - values_yt['electrons: sum of weights'] = np.sum(w) + e_energy = (m_e * c**2) * np.where( + e_gamma > gamma_relativistic_threshold, + e_gamma - 1, + (e_u2) / 2 + - (e_u2**2) / 8 + + (e_u2**3) / 16 + - (e_u2**4) * (5 / 128) + + (e_u2**5) * (7 / 256), + ) + values_yt["electrons: particle energy"] = np.sum(e_energy * w) + values_yt["electrons: particle momentum in x"] = np.sum(px * w) + values_yt["electrons: particle momentum in y"] = np.sum(py * w) + values_yt["electrons: particle momentum in z"] = np.sum(pz * w) + values_yt["electrons: number of particles"] = w.shape[0] + values_yt["electrons: sum of weights"] = np.sum(w) # Protons - px = ad['protons', 'particle_momentum_x'].to_ndarray() - py = ad['protons', 'particle_momentum_y'].to_ndarray() - pz = ad['protons', 'particle_momentum_z'].to_ndarray() - w = ad['protons', 'particle_weight'].to_ndarray() + px = ad["protons", "particle_momentum_x"].to_ndarray() + py = ad["protons", "particle_momentum_y"].to_ndarray() + pz = ad["protons", "particle_momentum_z"].to_ndarray() + w = ad["protons", "particle_weight"].to_ndarray() p2 = px**2 + py**2 + pz**2 # Accumulate particle energy, store number of particles and sum of weights - p_u2 = p2/(m_p**2 * c**2) + p_u2 = p2 / (m_p**2 * c**2) p_gamma = np.sqrt(1 + p_u2) - p_energy = (m_p * c**2)*np.where(p_gamma > gamma_relativistic_threshold, - p_gamma-1, - (p_u2)/2 - (p_u2**2)/8 + (p_u2**3)/16 - (p_u2**4)*(5/128) + (p_u2**5)*(7/256)) - values_yt['protons: particle energy'] = np.sum(p_energy * w) - values_yt['protons: particle momentum in x'] = np.sum(px * w) - values_yt['protons: particle momentum in y'] = np.sum(py * w) - values_yt['protons: particle momentum in z'] = np.sum(pz * w) - values_yt['protons: number of particles'] = w.shape[0] - values_yt['protons: sum of weights'] = np.sum(w) + p_energy = (m_p * c**2) * np.where( + p_gamma > gamma_relativistic_threshold, + p_gamma - 1, + (p_u2) / 2 + - (p_u2**2) / 8 + + (p_u2**3) / 16 + - (p_u2**4) * (5 / 128) + + (p_u2**5) * (7 / 256), + ) + values_yt["protons: particle energy"] = np.sum(p_energy * w) + values_yt["protons: particle momentum in x"] = np.sum(px * w) + values_yt["protons: particle momentum in y"] = np.sum(py * w) + values_yt["protons: particle momentum in z"] = np.sum(pz * w) + values_yt["protons: number of particles"] = w.shape[0] + values_yt["protons: sum of weights"] = np.sum(w) # Photons - px = ad['photons', 'particle_momentum_x'].to_ndarray() - py = ad['photons', 'particle_momentum_y'].to_ndarray() - pz = ad['photons', 'particle_momentum_z'].to_ndarray() - w = ad['photons', 'particle_weight'].to_ndarray() + px = ad["photons", "particle_momentum_x"].to_ndarray() + py = ad["photons", "particle_momentum_y"].to_ndarray() + pz = ad["photons", "particle_momentum_z"].to_ndarray() + w = ad["photons", "particle_weight"].to_ndarray() p2 = px**2 + py**2 + pz**2 # Accumulate particle energy, store number of particles and sum of weights - values_yt['photons: particle energy'] = np.sum(np.sqrt(p2 * c**2) * w) - values_yt['photons: particle momentum in x'] = np.sum(px * w) - values_yt['photons: particle momentum in y'] = np.sum(py * w) - values_yt['photons: particle momentum in z'] = np.sum(pz * w) - values_yt['photons: number of particles'] = w.shape[0] - values_yt['photons: sum of weights'] = np.sum(w) + values_yt["photons: particle energy"] = np.sum(np.sqrt(p2 * c**2) * w) + values_yt["photons: particle momentum in x"] = np.sum(px * w) + values_yt["photons: particle momentum in y"] = np.sum(py * w) + values_yt["photons: particle momentum in z"] = np.sum(pz * w) + values_yt["photons: number of particles"] = w.shape[0] + values_yt["photons: sum of weights"] = np.sum(w) # Accumulate total particle diagnostics - values_yt['particle energy'] = values_yt['electrons: particle energy'] \ - + values_yt['protons: particle energy'] \ - + values_yt['photons: particle energy'] - - values_yt['particle momentum in x'] = values_yt['electrons: particle momentum in x'] \ - + values_yt['protons: particle momentum in x'] \ - + values_yt['photons: particle momentum in x'] - - values_yt['particle momentum in y'] = values_yt['electrons: particle momentum in y'] \ - + values_yt['protons: particle momentum in y'] \ - + values_yt['photons: particle momentum in y'] - - values_yt['particle momentum in z'] = values_yt['electrons: particle momentum in z'] \ - + values_yt['protons: particle momentum in z'] \ - + values_yt['photons: particle momentum in z'] - - values_yt['number of particles'] = values_yt['electrons: number of particles'] \ - + values_yt['protons: number of particles'] \ - + values_yt['photons: number of particles'] - - values_yt['sum of weights'] = values_yt['electrons: sum of weights'] \ - + values_yt['protons: sum of weights'] \ - + values_yt['photons: sum of weights'] - - values_yt['mean particle energy'] = values_yt['particle energy'] / values_yt['sum of weights'] - - values_yt['mean particle momentum in x'] = values_yt['particle momentum in x'] / values_yt['sum of weights'] - values_yt['mean particle momentum in y'] = values_yt['particle momentum in y'] / values_yt['sum of weights'] - values_yt['mean particle momentum in z'] = values_yt['particle momentum in z'] / values_yt['sum of weights'] - - values_yt['electrons: mean particle energy'] = values_yt['electrons: particle energy'] \ - / values_yt['electrons: sum of weights'] - - values_yt['electrons: mean particle momentum in x'] = values_yt['electrons: particle momentum in x'] \ - / values_yt['electrons: sum of weights'] - values_yt['electrons: mean particle momentum in y'] = values_yt['electrons: particle momentum in y'] \ - / values_yt['electrons: sum of weights'] - values_yt['electrons: mean particle momentum in z'] = values_yt['electrons: particle momentum in z'] \ - / values_yt['electrons: sum of weights'] - - values_yt['protons: mean particle energy'] = values_yt['protons: particle energy'] \ - / values_yt['protons: sum of weights'] - - values_yt['protons: mean particle momentum in x'] = values_yt['protons: particle momentum in x'] \ - / values_yt['protons: sum of weights'] - values_yt['protons: mean particle momentum in y'] = values_yt['protons: particle momentum in y'] \ - / values_yt['protons: sum of weights'] - values_yt['protons: mean particle momentum in z'] = values_yt['protons: particle momentum in z'] \ - / values_yt['protons: sum of weights'] - - values_yt['photons: mean particle energy'] = values_yt['photons: particle energy'] \ - / values_yt['photons: sum of weights'] - - values_yt['photons: mean particle momentum in x'] = values_yt['photons: particle momentum in x'] \ - / values_yt['photons: sum of weights'] - values_yt['photons: mean particle momentum in y'] = values_yt['photons: particle momentum in y'] \ - / values_yt['photons: sum of weights'] - values_yt['photons: mean particle momentum in z'] = values_yt['photons: particle momentum in z'] \ - / values_yt['photons: sum of weights'] + values_yt["particle energy"] = ( + values_yt["electrons: particle energy"] + + values_yt["protons: particle energy"] + + values_yt["photons: particle energy"] + ) + + values_yt["particle momentum in x"] = ( + values_yt["electrons: particle momentum in x"] + + values_yt["protons: particle momentum in x"] + + values_yt["photons: particle momentum in x"] + ) + + values_yt["particle momentum in y"] = ( + values_yt["electrons: particle momentum in y"] + + values_yt["protons: particle momentum in y"] + + values_yt["photons: particle momentum in y"] + ) + + values_yt["particle momentum in z"] = ( + values_yt["electrons: particle momentum in z"] + + values_yt["protons: particle momentum in z"] + + values_yt["photons: particle momentum in z"] + ) + + values_yt["number of particles"] = ( + values_yt["electrons: number of particles"] + + values_yt["protons: number of particles"] + + values_yt["photons: number of particles"] + ) + + values_yt["sum of weights"] = ( + values_yt["electrons: sum of weights"] + + values_yt["protons: sum of weights"] + + values_yt["photons: sum of weights"] + ) + + values_yt["mean particle energy"] = ( + values_yt["particle energy"] / values_yt["sum of weights"] + ) + + values_yt["mean particle momentum in x"] = ( + values_yt["particle momentum in x"] / values_yt["sum of weights"] + ) + values_yt["mean particle momentum in y"] = ( + values_yt["particle momentum in y"] / values_yt["sum of weights"] + ) + values_yt["mean particle momentum in z"] = ( + values_yt["particle momentum in z"] / values_yt["sum of weights"] + ) + + values_yt["electrons: mean particle energy"] = ( + values_yt["electrons: particle energy"] / values_yt["electrons: sum of weights"] + ) + + values_yt["electrons: mean particle momentum in x"] = ( + values_yt["electrons: particle momentum in x"] + / values_yt["electrons: sum of weights"] + ) + values_yt["electrons: mean particle momentum in y"] = ( + values_yt["electrons: particle momentum in y"] + / values_yt["electrons: sum of weights"] + ) + values_yt["electrons: mean particle momentum in z"] = ( + values_yt["electrons: particle momentum in z"] + / values_yt["electrons: sum of weights"] + ) + + values_yt["protons: mean particle energy"] = ( + values_yt["protons: particle energy"] / values_yt["protons: sum of weights"] + ) + + values_yt["protons: mean particle momentum in x"] = ( + values_yt["protons: particle momentum in x"] + / values_yt["protons: sum of weights"] + ) + values_yt["protons: mean particle momentum in y"] = ( + values_yt["protons: particle momentum in y"] + / values_yt["protons: sum of weights"] + ) + values_yt["protons: mean particle momentum in z"] = ( + values_yt["protons: particle momentum in z"] + / values_yt["protons: sum of weights"] + ) + + values_yt["photons: mean particle energy"] = ( + values_yt["photons: particle energy"] / values_yt["photons: sum of weights"] + ) + + values_yt["photons: mean particle momentum in x"] = ( + values_yt["photons: particle momentum in x"] + / values_yt["photons: sum of weights"] + ) + values_yt["photons: mean particle momentum in y"] = ( + values_yt["photons: particle momentum in y"] + / values_yt["photons: sum of weights"] + ) + values_yt["photons: mean particle momentum in z"] = ( + values_yt["photons: particle momentum in z"] + / values_yt["photons: sum of weights"] + ) # Load 3D data from plotfiles - ad = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) - Ex = ad[('mesh','Ex')].to_ndarray() - Ey = ad[('mesh','Ey')].to_ndarray() - Ez = ad[('mesh','Ez')].to_ndarray() - Bx = ad[('mesh','Bx')].to_ndarray() - By = ad[('mesh','By')].to_ndarray() - Bz = ad[('mesh','Bz')].to_ndarray() - jx = ad[('mesh','jx')].to_ndarray() - jy = ad[('mesh','jy')].to_ndarray() - jz = ad[('mesh','jz')].to_ndarray() - rho = ad[('boxlib','rho')].to_ndarray() - rho_electrons = ad[('boxlib','rho_electrons')].to_ndarray() - rho_protons = ad[('boxlib','rho_protons')].to_ndarray() - x = ad[('boxlib','x')].to_ndarray() - y = ad[('boxlib','y')].to_ndarray() - z = ad[('boxlib','z')].to_ndarray() + ad = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions + ) + Ex = ad[("mesh", "Ex")].to_ndarray() + Ey = ad[("mesh", "Ey")].to_ndarray() + Ez = ad[("mesh", "Ez")].to_ndarray() + Bx = ad[("mesh", "Bx")].to_ndarray() + By = ad[("mesh", "By")].to_ndarray() + Bz = ad[("mesh", "Bz")].to_ndarray() + jx = ad[("mesh", "jx")].to_ndarray() + jy = ad[("mesh", "jy")].to_ndarray() + jz = ad[("mesh", "jz")].to_ndarray() + rho = ad[("boxlib", "rho")].to_ndarray() + rho_electrons = ad[("boxlib", "rho_electrons")].to_ndarray() + rho_protons = ad[("boxlib", "rho_protons")].to_ndarray() + x = ad[("boxlib", "x")].to_ndarray() + y = ad[("boxlib", "y")].to_ndarray() + z = ad[("boxlib", "z")].to_ndarray() # Field energy E2 = np.sum(Ex**2) + np.sum(Ey**2) + np.sum(Ez**2) B2 = np.sum(Bx**2) + np.sum(By**2) + np.sum(Bz**2) - N = np.array(ds.domain_width / ds.domain_dimensions) + N = np.array(ds.domain_width / ds.domain_dimensions) dV = N[0] * N[1] * N[2] - values_yt['field energy'] = 0.5 * dV * (E2 * eps0 + B2 / mu0) - values_yt['field momentum in x'] = eps0 * np.sum(Ey * Bz - Ez * By) * dV - values_yt['field momentum in y'] = eps0 * np.sum(Ez * Bx - Ex * Bz) * dV - values_yt['field momentum in z'] = eps0 * np.sum(Ex * By - Ey * Bx) * dV + values_yt["field energy"] = 0.5 * dV * (E2 * eps0 + B2 / mu0) + values_yt["field momentum in x"] = eps0 * np.sum(Ey * Bz - Ez * By) * dV + values_yt["field momentum in y"] = eps0 * np.sum(Ez * Bx - Ex * Bz) * dV + values_yt["field momentum in z"] = eps0 * np.sum(Ex * By - Ey * Bx) * dV # Field energy in quarter of simulation domain - E2 = np.sum((Ex**2 + Ey**2 + Ez**2)*(y > 0)*(z < 0)) - B2 = np.sum((Bx**2 + By**2 + Bz**2)*(y > 0)*(z < 0)) - values_yt['field energy in quarter of simulation domain'] = 0.5 * dV * (E2 * eps0 + B2 / mu0) + E2 = np.sum((Ex**2 + Ey**2 + Ez**2) * (y > 0) * (z < 0)) + B2 = np.sum((Bx**2 + By**2 + Bz**2) * (y > 0) * (z < 0)) + values_yt["field energy in quarter of simulation domain"] = ( + 0.5 * dV * (E2 * eps0 + B2 / mu0) + ) # Max/min values of various grid quantities - values_yt['maximum of |Ex|'] = np.amax(np.abs(Ex)) - values_yt['maximum of |Ey|'] = np.amax(np.abs(Ey)) - values_yt['maximum of |Ez|'] = np.amax(np.abs(Ez)) - values_yt['maximum of |Bx|'] = np.amax(np.abs(Bx)) - values_yt['maximum of |By|'] = np.amax(np.abs(By)) - values_yt['maximum of |Bz|'] = np.amax(np.abs(Bz)) - values_yt['maximum of |E|'] = np.amax(np.sqrt(Ex**2 + Ey**2 + Ez**2)) - values_yt['maximum of |B|'] = np.amax(np.sqrt(Bx**2 + By**2 + Bz**2)) - values_yt['maximum of rho'] = np.amax(rho) - values_yt['minimum of rho'] = np.amin(rho) - values_yt['electrons: maximum of |rho|'] = np.amax(np.abs(rho_electrons)) - values_yt['protons: maximum of |rho|'] = np.amax(np.abs(rho_protons)) - values_yt['maximum of |B| from generic field reduction'] = np.amax(np.sqrt(Bx**2 + By**2 + Bz**2)) - values_yt['minimum of x*Ey*Bz'] = np.amin(x*Ey*Bz) - values_yt['maximum of Edotj'] = np.amax(Ex*jx + Ey*jy + Ez*jz) - - #-------------------------------------------------------------------------------------------------- + values_yt["maximum of |Ex|"] = np.amax(np.abs(Ex)) + values_yt["maximum of |Ey|"] = np.amax(np.abs(Ey)) + values_yt["maximum of |Ez|"] = np.amax(np.abs(Ez)) + values_yt["maximum of |Bx|"] = np.amax(np.abs(Bx)) + values_yt["maximum of |By|"] = np.amax(np.abs(By)) + values_yt["maximum of |Bz|"] = np.amax(np.abs(Bz)) + values_yt["maximum of |E|"] = np.amax(np.sqrt(Ex**2 + Ey**2 + Ez**2)) + values_yt["maximum of |B|"] = np.amax(np.sqrt(Bx**2 + By**2 + Bz**2)) + values_yt["maximum of rho"] = np.amax(rho) + values_yt["minimum of rho"] = np.amin(rho) + values_yt["electrons: maximum of |rho|"] = np.amax(np.abs(rho_electrons)) + values_yt["protons: maximum of |rho|"] = np.amax(np.abs(rho_protons)) + values_yt["maximum of |B| from generic field reduction"] = np.amax( + np.sqrt(Bx**2 + By**2 + Bz**2) + ) + values_yt["minimum of x*Ey*Bz"] = np.amin(x * Ey * Bz) + values_yt["maximum of Edotj"] = np.amax(Ex * jx + Ey * jy + Ez * jz) + + # -------------------------------------------------------------------------------------------------- # Part 2: get results from reduced diagnostics (label '_rd') - #-------------------------------------------------------------------------------------------------- + # -------------------------------------------------------------------------------------------------- # Quantities computed from reduced diagnostics values_rd = dict() # Load data from output files - EFdata = np.genfromtxt('./diags/reducedfiles/EF.txt') # Field energy - EPdata = np.genfromtxt('./diags/reducedfiles/EP.txt') # Particle energy - PFdata = np.genfromtxt('./diags/reducedfiles/PF.txt') # Field momentum - PPdata = np.genfromtxt('./diags/reducedfiles/PP.txt') # Particle momentum - MFdata = np.genfromtxt('./diags/reducedfiles/MF.txt') # Field maximum - MRdata = np.genfromtxt('./diags/reducedfiles/MR.txt') # Rho maximum - NPdata = np.genfromtxt('./diags/reducedfiles/NP.txt') # Particle number - FR_Maxdata = np.genfromtxt('./diags/reducedfiles/FR_Max.txt') # Field Reduction using maximum - FR_Mindata = np.genfromtxt('./diags/reducedfiles/FR_Min.txt') # Field Reduction using minimum - FR_Integraldata = np.genfromtxt('./diags/reducedfiles/FR_Integral.txt') # Field Reduction using integral - Edotjdata = np.genfromtxt('./diags/reducedfiles/Edotj.txt') # E dot j maximum + EFdata = np.genfromtxt("./diags/reducedfiles/EF.txt") # Field energy + EPdata = np.genfromtxt("./diags/reducedfiles/EP.txt") # Particle energy + PFdata = np.genfromtxt("./diags/reducedfiles/PF.txt") # Field momentum + PPdata = np.genfromtxt("./diags/reducedfiles/PP.txt") # Particle momentum + MFdata = np.genfromtxt("./diags/reducedfiles/MF.txt") # Field maximum + MRdata = np.genfromtxt("./diags/reducedfiles/MR.txt") # Rho maximum + NPdata = np.genfromtxt("./diags/reducedfiles/NP.txt") # Particle number + FR_Maxdata = np.genfromtxt( + "./diags/reducedfiles/FR_Max.txt" + ) # Field Reduction using maximum + FR_Mindata = np.genfromtxt( + "./diags/reducedfiles/FR_Min.txt" + ) # Field Reduction using minimum + FR_Integraldata = np.genfromtxt( + "./diags/reducedfiles/FR_Integral.txt" + ) # Field Reduction using integral + Edotjdata = np.genfromtxt("./diags/reducedfiles/Edotj.txt") # E dot j maximum # First index "1" points to the values written at the last time step - values_rd['field energy'] = EFdata[1][2] - values_rd['field energy in quarter of simulation domain'] = FR_Integraldata[1][2] - values_rd['particle energy'] = EPdata[1][2] - values_rd['electrons: particle energy'] = EPdata[1][3] - values_rd['protons: particle energy'] = EPdata[1][4] - values_rd['photons: particle energy'] = EPdata[1][5] - values_rd['mean particle energy'] = EPdata[1][6] - values_rd['electrons: mean particle energy'] = EPdata[1][7] - values_rd['protons: mean particle energy'] = EPdata[1][8] - values_rd['photons: mean particle energy'] = EPdata[1][9] - values_rd['field momentum in x'] = PFdata[1][2] - values_rd['field momentum in y'] = PFdata[1][3] - values_rd['field momentum in z'] = PFdata[1][4] - values_rd['particle momentum in x'] = PPdata[1][2] - values_rd['particle momentum in y'] = PPdata[1][3] - values_rd['particle momentum in z'] = PPdata[1][4] - values_rd['electrons: particle momentum in x'] = PPdata[1][5] - values_rd['electrons: particle momentum in y'] = PPdata[1][6] - values_rd['electrons: particle momentum in z'] = PPdata[1][7] - values_rd['protons: particle momentum in x'] = PPdata[1][8] - values_rd['protons: particle momentum in y'] = PPdata[1][9] - values_rd['protons: particle momentum in z'] = PPdata[1][10] - values_rd['photons: particle momentum in x'] = PPdata[1][11] - values_rd['photons: particle momentum in y'] = PPdata[1][12] - values_rd['photons: particle momentum in z'] = PPdata[1][13] - values_rd['mean particle momentum in x'] = PPdata[1][14] - values_rd['mean particle momentum in y'] = PPdata[1][15] - values_rd['mean particle momentum in z'] = PPdata[1][16] - values_rd['electrons: mean particle momentum in x'] = PPdata[1][17] - values_rd['electrons: mean particle momentum in y'] = PPdata[1][18] - values_rd['electrons: mean particle momentum in z'] = PPdata[1][19] - values_rd['protons: mean particle momentum in x'] = PPdata[1][20] - values_rd['protons: mean particle momentum in y'] = PPdata[1][21] - values_rd['protons: mean particle momentum in z'] = PPdata[1][22] - values_rd['photons: mean particle momentum in x'] = PPdata[1][23] - values_rd['photons: mean particle momentum in y'] = PPdata[1][24] - values_rd['photons: mean particle momentum in z'] = PPdata[1][25] - values_rd['maximum of |Ex|'] = MFdata[1][2] - values_rd['maximum of |Ey|'] = MFdata[1][3] - values_rd['maximum of |Ez|'] = MFdata[1][4] - values_rd['maximum of |E|'] = MFdata[1][5] - values_rd['maximum of |Bx|'] = MFdata[1][6] - values_rd['maximum of |By|'] = MFdata[1][7] - values_rd['maximum of |Bz|'] = MFdata[1][8] - values_rd['maximum of |B|'] = MFdata[1][9] - values_rd['maximum of rho'] = MRdata[1][2] - values_rd['minimum of rho'] = MRdata[1][3] - values_rd['electrons: maximum of |rho|'] = MRdata[1][4] - values_rd['protons: maximum of |rho|'] = MRdata[1][5] - values_rd['number of particles'] = NPdata[1][2] - values_rd['electrons: number of particles'] = NPdata[1][3] - values_rd['protons: number of particles'] = NPdata[1][4] - values_rd['photons: number of particles'] = NPdata[1][5] - values_rd['sum of weights'] = NPdata[1][6] - values_rd['electrons: sum of weights'] = NPdata[1][7] - values_rd['protons: sum of weights'] = NPdata[1][8] - values_rd['photons: sum of weights'] = NPdata[1][9] - values_rd['maximum of |B| from generic field reduction'] = FR_Maxdata[1][2] - values_rd['minimum of x*Ey*Bz'] = FR_Mindata[1][2] - values_rd['maximum of Edotj'] = Edotjdata[1][2] - - #-------------------------------------------------------------------------------------------------- + values_rd["field energy"] = EFdata[1][2] + values_rd["field energy in quarter of simulation domain"] = FR_Integraldata[1][2] + values_rd["particle energy"] = EPdata[1][2] + values_rd["electrons: particle energy"] = EPdata[1][3] + values_rd["protons: particle energy"] = EPdata[1][4] + values_rd["photons: particle energy"] = EPdata[1][5] + values_rd["mean particle energy"] = EPdata[1][6] + values_rd["electrons: mean particle energy"] = EPdata[1][7] + values_rd["protons: mean particle energy"] = EPdata[1][8] + values_rd["photons: mean particle energy"] = EPdata[1][9] + values_rd["field momentum in x"] = PFdata[1][2] + values_rd["field momentum in y"] = PFdata[1][3] + values_rd["field momentum in z"] = PFdata[1][4] + values_rd["particle momentum in x"] = PPdata[1][2] + values_rd["particle momentum in y"] = PPdata[1][3] + values_rd["particle momentum in z"] = PPdata[1][4] + values_rd["electrons: particle momentum in x"] = PPdata[1][5] + values_rd["electrons: particle momentum in y"] = PPdata[1][6] + values_rd["electrons: particle momentum in z"] = PPdata[1][7] + values_rd["protons: particle momentum in x"] = PPdata[1][8] + values_rd["protons: particle momentum in y"] = PPdata[1][9] + values_rd["protons: particle momentum in z"] = PPdata[1][10] + values_rd["photons: particle momentum in x"] = PPdata[1][11] + values_rd["photons: particle momentum in y"] = PPdata[1][12] + values_rd["photons: particle momentum in z"] = PPdata[1][13] + values_rd["mean particle momentum in x"] = PPdata[1][14] + values_rd["mean particle momentum in y"] = PPdata[1][15] + values_rd["mean particle momentum in z"] = PPdata[1][16] + values_rd["electrons: mean particle momentum in x"] = PPdata[1][17] + values_rd["electrons: mean particle momentum in y"] = PPdata[1][18] + values_rd["electrons: mean particle momentum in z"] = PPdata[1][19] + values_rd["protons: mean particle momentum in x"] = PPdata[1][20] + values_rd["protons: mean particle momentum in y"] = PPdata[1][21] + values_rd["protons: mean particle momentum in z"] = PPdata[1][22] + values_rd["photons: mean particle momentum in x"] = PPdata[1][23] + values_rd["photons: mean particle momentum in y"] = PPdata[1][24] + values_rd["photons: mean particle momentum in z"] = PPdata[1][25] + values_rd["maximum of |Ex|"] = MFdata[1][2] + values_rd["maximum of |Ey|"] = MFdata[1][3] + values_rd["maximum of |Ez|"] = MFdata[1][4] + values_rd["maximum of |E|"] = MFdata[1][5] + values_rd["maximum of |Bx|"] = MFdata[1][6] + values_rd["maximum of |By|"] = MFdata[1][7] + values_rd["maximum of |Bz|"] = MFdata[1][8] + values_rd["maximum of |B|"] = MFdata[1][9] + values_rd["maximum of rho"] = MRdata[1][2] + values_rd["minimum of rho"] = MRdata[1][3] + values_rd["electrons: maximum of |rho|"] = MRdata[1][4] + values_rd["protons: maximum of |rho|"] = MRdata[1][5] + values_rd["number of particles"] = NPdata[1][2] + values_rd["electrons: number of particles"] = NPdata[1][3] + values_rd["protons: number of particles"] = NPdata[1][4] + values_rd["photons: number of particles"] = NPdata[1][5] + values_rd["sum of weights"] = NPdata[1][6] + values_rd["electrons: sum of weights"] = NPdata[1][7] + values_rd["protons: sum of weights"] = NPdata[1][8] + values_rd["photons: sum of weights"] = NPdata[1][9] + values_rd["maximum of |B| from generic field reduction"] = FR_Maxdata[1][2] + values_rd["minimum of x*Ey*Bz"] = FR_Mindata[1][2] + values_rd["maximum of Edotj"] = Edotjdata[1][2] + + # -------------------------------------------------------------------------------------------------- # Part 3: compare values from plotfiles and reduced diagnostics and print output - #-------------------------------------------------------------------------------------------------- + # -------------------------------------------------------------------------------------------------- error = dict() tolerance = 5e-3 if single_precision else 1e-12 @@ -303,12 +368,12 @@ def do_analysis(single_precision = False): # while the field energy from the reduced diagnostics is computed from (Yee) staggered data. for k in values_yt.keys(): print() - print('values_yt[' + k + '] = ', values_yt[k]) - print('values_rd[' + k + '] = ', values_rd[k]) + print("values_yt[" + k + "] = ", values_yt[k]) + print("values_rd[" + k + "] = ", values_rd[k]) error[k] = abs(values_yt[k] - values_rd[k]) / abs(values_yt[k]) - print('relative error = ', error[k]) - tol = field_energy_tolerance if (k == 'field energy') else tolerance - assert(error[k] < tol) + print("relative error = ", error[k]) + tol = field_energy_tolerance if (k == "field energy") else tolerance + assert error[k] < tol print() test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/reduced_diags/analysis_reduced_diags_loadbalancecosts.py b/Examples/Tests/reduced_diags/analysis_reduced_diags_load_balance_costs.py similarity index 75% rename from Examples/Tests/reduced_diags/analysis_reduced_diags_loadbalancecosts.py rename to Examples/Tests/reduced_diags/analysis_reduced_diags_load_balance_costs.py index a706aace1f6..05f696e2fe6 100755 --- a/Examples/Tests/reduced_diags/analysis_reduced_diags_loadbalancecosts.py +++ b/Examples/Tests/reduced_diags/analysis_reduced_diags_load_balance_costs.py @@ -17,11 +17,13 @@ # Possible running time: ~ 1 s +import os +import re import sys import numpy as np -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Command line argument @@ -29,13 +31,15 @@ # Load costs data data = np.genfromtxt("./diags/reducedfiles/LBC.txt") -data = data[:,2:] +data = data[:, 2:] # Compute the number of datafields saved per box n_data_fields = 0 with open("./diags/reducedfiles/LBC.txt") as f: h = f.readlines()[0] - unique_headers=[''.join([l for l in w if not l.isdigit()]) for w in h.split()][2::] + unique_headers = ["".join([ln for ln in w if not ln.isdigit()]) for w in h.split()][ + 2:: + ] n_data_fields = len(set(unique_headers)) f.close() @@ -46,11 +50,12 @@ # ... # cost_box_n, proc_box_n, lev_box_n, i_low_box_n, j_low_box_n, k_low_box_n(, gpu_ID_box_n if GPU run), hostname_box_n] + # Function to get efficiency at an iteration i def get_efficiency(i): # First get the unique ranks - costs, ranks = data[i,0::n_data_fields], data[i,1::n_data_fields].astype(int) - rank_to_cost_map = {r:0. for r in set(ranks)} + costs, ranks = data[i, 0::n_data_fields], data[i, 1::n_data_fields].astype(int) + rank_to_cost_map = {r: 0.0 for r in set(ranks)} # Compute efficiency before/after load balance and check it is improved for c, r in zip(costs, ranks): @@ -62,14 +67,18 @@ def get_efficiency(i): return efficiencies.mean() + # The iteration i=2 is load balanced; examine before/after load balance efficiency_before, efficiency_after = get_efficiency(1), get_efficiency(2) -print('load balance efficiency (before load balance): ', efficiency_before) -print('load balance efficiency (after load balance): ', efficiency_after) +print("load balance efficiency (before load balance): ", efficiency_before) +print("load balance efficiency (after load balance): ", efficiency_after) # The load balanced case is expected to be more efficient # than non-load balanced case -assert(efficiency_before < efficiency_after) +assert efficiency_before < efficiency_after -test_name = 'reduced_diags_loadbalancecosts_timers' +# The PICMI and native input versions run the same test, so +# their results are compared to the same benchmark file +test_name = os.path.split(os.getcwd())[1] +test_name = re.sub("_picmi", "", test_name) checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/reduced_diags/analysis_reduced_diags_single.py b/Examples/Tests/reduced_diags/analysis_reduced_diags_single.py index 0bd83854c4d..d900ec673c1 100755 --- a/Examples/Tests/reduced_diags/analysis_reduced_diags_single.py +++ b/Examples/Tests/reduced_diags/analysis_reduced_diags_single.py @@ -13,4 +13,4 @@ import analysis_reduced_diags_impl as an -an.do_analysis(single_precision = True) +an.do_analysis(single_precision=True) diff --git a/Examples/Tests/reduced_diags/inputs_loadbalancecosts b/Examples/Tests/reduced_diags/inputs_base_3d similarity index 100% rename from Examples/Tests/reduced_diags/inputs_loadbalancecosts rename to Examples/Tests/reduced_diags/inputs_base_3d diff --git a/Examples/Tests/reduced_diags/inputs b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags similarity index 100% rename from Examples/Tests/reduced_diags/inputs rename to Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags diff --git a/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_heuristic b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_heuristic new file mode 100644 index 00000000000..18777d5a1fa --- /dev/null +++ b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_heuristic @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.load_balance_costs_update = Heuristic diff --git a/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers new file mode 100644 index 00000000000..7d8586cd913 --- /dev/null +++ b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.load_balance_costs_update = Timers diff --git a/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers_picmi.py b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers_picmi.py new file mode 100644 index 00000000000..d1dc6935bb7 --- /dev/null +++ b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers_picmi.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 + +from pywarpx import picmi + +# Number of time steps +max_steps = 3 + +# Number of cells +nx = 128 +ny = 32 +nz = 128 + +# Physical domain +xmin = 0.0 +xmax = 4.0 +ymin = 0.0 +ymax = 4.0 +zmin = 0.0 +zmax = 4.0 + +# Create grid +grid = picmi.Cartesian3DGrid( + number_of_cells=[nx, ny, nz], + warpx_max_grid_size=32, + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["periodic", "periodic", "periodic"], + upper_boundary_conditions=["periodic", "periodic", "periodic"], +) + +# Electromagnetic solver +solver = picmi.ElectromagneticSolver(grid=grid, method="Yee", cfl=0.99999) + +# Particles +electrons = picmi.Species( + particle_type="electron", + name="electrons", + initial_distribution=picmi.UniformDistribution( + density=1e14, rms_velocity=[0] * 3, upper_bound=[xmax, ymax, 1.0] + ), +) +layout = picmi.GriddedLayout(n_macroparticle_per_cell=[1, 1, 1], grid=grid) + +# Reduced diagnostic +reduced_diags = [] +reduced_diags.append( + picmi.ReducedDiagnostic(diag_type="LoadBalanceCosts", period=1, name="LBC") +) + +reduced_diags.append( + picmi.ReducedDiagnostic( + diag_type="FieldReduction", + period=1, + name="FR", + reduction_type="Maximum", + reduced_function="Ez", + ) +) + +reduced_diags.append( + picmi.ReducedDiagnostic( + diag_type="ParticleHistogram", + period=1, + name="PH", + species=electrons, + bin_number=10, + bin_min=0.0, + bin_max=xmax, + normalization="unity_particle_weight", + histogram_function="x", + ) +) + +# Diagnostic +particle_diag = picmi.ParticleDiagnostic( + name="diag1", + period=3, + species=[electrons], + data_list=["ux", "uy", "uz", "x", "y", "z", "weighting"], +) +field_diag = picmi.FieldDiagnostic( + name="diag1", + grid=grid, + period=3, + data_list=["Bx", "By", "Bz", "Ex", "Ey", "Ez", "Jx", "Jy", "Jz"], +) + +# Set up simulation +sim = picmi.Simulation( + solver=solver, + max_steps=max_steps, + verbose=1, + particle_shape=1, + warpx_current_deposition_algo="esirkepov", + warpx_field_gathering_algo="energy-conserving", + warpx_load_balance_intervals=2, + warpx_load_balance_costs_update="timers", +) + +# Add species +sim.add_species(electrons, layout=layout) + +# Add reduced diagnostics +for reduced_diag in reduced_diags: + sim.add_diagnostic(reduced_diag) + +# Add diagnostics +sim.add_diagnostic(particle_diag) +sim.add_diagnostic(field_diag) + +# Advance simulation until last time step +# sim.write_input_file("test_input") +sim.step(max_steps) diff --git a/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers_psatd b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers_psatd new file mode 100644 index 00000000000..7d8586cd913 --- /dev/null +++ b/Examples/Tests/reduced_diags/inputs_test_3d_reduced_diags_load_balance_costs_timers_psatd @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.load_balance_costs_update = Timers diff --git a/Examples/Tests/relativistic_space_charge_initialization/CMakeLists.txt b/Examples/Tests/relativistic_space_charge_initialization/CMakeLists.txt new file mode 100644 index 00000000000..d89fb8b31b6 --- /dev/null +++ b/Examples/Tests/relativistic_space_charge_initialization/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_3d_relativistic_space_charge_initialization # name + 3 # dims + 2 # nprocs + inputs_test_3d_relativistic_space_charge_initialization # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/relativistic_space_charge_initialization/analysis.py b/Examples/Tests/relativistic_space_charge_initialization/analysis.py index 569a7d2678a..4828e3ddce5 100755 --- a/Examples/Tests/relativistic_space_charge_initialization/analysis.py +++ b/Examples/Tests/relativistic_space_charge_initialization/analysis.py @@ -11,82 +11,89 @@ verifying that the space-charge field of a Gaussian beam corresponds to the expected theoretical field. """ + import os import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np import scipy.constants as scc import yt yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Parameters from the Simulation -Qtot = -1.e-20 -r0 = 2.e-6 +Qtot = -1.0e-20 +r0 = 2.0e-6 # Open data file filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) # Extract data -ad0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -Ex_array = ad0[('mesh','Ex')].to_ndarray().squeeze() -By_array = ad0[('mesh','By')].to_ndarray() +ad0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +Ex_array = ad0[("mesh", "Ex")].to_ndarray().squeeze() +By_array = ad0[("mesh", "By")].to_ndarray() # Extract grid coordinates -Nx, Ny, Nz = ds.domain_dimensions +Nx, Ny, Nz = ds.domain_dimensions xmin, ymin, zmin = ds.domain_left_edge.v Lx, Ly, Lz = ds.domain_width.v -x = xmin + Lx/Nx*(0.5+np.arange(Nx)) -y = ymin + Ly/Ny*(0.5+np.arange(Ny)) -z = zmin + Lz/Nz*(0.5+np.arange(Nz)) +x = xmin + Lx / Nx * (0.5 + np.arange(Nx)) +y = ymin + Ly / Ny * (0.5 + np.arange(Ny)) +z = zmin + Lz / Nz * (0.5 + np.arange(Nz)) # Compute theoretical field -x_2d, y_2d, z_2d = np.meshgrid(x, y, z, indexing='ij') +x_2d, y_2d, z_2d = np.meshgrid(x, y, z, indexing="ij") r2 = x_2d**2 + y_2d**2 -factor = Qtot/scc.epsilon_0/(2*np.pi*r2) * (1-np.exp(-r2/(2*r0**2))) -factor_z = 1./(2*np.pi)**.5/r0 * np.exp(-z_2d**2/(2*r0**2)) -Ex_th = factor*factor_z*x_2d -Ey_th = factor*factor_z*y_2d +factor = Qtot / scc.epsilon_0 / (2 * np.pi * r2) * (1 - np.exp(-r2 / (2 * r0**2))) +factor_z = 1.0 / (2 * np.pi) ** 0.5 / r0 * np.exp(-(z_2d**2) / (2 * r0**2)) +Ex_th = factor * factor_z * x_2d +Ey_th = factor * factor_z * y_2d + # Plot theory and data def make_2d(arr): if arr.ndim == 3: - return arr[:,Ny//2,:] + return arr[:, Ny // 2, :] else: return arr -plt.figure(figsize=(10,10)) + + +plt.figure(figsize=(10, 10)) plt.subplot(221) -plt.title('Ex: Theory') +plt.title("Ex: Theory") plt.imshow(make_2d(Ex_th)) plt.colorbar() plt.subplot(222) -plt.title('Ex: Simulation') +plt.title("Ex: Simulation") plt.imshow(make_2d(Ex_array)) plt.colorbar() plt.subplot(223) -plt.title('By: Theory') -plt.imshow(make_2d(Ex_th/scc.c)) +plt.title("By: Theory") +plt.imshow(make_2d(Ex_th / scc.c)) plt.colorbar() plt.subplot(224) -plt.title('By: Simulation') +plt.title("By: Simulation") plt.imshow(make_2d(By_array)) plt.colorbar() -plt.savefig('Comparison.png') +plt.savefig("Comparison.png") + # Automatically check the results def check(E, E_th, label): - print( 'Relative error in %s: %.3f'%( - label, abs(E-E_th).max()/E_th.max())) - assert np.allclose( E, E_th, atol=0.175*E_th.max() ) + print("Relative error in %s: %.3f" % (label, abs(E - E_th).max() / E_th.max())) + assert np.allclose(E, E_th, atol=0.175 * E_th.max()) + -check( Ex_array, Ex_th, 'Ex' ) +check(Ex_array, Ex_th, "Ex") test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename, do_particles=False) diff --git a/Examples/Tests/relativistic_space_charge_initialization/inputs_3d b/Examples/Tests/relativistic_space_charge_initialization/inputs_test_3d_relativistic_space_charge_initialization similarity index 100% rename from Examples/Tests/relativistic_space_charge_initialization/inputs_3d rename to Examples/Tests/relativistic_space_charge_initialization/inputs_test_3d_relativistic_space_charge_initialization diff --git a/Examples/Tests/repelling_particles/CMakeLists.txt b/Examples/Tests/repelling_particles/CMakeLists.txt new file mode 100644 index 00000000000..056f670a860 --- /dev/null +++ b/Examples/Tests/repelling_particles/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_repelling_particles # name + 2 # dims + 2 # nprocs + inputs_test_2d_repelling_particles # inputs + analysis.py # analysis + diags/diag1000200 # output + OFF # dependency +) diff --git a/Examples/Tests/repelling_particles/analysis_repelling.py b/Examples/Tests/repelling_particles/analysis.py similarity index 61% rename from Examples/Tests/repelling_particles/analysis_repelling.py rename to Examples/Tests/repelling_particles/analysis.py index bda3d74d274..401ba7ba5d0 100755 --- a/Examples/Tests/repelling_particles/analysis_repelling.py +++ b/Examples/Tests/repelling_particles/analysis.py @@ -22,6 +22,7 @@ d is the distance between them beta is the velocity normalized by the speed of light """ + import glob import os import re @@ -36,22 +37,22 @@ # Check plotfile name specified in command line last_filename = sys.argv[1] -filename_radical = re.findall(r'(.*?)\d+/*$', last_filename)[0] +filename_radical = re.findall(r"(.*?)\d+/*$", last_filename)[0] # Loop through files, and extract the position and velocity of both particles x1 = [] x2 = [] beta1 = [] beta2 = [] -for filename in sorted(glob.glob(filename_radical + '*')): +for filename in sorted(glob.glob(filename_radical + "*")): print(filename) ds = yt.load(filename) ad = ds.all_data() - x1.append( float(ad[('electron1','particle_position_x')][0]) ) - x2.append( float(ad[('electron2','particle_position_x')][0]) ) - beta1.append( float(ad[('electron1','particle_momentum_x')][0])/(m_e*c) ) - beta2.append( float(ad[('electron2','particle_momentum_x')][0])/(m_e*c) ) + x1.append(float(ad[("electron1", "particle_position_x")][0])) + x2.append(float(ad[("electron2", "particle_position_x")][0])) + beta1.append(float(ad[("electron1", "particle_momentum_x")][0]) / (m_e * c)) + beta2.append(float(ad[("electron2", "particle_momentum_x")][0]) / (m_e * c)) # Convert to numpy array x1 = np.array(x1) @@ -60,23 +61,23 @@ beta2 = np.array(beta2) # Plot velocities, compare with theory -w = 5.e12 -re = physical_constants['classical electron radius'][0] -beta_th = np.sqrt( beta1[0]**2 - 2*w*re*np.log( (x2[0]-x1[0])/(x2-x1) ) ) -plt.plot( beta1, '+', label='Particle 1' ) -plt.plot( -beta2, 'x', label='Particle 2' ) -plt.plot( beta_th, '*', label='Theory' ) +w = 5.0e12 +re = physical_constants["classical electron radius"][0] +beta_th = np.sqrt(beta1[0] ** 2 - 2 * w * re * np.log((x2[0] - x1[0]) / (x2 - x1))) +plt.plot(beta1, "+", label="Particle 1") +plt.plot(-beta2, "x", label="Particle 2") +plt.plot(beta_th, "*", label="Theory") plt.legend(loc=0) -plt.xlabel('Time (a.u.)') -plt.ylabel('Normalized velocity') -plt.savefig('Comparison.png') +plt.xlabel("Time (a.u.)") +plt.ylabel("Normalized velocity") +plt.savefig("Comparison.png") # Check that the results are close to the theory -assert np.allclose( beta1[1:], beta_th[1:], atol=0.01 ) -assert np.allclose( -beta2[1:], beta_th[1:], atol=0.01 ) +assert np.allclose(beta1[1:], beta_th[1:], atol=0.01) +assert np.allclose(-beta2[1:], beta_th[1:], atol=0.01) # Run checksum regression test -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/repelling_particles/inputs_2d b/Examples/Tests/repelling_particles/inputs_test_2d_repelling_particles similarity index 100% rename from Examples/Tests/repelling_particles/inputs_2d rename to Examples/Tests/repelling_particles/inputs_test_2d_repelling_particles diff --git a/Examples/Tests/resampling/CMakeLists.txt b/Examples/Tests/resampling/CMakeLists.txt new file mode 100644 index 00000000000..46e34858014 --- /dev/null +++ b/Examples/Tests/resampling/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_resample_velocity_coincidence_thinning # name + 1 # dims + 2 # nprocs + inputs_test_1d_resample_velocity_coincidence_thinning # inputs + analysis_default_regression.py # analysis + diags/diag1000004 # output + OFF # dependency +) + +add_warpx_test( + test_1d_resample_velocity_coincidence_thinning_cartesian # name + 1 # dims + 2 # nprocs + inputs_test_1d_resample_velocity_coincidence_thinning_cartesian # inputs + analysis_default_regression.py # analysis + diags/diag1000004 # output + OFF # dependency +) + +add_warpx_test( + test_2d_leveling_thinning # name + 2 # dims + 2 # nprocs + inputs_test_2d_leveling_thinning # inputs + analysis.py # analysis + diags/diag1000008 # output + OFF # dependency +) diff --git a/Examples/Tests/resampling/analysis.py b/Examples/Tests/resampling/analysis.py new file mode 100755 index 00000000000..f55f3b996c5 --- /dev/null +++ b/Examples/Tests/resampling/analysis.py @@ -0,0 +1,175 @@ +#!/usr/bin/env python3 + +# Copyright 2020 Neil Zaim +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +## In this test, we check that leveling thinning works as expected on two simple cases. Each case +## corresponds to a different particle species. + +import os +import sys + +import numpy as np +import yt +from scipy.special import erf + +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +fn_final = sys.argv[1] +fn0 = fn_final[:-4] + "0000" + +ds0 = yt.load(fn0) +ds = yt.load(fn_final) + +ad0 = ds0.all_data() +ad = ds.all_data() + +numcells = 16 * 16 +t_r = 1.3 # target ratio +relative_tol = 1.0e-13 # tolerance for machine precision errors + + +#### Tests for first species #### +# Particles are present in all simulation cells and all have the same weight + +ppc = 400.0 +numparts_init = numcells * ppc + +w0 = ad0["resampled_part1", "particle_weight"].to_ndarray() # weights before resampling +w = ad["resampled_part1", "particle_weight"].to_ndarray() # weights after resampling + +# Renormalize weights for easier calculations +w0 = w0 * ppc +w = w * ppc + +# Check that initial number of particles is indeed as expected +assert w0.shape[0] == numparts_init +# Check that all initial particles have the same weight +assert np.unique(w0).shape[0] == 1 +# Check that this weight is 1 (to machine precision) +assert abs(w0[0] - 1) < relative_tol + +# Check that the number of particles after resampling is as expected +numparts_final = w.shape[0] +expected_numparts_final = numparts_init / t_r**2 +error = np.abs(numparts_final - expected_numparts_final) +std_numparts_final = np.sqrt(numparts_init / t_r**2 * (1.0 - 1.0 / t_r**2)) +# 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions +print( + "difference between expected and actual final number of particles (1st species): " + + str(error) +) +print("tolerance: " + str(5 * std_numparts_final)) +assert error < 5 * std_numparts_final + +# Check that the final weight is the same for all particles (to machine precision) and is as +# expected +final_weight = t_r**2 +assert np.amax(np.abs(w - final_weight)) < relative_tol * final_weight + + +#### Tests for second species #### +# Particles are only present in a single cell and have a gaussian weight distribution +# Using a single cell makes the analysis easier because leveling thinning is done separately in +# each cell + +ppc = 100000.0 +numparts_init = ppc + +w0 = ad0["resampled_part2", "particle_weight"].to_ndarray() # weights before resampling +w = ad["resampled_part2", "particle_weight"].to_ndarray() # weights after resampling + +# Renormalize and sort weights for easier calculations +w0 = np.sort(w0) * ppc +w = np.sort(w) * ppc + +## First we verify that the initial distribution is as expected + +# Check that the mean initial weight is as expected +mean_initial_weight = np.average(w0) +expected_mean_initial_weight = 2.0 * np.sqrt(2.0) +error = np.abs(mean_initial_weight - expected_mean_initial_weight) +expected_std_initial_weight = 1.0 / np.sqrt(2.0) +std_mean_initial_weight = expected_std_initial_weight / np.sqrt(numparts_init) +# 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions +print( + "difference between expected and actual mean initial weight (2nd species): " + + str(error) +) +print("tolerance: " + str(5 * std_mean_initial_weight)) +assert error < 5 * std_mean_initial_weight + +# Check that the initial weight variance is as expected +variance_initial_weight = np.var(w0) +expected_variance_initial_weight = 0.5 +error = np.abs(variance_initial_weight - expected_variance_initial_weight) +std_variance_initial_weight = expected_variance_initial_weight * np.sqrt( + 2.0 / numparts_init +) +# 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions +print( + "difference between expected and actual variance of initial weight (2nd species): " + + str(error) +) +print("tolerance: " + str(5 * std_variance_initial_weight)) + +## Next we verify that the resampling worked as expected + +# Check that the level weight value is as expected from the initial distribution +level_weight = w[0] +assert np.abs(level_weight - mean_initial_weight * t_r) < level_weight * relative_tol + +# Check that the number of particles at the level weight is the same as predicted from analytic +# calculations +numparts_leveled = np.argmax(w > level_weight) # This returns the first index for which +# w > level_weight, which thus corresponds to the number of particles at the level weight +expected_numparts_leveled = ( + numparts_init + / (2.0 * t_r) + * ( + 1 + + erf(expected_mean_initial_weight * (t_r - 1.0)) + - 1.0 + / (np.sqrt(np.pi) * expected_mean_initial_weight) + * np.exp(-((expected_mean_initial_weight * (t_r - 1.0)) ** 2)) + ) +) +error = np.abs(numparts_leveled - expected_numparts_leveled) +std_numparts_leveled = np.sqrt( + expected_numparts_leveled + - numparts_init + / np.sqrt(np.pi) + / (t_r * expected_mean_initial_weight) ** 2 + * ( + np.sqrt(np.pi) + / 4.0 + * (2.0 * expected_mean_initial_weight**2 + 1.0) + * (1.0 - erf(expected_mean_initial_weight * (t_r - 1.0))) + - 0.5 + * np.exp( + -((expected_mean_initial_weight * (t_r - 1.0)) ** 2) + * (expected_mean_initial_weight * (t_r + 1.0)) + ) + ) +) +# 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions +print( + "difference between expected and actual number of leveled particles (2nd species): " + + str(error) +) +print("tolerance: " + str(5 * std_numparts_leveled)) + +numparts_unaffected = w.shape[0] - numparts_leveled +numparts_unaffected_anticipated = w0.shape[0] - np.argmax(w0 > level_weight) +# Check that number of particles with weight higher than level weight is the same before and after +# resampling +assert numparts_unaffected == numparts_unaffected_anticipated +# Check that particles with weight higher than level weight are unaffected by resampling. +assert np.all(w[-numparts_unaffected:] == w0[-numparts_unaffected:]) + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, fn_final) diff --git a/Examples/Tests/resampling/analysis_default_regression.py b/Examples/Tests/resampling/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/resampling/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/resampling/analysis_leveling_thinning.py b/Examples/Tests/resampling/analysis_leveling_thinning.py deleted file mode 100755 index 5f3dc8ecdff..00000000000 --- a/Examples/Tests/resampling/analysis_leveling_thinning.py +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2020 Neil Zaim -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -## In this test, we check that leveling thinning works as expected on two simple cases. Each case -## corresponds to a different particle species. - -import os -import sys - -import numpy as np -import yt -from scipy.special import erf - -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -fn_final = sys.argv[1] -fn0 = fn_final[:-4] + '0000' - -ds0 = yt.load(fn0) -ds = yt.load(fn_final) - -ad0 = ds0.all_data() -ad = ds.all_data() - -numcells = 16*16 -t_r = 1.3 # target ratio -relative_tol = 1.e-13 # tolerance for machine precision errors - - -#### Tests for first species #### -# Particles are present in all simulation cells and all have the same weight - -ppc = 400. -numparts_init = numcells*ppc - -w0 = ad0['resampled_part1','particle_weight'].to_ndarray() # weights before resampling -w = ad['resampled_part1','particle_weight'].to_ndarray() # weights after resampling - -# Renormalize weights for easier calculations -w0 = w0*ppc -w = w*ppc - -# Check that initial number of particles is indeed as expected -assert(w0.shape[0] == numparts_init) -# Check that all initial particles have the same weight -assert(np.unique(w0).shape[0] == 1) -# Check that this weight is 1 (to machine precision) -assert(abs(w0[0] - 1) < relative_tol) - -# Check that the number of particles after resampling is as expected -numparts_final = w.shape[0] -expected_numparts_final = numparts_init/t_r**2 -error = np.abs(numparts_final - expected_numparts_final) -std_numparts_final = np.sqrt(numparts_init/t_r**2*(1.-1./t_r**2)) -# 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions -print("difference between expected and actual final number of particles (1st species): " + str(error)) -print("tolerance: " + str(5*std_numparts_final)) -assert(error<5*std_numparts_final) - -# Check that the final weight is the same for all particles (to machine precision) and is as -# expected -final_weight = t_r**2 -assert(np.amax(np.abs(w-final_weight)) < relative_tol*final_weight ) - - -#### Tests for second species #### -# Particles are only present in a single cell and have a gaussian weight distribution -# Using a single cell makes the analysis easier because leveling thinning is done separately in -# each cell - -ppc = 100000. -numparts_init = ppc - -w0 = ad0['resampled_part2','particle_weight'].to_ndarray() # weights before resampling -w = ad['resampled_part2','particle_weight'].to_ndarray() # weights after resampling - -# Renormalize and sort weights for easier calculations -w0 = np.sort(w0)*ppc -w = np.sort(w)*ppc - -## First we verify that the initial distribution is as expected - -# Check that the mean initial weight is as expected -mean_initial_weight = np.average(w0) -expected_mean_initial_weight = 2.*np.sqrt(2.) -error = np.abs(mean_initial_weight - expected_mean_initial_weight) -expected_std_initial_weight = 1./np.sqrt(2.) -std_mean_initial_weight = expected_std_initial_weight/np.sqrt(numparts_init) -# 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions -print("difference between expected and actual mean initial weight (2nd species): " + str(error)) -print("tolerance: " + str(5*std_mean_initial_weight)) -assert(error<5*std_mean_initial_weight) - -# Check that the initial weight variance is as expected -variance_initial_weight = np.var(w0) -expected_variance_initial_weight = 0.5 -error = np.abs(variance_initial_weight - expected_variance_initial_weight) -std_variance_initial_weight = expected_variance_initial_weight*np.sqrt(2./numparts_init) -# 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions -print("difference between expected and actual variance of initial weight (2nd species): " + str(error)) -print("tolerance: " + str(5*std_variance_initial_weight)) - -## Next we verify that the resampling worked as expected - -# Check that the level weight value is as expected from the initial distribution -level_weight = w[0] -assert(np.abs(level_weight - mean_initial_weight*t_r) < level_weight*relative_tol) - -# Check that the number of particles at the level weight is the same as predicted from analytic -# calculations -numparts_leveled = np.argmax(w > level_weight) # This returns the first index for which -# w > level_weight, which thus corresponds to the number of particles at the level weight -expected_numparts_leveled = numparts_init/(2.*t_r)*(1+erf(expected_mean_initial_weight*(t_r-1.)) \ - -1./(np.sqrt(np.pi)*expected_mean_initial_weight)* \ - np.exp(-(expected_mean_initial_weight*(t_r-1.))**2)) -error = np.abs(numparts_leveled - expected_numparts_leveled) -std_numparts_leveled = np.sqrt(expected_numparts_leveled - numparts_init/np.sqrt(np.pi)/(t_r* \ - expected_mean_initial_weight)**2*(np.sqrt(np.pi)/4.* \ - (2.*expected_mean_initial_weight**2+1.)*(1.-erf(expected_mean_initial_weight* \ - (t_r-1.)))-0.5*np.exp(-(expected_mean_initial_weight*(t_r-1.))**2* \ - (expected_mean_initial_weight*(t_r+1.))))) -# 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions -print("difference between expected and actual number of leveled particles (2nd species): " + str(error)) -print("tolerance: " + str(5*std_numparts_leveled)) - -numparts_unaffected = w.shape[0] - numparts_leveled -numparts_unaffected_anticipated = w0.shape[0] - np.argmax(w0 > level_weight) -# Check that number of particles with weight higher than level weight is the same before and after -# resampling -assert(numparts_unaffected == numparts_unaffected_anticipated) -# Check that particles with weight higher than level weight are unaffected by resampling. -assert(np.all(w[-numparts_unaffected:] == w0[-numparts_unaffected:])) - -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, fn_final) diff --git a/Examples/Tests/resampling/inputs_1d_velocity_coincidence_thinning b/Examples/Tests/resampling/inputs_test_1d_resample_velocity_coincidence_thinning similarity index 100% rename from Examples/Tests/resampling/inputs_1d_velocity_coincidence_thinning rename to Examples/Tests/resampling/inputs_test_1d_resample_velocity_coincidence_thinning diff --git a/Examples/Tests/resampling/inputs_1d_velocity_coincidence_thinning_cartesian b/Examples/Tests/resampling/inputs_test_1d_resample_velocity_coincidence_thinning_cartesian similarity index 100% rename from Examples/Tests/resampling/inputs_1d_velocity_coincidence_thinning_cartesian rename to Examples/Tests/resampling/inputs_test_1d_resample_velocity_coincidence_thinning_cartesian diff --git a/Examples/Tests/resampling/inputs_leveling_thinning b/Examples/Tests/resampling/inputs_test_2d_leveling_thinning similarity index 100% rename from Examples/Tests/resampling/inputs_leveling_thinning rename to Examples/Tests/resampling/inputs_test_2d_leveling_thinning diff --git a/Examples/Tests/restart/CMakeLists.txt b/Examples/Tests/restart/CMakeLists.txt new file mode 100644 index 00000000000..bb3e90059c9 --- /dev/null +++ b/Examples/Tests/restart/CMakeLists.txt @@ -0,0 +1,106 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_id_cpu_read_picmi # name + 2 # dims + 1 # nprocs + inputs_test_2d_id_cpu_read_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +# TODO +# - Add checksums file +# - Enable analysis +add_warpx_test( + test_2d_runtime_components_picmi # name + 2 # dims + 1 # nprocs + inputs_test_2d_runtime_components_picmi.py # inputs + OFF #analysis_default_regression.py # analysis + OFF #diags/diag1000010 # output + OFF # dependency +) + +# TODO +# - Add checksums file +# - Enable analysis +add_warpx_test( + test_2d_runtime_components_picmi_restart # name + 2 # dims + 1 # nprocs + "inputs_test_2d_runtime_components_picmi.py amr.restart='../test_2d_runtime_components_picmi/diags/chk000005'" # inputs + OFF #analysis_default_restart.py # analysis + OFF #diags/diag1000010 # output + test_2d_runtime_components_picmi # dependency +) + +add_warpx_test( + test_3d_acceleration # name + 3 # dims + 2 # nprocs + inputs_test_3d_acceleration # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency +) + +add_warpx_test( + test_3d_acceleration_restart # name + 3 # dims + 2 # nprocs + inputs_test_3d_acceleration_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000010 # output + test_3d_acceleration # dependency +) + +if(WarpX_FFT) + add_warpx_test( + test_3d_acceleration_psatd # name + 3 # dims + 2 # nprocs + inputs_test_3d_acceleration_psatd # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_acceleration_psatd_restart # name + 3 # dims + 2 # nprocs + inputs_test_3d_acceleration_psatd_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000010 # output + test_3d_acceleration_psatd # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_acceleration_psatd_time_avg # name + 3 # dims + 2 # nprocs + inputs_test_3d_acceleration_psatd_time_avg # inputs + analysis_default_regression.py # analysis + diags/diag1000010 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_acceleration_psatd_time_avg_restart # name + 3 # dims + 2 # nprocs + inputs_test_3d_acceleration_psatd_time_avg_restart # inputs + analysis_default_restart.py # analysis + diags/diag1000010 # output + test_3d_acceleration_psatd_time_avg # dependency + ) +endif() diff --git a/Examples/Tests/restart/analysis_default_regression.py b/Examples/Tests/restart/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/restart/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/restart/analysis_default_restart.py b/Examples/Tests/restart/analysis_default_restart.py new file mode 120000 index 00000000000..0459986eebc --- /dev/null +++ b/Examples/Tests/restart/analysis_default_restart.py @@ -0,0 +1 @@ +../../analysis_default_restart.py \ No newline at end of file diff --git a/Examples/Tests/restart/analysis_restart.py b/Examples/Tests/restart/analysis_restart.py index 1a5b1374672..4a4d198f63f 100755 --- a/Examples/Tests/restart/analysis_restart.py +++ b/Examples/Tests/restart/analysis_restart.py @@ -3,13 +3,13 @@ import os import sys -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] # Check restart data v. original data -sys.path.insert(0, '../../../../warpx/Examples/') +sys.path.insert(0, "../../../../warpx/Examples/") from analysis_default_restart import check_restart check_restart(filename) diff --git a/Examples/Tests/restart/inputs b/Examples/Tests/restart/inputs_base_3d similarity index 99% rename from Examples/Tests/restart/inputs rename to Examples/Tests/restart/inputs_base_3d index f6aef120466..6724bae64b3 100644 --- a/Examples/Tests/restart/inputs +++ b/Examples/Tests/restart/inputs_base_3d @@ -1,7 +1,6 @@ ################################# ####### GENERAL PARAMETERS ###### ################################# -#amr.restart = diags/chk00005/ max_step = 10 amr.n_cell = 32 32 256 amr.max_grid_size = 64 diff --git a/Examples/Tests/restart/PICMI_inputs_id_cpu_read.py b/Examples/Tests/restart/inputs_test_2d_id_cpu_read_picmi.py similarity index 60% rename from Examples/Tests/restart/PICMI_inputs_id_cpu_read.py rename to Examples/Tests/restart/inputs_test_2d_id_cpu_read_picmi.py index d400924a378..be6e621653f 100755 --- a/Examples/Tests/restart/PICMI_inputs_id_cpu_read.py +++ b/Examples/Tests/restart/inputs_test_2d_id_cpu_read_picmi.py @@ -34,73 +34,61 @@ ########################## grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, ny], - lower_bound = [xmin, ymin], - upper_bound = [xmax, ymax], - lower_boundary_conditions = ['dirichlet', 'periodic'], - upper_boundary_conditions = ['dirichlet', 'periodic'], - lower_boundary_conditions_particles = ['absorbing', 'periodic'], - upper_boundary_conditions_particles = ['absorbing', 'periodic'], - moving_window_velocity = None, - warpx_max_grid_size = 32 + number_of_cells=[nx, ny], + lower_bound=[xmin, ymin], + upper_bound=[xmax, ymax], + lower_boundary_conditions=["dirichlet", "periodic"], + upper_boundary_conditions=["dirichlet", "periodic"], + lower_boundary_conditions_particles=["absorbing", "periodic"], + upper_boundary_conditions_particles=["absorbing", "periodic"], + moving_window_velocity=None, + warpx_max_grid_size=32, ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-6, - warpx_self_fields_verbosity=0 + grid=grid, + method="Multigrid", + required_precision=1e-6, + warpx_self_fields_verbosity=0, ) ########################## # physics components ########################## -electrons = picmi.Species( - particle_type='electron', name='electrons' -) +electrons = picmi.Species(particle_type="electron", name="electrons") ########################## # diagnostics ########################## particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 10, - write_dir = '.', - warpx_file_prefix = f'Python_restart_runtime_components_plt' + name="diag1", + period=10, ) field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 10, - data_list = ['phi'], - write_dir = '.', - warpx_file_prefix = f'Python_restart_runtime_components_plt' + name="diag1", + grid=grid, + period=10, + data_list=["phi"], ) checkpoint = picmi.Checkpoint( - name = 'chkpoint', - period = 5, - write_dir = '.', - warpx_file_min_digits = 5, - warpx_file_prefix = f'Python_restart_runtime_components_chk' + name="chkpoint", + period=5, + write_dir=".", + warpx_file_min_digits=5, + warpx_file_prefix="Python_restart_runtime_components_chk", ) ########################## # simulation setup ########################## -sim = picmi.Simulation( - solver = solver, - time_step_size = dt, - max_steps = max_steps, - verbose = 1 -) +sim = picmi.Simulation(solver=solver, time_step_size=dt, max_steps=max_steps, verbose=1) sim.add_species( - electrons, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[0, 0], grid=grid - ) + electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[0, 0], grid=grid) ) for arg in sys.argv: @@ -124,11 +112,11 @@ np.random.seed(30025025) # wrap the electrons particle container -electron_wrapper = particle_containers.ParticleContainerWrapper('electrons') -electron_wrapper.add_real_comp('newPid') +electron_wrapper = particle_containers.ParticleContainerWrapper("electrons") +electron_wrapper.add_real_comp("newPid") -def add_particles(): +def add_particles(): nps = 10 x = np.linspace(0.005, 0.025, nps) y = np.zeros(nps) @@ -140,10 +128,10 @@ def add_particles(): newPid = 5.0 electron_wrapper.add_particles( - x=x, y=y, z=z, ux=ux, uy=uy, uz=uz, - w=w, newPid=newPid + x=x, y=y, z=z, ux=ux, uy=uy, uz=uz, w=w, newPid=newPid ) + callbacks.installbeforestep(add_particles) ########################## @@ -157,5 +145,5 @@ def add_particles(): # check that the ids and cpus are read properly ############################################### -assert(np.sum(np.concatenate(electron_wrapper.get_particle_id())) == 5050) -assert(np.sum(np.concatenate(electron_wrapper.get_particle_cpu())) == 0) +assert np.sum(np.concatenate(electron_wrapper.get_particle_id())) == 5050 +assert np.sum(np.concatenate(electron_wrapper.get_particle_cpu())) == 0 diff --git a/Examples/Tests/restart/PICMI_inputs_runtime_component_analyze.py b/Examples/Tests/restart/inputs_test_2d_runtime_components_picmi.py similarity index 66% rename from Examples/Tests/restart/PICMI_inputs_runtime_component_analyze.py rename to Examples/Tests/restart/inputs_test_2d_runtime_components_picmi.py index 32c9f4e5808..e90bfd266a7 100755 --- a/Examples/Tests/restart/PICMI_inputs_runtime_component_analyze.py +++ b/Examples/Tests/restart/inputs_test_2d_runtime_components_picmi.py @@ -35,73 +35,55 @@ ########################## grid = picmi.Cartesian2DGrid( - number_of_cells = [nx, ny], - lower_bound = [xmin, ymin], - upper_bound = [xmax, ymax], - lower_boundary_conditions = ['dirichlet', 'periodic'], - upper_boundary_conditions = ['dirichlet', 'periodic'], - lower_boundary_conditions_particles = ['absorbing', 'periodic'], - upper_boundary_conditions_particles = ['absorbing', 'periodic'], - moving_window_velocity = None, - warpx_max_grid_size = 32 + number_of_cells=[nx, ny], + lower_bound=[xmin, ymin], + upper_bound=[xmax, ymax], + lower_boundary_conditions=["dirichlet", "periodic"], + upper_boundary_conditions=["dirichlet", "periodic"], + lower_boundary_conditions_particles=["absorbing", "periodic"], + upper_boundary_conditions_particles=["absorbing", "periodic"], + moving_window_velocity=None, + warpx_max_grid_size=32, ) solver = picmi.ElectrostaticSolver( - grid=grid, method='Multigrid', required_precision=1e-6, - warpx_self_fields_verbosity=0 + grid=grid, + method="Multigrid", + required_precision=1e-6, + warpx_self_fields_verbosity=0, ) ########################## # physics components ########################## -electrons = picmi.Species( - particle_type='electron', name='electrons' -) +electrons = picmi.Species(particle_type="electron", name="electrons") ########################## # diagnostics ########################## particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = 10, - write_dir = '.', - warpx_file_prefix = f'Python_restart_runtime_components_plt' + name="diag1", + period=10, ) field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = 10, - data_list = ['phi'], - write_dir = '.', - warpx_file_prefix = f'Python_restart_runtime_components_plt' + name="diag1", + grid=grid, + period=10, + data_list=["phi"], ) -checkpoint = picmi.Checkpoint( - name = 'chkpoint', - period = 5, - write_dir = '.', - warpx_file_min_digits = 5, - warpx_file_prefix = f'Python_restart_runtime_components_chk' -) +checkpoint = picmi.Checkpoint(name="chk", period=5) ########################## # simulation setup ########################## -sim = picmi.Simulation( - solver = solver, - time_step_size = dt, - max_steps = max_steps, - verbose = 1 -) +sim = picmi.Simulation(solver=solver, time_step_size=dt, max_steps=max_steps, verbose=1) sim.add_species( - electrons, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[0, 0], grid=grid - ) + electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[0, 0], grid=grid) ) for arg in sys.argv: @@ -127,8 +109,8 @@ electron_wrapper = particle_containers.ParticleContainerWrapper("electrons") electron_wrapper.add_real_comp("newPid") -def add_particles(): +def add_particles(): nps = 10 x = np.linspace(0.005, 0.025, nps) y = np.zeros(nps) @@ -140,10 +122,10 @@ def add_particles(): newPid = 5.0 electron_wrapper.add_particles( - x=x, y=y, z=z, ux=ux, uy=uy, uz=uz, - w=w, newPid=newPid + x=x, y=y, z=z, ux=ux, uy=uy, uz=uz, w=w, newPid=newPid ) + callbacks.installbeforestep(add_particles) ########################## diff --git a/Examples/Tests/restart/inputs_test_3d_acceleration b/Examples/Tests/restart/inputs_test_3d_acceleration new file mode 100644 index 00000000000..7665a846eef --- /dev/null +++ b/Examples/Tests/restart/inputs_test_3d_acceleration @@ -0,0 +1,2 @@ +# base input parameters +FILE = inputs_base_3d diff --git a/Examples/Tests/restart/inputs_test_3d_acceleration_psatd b/Examples/Tests/restart/inputs_test_3d_acceleration_psatd new file mode 100644 index 00000000000..1f4e258b964 --- /dev/null +++ b/Examples/Tests/restart/inputs_test_3d_acceleration_psatd @@ -0,0 +1,11 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.maxwell_solver = psatd +boundary.field_hi = periodic periodic damped +boundary.field_lo = periodic periodic damped +particles.use_fdtd_nci_corr = 0 +psatd.current_correction = 0 +psatd.use_default_v_galilean = 1 +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_restart b/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_restart new file mode 100644 index 00000000000..ac2a354dcb9 --- /dev/null +++ b/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_restart @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_test_3d_acceleration_psatd + +# test input parameters +amr.restart = "../test_3d_acceleration_psatd/diags/chk000005" diff --git a/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_time_avg b/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_time_avg new file mode 100644 index 00000000000..d9625a7f058 --- /dev/null +++ b/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_time_avg @@ -0,0 +1,12 @@ +# base input parameters +FILE = inputs_base_3d + +# test input parameters +algo.maxwell_solver = psatd +boundary.field_hi = periodic periodic damped +boundary.field_lo = periodic periodic damped +particles.use_fdtd_nci_corr = 0 +psatd.current_correction = 0 +psatd.do_time_averaging = 1 +psatd.use_default_v_galilean = 1 +warpx.abort_on_warning_threshold = medium diff --git a/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_time_avg_restart b/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_time_avg_restart new file mode 100644 index 00000000000..44956c2259b --- /dev/null +++ b/Examples/Tests/restart/inputs_test_3d_acceleration_psatd_time_avg_restart @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_test_3d_acceleration_psatd_time_avg + +# test input parameters +amr.restart = "../test_3d_acceleration_psatd_time_avg/diags/chk000005" diff --git a/Examples/Tests/restart/inputs_test_3d_acceleration_restart b/Examples/Tests/restart/inputs_test_3d_acceleration_restart new file mode 100644 index 00000000000..320224f6c16 --- /dev/null +++ b/Examples/Tests/restart/inputs_test_3d_acceleration_restart @@ -0,0 +1,5 @@ +# base input parameters +FILE = inputs_test_3d_acceleration + +# test input parameters +amr.restart = "../test_3d_acceleration/diags/chk000005" diff --git a/Examples/Tests/restart_eb/CMakeLists.txt b/Examples/Tests/restart_eb/CMakeLists.txt new file mode 100644 index 00000000000..50f808c3e1f --- /dev/null +++ b/Examples/Tests/restart_eb/CMakeLists.txt @@ -0,0 +1,27 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_3d_eb_picmi # name + 3 # dims + 1 # nprocs + inputs_test_3d_eb_picmi.py # inputs + analysis_default_regression.py # analysis + diags/diag1000060 # output + OFF # dependency + ) +endif() + +# FIXME +#if(WarpX_EB) +# add_warpx_test( +# test_3d_eb_picmi_restart # name +# 3 # dims +# 1 # nprocs +## "inputs_test_3d_eb_picmi.py amr.restart='../test_3d_eb_picmi/diags/chk000030'" # inputs +# analysis_default_restart.py # analysis +# diags/diag1000060 # output +# test_3d_eb_picmi # dependency +# ) +#endif() diff --git a/Examples/Tests/restart_eb/analysis_default_regression.py b/Examples/Tests/restart_eb/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/restart_eb/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/restart_eb/analysis_default_restart.py b/Examples/Tests/restart_eb/analysis_default_restart.py new file mode 120000 index 00000000000..0459986eebc --- /dev/null +++ b/Examples/Tests/restart_eb/analysis_default_restart.py @@ -0,0 +1 @@ +../../analysis_default_restart.py \ No newline at end of file diff --git a/Examples/Tests/restart_eb/PICMI_inputs_restart_eb.py b/Examples/Tests/restart_eb/inputs_test_3d_eb_picmi.py similarity index 55% rename from Examples/Tests/restart_eb/PICMI_inputs_restart_eb.py rename to Examples/Tests/restart_eb/inputs_test_3d_eb_picmi.py index a4727053334..0f701ba999b 100755 --- a/Examples/Tests/restart_eb/PICMI_inputs_restart_eb.py +++ b/Examples/Tests/restart_eb/inputs_test_3d_eb_picmi.py @@ -34,16 +34,22 @@ ########################## uniform_plasma_elec = picmi.UniformDistribution( - density = 1e23, # number of electrons per m^3 - lower_bound = [-1e-5, -1e-5, -149e-6], - upper_bound = [1e-5, 1e-5, -129e-6], - directed_velocity = [0., 0., 2000.*picmi.constants.c] # uth the std of the (unitless) momentum + density=1e23, # number of electrons per m^3 + lower_bound=[-1e-5, -1e-5, -149e-6], + upper_bound=[1e-5, 1e-5, -129e-6], + directed_velocity=[ + 0.0, + 0.0, + 2000.0 * picmi.constants.c, + ], # uth the std of the (unitless) momentum ) electrons = picmi.Species( - particle_type='electron', name='electrons', + particle_type="electron", + name="electrons", initial_distribution=uniform_plasma_elec, - warpx_save_particles_at_xhi=1, warpx_save_particles_at_eb=1 + warpx_save_particles_at_xhi=1, + warpx_save_particles_at_eb=1, ) ########################## @@ -51,19 +57,17 @@ ########################## grid = picmi.Cartesian3DGrid( - number_of_cells = [nx, ny, nz], - lower_bound = [xmin, ymin, zmin], - upper_bound = [xmax, ymax, zmax], - lower_boundary_conditions=['none', 'none', 'none'], - upper_boundary_conditions=['none', 'none', 'none'], - lower_boundary_conditions_particles=['open', 'open', 'open'], - upper_boundary_conditions_particles=['open', 'open', 'open'], - warpx_max_grid_size = 32 + number_of_cells=[nx, ny, nz], + lower_bound=[xmin, ymin, zmin], + upper_bound=[xmax, ymax, zmax], + lower_boundary_conditions=["none", "none", "none"], + upper_boundary_conditions=["none", "none", "none"], + lower_boundary_conditions_particles=["open", "open", "open"], + upper_boundary_conditions_particles=["open", "open", "open"], + warpx_max_grid_size=32, ) -solver = picmi.ElectromagneticSolver( - grid=grid, cfl=cfl -) +solver = picmi.ElectromagneticSolver(grid=grid, cfl=cfl) embedded_boundary = picmi.EmbeddedBoundary( implicit_function="-max(max(max(x-12.5e-6,-12.5e-6-x),max(y-12.5e-6,-12.5e-6-y)),max(z-(-6.15e-5),-8.65e-5-z))" @@ -74,26 +78,19 @@ ########################## particle_diag = picmi.ParticleDiagnostic( - name = 'diag1', - period = diagnostic_intervals, - write_dir = '.', - warpx_file_prefix = 'Python_restart_eb_plt' + name="diag1", + period=diagnostic_intervals, ) field_diag = picmi.FieldDiagnostic( - name = 'diag1', - grid = grid, - period = diagnostic_intervals, - data_list = ['Ex', 'Ey', 'Ez', 'Bx', 'By', 'Bz'], - write_dir = '.', - warpx_file_prefix = 'Python_restart_eb_plt' + name="diag1", + grid=grid, + period=diagnostic_intervals, + data_list=["Ex", "Ey", "Ez", "Bx", "By", "Bz"], ) checkpoint = picmi.Checkpoint( - name = 'chkpoint', - period = diagnostic_intervals, - write_dir = '.', - warpx_file_min_digits = 5, - warpx_file_prefix = f'Python_restart_eb_chk' + name="chk", + period=diagnostic_intervals, ) ########################## @@ -101,19 +98,16 @@ ########################## sim = picmi.Simulation( - solver = solver, - max_steps = max_steps, + solver=solver, + max_steps=max_steps, warpx_embedded_boundary=embedded_boundary, verbose=True, warpx_load_balance_intervals=40, - warpx_load_balance_efficiency_ratio_threshold=0.9 + warpx_load_balance_efficiency_ratio_threshold=0.9, ) sim.add_species( - electrons, - layout = picmi.GriddedLayout( - n_macroparticle_per_cell=[1, 1, 1], grid=grid - ) + electrons, layout=picmi.GriddedLayout(n_macroparticle_per_cell=[1, 1, 1], grid=grid) ) for arg in sys.argv: diff --git a/Examples/Tests/rigid_injection/CMakeLists.txt b/Examples/Tests/rigid_injection/CMakeLists.txt new file mode 100644 index 00000000000..21004c3248c --- /dev/null +++ b/Examples/Tests/rigid_injection/CMakeLists.txt @@ -0,0 +1,22 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_rigid_injection_btd # name + 2 # dims + 2 # nprocs + inputs_test_2d_rigid_injection_btd # inputs + analysis_rigid_injection_btd.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_2d_rigid_injection_lab # name + 2 # dims + 2 # nprocs + inputs_test_2d_rigid_injection_lab # inputs + analysis_rigid_injection_lab.py # analysis + diags/diag1000289 # output + OFF # dependency +) diff --git a/Examples/Tests/rigid_injection/analysis_rigid_injection_BoostedFrame.py b/Examples/Tests/rigid_injection/analysis_rigid_injection_btd.py similarity index 52% rename from Examples/Tests/rigid_injection/analysis_rigid_injection_BoostedFrame.py rename to Examples/Tests/rigid_injection/analysis_rigid_injection_btd.py index fd51298816b..9b9054a4d42 100755 --- a/Examples/Tests/rigid_injection/analysis_rigid_injection_BoostedFrame.py +++ b/Examples/Tests/rigid_injection/analysis_rigid_injection_btd.py @@ -8,7 +8,7 @@ # License: BSD-3-Clause-LBNL -''' +""" Analysis script of a WarpX simulation of rigid injection in a boosted frame. A Gaussian electron beam starts from -5 microns, propagates rigidly up to @@ -18,7 +18,7 @@ The simulation runs in a boosted frame, and the analysis is done in the lab frame, i.e., on the back-transformed diagnostics. -''' +""" import os import sys @@ -29,7 +29,7 @@ yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] @@ -40,46 +40,46 @@ # Read data from new back-transformed diagnostics (plotfile) ds_plotfile = yt.load(filename) -x_plotfile = ds_plotfile.all_data()['beam', 'particle_position_x'].v -z_plotfile = ds_plotfile.all_data()['beam', 'particle_position_y'].v -ux_plotfile = ds_plotfile.all_data()['beam', 'particle_momentum_x'].v -uy_plotfile = ds_plotfile.all_data()['beam', 'particle_momentum_y'].v -uz_plotfile = ds_plotfile.all_data()['beam', 'particle_momentum_z'].v +x_plotfile = ds_plotfile.all_data()["beam", "particle_position_x"].v +z_plotfile = ds_plotfile.all_data()["beam", "particle_position_y"].v +ux_plotfile = ds_plotfile.all_data()["beam", "particle_momentum_x"].v +uy_plotfile = ds_plotfile.all_data()["beam", "particle_momentum_y"].v +uz_plotfile = ds_plotfile.all_data()["beam", "particle_momentum_z"].v # Read data from new back-transformed diagnostics (openPMD) series = io.Series("./diags/diag2/openpmd_%T.h5", io.Access.read_only) ds_openpmd = series.iterations[1] -x_openpmd = ds_openpmd.particles['beam']['position']['x'][:] -z_openpmd = ds_openpmd.particles['beam']['position']['z'][:] -ux_openpmd = ds_openpmd.particles['beam']['momentum']['x'][:] -uy_openpmd = ds_openpmd.particles['beam']['momentum']['y'][:] -uz_openpmd = ds_openpmd.particles['beam']['momentum']['z'][:] +x_openpmd = ds_openpmd.particles["beam"]["position"]["x"][:] +z_openpmd = ds_openpmd.particles["beam"]["position"]["z"][:] +ux_openpmd = ds_openpmd.particles["beam"]["momentum"]["x"][:] +uy_openpmd = ds_openpmd.particles["beam"]["momentum"]["y"][:] +uz_openpmd = ds_openpmd.particles["beam"]["momentum"]["z"][:] series.flush() # Sort and compare arrays to check consistency between plotfile BTD and openPMD BTD -assert(np.allclose(np.sort(x_plotfile), np.sort(x_openpmd), rtol=rtol, atol=atol)) -assert(np.allclose(np.sort(z_plotfile), np.sort(z_openpmd), rtol=rtol, atol=atol)) -assert(np.allclose(np.sort(ux_plotfile), np.sort(ux_openpmd), rtol=rtol, atol=atol)) -assert(np.allclose(np.sort(uy_plotfile), np.sort(uy_openpmd), rtol=rtol, atol=atol)) -assert(np.allclose(np.sort(uz_plotfile), np.sort(uz_openpmd), rtol=rtol, atol=atol)) +assert np.allclose(np.sort(x_plotfile), np.sort(x_openpmd), rtol=rtol, atol=atol) +assert np.allclose(np.sort(z_plotfile), np.sort(z_openpmd), rtol=rtol, atol=atol) +assert np.allclose(np.sort(ux_plotfile), np.sort(ux_openpmd), rtol=rtol, atol=atol) +assert np.allclose(np.sort(uy_plotfile), np.sort(uy_openpmd), rtol=rtol, atol=atol) +assert np.allclose(np.sort(uz_plotfile), np.sort(uz_openpmd), rtol=rtol, atol=atol) # Initial parameters -z0 = 20.e-6 -x0 = 1.e-6 +z0 = 20.0e-6 +x0 = 1.0e-6 theta0 = np.arcsin(0.1) # Theoretical beam width after propagation with rigid injection z = np.mean(z_plotfile) x = np.std(x_plotfile) -print(f'Beam position = {z}') -print(f'Beam width = {x}') +print(f"Beam position = {z}") +print(f"Beam width = {x}") -xth = np.sqrt(x0**2 + (z-z0)**2 * theta0**2) -err = np.abs((x-xth) / xth) +xth = np.sqrt(x0**2 + (z - z0) ** 2 * theta0**2) +err = np.abs((x - xth) / xth) tol = 1e-2 -print(f'error = {err}') -print(f'tolerance = {tol}') -assert(err < tol) +print(f"error = {err}") +print(f"tolerance = {tol}") +assert err < tol test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/rigid_injection/analysis_rigid_injection_LabFrame.py b/Examples/Tests/rigid_injection/analysis_rigid_injection_lab.py similarity index 69% rename from Examples/Tests/rigid_injection/analysis_rigid_injection_LabFrame.py rename to Examples/Tests/rigid_injection/analysis_rigid_injection_lab.py index ee88e32252d..94b2a1ac07e 100755 --- a/Examples/Tests/rigid_injection/analysis_rigid_injection_LabFrame.py +++ b/Examples/Tests/rigid_injection/analysis_rigid_injection_lab.py @@ -7,7 +7,7 @@ # License: BSD-3-Clause-LBNL -''' +""" Analysis script of a WarpX simulation of rigid injection. A Gaussian electron beam starts from -5 microns, propagates rigidly up to @@ -21,7 +21,7 @@ Additionally, this script tests that runtime attributes are correctly initialized with the gaussian_beam injection style. -''' +""" import os import sys @@ -30,53 +30,55 @@ import yt yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI filename = sys.argv[1] + # WarpX headers include more data when rigid injection is used, # which gives an error with the last yt release. # To avoid this issue, the three last lines of WarpXHeader are removed if # needed. def remove_rigid_lines(plotfile, nlines_if_rigid): - header_name = plotfile + '/WarpXHeader' - f = open(header_name, 'r') + header_name = plotfile + "/WarpXHeader" + f = open(header_name, "r") file_lines = f.readlines() nlines = len(file_lines) f.close() if nlines == nlines_if_rigid: - f = open(header_name, 'w') + f = open(header_name, "w") f.writelines(file_lines[:-3]) f.close() + # Remove rigid injection header lines remove_rigid_lines(filename, 18) # Read beam parameters -ds = yt.load( filename ) +ds = yt.load(filename) ad = ds.all_data() # Beam longitudinal position -z = np.mean(ad['beam', 'particle_position_y'].v) +z = np.mean(ad["beam", "particle_position_y"].v) # Beam width -w = np.std(ad['beam', 'particle_position_x'].v) +w = np.std(ad["beam", "particle_position_x"].v) # initial parameters -z0 = 20.e-6 -z0_no_rigid = -5.e-6 -w0 = 1.e-6 +z0 = 20.0e-6 +z0_no_rigid = -5.0e-6 +w0 = 1.0e-6 theta0 = np.arcsin(0.1) # Theoretical beam width after propagation if rigid OFF # Inform the user if rigid injection simply off (just to be kind) -wth_no_rigid = np.sqrt( w0**2 + (z-z0_no_rigid)**2*theta0**2 ) -error_no_rigid = np.abs((w-wth_no_rigid)/wth_no_rigid) -if ( error_no_rigid < 0.05): +wth_no_rigid = np.sqrt(w0**2 + (z - z0_no_rigid) ** 2 * theta0**2) +error_no_rigid = np.abs((w - wth_no_rigid) / wth_no_rigid) +if error_no_rigid < 0.05: print("error no rigid: " + str(error_no_rigid)) print("Looks like the beam defocuses as if rigid injection were OFF") # Theoretical beam width after propagation if rigid ON -wth = np.sqrt( w0**2 + (z-z0)**2*theta0**2 ) -error_rel = np.abs((w-wth)/wth) +wth = np.sqrt(w0**2 + (z - z0) ** 2 * theta0**2) +error_rel = np.abs((w - wth) / wth) tolerance_rel = 0.05 # Print error and assert small error @@ -86,19 +88,19 @@ def remove_rigid_lines(plotfile, nlines_if_rigid): print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel ### Check that user runtime attributes are correctly initialized -filename_start = filename[:-5] + '00000' -ds_start = yt.load( filename_start ) +filename_start = filename[:-5] + "00000" +ds_start = yt.load(filename_start) ad_start = ds_start.all_data() -x = ad_start['beam', 'particle_position_x'] -z = ad_start['beam', 'particle_position_y'] -orig_z = ad_start['beam', 'particle_orig_z'] -center = ad_start['beam', 'particle_center'] -assert(np.array_equal(z, orig_z)) -assert(np.array_equal(1*(np.abs(x) < 5.e-7), center)) +x = ad_start["beam", "particle_position_x"] +z = ad_start["beam", "particle_position_y"] +orig_z = ad_start["beam", "particle_orig_z"] +center = ad_start["beam", "particle_center"] +assert np.array_equal(z, orig_z) +assert np.array_equal(1 * (np.abs(x) < 5.0e-7), center) test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/rigid_injection/inputs_2d_BoostedFrame b/Examples/Tests/rigid_injection/inputs_test_2d_rigid_injection_btd similarity index 100% rename from Examples/Tests/rigid_injection/inputs_2d_BoostedFrame rename to Examples/Tests/rigid_injection/inputs_test_2d_rigid_injection_btd diff --git a/Examples/Tests/rigid_injection/inputs_2d_LabFrame b/Examples/Tests/rigid_injection/inputs_test_2d_rigid_injection_lab similarity index 100% rename from Examples/Tests/rigid_injection/inputs_2d_LabFrame rename to Examples/Tests/rigid_injection/inputs_test_2d_rigid_injection_lab diff --git a/Examples/Tests/scraping/CMakeLists.txt b/Examples/Tests/scraping/CMakeLists.txt new file mode 100644 index 00000000000..a0fd04b6b3f --- /dev/null +++ b/Examples/Tests/scraping/CMakeLists.txt @@ -0,0 +1,26 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_EB) + add_warpx_test( + test_rz_scraping # name + RZ # dims + 2 # nprocs + inputs_test_rz_scraping # inputs + analysis_rz.py # analysis + diags/diag1000037 # output + OFF # dependency + ) +endif() + +if(WarpX_EB) + add_warpx_test( + test_rz_scraping_filter # name + RZ # dims + 2 # nprocs + inputs_test_rz_scraping_filter # inputs + analysis_rz_filter.py # analysis + diags/diag1000037 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/scraping/analysis_rz.py b/Examples/Tests/scraping/analysis_rz.py index 11d0194707f..8bf86e320f3 100755 --- a/Examples/Tests/scraping/analysis_rz.py +++ b/Examples/Tests/scraping/analysis_rz.py @@ -27,46 +27,61 @@ import yt from openpmd_viewer import OpenPMDTimeSeries -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI tolerance = 0 fn = sys.argv[1] -ds = yt.load( fn ) +ds = yt.load(fn) ad = ds.all_data() -x = ad['electron', 'particle_position_x'].v +x = ad["electron", "particle_position_x"].v -error = len(x)-512 -print('error = ', error) -print('tolerance = ', tolerance) -assert(error==tolerance) +error = len(x) - 512 +print("error = ", error) +print("tolerance = ", tolerance) +assert error == tolerance # Check that all the removed particles are properly recorded # by making sure that, at each iteration, the sum of the number of # remaining particles and scraped particles is equal to the # original number of particles -ts_full = OpenPMDTimeSeries('./diags/diag2/') -ts_scraping = OpenPMDTimeSeries('./diags/diag3/particles_at_eb') +ts_full = OpenPMDTimeSeries("./diags/diag2/") +ts_scraping = OpenPMDTimeSeries("./diags/diag3/particles_at_eb") -def n_remaining_particles( iteration ): - w, = ts_full.get_particle(['w'], iteration=iteration) + +def n_remaining_particles(iteration): + (w,) = ts_full.get_particle(["w"], iteration=iteration) return len(w) -def n_scraped_particles( iteration ): - step_scraped = ts_scraping.get_particle( ['stepScraped'], iteration=ts_scraping.iterations[0] ) + + +def n_scraped_particles(iteration): + step_scraped = ts_scraping.get_particle( + ["stepScraped"], iteration=ts_scraping.iterations[0] + ) return (step_scraped <= iteration).sum() -n_remaining = np.array([ n_remaining_particles(iteration) for iteration in ts_full.iterations ]) -n_scraped = np.array([ n_scraped_particles(iteration) for iteration in ts_full.iterations ]) + + +n_remaining = np.array( + [n_remaining_particles(iteration) for iteration in ts_full.iterations] +) +n_scraped = np.array( + [n_scraped_particles(iteration) for iteration in ts_full.iterations] +) n_total = n_remaining[0] -assert np.all( n_scraped+n_remaining == n_total) +assert np.all(n_scraped + n_remaining == n_total) # Check that the particle IDs match between the initial iteration # (all particles in the simulation domain) and the finall iteration (particles are either scraped or still in simulation box) -id_initial, = ts_full.get_particle(['id'], iteration=0) -id_final_scrape, = ts_scraping.get_particle(['id'], iteration=ts_scraping.iterations[0]) -id_final_box, = ts_full.get_particle(['id'], iteration=ts_full.iterations[-1]) -id_final = np.concatenate( (id_final_scrape, id_final_box)) -assert np.all( np.sort(id_initial) == np.sort(id_final) ) # Sort because particles may not be in the same order +(id_initial,) = ts_full.get_particle(["id"], iteration=0) +(id_final_scrape,) = ts_scraping.get_particle( + ["id"], iteration=ts_scraping.iterations[0] +) +(id_final_box,) = ts_full.get_particle(["id"], iteration=ts_full.iterations[-1]) +id_final = np.concatenate((id_final_scrape, id_final_box)) +assert np.all( + np.sort(id_initial) == np.sort(id_final) +) # Sort because particles may not be in the same order # Checksum test test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/scraping/analysis_rz_filter.py b/Examples/Tests/scraping/analysis_rz_filter.py index a4e0dafddbc..498f25e8422 100755 --- a/Examples/Tests/scraping/analysis_rz_filter.py +++ b/Examples/Tests/scraping/analysis_rz_filter.py @@ -29,35 +29,50 @@ tolerance = 0 fn = sys.argv[1] -ds = yt.load( fn ) +ds = yt.load(fn) ad = ds.all_data() -x = ad['electron', 'particle_position_x'].v +x = ad["electron", "particle_position_x"].v -error = len(x)-512 -print('error = ', error) -print('tolerance = ', tolerance) -assert(error==tolerance) +error = len(x) - 512 +print("error = ", error) +print("tolerance = ", tolerance) +assert error == tolerance # Check that all the removed particles are properly recorded # by making sure that, at each iteration, the sum of the number of # remaining particles and scraped particles is equal to half the # original number of particles # also check that no particles with z <= 0 have been scraped -ts_full = OpenPMDTimeSeries('./diags/diag2/') -ts_scraping = OpenPMDTimeSeries('./diags/diag3/particles_at_eb') +ts_full = OpenPMDTimeSeries("./diags/diag2/") +ts_scraping = OpenPMDTimeSeries("./diags/diag3/particles_at_eb") -def n_remaining_particles( iteration ): - w, = ts_full.get_particle(['w'], iteration=iteration) + +def n_remaining_particles(iteration): + (w,) = ts_full.get_particle(["w"], iteration=iteration) return len(w) -def n_scraped_particles( iteration ): - step_scraped = ts_scraping.get_particle( ['stepScraped'], iteration=ts_scraping.iterations[0] ) + + +def n_scraped_particles(iteration): + step_scraped = ts_scraping.get_particle( + ["stepScraped"], iteration=ts_scraping.iterations[0] + ) return (step_scraped <= iteration).sum() -def n_scraped_z_leq_zero( iteration ): - z_pos, = ts_scraping.get_particle( ['z'], iteration=ts_scraping.iterations[0] ) + + +def n_scraped_z_leq_zero(iteration): + (z_pos,) = ts_scraping.get_particle(["z"], iteration=ts_scraping.iterations[0]) return (z_pos <= 0).sum() -n_remaining = np.array([ n_remaining_particles(iteration) for iteration in ts_full.iterations ]) -n_scraped = np.array([ n_scraped_particles(iteration) for iteration in ts_full.iterations ]) -n_z_leq_zero = np.array([ n_scraped_z_leq_zero(iteration) for iteration in ts_full.iterations ]) + + +n_remaining = np.array( + [n_remaining_particles(iteration) for iteration in ts_full.iterations] +) +n_scraped = np.array( + [n_scraped_particles(iteration) for iteration in ts_full.iterations] +) +n_z_leq_zero = np.array( + [n_scraped_z_leq_zero(iteration) for iteration in ts_full.iterations] +) n_total = n_remaining[0] -assert np.all( 2*n_scraped+n_remaining == n_total) -assert np.all( n_z_leq_zero == 0) +assert np.all(2 * n_scraped + n_remaining == n_total) +assert np.all(n_z_leq_zero == 0) diff --git a/Examples/Tests/scraping/inputs_rz b/Examples/Tests/scraping/inputs_test_rz_scraping similarity index 97% rename from Examples/Tests/scraping/inputs_rz rename to Examples/Tests/scraping/inputs_test_rz_scraping index 0dab9ebedd2..b332de2229a 100644 --- a/Examples/Tests/scraping/inputs_rz +++ b/Examples/Tests/scraping/inputs_test_rz_scraping @@ -21,6 +21,7 @@ boundary.potential_hi_y = 0 boundary.potential_lo_z = 0 boundary.potential_hi_z = 0 +warpx.abort_on_warning_threshold = medium warpx.const_dt = 1.216119097e-11 warpx.eb_implicit_function = "-(x**2-0.1**2)" diff --git a/Examples/Tests/scraping/inputs_rz_filter b/Examples/Tests/scraping/inputs_test_rz_scraping_filter similarity index 97% rename from Examples/Tests/scraping/inputs_rz_filter rename to Examples/Tests/scraping/inputs_test_rz_scraping_filter index 0d67fb96f6c..3a3ab78a226 100644 --- a/Examples/Tests/scraping/inputs_rz_filter +++ b/Examples/Tests/scraping/inputs_test_rz_scraping_filter @@ -21,6 +21,7 @@ boundary.potential_hi_y = 0 boundary.potential_lo_z = 0 boundary.potential_hi_z = 0 +warpx.abort_on_warning_threshold = medium warpx.const_dt = 1.216119097e-11 warpx.eb_implicit_function = "-(x**2-0.1**2)" diff --git a/Examples/Tests/silver_mueller/CMakeLists.txt b/Examples/Tests/silver_mueller/CMakeLists.txt new file mode 100644 index 00000000000..7866d23dc1f --- /dev/null +++ b/Examples/Tests/silver_mueller/CMakeLists.txt @@ -0,0 +1,42 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_1d_silver_mueller # name + 1 # dims + 2 # nprocs + inputs_test_1d_silver_mueller # inputs + analysis.py # analysis + diags/diag1000500 # output + OFF # dependency +) + +add_warpx_test( + test_2d_silver_mueller_x # name + 2 # dims + 2 # nprocs + inputs_test_2d_silver_mueller_x # inputs + analysis.py # analysis + diags/diag1000500 # output + OFF # dependency +) + +add_warpx_test( + test_2d_silver_mueller_z # name + 2 # dims + 2 # nprocs + inputs_test_2d_silver_mueller_z # inputs + analysis.py # analysis + diags/diag1000500 # output + OFF # dependency +) + +add_warpx_test( + test_rz_silver_mueller_z # name + RZ # dims + 2 # nprocs + inputs_test_rz_silver_mueller_z # inputs + analysis.py # analysis + diags/diag1000500 # output + OFF # dependency +) diff --git a/Examples/Tests/silver_mueller/analysis.py b/Examples/Tests/silver_mueller/analysis.py new file mode 100755 index 00000000000..e1de7199aa0 --- /dev/null +++ b/Examples/Tests/silver_mueller/analysis.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +# Copyright 2021 +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL +""" +This tests verifies the Silver-Mueller boundary condition. +A laser pulse is emitted and propagates towards the boundaries ; the +test check that the reflected field at the boundary is negligible. +""" + +import os +import re +import sys + +import numpy as np +import yt + +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + +filename = sys.argv[1] + +ds = yt.load(filename) +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +warpx_used_inputs = open("./warpx_used_inputs", "r").read() +geom_RZ = re.search("geometry.dims = RZ", warpx_used_inputs) +if geom_RZ: + Er = all_data_level_0["boxlib", "Er"].v.squeeze() + Et = all_data_level_0["boxlib", "Et"].v.squeeze() + Ez = all_data_level_0["boxlib", "Ez"].v.squeeze() +else: + Ex = all_data_level_0["boxlib", "Ex"].v.squeeze() + Ey = all_data_level_0["boxlib", "Ey"].v.squeeze() + Ez = all_data_level_0["boxlib", "Ez"].v.squeeze() +# The peak of the initial laser pulse is on the order of 6 V/m +# Check that the amplitude after reflection is less than 0.01 V/m +max_reflection_amplitude = 0.01 + +if geom_RZ: + assert np.all(abs(Er) < max_reflection_amplitude) + assert np.all(abs(Et) < max_reflection_amplitude) + assert np.all(abs(Ez) < max_reflection_amplitude) +else: + assert np.all(abs(Ex) < max_reflection_amplitude) + assert np.all(abs(Ey) < max_reflection_amplitude) + assert np.all(abs(Ez) < max_reflection_amplitude) + +test_name = os.path.split(os.getcwd())[1] +checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/silver_mueller/analysis_silver_mueller.py b/Examples/Tests/silver_mueller/analysis_silver_mueller.py deleted file mode 100755 index bfab40aa991..00000000000 --- a/Examples/Tests/silver_mueller/analysis_silver_mueller.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2021 -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL -""" -This tests verifies the Silver-Mueller boundary condition. -A laser pulse is emitted and propagates towards the boundaries ; the -test check that the reflected field at the boundary is negligible. -""" - -import os -import re -import sys - -import numpy as np - -import yt ; yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') -import checksumAPI - -filename = sys.argv[1] - -ds = yt.load( filename ) -all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -warpx_used_inputs = open('./warpx_used_inputs', 'r').read() -geom_RZ = re.search('geometry.dims = RZ', warpx_used_inputs) -if geom_RZ: - Er = all_data_level_0['boxlib', 'Er'].v.squeeze() - Et = all_data_level_0['boxlib', 'Et'].v.squeeze() - Ez = all_data_level_0['boxlib', 'Ez'].v.squeeze() -else: - Ex = all_data_level_0['boxlib', 'Ex'].v.squeeze() - Ey = all_data_level_0['boxlib', 'Ey'].v.squeeze() - Ez = all_data_level_0['boxlib', 'Ez'].v.squeeze() -# The peak of the initial laser pulse is on the order of 6 V/m -# Check that the amplitude after reflection is less than 0.01 V/m -max_reflection_amplitude = 0.01 - -if geom_RZ: - assert np.all( abs(Er) < max_reflection_amplitude ) - assert np.all( abs(Et) < max_reflection_amplitude ) - assert np.all( abs(Ez) < max_reflection_amplitude ) -else: - assert np.all( abs(Ex) < max_reflection_amplitude ) - assert np.all( abs(Ey) < max_reflection_amplitude ) - assert np.all( abs(Ez) < max_reflection_amplitude ) - -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/silver_mueller/inputs_1d b/Examples/Tests/silver_mueller/inputs_test_1d_silver_mueller similarity index 100% rename from Examples/Tests/silver_mueller/inputs_1d rename to Examples/Tests/silver_mueller/inputs_test_1d_silver_mueller diff --git a/Examples/Tests/silver_mueller/inputs_2d_x b/Examples/Tests/silver_mueller/inputs_test_2d_silver_mueller_x similarity index 100% rename from Examples/Tests/silver_mueller/inputs_2d_x rename to Examples/Tests/silver_mueller/inputs_test_2d_silver_mueller_x diff --git a/Examples/Tests/silver_mueller/inputs_2d_z b/Examples/Tests/silver_mueller/inputs_test_2d_silver_mueller_z similarity index 100% rename from Examples/Tests/silver_mueller/inputs_2d_z rename to Examples/Tests/silver_mueller/inputs_test_2d_silver_mueller_z diff --git a/Examples/Tests/silver_mueller/inputs_rz_z b/Examples/Tests/silver_mueller/inputs_test_rz_silver_mueller_z similarity index 100% rename from Examples/Tests/silver_mueller/inputs_rz_z rename to Examples/Tests/silver_mueller/inputs_test_rz_silver_mueller_z diff --git a/Examples/Tests/single_particle/CMakeLists.txt b/Examples/Tests/single_particle/CMakeLists.txt new file mode 100644 index 00000000000..bee870f0b17 --- /dev/null +++ b/Examples/Tests/single_particle/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_bilinear_filter # name + 2 # dims + 2 # nprocs + inputs_test_2d_bilinear_filter # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/single_particle/analysis_bilinear_filter.py b/Examples/Tests/single_particle/analysis.py similarity index 53% rename from Examples/Tests/single_particle/analysis_bilinear_filter.py rename to Examples/Tests/single_particle/analysis.py index db7250dc3bb..198d84c6bfd 100755 --- a/Examples/Tests/single_particle/analysis_bilinear_filter.py +++ b/Examples/Tests/single_particle/analysis.py @@ -11,10 +11,11 @@ import sys import numpy as np +import yt from scipy import signal -import yt ; yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +yt.funcs.mylog.setLevel(0) +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Build Jx without filter. This can be obtained by running this test without @@ -25,41 +26,45 @@ # > OMP_NUM_THREADS=2 mpirun -np 2 ~/warpx/Bin/main2d.gnu.TPROF.MPI.OMP.ex \ # inputs warpx.use_filter=1 warpx.filter_npass_each_dir=1 5 # and then print the values in the array F_filtered below. -my_F_nofilter = np.zeros([16,16]) -my_F_nofilter[8,8] = -1.601068237523421e-11 -my_F_nofilter[8,7] = -1.601068237523421e-11 +my_F_nofilter = np.zeros([16, 16]) +my_F_nofilter[8, 8] = -1.601068237523421e-11 +my_F_nofilter[8, 7] = -1.601068237523421e-11 # Build 2D filter -filter0 = np.array([.25,.5,.25]) -my_order = [1,5] +filter0 = np.array([0.25, 0.5, 0.25]) +my_order = [1, 5] my_filterx = filter0 my_filtery = filter0 -while my_order[0]>1: - my_filterx = np.convolve(my_filterx,filter0) +while my_order[0] > 1: + my_filterx = np.convolve(my_filterx, filter0) my_order[0] -= 1 -while my_order[1]>1: - my_filtery = np.convolve(my_filtery,filter0) +while my_order[1] > 1: + my_filtery = np.convolve(my_filtery, filter0) my_order[1] -= 1 -my_filter = my_filterx[:,None]*my_filtery +my_filter = my_filterx[:, None] * my_filtery # Apply filter. my_F_filtered is the theoretical value for filtered field -my_F_filtered = signal.convolve2d(my_F_nofilter, my_filter, boundary='symm', mode='same') +my_F_filtered = signal.convolve2d( + my_F_nofilter, my_filter, boundary="symm", mode="same" +) # Get simulation result for F_filtered filename = sys.argv[1] -ds = yt.load( filename ) -sl = yt.SlicePlot(ds, 2, 'jx', aspect=1) -all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -F_filtered = all_data_level_0['boxlib', 'jx'].v.squeeze() +ds = yt.load(filename) +sl = yt.SlicePlot(ds, 2, "jx", aspect=1) +all_data_level_0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +F_filtered = all_data_level_0["boxlib", "jx"].v.squeeze() # Compare theory and PIC for filtered value -error_rel = np.sum( np.abs(F_filtered - my_F_filtered) ) / np.sum( np.abs(my_F_filtered) ) -tolerance_rel = 1.e-14 +error_rel = np.sum(np.abs(F_filtered - my_F_filtered)) / np.sum(np.abs(my_F_filtered)) +tolerance_rel = 1.0e-14 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) -assert( error_rel < tolerance_rel ) +assert error_rel < tolerance_rel test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename) diff --git a/Examples/Tests/single_particle/inputs_2d b/Examples/Tests/single_particle/inputs_test_2d_bilinear_filter similarity index 93% rename from Examples/Tests/single_particle/inputs_2d rename to Examples/Tests/single_particle/inputs_test_2d_bilinear_filter index 71ca2101c22..6f8eb6fdcea 100644 --- a/Examples/Tests/single_particle/inputs_2d +++ b/Examples/Tests/single_particle/inputs_test_2d_bilinear_filter @@ -14,6 +14,8 @@ boundary.field_hi = pec pec algo.charge_deposition = standard algo.field_gathering = energy-conserving warpx.cfl = 1.0 +warpx.use_filter = 1 +warpx.filter_npass_each_dir = 1 5 # Order of particle shape factors algo.particle_shape = 1 diff --git a/Examples/Tests/space_charge_initialization/CMakeLists.txt b/Examples/Tests/space_charge_initialization/CMakeLists.txt new file mode 100644 index 00000000000..6ca1f4ad04c --- /dev/null +++ b/Examples/Tests/space_charge_initialization/CMakeLists.txt @@ -0,0 +1,22 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_space_charge_initialization # name + 2 # dims + 2 # nprocs + inputs_test_2d_space_charge_initialization # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency +) + +add_warpx_test( + test_3d_space_charge_initialization # name + 3 # dims + 2 # nprocs + inputs_test_3d_space_charge_initialization # inputs + analysis.py # analysis + diags/diag1000001 # output + OFF # dependency +) diff --git a/Examples/Tests/space_charge_initialization/analysis.py b/Examples/Tests/space_charge_initialization/analysis.py index 48e19ea0b75..1d5c8b9cb78 100755 --- a/Examples/Tests/space_charge_initialization/analysis.py +++ b/Examples/Tests/space_charge_initialization/analysis.py @@ -11,12 +11,13 @@ verifying that the space-charge field of a Gaussian beam corresponds to the expected theoretical field. """ + import os import sys import matplotlib -matplotlib.use('Agg') +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np import scipy.constants as scc @@ -24,23 +25,26 @@ from scipy.special import gammainc yt.funcs.mylog.setLevel(0) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Parameters from the Simulation -Qtot = -1.e-20 -r0 = 2.e-6 +Qtot = -1.0e-20 +r0 = 2.0e-6 # Open data file filename = sys.argv[1] -ds = yt.load( filename ) +ds = yt.load(filename) # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. -if 'force_periodicity' in dir(ds): ds.force_periodicity() +if "force_periodicity" in dir(ds): + ds.force_periodicity() # Extract data -ad0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) +ad0 = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) Ex_array = ad0[("mesh", "Ex")].to_ndarray().squeeze() if ds.dimensionality == 2: # Rename the z dimension as y, so as to make this script work for 2d and 3d @@ -50,65 +54,75 @@ Ez_array = ad0[("mesh", "Ez")].to_ndarray() # Extract grid coordinates -Nx, Ny, Nz = ds.domain_dimensions +Nx, Ny, Nz = ds.domain_dimensions xmin, ymin, zmin = ds.domain_left_edge.v Lx, Ly, Lz = ds.domain_width.v -x = xmin + Lx/Nx*(0.5+np.arange(Nx)) -y = ymin + Ly/Ny*(0.5+np.arange(Ny)) -z = zmin + Lz/Nz*(0.5+np.arange(Nz)) +x = xmin + Lx / Nx * (0.5 + np.arange(Nx)) +y = ymin + Ly / Ny * (0.5 + np.arange(Ny)) +z = zmin + Lz / Nz * (0.5 + np.arange(Nz)) # Compute theoretical field if ds.dimensionality == 2: - x_2d, y_2d = np.meshgrid(x, y, indexing='ij') + x_2d, y_2d = np.meshgrid(x, y, indexing="ij") r2 = x_2d**2 + y_2d**2 - factor = (Qtot/r0)/(2*np.pi*scc.epsilon_0*r2) * (1-np.exp(-r2/(2*r0**2))) + factor = ( + (Qtot / r0) / (2 * np.pi * scc.epsilon_0 * r2) * (1 - np.exp(-r2 / (2 * r0**2))) + ) Ex_th = x_2d * factor Ey_th = y_2d * factor elif ds.dimensionality == 3: - x_2d, y_2d, z_2d = np.meshgrid(x, y, z, indexing='ij') + x_2d, y_2d, z_2d = np.meshgrid(x, y, z, indexing="ij") r2 = x_2d**2 + y_2d**2 + z_2d**2 - factor = Qtot/(4*np.pi*scc.epsilon_0*r2**1.5) * gammainc(3./2, r2/(2.*r0**2)) - Ex_th = factor*x_2d - Ey_th = factor*y_2d - Ez_th = factor*z_2d + factor = ( + Qtot + / (4 * np.pi * scc.epsilon_0 * r2**1.5) + * gammainc(3.0 / 2, r2 / (2.0 * r0**2)) + ) + Ex_th = factor * x_2d + Ey_th = factor * y_2d + Ez_th = factor * z_2d + # Plot theory and data def make_2d(arr): if arr.ndim == 3: - return arr[:,:,Nz//2] + return arr[:, :, Nz // 2] else: return arr -plt.figure(figsize=(10,10)) + + +plt.figure(figsize=(10, 10)) plt.subplot(221) -plt.title('Ex: Theory') +plt.title("Ex: Theory") plt.imshow(make_2d(Ex_th)) plt.colorbar() plt.subplot(222) -plt.title('Ex: Simulation') +plt.title("Ex: Simulation") plt.imshow(make_2d(Ex_array)) plt.colorbar() plt.subplot(223) -plt.title('Ey: Theory') +plt.title("Ey: Theory") plt.imshow(make_2d(Ey_th)) plt.colorbar() plt.subplot(224) -plt.title('Ey: Simulation') +plt.title("Ey: Simulation") plt.imshow(make_2d(Ey_array)) plt.colorbar() -plt.savefig('Comparison.png') +plt.savefig("Comparison.png") + # Automatically check the results def check(E, E_th, label): - print( 'Relative error in %s: %.3f'%( - label, abs(E-E_th).max()/E_th.max())) + print("Relative error in %s: %.3f" % (label, abs(E - E_th).max() / E_th.max())) tolerance_rel = 0.165 print("tolerance_rel: " + str(tolerance_rel)) - assert np.allclose( E, E_th, atol=tolerance_rel*E_th.max() ) + assert np.allclose(E, E_th, atol=tolerance_rel * E_th.max()) + -check( Ex_array, Ex_th, 'Ex' ) -check( Ey_array, Ey_th, 'Ey' ) +check(Ex_array, Ex_th, "Ex") +check(Ey_array, Ey_th, "Ey") if ds.dimensionality == 3: - check( Ez_array, Ez_th, 'Ez' ) + check(Ez_array, Ez_th, "Ez") test_name = os.path.split(os.getcwd())[1] checksumAPI.evaluate_checksum(test_name, filename, do_particles=0) diff --git a/Examples/Tests/space_charge_initialization/inputs_test_2d_space_charge_initialization b/Examples/Tests/space_charge_initialization/inputs_test_2d_space_charge_initialization new file mode 100644 index 00000000000..4445217225c --- /dev/null +++ b/Examples/Tests/space_charge_initialization/inputs_test_2d_space_charge_initialization @@ -0,0 +1,37 @@ +max_step = 1 +amr.n_cell = 128 128 +amr.max_grid_size = 32 +amr.max_level = 0 + +geometry.dims = 3 +boundary.field_lo = pec pec +boundary.field_hi = pec pec +geometry.prob_lo = -50.e-6 -50.e-6 +geometry.prob_hi = 50.e-6 50.e-6 +geometry.dims = 2 + +warpx.cfl = 1.e-3 + +# Order of particle shape factors +algo.particle_shape = 1 + +particles.species_names = beam +beam.charge = -q_e +beam.mass = m_e +beam.injection_style = "gaussian_beam" +beam.initialize_self_fields = 1 +beam.x_rms = 2.e-6 +beam.y_rms = 2.e-6 +beam.z_rms = 2.e-6 +beam.x_m = 0. +beam.y_m = 0. +beam.z_m = 0.e-6 +beam.npart = 20000 +beam.q_tot = -1.e-20 +beam.momentum_distribution_type = "at_rest" + +# Diagnostics +diagnostics.diags_names = diag1 +diag1.intervals = 1 +diag1.diag_type = Full +diag1.fields_to_plot = Ex Ey Ez jx jy jz diff --git a/Examples/Tests/space_charge_initialization/inputs_3d b/Examples/Tests/space_charge_initialization/inputs_test_3d_space_charge_initialization similarity index 97% rename from Examples/Tests/space_charge_initialization/inputs_3d rename to Examples/Tests/space_charge_initialization/inputs_test_3d_space_charge_initialization index c8058fac519..d7a9f42fa70 100644 --- a/Examples/Tests/space_charge_initialization/inputs_3d +++ b/Examples/Tests/space_charge_initialization/inputs_test_3d_space_charge_initialization @@ -8,6 +8,7 @@ boundary.field_lo = pec pec pec boundary.field_hi = pec pec pec geometry.prob_lo = -50.e-6 -50.e-6 -50.e-6 geometry.prob_hi = 50.e-6 50.e-6 50.e-6 +geometry.dims = 3 warpx.cfl = 1.e-3 diff --git a/Examples/Tests/subcycling/CMakeLists.txt b/Examples/Tests/subcycling/CMakeLists.txt new file mode 100644 index 00000000000..688f54ac01c --- /dev/null +++ b/Examples/Tests/subcycling/CMakeLists.txt @@ -0,0 +1,12 @@ +# Add tests (alphabetical order) ############################################## +# + +add_warpx_test( + test_2d_subcycling_mr # name + 2 # dims + 2 # nprocs + inputs_test_2d_subcycling_mr # inputs + analysis_default_regression.py # analysis + diags/diag1000250 # output + OFF # dependency +) diff --git a/Examples/Tests/subcycling/analysis_default_regression.py b/Examples/Tests/subcycling/analysis_default_regression.py new file mode 120000 index 00000000000..d8ce3fca419 --- /dev/null +++ b/Examples/Tests/subcycling/analysis_default_regression.py @@ -0,0 +1 @@ +../../analysis_default_regression.py \ No newline at end of file diff --git a/Examples/Tests/subcycling/inputs_2d b/Examples/Tests/subcycling/inputs_test_2d_subcycling_mr similarity index 100% rename from Examples/Tests/subcycling/inputs_2d rename to Examples/Tests/subcycling/inputs_test_2d_subcycling_mr diff --git a/Examples/Tests/vay_deposition/CMakeLists.txt b/Examples/Tests/vay_deposition/CMakeLists.txt new file mode 100644 index 00000000000..ce8d51d3c2a --- /dev/null +++ b/Examples/Tests/vay_deposition/CMakeLists.txt @@ -0,0 +1,26 @@ +# Add tests (alphabetical order) ############################################## +# + +if(WarpX_FFT) + add_warpx_test( + test_2d_vay_deposition # name + 2 # dims + 2 # nprocs + inputs_test_2d_vay_deposition # inputs + analysis.py # analysis + diags/diag1000050 # output + OFF # dependency + ) +endif() + +if(WarpX_FFT) + add_warpx_test( + test_3d_vay_deposition # name + 3 # dims + 2 # nprocs + inputs_test_3d_vay_deposition # inputs + analysis.py # analysis + diags/diag1000025 # output + OFF # dependency + ) +endif() diff --git a/Examples/Tests/vay_deposition/analysis.py b/Examples/Tests/vay_deposition/analysis.py index cfd089f2112..82776c34c42 100755 --- a/Examples/Tests/vay_deposition/analysis.py +++ b/Examples/Tests/vay_deposition/analysis.py @@ -15,7 +15,7 @@ yt.funcs.mylog.setLevel(50) -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # Plotfile data set @@ -24,17 +24,16 @@ # Check relative L-infinity spatial norm of rho/epsilon_0 - div(E) data = ds.covering_grid( - level=0, - left_edge=ds.domain_left_edge, - dims=ds.domain_dimensions) -rho = data[('boxlib','rho')].to_ndarray() -divE = data[('boxlib','divE')].to_ndarray() -error_rel = np.amax(np.abs(divE-rho/epsilon_0))/np.amax(np.abs(rho/epsilon_0)) + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions +) +rho = data[("boxlib", "rho")].to_ndarray() +divE = data[("boxlib", "divE")].to_ndarray() +error_rel = np.amax(np.abs(divE - rho / epsilon_0)) / np.amax(np.abs(rho / epsilon_0)) tolerance = 1e-3 print("Error on charge conservation:") print("error_rel = {}".format(error_rel)) print("tolerance = {}".format(tolerance)) -assert( error_rel < tolerance ) +assert error_rel < tolerance # Checksum analysis test_name = os.path.split(os.getcwd())[1] diff --git a/Examples/Tests/vay_deposition/inputs_2d b/Examples/Tests/vay_deposition/inputs_test_2d_vay_deposition similarity index 100% rename from Examples/Tests/vay_deposition/inputs_2d rename to Examples/Tests/vay_deposition/inputs_test_2d_vay_deposition diff --git a/Examples/Tests/vay_deposition/inputs_3d b/Examples/Tests/vay_deposition/inputs_test_3d_vay_deposition similarity index 100% rename from Examples/Tests/vay_deposition/inputs_3d rename to Examples/Tests/vay_deposition/inputs_test_3d_vay_deposition diff --git a/Examples/analysis_default_openpmd_regression.py b/Examples/analysis_default_openpmd_regression.py index 3aadc49ac51..03a0f1ede1f 100755 --- a/Examples/analysis_default_openpmd_regression.py +++ b/Examples/analysis_default_openpmd_regression.py @@ -4,7 +4,7 @@ import re import sys -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -14,7 +14,7 @@ test_name = os.path.split(os.getcwd())[1] # Run checksum regression test -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, output_format='openpmd', rtol=2.e-6) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, output_format="openpmd", rtol=2.0e-6) else: - checksumAPI.evaluate_checksum(test_name, fn, output_format='openpmd') + checksumAPI.evaluate_checksum(test_name, fn, output_format="openpmd") diff --git a/Examples/analysis_default_regression.py b/Examples/analysis_default_regression.py index 453f650be01..519bbeeea64 100755 --- a/Examples/analysis_default_regression.py +++ b/Examples/analysis_default_regression.py @@ -4,7 +4,7 @@ import re import sys -sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") import checksumAPI # this will be the name of the plot file @@ -14,7 +14,8 @@ test_name = os.path.split(os.getcwd())[1] # Run checksum regression test -if re.search( 'single_precision', fn ): - checksumAPI.evaluate_checksum(test_name, fn, rtol=2.e-6) +if re.search("single_precision", fn): + checksumAPI.evaluate_checksum(test_name, fn, rtol=2.0e-6) else: + # using default relative tolerance checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/analysis_default_restart.py b/Examples/analysis_default_restart.py index 612851678fd..55bab253dbc 100755 --- a/Examples/analysis_default_restart.py +++ b/Examples/analysis_default_restart.py @@ -1,10 +1,16 @@ #!/usr/bin/env python3 +import os +import sys + import numpy as np import yt +sys.path.insert(1, "../../../../warpx/Regression/Checksum/") +import checksumAPI + -def check_restart(filename, tolerance = 1e-12): +def check_restart(filename, tolerance=1e-12): """ Compare output data generated from initial run with output data generated after restart. @@ -21,33 +27,52 @@ def check_restart(filename, tolerance = 1e-12): # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. - if 'force_periodicity' in dir(ds_restart): ds_restart.force_periodicity() + if "force_periodicity" in dir(ds_restart): + ds_restart.force_periodicity() - ad_restart = ds_restart.covering_grid(level = 0, - left_edge = ds_restart.domain_left_edge, dims = ds_restart.domain_dimensions) + ad_restart = ds_restart.covering_grid( + level=0, + left_edge=ds_restart.domain_left_edge, + dims=ds_restart.domain_dimensions, + ) # Load output data generated from initial run - benchmark = 'orig_' + filename + benchmark = os.path.join(os.getcwd().replace("_restart", ""), filename) ds_benchmark = yt.load(benchmark) # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. - if 'force_periodicity' in dir(ds_benchmark): ds_benchmark.force_periodicity() + if "force_periodicity" in dir(ds_benchmark): + ds_benchmark.force_periodicity() - ad_benchmark = ds_benchmark.covering_grid(level = 0, - left_edge = ds_benchmark.domain_left_edge, dims = ds_benchmark.domain_dimensions) + ad_benchmark = ds_benchmark.covering_grid( + level=0, + left_edge=ds_benchmark.domain_left_edge, + dims=ds_benchmark.domain_dimensions, + ) # Loop over all fields (all particle species, all particle attributes, all grid fields) # and compare output data generated from initial run with output data generated after restart - print('\ntolerance = {:g}'.format(tolerance)) + print(f"\ntolerance = {tolerance}") print() for field in ds_benchmark.field_list: dr = ad_restart[field].squeeze().v db = ad_benchmark[field].squeeze().v error = np.amax(np.abs(dr - db)) - if (np.amax(np.abs(db)) != 0.): + if np.amax(np.abs(db)) != 0.0: error /= np.amax(np.abs(db)) - print('field: {}; error = {:g}'.format(field, error)) - assert(error < tolerance) + print(f"field: {field}; error = {error}") + assert error < tolerance print() + + +filename = sys.argv[1] + +# compare restart results against original results +check_restart(filename) + +# compare restart checksums against original checksums +testname = os.path.split(os.getcwd())[1] +testname = testname.replace("_restart", "") +checksumAPI.evaluate_checksum(testname, filename, rtol=1e-12) diff --git a/Python/pywarpx/Algo.py b/Python/pywarpx/Algo.py index f8049207078..2f637627ac5 100644 --- a/Python/pywarpx/Algo.py +++ b/Python/pywarpx/Algo.py @@ -6,4 +6,4 @@ from .Bucket import Bucket -algo = Bucket('algo') +algo = Bucket("algo") diff --git a/Python/pywarpx/Amr.py b/Python/pywarpx/Amr.py index f9164f4d419..618db17d6d1 100644 --- a/Python/pywarpx/Amr.py +++ b/Python/pywarpx/Amr.py @@ -6,4 +6,4 @@ from .Bucket import Bucket -amr = Bucket('amr') +amr = Bucket("amr") diff --git a/Python/pywarpx/Amrex.py b/Python/pywarpx/Amrex.py index 4dab8225a84..34b50637003 100644 --- a/Python/pywarpx/Amrex.py +++ b/Python/pywarpx/Amrex.py @@ -6,4 +6,4 @@ from .Bucket import Bucket -amrex = Bucket('amrex') +amrex = Bucket("amrex") diff --git a/Python/pywarpx/Boundary.py b/Python/pywarpx/Boundary.py index b7ebd17af70..b84dbfe2193 100644 --- a/Python/pywarpx/Boundary.py +++ b/Python/pywarpx/Boundary.py @@ -6,4 +6,4 @@ from .Bucket import Bucket -boundary = Bucket('boundary') +boundary = Bucket("boundary") diff --git a/Python/pywarpx/Bucket.py b/Python/pywarpx/Bucket.py index 9dbe4def88e..fa595039726 100644 --- a/Python/pywarpx/Bucket.py +++ b/Python/pywarpx/Bucket.py @@ -13,9 +13,10 @@ class Bucket(object): The purpose of this class is to be a named bucket for holding attributes. This attributes will be concatenated into a string and passed into argv during initialization. """ + def __init__(self, instancename, **defaults): - self._localsetattr('instancename', instancename) - self._localsetattr('argvattrs', {}) + self._localsetattr("instancename", instancename) + self._localsetattr("argvattrs", {}) for name, value in defaults.items(): self.add_new_attr(name, value) @@ -26,7 +27,7 @@ def add_new_attr(self, name, value): """Names starting with "_" are made instance attributes. Otherwise the attribute is added to the args list. """ - if name.startswith('_'): + if name.startswith("_"): self._localsetattr(name, value) else: self.argvattrs[name] = value @@ -36,7 +37,7 @@ def add_new_group_attr(self, group, name, value): group is not an empty string, otherwise as only "name". """ if group: - self.argvattrs[f'{group}.{name}'] = value + self.argvattrs[f"{group}.{name}"] = value else: self.argvattrs[name] = value @@ -51,7 +52,9 @@ def __getattr__(self, name): def check_consistency(self, vname, value, errmsg): if vname in self.argvattrs: - assert (self.argvattrs[vname] is None) or (self.argvattrs[vname] == value), Exception(errmsg) + assert (self.argvattrs[vname] is None) or ( + self.argvattrs[vname] == value + ), Exception(errmsg) def attrlist(self): "Concatenate the attributes into a string" @@ -60,7 +63,7 @@ def attrlist(self): if value is None: continue if isinstance(value, str): - if value.find('=') > -1: + if value.find("=") > -1: # --- Expressions with temporary variables need to be inside quotes rhs = f'"{value}"' else: @@ -71,11 +74,11 @@ def attrlist(self): continue # --- For lists, tuples, and arrays make a space delimited string of the values. # --- The lambda is needed in case this is a list of strings. - rhs = ' '.join(map(lambda s : f'{s}', value)) + rhs = " ".join(map(lambda s: f"{s}", value)) elif isinstance(value, bool): rhs = 1 if value else 0 else: rhs = value - attrstring = f'{self.instancename}.{attr} = {rhs}' + attrstring = f"{self.instancename}.{attr} = {rhs}" result += [attrstring] return result diff --git a/Python/pywarpx/Collisions.py b/Python/pywarpx/Collisions.py index 9ad7f9e14a9..5269f530f4c 100644 --- a/Python/pywarpx/Collisions.py +++ b/Python/pywarpx/Collisions.py @@ -6,9 +6,10 @@ from .Bucket import Bucket -collisions = Bucket('collisions') +collisions = Bucket("collisions") collisions_list = [] + def newcollision(name): result = Bucket(name) collisions_list.append(result) diff --git a/Python/pywarpx/Constants.py b/Python/pywarpx/Constants.py index e899fa255ae..bd17c2f2dfc 100644 --- a/Python/pywarpx/Constants.py +++ b/Python/pywarpx/Constants.py @@ -13,18 +13,21 @@ class Constants(Bucket): """ The purpose of this class is to be hold user defined constants """ + def __init__(self): - Bucket.__init__(self, 'my_constants') + Bucket.__init__(self, "my_constants") def __setattr__(self, name, value): # Make sure that any constants redefined have a consistent value if name in self.argvattrs: - assert self.argvattrs[name] == value, Exception('Inconsistent values given for user defined constants') + assert self.argvattrs[name] == value, Exception( + "Inconsistent values given for user defined constants" + ) Bucket.__setattr__(self, name, value) def add_keywords(self, kwdict): mangle_dict = {} - for k,v in kwdict.items(): + for k, v in kwdict.items(): # WarpX has a single global dictionary of expression variables, my_constants, # so each variable must be unique. # Check if keyword has already been defined. If so and it has a different @@ -33,7 +36,7 @@ def add_keywords(self, kwdict): k_mangled = k while k_mangled in self.argvattrs and self.argvattrs[k_mangled] != v: mangle_number += 1 - k_mangled = f'{k}{mangle_number}' + k_mangled = f"{k}{mangle_number}" if mangle_number > 0: # The mangle_dict contains only mangled names mangle_dict[k] = k_mangled @@ -45,8 +48,8 @@ def mangle_expression(self, expression, mangle_dict): return None # For each key in mangle_dict, modify the expression replacing # the key with its value, the mangled version of key - for k,v in mangle_dict.items(): - expression = re.sub(r'\b%s\b'%k, v, expression) + for k, v in mangle_dict.items(): + expression = re.sub(r"\b%s\b" % k, v, expression) return expression diff --git a/Python/pywarpx/Diagnostics.py b/Python/pywarpx/Diagnostics.py index 19860e9b7ee..731d1d31d01 100644 --- a/Python/pywarpx/Diagnostics.py +++ b/Python/pywarpx/Diagnostics.py @@ -6,22 +6,25 @@ from .Bucket import Bucket -diagnostics = Bucket('diagnostics', _diagnostics_dict={}) -reduced_diagnostics = Bucket('warpx', _diagnostics_dict={}) +diagnostics = Bucket("diagnostics", _diagnostics_dict={}) +reduced_diagnostics = Bucket("warpx", _diagnostics_dict={}) + class Diagnostic(Bucket): """ This is the same as a Bucket, but checks that any attributes are always given the same value. """ + def add_new_attr_with_check(self, name, value): - if name.startswith('_'): + if name.startswith("_"): self._localsetattr(name, value) else: if name in self.argvattrs: - assert value == self.argvattrs[name], \ - Exception(f'Diagnostic attributes not consistent for ' - f'"{self.instancename}": ' - f'"{value}" != "{self.argvattrs[name]}"') + assert value == self.argvattrs[name], Exception( + f"Diagnostic attributes not consistent for " + f'"{self.instancename}": ' + f'"{value}" != "{self.argvattrs[name]}"' + ) self.argvattrs[name] = value def __setattr__(self, name, value): @@ -33,5 +36,5 @@ def set_or_replace_attr(self, name, value): (since __setattr__ cannot be used for replacing as it would raise an Exception) """ - assert not name.startswith('_') + assert not name.startswith("_") self.argvattrs[name] = value diff --git a/Python/pywarpx/EB2.py b/Python/pywarpx/EB2.py index 4b74aafb04f..949d362bfcc 100644 --- a/Python/pywarpx/EB2.py +++ b/Python/pywarpx/EB2.py @@ -6,4 +6,4 @@ from .Bucket import Bucket -eb2 = Bucket('eb2') +eb2 = Bucket("eb2") diff --git a/Python/pywarpx/Geometry.py b/Python/pywarpx/Geometry.py index 2eddb9b8f05..a870a2c5a57 100644 --- a/Python/pywarpx/Geometry.py +++ b/Python/pywarpx/Geometry.py @@ -6,4 +6,4 @@ from .Bucket import Bucket -geometry = Bucket('geometry') +geometry = Bucket("geometry") diff --git a/Python/pywarpx/HybridPICModel.py b/Python/pywarpx/HybridPICModel.py index e21bba4a240..7bd8c961950 100644 --- a/Python/pywarpx/HybridPICModel.py +++ b/Python/pywarpx/HybridPICModel.py @@ -8,4 +8,4 @@ from .Bucket import Bucket -hybridpicmodel = Bucket('hybrid_pic_model') +hybridpicmodel = Bucket("hybrid_pic_model") diff --git a/Python/pywarpx/Interpolation.py b/Python/pywarpx/Interpolation.py index d25539de77b..b84def573eb 100644 --- a/Python/pywarpx/Interpolation.py +++ b/Python/pywarpx/Interpolation.py @@ -6,4 +6,4 @@ from .Bucket import Bucket -interpolation = Bucket('interpolation') +interpolation = Bucket("interpolation") diff --git a/Python/pywarpx/Lasers.py b/Python/pywarpx/Lasers.py index 60dfaca31e9..3836700215d 100644 --- a/Python/pywarpx/Lasers.py +++ b/Python/pywarpx/Lasers.py @@ -6,9 +6,10 @@ from .Bucket import Bucket -lasers = Bucket('lasers', names=[]) +lasers = Bucket("lasers", names=[]) lasers_list = [] + def newlaser(name): result = Bucket(name) lasers_list.append(result) diff --git a/Python/pywarpx/LoadThirdParty.py b/Python/pywarpx/LoadThirdParty.py index ea62d558eeb..5ec84247604 100644 --- a/Python/pywarpx/LoadThirdParty.py +++ b/Python/pywarpx/LoadThirdParty.py @@ -17,19 +17,23 @@ def load_cupy(): if amr.Config.have_gpu: try: import cupy as cp + xp = cp # Note: found and will use cupy except ImportError: status = "Warning: GPU found but cupy not available! Trying managed memory in numpy..." import numpy as np + xp = np if amr.Config.gpu_backend == "SYCL": status = "Warning: SYCL GPU backend not yet implemented for Python" import numpy as np + xp = np else: import numpy as np + xp = np # Note: found and will use numpy return xp, status diff --git a/Python/pywarpx/PSATD.py b/Python/pywarpx/PSATD.py index 0cd3038336a..a5072a81fc8 100644 --- a/Python/pywarpx/PSATD.py +++ b/Python/pywarpx/PSATD.py @@ -6,4 +6,4 @@ from .Bucket import Bucket -psatd = Bucket('psatd') +psatd = Bucket("psatd") diff --git a/Python/pywarpx/Particles.py b/Python/pywarpx/Particles.py index e05341e8203..9c87bb7083e 100644 --- a/Python/pywarpx/Particles.py +++ b/Python/pywarpx/Particles.py @@ -6,10 +6,11 @@ from .Bucket import Bucket -particles = Bucket('particles', species_names=[], rigid_injected_species=[]) +particles = Bucket("particles", species_names=[], rigid_injected_species=[]) particles_list = [] particle_dict = {} + def newspecies(name): result = Bucket(name) particles_list.append(result) diff --git a/Python/pywarpx/ProjectionDivBCleaner.py b/Python/pywarpx/ProjectionDivBCleaner.py new file mode 100644 index 00000000000..f5b0aff7bcf --- /dev/null +++ b/Python/pywarpx/ProjectionDivBCleaner.py @@ -0,0 +1,11 @@ +# Copyright 2024 The WarpX Community +# +# This file is part of WarpX. +# +# Authors: S. Eric Clark (Helion Energy) +# +# License: BSD-3-Clause-LBNL + +from .Bucket import Bucket + +projectiondivbcleaner = Bucket("projection_divb_cleaner") diff --git a/Python/pywarpx/WarpX.py b/Python/pywarpx/WarpX.py index 6b24b35e918..9b3aaa27636 100644 --- a/Python/pywarpx/WarpX.py +++ b/Python/pywarpx/WarpX.py @@ -24,6 +24,7 @@ from .Interpolation import interpolation from .Lasers import lasers, lasers_list from .Particles import particles, particles_list +from .ProjectionDivBCleaner import projectiondivbcleaner from .PSATD import psatd @@ -37,7 +38,7 @@ def create_argv_list(self, **kw): for k, v in kw.items(): if v is not None: - argv.append(f'{k} = {v}') + argv.append(f"{k} = {v}") argv += warpx.attrlist() argv += my_constants.attrlist() @@ -48,6 +49,7 @@ def create_argv_list(self, **kw): argv += boundary.attrlist() argv += algo.attrlist() argv += interpolation.attrlist() + argv += projectiondivbcleaner.attrlist() argv += psatd.attrlist() argv += eb2.attrlist() @@ -62,7 +64,9 @@ def create_argv_list(self, **kw): particles_list.append(getattr(Particles, pstring)) particles_list_names.append(pstring) else: - raise Exception('Species %s listed in species_names not defined'%pstring) + raise Exception( + "Species %s listed in species_names not defined" % pstring + ) argv += particles.attrlist() for particle in particles_list: @@ -84,13 +88,26 @@ def create_argv_list(self, **kw): for species_diagnostic in diagnostic._species_dict.values(): argv += species_diagnostic.attrlist() - reduced_diagnostics.reduced_diags_names = reduced_diagnostics._diagnostics_dict.keys() + reduced_diagnostics.reduced_diags_names = ( + reduced_diagnostics._diagnostics_dict.keys() + ) argv += reduced_diagnostics.attrlist() for diagnostic in reduced_diagnostics._diagnostics_dict.values(): argv += diagnostic.attrlist() + for bucket in self._bucket_dict.values(): + argv += bucket.attrlist() + return argv + def get_bucket(self, bucket_name): + try: + return self._bucket_dict[bucket_name] + except KeyError: + bucket = Bucket(bucket_name) + self._bucket_dict[bucket_name] = bucket + return bucket + def init(self, mpi_comm=None, **kw): # note: argv[0] needs to be an absolute path so it works with AMReX backtraces # https://github.com/AMReX-Codes/amrex/issues/3435 @@ -109,25 +126,25 @@ def getProbLo(self, direction): def getProbHi(self, direction): return libwarpx.libwarpx_so.warpx_getProbHi(direction) - def write_inputs(self, filename='inputs', **kw): + def write_inputs(self, filename="inputs", **kw): argv = self.create_argv_list(**kw) # Sort the argv list to make it more human readable argv.sort() - with open(filename, 'w') as ff: - - prefix_old = '' + with open(filename, "w") as ff: + prefix_old = "" for arg in argv: # This prints the name of the input group (prefix) as a header # before each group to make the input file more human readable - prefix_new = re.split(' |\.', arg)[0] + prefix_new = re.split(" |\.", arg)[0] if prefix_new != prefix_old: - if prefix_old != '': - ff.write('\n') - ff.write(f'# {prefix_new}\n') + if prefix_old != "": + ff.write("\n") + ff.write(f"# {prefix_new}\n") prefix_old = prefix_new - ff.write(f'{arg}\n') + ff.write(f"{arg}\n") + -warpx = WarpX('warpx') +warpx = WarpX("warpx", _bucket_dict={}) diff --git a/Python/pywarpx/__init__.py b/Python/pywarpx/__init__.py index 037598f4ed4..054ca451756 100644 --- a/Python/pywarpx/__init__.py +++ b/Python/pywarpx/__init__.py @@ -1,8 +1,8 @@ -# Copyright 2016-2023 The WarpX Community +# Copyright 2016-2024 The WarpX Community # # This file is part of WarpX. # -# Authors: Andrew Myers, David Grote, Lorenzo Giacomel, Axel Huebl +# Authors: Andrew Myers, David Grote, Lorenzo Giacomel, Axel Huebl, S. Eric Clark # License: BSD-3-Clause-LBNL import os @@ -23,35 +23,38 @@ if os.path.exists(p_abs): os.add_dll_directory(p_abs) -from ._libwarpx import libwarpx -from .Algo import algo -from .Amr import amr -from .Amrex import amrex -from .Boundary import boundary -from .Collisions import collisions -from .Constants import my_constants -from .Diagnostics import diagnostics, reduced_diagnostics -from .EB2 import eb2 -from .Geometry import geometry -from .HybridPICModel import hybridpicmodel -from .Interpolation import interpolation -from .Lasers import lasers -from .LoadThirdParty import load_cupy -from .Particles import newspecies, particles -from .PSATD import psatd -from .WarpX import warpx +from ._libwarpx import libwarpx # noqa +from .Algo import algo # noqa +from .Amr import amr # noqa +from .Amrex import amrex # noqa +from .Boundary import boundary # noqa +from .Collisions import collisions # noqa +from .Constants import my_constants # noqa +from .Diagnostics import diagnostics, reduced_diagnostics # noqa +from .EB2 import eb2 # noqa +from .Geometry import geometry # noqa +from .HybridPICModel import hybridpicmodel # noqa +from .Interpolation import interpolation # noqa +from .Lasers import lasers # noqa +from .LoadThirdParty import load_cupy # noqa +from .Particles import newspecies, particles # noqa +from .ProjectionDivBCleaner import projectiondivbcleaner # noqa +from .PSATD import psatd # noqa +from .WarpX import warpx # noqa # This is a circular import and must happen after the import of libwarpx -from . import picmi # isort:skip +from . import picmi # noqa # isort:skip + # intentionally query the value - only set once sim dimension is known def __getattr__(name): # https://stackoverflow.com/a/57263518/2719194 - if name == '__version__': + if name == "__version__": return libwarpx.__version__ raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + # TODO -#__doc__ = cxx.__doc__ -#__license__ = cxx.__license__ -#__author__ = cxx.__author__ +# __doc__ = cxx.__doc__ +# __license__ = cxx.__license__ +# __author__ = cxx.__author__ diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py index 1eb410e65b8..40426104b9f 100755 --- a/Python/pywarpx/_libwarpx.py +++ b/Python/pywarpx/_libwarpx.py @@ -14,13 +14,12 @@ import atexit import os - -import numpy as np +import sys from .Geometry import geometry -class LibWarpX(): +class LibWarpX: """This class manages the WarpX classes, part of the Python module from the compiled C++ code. It will only load the library when it is referenced, and this can only be done after the geometry is defined so that the version of the library that is needed can be determined. @@ -36,7 +35,7 @@ def __init__(self): self.__version__ = None def __getattr__(self, attribute): - if attribute == 'libwarpx_so': + if attribute == "libwarpx_so": # If the 'libwarpx_so' is referenced, load it. # Once loaded, it gets added to the dictionary so this code won't be called again. self.load_library() @@ -47,21 +46,20 @@ def __getattr__(self, attribute): return self.__getattribute__(attribute) def _get_package_root(self): - ''' + """ Get the path to the installation location (where libwarpx.so would be installed). - ''' + """ cur = os.path.abspath(__file__) while True: name = os.path.basename(cur) - if name == 'pywarpx': + if name == "pywarpx": return cur elif not name: - return '' + return "" cur = os.path.dirname(cur) def load_library(self): - - if 'libwarpx_so' in self.__dict__: + if "libwarpx_so" in self.__dict__: raise RuntimeError( "Invalid attempt to load the pybind11 bindings library multiple times. " "Note that multiple AMReX/WarpX geometries cannot be loaded yet into the same Python process. " @@ -74,57 +72,69 @@ def load_library(self): _prob_lo = geometry.prob_lo _dims = geometry.dims except AttributeError: - raise Exception('The shared object could not be loaded. The geometry must be setup before the WarpX pybind11 module can be accessesd. The geometry determines which version of the shared object to load.') + raise Exception( + "The shared object could not be loaded. The geometry must be setup before the WarpX pybind11 module can be accessesd. The geometry determines which version of the shared object to load." + ) - if _dims == 'RZ': - self.geometry_dim = 'rz' - elif (_dims == '1' or _dims == '2' or _dims == '3'): - self.geometry_dim = '%dd'%len(_prob_lo) + if _dims == "RZ": + self.geometry_dim = "rz" + elif _dims == "1" or _dims == "2" or _dims == "3": + self.geometry_dim = "%dd" % len(_prob_lo) else: - raise Exception('Undefined geometry %d'%_dims) + raise Exception("Undefined geometry %d" % _dims) try: if self.geometry_dim == "1d": import amrex.space1d as amr + self.amr = amr from . import warpx_pybind_1d as cxx_1d + self.libwarpx_so = cxx_1d self.dim = 1 elif self.geometry_dim == "2d": import amrex.space2d as amr + self.amr = amr from . import warpx_pybind_2d as cxx_2d + self.libwarpx_so = cxx_2d self.dim = 2 elif self.geometry_dim == "rz": import amrex.space2d as amr + self.amr = amr from . import warpx_pybind_rz as cxx_rz + self.libwarpx_so = cxx_rz self.dim = 2 elif self.geometry_dim == "3d": import amrex.space3d as amr + self.amr = amr from . import warpx_pybind_3d as cxx_3d + self.libwarpx_so = cxx_3d self.dim = 3 self.Config = self.libwarpx_so.Config except ImportError: - raise Exception(f"Dimensionality '{self.geometry_dim}' was not compiled in this Python install. Please recompile with -DWarpX_DIMS={_dims}") + raise Exception( + f"Dimensionality '{self.geometry_dim}' was not compiled in this Python install. Please recompile with -DWarpX_DIMS={_dims}" + ) self.__version__ = self.libwarpx_so.__version__ def amrex_init(self, argv, mpi_comm=None): - if mpi_comm is None: # or MPI is None: + if mpi_comm is None: # or MPI is None: self.libwarpx_so.amrex_init(argv) else: - raise Exception('mpi_comm argument not yet supported') + raise Exception("mpi_comm argument not yet supported") def initialize(self, argv=None, mpi_comm=None): - ''' + """ Initialize WarpX and AMReX. Must be called before doing anything else. - ''' + """ if argv is None: argv = sys.argv self.amrex_init(argv, mpi_comm) @@ -133,22 +143,24 @@ def initialize(self, argv=None, mpi_comm=None): self.libwarpx_so.execute_python_callback("afterinit") self.libwarpx_so.execute_python_callback("particleloader") - #self.libwarpx_so.warpx_init() + # self.libwarpx_so.warpx_init() self.initialized = True def finalize(self, finalize_mpi=1): - ''' + """ Call finalize for WarpX and AMReX. Registered to run at program exit. - ''' + """ # TODO: simplify, part of pyAMReX already if self.initialized: del self.warpx # The call to warpx_finalize causes a crash - don't know why - #self.libwarpx_so.warpx_finalize() + # self.libwarpx_so.warpx_finalize() self.libwarpx_so.amrex_finalize() from pywarpx import callbacks + callbacks.clear_all() + libwarpx = LibWarpX() diff --git a/Python/pywarpx/callbacks.py b/Python/pywarpx/callbacks.py index 1f32fee6620..45c9b63a082 100644 --- a/Python/pywarpx/callbacks.py +++ b/Python/pywarpx/callbacks.py @@ -25,6 +25,7 @@ Functions can be called at the following times: +* ``loadExternalFields``: during ``WarpX::LoadExternalFields`` to write ``B/Efield_fp_external`` values * ``beforeInitEsolve``: before the initial solve for the E fields (i.e. before the PIC loop starts) * ``afterinit``: immediately after the init is complete * ``beforeEsolve``: before the solve for E fields @@ -100,19 +101,20 @@ class CallbackFunctions(object): installed a method in one of the call back lists. """ - def __init__(self,name=None,lcallonce=0,singlefunconly=False): + def __init__(self, name=None, lcallonce=0, singlefunconly=False): self.funcs = [] - self.time = 0. + self.time = 0.0 self.timers = {} self.name = name self.lcallonce = lcallonce self.singlefunconly = singlefunconly - def __call__(self,*args,**kw): + def __call__(self, *args, **kw): """Call all of the functions in the list""" - tt = self.callfuncsinlist(*args,**kw) + tt = self.callfuncsinlist(*args, **kw) self.time = self.time + tt - if self.lcallonce: self.funcs = [] + if self.lcallonce: + self.funcs = [] def clearlist(self): """Unregister/clear out all registered C callbacks""" @@ -131,7 +133,7 @@ def hasfuncsinstalled(self): """Checks if there are any functions installed""" return len(self.funcs) > 0 - def _getmethodobject(self,func): + def _getmethodobject(self, func): """For call backs that are methods, returns the method's instance""" return func[0] @@ -139,14 +141,15 @@ def callbackfunclist(self): """Generator returning callable functions from the list""" funclistcopy = copy.copy(self.funcs) for f in funclistcopy: - if isinstance(f,list): + if isinstance(f, list): object = self._getmethodobject(f) if object is None: self.funcs.remove(f) continue - result = getattr(object,f[1]) - elif isinstance(f,str): + result = getattr(object, f[1]) + elif isinstance(f, str): import __main__ + if f in __main__.__dict__: result = __main__.__dict__[f] # --- If the function with the name is found, then replace the @@ -159,19 +162,19 @@ def callbackfunclist(self): if not callable(result): print("\n\nWarning: a call back was found that is not callable.") if self.name is not None: - print("For %s"%self.name) + print("For %s" % self.name) print("Only callable objects can be installed.") print("It is possible that the callable's name has been overwritten") print("by something not callable. This can happen during restart") print("if a function name had later been used as a variable name.") print(self.name) - if isinstance(f,str): - print("The name of the call back is %s"%f) + if isinstance(f, str): + print(f"The name of the call back is {f}") print("\n\n") continue yield result - def installfuncinlist(self,f): + def installfuncinlist(self, f): """Check if the specified function is installed""" if self.singlefunconly and self.hasfuncsinstalled(): raise RuntimeError( @@ -182,12 +185,12 @@ def installfuncinlist(self,f): # If this is the first function installed, set the callback in the C++ # to call this class instance. libwarpx.libwarpx_so.add_python_callback(self.name, self) - if isinstance(f,types.MethodType): + if isinstance(f, types.MethodType): # --- If the function is a method of a class instance, then save a full # --- reference to that instance and the method name. finstance = f.__self__ fname = f.__name__ - self.funcs.append([finstance,fname]) + self.funcs.append([finstance, fname]) elif callable(f): # --- If a function had already been installed by name, then skip the install. # --- This is problematic, since no warning message is given, but it is unlikely @@ -202,7 +205,7 @@ def installfuncinlist(self,f): else: self.funcs.append(f) - def uninstallfuncinlist(self,f): + def uninstallfuncinlist(self, f): """Uninstall the specified function""" # --- An element by element search is needed # --- f can be a function or method object, or a name (string). @@ -212,71 +215,76 @@ def uninstallfuncinlist(self,f): if f == func: self.funcs.remove(f) break - elif isinstance(func,list) and isinstance(f,types.MethodType): + elif isinstance(func, list) and isinstance(f, types.MethodType): object = self._getmethodobject(func) if f.__self__ is object and f.__name__ == func[1]: self.funcs.remove(func) break - elif isinstance(func,str): + elif isinstance(func, str): if f.__name__ == func: self.funcs.remove(func) break - elif isinstance(f,str): - if isinstance(func,str): funcname = func - elif isinstance(func,list): funcname = None - else: funcname = func.__name__ + elif isinstance(f, str): + if isinstance(func, str): + funcname = func + elif isinstance(func, list): + funcname = None + else: + funcname = func.__name__ if f == funcname: self.funcs.remove(func) break # check that a function was removed if len(self.funcs) == len(funclistcopy): - raise Exception(f'Warning: no function, {f}, had been installed') + raise Exception(f"Warning: no function, {f}, had been installed") # if there are no functions left, remove the C callback if not self.hasfuncsinstalled(): self.clearlist() - def isinstalledfuncinlist(self,f): + def isinstalledfuncinlist(self, f): """Checks if the specified function is installed""" # --- An element by element search is needed funclistcopy = copy.copy(self.funcs) for func in funclistcopy: if f == func: return 1 - elif isinstance(func,list) and isinstance(f,types.MethodType): + elif isinstance(func, list) and isinstance(f, types.MethodType): object = self._getmethodobject(func) if f.__self__ is object and f.__name__ == func[1]: return 1 - elif isinstance(func,str): + elif isinstance(func, str): if f.__name__ == func: return 1 return 0 - def callfuncsinlist(self,*args,**kw): + def callfuncsinlist(self, *args, **kw): """Call the functions in the list""" bb = time.time() for f in self.callbackfunclist(): - #barrier() + # barrier() t1 = time.time() - f(*args,**kw) - #barrier() + f(*args, **kw) + # barrier() t2 = time.time() # --- For the timers, use the function (or method) name as the key. - self.timers[f.__name__] = self.timers.get(f.__name__,0.) + (t2 - t1) + self.timers[f.__name__] = self.timers.get(f.__name__, 0.0) + (t2 - t1) aa = time.time() return aa - bb -#============================================================================= + +# ============================================================================= callback_instances = { + "loadExternalFields": {}, "beforeInitEsolve": {}, "afterInitEsolve": {}, "afterinit": {}, "beforecollisions": {}, "aftercollisions": {}, "beforeEsolve": {}, - "poissonsolver": {'singlefunconly': True}, # external Poisson solver + "poissonsolver": {"singlefunconly": True}, # external Poisson solver "afterEsolve": {}, "afterBpush": {}, "afterEpush": {}, @@ -291,13 +299,14 @@ def callfuncsinlist(self,*args,**kw): "oncheckpointsignal": {}, "onbreaksignal": {}, "particleinjection": {}, - "appliedfields": {} + "appliedfields": {}, } # --- Now create the actual instances. for key, val in callback_instances.items(): callback_instances[key] = CallbackFunctions(name=key, **val) + def installcallback(name, f): """Installs a function to be called at that specified time. @@ -305,186 +314,273 @@ def installcallback(name, f): """ callback_instances[name].installfuncinlist(f) + def uninstallcallback(name, f): """Uninstalls the function (so it won't be called anymore). Removes the function from the list of functions called by this callback.""" callback_instances[name].uninstallfuncinlist(f) + def isinstalled(name, f): """Checks if a function is installed for this callback.""" return callback_instances[name].isinstalledfuncinlist(f) + def clear_all(): for key, val in callback_instances.items(): val.clearlist() -#============================================================================= -def printcallbacktimers(tmin=1.,lminmax=False,ff=None): +# ============================================================================ + + +def printcallbacktimers(tmin=1.0, lminmax=False, ff=None): """Prints timings of installed functions. - tmin=1.: only functions with time greater than tmin will be printed - lminmax=False: If True, prints the min and max times over all processors - ff=None: If given, timings will be written to the file object instead of stdout """ - if ff is None: ff = sys.stdout + if ff is None: + ff = sys.stdout for c in callback_instances.values(): - for fname, time in c.timers.items(): - #vlist = numpy.array(gather(time)) - vlist = numpy.array([time]) - #if me > 0: continue + for fname, this_time in c.timers.items(): + # vlist = numpy.array(gather(this_time)) + vlist = numpy.array([this_time]) + # if me > 0: continue vsum = numpy.sum(vlist) - if vsum <= tmin: continue - vrms = numpy.sqrt(max(0.,numpy.sum(vlist**2)/len(vlist) - (numpy.sum(vlist)/len(vlist))**2)) - npes = 1. # Only works for one processor - ff.write('%20s %s %10.4f %10.4f %10.4f'%(c.name,fname,vsum,vsum/npes,vrms)) + if vsum <= tmin: + continue + vrms = numpy.sqrt( + max( + 0.0, + numpy.sum(vlist**2) / len(vlist) + - (numpy.sum(vlist) / len(vlist)) ** 2, + ) + ) + npes = 1.0 # Only works for one processor + ff.write( + "%20s %s %10.4f %10.4f %10.4f" + % (c.name, fname, vsum, vsum / npes, vrms) + ) if lminmax: vmin = numpy.min(vlist) vmax = numpy.max(vlist) - ff.write(' %10.4f %10.4f'%(vmin,vmax)) + ff.write(" %10.4f %10.4f" % (vmin, vmax)) it = libwarpx.libwarpx_so.warpx_getistep(0) if it > 0: - ff.write(' %10.4f'%(vsum/npes/(it))) - ff.write('\n') + ff.write(" %10.4f" % (vsum / npes / (it))) + ff.write("\n") + + +# ============================================================================ + + +# ---------------------------------------------------------------------------- +def callfromloadExternalFields(f): + installcallback("loadExternalFields", f) + return f + + +def installloadExternalFields(f): + installcallback("loadExternalFields", f) -#============================================================================= # ---------------------------------------------------------------------------- def callfrombeforeInitEsolve(f): - installcallback('beforeInitEsolve', f) + installcallback("beforeInitEsolve", f) return f + + def installbeforeInitEsolve(f): - installcallback('beforeInitEsolve', f) + installcallback("beforeInitEsolve", f) + # ---------------------------------------------------------------------------- def callfromafterInitEsolve(f): - installcallback('afterInitEsolve', f) + installcallback("afterInitEsolve", f) return f + + def installafterInitEsolve(f): - installcallback('afterInitEsolve', f) + installcallback("afterInitEsolve", f) + # ---------------------------------------------------------------------------- def callfromafterinit(f): - installcallback('afterinit', f) + installcallback("afterinit", f) return f + + def installafterinit(f): - installcallback('afterinit', f) + installcallback("afterinit", f) + # ---------------------------------------------------------------------------- def callfrombeforecollisions(f): - installcallback('beforecollisions', f) + installcallback("beforecollisions", f) return f + + def installbeforecollisions(f): - installcallback('beforecollisions', f) + installcallback("beforecollisions", f) + # ---------------------------------------------------------------------------- def callfromaftercollisions(f): - installcallback('aftercollisions', f) + installcallback("aftercollisions", f) return f + + def installaftercollisions(f): - installcallback('aftercollisions', f) + installcallback("aftercollisions", f) + # ---------------------------------------------------------------------------- def callfrombeforeEsolve(f): - installcallback('beforeEsolve', f) + installcallback("beforeEsolve", f) return f + + def installbeforeEsolve(f): - installcallback('beforeEsolve', f) + installcallback("beforeEsolve", f) + # ---------------------------------------------------------------------------- def callfrompoissonsolver(f): - installcallback('poissonsolver', f) + installcallback("poissonsolver", f) return f + + def installpoissonsolver(f): - installcallback('poissonsolver', f) + installcallback("poissonsolver", f) + # ---------------------------------------------------------------------------- def callfromafterEsolve(f): - installcallback('afterEsolve', f) + installcallback("afterEsolve", f) return f + + def installafterEsolve(f): - installcallback('afterEsolve', f) + installcallback("afterEsolve", f) + # ---------------------------------------------------------------------------- def callfromafterBpush(f): - installcallback('afterBpush', f) + installcallback("afterBpush", f) return f + + def installafterBpush(f): - installcallback('afterBpush', f) + installcallback("afterBpush", f) + # ---------------------------------------------------------------------------- def callfromafterEpush(f): - installcallback('afterEpush', f) + installcallback("afterEpush", f) return f + + def installafterEpush(f): - installcallback('afterEpush', f) + installcallback("afterEpush", f) + # ---------------------------------------------------------------------------- def callfrombeforedeposition(f): - installcallback('beforedeposition', f) + installcallback("beforedeposition", f) return f + + def installbeforedeposition(f): - installcallback('beforedeposition', f) + installcallback("beforedeposition", f) + # ---------------------------------------------------------------------------- def callfromafterdeposition(f): - installcallback('afterdeposition', f) + installcallback("afterdeposition", f) return f + + def installafterdeposition(f): - installcallback('afterdeposition', f) + installcallback("afterdeposition", f) + # ---------------------------------------------------------------------------- def callfromparticlescraper(f): - installcallback('particlescraper', f) + installcallback("particlescraper", f) return f + + def installparticlescraper(f): - installcallback('particlescraper', f) + installcallback("particlescraper", f) + # ---------------------------------------------------------------------------- def callfromparticleloader(f): - installcallback('particleloader', f) + installcallback("particleloader", f) return f + + def installparticleloader(f): - installcallback('particleloader', f) + installcallback("particleloader", f) + # ---------------------------------------------------------------------------- def callfrombeforestep(f): - installcallback('beforestep', f) + installcallback("beforestep", f) return f + + def installbeforestep(f): - installcallback('beforestep', f) + installcallback("beforestep", f) + # ---------------------------------------------------------------------------- def callfromafterstep(f): - installcallback('afterstep', f) + installcallback("afterstep", f) return f + + def installafterstep(f): - installcallback('afterstep', f) + installcallback("afterstep", f) + # ---------------------------------------------------------------------------- def callfromafterdiagnostics(f): - installcallback('afterdiagnostics', f) + installcallback("afterdiagnostics", f) return f + + def installafterdiagnostics(f): - installcallback('afterdiagnostics', f) + installcallback("afterdiagnostics", f) + # ---------------------------------------------------------------------------- def oncheckpointsignal(f): - installcallback('oncheckpointsignal', f) + installcallback("oncheckpointsignal", f) return f + + def installoncheckpointsignal(f): - installcallback('oncheckpointsignal', f) + installcallback("oncheckpointsignal", f) + # ---------------------------------------------------------------------------- def onbreaksignal(f): - installcallback('onbreaksignal', f) + installcallback("onbreaksignal", f) return f + + def installonbreaksignal(f): - installcallback('onbreaksignal', f) + installcallback("onbreaksignal", f) + # ---------------------------------------------------------------------------- def callfromparticleinjection(f): - installcallback('particleinjection', f) + installcallback("particleinjection", f) return f + + def installparticleinjection(f): - installcallback('particleinjection', f) + installcallback("particleinjection", f) diff --git a/Python/pywarpx/fields.py b/Python/pywarpx/fields.py index 0f680595ef4..cbdd8d4517a 100644 --- a/Python/pywarpx/fields.py +++ b/Python/pywarpx/fields.py @@ -41,6 +41,7 @@ JxCPPMLWrapper, JyCPPMLWrapper, JzCPPMLWrapper FCPPMLWrapper, GCPPMLWrapper """ + import numpy as np try: @@ -51,6 +52,7 @@ try: from mpi4py import MPI as mpi + comm_world = mpi.COMM_WORLD npes = comm_world.Get_size() except ImportError: @@ -83,6 +85,7 @@ class _MultiFABWrapper(object): Note that when True, the first n-ghost negative indices will refer to the lower ghost cells. """ + def __init__(self, mf=None, mf_name=None, level=0, include_ghosts=False): self._mf = mf self.mf_name = mf_name @@ -94,7 +97,9 @@ def __init__(self, mf=None, mf_name=None, level=0, include_ghosts=False): # The overlaps list is one along the axes where the grid boundaries overlap the neighboring grid, # which is the case with node centering. ix_type = self.mf.box_array().ix_type() - self.overlaps = self._get_indices([int(ix_type.node_centered(i)) for i in range(self.dim)], 0) + self.overlaps = self._get_indices( + [int(ix_type.node_centered(i)) for i in range(self.dim)], 0 + ) def __len__(self): "Returns the number of blocks" @@ -112,17 +117,16 @@ def mf(self): # Always fetch this anew in case the C++ MultiFab is recreated warpx = libwarpx.libwarpx_so.get_instance() # All MultiFab names have the level suffix - return warpx.multifab(f'{self.mf_name}[level={self.level}]') + return warpx.multifab(f"{self.mf_name}[level={self.level}]") @property def shape(self): - """Returns the shape of the global array - """ + """Returns the shape of the global array""" min_box = self.mf.box_array().minimal_box() shape = list(min_box.size - min_box.small_end) if self.include_ghosts: nghosts = self.mf.n_grow_vect - shape = [shape[i] + 2*nghosts[i] for i in range(self.dim)] + shape = [shape[i] + 2 * nghosts[i] for i in range(self.dim)] shape.append(self.mf.nComp) return tuple(shape) @@ -139,20 +143,16 @@ def mesh(self, direction): """ try: - if libwarpx.geometry_dim == '3d': - idir = ['x', 'y', 'z'].index(direction) - celldir = idir - elif libwarpx.geometry_dim == '2d': - idir = ['x', 'z'].index(direction) - celldir = 2*idir - elif libwarpx.geometry_dim == 'rz': - idir = ['r', 'z'].index(direction) - celldir = 2*idir - elif libwarpx.geometry_dim == '1d': - idir = ['z'].index(direction) - celldir = idir + if libwarpx.geometry_dim == "3d": + idir = ["x", "y", "z"].index(direction) + elif libwarpx.geometry_dim == "2d": + idir = ["x", "z"].index(direction) + elif libwarpx.geometry_dim == "rz": + idir = ["r", "z"].index(direction) + elif libwarpx.geometry_dim == "1d": + idir = ["z"].index(direction) except ValueError: - raise Exception('Inappropriate direction given') + raise Exception("Inappropriate direction given") min_box = self.mf.box_array().minimal_box() ilo = min_box.small_end[idir] @@ -172,13 +172,13 @@ def mesh(self, direction): ix_type = self.mf.box_array().ix_type() if ix_type.node_centered(idir): # node centered - shift = 0. + shift = 0.0 else: # cell centered - shift = 0.5*dd + shift = 0.5 * dd lo = warpx.Geom(self.level).ProbLo(idir) - return lo + np.arange(ilo,ihi+1)*dd + shift + return lo + np.arange(ilo, ihi + 1) * dd + shift def _get_indices(self, index, missing): """Expand the index list to length three. @@ -214,8 +214,7 @@ def _get_min_indices(self): return imin def _get_max_indices(self): - """Returns the maximum indices, expanded to length 3. - """ + """Returns the maximum indices, expanded to length 3.""" min_box = self.mf.box_array().minimal_box() if self.include_ghosts: min_box.grow(self.mf.n_grow_vect) @@ -277,8 +276,12 @@ def _find_start_stop(self, ii, imin, imax, d): ii = self._fix_index(ii, imax, d) iistart = ii iistop = ii + 1 - assert imin <= iistart <= imax, Exception(f'Dimension {d+1} lower index is out of bounds') - assert imin <= iistop <= imax, Exception(f'Dimension {d+1} upper index is out of bounds') + assert imin <= iistart <= imax, Exception( + f"Dimension {d+1} lower index is out of bounds" + ) + assert imin <= iistop <= imax, Exception( + f"Dimension {d+1} upper index is out of bounds" + ) return iistart, iistop def _get_field(self, mfi): @@ -302,7 +305,9 @@ def _get_field(self, mfi): device_arr = device_arr4.to_numpy(copy=False) if not self.include_ghosts: nghosts = self._get_n_ghosts() - device_arr = device_arr[tuple([slice(ng, -ng) for ng in nghosts[:self.dim]])] + device_arr = device_arr[ + tuple([slice(ng, -ng) for ng in nghosts[: self.dim]]) + ] return device_arr def _get_intersect_slice(self, mfi, starts, stops, icstart, icstop): @@ -353,7 +358,6 @@ def _get_intersect_slice(self, mfi, starts, stops, icstart, icstop): i2 = np.minimum(stops, ihi_p1) if np.all(i1 < i2): - block_slices = [] global_slices = [] for i in range(3): @@ -384,19 +388,19 @@ def __getitem__(self, index): # Note that the index can have negative values (which wrap around) and has 1 added to the upper # limit using python style slicing if index == Ellipsis: - index = self.dim*[slice(None)] + index = self.dim * [slice(None)] elif isinstance(index, slice): # If only one slice passed in, it was not wrapped in a list index = [index] - if len(index) < self.dim+1: + if len(index) < self.dim + 1: # Add extra dims to index, including for the component. # These are the dims left out and assumed to extend over the full size of the dim index = list(index) - while len(index) < self.dim+1: + while len(index) < self.dim + 1: index.append(slice(None)) - elif len(index) > self.dim+1: - raise Exception('Too many indices given') + elif len(index) > self.dim + 1: + raise Exception("Too many indices given") # Expand the indices to length 3 ii = self._get_indices(index, None) @@ -407,9 +411,9 @@ def __getitem__(self, index): ixmax, iymax, izmax = self._get_max_indices() # Setup the size of the array to be returned - ixstart, ixstop = self._find_start_stop(ii[0], ixmin, ixmax+1, 0) - iystart, iystop = self._find_start_stop(ii[1], iymin, iymax+1, 1) - izstart, izstop = self._find_start_stop(ii[2], izmin, izmax+1, 2) + ixstart, ixstop = self._find_start_stop(ii[0], ixmin, ixmax + 1, 0) + iystart, iystop = self._find_start_stop(ii[1], iymin, iymax + 1, 1) + izstart, izstop = self._find_start_stop(ii[2], izmin, izmax + 1, 2) icstart, icstop = self._find_start_stop(ic, 0, self.mf.n_comp, 3) # Gather the data to be included in a list to be sent to other processes @@ -417,7 +421,9 @@ def __getitem__(self, index): stops = [ixstop, iystop, izstop] datalist = [] for mfi in self.mf: - block_slices, global_slices = self._get_intersect_slice(mfi, starts, stops, icstart, icstop) + block_slices, global_slices = self._get_intersect_slice( + mfi, starts, stops, icstart, icstop + ) if global_slices is not None: # Note that the array will always have 4 dimensions. device_arr = self._get_field(mfi) @@ -434,10 +440,12 @@ def __getitem__(self, index): all_datalist = comm_world.allgather(datalist) # Create the array to be returned - result_shape = (max(0, ixstop - ixstart), - max(0, iystop - iystart), - max(0, izstop - izstart), - max(0, icstop - icstart)) + result_shape = ( + max(0, ixstop - ixstart), + max(0, iystop - iystart), + max(0, izstop - izstart), + max(0, icstop - icstart), + ) # Now, copy the data into the result array result_global = None @@ -474,19 +482,19 @@ def __setitem__(self, index, value): # Note that the index can have negative values (which wrap around) and has 1 added to the upper # limit using python style slicing if index == Ellipsis: - index = tuple(self.dim*[slice(None)]) + index = tuple(self.dim * [slice(None)]) elif isinstance(index, slice): # If only one slice passed in, it was not wrapped in a list index = [index] - if len(index) < self.dim+1: + if len(index) < self.dim + 1: # Add extra dims to index, including for the component. # These are the dims left out and assumed to extend over the full size of the dim. index = list(index) - while len(index) < self.dim+1: + while len(index) < self.dim + 1: index.append(slice(None)) - elif len(index) > self.dim+1: - raise Exception('Too many indices given') + elif len(index) > self.dim + 1: + raise Exception("Too many indices given") # Expand the indices to length 3 ii = self._get_indices(index, None) @@ -497,9 +505,9 @@ def __setitem__(self, index, value): ixmax, iymax, izmax = self._get_max_indices() # Setup the size of the global array to be set - ixstart, ixstop = self._find_start_stop(ii[0], ixmin, ixmax+1, 0) - iystart, iystop = self._find_start_stop(ii[1], iymin, iymax+1, 1) - izstart, izstop = self._find_start_stop(ii[2], izmin, izmax+1, 2) + ixstart, ixstop = self._find_start_stop(ii[0], ixmin, ixmax + 1, 0) + iystart, iystop = self._find_start_stop(ii[1], iymin, iymax + 1, 1) + izstart, izstop = self._find_start_stop(ii[2], izmin, izmax + 1, 2) icstart, icstop = self._find_start_stop(ic, 0, self.mf.n_comp, 3) if isinstance(value, np.ndarray): @@ -511,10 +519,14 @@ def __setitem__(self, index, value): global_shape = list(value3d.shape) # The shape of 1 is added for the extra dimensions and when index is an integer # (in which case the dimension was not in the input array). - if not isinstance(ii[0], slice): global_shape[0:0] = [1] - if not isinstance(ii[1], slice): global_shape[1:1] = [1] - if not isinstance(ii[2], slice): global_shape[2:2] = [1] - if not isinstance(ic , slice) or len(global_shape) < 4: global_shape[3:3] = [1] + if not isinstance(ii[0], slice): + global_shape[0:0] = [1] + if not isinstance(ii[1], slice): + global_shape[1:1] = [1] + if not isinstance(ii[2], slice): + global_shape[2:2] = [1] + if not isinstance(ic, slice) or len(global_shape) < 4: + global_shape[3:3] = [1] value3d.shape = global_shape if libwarpx.libwarpx_so.Config.have_gpu: @@ -526,7 +538,9 @@ def __setitem__(self, index, value): starts = [ixstart, iystart, izstart] stops = [ixstop, iystop, izstop] for mfi in self.mf: - block_slices, global_slices = self._get_intersect_slice(mfi, starts, stops, icstart, icstop) + block_slices, global_slices = self._get_intersect_slice( + mfi, starts, stops, icstart, icstop + ) if global_slices is not None: mf_arr = self._get_field(mfi) if isinstance(value, np.ndarray): @@ -558,205 +572,442 @@ def norm0(self, *args): def ExWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_aux[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_aux[x]", level=level, include_ghosts=include_ghosts + ) + def EyWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_aux[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_aux[y]", level=level, include_ghosts=include_ghosts + ) + def EzWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_aux[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_aux[z]", level=level, include_ghosts=include_ghosts + ) + def BxWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_aux[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_aux[x]", level=level, include_ghosts=include_ghosts + ) + def ByWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_aux[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_aux[y]", level=level, include_ghosts=include_ghosts + ) + def BzWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_aux[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_aux[z]", level=level, include_ghosts=include_ghosts + ) + def JxWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp[x]", level=level, include_ghosts=include_ghosts + ) + def JyWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp[y]", level=level, include_ghosts=include_ghosts + ) + def JzWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp[z]", level=level, include_ghosts=include_ghosts + ) + def ExFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_fp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_fp[x]", level=level, include_ghosts=include_ghosts + ) + def EyFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_fp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_fp[y]", level=level, include_ghosts=include_ghosts + ) + def EzFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_fp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_fp[z]", level=level, include_ghosts=include_ghosts + ) + def BxFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_fp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_fp[x]", level=level, include_ghosts=include_ghosts + ) + def ByFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_fp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_fp[y]", level=level, include_ghosts=include_ghosts + ) + def BzFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_fp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_fp[z]", level=level, include_ghosts=include_ghosts + ) + + +def ExFPExternalWrapper(level=0, include_ghosts=False): + return _MultiFABWrapper( + mf_name="Efield_fp_external[x]", level=level, include_ghosts=include_ghosts + ) + + +def EyFPExternalWrapper(level=0, include_ghosts=False): + return _MultiFABWrapper( + mf_name="Efield_fp_external[y]", level=level, include_ghosts=include_ghosts + ) + + +def EzFPExternalWrapper(level=0, include_ghosts=False): + return _MultiFABWrapper( + mf_name="Efield_fp_external[z]", level=level, include_ghosts=include_ghosts + ) + + +def BxFPExternalWrapper(level=0, include_ghosts=False): + return _MultiFABWrapper( + mf_name="Bfield_fp_external[x]", level=level, include_ghosts=include_ghosts + ) + + +def ByFPExternalWrapper(level=0, include_ghosts=False): + return _MultiFABWrapper( + mf_name="Bfield_fp_external[y]", level=level, include_ghosts=include_ghosts + ) + + +def BzFPExternalWrapper(level=0, include_ghosts=False): + return _MultiFABWrapper( + mf_name="Bfield_fp_external[z]", level=level, include_ghosts=include_ghosts + ) + def JxFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp[x]", level=level, include_ghosts=include_ghosts + ) + def JyFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp[y]", level=level, include_ghosts=include_ghosts + ) + def JzFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp[z]", level=level, include_ghosts=include_ghosts + ) + def RhoFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='rho_fp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="rho_fp", level=level, include_ghosts=include_ghosts + ) + def PhiFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='phi_fp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="phi_fp", level=level, include_ghosts=include_ghosts + ) + def FFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='F_fp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper(mf_name="F_fp", level=level, include_ghosts=include_ghosts) + def GFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='G_fp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper(mf_name="G_fp", level=level, include_ghosts=include_ghosts) + def AxFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='vector_potential_fp_nodal[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="vector_potential_fp_nodal[x]", + level=level, + include_ghosts=include_ghosts, + ) + def AyFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='vector_potential_fp_nodal[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="vector_potential_fp_nodal[y]", + level=level, + include_ghosts=include_ghosts, + ) + def AzFPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='vector_potential_fp_nodal[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="vector_potential_fp_nodal[z]", + level=level, + include_ghosts=include_ghosts, + ) + def ExCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_cp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_cp[x]", level=level, include_ghosts=include_ghosts + ) + def EyCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_cp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_cp[y]", level=level, include_ghosts=include_ghosts + ) + def EzCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Efield_cp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Efield_cp[z]", level=level, include_ghosts=include_ghosts + ) + def BxCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_cp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_cp[x]", level=level, include_ghosts=include_ghosts + ) + def ByCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_cp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_cp[y]", level=level, include_ghosts=include_ghosts + ) + def BzCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='Bfield_cp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="Bfield_cp[z]", level=level, include_ghosts=include_ghosts + ) + def JxCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_cp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_cp[x]", level=level, include_ghosts=include_ghosts + ) + def JyCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_cp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_cp[y]", level=level, include_ghosts=include_ghosts + ) + def JzCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_cp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_cp[z]", level=level, include_ghosts=include_ghosts + ) + def RhoCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='rho_cp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="rho_cp", level=level, include_ghosts=include_ghosts + ) + def FCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='F_cp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper(mf_name="F_cp", level=level, include_ghosts=include_ghosts) + def GCPWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='G_cp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper(mf_name="G_cp", level=level, include_ghosts=include_ghosts) + def EdgeLengthsxWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='m_edge_lengths[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="m_edge_lengths[x]", level=level, include_ghosts=include_ghosts + ) + def EdgeLengthsyWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='m_edge_lengths[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="m_edge_lengths[y]", level=level, include_ghosts=include_ghosts + ) + def EdgeLengthszWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='m_edge_lengths[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="m_edge_lengths[z]", level=level, include_ghosts=include_ghosts + ) + def FaceAreasxWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='m_face_areas[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="m_face_areas[x]", level=level, include_ghosts=include_ghosts + ) + def FaceAreasyWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='m_face_areas[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="m_face_areas[y]", level=level, include_ghosts=include_ghosts + ) + def FaceAreaszWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='m_face_areas[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="m_face_areas[z]", level=level, include_ghosts=include_ghosts + ) + def JxFPAmpereWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp_ampere[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp_ampere[x]", level=level, include_ghosts=include_ghosts + ) + def JyFPAmpereWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp_ampere[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp_ampere[y]", level=level, include_ghosts=include_ghosts + ) + def JzFPAmpereWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='current_fp_ampere[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="current_fp_ampere[z]", level=level, include_ghosts=include_ghosts + ) + def ExFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_E_fp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_E_fp[x]", level=level, include_ghosts=include_ghosts + ) + def EyFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_E_fp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_E_fp[y]", level=level, include_ghosts=include_ghosts + ) + def EzFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_E_fp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_E_fp[z]", level=level, include_ghosts=include_ghosts + ) + def BxFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_B_fp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_B_fp[x]", level=level, include_ghosts=include_ghosts + ) + def ByFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_B_fp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_B_fp[y]", level=level, include_ghosts=include_ghosts + ) + def BzFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_B_fp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_B_fp[z]", level=level, include_ghosts=include_ghosts + ) + def JxFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_j_fp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_j_fp[x]", level=level, include_ghosts=include_ghosts + ) + def JyFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_j_fp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_j_fp[y]", level=level, include_ghosts=include_ghosts + ) + def JzFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_j_fp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_j_fp[z]", level=level, include_ghosts=include_ghosts + ) + def FFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_F_fp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_F_fp", level=level, include_ghosts=include_ghosts + ) + def GFPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_G_fp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_G_fp", level=level, include_ghosts=include_ghosts + ) + def ExCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_E_cp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_E_cp[x]", level=level, include_ghosts=include_ghosts + ) + def EyCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_E_cp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_E_cp[y]", level=level, include_ghosts=include_ghosts + ) + def EzCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_E_cp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_E_cp[z]", level=level, include_ghosts=include_ghosts + ) + def BxCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_B_cp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_B_cp[x]", level=level, include_ghosts=include_ghosts + ) + def ByCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_B_cp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_B_cp[y]", level=level, include_ghosts=include_ghosts + ) + def BzCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_B_cp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_B_cp[z]", level=level, include_ghosts=include_ghosts + ) + def JxCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_j_cp[x]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_j_cp[x]", level=level, include_ghosts=include_ghosts + ) + def JyCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_j_cp[y]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_j_cp[y]", level=level, include_ghosts=include_ghosts + ) + def JzCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_j_cp[z]', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_j_cp[z]", level=level, include_ghosts=include_ghosts + ) + def FCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_F_cp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_F_cp", level=level, include_ghosts=include_ghosts + ) + def GCPPMLWrapper(level=0, include_ghosts=False): - return _MultiFABWrapper(mf_name='pml_G_cp', level=level, include_ghosts=include_ghosts) + return _MultiFABWrapper( + mf_name="pml_G_cp", level=level, include_ghosts=include_ghosts + ) diff --git a/Python/pywarpx/particle_containers.py b/Python/pywarpx/particle_containers.py index 70471e24d1a..8af012f5e7b 100644 --- a/Python/pywarpx/particle_containers.py +++ b/Python/pywarpx/particle_containers.py @@ -29,10 +29,19 @@ def __init__(self, species_name): mypc = libwarpx.warpx.multi_particle_container() self.particle_container = mypc.get_particle_container_from_name(self.name) - - def add_particles(self, x=None, y=None, z=None, ux=None, uy=None, - uz=None, w=None, unique_particles=True, **kwargs): - ''' + def add_particles( + self, + x=None, + y=None, + z=None, + ux=None, + uy=None, + uz=None, + w=None, + unique_particles=True, + **kwargs, + ): + """ A function for adding particles to the WarpX simulation. Parameters @@ -58,7 +67,7 @@ def add_particles(self, x=None, y=None, z=None, ux=None, uy=None, kwargs : dict Containing an entry for all the extra particle attribute arrays. If an attribute is not given it will be set to 0. - ''' + """ # --- Get length of arrays, set to one for scalars lenx = np.size(x) @@ -87,32 +96,48 @@ def add_particles(self, x=None, y=None, z=None, ux=None, uy=None, maxlen = max(maxlen, lenw) # --- Make sure that the lengths of the input parameters are consistent - assert x is None or lenx==maxlen or lenx==1, "Length of x doesn't match len of others" - assert y is None or leny==maxlen or leny==1, "Length of y doesn't match len of others" - assert z is None or lenz==maxlen or lenz==1, "Length of z doesn't match len of others" - assert ux is None or lenux==maxlen or lenux==1, "Length of ux doesn't match len of others" - assert uy is None or lenuy==maxlen or lenuy==1, "Length of uy doesn't match len of others" - assert uz is None or lenuz==maxlen or lenuz==1, "Length of uz doesn't match len of others" - assert w is None or lenw==maxlen or lenw==1, "Length of w doesn't match len of others" + assert ( + x is None or lenx == maxlen or lenx == 1 + ), "Length of x doesn't match len of others" + assert ( + y is None or leny == maxlen or leny == 1 + ), "Length of y doesn't match len of others" + assert ( + z is None or lenz == maxlen or lenz == 1 + ), "Length of z doesn't match len of others" + assert ( + ux is None or lenux == maxlen or lenux == 1 + ), "Length of ux doesn't match len of others" + assert ( + uy is None or lenuy == maxlen or lenuy == 1 + ), "Length of uy doesn't match len of others" + assert ( + uz is None or lenuz == maxlen or lenuz == 1 + ), "Length of uz doesn't match len of others" + assert ( + w is None or lenw == maxlen or lenw == 1 + ), "Length of w doesn't match len of others" for key, val in kwargs.items(): - assert np.size(val)==1 or len(val)==maxlen, f"Length of {key} doesn't match len of others" + assert ( + np.size(val) == 1 or len(val) == maxlen + ), f"Length of {key} doesn't match len of others" # --- Broadcast scalars into appropriate length arrays # --- If the parameter was not supplied, use the default value if lenx == 1: - x = np.full(maxlen, (x or 0.)) + x = np.full(maxlen, (x or 0.0)) if leny == 1: - y = np.full(maxlen, (y or 0.)) + y = np.full(maxlen, (y or 0.0)) if lenz == 1: - z = np.full(maxlen, (z or 0.)) + z = np.full(maxlen, (z or 0.0)) if lenux == 1: - ux = np.full(maxlen, (ux or 0.)) + ux = np.full(maxlen, (ux or 0.0)) if lenuy == 1: - uy = np.full(maxlen, (uy or 0.)) + uy = np.full(maxlen, (uy or 0.0)) if lenuz == 1: - uz = np.full(maxlen, (uz or 0.)) + uz = np.full(maxlen, (uz or 0.0)) if lenw == 1: - w = np.full(maxlen, (w or 0.)) + w = np.full(maxlen, (w or 0.0)) for key, val in kwargs.items(): if np.size(val) == 1: kwargs[key] = np.full(maxlen, val) @@ -122,22 +147,22 @@ def add_particles(self, x=None, y=None, z=None, ux=None, uy=None, built_in_attrs = libwarpx.dim # --- The three velocities built_in_attrs += 3 - if libwarpx.geometry_dim == 'rz': + if libwarpx.geometry_dim == "rz": # --- With RZ, there is also theta built_in_attrs += 1 # --- The number of extra attributes (including the weight) nattr = self.particle_container.num_real_comps - built_in_attrs attr = np.zeros((maxlen, nattr)) - attr[:,0] = w + attr[:, 0] = w # --- Note that the velocities are handled separately and not included in attr # --- (even though they are stored as attributes in the C++) for key, vals in kwargs.items(): - attr[:,self.particle_container.get_comp_index(key) - built_in_attrs] = vals + attr[:, self.particle_container.get_comp_index(key) - built_in_attrs] = vals nattr_int = 0 - attr_int = np.empty([0], dtype=np.int32) + attr_int = np.empty([0], dtype=np.int32) # TODO: expose ParticleReal through pyAMReX # and cast arrays to the correct types, before calling add_n_particles @@ -149,13 +174,23 @@ def add_particles(self, x=None, y=None, z=None, ux=None, uy=None, # uz = uz.astype(self._numpy_particlereal_dtype, copy=False) self.particle_container.add_n_particles( - 0, x.size, x, y, z, ux, uy, uz, - nattr, attr, nattr_int, attr_int, unique_particles + 0, + x.size, + x, + y, + z, + ux, + uy, + uz, + nattr, + attr, + nattr_int, + attr_int, + unique_particles, ) - def get_particle_count(self, local=False): - ''' + """ Get the number of particles of this species in the simulation. Parameters @@ -170,13 +205,13 @@ def get_particle_count(self, local=False): int An integer count of the number of particles - ''' + """ return self.particle_container.total_number_of_particles(True, local) - nps = property(get_particle_count) + nps = property(get_particle_count) def add_real_comp(self, pid_name, comm=True): - ''' + """ Add a real component to the particle data array. Parameters @@ -187,12 +222,11 @@ def add_real_comp(self, pid_name, comm=True): comm : bool Should the component be communicated - ''' + """ self.particle_container.add_real_comp(pid_name, comm) - def get_particle_real_arrays(self, comp_name, level, copy_to_host=False): - ''' + """ This returns a list of numpy or cupy arrays containing the particle real array data on each tile for this process. @@ -218,7 +252,7 @@ def get_particle_real_arrays(self, comp_name, level, copy_to_host=False): List of arrays The requested particle array data - ''' + """ comp_idx = self.particle_container.get_comp_index(comp_name) data_array = [] @@ -236,9 +270,8 @@ def get_particle_real_arrays(self, comp_name, level, copy_to_host=False): return data_array - def get_particle_int_arrays(self, comp_name, level, copy_to_host=False): - ''' + """ This returns a list of numpy or cupy arrays containing the particle int array data on each tile for this process. @@ -264,7 +297,7 @@ def get_particle_int_arrays(self, comp_name, level, copy_to_host=False): List of arrays The requested particle array data - ''' + """ comp_idx = self.particle_container.get_icomp_index(comp_name) data_array = [] @@ -282,9 +315,8 @@ def get_particle_int_arrays(self, comp_name, level, copy_to_host=False): return data_array - def get_particle_idcpu_arrays(self, level, copy_to_host=False): - ''' + """ This returns a list of numpy or cupy arrays containing the particle idcpu data on each tile for this process. @@ -306,7 +338,7 @@ def get_particle_idcpu_arrays(self, level, copy_to_host=False): List of arrays The requested particle array data - ''' + """ data_array = [] for pti in libwarpx.libwarpx_so.WarpXParIter(self.particle_container, level): soa = pti.soa() @@ -322,9 +354,8 @@ def get_particle_idcpu_arrays(self, level, copy_to_host=False): return data_array - def get_particle_idcpu(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle 'idcpu' numbers on each tile. @@ -343,13 +374,13 @@ def get_particle_idcpu(self, level=0, copy_to_host=False): List of arrays The requested particle idcpu - ''' + """ return self.get_particle_idcpu_arrays(level, copy_to_host=copy_to_host) - idcpu = property(get_particle_idcpu) + idcpu = property(get_particle_idcpu) def get_particle_id(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle 'id' numbers on each tile. @@ -368,13 +399,12 @@ def get_particle_id(self, level=0, copy_to_host=False): List of arrays The requested particle ids - ''' + """ idcpu = self.get_particle_idcpu(level, copy_to_host) return [libwarpx.amr.unpack_ids(tile) for tile in idcpu] - def get_particle_cpu(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle 'cpu' numbers on each tile. @@ -393,13 +423,12 @@ def get_particle_cpu(self, level=0, copy_to_host=False): List of arrays The requested particle cpus - ''' + """ idcpu = self.get_particle_idcpu(level, copy_to_host) return [libwarpx.amr.unpack_cpus(tile) for tile in idcpu] - def get_particle_x(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle 'x' positions on each tile. @@ -418,13 +447,13 @@ def get_particle_x(self, level=0, copy_to_host=False): List of arrays The requested particle x position - ''' - return self.get_particle_real_arrays('x', level, copy_to_host=copy_to_host) - xp = property(get_particle_x) + """ + return self.get_particle_real_arrays("x", level, copy_to_host=copy_to_host) + xp = property(get_particle_x) def get_particle_y(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle 'y' positions on each tile. @@ -443,13 +472,13 @@ def get_particle_y(self, level=0, copy_to_host=False): List of arrays The requested particle y position - ''' - return self.get_particle_real_arrays('y', level, copy_to_host=copy_to_host) - yp = property(get_particle_y) + """ + return self.get_particle_real_arrays("y", level, copy_to_host=copy_to_host) + yp = property(get_particle_y) def get_particle_r(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle 'r' positions on each tile. @@ -468,22 +497,24 @@ def get_particle_r(self, level=0, copy_to_host=False): List of arrays The requested particle r position - ''' + """ xp, cupy_status = load_cupy() - if libwarpx.geometry_dim == 'rz': + if libwarpx.geometry_dim == "rz": return self.get_particle_x(level, copy_to_host) - elif libwarpx.geometry_dim == '3d': + elif libwarpx.geometry_dim == "3d": x = self.get_particle_x(level, copy_to_host) y = self.get_particle_y(level, copy_to_host) return xp.sqrt(x**2 + y**2) - elif libwarpx.geometry_dim == '2d' or libwarpx.geometry_dim == '1d': - raise Exception('get_particle_r: There is no r coordinate with 1D or 2D Cartesian') - rp = property(get_particle_r) + elif libwarpx.geometry_dim == "2d" or libwarpx.geometry_dim == "1d": + raise Exception( + "get_particle_r: There is no r coordinate with 1D or 2D Cartesian" + ) + rp = property(get_particle_r) def get_particle_theta(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle theta on each tile. @@ -502,22 +533,24 @@ def get_particle_theta(self, level=0, copy_to_host=False): List of arrays The requested particle theta position - ''' + """ xp, cupy_status = load_cupy() - if libwarpx.geometry_dim == 'rz': - return self.get_particle_real_arrays('theta', level, copy_to_host) - elif libwarpx.geometry_dim == '3d': + if libwarpx.geometry_dim == "rz": + return self.get_particle_real_arrays("theta", level, copy_to_host) + elif libwarpx.geometry_dim == "3d": x = self.get_particle_x(level, copy_to_host) y = self.get_particle_y(level, copy_to_host) return xp.arctan2(y, x) - elif libwarpx.geometry_dim == '2d' or libwarpx.geometry_dim == '1d': - raise Exception('get_particle_theta: There is no theta coordinate with 1D or 2D Cartesian') - thetap = property(get_particle_theta) + elif libwarpx.geometry_dim == "2d" or libwarpx.geometry_dim == "1d": + raise Exception( + "get_particle_theta: There is no theta coordinate with 1D or 2D Cartesian" + ) + thetap = property(get_particle_theta) def get_particle_z(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle 'z' positions on each tile. @@ -536,13 +569,13 @@ def get_particle_z(self, level=0, copy_to_host=False): List of arrays The requested particle z position - ''' - return self.get_particle_real_arrays('z', level, copy_to_host=copy_to_host) - zp = property(get_particle_z) + """ + return self.get_particle_real_arrays("z", level, copy_to_host=copy_to_host) + zp = property(get_particle_z) def get_particle_weight(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle weight on each tile. @@ -561,13 +594,13 @@ def get_particle_weight(self, level=0, copy_to_host=False): List of arrays The requested particle weight - ''' - return self.get_particle_real_arrays('w', level, copy_to_host=copy_to_host) - wp = property(get_particle_weight) + """ + return self.get_particle_real_arrays("w", level, copy_to_host=copy_to_host) + wp = property(get_particle_weight) def get_particle_ux(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle x momentum on each tile. @@ -586,13 +619,13 @@ def get_particle_ux(self, level=0, copy_to_host=False): List of arrays The requested particle x momentum - ''' - return self.get_particle_real_arrays('ux', level, copy_to_host=copy_to_host) - uxp = property(get_particle_ux) + """ + return self.get_particle_real_arrays("ux", level, copy_to_host=copy_to_host) + uxp = property(get_particle_ux) def get_particle_uy(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle y momentum on each tile. @@ -611,13 +644,13 @@ def get_particle_uy(self, level=0, copy_to_host=False): List of arrays The requested particle y momentum - ''' - return self.get_particle_real_arrays('uy', level, copy_to_host=copy_to_host) - uyp = property(get_particle_uy) + """ + return self.get_particle_real_arrays("uy", level, copy_to_host=copy_to_host) + uyp = property(get_particle_uy) def get_particle_uz(self, level=0, copy_to_host=False): - ''' + """ Return a list of numpy or cupy arrays containing the particle z momentum on each tile. @@ -636,14 +669,14 @@ def get_particle_uz(self, level=0, copy_to_host=False): List of arrays The requested particle z momentum - ''' + """ - return self.get_particle_real_arrays('uz', level, copy_to_host=copy_to_host) - uzp = property(get_particle_uz) + return self.get_particle_real_arrays("uz", level, copy_to_host=copy_to_host) + uzp = property(get_particle_uz) def get_species_charge_sum(self, local=False): - ''' + """ Returns the total charge in the simulation due to the given species. Parameters @@ -651,39 +684,38 @@ def get_species_charge_sum(self, local=False): local : bool If True return total charge per processor - ''' + """ return self.particle_container.sum_particle_charge(local) - def getex(self): - raise NotImplementedError('Particle E fields not supported') - ex = property(getex) + raise NotImplementedError("Particle E fields not supported") + ex = property(getex) def getey(self): - raise NotImplementedError('Particle E fields not supported') - ey = property(getey) + raise NotImplementedError("Particle E fields not supported") + ey = property(getey) def getez(self): - raise NotImplementedError('Particle E fields not supported') - ez = property(getez) + raise NotImplementedError("Particle E fields not supported") + ez = property(getez) def getbx(self): - raise NotImplementedError('Particle B fields not supported') - bx = property(getbx) + raise NotImplementedError("Particle B fields not supported") + bx = property(getbx) def getby(self): - raise NotImplementedError('Particle B fields not supported') - by = property(getby) + raise NotImplementedError("Particle B fields not supported") + by = property(getby) def getbz(self): - raise NotImplementedError('Particle B fields not supported') - bz = property(getbz) + raise NotImplementedError("Particle B fields not supported") + bz = property(getbz) def deposit_charge_density(self, level, clear_rho=True, sync_rho=True): """ @@ -701,7 +733,7 @@ def deposit_charge_density(self, level, clear_rho=True, sync_rho=True): sync_rho : bool If True, perform MPI exchange and properly set boundary cells for rho_fp. """ - rho_fp = libwarpx.warpx.multifab(f'rho_fp[level={level}]') + rho_fp = libwarpx.warpx.multifab(f"rho_fp[level={level}]") if rho_fp is None: raise RuntimeError("Multifab `rho_fp` is not allocated.") @@ -712,7 +744,7 @@ def deposit_charge_density(self, level, clear_rho=True, sync_rho=True): # deposit the charge density from the desired species self.particle_container.deposit_charge(rho_fp, level) - if libwarpx.geometry_dim == 'rz': + if libwarpx.geometry_dim == "rz": libwarpx.warpx.apply_inverse_volume_scaling_to_charge_density(rho_fp, level) if sync_rho: @@ -728,9 +760,8 @@ class ParticleBoundaryBufferWrapper(object): def __init__(self): self.particle_buffer = libwarpx.warpx.get_particle_boundary_buffer() - def get_particle_boundary_buffer_size(self, species_name, boundary, local=False): - ''' + """ This returns the number of particles that have been scraped so far in the simulation from the specified boundary and of the specified species. @@ -747,15 +778,13 @@ def get_particle_boundary_buffer_size(self, species_name, boundary, local=False) local : bool Whether to only return the number of particles in the current processor's buffer - ''' + """ return self.particle_buffer.get_num_particles_in_container( - species_name, self._get_boundary_number(boundary), - local=local + species_name, self._get_boundary_number(boundary), local=local ) - def get_particle_boundary_buffer(self, species_name, boundary, comp_name, level): - ''' + """ This returns a list of numpy or cupy arrays containing the particle array data for a species that has been scraped by a specific simulation boundary. @@ -783,41 +812,43 @@ def get_particle_boundary_buffer(self, species_name, boundary, comp_name, level) level : int Which AMR level to retrieve scraped particle data from. - ''' + """ xp, cupy_status = load_cupy() part_container = self.particle_buffer.get_particle_container( species_name, self._get_boundary_number(boundary) ) data_array = [] - #loop over the real attributes + # loop over the real attributes if comp_name in part_container.real_comp_names: comp_idx = part_container.real_comp_names[comp_name] - for ii, pti in enumerate(libwarpx.libwarpx_so.BoundaryBufferParIter(part_container, level)): + for ii, pti in enumerate( + libwarpx.libwarpx_so.BoundaryBufferParIter(part_container, level) + ): soa = pti.soa() data_array.append(xp.array(soa.get_real_data(comp_idx), copy=False)) - #loop over the integer attributes + # loop over the integer attributes elif comp_name in part_container.int_comp_names: - comp_idx = part_container.int_comp_names[comp_name] - for ii, pti in enumerate(libwarpx.libwarpx_so.BoundaryBufferParIter(part_container, level)): + comp_idx = part_container.int_comp_names[comp_name] + for ii, pti in enumerate( + libwarpx.libwarpx_so.BoundaryBufferParIter(part_container, level) + ): soa = pti.soa() data_array.append(xp.array(soa.get_int_data(comp_idx), copy=False)) else: - raise RuntimeError('Name %s not found' %comp_name) + raise RuntimeError("Name %s not found" % comp_name) return data_array - def clear_buffer(self): - ''' + """ Clear the buffer that holds the particles lost at the boundaries. - ''' + """ self.particle_buffer.clear_particles() - def _get_boundary_number(self, boundary): - ''' + """ Utility function to find the boundary number given a boundary name. @@ -832,34 +863,36 @@ def _get_boundary_number(self, boundary): ------- int Integer index in the boundary scraper buffer for the given boundary. - ''' - if libwarpx.geometry_dim == '3d': - dimensions = {'x' : 0, 'y' : 1, 'z' : 2} - elif libwarpx.geometry_dim == '2d' or libwarpx.geometry_dim == 'rz': - dimensions = {'x' : 0, 'z' : 1} - elif libwarpx.geometry_dim == '1d': - dimensions = {'z' : 0} + """ + if libwarpx.geometry_dim == "3d": + dimensions = {"x": 0, "y": 1, "z": 2} + elif libwarpx.geometry_dim == "2d" or libwarpx.geometry_dim == "rz": + dimensions = {"x": 0, "z": 1} + elif libwarpx.geometry_dim == "1d": + dimensions = {"z": 0} else: raise RuntimeError(f"Unknown simulation geometry: {libwarpx.geometry_dim}") - if boundary != 'eb': + if boundary != "eb": boundary_parts = boundary.split("_") dim_num = dimensions[boundary_parts[0]] - if boundary_parts[1] == 'lo': + if boundary_parts[1] == "lo": side = 0 - elif boundary_parts[1] == 'hi': + elif boundary_parts[1] == "hi": side = 1 else: - raise RuntimeError(f'Unknown boundary specified: {boundary}') + raise RuntimeError(f"Unknown boundary specified: {boundary}") boundary_num = 2 * dim_num + side else: - if libwarpx.geometry_dim == '3d': + if libwarpx.geometry_dim == "3d": boundary_num = 6 - elif libwarpx.geometry_dim == '2d' or libwarpx.geometry_dim == 'rz': + elif libwarpx.geometry_dim == "2d" or libwarpx.geometry_dim == "rz": boundary_num = 4 - elif libwarpx.geometry_dim == '1d': + elif libwarpx.geometry_dim == "1d": boundary_num = 2 else: - raise RuntimeError(f"Unknown simulation geometry: {libwarpx.geometry_dim}") + raise RuntimeError( + f"Unknown simulation geometry: {libwarpx.geometry_dim}" + ) return boundary_num diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index 42c0313a6e9..0d51a8723b4 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -6,8 +6,8 @@ # # License: BSD-3-Clause-LBNL -"""Classes following the PICMI standard -""" +"""Classes following the PICMI standard""" + import os import re from dataclasses import dataclass @@ -17,21 +17,28 @@ import picmistandard import pywarpx +import pywarpx.callbacks -codename = 'warpx' +codename = "warpx" picmistandard.register_codename(codename) # dictionary to map field boundary conditions from picmistandard to WarpX BC_map = { - 'open':'pml', 'dirichlet':'pec', 'periodic':'periodic', 'damped':'damped', - 'absorbing_silver_mueller':'absorbing_silver_mueller', - 'neumann':'neumann', 'none':'none', None:'none' + "open": "pml", + "dirichlet": "pec", + "periodic": "periodic", + "damped": "damped", + "absorbing_silver_mueller": "absorbing_silver_mueller", + "neumann": "neumann", + "none": "none", + None: "none", } + class constants: # --- Put the constants in their own namespace # --- Values from WarpXConst.H - c = 299792458. + c = 299792458.0 ep0 = 8.8541878128e-12 mu0 = 1.25663706212e-06 q_e = 1.602176634e-19 @@ -40,6 +47,7 @@ class constants: hbar = 1.054571817e-34 kb = 1.380649e-23 + picmistandard.register_constants(constants) @@ -180,37 +188,47 @@ class Species(picmistandard.PICMI_Species): Dictionary of extra real particle attributes initialized from an expression that is a function of the variables (x, y, z, ux, uy, uz, t). """ - def init(self, kw): - if self.particle_type == 'electron': - if self.charge is None: self.charge = '-q_e' - if self.mass is None: self.mass = 'm_e' - elif self.particle_type == 'positron': - if self.charge is None: self.charge = 'q_e' - if self.mass is None: self.mass = 'm_e' - elif self.particle_type == 'proton': - if self.charge is None: self.charge = 'q_e' - if self.mass is None: self.mass = 'm_p' - elif self.particle_type == 'anti-proton': - if self.charge is None: self.charge = '-q_e' - if self.mass is None: self.mass = 'm_p' + def init(self, kw): + if self.particle_type == "electron": + if self.charge is None: + self.charge = "-q_e" + if self.mass is None: + self.mass = "m_e" + elif self.particle_type == "positron": + if self.charge is None: + self.charge = "q_e" + if self.mass is None: + self.mass = "m_e" + elif self.particle_type == "proton": + if self.charge is None: + self.charge = "q_e" + if self.mass is None: + self.mass = "m_p" + elif self.particle_type == "anti-proton": + if self.charge is None: + self.charge = "-q_e" + if self.mass is None: + self.mass = "m_p" else: if self.charge is None and self.charge_state is not None: - if self.charge_state == +1.: - self.charge = 'q_e' - elif self.charge_state == -1.: - self.charge = '-q_e' + if self.charge_state == +1.0: + self.charge = "q_e" + elif self.charge_state == -1.0: + self.charge = "-q_e" else: - self.charge = self.charge_state*constants.q_e + self.charge = self.charge_state * constants.q_e if self.particle_type is not None: # Match a string of the format '#nXx', with the '#n' optional isotope number. - m = re.match(r'(?P#[\d+])*(?P[A-Za-z]+)', self.particle_type) + m = re.match(r"(?P#[\d+])*(?P[A-Za-z]+)", self.particle_type) if m is not None: - element = periodictable.elements.symbol(m['sym']) - if m['iso'] is not None: - element = element[m['iso'][1:]] + element = periodictable.elements.symbol(m["sym"]) + if m["iso"] is not None: + element = element[m["iso"][1:]] if self.charge_state is not None: - assert self.charge_state <= element.number, Exception('%s charge state not valid'%self.particle_type) + assert self.charge_state <= element.number, Exception( + "%s charge state not valid" % self.particle_type + ) try: element = element.ion[self.charge_state] except ValueError: @@ -219,107 +237,139 @@ def init(self, kw): pass self.element = element if self.mass is None: - self.mass = element.mass*periodictable.constants.atomic_mass_constant + self.mass = ( + element.mass * periodictable.constants.atomic_mass_constant + ) else: raise Exception('The species "particle_type" is not known') - self.boost_adjust_transverse_positions = kw.pop('warpx_boost_adjust_transverse_positions', None) + self.boost_adjust_transverse_positions = kw.pop( + "warpx_boost_adjust_transverse_positions", None + ) # For the relativistic electrostatic solver - self.self_fields_required_precision = kw.pop('warpx_self_fields_required_precision', None) - self.self_fields_absolute_tolerance = kw.pop('warpx_self_fields_absolute_tolerance', None) - self.self_fields_max_iters = kw.pop('warpx_self_fields_max_iters', None) - self.self_fields_verbosity = kw.pop('warpx_self_fields_verbosity', None) - self.save_previous_position = kw.pop('warpx_save_previous_position', None) - self.do_not_deposit = kw.pop('warpx_do_not_deposit', None) - self.do_not_push = kw.pop('warpx_do_not_push', None) - self.do_not_gather = kw.pop('warpx_do_not_gather', None) - self.random_theta = kw.pop('warpx_random_theta', None) + self.self_fields_required_precision = kw.pop( + "warpx_self_fields_required_precision", None + ) + self.self_fields_absolute_tolerance = kw.pop( + "warpx_self_fields_absolute_tolerance", None + ) + self.self_fields_max_iters = kw.pop("warpx_self_fields_max_iters", None) + self.self_fields_verbosity = kw.pop("warpx_self_fields_verbosity", None) + self.save_previous_position = kw.pop("warpx_save_previous_position", None) + self.do_not_deposit = kw.pop("warpx_do_not_deposit", None) + self.do_not_push = kw.pop("warpx_do_not_push", None) + self.do_not_gather = kw.pop("warpx_do_not_gather", None) + self.random_theta = kw.pop("warpx_random_theta", None) # For particle reflection - self.reflection_model_xlo = kw.pop('warpx_reflection_model_xlo', None) - self.reflection_model_xhi = kw.pop('warpx_reflection_model_xhi', None) - self.reflection_model_ylo = kw.pop('warpx_reflection_model_ylo', None) - self.reflection_model_yhi = kw.pop('warpx_reflection_model_yhi', None) - self.reflection_model_zlo = kw.pop('warpx_reflection_model_zlo', None) - self.reflection_model_zhi = kw.pop('warpx_reflection_model_zhi', None) + self.reflection_model_xlo = kw.pop("warpx_reflection_model_xlo", None) + self.reflection_model_xhi = kw.pop("warpx_reflection_model_xhi", None) + self.reflection_model_ylo = kw.pop("warpx_reflection_model_ylo", None) + self.reflection_model_yhi = kw.pop("warpx_reflection_model_yhi", None) + self.reflection_model_zlo = kw.pop("warpx_reflection_model_zlo", None) + self.reflection_model_zhi = kw.pop("warpx_reflection_model_zhi", None) # self.reflection_model_eb = kw.pop('warpx_reflection_model_eb', None) # For the scraper buffer - self.save_particles_at_xlo = kw.pop('warpx_save_particles_at_xlo', None) - self.save_particles_at_xhi = kw.pop('warpx_save_particles_at_xhi', None) - self.save_particles_at_ylo = kw.pop('warpx_save_particles_at_ylo', None) - self.save_particles_at_yhi = kw.pop('warpx_save_particles_at_yhi', None) - self.save_particles_at_zlo = kw.pop('warpx_save_particles_at_zlo', None) - self.save_particles_at_zhi = kw.pop('warpx_save_particles_at_zhi', None) - self.save_particles_at_eb = kw.pop('warpx_save_particles_at_eb', None) + self.save_particles_at_xlo = kw.pop("warpx_save_particles_at_xlo", None) + self.save_particles_at_xhi = kw.pop("warpx_save_particles_at_xhi", None) + self.save_particles_at_ylo = kw.pop("warpx_save_particles_at_ylo", None) + self.save_particles_at_yhi = kw.pop("warpx_save_particles_at_yhi", None) + self.save_particles_at_zlo = kw.pop("warpx_save_particles_at_zlo", None) + self.save_particles_at_zhi = kw.pop("warpx_save_particles_at_zhi", None) + self.save_particles_at_eb = kw.pop("warpx_save_particles_at_eb", None) # Resampling settings - self.do_resampling = kw.pop('warpx_do_resampling', None) - self.resampling_algorithm = kw.pop('warpx_resampling_algorithm', None) - self.resampling_min_ppc = kw.pop('warpx_resampling_min_ppc', None) - self.resampling_trigger_intervals = kw.pop('warpx_resampling_trigger_intervals', None) - self.resampling_triggering_max_avg_ppc = kw.pop('warpx_resampling_trigger_max_avg_ppc', None) - self.resampling_algorithm_target_weight = kw.pop('warpx_resampling_algorithm_target_weight', None) - self.resampling_algorithm_velocity_grid_type = kw.pop('warpx_resampling_algorithm_velocity_grid_type', None) - self.resampling_algorithm_delta_ur = kw.pop('warpx_resampling_algorithm_delta_ur', None) - self.resampling_algorithm_n_theta = kw.pop('warpx_resampling_algorithm_n_theta', None) - self.resampling_algorithm_n_phi = kw.pop('warpx_resampling_algorithm_n_phi', None) - self.resampling_algorithm_delta_u = kw.pop('warpx_resampling_algorithm_delta_u', None) - if self.resampling_algorithm_delta_u is not None and np.size(self.resampling_algorithm_delta_u) == 1: - self.resampling_algorithm_delta_u = [self.resampling_algorithm_delta_u]*3 + self.do_resampling = kw.pop("warpx_do_resampling", None) + self.resampling_algorithm = kw.pop("warpx_resampling_algorithm", None) + self.resampling_min_ppc = kw.pop("warpx_resampling_min_ppc", None) + self.resampling_trigger_intervals = kw.pop( + "warpx_resampling_trigger_intervals", None + ) + self.resampling_triggering_max_avg_ppc = kw.pop( + "warpx_resampling_trigger_max_avg_ppc", None + ) + self.resampling_algorithm_target_weight = kw.pop( + "warpx_resampling_algorithm_target_weight", None + ) + self.resampling_algorithm_velocity_grid_type = kw.pop( + "warpx_resampling_algorithm_velocity_grid_type", None + ) + self.resampling_algorithm_delta_ur = kw.pop( + "warpx_resampling_algorithm_delta_ur", None + ) + self.resampling_algorithm_n_theta = kw.pop( + "warpx_resampling_algorithm_n_theta", None + ) + self.resampling_algorithm_n_phi = kw.pop( + "warpx_resampling_algorithm_n_phi", None + ) + self.resampling_algorithm_delta_u = kw.pop( + "warpx_resampling_algorithm_delta_u", None + ) + if ( + self.resampling_algorithm_delta_u is not None + and np.size(self.resampling_algorithm_delta_u) == 1 + ): + self.resampling_algorithm_delta_u = [self.resampling_algorithm_delta_u] * 3 # extra particle attributes - self.extra_int_attributes = kw.pop('warpx_add_int_attributes', None) - self.extra_real_attributes = kw.pop('warpx_add_real_attributes', None) - - def species_initialize_inputs(self, layout, - initialize_self_fields = False, - injection_plane_position = None, - injection_plane_normal_vector = None): + self.extra_int_attributes = kw.pop("warpx_add_int_attributes", None) + self.extra_real_attributes = kw.pop("warpx_add_real_attributes", None) + + def species_initialize_inputs( + self, + layout, + initialize_self_fields=False, + injection_plane_position=None, + injection_plane_normal_vector=None, + ): self.species_number = len(pywarpx.particles.species_names) if self.name is None: - self.name = 'species{}'.format(self.species_number) + self.name = "species{}".format(self.species_number) pywarpx.particles.species_names.append(self.name) if initialize_self_fields is None: initialize_self_fields = False - self.species = pywarpx.Bucket.Bucket(self.name, - mass = self.mass, - charge = self.charge, - injection_style = None, - initialize_self_fields = int(initialize_self_fields), - boost_adjust_transverse_positions = self.boost_adjust_transverse_positions, - self_fields_required_precision = self.self_fields_required_precision, - self_fields_absolute_tolerance = self.self_fields_absolute_tolerance, - self_fields_max_iters = self.self_fields_max_iters, - self_fields_verbosity = self.self_fields_verbosity, - save_particles_at_xlo = self.save_particles_at_xlo, - save_particles_at_xhi = self.save_particles_at_xhi, - save_particles_at_ylo = self.save_particles_at_ylo, - save_particles_at_yhi = self.save_particles_at_yhi, - save_particles_at_zlo = self.save_particles_at_zlo, - save_particles_at_zhi = self.save_particles_at_zhi, - save_particles_at_eb = self.save_particles_at_eb, - save_previous_position = self.save_previous_position, - do_not_deposit = self.do_not_deposit, - do_not_push = self.do_not_push, - do_not_gather = self.do_not_gather, - random_theta = self.random_theta, - do_resampling=self.do_resampling, - resampling_algorithm=self.resampling_algorithm, - resampling_min_ppc=self.resampling_min_ppc, - resampling_trigger_intervals=self.resampling_trigger_intervals, - resampling_trigger_max_avg_ppc=self.resampling_triggering_max_avg_ppc, - resampling_algorithm_target_weight=self.resampling_algorithm_target_weight, - resampling_algorithm_velocity_grid_type=self.resampling_algorithm_velocity_grid_type, - resampling_algorithm_delta_ur=self.resampling_algorithm_delta_ur, - resampling_algorithm_n_theta=self.resampling_algorithm_n_theta, - resampling_algorithm_n_phi=self.resampling_algorithm_n_phi, - resampling_algorithm_delta_u=self.resampling_algorithm_delta_u) + self.species = pywarpx.Bucket.Bucket( + self.name, + mass=self.mass, + charge=self.charge, + injection_style=None, + initialize_self_fields=int(initialize_self_fields), + boost_adjust_transverse_positions=self.boost_adjust_transverse_positions, + self_fields_required_precision=self.self_fields_required_precision, + self_fields_absolute_tolerance=self.self_fields_absolute_tolerance, + self_fields_max_iters=self.self_fields_max_iters, + self_fields_verbosity=self.self_fields_verbosity, + save_particles_at_xlo=self.save_particles_at_xlo, + save_particles_at_xhi=self.save_particles_at_xhi, + save_particles_at_ylo=self.save_particles_at_ylo, + save_particles_at_yhi=self.save_particles_at_yhi, + save_particles_at_zlo=self.save_particles_at_zlo, + save_particles_at_zhi=self.save_particles_at_zhi, + save_particles_at_eb=self.save_particles_at_eb, + save_previous_position=self.save_previous_position, + do_not_deposit=self.do_not_deposit, + do_not_push=self.do_not_push, + do_not_gather=self.do_not_gather, + random_theta=self.random_theta, + do_resampling=self.do_resampling, + resampling_algorithm=self.resampling_algorithm, + resampling_min_ppc=self.resampling_min_ppc, + resampling_trigger_intervals=self.resampling_trigger_intervals, + resampling_trigger_max_avg_ppc=self.resampling_triggering_max_avg_ppc, + resampling_algorithm_target_weight=self.resampling_algorithm_target_weight, + resampling_algorithm_velocity_grid_type=self.resampling_algorithm_velocity_grid_type, + resampling_algorithm_delta_ur=self.resampling_algorithm_delta_ur, + resampling_algorithm_n_theta=self.resampling_algorithm_n_theta, + resampling_algorithm_n_phi=self.resampling_algorithm_n_phi, + resampling_algorithm_delta_u=self.resampling_algorithm_delta_u, + ) # add reflection models self.species.add_new_attr("reflection_model_xlo(E)", self.reflection_model_xlo) @@ -334,11 +384,15 @@ def species_initialize_inputs(self, layout, if self.extra_int_attributes is not None: self.species.addIntegerAttributes = self.extra_int_attributes.keys() for attr, function in self.extra_int_attributes.items(): - self.species.add_new_attr('attribute.'+attr+'(x,y,z,ux,uy,uz,t)', function) + self.species.add_new_attr( + "attribute." + attr + "(x,y,z,ux,uy,uz,t)", function + ) if self.extra_real_attributes is not None: self.species.addRealAttributes = self.extra_real_attributes.keys() for attr, function in self.extra_real_attributes.items(): - self.species.add_new_attr('attribute.'+attr+'(x,y,z,ux,uy,uz,t)', function) + self.species.add_new_attr( + "attribute." + attr + "(x,y,z,ux,uy,uz,t)", function + ) pywarpx.Particles.particles_list.append(self.species) @@ -346,101 +400,155 @@ def species_initialize_inputs(self, layout, distributions_is_list = np.iterable(self.initial_distribution) layout_is_list = np.iterable(layout) if not distributions_is_list and not layout_is_list: - self.initial_distribution.distribution_initialize_inputs(self.species_number, layout, self.species, - self.density_scale, '') + self.initial_distribution.distribution_initialize_inputs( + self.species_number, layout, self.species, self.density_scale, "" + ) elif distributions_is_list and (layout_is_list or layout is None): - assert layout is None or (len(self.initial_distribution) == len(layout)),\ - Exception('The initial distribution and layout lists must have the same lenth') - source_names = [f'dist{i}' for i in range(len(self.initial_distribution))] + assert layout is None or ( + len(self.initial_distribution) == len(layout) + ), Exception( + "The initial distribution and layout lists must have the same lenth" + ) + source_names = [ + f"dist{i}" for i in range(len(self.initial_distribution)) + ] self.species.injection_sources = source_names for i, dist in enumerate(self.initial_distribution): layout_i = layout[i] if layout is not None else None - dist.distribution_initialize_inputs(self.species_number, layout_i, self.species, - self.density_scale, source_names[i]) + dist.distribution_initialize_inputs( + self.species_number, + layout_i, + self.species, + self.density_scale, + source_names[i], + ) else: - raise Exception('The initial distribution and layout must both be scalars or both be lists') + raise Exception( + "The initial distribution and layout must both be scalars or both be lists" + ) if injection_plane_position is not None: if injection_plane_normal_vector is not None: - assert injection_plane_normal_vector[0] == 0. and injection_plane_normal_vector[1] == 0.,\ - Exception('Rigid injection can only be done along z') + assert ( + injection_plane_normal_vector[0] == 0.0 + and injection_plane_normal_vector[1] == 0.0 + ), Exception("Rigid injection can only be done along z") pywarpx.particles.rigid_injected_species.append(self.name) self.species.rigid_advance = 1 self.species.zinject_plane = injection_plane_position picmistandard.PICMI_MultiSpecies.Species_class = Species + + class MultiSpecies(picmistandard.PICMI_MultiSpecies): - def species_initialize_inputs(self, layout, - initialize_self_fields = False, - injection_plane_position = None, - injection_plane_normal_vector = None): + def species_initialize_inputs( + self, + layout, + initialize_self_fields=False, + injection_plane_position=None, + injection_plane_normal_vector=None, + ): for species in self.species_instances_list: - species.species_initialize_inputs(layout, - initialize_self_fields, - injection_plane_position, - injection_plane_normal_vector) + species.species_initialize_inputs( + layout, + initialize_self_fields, + injection_plane_position, + injection_plane_normal_vector, + ) class GaussianBunchDistribution(picmistandard.PICMI_GaussianBunchDistribution): def init(self, kw): - self.do_symmetrize = kw.pop('warpx_do_symmetrize', None) - self.symmetrization_order = kw.pop('warpx_symmetrization_order', None) - - def distribution_initialize_inputs(self, species_number, layout, species, density_scale, source_name): - species.add_new_group_attr(source_name, 'injection_style', "gaussian_beam") - species.add_new_group_attr(source_name, 'x_m', self.centroid_position[0]) - species.add_new_group_attr(source_name, 'y_m', self.centroid_position[1]) - species.add_new_group_attr(source_name, 'z_m', self.centroid_position[2]) - species.add_new_group_attr(source_name, 'x_rms', self.rms_bunch_size[0]) - species.add_new_group_attr(source_name, 'y_rms', self.rms_bunch_size[1]) - species.add_new_group_attr(source_name, 'z_rms', self.rms_bunch_size[2]) + self.do_symmetrize = kw.pop("warpx_do_symmetrize", None) + self.symmetrization_order = kw.pop("warpx_symmetrization_order", None) + + def distribution_initialize_inputs( + self, species_number, layout, species, density_scale, source_name + ): + species.add_new_group_attr(source_name, "injection_style", "gaussian_beam") + species.add_new_group_attr(source_name, "x_m", self.centroid_position[0]) + species.add_new_group_attr(source_name, "y_m", self.centroid_position[1]) + species.add_new_group_attr(source_name, "z_m", self.centroid_position[2]) + species.add_new_group_attr(source_name, "x_rms", self.rms_bunch_size[0]) + species.add_new_group_attr(source_name, "y_rms", self.rms_bunch_size[1]) + species.add_new_group_attr(source_name, "z_rms", self.rms_bunch_size[2]) # --- Only PseudoRandomLayout is supported - species.add_new_group_attr(source_name, 'npart', layout.n_macroparticles) + species.add_new_group_attr(source_name, "npart", layout.n_macroparticles) # --- Calculate the total charge. Note that charge might be a string instead of a number. charge = species.charge - if charge == 'q_e' or charge == '+q_e': + if charge == "q_e" or charge == "+q_e": charge = constants.q_e - elif charge == '-q_e': + elif charge == "-q_e": charge = -constants.q_e - species.add_new_group_attr(source_name, 'q_tot', self.n_physical_particles*charge) + species.add_new_group_attr( + source_name, "q_tot", self.n_physical_particles * charge + ) if density_scale is not None: - species.add_new_group_attr(source_name, 'q_tot', density_scale) + species.add_new_group_attr(source_name, "q_tot", density_scale) # --- The PICMI standard doesn't yet have a way of specifying these values. # --- They should default to the size of the domain. They are not typically # --- necessary though since any particles outside the domain are rejected. - #species.xmin - #species.xmax - #species.ymin - #species.ymax - #species.zmin - #species.zmax + # species.xmin + # species.xmax + # species.ymin + # species.ymax + # species.zmin + # species.zmax # --- Note that WarpX takes gamma*beta as input - if np.any(np.not_equal(self.velocity_divergence, 0.)): - species.add_new_group_attr(source_name, 'momentum_distribution_type', "radial_expansion") - species.add_new_group_attr(source_name, 'u_over_r', self.velocity_divergence[0]/constants.c) - #species.add_new_group_attr(source_name, 'u_over_y', self.velocity_divergence[1]/constants.c) - #species.add_new_group_attr(source_name, 'u_over_z', self.velocity_divergence[2]/constants.c) - elif np.any(np.not_equal(self.rms_velocity, 0.)): - species.add_new_group_attr(source_name, 'momentum_distribution_type', "gaussian") - species.add_new_group_attr(source_name, 'ux_m', self.centroid_velocity[0]/constants.c) - species.add_new_group_attr(source_name, 'uy_m', self.centroid_velocity[1]/constants.c) - species.add_new_group_attr(source_name, 'uz_m', self.centroid_velocity[2]/constants.c) - species.add_new_group_attr(source_name, 'ux_th', self.rms_velocity[0]/constants.c) - species.add_new_group_attr(source_name, 'uy_th', self.rms_velocity[1]/constants.c) - species.add_new_group_attr(source_name, 'uz_th', self.rms_velocity[2]/constants.c) + if np.any(np.not_equal(self.velocity_divergence, 0.0)): + species.add_new_group_attr( + source_name, "momentum_distribution_type", "radial_expansion" + ) + species.add_new_group_attr( + source_name, "u_over_r", self.velocity_divergence[0] / constants.c + ) + # species.add_new_group_attr(source_name, 'u_over_y', self.velocity_divergence[1]/constants.c) + # species.add_new_group_attr(source_name, 'u_over_z', self.velocity_divergence[2]/constants.c) + elif np.any(np.not_equal(self.rms_velocity, 0.0)): + species.add_new_group_attr( + source_name, "momentum_distribution_type", "gaussian" + ) + species.add_new_group_attr( + source_name, "ux_m", self.centroid_velocity[0] / constants.c + ) + species.add_new_group_attr( + source_name, "uy_m", self.centroid_velocity[1] / constants.c + ) + species.add_new_group_attr( + source_name, "uz_m", self.centroid_velocity[2] / constants.c + ) + species.add_new_group_attr( + source_name, "ux_th", self.rms_velocity[0] / constants.c + ) + species.add_new_group_attr( + source_name, "uy_th", self.rms_velocity[1] / constants.c + ) + species.add_new_group_attr( + source_name, "uz_th", self.rms_velocity[2] / constants.c + ) else: - species.add_new_group_attr(source_name, 'momentum_distribution_type', "constant") - species.add_new_group_attr(source_name, 'ux', self.centroid_velocity[0]/constants.c) - species.add_new_group_attr(source_name, 'uy', self.centroid_velocity[1]/constants.c) - species.add_new_group_attr(source_name, 'uz', self.centroid_velocity[2]/constants.c) + species.add_new_group_attr( + source_name, "momentum_distribution_type", "constant" + ) + species.add_new_group_attr( + source_name, "ux", self.centroid_velocity[0] / constants.c + ) + species.add_new_group_attr( + source_name, "uy", self.centroid_velocity[1] / constants.c + ) + species.add_new_group_attr( + source_name, "uz", self.centroid_velocity[2] / constants.c + ) - species.add_new_group_attr(source_name, 'do_symmetrize', self.do_symmetrize) - species.add_new_group_attr(source_name, 'symmetrization_order', self.symmetrization_order) + species.add_new_group_attr(source_name, "do_symmetrize", self.do_symmetrize) + species.add_new_group_attr( + source_name, "symmetrization_order", self.symmetrization_order + ) class DensityDistributionBase(object): @@ -448,7 +556,7 @@ class DensityDistributionBase(object): captures universal initialization logic.""" def set_mangle_dict(self): - if not hasattr(self, 'mangle_dict'): + if not hasattr(self, "mangle_dict"): self.mangle_dict = None if hasattr(self, "user_defined_kw") and self.mangle_dict is None: @@ -459,102 +567,193 @@ def set_mangle_dict(self): def set_species_attributes(self, species, layout, source_name): if isinstance(layout, GriddedLayout): # --- Note that the grid attribute of GriddedLayout is ignored - species.add_new_group_attr(source_name, 'injection_style', "nuniformpercell") - species.add_new_group_attr(source_name, 'num_particles_per_cell_each_dim', layout.n_macroparticle_per_cell) + species.add_new_group_attr( + source_name, "injection_style", "nuniformpercell" + ) + species.add_new_group_attr( + source_name, + "num_particles_per_cell_each_dim", + layout.n_macroparticle_per_cell, + ) elif isinstance(layout, PseudoRandomLayout): - assert (layout.n_macroparticles_per_cell is not None), Exception('WarpX only supports n_macroparticles_per_cell for the PseudoRandomLayout with this distribution') - species.add_new_group_attr(source_name, 'injection_style', "nrandompercell") - species.add_new_group_attr(source_name, 'num_particles_per_cell', layout.n_macroparticles_per_cell) + assert layout.n_macroparticles_per_cell is not None, Exception( + "WarpX only supports n_macroparticles_per_cell for the PseudoRandomLayout with this distribution" + ) + species.add_new_group_attr(source_name, "injection_style", "nrandompercell") + species.add_new_group_attr( + source_name, "num_particles_per_cell", layout.n_macroparticles_per_cell + ) else: - raise Exception('WarpX does not support the specified layout for this distribution') + raise Exception( + "WarpX does not support the specified layout for this distribution" + ) - species.add_new_group_attr(source_name, 'xmin', self.lower_bound[0]) - species.add_new_group_attr(source_name, 'xmax', self.upper_bound[0]) - species.add_new_group_attr(source_name, 'ymin', self.lower_bound[1]) - species.add_new_group_attr(source_name, 'ymax', self.upper_bound[1]) - species.add_new_group_attr(source_name, 'zmin', self.lower_bound[2]) - species.add_new_group_attr(source_name, 'zmax', self.upper_bound[2]) + species.add_new_group_attr(source_name, "xmin", self.lower_bound[0]) + species.add_new_group_attr(source_name, "xmax", self.upper_bound[0]) + species.add_new_group_attr(source_name, "ymin", self.lower_bound[1]) + species.add_new_group_attr(source_name, "ymax", self.upper_bound[1]) + species.add_new_group_attr(source_name, "zmin", self.lower_bound[2]) + species.add_new_group_attr(source_name, "zmax", self.upper_bound[2]) if self.fill_in: - species.add_new_group_attr(source_name, 'do_continuous_injection', 1) + species.add_new_group_attr(source_name, "do_continuous_injection", 1) # --- Note that WarpX takes gamma*beta as input - if (hasattr(self, "momentum_spread_expressions") - and np.any(np.not_equal(self.momentum_spread_expressions, None)) + if hasattr(self, "momentum_spread_expressions") and np.any( + np.not_equal(self.momentum_spread_expressions, None) ): - species.momentum_distribution_type = 'gaussian_parse_momentum_function' - self.setup_parse_momentum_functions(species, source_name, self.momentum_expressions, '_m', self.directed_velocity) - self.setup_parse_momentum_functions(species, source_name, self.momentum_spread_expressions, '_th', [0.,0.,0.]) - elif (hasattr(self, "momentum_expressions") - and np.any(np.not_equal(self.momentum_expressions, None)) + species.momentum_distribution_type = "gaussian_parse_momentum_function" + self.setup_parse_momentum_functions( + species, + source_name, + self.momentum_expressions, + "_m", + self.directed_velocity, + ) + self.setup_parse_momentum_functions( + species, + source_name, + self.momentum_spread_expressions, + "_th", + [0.0, 0.0, 0.0], + ) + elif hasattr(self, "momentum_expressions") and np.any( + np.not_equal(self.momentum_expressions, None) ): - species.add_new_group_attr(source_name, 'momentum_distribution_type', 'parse_momentum_function') - self.setup_parse_momentum_functions(species, source_name, self.momentum_expressions, '', self.directed_velocity) - elif np.any(np.not_equal(self.rms_velocity, 0.)): - species.add_new_group_attr(source_name, 'momentum_distribution_type', "gaussian") - species.add_new_group_attr(source_name, 'ux_m', self.directed_velocity[0]/constants.c) - species.add_new_group_attr(source_name, 'uy_m', self.directed_velocity[1]/constants.c) - species.add_new_group_attr(source_name, 'uz_m', self.directed_velocity[2]/constants.c) - species.add_new_group_attr(source_name, 'ux_th', self.rms_velocity[0]/constants.c) - species.add_new_group_attr(source_name, 'uy_th', self.rms_velocity[1]/constants.c) - species.add_new_group_attr(source_name, 'uz_th', self.rms_velocity[2]/constants.c) + species.add_new_group_attr( + source_name, "momentum_distribution_type", "parse_momentum_function" + ) + self.setup_parse_momentum_functions( + species, + source_name, + self.momentum_expressions, + "", + self.directed_velocity, + ) + elif np.any(np.not_equal(self.rms_velocity, 0.0)): + species.add_new_group_attr( + source_name, "momentum_distribution_type", "gaussian" + ) + species.add_new_group_attr( + source_name, "ux_m", self.directed_velocity[0] / constants.c + ) + species.add_new_group_attr( + source_name, "uy_m", self.directed_velocity[1] / constants.c + ) + species.add_new_group_attr( + source_name, "uz_m", self.directed_velocity[2] / constants.c + ) + species.add_new_group_attr( + source_name, "ux_th", self.rms_velocity[0] / constants.c + ) + species.add_new_group_attr( + source_name, "uy_th", self.rms_velocity[1] / constants.c + ) + species.add_new_group_attr( + source_name, "uz_th", self.rms_velocity[2] / constants.c + ) else: - species.add_new_group_attr(source_name, 'momentum_distribution_type', "constant") - species.add_new_group_attr(source_name, 'ux', self.directed_velocity[0]/constants.c) - species.add_new_group_attr(source_name, 'uy', self.directed_velocity[1]/constants.c) - species.add_new_group_attr(source_name, 'uz', self.directed_velocity[2]/constants.c) + species.add_new_group_attr( + source_name, "momentum_distribution_type", "constant" + ) + species.add_new_group_attr( + source_name, "ux", self.directed_velocity[0] / constants.c + ) + species.add_new_group_attr( + source_name, "uy", self.directed_velocity[1] / constants.c + ) + species.add_new_group_attr( + source_name, "uz", self.directed_velocity[2] / constants.c + ) - def setup_parse_momentum_functions(self, species, source_name, expressions, suffix, defaults): - for sdir, idir in zip(['x', 'y', 'z'], [0, 1, 2]): + if hasattr(self, "density_min"): + species.add_new_group_attr(source_name, "density_min", self.density_min) + if hasattr(self, "density_max"): + species.add_new_group_attr(source_name, "density_max", self.density_max) + + def setup_parse_momentum_functions( + self, species, source_name, expressions, suffix, defaults + ): + for sdir, idir in zip(["x", "y", "z"], [0, 1, 2]): if expressions[idir] is not None: - expression = pywarpx.my_constants.mangle_expression(expressions[idir], self.mangle_dict) + expression = pywarpx.my_constants.mangle_expression( + expressions[idir], self.mangle_dict + ) else: - expression = f'{defaults[idir]}' - species.add_new_group_attr(source_name, f'momentum_function_u{sdir}{suffix}(x,y,z)', f'({expression})/{constants.c}') - + expression = f"{defaults[idir]}" + species.add_new_group_attr( + source_name, + f"momentum_function_u{sdir}{suffix}(x,y,z)", + f"({expression})/{constants.c}", + ) -class UniformFluxDistribution(picmistandard.PICMI_UniformFluxDistribution, DensityDistributionBase): - def distribution_initialize_inputs(self, species_number, layout, species, density_scale, source_name): +class UniformFluxDistribution( + picmistandard.PICMI_UniformFluxDistribution, DensityDistributionBase +): + def distribution_initialize_inputs( + self, species_number, layout, species, density_scale, source_name + ): self.fill_in = False self.set_mangle_dict() self.set_species_attributes(species, layout, source_name) - species.add_new_group_attr(source_name, 'flux_profile', "constant") - species.add_new_group_attr(source_name, 'flux', self.flux) + species.add_new_group_attr(source_name, "flux_profile", "constant") + species.add_new_group_attr(source_name, "flux", self.flux) if density_scale is not None: - species.add_new_group_attr(source_name, 'flux', density_scale) - species.add_new_group_attr(source_name, 'flux_normal_axis', self.flux_normal_axis) - species.add_new_group_attr(source_name, 'surface_flux_pos', self.surface_flux_position) - species.add_new_group_attr(source_name, 'flux_direction', self.flux_direction) - species.add_new_group_attr(source_name, 'flux_tmin', self.flux_tmin) - species.add_new_group_attr(source_name, 'flux_tmax', self.flux_tmax) + species.add_new_group_attr(source_name, "flux", density_scale) + species.add_new_group_attr( + source_name, "flux_normal_axis", self.flux_normal_axis + ) + species.add_new_group_attr( + source_name, "surface_flux_pos", self.surface_flux_position + ) + species.add_new_group_attr(source_name, "flux_direction", self.flux_direction) + species.add_new_group_attr(source_name, "flux_tmin", self.flux_tmin) + species.add_new_group_attr(source_name, "flux_tmax", self.flux_tmax) # --- Use specific attributes for flux injection - species.add_new_group_attr(source_name, 'injection_style', "nfluxpercell") - assert (isinstance(layout, PseudoRandomLayout)), Exception('UniformFluxDistribution only supports the PseudoRandomLayout in WarpX') + species.add_new_group_attr(source_name, "injection_style", "nfluxpercell") + assert isinstance(layout, PseudoRandomLayout), Exception( + "UniformFluxDistribution only supports the PseudoRandomLayout in WarpX" + ) if self.gaussian_flux_momentum_distribution: - species.add_new_group_attr(source_name, 'momentum_distribution_type', "gaussianflux") - + species.add_new_group_attr( + source_name, "momentum_distribution_type", "gaussianflux" + ) -class UniformDistribution(picmistandard.PICMI_UniformDistribution, DensityDistributionBase): - def distribution_initialize_inputs(self, species_number, layout, species, density_scale, source_name): +class UniformDistribution( + picmistandard.PICMI_UniformDistribution, DensityDistributionBase +): + def distribution_initialize_inputs( + self, species_number, layout, species, density_scale, source_name + ): self.set_mangle_dict() self.set_species_attributes(species, layout, source_name) # --- Only constant density is supported by this class - species.add_new_group_attr(source_name, 'profile', "constant") - species.add_new_group_attr(source_name, 'density', self.density) + species.add_new_group_attr(source_name, "profile", "constant") + species.add_new_group_attr(source_name, "density", self.density) if density_scale is not None: - species.add_new_group_attr(source_name, 'density', density_scale) + species.add_new_group_attr(source_name, "density", density_scale) -class AnalyticDistribution(picmistandard.PICMI_AnalyticDistribution, DensityDistributionBase): +class AnalyticDistribution( + picmistandard.PICMI_AnalyticDistribution, DensityDistributionBase +): """ Parameters ---------- + warpx_density_min: float + Minimum plasma density. No particle is injected where the density is + below this value. + + warpx_density_max: float + Maximum plasma density. The density at each point is the minimum between + the value given in the profile, and density_max. + warpx_momentum_spread_expressions: list of string Analytic expressions describing the gamma*velocity spread for each axis [m/s]. Expressions should be in terms of the position, written as 'x', 'y', and 'z'. @@ -562,41 +761,68 @@ class AnalyticDistribution(picmistandard.PICMI_AnalyticDistribution, DensityDist For any axis not supplied (set to None), zero will be used. """ - def init(self, kw): - self.momentum_spread_expressions = kw.pop('warpx_momentum_spread_expressions', [None, None, None]) - def distribution_initialize_inputs(self, species_number, layout, species, density_scale, source_name): + def init(self, kw): + self.density_min = kw.pop("warpx_density_min", None) + self.density_max = kw.pop("warpx_density_max", None) + self.momentum_spread_expressions = kw.pop( + "warpx_momentum_spread_expressions", [None, None, None] + ) + def distribution_initialize_inputs( + self, species_number, layout, species, density_scale, source_name + ): self.set_mangle_dict() self.set_species_attributes(species, layout, source_name) - species.add_new_group_attr(source_name, 'profile', "parse_density_function") - expression = pywarpx.my_constants.mangle_expression(self.density_expression, self.mangle_dict) + species.add_new_group_attr(source_name, "profile", "parse_density_function") + expression = pywarpx.my_constants.mangle_expression( + self.density_expression, self.mangle_dict + ) if density_scale is None: - species.add_new_group_attr(source_name, 'density_function(x,y,z)', expression) + species.add_new_group_attr( + source_name, "density_function(x,y,z)", expression + ) else: - species.add_new_group_attr(source_name, 'density_function(x,y,z)', "{}*({})".format(density_scale, expression)) + species.add_new_group_attr( + source_name, + "density_function(x,y,z)", + "{}*({})".format(density_scale, expression), + ) class ParticleListDistribution(picmistandard.PICMI_ParticleListDistribution): def init(self, kw): pass - def distribution_initialize_inputs(self, species_number, layout, species, density_scale, source_name): - - species.add_new_group_attr(source_name, 'injection_style', "multipleparticles") - species.add_new_group_attr(source_name, 'multiple_particles_pos_x', self.x) - species.add_new_group_attr(source_name, 'multiple_particles_pos_y', self.y) - species.add_new_group_attr(source_name, 'multiple_particles_pos_z', self.z) - species.add_new_group_attr(source_name, 'multiple_particles_ux', np.array(self.ux)/constants.c) - species.add_new_group_attr(source_name, 'multiple_particles_uy', np.array(self.uy)/constants.c) - species.add_new_group_attr(source_name, 'multiple_particles_uz', np.array(self.uz)/constants.c) - species.add_new_group_attr(source_name, 'multiple_particles_weight', self.weight) + def distribution_initialize_inputs( + self, species_number, layout, species, density_scale, source_name + ): + species.add_new_group_attr(source_name, "injection_style", "multipleparticles") + species.add_new_group_attr(source_name, "multiple_particles_pos_x", self.x) + species.add_new_group_attr(source_name, "multiple_particles_pos_y", self.y) + species.add_new_group_attr(source_name, "multiple_particles_pos_z", self.z) + species.add_new_group_attr( + source_name, "multiple_particles_ux", np.array(self.ux) / constants.c + ) + species.add_new_group_attr( + source_name, "multiple_particles_uy", np.array(self.uy) / constants.c + ) + species.add_new_group_attr( + source_name, "multiple_particles_uz", np.array(self.uz) / constants.c + ) + species.add_new_group_attr( + source_name, "multiple_particles_weight", self.weight + ) if density_scale is not None: - species.add_new_group_attr(source_name, 'multiple_particles_weight', self.weight*density_scale) + species.add_new_group_attr( + source_name, "multiple_particles_weight", self.weight * density_scale + ) -class ParticleDistributionPlanarInjector(picmistandard.PICMI_ParticleDistributionPlanarInjector): +class ParticleDistributionPlanarInjector( + picmistandard.PICMI_ParticleDistributionPlanarInjector +): pass @@ -607,11 +833,12 @@ class GriddedLayout(picmistandard.PICMI_GriddedLayout): class PseudoRandomLayout(picmistandard.PICMI_PseudoRandomLayout): def init(self, kw): if self.seed is not None: - print('Warning: WarpX does not support specifying the random number seed in PseudoRandomLayout') + print( + "Warning: WarpX does not support specifying the random number seed in PseudoRandomLayout" + ) class BinomialSmoother(picmistandard.PICMI_BinomialSmoother): - def smoother_initialize_inputs(self, solver): pywarpx.warpx.use_filter = 1 pywarpx.warpx.use_filter_compensation = bool(np.all(self.compensation)) @@ -623,7 +850,7 @@ def smoother_initialize_inputs(self, solver): len(self.n_pass) except TypeError: # If not, make it a vector - self.n_pass = solver.grid.number_of_dimensions*[self.n_pass] + self.n_pass = solver.grid.number_of_dimensions * [self.n_pass] pywarpx.warpx.filter_npass_each_dir = self.n_pass @@ -681,34 +908,35 @@ class CylindricalGrid(picmistandard.PICMI_CylindricalGrid): specify the thermal speed for each species in the form {``: u_th}. Note: u_th = sqrt(T*q_e/mass)/clight with T in eV. """ + def init(self, kw): - self.max_grid_size = kw.pop('warpx_max_grid_size', 32) - self.max_grid_size_x = kw.pop('warpx_max_grid_size_x', None) - self.max_grid_size_y = kw.pop('warpx_max_grid_size_y', None) - self.blocking_factor = kw.pop('warpx_blocking_factor', None) - self.blocking_factor_x = kw.pop('warpx_blocking_factor_x', None) - self.blocking_factor_y = kw.pop('warpx_blocking_factor_y', None) - - self.potential_xmin = kw.pop('warpx_potential_lo_r', None) - self.potential_xmax = kw.pop('warpx_potential_hi_r', None) + self.max_grid_size = kw.pop("warpx_max_grid_size", 32) + self.max_grid_size_x = kw.pop("warpx_max_grid_size_x", None) + self.max_grid_size_y = kw.pop("warpx_max_grid_size_y", None) + self.blocking_factor = kw.pop("warpx_blocking_factor", None) + self.blocking_factor_x = kw.pop("warpx_blocking_factor_x", None) + self.blocking_factor_y = kw.pop("warpx_blocking_factor_y", None) + + self.potential_xmin = kw.pop("warpx_potential_lo_r", None) + self.potential_xmax = kw.pop("warpx_potential_hi_r", None) self.potential_ymin = None self.potential_ymax = None - self.potential_zmin = kw.pop('warpx_potential_lo_z', None) - self.potential_zmax = kw.pop('warpx_potential_hi_z', None) - self.reflect_all_velocities = kw.pop('warpx_reflect_all_velocities', None) + self.potential_zmin = kw.pop("warpx_potential_lo_z", None) + self.potential_zmax = kw.pop("warpx_potential_hi_z", None) + self.reflect_all_velocities = kw.pop("warpx_reflect_all_velocities", None) - self.start_moving_window_step = kw.pop('warpx_start_moving_window_step', None) - self.end_moving_window_step = kw.pop('warpx_end_moving_window_step', None) + self.start_moving_window_step = kw.pop("warpx_start_moving_window_step", None) + self.end_moving_window_step = kw.pop("warpx_end_moving_window_step", None) # Geometry # Set these as soon as the information is available # (since these are needed to determine which shared object to load) - pywarpx.geometry.dims = 'RZ' + pywarpx.geometry.dims = "RZ" pywarpx.geometry.prob_lo = self.lower_bound # physical domain pywarpx.geometry.prob_hi = self.upper_bound # if a thermal boundary is used for particles, get the thermal speeds - self.thermal_boundary_u_th = kw.pop('warpx_boundary_u_th', None) + self.thermal_boundary_u_th = kw.pop("warpx_boundary_u_th", None) def grid_initialize_inputs(self): pywarpx.amr.n_cell = self.number_of_cells @@ -722,37 +950,56 @@ def grid_initialize_inputs(self): pywarpx.amr.blocking_factor_x = self.blocking_factor_x pywarpx.amr.blocking_factor_y = self.blocking_factor_y - assert self.lower_bound[0] >= 0., Exception('Lower radial boundary must be >= 0.') - assert self.lower_boundary_conditions[0] != 'periodic' and self.upper_boundary_conditions[0] != 'periodic', Exception('Radial boundaries can not be periodic') + assert self.lower_bound[0] >= 0.0, Exception( + "Lower radial boundary must be >= 0." + ) + assert ( + self.lower_boundary_conditions[0] != "periodic" + and self.upper_boundary_conditions[0] != "periodic" + ), Exception("Radial boundaries can not be periodic") pywarpx.warpx.n_rz_azimuthal_modes = self.n_azimuthal_modes # Boundary conditions - pywarpx.boundary.field_lo = [BC_map[bc] for bc in self.lower_boundary_conditions] - pywarpx.boundary.field_hi = [BC_map[bc] for bc in self.upper_boundary_conditions] + pywarpx.boundary.field_lo = [ + BC_map[bc] for bc in self.lower_boundary_conditions + ] + pywarpx.boundary.field_hi = [ + BC_map[bc] for bc in self.upper_boundary_conditions + ] pywarpx.boundary.particle_lo = self.lower_boundary_conditions_particles pywarpx.boundary.particle_hi = self.upper_boundary_conditions_particles pywarpx.boundary.reflect_all_velocities = self.reflect_all_velocities if self.thermal_boundary_u_th is not None: for name, val in self.thermal_boundary_u_th.items(): - pywarpx.boundary.__setattr__(f'{name}.u_th', val) + pywarpx.boundary.__setattr__(f"{name}.u_th", val) - if self.moving_window_velocity is not None and np.any(np.not_equal(self.moving_window_velocity, 0.)): + if self.moving_window_velocity is not None and np.any( + np.not_equal(self.moving_window_velocity, 0.0) + ): pywarpx.warpx.do_moving_window = 1 - if self.moving_window_velocity[0] != 0.: - pywarpx.warpx.moving_window_dir = 'r' - pywarpx.warpx.moving_window_v = self.moving_window_velocity[0]/constants.c # in units of the speed of light - if self.moving_window_velocity[1] != 0.: - pywarpx.warpx.moving_window_dir = 'z' - pywarpx.warpx.moving_window_v = self.moving_window_velocity[1]/constants.c # in units of the speed of light + if self.moving_window_velocity[0] != 0.0: + pywarpx.warpx.moving_window_dir = "r" + pywarpx.warpx.moving_window_v = ( + self.moving_window_velocity[0] / constants.c + ) # in units of the speed of light + if self.moving_window_velocity[1] != 0.0: + pywarpx.warpx.moving_window_dir = "z" + pywarpx.warpx.moving_window_v = ( + self.moving_window_velocity[1] / constants.c + ) # in units of the speed of light pywarpx.warpx.start_moving_window_step = self.start_moving_window_step pywarpx.warpx.end_moving_window_step = self.end_moving_window_step if self.refined_regions: - assert len(self.refined_regions) == 1, Exception('WarpX only supports one refined region.') - assert self.refined_regions[0][0] == 1, Exception('The one refined region can only be level 1') + assert len(self.refined_regions) == 1, Exception( + "WarpX only supports one refined region." + ) + assert self.refined_regions[0][0] == 1, Exception( + "The one refined region can only be level 1" + ) pywarpx.amr.max_level = 1 pywarpx.warpx.fine_tag_lo = self.refined_regions[0][1] pywarpx.warpx.fine_tag_hi = self.refined_regions[0][2] @@ -797,31 +1044,32 @@ class Cartesian1DGrid(picmistandard.PICMI_Cartesian1DGrid): specify the thermal speed for each species in the form {``: u_th}. Note: u_th = sqrt(T*q_e/mass)/clight with T in eV. """ + def init(self, kw): - self.max_grid_size = kw.pop('warpx_max_grid_size', 32) - self.max_grid_size_x = kw.pop('warpx_max_grid_size_x', None) - self.blocking_factor = kw.pop('warpx_blocking_factor', None) - self.blocking_factor_x = kw.pop('warpx_blocking_factor_x', None) + self.max_grid_size = kw.pop("warpx_max_grid_size", 32) + self.max_grid_size_x = kw.pop("warpx_max_grid_size_x", None) + self.blocking_factor = kw.pop("warpx_blocking_factor", None) + self.blocking_factor_x = kw.pop("warpx_blocking_factor_x", None) self.potential_xmin = None self.potential_xmax = None self.potential_ymin = None self.potential_ymax = None - self.potential_zmin = kw.pop('warpx_potential_lo_z', None) - self.potential_zmax = kw.pop('warpx_potential_hi_z', None) + self.potential_zmin = kw.pop("warpx_potential_lo_z", None) + self.potential_zmax = kw.pop("warpx_potential_hi_z", None) - self.start_moving_window_step = kw.pop('warpx_start_moving_window_step', None) - self.end_moving_window_step = kw.pop('warpx_end_moving_window_step', None) + self.start_moving_window_step = kw.pop("warpx_start_moving_window_step", None) + self.end_moving_window_step = kw.pop("warpx_end_moving_window_step", None) # Geometry # Set these as soon as the information is available # (since these are needed to determine which shared object to load) - pywarpx.geometry.dims = '1' + pywarpx.geometry.dims = "1" pywarpx.geometry.prob_lo = self.lower_bound # physical domain pywarpx.geometry.prob_hi = self.upper_bound # if a thermal boundary is used for particles, get the thermal speeds - self.thermal_boundary_u_th = kw.pop('warpx_boundary_u_th', None) + self.thermal_boundary_u_th = kw.pop("warpx_boundary_u_th", None) def grid_initialize_inputs(self): pywarpx.amr.n_cell = self.number_of_cells @@ -834,27 +1082,39 @@ def grid_initialize_inputs(self): pywarpx.amr.blocking_factor_x = self.blocking_factor_x # Boundary conditions - pywarpx.boundary.field_lo = [BC_map[bc] for bc in self.lower_boundary_conditions] - pywarpx.boundary.field_hi = [BC_map[bc] for bc in self.upper_boundary_conditions] + pywarpx.boundary.field_lo = [ + BC_map[bc] for bc in self.lower_boundary_conditions + ] + pywarpx.boundary.field_hi = [ + BC_map[bc] for bc in self.upper_boundary_conditions + ] pywarpx.boundary.particle_lo = self.lower_boundary_conditions_particles pywarpx.boundary.particle_hi = self.upper_boundary_conditions_particles if self.thermal_boundary_u_th is not None: for name, val in self.thermal_boundary_u_th.items(): - pywarpx.boundary.__setattr__(f'{name}.u_th', val) + pywarpx.boundary.__setattr__(f"{name}.u_th", val) - if self.moving_window_velocity is not None and np.any(np.not_equal(self.moving_window_velocity, 0.)): + if self.moving_window_velocity is not None and np.any( + np.not_equal(self.moving_window_velocity, 0.0) + ): pywarpx.warpx.do_moving_window = 1 - if self.moving_window_velocity[0] != 0.: - pywarpx.warpx.moving_window_dir = 'z' - pywarpx.warpx.moving_window_v = self.moving_window_velocity[0]/constants.c # in units of the speed of light + if self.moving_window_velocity[0] != 0.0: + pywarpx.warpx.moving_window_dir = "z" + pywarpx.warpx.moving_window_v = ( + self.moving_window_velocity[0] / constants.c + ) # in units of the speed of light pywarpx.warpx.start_moving_window_step = self.start_moving_window_step pywarpx.warpx.end_moving_window_step = self.end_moving_window_step if self.refined_regions: - assert len(self.refined_regions) == 1, Exception('WarpX only supports one refined region.') - assert self.refined_regions[0][0] == 1, Exception('The one refined region can only be level 1') + assert len(self.refined_regions) == 1, Exception( + "WarpX only supports one refined region." + ) + assert self.refined_regions[0][0] == 1, Exception( + "The one refined region can only be level 1" + ) pywarpx.amr.max_level = 1 pywarpx.warpx.fine_tag_lo = self.refined_regions[0][1] pywarpx.warpx.fine_tag_hi = self.refined_regions[0][2] @@ -862,6 +1122,7 @@ def grid_initialize_inputs(self): else: pywarpx.amr.max_level = 0 + class Cartesian2DGrid(picmistandard.PICMI_Cartesian2DGrid): """ See `Input Parameters `__ for more information. @@ -910,33 +1171,34 @@ class Cartesian2DGrid(picmistandard.PICMI_Cartesian2DGrid): specify the thermal speed for each species in the form {``: u_th}. Note: u_th = sqrt(T*q_e/mass)/clight with T in eV. """ + def init(self, kw): - self.max_grid_size = kw.pop('warpx_max_grid_size', 32) - self.max_grid_size_x = kw.pop('warpx_max_grid_size_x', None) - self.max_grid_size_y = kw.pop('warpx_max_grid_size_y', None) - self.blocking_factor = kw.pop('warpx_blocking_factor', None) - self.blocking_factor_x = kw.pop('warpx_blocking_factor_x', None) - self.blocking_factor_y = kw.pop('warpx_blocking_factor_y', None) - - self.potential_xmin = kw.pop('warpx_potential_lo_x', None) - self.potential_xmax = kw.pop('warpx_potential_hi_x', None) + self.max_grid_size = kw.pop("warpx_max_grid_size", 32) + self.max_grid_size_x = kw.pop("warpx_max_grid_size_x", None) + self.max_grid_size_y = kw.pop("warpx_max_grid_size_y", None) + self.blocking_factor = kw.pop("warpx_blocking_factor", None) + self.blocking_factor_x = kw.pop("warpx_blocking_factor_x", None) + self.blocking_factor_y = kw.pop("warpx_blocking_factor_y", None) + + self.potential_xmin = kw.pop("warpx_potential_lo_x", None) + self.potential_xmax = kw.pop("warpx_potential_hi_x", None) self.potential_ymin = None self.potential_ymax = None - self.potential_zmin = kw.pop('warpx_potential_lo_z', None) - self.potential_zmax = kw.pop('warpx_potential_hi_z', None) + self.potential_zmin = kw.pop("warpx_potential_lo_z", None) + self.potential_zmax = kw.pop("warpx_potential_hi_z", None) - self.start_moving_window_step = kw.pop('warpx_start_moving_window_step', None) - self.end_moving_window_step = kw.pop('warpx_end_moving_window_step', None) + self.start_moving_window_step = kw.pop("warpx_start_moving_window_step", None) + self.end_moving_window_step = kw.pop("warpx_end_moving_window_step", None) # Geometry # Set these as soon as the information is available # (since these are needed to determine which shared object to load) - pywarpx.geometry.dims = '2' + pywarpx.geometry.dims = "2" pywarpx.geometry.prob_lo = self.lower_bound # physical domain pywarpx.geometry.prob_hi = self.upper_bound # if a thermal boundary is used for particles, get the thermal speeds - self.thermal_boundary_u_th = kw.pop('warpx_boundary_u_th', None) + self.thermal_boundary_u_th = kw.pop("warpx_boundary_u_th", None) def grid_initialize_inputs(self): pywarpx.amr.n_cell = self.number_of_cells @@ -951,30 +1213,44 @@ def grid_initialize_inputs(self): pywarpx.amr.blocking_factor_y = self.blocking_factor_y # Boundary conditions - pywarpx.boundary.field_lo = [BC_map[bc] for bc in self.lower_boundary_conditions] - pywarpx.boundary.field_hi = [BC_map[bc] for bc in self.upper_boundary_conditions] + pywarpx.boundary.field_lo = [ + BC_map[bc] for bc in self.lower_boundary_conditions + ] + pywarpx.boundary.field_hi = [ + BC_map[bc] for bc in self.upper_boundary_conditions + ] pywarpx.boundary.particle_lo = self.lower_boundary_conditions_particles pywarpx.boundary.particle_hi = self.upper_boundary_conditions_particles if self.thermal_boundary_u_th is not None: for name, val in self.thermal_boundary_u_th.items(): - pywarpx.boundary.__setattr__(f'{name}.u_th', val) + pywarpx.boundary.__setattr__(f"{name}.u_th", val) - if self.moving_window_velocity is not None and np.any(np.not_equal(self.moving_window_velocity, 0.)): + if self.moving_window_velocity is not None and np.any( + np.not_equal(self.moving_window_velocity, 0.0) + ): pywarpx.warpx.do_moving_window = 1 - if self.moving_window_velocity[0] != 0.: - pywarpx.warpx.moving_window_dir = 'x' - pywarpx.warpx.moving_window_v = self.moving_window_velocity[0]/constants.c # in units of the speed of light - if self.moving_window_velocity[1] != 0.: - pywarpx.warpx.moving_window_dir = 'z' - pywarpx.warpx.moving_window_v = self.moving_window_velocity[1]/constants.c # in units of the speed of light + if self.moving_window_velocity[0] != 0.0: + pywarpx.warpx.moving_window_dir = "x" + pywarpx.warpx.moving_window_v = ( + self.moving_window_velocity[0] / constants.c + ) # in units of the speed of light + if self.moving_window_velocity[1] != 0.0: + pywarpx.warpx.moving_window_dir = "z" + pywarpx.warpx.moving_window_v = ( + self.moving_window_velocity[1] / constants.c + ) # in units of the speed of light pywarpx.warpx.start_moving_window_step = self.start_moving_window_step pywarpx.warpx.end_moving_window_step = self.end_moving_window_step if self.refined_regions: - assert len(self.refined_regions) == 1, Exception('WarpX only supports one refined region.') - assert self.refined_regions[0][0] == 1, Exception('The one refined region can only be level 1') + assert len(self.refined_regions) == 1, Exception( + "WarpX only supports one refined region." + ) + assert self.refined_regions[0][0] == 1, Exception( + "The one refined region can only be level 1" + ) pywarpx.amr.max_level = 1 pywarpx.warpx.fine_tag_lo = self.refined_regions[0][1] pywarpx.warpx.fine_tag_hi = self.refined_regions[0][2] @@ -1043,35 +1319,36 @@ class Cartesian3DGrid(picmistandard.PICMI_Cartesian3DGrid): specify the thermal speed for each species in the form {``: u_th}. Note: u_th = sqrt(T*q_e/mass)/clight with T in eV. """ + def init(self, kw): - self.max_grid_size = kw.pop('warpx_max_grid_size', 32) - self.max_grid_size_x = kw.pop('warpx_max_grid_size_x', None) - self.max_grid_size_y = kw.pop('warpx_max_grid_size_y', None) - self.max_grid_size_z = kw.pop('warpx_max_grid_size_z', None) - self.blocking_factor = kw.pop('warpx_blocking_factor', None) - self.blocking_factor_x = kw.pop('warpx_blocking_factor_x', None) - self.blocking_factor_y = kw.pop('warpx_blocking_factor_y', None) - self.blocking_factor_z = kw.pop('warpx_blocking_factor_z', None) - - self.potential_xmin = kw.pop('warpx_potential_lo_x', None) - self.potential_xmax = kw.pop('warpx_potential_hi_x', None) - self.potential_ymin = kw.pop('warpx_potential_lo_y', None) - self.potential_ymax = kw.pop('warpx_potential_hi_y', None) - self.potential_zmin = kw.pop('warpx_potential_lo_z', None) - self.potential_zmax = kw.pop('warpx_potential_hi_z', None) - - self.start_moving_window_step = kw.pop('warpx_start_moving_window_step', None) - self.end_moving_window_step = kw.pop('warpx_end_moving_window_step', None) + self.max_grid_size = kw.pop("warpx_max_grid_size", 32) + self.max_grid_size_x = kw.pop("warpx_max_grid_size_x", None) + self.max_grid_size_y = kw.pop("warpx_max_grid_size_y", None) + self.max_grid_size_z = kw.pop("warpx_max_grid_size_z", None) + self.blocking_factor = kw.pop("warpx_blocking_factor", None) + self.blocking_factor_x = kw.pop("warpx_blocking_factor_x", None) + self.blocking_factor_y = kw.pop("warpx_blocking_factor_y", None) + self.blocking_factor_z = kw.pop("warpx_blocking_factor_z", None) + + self.potential_xmin = kw.pop("warpx_potential_lo_x", None) + self.potential_xmax = kw.pop("warpx_potential_hi_x", None) + self.potential_ymin = kw.pop("warpx_potential_lo_y", None) + self.potential_ymax = kw.pop("warpx_potential_hi_y", None) + self.potential_zmin = kw.pop("warpx_potential_lo_z", None) + self.potential_zmax = kw.pop("warpx_potential_hi_z", None) + + self.start_moving_window_step = kw.pop("warpx_start_moving_window_step", None) + self.end_moving_window_step = kw.pop("warpx_end_moving_window_step", None) # Geometry # Set these as soon as the information is available # (since these are needed to determine which shared object to load) - pywarpx.geometry.dims = '3' + pywarpx.geometry.dims = "3" pywarpx.geometry.prob_lo = self.lower_bound # physical domain pywarpx.geometry.prob_hi = self.upper_bound # if a thermal boundary is used for particles, get the thermal speeds - self.thermal_boundary_u_th = kw.pop('warpx_boundary_u_th', None) + self.thermal_boundary_u_th = kw.pop("warpx_boundary_u_th", None) def grid_initialize_inputs(self): pywarpx.amr.n_cell = self.number_of_cells @@ -1088,33 +1365,49 @@ def grid_initialize_inputs(self): pywarpx.amr.blocking_factor_z = self.blocking_factor_z # Boundary conditions - pywarpx.boundary.field_lo = [BC_map[bc] for bc in self.lower_boundary_conditions] - pywarpx.boundary.field_hi = [BC_map[bc] for bc in self.upper_boundary_conditions] + pywarpx.boundary.field_lo = [ + BC_map[bc] for bc in self.lower_boundary_conditions + ] + pywarpx.boundary.field_hi = [ + BC_map[bc] for bc in self.upper_boundary_conditions + ] pywarpx.boundary.particle_lo = self.lower_boundary_conditions_particles pywarpx.boundary.particle_hi = self.upper_boundary_conditions_particles if self.thermal_boundary_u_th is not None: for name, val in self.thermal_boundary_u_th.items(): - pywarpx.boundary.__setattr__(f'{name}.u_th', val) + pywarpx.boundary.__setattr__(f"{name}.u_th", val) - if self.moving_window_velocity is not None and np.any(np.not_equal(self.moving_window_velocity, 0.)): + if self.moving_window_velocity is not None and np.any( + np.not_equal(self.moving_window_velocity, 0.0) + ): pywarpx.warpx.do_moving_window = 1 - if self.moving_window_velocity[0] != 0.: - pywarpx.warpx.moving_window_dir = 'x' - pywarpx.warpx.moving_window_v = self.moving_window_velocity[0]/constants.c # in units of the speed of light - if self.moving_window_velocity[1] != 0.: - pywarpx.warpx.moving_window_dir = 'y' - pywarpx.warpx.moving_window_v = self.moving_window_velocity[1]/constants.c # in units of the speed of light - if self.moving_window_velocity[2] != 0.: - pywarpx.warpx.moving_window_dir = 'z' - pywarpx.warpx.moving_window_v = self.moving_window_velocity[2]/constants.c # in units of the speed of light + if self.moving_window_velocity[0] != 0.0: + pywarpx.warpx.moving_window_dir = "x" + pywarpx.warpx.moving_window_v = ( + self.moving_window_velocity[0] / constants.c + ) # in units of the speed of light + if self.moving_window_velocity[1] != 0.0: + pywarpx.warpx.moving_window_dir = "y" + pywarpx.warpx.moving_window_v = ( + self.moving_window_velocity[1] / constants.c + ) # in units of the speed of light + if self.moving_window_velocity[2] != 0.0: + pywarpx.warpx.moving_window_dir = "z" + pywarpx.warpx.moving_window_v = ( + self.moving_window_velocity[2] / constants.c + ) # in units of the speed of light pywarpx.warpx.start_moving_window_step = self.start_moving_window_step pywarpx.warpx.end_moving_window_step = self.end_moving_window_step if self.refined_regions: - assert len(self.refined_regions) == 1, Exception('WarpX only supports one refined region.') - assert self.refined_regions[0][0] == 1, Exception('The one refined region can only be level 1') + assert len(self.refined_regions) == 1, Exception( + "WarpX only supports one refined region." + ) + assert self.refined_regions[0][0] == 1, Exception( + "The one refined region can only be level 1" + ) pywarpx.amr.max_level = 1 pywarpx.warpx.fine_tag_lo = self.refined_regions[0][1] pywarpx.warpx.fine_tag_hi = self.refined_regions[0][2] @@ -1165,30 +1458,37 @@ class ElectromagneticSolver(picmistandard.PICMI_ElectromagneticSolver): warpx_do_pml_j_damping: bool, default=False Whether to do damping of J in the PML """ - def init(self, kw): - assert self.method is None or self.method in ['Yee', 'CKC', 'PSATD', 'ECT'], Exception("Only 'Yee', 'CKC', 'PSATD', and 'ECT' are supported") - - self.pml_ncell = kw.pop('warpx_pml_ncell', None) - if self.method == 'PSATD': - self.psatd_periodic_single_box_fft = kw.pop('warpx_periodic_single_box_fft', None) - self.psatd_current_correction = kw.pop('warpx_current_correction', None) - self.psatd_update_with_rho = kw.pop('warpx_psatd_update_with_rho', None) - self.psatd_do_time_averaging = kw.pop('warpx_psatd_do_time_averaging', None) - self.psatd_J_in_time = kw.pop('warpx_psatd_J_in_time', None) - self.psatd_rho_in_time = kw.pop('warpx_psatd_rho_in_time', None) + def init(self, kw): + assert self.method is None or self.method in [ + "Yee", + "CKC", + "PSATD", + "ECT", + ], Exception("Only 'Yee', 'CKC', 'PSATD', and 'ECT' are supported") + + self.pml_ncell = kw.pop("warpx_pml_ncell", None) + + if self.method == "PSATD": + self.psatd_periodic_single_box_fft = kw.pop( + "warpx_periodic_single_box_fft", None + ) + self.psatd_current_correction = kw.pop("warpx_current_correction", None) + self.psatd_update_with_rho = kw.pop("warpx_psatd_update_with_rho", None) + self.psatd_do_time_averaging = kw.pop("warpx_psatd_do_time_averaging", None) + self.psatd_J_in_time = kw.pop("warpx_psatd_J_in_time", None) + self.psatd_rho_in_time = kw.pop("warpx_psatd_rho_in_time", None) - self.do_pml_in_domain = kw.pop('warpx_do_pml_in_domain', None) - self.pml_has_particles = kw.pop('warpx_pml_has_particles', None) - self.do_pml_j_damping = kw.pop('warpx_do_pml_j_damping', None) + self.do_pml_in_domain = kw.pop("warpx_do_pml_in_domain", None) + self.pml_has_particles = kw.pop("warpx_pml_has_particles", None) + self.do_pml_j_damping = kw.pop("warpx_do_pml_j_damping", None) def solver_initialize_inputs(self): - self.grid.grid_initialize_inputs() pywarpx.warpx.pml_ncell = self.pml_ncell - if self.method == 'PSATD': + if self.method == "PSATD": pywarpx.psatd.periodic_single_box_fft = self.psatd_periodic_single_box_fft pywarpx.psatd.current_correction = self.psatd_current_correction pywarpx.psatd.update_with_rho = self.psatd_update_with_rho @@ -1210,8 +1510,14 @@ def solver_initialize_inputs(self): if self.galilean_velocity is not None: if self.grid.number_of_dimensions == 2: - self.galilean_velocity = [self.galilean_velocity[0], 0., self.galilean_velocity[1]] - pywarpx.psatd.v_galilean = np.array(self.galilean_velocity)/constants.c + self.galilean_velocity = [ + self.galilean_velocity[0], + 0.0, + self.galilean_velocity[1], + ] + pywarpx.psatd.v_galilean = ( + np.array(self.galilean_velocity) / constants.c + ) # --- Same method names are used, though mapped to lower case. pywarpx.algo.maxwell_solver = self.method @@ -1233,6 +1539,220 @@ def solver_initialize_inputs(self): pywarpx.warpx.do_pml_j_damping = self.do_pml_j_damping +class ExplicitEvolveScheme(picmistandard.base._ClassWithInit): + """ + Sets up the explicit evolve scheme + """ + + def solver_scheme_initialize_inputs(self): + pywarpx.algo.evolve_scheme = "explicit" + + +class ThetaImplicitEMEvolveScheme(picmistandard.base._ClassWithInit): + """ + Sets up the "theta implicit" electromagnetic evolve scheme + + Parameters + ---------- + nonlinear_solver: nonlinear solver instance + The nonlinear solver to use for the iterations + + theta: float, optional + The "theta" parameter, determining the level of implicitness + """ + + def __init__(self, nonlinear_solver, theta=None): + self.nonlinear_solver = nonlinear_solver + self.theta = theta + + def solver_scheme_initialize_inputs(self): + pywarpx.algo.evolve_scheme = "theta_implicit_em" + implicit_evolve = pywarpx.warpx.get_bucket("implicit_evolve") + implicit_evolve.theta = self.theta + + self.nonlinear_solver.nonlinear_solver_initialize_inputs() + + +class SemiImplicitEMEvolveScheme(picmistandard.base._ClassWithInit): + """ + Sets up the "semi-implicit" electromagnetic evolve scheme + + Parameters + ---------- + nonlinear_solver: nonlinear solver instance + The nonlinear solver to use for the iterations + """ + + def __init__(self, nonlinear_solver): + self.nonlinear_solver = nonlinear_solver + + def solver_scheme_initialize_inputs(self): + pywarpx.algo.evolve_scheme = "semi_implicit_em" + + self.nonlinear_solver.nonlinear_solver_initialize_inputs() + + +class PicardNonlinearSolver(picmistandard.base._ClassWithInit): + """ + Sets up the iterative Picard nonlinear solver for the implicit evolve scheme + + Parameters + ---------- + verbose: bool, default=True + Whether there is verbose output from the solver + + absolute_tolerance: float, default=0. + Absoluate tolerence of the convergence + + relative_tolerance: float, default=1.e-6 + Relative tolerance of the convergence + + max_iterations: integer, default=100 + Maximum number of iterations + + require_convergence: bool, default True + Whether convergence is required. If True and convergence is not obtained, the code will exit. + """ + + def __init__( + self, + verbose=None, + absolute_tolerance=None, + relative_tolerance=None, + max_iterations=None, + require_convergence=None, + ): + self.verbose = verbose + self.absolute_tolerance = absolute_tolerance + self.relative_tolerance = relative_tolerance + self.max_iterations = max_iterations + self.require_convergence = require_convergence + + def nonlinear_solver_initialize_inputs(self): + implicit_evolve = pywarpx.warpx.get_bucket("implicit_evolve") + implicit_evolve.nonlinear_solver = "picard" + + picard = pywarpx.warpx.get_bucket("picard") + picard.verbose = self.verbose + picard.absolute_tolerance = self.absolute_tolerance + picard.relative_tolerance = self.relative_tolerance + picard.max_iterations = self.max_iterations + picard.require_convergence = self.require_convergence + + +class NewtonNonlinearSolver(picmistandard.base._ClassWithInit): + """ + Sets up the iterative Newton nonlinear solver for the implicit evolve scheme + + Parameters + ---------- + verbose: bool, default=True + Whether there is verbose output from the solver + + absolute_tolerance: float, default=0. + Absoluate tolerence of the convergence + + relative_tolerance: float, default=1.e-6 + Relative tolerance of the convergence + + max_iterations: integer, default=100 + Maximum number of iterations + + require_convergence: bool, default True + Whether convergence is required. If True and convergence is not obtained, the code will exit. + + linear_solver: linear solver instance, optional + Specifies input arguments to the linear solver + + max_particle_iterations: integer, optional + The maximum number of particle iterations + + particle_tolerance: float, optional + The tolerance of parrticle quantities for convergence + + """ + + def __init__( + self, + verbose=None, + absolute_tolerance=None, + relative_tolerance=None, + max_iterations=None, + require_convergence=None, + linear_solver=None, + max_particle_iterations=None, + particle_tolerance=None, + ): + self.verbose = verbose + self.absolute_tolerance = absolute_tolerance + self.relative_tolerance = relative_tolerance + self.max_iterations = max_iterations + self.require_convergence = require_convergence + self.linear_solver = linear_solver + self.max_particle_iterations = max_particle_iterations + self.particle_tolerance = particle_tolerance + + def nonlinear_solver_initialize_inputs(self): + implicit_evolve = pywarpx.warpx.get_bucket("implicit_evolve") + implicit_evolve.nonlinear_solver = "newton" + implicit_evolve.max_particle_iterations = self.max_particle_iterations + implicit_evolve.particle_tolerance = self.particle_tolerance + + newton = pywarpx.warpx.get_bucket("newton") + newton.verbose = self.verbose + newton.absolute_tolerance = self.absolute_tolerance + newton.relative_tolerance = self.relative_tolerance + newton.max_iterations = self.max_iterations + newton.require_convergence = self.require_convergence + + self.linear_solver.linear_solver_initialize_inputs() + + +class GMRESLinearSolver(picmistandard.base._ClassWithInit): + """ + Sets up the iterative GMRES linear solver for the implicit Newton nonlinear solver + + Parameters + ---------- + verbose_int: integer, default=2 + Level of verbosity of output + + restart_length: integer, default=30 + How often to restart the GMRES iterations + + absolute_tolerance: float, default=0. + Absoluate tolerence of the convergence + + relative_tolerance: float, default=1.e-4 + Relative tolerance of the convergence + + max_iterations: integer, default=1000 + Maximum number of iterations + """ + + def __init__( + self, + verbose_int=None, + restart_length=None, + absolute_tolerance=None, + relative_tolerance=None, + max_iterations=None, + ): + self.verbose_int = verbose_int + self.restart_length = restart_length + self.absolute_tolerance = absolute_tolerance + self.relative_tolerance = relative_tolerance + self.max_iterations = max_iterations + + def linear_solver_initialize_inputs(self): + gmres = pywarpx.warpx.get_bucket("gmres") + gmres.verbose_int = self.verbose_int + gmres.restart_length = self.restart_length + gmres.absolute_tolerance = self.absolute_tolerance + gmres.relative_tolerance = self.relative_tolerance + gmres.max_iterations = self.max_iterations + + class HybridPICSolver(picmistandard.base._ClassWithInit): """ Hybrid-PIC solver based on Ohm's law. @@ -1264,11 +1784,22 @@ class HybridPICSolver(picmistandard.base._ClassWithInit): Jx/y/z_external_function: str Function of space and time specifying external (non-plasma) currents. """ - def __init__(self, grid, Te=None, n0=None, gamma=None, - n_floor=None, plasma_resistivity=None, - plasma_hyper_resistivity=None, substeps=None, - Jx_external_function=None, Jy_external_function=None, - Jz_external_function=None, **kw): + + def __init__( + self, + grid, + Te=None, + n0=None, + gamma=None, + n_floor=None, + plasma_resistivity=None, + plasma_hyper_resistivity=None, + substeps=None, + Jx_external_function=None, + Jy_external_function=None, + Jz_external_function=None, + **kw, + ): self.grid = grid self.method = "hybrid" @@ -1294,7 +1825,6 @@ def __init__(self, grid, Te=None, n0=None, gamma=None, self.handle_init(kw) def solver_initialize_inputs(self): - # Add the user defined keywords to my_constants # The keywords are mangled if there is a conflicting variable already # defined in my_constants with the same name but different value. @@ -1309,22 +1839,30 @@ def solver_initialize_inputs(self): pywarpx.hybridpicmodel.gamma = self.gamma pywarpx.hybridpicmodel.n_floor = self.n_floor pywarpx.hybridpicmodel.__setattr__( - 'plasma_resistivity(rho,J)', - pywarpx.my_constants.mangle_expression(self.plasma_resistivity, self.mangle_dict) + "plasma_resistivity(rho,J)", + pywarpx.my_constants.mangle_expression( + self.plasma_resistivity, self.mangle_dict + ), ) pywarpx.hybridpicmodel.plasma_hyper_resistivity = self.plasma_hyper_resistivity pywarpx.hybridpicmodel.substeps = self.substeps pywarpx.hybridpicmodel.__setattr__( - 'Jx_external_grid_function(x,y,z,t)', - pywarpx.my_constants.mangle_expression(self.Jx_external_function, self.mangle_dict) + "Jx_external_grid_function(x,y,z,t)", + pywarpx.my_constants.mangle_expression( + self.Jx_external_function, self.mangle_dict + ), ) pywarpx.hybridpicmodel.__setattr__( - 'Jy_external_grid_function(x,y,z,t)', - pywarpx.my_constants.mangle_expression(self.Jy_external_function, self.mangle_dict) + "Jy_external_grid_function(x,y,z,t)", + pywarpx.my_constants.mangle_expression( + self.Jy_external_function, self.mangle_dict + ), ) pywarpx.hybridpicmodel.__setattr__( - 'Jz_external_grid_function(x,y,z,t)', - pywarpx.my_constants.mangle_expression(self.Jz_external_function, self.mangle_dict) + "Jz_external_grid_function(x,y,z,t)", + pywarpx.my_constants.mangle_expression( + self.Jz_external_function, self.mangle_dict + ), ) @@ -1343,23 +1881,26 @@ class ElectrostaticSolver(picmistandard.PICMI_ElectrostaticSolver): warpx_self_fields_verbosity: integer, default=2 Level of verbosity for the lab frame solver """ + def init(self, kw): - self.relativistic = kw.pop('warpx_relativistic', False) - self.absolute_tolerance = kw.pop('warpx_absolute_tolerance', None) - self.self_fields_verbosity = kw.pop('warpx_self_fields_verbosity', None) - self.magnetostatic = kw.pop('warpx_magnetostatic', False) + self.relativistic = kw.pop("warpx_relativistic", False) + self.absolute_tolerance = kw.pop("warpx_absolute_tolerance", None) + self.self_fields_verbosity = kw.pop("warpx_self_fields_verbosity", None) + self.magnetostatic = kw.pop("warpx_magnetostatic", False) def solver_initialize_inputs(self): + # Open BC means FieldBoundaryType::Open for electrostatic sims, rather than perfectly-matched layer + BC_map["open"] = "open" self.grid.grid_initialize_inputs() if self.relativistic: - pywarpx.warpx.do_electrostatic = 'relativistic' + pywarpx.warpx.do_electrostatic = "relativistic" else: if self.magnetostatic: - pywarpx.warpx.do_electrostatic = 'labframe-electromagnetostatic' + pywarpx.warpx.do_electrostatic = "labframe-electromagnetostatic" else: - pywarpx.warpx.do_electrostatic = 'labframe' + pywarpx.warpx.do_electrostatic = "labframe" pywarpx.warpx.self_fields_required_precision = self.required_precision pywarpx.warpx.self_fields_absolute_tolerance = self.absolute_tolerance pywarpx.warpx.self_fields_max_iters = self.maximum_iterations @@ -1371,21 +1912,29 @@ def solver_initialize_inputs(self): pywarpx.boundary.potential_hi_y = self.grid.potential_ymax pywarpx.boundary.potential_hi_z = self.grid.potential_zmax + pywarpx.warpx.poisson_solver = self.method + class GaussianLaser(picmistandard.PICMI_GaussianLaser): def laser_initialize_inputs(self): self.laser_number = len(pywarpx.lasers.names) + 1 if self.name is None: - self.name = 'laser{}'.format(self.laser_number) + self.name = "laser{}".format(self.laser_number) self.laser = pywarpx.Lasers.newlaser(self.name) self.laser.profile = "Gaussian" - self.laser.wavelength = self.wavelength # The wavelength of the laser (in meters) + self.laser.wavelength = ( + self.wavelength + ) # The wavelength of the laser (in meters) self.laser.e_max = self.E0 # Maximum amplitude of the laser field (in V/m) - self.laser.polarization = self.polarization_direction # The main polarization vector + self.laser.polarization = ( + self.polarization_direction + ) # The main polarization vector self.laser.profile_waist = self.waist # The waist of the laser (in meters) - self.laser.profile_duration = self.duration # The duration of the laser (in seconds) + self.laser.profile_duration = ( + self.duration + ) # The duration of the laser (in seconds) self.laser.direction = self.propagation_direction self.laser.zeta = self.zeta self.laser.beta = self.beta @@ -1394,6 +1943,7 @@ def laser_initialize_inputs(self): self.laser.do_continuous_injection = self.fill_in + class AnalyticLaser(picmistandard.PICMI_AnalyticLaser): def init(self, kw): self.mangle_dict = None @@ -1401,14 +1951,18 @@ def init(self, kw): def laser_initialize_inputs(self): self.laser_number = len(pywarpx.lasers.names) + 1 if self.name is None: - self.name = 'laser{}'.format(self.laser_number) + self.name = "laser{}".format(self.laser_number) self.laser = pywarpx.Lasers.newlaser(self.name) self.laser.profile = "parse_field_function" - self.laser.wavelength = self.wavelength # The wavelength of the laser (in meters) + self.laser.wavelength = ( + self.wavelength + ) # The wavelength of the laser (in meters) self.laser.e_max = self.Emax # Maximum amplitude of the laser field (in V/m) - self.laser.polarization = self.polarization_direction # The main polarization vector + self.laser.polarization = ( + self.polarization_direction + ) # The main polarization vector self.laser.direction = self.propagation_direction self.laser.do_continuous_injection = self.fill_in @@ -1416,99 +1970,178 @@ def laser_initialize_inputs(self): # Only do this once so that the same variables are used in this distribution # is used multiple times self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) - expression = pywarpx.my_constants.mangle_expression(self.field_expression, self.mangle_dict) - self.laser.__setattr__('field_function(X,Y,t)', expression) + expression = pywarpx.my_constants.mangle_expression( + self.field_expression, self.mangle_dict + ) + self.laser.__setattr__("field_function(X,Y,t)", expression) class LaserAntenna(picmistandard.PICMI_LaserAntenna): def laser_antenna_initialize_inputs(self, laser): laser.laser.position = self.position # This point is on the laser plane - if ( - self.normal_vector is not None - and not np.allclose(laser.laser.direction, self.normal_vector) + if self.normal_vector is not None and not np.allclose( + laser.laser.direction, self.normal_vector ): raise AttributeError( - 'The specified laser direction does not match the ' - 'specified antenna normal.' + "The specified laser direction does not match the " + "specified antenna normal." ) - self.normal_vector = laser.laser.direction # The plane normal direction + self.normal_vector = laser.laser.direction # The plane normal direction + # Ensure the normal vector is a unit vector + self.normal_vector /= np.linalg.norm(self.normal_vector) if isinstance(laser, GaussianLaser): - # Focal distance from the antenna (in meters) - laser.laser.profile_focal_distance = np.sqrt( - (laser.focal_position[0] - self.position[0])**2 + - (laser.focal_position[1] - self.position[1])**2 + - (laser.focal_position[2] - self.position[2])**2 + # Focal displacement from the antenna (in meters) + laser.laser.profile_focal_distance = ( + (laser.focal_position[0] - self.position[0]) * self.normal_vector[0] + + (laser.focal_position[1] - self.position[1]) * self.normal_vector[1] + + (laser.focal_position[2] - self.position[2]) * self.normal_vector[2] ) # The time at which the laser reaches its peak (in seconds) - laser.laser.profile_t_peak = np.sqrt( - (self.position[0] - laser.centroid_position[0])**2 + - (self.position[1] - laser.centroid_position[1])**2 + - (self.position[2] - laser.centroid_position[2])**2 + laser.laser.profile_t_peak = ( + (self.position[0] - laser.centroid_position[0]) * self.normal_vector[0] + + (self.position[1] - laser.centroid_position[1]) + * self.normal_vector[1] + + (self.position[2] - laser.centroid_position[2]) + * self.normal_vector[2] ) / constants.c class LoadInitialField(picmistandard.PICMI_LoadGriddedField): + def init(self, kw): + self.do_divb_cleaning_external = kw.pop("warpx_do_divb_cleaning_external", None) + self.divb_cleaner_atol = kw.pop("warpx_projection_divb_cleaner_atol", None) + self.divb_cleaner_rtol = kw.pop("warpx_projection_divb_cleaner_rtol", None) + def applied_field_initialize_inputs(self): pywarpx.warpx.read_fields_from_path = self.read_fields_from_path if self.load_E: - pywarpx.warpx.E_ext_grid_init_style = 'read_from_file' + pywarpx.warpx.E_ext_grid_init_style = "read_from_file" + if self.load_B: + pywarpx.warpx.B_ext_grid_init_style = "read_from_file" + pywarpx.warpx.do_divb_cleaning_external = self.do_divb_cleaning_external + pywarpx.projectiondivbcleaner.atol = self.divb_cleaner_atol + pywarpx.projectiondivbcleaner.rtol = self.divb_cleaner_rtol + + +class LoadInitialFieldFromPython: + """ + Field Initializer that takes a function handle to be registered as a callback. + The function is expected to write the E and/or B fields into the + fields.Bx/y/zFPExternalWrapper() multifab. The callback is installed + in the beforeInitEsolve hook. This should operate identically to loading from + a file. + + Parameters + ---------- + warpx_do_divb_cleaning_external: bool, default=True + Flag that controls whether or not to execute the Projection based B-field divergence cleaner. + + load_E: bool, default=True + E field is expected to be loaded in the registered callback. + + load_B: bool, default=True + B field is expected to be loaded in the registered callback. + """ + + def __init__(self, **kw): + self.do_divb_cleaning_external = kw.pop("warpx_do_divb_cleaning_external", None) + self.divb_cleaner_atol = kw.pop("warpx_projection_divb_cleaner_atol", None) + self.divb_cleaner_rtol = kw.pop("warpx_projection_divb_cleaner_rtol", None) + + # If using load_from_python, a function handle is expected for callback + self.load_from_python = kw.pop("load_from_python") + self.load_E = kw.pop("load_E", True) + self.load_B = kw.pop("load_B", True) + + def applied_field_initialize_inputs(self): + if self.load_E: + pywarpx.warpx.E_ext_grid_init_style = "load_from_python" if self.load_B: - pywarpx.warpx.B_ext_grid_init_style = 'read_from_file' + pywarpx.warpx.B_ext_grid_init_style = "load_from_python" + pywarpx.warpx.do_divb_cleaning_external = self.do_divb_cleaning_external + pywarpx.projectiondivbcleaner.atol = self.divb_cleaner_atol + pywarpx.projectiondivbcleaner.rtol = self.divb_cleaner_rtol + + pywarpx.callbacks.installloadExternalFields(self.load_from_python) class AnalyticInitialField(picmistandard.PICMI_AnalyticAppliedField): def init(self, kw): self.mangle_dict = None - self.maxlevel_extEMfield_init = kw.pop('warpx_maxlevel_extEMfield_init', None); + self.maxlevel_extEMfield_init = kw.pop("warpx_maxlevel_extEMfield_init", None) def applied_field_initialize_inputs(self): # Note that lower and upper_bound are not used by WarpX - pywarpx.warpx.maxlevel_extEMfield_init = self.maxlevel_extEMfield_init; + pywarpx.warpx.maxlevel_extEMfield_init = self.maxlevel_extEMfield_init if self.mangle_dict is None: # Only do this once so that the same variables are used in this distribution # is used multiple times self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) - if (self.Ex_expression is not None or - self.Ey_expression is not None or - self.Ez_expression is not None): - pywarpx.warpx.E_ext_grid_init_style = 'parse_e_ext_grid_function' - for sdir, expression in zip(['x', 'y', 'z'], [self.Ex_expression, self.Ey_expression, self.Ez_expression]): - expression = pywarpx.my_constants.mangle_expression(expression, self.mangle_dict) - pywarpx.warpx.__setattr__(f'E{sdir}_external_grid_function(x,y,z)', expression) - - if (self.Bx_expression is not None or - self.By_expression is not None or - self.Bz_expression is not None): - pywarpx.warpx.B_ext_grid_init_style = 'parse_b_ext_grid_function' - for sdir, expression in zip(['x', 'y', 'z'], [self.Bx_expression, self.By_expression, self.Bz_expression]): - expression = pywarpx.my_constants.mangle_expression(expression, self.mangle_dict) - pywarpx.warpx.__setattr__(f'B{sdir}_external_grid_function(x,y,z)', expression) + if ( + self.Ex_expression is not None + or self.Ey_expression is not None + or self.Ez_expression is not None + ): + pywarpx.warpx.E_ext_grid_init_style = "parse_e_ext_grid_function" + for sdir, expression in zip( + ["x", "y", "z"], + [self.Ex_expression, self.Ey_expression, self.Ez_expression], + ): + expression = pywarpx.my_constants.mangle_expression( + expression, self.mangle_dict + ) + pywarpx.warpx.__setattr__( + f"E{sdir}_external_grid_function(x,y,z)", expression + ) + + if ( + self.Bx_expression is not None + or self.By_expression is not None + or self.Bz_expression is not None + ): + pywarpx.warpx.B_ext_grid_init_style = "parse_b_ext_grid_function" + for sdir, expression in zip( + ["x", "y", "z"], + [self.Bx_expression, self.By_expression, self.Bz_expression], + ): + expression = pywarpx.my_constants.mangle_expression( + expression, self.mangle_dict + ) + pywarpx.warpx.__setattr__( + f"B{sdir}_external_grid_function(x,y,z)", expression + ) + class LoadAppliedField(picmistandard.PICMI_LoadAppliedField): def applied_field_initialize_inputs(self): pywarpx.particles.read_fields_from_path = self.read_fields_from_path if self.load_E: - pywarpx.particles.E_ext_particle_init_style = 'read_from_file' + pywarpx.particles.E_ext_particle_init_style = "read_from_file" if self.load_B: - pywarpx.particles.B_ext_particle_init_style = 'read_from_file' + pywarpx.particles.B_ext_particle_init_style = "read_from_file" + class ConstantAppliedField(picmistandard.PICMI_ConstantAppliedField): def applied_field_initialize_inputs(self): # Note that lower and upper_bound are not used by WarpX - if (self.Ex is not None or - self.Ey is not None or - self.Ez is not None): - pywarpx.particles.E_ext_particle_init_style = 'constant' - pywarpx.particles.E_external_particle = [self.Ex or 0., self.Ey or 0., self.Ez or 0.] + if self.Ex is not None or self.Ey is not None or self.Ez is not None: + pywarpx.particles.E_ext_particle_init_style = "constant" + pywarpx.particles.E_external_particle = [ + self.Ex or 0.0, + self.Ey or 0.0, + self.Ez or 0.0, + ] - if (self.Bx is not None or - self.By is not None or - self.Bz is not None): - pywarpx.particles.B_ext_particle_init_style = 'constant' - pywarpx.particles.B_external_particle = [self.Bx or 0., self.By or 0., self.Bz or 0.] + if self.Bx is not None or self.By is not None or self.Bz is not None: + pywarpx.particles.B_ext_particle_init_style = "constant" + pywarpx.particles.B_external_particle = [ + self.Bx or 0.0, + self.By or 0.0, + self.Bz or 0.0, + ] class AnalyticAppliedField(picmistandard.PICMI_AnalyticAppliedField): @@ -1523,21 +2156,43 @@ def applied_field_initialize_inputs(self): # is used multiple times self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) - if (self.Ex_expression is not None or - self.Ey_expression is not None or - self.Ez_expression is not None): - pywarpx.particles.E_ext_particle_init_style = 'parse_e_ext_particle_function' - for sdir, expression in zip(['x', 'y', 'z'], [self.Ex_expression, self.Ey_expression, self.Ez_expression]): - expression = pywarpx.my_constants.mangle_expression(expression, self.mangle_dict) - pywarpx.particles.__setattr__(f'E{sdir}_external_particle_function(x,y,z,t)', expression) + if ( + self.Ex_expression is not None + or self.Ey_expression is not None + or self.Ez_expression is not None + ): + pywarpx.particles.E_ext_particle_init_style = ( + "parse_e_ext_particle_function" + ) + for sdir, expression in zip( + ["x", "y", "z"], + [self.Ex_expression, self.Ey_expression, self.Ez_expression], + ): + expression = pywarpx.my_constants.mangle_expression( + expression, self.mangle_dict + ) + pywarpx.particles.__setattr__( + f"E{sdir}_external_particle_function(x,y,z,t)", expression + ) - if (self.Bx_expression is not None or - self.By_expression is not None or - self.Bz_expression is not None): - pywarpx.particles.B_ext_particle_init_style = 'parse_b_ext_particle_function' - for sdir, expression in zip(['x', 'y', 'z'], [self.Bx_expression, self.By_expression, self.Bz_expression]): - expression = pywarpx.my_constants.mangle_expression(expression, self.mangle_dict) - pywarpx.particles.__setattr__(f'B{sdir}_external_particle_function(x,y,z,t)', expression) + if ( + self.Bx_expression is not None + or self.By_expression is not None + or self.Bz_expression is not None + ): + pywarpx.particles.B_ext_particle_init_style = ( + "parse_b_ext_particle_function" + ) + for sdir, expression in zip( + ["x", "y", "z"], + [self.Bx_expression, self.By_expression, self.Bz_expression], + ): + expression = pywarpx.my_constants.mangle_expression( + expression, self.mangle_dict + ) + pywarpx.particles.__setattr__( + f"B{sdir}_external_particle_function(x,y,z,t)", expression + ) class Mirror(picmistandard.PICMI_Mirror): @@ -1560,13 +2215,20 @@ class FieldIonization(picmistandard.PICMI_FieldIonization): """ WarpX only has ADK ionization model implemented. """ + def interaction_initialize_inputs(self): - assert self.model == 'ADK', 'WarpX only has ADK ionization model implemented' + assert self.model == "ADK", "WarpX only has ADK ionization model implemented" self.ionized_species.species.do_field_ionization = 1 - self.ionized_species.species.physical_element = self.ionized_species.particle_type - self.ionized_species.species.ionization_product_species = self.product_species.name - self.ionized_species.species.ionization_initial_level = self.ionized_species.charge_state - self.ionized_species.species.charge = 'q_e' + self.ionized_species.species.physical_element = ( + self.ionized_species.particle_type + ) + self.ionized_species.species.ionization_product_species = ( + self.product_species.name + ) + self.ionized_species.species.ionization_initial_level = ( + self.ionized_species.charge_state + ) + self.ionized_species.species.charge = "q_e" class CoulombCollisions(picmistandard.base._ClassWithInit): @@ -1590,6 +2252,7 @@ class CoulombCollisions(picmistandard.base._ClassWithInit): ndt: integer, optional The collisions will be applied every "ndt" steps. Must be 1 or larger. """ + def __init__(self, name, species, CoulombLog=None, ndt=None, **kw): self.name = name self.species = species @@ -1600,7 +2263,7 @@ def __init__(self, name, species, CoulombLog=None, ndt=None, **kw): def collision_initialize_inputs(self): collision = pywarpx.Collisions.newcollision(self.name) - collision.type = 'pairwisecoulomb' + collision.type = "pairwisecoulomb" collision.species = [species.name for species in self.species] collision.CoulombLog = self.CoulombLog collision.ndt = self.ndt @@ -1641,9 +2304,18 @@ class MCCCollisions(picmistandard.base._ClassWithInit): The collisions will be applied every "ndt" steps. Must be 1 or larger. """ - def __init__(self, name, species, background_density, - background_temperature, scattering_processes, - background_mass=None, max_background_density=None, ndt=None, **kw): + def __init__( + self, + name, + species, + background_density, + background_temperature, + scattering_processes, + background_mass=None, + max_background_density=None, + ndt=None, + **kw, + ): self.name = name self.species = species self.background_density = background_density @@ -1657,14 +2329,18 @@ def __init__(self, name, species, background_density, def collision_initialize_inputs(self): collision = pywarpx.Collisions.newcollision(self.name) - collision.type = 'background_mcc' + collision.type = "background_mcc" collision.species = self.species.name if isinstance(self.background_density, str): - collision.__setattr__('background_density(x,y,z,t)', self.background_density) + collision.__setattr__( + "background_density(x,y,z,t)", self.background_density + ) else: collision.background_density = self.background_density if isinstance(self.background_temperature, str): - collision.__setattr__('background_temperature(x,y,z,t)', self.background_temperature) + collision.__setattr__( + "background_temperature(x,y,z,t)", self.background_temperature + ) else: collision.background_temperature = self.background_temperature collision.background_mass = self.background_mass @@ -1674,9 +2350,9 @@ def collision_initialize_inputs(self): collision.scattering_processes = self.scattering_processes.keys() for process, kw in self.scattering_processes.items(): for key, val in kw.items(): - if key == 'species': + if key == "species": val = val.name - collision.add_new_attr(process+'_'+key, val) + collision.add_new_attr(process + "_" + key, val) class DSMCCollisions(picmistandard.base._ClassWithInit): @@ -1710,16 +2386,16 @@ def __init__(self, name, species, scattering_processes, ndt=None, **kw): def collision_initialize_inputs(self): collision = pywarpx.Collisions.newcollision(self.name) - collision.type = 'dsmc' + collision.type = "dsmc" collision.species = [species.name for species in self.species] collision.ndt = self.ndt collision.scattering_processes = self.scattering_processes.keys() for process, kw in self.scattering_processes.items(): for key, val in kw.items(): - if key == 'species': + if key == "species": val = val.name - collision.add_new_attr(process+'_'+key, val) + collision.add_new_attr(process + "_" + key, val) class EmbeddedBoundary(picmistandard.base._ClassWithInit): @@ -1758,19 +2434,35 @@ class EmbeddedBoundary(picmistandard.base._ClassWithInit): Parameters used in the analytic expressions should be given as additional keyword arguments. """ - def __init__(self, implicit_function=None, stl_file=None, stl_scale=None, stl_center=None, stl_reverse_normal=False, - potential=None, cover_multiple_cuts=None, **kw): - assert stl_file is None or implicit_function is None, Exception('Only one between implicit_function and ' - 'stl_file can be specified') + def __init__( + self, + implicit_function=None, + stl_file=None, + stl_scale=None, + stl_center=None, + stl_reverse_normal=False, + potential=None, + cover_multiple_cuts=None, + **kw, + ): + assert stl_file is None or implicit_function is None, Exception( + "Only one between implicit_function and " "stl_file can be specified" + ) self.implicit_function = implicit_function self.stl_file = stl_file if stl_file is None: - assert stl_scale is None, Exception('EB can only be scaled only when using an stl file') - assert stl_center is None, Exception('EB can only be translated only when using an stl file') - assert stl_reverse_normal is False, Exception('EB can only be reversed only when using an stl file') + assert stl_scale is None, Exception( + "EB can only be scaled only when using an stl file" + ) + assert stl_center is None, Exception( + "EB can only be translated only when using an stl file" + ) + assert stl_reverse_normal is False, Exception( + "EB can only be reversed only when using an stl file" + ) self.stl_scale = stl_scale self.stl_center = stl_center @@ -1783,22 +2475,26 @@ def __init__(self, implicit_function=None, stl_file=None, stl_scale=None, stl_ce # Handle keyword arguments used in expressions self.user_defined_kw = {} for k in list(kw.keys()): - if (implicit_function is not None and re.search(r'\b%s\b'%k, implicit_function) or - (potential is not None and re.search(r'\b%s\b'%k, potential))): + if ( + implicit_function is not None + and re.search(r"\b%s\b" % k, implicit_function) + or (potential is not None and re.search(r"\b%s\b" % k, potential)) + ): self.user_defined_kw[k] = kw[k] del kw[k] self.handle_init(kw) def embedded_boundary_initialize_inputs(self, solver): - # Add the user defined keywords to my_constants # The keywords are mangled if there is a conflicting variable already # defined in my_constants with the same name but different value. self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) if self.implicit_function is not None: - expression = pywarpx.my_constants.mangle_expression(self.implicit_function, self.mangle_dict) + expression = pywarpx.my_constants.mangle_expression( + self.implicit_function, self.mangle_dict + ) pywarpx.warpx.eb_implicit_function = expression if self.stl_file is not None: @@ -1811,8 +2507,10 @@ def embedded_boundary_initialize_inputs(self, solver): pywarpx.eb2.cover_multiple_cuts = self.cover_multiple_cuts if self.potential is not None: - expression = pywarpx.my_constants.mangle_expression(self.potential, self.mangle_dict) - pywarpx.warpx.__setattr__('eb_potential(x,y,z,t)', expression) + expression = pywarpx.my_constants.mangle_expression( + self.potential, self.mangle_dict + ) + pywarpx.warpx.__setattr__("eb_potential(x,y,z,t)", expression) class PlasmaLens(picmistandard.base._ClassWithInit): @@ -1849,22 +2547,25 @@ class PlasmaLens(picmistandard.base._ClassWithInit): - By = -x*strengths_B """ - def __init__(self, period, starts, lengths, strengths_E=None, strengths_B=None, **kw): + + def __init__( + self, period, starts, lengths, strengths_E=None, strengths_B=None, **kw + ): self.period = period self.starts = starts self.lengths = lengths self.strengths_E = strengths_E self.strengths_B = strengths_B - assert (self.strengths_E is not None) or (self.strengths_B is not None),\ - Exception('One of strengths_E or strengths_B must be supplied') + assert (self.strengths_E is not None) or ( + self.strengths_B is not None + ), Exception("One of strengths_E or strengths_B must be supplied") self.handle_init(kw) def applied_field_initialize_inputs(self): - - pywarpx.particles.E_ext_particle_init_style = 'repeated_plasma_lens' - pywarpx.particles.B_ext_particle_init_style = 'repeated_plasma_lens' + pywarpx.particles.E_ext_particle_init_style = "repeated_plasma_lens" + pywarpx.particles.B_ext_particle_init_style = "repeated_plasma_lens" pywarpx.particles.repeated_plasma_lens_period = self.period pywarpx.particles.repeated_plasma_lens_starts = self.starts pywarpx.particles.repeated_plasma_lens_lengths = self.lengths @@ -1878,6 +2579,9 @@ class Simulation(picmistandard.PICMI_Simulation): Parameters ---------- + warpx_evolve_scheme: solver scheme instance, optional + Which evolve scheme to use + warpx_current_deposition_algo: {'direct', 'esirkepov', and 'vay'}, optional Current deposition algorithm. The default depends on conditions. @@ -1941,6 +2645,9 @@ class Simulation(picmistandard.PICMI_Simulation): warpx_do_dynamic_scheduling: bool, default=True Whether to do dynamic scheduling with OpenMP + warpx_roundrobin_sfc: bool, default=False + Whether to use the RRSFC strategy for making DistributionMapping + warpx_load_balance_intervals: string, default='0' The intervals for doing load balancing @@ -2040,48 +2747,63 @@ class Simulation(picmistandard.PICMI_Simulation): extension = pywarpx.libwarpx def init(self, kw): + self.evolve_scheme = kw.pop("warpx_evolve_scheme", None) + self.current_deposition_algo = kw.pop("warpx_current_deposition_algo", None) + self.charge_deposition_algo = kw.pop("warpx_charge_deposition_algo", None) + self.field_gathering_algo = kw.pop("warpx_field_gathering_algo", None) + self.particle_pusher_algo = kw.pop("warpx_particle_pusher_algo", None) + self.use_filter = kw.pop("warpx_use_filter", None) + self.do_multi_J = kw.pop("warpx_do_multi_J", None) + self.do_multi_J_n_depositions = kw.pop("warpx_do_multi_J_n_depositions", None) + self.grid_type = kw.pop("warpx_grid_type", None) + self.do_current_centering = kw.pop("warpx_do_current_centering", None) + self.field_centering_order = kw.pop("warpx_field_centering_order", None) + self.current_centering_order = kw.pop("warpx_current_centering_order", None) + self.serialize_initial_conditions = kw.pop( + "warpx_serialize_initial_conditions", None + ) + self.random_seed = kw.pop("warpx_random_seed", None) + self.do_dynamic_scheduling = kw.pop("warpx_do_dynamic_scheduling", None) + self.roundrobin_sfc = kw.pop("warpx_roundrobin_sfc", None) + self.load_balance_intervals = kw.pop("warpx_load_balance_intervals", None) + self.load_balance_efficiency_ratio_threshold = kw.pop( + "warpx_load_balance_efficiency_ratio_threshold", None + ) + self.load_balance_with_sfc = kw.pop("warpx_load_balance_with_sfc", None) + self.load_balance_knapsack_factor = kw.pop( + "warpx_load_balance_knapsack_factor", None + ) + self.load_balance_costs_update = kw.pop("warpx_load_balance_costs_update", None) + self.costs_heuristic_particles_wt = kw.pop( + "warpx_costs_heuristic_particles_wt", None + ) + self.costs_heuristic_cells_wt = kw.pop("warpx_costs_heuristic_cells_wt", None) + self.use_fdtd_nci_corr = kw.pop("warpx_use_fdtd_nci_corr", None) + self.amr_check_input = kw.pop("warpx_amr_check_input", None) + self.amr_restart = kw.pop("warpx_amr_restart", None) + self.amrex_the_arena_is_managed = kw.pop( + "warpx_amrex_the_arena_is_managed", None + ) + self.amrex_the_arena_init_size = kw.pop("warpx_amrex_the_arena_init_size", None) + self.amrex_use_gpu_aware_mpi = kw.pop("warpx_amrex_use_gpu_aware_mpi", None) + self.zmax_plasma_to_compute_max_step = kw.pop( + "warpx_zmax_plasma_to_compute_max_step", None + ) + self.compute_max_step_from_btd = kw.pop("warpx_compute_max_step_from_btd", None) + self.sort_intervals = kw.pop("warpx_sort_intervals", None) + self.sort_particles_for_deposition = kw.pop( + "warpx_sort_particles_for_deposition", None + ) + self.sort_idx_type = kw.pop("warpx_sort_idx_type", None) + self.sort_bin_size = kw.pop("warpx_sort_bin_size", None) + self.used_inputs_file = kw.pop("warpx_used_inputs_file", None) + + self.collisions = kw.pop("warpx_collisions", None) + self.embedded_boundary = kw.pop("warpx_embedded_boundary", None) - self.current_deposition_algo = kw.pop('warpx_current_deposition_algo', None) - self.charge_deposition_algo = kw.pop('warpx_charge_deposition_algo', None) - self.field_gathering_algo = kw.pop('warpx_field_gathering_algo', None) - self.particle_pusher_algo = kw.pop('warpx_particle_pusher_algo', None) - self.use_filter = kw.pop('warpx_use_filter', None) - self.do_multi_J = kw.pop('warpx_do_multi_J', None) - self.do_multi_J_n_depositions = kw.pop('warpx_do_multi_J_n_depositions', None) - self.grid_type = kw.pop('warpx_grid_type', None) - self.do_current_centering = kw.pop('warpx_do_current_centering', None) - self.field_centering_order = kw.pop('warpx_field_centering_order', None) - self.current_centering_order = kw.pop('warpx_current_centering_order', None) - self.serialize_initial_conditions = kw.pop('warpx_serialize_initial_conditions', None) - self.random_seed = kw.pop('warpx_random_seed', None) - self.do_dynamic_scheduling = kw.pop('warpx_do_dynamic_scheduling', None) - self.load_balance_intervals = kw.pop('warpx_load_balance_intervals', None) - self.load_balance_efficiency_ratio_threshold = kw.pop('warpx_load_balance_efficiency_ratio_threshold', None) - self.load_balance_with_sfc = kw.pop('warpx_load_balance_with_sfc', None) - self.load_balance_knapsack_factor = kw.pop('warpx_load_balance_knapsack_factor', None) - self.load_balance_costs_update = kw.pop('warpx_load_balance_costs_update', None) - self.costs_heuristic_particles_wt = kw.pop('warpx_costs_heuristic_particles_wt', None) - self.costs_heuristic_cells_wt = kw.pop('warpx_costs_heuristic_cells_wt', None) - self.use_fdtd_nci_corr = kw.pop('warpx_use_fdtd_nci_corr', None) - self.amr_check_input = kw.pop('warpx_amr_check_input', None) - self.amr_restart = kw.pop('warpx_amr_restart', None) - self.amrex_the_arena_is_managed = kw.pop('warpx_amrex_the_arena_is_managed', None) - self.amrex_the_arena_init_size = kw.pop('warpx_amrex_the_arena_init_size', None) - self.amrex_use_gpu_aware_mpi = kw.pop('warpx_amrex_use_gpu_aware_mpi', None) - self.zmax_plasma_to_compute_max_step = kw.pop('warpx_zmax_plasma_to_compute_max_step', None) - self.compute_max_step_from_btd = kw.pop('warpx_compute_max_step_from_btd', None) - self.sort_intervals = kw.pop('warpx_sort_intervals', None) - self.sort_particles_for_deposition = kw.pop('warpx_sort_particles_for_deposition', None) - self.sort_idx_type = kw.pop('warpx_sort_idx_type', None) - self.sort_bin_size = kw.pop('warpx_sort_bin_size', None) - self.used_inputs_file = kw.pop('warpx_used_inputs_file', None) - - self.collisions = kw.pop('warpx_collisions', None) - self.embedded_boundary = kw.pop('warpx_embedded_boundary', None) - - self.break_signals = kw.pop('warpx_break_signals', None) - self.checkpoint_signals = kw.pop('warpx_checkpoint_signals', None) - self.numprocs = kw.pop('warpx_numprocs', None) + self.break_signals = kw.pop("warpx_break_signals", None) + self.checkpoint_signals = kw.pop("warpx_checkpoint_signals", None) + self.numprocs = kw.pop("warpx_numprocs", None) self.inputs_initialized = False self.warpx_initialized = False @@ -2098,9 +2820,11 @@ def initialize_inputs(self): if self.gamma_boost is not None: pywarpx.warpx.gamma_boost = self.gamma_boost - pywarpx.warpx.boost_direction = 'z' + pywarpx.warpx.boost_direction = "z" - pywarpx.warpx.zmax_plasma_to_compute_max_step = self.zmax_plasma_to_compute_max_step + pywarpx.warpx.zmax_plasma_to_compute_max_step = ( + self.zmax_plasma_to_compute_max_step + ) pywarpx.warpx.compute_max_step_from_btd = self.compute_max_step_from_btd pywarpx.warpx.sort_intervals = self.sort_intervals @@ -2108,12 +2832,17 @@ def initialize_inputs(self): pywarpx.warpx.sort_idx_type = self.sort_idx_type pywarpx.warpx.sort_bin_size = self.sort_bin_size + if self.evolve_scheme is not None: + self.evolve_scheme.solver_scheme_initialize_inputs() + pywarpx.algo.current_deposition = self.current_deposition_algo pywarpx.algo.charge_deposition = self.charge_deposition_algo pywarpx.algo.field_gathering = self.field_gathering_algo pywarpx.algo.particle_pusher = self.particle_pusher_algo pywarpx.algo.load_balance_intervals = self.load_balance_intervals - pywarpx.algo.load_balance_efficiency_ratio_threshold = self.load_balance_efficiency_ratio_threshold + pywarpx.algo.load_balance_efficiency_ratio_threshold = ( + self.load_balance_efficiency_ratio_threshold + ) pywarpx.algo.load_balance_with_sfc = self.load_balance_with_sfc pywarpx.algo.load_balance_knapsack_factor = self.load_balance_knapsack_factor pywarpx.algo.load_balance_costs_update = self.load_balance_costs_update @@ -2131,6 +2860,8 @@ def initialize_inputs(self): pywarpx.warpx.do_dynamic_scheduling = self.do_dynamic_scheduling + pywarpx.warpx.roundrobin_sfc = self.roundrobin_sfc + pywarpx.particles.use_fdtd_nci_corr = self.use_fdtd_nci_corr pywarpx.amr.check_input = self.amr_check_input @@ -2143,13 +2874,22 @@ def initialize_inputs(self): particle_shape = self.particle_shape for s in self.species: if s.particle_shape is not None: - assert particle_shape is None or particle_shape == s.particle_shape, Exception('WarpX only supports one particle shape for all species') + assert ( + particle_shape is None or particle_shape == s.particle_shape + ), Exception("WarpX only supports one particle shape for all species") # --- If this was set for any species, use that value. particle_shape = s.particle_shape - if particle_shape is not None and (len(self.species) > 0 or len(self.lasers) > 0): + if particle_shape is not None and ( + len(self.species) > 0 or len(self.lasers) > 0 + ): if isinstance(particle_shape, str): - interpolation_order = {'NGP':0, 'linear':1, 'quadratic':2, 'cubic':3}[particle_shape] + interpolation_order = { + "NGP": 0, + "linear": 1, + "quadratic": 2, + "cubic": 3, + }[particle_shape] else: interpolation_order = particle_shape pywarpx.algo.particle_shape = interpolation_order @@ -2172,13 +2912,15 @@ def initialize_inputs(self): pywarpx.warpx.current_centering_noz = self.current_centering_order[-1] for i in range(len(self.species)): - self.species[i].species_initialize_inputs(self.layouts[i], - self.initialize_self_fields[i], - self.injection_plane_positions[i], - self.injection_plane_normal_vectors[i]) + self.species[i].species_initialize_inputs( + self.layouts[i], + self.initialize_self_fields[i], + self.injection_plane_positions[i], + self.injection_plane_normal_vectors[i], + ) for interaction in self.interactions: - assert(isinstance(interaction, FieldIonization)) + assert isinstance(interaction, FieldIonization) interaction.interaction_initialize_inputs() if self.collisions is not None: @@ -2192,7 +2934,9 @@ def initialize_inputs(self): for i in range(len(self.lasers)): self.lasers[i].laser_initialize_inputs() - self.laser_injection_methods[i].laser_antenna_initialize_inputs(self.lasers[i]) + self.laser_injection_methods[i].laser_antenna_initialize_inputs( + self.lasers[i] + ) for applied_field in self.applied_fields: applied_field.applied_field_initialize_inputs() @@ -2219,9 +2963,11 @@ def initialize_warpx(self, mpi_comm=None): self.warpx_initialized = True pywarpx.warpx.init(mpi_comm, max_step=self.max_steps, stop_time=self.max_time) - def write_input_file(self, file_name='inputs'): + def write_input_file(self, file_name="inputs"): self.initialize_inputs() - pywarpx.warpx.write_inputs(file_name, max_step=self.max_steps, stop_time=self.max_time) + pywarpx.warpx.write_inputs( + file_name, max_step=self.max_steps, stop_time=self.max_time + ) def step(self, nsteps=None, mpi_comm=None): self.initialize_inputs() @@ -2243,24 +2989,26 @@ def finalize(self): # Simulation frame diagnostics # ---------------------------- + class WarpXDiagnosticBase(object): """ Base class for all WarpX diagnostic containing functionality shared by all WarpX diagnostic installations. """ + def add_diagnostic(self): # reduced diagnostics go in a different bucket than regular diagnostics if isinstance(self, ReducedDiagnostic): bucket = pywarpx.reduced_diagnostics - name_template = 'reduced_diag' + name_template = "reduced_diag" else: bucket = pywarpx.diagnostics - name_template = 'diag' + name_template = "diag" - name = getattr(self, 'name', None) + name = getattr(self, "name", None) if name is None: - diagnostics_number = (len(bucket._diagnostics_dict) + 1) - self.name = f'{name_template}{diagnostics_number}' + diagnostics_number = len(bucket._diagnostics_dict) + 1 + self.name = f"{name_template}{diagnostics_number}" try: self.diagnostic = bucket._diagnostics_dict[self.name] @@ -2272,8 +3020,8 @@ def add_diagnostic(self): def set_write_dir(self): if self.write_dir is not None or self.file_prefix is not None: - write_dir = (self.write_dir or 'diags') - file_prefix = (self.file_prefix or self.name) + write_dir = self.write_dir or "diags" + file_prefix = self.file_prefix or self.name self.diagnostic.file_prefix = os.path.join(write_dir, file_prefix) @@ -2300,6 +3048,7 @@ class ParticleFieldDiagnostic: If not specified, all particles will be included. The function arguments are the same as the `func` above. """ + name: str func: str do_average: int = 1 @@ -2324,6 +3073,11 @@ class FieldDiagnostic(picmistandard.PICMI_FieldDiagnostic, WarpXDiagnosticBase): warpx_openpmd_backend: {bp, h5, json}, optional Openpmd backend file format + warpx_openpmd_encoding: 'v' (variable based), 'f' (file based) or 'g' (group based), optional + Only read if ``.format = openpmd``. openPMD file output encoding. + File based: one file per timestep (slower), group/variable based: one file for all steps (faster)). + Variable based is an experimental feature with ADIOS2. Default: `'f'`. + warpx_file_prefix: string, optional Prefix on the diagnostic file name @@ -2333,6 +3087,9 @@ class FieldDiagnostic(picmistandard.PICMI_FieldDiagnostic, WarpXDiagnosticBase): warpx_dump_rz_modes: bool, optional Flag whether to dump the data for all RZ modes + warpx_dump_last_timestep: bool, optional + If true, the last timestep is dumped regardless of the diagnostic period/intervals. + warpx_particle_fields_to_plot: list of ParticleFieldDiagnostics List of ParticleFieldDiagnostic classes to install in the simulation. Error checking is handled in the class itself. @@ -2342,65 +3099,78 @@ class FieldDiagnostic(picmistandard.PICMI_FieldDiagnostic, WarpXDiagnosticBase): be calculated separately for each specified species. If not passed, default is all of the available particle species. """ - def init(self, kw): - self.plot_raw_fields = kw.pop('warpx_plot_raw_fields', None) - self.plot_raw_fields_guards = kw.pop('warpx_plot_raw_fields_guards', None) - self.plot_finepatch = kw.pop('warpx_plot_finepatch', None) - self.plot_crsepatch = kw.pop('warpx_plot_crsepatch', None) - self.format = kw.pop('warpx_format', 'plotfile') - self.openpmd_backend = kw.pop('warpx_openpmd_backend', None) - self.file_prefix = kw.pop('warpx_file_prefix', None) - self.file_min_digits = kw.pop('warpx_file_min_digits', None) - self.dump_rz_modes = kw.pop('warpx_dump_rz_modes', None) - self.particle_fields_to_plot = kw.pop('warpx_particle_fields_to_plot', []) - self.particle_fields_species = kw.pop('warpx_particle_fields_species', None) + def init(self, kw): + self.plot_raw_fields = kw.pop("warpx_plot_raw_fields", None) + self.plot_raw_fields_guards = kw.pop("warpx_plot_raw_fields_guards", None) + self.plot_finepatch = kw.pop("warpx_plot_finepatch", None) + self.plot_crsepatch = kw.pop("warpx_plot_crsepatch", None) + self.format = kw.pop("warpx_format", "plotfile") + self.openpmd_backend = kw.pop("warpx_openpmd_backend", None) + self.openpmd_encoding = kw.pop("warpx_openpmd_encoding", None) + self.file_prefix = kw.pop("warpx_file_prefix", None) + self.file_min_digits = kw.pop("warpx_file_min_digits", None) + self.dump_rz_modes = kw.pop("warpx_dump_rz_modes", None) + self.dump_last_timestep = kw.pop("warpx_dump_last_timestep", None) + self.particle_fields_to_plot = kw.pop("warpx_particle_fields_to_plot", []) + self.particle_fields_species = kw.pop("warpx_particle_fields_species", None) def diagnostic_initialize_inputs(self): - self.add_diagnostic() - self.diagnostic.diag_type = 'Full' + self.diagnostic.diag_type = "Full" self.diagnostic.format = self.format self.diagnostic.openpmd_backend = self.openpmd_backend + self.diagnostic.openpmd_encoding = self.openpmd_encoding self.diagnostic.file_min_digits = self.file_min_digits self.diagnostic.dump_rz_modes = self.dump_rz_modes + self.diagnostic.dump_last_timestep = self.dump_last_timestep self.diagnostic.intervals = self.period self.diagnostic.diag_lo = self.lower_bound self.diagnostic.diag_hi = self.upper_bound if self.number_of_cells is not None: - self.diagnostic.coarsening_ratio = (np.array(self.grid.number_of_cells)/np.array(self.number_of_cells)).astype(int) + self.diagnostic.coarsening_ratio = ( + np.array(self.grid.number_of_cells) / np.array(self.number_of_cells) + ).astype(int) # --- Use a set to ensure that fields don't get repeated. fields_to_plot = set() - if pywarpx.geometry.dims == 'RZ': - E_fields_list = ['Er', 'Et', 'Ez'] - B_fields_list = ['Br', 'Bt', 'Bz'] - J_fields_list = ['Jr', 'Jt', 'Jz'] - J_displacement_fields_list = ['Jr_displacement', 'Jt_displacement', 'Jz_displacement'] - A_fields_list = ['Ar', 'At', 'Az'] + if pywarpx.geometry.dims == "RZ": + E_fields_list = ["Er", "Et", "Ez"] + B_fields_list = ["Br", "Bt", "Bz"] + J_fields_list = ["Jr", "Jt", "Jz"] + J_displacement_fields_list = [ + "Jr_displacement", + "Jt_displacement", + "Jz_displacement", + ] + A_fields_list = ["Ar", "At", "Az"] else: - E_fields_list = ['Ex', 'Ey', 'Ez'] - B_fields_list = ['Bx', 'By', 'Bz'] - J_fields_list = ['Jx', 'Jy', 'Jz'] - J_displacement_fields_list = ['Jx_displacement', 'Jy_displacement', 'Jz_displacement'] - A_fields_list = ['Ax', 'Ay', 'Az'] + E_fields_list = ["Ex", "Ey", "Ez"] + B_fields_list = ["Bx", "By", "Bz"] + J_fields_list = ["Jx", "Jy", "Jz"] + J_displacement_fields_list = [ + "Jx_displacement", + "Jy_displacement", + "Jz_displacement", + ] + A_fields_list = ["Ax", "Ay", "Az"] if self.data_list is not None: for dataname in self.data_list: - if dataname == 'E': + if dataname == "E": for field_name in E_fields_list: fields_to_plot.add(field_name) - elif dataname == 'B': + elif dataname == "B": for field_name in B_fields_list: fields_to_plot.add(field_name) - elif dataname == 'J': + elif dataname == "J": for field_name in J_fields_list: fields_to_plot.add(field_name.lower()) - elif dataname == 'J_displacement': + elif dataname == "J_displacement": for field_name in J_displacement_fields_list: fields_to_plot.add(field_name.lower()) - elif dataname == 'A': + elif dataname == "A": for field_name in A_fields_list: fields_to_plot.add(field_name) elif dataname in E_fields_list: @@ -2409,52 +3179,61 @@ def diagnostic_initialize_inputs(self): fields_to_plot.add(dataname) elif dataname in A_fields_list: fields_to_plot.add(dataname) - elif dataname in ['rho', 'phi', 'F', 'G', 'divE', 'divB', 'proc_number', 'part_per_cell']: + elif dataname in [ + "rho", + "phi", + "F", + "G", + "divE", + "divB", + "proc_number", + "part_per_cell", + ]: fields_to_plot.add(dataname) elif dataname in J_fields_list: fields_to_plot.add(dataname.lower()) elif dataname in J_displacement_fields_list: fields_to_plot.add(dataname.lower()) - elif dataname.startswith('rho_'): + elif dataname.startswith("rho_"): # Adds rho_species diagnostic fields_to_plot.add(dataname) - elif dataname.startswith('T_'): + elif dataname.startswith("T_"): # Adds T_species diagnostic fields_to_plot.add(dataname) - elif dataname == 'dive': - fields_to_plot.add('divE') - elif dataname == 'divb': - fields_to_plot.add('divB') - elif dataname == 'raw_fields': + elif dataname == "dive": + fields_to_plot.add("divE") + elif dataname == "divb": + fields_to_plot.add("divB") + elif dataname == "raw_fields": self.plot_raw_fields = 1 - elif dataname == 'raw_fields_guards': + elif dataname == "raw_fields_guards": self.plot_raw_fields_guards = 1 - elif dataname == 'finepatch': + elif dataname == "finepatch": self.plot_finepatch = 1 - elif dataname == 'crsepatch': + elif dataname == "crsepatch": self.plot_crsepatch = 1 - elif dataname == 'none': - fields_to_plot = set(('none',)) + elif dataname == "none": + fields_to_plot = set(("none",)) # --- Convert the set to a sorted list so that the order # --- is the same on all processors. fields_to_plot = list(fields_to_plot) fields_to_plot.sort() - self.diagnostic.set_or_replace_attr('fields_to_plot', fields_to_plot) + self.diagnostic.set_or_replace_attr("fields_to_plot", fields_to_plot) particle_fields_to_plot_names = list() for pfd in self.particle_fields_to_plot: if pfd.name in particle_fields_to_plot_names: - raise Exception('A particle fields name can not be repeated.') + raise Exception("A particle fields name can not be repeated.") particle_fields_to_plot_names.append(pfd.name) self.diagnostic.__setattr__( - f'particle_fields.{pfd.name}(x,y,z,ux,uy,uz)', pfd.func + f"particle_fields.{pfd.name}(x,y,z,ux,uy,uz)", pfd.func ) self.diagnostic.__setattr__( - f'particle_fields.{pfd.name}.do_average', pfd.do_average + f"particle_fields.{pfd.name}.do_average", pfd.do_average ) self.diagnostic.__setattr__( - f'particle_fields.{pfd.name}.filter(x,y,z,ux,uy,uz)', pfd.filter + f"particle_fields.{pfd.name}.filter(x,y,z,ux,uy,uz)", pfd.filter ) # --- Convert to a sorted list so that the order @@ -2467,7 +3246,7 @@ def diagnostic_initialize_inputs(self): self.diagnostic.plot_raw_fields_guards = self.plot_raw_fields_guards self.diagnostic.plot_finepatch = self.plot_finepatch self.diagnostic.plot_crsepatch = self.plot_crsepatch - if 'write_species' not in self.diagnostic.argvattrs: + if "write_species" not in self.diagnostic.argvattrs: self.diagnostic.write_species = False self.set_write_dir() @@ -2491,26 +3270,24 @@ class Checkpoint(picmistandard.base._ClassWithInit, WarpXDiagnosticBase): directory name. """ - def __init__(self, period = 1, write_dir = None, name = None, **kw): - + def __init__(self, period=1, write_dir=None, name=None, **kw): self.period = period self.write_dir = write_dir - self.file_prefix = kw.pop('warpx_file_prefix', None) - self.file_min_digits = kw.pop('warpx_file_min_digits', None) + self.file_prefix = kw.pop("warpx_file_prefix", None) + self.file_min_digits = kw.pop("warpx_file_min_digits", None) self.name = name if self.name is None: - self.name = 'chkpoint' + self.name = "chkpoint" self.handle_init(kw) def diagnostic_initialize_inputs(self): - self.add_diagnostic() self.diagnostic.intervals = self.period - self.diagnostic.diag_type = 'Full' - self.diagnostic.format = 'checkpoint' + self.diagnostic.diag_type = "Full" + self.diagnostic.format = "checkpoint" self.diagnostic.file_min_digits = self.file_min_digits self.set_write_dir() @@ -2528,6 +3305,11 @@ class ParticleDiagnostic(picmistandard.PICMI_ParticleDiagnostic, WarpXDiagnostic warpx_openpmd_backend: {bp, h5, json}, optional Openpmd backend file format + warpx_openpmd_encoding: 'v' (variable based), 'f' (file based) or 'g' (group based), optional + Only read if ``.format = openpmd``. openPMD file output encoding. + File based: one file per timestep (slower), group/variable based: one file for all steps (faster)). + Variable based is an experimental feature with ADIOS2. Default: `'f'`. + warpx_file_prefix: string, optional Prefix on the diagnostic file name @@ -2546,42 +3328,50 @@ class ParticleDiagnostic(picmistandard.PICMI_ParticleDiagnostic, WarpXDiagnostic a dictionary is given the keys should be species with the value specifying the stride for that species. + warpx_dump_last_timestep: bool, optional + If true, the last timestep is dumped regardless of the diagnostic period/intervals. + warpx_plot_filter_function: string, optional Analytic expression to down select the particles to in the diagnostic """ - def init(self, kw): - self.format = kw.pop('warpx_format', 'plotfile') - self.openpmd_backend = kw.pop('warpx_openpmd_backend', None) - self.file_prefix = kw.pop('warpx_file_prefix', None) - self.file_min_digits = kw.pop('warpx_file_min_digits', None) - self.random_fraction = kw.pop('warpx_random_fraction', None) - self.uniform_stride = kw.pop('warpx_uniform_stride', None) - self.plot_filter_function = kw.pop('warpx_plot_filter_function', None) + def init(self, kw): + self.format = kw.pop("warpx_format", "plotfile") + self.openpmd_backend = kw.pop("warpx_openpmd_backend", None) + self.openpmd_encoding = kw.pop("warpx_openpmd_encoding", None) + self.file_prefix = kw.pop("warpx_file_prefix", None) + self.file_min_digits = kw.pop("warpx_file_min_digits", None) + self.random_fraction = kw.pop("warpx_random_fraction", None) + self.uniform_stride = kw.pop("warpx_uniform_stride", None) + self.plot_filter_function = kw.pop("warpx_plot_filter_function", None) + self.dump_last_timestep = kw.pop("warpx_dump_last_timestep", None) self.user_defined_kw = {} if self.plot_filter_function is not None: # This allows variables to be used in the plot_filter_function, but # in order not to break other codes, the variables must begin with "warpx_" for k in list(kw.keys()): - if k.startswith('warpx_') and re.search(r'\b%s\b'%k, self.plot_filter_function): + if k.startswith("warpx_") and re.search( + r"\b%s\b" % k, self.plot_filter_function + ): self.user_defined_kw[k] = kw[k] del kw[k] self.mangle_dict = None def diagnostic_initialize_inputs(self): - self.add_diagnostic() - self.diagnostic.diag_type = 'Full' + self.diagnostic.diag_type = "Full" self.diagnostic.format = self.format self.diagnostic.openpmd_backend = self.openpmd_backend + self.diagnostic.openpmd_encoding = self.openpmd_encoding self.diagnostic.file_min_digits = self.file_min_digits + self.diagnostic.dump_last_timestep = self.dump_last_timestep self.diagnostic.intervals = self.period - self.diagnostic.set_or_replace_attr('write_species', True) - if 'fields_to_plot' not in self.diagnostic.argvattrs: - self.diagnostic.fields_to_plot = 'none' + self.diagnostic.set_or_replace_attr("write_species", True) + if "fields_to_plot" not in self.diagnostic.argvattrs: + self.diagnostic.fields_to_plot = "none" self.set_write_dir() # --- Use a set to ensure that fields don't get repeated. @@ -2589,39 +3379,59 @@ def diagnostic_initialize_inputs(self): if self.data_list is not None: for dataname in self.data_list: - if dataname == 'position': - if pywarpx.geometry.dims != '1': # because then it's WARPX_DIM_1D_Z - variables.add('x') - if pywarpx.geometry.dims == '3': - variables.add('y') - variables.add('z') - if pywarpx.geometry.dims == 'RZ': - variables.add('theta') - elif dataname == 'momentum': - variables.add('ux') - variables.add('uy') - variables.add('uz') - elif dataname == 'weighting': - variables.add('w') - elif dataname == 'fields': - variables.add('Ex') - variables.add('Ey') - variables.add('Ez') - variables.add('Bx') - variables.add('By') - variables.add('Bz') - elif dataname in ['x', 'y', 'z', 'theta', 'ux', 'uy', 'uz', 'Ex', 'Ey', 'Ez', 'Bx', 'By', 'Bz', 'Er', 'Et', 'Br', 'Bt']: - if pywarpx.geometry.dims == '1' and (dataname == 'x' or dataname == 'y'): + if dataname == "position": + if pywarpx.geometry.dims != "1": # because then it's WARPX_DIM_1D_Z + variables.add("x") + if pywarpx.geometry.dims == "3": + variables.add("y") + variables.add("z") + if pywarpx.geometry.dims == "RZ": + variables.add("theta") + elif dataname == "momentum": + variables.add("ux") + variables.add("uy") + variables.add("uz") + elif dataname == "weighting": + variables.add("w") + elif dataname == "fields": + variables.add("Ex") + variables.add("Ey") + variables.add("Ez") + variables.add("Bx") + variables.add("By") + variables.add("Bz") + elif dataname in [ + "x", + "y", + "z", + "theta", + "ux", + "uy", + "uz", + "Ex", + "Ey", + "Ez", + "Bx", + "By", + "Bz", + "Er", + "Et", + "Br", + "Bt", + ]: + if pywarpx.geometry.dims == "1" and ( + dataname == "x" or dataname == "y" + ): raise RuntimeError( f"The attribute {dataname} is not available in mode WARPX_DIM_1D_Z" f"chosen by dim={pywarpx.geometry.dims} in pywarpx." ) - elif pywarpx.geometry.dims != '3' and dataname == 'y': + elif pywarpx.geometry.dims != "3" and dataname == "y": raise RuntimeError( f"The attribute {dataname} is not available outside of mode WARPX_DIM_3D" f"The chosen value was dim={pywarpx.geometry.dims} in pywarpx." ) - elif pywarpx.geometry.dims != 'RZ' and dataname == 'theta': + elif pywarpx.geometry.dims != "RZ" and dataname == "theta": raise RuntimeError( f"The attribute {dataname} is not available outside of mode WARPX_DIM_RZ." f"The chosen value was dim={pywarpx.geometry.dims} in pywarpx." @@ -2667,21 +3477,27 @@ def diagnostic_initialize_inputs(self): self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) for name in species_names: - diag = pywarpx.Bucket.Bucket(self.name + '.' + name, - variables = variables, - random_fraction = random_fraction.get(name, random_fraction_default), - uniform_stride = uniform_stride.get(name, uniform_stride_default)) - expression = pywarpx.my_constants.mangle_expression(self.plot_filter_function, self.mangle_dict) - diag.__setattr__('plot_filter_function(t,x,y,z,ux,uy,uz)', expression) + diag = pywarpx.Bucket.Bucket( + self.name + "." + name, + variables=variables, + random_fraction=random_fraction.get(name, random_fraction_default), + uniform_stride=uniform_stride.get(name, uniform_stride_default), + ) + expression = pywarpx.my_constants.mangle_expression( + self.plot_filter_function, self.mangle_dict + ) + diag.__setattr__("plot_filter_function(t,x,y,z,ux,uy,uz)", expression) self.diagnostic._species_dict[name] = diag + # ---------------------------- # Lab frame diagnostics # ---------------------------- -class LabFrameFieldDiagnostic(picmistandard.PICMI_LabFrameFieldDiagnostic, - WarpXDiagnosticBase): +class LabFrameFieldDiagnostic( + picmistandard.PICMI_LabFrameFieldDiagnostic, WarpXDiagnosticBase +): """ See `Input Parameters `__ for more information. @@ -2694,6 +3510,11 @@ class LabFrameFieldDiagnostic(picmistandard.PICMI_LabFrameFieldDiagnostic, warpx_openpmd_backend: string, optional Passed to .openpmd_backend + warpx_openpmd_encoding: 'f' (file based) or 'g' (group based), optional + Only read if ``.format = openpmd``. openPMD file output encoding. + File based: one file per timestep (slower), group/variable based: one file for all steps (faster)). + Default: `'f'`. + warpx_file_prefix: string, optional Passed to .file_prefix @@ -2713,25 +3534,27 @@ class LabFrameFieldDiagnostic(picmistandard.PICMI_LabFrameFieldDiagnostic, warpx_upper_bound: vector of floats, optional Passed to .upper_bound """ + def init(self, kw): """The user is using the new BTD""" - self.format = kw.pop('warpx_format', None) - self.openpmd_backend = kw.pop('warpx_openpmd_backend', None) - self.file_prefix = kw.pop('warpx_file_prefix', None) - self.intervals = kw.pop('warpx_intervals', None) - self.file_min_digits = kw.pop('warpx_file_min_digits', None) - self.buffer_size = kw.pop('warpx_buffer_size', None) - self.lower_bound = kw.pop('warpx_lower_bound', None) - self.upper_bound = kw.pop('warpx_upper_bound', None) + self.format = kw.pop("warpx_format", None) + self.openpmd_backend = kw.pop("warpx_openpmd_backend", None) + self.openpmd_encoding = kw.pop("warpx_openpmd_encoding", None) + self.file_prefix = kw.pop("warpx_file_prefix", None) + self.intervals = kw.pop("warpx_intervals", None) + self.file_min_digits = kw.pop("warpx_file_min_digits", None) + self.buffer_size = kw.pop("warpx_buffer_size", None) + self.lower_bound = kw.pop("warpx_lower_bound", None) + self.upper_bound = kw.pop("warpx_upper_bound", None) def diagnostic_initialize_inputs(self): - self.add_diagnostic() - self.diagnostic.diag_type = 'BackTransformed' + self.diagnostic.diag_type = "BackTransformed" self.diagnostic.format = self.format self.diagnostic.openpmd_backend = self.openpmd_backend + self.diagnostic.openpmd_encoding = self.openpmd_encoding self.diagnostic.file_min_digits = self.file_min_digits self.diagnostic.diag_lo = self.lower_bound self.diagnostic.diag_hi = self.upper_bound @@ -2749,23 +3572,23 @@ def diagnostic_initialize_inputs(self): # --- Use a set to ensure that fields don't get repeated. fields_to_plot = set() - if pywarpx.geometry.dims == 'RZ': - E_fields_list = ['Er', 'Et', 'Ez'] - B_fields_list = ['Br', 'Bt', 'Bz'] - J_fields_list = ['Jr', 'Jt', 'Jz'] + if pywarpx.geometry.dims == "RZ": + E_fields_list = ["Er", "Et", "Ez"] + B_fields_list = ["Br", "Bt", "Bz"] + J_fields_list = ["Jr", "Jt", "Jz"] else: - E_fields_list = ['Ex', 'Ey', 'Ez'] - B_fields_list = ['Bx', 'By', 'Bz'] - J_fields_list = ['Jx', 'Jy', 'Jz'] + E_fields_list = ["Ex", "Ey", "Ez"] + B_fields_list = ["Bx", "By", "Bz"] + J_fields_list = ["Jx", "Jy", "Jz"] if self.data_list is not None: for dataname in self.data_list: - if dataname == 'E': + if dataname == "E": for field_name in E_fields_list: fields_to_plot.add(field_name) - elif dataname == 'B': + elif dataname == "B": for field_name in B_fields_list: fields_to_plot.add(field_name) - elif dataname == 'J': + elif dataname == "J": for field_name in J_fields_list: fields_to_plot.add(field_name.lower()) elif dataname in E_fields_list: @@ -2774,7 +3597,7 @@ def diagnostic_initialize_inputs(self): fields_to_plot.add(dataname) elif dataname in J_fields_list: fields_to_plot.add(dataname.lower()) - elif dataname.startswith('rho_'): + elif dataname.startswith("rho_"): # Adds rho_species diagnostic fields_to_plot.add(dataname) @@ -2782,15 +3605,16 @@ def diagnostic_initialize_inputs(self): # --- is the same on all processors. fields_to_plot = list(fields_to_plot) fields_to_plot.sort() - self.diagnostic.set_or_replace_attr('fields_to_plot', fields_to_plot) + self.diagnostic.set_or_replace_attr("fields_to_plot", fields_to_plot) - if 'write_species' not in self.diagnostic.argvattrs: + if "write_species" not in self.diagnostic.argvattrs: self.diagnostic.write_species = False self.set_write_dir() -class LabFrameParticleDiagnostic(picmistandard.PICMI_LabFrameParticleDiagnostic, - WarpXDiagnosticBase): +class LabFrameParticleDiagnostic( + picmistandard.PICMI_LabFrameParticleDiagnostic, WarpXDiagnosticBase +): """ See `Input Parameters `__ for more information. @@ -2803,6 +3627,11 @@ class LabFrameParticleDiagnostic(picmistandard.PICMI_LabFrameParticleDiagnostic, warpx_openpmd_backend: string, optional Passed to .openpmd_backend + warpx_openpmd_encoding: 'f' (file based) or 'g' (group based), optional + Only read if ``.format = openpmd``. openPMD file output encoding. + File based: one file per timestep (slower), group/variable based: one file for all steps (faster)). + Default: `'f'`. + warpx_file_prefix: string, optional Passed to .file_prefix @@ -2816,21 +3645,23 @@ class LabFrameParticleDiagnostic(picmistandard.PICMI_LabFrameParticleDiagnostic, warpx_buffer_size: integer, optional Passed to .buffer_size """ + def init(self, kw): - self.format = kw.pop('warpx_format', None) - self.openpmd_backend = kw.pop('warpx_openpmd_backend', None) - self.file_prefix = kw.pop('warpx_file_prefix', None) - self.intervals = kw.pop('warpx_intervals', None) - self.file_min_digits = kw.pop('warpx_file_min_digits', None) - self.buffer_size = kw.pop('warpx_buffer_size', None) + self.format = kw.pop("warpx_format", None) + self.openpmd_backend = kw.pop("warpx_openpmd_backend", None) + self.openpmd_encoding = kw.pop("warpx_openpmd_encoding", None) + self.file_prefix = kw.pop("warpx_file_prefix", None) + self.intervals = kw.pop("warpx_intervals", None) + self.file_min_digits = kw.pop("warpx_file_min_digits", None) + self.buffer_size = kw.pop("warpx_buffer_size", None) def diagnostic_initialize_inputs(self): - self.add_diagnostic() - self.diagnostic.diag_type = 'BackTransformed' + self.diagnostic.diag_type = "BackTransformed" self.diagnostic.format = self.format self.diagnostic.openpmd_backend = self.openpmd_backend + self.diagnostic.openpmd_encoding = self.openpmd_encoding self.diagnostic.file_min_digits = self.file_min_digits self.diagnostic.do_back_transformed_particles = True @@ -2845,9 +3676,9 @@ def diagnostic_initialize_inputs(self): self.diagnostic.do_back_transformed_fields = False - self.diagnostic.set_or_replace_attr('write_species', True) - if 'fields_to_plot' not in self.diagnostic.argvattrs: - self.diagnostic.fields_to_plot = 'none' + self.diagnostic.set_or_replace_attr("write_species", True) + if "fields_to_plot" not in self.diagnostic.argvattrs: + self.diagnostic.fields_to_plot = "none" self.set_write_dir() @@ -2856,39 +3687,59 @@ def diagnostic_initialize_inputs(self): if self.data_list is not None: for dataname in self.data_list: - if dataname == 'position': - if pywarpx.geometry.dims != '1': # because then it's WARPX_DIM_1D_Z - variables.add('x') - if pywarpx.geometry.dims == '3': - variables.add('y') - variables.add('z') - if pywarpx.geometry.dims == 'RZ': - variables.add('theta') - elif dataname == 'momentum': - variables.add('ux') - variables.add('uy') - variables.add('uz') - elif dataname == 'weighting': - variables.add('w') - elif dataname == 'fields': - variables.add('Ex') - variables.add('Ey') - variables.add('Ez') - variables.add('Bx') - variables.add('By') - variables.add('Bz') - elif dataname in ['x', 'y', 'z', 'theta', 'ux', 'uy', 'uz', 'Ex', 'Ey', 'Ez', 'Bx', 'By', 'Bz', 'Er', 'Et', 'Br', 'Bt']: - if pywarpx.geometry.dims == '1' and (dataname == 'x' or dataname == 'y'): + if dataname == "position": + if pywarpx.geometry.dims != "1": # because then it's WARPX_DIM_1D_Z + variables.add("x") + if pywarpx.geometry.dims == "3": + variables.add("y") + variables.add("z") + if pywarpx.geometry.dims == "RZ": + variables.add("theta") + elif dataname == "momentum": + variables.add("ux") + variables.add("uy") + variables.add("uz") + elif dataname == "weighting": + variables.add("w") + elif dataname == "fields": + variables.add("Ex") + variables.add("Ey") + variables.add("Ez") + variables.add("Bx") + variables.add("By") + variables.add("Bz") + elif dataname in [ + "x", + "y", + "z", + "theta", + "ux", + "uy", + "uz", + "Ex", + "Ey", + "Ez", + "Bx", + "By", + "Bz", + "Er", + "Et", + "Br", + "Bt", + ]: + if pywarpx.geometry.dims == "1" and ( + dataname == "x" or dataname == "y" + ): raise RuntimeError( f"The attribute {dataname} is not available in mode WARPX_DIM_1D_Z" f"chosen by dim={pywarpx.geometry.dims} in pywarpx." ) - elif pywarpx.geometry.dims != '3' and dataname == 'y': + elif pywarpx.geometry.dims != "3" and dataname == "y": raise RuntimeError( f"The attribute {dataname} is not available outside of mode WARPX_DIM_3D" f"The chosen value was dim={pywarpx.geometry.dims} in pywarpx." ) - elif pywarpx.geometry.dims != 'RZ' and dataname == 'theta': + elif pywarpx.geometry.dims != "RZ" and dataname == "theta": raise RuntimeError( f"The attribute {dataname} is not available outside of mode WARPX_DIM_RZ." f"The chosen value was dim={pywarpx.geometry.dims} in pywarpx." @@ -2910,8 +3761,7 @@ def diagnostic_initialize_inputs(self): species_names = [self.species.name] for name in species_names: - diag = pywarpx.Bucket.Bucket(self.name + '.' + name, - variables = variables) + diag = pywarpx.Bucket.Bucket(self.name + "." + name, variables=variables) self.diagnostic._species_dict[name] = diag @@ -3007,9 +3857,16 @@ class ReducedDiagnostic(picmistandard.base._ClassWithInit, WarpXDiagnosticBase): For diagnostic type 'FieldProbe', the vector specifying up in the 'Plane' """ - def __init__(self, diag_type, name=None, period=1, path=None, - extension=None, separator=None, **kw): - + def __init__( + self, + diag_type, + name=None, + period=1, + path=None, + extension=None, + separator=None, + **kw, + ): self.name = name self.type = diag_type self.intervals = period @@ -3024,21 +3881,29 @@ def __init__(self, diag_type, name=None, period=1, path=None, # The simple diagnostics do not require any additional arguments self._simple_reduced_diagnostics = [ - 'ParticleEnergy', 'ParticleMomentum', 'FieldEnergy', - 'FieldMomentum', 'FieldMaximum', 'RhoMaximum', 'ParticleNumber', - 'LoadBalanceCosts', 'LoadBalanceEfficiency' + "ParticleEnergy", + "ParticleMomentum", + "FieldEnergy", + "FieldMomentum", + "FieldMaximum", + "RhoMaximum", + "ParticleNumber", + "LoadBalanceCosts", + "LoadBalanceEfficiency", ] # The species diagnostics require a species to be provided self._species_reduced_diagnostics = [ - 'BeamRelevant', 'ParticleHistogram', 'ParticleExtrema' + "BeamRelevant", + "ParticleHistogram", + "ParticleExtrema", ] if self.type in self._simple_reduced_diagnostics: pass elif self.type in self._species_reduced_diagnostics: - species = kw.pop('species') + species = kw.pop("species") self.species = species.name - if self.type == 'ParticleHistogram': + if self.type == "ParticleHistogram": kw = self._handle_particle_histogram(**kw) elif self.type == "FieldProbe": kw = self._handle_field_probe(**kw) @@ -3048,8 +3913,7 @@ def __init__(self, diag_type, name=None, period=1, path=None, kw = self._handle_charge_on_eb(**kw) else: raise RuntimeError( - f"{self.type} reduced diagnostic is not yet supported " - "in pywarpx." + f"{self.type} reduced diagnostic is not yet supported " "in pywarpx." ) self.handle_init(kw) @@ -3065,15 +3929,15 @@ def _handle_field_probe(self, **kw): self.integrate = kw.pop("integrate", None) self.do_moving_window_FP = kw.pop("do_moving_window_FP", None) - if self.probe_geometry.lower() != 'point': + if self.probe_geometry.lower() != "point": self.resolution = kw.pop("resolution") - if self.probe_geometry.lower() == 'line': + if self.probe_geometry.lower() == "line": self.x1_probe = kw.pop("x1_probe", None) self.y1_probe = kw.pop("y1_probe", None) self.z1_probe = kw.pop("z1_probe") - if self.probe_geometry.lower() == 'plane': + if self.probe_geometry.lower() == "plane": self.detector_radius = kw.pop("detector_radius") self.target_normal_x = kw.pop("target_normal_x", None) @@ -3091,9 +3955,15 @@ def _handle_particle_histogram(self, **kw): self.bin_max = kw.pop("bin_max") self.bin_min = kw.pop("bin_min") self.normalization = kw.pop("normalization", None) - if self.normalization not in [None, "unity_particle_weight", "max_to_unity", "area_to_unity"]: + if self.normalization not in [ + None, + "unity_particle_weight", + "max_to_unity", + "area_to_unity", + ]: raise AttributeError( - "The ParticleHistogram normalization must be one of 'unity_particle_weight', 'max_to_unity', or 'area_to_unity'") + "The ParticleHistogram normalization must be one of 'unity_particle_weight', 'max_to_unity', or 'area_to_unity'" + ) histogram_function = kw.pop("histogram_function") filter_function = kw.pop("filter_function", None) @@ -3103,8 +3973,10 @@ def _handle_particle_histogram(self, **kw): # Check the reduced function expressions for constants for k in list(kw.keys()): - if (re.search(r'\b%s\b'%k, histogram_function) or - (filter_function is not None and re.search(r'\b%s\b'%k, filter_function))): + if re.search(r"\b%s\b" % k, histogram_function) or ( + filter_function is not None + and re.search(r"\b%s\b" % k, filter_function) + ): self.user_defined_kw[k] = kw[k] del kw[k] @@ -3114,11 +3986,13 @@ def _handle_field_reduction(self, **kw): self.reduction_type = kw.pop("reduction_type") reduced_function = kw.pop("reduced_function") - self.__setattr__("reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz,jx,jy,jz)", reduced_function) + self.__setattr__( + "reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz,jx,jy,jz)", reduced_function + ) # Check the reduced function expression for constants for k in list(kw.keys()): - if re.search(r'\b%s\b'%k, reduced_function): + if re.search(r"\b%s\b" % k, reduced_function): self.user_defined_kw[k] = kw[k] del kw[k] @@ -3131,23 +4005,199 @@ def _handle_charge_on_eb(self, **kw): # Check the reduced function expression for constants for k in list(kw.keys()): - if re.search(r'\b%s\b'%k, weighting_function): + if re.search(r"\b%s\b" % k, weighting_function): self.user_defined_kw[k] = kw[k] del kw[k] return kw def diagnostic_initialize_inputs(self): - self.add_diagnostic() self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) for key, value in self.__dict__.items(): - if not key.startswith('_') and key not in ['name', 'diagnostic']: + if not key.startswith("_") and key not in ["name", "diagnostic"]: if key.endswith(")"): # Analytic expressions require processing to deal with constants - expression = pywarpx.my_constants.mangle_expression(value, self.mangle_dict) + expression = pywarpx.my_constants.mangle_expression( + value, self.mangle_dict + ) self.diagnostic.__setattr__(key, expression) else: self.diagnostic.__setattr__(key, value) + + +class ParticleBoundaryScrapingDiagnostic( + picmistandard.PICMI_ParticleBoundaryScrapingDiagnostic, WarpXDiagnosticBase +): + """ + See `Input Parameters `__ for more information. + + Parameters + ---------- + warpx_format: openpmd + Diagnostic file format + + warpx_openpmd_backend: {bp, h5, json}, optional + Openpmd backend file format + + warpx_openpmd_encoding: 'v' (variable based), 'f' (file based) or 'g' (group based), optional + Only read if ``.format = openpmd``. openPMD file output encoding. + File based: one file per timestep (slower), group/variable based: one file for all steps (faster)). + Variable based is an experimental feature with ADIOS2. Default: `'f'`. + + warpx_file_prefix: string, optional + Prefix on the diagnostic file name + + warpx_file_min_digits: integer, optional + Minimum number of digits for the time step number in the file name + + warpx_random_fraction: float or dict, optional + Random fraction of particles to include in the diagnostic. If a float + is given the same fraction will be used for all species, if a dictionary + is given the keys should be species with the value specifying the random + fraction for that species. + + warpx_uniform_stride: integer or dict, optional + Stride to down select to the particles to include in the diagnostic. + If an integer is given the same stride will be used for all species, if + a dictionary is given the keys should be species with the value + specifying the stride for that species. + + warpx_dump_last_timestep: bool, optional + If true, the last timestep is dumped regardless of the diagnostic period/intervals. + + warpx_plot_filter_function: string, optional + Analytic expression to down select the particles to in the diagnostic + """ + + def init(self, kw): + self.format = kw.pop("warpx_format", "openpmd") + self.openpmd_backend = kw.pop("warpx_openpmd_backend", None) + self.openpmd_encoding = kw.pop("warpx_openpmd_encoding", None) + self.file_prefix = kw.pop("warpx_file_prefix", None) + self.file_min_digits = kw.pop("warpx_file_min_digits", None) + self.random_fraction = kw.pop("warpx_random_fraction", None) + self.uniform_stride = kw.pop("warpx_uniform_stride", None) + self.plot_filter_function = kw.pop("warpx_plot_filter_function", None) + self.dump_last_timestep = kw.pop("warpx_dump_last_timestep", None) + + self.user_defined_kw = {} + if self.plot_filter_function is not None: + # This allows variables to be used in the plot_filter_function, but + # in order not to break other codes, the variables must begin with "warpx_" + for k in list(kw.keys()): + if k.startswith("warpx_") and re.search( + r"\b%s\b" % k, self.plot_filter_function + ): + self.user_defined_kw[k] = kw[k] + del kw[k] + + self.mangle_dict = None + + def diagnostic_initialize_inputs(self): + self.add_diagnostic() + + self.diagnostic.diag_type = "BoundaryScraping" + self.diagnostic.format = self.format + self.diagnostic.openpmd_backend = self.openpmd_backend + self.diagnostic.openpmd_encoding = self.openpmd_encoding + self.diagnostic.file_min_digits = self.file_min_digits + self.diagnostic.dump_last_timestep = self.dump_last_timestep + self.diagnostic.intervals = self.period + self.diagnostic.set_or_replace_attr("write_species", True) + if "fields_to_plot" not in self.diagnostic.argvattrs: + self.diagnostic.fields_to_plot = "none" + + self.set_write_dir() + + # --- Use a set to ensure that fields don't get repeated. + variables = set() + + if self.data_list is not None: + for dataname in self.data_list: + if dataname == "position": + if pywarpx.geometry.dims != "1": # because then it's WARPX_DIM_1D_Z + variables.add("x") + if pywarpx.geometry.dims == "3": + variables.add("y") + variables.add("z") + if pywarpx.geometry.dims == "RZ": + variables.add("theta") + elif dataname == "momentum": + variables.add("ux") + variables.add("uy") + variables.add("uz") + elif dataname == "weighting": + variables.add("w") + elif dataname in ["x", "y", "z", "theta", "ux", "uy", "uz"]: + if pywarpx.geometry.dims == "1" and ( + dataname == "x" or dataname == "y" + ): + raise RuntimeError( + f"The attribute {dataname} is not available in mode WARPX_DIM_1D_Z" + f"chosen by dim={pywarpx.geometry.dims} in pywarpx." + ) + elif pywarpx.geometry.dims != "3" and dataname == "y": + raise RuntimeError( + f"The attribute {dataname} is not available outside of mode WARPX_DIM_3D" + f"The chosen value was dim={pywarpx.geometry.dims} in pywarpx." + ) + elif pywarpx.geometry.dims != "RZ" and dataname == "theta": + raise RuntimeError( + f"The attribute {dataname} is not available outside of mode WARPX_DIM_RZ." + f"The chosen value was dim={pywarpx.geometry.dims} in pywarpx." + ) + else: + variables.add(dataname) + else: + # possibly add user defined attributes + variables.add(dataname) + + # --- Convert the set to a sorted list so that the order + # --- is the same on all processors. + variables = list(variables) + variables.sort() + + # species list + if self.species is None: + species_names = pywarpx.particles.species_names + elif np.iterable(self.species): + species_names = [species.name for species in self.species] + else: + species_names = [self.species.name] + + # check if random fraction is specified and whether a value is given per species + random_fraction = {} + random_fraction_default = self.random_fraction + if isinstance(self.random_fraction, dict): + random_fraction_default = 1.0 + for key, val in self.random_fraction.items(): + random_fraction[key.name] = val + + # check if uniform stride is specified and whether a value is given per species + uniform_stride = {} + uniform_stride_default = self.uniform_stride + if isinstance(self.uniform_stride, dict): + uniform_stride_default = 1 + for key, val in self.uniform_stride.items(): + uniform_stride[key.name] = val + + if self.mangle_dict is None: + # Only do this once so that the same variables are used in this distribution + # is used multiple times + self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) + + for name in species_names: + diag = pywarpx.Bucket.Bucket( + self.name + "." + name, + variables=variables, + random_fraction=random_fraction.get(name, random_fraction_default), + uniform_stride=uniform_stride.get(name, uniform_stride_default), + ) + expression = pywarpx.my_constants.mangle_expression( + self.plot_filter_function, self.mangle_dict + ) + diag.__setattr__("plot_filter_function(t,x,y,z,ux,uy,uz)", expression) + self.diagnostic._species_dict[name] = diag diff --git a/Python/setup.py b/Python/setup.py index 31f35eeceac..86585bf8886 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -19,8 +19,18 @@ from setuptools import setup argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument('--with-libwarpx', type=str, default=None, help='Install libwarpx with the given value as DIM. This option is only used by the GNU makefile build system.') -argparser.add_argument('--with-lib-dir', type=str, default=None, help='Install with all libwarpx* binaries found in a directory.') +argparser.add_argument( + "--with-libwarpx", + type=str, + default=None, + help="Install libwarpx with the given value as DIM. This option is only used by the GNU makefile build system.", +) +argparser.add_argument( + "--with-lib-dir", + type=str, + default=None, + help="Install with all libwarpx* binaries found in a directory.", +) args, unknown = argparser.parse_known_args() sys.argv = [sys.argv[0]] + unknown @@ -28,38 +38,39 @@ # Allow to control options via environment vars. # Work-around for https://github.com/pypa/setuptools/issues/1712 -PYWARPX_LIB_DIR = os.environ.get('PYWARPX_LIB_DIR') +PYWARPX_LIB_DIR = os.environ.get("PYWARPX_LIB_DIR") if args.with_libwarpx: # GNUmake if args.with_libwarpx not in allowed_dims: print("WARNING: '%s' is not an allowed WarpX DIM" % args.with_libwarpx) - package_data = {'pywarpx' : ['libwarpx.%s.so' % args.with_libwarpx]} + package_data = {"pywarpx": ["libwarpx.%s.so" % args.with_libwarpx]} data_files = [] elif args.with_lib_dir or PYWARPX_LIB_DIR: # CMake and Package Managers - package_data = {'pywarpx' : []} + package_data = {"pywarpx": []} lib_dir = args.with_lib_dir if args.with_lib_dir else PYWARPX_LIB_DIR my_path = os.path.dirname(os.path.realpath(__file__)) for dim in allowed_dims: - lib_name = 'libwarpx.%s.so' % dim + lib_name = "libwarpx.%s.so" % dim lib_path = os.path.join(lib_dir, lib_name) link_name = os.path.join(my_path, "pywarpx", lib_name) if os.path.isfile(link_name): os.remove(link_name) if os.path.isfile(lib_path) and os.access(lib_path, os.R_OK): os.symlink(lib_path, link_name) - package_data['pywarpx'].append(lib_name) + package_data["pywarpx"].append(lib_name) else: package_data = {} -setup(name = 'pywarpx', - version = '24.07', - packages = ['pywarpx'], - package_dir = {'pywarpx': 'pywarpx'}, - description = """Wrapper of WarpX""", - package_data = package_data, - install_requires = ['numpy', 'picmistandard==0.29.0', 'periodictable'], - python_requires = '>=3.8', - zip_safe=False +setup( + name="pywarpx", + version="24.08", + packages=["pywarpx"], + package_dir={"pywarpx": "pywarpx"}, + description="""Wrapper of WarpX""", + package_data=package_data, + install_requires=["numpy", "picmistandard==0.30.0", "periodictable"], + python_requires=">=3.8", + zip_safe=False, ) diff --git a/README.md b/README.md index b2de2211b60..7760a004081 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Discussions](https://img.shields.io/badge/chat-discussions-turquoise.svg)](https://github.com/ECP-WarpX/WarpX/discussions) [![Supported Platforms](https://img.shields.io/badge/platforms-linux%20|%20osx%20|%20win-blue)](https://warpx.readthedocs.io/en/latest/install/users.html) [![GitHub commits since last release](https://img.shields.io/github/commits-since/ECP-WarpX/WarpX/latest/development.svg)](https://github.com/ECP-WarpX/WarpX/compare/development) -[![Exascale Computing Project](https://img.shields.io/badge/supported%20by-ECP-orange)](https://www.exascaleproject.org/research/) +[![HPSF](https://img.shields.io/badge/hosted%20by-HPSF-orange)](https://hpsf.io) [![Language: C++17](https://img.shields.io/badge/language-C%2B%2B17-orange.svg)](https://isocpp.org/) [![Language: Python](https://img.shields.io/badge/language-Python-orange.svg)](https://python.org/) [![License WarpX](https://img.shields.io/badge/license-BSD--3--Clause--LBNL-blue.svg)](https://spdx.org/licenses/BSD-3-Clause-LBNL.html) @@ -45,6 +45,14 @@ To contact the developers, feel free to open an issue on this repo, or visit our [![SENSEI](https://img.shields.io/static/v1?label="runs%20on"&message="SENSEI"&color="blueviolet")](https://sensei-insitu.org) Our workflow is described in [CONTRIBUTING.rst](CONTRIBUTING.rst). +We invite you to contribute to WarpX in any form following our [Code of Conduct](https://warpx.readthedocs.io/en/latest/coc.html), e.g., contribute to [discussions](https://github.com/ECP-WarpX/WarpX/discussions), help each other in [issues](https://github.com/ECP-WarpX/WarpX/issues), fix bugs, or add [documentation](https://warpx.readthedocs.io/en/latest/developers/documentation.html) and new functionality! + +## Governance + +WarpX is hosted by the High Performance Computing Foundation (HPSF). +If your organization wants to help steer the evolution of the HPC software ecosystem, visit [hpsf.io](https://hpsf.io) and consider joining! + +The WarpX open governance model is described in [GOVERNANCE.rst](GOVERNANCE.rst). ## Copyright Notice diff --git a/Regression/Checksum/benchmark.py b/Regression/Checksum/benchmark.py index fbbe44f98b0..549900da628 100644 --- a/Regression/Checksum/benchmark.py +++ b/Regression/Checksum/benchmark.py @@ -34,8 +34,9 @@ def __init__(self, test_name, data=None): """ self.test_name = test_name - self.json_file = os.path.join(config.benchmark_location, - self.test_name + '.json') + self.json_file = os.path.join( + config.benchmark_location, self.test_name + ".json" + ) if data is None: self.data = self.get() else: @@ -45,7 +46,7 @@ def reset(self): """ Update the benchmark (overwrites reference json file). """ - with open(self.json_file, 'w') as outfile: + with open(self.json_file, "w") as outfile: json.dump(self.data, outfile, sort_keys=True, indent=2) def get(self): diff --git a/Regression/Checksum/benchmarks_json/BeamBeamCollision.json b/Regression/Checksum/benchmarks_json/BeamBeamCollision.json deleted file mode 100644 index 799692135ce..00000000000 --- a/Regression/Checksum/benchmarks_json/BeamBeamCollision.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "lev=0": { - "Bx": 958613893612.4355, - "By": 958606286084.2804, - "Bz": 50291310.73170665, - "Ex": 2.873993867215236e+20, - "Ey": 2.8740263458334176e+20, - "Ez": 1.3469564521662371e+17, - "rho_beam1": 7.96926761425663e+16, - "rho_beam2": 7.969234189119718e+16, - "rho_ele1": 325562788515568.7, - "rho_ele2": 301373974746269.7, - "rho_pos1": 314013278169396.75, - "rho_pos2": 311298336003435.56 - }, - "beam1": { - "particle_opticalDepthQSR": 104848.69019384333, - "particle_position_x": 0.0015001641452988207, - "particle_position_y": 0.0015001296473841738, - "particle_position_z": 0.004965480036291212, - "particle_momentum_x": 6.203657034942546e-15, - "particle_momentum_y": 6.161790111190829e-15, - "particle_momentum_z": 6.806194292286189e-12, - "particle_weight": 635868088.3867786 - }, - "beam2": { - "particle_opticalDepthQSR": 104197.28107371755, - "particle_position_x": 0.0015001452558405398, - "particle_position_y": 0.0015001281739351966, - "particle_position_z": 0.0049656445643994716, - "particle_momentum_x": 6.202758467582172e-15, - "particle_momentum_y": 6.18910011814166e-15, - "particle_momentum_z": 6.7994521022372906e-12, - "particle_weight": 635874794.3085052 - }, - "ele1": { - "particle_opticalDepthQSR": 398.7154177999122, - "particle_position_x": 5.2166787076833645e-06, - "particle_position_y": 5.005755590473258e-06, - "particle_position_z": 1.856829463647771e-05, - "particle_momentum_x": 6.0736878569270085e-18, - "particle_momentum_y": 5.735020185191748e-18, - "particle_momentum_z": 2.827581034346608e-15, - "particle_weight": 2602683.4209351614 - }, - "ele2": { - "particle_opticalDepthQSR": 328.6975869797729, - "particle_position_x": 4.984003903707884e-06, - "particle_position_y": 4.695016970410262e-06, - "particle_position_z": 1.606918799511055e-05, - "particle_momentum_x": 4.524294388810778e-18, - "particle_momentum_y": 4.193609622515901e-18, - "particle_momentum_z": 2.624217472737641e-15, - "particle_weight": 2432495.8168380223 - }, - "pho1": { - "particle_opticalDepthBW": 10028.214317531058, - "particle_position_x": 0.00014200324200040716, - "particle_position_y": 0.00014310262095706036, - "particle_position_z": 0.00047470309948487784, - "particle_momentum_x": 0.0, - "particle_momentum_y": 0.0, - "particle_momentum_z": 0.0, - "particle_weight": 61455533.15171491 - }, - "pho2": { - "particle_opticalDepthBW": 10261.48950301913, - "particle_position_x": 0.0001465092909391631, - "particle_position_y": 0.00014555115652303745, - "particle_position_z": 0.00048686081947093, - "particle_momentum_x": 0.0, - "particle_momentum_y": 0.0, - "particle_momentum_z": 0.0, - "particle_weight": 61924991.09906147 - }, - "pos1": { - "particle_opticalDepthQSR": 380.4787933889546, - "particle_position_x": 5.59226140958729e-06, - "particle_position_y": 5.199149983019462e-06, - "particle_position_z": 1.7261766049926983e-05, - "particle_momentum_x": 5.182944941041321e-18, - "particle_momentum_y": 4.665394338329992e-18, - "particle_momentum_z": 2.565450485567441e-15, - "particle_weight": 2523696.1743423166 - }, - "pos2": { - "particle_opticalDepthQSR": 378.7526306435402, - "particle_position_x": 4.812490588954386e-06, - "particle_position_y": 4.351750384371962e-06, - "particle_position_z": 1.7621416174292307e-05, - "particle_momentum_x": 4.979887438720444e-18, - "particle_momentum_y": 4.8215630209506066e-18, - "particle_momentum_z": 2.193964301475807e-15, - "particle_weight": 2513162.277112609 - } -} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphereEB_RZ_MR.json b/Regression/Checksum/benchmarks_json/ElectrostaticSphereEB_RZ_MR.json deleted file mode 100644 index ffa8d68f9d9..00000000000 --- a/Regression/Checksum/benchmarks_json/ElectrostaticSphereEB_RZ_MR.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "lev=0": { - "Er": 8487.661571739109, - "phi": 2036.0428085225362 - }, - "lev=1": { - "Er": 19519.172334977942, - "phi": 3291.0262856782897 - } -} diff --git a/Regression/Checksum/benchmarks_json/FluxInjection.json b/Regression/Checksum/benchmarks_json/FluxInjection.json deleted file mode 100644 index 5a80590891c..00000000000 --- a/Regression/Checksum/benchmarks_json/FluxInjection.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "electron": { - "particle_momentum_x": 7.168456345337534e-18, - "particle_momentum_y": 7.02290351254873e-18, - "particle_momentum_z": 9.565641373942318e-42, - "particle_position_x": 6962.988311042427, - "particle_position_y": 2034.5301680154264, - "particle_theta": 6397.068924320389, - "particle_weight": 3.215011942598676e-08 - }, - "lev=0": { - "Bz": 9.526664429810971e-24 - } -} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/LaserAcceleration_1d_fluid.json b/Regression/Checksum/benchmarks_json/LaserAcceleration_1d_fluid.json deleted file mode 100644 index 2843e49ce22..00000000000 --- a/Regression/Checksum/benchmarks_json/LaserAcceleration_1d_fluid.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "lev=0": { - "Bx": 14264658.38987597, - "By": 0.0, - "Bz": 0.0, - "Ex": 0.0, - "Ey": 4276056420659746.5, - "Ez": 762168740318568.1, - "jx": 0.0, - "jy": 7.47674123799233e+16, - "jz": 4.817762115932484e+17, - "rho": 1609691680.1267354 - } -} - diff --git a/Regression/Checksum/benchmarks_json/LaserIonAcc3d.json b/Regression/Checksum/benchmarks_json/LaserIonAcc3d.json deleted file mode 100644 index de5472105d9..00000000000 --- a/Regression/Checksum/benchmarks_json/LaserIonAcc3d.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "electrons": { - "particle_momentum_x": 1.6966182372218133e-16, - "particle_momentum_y": 2.6850066145197374e-17, - "particle_momentum_z": 2.0052710316284176e-16, - "particle_position_x": 0.3393352015355679, - "particle_position_y": 1.1078675395554147, - "particle_position_z": 0.3419438867441836, - "particle_weight": 26433181926540.81 - }, - "hydrogen": { - "particle_momentum_x": 1.7161831722699107e-16, - "particle_momentum_y": 4.9196233343263506e-17, - "particle_momentum_z": 2.1370961936359413e-16, - "particle_position_x": 0.3375134789944616, - "particle_position_y": 1.1080021730384098, - "particle_position_z": 0.33939049172256086, - "particle_weight": 26441597005520.95 - }, - "lev=0": { - "Bx": 41555976.87146437, - "By": 175750876.1712573, - "Bz": 35156983.723599546, - "Ex": 3.872657491899755e+17, - "Ey": 3.3815796095277564e+16, - "Ez": 3.937276394651024e+17, - "jx": 3.5072653955241413e+21, - "jy": 4.011484251839508e+20, - "jz": 3.787151010057889e+21, - "rho": 7429502184315.598 - } -} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/Python_dsmc_1d.json b/Regression/Checksum/benchmarks_json/Python_dsmc_1d.json deleted file mode 100644 index 53c3708056f..00000000000 --- a/Regression/Checksum/benchmarks_json/Python_dsmc_1d.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "lev=0": { - "rho_electrons": 0.004434311371276535, - "rho_he_ions": 0.005200489146365628 - }, - "he_ions": { - "particle_momentum_x": 2.7688639005236794e-19, - "particle_momentum_y": 2.760648864116014e-19, - "particle_momentum_z": 3.6226628630061563e-19, - "particle_position_x": 2201.614485497906, - "particle_weight": 17190996093750.002 - }, - "neutrals": { - "particle_momentum_x": 1.4040775167811838e-19, - "particle_momentum_y": 1.4009514702703257e-19, - "particle_momentum_z": 1.4093144247152345e-19, - "particle_position_x": 1119.524782452131, - "particle_weight": 6.4588e+19 - }, - "electrons": { - "particle_momentum_x": 3.5193566020597954e-20, - "particle_momentum_y": 3.5368803263788353e-20, - "particle_momentum_z": 1.2572273121326582e-19, - "particle_position_x": 2139.3709122461873, - "particle_weight": 14579566406250.002 - } -} diff --git a/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_landau_damping_2d.json b/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_landau_damping_2d.json deleted file mode 100644 index e61206d19e3..00000000000 --- a/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_landau_damping_2d.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "lev=0": { - "Bx": 0.0, - "By": 7.079679609748623e-06, - "Bz": 0.0, - "Ex": 2726044.0536666242, - "Ey": 0.0, - "Ez": 4060168.6414095857, - "jx": 177543428.8941278, - "jy": 187432087.03814715, - "jz": 594259755.4658135 - }, - "ions": { - "particle_momentum_x": 9.141594694084731e-17, - "particle_momentum_y": 9.135546407258978e-17, - "particle_momentum_z": 9.137866220861254e-17, - "particle_position_x": 1197.3344862524336, - "particle_position_y": 153269.17690371818, - "particle_weight": 8.032598963696067e+16 - } -} diff --git a/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_magnetic_reconnection_2d.json b/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_magnetic_reconnection_2d.json deleted file mode 100644 index 316bcb5b30d..00000000000 --- a/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_magnetic_reconnection_2d.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "lev=0": { - "Bx": 1524.8789585554075, - "By": 639.8314135126764, - "Bz": 7.476064371022787, - "Ex": 56500024.54347144, - "Ey": 75064104.7364582, - "Ez": 309548482.989921 - }, - "ions": { - "particle_momentum_x": 7.142955224072594e-15, - "particle_momentum_y": 7.13807805985974e-15, - "particle_momentum_z": 7.141134511815448e-15, - "particle_position_x": 11170689.202853566, - "particle_position_y": 5585328.08326772, - "particle_weight": 9.036667901693183e+18 - } -} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/TwoParticle_electrostatic.json b/Regression/Checksum/benchmarks_json/TwoParticle_electrostatic.json deleted file mode 100644 index aaf04f8a74c..00000000000 --- a/Regression/Checksum/benchmarks_json/TwoParticle_electrostatic.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "electron1": { - "particle_momentum_x": 3.346088201352191e-29, - "particle_momentum_y": 3.346088199932699e-29, - "particle_momentum_z": 3.3460881978884573e-29, - "particle_position_x": 0.1545496421786394, - "particle_position_y": 0.15454964213891717, - "particle_position_z": 0.15454964208395047, - "particle_weight": 1.0 - }, - "electron2": { - "particle_momentum_x": 3.346088199424244e-29, - "particle_momentum_y": 3.346088202432085e-29, - "particle_momentum_z": 3.346088202108714e-29, - "particle_position_x": 0.15454964215048347, - "particle_position_y": 0.15454964222866666, - "particle_position_z": 0.15454964222208387, - "particle_weight": 1.0 - }, - "lev=0": { - "Ex": 7.101527209952963e-05, - "Ey": 7.10152721046017e-05, - "Ez": 7.101527211163835e-05, - "rho": 1.3125030985727997e-15 - } -} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/collisionISO.json b/Regression/Checksum/benchmarks_json/collisionISO.json deleted file mode 100644 index a2fd6116cb8..00000000000 --- a/Regression/Checksum/benchmarks_json/collisionISO.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "lev=0": { - "Bx": 0.0, - "By": 0.0, - "Bz": 0.0, - "Ex": 0.0, - "Ey": 0.0, - "Ez": 0.0, - "jx": 0.0, - "jy": 0.0, - "jz": 0.0 - }, - "electron": { - "particle_momentum_x": 3.579989064013309e-19, - "particle_momentum_y": 3.5822945977746767e-19, - "particle_momentum_z": 3.579753452653627e-19, - "particle_position_x": 1.0241322532163375, - "particle_position_y": 1.0238995904625479, - "particle_position_z": 1.02402135051502, - "particle_weight": 714240000000.0 - } -} diff --git a/Regression/Checksum/benchmarks_json/collisionXYZ.json b/Regression/Checksum/benchmarks_json/collisionXYZ.json deleted file mode 100644 index 2aa0e4686eb..00000000000 --- a/Regression/Checksum/benchmarks_json/collisionXYZ.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "lev=0": { - "Bx": 0.0, - "By": 0.0, - "Bz": 0.0, - "Ex": 0.0, - "Ey": 0.0, - "Ez": 0.0, - "T_electron": 381488.6528070591, - "T_ion": 320091.2785835478 - }, - "electron": { - "particle_momentum_x": 8.667025573698235e-19, - "particle_momentum_y": 8.457499789250831e-19, - "particle_momentum_z": 8.482438182280524e-19, - "particle_position_x": 21262567.138872623, - "particle_position_y": 21245135.070665065, - "particle_position_z": 21232644.283726066, - "particle_weight": 7.168263344048695e+28 - }, - "ion": { - "particle_momentum_x": 1.9300495097720012e-18, - "particle_momentum_y": 1.747257416857836e-18, - "particle_momentum_z": 1.7510296287537058e-18, - "particle_position_x": 21217348.883301035, - "particle_position_y": 21300859.0630925, - "particle_position_z": 21237901.246521123, - "particle_weight": 7.168263344048695e+28 - } -} diff --git a/Regression/Checksum/benchmarks_json/collisionXZ.json b/Regression/Checksum/benchmarks_json/collisionXZ.json deleted file mode 100644 index 49138f0a1df..00000000000 --- a/Regression/Checksum/benchmarks_json/collisionXZ.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "lev=0": { - "Bx": 0.0, - "By": 0.0, - "Bz": 0.0, - "Ex": 0.0, - "Ey": 0.0, - "Ez": 0.0 - }, - "ion": { - "particle_momentum_x": 2.458306853810186e-19, - "particle_momentum_y": 2.272685285153902e-19, - "particle_momentum_z": 2.281205462681013e-19, - "particle_position_x": 2645436.647039526, - "particle_position_y": 2672571.48688055, - "particle_weight": 1.7256099431746894e+26 - }, - "electron": { - "particle_momentum_x": 1.0454942263455085e-19, - "particle_momentum_y": 1.0323735347957779e-19, - "particle_momentum_z": 1.0199134968670343e-19, - "particle_position_x": 2681776.3648108337, - "particle_position_y": 2663907.8843079703, - "particle_weight": 1.7256099431746894e+26 - } -} diff --git a/Regression/Checksum/benchmarks_json/embedded_boundary_cube_macroscopic.json b/Regression/Checksum/benchmarks_json/embedded_boundary_cube_macroscopic.json deleted file mode 100644 index c759f36ac5d..00000000000 --- a/Regression/Checksum/benchmarks_json/embedded_boundary_cube_macroscopic.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "lev=0": { - "Bx": 3.898540288712651e-18, - "By": 0.005101824310293573, - "Bz": 0.005101824310293573, - "Ex": 4414725.184731114, - "Ey": 6.323754812712063e-05, - "Ez": 6.323754812712063e-05 - } -} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/multi_J_rz_psatd.json b/Regression/Checksum/benchmarks_json/multi_J_rz_psatd.json deleted file mode 100644 index f30e773e7e0..00000000000 --- a/Regression/Checksum/benchmarks_json/multi_J_rz_psatd.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "lev=0": { - "Bt": 24080.416715463354, - "Er": 4536303784778.672, - "Ez": 4298815071343.07, - "jr": 361182004529074.8, - "jz": 1802215706551553.5, - "rho": 4884623.957368025, - "rho_driver": 6288266.101815153, - "rho_plasma_e": 49568366.40537152, - "rho_plasma_p": 50769182.21072973 - }, - "driver": { - "particle_momentum_x": 8.723405122353729e-16, - "particle_momentum_y": 8.719285567351437e-16, - "particle_momentum_z": 5.461771334692466e-13, - "particle_position_x": 6.269566322411488, - "particle_position_y": 17.934200805964075, - "particle_theta": 1570790.0436095877, - "particle_weight": 6241484108.424456 - }, - "plasma_p": { - "particle_momentum_x": 6.650539058831456e-20, - "particle_momentum_y": 6.776260514923786e-20, - "particle_momentum_z": 5.470216831432835e-20, - "particle_position_x": 1.1365201443471713, - "particle_position_y": 0.6152066517828133, - "particle_theta": 20286.92798337582, - "particle_weight": 1002457942911.3788 - }, - "plasma_e": { - "particle_momentum_x": 6.655027717314839e-20, - "particle_momentum_y": 6.730480164464723e-20, - "particle_momentum_z": 2.8073811669581434e-20, - "particle_position_x": 1.1423427658689635, - "particle_position_y": 0.6140113094028803, - "particle_theta": 20188.939948727297, - "particle_weight": 1002457942911.3788 - } -} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/test_1d_collision_z.json b/Regression/Checksum/benchmarks_json/test_1d_collision_z.json new file mode 100644 index 00000000000..e517fc2b281 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_1d_collision_z.json @@ -0,0 +1,20 @@ +{ + "lev=0": { + "Bx": 0.0, + "By": 0.0, + "Bz": 0.0, + "Ex": 0.0, + "Ey": 0.0, + "Ez": 0.0, + "jx": 0.0, + "jy": 0.0, + "jz": 0.0 + }, + "ions": { + "particle_momentum_x": 3.4242515316949867e-16, + "particle_momentum_y": 3.441515880563085e-16, + "particle_momentum_z": 5.537993210573513e-16, + "particle_position_x": 720.0714079424476, + "particle_weight": 1.0999999999999997e+24 + } +} diff --git a/Regression/Checksum/benchmarks_json/test_1d_dsmc_picmi.json b/Regression/Checksum/benchmarks_json/test_1d_dsmc_picmi.json new file mode 100644 index 00000000000..62f915cf2e8 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_1d_dsmc_picmi.json @@ -0,0 +1,27 @@ +{ + "lev=0": { + "rho_electrons": 0.004437338851654305, + "rho_he_ions": 0.005200276265886133 + }, + "he_ions": { + "particle_momentum_x": 2.768463746716725e-19, + "particle_momentum_y": 2.7585450668167785e-19, + "particle_momentum_z": 3.6189671443598533e-19, + "particle_position_x": 2201.408357891233, + "particle_weight": 17190472656250.002 + }, + "electrons": { + "particle_momentum_x": 3.523554668287801e-20, + "particle_momentum_y": 3.515628626179393e-20, + "particle_momentum_z": 1.258711379033217e-19, + "particle_position_x": 2140.8168584833174, + "particle_weight": 14588988281250.002 + }, + "neutrals": { + "particle_momentum_x": 1.4054952479597137e-19, + "particle_momentum_y": 1.403311018061206e-19, + "particle_momentum_z": 1.411491089895956e-19, + "particle_position_x": 1119.82858839282, + "particle_weight": 6.4588e+19 + } +} diff --git a/Regression/Checksum/benchmarks_json/Langmuir_fluid_1D.json b/Regression/Checksum/benchmarks_json/test_1d_langmuir_fluid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_fluid_1D.json rename to Regression/Checksum/benchmarks_json/test_1d_langmuir_fluid.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_1d.json b/Regression/Checksum/benchmarks_json/test_1d_langmuir_multi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_langmuir_multi.json diff --git a/Regression/Checksum/benchmarks_json/LaserAcceleration_1d.json b/Regression/Checksum/benchmarks_json/test_1d_laser_acceleration.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserAcceleration_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_laser_acceleration.json diff --git a/Regression/Checksum/benchmarks_json/LaserAcceleration_1d_fluid_boosted.json b/Regression/Checksum/benchmarks_json/test_1d_laser_acceleration_fluid_boosted.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserAcceleration_1d_fluid_boosted.json rename to Regression/Checksum/benchmarks_json/test_1d_laser_acceleration_fluid_boosted.json diff --git a/Regression/Checksum/benchmarks_json/Python_LaserAcceleration_1d.json b/Regression/Checksum/benchmarks_json/test_1d_laser_acceleration_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_LaserAcceleration_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_laser_acceleration_picmi.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjection_1d.json b/Regression/Checksum/benchmarks_json/test_1d_laser_injection.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjection_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_laser_injection.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile_1d.json b/Regression/Checksum/benchmarks_json/test_1d_laser_injection_from_lasy_file.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_laser_injection_from_lasy_file.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile_1d_boost.json b/Regression/Checksum/benchmarks_json/test_1d_laser_injection_from_lasy_file_boost.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile_1d_boost.json rename to Regression/Checksum/benchmarks_json/test_1d_laser_injection_from_lasy_file_boost.json diff --git a/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_EM_modes_1d.json b/Regression/Checksum/benchmarks_json/test_1d_ohm_solver_em_modes_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_ohms_law_solver_EM_modes_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_ohm_solver_em_modes_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_ion_beam_1d.json b/Regression/Checksum/benchmarks_json/test_1d_ohm_solver_ion_beam_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_ohms_law_solver_ion_beam_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_ohm_solver_ion_beam_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Python_PlasmaAcceleration1d.json b/Regression/Checksum/benchmarks_json/test_1d_plasma_acceleration_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_PlasmaAcceleration1d.json rename to Regression/Checksum/benchmarks_json/test_1d_plasma_acceleration_picmi.json diff --git a/Regression/Checksum/benchmarks_json/resample_velocity_coincidence_thinning.json b/Regression/Checksum/benchmarks_json/test_1d_resample_velocity_coincidence_thinning.json similarity index 100% rename from Regression/Checksum/benchmarks_json/resample_velocity_coincidence_thinning.json rename to Regression/Checksum/benchmarks_json/test_1d_resample_velocity_coincidence_thinning.json diff --git a/Regression/Checksum/benchmarks_json/resample_velocity_coincidence_thinning_cartesian.json b/Regression/Checksum/benchmarks_json/test_1d_resample_velocity_coincidence_thinning_cartesian.json similarity index 100% rename from Regression/Checksum/benchmarks_json/resample_velocity_coincidence_thinning_cartesian.json rename to Regression/Checksum/benchmarks_json/test_1d_resample_velocity_coincidence_thinning_cartesian.json diff --git a/Regression/Checksum/benchmarks_json/SemiImplicitPicard_1d.json b/Regression/Checksum/benchmarks_json/test_1d_semi_implicit_picard.json similarity index 100% rename from Regression/Checksum/benchmarks_json/SemiImplicitPicard_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_semi_implicit_picard.json diff --git a/Regression/Checksum/benchmarks_json/silver_mueller_1d.json b/Regression/Checksum/benchmarks_json/test_1d_silver_mueller.json similarity index 100% rename from Regression/Checksum/benchmarks_json/silver_mueller_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_silver_mueller.json diff --git a/Regression/Checksum/benchmarks_json/ThetaImplicitPicard_1d.json b/Regression/Checksum/benchmarks_json/test_1d_theta_implicit_picard.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ThetaImplicitPicard_1d.json rename to Regression/Checksum/benchmarks_json/test_1d_theta_implicit_picard.json diff --git a/Regression/Checksum/benchmarks_json/averaged_galilean_2d_psatd.json b/Regression/Checksum/benchmarks_json/test_2d_averaged_galilean_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/averaged_galilean_2d_psatd.json rename to Regression/Checksum/benchmarks_json/test_2d_averaged_galilean_psatd.json diff --git a/Regression/Checksum/benchmarks_json/averaged_galilean_2d_psatd_hybrid.json b/Regression/Checksum/benchmarks_json/test_2d_averaged_galilean_psatd_hybrid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/averaged_galilean_2d_psatd_hybrid.json rename to Regression/Checksum/benchmarks_json/test_2d_averaged_galilean_psatd_hybrid.json diff --git a/Regression/Checksum/benchmarks_json/background_mcc.json b/Regression/Checksum/benchmarks_json/test_2d_background_mcc.json similarity index 100% rename from Regression/Checksum/benchmarks_json/background_mcc.json rename to Regression/Checksum/benchmarks_json/test_2d_background_mcc.json diff --git a/Regression/Checksum/benchmarks_json/background_mcc_dp_psp.json b/Regression/Checksum/benchmarks_json/test_2d_background_mcc_dp_psp.json similarity index 100% rename from Regression/Checksum/benchmarks_json/background_mcc_dp_psp.json rename to Regression/Checksum/benchmarks_json/test_2d_background_mcc_dp_psp.json diff --git a/Regression/Checksum/benchmarks_json/bilinear_filter.json b/Regression/Checksum/benchmarks_json/test_2d_bilinear_filter.json similarity index 100% rename from Regression/Checksum/benchmarks_json/bilinear_filter.json rename to Regression/Checksum/benchmarks_json/test_2d_bilinear_filter.json diff --git a/Regression/Checksum/benchmarks_json/test_2d_collision_xz.json b/Regression/Checksum/benchmarks_json/test_2d_collision_xz.json new file mode 100644 index 00000000000..1e01ddcd291 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_2d_collision_xz.json @@ -0,0 +1,26 @@ +{ + "lev=0": { + "Bx": 0.0, + "By": 0.0, + "Bz": 0.0, + "Ex": 0.0, + "Ey": 0.0, + "Ez": 0.0 + }, + "ion": { + "particle_momentum_x": 2.4848259831544605e-19, + "particle_momentum_y": 2.268622463170605e-19, + "particle_momentum_z": 2.266703976728937e-19, + "particle_position_x": 2661759.7677191226, + "particle_position_y": 2654536.6931685647, + "particle_weight": 1.7256099431746894e+26 + }, + "electron": { + "particle_momentum_x": 1.0437899826798073e-19, + "particle_momentum_y": 1.0175192222562617e-19, + "particle_momentum_z": 1.0262602372143781e-19, + "particle_position_x": 2653326.05816203, + "particle_position_y": 2659804.729475678, + "particle_weight": 1.7256099431746894e+26 + } +} diff --git a/Regression/Checksum/benchmarks_json/comoving_2d_psatd_hybrid.json b/Regression/Checksum/benchmarks_json/test_2d_comoving_psatd_hybrid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/comoving_2d_psatd_hybrid.json rename to Regression/Checksum/benchmarks_json/test_2d_comoving_psatd_hybrid.json diff --git a/Regression/Checksum/benchmarks_json/dive_cleaning_2d.json b/Regression/Checksum/benchmarks_json/test_2d_dive_cleaning.json similarity index 100% rename from Regression/Checksum/benchmarks_json/dive_cleaning_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_dive_cleaning.json diff --git a/Regression/Checksum/benchmarks_json/embedded_boundary_cube_2d.json b/Regression/Checksum/benchmarks_json/test_2d_embedded_boundary_cube.json similarity index 100% rename from Regression/Checksum/benchmarks_json/embedded_boundary_cube_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_embedded_boundary_cube.json diff --git a/Regression/Checksum/benchmarks_json/embedded_boundary_rotated_cube_2d.json b/Regression/Checksum/benchmarks_json/test_2d_embedded_boundary_rotated_cube.json similarity index 100% rename from Regression/Checksum/benchmarks_json/embedded_boundary_rotated_cube_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_embedded_boundary_rotated_cube.json diff --git a/Regression/Checksum/benchmarks_json/embedded_circle.json b/Regression/Checksum/benchmarks_json/test_2d_embedded_circle.json similarity index 100% rename from Regression/Checksum/benchmarks_json/embedded_circle.json rename to Regression/Checksum/benchmarks_json/test_2d_embedded_circle.json diff --git a/Regression/Checksum/benchmarks_json/EnergyConservingThermalPlasma.json b/Regression/Checksum/benchmarks_json/test_2d_energy_conserving_thermal_plasma.json similarity index 100% rename from Regression/Checksum/benchmarks_json/EnergyConservingThermalPlasma.json rename to Regression/Checksum/benchmarks_json/test_2d_energy_conserving_thermal_plasma.json diff --git a/Regression/Checksum/benchmarks_json/galilean_2d_psatd.json b/Regression/Checksum/benchmarks_json/test_2d_galilean_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_2d_psatd.json rename to Regression/Checksum/benchmarks_json/test_2d_galilean_psatd.json diff --git a/Regression/Checksum/benchmarks_json/galilean_2d_psatd_current_correction.json b/Regression/Checksum/benchmarks_json/test_2d_galilean_psatd_current_correction.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_2d_psatd_current_correction.json rename to Regression/Checksum/benchmarks_json/test_2d_galilean_psatd_current_correction.json diff --git a/Regression/Checksum/benchmarks_json/galilean_2d_psatd_current_correction_psb.json b/Regression/Checksum/benchmarks_json/test_2d_galilean_psatd_current_correction_psb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_2d_psatd_current_correction_psb.json rename to Regression/Checksum/benchmarks_json/test_2d_galilean_psatd_current_correction_psb.json diff --git a/Regression/Checksum/benchmarks_json/galilean_2d_psatd_hybrid.json b/Regression/Checksum/benchmarks_json/test_2d_galilean_psatd_hybrid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_2d_psatd_hybrid.json rename to Regression/Checksum/benchmarks_json/test_2d_galilean_psatd_hybrid.json diff --git a/Regression/Checksum/benchmarks_json/test_2d_id_cpu_read_picmi.json b/Regression/Checksum/benchmarks_json/test_2d_id_cpu_read_picmi.json new file mode 100644 index 00000000000..a59b780ba38 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_2d_id_cpu_read_picmi.json @@ -0,0 +1,14 @@ +{ + "lev=0": { + "phi": 0.001516261625969309 + }, + "electrons": { + "particle_momentum_x": 7.751654441658017e-26, + "particle_momentum_y": 6.938526597814195e-26, + "particle_momentum_z": 6.572520038890184e-26, + "particle_newPid": 500.0, + "particle_position_x": 1.4999588764815643, + "particle_position_y": 1.4999551809411737, + "particle_weight": 200.0 + } +} diff --git a/Regression/Checksum/benchmarks_json/ionization_boost.json b/Regression/Checksum/benchmarks_json/test_2d_ionization_boost.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ionization_boost.json rename to Regression/Checksum/benchmarks_json/test_2d_ionization_boost.json diff --git a/Regression/Checksum/benchmarks_json/ionization_lab.json b/Regression/Checksum/benchmarks_json/test_2d_ionization_lab.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ionization_lab.json rename to Regression/Checksum/benchmarks_json/test_2d_ionization_lab.json diff --git a/Regression/Checksum/benchmarks_json/Python_ionization.json b/Regression/Checksum/benchmarks_json/test_2d_ionization_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_ionization.json rename to Regression/Checksum/benchmarks_json/test_2d_ionization_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_fluid_2D.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_fluid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_fluid_2D.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_fluid.json diff --git a/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi.json new file mode 100644 index 00000000000..899352c45ba --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi.json @@ -0,0 +1,29 @@ +{ + "lev=0": { + "Bx": 0.0, + "By": 5.726296856755232, + "Bz": 0.0, + "Ex": 3751589134191.326, + "Ey": 0.0, + "Ez": 3751589134191.332, + "jx": 1.0100623329922576e+16, + "jy": 0.0, + "jz": 1.0100623329922578e+16 + }, + "electrons": { + "particle_momentum_x": 5.668407513430198e-20, + "particle_momentum_y": 0.0, + "particle_momentum_z": 5.668407513430198e-20, + "particle_position_x": 0.6553599999999999, + "particle_position_y": 0.65536, + "particle_weight": 3200000000000000.5 + }, + "positrons": { + "particle_momentum_x": 5.668407513430198e-20, + "particle_momentum_y": 0.0, + "particle_momentum_z": 5.668407513430198e-20, + "particle_position_x": 0.6553599999999999, + "particle_position_y": 0.65536, + "particle_weight": 3200000000000000.5 + } +} diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_MR.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_mr.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_MR.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_mr.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_MR_anisotropic.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_mr_anisotropic.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_MR_anisotropic.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_mr_anisotropic.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_MR_momentum_conserving.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_mr_momentum_conserving.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_MR_momentum_conserving.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_mr_momentum_conserving.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_MR_psatd.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_mr_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_MR_psatd.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_mr_psatd.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_nodal.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_nodal.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Python_Langmuir_2d.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_Langmuir_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_current_correction.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_current_correction.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_current_correction.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_current_correction.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_current_correction_nodal.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_current_correction_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_current_correction_nodal.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_current_correction_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_momentum_conserving.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_momentum_conserving.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_momentum_conserving.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_momentum_conserving.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_multiJ.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_multiJ.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_multiJ.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_multiJ.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_multiJ_nodal.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_multiJ_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_multiJ_nodal.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_multiJ_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_nodal.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_nodal.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_Vay_deposition.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_vay_deposition.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_Vay_deposition.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_vay_deposition.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_Vay_deposition_nodal.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_vay_deposition_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_Vay_deposition_nodal.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_vay_deposition_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_Vay_deposition_particle_shape_4.json b/Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_vay_deposition_particle_shape_4.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_2d_psatd_Vay_deposition_particle_shape_4.json rename to Regression/Checksum/benchmarks_json/test_2d_langmuir_multi_psatd_vay_deposition_particle_shape_4.json diff --git a/Regression/Checksum/benchmarks_json/Larmor.json b/Regression/Checksum/benchmarks_json/test_2d_larmor.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Larmor.json rename to Regression/Checksum/benchmarks_json/test_2d_larmor.json diff --git a/Regression/Checksum/benchmarks_json/LaserAccelerationBoost.json b/Regression/Checksum/benchmarks_json/test_2d_laser_acceleration_boosted.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserAccelerationBoost.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_acceleration_boosted.json diff --git a/Regression/Checksum/benchmarks_json/LaserAccelerationMR.json b/Regression/Checksum/benchmarks_json/test_2d_laser_acceleration_mr.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserAccelerationMR.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_acceleration_mr.json diff --git a/Regression/Checksum/benchmarks_json/Python_LaserAccelerationMR.json b/Regression/Checksum/benchmarks_json/test_2d_laser_acceleration_mr_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_LaserAccelerationMR.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_acceleration_mr_picmi.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjection_2d.json b/Regression/Checksum/benchmarks_json/test_2d_laser_injection.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjection_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_injection.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjectionFromBINARYFile.json b/Regression/Checksum/benchmarks_json/test_2d_laser_injection_from_binary_file.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjectionFromBINARYFile.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_injection_from_binary_file.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile_2d.json b/Regression/Checksum/benchmarks_json/test_2d_laser_injection_from_lasy_file.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_injection_from_lasy_file.json diff --git a/Regression/Checksum/benchmarks_json/LaserIonAcc2d.json b/Regression/Checksum/benchmarks_json/test_2d_laser_ion_acc.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserIonAcc2d.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_ion_acc.json diff --git a/Regression/Checksum/benchmarks_json/LaserIonAcc2d_no_field_diag.json b/Regression/Checksum/benchmarks_json/test_2d_laser_ion_acc_no_field_diag.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserIonAcc2d_no_field_diag.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_ion_acc_no_field_diag.json diff --git a/Regression/Checksum/benchmarks_json/Python_LaserIonAcc2d.json b/Regression/Checksum/benchmarks_json/test_2d_laser_ion_acc_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_LaserIonAcc2d.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_ion_acc_picmi.json diff --git a/Regression/Checksum/benchmarks_json/LaserOnFine.json b/Regression/Checksum/benchmarks_json/test_2d_laser_on_fine.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserOnFine.json rename to Regression/Checksum/benchmarks_json/test_2d_laser_on_fine.json diff --git a/Regression/Checksum/benchmarks_json/leveling_thinning.json b/Regression/Checksum/benchmarks_json/test_2d_leveling_thinning.json similarity index 100% rename from Regression/Checksum/benchmarks_json/leveling_thinning.json rename to Regression/Checksum/benchmarks_json/test_2d_leveling_thinning.json diff --git a/Regression/Checksum/benchmarks_json/Maxwell_Hybrid_QED_solver.json b/Regression/Checksum/benchmarks_json/test_2d_maxwell_hybrid_qed_solver.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Maxwell_Hybrid_QED_solver.json rename to Regression/Checksum/benchmarks_json/test_2d_maxwell_hybrid_qed_solver.json diff --git a/Regression/Checksum/benchmarks_json/nci_corrector.json b/Regression/Checksum/benchmarks_json/test_2d_nci_corrector.json similarity index 100% rename from Regression/Checksum/benchmarks_json/nci_corrector.json rename to Regression/Checksum/benchmarks_json/test_2d_nci_corrector.json diff --git a/Regression/Checksum/benchmarks_json/nci_correctorMR.json b/Regression/Checksum/benchmarks_json/test_2d_nci_corrector_mr.json similarity index 100% rename from Regression/Checksum/benchmarks_json/nci_correctorMR.json rename to Regression/Checksum/benchmarks_json/test_2d_nci_corrector_mr.json diff --git a/Regression/Checksum/benchmarks_json/test_2d_ohm_solver_landau_damping_picmi.json b/Regression/Checksum/benchmarks_json/test_2d_ohm_solver_landau_damping_picmi.json new file mode 100644 index 00000000000..b8328651b2e --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_2d_ohm_solver_landau_damping_picmi.json @@ -0,0 +1,21 @@ +{ + "lev=0": { + "Bx": 0.0, + "By": 0.0, + "Bz": 0.0, + "Ex": 2726044.0531522455, + "Ey": 0.0, + "Ez": 4060168.641739453, + "jx": 177543428.93227622, + "jy": 187432087.0391676, + "jz": 594259755.4796929 + }, + "ions": { + "particle_momentum_x": 9.14159469411586e-17, + "particle_momentum_y": 9.135546407258978e-17, + "particle_momentum_z": 9.137866220831626e-17, + "particle_position_x": 1197.3344862525519, + "particle_position_y": 153269.1769037183, + "particle_weight": 8.032598963696067e+16 + } +} diff --git a/Regression/Checksum/benchmarks_json/test_2d_ohm_solver_magnetic_reconnection_picmi.json b/Regression/Checksum/benchmarks_json/test_2d_ohm_solver_magnetic_reconnection_picmi.json new file mode 100644 index 00000000000..9a4e9056250 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_2d_ohm_solver_magnetic_reconnection_picmi.json @@ -0,0 +1,18 @@ +{ + "lev=0": { + "Bx": 1524.8789586064377, + "By": 639.8314135126764, + "Bz": 7.475443144751569, + "Ex": 56498215.028332025, + "Ey": 75045238.66546318, + "Ez": 309589044.22395706 + }, + "ions": { + "particle_momentum_x": 7.142955285069654e-15, + "particle_momentum_y": 7.138077993721551e-15, + "particle_momentum_z": 7.141133937530391e-15, + "particle_position_x": 11170689.202379484, + "particle_position_y": 5585328.091626547, + "particle_weight": 9.036667901693183e+18 + } +} diff --git a/Regression/Checksum/benchmarks_json/parabolic_channel_initialization_2d_single_precision.json b/Regression/Checksum/benchmarks_json/test_2d_parabolic_channel_initialization.json similarity index 100% rename from Regression/Checksum/benchmarks_json/parabolic_channel_initialization_2d_single_precision.json rename to Regression/Checksum/benchmarks_json/test_2d_parabolic_channel_initialization.json diff --git a/Regression/Checksum/benchmarks_json/particle_thermal_boundary.json b/Regression/Checksum/benchmarks_json/test_2d_particle_thermal_boundary.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particle_thermal_boundary.json rename to Regression/Checksum/benchmarks_json/test_2d_particle_thermal_boundary.json diff --git a/Regression/Checksum/benchmarks_json/particles_in_pml_2d.json b/Regression/Checksum/benchmarks_json/test_2d_particles_in_pml.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particles_in_pml_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_particles_in_pml.json diff --git a/Regression/Checksum/benchmarks_json/particles_in_pml_2d_MR.json b/Regression/Checksum/benchmarks_json/test_2d_particles_in_pml_mr.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particles_in_pml_2d_MR.json rename to Regression/Checksum/benchmarks_json/test_2d_particles_in_pml_mr.json diff --git a/Regression/Checksum/benchmarks_json/PlasmaAccelerationBoost2d.json b/Regression/Checksum/benchmarks_json/test_2d_plasma_acceleration_boosted.json similarity index 100% rename from Regression/Checksum/benchmarks_json/PlasmaAccelerationBoost2d.json rename to Regression/Checksum/benchmarks_json/test_2d_plasma_acceleration_boosted.json diff --git a/Regression/Checksum/benchmarks_json/PlasmaAccelerationMR.json b/Regression/Checksum/benchmarks_json/test_2d_plasma_acceleration_mr.json similarity index 100% rename from Regression/Checksum/benchmarks_json/PlasmaAccelerationMR.json rename to Regression/Checksum/benchmarks_json/test_2d_plasma_acceleration_mr.json diff --git a/Regression/Checksum/benchmarks_json/momentum-conserving-gather.json b/Regression/Checksum/benchmarks_json/test_2d_plasma_acceleration_mr_momentum_conserving.json similarity index 100% rename from Regression/Checksum/benchmarks_json/momentum-conserving-gather.json rename to Regression/Checksum/benchmarks_json/test_2d_plasma_acceleration_mr_momentum_conserving.json diff --git a/Regression/Checksum/benchmarks_json/PlasmaMirror.json b/Regression/Checksum/benchmarks_json/test_2d_plasma_mirror.json similarity index 100% rename from Regression/Checksum/benchmarks_json/PlasmaMirror.json rename to Regression/Checksum/benchmarks_json/test_2d_plasma_mirror.json diff --git a/Regression/Checksum/benchmarks_json/pml_x_ckc.json b/Regression/Checksum/benchmarks_json/test_2d_pml_x_ckc.json similarity index 100% rename from Regression/Checksum/benchmarks_json/pml_x_ckc.json rename to Regression/Checksum/benchmarks_json/test_2d_pml_x_ckc.json diff --git a/Regression/Checksum/benchmarks_json/pml_x_galilean.json b/Regression/Checksum/benchmarks_json/test_2d_pml_x_galilean.json similarity index 100% rename from Regression/Checksum/benchmarks_json/pml_x_galilean.json rename to Regression/Checksum/benchmarks_json/test_2d_pml_x_galilean.json diff --git a/Regression/Checksum/benchmarks_json/pml_x_psatd.json b/Regression/Checksum/benchmarks_json/test_2d_pml_x_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/pml_x_psatd.json rename to Regression/Checksum/benchmarks_json/test_2d_pml_x_psatd.json diff --git a/Regression/Checksum/benchmarks_json/pml_x_yee.json b/Regression/Checksum/benchmarks_json/test_2d_pml_x_yee.json similarity index 100% rename from Regression/Checksum/benchmarks_json/pml_x_yee.json rename to Regression/Checksum/benchmarks_json/test_2d_pml_x_yee.json diff --git a/Regression/Checksum/benchmarks_json/pml_x_yee_eb.json b/Regression/Checksum/benchmarks_json/test_2d_pml_x_yee_eb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/pml_x_yee_eb.json rename to Regression/Checksum/benchmarks_json/test_2d_pml_x_yee_eb.json diff --git a/Regression/Checksum/benchmarks_json/Python_prev_positions.json b/Regression/Checksum/benchmarks_json/test_2d_prev_positions_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_prev_positions.json rename to Regression/Checksum/benchmarks_json/test_2d_prev_positions_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Proton_Boron_Fusion_2D.json b/Regression/Checksum/benchmarks_json/test_2d_proton_boron_fusion.json similarity index 65% rename from Regression/Checksum/benchmarks_json/Proton_Boron_Fusion_2D.json rename to Regression/Checksum/benchmarks_json/test_2d_proton_boron_fusion.json index cdee4b078b0..2de146e45ce 100644 --- a/Regression/Checksum/benchmarks_json/Proton_Boron_Fusion_2D.json +++ b/Regression/Checksum/benchmarks_json/test_2d_proton_boron_fusion.json @@ -2,22 +2,6 @@ "lev=0": { "rho": 0.0 }, - "alpha2": { - "particle_momentum_x": 4.057984510682467e-15, - "particle_momentum_y": 4.104188139725855e-15, - "particle_momentum_z": 4.17858000090827e-15, - "particle_position_x": 408793.7905852193, - "particle_position_y": 861780.8020495367, - "particle_weight": 5.078061191951185e+18 - }, - "alpha3": { - "particle_momentum_x": 5.017656304003558e-16, - "particle_momentum_y": 4.935595075276182e-16, - "particle_momentum_z": 4.867133212376827e-16, - "particle_position_x": 52678.192400911765, - "particle_position_y": 105483.59950020742, - "particle_weight": 1.5413633830148085e+27 - }, "boron1": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, @@ -26,6 +10,22 @@ "particle_position_y": 81921136.14476715, "particle_weight": 128.00000000000261 }, + "boron3": { + "particle_momentum_x": 9.277692671587846e-15, + "particle_momentum_y": 9.268409636965691e-15, + "particle_momentum_z": 9.279446607709548e-15, + "particle_position_x": 4096178.1664224654, + "particle_position_y": 8192499.7060386725, + "particle_weight": 6.399499907503547e+30 + }, + "alpha5": { + "particle_momentum_x": 2.3859593638404282e-14, + "particle_momentum_y": 2.38840514351394e-14, + "particle_momentum_z": 2.3991308560597987e-14, + "particle_position_x": 2457556.8571638414, + "particle_position_y": 4914659.635379324, + "particle_weight": 3.839999999999998e-19 + }, "boron2": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, @@ -34,53 +34,37 @@ "particle_position_y": 819270.9858143466, "particle_weight": 1.2799999998307316e+28 }, - "boron5": { - "particle_momentum_x": 0.0, - "particle_momentum_y": 0.0, - "particle_momentum_z": 0.0, - "particle_position_x": 409547.3312927569, - "particle_position_y": 819118.5558814355, - "particle_weight": 127.99999999999999 - }, "alpha1": { - "particle_momentum_x": 4.691909092431811e-15, - "particle_momentum_y": 4.6836958163275755e-15, - "particle_momentum_z": 4.657203546376977e-15, + "particle_momentum_x": 4.758865177822356e-15, + "particle_momentum_y": 4.7625215232714745e-15, + "particle_momentum_z": 4.734412976565431e-15, "particle_position_x": 463465.27131109464, "particle_position_y": 978207.6061359186, "particle_weight": 4.977661460251435e-28 }, - "proton2": { - "particle_momentum_x": 0.0, - "particle_momentum_y": 0.0, - "particle_momentum_z": 2.3723248133690294e-14, - "particle_position_x": 4095630.6981353555, - "particle_position_y": 8192073.551798361, - "particle_weight": 1.2885512788807322e+28 - }, - "proton1": { + "proton5": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, - "particle_momentum_z": 2.524872467113344e-13, - "particle_position_x": 40960140.72983792, - "particle_position_y": 81919772.69310114, - "particle_weight": 128.00000000000261 + "particle_momentum_z": 1.7586062624930794e-15, + "particle_position_x": 409638.2877618571, + "particle_position_y": 819101.3225783394, + "particle_weight": 1.2800000000000004e+37 }, - "alpha5": { - "particle_momentum_x": 2.3343485859070736e-14, - "particle_momentum_y": 2.3451128753701046e-14, - "particle_momentum_z": 2.3579462789062662e-14, - "particle_position_x": 2457556.8571638423, - "particle_position_y": 4914659.635379322, - "particle_weight": 3.839999999999998e-19 + "proton3": { + "particle_momentum_x": 1.6842001035542442e-15, + "particle_momentum_y": 1.6822700479972656e-15, + "particle_momentum_z": 1.6797740090740159e-15, + "particle_position_x": 2456930.3827292607, + "particle_position_y": 4913715.277730561, + "particle_weight": 1.2794999075035503e+30 }, - "boron3": { - "particle_momentum_x": 9.277692671587846e-15, - "particle_momentum_y": 9.268409636965691e-15, - "particle_momentum_z": 9.279446607709548e-15, - "particle_position_x": 4096178.1664224654, - "particle_position_y": 8192499.7060386725, - "particle_weight": 6.399486212205656e+30 + "alpha2": { + "particle_momentum_x": 4.140109871048478e-15, + "particle_momentum_y": 4.159837925039718e-15, + "particle_momentum_z": 4.251680389225861e-15, + "particle_position_x": 408793.7905852193, + "particle_position_y": 861780.8020495367, + "particle_weight": 5.078061191951185e+18 }, "proton4": { "particle_momentum_x": 0.0, @@ -90,28 +74,44 @@ "particle_position_y": 819198.7077771134, "particle_weight": 1.2800000000000004e+37 }, - "proton3": { - "particle_momentum_x": 1.6847290893972251e-15, - "particle_momentum_y": 1.6827074502304075e-15, - "particle_momentum_z": 1.6802489646490975e-15, - "particle_position_x": 2457270.6999197667, - "particle_position_y": 4914315.665267942, - "particle_weight": 1.279486212205663e+30 + "proton1": { + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 2.524872467113344e-13, + "particle_position_x": 40960140.72983792, + "particle_position_y": 81919772.69310114, + "particle_weight": 128.00000000000261 + }, + "boron5": { + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 0.0, + "particle_position_x": 409547.3312927569, + "particle_position_y": 819118.5558814355, + "particle_weight": 127.99999999999999 }, "alpha4": { - "particle_momentum_x": 2.338084461204216e-14, - "particle_momentum_y": 2.3436156778849828e-14, - "particle_momentum_z": 2.35535708386288e-14, - "particle_position_x": 2457367.4582781536, - "particle_position_y": 4915112.044373056, + "particle_momentum_x": 2.3844872070315362e-14, + "particle_momentum_y": 2.3880317964250153e-14, + "particle_momentum_z": 2.4010930856446718e-14, + "particle_position_x": 2457367.4582781526, + "particle_position_y": 4915112.044373058, "particle_weight": 384.0000000000002 }, - "proton5": { + "proton2": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, - "particle_momentum_z": 1.7586062624930794e-15, - "particle_position_x": 409638.2877618571, - "particle_position_y": 819101.3225783394, - "particle_weight": 1.2800000000000004e+37 + "particle_momentum_z": 2.3723248133690294e-14, + "particle_position_x": 4095630.6981353555, + "particle_position_y": 8192073.551798361, + "particle_weight": 1.2885512788807322e+28 + }, + "alpha3": { + "particle_momentum_x": 4.758972533179803e-16, + "particle_momentum_y": 4.744688612812961e-16, + "particle_momentum_z": 4.703298089277572e-16, + "particle_position_x": 49191.438625552386, + "particle_position_y": 98893.17267714937, + "particle_weight": 1.500277489351144e+27 } } diff --git a/Regression/Checksum/benchmarks_json/Python_wrappers.json b/Regression/Checksum/benchmarks_json/test_2d_python_wrappers_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_wrappers.json rename to Regression/Checksum/benchmarks_json/test_2d_python_wrappers_picmi.json diff --git a/Regression/Checksum/benchmarks_json/qed_breit_wheeler_2d.json b/Regression/Checksum/benchmarks_json/test_2d_qed_breit_wheeler.json similarity index 100% rename from Regression/Checksum/benchmarks_json/qed_breit_wheeler_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_qed_breit_wheeler.json diff --git a/Regression/Checksum/benchmarks_json/qed_quantum_sync_2d.json b/Regression/Checksum/benchmarks_json/test_2d_qed_quantum_sync.json similarity index 100% rename from Regression/Checksum/benchmarks_json/qed_quantum_sync_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_qed_quantum_sync.json diff --git a/Regression/Checksum/benchmarks_json/RefinedInjection.json b/Regression/Checksum/benchmarks_json/test_2d_refined_injection.json similarity index 100% rename from Regression/Checksum/benchmarks_json/RefinedInjection.json rename to Regression/Checksum/benchmarks_json/test_2d_refined_injection.json diff --git a/Regression/Checksum/benchmarks_json/RepellingParticles.json b/Regression/Checksum/benchmarks_json/test_2d_repelling_particles.json similarity index 100% rename from Regression/Checksum/benchmarks_json/RepellingParticles.json rename to Regression/Checksum/benchmarks_json/test_2d_repelling_particles.json diff --git a/Regression/Checksum/benchmarks_json/RigidInjection_BTD.json b/Regression/Checksum/benchmarks_json/test_2d_rigid_injection_btd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/RigidInjection_BTD.json rename to Regression/Checksum/benchmarks_json/test_2d_rigid_injection_btd.json diff --git a/Regression/Checksum/benchmarks_json/RigidInjection_lab.json b/Regression/Checksum/benchmarks_json/test_2d_rigid_injection_lab.json similarity index 100% rename from Regression/Checksum/benchmarks_json/RigidInjection_lab.json rename to Regression/Checksum/benchmarks_json/test_2d_rigid_injection_lab.json diff --git a/Regression/Checksum/benchmarks_json/silver_mueller_2d_x.json b/Regression/Checksum/benchmarks_json/test_2d_silver_mueller_x.json similarity index 100% rename from Regression/Checksum/benchmarks_json/silver_mueller_2d_x.json rename to Regression/Checksum/benchmarks_json/test_2d_silver_mueller_x.json diff --git a/Regression/Checksum/benchmarks_json/silver_mueller_2d_z.json b/Regression/Checksum/benchmarks_json/test_2d_silver_mueller_z.json similarity index 100% rename from Regression/Checksum/benchmarks_json/silver_mueller_2d_z.json rename to Regression/Checksum/benchmarks_json/test_2d_silver_mueller_z.json diff --git a/Regression/Checksum/benchmarks_json/space_charge_initialization_2d.json b/Regression/Checksum/benchmarks_json/test_2d_space_charge_initialization.json similarity index 100% rename from Regression/Checksum/benchmarks_json/space_charge_initialization_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_space_charge_initialization.json diff --git a/Regression/Checksum/benchmarks_json/subcyclingMR.json b/Regression/Checksum/benchmarks_json/test_2d_subcycling_mr.json similarity index 100% rename from Regression/Checksum/benchmarks_json/subcyclingMR.json rename to Regression/Checksum/benchmarks_json/test_2d_subcycling_mr.json diff --git a/Regression/Checksum/benchmarks_json/ThetaImplicitJFNK_VandB_2d.json b/Regression/Checksum/benchmarks_json/test_2d_theta_implicit_jfnk_vandb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ThetaImplicitJFNK_VandB_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_theta_implicit_jfnk_vandb.json diff --git a/Regression/Checksum/benchmarks_json/test_2d_theta_implicit_jfnk_vandb_picmi.json b/Regression/Checksum/benchmarks_json/test_2d_theta_implicit_jfnk_vandb_picmi.json new file mode 100644 index 00000000000..d97eb04883f --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_2d_theta_implicit_jfnk_vandb_picmi.json @@ -0,0 +1,31 @@ +{ + "lev=0": { + "Bx": 72730.70321925254, + "By": 89276.6097395453, + "Bz": 66911.00019634314, + "Ex": 92036838733000.64, + "Ey": 15583500940725.84, + "Ez": 89163420502164.97, + "divE": 8.998871921763322e+22, + "jx": 2.7748639888523993e+19, + "jy": 2.9501400595579277e+19, + "jz": 2.6976140199337787e+19, + "rho": 796777020986.2787 + }, + "protons": { + "particle_momentum_x": 2.0873315539608036e-17, + "particle_momentum_y": 2.0858882907322405e-17, + "particle_momentum_z": 2.0877345477243595e-17, + "particle_position_x": 0.004251275869323399, + "particle_position_y": 0.0042512738905209615, + "particle_weight": 2823958719279159.5 + }, + "electrons": { + "particle_momentum_x": 4.882673707817137e-19, + "particle_momentum_y": 4.879672470952739e-19, + "particle_momentum_z": 4.872329687213274e-19, + "particle_position_x": 0.004251641684258687, + "particle_position_y": 0.004251751978637919, + "particle_weight": 2823958719279159.5 + } +} diff --git a/Regression/Checksum/benchmarks_json/Uniform_2d.json b/Regression/Checksum/benchmarks_json/test_2d_uniform_plasma.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Uniform_2d.json rename to Regression/Checksum/benchmarks_json/test_2d_uniform_plasma.json diff --git a/Regression/Checksum/benchmarks_json/VayDeposition2D.json b/Regression/Checksum/benchmarks_json/test_2d_vay_deposition.json similarity index 100% rename from Regression/Checksum/benchmarks_json/VayDeposition2D.json rename to Regression/Checksum/benchmarks_json/test_2d_vay_deposition.json diff --git a/Regression/Checksum/benchmarks_json/restart.json b/Regression/Checksum/benchmarks_json/test_3d_acceleration.json similarity index 100% rename from Regression/Checksum/benchmarks_json/restart.json rename to Regression/Checksum/benchmarks_json/test_3d_acceleration.json diff --git a/Regression/Checksum/benchmarks_json/restart_psatd.json b/Regression/Checksum/benchmarks_json/test_3d_acceleration_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/restart_psatd.json rename to Regression/Checksum/benchmarks_json/test_3d_acceleration_psatd.json diff --git a/Regression/Checksum/benchmarks_json/restart_psatd_time_avg.json b/Regression/Checksum/benchmarks_json/test_3d_acceleration_psatd_time_avg.json similarity index 100% rename from Regression/Checksum/benchmarks_json/restart_psatd_time_avg.json rename to Regression/Checksum/benchmarks_json/test_3d_acceleration_psatd_time_avg.json diff --git a/Regression/Checksum/benchmarks_json/averaged_galilean_3d_psatd.json b/Regression/Checksum/benchmarks_json/test_3d_averaged_galilean_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/averaged_galilean_3d_psatd.json rename to Regression/Checksum/benchmarks_json/test_3d_averaged_galilean_psatd.json diff --git a/Regression/Checksum/benchmarks_json/averaged_galilean_3d_psatd_hybrid.json b/Regression/Checksum/benchmarks_json/test_3d_averaged_galilean_psatd_hybrid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/averaged_galilean_3d_psatd_hybrid.json rename to Regression/Checksum/benchmarks_json/test_3d_averaged_galilean_psatd_hybrid.json diff --git a/Regression/Checksum/benchmarks_json/test_3d_beam_beam_collision.json b/Regression/Checksum/benchmarks_json/test_3d_beam_beam_collision.json new file mode 100644 index 00000000000..ad478e96e2f --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_3d_beam_beam_collision.json @@ -0,0 +1,96 @@ +{ + "lev=0": { + "Bx": 461189750202.8409, + "By": 461177227889.41614, + "Bz": 20074725.954957746, + "Ex": 1.3827102525768512e+20, + "Ey": 1.3827414851469086e+20, + "Ez": 3.5091001092648376e+16, + "rho_beam1": 3.829927705533972e+16, + "rho_beam2": 3.830015035966193e+16, + "rho_ele1": 162411820580232.94, + "rho_ele2": 150511095307150.62, + "rho_pos1": 159308102449286.12, + "rho_pos2": 156118194376152.7 + }, + "beam1": { + "particle_opticalDepthQSR": 52563.18675345914, + "particle_position_x": 0.0007501135479816878, + "particle_position_y": 0.0007501095180907413, + "particle_position_z": 0.002483074586668512, + "particle_momentum_x": 3.0935661449588394e-15, + "particle_momentum_y": 3.070048977445414e-15, + "particle_momentum_z": 3.4017266957145416e-12, + "particle_weight": 636083515.3729652 + }, + "beam2": { + "particle_opticalDepthQSR": 52275.42552501091, + "particle_position_x": 0.0007500428425956199, + "particle_position_y": 0.0007500867178448842, + "particle_position_z": 0.0024830812114940977, + "particle_momentum_x": 3.1124995623090863e-15, + "particle_momentum_y": 3.094827769550167e-15, + "particle_momentum_z": 3.4015150389915676e-12, + "particle_weight": 636114264.930704 + }, + "ele1": { + "particle_opticalDepthQSR": 156.022199846285, + "particle_position_x": 2.4401923319868757e-06, + "particle_position_y": 2.399150249907213e-06, + "particle_position_z": 8.791577071017722e-06, + "particle_momentum_x": 2.7299291171683895e-18, + "particle_momentum_y": 2.6551510668418435e-18, + "particle_momentum_z": 1.33445643731407e-15, + "particle_weight": 2656838.9769653436 + }, + "ele2": { + "particle_opticalDepthQSR": 163.79686010701988, + "particle_position_x": 2.724737203764692e-06, + "particle_position_y": 2.9829403746737846e-06, + "particle_position_z": 9.127382649103148e-06, + "particle_momentum_x": 2.1813342297510976e-18, + "particle_momentum_y": 2.7643067192718357e-18, + "particle_momentum_z": 1.259574872512064e-15, + "particle_weight": 2517356.358594387 + }, + "pho1": { + "particle_opticalDepthBW": 5007.597539698783, + "particle_position_x": 7.214053121897416e-05, + "particle_position_y": 7.223804186317301e-05, + "particle_position_z": 0.00024115699590772453, + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 0.0, + "particle_weight": 62860453.544321 + }, + "pho2": { + "particle_opticalDepthBW": 5113.753887045111, + "particle_position_x": 7.271625175781002e-05, + "particle_position_y": 7.311023374122331e-05, + "particle_position_z": 0.00024123464128276151, + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 0.0, + "particle_weight": 59821371.52413007 + }, + "pos1": { + "particle_opticalDepthQSR": 176.87865344045926, + "particle_position_x": 2.597218595285766e-06, + "particle_position_y": 2.5071002403671178e-06, + "particle_position_z": 8.190923176799435e-06, + "particle_momentum_x": 2.409544640420923e-18, + "particle_momentum_y": 2.5096320511498773e-18, + "particle_momentum_z": 1.3349884612525734e-15, + "particle_weight": 2604339.6419650833 + }, + "pos2": { + "particle_opticalDepthQSR": 229.50925371797547, + "particle_position_x": 2.6205324097963396e-06, + "particle_position_y": 2.8134541282576216e-06, + "particle_position_z": 9.865542956073817e-06, + "particle_momentum_x": 2.536744632018102e-18, + "particle_momentum_y": 3.035517414633681e-18, + "particle_momentum_z": 1.3203905663185877e-15, + "particle_weight": 2570091.732557297 + } +} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/collider_diagnostics.json b/Regression/Checksum/benchmarks_json/test_3d_collider_diagnostics.json similarity index 100% rename from Regression/Checksum/benchmarks_json/collider_diagnostics.json rename to Regression/Checksum/benchmarks_json/test_3d_collider_diagnostics.json diff --git a/Regression/Checksum/benchmarks_json/test_3d_collision_iso.json b/Regression/Checksum/benchmarks_json/test_3d_collision_iso.json new file mode 100644 index 00000000000..c14fcbe99d8 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_3d_collision_iso.json @@ -0,0 +1,22 @@ +{ + "lev=0": { + "Bx": 0.0, + "By": 0.0, + "Bz": 0.0, + "Ex": 0.0, + "Ey": 0.0, + "Ez": 0.0, + "jx": 0.0, + "jy": 0.0, + "jz": 0.0 + }, + "electron": { + "particle_momentum_x": 3.578935809964031e-19, + "particle_momentum_y": 3.5778028343192025e-19, + "particle_momentum_z": 3.579884355240226e-19, + "particle_position_x": 1.0241442531780067, + "particle_position_y": 1.0238915904698023, + "particle_position_z": 1.024005350488445, + "particle_weight": 714240000000.0 + } +} diff --git a/Regression/Checksum/benchmarks_json/test_3d_collision_xyz.json b/Regression/Checksum/benchmarks_json/test_3d_collision_xyz.json new file mode 100644 index 00000000000..a3769ba7fa0 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_3d_collision_xyz.json @@ -0,0 +1,30 @@ +{ + "lev=0": { + "Bx": 0.0, + "By": 0.0, + "Bz": 0.0, + "Ex": 0.0, + "Ey": 0.0, + "Ez": 0.0, + "T_electron": 351188.7347045234, + "T_ion": 350097.5453711827 + }, + "electron": { + "particle_momentum_x": 8.348736016166693e-19, + "particle_momentum_y": 8.175754844970833e-19, + "particle_momentum_z": 8.209507928471627e-19, + "particle_position_x": 21258578.13072786, + "particle_position_y": 21266758.00828195, + "particle_position_z": 21207386.447255243, + "particle_weight": 7.168263344048695e+28 + }, + "ion": { + "particle_momentum_x": 2.008818164997072e-18, + "particle_momentum_y": 1.829384185025146e-18, + "particle_momentum_z": 1.8289477333243715e-18, + "particle_position_x": 21233610.538310427, + "particle_position_y": 21280892.516510233, + "particle_position_z": 21213150.945697505, + "particle_weight": 7.168263344048695e+28 + } +} diff --git a/Regression/Checksum/benchmarks_json/Deuterium_Deuterium_Fusion_3D.json b/Regression/Checksum/benchmarks_json/test_3d_deuterium_deuterium_fusion.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Deuterium_Deuterium_Fusion_3D.json rename to Regression/Checksum/benchmarks_json/test_3d_deuterium_deuterium_fusion.json diff --git a/Regression/Checksum/benchmarks_json/Deuterium_Deuterium_Fusion_3D_intraspecies.json b/Regression/Checksum/benchmarks_json/test_3d_deuterium_deuterium_fusion_intraspecies.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Deuterium_Deuterium_Fusion_3D_intraspecies.json rename to Regression/Checksum/benchmarks_json/test_3d_deuterium_deuterium_fusion_intraspecies.json diff --git a/Regression/Checksum/benchmarks_json/Deuterium_Tritium_Fusion_3D.json b/Regression/Checksum/benchmarks_json/test_3d_deuterium_tritium_fusion.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Deuterium_Tritium_Fusion_3D.json rename to Regression/Checksum/benchmarks_json/test_3d_deuterium_tritium_fusion.json diff --git a/Regression/Checksum/benchmarks_json/test_3d_diff_lumi_diag.json b/Regression/Checksum/benchmarks_json/test_3d_diff_lumi_diag.json new file mode 100644 index 00000000000..5764278a0c0 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_3d_diff_lumi_diag.json @@ -0,0 +1,24 @@ +{ + "lev=0": { + "rho_beam1": 656097730.398061, + "rho_beam2": 656073566.2600528 + }, + "beam2": { + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 1.3357156607472946e-11, + "particle_position_x": 0.07980004798883583, + "particle_position_y": 0.0015964156825818534, + "particle_position_z": 240184.81987149065, + "particle_weight": 11997240000.0 + }, + "beam1": { + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 1.3357730733347833e-11, + "particle_position_x": 0.0796200211671279, + "particle_position_y": 0.001592794429510446, + "particle_position_z": 239913.37896451252, + "particle_weight": 11997780000.0 + } +} diff --git a/Regression/Checksum/benchmarks_json/divb_cleaning_3d.json b/Regression/Checksum/benchmarks_json/test_3d_divb_cleaning.json similarity index 100% rename from Regression/Checksum/benchmarks_json/divb_cleaning_3d.json rename to Regression/Checksum/benchmarks_json/test_3d_divb_cleaning.json diff --git a/Regression/Checksum/benchmarks_json/dive_cleaning_3d.json b/Regression/Checksum/benchmarks_json/test_3d_dive_cleaning.json similarity index 100% rename from Regression/Checksum/benchmarks_json/dive_cleaning_3d.json rename to Regression/Checksum/benchmarks_json/test_3d_dive_cleaning.json diff --git a/Regression/Checksum/benchmarks_json/Python_restart_eb.json b/Regression/Checksum/benchmarks_json/test_3d_eb_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_restart_eb.json rename to Regression/Checksum/benchmarks_json/test_3d_eb_picmi.json diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphere.json b/Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ElectrostaticSphere.json rename to Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere.json diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphereEB.json b/Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_eb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ElectrostaticSphereEB.json rename to Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_eb.json diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphereEB_mixedBCs.json b/Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_eb_mixed_bc.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ElectrostaticSphereEB_mixedBCs.json rename to Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_eb_mixed_bc.json diff --git a/Regression/Checksum/benchmarks_json/Python_ElectrostaticSphereEB.json b/Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_eb_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_ElectrostaticSphereEB.json rename to Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_eb_picmi.json diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphereLabFrame.json b/Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_lab_frame.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ElectrostaticSphereLabFrame.json rename to Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_lab_frame.json diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphereLabFrame_MR_emass_10.json b/Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_lab_frame_mr_emass_10.json similarity index 59% rename from Regression/Checksum/benchmarks_json/ElectrostaticSphereLabFrame_MR_emass_10.json rename to Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_lab_frame_mr_emass_10.json index 024127a1bd2..21d5208c59a 100644 --- a/Regression/Checksum/benchmarks_json/ElectrostaticSphereLabFrame_MR_emass_10.json +++ b/Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_lab_frame_mr_emass_10.json @@ -6,15 +6,15 @@ "rho": 0.0 }, "lev=1": { - "Ex": 14.281015560380963, - "Ey": 14.281015560380965, - "Ez": 14.281015560380965, + "Ex": 7.170105936287823, + "Ey": 7.17010593628782, + "Ez": 7.170105936287821, "rho": 2.6092568008333786e-10 }, "electron": { - "particle_momentum_x": 1.80842228672388e-24, - "particle_momentum_y": 1.8084222867238806e-24, - "particle_momentum_z": 1.7598771525647628e-24, + "particle_momentum_x": 9.257577597262615e-25, + "particle_momentum_y": 9.257577597262618e-25, + "particle_momentum_z": 9.257577597262624e-25, "particle_position_x": 327.46875, "particle_position_y": 327.46875, "particle_position_z": 327.46875, diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphereRelNodal.json b/Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_rel_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ElectrostaticSphereRelNodal.json rename to Regression/Checksum/benchmarks_json/test_3d_electrostatic_sphere_rel_nodal.json diff --git a/Regression/Checksum/benchmarks_json/embedded_boundary_cube.json b/Regression/Checksum/benchmarks_json/test_3d_embedded_boundary_cube.json similarity index 53% rename from Regression/Checksum/benchmarks_json/embedded_boundary_cube.json rename to Regression/Checksum/benchmarks_json/test_3d_embedded_boundary_cube.json index d0edafb9f0e..58ee8806540 100644 --- a/Regression/Checksum/benchmarks_json/embedded_boundary_cube.json +++ b/Regression/Checksum/benchmarks_json/test_3d_embedded_boundary_cube.json @@ -1,10 +1,10 @@ { "lev=0": { - "Bx": 3.769898030127477e-18, + "Bx": 4.060477854092961e-18, "By": 0.006628374119786834, "Bz": 0.006628374119786834, "Ex": 5102618.4711524295, - "Ey": 6.323755130400527e-05, - "Ez": 6.323755130400527e-05 + "Ey": 6.323754160591239e-05, + "Ez": 6.323754160591239e-05 } -} \ No newline at end of file +} diff --git a/Regression/Checksum/benchmarks_json/test_3d_embedded_boundary_cube_macroscopic.json b/Regression/Checksum/benchmarks_json/test_3d_embedded_boundary_cube_macroscopic.json new file mode 100644 index 00000000000..8cc6af7cb93 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_3d_embedded_boundary_cube_macroscopic.json @@ -0,0 +1,10 @@ +{ + "lev=0": { + "Bx": 4.20930075273562e-18, + "By": 0.005101824310293573, + "Bz": 0.005101824310293573, + "Ex": 4414725.184731115, + "Ey": 6.32375413967707e-05, + "Ez": 6.32375413967707e-05 + } +} diff --git a/Regression/Checksum/benchmarks_json/embedded_boundary_rotated_cube.json b/Regression/Checksum/benchmarks_json/test_3d_embedded_boundary_rotated_cube.json similarity index 100% rename from Regression/Checksum/benchmarks_json/embedded_boundary_rotated_cube.json rename to Regression/Checksum/benchmarks_json/test_3d_embedded_boundary_rotated_cube.json diff --git a/Regression/Checksum/benchmarks_json/FluxInjection3D.json b/Regression/Checksum/benchmarks_json/test_3d_flux_injection.json similarity index 100% rename from Regression/Checksum/benchmarks_json/FluxInjection3D.json rename to Regression/Checksum/benchmarks_json/test_3d_flux_injection.json diff --git a/Regression/Checksum/benchmarks_json/focusing_gaussian_beam.json b/Regression/Checksum/benchmarks_json/test_3d_focusing_gaussian_beam.json similarity index 100% rename from Regression/Checksum/benchmarks_json/focusing_gaussian_beam.json rename to Regression/Checksum/benchmarks_json/test_3d_focusing_gaussian_beam.json diff --git a/Regression/Checksum/benchmarks_json/galilean_3d_psatd.json b/Regression/Checksum/benchmarks_json/test_3d_galilean_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_3d_psatd.json rename to Regression/Checksum/benchmarks_json/test_3d_galilean_psatd.json diff --git a/Regression/Checksum/benchmarks_json/galilean_3d_psatd_current_correction.json b/Regression/Checksum/benchmarks_json/test_3d_galilean_psatd_current_correction.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_3d_psatd_current_correction.json rename to Regression/Checksum/benchmarks_json/test_3d_galilean_psatd_current_correction.json diff --git a/Regression/Checksum/benchmarks_json/galilean_3d_psatd_current_correction_psb.json b/Regression/Checksum/benchmarks_json/test_3d_galilean_psatd_current_correction_psb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_3d_psatd_current_correction_psb.json rename to Regression/Checksum/benchmarks_json/test_3d_galilean_psatd_current_correction_psb.json diff --git a/Regression/Checksum/benchmarks_json/Python_gaussian_beam.json b/Regression/Checksum/benchmarks_json/test_3d_gaussian_beam_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_gaussian_beam.json rename to Regression/Checksum/benchmarks_json/test_3d_gaussian_beam_picmi.json diff --git a/Regression/Checksum/benchmarks_json/hard_edged_quadrupoles.json b/Regression/Checksum/benchmarks_json/test_3d_hard_edged_quadrupoles.json similarity index 100% rename from Regression/Checksum/benchmarks_json/hard_edged_quadrupoles.json rename to Regression/Checksum/benchmarks_json/test_3d_hard_edged_quadrupoles.json diff --git a/Regression/Checksum/benchmarks_json/hard_edged_quadrupoles_boosted.json b/Regression/Checksum/benchmarks_json/test_3d_hard_edged_quadrupoles_boosted.json similarity index 100% rename from Regression/Checksum/benchmarks_json/hard_edged_quadrupoles_boosted.json rename to Regression/Checksum/benchmarks_json/test_3d_hard_edged_quadrupoles_boosted.json diff --git a/Regression/Checksum/benchmarks_json/hard_edged_quadrupoles_moving.json b/Regression/Checksum/benchmarks_json/test_3d_hard_edged_quadrupoles_moving.json similarity index 100% rename from Regression/Checksum/benchmarks_json/hard_edged_quadrupoles_moving.json rename to Regression/Checksum/benchmarks_json/test_3d_hard_edged_quadrupoles_moving.json diff --git a/Regression/Checksum/benchmarks_json/initial_distribution.json b/Regression/Checksum/benchmarks_json/test_3d_initial_distribution.json similarity index 100% rename from Regression/Checksum/benchmarks_json/initial_distribution.json rename to Regression/Checksum/benchmarks_json/test_3d_initial_distribution.json diff --git a/Regression/Checksum/benchmarks_json/ion_stopping.json b/Regression/Checksum/benchmarks_json/test_3d_ion_stopping.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ion_stopping.json rename to Regression/Checksum/benchmarks_json/test_3d_ion_stopping.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_fluid_multi.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_fluid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_fluid_multi.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_fluid.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_nodal.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_nodal.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Python_Langmuir.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_Langmuir.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_current_correction.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_current_correction.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_current_correction.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_current_correction.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_current_correction_nodal.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_current_correction_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_current_correction_nodal.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_current_correction_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_div_cleaning.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_div_cleaning.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_div_cleaning.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_div_cleaning.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_momentum_conserving.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_momentum_conserving.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_momentum_conserving.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_momentum_conserving.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_multiJ.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_multiJ.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_multiJ.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_multiJ.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_multiJ_nodal.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_multiJ_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_multiJ_nodal.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_multiJ_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_nodal.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_nodal.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_single_precision.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_single_precision.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_single_precision.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_single_precision.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_Vay_deposition.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_vay_deposition.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_Vay_deposition.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_vay_deposition.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_Vay_deposition_nodal.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_vay_deposition_nodal.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_psatd_Vay_deposition_nodal.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_psatd_vay_deposition_nodal.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_single_precision.json b/Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_single_precision.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_single_precision.json rename to Regression/Checksum/benchmarks_json/test_3d_langmuir_multi_single_precision.json diff --git a/Regression/Checksum/benchmarks_json/LaserAcceleration.json b/Regression/Checksum/benchmarks_json/test_3d_laser_acceleration.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserAcceleration.json rename to Regression/Checksum/benchmarks_json/test_3d_laser_acceleration.json diff --git a/Regression/Checksum/benchmarks_json/LaserAcceleration_BTD.json b/Regression/Checksum/benchmarks_json/test_3d_laser_acceleration_btd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserAcceleration_BTD.json rename to Regression/Checksum/benchmarks_json/test_3d_laser_acceleration_btd.json diff --git a/Regression/Checksum/benchmarks_json/Python_LaserAcceleration.json b/Regression/Checksum/benchmarks_json/test_3d_laser_acceleration_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_LaserAcceleration.json rename to Regression/Checksum/benchmarks_json/test_3d_laser_acceleration_picmi.json diff --git a/Regression/Checksum/benchmarks_json/LaserAcceleration_single_precision_comms.json b/Regression/Checksum/benchmarks_json/test_3d_laser_acceleration_single_precision_comms.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserAcceleration_single_precision_comms.json rename to Regression/Checksum/benchmarks_json/test_3d_laser_acceleration_single_precision_comms.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjection.json b/Regression/Checksum/benchmarks_json/test_3d_laser_injection.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjection.json rename to Regression/Checksum/benchmarks_json/test_3d_laser_injection.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile.json b/Regression/Checksum/benchmarks_json/test_3d_laser_injection_from_lasy_file.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile.json rename to Regression/Checksum/benchmarks_json/test_3d_laser_injection_from_lasy_file.json diff --git a/Regression/Checksum/benchmarks_json/Python_LoadExternalGridField3D.json b/Regression/Checksum/benchmarks_json/test_3d_load_external_field_grid_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_LoadExternalGridField3D.json rename to Regression/Checksum/benchmarks_json/test_3d_load_external_field_grid_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Python_LoadExternalParticleField3D.json b/Regression/Checksum/benchmarks_json/test_3d_load_external_field_particle_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_LoadExternalParticleField3D.json rename to Regression/Checksum/benchmarks_json/test_3d_load_external_field_particle_picmi.json diff --git a/Regression/Checksum/benchmarks_json/magnetostatic_eb_3d.json b/Regression/Checksum/benchmarks_json/test_3d_magnetostatic_eb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/magnetostatic_eb_3d.json rename to Regression/Checksum/benchmarks_json/test_3d_magnetostatic_eb.json diff --git a/Regression/Checksum/benchmarks_json/Python_magnetostatic_eb_3d.json b/Regression/Checksum/benchmarks_json/test_3d_magnetostatic_eb_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_magnetostatic_eb_3d.json rename to Regression/Checksum/benchmarks_json/test_3d_magnetostatic_eb_picmi.json diff --git a/Regression/Checksum/benchmarks_json/NodalElectrostaticSolver.json b/Regression/Checksum/benchmarks_json/test_3d_nodal_electrostatic_solver.json similarity index 100% rename from Regression/Checksum/benchmarks_json/NodalElectrostaticSolver.json rename to Regression/Checksum/benchmarks_json/test_3d_nodal_electrostatic_solver.json diff --git a/Regression/Checksum/benchmarks_json/openbc_poisson_solver.json b/Regression/Checksum/benchmarks_json/test_3d_open_bc_poisson_solver.json similarity index 100% rename from Regression/Checksum/benchmarks_json/openbc_poisson_solver.json rename to Regression/Checksum/benchmarks_json/test_3d_open_bc_poisson_solver.json diff --git a/Regression/Checksum/benchmarks_json/particle_boundaries_3d.json b/Regression/Checksum/benchmarks_json/test_3d_particle_boundaries.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particle_boundaries_3d.json rename to Regression/Checksum/benchmarks_json/test_3d_particle_boundaries.json diff --git a/Regression/Checksum/benchmarks_json/particle_fields_diags.json b/Regression/Checksum/benchmarks_json/test_3d_particle_fields_diags.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particle_fields_diags.json rename to Regression/Checksum/benchmarks_json/test_3d_particle_fields_diags.json diff --git a/Regression/Checksum/benchmarks_json/particle_fields_diags_single_precision.json b/Regression/Checksum/benchmarks_json/test_3d_particle_fields_diags_single_precision.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particle_fields_diags_single_precision.json rename to Regression/Checksum/benchmarks_json/test_3d_particle_fields_diags_single_precision.json diff --git a/Regression/Checksum/benchmarks_json/particle_pusher.json b/Regression/Checksum/benchmarks_json/test_3d_particle_pusher.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particle_pusher.json rename to Regression/Checksum/benchmarks_json/test_3d_particle_pusher.json diff --git a/Regression/Checksum/benchmarks_json/particles_in_pml.json b/Regression/Checksum/benchmarks_json/test_3d_particles_in_pml.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particles_in_pml.json rename to Regression/Checksum/benchmarks_json/test_3d_particles_in_pml.json diff --git a/Regression/Checksum/benchmarks_json/particles_in_pml_3d_MR.json b/Regression/Checksum/benchmarks_json/test_3d_particles_in_pml_mr.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particles_in_pml_3d_MR.json rename to Regression/Checksum/benchmarks_json/test_3d_particles_in_pml_mr.json diff --git a/Regression/Checksum/benchmarks_json/PEC_field.json b/Regression/Checksum/benchmarks_json/test_3d_pec_field.json similarity index 100% rename from Regression/Checksum/benchmarks_json/PEC_field.json rename to Regression/Checksum/benchmarks_json/test_3d_pec_field.json diff --git a/Regression/Checksum/benchmarks_json/PEC_field_mr.json b/Regression/Checksum/benchmarks_json/test_3d_pec_field_mr.json similarity index 100% rename from Regression/Checksum/benchmarks_json/PEC_field_mr.json rename to Regression/Checksum/benchmarks_json/test_3d_pec_field_mr.json diff --git a/Regression/Checksum/benchmarks_json/PEC_particle.json b/Regression/Checksum/benchmarks_json/test_3d_pec_particle.json similarity index 100% rename from Regression/Checksum/benchmarks_json/PEC_particle.json rename to Regression/Checksum/benchmarks_json/test_3d_pec_particle.json diff --git a/Regression/Checksum/benchmarks_json/photon_pusher.json b/Regression/Checksum/benchmarks_json/test_3d_photon_pusher.json similarity index 100% rename from Regression/Checksum/benchmarks_json/photon_pusher.json rename to Regression/Checksum/benchmarks_json/test_3d_photon_pusher.json diff --git a/Regression/Checksum/benchmarks_json/PlasmaAccelerationBoost3d.json b/Regression/Checksum/benchmarks_json/test_3d_plasma_acceleration_boosted.json similarity index 100% rename from Regression/Checksum/benchmarks_json/PlasmaAccelerationBoost3d.json rename to Regression/Checksum/benchmarks_json/test_3d_plasma_acceleration_boosted.json diff --git a/Regression/Checksum/benchmarks_json/PlasmaAccelerationBoost3d_hybrid.json b/Regression/Checksum/benchmarks_json/test_3d_plasma_acceleration_boosted_hybrid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/PlasmaAccelerationBoost3d_hybrid.json rename to Regression/Checksum/benchmarks_json/test_3d_plasma_acceleration_boosted_hybrid.json diff --git a/Regression/Checksum/benchmarks_json/Python_PlasmaAccelerationMR.json b/Regression/Checksum/benchmarks_json/test_3d_plasma_acceleration_mr_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_PlasmaAccelerationMR.json rename to Regression/Checksum/benchmarks_json/test_3d_plasma_acceleration_mr_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Python_PlasmaAcceleration.json b/Regression/Checksum/benchmarks_json/test_3d_plasma_acceleration_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_PlasmaAcceleration.json rename to Regression/Checksum/benchmarks_json/test_3d_plasma_acceleration_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Plasma_lens.json b/Regression/Checksum/benchmarks_json/test_3d_plasma_lens.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Plasma_lens.json rename to Regression/Checksum/benchmarks_json/test_3d_plasma_lens.json diff --git a/Regression/Checksum/benchmarks_json/Plasma_lens_boosted.json b/Regression/Checksum/benchmarks_json/test_3d_plasma_lens_boosted.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Plasma_lens_boosted.json rename to Regression/Checksum/benchmarks_json/test_3d_plasma_lens_boosted.json diff --git a/Regression/Checksum/benchmarks_json/hard_edged_plasma_lens.json b/Regression/Checksum/benchmarks_json/test_3d_plasma_lens_hard_edged.json similarity index 100% rename from Regression/Checksum/benchmarks_json/hard_edged_plasma_lens.json rename to Regression/Checksum/benchmarks_json/test_3d_plasma_lens_hard_edged.json diff --git a/Regression/Checksum/benchmarks_json/Plasma_lens_short.json b/Regression/Checksum/benchmarks_json/test_3d_plasma_lens_short.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Plasma_lens_short.json rename to Regression/Checksum/benchmarks_json/test_3d_plasma_lens_short.json diff --git a/Regression/Checksum/benchmarks_json/pml_psatd_dive_divb_cleaning.json b/Regression/Checksum/benchmarks_json/test_3d_pml_psatd_dive_divb_cleaning.json similarity index 100% rename from Regression/Checksum/benchmarks_json/pml_psatd_dive_divb_cleaning.json rename to Regression/Checksum/benchmarks_json/test_3d_pml_psatd_dive_divb_cleaning.json diff --git a/Regression/Checksum/benchmarks_json/Point_of_contact_EB_3d.json b/Regression/Checksum/benchmarks_json/test_3d_point_of_contact_eb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Point_of_contact_EB_3d.json rename to Regression/Checksum/benchmarks_json/test_3d_point_of_contact_eb.json diff --git a/Regression/Checksum/benchmarks_json/test_3d_projection_divb_cleaner_callback_picmi.json b/Regression/Checksum/benchmarks_json/test_3d_projection_divb_cleaner_callback_picmi.json new file mode 100644 index 00000000000..bd44f9d2c44 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_3d_projection_divb_cleaner_callback_picmi.json @@ -0,0 +1,7 @@ +{ + "lev=0": { + "Bx": 16281.68118911512, + "By": 16281.681189115117, + "Bz": 78850.29928317585 + } +} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/test_3d_projection_divb_cleaner_picmi.json b/Regression/Checksum/benchmarks_json/test_3d_projection_divb_cleaner_picmi.json new file mode 100644 index 00000000000..7bf927205ee --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_3d_projection_divb_cleaner_picmi.json @@ -0,0 +1,7 @@ +{ + "lev=0": { + "Bx": 51.23782716855388, + "By": 51.23782716855387, + "Bz": 341.0698792433061 + } +} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/Proton_Boron_Fusion_3D.json b/Regression/Checksum/benchmarks_json/test_3d_proton_boron_fusion.json similarity index 53% rename from Regression/Checksum/benchmarks_json/Proton_Boron_Fusion_3D.json rename to Regression/Checksum/benchmarks_json/test_3d_proton_boron_fusion.json index ec7e047c537..5c9d00d6f70 100644 --- a/Regression/Checksum/benchmarks_json/Proton_Boron_Fusion_3D.json +++ b/Regression/Checksum/benchmarks_json/test_3d_proton_boron_fusion.json @@ -1,17 +1,17 @@ { - "lev=0": { - "rho": 0.0 - }, - "proton1": { - "particle_momentum_x": 0.0, - "particle_momentum_y": 0.0, - "particle_momentum_z": 2.524872467113344e-13, - "particle_position_x": 40960140.72983793, - "particle_position_y": 40959772.69310104, - "particle_position_z": 81919021.52308556, - "particle_weight": 1024.000000000021 - }, - "boron1": { + "lev=0": { + "rho": 0.0 + }, + "proton1": { + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 2.524872467113344e-13, + "particle_position_x": 40960140.72983793, + "particle_position_y": 40959772.69310104, + "particle_position_z": 81919021.52308556, + "particle_weight": 1024.000000000021 + }, + "boron1": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, "particle_momentum_z": 2.524872467113344e-13, @@ -19,35 +19,36 @@ "particle_position_y": 40961136.14476712, "particle_position_z": 81920546.19181262, "particle_weight": 1024.000000000021 - }, - "alpha3": { - "particle_momentum_x": 4.764404554793872e-16, - "particle_momentum_y": 4.655900875811434e-16, - "particle_momentum_z": 4.578927372510084e-16, - "particle_position_x": 50987.442011759704, - "particle_position_y": 48999.674675246955, - "particle_position_z": 101142.57224226737, - "particle_weight": 1.0633705344227063e+28 - }, - "alpha1": { - "particle_momentum_x": 4.665933695243743e-15, - "particle_momentum_y": 4.603805875733438e-15, - "particle_momentum_z": 4.706765986105302e-15, + }, + "boron3": { + "particle_momentum_x": 9.277692671587846e-15, + "particle_momentum_y": 9.268409636965691e-15, + "particle_momentum_z": 9.279446607709548e-15, + "particle_position_x": 4096178.1664224654, + "particle_position_y": 4096499.7060386725, + "particle_position_z": 8191465.586938233, + "particle_weight": 5.119677303391259e+31 + }, + "alpha2": { + "particle_momentum_x": 4.172264972648105e-15, + "particle_momentum_y": 4.1838781269703316e-15, + "particle_momentum_z": 4.256769380749126e-15, + "particle_position_x": 408575.75269073684, + "particle_position_y": 413407.5155277014, + "particle_position_z": 863983.4313441743, + "particle_weight": 3.3372246639840338e+19 + }, + + "alpha1": { + "particle_momentum_x": 4.743550273664842e-15, + "particle_momentum_y": 4.703189539479841e-15, + "particle_momentum_z": 4.75829084832661e-15, "particle_position_x": 461871.79172011977, "particle_position_y": 461162.2166206925, "particle_position_z": 969262.7809050508, "particle_weight": 3.2387855108185994e-27 - }, - "alpha5": { - "particle_momentum_x": 2.3388206254864998e-14, - "particle_momentum_y": 2.334372885765467e-14, - "particle_momentum_z": 2.363588638941874e-14, - "particle_position_x": 2457556.857163843, - "particle_position_y": 2457059.6353793247, - "particle_position_z": 4915847.043341331, - "particle_weight": 3.0719999999999984e-18 - }, - "boron5": { + }, + "boron5": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, "particle_momentum_z": 0.0, @@ -55,17 +56,17 @@ "particle_position_y": 409518.5558814353, "particle_position_z": 819306.5006950963, "particle_weight": 1023.9999999999999 - }, - "proton2": { - "particle_momentum_x": 0.0, - "particle_momentum_y": 0.0, - "particle_momentum_z": 2.3745333755307162e-14, - "particle_position_x": 4095630.698135355, - "particle_position_y": 4096073.5517983637, - "particle_position_z": 8191737.5566503005, - "particle_weight": 1.022781024024315e+29 - }, - "proton4": { + }, + "proton3": { + "particle_momentum_x": 1.6843593058271961e-15, + "particle_momentum_y": 1.6823892851456668e-15, + "particle_momentum_z": 1.6800222030208115e-15, + "particle_position_x": 2457072.7669634065, + "particle_position_y": 2456771.196542574, + "particle_position_z": 4914021.8271464575, + "particle_weight": 1.0236773033912632e+31 + }, + "proton4": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, "particle_momentum_z": 1.7586062624930794e-15, @@ -73,44 +74,44 @@ "particle_position_y": 409598.7077771135, "particle_position_z": 818958.0399127571, "particle_weight": 1.0240000000000003e+38 - }, - "boron3": { - "particle_momentum_x": 9.277692671587846e-15, - "particle_momentum_y": 9.268409636965691e-15, - "particle_momentum_z": 9.279446607709548e-15, - "particle_position_x": 4096178.1664224654, - "particle_position_y": 4096499.7060386725, - "particle_position_z": 8191465.586938233, - "particle_weight": 5.1196455431551905e+31 - }, - "alpha4": { - "particle_momentum_x": 2.33898275612641e-14, - "particle_momentum_y": 2.3423797451957437e-14, - "particle_momentum_z": 2.3516107929259732e-14, - "particle_position_x": 2457367.458278153, - "particle_position_y": 2457512.0443730573, + }, + "alpha3": { + "particle_momentum_x": 4.529369912319074e-16, + "particle_momentum_y": 4.55762819982174e-16, + "particle_momentum_z": 4.501223434274883e-16, + "particle_position_x": 48732.63289890166, + "particle_position_y": 46262.85664926968, + "particle_position_z": 95593.72900482587, + "particle_weight": 9.680898262134895e+27 + }, + "alpha5": { + "particle_momentum_x": 2.3875154301762454e-14, + "particle_momentum_y": 2.3859525730749002e-14, + "particle_momentum_z": 2.4029799910201597e-14, + "particle_position_x": 2457556.8571638423, + "particle_position_y": 2457059.6353793237, + "particle_position_z": 4915847.043341332, + "particle_weight": 3.0719999999999984e-18 + }, + "alpha4": { + "particle_momentum_x": 2.3842314895045605e-14, + "particle_momentum_y": 2.386245392919704e-14, + "particle_momentum_z": 2.4007606987094537e-14, + "particle_position_x": 2457367.4582781545, + "particle_position_y": 2457512.044373057, "particle_position_z": 4914475.7765130745, "particle_weight": 3072.000000000002 - }, - "proton3": { - "particle_momentum_x": 1.6847282386883186e-15, - "particle_momentum_y": 1.6828065767793222e-15, - "particle_momentum_z": 1.6803456707569493e-15, - "particle_position_x": 2457343.371083716, - "particle_position_y": 2457033.3891170574, - "particle_position_z": 4914529.855222688, - "particle_weight": 1.023645543155193e+31 - }, - "proton5": { + }, + "proton2": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, - "particle_momentum_z": 1.7586062624930794e-15, - "particle_position_x": 409638.28776185703, - "particle_position_y": 409501.32257833943, - "particle_position_z": 819309.1804186807, - "particle_weight": 1.0240000000000003e+38 - }, - "boron2": { + "particle_momentum_z": 2.3745333755307162e-14, + "particle_position_x": 4095630.698135355, + "particle_position_y": 4096073.5517983637, + "particle_position_z": 8191737.5566503005, + "particle_weight": 1.022781024024315e+29 + }, + "boron2": { "particle_momentum_x": 0.0, "particle_momentum_y": 0.0, "particle_momentum_z": 0.0, @@ -118,14 +119,14 @@ "particle_position_y": 409670.9858143465, "particle_position_z": 819255.8152412223, "particle_weight": 1.0239999998887592e+29 - }, - "alpha2": { - "particle_momentum_x": 4.1179548991012315e-15, - "particle_momentum_y": 4.110026665992801e-15, - "particle_momentum_z": 4.169802553223462e-15, - "particle_position_x": 408575.75269073684, - "particle_position_y": 413407.5155277014, - "particle_position_z": 863983.4313441743, - "particle_weight": 3.3372246639840338e+19 - } + }, + "proton5": { + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 1.7586062624930794e-15, + "particle_position_x": 409638.28776185703, + "particle_position_y": 409501.32257833943, + "particle_position_z": 819309.1804186807, + "particle_weight": 1.0240000000000003e+38 + } } diff --git a/Regression/Checksum/benchmarks_json/qed_breit_wheeler_3d.json b/Regression/Checksum/benchmarks_json/test_3d_qed_breit_wheeler.json similarity index 100% rename from Regression/Checksum/benchmarks_json/qed_breit_wheeler_3d.json rename to Regression/Checksum/benchmarks_json/test_3d_qed_breit_wheeler.json diff --git a/Regression/Checksum/benchmarks_json/qed_quantum_sync_3d.json b/Regression/Checksum/benchmarks_json/test_3d_qed_quantum_sync.json similarity index 100% rename from Regression/Checksum/benchmarks_json/qed_quantum_sync_3d.json rename to Regression/Checksum/benchmarks_json/test_3d_qed_quantum_sync.json diff --git a/Regression/Checksum/benchmarks_json/qed_schwinger1.json b/Regression/Checksum/benchmarks_json/test_3d_qed_schwinger_1.json similarity index 100% rename from Regression/Checksum/benchmarks_json/qed_schwinger1.json rename to Regression/Checksum/benchmarks_json/test_3d_qed_schwinger_1.json diff --git a/Regression/Checksum/benchmarks_json/qed_schwinger2.json b/Regression/Checksum/benchmarks_json/test_3d_qed_schwinger_2.json similarity index 100% rename from Regression/Checksum/benchmarks_json/qed_schwinger2.json rename to Regression/Checksum/benchmarks_json/test_3d_qed_schwinger_2.json diff --git a/Regression/Checksum/benchmarks_json/qed_schwinger3.json b/Regression/Checksum/benchmarks_json/test_3d_qed_schwinger_3.json similarity index 100% rename from Regression/Checksum/benchmarks_json/qed_schwinger3.json rename to Regression/Checksum/benchmarks_json/test_3d_qed_schwinger_3.json diff --git a/Regression/Checksum/benchmarks_json/qed_schwinger4.json b/Regression/Checksum/benchmarks_json/test_3d_qed_schwinger_4.json similarity index 100% rename from Regression/Checksum/benchmarks_json/qed_schwinger4.json rename to Regression/Checksum/benchmarks_json/test_3d_qed_schwinger_4.json diff --git a/Regression/Checksum/benchmarks_json/radiation_reaction.json b/Regression/Checksum/benchmarks_json/test_3d_radiation_reaction.json similarity index 100% rename from Regression/Checksum/benchmarks_json/radiation_reaction.json rename to Regression/Checksum/benchmarks_json/test_3d_radiation_reaction.json diff --git a/Regression/Checksum/benchmarks_json/reduced_diags.json b/Regression/Checksum/benchmarks_json/test_3d_reduced_diags.json similarity index 100% rename from Regression/Checksum/benchmarks_json/reduced_diags.json rename to Regression/Checksum/benchmarks_json/test_3d_reduced_diags.json diff --git a/Regression/Checksum/benchmarks_json/reduced_diags_loadbalancecosts_heuristic.json b/Regression/Checksum/benchmarks_json/test_3d_reduced_diags_load_balance_costs_heuristic.json similarity index 100% rename from Regression/Checksum/benchmarks_json/reduced_diags_loadbalancecosts_heuristic.json rename to Regression/Checksum/benchmarks_json/test_3d_reduced_diags_load_balance_costs_heuristic.json diff --git a/Regression/Checksum/benchmarks_json/reduced_diags_loadbalancecosts_timers.json b/Regression/Checksum/benchmarks_json/test_3d_reduced_diags_load_balance_costs_timers.json similarity index 100% rename from Regression/Checksum/benchmarks_json/reduced_diags_loadbalancecosts_timers.json rename to Regression/Checksum/benchmarks_json/test_3d_reduced_diags_load_balance_costs_timers.json diff --git a/Regression/Checksum/benchmarks_json/reduced_diags_loadbalancecosts_timers_psatd.json b/Regression/Checksum/benchmarks_json/test_3d_reduced_diags_load_balance_costs_timers_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/reduced_diags_loadbalancecosts_timers_psatd.json rename to Regression/Checksum/benchmarks_json/test_3d_reduced_diags_load_balance_costs_timers_psatd.json diff --git a/Regression/Checksum/benchmarks_json/reduced_diags_single_precision.json b/Regression/Checksum/benchmarks_json/test_3d_reduced_diags_single_precision.json similarity index 100% rename from Regression/Checksum/benchmarks_json/reduced_diags_single_precision.json rename to Regression/Checksum/benchmarks_json/test_3d_reduced_diags_single_precision.json diff --git a/Regression/Checksum/benchmarks_json/relativistic_space_charge_initialization.json b/Regression/Checksum/benchmarks_json/test_3d_relativistic_space_charge_initialization.json similarity index 100% rename from Regression/Checksum/benchmarks_json/relativistic_space_charge_initialization.json rename to Regression/Checksum/benchmarks_json/test_3d_relativistic_space_charge_initialization.json diff --git a/Regression/Checksum/benchmarks_json/space_charge_initialization.json b/Regression/Checksum/benchmarks_json/test_3d_space_charge_initialization.json similarity index 100% rename from Regression/Checksum/benchmarks_json/space_charge_initialization.json rename to Regression/Checksum/benchmarks_json/test_3d_space_charge_initialization.json diff --git a/Regression/Checksum/benchmarks_json/uniform_plasma_restart.json b/Regression/Checksum/benchmarks_json/test_3d_uniform_plasma.json similarity index 100% rename from Regression/Checksum/benchmarks_json/uniform_plasma_restart.json rename to Regression/Checksum/benchmarks_json/test_3d_uniform_plasma.json diff --git a/Regression/Checksum/benchmarks_json/uniform_plasma_multiJ.json b/Regression/Checksum/benchmarks_json/test_3d_uniform_plasma_multiJ.json similarity index 100% rename from Regression/Checksum/benchmarks_json/uniform_plasma_multiJ.json rename to Regression/Checksum/benchmarks_json/test_3d_uniform_plasma_multiJ.json diff --git a/Regression/Checksum/benchmarks_json/VayDeposition3D.json b/Regression/Checksum/benchmarks_json/test_3d_vay_deposition.json similarity index 100% rename from Regression/Checksum/benchmarks_json/VayDeposition3D.json rename to Regression/Checksum/benchmarks_json/test_3d_vay_deposition.json diff --git a/Regression/Checksum/benchmarks_json/BTD_rz.json b/Regression/Checksum/benchmarks_json/test_rz_btd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/BTD_rz.json rename to Regression/Checksum/benchmarks_json/test_rz_btd.json diff --git a/Regression/Checksum/benchmarks_json/collisionRZ.json b/Regression/Checksum/benchmarks_json/test_rz_collision.json similarity index 100% rename from Regression/Checksum/benchmarks_json/collisionRZ.json rename to Regression/Checksum/benchmarks_json/test_rz_collision.json diff --git a/Regression/Checksum/benchmarks_json/Deuterium_Tritium_Fusion_RZ.json b/Regression/Checksum/benchmarks_json/test_rz_deuterium_tritium_fusion.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Deuterium_Tritium_Fusion_RZ.json rename to Regression/Checksum/benchmarks_json/test_rz_deuterium_tritium_fusion.json diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphereRZ.json b/Regression/Checksum/benchmarks_json/test_rz_electrostatic_sphere.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ElectrostaticSphereRZ.json rename to Regression/Checksum/benchmarks_json/test_rz_electrostatic_sphere.json diff --git a/Regression/Checksum/benchmarks_json/ElectrostaticSphereEB_RZ.json b/Regression/Checksum/benchmarks_json/test_rz_electrostatic_sphere_eb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/ElectrostaticSphereEB_RZ.json rename to Regression/Checksum/benchmarks_json/test_rz_electrostatic_sphere_eb.json diff --git a/Regression/Checksum/benchmarks_json/test_rz_electrostatic_sphere_eb_mr.json b/Regression/Checksum/benchmarks_json/test_rz_electrostatic_sphere_eb_mr.json new file mode 100644 index 00000000000..6bbfce0e3b3 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_rz_electrostatic_sphere_eb_mr.json @@ -0,0 +1,10 @@ +{ + "lev=0": { + "Er": 16975.32314347822, + "phi": 4072.085617045073 + }, + "lev=1": { + "Er": 26818.189739547757, + "phi_lvl1": 8731.176548788893 + } +} diff --git a/Regression/Checksum/benchmarks_json/EmbeddedBoundaryDiffraction.json b/Regression/Checksum/benchmarks_json/test_rz_embedded_boundary_diffraction.json similarity index 100% rename from Regression/Checksum/benchmarks_json/EmbeddedBoundaryDiffraction.json rename to Regression/Checksum/benchmarks_json/test_rz_embedded_boundary_diffraction.json diff --git a/Regression/Checksum/benchmarks_json/test_rz_flux_injection.json b/Regression/Checksum/benchmarks_json/test_rz_flux_injection.json new file mode 100644 index 00000000000..2ba80d4fb0e --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_rz_flux_injection.json @@ -0,0 +1,15 @@ +{ + "lev=0": { + "Bz": 9.524453851623612e-24 + }, + "electron": { + "particle_momentum_x": 7.146168286112378e-18, + "particle_momentum_y": 7.073108431229069e-18, + "particle_momentum_z": 9.282175511339672e-42, + "particle_position_x": 6978.157994231982, + "particle_position_y": 2044.6981840260364, + "particle_theta": 6298.956888689097, + "particle_weight": 3.2236798669537214e-08 + } +} + diff --git a/Regression/Checksum/benchmarks_json/galilean_rz_psatd.json b/Regression/Checksum/benchmarks_json/test_rz_galilean_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_rz_psatd.json rename to Regression/Checksum/benchmarks_json/test_rz_galilean_psatd.json diff --git a/Regression/Checksum/benchmarks_json/galilean_rz_psatd_current_correction.json b/Regression/Checksum/benchmarks_json/test_rz_galilean_psatd_current_correction.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_rz_psatd_current_correction.json rename to Regression/Checksum/benchmarks_json/test_rz_galilean_psatd_current_correction.json diff --git a/Regression/Checksum/benchmarks_json/galilean_rz_psatd_current_correction_psb.json b/Regression/Checksum/benchmarks_json/test_rz_galilean_psatd_current_correction_psb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/galilean_rz_psatd_current_correction_psb.json rename to Regression/Checksum/benchmarks_json/test_rz_galilean_psatd_current_correction_psb.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_fluid_RZ.json b/Regression/Checksum/benchmarks_json/test_rz_langmuir_fluid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_fluid_RZ.json rename to Regression/Checksum/benchmarks_json/test_rz_langmuir_fluid.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_rz.json b/Regression/Checksum/benchmarks_json/test_rz_langmuir_multi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_rz.json rename to Regression/Checksum/benchmarks_json/test_rz_langmuir_multi.json diff --git a/Regression/Checksum/benchmarks_json/Python_Langmuir_rz_multimode.json b/Regression/Checksum/benchmarks_json/test_rz_langmuir_multi_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_Langmuir_rz_multimode.json rename to Regression/Checksum/benchmarks_json/test_rz_langmuir_multi_picmi.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_rz_psatd.json b/Regression/Checksum/benchmarks_json/test_rz_langmuir_multi_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_rz_psatd.json rename to Regression/Checksum/benchmarks_json/test_rz_langmuir_multi_psatd.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_rz_psatd_current_correction.json b/Regression/Checksum/benchmarks_json/test_rz_langmuir_multi_psatd_current_correction.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_rz_psatd_current_correction.json rename to Regression/Checksum/benchmarks_json/test_rz_langmuir_multi_psatd_current_correction.json diff --git a/Regression/Checksum/benchmarks_json/Langmuir_multi_rz_psatd_multiJ.json b/Regression/Checksum/benchmarks_json/test_rz_langmuir_multi_psatd_multiJ.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Langmuir_multi_rz_psatd_multiJ.json rename to Regression/Checksum/benchmarks_json/test_rz_langmuir_multi_psatd_multiJ.json diff --git a/Regression/Checksum/benchmarks_json/LaserAccelerationRZ.json b/Regression/Checksum/benchmarks_json/test_rz_laser_acceleration.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserAccelerationRZ.json rename to Regression/Checksum/benchmarks_json/test_rz_laser_acceleration.json diff --git a/Regression/Checksum/benchmarks_json/Python_LaserAccelerationRZ.json b/Regression/Checksum/benchmarks_json/test_rz_laser_acceleration_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_LaserAccelerationRZ.json rename to Regression/Checksum/benchmarks_json/test_rz_laser_acceleration_picmi.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjectionFromRZLASYFile.json b/Regression/Checksum/benchmarks_json/test_rz_laser_injection_from_RZ_lasy_file.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjectionFromRZLASYFile.json rename to Regression/Checksum/benchmarks_json/test_rz_laser_injection_from_RZ_lasy_file.json diff --git a/Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile_RZ.json b/Regression/Checksum/benchmarks_json/test_rz_laser_injection_from_lasy_file.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LaserInjectionFromLASYFile_RZ.json rename to Regression/Checksum/benchmarks_json/test_rz_laser_injection_from_lasy_file.json diff --git a/Regression/Checksum/benchmarks_json/LoadExternalFieldRZGrid.json b/Regression/Checksum/benchmarks_json/test_rz_load_external_field_grid.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LoadExternalFieldRZGrid.json rename to Regression/Checksum/benchmarks_json/test_rz_load_external_field_grid.json diff --git a/Regression/Checksum/benchmarks_json/LoadExternalFieldRZParticles.json b/Regression/Checksum/benchmarks_json/test_rz_load_external_field_particles.json similarity index 100% rename from Regression/Checksum/benchmarks_json/LoadExternalFieldRZParticles.json rename to Regression/Checksum/benchmarks_json/test_rz_load_external_field_particles.json diff --git a/Regression/Checksum/benchmarks_json/Python_magnetostatic_eb_rz.json b/Regression/Checksum/benchmarks_json/test_rz_magnetostatic_eb_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_magnetostatic_eb_rz.json rename to Regression/Checksum/benchmarks_json/test_rz_magnetostatic_eb_picmi.json diff --git a/Regression/Checksum/benchmarks_json/test_rz_multiJ_psatd.json b/Regression/Checksum/benchmarks_json/test_rz_multiJ_psatd.json new file mode 100644 index 00000000000..d9ca66cf0c3 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_rz_multiJ_psatd.json @@ -0,0 +1,40 @@ +{ + "lev=0": { + "Bt": 5436.145827903481, + "Er": 1084033329144.5951, + "Ez": 1031727477244.4946, + "jr": 86689049352046.02, + "jz": 384358875752423.8, + "rho": 863406.9511533659, + "rho_driver": 1142390.635353391, + "rho_plasma_e": 12207428.74629265, + "rho_plasma_p": 12452342.269855343 + }, + "driver": { + "particle_momentum_x": 8.723365602723476e-16, + "particle_momentum_y": 8.719184082046568e-16, + "particle_momentum_z": 5.461727890375063e-13, + "particle_position_x": 6.269474429349755, + "particle_position_y": 17.933429487411857, + "particle_theta": 1570777.477238974, + "particle_weight": 6241434176.35186 + }, + "plasma_e": { + "particle_momentum_x": 1.369719083664514e-20, + "particle_momentum_y": 1.5823095211640957e-20, + "particle_momentum_z": 7.189697105606772e-21, + "particle_position_x": 0.28510775565436686, + "particle_position_y": 0.1491507116912657, + "particle_theta": 5011.181913404598, + "particle_weight": 1001422925327.429 + }, + "plasma_p": { + "particle_momentum_x": 1.4836311665634252e-20, + "particle_momentum_y": 1.3653689459385548e-20, + "particle_momentum_z": 1.2505361981099512e-20, + "particle_position_x": 0.2838368160801851, + "particle_position_y": 0.14950442866368444, + "particle_theta": 4995.577541103406, + "particle_weight": 1001422925327.4291 + } +} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/Python_ohms_law_solver_EM_modes_rz.json b/Regression/Checksum/benchmarks_json/test_rz_ohm_solver_em_modes_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Python_ohms_law_solver_EM_modes_rz.json rename to Regression/Checksum/benchmarks_json/test_rz_ohm_solver_em_modes_picmi.json diff --git a/Regression/Checksum/benchmarks_json/particle_boundary_interaction.json b/Regression/Checksum/benchmarks_json/test_rz_particle_boundary_interaction_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/particle_boundary_interaction.json rename to Regression/Checksum/benchmarks_json/test_rz_particle_boundary_interaction_picmi.json diff --git a/Regression/Checksum/benchmarks_json/pml_psatd_rz.json b/Regression/Checksum/benchmarks_json/test_rz_pml_psatd.json similarity index 100% rename from Regression/Checksum/benchmarks_json/pml_psatd_rz.json rename to Regression/Checksum/benchmarks_json/test_rz_pml_psatd.json diff --git a/Regression/Checksum/benchmarks_json/Point_of_contact_EB_rz.json b/Regression/Checksum/benchmarks_json/test_rz_point_of_contact_eb.json similarity index 100% rename from Regression/Checksum/benchmarks_json/Point_of_contact_EB_rz.json rename to Regression/Checksum/benchmarks_json/test_rz_point_of_contact_eb.json diff --git a/Regression/Checksum/benchmarks_json/test_rz_projection_divb_cleaner.json b/Regression/Checksum/benchmarks_json/test_rz_projection_divb_cleaner.json new file mode 100644 index 00000000000..df8024c11b1 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_rz_projection_divb_cleaner.json @@ -0,0 +1,7 @@ +{ + "lev=0": { + "Br": 0.8165863784977822, + "Bt": 0.0, + "Bz": 6.203503481560605 + } +} \ No newline at end of file diff --git a/Regression/Checksum/benchmarks_json/scraping.json b/Regression/Checksum/benchmarks_json/test_rz_scraping.json similarity index 100% rename from Regression/Checksum/benchmarks_json/scraping.json rename to Regression/Checksum/benchmarks_json/test_rz_scraping.json diff --git a/Regression/Checksum/benchmarks_json/silver_mueller_rz_z.json b/Regression/Checksum/benchmarks_json/test_rz_silver_mueller_z.json similarity index 100% rename from Regression/Checksum/benchmarks_json/silver_mueller_rz_z.json rename to Regression/Checksum/benchmarks_json/test_rz_silver_mueller_z.json diff --git a/Regression/Checksum/benchmarks_json/spacecraft_charging.json b/Regression/Checksum/benchmarks_json/test_rz_spacecraft_charging_picmi.json similarity index 100% rename from Regression/Checksum/benchmarks_json/spacecraft_charging.json rename to Regression/Checksum/benchmarks_json/test_rz_spacecraft_charging_picmi.json diff --git a/Regression/Checksum/checksum.py b/Regression/Checksum/checksum.py index 727c8beb7f7..4133d882a41 100644 --- a/Regression/Checksum/checksum.py +++ b/Regression/Checksum/checksum.py @@ -1,10 +1,10 @@ """ - Copyright 2020 +Copyright 2020 - This file is part of WarpX. +This file is part of WarpX. - License: BSD-3-Clause-LBNL - """ +License: BSD-3-Clause-LBNL +""" import json import sys @@ -19,10 +19,16 @@ class Checksum: - """Class for checksum comparison of one test. - """ + """Class for checksum comparison of one test.""" - def __init__(self, test_name, output_file, output_format='plotfile', do_fields=True, do_particles=True): + def __init__( + self, + test_name, + output_file, + output_format="plotfile", + do_fields=True, + do_particles=True, + ): """ Checksum constructor. Store test_name, output file name and format, compute checksum @@ -49,8 +55,9 @@ def __init__(self, test_name, output_file, output_format='plotfile', do_fields=T self.test_name = test_name self.output_file = output_file self.output_format = output_format - self.data = self.read_output_file(do_fields=do_fields, - do_particles=do_particles) + self.data = self.read_output_file( + do_fields=do_fields, do_particles=do_particles + ) def read_output_file(self, do_fields=True, do_particles=True): """ @@ -68,38 +75,45 @@ def read_output_file(self, do_fields=True, do_particles=True): Whether to read particles from the output file. """ - if self.output_format == 'plotfile': + if self.output_format == "plotfile": ds = yt.load(self.output_file) # yt 4.0+ has rounding issues with our domain data: # RuntimeError: yt attempted to read outside the boundaries # of a non-periodic domain along dimension 0. - if 'force_periodicity' in dir(ds): ds.force_periodicity() - grid_fields = [item for item in ds.field_list if item[0] == 'boxlib'] + if "force_periodicity" in dir(ds): + ds.force_periodicity() + grid_fields = [item for item in ds.field_list if item[0] == "boxlib"] # "fields"/"species" we remove: # - nbody: added by yt by default, unused by us - species_list = set([item[0] for item in ds.field_list if - item[1][:9] == 'particle_' and - item[0] != 'all' and - item[0] != 'nbody']) + species_list = set( + [ + item[0] + for item in ds.field_list + if item[1][:9] == "particle_" + and item[0] != "all" + and item[0] != "nbody" + ] + ) data = {} # Compute checksum for field quantities if do_fields: - for lev in range(ds.max_level+1): + for lev in range(ds.max_level + 1): data_lev = {} - lev_grids = [grid for grid in ds.index.grids - if grid.Level == lev] + lev_grids = [grid for grid in ds.index.grids if grid.Level == lev] # Warning: For now, we assume all levels are rectangular LeftEdge = np.min( - np.array([grid.LeftEdge.v for grid in lev_grids]), axis=0) + np.array([grid.LeftEdge.v for grid in lev_grids]), axis=0 + ) all_data_level = ds.covering_grid( - level=lev, left_edge=LeftEdge, dims=ds.domain_dimensions) + level=lev, left_edge=LeftEdge, dims=ds.domain_dimensions + ) for field in grid_fields: Q = all_data_level[field].v.squeeze() data_lev[field[1]] = np.sum(np.abs(Q)) - data['lev=' + str(lev)] = data_lev + data["lev=" + str(lev)] = data_lev # Compute checksum for particle quantities if do_particles: @@ -109,49 +123,63 @@ def read_output_file(self, do_fields=True, do_particles=True): # - particle_cpu/id: they depend on the parallelism: MPI-ranks and # on-node acceleration scheme, thus not portable # and irrelevant for physics benchmarking - part_fields = [item[1] for item in ds.field_list - if item[0] == species and - item[1] != 'particle_cpu' and - item[1] != 'particle_id' - ] + part_fields = [ + item[1] + for item in ds.field_list + if item[0] == species + and item[1] != "particle_cpu" + and item[1] != "particle_id" + ] data_species = {} for field in part_fields: Q = ad[(species, field)].v data_species[field] = np.sum(np.abs(Q)) data[species] = data_species - elif self.output_format == 'openpmd': + elif self.output_format == "openpmd": # Load time series ts = OpenPMDTimeSeries(self.output_file) data = {} # Compute number of MR levels # TODO This calculation of nlevels assumes that the last element # of level_fields is by default on the highest MR level. - level_fields = [field for field in ts.avail_fields if 'lvl' in field] + level_fields = [field for field in ts.avail_fields if "lvl" in field] nlevels = 0 if level_fields == [] else int(level_fields[-1][-1]) # Compute checksum for field quantities if do_fields: - for lev in range(nlevels+1): + for lev in range(nlevels + 1): # Create list of fields specific to level lev grid_fields = [] if lev == 0: - grid_fields = [field for field in ts.avail_fields if 'lvl' not in field] + grid_fields = [ + field for field in ts.avail_fields if "lvl" not in field + ] else: - grid_fields = [field for field in ts.avail_fields if f'lvl{lev}' in field] + grid_fields = [ + field for field in ts.avail_fields if f"lvl{lev}" in field + ] data_lev = {} for field in grid_fields: - vector_components = ts.fields_metadata[field]['avail_components'] + vector_components = ts.fields_metadata[field][ + "avail_components" + ] if vector_components != []: for coord in vector_components: - Q, info = ts.get_field(field=field, iteration=ts.iterations[-1], coord=coord) + Q, info = ts.get_field( + field=field, + iteration=ts.iterations[-1], + coord=coord, + ) # key stores strings composed of field name and vector components # (e.g., field='B' or field='B_lvl1' + coord='y' results in key='By') - key = field.replace(f'_lvl{lev}', '') + coord + key = field.replace(f"_lvl{lev}", "") + coord data_lev[key] = np.sum(np.abs(Q)) - else: # scalar field - Q, info = ts.get_field(field=field, iteration=ts.iterations[-1]) + else: # scalar field + Q, info = ts.get_field( + field=field, iteration=ts.iterations[-1] + ) data_lev[field] = np.sum(np.abs(Q)) - data[f'lev={lev}'] = data_lev + data[f"lev={lev}"] = data_lev # Compute checksum for particle quantities if do_particles: species_list = [] @@ -159,27 +187,36 @@ def read_output_file(self, do_fields=True, do_particles=True): species_list = ts.avail_record_components.keys() for species in species_list: data_species = {} - part_fields = [item for item in ts.avail_record_components[species] - if item != 'id' and item != 'charge' and item != 'mass'] + part_fields = [ + item + for item in ts.avail_record_components[species] + if item != "id" and item != "charge" and item != "mass" + ] # Convert the field name to the name used in plotfiles for field in part_fields: - Q = ts.get_particle(var_list=[field], species=species, iteration=ts.iterations[-1]) - if field in ['x', 'y', 'z']: - field_name = 'particle_position_' + field - elif field in ['ux', 'uy', 'uz']: - field_name = 'particle_momentum_' + field[-1] - m, = ts.get_particle(['mass'], species=species, iteration=ts.iterations[-1]) - Q *= m*c - elif field in ['w']: - field_name = 'particle_weight' + Q = ts.get_particle( + var_list=[field], + species=species, + iteration=ts.iterations[-1], + ) + if field in ["x", "y", "z"]: + field_name = "particle_position_" + field + elif field in ["ux", "uy", "uz"]: + field_name = "particle_momentum_" + field[-1] + (m,) = ts.get_particle( + ["mass"], species=species, iteration=ts.iterations[-1] + ) + Q *= m * c + elif field in ["w"]: + field_name = "particle_weight" else: - field_name = 'particle_' + field + field_name = "particle_" + field data_species[field_name] = np.sum(np.abs(Q)) data[species] = data_species return data - def evaluate(self, rtol=1.e-9, atol=1.e-40): + def evaluate(self, rtol=1.0e-9, atol=1.0e-40): """ Compare output file checksum with benchmark. Read checksum from output file, read benchmark @@ -199,9 +236,11 @@ def evaluate(self, rtol=1.e-9, atol=1.e-40): ref_benchmark = Benchmark(self.test_name) # Dictionaries have same outer keys (levels, species)? - if (self.data.keys() != ref_benchmark.data.keys()): - print("ERROR: Benchmark and output file checksum " - "have different outer keys:") + if self.data.keys() != ref_benchmark.data.keys(): + print( + "ERROR: Benchmark and output file checksum " + "have different outer keys:" + ) print("Benchmark: %s" % ref_benchmark.data.keys()) print("Test file: %s" % self.data.keys()) print("\n----------------\nNew file for " + self.test_name + ":") @@ -211,14 +250,17 @@ def evaluate(self, rtol=1.e-9, atol=1.e-40): # Dictionaries have same inner keys (field and particle quantities)? for key1 in ref_benchmark.data.keys(): - if (self.data[key1].keys() != ref_benchmark.data[key1].keys()): - print("ERROR: Benchmark and output file checksum have " - "different inner keys:") + if self.data[key1].keys() != ref_benchmark.data[key1].keys(): + print( + "ERROR: Benchmark and output file checksum have " + "different inner keys:" + ) print("Common outer keys: %s" % ref_benchmark.data.keys()) - print("Benchmark inner keys in %s: %s" - % (key1, ref_benchmark.data[key1].keys())) - print("Test file inner keys in %s: %s" - % (key1, self.data[key1].keys())) + print( + "Benchmark inner keys in %s: %s" + % (key1, ref_benchmark.data[key1].keys()) + ) + print("Test file inner keys in %s: %s" % (key1, self.data[key1].keys())) print("\n----------------\nNew file for " + self.test_name + ":") print(json.dumps(self.data, indent=2)) print("----------------") @@ -228,23 +270,31 @@ def evaluate(self, rtol=1.e-9, atol=1.e-40): checksums_differ = False for key1 in ref_benchmark.data.keys(): for key2 in ref_benchmark.data[key1].keys(): - passed = np.isclose(self.data[key1][key2], - ref_benchmark.data[key1][key2], - rtol=rtol, atol=atol) + passed = np.isclose( + self.data[key1][key2], + ref_benchmark.data[key1][key2], + rtol=rtol, + atol=atol, + ) if not passed: - print("ERROR: Benchmark and output file checksum have " - "different value for key [%s,%s]" % (key1, key2)) - print("Benchmark: [%s,%s] %.15e" - % (key1, key2, ref_benchmark.data[key1][key2])) - print("Test file: [%s,%s] %.15e" - % (key1, key2, self.data[key1][key2])) + print( + "ERROR: Benchmark and output file checksum have " + "different value for key [%s,%s]" % (key1, key2) + ) + print( + "Benchmark: [%s,%s] %.15e" + % (key1, key2, ref_benchmark.data[key1][key2]) + ) + print( + "Test file: [%s,%s] %.15e" % (key1, key2, self.data[key1][key2]) + ) checksums_differ = True # Print absolute and relative error for each failing key x = ref_benchmark.data[key1][key2] y = self.data[key1][key2] abs_err = np.abs(x - y) print("Absolute error: {:.2e}".format(abs_err)) - if (np.abs(x) != 0.): + if np.abs(x) != 0.0: rel_err = abs_err / np.abs(x) print("Relative error: {:.2e}".format(rel_err)) if checksums_differ: diff --git a/Regression/Checksum/checksumAPI.py b/Regression/Checksum/checksumAPI.py index cc13ceefa28..85aac38c3d4 100755 --- a/Regression/Checksum/checksumAPI.py +++ b/Regression/Checksum/checksumAPI.py @@ -1,12 +1,12 @@ #! /usr/bin/env python3 """ - Copyright 2020 +Copyright 2020 - This file is part of WarpX. +This file is part of WarpX. - License: BSD-3-Clause-LBNL - """ +License: BSD-3-Clause-LBNL +""" import argparse import glob @@ -35,13 +35,23 @@ """ -def evaluate_checksum(test_name, output_file, output_format='plotfile', rtol=1.e-9, atol=1.e-40, - do_fields=True, do_particles=True): +def evaluate_checksum( + test_name, + output_file, + output_format="plotfile", + rtol=1.0e-9, + atol=1.0e-40, + do_fields=True, + do_particles=True, +): """ Compare output file checksum with benchmark. Read checksum from output file, read benchmark corresponding to test_name, and assert their equality. + If the environment variable CHECKSUM_RESET is set while this function is run, + the evaluation will be replaced with a call to reset_benchmark (see below). + Parameters ---------- test_name: string @@ -65,12 +75,35 @@ def evaluate_checksum(test_name, output_file, output_format='plotfile', rtol=1.e do_particles: bool, default=True Whether to compare particles in the checksum. """ - test_checksum = Checksum(test_name, output_file, output_format, - do_fields=do_fields, do_particles=do_particles) - test_checksum.evaluate(rtol=rtol, atol=atol) - - -def reset_benchmark(test_name, output_file, output_format='plotfile', do_fields=True, do_particles=True): + # Reset benchmark? + reset = os.getenv("CHECKSUM_RESET", "False").lower() in [ + "true", + "1", + "t", + "y", + "yes", + "on", + ] + + if reset: + print( + f"Environment variable CHECKSUM_RESET is set, resetting benchmark for {test_name}" + ) + reset_benchmark(test_name, output_file, output_format, do_fields, do_particles) + else: + test_checksum = Checksum( + test_name, + output_file, + output_format, + do_fields=do_fields, + do_particles=do_particles, + ) + test_checksum.evaluate(rtol=rtol, atol=atol) + + +def reset_benchmark( + test_name, output_file, output_format="plotfile", do_fields=True, do_particles=True +): """ Update the benchmark (overwrites reference json file). Overwrite value of benchmark corresponding to @@ -93,13 +126,18 @@ def reset_benchmark(test_name, output_file, output_format='plotfile', do_fields= do_particles: bool, default=True Whether to write particles checksums in the benchmark. """ - ref_checksum = Checksum(test_name, output_file, output_format, - do_fields=do_fields, do_particles=do_particles) + ref_checksum = Checksum( + test_name, + output_file, + output_format, + do_fields=do_fields, + do_particles=do_particles, + ) ref_benchmark = Benchmark(test_name, ref_checksum.data) ref_benchmark.reset() -def reset_all_benchmarks(path_to_all_output_files, output_format='plotfile'): +def reset_all_benchmarks(path_to_all_output_files, output_format="plotfile"): """ Update all benchmarks (overwrites reference json files) found in path_to_all_output_files @@ -116,8 +154,9 @@ def reset_all_benchmarks(path_to_all_output_files, output_format='plotfile'): """ # Get list of output files in path_to_all_output_files - output_file_list = glob.glob(path_to_all_output_files + '*_plt*[0-9]', - recursive=True) + output_file_list = glob.glob( + path_to_all_output_files + "*_plt*[0-9]", recursive=True + ) output_file_list.sort() # Loop over output files and reset the corresponding benchmark @@ -126,68 +165,122 @@ def reset_all_benchmarks(path_to_all_output_files, output_format='plotfile'): reset_benchmark(test_name, output_file, output_format) -if __name__ == '__main__': - +if __name__ == "__main__": parser = argparse.ArgumentParser() # Options relevant to evaluate a checksum or reset a benchmark - parser.add_argument('--evaluate', dest='evaluate', action='store_true', - default=False, help='Evaluate a checksum.') - parser.add_argument('--reset-benchmark', dest='reset_benchmark', - default=False, - action='store_true', help='Reset a benchmark.') - parser.add_argument('--test-name', dest='test_name', type=str, default='', - required='--evaluate' in sys.argv or - '--reset-benchmark' in sys.argv, - help='Name of the test (as in WarpX-tests.ini)') - parser.add_argument('--output-file', dest='output_file', type=str, default='', - required='--evaluate' in sys.argv or - '--reset-benchmark' in sys.argv, - help='Name of WarpX output file') - parser.add_argument('--output-format', dest='output_format', type=str, default='plotfile', - required='--evaluate' in sys.argv or - '--reset-benchmark' in sys.argv, - help='Format of the output file (plotfile, openpmd)') - parser.add_argument('--skip-fields', dest='do_fields', - default=True, action='store_false', - help='If used, do not read/write field checksums') - parser.add_argument('--skip-particles', dest='do_particles', - default=True, action='store_false', - help='If used, do not read/write particle checksums') + parser.add_argument( + "--evaluate", + dest="evaluate", + action="store_true", + default=False, + help="Evaluate a checksum.", + ) + parser.add_argument( + "--reset-benchmark", + dest="reset_benchmark", + default=False, + action="store_true", + help="Reset a benchmark.", + ) + parser.add_argument( + "--test-name", + dest="test_name", + type=str, + default="", + required="--evaluate" in sys.argv or "--reset-benchmark" in sys.argv, + help="Name of the test (as in WarpX-tests.ini)", + ) + parser.add_argument( + "--output-file", + dest="output_file", + type=str, + default="", + required="--evaluate" in sys.argv or "--reset-benchmark" in sys.argv, + help="Name of WarpX output file", + ) + parser.add_argument( + "--output-format", + dest="output_format", + type=str, + default="plotfile", + required="--evaluate" in sys.argv or "--reset-benchmark" in sys.argv, + help="Format of the output file (plotfile, openpmd)", + ) + parser.add_argument( + "--skip-fields", + dest="do_fields", + default=True, + action="store_false", + help="If used, do not read/write field checksums", + ) + parser.add_argument( + "--skip-particles", + dest="do_particles", + default=True, + action="store_false", + help="If used, do not read/write particle checksums", + ) # Fields and/or particles are read from output file/written to benchmark? - parser.add_argument('--rtol', dest='rtol', - type=float, default=1.e-9, - help='relative tolerance for comparison') - parser.add_argument('--atol', dest='atol', - type=float, default=1.e-40, - help='absolute tolerance for comparison') + parser.add_argument( + "--rtol", + dest="rtol", + type=float, + default=1.0e-9, + help="relative tolerance for comparison", + ) + parser.add_argument( + "--atol", + dest="atol", + type=float, + default=1.0e-40, + help="absolute tolerance for comparison", + ) # Option to reset all benchmarks present in a folder. - parser.add_argument('--reset-all-benchmarks', dest='reset_all_benchmarks', - action='store_true', default=False, - help='Reset all benchmarks.') - parser.add_argument('--path-to-all-output-files', - dest='path_to_all_output_files', type=str, default='', - required='--reset-all-benchmarks' in sys.argv, - help='Directory containing all benchmark output files, \ + parser.add_argument( + "--reset-all-benchmarks", + dest="reset_all_benchmarks", + action="store_true", + default=False, + help="Reset all benchmarks.", + ) + parser.add_argument( + "--path-to-all-output-files", + dest="path_to_all_output_files", + type=str, + default="", + required="--reset-all-benchmarks" in sys.argv, + help="Directory containing all benchmark output files, \ typically WarpX-benchmarks generated by \ - regression_testing/regtest.py') + regression_testing/regtest.py", + ) args = parser.parse_args() if args.reset_benchmark: - reset_benchmark(args.test_name, args.output_file, args.output_format, - do_fields=args.do_fields, - do_particles=args.do_particles) + reset_benchmark( + args.test_name, + args.output_file, + args.output_format, + do_fields=args.do_fields, + do_particles=args.do_particles, + ) if args.evaluate: - evaluate_checksum(args.test_name, args.output_file, args.output_format, - rtol=args.rtol, atol=args.atol, - do_fields=args.do_fields, do_particles=args.do_particles) + evaluate_checksum( + args.test_name, + args.output_file, + args.output_format, + rtol=args.rtol, + atol=args.atol, + do_fields=args.do_fields, + do_particles=args.do_particles, + ) if args.reset_all_benchmarks: - if args.output_format == 'openpmd': - sys.exit('Option --reset-all-benchmarks does not work with openPMD format') + if args.output_format == "openpmd": + sys.exit("Option --reset-all-benchmarks does not work with openPMD format") # WARNING: this mode does not support skip-fields/particles and tolerances reset_all_benchmarks(args.path_to_all_output_files, args.output_format) diff --git a/Regression/Checksum/config.py b/Regression/Checksum/config.py index fb9dbb223c8..8d19d82beaa 100644 --- a/Regression/Checksum/config.py +++ b/Regression/Checksum/config.py @@ -1,11 +1,11 @@ """ - Copyright 2020 +Copyright 2020 - This file is part of WarpX. +This file is part of WarpX. - License: BSD-3-Clause-LBNL - """ +License: BSD-3-Clause-LBNL +""" import os -benchmark_location = os.path.split(__file__)[0] + '/benchmarks_json' +benchmark_location = os.path.split(__file__)[0] + "/benchmarks_json" diff --git a/Regression/PostProcessingUtils/__init__.py b/Regression/PostProcessingUtils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Regression/PostProcessingUtils/post_processing_utils.py b/Regression/PostProcessingUtils/post_processing_utils.py index 50026ca1076..55bc357c28b 100644 --- a/Regression/PostProcessingUtils/post_processing_utils.py +++ b/Regression/PostProcessingUtils/post_processing_utils.py @@ -13,118 +13,157 @@ ## This is a generic function to test a particle filter. We reproduce the filter in python and ## verify that the results are the same as with the WarpX filtered diagnostic. def check_particle_filter(fn, filtered_fn, filter_expression, dim, species_name): - ds = yt.load( fn ) - ds_filtered = yt.load( filtered_fn ) - ad = ds.all_data() - ad_filtered = ds_filtered.all_data() + ds = yt.load(fn) + ds_filtered = yt.load(filtered_fn) + ad = ds.all_data() + ad_filtered = ds_filtered.all_data() ## Load arrays from the unfiltered diagnostic - ids = ad[species_name, 'particle_id'].to_ndarray() - cpus = ad[species_name, 'particle_cpu'].to_ndarray() - px = ad[species_name, 'particle_momentum_x'].to_ndarray() - pz = ad[species_name, 'particle_momentum_z'].to_ndarray() - py = ad[species_name, 'particle_momentum_y'].to_ndarray() - w = ad[species_name, 'particle_weight'].to_ndarray() - if (dim == "2d"): - x = ad[species_name, 'particle_position_x'].to_ndarray() - z = ad[species_name, 'particle_position_y'].to_ndarray() - elif (dim == "3d"): - x = ad[species_name, 'particle_position_x'].to_ndarray() - y = ad[species_name, 'particle_position_y'].to_ndarray() - z = ad[species_name, 'particle_position_z'].to_ndarray() - elif (dim == "rz"): - r = ad[species_name, 'particle_position_x'].to_ndarray() - z = ad[species_name, 'particle_position_y'].to_ndarray() - theta = ad[species_name, 'particle_theta'].to_ndarray() + ids = ad[species_name, "particle_id"].to_ndarray() + cpus = ad[species_name, "particle_cpu"].to_ndarray() + px = ad[species_name, "particle_momentum_x"].to_ndarray() + pz = ad[species_name, "particle_momentum_z"].to_ndarray() + py = ad[species_name, "particle_momentum_y"].to_ndarray() + w = ad[species_name, "particle_weight"].to_ndarray() + if dim == "2d": + x = ad[species_name, "particle_position_x"].to_ndarray() + z = ad[species_name, "particle_position_y"].to_ndarray() + elif dim == "3d": + x = ad[species_name, "particle_position_x"].to_ndarray() + y = ad[species_name, "particle_position_y"].to_ndarray() + z = ad[species_name, "particle_position_z"].to_ndarray() + elif dim == "rz": + r = ad[species_name, "particle_position_x"].to_ndarray() + z = ad[species_name, "particle_position_y"].to_ndarray() + theta = ad[species_name, "particle_theta"].to_ndarray() ## Load arrays from the filtered diagnostic - ids_filtered_warpx = ad_filtered[species_name, 'particle_id'].to_ndarray() - cpus_filtered_warpx = ad_filtered[species_name, 'particle_cpu'].to_ndarray() - px_filtered_warpx = ad_filtered[species_name, 'particle_momentum_x'].to_ndarray() - pz_filtered_warpx = ad_filtered[species_name, 'particle_momentum_z'].to_ndarray() - py_filtered_warpx = ad_filtered[species_name, 'particle_momentum_y'].to_ndarray() - w_filtered_warpx = ad_filtered[species_name, 'particle_weight'].to_ndarray() - if (dim == "2d"): - x_filtered_warpx = ad_filtered[species_name, 'particle_position_x'].to_ndarray() - z_filtered_warpx = ad_filtered[species_name, 'particle_position_y'].to_ndarray() - elif (dim == "3d"): - x_filtered_warpx = ad_filtered[species_name, 'particle_position_x'].to_ndarray() - y_filtered_warpx = ad_filtered[species_name, 'particle_position_y'].to_ndarray() - z_filtered_warpx = ad_filtered[species_name, 'particle_position_z'].to_ndarray() - elif (dim == "rz"): - r_filtered_warpx = ad_filtered[species_name, 'particle_position_x'].to_ndarray() - z_filtered_warpx = ad_filtered[species_name, 'particle_position_y'].to_ndarray() - theta_filtered_warpx = ad_filtered[species_name, 'particle_theta'].to_ndarray() + ids_filtered_warpx = ad_filtered[species_name, "particle_id"].to_ndarray() + cpus_filtered_warpx = ad_filtered[species_name, "particle_cpu"].to_ndarray() + px_filtered_warpx = ad_filtered[species_name, "particle_momentum_x"].to_ndarray() + pz_filtered_warpx = ad_filtered[species_name, "particle_momentum_z"].to_ndarray() + py_filtered_warpx = ad_filtered[species_name, "particle_momentum_y"].to_ndarray() + w_filtered_warpx = ad_filtered[species_name, "particle_weight"].to_ndarray() + if dim == "2d": + x_filtered_warpx = ad_filtered[species_name, "particle_position_x"].to_ndarray() + z_filtered_warpx = ad_filtered[species_name, "particle_position_y"].to_ndarray() + elif dim == "3d": + x_filtered_warpx = ad_filtered[species_name, "particle_position_x"].to_ndarray() + y_filtered_warpx = ad_filtered[species_name, "particle_position_y"].to_ndarray() + z_filtered_warpx = ad_filtered[species_name, "particle_position_z"].to_ndarray() + elif dim == "rz": + r_filtered_warpx = ad_filtered[species_name, "particle_position_x"].to_ndarray() + z_filtered_warpx = ad_filtered[species_name, "particle_position_y"].to_ndarray() + theta_filtered_warpx = ad_filtered[species_name, "particle_theta"].to_ndarray() ## Reproduce the filter in python: this returns the indices of the filtered particles in the ## unfiltered arrays. - ind_filtered_python, = np.where(eval(filter_expression)) + (ind_filtered_python,) = np.where(eval(filter_expression)) ## Sort the indices of the filtered arrays by particle id. - sorted_ind_filtered_python = ind_filtered_python[np.argsort(ids[ind_filtered_python])] + sorted_ind_filtered_python = ind_filtered_python[ + np.argsort(ids[ind_filtered_python]) + ] sorted_ind_filtered_warpx = np.argsort(ids_filtered_warpx) ## Check that the sorted ids are exactly the same with the warpx filter and the filter ## reproduced in python - assert(np.array_equal(ids[sorted_ind_filtered_python], - ids_filtered_warpx[sorted_ind_filtered_warpx])) - assert(np.array_equal(cpus[sorted_ind_filtered_python], - cpus_filtered_warpx[sorted_ind_filtered_warpx])) + assert np.array_equal( + ids[sorted_ind_filtered_python], ids_filtered_warpx[sorted_ind_filtered_warpx] + ) + assert np.array_equal( + cpus[sorted_ind_filtered_python], cpus_filtered_warpx[sorted_ind_filtered_warpx] + ) ## Finally, we check that the sum of the particles quantities are the same to machine precision - tolerance_checksum = 1.e-12 - check_array_sum(px[sorted_ind_filtered_python], - px_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - check_array_sum(pz[sorted_ind_filtered_python], - pz_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - check_array_sum(py[sorted_ind_filtered_python], - py_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - check_array_sum(w[sorted_ind_filtered_python], - w_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - check_array_sum(z[sorted_ind_filtered_python], - z_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - if (dim == "2d"): - check_array_sum(x[sorted_ind_filtered_python], - x_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - elif (dim == "3d"): - check_array_sum(x[sorted_ind_filtered_python], - x_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - check_array_sum(y[sorted_ind_filtered_python], - y_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - elif (dim == "rz"): - check_array_sum(r[sorted_ind_filtered_python], - r_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) - check_array_sum(theta[sorted_ind_filtered_python], - theta_filtered_warpx[sorted_ind_filtered_warpx], tolerance_checksum) + tolerance_checksum = 1.0e-12 + check_array_sum( + px[sorted_ind_filtered_python], + px_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + check_array_sum( + pz[sorted_ind_filtered_python], + pz_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + check_array_sum( + py[sorted_ind_filtered_python], + py_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + check_array_sum( + w[sorted_ind_filtered_python], + w_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + check_array_sum( + z[sorted_ind_filtered_python], + z_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + if dim == "2d": + check_array_sum( + x[sorted_ind_filtered_python], + x_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + elif dim == "3d": + check_array_sum( + x[sorted_ind_filtered_python], + x_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + check_array_sum( + y[sorted_ind_filtered_python], + y_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + elif dim == "rz": + check_array_sum( + r[sorted_ind_filtered_python], + r_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + check_array_sum( + theta[sorted_ind_filtered_python], + theta_filtered_warpx[sorted_ind_filtered_warpx], + tolerance_checksum, + ) + ## This function checks that the absolute sums of two arrays are the same to a required precision def check_array_sum(array1, array2, tolerance_checksum): sum1 = np.sum(np.abs(array1)) sum2 = np.sum(np.abs(array2)) - assert(abs(sum2-sum1)/sum1 < tolerance_checksum) + assert abs(sum2 - sum1) / sum1 < tolerance_checksum + ## This function is specifically used to test the random filter. First, we check that the number of ## dumped particles is as expected. Next, we call the generic check_particle_filter function. def check_random_filter(fn, filtered_fn, random_fraction, dim, species_name): - ds = yt.load( fn ) - ds_filtered = yt.load( filtered_fn ) - ad = ds.all_data() - ad_filtered = ds_filtered.all_data() + ds = yt.load(fn) + ds_filtered = yt.load(filtered_fn) + ad = ds.all_data() + ad_filtered = ds_filtered.all_data() ## Check that the number of particles is as expected - numparts = ad[species_name, 'particle_id'].to_ndarray().shape[0] - numparts_filtered = ad_filtered['particle_id'].to_ndarray().shape[0] - expected_numparts_filtered = random_fraction*numparts + numparts = ad[species_name, "particle_id"].to_ndarray().shape[0] + numparts_filtered = ad_filtered["particle_id"].to_ndarray().shape[0] + expected_numparts_filtered = random_fraction * numparts # 5 sigma test that has an intrinsic probability to fail of 1 over ~2 millions std_numparts_filtered = np.sqrt(expected_numparts_filtered) - error = abs(numparts_filtered-expected_numparts_filtered) - print("Random filter: difference between expected and actual number of dumped particles: " \ - + str(error)) - print("tolerance: " + str(5*std_numparts_filtered)) - assert(error<5*std_numparts_filtered) + error = abs(numparts_filtered - expected_numparts_filtered) + print( + "Random filter: difference between expected and actual number of dumped particles: " + + str(error) + ) + print("tolerance: " + str(5 * std_numparts_filtered)) + assert error < 5 * std_numparts_filtered ## Dirty trick to find particles with the same ID + same CPU (does not work with more than 10 ## MPI ranks) - random_filter_expression = 'np.isin(ids + 0.1*cpus,' \ - 'ids_filtered_warpx + 0.1*cpus_filtered_warpx)' + random_filter_expression = ( + "np.isin(ids + 0.1*cpus," "ids_filtered_warpx + 0.1*cpus_filtered_warpx)" + ) check_particle_filter(fn, filtered_fn, random_filter_expression, dim, species_name) diff --git a/Regression/WarpX-GPU-tests.ini b/Regression/WarpX-GPU-tests.ini deleted file mode 100644 index a2447ac3cf5..00000000000 --- a/Regression/WarpX-GPU-tests.ini +++ /dev/null @@ -1,678 +0,0 @@ -# This file is used both for the nightly regression tests -# on the garunda server, and for CI tests. -# In the case of CI, some of the parameters entered -# below are overwritten, see prepare_file_ci.py -[main] -# repeat captured errors to stderr, e.g., for CI runs -verbose = 1 - -testTopDir = /home/regtester/RegTesting/rt-WarpX/ -webTopDir = /home/regtester/RegTesting/rt-WarpX/web - -sourceTree = C_Src - -# suiteName is the name prepended to all output directories -suiteName = WarpX-GPU - -COMP = g++ -add_to_c_make_command = TEST=TRUE USE_ASSERTION=TRUE WarpxBinDir= - -archive_output = 0 -purge_output = 1 - -MAKE = make -numMakeJobs = 8 - -# We build by default a few tools for output comparison. -# The build time for those can be skipped if they are not needed. -ftools = - -# Control the build of the particle_compare tool. -# Needed for test particle_tolerance option. -use_ctools = 0 - -# MPIcommand should use the placeholders: -# @host@ to indicate where to put the hostname to run on -# @nprocs@ to indicate where to put the number of processors -# @command@ to indicate where to put the command to run -# -# only tests with useMPI = 1 will run in parallel -# nprocs is problem dependent and specified in the individual problem -# sections. - -#MPIcommand = mpiexec -host @host@ -n @nprocs@ @command@ -MPIcommand = mpiexec -n @nprocs@ @command@ -MPIhost = - -reportActiveTestsOnly = 1 - -# Add "GO UP" link at the top of the web page? -goUpLink = 1 - -# string queried to change plotfiles and checkpoint files -plot_file_name = diag1.file_prefix -check_file_name = none - -# email -sendEmailWhenFail = 1 -emailTo = weiqunzhang@lbl.gov, jlvay@lbl.gov, rlehe@lbl.gov, atmyers@lbl.gov, mthevenet@lbl.gov, oshapoval@lbl.gov, ldianaamorim@lbl.gov, rjambunathan@lbl.gov, axelhuebl@lbl.gov, ezoni@lbl.gov -emailBody = Check https://ccse.lbl.gov/pub/GpuRegressionTesting/WarpX/ for more details. - -[AMReX] -dir = /home/regtester/git/amrex/ -branch = 0c3273f5e591815909180f8ffaf5b793cabbf9bc - -[source] -dir = /home/regtester/git/WarpX -branch = development - -[extra-PICSAR] -dir = /home/regtester/git/picsar/ -branch = 7b5449f92a4b30a095cc4a67f0a8b1fc69680e15 - -# individual problems follow - -[pml_x_yee] -buildDir = . -inputFile = Examples/Tests/pml/inputs_2d -runtime_params = warpx.do_dynamic_scheduling=0 algo.maxwell_solver=yee -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -analysisRoutine = Examples/Tests/pml/analysis_pml_yee.py - -[pml_x_ckc] -buildDir = . -inputFile = Examples/Tests/pml/inputs_2d -runtime_params = warpx.do_dynamic_scheduling=0 algo.maxwell_solver=ckc -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -analysisRoutine = Examples/Tests/pml/analysis_pml_ckc.py - -#[pml_x_psatd] -#buildDir = . -#inputFile = Examples/Tests/pml/inputs_2d -#runtime_params = algo.maxwell_solver=psatd warpx.do_dynamic_scheduling=0 -#dim = 2 -#addToCompileString = USE_FFT=TRUE USE_GPU=TRUE -#restartTest = 0 -#useMPI = 1 -#numprocs = 2 -#useOMP = 0 -#numthreads = 1 -#compileTest = 0 -#doVis = 0 -#analysisRoutine = Examples/Tests/pml/analysis_pml_psatd.py -# -[RigidInjection_lab] -buildDir = . -inputFile = Examples/Tests/RigidInjection/inputs_2d_LabFrame -runtime_params = -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -analysisRoutine = Examples/Tests/RigidInjection/analysis_rigid_injection_LabFrame.py - -[RigidInjection_boost_backtransformed] -buildDir = . -inputFile = Examples/Tests/RigidInjection/inputs_2d_BoostedFrame -runtime_params = -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -doComparison = 0 -aux1File = Tools/PostProcessing/read_raw_data.py -analysisRoutine = Examples/Tests/RigidInjection/analysis_rigid_injection_BoostedFrame.py - -[nci_corrector] -buildDir = . -inputFile = Examples/Tests/nci_fdtd_stability/inputs_2d -runtime_params = amr.max_level=0 particles.use_fdtd_nci_corr=1 -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -doComparison = 0 -analysisRoutine = Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py - -# [nci_correctorMR] -# buildDir = . -# inputFile = Examples/Tests/nci_fdtd_stability/inputs_2d -# runtime_params = amr.max_level=1 particles.use_fdtd_nci_corr=1 -# dim = 2 -# addToCompileString = USE_GPU=TRUE -# restartTest = 0 -# useMPI = 1 -# numprocs = 2 -# useOMP = 0 -# numthreads = 1 -# compileTest = 0 -# doVis = 0 -# doComparison = 0 -# analysisRoutine = Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py -# -# [ionization_lab] -# buildDir = . -# inputFile = Examples/Tests/ionization/inputs_2d_rt -# runtime_params = -# dim = 2 -# addToCompileString = USE_GPU=TRUE -# restartTest = 0 -# useMPI = 1 -# numprocs = 2 -# useOMP = 0 -# numthreads = 1 -# compileTest = 0 -# doVis = 0 -# analysisRoutine = Examples/Tests/ionization/analysis_ionization.py -# -# [ionization_boost] -# buildDir = . -# inputFile = Examples/Tests/ionization/inputs_2d_bf_rt -# runtime_params = -# dim = 2 -# addToCompileString = USE_GPU=TRUE -# restartTest = 0 -# useMPI = 1 -# numprocs = 2 -# useOMP = 0 -# numthreads = 1 -# compileTest = 0 -# doVis = 0 -# analysisRoutine = Examples/Tests/ionization/analysis_ionization.py -# -[bilinear_filter] -buildDir = . -inputFile = Examples/Tests/single_particle/inputs_2d -runtime_params = warpx.use_filter=1 warpx.filter_npass_each_dir=1 5 -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -analysisRoutine = Examples/Tests/single_particle/analysis_bilinear_filter.py - -[Langmuir_2d] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_rt -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons -runtime_params = electrons.ux=0.01 electrons.xmax=0.e-6 diag1.fields_to_plot=Ex jx diag1.electrons.variables=w ux -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir2d.py -analysisOutputImage = langmuir2d_analysis.png - -[Langmuir_2d_single_precision] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_rt -runtime_params = electrons.ux=0.01 electrons.xmax=0.e-6 diag1.fields_to_plot=Ex jx diag1.electrons.variables=w ux -dim = 2 -addToCompileString = USE_GPU=TRUE PRECISION=FLOAT USE_SINGLE_PRECISION_PARTICLES=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir2d.py -analysisOutputImage = langmuir2d_analysis.png - -[Langmuir_2d_nompi] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_rt -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 0 -numprocs = 1 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons -runtime_params = electrons.ux=0.01 electrons.xmax=0.e-6 diag1.fields_to_plot=Ex jx diag1.electrons.variables=w ux -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir2d.py -analysisOutputImage = langmuir2d_analysis.png - -[Langmuir_x] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_rt -dim = 3 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 4 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons -runtime_params = electrons.ux=0.01 electrons.xmax=0.e-6 warpx.do_dynamic_scheduling=0 diag1.fields_to_plot = Ex jx diag1.electrons.variables=w ux -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir.py -analysisOutputImage = langmuir_x_analysis.png - -[Langmuir_y] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_rt -dim = 3 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 4 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons -runtime_params = electrons.uy=0.01 electrons.ymax=0.e-6 warpx.do_dynamic_scheduling=0 diag1.fields_to_plot = Ey jy diag1.electrons.variables=w uy -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir.py -analysisOutputImage = langmuir_y_analysis.png - -[Langmuir_z] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_rt -dim = 3 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 4 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons -runtime_params = electrons.uz=0.01 electrons.zmax=0.e-6 warpx.do_dynamic_scheduling=0 diag1.fields_to_plot = Ez jz diag1.electrons.variables=w uz -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir.py -analysisOutputImage = langmuir_z_analysis.png - -[Langmuir_multi] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_multi_rt -dim = 3 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 4 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -runtime_params = warpx.do_dynamic_scheduling=0 -particleTypes = electrons positrons -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir_multi.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_multi_rt -dim = 3 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 4 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -runtime_params = warpx.do_dynamic_scheduling=0 warpx.grid_type=collocated algo.current_deposition=direct -particleTypes = electrons positrons -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir_multi.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_multi_rt -runtime_params = algo.maxwell_solver=psatd warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons positrons -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir_multi.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d_multi_rt -runtime_params = algo.maxwell_solver=psatd warpx.do_dynamic_scheduling=0 warpx.grid_type=collocated algo.current_deposition=direct warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons positrons -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir_multi.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_2d_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d_multi_rt -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 4 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -runtime_params = warpx.grid_type=collocated algo.current_deposition=direct diag1.electrons.variables=w ux uy uz diag1.positrons.variables=w ux uy uz -particleTypes = electrons positrons -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir_multi_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d_multi_rt -runtime_params = algo.maxwell_solver=psatd diag1.electrons.variables=w ux uy uz diag1.positrons.variables=w ux uy uz diag1.fields_to_plot=Ex Ey Ez jx jy jz part_per_cell warpx.cfl = 0.7071067811865475 -dim = 2 -addToCompileString = USE_FFT=TRUE USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons positrons -analysisRoutine = Examples/Tests/langmuir/analysis_langmuir_multi_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -# [Langmuir_multi_2d_psatd_nodal] -# buildDir = . -# inputFile = Examples/Tests/langmuir/inputs_2d_multi_rt -# runtime_params = algo.maxwell_solver=psatd warpx.grid_type=collocated algo.current_deposition=direct diag1.electrons.variables=w ux uy uz diag1.positrons.variables=w ux uy uz diag1.fields_to_plot=Ex Ey Ez jx jy jz part_per_cell -# dim = 2 -# addToCompileString = USE_FFT=TRUE USE_GPU=TRUE -# restartTest = 0 -# useMPI = 1 -# numprocs = 4 -# useOMP = 0 -# numthreads = 1 -# compileTest = 0 -# doVis = 0 -# compareParticles = 0 -# particleTypes = electrons positrons -# analysisRoutine = Examples/Tests/langmuir/analysis_langmuir_multi_2d.py -# analysisOutputImage = langmuir_multi_2d_analysis.png -# -# [Langmuir_multi_rz] -# buildDir = . -# inputFile = Examples/Tests/langmuir/inputs_2d_multi_rz_rt -# dim = 2 -# addToCompileString = USE_RZ=TRUE USE_GPU=TRUE -# restartTest = 0 -# useMPI = 1 -# numprocs = 4 -# useOMP = 0 -# numthreads = 1 -# compileTest = 0 -# doVis = 0 -# runtime_params = diag1.electrons.variables=w ux uy uz diag1.ions.variables=w ux uy uz -# compareParticles = 0 -# particleTypes = electrons ions -# analysisRoutine = Examples/Tests/langmuir/analysis_langmuir_multi_rz.py -# analysisOutputImage = langmuir_multi_rz_analysis.png -# -# [Langmuir_rz_multimode] -# buildDir = . -# inputFile = Examples/Tests/langmuir/PICMI_inputs_langmuir_rz_multimode_analyze.py -# customRunCmd = python PICMI_inputs_langmuir_rz_multimode_analyze.py -# runtime_params = -# dim = 2 -# addToCompileString = USE_PYTHON_MAIN=TRUE USE_RZ=TRUE USE_GPU=TRUE PYINSTALLOPTIONS="--user --prefix=" -# restartTest = 0 -# useMPI = 1 -# numprocs = 4 -# useOMP = 0 -# numthreads = 1 -# compileTest = 0 -# doVis = 0 -# compareParticles = 0 -# particleTypes = electrons protons -# outputFile = diags/plotfiles/plt00040 -# -[LaserInjection] -buildDir = . -inputFile = Examples/Tests/laser_injection/inputs_3d_rt -dim = 3 -runtime_params = max_step=20 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 4 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -analysisRoutine = Examples/Tests/laser_injection/analysis_laser.py -analysisOutputImage = laser_analysis.png - -[LaserInjection_2d] -buildDir = . -inputFile = Examples/Tests/laser_injection/inputs_2d_rt -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -runtime_params = warpx.do_dynamic_scheduling=0 warpx.serialize_initial_conditions=1 -compareParticles = 0 - -#xxxxx -#[LaserAcceleration] -#buildDir = . -#inputFile = Examples/Physics_applications/laser_acceleration/inputs_3d -#runtime_params = warpx.do_dynamic_scheduling=0 amr.n_cell=32 32 256 max_step=100 electrons.zmin=0.e-6 warpx.serialize_initial_conditions=1 -#dim = 3 -#addToCompileString = USE_GPU=TRUE -#restartTest = 0 -#useMPI = 1 -#numprocs = 2 -#useOMP = 0 -#numthreads = 1 -#compileTest = 0 -#doVis = 0 -#compareParticles = 0 -#particleTypes = electrons -# -[subcyclingMR] -buildDir = . -inputFile = Examples/Tests/subcycling/inputs_2d -runtime_params = warpx.serialize_initial_conditions=1 warpx.do_dynamic_scheduling=0 -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 - -[LaserAccelerationMR] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_2d -runtime_params = amr.max_level=1 max_step=200 warpx.serialize_initial_conditions=1 warpx.fine_tag_lo=-5.e-6 -35.e-6 warpx.fine_tag_hi=5.e-6 -25.e-6 -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons beam - -[PlasmaAccelerationMR] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/inputs_2d -runtime_params = amr.max_level=1 amr.n_cell=32 512 max_step=400 warpx.serialize_initial_conditions=1 warpx.do_dynamic_scheduling=0 -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = beam driver plasma_e - -[Python_Langmuir] -buildDir = . -inputFile = Examples/Tests/langmuir/PICMI_inputs_langmuir_rt.py -customRunCmd = python PICMI_inputs_langmuir_rt.py -runtime_params = -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_GPU=TRUE PYINSTALLOPTIONS="--user --prefix=" -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons -outputFile = diags/diag200040 - -[uniform_plasma_restart] -buildDir = . -inputFile = Examples/Physics_applications/uniform_plasma/inputs_3d -runtime_params = chk.file_prefix=uniform_plasma_restart_chk -dim = 3 -addToCompileString = USE_GPU=TRUE -restartTest = 1 -restartFileNum = 6 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -particleTypes = electrons - -[particles_in_pml_2d] -buildDir = . -inputFile = Examples/Tests/particles_in_pml/inputs_2d -runtime_params = -dim = 2 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -analysisRoutine = Examples/Tests/particles_in_pml/analysis_particles_in_pml.py - -[particles_in_pml] -buildDir = . -inputFile = Examples/Tests/particles_in_pml/inputs_3d -runtime_params = -dim = 3 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -analysisRoutine = Examples/Tests/particles_in_pml/analysis_particles_in_pml.py - -[photon_pusher] -buildDir = . -inputFile = Examples/Tests/photon_pusher/inputs_3d -runtime_params = -dim = 3 -addToCompileString = USE_GPU=TRUE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -compileTest = 0 -doVis = 0 -compareParticles = 0 -analysisRoutine = Examples/Tests/photon_pusher/analysis_photon_pusher.py diff --git a/Regression/WarpX-tests.ini b/Regression/WarpX-tests.ini deleted file mode 100644 index 17ecfd64f29..00000000000 --- a/Regression/WarpX-tests.ini +++ /dev/null @@ -1,3981 +0,0 @@ -# This file is used both for the nightly regression tests -# on the battra server, and for CI tests. -# In the case of CI, some of the parameters entered -# below are overwritten, see prepare_file_ci.py -[main] -# repeat captured errors to stderr, e.g., for CI runs -verbose = 1 - -testTopDir = /home/regtester/AMReX_RegTesting/rt-WarpX/ -webTopDir = /home/regtester/AMReX_RegTesting/rt-WarpX/web - -sourceTree = C_Src - -# suiteName is the name prepended to all output directories -suiteName = WarpX - -archive_output = 0 -purge_output = 1 - -useCmake = 1 -isSuperbuild = 1 -MAKE = make -numMakeJobs = 8 - -# We build by default a few tools for output comparison. -# The build time for those can be skipped if they are not needed. -ftools = - -# Control the build of the particle_compare tool. -# Needed for test particle_tolerance option. -use_ctools = 0 - -# MPIcommand should use the placeholders: -# @host@ to indicate where to put the hostname to run on -# @nprocs@ to indicate where to put the number of processors -# @command@ to indicate where to put the command to run -# -# only tests with useMPI = 1 will run in parallel -# nprocs is problem dependent and specified in the individual problem -# sections. - -#MPIcommand = mpiexec -host @host@ -n @nprocs@ @command@ -MPIcommand = mpiexec -n @nprocs@ @command@ -MPIhost = - -reportActiveTestsOnly = 1 - -# Add "GO UP" link at the top of the web page? -goUpLink = 1 - -# string queried to change plotfiles and checkpoint files -plot_file_name = diag1.file_prefix -check_file_name = none - -# email -sendEmailWhenFail = 1 -emailTo = weiqunzhang@lbl.gov, jlvay@lbl.gov, rlehe@lbl.gov, atmyers@lbl.gov, oshapoval@lbl.gov, henri.vincenti@cea.fr, rjambunathan@lbl.gov, yinjianzhao@lbl.gov -emailBody = Check https://ccse.lbl.gov/pub/RegressionTesting/WarpX/ for more details. - -[AMReX] -dir = /home/regtester/AMReX_RegTesting/amrex/ -branch = 0c3273f5e591815909180f8ffaf5b793cabbf9bc - -[source] -dir = /home/regtester/AMReX_RegTesting/warpx -branch = development -cmakeSetupOpts = -DAMReX_ASSERTIONS=ON -DAMReX_TESTING=ON -DWarpX_PYTHON_IPO=OFF -DpyAMReX_IPO=OFF -# -DPYINSTALLOPTIONS="--disable-pip-version-check" - -# individual problems follow - -[averaged_galilean_2d_psatd] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_avg_2d -runtime_params = psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[averaged_galilean_2d_psatd_hybrid] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_avg_2d -runtime_params = amr.max_grid_size_x=128 amr.max_grid_size_y=64 warpx.grid_type=hybrid psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[averaged_galilean_3d_psatd] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_avg_3d -runtime_params = psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[averaged_galilean_3d_psatd_hybrid] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_avg_3d -runtime_params = warpx.grid_type=hybrid psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[background_mcc] -buildDir = . -inputFile = Examples/Physics_applications/capacitive_discharge/inputs_2d -runtime_params = warpx.abort_on_warning_threshold = high -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[background_mcc_dp_psp] -buildDir = . -inputFile = Examples/Physics_applications/capacitive_discharge/inputs_2d -runtime_params = warpx.abort_on_warning_threshold = high -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_PRECISION=DOUBLE -DWarpX_PARTICLE_PRECISION=SINGLE -DWarpX_QED=OFF -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[bilinear_filter] -buildDir = . -inputFile = Examples/Tests/single_particle/inputs_2d -runtime_params = warpx.use_filter=1 warpx.filter_npass_each_dir=1 5 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/single_particle/analysis_bilinear_filter.py - -[BTD_rz] -buildDir = . -inputFile = Examples/Tests/btd_rz/inputs_rz_z_boosted_BTD -runtime_params = -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/btd_rz/analysis_BTD_laser_antenna.py - -[collider_diagnostics] -buildDir = . -inputFile = Examples/Tests/collider_relevant_diags/inputs_3d_multiple_particles -runtime_params = warpx.abort_on_warning_threshold=high -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/collider_relevant_diags/analysis_multiple_particles.py - -[collisionISO] -buildDir = . -inputFile = Examples/Tests/collision/inputs_3d_isotropization -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/collision/analysis_collision_3d_isotropization.py -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[collisionRZ] -buildDir = . -inputFile = Examples/Tests/collision/inputs_rz -runtime_params = -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=FALSE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=OFF -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/collision/analysis_collision_rz.py -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[collisionXYZ] -buildDir = . -inputFile = Examples/Tests/collision/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/collision/analysis_collision_3d.py -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[collisionXZ] -buildDir = . -inputFile = Examples/Tests/collision/inputs_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/collision/analysis_collision_2d.py -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[comoving_2d_psatd_hybrid] -buildDir = . -inputFile = Examples/Tests/comoving/inputs_2d_hybrid -runtime_params = psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Deuterium_Deuterium_Fusion_3D] -buildDir = . -inputFile = Examples/Tests/nuclear_fusion/inputs_deuterium_deuterium_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nuclear_fusion/analysis_two_product_fusion.py - -[Deuterium_Deuterium_Fusion_3D_intraspecies] -buildDir = . -inputFile = Examples/Tests/nuclear_fusion/inputs_deuterium_deuterium_3d_intraspecies -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nuclear_fusion/analysis_deuterium_deuterium_3d_intraspecies.py - -[Deuterium_Tritium_Fusion_3D] -buildDir = . -inputFile = Examples/Tests/nuclear_fusion/inputs_deuterium_tritium_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nuclear_fusion/analysis_two_product_fusion.py - -[Deuterium_Tritium_Fusion_RZ] -buildDir = . -inputFile = Examples/Tests/nuclear_fusion/inputs_deuterium_tritium_rz -runtime_params = warpx.abort_on_warning_threshold=high -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nuclear_fusion/analysis_two_product_fusion.py - -[dirichletbc] -buildDir = . -inputFile = Examples/Tests/electrostatic_dirichlet_bc/inputs_2d -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_dirichlet_bc/analysis.py - -[divb_cleaning_3d] -buildDir = . -inputFile = Examples/Tests/divb_cleaning/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/divb_cleaning/analysis.py - -[dive_cleaning_2d] -buildDir = . -inputFile = Examples/Tests/dive_cleaning/inputs_3d -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -runtime_params = geometry.dims=2 -analysisRoutine = Examples/Tests/dive_cleaning/analysis.py -analysisOutputImage = Comparison.png - -[dive_cleaning_3d] -buildDir = . -inputFile = Examples/Tests/dive_cleaning/inputs_3d -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -runtime_params = -analysisRoutine = Examples/Tests/dive_cleaning/analysis.py -analysisOutputImage = Comparison.png - -[ElectrostaticSphere] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere/inputs_3d -runtime_params = warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py - -[ElectrostaticSphereLabFrame_MR_emass_10] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere/inputs_3d -runtime_params = warpx.do_electrostatic=labframe diag2.electron.variables=x y z ux uy uz w warpx.abort_on_warning_threshold=medium electron.mass = 10 amr.max_level = 1 amr.ref_ratio_vect = 2 2 2 warpx.fine_tag_lo = -0.5 -0.5 -0.5 warpx.fine_tag_hi = 0.5 0.5 0.5 max_step = 2 -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py - -[ElectrostaticSphereEB] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere_eb/inputs_3d -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere_eb/analysis.py - -[ElectrostaticSphereEB_mixedBCs] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere_eb/inputs_3d_mixed_BCs -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[EmbeddedBoundaryDiffraction] -buildDir = . -inputFile = Examples/Tests/embedded_boundary_diffraction/inputs_rz -runtime_params = -dim = 2 -addToCompileString = USE_EB=TRUE USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = EmbeddedBoundaryDiffraction_plt -analysisRoutine = Examples/Tests/embedded_boundary_diffraction/analysis_fields.py - -[ElectrostaticSphereEB_RZ] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere_eb/inputs_rz -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 2 -addToCompileString = USE_EB=TRUE USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere_eb/analysis_rz.py - -[ElectrostaticSphereEB_RZ_MR] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere_eb/inputs_rz_mr -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 2 -addToCompileString = USE_EB=TRUE USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere_eb/analysis_rz.py - -[ElectrostaticSphereLabFrame] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere/inputs_3d -runtime_params = warpx.do_electrostatic=labframe diag2.electron.variables=x y z ux uy uz w phi -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py - -[ElectrostaticSphereRZ] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere/inputs_rz -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py - -[ElectrostaticSphereRelNodal] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere/inputs_3d -runtime_params = warpx.abort_on_warning_threshold = medium warpx.grid_type = collocated -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py - -[embedded_boundary_cube] -buildDir = . -inputFile = Examples/Tests/embedded_boundary_cube/inputs_3d -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/embedded_boundary_cube/analysis_fields.py - -[embedded_boundary_cube_2d] -buildDir = . -inputFile = Examples/Tests/embedded_boundary_cube/inputs_2d -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 2 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/embedded_boundary_cube/analysis_fields_2d.py - -[embedded_boundary_cube_macroscopic] -buildDir = . -inputFile = Examples/Tests/embedded_boundary_cube/inputs_3d -runtime_params = algo.em_solver_medium=macroscopic macroscopic.epsilon=1.5*8.8541878128e-12 macroscopic.sigma=0 macroscopic.mu=1.25663706212e-06 warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/embedded_boundary_cube/analysis_fields.py - -[embedded_boundary_python_API] -buildDir = . -inputFile = Examples/Tests/embedded_boundary_python_api/PICMI_inputs_EB_API.py -runtime_params = -customRunCmd = python PICMI_inputs_EB_API.py -dim = 3 -addToCompileString = USE_EB=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/embedded_boundary_python_api/analysis.py - -[embedded_boundary_rotated_cube] -buildDir = . -inputFile = Examples/Tests/embedded_boundary_rotated_cube/inputs_3d -runtime_params = warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/embedded_boundary_rotated_cube/analysis_fields.py - -[embedded_boundary_rotated_cube_2d] -buildDir = . -inputFile = Examples/Tests/embedded_boundary_rotated_cube/inputs_2d -runtime_params = warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/embedded_boundary_rotated_cube/analysis_fields_2d.py - -[embedded_circle] -buildDir = . -inputFile = Examples/Tests/embedded_circle/inputs_2d -runtime_params = warpx.abort_on_warning_threshold = high -dim = 2 -addToCompileString = USE_EB=TRUE USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_EB=ON -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/embedded_circle/analysis.py - -[FieldProbe] -buildDir = . -inputFile = Examples/Tests/field_probe/inputs_2d -runtime_params = -dim = 2 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/field_probe/analysis_field_probe.py - -[FluxInjection] -buildDir = . -inputFile = Examples/Tests/flux_injection/inputs_rz -runtime_params = warpx.abort_on_warning_threshold = high -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/flux_injection/analysis_flux_injection_rz.py - -[FluxInjection3D] -buildDir = . -inputFile = Examples/Tests/flux_injection/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/flux_injection/analysis_flux_injection_3d.py - -[galilean_2d_psatd] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_2d -runtime_params = warpx.grid_type=collocated algo.current_deposition=direct psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[galilean_2d_psatd_current_correction] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_2d -runtime_params = psatd.periodic_single_box_fft=0 psatd.update_with_rho=0 psatd.current_correction=1 diag1.fields_to_plot=Ex Ey Ez Bx By Bz jx jy jz rho divE amr.max_grid_size=64 amr.blocking_factor=64 -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[galilean_2d_psatd_current_correction_psb] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_2d -runtime_params = psatd.periodic_single_box_fft=1 psatd.update_with_rho=0 psatd.current_correction=1 diag1.fields_to_plot=Ex Ey Ez Bx By Bz jx jy jz rho divE -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[galilean_2d_psatd_hybrid] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_2d_hybrid -runtime_params = psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[galilean_3d_psatd] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_3d -runtime_params = psatd.v_galilean=0. 0. 0.99498743710662 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[galilean_3d_psatd_current_correction] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_3d -runtime_params = psatd.v_galilean=0. 0. 0.99498743710662 warpx.numprocs=1 1 2 psatd.periodic_single_box_fft=0 psatd.update_with_rho=0 psatd.current_correction=1 diag1.fields_to_plot=Ex Ey Ez Bx By Bz jx jy jz rho divE -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[galilean_3d_psatd_current_correction_psb] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_3d -runtime_params = psatd.v_galilean=0. 0. 0.99498743710662 warpx.numprocs=1 1 1 psatd.periodic_single_box_fft=1 psatd.update_with_rho=0 psatd.current_correction=1 diag1.fields_to_plot=Ex Ey Ez Bx By Bz jx jy jz rho divE -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[galilean_rz_psatd] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_rz -runtime_params = electrons.random_theta=0 ions.random_theta=0 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=TRUE BLAS_LIB=-lblas LAPACK_LIB=-llapack -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[galilean_rz_psatd_current_correction_psb] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_rz -runtime_params = psatd.periodic_single_box_fft=1 psatd.current_correction=1 electrons.random_theta=0 ions.random_theta=0 -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=TRUE BLAS_LIB=-lblas LAPACK_LIB=-llapack -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[galilean_rz_psatd_current_correction] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_rz -runtime_params = psatd.periodic_single_box_fft=0 psatd.current_correction=1 electrons.random_theta=0 ions.random_theta=0 amr.max_grid_size=32 amr.blocking_factor=32 -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=TRUE BLAS_LIB=-lblas LAPACK_LIB=-llapack -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_galilean.py - -[hard_edged_plasma_lens] -buildDir = . -inputFile = Examples/Tests/plasma_lens/inputs_lattice_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/plasma_lens/analysis.py - -[hard_edged_quadrupoles] -buildDir = . -inputFile = Examples/Tests/AcceleratorLattice/inputs_quad_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/AcceleratorLattice/analysis.py - -[hard_edged_quadrupoles_boosted] -buildDir = . -inputFile = Examples/Tests/AcceleratorLattice/inputs_quad_boosted_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/AcceleratorLattice/analysis.py - -[hard_edged_quadrupoles_moving] -buildDir = . -inputFile = Examples/Tests/AcceleratorLattice/inputs_quad_moving_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/AcceleratorLattice/analysis.py - -[initial_distribution] -buildDir = . -inputFile = Examples/Tests/initial_distribution/inputs -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/initial_distribution/analysis_distribution.py -aux1File = Tools/PostProcessing/read_raw_data.py - -[ionization_boost] -buildDir = . -inputFile = Examples/Tests/ionization/inputs_2d_bf_rt -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ionization/analysis_ionization.py - -[ionization_lab] -buildDir = . -inputFile = Examples/Tests/ionization/inputs_2d_rt -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ionization/analysis_ionization.py - -[ion_stopping] -buildDir = . -inputFile = Examples/Tests/ion_stopping/inputs_3d -runtime_params = warpx.cfl=0.7 -dim = 3 -addToCompileString = -cmakeSetupOpts = -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ion_stopping/analysis_ion_stopping.py - -[Langmuir_multi] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_fluid_1D] -buildDir = . -inputFile = Examples/Tests/langmuir_fluids/inputs_1d -runtime_params = -dim = 1 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=1 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir_fluids/analysis_1d.py -analysisOutputImage = langmuir_fluid_multi_1d_analysis.png - -[Langmuir_fluid_RZ] -buildDir = . -inputFile = Examples/Tests/langmuir_fluids/inputs_rz -runtime_params = -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir_fluids/analysis_rz.py -analysisOutputImage = langmuir_fluid_rz_analysis.png - -[Langmuir_fluid_2D] -buildDir = . -inputFile = Examples/Tests/langmuir_fluids/inputs_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir_fluids/analysis_2d.py -analysisOutputImage = langmuir_fluid_multi_2d_analysis.png - -[Langmuir_fluid_multi] -buildDir = . -inputFile = Examples/Tests/langmuir_fluids/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir_fluids/analysis_3d.py -analysisOutputImage = langmuir_fluid_multi_analysis.png - -[Langmuir_multi_1d] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_1d -runtime_params = algo.current_deposition=esirkepov diag1.electrons.variables=z w ux uy uz diag1.positrons.variables=z w ux uy uz -dim = 1 -addToCompileString = USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_1d.py -analysisOutputImage = langmuir_multi_1d_analysis.png - -[Langmuir_multi_2d_MR] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver = ckc warpx.use_filter = 1 amr.max_level = 1 amr.ref_ratio = 4 warpx.fine_tag_lo = -10.e-6 -10.e-6 warpx.fine_tag_hi = 10.e-6 10.e-6 diag1.electrons.variables = x z w ux uy uz diag1.positrons.variables = x z w ux uy uz -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = Langmuir_multi_2d_MR.png - -[Langmuir_multi_2d_MR_anisotropic] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver = ckc warpx.use_filter = 1 amr.max_level = 1 amr.ref_ratio_vect = 4 2 warpx.fine_tag_lo = -10.e-6 -10.e-6 warpx.fine_tag_hi = 10.e-6 10.e-6 diag1.electrons.variables = x z w ux uy uz diag1.positrons.variables = x z w ux uy uz -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = Langmuir_multi_2d_MR.png - -[Langmuir_multi_2d_MR_momentum_conserving] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=ckc warpx.use_filter=1 amr.max_level=1 amr.ref_ratio=4 warpx.fine_tag_lo=-10.e-6 -10.e-6 warpx.fine_tag_hi=10.e-6 10.e-6 algo.field_gathering=momentum-conserving diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = Langmuir_multi_2d_MR_momentum_conserving.png - -[Langmuir_multi_2d_MR_psatd] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver = psatd warpx.use_filter = 1 amr.max_level = 1 amr.ref_ratio = 4 warpx.fine_tag_lo = -10.e-6 -10.e-6 warpx.fine_tag_hi = 10.e-6 10.e-6 diag1.electrons.variables = x z w ux uy uz diag1.positrons.variables = x z w ux uy uz psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = Langmuir_multi_2d_MR_psatd.png - -[Langmuir_multi_2d_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = warpx.grid_type=collocated algo.current_deposition=direct diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot=Ex Ey Ez jx jy jz part_per_cell warpx.cfl = 0.7071067811865475 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd_current_correction] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 algo.current_deposition=esirkepov psatd.periodic_single_box_fft=1 psatd.current_correction=1 diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot =Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd_current_correction_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 algo.current_deposition=direct psatd.periodic_single_box_fft=1 psatd.current_correction=1 warpx.grid_type=collocated diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot =Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd_momentum_conserving] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd algo.field_gathering=momentum-conserving diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot=Ex Ey Ez jx jy jz part_per_cell warpx.cfl = 0.7071067811865475 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd_multiJ] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd warpx.cfl=0.7071067811865475 psatd.update_with_rho=1 warpx.do_multi_J=1 warpx.do_multi_J_n_depositions=2 psatd.solution_type=first-order psatd.J_in_time=linear warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = Langmuir_multi_2d_psatd_multiJ.png - -[Langmuir_multi_2d_psatd_multiJ_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd warpx.cfl=0.7071067811865475 psatd.update_with_rho=1 warpx.do_multi_J=1 warpx.do_multi_J_n_depositions=2 psatd.solution_type=first-order psatd.J_in_time=linear warpx.abort_on_warning_threshold=medium warpx.grid_type=collocated -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = Langmuir_multi_2d_psatd_multiJ_nodal.png - -[Langmuir_multi_2d_psatd_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd warpx.grid_type=collocated algo.current_deposition=direct diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot=Ex Ey Ez jx jy jz part_per_cell warpx.cfl = 0.7071067811865475 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd_Vay_deposition] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 algo.current_deposition=vay diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd_Vay_deposition_particle_shape_4] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 algo.current_deposition=vay diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 algo.particle_shape=4 -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_2d_psatd_Vay_deposition_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d -runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 warpx.grid_type=collocated algo.current_deposition=vay diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_2d.py -analysisOutputImage = langmuir_multi_2d_analysis.png - -[Langmuir_multi_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = warpx.grid_type=collocated algo.current_deposition=direct -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_current_correction] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd algo.current_deposition=esirkepov psatd.periodic_single_box_fft=1 psatd.current_correction=1 diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz part_per_cell rho divE warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_current_correction_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd algo.current_deposition=direct psatd.periodic_single_box_fft=1 psatd.current_correction=1 warpx.grid_type=collocated diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz part_per_cell rho divE warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_div_cleaning] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd warpx.cfl = 0.5773502691896258 psatd.update_with_rho = 1 algo.current_deposition = direct warpx.do_dive_cleaning = 1 warpx.do_divb_cleaning = 1 diag1.intervals = 0, 38:40:1 diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz part_per_cell rho divE F warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_momentum_conserving] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd algo.field_gathering=momentum-conserving warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_multiJ] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd warpx.cfl=0.5773502691896258 algo.current_deposition=direct psatd.update_with_rho=1 warpx.do_multi_J=1 warpx.do_multi_J_n_depositions=2 psatd.solution_type=first-order psatd.J_in_time=linear warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = Langmuir_multi_psatd_multiJ.png - -[Langmuir_multi_psatd_multiJ_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd warpx.cfl=0.5773502691896258 algo.current_deposition=direct psatd.update_with_rho=1 warpx.do_multi_J=1 warpx.do_multi_J_n_depositions=2 psatd.solution_type=first-order psatd.J_in_time=linear warpx.abort_on_warning_threshold=medium warpx.grid_type=collocated -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = Langmuir_multi_psatd_multiJ_nodal.png - -[Langmuir_multi_psatd_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd warpx.grid_type=collocated algo.current_deposition=direct warpx.cfl = 0.5773502691896258 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_single_precision] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE PRECISION=FLOAT USE_SINGLE_PRECISION_PARTICLES=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -DWarpX_PRECISION=SINGLE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_Vay_deposition] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd algo.current_deposition=vay diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_psatd_Vay_deposition_nodal] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = algo.maxwell_solver=psatd warpx.grid_type=collocated algo.current_deposition=vay diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.5773502691896258 -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Langmuir_multi_rz] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_rz -runtime_params = diag1.electrons.variables=x y z w ux uy uz diag1.ions.variables=x y z w ux uy uz diag1.dump_rz_modes=0 -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_rz.py -analysisOutputImage = Langmuir_multi_rz_analysis.png -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[Langmuir_multi_rz_psatd] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_rz -runtime_params = algo.maxwell_solver=psatd diag1.electrons.variables=x y z w ux uy uz diag1.ions.variables=x y z w ux uy uz diag1.dump_rz_modes=0 algo.current_deposition=direct warpx.do_dive_cleaning=0 psatd.update_with_rho=1 electrons.random_theta=0 ions.random_theta=0 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=TRUE BLAS_LIB=-lblas LAPACK_LIB=-llapack -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_rz.py -analysisOutputImage = Langmuir_multi_rz_psatd_analysis.png -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[Langmuir_multi_rz_psatd_current_correction] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_rz -runtime_params = algo.maxwell_solver=psatd diag1.electrons.variables=x y z w ux uy uz diag1.ions.variables=x y z w ux uy uz diag1.dump_rz_modes=0 algo.current_deposition=direct warpx.do_dive_cleaning=0 amr.max_grid_size=128 psatd.periodic_single_box_fft=1 psatd.current_correction=1 diag1.fields_to_plot=jr jz Er Ez Bt rho divE electrons.random_theta=0 ions.random_theta=0 -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=TRUE BLAS_LIB=-lblas LAPACK_LIB=-llapack -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_rz.py -analysisOutputImage = Langmuir_multi_rz_psatd_analysis.png -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[Langmuir_multi_rz_psatd_multiJ] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_rz -runtime_params = amr.max_grid_size=32 algo.maxwell_solver=psatd diag1.electrons.variables=x y z w ux uy uz diag1.ions.variables=x y z w ux uy uz diag1.dump_rz_modes=0 algo.current_deposition=direct warpx.do_dive_cleaning=0 psatd.update_with_rho=1 warpx.n_rz_azimuthal_modes=2 electrons.random_theta=0 electrons.num_particles_per_cell_each_dim=2 4 2 ions.random_theta=0 ions.num_particles_per_cell_each_dim=2 4 2 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium warpx.do_multi_J=1 warpx.do_multi_J_n_depositions=4 warpx.use_filter=1 -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=TRUE BLAS_LIB=-lblas LAPACK_LIB=-llapack -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_rz.py -analysisOutputImage = Langmuir_multi_rz_psatd_multiJ_analysis.png -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[Langmuir_multi_single_precision] -buildDir = . -inputFile = Examples/Tests/langmuir/inputs_3d -runtime_params = -dim = 3 -addToCompileString = PRECISION=FLOAT USE_SINGLE_PRECISION_PARTICLES=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_PRECISION=SINGLE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/langmuir/analysis_3d.py -analysisOutputImage = langmuir_multi_analysis.png - -[Larmor] -buildDir = . -inputFile = Examples/Tests/larmor/inputs_2d_mr -runtime_params = max_step=10 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[LaserAcceleration] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = LaserAcceleration_plt -analysisRoutine = Examples/analysis_default_openpmd_regression.py - -[LaserAcceleration_1d] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_1d -runtime_params = -dim = 1 -addToCompileString = USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[LaserAcceleration_1d_fluid] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_1d_fluids -runtime_params = -dim = 1 -addToCompileString = USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Physics_applications/laser_acceleration/analysis_1d_fluids.py - -[LaserAcceleration_1d_fluid_boosted] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_1d_fluids_boosted -runtime_params = -dim = 1 -addToCompileString = USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Physics_applications/laser_acceleration/analysis_1d_fluids_boosted.py - -[LaserAccelerationBoost] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_2d_boost -runtime_params = amr.n_cell=64 512 max_step=300 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[LaserAcceleration_BTD] -buildDir = . -inputFile = Examples/Tests/boosted_diags/inputs_3d -runtime_params = -dim = 3 -addToCompileString = USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/boosted_diags/analysis.py - -[LaserAccelerationMR] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[LaserAccelerationRZ] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_rz -runtime_params = diag1.dump_rz_modes=1 warpx.abort_on_warning_threshold=high -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[LaserAccelerationRZ_opmd] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_rz -runtime_params = diag1.format=openpmd diag1.openpmd_backend=h5 max_step=20 diag1.fields_to_plot=Er Bt Bz jr jt jz rho part_per_cell part_per_grid rho_beam rho_electrons warpx.abort_on_warning_threshold=high -dim = 2 -addToCompileString = USE_RZ=TRUE USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = LaserAccelerationRZ_opmd_plt -analysisRoutine = Examples/Tests/openpmd_rz/analysis_openpmd_rz.py - -[LaserAcceleration_single_precision_comms] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_3d -runtime_params = warpx.do_single_precision_comms=1 -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = LaserAcceleration_single_precision_comms_plt -analysisRoutine = Examples/analysis_default_openpmd_regression.py - -[LaserInjection] -buildDir = . -inputFile = Examples/Tests/laser_injection/inputs_3d_rt -runtime_params = max_step=20 -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/laser_injection/analysis_laser.py -analysisOutputImage = laser_analysis.png - -[LaserInjection_1d] -buildDir = . -inputFile = Examples/Tests/laser_injection/inputs_1d_rt -runtime_params = -dim = 1 -addToCompileString = USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/laser_injection/analysis_1d.py - -[LaserInjection_2d] -buildDir = . -inputFile = Examples/Tests/laser_injection/inputs_2d_rt -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/laser_injection/analysis_2d.py - -[LaserInjectionFromBINARYFile] -buildDir = . -inputFile = Examples/Tests/laser_injection_from_file/analysis_2d_binary.py -aux1File = Examples/Tests/laser_injection_from_file/inputs.2d_test_binary -customRunCmd = ./analysis_2d_binary.py -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -selfTest = 1 -stSuccessString = Passed - -[LaserInjectionFromLASYFile] -buildDir = . -inputFile = Examples/Tests/laser_injection_from_file/analysis_3d.py -aux1File = Examples/Tests/laser_injection_from_file/inputs.3d_test -customRunCmd = ./analysis_3d.py -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -selfTest = 1 -stSuccessString = Passed - -[LaserInjectionFromLASYFile_1d] -buildDir = . -inputFile = Examples/Tests/laser_injection_from_file/analysis_1d.py -aux1File = Examples/Tests/laser_injection_from_file/inputs.1d_test -customRunCmd = ./analysis_1d.py -runtime_params = -dim = 1 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=1 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -selfTest = 1 -stSuccessString = Passed - -[LaserInjectionFromLASYFile_1d_boost] -buildDir = . -inputFile = Examples/Tests/laser_injection_from_file/analysis_1d_boost.py -aux1File = Examples/Tests/laser_injection_from_file/inputs.1d_boost_test -customRunCmd = ./analysis_1d_boost.py -runtime_params = -dim = 1 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=1 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -selfTest = 1 -stSuccessString = Passed - -[LaserInjectionFromLASYFile_2d] -buildDir = . -inputFile = Examples/Tests/laser_injection_from_file/analysis_2d.py -aux1File = Examples/Tests/laser_injection_from_file/inputs.2d_test -customRunCmd = ./analysis_2d.py -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -selfTest = 1 -stSuccessString = Passed - -[LaserInjectionFromLASYFile_RZ] -buildDir = . -inputFile = Examples/Tests/laser_injection_from_file/analysis_RZ.py -aux1File = Examples/Tests/laser_injection_from_file/inputs.RZ_test -customRunCmd = ./analysis_RZ.py -runtime_params = -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -selfTest = 1 -stSuccessString = Passed - -[LaserInjectionFromRZLASYFile] -buildDir = . -inputFile = Examples/Tests/laser_injection_from_file/analysis_from_RZ_file.py -aux1File = Examples/Tests/laser_injection_from_file/inputs.from_RZ_file_test -customRunCmd = ./analysis_from_RZ_file.py -runtime_params = -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -selfTest = 1 -stSuccessString = Passed - -[LaserIonAcc2d] -buildDir = . -inputFile = Examples/Physics_applications/laser_ion/inputs_2d -outputFile = LaserIonAcc2d_plt -runtime_params = -dim = 2 -addToCompileString = USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_openpmd_regression.py - -[LaserOnFine] -buildDir = . -inputFile = Examples/Tests/laser_on_fine/inputs_2d -runtime_params = max_step=50 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[leveling_thinning] -buildDir = . -inputFile = Examples/Tests/resampling/inputs_leveling_thinning -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/resampling/analysis_leveling_thinning.py - -[LoadExternalFieldRZGrid] -buildDir = . -inputFile = Examples/Tests/LoadExternalField/inputs_rz_grid_fields -runtime_params = warpx.abort_on_warning_threshold=medium chk.file_prefix=LoadExternalFieldRZGrid_chk chk.file_min_digits=5 -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_OPENPMD=ON -restartTest = 1 -restartFileNum = 150 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/LoadExternalField/analysis_rz.py - -[LoadExternalFieldRZParticles] -buildDir = . -inputFile = Examples/Tests/LoadExternalField/inputs_rz_particle_fields -runtime_params = warpx.abort_on_warning_threshold=medium chk.file_prefix=LoadExternalFieldRZParticles_chk chk.file_min_digits=5 -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_OPENPMD=ON -restartTest = 1 -restartFileNum = 150 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/LoadExternalField/analysis_rz.py - -[magnetostatic_eb_3d] -buildDir = . -inputFile = Examples/Tests/magnetostatic_eb/inputs_3d -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 2 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Maxwell_Hybrid_QED_solver] -buildDir = . -inputFile = Examples/Tests/maxwell_hybrid_qed/inputs_2d -runtime_params = warpx.cfl=0.7071067811865475 -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/maxwell_hybrid_qed/analysis_Maxwell_QED_Hybrid.py - -[momentum-conserving-gather] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/inputs_2d -runtime_params = amr.max_level=1 amr.n_cell=32 512 max_step=400 algo.field_gathering=momentum-conserving -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[multi_J_rz_psatd] -buildDir = . -inputFile = Examples/Tests/multi_j/inputs_rz -runtime_params = warpx.abort_on_warning_threshold=medium psatd.J_in_time=linear -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[nci_corrector] -buildDir = . -inputFile = Examples/Tests/nci_fdtd_stability/inputs_2d -runtime_params = amr.max_level=0 particles.use_fdtd_nci_corr=1 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py - -[nci_correctorMR] -buildDir = . -inputFile = Examples/Tests/nci_fdtd_stability/inputs_2d -runtime_params = amr.max_level=1 particles.use_fdtd_nci_corr=1 amr.n_cell=64 64 warpx.fine_tag_lo=-20.e-6 -20.e-6 warpx.fine_tag_hi=20.e-6 20.e-6 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py - -[parabolic_channel_initialization_2d_single_precision] -buildDir = . -inputFile = Examples/Tests/initial_plasma_profile/inputs -dim = 2 -addToCompileString = PRECISION=FLOAT USE_SINGLE_PRECISION_PARTICLES=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_PRECISION=SINGLE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -runtime_params = -analysisRoutine = Examples/Tests/initial_plasma_profile/analysis.py - -[particle_absorption] -buildDir = . -inputFile = Examples/Tests/particle_boundary_process/inputs_absorption -runtime_params = -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_boundary_process/analysis_absorption.py - -[particle_boundaries_3d] -buildDir = . -inputFile = Examples/Tests/boundaries/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/boundaries/analysis.py - -[particle_fields_diags] -buildDir = . -inputFile = Examples/Tests/particle_fields_diags/inputs -aux1File = Examples/Tests/particle_fields_diags/analysis_particle_diags_impl.py -runtime_params = -dim = 3 -addToCompileString = USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_fields_diags/analysis_particle_diags.py - -[particle_fields_diags_single_precision] -buildDir = . -inputFile = Examples/Tests/particle_fields_diags/inputs -aux1File = Examples/Tests/particle_fields_diags/analysis_particle_diags_impl.py -runtime_params = -dim = 3 -addToCompileString = PRECISION=FLOAT USE_SINGLE_PRECISION_PARTICLES=TRUE USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_PRECISION=SINGLE -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_fields_diags/analysis_particle_diags_single.py - -[particle_pusher] -buildDir = . -inputFile = Examples/Tests/particle_pusher/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_pusher/analysis_pusher.py - -[particle_scrape] -buildDir = . -inputFile = Examples/Tests/particle_boundary_scrape/inputs_scrape -runtime_params = -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_boundary_scrape/analysis_scrape.py - -[particles_in_pml] -buildDir = . -inputFile = Examples/Tests/particles_in_pml/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particles_in_pml/analysis_particles_in_pml.py - -[particles_in_pml_2d] -buildDir = . -inputFile = Examples/Tests/particles_in_pml/inputs_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particles_in_pml/analysis_particles_in_pml.py - -[particles_in_pml_2d_MR] -buildDir = . -inputFile = Examples/Tests/particles_in_pml/inputs_mr_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particles_in_pml/analysis_particles_in_pml.py - -[particles_in_pml_3d_MR] -buildDir = . -inputFile = Examples/Tests/particles_in_pml/inputs_mr_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particles_in_pml/analysis_particles_in_pml.py - -[PEC_field] -buildDir = . -inputFile = Examples/Tests/pec/inputs_field_PEC_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/pec/analysis_pec.py - -[PEC_field_mr] -buildDir = . -inputFile = Examples/Tests/pec/inputs_field_PEC_mr_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/pec/analysis_pec_mr.py - -[PEC_particle] -buildDir = . -inputFile = Examples/Tests/pec/inputs_particle_PEC_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Performance_works_1_uniform_rest_32ppc] -buildDir = . -inputFile = Examples/Tests/performance_tests/automated_test_1_uniform_rest_32ppc -runtime_params = amr.max_grid_size=32 amr.n_cell=32 32 32 max_step=5 diagnostics.diags_names=diag1 diag1.intervals=0 diag1.diag_type=Full -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[Performance_works_2_uniform_rest_1ppc] -buildDir = . -inputFile = Examples/Tests/performance_tests/automated_test_2_uniform_rest_1ppc -runtime_params = amr.max_grid_size=32 amr.n_cell=32 32 32 max_step=5 diagnostics.diags_names=diag1 diag1.intervals=0 diag1.diag_type=Full -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[Performance_works_3_uniform_drift_4ppc] -buildDir = . -inputFile = Examples/Tests/performance_tests/automated_test_3_uniform_drift_4ppc -runtime_params = amr.max_grid_size=32 amr.n_cell=32 32 32 max_step=5 diagnostics.diags_names=diag1 diag1.intervals=0 diag1.diag_type=Full -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[Performance_works_4_labdiags_2ppc] -buildDir = . -inputFile = Examples/Tests/performance_tests/automated_test_4_labdiags_2ppc -runtime_params = amr.n_cell=64 64 64 max_step=10 diagnostics.diags_names=diag1 diag1.intervals=0 diag1.diag_type=Full -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[Performance_works_5_loadimbalance] -buildDir = . -inputFile = Examples/Tests/performance_tests/automated_test_5_loadimbalance -runtime_params = amr.max_grid_size=32 amr.n_cell=32 32 32 max_step=5 diagnostics.diags_names=diag1 diag1.intervals=0 diag1.diag_type=Full -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[Performance_works_6_output_2ppc] -buildDir = . -inputFile = Examples/Tests/performance_tests/automated_test_6_output_2ppc -runtime_params = amr.n_cell=64 64 64 max_step=10 -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[photon_pusher] -buildDir = . -inputFile = Examples/Tests/photon_pusher/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/photon_pusher/analysis_photon_pusher.py - -[PlasmaAccelerationBoost2d] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/inputs_2d_boost -runtime_params = amr.n_cell=64 256 max_step=20 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[PlasmaAccelerationBoost3d] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/inputs_3d_boost -runtime_params = amr.n_cell=64 64 128 max_step=5 -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[PlasmaAccelerationBoost3d_hybrid] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/inputs_3d_boost -runtime_params = amr.n_cell=64 64 128 max_step=25 warpx.grid_type=hybrid warpx.do_current_centering=0 -dim = 3 -addToCompileString = -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[PlasmaAccelerationMR] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/inputs_2d -runtime_params = amr.max_level=1 amr.n_cell=32 512 max_step=400 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Plasma_lens] -buildDir = . -inputFile = Examples/Tests/plasma_lens/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/plasma_lens/analysis.py - -[Plasma_lens_boosted] -buildDir = . -inputFile = Examples/Tests/plasma_lens/inputs_boosted_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/plasma_lens/analysis.py - -[Plasma_lens_short] -buildDir = . -inputFile = Examples/Tests/plasma_lens/inputs_short_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/plasma_lens/analysis.py - -[PlasmaMirror] -buildDir = . -inputFile = Examples/Physics_applications/plasma_mirror/inputs_2d -runtime_params = amr.n_cell=256 128 max_step=20 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[pml_psatd_dive_divb_cleaning] -buildDir = . -inputFile = Examples/Tests/pml/inputs_3d -runtime_params = warpx.do_similar_dm_pml=0 warpx.abort_on_warning_threshold=medium ablastr.fillboundary_always_sync=1 -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[pml_psatd_rz] -buildDir = . -inputFile = Examples/Tests/pml/inputs_rz -runtime_params = warpx.cfl=0.7 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_RZ=TRUE USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/pml/analysis_pml_psatd_rz.py - -[pml_x_ckc] -buildDir = . -inputFile = Examples/Tests/pml/inputs_2d -runtime_params = algo.maxwell_solver=ckc -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/pml/analysis_pml_ckc.py - -[pml_x_galilean] -buildDir = . -inputFile = Examples/Tests/pml/inputs_2d -runtime_params = algo.maxwell_solver=psatd psatd.update_with_rho=1 diag1.fields_to_plot=Ex Ey Ez Bx By Bz rho divE warpx.cfl=0.7071067811865475 warpx.do_pml_dive_cleaning=1 warpx.do_pml_divb_cleaning=1 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium psatd.v_galilean=0. 0. 0.99 warpx.grid_type=collocated -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/pml/analysis_pml_psatd.py - -[pml_x_psatd] -buildDir = . -inputFile = Examples/Tests/pml/inputs_2d -runtime_params = algo.maxwell_solver=psatd psatd.update_with_rho=1 diag1.fields_to_plot = Ex Ey Ez Bx By Bz rho divE warpx.cfl = 0.7071067811865475 warpx.do_pml_dive_cleaning=0 warpx.do_pml_divb_cleaning=0 chk.file_prefix=pml_x_psatd_chk chk.file_min_digits=5 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 1 -restartFileNum = 150 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/pml/analysis_pml_psatd.py - -[pml_x_yee] -buildDir = . -inputFile = Examples/Tests/pml/inputs_2d -runtime_params = algo.maxwell_solver=yee chk.file_prefix=pml_x_yee_chk chk.file_min_digits=5 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 1 -restartFileNum = 150 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/pml/analysis_pml_yee.py - -[pml_x_yee_eb] -buildDir = . -inputFile = Examples/Tests/pml/inputs_2d -runtime_params = algo.maxwell_solver=yee chk.file_prefix=pml_x_yee_eb_chk chk.file_min_digits=5 -dim = 2 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_EB=ON -restartTest = 1 -restartFileNum = 150 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/pml/analysis_pml_yee.py - -[Proton_Boron_Fusion_2D] -buildDir = . -inputFile = Examples/Tests/nuclear_fusion/inputs_proton_boron_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nuclear_fusion/analysis_proton_boron_fusion.py - -[Proton_Boron_Fusion_3D] -buildDir = . -inputFile = Examples/Tests/nuclear_fusion/inputs_proton_boron_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nuclear_fusion/analysis_proton_boron_fusion.py - -[Python_background_mcc] -buildDir = . -inputFile = Examples/Physics_applications/capacitive_discharge/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Physics_applications/capacitive_discharge/analysis_2d.py - -[Python_background_mcc_1d] -buildDir = . -inputFile = Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_1d.py --test --pythonsolver -dim = 1 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Physics_applications/capacitive_discharge/analysis_1d.py - -[Python_background_mcc_1d_tridiag] -buildDir = . -inputFile = Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_1d.py --test -dim = 1 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Physics_applications/capacitive_discharge/analysis_1d.py - -[Python_collisionXZ] -buildDir = . -inputFile = Examples/Tests/collision/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/collision/analysis_collision_2d.py -aux1File = Regression/PostProcessingUtils/post_processing_utils.py - -[Python_dirichletbc] -buildDir = . -inputFile = Examples/Tests/electrostatic_dirichlet_bc/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_dirichlet_bc/analysis.py - -[Python_dsmc_1d] -buildDir = . -inputFile = Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_1d.py --test --dsmc -dim = 1 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py - -[Python_ElectrostaticSphereEB] -buildDir = . -inputFile = Examples/Tests/electrostatic_sphere_eb/PICMI_inputs_3d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_3d.py -dim = 3 -addToCompileString = USE_EB=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/electrostatic_sphere_eb/analysis.py - -[Python_gaussian_beam] -buildDir = . -inputFile = Examples/Tests/gaussian_beam/PICMI_inputs_gaussian_beam.py -customRunCmd = python3 PICMI_inputs_gaussian_beam.py -runtime_params = -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_gaussian_beam_no_field_output] -buildDir = . -inputFile = Examples/Tests/gaussian_beam/PICMI_inputs_gaussian_beam.py -customRunCmd = python3 PICMI_inputs_gaussian_beam.py --fields_to_plot none -runtime_params = -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[Python_gaussian_beam_opmd] -buildDir = . -inputFile = Examples/Tests/gaussian_beam/PICMI_inputs_gaussian_beam.py -customRunCmd = python3 PICMI_inputs_gaussian_beam.py --diagformat=openpmd -runtime_params = -dim = 3 -addToCompileString = USE_OPENPMD=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_OPENPMD=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[Python_gaussian_beam_opmd_no_field_output] -buildDir = . -inputFile = Examples/Tests/gaussian_beam/PICMI_inputs_gaussian_beam.py -customRunCmd = python PICMI_inputs_gaussian_beam.py --diagformat=openpmd --fields_to_plot none -runtime_params = -dim = 3 -addToCompileString = USE_OPENPMD=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_OPENPMD=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = - -[Python_id_cpu_read] -buildDir = . -inputFile = Examples/Tests/restart/PICMI_inputs_id_cpu_read.py -runtime_params = -customRunCmd = python3 PICMI_inputs_id_cpu_read.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 - -[Python_ionization] -buildDir = . -inputFile = Examples/Tests/ionization/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ionization/analysis_ionization.py - -[Python_Langmuir] -buildDir = . -inputFile = Examples/Tests/langmuir/PICMI_inputs_3d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_3d.py -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_Langmuir_2d] -buildDir = . -inputFile = Examples/Tests/langmuir/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_Langmuir_rz_multimode] -buildDir = . -inputFile = Examples/Tests/langmuir/PICMI_inputs_rz.py -runtime_params = -customRunCmd = python3 PICMI_inputs_rz.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_LaserAcceleration] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_3d.py -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_LaserAcceleration_1d] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/PICMI_inputs_1d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_1d.py -dim = 1 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_LaserAccelerationMR] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_LaserAccelerationRZ] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/PICMI_inputs_rz.py -runtime_params = -customRunCmd = python3 PICMI_inputs_rz.py -dim = 2 -addToCompileString = USE_RZ=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_LaserIonAcc2d] -buildDir = . -inputFile = Examples/Physics_applications/laser_ion/PICMI_inputs_2d.py -outputFile= diags/Python_LaserIonAcc2d_plt -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_OPENPMD=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_openpmd_regression.py - -[Python_LoadExternalGridField3D] -buildDir = . -inputFile = Examples/Tests/LoadExternalField/PICMI_inputs_3d_grid_fields.py -runtime_params = -customRunCmd = python3 PICMI_inputs_3d_grid_fields.py -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/LoadExternalField/analysis_3d.py - -[Python_LoadExternalParticleField3D] -buildDir = . -inputFile = Examples/Tests/LoadExternalField/PICMI_inputs_3d_particle_fields.py -runtime_params = -customRunCmd = python3 PICMI_inputs_3d_particle_fields.py -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/LoadExternalField/analysis_3d.py - -[Python_magnetostatic_eb_3d] -buildDir = . -inputFile = Examples/Tests/magnetostatic_eb/PICMI_inputs_3d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_3d.py -dim = 3 -addToCompileString = USE_EB=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_EB=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 2 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_magnetostatic_eb_rz] -buildDir = . -inputFile = Examples/Tests/magnetostatic_eb/PICMI_inputs_rz.py -runtime_params = -customRunCmd = python3 PICMI_inputs_rz.py -dim = 2 -addToCompileString = USE_EB=TRUE USE_PYTHON_MAIN=TRUE USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_EB=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 2 -analysisRoutine = Examples/Tests/magnetostatic_eb/analysis_rz.py - -[Python_ohms_law_solver_EM_modes_1d] -buildDir = . -inputFile = Examples/Tests/ohm_solver_EM_modes/PICMI_inputs.py -runtime_params = warpx.abort_on_warning_threshold = medium -customRunCmd = python3 PICMI_inputs.py --test --dim 1 --bdir z -dim = 1 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ohm_solver_EM_modes/analysis.py - -[Python_ohms_law_solver_EM_modes_rz] -buildDir = . -inputFile = Examples/Tests/ohm_solver_EM_modes/PICMI_inputs_rz.py -runtime_params = warpx.abort_on_warning_threshold = medium -customRunCmd = python3 PICMI_inputs_rz.py --test -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_APP=OFF -DWarpX_QED=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ohm_solver_EM_modes/analysis_rz.py - -[Python_ohms_law_solver_ion_beam_1d] -buildDir = . -inputFile = Examples/Tests/ohm_solver_ion_beam_instability/PICMI_inputs.py -runtime_params = warpx.abort_on_warning_threshold = medium -customRunCmd = python3 PICMI_inputs.py --test --dim 1 --resonant -dim = 1 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ohm_solver_ion_beam_instability/analysis.py - -[Python_ohms_law_solver_landau_damping_2d] -buildDir = . -inputFile = Examples/Tests/ohm_solver_ion_Landau_damping/PICMI_inputs.py -runtime_params = warpx.abort_on_warning_threshold = medium -customRunCmd = python3 PICMI_inputs.py --test --dim 2 --temp_ratio 0.1 -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ohm_solver_ion_Landau_damping/analysis.py - -[Python_ohms_law_solver_magnetic_reconnection_2d] -buildDir = . -inputFile = Examples/Tests/ohm_solver_magnetic_reconnection/PICMI_inputs.py -runtime_params = warpx.abort_on_warning_threshold = medium -customRunCmd = python3 PICMI_inputs.py --test -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/ohm_solver_magnetic_reconnection/analysis.py - -[Python_particle_attr_access] -buildDir = . -inputFile = Examples/Tests/particle_data_python/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_data_python/analysis.py - -[Python_particle_attr_access_unique] -buildDir = . -inputFile = Examples/Tests/particle_data_python/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py --unique -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_data_python/analysis.py - -[Python_particle_reflection] -buildDir = . -inputFile = Examples/Tests/particle_boundary_process/PICMI_inputs_reflection.py -runtime_params = -customRunCmd = python3 PICMI_inputs_reflection.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_boundary_process/analysis_reflection.py - -[Python_particle_scrape] -buildDir = . -inputFile = Examples/Tests/particle_boundary_scrape/PICMI_inputs_scrape.py -runtime_params = -customRunCmd = python3 PICMI_inputs_scrape.py -dim = 3 -addToCompileString = USE_EB=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_boundary_scrape/analysis_scrape.py - -# TODO: Enable in pyAMReX, then enable lines in PICMI_inputs_2d.py again -# https://github.com/AMReX-Codes/pyamrex/issues/163 -[Python_pass_mpi_comm] -buildDir = . -inputFile = Examples/Tests/pass_mpi_communicator/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -# TODO: comment in again once enabled -#analysisRoutine = Examples/Tests/pass_mpi_communicator/analysis.py - -[Python_PlasmaAcceleration] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration.py -runtime_params = -customRunCmd = python3 PICMI_inputs_plasma_acceleration.py -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_PlasmaAcceleration1d] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_1d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_plasma_acceleration_1d.py -dim = 1 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_OPENPMD=TRUE QED=FALSE -cmakeSetupOpts = -DWarpX_DIMS=1 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -DWarpX_OPENPMD=ON -DWarpX_QED=OFF -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_PlasmaAccelerationMR] -buildDir = . -inputFile = Examples/Physics_applications/plasma_acceleration/PICMI_inputs_plasma_acceleration_mr.py -runtime_params = -customRunCmd = python3 PICMI_inputs_plasma_acceleration_mr.py -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_plasma_lens] -buildDir = . -inputFile = Examples/Tests/plasma_lens/PICMI_inputs_3d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_3d.py -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/plasma_lens/analysis.py - -[Python_prev_positions] -buildDir = . -inputFile = Examples/Tests/particle_data_python/PICMI_inputs_prev_pos_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_prev_pos_2d.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Python_reduced_diags_loadbalancecosts_timers] -buildDir = . -inputFile = Examples/Tests/reduced_diags/PICMI_inputs_loadbalancecosts.py -runtime_params = algo.load_balance_costs_update=Timers -customRunCmd = python3 PICMI_inputs_loadbalancecosts.py -dim = 3 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/reduced_diags/analysis_reduced_diags_loadbalancecosts.py - -[Python_restart_eb] -buildDir = . -inputFile = Examples/Tests/restart_eb/PICMI_inputs_restart_eb.py -runtime_params = -customRunCmd = python3 PICMI_inputs_restart_eb.py -dim = 3 -addToCompileString = USE_EB=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 1 -restartFileNum = 30 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/restart/analysis_restart.py - -[Python_restart_runtime_components] -buildDir = . -inputFile = Examples/Tests/restart/PICMI_inputs_runtime_component_analyze.py -runtime_params = -customRunCmd = python3 PICMI_inputs_runtime_component_analyze.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 1 -restartFileNum = 5 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 - -[Python_wrappers] -buildDir = . -inputFile = Examples/Tests/python_wrappers/PICMI_inputs_2d.py -runtime_params = -customRunCmd = python3 PICMI_inputs_2d.py -dim = 2 -addToCompileString = USE_FFT=TRUE USE_PYTHON_MAIN=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -DWarpX_APP=OFF -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[qed_breit_wheeler_2d] -buildDir = . -inputFile = Examples/Tests/qed/breit_wheeler/inputs_2d -aux1File = Examples/Tests/qed/breit_wheeler/analysis_core.py -runtime_params = warpx.abort_on_warning_threshold = high -dim = 2 -addToCompileString = QED=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_QED=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/qed/breit_wheeler/analysis_yt.py - -[qed_breit_wheeler_2d_opmd] -buildDir = . -inputFile = Examples/Tests/qed/breit_wheeler/inputs_2d -aux1File = Examples/Tests/qed/breit_wheeler/analysis_core.py -runtime_params = diag1.format = openpmd diag1.openpmd_backend = h5 warpx.abort_on_warning_threshold = high -dim = 2 -addToCompileString = QED=TRUE USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_QED=ON -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = qed_breit_wheeler_2d_opmd_plt -analysisRoutine = Examples/Tests/qed/breit_wheeler/analysis_opmd.py - -[qed_breit_wheeler_3d] -buildDir = . -inputFile = Examples/Tests/qed/breit_wheeler/inputs_3d -aux1File = Examples/Tests/qed/breit_wheeler/analysis_core.py -runtime_params = warpx.abort_on_warning_threshold = high -dim = 3 -addToCompileString = QED=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_QED=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/qed/breit_wheeler/analysis_yt.py - -[qed_breit_wheeler_3d_opmd] -buildDir = . -inputFile = Examples/Tests/qed/breit_wheeler/inputs_3d -aux1File = Examples/Tests/qed/breit_wheeler/analysis_core.py -runtime_params = diag1.format = openpmd diag1.openpmd_backend = h5 warpx.abort_on_warning_threshold = high -dim = 3 -addToCompileString = QED=TRUE USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_QED=ON -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = qed_breit_wheeler_3d_opmd_plt -analysisRoutine = Examples/Tests/qed/breit_wheeler/analysis_opmd.py - -[qed_quantum_sync_2d] -buildDir = . -inputFile = Examples/Tests/qed/quantum_synchrotron/inputs_2d -runtime_params = warpx.abort_on_warning_threshold = high -dim = 2 -addToCompileString = QED=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_QED=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/qed/quantum_synchrotron/analysis.py - -[qed_quantum_sync_3d] -buildDir = . -inputFile = Examples/Tests/qed/quantum_synchrotron/inputs_3d -runtime_params = warpx.abort_on_warning_threshold = high -dim = 3 -addToCompileString = QED=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_QED=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/qed/quantum_synchrotron/analysis.py - -[qed_schwinger1] -buildDir = . -inputFile = Examples/Tests/qed/schwinger/inputs_3d_schwinger -runtime_params = warpx.E_external_grid = 1.e16 0 0 warpx.B_external_grid = 16792888.570516706 5256650.141557486 18363530.799561853 -dim = 3 -addToCompileString = QED=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_QED=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/qed/schwinger/analysis_schwinger.py - -[qed_schwinger2] -buildDir = . -inputFile = Examples/Tests/qed/schwinger/inputs_3d_schwinger -runtime_params = warpx.E_external_grid = 1.e18 0 0 warpx.B_external_grid = 1679288857.0516706 525665014.1557486 1836353079.9561853 qed_schwinger.xmin = -2.5e-7 qed_schwinger.xmax = 2.49e-7 -dim = 3 -addToCompileString = QED=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_QED=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/qed/schwinger/analysis_schwinger.py - -[qed_schwinger3] -buildDir = . -inputFile = Examples/Tests/qed/schwinger/inputs_3d_schwinger -runtime_params = warpx.E_external_grid = 0 1.090934525450495e+17 0 -dim = 3 -addToCompileString = QED=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_QED=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/qed/schwinger/analysis_schwinger.py - -[qed_schwinger4] -buildDir = . -inputFile = Examples/Tests/qed/schwinger/inputs_3d_schwinger -runtime_params = warpx.E_external_grid = 0 0 2.5e+20 warpx.B_external_grid = 0 833910140000. 0 qed_schwinger.ymin = -2.5e-7 qed_schwinger.zmax = 2.49e-7 -dim = 3 -addToCompileString = QED=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_QED=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/qed/schwinger/analysis_schwinger.py - -[radiation_reaction] -buildDir = . -inputFile = Examples/Tests/radiation_reaction/test_const_B_analytical/inputs_3d -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/radiation_reaction/test_const_B_analytical/analysis_classicalRR.py - -[reduced_diags] -buildDir = . -inputFile = Examples/Tests/reduced_diags/inputs -aux1File = Examples/Tests/reduced_diags/analysis_reduced_diags_impl.py -runtime_params = -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/reduced_diags/analysis_reduced_diags.py - -[reduced_diags_loadbalancecosts_heuristic] -buildDir = . -inputFile = Examples/Tests/reduced_diags/inputs_loadbalancecosts -runtime_params = algo.load_balance_costs_update=Heuristic -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/reduced_diags/analysis_reduced_diags_loadbalancecosts.py - -[reduced_diags_loadbalancecosts_timers] -buildDir = . -inputFile = Examples/Tests/reduced_diags/inputs_loadbalancecosts -runtime_params = algo.load_balance_costs_update=Timers -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/reduced_diags/analysis_reduced_diags_loadbalancecosts.py - -[reduced_diags_loadbalancecosts_timers_psatd] -buildDir = . -inputFile = Examples/Tests/reduced_diags/inputs_loadbalancecosts -runtime_params = algo.load_balance_costs_update=Timers -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/reduced_diags/analysis_reduced_diags_loadbalancecosts.py - -[reduced_diags_single_precision] -buildDir = . -inputFile = Examples/Tests/reduced_diags/inputs -aux1File = Examples/Tests/reduced_diags/analysis_reduced_diags_impl.py -runtime_params = -dim = 3 -addToCompileString = PRECISION=FLOAT USE_SINGLE_PRECISION_PARTICLES=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_PRECISION=SINGLE -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/reduced_diags/analysis_reduced_diags_single.py - -[RefinedInjection] -buildDir = . -inputFile = Examples/Physics_applications/laser_acceleration/inputs_2d -runtime_params = warpx.refine_plasma=1 amr.ref_ratio_vect = 2 1 -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Physics_applications/laser_acceleration/analysis_refined_injection.py - -[relativistic_space_charge_initialization] -buildDir = . -inputFile = Examples/Tests/relativistic_space_charge_initialization/inputs_3d -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -runtime_params = -analysisRoutine = Examples/Tests/relativistic_space_charge_initialization/analysis.py -analysisOutputImage = Comparison.png - -[RepellingParticles] -buildDir = . -inputFile = Examples/Tests/repelling_particles/inputs_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/repelling_particles/analysis_repelling.py - -[resample_velocity_coincidence_thinning] -buildDir = . -inputFile = Examples/Tests/resampling/inputs_1d_velocity_coincidence_thinning -runtime_params = -dim = 1 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=1 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[resample_velocity_coincidence_thinning_cartesian] -buildDir = . -inputFile = Examples/Tests/resampling/inputs_1d_velocity_coincidence_thinning_cartesian -runtime_params = -dim = 1 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=1 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[restart] -buildDir = . -inputFile = Examples/Tests/restart/inputs -runtime_params = chk.file_prefix=restart_chk chk.file_min_digits=5 -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 1 -restartFileNum = 5 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/restart/analysis_restart.py - -[restart_psatd] -buildDir = . -inputFile = Examples/Tests/restart/inputs -runtime_params = algo.maxwell_solver=psatd psatd.use_default_v_galilean=1 particles.use_fdtd_nci_corr=0 chk.file_prefix=restart_psatd_chk chk.file_min_digits=5 boundary.field_lo=periodic periodic damped boundary.field_hi=periodic periodic damped psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 1 -restartFileNum = 5 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/restart/analysis_restart.py - -[restart_psatd_time_avg] -buildDir = . -inputFile = Examples/Tests/restart/inputs -runtime_params = algo.maxwell_solver=psatd psatd.use_default_v_galilean=1 particles.use_fdtd_nci_corr=0 chk.file_prefix=restart_psatd_time_avg_chk chk.file_min_digits=5 boundary.field_lo=periodic periodic damped boundary.field_hi=periodic periodic damped psatd.do_time_averaging=1 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 1 -restartFileNum = 5 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/restart/analysis_restart.py - -[RigidInjection_BTD] -buildDir = . -inputFile = Examples/Tests/rigid_injection/inputs_2d_BoostedFrame -runtime_params = -dim = 2 -addToCompileString = USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/rigid_injection/analysis_rigid_injection_BoostedFrame.py - -[RigidInjection_lab] -buildDir = . -inputFile = Examples/Tests/rigid_injection/inputs_2d_LabFrame -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/rigid_injection/analysis_rigid_injection_LabFrame.py - -[scraping] -buildDir = . -inputFile = Examples/Tests/scraping/inputs_rz -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 2 -addToCompileString = USE_EB=TRUE USE_RZ=TRUE USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_EB=ON -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/scraping/analysis_rz.py - -[scraping_filter] -buildDir = . -inputFile = Examples/Tests/scraping/inputs_rz_filter -runtime_params = warpx.abort_on_warning_threshold = medium -dim = 2 -addToCompileString = USE_EB=TRUE USE_RZ=TRUE USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_EB=ON -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/scraping/analysis_rz_filter.py - -[silver_mueller_1d] -buildDir = . -inputFile = Examples/Tests/silver_mueller/inputs_1d -runtime_params = -dim = 1 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=1 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/silver_mueller/analysis_silver_mueller.py - -[silver_mueller_2d_x] -buildDir = . -inputFile = Examples/Tests/silver_mueller/inputs_2d_x -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/silver_mueller/analysis_silver_mueller.py - -[silver_mueller_2d_z] -buildDir = . -inputFile = Examples/Tests/silver_mueller/inputs_2d_z -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/silver_mueller/analysis_silver_mueller.py - -[silver_mueller_rz_z] -buildDir = . -inputFile = Examples/Tests/silver_mueller/inputs_rz_z -runtime_params = -dim = 2 -addToCompileString = USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/silver_mueller/analysis_silver_mueller.py - -[space_charge_initialization] -buildDir = . -inputFile = Examples/Tests/space_charge_initialization/inputs_3d -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -runtime_params = -analysisRoutine = Examples/Tests/space_charge_initialization/analysis.py -analysisOutputImage = Comparison.png - -[space_charge_initialization_2d] -buildDir = . -inputFile = Examples/Tests/space_charge_initialization/inputs_3d -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -runtime_params = geometry.dims=2 -analysisRoutine = Examples/Tests/space_charge_initialization/analysis.py -analysisOutputImage = Comparison.png - -[subcyclingMR] -buildDir = . -inputFile = Examples/Tests/subcycling/inputs_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[Uniform_2d] -buildDir = . -inputFile = Examples/Physics_applications/uniform_plasma/inputs_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/analysis_default_regression.py - -[uniform_plasma_restart] -buildDir = . -inputFile = Examples/Physics_applications/uniform_plasma/inputs_3d -runtime_params = chk.file_prefix=uniform_plasma_restart_chk chk.file_min_digits=5 -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 1 -restartFileNum = 6 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/restart/analysis_restart.py - -[uniform_plasma_multiJ] -buildDir = . -inputFile = Examples/Tests/nci_psatd_stability/inputs_3d -runtime_params = psatd.solution_type=first-order psatd.J_in_time=constant psatd.rho_in_time=constant warpx.do_dive_cleaning=1 warpx.do_divb_cleaning=1 warpx.do_multi_J=1 warpx.do_multi_J_n_depositions=1 diag1.fields_to_plot=Bx By Bz divE Ex Ey Ez F G jx jy jz rho warpx.abort_on_warning_threshold=medium -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nci_psatd_stability/analysis_multiJ.py - -[VayDeposition2D] -buildDir = . -inputFile = Examples/Tests/vay_deposition/inputs_2d -runtime_params = -dim = 2 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/vay_deposition/analysis.py - -[VayDeposition3D] -buildDir = . -inputFile = Examples/Tests/vay_deposition/inputs_3d -runtime_params = -dim = 3 -addToCompileString = USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/vay_deposition/analysis.py - -[NodalElectrostaticSolver] -buildDir = . -inputFile = Examples/Tests/nodal_electrostatic/inputs_3d -runtime_params = warpx.abort_on_warning_threshold=high -dim = 3 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=3 -restartTest = 0 -useMPI = 1 -numprocs = 1 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/nodal_electrostatic/analysis_3d.py - -[BeamBeamCollision] -buildDir = . -inputFile = Examples/Physics_applications/beam-beam_collision/inputs -runtime_params = warpx.abort_on_warning_threshold=high -dim = 3 -addToCompileString = USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = BeamBeamCollision_plt -analysisRoutine = Examples/analysis_default_openpmd_regression.py - -[spacecraft_charging] -buildDir = . -inputFile = Examples/Physics_applications/spacecraft_charging/PICMI_inputs_rz.py -runtime_params = -customRunCmd = python3 PICMI_inputs_rz.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS="RZ" -DWarpX_EB=ON -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = spacecraft_charging_plt -analysisRoutine = Examples/Physics_applications/spacecraft_charging/analysis.py -analysisOutputImage = min_phi_analysis.png - -[Point_of_contact_EB_3d] -buildDir = . -inputFile = Examples/Tests/point_of_contact_EB/inputs_3d -runtime_params = -dim = 3 -addToCompileString = USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -outputFile = Point_of_contact_EB_3d_plt -analysisRoutine = Examples/Tests/point_of_contact_EB/analysis.py - -[Point_of_contact_EB_rz] -buildDir = . -inputFile = Examples/Tests/point_of_contact_EB/inputs_rz -runtime_params = -dim = 2 -addToCompileString = USE_RZ=TRUE USE_EB=TRUE -cmakeSetupOpts = -DWarpX_DIMS=RZ -DWarpX_EB=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -outputFile = Point_of_contact_EB_rz_plt -analysisRoutine = Examples/Tests/point_of_contact_EB/analysis.py - -[ThetaImplicitPicard_1d] -buildDir = . -inputFile = Examples/Tests/Implicit/inputs_1d -runtime_params = warpx.abort_on_warning_threshold=high -dim = 1 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=1 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -analysisRoutine = Examples/Tests/Implicit/analysis_1d.py - -[ThetaImplicitJFNK_VandB_2d] -buildDir = . -inputFile = Examples/Tests/Implicit/inputs_vandb_jfnk_2d -runtime_params = warpx.abort_on_warning_threshold=high -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -analysisRoutine = Examples/Tests/Implicit/analysis_vandb_jfnk_2d.py - -[SemiImplicitPicard_1d] -buildDir = . -inputFile = Examples/Tests/Implicit/inputs_1d_semiimplicit -runtime_params = warpx.abort_on_warning_threshold=high -dim = 1 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=1 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -analysisRoutine = Examples/Tests/Implicit/analysis_1d.py - -[EnergyConservingThermalPlasma] -buildDir = . -inputFile = Examples/Tests/energy_conserving_thermal_plasma/inputs_2d_electrostatic -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 0 -numthreads = 1 -analysisRoutine = Examples/Tests/energy_conserving_thermal_plasma/analysis.py - -[focusing_gaussian_beam] -buildDir = . -inputFile = Examples/Tests/gaussian_beam/inputs_focusing_beam -runtime_params = -dim = 3 -addToCompileString = USE_OPENPMD=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/gaussian_beam/analysis_focusing_beam.py - -[particle_boundary_interaction] -buildDir = . -inputFile = Examples/Tests/particle_boundary_interaction/PICMI_inputs_rz.py -runtime_params = -customRunCmd = python3 PICMI_inputs_rz.py -dim = 2 -addToCompileString = USE_PYTHON_MAIN=TRUE USE_RZ=TRUE -cmakeSetupOpts = -DWarpX_DIMS="RZ" -DWarpX_EB=ON -DWarpX_PYTHON=ON -target = pip_install -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -outputFile = particle_boundary_interaction_plt -analysisRoutine = Examples/Tests/particle_boundary_interaction/analysis.py - -[particle_thermal_boundary] -buildDir = . -inputFile = Examples/Tests/particle_thermal_boundary/inputs_2d -runtime_params = -dim = 2 -addToCompileString = -cmakeSetupOpts = -DWarpX_DIMS=2 -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/particle_thermal_boundary/analysis_2d.py - -[openbc_poisson_solver] -buildDir = . -inputFile = Examples/Tests/openbc_poisson_solver/inputs_3d -runtime_params = warpx.abort_on_warning_threshold = high -dim = 3 -addToCompileString = USE_OPENPMD=TRUE USE_FFT=TRUE -cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_FFT=ON -DWarpX_OPENPMD=ON -restartTest = 0 -useMPI = 1 -numprocs = 2 -useOMP = 1 -numthreads = 1 -analysisRoutine = Examples/Tests/openbc_poisson_solver/analysis.py diff --git a/Regression/prepare_file_ci.py b/Regression/prepare_file_ci.py deleted file mode 100644 index f7b610dace9..00000000000 --- a/Regression/prepare_file_ci.py +++ /dev/null @@ -1,161 +0,0 @@ -# Copyright 2018-2019 Andrew Myers, Luca Fedeli, Maxence Thevenet -# Remi Lehe -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import os - -# This script modifies `WarpX-test.ini` (which is used for nightly builds) -# and creates the file `ci-test.ini` (which is used for continuous -# integration) -# The subtests that are selected are controlled by WARPX_TEST_DIM -# The architecture (CPU/GPU) is selected by WARPX_TEST_ARCH -import re - -# Get relevant environment variables -arch = os.environ.get('WARPX_TEST_ARCH', 'CPU') - -ci_regular_cartesian_1d = os.environ.get('WARPX_CI_REGULAR_CARTESIAN_1D') == 'TRUE' -ci_regular_cartesian_2d = os.environ.get('WARPX_CI_REGULAR_CARTESIAN_2D') == 'TRUE' -ci_regular_cartesian_3d = os.environ.get('WARPX_CI_REGULAR_CARTESIAN_3D') == 'TRUE' -ci_psatd = os.environ.get('WARPX_CI_PSATD', 'TRUE') == 'TRUE' -ci_single_precision = os.environ.get('WARPX_CI_SINGLE_PRECISION') == 'TRUE' -ci_rz_or_nompi = os.environ.get('WARPX_CI_RZ_OR_NOMPI') == 'TRUE' -ci_qed = os.environ.get('WARPX_CI_QED') == 'TRUE' -ci_eb = os.environ.get('WARPX_CI_EB') == 'TRUE' -ci_openpmd = os.environ.get('WARPX_CI_OPENPMD') == 'TRUE' -ci_ccache = os.environ.get('WARPX_CI_CCACHE') == 'TRUE' -ci_num_make_jobs = os.environ.get('WARPX_CI_NUM_MAKE_JOBS', None) - -# Find the directory in which the tests should be run -current_dir = os.getcwd() -test_dir = re.sub('warpx/Regression', '', current_dir ) - -with open('WarpX-tests.ini') as f: - text = f.read() - -# Replace default folder name -text = re.sub('/home/regtester/AMReX_RegTesting', test_dir, text) -# Remove the web directory -text = re.sub('[\w\-\/]*/web', '', text) - -# Add doComparison = 0 for each test -text = re.sub( '\[(?P.*)\]\nbuildDir = ', - '[\g]\ndoComparison = 0\nbuildDir = ', text ) - -# Change compile options when running on GPU -if arch == 'GPU': - text = re.sub( 'addToCompileString =', - 'addToCompileString = USE_GPU=TRUE USE_OMP=FALSE ', text) -print('Compiling for %s' %arch) - -# Extra dependencies -if ci_openpmd: - text = re.sub('addToCompileString =', - 'addToCompileString = USE_OPENPMD=TRUE ', text) - -# always build with PSATD support (runtime controlled if used) -if ci_psatd: - text = re.sub('addToCompileString =', - 'addToCompileString = USE_FFT=TRUE ', text) - text = re.sub('USE_FFT=FALSE', - '', text) - -# CCache -if ci_ccache: - text = re.sub('addToCompileString =', - 'addToCompileString = USE_CCACHE=TRUE ', text) - -# Add runtime options: -# > crash for unused variables -# > trap NaNs, divisions by zero, and overflows -# > abort upon any warning message by default -text = re.sub('runtime_params =', - 'runtime_params = amrex.abort_on_unused_inputs=1 '+ - 'amrex.fpe_trap_invalid=1 amrex.fpe_trap_zero=1 amrex.fpe_trap_overflow=1 '+ - 'warpx.always_warn_immediately=1 warpx.abort_on_warning_threshold=low', - text) - -# Add runtime options for CPU: -# > serialize initial conditions and no dynamic scheduling in OpenMP -if arch == 'CPU': - text = re.sub('runtime_params =', - 'runtime_params = '+ - 'warpx.do_dynamic_scheduling=0 warpx.serialize_initial_conditions=1', - text) - -# Use less/more cores for compiling, e.g. public CI only provides 2 cores -if ci_num_make_jobs is not None: - text = re.sub( 'numMakeJobs = \d+', 'numMakeJobs = {}'.format(ci_num_make_jobs), text ) - -# Prevent emails from being sent -text = re.sub( 'sendEmailWhenFail = 1', 'sendEmailWhenFail = 0', text ) - -# Select the tests to be run -# -------------------------- - -# - Extract test blocks (they are identified by the fact that they contain "inputFile") -select_test_regex = r'(\[(.+\n)*inputFile(.+\n)*)' -test_blocks = [ match[0] for match in re.findall(select_test_regex, text) ] -# - Remove the test blocks from `text` (only the selected ones will be added back) -text = re.sub( select_test_regex, '', text ) - -def select_tests(blocks, match_string_list, do_test): - """Remove or keep tests from list in WarpX-tests.ini according to do_test variable""" - if do_test not in [True, False]: - raise ValueError("do_test must be True or False") - if (do_test == False): - for match_string in match_string_list: - print('Selecting tests without ' + match_string) - blocks = [ block for block in blocks if not match_string in block ] - else: - for match_string in match_string_list: - print('Selecting tests with ' + match_string) - blocks = [ block for block in blocks if match_string in block ] - return blocks - -if ci_regular_cartesian_1d: - test_blocks = select_tests(test_blocks, ['dim = 1'], True) - test_blocks = select_tests(test_blocks, ['USE_RZ=TRUE'], False) - test_blocks = select_tests(test_blocks, ['PRECISION=FLOAT', 'USE_SINGLE_PRECISION_PARTICLES=TRUE'], False) - test_blocks = select_tests(test_blocks, ['useMPI = 0'], False) - test_blocks = select_tests(test_blocks, ['QED=TRUE'], False) - test_blocks = select_tests(test_blocks, ['USE_EB=TRUE'], False) - -if ci_regular_cartesian_2d: - test_blocks = select_tests(test_blocks, ['dim = 2'], True) - test_blocks = select_tests(test_blocks, ['USE_RZ=TRUE'], False) - test_blocks = select_tests(test_blocks, ['PRECISION=FLOAT', 'USE_SINGLE_PRECISION_PARTICLES=TRUE'], False) - test_blocks = select_tests(test_blocks, ['useMPI = 0'], False) - test_blocks = select_tests(test_blocks, ['QED=TRUE'], False) - test_blocks = select_tests(test_blocks, ['USE_EB=TRUE'], False) - -if ci_regular_cartesian_3d: - test_blocks = select_tests(test_blocks, ['dim = 3'], True) - test_blocks = select_tests(test_blocks, ['PRECISION=FLOAT', 'USE_SINGLE_PRECISION_PARTICLES=TRUE'], False) - test_blocks = select_tests(test_blocks, ['useMPI = 0'], False) - test_blocks = select_tests(test_blocks, ['QED=TRUE'], False) - test_blocks = select_tests(test_blocks, ['USE_EB=TRUE'], False) - -if ci_single_precision: - test_blocks = select_tests(test_blocks, ['PRECISION=FLOAT', 'USE_SINGLE_PRECISION_PARTICLES=TRUE'], True) - -if ci_rz_or_nompi: - block1 = select_tests(test_blocks, ['USE_RZ=TRUE'], True) - block2 = select_tests(test_blocks, ['useMPI = 0'], True) - test_blocks = block1 + block2 - -if ci_qed: - test_blocks = select_tests(test_blocks, ['QED=TRUE'], True) - -if ci_eb: - test_blocks = select_tests(test_blocks, ['USE_RZ=TRUE'], False) - test_blocks = select_tests(test_blocks, ['USE_EB=TRUE'], True) - -# - Add the selected test blocks to the text -text = text + '\n' + '\n'.join(test_blocks) - -with open('ci-tests.ini', 'w') as f: - f.write(text) diff --git a/Regression/requirements.txt b/Regression/requirements.txt index 5bdd04ba106..509123899ba 100644 --- a/Regression/requirements.txt +++ b/Regression/requirements.txt @@ -1,10 +1,12 @@ +-r ../requirements.txt dill -lasy +lasy>=0.5.0 matplotlib mpi4py numpy openpmd-api openpmd-viewer pandas +periodictable scipy yt diff --git a/Source/BoundaryConditions/PML.H b/Source/BoundaryConditions/PML.H index 7ed1def8f72..203c109f026 100644 --- a/Source/BoundaryConditions/PML.H +++ b/Source/BoundaryConditions/PML.H @@ -140,12 +140,15 @@ public: const amrex::DistributionMapping& dm, bool do_similar_dm_pml, const amrex::Geometry* geom, const amrex::Geometry* cgeom, int ncell, int delta, amrex::IntVect ref_ratio, - amrex::Real dt, int nox_fft, int noy_fft, int noz_fft, short grid_type, + amrex::Real dt, int nox_fft, int noy_fft, int noz_fft, + ablastr::utils::enums::GridType grid_type, int do_moving_window, int pml_has_particles, int do_pml_in_domain, - int psatd_solution_type, int J_in_time, int rho_in_time, + PSATDSolutionType psatd_solution_type, + JInTime J_in_time, RhoInTime rho_in_time, bool do_pml_dive_cleaning, bool do_pml_divb_cleaning, const amrex::IntVect& fill_guards_fields, const amrex::IntVect& fill_guards_current, + bool eb_enabled, int max_guard_EB, amrex::Real v_sigma_sb, amrex::IntVect do_pml_Lo = amrex::IntVect::TheUnitVector(), amrex::IntVect do_pml_Hi = amrex::IntVect::TheUnitVector()); @@ -259,7 +262,7 @@ private: } #ifdef AMREX_USE_EB - amrex::EBFArrayBoxFactory const& fieldEBFactory () const noexcept { + [[nodiscard]] amrex::EBFArrayBoxFactory const& fieldEBFactory () const noexcept { return static_cast(*pml_field_factory); } #endif diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index ed82cc07bb9..a66dcb5c0bb 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -22,6 +22,7 @@ #include "WarpX.H" #include +#include #include #include @@ -548,12 +549,15 @@ PML::PML (const int lev, const BoxArray& grid_ba, const DistributionMapping& grid_dm, const bool do_similar_dm_pml, const Geometry* geom, const Geometry* cgeom, int ncell, int delta, amrex::IntVect ref_ratio, - Real dt, int nox_fft, int noy_fft, int noz_fft, short grid_type, + Real dt, int nox_fft, int noy_fft, int noz_fft, + ablastr::utils::enums::GridType grid_type, int do_moving_window, int /*pml_has_particles*/, int do_pml_in_domain, - const int psatd_solution_type, const int J_in_time, const int rho_in_time, + const PSATDSolutionType psatd_solution_type, + const JInTime J_in_time, const RhoInTime rho_in_time, const bool do_pml_dive_cleaning, const bool do_pml_divb_cleaning, const amrex::IntVect& fill_guards_fields, const amrex::IntVect& fill_guards_current, + bool eb_enabled, int max_guard_EB, const amrex::Real v_sigma_sb, const amrex::IntVect do_pml_Lo, const amrex::IntVect do_pml_Hi) : m_dive_cleaning(do_pml_dive_cleaning), @@ -563,6 +567,10 @@ PML::PML (const int lev, const BoxArray& grid_ba, m_geom(geom), m_cgeom(cgeom) { +#ifndef AMREX_USE_EB + WARPX_ALWAYS_ASSERT_WITH_MESSAGE(!eb_enabled, "PML: eb_enabled is true but was not compiled in."); +#endif + // When `do_pml_in_domain` is true, the PML overlap with the last `ncell` of the physical domain or fine patch(es) // (instead of extending `ncell` outside of the physical domain or fine patch(es)) // In order to implement this, we define a new reduced Box Array ensuring that it does not @@ -631,6 +639,8 @@ PML::PML (const int lev, const BoxArray& grid_ba, } if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) { + using namespace ablastr::utils::enums; + // Increase the number of guard cells, in order to fit the extent // of the stencil for the spectral solver int ngFFt_x = (grid_type == GridType::Collocated) ? nox_fft : nox_fft/2; @@ -669,13 +679,20 @@ PML::PML (const int lev, const BoxArray& grid_ba, } #ifdef AMREX_USE_EB - pml_field_factory = amrex::makeEBFabFactory(*geom, ba, dm, - {max_guard_EB, max_guard_EB, max_guard_EB}, - amrex::EBSupport::full); -#else - amrex::ignore_unused(max_guard_EB); - pml_field_factory = std::make_unique(); + if (eb_enabled) { + pml_field_factory = amrex::makeEBFabFactory( + *geom, + ba, + dm, + {max_guard_EB, max_guard_EB, max_guard_EB}, + amrex::EBSupport::full + ); + } else #endif + { + amrex::ignore_unused(max_guard_EB); + pml_field_factory = std::make_unique(); + } // Allocate diagonal components (xx,yy,zz) only with divergence cleaning const int ncompe = (m_dive_cleaning) ? 3 : 2; @@ -703,20 +720,22 @@ PML::PML (const int lev, const BoxArray& grid_ba, WarpX::AllocInitMultiFab(pml_j_fp[2], ba_jz, dm, 1, ngb, lev, "pml_j_fp[z]", 0.0_rt); #ifdef AMREX_USE_EB - const amrex::IntVect max_guard_EB_vect = amrex::IntVect(max_guard_EB); - WarpX::AllocInitMultiFab(pml_edge_lengths[0], ba_Ex, dm, WarpX::ncomps, max_guard_EB_vect, lev, "pml_edge_lengths[x]", 0.0_rt); - WarpX::AllocInitMultiFab(pml_edge_lengths[1], ba_Ey, dm, WarpX::ncomps, max_guard_EB_vect, lev, "pml_edge_lengths[y]", 0.0_rt); - WarpX::AllocInitMultiFab(pml_edge_lengths[2], ba_Ez, dm, WarpX::ncomps, max_guard_EB_vect, lev, "pml_edge_lengths[z]", 0.0_rt); + if (eb_enabled) { + const amrex::IntVect max_guard_EB_vect = amrex::IntVect(max_guard_EB); + WarpX::AllocInitMultiFab(pml_edge_lengths[0], ba_Ex, dm, WarpX::ncomps, max_guard_EB_vect, lev, "pml_edge_lengths[x]", 0.0_rt); + WarpX::AllocInitMultiFab(pml_edge_lengths[1], ba_Ey, dm, WarpX::ncomps, max_guard_EB_vect, lev, "pml_edge_lengths[y]", 0.0_rt); + WarpX::AllocInitMultiFab(pml_edge_lengths[2], ba_Ez, dm, WarpX::ncomps, max_guard_EB_vect, lev, "pml_edge_lengths[z]", 0.0_rt); - if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::Yee || - WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::CKC || - WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { + if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::Yee || + WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::CKC || + WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { - auto const eb_fact = fieldEBFactory(); + auto const eb_fact = fieldEBFactory(); - WarpX::ComputeEdgeLengths(pml_edge_lengths, eb_fact); - WarpX::ScaleEdges(pml_edge_lengths, WarpX::CellSize(lev)); + WarpX::ComputeEdgeLengths(pml_edge_lengths, eb_fact); + WarpX::ScaleEdges(pml_edge_lengths, WarpX::CellSize(lev)); + } } #endif diff --git a/Source/BoundaryConditions/WarpXEvolvePML.cpp b/Source/BoundaryConditions/WarpXEvolvePML.cpp index ec696689373..c6a89d80c07 100644 --- a/Source/BoundaryConditions/WarpXEvolvePML.cpp +++ b/Source/BoundaryConditions/WarpXEvolvePML.cpp @@ -11,6 +11,7 @@ #if (defined WARPX_DIM_RZ) && (defined WARPX_USE_FFT) # include "BoundaryConditions/PML_RZ.H" #endif +#include "EmbeddedBoundary/Enabled.H" #include "PML_current.H" #include "Utils/WarpXProfilerWrapper.H" #include "WarpX_PML_kernels.H" @@ -269,13 +270,17 @@ WarpX::DampJPML (int lev, PatchType patch_type) const Real* sigma_star_cumsum_fac_j_z = sigba[mfi].sigma_star_cumsum_fac[1].data(); #endif -#ifdef AMREX_USE_EB - const auto& pml_edge_lenghts = pml[lev]->Get_edge_lengths(); + // Skip the field update if this gridpoint is inside the embedded boundary + amrex::Array4 eb_lxfab, eb_lyfab, eb_lzfab; + if (EB::enabled()) { + const auto &pml_edge_lenghts = pml[lev]->Get_edge_lengths(); - auto const& pml_lxfab = pml_edge_lenghts[0]->array(mfi); - auto const& pml_lyfab = pml_edge_lenghts[1]->array(mfi); - auto const& pml_lzfab = pml_edge_lenghts[2]->array(mfi); -#endif + eb_lxfab = pml_edge_lenghts[0]->array(mfi); + eb_lyfab = pml_edge_lenghts[1]->array(mfi); + eb_lzfab = pml_edge_lenghts[2]->array(mfi); + } else { + amrex::ignore_unused(eb_lxfab, eb_lyfab, eb_lzfab); + } const Box& tjx = mfi.tilebox( pml_j[0]->ixType().toIntVect() ); const Box& tjy = mfi.tilebox( pml_j[1]->ixType().toIntVect() ); @@ -301,27 +306,21 @@ WarpX::DampJPML (int lev, PatchType patch_type) amrex::ParallelFor( tjx, tjy, tjz, [=] AMREX_GPU_DEVICE (int i, int j, int k) { -#ifdef AMREX_USE_EB - if(pml_lxfab(i, j, k) <= 0) return; -#endif + if (eb_lxfab && eb_lxfab(i, j, k) <= 0) { return; } damp_jx_pml(i, j, k, pml_jxfab, sigma_star_cumsum_fac_j_x, sigma_cumsum_fac_j_y, sigma_cumsum_fac_j_z, xs_lo,y_lo, z_lo); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { -#ifdef AMREX_USE_EB - if(pml_lyfab(i, j, k) <= 0) return; -#endif + if (eb_lyfab && eb_lyfab(i, j, k) <= 0) { return; } damp_jy_pml(i, j, k, pml_jyfab, sigma_cumsum_fac_j_x, sigma_star_cumsum_fac_j_y, sigma_cumsum_fac_j_z, x_lo,ys_lo, z_lo); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { -#ifdef AMREX_USE_EB - if(pml_lzfab(i, j, k)<=0) return; -#endif + if (eb_lzfab && eb_lzfab(i, j, k) <= 0) { return; } damp_jz_pml(i, j, k, pml_jzfab, sigma_cumsum_fac_j_x, sigma_cumsum_fac_j_y, sigma_star_cumsum_fac_j_z, diff --git a/Source/BoundaryConditions/WarpXFieldBoundaries.cpp b/Source/BoundaryConditions/WarpXFieldBoundaries.cpp index 2b063b99a15..6d2525bc724 100644 --- a/Source/BoundaryConditions/WarpXFieldBoundaries.cpp +++ b/Source/BoundaryConditions/WarpXFieldBoundaries.cpp @@ -25,8 +25,8 @@ namespace /** Returns true if any field boundary is set to FieldBoundaryType FT, else returns false.*/ template [[nodiscard]] - bool isAnyBoundary (const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi) + bool isAnyBoundary (const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi) { const auto isFT = [](const auto& b){ return b == FT;}; @@ -37,8 +37,8 @@ namespace /** Returns true if any particle boundary is set to ParticleBoundaryType PT, else returns false.*/ template [[nodiscard]] - bool isAnyBoundary (const amrex::Vector& particle_boundary_lo, - const amrex::Vector& particle_boundary_hi) + bool isAnyBoundary (const amrex::Array& particle_boundary_lo, + const amrex::Array& particle_boundary_hi) { const auto isPT = [](const auto& b){ return b == PT;}; diff --git a/Source/BoundaryConditions/WarpX_PEC.H b/Source/BoundaryConditions/WarpX_PEC.H index a6af894beb4..c387d8c1793 100644 --- a/Source/BoundaryConditions/WarpX_PEC.H +++ b/Source/BoundaryConditions/WarpX_PEC.H @@ -31,8 +31,8 @@ namespace PEC { */ void ApplyPECtoEfield ( std::array Efield, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, const amrex::IntVect& ng_fieldgather, const amrex::Geometry& geom, int lev, PatchType patch_type, const amrex::Vector& ref_ratios, bool split_pml_field = false); @@ -52,8 +52,8 @@ namespace PEC { */ void ApplyPECtoBfield ( std::array Bfield, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, const amrex::IntVect& ng_fieldgather, const amrex::Geometry& geom, int lev, PatchType patch_type, const amrex::Vector& ref_ratios); @@ -73,10 +73,10 @@ namespace PEC { */ void ApplyReflectiveBoundarytoRhofield( amrex::MultiFab* rho, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, - const amrex::Vector& particle_boundary_lo, - const amrex::Vector& particle_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, + const amrex::Array& particle_boundary_lo, + const amrex::Array& particle_boundary_hi, const amrex::Geometry& geom, int lev, PatchType patch_type, const amrex::Vector& ref_ratios); @@ -97,10 +97,10 @@ namespace PEC { void ApplyReflectiveBoundarytoJfield( amrex::MultiFab* Jx, amrex::MultiFab* Jy, amrex::MultiFab* Jz, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, - const amrex::Vector& particle_boundary_lo, - const amrex::Vector& particle_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, + const amrex::Array& particle_boundary_lo, + const amrex::Array& particle_boundary_hi, const amrex::Geometry& geom, int lev, PatchType patch_type, const amrex::Vector& ref_ratios); @@ -117,8 +117,8 @@ namespace PEC { */ void ApplyPECtoElectronPressure ( amrex::MultiFab* Pefield, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, const amrex::Geometry& geom, int lev, PatchType patch_type, const amrex::Vector& ref_ratios); } diff --git a/Source/BoundaryConditions/WarpX_PEC.cpp b/Source/BoundaryConditions/WarpX_PEC.cpp index 0067f54d3ff..bedc5b264b7 100644 --- a/Source/BoundaryConditions/WarpX_PEC.cpp +++ b/Source/BoundaryConditions/WarpX_PEC.cpp @@ -457,8 +457,8 @@ namespace void PEC::ApplyPECtoEfield ( std::array Efield, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, const amrex::IntVect& ng_fieldgather, const amrex::Geometry& geom, const int lev, PatchType patch_type, const amrex::Vector& ref_ratios, const bool split_pml_field) @@ -510,12 +510,7 @@ PEC::ApplyPECtoEfield ( amrex::ParallelFor( tex, nComp_x, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#endif -#if (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); const int icomp = 0; ::SetEfieldOnPEC(icomp, domain_lo, domain_hi, iv, n, @@ -523,12 +518,7 @@ PEC::ApplyPECtoEfield ( }, tey, nComp_y, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#endif -#if (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); const int icomp = 1; ::SetEfieldOnPEC(icomp, domain_lo, domain_hi, iv, n, @@ -536,12 +526,7 @@ PEC::ApplyPECtoEfield ( }, tez, nComp_z, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#endif -#if (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); const int icomp = 2; ::SetEfieldOnPEC(icomp, domain_lo, domain_hi, iv, n, @@ -555,8 +540,8 @@ PEC::ApplyPECtoEfield ( void PEC::ApplyPECtoBfield ( std::array Bfield, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, const amrex::IntVect& ng_fieldgather, const amrex::Geometry& geom, const int lev, PatchType patch_type, const amrex::Vector& ref_ratios) { @@ -602,12 +587,7 @@ PEC::ApplyPECtoBfield ( amrex::ParallelFor( tbx, nComp_x, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#endif -#if (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); const int icomp = 0; ::SetBfieldOnPEC(icomp, domain_lo, domain_hi, iv, n, @@ -615,12 +595,7 @@ PEC::ApplyPECtoBfield ( }, tby, nComp_y, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#endif -#if (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); const int icomp = 1; ::SetBfieldOnPEC(icomp, domain_lo, domain_hi, iv, n, @@ -628,12 +603,7 @@ PEC::ApplyPECtoBfield ( }, tbz, nComp_z, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#endif -#if (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); const int icomp = 2; ::SetBfieldOnPEC(icomp, domain_lo, domain_hi, iv, n, @@ -657,10 +627,10 @@ PEC::ApplyPECtoBfield ( void PEC::ApplyReflectiveBoundarytoRhofield ( amrex::MultiFab* rho, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, - const amrex::Vector& particle_boundary_lo, - const amrex::Vector& particle_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, + const amrex::Array& particle_boundary_lo, + const amrex::Array& particle_boundary_hi, const amrex::Geometry& geom, const int lev, PatchType patch_type, const amrex::Vector& ref_ratios) { @@ -727,11 +697,7 @@ PEC::ApplyReflectiveBoundarytoRhofield ( // Loop over valid cells (i.e. cells inside the domain) amrex::ParallelFor(mfi.validbox(), nComp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#elif (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif // Store the array index const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); @@ -747,10 +713,10 @@ PEC::ApplyReflectiveBoundarytoRhofield ( void PEC::ApplyReflectiveBoundarytoJfield( amrex::MultiFab* Jx, amrex::MultiFab* Jy, amrex::MultiFab* Jz, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, - const amrex::Vector& particle_boundary_lo, - const amrex::Vector& particle_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, + const amrex::Array& particle_boundary_lo, + const amrex::Array& particle_boundary_hi, const amrex::Geometry& geom, const int lev, PatchType patch_type, const amrex::Vector& ref_ratios) { @@ -859,11 +825,7 @@ PEC::ApplyReflectiveBoundarytoJfield( // Loop over valid cells (i.e. cells inside the domain) amrex::ParallelFor(mfi.validbox(), Jx->nComp(), [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#elif (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif // Store the array index const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); @@ -894,11 +856,7 @@ PEC::ApplyReflectiveBoundarytoJfield( // Loop over valid cells (i.e. cells inside the domain) amrex::ParallelFor(mfi.validbox(), Jy->nComp(), [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#elif (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif // Store the array index const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); @@ -929,11 +887,7 @@ PEC::ApplyReflectiveBoundarytoJfield( // Loop over valid cells (i.e. cells inside the domain) amrex::ParallelFor(mfi.validbox(), Jz->nComp(), [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#elif (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif // Store the array index const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); @@ -948,8 +902,8 @@ PEC::ApplyReflectiveBoundarytoJfield( void PEC::ApplyPECtoElectronPressure ( amrex::MultiFab* Pefield, - const amrex::Vector& field_boundary_lo, - const amrex::Vector& field_boundary_hi, + const amrex::Array& field_boundary_lo, + const amrex::Array& field_boundary_hi, const amrex::Geometry& geom, const int lev, PatchType patch_type, const amrex::Vector& ref_ratios) { @@ -1000,11 +954,7 @@ PEC::ApplyPECtoElectronPressure ( // Loop over valid cells (i.e. cells inside the domain) amrex::ParallelFor(mfi.validbox(), nComp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) { -#if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) - amrex::ignore_unused(k); -#elif (defined WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif // Store the array index const amrex::IntVect iv(AMREX_D_DECL(i,j,k)); diff --git a/Source/Diagnostics/BTDiagnostics.cpp b/Source/Diagnostics/BTDiagnostics.cpp index 1cee9909226..6fdb605f8dc 100644 --- a/Source/Diagnostics/BTDiagnostics.cpp +++ b/Source/Diagnostics/BTDiagnostics.cpp @@ -170,18 +170,18 @@ void BTDiagnostics::DerivedInitData () if (final_snapshot_fill_iteration > warpx.maxStep()) { warpx.updateMaxStep(final_snapshot_fill_iteration); amrex::Print()<<"max_step insufficient to fill all BTD snapshots. Automatically increased to: " - << final_snapshot_fill_iteration << std::endl; + << final_snapshot_fill_iteration << "\n"; } if (final_snapshot_fill_time > warpx.stopTime()) { warpx.updateStopTime(final_snapshot_fill_time); amrex::Print()<<"stop_time insufficient to fill all BTD snapshots. Automatically increased to: " - << final_snapshot_fill_time << std::endl; + << final_snapshot_fill_time << "\n"; } if (warpx.maxStep() == std::numeric_limits::max() && warpx.stopTime() == std::numeric_limits::max()) { amrex::Print()<<"max_step unspecified and stop time unspecified. Setting max step to " - <(amrex::Math::floor(lx)); -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ) - const amrex::ParticleReal y = p.pos(1); - const amrex::Real ly = (y - plo[1]) * dxi[1]; - jj = static_cast(amrex::Math::floor(ly)); -#endif -#if defined(WARPX_DIM_3D) - const amrex::ParticleReal z = p.pos(2); - const amrex::Real lz = (z - plo[2]) * dxi[2]; - kk = static_cast(amrex::Math::floor(lz)); -#endif + const auto [ii, jj, kk] = amrex::getParticleCell(p, plo, dxi).dim3(); // Fix dimensions since parser assumes u = gamma * v / c const amrex::ParticleReal ux = p.rdata(PIdx::ux) / PhysConst::c; diff --git a/Source/Diagnostics/ComputeDiagFunctors/TemperatureFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/TemperatureFunctor.cpp index c42f8970d5e..cdf86c3b63d 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/TemperatureFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/TemperatureFunctor.cpp @@ -53,22 +53,7 @@ TemperatureFunctor::operator() (amrex::MultiFab& mf_dst, const int dcomp, const amrex::GpuArray const& dxi) { // Get position in AMReX convention to calculate corresponding index. - // Ideally this will be replaced with the AMReX NGP interpolator - // Always do x direction. - int ii = 0, jj = 0, kk = 0; - const amrex::ParticleReal x = p.pos(0); - const amrex::Real lx = (x - plo[0]) * dxi[0]; - ii = static_cast(amrex::Math::floor(lx)); -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ) - const amrex::ParticleReal y = p.pos(1); - const amrex::Real ly = (y - plo[1]) * dxi[1]; - jj = static_cast(amrex::Math::floor(ly)); -#endif -#if defined(WARPX_DIM_3D) - const amrex::ParticleReal z = p.pos(2); - const amrex::Real lz = (z - plo[2]) * dxi[2]; - kk = static_cast(amrex::Math::floor(lz)); -#endif + const auto [ii, jj, kk] = amrex::getParticleCell(p, plo, dxi).dim3(); const amrex::ParticleReal w = p.rdata(PIdx::w); const amrex::ParticleReal ux = p.rdata(PIdx::ux); @@ -103,34 +88,20 @@ TemperatureFunctor::operator() (amrex::MultiFab& mf_dst, const int dcomp, const for (WarpXParIter pti(pc, m_lev); pti.isValid(); ++pti) { const long np = pti.numParticles(); + auto& tile = pti.GetParticleTile(); + auto ptd = tile.getParticleTileData(); amrex::ParticleReal* wp = pti.GetAttribs(PIdx::w).dataPtr(); amrex::ParticleReal* uxp = pti.GetAttribs(PIdx::ux).dataPtr(); amrex::ParticleReal* uyp = pti.GetAttribs(PIdx::uy).dataPtr(); amrex::ParticleReal* uzp = pti.GetAttribs(PIdx::uz).dataPtr(); - auto const GetPosition = GetParticlePosition(pti); - amrex::Array4 const& out_array = sum_mf.array(pti); amrex::ParallelFor(np, [=] AMREX_GPU_DEVICE (long ip) { - // --- Get particle quantities - amrex::ParticleReal xp, yp, zp; - GetPosition.AsStored(ip, xp, yp, zp); - // Get position in AMReX convention to calculate corresponding index. - int ii = 0, jj = 0, kk = 0; - const amrex::Real lx = (xp - plo[0]) * dxi[0]; - ii = static_cast(amrex::Math::floor(lx)); -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const amrex::Real lz = (zp - plo[1]) * dxi[1]; - jj = static_cast(amrex::Math::floor(lz)); -#elif defined(WARPX_DIM_3D) - const amrex::Real ly = (yp - plo[1]) * dxi[1]; - jj = static_cast(amrex::Math::floor(ly)); - const amrex::Real lz = (zp - plo[2]) * dxi[2]; - kk = static_cast(amrex::Math::floor(lz)); -#endif + const auto p = WarpXParticleContainer::ParticleType(ptd, ip); + const auto [ii, jj, kk] = getParticleCell(p, plo, dxi).dim3(); const amrex::ParticleReal w = wp[ip]; const amrex::ParticleReal ux = uxp[ip] - out_array(ii, jj, kk, 1); diff --git a/Source/Diagnostics/Diagnostics.cpp b/Source/Diagnostics/Diagnostics.cpp index f6e2da74127..dc28aeda095 100644 --- a/Source/Diagnostics/Diagnostics.cpp +++ b/Source/Diagnostics/Diagnostics.cpp @@ -4,6 +4,7 @@ #include "ComputeDiagFunctors/BackTransformParticleFunctor.H" #include "Diagnostics/FlushFormats/FlushFormat.H" #include "Diagnostics/ParticleDiag/ParticleDiag.H" +#include "FlushFormats/FlushFormatCatalyst.H" #include "FlushFormats/FlushFormatAscent.H" #include "FlushFormats/FlushFormatCheckpoint.H" #ifdef WARPX_USE_OPENPMD @@ -505,7 +506,9 @@ Diagnostics::InitBaseData () m_flush_format = std::make_unique() ; } else if (m_format == "ascent"){ m_flush_format = std::make_unique(); - } else if (m_format == "sensei"){ + } else if (m_format == "catalyst") { + m_flush_format = std::make_unique(); + } else if (m_format == "sensei") { #ifdef AMREX_USE_SENSEI_INSITU m_flush_format = std::make_unique( dynamic_cast(const_cast(&warpx)), diff --git a/Source/Diagnostics/FlushFormats/CMakeLists.txt b/Source/Diagnostics/FlushFormats/CMakeLists.txt index fea3124302a..f124b400a2b 100644 --- a/Source/Diagnostics/FlushFormats/CMakeLists.txt +++ b/Source/Diagnostics/FlushFormats/CMakeLists.txt @@ -2,6 +2,8 @@ foreach(D IN LISTS WarpX_DIMS) warpx_set_suffix_dims(SD ${D}) target_sources(lib_${SD} PRIVATE + FlushFormatInSitu.cpp + FlushFormatCatalyst.cpp FlushFormatAscent.cpp FlushFormatCheckpoint.cpp FlushFormatPlotfile.cpp diff --git a/Source/Diagnostics/FlushFormats/FlushFormatAscent.H b/Source/Diagnostics/FlushFormats/FlushFormatAscent.H index 9d8d3fcd7d2..a5a10d77bdc 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatAscent.H +++ b/Source/Diagnostics/FlushFormats/FlushFormatAscent.H @@ -1,7 +1,7 @@ #ifndef WARPX_FLUSHFORMATASCENT_H_ #define WARPX_FLUSHFORMATASCENT_H_ -#include "FlushFormat.H" +#include "FlushFormatInSitu.H" #include "Diagnostics/ParticleDiag/ParticleDiag_fwd.H" @@ -24,7 +24,7 @@ * In particular, function WriteToFile takes fields and particles as input arguments, * and calls amrex functions to do the in-situ visualization. */ -class FlushFormatAscent : public FlushFormat +class FlushFormatAscent : public FlushFormatInSitu { public: /** Do in-situ visualization for field and particle data */ @@ -43,15 +43,6 @@ public: const amrex::Geometry& full_BTD_snapshot = amrex::Geometry(), bool isLastBTDFlush = false ) const override; -#ifdef AMREX_USE_ASCENT - /** \brief Do in-situ visualization for particle data. - * \param[in] particle_diags Each element of this vector handles output of 1 species. - * \param[out] a_bp_mesh blueprint mesh generated from the container - * Only compile if AMREX_USE_ASCENT because we need to pass a conduit class - */ - void WriteParticles(const amrex::Vector& particle_diags, conduit::Node& a_bp_mesh) const; -#endif - FlushFormatAscent () = default; ~FlushFormatAscent() override = default; diff --git a/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp b/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp index 0024122ebf9..36f0ef05faa 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp @@ -71,53 +71,3 @@ FlushFormatAscent::WriteToFile ( #endif // AMREX_USE_ASCENT amrex::ignore_unused(prefix, plot_raw_fields, plot_raw_fields_guards); } - -#ifdef AMREX_USE_ASCENT -void -FlushFormatAscent::WriteParticles(const amrex::Vector& particle_diags, conduit::Node& a_bp_mesh) const -{ - WARPX_PROFILE("FlushFormatAscent::WriteParticles()"); - - // wrap particle data for each species - // we prefix the fields with "particle_{species_name}" b/c we - // want to to uniquely name all the fields that can be plotted - - for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) { - Vector particle_varnames; - Vector particle_int_varnames; - std::string prefix = "particle_" + particle_diags[i].getSpeciesName(); - - // Get pc for species - // auto& pc = mypc->GetParticleContainer(i); - WarpXParticleContainer* pc = particle_diags[i].getParticleContainer(); - - // get names of real comps - std::map real_comps_map = pc->getParticleComps(); - - // WarpXParticleContainer compile-time extra SoA attributes (Real): PIdx::nattribs - // not an efficient search, but N is small... - for(int j = 0; j < PIdx::nattribs; ++j) - { - auto rvn_it = real_comps_map.begin(); - for (; rvn_it != real_comps_map.end(); ++rvn_it) - if (rvn_it->second == j) - break; - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - rvn_it != real_comps_map.end(), - "Ascent: SoA real attribute not found"); - std::string varname = rvn_it->first; - particle_varnames.push_back(prefix + "_" + varname); - } - // WarpXParticleContainer compile-time extra SoA attributes (int): 0 - - // WarpXParticleContainer "runtime" SoA attributes (Real), e.g QED: to do - - // wrap pc for current species into a blueprint topology - amrex::ParticleContainerToBlueprint(*pc, - particle_varnames, - particle_int_varnames, - a_bp_mesh, - prefix); - } -} -#endif // AMREX_USE_ASCENT diff --git a/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H b/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H new file mode 100644 index 00000000000..6974bf731a6 --- /dev/null +++ b/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.H @@ -0,0 +1,64 @@ +#ifndef WARPX_FLUSHFORMATCATALYST_H_ +#define WARPX_FLUSHFORMATCATALYST_H_ + +#include "FlushFormatInSitu.H" + +#include "Diagnostics/ParticleDiag/ParticleDiag_fwd.H" + +#ifdef AMREX_USE_CONDUIT +# include +#endif +#include +#include + +#include + +#ifdef AMREX_USE_CATALYST +# include +#endif + +#include + +/** + * \brief This class aims at dumping performing in-situ analysis and visualization + * with Catalyst. Catalyst initialize and finalize are called in the constructor + * and destructor respectivelyThe function WriteToFile takes in the particles, + * meshes, and fields, and formats them to be used by given pipeline scripts. All + * exports are defined and executed externally through the given catalyst pipeline + * and implementation. + */ +class FlushFormatCatalyst : public FlushFormatInSitu +{ +public: + // Initialize + FlushFormatCatalyst(); + + /** Send particle, mesh, and field information through the catalyst pipeline */ + void WriteToFile ( + const amrex::Vector& varnames, + const amrex::Vector& mf, + amrex::Vector& geom, + amrex::Vector iteration, double time, + const amrex::Vector& particle_diags, int nlev, + std::string prefix, int file_min_digits, + bool plot_raw_fields, + bool plot_raw_fields_guards, + bool use_pinned_pc = false, + bool isBTD = false, int snapshotID = -1, + int bufferID = 1, int numBuffers = 1, + const amrex::Geometry& full_BTD_snapshot = amrex::Geometry(), + bool isLastBTDFlush = false) const override; + +#ifdef AMREX_USE_CATALYST + ~FlushFormatCatalyst() override; +#else + ~FlushFormatCatalyst() override = default; +#endif + + FlushFormatCatalyst ( FlushFormatCatalyst const &) = default; + FlushFormatCatalyst& operator= ( FlushFormatCatalyst const & ) = default; + FlushFormatCatalyst ( FlushFormatCatalyst&& ) = default; + FlushFormatCatalyst& operator= ( FlushFormatCatalyst&& ) = default; +}; + +#endif diff --git a/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp b/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp new file mode 100644 index 00000000000..425c13de6a4 --- /dev/null +++ b/Source/Diagnostics/FlushFormats/FlushFormatCatalyst.cpp @@ -0,0 +1,211 @@ +#include "FlushFormatCatalyst.H" + +#include "WarpX.H" +#include "Utils/TextMsg.H" +#include "Utils/WarpXProfilerWrapper.H" + +#include +#include +#include + +#include +#include + +#ifdef AMREX_USE_CATALYST + #include "conduit_cpp_to_c.hpp" +#endif + +#ifdef AMREX_USE_CATALYST +namespace internal { + +void EmptyParticleData ( + const std::vector& real_fields, + conduit::Node& node) +{ + const std::string topology_name = "particles"; + + // make a dummy node for catalyst + const std::string& patch_name = amrex::Concatenate("domain_x", 0, 6); + conduit::Node &patch = node[patch_name]; + + patch["state/domain_id"] = 0; + + std::string coordset_name = topology_name + "+coords"; + conduit::Node &n_coords = patch["coordsets"][coordset_name]; + n_coords["type"] = "explicit"; + + // create an explicit points topology + conduit::Node &n_topo = patch["topologies"][topology_name]; + n_topo["coordset"] = coordset_name; + n_topo["type"] = "unstructured"; + n_topo["elements/shape"] = "point"; + n_topo["elements/connectivity"].set(conduit::DataType::c_int(0)); + + n_coords["values/x"].set(conduit::DataType::c_int(0)); + n_coords["values/y"].set(conduit::DataType::c_int(0)); + n_coords["values/z"].set(conduit::DataType::c_int(0)); + + conduit::Node &n_fields = patch["fields"]; + + // id field + conduit::Node &n_f_id = n_fields[topology_name + "_id"]; + n_f_id["topology"] = topology_name; + n_f_id["association"] = "element"; + n_f_id["values"].set(conduit::DataType::c_int(0)); + + // cpu field + conduit::Node &n_f_cpu = n_fields[topology_name + "_cpu"]; + n_f_cpu["topology"] = topology_name; + n_f_cpu["association"] = "element"; + n_f_cpu["values"].set(conduit::DataType::c_int(0)); + + for (auto& rfield : real_fields) + { + conduit::Node & n_f = n_fields[rfield]; + n_f["topology"] = topology_name; + n_f["association"] = "element"; + n_f["values"].set(conduit::DataType::c_int(0)); + } +} + +} // namespace internal +#endif + +using namespace amrex; + +FlushFormatCatalyst::FlushFormatCatalyst() { + ParmParse const pp_catalyst("catalyst"); + std::string scriptPaths; + std::string implementation {"paraview"}; + std::string searchPaths; + pp_catalyst.query("script_paths", scriptPaths); + pp_catalyst.query("implementation", implementation); + pp_catalyst.query("implementation_search_paths", searchPaths); + +#ifdef AMREX_USE_CATALYST + conduit::Node node; + + // Loop over all given paths and load all the scripts. Delimiters are ';' and ':' + size_t scriptNumber = 0; + size_t pos = 0; + std::string subpath; + while (scriptPaths.find(':') != std::string::npos || scriptPaths.find(';') != std::string::npos) { + pos = std::min(scriptPaths.find(':'), scriptPaths.find(';')); + subpath = scriptPaths.substr(0, pos); + + node["catalyst/scripts/script" + std::to_string(scriptNumber)].set_string(subpath); + + scriptNumber++; + scriptPaths.erase(0, pos + 1); + } + // Prevent empty end paths + if (scriptPaths.length() != 0) { + node["catalyst/scripts/script" + std::to_string(scriptNumber)].set_string(scriptPaths); + } + + node["catalyst_load/implementation"].set_string(implementation); + node["catalyst_load/search_paths/" + implementation].set_string(searchPaths); + + catalyst_status err = catalyst_initialize(conduit::c_node(&node)); + if (err != catalyst_status_ok) + { + std::string message = " Error: Failed to initialize Catalyst!\n"; + std::cerr << message << err << std::endl; + amrex::Print() << message; + amrex::Abort(message); + } + +#endif // AMREX_USE_CATALYST +} + +void +FlushFormatCatalyst::WriteToFile ( + const amrex::Vector& varnames, + const amrex::Vector& mf, + amrex::Vector& geom, + amrex::Vector iteration, double time, + const amrex::Vector& particle_diags, int nlev, + const std::string prefix, int file_min_digits, bool plot_raw_fields, + bool plot_raw_fields_guards, + bool /*use_pinned_pc*/, + bool isBTD, int /*snapshotID*/, int /*bufferID*/, int /*numBuffers*/, + const amrex::Geometry& /*full_BTD_snapshot*/, + bool /*isLastBTDFlush*/) const +{ +#ifdef AMREX_USE_CATALYST + amrex::Print() << Utils::TextMsg::Info("Running Catalyst pipeline scripts..."); + + WARPX_PROFILE("FlushFormatCatalyst::WriteToFile()"); + auto & warpx = WarpX::GetInstance(); + + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + !isBTD, + "In-situ visualization is not currently supported for back-transformed diagnostics."); + + // Mesh data + WARPX_PROFILE_VAR("FlushFormatCatalyst::WriteToFile::MultiLevelToBlueprint", prof_catalyst_mesh_blueprint); + conduit::Node node; + auto & state = node["catalyst/state"]; + state["timestep"].set(iteration[0]); + state["time"].set(time); + + auto& meshChannel = node["catalyst/channels/mesh"]; + meshChannel["type"].set_string("multimesh"); + auto& meshData = meshChannel["data"]; + + amrex::MultiLevelToBlueprint( + nlev, amrex::GetVecOfConstPtrs(mf), varnames, geom, time, iteration, warpx.refRatio(), meshData); + WARPX_PROFILE_VAR_STOP(prof_catalyst_mesh_blueprint); + + // Particle data + WARPX_PROFILE_VAR("FlushFormatCatalyst::WriteToFile::WriteParticles", prof_catalyst_particles); + auto& particleChannel = node["catalyst/channels/particles"]; + particleChannel["type"].set_string("multimesh"); + auto& particleData = particleChannel["data"]; + + conduit::Node amrexParticles; + WriteParticles(particle_diags, amrexParticles); + particleData.update(amrexParticles); + if(!particleData.dtype().is_object()) + { + internal::EmptyParticleData(varnames, particleData); + } + + WARPX_PROFILE_VAR_STOP(prof_catalyst_particles); + + // Execution + WARPX_PROFILE_VAR("FlushFormatCatalyst::WriteToFile::execute", prof_catalyst_execute); + catalyst_status err = catalyst_execute(conduit::c_node(&node)); + if (err != catalyst_status_ok) + { + std::string message = " Error: Failed to execute Catalyst!\n"; + std::cerr << message << err << std::endl; + amrex::Print() << message; + } + WARPX_PROFILE_VAR_STOP(prof_catalyst_execute); + +#else + amrex::ignore_unused(varnames, mf, geom, iteration, time, + particle_diags, nlev, file_min_digits, isBTD); +#endif // AMREX_USE_CATALYST + amrex::ignore_unused(prefix, plot_raw_fields, file_min_digits, plot_raw_fields_guards); +} + +#ifdef AMREX_USE_CATALYST +FlushFormatCatalyst::~FlushFormatCatalyst() { + + conduit::Node node; + catalyst_status err = catalyst_finalize(conduit::c_node(&node)); + if (err != catalyst_status_ok) + { + std::string message = " Error: Failed to finalize Catalyst!\n"; + std::cerr << message << err << std::endl; + amrex::Print() << message; + amrex::Abort(message); + } else { + // Temporary, remove for final + std::cout << "Successfully finalized Catalyst\n"; + } + +} +#endif // AMREX_USE_CATALYST diff --git a/Source/Diagnostics/FlushFormats/FlushFormatInSitu.H b/Source/Diagnostics/FlushFormats/FlushFormatInSitu.H new file mode 100644 index 00000000000..b71fc79b510 --- /dev/null +++ b/Source/Diagnostics/FlushFormats/FlushFormatInSitu.H @@ -0,0 +1,48 @@ +#ifndef WARPX_FLUSHFORMATINSITU_H_ +#define WARPX_FLUSHFORMATINSITU_H_ + +#include "FlushFormat.H" + +#include "Diagnostics/ParticleDiag/ParticleDiag_fwd.H" + +#if defined(AMREX_USE_CONDUIT) || defined(AMREX_USE_ASCENT) +# include +#endif +#include +#include + +#include + +#include + +/** + * \brief This class is a wrapper for the two single-backend in-situ formats, those + * being Catalyst and Ascent. They both use the exact same code for writing particles + * and this class aims to reduce redundancy by defining the method only once. + */ +class FlushFormatInSitu : public FlushFormat +{ +public: + // May need to include separate exporters for particles, meshes, etc etc. Would probably also be useful + // to give some higher level debug functions (like in the plotfile flush) since it's useful sometimes. + // Could probably also include AMREX_USE_ASCENT or AMREX_USE_CONDUIT in here + #if defined(AMREX_USE_CONDUIT) || defined(AMREX_USE_ASCENT) + /** \brief Do in-situ visualization for particle data. + * \param[in] particle_diags Each element of this vector handles output of 1 species. + * \param[out] a_bp_mesh blueprint mesh generated from the container + * Only compile if AMREX_USE_CONDUIT or AMREX_USE_ASCENT because we need to pass a + * conduit class (conduit is required for catalyst so it does not need to be checked) + */ + void WriteParticles(const amrex::Vector& particle_diags, conduit::Node& a_bp_mesh) const; + #endif + + FlushFormatInSitu () = default; + ~FlushFormatInSitu() override = default; + + FlushFormatInSitu ( FlushFormatInSitu const &) = default; + FlushFormatInSitu& operator= ( FlushFormatInSitu const & ) = default; + FlushFormatInSitu ( FlushFormatInSitu&& ) = default; + FlushFormatInSitu& operator= ( FlushFormatInSitu&& ) = default; +}; + +#endif diff --git a/Source/Diagnostics/FlushFormats/FlushFormatInSitu.cpp b/Source/Diagnostics/FlushFormats/FlushFormatInSitu.cpp new file mode 100644 index 00000000000..be3047d7ab6 --- /dev/null +++ b/Source/Diagnostics/FlushFormats/FlushFormatInSitu.cpp @@ -0,0 +1,71 @@ +#include "FlushFormatInSitu.H" + +#include "WarpX.H" +#include "Utils/TextMsg.H" +#include "Utils/WarpXProfilerWrapper.H" + +#include +#include +#include + +#include +#include + +#if defined(AMREX_USE_CONDUIT) || defined(AMREX_USE_ASCENT) + #include "conduit_cpp_to_c.hpp" +#endif + +using namespace amrex; + +#if defined(AMREX_USE_CONDUIT) || defined(AMREX_USE_ASCENT) +void +FlushFormatInSitu::WriteParticles(const amrex::Vector& particle_diags, conduit::Node& a_bp_mesh) const +{ + WARPX_PROFILE("FlushFormatInSitu::WriteParticles()"); + + // wrap particle data for each species + // we prefix the fields with "particle_{species_name}" b/c we + // want to to uniquely name all the fields that can be plotted + + for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) { + Vector particle_varnames; + Vector particle_int_varnames; + std::string prefix = "particle_" + particle_diags[i].getSpeciesName(); + + // Get pc for species + // auto& pc = mypc->GetParticleContainer(i); + WarpXParticleContainer* pc = particle_diags[i].getParticleContainer(); + + // get names of real comps + std::map real_comps_map = pc->getParticleComps(); + + // WarpXParticleContainer compile-time extra AoS attributes (Real): 0 + // WarpXParticleContainer compile-time extra AoS attributes (int): 0 + + // WarpXParticleContainer compile-time extra SoA attributes (Real): PIdx::nattribs + // not an efficient search, but N is small... + for(int j = 0; j < PIdx::nattribs; ++j) + { + auto rvn_it = real_comps_map.begin(); + for (; rvn_it != real_comps_map.end(); ++rvn_it) + if (rvn_it->second == j) + break; + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + rvn_it != real_comps_map.end(), + "WarpX In Situ: SoA real attribute not found"); + std::string varname = rvn_it->first; + particle_varnames.push_back(prefix + "_" + varname); + } + // WarpXParticleContainer compile-time extra SoA attributes (int): 0 + + // WarpXParticleContainer "runtime" SoA attributes (Real), e.g QED: to do + + // wrap pc for current species into a blueprint topology + amrex::ParticleContainerToBlueprint(*pc, + particle_varnames, + particle_int_varnames, + a_bp_mesh, + prefix); + } +} +#endif // defined(AMREX_USE_CONDUIT) || defined(AMREX_USE_ASCENT) diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp index 94b9901b06e..f6c73d9fa7e 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp @@ -226,7 +226,7 @@ FlushFormatPlotfile::WriteJobInfo(const std::string& dir) const jobInfoFile << " Inputs File Parameters\n"; jobInfoFile << PrettyLine; - ParmParse::dumpTable(jobInfoFile, true); + ParmParse::prettyPrintTable(jobInfoFile); jobInfoFile.close(); } diff --git a/Source/Diagnostics/FlushFormats/Make.package b/Source/Diagnostics/FlushFormats/Make.package index 8b3a796007a..59c4525da2e 100644 --- a/Source/Diagnostics/FlushFormats/Make.package +++ b/Source/Diagnostics/FlushFormats/Make.package @@ -1,5 +1,7 @@ CEXE_sources += FlushFormatPlotfile.cpp CEXE_sources += FlushFormatCheckpoint.cpp +CEXE_sources += FlushFormatInSitu.cpp +CEXE_sources += FlushFormatCatalyst.cpp CEXE_sources += FlushFormatAscent.cpp CEXE_sources += FlushFormatSensei.cpp ifeq ($(USE_OPENPMD), TRUE) diff --git a/Source/Diagnostics/FullDiagnostics.cpp b/Source/Diagnostics/FullDiagnostics.cpp index 55af73d6408..bcf613f49b0 100644 --- a/Source/Diagnostics/FullDiagnostics.cpp +++ b/Source/Diagnostics/FullDiagnostics.cpp @@ -90,8 +90,8 @@ FullDiagnostics::ReadParameters () WARPX_ALWAYS_ASSERT_WITH_MESSAGE( m_format == "plotfile" || m_format == "openpmd" || m_format == "checkpoint" || m_format == "ascent" || - m_format == "sensei", - ".format must be plotfile or openpmd or checkpoint or ascent or sensei"); + m_format == "sensei" || m_format == "catalyst", + ".format must be plotfile or openpmd or checkpoint or ascent or catalyst or sensei"); std::vector intervals_string_vec = {"0"}; pp_diag_name.getarr("intervals", intervals_string_vec); m_intervals = utils::parser::IntervalsParser(intervals_string_vec); diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index bfb1867e741..bf67b51bbeb 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -241,7 +241,7 @@ MultiParticleContainer::WriteHeader (std::ostream& os) const void storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, - int electrostatic_solver_id, bool is_full_diagnostic ) { + ElectrostaticSolverAlgo electrostatic_solver_id, bool is_full_diagnostic ) { using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; diff --git a/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp b/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp index 9b5a28a3516..af18ab508a9 100644 --- a/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp +++ b/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp @@ -109,7 +109,7 @@ BeamRelevant::BeamRelevant (const std::string& rd_name) ofs << "[" << c++ << "]alpha_y()"; ofs << m_sep; ofs << "[" << c++ << "]beta_x(m)"; ofs << m_sep; ofs << "[" << c++ << "]beta_y(m)"; ofs << m_sep; - ofs << "[" << c++ << "]charge(C)"; ofs << std::endl; + ofs << "[" << c++ << "]charge(C)"; ofs << "\n"; #elif (defined WARPX_DIM_XZ) int c = 0; ofs << "#"; @@ -131,7 +131,7 @@ BeamRelevant::BeamRelevant (const std::string& rd_name) ofs << "[" << c++ << "]emittance_z(m)"; ofs << m_sep; ofs << "[" << c++ << "]alpha_x()"; ofs << m_sep; ofs << "[" << c++ << "]beta_x(m)"; ofs << m_sep; - ofs << "[" << c++ << "]charge(C)"; ofs << std::endl; + ofs << "[" << c++ << "]charge(C)"; ofs << "\n"; #elif (defined WARPX_DIM_1D_Z) int c = 0; ofs << "#"; @@ -148,7 +148,7 @@ BeamRelevant::BeamRelevant (const std::string& rd_name) ofs << "[" << c++ << "]pz_rms(kg*m/s)"; ofs << m_sep; ofs << "[" << c++ << "]gamma_rms()"; ofs << m_sep; ofs << "[" << c++ << "]emittance_z(m)"; ofs << m_sep; - ofs << "[" << c++ << "]charge(C)"; ofs << std::endl; + ofs << "[" << c++ << "]charge(C)"; ofs << "\n"; #endif // close file ofs.close(); diff --git a/Source/Diagnostics/ReducedDiags/CMakeLists.txt b/Source/Diagnostics/ReducedDiags/CMakeLists.txt index e63764bc24f..4f0b05f6180 100644 --- a/Source/Diagnostics/ReducedDiags/CMakeLists.txt +++ b/Source/Diagnostics/ReducedDiags/CMakeLists.txt @@ -4,6 +4,7 @@ foreach(D IN LISTS WarpX_DIMS) PRIVATE BeamRelevant.cpp ColliderRelevant.cpp + DifferentialLuminosity.cpp FieldEnergy.cpp FieldProbe.cpp FieldProbeParticleContainer.cpp diff --git a/Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp b/Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp index 2991831420e..975fed6d74c 100644 --- a/Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp +++ b/Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp @@ -8,6 +8,7 @@ #include "ChargeOnEB.H" #include "Diagnostics/ReducedDiags/ReducedDiags.H" +#include "EmbeddedBoundary/Enabled.H" #include "FieldSolver/Fields.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" @@ -24,11 +25,13 @@ #include #include +#include #include using namespace amrex; using namespace warpx::fields; + // constructor ChargeOnEB::ChargeOnEB (const std::string& rd_name) : ReducedDiags{rd_name} @@ -44,6 +47,10 @@ ChargeOnEB::ChargeOnEB (const std::string& rd_name) "ChargeOnEB reduced diagnostics only works when compiling with EB support"); #endif + if (!EB::enabled()) { + throw std::runtime_error("ChargeOnEB reduced diagnostics only works when EBs are enabled at runtime"); + } + // resize data array m_data.resize(1, 0.0_rt); @@ -72,8 +79,7 @@ ChargeOnEB::ChargeOnEB (const std::string& rd_name) ofs << m_sep; ofs << "[" << c++ << "]time(s)"; ofs << m_sep; - ofs << "[" << c++ << "]Charge (C)"; - ofs << std::endl; + ofs << "[" << c++ << "]Charge (C)\n"; // close file ofs.close(); } @@ -87,6 +93,9 @@ void ChargeOnEB::ComputeDiags (const int step) // Judge whether the diags should be done if (!m_intervals.contains(step+1)) { return; } + if (!EB::enabled()) { + throw std::runtime_error("ChargeOnEB::ComputeDiags only works when EBs are enabled at runtime"); + } #if ((defined WARPX_DIM_3D) && (defined AMREX_USE_EB)) // get a reference to WarpX instance auto & warpx = WarpX::GetInstance(); @@ -132,9 +141,9 @@ void ChargeOnEB::ComputeDiags (const int step) // Skip boxes that do not intersect with the embedded boundary // (i.e. either fully covered or fully regular) - amrex::FabType fab_type = eb_flag[mfi].getType(box); - if (fab_type == amrex::FabType::regular) continue; - if (fab_type == amrex::FabType::covered) continue; + const amrex::FabType fab_type = eb_flag[mfi].getType(box); + if (fab_type == amrex::FabType::regular) { continue; } + if (fab_type == amrex::FabType::covered) { continue; } // Extract data for electric field const amrex::Array4 & Ex_arr = Ex.array(mfi); @@ -153,7 +162,7 @@ void ChargeOnEB::ComputeDiags (const int step) [=] AMREX_GPU_DEVICE (int i, int j, int k) { // Only cells that are partially covered do contribute to the integral - if (eb_flag_arr(i,j,k).isRegular() || eb_flag_arr(i,j,k).isCovered()) return; + if (eb_flag_arr(i,j,k).isRegular() || eb_flag_arr(i,j,k).isCovered()) { return; } // Find nodal point which is outside of the EB // (eb_normal points towards the *interior* of the EB) @@ -164,14 +173,14 @@ void ChargeOnEB::ComputeDiags (const int step) // Find cell-centered point which is outside of the EB // (eb_normal points towards the *interior* of the EB) int i_c = i; - if ((eb_bnd_normal_arr(i,j,k,0)>0) && (eb_bnd_cent_arr(i,j,k,0)<=0)) i_c -= 1; - if ((eb_bnd_normal_arr(i,j,k,0)<0) && (eb_bnd_cent_arr(i,j,k,0)>=0)) i_c += 1; + if ((eb_bnd_normal_arr(i,j,k,0)>0) && (eb_bnd_cent_arr(i,j,k,0)<=0)) { i_c -= 1; } + if ((eb_bnd_normal_arr(i,j,k,0)<0) && (eb_bnd_cent_arr(i,j,k,0)>=0)) { i_c += 1; } int j_c = j; - if ((eb_bnd_normal_arr(i,j,k,1)>0) && (eb_bnd_cent_arr(i,j,k,1)<=0)) j_c -= 1; - if ((eb_bnd_normal_arr(i,j,k,1)<0) && (eb_bnd_cent_arr(i,j,k,1)>=0)) j_c += 1; + if ((eb_bnd_normal_arr(i,j,k,1)>0) && (eb_bnd_cent_arr(i,j,k,1)<=0)) { j_c -= 1; } + if ((eb_bnd_normal_arr(i,j,k,1)<0) && (eb_bnd_cent_arr(i,j,k,1)>=0)) { j_c += 1; } int k_c = k; - if ((eb_bnd_normal_arr(i,j,k,2)>0) && (eb_bnd_cent_arr(i,j,k,2)<=0)) k_c -= 1; - if ((eb_bnd_normal_arr(i,j,k,2)<0) && (eb_bnd_cent_arr(i,j,k,2)>=0)) k_c += 1; + if ((eb_bnd_normal_arr(i,j,k,2)>0) && (eb_bnd_cent_arr(i,j,k,2)<=0)) { k_c -= 1; } + if ((eb_bnd_normal_arr(i,j,k,2)<0) && (eb_bnd_cent_arr(i,j,k,2)>=0)) { k_c += 1; } // Compute contribution to the surface integral $\int dS \cdot E$) amrex::Real local_integral_contribution = 0; @@ -182,9 +191,9 @@ void ChargeOnEB::ComputeDiags (const int step) // Add weighting if requested by user if (do_parser_weighting) { // Get the 3D position of the centroid of surface element - amrex::Real x = (i + 0.5_rt + eb_bnd_cent_arr(i,j,k,0))*dx[0] + real_box.lo(0); - amrex::Real y = (j + 0.5_rt + eb_bnd_cent_arr(i,j,k,1))*dx[1] + real_box.lo(1); - amrex::Real z = (k + 0.5_rt + eb_bnd_cent_arr(i,j,k,2))*dx[2] + real_box.lo(2); + const amrex::Real x = (i + 0.5_rt + eb_bnd_cent_arr(i,j,k,0))*dx[0] + real_box.lo(0); + const amrex::Real y = (j + 0.5_rt + eb_bnd_cent_arr(i,j,k,1))*dx[1] + real_box.lo(1); + const amrex::Real z = (k + 0.5_rt + eb_bnd_cent_arr(i,j,k,2))*dx[2] + real_box.lo(2); // Apply weighting local_integral_contribution *= fun_weightingparser(x, y, z); } diff --git a/Source/Diagnostics/ReducedDiags/ColliderRelevant.cpp b/Source/Diagnostics/ReducedDiags/ColliderRelevant.cpp index 1b0c74cf7fa..fb683e25319 100644 --- a/Source/Diagnostics/ReducedDiags/ColliderRelevant.cpp +++ b/Source/Diagnostics/ReducedDiags/ColliderRelevant.cpp @@ -181,7 +181,7 @@ ColliderRelevant::ColliderRelevant (const std::string& rd_name) const auto& el = m_headers_indices[name]; ofs << m_sep << "[" << el.idx + off << "]" << el.header; } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/ReducedDiags/DifferentialLuminosity.H b/Source/Diagnostics/ReducedDiags/DifferentialLuminosity.H new file mode 100644 index 00000000000..13c1dca55f9 --- /dev/null +++ b/Source/Diagnostics/ReducedDiags/DifferentialLuminosity.H @@ -0,0 +1,62 @@ +/* Copyright 2023 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Arianna Formenti + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_DIAGNOSTICS_REDUCEDDIAGS_DIFFERENTIALLUMINOSITY_H_ +#define WARPX_DIAGNOSTICS_REDUCEDDIAGS_DIFFERENTIALLUMINOSITY_H_ + +#include "ReducedDiags.H" +#include + +#include +#include +#include + +/** + * This class contains the differential luminosity diagnostics. + */ +class DifferentialLuminosity : public ReducedDiags +{ +public: + + /** + * constructor + * @param[in] rd_name reduced diags names + */ + DifferentialLuminosity(const std::string& rd_name); + + /// name of the two colliding species + std::vector m_beam_name; + + /// number of bins + int m_bin_num; + + /// max and min bin values + amrex::Real m_bin_max; + amrex::Real m_bin_min; + + /// bin size + amrex::Real m_bin_size; + + void ComputeDiags(int step) final; + +private: + /// auxiliary structure to store headers and indices of the reduced diagnostics + struct aux_header_index + { + std::string header; + int idx; + }; + + /// map to store header texts and indices of the reduced diagnostics + std::map m_headers_indices; + + // Array in which to accumulate the luminosity across timesteps + amrex::Gpu::DeviceVector< amrex::Real > d_data; +}; + +#endif // WARPX_DIAGNOSTICS_REDUCEDDIAGS_DIFFERENTIALLUMINOSITY_H_ diff --git a/Source/Diagnostics/ReducedDiags/DifferentialLuminosity.cpp b/Source/Diagnostics/ReducedDiags/DifferentialLuminosity.cpp new file mode 100644 index 00000000000..59a32cf0545 --- /dev/null +++ b/Source/Diagnostics/ReducedDiags/DifferentialLuminosity.cpp @@ -0,0 +1,273 @@ +/* Copyright 2023 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Arianna Formenti, Yinjian Zhao + * License: BSD-3-Clause-LBNL + */ +#include "DifferentialLuminosity.H" + +#include "Diagnostics/ReducedDiags/ReducedDiags.H" +#include "Particles/MultiParticleContainer.H" +#include "Particles/Pusher/GetAndSetPosition.H" +#include "Particles/SpeciesPhysicalProperties.H" +#include "Particles/WarpXParticleContainer.H" +#include "Utils/ParticleUtils.H" +#include "Utils/Parser/ParserUtils.H" +#include "Utils/WarpXConst.H" +#include "Utils/TextMsg.H" +#include "Utils/WarpXProfilerWrapper.H" +#include "WarpX.H" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using ParticleType = WarpXParticleContainer::ParticleType; +using ParticleTileType = WarpXParticleContainer::ParticleTileType; +using ParticleTileDataType = ParticleTileType::ParticleTileDataType; +using ParticleBins = amrex::DenseBins; +using index_type = ParticleBins::index_type; + +using namespace amrex; + +DifferentialLuminosity::DifferentialLuminosity (const std::string& rd_name) +: ReducedDiags{rd_name} +{ + // read colliding species names - must be 2 + const amrex::ParmParse pp_rd_name(m_rd_name); + pp_rd_name.getarr("species", m_beam_name); + + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + m_beam_name.size() == 2u, + "DifferentialLuminosity diagnostics must involve exactly two species"); + + // RZ coordinate is not supported +#if (defined WARPX_DIM_RZ) + WARPX_ABORT_WITH_MESSAGE( + "DifferentialLuminosity diagnostics do not work in RZ geometry."); +#endif + + // read bin parameters + int bin_num = 0; + amrex::Real bin_max = 0.0_rt, bin_min = 0.0_rt; + utils::parser::getWithParser(pp_rd_name, "bin_number", bin_num); + utils::parser::getWithParser(pp_rd_name, "bin_max", bin_max); + utils::parser::getWithParser(pp_rd_name, "bin_min", bin_min); + m_bin_num = bin_num; + m_bin_max = bin_max; + m_bin_min = bin_min; + m_bin_size = (bin_max - bin_min) / bin_num; + + // resize and zero-out data array + m_data.resize(m_bin_num,0.0_rt); + d_data.resize(m_bin_num,0.0_rt); + + if (amrex::ParallelDescriptor::IOProcessor()) + { + if ( m_write_header ) + { + // open file + std::ofstream ofs; + ofs.open(m_path + m_rd_name + "." + m_extension, + std::ofstream::out | std::ofstream::app); + // write header row + int off = 0; + ofs << "#"; + ofs << "[" << off++ << "]step()"; + ofs << m_sep; + ofs << "[" << off++ << "]time(s)"; + for (int i = 0; i < m_bin_num; ++i) + { + ofs << m_sep; + ofs << "[" << off++ << "]"; + const Real b = m_bin_min + m_bin_size*(Real(i)+0.5_rt); + ofs << "bin" << 1+i << "=" << b << "(eV)"; + } + ofs << "\n"; + // close file + ofs.close(); + } + } +} + +void DifferentialLuminosity::ComputeDiags (int step) +{ +#if defined(WARPX_DIM_RZ) + amrex::ignore_unused(step); +#else + WARPX_PROFILE("DifferentialLuminosity::ComputeDiags"); + + // Since this diagnostic *accumulates* the luminosity in the + // array d_data, we add contributions at *each timestep*, but + // we only write the data to file at intervals specified by the user. + + const Real c2_over_qe = PhysConst::c*PhysConst::c/PhysConst::q_e; + const Real inv_c2 = 1._rt/(PhysConst::c*PhysConst::c); + + // get a reference to WarpX instance + auto& warpx = WarpX::GetInstance(); + const Real dt = warpx.getdt(0); + // get cell volume + Geometry const & geom = warpx.Geom(0); + const Real dV = AMREX_D_TERM(geom.CellSize(0), *geom.CellSize(1), *geom.CellSize(2)); + + // declare local variables + auto const num_bins = m_bin_num; + Real const bin_min = m_bin_min; + Real const bin_size = m_bin_size; + + // get MultiParticleContainer class object + const MultiParticleContainer& mypc = warpx.GetPartContainer(); + + auto& species_1 = mypc.GetParticleContainerFromName(m_beam_name[0]); + auto& species_2 = mypc.GetParticleContainerFromName(m_beam_name[1]); + + const ParticleReal m1 = species_1.getMass(); + const ParticleReal m2 = species_2.getMass(); + + amrex::Real* const AMREX_RESTRICT dptr_data = d_data.dataPtr(); + + // Enable tiling + amrex::MFItInfo info; + if (amrex::Gpu::notInLaunchRegion()) { info.EnableTiling(WarpXParticleContainer::tile_size); } + + int const nlevs = std::max(0, species_1.finestLevel()+1); // species_1 ? + for (int lev = 0; lev < nlevs; ++lev) { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + + for (amrex::MFIter mfi = species_1.MakeMFIter(lev, info); mfi.isValid(); ++mfi){ + + ParticleTileType& ptile_1 = species_1.ParticlesAt(lev, mfi); + ParticleTileType& ptile_2 = species_2.ParticlesAt(lev, mfi); + + ParticleBins bins_1 = ParticleUtils::findParticlesInEachCell( lev, mfi, ptile_1 ); + ParticleBins bins_2 = ParticleUtils::findParticlesInEachCell( lev, mfi, ptile_2 ); + + // Species + const auto soa_1 = ptile_1.getParticleTileData(); + index_type* AMREX_RESTRICT indices_1 = bins_1.permutationPtr(); + index_type const* AMREX_RESTRICT cell_offsets_1 = bins_1.offsetsPtr(); + + // Particle data in the tile/box + amrex::ParticleReal * const AMREX_RESTRICT w1 = soa_1.m_rdata[PIdx::w]; + amrex::ParticleReal * const AMREX_RESTRICT u1x = soa_1.m_rdata[PIdx::ux]; + amrex::ParticleReal * const AMREX_RESTRICT u1y = soa_1.m_rdata[PIdx::uy]; // v*gamma=p/m + amrex::ParticleReal * const AMREX_RESTRICT u1z = soa_1.m_rdata[PIdx::uz]; + + const auto soa_2 = ptile_2.getParticleTileData(); + index_type* AMREX_RESTRICT indices_2 = bins_2.permutationPtr(); + index_type const* AMREX_RESTRICT cell_offsets_2 = bins_2.offsetsPtr(); + + amrex::ParticleReal * const AMREX_RESTRICT w2 = soa_2.m_rdata[PIdx::w]; + amrex::ParticleReal * const AMREX_RESTRICT u2x = soa_2.m_rdata[PIdx::ux]; + amrex::ParticleReal * const AMREX_RESTRICT u2y = soa_2.m_rdata[PIdx::uy]; + amrex::ParticleReal * const AMREX_RESTRICT u2z = soa_2.m_rdata[PIdx::uz]; + + // Extract low-level data + auto const n_cells = static_cast(bins_1.numBins()); + + // Loop over cells + amrex::ParallelFor( n_cells, + [=] AMREX_GPU_DEVICE (int i_cell) noexcept + { + // The particles from species1 that are in the cell `i_cell` are + // given by the `indices_1[cell_start_1:cell_stop_1]` + index_type const cell_start_1 = cell_offsets_1[i_cell]; + index_type const cell_stop_1 = cell_offsets_1[i_cell+1]; + // Same for species 2 + index_type const cell_start_2 = cell_offsets_2[i_cell]; + index_type const cell_stop_2 = cell_offsets_2[i_cell+1]; + + for(index_type i_1=cell_start_1; i_1=num_bins ) { continue; } // discard if out-of-range + + Real const v1_minus_v2_x = u1x[j_1]/gamma1 - u2x[j_2]/gamma2; + Real const v1_minus_v2_y = u1y[j_1]/gamma1 - u2y[j_2]/gamma2; + Real const v1_minus_v2_z = u1z[j_1]/gamma1 - u2z[j_2]/gamma2; + Real const v1_minus_v2_square = v1_minus_v2_x*v1_minus_v2_x + v1_minus_v2_y*v1_minus_v2_y + v1_minus_v2_z*v1_minus_v2_z; + + Real const u1_cross_u2_x = u1y[j_1]*u2z[j_2] - u1z[j_1]*u2y[j_2]; + Real const u1_cross_u2_y = u1z[j_1]*u2x[j_2] - u1x[j_1]*u2z[j_2]; + Real const u1_cross_u2_z = u1x[j_1]*u2y[j_2] - u1y[j_1]*u2x[j_2]; + + Real const v1_cross_v2_square = (u1_cross_u2_x*u1_cross_u2_x + u1_cross_u2_y*u1_cross_u2_y + u1_cross_u2_z*u1_cross_u2_z) / (gamma1*gamma1*gamma2*gamma2); + + Real const radicand = v1_minus_v2_square - v1_cross_v2_square * inv_c2; + + Real const dL_dEcom = std::sqrt( radicand ) * w1[j_1] * w2[j_2] / dV / bin_size * dt; // m^-2 eV^-1 + + amrex::HostDevice::Atomic::Add(&dptr_data[bin], dL_dEcom); + + } // particles species 2 + } // particles species 1 + }); // cells + } // boxes + } // levels + + // Only write to file at intervals specified by the user. + // At these intervals, the data needs to ready on the CPU, + // so we copy it from the GPU to the CPU and reduce across MPI ranks. + if (m_intervals.contains(step+1)) { + // blocking copy from device to host + amrex::Gpu::copy(amrex::Gpu::deviceToHost, + d_data.begin(), d_data.end(), m_data.begin()); + + // reduced sum over mpi ranks + ParallelDescriptor::ReduceRealSum + (m_data.data(), static_cast(m_data.size()), ParallelDescriptor::IOProcessorNumber()); + } + +#endif // not RZ + +} diff --git a/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp b/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp index 9c0fac101a2..fbfdaf11017 100644 --- a/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp @@ -67,7 +67,7 @@ FieldEnergy::FieldEnergy (const std::string& rd_name) ofs << m_sep; ofs << "[" << c++ << "]B_lev" + std::to_string(lev) + "(J)"; } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/ReducedDiags/FieldMaximum.cpp b/Source/Diagnostics/ReducedDiags/FieldMaximum.cpp index 24d9dda3ea6..4fbbd1ec82c 100644 --- a/Source/Diagnostics/ReducedDiags/FieldMaximum.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldMaximum.cpp @@ -92,7 +92,7 @@ FieldMaximum::FieldMaximum (const std::string& rd_name) ofs << m_sep; ofs << "[" << c++ << "]max_|B|_lev" + std::to_string(lev) + "(T)"; } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp b/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp index 7eb16efecff..72bece9265b 100644 --- a/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp @@ -87,7 +87,7 @@ FieldMomentum::FieldMomentum (const std::string& rd_name) ofs << "momentum_z_lev" << lev << "(kg*m/s)"; } - ofs << std::endl; + ofs << "\n"; ofs.close(); } } diff --git a/Source/Diagnostics/ReducedDiags/FieldProbe.cpp b/Source/Diagnostics/ReducedDiags/FieldProbe.cpp index 1113075f4cd..f498cea7566 100644 --- a/Source/Diagnostics/ReducedDiags/FieldProbe.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldProbe.cpp @@ -225,7 +225,7 @@ FieldProbe::FieldProbe (const std::string& rd_name) ofs << m_sep; ofs << "[" << c++ << "]part_S_lev" + std::to_string(lev) + u_map[FieldProbePIdx::S]; } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); @@ -678,7 +678,7 @@ void FieldProbe::WriteToFile (int step) const ofs << m_sep; ofs << sorted_data[i * noutputs + k]; } - ofs << std::endl; + ofs << "\n"; } // end loop over data size // close file ofs.close(); diff --git a/Source/Diagnostics/ReducedDiags/FieldReduction.H b/Source/Diagnostics/ReducedDiags/FieldReduction.H index f467499ad56..9574caa3d5d 100644 --- a/Source/Diagnostics/ReducedDiags/FieldReduction.H +++ b/Source/Diagnostics/ReducedDiags/FieldReduction.H @@ -73,7 +73,7 @@ private: std::unique_ptr m_parser; // Type of reduction (e.g. Maximum, Minimum or Sum) - int m_reduction_type; + ReductionType m_reduction_type; public: diff --git a/Source/Diagnostics/ReducedDiags/FieldReduction.cpp b/Source/Diagnostics/ReducedDiags/FieldReduction.cpp index 683ae1921d6..fbf67be4e4a 100644 --- a/Source/Diagnostics/ReducedDiags/FieldReduction.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldReduction.cpp @@ -60,9 +60,7 @@ FieldReduction::FieldReduction (const std::string& rd_name) parser_string = std::regex_replace(parser_string, std::regex("\n\\s*"), " "); // read reduction type - std::string reduction_type_string; - pp_rd_name.get("reduction_type", reduction_type_string); - m_reduction_type = GetAlgorithmInteger (pp_rd_name, "reduction_type"); + pp_rd_name.get_enum_sloppy("reduction_type", m_reduction_type, "-_"); if (amrex::ParallelDescriptor::IOProcessor()) { @@ -77,9 +75,9 @@ FieldReduction::FieldReduction (const std::string& rd_name) ofs << m_sep; ofs << "[" << c++ << "]time(s)"; ofs << m_sep; - ofs << "[" << c++ << "]" + reduction_type_string + " of " + parser_string + " (SI units)"; + ofs << "[" << c++ << "]" + amrex::getEnumNameString(m_reduction_type) + " of " + parser_string + " (SI units)"; - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp b/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp index 882c94b12eb..a11a8d35853 100644 --- a/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp +++ b/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp @@ -275,7 +275,7 @@ void LoadBalanceCosts::WriteToFile (int step) const // end loop over data size // end line - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); @@ -329,7 +329,7 @@ void LoadBalanceCosts::WriteToFile (int step) const ofstmp << m_sep; ofstmp << "[" << c++ << "]hostname_box_" + std::to_string(boxNumber) + "()"; } - ofstmp << std::endl; + ofstmp << "\n"; // open the data-containing file const std::string fileDataName = m_path + m_rd_name + "." + m_extension; @@ -360,7 +360,7 @@ void LoadBalanceCosts::WriteToFile (int step) const { ofstmp << m_sep << "NaN"; } - ofstmp << std::endl; + ofstmp << "\n"; } // close files diff --git a/Source/Diagnostics/ReducedDiags/LoadBalanceEfficiency.cpp b/Source/Diagnostics/ReducedDiags/LoadBalanceEfficiency.cpp index b6f3a58e670..6c1f46a6c54 100644 --- a/Source/Diagnostics/ReducedDiags/LoadBalanceEfficiency.cpp +++ b/Source/Diagnostics/ReducedDiags/LoadBalanceEfficiency.cpp @@ -50,7 +50,7 @@ LoadBalanceEfficiency::LoadBalanceEfficiency (const std::string& rd_name) ofs << m_sep; ofs << "[" << c++ << "]lev" + std::to_string(lev); } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); diff --git a/Source/Diagnostics/ReducedDiags/Make.package b/Source/Diagnostics/ReducedDiags/Make.package index a1f08a24da3..e840931f8d3 100644 --- a/Source/Diagnostics/ReducedDiags/Make.package +++ b/Source/Diagnostics/ReducedDiags/Make.package @@ -8,6 +8,7 @@ CEXE_sources += FieldProbeParticleContainer.cpp CEXE_sources += FieldMomentum.cpp CEXE_sources += BeamRelevant.cpp CEXE_sources += ColliderRelevant.cpp +CEXE_sources += DifferentialLuminosity.cpp CEXE_sources += LoadBalanceCosts.cpp CEXE_sources += LoadBalanceEfficiency.cpp CEXE_sources += ParticleHistogram.cpp diff --git a/Source/Diagnostics/ReducedDiags/MultiReducedDiags.cpp b/Source/Diagnostics/ReducedDiags/MultiReducedDiags.cpp index 73e63aeb4d3..25ea87d9f54 100644 --- a/Source/Diagnostics/ReducedDiags/MultiReducedDiags.cpp +++ b/Source/Diagnostics/ReducedDiags/MultiReducedDiags.cpp @@ -9,6 +9,7 @@ #include "BeamRelevant.H" #include "ChargeOnEB.H" #include "ColliderRelevant.H" +#include "DifferentialLuminosity.H" #include "FieldEnergy.H" #include "FieldMaximum.H" #include "FieldProbe.H" @@ -61,6 +62,7 @@ MultiReducedDiags::MultiReducedDiags () {"RhoMaximum", [](CS s){return std::make_unique(s);}}, {"BeamRelevant", [](CS s){return std::make_unique(s);}}, {"ColliderRelevant", [](CS s){return std::make_unique(s);}}, + {"DifferentialLuminosity",[](CS s){return std::make_unique(s);}}, {"LoadBalanceCosts", [](CS s){return std::make_unique(s);}}, {"LoadBalanceEfficiency", [](CS s){return std::make_unique(s);}}, {"ParticleHistogram", [](CS s){return std::make_unique(s);}}, diff --git a/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp b/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp index 9446af5e20c..41b58ea8fe3 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp @@ -78,7 +78,7 @@ ParticleEnergy::ParticleEnergy (const std::string& rd_name) ofs << m_sep; ofs << "[" << c++ << "]" << species_names[i] + "_mean(J)"; } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp b/Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp index 811fee7a9de..842dd3c9efd 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp @@ -140,7 +140,7 @@ ParticleExtrema::ParticleExtrema (const std::string& rd_name) const auto& el = m_headers_indices[name]; ofs << m_sep << "[" << el.idx + off << "]" << el.header; } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp index 4aeb2af526f..8ba78b30cf2 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp @@ -146,7 +146,7 @@ ParticleHistogram::ParticleHistogram (const std::string& rd_name) ofs << "bin" + std::to_string(1+i) + "=" + std::to_string(b) + "()"; } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp b/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp index 47d1ec2cdd4..8cd4a9bc00c 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp @@ -107,7 +107,7 @@ ParticleMomentum::ParticleMomentum (const std::string& rd_name) ofs << species_names[i] + "_mean_z(kg*m/s)"; } - ofs << std::endl; + ofs << "\n"; ofs.close(); } } diff --git a/Source/Diagnostics/ReducedDiags/ParticleNumber.cpp b/Source/Diagnostics/ReducedDiags/ParticleNumber.cpp index bfdf1daffe3..83dc3d118f6 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleNumber.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleNumber.cpp @@ -75,7 +75,7 @@ ParticleNumber::ParticleNumber (const std::string& rd_name) ofs << m_sep; ofs << "[" << c++ << "]" << species_names[i] + "_weight()"; } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp b/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp index e3835dde416..ec31d9de81c 100644 --- a/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp +++ b/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp @@ -121,7 +121,7 @@ void ReducedDiags::WriteToFile (int step) const // end loop over data size // end line - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); diff --git a/Source/Diagnostics/ReducedDiags/RhoMaximum.cpp b/Source/Diagnostics/ReducedDiags/RhoMaximum.cpp index 9902415d9a9..66460613a56 100644 --- a/Source/Diagnostics/ReducedDiags/RhoMaximum.cpp +++ b/Source/Diagnostics/ReducedDiags/RhoMaximum.cpp @@ -113,7 +113,7 @@ RhoMaximum::RhoMaximum (const std::string& rd_name) + "_|rho|_lev" + std::to_string(lev) + "(C/m^3)"; } } - ofs << std::endl; + ofs << "\n"; // close file ofs.close(); } diff --git a/Source/Diagnostics/WarpXIO.cpp b/Source/Diagnostics/WarpXIO.cpp index a17abe04178..a3b902386f6 100644 --- a/Source/Diagnostics/WarpXIO.cpp +++ b/Source/Diagnostics/WarpXIO.cpp @@ -11,6 +11,7 @@ #if (defined WARPX_DIM_RZ) && (defined WARPX_USE_FFT) # include "BoundaryConditions/PML_RZ.H" #endif +#include "EmbeddedBoundary/Enabled.H" #include "FieldIO.H" #include "Particles/MultiParticleContainer.H" #include "Utils/TextMsg.H" @@ -393,7 +394,7 @@ WarpX::InitFromCheckpoint () } } - InitializeEBGridData(maxLevel()); + if (EB::enabled()) { InitializeEBGridData(maxLevel()); } // Initialize particles mypc->AllocData(); diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 36827bd316a..4e1b6238adf 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -466,7 +466,7 @@ void WarpXOpenPMDPlot::CloseStep (bool isBTD, bool isLastBTDFlush) std::string const filename = GetFileName(filepath); std::ofstream pv_helper_file(m_dirPrefix + "/paraview.pmd"); - pv_helper_file << filename << std::endl; + pv_helper_file << filename << "\n"; pv_helper_file.close(); } } diff --git a/Source/EmbeddedBoundary/CMakeLists.txt b/Source/EmbeddedBoundary/CMakeLists.txt index 3fa0ea0228f..2fa5e3e602b 100644 --- a/Source/EmbeddedBoundary/CMakeLists.txt +++ b/Source/EmbeddedBoundary/CMakeLists.txt @@ -2,8 +2,10 @@ foreach(D IN LISTS WarpX_DIMS) warpx_set_suffix_dims(SD ${D}) target_sources(lib_${SD} PRIVATE + Enabled.cpp WarpXInitEB.cpp WarpXFaceExtensions.cpp WarpXFaceInfoBox.H + Enabled.cpp ) endforeach() diff --git a/Source/EmbeddedBoundary/DistanceToEB.H b/Source/EmbeddedBoundary/DistanceToEB.H index 7ee47c1172c..0c13724380c 100644 --- a/Source/EmbeddedBoundary/DistanceToEB.H +++ b/Source/EmbeddedBoundary/DistanceToEB.H @@ -14,8 +14,6 @@ #include #include -#ifdef AMREX_USE_EB - namespace DistanceToEB { @@ -28,7 +26,8 @@ amrex::Real dot_product (const amrex::RealVect& a, const amrex::RealVect& b) noe AMREX_GPU_HOST_DEVICE AMREX_INLINE void normalize (amrex::RealVect& a) noexcept { - amrex::Real inv_norm = 1.0/std::sqrt(dot_product(a,a)); + using namespace amrex::literals; + amrex::Real const inv_norm = 1.0_rt / std::sqrt(dot_product(a, a)); AMREX_D_DECL(a[0] *= inv_norm, a[1] *= inv_norm, a[2] *= inv_norm); @@ -46,6 +45,7 @@ amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SP amrex::Array4 const& phi, amrex::GpuArray const& dxi) noexcept { + using namespace amrex::literals; #if (defined WARPX_DIM_3D) amrex::RealVect normal{0.0, 0.0, 0.0}; @@ -53,11 +53,11 @@ amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SP for (int kk = 0; kk < 2; ++kk) { for (int jj=0; jj< 2; ++jj) { for (int ii = 0; ii < 2; ++ii) { - int icstart = ic + iic; - amrex::Real sign = (ii%2)*2. - 1.; - int wccomp = static_cast(iic%2); - int w1comp = static_cast(jj%2); - int w2comp = static_cast(kk%2); + int const icstart = ic + iic; + amrex::Real const sign = (ii%2)*2._rt - 1._rt; + int const wccomp = static_cast(iic%2); + int const w1comp = static_cast(jj%2); + int const w2comp = static_cast(kk%2); normal[0] += sign * phi(icstart + ii, j + jj, k + kk) * dxi[0] * Wc[0][wccomp] * W[1][w1comp] * W[2][w2comp]; } } @@ -67,11 +67,11 @@ amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SP for (int kk = 0; kk < 2; ++kk) { for (int ii=0; ii< 2; ++ii) { for (int jj = 0; jj < 2; ++jj) { - int jcstart = jc + iic; - amrex::Real sign = (jj%2)*2. - 1.; - int wccomp = static_cast(iic%2); - int w1comp = static_cast(ii%2); - int w2comp = static_cast(kk%2); + int const jcstart = jc + iic; + amrex::Real const sign = (jj%2)*2._rt - 1._rt; + int const wccomp = static_cast(iic%2); + int const w1comp = static_cast(ii%2); + int const w2comp = static_cast(kk%2); normal[1] += sign * phi(i + ii, jcstart + jj, k + kk) * dxi[1] * W[0][w1comp] * Wc[1][wccomp] * W[2][w2comp]; } } @@ -81,11 +81,11 @@ amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SP for (int jj = 0; jj < 2; ++jj) { for (int ii=0; ii< 2; ++ii) { for (int kk = 0; kk < 2; ++kk) { - int kcstart = kc + iic; - amrex::Real sign = (kk%2)*2. - 1.; - int wccomp = static_cast(iic%2); - int w1comp = static_cast(ii%2); - int w2comp = static_cast(jj%2); + int const kcstart = kc + iic; + amrex::Real const sign = (kk%2)*2._rt - 1._rt; + int const wccomp = static_cast(iic%2); + int const w1comp = static_cast(ii%2); + int const w2comp = static_cast(jj%2); normal[2] += sign * phi(i + ii, j + jj, kcstart + kk) * dxi[2] * W[0][w1comp] * W[1][w2comp] * Wc[2][wccomp]; } } @@ -97,10 +97,10 @@ amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SP for (int iic = 0; iic < 2; ++iic) { for (int jj=0; jj< 2; ++jj) { for (int ii = 0; ii < 2; ++ii) { - int icstart = ic + iic; - amrex::Real sign = (ii%2)*2. - 1.; - int wccomp = static_cast(iic%2); - int w1comp = static_cast(jj%2); + int const icstart = ic + iic; + amrex::Real const sign = (ii%2)*2._rt - 1._rt; + int const wccomp = static_cast(iic%2); + int const w1comp = static_cast(jj%2); normal[0] += sign * phi(icstart + ii, j + jj, k) * dxi[0] * Wc[0][wccomp] * W[1][w1comp]; } } @@ -108,10 +108,10 @@ amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SP for (int iic = 0; iic < 2; ++iic) { for (int ii=0; ii< 2; ++ii) { for (int jj = 0; jj < 2; ++jj) { - int jcstart = jc + iic; - amrex::Real sign = (jj%2)*2. - 1.; - int wccomp = static_cast(iic%2); - int w1comp = static_cast(ii%2); + int const jcstart = jc + iic; + amrex::Real const sign = (jj%2)*2._rt - 1._rt; + int const wccomp = static_cast(iic%2); + int const w1comp = static_cast(ii%2); normal[1] += sign * phi(i + ii, jcstart + jj, k) * dxi[1] * W[0][w1comp] * Wc[1][wccomp]; } } @@ -120,13 +120,11 @@ amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SP #else amrex::ignore_unused(i, j, k, ic, jc, kc, W, Wc, phi, dxi); - amrex::RealVect normal{0.0, 0.0}; + amrex::RealVect normal(0.0); WARPX_ABORT_WITH_MESSAGE("Error: interp_distance not yet implemented in 1D"); #endif return normal; } } - -#endif // AMREX_USE_EB #endif // WARPX_DISTANCETOEB_H_ diff --git a/Source/EmbeddedBoundary/Enabled.H b/Source/EmbeddedBoundary/Enabled.H new file mode 100644 index 00000000000..af01272e262 --- /dev/null +++ b/Source/EmbeddedBoundary/Enabled.H @@ -0,0 +1,18 @@ +/* Copyright 2024 Axel Huebl + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ +#ifndef WARPX_EB_ENABLED_H_ +#define WARPX_EB_ENABLED_H_ + +#include + +namespace EB +{ + /** Are embedded boundaries enabled? */ + bool enabled (); + +} // namespace EB +#endif // WARPX_EB_ENABLED_H_ diff --git a/Source/EmbeddedBoundary/Enabled.cpp b/Source/EmbeddedBoundary/Enabled.cpp new file mode 100644 index 00000000000..935c51c7c0f --- /dev/null +++ b/Source/EmbeddedBoundary/Enabled.cpp @@ -0,0 +1,39 @@ +/* Copyright 2024 Axel Huebl + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ +#include "Enabled.H" + +#ifdef AMREX_USE_EB +#include +#endif +#if defined(AMREX_USE_EB) && defined(WARPX_DIM_RZ) +#include +#endif + + +namespace EB +{ + bool enabled () + { +#ifndef AMREX_USE_EB + return false; +#else + amrex::ParmParse const pp_warpx("warpx"); + amrex::ParmParse const pp_eb2("eb2"); + + // test various runtime options to enable EBs + std::string eb_implicit_function; + bool eb_enabled = pp_warpx.query("eb_implicit_function", eb_implicit_function); + + // https://amrex-codes.github.io/amrex/docs_html/EB.html + std::string eb_stl; + eb_enabled |= pp_eb2.query("geom_type", eb_stl); + + return eb_enabled; +#endif + } + +} // namespace EB diff --git a/Source/EmbeddedBoundary/Make.package b/Source/EmbeddedBoundary/Make.package index 6ed944d19bd..76a20896f85 100644 --- a/Source/EmbeddedBoundary/Make.package +++ b/Source/EmbeddedBoundary/Make.package @@ -1,8 +1,10 @@ +CEXE_headers += Enabled.H CEXE_headers += ParticleScraper.H CEXE_headers += ParticleBoundaryProcess.H CEXE_headers += DistanceToEB.H CEXE_headers += WarpXFaceInfoBox.H +CEXE_sources += Enabled.cpp CEXE_sources += WarpXInitEB.cpp CEXE_sources += WarpXFaceExtensions.cpp diff --git a/Source/EmbeddedBoundary/ParticleScraper.H b/Source/EmbeddedBoundary/ParticleScraper.H index 1e915b39381..c5d9cc68c60 100644 --- a/Source/EmbeddedBoundary/ParticleScraper.H +++ b/Source/EmbeddedBoundary/ParticleScraper.H @@ -176,7 +176,7 @@ scrapeParticlesAtEB (PC& pc, const amrex::Vector& distan [=] AMREX_GPU_DEVICE (const int ip, amrex::RandomEngine const& engine) noexcept { // skip particles that are already flagged for removal - if (!amrex::ParticleIDWrapper{ptd.m_idcpu[ip]}.is_valid()) return; + if (!amrex::ParticleIDWrapper{ptd.m_idcpu[ip]}.is_valid()) { return; } amrex::ParticleReal xp, yp, zp; getPosition(ip, xp, yp, zp); @@ -185,7 +185,7 @@ scrapeParticlesAtEB (PC& pc, const amrex::Vector& distan amrex::Real W[AMREX_SPACEDIM][2]; ablastr::particles::compute_weights( xp, yp, zp, plo, dxi, i, j, k, W); - amrex::Real phi_value = ablastr::particles::interp_field_nodal(i, j, k, W, phi); + amrex::Real const phi_value = ablastr::particles::interp_field_nodal(i, j, k, W, phi); if (phi_value < 0.0) { diff --git a/Source/EmbeddedBoundary/WarpXFaceExtensions.cpp b/Source/EmbeddedBoundary/WarpXFaceExtensions.cpp index 21c13f23845..717aa26b021 100644 --- a/Source/EmbeddedBoundary/WarpXFaceExtensions.cpp +++ b/Source/EmbeddedBoundary/WarpXFaceExtensions.cpp @@ -6,6 +6,7 @@ */ #include "WarpXFaceInfoBox.H" +#include "EmbeddedBoundary/Enabled.H" #include "Utils/TextMsg.H" #include "WarpX.H" @@ -163,43 +164,49 @@ ComputeSStab(const int i, const int j, const int k, amrex::Array1D -WarpX::CountExtFaces() { +WarpX::CountExtFaces () { amrex::Array1D sums{0, 0, 0}; #ifdef AMREX_USE_EB + if (EB::enabled()) { #ifndef WARPX_DIM_RZ #ifdef WARPX_DIM_XZ - // In 2D we change the extrema of the for loop so that we only have the case idim=1 - for(int idim = 1; idim < AMREX_SPACEDIM; ++idim) { + // In 2D we change the extrema of the for loop so that we only have the case idim=1 + for(int idim = 1; idim < AMREX_SPACEDIM; ++idim) { #elif defined(WARPX_DIM_3D) for(int idim = 0; idim < AMREX_SPACEDIM; ++idim) { #else - WARPX_ABORT_WITH_MESSAGE( - "CountExtFaces: Only implemented in 2D3V and 3D3V"); + WARPX_ABORT_WITH_MESSAGE( + "CountExtFaces: Only implemented in 2D3V and 3D3V"); #endif - amrex::ReduceOps reduce_ops; - amrex::ReduceData reduce_data(reduce_ops); - for (amrex::MFIter mfi(*m_flag_ext_face[maxLevel()][idim]); mfi.isValid(); ++mfi) { - amrex::Box const &box = mfi.validbox(); - auto const &flag_ext_face = m_flag_ext_face[maxLevel()][idim]->array(mfi); - reduce_ops.eval(box, reduce_data, - [=] AMREX_GPU_DEVICE(int i, int j, int k) -> amrex::GpuTuple { - return flag_ext_face(i, j, k); - }); - } + amrex::ReduceOps reduce_ops; + amrex::ReduceData reduce_data(reduce_ops); + for (amrex::MFIter mfi(*m_flag_ext_face[maxLevel()][idim]); mfi.isValid(); ++mfi) { + amrex::Box const &box = mfi.validbox(); + auto const &flag_ext_face = m_flag_ext_face[maxLevel()][idim]->array(mfi); + reduce_ops.eval(box, reduce_data, + [=] AMREX_GPU_DEVICE(int i, int j, int k) -> amrex::GpuTuple { + return flag_ext_face(i, j, k); + }); + } - auto r = reduce_data.value(); - sums(idim) = amrex::get<0>(r); - } + auto r = reduce_data.value(); + sums(idim) = amrex::get<0>(r); + } - amrex::ParallelDescriptor::ReduceIntSum(&(sums(0)), AMREX_SPACEDIM); + amrex::ParallelDescriptor::ReduceIntSum(&(sums(0)), AMREX_SPACEDIM); #endif + } #endif return sums; } void -WarpX::ComputeFaceExtensions(){ +WarpX::ComputeFaceExtensions () +{ + if (!EB::enabled()) { + throw std::runtime_error("ComputeFaceExtensions only works when EBs are enabled at runtime"); + } #ifdef AMREX_USE_EB amrex::Array1D N_ext_faces = CountExtFaces(); ablastr::warn_manager::WMRecordWarning("Embedded Boundary", @@ -421,7 +428,11 @@ ComputeNBorrowEightFacesExtension(const amrex::Dim3 cell, const amrex::Real S_ex void -WarpX::ComputeOneWayExtensions() { +WarpX::ComputeOneWayExtensions () +{ + if (!EB::enabled()) { + throw std::runtime_error("ComputeOneWayExtensions only works when EBs are enabled at runtime"); + } #ifdef AMREX_USE_EB #ifndef WARPX_DIM_RZ auto const eb_fact = fieldEBFactory(maxLevel()); @@ -452,7 +463,7 @@ WarpX::ComputeOneWayExtensions() { auto &borrowing = (*m_borrowing[maxLevel()][idim])[mfi]; auto const &borrowing_inds_pointer = borrowing.inds_pointer.array(); auto const &borrowing_size = borrowing.size.array(); - amrex::Long ncells = box.numPts(); + amrex::Long const ncells = box.numPts(); int* borrowing_inds = borrowing.inds.data(); FaceInfoBox::Neighbours* borrowing_neigh_faces = borrowing.neigh_faces.data(); amrex::Real* borrowing_area = borrowing.area.data(); @@ -503,7 +514,7 @@ WarpX::ComputeOneWayExtensions() { for (int i_n = -1; i_n < 2; i_n++) { for (int j_n = -1; j_n < 2; j_n++) { //This if makes sure that we don't visit the "diagonal neighbours" - if( !(i_n == j_n || i_n == -j_n)){ + if (i_n != j_n && i_n != -j_n){ // Here a face is available if it doesn't need to be extended itself and if its // area exceeds Sz_ext. Here we need to take into account if the intruded face // has given away already some area, so we use Sz_red rather than Sz. @@ -545,8 +556,14 @@ WarpX::ComputeOneWayExtensions() { void -WarpX::ComputeEightWaysExtensions() { +WarpX::ComputeEightWaysExtensions () +{ + if (!EB::enabled()) { + throw std::runtime_error("ComputeEightWaysExtensions only works when EBs are enabled at runtime"); + } #ifdef AMREX_USE_EB + using namespace amrex::literals; + #ifndef WARPX_DIM_RZ auto const &cell_size = CellSize(maxLevel()); @@ -574,7 +591,7 @@ WarpX::ComputeEightWaysExtensions() { auto &borrowing = (*m_borrowing[maxLevel()][idim])[mfi]; auto const &borrowing_inds_pointer = borrowing.inds_pointer.array(); auto const &borrowing_size = borrowing.size.array(); - amrex::Long ncells = box.numPts(); + amrex::Long const ncells = box.numPts(); int* borrowing_inds = borrowing.inds.data(); FaceInfoBox::Neighbours* borrowing_neigh_faces = borrowing.neigh_faces.data(); amrex::Real* borrowing_area = borrowing.area.data(); @@ -650,7 +667,7 @@ WarpX::ComputeEightWaysExtensions() { neg_face = false; for (int i_n = -1; i_n < 2; i_n++) { for (int j_n = -1; j_n < 2; j_n++) { - if(local_avail(i_n + 1, j_n + 1)){ + if (local_avail(i_n + 1, j_n + 1) != 0_rt){ const amrex::Real patch = S_ext * GetNeigh(S, i, j, k, i_n, j_n, idim) / denom; if(GetNeigh(S_mod, i, j, k, i_n, j_n, idim) - patch <= 0) { neg_face = true; @@ -675,7 +692,7 @@ WarpX::ComputeEightWaysExtensions() { int count = 0; for (int i_n = -1; i_n < 2; i_n++) { for (int j_n = -1; j_n < 2; j_n++) { - if(local_avail(i_n + 1, j_n + 1)){ + if(local_avail(i_n + 1, j_n + 1) != 0_rt){ const amrex::Real patch = S_ext * GetNeigh(S, i, j, k, i_n, j_n, idim) / denom; borrowing_inds[ps + count] = ps + count; FaceInfoBox::addConnectedNeighbor(i_n, j_n, ps + count, @@ -703,7 +720,11 @@ WarpX::ComputeEightWaysExtensions() { } void -WarpX::ApplyBCKCorrection(const int idim) { +WarpX::ApplyBCKCorrection (const int idim) +{ + if (!EB::enabled()) { + throw std::runtime_error("ApplyBCKCorrection only works when EBs are enabled at runtime"); + } #if defined(AMREX_USE_EB) and !defined(WARPX_DIM_RZ) const std::array &cell_size = CellSize(maxLevel()); @@ -736,7 +757,8 @@ WarpX::ApplyBCKCorrection(const int idim) { } void -WarpX::ShrinkBorrowing() { +WarpX::ShrinkBorrowing () +{ for(int idim = 0; idim < AMREX_SPACEDIM; idim++) { for (amrex::MFIter mfi(*Bfield_fp[maxLevel()][idim]); mfi.isValid(); ++mfi) { auto &borrowing = (*m_borrowing[maxLevel()][idim])[mfi]; diff --git a/Source/EmbeddedBoundary/WarpXInitEB.cpp b/Source/EmbeddedBoundary/WarpXInitEB.cpp index 655bec0dc29..f63e4eb45d3 100644 --- a/Source/EmbeddedBoundary/WarpXInitEB.cpp +++ b/Source/EmbeddedBoundary/WarpXInitEB.cpp @@ -7,6 +7,7 @@ #include "WarpX.H" +#include "EmbeddedBoundary/Enabled.H" #ifdef AMREX_USE_EB # include "Utils/Parser/ParserUtils.H" # include "Utils/TextMsg.H" @@ -57,6 +58,8 @@ namespace { ParserIF& operator= (const ParserIF& rhs) = delete; ParserIF& operator= (ParserIF&& rhs) = delete; + ~ParserIF() = default; + AMREX_GPU_HOST_DEVICE inline amrex::Real operator() (AMREX_D_DECL(amrex::Real x, amrex::Real y, amrex::Real z)) const noexcept { @@ -80,6 +83,14 @@ namespace { void WarpX::InitEB () { + if (!EB::enabled()) { + throw std::runtime_error("InitEB only works when EBs are enabled at runtime"); + } + +#if !defined(WARPX_DIM_3D) && !defined(WARPX_DIM_XZ) && !defined(WARPX_DIM_RZ) + WARPX_ABORT_WITH_MESSAGE("EBs only implemented in 2D and 3D"); +#endif + #ifdef AMREX_USE_EB BL_PROFILE("InitEB"); @@ -88,7 +99,7 @@ WarpX::InitEB () pp_warpx.query("eb_implicit_function", impf); if (! impf.empty()) { auto eb_if_parser = utils::parser::makeParser(impf, {"x", "y", "z"}); - ParserIF pif(eb_if_parser.compile<3>()); + ParserIF const pif(eb_if_parser.compile<3>()); auto gshop = amrex::EB2::makeShop(pif, eb_if_parser); // The last argument of amrex::EB2::Build is the maximum coarsening level // to which amrex should try to coarsen the EB. It will stop after coarsening @@ -100,13 +111,12 @@ WarpX::InitEB () } else { amrex::ParmParse pp_eb2("eb2"); if (!pp_eb2.contains("geom_type")) { - std::string geom_type = "all_regular"; + std::string const geom_type = "all_regular"; pp_eb2.add("geom_type", geom_type); // use all_regular by default } // See the comment above on amrex::EB2::Build for the hard-wired number 20. amrex::EB2::Build(Geom(maxLevel()), maxLevel(), maxLevel()+20); } - #endif } @@ -116,24 +126,23 @@ WarpX::ComputeEdgeLengths (std::array< std::unique_ptr, 3 >& ed const amrex::EBFArrayBoxFactory& eb_fact) { BL_PROFILE("ComputeEdgeLengths"); +#if !defined(WARPX_DIM_3D) && !defined(WARPX_DIM_XZ) && !defined(WARPX_DIM_RZ) + WARPX_ABORT_WITH_MESSAGE("ComputeEdgeLengths only implemented in 2D and 3D"); +#endif + auto const &flags = eb_fact.getMultiEBCellFlagFab(); auto const &edge_centroid = eb_fact.getEdgeCent(); + for (int idim = 0; idim < 3; ++idim){ #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - edge_lengths[1]->setVal(0.); -#endif - for (amrex::MFIter mfi(flags); mfi.isValid(); ++mfi){ -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - for (int idim = 0; idim < 3; ++idim){ - if(idim == 1) continue; -#elif defined(WARPX_DIM_3D) - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim){ -#else - WARPX_ABORT_WITH_MESSAGE( - "ComputeEdgeLengths: Only implemented in 2D3V and 3D3V"); + if (idim == 1) { + edge_lengths[1]->setVal(0.); + continue; + } #endif - amrex::Box box = mfi.tilebox(edge_lengths[idim]->ixType().toIntVect(), - edge_lengths[idim]->nGrowVect()); - amrex::FabType fab_type = flags[mfi].getType(box); + for (amrex::MFIter mfi(flags); mfi.isValid(); ++mfi){ + amrex::Box const box = mfi.tilebox(edge_lengths[idim]->ixType().toIntVect(), + edge_lengths[idim]->nGrowVect()); + amrex::FabType const fab_type = flags[mfi].getType(box); auto const &edge_lengths_dim = edge_lengths[idim]->array(mfi); if (fab_type == amrex::FabType::regular) { @@ -149,13 +158,10 @@ WarpX::ComputeEdgeLengths (std::array< std::unique_ptr, 3 >& ed } else { #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) int idim_amrex = idim; - if(idim == 2) idim_amrex = 1; + if (idim == 2) { idim_amrex = 1; } auto const &edge_cent = edge_centroid[idim_amrex]->const_array(mfi); #elif defined(WARPX_DIM_3D) auto const &edge_cent = edge_centroid[idim]->const_array(mfi); -#else - WARPX_ABORT_WITH_MESSAGE( - "ComputeEdgeLengths: Only implemented in 2D3V and 3D3V"); #endif amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) { if (edge_cent(i, j, k) == amrex::Real(-1.0)) { @@ -182,34 +188,29 @@ WarpX::ComputeFaceAreas (std::array< std::unique_ptr, 3 >& face const amrex::EBFArrayBoxFactory& eb_fact) { BL_PROFILE("ComputeFaceAreas"); +#if !defined(WARPX_DIM_3D) && !defined(WARPX_DIM_XZ) && !defined(WARPX_DIM_RZ) + WARPX_ABORT_WITH_MESSAGE("ComputeFaceAreas only implemented in 2D and 3D"); +#endif + auto const &flags = eb_fact.getMultiEBCellFlagFab(); #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) //In 2D the volume frac is actually the area frac. auto const &area_frac = eb_fact.getVolFrac(); #elif defined(WARPX_DIM_3D) auto const &area_frac = eb_fact.getAreaFrac(); -#else - WARPX_ABORT_WITH_MESSAGE( - "ComputeFaceAreas: Only implemented in 2D3V and 3D3V"); #endif + for (int idim = 0; idim < 3; ++idim) { #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - face_areas[0]->setVal(0.); - face_areas[2]->setVal(0.); -#endif - for (amrex::MFIter mfi(flags); mfi.isValid(); ++mfi) { -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - // In 2D we change the extrema of the for loop so that we only have the case idim=1 - for (int idim = 1; idim < AMREX_SPACEDIM; ++idim) { -#elif defined(WARPX_DIM_3D) - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -#else - WARPX_ABORT_WITH_MESSAGE( - "ComputeFaceAreas: Only implemented in 2D3V and 3D3V"); + if (idim == 0 || idim == 2) { + face_areas[idim]->setVal(0.); + continue; + } #endif - amrex::Box box = mfi.tilebox(face_areas[idim]->ixType().toIntVect(), - face_areas[idim]->nGrowVect()); - amrex::FabType fab_type = flags[mfi].getType(box); + for (amrex::MFIter mfi(flags); mfi.isValid(); ++mfi) { + amrex::Box const box = mfi.tilebox(face_areas[idim]->ixType().toIntVect(), + face_areas[idim]->nGrowVect()); + amrex::FabType const fab_type = flags[mfi].getType(box); auto const &face_areas_dim = face_areas[idim]->array(mfi); if (fab_type == amrex::FabType::regular) { // every cell in box is all regular @@ -226,9 +227,6 @@ WarpX::ComputeFaceAreas (std::array< std::unique_ptr, 3 >& face auto const &face = area_frac.const_array(mfi); #elif defined(WARPX_DIM_3D) auto const &face = area_frac[idim]->const_array(mfi); -#else - WARPX_ABORT_WITH_MESSAGE( - "ComputeFaceAreas: Only implemented in 2D3V and 3D3V"); #endif amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) { face_areas_dim(i, j, k) = face(i, j, k); @@ -244,16 +242,15 @@ WarpX::ScaleEdges (std::array< std::unique_ptr, 3 >& edge_lengt const std::array& cell_size) { BL_PROFILE("ScaleEdges"); - for (amrex::MFIter mfi(*edge_lengths[0]); mfi.isValid(); ++mfi) { +#if !defined(WARPX_DIM_3D) && !defined(WARPX_DIM_XZ) && !defined(WARPX_DIM_RZ) + WARPX_ABORT_WITH_MESSAGE("ScaleEdges only implemented in 2D and 3D"); +#endif + + for (int idim = 0; idim < 3; ++idim){ #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - for (int idim = 0; idim < 3; ++idim){ - if(idim == 1) continue; -#elif defined(WARPX_DIM_3D) - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim){ -#else - WARPX_ABORT_WITH_MESSAGE( - "ScaleEdges: Only implemented in 2D3V and 3D3V"); + if (idim == 1) { continue; } #endif + for (amrex::MFIter mfi(*edge_lengths[0]); mfi.isValid(); ++mfi) { const amrex::Box& box = mfi.tilebox(edge_lengths[idim]->ixType().toIntVect(), edge_lengths[idim]->nGrowVect() ); auto const &edge_lengths_dim = edge_lengths[idim]->array(mfi); @@ -265,38 +262,22 @@ WarpX::ScaleEdges (std::array< std::unique_ptr, 3 >& edge_lengt } void -WarpX::ScaleAreas(std::array< std::unique_ptr, 3 >& face_areas, - const std::array& cell_size) { +WarpX::ScaleAreas (std::array< std::unique_ptr, 3 >& face_areas, + const std::array& cell_size) { BL_PROFILE("ScaleAreas"); - amrex::Real full_area; +#if !defined(WARPX_DIM_3D) && !defined(WARPX_DIM_XZ) && !defined(WARPX_DIM_RZ) + WARPX_ABORT_WITH_MESSAGE("ScaleAreas only implemented in 2D and 3D"); +#endif - for (amrex::MFIter mfi(*face_areas[0]); mfi.isValid(); ++mfi) { + for (int idim = 0; idim < 3; ++idim) { #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - // In 2D we change the extrema of the for loop so that we only have the case idim=1 - for (int idim = 1; idim < AMREX_SPACEDIM; ++idim) { -#elif defined(WARPX_DIM_3D) - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -#else - WARPX_ABORT_WITH_MESSAGE( - "ScaleAreas: Only implemented in 2D3V and 3D3V"); + if (idim == 0 || idim == 2) { continue; } #endif + for (amrex::MFIter mfi(*face_areas[0]); mfi.isValid(); ++mfi) { const amrex::Box& box = mfi.tilebox(face_areas[idim]->ixType().toIntVect(), face_areas[idim]->nGrowVect() ); -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - full_area = cell_size[0]*cell_size[2]; -#elif defined(WARPX_DIM_3D) - if (idim == 0) { - full_area = cell_size[1]*cell_size[2]; - } else if (idim == 1) { - full_area = cell_size[0]*cell_size[2]; - } else { - full_area = cell_size[0]*cell_size[1]; - } -#else - WARPX_ABORT_WITH_MESSAGE( - "ScaleAreas: Only implemented in 2D3V and 3D3V"); -#endif + amrex::Real const full_area = cell_size[(idim+1)%3]*cell_size[(idim+2)%3]; auto const &face_areas_dim = face_areas[idim]->array(mfi); amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) { @@ -309,22 +290,21 @@ WarpX::ScaleAreas(std::array< std::unique_ptr, 3 >& face_areas, void -WarpX::MarkCells(){ +WarpX::MarkCells () { #ifndef WARPX_DIM_RZ auto const &cell_size = CellSize(maxLevel()); -#ifdef WARPX_DIM_3D - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -#elif defined(WARPX_DIM_XZ) - m_flag_info_face[maxLevel()][0]->setVal(0.); - m_flag_info_face[maxLevel()][2]->setVal(0.); - m_flag_ext_face[maxLevel()][0]->setVal(0.); - m_flag_ext_face[maxLevel()][2]->setVal(0.); - // In 2D we change the extrema of the for loop so that we only have the case idim=1 - for (int idim = 1; idim < AMREX_SPACEDIM; ++idim) { -#else - WARPX_ABORT_WITH_MESSAGE( - "MarkCells: Only implemented in 2D3V and 3D3V"); +#if !defined(WARPX_DIM_3D) && !defined(WARPX_DIM_XZ) + WARPX_ABORT_WITH_MESSAGE("MarkCells only implemented in 2D and 3D"); +#endif + + for (int idim = 0; idim < 3; ++idim) { +#if defined(WARPX_DIM_XZ) + if (idim == 0 || idim == 2) { + m_flag_info_face[maxLevel()][idim]->setVal(0.); + m_flag_ext_face[maxLevel()][idim]->setVal(0.); + continue; + } #endif for (amrex::MFIter mfi(*Bfield_fp[maxLevel()][idim]); mfi.isValid(); ++mfi) { //amrex::Box const &box = mfi.tilebox(m_face_areas[maxLevel()][idim]->ixType().toIntVect()); @@ -347,19 +327,16 @@ WarpX::MarkCells(){ // Minimal area for this cell to be stable mod_areas_dim(i, j, k) = S(i, j, k); double S_stab; - if(idim == 0){ + if (idim == 0){ S_stab = 0.5 * std::max({ly(i, j, k) * dz, ly(i, j, k + 1) * dz, lz(i, j, k) * dy, lz(i, j + 1, k) * dy}); - }else if(idim == 1){ + }else if (idim == 1){ #ifdef WARPX_DIM_XZ S_stab = 0.5 * std::max({lx(i, j, k) * dz, lx(i, j + 1, k) * dz, lz(i, j, k) * dx, lz(i + 1, j, k) * dx}); #elif defined(WARPX_DIM_3D) S_stab = 0.5 * std::max({lx(i, j, k) * dz, lx(i, j, k + 1) * dz, lz(i, j, k) * dx, lz(i + 1, j, k) * dx}); -#else - WARPX_ABORT_WITH_MESSAGE( - "MarkCells: Only implemented in 2D3V and 3D3V"); #endif }else { S_stab = 0.5 * std::max({lx(i, j, k) * dy, lx(i, j + 1, k) * dy, @@ -397,7 +374,11 @@ WarpX::MarkCells(){ #endif void -WarpX::ComputeDistanceToEB () { +WarpX::ComputeDistanceToEB () +{ + if (!EB::enabled()) { + throw std::runtime_error("ComputeDistanceToEB only works when EBs are enabled at runtime"); + } #ifdef AMREX_USE_EB BL_PROFILE("ComputeDistanceToEB"); const amrex::EB2::IndexSpace& eb_is = amrex::EB2::IndexSpace::top(); diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index 7bdba64dc4e..c668eac2e26 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -13,6 +13,7 @@ #include "BoundaryConditions/PML.H" #include "Diagnostics/MultiDiagnostics.H" #include "Diagnostics/ReducedDiags/MultiReducedDiags.H" +#include "EmbeddedBoundary/Enabled.H" #include "Evolve/WarpXDtType.H" #include "FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H" #ifdef WARPX_USE_FFT @@ -206,6 +207,7 @@ WarpX::Evolve (int numsteps) // sync up time for (int i = 0; i <= max_level; ++i) { + t_old[i] = t_new[i]; t_new[i] = cur_time; } multi_diags->FilterComputePackFlush( step, false, true ); @@ -246,7 +248,12 @@ WarpX::Evolve (int numsteps) // This is currently a lab frame calculation. ComputeMagnetostaticField(); } - AddExternalFields(); + // Since the fields were reset above, the external fields are added + // back on to the fine patch fields. This make it so that the net fields + // are the sum of the field solution and any external field. + for (int lev = 0; lev <= max_level; ++lev) { + AddExternalFields(lev); + } } else if (electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC) { // Hybrid-PIC case: // The particles are now at p^{n+1/2} and x^{n+1}. The fields @@ -519,11 +526,12 @@ void WarpX::HandleParticlesAtBoundaries (int step, amrex::Real cur_time, int num } // interact the particles with EB walls (if present) -#ifdef AMREX_USE_EB - mypc->ScrapeParticlesAtEB(amrex::GetVecOfConstPtrs(m_distance_to_eb)); - m_particle_boundary_buffer->gatherParticlesFromEmbeddedBoundaries(*mypc, amrex::GetVecOfConstPtrs(m_distance_to_eb)); - mypc->deleteInvalidParticles(); -#endif + if (EB::enabled()) { + mypc->ScrapeParticlesAtEB(amrex::GetVecOfConstPtrs(m_distance_to_eb)); + m_particle_boundary_buffer->gatherParticlesFromEmbeddedBoundaries( + *mypc, amrex::GetVecOfConstPtrs(m_distance_to_eb)); + mypc->deleteInvalidParticles(); + } if (sort_intervals.contains(step+1)) { if (verbose) { diff --git a/Source/FieldSolver/CMakeLists.txt b/Source/FieldSolver/CMakeLists.txt index 859117eb214..896b3f04fc2 100644 --- a/Source/FieldSolver/CMakeLists.txt +++ b/Source/FieldSolver/CMakeLists.txt @@ -2,13 +2,14 @@ foreach(D IN LISTS WarpX_DIMS) warpx_set_suffix_dims(SD ${D}) target_sources(lib_${SD} PRIVATE - ElectrostaticSolver.cpp WarpXPushFieldsEM.cpp WarpXPushFieldsHybridPIC.cpp WarpX_QED_Field_Pushers.cpp + WarpXSolveFieldsES.cpp ) endforeach() +add_subdirectory(ElectrostaticSolvers) add_subdirectory(FiniteDifferenceSolver) add_subdirectory(MagnetostaticSolver) add_subdirectory(ImplicitSolvers) diff --git a/Source/FieldSolver/ElectrostaticSolver.H b/Source/FieldSolver/ElectrostaticSolver.H deleted file mode 100644 index c5c2ce8b6eb..00000000000 --- a/Source/FieldSolver/ElectrostaticSolver.H +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright 2021 Modern Electron - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ -#ifndef WARPX_ELECTROSTATICSOLVER_H_ -#define WARPX_ELECTROSTATICSOLVER_H_ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - -namespace ElectrostaticSolver { - - struct PhiCalculatorEB { - - amrex::Real t; - amrex::ParserExecutor<4> potential_eb; - - AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - amrex::Real operator()(const amrex::Real x, const amrex::Real z) const noexcept { - using namespace amrex::literals; - return potential_eb(x, 0.0_rt, z, t); - } - - AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - amrex::Real operator()(const amrex::Real x, const amrex::Real y, const amrex::Real z) const noexcept { - return potential_eb(x, y, z, t); - } - }; - - class PoissonBoundaryHandler { - public: - - amrex::Array lobc, hibc; - bool bcs_set = false; - std::array dirichlet_flag; - bool has_non_periodic = false; - bool phi_EB_only_t = true; - - void definePhiBCs (const amrex::Geometry& geom); - - void buildParsers (); - void buildParsersEB (); - - /* \brief Sets the EB potential string and updates the function parser - * - * \param [in] potential The string value of the potential - */ - void setPotentialEB(const std::string& potential) { - potential_eb_str = potential; - buildParsersEB(); - } - - [[nodiscard]] PhiCalculatorEB - getPhiEB(amrex::Real t) const noexcept - { - return PhiCalculatorEB{t, potential_eb}; - } - - // set default potentials to zero in order for current tests to pass - // but forcing the user to specify a potential might be better - std::string potential_xlo_str = "0"; - std::string potential_xhi_str = "0"; - std::string potential_ylo_str = "0"; - std::string potential_yhi_str = "0"; - std::string potential_zlo_str = "0"; - std::string potential_zhi_str = "0"; - std::string potential_eb_str = "0"; - - amrex::ParserExecutor<1> potential_xlo; - amrex::ParserExecutor<1> potential_xhi; - amrex::ParserExecutor<1> potential_ylo; - amrex::ParserExecutor<1> potential_yhi; - amrex::ParserExecutor<1> potential_zlo; - amrex::ParserExecutor<1> potential_zhi; - amrex::ParserExecutor<1> potential_eb_t; - amrex::ParserExecutor<4> potential_eb; - - private: - - amrex::Parser potential_xlo_parser; - amrex::Parser potential_xhi_parser; - amrex::Parser potential_ylo_parser; - amrex::Parser potential_yhi_parser; - amrex::Parser potential_zlo_parser; - amrex::Parser potential_zhi_parser; - amrex::Parser potential_eb_parser; - }; - - /** use amrex to directly calculate the electric field since with EB's the - * - * simple finite difference scheme in WarpX::computeE sometimes fails - */ - class EBCalcEfromPhiPerLevel { - private: - amrex::Vector< - amrex::Array - > m_e_field; - - public: - EBCalcEfromPhiPerLevel(amrex::Vector > e_field) - : m_e_field(std::move(e_field)) {} - - void operator()(amrex::MLMG & mlmg, int const lev) { - using namespace amrex::literals; - - mlmg.getGradSolution({m_e_field[lev]}); - for (auto &field: m_e_field[lev]) { - field->mult(-1._rt); - } - } - }; -} // namespace ElectrostaticSolver - -#endif // WARPX_ELECTROSTATICSOLVER_H_ diff --git a/Source/FieldSolver/ElectrostaticSolver.cpp b/Source/FieldSolver/ElectrostaticSolver.cpp deleted file mode 100644 index 3860bd55325..00000000000 --- a/Source/FieldSolver/ElectrostaticSolver.cpp +++ /dev/null @@ -1,1144 +0,0 @@ -/* Copyright 2019 Remi Lehe - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ -#include "WarpX.H" - -#include "FieldSolver/ElectrostaticSolver.H" -#include "Fluids/MultiFluidContainer.H" -#include "Fluids/WarpXFluidContainer.H" -#include "Parallelization/GuardCellManager.H" -#include "Particles/MultiParticleContainer.H" -#include "Particles/WarpXParticleContainer.H" -#include "Python/callbacks.H" -#include "Utils/Parser/ParserUtils.H" -#include "Utils/WarpXAlgorithmSelection.H" -#include "Utils/WarpXConst.H" -#include "Utils/TextMsg.H" -#include "Utils/WarpXProfilerWrapper.H" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef AMREX_USE_EB -# include -#endif - -#include -#include -#include - -using namespace amrex; -using namespace warpx::fields; - -void -WarpX::ComputeSpaceChargeField (bool const reset_fields) -{ - WARPX_PROFILE("WarpX::ComputeSpaceChargeField"); - if (reset_fields) { - // Reset all E and B fields to 0, before calculating space-charge fields - WARPX_PROFILE("WarpX::ComputeSpaceChargeField::reset_fields"); - for (int lev = 0; lev <= max_level; lev++) { - for (int comp=0; comp<3; comp++) { - Efield_fp[lev][comp]->setVal(0); - Bfield_fp[lev][comp]->setVal(0); - } - } - } - - if (electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame || - electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic) { - AddSpaceChargeFieldLabFrame(); - } - else { - // Loop over the species and add their space-charge contribution to E and B. - // Note that the fields calculated here does not include the E field - // due to simulation boundary potentials - for (int ispecies=0; ispeciesnSpecies(); ispecies++){ - WarpXParticleContainer& species = mypc->GetParticleContainer(ispecies); - if (species.initialize_self_fields || - (electrostatic_solver_id == ElectrostaticSolverAlgo::Relativistic)) { - AddSpaceChargeField(species); - } - } - - // Add the field due to the boundary potentials - if (m_boundary_potential_specified || - (electrostatic_solver_id == ElectrostaticSolverAlgo::Relativistic)){ - AddBoundaryField(); - } - } -} - -/* Compute the potential `phi` by solving the Poisson equation with the - simulation specific boundary conditions and boundary values, then add the - E field due to that `phi` to `Efield_fp`. -*/ -void -WarpX::AddBoundaryField () -{ - WARPX_PROFILE("WarpX::AddBoundaryField"); - - // Store the boundary conditions for the field solver if they haven't been - // stored yet - if (!m_poisson_boundary_handler.bcs_set) { - m_poisson_boundary_handler.definePhiBCs(Geom(0)); - } - - // Allocate fields for charge and potential - const int num_levels = max_level + 1; - Vector > rho(num_levels); - Vector > phi(num_levels); - // Use number of guard cells used for local deposition of rho - const amrex::IntVect ng = guard_cells.ng_depos_rho; - for (int lev = 0; lev <= max_level; lev++) { - BoxArray nba = boxArray(lev); - nba.surroundingNodes(); - rho[lev] = std::make_unique(nba, DistributionMap(lev), 1, ng); - rho[lev]->setVal(0.); - phi[lev] = std::make_unique(nba, DistributionMap(lev), 1, 1); - phi[lev]->setVal(0.); - } - - // Set the boundary potentials appropriately - setPhiBC(phi); - - // beta is zero for boundaries - const std::array beta = {0._rt}; - - // Compute the potential phi, by solving the Poisson equation - computePhi( rho, phi, beta, self_fields_required_precision, - self_fields_absolute_tolerance, self_fields_max_iters, - self_fields_verbosity ); - - // Compute the corresponding electric and magnetic field, from the potential phi. - computeE( Efield_fp, phi, beta ); - computeB( Bfield_fp, phi, beta ); -} - -void -WarpX::AddSpaceChargeField (WarpXParticleContainer& pc) -{ - WARPX_PROFILE("WarpX::AddSpaceChargeField"); - - if (pc.getCharge() == 0) { - return; - } - - // Store the boundary conditions for the field solver if they haven't been - // stored yet - if (!m_poisson_boundary_handler.bcs_set) { - m_poisson_boundary_handler.definePhiBCs(Geom(0)); - } - -#ifdef WARPX_DIM_RZ - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(n_rz_azimuthal_modes == 1, - "Error: RZ electrostatic only implemented for a single mode"); -#endif - - // Allocate fields for charge and potential - const int num_levels = max_level + 1; - Vector > rho(num_levels); - Vector > rho_coarse(num_levels); // Used in order to interpolate between levels - Vector > phi(num_levels); - // Use number of guard cells used for local deposition of rho - const amrex::IntVect ng = guard_cells.ng_depos_rho; - for (int lev = 0; lev <= max_level; lev++) { - BoxArray nba = boxArray(lev); - nba.surroundingNodes(); - rho[lev] = std::make_unique(nba, DistributionMap(lev), 1, ng); - rho[lev]->setVal(0.); - phi[lev] = std::make_unique(nba, DistributionMap(lev), 1, 1); - phi[lev]->setVal(0.); - if (lev > 0) { - // For MR levels: allocated the coarsened version of rho - BoxArray cba = nba; - cba.coarsen(refRatio(lev-1)); - rho_coarse[lev] = std::make_unique(cba, DistributionMap(lev), 1, ng); - rho_coarse[lev]->setVal(0.); - } - } - - // Deposit particle charge density (source of Poisson solver) - // The options below are identical to those in MultiParticleContainer::DepositCharge - bool const local = true; - bool const reset = false; - bool const apply_boundary_and_scale_volume = true; - bool const interpolate_across_levels = false; - if ( !pc.do_not_deposit) { - pc.DepositCharge(rho, local, reset, apply_boundary_and_scale_volume, - interpolate_across_levels); - } - for (int lev = 0; lev <= max_level; lev++) { - if (lev > 0) { - if (charge_buf[lev]) { - charge_buf[lev]->setVal(0.); - } - } - } - SyncRho(rho, rho_coarse, charge_buf); // Apply filter, perform MPI exchange, interpolate across levels - - // Get the particle beta vector - bool const local_average = false; // Average across all MPI ranks - std::array beta_pr = pc.meanParticleVelocity(local_average); - std::array beta; - for (int i=0 ; i < static_cast(beta.size()) ; i++) { - beta[i] = beta_pr[i]/PhysConst::c; // Normalize - } - - // Compute the potential phi, by solving the Poisson equation - computePhi( rho, phi, beta, pc.self_fields_required_precision, - pc.self_fields_absolute_tolerance, pc.self_fields_max_iters, - pc.self_fields_verbosity ); - - // Compute the corresponding electric and magnetic field, from the potential phi - computeE( Efield_fp, phi, beta ); - computeB( Bfield_fp, phi, beta ); - -} - -void -WarpX::AddSpaceChargeFieldLabFrame () -{ - WARPX_PROFILE("WarpX::AddSpaceChargeFieldLabFrame"); - - // Store the boundary conditions for the field solver if they haven't been - // stored yet - if (!m_poisson_boundary_handler.bcs_set) { - m_poisson_boundary_handler.definePhiBCs(Geom(0)); - } - -#ifdef WARPX_DIM_RZ - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(n_rz_azimuthal_modes == 1, - "Error: RZ electrostatic only implemented for a single mode"); -#endif - - // Deposit particle charge density (source of Poisson solver) - mypc->DepositCharge(rho_fp, 0.0_rt); - if (do_fluid_species) { - int const lev = 0; - myfl->DepositCharge( lev, *rho_fp[lev] ); - } - for (int lev = 0; lev <= max_level; lev++) { - if (lev > 0) { - if (charge_buf[lev]) { - charge_buf[lev]->setVal(0.); - } - } - } - SyncRho(rho_fp, rho_cp, charge_buf); // Apply filter, perform MPI exchange, interpolate across levels -#ifndef WARPX_DIM_RZ - for (int lev = 0; lev <= finestLevel(); lev++) { - // Reflect density over PEC boundaries, if needed. - ApplyRhofieldBoundary(lev, rho_fp[lev].get(), PatchType::fine); - } -#endif - - // beta is zero in lab frame - // Todo: use simpler finite difference form with beta=0 - const std::array beta = {0._rt}; - - // set the boundary potentials appropriately - setPhiBC(phi_fp); - - // Compute the potential phi, by solving the Poisson equation - if (IsPythonCallbackInstalled("poissonsolver")) { - - // Use the Python level solver (user specified) - ExecutePythonCallback("poissonsolver"); - - } else { - -#if defined(WARPX_DIM_1D_Z) - // Use the tridiag solver with 1D - computePhiTriDiagonal(rho_fp, phi_fp); -#else - // Use the AMREX MLMG or the FFT (IGF) solver otherwise - computePhi(rho_fp, phi_fp, beta, self_fields_required_precision, - self_fields_absolute_tolerance, self_fields_max_iters, - self_fields_verbosity); -#endif - - } - - // Compute the electric field. Note that if an EB is used the electric - // field will be calculated in the computePhi call. -#ifndef AMREX_USE_EB - computeE( Efield_fp, phi_fp, beta ); -#else - if ( IsPythonCallbackInstalled("poissonsolver") ) computeE( Efield_fp, phi_fp, beta ); -#endif - - // Compute the magnetic field - computeB( Bfield_fp, phi_fp, beta ); -} - -/* Compute the potential `phi` by solving the Poisson equation with `rho` as - a source, assuming that the source moves at a constant speed \f$\vec{\beta}\f$. - This uses the amrex solver. - - More specifically, this solves the equation - \f[ - \vec{\nabla}^2 r \phi - (\vec{\beta}\cdot\vec{\nabla})^2 r \phi = -\frac{r \rho}{\epsilon_0} - \f] - - \param[in] rho The charge density a given species - \param[out] phi The potential to be computed by this function - \param[in] beta Represents the velocity of the source of `phi` - \param[in] required_precision The relative convergence threshold for the MLMG solver - \param[in] absolute_tolerance The absolute convergence threshold for the MLMG solver - \param[in] max_iters The maximum number of iterations allowed for the MLMG solver - \param[in] verbosity The verbosity setting for the MLMG solver -*/ -void -WarpX::computePhi (const amrex::Vector >& rho, - amrex::Vector >& phi, - std::array const beta, - Real const required_precision, - Real absolute_tolerance, - int const max_iters, - int const verbosity) const -{ - // create a vector to our fields, sorted by level - amrex::Vector sorted_rho; - amrex::Vector sorted_phi; - for (int lev = 0; lev <= finest_level; ++lev) { - sorted_rho.emplace_back(rho[lev].get()); - sorted_phi.emplace_back(phi[lev].get()); - } - -#if defined(AMREX_USE_EB) - - std::optional post_phi_calculation; - - // EB: use AMReX to directly calculate the electric field since with EB's the - // simple finite difference scheme in WarpX::computeE sometimes fails - if (electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame || - electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic) - { - // TODO: maybe make this a helper function or pass Efield_fp directly - amrex::Vector< - amrex::Array - > e_field; - for (int lev = 0; lev <= finest_level; ++lev) { - e_field.push_back( -# if defined(WARPX_DIM_1D_Z) - amrex::Array{ - getFieldPointer(FieldType::Efield_fp, lev, 2) - } -# elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::Array{ - getFieldPointer(FieldType::Efield_fp, lev, 0), - getFieldPointer(FieldType::Efield_fp, lev, 2) - } -# elif defined(WARPX_DIM_3D) - amrex::Array{ - getFieldPointer(FieldType::Efield_fp, lev, 0), - getFieldPointer(FieldType::Efield_fp, lev, 1), - getFieldPointer(FieldType::Efield_fp, lev, 2) - } -# endif - ); - } - post_phi_calculation = ElectrostaticSolver::EBCalcEfromPhiPerLevel(e_field); - } - - std::optional > eb_farray_box_factory; - amrex::Vector< - amrex::EBFArrayBoxFactory const * - > factories; - for (int lev = 0; lev <= finest_level; ++lev) { - factories.push_back(&WarpX::fieldEBFactory(lev)); - } - eb_farray_box_factory = factories; -#else - const std::optional post_phi_calculation; - const std::optional > eb_farray_box_factory; -#endif - - bool const is_solver_igf_on_lev0 = - WarpX::poisson_solver_id == PoissonSolverAlgo::IntegratedGreenFunction; - - ablastr::fields::computePhi( - sorted_rho, - sorted_phi, - beta, - required_precision, - absolute_tolerance, - max_iters, - verbosity, - this->geom, - this->dmap, - this->grids, - this->m_poisson_boundary_handler, - is_solver_igf_on_lev0, - WarpX::do_single_precision_comms, - this->ref_ratio, - post_phi_calculation, - gett_new(0), - eb_farray_box_factory - ); - -} - - -/* \brief Set Dirichlet boundary conditions for the electrostatic solver. - - The given potential's values are fixed on the boundaries of the given - dimension according to the desired values from the simulation input file, - boundary.potential_lo and boundary.potential_hi. - - \param[inout] phi The electrostatic potential - \param[in] idim The dimension for which the Dirichlet boundary condition is set -*/ -void -WarpX::setPhiBC ( amrex::Vector>& phi ) const -{ - // check if any dimension has non-periodic boundary conditions - if (!m_poisson_boundary_handler.has_non_periodic) { return; } - - // get the boundary potentials at the current time - amrex::Array phi_bc_values_lo; - amrex::Array phi_bc_values_hi; - phi_bc_values_lo[WARPX_ZINDEX] = m_poisson_boundary_handler.potential_zlo(gett_new(0)); - phi_bc_values_hi[WARPX_ZINDEX] = m_poisson_boundary_handler.potential_zhi(gett_new(0)); -#ifndef WARPX_DIM_1D_Z - phi_bc_values_lo[0] = m_poisson_boundary_handler.potential_xlo(gett_new(0)); - phi_bc_values_hi[0] = m_poisson_boundary_handler.potential_xhi(gett_new(0)); -#endif -#if defined(WARPX_DIM_3D) - phi_bc_values_lo[1] = m_poisson_boundary_handler.potential_ylo(gett_new(0)); - phi_bc_values_hi[1] = m_poisson_boundary_handler.potential_yhi(gett_new(0)); -#endif - - auto dirichlet_flag = m_poisson_boundary_handler.dirichlet_flag; - - // loop over all mesh refinement levels and set the boundary values - for (int lev=0; lev <= max_level; lev++) { - - amrex::Box domain = Geom(lev).Domain(); - domain.surroundingNodes(); - -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for ( MFIter mfi(*phi[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi ) { - // Extract the potential - auto phi_arr = phi[lev]->array(mfi); - // Extract tileboxes for which to loop - const Box& tb = mfi.tilebox( phi[lev]->ixType().toIntVect() ); - - // loop over dimensions - for (int idim=0; idim, 3> >& E, - const amrex::Vector >& phi, - std::array const beta ) const -{ - for (int lev = 0; lev <= max_level; lev++) { - - const Real* dx = Geom(lev).CellSize(); - -#ifdef AMREX_USE_OMP -# pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for ( MFIter mfi(*phi[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi ) - { -#if defined(WARPX_DIM_3D) - const Real inv_dx = 1._rt/dx[0]; - const Real inv_dy = 1._rt/dx[1]; - const Real inv_dz = 1._rt/dx[2]; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const Real inv_dx = 1._rt/dx[0]; - const Real inv_dz = 1._rt/dx[1]; -#else - const Real inv_dz = 1._rt/dx[0]; -#endif - const amrex::IntVect ex_type = E[lev][0]->ixType().toIntVect(); - const amrex::IntVect ey_type = E[lev][1]->ixType().toIntVect(); - const amrex::IntVect ez_type = E[lev][2]->ixType().toIntVect(); - - const amrex::Box& tbx = mfi.tilebox(ex_type); - const amrex::Box& tby = mfi.tilebox(ey_type); - const amrex::Box& tbz = mfi.tilebox(ez_type); - - const auto& phi_arr = phi[lev]->array(mfi); - const auto& Ex_arr = (*E[lev][0])[mfi].array(); - const auto& Ey_arr = (*E[lev][1])[mfi].array(); - const auto& Ez_arr = (*E[lev][2])[mfi].array(); - - const Real beta_x = beta[0]; - const Real beta_y = beta[1]; - const Real beta_z = beta[2]; - - // Calculate the electric field - // Use discretized derivative that matches the staggering of the grid. - // Nodal solver - if (ex_type == amrex::IntVect::TheNodeVector() && - ey_type == amrex::IntVect::TheNodeVector() && - ez_type == amrex::IntVect::TheNodeVector()) - { -#if defined(WARPX_DIM_3D) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ex_arr(i,j,k) += - +(beta_x*beta_x-1._rt)*0.5_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k )) - + beta_x*beta_y *0.5_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k )) - + beta_x*beta_z *0.5_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ey_arr(i,j,k) += - + beta_y*beta_x *0.5_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k )) - +(beta_y*beta_y-1._rt)*0.5_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k )) - + beta_y*beta_z *0.5_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1)); }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - + beta_z*beta_x *0.5_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k )) - + beta_z*beta_y *0.5_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k )) - +(beta_z*beta_z-1._rt)*0.5_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1)); - } - ); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ex_arr(i,j,k) += - +(beta_x*beta_x-1._rt)*0.5_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) - + beta_x*beta_z *0.5_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ey_arr(i,j,k) += - +beta_x*beta_y*0.5_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) - +beta_y*beta_z*0.5_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - + beta_z*beta_x *0.5_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) - +(beta_z*beta_z-1._rt)*0.5_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)); - } - ); -#else - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ex_arr(i,j,k) += - +(beta_x*beta_z-1._rt)*0.5_rt*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ey_arr(i,j,k) += - +beta_y*beta_z*0.5_rt*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - +(beta_z*beta_z-1._rt)*0.5_rt*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)); - } - ); -#endif - } - else // Staggered solver - { -#if defined(WARPX_DIM_3D) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ex_arr(i,j,k) += - +(beta_x*beta_x-1._rt) *inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i ,j ,k )) - + beta_x*beta_y*0.25_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k ) - + phi_arr(i+1,j+1,k )-phi_arr(i+1,j-1,k )) - + beta_x*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1) - + phi_arr(i+1,j ,k+1)-phi_arr(i+1,j ,k-1)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ey_arr(i,j,k) += - + beta_y*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k ) - + phi_arr(i+1,j+1,k )-phi_arr(i-1,j+1,k )) - +(beta_y*beta_y-1._rt) *inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j ,k )) - + beta_y*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1) - + phi_arr(i ,j+1,k+1)-phi_arr(i ,j+1,k-1)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - + beta_z*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k ) - + phi_arr(i+1,j ,k+1)-phi_arr(i-1,j ,k+1)) - + beta_z*beta_y*0.25_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k ) - + phi_arr(i ,j+1,k+1)-phi_arr(i ,j-1,k+1)) - +(beta_z*beta_z-1._rt) *inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k )); - } - ); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ParallelFor( tbx, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ex_arr(i,j,k) += - +(beta_x*beta_x-1._rt)*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i ,j ,k)) - +beta_x*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k) - + phi_arr(i+1,j+1,k)-phi_arr(i+1,j-1,k)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - +beta_z*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i-1,j+1,k)) - +(beta_z*beta_z-1._rt)*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j ,k)); - } - ); - ignore_unused(beta_y); -#else - amrex::ParallelFor( tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - +(beta_z*beta_z-1._rt)*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k)); - } - ); - ignore_unused(beta_x,beta_y); -#endif - } - } - } -} - - -/* \brief Compute the magnetic field that corresponds to `phi`, and - add it to the set of MultiFab `B`. - - The magnetic field is calculated by assuming that the source that - produces the `phi` potential is moving with a constant speed \f$\vec{\beta}\f$: - \f[ - \vec{B} = -\frac{1}{c}\vec{\beta}\times\vec{\nabla}\phi - \f] - (this represents the term \f$\vec{\nabla} \times \vec{A}\f$, in the case of a moving source) - - \param[inout] E Electric field on the grid - \param[in] phi The potential from which to compute the electric field - \param[in] beta Represents the velocity of the source of `phi` -*/ -void -WarpX::computeB (amrex::Vector, 3> >& B, - const amrex::Vector >& phi, - std::array const beta ) const -{ - // return early if beta is 0 since there will be no B-field - if ((beta[0] == 0._rt) && (beta[1] == 0._rt) && (beta[2] == 0._rt)) { return; } - - for (int lev = 0; lev <= max_level; lev++) { - - const Real* dx = Geom(lev).CellSize(); - -#ifdef AMREX_USE_OMP -# pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for ( MFIter mfi(*phi[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi ) - { -#if defined(WARPX_DIM_3D) - const Real inv_dx = 1._rt/dx[0]; - const Real inv_dy = 1._rt/dx[1]; - const Real inv_dz = 1._rt/dx[2]; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const Real inv_dx = 1._rt/dx[0]; - const Real inv_dz = 1._rt/dx[1]; -#else - const Real inv_dz = 1._rt/dx[0]; -#endif - const amrex::IntVect bx_type = B[lev][0]->ixType().toIntVect(); - const amrex::IntVect by_type = B[lev][1]->ixType().toIntVect(); - const amrex::IntVect bz_type = B[lev][2]->ixType().toIntVect(); - - const amrex::Box& tbx = mfi.tilebox(bx_type); - const amrex::Box& tby = mfi.tilebox(by_type); - const amrex::Box& tbz = mfi.tilebox(bz_type); - - const auto& phi_arr = phi[lev]->array(mfi); - const auto& Bx_arr = (*B[lev][0])[mfi].array(); - const auto& By_arr = (*B[lev][1])[mfi].array(); - const auto& Bz_arr = (*B[lev][2])[mfi].array(); - - const Real beta_x = beta[0]; - const Real beta_y = beta[1]; - const Real beta_z = beta[2]; - - constexpr Real inv_c = 1._rt/PhysConst::c; - - // Calculate the magnetic field - // Use discretized derivative that matches the staggering of the grid. - // Nodal solver - if (bx_type == amrex::IntVect::TheNodeVector() && - by_type == amrex::IntVect::TheNodeVector() && - bz_type == amrex::IntVect::TheNodeVector()) - { -#if defined(WARPX_DIM_3D) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*0.5_rt*(phi_arr(i,j ,k+1)-phi_arr(i,j ,k-1)) - +beta_z*inv_dy*0.5_rt*(phi_arr(i,j+1,k )-phi_arr(i,j-1,k ))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k )-phi_arr(i-1,j,k )) - +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j,k+1)-phi_arr(i ,j,k-1))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bz_arr(i,j,k) += inv_c * ( - -beta_x*inv_dy*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)) - +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k))); - } - ); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*0.5_rt*(phi_arr(i,j+1,k)-phi_arr(i,j-1,k))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) - +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bz_arr(i,j,k) += inv_c * ( - +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k))); - } - ); -#else - amrex::ParallelFor( tbx, tby, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - +beta_x*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); - } - ); - ignore_unused(beta_z,tbz,Bz_arr); -#endif - } - else // Staggered solver - { -#if defined(WARPX_DIM_3D) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*0.5_rt*(phi_arr(i,j ,k+1)-phi_arr(i,j ,k ) - + phi_arr(i,j+1,k+1)-phi_arr(i,j+1,k )) - +beta_z*inv_dy*0.5_rt*(phi_arr(i,j+1,k )-phi_arr(i,j ,k ) - + phi_arr(i,j+1,k+1)-phi_arr(i,j ,k+1))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k )-phi_arr(i ,j,k ) - + phi_arr(i+1,j,k+1)-phi_arr(i ,j,k+1)) - +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j,k+1)-phi_arr(i ,j,k ) - + phi_arr(i+1,j,k+1)-phi_arr(i+1,j,k ))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bz_arr(i,j,k) += inv_c * ( - -beta_x*inv_dy*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i+1,j ,k)) - +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i ,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i ,j+1,k))); - } - ); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*(phi_arr(i,j+1,k)-phi_arr(i,j,k))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i ,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i ,j+1,k)) - +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i+1,j ,k))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bz_arr(i,j,k) += inv_c * ( - +beta_y*inv_dx*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); - } - ); -#else - amrex::ParallelFor( tbx, tby, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - +beta_x*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); - } - ); - ignore_unused(beta_z,tbz,Bz_arr); -#endif - } - } - } -} - -/* \brief Compute the potential by solving Poisson's equation with - a 1D tridiagonal solve. - - \param[in] rho The charge density a given species - \param[out] phi The potential to be computed by this function -*/ -void -WarpX::computePhiTriDiagonal (const amrex::Vector >& rho, - amrex::Vector >& phi) const -{ - - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(max_level == 0, - "The tridiagonal solver cannot be used with mesh refinement"); - - const int lev = 0; - - const amrex::Real* dx = Geom(lev).CellSize(); - const amrex::Real xmin = Geom(lev).ProbLo(0); - const amrex::Real xmax = Geom(lev).ProbHi(0); - const int nx_full_domain = static_cast( (xmax - xmin)/dx[0] + 0.5_rt ); - - int nx_solve_min = 1; - int nx_solve_max = nx_full_domain - 1; - - auto field_boundary_lo0 = WarpX::field_boundary_lo[0]; - auto field_boundary_hi0 = WarpX::field_boundary_hi[0]; - if (field_boundary_lo0 == FieldBoundaryType::Neumann || field_boundary_lo0 == FieldBoundaryType::Periodic) { - // Neumann or periodic boundary condition - // Solve for the point on the lower boundary - nx_solve_min = 0; - } - if (field_boundary_hi0 == FieldBoundaryType::Neumann || field_boundary_hi0 == FieldBoundaryType::Periodic) { - // Neumann or periodic boundary condition - // Solve for the point on the upper boundary - nx_solve_max = nx_full_domain; - } - - // Create a 1-D MultiFab that covers all of x. - // The tridiag solve will be done in this MultiFab and then copied out afterwards. - const amrex::IntVect lo_full_domain(AMREX_D_DECL(0,0,0)); - const amrex::IntVect hi_full_domain(AMREX_D_DECL(nx_full_domain,0,0)); - const amrex::Box box_full_domain_node(lo_full_domain, hi_full_domain, amrex::IntVect::TheNodeVector()); - const BoxArray ba_full_domain_node(box_full_domain_node); - const amrex::Vector pmap = {0}; // The data will only be on processor 0 - const amrex::DistributionMapping dm_full_domain(pmap); - - // Put the data in the pinned arena since the tridiag solver will be done on the CPU, but have - // the data readily accessible from the GPU. - auto phi1d_mf = MultiFab(ba_full_domain_node, dm_full_domain, 1, 0, MFInfo().SetArena(The_Pinned_Arena())); - auto zwork1d_mf = MultiFab(ba_full_domain_node, dm_full_domain, 1, 0, MFInfo().SetArena(The_Pinned_Arena())); - auto rho1d_mf = MultiFab(ba_full_domain_node, dm_full_domain, 1, 0, MFInfo().SetArena(The_Pinned_Arena())); - - if (field_boundary_lo0 == FieldBoundaryType::PEC || field_boundary_hi0 == FieldBoundaryType::PEC) { - // Copy from phi to get the boundary values - phi1d_mf.ParallelCopy(*phi[lev], 0, 0, 1); - } - rho1d_mf.ParallelCopy(*rho[lev], 0, 0, 1); - - // Multiplier on the charge density - const amrex::Real norm = dx[0]*dx[0]/PhysConst::ep0; - rho1d_mf.mult(norm); - - // Use the MFIter loop since when parallel, only process zero has a FAB. - // This skips the loop on all other processors. - for (MFIter mfi(phi1d_mf); mfi.isValid(); ++mfi) { - - const auto& phi1d_arr = phi1d_mf[mfi].array(); - const auto& zwork1d_arr = zwork1d_mf[mfi].array(); - const auto& rho1d_arr = rho1d_mf[mfi].array(); - - // The loops are always performed on the CPU - - amrex::Real diag = 2._rt; - - // The initial values depend on the boundary condition - if (field_boundary_lo0 == FieldBoundaryType::PEC) { - - phi1d_arr(1,0,0) = (phi1d_arr(0,0,0) + rho1d_arr(1,0,0))/diag; - - } else if (field_boundary_lo0 == FieldBoundaryType::Neumann) { - - // Neumann boundary condition - phi1d_arr(0,0,0) = rho1d_arr(0,0,0)/diag; - - zwork1d_arr(1,0,0) = 2._rt/diag; - diag = 2._rt - zwork1d_arr(1,0,0); - phi1d_arr(1,0,0) = (rho1d_arr(1,0,0) - (-1._rt)*phi1d_arr(1-1,0,0))/diag; - - } else if (field_boundary_lo0 == FieldBoundaryType::Periodic) { - - phi1d_arr(0,0,0) = rho1d_arr(0,0,0)/diag; - - zwork1d_arr(1,0,0) = 1._rt/diag; - diag = 2._rt - zwork1d_arr(1,0,0); - phi1d_arr(1,0,0) = (rho1d_arr(1,0,0) - (-1._rt)*phi1d_arr(1-1,0,0))/diag; - - } - - // Loop upward, calculating the Gaussian elimination multipliers and right hand sides - for (int i_up = 2 ; i_up < nx_solve_max ; i_up++) { - - zwork1d_arr(i_up,0,0) = 1._rt/diag; - diag = 2._rt - zwork1d_arr(i_up,0,0); - phi1d_arr(i_up,0,0) = (rho1d_arr(i_up,0,0) - (-1._rt)*phi1d_arr(i_up-1,0,0))/diag; - - } - - // The last value depend on the boundary condition - amrex::Real zwork_product = 1.; // Needed for parallel boundaries - if (field_boundary_hi0 == FieldBoundaryType::PEC) { - - int const nxm1 = nx_full_domain - 1; - zwork1d_arr(nxm1,0,0) = 1._rt/diag; - diag = 2._rt - zwork1d_arr(nxm1,0,0); - phi1d_arr(nxm1,0,0) = (phi1d_arr(nxm1+1,0,0) + rho1d_arr(nxm1,0,0) - (-1._rt)*phi1d_arr(nxm1-1,0,0))/diag; - - } else if (field_boundary_hi0 == FieldBoundaryType::Neumann) { - - // Neumann boundary condition - zwork1d_arr(nx_full_domain,0,0) = 1._rt/diag; - diag = 2._rt - 2._rt*zwork1d_arr(nx_full_domain,0,0); - if (diag == 0._rt) { - // This happens if the lower boundary is also Neumann. - // It this case, the potential is relative to an arbitrary constant, - // so set the upper boundary to zero to force a value. - phi1d_arr(nx_full_domain,0,0) = 0.; - } else { - phi1d_arr(nx_full_domain,0,0) = (rho1d_arr(nx_full_domain,0,0) - (-1._rt)*phi1d_arr(nx_full_domain-1,0,0))/diag; - } - - } else if (field_boundary_hi0 == FieldBoundaryType::Periodic) { - - zwork1d_arr(nx_full_domain,0,0) = 1._rt/diag; - - for (int i = 1 ; i <= nx_full_domain ; i++) { - zwork_product *= zwork1d_arr(i,0,0); - } - - diag = 2._rt - zwork1d_arr(nx_full_domain,0,0) - zwork_product; - // Note that rho1d_arr(0,0,0) is used to ensure that the same value is used - // on both boundaries. - phi1d_arr(nx_full_domain,0,0) = (rho1d_arr(0,0,0) - (-1._rt)*phi1d_arr(nx_full_domain-1,0,0))/diag; - - } - - // Loop downward to calculate the phi - if (field_boundary_lo0 == FieldBoundaryType::Periodic) { - - // With periodic, the right hand column adds an extra term for all rows - for (int i_down = nx_full_domain-1 ; i_down >= 0 ; i_down--) { - zwork_product /= zwork1d_arr(i_down+1,0,0); - phi1d_arr(i_down,0,0) = phi1d_arr(i_down,0,0) + zwork1d_arr(i_down+1,0,0)*phi1d_arr(i_down+1,0,0) + zwork_product*phi1d_arr(nx_full_domain,0,0); - } - - } else { - - for (int i_down = nx_solve_max-1 ; i_down >= nx_solve_min ; i_down--) { - phi1d_arr(i_down,0,0) = phi1d_arr(i_down,0,0) + zwork1d_arr(i_down+1,0,0)*phi1d_arr(i_down+1,0,0); - } - - } - - } - - // Copy phi1d to phi - phi[lev]->ParallelCopy(phi1d_mf, 0, 0, 1); -} - -void ElectrostaticSolver::PoissonBoundaryHandler::definePhiBCs (const amrex::Geometry& geom) -{ -#ifdef WARPX_DIM_RZ - if (geom.ProbLo(0) == 0){ - lobc[0] = LinOpBCType::Neumann; - dirichlet_flag[0] = false; - - // handle the r_max boundary explicitly - if (WarpX::field_boundary_hi[0] == FieldBoundaryType::PEC) { - hibc[0] = LinOpBCType::Dirichlet; - dirichlet_flag[1] = true; - } - else if (WarpX::field_boundary_hi[0] == FieldBoundaryType::Neumann) { - hibc[0] = LinOpBCType::Neumann; - dirichlet_flag[1] = false; - } - else { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(false, - "Field boundary condition at the outer radius must be either PEC or neumann " - "when using the electrostatic solver" - ); - } - } - const int dim_start = 1; -#else - const int dim_start = 0; - amrex::ignore_unused(geom); -#endif - for (int idim=dim_start; idim(); - potential_xhi = potential_xhi_parser.compile<1>(); - potential_ylo = potential_ylo_parser.compile<1>(); - potential_yhi = potential_yhi_parser.compile<1>(); - potential_zlo = potential_zlo_parser.compile<1>(); - potential_zhi = potential_zhi_parser.compile<1>(); - - buildParsersEB(); -} - -void ElectrostaticSolver::PoissonBoundaryHandler::buildParsersEB () -{ - potential_eb_parser = utils::parser::makeParser(potential_eb_str, {"x", "y", "z", "t"}); - - // check if the EB potential is a function of space or only of time - const std::set eb_symbols = potential_eb_parser.symbols(); - if ((eb_symbols.count("x") != 0) || (eb_symbols.count("y") != 0) - || (eb_symbols.count("z") != 0)) { - potential_eb = potential_eb_parser.compile<4>(); - phi_EB_only_t = false; - } - else { - potential_eb_parser = utils::parser::makeParser(potential_eb_str, {"t"}); - potential_eb_t = potential_eb_parser.compile<1>(); - } -} diff --git a/Source/FieldSolver/ElectrostaticSolvers/CMakeLists.txt b/Source/FieldSolver/ElectrostaticSolvers/CMakeLists.txt new file mode 100644 index 00000000000..39c4478c110 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/CMakeLists.txt @@ -0,0 +1,10 @@ +foreach(D IN LISTS WarpX_DIMS) + warpx_set_suffix_dims(SD ${D}) + target_sources(lib_${SD} + PRIVATE + ElectrostaticSolver.cpp + LabFrameExplicitES.cpp + PoissonBoundaryHandler.cpp + RelativisticExplicitES.cpp + ) +endforeach() diff --git a/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H b/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H new file mode 100644 index 00000000000..8d23088799f --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H @@ -0,0 +1,163 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Roelof Groenewald, Arianna Formenti, Revathi Jambunathan + * + * License: BSD-3-Clause-LBNL + */ +#ifndef WARPX_ELECTROSTATICSOLVER_H_ +#define WARPX_ELECTROSTATICSOLVER_H_ + +#include "PoissonBoundaryHandler.H" +#include "Fluids/MultiFluidContainer.H" +#include "Particles/MultiParticleContainer.H" +#include "Utils/WarpXProfilerWrapper.H" +#include "WarpX.H" + +#include + + +/** + * \brief Base class for Electrostatic Solver + * + */ +class ElectrostaticSolver +{ +public: + ElectrostaticSolver() = default; + ElectrostaticSolver( int nlevs_max ); + + virtual ~ElectrostaticSolver(); + + // Prohibit Move and Copy operations + ElectrostaticSolver(const ElectrostaticSolver&) = delete; + ElectrostaticSolver& operator=(const ElectrostaticSolver&) = delete; + ElectrostaticSolver(ElectrostaticSolver&&) = delete; + ElectrostaticSolver& operator=(ElectrostaticSolver&&) = delete; + + void ReadParameters (); + + virtual void InitData () {} + + /** + * \brief Computes charge density, rho, and solves Poisson's equation + * to obtain the associated electrostatic potential, phi. + * Using the electrostatic potential, the electric field is computed + * in lab frame, and if relativistic, then the electric and magnetic + * fields are computed using potential, phi, and + * velocity of source for potential, beta. + * This function must be defined in the derived classes. + */ + virtual void ComputeSpaceChargeField ( + [[maybe_unused]] amrex::Vector< std::unique_ptr >& rho_fp, + [[maybe_unused]] amrex::Vector< std::unique_ptr >& rho_cp, + [[maybe_unused]] amrex::Vector< std::unique_ptr >& charge_buf, + [[maybe_unused]] amrex::Vector< std::unique_ptr >& phi_fp, + [[maybe_unused]] MultiParticleContainer& mpc, + [[maybe_unused]] MultiFluidContainer* mfl, + [[maybe_unused]] amrex::Vector< std::array< std::unique_ptr, 3> >& Efield_fp, + [[maybe_unused]] amrex::Vector< std::array< std::unique_ptr, 3> >& Bfield_fp + ) = 0; + + /** + * \brief Set Dirichlet boundary conditions for the electrostatic solver. + * The given potential's values are fixed on the boundaries of the given + * dimension according to the desired values from the simulation input file, + * boundary.potential_lo and boundary.potential_hi. + * \param[inout] phi The electrostatic potential + * \param[in] idim The dimension for which the Dirichlet boundary condition is set + */ + void setPhiBC ( + amrex::Vector>& phi, + amrex::Real t + ) const; + + /** + * Compute the potential `phi` by solving the Poisson equation with `rho` as + * a source, assuming that the source moves at a constant speed \f$\vec{\beta}\f$. + * This uses the amrex solver. + * More specifically, this solves the equation + * \f[ + * \vec{\nabla}^2 r \phi - (\vec{\beta}\cdot\vec{\nabla})^2 r \phi = -\frac{r \rho}{\epsilon_0} + * \f] + * \param[out] phi The potential to be computed by this function + * \param[in] rho The charge density for a given species (relativistic solver) + * or total charge density (labframe solver) + * \param[in] beta Represents the velocity of the source of `phi` + * \param[in] required_precision The relative convergence threshold for the MLMG solver + * \param[in] absolute_tolerance The absolute convergence threshold for the MLMG solver + * \param[in] max_iters The maximum number of iterations allowed for the MLMG solver + * \param[in] verbosity The verbosity setting for the MLMG solver + */ + void computePhi ( + const amrex::Vector >& rho, + amrex::Vector >& phi, + std::array beta, + amrex::Real required_precision, + amrex::Real absolute_tolerance, + int max_iters, + int verbosity + ) const; + + /** + * \brief Compute the electric field that corresponds to `phi`, and + * add it to the set of MultiFab `E`. + * The electric field is calculated by assuming that the source that + * produces the `phi` potential is moving with a constant speed \f$\vec{\beta}\f$: + * \f[ + * \vec{E} = -\vec{\nabla}\phi + \vec{\beta}(\vec{\beta} \cdot \vec{\nabla}\phi) + * \f] + * (where the second term represent the term \f$\partial_t \vec{A}\f$, in + * the case of a moving source) + * + * \param[inout] E Electric field on the grid + * \param[in] phi The potential from which to compute the electric field + * \param[in] beta Represents the velocity of the source of `phi` + */ + void computeE ( + amrex::Vector, 3> >& E, + const amrex::Vector >& phi, + std::array beta + ) const; + + /** + * \brief Compute the magnetic field that corresponds to `phi`, and + * add it to the set of MultiFab `B`. + *The magnetic field is calculated by assuming that the source that + *produces the `phi` potential is moving with a constant speed \f$\vec{\beta}\f$: + *\f[ + * \vec{B} = -\frac{1}{c}\vec{\beta}\times\vec{\nabla}\phi + *\f] + *(this represents the term \f$\vec{\nabla} \times \vec{A}\f$, in the case of a moving source) + * + *\param[inout] B Electric field on the grid + *\param[in] phi The potential from which to compute the electric field + *\param[in] beta Represents the velocity of the source of `phi` + */ + void computeB ( + amrex::Vector, 3> >& B, + const amrex::Vector >& phi, + std::array beta + ) const; + + /** Maximum levels for the electrostatic solver grid */ + int num_levels; + + /** Boundary handler object to set potential for EB and on the domain boundary */ + std::unique_ptr m_poisson_boundary_handler; + + /** Parameters for MLMG Poisson solve */ + amrex::Real self_fields_required_precision = 1e-11; + amrex::Real self_fields_absolute_tolerance = 0.0; + /** Limit on number of MLMG iterations */ + int self_fields_max_iters = 200; + /** Verbosity for the MLMG solver. + * 0 : no verbosity + * 1 : timing and convergence at the end of MLMG + * 2 : convergence progress at every MLMG iteration + */ + int self_fields_verbosity = 2; +}; + +#endif // WARPX_ELECTROSTATICSOLVER_H_ diff --git a/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.cpp b/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.cpp new file mode 100644 index 00000000000..895615a5b21 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.cpp @@ -0,0 +1,533 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Roelof Groenewald, Arianna Formenti, Revathi Jambunathan + * + * License: BSD-3-Clause-LBNL + */ + +#include "ElectrostaticSolver.H" +#include +#include "EmbeddedBoundary/Enabled.H" + +using namespace amrex; + +ElectrostaticSolver::ElectrostaticSolver (int nlevs_max) : num_levels{nlevs_max} +{ + // Create an instance of the boundary handler to properly set boundary + // conditions + m_poisson_boundary_handler = std::make_unique(); +} + +ElectrostaticSolver::~ElectrostaticSolver () = default; + +void ElectrostaticSolver::ReadParameters () { + + ParmParse const pp_warpx("warpx"); + + // Note that with the relativistic version, these parameters would be + // input for each species. + utils::parser::queryWithParser( + pp_warpx, "self_fields_required_precision", self_fields_required_precision); + utils::parser::queryWithParser( + pp_warpx, "self_fields_absolute_tolerance", self_fields_absolute_tolerance); + utils::parser::queryWithParser( + pp_warpx, "self_fields_max_iters", self_fields_max_iters); + pp_warpx.query("self_fields_verbosity", self_fields_verbosity); +} + +void +ElectrostaticSolver::setPhiBC ( + amrex::Vector>& phi, + amrex::Real t +) const +{ + // check if any dimension has non-periodic boundary conditions + if (!m_poisson_boundary_handler->has_non_periodic) { return; } + + // get the boundary potentials at the current time + amrex::Array phi_bc_values_lo; + amrex::Array phi_bc_values_hi; + phi_bc_values_lo[WARPX_ZINDEX] = m_poisson_boundary_handler->potential_zlo(t); + phi_bc_values_hi[WARPX_ZINDEX] = m_poisson_boundary_handler->potential_zhi(t); +#ifndef WARPX_DIM_1D_Z + phi_bc_values_lo[0] = m_poisson_boundary_handler->potential_xlo(t); + phi_bc_values_hi[0] = m_poisson_boundary_handler->potential_xhi(t); +#endif +#if defined(WARPX_DIM_3D) + phi_bc_values_lo[1] = m_poisson_boundary_handler->potential_ylo(t); + phi_bc_values_hi[1] = m_poisson_boundary_handler->potential_yhi(t); +#endif + + auto dirichlet_flag = m_poisson_boundary_handler->dirichlet_flag; + + auto & warpx = WarpX::GetInstance(); + + // loop over all mesh refinement levels and set the boundary values + for (int lev=0; lev < num_levels; lev++) { + + amrex::Box domain = warpx.Geom(lev).Domain(); + domain.surroundingNodes(); + +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for ( MFIter mfi(*phi[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi ) { + // Extract the potential + auto phi_arr = phi[lev]->array(mfi); + // Extract tileboxes for which to loop + const Box& tb = mfi.tilebox( phi[lev]->ixType().toIntVect() ); + + // loop over dimensions + for (int idim=0; idim >& rho, + amrex::Vector >& phi, + std::array const beta, + Real const required_precision, + Real absolute_tolerance, + int const max_iters, + int const verbosity) const { + // create a vector to our fields, sorted by level + amrex::Vector sorted_rho; + amrex::Vector sorted_phi; + for (int lev = 0; lev < num_levels; ++lev) { + sorted_rho.emplace_back(rho[lev].get()); + sorted_phi.emplace_back(phi[lev].get()); + } + + std::optional post_phi_calculation; +#ifdef AMREX_USE_EB + // TODO: double check no overhead occurs on "m_eb_enabled == false" + std::optional > eb_farray_box_factory; +#else + std::optional > const eb_farray_box_factory; +#endif + auto & warpx = WarpX::GetInstance(); + if (EB::enabled()) + { + if (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame || + WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic) + { + // EB: use AMReX to directly calculate the electric field since with EB's the + // simple finite difference scheme in WarpX::computeE sometimes fails + + // TODO: maybe make this a helper function or pass Efield_fp directly + amrex::Vector< + amrex::Array + > e_field; + for (int lev = 0; lev < num_levels; ++lev) { + e_field.push_back( +#if defined(WARPX_DIM_1D_Z) + amrex::Array{ + warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2) + } +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + amrex::Array{ + warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 0), + warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2) + } +#elif defined(WARPX_DIM_3D) + amrex::Array{ + warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 0), + warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 1), + warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2) + } +#endif + ); + } + post_phi_calculation = EBCalcEfromPhiPerLevel(e_field); + } +#ifdef AMREX_USE_EB + amrex::Vector< + amrex::EBFArrayBoxFactory const * + > factories; + for (int lev = 0; lev < num_levels; ++lev) { + factories.push_back(&warpx.fieldEBFactory(lev)); + } + eb_farray_box_factory = factories; +#endif + } + + bool const is_solver_igf_on_lev0 = + WarpX::poisson_solver_id == PoissonSolverAlgo::IntegratedGreenFunction; + + ablastr::fields::computePhi( + sorted_rho, + sorted_phi, + beta, + required_precision, + absolute_tolerance, + max_iters, + verbosity, + warpx.Geom(), + warpx.DistributionMap(), + warpx.boxArray(), + WarpX::grid_type, + *m_poisson_boundary_handler, + is_solver_igf_on_lev0, + EB::enabled(), + WarpX::do_single_precision_comms, + warpx.refRatio(), + post_phi_calculation, + warpx.gett_new(0), + eb_farray_box_factory + ); + +} + +void +ElectrostaticSolver::computeE (amrex::Vector, 3> >& E, + const amrex::Vector >& phi, + std::array const beta ) const +{ + auto & warpx = WarpX::GetInstance(); + for (int lev = 0; lev < num_levels; lev++) { + + const Real* dx = warpx.Geom(lev).CellSize(); + +#ifdef AMREX_USE_OMP +# pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for ( MFIter mfi(*phi[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi ) + { +#if defined(WARPX_DIM_3D) + const Real inv_dx = 1._rt/dx[0]; + const Real inv_dy = 1._rt/dx[1]; + const Real inv_dz = 1._rt/dx[2]; +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + const Real inv_dx = 1._rt/dx[0]; + const Real inv_dz = 1._rt/dx[1]; +#else + const Real inv_dz = 1._rt/dx[0]; +#endif + const amrex::IntVect ex_type = E[lev][0]->ixType().toIntVect(); + const amrex::IntVect ey_type = E[lev][1]->ixType().toIntVect(); + const amrex::IntVect ez_type = E[lev][2]->ixType().toIntVect(); + + const amrex::Box& tbx = mfi.tilebox(ex_type); + const amrex::Box& tby = mfi.tilebox(ey_type); + const amrex::Box& tbz = mfi.tilebox(ez_type); + + const auto& phi_arr = phi[lev]->array(mfi); + const auto& Ex_arr = (*E[lev][0])[mfi].array(); + const auto& Ey_arr = (*E[lev][1])[mfi].array(); + const auto& Ez_arr = (*E[lev][2])[mfi].array(); + + const Real beta_x = beta[0]; + const Real beta_y = beta[1]; + const Real beta_z = beta[2]; + + // Calculate the electric field + // Use discretized derivative that matches the staggering of the grid. + // Nodal solver + if (ex_type == amrex::IntVect::TheNodeVector() && + ey_type == amrex::IntVect::TheNodeVector() && + ez_type == amrex::IntVect::TheNodeVector()) + { +#if defined(WARPX_DIM_3D) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_x-1._rt)*0.5_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k )) + + beta_x*beta_y *0.5_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k )) + + beta_x*beta_z *0.5_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ey_arr(i,j,k) += + + beta_y*beta_x *0.5_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k )) + +(beta_y*beta_y-1._rt)*0.5_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k )) + + beta_y*beta_z *0.5_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1)); }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + + beta_z*beta_x *0.5_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k )) + + beta_z*beta_y *0.5_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k )) + +(beta_z*beta_z-1._rt)*0.5_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1)); + } + ); +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_x-1._rt)*0.5_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) + + beta_x*beta_z *0.5_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ey_arr(i,j,k) += + +beta_x*beta_y*0.5_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) + +beta_y*beta_z*0.5_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + + beta_z*beta_x *0.5_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) + +(beta_z*beta_z-1._rt)*0.5_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)); + } + ); +#else + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_z-1._rt)*0.5_rt*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ey_arr(i,j,k) += + +beta_y*beta_z*0.5_rt*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +(beta_z*beta_z-1._rt)*0.5_rt*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)); + } + ); +#endif + } + else // Staggered solver + { +#if defined(WARPX_DIM_3D) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_x-1._rt) *inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i ,j ,k )) + + beta_x*beta_y*0.25_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k ) + + phi_arr(i+1,j+1,k )-phi_arr(i+1,j-1,k )) + + beta_x*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1) + + phi_arr(i+1,j ,k+1)-phi_arr(i+1,j ,k-1)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ey_arr(i,j,k) += + + beta_y*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k ) + + phi_arr(i+1,j+1,k )-phi_arr(i-1,j+1,k )) + +(beta_y*beta_y-1._rt) *inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j ,k )) + + beta_y*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k-1) + + phi_arr(i ,j+1,k+1)-phi_arr(i ,j+1,k-1)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + + beta_z*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k )-phi_arr(i-1,j ,k ) + + phi_arr(i+1,j ,k+1)-phi_arr(i-1,j ,k+1)) + + beta_z*beta_y*0.25_rt*inv_dy*(phi_arr(i ,j+1,k )-phi_arr(i ,j-1,k ) + + phi_arr(i ,j+1,k+1)-phi_arr(i ,j-1,k+1)) + +(beta_z*beta_z-1._rt) *inv_dz*(phi_arr(i ,j ,k+1)-phi_arr(i ,j ,k )); + } + ); +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + amrex::ParallelFor( tbx, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_x-1._rt)*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i ,j ,k)) + +beta_x*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k) + + phi_arr(i+1,j+1,k)-phi_arr(i+1,j-1,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +beta_z*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i-1,j+1,k)) + +(beta_z*beta_z-1._rt)*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j ,k)); + } + ); + ignore_unused(beta_y); +#else + amrex::ParallelFor( tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +(beta_z*beta_z-1._rt)*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k)); + } + ); + ignore_unused(beta_x,beta_y); +#endif + } + } + } +} + + +void ElectrostaticSolver::computeB (amrex::Vector, 3> >& B, + const amrex::Vector >& phi, + std::array const beta ) const +{ + // return early if beta is 0 since there will be no B-field + if ((beta[0] == 0._rt) && (beta[1] == 0._rt) && (beta[2] == 0._rt)) { return; } + + auto & warpx = WarpX::GetInstance(); + for (int lev = 0; lev < num_levels; lev++) { + + const Real* dx = warpx.Geom(lev).CellSize(); + +#ifdef AMREX_USE_OMP +# pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for ( MFIter mfi(*phi[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi ) + { +#if defined(WARPX_DIM_3D) + const Real inv_dx = 1._rt/dx[0]; + const Real inv_dy = 1._rt/dx[1]; + const Real inv_dz = 1._rt/dx[2]; +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + const Real inv_dx = 1._rt/dx[0]; + const Real inv_dz = 1._rt/dx[1]; +#else + const Real inv_dz = 1._rt/dx[0]; +#endif + const amrex::IntVect bx_type = B[lev][0]->ixType().toIntVect(); + const amrex::IntVect by_type = B[lev][1]->ixType().toIntVect(); + const amrex::IntVect bz_type = B[lev][2]->ixType().toIntVect(); + + const amrex::Box& tbx = mfi.tilebox(bx_type); + const amrex::Box& tby = mfi.tilebox(by_type); + const amrex::Box& tbz = mfi.tilebox(bz_type); + + const auto& phi_arr = phi[lev]->array(mfi); + const auto& Bx_arr = (*B[lev][0])[mfi].array(); + const auto& By_arr = (*B[lev][1])[mfi].array(); + const auto& Bz_arr = (*B[lev][2])[mfi].array(); + + const Real beta_x = beta[0]; + const Real beta_y = beta[1]; + const Real beta_z = beta[2]; + + constexpr Real inv_c = 1._rt/PhysConst::c; + + // Calculate the magnetic field + // Use discretized derivative that matches the staggering of the grid. + // Nodal solver + if (bx_type == amrex::IntVect::TheNodeVector() && + by_type == amrex::IntVect::TheNodeVector() && + bz_type == amrex::IntVect::TheNodeVector()) + { +#if defined(WARPX_DIM_3D) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*0.5_rt*(phi_arr(i,j ,k+1)-phi_arr(i,j ,k-1)) + +beta_z*inv_dy*0.5_rt*(phi_arr(i,j+1,k )-phi_arr(i,j-1,k ))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k )-phi_arr(i-1,j,k )) + +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j,k+1)-phi_arr(i ,j,k-1))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bz_arr(i,j,k) += inv_c * ( + -beta_x*inv_dy*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)) + +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k))); + } + ); +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*0.5_rt*(phi_arr(i,j+1,k)-phi_arr(i,j-1,k))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) + +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bz_arr(i,j,k) += inv_c * ( + +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k))); + } + ); +#else + amrex::ParallelFor( tbx, tby, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + +beta_x*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); + } + ); + ignore_unused(beta_z,tbz,Bz_arr); +#endif + } + else // Staggered solver + { +#if defined(WARPX_DIM_3D) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*0.5_rt*(phi_arr(i,j ,k+1)-phi_arr(i,j ,k ) + + phi_arr(i,j+1,k+1)-phi_arr(i,j+1,k )) + +beta_z*inv_dy*0.5_rt*(phi_arr(i,j+1,k )-phi_arr(i,j ,k ) + + phi_arr(i,j+1,k+1)-phi_arr(i,j ,k+1))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k )-phi_arr(i ,j,k ) + + phi_arr(i+1,j,k+1)-phi_arr(i ,j,k+1)) + +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j,k+1)-phi_arr(i ,j,k ) + + phi_arr(i+1,j,k+1)-phi_arr(i+1,j,k ))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bz_arr(i,j,k) += inv_c * ( + -beta_x*inv_dy*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i+1,j ,k)) + +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i ,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i ,j+1,k))); + } + ); +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*(phi_arr(i,j+1,k)-phi_arr(i,j,k))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i ,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i ,j+1,k)) + +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i+1,j ,k))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bz_arr(i,j,k) += inv_c * ( + +beta_y*inv_dx*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); + } + ); +#else + amrex::ParallelFor( tbx, tby, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + +beta_x*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); + } + ); + ignore_unused(beta_z,tbz,Bz_arr); +#endif + } + } + } +} diff --git a/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver_fwd.H b/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver_fwd.H new file mode 100644 index 00000000000..00cd061e975 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver_fwd.H @@ -0,0 +1,15 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Roelof Groenewald, Arianna Formenti, Revathi Jambunathan + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_ELECTROSTATICSOLVER_FWD_H +#define WARPX_ELECTROSTATICSOLVER_FWD_H + +class ElectrostaticSolver; + +#endif /* WARPX_ELECTROSTATICSOLVER_FWD_H */ diff --git a/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.H b/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.H new file mode 100644 index 00000000000..7dc41f0a056 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.H @@ -0,0 +1,42 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Roelof Groenewald, Arianna Formenti, Revathi Jambunathan + * + * License: BSD-3-Clause-LBNL + */ +#ifndef WARPX_LABFRAMEEXPLICITES_H_ +#define WARPX_LABFRAMEEXPLICITES_H_ + +#include "ElectrostaticSolver.H" + +class LabFrameExplicitES final : public ElectrostaticSolver +{ +public: + + LabFrameExplicitES (int nlevs_max) : ElectrostaticSolver (nlevs_max) { + ReadParameters(); + } + + void InitData () override; + + void ComputeSpaceChargeField ( + amrex::Vector< std::unique_ptr >& rho_fp, + amrex::Vector< std::unique_ptr >& rho_cp, + amrex::Vector< std::unique_ptr >& charge_buf, + amrex::Vector< std::unique_ptr >& phi_fp, + MultiParticleContainer& mpc, + MultiFluidContainer* mfl, + amrex::Vector< std::array< std::unique_ptr, 3> >& Efield_fp, + amrex::Vector< std::array< std::unique_ptr, 3> >& Bfield_fp + ) override; + + void computePhiTriDiagonal ( + const amrex::Vector >& rho, + amrex::Vector >& phi + ); + +}; + +#endif // WARPX_LABFRAMEEXPLICITES_H_ diff --git a/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.cpp b/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.cpp new file mode 100644 index 00000000000..d14abd1848a --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.cpp @@ -0,0 +1,256 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Roelof Groenewald, Arianna Formenti, Revathi Jambunathan + * + * License: BSD-3-Clause-LBNL + */ +#include "LabFrameExplicitES.H" +#include "Fluids/MultiFluidContainer_fwd.H" +#include "EmbeddedBoundary/Enabled.H" +#include "Particles/MultiParticleContainer_fwd.H" +#include "Python/callbacks.H" +#include "WarpX.H" + +using namespace amrex; + +void LabFrameExplicitES::InitData() { + auto & warpx = WarpX::GetInstance(); + m_poisson_boundary_handler->DefinePhiBCs(warpx.Geom(0)); +} + +void LabFrameExplicitES::ComputeSpaceChargeField ( + amrex::Vector< std::unique_ptr >& rho_fp, + amrex::Vector< std::unique_ptr >& rho_cp, + amrex::Vector< std::unique_ptr >& charge_buf, + amrex::Vector< std::unique_ptr >& phi_fp, + MultiParticleContainer& mpc, + MultiFluidContainer* mfl, + amrex::Vector< std::array< std::unique_ptr, 3> >& Efield_fp, + amrex::Vector< std::array< std::unique_ptr, 3> >& /*Bfield_fp*/ +) { + mpc.DepositCharge(rho_fp, 0.0_rt); + if (mfl) { + const int lev = 0; + mfl->DepositCharge(lev, *rho_fp[lev]); + } + + auto & warpx = WarpX::GetInstance(); + for (int lev = 0; lev < num_levels; lev++) { + if (lev > 0) { + if (charge_buf[lev]) { + charge_buf[lev]->setVal(0.); + } + } + } + warpx.SyncRho(rho_fp, rho_cp, charge_buf); // Apply filter, perform MPI exchange, interpolate across levels + +#ifndef WARPX_DIM_RZ + for (int lev = 0; lev < num_levels; lev++) { + // Reflect density over PEC boundaries, if needed. + warpx.ApplyRhofieldBoundary(lev, rho_fp[lev].get(), PatchType::fine); + } +#endif + // beta is zero in lab frame + // Todo: use simpler finite difference form with beta=0 + const std::array beta = {0._rt}; + + // set the boundary potentials appropriately + setPhiBC(phi_fp, warpx.gett_new(0)); + + // Compute the potential phi, by solving the Poisson equation + if (IsPythonCallbackInstalled("poissonsolver")) { + + // Use the Python level solver (user specified) + ExecutePythonCallback("poissonsolver"); + + } else { + +#if defined(WARPX_DIM_1D_Z) + // Use the tridiag solver with 1D + computePhiTriDiagonal(rho_fp, phi_fp); +#else + // Use the AMREX MLMG or the FFT (IGF) solver otherwise + computePhi(rho_fp, phi_fp, beta, self_fields_required_precision, + self_fields_absolute_tolerance, self_fields_max_iters, + self_fields_verbosity); +#endif + + } + + // Compute the electric field. Note that if an EB is used the electric + // field will be calculated in the computePhi call. + if (!EB::enabled()) { computeE( Efield_fp, phi_fp, beta ); } + else { + if (IsPythonCallbackInstalled("poissonsolver")) { computeE(Efield_fp, phi_fp, beta); } + } +} + +/* \brief Compute the potential by solving Poisson's equation with + a 1D tridiagonal solve. + + \param[in] rho The charge density a given species + \param[out] phi The potential to be computed by this function +*/ +void LabFrameExplicitES::computePhiTriDiagonal ( + const amrex::Vector >& rho, + amrex::Vector >& phi) +{ + WARPX_ALWAYS_ASSERT_WITH_MESSAGE(num_levels == 1, + "The tridiagonal solver cannot be used with mesh refinement"); + + const int lev = 0; + auto & warpx = WarpX::GetInstance(); + + const amrex::Real* dx = warpx.Geom(lev).CellSize(); + const amrex::Real xmin = warpx.Geom(lev).ProbLo(0); + const amrex::Real xmax = warpx.Geom(lev).ProbHi(0); + const int nx_full_domain = static_cast( (xmax - xmin)/dx[0] + 0.5_rt ); + + int nx_solve_min = 1; + int nx_solve_max = nx_full_domain - 1; + + auto field_boundary_lo0 = WarpX::field_boundary_lo[0]; + auto field_boundary_hi0 = WarpX::field_boundary_hi[0]; + if (field_boundary_lo0 == FieldBoundaryType::Neumann || field_boundary_lo0 == FieldBoundaryType::Periodic) { + // Neumann or periodic boundary condition + // Solve for the point on the lower boundary + nx_solve_min = 0; + } + if (field_boundary_hi0 == FieldBoundaryType::Neumann || field_boundary_hi0 == FieldBoundaryType::Periodic) { + // Neumann or periodic boundary condition + // Solve for the point on the upper boundary + nx_solve_max = nx_full_domain; + } + + // Create a 1-D MultiFab that covers all of x. + // The tridiag solve will be done in this MultiFab and then copied out afterwards. + const amrex::IntVect lo_full_domain(AMREX_D_DECL(0,0,0)); + const amrex::IntVect hi_full_domain(AMREX_D_DECL(nx_full_domain,0,0)); + const amrex::Box box_full_domain_node(lo_full_domain, hi_full_domain, amrex::IntVect::TheNodeVector()); + const BoxArray ba_full_domain_node(box_full_domain_node); + const amrex::Vector pmap = {0}; // The data will only be on processor 0 + const amrex::DistributionMapping dm_full_domain(pmap); + + // Put the data in the pinned arena since the tridiag solver will be done on the CPU, but have + // the data readily accessible from the GPU. + auto phi1d_mf = MultiFab(ba_full_domain_node, dm_full_domain, 1, 0, MFInfo().SetArena(The_Pinned_Arena())); + auto zwork1d_mf = MultiFab(ba_full_domain_node, dm_full_domain, 1, 0, MFInfo().SetArena(The_Pinned_Arena())); + auto rho1d_mf = MultiFab(ba_full_domain_node, dm_full_domain, 1, 0, MFInfo().SetArena(The_Pinned_Arena())); + + if (field_boundary_lo0 == FieldBoundaryType::PEC || field_boundary_hi0 == FieldBoundaryType::PEC) { + // Copy from phi to get the boundary values + phi1d_mf.ParallelCopy(*phi[lev], 0, 0, 1); + } + rho1d_mf.ParallelCopy(*rho[lev], 0, 0, 1); + + // Multiplier on the charge density + const amrex::Real norm = dx[0]*dx[0]/PhysConst::ep0; + rho1d_mf.mult(norm); + + // Use the MFIter loop since when parallel, only process zero has a FAB. + // This skips the loop on all other processors. + for (MFIter mfi(phi1d_mf); mfi.isValid(); ++mfi) { + + const auto& phi1d_arr = phi1d_mf[mfi].array(); + const auto& zwork1d_arr = zwork1d_mf[mfi].array(); + const auto& rho1d_arr = rho1d_mf[mfi].array(); + + // The loops are always performed on the CPU + + amrex::Real diag = 2._rt; + + // The initial values depend on the boundary condition + if (field_boundary_lo0 == FieldBoundaryType::PEC) { + + phi1d_arr(1,0,0) = (phi1d_arr(0,0,0) + rho1d_arr(1,0,0))/diag; + + } else if (field_boundary_lo0 == FieldBoundaryType::Neumann) { + + // Neumann boundary condition + phi1d_arr(0,0,0) = rho1d_arr(0,0,0)/diag; + + zwork1d_arr(1,0,0) = 2._rt/diag; + diag = 2._rt - zwork1d_arr(1,0,0); + phi1d_arr(1,0,0) = (rho1d_arr(1,0,0) - (-1._rt)*phi1d_arr(1-1,0,0))/diag; + + } else if (field_boundary_lo0 == FieldBoundaryType::Periodic) { + + phi1d_arr(0,0,0) = rho1d_arr(0,0,0)/diag; + + zwork1d_arr(1,0,0) = 1._rt/diag; + diag = 2._rt - zwork1d_arr(1,0,0); + phi1d_arr(1,0,0) = (rho1d_arr(1,0,0) - (-1._rt)*phi1d_arr(1-1,0,0))/diag; + + } + + // Loop upward, calculating the Gaussian elimination multipliers and right hand sides + for (int i_up = 2 ; i_up < nx_solve_max ; i_up++) { + + zwork1d_arr(i_up,0,0) = 1._rt/diag; + diag = 2._rt - zwork1d_arr(i_up,0,0); + phi1d_arr(i_up,0,0) = (rho1d_arr(i_up,0,0) - (-1._rt)*phi1d_arr(i_up-1,0,0))/diag; + + } + + // The last value depend on the boundary condition + amrex::Real zwork_product = 1.; // Needed for parallel boundaries + if (field_boundary_hi0 == FieldBoundaryType::PEC) { + + int const nxm1 = nx_full_domain - 1; + zwork1d_arr(nxm1,0,0) = 1._rt/diag; + diag = 2._rt - zwork1d_arr(nxm1,0,0); + phi1d_arr(nxm1,0,0) = (phi1d_arr(nxm1+1,0,0) + rho1d_arr(nxm1,0,0) - (-1._rt)*phi1d_arr(nxm1-1,0,0))/diag; + + } else if (field_boundary_hi0 == FieldBoundaryType::Neumann) { + + // Neumann boundary condition + zwork1d_arr(nx_full_domain,0,0) = 1._rt/diag; + diag = 2._rt - 2._rt*zwork1d_arr(nx_full_domain,0,0); + if (diag == 0._rt) { + // This happens if the lower boundary is also Neumann. + // It this case, the potential is relative to an arbitrary constant, + // so set the upper boundary to zero to force a value. + phi1d_arr(nx_full_domain,0,0) = 0.; + } else { + phi1d_arr(nx_full_domain,0,0) = (rho1d_arr(nx_full_domain,0,0) - (-1._rt)*phi1d_arr(nx_full_domain-1,0,0))/diag; + } + + } else if (field_boundary_hi0 == FieldBoundaryType::Periodic) { + + zwork1d_arr(nx_full_domain,0,0) = 1._rt/diag; + + for (int i = 1 ; i <= nx_full_domain ; i++) { + zwork_product *= zwork1d_arr(i,0,0); + } + + diag = 2._rt - zwork1d_arr(nx_full_domain,0,0) - zwork_product; + // Note that rho1d_arr(0,0,0) is used to ensure that the same value is used + // on both boundaries. + phi1d_arr(nx_full_domain,0,0) = (rho1d_arr(0,0,0) - (-1._rt)*phi1d_arr(nx_full_domain-1,0,0))/diag; + + } + + // Loop downward to calculate the phi + if (field_boundary_lo0 == FieldBoundaryType::Periodic) { + + // With periodic, the right hand column adds an extra term for all rows + for (int i_down = nx_full_domain-1 ; i_down >= 0 ; i_down--) { + zwork_product /= zwork1d_arr(i_down+1,0,0); + phi1d_arr(i_down,0,0) = phi1d_arr(i_down,0,0) + zwork1d_arr(i_down+1,0,0)*phi1d_arr(i_down+1,0,0) + zwork_product*phi1d_arr(nx_full_domain,0,0); + } + + } else { + + for (int i_down = nx_solve_max-1 ; i_down >= nx_solve_min ; i_down--) { + phi1d_arr(i_down,0,0) = phi1d_arr(i_down,0,0) + zwork1d_arr(i_down+1,0,0)*phi1d_arr(i_down+1,0,0); + } + + } + + } + + // Copy phi1d to phi + phi[lev]->ParallelCopy(phi1d_mf, 0, 0, 1); +} diff --git a/Source/FieldSolver/ElectrostaticSolvers/Make.package b/Source/FieldSolver/ElectrostaticSolvers/Make.package new file mode 100644 index 00000000000..a1d2d78dbb0 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/Make.package @@ -0,0 +1,6 @@ +CEXE_sources += PoissonBoundaryHandler.cpp +CEXE_sources += LabFrameExplicitES.cpp +CEXE_sources += RelativisticExplicitES.cpp +CEXE_sources += ElectrostaticSolver.cpp + +VPATH_LOCATIONS += $(WARPX_HOME)/Source/FieldSolver/ElectrostaticSolvers diff --git a/Source/FieldSolver/ElectrostaticSolvers/PoissonBoundaryHandler.H b/Source/FieldSolver/ElectrostaticSolvers/PoissonBoundaryHandler.H new file mode 100644 index 00000000000..04e427d7122 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/PoissonBoundaryHandler.H @@ -0,0 +1,142 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Roelof Groenewald (TAE Technologies) + * + * License: BSD-3-Clause-LBNL + */ +#ifndef WARPX_BOUNDARYHANDLER_H_ +#define WARPX_BOUNDARYHANDLER_H_ + +#include "Utils/Parser/ParserUtils.H" +#include "WarpX.H" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +class PoissonBoundaryHandler +{ +public: + PoissonBoundaryHandler (); // constructor + + /** Read runtime parameters. Called in constructor. */ + void ReadParameters (); + + /** + * \brief Read the input settings and set the boundary conditions used + * on each domain boundary for the Poisson solver. + */ + void DefinePhiBCs (const amrex::Geometry& geom); + + /** + * \brief Initialize amrex::Parser objects to get the boundary potential + * values at specified times. + */ + void BuildParsers (); + void BuildParsersEB (); + + /** + * \brief Sets the EB potential string and updates the function parser. + * + * \param [in] potential The string value of the potential + */ + void setPotentialEB(const std::string& potential) { + potential_eb_str = potential; + BuildParsersEB(); + } + + struct PhiCalculatorEB { + + amrex::Real t; + amrex::ParserExecutor<4> potential_eb; + + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + amrex::Real operator()(const amrex::Real x, const amrex::Real z) const noexcept { + using namespace amrex::literals; + return potential_eb(x, 0.0_rt, z, t); + } + + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + amrex::Real operator()(const amrex::Real x, const amrex::Real y, const amrex::Real z) const noexcept { + return potential_eb(x, y, z, t); + } + }; + + [[nodiscard]] PhiCalculatorEB + getPhiEB(amrex::Real t) const noexcept + { + return PhiCalculatorEB{t, potential_eb}; + } + + bool m_boundary_potential_specified = false; + + // set default potentials to zero in order for current tests to pass + // but forcing the user to specify a potential might be better + std::string potential_xlo_str = "0"; + std::string potential_xhi_str = "0"; + std::string potential_ylo_str = "0"; + std::string potential_yhi_str = "0"; + std::string potential_zlo_str = "0"; + std::string potential_zhi_str = "0"; + std::string potential_eb_str = "0"; + + amrex::ParserExecutor<1> potential_xlo; + amrex::ParserExecutor<1> potential_xhi; + amrex::ParserExecutor<1> potential_ylo; + amrex::ParserExecutor<1> potential_yhi; + amrex::ParserExecutor<1> potential_zlo; + amrex::ParserExecutor<1> potential_zhi; + amrex::ParserExecutor<1> potential_eb_t; + amrex::ParserExecutor<4> potential_eb; + + amrex::Array lobc, hibc; + std::array dirichlet_flag; + bool has_non_periodic = false; + bool phi_EB_only_t = true; + +private: + + amrex::Parser potential_xlo_parser; + amrex::Parser potential_xhi_parser; + amrex::Parser potential_ylo_parser; + amrex::Parser potential_yhi_parser; + amrex::Parser potential_zlo_parser; + amrex::Parser potential_zhi_parser; + amrex::Parser potential_eb_parser; +}; + +/** use amrex to directly calculate the electric field since with EB's the + * + * simple finite difference scheme in WarpX::computeE sometimes fails + */ +class EBCalcEfromPhiPerLevel { + private: + amrex::Vector< + amrex::Array + > m_e_field; + + public: + EBCalcEfromPhiPerLevel(amrex::Vector > e_field) + : m_e_field(std::move(e_field)) {} + + void operator()(amrex::MLMG & mlmg, int const lev) { + using namespace amrex::literals; + + mlmg.getGradSolution({m_e_field[lev]}); + for (auto &field: m_e_field[lev]) { + field->mult(-1._rt); + } + } +}; + +#endif // WARPX_BOUNDARYHANDLER_H_ diff --git a/Source/FieldSolver/ElectrostaticSolvers/PoissonBoundaryHandler.cpp b/Source/FieldSolver/ElectrostaticSolvers/PoissonBoundaryHandler.cpp new file mode 100644 index 00000000000..8afaf4c0587 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/PoissonBoundaryHandler.cpp @@ -0,0 +1,187 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Roelof Groenewald (TAE Technologies) + * + * License: BSD-3-Clause-LBNL + */ + +#include "PoissonBoundaryHandler.H" + +using namespace amrex; + +PoissonBoundaryHandler::PoissonBoundaryHandler () +{ + ReadParameters(); + BuildParsers(); +} + +void PoissonBoundaryHandler::ReadParameters() +{ + // Parse the input file for domain boundary potentials + const ParmParse pp_boundary("boundary"); + + // Read potentials from input file + m_boundary_potential_specified |= pp_boundary.query("potential_lo_x", potential_xlo_str); + m_boundary_potential_specified |= pp_boundary.query("potential_hi_x", potential_xhi_str); + m_boundary_potential_specified |= pp_boundary.query("potential_lo_y", potential_ylo_str); + m_boundary_potential_specified |= pp_boundary.query("potential_hi_y", potential_yhi_str); + m_boundary_potential_specified |= pp_boundary.query("potential_lo_z", potential_zlo_str); + m_boundary_potential_specified |= pp_boundary.query("potential_hi_z", potential_zhi_str); + + const ParmParse pp_warpx("warpx"); + m_boundary_potential_specified |= pp_warpx.query("eb_potential(x,y,z,t)", potential_eb_str); + + if (m_boundary_potential_specified & (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC)) { + ablastr::warn_manager::WMRecordWarning( + "Algorithms", + "The input script specifies the electric potential (phi) at the boundary, but \ + also uses the hybrid PIC solver based on Ohm’s law. When using this solver, the \ + electric potential does not have any impact on the simulation.", + ablastr::warn_manager::WarnPriority::low); + } + else if (m_boundary_potential_specified & (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::None)) { + ablastr::warn_manager::WMRecordWarning( + "Algorithms", + "The input script specifies the electric potential (phi) at the boundary so \ + an initial Poisson solve will be performed.", + ablastr::warn_manager::WarnPriority::low); + } +} + +void PoissonBoundaryHandler::DefinePhiBCs (const amrex::Geometry& geom) +{ +#ifdef WARPX_DIM_RZ + if (geom.ProbLo(0) == 0){ + lobc[0] = LinOpBCType::Neumann; + dirichlet_flag[0] = false; + + // handle the r_max boundary explicitly + if (WarpX::field_boundary_hi[0] == FieldBoundaryType::PEC) { + hibc[0] = LinOpBCType::Dirichlet; + dirichlet_flag[1] = true; + } + else if (WarpX::field_boundary_hi[0] == FieldBoundaryType::Neumann) { + hibc[0] = LinOpBCType::Neumann; + dirichlet_flag[1] = false; + } + else { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE(false, + "Field boundary condition at the outer radius must be either PEC or neumann " + "when using the electrostatic solver" + ); + } + } + const int dim_start = 1; +#else + const int dim_start = 0; + amrex::ignore_unused(geom); +#endif + for (int idim=dim_start; idim(); + potential_xhi = potential_xhi_parser.compile<1>(); + potential_ylo = potential_ylo_parser.compile<1>(); + potential_yhi = potential_yhi_parser.compile<1>(); + potential_zlo = potential_zlo_parser.compile<1>(); + potential_zhi = potential_zhi_parser.compile<1>(); + + BuildParsersEB(); +} + +void PoissonBoundaryHandler::BuildParsersEB () +{ + potential_eb_parser = utils::parser::makeParser(potential_eb_str, {"x", "y", "z", "t"}); + + // check if the EB potential is a function of space or only of time + const std::set eb_symbols = potential_eb_parser.symbols(); + if ((eb_symbols.count("x") != 0) || (eb_symbols.count("y") != 0) + || (eb_symbols.count("z") != 0)) { + potential_eb = potential_eb_parser.compile<4>(); + phi_EB_only_t = false; + } + else { + potential_eb_parser = utils::parser::makeParser(potential_eb_str, {"t"}); + potential_eb_t = potential_eb_parser.compile<1>(); + } +} diff --git a/Source/FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.H b/Source/FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.H new file mode 100644 index 00000000000..70382d7ced5 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.H @@ -0,0 +1,84 @@ + +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Remi Lehe, Roelof Groenewald, Arianna Formenti, Revathi Jambunathan + * + * License: BSD-3-Clause-LBNL + */ +#ifndef WARPX_RELATIVISTICEXPLICITES_H_ +#define WARPX_RELATIVISTICEXPLICITES_H_ + +#include "ElectrostaticSolver.H" +#include "Particles/WarpXParticleContainer.H" + + +class RelativisticExplicitES final : public ElectrostaticSolver +{ +public: + + RelativisticExplicitES (int nlevs_max) : ElectrostaticSolver (nlevs_max) { + ReadParameters(); + } + + void InitData () override; + + /** + * \brief Computes electrostatic fields for species + * that have initialize self fields turned on. + * A loop over all the species is performed and for each species (with self fields) + * the function ``AddSpaceChargeField`` is called. + * This function computes the electrostatic potential for species charge denisyt as source + * and then the electric and magnetic fields are updated to include the + * corresponding fields from the electrostatic potential. + * Then electric and magnetic fields are updated to include potential variation + * due to boundary conditions using the function ``AddBoundaryField`` + * + * \param[in,unused] rho_fp A temporary multifab is used for species charge density + * \param[in,unused] rho_cp A temporary multifab is used to store species charge density on coarse patch + * \param[in] charge_buf Buffer region to synchronize charge density from fine and coarse patch + * \param[in,unused] phi_fp A temporary multifab is used to compute electrostatic potentail for each species + * \param[in] mpc Pointer to multi particle container to access species data + * \param[in,out] Efield_fp Field contribution from phi computed from each species' charge density is added + * \param[in,out] Bfield Field contribution from phi computed from each species' charge density is added + */ + void ComputeSpaceChargeField ( + [[maybe_unused]] amrex::Vector< std::unique_ptr >& rho_fp, + [[maybe_unused]] amrex::Vector< std::unique_ptr >& rho_cp, + amrex::Vector< std::unique_ptr >& charge_buf, + amrex::Vector< std::unique_ptr >& phi_fp, + MultiParticleContainer& mpc, + [[maybe_unused]] MultiFluidContainer* mfl, + amrex::Vector< std::array< std::unique_ptr, 3> >& Efield_fp, + amrex::Vector< std::array< std::unique_ptr, 3> >& Bfield_fp + ) override; + + /** + * Compute the charge density of the species paricle container, pc, + * and obtain the corresponding electrostatic potential to + * update the electric and magnetic fields. + * \param[in] charge_buf Multifab that stores buffer region to + * synchronize charge density on fine and coarse patch + * \param[in] pc particle container for the selected species + * \param[in] Efield Efield updated to include potential computed for selected species charge density as source + * \param[in] Bfield Bfield updated to include potential computed for selected species charge density as source + */ + void AddSpaceChargeField ( + amrex::Vector >& charge_buf, + WarpXParticleContainer& pc, + amrex::Vector, 3>>& Efield, + amrex::Vector, 3>>& Bfield + ); + + /** Compute the potential `phi` by solving the Poisson equation with the + simulation specific boundary conditions and boundary values, then add the + E field due to that `phi` to `Efield_fp`. + * \param[in] Efield Efield updated to include potential gradient from boundary condition + */ + void AddBoundaryField ( + amrex::Vector, 3>>& Efield + ); +}; + +#endif // WARPX_RELATIVISTICEXPLICITES_H_ diff --git a/Source/FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.cpp b/Source/FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.cpp new file mode 100644 index 00000000000..1660efd48c2 --- /dev/null +++ b/Source/FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.cpp @@ -0,0 +1,168 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Remi Lehe, Roelof Groenewald, Arianna Formenti, Revathi Jambunathan + * + * License: BSD-3-Clause-LBNL + */ +#include "WarpX.H" + +#include "RelativisticExplicitES.H" + +#include "Particles/MultiParticleContainer.H" +#include "Particles/WarpXParticleContainer.H" + +using namespace amrex; + +void RelativisticExplicitES::InitData () { + auto & warpx = WarpX::GetInstance(); + bool prepare_field_solve = (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::Relativistic); + // check if any of the particle containers have initialize_self_fields = True + for (auto const& species : warpx.GetPartContainer()) { + prepare_field_solve |= species->initialize_self_fields; + } + prepare_field_solve |= m_poisson_boundary_handler->m_boundary_potential_specified; + + if (prepare_field_solve) { + m_poisson_boundary_handler->DefinePhiBCs(warpx.Geom(0)); + } +} + +void RelativisticExplicitES::ComputeSpaceChargeField ( + amrex::Vector< std::unique_ptr >& rho_fp, + amrex::Vector< std::unique_ptr >& rho_cp, + amrex::Vector< std::unique_ptr >& charge_buf, + amrex::Vector< std::unique_ptr >& phi_fp, + MultiParticleContainer& mpc, + MultiFluidContainer* mfl, + amrex::Vector< std::array< std::unique_ptr, 3> >& Efield_fp, + amrex::Vector< std::array< std::unique_ptr, 3> >& Bfield_fp +) { + WARPX_PROFILE("RelativisticExplicitES::ComputeSpaceChargeField"); + amrex::ignore_unused(rho_fp, rho_cp, phi_fp, mfl); + + const bool always_run_solve = (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::Relativistic); + + // Loop over the species and add their space-charge contribution to E and B. + // Note that the fields calculated here does not include the E field + // due to simulation boundary potentials + for (auto const& species : mpc) { + if (always_run_solve || (species->initialize_self_fields)) { + AddSpaceChargeField(charge_buf, *species, Efield_fp, Bfield_fp); + } + } + + // Add the field due to the boundary potentials + if (always_run_solve || (m_poisson_boundary_handler->m_boundary_potential_specified)) + { + AddBoundaryField(Efield_fp); + } +} + +void RelativisticExplicitES::AddSpaceChargeField ( + amrex::Vector >& charge_buf, + WarpXParticleContainer& pc, + amrex::Vector, 3>>& Efield_fp, + amrex::Vector, 3>>& Bfield_fp) +{ + WARPX_PROFILE("RelativisticExplicitES::AddSpaceChargeField"); + + if (pc.getCharge() == 0) { return; } + +#ifdef WARPX_DIM_RZ + WARPX_ALWAYS_ASSERT_WITH_MESSAGE(WarpX::n_rz_azimuthal_modes == 1, + "Error: RZ electrostatic only implemented for a single mode"); +#endif + + auto & warpx = WarpX::GetInstance(); + + // Allocate fields for charge and potential + Vector > rho(num_levels); + Vector > rho_coarse(num_levels); // Used in order to interpolate between levels + Vector > phi(num_levels); + // Use number of guard cells used for local deposition of rho + const amrex::IntVect ng = warpx.get_ng_depos_rho(); + for (int lev = 0; lev < num_levels; lev++) { + BoxArray nba = warpx.boxArray(lev); + nba.surroundingNodes(); + rho[lev] = std::make_unique(nba, warpx.DistributionMap(lev), 1, ng); + rho[lev]->setVal(0.); + phi[lev] = std::make_unique(nba, warpx.DistributionMap(lev), 1, 1); + phi[lev]->setVal(0.); + if (lev > 0) { + // For MR levels: allocated the coarsened version of rho + BoxArray cba = nba; + cba.coarsen(warpx.refRatio(lev-1)); + rho_coarse[lev] = std::make_unique(cba, warpx.DistributionMap(lev), 1, ng); + rho_coarse[lev]->setVal(0.); + if (charge_buf[lev]) { + charge_buf[lev]->setVal(0.); + } + } + } + // Deposit particle charge density (source of Poisson solver) + // The options below are identical to those in MultiParticleContainer::DepositCharge + bool const local = true; + bool const reset = false; + bool const apply_boundary_and_scale_volume = true; + bool const interpolate_across_levels = false; + if ( !pc.do_not_deposit) { + pc.DepositCharge(rho, local, reset, apply_boundary_and_scale_volume, + interpolate_across_levels); + } + warpx.SyncRho(rho, rho_coarse, charge_buf); // Apply filter, perform MPI exchange, interpolate across levels + + // Get the particle beta vector + bool const local_average = false; // Average across all MPI ranks + std::array beta_pr = pc.meanParticleVelocity(local_average); + std::array beta; + for (int i=0 ; i < static_cast(beta.size()) ; i++) { + beta[i] = beta_pr[i]/PhysConst::c; // Normalize + } + + // Compute the potential phi, by solving the Poisson equation + computePhi( rho, phi, beta, pc.self_fields_required_precision, + pc.self_fields_absolute_tolerance, pc.self_fields_max_iters, + pc.self_fields_verbosity ); + + // Compute the corresponding electric and magnetic field, from the potential phi + computeE( Efield_fp, phi, beta ); + computeB( Bfield_fp, phi, beta ); + +} + +void RelativisticExplicitES::AddBoundaryField (amrex::Vector, 3>>& Efield_fp) +{ + WARPX_PROFILE("RelativisticExplicitES::AddBoundaryField"); + + auto & warpx = WarpX::GetInstance(); + + // Allocate fields for charge and potential + amrex::Vector > rho(num_levels); + amrex::Vector > phi(num_levels); + // Use number of guard cells used for local deposition of rho + const amrex::IntVect ng = warpx.get_ng_depos_rho(); + for (int lev = 0; lev < num_levels; lev++) { + BoxArray nba = warpx.boxArray(lev); + nba.surroundingNodes(); + rho[lev] = std::make_unique(nba, warpx.DistributionMap(lev), 1, ng); + rho[lev]->setVal(0.); + phi[lev] = std::make_unique(nba, warpx.DistributionMap(lev), 1, 1); + phi[lev]->setVal(0.); + } + + // Set the boundary potentials appropriately + setPhiBC(phi, warpx.gett_new(0)); + + // beta is zero for boundaries + const std::array beta = {0._rt}; + + // Compute the potential phi, by solving the Poisson equation + computePhi( rho, phi, beta, self_fields_required_precision, + self_fields_absolute_tolerance, self_fields_max_iters, + self_fields_verbosity ); + + // Compute the corresponding electric field, from the potential phi. + computeE( Efield_fp, phi, beta ); +} diff --git a/Source/FieldSolver/Fields.H b/Source/FieldSolver/Fields.H index 76ff9a74f7b..9e4ce5a71a7 100644 --- a/Source/FieldSolver/Fields.H +++ b/Source/FieldSolver/Fields.H @@ -7,14 +7,20 @@ #ifndef WARPX_FIELDS_H_ #define WARPX_FIELDS_H_ +#include +#include + namespace warpx::fields { enum struct FieldType : int { + None, Efield_aux, Bfield_aux, Efield_fp, Bfield_fp, + Efield_fp_external, + Bfield_fp_external, current_fp, current_fp_nodal, rho_fp, @@ -35,6 +41,20 @@ namespace warpx::fields Efield_avg_cp, Bfield_avg_cp }; + + constexpr FieldType ArrayFieldTypes[] = { + FieldType::Efield_aux, FieldType::Bfield_aux, FieldType::Efield_fp, FieldType::Bfield_fp, + FieldType::current_fp, FieldType::current_fp_nodal, FieldType::vector_potential_fp, + FieldType::Efield_cp, FieldType::Bfield_cp, FieldType::current_cp, + FieldType::Efield_avg_fp, FieldType::Bfield_avg_fp, FieldType::Efield_avg_cp, FieldType::Bfield_avg_cp}; + + inline bool + isFieldArray (const FieldType field_type) + { + return std::any_of( std::begin(ArrayFieldTypes), std::end(ArrayFieldTypes), + [field_type](const FieldType& f) { return f == field_type; }); + } + } #endif //WARPX_FIELDS_H_ diff --git a/Source/FieldSolver/FiniteDifferenceSolver/ApplySilverMuellerBoundary.cpp b/Source/FieldSolver/FiniteDifferenceSolver/ApplySilverMuellerBoundary.cpp index 5e75698903e..e6f010e6f44 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/ApplySilverMuellerBoundary.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/ApplySilverMuellerBoundary.cpp @@ -39,8 +39,8 @@ void FiniteDifferenceSolver::ApplySilverMuellerBoundary ( std::array< std::unique_ptr, 3 >& Bfield, amrex::Box domain_box, amrex::Real const dt, - amrex::Vector field_boundary_lo, - amrex::Vector field_boundary_hi) { + amrex::Array field_boundary_lo, + amrex::Array field_boundary_hi) { // Ensure that we are using the Yee solver WARPX_ALWAYS_ASSERT_WITH_MESSAGE( diff --git a/Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp b/Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp index 3cc05c58068..0702b264874 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp @@ -52,7 +52,7 @@ void FiniteDifferenceSolver::ComputeDivE ( ComputeDivECylindrical ( Efield, divEfield ); #else - if (m_grid_type == GridType::Collocated) { + if (m_grid_type == ablastr::utils::enums::GridType::Collocated) { ComputeDivECartesian ( Efield, divEfield ); diff --git a/Source/FieldSolver/FiniteDifferenceSolver/EvolveB.cpp b/Source/FieldSolver/FiniteDifferenceSolver/EvolveB.cpp index fbc1397b413..4a71afda671 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/EvolveB.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/EvolveB.cpp @@ -48,32 +48,25 @@ using namespace amrex; * \brief Update the B field, over one timestep */ void FiniteDifferenceSolver::EvolveB ( - std::array< std::unique_ptr, 3 >& Bfield, - std::array< std::unique_ptr, 3 > const& Efield, - std::unique_ptr const& Gfield, - std::array< std::unique_ptr, 3 > const& face_areas, - std::array< std::unique_ptr, 3 > const& area_mod, - std::array< std::unique_ptr, 3 >& ECTRhofield, - std::array< std::unique_ptr, 3 >& Venl, - std::array< std::unique_ptr, 3 >& flag_info_cell, - std::array< std::unique_ptr >, 3 >& borrowing, - int lev, amrex::Real const dt ) { - -#if defined(WARPX_DIM_RZ) || !defined(AMREX_USE_EB) - amrex::ignore_unused(area_mod, ECTRhofield, Venl, flag_info_cell, borrowing); -#endif + [[maybe_unused]] std::array< std::unique_ptr, 3 >& Bfield, + [[maybe_unused]] std::array< std::unique_ptr, 3 > const& Efield, + [[maybe_unused]] std::unique_ptr const& Gfield, + [[maybe_unused]] std::array< std::unique_ptr, 3 > const& face_areas, + [[maybe_unused]] std::array< std::unique_ptr, 3 > const& area_mod, + [[maybe_unused]] std::array< std::unique_ptr, 3 >& ECTRhofield, + [[maybe_unused]] std::array< std::unique_ptr, 3 >& Venl, + [[maybe_unused]] std::array< std::unique_ptr, 3 >& flag_info_cell, + [[maybe_unused]] std::array< std::unique_ptr >, 3 >& borrowing, + [[maybe_unused]] int lev, + [[maybe_unused]] amrex::Real const dt ) { // Select algorithm (The choice of algorithm is a runtime option, // but we compile code for each algorithm, using templates) #ifdef WARPX_DIM_RZ if ((m_fdtd_algo == ElectromagneticSolverAlgo::Yee)|| (m_fdtd_algo == ElectromagneticSolverAlgo::HybridPIC)){ - ignore_unused(Gfield, face_areas); EvolveBCylindrical ( Bfield, Efield, lev, dt ); #else - if(m_grid_type == GridType::Collocated || m_fdtd_algo != ElectromagneticSolverAlgo::ECT){ - amrex::ignore_unused(face_areas); - } if (m_grid_type == GridType::Collocated) { @@ -87,12 +80,9 @@ void FiniteDifferenceSolver::EvolveB ( } else if (m_fdtd_algo == ElectromagneticSolverAlgo::CKC) { EvolveBCartesian ( Bfield, Efield, Gfield, lev, dt ); -#ifdef AMREX_USE_EB } else if (m_fdtd_algo == ElectromagneticSolverAlgo::ECT) { - EvolveBCartesianECT(Bfield, face_areas, area_mod, ECTRhofield, Venl, flag_info_cell, borrowing, lev, dt); -#endif #endif } else { WARPX_ABORT_WITH_MESSAGE("EvolveB: Unknown algorithm"); @@ -245,9 +235,9 @@ void FiniteDifferenceSolver::EvolveBCartesianECT ( amrex::Array4 const &S = face_areas[idim]->array(mfi); amrex::Array4 const &S_mod = area_mod[idim]->array(mfi); - auto &borrowing_dim = (*borrowing[idim])[mfi]; - auto borrowing_dim_neigh_faces = borrowing_dim.neigh_faces.data(); - auto borrowing_dim_area = borrowing_dim.area.data(); + auto & borrowing_dim = (*borrowing[idim])[mfi]; + auto * borrowing_dim_neigh_faces = borrowing_dim.neigh_faces.data(); + auto * borrowing_dim_area = borrowing_dim.area.data(); auto const &borrowing_inds = (*borrowing[idim])[mfi].inds.data(); auto const &borrowing_size = (*borrowing[idim])[mfi].size.array(); @@ -259,24 +249,23 @@ void FiniteDifferenceSolver::EvolveBCartesianECT ( //Take care of the unstable cells amrex::ParallelFor(tb, [=] AMREX_GPU_DEVICE(int i, int j, int k) { - if (S(i, j, k) <= 0) return; + if (S(i, j, k) <= 0) { return; } - if (!(flag_info_cell_dim(i, j, k) == 0)) - return; + if (!(flag_info_cell_dim(i, j, k) == 0)) { return; } Venl_dim(i, j, k) = Rho(i, j, k) * S(i, j, k); amrex::Real rho_enl; // First we compute the rho of the enlarged face for (int offset = 0; offset (Bfield, Efield, dt, dive_cleaning); diff --git a/Source/FieldSolver/FiniteDifferenceSolver/EvolveE.cpp b/Source/FieldSolver/FiniteDifferenceSolver/EvolveE.cpp index 5f707fbc927..566a81da021 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/EvolveE.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/EvolveE.cpp @@ -13,6 +13,7 @@ #else # include "FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H" #endif +#include "EmbeddedBoundary/Enabled.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" @@ -55,13 +56,9 @@ void FiniteDifferenceSolver::EvolveE ( std::unique_ptr const& Ffield, int lev, amrex::Real const dt ) { -#ifdef AMREX_USE_EB if (m_fdtd_algo != ElectromagneticSolverAlgo::ECT) { amrex::ignore_unused(face_areas, ECTRhofield); } -#else - amrex::ignore_unused(face_areas, ECTRhofield); -#endif // Select algorithm (The choice of algorithm is a runtime option, // but we compile code for each algorithm, using templates) @@ -129,11 +126,12 @@ void FiniteDifferenceSolver::EvolveECartesian ( Array4 const& jy = Jfield[1]->array(mfi); Array4 const& jz = Jfield[2]->array(mfi); -#ifdef AMREX_USE_EB - amrex::Array4 const& lx = edge_lengths[0]->array(mfi); - amrex::Array4 const& ly = edge_lengths[1]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); -#endif + amrex::Array4 lx, ly, lz; + if (EB::enabled()) { + lx = edge_lengths[0]->array(mfi); + ly = edge_lengths[1]->array(mfi); + lz = edge_lengths[2]->array(mfi); + } // Extract stencil coefficients Real const * const AMREX_RESTRICT coefs_x = m_stencil_coefs_x.dataPtr(); @@ -152,10 +150,9 @@ void FiniteDifferenceSolver::EvolveECartesian ( amrex::ParallelFor(tex, tey, tez, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries - if (lx(i, j, k) <= 0) return; -#endif + if (lx && lx(i, j, k) <= 0) { return; } + Ex(i, j, k) += c2 * dt * ( - T_Algo::DownwardDz(By, coefs_z, n_coefs_z, i, j, k) + T_Algo::DownwardDy(Bz, coefs_y, n_coefs_y, i, j, k) @@ -163,16 +160,15 @@ void FiniteDifferenceSolver::EvolveECartesian ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries #ifdef WARPX_DIM_3D - if (ly(i,j,k) <= 0) return; + if (ly && ly(i,j,k) <= 0) { return; } #elif defined(WARPX_DIM_XZ) //In XZ Ey is associated with a mesh node, so we need to check if the mesh node is covered amrex::ignore_unused(ly); - if (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j-1, k)<=0 || lz(i, j, k)<=0) return; -#endif + if (lx && (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j-1, k)<=0 || lz(i, j, k)<=0)) { return; } #endif + Ey(i, j, k) += c2 * dt * ( - T_Algo::DownwardDx(Bz, coefs_x, n_coefs_x, i, j, k) + T_Algo::DownwardDz(Bx, coefs_z, n_coefs_z, i, j, k) @@ -180,10 +176,8 @@ void FiniteDifferenceSolver::EvolveECartesian ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries - if (lz(i,j,k) <= 0) return; -#endif + if (lz && lz(i,j,k) <= 0) { return; } Ez(i, j, k) += c2 * dt * ( - T_Algo::DownwardDy(Bx, coefs_y, n_coefs_y, i, j, k) + T_Algo::DownwardDx(By, coefs_x, n_coefs_x, i, j, k) @@ -265,10 +259,11 @@ void FiniteDifferenceSolver::EvolveECylindrical ( Array4 const& jt = Jfield[1]->array(mfi); Array4 const& jz = Jfield[2]->array(mfi); -#ifdef AMREX_USE_EB - amrex::Array4 const& lr = edge_lengths[0]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); -#endif + amrex::Array4 lr, lz; + if (EB::enabled()) { + lr = edge_lengths[0]->array(mfi); + lz = edge_lengths[2]->array(mfi); + } // Extract stencil coefficients Real const * const AMREX_RESTRICT coefs_r = m_stencil_coefs_r.dataPtr(); @@ -292,10 +287,9 @@ void FiniteDifferenceSolver::EvolveECylindrical ( amrex::ParallelFor(ter, tet, tez, [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries - if (lr(i, j, 0) <= 0) return; -#endif + if (lr && lr(i, j, 0) <= 0) { return; } + Real const r = rmin + (i + 0.5_rt)*dr; // r on cell-centered point (Er is cell-centered in r) Er(i, j, 0, 0) += c2 * dt*( - T_Algo::DownwardDz(Bt, coefs_z, n_coefs_z, i, j, 0, 0) @@ -313,11 +307,10 @@ void FiniteDifferenceSolver::EvolveECylindrical ( }, [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries // The Et field is at a node, so we need to check if the node is covered - if (lr(i, j, 0)<=0 || lr(i-1, j, 0)<=0 || lz(i, j-1, 0)<=0 || lz(i, j, 0)<=0) return; -#endif + if (lr && (lr(i, j, 0)<=0 || lr(i-1, j, 0)<=0 || lz(i, j-1, 0)<=0 || lz(i, j, 0)<=0)) { return; } + Real const r = rmin + i*dr; // r on a nodal grid (Et is nodal in r) if (r != 0) { // Off-axis, regular Maxwell equations Et(i, j, 0, 0) += c2 * dt*( @@ -359,10 +352,9 @@ void FiniteDifferenceSolver::EvolveECylindrical ( }, [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries - if (lz(i, j, 0) <= 0) return; -#endif + if (lz && lz(i, j, 0) <= 0) { return; } + Real const r = rmin + i*dr; // r on a nodal grid (Ez is nodal in r) if (r != 0) { // Off-axis, regular Maxwell equations Ez(i, j, 0, 0) += c2 * dt*( diff --git a/Source/FieldSolver/FiniteDifferenceSolver/EvolveECTRho.cpp b/Source/FieldSolver/FiniteDifferenceSolver/EvolveECTRho.cpp index 95f899c98e1..8abdab71300 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/EvolveECTRho.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/EvolveECTRho.cpp @@ -112,7 +112,7 @@ void FiniteDifferenceSolver::EvolveRhoCartesianECT ( amrex::ParallelFor(trhox, trhoy, trhoz, [=] AMREX_GPU_DEVICE(int i, int j, int k) { - if (Sx(i, j, k) <= 0) return; + if (Sx(i, j, k) <= 0) { return; } // If we implement ECT in 1D we will need to take care of this #ifndef differently #ifndef WARPX_DIM_XZ @@ -122,7 +122,7 @@ void FiniteDifferenceSolver::EvolveRhoCartesianECT ( }, [=] AMREX_GPU_DEVICE(int i, int j, int k) { - if (Sy(i, j, k) <= 0) return; + if (Sy(i, j, k) <= 0) { return; } #ifdef WARPX_DIM_XZ Rhoy(i, j, k) = (Ez(i, j, k) * lz(i, j, k) - Ez(i + 1, j, k) * lz(i + 1, j, k) + @@ -136,7 +136,7 @@ void FiniteDifferenceSolver::EvolveRhoCartesianECT ( }, [=] AMREX_GPU_DEVICE(int i, int j, int k) { - if (Sz(i, j, k) <= 0) return; + if (Sz(i, j, k) <= 0) { return; } // If we implement ECT in 1D we will need to take care of this #ifndef differently #ifndef WARPX_DIM_XZ diff --git a/Source/FieldSolver/FiniteDifferenceSolver/EvolveEPML.cpp b/Source/FieldSolver/FiniteDifferenceSolver/EvolveEPML.cpp index 93352ce9896..a1ba6e44a8c 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/EvolveEPML.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/EvolveEPML.cpp @@ -16,6 +16,7 @@ #else # include "FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H" #endif +#include "EmbeddedBoundary/Enabled.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" @@ -109,11 +110,12 @@ void FiniteDifferenceSolver::EvolveEPMLCartesian ( Array4 const& By = Bfield[1]->array(mfi); Array4 const& Bz = Bfield[2]->array(mfi); -#ifdef AMREX_USE_EB - Array4 const& lx = edge_lengths[0]->array(mfi); - Array4 const& ly = edge_lengths[1]->array(mfi); - Array4 const& lz = edge_lengths[2]->array(mfi); -#endif + amrex::Array4 lx, ly, lz; + if (EB::enabled()) { + lx = edge_lengths[0]->array(mfi); + ly = edge_lengths[1]->array(mfi); + lz = edge_lengths[2]->array(mfi); + } // Extract stencil coefficients Real const * const AMREX_RESTRICT coefs_x = m_stencil_coefs_x.dataPtr(); @@ -132,9 +134,7 @@ void FiniteDifferenceSolver::EvolveEPMLCartesian ( amrex::ParallelFor(tex, tey, tez, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB - if(lx(i, j, k) <= 0) return; -#endif + if (lx && lx(i, j, k) <= 0) { return; } Ex(i, j, k, PMLComp::xz) -= c2 * dt * ( T_Algo::DownwardDz(By, coefs_z, n_coefs_z, i, j, k, PMLComp::yx) @@ -145,16 +145,15 @@ void FiniteDifferenceSolver::EvolveEPMLCartesian ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries #ifdef WARPX_DIM_3D - if (ly(i,j,k) <= 0) return; + if (ly && ly(i,j,k) <= 0) { return; } #elif defined(WARPX_DIM_XZ) //In XZ Ey is associated with a mesh node, so we need to check if the mesh node is covered amrex::ignore_unused(ly); - if (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j-1, k)<=0 || lz(i, j, k)<=0) return; -#endif + if (lx && (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j-1, k)<=0 || lz(i, j, k)<=0)) { return; } #endif + Ey(i, j, k, PMLComp::yx) -= c2 * dt * ( T_Algo::DownwardDx(Bz, coefs_x, n_coefs_x, i, j, k, PMLComp::zx) + T_Algo::DownwardDx(Bz, coefs_x, n_coefs_x, i, j, k, PMLComp::zy) ); @@ -164,9 +163,7 @@ void FiniteDifferenceSolver::EvolveEPMLCartesian ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB - if(lz(i, j, k) <= 0) return; -#endif + if (lz && lz(i, j, k) <= 0) { return; } Ez(i, j, k, PMLComp::zy) -= c2 * dt * ( T_Algo::DownwardDy(Bx, coefs_y, n_coefs_y, i, j, k, PMLComp::xy) @@ -244,13 +241,7 @@ void FiniteDifferenceSolver::EvolveEPMLCartesian ( } ); } - - } - -#ifndef AMREX_USE_EB - amrex::ignore_unused(edge_lengths); -#endif - + } // MFIter } -#endif // corresponds to ifndef WARPX_DIM_RZ +#endif // ifndef WARPX_DIM_RZ diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H index 737146f24a3..cf27898cb86 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H @@ -26,7 +26,7 @@ struct CartesianCKCAlgorithm { static void InitializeStencilCoefficients ( - std::array& cell_size, + std::array& cell_size, amrex::Vector& stencil_coefs_x, amrex::Vector& stencil_coefs_y, amrex::Vector& stencil_coefs_z ) { @@ -129,7 +129,7 @@ struct CartesianCKCAlgorithm { * Perform derivative along x on a cell-centered grid, from a nodal field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDx ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_x, int const /*n_coefs_x*/, int const i, int const j, int const k, int const ncomp=0 ) { @@ -186,7 +186,7 @@ struct CartesianCKCAlgorithm { * Perform derivative along y on a cell-centered grid, from a nodal field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDy ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_y, int const n_coefs_y, int const i, int const j, int const k, int const ncomp=0 ) { @@ -244,7 +244,7 @@ struct CartesianCKCAlgorithm { * Perform derivative along z on a cell-centered grid, from a nodal field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDz ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_z, int const n_coefs_z, int const i, int const j, int const k, int const ncomp=0 ) { diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianNodalAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianNodalAlgorithm.H index b693ed8785f..46940e7e306 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianNodalAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianNodalAlgorithm.H @@ -69,7 +69,7 @@ struct CartesianNodalAlgorithm { * account the staggering; but for `CartesianNodalAlgorithm`, they are equivalent) */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDx ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_x, int const /*n_coefs_x*/, int const i, int const j, int const k, int const ncomp=0 ) { @@ -89,7 +89,7 @@ struct CartesianNodalAlgorithm { * account the staggering; but for `CartesianNodalAlgorithm`, they are equivalent) */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real DownwardDx ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_x, int const n_coefs_x, int const i, int const j, int const k, int const ncomp=0 ) { @@ -109,7 +109,7 @@ struct CartesianNodalAlgorithm { * account the staggering; but for `CartesianNodalAlgorithm`, they are equivalent) */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDy ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_y, int const /*n_coefs_y*/, int const i, int const j, int const k, int const ncomp=0 ) { @@ -129,7 +129,7 @@ struct CartesianNodalAlgorithm { * account the staggering; but for `CartesianNodalAlgorithm`, they are equivalent) */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real DownwardDy ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_y, int const n_coefs_y, int const i, int const j, int const k, int const ncomp=0 ) { @@ -143,7 +143,7 @@ struct CartesianNodalAlgorithm { * account the staggering; but for `CartesianNodalAlgorithm`, they are equivalent) */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDz ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_z, int const /*n_coefs_z*/, int const i, int const j, int const k, int const ncomp=0 ) { @@ -164,7 +164,7 @@ struct CartesianNodalAlgorithm { * account the staggering; but for `CartesianNodalAlgorithm`, they are equivalent) */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real DownwardDz ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_z, int const n_coefs_z, int const i, int const j, int const k, int const ncomp=0 ) { diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianYeeAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianYeeAlgorithm.H index c4978287aec..485698802b6 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianYeeAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianYeeAlgorithm.H @@ -67,7 +67,7 @@ struct CartesianYeeAlgorithm { * Perform derivative along x on a cell-centered grid, from a nodal field `F`*/ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDx ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_x, int const /*n_coefs_x*/, int const i, int const j, int const k, int const ncomp=0 ) { @@ -123,7 +123,7 @@ struct CartesianYeeAlgorithm { * Perform derivative along y on a cell-centered grid, from a nodal field `F`*/ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDy ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_y, int const n_coefs_y, int const i, int const j, int const k, int const ncomp=0 ) { @@ -189,7 +189,7 @@ struct CartesianYeeAlgorithm { * Perform derivative along z on a cell-centered grid, from a nodal field `F`*/ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDz ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_z, int const /*n_coefs_z*/, int const i, int const j, int const k, int const ncomp=0 ) { diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H index 436f0a83f31..d20e1ef829b 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H @@ -74,7 +74,7 @@ struct CylindricalYeeAlgorithm { * The input parameter `r` is given at the cell-centered position */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDrr_over_r ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const r, amrex::Real const dr, amrex::Real const * const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp ) { @@ -92,7 +92,7 @@ struct CylindricalYeeAlgorithm { * The input parameter `r` is given at the cell-centered position */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real DownwardDrr_over_r ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const r, amrex::Real const dr, amrex::Real const * const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp ) { @@ -108,7 +108,7 @@ struct CylindricalYeeAlgorithm { * Perform derivative along r on a cell-centered grid, from a nodal field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDr ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp ) { @@ -123,7 +123,7 @@ struct CylindricalYeeAlgorithm { * Perform derivative along r on a nodal grid, from a cell-centered field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real DownwardDr ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp ) { @@ -156,7 +156,7 @@ struct CylindricalYeeAlgorithm { * Perform derivative along z on a cell-centered grid, from a nodal field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDz ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_z, int const n_coefs_z, int const i, int const j, int const k, int const comp ) { @@ -170,7 +170,7 @@ struct CylindricalYeeAlgorithm { * Perform derivative along z on a nodal grid, from a cell-centered field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real DownwardDz ( - amrex::Array4 const& F, + amrex::Array4 const& F, amrex::Real const * const coefs_z, int const n_coefs_z, int const i, int const j, int const k, int const comp ) { diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H index a7a4f10a713..0a9f21e6863 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H @@ -17,6 +17,8 @@ #include "HybridPICModel/HybridPICModel_fwd.H" #include "MacroscopicProperties/MacroscopicProperties_fwd.H" +#include + #include #include @@ -45,9 +47,9 @@ class FiniteDifferenceSolver * \param grid_type Whether the solver is applied to a collocated or staggered grid */ FiniteDifferenceSolver ( - int fdtd_algo, + ElectromagneticSolverAlgo fdtd_algo, std::array cell_size, - short grid_type ); + ablastr::utils::enums::GridType grid_type ); void EvolveB ( std::array< std::unique_ptr, 3 >& Bfield, std::array< std::unique_ptr, 3 > const& Efield, @@ -90,8 +92,8 @@ class FiniteDifferenceSolver std::array< std::unique_ptr, 3 >& Bfield, amrex::Box domain_box, amrex::Real dt, - amrex::Vector field_boundary_lo, - amrex::Vector field_boundary_hi); + amrex::Array field_boundary_lo, + amrex::Array field_boundary_hi); void ComputeDivE ( const std::array,3>& Efield, amrex::MultiFab& divE ); @@ -147,7 +149,7 @@ class FiniteDifferenceSolver * \param[in] edge_lengths length of edges along embedded boundaries * \param[in] lev level number for the calculation * \param[in] hybrid_model instance of the hybrid-PIC model - * \param[in] include_resistivity_term boolean flag for whether to include resistivity + * \param[in] solve_for_Faraday boolean flag for whether the E-field is solved to be used in Faraday's equation */ void HybridPICSolveE ( std::array< std::unique_ptr, 3>& Efield, std::array< std::unique_ptr, 3>& Jfield, @@ -158,7 +160,7 @@ class FiniteDifferenceSolver std::unique_ptr const& Pefield, std::array< std::unique_ptr, 3 > const& edge_lengths, int lev, HybridPICModel const* hybrid_model, - bool include_resistivity_term ); + bool solve_for_Faraday ); /** * \brief Calculation of total current using Ampere's law (without @@ -177,8 +179,8 @@ class FiniteDifferenceSolver private: - int m_fdtd_algo; - short m_grid_type; + ElectromagneticSolverAlgo m_fdtd_algo; + ablastr::utils::enums::GridType m_grid_type; #ifdef WARPX_DIM_RZ amrex::Real m_dr, m_rmin; @@ -243,7 +245,7 @@ class FiniteDifferenceSolver std::unique_ptr const& Pefield, std::array< std::unique_ptr, 3 > const& edge_lengths, int lev, HybridPICModel const* hybrid_model, - bool include_resistivity_term ); + bool solve_for_Faraday ); template void CalculateCurrentAmpereCylindrical ( @@ -348,7 +350,7 @@ class FiniteDifferenceSolver std::unique_ptr const& Pefield, std::array< std::unique_ptr, 3 > const& edge_lengths, int lev, HybridPICModel const* hybrid_model, - bool include_resistivity_term ); + bool solve_for_Faraday ); template void CalculateCurrentAmpereCartesian ( diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.cpp b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.cpp index 1bbc6c9b337..fdd02c5249b 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.cpp @@ -28,9 +28,9 @@ /* This function initializes the stencil coefficients for the chosen finite-difference algorithm */ FiniteDifferenceSolver::FiniteDifferenceSolver ( - int const fdtd_algo, + ElectromagneticSolverAlgo const fdtd_algo, std::array cell_size, - short grid_type): + ablastr::utils::enums::GridType grid_type): // Register the type of finite-difference algorithm m_fdtd_algo{fdtd_algo}, m_grid_type{grid_type} @@ -63,7 +63,7 @@ FiniteDifferenceSolver::FiniteDifferenceSolver ( "FiniteDifferenceSolver: Unknown algorithm"); } #else - if (grid_type == GridType::Collocated) { + if (grid_type == ablastr::utils::enums::GridType::Collocated) { CartesianNodalAlgorithm::InitializeStencilCoefficients( cell_size, m_h_stencil_coefs_x, m_h_stencil_coefs_y, m_h_stencil_coefs_z ); diff --git a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H index 15208727559..3a49d5fad4b 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H @@ -91,7 +91,7 @@ public: amrex::Vector, 3>> const& Bfield, amrex::Vector> const& rhofield, amrex::Vector, 3>> const& edge_lengths, - bool include_resistivity_term); + bool solve_for_Faraday); void HybridPICSolveE ( std::array< std::unique_ptr, 3>& Efield, @@ -99,7 +99,7 @@ public: std::array< std::unique_ptr, 3> const& Bfield, std::unique_ptr const& rhofield, std::array< std::unique_ptr, 3> const& edge_lengths, - int lev, bool include_resistivity_term); + int lev, bool solve_for_Faraday); void HybridPICSolveE ( std::array< std::unique_ptr, 3>& Efield, @@ -107,7 +107,7 @@ public: std::array< std::unique_ptr, 3> const& Bfield, std::unique_ptr const& rhofield, std::array< std::unique_ptr, 3> const& edge_lengths, - int lev, PatchType patch_type, bool include_resistivity_term); + int lev, PatchType patch_type, bool solve_for_Faraday); void BfieldEvolveRK ( amrex::Vector, 3>>& Bfield, @@ -138,12 +138,11 @@ public: /** * \brief - * Function to calculate the electron pressure at a given timestep type - * using the simulation charge density. Used in the Ohm's law solver - * (kinetic-fluid hybrid model). + * Function to calculate the electron pressure using the simulation charge + * density. Used in the Ohm's law solver (kinetic-fluid hybrid model). */ - void CalculateElectronPressure ( DtType a_dt_type); - void CalculateElectronPressure (int lev, DtType a_dt_type); + void CalculateElectronPressure (); + void CalculateElectronPressure (int lev); /** * \brief Fill the electron pressure multifab given the kinetic particle diff --git a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp index 6a72bb3569c..70efc04e259 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp @@ -9,6 +9,7 @@ #include "HybridPICModel.H" +#include "EmbeddedBoundary/Enabled.H" #include "FieldSolver/Fields.H" #include "WarpX.H" @@ -226,23 +227,23 @@ void HybridPICModel::InitData () // Initialize external current - note that this approach skips the check // if the current is time dependent which is what needs to be done to // write time independent fields on the first step. - for (int lev = 0; lev <= warpx.finestLevel(); ++lev) - { + for (int lev = 0; lev <= warpx.finestLevel(); ++lev) { + auto edge_lengths = std::array, 3>(); #ifdef AMREX_USE_EB - auto& edge_lengths_x = warpx.getField(FieldType::edge_lengths, lev, 0); - auto& edge_lengths_y = warpx.getField(FieldType::edge_lengths, lev, 1); - auto& edge_lengths_z = warpx.getField(FieldType::edge_lengths, lev, 2); - - const auto edge_lengths = std::array< std::unique_ptr, 3 >{ - std::make_unique( - edge_lengths_x, amrex::make_alias, 0, edge_lengths_x.nComp()), - std::make_unique( - edge_lengths_y, amrex::make_alias, 0, edge_lengths_y.nComp()), - std::make_unique( - edge_lengths_z, amrex::make_alias, 0, edge_lengths_z.nComp()) - }; -#else - const auto edge_lengths = std::array< std::unique_ptr, 3 >(); + if (EB::enabled()) { + auto const & edge_lengths_x = warpx.getField(FieldType::edge_lengths, lev, 0); + auto const & edge_lengths_y = warpx.getField(FieldType::edge_lengths, lev, 1); + auto const & edge_lengths_z = warpx.getField(FieldType::edge_lengths, lev, 2); + + edge_lengths = std::array< std::unique_ptr, 3 >{ + std::make_unique( + edge_lengths_x, amrex::make_alias, 0, edge_lengths_x.nComp()), + std::make_unique( + edge_lengths_y, amrex::make_alias, 0, edge_lengths_y.nComp()), + std::make_unique( + edge_lengths_z, amrex::make_alias, 0, edge_lengths_z.nComp()) + }; + } #endif GetCurrentExternal(edge_lengths, lev); } @@ -289,31 +290,26 @@ void HybridPICModel::GetCurrentExternal ( for ( MFIter mfi(*mfx, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const amrex::Box& tbx = mfi.tilebox( x_nodal_flag, mfx->nGrowVect() ); - const amrex::Box& tby = mfi.tilebox( y_nodal_flag, mfy->nGrowVect() ); - const amrex::Box& tbz = mfi.tilebox( z_nodal_flag, mfz->nGrowVect() ); + const amrex::Box& tbx = mfi.tilebox( x_nodal_flag, mfx->nGrowVect() ); + const amrex::Box& tby = mfi.tilebox( y_nodal_flag, mfy->nGrowVect() ); + const amrex::Box& tbz = mfi.tilebox( z_nodal_flag, mfz->nGrowVect() ); - auto const& mfxfab = mfx->array(mfi); - auto const& mfyfab = mfy->array(mfi); - auto const& mfzfab = mfz->array(mfi); + auto const& mfxfab = mfx->array(mfi); + auto const& mfyfab = mfy->array(mfi); + auto const& mfzfab = mfz->array(mfi); -#ifdef AMREX_USE_EB - amrex::Array4 const& lx = edge_lengths[0]->array(mfi); - amrex::Array4 const& ly = edge_lengths[1]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ignore_unused(ly); -#endif -#else - amrex::ignore_unused(edge_lengths); -#endif + amrex::Array4 lx, ly, lz; + if (EB::enabled()) { + lx = edge_lengths[0]->array(mfi); + ly = edge_lengths[1]->array(mfi); + lz = edge_lengths[2]->array(mfi); + } amrex::ParallelFor (tbx, tby, tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k) { // skip if node is covered by an embedded boundary -#ifdef AMREX_USE_EB - if (lx(i, j, k) <= 0) return; -#endif + if (lx && lx(i, j, k) <= 0) { return; } + // Shift required in the x-, y-, or z- position // depending on the index type of the multifab #if defined(WARPX_DIM_1D_Z) @@ -340,9 +336,8 @@ void HybridPICModel::GetCurrentExternal ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { // skip if node is covered by an embedded boundary -#ifdef AMREX_USE_EB - if (ly(i, j, k) <= 0) return; -#endif + if (ly && ly(i, j, k) <= 0) { return; } + #if defined(WARPX_DIM_1D_Z) const amrex::Real x = 0._rt; const amrex::Real y = 0._rt; @@ -367,9 +362,8 @@ void HybridPICModel::GetCurrentExternal ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { // skip if node is covered by an embedded boundary -#ifdef AMREX_USE_EB - if (lz(i, j, k) <= 0) return; -#endif + if (lz && lz(i, j, k) <= 0) { return; } + #if defined(WARPX_DIM_1D_Z) const amrex::Real x = 0._rt; const amrex::Real y = 0._rt; @@ -432,14 +426,14 @@ void HybridPICModel::HybridPICSolveE ( amrex::Vector, 3>> const& Bfield, amrex::Vector> const& rhofield, amrex::Vector, 3>> const& edge_lengths, - const bool include_resistivity_term) + const bool solve_for_Faraday) { auto& warpx = WarpX::GetInstance(); for (int lev = 0; lev <= warpx.finestLevel(); ++lev) { HybridPICSolveE( Efield[lev], Jfield[lev], Bfield[lev], rhofield[lev], - edge_lengths[lev], lev, include_resistivity_term + edge_lengths[lev], lev, solve_for_Faraday ); } } @@ -450,13 +444,13 @@ void HybridPICModel::HybridPICSolveE ( std::array< std::unique_ptr, 3> const& Bfield, std::unique_ptr const& rhofield, std::array< std::unique_ptr, 3> const& edge_lengths, - const int lev, const bool include_resistivity_term) + const int lev, const bool solve_for_Faraday) { WARPX_PROFILE("WarpX::HybridPICSolveE()"); HybridPICSolveE( Efield, Jfield, Bfield, rhofield, edge_lengths, lev, - PatchType::fine, include_resistivity_term + PatchType::fine, solve_for_Faraday ); if (lev > 0) { @@ -472,7 +466,7 @@ void HybridPICModel::HybridPICSolveE ( std::unique_ptr const& rhofield, std::array< std::unique_ptr, 3> const& edge_lengths, const int lev, PatchType patch_type, - const bool include_resistivity_term) + const bool solve_for_Faraday) { auto& warpx = WarpX::GetInstance(); @@ -481,36 +475,29 @@ void HybridPICModel::HybridPICSolveE ( Efield, current_fp_ampere[lev], Jfield, current_fp_external[lev], Bfield, rhofield, electron_pressure_fp[lev], - edge_lengths, lev, this, include_resistivity_term + edge_lengths, lev, this, solve_for_Faraday ); warpx.ApplyEfieldBoundary(lev, patch_type); } -void HybridPICModel::CalculateElectronPressure(DtType a_dt_type) +void HybridPICModel::CalculateElectronPressure() { auto& warpx = WarpX::GetInstance(); for (int lev = 0; lev <= warpx.finestLevel(); ++lev) { - CalculateElectronPressure(lev, a_dt_type); + CalculateElectronPressure(lev); } } -void HybridPICModel::CalculateElectronPressure(const int lev, DtType a_dt_type) +void HybridPICModel::CalculateElectronPressure(const int lev) { WARPX_PROFILE("WarpX::CalculateElectronPressure()"); auto& warpx = WarpX::GetInstance(); - // The full step uses rho^{n+1}, otherwise use the old or averaged - // charge density. - if (a_dt_type == DtType::Full) { - FillElectronPressureMF( - electron_pressure_fp[lev], warpx.getFieldPointer(FieldType::rho_fp, lev) - ); - } else { - FillElectronPressureMF( - electron_pressure_fp[lev], rho_fp_temp[lev].get() - ); - } + // Calculate the electron pressure using rho^{n+1}. + FillElectronPressureMF( + electron_pressure_fp[lev], warpx.getFieldPointer(FieldType::rho_fp, lev) + ); warpx.ApplyElectronPressureBoundary(lev, PatchType::fine); electron_pressure_fp[lev]->FillBoundary(warpx.Geom(lev).periodicity()); } diff --git a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICSolveE.cpp b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICSolveE.cpp index 456c542a534..baeaf7a6c18 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICSolveE.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICSolveE.cpp @@ -9,6 +9,7 @@ #include "FiniteDifferenceSolver.H" +#include "EmbeddedBoundary/Enabled.H" #ifdef WARPX_DIM_RZ # include "FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H" #else @@ -67,10 +68,6 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCylindrical ( // for the profiler amrex::LayoutData* cost = WarpX::getCosts(lev); -#ifndef AMREX_USE_EB - amrex::ignore_unused(edge_lengths); -#endif - // reset Jfield Jfield[0]->setVal(0); Jfield[1]->setVal(0); @@ -95,11 +92,13 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCylindrical ( Array4 const& Bt = Bfield[1]->array(mfi); Array4 const& Bz = Bfield[2]->array(mfi); -#ifdef AMREX_USE_EB - amrex::Array4 const& lr = edge_lengths[0]->array(mfi); - amrex::Array4 const& lt = edge_lengths[1]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); -#endif + amrex::Array4 lr, lt, lz; + + if (EB::enabled()) { + lr = edge_lengths[0]->array(mfi); + lt = edge_lengths[1]->array(mfi); + lz = edge_lengths[2]->array(mfi); + } // Extract stencil coefficients Real const * const AMREX_RESTRICT coefs_r = m_stencil_coefs_r.dataPtr(); @@ -125,10 +124,8 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCylindrical ( // Jr calculation [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // Skip if this cell is fully covered by embedded boundaries - if (lr(i, j, 0) <= 0) return; -#endif + if (lr && lr(i, j, 0) <= 0) { return; } // Mode m=0 Jr(i, j, 0, 0) = one_over_mu0 * ( - T_Algo::DownwardDz(Bt, coefs_z, n_coefs_z, i, j, 0, 0) @@ -151,11 +148,9 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCylindrical ( // Jt calculation [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // In RZ Jt is associated with a mesh node, so we need to check if the mesh node is covered - amrex::ignore_unused(lt); - if (lr(i, j, 0)<=0 || lr(i-1, j, 0)<=0 || lz(i, j-1, 0)<=0 || lz(i, j, 0)<=0) return; -#endif + if (lr && (lr(i, j, 0)<=0 || lr(i-1, j, 0)<=0 || lz(i, j-1, 0)<=0 || lz(i, j, 0)<=0)) { return; } + // r on a nodal point (Jt is nodal in r) Real const r = rmin + i*dr; // Off-axis, regular curl @@ -199,10 +194,8 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCylindrical ( // Jz calculation [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // Skip if this cell is fully covered by embedded boundaries - if (lz(i, j, 0) <= 0) return; -#endif + if (lz && lz(i, j, 0) <= 0) { return; } // r on a nodal point (Jz is nodal in r) Real const r = rmin + i*dr; // Off-axis, regular curl @@ -258,10 +251,6 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCartesian ( // for the profiler amrex::LayoutData* cost = WarpX::getCosts(lev); -#ifndef AMREX_USE_EB - amrex::ignore_unused(edge_lengths); -#endif - // reset Jfield Jfield[0]->setVal(0); Jfield[1]->setVal(0); @@ -272,25 +261,25 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCartesian ( #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif for ( MFIter mfi(*Jfield[0], TilingIfNotGPU()); mfi.isValid(); ++mfi ) { - if (cost && WarpX::load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Timers) - { + if (cost && WarpX::load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Timers) { amrex::Gpu::synchronize(); } auto wt = static_cast(amrex::second()); // Extract field data for this grid/tile - Array4 const& Jx = Jfield[0]->array(mfi); - Array4 const& Jy = Jfield[1]->array(mfi); - Array4 const& Jz = Jfield[2]->array(mfi); - Array4 const& Bx = Bfield[0]->const_array(mfi); - Array4 const& By = Bfield[1]->const_array(mfi); - Array4 const& Bz = Bfield[2]->const_array(mfi); - -#ifdef AMREX_USE_EB - amrex::Array4 const& lx = edge_lengths[0]->array(mfi); - amrex::Array4 const& ly = edge_lengths[1]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); -#endif + Array4 const &Jx = Jfield[0]->array(mfi); + Array4 const &Jy = Jfield[1]->array(mfi); + Array4 const &Jz = Jfield[2]->array(mfi); + Array4 const &Bx = Bfield[0]->const_array(mfi); + Array4 const &By = Bfield[1]->const_array(mfi); + Array4 const &Bz = Bfield[2]->const_array(mfi); + + amrex::Array4 lx, ly, lz; + if (EB::enabled()) { + lx = edge_lengths[0]->array(mfi); + ly = edge_lengths[1]->array(mfi); + lz = edge_lengths[2]->array(mfi); + } // Extract stencil coefficients Real const * const AMREX_RESTRICT coefs_x = m_stencil_coefs_x.dataPtr(); @@ -313,10 +302,9 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCartesian ( // Jx calculation [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip if this cell is fully covered by embedded boundaries - if (lx(i, j, k) <= 0) return; -#endif + if (lx && lx(i, j, k) <= 0) { return; } + Jx(i, j, k) = one_over_mu0 * ( - T_Algo::DownwardDz(By, coefs_z, n_coefs_z, i, j, k) + T_Algo::DownwardDy(Bz, coefs_y, n_coefs_y, i, j, k) @@ -325,15 +313,13 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCartesian ( // Jy calculation [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip if this cell is fully covered by embedded boundaries #ifdef WARPX_DIM_3D - if (ly(i,j,k) <= 0) return; + if (ly && ly(i,j,k) <= 0) { return; } #elif defined(WARPX_DIM_XZ) // In XZ Jy is associated with a mesh node, so we need to check if the mesh node is covered amrex::ignore_unused(ly); - if (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j-1, k)<=0 || lz(i, j, k)<=0) return; -#endif + if (lx && (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j-1, k)<=0 || lz(i, j, k)<=0)) { return; } #endif Jy(i, j, k) = one_over_mu0 * ( - T_Algo::DownwardDx(Bz, coefs_x, n_coefs_x, i, j, k) @@ -343,10 +329,9 @@ void FiniteDifferenceSolver::CalculateCurrentAmpereCartesian ( // Jz calculation [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip if this cell is fully covered by embedded boundaries - if (lz(i,j,k) <= 0) return; -#endif + if (lz && lz(i,j,k) <= 0) { return; } + Jz(i, j, k) = one_over_mu0 * ( - T_Algo::DownwardDy(Bx, coefs_y, n_coefs_y, i, j, k) + T_Algo::DownwardDx(By, coefs_x, n_coefs_x, i, j, k) @@ -375,7 +360,7 @@ void FiniteDifferenceSolver::HybridPICSolveE ( std::unique_ptr const& Pefield, std::array< std::unique_ptr, 3 > const& edge_lengths, int lev, HybridPICModel const* hybrid_model, - const bool include_resistivity_term) + const bool solve_for_Faraday) { // Select algorithm (The choice of algorithm is a runtime option, // but we compile code for each algorithm, using templates) @@ -384,14 +369,14 @@ void FiniteDifferenceSolver::HybridPICSolveE ( HybridPICSolveECylindrical ( Efield, Jfield, Jifield, Jextfield, Bfield, rhofield, Pefield, - edge_lengths, lev, hybrid_model, include_resistivity_term + edge_lengths, lev, hybrid_model, solve_for_Faraday ); #else HybridPICSolveECartesian ( Efield, Jfield, Jifield, Jextfield, Bfield, rhofield, Pefield, - edge_lengths, lev, hybrid_model, include_resistivity_term + edge_lengths, lev, hybrid_model, solve_for_Faraday ); #endif @@ -413,12 +398,8 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( std::unique_ptr const& Pefield, std::array< std::unique_ptr, 3 > const& edge_lengths, int lev, HybridPICModel const* hybrid_model, - const bool include_resistivity_term ) + const bool solve_for_Faraday ) { -#ifndef AMREX_USE_EB - amrex::ignore_unused(edge_lengths); -#endif - // Both steps below do not currently support m > 0 and should be // modified if such support wants to be added WARPX_ALWAYS_ASSERT_WITH_MESSAGE( @@ -436,7 +417,7 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( const auto rho_floor = hybrid_model->m_n_floor * PhysConst::q_e; const auto resistivity_has_J_dependence = hybrid_model->m_resistivity_has_J_dependence; - const bool include_hyper_resistivity_term = (eta_h > 0.0) && include_resistivity_term; + const bool include_hyper_resistivity_term = (eta_h > 0.0) && solve_for_Faraday; // Index type required for interpolating fields from their respective // staggering to the Ex, Ey, Ez locations @@ -561,11 +542,12 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( Array4 const& rho = rhofield->const_array(mfi); Array4 const& Pe = Pefield->array(mfi); -#ifdef AMREX_USE_EB - amrex::Array4 const& lr = edge_lengths[0]->array(mfi); - amrex::Array4 const& lt = edge_lengths[1]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); -#endif + amrex::Array4 lr, lz; + if (EB::enabled()) { + lr = edge_lengths[0]->array(mfi); + // edge_lengths[1] is `lt` and is not needed + lz = edge_lengths[2]->array(mfi); + } // Extract stencil coefficients Real const * const AMREX_RESTRICT coefs_r = m_stencil_coefs_r.dataPtr(); @@ -586,16 +568,15 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( // Er calculation [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // Skip if this cell is fully covered by embedded boundaries - if (lr(i, j, 0) <= 0) return; -#endif + if (lr && lr(i, j, 0) <= 0) { return; } + // Interpolate to get the appropriate charge density in space Real rho_val = Interp(rho, nodal, Er_stag, coarsen, i, j, 0, 0); // Interpolate current to appropriate staggering to match E field Real jtot_val = 0._rt; - if (include_resistivity_term && resistivity_has_J_dependence) { + if (solve_for_Faraday && resistivity_has_J_dependence) { const Real jr_val = Interp(Jr, Jr_stag, Er_stag, coarsen, i, j, 0, 0); const Real jt_val = Interp(Jt, Jt_stag, Er_stag, coarsen, i, j, 0, 0); const Real jz_val = Interp(Jz, Jz_stag, Er_stag, coarsen, i, j, 0, 0); @@ -605,8 +586,10 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( // safety condition since we divide by rho_val later if (rho_val < rho_floor) { rho_val = rho_floor; } - // Get the gradient of the electron pressure - auto grad_Pe = T_Algo::UpwardDr(Pe, coefs_r, n_coefs_r, i, j, 0, 0); + // Get the gradient of the electron pressure if the longitudinal part of + // the E-field should be included, otherwise ignore it since curl x (grad Pe) = 0 + Real grad_Pe = 0._rt; + if (!solve_for_Faraday) { grad_Pe = T_Algo::UpwardDr(Pe, coefs_r, n_coefs_r, i, j, 0, 0); } // interpolate the nodal neE values to the Yee grid auto enE_r = Interp(enE, nodal, Er_stag, coarsen, i, j, 0, 0); @@ -614,7 +597,7 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( Er(i, j, 0) = (enE_r - grad_Pe) / rho_val; // Add resistivity only if E field value is used to update B - if (include_resistivity_term) { Er(i, j, 0) += eta(rho_val, jtot_val) * Jr(i, j, 0); } + if (solve_for_Faraday) { Er(i, j, 0) += eta(rho_val, jtot_val) * Jr(i, j, 0); } if (include_hyper_resistivity_term) { // r on cell-centered point (Jr is cell-centered in r) @@ -627,11 +610,9 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( // Et calculation [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // In RZ Et is associated with a mesh node, so we need to check if the mesh node is covered - amrex::ignore_unused(lt); - if (lr(i, j, 0)<=0 || lr(i-1, j, 0)<=0 || lz(i, j-1, 0)<=0 || lz(i, j, 0)<=0) return; -#endif + if (lr && (lr(i, j, 0)<=0 || lr(i-1, j, 0)<=0 || lz(i, j-1, 0)<=0 || lz(i, j, 0)<=0)) { return; } + // r on a nodal grid (Et is nodal in r) Real const r = rmin + i*dr; // Mode m=0: // Ensure that Et remains 0 on axis @@ -645,7 +626,7 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( // Interpolate current to appropriate staggering to match E field Real jtot_val = 0._rt; - if (include_resistivity_term && resistivity_has_J_dependence) { + if (solve_for_Faraday && resistivity_has_J_dependence) { const Real jr_val = Interp(Jr, Jr_stag, Et_stag, coarsen, i, j, 0, 0); const Real jt_val = Interp(Jt, Jt_stag, Et_stag, coarsen, i, j, 0, 0); const Real jz_val = Interp(Jz, Jz_stag, Et_stag, coarsen, i, j, 0, 0); @@ -665,23 +646,22 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( Et(i, j, 0) = (enE_t - grad_Pe) / rho_val; // Add resistivity only if E field value is used to update B - if (include_resistivity_term) { Et(i, j, 0) += eta(rho_val, jtot_val) * Jt(i, j, 0); } + if (solve_for_Faraday) { Et(i, j, 0) += eta(rho_val, jtot_val) * Jt(i, j, 0); } // Note: Hyper-resisitivity should be revisited here when modal decomposition is implemented }, // Ez calculation [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/){ -#ifdef AMREX_USE_EB // Skip field solve if this cell is fully covered by embedded boundaries - if (lz(i,j,0) <= 0) { return; } -#endif + if (lz && lz(i,j,0) <= 0) { return; } + // Interpolate to get the appropriate charge density in space Real rho_val = Interp(rho, nodal, Ez_stag, coarsen, i, j, 0, 0); // Interpolate current to appropriate staggering to match E field Real jtot_val = 0._rt; - if (include_resistivity_term && resistivity_has_J_dependence) { + if (solve_for_Faraday && resistivity_has_J_dependence) { const Real jr_val = Interp(Jr, Jr_stag, Ez_stag, coarsen, i, j, 0, 0); const Real jt_val = Interp(Jt, Jt_stag, Ez_stag, coarsen, i, j, 0, 0); const Real jz_val = Interp(Jz, Jz_stag, Ez_stag, coarsen, i, j, 0, 0); @@ -691,8 +671,10 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( // safety condition since we divide by rho_val later if (rho_val < rho_floor) { rho_val = rho_floor; } - // Get the gradient of the electron pressure - auto grad_Pe = T_Algo::UpwardDz(Pe, coefs_z, n_coefs_z, i, j, 0, 0); + // Get the gradient of the electron pressure if the longitudinal part of + // the E-field should be included, otherwise ignore it since curl x (grad Pe) = 0 + Real grad_Pe = 0._rt; + if (!solve_for_Faraday) { grad_Pe = T_Algo::UpwardDz(Pe, coefs_z, n_coefs_z, i, j, 0, 0); } // interpolate the nodal neE values to the Yee grid auto enE_z = Interp(enE, nodal, Ez_stag, coarsen, i, j, 0, 2); @@ -700,7 +682,7 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical ( Ez(i, j, 0) = (enE_z - grad_Pe) / rho_val; // Add resistivity only if E field value is used to update B - if (include_resistivity_term) { Ez(i, j, 0) += eta(rho_val, jtot_val) * Jz(i, j, 0); } + if (solve_for_Faraday) { Ez(i, j, 0) += eta(rho_val, jtot_val) * Jz(i, j, 0); } if (include_hyper_resistivity_term) { auto nabla2Jz = T_Algo::Dzz(Jz, coefs_z, n_coefs_z, i, j, 0, 0); @@ -731,12 +713,8 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( std::unique_ptr const& Pefield, std::array< std::unique_ptr, 3 > const& edge_lengths, int lev, HybridPICModel const* hybrid_model, - const bool include_resistivity_term ) + const bool solve_for_Faraday ) { -#ifndef AMREX_USE_EB - amrex::ignore_unused(edge_lengths); -#endif - // for the profiler amrex::LayoutData* cost = WarpX::getCosts(lev); @@ -748,7 +726,7 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( const auto rho_floor = hybrid_model->m_n_floor * PhysConst::q_e; const auto resistivity_has_J_dependence = hybrid_model->m_resistivity_has_J_dependence; - const bool include_hyper_resistivity_term = (eta_h > 0.) && include_resistivity_term; + const bool include_hyper_resistivity_term = (eta_h > 0.) && solve_for_Faraday; // Index type required for interpolating fields from their respective // staggering to the Ex, Ey, Ez locations @@ -873,11 +851,12 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( Array4 const& rho = rhofield->const_array(mfi); Array4 const& Pe = Pefield->array(mfi); -#ifdef AMREX_USE_EB - amrex::Array4 const& lx = edge_lengths[0]->array(mfi); - amrex::Array4 const& ly = edge_lengths[1]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); -#endif + amrex::Array4 lx, ly, lz; + if (EB::enabled()) { + lx = edge_lengths[0]->array(mfi); + ly = edge_lengths[1]->array(mfi); + lz = edge_lengths[2]->array(mfi); + } // Extract stencil coefficients Real const * const AMREX_RESTRICT coefs_x = m_stencil_coefs_x.dataPtr(); @@ -896,16 +875,15 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( // Ex calculation [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip if this cell is fully covered by embedded boundaries - if (lx(i, j, k) <= 0) return; -#endif + if (lx && lx(i, j, k) <= 0) { return; } + // Interpolate to get the appropriate charge density in space Real rho_val = Interp(rho, nodal, Ex_stag, coarsen, i, j, k, 0); // Interpolate current to appropriate staggering to match E field Real jtot_val = 0._rt; - if (include_resistivity_term && resistivity_has_J_dependence) { + if (solve_for_Faraday && resistivity_has_J_dependence) { const Real jx_val = Interp(Jx, Jx_stag, Ex_stag, coarsen, i, j, k, 0); const Real jy_val = Interp(Jy, Jy_stag, Ex_stag, coarsen, i, j, k, 0); const Real jz_val = Interp(Jz, Jz_stag, Ex_stag, coarsen, i, j, k, 0); @@ -915,8 +893,10 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( // safety condition since we divide by rho_val later if (rho_val < rho_floor) { rho_val = rho_floor; } - // Get the gradient of the electron pressure - auto grad_Pe = T_Algo::UpwardDx(Pe, coefs_x, n_coefs_x, i, j, k); + // Get the gradient of the electron pressure if the longitudinal part of + // the E-field should be included, otherwise ignore it since curl x (grad Pe) = 0 + Real grad_Pe = 0._rt; + if (!solve_for_Faraday) { grad_Pe = T_Algo::UpwardDx(Pe, coefs_x, n_coefs_x, i, j, k); } // interpolate the nodal neE values to the Yee grid auto enE_x = Interp(enE, nodal, Ex_stag, coarsen, i, j, k, 0); @@ -924,7 +904,7 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( Ex(i, j, k) = (enE_x - grad_Pe) / rho_val; // Add resistivity only if E field value is used to update B - if (include_resistivity_term) { Ex(i, j, k) += eta(rho_val, jtot_val) * Jx(i, j, k); } + if (solve_for_Faraday) { Ex(i, j, k) += eta(rho_val, jtot_val) * Jx(i, j, k); } if (include_hyper_resistivity_term) { auto nabla2Jx = T_Algo::Dxx(Jx, coefs_x, n_coefs_x, i, j, k); @@ -933,23 +913,21 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( }, // Ey calculation - [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB + [=] AMREX_GPU_DEVICE (int i, int j, int k) { // Skip field solve if this cell is fully covered by embedded boundaries #ifdef WARPX_DIM_3D - if (ly(i,j,k) <= 0) { return; } + if (ly && ly(i,j,k) <= 0) { return; } #elif defined(WARPX_DIM_XZ) //In XZ Ey is associated with a mesh node, so we need to check if the mesh node is covered amrex::ignore_unused(ly); - if (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j-1, k)<=0 || lz(i, j, k)<=0) { return; } -#endif + if (lx && (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j-1, k)<=0 || lz(i, j, k)<=0)) { return; } #endif // Interpolate to get the appropriate charge density in space Real rho_val = Interp(rho, nodal, Ey_stag, coarsen, i, j, k, 0); // Interpolate current to appropriate staggering to match E field Real jtot_val = 0._rt; - if (include_resistivity_term && resistivity_has_J_dependence) { + if (solve_for_Faraday && resistivity_has_J_dependence) { const Real jx_val = Interp(Jx, Jx_stag, Ey_stag, coarsen, i, j, k, 0); const Real jy_val = Interp(Jy, Jy_stag, Ey_stag, coarsen, i, j, k, 0); const Real jz_val = Interp(Jz, Jz_stag, Ey_stag, coarsen, i, j, k, 0); @@ -959,8 +937,10 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( // safety condition since we divide by rho_val later if (rho_val < rho_floor) { rho_val = rho_floor; } - // Get the gradient of the electron pressure - auto grad_Pe = T_Algo::UpwardDy(Pe, coefs_y, n_coefs_y, i, j, k); + // Get the gradient of the electron pressure if the longitudinal part of + // the E-field should be included, otherwise ignore it since curl x (grad Pe) = 0 + Real grad_Pe = 0._rt; + if (!solve_for_Faraday) { grad_Pe = T_Algo::UpwardDy(Pe, coefs_y, n_coefs_y, i, j, k); } // interpolate the nodal neE values to the Yee grid auto enE_y = Interp(enE, nodal, Ey_stag, coarsen, i, j, k, 1); @@ -968,7 +948,7 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( Ey(i, j, k) = (enE_y - grad_Pe) / rho_val; // Add resistivity only if E field value is used to update B - if (include_resistivity_term) { Ey(i, j, k) += eta(rho_val, jtot_val) * Jy(i, j, k); } + if (solve_for_Faraday) { Ey(i, j, k) += eta(rho_val, jtot_val) * Jy(i, j, k); } if (include_hyper_resistivity_term) { auto nabla2Jy = T_Algo::Dyy(Jy, coefs_y, n_coefs_y, i, j, k); @@ -980,14 +960,14 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( [=] AMREX_GPU_DEVICE (int i, int j, int k){ #ifdef AMREX_USE_EB // Skip field solve if this cell is fully covered by embedded boundaries - if (lz(i,j,k) <= 0) { return; } + if (lz && lz(i,j,k) <= 0) { return; } #endif // Interpolate to get the appropriate charge density in space Real rho_val = Interp(rho, nodal, Ez_stag, coarsen, i, j, k, 0); // Interpolate current to appropriate staggering to match E field Real jtot_val = 0._rt; - if (include_resistivity_term && resistivity_has_J_dependence) { + if (solve_for_Faraday && resistivity_has_J_dependence) { const Real jx_val = Interp(Jx, Jx_stag, Ez_stag, coarsen, i, j, k, 0); const Real jy_val = Interp(Jy, Jy_stag, Ez_stag, coarsen, i, j, k, 0); const Real jz_val = Interp(Jz, Jz_stag, Ez_stag, coarsen, i, j, k, 0); @@ -997,8 +977,10 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( // safety condition since we divide by rho_val later if (rho_val < rho_floor) { rho_val = rho_floor; } - // Get the gradient of the electron pressure - auto grad_Pe = T_Algo::UpwardDz(Pe, coefs_z, n_coefs_z, i, j, k); + // Get the gradient of the electron pressure if the longitudinal part of + // the E-field should be included, otherwise ignore it since curl x (grad Pe) = 0 + Real grad_Pe = 0._rt; + if (!solve_for_Faraday) { grad_Pe = T_Algo::UpwardDz(Pe, coefs_z, n_coefs_z, i, j, k); } // interpolate the nodal neE values to the Yee grid auto enE_z = Interp(enE, nodal, Ez_stag, coarsen, i, j, k, 2); @@ -1006,7 +988,7 @@ void FiniteDifferenceSolver::HybridPICSolveECartesian ( Ez(i, j, k) = (enE_z - grad_Pe) / rho_val; // Add resistivity only if E field value is used to update B - if (include_resistivity_term) { Ez(i, j, k) += eta(rho_val, jtot_val) * Jz(i, j, k); } + if (solve_for_Faraday) { Ez(i, j, k) += eta(rho_val, jtot_val) * Jz(i, j, k); } if (include_hyper_resistivity_term) { auto nabla2Jz = T_Algo::Dzz(Jz, coefs_z, n_coefs_z, i, j, k); diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp index 3aee7697073..46e4d3efa06 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp @@ -7,6 +7,7 @@ # include "FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H" # include "FiniteDifferenceAlgorithms/FieldAccessorFunctors.H" #endif +#include "EmbeddedBoundary/Enabled.H" #include "MacroscopicProperties/MacroscopicProperties.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" @@ -139,10 +140,14 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian ( Array4 const& jy = Jfield[1]->array(mfi); Array4 const& jz = Jfield[2]->array(mfi); -#ifdef AMREX_USE_EB - amrex::Array4 const& lx = edge_lengths[0]->array(mfi); - amrex::Array4 const& ly = edge_lengths[1]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); + amrex::Array4 eb_lx, eb_ly, eb_lz; + if (EB::enabled()) { + eb_lx = edge_lengths[0]->array(mfi); + eb_ly = edge_lengths[1]->array(mfi); + eb_lz = edge_lengths[2]->array(mfi); + } +#ifdef WARPX_DIM_XZ + amrex::ignore_unused(eb_ly); #endif // material prop // @@ -174,10 +179,9 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian ( // Loop over the cells and update the fields amrex::ParallelFor(tex, tey, tez, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries - if (lx(i, j, k) <= 0) return; -#endif + if (eb_lx && eb_lx(i, j, k) <= 0) { return; } + // Interpolate conductivity, sigma, to Ex position on the grid amrex::Real const sigma_interp = ablastr::coarsen::sample::Interp(sigma_arr, sigma_stag, Ex_stag, macro_cr, i, j, k, scomp); @@ -193,15 +197,13 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB #ifdef WARPX_DIM_3D - if (ly(i,j,k) <= 0) return; + if (eb_ly && eb_ly(i,j,k) <= 0) { return; } #elif defined(WARPX_DIM_XZ) //In XZ Ey is associated with a mesh node, so we need to check if the mesh node is covered - amrex::ignore_unused(ly); - if (lx(i, j, k)<=0 || lx(i-1, j, k)<=0 || lz(i, j, k)<=0 || lz(i, j-1, k)<=0) return; -#endif + if (eb_lx && (eb_lx(i, j, k)<=0 || eb_lx(i-1, j, k)<=0 || eb_lz(i, j, k)<=0 || eb_lz(i, j-1, k)<=0)) { return; } #endif + // Interpolate conductivity, sigma, to Ey position on the grid amrex::Real const sigma_interp = ablastr::coarsen::sample::Interp(sigma_arr, sigma_stag, Ey_stag, macro_cr, i, j, k, scomp); @@ -218,10 +220,9 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian ( }, [=] AMREX_GPU_DEVICE (int i, int j, int k){ -#ifdef AMREX_USE_EB // Skip field push if this cell is fully covered by embedded boundaries - if (lz(i,j,k) <= 0) return; -#endif + if (eb_lz && eb_lz(i, j, k) <= 0) { return; } + // Interpolate conductivity, sigma, to Ez position on the grid amrex::Real const sigma_interp = ablastr::coarsen::sample::Interp(sigma_arr, sigma_stag, Ez_stag, macro_cr, i, j, k, scomp); diff --git a/Source/FieldSolver/ImplicitSolvers/SemiImplicitEM.cpp b/Source/FieldSolver/ImplicitSolvers/SemiImplicitEM.cpp index 897bd5c07f3..33e2ced7b53 100644 --- a/Source/FieldSolver/ImplicitSolvers/SemiImplicitEM.cpp +++ b/Source/FieldSolver/ImplicitSolvers/SemiImplicitEM.cpp @@ -20,13 +20,8 @@ void SemiImplicitEM::Define ( WarpX* a_WarpX ) m_WarpX = a_WarpX; // Define E and Eold vectors - m_E.Define( m_WarpX->getMultiLevelField(FieldType::Efield_fp) ); - m_Eold.Define( m_WarpX->getMultiLevelField(FieldType::Efield_fp) ); - - // Need to define the WarpXSolverVec owned dot_mask to do dot - // product correctly for linear and nonlinear solvers - const amrex::Vector& Geom = m_WarpX->Geom(); - m_E.SetDotMask(Geom); + m_E.Define( m_WarpX, FieldType::Efield_fp ); + m_Eold.Define( m_E ); // Parse implicit solver parameters const amrex::ParmParse pp("implicit_evolve"); @@ -41,21 +36,20 @@ void SemiImplicitEM::Define ( WarpX* a_WarpX ) void SemiImplicitEM::PrintParameters () const { if (!m_WarpX->Verbose()) { return; } - amrex::Print() << std::endl; - amrex::Print() << "-----------------------------------------------------------" << std::endl; - amrex::Print() << "----------- SEMI IMPLICIT EM SOLVER PARAMETERS ------------" << std::endl; - amrex::Print() << "-----------------------------------------------------------" << std::endl; - amrex::Print() << "max particle iterations: " << m_max_particle_iterations << std::endl; - amrex::Print() << "particle tolerance: " << m_particle_tolerance << std::endl; + amrex::Print() << "\n"; + amrex::Print() << "-----------------------------------------------------------\n"; + amrex::Print() << "----------- SEMI IMPLICIT EM SOLVER PARAMETERS ------------\n"; + amrex::Print() << "-----------------------------------------------------------\n"; + amrex::Print() << "max particle iterations: " << m_max_particle_iterations << "\n"; + amrex::Print() << "particle tolerance: " << m_particle_tolerance << "\n"; if (m_nlsolver_type==NonlinearSolverType::Picard) { - amrex::Print() << "Nonlinear solver type: Picard" << std::endl; + amrex::Print() << "Nonlinear solver type: Picard\n"; } else if (m_nlsolver_type==NonlinearSolverType::Newton) { - amrex::Print() << "Nonlinear solver type: Newton" << std::endl; + amrex::Print() << "Nonlinear solver type: Newton\n"; } m_nlsolver->PrintParams(); - amrex::Print() << "-----------------------------------------------------------" << std::endl; - amrex::Print() << std::endl; + amrex::Print() << "-----------------------------------------------------------\n\n"; } void SemiImplicitEM::OneStep ( amrex::Real a_time, @@ -64,24 +58,24 @@ void SemiImplicitEM::OneStep ( amrex::Real a_time, { amrex::ignore_unused(a_step); - // Fields have E^{n}, B^{n-1/2} - // Particles have p^{n} and x^{n}. + // Fields have Eg^{n}, Bg^{n-1/2} + // Particles have up^{n} and xp^{n}. - // Save the values at the start of the time step, + // Save up and xp at the start of the time step m_WarpX->SaveParticlesAtImplicitStepStart ( ); - // Save the fields at the start of the step - m_Eold.Copy( m_WarpX->getMultiLevelField(FieldType::Efield_fp) ); - m_E.Copy(m_Eold); // initial guess for E + // Save Eg at the start of the time step + m_Eold.Copy( FieldType::Efield_fp ); - // Compute Bfield at time n+1/2 + // Advance WarpX owned Bfield_fp to t_{n+1/2} m_WarpX->EvolveB(a_dt, DtType::Full); m_WarpX->ApplyMagneticFieldBCs(); const amrex::Real half_time = a_time + 0.5_rt*a_dt; - // Solve nonlinear system for E at t_{n+1/2} + // Solve nonlinear system for Eg at t_{n+1/2} // Particles will be advanced to t_{n+1/2} + m_E.Copy(m_Eold); // initial guess for Eg^{n+1/2} m_nlsolver->Solve( m_E, m_Eold, half_time, a_dt ); // Update WarpX owned Efield_fp to t_{n+1/2} @@ -90,8 +84,8 @@ void SemiImplicitEM::OneStep ( amrex::Real a_time, // Advance particles from time n+1/2 to time n+1 m_WarpX->FinishImplicitParticleUpdate(); - // Advance E fields from time n+1/2 to time n+1 - // Eg^{n+1} = 2.0*E_g^{n+1/2} - E_g^n + // Advance Eg from time n+1/2 to time n+1 + // Eg^{n+1} = 2.0*Eg^{n+1/2} - Eg^n m_E.linComb( 2._rt, m_E, -1._rt, m_Eold ); m_WarpX->SetElectricFieldAndApplyBCs( m_E ); @@ -104,14 +98,14 @@ void SemiImplicitEM::ComputeRHS ( WarpXSolverVec& a_RHS, int a_nl_iter, bool a_from_jacobian ) { - // update WarpX-owned Efield_fp using current state of E from + // Update WarpX-owned Efield_fp using current state of Eg from // the nonlinear solver at time n+theta m_WarpX->SetElectricFieldAndApplyBCs( a_E ); - // Self consistently update particle positions and velocities using the - // current state of the fields E and B. Deposit current density at time n+1/2. + // Update particle positions and velocities using the current state + // of Eg and Bg. Deposit current density at time n+1/2 m_WarpX->ImplicitPreRHSOp( a_time, a_dt, a_nl_iter, a_from_jacobian ); - // RHS = cvac^2*0.5*dt*( curl(B^{n+1/2}) - mu0*J^{n+1/2} ) + // RHS = cvac^2*0.5*dt*( curl(Bg^{n+1/2}) - mu0*Jg^{n+1/2} ) m_WarpX->ImplicitComputeRHSE(0.5_rt*a_dt, a_RHS); } diff --git a/Source/FieldSolver/ImplicitSolvers/ThetaImplicitEM.cpp b/Source/FieldSolver/ImplicitSolvers/ThetaImplicitEM.cpp index 026c509c3ba..3d74ddfde69 100644 --- a/Source/FieldSolver/ImplicitSolvers/ThetaImplicitEM.cpp +++ b/Source/FieldSolver/ImplicitSolvers/ThetaImplicitEM.cpp @@ -21,13 +21,8 @@ void ThetaImplicitEM::Define ( WarpX* const a_WarpX ) m_WarpX = a_WarpX; // Define E and Eold vectors - m_E.Define( m_WarpX->getMultiLevelField(FieldType::Efield_fp) ); - m_Eold.Define( m_WarpX->getMultiLevelField(FieldType::Efield_fp) ); - - // Need to define the WarpXSolverVec owned dot_mask to do dot - // product correctly for linear and nonlinear solvers - const amrex::Vector& Geom = m_WarpX->Geom(); - m_E.SetDotMask(Geom); + m_E.Define( m_WarpX, FieldType::Efield_fp ); + m_Eold.Define( m_E ); // Define Bold MultiFab const int num_levels = 1; @@ -61,22 +56,21 @@ void ThetaImplicitEM::Define ( WarpX* const a_WarpX ) void ThetaImplicitEM::PrintParameters () const { if (!m_WarpX->Verbose()) { return; } - amrex::Print() << std::endl; - amrex::Print() << "-----------------------------------------------------------" << std::endl; - amrex::Print() << "----------- THETA IMPLICIT EM SOLVER PARAMETERS -----------" << std::endl; - amrex::Print() << "-----------------------------------------------------------" << std::endl; - amrex::Print() << "Time-bias parameter theta: " << m_theta << std::endl; - amrex::Print() << "max particle iterations: " << m_max_particle_iterations << std::endl; - amrex::Print() << "particle tolerance: " << m_particle_tolerance << std::endl; + amrex::Print() << "\n"; + amrex::Print() << "-----------------------------------------------------------\n"; + amrex::Print() << "----------- THETA IMPLICIT EM SOLVER PARAMETERS -----------\n"; + amrex::Print() << "-----------------------------------------------------------\n"; + amrex::Print() << "Time-bias parameter theta: " << m_theta << "\n"; + amrex::Print() << "max particle iterations: " << m_max_particle_iterations << "\n"; + amrex::Print() << "particle tolerance: " << m_particle_tolerance << "\n"; if (m_nlsolver_type==NonlinearSolverType::Picard) { - amrex::Print() << "Nonlinear solver type: Picard" << std::endl; + amrex::Print() << "Nonlinear solver type: Picard\n"; } else if (m_nlsolver_type==NonlinearSolverType::Newton) { - amrex::Print() << "Nonlinear solver type: Newton" << std::endl; + amrex::Print() << "Nonlinear solver type: Newton\n"; } m_nlsolver->PrintParams(); - amrex::Print() << "-----------------------------------------------------------" << std::endl; - amrex::Print() << std::endl; + amrex::Print() << "-----------------------------------------------------------\n\n"; } void ThetaImplicitEM::OneStep ( const amrex::Real a_time, @@ -85,15 +79,14 @@ void ThetaImplicitEM::OneStep ( const amrex::Real a_time, { amrex::ignore_unused(a_step); - // Fields have E^{n} and B^{n} - // Particles have p^{n} and x^{n}. + // Fields have Eg^{n} and Bg^{n} + // Particles have up^{n} and xp^{n}. - // Save the values at the start of the time step, + // Save up and xp at the start of the time step m_WarpX->SaveParticlesAtImplicitStepStart ( ); - // Save the fields at the start of the step - m_Eold.Copy( m_WarpX->getMultiLevelField(FieldType::Efield_fp) ); - m_E.Copy(m_Eold); // initial guess for E + // Save Eg at the start of the time step + m_Eold.Copy( FieldType::Efield_fp ); const int num_levels = static_cast(m_Bold.size()); for (int lev = 0; lev < num_levels; ++lev) { @@ -106,8 +99,9 @@ void ThetaImplicitEM::OneStep ( const amrex::Real a_time, const amrex::Real theta_time = a_time + m_theta*a_dt; - // Solve nonlinear system for E at t_{n+theta} + // Solve nonlinear system for Eg at t_{n+theta} // Particles will be advanced to t_{n+1/2} + m_E.Copy(m_Eold); // initial guess for Eg^{n+theta} m_nlsolver->Solve( m_E, m_Eold, theta_time, a_dt ); // Update WarpX owned Efield_fp and Bfield_fp to t_{n+theta} @@ -116,7 +110,7 @@ void ThetaImplicitEM::OneStep ( const amrex::Real a_time, // Advance particles from time n+1/2 to time n+1 m_WarpX->FinishImplicitParticleUpdate(); - // Advance E and B fields from time n+theta to time n+1 + // Advance Eg and Bg from time n+theta to time n+1 const amrex::Real new_time = a_time + a_dt; FinishFieldUpdate( new_time ); @@ -129,15 +123,15 @@ void ThetaImplicitEM::ComputeRHS ( WarpXSolverVec& a_RHS, int a_nl_iter, bool a_from_jacobian ) { - // update WarpX-owned Efield_fp and Bfield_fp using current state of E from - // the nonlinear solver at time n+theta + // Update WarpX-owned Efield_fp and Bfield_fp using current state of + // Eg from the nonlinear solver at time n+theta UpdateWarpXFields( a_E, a_time, a_dt ); - // Self consistently update particle positions and velocities using the - // current state of the fields E and B. Deposit current density at time n+1/2. + // Update particle positions and velocities using the current state + // of Eg and Bg. Deposit current density at time n+1/2 m_WarpX->ImplicitPreRHSOp( a_time, a_dt, a_nl_iter, a_from_jacobian ); - // RHS = cvac^2*m_theta*dt*( curl(B^{n+theta}) - mu0*J^{n+1/2} ) + // RHS = cvac^2*m_theta*dt*( curl(Bg^{n+theta}) - mu0*Jg^{n+1/2} ) m_WarpX->ImplicitComputeRHSE(m_theta*a_dt, a_RHS); } @@ -159,8 +153,8 @@ void ThetaImplicitEM::FinishFieldUpdate ( amrex::Real a_new_time ) { amrex::ignore_unused(a_new_time); - // Eg^{n+1} = (1/theta)*E_g^{n+theta} + (1-1/theta)*E_g^n - // Bg^{n+1} = (1/theta)*B_g^{n+theta} + (1-1/theta)*B_g^n + // Eg^{n+1} = (1/theta)*Eg^{n+theta} + (1-1/theta)*Eg^n + // Bg^{n+1} = (1/theta)*Bg^{n+theta} + (1-1/theta)*Bg^n const amrex::Real c0 = 1._rt/m_theta; const amrex::Real c1 = 1._rt - c0; diff --git a/Source/FieldSolver/ImplicitSolvers/WarpXImplicitOps.cpp b/Source/FieldSolver/ImplicitSolvers/WarpXImplicitOps.cpp index 7b95abade3e..8dd97ed5525 100644 --- a/Source/FieldSolver/ImplicitSolvers/WarpXImplicitOps.cpp +++ b/Source/FieldSolver/ImplicitSolvers/WarpXImplicitOps.cpp @@ -11,14 +11,8 @@ #include "Diagnostics/ReducedDiags/MultiReducedDiags.H" #include "Evolve/WarpXDtType.H" #include "Evolve/WarpXPushType.H" +#include "FieldSolver/Fields.H" #include "FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H" -#ifdef WARPX_USE_PSATD -# ifdef WARPX_DIM_RZ -# include "FieldSolver/SpectralSolver/SpectralSolverRZ.H" -# else -# include "FieldSolver/SpectralSolver/SpectralSolver.H" -# endif -#endif #include "Parallelization/GuardCellManager.H" #include "Particles/MultiParticleContainer.H" #include "Particles/ParticleBoundaryBuffer.H" @@ -75,7 +69,11 @@ WarpX::ImplicitPreRHSOp ( amrex::Real a_cur_time, void WarpX::SetElectricFieldAndApplyBCs ( const WarpXSolverVec& a_E ) { - const amrex::Vector, 3 > >& Evec = a_E.getVec(); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + a_E.getArrayVecType()==warpx::fields::FieldType::Efield_fp, + "WarpX::SetElectricFieldAndApplyBCs() must be called with Efield_fp type"); + + const amrex::Vector, 3 > >& Evec = a_E.getArrayVec(); amrex::MultiFab::Copy(*Efield_fp[0][0], *Evec[0][0], 0, 0, ncomps, Evec[0][0]->nGrowVect()); amrex::MultiFab::Copy(*Efield_fp[0][1], *Evec[0][1], 0, 0, ncomps, Evec[0][1]->nGrowVect()); amrex::MultiFab::Copy(*Efield_fp[0][2], *Evec[0][2], 0, 0, ncomps, Evec[0][2]->nGrowVect()); @@ -323,22 +321,26 @@ WarpX::ImplicitComputeRHSE (int lev, amrex::Real a_dt, WarpXSolverVec& a_Erhs_v void WarpX::ImplicitComputeRHSE (int lev, PatchType patch_type, amrex::Real a_dt, WarpXSolverVec& a_Erhs_vec) { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + a_Erhs_vec.getArrayVecType()==warpx::fields::FieldType::Efield_fp, + "WarpX::ImplicitComputeRHSE() must be called with Efield_fp type"); + // set RHS to zero value - a_Erhs_vec.getVec()[lev][0]->setVal(0.0); - a_Erhs_vec.getVec()[lev][1]->setVal(0.0); - a_Erhs_vec.getVec()[lev][2]->setVal(0.0); + a_Erhs_vec.getArrayVec()[lev][0]->setVal(0.0); + a_Erhs_vec.getArrayVec()[lev][1]->setVal(0.0); + a_Erhs_vec.getArrayVec()[lev][2]->setVal(0.0); // Compute Efield_rhs in regular cells by calling EvolveE. Because // a_Erhs_vec is set to zero above, calling EvolveE below results in // a_Erhs_vec storing only the RHS of the update equation. I.e., // c^2*dt*(curl(B^{n+theta} - mu0*J^{n+1/2}) if (patch_type == PatchType::fine) { - m_fdtd_solver_fp[lev]->EvolveE( a_Erhs_vec.getVec()[lev], Bfield_fp[lev], + m_fdtd_solver_fp[lev]->EvolveE( a_Erhs_vec.getArrayVec()[lev], Bfield_fp[lev], current_fp[lev], m_edge_lengths[lev], m_face_areas[lev], ECTRhofield[lev], F_fp[lev], lev, a_dt ); } else { - m_fdtd_solver_cp[lev]->EvolveE( a_Erhs_vec.getVec()[lev], Bfield_cp[lev], + m_fdtd_solver_cp[lev]->EvolveE( a_Erhs_vec.getArrayVec()[lev], Bfield_cp[lev], current_cp[lev], m_edge_lengths[lev], m_face_areas[lev], ECTRhofield[lev], F_cp[lev], lev, a_dt ); diff --git a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H index 89a0b82b700..f884f5fa623 100644 --- a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H +++ b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H @@ -8,6 +8,7 @@ #define WarpXSolverVec_H_ #include "Utils/TextMsg.H" +#include "FieldSolver/Fields.H" #include #include @@ -15,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -32,18 +32,25 @@ #include #include + +// forward declaration +class WarpX; + /** - * \brief This is a wrapper class around a Vector of array of pointers to MultiFabs that + * \brief + * This is a wrapper class around a Vector of pointers to MultiFabs that * contains basic math operators and functionality needed to interact with nonlinear - * solvers in WarpX and linear solvers in AMReX, such as GMRES. + * solvers in WarpX and linear solvers in AMReX, such as GMRES. The size of the + * Vector is the number of amr levels. Hardcoded for 1 right now. * - * The size of the Vector is the number of amr levels. Hardcoded for 1 right now. The - * size of the array is the number of MultiFabs. It is hardcoded for 3 right now as it - * is only used for the electric field in the implicit electromagnetic time solvers. In - * the future, the array size can be made a template parameter so that this class can - * be used for other solver vectors, such as electrostatic (array size 1) or Darwin (array size 4). + * A WarpXSolverVec can consist of an array size 3 of MultiFabs (for vector fields + * such as E, B, and A) or of a single MultiFab for scalar fields. Both the array + * size 3 and scalar fields must be of type warpx::fields::FieldType. + * Additionally, a WarpXSolverVec can in general contain both an array size 3 field and a + * scalar field. For example, the array size 3 field can be used for the vector potential A + * and the scalar field can be used for the scalar potential phi, which is the full state of + * unknowns for a Darwin electromagnetic model. */ - class WarpXSolverVec { public: @@ -59,88 +66,94 @@ public: [[nodiscard]] inline bool IsDefined () const { return m_is_defined; } - inline - void Define (const WarpXSolverVec& a_vec) - { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - a_vec.IsDefined(), - "WarpXSolverVec::Define(a_vec) called with undefined a_vec"); - Define( a_vec.getVec() ); - } + void Define ( WarpX* a_WarpX, + warpx::fields::FieldType a_array_type, + warpx::fields::FieldType a_scalar_type = warpx::fields::FieldType::None ); inline - void Define ( const amrex::Vector, 3 > >& a_solver_vec ) + void Define ( const WarpXSolverVec& a_solver_vec ) { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - !IsDefined(), - "WarpXSolverVec::Define() called on undefined WarpXSolverVec"); - m_field_vec.resize(m_num_amr_levels); - const int lev = 0; - for (int n=0; n<3; n++) { - const amrex::MultiFab& mf_model = *a_solver_vec[lev][n]; - m_field_vec[lev][n] = std::make_unique( mf_model.boxArray(), mf_model.DistributionMap(), - mf_model.nComp(), amrex::IntVect::TheZeroVector() ); - } - m_is_defined = true; + assertIsDefined( a_solver_vec ); + Define( WarpXSolverVec::m_WarpX, + a_solver_vec.getArrayVecType(), + a_solver_vec.getScalarVecType() ); } - void SetDotMask( const amrex::Vector& a_Geom ); [[nodiscard]] RT dotProduct( const WarpXSolverVec& a_X ) const; + void Copy ( warpx::fields::FieldType a_array_type, + warpx::fields::FieldType a_scalar_type = warpx::fields::FieldType::None ); + inline - void Copy ( const amrex::Vector, 3 > >& a_solver_vec ) + void Copy ( const WarpXSolverVec& a_solver_vec ) { - AMREX_ASSERT_WITH_MESSAGE( - IsDefined(), - "WarpXSolverVec::Copy() called on undefined WarpXSolverVec"); + assertIsDefined( a_solver_vec ); + if (IsDefined()) { assertSameType( a_solver_vec ); } + else { Define(a_solver_vec); } + for (int lev = 0; lev < m_num_amr_levels; ++lev) { - for (int n = 0; n < 3; ++n) { - amrex::MultiFab::Copy(*m_field_vec[lev][n], *a_solver_vec[lev][n], 0, 0, m_ncomp, amrex::IntVect::TheZeroVector() ); + if (m_array_type != warpx::fields::FieldType::None) { + for (int n = 0; n < 3; ++n) { + const std::unique_ptr& this_field = a_solver_vec.getArrayVec()[lev][n]; + amrex::MultiFab::Copy( *m_array_vec[lev][n], *this_field, 0, 0, m_ncomp, + amrex::IntVect::TheZeroVector() ); + } + } + if (m_scalar_type != warpx::fields::FieldType::None) { + const std::unique_ptr& this_scalar = a_solver_vec.getScalarVec()[lev]; + amrex::MultiFab::Copy( *m_scalar_vec[lev], *this_scalar, 0, 0, m_ncomp, + amrex::IntVect::TheZeroVector() ); } } } - inline - void Copy ( const WarpXSolverVec& a_vec ) - { - AMREX_ASSERT_WITH_MESSAGE( - a_vec.IsDefined(), - "WarpXSolverVec::Copy(a_vec) called with undefined a_vec"); - if (!IsDefined()) { Define(a_vec); } - const amrex::Vector, 3 > >& field_vec = a_vec.getVec(); - Copy(field_vec); - } - // Prohibit Copy assignment operator - WarpXSolverVec& operator= ( const WarpXSolverVec& a_vec ) = delete; + WarpXSolverVec& operator= ( const WarpXSolverVec& a_solver_vec ) = delete; // Move assignment operator WarpXSolverVec(WarpXSolverVec&&) noexcept = default; - WarpXSolverVec& operator= ( WarpXSolverVec&& a_vec ) noexcept + WarpXSolverVec& operator= ( WarpXSolverVec&& a_solver_vec ) noexcept { - if (this != &a_vec) { - m_field_vec = std::move(a_vec.m_field_vec); + if (this != &a_solver_vec) { + m_array_vec = std::move(a_solver_vec.m_array_vec); + m_scalar_vec = std::move(a_solver_vec.m_scalar_vec); + m_array_type = a_solver_vec.m_array_type; + m_scalar_type = a_solver_vec.m_scalar_type; m_is_defined = true; } return *this; } inline - void operator+= ( const WarpXSolverVec& a_vec ) + void operator+= ( const WarpXSolverVec& a_solver_vec ) { + assertIsDefined( a_solver_vec ); + assertSameType( a_solver_vec ); for (int lev = 0; lev < m_num_amr_levels; ++lev) { - for (int n=0; n<3; n++) { - m_field_vec[lev][n]->plus(*(a_vec.getVec()[lev][n]), 0, 1, 0); + if (m_array_type != warpx::fields::FieldType::None) { + m_array_vec[lev][0]->plus(*(a_solver_vec.getArrayVec()[lev][0]), 0, 1, 0); + m_array_vec[lev][1]->plus(*(a_solver_vec.getArrayVec()[lev][1]), 0, 1, 0); + m_array_vec[lev][2]->plus(*(a_solver_vec.getArrayVec()[lev][2]), 0, 1, 0); + } + if (m_scalar_type != warpx::fields::FieldType::None) { + m_scalar_vec[lev]->plus(*(a_solver_vec.getScalarVec()[lev]), 0, 1, 0); } } } inline - void operator-= (const WarpXSolverVec& a_vec) + void operator-= (const WarpXSolverVec& a_solver_vec) { + assertIsDefined( a_solver_vec ); + assertSameType( a_solver_vec ); for (int lev = 0; lev < m_num_amr_levels; ++lev) { - for (int n=0; n<3; n++) { - m_field_vec[lev][n]->minus(*(a_vec.getVec()[lev][n]), 0, 1, 0); + if (m_array_type != warpx::fields::FieldType::None) { + m_array_vec[lev][0]->minus(*(a_solver_vec.getArrayVec()[lev][0]), 0, 1, 0); + m_array_vec[lev][1]->minus(*(a_solver_vec.getArrayVec()[lev][1]), 0, 1, 0); + m_array_vec[lev][2]->minus(*(a_solver_vec.getArrayVec()[lev][2]), 0, 1, 0); + } + if (m_scalar_type != warpx::fields::FieldType::None) { + m_scalar_vec[lev]->minus(*(a_solver_vec.getScalarVec()[lev]), 0, 1, 0); } } } @@ -151,11 +164,22 @@ public: inline void linComb (const RT a, const WarpXSolverVec& X, const RT b, const WarpXSolverVec& Y) { + assertIsDefined( X ); + assertIsDefined( Y ); + assertSameType( X ); + assertSameType( Y ); for (int lev = 0; lev < m_num_amr_levels; ++lev) { - for (int n=0; n<3; n++) { - amrex::MultiFab::LinComb(*m_field_vec[lev][n], a, *X.getVec()[lev][n], 0, - b, *Y.getVec()[lev][n], 0, - 0, 1, 0); + if (m_array_type != warpx::fields::FieldType::None) { + for (int n = 0; n < 3; n++) { + amrex::MultiFab::LinComb(*m_array_vec[lev][n], a, *X.getArrayVec()[lev][n], 0, + b, *Y.getArrayVec()[lev][n], 0, + 0, 1, 0); + } + } + if (m_scalar_type != warpx::fields::FieldType::None) { + amrex::MultiFab::LinComb(*m_scalar_vec[lev], a, *X.getScalarVec()[lev], 0, + b, *Y.getScalarVec()[lev], 0, + 0, 1, 0); } } } @@ -165,9 +189,17 @@ public: */ void increment (const WarpXSolverVec& X, const RT a) { + assertIsDefined( X ); + assertSameType( X ); for (int lev = 0; lev < m_num_amr_levels; ++lev) { - for (int n=0; n<3; n++) { - amrex::MultiFab::Saxpy( *m_field_vec[lev][n], a, *X.getVec()[lev][n], + if (m_array_type != warpx::fields::FieldType::None) { + for (int n = 0; n < 3; n++) { + amrex::MultiFab::Saxpy( *m_array_vec[lev][n], a, *X.getArrayVec()[lev][n], + 0, 0, 1, amrex::IntVect::TheZeroVector() ); + } + } + if (m_scalar_type != warpx::fields::FieldType::None) { + amrex::MultiFab::Saxpy( *m_scalar_vec[lev], a, *X.getScalarVec()[lev], 0, 0, 1, amrex::IntVect::TheZeroVector() ); } } @@ -179,9 +211,17 @@ public: inline void scale (RT a_a) { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + IsDefined(), + "WarpXSolverVec::scale() called on undefined WarpXSolverVec"); for (int lev = 0; lev < m_num_amr_levels; ++lev) { - for (int n=0; n<3; n++) { - m_field_vec[lev][n]->mult(a_a, 0, 1); + if (m_array_type != warpx::fields::FieldType::None) { + m_array_vec[lev][0]->mult(a_a, 0, 1); + m_array_vec[lev][1]->mult(a_a, 0, 1); + m_array_vec[lev][2]->mult(a_a, 0, 1); + } + if (m_scalar_type != warpx::fields::FieldType::None) { + m_scalar_vec[lev]->mult(a_a, 0, 1); } } } @@ -192,41 +232,69 @@ public: inline void setVal ( const RT a_val ) { - AMREX_ASSERT_WITH_MESSAGE( + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( IsDefined(), - "WarpXSolverVec::ones() called on undefined WarpXSolverVec"); + "WarpXSolverVec::setVal() called on undefined WarpXSolverVec"); for (int lev = 0; lev < m_num_amr_levels; ++lev) { - for (int n=0; n<3; n++) { - m_field_vec[lev][n]->setVal(a_val); + if (m_array_type != warpx::fields::FieldType::None) { + m_array_vec[lev][0]->setVal(a_val); + m_array_vec[lev][1]->setVal(a_val); + m_array_vec[lev][2]->setVal(a_val); + } + if (m_scalar_type != warpx::fields::FieldType::None) { + m_scalar_vec[lev]->setVal(a_val); } } } + inline + void assertIsDefined( const WarpXSolverVec& a_solver_vec ) const + { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + a_solver_vec.IsDefined(), + "WarpXSolverVec::function(X) called with undefined WarpXSolverVec X"); + } + + inline + void assertSameType( const WarpXSolverVec& a_solver_vec ) const + { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + a_solver_vec.getArrayVecType()==m_array_type && + a_solver_vec.getScalarVecType()==m_scalar_type, + "WarpXSolverVec::function(X) called with WarpXSolverVec X of different type"); + } + [[nodiscard]] inline RT norm2 () const { auto const norm = dotProduct(*this); return std::sqrt(norm); } - [[nodiscard]] const amrex::Vector, 3 > >& getVec() const {return m_field_vec;} - amrex::Vector, 3 > >& getVec() {return m_field_vec;} + [[nodiscard]] const amrex::Vector,3>>& getArrayVec() const {return m_array_vec;} + amrex::Vector,3>>& getArrayVec() {return m_array_vec;} + + [[nodiscard]] const amrex::Vector>& getScalarVec() const {return m_scalar_vec;} + amrex::Vector>& getScalarVec() {return m_scalar_vec;} - // clearDotMask() must be called by the highest class that owns WarpXSolverVec() - // after it is done being used ( typically in the destructor ) to avoid the - // following error message after the simulation finishes: - // malloc_consolidate(): unaligned fastbin chunk detected - static void clearDotMask() { m_dotMask.clear(); } + // solver vector types are type warpx::fields::FieldType + [[nodiscard]] warpx::fields::FieldType getArrayVecType () const { return m_array_type; } + [[nodiscard]] warpx::fields::FieldType getScalarVecType () const { return m_scalar_type; } private: - bool m_is_defined = false; - amrex::Vector, 3 > > m_field_vec; + bool m_is_defined = false; + + amrex::Vector,3>> m_array_vec; + amrex::Vector> m_scalar_vec; + + warpx::fields::FieldType m_array_type = warpx::fields::FieldType::None; + warpx::fields::FieldType m_scalar_type = warpx::fields::FieldType::None; static constexpr int m_ncomp = 1; static constexpr int m_num_amr_levels = 1; - inline static bool m_dot_mask_defined = false; - inline static amrex::Vector,3>> m_dotMask; + inline static bool m_warpx_ptr_defined = false; + inline static WarpX* m_WarpX = nullptr; }; diff --git a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp index b181f038fb5..f2a88d82d42 100644 --- a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp +++ b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp @@ -5,46 +5,127 @@ * License: BSD-3-Clause-LBNL */ #include "FieldSolver/ImplicitSolvers/WarpXSolverVec.H" +#include "WarpX.H" -void WarpXSolverVec::SetDotMask( const amrex::Vector& a_Geom ) +using namespace warpx::fields; + +void WarpXSolverVec::Define ( WarpX* a_WarpX, + FieldType a_array_type, + FieldType a_scalar_type ) { - if (m_dot_mask_defined) { return; } + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + !IsDefined(), + "WarpXSolverVec::Define() called on already defined WarpXSolverVec"); + + // Define static member pointer to WarpX + if (!m_warpx_ptr_defined) { + m_WarpX = a_WarpX; + m_warpx_ptr_defined = true; + } + + m_array_type = a_array_type; + m_scalar_type = a_scalar_type; + + m_array_vec.resize(m_num_amr_levels); + m_scalar_vec.resize(m_num_amr_levels); + + // Define the 3D vector field data container + if (m_array_type != FieldType::None) { + + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + isFieldArray(m_array_type), + "WarpXSolverVec::Define() called with array_type not an array field"); + + for (int lev = 0; lev < m_num_amr_levels; ++lev) { + using arr_mf_type = std::array; + const arr_mf_type this_array = m_WarpX->getFieldPointerArray(m_array_type, lev); + for (int n = 0; n < 3; n++) { + m_array_vec[lev][n] = std::make_unique( this_array[n]->boxArray(), + this_array[n]->DistributionMap(), + this_array[n]->nComp(), + amrex::IntVect::TheZeroVector() ); + } + } + + } + + // Define the scalar data container + if (m_scalar_type != FieldType::None) { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - IsDefined(), - "WarpXSolverVec::SetDotMask() called from undefined instance "); - - m_dotMask.resize(m_num_amr_levels); - for ( int n = 0; n < 3; n++) { - const amrex::BoxArray& grids = m_field_vec[0][n]->boxArray(); - const amrex::MultiFab tmp( grids, m_field_vec[0][n]->DistributionMap(), - 1, 0, amrex::MFInfo().SetAlloc(false) ); - const amrex::Periodicity& period = a_Geom[0].periodicity(); - m_dotMask[0][n] = tmp.OwnerMask(period); + !isFieldArray(m_scalar_type), + "WarpXSolverVec::Define() called with scalar_type not a scalar field "); + + for (int lev = 0; lev < m_num_amr_levels; ++lev) { + const amrex::MultiFab* this_mf = m_WarpX->getFieldPointer(m_scalar_type,lev,0); + m_scalar_vec[lev] = std::make_unique( this_mf->boxArray(), + this_mf->DistributionMap(), + this_mf->nComp(), + amrex::IntVect::TheZeroVector() ); + } + } - m_dot_mask_defined = true; - // If the function below is not called, then the following - // error message occurs after the simulation finishes: - // malloc_consolidate(): unaligned fastbin chunk detected - amrex::ExecOnFinalize(WarpXSolverVec::clearDotMask); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + m_array_type != FieldType::None || + m_scalar_type != FieldType::None, + "WarpXSolverVec cannot be defined with both array and scalar vecs FieldType::None"); + + m_is_defined = true; } -[[nodiscard]] amrex::Real WarpXSolverVec::dotProduct ( const WarpXSolverVec& a_X ) const +void WarpXSolverVec::Copy ( FieldType a_array_type, + FieldType a_scalar_type ) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - m_dot_mask_defined, - "WarpXSolverVec::dotProduct called with m_dotMask not yet defined"); + IsDefined(), + "WarpXSolverVec::Copy() called on undefined WarpXSolverVec"); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - a_X.IsDefined(), - "WarpXSolverVec::dotProduct(a_X) called with undefined a_X"); + a_array_type==m_array_type && + a_scalar_type==m_scalar_type, + "WarpXSolverVec::Copy() called with vecs of different types"); + + for (int lev = 0; lev < m_num_amr_levels; ++lev) { + if (m_array_type != FieldType::None) { + using arr_mf_type = std::array; + const arr_mf_type this_array = m_WarpX->getFieldPointerArray(m_array_type, lev); + for (int n = 0; n < 3; ++n) { + amrex::MultiFab::Copy( *m_array_vec[lev][n], *this_array[n], 0, 0, m_ncomp, + amrex::IntVect::TheZeroVector() ); + } + } + if (m_scalar_type != FieldType::None) { + const amrex::MultiFab* this_scalar = m_WarpX->getFieldPointer(m_scalar_type,lev,0); + amrex::MultiFab::Copy( *m_scalar_vec[lev], *this_scalar, 0, 0, m_ncomp, + amrex::IntVect::TheZeroVector() ); + } + } +} + +[[nodiscard]] amrex::Real WarpXSolverVec::dotProduct ( const WarpXSolverVec& a_X ) const +{ + assertIsDefined( a_X ); + assertSameType( a_X ); + amrex::Real result = 0.0; - const int lev = 0; const bool local = true; - for (int n = 0; n < 3; ++n) { - auto rtmp = amrex::MultiFab::Dot( *m_dotMask[lev][n], - *m_field_vec[lev][n], 0, - *a_X.getVec()[lev][n], 0, 1, 0, local); - result += rtmp; + for (int lev = 0; lev < m_num_amr_levels; ++lev) { + if (m_array_type != FieldType::None) { + for (int n = 0; n < 3; ++n) { + const amrex::iMultiFab* dotMask = m_WarpX->getFieldDotMaskPointer(m_array_type,lev,n); + auto rtmp = amrex::MultiFab::Dot( *dotMask, + *m_array_vec[lev][n], 0, + *a_X.getArrayVec()[lev][n], 0, 1, 0, local); + result += rtmp; + } + } + if (m_scalar_type != FieldType::None) { + const amrex::iMultiFab* dotMask = m_WarpX->getFieldDotMaskPointer(m_scalar_type,lev,0); + auto rtmp = amrex::MultiFab::Dot( *dotMask, + *m_scalar_vec[lev], 0, + *a_X.getScalarVec()[lev], 0, 1, 0, local); + result += rtmp; + } } amrex::ParallelAllReduce::Sum(result, amrex::ParallelContext::CommunicatorSub()); return result; diff --git a/Source/FieldSolver/MagnetostaticSolver/MagnetostaticSolver.cpp b/Source/FieldSolver/MagnetostaticSolver/MagnetostaticSolver.cpp index 26ac1ac96c8..031bc915afc 100644 --- a/Source/FieldSolver/MagnetostaticSolver/MagnetostaticSolver.cpp +++ b/Source/FieldSolver/MagnetostaticSolver/MagnetostaticSolver.cpp @@ -7,6 +7,7 @@ #include "WarpX.H" #include "FieldSolver/MagnetostaticSolver/MagnetostaticSolver.H" +#include "EmbeddedBoundary/Enabled.H" #include "Parallelization/GuardCellManager.H" #include "Particles/MultiParticleContainer.H" #include "Particles/WarpXParticleContainer.H" @@ -115,7 +116,12 @@ WarpX::AddMagnetostaticFieldLabFrame() WARPX_ALWAYS_ASSERT_WITH_MESSAGE( !IsPythonCallbackInstalled("poissonsolver"), "Python Level Poisson Solve not supported for Magnetostatic implementation."); - const amrex::Real magnetostatic_absolute_tolerance = self_fields_absolute_tolerance*PhysConst::c; + // const amrex::Real magnetostatic_absolute_tolerance = self_fields_absolute_tolerance*PhysConst::c; + // temporary fix!!! + const amrex::Real magnetostatic_absolute_tolerance = 0.0; + const amrex::Real self_fields_required_precision = 1e-12; + const int self_fields_max_iters = 200; + const int self_fields_verbosity = 2; computeVectorPotential( current_fp, vector_potential_fp_nodal, self_fields_required_precision, magnetostatic_absolute_tolerance, self_fields_max_iters, @@ -184,6 +190,7 @@ WarpX::computeVectorPotential (const amrex::Vectordmap, this->grids, this->m_vector_poisson_boundary_handler, + EB::enabled(), WarpX::do_single_precision_comms, this->ref_ratio, post_A_calculation, @@ -320,7 +327,7 @@ void MagnetostaticSolver::VectorPoissonBoundaryHandler::defineVectorPotentialBCs else { WARPX_ABORT_WITH_MESSAGE( "Field boundary conditions have to be either periodic, PEC or neumann " - "when using the magnetostatic solver, but they are " + GetFieldBCTypeString(WarpX::field_boundary_lo[idim]) + "when using the magnetostatic solver, but they are " + amrex::getEnumNameString(WarpX::field_boundary_lo[idim]) ); } @@ -340,7 +347,7 @@ void MagnetostaticSolver::VectorPoissonBoundaryHandler::defineVectorPotentialBCs else { WARPX_ABORT_WITH_MESSAGE( "Field boundary conditions have to be either periodic, PEC or neumann " - "when using the magnetostatic solver, but they are " + GetFieldBCTypeString(WarpX::field_boundary_lo[idim]) + "when using the magnetostatic solver, but they are " + amrex::getEnumNameString(WarpX::field_boundary_lo[idim]) ); } } diff --git a/Source/FieldSolver/Make.package b/Source/FieldSolver/Make.package index a8af4c2de97..4c7c41f6f8e 100644 --- a/Source/FieldSolver/Make.package +++ b/Source/FieldSolver/Make.package @@ -2,9 +2,11 @@ CEXE_sources += WarpXPushFieldsEM.cpp CEXE_sources += WarpXPushFieldsHybridPIC.cpp CEXE_sources += ElectrostaticSolver.cpp CEXE_sources += WarpX_QED_Field_Pushers.cpp +CEXE_sources += WarpXSolveFieldsES.cpp ifeq ($(USE_FFT),TRUE) include $(WARPX_HOME)/Source/FieldSolver/SpectralSolver/Make.package endif +include $(WARPX_HOME)/Source/FieldSolver/ElectrostaticSolvers/Make.package include $(WARPX_HOME)/Source/FieldSolver/FiniteDifferenceSolver/Make.package include $(WARPX_HOME)/Source/FieldSolver/MagnetostaticSolver/Make.package include $(WARPX_HOME)/Source/FieldSolver/ImplicitSolvers/Make.package diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.H index 70468277749..b7ee256f414 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.H @@ -5,6 +5,8 @@ #include "FieldSolver/SpectralSolver/SpectralKSpace.H" #include "SpectralBaseAlgorithm.H" +#include + #include #include #include @@ -32,7 +34,7 @@ class PsatdAlgorithmComoving : public SpectralBaseAlgorithm int norder_x, int norder_y, int norder_z, - short grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_comoving, amrex::Real dt, bool update_with_rho); diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.cpp index 6da6641c052..f809c3f2c20 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.cpp @@ -5,6 +5,8 @@ #include "Utils/WarpXConst.H" #include "Utils/WarpX_Complex.H" +#include + #include #include #include @@ -26,8 +28,10 @@ using namespace amrex; PsatdAlgorithmComoving::PsatdAlgorithmComoving (const SpectralKSpace& spectral_kspace, const DistributionMapping& dm, const SpectralFieldIndex& spectral_index, - const int norder_x, const int norder_y, - const int norder_z, const short grid_type, + const int norder_x, + const int norder_y, + const int norder_z, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_comoving, const amrex::Real dt, const bool update_with_rho) @@ -35,12 +39,12 @@ PsatdAlgorithmComoving::PsatdAlgorithmComoving (const SpectralKSpace& spectral_k : SpectralBaseAlgorithm{spectral_kspace, dm, spectral_index, norder_x, norder_y, norder_z, grid_type}, // Initialize the infinite-order k vectors (the argument n_order = -1 selects // the infinite order option, the argument grid_type=GridType::Staggered is then irrelevant) - kx_vec{spectral_kspace.getModifiedKComponent(dm, 0, -1, GridType::Staggered)}, + kx_vec{spectral_kspace.getModifiedKComponent(dm, 0, -1, ablastr::utils::enums::GridType::Staggered)}, #if defined(WARPX_DIM_3D) ky_vec{spectral_kspace.getModifiedKComponent(dm, 1, -1, GridType::Staggered)}, kz_vec{spectral_kspace.getModifiedKComponent(dm, 2, -1, GridType::Staggered)}, #else - kz_vec{spectral_kspace.getModifiedKComponent(dm, 1, -1, GridType::Staggered)}, + kz_vec{spectral_kspace.getModifiedKComponent(dm, 1, -1, ablastr::utils::enums::GridType::Staggered)}, #endif m_v_comoving{v_comoving}, m_dt{dt} diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.H index 23d4c2f82e3..94a16c13ec1 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.H @@ -11,6 +11,8 @@ #include "FieldSolver/SpectralSolver/SpectralKSpace.H" #include "SpectralBaseAlgorithm.H" +#include + #include #include #include @@ -50,11 +52,11 @@ class PsatdAlgorithmFirstOrder : public SpectralBaseAlgorithm int norder_x, int norder_y, int norder_z, - short grid_type, + ablastr::utils::enums::GridType grid_type, amrex::Real dt, bool div_cleaning, - int J_in_time, - int rho_in_time); + JInTime J_in_time, + RhoInTime rho_in_time); /** * \brief Updates E, B, F, and G fields in spectral space, @@ -91,8 +93,8 @@ class PsatdAlgorithmFirstOrder : public SpectralBaseAlgorithm // Other member variables amrex::Real m_dt; bool m_div_cleaning; - int m_J_in_time; - int m_rho_in_time; + JInTime m_J_in_time; + RhoInTime m_rho_in_time; }; #endif // WARPX_USE_FFT #endif // WARPX_PSATD_ALGORITHM_FIRST_ORDER_H_ diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.cpp index 041b70b8edf..c5f60e18d24 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.cpp @@ -28,18 +28,19 @@ using namespace amrex::literals; -PsatdAlgorithmFirstOrder::PsatdAlgorithmFirstOrder( +PsatdAlgorithmFirstOrder::PsatdAlgorithmFirstOrder ( const SpectralKSpace& spectral_kspace, const amrex::DistributionMapping& dm, const SpectralFieldIndex& spectral_index, const int norder_x, const int norder_y, const int norder_z, - const short grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Real dt, const bool div_cleaning, - const int J_in_time, - const int rho_in_time) + const JInTime J_in_time, + const RhoInTime rho_in_time +) // Initializer list : SpectralBaseAlgorithm(spectral_kspace, dm, spectral_index, norder_x, norder_y, norder_z, grid_type), m_dt(dt), diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmGalileanRZ.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmGalileanRZ.H index ad0aca1ecf5..0861eba3abf 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmGalileanRZ.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmGalileanRZ.H @@ -9,6 +9,9 @@ #include "SpectralBaseAlgorithmRZ.H" +#include + + /* \brief Class that updates the field in spectral space * and stores the coefficients of the corresponding update equation. */ @@ -20,7 +23,7 @@ class PsatdAlgorithmGalileanRZ : public SpectralBaseAlgorithmRZ amrex::DistributionMapping const & dm, const SpectralFieldIndex& spectral_index, int n_rz_azimuthal_modes, int norder_z, - short grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, amrex::Real dt_step, bool update_with_rho); diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmGalileanRZ.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmGalileanRZ.cpp index c24648fbf07..63127969149 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmGalileanRZ.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmGalileanRZ.cpp @@ -20,7 +20,7 @@ PsatdAlgorithmGalileanRZ::PsatdAlgorithmGalileanRZ (SpectralKSpaceRZ const & spe amrex::DistributionMapping const & dm, const SpectralFieldIndex& spectral_index, int const n_rz_azimuthal_modes, int const norder_z, - short const grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, amrex::Real const dt, bool const update_with_rho): diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.H index 5d83b5519a6..12e3203db39 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.H @@ -11,6 +11,8 @@ #include "FieldSolver/SpectralSolver/SpectralKSpace.H" #include "SpectralBaseAlgorithm.H" +#include + #include #include #include @@ -52,7 +54,7 @@ class PsatdAlgorithmJConstantInTime : public SpectralBaseAlgorithm int norder_x, int norder_y, int norder_z, - short grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, amrex::Real dt, bool update_with_rho, diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp index 59d56b99afc..991bf981924 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp @@ -36,7 +36,7 @@ PsatdAlgorithmJConstantInTime::PsatdAlgorithmJConstantInTime( const int norder_x, const int norder_y, const int norder_z, - const short grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, const amrex::Real dt, const bool update_with_rho, diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJLinearInTime.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJLinearInTime.H index 970657978bb..c26fc4a81a4 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJLinearInTime.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJLinearInTime.H @@ -11,6 +11,8 @@ #include "FieldSolver/SpectralSolver/SpectralKSpace.H" #include "SpectralBaseAlgorithm.H" +#include + #include #include #include @@ -53,11 +55,12 @@ class PsatdAlgorithmJLinearInTime : public SpectralBaseAlgorithm int norder_x, int norder_y, int norder_z, - short grid_type, + ablastr::utils::enums::GridType grid_type, amrex::Real dt, bool time_averaging, bool dive_cleaning, - bool divb_cleaning); + bool divb_cleaning + ); /** * \brief Updates the E and B fields in spectral space, according to the multi-J PSATD equations diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJLinearInTime.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJLinearInTime.cpp index a6ee55147c9..2626dd0376e 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJLinearInTime.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJLinearInTime.cpp @@ -35,7 +35,7 @@ PsatdAlgorithmJLinearInTime::PsatdAlgorithmJLinearInTime( const int norder_x, const int norder_y, const int norder_z, - const short grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Real dt, const bool time_averaging, const bool dive_cleaning, diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPml.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPml.H index 1c19827a0a7..f01b8cad379 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPml.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPml.H @@ -12,8 +12,9 @@ #include "FieldSolver/SpectralSolver/SpectralFieldData_fwd.H" #include "FieldSolver/SpectralSolver/SpectralKSpace_fwd.H" -#include +#include +#include #include #include @@ -51,7 +52,7 @@ class PsatdAlgorithmPml : public SpectralBaseAlgorithm int norder_x, int norder_y, int norder_z, - short grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, amrex::Real dt, bool dive_cleaning, diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPml.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPml.cpp index ee776a71a20..5907485a526 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPml.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPml.cpp @@ -37,7 +37,7 @@ PsatdAlgorithmPml::PsatdAlgorithmPml( int norder_x, int norder_y, int norder_z, - short grid_type, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, Real dt, bool dive_cleaning, diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPmlRZ.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPmlRZ.H index 00264956900..9f2a21db595 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPmlRZ.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPmlRZ.H @@ -9,6 +9,9 @@ #include "SpectralBaseAlgorithmRZ.H" +#include + + /* \brief Class that updates the field in spectral space * and stores the coefficients of the corresponding update equation. */ @@ -19,8 +22,10 @@ class PsatdAlgorithmPmlRZ : public SpectralBaseAlgorithmRZ PsatdAlgorithmPmlRZ (SpectralKSpaceRZ const & spectral_kspace, amrex::DistributionMapping const & dm, const SpectralFieldIndex& spectral_index, - int n_rz_azimuthal_modes, int norder_z, - short grid_type, amrex::Real dt_step); + int n_rz_azimuthal_modes, + int norder_z, + ablastr::utils::enums::GridType grid_type, + amrex::Real dt_step); // Redefine functions from base class void pushSpectralFields (SpectralFieldDataRZ & f) final; diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPmlRZ.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPmlRZ.cpp index 66aa463503f..50522f3c9b2 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPmlRZ.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmPmlRZ.cpp @@ -19,8 +19,10 @@ using namespace amrex::literals; PsatdAlgorithmPmlRZ::PsatdAlgorithmPmlRZ (SpectralKSpaceRZ const & spectral_kspace, amrex::DistributionMapping const & dm, const SpectralFieldIndex& spectral_index, - int const n_rz_azimuthal_modes, int const norder_z, - short const grid_type, amrex::Real const dt): + int const n_rz_azimuthal_modes, + int const norder_z, + ablastr::utils::enums::GridType grid_type, + amrex::Real const dt): // Initialize members of base class and member variables SpectralBaseAlgorithmRZ{spectral_kspace, dm, spectral_index, norder_z, grid_type}, m_dt{dt} diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.H index 10feafec38b..2cbb4d7402d 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.H @@ -9,6 +9,9 @@ #include "SpectralBaseAlgorithmRZ.H" +#include + + /* \brief Class that updates the field in spectral space * and stores the coefficients of the corresponding update equation. */ @@ -20,11 +23,12 @@ class PsatdAlgorithmRZ : public SpectralBaseAlgorithmRZ amrex::DistributionMapping const & dm, const SpectralFieldIndex& spectral_index, int n_rz_azimuthal_modes, int norder_z, - short grid_type, amrex::Real dt_step, + ablastr::utils::enums::GridType grid_type, + amrex::Real dt_step, bool update_with_rho, bool time_averaging, - int J_in_time, - int rho_in_time, + JInTime J_in_time, + RhoInTime rho_in_time, bool dive_cleaning, bool divb_cleaning); // Redefine functions from base class @@ -61,7 +65,7 @@ class PsatdAlgorithmRZ : public SpectralBaseAlgorithmRZ amrex::Real m_dt; bool m_update_with_rho; bool m_time_averaging; - int m_J_in_time; + JInTime m_J_in_time; bool m_dive_cleaning; bool m_divb_cleaning; SpectralRealCoefficients C_coef, S_ck_coef, X1_coef, X2_coef, X3_coef; diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.cpp index f621d3c7af9..66d99e29715 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.cpp @@ -19,12 +19,14 @@ using namespace amrex::literals; PsatdAlgorithmRZ::PsatdAlgorithmRZ (SpectralKSpaceRZ const & spectral_kspace, amrex::DistributionMapping const & dm, const SpectralFieldIndex& spectral_index, - int const n_rz_azimuthal_modes, int const norder_z, - short const grid_type, amrex::Real const dt, + int const n_rz_azimuthal_modes, + int const norder_z, + ablastr::utils::enums::GridType grid_type, + amrex::Real const dt, bool const update_with_rho, const bool time_averaging, - const int J_in_time, - const int rho_in_time, + const JInTime J_in_time, + const RhoInTime rho_in_time, const bool dive_cleaning, const bool divb_cleaning): // Initialize members of base class and member variables diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H index e6787c9e52d..c72e7db250d 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H @@ -13,6 +13,8 @@ #include "FieldSolver/SpectralSolver/SpectralFieldData_fwd.H" #include "FieldSolver/SpectralSolver/SpectralFieldData.H" +#include + #include #include #include @@ -88,8 +90,10 @@ class SpectralBaseAlgorithm SpectralBaseAlgorithm(const SpectralKSpace& spectral_kspace, const amrex::DistributionMapping& dm, const SpectralFieldIndex& spectral_index, - int norder_x, int norder_y, - int norder_z, short grid_type); + int norder_x, + int norder_y, + int norder_z, + ablastr::utils::enums::GridType grid_type); SpectralFieldIndex m_spectral_index; diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.cpp index d635a5debe3..b3f18dd6912 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.cpp @@ -27,11 +27,15 @@ using namespace amrex; /** * \brief Constructor */ -SpectralBaseAlgorithm::SpectralBaseAlgorithm(const SpectralKSpace& spectral_kspace, +SpectralBaseAlgorithm::SpectralBaseAlgorithm ( + const SpectralKSpace& spectral_kspace, const amrex::DistributionMapping& dm, const SpectralFieldIndex& spectral_index, - const int norder_x, const int norder_y, - const int norder_z, const short grid_type): + const int norder_x, + const int norder_y, + const int norder_z, + ablastr::utils::enums::GridType grid_type +): m_spectral_index(spectral_index), // Compute and assign the modified k vectors modified_kx_vec(spectral_kspace.getModifiedKComponent(dm,0,norder_x,grid_type)), diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithmRZ.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithmRZ.H index 95c68f6d61b..8e03a2a2559 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithmRZ.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithmRZ.H @@ -10,6 +10,9 @@ #include "FieldSolver/SpectralSolver/SpectralKSpaceRZ.H" #include "FieldSolver/SpectralSolver/SpectralFieldDataRZ.H" +#include + + /* \brief Class that updates the field in spectral space * and stores the coefficients of the corresponding update equation. * @@ -84,7 +87,8 @@ class SpectralBaseAlgorithmRZ SpectralBaseAlgorithmRZ(SpectralKSpaceRZ const & spectral_kspace, amrex::DistributionMapping const & dm, const SpectralFieldIndex& spectral_index, - int const norder_z, short const grid_type) + int const norder_z, + ablastr::utils::enums::GridType grid_type) // Compute and assign the modified k vectors : m_spectral_index(spectral_index), modified_kz_vec(spectral_kspace.getModifiedKComponent(dm, 1, norder_z, grid_type)) diff --git a/Source/FieldSolver/SpectralSolver/SpectralFieldData.H b/Source/FieldSolver/SpectralSolver/SpectralFieldData.H index 8ced43ced94..42bf32c4724 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralFieldData.H +++ b/Source/FieldSolver/SpectralSolver/SpectralFieldData.H @@ -11,6 +11,7 @@ #include "SpectralFieldData_fwd.H" #include "SpectralKSpace.H" +#include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpX_Complex.H" #include @@ -59,8 +60,8 @@ class SpectralFieldIndex */ SpectralFieldIndex (bool update_with_rho, bool time_averaging, - int J_in_time, - int rho_in_time, + JInTime J_in_time, + RhoInTime rho_in_time, bool dive_cleaning, bool divb_cleaning, bool pml, @@ -176,11 +177,10 @@ class SpectralFieldData ablastr::math::anyfft::FFTplans forward_plan, backward_plan; // Correcting "shift" factors when performing FFT from/to // a cell-centered grid in real space, instead of a nodal grid - SpectralShiftFactor xshift_FFTfromCell, xshift_FFTtoCell, - zshift_FFTfromCell, zshift_FFTtoCell; -#if defined(WARPX_DIM_3D) - SpectralShiftFactor yshift_FFTfromCell, yshift_FFTtoCell; -#endif + // (0,1,2) is the dimension number + SpectralShiftFactor shift0_FFTfromCell, shift0_FFTtoCell, + shift1_FFTfromCell, shift1_FFTtoCell, + shift2_FFTfromCell, shift2_FFTtoCell; bool m_periodic_single_box; }; diff --git a/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp b/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp index 20c97f4b5d4..a20429eea68 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp @@ -35,8 +35,8 @@ using namespace amrex; SpectralFieldIndex::SpectralFieldIndex (const bool update_with_rho, const bool time_averaging, - const int J_in_time, - const int rho_in_time, + const JInTime J_in_time, + const RhoInTime rho_in_time, const bool dive_cleaning, const bool divb_cleaning, const bool pml, @@ -142,24 +142,21 @@ SpectralFieldData::SpectralFieldData( const int lev, // By default, we assume the FFT is done from/to a nodal grid in real space // If the FFT is performed from/to a cell-centered grid in real space, // a correcting "shift" factor must be applied in spectral space. - xshift_FFTfromCell = k_space.getSpectralShiftFactor(dm, 0, + shift0_FFTfromCell = k_space.getSpectralShiftFactor(dm, 0, ShiftType::TransformFromCellCentered); - xshift_FFTtoCell = k_space.getSpectralShiftFactor(dm, 0, + shift0_FFTtoCell = k_space.getSpectralShiftFactor(dm, 0, ShiftType::TransformToCellCentered); -#if defined(WARPX_DIM_3D) - yshift_FFTfromCell = k_space.getSpectralShiftFactor(dm, 1, +#if AMREX_SPACEDIM > 1 + shift1_FFTfromCell = k_space.getSpectralShiftFactor(dm, 1, ShiftType::TransformFromCellCentered); - yshift_FFTtoCell = k_space.getSpectralShiftFactor(dm, 1, + shift1_FFTtoCell = k_space.getSpectralShiftFactor(dm, 1, ShiftType::TransformToCellCentered); - zshift_FFTfromCell = k_space.getSpectralShiftFactor(dm, 2, +#if AMREX_SPACEDIM > 2 + shift2_FFTfromCell = k_space.getSpectralShiftFactor(dm, 2, ShiftType::TransformFromCellCentered); - zshift_FFTtoCell = k_space.getSpectralShiftFactor(dm, 2, - ShiftType::TransformToCellCentered); -#else - zshift_FFTfromCell = k_space.getSpectralShiftFactor(dm, 1, - ShiftType::TransformFromCellCentered); - zshift_FFTtoCell = k_space.getSpectralShiftFactor(dm, 1, + shift2_FFTtoCell = k_space.getSpectralShiftFactor(dm, 2, ShiftType::TransformToCellCentered); +#endif #endif // Allocate and initialize the FFT plans @@ -221,16 +218,12 @@ SpectralFieldData::ForwardTransform (const int lev, const bool do_costs = WarpXUtilLoadBalance::doCosts(cost, mf.boxArray(), mf.DistributionMap()); // Check field index type, in order to apply proper shift in spectral space -#if (AMREX_SPACEDIM >= 2) - const bool is_nodal_x = mf.is_nodal(0); + const bool is_nodal_0 = mf.is_nodal(0); +#if AMREX_SPACEDIM > 1 + const bool is_nodal_1 = mf.is_nodal(1); +#if AMREX_SPACEDIM > 2 + const bool is_nodal_2 = mf.is_nodal(2); #endif -#if defined(WARPX_DIM_3D) - const bool is_nodal_y = mf.is_nodal(1); - const bool is_nodal_z = mf.is_nodal(2); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const bool is_nodal_z = mf.is_nodal(1); -#elif defined(WARPX_DIM_1D_Z) - const bool is_nodal_z = mf.is_nodal(0); #endif // Loop over boxes @@ -275,13 +268,14 @@ SpectralFieldData::ForwardTransform (const int lev, { const Array4 fields_arr = SpectralFieldData::fields[mfi].array(); const Array4 tmp_arr = tmpSpectralField[mfi].array(); -#if (AMREX_SPACEDIM >= 2) - const Complex* xshift_arr = xshift_FFTfromCell[mfi].dataPtr(); + + const Complex* shift0_arr = shift0_FFTfromCell[mfi].dataPtr(); +#if AMREX_SPACEDIM > 1 + const Complex* shift1_arr = shift1_FFTfromCell[mfi].dataPtr(); +#if AMREX_SPACEDIM > 2 + const Complex* shift2_arr = shift2_FFTfromCell[mfi].dataPtr(); #endif -#if defined(WARPX_DIM_3D) - const Complex* yshift_arr = yshift_FFTfromCell[mfi].dataPtr(); #endif - const Complex* zshift_arr = zshift_FFTfromCell[mfi].dataPtr(); // Loop over indices within one box const Box spectralspace_bx = tmpSpectralField[mfi].box(); @@ -289,16 +283,12 @@ SpectralFieldData::ForwardTransform (const int lev, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { Complex spectral_field_value = tmp_arr(i,j,k); // Apply proper shift in each dimension -#if (AMREX_SPACEDIM >= 2) - if (!is_nodal_x) { spectral_field_value *= xshift_arr[i]; } + if (!is_nodal_0) { spectral_field_value *= shift0_arr[i]; } +#if AMREX_SPACEDIM > 1 + if (!is_nodal_1) { spectral_field_value *= shift1_arr[j]; } +#if AMREX_SPACEDIM > 2 + if (!is_nodal_2) { spectral_field_value *= shift2_arr[k]; } #endif -#if defined(WARPX_DIM_3D) - if (!is_nodal_y) { spectral_field_value *= yshift_arr[j]; } - if (!is_nodal_z) { spectral_field_value *= zshift_arr[k]; } -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - if (!is_nodal_z) { spectral_field_value *= zshift_arr[j]; } -#elif defined(WARPX_DIM_1D_Z) - if (!is_nodal_z) { spectral_field_value *= zshift_arr[i]; } #endif // Copy field into the right index fields_arr(i,j,k,field_index) = spectral_field_value; @@ -328,32 +318,9 @@ SpectralFieldData::BackwardTransform (const int lev, const bool do_costs = WarpXUtilLoadBalance::doCosts(cost, mf.boxArray(), mf.DistributionMap()); // Check field index type, in order to apply proper shift in spectral space -#if (AMREX_SPACEDIM >= 2) - const bool is_nodal_x = mf.is_nodal(0); -#endif -#if defined(WARPX_DIM_3D) - const bool is_nodal_y = mf.is_nodal(1); - const bool is_nodal_z = mf.is_nodal(2); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const bool is_nodal_z = mf.is_nodal(1); -#elif defined(WARPX_DIM_1D_Z) - const bool is_nodal_z = mf.is_nodal(0); -#endif - -#if (AMREX_SPACEDIM >= 2) - const int si = (is_nodal_x) ? 1 : 0; -#endif -#if defined(WARPX_DIM_1D_Z) - const int si = (is_nodal_z) ? 1 : 0; - const int sj = 0; - const int sk = 0; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const int sj = (is_nodal_z) ? 1 : 0; - const int sk = 0; -#elif defined(WARPX_DIM_3D) - const int sj = (is_nodal_y) ? 1 : 0; - const int sk = (is_nodal_z) ? 1 : 0; -#endif + const bool is_nodal_0 = mf.is_nodal(0); + const bool is_nodal_1 = (AMREX_SPACEDIM > 1 ? mf.is_nodal(1) : 0); + const bool is_nodal_2 = (AMREX_SPACEDIM > 2 ? mf.is_nodal(2) : 0); // Numbers of guard cells const amrex::IntVect& mf_ng = mf.nGrowVect(); @@ -375,13 +342,13 @@ SpectralFieldData::BackwardTransform (const int lev, { const Array4 field_arr = SpectralFieldData::fields[mfi].array(); const Array4 tmp_arr = tmpSpectralField[mfi].array(); -#if (AMREX_SPACEDIM >= 2) - const Complex* xshift_arr = xshift_FFTtoCell[mfi].dataPtr(); + const Complex* shift0_arr = shift0_FFTtoCell[mfi].dataPtr(); +#if AMREX_SPACEDIM > 1 + const Complex* shift1_arr = shift1_FFTtoCell[mfi].dataPtr(); +#if AMREX_SPACEDIM > 2 + const Complex* shift2_arr = shift2_FFTtoCell[mfi].dataPtr(); #endif -#if defined(WARPX_DIM_3D) - const Complex* yshift_arr = yshift_FFTtoCell[mfi].dataPtr(); #endif - const Complex* zshift_arr = zshift_FFTtoCell[mfi].dataPtr(); // Loop over indices within one box const Box spectralspace_bx = tmpSpectralField[mfi].box(); @@ -389,16 +356,12 @@ SpectralFieldData::BackwardTransform (const int lev, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { Complex spectral_field_value = field_arr(i,j,k,field_index); // Apply proper shift in each dimension -#if (AMREX_SPACEDIM >= 2) - if (!is_nodal_x) { spectral_field_value *= xshift_arr[i]; } + if (!is_nodal_0) { spectral_field_value *= shift0_arr[i]; } +#if AMREX_SPACEDIM > 1 + if (!is_nodal_1) { spectral_field_value *= shift1_arr[j]; } +#if AMREX_SPACEDIM > 2 + if (!is_nodal_2) { spectral_field_value *= shift2_arr[k]; } #endif -#if defined(WARPX_DIM_3D) - if (!is_nodal_y) { spectral_field_value *= yshift_arr[j]; } - if (!is_nodal_z) { spectral_field_value *= zshift_arr[k]; } -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - if (!is_nodal_z) { spectral_field_value *= zshift_arr[j]; } -#elif defined(WARPX_DIM_1D_Z) - if (!is_nodal_z) { spectral_field_value *= zshift_arr[i]; } #endif // Copy field into temporary array tmp_arr(i,j,k) = spectral_field_value; @@ -419,28 +382,18 @@ SpectralFieldData::BackwardTransform (const int lev, // Total number of cells, including ghost cells (nj represents ny in 3D and nz in 2D) const int ni = mf_box.length(0); -#if defined(WARPX_DIM_1D_Z) - constexpr int nj = 1; - constexpr int nk = 1; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const int nj = mf_box.length(1); - constexpr int nk = 1; -#elif defined(WARPX_DIM_3D) - const int nj = mf_box.length(1); - const int nk = mf_box.length(2); -#endif + const int nj = (AMREX_SPACEDIM > 1 ? mf_box.length(1) : 1); + const int nk = (AMREX_SPACEDIM > 2 ? mf_box.length(2) : 1); + + const int si = (is_nodal_0) ? 1 : 0; + const int sj = (is_nodal_1) ? 1 : 0; + const int sk = (is_nodal_2) ? 1 : 0; + // Lower bound of the box (lo_j represents lo_y in 3D and lo_z in 2D) const int lo_i = amrex::lbound(mf_box).x; -#if defined(WARPX_DIM_1D_Z) - constexpr int lo_j = 0; - constexpr int lo_k = 0; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const int lo_j = amrex::lbound(mf_box).y; - constexpr int lo_k = 0; -#elif defined(WARPX_DIM_3D) - const int lo_j = amrex::lbound(mf_box).y; - const int lo_k = amrex::lbound(mf_box).z; -#endif + const int lo_j = (AMREX_SPACEDIM > 1 ? amrex::lbound(mf_box).y : 0); + const int lo_k = (AMREX_SPACEDIM > 2 ? amrex::lbound(mf_box).z : 0); + // If necessary, do not fill the guard cells // (shrink box by passing negative number of cells) if (!m_periodic_single_box) diff --git a/Source/FieldSolver/SpectralSolver/SpectralKSpace.H b/Source/FieldSolver/SpectralSolver/SpectralKSpace.H index 2a4dd3d1580..16f93d8292a 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralKSpace.H +++ b/Source/FieldSolver/SpectralSolver/SpectralKSpace.H @@ -12,6 +12,8 @@ #include "Utils/WarpX_Complex.H" +#include + #include #include #include @@ -59,9 +61,11 @@ class SpectralKSpace const amrex::BoxArray& realspace_ba, int i_dim, bool only_positive_k ) const; - KVectorComponent getModifiedKComponent( - const amrex::DistributionMapping& dm, int i_dim, - int n_order, short grid_type ) const; + KVectorComponent getModifiedKComponent ( + const amrex::DistributionMapping& dm, + int i_dim, + int n_order, + ablastr::utils::enums::GridType grid_type) const; SpectralShiftFactor getSpectralShiftFactor( const amrex::DistributionMapping& dm, int i_dim, diff --git a/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp b/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp index 91fe2953668..94bd384f265 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp @@ -188,10 +188,10 @@ SpectralKSpace::getSpectralShiftFactor( const DistributionMapping& dm, * \param grid_type type of grid (collocated or not) */ KVectorComponent -SpectralKSpace::getModifiedKComponent( const DistributionMapping& dm, +SpectralKSpace::getModifiedKComponent (const DistributionMapping& dm, const int i_dim, const int n_order, - const short grid_type ) const + ablastr::utils::enums::GridType grid_type) const { // Initialize an empty DeviceVector in each box KVectorComponent modified_k_comp(spectralspace_ba, dm); diff --git a/Source/FieldSolver/SpectralSolver/SpectralSolver.H b/Source/FieldSolver/SpectralSolver/SpectralSolver.H index 3d751974a2b..1aa1e540711 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralSolver.H +++ b/Source/FieldSolver/SpectralSolver/SpectralSolver.H @@ -12,6 +12,10 @@ #include "SpectralAlgorithms/SpectralBaseAlgorithm.H" #include "SpectralFieldData.H" +#include "Utils/WarpXAlgorithmSelection.H" + +#include + #include #include #include @@ -72,8 +76,10 @@ class SpectralSolver SpectralSolver (int lev, const amrex::BoxArray& realspace_ba, const amrex::DistributionMapping& dm, - int norder_x, int norder_y, - int norder_z, short grid_type, + int norder_x, + int norder_y, + int norder_z, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, const amrex::Vector& v_comoving, amrex::RealVect dx, @@ -82,9 +88,9 @@ class SpectralSolver bool periodic_single_box, bool update_with_rho, bool fft_do_time_averaging, - int psatd_solution_type, - int J_in_time, - int rho_in_time, + PSATDSolutionType psatd_solution_type, + JInTime J_in_time, + RhoInTime rho_in_time, bool dive_cleaning, bool divb_cleaning); diff --git a/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp b/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp index 9fc8f8056ca..fcd52597e07 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp @@ -17,25 +17,29 @@ #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXProfilerWrapper.H" +#include + #include #if WARPX_USE_FFT -SpectralSolver::SpectralSolver( +SpectralSolver::SpectralSolver ( const int lev, const amrex::BoxArray& realspace_ba, const amrex::DistributionMapping& dm, - const int norder_x, const int norder_y, - const int norder_z, const short grid_type, + const int norder_x, + const int norder_y, + const int norder_z, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, const amrex::Vector& v_comoving, const amrex::RealVect dx, const amrex::Real dt, const bool pml, const bool periodic_single_box, const bool update_with_rho, const bool fft_do_time_averaging, - const int psatd_solution_type, - const int J_in_time, - const int rho_in_time, + const PSATDSolutionType psatd_solution_type, + const JInTime J_in_time, + const RhoInTime rho_in_time, const bool dive_cleaning, const bool divb_cleaning) { diff --git a/Source/FieldSolver/SpectralSolver/SpectralSolverRZ.H b/Source/FieldSolver/SpectralSolver/SpectralSolverRZ.H index 30bfe5cf16c..004255e4d72 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralSolverRZ.H +++ b/Source/FieldSolver/SpectralSolver/SpectralSolverRZ.H @@ -12,6 +12,9 @@ #include "SpectralAlgorithms/SpectralBaseAlgorithmRZ.H" #include "SpectralFieldDataRZ.H" +#include + + /* \brief Top-level class for the electromagnetic spectral solver * * Stores the field in spectral space, and has member functions @@ -31,14 +34,15 @@ class SpectralSolverRZ amrex::BoxArray const & realspace_ba, amrex::DistributionMapping const & dm, int n_rz_azimuthal_modes, - int norder_z, short grid_type, + int norder_z, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, amrex::RealVect dx, amrex::Real dt, bool with_pml, bool update_with_rho, bool fft_do_time_averaging, - int J_in_time, - int rho_in_time, + JInTime J_in_time, + RhoInTime rho_in_time, bool dive_cleaning, bool divb_cleaning); diff --git a/Source/FieldSolver/SpectralSolver/SpectralSolverRZ.cpp b/Source/FieldSolver/SpectralSolver/SpectralSolverRZ.cpp index 9b0d2f21f94..7eb3f2c3ae6 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralSolverRZ.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralSolverRZ.cpp @@ -29,14 +29,15 @@ SpectralSolverRZ::SpectralSolverRZ (const int lev, amrex::BoxArray const & realspace_ba, amrex::DistributionMapping const & dm, int const n_rz_azimuthal_modes, - int const norder_z, short const grid_type, + int const norder_z, + ablastr::utils::enums::GridType grid_type, const amrex::Vector& v_galilean, amrex::RealVect const dx, amrex::Real const dt, bool const with_pml, bool const update_with_rho, const bool fft_do_time_averaging, - const int J_in_time, - const int rho_in_time, + const JInTime J_in_time, + const RhoInTime rho_in_time, const bool dive_cleaning, const bool divb_cleaning) : k_space(realspace_ba, dm, dx) diff --git a/Source/FieldSolver/WarpXPushFieldsHybridPIC.cpp b/Source/FieldSolver/WarpXPushFieldsHybridPIC.cpp index 4dbe10c4e5a..c16f0193b8d 100644 --- a/Source/FieldSolver/WarpXPushFieldsHybridPIC.cpp +++ b/Source/FieldSolver/WarpXPushFieldsHybridPIC.cpp @@ -88,9 +88,6 @@ void WarpX::HybridPICEvolveFields () } } - // Calculate the electron pressure at t=n using rho^n - m_hybrid_pic_model->CalculateElectronPressure(DtType::FirstHalf); - // Push the B field from t=n to t=n+1/2 using the current and density // at t=n, while updating the E field along with B using the electron // momentum equation @@ -116,9 +113,6 @@ void WarpX::HybridPICEvolveFields () ); } - // Calculate the electron pressure at t=n+1/2 - m_hybrid_pic_model->CalculateElectronPressure(DtType::SecondHalf); - // Now push the B field from t=n+1/2 to t=n+1 using the n+1/2 quantities for (int sub_step = 0; sub_step < sub_steps; sub_step++) { @@ -149,7 +143,7 @@ void WarpX::HybridPICEvolveFields () } // Calculate the electron pressure at t=n+1 - m_hybrid_pic_model->CalculateElectronPressure(DtType::Full); + m_hybrid_pic_model->CalculateElectronPressure(); // Update the E field to t=n+1 using the extrapolated J_i^n+1 value m_hybrid_pic_model->CalculateCurrentAmpere(Bfield_fp, m_edge_lengths); diff --git a/Source/FieldSolver/WarpXSolveFieldsES.cpp b/Source/FieldSolver/WarpXSolveFieldsES.cpp new file mode 100644 index 00000000000..42a537b5c2a --- /dev/null +++ b/Source/FieldSolver/WarpXSolveFieldsES.cpp @@ -0,0 +1,30 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: Remi Lehe, Roelof Groenewald, Arianna Formenti, Revathi Jambunathan + * + * License: BSD-3-Clause-LBNL + */ +#include "FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H" +#include "Utils/WarpXProfilerWrapper.H" +#include "WarpX.H" + +void WarpX::ComputeSpaceChargeField (bool const reset_fields) +{ + WARPX_PROFILE("WarpX::ComputeSpaceChargeField"); + if (reset_fields) { + // Reset all E and B fields to 0, before calculating space-charge fields + WARPX_PROFILE("WarpX::ComputeSpaceChargeField::reset_fields"); + for (int lev = 0; lev <= max_level; lev++) { + for (int comp=0; comp<3; comp++) { + Efield_fp[lev][comp]->setVal(0); + Bfield_fp[lev][comp]->setVal(0); + } + } + } + + m_electrostatic_solver->ComputeSpaceChargeField( + rho_fp, rho_cp, charge_buf, phi_fp, *mypc, myfl.get(), Efield_fp, Bfield_fp + ); +} diff --git a/Source/FieldSolver/WarpX_QED_Field_Pushers.cpp b/Source/FieldSolver/WarpX_QED_Field_Pushers.cpp index 1d3cb04a8a7..9741d9b667b 100644 --- a/Source/FieldSolver/WarpX_QED_Field_Pushers.cpp +++ b/Source/FieldSolver/WarpX_QED_Field_Pushers.cpp @@ -169,7 +169,7 @@ WarpX::Hybrid_QED_Push (int lev, PatchType patch_type, amrex::Real a_dt) ); // Make local copy of xi, to use on device. - const Real xi_c2 = WarpX::quantum_xi_c2; + const Real xi_c2 = m_quantum_xi_c2; // Apply QED correction to electric field, using temporary arrays. amrex::ParallelFor( diff --git a/Source/Filter/BilinearFilter.cpp b/Source/Filter/BilinearFilter.cpp index a095bce6ae3..66976045943 100644 --- a/Source/Filter/BilinearFilter.cpp +++ b/Source/Filter/BilinearFilter.cpp @@ -64,34 +64,25 @@ void BilinearFilter::ComputeStencils(){ WARPX_PROFILE("BilinearFilter::ComputeStencils()"); int i = 0; for (const auto& el : npass_each_dir ) { - stencil_length_each_dir[i++] = static_cast(el); + stencil_length_each_dir[i++] = static_cast(el) + 1; } - stencil_length_each_dir += 1.; + + m_stencil_0.resize( 1u + npass_each_dir[0] ); + compute_stencil(m_stencil_0, npass_each_dir[0]); +#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_3D) + m_stencil_1.resize( 1u + npass_each_dir[1] ); + compute_stencil(m_stencil_1, npass_each_dir[1]); +#endif #if defined(WARPX_DIM_3D) - // npass_each_dir = npass_x npass_y npass_z - stencil_x.resize( 1u + npass_each_dir[0] ); - stencil_y.resize( 1u + npass_each_dir[1] ); - stencil_z.resize( 1u + npass_each_dir[2] ); - compute_stencil(stencil_x, npass_each_dir[0]); - compute_stencil(stencil_y, npass_each_dir[1]); - compute_stencil(stencil_z, npass_each_dir[2]); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - // npass_each_dir = npass_x npass_z - stencil_x.resize( 1u + npass_each_dir[0] ); - stencil_z.resize( 1u + npass_each_dir[1] ); - compute_stencil(stencil_x, npass_each_dir[0]); - compute_stencil(stencil_z, npass_each_dir[1]); -#elif defined(WARPX_DIM_1D_Z) - // npass_each_dir = npass_z - stencil_z.resize( 1u + npass_each_dir[0] ); - compute_stencil(stencil_z, npass_each_dir[0]); + m_stencil_2.resize( 1u + npass_each_dir[2] ); + compute_stencil(m_stencil_2, npass_each_dir[2]); #endif + slen = stencil_length_each_dir.dim3(); -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) +#if defined(WARPX_DIM_1D_Z) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) slen.z = 1; #endif #if defined(WARPX_DIM_1D_Z) slen.y = 1; - slen.z = 1; #endif } diff --git a/Source/Filter/Filter.H b/Source/Filter/Filter.H index 5c648a75c4c..584f6b151d7 100644 --- a/Source/Filter/Filter.H +++ b/Source/Filter/Filter.H @@ -21,9 +21,9 @@ public: // Apply stencil on MultiFab. // Guard cells are handled inside this function - void ApplyStencil(amrex::MultiFab& dstmf, - const amrex::MultiFab& srcmf, int lev, int scomp=0, - int dcomp=0, int ncomp=10000); + void ApplyStencil (amrex::MultiFab& dstmf, + const amrex::MultiFab& srcmf, int lev, int scomp=0, + int dcomp=0, int ncomp=10000); // Apply stencil on a FabArray. void ApplyStencil (amrex::FArrayBox& dstfab, @@ -31,20 +31,18 @@ public: int scomp=0, int dcomp=0, int ncomp=10000); // public for cuda - void DoFilter(const amrex::Box& tbx, - amrex::Array4 const& tmp, - amrex::Array4 const& dst, - int scomp, int dcomp, int ncomp); + void DoFilter (const amrex::Box& tbx, + amrex::Array4 const& tmp, + amrex::Array4 const& dst, + int scomp, int dcomp, int ncomp); - // In 2D, stencil_length_each_dir = {length(stencil_x), length(stencil_z)} + // Length of stencil in each included direction amrex::IntVect stencil_length_each_dir; protected: // Stencil along each direction. - // in 2D, stencil_y is not initialized. - amrex::Gpu::DeviceVector stencil_x, stencil_y, stencil_z; - // Length of each stencil. - // In 2D, slen = {length(stencil_x), length(stencil_z), 1} + amrex::Gpu::DeviceVector m_stencil_0, m_stencil_1, m_stencil_2; + // Length of each stencil, 1 for dimensions not included amrex::Dim3 slen; private: diff --git a/Source/Filter/Filter.cpp b/Source/Filter/Filter.cpp index 6243ce4ebbf..40dfc54f8cb 100644 --- a/Source/Filter/Filter.cpp +++ b/Source/Filter/Filter.cpp @@ -87,23 +87,21 @@ Filter::ApplyStencil (FArrayBox& dstfab, const FArrayBox& srcfab, DoFilter(tbx, src, dst, scomp, dcomp, ncomp); } -/* \brief Apply stencil (2D/3D, CPU/GPU) +/* \brief Apply stencil (CPU/GPU) */ void Filter::DoFilter (const Box& tbx, Array4 const& src, Array4 const& dst, int scomp, int dcomp, int ncomp) { -#if (AMREX_SPACEDIM >= 2) - amrex::Real const* AMREX_RESTRICT sx = stencil_x.data(); -#endif -#if defined(WARPX_DIM_3D) - amrex::Real const* AMREX_RESTRICT sy = stencil_y.data(); -#endif - amrex::Real const* AMREX_RESTRICT sz = stencil_z.data(); + AMREX_D_TERM( + amrex::Real const* AMREX_RESTRICT s0 = m_stencil_0.data();, + amrex::Real const* AMREX_RESTRICT s1 = m_stencil_1.data();, + amrex::Real const* AMREX_RESTRICT s2 = m_stencil_2.data(); + ) Dim3 slen_local = slen; -#if defined(WARPX_DIM_3D) +#if AMREX_SPACEDIM == 3 AMREX_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n, { Real d = 0.0; @@ -115,25 +113,25 @@ void Filter::DoFilter (const Box& tbx, return src.contains(jj,kk,ll) ? src(jj,kk,ll,nn) : 0.0_rt; }; - for (int iz=0; iz < slen_local.z; ++iz){ - for (int iy=0; iy < slen_local.y; ++iy){ - for (int ix=0; ix < slen_local.x; ++ix){ - Real sss = sx[ix]*sy[iy]*sz[iz]; - d += sss*( src_zeropad(i-ix,j-iy,k-iz,scomp+n) - +src_zeropad(i+ix,j-iy,k-iz,scomp+n) - +src_zeropad(i-ix,j+iy,k-iz,scomp+n) - +src_zeropad(i+ix,j+iy,k-iz,scomp+n) - +src_zeropad(i-ix,j-iy,k+iz,scomp+n) - +src_zeropad(i+ix,j-iy,k+iz,scomp+n) - +src_zeropad(i-ix,j+iy,k+iz,scomp+n) - +src_zeropad(i+ix,j+iy,k+iz,scomp+n)); + for (int i2=0; i2 < slen_local.z; ++i2){ + for (int i1=0; i1 < slen_local.y; ++i1){ + for (int i0=0; i0 < slen_local.x; ++i0){ + Real sss = s0[i0]*s1[i1]*s2[i2]; + d += sss*( src_zeropad(i-i0,j-i1,k-i2,scomp+n) + +src_zeropad(i+i0,j-i1,k-i2,scomp+n) + +src_zeropad(i-i0,j+i1,k-i2,scomp+n) + +src_zeropad(i+i0,j+i1,k-i2,scomp+n) + +src_zeropad(i-i0,j-i1,k+i2,scomp+n) + +src_zeropad(i+i0,j-i1,k+i2,scomp+n) + +src_zeropad(i-i0,j+i1,k+i2,scomp+n) + +src_zeropad(i+i0,j+i1,k+i2,scomp+n)); } } } dst(i,j,k,dcomp+n) = d; }); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) +#elif AMREX_SPACEDIM == 2 AMREX_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n, { Real d = 0.0; @@ -145,21 +143,21 @@ void Filter::DoFilter (const Box& tbx, return src.contains(jj,kk,ll) ? src(jj,kk,ll,nn) : 0.0_rt; }; - for (int iz=0; iz < slen_local.z; ++iz){ - for (int iy=0; iy < slen_local.y; ++iy){ - for (int ix=0; ix < slen_local.x; ++ix){ - Real sss = sx[ix]*sz[iy]; - d += sss*( src_zeropad(i-ix,j-iy,k,scomp+n) - +src_zeropad(i+ix,j-iy,k,scomp+n) - +src_zeropad(i-ix,j+iy,k,scomp+n) - +src_zeropad(i+ix,j+iy,k,scomp+n)); + for (int i2=0; i2 < slen_local.z; ++i2){ + for (int i1=0; i1 < slen_local.y; ++i1){ + for (int i0=0; i0 < slen_local.x; ++i0){ + Real sss = s0[i0]*s1[i1]; + d += sss*( src_zeropad(i-i0,j-i1,k,scomp+n) + +src_zeropad(i+i0,j-i1,k,scomp+n) + +src_zeropad(i-i0,j+i1,k,scomp+n) + +src_zeropad(i+i0,j+i1,k,scomp+n)); } } } dst(i,j,k,dcomp+n) = d; }); -#elif defined(WARPX_DIM_1D_Z) +#elif AMREX_SPACEDIM == 1 AMREX_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n, { Real d = 0.0; @@ -171,21 +169,18 @@ void Filter::DoFilter (const Box& tbx, return src.contains(jj,kk,ll) ? src(jj,kk,ll,nn) : 0.0_rt; }; - for (int iz=0; iz < slen_local.z; ++iz){ - for (int iy=0; iy < slen_local.y; ++iy){ - for (int ix=0; ix < slen_local.x; ++ix){ - Real sss = sz[iy]; - d += sss*( src_zeropad(i-ix,j,k,scomp+n) - +src_zeropad(i+ix,j,k,scomp+n)); + for (int i2=0; i2 < slen_local.z; ++i2){ + for (int i1=0; i1 < slen_local.y; ++i1){ + for (int i0=0; i0 < slen_local.x; ++i0){ + Real sss = s0[i0]; + d += sss*( src_zeropad(i-i0,j,k,scomp+n) + +src_zeropad(i+i0,j,k,scomp+n)); } } } dst(i,j,k,dcomp+n) = d; }); -#else - WARPX_ABORT_WITH_MESSAGE( - "Filter not implemented for the current geometry!"); #endif } @@ -278,13 +273,11 @@ void Filter::DoFilter (const Box& tbx, const auto lo = amrex::lbound(tbx); const auto hi = amrex::ubound(tbx); // tmp and dst are of type Array4 (Fortran ordering) -#if (AMREX_SPACEDIM >= 2) - amrex::Real const* AMREX_RESTRICT sx = stencil_x.data(); -#endif -#if defined(WARPX_DIM_3D) - amrex::Real const* AMREX_RESTRICT sy = stencil_y.data(); -#endif - amrex::Real const* AMREX_RESTRICT sz = stencil_z.data(); + AMREX_D_TERM( + amrex::Real const* AMREX_RESTRICT s0 = m_stencil_0.data();, + amrex::Real const* AMREX_RESTRICT s1 = m_stencil_1.data();, + amrex::Real const* AMREX_RESTRICT s2 = m_stencil_2.data(); + ) for (int n = 0; n < ncomp; ++n) { // Set dst value to 0. for (int k = lo.z; k <= hi.z; ++k) { @@ -295,41 +288,32 @@ void Filter::DoFilter (const Box& tbx, } } // 3 nested loop on 3D stencil - for (int iz=0; iz < slen.z; ++iz){ - for (int iy=0; iy < slen.y; ++iy){ - for (int ix=0; ix < slen.x; ++ix){ -#if defined(WARPX_DIM_3D) - const Real sss = sx[ix]*sy[iy]*sz[iz]; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const Real sss = sx[ix]*sz[iy]; -#else - const Real sss = sz[ix]; -#endif + for (int i2=0; i2 < slen.z; ++i2){ + for (int i1=0; i1 < slen.y; ++i1){ + for (int i0=0; i0 < slen.x; ++i0){ + const Real sss = AMREX_D_TERM(s0[i0], *s1[i1], *s2[i2]); // 3 nested loop on 3D array for (int k = lo.z; k <= hi.z; ++k) { for (int j = lo.y; j <= hi.y; ++j) { AMREX_PRAGMA_SIMD for (int i = lo.x; i <= hi.x; ++i) { -#if defined(WARPX_DIM_3D) - dst(i,j,k,dcomp+n) += sss*(tmp(i-ix,j-iy,k-iz,scomp+n) - +tmp(i+ix,j-iy,k-iz,scomp+n) - +tmp(i-ix,j+iy,k-iz,scomp+n) - +tmp(i+ix,j+iy,k-iz,scomp+n) - +tmp(i-ix,j-iy,k+iz,scomp+n) - +tmp(i+ix,j-iy,k+iz,scomp+n) - +tmp(i-ix,j+iy,k+iz,scomp+n) - +tmp(i+ix,j+iy,k+iz,scomp+n)); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - dst(i,j,k,dcomp+n) += sss*(tmp(i-ix,j-iy,k,scomp+n) - +tmp(i+ix,j-iy,k,scomp+n) - +tmp(i-ix,j+iy,k,scomp+n) - +tmp(i+ix,j+iy,k,scomp+n)); -#elif defined(WARPX_DIM_1D_Z) - dst(i,j,k,dcomp+n) += sss*(tmp(i-ix,j,k,scomp+n) - +tmp(i+ix,j,k,scomp+n)); -#else - WARPX_ABORT_WITH_MESSAGE( - "Filter not implemented for the current geometry!"); +#if AMREX_SPACEDIM == 3 + dst(i,j,k,dcomp+n) += sss*(tmp(i-i0,j-i1,k-i2,scomp+n) + +tmp(i+i0,j-i1,k-i2,scomp+n) + +tmp(i-i0,j+i1,k-i2,scomp+n) + +tmp(i+i0,j+i1,k-i2,scomp+n) + +tmp(i-i0,j-i1,k+i2,scomp+n) + +tmp(i+i0,j-i1,k+i2,scomp+n) + +tmp(i-i0,j+i1,k+i2,scomp+n) + +tmp(i+i0,j+i1,k+i2,scomp+n)); +#elif AMREX_SPACEDIM == 2 + dst(i,j,k,dcomp+n) += sss*(tmp(i-i0,j-i1,k,scomp+n) + +tmp(i+i0,j-i1,k,scomp+n) + +tmp(i-i0,j+i1,k,scomp+n) + +tmp(i+i0,j+i1,k,scomp+n)); +#elif AMREX_SPACEDIM == 1 + dst(i,j,k,dcomp+n) += sss*(tmp(i-i0,j,k,scomp+n) + +tmp(i+i0,j,k,scomp+n)); #endif } } diff --git a/Source/Filter/NCIGodfreyFilter.cpp b/Source/Filter/NCIGodfreyFilter.cpp index 9567bdf1bb2..a73efb0ec64 100644 --- a/Source/Filter/NCIGodfreyFilter.cpp +++ b/Source/Filter/NCIGodfreyFilter.cpp @@ -121,17 +121,18 @@ void NCIGodfreyFilter::ComputeStencils() # endif h_stencil_z[0] /= 2._rt; - stencil_x.resize(h_stencil_x.size()); + m_stencil_0.resize(h_stencil_x.size()); + Gpu::copyAsync(Gpu::hostToDevice,h_stencil_x.begin(),h_stencil_x.end(),m_stencil_0.begin()); # if defined(WARPX_DIM_3D) - stencil_y.resize(h_stencil_y.size()); + m_stencil_1.resize(h_stencil_y.size()); + m_stencil_2.resize(h_stencil_z.size()); + Gpu::copyAsync(Gpu::hostToDevice,h_stencil_y.begin(),h_stencil_y.end(),m_stencil_1.begin()); + Gpu::copyAsync(Gpu::hostToDevice,h_stencil_z.begin(),h_stencil_z.end(),m_stencil_2.begin()); +# elif (AMREX_SPACEDIM == 2) + // In 2D, the filter applies stencil_1 to the 2nd dimension + m_stencil_1.resize(h_stencil_z.size()); + Gpu::copyAsync(Gpu::hostToDevice,h_stencil_z.begin(),h_stencil_z.end(),m_stencil_1.begin()); # endif - stencil_z.resize(h_stencil_z.size()); - - Gpu::copyAsync(Gpu::hostToDevice,h_stencil_x.begin(),h_stencil_x.end(),stencil_x.begin()); -# if defined(WARPX_DIM_3D) - Gpu::copyAsync(Gpu::hostToDevice,h_stencil_y.begin(),h_stencil_y.end(),stencil_y.begin()); -# endif - Gpu::copyAsync(Gpu::hostToDevice,h_stencil_z.begin(),h_stencil_z.end(),stencil_z.begin()); Gpu::synchronize(); } diff --git a/Source/Fluids/WarpXFluidContainer.cpp b/Source/Fluids/WarpXFluidContainer.cpp index 11f25678dc0..99a1212ac90 100644 --- a/Source/Fluids/WarpXFluidContainer.cpp +++ b/Source/Fluids/WarpXFluidContainer.cpp @@ -1035,14 +1035,27 @@ void WarpXFluidContainer::GatherAndPush ( // Here, we do not perform any coarsening. const amrex::GpuArray coarsening_ratio = {1, 1, 1}; - amrex::ParallelFor(tile_box, - [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept + enum exte_flags : int { no_exte, has_exte }; + enum extb_flags : int { no_extb, has_extb }; + enum boost_flags : int { no_gamma_boost, has_gamma_boost }; + const int exte_runtime_flag = external_e_fields ? has_exte : no_exte; + const int extb_runtime_flag = external_b_fields ? has_extb : no_extb; + const int boost_runtime_flag = (gamma_boost > 1._rt) ? has_gamma_boost : no_gamma_boost; + + amrex::ParallelFor(TypeList, + CompileTimeOptions, + CompileTimeOptions>{}, + {exte_runtime_flag, extb_runtime_flag, boost_runtime_flag}, + tile_box, + [=] AMREX_GPU_DEVICE(int i, int j, int k, + auto exte_control, auto extb_control, auto boost_control) noexcept { // Only run if density is positive if (N_arr(i,j,k)>0.0) { // Interpolate fields from tmp to Nodal points + // NOLINTBEGIN(misc-const-correctness) amrex::Real Ex_Nodal = ablastr::coarsen::sample::Interp(Ex_arr, Ex_type, Nodal_type, coarsening_ratio, i, j, k, 0); amrex::Real Ey_Nodal = ablastr::coarsen::sample::Interp(Ey_arr, @@ -1055,9 +1068,16 @@ void WarpXFluidContainer::GatherAndPush ( By_type, Nodal_type, coarsening_ratio, i, j, k, 0); amrex::Real Bz_Nodal = ablastr::coarsen::sample::Interp(Bz_arr, Bz_type, Nodal_type, coarsening_ratio, i, j, k, 0); + // NOLINTEND(misc-const-correctness) + +#ifdef AMREX_USE_CUDA + amrex::ignore_unused(Exfield_parser, Eyfield_parser, Ezfield_parser, + Bxfield_parser, Byfield_parser, Bzfield_parser, + gamma_boost, problo, dx, t, beta_boost); +#endif - if (gamma_boost > 1._rt) { // Lorentz transform fields due to moving frame - if ( ( external_b_fields ) || ( external_e_fields ) ){ + if constexpr (boost_control == has_gamma_boost) { // Lorentz transform fields due to moving frame + if constexpr (exte_control == has_exte || extb_control == has_extb) { // Lorentz transform z (from boosted to lab frame) amrex::Real Ex_ext_boost, Ey_ext_boost, Ez_ext_boost; @@ -1086,7 +1106,7 @@ void WarpXFluidContainer::GatherAndPush ( const amrex::Real z_lab = gamma_boost*(z + beta_boost*PhysConst::c*t); // Grab the external fields in the lab frame: - if ( external_e_fields ) { + if ( exte_control == has_exte ) { Ex_ext_lab = Exfield_parser(x, y, z_lab, t_lab); Ey_ext_lab = Eyfield_parser(x, y, z_lab, t_lab); Ez_ext_lab = Ezfield_parser(x, y, z_lab, t_lab); @@ -1095,7 +1115,7 @@ void WarpXFluidContainer::GatherAndPush ( Ey_ext_lab = 0.0; Ez_ext_lab = 0.0; } - if ( external_b_fields ) { + if ( extb_control == has_extb ) { Bx_ext_lab = Bxfield_parser(x, y, z_lab, t_lab); By_ext_lab = Byfield_parser(x, y, z_lab, t_lab); Bz_ext_lab = Bzfield_parser(x, y, z_lab, t_lab); @@ -1126,7 +1146,7 @@ void WarpXFluidContainer::GatherAndPush ( } else { // Added external e fields: - if ( external_e_fields ){ + if constexpr ( exte_control == has_exte ){ #if defined(WARPX_DIM_3D) const amrex::Real x = problo[0] + i * dx[0]; const amrex::Real y = problo[1] + j * dx[1]; @@ -1147,7 +1167,7 @@ void WarpXFluidContainer::GatherAndPush ( } // Added external b fields: - if ( external_b_fields ){ + if ( extb_control == has_extb ){ #if defined(WARPX_DIM_3D) const amrex::Real x = problo[0] + i * dx[0]; const amrex::Real y = problo[1] + j * dx[1]; diff --git a/Source/Initialization/CMakeLists.txt b/Source/Initialization/CMakeLists.txt index e5e2334fd7e..1063ddb74f1 100644 --- a/Source/Initialization/CMakeLists.txt +++ b/Source/Initialization/CMakeLists.txt @@ -15,3 +15,5 @@ foreach(D IN LISTS WarpX_DIMS) WarpXInitData.cpp ) endforeach() + +add_subdirectory(DivCleaner) diff --git a/Source/Initialization/DivCleaner/CMakeLists.txt b/Source/Initialization/DivCleaner/CMakeLists.txt new file mode 100644 index 00000000000..9acedc05fb0 --- /dev/null +++ b/Source/Initialization/DivCleaner/CMakeLists.txt @@ -0,0 +1,7 @@ +foreach(D IN LISTS WarpX_DIMS) + warpx_set_suffix_dims(SD ${D}) + target_sources(lib_${SD} + PRIVATE + ProjectionDivCleaner.cpp + ) +endforeach() diff --git a/Source/Initialization/DivCleaner/Make.package b/Source/Initialization/DivCleaner/Make.package new file mode 100644 index 00000000000..2ef55d8f4fc --- /dev/null +++ b/Source/Initialization/DivCleaner/Make.package @@ -0,0 +1,3 @@ +CEXE_sources += ProjectionDivCleaner.cpp + +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Initialization/DivCleaner diff --git a/Source/Initialization/DivCleaner/ProjectionDivCleaner.H b/Source/Initialization/DivCleaner/ProjectionDivCleaner.H new file mode 100644 index 00000000000..7ee1fe57048 --- /dev/null +++ b/Source/Initialization/DivCleaner/ProjectionDivCleaner.H @@ -0,0 +1,98 @@ + /* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: S. Eric Clark (Helion Energy, Inc.) + * + * License: BSD-3-Clause-LBNL + */ +#ifndef WARPX_PROJECTION_DIV_CLEANER_H_ +#define WARPX_PROJECTION_DIV_CLEANER_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "Utils/Parser/ParserUtils.H" + +namespace warpx::initialization { + +class ProjectionDivCleaner +{ +protected: + int m_levels = 1; // Hard coded to 1 for now, will only clean first level + + int m_ref_ratio = 1; + + // For MLMG solver + int m_verbose = 2; + int m_bottom_verbose = 0; + int m_max_iter = 5000; + int m_max_fmg_iter = 1000; + int m_linop_maxorder = 3; + bool m_agglomeration = false; + bool m_consolidation = false; + bool m_semicoarsening = true; + int m_max_coarsening_level = 10; + int m_max_semicoarsening_level = 10; + amrex::BottomSolver m_bottom_solver = amrex::BottomSolver::bicgstab; + + + amrex::Real m_rtol; + amrex::Real m_atol; + + warpx::fields::FieldType m_field_type; + +public: + amrex::Vector< std::unique_ptr > m_solution; + amrex::Vector< std::unique_ptr > m_source; + + amrex::Vector m_h_stencil_coefs_x; +#if !defined(WARPX_DIM_RZ) + amrex::Vector m_h_stencil_coefs_y; +#endif + amrex::Vector m_h_stencil_coefs_z; + + amrex::Gpu::DeviceVector m_stencil_coefs_x; +#if !defined(WARPX_DIM_RZ) + amrex::Gpu::DeviceVector m_stencil_coefs_y; +#endif + amrex::Gpu::DeviceVector m_stencil_coefs_z; + + // Default Constructor + ProjectionDivCleaner (warpx::fields::FieldType a_field_type); + + void ReadParameters (); + + void solve (); + void setSourceFromBfield (); + void correctBfield (); + +}; + +} // end namespace warpx::initialization + +#endif // WARPX_PROJECTION_DIV_CLEANER_H_ diff --git a/Source/Initialization/DivCleaner/ProjectionDivCleaner.cpp b/Source/Initialization/DivCleaner/ProjectionDivCleaner.cpp new file mode 100644 index 00000000000..40326aadc3c --- /dev/null +++ b/Source/Initialization/DivCleaner/ProjectionDivCleaner.cpp @@ -0,0 +1,354 @@ + /* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * Authors: S. Eric Clark (Helion Energy, Inc.) + * + * License: BSD-3-Clause-LBNL + */ + +#include "ProjectionDivCleaner.H" + +#include +#include +#include + +#include +#if defined WARPX_DIM_RZ +#include +#else +#include +#endif +#include +#include +#include +#include + +#include + +using namespace amrex; + +namespace warpx::initialization { + +ProjectionDivCleaner::ProjectionDivCleaner(warpx::fields::FieldType a_field_type) : + m_field_type(a_field_type) +{ + ReadParameters(); + + auto& warpx = WarpX::GetInstance(); + + // Only div clean level 0 + if (warpx.finestLevel() > 0) { + ablastr::warn_manager::WMRecordWarning("Projection Div Cleaner", + "Multiple AMR levels detected, only first level has been cleaned.", + ablastr::warn_manager::WarnPriority::low); + } + + m_solution.resize(m_levels); + m_source.resize(m_levels); + + const int ncomps = WarpX::ncomps; + auto const& ng = warpx.getFieldPointer(m_field_type, 0, 0)->nGrowVect(); + + for (int lev = 0; lev < m_levels; ++lev) + { + // Default BoxArray and DistributionMap for initializing the output MultiFab, m_mf_output. + const amrex::BoxArray& ba = warpx.boxArray(lev); + const amrex::DistributionMapping& dmap = warpx.DistributionMap(lev); + + m_solution[lev].reset(); + m_source[lev].reset(); + + const auto tag1 = amrex::MFInfo().SetTag("div_cleaner_solution"); + m_solution[lev] = std::make_unique(amrex::convert(ba, IntVect::TheCellVector()), + dmap, ncomps, ng, tag1); + const auto tag2 = amrex::MFInfo().SetTag("div_cleaner_source"); + m_source[lev] = std::make_unique(amrex::convert(ba, IntVect::TheCellVector()), + dmap, ncomps, ng, tag2); + + m_solution[lev]->setVal(0.0, ng); + m_source[lev]->setVal(0.0, ng); + } + + auto cell_size = WarpX::CellSize(0); +#if defined(WARPX_DIM_RZ) + CylindricalYeeAlgorithm::InitializeStencilCoefficients( cell_size, + m_h_stencil_coefs_x, m_h_stencil_coefs_z ); +#else + CartesianYeeAlgorithm::InitializeStencilCoefficients( cell_size, + m_h_stencil_coefs_x, m_h_stencil_coefs_y, m_h_stencil_coefs_z ); +#endif + + m_stencil_coefs_x.resize(m_h_stencil_coefs_x.size()); +#if !defined(WARPX_DIM_RZ) + m_stencil_coefs_y.resize(m_h_stencil_coefs_y.size()); +#endif + m_stencil_coefs_z.resize(m_h_stencil_coefs_z.size()); + + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, + m_h_stencil_coefs_x.begin(), m_h_stencil_coefs_x.end(), + m_stencil_coefs_x.begin()); +#if !defined(WARPX_DIM_RZ) + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, + m_h_stencil_coefs_y.begin(), m_h_stencil_coefs_y.end(), + m_stencil_coefs_y.begin()); +#endif + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, + m_h_stencil_coefs_z.begin(), m_h_stencil_coefs_z.end(), + m_stencil_coefs_z.begin()); + amrex::Gpu::synchronize(); +} + +void +ProjectionDivCleaner::ReadParameters () +{ + // Initialize tolerance based on field precision + if constexpr (std::is_same::value) { + m_rtol = 5e-5; + m_atol = 0.0; + } + else { + m_rtol = 5e-12; + m_atol = 0.0; + } + + const ParmParse pp_divb_cleaner("projection_divb_cleaner"); + + // Defaults to rtol 5e-12 for double fields and 5e-5 for single + utils::parser::queryWithParser(pp_divb_cleaner, "atol", m_atol); + utils::parser::queryWithParser(pp_divb_cleaner, "rtol", m_rtol); +} + +void +ProjectionDivCleaner::solve () +{ + // Get WarpX object + auto & warpx = WarpX::GetInstance(); + + const auto& ba = warpx.boxArray(); + const auto& dmap = warpx.DistributionMap(); + const auto& geom = warpx.Geom(); + + // Pull boundary conditions from WarpX class + // bogus values are overwritten. + amrex::Array lobc({AMREX_D_DECL(LinOpBCType::bogus, + LinOpBCType::bogus, + LinOpBCType::bogus)}); + amrex::Array hibc({AMREX_D_DECL(LinOpBCType::bogus, + LinOpBCType::bogus, + LinOpBCType::bogus)}); + + std::map bcmap{ + {FieldBoundaryType::PEC, LinOpBCType::Dirichlet}, + {FieldBoundaryType::Neumann, LinOpBCType::Neumann}, + {FieldBoundaryType::Periodic, LinOpBCType::Periodic}, + {FieldBoundaryType::None, LinOpBCType::Neumann} + }; + + for (int idim=0; idim 0) { + mlpoisson.setCoarseFineBC(m_solution[ilev-1].get(), m_ref_ratio); + } + + mlpoisson.setLevelBC(ilev, m_solution[ilev].get()); + + MLMG mlmg(mlpoisson); + mlmg.setMaxIter(m_max_iter); + mlmg.setMaxFmgIter(m_max_fmg_iter); + mlmg.setBottomSolver(m_bottom_solver); + mlmg.setVerbose(m_verbose); + mlmg.setBottomVerbose(m_bottom_verbose); + mlmg.setAlwaysUseBNorm(false); + mlmg.solve({m_solution[ilev].get()}, {m_source[ilev].get()}, m_rtol, m_atol); + + // Synchronize the ghost cells, do halo exchange + ablastr::utils::communication::FillBoundary(*m_solution[ilev], + m_solution[ilev]->nGrowVect(), + WarpX::do_single_precision_comms, + geom[ilev].periodicity()); + } +} + +void +ProjectionDivCleaner::setSourceFromBfield () +{ + // Get WarpX object + auto & warpx = WarpX::GetInstance(); + const auto& geom = warpx.Geom(); + + // This function will compute -divB and store it in the source multifab + for (int ilev = 0; ilev < m_levels; ++ilev) + { + WarpX::ComputeDivB( + *m_source[ilev], + 0, + warpx.getFieldPointerArray(m_field_type, ilev), + WarpX::CellSize(0) + ); + + m_source[ilev]->mult(-1._rt); + + // Synchronize the ghost cells, do halo exchange + ablastr::utils::communication::FillBoundary(*m_source[ilev], + m_source[ilev]->nGrowVect(), + WarpX::do_single_precision_comms, + geom[ilev].periodicity()); + } +} + +void +ProjectionDivCleaner::correctBfield () +{ + // Get WarpX object + auto & warpx = WarpX::GetInstance(); + const auto& geom = warpx.Geom(); + + // This function computes the gradient of the solution and subtracts out divB component from B + for (int ilev = 0; ilev < m_levels; ++ilev) + { + // Grab B-field multifabs at this level + amrex::MultiFab* Bx = warpx.getFieldPointer(m_field_type, ilev, 0); + amrex::MultiFab* By = warpx.getFieldPointer(m_field_type, ilev, 1); + amrex::MultiFab* Bz = warpx.getFieldPointer(m_field_type, ilev, 2); + +#ifdef AMREX_USE_OMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(*m_solution[ilev], TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + // Grab references to B field arrays for this grid/tile + amrex::Array4 const& Bx_arr = Bx->array(mfi); +#if !defined(WARPX_DIM_RZ) + amrex::Array4 const& By_arr = By->array(mfi); +#endif + amrex::Array4 const& Bz_arr = Bz->array(mfi); + + // Extract stencil coefficients + Real const * const AMREX_RESTRICT coefs_x = m_stencil_coefs_x.dataPtr(); + auto const n_coefs_x = static_cast(m_stencil_coefs_x.size()); +#if !defined(WARPX_DIM_RZ) + Real const * const AMREX_RESTRICT coefs_y = m_stencil_coefs_y.dataPtr(); + auto const n_coefs_y = static_cast(m_stencil_coefs_y.size()); +#endif + Real const * const AMREX_RESTRICT coefs_z = m_stencil_coefs_z.dataPtr(); + auto const n_coefs_z = static_cast(m_stencil_coefs_z.size()); + + const Box& tbx = mfi.tilebox(Bx->ixType().toIntVect()); +#if !defined(WARPX_DIM_RZ) + const Box& tby = mfi.tilebox(By->ixType().toIntVect()); +#endif + const Box& tbz = mfi.tilebox(Bz->ixType().toIntVect()); + + amrex::Array4 const& sol_arr = m_solution[ilev]->array(mfi); + +#if defined(WARPX_DIM_RZ) + amrex::ParallelFor(tbx, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/) + { + Bx_arr(i,j,0) += CylindricalYeeAlgorithm::DownwardDr(sol_arr, coefs_x, n_coefs_x, i, j, 0, 0); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/) + { + Bz_arr(i,j,0) += CylindricalYeeAlgorithm::DownwardDz(sol_arr, coefs_z, n_coefs_z, i, j, 0, 0); + }); +#else + amrex::ParallelFor(tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) + { + Bx_arr(i,j,k) += CartesianYeeAlgorithm::DownwardDx(sol_arr, coefs_x, n_coefs_x, i, j, k); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) + { + By_arr(i,j,k) += CartesianYeeAlgorithm::DownwardDy(sol_arr, coefs_y, n_coefs_y, i, j, k); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) + { + Bz_arr(i,j,k) += CartesianYeeAlgorithm::DownwardDz(sol_arr, coefs_z, n_coefs_z, i, j, k); + }); +#endif + } + // Synchronize the ghost cells, do halo exchange + ablastr::utils::communication::FillBoundary(*Bx, + Bx->nGrowVect(), + WarpX::do_single_precision_comms, + geom[ilev].periodicity()); + ablastr::utils::communication::FillBoundary(*By, + By->nGrowVect(), + WarpX::do_single_precision_comms, + geom[ilev].periodicity()); + ablastr::utils::communication::FillBoundary(*Bz, + Bz->nGrowVect(), + WarpX::do_single_precision_comms, + geom[ilev].periodicity()); + amrex::Gpu::synchronize(); + } +} + +} // namespace warpx::initialization + +void +WarpX::ProjectionCleanDivB() { + WARPX_PROFILE("WarpX::ProjectionDivCleanB()"); + + if (grid_type == GridType::Collocated) { + ablastr::warn_manager::WMRecordWarning("Projection Div Cleaner", + "Grid Type is collocated, so divB not cleaned. Interpolation may lead to non-zero B field divergence.", + ablastr::warn_manager::WarnPriority::low); + } else if ( WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::Yee + || WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC + || ( (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame + || WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic) + && WarpX::poisson_solver_id == PoissonSolverAlgo::Multigrid)) { + amrex::Print() << Utils::TextMsg::Info( "Starting Projection B-Field divergence cleaner."); + + if constexpr (!std::is_same::value) { + ablastr::warn_manager::WMRecordWarning("Projection Div Cleaner", + "WarpX is running with a field precision of SINGLE." + "Convergence of projection based div cleaner is not optimal and may fail.", + ablastr::warn_manager::WarnPriority::low); + } + + warpx::initialization::ProjectionDivCleaner dc( + warpx::fields::FieldType::Bfield_fp_external); + + dc.setSourceFromBfield(); + dc.solve(); + dc.correctBfield(); + + amrex::Print() << Utils::TextMsg::Info( "Finished Projection B-Field divergence cleaner."); + } else { + ablastr::warn_manager::WMRecordWarning("Projection Div Cleaner", + "Only Yee, HybridPIC, and MLMG based static Labframe solvers are currently supported, so divB not cleaned. " + "Interpolation may lead to non-zero B field divergence.", + ablastr::warn_manager::WarnPriority::low); + } +} diff --git a/Source/Initialization/ExternalField.H b/Source/Initialization/ExternalField.H index b32e361bff4..4cd4c41ccf2 100644 --- a/Source/Initialization/ExternalField.H +++ b/Source/Initialization/ExternalField.H @@ -23,7 +23,8 @@ enum class ExternalFieldType default_zero, constant, parse_ext_grid_function, - read_from_file + read_from_file, + load_from_python }; /** diff --git a/Source/Initialization/ExternalField.cpp b/Source/Initialization/ExternalField.cpp index 69120c0ae3c..d86c0a484bf 100644 --- a/Source/Initialization/ExternalField.cpp +++ b/Source/Initialization/ExternalField.cpp @@ -47,6 +47,9 @@ namespace else if ( s == "read_from_file"){ return ExternalFieldType::read_from_file; } + else if ( s == "load_from_python"){ + return ExternalFieldType::load_from_python; + } else{ WARPX_ABORT_WITH_MESSAGE( "'" + s + "' is an unknown external field type!"); diff --git a/Source/Initialization/Make.package b/Source/Initialization/Make.package index 831e3fc3f89..47cedb61b6e 100644 --- a/Source/Initialization/Make.package +++ b/Source/Initialization/Make.package @@ -10,4 +10,6 @@ CEXE_sources += WarpXAMReXInit.cpp CEXE_sources += WarpXInit.cpp CEXE_sources += WarpXInitData.cpp +include $(WARPX_HOME)/Source/Initialization/DivCleaner/Make.package + VPATH_LOCATIONS += $(WARPX_HOME)/Source/Initialization diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index 2e338b20c09..3d846375a99 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -51,11 +51,11 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name, { #ifdef AMREX_USE_GPU - static_assert(std::is_trivially_copyable::value, + static_assert(std::is_trivially_copyable_v, "InjectorPosition must be trivially copyable"); - static_assert(std::is_trivially_copyable::value, + static_assert(std::is_trivially_copyable_v, "InjectorDensity must be trivially copyable"); - static_assert(std::is_trivially_copyable::value, + static_assert(std::is_trivially_copyable_v, "InjectorMomentum must be trivially copyable"); #endif diff --git a/Source/Initialization/WarpXAMReXInit.cpp b/Source/Initialization/WarpXAMReXInit.cpp index 900dbb53e06..5009d2def59 100644 --- a/Source/Initialization/WarpXAMReXInit.cpp +++ b/Source/Initialization/WarpXAMReXInit.cpp @@ -12,71 +12,98 @@ #include #include #include -#include +#include #include namespace { - /** Overwrite defaults in AMReX Inputs - * - * This overwrites defaults in amrex::ParmParse for inputs. - */ - void - overwrite_amrex_parser_defaults () - { - amrex::ParmParse pp_amrex("amrex"); +#ifdef AMREX_USE_GPU + constexpr auto amrex_use_gpu = true; +#else + constexpr auto amrex_use_gpu = false; +#endif + + void override_default_abort_on_out_of_gpu_memory () + { // https://amrex-codes.github.io/amrex/docs_html/GPU.html#inputs-parameters - bool abort_on_out_of_gpu_memory = true; // AMReX' default: false + auto pp_amrex = amrex::ParmParse{"amrex"}; + bool abort_on_out_of_gpu_memory = true; // AMReX's default: false pp_amrex.queryAdd("abort_on_out_of_gpu_memory", abort_on_out_of_gpu_memory); + } - bool the_arena_is_managed = false; // AMReX' default: true + void override_default_the_arena_is_managed () + { + auto pp_amrex = amrex::ParmParse{"amrex"}; + bool the_arena_is_managed = false; // AMReX's default: true pp_amrex.queryAdd("the_arena_is_managed", the_arena_is_managed); + } + void override_default_omp_threads () + { // https://amrex-codes.github.io/amrex/docs_html/InputsComputeBackends.html - std::string omp_threads = "nosmt"; // AMReX' default: system + auto pp_amrex = amrex::ParmParse{"amrex"}; + std::string omp_threads = "nosmt"; // AMReX's default: system pp_amrex.queryAdd("omp_threads", omp_threads); + } + + void set_device_synchronization () + { + //See https://github.com/AMReX-Codes/amrex/pull/3763 + auto warpx_do_device_synchronize = amrex_use_gpu; + + auto pp_warpx = amrex::ParmParse{"warpx"}; + pp_warpx.query("do_device_synchronize", warpx_do_device_synchronize); + bool do_device_synchronize = warpx_do_device_synchronize; + + auto pp_tiny_profiler = amrex::ParmParse{"tiny_profiler"}; + if (pp_tiny_profiler.queryAdd("device_synchronize_around_region", do_device_synchronize) ) + { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + do_device_synchronize == warpx_do_device_synchronize, + "tiny_profiler.device_synchronize_around_region overrides warpx.do_device_synchronize."); + } + + } + void apply_workaround_for_warpx_numprocs () + { // Work-around: // If warpx.numprocs is used for the domain decomposition, we will not use blocking factor // to generate grids. Nonetheless, AMReX has asserts in place that validate that the // number of cells is a multiple of blocking factor. We set the blocking factor to 1 so those // AMReX asserts will always pass. - const amrex::ParmParse pp_warpx("warpx"); + const auto pp_warpx = amrex::ParmParse{"warpx"}; if (pp_warpx.contains("numprocs")) { amrex::ParmParse pp_amr("amr"); pp_amr.add("blocking_factor", 1); } + } - //See https://github.com/AMReX-Codes/amrex/pull/3763 -#ifdef AMREX_USE_GPU - bool warpx_do_device_synchronize = true; -#else - bool warpx_do_device_synchronize = false; -#endif - pp_warpx.query("do_device_synchronize", warpx_do_device_synchronize); - bool do_device_synchronize = warpx_do_device_synchronize; - amrex::ParmParse pp_tiny_profiler("tiny_profiler"); - if (pp_tiny_profiler.queryAdd("device_synchronize_around_region", do_device_synchronize) ) - { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - do_device_synchronize == warpx_do_device_synchronize, - "tiny_profiler.device_synchronize_around_region overrides warpx.do_device_synchronize."); - } - + void override_default_tiling_option_for_particles () + { // Here we override the default tiling option for particles, which is always // "false" in AMReX, to "false" if compiling for GPU execution and "true" // if compiling for CPU. - { - amrex::ParmParse pp_particles("particles"); -#ifdef AMREX_USE_GPU - bool do_tiling = false; // By default, tiling is off on GPU -#else - bool do_tiling = true; -#endif - pp_particles.queryAdd("do_tiling", do_tiling); - } + auto pp_particles = amrex::ParmParse{"particles"}; + auto do_tiling = !amrex_use_gpu; // By default, tiling is off on GPU + pp_particles.queryAdd("do_tiling", do_tiling); + } + + /** Overwrite defaults in AMReX Inputs + * + * This overwrites defaults in amrex::ParmParse for inputs. + */ + void + overwrite_amrex_parser_defaults () + { + override_default_abort_on_out_of_gpu_memory(); + override_default_the_arena_is_managed(); + override_default_omp_threads(); + apply_workaround_for_warpx_numprocs(); + set_device_synchronization(); + override_default_tiling_option_for_particles(); } } diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index e9f63e34bb0..0cf9496e63e 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -16,12 +16,15 @@ #endif #include "Diagnostics/MultiDiagnostics.H" #include "Diagnostics/ReducedDiags/MultiReducedDiags.H" +#include "EmbeddedBoundary/Enabled.H" #include "FieldSolver/Fields.H" +#include "FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H" #include "FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H" #include "FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H" #include "Filter/BilinearFilter.H" #include "Filter/NCIGodfreyFilter.H" #include "Initialization/ExternalField.H" +#include "Initialization/DivCleaner/ProjectionDivCleaner.H" #include "Particles/MultiParticleContainer.H" #include "Utils/Algorithms/LinearInterpolation.H" #include "Utils/Logo/GetLogo.H" @@ -106,6 +109,71 @@ namespace WARPX_ALWAYS_ASSERT_WITH_MESSAGE(vc.allGT(gc), ss_msg.str()); } } + + /** + * \brief Check the requested resources and write performance hints + * + * @param[in] total_nboxes total number of boxes in the simulation + * @param[in] nprocs number of MPI processes + */ + void PerformanceHints (const amrex::Long total_nboxes, const amrex::Long nprocs) + { + // Check: are there more MPI ranks than Boxes? + if (nprocs > total_nboxes) { + std::stringstream warnMsg; + warnMsg << "Too many resources / too little work!\n" + << " It looks like you requested more compute resources than " + << "there are total number of boxes of cells available (" + << total_nboxes << "). " + << "You started with (" << nprocs + << ") MPI ranks, so (" << nprocs - total_nboxes + << ") rank(s) will have no work.\n" + #ifdef AMREX_USE_GPU + << " On GPUs, consider using 1-8 boxes per GPU that together fill " + << "each GPU's memory sufficiently. If you do not rely on dynamic " + << "load-balancing, then one large box per GPU is ideal.\n" + #endif + << "Consider decreasing the amr.blocking_factor and " + << "amr.max_grid_size parameters and/or using fewer MPI ranks.\n" + << " More information:\n" + << " https://warpx.readthedocs.io/en/latest/usage/workflows/parallelization.html\n"; + + ablastr::warn_manager::WMRecordWarning( + "Performance", warnMsg.str(), ablastr::warn_manager::WarnPriority::high); + } + + #ifdef AMREX_USE_GPU + // Check: Are there more than 12 boxes per GPU? + if (total_nboxes > nprocs * 12) { + std::stringstream warnMsg; + warnMsg << "Too many boxes per GPU!\n" + << " It looks like you split your simulation domain " + << "in too many boxes (" << total_nboxes << "), which " + << "results in an average number of (" + << amrex::Long(total_nboxes/nprocs) << ") per GPU. " + << "This causes severe overhead in the communication of " + << "border/guard regions.\n" + << " On GPUs, consider using 1-8 boxes per GPU that together fill " + << "each GPU's memory sufficiently. If you do not rely on dynamic " + << "load-balancing, then one large box per GPU is ideal.\n" + << "Consider increasing the amr.blocking_factor and " + << "amr.max_grid_size parameters and/or using more MPI ranks.\n" + << " More information:\n" + << " https://warpx.readthedocs.io/en/latest/usage/workflows/parallelization.html\n"; + + ablastr::warn_manager::WMRecordWarning( + "Performance", warnMsg.str(), ablastr::warn_manager::WarnPriority::high); + } + #endif + + // TODO: warn if some ranks have disproportionally more work than all others + // tricky: it can be ok to assign "vacuum" boxes to some ranks w/o slowing down + // all other ranks; we need to measure this with our load-balancing + // routines and issue a warning only of some ranks stall all other ranks + // TODO: check MPI-rank to GPU ratio (should be 1:1) + // TODO: check memory per MPI rank, especially if GPUs are underutilized + // TODO: CPU tiling hints with OpenMP + } } void @@ -484,6 +552,8 @@ WarpX::InitData () ); } + m_electrostatic_solver->InitData(); + if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC) { m_hybrid_pic_model->InitData(); } @@ -503,6 +573,11 @@ WarpX::InitData () } WriteUsedInputsFile(); + // Run div cleaner here on loaded external fields + if (WarpX::do_divb_cleaning_external) { + WarpX::ProjectionCleanDivB(); + } + if (restart_chkfile.empty()) { // Loop through species and calculate their space-charge field @@ -513,12 +588,11 @@ WarpX::InitData () if (electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic) { ComputeMagnetostaticField(); } - - // Set up an invariant condition through the rest of - // execution, that any code besides the field solver that - // looks at field values will see the composite of the field - // solution and any external field - AddExternalFields(); + // Add external fields to the fine patch fields. This makes it so that the + // net fields are the sum of the field solutions and any external fields. + for (int lev = 0; lev <= max_level; ++lev) { + AddExternalFields(lev); + } } if (restart_chkfile.empty() || write_diagnostics_on_restart) { @@ -533,21 +607,40 @@ WarpX::InitData () } } - PerformanceHints(); + // Computes available boxes on all levels. + amrex::Long total_nboxes = 0; + for (int ilev = 0; ilev <= finestLevel(); ++ilev) { + total_nboxes += boxArray(ilev).size(); + } + auto const nprocs = ParallelDescriptor::NProcs(); + + ::PerformanceHints(total_nboxes, nprocs); CheckKnownIssues(); } void -WarpX::AddExternalFields () { - for (int lev = 0; lev <= finest_level; ++lev) { - // FIXME: RZ multimode has more than one component for all these - if (m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::read_from_file) { +WarpX::AddExternalFields (int const lev) { + // FIXME: RZ multimode has more than one component for all these + if (m_p_ext_field_params->E_ext_grid_type != ExternalFieldType::default_zero) { + if (m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::constant) { + Efield_fp[lev][0]->plus(m_p_ext_field_params->E_external_grid[0], guard_cells.ng_alloc_EB.min()); + Efield_fp[lev][1]->plus(m_p_ext_field_params->E_external_grid[1], guard_cells.ng_alloc_EB.min()); + Efield_fp[lev][2]->plus(m_p_ext_field_params->E_external_grid[2], guard_cells.ng_alloc_EB.min()); + } + else { amrex::MultiFab::Add(*Efield_fp[lev][0], *Efield_fp_external[lev][0], 0, 0, 1, guard_cells.ng_alloc_EB); amrex::MultiFab::Add(*Efield_fp[lev][1], *Efield_fp_external[lev][1], 0, 0, 1, guard_cells.ng_alloc_EB); amrex::MultiFab::Add(*Efield_fp[lev][2], *Efield_fp_external[lev][2], 0, 0, 1, guard_cells.ng_alloc_EB); } - if (m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::read_from_file) { + } + if (m_p_ext_field_params->B_ext_grid_type != ExternalFieldType::default_zero) { + if (m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::constant) { + Bfield_fp[lev][0]->plus(m_p_ext_field_params->B_external_grid[0], guard_cells.ng_alloc_EB.min()); + Bfield_fp[lev][1]->plus(m_p_ext_field_params->B_external_grid[1], guard_cells.ng_alloc_EB.min()); + Bfield_fp[lev][2]->plus(m_p_ext_field_params->B_external_grid[2], guard_cells.ng_alloc_EB.min()); + } + else { amrex::MultiFab::Add(*Bfield_fp[lev][0], *Bfield_fp_external[lev][0], 0, 0, 1, guard_cells.ng_alloc_EB); amrex::MultiFab::Add(*Bfield_fp[lev][1], *Bfield_fp_external[lev][1], 0, 0, 1, guard_cells.ng_alloc_EB); amrex::MultiFab::Add(*Bfield_fp[lev][2], *Bfield_fp_external[lev][2], 0, 0, 1, guard_cells.ng_alloc_EB); @@ -613,6 +706,7 @@ WarpX::InitPML () if (finest_level > 0) { do_pml = 1; } if (do_pml) { + bool const eb_enabled = EB::enabled(); #if (defined WARPX_DIM_RZ) && (defined WARPX_USE_FFT) do_pml_Lo[0][0] = 0; // no PML at r=0, in cylindrical geometry pml_rz[0] = std::make_unique(0, boxArray(0), DistributionMap(0), &Geom(0), pml_ncell, do_pml_in_domain); @@ -628,6 +722,7 @@ WarpX::InitPML () psatd_solution_type, J_in_time, rho_in_time, do_pml_dive_cleaning, do_pml_divb_cleaning, amrex::IntVect(0), amrex::IntVect(0), + eb_enabled, guard_cells.ng_FieldSolver.max(), v_particle_pml, do_pml_Lo[0], do_pml_Hi[0]); @@ -667,6 +762,7 @@ WarpX::InitPML () do_moving_window, pml_has_particles, do_pml_in_domain, psatd_solution_type, J_in_time, rho_in_time, do_pml_dive_cleaning, do_pml_divb_cleaning, amrex::IntVect(0), amrex::IntVect(0), + eb_enabled, guard_cells.ng_FieldSolver.max(), v_particle_pml, do_pml_Lo[lev], do_pml_Hi[lev]); @@ -737,7 +833,7 @@ WarpX::computeMaxStepBoostAccelerator() { static_cast(interaction_time_boost/dt[maxLevel()]); max_step = computed_max_step; Print()<<"max_step computed in computeMaxStepBoostAccelerator: " - <PostRestart(); for (int lev = 0; lev <= maxLevel(); ++lev) { - LoadExternalFieldsFromFile(lev); + LoadExternalFields(lev); } } @@ -810,7 +906,6 @@ WarpX::InitLevelData (int lev, Real /*time*/) m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::default_zero; if ( is_B_ext_const && (lev <= maxlevel_extEMfield_init) ) { - Bfield_fp[lev][i]->setVal(m_p_ext_field_params->B_external_grid[i]); if (fft_do_time_averaging) { Bfield_avg_fp[lev][i]->setVal(m_p_ext_field_params->B_external_grid[i]); } @@ -831,7 +926,6 @@ WarpX::InitLevelData (int lev, Real /*time*/) m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::default_zero; if ( is_E_ext_const && (lev <= maxlevel_extEMfield_init) ) { - Efield_fp[lev][i]->setVal(m_p_ext_field_params->E_external_grid[i]); if (fft_do_time_averaging) { Efield_avg_fp[lev][i]->setVal(m_p_ext_field_params->E_external_grid[i]); } @@ -847,7 +941,8 @@ WarpX::InitLevelData (int lev, Real /*time*/) } #ifdef AMREX_USE_EB - InitializeEBGridData(lev); + bool const eb_enabled = EB::enabled(); + if (eb_enabled) { InitializeEBGridData(lev); } #endif // if the input string for the B-field is "parse_b_ext_grid_function", @@ -856,13 +951,12 @@ WarpX::InitLevelData (int lev, Real /*time*/) // Externally imposed fields are only initialized until the user-defined maxlevel_extEMfield_init. // The default maxlevel_extEMfield_init value is the total number of levels in the simulation if ((m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::parse_ext_grid_function) - && (lev <= maxlevel_extEMfield_init)) { + && (lev > 0) && (lev <= maxlevel_extEMfield_init)) { - // Initialize Bfield_fp with external function InitializeExternalFieldsOnGridUsingParser( - Bfield_fp[lev][0].get(), - Bfield_fp[lev][1].get(), - Bfield_fp[lev][2].get(), + Bfield_aux[lev][0].get(), + Bfield_aux[lev][1].get(), + Bfield_aux[lev][2].get(), m_p_ext_field_params->Bxfield_parser->compile<3>(), m_p_ext_field_params->Byfield_parser->compile<3>(), m_p_ext_field_params->Bzfield_parser->compile<3>(), @@ -871,31 +965,17 @@ WarpX::InitLevelData (int lev, Real /*time*/) 'B', lev, PatchType::fine); - if (lev > 0) { - InitializeExternalFieldsOnGridUsingParser( - Bfield_aux[lev][0].get(), - Bfield_aux[lev][1].get(), - Bfield_aux[lev][2].get(), - m_p_ext_field_params->Bxfield_parser->compile<3>(), - m_p_ext_field_params->Byfield_parser->compile<3>(), - m_p_ext_field_params->Bzfield_parser->compile<3>(), - m_edge_lengths[lev], - m_face_areas[lev], - 'B', - lev, PatchType::fine); - - InitializeExternalFieldsOnGridUsingParser( - Bfield_cp[lev][0].get(), - Bfield_cp[lev][1].get(), - Bfield_cp[lev][2].get(), - m_p_ext_field_params->Bxfield_parser->compile<3>(), - m_p_ext_field_params->Byfield_parser->compile<3>(), - m_p_ext_field_params->Bzfield_parser->compile<3>(), - m_edge_lengths[lev], - m_face_areas[lev], - 'B', - lev, PatchType::coarse); - } + InitializeExternalFieldsOnGridUsingParser( + Bfield_cp[lev][0].get(), + Bfield_cp[lev][1].get(), + Bfield_cp[lev][2].get(), + m_p_ext_field_params->Bxfield_parser->compile<3>(), + m_p_ext_field_params->Byfield_parser->compile<3>(), + m_p_ext_field_params->Bzfield_parser->compile<3>(), + m_edge_lengths[lev], + m_face_areas[lev], + 'B', + lev, PatchType::coarse); } // if the input string for the E-field is "parse_e_ext_grid_function", @@ -906,25 +986,14 @@ WarpX::InitLevelData (int lev, Real /*time*/) if ((m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::parse_ext_grid_function) && (lev <= maxlevel_extEMfield_init)) { - // Initialize Efield_fp with external function - InitializeExternalFieldsOnGridUsingParser( - Efield_fp[lev][0].get(), - Efield_fp[lev][1].get(), - Efield_fp[lev][2].get(), - m_p_ext_field_params->Exfield_parser->compile<3>(), - m_p_ext_field_params->Eyfield_parser->compile<3>(), - m_p_ext_field_params->Ezfield_parser->compile<3>(), - m_edge_lengths[lev], - m_face_areas[lev], - 'E', - lev, PatchType::fine); - #ifdef AMREX_USE_EB - // We initialize ECTRhofield consistently with the Efield - if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { - m_fdtd_solver_fp[lev]->EvolveECTRho( - Efield_fp[lev], m_edge_lengths[lev], - m_face_areas[lev], ECTRhofield[lev], lev); + if (eb_enabled) { + // We initialize ECTRhofield consistently with the Efield + if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { + m_fdtd_solver_fp[lev]->EvolveECTRho( + Efield_fp[lev], m_edge_lengths[lev], + m_face_areas[lev], ECTRhofield[lev], lev); + } } #endif @@ -953,17 +1022,20 @@ WarpX::InitLevelData (int lev, Real /*time*/) 'E', lev, PatchType::coarse); #ifdef AMREX_USE_EB - if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { - // We initialize ECTRhofield consistently with the Efield - m_fdtd_solver_cp[lev]->EvolveECTRho(Efield_cp[lev], m_edge_lengths[lev], - m_face_areas[lev], ECTRhofield[lev], lev); + if (eb_enabled) { + if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { + // We initialize ECTRhofield consistently with the Efield + m_fdtd_solver_cp[lev]->EvolveECTRho(Efield_cp[lev], m_edge_lengths[lev], + m_face_areas[lev], ECTRhofield[lev], lev); + } } #endif } } - LoadExternalFieldsFromFile(lev); + // load external grid fields into E/Bfield_fp_external multifabs + LoadExternalFields(lev); if (costs[lev]) { const auto iarr = costs[lev]->IndexArray(); @@ -981,7 +1053,7 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( ParserExecutor<3> const& zfield_parser, std::array< std::unique_ptr, 3 > const& edge_lengths, std::array< std::unique_ptr, 3 > const& face_areas, - const char field, + [[maybe_unused]] const char field, const int lev, PatchType patch_type) { @@ -997,49 +1069,47 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( const amrex::IntVect y_nodal_flag = mfy->ixType().toIntVect(); const amrex::IntVect z_nodal_flag = mfz->ixType().toIntVect(); - for ( MFIter mfi(*mfx, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const amrex::Box& tbx = mfi.tilebox( x_nodal_flag, mfx->nGrowVect() ); - const amrex::Box& tby = mfi.tilebox( y_nodal_flag, mfy->nGrowVect() ); - const amrex::Box& tbz = mfi.tilebox( z_nodal_flag, mfz->nGrowVect() ); - - auto const& mfxfab = mfx->array(mfi); - auto const& mfyfab = mfy->array(mfi); - auto const& mfzfab = mfz->array(mfi); - -#ifdef AMREX_USE_EB - amrex::Array4 const& lx = edge_lengths[0]->array(mfi); - amrex::Array4 const& ly = edge_lengths[1]->array(mfi); - amrex::Array4 const& lz = edge_lengths[2]->array(mfi); - amrex::Array4 const& Sx = face_areas[0]->array(mfi); - amrex::Array4 const& Sy = face_areas[1]->array(mfi); - amrex::Array4 const& Sz = face_areas[2]->array(mfi); + bool const eb_enabled = EB::enabled(); + + for ( MFIter mfi(*mfx, TilingIfNotGPU()); mfi.isValid(); ++mfi) { + const amrex::Box &tbx = mfi.tilebox(x_nodal_flag, mfx->nGrowVect()); + const amrex::Box &tby = mfi.tilebox(y_nodal_flag, mfy->nGrowVect()); + const amrex::Box &tbz = mfi.tilebox(z_nodal_flag, mfz->nGrowVect()); + + auto const &mfxfab = mfx->array(mfi); + auto const &mfyfab = mfy->array(mfi); + auto const &mfzfab = mfz->array(mfi); + + amrex::Array4 lx, ly, lz, Sx, Sy, Sz; + if (eb_enabled) { + lx = edge_lengths[0]->array(mfi); + ly = edge_lengths[1]->array(mfi); + lz = edge_lengths[2]->array(mfi); + Sx = face_areas[0]->array(mfi); + Sy = face_areas[1]->array(mfi); + Sz = face_areas[2]->array(mfi); + } #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const amrex::Dim3 lx_lo = amrex::lbound(lx); - const amrex::Dim3 lx_hi = amrex::ubound(lx); - const amrex::Dim3 lz_lo = amrex::lbound(lz); - const amrex::Dim3 lz_hi = amrex::ubound(lz); + amrex::Dim3 lx_lo, lx_hi, lz_lo, lz_hi; #endif - + if (eb_enabled) { #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ignore_unused(ly, Sx, Sz); -#elif defined(WARPX_DIM_1D_Z) - amrex::ignore_unused(lx, ly, lz, Sx, Sy, Sz); -#endif - -#else - amrex::ignore_unused(edge_lengths, face_areas, field); + lx_lo = amrex::lbound(lx); + lx_hi = amrex::ubound(lx); + lz_lo = amrex::lbound(lz); + lz_hi = amrex::ubound(lz); #endif + } amrex::ParallelFor (tbx, tby, tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k) { #ifdef AMREX_USE_EB #ifdef WARPX_DIM_3D - if((field=='E' and lx(i, j, k)<=0) or (field=='B' and Sx(i, j, k)<=0)) return; + if(lx && ((field=='E' and lx(i, j, k)<=0) or (field=='B' and Sx(i, j, k)<=0))) { return; } #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) //In XZ and RZ Ex is associated with a x-edge, while Bx is associated with a z-edge - if((field=='E' and lx(i, j, k)<=0) or (field=='B' and lz(i, j, k)<=0)) return; + if(lx && ((field=='E' and lx(i, j, k)<=0) or (field=='B' and lz(i, j, k)<=0))) { return; } #endif #endif // Shift required in the x-, y-, or z- position @@ -1069,14 +1139,15 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( [=] AMREX_GPU_DEVICE (int i, int j, int k) { #ifdef AMREX_USE_EB #ifdef WARPX_DIM_3D - if((field=='E' and ly(i, j, k)<=0) or (field=='B' and Sy(i, j, k)<=0)) return; + if(ly && ((field=='E' and ly(i, j, k)<=0) or (field=='B' and Sy(i, j, k)<=0))) { return; } #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) //In XZ and RZ Ey is associated with a mesh node, so we need to check if the mesh node is covered - if((field=='E' and (lx(std::min(i , lx_hi.x), std::min(j , lx_hi.y), k)<=0 + if(lx && + ((field=='E' and (lx(std::min(i , lx_hi.x), std::min(j , lx_hi.y), k)<=0 || lx(std::max(i-1, lx_lo.x), std::min(j , lx_hi.y), k)<=0 || lz(std::min(i , lz_hi.x), std::min(j , lz_hi.y), k)<=0 || lz(std::min(i , lz_hi.x), std::max(j-1, lz_lo.y), k)<=0)) or - (field=='B' and Sy(i,j,k)<=0)) return; + (field=='B' and Sy(i,j,k)<=0))) { return; } #endif #endif #if defined(WARPX_DIM_1D_Z) @@ -1104,10 +1175,10 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( [=] AMREX_GPU_DEVICE (int i, int j, int k) { #ifdef AMREX_USE_EB #ifdef WARPX_DIM_3D - if((field=='E' and lz(i, j, k)<=0) or (field=='B' and Sz(i, j, k)<=0)) return; + if(lz && ((field=='E' and lz(i, j, k)<=0) or (field=='B' and Sz(i, j, k)<=0))) { return; } #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) //In XZ and RZ Ez is associated with a z-edge, while Bz is associated with a x-edge - if((field=='E' and lz(i, j, k)<=0) or (field=='B' and lx(i, j, k)<=0)) return; + if(lz && ((field=='E' and lz(i, j, k)<=0) or (field=='B' and lx(i, j, k)<=0))) { return; } #endif #endif #if defined(WARPX_DIM_1D_Z) @@ -1136,73 +1207,6 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( } } -void -WarpX::PerformanceHints () -{ - // Check requested MPI ranks and available boxes - amrex::Long total_nboxes = 0; // on all MPI ranks - for (int ilev = 0; ilev <= finestLevel(); ++ilev) { - total_nboxes += boxArray(ilev).size(); - } - auto const nprocs = ParallelDescriptor::NProcs(); - - // Check: are there more MPI ranks than Boxes? - if (nprocs > total_nboxes) { - std::stringstream warnMsg; - warnMsg << "Too many resources / too little work!\n" - << " It looks like you requested more compute resources than " - << "there are total number of boxes of cells available (" - << total_nboxes << "). " - << "You started with (" << nprocs - << ") MPI ranks, so (" << nprocs - total_nboxes - << ") rank(s) will have no work.\n" -#ifdef AMREX_USE_GPU - << " On GPUs, consider using 1-8 boxes per GPU that together fill " - << "each GPU's memory sufficiently. If you do not rely on dynamic " - << "load-balancing, then one large box per GPU is ideal.\n" -#endif - << "Consider decreasing the amr.blocking_factor and " - << "amr.max_grid_size parameters and/or using fewer MPI ranks.\n" - << " More information:\n" - << " https://warpx.readthedocs.io/en/latest/usage/workflows/parallelization.html\n"; - - ablastr::warn_manager::WMRecordWarning( - "Performance", warnMsg.str(), ablastr::warn_manager::WarnPriority::high); - } - -#ifdef AMREX_USE_GPU - // Check: Are there more than 12 boxes per GPU? - if (total_nboxes > nprocs * 12) { - std::stringstream warnMsg; - warnMsg << "Too many boxes per GPU!\n" - << " It looks like you split your simulation domain " - << "in too many boxes (" << total_nboxes << "), which " - << "results in an average number of (" - << amrex::Long(total_nboxes/nprocs) << ") per GPU. " - << "This causes severe overhead in the communication of " - << "border/guard regions.\n" - << " On GPUs, consider using 1-8 boxes per GPU that together fill " - << "each GPU's memory sufficiently. If you do not rely on dynamic " - << "load-balancing, then one large box per GPU is ideal.\n" - << "Consider increasing the amr.blocking_factor and " - << "amr.max_grid_size parameters and/or using more MPI ranks.\n" - << " More information:\n" - << " https://warpx.readthedocs.io/en/latest/usage/workflows/parallelization.html\n"; - - ablastr::warn_manager::WMRecordWarning( - "Performance", warnMsg.str(), ablastr::warn_manager::WarnPriority::high); - } -#endif - - // TODO: warn if some ranks have disproportionally more work than all others - // tricky: it can be ok to assign "vacuum" boxes to some ranks w/o slowing down - // all other ranks; we need to measure this with our load-balancing - // routines and issue a warning only of some ranks stall all other ranks - // TODO: check MPI-rank to GPU ratio (should be 1:1) - // TODO: check memory per MPI rank, especially if GPUs are underutilized - // TODO: CPU tiling hints with OpenMP -} - void WarpX::CheckGuardCells() { for (int lev = 0; lev <= finest_level; ++lev) @@ -1275,9 +1279,7 @@ void WarpX::InitializeEBGridData (int lev) if (lev == maxLevel()) { // Throw a warning if EB is on and particle_shape > 1 - bool flag_eb_on = not fieldEBFactory(lev).isAllRegular(); - - if ((nox > 1 or noy > 1 or noz > 1) and flag_eb_on) + if ((nox > 1 or noy > 1 or noz > 1) and EB::enabled()) { ablastr::warn_manager::WMRecordWarning("Particles", "when algo.particle_shape > 1, numerical artifacts will be present when\n" @@ -1354,7 +1356,7 @@ void WarpX::CheckKnownIssues() } void -WarpX::LoadExternalFieldsFromFile (int const lev) +WarpX::LoadExternalFields (int const lev) { // External fields from file are currently not compatible with the moving window // In order to support the moving window, the MultiFab containing the external @@ -1370,8 +1372,21 @@ WarpX::LoadExternalFieldsFromFile (int const lev) } // External grid fields - - if (m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::read_from_file) { + if (m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::parse_ext_grid_function) { + // Initialize Bfield_fp_external with external function + InitializeExternalFieldsOnGridUsingParser( + Bfield_fp_external[lev][0].get(), + Bfield_fp_external[lev][1].get(), + Bfield_fp_external[lev][2].get(), + m_p_ext_field_params->Bxfield_parser->compile<3>(), + m_p_ext_field_params->Byfield_parser->compile<3>(), + m_p_ext_field_params->Bzfield_parser->compile<3>(), + m_edge_lengths[lev], + m_face_areas[lev], + 'B', + lev, PatchType::fine); + } + else if (m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::read_from_file) { #if defined(WARPX_DIM_RZ) WARPX_ALWAYS_ASSERT_WITH_MESSAGE(n_rz_azimuthal_modes == 1, "External field reading is not implemented for more than one RZ mode (see #3829)"); @@ -1384,7 +1399,22 @@ WarpX::LoadExternalFieldsFromFile (int const lev) ReadExternalFieldFromFile(m_p_ext_field_params->external_fields_path, Bfield_fp_external[lev][2].get(), "B", "z"); #endif } - if (m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::read_from_file) { + + if (m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::parse_ext_grid_function) { + // Initialize Efield_fp_external with external function + InitializeExternalFieldsOnGridUsingParser( + Efield_fp_external[lev][0].get(), + Efield_fp_external[lev][1].get(), + Efield_fp_external[lev][2].get(), + m_p_ext_field_params->Exfield_parser->compile<3>(), + m_p_ext_field_params->Eyfield_parser->compile<3>(), + m_p_ext_field_params->Ezfield_parser->compile<3>(), + m_edge_lengths[lev], + m_face_areas[lev], + 'E', + lev, PatchType::fine); + } + else if (m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::read_from_file) { #if defined(WARPX_DIM_RZ) WARPX_ALWAYS_ASSERT_WITH_MESSAGE(n_rz_azimuthal_modes == 1, "External field reading is not implemented for more than one RZ mode (see #3829)"); @@ -1398,6 +1428,10 @@ WarpX::LoadExternalFieldsFromFile (int const lev) #endif } + if (lev == finestLevel()) { + // Call Python callback which might write values to external field multifabs + ExecutePythonCallback("loadExternalFields"); + } // External particle fields if (mypc->m_B_ext_particle_s == "read_from_file") { diff --git a/Source/Make.WarpX b/Source/Make.WarpX index 502cb8a6714..57bac56e9a4 100644 --- a/Source/Make.WarpX +++ b/Source/Make.WarpX @@ -183,6 +183,8 @@ ifeq ($(USE_FFT),TRUE) INCLUDE_LOCATIONS += $(ROC_PATH)/rocfft/include LIBRARY_LOCATIONS += $(ROC_PATH)/rocfft/lib libraries += -lrocfft + else ifeq ($(USE_SYCL),TRUE) + # nothing else # Running on CPU # Use FFTW ifeq ($(PRECISION),FLOAT) diff --git a/Source/NonlinearSolvers/JacobianFunctionMF.H b/Source/NonlinearSolvers/JacobianFunctionMF.H index 823523df23c..d5c2b6cbac9 100644 --- a/Source/NonlinearSolvers/JacobianFunctionMF.H +++ b/Source/NonlinearSolvers/JacobianFunctionMF.H @@ -21,8 +21,8 @@ class JacobianFunctionMF using RT = typename T::value_type; - JacobianFunctionMF() = default; - ~JacobianFunctionMF() = default; + JacobianFunctionMF() = default; + ~JacobianFunctionMF() = default; // Default move and copy operations JacobianFunctionMF(const JacobianFunctionMF&) = default; diff --git a/Source/NonlinearSolvers/NewtonSolver.H b/Source/NonlinearSolvers/NewtonSolver.H index 93ad432208a..742e139a5f5 100644 --- a/Source/NonlinearSolvers/NewtonSolver.H +++ b/Source/NonlinearSolvers/NewtonSolver.H @@ -28,9 +28,9 @@ class NewtonSolver : public NonlinearSolver { public: - NewtonSolver() = default; + NewtonSolver() = default; - ~NewtonSolver() override = default; + ~NewtonSolver() override = default; // Prohibit Move and Copy operations NewtonSolver(const NewtonSolver&) = delete; @@ -69,16 +69,16 @@ public: void PrintParams () const override { - amrex::Print() << "Newton verbose: " << (this->m_verbose?"true":"false") << std::endl; - amrex::Print() << "Newton max iterations: " << m_maxits << std::endl; - amrex::Print() << "Newton relative tolerance: " << m_rtol << std::endl; - amrex::Print() << "Newton absolute tolerance: " << m_atol << std::endl; - amrex::Print() << "Newton require convergence: " << (m_require_convergence?"true":"false") << std::endl; - amrex::Print() << "GMRES verbose: " << m_gmres_verbose_int << std::endl; - amrex::Print() << "GMRES restart length: " << m_gmres_restart_length << std::endl; - amrex::Print() << "GMRES max iterations: " << m_gmres_maxits << std::endl; - amrex::Print() << "GMRES relative tolerance: " << m_gmres_rtol << std::endl; - amrex::Print() << "GMRES absolute tolerance: " << m_gmres_atol << std::endl; + amrex::Print() << "Newton verbose: " << (this->m_verbose?"true":"false") << "\n"; + amrex::Print() << "Newton max iterations: " << m_maxits << "\n"; + amrex::Print() << "Newton relative tolerance: " << m_rtol << "\n"; + amrex::Print() << "Newton absolute tolerance: " << m_atol << "\n"; + amrex::Print() << "Newton require convergence: " << (m_require_convergence?"true":"false") << "\n"; + amrex::Print() << "GMRES verbose: " << m_gmres_verbose_int << "\n"; + amrex::Print() << "GMRES restart length: " << m_gmres_restart_length << "\n"; + amrex::Print() << "GMRES max iterations: " << m_gmres_maxits << "\n"; + amrex::Print() << "GMRES relative tolerance: " << m_gmres_rtol << "\n"; + amrex::Print() << "GMRES absolute tolerance: " << m_gmres_atol << "\n"; } private: @@ -261,19 +261,19 @@ void NewtonSolver::Solve ( Vec& a_U, if (norm_abs < m_rtol) { amrex::Print() << "Newton: exiting at iteration = " << std::setw(3) << iter - << ". Satisfied absolute tolerance " << m_atol << std::endl; + << ". Satisfied absolute tolerance " << m_atol << "\n"; break; } if (norm_rel < m_rtol) { amrex::Print() << "Newton: exiting at iteration = " << std::setw(3) << iter - << ". Satisfied relative tolerance " << m_rtol << std::endl; + << ". Satisfied relative tolerance " << m_rtol << "\n"; break; } if (norm_abs > 100._rt*norm0) { amrex::Print() << "Newton: exiting at iteration = " << std::setw(3) << iter - << ". SOLVER DIVERGED! relative tolerance = " << m_rtol << std::endl; + << ". SOLVER DIVERGED! relative tolerance = " << m_rtol << "\n"; std::stringstream convergenceMsg; convergenceMsg << "Newton: exiting at iteration " << std::setw(3) << iter << ". SOLVER DIVERGED! absolute norm = " << norm_abs << @@ -291,7 +291,7 @@ void NewtonSolver::Solve ( Vec& a_U, iter++; if (iter >= m_maxits) { amrex::Print() << "Newton: exiting at iter = " << std::setw(3) << iter - << ". Maximum iteration reached: iter = " << m_maxits << std::endl; + << ". Maximum iteration reached: iter = " << m_maxits << "\n"; break; } diff --git a/Source/NonlinearSolvers/NonlinearSolver.H b/Source/NonlinearSolvers/NonlinearSolver.H index 5587826474c..6e64f1eb113 100644 --- a/Source/NonlinearSolvers/NonlinearSolver.H +++ b/Source/NonlinearSolvers/NonlinearSolver.H @@ -28,9 +28,9 @@ class NonlinearSolver { public: - NonlinearSolver() = default; + NonlinearSolver() = default; - virtual ~NonlinearSolver() = default; + virtual ~NonlinearSolver() = default; // Prohibit Move and Copy operations NonlinearSolver(const NonlinearSolver&) = delete; diff --git a/Source/NonlinearSolvers/PicardSolver.H b/Source/NonlinearSolvers/PicardSolver.H index f05b9a106e6..f6c47c4f4bc 100644 --- a/Source/NonlinearSolvers/PicardSolver.H +++ b/Source/NonlinearSolvers/PicardSolver.H @@ -26,9 +26,9 @@ class PicardSolver : public NonlinearSolver { public: - PicardSolver() = default; + PicardSolver() = default; - ~PicardSolver() override = default; + ~PicardSolver() override = default; // Prohibit Move and Copy operations PicardSolver(const PicardSolver&) = delete; @@ -55,10 +55,10 @@ public: void PrintParams () const override { - amrex::Print() << "Picard max iterations: " << m_maxits << std::endl; - amrex::Print() << "Picard relative tolerance: " << m_rtol << std::endl; - amrex::Print() << "Picard absolute tolerance: " << m_atol << std::endl; - amrex::Print() << "Picard require convergence: " << (m_require_convergence?"true":"false") << std::endl; + amrex::Print() << "Picard max iterations: " << m_maxits << "\n"; + amrex::Print() << "Picard relative tolerance: " << m_rtol << "\n"; + amrex::Print() << "Picard absolute tolerance: " << m_atol << "\n"; + amrex::Print() << "Picard require convergence: " << (m_require_convergence?"true":"false") << "\n"; } private: @@ -179,19 +179,19 @@ void PicardSolver::Solve ( Vec& a_U, if (norm_abs < m_atol) { amrex::Print() << "Picard: exiting at iter = " << std::setw(3) << iter - << ". Satisfied absolute tolerance " << m_atol << std::endl; + << ". Satisfied absolute tolerance " << m_atol << "\n"; break; } if (norm_rel < m_rtol) { amrex::Print() << "Picard: exiting at iter = " << std::setw(3) << iter - << ". Satisfied relative tolerance " << m_rtol << std::endl; + << ". Satisfied relative tolerance " << m_rtol << "\n"; break; } if (iter >= m_maxits) { amrex::Print() << "Picard: exiting at iter = " << std::setw(3) << iter - << ". Maximum iteration reached: iter = " << m_maxits << std::endl; + << ". Maximum iteration reached: iter = " << m_maxits << "\n"; break; } diff --git a/Source/Parallelization/GuardCellManager.H b/Source/Parallelization/GuardCellManager.H index 561456943f1..c9de3d8b250 100644 --- a/Source/Parallelization/GuardCellManager.H +++ b/Source/Parallelization/GuardCellManager.H @@ -7,6 +7,9 @@ #ifndef WARPX_GUARDCELLMANAGER_H_ #define WARPX_GUARDCELLMANAGER_H_ +#include +#include + #include #include #include @@ -55,13 +58,13 @@ public: const amrex::Real * dx, bool do_subcycling, bool do_fdtd_nci_corr, - short grid_type, + ablastr::utils::enums::GridType grid_type, bool do_moving_window, int moving_window_dir, int nox, int nox_fft, int noy_fft, int noz_fft, int nci_corr_stencil, - int electromagnetic_solver_id, + ElectromagneticSolverAlgo electromagnetic_solver_id, int max_level, const amrex::Vector& v_galilean, const amrex::Vector& v_comoving, diff --git a/Source/Parallelization/GuardCellManager.cpp b/Source/Parallelization/GuardCellManager.cpp index bf010736853..a36e39d9497 100644 --- a/Source/Parallelization/GuardCellManager.cpp +++ b/Source/Parallelization/GuardCellManager.cpp @@ -36,13 +36,13 @@ guardCellManager::Init ( const amrex::Real *dx, const bool do_subcycling, const bool do_fdtd_nci_corr, - const short grid_type, + ablastr::utils::enums::GridType grid_type, const bool do_moving_window, const int moving_window_dir, const int nox, const int nox_fft, const int noy_fft, const int noz_fft, const int nci_corr_stencil, - const int electromagnetic_solver_id, + const ElectromagneticSolverAlgo electromagnetic_solver_id, const int max_level, const amrex::Vector& v_galilean, const amrex::Vector& v_comoving, @@ -101,9 +101,9 @@ guardCellManager::Init ( // the fine grid by a number of cells equal to the ref_ratio in the moving // window direction. if (do_moving_window) { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(ref_ratios.size() <= 1, + WARPX_ALWAYS_ASSERT_WITH_MESSAGE(max_level <= 1, "The number of grow cells for the moving window currently assumes 2 levels max."); - const auto nlevs = static_cast(ref_ratios.size()+1); + const auto nlevs = static_cast(max_level+1); const int max_r = (nlevs > 1) ? ref_ratios[0][moving_window_dir] : 2; ngx = std::max(ngx,max_r); @@ -200,6 +200,7 @@ guardCellManager::Init ( // currents in the latter case). This does not seem to be necessary in x and y, // where it still seems fine to set half the number of guard cells of the nodal case. + using namespace ablastr::utils::enums; int ngFFt_x = (grid_type == GridType::Collocated) ? nox_fft : nox_fft / 2; int ngFFt_y = (grid_type == GridType::Collocated) ? noy_fft : noy_fft / 2; int ngFFt_z = (grid_type == GridType::Collocated || galilean) ? noz_fft : noz_fft / 2; diff --git a/Source/Parallelization/WarpXComm.cpp b/Source/Parallelization/WarpXComm.cpp index e7df489236e..6c44df061fd 100644 --- a/Source/Parallelization/WarpXComm.cpp +++ b/Source/Parallelization/WarpXComm.cpp @@ -171,136 +171,191 @@ WarpX::UpdateAuxilaryDataStagToNodal () // Bfield { - Array,3> Btmp; - if (Bfield_cax[lev][0]) { - for (int i = 0; i < 3; ++i) { - Btmp[i] = std::make_unique( - *Bfield_cax[lev][i], amrex::make_alias, 0, 1); + if (electromagnetic_solver_id != ElectromagneticSolverAlgo::None) { + Array,3> Btmp; + if (Bfield_cax[lev][0]) { + for (int i = 0; i < 3; ++i) { + Btmp[i] = std::make_unique( + *Bfield_cax[lev][i], amrex::make_alias, 0, 1); + } + } else { + const IntVect ngtmp = Bfield_aux[lev-1][0]->nGrowVect(); + for (int i = 0; i < 3; ++i) { + Btmp[i] = std::make_unique(cnba, dm, 1, ngtmp); + } } - } else { - const IntVect ngtmp = Bfield_aux[lev-1][0]->nGrowVect(); + Btmp[0]->setVal(0.0); + Btmp[1]->setVal(0.0); + Btmp[2]->setVal(0.0); + // ParallelCopy from coarse level for (int i = 0; i < 3; ++i) { - Btmp[i] = std::make_unique(cnba, dm, 1, ngtmp); + const IntVect ng = Btmp[i]->nGrowVect(); + // Guard cells may not be up to date beyond ng_FieldGather + const amrex::IntVect& ng_src = guard_cells.ng_FieldGather; + // Copy Bfield_aux to Btmp, using up to ng_src (=ng_FieldGather) guard cells from + // Bfield_aux and filling up to ng (=nGrow) guard cells in Btmp + ablastr::utils::communication::ParallelCopy(*Btmp[i], *Bfield_aux[lev - 1][i], 0, 0, 1, + ng_src, ng, WarpX::do_single_precision_comms, cperiod); } - } - Btmp[0]->setVal(0.0); - Btmp[1]->setVal(0.0); - Btmp[2]->setVal(0.0); - // ParallelCopy from coarse level - for (int i = 0; i < 3; ++i) { - const IntVect ng = Btmp[i]->nGrowVect(); - // Guard cells may not be up to date beyond ng_FieldGather - const amrex::IntVect& ng_src = guard_cells.ng_FieldGather; - // Copy Bfield_aux to Btmp, using up to ng_src (=ng_FieldGather) guard cells from - // Bfield_aux and filling up to ng (=nGrow) guard cells in Btmp - ablastr::utils::communication::ParallelCopy(*Btmp[i], *Bfield_aux[lev - 1][i], 0, 0, 1, - ng_src, ng, WarpX::do_single_precision_comms, cperiod); - } - const amrex::IntVect& refinement_ratio = refRatio(lev-1); + const amrex::IntVect& refinement_ratio = refRatio(lev-1); - const amrex::IntVect& Bx_fp_stag = Bfield_fp[lev][0]->ixType().toIntVect(); - const amrex::IntVect& By_fp_stag = Bfield_fp[lev][1]->ixType().toIntVect(); - const amrex::IntVect& Bz_fp_stag = Bfield_fp[lev][2]->ixType().toIntVect(); + const amrex::IntVect& Bx_fp_stag = Bfield_fp[lev][0]->ixType().toIntVect(); + const amrex::IntVect& By_fp_stag = Bfield_fp[lev][1]->ixType().toIntVect(); + const amrex::IntVect& Bz_fp_stag = Bfield_fp[lev][2]->ixType().toIntVect(); - const amrex::IntVect& Bx_cp_stag = Bfield_cp[lev][0]->ixType().toIntVect(); - const amrex::IntVect& By_cp_stag = Bfield_cp[lev][1]->ixType().toIntVect(); - const amrex::IntVect& Bz_cp_stag = Bfield_cp[lev][2]->ixType().toIntVect(); + const amrex::IntVect& Bx_cp_stag = Bfield_cp[lev][0]->ixType().toIntVect(); + const amrex::IntVect& By_cp_stag = Bfield_cp[lev][1]->ixType().toIntVect(); + const amrex::IntVect& Bz_cp_stag = Bfield_cp[lev][2]->ixType().toIntVect(); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(*Bfield_aux[lev][0], TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - Array4 const& bx_aux = Bfield_aux[lev][0]->array(mfi); - Array4 const& by_aux = Bfield_aux[lev][1]->array(mfi); - Array4 const& bz_aux = Bfield_aux[lev][2]->array(mfi); - Array4 const& bx_fp = Bfield_fp[lev][0]->const_array(mfi); - Array4 const& by_fp = Bfield_fp[lev][1]->const_array(mfi); - Array4 const& bz_fp = Bfield_fp[lev][2]->const_array(mfi); - Array4 const& bx_cp = Bfield_cp[lev][0]->const_array(mfi); - Array4 const& by_cp = Bfield_cp[lev][1]->const_array(mfi); - Array4 const& bz_cp = Bfield_cp[lev][2]->const_array(mfi); - Array4 const& bx_c = Btmp[0]->const_array(mfi); - Array4 const& by_c = Btmp[1]->const_array(mfi); - Array4 const& bz_c = Btmp[2]->const_array(mfi); - - const Box& bx = mfi.growntilebox(); - amrex::ParallelFor(bx, - [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + for (MFIter mfi(*Bfield_aux[lev][0], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - warpx_interp(j, k, l, bx_aux, bx_fp, bx_cp, bx_c, Bx_fp_stag, Bx_cp_stag, refinement_ratio); - warpx_interp(j, k, l, by_aux, by_fp, by_cp, by_c, By_fp_stag, By_cp_stag, refinement_ratio); - warpx_interp(j, k, l, bz_aux, bz_fp, bz_cp, bz_c, Bz_fp_stag, Bz_cp_stag, refinement_ratio); - }); + Array4 const& bx_aux = Bfield_aux[lev][0]->array(mfi); + Array4 const& by_aux = Bfield_aux[lev][1]->array(mfi); + Array4 const& bz_aux = Bfield_aux[lev][2]->array(mfi); + Array4 const& bx_fp = Bfield_fp[lev][0]->const_array(mfi); + Array4 const& by_fp = Bfield_fp[lev][1]->const_array(mfi); + Array4 const& bz_fp = Bfield_fp[lev][2]->const_array(mfi); + Array4 const& bx_cp = Bfield_cp[lev][0]->const_array(mfi); + Array4 const& by_cp = Bfield_cp[lev][1]->const_array(mfi); + Array4 const& bz_cp = Bfield_cp[lev][2]->const_array(mfi); + Array4 const& bx_c = Btmp[0]->const_array(mfi); + Array4 const& by_c = Btmp[1]->const_array(mfi); + Array4 const& bz_c = Btmp[2]->const_array(mfi); + + const Box& bx = mfi.growntilebox(); + amrex::ParallelFor(bx, + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, bx_aux, bx_fp, bx_cp, bx_c, Bx_fp_stag, Bx_cp_stag, refinement_ratio); + warpx_interp(j, k, l, by_aux, by_fp, by_cp, by_c, By_fp_stag, By_cp_stag, refinement_ratio); + warpx_interp(j, k, l, bz_aux, bz_fp, bz_cp, bz_c, Bz_fp_stag, Bz_cp_stag, refinement_ratio); + }); + } + } + else { // electrostatic + const amrex::IntVect& Bx_fp_stag = Bfield_fp[lev][0]->ixType().toIntVect(); + const amrex::IntVect& By_fp_stag = Bfield_fp[lev][1]->ixType().toIntVect(); + const amrex::IntVect& Bz_fp_stag = Bfield_fp[lev][2]->ixType().toIntVect(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(*Bfield_aux[lev][0], TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + Array4 const& bx_aux = Bfield_aux[lev][0]->array(mfi); + Array4 const& by_aux = Bfield_aux[lev][1]->array(mfi); + Array4 const& bz_aux = Bfield_aux[lev][2]->array(mfi); + Array4 const& bx_fp = Bfield_fp[lev][0]->const_array(mfi); + Array4 const& by_fp = Bfield_fp[lev][1]->const_array(mfi); + Array4 const& bz_fp = Bfield_fp[lev][2]->const_array(mfi); + + const Box& bx = mfi.growntilebox(); + amrex::ParallelFor(bx, + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, bx_aux, bx_fp, Bx_fp_stag); + warpx_interp(j, k, l, by_aux, by_fp, By_fp_stag); + warpx_interp(j, k, l, bz_aux, bz_fp, Bz_fp_stag); + }); + } } } - // Efield { - Array,3> Etmp; - if (Efield_cax[lev][0]) { - for (int i = 0; i < 3; ++i) { - Etmp[i] = std::make_unique( - *Efield_cax[lev][i], amrex::make_alias, 0, 1); + if (electromagnetic_solver_id != ElectromagneticSolverAlgo::None) { + Array,3> Etmp; + if (Efield_cax[lev][0]) { + for (int i = 0; i < 3; ++i) { + Etmp[i] = std::make_unique( + *Efield_cax[lev][i], amrex::make_alias, 0, 1); + } + } else { + const IntVect ngtmp = Efield_aux[lev-1][0]->nGrowVect(); + for (int i = 0; i < 3; ++i) { + Etmp[i] = std::make_unique( + cnba, dm, 1, ngtmp); + } } - } else { - const IntVect ngtmp = Efield_aux[lev-1][0]->nGrowVect(); + Etmp[0]->setVal(0.0); + Etmp[1]->setVal(0.0); + Etmp[2]->setVal(0.0); + // ParallelCopy from coarse level for (int i = 0; i < 3; ++i) { - Etmp[i] = std::make_unique( - cnba, dm, 1, ngtmp); + const IntVect ng = Etmp[i]->nGrowVect(); + // Guard cells may not be up to date beyond ng_FieldGather + const amrex::IntVect& ng_src = guard_cells.ng_FieldGather; + // Copy Efield_aux to Etmp, using up to ng_src (=ng_FieldGather) guard cells from + // Efield_aux and filling up to ng (=nGrow) guard cells in Etmp + ablastr::utils::communication::ParallelCopy(*Etmp[i], *Efield_aux[lev - 1][i], 0, 0, 1, + ng_src, ng, WarpX::do_single_precision_comms, cperiod); } - } - Etmp[0]->setVal(0.0); - Etmp[1]->setVal(0.0); - Etmp[2]->setVal(0.0); - // ParallelCopy from coarse level - for (int i = 0; i < 3; ++i) { - const IntVect ng = Etmp[i]->nGrowVect(); - // Guard cells may not be up to date beyond ng_FieldGather - const amrex::IntVect& ng_src = guard_cells.ng_FieldGather; - // Copy Efield_aux to Etmp, using up to ng_src (=ng_FieldGather) guard cells from - // Efield_aux and filling up to ng (=nGrow) guard cells in Etmp - ablastr::utils::communication::ParallelCopy(*Etmp[i], *Efield_aux[lev - 1][i], 0, 0, 1, - ng_src, ng, WarpX::do_single_precision_comms, cperiod); - } - const amrex::IntVect& refinement_ratio = refRatio(lev-1); + const amrex::IntVect& refinement_ratio = refRatio(lev-1); - const amrex::IntVect& Ex_fp_stag = Efield_fp[lev][0]->ixType().toIntVect(); - const amrex::IntVect& Ey_fp_stag = Efield_fp[lev][1]->ixType().toIntVect(); - const amrex::IntVect& Ez_fp_stag = Efield_fp[lev][2]->ixType().toIntVect(); + const amrex::IntVect& Ex_fp_stag = Efield_fp[lev][0]->ixType().toIntVect(); + const amrex::IntVect& Ey_fp_stag = Efield_fp[lev][1]->ixType().toIntVect(); + const amrex::IntVect& Ez_fp_stag = Efield_fp[lev][2]->ixType().toIntVect(); - const amrex::IntVect& Ex_cp_stag = Efield_cp[lev][0]->ixType().toIntVect(); - const amrex::IntVect& Ey_cp_stag = Efield_cp[lev][1]->ixType().toIntVect(); - const amrex::IntVect& Ez_cp_stag = Efield_cp[lev][2]->ixType().toIntVect(); + const amrex::IntVect& Ex_cp_stag = Efield_cp[lev][0]->ixType().toIntVect(); + const amrex::IntVect& Ey_cp_stag = Efield_cp[lev][1]->ixType().toIntVect(); + const amrex::IntVect& Ez_cp_stag = Efield_cp[lev][2]->ixType().toIntVect(); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(*Efield_aux[lev][0]); mfi.isValid(); ++mfi) - { - Array4 const& ex_aux = Efield_aux[lev][0]->array(mfi); - Array4 const& ey_aux = Efield_aux[lev][1]->array(mfi); - Array4 const& ez_aux = Efield_aux[lev][2]->array(mfi); - Array4 const& ex_fp = Efield_fp[lev][0]->const_array(mfi); - Array4 const& ey_fp = Efield_fp[lev][1]->const_array(mfi); - Array4 const& ez_fp = Efield_fp[lev][2]->const_array(mfi); - Array4 const& ex_cp = Efield_cp[lev][0]->const_array(mfi); - Array4 const& ey_cp = Efield_cp[lev][1]->const_array(mfi); - Array4 const& ez_cp = Efield_cp[lev][2]->const_array(mfi); - Array4 const& ex_c = Etmp[0]->const_array(mfi); - Array4 const& ey_c = Etmp[1]->const_array(mfi); - Array4 const& ez_c = Etmp[2]->const_array(mfi); - - const Box& bx = mfi.fabbox(); - amrex::ParallelFor(bx, - [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + for (MFIter mfi(*Efield_aux[lev][0], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - warpx_interp(j, k, l, ex_aux, ex_fp, ex_cp, ex_c, Ex_fp_stag, Ex_cp_stag, refinement_ratio); - warpx_interp(j, k, l, ey_aux, ey_fp, ey_cp, ey_c, Ey_fp_stag, Ey_cp_stag, refinement_ratio); - warpx_interp(j, k, l, ez_aux, ez_fp, ez_cp, ez_c, Ez_fp_stag, Ez_cp_stag, refinement_ratio); - }); + Array4 const& ex_aux = Efield_aux[lev][0]->array(mfi); + Array4 const& ey_aux = Efield_aux[lev][1]->array(mfi); + Array4 const& ez_aux = Efield_aux[lev][2]->array(mfi); + Array4 const& ex_fp = Efield_fp[lev][0]->const_array(mfi); + Array4 const& ey_fp = Efield_fp[lev][1]->const_array(mfi); + Array4 const& ez_fp = Efield_fp[lev][2]->const_array(mfi); + Array4 const& ex_cp = Efield_cp[lev][0]->const_array(mfi); + Array4 const& ey_cp = Efield_cp[lev][1]->const_array(mfi); + Array4 const& ez_cp = Efield_cp[lev][2]->const_array(mfi); + Array4 const& ex_c = Etmp[0]->const_array(mfi); + Array4 const& ey_c = Etmp[1]->const_array(mfi); + Array4 const& ez_c = Etmp[2]->const_array(mfi); + + const Box& bx = mfi.growntilebox(); + amrex::ParallelFor(bx, + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, ex_aux, ex_fp, ex_cp, ex_c, Ex_fp_stag, Ex_cp_stag, refinement_ratio); + warpx_interp(j, k, l, ey_aux, ey_fp, ey_cp, ey_c, Ey_fp_stag, Ey_cp_stag, refinement_ratio); + warpx_interp(j, k, l, ez_aux, ez_fp, ez_cp, ez_c, Ez_fp_stag, Ez_cp_stag, refinement_ratio); + }); + } + } + else { // electrostatic + const amrex::IntVect& Ex_fp_stag = Efield_fp[lev][0]->ixType().toIntVect(); + const amrex::IntVect& Ey_fp_stag = Efield_fp[lev][1]->ixType().toIntVect(); + const amrex::IntVect& Ez_fp_stag = Efield_fp[lev][2]->ixType().toIntVect(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(*Efield_aux[lev][0], TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + Array4 const& ex_aux = Efield_aux[lev][0]->array(mfi); + Array4 const& ey_aux = Efield_aux[lev][1]->array(mfi); + Array4 const& ez_aux = Efield_aux[lev][2]->array(mfi); + Array4 const& ex_fp = Efield_fp[lev][0]->const_array(mfi); + Array4 const& ey_fp = Efield_fp[lev][1]->const_array(mfi); + Array4 const& ez_fp = Efield_fp[lev][2]->const_array(mfi); + + const Box& bx = mfi.growntilebox(); + amrex::ParallelFor(bx, + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, ex_aux, ex_fp, Ex_fp_stag); + warpx_interp(j, k, l, ey_aux, ey_fp, Ey_fp_stag); + warpx_interp(j, k, l, ez_aux, ez_fp, Ez_fp_stag); + }); + } } } } @@ -341,141 +396,158 @@ WarpX::UpdateAuxilaryDataSameType () // B field { - MultiFab dBx(Bfield_cp[lev][0]->boxArray(), dm, Bfield_cp[lev][0]->nComp(), ng); - MultiFab dBy(Bfield_cp[lev][1]->boxArray(), dm, Bfield_cp[lev][1]->nComp(), ng); - MultiFab dBz(Bfield_cp[lev][2]->boxArray(), dm, Bfield_cp[lev][2]->nComp(), ng); - dBx.setVal(0.0); - dBy.setVal(0.0); - dBz.setVal(0.0); - - // Copy Bfield_aux to the dB MultiFabs, using up to ng_src (=ng_FieldGather) guard - // cells from Bfield_aux and filling up to ng (=nGrow) guard cells in the dB MultiFabs - - ablastr::utils::communication::ParallelCopy(dBx, *Bfield_aux[lev - 1][0], 0, 0, - Bfield_aux[lev - 1][0]->nComp(), ng_src, ng, WarpX::do_single_precision_comms, - crse_period); - ablastr::utils::communication::ParallelCopy(dBy, *Bfield_aux[lev - 1][1], 0, 0, - Bfield_aux[lev - 1][1]->nComp(), ng_src, ng, WarpX::do_single_precision_comms, - crse_period); - ablastr::utils::communication::ParallelCopy(dBz, *Bfield_aux[lev - 1][2], 0, 0, - Bfield_aux[lev - 1][2]->nComp(), ng_src, ng, WarpX::do_single_precision_comms, - crse_period); - - if (Bfield_cax[lev][0]) + if (electromagnetic_solver_id != ElectromagneticSolverAlgo::None) { - MultiFab::Copy(*Bfield_cax[lev][0], dBx, 0, 0, Bfield_cax[lev][0]->nComp(), ng); - MultiFab::Copy(*Bfield_cax[lev][1], dBy, 0, 0, Bfield_cax[lev][1]->nComp(), ng); - MultiFab::Copy(*Bfield_cax[lev][2], dBz, 0, 0, Bfield_cax[lev][2]->nComp(), ng); - } - MultiFab::Subtract(dBx, *Bfield_cp[lev][0], 0, 0, Bfield_cp[lev][0]->nComp(), ng); - MultiFab::Subtract(dBy, *Bfield_cp[lev][1], 0, 0, Bfield_cp[lev][1]->nComp(), ng); - MultiFab::Subtract(dBz, *Bfield_cp[lev][2], 0, 0, Bfield_cp[lev][2]->nComp(), ng); + MultiFab dBx(Bfield_cp[lev][0]->boxArray(), dm, Bfield_cp[lev][0]->nComp(), ng); + MultiFab dBy(Bfield_cp[lev][1]->boxArray(), dm, Bfield_cp[lev][1]->nComp(), ng); + MultiFab dBz(Bfield_cp[lev][2]->boxArray(), dm, Bfield_cp[lev][2]->nComp(), ng); + dBx.setVal(0.0); + dBy.setVal(0.0); + dBz.setVal(0.0); + + // Copy Bfield_aux to the dB MultiFabs, using up to ng_src (=ng_FieldGather) guard + // cells from Bfield_aux and filling up to ng (=nGrow) guard cells in the dB MultiFabs + + ablastr::utils::communication::ParallelCopy(dBx, *Bfield_aux[lev - 1][0], 0, 0, + Bfield_aux[lev - 1][0]->nComp(), ng_src, ng, WarpX::do_single_precision_comms, + crse_period); + ablastr::utils::communication::ParallelCopy(dBy, *Bfield_aux[lev - 1][1], 0, 0, + Bfield_aux[lev - 1][1]->nComp(), ng_src, ng, WarpX::do_single_precision_comms, + crse_period); + ablastr::utils::communication::ParallelCopy(dBz, *Bfield_aux[lev - 1][2], 0, 0, + Bfield_aux[lev - 1][2]->nComp(), ng_src, ng, WarpX::do_single_precision_comms, + crse_period); + + if (Bfield_cax[lev][0]) + { + MultiFab::Copy(*Bfield_cax[lev][0], dBx, 0, 0, Bfield_cax[lev][0]->nComp(), ng); + MultiFab::Copy(*Bfield_cax[lev][1], dBy, 0, 0, Bfield_cax[lev][1]->nComp(), ng); + MultiFab::Copy(*Bfield_cax[lev][2], dBz, 0, 0, Bfield_cax[lev][2]->nComp(), ng); + } + MultiFab::Subtract(dBx, *Bfield_cp[lev][0], 0, 0, Bfield_cp[lev][0]->nComp(), ng); + MultiFab::Subtract(dBy, *Bfield_cp[lev][1], 0, 0, Bfield_cp[lev][1]->nComp(), ng); + MultiFab::Subtract(dBz, *Bfield_cp[lev][2], 0, 0, Bfield_cp[lev][2]->nComp(), ng); - const amrex::IntVect& refinement_ratio = refRatio(lev-1); + const amrex::IntVect& refinement_ratio = refRatio(lev-1); - const amrex::IntVect& Bx_stag = Bfield_aux[lev-1][0]->ixType().toIntVect(); - const amrex::IntVect& By_stag = Bfield_aux[lev-1][1]->ixType().toIntVect(); - const amrex::IntVect& Bz_stag = Bfield_aux[lev-1][2]->ixType().toIntVect(); + const amrex::IntVect& Bx_stag = Bfield_aux[lev-1][0]->ixType().toIntVect(); + const amrex::IntVect& By_stag = Bfield_aux[lev-1][1]->ixType().toIntVect(); + const amrex::IntVect& Bz_stag = Bfield_aux[lev-1][2]->ixType().toIntVect(); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(*Bfield_aux[lev][0]); mfi.isValid(); ++mfi) - { - Array4 const& bx_aux = Bfield_aux[lev][0]->array(mfi); - Array4 const& by_aux = Bfield_aux[lev][1]->array(mfi); - Array4 const& bz_aux = Bfield_aux[lev][2]->array(mfi); - Array4 const& bx_fp = Bfield_fp[lev][0]->const_array(mfi); - Array4 const& by_fp = Bfield_fp[lev][1]->const_array(mfi); - Array4 const& bz_fp = Bfield_fp[lev][2]->const_array(mfi); - Array4 const& bx_c = dBx.const_array(mfi); - Array4 const& by_c = dBy.const_array(mfi); - Array4 const& bz_c = dBz.const_array(mfi); - - amrex::ParallelFor(Box(bx_aux), Box(by_aux), Box(bz_aux), - [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept - { - warpx_interp(j, k, l, bx_aux, bx_fp, bx_c, Bx_stag, refinement_ratio); - }, - [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept - { - warpx_interp(j, k, l, by_aux, by_fp, by_c, By_stag, refinement_ratio); - }, - [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + for (MFIter mfi(*Bfield_aux[lev][0]); mfi.isValid(); ++mfi) { - warpx_interp(j, k, l, bz_aux, bz_fp, bz_c, Bz_stag, refinement_ratio); - }); + Array4 const& bx_aux = Bfield_aux[lev][0]->array(mfi); + Array4 const& by_aux = Bfield_aux[lev][1]->array(mfi); + Array4 const& bz_aux = Bfield_aux[lev][2]->array(mfi); + Array4 const& bx_fp = Bfield_fp[lev][0]->const_array(mfi); + Array4 const& by_fp = Bfield_fp[lev][1]->const_array(mfi); + Array4 const& bz_fp = Bfield_fp[lev][2]->const_array(mfi); + Array4 const& bx_c = dBx.const_array(mfi); + Array4 const& by_c = dBy.const_array(mfi); + Array4 const& bz_c = dBz.const_array(mfi); + + amrex::ParallelFor(Box(bx_aux), Box(by_aux), Box(bz_aux), + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, bx_aux, bx_fp, bx_c, Bx_stag, refinement_ratio); + }, + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, by_aux, by_fp, by_c, By_stag, refinement_ratio); + }, + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, bz_aux, bz_fp, bz_c, Bz_stag, refinement_ratio); + }); + } + } + else // electrostatic + { + MultiFab::Copy(*Bfield_aux[lev][0], *Bfield_fp[lev][0], 0, 0, Bfield_aux[lev][0]->nComp(), Bfield_aux[lev][0]->nGrowVect()); + MultiFab::Copy(*Bfield_aux[lev][1], *Bfield_fp[lev][1], 0, 0, Bfield_aux[lev][1]->nComp(), Bfield_aux[lev][1]->nGrowVect()); + MultiFab::Copy(*Bfield_aux[lev][2], *Bfield_fp[lev][2], 0, 0, Bfield_aux[lev][2]->nComp(), Bfield_aux[lev][2]->nGrowVect()); } } - // E field { - MultiFab dEx(Efield_cp[lev][0]->boxArray(), dm, Efield_cp[lev][0]->nComp(), ng); - MultiFab dEy(Efield_cp[lev][1]->boxArray(), dm, Efield_cp[lev][1]->nComp(), ng); - MultiFab dEz(Efield_cp[lev][2]->boxArray(), dm, Efield_cp[lev][2]->nComp(), ng); - dEx.setVal(0.0); - dEy.setVal(0.0); - dEz.setVal(0.0); - - // Copy Efield_aux to the dE MultiFabs, using up to ng_src (=ng_FieldGather) guard - // cells from Efield_aux and filling up to ng (=nGrow) guard cells in the dE MultiFabs - ablastr::utils::communication::ParallelCopy(dEx, *Efield_aux[lev - 1][0], 0, 0, - Efield_aux[lev - 1][0]->nComp(), ng_src, ng, - WarpX::do_single_precision_comms, - crse_period); - ablastr::utils::communication::ParallelCopy(dEy, *Efield_aux[lev - 1][1], 0, 0, - Efield_aux[lev - 1][1]->nComp(), ng_src, ng, - WarpX::do_single_precision_comms, - crse_period); - ablastr::utils::communication::ParallelCopy(dEz, *Efield_aux[lev - 1][2], 0, 0, - Efield_aux[lev - 1][2]->nComp(), ng_src, ng, - WarpX::do_single_precision_comms, - crse_period); - - if (Efield_cax[lev][0]) + if (electromagnetic_solver_id != ElectromagneticSolverAlgo::None) { - MultiFab::Copy(*Efield_cax[lev][0], dEx, 0, 0, Efield_cax[lev][0]->nComp(), ng); - MultiFab::Copy(*Efield_cax[lev][1], dEy, 0, 0, Efield_cax[lev][1]->nComp(), ng); - MultiFab::Copy(*Efield_cax[lev][2], dEz, 0, 0, Efield_cax[lev][2]->nComp(), ng); - } - MultiFab::Subtract(dEx, *Efield_cp[lev][0], 0, 0, Efield_cp[lev][0]->nComp(), ng); - MultiFab::Subtract(dEy, *Efield_cp[lev][1], 0, 0, Efield_cp[lev][1]->nComp(), ng); - MultiFab::Subtract(dEz, *Efield_cp[lev][2], 0, 0, Efield_cp[lev][2]->nComp(), ng); + MultiFab dEx(Efield_cp[lev][0]->boxArray(), dm, Efield_cp[lev][0]->nComp(), ng); + MultiFab dEy(Efield_cp[lev][1]->boxArray(), dm, Efield_cp[lev][1]->nComp(), ng); + MultiFab dEz(Efield_cp[lev][2]->boxArray(), dm, Efield_cp[lev][2]->nComp(), ng); + dEx.setVal(0.0); + dEy.setVal(0.0); + dEz.setVal(0.0); + + // Copy Efield_aux to the dE MultiFabs, using up to ng_src (=ng_FieldGather) guard + // cells from Efield_aux and filling up to ng (=nGrow) guard cells in the dE MultiFabs + ablastr::utils::communication::ParallelCopy(dEx, *Efield_aux[lev - 1][0], 0, 0, + Efield_aux[lev - 1][0]->nComp(), ng_src, ng, + WarpX::do_single_precision_comms, + crse_period); + ablastr::utils::communication::ParallelCopy(dEy, *Efield_aux[lev - 1][1], 0, 0, + Efield_aux[lev - 1][1]->nComp(), ng_src, ng, + WarpX::do_single_precision_comms, + crse_period); + ablastr::utils::communication::ParallelCopy(dEz, *Efield_aux[lev - 1][2], 0, 0, + Efield_aux[lev - 1][2]->nComp(), ng_src, ng, + WarpX::do_single_precision_comms, + crse_period); + + if (Efield_cax[lev][0]) + { + MultiFab::Copy(*Efield_cax[lev][0], dEx, 0, 0, Efield_cax[lev][0]->nComp(), ng); + MultiFab::Copy(*Efield_cax[lev][1], dEy, 0, 0, Efield_cax[lev][1]->nComp(), ng); + MultiFab::Copy(*Efield_cax[lev][2], dEz, 0, 0, Efield_cax[lev][2]->nComp(), ng); + } + MultiFab::Subtract(dEx, *Efield_cp[lev][0], 0, 0, Efield_cp[lev][0]->nComp(), ng); + MultiFab::Subtract(dEy, *Efield_cp[lev][1], 0, 0, Efield_cp[lev][1]->nComp(), ng); + MultiFab::Subtract(dEz, *Efield_cp[lev][2], 0, 0, Efield_cp[lev][2]->nComp(), ng); - const amrex::IntVect& refinement_ratio = refRatio(lev-1); + const amrex::IntVect& refinement_ratio = refRatio(lev-1); - const amrex::IntVect& Ex_stag = Efield_aux[lev-1][0]->ixType().toIntVect(); - const amrex::IntVect& Ey_stag = Efield_aux[lev-1][1]->ixType().toIntVect(); - const amrex::IntVect& Ez_stag = Efield_aux[lev-1][2]->ixType().toIntVect(); + const amrex::IntVect& Ex_stag = Efield_aux[lev-1][0]->ixType().toIntVect(); + const amrex::IntVect& Ey_stag = Efield_aux[lev-1][1]->ixType().toIntVect(); + const amrex::IntVect& Ez_stag = Efield_aux[lev-1][2]->ixType().toIntVect(); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(*Efield_aux[lev][0]); mfi.isValid(); ++mfi) - { - Array4 const& ex_aux = Efield_aux[lev][0]->array(mfi); - Array4 const& ey_aux = Efield_aux[lev][1]->array(mfi); - Array4 const& ez_aux = Efield_aux[lev][2]->array(mfi); - Array4 const& ex_fp = Efield_fp[lev][0]->const_array(mfi); - Array4 const& ey_fp = Efield_fp[lev][1]->const_array(mfi); - Array4 const& ez_fp = Efield_fp[lev][2]->const_array(mfi); - Array4 const& ex_c = dEx.const_array(mfi); - Array4 const& ey_c = dEy.const_array(mfi); - Array4 const& ez_c = dEz.const_array(mfi); - - amrex::ParallelFor(Box(ex_aux), Box(ey_aux), Box(ez_aux), - [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + for (MFIter mfi(*Efield_aux[lev][0]); mfi.isValid(); ++mfi) { - warpx_interp(j, k, l, ex_aux, ex_fp, ex_c, Ex_stag, refinement_ratio); - }, - [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept - { - warpx_interp(j, k, l, ey_aux, ey_fp, ey_c, Ey_stag, refinement_ratio); - }, - [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept - { - warpx_interp(j, k, l, ez_aux, ez_fp, ez_c, Ez_stag, refinement_ratio); - }); + Array4 const& ex_aux = Efield_aux[lev][0]->array(mfi); + Array4 const& ey_aux = Efield_aux[lev][1]->array(mfi); + Array4 const& ez_aux = Efield_aux[lev][2]->array(mfi); + Array4 const& ex_fp = Efield_fp[lev][0]->const_array(mfi); + Array4 const& ey_fp = Efield_fp[lev][1]->const_array(mfi); + Array4 const& ez_fp = Efield_fp[lev][2]->const_array(mfi); + Array4 const& ex_c = dEx.const_array(mfi); + Array4 const& ey_c = dEy.const_array(mfi); + Array4 const& ez_c = dEz.const_array(mfi); + + amrex::ParallelFor(Box(ex_aux), Box(ey_aux), Box(ez_aux), + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, ex_aux, ex_fp, ex_c, Ex_stag, refinement_ratio); + }, + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, ey_aux, ey_fp, ey_c, Ey_stag, refinement_ratio); + }, + [=] AMREX_GPU_DEVICE (int j, int k, int l) noexcept + { + warpx_interp(j, k, l, ez_aux, ez_fp, ez_c, Ez_stag, refinement_ratio); + }); + } + } + else // electrostatic + { + MultiFab::Copy(*Efield_aux[lev][0], *Efield_fp[lev][0], 0, 0, Efield_aux[lev][0]->nComp(), Efield_aux[lev][0]->nGrowVect()); + MultiFab::Copy(*Efield_aux[lev][1], *Efield_fp[lev][1], 0, 0, Efield_aux[lev][1]->nComp(), Efield_aux[lev][1]->nGrowVect()); + MultiFab::Copy(*Efield_aux[lev][2], *Efield_fp[lev][2], 0, 0, Efield_aux[lev][2]->nComp(), Efield_aux[lev][2]->nGrowVect()); } } } diff --git a/Source/Parallelization/WarpXComm_K.H b/Source/Parallelization/WarpXComm_K.H index a2b8fe38ed4..79f2b34fba0 100644 --- a/Source/Parallelization/WarpXComm_K.H +++ b/Source/Parallelization/WarpXComm_K.H @@ -12,7 +12,7 @@ /** * \brief Interpolation function called within WarpX::UpdateAuxilaryDataSameType - * to interpolate data from the coarse and fine grids to the fine aux grid, + * with electromagnetic solver to interpolate data from the coarse and fine grids to the fine aux grid, * assuming that all grids have the same staggering (either collocated or staggered). * * \param[in] j index along x of the output array @@ -44,18 +44,19 @@ void warpx_interp (int j, int k, int l, // Refinement ratio const int rj = rr[0]; - const int rk = (AMREX_SPACEDIM == 1) ? 1 : rr[1]; - const int rl = (AMREX_SPACEDIM <= 2) ? 1 : rr[2]; + const int rk = (AMREX_SPACEDIM > 1) ? rr[1] : 1; + const int rl = (AMREX_SPACEDIM > 2) ? rr[2] : 1; // Staggering (0: cell-centered; 1: nodal) + // Unused dimensions are considered nodal. const int sj = arr_stag[0]; - const int sk = (AMREX_SPACEDIM == 1) ? 0 : arr_stag[1]; - const int sl = (AMREX_SPACEDIM <= 2) ? 0 : arr_stag[2]; + const int sk = (AMREX_SPACEDIM > 1) ? arr_stag[1] : 1; + const int sl = (AMREX_SPACEDIM > 2) ? arr_stag[2] : 1; // Number of points used for interpolation from coarse grid to fine grid const int nj = 2; - const int nk = 2; - const int nl = 2; + const int nk = (AMREX_SPACEDIM > 1) ? 2 : 1; + const int nl = (AMREX_SPACEDIM > 2) ? 2 : 1; const int jc = (sj == 0) ? amrex::coarsen(j - rj/2, rj) : amrex::coarsen(j, rj); const int kc = (sk == 0) ? amrex::coarsen(k - rk/2, rk) : amrex::coarsen(k, rk); @@ -133,38 +134,20 @@ void warpx_interp (int j, int k, int l, // Refinement ratio const int rj = rr[0]; -#if defined(WARPX_DIM_1D_Z) - constexpr int rk = 1; - constexpr int rl = 1; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const int rk = rr[1]; - constexpr int rl = 1; -#else - const int rk = rr[1]; - const int rl = rr[2]; -#endif + const int rk = (AMREX_SPACEDIM > 1) ? rr[1] : 1; + const int rl = (AMREX_SPACEDIM > 2) ? rr[2] : 1; // Staggering of fine array (0: cell-centered; 1: nodal) + // Unused dimensions are considered nodal. const int sj_fp = arr_fine_stag[0]; -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const int sk_fp = arr_fine_stag[1]; -#elif defined(WARPX_DIM_3D) - const int sk_fp = arr_fine_stag[1]; - const int sl_fp = arr_fine_stag[2]; -#endif + const int sk_fp = (AMREX_SPACEDIM > 1) ? arr_fine_stag[1] : 1; + const int sl_fp = (AMREX_SPACEDIM > 2) ? arr_fine_stag[2] : 1; // Staggering of coarse array (0: cell-centered; 1: nodal) + // Unused dimensions are considered nodal. const int sj_cp = arr_coarse_stag[0]; -#if defined(WARPX_DIM_1D_Z) - constexpr int sk_cp = 0; - constexpr int sl_cp = 0; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const int sk_cp = arr_coarse_stag[1]; - constexpr int sl_cp = 0; -#else - const int sk_cp = arr_coarse_stag[1]; - const int sl_cp = arr_coarse_stag[2]; -#endif + const int sk_cp = (AMREX_SPACEDIM > 1) ? arr_coarse_stag[1] : 1; + const int sl_cp = (AMREX_SPACEDIM > 2) ? arr_coarse_stag[2] : 1; // Number of points used for interpolation from coarse grid to fine grid int nj; @@ -182,27 +165,19 @@ void warpx_interp (int j, int k, int l, // 1) Interpolation from coarse nodal to fine nodal nj = 2; -#if defined(WARPX_DIM_1D_Z) - nk = 1; - nl = 1; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - nk = 2; - nl = 1; -#else - nk = 2; - nl = 2; -#endif + nk = (AMREX_SPACEDIM > 1) ? 2 : 1; + nl = (AMREX_SPACEDIM > 2) ? 2 : 1; for (int jj = 0; jj < nj; jj++) { for (int kk = 0; kk < nk; kk++) { for (int ll = 0; ll < nl; ll++) { auto c = arr_tmp_zeropad(jc+jj,kc+kk,lc+ll); c *= (rj - amrex::Math::abs(j - (jc + jj) * rj)) / static_cast(rj); -#if (AMREX_SPACEDIM >= 2) +#if (AMREX_SPACEDIM > 1) c *= (rk - amrex::Math::abs(k - (kc + kk) * rk)) / static_cast(rk); -#endif -#if (AMREX_SPACEDIM == 3) +#if (AMREX_SPACEDIM > 2) c *= (rl - amrex::Math::abs(l - (lc + ll) * rl)) / static_cast(rl); +#endif #endif tmp += c; } @@ -212,16 +187,8 @@ void warpx_interp (int j, int k, int l, // 2) Interpolation from coarse staggered to fine nodal nj = 2; -#if defined(WARPX_DIM_1D_Z) - nk = 1; - nl = 1; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - nk = 2; - nl = 1; -#else - nk = 2; - nl = 2; -#endif + nk = (AMREX_SPACEDIM > 1) ? 2 : 1; + nl = (AMREX_SPACEDIM > 2) ? 2 : 1; const int jn = (sj_cp == 1) ? j : j - rj / 2; const int kn = (sk_cp == 1) ? k : k - rk / 2; @@ -236,11 +203,11 @@ void warpx_interp (int j, int k, int l, for (int ll = 0; ll < nl; ll++) { auto c = arr_coarse_zeropad(jc+jj,kc+kk,lc+ll); c *= (rj - amrex::Math::abs(jn - (jc + jj) * rj)) / static_cast(rj); -#if (AMREX_SPACEDIM >= 2) +#if (AMREX_SPACEDIM > 1) c *= (rk - amrex::Math::abs(kn - (kc + kk) * rk)) / static_cast(rk); -#endif -#if (AMREX_SPACEDIM == 3) +#if (AMREX_SPACEDIM > 2) c *= (rl - amrex::Math::abs(ln - (lc + ll) * rl)) / static_cast(rl); +#endif #endif coarse += c; } @@ -250,28 +217,12 @@ void warpx_interp (int j, int k, int l, // 3) Interpolation from fine staggered to fine nodal nj = (sj_fp == 0) ? 2 : 1; -#if defined(WARPX_DIM_1D_Z) - nk = 1; - nl = 1; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - nk = (sk_fp == 0) ? 2 : 1; - nl = 1; -#else nk = (sk_fp == 0) ? 2 : 1; nl = (sl_fp == 0) ? 2 : 1; -#endif const int jm = (sj_fp == 0) ? j-1 : j; -#if defined(WARPX_DIM_1D_Z) - const int km = k; - const int lm = l; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const int km = (sk_fp == 0) ? k-1 : k; - const int lm = l; -#else const int km = (sk_fp == 0) ? k-1 : k; const int lm = (sl_fp == 0) ? l-1 : l; -#endif for (int jj = 0; jj < nj; jj++) { for (int kk = 0; kk < nk; kk++) { @@ -286,6 +237,76 @@ void warpx_interp (int j, int k, int l, arr_aux(j,k,l) = tmp + (fine - coarse); } +/** + * \brief Interpolation function called within WarpX::UpdateAuxilaryDataStagToNodal + * to interpolate data from the coarse and fine grids to the fine aux grid, + * with momentum-conserving field gathering, hence between grids with different staggering, + * and assuming that the aux grid is collocated. + * + * \param[in] j index along x of the output array + * \param[in] k index along y (in 3D) or z (in 2D) of the output array + * \param[in] l index along z (in 3D, l=0 in 2D) of the output array + * \param[in,out] arr_aux output array where interpolated values are stored + * \param[in] arr_fine input fine-patch array storing the values to interpolate + * \param[in] arr_fine_stag IndexType of the fine-patch arrays + */ +AMREX_GPU_DEVICE AMREX_FORCE_INLINE +void warpx_interp (int j, int k, int l, + amrex::Array4 const& arr_aux, + amrex::Array4 const& arr_fine, + const amrex::IntVect& arr_fine_stag) +{ + using namespace amrex; + + // Pad input arrays with zeros beyond ghost cells + // for out-of-bound accesses due to large-stencil operations + const auto arr_fine_zeropad = [arr_fine] (const int jj, const int kk, const int ll) noexcept + { + return arr_fine.contains(jj,kk,ll) ? arr_fine(jj,kk,ll) : 0.0_rt; + }; + + // NOTE Indices (j,k,l) in the following refer to: + // - (z,-,-) in 1D + // - (x,z,-) in 2D + // - (r,z,-) in RZ + // - (x,y,z) in 3D + + // Staggering of fine array (0: cell-centered; 1: nodal) + // Unused dimensions are considered nodal. + const int sj_fp = arr_fine_stag[0]; + const int sk_fp = (AMREX_SPACEDIM > 1) ? arr_fine_stag[1] : 1; + const int sl_fp = (AMREX_SPACEDIM > 2) ? arr_fine_stag[2] : 1; + + // Number of points used for interpolation from coarse grid to fine grid + int nj; + int nk; + int nl; + + amrex::Real fine = 0.0_rt; + + // 3) Interpolation from fine staggered to fine nodal + + nj = (sj_fp == 0) ? 2 : 1; + nk = (sk_fp == 0) ? 2 : 1; + nl = (sl_fp == 0) ? 2 : 1; + + int const jm = (sj_fp == 0) ? j-1 : j; + int const km = (sk_fp == 0) ? k-1 : k; + int const lm = (sl_fp == 0) ? l-1 : l; + + for (int jj = 0; jj < nj; jj++) { + for (int kk = 0; kk < nk; kk++) { + for (int ll = 0; ll < nl; ll++) { + fine += arr_fine_zeropad(jm+jj,km+kk,lm+ll); + } + } + } + fine = fine/static_cast(nj*nk*nl); + + // Final result + arr_aux(j,k,l) = fine; +} + /** * \brief Arbitrary-order interpolation function used to center a given MultiFab between two grids * with different staggerings. The arbitrary-order interpolation is based on the Fornberg coefficients. @@ -330,11 +351,7 @@ void warpx_interp (const int j, }; // Avoid compiler warnings -#if defined(WARPX_DIM_1D_Z) amrex::ignore_unused(nox, noy, stencil_coeffs_x, stencil_coeffs_y); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ignore_unused(noy, stencil_coeffs_y); -#endif // If dst_nodal = true , we are centering from a staggered grid to a nodal grid // If dst_nodal = false, we are centering from a nodal grid to a staggered grid @@ -344,70 +361,32 @@ void warpx_interp (const int j, const int shift = (dst_nodal) ? 0 : 1; // Staggering (s = 0 if cell-centered, s = 1 if nodal) + // Unused dimensions are considered nodal. const int sj = (dst_nodal) ? src_stag[0] : dst_stag[0]; -#if (AMREX_SPACEDIM >= 2) - const int sk = (dst_nodal) ? src_stag[1] : dst_stag[1]; -#endif -#if defined(WARPX_DIM_3D) - const int sl = (dst_nodal) ? src_stag[2] : dst_stag[2]; -#endif + const int sk = (AMREX_SPACEDIM > 1) ? ((dst_nodal) ? src_stag[1] : dst_stag[1]) : 1; + const int sl = (AMREX_SPACEDIM > 2) ? ((dst_nodal) ? src_stag[2] : dst_stag[2]) : 1; // Interpolate along j,k,l only if source MultiFab is staggered along j,k,l const bool interp_j = (sj == 0); -#if (AMREX_SPACEDIM >= 2) const bool interp_k = (sk == 0); -#endif -#if defined(WARPX_DIM_3D) const bool interp_l = (sl == 0); -#endif -#if defined(WARPX_DIM_1D_Z) - const int noj = noz; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const int noj = nox; - const int nok = noz; -#elif defined(WARPX_DIM_3D) - const int noj = nox; - const int nok = noy; - const int nol = noz; -#endif + const int noj = AMREX_D_PICK(noz, nox, nox); + const int nok = AMREX_D_PICK(0 , noz, noy); + const int nol = AMREX_D_PICK(0 , 0 , noz); // Additional normalization factor const amrex::Real wj = (interp_j) ? 0.5_rt : 1.0_rt; -#if defined(WARPX_DIM_1D_Z) - constexpr amrex::Real wk = 1.0_rt; - constexpr amrex::Real wl = 1.0_rt; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - const amrex::Real wk = (interp_k) ? 0.5_rt : 1.0_rt; - constexpr amrex::Real wl = 1.0_rt; -#elif defined(WARPX_DIM_3D) const amrex::Real wk = (interp_k) ? 0.5_rt : 1.0_rt; const amrex::Real wl = (interp_l) ? 0.5_rt : 1.0_rt; -#endif - // Min and max for interpolation loop along j + // Min and max for interpolation loop const int jmin = (interp_j) ? j - noj/2 + shift : j; const int jmax = (interp_j) ? j + noj/2 + shift - 1 : j; - - // Min and max for interpolation loop along k -#if defined(WARPX_DIM_1D_Z) - // k = 0 always - const int kmin = k; - const int kmax = k; -#else const int kmin = (interp_k) ? k - nok/2 + shift : k; const int kmax = (interp_k) ? k + nok/2 + shift - 1 : k; -#endif - - // Min and max for interpolation loop along l -#if (AMREX_SPACEDIM <= 2) - // l = 0 always - const int lmin = l; - const int lmax = l; -#elif defined(WARPX_DIM_3D) const int lmin = (interp_l) ? l - nol/2 + shift : l; const int lmax = (interp_l) ? l + nol/2 + shift - 1 : l; -#endif // Number of interpolation points const int nj = jmax - jmin; @@ -455,31 +434,16 @@ void warpx_interp (const int j, amrex::Real res = 0.0_rt; -#if defined(WARPX_DIM_1D_Z) - amrex::Real const* scj = stencil_coeffs_z; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::Real const* scj = stencil_coeffs_x; - amrex::Real const* sck = stencil_coeffs_z; -#elif defined(WARPX_DIM_3D) - amrex::Real const* scj = stencil_coeffs_x; - amrex::Real const* sck = stencil_coeffs_y; - amrex::Real const* scl = stencil_coeffs_z; -#endif + amrex::Real const* scj = AMREX_D_PICK(stencil_coeffs_z, stencil_coeffs_x, stencil_coeffs_x); + amrex::Real const* sck = AMREX_D_PICK(nullptr , stencil_coeffs_z, stencil_coeffs_y); + amrex::Real const* scl = AMREX_D_PICK(nullptr , nullptr , stencil_coeffs_z); for (int ll = 0; ll <= nl; ll++) { -#if defined(WARPX_DIM_3D) - const amrex::Real cl = (interp_l)? scl[ll] : 1.0_rt; -#else - const amrex::Real cl = 1.0_rt; -#endif + const amrex::Real cl = (interp_l)? scl[ll] : 1.0_rt; for (int kk = 0; kk <= nk; kk++) { -#if (AMREX_SPACEDIM >= 2) const amrex::Real ck = (interp_k)? sck[kk] : 1.0_rt; -#else - const amrex::Real ck = 1.0_rt; -#endif for (int jj = 0; jj <= nj; jj++) { const amrex::Real cj = (interp_j)? scj[jj] : 1.0_rt; diff --git a/Source/Parallelization/WarpXRegrid.cpp b/Source/Parallelization/WarpXRegrid.cpp index d33bd17ccdd..0a3ab8d2099 100644 --- a/Source/Parallelization/WarpXRegrid.cpp +++ b/Source/Parallelization/WarpXRegrid.cpp @@ -10,6 +10,7 @@ #include "Diagnostics/MultiDiagnostics.H" #include "Diagnostics/ReducedDiags/MultiReducedDiags.H" +#include "EmbeddedBoundary/Enabled.H" #include "EmbeddedBoundary/WarpXFaceInfoBox.H" #include "FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H" #include "Initialization/ExternalField.H" @@ -177,6 +178,7 @@ WarpX::RemakeLevel (int lev, Real /*time*/, const BoxArray& ba, const Distributi mf = std::move(pmf); }; + bool const eb_enabled = EB::enabled(); if (ba == boxArray(lev)) { if (ParallelDescriptor::NProcs() == 1) { return; } @@ -215,20 +217,20 @@ WarpX::RemakeLevel (int lev, Real /*time*/, const BoxArray& ba, const Distributi RemakeMultiFab(m_hybrid_pic_model->current_fp_ampere[lev][idim], false); RemakeMultiFab(m_hybrid_pic_model->current_fp_external[lev][idim],true); } -#ifdef AMREX_USE_EB - if (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::PSATD) { - RemakeMultiFab(m_edge_lengths[lev][idim], false); - RemakeMultiFab(m_face_areas[lev][idim], false); - if(WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT){ - RemakeMultiFab(Venl[lev][idim], false); - RemakeMultiFab(m_flag_info_face[lev][idim], false); - RemakeMultiFab(m_flag_ext_face[lev][idim], false); - RemakeMultiFab(m_area_mod[lev][idim], false); - RemakeMultiFab(ECTRhofield[lev][idim], false); - m_borrowing[lev][idim] = std::make_unique>(amrex::convert(ba, Bfield_fp[lev][idim]->ixType().toIntVect()), dm); + if (eb_enabled) { + if (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::PSATD) { + RemakeMultiFab(m_edge_lengths[lev][idim], false); + RemakeMultiFab(m_face_areas[lev][idim], false); + if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { + RemakeMultiFab(Venl[lev][idim], false); + RemakeMultiFab(m_flag_info_face[lev][idim], false); + RemakeMultiFab(m_flag_ext_face[lev][idim], false); + RemakeMultiFab(m_area_mod[lev][idim], false); + RemakeMultiFab(ECTRhofield[lev][idim], false); + m_borrowing[lev][idim] = std::make_unique>(amrex::convert(ba, Bfield_fp[lev][idim]->ixType().toIntVect()), dm); + } } } -#endif } RemakeMultiFab(F_fp[lev], true); @@ -242,18 +244,19 @@ WarpX::RemakeLevel (int lev, Real /*time*/, const BoxArray& ba, const Distributi RemakeMultiFab(m_hybrid_pic_model->electron_pressure_fp[lev], false); } -#ifdef AMREX_USE_EB - RemakeMultiFab(m_distance_to_eb[lev], false); - - int max_guard = guard_cells.ng_FieldSolver.max(); - m_field_factory[lev] = amrex::makeEBFabFactory(Geom(lev), ba, dm, - {max_guard, max_guard, max_guard}, - amrex::EBSupport::full); + if (eb_enabled) { + RemakeMultiFab(m_distance_to_eb[lev], false); - InitializeEBGridData(lev); -#else - m_field_factory[lev] = std::make_unique(); +#ifdef AMREX_USE_EB + int const max_guard = guard_cells.ng_FieldSolver.max(); + m_field_factory[lev] = amrex::makeEBFabFactory(Geom(lev), ba, dm, + {max_guard, max_guard, max_guard}, + amrex::EBSupport::full); #endif + InitializeEBGridData(lev); + } else { + m_field_factory[lev] = std::make_unique(); + } #ifdef WARPX_USE_FFT if (electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) { diff --git a/Source/Particles/AddPlasmaUtilities.H b/Source/Particles/AddPlasmaUtilities.H new file mode 100644 index 00000000000..8f0489e3921 --- /dev/null +++ b/Source/Particles/AddPlasmaUtilities.H @@ -0,0 +1,210 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + * Authors: Andrew Myers + */ +#ifndef WARPX_ADDPLASMAUTILITIES_H_ +#define WARPX_ADDPLASMAUTILITIES_H_ + +#include "Initialization/PlasmaInjector.H" + +#ifdef WARPX_QED +# include "Particles/ElementaryProcess/QEDInternals/BreitWheelerEngineWrapper.H" +# include "Particles/ElementaryProcess/QEDInternals/QuantumSyncEngineWrapper.H" +#endif + +#include +#include +#include +#include +#include +#include + +/* + Finds the overlap region between the given tile_realbox and part_realbox, returning true + if an overlap exists and false if otherwise. This also sets the parameters overlap_realbox, + overlap_box, and shifted to the appropriate values. + */ +bool find_overlap (const amrex::RealBox& tile_realbox, const amrex::RealBox& part_realbox, + const amrex::GpuArray& dx, + const amrex::GpuArray& prob_lo, + amrex::RealBox& overlap_realbox, amrex::Box& overlap_box, amrex::IntVect& shifted); + +/* + Finds the overlap region between the given tile_realbox, part_realbox and the surface used for + flux injection, returning true if an overlap exists and false if otherwise. This also sets the + parameters overlap_realbox, overlap_box, and shifted to the appropriate values. + */ +bool find_overlap_flux (const amrex::RealBox& tile_realbox, const amrex::RealBox& part_realbox, + const amrex::GpuArray& dx, + const amrex::GpuArray& prob_lo, + const PlasmaInjector& plasma_injector, + amrex::RealBox& overlap_realbox, amrex::Box& overlap_box, amrex::IntVect& shifted); + +/* + This computes the scale_fac (used for setting the particle weights) on a volumetric basis. + */ +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +amrex::Real compute_scale_fac_volume (const amrex::GpuArray& dx, + const amrex::Long pcount) { + using namespace amrex::literals; + return (pcount != 0) ? AMREX_D_TERM(dx[0],*dx[1],*dx[2])/pcount : 0.0_rt; +} + +/* + Given a refinement ratio, this computes the total increase in resolution for a plane + defined by the normal_axis. + */ +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +int compute_area_weights (const amrex::IntVect& iv, const int normal_axis) { + int r = AMREX_D_TERM(iv[0],*iv[1],*iv[2]); +#if defined(WARPX_DIM_3D) + r /= iv[normal_axis]; +#elif defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ) + if (normal_axis == 0) { r /= iv[0]; } + else if (normal_axis == 2) { r /= iv[1]; } +#elif defined(WARPX_DIM_1D_Z) + if (normal_axis == 2) { r /= iv[0]; } +#endif + return r; +} + +/* + This computes the scale_fac (used for setting the particle weights) on a on area basis + (used for flux injection). + */ +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +amrex::Real compute_scale_fac_area (const amrex::GpuArray& dx, + const amrex::Real num_ppc_real, const int flux_normal_axis) { + using namespace amrex::literals; + amrex::Real scale_fac = AMREX_D_TERM(dx[0],*dx[1],*dx[2])/num_ppc_real; + // Scale particle weight by the area of the emitting surface, within one cell +#if defined(WARPX_DIM_3D) + scale_fac /= dx[flux_normal_axis]; +#elif defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ) + // When emission is in the r direction, the emitting surface is a cylinder. + // The factor 2*pi*r is added later below. + if (flux_normal_axis == 0) { scale_fac /= dx[0]; } + // When emission is in the z direction, the emitting surface is an annulus + // The factor 2*pi*r is added later below. + if (flux_normal_axis == 2) { scale_fac /= dx[1]; } + // When emission is in the theta direction (flux_normal_axis == 1), + // the emitting surface is a rectangle, within the plane of the simulation +#elif defined(WARPX_DIM_1D_Z) + if (flux_normal_axis == 2) { scale_fac /= dx[0]; } +#endif + return scale_fac; +} + +/* + These structs encapsulates several data structures needed for using the parser during plasma + injection. + */ +struct PlasmaParserWrapper +{ + PlasmaParserWrapper (std::size_t a_num_user_int_attribs, + std::size_t a_num_user_real_attribs, + const amrex::Vector< std::unique_ptr >& a_user_int_attrib_parser, + const amrex::Vector< std::unique_ptr >& a_user_real_attrib_parser); + + amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > m_user_int_attrib_parserexec_pinned; + amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > m_user_real_attrib_parserexec_pinned; +}; + +struct PlasmaParserHelper +{ + template + PlasmaParserHelper (SoAType& a_soa, std::size_t old_size, + const std::vector& a_user_int_attribs, + const std::vector& a_user_real_attribs, + std::map& a_particle_icomps, + std::map& a_particle_comps, + const PlasmaParserWrapper& wrapper) : + m_wrapper_ptr(&wrapper) { + m_pa_user_int_pinned.resize(a_user_int_attribs.size()); + m_pa_user_real_pinned.resize(a_user_real_attribs.size()); + +#ifdef AMREX_USE_GPU + m_d_pa_user_int.resize(a_user_int_attribs.size()); + m_d_pa_user_real.resize(a_user_real_attribs.size()); + m_d_user_int_attrib_parserexec.resize(a_user_int_attribs.size()); + m_d_user_real_attrib_parserexec.resize(a_user_real_attribs.size()); +#endif + + for (std::size_t ia = 0; ia < a_user_int_attribs.size(); ++ia) { + m_pa_user_int_pinned[ia] = a_soa.GetIntData(a_particle_icomps[a_user_int_attribs[ia]]).data() + old_size; + } + for (std::size_t ia = 0; ia < a_user_real_attribs.size(); ++ia) { + m_pa_user_real_pinned[ia] = a_soa.GetRealData(a_particle_comps[a_user_real_attribs[ia]]).data() + old_size; + } + +#ifdef AMREX_USE_GPU + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, m_pa_user_int_pinned.begin(), + m_pa_user_int_pinned.end(), m_d_pa_user_int.begin()); + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, m_pa_user_real_pinned.begin(), + m_pa_user_real_pinned.end(), m_d_pa_user_real.begin()); + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, wrapper.m_user_int_attrib_parserexec_pinned.begin(), + wrapper.m_user_int_attrib_parserexec_pinned.end(), m_d_user_int_attrib_parserexec.begin()); + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, wrapper.m_user_real_attrib_parserexec_pinned.begin(), + wrapper.m_user_real_attrib_parserexec_pinned.end(), m_d_user_real_attrib_parserexec.begin()); +#endif + } + + int** getUserIntDataPtrs (); + amrex::ParticleReal** getUserRealDataPtrs (); + [[nodiscard]] amrex::ParserExecutor<7> const* getUserIntParserExecData () const; + [[nodiscard]] amrex::ParserExecutor<7> const* getUserRealParserExecData () const; + + amrex::Gpu::PinnedVector m_pa_user_int_pinned; + amrex::Gpu::PinnedVector m_pa_user_real_pinned; + +#ifdef AMREX_USE_GPU + // To avoid using managed memory, we first define pinned memory vector, initialize on cpu, + // and them memcpy to device from host + amrex::Gpu::DeviceVector m_d_pa_user_int; + amrex::Gpu::DeviceVector m_d_pa_user_real; + amrex::Gpu::DeviceVector< amrex::ParserExecutor<7> > m_d_user_int_attrib_parserexec; + amrex::Gpu::DeviceVector< amrex::ParserExecutor<7> > m_d_user_real_attrib_parserexec; +#endif + const PlasmaParserWrapper* m_wrapper_ptr; +}; + +#ifdef WARPX_QED +struct QEDHelper +{ + template + QEDHelper (SoAType& a_soa, std::size_t old_size, + std::map& a_particle_comps, + bool a_has_quantum_sync, bool a_has_breit_wheeler, + const std::shared_ptr& a_shr_p_qs_engine, + const std::shared_ptr& a_shr_p_bw_engine) + : has_quantum_sync(a_has_quantum_sync), has_breit_wheeler(a_has_breit_wheeler) + { + if(has_quantum_sync){ + quantum_sync_get_opt = + a_shr_p_qs_engine->build_optical_depth_functor(); + p_optical_depth_QSR = a_soa.GetRealData( + a_particle_comps["opticalDepthQSR"]).data() + old_size; + } + if(has_breit_wheeler){ + breit_wheeler_get_opt = + a_shr_p_bw_engine->build_optical_depth_functor(); + p_optical_depth_BW = a_soa.GetRealData( + a_particle_comps["opticalDepthBW"]).data() + old_size; + } + } + + amrex::ParticleReal* p_optical_depth_QSR = nullptr; + amrex::ParticleReal* p_optical_depth_BW = nullptr; + + const bool has_quantum_sync; + const bool has_breit_wheeler; + + QuantumSynchrotronGetOpticalDepth quantum_sync_get_opt; + BreitWheelerGetOpticalDepth breit_wheeler_get_opt; +}; +#endif + +#endif /*WARPX_ADDPLASMAUTILITIES_H_*/ diff --git a/Source/Particles/AddPlasmaUtilities.cpp b/Source/Particles/AddPlasmaUtilities.cpp new file mode 100644 index 00000000000..31066516477 --- /dev/null +++ b/Source/Particles/AddPlasmaUtilities.cpp @@ -0,0 +1,158 @@ +/* Copyright 2024 The WarpX Community + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + * Authors: Andrew Myers + */ +#include "AddPlasmaUtilities.H" + +#include + +bool find_overlap (const amrex::RealBox& tile_realbox, const amrex::RealBox& part_realbox, + const amrex::GpuArray& dx, + const amrex::GpuArray& prob_lo, + amrex::RealBox& overlap_realbox, amrex::Box& overlap_box, amrex::IntVect& shifted) +{ + using namespace amrex::literals; + + bool no_overlap = false; + for (int dir=0; dir= part_realbox.lo(dir) ) { + const amrex::Real ncells_adjust = std::floor( (part_realbox.hi(dir) - tile_realbox.hi(dir))/dx[dir] ); + overlap_realbox.setHi( dir, part_realbox.hi(dir) - std::max(ncells_adjust, 0._rt) * dx[dir]); + } else { + no_overlap = true; break; + } + // Count the number of cells in this direction in overlap_realbox + overlap_box.setSmall( dir, 0 ); + overlap_box.setBig( dir, + int( std::round((overlap_realbox.hi(dir)-overlap_realbox.lo(dir)) + /dx[dir] )) - 1); + shifted[dir] = + static_cast(std::round((overlap_realbox.lo(dir)-prob_lo[dir])/dx[dir])); + // shifted is exact in non-moving-window direction. That's all we care. + } + return no_overlap; +} + +bool find_overlap_flux (const amrex::RealBox& tile_realbox, const amrex::RealBox& part_realbox, + const amrex::GpuArray& dx, + const amrex::GpuArray& prob_lo, + const PlasmaInjector& plasma_injector, + amrex::RealBox& overlap_realbox, amrex::Box& overlap_box, amrex::IntVect& shifted) +{ + using namespace amrex::literals; + + bool no_overlap = false; + for (int dir=0; dir 0) { + if (plasma_injector.surface_flux_pos < tile_realbox.lo(dir) || + plasma_injector.surface_flux_pos >= tile_realbox.hi(dir)) { + no_overlap = true; + break; + } + } else { + if (plasma_injector.surface_flux_pos <= tile_realbox.lo(dir) || + plasma_injector.surface_flux_pos > tile_realbox.hi(dir)) { + no_overlap = true; + break; + } + } + overlap_realbox.setLo( dir, plasma_injector.surface_flux_pos ); + overlap_realbox.setHi( dir, plasma_injector.surface_flux_pos ); + overlap_box.setSmall( dir, 0 ); + overlap_box.setBig( dir, 0 ); + shifted[dir] = + static_cast(std::round((overlap_realbox.lo(dir)-prob_lo[dir])/dx[dir])); + } else { + if ( tile_realbox.lo(dir) <= part_realbox.hi(dir) ) { + const amrex::Real ncells_adjust = std::floor( (tile_realbox.lo(dir) - part_realbox.lo(dir))/dx[dir] ); + overlap_realbox.setLo( dir, part_realbox.lo(dir) + std::max(ncells_adjust, 0._rt) * dx[dir]); + } else { + no_overlap = true; break; + } + if ( tile_realbox.hi(dir) >= part_realbox.lo(dir) ) { + const amrex::Real ncells_adjust = std::floor( (part_realbox.hi(dir) - tile_realbox.hi(dir))/dx[dir] ); + overlap_realbox.setHi( dir, part_realbox.hi(dir) - std::max(ncells_adjust, 0._rt) * dx[dir]); + } else { + no_overlap = true; break; + } + // Count the number of cells in this direction in overlap_realbox + overlap_box.setSmall( dir, 0 ); + overlap_box.setBig( dir, + int( std::round((overlap_realbox.hi(dir)-overlap_realbox.lo(dir)) + /dx[dir] )) - 1); + shifted[dir] = + static_cast(std::round((overlap_realbox.lo(dir)-prob_lo[dir])/dx[dir])); + // shifted is exact in non-moving-window direction. That's all we care. + } + } + + return no_overlap; +} + +PlasmaParserWrapper::PlasmaParserWrapper (const std::size_t a_num_user_int_attribs, + const std::size_t a_num_user_real_attribs, + const amrex::Vector< std::unique_ptr >& a_user_int_attrib_parser, + const amrex::Vector< std::unique_ptr >& a_user_real_attrib_parser) + +{ + m_user_int_attrib_parserexec_pinned.resize(a_num_user_int_attribs); + m_user_real_attrib_parserexec_pinned.resize(a_num_user_real_attribs); + + for (std::size_t ia = 0; ia < a_num_user_int_attribs; ++ia) { + m_user_int_attrib_parserexec_pinned[ia] = a_user_int_attrib_parser[ia]->compile<7>(); + } + for (std::size_t ia = 0; ia < a_num_user_real_attribs; ++ia) { + m_user_real_attrib_parserexec_pinned[ia] = a_user_real_attrib_parser[ia]->compile<7>(); + } +} + +int** PlasmaParserHelper::getUserIntDataPtrs () { +#ifdef AMREX_USE_GPU + return m_d_pa_user_int.dataPtr(); +#else + return m_pa_user_int_pinned.dataPtr(); +#endif +} + +amrex::ParticleReal** PlasmaParserHelper::getUserRealDataPtrs () { +#ifdef AMREX_USE_GPU + return m_d_pa_user_real.dataPtr(); +#else + return m_pa_user_real_pinned.dataPtr(); +#endif +} + +amrex::ParserExecutor<7> const* PlasmaParserHelper::getUserIntParserExecData () const { +#ifdef AMREX_USE_GPU + return m_d_user_int_attrib_parserexec.dataPtr(); +#else + return m_wrapper_ptr->m_user_int_attrib_parserexec_pinned.dataPtr(); +#endif +} + +amrex::ParserExecutor<7> const* PlasmaParserHelper::getUserRealParserExecData () const { +#ifdef AMREX_USE_GPU + return m_d_user_real_attrib_parserexec.dataPtr(); +#else + return m_wrapper_ptr->m_user_real_attrib_parserexec_pinned.dataPtr(); +#endif +} diff --git a/Source/Particles/CMakeLists.txt b/Source/Particles/CMakeLists.txt index 67af14ef889..6b434c0a4e1 100644 --- a/Source/Particles/CMakeLists.txt +++ b/Source/Particles/CMakeLists.txt @@ -2,6 +2,7 @@ foreach(D IN LISTS WarpX_DIMS) warpx_set_suffix_dims(SD ${D}) target_sources(lib_${SD} PRIVATE + AddPlasmaUtilities.cpp MultiParticleContainer.cpp ParticleBoundaries.cpp PhotonParticleContainer.cpp diff --git a/Source/Particles/Collision/BinaryCollision/BinaryCollision.H b/Source/Particles/Collision/BinaryCollision/BinaryCollision.H index 0ba49e9b09f..b64c6d4b1fa 100644 --- a/Source/Particles/Collision/BinaryCollision/BinaryCollision.H +++ b/Source/Particles/Collision/BinaryCollision/BinaryCollision.H @@ -262,6 +262,28 @@ public: } auto *tile_products_data = tile_products.data(); + amrex::Geometry const& geom = WarpX::GetInstance().Geom(lev); + auto const dV = AMREX_D_TERM(geom.CellSize(0), *geom.CellSize(1), *geom.CellSize(2)); +#if defined WARPX_DIM_RZ + amrex::Box const& cbx = mfi.tilebox(amrex::IntVect::TheZeroVector()); //Cell-centered box + auto const lo = lbound(cbx); + auto const hi = ubound(cbx); + int const nz = hi.y - lo.y + 1; + auto const dr = geom.CellSize(0); +#endif + + auto volume_factor = [=] AMREX_GPU_DEVICE(int i_cell) noexcept { +#if defined WARPX_DIM_RZ + // Return the radial factor for the volume element, dV + int const ri = (i_cell - i_cell%nz)/nz; + return MathConst::pi*(2.0_prt*ri + 1.0_prt)*dr; +#else + // No factor is needed for Cartesian + amrex::ignore_unused(i_cell); + return 1._prt; +#endif + }; + if ( m_isSameSpecies ) // species_1 == species_2 { // Extract particles in the tile that `mfi` points to @@ -282,22 +304,6 @@ public: const amrex::ParticleReal m1 = species_1.getMass(); auto get_position_1 = GetParticlePosition(ptile_1, getpos_offset); - amrex::Geometry const& geom = WarpX::GetInstance().Geom(lev); -#if defined WARPX_DIM_1D_Z - auto dV = geom.CellSize(0); -#elif defined WARPX_DIM_XZ - auto dV = geom.CellSize(0) * geom.CellSize(1); -#elif defined WARPX_DIM_RZ - amrex::Box const& cbx = mfi.tilebox(amrex::IntVect::TheZeroVector()); //Cell-centered box - const auto lo = lbound(cbx); - const auto hi = ubound(cbx); - int const nz = hi.y-lo.y+1; - auto dr = geom.CellSize(0); - auto dz = geom.CellSize(1); -#elif defined(WARPX_DIM_3D) - auto dV = geom.CellSize(0) * geom.CellSize(1) * geom.CellSize(2); -#endif - /* The following calculations are only required when creating product particles */ @@ -363,17 +369,14 @@ public: // create vectors to store density and temperature on cell level amrex::Gpu::DeviceVector n1_vec; - amrex::Gpu::DeviceVector n12_vec; amrex::Gpu::DeviceVector T1_vec; if (binary_collision_functor.m_computeSpeciesDensities) { n1_vec.resize(n_cells); - n12_vec.resize(n_cells); } if (binary_collision_functor.m_computeSpeciesTemperatures) { T1_vec.resize(n_cells); } amrex::ParticleReal* AMREX_RESTRICT n1_in_each_cell = n1_vec.dataPtr(); - amrex::ParticleReal* AMREX_RESTRICT n12_in_each_cell = n12_vec.dataPtr(); amrex::ParticleReal* AMREX_RESTRICT T1_in_each_cell = T1_vec.dataPtr(); // Loop over cells @@ -384,7 +387,6 @@ public: // given by the `indices_1[cell_start_1:cell_stop_1]` index_type const cell_start_1 = cell_offsets_1[i_cell]; index_type const cell_stop_1 = cell_offsets_1[i_cell+1]; - index_type const cell_half_1 = (cell_start_1+cell_stop_1)/2; // Do not collide if there is only one particle in the cell if ( cell_stop_1 - cell_start_1 <= 1 ) { return; } @@ -396,11 +398,8 @@ public: for (index_type i1=cell_start_1; i1(ptile_2, getpos_offset); - amrex::Geometry const& geom = WarpX::GetInstance().Geom(lev); -#if defined WARPX_DIM_1D_Z - auto dV = geom.CellSize(0); -#elif defined WARPX_DIM_XZ - auto dV = geom.CellSize(0) * geom.CellSize(1); -#elif defined WARPX_DIM_RZ - amrex::Box const& cbx = mfi.tilebox(amrex::IntVect::TheZeroVector()); //Cell-centered box - const auto lo = lbound(cbx); - const auto hi = ubound(cbx); - const int nz = hi.y-lo.y+1; - auto dr = geom.CellSize(0); - auto dz = geom.CellSize(1); -#elif defined(WARPX_DIM_3D) - auto dV = geom.CellSize(0) * geom.CellSize(1) * geom.CellSize(2); -#endif - /* The following calculations are only required when creating product particles */ @@ -642,12 +595,10 @@ public: // create vectors to store density and temperature on cell level amrex::Gpu::DeviceVector n1_vec, n2_vec; - amrex::Gpu::DeviceVector n12_vec; amrex::Gpu::DeviceVector T1_vec, T2_vec; if (binary_collision_functor.m_computeSpeciesDensities) { n1_vec.resize(n_cells); n2_vec.resize(n_cells); - n12_vec.resize(n_cells); } if (binary_collision_functor.m_computeSpeciesTemperatures) { T1_vec.resize(n_cells); @@ -655,7 +606,6 @@ public: } amrex::ParticleReal* AMREX_RESTRICT n1_in_each_cell = n1_vec.dataPtr(); amrex::ParticleReal* AMREX_RESTRICT n2_in_each_cell = n2_vec.dataPtr(); - amrex::ParticleReal* AMREX_RESTRICT n12_in_each_cell = n12_vec.dataPtr(); amrex::ParticleReal* AMREX_RESTRICT T1_in_each_cell = T1_vec.dataPtr(); amrex::ParticleReal* AMREX_RESTRICT T2_in_each_cell = T2_vec.dataPtr(); @@ -687,12 +637,8 @@ public: for (index_type i2=cell_start_2; i2( 1.0/std::cbrt(4.0*MathConst::pi/3.0*maxn) ); + + // bmax (screening length) cannot be smaller than atomic spacing + const T_PR bmax = amrex::max(lmdD, rmin); + + // set max cross section based on mfp = atomic spacing + const T_PR sigma_max = T_PR(1.0) / (maxn * rmin); #if (defined WARPX_DIM_RZ) T_PR * const AMREX_RESTRICT theta1 = soa_1.m_rdata[PIdx::theta]; @@ -108,13 +115,22 @@ void ElasticCollisionPerez ( u1y[I1[i1]] = u1xbuf*std::sin(theta) + u1y[I1[i1]]*std::cos(theta); #endif + // Compute the effective density n12 used to compute the normalized + // scattering path s12 in UpdateMomentumPerezElastic(). + // s12 is defined such that the expected value of the change in particle + // velocity is equal to that from the full NxN pairing method, as described + // here https://arxiv.org/abs/2407.19151. This method is a direct extension + // of the original method by Takizuka and Abe JCP 25 (1977) to weighted particles. + T_PR n12; + const T_PR wpmax = amrex::max(w1[ I1[i1] ],w2[ I2[i2] ]); + if (isSameSpecies) { n12 = wpmax*static_cast(min_N+max_N-1)/dV; } + else { n12 = wpmax*static_cast(min_N)/dV; } + UpdateMomentumPerezElastic( u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ], u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ], - n1, n2, n12, q1, m1, w1[ I1[i1] ], q2, m2, w2[ I2[i2] ], - dt, L, lmdD, - engine); + n12, sigma_max, L, bmax, dt, engine ); #if (defined WARPX_DIM_RZ) T_PR const u1xbuf_new = u1x[I1[i1]]; diff --git a/Source/Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H b/Source/Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H index cd3cd5a5c83..3322c19ed2d 100644 --- a/Source/Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H +++ b/Source/Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H @@ -91,11 +91,10 @@ public: const SoaData_type& soa_1, const SoaData_type& soa_2, GetParticlePosition /*get_position_1*/, GetParticlePosition /*get_position_2*/, amrex::ParticleReal const n1, amrex::ParticleReal const n2, - amrex::ParticleReal const n12, amrex::ParticleReal const T1, amrex::ParticleReal const T2, amrex::ParticleReal const q1, amrex::ParticleReal const q2, amrex::ParticleReal const m1, amrex::ParticleReal const m2, - amrex::Real const dt, amrex::Real const /*dV*/, index_type coll_idx, + amrex::Real const dt, amrex::Real const dV, index_type coll_idx, index_type const /*cell_start_pair*/, index_type* /*p_mask*/, index_type* /*p_pair_indices_1*/, index_type* /*p_pair_indices_2*/, amrex::ParticleReal* /*p_pair_reaction_weight*/, @@ -105,9 +104,9 @@ public: ElasticCollisionPerez( I1s, I1e, I2s, I2e, I1, I2, - soa_1, soa_2, n1, n2, n12, T1, T2, + soa_1, soa_2, n1, n2, T1, T2, q1, q2, m1, m2, - dt, m_CoulombLog, engine, coll_idx); + dt, m_CoulombLog, dV, engine, m_isSameSpecies, coll_idx); } amrex::ParticleReal m_CoulombLog; diff --git a/Source/Particles/Collision/BinaryCollision/Coulomb/UpdateMomentumPerezElastic.H b/Source/Particles/Collision/BinaryCollision/Coulomb/UpdateMomentumPerezElastic.H index 3101047e211..f6403071aec 100644 --- a/Source/Particles/Collision/BinaryCollision/Coulomb/UpdateMomentumPerezElastic.H +++ b/Source/Particles/Collision/BinaryCollision/Coulomb/UpdateMomentumPerezElastic.H @@ -18,9 +18,12 @@ /* \brief Update particle velocities according to * F. Perez et al., Phys.Plasmas.19.083104 (2012), * which is based on Nanbu's method, PhysRevE.55.4642 (1997). - * @param[in] LmdD is max(Debye length, minimal interparticle distance). + * @param[in] bmax is max(Debye length, minimal interparticle distance). * @param[in] L is the Coulomb log. A fixed L will be used if L > 0, * otherwise L will be calculated based on the algorithm. + * @param[in] n12 = max(w1,w2)*min(N1,N2)/dV is the effective density used for s12 + * @param[in] sigma_max is the maximum cross section based on mfp = atomic spacing + * used for the normalized scattering length s12 (see Sec. II.C of Perez et al.) * To see if there are nan or inf updated velocities, * compile with USE_ASSERTION=TRUE. * @@ -33,27 +36,29 @@ template AMREX_GPU_HOST_DEVICE AMREX_INLINE void UpdateMomentumPerezElastic ( T_PR& u1x, T_PR& u1y, T_PR& u1z, T_PR& u2x, T_PR& u2y, T_PR& u2z, - T_PR const n1, T_PR const n2, T_PR const n12, T_PR const q1, T_PR const m1, T_PR const w1, T_PR const q2, T_PR const m2, T_PR const w2, - T_R const dt, T_PR const L, T_PR const lmdD, - amrex::RandomEngine const& engine) + T_PR const n12, T_PR const sigma_max, + T_PR const L, T_PR const bmax, + T_R const dt, amrex::RandomEngine const& engine ) { - T_PR const diffx = amrex::Math::abs(u1x-u2x); - T_PR const diffy = amrex::Math::abs(u1y-u2y); - T_PR const diffz = amrex::Math::abs(u1z-u2z); - T_PR const diffm = std::sqrt(diffx*diffx+diffy*diffy+diffz*diffz); - T_PR const summm = std::sqrt(u1x*u1x+u1y*u1y+u1z*u1z) + std::sqrt(u2x*u2x+u2y*u2y+u2z*u2z); - // If g = u1 - u2 = 0, do not collide. - // Or if the relative difference is less than 1.0e-10. - if ( diffm < std::numeric_limits::min() || diffm/summm < 1.0e-10 ) { return; } - T_PR constexpr inv_c2 = T_PR(1.0) / ( PhysConst::c * PhysConst::c ); // Compute Lorentz factor gamma - T_PR const g1 = std::sqrt( T_PR(1.0) + (u1x*u1x+u1y*u1y+u1z*u1z)*inv_c2 ); - T_PR const g2 = std::sqrt( T_PR(1.0) + (u2x*u2x+u2y*u2y+u2z*u2z)*inv_c2 ); + T_PR const gb1sq = (u1x*u1x + u1y*u1y + u1z*u1z)*inv_c2; + T_PR const gb2sq = (u2x*u2x + u2y*u2y + u2z*u2z)*inv_c2; + T_PR const g1 = std::sqrt( T_PR(1.0) + gb1sq ); + T_PR const g2 = std::sqrt( T_PR(1.0) + gb2sq ); + + T_PR const diffx = u1x-u2x; + T_PR const diffy = u1y-u2y; + T_PR const diffz = u1z-u2z; + T_PR const diffm = std::sqrt((diffx*diffx+diffy*diffy+diffz*diffz)*inv_c2); + T_PR const summm = std::sqrt(gb1sq) + std::sqrt(gb2sq); + // If g = u1 - u2 = 0, do not collide. + // Or if the relative difference is less than 1.0e-10. + if ( diffm < std::numeric_limits::min() || diffm/summm < 1.0e-10 ) { return; } // Compute momenta T_PR const p1x = u1x * m1; @@ -63,7 +68,7 @@ void UpdateMomentumPerezElastic ( T_PR const p2y = u2y * m2; T_PR const p2z = u2z * m2; - // Compute center-of-mass (COM) velocity and gamma + // Compute center-of-momentum (COM) velocity and gamma T_PR const mass_g = m1 * g1 + m2 * g2; T_PR const vcx = (p1x+p2x) / mass_g; T_PR const vcy = (p1y+p2y) / mass_g; @@ -76,84 +81,78 @@ void UpdateMomentumPerezElastic ( T_PR const vcDv2 = (vcx*u2x + vcy*u2y + vcz*u2z) / g2; // Compute p1 star - T_PR p1sx; - T_PR p1sy; - T_PR p1sz; - if ( vcms > std::numeric_limits::min() ) - { - /* lorentz_transform_factor = ( (gc-1.0)/vcms*vcDv1 - gc )*m1*g1; - * Rewrite to avoid loss of precision from subtracting similar - * numbers when gc is close to 1 */ - T_PR const lorentz_transform_factor = - ( (gc*gc*vcms*inv_c2/(T_PR(1.0) + gc))/vcms*vcDv1 - gc )*m1*g1; - p1sx = p1x + vcx*lorentz_transform_factor; - p1sy = p1y + vcy*lorentz_transform_factor; - p1sz = p1z + vcz*lorentz_transform_factor; - } - else // If vcms = 0, don't do Lorentz-transform. - { - p1sx = p1x; - p1sy = p1y; - p1sz = p1z; - } + // lorentz_transform_factor = ( (gc-1.0)/vcms*vcDv1 - gc )*m1*g1 + // Rewrite by multiplying and dividing first term by (gc+1) to + // avoid loss of precision when gc is close to 1 + T_PR const lorentz_transform_factor = + ( gc*gc*vcDv1*inv_c2/(T_PR(1.0) + gc) - gc )*m1*g1; + T_PR const p1sx = p1x + vcx*lorentz_transform_factor; + T_PR const p1sy = p1y + vcy*lorentz_transform_factor; + T_PR const p1sz = p1z + vcz*lorentz_transform_factor; T_PR const p1sm = std::sqrt( p1sx*p1sx + p1sy*p1sy + p1sz*p1sz ); // Compute gamma star T_PR const g1s = ( T_PR(1.0) - vcDv1*inv_c2 )*gc*g1; T_PR const g2s = ( T_PR(1.0) - vcDv2*inv_c2 )*gc*g2; - // Compute s - T_PR s = 0; + // Compute relative velocity in center-of-momentum frame + // (not a Lorentz invariant quantity) + T_PR const muRst = g1s*m1*g2s*m2/(g1s*m1 + g2s*m2); + T_PR const vrelst = p1sm/muRst; // |v1s - v2s| + + // Compute invariant relative velocity in center-of-momentum frame + // (Lorentz invariant quantity) + T_PR const denom = T_PR(1.0) + p1sm*p1sm/(m1*g1s*m2*g2s)*inv_c2; // (1.0 - v1s*v2s/c^2) + T_PR const vrelst_invar = vrelst/denom; // |v1s - v2s|/(1.0 - v1s*v2s/c^2) + + // Compute s12 + T_PR s12 = 0; if (p1sm > std::numeric_limits::min()) { - // s is non-zero (i.e. particles scatter) only if the relative - // motion between particles is not negligible (p1sm non-zero) + // Writing b0 in a form that is directly analagous to the well-known non-relativistic form. + // See Eq. 3.3.2 in Principles of Plasma Discharges and Material Processing by + // M. A. Lieberman and A. J. Lichtenberg. + // Note that b0 on Eq. 22 of Perez POP 19 (2012) is bmin = b0/2, + // Note: there is a typo in Eq 22 of Perez, the last square is incorrect! + // See the SMILEI documentation: https://smileipic.github.io/Smilei/Understand/collisions.html + // and https://github.com/ECP-WarpX/WarpX/files/3799803/main.pdf from GitHub #429 + T_PR const b0 = amrex::Math::abs(q1*q2) / + (T_PR(2.0)*MathConst::pi*PhysConst::ep0*muRst*vrelst*vrelst_invar); + // Compute the Coulomb log lnLmd first T_PR lnLmd; if ( L > T_PR(0.0) ) { lnLmd = L; } else { - // Compute b0 according to eq (22) from Perez et al., Phys.Plasmas.19.083104 (2012) - // Note: there is a typo in the equation, the last square is incorrect! - // See the SMILEI documentation: https://smileipic.github.io/Smilei/Understand/collisions.html - // and https://github.com/ECP-WarpX/WarpX/files/3799803/main.pdf from GitHub #429 - T_PR const b0 = amrex::Math::abs(q1*q2) * inv_c2 / - (T_PR(4.0)*MathConst::pi*PhysConst::ep0) * gc/mass_g * - ( m1*g1s*m2*g2s/(p1sm*p1sm*inv_c2) + T_PR(1.0) ); - - // Compute the minimal impact parameter - constexpr T_PR hbar_pi = static_cast(PhysConst::hbar*MathConst::pi); - const T_PR bmin = amrex::max(hbar_pi/p1sm, b0); + + // Compute the minimum impact parameter from quantum: bqm = lDB/(4*pi) = hbar/(2*p1sm) + // See NRL formulary. Also see "An introduction to the physics of the Coulomb logarithm, + // with emphasis on quantum-mechanical effects", J. Plasma Phys. vol. 85 (2019). by J.A. Krommes. + // Note: The formula in Perez 2012 and in Lee and More 1984 uses h rather than + // hbar for bqm. If this is used, then the transition energy where bmin goes from classical + // to quantum is only 2.5 eV for electrons; compared to 100 eV when using hbar. + const T_PR bmin_qm = static_cast(PhysConst::hbar*0.5/p1sm); + + // Set the minimum impact parameter + const T_PR bmin = amrex::max(bmin_qm, T_PR(0.5)*b0); // Compute the Coulomb log lnLmd lnLmd = amrex::max( T_PR(2.0), - T_PR(0.5)*std::log(T_PR(1.0)+lmdD*lmdD/(bmin*bmin)) ); + T_PR(0.5)*std::log(T_PR(1.0) + bmax*bmax/(bmin*bmin)) ); } - // Compute s - const auto tts = m1*g1s*m2*g2s/(inv_c2*p1sm*p1sm) + T_PR(1.0); - const auto tts2 = tts*tts; - s = n1*n2/n12 * dt*lnLmd*q1*q1*q2*q2 / - ( T_PR(4.0) * MathConst::pi * PhysConst::ep0 * PhysConst::ep0 * - m1*g1*m2*g2/(inv_c2*inv_c2) ) * gc*p1sm/mass_g * tts2; - - // Compute s' - const auto cbrt_n1 = std::cbrt(n1); - const auto cbrt_n2 = std::cbrt(n2); - const auto coeff = static_cast( - std::pow(4.0*MathConst::pi/3.0,1.0/3.0)); - T_PR const vrel = mass_g*p1sm/(m1*g1s*m2*g2s*gc); - T_PR const sp = coeff * n1*n2/n12 * dt * vrel * (m1+m2) / - amrex::max( m1*cbrt_n1*cbrt_n1, - m2*cbrt_n2*cbrt_n2); - - // Determine s - s = amrex::min(s,sp); + // Compute s12 with sigma limited by sigma_max where mfp = atomic spacing + // See https://github.com/user-attachments/files/16555064/CoulombScattering_s12.pdf + // for a proof that this expression for s12 is the same as Eq. 9 of Perez 2012 when + // sigma_eff = pi*b0^2*lnLmd + const T_PR sigma_eff = amrex::min(T_PR(MathConst::pi)*b0*b0*lnLmd,sigma_max); + s12 = sigma_eff * n12 * dt * vrelst * g1s*g2s/(g1*g2); + } - // Only modify momenta if is s is non-zero - if (s > std::numeric_limits::min()) { + // Only modify momenta if s12 is non-zero + if (s12 > std::numeric_limits::min()) { // Get random numbers T_PR r = amrex::Random(engine); @@ -161,27 +160,27 @@ void UpdateMomentumPerezElastic ( // Compute scattering angle T_PR cosXs; T_PR sinXs; - if ( s <= T_PR(0.1) ) + if ( s12 <= T_PR(0.1) ) { while ( true ) { - cosXs = T_PR(1.0) + s * std::log(r); + cosXs = T_PR(1.0) + s12 * std::log(r); // Avoid the bug when r is too small such that cosXs < -1 if ( cosXs >= T_PR(-1.0) ) { break; } r = amrex::Random(engine); } } - else if ( s > T_PR(0.1) && s <= T_PR(3.0) ) + else if ( s12 > T_PR(0.1) && s12 <= T_PR(3.0) ) { T_PR const Ainv = static_cast( - 0.0056958 + 0.9560202*s - 0.508139*s*s + - 0.47913906*s*s*s - 0.12788975*s*s*s*s + 0.02389567*s*s*s*s*s); + 0.0056958 + 0.9560202*s12 - 0.508139*s12*s12 + + 0.47913906*s12*s12*s12 - 0.12788975*s12*s12*s12*s12 + 0.02389567*s12*s12*s12*s12*s12); cosXs = Ainv * std::log( std::exp(T_PR(-1.0)/Ainv) + T_PR(2.0) * r * std::sinh(T_PR(1.0)/Ainv) ); } - else if ( s > T_PR(3.0) && s <= T_PR(6.0) ) + else if ( s12 > T_PR(3.0) && s12 <= T_PR(6.0) ) { - T_PR const A = T_PR(3.0) * std::exp(-s); + T_PR const A = T_PR(3.0) * std::exp(-s12); cosXs = T_PR(1.0)/A * std::log( std::exp(-A) + T_PR(2.0) * r * std::sinh(A) ); } @@ -240,33 +239,18 @@ void UpdateMomentumPerezElastic ( T_PR const p2fsz = -p1fsz; // Transform from COM to lab frame - T_PR p1fx; T_PR p2fx; - T_PR p1fy; T_PR p2fy; - T_PR p1fz; T_PR p2fz; - if ( vcms > std::numeric_limits::min() ) - { - T_PR const vcDp1fs = vcx*p1fsx + vcy*p1fsy + vcz*p1fsz; - T_PR const vcDp2fs = vcx*p2fsx + vcy*p2fsy + vcz*p2fsz; - /* factor = (gc-1.0)/vcms; Rewrite to avoid subtraction losing precision when gc is close to 1 */ - T_PR const factor = gc*gc*inv_c2/(gc+T_PR(1.0)); - T_PR const factor1 = factor*vcDp1fs + m1*g1s*gc; - T_PR const factor2 = factor*vcDp2fs + m2*g2s*gc; - p1fx = p1fsx + vcx * factor1; - p1fy = p1fsy + vcy * factor1; - p1fz = p1fsz + vcz * factor1; - p2fx = p2fsx + vcx * factor2; - p2fy = p2fsy + vcy * factor2; - p2fz = p2fsz + vcz * factor2; - } - else // If vcms = 0, don't do Lorentz-transform. - { - p1fx = p1fsx; - p1fy = p1fsy; - p1fz = p1fsz; - p2fx = p2fsx; - p2fy = p2fsy; - p2fz = p2fsz; - } + T_PR const vcDp1fs = vcx*p1fsx + vcy*p1fsy + vcz*p1fsz; + T_PR const vcDp2fs = vcx*p2fsx + vcy*p2fsy + vcz*p2fsz; + /* factor = (gc-1.0)/vcms; Rewrite to avoid subtraction losing precision when gc is close to 1 */ + T_PR const factor = gc*gc*inv_c2/(gc+T_PR(1.0)); + T_PR const factor1 = factor*vcDp1fs + m1*g1s*gc; + T_PR const factor2 = factor*vcDp2fs + m2*g2s*gc; + T_PR const p1fx = p1fsx + vcx * factor1; + T_PR const p1fy = p1fsy + vcy * factor1; + T_PR const p1fz = p1fsz + vcz * factor1; + T_PR const p2fx = p2fsx + vcx * factor2; + T_PR const p2fy = p2fsy + vcy * factor2; + T_PR const p2fz = p2fsz + vcz * factor2; // Rejection method r = amrex::Random(engine); diff --git a/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H b/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H index 152dca4e1a1..a692d2cbb9e 100644 --- a/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H +++ b/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H @@ -97,7 +97,6 @@ public: const SoaData_type& soa_1, const SoaData_type& soa_2, GetParticlePosition /*get_position_1*/, GetParticlePosition /*get_position_2*/, amrex::ParticleReal const /*n1*/, amrex::ParticleReal const /*n2*/, - amrex::ParticleReal const /*n12*/, amrex::ParticleReal const /*T1*/, amrex::ParticleReal const /*T2*/, amrex::ParticleReal const /*q1*/, amrex::ParticleReal const /*q2*/, amrex::ParticleReal const m1, amrex::ParticleReal const m2, @@ -111,11 +110,13 @@ public: amrex::ParticleReal * const AMREX_RESTRICT u1x = soa_1.m_rdata[PIdx::ux]; amrex::ParticleReal * const AMREX_RESTRICT u1y = soa_1.m_rdata[PIdx::uy]; amrex::ParticleReal * const AMREX_RESTRICT u1z = soa_1.m_rdata[PIdx::uz]; + uint64_t* AMREX_RESTRICT idcpu1 = soa_1.m_idcpu; amrex::ParticleReal * const AMREX_RESTRICT w2 = soa_2.m_rdata[PIdx::w]; amrex::ParticleReal * const AMREX_RESTRICT u2x = soa_2.m_rdata[PIdx::ux]; amrex::ParticleReal * const AMREX_RESTRICT u2y = soa_2.m_rdata[PIdx::uy]; amrex::ParticleReal * const AMREX_RESTRICT u2z = soa_2.m_rdata[PIdx::uz]; + uint64_t* AMREX_RESTRICT idcpu2 = soa_2.m_idcpu; // Number of macroparticles of each species const index_type NI1 = I1e - I1s; @@ -125,14 +126,9 @@ public: index_type pair_index = cell_start_pair + coll_idx; - // Because the number of particles of each species is not always equal (NI1 != NI2 - // in general), some macroparticles will be paired with multiple macroparticles of the - // other species and we need to decrease their weight accordingly. - // c1 corresponds to the minimum number of times a particle of species 1 will be paired - // with a particle of species 2. Same for c2. - // index_type(1): https://github.com/AMReX-Codes/amrex/pull/3684 - const index_type c1 = amrex::max(NI2/NI1, index_type(1)); - const index_type c2 = amrex::max(NI1/NI2, index_type(1)); + // multiplier ratio to take into account unsampled pairs + const auto multiplier_ratio = static_cast( + m_isSameSpecies ? min_N + max_N - 1 : min_N); #if (defined WARPX_DIM_RZ) amrex::ParticleReal * const AMREX_RESTRICT theta1 = soa_1.m_rdata[PIdx::theta]; @@ -144,49 +140,56 @@ public: // stride (smaller set size) until we do all collisions (larger set size) for (index_type k = coll_idx; k < max_N; k += min_N) { - // c1k : how many times the current particle of species 1 is paired with a particle - // of species 2. Same for c2k. - const index_type c1k = (k%NI1 < max_N%NI1) ? c1 + 1: c1; - const index_type c2k = (k%NI2 < max_N%NI2) ? c2 + 1: c2; + // do not check for collision if a particle's weight was + // reduced to zero from a previous collision + if (idcpu1[ I1[i1] ]==amrex::ParticleIdCpus::Invalid || + idcpu2[ I2[i2] ]==amrex::ParticleIdCpus::Invalid ) { + p_mask[pair_index] = false; + } else { #if (defined WARPX_DIM_RZ) - /* In RZ geometry, macroparticles can collide with other macroparticles - * in the same *cylindrical* cell. For this reason, collisions between macroparticles - * are actually not local in space. In this case, the underlying assumption is that - * particles within the same cylindrical cell represent a cylindrically-symmetry - * momentum distribution function. Therefore, here, we temporarily rotate the - * momentum of one of the macroparticles in agreement with this cylindrical symmetry. - * (This is technically only valid if we use only the m=0 azimuthal mode in the simulation; - * there is a corresponding assert statement at initialization.) - */ - amrex::ParticleReal const theta = theta2[I2[i2]]-theta1[I1[i1]]; - amrex::ParticleReal const u1xbuf = u1x[I1[i1]]; - u1x[I1[i1]] = u1xbuf*std::cos(theta) - u1y[I1[i1]]*std::sin(theta); - u1y[I1[i1]] = u1xbuf*std::sin(theta) + u1y[I1[i1]]*std::cos(theta); + /* In RZ geometry, macroparticles can collide with other macroparticles + * in the same *cylindrical* cell. For this reason, collisions between macroparticles + * are actually not local in space. In this case, the underlying assumption is that + * particles within the same cylindrical cell represent a cylindrically-symmetry + * momentum distribution function. Therefore, here, we temporarily rotate the + * momentum of one of the macroparticles in agreement with this cylindrical symmetry. + * (This is technically only valid if we use only the m=0 azimuthal mode in the simulation; + * there is a corresponding assert statement at initialization.) + */ + amrex::ParticleReal const theta = theta2[I2[i2]]-theta1[I1[i1]]; + amrex::ParticleReal const u1xbuf = u1x[I1[i1]]; + u1x[I1[i1]] = u1xbuf*std::cos(theta) - u1y[I1[i1]]*std::sin(theta); + u1y[I1[i1]] = u1xbuf*std::sin(theta) + u1y[I1[i1]]*std::cos(theta); #endif - CollisionPairFilter( - u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ], - u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ], - m1, m2, w1[ I1[i1] ]/c1k, w2[ I2[i2] ]/c2k, - dt, dV, static_cast(pair_index), p_mask, - p_pair_reaction_weight, static_cast(max_N), - m_process_count, m_scattering_processes_data, engine); + CollisionPairFilter( + u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ], + u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ], + m1, m2, w1[ I1[i1] ], w2[ I2[i2] ], + dt, dV, static_cast(pair_index), p_mask, + p_pair_reaction_weight, multiplier_ratio, + m_process_count, m_scattering_processes_data, engine); #if (defined WARPX_DIM_RZ) - amrex::ParticleReal const u1xbuf_new = u1x[I1[i1]]; - u1x[I1[i1]] = u1xbuf_new*std::cos(-theta) - u1y[I1[i1]]*std::sin(-theta); - u1y[I1[i1]] = u1xbuf_new*std::sin(-theta) + u1y[I1[i1]]*std::cos(-theta); + amrex::ParticleReal const u1xbuf_new = u1x[I1[i1]]; + u1x[I1[i1]] = u1xbuf_new*std::cos(-theta) - u1y[I1[i1]]*std::sin(-theta); + u1y[I1[i1]] = u1xbuf_new*std::sin(-theta) + u1y[I1[i1]]*std::cos(-theta); #endif + // Remove pair reaction weight from the colliding particles' weights + if (p_mask[pair_index]) { + BinaryCollisionUtils::remove_weight_from_colliding_particle( + w1[ I1[i1] ], idcpu1[ I1[i1] ], p_pair_reaction_weight[pair_index]); + BinaryCollisionUtils::remove_weight_from_colliding_particle( + w2[ I2[i2] ], idcpu2[ I2[i2] ], p_pair_reaction_weight[pair_index]); + } + } + p_pair_indices_1[pair_index] = I1[i1]; p_pair_indices_2[pair_index] = I2[i2]; - if (max_N == NI1) { - i1 += min_N; - } - if (max_N == NI2) { - i2 += min_N; - } + if (max_N == NI1) { i1 += min_N; } + if (max_N == NI2) { i2 += min_N; } pair_index += min_N; } } @@ -194,6 +197,7 @@ public: int m_process_count; bool m_computeSpeciesDensities = false; bool m_computeSpeciesTemperatures = false; + bool m_isSameSpecies = false; ScatteringProcess::Executor* m_scattering_processes_data; }; @@ -202,6 +206,7 @@ public: private: amrex::Vector m_scattering_processes; amrex::Gpu::DeviceVector m_scattering_processes_exe; + bool m_isSameSpecies; Executor m_exe; }; diff --git a/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.cpp b/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.cpp index 9ee676bf002..e40a4e9822c 100644 --- a/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.cpp +++ b/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.cpp @@ -19,7 +19,7 @@ DSMCFunc::DSMCFunc ( const std::string& collision_name, [[maybe_unused]] MultiParticleContainer const * const mypc, - [[maybe_unused]] const bool isSameSpecies ) + const bool isSameSpecies ): m_isSameSpecies{isSameSpecies} { using namespace amrex::literals; @@ -76,4 +76,5 @@ DSMCFunc::DSMCFunc ( // Link executor to appropriate ScatteringProcess executors m_exe.m_scattering_processes_data = m_scattering_processes_exe.data(); m_exe.m_process_count = process_count; + m_exe.m_isSameSpecies = m_isSameSpecies; } diff --git a/Source/Particles/Collision/BinaryCollision/DSMC/SplitAndScatterFunc.H b/Source/Particles/Collision/BinaryCollision/DSMC/SplitAndScatterFunc.H index a0c6ca8c8d4..473199a6b21 100644 --- a/Source/Particles/Collision/BinaryCollision/DSMC/SplitAndScatterFunc.H +++ b/Source/Particles/Collision/BinaryCollision/DSMC/SplitAndScatterFunc.H @@ -94,11 +94,6 @@ public: const auto soa_1 = ptile1.getParticleTileData(); const auto soa_2 = ptile2.getParticleTileData(); - amrex::ParticleReal* AMREX_RESTRICT w1 = soa_1.m_rdata[PIdx::w]; - amrex::ParticleReal* AMREX_RESTRICT w2 = soa_2.m_rdata[PIdx::w]; - uint64_t* AMREX_RESTRICT idcpu1 = soa_1.m_idcpu; - uint64_t* AMREX_RESTRICT idcpu2 = soa_2.m_idcpu; - // Create necessary GPU vectors, that will be used in the kernel below amrex::Vector soa_products; for (int i = 0; i < m_num_product_species; i++) @@ -151,12 +146,6 @@ public: // Set the weight of the new particles to p_pair_reaction_weight[i] soa_products_data[1].m_rdata[PIdx::w][product2_index] = p_pair_reaction_weight[i]; - // Remove p_pair_reaction_weight[i] from the colliding particles' weights - BinaryCollisionUtils::remove_weight_from_colliding_particle( - w1[p_pair_indices_1[i]], idcpu1[p_pair_indices_1[i]], p_pair_reaction_weight[i]); - BinaryCollisionUtils::remove_weight_from_colliding_particle( - w2[p_pair_indices_2[i]], idcpu2[p_pair_indices_2[i]], p_pair_reaction_weight[i]); - // Set the child particle properties appropriately auto& ux1 = soa_products_data[0].m_rdata[PIdx::ux][product1_index]; auto& uy1 = soa_products_data[0].m_rdata[PIdx::uy][product1_index]; diff --git a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H index 1f3e5e56582..14b1422db27 100644 --- a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H +++ b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H @@ -132,7 +132,6 @@ public: const SoaData_type& soa_1, const SoaData_type& soa_2, GetParticlePosition /*get_position_1*/, GetParticlePosition /*get_position_2*/, amrex::ParticleReal const /*n1*/, amrex::ParticleReal const /*n2*/, - amrex::ParticleReal const /*n12*/, amrex::ParticleReal const /*T1*/, amrex::ParticleReal const /*T2*/, amrex::ParticleReal const /*q1*/, amrex::ParticleReal const /*q2*/, amrex::ParticleReal const m1, amrex::ParticleReal const m2, @@ -146,11 +145,13 @@ public: amrex::ParticleReal * const AMREX_RESTRICT u1x = soa_1.m_rdata[PIdx::ux]; amrex::ParticleReal * const AMREX_RESTRICT u1y = soa_1.m_rdata[PIdx::uy]; amrex::ParticleReal * const AMREX_RESTRICT u1z = soa_1.m_rdata[PIdx::uz]; + uint64_t* AMREX_RESTRICT idcpu1 = soa_1.m_idcpu; amrex::ParticleReal * const AMREX_RESTRICT w2 = soa_2.m_rdata[PIdx::w]; amrex::ParticleReal * const AMREX_RESTRICT u2x = soa_2.m_rdata[PIdx::ux]; amrex::ParticleReal * const AMREX_RESTRICT u2y = soa_2.m_rdata[PIdx::uy]; amrex::ParticleReal * const AMREX_RESTRICT u2z = soa_2.m_rdata[PIdx::uz]; + uint64_t* AMREX_RESTRICT idcpu2 = soa_2.m_idcpu; // Number of macroparticles of each species const index_type NI1 = I1e - I1s; @@ -160,18 +161,9 @@ public: index_type pair_index = cell_start_pair + coll_idx; - // Because the number of particles of each species is not always equal (NI1 != NI2 - // in general), some macroparticles will be paired with multiple macroparticles of the - // other species and we need to decrease their weight accordingly. - // c1 corresponds to the minimum number of times a particle of species 1 will be paired - // with a particle of species 2. Same for c2. - // index_type(1): https://github.com/AMReX-Codes/amrex/pull/3684 - const index_type c1 = amrex::max(NI2/NI1, index_type(1)); - const index_type c2 = amrex::max(NI1/NI2, index_type(1)); - // multiplier ratio to take into account unsampled pairs const auto multiplier_ratio = static_cast( - m_isSameSpecies ? 2*max_N - 1 : max_N); + m_isSameSpecies ? min_N + max_N - 1 : min_N); #if (defined WARPX_DIM_RZ) amrex::ParticleReal * const AMREX_RESTRICT theta1 = soa_1.m_rdata[PIdx::theta]; @@ -183,50 +175,60 @@ public: // stride (smaller set size) until we do all collisions (larger set size) for (index_type k = coll_idx; k < max_N; k += min_N) { - // c1k : how many times the current particle of species 1 is paired with a particle - // of species 2. Same for c2k. - const index_type c1k = (k%NI1 < max_N%NI1) ? c1 + 1: c1; - const index_type c2k = (k%NI2 < max_N%NI2) ? c2 + 1: c2; + + // do not check for collision if a particle's weight was + // reduced to zero from a previous collision + if (idcpu1[ I1[i1] ]==amrex::ParticleIdCpus::Invalid || + idcpu2[ I2[i2] ]==amrex::ParticleIdCpus::Invalid ) { + p_mask[pair_index] = false; + } + else { #if (defined WARPX_DIM_RZ) - /* In RZ geometry, macroparticles can collide with other macroparticles - * in the same *cylindrical* cell. For this reason, collisions between macroparticles - * are actually not local in space. In this case, the underlying assumption is that - * particles within the same cylindrical cell represent a cylindrically-symmetry - * momentum distribution function. Therefore, here, we temporarily rotate the - * momentum of one of the macroparticles in agreement with this cylindrical symmetry. - * (This is technically only valid if we use only the m=0 azimuthal mode in the simulation; - * there is a corresponding assert statement at initialization.) */ - amrex::ParticleReal const theta = theta2[I2[i2]]-theta1[I1[i1]]; - amrex::ParticleReal const u1xbuf = u1x[I1[i1]]; - u1x[I1[i1]] = u1xbuf*std::cos(theta) - u1y[I1[i1]]*std::sin(theta); - u1y[I1[i1]] = u1xbuf*std::sin(theta) + u1y[I1[i1]]*std::cos(theta); + /* In RZ geometry, macroparticles can collide with other macroparticles + * in the same *cylindrical* cell. For this reason, collisions between macroparticles + * are actually not local in space. In this case, the underlying assumption is that + * particles within the same cylindrical cell represent a cylindrically-symmetry + * momentum distribution function. Therefore, here, we temporarily rotate the + * momentum of one of the macroparticles in agreement with this cylindrical symmetry. + * (This is technically only valid if we use only the m=0 azimuthal mode in the simulation; + * there is a corresponding assert statement at initialization.) */ + amrex::ParticleReal const theta = theta2[I2[i2]]-theta1[I1[i1]]; + amrex::ParticleReal const u1xbuf = u1x[I1[i1]]; + u1x[I1[i1]] = u1xbuf*std::cos(theta) - u1y[I1[i1]]*std::sin(theta); + u1y[I1[i1]] = u1xbuf*std::sin(theta) + u1y[I1[i1]]*std::cos(theta); #endif - SingleNuclearFusionEvent( - u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ], - u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ], - m1, m2, w1[ I1[i1] ]/c1k, w2[ I2[i2] ]/c2k, - dt, dV, static_cast(pair_index), p_mask, p_pair_reaction_weight, - m_fusion_multiplier, multiplier_ratio, - m_probability_threshold, - m_probability_target_value, - m_fusion_type, engine); + SingleNuclearFusionEvent( + u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ], + u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ], + m1, m2, w1[ I1[i1] ], w2[ I2[i2] ], + dt, dV, static_cast(pair_index), p_mask, p_pair_reaction_weight, + m_fusion_multiplier, multiplier_ratio, + m_probability_threshold, + m_probability_target_value, + m_fusion_type, engine); #if (defined WARPX_DIM_RZ) - amrex::ParticleReal const u1xbuf_new = u1x[I1[i1]]; - u1x[I1[i1]] = u1xbuf_new*std::cos(-theta) - u1y[I1[i1]]*std::sin(-theta); - u1y[I1[i1]] = u1xbuf_new*std::sin(-theta) + u1y[I1[i1]]*std::cos(-theta); + amrex::ParticleReal const u1xbuf_new = u1x[I1[i1]]; + u1x[I1[i1]] = u1xbuf_new*std::cos(-theta) - u1y[I1[i1]]*std::sin(-theta); + u1y[I1[i1]] = u1xbuf_new*std::sin(-theta) + u1y[I1[i1]]*std::cos(-theta); #endif + // Remove pair reaction weight from the colliding particles' weights + if (p_mask[pair_index]) { + BinaryCollisionUtils::remove_weight_from_colliding_particle( + w1[ I1[i1] ], idcpu1[ I1[i1] ], p_pair_reaction_weight[pair_index]); + BinaryCollisionUtils::remove_weight_from_colliding_particle( + w2[ I2[i2] ], idcpu2[ I2[i2] ], p_pair_reaction_weight[pair_index]); + } + + } + p_pair_indices_1[pair_index] = I1[i1]; p_pair_indices_2[pair_index] = I2[i2]; - if (max_N == NI1) { - i1 += min_N; - } - if (max_N == NI2) { - i2 += min_N; - } + if (max_N == NI1) { i1 += min_N; } + if (max_N == NI2) { i2 += min_N; } pair_index += min_N; } } diff --git a/Source/Particles/Collision/BinaryCollision/NuclearFusion/ProtonBoronFusionInitializeMomentum.H b/Source/Particles/Collision/BinaryCollision/NuclearFusion/ProtonBoronFusionInitializeMomentum.H index 375cc1e6d51..63f35d3d254 100644 --- a/Source/Particles/Collision/BinaryCollision/NuclearFusion/ProtonBoronFusionInitializeMomentum.H +++ b/Source/Particles/Collision/BinaryCollision/NuclearFusion/ProtonBoronFusionInitializeMomentum.H @@ -33,11 +33,11 @@ namespace { * \brief This function initializes the momentum of the alpha particles produced from * proton-boron fusion. The momentum is initialized by assuming that the fusion of a proton * with a boron nucleus into 3 alphas takes place in two steps. In the first step, the proton - * and the boron fuse into a beryllium nucleus and an alpha particle. In the second step, the - * beryllium decays into two alpha particles. The first step produces 8.59009 MeV of kinetic - * energy while the second step produces 91.8984 keV of kinetic energy. This two-step process + * and the boron fuse into an excited beryllium nucleus and an alpha particle. In the second step, the + * excited beryllium decays into two alpha particles. The first step produces ~5.56 MeV of kinetic + * energy while the second step produces ~3.12 MeV of kinetic energy. This two-step process * is considered to be the dominant process of proton+boron fusion into alphas (see - * Becker et al., Zeitschrift für Physik A Atomic Nuclei, 327(3), 341-355 (1987)). + * D.R. Tilley et al. / Nuclear Physics A 745 (2004) 155–362). * For each step, we assume in this function that the particles are emitted isotropically in * the corresponding center of mass frame (center of mass frame of proton + boron for the * creation of first alpha+beryllium and rest frame of beryllium for the creation of second and @@ -73,18 +73,21 @@ namespace { constexpr amrex::ParticleReal mev_to_joule = PhysConst::q_e*1.e6_prt; // Energy produced in the fusion reaction proton + boron11 -> Beryllium8 + alpha - // cf. Janis book of proton-induced cross-sections (2019) - constexpr amrex::ParticleReal E_fusion = 8.59009_prt*mev_to_joule; + // cf. https://doi.org/10.1016/j.radphyschem.2022.110727 + // Dominant reaction channel is p + B11 -> alpha_1 + 8Be* -> alpha_1 + alpha_11 + alpha_12 + 8.68 MeV + // cf. Kelley et al., (2017) http://dx.doi.org/10.1016/j.nuclphysa.2017.07.015 + constexpr amrex::ParticleReal E_fusion = 5.55610759_prt*mev_to_joule; // Energy produced when Beryllium8 decays into two alphas - // cf. JEFF-3.3 radioactive decay data library (2017) - constexpr amrex::ParticleReal E_decay = 0.0918984_prt*mev_to_joule; + // cf. Kelley et al., (2017) http://dx.doi.org/10.1016/j.nuclphysa.2017.07.015 + constexpr amrex::ParticleReal E_decay = 3.12600414_prt*mev_to_joule; // The constexprs ma_sq and mBe_sq underflow in single precision because we use SI units, // which can cause compilation to fail or generate a warning, so we're explicitly setting // them as double. Note that nuclear fusion module does not currently work with single // precision anyways. constexpr double m_alpha = PhysConst::m_u * 4.00260325413_prt; - constexpr double m_beryllium = PhysConst::m_p * 7.94748_prt; + // mass of the Be8 excited state (3.03 MeV above ground state) + constexpr double m_beryllium = PhysConst::m_u*(8.0053095729_prt+0.00325283863_prt); constexpr double mBe_sq = m_beryllium*m_beryllium; constexpr amrex::ParticleReal c_sq = PhysConst::c * PhysConst::c; diff --git a/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H b/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H index 3cb7197b93a..e4772aab7c9 100644 --- a/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H +++ b/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H @@ -131,11 +131,6 @@ public: const auto soa_1 = ptile1.getParticleTileData(); const auto soa_2 = ptile2.getParticleTileData(); - amrex::ParticleReal* AMREX_RESTRICT w1 = soa_1.m_rdata[PIdx::w]; - amrex::ParticleReal* AMREX_RESTRICT w2 = soa_2.m_rdata[PIdx::w]; - uint64_t* AMREX_RESTRICT idcpu1 = soa_1.m_idcpu; - uint64_t* AMREX_RESTRICT idcpu2 = soa_2.m_idcpu; - // Create necessary GPU vectors, that will be used in the kernel below amrex::Vector soa_products; for (int i = 0; i < m_num_product_species; i++) @@ -197,12 +192,6 @@ public: } } - // Remove p_pair_reaction_weight[i] from the colliding particles' weights - BinaryCollisionUtils::remove_weight_from_colliding_particle( - w1[p_pair_indices_1[i]], idcpu1[p_pair_indices_1[i]], p_pair_reaction_weight[i]); - BinaryCollisionUtils::remove_weight_from_colliding_particle( - w2[p_pair_indices_2[i]], idcpu2[p_pair_indices_2[i]], p_pair_reaction_weight[i]); - // Initialize the product particles' momentum, using a function depending on the // specific collision type if (t_collision_type == CollisionType::ProtonBoronToAlphasFusion) diff --git a/Source/Particles/Gather/FieldGather.H b/Source/Particles/Gather/FieldGather.H index 4b4590b8642..95a010031ec 100644 --- a/Source/Particles/Gather/FieldGather.H +++ b/Source/Particles/Gather/FieldGather.H @@ -1714,9 +1714,9 @@ void doGatherShapeNImplicit ( const amrex::Dim3& lo, const int n_rz_azimuthal_modes, const int nox, - const int depos_type ) + const CurrentDepositionAlgo depos_type ) { - if (depos_type==0) { // CurrentDepositionAlgo::Esirkepov + if (depos_type == CurrentDepositionAlgo::Esirkepov) { if (nox == 1) { doGatherShapeNEsirkepovStencilImplicit<1>(xp_n, yp_n, zp_n, xp_nph, yp_nph, zp_nph, Exp, Eyp, Ezp, Bxp, Byp, Bzp, @@ -1743,7 +1743,7 @@ void doGatherShapeNImplicit ( dinv, xyzmin, lo, n_rz_azimuthal_modes); } } - else if (depos_type==3) { // CurrentDepositionAlgo::Villasenor + else if (depos_type == CurrentDepositionAlgo::Villasenor) { if (nox == 1) { doGatherPicnicShapeN<1>(xp_n, yp_n, zp_n, xp_nph, yp_nph, zp_nph, Exp, Eyp, Ezp, Bxp, Byp, Bzp, @@ -1770,7 +1770,7 @@ void doGatherShapeNImplicit ( dinv, xyzmin, lo, n_rz_azimuthal_modes); } } - else if (depos_type==1) { // CurrentDepositionAlgo::Direct + else if (depos_type == CurrentDepositionAlgo::Direct) { if (nox == 1) { doGatherShapeN<1,0>(xp_nph, yp_nph, zp_nph, Exp, Eyp, Ezp, Bxp, Byp, Bzp, ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, diff --git a/Source/Particles/LaserParticleContainer.cpp b/Source/Particles/LaserParticleContainer.cpp index bd266ab368a..d43fb240756 100644 --- a/Source/Particles/LaserParticleContainer.cpp +++ b/Source/Particles/LaserParticleContainer.cpp @@ -181,10 +181,11 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, if (WarpX::gamma_boost > 1.) { // Check that the laser direction is equal to the boost direction - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( m_nvec[0]*WarpX::boost_direction[0] - + m_nvec[1]*WarpX::boost_direction[1] - + m_nvec[2]*WarpX::boost_direction[2] - 1. < 1.e-12, - "The Lorentz boost should be in the same direction as the laser propagation"); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + (m_nvec[0]-WarpX::boost_direction[0])*(m_nvec[0]-WarpX::boost_direction[0]) + + (m_nvec[1]-WarpX::boost_direction[1])*(m_nvec[1]-WarpX::boost_direction[1]) + + (m_nvec[2]-WarpX::boost_direction[2])*(m_nvec[2]-WarpX::boost_direction[2]) < 1.e-12, + "The Lorentz boost should be in the same direction as the laser propagation"); // Get the position of the plane, along the boost direction, in the lab frame // and convert the position of the antenna to the boosted frame m_Z0_lab = m_nvec[0]*m_position[0] + m_nvec[1]*m_position[1] + m_nvec[2]*m_position[2]; @@ -246,8 +247,10 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, windir[dir] = 1.0; #endif AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - (m_nvec[0]-windir[0]) + (m_nvec[1]-windir[1]) + (m_nvec[2]-windir[2]) - < 1.e-12, "do_continous_injection for laser particle only works" + + (m_nvec[0]-windir[0])*(m_nvec[0]-windir[0]) + + (m_nvec[1]-windir[1])*(m_nvec[1]-windir[1]) + + (m_nvec[2]-windir[2])*(m_nvec[2]-windir[2]) < 1.e-12, + "do_continous_injection for laser particle only works" + " if moving window direction and laser propagation direction are the same"); if ( WarpX::gamma_boost>1 ){ AMREX_ALWAYS_ASSERT_WITH_MESSAGE( @@ -410,12 +413,10 @@ LaserParticleContainer::InitData (int lev) #if defined(WARPX_DIM_3D) return {m_u_X[0]*(pos[0]-m_position[0])+m_u_X[1]*(pos[1]-m_position[1])+m_u_X[2]*(pos[2]-m_position[2]), m_u_Y[0]*(pos[0]-m_position[0])+m_u_Y[1]*(pos[1]-m_position[1])+m_u_Y[2]*(pos[2]-m_position[2])}; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) -# if defined(WARPX_DIM_RZ) +#elif defined(WARPX_DIM_RZ) return {pos[0]-m_position[0], 0.0_rt}; -# else +#elif defined(WARPX_DIM_XZ) return {m_u_X[0]*(pos[0]-m_position[0])+m_u_X[2]*(pos[2]-m_position[2]), 0.0_rt}; -# endif #else return {m_u_X[2]*(pos[2]-m_position[2]), 0.0_rt}; #endif @@ -731,13 +732,12 @@ LaserParticleContainer::ComputeSpacing (int lev, Real& Sx, Real& Sy) const Sy = std::min(std::min(dx[0]/(std::abs(m_u_Y[0])+eps), dx[1]/(std::abs(m_u_Y[1])+eps)), dx[2]/(std::abs(m_u_Y[2])+eps)); -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) -# if defined(WARPX_DIM_RZ) +#elif defined(WARPX_DIM_RZ) Sx = dx[0]; -# else + Sy = 1.0; +#elif defined(WARPX_DIM_XZ) Sx = std::min(dx[0]/(std::abs(m_u_X[0])+eps), dx[2]/(std::abs(m_u_X[2])+eps)); -# endif Sy = 1.0; #else Sx = 1.0; @@ -747,7 +747,7 @@ LaserParticleContainer::ComputeSpacing (int lev, Real& Sx, Real& Sy) const } void -LaserParticleContainer::ComputeWeightMobility (Real Sx, Real Sy) +LaserParticleContainer::ComputeWeightMobility ([[maybe_unused]] Real Sx, [[maybe_unused]] Real Sy) { // The mobility is the constant of proportionality between the field to // be emitted, and the corresponding velocity that the particles need to have. @@ -757,14 +757,7 @@ LaserParticleContainer::ComputeWeightMobility (Real Sx, Real Sy) m_mobility = eps/m_e_max; m_weight = PhysConst::ep0 / m_mobility; // Multiply by particle spacing -#if defined(WARPX_DIM_3D) - m_weight *= Sx * Sy; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - m_weight *= Sx; - amrex::ignore_unused(Sy); -#else - amrex::ignore_unused(Sx,Sy); -#endif + m_weight *= AMREX_D_TERM(1._rt, * Sx, * Sy); // When running in the boosted-frame, the input parameters (and in particular // the amplitude of the field) are given in the lab-frame. // Therefore, the mobility needs to be modified by a factor WarpX::gamma_boost. diff --git a/Source/Particles/Make.package b/Source/Particles/Make.package index 58cbe11a980..69918f69940 100644 --- a/Source/Particles/Make.package +++ b/Source/Particles/Make.package @@ -1,3 +1,4 @@ +CEXE_sources += AddPlasmaUtilities.cpp CEXE_sources += MultiParticleContainer.cpp CEXE_sources += WarpXParticleContainer.cpp CEXE_sources += RigidInjectedParticleContainer.cpp diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index f007d5088e3..97e4e1bc4da 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -89,6 +89,8 @@ public: return allcontainers[index]->meanParticleVelocity(); } + amrex::ParticleReal maxParticleVelocity(); + void AllocData (); void InitData (); diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index fc496217388..23af4177228 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -39,10 +39,8 @@ #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXProfilerWrapper.H" #include "Utils/WarpXUtil.H" -#ifdef AMREX_USE_EB -# include "EmbeddedBoundary/ParticleScraper.H" -# include "EmbeddedBoundary/ParticleBoundaryProcess.H" -#endif +#include "EmbeddedBoundary/ParticleScraper.H" +#include "EmbeddedBoundary/ParticleBoundaryProcess.H" #include "WarpX.H" @@ -399,6 +397,15 @@ MultiParticleContainer::GetParticleContainerFromName (const std::string& name) c return *allcontainers[i]; } +amrex::ParticleReal +MultiParticleContainer::maxParticleVelocity() { + amrex::ParticleReal max_v = 0.0_prt; + for (const auto &pc : allcontainers) { + max_v = std::max(max_v, pc->maxParticleVelocity()); + } + return max_v; +} + void MultiParticleContainer::AllocData () { @@ -958,13 +965,9 @@ void MultiParticleContainer::CheckIonizationProductSpecies() void MultiParticleContainer::ScrapeParticlesAtEB (const amrex::Vector& distance_to_eb) { -#ifdef AMREX_USE_EB for (auto& pc : allcontainers) { scrapeParticlesAtEB(*pc, distance_to_eb, ParticleBoundaryProcess::Absorb()); } -#else - amrex::ignore_unused(distance_to_eb); -#endif } #ifdef WARPX_QED diff --git a/Source/Particles/ParticleBoundaries_K.H b/Source/Particles/ParticleBoundaries_K.H index 71b95aae95a..5dd340d9053 100644 --- a/Source/Particles/ParticleBoundaries_K.H +++ b/Source/Particles/ParticleBoundaries_K.H @@ -109,17 +109,10 @@ namespace ApplyParticleBoundaries { */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void - apply_boundaries ( -#ifndef WARPX_DIM_1D_Z - amrex::ParticleReal& x, amrex::Real xmin, amrex::Real xmax, -#endif -#if (defined WARPX_DIM_3D) || (defined WARPX_DIM_RZ) - amrex::ParticleReal& y, -#endif -#if (defined WARPX_DIM_3D) - amrex::Real ymin, amrex::Real ymax, -#endif - amrex::ParticleReal& z, amrex::Real zmin, amrex::Real zmax, + apply_boundaries ([[maybe_unused]] amrex::ParticleReal& x, + [[maybe_unused]] amrex::ParticleReal& y, + [[maybe_unused]] amrex::ParticleReal& z, + amrex::XDim3 gridmin, amrex::XDim3 gridmax, amrex::ParticleReal& ux, amrex::ParticleReal& uy, amrex::ParticleReal& uz, bool& particle_lost, ParticleBoundaries::ParticleBoundariesData const& boundaries, @@ -131,7 +124,7 @@ namespace ApplyParticleBoundaries { #ifndef WARPX_DIM_1D_Z bool rethermalize_x = false; // stores if particle crosses x boundary and needs to be thermalized - apply_boundary(x, xmin, xmax, change_sign_ux, rethermalize_x, particle_lost, + apply_boundary(x, gridmin.x, gridmax.x, change_sign_ux, rethermalize_x, particle_lost, boundaries.xmin_bc, boundaries.xmax_bc, boundaries.reflection_model_xlo(-ux), boundaries.reflection_model_xhi(ux), engine); @@ -141,7 +134,7 @@ namespace ApplyParticleBoundaries { #endif #ifdef WARPX_DIM_3D bool rethermalize_y = false; // stores if particle crosses y boundary and needs to be thermalized - apply_boundary(y, ymin, ymax, change_sign_uy, rethermalize_y, particle_lost, + apply_boundary(y, gridmin.y, gridmax.y, change_sign_uy, rethermalize_y, particle_lost, boundaries.ymin_bc, boundaries.ymax_bc, boundaries.reflection_model_ylo(-uy), boundaries.reflection_model_yhi(uy), engine); @@ -150,7 +143,7 @@ namespace ApplyParticleBoundaries { } #endif bool rethermalize_z = false; // stores if particle crosses z boundary and needs to be thermalized - apply_boundary(z, zmin, zmax, change_sign_uz, rethermalize_z, particle_lost, + apply_boundary(z, gridmin.z, gridmax.z, change_sign_uz, rethermalize_z, particle_lost, boundaries.zmin_bc, boundaries.zmax_bc, boundaries.reflection_model_zlo(-uz), boundaries.reflection_model_zhi(uz), engine); diff --git a/Source/Particles/ParticleBoundaryBuffer.cpp b/Source/Particles/ParticleBoundaryBuffer.cpp index 25068b2e65c..bc113e8e3a3 100644 --- a/Source/Particles/ParticleBoundaryBuffer.cpp +++ b/Source/Particles/ParticleBoundaryBuffer.cpp @@ -6,6 +6,7 @@ */ #include "WarpX.H" +#include "EmbeddedBoundary/Enabled.H" #include "EmbeddedBoundary/DistanceToEB.H" #include "Particles/ParticleBoundaryBuffer.H" #include "Particles/MultiParticleContainer.H" @@ -23,8 +24,10 @@ #include #include #include + using namespace amrex::literals; + struct IsOutsideDomainBoundary { amrex::GpuArray m_plo; amrex::GpuArray m_phi; @@ -46,7 +49,6 @@ struct IsOutsideDomainBoundary { } }; -#ifdef AMREX_USE_EB struct FindEmbeddedBoundaryIntersection { const int m_step_index; const int m_delta_index; @@ -86,13 +88,13 @@ struct FindEmbeddedBoundaryIntersection { amrex::ParticleReal const uz = dst.m_rdata[PIdx::uz][dst_i]; // Temporary variables to avoid implicit capture - amrex::Real dt = m_dt; - amrex::Array4 phiarr = m_phiarr; - amrex::GpuArray dxi = m_dxi; - amrex::GpuArray plo = m_plo; + amrex::Real const dt = m_dt; + amrex::Array4 const phiarr = m_phiarr; + amrex::GpuArray const dxi = m_dxi; + amrex::GpuArray const plo = m_plo; // Bisection algorithm to find the point where phi(x,y,z)=0 (i.e. on the embedded boundary) - amrex::Real dt_fraction = amrex::bisect( 0.0, 1.0, + amrex::Real const dt_fraction = amrex::bisect( 0.0, 1.0, [=] (amrex::Real dt_frac) { int i, j, k; amrex::Real W[AMREX_SPACEDIM][2]; @@ -100,7 +102,7 @@ struct FindEmbeddedBoundaryIntersection { UpdatePosition(x_temp, y_temp, z_temp, ux, uy, uz, -dt_frac*dt); ablastr::particles::compute_weights( x_temp, y_temp, z_temp, plo, dxi, i, j, k, W); - amrex::Real phi_value = ablastr::particles::interp_field_nodal(i, j, k, W, phiarr); + amrex::Real const phi_value = ablastr::particles::interp_field_nodal(i, j, k, W, phiarr); return phi_value; } ); @@ -146,7 +148,7 @@ struct FindEmbeddedBoundaryIntersection { dst.m_rdata[PIdx::z][dst_i] = z_temp; dst.m_rdata[PIdx::theta][dst_i] = std::atan2(y_temp, x_temp); //save normal components - amrex::Real theta=std::atan2(y_temp, x_temp); + amrex::Real const theta = std::atan2(y_temp, x_temp); dst.m_runtime_rdata[m_normal_index][dst_i] = normal[0]*std::cos(theta); dst.m_runtime_rdata[m_normal_index+1][dst_i] = normal[0]*std::sin(theta); dst.m_runtime_rdata[m_normal_index+2][dst_i] = normal[1]; @@ -165,7 +167,6 @@ struct FindEmbeddedBoundaryIntersection { amrex::ParticleIDWrapper{dst.m_idcpu[dst_i]}.make_valid(); } }; -#endif struct CopyAndTimestamp { int m_step_index; @@ -239,6 +240,8 @@ ParticleBoundaryBuffer::ParticleBoundaryBuffer () constexpr auto idx_zhi = 5; #endif + bool const eb_enabled = EB::enabled(); + for (int ispecies = 0; ispecies < numSpecies(); ++ispecies) { const amrex::ParmParse pp_species(getSpeciesNames()[ispecies]); @@ -258,9 +261,9 @@ ParticleBoundaryBuffer::ParticleBoundaryBuffer () pp_species.query("save_particles_at_zlo", m_do_boundary_buffer[idx_zlo][ispecies]); pp_species.query("save_particles_at_zhi", m_do_boundary_buffer[idx_zhi][ispecies]); #endif -#ifdef AMREX_USE_EB - pp_species.query("save_particles_at_eb", m_do_boundary_buffer[AMREX_SPACEDIM*2][ispecies]); -#endif + + if (eb_enabled) { pp_species.query("save_particles_at_eb", m_do_boundary_buffer[AMREX_SPACEDIM*2][ispecies]); } + // Set the flag whether the boundary is active or any species for (int i = 0; i < numBoundaries(); ++i) { if (m_do_boundary_buffer[i][ispecies]) { m_do_any_boundary[i] = 1; } @@ -283,10 +286,7 @@ ParticleBoundaryBuffer::ParticleBoundaryBuffer () m_boundary_names[idx_zlo] = "zlo"; m_boundary_names[idx_zhi] = "zhi"; #endif -#ifdef AMREX_USE_EB - m_boundary_names[AMREX_SPACEDIM*2] = "eb"; -#endif - + if (eb_enabled) { m_boundary_names[AMREX_SPACEDIM*2] = "eb"; } } void ParticleBoundaryBuffer::printNumParticles () const { @@ -306,17 +306,17 @@ void ParticleBoundaryBuffer::printNumParticles () const { } } } -#ifdef AMREX_USE_EB - auto& buffer = m_particle_containers[2*AMREX_SPACEDIM]; - for (int i = 0; i < numSpecies(); ++i) - { - const auto np = buffer[i].isDefined() ? buffer[i].TotalNumberOfParticles(false) : 0; - amrex::Print() << Utils::TextMsg::Info( - "Species " + getSpeciesNames()[i] + " has " - + std::to_string(np) + " particles in the EB boundary buffer" - ); + + if (EB::enabled()) { + auto const & buffer = m_particle_containers[2 * AMREX_SPACEDIM]; + for (int i = 0; i < numSpecies(); ++i) { + const auto np = buffer[i].isDefined() ? buffer[i].TotalNumberOfParticles(false) : 0; + amrex::Print() << Utils::TextMsg::Info( + "Species " + getSpeciesNames()[i] + " has " + + std::to_string(np) + " particles in the EB boundary buffer" + ); + } } -#endif } void ParticleBoundaryBuffer::redistribute () { @@ -401,6 +401,11 @@ void ParticleBoundaryBuffer::gatherParticlesFromDomainBoundaries (MultiParticleC for (int lev = 0; lev < pc.numLevels(); ++lev) { + for (PIter pti(pc, lev); pti.isValid(); ++pti) { + species_buffer.DefineAndReturnParticleTile( + lev, pti.index(), pti.LocalTileIndex()); + } + const auto& plevel = pc.GetParticles(lev); #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) @@ -408,10 +413,10 @@ void ParticleBoundaryBuffer::gatherParticlesFromDomainBoundaries (MultiParticleC for(PIter pti(pc, lev); pti.isValid(); ++pti) { auto index = std::make_pair(pti.index(), pti.LocalTileIndex()); - if(plevel.find(index) == plevel.end()) { continue; } - auto& ptile_buffer = species_buffer.DefineAndReturnParticleTile( - lev, pti.index(), pti.LocalTileIndex()); + auto& ptile_buffer = + species_buffer.ParticlesAt(lev, pti.index(), pti.LocalTileIndex()); + const auto& ptile = plevel.at(index); auto np = ptile.numParticles(); if (np == 0) { continue; } @@ -459,107 +464,108 @@ void ParticleBoundaryBuffer::gatherParticlesFromDomainBoundaries (MultiParticleC void ParticleBoundaryBuffer::gatherParticlesFromEmbeddedBoundaries ( MultiParticleContainer& mypc, const amrex::Vector& distance_to_eb) { -#ifdef AMREX_USE_EB - WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::EB"); + if (EB::enabled()) { + WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::EB"); - using PIter = amrex::ParConstIterSoA; - const auto& warpx_instance = WarpX::GetInstance(); - const amrex::Geometry& geom = warpx_instance.Geom(0); - auto plo = geom.ProbLoArray(); - auto& buffer = m_particle_containers[m_particle_containers.size()-1]; - for (int i = 0; i < numSpecies(); ++i) - { - if (!m_do_boundary_buffer[AMREX_SPACEDIM*2][i]) continue; - const auto& pc = mypc.GetParticleContainer(i); - if (!buffer[i].isDefined()) + using PIter = amrex::ParConstIterSoA; + const auto &warpx_instance = WarpX::GetInstance(); + const amrex::Geometry &geom = warpx_instance.Geom(0); + auto plo = geom.ProbLoArray(); + + auto& buffer = m_particle_containers[m_particle_containers.size()-1]; + for (int i = 0; i < numSpecies(); ++i) { - buffer[i] = pc.make_alike(); - buffer[i].AddIntComp("stepScraped", false); - buffer[i].AddRealComp("deltaTimeScraped", false); - buffer[i].AddRealComp("nx", false); - buffer[i].AddRealComp("ny", false); - buffer[i].AddRealComp("nz", false); + if (!m_do_boundary_buffer[AMREX_SPACEDIM*2][i]) { continue; } + const auto& pc = mypc.GetParticleContainer(i); + if (!buffer[i].isDefined()) + { + buffer[i] = pc.make_alike(); + buffer[i].AddIntComp("stepScraped", false); + buffer[i].AddRealComp("deltaTimeScraped", false); + buffer[i].AddRealComp("nx", false); + buffer[i].AddRealComp("ny", false); + buffer[i].AddRealComp("nz", false); - } + } - auto& species_buffer = buffer[i]; - for (int lev = 0; lev < pc.numLevels(); ++lev){ - for(PIter pti(pc, lev); pti.isValid(); ++pti){ - species_buffer.DefineAndReturnParticleTile( - lev, pti.index(), pti.LocalTileIndex()); + auto& species_buffer = buffer[i]; + for (int lev = 0; lev < pc.numLevels(); ++lev) { + for (PIter pti(pc, lev); pti.isValid(); ++pti) { + species_buffer.DefineAndReturnParticleTile( + lev, pti.index(), pti.LocalTileIndex()); + } } - } - for (int lev = 0; lev < pc.numLevels(); ++lev) - { - const auto& plevel = pc.GetParticles(lev); - auto dxi = warpx_instance.Geom(lev).InvCellSizeArray(); + for (int lev = 0; lev < pc.numLevels(); ++lev) + { + const auto& plevel = pc.GetParticles(lev); + auto dxi = warpx_instance.Geom(lev).InvCellSizeArray(); #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - for(PIter pti(pc, lev); pti.isValid(); ++pti) - { - auto phiarr = (*distance_to_eb[lev])[pti].array(); // signed distance function - auto index = std::make_pair(pti.index(), pti.LocalTileIndex()); - if(plevel.find(index) == plevel.end()) continue; - - const auto getPosition = GetParticlePosition(pti); - auto& ptile_buffer = species_buffer.DefineAndReturnParticleTile(lev, pti.index(), - pti.LocalTileIndex()); - const auto& ptile = plevel.at(index); - auto np = ptile.numParticles(); - if (np == 0) { continue; } - - using SrcData = WarpXParticleContainer::ParticleTileType::ConstParticleTileDataType; - auto predicate = [=] AMREX_GPU_HOST_DEVICE (const SrcData& /*src*/, const int ip) - /* NVCC 11.3.109 chokes in C++17 on this: noexcept */ - { - amrex::ParticleReal xp, yp, zp; - getPosition(ip, xp, yp, zp); - - amrex::Real phi_value = ablastr::particles::doGatherScalarFieldNodal( - xp, yp, zp, phiarr, dxi, plo - ); - return phi_value < 0.0 ? 1 : 0; - }; - - const auto ptile_data = ptile.getConstParticleTileData(); - - amrex::ReduceOps reduce_op; - amrex::ReduceData reduce_data(reduce_op); - { - WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::count_out_of_boundsEB"); - reduce_op.eval(np, reduce_data, [=] AMREX_GPU_HOST_DEVICE (int ip) - { return predicate(ptile_data, ip) ? 1 : 0; }); - } + for (PIter pti(pc, lev); pti.isValid(); ++pti) { + auto phiarr = (*distance_to_eb[lev])[pti].array(); // signed distance function + auto index = std::make_pair(pti.index(), pti.LocalTileIndex()); + if (plevel.find(index) == plevel.end()) { continue; } + + const auto getPosition = GetParticlePosition(pti); + auto &ptile_buffer = species_buffer.DefineAndReturnParticleTile(lev, pti.index(), + pti.LocalTileIndex()); + const auto &ptile = plevel.at(index); + auto np = ptile.numParticles(); + if (np == 0) { continue; } + + using SrcData = WarpXParticleContainer::ParticleTileType::ConstParticleTileDataType; + auto predicate = [=] AMREX_GPU_HOST_DEVICE(const SrcData & /*src*/, const int ip) + /* NVCC 11.3.109 chokes in C++17 on this: noexcept */ + { + amrex::ParticleReal xp, yp, zp; + getPosition(ip, xp, yp, zp); - auto dst_index = ptile_buffer.numParticles(); - { - WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::resize_eb"); - ptile_buffer.resize(dst_index + amrex::get<0>(reduce_data.value())); - } - auto& warpx = WarpX::GetInstance(); - const auto dt = warpx.getdt(pti.GetLevel()); - auto string_to_index_intcomp = buffer[i].getParticleRuntimeiComps(); - const int step_scraped_index = string_to_index_intcomp.at("stepScraped"); - auto string_to_index_realcomp = buffer[i].getParticleRuntimeComps(); - const int delta_index = string_to_index_realcomp.at("deltaTimeScraped"); - const int normal_index = string_to_index_realcomp.at("nx"); - const int step = warpx_instance.getistep(0); + amrex::Real const phi_value = ablastr::particles::doGatherScalarFieldNodal( + xp, yp, zp, phiarr, dxi, plo + ); + return phi_value < 0.0 ? 1 : 0; + }; - { - WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::filterTransformEB"); - amrex::filterAndTransformParticles(ptile_buffer, ptile, predicate, - FindEmbeddedBoundaryIntersection{step_scraped_index,delta_index, normal_index, step, dt, phiarr, dxi, plo}, 0, dst_index); + const auto ptile_data = ptile.getConstParticleTileData(); + + amrex::ReduceOps reduce_op; + amrex::ReduceData reduce_data(reduce_op); + { + WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::count_out_of_boundsEB"); + reduce_op.eval(np, reduce_data, + [=] AMREX_GPU_HOST_DEVICE(int ip) { return predicate(ptile_data, ip) ? 1 : 0; }); + } + + auto dst_index = ptile_buffer.numParticles(); + { + WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::resize_eb"); + ptile_buffer.resize(dst_index + amrex::get<0>(reduce_data.value())); + } + auto &warpx = WarpX::GetInstance(); + const auto dt = warpx.getdt(pti.GetLevel()); + auto string_to_index_intcomp = buffer[i].getParticleRuntimeiComps(); + const int step_scraped_index = string_to_index_intcomp.at("stepScraped"); + auto string_to_index_realcomp = buffer[i].getParticleRuntimeComps(); + const int delta_index = string_to_index_realcomp.at("deltaTimeScraped"); + const int normal_index = string_to_index_realcomp.at("nx"); + const int step = warpx_instance.getistep(0); + + { + WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::filterTransformEB"); + amrex::filterAndTransformParticles(ptile_buffer, ptile, predicate, + FindEmbeddedBoundaryIntersection{step_scraped_index, + delta_index, normal_index, + step, dt, phiarr, dxi, plo}, + 0, dst_index); + } } } } } -#else - amrex::ignore_unused(mypc, distance_to_eb); -#endif } int ParticleBoundaryBuffer::getNumParticlesInContainer( diff --git a/Source/Particles/ParticleCreation/FilterCopyTransform.H b/Source/Particles/ParticleCreation/FilterCopyTransform.H index 4815a98ca31..c6ca69d5e89 100644 --- a/Source/Particles/ParticleCreation/FilterCopyTransform.H +++ b/Source/Particles/ParticleCreation/FilterCopyTransform.H @@ -51,7 +51,7 @@ */ template ::value, int> foo = 0> + amrex::EnableIf_t, int> foo = 0> Index filterCopyTransformParticles (DstPC& pc, DstTile& dst, SrcTile& src, Index* mask, Index dst_index, CopyFunc&& copy, TransFunc&& transform) noexcept @@ -210,7 +210,7 @@ Index filterCopyTransformParticles (DstPC& pc, DstTile& dst, SrcTile& src, Index */ template ::value, int> foo = 0> + amrex::EnableIf_t, int> foo = 0> Index filterCopyTransformParticles (DstPC& pc1, DstPC& pc2, DstTile& dst1, DstTile& dst2, SrcTile& src, Index* mask, Index dst1_index, Index dst2_index, CopyFunc1&& copy1, CopyFunc2&& copy2, diff --git a/Source/Particles/ParticleCreation/FilterCreateTransformFromFAB.H b/Source/Particles/ParticleCreation/FilterCreateTransformFromFAB.H index 8a83c60b221..424008e18a6 100644 --- a/Source/Particles/ParticleCreation/FilterCreateTransformFromFAB.H +++ b/Source/Particles/ParticleCreation/FilterCreateTransformFromFAB.H @@ -45,7 +45,7 @@ */ template ::value, int> foo = 0> + amrex::EnableIf_t, int> foo = 0> Index filterCreateTransformFromFAB (DstPC& pc1, DstPC& pc2, DstTile& dst1, DstTile& dst2, const amrex::Box box, const FAB *src_FAB, const Index* mask, diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index d5fc68f4097..8d3516e6890 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -90,6 +90,6 @@ particlesConvertUnits (ConvertDirection convert_direction, T_ParticleContainer* */ void storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, - int electrostatic_solver_id, bool is_full_diagnostic ); + ElectrostaticSolverAlgo electrostatic_solver_id, bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index 5d9b41b8b75..8102fc96a91 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -392,6 +392,14 @@ public: } protected: + + /* + Finds the box defining the region where refine injection should be used, if that + option is enabled. Currently this only works for numLevels() == 2 and static mesh + refinement. + */ + bool findRefinedInjectionBox (amrex::Box& fine_injection_box, amrex::IntVect& rrfac); + std::string species_name; std::vector> plasma_injectors; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 3a30467c20d..23af57b9206 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -15,6 +15,7 @@ #include "Initialization/InjectorMomentum.H" #include "Initialization/InjectorPosition.H" #include "MultiParticleContainer.H" +#include "Particles/AddPlasmaUtilities.H" #ifdef WARPX_QED # include "Particles/ElementaryProcess/QEDInternals/BreitWheelerEngineWrapper.H" # include "Particles/ElementaryProcess/QEDInternals/QuantumSyncEngineWrapper.H" @@ -39,6 +40,7 @@ #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" +#include "EmbeddedBoundary/Enabled.H" #ifdef AMREX_USE_EB # include "EmbeddedBoundary/ParticleBoundaryProcess.H" # include "EmbeddedBoundary/ParticleScraper.H" @@ -177,16 +179,16 @@ namespace pos.x = lo_corner[0] + (iv[0]+r.x)*dx[0]; pos.y = lo_corner[1] + (iv[1]+r.y)*dx[1]; pos.z = lo_corner[2] + (iv[2]+r.z)*dx[2]; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) +#elif defined(WARPX_DIM_XZ) pos.x = lo_corner[0] + (iv[0]+r.x)*dx[0]; pos.y = 0.0_rt; -#if defined WARPX_DIM_XZ pos.z = lo_corner[1] + (iv[1]+r.y)*dx[1]; -#elif defined WARPX_DIM_RZ +#elif defined(WARPX_DIM_RZ) // Note that for RZ, r.y will be theta + pos.x = lo_corner[0] + (iv[0]+r.x)*dx[0]; + pos.y = 0.0_rt; pos.z = lo_corner[1] + (iv[1]+r.z)*dx[1]; -#endif -#else +#elif defined(WARPX_DIM_1D_Z) pos.x = 0.0_rt; pos.y = 0.0_rt; pos.z = lo_corner[0] + (iv[0]+r.x)*dx[0]; @@ -216,29 +218,17 @@ namespace const GpuArray& pa, long& ip, const bool& do_field_ionization, int* pi #ifdef WARPX_QED - ,const bool& has_quantum_sync, amrex::ParticleReal* AMREX_RESTRICT p_optical_depth_QSR - ,const bool& has_breit_wheeler, amrex::ParticleReal* AMREX_RESTRICT p_optical_depth_BW + ,const QEDHelper& qed_helper #endif ) noexcept { - pa[PIdx::z][ip] = 0._rt; -#if (AMREX_SPACEDIM >= 2) - pa[PIdx::x][ip] = 0._rt; -#endif -#if defined(WARPX_DIM_3D) - pa[PIdx::y][ip] = 0._rt; -#endif - pa[PIdx::w ][ip] = 0._rt; - pa[PIdx::ux][ip] = 0._rt; - pa[PIdx::uy][ip] = 0._rt; - pa[PIdx::uz][ip] = 0._rt; -#ifdef WARPX_DIM_RZ - pa[PIdx::theta][ip] = 0._rt; -#endif + for (int idx=0 ; idx < PIdx::nattribs ; idx++) { + pa[idx][ip] = 0._rt; + } if (do_field_ionization) {pi[ip] = 0;} #ifdef WARPX_QED - if (has_quantum_sync) {p_optical_depth_QSR[ip] = 0._rt;} - if (has_breit_wheeler) {p_optical_depth_BW[ip] = 0._rt;} + if (qed_helper.has_quantum_sync) {qed_helper.p_optical_depth_QSR[ip] = 0._rt;} + if (qed_helper.has_breit_wheeler) {qed_helper.p_optical_depth_BW[ip] = 0._rt;} #endif idcpu[ip] = amrex::ParticleIdCpus::Invalid; @@ -757,6 +747,7 @@ PhysicalParticleContainer::AddPlasmaFromFile(PlasmaInjector & plasma_injector, const std::shared_ptr ptr_offset_z = ps["positionOffset"]["z"].loadChunk(); auto const position_unit_z = static_cast(ps["position"]["z"].unitSI()); auto const position_offset_unit_z = static_cast(ps["positionOffset"]["z"].unitSI()); + const std::shared_ptr ptr_ux = ps["momentum"]["x"].loadChunk(); auto const momentum_unit_x = static_cast(ps["momentum"]["x"].unitSI()); const std::shared_ptr ptr_uz = ps["momentum"]["z"].loadChunk(); @@ -973,22 +964,9 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int amrex::LayoutData* cost = WarpX::getCosts(lev); - const int nlevs = numLevels(); - static bool refine_injection = false; - static Box fine_injection_box; - static amrex::IntVect rrfac(AMREX_D_DECL(1,1,1)); - // This does not work if the mesh is dynamic. But in that case, we should - // not use refined injected either. We also assume there is only one fine level. - if (WarpX::moving_window_active(WarpX::GetInstance().getistep(0)+1) and WarpX::refine_plasma - and do_continuous_injection and nlevs == 2) - { - refine_injection = true; - fine_injection_box = ParticleBoxArray(1).minimalBox(); - fine_injection_box.setSmall(WarpX::moving_window_dir, std::numeric_limits::lowest()/2); - fine_injection_box.setBig(WarpX::moving_window_dir, std::numeric_limits::max()/2); - rrfac = m_gdb->refRatio(0); - fine_injection_box.coarsen(rrfac); - } + Box fine_injection_box; + amrex::IntVect rrfac(AMREX_D_DECL(1,1,1)); + const bool refine_injection = findRefinedInjectionBox(fine_injection_box, rrfac); InjectorPosition* inj_pos = plasma_injector.getInjectorPosition(); InjectorDensity* inj_rho = plasma_injector.getInjectorDensity(); @@ -1004,18 +982,12 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int const bool radially_weighted = plasma_injector.radially_weighted; #endif - - // User-defined integer and real attributes: prepare parsers - const auto n_user_int_attribs = static_cast(m_user_int_attribs.size()); - const auto n_user_real_attribs = static_cast(m_user_real_attribs.size()); - amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > user_int_attrib_parserexec_pinned(n_user_int_attribs); - amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > user_real_attrib_parserexec_pinned(n_user_real_attribs); - for (int ia = 0; ia < n_user_int_attribs; ++ia) { - user_int_attrib_parserexec_pinned[ia] = m_user_int_attrib_parser[ia]->compile<7>(); - } - for (int ia = 0; ia < n_user_real_attribs; ++ia) { - user_real_attrib_parserexec_pinned[ia] = m_user_real_attrib_parser[ia]->compile<7>(); - } + auto n_user_int_attribs = static_cast(m_user_int_attribs.size()); + auto n_user_real_attribs = static_cast(m_user_real_attribs.size()); + const PlasmaParserWrapper plasma_parser_wrapper (m_user_int_attribs.size(), + m_user_real_attribs.size(), + m_user_int_attrib_parser, + m_user_real_attrib_parser); MFItInfo info; if (do_tiling && Gpu::notInLaunchRegion()) { @@ -1041,30 +1013,7 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int RealBox overlap_realbox; Box overlap_box; IntVect shifted; - bool no_overlap = false; - - for (int dir=0; dir= part_realbox.lo(dir) ) { - const Real ncells_adjust = std::floor( (part_realbox.hi(dir) - tile_realbox.hi(dir))/dx[dir] ); - overlap_realbox.setHi( dir, part_realbox.hi(dir) - std::max(ncells_adjust, 0._rt) * dx[dir]); - } else { - no_overlap = true; break; - } - // Count the number of cells in this direction in overlap_realbox - overlap_box.setSmall( dir, 0 ); - overlap_box.setBig( dir, - int( std::round((overlap_realbox.hi(dir)-overlap_realbox.lo(dir)) - /dx[dir] )) - 1); - shifted[dir] = - static_cast(std::round((overlap_realbox.lo(dir)-problo[dir])/dx[dir])); - // shifted is exact in non-moving-window direction. That's all we care. - } + const bool no_overlap = find_overlap(tile_realbox, part_realbox, dx, problo, overlap_realbox, overlap_box, shifted); if (no_overlap) { continue; // Go to the next tile } @@ -1081,7 +1030,6 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int Gpu::DeviceVector counts(overlap_box.numPts(), 0); Gpu::DeviceVector offset(overlap_box.numPts()); auto *pcounts = counts.data(); - const amrex::IntVect lrrfac = rrfac; Box fine_overlap_box; // default Box is NOT ok(). if (refine_injection) { fine_overlap_box = overlap_box & amrex::shift(fine_injection_box, -shifted); @@ -1099,7 +1047,7 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int { auto index = overlap_box.index(iv); const amrex::Long r = (fine_overlap_box.ok() && fine_overlap_box.contains(iv))? - (AMREX_D_TERM(lrrfac[0],*lrrfac[1],*lrrfac[2])) : (1); + (AMREX_D_TERM(rrfac[0],*rrfac[1],*rrfac[2])) : (1); pcounts[index] = num_ppc*r; // update pcount by checking if cell-corners or cell-center // has non-zero density @@ -1119,19 +1067,9 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int } return 0; }; - const int flag_pcount = checker(); - if (flag_pcount == 1) { - pcounts[index] = num_ppc*r; - } else { - pcounts[index] = 0; - } + pcounts[index] = checker() ? num_ppc*r : 0; } -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ignore_unused(k); -#endif -#if defined(WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); -#endif }); // Max number of new particles. All of them are created, @@ -1169,40 +1107,12 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int pa[ia] = soa.GetRealData(ia).data() + old_size; } uint64_t * AMREX_RESTRICT pa_idcpu = soa.GetIdCPUData().data() + old_size; - // user-defined integer and real attributes - amrex::Gpu::PinnedVector pa_user_int_pinned(n_user_int_attribs); - amrex::Gpu::PinnedVector pa_user_real_pinned(n_user_real_attribs); - for (int ia = 0; ia < n_user_int_attribs; ++ia) { - pa_user_int_pinned[ia] = soa.GetIntData(particle_icomps[m_user_int_attribs[ia]]).data() + old_size; - } - for (int ia = 0; ia < n_user_real_attribs; ++ia) { - pa_user_real_pinned[ia] = soa.GetRealData(particle_comps[m_user_real_attribs[ia]]).data() + old_size; - } -#ifdef AMREX_USE_GPU - // To avoid using managed memory, we first define pinned memory vector, initialize on cpu, - // and them memcpy to device from host - amrex::Gpu::DeviceVector d_pa_user_int(n_user_int_attribs); - amrex::Gpu::DeviceVector d_pa_user_real(n_user_real_attribs); - amrex::Gpu::DeviceVector< amrex::ParserExecutor<7> > d_user_int_attrib_parserexec(n_user_int_attribs); - amrex::Gpu::DeviceVector< amrex::ParserExecutor<7> > d_user_real_attrib_parserexec(n_user_real_attribs); - amrex::Gpu::copyAsync(Gpu::hostToDevice, pa_user_int_pinned.begin(), - pa_user_int_pinned.end(), d_pa_user_int.begin()); - amrex::Gpu::copyAsync(Gpu::hostToDevice, pa_user_real_pinned.begin(), - pa_user_real_pinned.end(), d_pa_user_real.begin()); - amrex::Gpu::copyAsync(Gpu::hostToDevice, user_int_attrib_parserexec_pinned.begin(), - user_int_attrib_parserexec_pinned.end(), d_user_int_attrib_parserexec.begin()); - amrex::Gpu::copyAsync(Gpu::hostToDevice, user_real_attrib_parserexec_pinned.begin(), - user_real_attrib_parserexec_pinned.end(), d_user_real_attrib_parserexec.begin()); - int** pa_user_int_data = d_pa_user_int.dataPtr(); - ParticleReal** pa_user_real_data = d_pa_user_real.dataPtr(); - amrex::ParserExecutor<7> const* user_int_parserexec_data = d_user_int_attrib_parserexec.dataPtr(); - amrex::ParserExecutor<7> const* user_real_parserexec_data = d_user_real_attrib_parserexec.dataPtr(); -#else - int** pa_user_int_data = pa_user_int_pinned.dataPtr(); - ParticleReal** pa_user_real_data = pa_user_real_pinned.dataPtr(); - amrex::ParserExecutor<7> const* user_int_parserexec_data = user_int_attrib_parserexec_pinned.dataPtr(); - amrex::ParserExecutor<7> const* user_real_parserexec_data = user_real_attrib_parserexec_pinned.dataPtr(); -#endif + + PlasmaParserHelper plasma_parser_helper (soa, old_size, m_user_int_attribs, m_user_real_attribs, particle_icomps, particle_comps, plasma_parser_wrapper); + int** pa_user_int_data = plasma_parser_helper.getUserIntDataPtrs(); + ParticleReal** pa_user_real_data = plasma_parser_helper.getUserRealDataPtrs(); + amrex::ParserExecutor<7> const* user_int_parserexec_data = plasma_parser_helper.getUserIntParserExecData(); + amrex::ParserExecutor<7> const* user_real_parserexec_data = plasma_parser_helper.getUserRealParserExecData(); int* pi = nullptr; if (do_field_ionization) { @@ -1210,34 +1120,9 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int } #ifdef WARPX_QED - //Pointer to the optical depth component - amrex::ParticleReal* p_optical_depth_QSR = nullptr; - amrex::ParticleReal* p_optical_depth_BW = nullptr; - - // If a QED effect is enabled, the corresponding optical depth - // has to be initialized - const bool loc_has_quantum_sync = has_quantum_sync(); - const bool loc_has_breit_wheeler = has_breit_wheeler(); - if (loc_has_quantum_sync) { - p_optical_depth_QSR = soa.GetRealData( - particle_comps["opticalDepthQSR"]).data() + old_size; - } - if(loc_has_breit_wheeler) { - p_optical_depth_BW = soa.GetRealData( - particle_comps["opticalDepthBW"]).data() + old_size; - } - - //If needed, get the appropriate functors from the engines - QuantumSynchrotronGetOpticalDepth quantum_sync_get_opt; - BreitWheelerGetOpticalDepth breit_wheeler_get_opt; - if(loc_has_quantum_sync){ - quantum_sync_get_opt = - m_shr_p_qs_engine->build_optical_depth_functor(); - } - if(loc_has_breit_wheeler){ - breit_wheeler_get_opt = - m_shr_p_bw_engine->build_optical_depth_functor(); - } + const QEDHelper qed_helper(soa, old_size, particle_comps, + has_quantum_sync(), has_breit_wheeler(), + m_shr_p_qs_engine, m_shr_p_bw_engine); #endif const bool loc_do_field_ionization = do_field_ionization; @@ -1255,67 +1140,42 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int [=] AMREX_GPU_DEVICE (int i, int j, int k, amrex::RandomEngine const& engine) noexcept { const IntVect iv = IntVect(AMREX_D_DECL(i, j, k)); + amrex::ignore_unused(j,k); const auto index = overlap_box.index(iv); #ifdef WARPX_DIM_RZ Real theta_offset = 0._rt; if (rz_random_theta) { theta_offset = amrex::Random(engine) * 2._rt * MathConst::pi; } #endif - Real scale_fac = 0.0_rt; - if( pcounts[index] != 0) { -#if defined(WARPX_DIM_3D) - scale_fac = dx[0]*dx[1]*dx[2]/pcounts[index]; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - scale_fac = dx[0]*dx[1]/pcounts[index]; -#elif defined(WARPX_DIM_1D_Z) - scale_fac = dx[0]/pcounts[index]; -#endif - } - + const Real scale_fac = compute_scale_fac_volume(dx, pcounts[index]); for (int i_part = 0; i_part < pcounts[index]; ++i_part) { long ip = poffset[index] + i_part; pa_idcpu[ip] = amrex::SetParticleIDandCPU(pid+ip, cpuid); const XDim3 r = (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) ? - // In the refined injection region: use refinement ratio `lrrfac` - inj_pos->getPositionUnitBox(i_part, lrrfac, engine) : + // In the refined injection region: use refinement ratio `rrfac` + inj_pos->getPositionUnitBox(i_part, rrfac, engine) : // Otherwise: use 1 as the refinement ratio inj_pos->getPositionUnitBox(i_part, amrex::IntVect::TheUnitVector(), engine); auto pos = getCellCoords(overlap_corner, dx, r, iv); #if defined(WARPX_DIM_3D) - if (!tile_realbox.contains(XDim3{pos.x,pos.y,pos.z})) { - ZeroInitializeAndSetNegativeID(pa_idcpu, pa, ip, loc_do_field_ionization, pi -#ifdef WARPX_QED - ,loc_has_quantum_sync, p_optical_depth_QSR - ,loc_has_breit_wheeler, p_optical_depth_BW -#endif - ); - continue; - } + bool const box_contains = tile_realbox.contains(XDim3{pos.x,pos.y,pos.z}); #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) amrex::ignore_unused(k); - if (!tile_realbox.contains(XDim3{pos.x,pos.z,0.0_rt})) { - ZeroInitializeAndSetNegativeID(pa_idcpu, pa, ip, loc_do_field_ionization, pi -#ifdef WARPX_QED - ,loc_has_quantum_sync, p_optical_depth_QSR - ,loc_has_breit_wheeler, p_optical_depth_BW -#endif - ); - continue; - } -#else + bool const box_contains = tile_realbox.contains(XDim3{pos.x,pos.z,0.0_rt}); +#elif defined(WARPX_DIM_1D_Z) amrex::ignore_unused(j,k); - if (!tile_realbox.contains(XDim3{pos.z,0.0_rt,0.0_rt})) { + bool const box_contains = tile_realbox.contains(XDim3{pos.z,0.0_rt,0.0_rt}); +#endif + if (!box_contains) { ZeroInitializeAndSetNegativeID(pa_idcpu, pa, ip, loc_do_field_ionization, pi #ifdef WARPX_QED - ,loc_has_quantum_sync, p_optical_depth_QSR - ,loc_has_breit_wheeler, p_optical_depth_BW + ,qed_helper #endif ); continue; } -#endif // Save the x and y values to use in the insideBounds checks. // This is needed with WARPX_DIM_RZ since x and y are modified. @@ -1348,8 +1208,7 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int if (!inj_pos->insideBounds(xb, yb, z0)) { ZeroInitializeAndSetNegativeID(pa_idcpu, pa, ip, loc_do_field_ionization, pi #ifdef WARPX_QED - ,loc_has_quantum_sync, p_optical_depth_QSR - ,loc_has_breit_wheeler, p_optical_depth_BW + ,qed_helper #endif ); continue; @@ -1362,8 +1221,7 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int if ( dens < density_min ){ ZeroInitializeAndSetNegativeID(pa_idcpu, pa, ip, loc_do_field_ionization, pi #ifdef WARPX_QED - ,loc_has_quantum_sync, p_optical_depth_QSR - ,loc_has_breit_wheeler, p_optical_depth_BW + ,qed_helper #endif ); continue; @@ -1380,8 +1238,7 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int if (!inj_pos->insideBounds(xb, yb, z0_lab)) { ZeroInitializeAndSetNegativeID(pa_idcpu, pa, ip, loc_do_field_ionization, pi #ifdef WARPX_QED - ,loc_has_quantum_sync, p_optical_depth_QSR - ,loc_has_breit_wheeler, p_optical_depth_BW + ,qed_helper #endif ); continue; @@ -1392,8 +1249,7 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int if ( dens < density_min ){ ZeroInitializeAndSetNegativeID(pa_idcpu, pa, ip, loc_do_field_ionization, pi #ifdef WARPX_QED - ,loc_has_quantum_sync, p_optical_depth_QSR - ,loc_has_breit_wheeler, p_optical_depth_BW + ,qed_helper #endif ); continue; @@ -1417,12 +1273,12 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int } #ifdef WARPX_QED - if(loc_has_quantum_sync){ - p_optical_depth_QSR[ip] = quantum_sync_get_opt(engine); + if(qed_helper.has_quantum_sync){ + qed_helper.p_optical_depth_QSR[ip] = qed_helper.quantum_sync_get_opt(engine); } - if(loc_has_breit_wheeler){ - p_optical_depth_BW[ip] = breit_wheeler_get_opt(engine); + if(qed_helper.has_breit_wheeler){ + qed_helper.p_optical_depth_BW[ip] = qed_helper.breit_wheeler_get_opt(engine); } #endif // Initialize user-defined integers with user-defined parser @@ -1460,13 +1316,14 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int pa[PIdx::x][ip] = pos.x; pa[PIdx::y][ip] = pos.y; pa[PIdx::z][ip] = pos.z; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) -#ifdef WARPX_DIM_RZ +#elif defined(WARPX_DIM_XZ) + pa[PIdx::x][ip] = pos.x; + pa[PIdx::z][ip] = pos.z; +#elif defined(WARPX_DIM_RZ) pa[PIdx::theta][ip] = theta; -#endif pa[PIdx::x][ip] = xb; pa[PIdx::z][ip] = pos.z; -#else +#elif defined(WARPX_DIM_1D_Z) pa[PIdx::z][ip] = pos.z; #endif } @@ -1483,8 +1340,11 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int // Remove particles that are inside the embedded boundaries #ifdef AMREX_USE_EB - auto & distance_to_eb = WarpX::GetInstance().GetDistanceToEB(); - scrapeParticlesAtEB( *this, amrex::GetVecOfConstPtrs(distance_to_eb), ParticleBoundaryProcess::Absorb()); + if (EB::enabled()) + { + auto &distance_to_eb = WarpX::GetInstance().GetDistanceToEB(); + scrapeParticlesAtEB(*this, amrex::GetVecOfConstPtrs(distance_to_eb), ParticleBoundaryProcess::Absorb()); + } #endif // The function that calls this is responsible for redistributing particles. @@ -1506,25 +1366,6 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, const auto dx = geom.CellSizeArray(); const auto problo = geom.ProbLoArray(); - Real scale_fac = 0._rt; - // Scale particle weight by the area of the emitting surface, within one cell -#if defined(WARPX_DIM_3D) - scale_fac = dx[0]*dx[1]*dx[2]/dx[plasma_injector.flux_normal_axis]/num_ppc_real; -#elif defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ) - scale_fac = dx[0]*dx[1]/num_ppc_real; - // When emission is in the r direction, the emitting surface is a cylinder. - // The factor 2*pi*r is added later below. - if (plasma_injector.flux_normal_axis == 0) { scale_fac /= dx[0]; } - // When emission is in the z direction, the emitting surface is an annulus - // The factor 2*pi*r is added later below. - if (plasma_injector.flux_normal_axis == 2) { scale_fac /= dx[1]; } - // When emission is in the theta direction (flux_normal_axis == 1), - // the emitting surface is a rectangle, within the plane of the simulation -#elif defined(WARPX_DIM_1D_Z) - scale_fac = dx[0]/num_ppc_real; - if (plasma_injector.flux_normal_axis == 2) { scale_fac /= dx[0]; } -#endif - amrex::LayoutData* cost = WarpX::getCosts(0); // Create temporary particle container to which particles will be added; @@ -1535,19 +1376,9 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, for (int ic = 0; ic < NumRuntimeIntComps(); ++ic) { tmp_pc.AddIntComp(false); } tmp_pc.defineAllParticleTiles(); - const int nlevs = numLevels(); - static bool refine_injection = false; - static Box fine_injection_box; - static amrex::IntVect rrfac(AMREX_D_DECL(1,1,1)); - // This does not work if the mesh is dynamic. But in that case, we should - // not use refined injected either. We also assume there is only one fine level. - if (WarpX::refine_plasma && nlevs == 2) - { - refine_injection = true; - fine_injection_box = ParticleBoxArray(1).minimalBox(); - rrfac = m_gdb->refRatio(0); - fine_injection_box.coarsen(rrfac); - } + Box fine_injection_box; + amrex::IntVect rrfac(AMREX_D_DECL(1,1,1)); + const bool refine_injection = findRefinedInjectionBox(fine_injection_box, rrfac); InjectorPosition* flux_pos = plasma_injector.getInjectorFluxPosition(); InjectorFlux* inj_flux = plasma_injector.getInjectorFlux(); @@ -1561,6 +1392,13 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, const bool radially_weighted = plasma_injector.radially_weighted; #endif + auto n_user_int_attribs = static_cast(m_user_int_attribs.size()); + auto n_user_real_attribs = static_cast(m_user_real_attribs.size()); + const PlasmaParserWrapper plasma_parser_wrapper (m_user_int_attribs.size(), + m_user_real_attribs.size(), + m_user_int_attrib_parser, + m_user_real_attrib_parser); + MFItInfo info; if (do_tiling && Gpu::notInLaunchRegion()) { info.EnableTiling(tile_size); @@ -1585,61 +1423,7 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, RealBox overlap_realbox; Box overlap_box; IntVect shifted; - bool no_overlap = false; - - for (int dir=0; dir 0) { - if (plasma_injector.surface_flux_pos < tile_realbox.lo(dir) || - plasma_injector.surface_flux_pos >= tile_realbox.hi(dir)) { - no_overlap = true; - break; - } - } else { - if (plasma_injector.surface_flux_pos <= tile_realbox.lo(dir) || - plasma_injector.surface_flux_pos > tile_realbox.hi(dir)) { - no_overlap = true; - break; - } - } - overlap_realbox.setLo( dir, plasma_injector.surface_flux_pos ); - overlap_realbox.setHi( dir, plasma_injector.surface_flux_pos ); - overlap_box.setSmall( dir, 0 ); - overlap_box.setBig( dir, 0 ); - shifted[dir] = - static_cast(std::round((overlap_realbox.lo(dir)-problo[dir])/dx[dir])); - } else { - if ( tile_realbox.lo(dir) <= part_realbox.hi(dir) ) { - const Real ncells_adjust = std::floor( (tile_realbox.lo(dir) - part_realbox.lo(dir))/dx[dir] ); - overlap_realbox.setLo( dir, part_realbox.lo(dir) + std::max(ncells_adjust, 0._rt) * dx[dir]); - } else { - no_overlap = true; break; - } - if ( tile_realbox.hi(dir) >= part_realbox.lo(dir) ) { - const Real ncells_adjust = std::floor( (part_realbox.hi(dir) - tile_realbox.hi(dir))/dx[dir] ); - overlap_realbox.setHi( dir, part_realbox.hi(dir) - std::max(ncells_adjust, 0._rt) * dx[dir]); - } else { - no_overlap = true; break; - } - // Count the number of cells in this direction in overlap_realbox - overlap_box.setSmall( dir, 0 ); - overlap_box.setBig( dir, - int( std::round((overlap_realbox.hi(dir)-overlap_realbox.lo(dir)) - /dx[dir] )) - 1); - shifted[dir] = - static_cast(std::round((overlap_realbox.lo(dir)-problo[dir])/dx[dir])); - // shifted is exact in non-moving-window direction. That's all we care. - } - } + const bool no_overlap = find_overlap_flux(tile_realbox, part_realbox, dx, problo, plasma_injector, overlap_realbox, overlap_box, shifted); if (no_overlap) { continue; // Go to the next tile } @@ -1656,7 +1440,7 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, Gpu::DeviceVector counts(overlap_box.numPts(), 0); Gpu::DeviceVector offset(overlap_box.numPts()); auto *pcounts = counts.data(); - const amrex::IntVect lrrfac = rrfac; + const int flux_normal_axis = plasma_injector.flux_normal_axis; Box fine_overlap_box; // default Box is NOT ok(). if (refine_injection) { fine_overlap_box = overlap_box & amrex::shift(fine_injection_box, -shifted); @@ -1664,27 +1448,21 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, amrex::ParallelForRNG(overlap_box, [=] AMREX_GPU_DEVICE (int i, int j, int k, amrex::RandomEngine const& engine) noexcept { const IntVect iv(AMREX_D_DECL(i, j, k)); + amrex::ignore_unused(j,k); + auto lo = getCellCoords(overlap_corner, dx, {0._rt, 0._rt, 0._rt}, iv); auto hi = getCellCoords(overlap_corner, dx, {1._rt, 1._rt, 1._rt}, iv); - const int num_ppc_int = static_cast(num_ppc_real + amrex::Random(engine)); - if (flux_pos->overlapsWith(lo, hi)) { auto index = overlap_box.index(iv); - int r; + int r = 1; if (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) { - r = AMREX_D_TERM(lrrfac[0],*lrrfac[1],*lrrfac[2]); - } else { - r = 1; + r = compute_area_weights(rrfac, flux_normal_axis); } - pcounts[index] = num_ppc_int*r; + const int num_ppc_int = static_cast(num_ppc_real*r + amrex::Random(engine)); + pcounts[index] = num_ppc_int; } -#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ignore_unused(k); -#elif defined(WARPX_DIM_1D_Z) - amrex::ignore_unused(j,k); -#endif }); // Max number of new particles. All of them are created, @@ -1719,46 +1497,11 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, } uint64_t * AMREX_RESTRICT pa_idcpu = soa.GetIdCPUData().data() + old_size; - // user-defined integer and real attributes - const auto n_user_int_attribs = static_cast(m_user_int_attribs.size()); - const auto n_user_real_attribs = static_cast(m_user_real_attribs.size()); - amrex::Gpu::PinnedVector pa_user_int_pinned(n_user_int_attribs); - amrex::Gpu::PinnedVector pa_user_real_pinned(n_user_real_attribs); - amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > user_int_attrib_parserexec_pinned(n_user_int_attribs); - amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > user_real_attrib_parserexec_pinned(n_user_real_attribs); - for (int ia = 0; ia < n_user_int_attribs; ++ia) { - pa_user_int_pinned[ia] = soa.GetIntData(particle_icomps[m_user_int_attribs[ia]]).data() + old_size; - user_int_attrib_parserexec_pinned[ia] = m_user_int_attrib_parser[ia]->compile<7>(); - } - for (int ia = 0; ia < n_user_real_attribs; ++ia) { - pa_user_real_pinned[ia] = soa.GetRealData(particle_comps[m_user_real_attribs[ia]]).data() + old_size; - user_real_attrib_parserexec_pinned[ia] = m_user_real_attrib_parser[ia]->compile<7>(); - } -#ifdef AMREX_USE_GPU - // To avoid using managed memory, we first define pinned memory vector, initialize on cpu, - // and them memcpy to device from host - amrex::Gpu::DeviceVector d_pa_user_int(n_user_int_attribs); - amrex::Gpu::DeviceVector d_pa_user_real(n_user_real_attribs); - amrex::Gpu::DeviceVector< amrex::ParserExecutor<7> > d_user_int_attrib_parserexec(n_user_int_attribs); - amrex::Gpu::DeviceVector< amrex::ParserExecutor<7> > d_user_real_attrib_parserexec(n_user_real_attribs); - amrex::Gpu::copyAsync(Gpu::hostToDevice, pa_user_int_pinned.begin(), - pa_user_int_pinned.end(), d_pa_user_int.begin()); - amrex::Gpu::copyAsync(Gpu::hostToDevice, pa_user_real_pinned.begin(), - pa_user_real_pinned.end(), d_pa_user_real.begin()); - amrex::Gpu::copyAsync(Gpu::hostToDevice, user_int_attrib_parserexec_pinned.begin(), - user_int_attrib_parserexec_pinned.end(), d_user_int_attrib_parserexec.begin()); - amrex::Gpu::copyAsync(Gpu::hostToDevice, user_real_attrib_parserexec_pinned.begin(), - user_real_attrib_parserexec_pinned.end(), d_user_real_attrib_parserexec.begin()); - int** pa_user_int_data = d_pa_user_int.dataPtr(); - ParticleReal** pa_user_real_data = d_pa_user_real.dataPtr(); - amrex::ParserExecutor<7> const* user_int_parserexec_data = d_user_int_attrib_parserexec.dataPtr(); - amrex::ParserExecutor<7> const* user_real_parserexec_data = d_user_real_attrib_parserexec.dataPtr(); -#else - int** pa_user_int_data = pa_user_int_pinned.dataPtr(); - ParticleReal** pa_user_real_data = pa_user_real_pinned.dataPtr(); - amrex::ParserExecutor<7> const* user_int_parserexec_data = user_int_attrib_parserexec_pinned.dataPtr(); - amrex::ParserExecutor<7> const* user_real_parserexec_data = user_real_attrib_parserexec_pinned.dataPtr(); -#endif + PlasmaParserHelper plasma_parser_helper (soa, old_size, m_user_int_attribs, m_user_real_attribs, particle_icomps, particle_comps, plasma_parser_wrapper); + int** pa_user_int_data = plasma_parser_helper.getUserIntDataPtrs(); + ParticleReal** pa_user_real_data = plasma_parser_helper.getUserRealDataPtrs(); + amrex::ParserExecutor<7> const* user_int_parserexec_data = plasma_parser_helper.getUserIntParserExecData(); + amrex::ParserExecutor<7> const* user_real_parserexec_data = plasma_parser_helper.getUserRealParserExecData(); int* p_ion_level = nullptr; if (do_field_ionization) { @@ -1766,34 +1509,9 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, } #ifdef WARPX_QED - //Pointer to the optical depth component - amrex::ParticleReal* p_optical_depth_QSR = nullptr; - amrex::ParticleReal* p_optical_depth_BW = nullptr; - - // If a QED effect is enabled, the corresponding optical depth - // has to be initialized - const bool loc_has_quantum_sync = has_quantum_sync(); - const bool loc_has_breit_wheeler = has_breit_wheeler(); - if (loc_has_quantum_sync) { - p_optical_depth_QSR = soa.GetRealData( - particle_comps["opticalDepthQSR"]).data() + old_size; - } - if(loc_has_breit_wheeler) { - p_optical_depth_BW = soa.GetRealData( - particle_comps["opticalDepthBW"]).data() + old_size; - } - - //If needed, get the appropriate functors from the engines - QuantumSynchrotronGetOpticalDepth quantum_sync_get_opt; - BreitWheelerGetOpticalDepth breit_wheeler_get_opt; - if(loc_has_quantum_sync){ - quantum_sync_get_opt = - m_shr_p_qs_engine->build_optical_depth_functor(); - } - if(loc_has_breit_wheeler){ - breit_wheeler_get_opt = - m_shr_p_bw_engine->build_optical_depth_functor(); - } + const QEDHelper qed_helper(soa, old_size, particle_comps, + has_quantum_sync(), has_breit_wheeler(), + m_shr_p_qs_engine, m_shr_p_bw_engine); #endif const bool loc_do_field_ionization = do_field_ionization; @@ -1811,7 +1529,15 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, [=] AMREX_GPU_DEVICE (int i, int j, int k, amrex::RandomEngine const& engine) noexcept { const IntVect iv = IntVect(AMREX_D_DECL(i, j, k)); + amrex::ignore_unused(j,k); const auto index = overlap_box.index(iv); + + Real scale_fac = compute_scale_fac_area(dx, num_ppc_real, flux_normal_axis); + + if (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) { + scale_fac /= compute_area_weights(rrfac, flux_normal_axis); + } + for (int i_part = 0; i_part < pcounts[index]; ++i_part) { const long ip = poffset[index] + i_part; @@ -1819,8 +1545,8 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, // This assumes the flux_pos is of type InjectorPositionRandomPlane const XDim3 r = (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) ? - // In the refined injection region: use refinement ratio `lrrfac` - flux_pos->getPositionUnitBox(i_part, lrrfac, engine) : + // In the refined injection region: use refinement ratio `rrfac` + flux_pos->getPositionUnitBox(i_part, rrfac, engine) : // Otherwise: use 1 as the refinement ratio flux_pos->getPositionUnitBox(i_part, amrex::IntVect::TheUnitVector(), engine); auto pos = getCellCoords(overlap_corner, dx, r, iv); @@ -1903,14 +1629,15 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, } #ifdef WARPX_QED - if (loc_has_quantum_sync) { - p_optical_depth_QSR[ip] = quantum_sync_get_opt(engine); + if(qed_helper.has_quantum_sync){ + qed_helper.p_optical_depth_QSR[ip] = qed_helper.quantum_sync_get_opt(engine); } - if(loc_has_breit_wheeler){ - p_optical_depth_BW[ip] = breit_wheeler_get_opt(engine); + if(qed_helper.has_breit_wheeler){ + qed_helper.p_optical_depth_BW[ip] = qed_helper.breit_wheeler_get_opt(engine); } #endif + // Initialize user-defined integers with user-defined parser for (int ia = 0; ia < n_user_int_attribs; ++ia) { pa_user_int_data[ia][ip] = static_cast(user_int_parserexec_data[ia](pos.x, pos.y, pos.z, u.x, u.y, u.z, t)); @@ -1963,7 +1690,7 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, #elif defined(WARPX_DIM_XZ) pa[PIdx::x][ip] = ppos.x; pa[PIdx::z][ip] = ppos.z; -#else +#elif defined(WARPX_DIM_1D_Z) pa[PIdx::z][ip] = ppos.z; #endif } @@ -1980,8 +1707,11 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, // Remove particles that are inside the embedded boundaries #ifdef AMREX_USE_EB - auto & distance_to_eb = WarpX::GetInstance().GetDistanceToEB(); - scrapeParticlesAtEB(tmp_pc, amrex::GetVecOfConstPtrs(distance_to_eb), ParticleBoundaryProcess::Absorb()); + if (EB::enabled()) + { + auto & distance_to_eb = WarpX::GetInstance().GetDistanceToEB(); + scrapeParticlesAtEB(tmp_pc, amrex::GetVecOfConstPtrs(distance_to_eb), ParticleBoundaryProcess::Absorb()); + } #endif // Redistribute the new particles that were added to the temporary container. @@ -1989,26 +1719,8 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector, // are in the right tile.) tmp_pc.Redistribute(); - // Add the particles to the current container, tile by tile - for (int lev=0; levaddParticles(tmp_pc, true); } void @@ -2360,13 +2072,7 @@ PhysicalParticleContainer::SplitParticles (int lev) long np_split; if(split_type==0) { - #if defined(WARPX_DIM_3D) - np_split = 8; - #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - np_split = 4; - #else - np_split = 2; - #endif + np_split = amrex::Math::powi(2); } else { np_split = 2*AMREX_SPACEDIM; } @@ -2825,15 +2531,12 @@ PhysicalParticleContainer::PushPX (WarpXParIter& pti, if (save_previous_position) { #if (AMREX_SPACEDIM >= 2) x_old = pti.GetAttribs(particle_comps["prev_x"]).dataPtr() + offset; -#else - amrex::ignore_unused(x_old); #endif #if defined(WARPX_DIM_3D) y_old = pti.GetAttribs(particle_comps["prev_y"]).dataPtr() + offset; -#else - amrex::ignore_unused(y_old); #endif z_old = pti.GetAttribs(particle_comps["prev_z"]).dataPtr() + offset; + amrex::ignore_unused(x_old, y_old); } // Loop over the particles and update their momentum @@ -3033,7 +2736,7 @@ PhysicalParticleContainer::ImplicitPushXP (WarpXParIter& pti, const Dim3 lo = lbound(box); - const int depos_type = WarpX::current_deposition_algo; + const auto depos_type = WarpX::current_deposition_algo; const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; @@ -3259,10 +2962,10 @@ PhysicalParticleContainer::ImplicitPushXP (WarpXParIter& pti, #if !defined(AMREX_USE_GPU) std::stringstream convergenceMsg; convergenceMsg << "Picard solver for particle failed to converge after " << - iter << " iterations. " << std::endl; + iter << " iterations.\n"; convergenceMsg << "Position step norm is " << step_norm << - " and the tolerance is " << particle_tolerance << std::endl; - convergenceMsg << " ux = " << ux[ip] << ", uy = " << uy[ip] << ", uz = " << uz[ip] << std::endl; + " and the tolerance is " << particle_tolerance << "\n"; + convergenceMsg << " ux = " << ux[ip] << ", uy = " << uy[ip] << ", uz = " << uz[ip] << "\n"; convergenceMsg << " xp = " << xp << ", yp = " << yp << ", zp = " << zp; ablastr::warn_manager::WMRecordWarning("ImplicitPushXP", convergenceMsg.str()); #endif @@ -3443,6 +3146,28 @@ void PhysicalParticleContainer::resample (const int timestep, const bool verbose WARPX_PROFILE_VAR_STOP(blp_resample_actual); } +bool +PhysicalParticleContainer::findRefinedInjectionBox (amrex::Box& a_fine_injection_box, amrex::IntVect& a_rrfac) +{ + WARPX_PROFILE("PhysicalParticleContainer::findRefinedInjectionBox"); + + // This does not work if the mesh is dynamic. But in that case, we should + // not use refined injected either. We also assume there is only one fine level. + static bool refine_injection = false; + static Box fine_injection_box; + static amrex::IntVect rrfac(AMREX_D_DECL(1,1,1)); + if (!refine_injection and WarpX::moving_window_active(WarpX::GetInstance().getistep(0)+1) and WarpX::refine_plasma and do_continuous_injection and numLevels() == 2) { + refine_injection = true; + fine_injection_box = ParticleBoxArray(1).minimalBox(); + fine_injection_box.setSmall(WarpX::moving_window_dir, std::numeric_limits::lowest()/2); + fine_injection_box.setBig(WarpX::moving_window_dir, std::numeric_limits::max()/2); + rrfac = m_gdb->refRatio(0); + fine_injection_box.coarsen(rrfac); + } + a_fine_injection_box = fine_injection_box; + a_rrfac = rrfac; + return refine_injection; +} #ifdef WARPX_QED diff --git a/Source/Particles/Pusher/GetAndSetPosition.H b/Source/Particles/Pusher/GetAndSetPosition.H index 44641557756..ab06fe3d6cd 100644 --- a/Source/Particles/Pusher/GetAndSetPosition.H +++ b/Source/Particles/Pusher/GetAndSetPosition.H @@ -63,25 +63,16 @@ struct GetParticlePosition { using RType = amrex::ParticleReal; -#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ) - const RType* AMREX_RESTRICT m_x = nullptr; - const RType* AMREX_RESTRICT m_z = nullptr; -#elif defined(WARPX_DIM_3D) const RType* AMREX_RESTRICT m_x = nullptr; const RType* AMREX_RESTRICT m_y = nullptr; const RType* AMREX_RESTRICT m_z = nullptr; -#elif defined(WARPX_DIM_1D_Z) - const RType* AMREX_RESTRICT m_z = nullptr; -#endif #if defined(WARPX_DIM_RZ) const RType* m_theta = nullptr; -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - static constexpr RType m_y_default = RType(0.0); -#elif defined(WARPX_DIM_1D_Z) +#endif + static constexpr RType m_x_default = RType(0.0); static constexpr RType m_y_default = RType(0.0); -#endif GetParticlePosition () = default; @@ -118,20 +109,20 @@ struct GetParticlePosition AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator() (const long i, RType& x, RType& y, RType& z) const noexcept { -#ifdef WARPX_DIM_RZ +#if defined(WARPX_DIM_RZ) RType const r = m_x[i]; x = r*std::cos(m_theta[i]); y = r*std::sin(m_theta[i]); z = m_z[i]; -#elif WARPX_DIM_3D +#elif defined(WARPX_DIM_3D) x = m_x[i]; y = m_y[i]; z = m_z[i]; -#elif WARPX_DIM_XZ +#elif defined(WARPX_DIM_XZ) x = m_x[i]; y = m_y_default; z = m_z[i]; -#else +#elif defined(WARPX_DIM_1D_Z) x = m_x_default; y = m_y_default; z = m_z[i]; @@ -146,19 +137,19 @@ struct GetParticlePosition AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AsStored (const long i, RType& x, RType& y, RType& z) const noexcept { -#ifdef WARPX_DIM_RZ +#if defined(WARPX_DIM_RZ) x = m_x[i]; y = m_theta[i]; z = m_z[i]; -#elif WARPX_DIM_3D +#elif defined(WARPX_DIM_3D) x = m_x[i]; y = m_y[i]; z = m_z[i]; -#elif WARPX_DIM_XZ +#elif defined(WARPX_DIM_XZ) x = m_x[i]; y = m_y_default; z = m_z[i]; -#else +#elif defined(WARPX_DIM_1D_Z) x = m_x_default; y = m_y_default; z = m_z[i]; @@ -178,16 +169,17 @@ struct SetParticlePosition { using RType = amrex::ParticleReal; -#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ) +#if defined(WARPX_DIM_3D) RType* AMREX_RESTRICT m_x; + RType* AMREX_RESTRICT m_y; RType* AMREX_RESTRICT m_z; -#elif defined(WARPX_DIM_3D) +#elif defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ) RType* AMREX_RESTRICT m_x; - RType* AMREX_RESTRICT m_y; RType* AMREX_RESTRICT m_z; #elif defined(WARPX_DIM_1D_Z) RType* AMREX_RESTRICT m_z; #endif + #if defined(WARPX_DIM_RZ) RType* AMREX_RESTRICT m_theta; #endif @@ -216,24 +208,19 @@ struct SetParticlePosition AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator() (const long i, RType x, RType y, RType z) const noexcept { -#if defined(WARPX_DIM_XZ) - amrex::ignore_unused(y); -#endif -#if defined(WARPX_DIM_1D_Z) - amrex::ignore_unused(x,y); -#endif -#ifdef WARPX_DIM_RZ + amrex::ignore_unused(x,y,z); +#if defined(WARPX_DIM_RZ) m_theta[i] = std::atan2(y, x); m_x[i] = std::sqrt(x*x + y*y); m_z[i] = z; -#elif WARPX_DIM_3D +#elif defined(WARPX_DIM_3D) m_x[i] = x; m_y[i] = y; m_z[i] = z; -#elif WARPX_DIM_XZ +#elif defined(WARPX_DIM_XZ) m_x[i] = x; m_z[i] = z; -#else +#elif defined(WARPX_DIM_1D_Z) m_z[i] = z; #endif } @@ -245,24 +232,19 @@ struct SetParticlePosition AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AsStored (const long i, RType x, RType y, RType z) const noexcept { -#if defined(WARPX_DIM_XZ) - amrex::ignore_unused(y); -#endif -#if defined(WARPX_DIM_1D_Z) - amrex::ignore_unused(x,y); -#endif -#ifdef WARPX_DIM_RZ + amrex::ignore_unused(x,y,z); +#if defined(WARPX_DIM_RZ) m_x[i] = x; m_theta[i] = y; m_z[i] = z; -#elif WARPX_DIM_3D +#elif defined(WARPX_DIM_3D) m_x[i] = x; m_y[i] = y; m_z[i] = z; -#elif WARPX_DIM_XZ +#elif defined(WARPX_DIM_XZ) m_x[i] = x; m_z[i] = z; -#else +#elif defined(WARPX_DIM_1D_Z) m_z[i] = z; #endif } diff --git a/Source/Particles/Pusher/PushSelector.H b/Source/Particles/Pusher/PushSelector.H index 4a82e582bfb..d256a1a5e40 100644 --- a/Source/Particles/Pusher/PushSelector.H +++ b/Source/Particles/Pusher/PushSelector.H @@ -49,7 +49,7 @@ void doParticleMomentumPush(amrex::ParticleReal& ux, const int ion_lev, const amrex::ParticleReal m, const amrex::ParticleReal a_q, - const int pusher_algo, + const ParticlePusherAlgo pusher_algo, const int do_crr, #ifdef WARPX_QED const amrex::Real t_chi_max, diff --git a/Source/Particles/Pusher/UpdatePosition.H b/Source/Particles/Pusher/UpdatePosition.H index 89c2de88e47..d11ba6fe21f 100644 --- a/Source/Particles/Pusher/UpdatePosition.H +++ b/Source/Particles/Pusher/UpdatePosition.H @@ -22,7 +22,9 @@ * x^{n+1} - x^{n} = dt*u^{n+1/2}/gamma^{n+1/2} */ AMREX_GPU_HOST_DEVICE AMREX_INLINE -void UpdatePosition(amrex::ParticleReal& x, amrex::ParticleReal& y, amrex::ParticleReal& z, +void UpdatePosition([[maybe_unused]] amrex::ParticleReal& x, + [[maybe_unused]] amrex::ParticleReal& y, + [[maybe_unused]] amrex::ParticleReal& z, const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz, const amrex::Real dt ) { @@ -35,13 +37,9 @@ void UpdatePosition(amrex::ParticleReal& x, amrex::ParticleReal& y, amrex::Parti // Update positions over one time step #if (AMREX_SPACEDIM >= 2) x += ux * inv_gamma * dt; -#else - amrex::ignore_unused(x); #endif #if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ) // RZ pushes particles in 3D y += uy * inv_gamma * dt; -#else - amrex::ignore_unused(y); #endif z += uz * inv_gamma * dt; } @@ -53,10 +51,12 @@ void UpdatePosition(amrex::ParticleReal& x, amrex::ParticleReal& y, amrex::Parti * See Eqs. 15 and 17 in Chen, JCP 407 (2020) 109228. */ AMREX_GPU_HOST_DEVICE AMREX_INLINE -void UpdatePositionImplicit(amrex::ParticleReal& x, amrex::ParticleReal& y, amrex::ParticleReal& z, - const amrex::ParticleReal ux_n, const amrex::ParticleReal uy_n, const amrex::ParticleReal uz_n, - const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz, - const amrex::Real dt ) +void UpdatePositionImplicit ([[maybe_unused]] amrex::ParticleReal& x, + [[maybe_unused]] amrex::ParticleReal& y, + [[maybe_unused]] amrex::ParticleReal& z, + const amrex::ParticleReal ux_n, const amrex::ParticleReal uy_n, const amrex::ParticleReal uz_n, + const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz, + const amrex::Real dt ) { using namespace amrex::literals; @@ -74,13 +74,9 @@ void UpdatePositionImplicit(amrex::ParticleReal& x, amrex::ParticleReal& y, amre // Update positions over one time step #if (AMREX_SPACEDIM >= 2) x += ux * inv_gamma * dt; -#else - amrex::ignore_unused(x); #endif #if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ) // RZ pushes particles in 3D y += uy * inv_gamma * dt; -#else - amrex::ignore_unused(y); #endif z += uz * inv_gamma * dt; } @@ -90,20 +86,19 @@ void UpdatePositionImplicit(amrex::ParticleReal& x, amrex::ParticleReal& y, amre * of the particles for given electric and magnetic fields on the grid. */ AMREX_GPU_HOST_DEVICE AMREX_INLINE -void PositionNorm( amrex::ParticleReal dxp, amrex::ParticleReal dyp, amrex::ParticleReal dzp, - amrex::ParticleReal& dxp_save, amrex::ParticleReal& dyp_save, amrex::ParticleReal& dzp_save, - amrex::ParticleReal idxg2, amrex::ParticleReal idyg2, amrex::ParticleReal idzg2, +void PositionNorm ([[maybe_unused]] amrex::ParticleReal dxp, + [[maybe_unused]] amrex::ParticleReal dyp, + [[maybe_unused]] amrex::ParticleReal dzp, + [[maybe_unused]] amrex::ParticleReal& dxp_save, + [[maybe_unused]] amrex::ParticleReal& dyp_save, + [[maybe_unused]] amrex::ParticleReal& dzp_save, + [[maybe_unused]] amrex::ParticleReal idxg2, + [[maybe_unused]] amrex::ParticleReal idyg2, + [[maybe_unused]] amrex::ParticleReal idzg2, amrex::ParticleReal& step_norm, const int iter ) { using namespace amrex::literals; -#if defined(WARPX_DIM_1D_Z) - amrex::ignore_unused(dxp, dxp_save, idxg2); -#endif -#if !defined(WARPX_DIM_3D) - amrex::ignore_unused(dyp, dyp_save, idyg2); -#endif - if (iter==0) { step_norm = 1.0_prt; } else { step_norm = (dzp - dzp_save)*(dzp - dzp_save)*idzg2; diff --git a/Source/Particles/Resampling/VelocityCoincidenceThinning.H b/Source/Particles/Resampling/VelocityCoincidenceThinning.H index bb325734777..a815092e03e 100644 --- a/Source/Particles/Resampling/VelocityCoincidenceThinning.H +++ b/Source/Particles/Resampling/VelocityCoincidenceThinning.H @@ -123,7 +123,7 @@ public: void labelOnSphericalVelocityGrid (const amrex::ParticleReal ux[], const amrex::ParticleReal uy[], const amrex::ParticleReal uz[], - const unsigned int indices[], + const int indices[], int bin_array[], int index_array[], const int cell_start, const int cell_stop ) const { @@ -151,7 +151,7 @@ public: void labelOnCartesianVelocityGrid (const amrex::ParticleReal ux[], const amrex::ParticleReal uy[], const amrex::ParticleReal uz[], - const unsigned int indices[], + const int indices[], int bin_array[], int index_array[], const int cell_start, const int cell_stop ) const { @@ -168,7 +168,7 @@ public: AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator() (const amrex::ParticleReal ux[], const amrex::ParticleReal uy[], - const amrex::ParticleReal uz[], const unsigned int indices[], + const amrex::ParticleReal uz[], const int indices[], int bin_array[], int index_array[], const int cell_start, const int cell_stop) const { diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index d4c325fbfb8..7e882c151e8 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -354,7 +354,7 @@ public: amrex::Vector m_E_external_particle; //! Current injection position - amrex::Real m_current_injection_position; + amrex::Real m_current_injection_position = 0.; // split along diagonals (0) or axes (1) int split_type = 0; @@ -433,7 +433,7 @@ protected: amrex::ParticleReal charge; amrex::ParticleReal mass; - PhysicalSpecies physical_species; + PhysicalSpecies physical_species = PhysicalSpecies::unspecified; // Controls boundaries for particles exiting the domain ParticleBoundaries m_boundary_conditions; diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index bdce18b7b2b..591190a7a19 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -13,6 +13,7 @@ #include "Deposition/ChargeDeposition.H" #include "Deposition/CurrentDeposition.H" #include "Deposition/SharedDepositionUtils.H" +#include "EmbeddedBoundary/Enabled.H" #include "Pusher/GetAndSetPosition.H" #include "Pusher/UpdatePosition.H" #include "ParticleBoundaries_K.H" @@ -300,9 +301,11 @@ WarpXParticleContainer::AddNParticles (int /*lev*/, long n, // Remove particles that are inside the embedded boundaries #ifdef AMREX_USE_EB - auto & distance_to_eb = WarpX::GetInstance().GetDistanceToEB(); - scrapeParticlesAtEB( *this, amrex::GetVecOfConstPtrs(distance_to_eb), ParticleBoundaryProcess::Absorb()); - deleteInvalidParticles(); + if (EB::enabled()) { + auto & distance_to_eb = WarpX::GetInstance().GetDistanceToEB(); + scrapeParticlesAtEB( *this, amrex::GetVecOfConstPtrs(distance_to_eb), ParticleBoundaryProcess::Absorb()); + deleteInvalidParticles(); + } #endif } @@ -1422,26 +1425,33 @@ std::array WarpXParticleContainer::meanParticleVelocity(bool lo amrex::ParticleReal WarpXParticleContainer::maxParticleVelocity(bool local) { - amrex::ParticleReal max_v = 0.0; + const amrex::ParticleReal inv_clight_sq = 1.0_prt/(PhysConst::c*PhysConst::c); + ReduceOps reduce_op; + ReduceData reduce_data(reduce_op); const int nLevels = finestLevel(); - for (int lev = 0; lev <= nLevels; ++lev) - { #ifdef AMREX_USE_OMP -#pragma omp parallel reduction(max:max_v) +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif + for (int lev = 0; lev <= nLevels; ++lev) { for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) { - auto& ux = pti.GetAttribs(PIdx::ux); - auto& uy = pti.GetAttribs(PIdx::uy); - auto& uz = pti.GetAttribs(PIdx::uz); - for (unsigned long i = 0; i < ux.size(); i++) { - max_v = std::max(max_v, std::sqrt(ux[i]*ux[i] + uy[i]*uy[i] + uz[i]*uz[i])); - } + auto *const ux = pti.GetAttribs(PIdx::ux).data(); + auto *const uy = pti.GetAttribs(PIdx::uy).data(); + auto *const uz = pti.GetAttribs(PIdx::uz).data(); + + reduce_op.eval(pti.numParticles(), reduce_data, + [=] AMREX_GPU_DEVICE (int ip) + { return (ux[ip]*ux[ip] + uy[ip]*uy[ip] + uz[ip]*uz[ip]) * inv_clight_sq; }); } } + const amrex::ParticleReal max_usq = amrex::get<0>(reduce_data.value()); + + const amrex::ParticleReal gaminv = 1.0_prt/std::sqrt(1.0_prt + max_usq); + amrex::ParticleReal max_v = gaminv * std::sqrt(max_usq) * PhysConst::c; + if (!local) { ParallelAllReduce::Max(max_v, ParallelDescriptor::Communicator()); } return max_v; } @@ -1573,16 +1583,18 @@ WarpXParticleContainer::ApplyBoundaryConditions (){ { auto GetPosition = GetParticlePosition(pti); auto SetPosition = SetParticlePosition(pti); + amrex::XDim3 gridmin; + amrex::XDim3 gridmax; #ifndef WARPX_DIM_1D_Z - const Real xmin = Geom(lev).ProbLo(0); - const Real xmax = Geom(lev).ProbHi(0); + gridmin.x = Geom(lev).ProbLo(0); + gridmax.x = Geom(lev).ProbHi(0); #endif #ifdef WARPX_DIM_3D - const Real ymin = Geom(lev).ProbLo(1); - const Real ymax = Geom(lev).ProbHi(1); + gridmin.y = Geom(lev).ProbLo(1); + gridmax.y = Geom(lev).ProbHi(1); #endif - const Real zmin = Geom(lev).ProbLo(WARPX_ZINDEX); - const Real zmax = Geom(lev).ProbHi(WARPX_ZINDEX); + gridmin.z = Geom(lev).ProbLo(WARPX_ZINDEX); + gridmax.z = Geom(lev).ProbHi(WARPX_ZINDEX); ParticleTileType& ptile = ParticlesAt(lev, pti); @@ -1605,17 +1617,7 @@ WarpXParticleContainer::ApplyBoundaryConditions (){ // Note that for RZ, (x, y, z) is actually (r, theta, z). bool particle_lost = false; - ApplyParticleBoundaries::apply_boundaries( -#ifndef WARPX_DIM_1D_Z - x, xmin, xmax, -#endif -#if (defined WARPX_DIM_3D) || (defined WARPX_DIM_RZ) - y, -#endif -#if (defined WARPX_DIM_3D) - ymin, ymax, -#endif - z, zmin, zmax, + ApplyParticleBoundaries::apply_boundaries(x, y, z, gridmin, gridmax, ux[i], uy[i], uz[i], particle_lost, boundary_conditions, engine); diff --git a/Source/Python/WarpX.cpp b/Source/Python/WarpX.cpp index b3bd5414303..2689b3115fa 100644 --- a/Source/Python/WarpX.cpp +++ b/Source/Python/WarpX.cpp @@ -36,7 +36,7 @@ #include #include #include - +#include "FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H" #include #include #include @@ -176,13 +176,13 @@ The physical fields in WarpX have the following naming: std::string potential_lo_y, std::string potential_hi_y, std::string potential_lo_z, std::string potential_hi_z) { - if (potential_lo_x != "") wx.m_poisson_boundary_handler.potential_xlo_str = potential_lo_x; - if (potential_hi_x != "") wx.m_poisson_boundary_handler.potential_xhi_str = potential_hi_x; - if (potential_lo_y != "") wx.m_poisson_boundary_handler.potential_ylo_str = potential_lo_y; - if (potential_hi_y != "") wx.m_poisson_boundary_handler.potential_yhi_str = potential_hi_y; - if (potential_lo_z != "") wx.m_poisson_boundary_handler.potential_zlo_str = potential_lo_z; - if (potential_hi_z != "") wx.m_poisson_boundary_handler.potential_zhi_str = potential_hi_z; - wx.m_poisson_boundary_handler.buildParsers(); + if (potential_lo_x != "") wx.GetElectrostaticSolver().m_poisson_boundary_handler->potential_xlo_str = potential_lo_x; + if (potential_hi_x != "") wx.GetElectrostaticSolver().m_poisson_boundary_handler->potential_xhi_str = potential_hi_x; + if (potential_lo_y != "") wx.GetElectrostaticSolver().m_poisson_boundary_handler->potential_ylo_str = potential_lo_y; + if (potential_hi_y != "") wx.GetElectrostaticSolver().m_poisson_boundary_handler->potential_yhi_str = potential_hi_y; + if (potential_lo_z != "") wx.GetElectrostaticSolver().m_poisson_boundary_handler->potential_zlo_str = potential_lo_z; + if (potential_hi_z != "") wx.GetElectrostaticSolver().m_poisson_boundary_handler->potential_zhi_str = potential_hi_z; + wx.GetElectrostaticSolver().m_poisson_boundary_handler->BuildParsers(); }, py::arg("potential_lo_x") = "", py::arg("potential_hi_x") = "", @@ -194,11 +194,15 @@ The physical fields in WarpX have the following naming: ) .def("set_potential_on_eb", [](WarpX& wx, std::string potential) { - wx.m_poisson_boundary_handler.setPotentialEB(potential); + wx.GetElectrostaticSolver().m_poisson_boundary_handler->setPotentialEB(potential); }, py::arg("potential"), "Sets the EB potential string and updates the function parser." ) + .def_static("run_div_cleaner", + [] () { WarpX::ProjectionCleanDivB(); }, + "Executes projection based divergence cleaner on loaded Bfield_fp_external." + ) ; py::class_(m, "Config") diff --git a/Source/Utils/Algorithms/IsIn.H b/Source/Utils/Algorithms/IsIn.H index c9d2f477ef8..a4a9f955eec 100644 --- a/Source/Utils/Algorithms/IsIn.H +++ b/Source/Utils/Algorithms/IsIn.H @@ -26,7 +26,7 @@ namespace utils::algorithms * @return true if elem is in vect, false otherwise */ template ::value>::type> + class = typename std::enable_if_t>> bool is_in(const std::vector& vect, const TE& elem) { @@ -46,7 +46,7 @@ namespace utils::algorithms * @return true if any element of elems is in vect, false otherwise */ template ::value>::type> + class = typename std::enable_if_t>> bool any_of_is_in(const std::vector& vect, const std::vector& elems) { diff --git a/Source/Utils/CMakeLists.txt b/Source/Utils/CMakeLists.txt index 3d804fe9cde..82053bfc88a 100644 --- a/Source/Utils/CMakeLists.txt +++ b/Source/Utils/CMakeLists.txt @@ -6,7 +6,6 @@ foreach(D IN LISTS WarpX_DIMS) ParticleUtils.cpp SpeciesUtils.cpp RelativeCellPosition.cpp - WarpXAlgorithmSelection.cpp WarpXMovingWindow.cpp WarpXTagging.cpp WarpXUtil.cpp diff --git a/Source/Utils/Make.package b/Source/Utils/Make.package index dd7e61ff4fa..dc1f1da5c4c 100644 --- a/Source/Utils/Make.package +++ b/Source/Utils/Make.package @@ -2,7 +2,6 @@ CEXE_sources += WarpXMovingWindow.cpp CEXE_sources += WarpXTagging.cpp CEXE_sources += WarpXUtil.cpp CEXE_sources += WarpXVersion.cpp -CEXE_sources += WarpXAlgorithmSelection.cpp CEXE_sources += Interpolate.cpp CEXE_sources += IntervalsParser.cpp CEXE_sources += RelativeCellPosition.cpp diff --git a/Source/Utils/Physics/write_atomic_data_cpp.py b/Source/Utils/Physics/write_atomic_data_cpp.py index 11cd3b2c0c5..e1572871ada 100644 --- a/Source/Utils/Physics/write_atomic_data_cpp.py +++ b/Source/Utils/Physics/write_atomic_data_cpp.py @@ -7,84 +7,93 @@ # # License: BSD-3-Clause-LBNL -''' +""" This python script reads ionization tables in atomic_data.txt (generated from the NIST website) and extracts ionization levels into C++ file IonizationEnergiesTable.H, which contains tables + metadata. -''' +""" import os import re import numpy as np -filename = os.path.join( '.', 'atomic_data.txt' ) +filename = os.path.join(".", "atomic_data.txt") with open(filename) as f: text_data = f.read() # Read full table from file and get names, atomic numbers and offsets # position in table of ionization energies for all species -regex_command = '\n\s+(\d+)\s+\|\s+([A-Z]+[a-z]*)\s+\w+\s+\|\s+\+*(\d+)\s+\|\s+\(*\[*(\d+\.*\d*)' -list_of_tuples = re.findall( regex_command, text_data ) -ion_atom_numbers = [int(i) for i in list(dict.fromkeys( [x[0] for x in list_of_tuples] ))] -ion_names = list(dict.fromkeys( [x[1] for x in list_of_tuples] )) +regex_command = ( + "\n\s+(\d+)\s+\|\s+([A-Z]+[a-z]*)\s+\w+\s+\|\s+\+*(\d+)\s+\|\s+\(*\[*(\d+\.*\d*)" +) +list_of_tuples = re.findall(regex_command, text_data) +ion_atom_numbers = [int(i) for i in list(dict.fromkeys([x[0] for x in list_of_tuples]))] +ion_names = list(dict.fromkeys([x[1] for x in list_of_tuples])) ion_offsets = np.concatenate(([0], np.cumsum(np.array(ion_atom_numbers)[:-1])), axis=0) # Head of CPP file -cpp_string = '// This script was automatically generated!\n' -cpp_string += '// Edit dev/Source/Utils/Physics/write_atomic_data_cpp.py instead!\n\n' -cpp_string += '#ifndef WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n' -cpp_string += '#define WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n\n' -cpp_string += '#include \n\n' -cpp_string += '#include \n' -cpp_string += '#include \n\n' -cpp_string += 'namespace utils::physics\n' -cpp_string += '{\n' +cpp_string = "// This script was automatically generated!\n" +cpp_string += "// Edit dev/Source/Utils/Physics/write_atomic_data_cpp.py instead!\n\n" +cpp_string += "#ifndef WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n" +cpp_string += "#define WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n\n" +cpp_string += "#include \n\n" +cpp_string += "#include \n" +cpp_string += "#include \n\n" +cpp_string += "namespace utils::physics\n" +cpp_string += "{\n" # Map each element to ID in table -cpp_string += ' static std::map const ion_map_ids = {' +cpp_string += " static std::map const ion_map_ids = {" for count, name in enumerate(ion_names): - cpp_string += '\n {"' + name + '", ' + str(count) + '},' + cpp_string += '\n {"' + name + '", ' + str(count) + "}," cpp_string = cpp_string[:-1] -cpp_string += ' };\n\n' +cpp_string += " };\n\n" # Atomic number of each species -cpp_string += ' constexpr int nelements = ' + str(len(ion_names)) + ';\n\n' -cpp_string += ' constexpr int ion_atomic_numbers[nelements] = {\n ' +cpp_string += " constexpr int nelements = " + str(len(ion_names)) + ";\n\n" +cpp_string += " constexpr int ion_atomic_numbers[nelements] = {\n " for count, atom_num in enumerate(ion_atom_numbers): - if count%10==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' - cpp_string += str(atom_num) + ', ' + if count % 10 == 0 and count > 0: + cpp_string = cpp_string[:-2] + ",\n " + cpp_string += str(atom_num) + ", " cpp_string = cpp_string[:-2] -cpp_string += '};\n\n' +cpp_string += "};\n\n" # Offset of each element in table of ionization energies -cpp_string += ' constexpr int ion_energy_offsets[nelements] = {\n ' +cpp_string += " constexpr int ion_energy_offsets[nelements] = {\n " for count, offset in enumerate(ion_offsets): - if count%10==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' - cpp_string += str(offset) + ', ' + if count % 10 == 0 and count > 0: + cpp_string = cpp_string[:-2] + ",\n " + cpp_string += str(offset) + ", " cpp_string = cpp_string[:-2] -cpp_string += '};\n\n' +cpp_string += "};\n\n" # Table of ionization energies -cpp_string += ' constexpr int energies_tab_length = ' + str(len(list_of_tuples)) + ';\n\n' -cpp_string += ' constexpr amrex::Real table_ionization_energies[energies_tab_length]{' +cpp_string += ( + " constexpr int energies_tab_length = " + str(len(list_of_tuples)) + ";\n\n" +) +cpp_string += ( + " constexpr amrex::Real table_ionization_energies[energies_tab_length]{" +) for element in ion_names: - cpp_string += '\n // ' + element + '\n ' - regex_command = \ - '\n\s+(\d+)\s+\|\s+%s\s+\w+\s+\|\s+\+*(\d+)\s+\|\s+\(*\[*(\d+\.*\d*)' \ - %element - list_of_tuples = re.findall( regex_command, text_data ) + cpp_string += "\n // " + element + "\n " + regex_command = ( + "\n\s+(\d+)\s+\|\s+%s\s+\w+\s+\|\s+\+*(\d+)\s+\|\s+\(*\[*(\d+\.*\d*)" % element + ) + list_of_tuples = re.findall(regex_command, text_data) for count, energy in enumerate([x[2] for x in list_of_tuples]): - if count%3==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' - cpp_string += "amrex::Real(" + energy + '), ' + if count % 3 == 0 and count > 0: + cpp_string = cpp_string[:-2] + ",\n " + cpp_string += "amrex::Real(" + energy + "), " cpp_string = cpp_string[:-1] cpp_string = cpp_string[:-1] -cpp_string += '\n };\n\n' +cpp_string += "\n };\n\n" -cpp_string += '}\n\n' +cpp_string += "}\n\n" # Write the string to file -cpp_string += '#endif // #ifndef WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n' -f= open("IonizationEnergiesTable.H","w") +cpp_string += "#endif // #ifndef WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n" +f = open("IonizationEnergiesTable.H", "w") f.write(cpp_string) f.close() diff --git a/Source/Utils/WarpXAlgorithmSelection.H b/Source/Utils/WarpXAlgorithmSelection.H index 527b7766895..f67aeddadd0 100644 --- a/Source/Utils/WarpXAlgorithmSelection.H +++ b/Source/Utils/WarpXAlgorithmSelection.H @@ -9,30 +9,31 @@ #define WARPX_UTILS_WARPXALGORITHMSELECTION_H_ #include +#include +#include #include +using namespace ablastr::utils::enums; // NOLINT(google-global-names-in-headers) + + /** * \brief struct to determine the computational medium, i.e., vacuum or material/macroscopic default is vacuum. */ -struct MediumForEM { - enum { - Vacuum = 0, - Macroscopic = 1 - }; -}; +AMREX_ENUM(MediumForEM, + Vacuum, + Macroscopic, + Default = Vacuum); /** * \brief struct to select the overall evolve scheme */ -struct EvolveScheme { - enum { - Explicit = 0, - ThetaImplicitEM = 1, - SemiImplicitEM = 2 - }; -}; +AMREX_ENUM(EvolveScheme, + Explicit, + ThetaImplicitEM, + SemiImplicitEM, + Default = Explicit); /** * \brief struct to select algorithm for macroscopic Maxwell solver @@ -40,172 +41,116 @@ struct EvolveScheme { Backward Euler (fully-implicit) represents sigma*E = sigma*E^(n+1) default is Backward Euler as it is more robust. */ -struct MacroscopicSolverAlgo { - enum { - BackwardEuler = 0, - LaxWendroff = 1 - }; -}; - -struct GridType { - enum { - Collocated = 0, - Staggered = 1, - Hybrid = 2 - }; -}; - -enum struct PatchType -{ - fine, - coarse -}; - -struct ElectromagneticSolverAlgo { - enum { - None = 0, - Yee = 1, - CKC = 2, - PSATD = 3, - ECT = 4, - HybridPIC = 5 - }; -}; - -struct ElectrostaticSolverAlgo { - enum { - None = 0, - Relativistic = 1, - LabFrameElectroMagnetostatic = 2, - LabFrame = 3 // Non relativistic - }; -}; - -struct PoissonSolverAlgo { - enum { - Multigrid = 1, - IntegratedGreenFunction = 2, - }; -}; - -struct ParticlePusherAlgo { - enum { - Boris = 0, - Vay = 1, - HigueraCary = 2 - }; -}; - -struct CurrentDepositionAlgo { - enum { - Esirkepov = 0, - Direct = 1, - Vay = 2, - Villasenor = 3 - }; -}; - -struct ChargeDepositionAlgo { - // Only the Standard algorithm is implemented - enum { - Standard = 0 - }; -}; - -struct GatheringAlgo { - enum { - EnergyConserving = 0, - MomentumConserving - }; -}; - -struct PSATDSolutionType { - enum { - FirstOrder = 0, - SecondOrder = 1 - }; -}; - -struct JInTime { - enum { - Constant = 0, - Linear = 1 - }; -}; - -struct RhoInTime { - enum { - Constant = 0, - Linear = 1 - }; -}; +AMREX_ENUM(MacroscopicSolverAlgo, + BackwardEuler, + LaxWendroff, + Default = BackwardEuler); + +AMREX_ENUM(ElectromagneticSolverAlgo, + None, + Yee, + CKC, + PSATD, + ECT, + HybridPIC, + hybrid = HybridPIC, + Default = Yee); + +AMREX_ENUM(ElectrostaticSolverAlgo, + None, + Relativistic, + LabFrameElectroMagnetostatic, + LabFrame, + Default = None); + +AMREX_ENUM(PoissonSolverAlgo, + Multigrid, + IntegratedGreenFunction, + fft = IntegratedGreenFunction, + Default = Multigrid); + +AMREX_ENUM(ParticlePusherAlgo, + Boris, + Vay, + HigueraCary, + higuera = HigueraCary, + Default = Boris); + +AMREX_ENUM(CurrentDepositionAlgo, + Esirkepov, + Direct, + Vay, + Villasenor, + Default = Esirkepov); + +AMREX_ENUM(ChargeDepositionAlgo, + Standard, + Default = Standard); + +AMREX_ENUM(GatheringAlgo, + EnergyConserving, + MomentumConserving, + Default = EnergyConserving); + +AMREX_ENUM(PSATDSolutionType, + FirstOrder, + SecondOrder, + Default = SecondOrder); + +AMREX_ENUM(JInTime, + Constant, + Linear, + Default = Constant); + +AMREX_ENUM(RhoInTime, + Constant, + Linear, + Default = Linear); /** Strategy to compute weights for use in load balance. */ -struct LoadBalanceCostsUpdateAlgo { - enum { - Timers = 0, //!< load balance according to in-code timer-based weights (i.e., with `costs`) - Heuristic = 1 /**< load balance according to weights computed from number of cells - and number of particles per box (i.e., with `costs_heuristic`) */ - }; -}; +AMREX_ENUM(LoadBalanceCostsUpdateAlgo, + Timers, //!< load balance according to in-code timer-based weights (i.e., with `costs`) + Heuristic, /**< load balance according to weights computed from number of cells + and number of particles per box (i.e., with `costs_heuristic`) */ + Default = Timers); /** Field boundary conditions at the domain boundary */ -enum struct FieldBoundaryType { - PML = 0, - Periodic = 1, - PEC = 2, //!< perfect electric conductor (PEC) with E_tangential=0 - PMC = 3, //!< perfect magnetic conductor (PMC) with B_tangential=0 - Damped = 4, // Fields in the guard cells are damped for PSATD - //in the moving window direction - Absorbing_SilverMueller = 5, // Silver-Mueller boundary condition - Neumann = 6, // For electrostatic, the normal E is set to zero - None = 7, // The fields values at the boundary are not updated. This is - // useful for RZ simulations, at r=0. - Open = 8 // Used in the Integrated Green Function Poisson solver - // Note that the solver implicitely assumes open BCs: - // no need to enforce them separately -}; +AMREX_ENUM(FieldBoundaryType, + PML, + Periodic, + PEC, //!< perfect electric conductor (PEC) with E_tangential=0 + PMC, //!< perfect magnetic conductor (PMC) with B_tangential=0 + Damped, // Fields in the guard cells are damped for PSATD + //in the moving window direction + Absorbing_SilverMueller, // Silver-Mueller boundary condition + absorbingsilvermueller = Absorbing_SilverMueller, + Neumann, // For electrostatic, the normal E is set to zero + None, // The fields values at the boundary are not updated. This is + // useful for RZ simulations, at r=0. + Open, // Used in the Integrated Green Function Poisson solver + // Note that the solver implicitely assumes open BCs: + // no need to enforce them separately + Default = PML); /** Particle boundary conditions at the domain boundary */ -enum struct ParticleBoundaryType { - Absorbing = 0, //!< particles crossing domain boundary are removed - Open = 1, //!< particles cross domain boundary leave with damped j - Reflecting = 2, //!< particles are reflected - Periodic = 3, //!< particles are introduced from the periodic boundary - Thermal = 4, - None = 5 //!< For r=0 boundary with RZ simulations -}; +AMREX_ENUM(ParticleBoundaryType, + Absorbing, //!< particles crossing domain boundary are removed + Open, //!< particles cross domain boundary leave with damped j + Reflecting, //!< particles are reflected + Periodic, //!< particles are introduced from the periodic boundary + Thermal, + None, //!< For r=0 boundary with RZ simulations + Default = Absorbing); /** MPI reductions */ -struct ReductionType { - enum { - Maximum = 0, - Minimum = 1, - Sum = 2 - }; -}; - -int -GetAlgorithmInteger(const amrex::ParmParse& pp, const char* pp_search_key ); - -/** Select BC Type for fields, if field=true - * else select BCType for particles. - */ -FieldBoundaryType -GetFieldBCTypeInteger( std::string BCType ); - -/** Select BC Type for particles. - */ -ParticleBoundaryType -GetParticleBCTypeInteger( std::string BCType ); - -/** Find the name associated with a BC type - */ -std::string -GetFieldBCTypeString( FieldBoundaryType fb_type ); +AMREX_ENUM(ReductionType, + Maximum, + Minimum, + Sum, + Integral = Sum); #endif // WARPX_UTILS_WARPXALGORITHMSELECTION_H_ diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp deleted file mode 100644 index 89784c3b86c..00000000000 --- a/Source/Utils/WarpXAlgorithmSelection.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* Copyright 2019-2020 Axel Huebl, David Grote, Luca Fedeli - * Remi Lehe, Weiqun Zhang, Yinjian Zhao - * - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ -#include "WarpX.H" -#include "WarpXAlgorithmSelection.H" -#include "Utils/TextMsg.H" - -#include - -#include - -#include -#include -#include -#include -#include - -// Define dictionary with correspondence between user-input strings, -// and corresponding integer for use inside the code - -const std::map evolve_scheme_to_int = { - {"explicit", EvolveScheme::Explicit }, - {"theta_implicit_em", EvolveScheme::ThetaImplicitEM }, - {"semi_implicit_em", EvolveScheme::SemiImplicitEM }, - {"default", EvolveScheme::Explicit } -}; - -const std::map grid_to_int = { - {"collocated", GridType::Collocated}, - {"staggered", GridType::Staggered}, - {"hybrid", GridType::Hybrid}, - {"default", GridType::Staggered} -}; - -const std::map electromagnetic_solver_algo_to_int = { - {"none", ElectromagneticSolverAlgo::None }, - {"yee", ElectromagneticSolverAlgo::Yee }, - {"ckc", ElectromagneticSolverAlgo::CKC }, - {"psatd", ElectromagneticSolverAlgo::PSATD }, - {"ect", ElectromagneticSolverAlgo::ECT }, - {"hybrid", ElectromagneticSolverAlgo::HybridPIC }, - {"default", ElectromagneticSolverAlgo::Yee } -}; - -const std::map electrostatic_solver_algo_to_int = { - {"none", ElectrostaticSolverAlgo::None }, - {"relativistic", ElectrostaticSolverAlgo::Relativistic}, - {"labframe-electromagnetostatic", ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic}, - {"labframe", ElectrostaticSolverAlgo::LabFrame}, - {"default", ElectrostaticSolverAlgo::None } -}; - -const std::map poisson_solver_algo_to_int = { - {"multigrid", PoissonSolverAlgo::Multigrid}, - {"fft", PoissonSolverAlgo::IntegratedGreenFunction}, - {"default", PoissonSolverAlgo::Multigrid } -}; - -const std::map particle_pusher_algo_to_int = { - {"boris", ParticlePusherAlgo::Boris }, - {"vay", ParticlePusherAlgo::Vay }, - {"higuera", ParticlePusherAlgo::HigueraCary }, - {"default", ParticlePusherAlgo::Boris } -}; - -const std::map current_deposition_algo_to_int = { - {"esirkepov", CurrentDepositionAlgo::Esirkepov }, - {"direct", CurrentDepositionAlgo::Direct }, - {"vay", CurrentDepositionAlgo::Vay }, - {"villasenor", CurrentDepositionAlgo::Villasenor }, - {"default", CurrentDepositionAlgo::Esirkepov } // NOTE: overwritten for PSATD and Hybrid-PIC below -}; - -const std::map charge_deposition_algo_to_int = { - {"standard", ChargeDepositionAlgo::Standard }, - {"default", ChargeDepositionAlgo::Standard } -}; - -const std::map gathering_algo_to_int = { - {"energy-conserving", GatheringAlgo::EnergyConserving }, - {"momentum-conserving", GatheringAlgo::MomentumConserving }, - {"default", GatheringAlgo::EnergyConserving } -}; - -const std::map psatd_solution_type_to_int = { - {"first-order", PSATDSolutionType::FirstOrder}, - {"second-order", PSATDSolutionType::SecondOrder}, - {"default", PSATDSolutionType::SecondOrder} -}; - -const std::map J_in_time_to_int = { - {"constant", JInTime::Constant}, - {"linear", JInTime::Linear}, - {"default", JInTime::Constant} -}; - -const std::map rho_in_time_to_int = { - {"constant", RhoInTime::Constant}, - {"linear", RhoInTime::Linear}, - {"default", RhoInTime::Linear} -}; - -const std::map load_balance_costs_update_algo_to_int = { - {"timers", LoadBalanceCostsUpdateAlgo::Timers }, - {"heuristic", LoadBalanceCostsUpdateAlgo::Heuristic }, - {"default", LoadBalanceCostsUpdateAlgo::Timers } -}; - -const std::map MaxwellSolver_medium_algo_to_int = { - {"vacuum", MediumForEM::Vacuum}, - {"macroscopic", MediumForEM::Macroscopic}, - {"default", MediumForEM::Vacuum} -}; - -const std::map MacroscopicSolver_algo_to_int = { - {"backwardeuler", MacroscopicSolverAlgo::BackwardEuler}, - {"laxwendroff", MacroscopicSolverAlgo::LaxWendroff}, - {"default", MacroscopicSolverAlgo::BackwardEuler} -}; - -const std::map FieldBCType_algo_to_enum = { - {"pml", FieldBoundaryType::PML}, - {"periodic", FieldBoundaryType::Periodic}, - {"pec", FieldBoundaryType::PEC}, - {"pmc", FieldBoundaryType::PMC}, - {"damped", FieldBoundaryType::Damped}, - {"absorbing_silver_mueller", FieldBoundaryType::Absorbing_SilverMueller}, - {"neumann", FieldBoundaryType::Neumann}, - {"open", FieldBoundaryType::Open}, - {"none", FieldBoundaryType::None}, - {"default", FieldBoundaryType::PML} -}; - -const std::map ParticleBCType_algo_to_enum = { - {"absorbing", ParticleBoundaryType::Absorbing}, - {"open", ParticleBoundaryType::Open}, - {"reflecting", ParticleBoundaryType::Reflecting}, - {"periodic", ParticleBoundaryType::Periodic}, - {"thermal", ParticleBoundaryType::Thermal}, - {"none", ParticleBoundaryType::None}, - {"default", ParticleBoundaryType::Absorbing} -}; - -const std::map ReductionType_algo_to_int = { - {"maximum", ReductionType::Maximum}, - {"minimum", ReductionType::Minimum}, - {"integral", ReductionType::Sum} -}; - -int -GetAlgorithmInteger(const amrex::ParmParse& pp, const char* pp_search_key ){ - - // Read user input ; use "default" if it is not found - std::string algo = "default"; - pp.query( pp_search_key, algo ); - // Convert to lower case - std::transform(algo.begin(), algo.end(), algo.begin(), ::tolower); - - // Pick the right dictionary - std::map algo_to_int; - if (0 == std::strcmp(pp_search_key, "evolve_scheme")) { - algo_to_int = evolve_scheme_to_int; - } else if (0 == std::strcmp(pp_search_key, "maxwell_solver")) { - algo_to_int = electromagnetic_solver_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "grid_type")) { - algo_to_int = grid_to_int; - } else if (0 == std::strcmp(pp_search_key, "do_electrostatic")) { - algo_to_int = electrostatic_solver_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "poisson_solver")) { - algo_to_int = poisson_solver_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "particle_pusher")) { - algo_to_int = particle_pusher_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "current_deposition")) { - algo_to_int = current_deposition_algo_to_int; - if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD || - WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC || - WarpX::electrostatic_solver_id != ElectrostaticSolverAlgo::None) { - algo_to_int["default"] = CurrentDepositionAlgo::Direct; - } - } else if (0 == std::strcmp(pp_search_key, "charge_deposition")) { - algo_to_int = charge_deposition_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "field_gathering")) { - algo_to_int = gathering_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "solution_type")) { - algo_to_int = psatd_solution_type_to_int; - } else if (0 == std::strcmp(pp_search_key, "J_in_time")) { - algo_to_int = J_in_time_to_int; - } else if (0 == std::strcmp(pp_search_key, "rho_in_time")) { - algo_to_int = rho_in_time_to_int; - } else if (0 == std::strcmp(pp_search_key, "load_balance_costs_update")) { - algo_to_int = load_balance_costs_update_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "em_solver_medium")) { - algo_to_int = MaxwellSolver_medium_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "macroscopic_sigma_method")) { - algo_to_int = MacroscopicSolver_algo_to_int; - } else if (0 == std::strcmp(pp_search_key, "reduction_type")) { - algo_to_int = ReductionType_algo_to_int; - } else { - std::string const pp_search_string = pp_search_key; - WARPX_ABORT_WITH_MESSAGE("Unknown algorithm type: " + pp_search_string); - } - - // Check if the user-input is a valid key for the dictionary - if (algo_to_int.count(algo) == 0) { - // Not a valid key ; print error message - const std::string pp_search_string = pp_search_key; - std::string error_message = "Invalid string for algo." + pp_search_string - + ": " + algo + ".\nThe valid values are:\n"; - for ( const auto &valid_pair : algo_to_int ) { - if (valid_pair.first != "default"){ - error_message += " - " + valid_pair.first + "\n"; - } - } - WARPX_ABORT_WITH_MESSAGE(error_message); - } - - // If the input is a valid key, return the value - return algo_to_int[algo]; -} - -FieldBoundaryType -GetFieldBCTypeInteger( std::string BCType ){ - std::transform(BCType.begin(), BCType.end(), BCType.begin(), ::tolower); - - if (FieldBCType_algo_to_enum.count(BCType) == 0) { - std::string error_message = "Invalid string for field/particle BC. : " + BCType + "\nThe valid values are : \n"; - for (const auto &valid_pair : FieldBCType_algo_to_enum) { - if (valid_pair.first != "default"){ - error_message += " - " + valid_pair.first + "\n"; - } - } - WARPX_ABORT_WITH_MESSAGE(error_message); - } - // return FieldBCType_algo_to_enum[BCType]; // This operator cannot be used for a const map - return FieldBCType_algo_to_enum.at(BCType); -} - -ParticleBoundaryType -GetParticleBCTypeInteger( std::string BCType ){ - std::transform(BCType.begin(), BCType.end(), BCType.begin(), ::tolower); - - if (ParticleBCType_algo_to_enum.count(BCType) == 0) { - std::string error_message = "Invalid string for particle BC. : " + BCType + "\nThe valid values are : \n"; - for (const auto &valid_pair : ParticleBCType_algo_to_enum) { - if (valid_pair.first != "default"){ - error_message += " - " + valid_pair.first + "\n"; - } - } - WARPX_ABORT_WITH_MESSAGE(error_message); - } - // return ParticleBCType_algo_to_enum[BCType]; // This operator cannot be used for a const map - return ParticleBCType_algo_to_enum.at(BCType); -} - -std::string -GetFieldBCTypeString( FieldBoundaryType fb_type ) { - std::string boundary_name; - for (const auto &valid_pair : FieldBCType_algo_to_enum) { - if ((valid_pair.second == fb_type)&&(valid_pair.first != "default")){ - boundary_name = valid_pair.first; - break; - } - } - return boundary_name; -} diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index d64394dafc9..73696838cd4 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -534,7 +534,7 @@ WarpX::shiftMF (amrex::MultiFab& mf, const amrex::Geometry& geom, #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (amrex::MFIter mfi(tmpmf); mfi.isValid(); ++mfi ) + for (amrex::MFIter mfi(tmpmf, TilingIfNotGPU()); mfi.isValid(); ++mfi ) { if (cost && WarpX::load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Timers) { @@ -545,7 +545,7 @@ WarpX::shiftMF (amrex::MultiFab& mf, const amrex::Geometry& geom, auto const& dstfab = mf.array(mfi); auto const& srcfab = tmpmf.array(mfi); - const amrex::Box& outbox = mfi.fabbox() & adjBox; + const amrex::Box& outbox = mfi.growntilebox() & adjBox; if (outbox.ok()) { if (!useparser) { diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 2ef4ee55d6e..4556d64684f 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -76,7 +76,8 @@ void ParseGeometryInput() #ifdef WARPX_DIM_RZ const ParmParse pp_algo("algo"); - const int electromagnetic_solver_id = GetAlgorithmInteger(pp_algo, "maxwell_solver"); + auto electromagnetic_solver_id = ElectromagneticSolverAlgo::Default; + pp_algo.query_enum_sloppy("maxwell_solver", electromagnetic_solver_id, "-_"); if (electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE(prob_lo[0] == 0., @@ -310,7 +311,8 @@ void CheckGriddingForRZSpectral () CheckDims(); const ParmParse pp_algo("algo"); - const int electromagnetic_solver_id = GetAlgorithmInteger(pp_algo, "maxwell_solver"); + auto electromagnetic_solver_id = ElectromagneticSolverAlgo::Default; + pp_algo.query_enum_sloppy("maxwell_solver", electromagnetic_solver_id, "-_"); // only check for PSATD in RZ if (electromagnetic_solver_id != ElectromagneticSolverAlgo::PSATD) { @@ -395,16 +397,14 @@ void CheckGriddingForRZSpectral () void ReadBCParams () { - amrex::Vector field_BC_lo(AMREX_SPACEDIM,"default"); - amrex::Vector field_BC_hi(AMREX_SPACEDIM,"default"); - amrex::Vector particle_BC_lo(AMREX_SPACEDIM,"default"); - amrex::Vector particle_BC_hi(AMREX_SPACEDIM,"default"); amrex::Vector geom_periodicity(AMREX_SPACEDIM,0); ParmParse pp_geometry("geometry"); const ParmParse pp_warpx("warpx"); const ParmParse pp_algo("algo"); - const int electromagnetic_solver_id = GetAlgorithmInteger(pp_algo, "maxwell_solver"); - const int poisson_solver_id = GetAlgorithmInteger(pp_warpx, "poisson_solver"); + auto electromagnetic_solver_id = ElectromagneticSolverAlgo::Default; + pp_algo.query_enum_sloppy("maxwell_solver", electromagnetic_solver_id, "-_"); + auto poisson_solver_id = PoissonSolverAlgo::Default; + pp_warpx.query_enum_sloppy("poisson_solver", poisson_solver_id, "-_"); if (pp_geometry.queryarr("is_periodic", geom_periodicity)) { @@ -419,26 +419,21 @@ void ReadBCParams () // particle boundary may not be explicitly specified for some applications bool particle_boundary_specified = false; const ParmParse pp_boundary("boundary"); - pp_boundary.queryarr("field_lo", field_BC_lo, 0, AMREX_SPACEDIM); - pp_boundary.queryarr("field_hi", field_BC_hi, 0, AMREX_SPACEDIM); - if (pp_boundary.queryarr("particle_lo", particle_BC_lo, 0, AMREX_SPACEDIM)) { - particle_boundary_specified = true; - } - if (pp_boundary.queryarr("particle_hi", particle_BC_hi, 0, AMREX_SPACEDIM)) { - particle_boundary_specified = true; - } - AMREX_ALWAYS_ASSERT(field_BC_lo.size() == AMREX_SPACEDIM); - AMREX_ALWAYS_ASSERT(field_BC_hi.size() == AMREX_SPACEDIM); - AMREX_ALWAYS_ASSERT(particle_BC_lo.size() == AMREX_SPACEDIM); - AMREX_ALWAYS_ASSERT(particle_BC_hi.size() == AMREX_SPACEDIM); - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { // Get field boundary type - WarpX::field_boundary_lo[idim] = GetFieldBCTypeInteger(field_BC_lo[idim]); - WarpX::field_boundary_hi[idim] = GetFieldBCTypeInteger(field_BC_hi[idim]); + pp_boundary.query_enum_sloppy("field_lo", + WarpX::field_boundary_lo[idim], "-_", idim); + pp_boundary.query_enum_sloppy("field_hi", + WarpX::field_boundary_hi[idim], "-_", idim); // Get particle boundary type - WarpX::particle_boundary_lo[idim] = GetParticleBCTypeInteger(particle_BC_lo[idim]); - WarpX::particle_boundary_hi[idim] = GetParticleBCTypeInteger(particle_BC_hi[idim]); + if (pp_boundary.query_enum_sloppy("particle_lo", + WarpX::particle_boundary_lo[idim], "-_", idim)) { + particle_boundary_specified = true; + } + if (pp_boundary.query_enum_sloppy("particle_hi", + WarpX::particle_boundary_hi[idim], "-_", idim)) { + particle_boundary_specified = true; + } if (WarpX::field_boundary_lo[idim] == FieldBoundaryType::Periodic || WarpX::field_boundary_hi[idim] == FieldBoundaryType::Periodic || diff --git a/Source/Utils/check_interp_points_and_weights.py b/Source/Utils/check_interp_points_and_weights.py index 8bf2cf08490..2f5a6e13b96 100644 --- a/Source/Utils/check_interp_points_and_weights.py +++ b/Source/Utils/check_interp_points_and_weights.py @@ -4,7 +4,7 @@ # # License: BSD-3-Clause-LBNL -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Compute interpolation points and weights for coarsening and refinement in IO # and MR applications in 1D (extensions to 2D and 3D are trivial). Weights are # computed in order to guarantee total charge conservation for both cell-centered @@ -23,7 +23,7 @@ # while terms multiplied by sf*sc are ON for nodal data and OFF for cell-centered # data. C++ implementation in Source/ablastr/coarsen/average.(H/.cpp) and # Source/ablastr/coarsen/sample.(H/.cpp) -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- import sys @@ -31,57 +31,67 @@ # Fine grid limits (without ghost cells) -def fine_grid_limits( sf ): - if ( sf == 0 ): # cell-centered - iimin = 0 - iimax = 7 - elif ( sf == 1 ): # nodal - iimin = 0 - iimax = 8 - return [ iimin, iimax ] +def fine_grid_limits(sf): + if sf == 0: # cell-centered + iimin = 0 + iimax = 7 + elif sf == 1: # nodal + iimin = 0 + iimax = 8 + return [iimin, iimax] + # Coarse grid limits (without ghost cells) -def coarse_grid_limits( sc, sf, iimin, iimax ): - imin = int( iimin/cr ) - imax = int( iimax/cr )-(1-sc)*sf+(1-sf)*sc - return [ imin, imax ] +def coarse_grid_limits(sc, sf, iimin, iimax): + imin = int(iimin / cr) + imax = int(iimax / cr) - (1 - sc) * sf + (1 - sf) * sc + return [imin, imax] + # Coarsening for MR: interpolation points and weights -def coarsening_points_and_weights( i, sc, sf, cr ): - if ( cr==1 ): +def coarsening_points_and_weights(i, sc, sf, cr): + if cr == 1: numpts = 1 idxmin = i - elif ( cr>=2 ): - numpts = cr*(1-sf)*(1-sc)+(2*(cr-1)+1)*sf*sc - idxmin = i*cr*(1-sf)*(1-sc)+(i*cr-cr+1)*sf*sc - weights = np.zeros( numpts ) - for ir in range( numpts ): - ii = idxmin+ir - weights[ir] = (1/cr)*(1-sf)*(1-sc)+((abs(cr-abs(ii-i*cr)))/(cr*cr))*sf*sc - return [ numpts, idxmin, weights ] + elif cr >= 2: + numpts = cr * (1 - sf) * (1 - sc) + (2 * (cr - 1) + 1) * sf * sc + idxmin = i * cr * (1 - sf) * (1 - sc) + (i * cr - cr + 1) * sf * sc + weights = np.zeros(numpts) + for ir in range(numpts): + ii = idxmin + ir + weights[ir] = (1 / cr) * (1 - sf) * (1 - sc) + ( + (abs(cr - abs(ii - i * cr))) / (cr * cr) + ) * sf * sc + return [numpts, idxmin, weights] + # Refinement for MR: interpolation points and weights -def refinement_points_and_weights( ii, sc, sf, cr ): - if ( cr==1 ): +def refinement_points_and_weights(ii, sc, sf, cr): + if cr == 1: numpts = 1 idxmin = ii - elif ( cr>=2 ): - if ( ii%cr==0 ): - numpts = (1-sf)*(1-sc)+sf*sc - elif ( ii%cr!=0 ): - numpts = (1-sf)*(1-sc)+2*sf*sc - idxmin = (ii//cr)*(1-sf)*(1-sc)+(ii//cr)*sf*sc - weights = np.zeros( numpts ) - for ir in range( numpts ): - i = idxmin+ir - if ( ii==iimin or ii==iimax ): - weights[ir] = (1-sf)*(1-sc)+((abs(cr-abs(ii-i*cr)))/(cr)+(cr/2-0.5))*sf*sc + elif cr >= 2: + if ii % cr == 0: + numpts = (1 - sf) * (1 - sc) + sf * sc + elif ii % cr != 0: + numpts = (1 - sf) * (1 - sc) + 2 * sf * sc + idxmin = (ii // cr) * (1 - sf) * (1 - sc) + (ii // cr) * sf * sc + weights = np.zeros(numpts) + for ir in range(numpts): + i = idxmin + ir + if ii == iimin or ii == iimax: + weights[ir] = (1 - sf) * (1 - sc) + ( + (abs(cr - abs(ii - i * cr))) / (cr) + (cr / 2 - 0.5) + ) * sf * sc else: - weights[ir] = (1-sf)*(1-sc)+((abs(cr-abs(ii-i*cr)))/(cr))*sf*sc - return [ numpts, idxmin, weights ] + weights[ir] = (1 - sf) * (1 - sc) + ( + (abs(cr - abs(ii - i * cr))) / (cr) + ) * sf * sc + return [numpts, idxmin, weights] + ## TODO Coarsening for IO: interpolation points and weights -#def coarsening_points_and_weights_for_IO( i, sf, sc, cr ): +# def coarsening_points_and_weights_for_IO( i, sf, sc, cr ): # if ( cr==1 ): # numpts = 1+abs(sf-sc) # idxmin = i-sc*(1-sf) @@ -93,98 +103,113 @@ def refinement_points_and_weights( ii, sc, sf, cr ): # weights[ir] = (1/numpts)*(1-sf)*(1-sc)+(1/numpts)*sf*sc # return [ numpts, idxmin, weights ] -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Main -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Input coarsening ratio -cr = int( input( "\n Select coarsening ratio (cr=1,2,4): cr=" ) ) -if ( cr!=1 and cr!=2 and cr!=4 ): +cr = int(input("\n Select coarsening ratio (cr=1,2,4): cr=")) +if cr != 1 and cr != 2 and cr != 4: print() - sys.exit( 'coarsening ratio cr={} is not valid'.format( cr ) ) + sys.exit("coarsening ratio cr={} is not valid".format(cr)) # Loop over possible staggering of coarse and fine grid (cell-centered or nodal) -for sc in [0,1]: - for sf in [0,1]: - - print( '\n **************************************************' ) - print( ' * Staggering of coarse grid: sc={}'.format( sc ), end='' ) - if ( sc == 0 ): - print( ' cell-centered *' ) - elif ( sc == 1 ): - print( ' nodal *' ) - print( ' * Staggering of fine grid: sf={}'.format( sf ), end='' ) - if ( sf == 0 ): - print( ' cell-centered *' ) - elif ( sf == 1 ): - print( ' nodal *' ) - print( ' **************************************************' ) - - iimin,iimax = fine_grid_limits( sf ) - imin ,imax = coarse_grid_limits( sc, sf, iimin, iimax ) - - print( '\n Min and max index on coarse grid: imin={} imax={}'.format( imin, imax ) ) - print( ' Min and max index on fine grid: iimin={} iimax={}'.format( iimin, iimax ) ) +for sc in [0, 1]: + for sf in [0, 1]: + print("\n **************************************************") + print(" * Staggering of coarse grid: sc={}".format(sc), end="") + if sc == 0: + print(" cell-centered *") + elif sc == 1: + print(" nodal *") + print(" * Staggering of fine grid: sf={}".format(sf), end="") + if sf == 0: + print(" cell-centered *") + elif sf == 1: + print(" nodal *") + print(" **************************************************") + + iimin, iimax = fine_grid_limits(sf) + imin, imax = coarse_grid_limits(sc, sf, iimin, iimax) + + print( + "\n Min and max index on coarse grid: imin={} imax={}".format(imin, imax) + ) + print( + " Min and max index on fine grid: iimin={} iimax={}".format(iimin, iimax) + ) # Number of grid points - nc = imax-imin+1 - nf = iimax-iimin+1 - - print( '\n Number of points on coarse grid: nc={}'.format( nc ) ) - print( ' Number of points on fine grid: nf={}'.format( nf ) ) - - if ( sf!=sc ): - print( '\n WARNING: sc={} not equal to sf={}, not implemented for MR, continue ...'.format( sc, sf ) ) + nc = imax - imin + 1 + nf = iimax - iimin + 1 + + print("\n Number of points on coarse grid: nc={}".format(nc)) + print(" Number of points on fine grid: nf={}".format(nf)) + + if sf != sc: + print( + "\n WARNING: sc={} not equal to sf={}, not implemented for MR, continue ...".format( + sc, sf + ) + ) continue - print( '\n Coarsening for MR: check interpolation points and weights' ) - print( ' ---------------------------------------------------------' ) + print("\n Coarsening for MR: check interpolation points and weights") + print(" ---------------------------------------------------------") # Coarsening for MR: interpolation points and weights - for i in range ( nc ): # index on coarse grid - numpts,idxmin,weights = coarsening_points_and_weights( i, sc, sf, cr ) - print( '\n Find value at i={} by interpolating over the following points and weights:'.format( i ) ) - for ir in range( numpts ): # interpolation points and weights - ii = idxmin+ir - print( ' ({},{})'.format( ii, weights[ir] ), end='' ) - if not ( ir == numpts-1 ): - print( ' ', end='' ) + for i in range(nc): # index on coarse grid + numpts, idxmin, weights = coarsening_points_and_weights(i, sc, sf, cr) + print( + "\n Find value at i={} by interpolating over the following points and weights:".format( + i + ) + ) + for ir in range(numpts): # interpolation points and weights + ii = idxmin + ir + print(" ({},{})".format(ii, weights[ir]), end="") + if not (ir == numpts - 1): + print(" ", end="") print() # Coarsening for MR: check conservation properties - for ii in range( nf ): # index on fine grid + for ii in range(nf): # index on fine grid ws = 0.0 - for i in range( nc ): # index on coarse grid - numpts,idxmin,weights = coarsening_points_and_weights( i, sc, sf, cr ) - for ir in range( numpts ): # interpolation points and weights - jj = idxmin+ir - if ( jj==ii ): # interpolation point matches point on fine grid - ws += weights[ir] - if ( ws!=1.0/cr ): - print( '\n ERROR: sum of weights ws={} should be 1/cr'.format( ws ) ) - - print( '\n Refinement for MR: check interpolation points and weights' ) - print( ' ---------------------------------------------------------' ) + for i in range(nc): # index on coarse grid + numpts, idxmin, weights = coarsening_points_and_weights(i, sc, sf, cr) + for ir in range(numpts): # interpolation points and weights + jj = idxmin + ir + if jj == ii: # interpolation point matches point on fine grid + ws += weights[ir] + if ws != 1.0 / cr: + print("\n ERROR: sum of weights ws={} should be 1/cr".format(ws)) + + print("\n Refinement for MR: check interpolation points and weights") + print(" ---------------------------------------------------------") # Refinement for MR: interpolation points and weights - for ii in range ( nf ): # index on fine grid - numpts,idxmin,weights = refinement_points_and_weights( ii, sc, sf, cr ) - print( '\n Find value at ii={} by interpolating over the following points and weights:'.format( ii ) ) - for ir in range( numpts ): # interpolation points and weights - i = idxmin+ir - print( ' ({},{})'.format( i, weights[ir] ), end='' ) - if not ( ir == numpts-1 ): - print( ' ', end='' ) + for ii in range(nf): # index on fine grid + numpts, idxmin, weights = refinement_points_and_weights(ii, sc, sf, cr) + print( + "\n Find value at ii={} by interpolating over the following points and weights:".format( + ii + ) + ) + for ir in range(numpts): # interpolation points and weights + i = idxmin + ir + print(" ({},{})".format(i, weights[ir]), end="") + if not (ir == numpts - 1): + print(" ", end="") print() # Refinement for MR: check conservation properties - for i in range( nc ): # index on coarse grid + for i in range(nc): # index on coarse grid ws = 0.0 - for ii in range( nf ): # index on fine grid - numpts,idxmin,weights = refinement_points_and_weights( ii, sc, sf, cr ) - for ir in range( numpts ): # interpolation points and weights - jj = idxmin+ir - if ( jj==i ): # interpolation point matches point on coarse grid - ws += weights[ir] - if ( ws!=cr ): - print( '\n ERROR: sum of weights ws={} should be cr'.format( ws ) ) + for ii in range(nf): # index on fine grid + numpts, idxmin, weights = refinement_points_and_weights(ii, sc, sf, cr) + for ir in range(numpts): # interpolation points and weights + jj = idxmin + ir + if jj == i: # interpolation point matches point on coarse grid + ws += weights[ir] + if ws != cr: + print("\n ERROR: sum of weights ws={} should be cr".format(ws)) diff --git a/Source/WarpX.H b/Source/WarpX.H index 3372dd869cc..28bb6215a45 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -16,6 +16,7 @@ #include "Diagnostics/MultiDiagnostics_fwd.H" #include "Diagnostics/ReducedDiags/MultiReducedDiags_fwd.H" #include "EmbeddedBoundary/WarpXFaceInfoBox_fwd.H" +#include "FieldSolver/ElectrostaticSolvers/ElectrostaticSolver_fwd.H" #include "FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver_fwd.H" #include "FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties_fwd.H" #include "FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel_fwd.H" @@ -39,7 +40,6 @@ #include "Evolve/WarpXDtType.H" #include "Evolve/WarpXPushType.H" #include "FieldSolver/Fields.H" -#include "FieldSolver/ElectrostaticSolver.H" #include "FieldSolver/MagnetostaticSolver/MagnetostaticSolver.H" #include "FieldSolver/ImplicitSolvers/ImplicitSolver.H" #include "FieldSolver/ImplicitSolvers/WarpXSolverVec.H" @@ -49,6 +49,8 @@ #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/export.H" +#include + #include #include #include @@ -140,6 +142,7 @@ public: MultiParticleContainer& GetPartContainer () { return *mypc; } MultiFluidContainer& GetFluidContainer () { return *myfl; } MacroscopicProperties& GetMacroscopicProperties () { return *m_macroscopic_properties; } + ElectrostaticSolver& GetElectrostaticSolver () {return *m_electrostatic_solver;} HybridPICModel& GetHybridPICModel () { return *m_hybrid_pic_model; } [[nodiscard]] HybridPICModel * get_pointer_HybridPICModel () const { return m_hybrid_pic_model.get(); } MultiDiagnostics& GetMultiDiags () {return *multi_diags;} @@ -168,17 +171,17 @@ public: // Algorithms //! Integer that corresponds to the current deposition algorithm (Esirkepov, direct, Vay, Villasenor) - static short current_deposition_algo; + static inline auto current_deposition_algo = CurrentDepositionAlgo::Default; //! Integer that corresponds to the charge deposition algorithm (only standard deposition) - static short charge_deposition_algo; + static inline auto charge_deposition_algo = ChargeDepositionAlgo::Default; //! Integer that corresponds to the field gathering algorithm (energy-conserving, momentum-conserving) - static short field_gathering_algo; + static inline auto field_gathering_algo = GatheringAlgo::Default; //! Integer that corresponds to the particle push algorithm (Boris, Vay, Higuera-Cary) - static short particle_pusher_algo; + static inline auto particle_pusher_algo = ParticlePusherAlgo::Default; //! Integer that corresponds to the type of Maxwell solver (Yee, CKC, PSATD, ECT) - static short electromagnetic_solver_id; + static inline auto electromagnetic_solver_id = ElectromagneticSolverAlgo::Default; //! Integer that corresponds to the evolve scheme (explicit, semi_implicit_em, theta_implicit_em) - static short evolve_scheme; + static inline auto evolve_scheme = EvolveScheme::Default; //! Maximum iterations used for self-consistent particle update in implicit particle-suppressed evolve schemes static int max_particle_its_in_implicit_scheme; //! Relative tolerance used for self-consistent particle update in implicit particle-suppressed evolve schemes @@ -186,43 +189,55 @@ public: /** Records a number corresponding to the load balance cost update strategy * being used (0 or 1 corresponding to timers or heuristic). */ - static short load_balance_costs_update_algo; + static inline auto load_balance_costs_update_algo = LoadBalanceCostsUpdateAlgo::Default; //! Integer that corresponds to electromagnetic Maxwell solver (vacuum - 0, macroscopic - 1) - static int em_solver_medium; + static inline auto em_solver_medium = MediumForEM::Default; /** Integer that correspond to macroscopic Maxwell solver algorithm * (BackwardEuler - 0, Lax-Wendroff - 1) */ - static int macroscopic_solver_algo; + static inline auto macroscopic_solver_algo = MacroscopicSolverAlgo::Default; /** Integers that correspond to boundary condition applied to fields at the * lower domain boundaries * (0 to 6 correspond to PML, Periodic, PEC, PMC, Damped, Absorbing Silver-Mueller, None) */ - static amrex::Vector field_boundary_lo; + static inline amrex::Array + field_boundary_lo {AMREX_D_DECL(FieldBoundaryType::Default, + FieldBoundaryType::Default, + FieldBoundaryType::Default)}; /** Integers that correspond to boundary condition applied to fields at the * upper domain boundaries * (0 to 6 correspond to PML, Periodic, PEC, PMC, Damped, Absorbing Silver-Mueller, None) */ - static amrex::Vector field_boundary_hi; + static inline amrex::Array + field_boundary_hi {AMREX_D_DECL(FieldBoundaryType::Default, + FieldBoundaryType::Default, + FieldBoundaryType::Default)}; /** Integers that correspond to boundary condition applied to particles at the * lower domain boundaries * (0 to 4 correspond to Absorbing, Open, Reflecting, Periodic, Thermal) */ - static amrex::Vector particle_boundary_lo; + static inline amrex::Array + particle_boundary_lo {AMREX_D_DECL(ParticleBoundaryType::Default, + ParticleBoundaryType::Default, + ParticleBoundaryType::Default)}; /** Integers that correspond to boundary condition applied to particles at the * upper domain boundaries * (0 to 4 correspond to Absorbing, Open, Reflecting, Periodic, Thermal) */ - static amrex::Vector particle_boundary_hi; + static inline amrex::Array + particle_boundary_hi {AMREX_D_DECL(ParticleBoundaryType::Default, + ParticleBoundaryType::Default, + ParticleBoundaryType::Default)}; //! Integer that corresponds to the order of the PSATD solution //! (whether the PSATD equations are derived from first-order or //! second-order solution) - static short psatd_solution_type; + static inline auto psatd_solution_type = PSATDSolutionType::Default; //! Integers that correspond to the time dependency of J (constant, linear) //! and rho (linear, quadratic) for the PSATD algorithm - static short J_in_time; - static short rho_in_time; + static inline auto J_in_time = JInTime::Default; + static inline auto rho_in_time = RhoInTime::Default; //! If true, the current is deposited on a nodal grid and then centered onto a staggered grid //! using finite centering of order given by #current_centering_nox, #current_centering_noy, @@ -231,7 +246,7 @@ public: //! If true, a correction is applied to the current in Fourier space, // to satisfy the continuity equation and charge conservation - bool current_correction; + bool current_correction = true; //! If true, the PSATD update equation for E contains both J and rho //! (default is false for standard PSATD and true for Galilean PSATD) @@ -264,6 +279,10 @@ public: //! Solve additional Maxwell equation for G in order to control errors in magnetic Gauss' law static bool do_divb_cleaning; + //! Solve Poisson equation when loading an external magnetic field to clean divergence + //! This is useful to remove errors that could lead to non-zero B field divergence + static bool do_divb_cleaning_external; + //! Order of the particle shape factors (splines) along x static int nox; //! Order of the particle shape factors (splines) along y @@ -371,7 +390,7 @@ public: //! Integer that corresponds to the type of grid used in the simulation //! (collocated, staggered, hybrid) - static short grid_type; + static inline auto grid_type = ablastr::utils::enums::GridType::Default; // Global rho nodal flag to know about rho index type when rho MultiFab is not allocated amrex::IntVect m_rho_nodal_flag; @@ -533,6 +552,20 @@ public: [[nodiscard]] const amrex::Vector,3>>& getMultiLevelField(warpx::fields::FieldType field_type) const; + /** + * \brief + * Get pointer to the amrex::MultiFab containing the dotMask for the specified field + */ + [[nodiscard]] const amrex::iMultiFab* + getFieldDotMaskPointer (warpx::fields::FieldType field_type, int lev, int dir) const; + + /** + * \brief + * Set the dotMask container + */ + void SetDotMask( std::unique_ptr& field_dotMask, + warpx::fields::FieldType field_type, int lev, int dir ) const; + [[nodiscard]] bool DoPML () const {return do_pml;} [[nodiscard]] bool DoFluidSpecies () const {return do_fluid_species;} @@ -665,7 +698,7 @@ public: */ void Hybrid_QED_Push (int lev, PatchType patch_type, amrex::Real dt); - static amrex::Real quantum_xi_c2; + amrex::Real m_quantum_xi_c2; /** Check and potentially compute load balancing */ @@ -922,14 +955,8 @@ public: static const amrex::iMultiFab* CurrentBufferMasks (int lev); static const amrex::iMultiFab* GatherBufferMasks (int lev); - static int electrostatic_solver_id; - static int poisson_solver_id; - - // Parameters for lab frame electrostatic - static amrex::Real self_fields_required_precision; - static amrex::Real self_fields_absolute_tolerance; - static int self_fields_max_iters; - static int self_fields_verbosity; + static inline auto electrostatic_solver_id = ElectrostaticSolverAlgo::Default; + static inline auto poisson_solver_id = PoissonSolverAlgo::Default; static int do_moving_window; // boolean static int start_moving_window_step; // the first step to move window @@ -959,6 +986,8 @@ public: void ComputeDivE(amrex::MultiFab& divE, int lev); + static void ProjectionCleanDivB (); + [[nodiscard]] amrex::IntVect getngEB() const { return guard_cells.ng_alloc_EB; } [[nodiscard]] amrex::IntVect getngF() const { return guard_cells.ng_alloc_F; } [[nodiscard]] amrex::IntVect getngUpdateAux() const { return guard_cells.ng_UpdateAux; } @@ -975,30 +1004,8 @@ public: */ [[nodiscard]] amrex::IntVect get_numprocs() const {return numprocs;} - bool m_boundary_potential_specified = false; - ElectrostaticSolver::PoissonBoundaryHandler m_poisson_boundary_handler; + /** Electrostatic solve call */ void ComputeSpaceChargeField (bool reset_fields); - void AddBoundaryField (); - void AddSpaceChargeField (WarpXParticleContainer& pc); - void AddSpaceChargeFieldLabFrame (); - void computePhi (const amrex::Vector >& rho, - amrex::Vector >& phi, - std::array beta = {{0,0,0}}, - amrex::Real required_precision=amrex::Real(1.e-11), - amrex::Real absolute_tolerance=amrex::Real(0.0), - int max_iters=200, - int verbosity=2) const; - - void setPhiBC (amrex::Vector >& phi ) const; - - void computeE (amrex::Vector, 3> >& E, - const amrex::Vector >& phi, - std::array beta = {{0,0,0}} ) const; - void computeB (amrex::Vector, 3> >& B, - const amrex::Vector >& phi, - std::array beta = {{0,0,0}} ) const; - void computePhiTriDiagonal (const amrex::Vector >& rho, - amrex::Vector >& phi) const; // Magnetostatic Solver Interface MagnetostaticSolver::VectorPoissonBoundaryHandler m_vector_poisson_boundary_handler; @@ -1041,14 +1048,14 @@ public: amrex::ParserExecutor<3> const& zfield_parser, std::array< std::unique_ptr, 3 > const& edge_lengths, std::array< std::unique_ptr, 3 > const& face_areas, - char field, + [[maybe_unused]] char field, int lev, PatchType patch_type); /** * \brief Load field values from a user-specified openPMD file, * for the fields Ex, Ey, Ez, Bx, By, Bz */ - void LoadExternalFieldsFromFile (int lev); + void LoadExternalFields (int lev); /** * \brief Load field values from a user-specified openPMD file @@ -1085,7 +1092,7 @@ public: * \param[in] n_order order of the finite-difference approximation * \param[in] a_grid_type type of grid (collocated or not) */ - static amrex::Vector getFornbergStencilCoefficients(int n_order, short a_grid_type); + static amrex::Vector getFornbergStencilCoefficients (int n_order, ablastr::utils::enums::GridType a_grid_type); // Device vectors of stencil coefficients used for finite-order centering of fields amrex::Gpu::DeviceVector device_field_centering_stencil_coeffs_x; @@ -1108,7 +1115,7 @@ public: void BuildBufferMasksInBox ( amrex::Box tbx, amrex::IArrayBox &buffer_mask, const amrex::IArrayBox &guard_mask, int ng ); #ifdef AMREX_USE_EB - amrex::EBFArrayBoxFactory const& fieldEBFactory (int lev) const noexcept { + [[nodiscard]] amrex::EBFArrayBoxFactory const& fieldEBFactory (int lev) const noexcept { return static_cast(*m_field_factory[lev]); } #endif @@ -1240,6 +1247,10 @@ protected: //! This function is called in amrex::AmrCore::InitFromScratch. void PostProcessBaseGrids (amrex::BoxArray& ba0) const final; + //! Use this function to override how DistributionMapping is made. + [[nodiscard]] amrex::DistributionMapping + MakeDistributionMap (int lev, amrex::BoxArray const& ba) final; + //! Make a new level from scratch using provided BoxArray and //! DistributionMapping. Only used during initialization. Called //! by AmrCoreInitFromScratch. @@ -1291,7 +1302,7 @@ private: void FillBoundaryB_avg (int lev, PatchType patch_type, amrex::IntVect ng); void FillBoundaryE_avg (int lev, PatchType patch_type, amrex::IntVect ng); - void AddExternalFields (); + void AddExternalFields (int lev); void OneStep_nosub (amrex::Real cur_time); void OneStep_sub1 (amrex::Real cur_time); @@ -1397,9 +1408,6 @@ private: */ void CheckKnownIssues(); - /** Check the requested resources and write performance hints */ - void PerformanceHints (); - void BuildBufferMasks (); [[nodiscard]] const amrex::iMultiFab* getCurrentBufferMasks (int lev) const { @@ -1441,7 +1449,7 @@ private: int centering_nox, int centering_noy, int centering_noz, - short a_grid_type); + ablastr::utils::enums::GridType a_grid_type); void AllocLevelMFs (int lev, const amrex::BoxArray& ba, const amrex::DistributionMapping& dm, const amrex::IntVect& ngEB, amrex::IntVect& ngJ, @@ -1503,6 +1511,13 @@ private: amrex::Vector, 3 > > Efield_avg_fp; amrex::Vector, 3 > > Bfield_avg_fp; + // Masks for computing dot product and global moments of fields when using grids that + // have shared locations across different ranks (e.g., a Yee grid) + mutable amrex::Vector,3 > > Efield_dotMask; + mutable amrex::Vector,3 > > Bfield_dotMask; + mutable amrex::Vector,3 > > Afield_dotMask; + mutable amrex::Vector< std::unique_ptr > phi_dotMask; + // Memory buffers for computing magnetostatic fields // Vector Potential A and previous step. Time buffer needed for computing dA/dt to first order amrex::Vector, 3 > > vector_potential_fp_nodal; @@ -1633,6 +1648,9 @@ private: // Macroscopic properties std::unique_ptr m_macroscopic_properties; + // Electrostatic solver + std::unique_ptr m_electrostatic_solver; + // Hybrid PIC algorithm parameters std::unique_ptr m_hybrid_pic_model; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index b725431c2f1..ef1668de4c0 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -14,7 +14,11 @@ #include "BoundaryConditions/PML.H" #include "Diagnostics/MultiDiagnostics.H" #include "Diagnostics/ReducedDiags/MultiReducedDiags.H" +#include "EmbeddedBoundary/Enabled.H" #include "EmbeddedBoundary/WarpXFaceInfoBox.H" +#include "FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H" +#include "FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.H" +#include "FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.H" #include "FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H" #include "FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H" #include "FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H" @@ -83,6 +87,7 @@ #include #include #include +#include #include #include @@ -100,7 +105,6 @@ bool WarpX::fft_do_time_averaging = false; amrex::IntVect WarpX::m_fill_guards_fields = amrex::IntVect(0); amrex::IntVect WarpX::m_fill_guards_current = amrex::IntVect(0); -Real WarpX::quantum_xi_c2 = PhysConst::xi_c2; Real WarpX::gamma_boost = 1._rt; Real WarpX::beta_boost = 0._rt; Vector WarpX::boost_direction = {0,0,0}; @@ -109,22 +113,11 @@ bool WarpX::compute_max_step_from_btd = false; Real WarpX::zmax_plasma_to_compute_max_step = 0._rt; Real WarpX::zmin_domain_boost_step_0 = 0._rt; -short WarpX::current_deposition_algo; -short WarpX::charge_deposition_algo; -short WarpX::field_gathering_algo; -short WarpX::particle_pusher_algo; -short WarpX::electromagnetic_solver_id; -short WarpX::evolve_scheme; int WarpX::max_particle_its_in_implicit_scheme = 21; ParticleReal WarpX::particle_tol_in_implicit_scheme = 1.e-10; -short WarpX::psatd_solution_type; -short WarpX::J_in_time; -short WarpX::rho_in_time; -short WarpX::load_balance_costs_update_algo; bool WarpX::do_dive_cleaning = false; bool WarpX::do_divb_cleaning = false; -int WarpX::em_solver_medium; -int WarpX::macroscopic_solver_algo; +bool WarpX::do_divb_cleaning_external = false; bool WarpX::do_single_precision_comms = false; bool WarpX::do_shared_mem_charge_deposition = false; @@ -139,11 +132,6 @@ amrex::IntVect WarpX::shared_tilesize(AMREX_D_DECL(1,1,1)); #endif int WarpX::shared_mem_current_tpb = 128; -amrex::Vector WarpX::field_boundary_lo(AMREX_SPACEDIM,FieldBoundaryType::PML); -amrex::Vector WarpX::field_boundary_hi(AMREX_SPACEDIM,FieldBoundaryType::PML); -amrex::Vector WarpX::particle_boundary_lo(AMREX_SPACEDIM,ParticleBoundaryType::Absorbing); -amrex::Vector WarpX::particle_boundary_hi(AMREX_SPACEDIM,ParticleBoundaryType::Absorbing); - int WarpX::n_rz_azimuthal_modes = 1; int WarpX::ncomps = 1; @@ -189,13 +177,6 @@ amrex::IntVect WarpX::sort_idx_type(AMREX_D_DECL(0,0,0)); bool WarpX::do_dynamic_scheduling = true; -int WarpX::electrostatic_solver_id; -int WarpX::poisson_solver_id; -Real WarpX::self_fields_required_precision = 1.e-11_rt; -Real WarpX::self_fields_absolute_tolerance = 0.0_rt; -int WarpX::self_fields_max_iters = 200; -int WarpX::self_fields_verbosity = 2; - bool WarpX::do_subcycling = false; bool WarpX::do_multi_J = false; int WarpX::do_multi_J_n_depositions; @@ -209,7 +190,6 @@ IntVect WarpX::filter_npass_each_dir(1); int WarpX::n_field_gather_buffer = -1; int WarpX::n_current_deposition_buffer = -1; -short WarpX::grid_type; amrex::IntVect m_rho_nodal_flag; WarpX* WarpX::m_instance = nullptr; @@ -258,7 +238,7 @@ WarpX::WarpX () BackwardCompatibility(); - InitEB(); + if (EB::enabled()) { InitEB(); } ablastr::utils::SignalHandling::InitSignalHandling(); @@ -285,7 +265,7 @@ WarpX::WarpX () // Loop over species (particles and lasers) // and set current injection position per species - if (do_moving_window){ + if (do_moving_window){ const int n_containers = mypc->nContainers(); for (int i=0; i(nlevs_max); + } + else + { + m_electrostatic_solver = std::make_unique(nlevs_max); + } + if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC) { // Create hybrid-PIC model object if needed @@ -533,11 +529,14 @@ WarpX::ReadParameters () { const ParmParse pp_algo("algo"); - electromagnetic_solver_id = static_cast(GetAlgorithmInteger(pp_algo, "maxwell_solver")); + pp_algo.query_enum_sloppy("maxwell_solver", electromagnetic_solver_id, "-_"); + if (electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT && !EB::enabled()) { + throw std::runtime_error("ECP Solver requires to enable embedded boundaries at runtime."); + } } { - const ParmParse pp_warpx("warpx"); + ParmParse const pp_warpx("warpx"); //"Synthetic" warning messages may be injected in the Warning Manager via // inputfile for debug&testing purposes. @@ -737,27 +736,13 @@ WarpX::ReadParameters () maxlevel_extEMfield_init = maxLevel(); pp_warpx.query("maxlevel_extEMfield_init", maxlevel_extEMfield_init); - electrostatic_solver_id = GetAlgorithmInteger(pp_warpx, "do_electrostatic"); + pp_warpx.query_enum_sloppy("do_electrostatic", electrostatic_solver_id, "-_"); // if an electrostatic solver is used, set the Maxwell solver to None if (electrostatic_solver_id != ElectrostaticSolverAlgo::None) { electromagnetic_solver_id = ElectromagneticSolverAlgo::None; } - if (electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame || - electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic) - { - // Note that with the relativistic version, these parameters would be - // input for each species. - utils::parser::queryWithParser( - pp_warpx, "self_fields_required_precision", self_fields_required_precision); - utils::parser::queryWithParser( - pp_warpx, "self_fields_absolute_tolerance", self_fields_absolute_tolerance); - utils::parser::queryWithParser( - pp_warpx, "self_fields_max_iters", self_fields_max_iters); - pp_warpx.query("self_fields_verbosity", self_fields_verbosity); - } - - poisson_solver_id = GetAlgorithmInteger(pp_warpx, "poisson_solver"); + pp_warpx.query_enum_sloppy("poisson_solver", poisson_solver_id, "-_"); #ifndef WARPX_DIM_3D WARPX_ALWAYS_ASSERT_WITH_MESSAGE( poisson_solver_id!=PoissonSolverAlgo::IntegratedGreenFunction, @@ -777,38 +762,16 @@ WarpX::ReadParameters () "The FFT Poisson solver is not implemented in labframe-electromagnetostatic mode yet." ); - // Parse the input file for domain boundary potentials - const ParmParse pp_boundary("boundary"); - bool potential_specified = false; - // When reading the potential at the boundary from the input file, set this flag to true if any of the potential is specified - potential_specified |= pp_boundary.query("potential_lo_x", m_poisson_boundary_handler.potential_xlo_str); - potential_specified |= pp_boundary.query("potential_hi_x", m_poisson_boundary_handler.potential_xhi_str); - potential_specified |= pp_boundary.query("potential_lo_y", m_poisson_boundary_handler.potential_ylo_str); - potential_specified |= pp_boundary.query("potential_hi_y", m_poisson_boundary_handler.potential_yhi_str); - potential_specified |= pp_boundary.query("potential_lo_z", m_poisson_boundary_handler.potential_zlo_str); - potential_specified |= pp_boundary.query("potential_hi_z", m_poisson_boundary_handler.potential_zhi_str); -#if defined(AMREX_USE_EB) - potential_specified |= pp_warpx.query("eb_potential(x,y,z,t)", m_poisson_boundary_handler.potential_eb_str); + [[maybe_unused]] bool const eb_enabled = EB::enabled(); +#if !defined(AMREX_USE_EB) + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + !eb_enabled, + "Embedded boundaries are requested via warpx.eb_enabled but were not compiled!" + ); #endif - m_boundary_potential_specified = potential_specified; - if (potential_specified & (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC)) { - ablastr::warn_manager::WMRecordWarning( - "Algorithms", - "The input script specifies the electric potential (phi) at the boundary, but \ - also uses the hybrid PIC solver based on Ohm’s law. When using this solver, the \ - electric potential does not have any impact on the simulation.", - ablastr::warn_manager::WarnPriority::low); - } - else if (potential_specified & (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::None)) { - ablastr::warn_manager::WMRecordWarning( - "Algorithms", - "The input script specifies the electric potential (phi) at the boundary so \ - an initial Poisson solve will be performed.", - ablastr::warn_manager::WarnPriority::low); - } - m_poisson_boundary_handler.buildParsers(); #ifdef WARPX_DIM_RZ + const ParmParse pp_boundary("boundary"); pp_boundary.query("verboncoeur_axis_correction", verboncoeur_axis_correction); #endif @@ -898,17 +861,21 @@ WarpX::ReadParameters () pp_warpx.query("refine_plasma", refine_plasma); pp_warpx.query("do_dive_cleaning", do_dive_cleaning); pp_warpx.query("do_divb_cleaning", do_divb_cleaning); + utils::parser::queryWithParser( pp_warpx, "n_field_gather_buffer", n_field_gather_buffer); utils::parser::queryWithParser( pp_warpx, "n_current_deposition_buffer", n_current_deposition_buffer); + //Default value for the quantum parameter used in Maxwell’s QED equations + m_quantum_xi_c2 = PhysConst::xi_c2; + amrex::Real quantum_xi_tmp; const auto quantum_xi_is_specified = utils::parser::queryWithParser(pp_warpx, "quantum_xi", quantum_xi_tmp); if (quantum_xi_is_specified) { double const quantum_xi = quantum_xi_tmp; - quantum_xi_c2 = static_cast(quantum_xi * PhysConst::c * PhysConst::c); + m_quantum_xi_c2 = static_cast(quantum_xi * PhysConst::c * PhysConst::c); } const auto at_least_one_boundary_is_pml = @@ -1066,7 +1033,7 @@ WarpX::ReadParameters () // Integer that corresponds to the type of grid used in the simulation // (collocated, staggered, hybrid) - grid_type = static_cast(GetAlgorithmInteger(pp_warpx, "grid_type")); + pp_warpx.query_enum_sloppy("grid_type", grid_type, "-_"); // Use same shape factors in all directions, for gathering if (grid_type == GridType::Collocated) { galerkin_interpolation = false; } @@ -1118,6 +1085,22 @@ WarpX::ReadParameters () "warpx.grid_type=hybrid is not implemented in RZ geometry"); #endif + // Update default to external projection divb cleaner if external fields are loaded, + // the grids are staggered, and the solver is compatible with the cleaner + if (!do_divb_cleaning + && m_p_ext_field_params->B_ext_grid_type != ExternalFieldType::default_zero + && m_p_ext_field_params->B_ext_grid_type != ExternalFieldType::constant + && grid_type != GridType::Collocated + && (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::Yee + || WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC + || ( (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame + || WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic) + && WarpX::poisson_solver_id == PoissonSolverAlgo::Multigrid))) + { + do_divb_cleaning_external = true; + } + pp_warpx.query("do_divb_cleaning_external", do_divb_cleaning_external); + // If true, the current is deposited on a nodal grid and centered onto // a staggered grid. Setting warpx.do_current_centering=1 makes sense // only if warpx.grid_type=hybrid. Instead, if warpx.grid_type=nodal or @@ -1193,10 +1176,15 @@ WarpX::ReadParameters () // note: current_deposition must be set after maxwell_solver (electromagnetic_solver_id) or // do_electrostatic (electrostatic_solver_id) are already determined, // because its default depends on the solver selection - current_deposition_algo = static_cast(GetAlgorithmInteger(pp_algo, "current_deposition")); - charge_deposition_algo = static_cast(GetAlgorithmInteger(pp_algo, "charge_deposition")); - particle_pusher_algo = static_cast(GetAlgorithmInteger(pp_algo, "particle_pusher")); - evolve_scheme = static_cast(GetAlgorithmInteger(pp_algo, "evolve_scheme")); + if (electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD || + electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC || + electrostatic_solver_id != ElectrostaticSolverAlgo::None) { + current_deposition_algo = CurrentDepositionAlgo::Direct; + } + pp_algo.query_enum_sloppy("current_deposition", current_deposition_algo, "-_"); + pp_algo.query_enum_sloppy("charge_deposition", charge_deposition_algo, "-_"); + pp_algo.query_enum_sloppy("particle_pusher", particle_pusher_algo, "-_"); + pp_algo.query_enum_sloppy("evolve_scheme", evolve_scheme, "-_"); // check for implicit evolve scheme if (evolve_scheme == EvolveScheme::SemiImplicitEM) { @@ -1257,7 +1245,7 @@ WarpX::ReadParameters () // Query algo.field_gathering from input, set field_gathering_algo to // "default" if not found (default defined in Utils/WarpXAlgorithmSelection.cpp) - field_gathering_algo = static_cast(GetAlgorithmInteger(pp_algo, "field_gathering")); + pp_algo.query_enum_sloppy("field_gathering", field_gathering_algo, "-_"); // Set default field gathering algorithm for hybrid grids (momentum-conserving) std::string tmp_algo; @@ -1314,9 +1302,10 @@ WarpX::ReadParameters () " combined with mesh refinement is currently not implemented"); } - em_solver_medium = GetAlgorithmInteger(pp_algo, "em_solver_medium"); + pp_algo.query_enum_sloppy("em_solver_medium", em_solver_medium, "-_"); if (em_solver_medium == MediumForEM::Macroscopic ) { - macroscopic_solver_algo = GetAlgorithmInteger(pp_algo,"macroscopic_sigma_method"); + pp_algo.query_enum_sloppy("macroscopic_sigma_method", + macroscopic_solver_algo, "-_"); } if (evolve_scheme == EvolveScheme::SemiImplicitEM || @@ -1355,7 +1344,7 @@ WarpX::ReadParameters () } utils::parser::queryWithParser(pp_algo, "load_balance_efficiency_ratio_threshold", load_balance_efficiency_ratio_threshold); - load_balance_costs_update_algo = static_cast(GetAlgorithmInteger(pp_algo, "load_balance_costs_update")); + pp_algo.query_enum_sloppy("load_balance_costs_update", load_balance_costs_update_algo, "-_"); if (WarpX::load_balance_costs_update_algo==LoadBalanceCostsUpdateAlgo::Heuristic) { utils::parser::queryWithParser( pp_algo, "costs_heuristic_cells_wt", costs_heuristic_cells_wt); @@ -1526,12 +1515,12 @@ WarpX::ReadParameters () // Integer that corresponds to the order of the PSATD solution // (whether the PSATD equations are derived from first-order or // second-order solution) - psatd_solution_type = static_cast(GetAlgorithmInteger(pp_psatd, "solution_type")); + pp_psatd.query_enum_sloppy("solution_type", psatd_solution_type, "-_"); // Integers that correspond to the time dependency of J (constant, linear) // and rho (linear, quadratic) for the PSATD algorithm - J_in_time = static_cast(GetAlgorithmInteger(pp_psatd, "J_in_time")); - rho_in_time = static_cast(GetAlgorithmInteger(pp_psatd, "rho_in_time")); + pp_psatd.query_enum_sloppy("J_in_time", J_in_time, "-_"); + pp_psatd.query_enum_sloppy("rho_in_time", rho_in_time, "-_"); if (psatd_solution_type != PSATDSolutionType::FirstOrder || !do_multi_J) { @@ -1544,7 +1533,6 @@ WarpX::ReadParameters () // Current correction activated by default, unless a charge-conserving // current deposition (Esirkepov, Vay) or the div(E) cleaning scheme // are used - current_correction = true; if (WarpX::current_deposition_algo == CurrentDepositionAlgo::Esirkepov || WarpX::current_deposition_algo == CurrentDepositionAlgo::Villasenor || WarpX::current_deposition_algo == CurrentDepositionAlgo::Vay || @@ -2068,6 +2056,10 @@ WarpX::ClearLevel (int lev) Efield_fp [lev][i].reset(); Bfield_fp [lev][i].reset(); + Efield_dotMask [lev][i].reset(); + Bfield_dotMask [lev][i].reset(); + Afield_dotMask [lev][i].reset(); + current_store[lev][i].reset(); if (do_current_centering) @@ -2114,6 +2106,8 @@ WarpX::ClearLevel (int lev) G_cp [lev].reset(); rho_cp[lev].reset(); + phi_dotMask[lev].reset(); + #ifdef WARPX_USE_FFT if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) { spectral_solver_fp[lev].reset(); @@ -2164,15 +2158,18 @@ WarpX::AllocLevelData (int lev, const BoxArray& ba, const DistributionMapping& d use_filter, bilinear_filter.stencil_length_each_dir); - #ifdef AMREX_USE_EB - int max_guard = guard_cells.ng_FieldSolver.max(); + bool const eb_enabled = EB::enabled(); + if (eb_enabled) { + int const max_guard = guard_cells.ng_FieldSolver.max(); m_field_factory[lev] = amrex::makeEBFabFactory(Geom(lev), ba, dm, {max_guard, max_guard, max_guard}, amrex::EBSupport::full); -#else - m_field_factory[lev] = std::make_unique(); + } else #endif + { + m_field_factory[lev] = std::make_unique(); + } if (mypc->nSpeciesDepositOnMainGrid() && n_current_deposition_buffer == 0) { @@ -2391,51 +2388,81 @@ WarpX::AllocLevelMFs (int lev, const BoxArray& ba, const DistributionMapping& dm AllocInitMultiFab(Efield_avg_fp[lev][2], amrex::convert(ba, Ez_nodal_flag), dm, ncomps, ngEB, lev, "Efield_avg_fp[z]", 0.0_rt); } -#ifdef AMREX_USE_EB - constexpr int nc_ls = 1; - amrex::IntVect ng_ls(2); - AllocInitMultiFab(m_distance_to_eb[lev], amrex::convert(ba, IntVect::TheNodeVector()), dm, nc_ls, ng_ls, lev, "m_distance_to_eb"); - - // EB info are needed only at the finest level - if (lev == maxLevel()) - { - if (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::PSATD) { - AllocInitMultiFab(m_edge_lengths[lev][0], amrex::convert(ba, Ex_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_edge_lengths[x]"); - AllocInitMultiFab(m_edge_lengths[lev][1], amrex::convert(ba, Ey_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_edge_lengths[y]"); - AllocInitMultiFab(m_edge_lengths[lev][2], amrex::convert(ba, Ez_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_edge_lengths[z]"); - AllocInitMultiFab(m_face_areas[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_face_areas[x]"); - AllocInitMultiFab(m_face_areas[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_face_areas[y]"); - AllocInitMultiFab(m_face_areas[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_face_areas[z]"); - } - if(WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { - AllocInitMultiFab(m_edge_lengths[lev][0], amrex::convert(ba, Ex_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_edge_lengths[x]"); - AllocInitMultiFab(m_edge_lengths[lev][1], amrex::convert(ba, Ey_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_edge_lengths[y]"); - AllocInitMultiFab(m_edge_lengths[lev][2], amrex::convert(ba, Ez_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_edge_lengths[z]"); - AllocInitMultiFab(m_face_areas[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_face_areas[x]"); - AllocInitMultiFab(m_face_areas[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_face_areas[y]"); - AllocInitMultiFab(m_face_areas[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_face_areas[z]"); - AllocInitMultiFab(m_flag_info_face[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_flag_info_face[x]"); - AllocInitMultiFab(m_flag_info_face[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_flag_info_face[y]"); - AllocInitMultiFab(m_flag_info_face[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_flag_info_face[z]"); - AllocInitMultiFab(m_flag_ext_face[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_flag_ext_face[x]"); - AllocInitMultiFab(m_flag_ext_face[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_flag_ext_face[y]"); - AllocInitMultiFab(m_flag_ext_face[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_flag_ext_face[z]"); - AllocInitMultiFab(m_area_mod[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_area_mod[x]"); - AllocInitMultiFab(m_area_mod[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_area_mod[y]"); - AllocInitMultiFab(m_area_mod[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "m_area_mod[z]"); - m_borrowing[lev][0] = std::make_unique>(amrex::convert(ba, Bx_nodal_flag), dm); - m_borrowing[lev][1] = std::make_unique>(amrex::convert(ba, By_nodal_flag), dm); - m_borrowing[lev][2] = std::make_unique>(amrex::convert(ba, Bz_nodal_flag), dm); - AllocInitMultiFab(Venl[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "Venl[x]"); - AllocInitMultiFab(Venl[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "Venl[y]"); - AllocInitMultiFab(Venl[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "Venl[z]"); - - AllocInitMultiFab(ECTRhofield[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "ECTRhofield[x]", 0.0_rt); - AllocInitMultiFab(ECTRhofield[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "ECTRhofield[y]", 0.0_rt); - AllocInitMultiFab(ECTRhofield[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, guard_cells.ng_FieldSolver, lev, "ECTRhofield[z]", 0.0_rt); + if (EB::enabled()) { + constexpr int nc_ls = 1; + amrex::IntVect const ng_ls(2); + AllocInitMultiFab(m_distance_to_eb[lev], amrex::convert(ba, IntVect::TheNodeVector()), dm, nc_ls, ng_ls, lev, + "m_distance_to_eb"); + + // EB info are needed only at the finest level + if (lev == maxLevel()) { + if (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::PSATD) { + AllocInitMultiFab(m_edge_lengths[lev][0], amrex::convert(ba, Ex_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_edge_lengths[x]"); + AllocInitMultiFab(m_edge_lengths[lev][1], amrex::convert(ba, Ey_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_edge_lengths[y]"); + AllocInitMultiFab(m_edge_lengths[lev][2], amrex::convert(ba, Ez_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_edge_lengths[z]"); + AllocInitMultiFab(m_face_areas[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_face_areas[x]"); + AllocInitMultiFab(m_face_areas[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_face_areas[y]"); + AllocInitMultiFab(m_face_areas[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_face_areas[z]"); + } + if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT) { + AllocInitMultiFab(m_edge_lengths[lev][0], amrex::convert(ba, Ex_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_edge_lengths[x]"); + AllocInitMultiFab(m_edge_lengths[lev][1], amrex::convert(ba, Ey_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_edge_lengths[y]"); + AllocInitMultiFab(m_edge_lengths[lev][2], amrex::convert(ba, Ez_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_edge_lengths[z]"); + AllocInitMultiFab(m_face_areas[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_face_areas[x]"); + AllocInitMultiFab(m_face_areas[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_face_areas[y]"); + AllocInitMultiFab(m_face_areas[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_face_areas[z]"); + AllocInitMultiFab(m_flag_info_face[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_flag_info_face[x]"); + AllocInitMultiFab(m_flag_info_face[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_flag_info_face[y]"); + AllocInitMultiFab(m_flag_info_face[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_flag_info_face[z]"); + AllocInitMultiFab(m_flag_ext_face[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_flag_ext_face[x]"); + AllocInitMultiFab(m_flag_ext_face[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_flag_ext_face[y]"); + AllocInitMultiFab(m_flag_ext_face[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_flag_ext_face[z]"); + AllocInitMultiFab(m_area_mod[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_area_mod[x]"); + AllocInitMultiFab(m_area_mod[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_area_mod[y]"); + AllocInitMultiFab(m_area_mod[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "m_area_mod[z]"); + m_borrowing[lev][0] = std::make_unique>( + amrex::convert(ba, Bx_nodal_flag), dm); + m_borrowing[lev][1] = std::make_unique>( + amrex::convert(ba, By_nodal_flag), dm); + m_borrowing[lev][2] = std::make_unique>( + amrex::convert(ba, Bz_nodal_flag), dm); + AllocInitMultiFab(Venl[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "Venl[x]"); + AllocInitMultiFab(Venl[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "Venl[y]"); + AllocInitMultiFab(Venl[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "Venl[z]"); + + AllocInitMultiFab(ECTRhofield[lev][0], amrex::convert(ba, Bx_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "ECTRhofield[x]", 0.0_rt); + AllocInitMultiFab(ECTRhofield[lev][1], amrex::convert(ba, By_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "ECTRhofield[y]", 0.0_rt); + AllocInitMultiFab(ECTRhofield[lev][2], amrex::convert(ba, Bz_nodal_flag), dm, ncomps, + guard_cells.ng_FieldSolver, lev, "ECTRhofield[z]", 0.0_rt); + } } } -#endif int rho_ncomps = 0; if( (electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame) || @@ -2596,7 +2623,7 @@ WarpX::AllocLevelMFs (int lev, const BoxArray& ba, const DistributionMapping& dm } // The external fields that are read from file - if (m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::read_from_file) { + if (m_p_ext_field_params->B_ext_grid_type != ExternalFieldType::default_zero && m_p_ext_field_params->B_ext_grid_type != ExternalFieldType::constant) { // These fields will be added directly to the grid, i.e. to fp, and need to match the index type AllocInitMultiFab(Bfield_fp_external[lev][0], amrex::convert(ba, Bfield_fp[lev][0]->ixType()), dm, ncomps, ngEB, lev, "Bfield_fp_external[x]", 0.0_rt); @@ -2614,7 +2641,7 @@ WarpX::AllocLevelMFs (int lev, const BoxArray& ba, const DistributionMapping& dm AllocInitMultiFab(B_external_particle_field[lev][2], amrex::convert(ba, Bfield_aux[lev][2]->ixType()), dm, ncomps, ngEB, lev, "B_external_particle_field[z]", 0.0_rt); } - if (m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::read_from_file) { + if (m_p_ext_field_params->E_ext_grid_type != ExternalFieldType::default_zero && m_p_ext_field_params->E_ext_grid_type != ExternalFieldType::constant) { // These fields will be added directly to the grid, i.e. to fp, and need to match the index type AllocInitMultiFab(Efield_fp_external[lev][0], amrex::convert(ba, Efield_fp[lev][0]->ixType()), dm, ncomps, ngEB, lev, "Efield_fp_external[x]", 0.0_rt); @@ -2977,36 +3004,7 @@ WarpX::ComputeDivB (amrex::MultiFab& divB, int const dcomp, const std::array& B, const std::array& dx) { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(grid_type != GridType::Collocated, - "ComputeDivB not implemented with warpx.grid_type=Collocated."); - - const Real dxinv = 1._rt/dx[0], dyinv = 1._rt/dx[1], dzinv = 1._rt/dx[2]; - -#ifdef WARPX_DIM_RZ - const Real rmin = GetInstance().Geom(0).ProbLo(0); -#endif - -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(divB, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& bx = mfi.tilebox(); - amrex::Array4 const& Bxfab = B[0]->array(mfi); - amrex::Array4 const& Byfab = B[1]->array(mfi); - amrex::Array4 const& Bzfab = B[2]->array(mfi); - amrex::Array4 const& divBfab = divB.array(mfi); - - ParallelFor(bx, - [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept - { - warpx_computedivb(i, j, k, dcomp, divBfab, Bxfab, Byfab, Bzfab, dxinv, dyinv, dzinv -#ifdef WARPX_DIM_RZ - ,rmin -#endif - ); - }); - } + ComputeDivB(divB, dcomp, B, dx, IntVect::TheZeroVector()); } void @@ -3203,7 +3201,7 @@ WarpX::BuildBufferMasksInBox ( const amrex::Box tbx, amrex::IArrayBox &buffer_ma }); } -amrex::Vector WarpX::getFornbergStencilCoefficients(const int n_order, const short a_grid_type) +amrex::Vector WarpX::getFornbergStencilCoefficients (const int n_order, ablastr::utils::enums::GridType a_grid_type) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE(n_order % 2 == 0, "n_order must be even"); @@ -3265,7 +3263,7 @@ void WarpX::AllocateCenteringCoefficients (amrex::Gpu::DeviceVector const int centering_nox, const int centering_noy, const int centering_noz, - const short a_grid_type) + ablastr::utils::enums::GridType a_grid_type) { // Vectors of Fornberg stencil coefficients amrex::Vector Fornberg_stencil_coeffs_x; @@ -3466,70 +3464,76 @@ WarpX::getFieldPointerUnchecked (const FieldType field_type, const int lev, cons case FieldType::Efield_aux : field_pointer = Efield_aux[lev][direction].get(); break; - case FieldType::Bfield_aux : + case FieldType::Bfield_aux : field_pointer = Bfield_aux[lev][direction].get(); break; - case FieldType::Efield_fp : + case FieldType::Efield_fp : field_pointer = Efield_fp[lev][direction].get(); break; - case FieldType::Bfield_fp : + case FieldType::Bfield_fp : field_pointer = Bfield_fp[lev][direction].get(); break; - case FieldType::current_fp : + case FieldType::Efield_fp_external : + field_pointer = Efield_fp_external[lev][direction].get(); + break; + case FieldType::Bfield_fp_external : + field_pointer = Bfield_fp_external[lev][direction].get(); + break; + case FieldType::current_fp : field_pointer = current_fp[lev][direction].get(); break; - case FieldType::current_fp_nodal : + case FieldType::current_fp_nodal : field_pointer = current_fp_nodal[lev][direction].get(); break; - case FieldType::rho_fp : + case FieldType::rho_fp : field_pointer = rho_fp[lev].get(); break; - case FieldType::F_fp : + case FieldType::F_fp : field_pointer = F_fp[lev].get(); break; - case FieldType::G_fp : + case FieldType::G_fp : field_pointer = G_fp[lev].get(); break; - case FieldType::phi_fp : + case FieldType::phi_fp : field_pointer = phi_fp[lev].get(); break; - case FieldType::vector_potential_fp : + case FieldType::vector_potential_fp : field_pointer = vector_potential_fp_nodal[lev][direction].get(); break; - case FieldType::Efield_cp : + case FieldType::Efield_cp : field_pointer = Efield_cp[lev][direction].get(); break; - case FieldType::Bfield_cp : + case FieldType::Bfield_cp : field_pointer = Bfield_cp[lev][direction].get(); break; - case FieldType::current_cp : + case FieldType::current_cp : field_pointer = current_cp[lev][direction].get(); break; - case FieldType::rho_cp : + case FieldType::rho_cp : field_pointer = rho_cp[lev].get(); break; - case FieldType::F_cp : + case FieldType::F_cp : field_pointer = F_cp[lev].get(); break; - case FieldType::G_cp : + case FieldType::G_cp : field_pointer = G_cp[lev].get(); break; - case FieldType::edge_lengths : + case FieldType::edge_lengths : field_pointer = m_edge_lengths[lev][direction].get(); break; - case FieldType::face_areas : + case FieldType::face_areas : field_pointer = m_face_areas[lev][direction].get(); break; - case FieldType::Efield_avg_fp : + case FieldType::Efield_avg_fp : field_pointer = Efield_avg_fp[lev][direction].get(); break; - case FieldType::Bfield_avg_fp : + case FieldType::Bfield_avg_fp : field_pointer = Bfield_avg_fp[lev][direction].get(); break; - case FieldType::Efield_avg_cp : + case FieldType::Efield_avg_cp : field_pointer = Efield_avg_cp[lev][direction].get(); break; - case FieldType::Bfield_avg_cp : + case FieldType::Bfield_avg_cp : field_pointer = Bfield_avg_cp[lev][direction].get(); break; default: @@ -3562,6 +3566,7 @@ WarpX::getFieldPointerArray (const FieldType field_type, const int lev) const WARPX_ALWAYS_ASSERT_WITH_MESSAGE( (field_type == FieldType::Efield_aux) || (field_type == FieldType::Bfield_aux) || (field_type == FieldType::Efield_fp) || (field_type == FieldType::Bfield_fp) || + (field_type == FieldType::Efield_fp_external) || (field_type == FieldType::Bfield_fp_external) || (field_type == FieldType::current_fp) || (field_type == FieldType::current_fp_nodal) || (field_type == FieldType::Efield_cp) || (field_type == FieldType::Bfield_cp) || (field_type == FieldType::current_cp), "Requested field type is not a vector."); @@ -3578,6 +3583,32 @@ WarpX::getField(FieldType field_type, const int lev, const int direction) const return *getFieldPointer(field_type, lev, direction); } +amrex::DistributionMapping +WarpX::MakeDistributionMap (int lev, amrex::BoxArray const& ba) +{ + bool roundrobin_sfc = false; + const ParmParse pp("warpx"); + pp.query("roundrobin_sfc", roundrobin_sfc); + + // If this is true, AMReX's RRSFC strategy is used to make + // DistributionMapping. Note that the DistributionMapping made by the + // here could still be overridden by load balancing. In the RRSFC + // strategy, the Round robin method is used to distribute Boxes orderd + // by the space filling curve. This might help avoid some processes + // running out of memory due to having too many particles during + // initialization. + + if (roundrobin_sfc) { + auto old_strategy = amrex::DistributionMapping::strategy(); + amrex::DistributionMapping::strategy(amrex::DistributionMapping::RRSFC); + amrex::DistributionMapping dm(ba); + amrex::DistributionMapping::strategy(old_strategy); + return dm; + } else { + return amrex::AmrCore::MakeDistributionMap(lev, ba); + } +} + const amrex::Vector,3>>& WarpX::getMultiLevelField(warpx::fields::FieldType field_type) const { @@ -3589,8 +3620,12 @@ WarpX::getMultiLevelField(warpx::fields::FieldType field_type) const return Bfield_aux; case FieldType::Efield_fp : return Efield_fp; + case FieldType::Efield_fp_external : + return Efield_fp_external; case FieldType::Bfield_fp : return Bfield_fp; + case FieldType::Bfield_fp_external : + return Bfield_fp_external; case FieldType::current_fp : return current_fp; case FieldType::current_fp_nodal : @@ -3606,3 +3641,42 @@ WarpX::getMultiLevelField(warpx::fields::FieldType field_type) const return Efield_fp; } } + +const amrex::iMultiFab* +WarpX::getFieldDotMaskPointer ( FieldType field_type, int lev, int dir ) const +{ + switch(field_type) + { + case FieldType::Efield_fp : + SetDotMask( Efield_dotMask[lev][dir], field_type, lev, dir ); + return Efield_dotMask[lev][dir].get(); + case FieldType::Bfield_fp : + SetDotMask( Bfield_dotMask[lev][dir], field_type, lev, dir ); + return Bfield_dotMask[lev][dir].get(); + case FieldType::vector_potential_fp : + SetDotMask( Afield_dotMask[lev][dir], field_type, lev, dir ); + return Afield_dotMask[lev][dir].get(); + case FieldType::phi_fp : + SetDotMask( phi_dotMask[lev], field_type, lev, 0 ); + return phi_dotMask[lev].get(); + default: + WARPX_ABORT_WITH_MESSAGE("Invalid field type for dotMask"); + return Efield_dotMask[lev][dir].get(); + } +} + +void WarpX::SetDotMask( std::unique_ptr& field_dotMask, + FieldType field_type, int lev, int dir ) const +{ + // Define the dot mask for this field_type needed to properly compute dotProduct() + // for field values that have shared locations on different MPI ranks + if (field_dotMask != nullptr) { return; } + + const amrex::MultiFab* this_field = getFieldPointer(field_type,lev,dir); + const amrex::BoxArray& this_ba = this_field->boxArray(); + const amrex::MultiFab tmp( this_ba, this_field->DistributionMap(), + 1, 0, amrex::MFInfo().SetAlloc(false) ); + const amrex::Periodicity& period = Geom(lev).periodicity(); + field_dotMask = tmp.OwnerMask(period); + +} diff --git a/Source/ablastr/fields/PoissonSolver.H b/Source/ablastr/fields/PoissonSolver.H index ca262981010..c36c83bc336 100644 --- a/Source/ablastr/fields/PoissonSolver.H +++ b/Source/ablastr/fields/PoissonSolver.H @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -45,9 +46,7 @@ #include #include #include -#if defined(AMREX_USE_EB) || defined(WARPX_DIM_RZ) -# include -#endif +#include #ifdef AMREX_USE_EB # include #endif @@ -58,6 +57,101 @@ namespace ablastr::fields { +/** Compute the L-infinity norm of the charge density `rho` across all MR levels + * to determine if `rho` is zero everywhere + * + * \param[in] rho The charge density a given species + * \param[in] finest_level The most refined mesh refinement level + * \param[in] absolute_tolerance The absolute convergence threshold for the MLMG solver + * \param[out] max_norm_rho The maximum L-infinity norm of `rho` across all levels + */ +inline amrex::Real getMaxNormRho ( + amrex::Vector const & rho, + int finest_level, + amrex::Real & absolute_tolerance) +{ + amrex::Real max_norm_rho = 0.0; + for (int lev=0; lev<=finest_level; lev++) { + max_norm_rho = amrex::max(max_norm_rho, rho[lev]->norm0()); + } + amrex::ParallelDescriptor::ReduceRealMax(max_norm_rho); + + if (max_norm_rho == 0) { + if (absolute_tolerance == 0.0) { absolute_tolerance = amrex::Real(1e-6); } + ablastr::warn_manager::WMRecordWarning( + "ElectrostaticSolver", + "Max norm of rho is 0", + ablastr::warn_manager::WarnPriority::low + ); + } + return max_norm_rho; +} + +/** Interpolate the potential `phi` from level `lev` to `lev+1` + * + * Needed to solve Poisson equation on `lev+1` + * The coarser level `lev` provides both + * the boundary values and initial guess for `phi` + * on the finer level `lev+1` + * + * \param[in] phi_lev The potential on a given mesh refinement level `lev` + * \param[in] phi_lev_plus_one The potential on the next level `lev+1` + * \param[in] geom_lev The geometry of level `lev` + * \param[in] do_single_precision_comms perform communications in single precision + * \param[in] refratio mesh refinement ratio between level `lev` and `lev+1` + * \param[in] ncomp Number of components of the multifab (1) + * \param[in] ng Number of ghost cells (1 if collocated, 0 otherwise) + */ +inline void interpolatePhiBetweenLevels ( + amrex::MultiFab const* phi_lev, + amrex::MultiFab* phi_lev_plus_one, + amrex::Geometry const & geom_lev, + bool do_single_precision_comms, + const amrex::IntVect& refratio, + const int ncomp, + const int ng) +{ + using namespace amrex::literals; + + // Allocate phi_cp for lev+1 + amrex::BoxArray ba = phi_lev_plus_one->boxArray(); + ba.coarsen(refratio); + amrex::MultiFab phi_cp(ba, phi_lev_plus_one->DistributionMap(), ncomp, ng); + if (ng > 0) { + // Set all values outside the domain to zero + phi_cp.setDomainBndry(0.0_rt, geom_lev); + } + + // Copy from phi[lev] to phi_cp (in parallel) + const amrex::Periodicity& crse_period = geom_lev.periodicity(); + + ablastr::utils::communication::ParallelCopy( + phi_cp, + *phi_lev, + 0, + 0, + 1, + amrex::IntVect(0), + amrex::IntVect(ng), + do_single_precision_comms, + crse_period + ); + + // Local interpolation from phi_cp to phi[lev+1] +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(*phi_lev_plus_one, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { + amrex::Array4 const phi_fp_arr = phi_lev_plus_one->array(mfi); + amrex::Array4 const phi_cp_arr = phi_cp.array(mfi); + + details::PoissonInterpCPtoFP const interp(phi_fp_arr, phi_cp_arr, refratio); + + amrex::Box const& b = mfi.growntilebox(ng); + amrex::ParallelFor(b, interp); + } +} + /** Compute the potential `phi` by solving the Poisson equation * * Uses `rho` as a source, assuming that the source moves at a @@ -81,8 +175,10 @@ namespace ablastr::fields { * \param[in] geom the geometry per level (e.g., from AmrMesh) * \param[in] dmap the distribution mapping per level (e.g., from AmrMesh) * \param[in] grids the grids per level (e.g., from AmrMesh) + * \param[in] grid_type Integer that corresponds to the type of grid used in the simulation (collocated, staggered, hybrid) * \param[in] boundary_handler a handler for boundary conditions, for example @see ElectrostaticSolver::PoissonBoundaryHandler * \param[in] is_solver_igf_on_lev0 boolean to select the Poisson solver: 1 for FFT on level 0 & Multigrid on other levels, 0 for Multigrid on all levels + * \param[in] eb_enabled solve with embedded boundaries * \param[in] do_single_precision_comms perform communications in single precision * \param[in] rel_ref_ratio mesh refinement ratio between levels (default: 1) * \param[in] post_phi_calculation perform a calculation per level directly after phi was calculated; required for embedded boundaries (default: none) @@ -98,16 +194,18 @@ void computePhi (amrex::Vector const & rho, amrex::Vector & phi, std::array const beta, - amrex::Real const relative_tolerance, + amrex::Real relative_tolerance, amrex::Real absolute_tolerance, - int const max_iters, - int const verbosity, + int max_iters, + int verbosity, amrex::Vector const& geom, amrex::Vector const& dmap, amrex::Vector const& grids, + utils::enums::GridType grid_type, T_BoundaryHandler const boundary_handler, bool is_solver_igf_on_lev0, - bool const do_single_precision_comms = false, + bool eb_enabled = false, + bool do_single_precision_comms = false, std::optional > rel_ref_ratio = std::nullopt, [[maybe_unused]] T_PostPhiCalculationFunctor post_phi_calculation = std::nullopt, [[maybe_unused]] std::optional current_time = std::nullopt, // only used for EB @@ -118,46 +216,17 @@ computePhi (amrex::Vector const & rho, ABLASTR_PROFILE("computePhi"); + auto const finest_level = static_cast(rho.size() - 1); + if (!rel_ref_ratio.has_value()) { - ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE(rho.size() == 1u, + ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE(finest_level == 0u, "rel_ref_ratio must be set if mesh-refinement is used"); rel_ref_ratio = amrex::Vector{{amrex::IntVect(AMREX_D_DECL(1, 1, 1))}}; } - auto const finest_level = static_cast(rho.size() - 1); - - // determine if rho is zero everywhere - amrex::Real max_norm_b = 0.0; - for (int lev=0; lev<=finest_level; lev++) { - max_norm_b = amrex::max(max_norm_b, rho[lev]->norm0()); - } - amrex::ParallelDescriptor::ReduceRealMax(max_norm_b); - - const bool always_use_bnorm = (max_norm_b > 0); - if (!always_use_bnorm) { - if (absolute_tolerance == 0.0) { absolute_tolerance = amrex::Real(1e-6); } - ablastr::warn_manager::WMRecordWarning( - "ElectrostaticSolver", - "Max norm of rho is 0", - ablastr::warn_manager::WarnPriority::low - ); - } - -#if !(defined(AMREX_USE_EB) || defined(WARPX_DIM_RZ)) - amrex::LPInfo info; -#else - const amrex::LPInfo info; -#endif - - for (int lev=0; lev<=finest_level; lev++) { - // Set the value of beta - amrex::Array beta_solver = -#if defined(WARPX_DIM_1D_Z) - {{ beta[2] }}; // beta_x and beta_z -#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - {{ beta[0], beta[2] }}; // beta_x and beta_z -#else - {{ beta[0], beta[1], beta[2] }}; +#if !defined(AMREX_USE_EB) + ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE(!eb_enabled, + "Embedded boundary solve requested but not compiled in"); #endif #if !defined(ABLASTR_USE_FFT) @@ -170,103 +239,152 @@ computePhi (amrex::Vector const & rho, "The FFT Poisson solver is currently only implemented for 3D!"); #endif -#if (defined(ABLASTR_USE_FFT) && defined(WARPX_DIM_3D)) + // Set the value of beta + amrex::Array beta_solver = +#if defined(WARPX_DIM_1D_Z) + {{ beta[2] }}; // beta_x and beta_z +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + {{ beta[0], beta[2] }}; // beta_x and beta_z +#else + {{ beta[0], beta[1], beta[2] }}; +#endif + + // determine if rho is zero everywhere + const amrex::Real max_norm_b = getMaxNormRho(rho, finest_level, absolute_tolerance); + + amrex::LPInfo info; + + for (int lev=0; lev<=finest_level; lev++) { + amrex::Array const dx_scaled + {AMREX_D_DECL(geom[lev].CellSize(0)/std::sqrt(1._rt-beta_solver[0]*beta_solver[0]), + geom[lev].CellSize(1)/std::sqrt(1._rt-beta_solver[1]*beta_solver[1]), + geom[lev].CellSize(2)/std::sqrt(1._rt-beta_solver[2]*beta_solver[2]))}; + +#if (defined(ABLASTR_USE_FFT) && defined(WARPX_DIM_3D)) // Use the Integrated Green Function solver (FFT) on the coarsest level if it was selected if(is_solver_igf_on_lev0 && lev==0){ - amrex::Array const dx_igf - {AMREX_D_DECL(geom[lev].CellSize(0)/std::sqrt(1._rt-beta_solver[0]*beta_solver[0]), - geom[lev].CellSize(1)/std::sqrt(1._rt-beta_solver[1]*beta_solver[1]), - geom[lev].CellSize(2)/std::sqrt(1._rt-beta_solver[2]*beta_solver[2]))}; if ( max_norm_b == 0 ) { phi[lev]->setVal(0); } else { - computePhiIGF( *rho[lev], *phi[lev], dx_igf, grids[lev] ); + computePhiIGF( *rho[lev], *phi[lev], dx_scaled, grids[lev] ); } continue; } #endif - // Use the Multigrid (MLMG) solver if selected or on refined patches // but first scale rho appropriately - using namespace ablastr::constant::SI; - rho[lev]->mult(-1._rt/ep0); // TODO: when do we "un-multiply" this? We need to document this side-effect! + rho[lev]->mult(-1._rt / ablastr::constant::SI::ep0); // TODO: when do we "un-multiply" this? We need to document this side-effect! -#if !(defined(AMREX_USE_EB) || defined(WARPX_DIM_RZ)) - // Determine whether to use semi-coarsening - amrex::Array dx_scaled - {AMREX_D_DECL(geom[lev].CellSize(0)/std::sqrt(1._rt-beta_solver[0]*beta_solver[0]), - geom[lev].CellSize(1)/std::sqrt(1._rt-beta_solver[1]*beta_solver[1]), - geom[lev].CellSize(2)/std::sqrt(1._rt-beta_solver[2]*beta_solver[2]))}; - int max_semicoarsening_level = 0; - int semicoarsening_direction = -1; - const auto min_dir = static_cast(std::distance(dx_scaled.begin(), - std::min_element(dx_scaled.begin(),dx_scaled.end()))); - const auto max_dir = static_cast(std::distance(dx_scaled.begin(), - std::max_element(dx_scaled.begin(),dx_scaled.end()))); - if (dx_scaled[max_dir] > dx_scaled[min_dir]) { - semicoarsening_direction = max_dir; - max_semicoarsening_level = static_cast - (std::log2(dx_scaled[max_dir]/dx_scaled[min_dir])); - } - if (max_semicoarsening_level > 0) { - info.setSemicoarsening(true); - info.setMaxSemicoarseningLevel(max_semicoarsening_level); - info.setSemicoarseningDirection(semicoarsening_direction); - } +#ifdef WARPX_DIM_RZ + constexpr bool is_rz = true; +#else + constexpr bool is_rz = false; #endif -#if defined(AMREX_USE_EB) || defined(WARPX_DIM_RZ) - // In the presence of EB or RZ: the solver assumes that the beam is - // propagating along one of the axes of the grid, i.e. that only *one* - // of the components of `beta` is non-negligible. - amrex::MLEBNodeFDLaplacian linop( {geom[lev]}, {grids[lev]}, {dmap[lev]}, info + if (!eb_enabled && !is_rz) { + // Determine whether to use semi-coarsening + int max_semicoarsening_level = 0; + int semicoarsening_direction = -1; + const auto min_dir = static_cast(std::distance(dx_scaled.begin(), + std::min_element(dx_scaled.begin(), dx_scaled.end()))); + const auto max_dir = static_cast(std::distance(dx_scaled.begin(), + std::max_element(dx_scaled.begin(), dx_scaled.end()))); + if (dx_scaled[max_dir] > dx_scaled[min_dir]) { + semicoarsening_direction = max_dir; + max_semicoarsening_level = static_cast(std::log2(dx_scaled[max_dir] / dx_scaled[min_dir])); + } + if (max_semicoarsening_level > 0) { + info.setSemicoarsening(true); + info.setMaxSemicoarseningLevel(max_semicoarsening_level); + info.setSemicoarseningDirection(semicoarsening_direction); + } + } + + std::unique_ptr linop; + if (eb_enabled || is_rz) { + // In the presence of EB or RZ: the solver assumes that the beam is + // propagating along one of the axes of the grid, i.e. that only *one* + // of the components of `beta` is non-negligible. + auto linop_nodelap = std::make_unique(); + if (eb_enabled) { #if defined(AMREX_USE_EB) - , {eb_farray_box_factory.value()[lev]} + linop_nodelap->define( + amrex::Vector{geom[lev]}, + amrex::Vector{grids[lev]}, + amrex::Vector{dmap[lev]}, + info, + amrex::Vector{eb_farray_box_factory.value()[lev]} + ); #endif - ); + } + else { + // TODO: rather use MLNodeTensorLaplacian (for RZ w/o EB) here? Semi-Coarsening would be nice here + linop_nodelap->define( + amrex::Vector{geom[lev]}, + amrex::Vector{grids[lev]}, + amrex::Vector{dmap[lev]}, + info + ); + } - // Note: this assumes that the beam is propagating along - // one of the axes of the grid, i.e. that only *one* of the - // components of `beta` is non-negligible. // we use this + // Note: this assumes that the beam is propagating along + // one of the axes of the grid, i.e. that only *one* of the + // components of `beta` is non-negligible. // we use this #if defined(WARPX_DIM_RZ) - linop.setSigma({0._rt, 1._rt-beta_solver[1]*beta_solver[1]}); + linop_nodelap->setRZ(true); + linop_nodelap->setSigma({0._rt, 1._rt-beta_solver[1]*beta_solver[1]}); #else - linop.setSigma({AMREX_D_DECL( - 1._rt-beta_solver[0]*beta_solver[0], - 1._rt-beta_solver[1]*beta_solver[1], - 1._rt-beta_solver[2]*beta_solver[2])}); + linop_nodelap->setSigma({AMREX_D_DECL( + 1._rt-beta_solver[0]*beta_solver[0], + 1._rt-beta_solver[1]*beta_solver[1], + 1._rt-beta_solver[2]*beta_solver[2])}); #endif - #if defined(AMREX_USE_EB) - // if the EB potential only depends on time, the potential can be passed - // as a float instead of a callable - if (boundary_handler.phi_EB_only_t) { - linop.setEBDirichlet(boundary_handler.potential_eb_t(current_time.value())); - } - else - linop.setEBDirichlet(boundary_handler.getPhiEB(current_time.value())); -#endif -#else - // In the absence of EB and RZ: use a more generic solver - // that can handle beams propagating in any direction - amrex::MLNodeTensorLaplacian linop( {geom[lev]}, {grids[lev]}, - {dmap[lev]}, info ); - linop.setBeta( beta_solver ); // for the non-axis-aligned solver + if (eb_enabled) { + // if the EB potential only depends on time, the potential can be passed + // as a float instead of a callable + if (boundary_handler.phi_EB_only_t) { + linop_nodelap->setEBDirichlet(boundary_handler.potential_eb_t(current_time.value())); + } else { + linop_nodelap->setEBDirichlet(boundary_handler.getPhiEB(current_time.value())); + } + } #endif + linop = std::move(linop_nodelap); + } else { + // In the absence of EB and RZ: use a more generic solver + // that can handle beams propagating in any direction + auto linop_tenslap = std::make_unique( + amrex::Vector{geom[lev]}, + amrex::Vector{grids[lev]}, + amrex::Vector{dmap[lev]}, + info + ); + linop_tenslap->setBeta(beta_solver); // for the non-axis-aligned solver + linop = std::move(linop_tenslap); + } // Solve the Poisson equation - linop.setDomainBC( boundary_handler.lobc, boundary_handler.hibc ); -#ifdef WARPX_DIM_RZ - linop.setRZ(true); -#endif - amrex::MLMG mlmg(linop); // actual solver defined here + linop->setDomainBC(boundary_handler.lobc, boundary_handler.hibc); + + amrex::MLMG mlmg(*linop); // actual solver defined here mlmg.setVerbose(verbosity); mlmg.setMaxIter(max_iters); - mlmg.setAlwaysUseBNorm(always_use_bnorm); + mlmg.setAlwaysUseBNorm((max_norm_b > 0)); + + const int ng = int(grid_type == utils::enums::GridType::Collocated); // ghost cells + if (ng) { + // In this case, computeE needs to use ghost nodes data. So we + // ask MLMG to fill BC for us after it solves the problem. + mlmg.setFinalFillBC(true); + } // Solve Poisson equation at lev mlmg.solve( {phi[lev]}, {rho[lev]}, - relative_tolerance, absolute_tolerance ); + relative_tolerance, absolute_tolerance ); + + const amrex::IntVect& refratio = rel_ref_ratio.value()[lev]; + const int ncomp = linop->getNComp(); // needed for solving the levels by levels: // - coarser level is initial guess for finer level @@ -274,44 +392,13 @@ computePhi (amrex::Vector const & rho, // Interpolation from phi[lev] to phi[lev+1] // (This provides both the boundary conditions and initial guess for phi[lev+1]) if (lev < finest_level) { - - // Allocate phi_cp for lev+1 - amrex::BoxArray ba = phi[lev+1]->boxArray(); - const amrex::IntVect& refratio = rel_ref_ratio.value()[lev]; - ba.coarsen(refratio); - const int ncomp = linop.getNComp(); - amrex::MultiFab phi_cp(ba, phi[lev+1]->DistributionMap(), ncomp, 1); - - // Copy from phi[lev] to phi_cp (in parallel) - const amrex::IntVect& ng = amrex::IntVect::TheUnitVector(); - const amrex::Periodicity& crse_period = geom[lev].periodicity(); - - ablastr::utils::communication::ParallelCopy( - phi_cp, - *phi[lev], - 0, - 0, - 1, - ng, - ng, - do_single_precision_comms, - crse_period - ); - - // Local interpolation from phi_cp to phi[lev+1] -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(*phi[lev + 1], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { - amrex::Array4 const phi_fp_arr = phi[lev + 1]->array(mfi); - amrex::Array4 const phi_cp_arr = phi_cp.array(mfi); - - details::PoissonInterpCPtoFP const interp(phi_fp_arr, phi_cp_arr, refratio); - - amrex::Box const b = mfi.tilebox(phi[lev + 1]->ixType().toIntVect()); - amrex::ParallelFor(b, interp); - } - + interpolatePhiBetweenLevels(phi[lev], + phi[lev+1], + geom[lev], + do_single_precision_comms, + refratio, + ncomp, + ng); } // Run additional operations, such as calculation of the E field for embedded boundaries @@ -320,10 +407,8 @@ computePhi (amrex::Vector const & rho, post_phi_calculation.value()(mlmg, lev); } } - } // loop over lev(els) -} - +} // computePhi } // namespace ablastr::fields #endif // ABLASTR_POISSON_SOLVER_H diff --git a/Source/ablastr/fields/VectorPoissonSolver.H b/Source/ablastr/fields/VectorPoissonSolver.H index 3ef96c30c84..f6dd2a99cf1 100644 --- a/Source/ablastr/fields/VectorPoissonSolver.H +++ b/Source/ablastr/fields/VectorPoissonSolver.H @@ -71,6 +71,7 @@ namespace ablastr::fields { * \param[in] dmap the distribution mapping per level (e.g., from AmrMesh) * \param[in] grids the grids per level (e.g., from AmrMesh) * \param[in] boundary_handler a handler for boundary conditions, for example @see MagnetostaticSolver::VectorPoissonBoundaryHandler + * \param[in] eb_enabled solve with embedded boundaries * \param[in] do_single_precision_comms perform communications in single precision * \param[in] rel_ref_ratio mesh refinement ratio between levels (default: 1) * \param[in] post_A_calculation perform a calculation per level directly after A was calculated; required for embedded boundaries (default: none) @@ -85,15 +86,16 @@ template< void computeVectorPotential ( amrex::Vector > const & curr, amrex::Vector > & A, - amrex::Real const relative_tolerance, + amrex::Real relative_tolerance, amrex::Real absolute_tolerance, - int const max_iters, - int const verbosity, + int max_iters, + int verbosity, amrex::Vector const& geom, amrex::Vector const& dmap, amrex::Vector const& grids, T_BoundaryHandler const boundary_handler, - bool const do_single_precision_comms = false, + bool eb_enabled = false, + bool do_single_precision_comms = false, std::optional > rel_ref_ratio = std::nullopt, [[maybe_unused]] T_PostACalculationFunctor post_A_calculation = std::nullopt, [[maybe_unused]] std::optional current_time = std::nullopt, // only used for EB @@ -108,6 +110,11 @@ computeVectorPotential ( amrex::Vector > co rel_ref_ratio = amrex::Vector{{amrex::IntVect(AMREX_D_DECL(1, 1, 1))}}; } +#if !defined(AMREX_USE_EB) + ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE(!eb_enabled, + "Embedded boundary solve requested but not compiled in"); +#endif + auto const finest_level = static_cast(curr.size()) - 1; // scale J appropriately; also determine if current is zero everywhere @@ -134,24 +141,18 @@ computeVectorPotential ( amrex::Vector > co // Loop over dimensions of A to solve each component individually for (int lev=0; lev<=finest_level; lev++) { - amrex::MLEBNodeFDLaplacian linopx( - {geom[lev]}, {grids[lev]}, {dmap[lev]}, info -#if defined(AMREX_USE_EB) - , {eb_farray_box_factory.value()[lev]} -#endif - ); - amrex::MLEBNodeFDLaplacian linopy( - {geom[lev]}, {grids[lev]}, {dmap[lev]}, info -#if defined(AMREX_USE_EB) - , {eb_farray_box_factory.value()[lev]} -#endif - ); - amrex::MLEBNodeFDLaplacian linopz( - {geom[lev]}, {grids[lev]}, {dmap[lev]}, info -#if defined(AMREX_USE_EB) - , {eb_farray_box_factory.value()[lev]} + amrex::MLEBNodeFDLaplacian linopx, linopy, linopz; + if (eb_enabled) { +#ifdef AMREX_USE_EB + linopx.define({geom[lev]}, {grids[lev]}, {dmap[lev]}, info, {eb_farray_box_factory.value()[lev]}); + linopy.define({geom[lev]}, {grids[lev]}, {dmap[lev]}, info, {eb_farray_box_factory.value()[lev]}); + linopz.define({geom[lev]}, {grids[lev]}, {dmap[lev]}, info, {eb_farray_box_factory.value()[lev]}); #endif - ); + } else { + linopx.define({geom[lev]}, {grids[lev]}, {dmap[lev]}, info); + linopy.define({geom[lev]}, {grids[lev]}, {dmap[lev]}, info); + linopz.define({geom[lev]}, {grids[lev]}, {dmap[lev]}, info); + } amrex::Array linop = {&linopx,&linopy,&linopz}; amrex::Array,3> mlmg; @@ -163,9 +164,9 @@ computeVectorPotential ( amrex::Vector > co // Note: this assumes that beta is zero linop[adim]->setSigma({AMREX_D_DECL(1._rt, 1._rt, 1._rt)}); -#if defined(AMREX_USE_EB) // Set Homogeneous Dirichlet Boundary on EB - linop[adim]->setEBDirichlet(0_rt); +#if defined(AMREX_USE_EB) + if (eb_enabled) { linop[adim]->setEBDirichlet(0_rt); } #endif #ifdef WARPX_DIM_RZ diff --git a/Source/ablastr/math/fft/AnyFFT.H b/Source/ablastr/math/fft/AnyFFT.H index c848e005d6f..3ebcb315ad1 100644 --- a/Source/ablastr/math/fft/AnyFFT.H +++ b/Source/ablastr/math/fft/AnyFFT.H @@ -10,16 +10,21 @@ #ifdef ABLASTR_USE_FFT # include +# include # include # if defined(AMREX_USE_CUDA) # include +# include # elif defined(AMREX_USE_HIP) # if __has_include() // ROCm 5.3+ # include # else # include # endif +# include +# elif defined(AMREX_USE_SYCL) +# include # else # include # endif @@ -62,6 +67,8 @@ namespace ablastr::math::anyfft # else using Complex = double2; # endif +# elif defined(AMREX_USE_SYCL) + using Complex = amrex::GpuComplex; # else # ifdef AMREX_USE_FLOAT using Complex = fftwf_complex; @@ -70,6 +77,28 @@ namespace ablastr::math::anyfft # endif # endif + /* Library-dependent multiply helpers */ +# if defined(AMREX_USE_CUDA) +# ifdef AMREX_USE_FLOAT + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void multiply (Complex & c, Complex const & a, Complex const & b) { c = cuCmulf(a, b); } +# else + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void multiply (Complex & c, Complex const & a, Complex const & b) { c = cuCmul(a, b); } +# endif +# elif defined(AMREX_USE_HIP) + # ifdef AMREX_USE_FLOAT + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void multiply (Complex & c, Complex const & a, Complex const & b) { c = hipCmulf(a, b); } +# else + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void multiply (Complex & c, Complex const & a, Complex const & b) { c = hipCmul(a, b); } +# endif +# elif defined(AMREX_USE_SYCL) + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void multiply (Complex & c, Complex const & a, Complex const & b) { c = a * b; } +# else + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void multiply (Complex & c, Complex const & a, Complex const & b) { + c[0] = a[0] * b[0] - a[1] * b[1]; + c[1] = a[0] * b[1] + a[1] * b[0]; + } +# endif + /** Library-dependent FFT plans type, which holds one fft plan per box * (plans are only initialized for the boxes that are owned by the local MPI rank). */ @@ -77,6 +106,15 @@ namespace ablastr::math::anyfft using VendorFFTPlan = cufftHandle; # elif defined(AMREX_USE_HIP) using VendorFFTPlan = rocfft_plan; +# elif defined(AMREX_USE_SYCL) + using VendorFFTPlan = oneapi::mkl::dft::descriptor< +# ifdef AMREX_USE_FLOAT + oneapi::mkl::dft::precision::SINGLE, +# else + oneapi::mkl::dft::precision::DOUBLE, +# endif + oneapi::mkl::dft::domain::REAL> *; + // dft::descriptor has no default ctor, so we have to use ptr. # else # ifdef AMREX_USE_FLOAT using VendorFFTPlan = fftwf_plan; @@ -99,6 +137,9 @@ namespace ablastr::math::anyfft VendorFFTPlan m_plan; /**< Vendor FFT plan */ direction m_dir; /**< direction (C2R or R2C) */ int m_dim; /**< Dimensionality of the FFT plan */ +#ifdef AMREX_USE_SYCL + amrex::gpuStream_t m_stream; +#endif }; /** Collection of FFT plans, one FFTplan per box */ diff --git a/Source/ablastr/math/fft/CMakeLists.txt b/Source/ablastr/math/fft/CMakeLists.txt index 913a912e1ee..b0ebc3c8050 100644 --- a/Source/ablastr/math/fft/CMakeLists.txt +++ b/Source/ablastr/math/fft/CMakeLists.txt @@ -5,6 +5,8 @@ foreach(D IN LISTS WarpX_DIMS) target_sources(ablastr_${SD} PRIVATE WrapCuFFT.cpp) elseif(WarpX_COMPUTE STREQUAL HIP) target_sources(ablastr_${SD} PRIVATE WrapRocFFT.cpp) + elseif(WarpX_COMPUTE STREQUAL SYCL) + target_sources(ablastr_${SD} PRIVATE WrapMklFFT.cpp) else() target_sources(ablastr_${SD} PRIVATE WrapFFTW.cpp) endif() diff --git a/Source/ablastr/math/fft/Make.package b/Source/ablastr/math/fft/Make.package index 63786cdc006..6e7dc2b3dd4 100644 --- a/Source/ablastr/math/fft/Make.package +++ b/Source/ablastr/math/fft/Make.package @@ -3,6 +3,8 @@ ifeq ($(USE_FFT),TRUE) CEXE_sources += WrapCuFFT.cpp else ifeq ($(USE_HIP),TRUE) CEXE_sources += WrapRocFFT.cpp + else ifeq ($(USE_SYCL),TRUE) + CEXE_sources += WrapMklFFT.cpp else CEXE_sources += WrapFFTW.cpp endif diff --git a/Source/ablastr/math/fft/WrapCuFFT.cpp b/Source/ablastr/math/fft/WrapCuFFT.cpp index 578f5484e41..1d05d537da6 100644 --- a/Source/ablastr/math/fft/WrapCuFFT.cpp +++ b/Source/ablastr/math/fft/WrapCuFFT.cpp @@ -42,8 +42,11 @@ namespace ablastr::math::anyfft } else if (dim == 2) { result = cufftPlan2d( &(fft_plan.m_plan), real_size[1], real_size[0], VendorR2C); + } else if (dim == 1) { + result = cufftPlan1d( + &(fft_plan.m_plan), real_size[0], VendorR2C, 1); } else { - ABLASTR_ABORT_WITH_MESSAGE("only dim=2 and dim=3 have been implemented"); + ABLASTR_ABORT_WITH_MESSAGE("only dim=1 and dim=2 and dim=3 have been implemented"); } } else { if (dim == 3) { @@ -52,6 +55,9 @@ namespace ablastr::math::anyfft } else if (dim == 2) { result = cufftPlan2d( &(fft_plan.m_plan), real_size[1], real_size[0], VendorC2R); + } else if (dim == 1) { + result = cufftPlan1d( + &(fft_plan.m_plan), real_size[0], VendorC2R, 1); } else { ABLASTR_ABORT_WITH_MESSAGE("only dim=2 and dim=3 have been implemented"); } diff --git a/Source/ablastr/math/fft/WrapFFTW.cpp b/Source/ablastr/math/fft/WrapFFTW.cpp index 61fee3f3cb2..f1783b14116 100644 --- a/Source/ablastr/math/fft/WrapFFTW.cpp +++ b/Source/ablastr/math/fft/WrapFFTW.cpp @@ -25,11 +25,15 @@ namespace ablastr::math::anyfft const auto VendorCreatePlanC2R3D = fftwf_plan_dft_c2r_3d; const auto VendorCreatePlanR2C2D = fftwf_plan_dft_r2c_2d; const auto VendorCreatePlanC2R2D = fftwf_plan_dft_c2r_2d; + const auto VendorCreatePlanR2C1D = fftwf_plan_dft_r2c_1d; + const auto VendorCreatePlanC2R1D = fftwf_plan_dft_c2r_1d; #else const auto VendorCreatePlanR2C3D = fftw_plan_dft_r2c_3d; const auto VendorCreatePlanC2R3D = fftw_plan_dft_c2r_3d; const auto VendorCreatePlanR2C2D = fftw_plan_dft_r2c_2d; const auto VendorCreatePlanC2R2D = fftw_plan_dft_c2r_2d; + const auto VendorCreatePlanR2C1D = fftw_plan_dft_r2c_1d; + const auto VendorCreatePlanC2R1D = fftw_plan_dft_c2r_1d; #endif FFTplan CreatePlan(const amrex::IntVect& real_size, amrex::Real * const real_array, @@ -56,9 +60,12 @@ namespace ablastr::math::anyfft } else if (dim == 2) { fft_plan.m_plan = VendorCreatePlanR2C2D( real_size[1], real_size[0], real_array, complex_array, FFTW_ESTIMATE); + } else if (dim == 1) { + fft_plan.m_plan = VendorCreatePlanR2C1D( + real_size[0], real_array, complex_array, FFTW_ESTIMATE); } else { ABLASTR_ABORT_WITH_MESSAGE( - "only dim=2 and dim=3 have been implemented"); + "only dim=1 and dim=2 and dim=3 have been implemented"); } } else if (dir == direction::C2R){ if (dim == 3) { @@ -67,9 +74,12 @@ namespace ablastr::math::anyfft } else if (dim == 2) { fft_plan.m_plan = VendorCreatePlanC2R2D( real_size[1], real_size[0], complex_array, real_array, FFTW_ESTIMATE); + } else if (dim == 1) { + fft_plan.m_plan = VendorCreatePlanC2R1D( + real_size[0], complex_array, real_array, FFTW_ESTIMATE); } else { ABLASTR_ABORT_WITH_MESSAGE( - "only dim=2 and dim=3 have been implemented. Should be easy to add dim=1."); + "only dim=1 and dim=2 and dim=3 have been implemented."); } } diff --git a/Source/ablastr/math/fft/WrapMklFFT.cpp b/Source/ablastr/math/fft/WrapMklFFT.cpp new file mode 100644 index 00000000000..ef2cb6c42fa --- /dev/null +++ b/Source/ablastr/math/fft/WrapMklFFT.cpp @@ -0,0 +1,96 @@ +/* Copyright 2019-2023 + * + * This file is part of ABLASTR. + * + * License: BSD-3-Clause-LBNL + */ + +#include "AnyFFT.H" + +#include "ablastr/utils/TextMsg.H" +#include "ablastr/profiler/ProfilerWrapper.H" + +#include + +namespace ablastr::math::anyfft +{ + + void setup () {/*nothing to do*/} + + void cleanup () {/*nothing to do*/} + + FFTplan CreatePlan (const amrex::IntVect& real_size, amrex::Real * const real_array, + Complex * const complex_array, const direction dir, const int dim) + { + FFTplan fft_plan; + ABLASTR_PROFILE("ablastr::math::anyfft::CreatePlan"); + + // Initialize fft_plan.m_plan with the vendor fft plan. + std::vector strides(dim+1); + if (dim == 3) { + fft_plan.m_plan = new std::remove_pointer_t( + {std::int64_t(real_size[2]), + std::int64_t(real_size[1]), + std::int64_t(real_size[0])}); + strides[0] = 0; + strides[1] = real_size[0] * real_size[1]; + strides[2] = real_size[0]; + strides[3] = 1; + } else if (dim == 2) { + fft_plan.m_plan = new std::remove_pointer_t( + {std::int64_t(real_size[1]), + std::int64_t(real_size[0])}); + strides[0] = 0; + strides[1] = real_size[0]; + strides[2] = 1; + } else if (dim == 1) { + strides[0] = 0; + strides[1] = 1; + fft_plan.m_plan = new std::remove_pointer_t( + std::int64_t(real_size[0])); + } else { + ABLASTR_ABORT_WITH_MESSAGE("only dim2 =1, dim=2 and dim=3 have been implemented"); + } + + fft_plan.m_plan->set_value(oneapi::mkl::dft::config_param::PLACEMENT, + DFTI_NOT_INPLACE); + fft_plan.m_plan->set_value(oneapi::mkl::dft::config_param::FWD_STRIDES, + strides.data()); + fft_plan.m_plan->commit(amrex::Gpu::Device::streamQueue()); + + // Store meta-data in fft_plan + fft_plan.m_real_array = real_array; + fft_plan.m_complex_array = complex_array; + fft_plan.m_dir = dir; + fft_plan.m_dim = dim; + fft_plan.m_stream = amrex::Gpu::gpuStream(); + + return fft_plan; + } + + void DestroyPlan (FFTplan& fft_plan) + { + delete fft_plan.m_plan; + } + + void Execute (FFTplan& fft_plan) + { + if (!(fft_plan.m_stream == amrex::Gpu::gpuStream())) { + amrex::Gpu::streamSynchronize(); + } + + sycl::event r; + if (fft_plan.m_dir == direction::R2C) { + r = oneapi::mkl::dft::compute_forward( + *fft_plan.m_plan, + fft_plan.m_real_array, + reinterpret_cast*>(fft_plan.m_complex_array)); + } else { + r = oneapi::mkl::dft::compute_backward( + *fft_plan.m_plan, + reinterpret_cast*>(fft_plan.m_complex_array), + fft_plan.m_real_array); + } + r.wait(); + } +} diff --git a/Source/ablastr/particles/DepositCharge.H b/Source/ablastr/particles/DepositCharge.H index 75e3bca170d..2eac9eb951b 100644 --- a/Source/ablastr/particles/DepositCharge.H +++ b/Source/ablastr/particles/DepositCharge.H @@ -46,7 +46,7 @@ namespace ablastr::particles * \param nc number of components to deposit */ template< typename T_PC > -static void +void deposit_charge (typename T_PC::ParIterType& pti, typename T_PC::RealVector const& wp, amrex::Real const charge, diff --git a/Source/ablastr/utils/Enums.H b/Source/ablastr/utils/Enums.H new file mode 100644 index 00000000000..7c7129cae77 --- /dev/null +++ b/Source/ablastr/utils/Enums.H @@ -0,0 +1,37 @@ +/* Copyright 2024 Axel Huebl + * + * This file is part of ABLASTR. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef ABLASTR_UTILS_ENUMS_H_ +#define ABLASTR_UTILS_ENUMS_H_ + +#include + +namespace ablastr::utils::enums +{ + /** Type of grids used in a simulation: + * + * Collocated at the same location (AMReX: all "NODAL"), staggered (Yee-style), or hybrid. + */ + AMREX_ENUM(GridType, + Collocated, + Staggered, + Hybrid, + Default = Staggered); + + /** Mesh-refinement patch + * + * The fine or coarse patch (in terms of spatial resolution) on the same MR level. + * https://warpx.readthedocs.io/en/latest/theory/amr.html + */ + enum struct PatchType { + fine, + coarse + }; + +} // namespace ablastr::utils::enums + +#endif // ABLASTR_UTILS_ENUMS_H_ diff --git a/Source/ablastr/utils/SignalHandling.cpp b/Source/ablastr/utils/SignalHandling.cpp index 4095b9207ce..5eeaeec259f 100644 --- a/Source/ablastr/utils/SignalHandling.cpp +++ b/Source/ablastr/utils/SignalHandling.cpp @@ -104,7 +104,7 @@ SignalHandling::parseSignalNameToNumber (const std::string &str) auto spf = signals_parser.compileHost<0>(); - const int sig = spf(); + const auto sig = int(spf()); ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE(sig < NUM_SIGNALS, "Parsed signal value is outside the supported range of [1, 31]"); diff --git a/Source/ablastr/utils/UsedInputsFile.cpp b/Source/ablastr/utils/UsedInputsFile.cpp index dfdc4bfa192..a7777556242 100644 --- a/Source/ablastr/utils/UsedInputsFile.cpp +++ b/Source/ablastr/utils/UsedInputsFile.cpp @@ -23,7 +23,7 @@ ablastr::utils::write_used_inputs_file (std::string const & filename) if (amrex::ParallelDescriptor::IOProcessor()) { std::ofstream jobInfoFile; jobInfoFile.open(filename.c_str(), std::ios::out); - amrex::ParmParse::dumpTable(jobInfoFile, true); + amrex::ParmParse::prettyPrintTable(jobInfoFile); jobInfoFile.close(); } } diff --git a/Tools/Algorithms/psatd.ipynb b/Tools/Algorithms/psatd.ipynb index c2f326e4110..3e8b2a82d2e 100644 --- a/Tools/Algorithms/psatd.ipynb +++ b/Tools/Algorithms/psatd.ipynb @@ -3,13 +3,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "import sympy as sp\n", - "from sympy import *\n", + "from sympy import * # noqa\n", "\n", "sp.init_session()\n", "sp.init_printing()" @@ -39,8 +37,8 @@ "source": [ "divE_cleaning = True\n", "divB_cleaning = True\n", - "J_in_time = 'constant'\n", - "rho_in_time = 'constant'" + "J_in_time = \"constant\"\n", + "rho_in_time = \"constant\"" ] }, { @@ -63,10 +61,13 @@ " Wd = P * D * invP\n", " for i in range(Wd.shape[0]):\n", " for j in range(Wd.shape[1]):\n", - " Wd[i,j] = Wd[i,j].expand().simplify()\n", - " diff = W[i,j] - Wd[i,j]\n", + " Wd[i, j] = Wd[i, j].expand().simplify()\n", + " diff = W[i, j] - Wd[i, j]\n", " diff = diff.expand().simplify()\n", - " assert (diff == 0), f'Diagonalization failed: W[{i},{j}] - Wd[{i},{j}] = {diff} is not zero'\n", + " assert (\n", + " diff == 0\n", + " ), f\"Diagonalization failed: W[{i},{j}] - Wd[{i},{j}] = {diff} is not zero\"\n", + "\n", "\n", "def simple_mat(W):\n", " \"\"\"\n", @@ -74,7 +75,7 @@ " \"\"\"\n", " for i in range(W.shape[0]):\n", " for j in range(W.shape[1]):\n", - " W[i,j] = W[i,j].expand().simplify()" + " W[i, j] = W[i, j].expand().simplify()" ] }, { @@ -98,41 +99,41 @@ " dim += 1\n", "\n", "# Define symbols for physical constants\n", - "c = sp.symbols(r'c', real=True, positive=True)\n", - "mu0 = sp.symbols(r'\\mu_0', real=True, positive=True)\n", + "c = sp.symbols(r\"c\", real=True, positive=True)\n", + "mu0 = sp.symbols(r\"\\mu_0\", real=True, positive=True)\n", "\n", "# Define symbols for time variables\n", "# (s is auxiliary variable used in integral over time)\n", - "s = sp.symbols(r's', real=True, positive=True)\n", - "t = sp.symbols(r't', real=True, positive=True)\n", - "tn = sp.symbols(r't_n', real=True, positive=True)\n", - "dt = sp.symbols(r'\\Delta{t}', real=True, positive=True)\n", + "s = sp.symbols(r\"s\", real=True, positive=True)\n", + "t = sp.symbols(r\"t\", real=True, positive=True)\n", + "tn = sp.symbols(r\"t_n\", real=True, positive=True)\n", + "dt = sp.symbols(r\"\\Delta{t}\", real=True, positive=True)\n", "\n", "# The assumption that kx, ky and kz are positive is general enough\n", "# and makes it easier for SymPy to perform some of the calculations\n", - "kx = sp.symbols(r'k_x', real=True, positive=True)\n", - "ky = sp.symbols(r'k_y', real=True, positive=True)\n", - "kz = sp.symbols(r'k_z', real=True, positive=True)\n", + "kx = sp.symbols(r\"k_x\", real=True, positive=True)\n", + "ky = sp.symbols(r\"k_y\", real=True, positive=True)\n", + "kz = sp.symbols(r\"k_z\", real=True, positive=True)\n", "\n", "# Define symbols for the Cartesian components of the electric field\n", - "Ex = sp.symbols(r'E^x')\n", - "Ey = sp.symbols(r'E^y')\n", - "Ez = sp.symbols(r'E^z')\n", + "Ex = sp.symbols(r\"E^x\")\n", + "Ey = sp.symbols(r\"E^y\")\n", + "Ez = sp.symbols(r\"E^z\")\n", "E = Matrix([[Ex], [Ey], [Ez]])\n", "\n", "# Define symbols for the Cartesian components of the magnetic field\n", - "Bx = sp.symbols(r'B^x')\n", - "By = sp.symbols(r'B^y')\n", - "Bz = sp.symbols(r'B^z')\n", + "Bx = sp.symbols(r\"B^x\")\n", + "By = sp.symbols(r\"B^y\")\n", + "Bz = sp.symbols(r\"B^z\")\n", "B = Matrix([[Bx], [By], [Bz]])\n", "\n", "# Define symbol for the scalar field F used with div(E) cleaning\n", "if divE_cleaning:\n", - " F = sp.symbols(r'F')\n", + " F = sp.symbols(r\"F\")\n", "\n", "# Define symbol for the scalar field G used with div(B) cleaning\n", "if divB_cleaning:\n", - " G = sp.symbols(r'G')" + " G = sp.symbols(r\"G\")" ] }, { @@ -149,30 +150,30 @@ "outputs": [], "source": [ "# Define first-order time derivatives of the electric field\n", - "dEx_dt = I*c**2*(ky*Bz-kz*By) \n", - "dEy_dt = I*c**2*(kz*Bx-kx*Bz)\n", - "dEz_dt = I*c**2*(kx*By-ky*Bx)\n", + "dEx_dt = I * c**2 * (ky * Bz - kz * By)\n", + "dEy_dt = I * c**2 * (kz * Bx - kx * Bz)\n", + "dEz_dt = I * c**2 * (kx * By - ky * Bx)\n", "\n", "# Define first-order time derivatives of the magnetic field\n", - "dBx_dt = -I*(ky*Ez-kz*Ey)\n", - "dBy_dt = -I*(kz*Ex-kx*Ez)\n", - "dBz_dt = -I*(kx*Ey-ky*Ex)\n", + "dBx_dt = -I * (ky * Ez - kz * Ey)\n", + "dBy_dt = -I * (kz * Ex - kx * Ez)\n", + "dBz_dt = -I * (kx * Ey - ky * Ex)\n", "\n", "# Define first-order time derivative of the scalar field F used with div(E) cleaning,\n", "# and related additional terms in the first-order time derivative of the electric field\n", "if divE_cleaning:\n", - " dEx_dt += I*c**2*F*kx \n", - " dEy_dt += I*c**2*F*ky\n", - " dEz_dt += I*c**2*F*kz\n", - " dF_dt = I*(kx*Ex+ky*Ey+kz*Ez)\n", + " dEx_dt += I * c**2 * F * kx\n", + " dEy_dt += I * c**2 * F * ky\n", + " dEz_dt += I * c**2 * F * kz\n", + " dF_dt = I * (kx * Ex + ky * Ey + kz * Ez)\n", "\n", "# Define first-order time derivative of the scalar field G used with div(B) cleaning,\n", "# and related additional terms in the first-order time derivative of the magnetic field\n", "if divB_cleaning:\n", - " dBx_dt += I*c**2*G*kx\n", - " dBy_dt += I*c**2*G*ky\n", - " dBz_dt += I*c**2*G*kz\n", - " dG_dt = I*(kx*Bx+ky*By+kz*Bz)\n", + " dBx_dt += I * c**2 * G * kx\n", + " dBy_dt += I * c**2 * G * ky\n", + " dBz_dt += I * c**2 * G * kz\n", + " dG_dt = I * (kx * Bx + ky * By + kz * Bz)\n", "\n", "# Define array of first-order time derivatives of the electric and magnetic fields\n", "dE_dt = Matrix([[dEx_dt], [dEy_dt], [dEz_dt]])\n", @@ -242,8 +243,8 @@ "M = zeros(dim)\n", "for i in range(M.shape[0]):\n", " for j in range(M.shape[1]):\n", - " M[i,j] = dEBFG_dt[i].coeff(EBFG[j], 1)\n", - "print(r'M = ')\n", + " M[i, j] = dEBFG_dt[i].coeff(EBFG[j], 1)\n", + "print(r\"M = \")\n", "display(M)" ] }, @@ -308,12 +309,12 @@ "\n", "# Compute matrices of eigenvectors and eigenvalues for diagonalization of M\n", "P, D = M.diagonalize()\n", - "invP = P**(-1)\n", + "invP = P ** (-1)\n", "expD = exp(D)\n", "check_diag(M, D, P, invP)\n", - "print('P = ')\n", + "print(\"P = \")\n", "display(P)\n", - "print('D = ')\n", + "print(\"D = \")\n", "display(D)" ] }, @@ -334,7 +335,7 @@ "\n", "# Compute matrices of eigenvectors and eigenvalues for diagonalization of W1\n", "P1 = P\n", - "D1 = D * (t-tn)\n", + "D1 = D * (t - tn)\n", "invP1 = invP\n", "expD1 = exp(D1)" ] @@ -418,8 +419,8 @@ "expW1 = P1 * expD1 * invP1\n", "\n", "# Compute general solution at time t = tn+dt\n", - "EBFG_h = expW1 * EBFG \n", - "EBFG_h_new = EBFG_h.subs(t, tn+dt)" + "EBFG_h = expW1 * EBFG\n", + "EBFG_h_new = EBFG_h.subs(t, tn + dt)" ] }, { @@ -436,41 +437,41 @@ "outputs": [], "source": [ "# Define J\n", - "Jx_c0 = sp.symbols(r'\\gamma_{J_x}', real=True)\n", - "Jy_c0 = sp.symbols(r'\\gamma_{J_y}', real=True)\n", - "Jz_c0 = sp.symbols(r'\\gamma_{J_z}', real=True)\n", + "Jx_c0 = sp.symbols(r\"\\gamma_{J_x}\", real=True)\n", + "Jy_c0 = sp.symbols(r\"\\gamma_{J_y}\", real=True)\n", + "Jz_c0 = sp.symbols(r\"\\gamma_{J_z}\", real=True)\n", "Jx = Jx_c0\n", "Jy = Jy_c0\n", "Jz = Jz_c0\n", - "if J_in_time == 'linear':\n", - " Jx_c1 = sp.symbols(r'\\beta_{J_x}', real=True)\n", - " Jy_c1 = sp.symbols(r'\\beta_{J_y}', real=True)\n", - " Jz_c1 = sp.symbols(r'\\beta_{J_z}', real=True)\n", - " Jx += Jx_c1*(s-tn)\n", - " Jy += Jy_c1*(s-tn)\n", - " Jz += Jz_c1*(s-tn)\n", - "if J_in_time == 'quadratic':\n", - " Jx_c1 = sp.symbols(r'\\beta_{J_x}', real=True)\n", - " Jy_c1 = sp.symbols(r'\\beta_{J_y}', real=True)\n", - " Jz_c1 = sp.symbols(r'\\beta_{J_z}', real=True)\n", - " Jx_c2 = sp.symbols(r'\\alpha_{J_x}', real=True)\n", - " Jy_c2 = sp.symbols(r'\\alpha_{J_y}', real=True)\n", - " Jz_c2 = sp.symbols(r'\\alpha_{J_z}', real=True)\n", - " Jx += Jx_c1*(s-tn) + Jx_c2*(s-tn)**2\n", - " Jy += Jy_c1*(s-tn) + Jy_c2*(s-tn)**2\n", - " Jz += Jz_c1*(s-tn) + Jz_c2*(s-tn)**2\n", + "if J_in_time == \"linear\":\n", + " Jx_c1 = sp.symbols(r\"\\beta_{J_x}\", real=True)\n", + " Jy_c1 = sp.symbols(r\"\\beta_{J_y}\", real=True)\n", + " Jz_c1 = sp.symbols(r\"\\beta_{J_z}\", real=True)\n", + " Jx += Jx_c1 * (s - tn)\n", + " Jy += Jy_c1 * (s - tn)\n", + " Jz += Jz_c1 * (s - tn)\n", + "if J_in_time == \"quadratic\":\n", + " Jx_c1 = sp.symbols(r\"\\beta_{J_x}\", real=True)\n", + " Jy_c1 = sp.symbols(r\"\\beta_{J_y}\", real=True)\n", + " Jz_c1 = sp.symbols(r\"\\beta_{J_z}\", real=True)\n", + " Jx_c2 = sp.symbols(r\"\\alpha_{J_x}\", real=True)\n", + " Jy_c2 = sp.symbols(r\"\\alpha_{J_y}\", real=True)\n", + " Jz_c2 = sp.symbols(r\"\\alpha_{J_z}\", real=True)\n", + " Jx += Jx_c1 * (s - tn) + Jx_c2 * (s - tn) ** 2\n", + " Jy += Jy_c1 * (s - tn) + Jy_c2 * (s - tn) ** 2\n", + " Jz += Jz_c1 * (s - tn) + Jz_c2 * (s - tn) ** 2\n", "\n", "# Define rho\n", "if divE_cleaning:\n", - " rho_c0 = sp.symbols(r'\\gamma_{\\rho}', real=True)\n", + " rho_c0 = sp.symbols(r\"\\gamma_{\\rho}\", real=True)\n", " rho = rho_c0\n", - " if rho_in_time == 'linear':\n", - " rho_c1 = sp.symbols(r'\\beta_{\\rho}', real=True)\n", - " rho += rho_c1*(s-tn)\n", - " if rho_in_time == 'quadratic':\n", - " rho_c1 = sp.symbols(r'\\beta_{\\rho}', real=True)\n", - " rho_c2 = sp.symbols(r'\\alpha_{\\rho}', real=True)\n", - " rho += rho_c1*(s-tn) + rho_c2*(s-tn)**2" + " if rho_in_time == \"linear\":\n", + " rho_c1 = sp.symbols(r\"\\beta_{\\rho}\", real=True)\n", + " rho += rho_c1 * (s - tn)\n", + " if rho_in_time == \"quadratic\":\n", + " rho_c1 = sp.symbols(r\"\\beta_{\\rho}\", real=True)\n", + " rho_c2 = sp.symbols(r\"\\alpha_{\\rho}\", real=True)\n", + " rho += rho_c1 * (s - tn) + rho_c2 * (s - tn) ** 2" ] }, { @@ -500,9 +501,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "%%time \n", @@ -515,7 +514,7 @@ " fields_list.append(0)\n", "S = zeros(dim, 1)\n", "for i in range(S.shape[0]):\n", - " S[i] = -mu0*c**2 * fields_list[i]\n", + " S[i] = -mu0 * c**2 * fields_list[i]\n", "\n", "# Compute integral of exp(W3)*S over s (assuming |k| is not zero)\n", "integral = zeros(dim, 1)\n", @@ -524,12 +523,12 @@ "for i in range(dim):\n", " r = integrate(tmp[i], (s, tn, t))\n", " integral[i] = r\n", - " \n", + "\n", "# Compute particular solution at time t = tn+dt\n", "tmp = invP2 * P3\n", "simple_mat(tmp)\n", "EBFG_nh = P2 * expD2 * tmp * integral\n", - "EBFG_nh_new = EBFG_nh.subs(t, tn+dt)" + "EBFG_nh_new = EBFG_nh.subs(t, tn + dt)" ] }, { @@ -549,13 +548,13 @@ "\n", "for i in range(EBFG.shape[0]):\n", " lhs = dEBFG_dt[i] + S[i]\n", - " lhs = lhs.subs(s, tn) # sources were written as functions of s\n", + " lhs = lhs.subs(s, tn) # sources were written as functions of s\n", " rhs = (EBFG_h[i] + EBFG_nh[i]).diff(t)\n", - " rhs = rhs.subs(t, tn) # results were written as functions of t\n", + " rhs = rhs.subs(t, tn) # results were written as functions of t\n", " rhs = rhs.simplify()\n", " diff = lhs - rhs\n", " diff = diff.simplify()\n", - " assert (diff == 0), f'Integration of linear system of ODEs failed'" + " assert diff == 0, \"Integration of linear system of ODEs failed\"" ] }, { @@ -575,22 +574,30 @@ "source": [ "%%time\n", "\n", - "L = ['Ex', 'Ey', 'Ez', 'Bx', 'By', 'Bz']\n", - "R = ['Ex', 'Ey', 'Ez', 'Bx', 'By', 'Bz']\n", + "L = [\"Ex\", \"Ey\", \"Ez\", \"Bx\", \"By\", \"Bz\"]\n", + "R = [\"Ex\", \"Ey\", \"Ez\", \"Bx\", \"By\", \"Bz\"]\n", "if divE_cleaning:\n", - " L.append('F')\n", - " R.append('F')\n", + " L.append(\"F\")\n", + " R.append(\"F\")\n", "if divB_cleaning:\n", - " L.append('G')\n", - " R.append('G')\n", + " L.append(\"G\")\n", + " R.append(\"G\")\n", "\n", "# Compute individual coefficients in the update equations\n", "coeff_h = dict()\n", "for i in range(dim):\n", " for j in range(dim):\n", " key = (L[i], R[j])\n", - " coeff_h[key] = EBFG_h_new[i].coeff(EBFG[j], 1).expand().simplify().rewrite(cos).trigsimp().simplify()\n", - " print(f'Coefficient of {L[i]} with respect to {R[j]}:')\n", + " coeff_h[key] = (\n", + " EBFG_h_new[i]\n", + " .coeff(EBFG[j], 1)\n", + " .expand()\n", + " .simplify()\n", + " .rewrite(cos)\n", + " .trigsimp()\n", + " .simplify()\n", + " )\n", + " print(f\"Coefficient of {L[i]} with respect to {R[j]}:\")\n", " display(coeff_h[key])" ] }, @@ -611,36 +618,36 @@ "source": [ "%%time\n", "\n", - "L = ['Ex', 'Ey', 'Ez', 'Bx', 'By', 'Bz']\n", - "R = ['Jx_c0', 'Jy_c0', 'Jz_c0']\n", - "if J_in_time == 'linear':\n", - " R.append('Jx_c1')\n", - " R.append('Jy_c1')\n", - " R.append('Jz_c1')\n", - "if J_in_time == 'quadratic':\n", - " R.append('Jx_c1')\n", - " R.append('Jy_c1')\n", - " R.append('Jz_c1')\n", - " R.append('Jx_c2')\n", - " R.append('Jy_c2')\n", - " R.append('Jz_c2')\n", + "L = [\"Ex\", \"Ey\", \"Ez\", \"Bx\", \"By\", \"Bz\"]\n", + "R = [\"Jx_c0\", \"Jy_c0\", \"Jz_c0\"]\n", + "if J_in_time == \"linear\":\n", + " R.append(\"Jx_c1\")\n", + " R.append(\"Jy_c1\")\n", + " R.append(\"Jz_c1\")\n", + "if J_in_time == \"quadratic\":\n", + " R.append(\"Jx_c1\")\n", + " R.append(\"Jy_c1\")\n", + " R.append(\"Jz_c1\")\n", + " R.append(\"Jx_c2\")\n", + " R.append(\"Jy_c2\")\n", + " R.append(\"Jz_c2\")\n", "if divE_cleaning:\n", - " L.append('F')\n", - " R.append('rho_c0')\n", - " if rho_in_time == 'linear':\n", - " R.append('rho_c1')\n", - " if rho_in_time == 'quadratic':\n", - " R.append('rho_c1')\n", - " R.append('rho_c2')\n", + " L.append(\"F\")\n", + " R.append(\"rho_c0\")\n", + " if rho_in_time == \"linear\":\n", + " R.append(\"rho_c1\")\n", + " if rho_in_time == \"quadratic\":\n", + " R.append(\"rho_c1\")\n", + " R.append(\"rho_c2\")\n", "if divB_cleaning:\n", - " L.append('G')\n", + " L.append(\"G\")\n", "\n", "cs = [Jx_c0, Jy_c0, Jz_c0]\n", - "if J_in_time == 'linear':\n", + "if J_in_time == \"linear\":\n", " cs.append(Jx_c1)\n", " cs.append(Jy_c1)\n", " cs.append(Jz_c1)\n", - "if J_in_time == 'quadratic':\n", + "if J_in_time == \"quadratic\":\n", " cs.append(Jx_c1)\n", " cs.append(Jy_c1)\n", " cs.append(Jz_c1)\n", @@ -649,19 +656,28 @@ " cs.append(Jz_c2)\n", "if divE_cleaning:\n", " cs.append(rho_c0)\n", - " if rho_in_time == 'linear':\n", + " if rho_in_time == \"linear\":\n", " cs.append(rho_c1)\n", - " if rho_in_time == 'quadratic':\n", + " if rho_in_time == \"quadratic\":\n", " cs.append(rho_c1)\n", " cs.append(rho_c2)\n", - " \n", + "\n", "# Compute individual coefficients in the update equation\n", "coeff_nh = dict()\n", "for i in range(len(L)):\n", " for j in range(len(R)):\n", " key = (L[i], R[j])\n", - " coeff_nh[key] = EBFG_nh_new[i].expand().coeff(cs[j], 1).expand().simplify().rewrite(cos).trigsimp().simplify()\n", - " print(f'Coefficient of {L[i]} with respect to {R[j]}:')\n", + " coeff_nh[key] = (\n", + " EBFG_nh_new[i]\n", + " .expand()\n", + " .coeff(cs[j], 1)\n", + " .expand()\n", + " .simplify()\n", + " .rewrite(cos)\n", + " .trigsimp()\n", + " .simplify()\n", + " )\n", + " print(f\"Coefficient of {L[i]} with respect to {R[j]}:\")\n", " display(coeff_nh[key])" ] }, @@ -677,29 +693,25 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ - "coeff_h[('Ex', 'By')]" + "coeff_h[(\"Ex\", \"By\")]" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ - "coeff_nh[('Ex', 'Jx_c0')]" + "coeff_nh[(\"Ex\", \"Jx_c0\")]" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -713,7 +725,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.12.4" } }, "nbformat": 4, diff --git a/Tools/Algorithms/psatd_pml.ipynb b/Tools/Algorithms/psatd_pml.ipynb index 897ffa70b9e..66ae219747b 100644 --- a/Tools/Algorithms/psatd_pml.ipynb +++ b/Tools/Algorithms/psatd_pml.ipynb @@ -8,9 +8,8 @@ }, "outputs": [], "source": [ - "import inspect\n", "import sympy as sp\n", - "from sympy import *\n", + "from sympy import * # noqa\n", "from sympy.solvers.solveset import linsolve\n", "\n", "sp.init_session()\n", @@ -35,16 +34,16 @@ "DD = 12\n", "\n", "# Speed of light, time, time step\n", - "c = sp.symbols(r'c', real = True, positive = True)\n", - "t = sp.symbols(r't', real = True)\n", - "tn = sp.symbols(r't_n', real = True)\n", - "dt = sp.symbols(r'\\Delta{t}', real = True, positive = True)\n", + "c = sp.symbols(r\"c\", real=True, positive=True)\n", + "t = sp.symbols(r\"t\", real=True)\n", + "tn = sp.symbols(r\"t_n\", real=True)\n", + "dt = sp.symbols(r\"\\Delta{t}\", real=True, positive=True)\n", "\n", "# Components of k vector, omega, norm of k vector\n", - "kx = sp.symbols(r'k_x', real = True)\n", - "ky = sp.symbols(r'k_y', real = True)\n", - "kz = sp.symbols(r'k_z', real = True)\n", - "om = sp.symbols(r'omega', real = True, positive = True)\n", + "kx = sp.symbols(r\"k_x\", real=True)\n", + "ky = sp.symbols(r\"k_y\", real=True)\n", + "kz = sp.symbols(r\"k_z\", real=True)\n", + "om = sp.symbols(r\"omega\", real=True, positive=True)\n", "knorm = sp.sqrt(kx**2 + ky**2 + kz**2)" ] }, @@ -98,10 +97,12 @@ "outputs": [], "source": [ "def C(omega, t):\n", - " return sp.cos(omega * (t-tn))\n", + " return sp.cos(omega * (t - tn))\n", + "\n", "\n", "def S(omega, t):\n", - " return (t-tn) if omega == 0. else sp.sin(omega * (t-tn)) / omega\n", + " return (t - tn) if omega == 0.0 else sp.sin(omega * (t - tn)) / omega\n", + "\n", "\n", "def Xt(eigenpairs, a, b, t):\n", " \"\"\"\n", @@ -114,7 +115,7 @@ " # Loop over matrix eigenpairs\n", " for ep in eigenpairs:\n", " # ep[0] is an eigenvalue and om = sp.sqrt(-ep[0])\n", - " omega = 0. if ep[0] == 0. else om\n", + " omega = 0.0 if ep[0] == 0.0 else om\n", " # am is the algebraic multiplicity of the eigenvalue\n", " am = ep[1]\n", " # vF is the list of all eigenvectors corresponding to the eigenvalue\n", @@ -125,6 +126,7 @@ " i += 1\n", " return XX\n", "\n", + "\n", "def evolve(X, dX_dt, d2X_dt2):\n", " \"\"\"\n", " Solve ordinary differential equation X'' = M*X.\n", @@ -133,15 +135,15 @@ " MX = zeros(DD)\n", " for i in range(DD):\n", " for j in range(DD):\n", - " MX[i,j] = d2X_dt2[i].coeff(X[j], 1)\n", - " #MX /= c**2\n", + " MX[i, j] = d2X_dt2[i].coeff(X[j], 1)\n", + " # MX /= c**2\n", "\n", " print()\n", - " print(r'Matrix:')\n", + " print(r\"Matrix:\")\n", " display(MX)\n", "\n", " # Characteristic matrix\n", - " lamda = sp.symbols(r'lamda')\n", + " lamda = sp.symbols(r\"lamda\")\n", " Id = eye(DD)\n", " MX_charmat = MX - lamda * Id\n", "\n", @@ -149,9 +151,9 @@ " MX_charpoly = MX_charmat.det()\n", " MX_charpoly = factor(MX_charpoly.as_expr())\n", "\n", - " print(r'Characteristic polynomial:')\n", + " print(r\"Characteristic polynomial:\")\n", " display(MX_charpoly)\n", - " \n", + "\n", " MX_eigenvals = sp.solve(MX_charpoly, lamda)\n", "\n", " # List of eigenvectors\n", @@ -159,59 +161,58 @@ "\n", " # List of eigenpairs\n", " MX_eigenpairs = []\n", - " \n", - " # Compute eigenvectors as null spaces\n", - " for l in MX_eigenvals:\n", "\n", + " # Compute eigenvectors as null spaces\n", + " for ev in MX_eigenvals:\n", " # M - lamda * Id\n", - " A = MX_charmat.subs(lamda, l)\n", + " A = MX_charmat.subs(lamda, ev)\n", " A.simplify()\n", "\n", - " print(r'Eigenvalue:')\n", - " display(l)\n", + " print(r\"Eigenvalue:\")\n", + " display(ev)\n", "\n", - " print(r'Characteristic matrix:')\n", + " print(r\"Characteristic matrix:\")\n", " display(A)\n", "\n", " # Perform Gaussian elimination (necessary for lamda != 0)\n", - " if (l != 0.):\n", - " print(r'Gaussian elimination:')\n", - " print(r'A[0,:] += A[1,:]')\n", - " A[0,:] += A[1,:]\n", - " print(r'A[0,:] += A[2,:]')\n", - " A[0,:] += A[2,:]\n", - " print(r'Swap A[0,:] and A[11,:]')\n", - " row = A[11,:]\n", - " A[11,:] = A[0,:]\n", - " A[0,:] = row\n", - " print(r'A[3,:] += A[4,:]')\n", - " A[3,:] += A[4,:]\n", - " print(r'A[3,:] += A[5,:]')\n", - " A[3,:] += A[5,:]\n", - " print(r'Swap A[3,:] and A[10,:]')\n", - " row = A[10,:]\n", - " A[10,:] = A[3,:]\n", - " A[3,:] = row\n", - " print(r'A[0,:] += A[3,:]')\n", - " A[0,:] += A[3,:]\n", - " print(r'A[0,:] += A[9,:]')\n", - " A[0,:] += A[9,:]\n", - " print(r'Swap A[0,:] and A[9,:]')\n", - " row = A[9,:]\n", - " A[9,:] = A[0,:]\n", - " A[0,:] = row\n", - " print(r'A[6,:] += A[8,:]')\n", - " A[6,:] += A[8,:]\n", - " print(r'A[6,:] += A[7,:]')\n", - " A[6,:] += A[7,:]\n", - " print(r'Swap A[6,:] and A[8,:]')\n", - " row = A[8,:]\n", - " A[8,:] = A[6,:]\n", - " A[6,:] = row\n", - " print(r'A[6,:] += A[7,:]')\n", - " A[6,:] += A[7,:]\n", - " print(r'A[4,:] += A[5,:]')\n", - " A[4,:] += A[5,:]\n", + " if ev != 0.0:\n", + " print(r\"Gaussian elimination:\")\n", + " print(r\"A[0,:] += A[1,:]\")\n", + " A[0, :] += A[1, :]\n", + " print(r\"A[0,:] += A[2,:]\")\n", + " A[0, :] += A[2, :]\n", + " print(r\"Swap A[0,:] and A[11,:]\")\n", + " row = A[11, :]\n", + " A[11, :] = A[0, :]\n", + " A[0, :] = row\n", + " print(r\"A[3,:] += A[4,:]\")\n", + " A[3, :] += A[4, :]\n", + " print(r\"A[3,:] += A[5,:]\")\n", + " A[3, :] += A[5, :]\n", + " print(r\"Swap A[3,:] and A[10,:]\")\n", + " row = A[10, :]\n", + " A[10, :] = A[3, :]\n", + " A[3, :] = row\n", + " print(r\"A[0,:] += A[3,:]\")\n", + " A[0, :] += A[3, :]\n", + " print(r\"A[0,:] += A[9,:]\")\n", + " A[0, :] += A[9, :]\n", + " print(r\"Swap A[0,:] and A[9,:]\")\n", + " row = A[9, :]\n", + " A[9, :] = A[0, :]\n", + " A[0, :] = row\n", + " print(r\"A[6,:] += A[8,:]\")\n", + " A[6, :] += A[8, :]\n", + " print(r\"A[6,:] += A[7,:]\")\n", + " A[6, :] += A[7, :]\n", + " print(r\"Swap A[6,:] and A[8,:]\")\n", + " row = A[8, :]\n", + " A[8, :] = A[6, :]\n", + " A[6, :] = row\n", + " print(r\"A[6,:] += A[7,:]\")\n", + " A[6, :] += A[7, :]\n", + " print(r\"A[4,:] += A[5,:]\")\n", + " A[4, :] += A[5, :]\n", " A.simplify()\n", " display(A)\n", "\n", @@ -219,36 +220,36 @@ " v = A.nullspace()\n", " MX_eigenvects.append(v)\n", "\n", - " print(r'Eigenvectors:')\n", + " print(r\"Eigenvectors:\")\n", " display(v)\n", - " \n", + "\n", " # Store eigenpairs (eigenvalue, algebraic multiplicity, eigenvectors)\n", - " MX_eigenpairs.append((l, len(v), v))\n", - " \n", - " #print(r'Eigenpairs:')\n", - " #display(MX_eigenpairs)\n", + " MX_eigenpairs.append((ev, len(v), v))\n", + "\n", + " # print(r'Eigenpairs:')\n", + " # display(MX_eigenpairs)\n", "\n", " # Verify that the eigenpairs satisfy the characteristic equations\n", " for ep in MX_eigenpairs:\n", " for j in range(ep[1]):\n", " diff = MX * ep[2][j] - ep[0] * ep[2][j]\n", " diff.simplify()\n", - " if diff != zeros(DD,1):\n", - " print('The charcteristic equation is not verified for some eigenpairs')\n", + " if diff != zeros(DD, 1):\n", + " print(\"The charcteristic equation is not verified for some eigenpairs\")\n", " display(diff)\n", "\n", " # Define integration constants\n", " a = []\n", " b = []\n", " for i in range(DD):\n", - " an = r'a_{:d}'.format(i+1)\n", - " bn = r'b_{:d}'.format(i+1) \n", + " an = r\"a_{:d}\".format(i + 1)\n", + " bn = r\"b_{:d}\".format(i + 1)\n", " a.append(sp.symbols(an))\n", " b.append(sp.symbols(bn))\n", "\n", " # Set equations corresponding to initial conditions\n", " lhs_a = Xt(MX_eigenpairs, a, b, tn) - X\n", - " lhs_b = Xt(MX_eigenpairs, a, b, t ).diff(t).subs(t, tn) - dX_dt\n", + " lhs_b = Xt(MX_eigenpairs, a, b, t).diff(t).subs(t, tn) - dX_dt\n", "\n", " # Compute integration constants from initial conditions\n", " # (convert list of tuples to list using list comprehension)\n", @@ -258,7 +259,7 @@ " b = [item for el in b for item in el]\n", "\n", " # Evaluate solution at t = tn + dt\n", - " X_new = Xt(MX_eigenpairs, a, b, tn+dt).expand()\n", + " X_new = Xt(MX_eigenpairs, a, b, tn + dt).expand()\n", " for d in range(DD):\n", " for Eij in E:\n", " X_new[d] = X_new[d].collect(Eij)\n", @@ -272,12 +273,12 @@ " # Check correctness by taking *second* derivative\n", " # and comparing with initial right-hand side at time tn\n", " X_t = Xt(MX_eigenpairs, a, b, t)\n", - " diff = X_t.diff(t).diff(t).subs(t, tn).subs(om, c*knorm).expand() - d2X_dt2\n", + " diff = X_t.diff(t).diff(t).subs(t, tn).subs(om, c * knorm).expand() - d2X_dt2\n", " diff.simplify()\n", - " if diff != zeros(DD,1):\n", - " print('Integration in time failed')\n", + " if diff != zeros(DD, 1):\n", + " print(\"Integration in time failed\")\n", " display(diff)\n", - " \n", + "\n", " return X_t, X_new" ] }, @@ -334,121 +335,167 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "# indices 0 1 2 3 4 5 6 7 8\n", - "labels = ['xx', 'xy', 'xz', 'yx', 'yy', 'yz', 'zx', 'zy', 'zz']\n", + "labels = [\"xx\", \"xy\", \"xz\", \"yx\", \"yy\", \"yz\", \"zx\", \"zy\", \"zz\"]\n", "\n", "# E fields\n", - "Exx = sp.symbols(r'E_{xx}')\n", - "Exy = sp.symbols(r'E_{xy}')\n", - "Exz = sp.symbols(r'E_{xz}')\n", - "Eyx = sp.symbols(r'E_{yx}')\n", - "Eyy = sp.symbols(r'E_{yy}')\n", - "Eyz = sp.symbols(r'E_{yz}')\n", - "Ezx = sp.symbols(r'E_{zx}')\n", - "Ezy = sp.symbols(r'E_{zy}')\n", - "Ezz = sp.symbols(r'E_{zz}')\n", - "E = Matrix([[Exx],[Exy],[Exz],[Eyx],[Eyy],[Eyz],[Ezx],[Ezy],[Ezz]])\n", + "Exx = sp.symbols(r\"E_{xx}\")\n", + "Exy = sp.symbols(r\"E_{xy}\")\n", + "Exz = sp.symbols(r\"E_{xz}\")\n", + "Eyx = sp.symbols(r\"E_{yx}\")\n", + "Eyy = sp.symbols(r\"E_{yy}\")\n", + "Eyz = sp.symbols(r\"E_{yz}\")\n", + "Ezx = sp.symbols(r\"E_{zx}\")\n", + "Ezy = sp.symbols(r\"E_{zy}\")\n", + "Ezz = sp.symbols(r\"E_{zz}\")\n", + "E = Matrix([[Exx], [Exy], [Exz], [Eyx], [Eyy], [Eyz], [Ezx], [Ezy], [Ezz]])\n", "\n", "# B fields\n", - "Bxx = sp.symbols(r'B_{xx}')\n", - "Bxy = sp.symbols(r'B_{xy}')\n", - "Bxz = sp.symbols(r'B_{xz}')\n", - "Byx = sp.symbols(r'B_{yx}')\n", - "Byy = sp.symbols(r'B_{yy}')\n", - "Byz = sp.symbols(r'B_{yz}')\n", - "Bzx = sp.symbols(r'B_{zx}')\n", - "Bzy = sp.symbols(r'B_{zy}')\n", - "Bzz = sp.symbols(r'B_{zz}')\n", - "B = Matrix([[Bxx],[Bxy],[Bxz],[Byx],[Byy],[Byz],[Bzx],[Bzy],[Bzz]])\n", + "Bxx = sp.symbols(r\"B_{xx}\")\n", + "Bxy = sp.symbols(r\"B_{xy}\")\n", + "Bxz = sp.symbols(r\"B_{xz}\")\n", + "Byx = sp.symbols(r\"B_{yx}\")\n", + "Byy = sp.symbols(r\"B_{yy}\")\n", + "Byz = sp.symbols(r\"B_{yz}\")\n", + "Bzx = sp.symbols(r\"B_{zx}\")\n", + "Bzy = sp.symbols(r\"B_{zy}\")\n", + "Bzz = sp.symbols(r\"B_{zz}\")\n", + "B = Matrix([[Bxx], [Bxy], [Bxz], [Byx], [Byy], [Byz], [Bzx], [Bzy], [Bzz]])\n", "\n", "# F fields\n", - "Fx = sp.symbols(r'F_{x}')\n", - "Fy = sp.symbols(r'F_{y}')\n", - "Fz = sp.symbols(r'F_{z}')\n", - "F = Matrix([[Fx],[Fy],[Fz]])\n", + "Fx = sp.symbols(r\"F_{x}\")\n", + "Fy = sp.symbols(r\"F_{y}\")\n", + "Fz = sp.symbols(r\"F_{z}\")\n", + "F = Matrix([[Fx], [Fy], [Fz]])\n", "\n", "# G fields\n", - "Gx = sp.symbols(r'G_{x}')\n", - "Gy = sp.symbols(r'G_{y}')\n", - "Gz = sp.symbols(r'G_{z}')\n", - "G = Matrix([[Gx],[Gy],[Gz]])\n", + "Gx = sp.symbols(r\"G_{x}\")\n", + "Gy = sp.symbols(r\"G_{y}\")\n", + "Gz = sp.symbols(r\"G_{z}\")\n", + "G = Matrix([[Gx], [Gy], [Gz]])\n", "\n", "# dE/dt\n", - "dExx_dt = c**2 * I * kx * (Fx + Fy + Fz)\n", - "dExy_dt = c**2 * I * ky * (Bzx + Bzy + Bzz)\n", - "dExz_dt = - c**2 * I * kz * (Byx + Byy + Byz)\n", - "dEyx_dt = - c**2 * I * kx * (Bzx + Bzy + Bzz)\n", - "dEyy_dt = c**2 * I * ky * (Fx + Fy + Fz)\n", - "dEyz_dt = c**2 * I * kz * (Bxx + Bxy + Bxz)\n", - "dEzx_dt = c**2 * I * kx * (Byx + Byy + Byz)\n", - "dEzy_dt = - c**2 * I * ky * (Bxx + Bxy + Bxz)\n", - "dEzz_dt = c**2 * I * kz * (Fx + Fy + Fz)\n", - "dE_dt = Matrix([[dExx_dt],[dExy_dt],[dExz_dt],[dEyx_dt],[dEyy_dt],[dEyz_dt],[dEzx_dt],[dEzy_dt],[dEzz_dt]])\n", + "dExx_dt = c**2 * I * kx * (Fx + Fy + Fz)\n", + "dExy_dt = c**2 * I * ky * (Bzx + Bzy + Bzz)\n", + "dExz_dt = -(c**2) * I * kz * (Byx + Byy + Byz)\n", + "dEyx_dt = -(c**2) * I * kx * (Bzx + Bzy + Bzz)\n", + "dEyy_dt = c**2 * I * ky * (Fx + Fy + Fz)\n", + "dEyz_dt = c**2 * I * kz * (Bxx + Bxy + Bxz)\n", + "dEzx_dt = c**2 * I * kx * (Byx + Byy + Byz)\n", + "dEzy_dt = -(c**2) * I * ky * (Bxx + Bxy + Bxz)\n", + "dEzz_dt = c**2 * I * kz * (Fx + Fy + Fz)\n", + "dE_dt = Matrix(\n", + " [\n", + " [dExx_dt],\n", + " [dExy_dt],\n", + " [dExz_dt],\n", + " [dEyx_dt],\n", + " [dEyy_dt],\n", + " [dEyz_dt],\n", + " [dEzx_dt],\n", + " [dEzy_dt],\n", + " [dEzz_dt],\n", + " ]\n", + ")\n", "\n", "# dB/dt\n", - "dBxx_dt = I * kx * (Gx + Gy + Gz)\n", - "dBxy_dt = - I * ky * (Ezx + Ezy + Ezz)\n", - "dBxz_dt = I * kz * (Eyx + Eyy + Eyz)\n", - "dByx_dt = I * kx * (Ezx + Ezy + Ezz)\n", - "dByy_dt = I * ky * (Gx + Gy + Gz)\n", - "dByz_dt = - I * kz * (Exx + Exy + Exz)\n", - "dBzx_dt = - I * kx * (Eyx + Eyy + Eyz)\n", - "dBzy_dt = I * ky * (Exx + Exy + Exz)\n", - "dBzz_dt = I * kz * (Gx + Gy + Gz)\n", - "dB_dt = Matrix([[dBxx_dt],[dBxy_dt],[dBxz_dt],[dByx_dt],[dByy_dt],[dByz_dt],[dBzx_dt],[dBzy_dt],[dBzz_dt]])\n", + "dBxx_dt = I * kx * (Gx + Gy + Gz)\n", + "dBxy_dt = -I * ky * (Ezx + Ezy + Ezz)\n", + "dBxz_dt = I * kz * (Eyx + Eyy + Eyz)\n", + "dByx_dt = I * kx * (Ezx + Ezy + Ezz)\n", + "dByy_dt = I * ky * (Gx + Gy + Gz)\n", + "dByz_dt = -I * kz * (Exx + Exy + Exz)\n", + "dBzx_dt = -I * kx * (Eyx + Eyy + Eyz)\n", + "dBzy_dt = I * ky * (Exx + Exy + Exz)\n", + "dBzz_dt = I * kz * (Gx + Gy + Gz)\n", + "dB_dt = Matrix(\n", + " [\n", + " [dBxx_dt],\n", + " [dBxy_dt],\n", + " [dBxz_dt],\n", + " [dByx_dt],\n", + " [dByy_dt],\n", + " [dByz_dt],\n", + " [dBzx_dt],\n", + " [dBzy_dt],\n", + " [dBzz_dt],\n", + " ]\n", + ")\n", "\n", "# dF/dt\n", "dFx_dt = I * kx * (Exx + Exy + Exz)\n", "dFy_dt = I * ky * (Eyx + Eyy + Eyz)\n", "dFz_dt = I * kz * (Ezx + Ezy + Ezz)\n", - "dF_dt = Matrix([[dFx_dt],[dFy_dt],[dFz_dt]])\n", + "dF_dt = Matrix([[dFx_dt], [dFy_dt], [dFz_dt]])\n", "\n", "# dG/dt\n", "dGx_dt = c**2 * I * kx * (Bxx + Bxy + Bxz)\n", "dGy_dt = c**2 * I * ky * (Byx + Byy + Byz)\n", "dGz_dt = c**2 * I * kz * (Bzx + Bzy + Bzz)\n", - "dG_dt = Matrix([[dGx_dt],[dGy_dt],[dGz_dt]])\n", + "dG_dt = Matrix([[dGx_dt], [dGy_dt], [dGz_dt]])\n", "\n", "# d2E/dt2\n", - "d2Exx_dt2 = c**2 * I * kx * (dFx_dt + dFy_dt + dFz_dt)\n", - "d2Exy_dt2 = c**2 * I * ky * (dBzx_dt + dBzy_dt + dBzz_dt)\n", - "d2Exz_dt2 = - c**2 * I * kz * (dByx_dt + dByy_dt + dByz_dt)\n", - "d2Eyx_dt2 = - c**2 * I * kx * (dBzx_dt + dBzy_dt + dBzz_dt)\n", - "d2Eyy_dt2 = c**2 * I * ky * (dFx_dt + dFy_dt + dFz_dt)\n", - "d2Eyz_dt2 = c**2 * I * kz * (dBxx_dt + dBxy_dt + dBxz_dt)\n", - "d2Ezx_dt2 = c**2 * I * kx * (dByx_dt + dByy_dt + dByz_dt)\n", - "d2Ezy_dt2 = - c**2 * I * ky * (dBxx_dt + dBxy_dt + dBxz_dt)\n", - "d2Ezz_dt2 = c**2 * I * kz * (dFx_dt + dFy_dt + dFz_dt)\n", - "d2E_dt2 = Matrix([[d2Exx_dt2],[d2Exy_dt2],[d2Exz_dt2],[d2Eyx_dt2],[d2Eyy_dt2],[d2Eyz_dt2],[d2Ezx_dt2],[d2Ezy_dt2],[d2Ezz_dt2]])\n", + "d2Exx_dt2 = c**2 * I * kx * (dFx_dt + dFy_dt + dFz_dt)\n", + "d2Exy_dt2 = c**2 * I * ky * (dBzx_dt + dBzy_dt + dBzz_dt)\n", + "d2Exz_dt2 = -(c**2) * I * kz * (dByx_dt + dByy_dt + dByz_dt)\n", + "d2Eyx_dt2 = -(c**2) * I * kx * (dBzx_dt + dBzy_dt + dBzz_dt)\n", + "d2Eyy_dt2 = c**2 * I * ky * (dFx_dt + dFy_dt + dFz_dt)\n", + "d2Eyz_dt2 = c**2 * I * kz * (dBxx_dt + dBxy_dt + dBxz_dt)\n", + "d2Ezx_dt2 = c**2 * I * kx * (dByx_dt + dByy_dt + dByz_dt)\n", + "d2Ezy_dt2 = -(c**2) * I * ky * (dBxx_dt + dBxy_dt + dBxz_dt)\n", + "d2Ezz_dt2 = c**2 * I * kz * (dFx_dt + dFy_dt + dFz_dt)\n", + "d2E_dt2 = Matrix(\n", + " [\n", + " [d2Exx_dt2],\n", + " [d2Exy_dt2],\n", + " [d2Exz_dt2],\n", + " [d2Eyx_dt2],\n", + " [d2Eyy_dt2],\n", + " [d2Eyz_dt2],\n", + " [d2Ezx_dt2],\n", + " [d2Ezy_dt2],\n", + " [d2Ezz_dt2],\n", + " ]\n", + ")\n", "\n", "# d2B/dt2\n", - "d2Bxx_dt2 = I * kx * (dGx_dt + dGy_dt + dGz_dt)\n", - "d2Bxy_dt2 = - I * ky * (dEzx_dt + dEzy_dt + dEzz_dt)\n", - "d2Bxz_dt2 = I * kz * (dEyx_dt + dEyy_dt + dEyz_dt)\n", - "d2Byx_dt2 = I * kx * (dEzx_dt + dEzy_dt + dEzz_dt)\n", - "d2Byy_dt2 = I * ky * (dGx_dt + dGy_dt + dGz_dt)\n", - "d2Byz_dt2 = - I * kz * (dExx_dt + dExy_dt + dExz_dt)\n", - "d2Bzx_dt2 = - I * kx * (dEyx_dt + dEyy_dt + dEyz_dt)\n", - "d2Bzy_dt2 = I * ky * (dExx_dt + dExy_dt + dExz_dt)\n", - "d2Bzz_dt2 = I * kz * (dGx_dt + dGy_dt + dGz_dt)\n", - "d2B_dt2 = Matrix([[d2Bxx_dt2],[d2Bxy_dt2],[d2Bxz_dt2],[d2Byx_dt2],[d2Byy_dt2],[d2Byz_dt2],[d2Bzx_dt2],[d2Bzy_dt2],[d2Bzz_dt2]])\n", + "d2Bxx_dt2 = I * kx * (dGx_dt + dGy_dt + dGz_dt)\n", + "d2Bxy_dt2 = -I * ky * (dEzx_dt + dEzy_dt + dEzz_dt)\n", + "d2Bxz_dt2 = I * kz * (dEyx_dt + dEyy_dt + dEyz_dt)\n", + "d2Byx_dt2 = I * kx * (dEzx_dt + dEzy_dt + dEzz_dt)\n", + "d2Byy_dt2 = I * ky * (dGx_dt + dGy_dt + dGz_dt)\n", + "d2Byz_dt2 = -I * kz * (dExx_dt + dExy_dt + dExz_dt)\n", + "d2Bzx_dt2 = -I * kx * (dEyx_dt + dEyy_dt + dEyz_dt)\n", + "d2Bzy_dt2 = I * ky * (dExx_dt + dExy_dt + dExz_dt)\n", + "d2Bzz_dt2 = I * kz * (dGx_dt + dGy_dt + dGz_dt)\n", + "d2B_dt2 = Matrix(\n", + " [\n", + " [d2Bxx_dt2],\n", + " [d2Bxy_dt2],\n", + " [d2Bxz_dt2],\n", + " [d2Byx_dt2],\n", + " [d2Byy_dt2],\n", + " [d2Byz_dt2],\n", + " [d2Bzx_dt2],\n", + " [d2Bzy_dt2],\n", + " [d2Bzz_dt2],\n", + " ]\n", + ")\n", "\n", "# d2F/dt2\n", "d2Fx_dt2 = I * kx * (dExx_dt + dExy_dt + dExz_dt)\n", "d2Fy_dt2 = I * ky * (dEyx_dt + dEyy_dt + dEyz_dt)\n", "d2Fz_dt2 = I * kz * (dEzx_dt + dEzy_dt + dEzz_dt)\n", - "d2F_dt2 = Matrix([[d2Fx_dt2],[d2Fy_dt2],[d2Fz_dt2]])\n", + "d2F_dt2 = Matrix([[d2Fx_dt2], [d2Fy_dt2], [d2Fz_dt2]])\n", "\n", "# d2G/dt2\n", "d2Gx_dt2 = c**2 * I * kx * (dBxx_dt + dBxy_dt + dBxz_dt)\n", "d2Gy_dt2 = c**2 * I * ky * (dByx_dt + dByy_dt + dByz_dt)\n", "d2Gz_dt2 = c**2 * I * kz * (dBzx_dt + dBzy_dt + dBzz_dt)\n", - "d2G_dt2 = Matrix([[d2Gx_dt2],[d2Gy_dt2],[d2Gz_dt2]])\n", + "d2G_dt2 = Matrix([[d2Gx_dt2], [d2Gy_dt2], [d2Gz_dt2]])\n", "\n", "for i in range(dd):\n", " d2E_dt2[i] = sp.expand(d2E_dt2[i])\n", @@ -458,51 +505,51 @@ "\n", "for i in range(3):\n", " d2F_dt2[i] = sp.expand(d2F_dt2[i])\n", - " \n", + "\n", "for i in range(3):\n", " d2G_dt2[i] = sp.expand(d2G_dt2[i])\n", - " \n", + "\n", "# Extended array for E and G\n", - "EG = zeros(DD,1)\n", + "EG = zeros(DD, 1)\n", "for i in range(dd):\n", " EG[i] = E[i]\n", - "for i in range(dd,DD):\n", - " EG[i] = G[i-dd]\n", + "for i in range(dd, DD):\n", + " EG[i] = G[i - dd]\n", "\n", "# dEG/dt\n", - "dEG_dt = zeros(DD,1)\n", + "dEG_dt = zeros(DD, 1)\n", "for i in range(dd):\n", " dEG_dt[i] = dE_dt[i]\n", - "for i in range(dd,DD):\n", - " dEG_dt[i] = dG_dt[i-dd]\n", - " \n", + "for i in range(dd, DD):\n", + " dEG_dt[i] = dG_dt[i - dd]\n", + "\n", "# d2EG/dt2\n", - "d2EG_dt2 = zeros(DD,1)\n", + "d2EG_dt2 = zeros(DD, 1)\n", "for i in range(dd):\n", " d2EG_dt2[i] = d2E_dt2[i]\n", - "for i in range(dd,DD):\n", - " d2EG_dt2[i] = d2G_dt2[i-dd]\n", - " \n", + "for i in range(dd, DD):\n", + " d2EG_dt2[i] = d2G_dt2[i - dd]\n", + "\n", "# Extended array for B and F\n", - "BF = zeros(DD,1)\n", + "BF = zeros(DD, 1)\n", "for i in range(dd):\n", " BF[i] = B[i]\n", - "for i in range(dd,DD):\n", - " BF[i] = F[i-dd]\n", + "for i in range(dd, DD):\n", + " BF[i] = F[i - dd]\n", "\n", "# dBF/dt\n", - "dBF_dt = zeros(DD,1)\n", + "dBF_dt = zeros(DD, 1)\n", "for i in range(dd):\n", " dBF_dt[i] = dB_dt[i]\n", - "for i in range(dd,DD):\n", - " dBF_dt[i] = dF_dt[i-dd]\n", + "for i in range(dd, DD):\n", + " dBF_dt[i] = dF_dt[i - dd]\n", "\n", "# d2BF/dt2\n", - "d2BF_dt2 = zeros(DD,1)\n", + "d2BF_dt2 = zeros(DD, 1)\n", "for i in range(dd):\n", " d2BF_dt2[i] = d2B_dt2[i]\n", - "for i in range(dd,DD):\n", - " d2BF_dt2[i] = d2F_dt2[i-dd]" + "for i in range(dd, DD):\n", + " d2BF_dt2[i] = d2F_dt2[i - dd]" ] }, { @@ -515,30 +562,28 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ - "print(r'Solve equations for E and G:')\n", + "print(r\"Solve equations for E and G:\")\n", "EG_t, EG_new = evolve(EG, dEG_dt, d2EG_dt2)\n", "\n", - "print(r'Solve equations for B and F:')\n", + "print(r\"Solve equations for B and F:\")\n", "BF_t, BF_new = evolve(BF, dBF_dt, d2BF_dt2)\n", "\n", "# Check correctness by taking *first* derivative\n", "# and comparing with initial right-hand side at time tn\n", "# E,G\n", - "diff = EG_t.diff(t).subs(t, tn).subs(om, c*knorm).expand() - dEG_dt\n", + "diff = EG_t.diff(t).subs(t, tn).subs(om, c * knorm).expand() - dEG_dt\n", "diff.simplify()\n", - "if diff != zeros(DD,1):\n", - " print('Integration in time failed')\n", + "if diff != zeros(DD, 1):\n", + " print(\"Integration in time failed\")\n", " display(diff)\n", "# B,F\n", - "diff = BF_t.diff(t).subs(t, tn).subs(om, c*knorm).expand() - dBF_dt\n", + "diff = BF_t.diff(t).subs(t, tn).subs(om, c * knorm).expand() - dBF_dt\n", "diff.simplify()\n", - "if diff != zeros(DD,1):\n", - " print('Integration in time failed')\n", + "if diff != zeros(DD, 1):\n", + " print(\"Integration in time failed\")\n", " display(diff)" ] }, @@ -552,13 +597,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "# Code generation\n", - "from sympy.codegen.ast import Assignment\n", "\n", "# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\n", "# EG: Exx, Exy, Exz, Eyx, Eyy, Eyz, Ezx, Ezy, Ezz, Gx, Gy, Gz\n", @@ -570,22 +612,22 @@ "# Extract individual terms (right hand side)\n", "for i in range(DD):\n", " X = EG[i]\n", - " C = X_new.coeff(X, 1).simplify()\n", - " print(r'Coefficient multiplying ' + str(X))\n", - " display(C)\n", - " #print(ccode(Assignment(sp.symbols(r'LHS'), C)))\n", + " C1 = X_new.coeff(X, 1).simplify()\n", + " print(r\"Coefficient multiplying \" + str(X))\n", + " display(C1)\n", + " # print(ccode(Assignment(sp.symbols(r'LHS'), C1)))\n", "for i in range(DD):\n", " X = BF[i]\n", - " C = X_new.coeff(X, 1).simplify()\n", - " print(r'Coefficient multiplying ' + str(X))\n", - " display(C)\n", - " #print(ccode(Assignment(sp.symbols(r'LHS'), C)))" + " C2 = X_new.coeff(X, 1).simplify()\n", + " print(r\"Coefficient multiplying \" + str(X))\n", + " display(C2)\n", + " # print(ccode(Assignment(sp.symbols(r'LHS'), C2)))" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -599,7 +641,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.12.4" } }, "nbformat": 4, diff --git a/Tools/Algorithms/stencil.py b/Tools/Algorithms/stencil.py index dde7398daaa..2fe67d1c681 100644 --- a/Tools/Algorithms/stencil.py +++ b/Tools/Algorithms/stencil.py @@ -15,18 +15,19 @@ import os import sys -sys.path.append('../Parser/') +sys.path.append("../Parser/") import matplotlib.pyplot as plt import numpy as np from input_file_parser import parse_input_file from scipy.constants import c -plt.style.use('tableau-colorblind10') -plt.rcParams.update({'font.size': 14}) +plt.style.use("tableau-colorblind10") +plt.rcParams.update({"font.size": 14}) sp = np.finfo(np.float32).eps dp = np.finfo(np.float64).eps + def get_Fornberg_coeffs(order, staggered): """ Compute the centered or staggered Fornberg coefficients at finite order. @@ -43,24 +44,29 @@ def get_Fornberg_coeffs(order, staggered): coeffs : numpy.ndarray Array of centered or staggered Fornberg coefficients. """ - m = order//2 - coeffs = np.zeros(m+1) + m = order // 2 + coeffs = np.zeros(m + 1) # Compute Fornberg coefficients by recurrence if staggered: - prod = 1. - for k in range(1, m+1): - prod = prod*(m+k)/(4*k) - coeffs[0] = 4*m*prod**2 - for n in range(1, m+1): - coeffs[n] = -(((2*n-3)*(m+1-n))/((2*n-1)*(m-1+n))*coeffs[n-1]) + prod = 1.0 + for k in range(1, m + 1): + prod = prod * (m + k) / (4 * k) + coeffs[0] = 4 * m * prod**2 + for n in range(1, m + 1): + coeffs[n] = -( + ((2 * n - 3) * (m + 1 - n)) + / ((2 * n - 1) * (m - 1 + n)) + * coeffs[n - 1] + ) else: - coeffs[0] = -2. - for n in range(1, m+1): - coeffs[n] = -(m+1-n)/(m+n)*coeffs[n-1] + coeffs[0] = -2.0 + for n in range(1, m + 1): + coeffs[n] = -(m + 1 - n) / (m + n) * coeffs[n - 1] return coeffs + def modified_k(kx, dx, order, staggered): """ Compute the centered or staggered modified wave vector at finite order. @@ -81,24 +87,29 @@ def modified_k(kx, dx, order, staggered): k_mod : numpy.ndarray Centered or staggered modified wave vector. """ - m = order//2 + m = order // 2 coeffs = get_Fornberg_coeffs(order, staggered) # Array of values for n: from 1 to m - n = np.arange(1, m+1) + n = np.arange(1, m + 1) # Array of values of sin # (first axis corresponds to k and second axis to n) if staggered: - sin_kn = (np.sin(kx[:,np.newaxis]*(n[np.newaxis,:]-0.5)*dx)/((n[np.newaxis,:]-0.5)*dx)) + sin_kn = np.sin(kx[:, np.newaxis] * (n[np.newaxis, :] - 0.5) * dx) / ( + (n[np.newaxis, :] - 0.5) * dx + ) else: - sin_kn = (np.sin(kx[:,np.newaxis]*n[np.newaxis,:]*dx)/(n[np.newaxis,:]*dx)) + sin_kn = np.sin(kx[:, np.newaxis] * n[np.newaxis, :] * dx) / ( + n[np.newaxis, :] * dx + ) # Modified k - k_mod = np.tensordot(sin_kn, coeffs[1:], axes=(-1,-1)) + k_mod = np.tensordot(sin_kn, coeffs[1:], axes=(-1, -1)) return k_mod + def func_cosine(om, w_c, dt): """ Compute the leading spectral coefficient of the general PSATD equations: @@ -120,10 +131,11 @@ def func_cosine(om, w_c, dt): coeff : numpy.ndarray Leading spectral coefficient of the general PSATD equations. """ - theta_c = np.exp(1.j*w_c*dt*0.5) - coeff = theta_c**2*np.cos(om*dt) + theta_c = np.exp(1.0j * w_c * dt * 0.5) + coeff = theta_c**2 * np.cos(om * dt) return coeff + def compute_stencils(coeff_nodal, coeff_stagg, axis): """ Compute nodal and staggered stencils along a given direction. @@ -159,17 +171,20 @@ def compute_stencils(coeff_nodal, coeff_stagg, axis): # Average over the other two directions i1 = (axis + 1) % 3 i2 = (axis + 2) % 3 - stencil_avg_nodal = (stencil_nodal.sum(axis=(i1,i2)) / - (stencil_nodal.shape[i1]*stencil_nodal.shape[i2])) - stencil_avg_stagg = (stencil_stagg.sum(axis=(i1,i2)) / - (stencil_stagg.shape[i1]*stencil_stagg.shape[i2])) + stencil_avg_nodal = stencil_nodal.sum(axis=(i1, i2)) / ( + stencil_nodal.shape[i1] * stencil_nodal.shape[i2] + ) + stencil_avg_stagg = stencil_stagg.sum(axis=(i1, i2)) / ( + stencil_stagg.shape[i1] * stencil_stagg.shape[i2] + ) stencils = dict() - stencils['nodal'] = abs(stencil_avg_nodal) - stencils['stagg'] = abs(stencil_avg_stagg) + stencils["nodal"] = abs(stencil_avg_nodal) + stencils["stagg"] = abs(stencil_avg_stagg) return stencils + def compute_all(dx_boosted, dt, psatd_order, v_gal, nx=None): """ Compute nodal and staggered stencils along all directions. @@ -200,12 +215,12 @@ def compute_all(dx_boosted, dt, psatd_order, v_gal, nx=None): nx = np.full(shape=dims, fill_value=256) # k vectors and modified k vectors - k_arr = [] + k_arr = [] k_arr_c = [] k_arr_s = [] for i in range(dims): - k_arr.append(2*np.pi*np.fft.fftfreq(nx[i], dx_boosted[i])) - if psatd_order[i] != 'inf': + k_arr.append(2 * np.pi * np.fft.fftfreq(nx[i], dx_boosted[i])) + if psatd_order[i] != "inf": k_arr_c.append(modified_k(k_arr[i], dx_boosted[i], psatd_order[i], False)) k_arr_s.append(modified_k(k_arr[i], dx_boosted[i], psatd_order[i], True)) else: @@ -219,9 +234,9 @@ def compute_all(dx_boosted, dt, psatd_order, v_gal, nx=None): kk_s = np.sqrt(sum(k**2 for k in k_s)) # Frequencies - om_c = c*kk_c - om_s = c*kk_s - w_c = v_gal*k_c[-1] + om_c = c * kk_c + om_s = c * kk_s + w_c = v_gal * k_c[-1] # Spectral coefficient coeff_nodal = func_cosine(om_c, w_c, dt) @@ -234,6 +249,7 @@ def compute_all(dx_boosted, dt, psatd_order, v_gal, nx=None): return stencils + def compute_guard_cells(errmin, errmax, stencil): """ Compute the minimum number of guard cells for a given error threshold @@ -254,15 +270,16 @@ def compute_guard_cells(errmin, errmax, stencil): """ diff = stencil - errmin v = next(d for d in diff if d < 0) - gcmin = np.argwhere(diff == v)[0,0] + gcmin = np.argwhere(diff == v)[0, 0] diff = stencil - errmax try: v = next(d for d in diff if d < 0) - gcmax = np.argwhere(diff == v)[0,0] - 1 + gcmax = np.argwhere(diff == v)[0, 0] - 1 except StopIteration: - gcmin, gcmax = compute_guard_cells(errmin, errmax*10, stencil) + gcmin, gcmax = compute_guard_cells(errmin, errmax * 10, stencil) return (gcmin, gcmax) + def plot_stencil(cells, stencil_nodal, stencil_stagg, label, path, name): """ Plot stencil extent for nodal and staggered/hybrid solver, @@ -281,34 +298,37 @@ def plot_stencil(cells, stencil_nodal, stencil_stagg, label, path, name): name : str Label for figure name. """ - fig = plt.figure(figsize=[10,6]) + fig = plt.figure(figsize=[10, 6]) ax = fig.add_subplot(111) - ax.plot(cells, stencil_nodal, linestyle='-', label='nodal') - ax.plot(cells, stencil_stagg, linestyle='-', label='staggered or hybrid') + ax.plot(cells, stencil_nodal, linestyle="-", label="nodal") + ax.plot(cells, stencil_stagg, linestyle="-", label="staggered or hybrid") # Plot single and double precision machine epsilons - ax.axhline(y=sp, c='grey', ls='dashed', label='machine epsilon (single precision)') - ax.axhline(y=dp, c='grey', ls='dotted', label='machine epsilon (double precision)') + ax.axhline(y=sp, c="grey", ls="dashed", label="machine epsilon (single precision)") + ax.axhline(y=dp, c="grey", ls="dotted", label="machine epsilon (double precision)") # Shade regions between single and double precision machine epsilons xmin, xmax = compute_guard_cells(sp, dp, stencil_nodal) - ax.fill_between(cells[xmin:xmax+1], stencil_nodal[xmin:xmax+1], alpha=0.5) + ax.fill_between(cells[xmin : xmax + 1], stencil_nodal[xmin : xmax + 1], alpha=0.5) xmin, xmax = compute_guard_cells(sp, dp, stencil_stagg) - ax.fill_between(cells[xmin:xmax+1], stencil_stagg[xmin:xmax+1], alpha=0.5) + ax.fill_between(cells[xmin : xmax + 1], stencil_stagg[xmin : xmax + 1], alpha=0.5) # - ax.set_yscale('log') + ax.set_yscale("log") ax.set_xticks(cells, minor=True) - ax.grid(which='minor', linewidth=0.2) - ax.grid(which='major', linewidth=0.4) + ax.grid(which="minor", linewidth=0.2) + ax.grid(which="major", linewidth=0.4) ax.legend() - ax.set_xlabel('number of cells') - ax.set_ylabel('signal to be truncated') - ax.set_title(r'Stencil extent along ${:s}$'.format(label)) + ax.set_xlabel("number of cells") + ax.set_ylabel("signal to be truncated") + ax.set_title(r"Stencil extent along ${:s}$".format(label)) fig.tight_layout() - fig_name = os.path.join(path, 'figure_stencil_' + label) + fig_name = os.path.join(path, "figure_stencil_" + label) if name: - fig_name += '_' + name - fig.savefig(fig_name + '.png', dpi=150) + fig_name += "_" + name + fig.savefig(fig_name + ".png", dpi=150) + -def run_main(dims, dx_boosted, dt, psatd_order, gamma=1., galilean=False, path='.', name=''): +def run_main( + dims, dx_boosted, dt, psatd_order, gamma=1.0, galilean=False, path=".", name="" +): """ Main function. @@ -333,44 +353,44 @@ def run_main(dims, dx_boosted, dt, psatd_order, gamma=1., galilean=False, path=' """ # Galilean velocity (default = 0.) - v_gal = 0. + v_gal = 0.0 if galilean: - v_gal = -np.sqrt(1.-1./gamma**2)*c + v_gal = -np.sqrt(1.0 - 1.0 / gamma**2) * c # Display some output - print('\nCell size:') - print(f'- dx = {dx_boosted}') + print("\nCell size:") + print(f"- dx = {dx_boosted}") if dims > 1: - print(f'- dx[1:]/dx[0] = {dx_boosted[1:]/dx_boosted[0]}') - print('\nTime step:') - print(f'- dt = {dt}') - print(f'- c*dt/dx = {c*dt/dx_boosted}') - print('\nSpectral order:') - print(f'- order = {psatd_order}') - print('\nLorentz boost, Galilean velocity:') - print(f'- gamma = {gamma}') - print(f'- v_gal = {v_gal}') + print(f"- dx[1:]/dx[0] = {dx_boosted[1:]/dx_boosted[0]}") + print("\nTime step:") + print(f"- dt = {dt}") + print(f"- c*dt/dx = {c*dt/dx_boosted}") + print("\nSpectral order:") + print(f"- order = {psatd_order}") + print("\nLorentz boost, Galilean velocity:") + print(f"- gamma = {gamma}") + print(f"- v_gal = {v_gal}") stencils = compute_all(dx_boosted, dt, psatd_order, v_gal) # Maximum number of cells - nc = dims*[65] + nc = dims * [65] # Arrays of stencils for i, s in enumerate(stencils): - s['nodal'] = s['nodal'][:nc[i]] - s['stagg'] = s['stagg'][:nc[i]] + s["nodal"] = s["nodal"][: nc[i]] + s["stagg"] = s["stagg"][: nc[i]] # Axis labels - label = ['x'] + label = ["x"] if dims == 3: - label.append('y') + label.append("y") if dims > 1: - label.append('z') + label.append("z") # Plot stencils for i, s in enumerate(stencils): - plot_stencil(np.arange(nc[i]), s['nodal'], s['stagg'], label[i], path, name) + plot_stencil(np.arange(nc[i]), s["nodal"], s["stagg"], label[i], path, name) # Compute min and max numbers of guard cells gcmin_nodal = [] @@ -378,38 +398,46 @@ def run_main(dims, dx_boosted, dt, psatd_order, gamma=1., galilean=False, path=' gcmin_stagg = [] gcmax_stagg = [] for s in stencils: - gcmin, gcmax = compute_guard_cells(sp, dp, s['nodal']) + gcmin, gcmax = compute_guard_cells(sp, dp, s["nodal"]) gcmin_nodal.append(gcmin) gcmax_nodal.append(gcmax) - gcmin, gcmax = compute_guard_cells(sp, dp, s['stagg']) + gcmin, gcmax = compute_guard_cells(sp, dp, s["stagg"]) gcmin_stagg.append(gcmin) gcmax_stagg.append(gcmax) fig_path = os.path.abspath(path) - print(f'\nFigures saved in {fig_path}/.') - print('\nThe plots show the extent of the signal to be truncated (y-axis)' - + '\nby choosing a given number of cells (x-axis) for the ghost regions' - + '\nof each simulation grid, along x, y, and z.') - print('\nIt is recommended to choose a number of ghost cells that corresponds to' - + '\na truncation of the signal between single and double machine precision.' - + '\nThe more ghost cells, the more accurate, yet expensive, results.' - + '\nFor each stencil the region of accuracy between single and double precision' - + '\nis shaded to help you identify a suitable number of ghost cells.') - print('\nFor a nodal simulation, choose:') + print(f"\nFigures saved in {fig_path}/.") + print( + "\nThe plots show the extent of the signal to be truncated (y-axis)" + + "\nby choosing a given number of cells (x-axis) for the ghost regions" + + "\nof each simulation grid, along x, y, and z." + ) + print( + "\nIt is recommended to choose a number of ghost cells that corresponds to" + + "\na truncation of the signal between single and double machine precision." + + "\nThe more ghost cells, the more accurate, yet expensive, results." + + "\nFor each stencil the region of accuracy between single and double precision" + + "\nis shaded to help you identify a suitable number of ghost cells." + ) + print("\nFor a nodal simulation, choose:") for i in range(dims): - print(f'- between {gcmin_nodal[i]} and {gcmax_nodal[i]} ghost cells along {label[i]}') - print('\nFor a staggered or hybrid simulation, choose:') + print( + f"- between {gcmin_nodal[i]} and {gcmax_nodal[i]} ghost cells along {label[i]}" + ) + print("\nFor a staggered or hybrid simulation, choose:") for i in range(dims): - print(f'- between {gcmin_stagg[i]} and {gcmax_stagg[i]} ghost cells along {label[i]}') + print( + f"- between {gcmin_stagg[i]} and {gcmax_stagg[i]} ghost cells along {label[i]}" + ) print() return -if __name__ == '__main__': +if __name__ == "__main__": # Parse path to input file from command line parser = argparse.ArgumentParser() - parser.add_argument('--input_file', help='path to input file to be parsed') + parser.add_argument("--input_file", help="path to input file to be parsed") args = parser.parse_args() input_file = args.input_file @@ -417,45 +445,45 @@ def run_main(dims, dx_boosted, dt, psatd_order, gamma=1., galilean=False, path=' input_dict = parse_input_file(input_file) # TODO Handle RZ - dims = int(input_dict['geometry.dims'][0]) + dims = int(input_dict["geometry.dims"][0]) # Notation considering x as vector of coordinates (x,y,z) - nx = np.array([int(w) for w in input_dict['amr.n_cell']]) - xmin = np.array([float(w) for w in input_dict['geometry.prob_lo']]) - xmax = np.array([float(w) for w in input_dict['geometry.prob_hi']]) + nx = np.array([int(w) for w in input_dict["amr.n_cell"]]) + xmin = np.array([float(w) for w in input_dict["geometry.prob_lo"]]) + xmax = np.array([float(w) for w in input_dict["geometry.prob_hi"]]) # Cell size in the lab frame and boosted frame (boost along z) ## lab frame - dx = (xmax-xmin) / nx + dx = (xmax - xmin) / nx ## boosted frame - gamma = 1. - if 'warpx.gamma_boost' in input_dict: - gamma = float(input_dict['warpx.gamma_boost'][0]) - beta = np.sqrt(1. - 1./gamma**2) + gamma = 1.0 + if "warpx.gamma_boost" in input_dict: + gamma = float(input_dict["warpx.gamma_boost"][0]) + beta = np.sqrt(1.0 - 1.0 / gamma**2) dx_boosted = np.copy(dx) - dx_boosted[-1] = (1. + beta) * gamma * dx[-1] + dx_boosted[-1] = (1.0 + beta) * gamma * dx[-1] # Time step for pseudo-spectral scheme cfl = 0.999 - if 'warpx.cfl' in input_dict: - cfl = float(input_dict['warpx.cfl'][0]) + if "warpx.cfl" in input_dict: + cfl = float(input_dict["warpx.cfl"][0]) dt = cfl * np.min(dx_boosted) / c # Pseudo-spectral order psatd_order = np.full(shape=dims, fill_value=16) - if 'psatd.nox' in input_dict: - psatd_order[0] = int(input_dict['psatd.nox'][0]) - if 'psatd.noy' in input_dict: - psatd_order[1] = int(input_dict['psatd.noy'][0]) - if 'psatd.noz' in input_dict: - psatd_order[-1] = int(input_dict['psatd.noz'][0]) + if "psatd.nox" in input_dict: + psatd_order[0] = int(input_dict["psatd.nox"][0]) + if "psatd.noy" in input_dict: + psatd_order[1] = int(input_dict["psatd.noy"][0]) + if "psatd.noz" in input_dict: + psatd_order[-1] = int(input_dict["psatd.noz"][0]) # Galilean flag galilean = False - if 'psatd.use_default_v_galilean' in input_dict: - galilean = bool(input_dict['psatd.use_default_v_galilean'][0]) - if 'psatd.v_galilean' in input_dict: - galilean = bool(input_dict['psatd.v_galilean'][-1]) + if "psatd.use_default_v_galilean" in input_dict: + galilean = bool(input_dict["psatd.use_default_v_galilean"][0]) + if "psatd.v_galilean" in input_dict: + galilean = bool(input_dict["psatd.v_galilean"][-1]) # Run main function (some arguments are optional, # see definition of run_main function for help) diff --git a/Tools/Ascent/ascent_replay_warpx.ipynb b/Tools/Ascent/ascent_replay_warpx.ipynb index 636e9721c74..e9361d298de 100644 --- a/Tools/Ascent/ascent_replay_warpx.ipynb +++ b/Tools/Ascent/ascent_replay_warpx.ipynb @@ -14,14 +14,12 @@ "metadata": {}, "outputs": [], "source": [ + "import glob\n", + "\n", + "import ascent\n", "import conduit\n", "import conduit.blueprint\n", - "import conduit.relay\n", - "import ascent\n", - "\n", - "from IPython.display import Image\n", - "\n", - "import glob" + "import conduit.relay" ] }, { @@ -30,7 +28,7 @@ "metadata": {}, "outputs": [], "source": [ - "#print(conduit.about())" + "# print(conduit.about())" ] }, { @@ -85,8 +83,10 @@ "# we publish this data now once to visualize it in multiple ways below\n", "a = ascent.Ascent()\n", "opts = conduit.Node()\n", - "opts[\"actions_file\"] = \"\" # work-around: ascent_actions.yaml file must not overwrite our replay action\n", - "#opts[\"exceptions\"] = \"forward\"\n", + "opts[\"actions_file\"] = (\n", + " \"\" # work-around: ascent_actions.yaml file must not overwrite our replay action\n", + ")\n", + "# opts[\"exceptions\"] = \"forward\"\n", "a.open(opts)\n", "a.publish(data)" ] diff --git a/Tools/DevUtils/compare_wx_w_3d.ipynb b/Tools/DevUtils/compare_wx_w_3d.ipynb index d4b0520dd36..7d59554ed23 100644 --- a/Tools/DevUtils/compare_wx_w_3d.ipynb +++ b/Tools/DevUtils/compare_wx_w_3d.ipynb @@ -23,16 +23,14 @@ "outputs": [], "source": [ "# Import statements\n", - "import sys\n", - "from tqdm import tqdm\n", - "import yt, glob\n", + "import glob\n", + "\n", + "import yt\n", + "\n", "yt.funcs.mylog.setLevel(50)\n", - "from IPython.display import clear_output\n", - "import numpy as np\n", - "from ipywidgets import interact, RadioButtons, IntSlider\n", - "from openpmd_viewer import OpenPMDTimeSeries\n", - "from yt.units import volt\n", "import matplotlib.pyplot as plt\n", + "from ipywidgets import IntSlider, RadioButtons, interact\n", + "\n", "%matplotlib" ] }, @@ -45,9 +43,11 @@ "outputs": [], "source": [ "# Define path way for WarpX results and find iterations\n", - "path_warpx = '/Users/mthevenet/warpX_directory/res_warpx/valid_pwfa/'\n", - "file_list_warpx = glob.glob(path_warpx + 'plt?????')\n", - "iterations_warpx = [ int(file_name[len(file_name)-5:]) for file_name in file_list_warpx ]" + "path_warpx = \"/Users/mthevenet/warpX_directory/res_warpx/valid_pwfa/\"\n", + "file_list_warpx = glob.glob(path_warpx + \"plt?????\")\n", + "iterations_warpx = [\n", + " int(file_name[len(file_name) - 5 :]) for file_name in file_list_warpx\n", + "]" ] }, { @@ -59,9 +59,12 @@ "outputs": [], "source": [ "# Define path way for Warp results and find iterations\n", - "path_warp = '/Users/mthevenet/warp_results/valid_pwfa/'\n", - "file_list_warp = glob.glob(path_warp + 'diags/hdf5/data????????.h5')\n", - "iterations_warp = [ int(file_name[len(file_name)-11:len(file_name)-3]) for file_name in file_list_warp ]" + "path_warp = \"/Users/mthevenet/warp_results/valid_pwfa/\"\n", + "file_list_warp = glob.glob(path_warp + \"diags/hdf5/data????????.h5\")\n", + "iterations_warp = [\n", + " int(file_name[len(file_name) - 11 : len(file_name) - 3])\n", + " for file_name in file_list_warp\n", + "]" ] }, { @@ -81,89 +84,104 @@ }, "outputs": [], "source": [ - "def plot_field( iteration, field, slicing_direction='y'):\n", - " \n", + "def plot_field(iteration, field, slicing_direction=\"y\"):\n", " # First dataset\n", - " ds = yt.load( path_warpx + '/plt%05d/' %iteration )\n", - " all_data_level_0 = ds.covering_grid(level=0, \n", - " left_edge=ds.domain_left_edge, dims=ds.domain_dimensions)\n", - " \n", + " ds = yt.load(path_warpx + \"/plt%05d/\" % iteration)\n", + " all_data_level_0 = ds.covering_grid(\n", + " level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions\n", + " )\n", + "\n", " # Second dataset\n", - "# ts = OpenPMDTimeSeries(path_warp + 'diags/hdf5/') \n", - " ds2 = yt.load( path_warp + 'diags/hdf5/data%08d.h5' %iteration )\n", - " all_data_level_02 = ds2.covering_grid(level=0, \n", - " left_edge=ds2.domain_left_edge, dims=ds2.domain_dimensions)\n", + " # ts = OpenPMDTimeSeries(path_warp + 'diags/hdf5/')\n", + " ds2 = yt.load(path_warp + \"diags/hdf5/data%08d.h5\" % iteration)\n", + " all_data_level_02 = ds2.covering_grid(\n", + " level=0, left_edge=ds2.domain_left_edge, dims=ds2.domain_dimensions\n", + " )\n", "\n", " # first dataset loaded via yt\n", - " left_edge = ds.domain_left_edge.convert_to_mks()*1e6\n", - " right_edge = ds.domain_right_edge.convert_to_mks()*1e6\n", - " if slicing_direction == 'x':\n", - " n = int( ds.domain_dimensions[0]//2 )\n", + " left_edge = ds.domain_left_edge.convert_to_mks() * 1e6\n", + " right_edge = ds.domain_right_edge.convert_to_mks() * 1e6\n", + " if slicing_direction == \"x\":\n", + " n = int(ds.domain_dimensions[0] // 2)\n", " data2d = all_data_level_0[field][n, :, :]\n", - " extent = [ left_edge[2], right_edge[2], left_edge[1], right_edge[1] ]\n", - " elif slicing_direction == 'y':\n", - " n = int( ds.domain_dimensions[1]//2 )\n", + " extent = [left_edge[2], right_edge[2], left_edge[1], right_edge[1]]\n", + " elif slicing_direction == \"y\":\n", + " n = int(ds.domain_dimensions[1] // 2)\n", " data2d = all_data_level_0[field][:, n, :]\n", - " extent = [ left_edge[2], right_edge[2], left_edge[0], right_edge[0] ]\n", - " elif slicing_direction == 'z':\n", - " n = int( ds.domain_dimensions[2]//2 )\n", + " extent = [left_edge[2], right_edge[2], left_edge[0], right_edge[0]]\n", + " elif slicing_direction == \"z\":\n", + " n = int(ds.domain_dimensions[2] // 2)\n", " data2d = all_data_level_0[field][:, :, n]\n", - " extent = [ left_edge[1], right_edge[1], left_edge[0], right_edge[0] ]\n", + " extent = [left_edge[1], right_edge[1], left_edge[0], right_edge[0]]\n", "\n", " # second dataset loaded via yt\n", - " left_edge = ds2.domain_left_edge.convert_to_mks()*1e6\n", - " right_edge = ds2.domain_right_edge.convert_to_mks()*1e6\n", - " field_reformat = field[0].upper() + '_' + field[1]\n", - " if slicing_direction == 'x':\n", - " n = int( ds2.domain_dimensions[0]//2 )\n", + " left_edge = ds2.domain_left_edge.convert_to_mks() * 1e6\n", + " right_edge = ds2.domain_right_edge.convert_to_mks() * 1e6\n", + " field_reformat = field[0].upper() + \"_\" + field[1]\n", + " if slicing_direction == \"x\":\n", + " n = int(ds2.domain_dimensions[0] // 2)\n", " data2d2 = all_data_level_02[field_reformat][n, :, :]\n", - " extent2 = [ left_edge[2], right_edge[2], left_edge[1], right_edge[1] ]\n", - " elif slicing_direction == 'y':\n", - " n = int( ds2.domain_dimensions[1]//2 )\n", + " extent2 = [left_edge[2], right_edge[2], left_edge[1], right_edge[1]]\n", + " elif slicing_direction == \"y\":\n", + " n = int(ds2.domain_dimensions[1] // 2)\n", " data2d2 = all_data_level_02[field_reformat][:, n, :]\n", - " extent2 = [ left_edge[2], right_edge[2], left_edge[0], right_edge[0] ]\n", - " elif slicing_direction == 'z':\n", - " n = int( ds2.domain_dimensions[2]//2 )\n", + " extent2 = [left_edge[2], right_edge[2], left_edge[0], right_edge[0]]\n", + " elif slicing_direction == \"z\":\n", + " n = int(ds2.domain_dimensions[2] // 2)\n", " data2d2 = all_data_level_02[field_reformat][:, :, n]\n", - " extent2 = [ left_edge[1], right_edge[1], left_edge[0], right_edge[0] ]\n", + " extent2 = [left_edge[1], right_edge[1], left_edge[0], right_edge[0]]\n", "\n", - " if slicing_direction == 'x':\n", - " yaxis_label = 'y'\n", - " if slicing_direction == 'y':\n", - " yaxis_label = 'x'\n", - " if slicing_direction == 'z':\n", - " yaxis_label = 'y'\n", + " if slicing_direction == \"x\":\n", + " yaxis_label = \"y\"\n", + " if slicing_direction == \"y\":\n", + " yaxis_label = \"x\"\n", + " if slicing_direction == \"z\":\n", + " yaxis_label = \"y\"\n", "\n", - "# xlim = [5,25]\n", - "# ylim = [-20,20]\n", + " xlim = [extent[0], extent[1]]\n", + " ylim = [extent[2], extent[3]]\n", "\n", " plt.clf()\n", " # first dataset\n", - " plt.subplot(2,1,1)\n", - " plt.title(\"WarpX %s at iteration %d\" %(field, iteration) )\n", - " plt.imshow( data2d, interpolation='nearest', cmap='viridis',\n", - " origin='lower', extent=extent, aspect='auto')\n", - " plt.ylabel(yaxis_label + ' (um)')\n", + " plt.subplot(2, 1, 1)\n", + " plt.title(\"WarpX %s at iteration %d\" % (field, iteration))\n", + " plt.imshow(\n", + " data2d,\n", + " interpolation=\"nearest\",\n", + " cmap=\"viridis\",\n", + " origin=\"lower\",\n", + " extent=extent,\n", + " aspect=\"auto\",\n", + " )\n", + " plt.ylabel(yaxis_label + \" (um)\")\n", " vmin, vmax = plt.gci().get_clim()\n", " plt.colorbar()\n", - " if 'xlim' in locals():\n", + " if \"xlim\" in locals():\n", " plt.xlim(xlim)\n", - " if 'ylim' in locals():\n", + " if \"ylim\" in locals():\n", " plt.ylim(ylim)\n", " plt.xticks([])\n", - " \n", + "\n", " # second dataset\n", - " plt.subplot(2,1,2)\n", - " plt.title(\"Warp %s at iteration %d\" %(field, iteration) )\n", - " plt.imshow( data2d2, interpolation='nearest', cmap='viridis',\n", - " origin='lower', extent=extent2, aspect='auto',vmin=vmin,vmax=vmax)\n", + " plt.subplot(2, 1, 2)\n", + " plt.title(\"Warp %s at iteration %d\" % (field, iteration))\n", + " plt.imshow(\n", + " data2d2,\n", + " interpolation=\"nearest\",\n", + " cmap=\"viridis\",\n", + " origin=\"lower\",\n", + " extent=extent2,\n", + " aspect=\"auto\",\n", + " vmin=vmin,\n", + " vmax=vmax,\n", + " )\n", " plt.colorbar()\n", - " if 'xlim' in locals():\n", + " if \"xlim\" in locals():\n", " plt.xlim(xlim)\n", - " if 'ylim' in locals():\n", + " if \"ylim\" in locals():\n", " plt.ylim(ylim)\n", - " plt.xlabel('z (um)')\n", - " plt.ylabel(yaxis_label + ' (um)')" + " plt.xlabel(\"z (um)\")\n", + " plt.ylabel(yaxis_label + \" (um)\")" ] }, { @@ -182,10 +200,14 @@ "outputs": [], "source": [ "iterations = iterations_warp\n", - "interact(plot_field, \n", - " iteration = IntSlider(min=min(iterations), max=max(iterations), step=iterations[1]-iterations[0]),\n", - " field = RadioButtons( options=['jx', 'jy', 'jz', 'Ex', 'Ey', 'Ez'], value='jx'),\n", - " slicing_direction = RadioButtons( options=[ 'x', 'y', 'z'], value='x'))" + "interact(\n", + " plot_field,\n", + " iteration=IntSlider(\n", + " min=min(iterations), max=max(iterations), step=iterations[1] - iterations[0]\n", + " ),\n", + " field=RadioButtons(options=[\"jx\", \"jy\", \"jz\", \"Ex\", \"Ey\", \"Ez\"], value=\"jx\"),\n", + " slicing_direction=RadioButtons(options=[\"x\", \"y\", \"z\"], value=\"x\"),\n", + ")" ] }, { diff --git a/Tools/DevUtils/compute_domain.py b/Tools/DevUtils/compute_domain.py index b54412639bd..d54ef2abad4 100644 --- a/Tools/DevUtils/compute_domain.py +++ b/Tools/DevUtils/compute_domain.py @@ -6,7 +6,7 @@ import numpy as np -''' +""" This Python script helps a user to parallelize a WarpX simulation. The user specifies the minimal size of the physical domain and the resolution @@ -22,96 +22,106 @@ Note that the script has no notion of blocking_factor. It is assumed that blocking_factor = max_grid_size, and that all boxes have the same size. -''' +""" # Update the lines below for your simulation # ------------------------------------------ # 2 elements for 2D, 3 elements for 3D # Lower corner of the box -box_lo0 = np.array([-25.e-6, -25.e-6, -15.e-6]) +box_lo0 = np.array([-25.0e-6, -25.0e-6, -15.0e-6]) # Upper corner of the box -box_hi0 = np.array([ 25.e-6, 25.e-6, 60.e-6]) +box_hi0 = np.array([25.0e-6, 25.0e-6, 60.0e-6]) # Cell size -dx = 1.e-6 +dx = 1.0e-6 dz = dx cell_size = np.array([dx, dx, dz]) # Use this for simulations in a boosted frame if you # want to enforce dz < dx / dx_over_dz_boosted_frame compute_dz_boosted_frame = True -gamma_boost = 30. -dx_over_dz_boosted_frame = 1.1 # >1. is usually more stable +gamma_boost = 30.0 +dx_over_dz_boosted_frame = 1.1 # >1. is usually more stable # ------------------------------------------ + # similar to numpy.ceil, except the output data type is int def intceil(num): return np.ceil(num).astype(int) + # Enlarge simulation boundaries to satisfy three conditions: # - The resolution must be exactly the one provided by the user # - The physical domain must cover the domain specified by box_lo0, box_hi0 # - The number of cells must be a multiple of mgs (max_grid_size). def adjust_bounds(box_lo0, box_hi0, box_ncell0, mgs): - cell_size = (box_hi0-box_lo0) / box_ncell0 - box_ncell = intceil(box_ncell0/mgs)*mgs + cell_size = (box_hi0 - box_lo0) / box_ncell0 + box_ncell = intceil(box_ncell0 / mgs) * mgs box_lo = box_ncell * cell_size * box_lo0 / (box_hi0 - box_lo0) box_hi = box_ncell * cell_size * box_hi0 / (box_hi0 - box_lo0) return box_lo, box_hi, box_ncell + # Calculate parallelization for the simulation, given numerical parameters # (number of cells, max_grid_size, number of threads per node etc.) -def nb_nodes_mpi(box_ncell,mgs,threadspernode,ompnumthreads,ngridpernode, ndim): - nmpipernode = threadspernode/ompnumthreads - ngridpermpi = ngridpernode/nmpipernode - box_ngrids = box_ncell/mgs +def nb_nodes_mpi(box_ncell, mgs, threadspernode, ompnumthreads, ngridpernode, ndim): + nmpipernode = threadspernode / ompnumthreads + ngridpermpi = ngridpernode / nmpipernode + box_ngrids = box_ncell / mgs if ndim == 2: ngrids = box_ngrids[0] * box_ngrids[1] elif ndim == 3: ngrids = np.prod(box_ngrids) - n_mpi = intceil( ngrids/ngridpermpi ) - n_node = intceil( n_mpi/nmpipernode ) + n_mpi = intceil(ngrids / ngridpermpi) + n_node = intceil(n_mpi / nmpipernode) return n_node, n_mpi + # Get number of dimensions (2 or 3) ndim = box_lo0.size if compute_dz_boosted_frame: # Adjust dz so that dx/dz = dx_over_dz_boosted_frame in simulation frame - cell_size[-1] = cell_size[0] / dx_over_dz_boosted_frame / 2. / gamma_boost + cell_size[-1] = cell_size[0] / dx_over_dz_boosted_frame / 2.0 / gamma_boost # Given the resolution, compute number of cells a priori -box_ncell0 = ( box_hi0 - box_lo0 ) / cell_size +box_ncell0 = (box_hi0 - box_lo0) / cell_size if ndim == 2: # Set of parameters suitable for a 2D simulation on Cori KNL - ngridpernode = 16. - ompnumthreads = 8. - mgs = 1024. - threadspernode = 64. # HyperThreading level = 1: no hyperthreading - distance_between_threads = int(68*4/threadspernode) - c_option = int( ompnumthreads*distance_between_threads ) + ngridpernode = 16.0 + ompnumthreads = 8.0 + mgs = 1024.0 + threadspernode = 64.0 # HyperThreading level = 1: no hyperthreading + distance_between_threads = int(68 * 4 / threadspernode) + c_option = int(ompnumthreads * distance_between_threads) elif ndim == 3: # Set of parameters suitable for a 3D simulation on Cori KNL - ngridpernode = 8. - ompnumthreads = 8. - mgs = 64. - threadspernode = 64. # HyperThreading level = 1: no hyperthreading - distance_between_threads = int(68*4/threadspernode) - c_option = int( ompnumthreads*distance_between_threads ) + ngridpernode = 8.0 + ompnumthreads = 8.0 + mgs = 64.0 + threadspernode = 64.0 # HyperThreading level = 1: no hyperthreading + distance_between_threads = int(68 * 4 / threadspernode) + c_option = int(ompnumthreads * distance_between_threads) # Adjust simulation bounds box_lo, box_hi, box_ncell = adjust_bounds(box_lo0, box_hi0, box_ncell0, mgs) # Calculate parallelization -n_node,n_mpi = nb_nodes_mpi(box_ncell, mgs, threadspernode, ompnumthreads, ngridpernode, ndim) +n_node, n_mpi = nb_nodes_mpi( + box_ncell, mgs, threadspernode, ompnumthreads, ngridpernode, ndim +) # Print results -string_output = ' ### Parameters used ### \n' -string_output += 'ngridpernode = ' + str(ngridpernode) + '\n' -string_output += 'ompnumthreads = ' + str(ompnumthreads) + '\n' -string_output += 'mgs (max_grid_size) = ' + str(mgs) + '\n' -string_output += 'threadspernode ( = # MPI ranks per node * OMP_NUM_THREADS) = ' + str(threadspernode) + '\n' -string_output += 'ndim = ' + str(ndim) + '\n\n' -string_output += 'box_lo = ' + str(box_lo) + '\n' -string_output += 'box_hi = ' + str(box_hi) + '\n' -string_output += 'box_ncell = ' + str(box_ncell) + '\n' -string_output += 'n_node = ' + str(n_node) + '\n' -string_output += 'n_mpi = ' + str(n_mpi) + '\n' +string_output = " ### Parameters used ### \n" +string_output += "ngridpernode = " + str(ngridpernode) + "\n" +string_output += "ompnumthreads = " + str(ompnumthreads) + "\n" +string_output += "mgs (max_grid_size) = " + str(mgs) + "\n" +string_output += ( + "threadspernode ( = # MPI ranks per node * OMP_NUM_THREADS) = " + + str(threadspernode) + + "\n" +) +string_output += "ndim = " + str(ndim) + "\n\n" +string_output += "box_lo = " + str(box_lo) + "\n" +string_output += "box_hi = " + str(box_hi) + "\n" +string_output += "box_ncell = " + str(box_ncell) + "\n" +string_output += "n_node = " + str(n_node) + "\n" +string_output += "n_mpi = " + str(n_mpi) + "\n" print(string_output) diff --git a/Tools/DevUtils/update_benchmarks_from_azure_output.py b/Tools/DevUtils/update_benchmarks_from_azure_output.py index ec7b17d1050..b2be4d17a7b 100644 --- a/Tools/DevUtils/update_benchmarks_from_azure_output.py +++ b/Tools/DevUtils/update_benchmarks_from_azure_output.py @@ -8,7 +8,7 @@ import re import sys -''' +""" This Python script updates the Azure benchmarks automatically using a raw Azure output textfile that is given as the first and only argument of the script. @@ -17,12 +17,12 @@ and the next occurrence of "'----------------'" And use these lines to update the benchmarks -''' +""" azure_output_filename = sys.argv[1] -pattern_test_name = 'New file for (?P[\w\-]*)' -closing_string = '----------------' +pattern_test_name = "New file for (?P[\w\-]*)" +closing_string = "----------------" benchmark_path = "../../Regression/Checksum/benchmarks_json/" benchmark_suffix = ".json" @@ -31,14 +31,13 @@ with open(azure_output_filename, "r") as f: for line in f: - if current_test == "": # Here we search lines that read, for example, # "New file for LaserAcceleration_BTD" # and we set current_test = "LaserAcceleration_BTD" match_test_name = re.search(pattern_test_name, line) if match_test_name: - current_test = match_test_name.group('testname') + current_test = match_test_name.group("testname") new_file_string = "" else: @@ -46,20 +45,20 @@ # "----------------" # which indicates that we have read the new file entirely - if not closing_string in line: + if closing_string not in line: if not first_line_read: # Raw Azure output comes with a prefix at the beginning of each line that we do # not need here. The first line that we will read is the prefix followed by the # "{" character, so we determine how long the prefix is by finding the last # occurrence of the "{" character in this line. - azure_indent = line.rfind('{') + azure_indent = line.rfind("{") first_line_read = True new_file_string += line[azure_indent:] else: # We have read the new file entirely. Dump it in the json file. new_file_json = json.loads(new_file_string) - json_filepath = benchmark_path+current_test+benchmark_suffix + json_filepath = benchmark_path + current_test + benchmark_suffix with open(json_filepath, "w") as f_json: json.dump(new_file_json, f_json, indent=2) current_test = "" diff --git a/Tools/Parser/input_file_parser.py b/Tools/Parser/input_file_parser.py index 0ab134f6222..9aeba6bbacf 100644 --- a/Tools/Parser/input_file_parser.py +++ b/Tools/Parser/input_file_parser.py @@ -16,16 +16,18 @@ def parse_input_file(input_file): input_dict = dict() with open(input_file) as ff: for line in ff: - sline = line.split('=') + sline = line.split("=") # skip lines that are commented out, blank, or continuation of previous parameters - skip_line = sline[0].startswith('#') or sline[0].startswith('\n') or len(sline) == 1 + skip_line = ( + sline[0].startswith("#") or sline[0].startswith("\n") or len(sline) == 1 + ) if not skip_line: key = sline[0].strip() val = sline[1].split() # The value corresponding to a given key of input_dict is a list # of strings, from which we remove any leftover comments for i in range(len(val)): - if val[i].startswith('#'): + if val[i].startswith("#"): val = val[:i] break input_dict[key] = val diff --git a/Tools/PerformanceTests/automated_test_1_uniform_rest_32ppc b/Tools/PerformanceTests/automated_test_1_uniform_rest_32ppc deleted file mode 100644 index e5e722aa761..00000000000 --- a/Tools/PerformanceTests/automated_test_1_uniform_rest_32ppc +++ /dev/null @@ -1,58 +0,0 @@ -# Maximum number of time steps: command-line argument -# number of grid points: command-line argument - -# Maximum allowable size of each subdomain in the problem domain; -# this is used to decompose the domain for parallel calculations. -amr.max_grid_size = 64 - -# Maximum level in hierarchy (for now must be 0, i.e., one level in total) -amr.max_level = 0 - -# Geometry -geometry.dims = 3 -geometry.prob_lo = -20.e-6 -20.e-6 -20.e-6 # physical domain -geometry.prob_hi = 20.e-6 20.e-6 20.e-6 - -# Boundaries -boundary.field_lo = pec pec periodic -boundary.field_hi = pec pec periodic -boundary.particle_lo = absorbing absorbing periodic -boundary.particle_hi = absorbing absorbing periodic - -# Verbosity -warpx.verbose = 1 - -algo.particle_shape = 3 - -# CFL -warpx.cfl = 1.0 - -particles.species_names = electrons ions - -electrons.charge = -q_e -electrons.mass = m_e -electrons.injection_style = "NUniformPerCell" -electrons.num_particles_per_cell_each_dim = 2 2 4 -electrons.profile = constant -electrons.density = 1.e20 # number of electrons per m^3 -electrons.momentum_distribution_type = "gaussian" -electrons.ux_th = 0.01 -electrons.uy_th = 0.01 -electrons.uz_th = 0.01 -electrons.ux_m = 0. -electrons.uy_m = 0. -electrons.uz_m = 0. - -ions.charge = q_e -ions.mass = m_p -ions.injection_style = "NUniformPerCell" -ions.num_particles_per_cell_each_dim = 2 2 4 -ions.profile = constant -ions.density = 1.e20 # number of electrons per m^3 -ions.momentum_distribution_type = "gaussian" -ions.ux_th = 0.01 -ions.uy_th = 0.01 -ions.uz_th = 0.01 -ions.ux_m = 0. -ions.uy_m = 0. -ions.uz_m = 0. diff --git a/Tools/PerformanceTests/automated_test_2_uniform_rest_1ppc b/Tools/PerformanceTests/automated_test_2_uniform_rest_1ppc deleted file mode 100644 index 610990ac140..00000000000 --- a/Tools/PerformanceTests/automated_test_2_uniform_rest_1ppc +++ /dev/null @@ -1,44 +0,0 @@ -# Maximum number of time steps: command-line argument -# number of grid points: command-line argument - -# Maximum allowable size of each subdomain in the problem domain; -# this is used to decompose the domain for parallel calculations. -amr.max_grid_size = 32 - -# Maximum level in hierarchy (for now must be 0, i.e., one level in total) -amr.max_level = 0 - -# Geometry -geometry.dims = 3 -geometry.prob_lo = -20.e-6 -20.e-6 -20.e-6 # physical domain -geometry.prob_hi = 20.e-6 20.e-6 20.e-6 - -# Boundaries -boundary.field_lo = pec pec pec -boundary.field_hi = pec pec pec -boundary.particle_lo = absorbing absorbing absorbing -boundary.particle_hi = absorbing absorbing absorbing - -# Verbosity -warpx.verbose = 1 - -algo.particle_shape = 3 - -# CFL -warpx.cfl = 1.0 - -particles.species_names = electrons - -electrons.charge = -q_e -electrons.mass = m_e -electrons.injection_style = "NUniformPerCell" -electrons.num_particles_per_cell_each_dim = 1 1 1 -electrons.profile = constant -electrons.density = 1.e20 # number of electrons per m^3 -electrons.momentum_distribution_type = "gaussian" -electrons.ux_th = 0.01 -electrons.uy_th = 0.01 -electrons.uz_th = 0.01 -electrons.ux_m = 0. -electrons.uy_m = 0. -electrons.uz_m = 0. diff --git a/Tools/PerformanceTests/automated_test_3_uniform_drift_4ppc b/Tools/PerformanceTests/automated_test_3_uniform_drift_4ppc deleted file mode 100644 index 5a834cb4117..00000000000 --- a/Tools/PerformanceTests/automated_test_3_uniform_drift_4ppc +++ /dev/null @@ -1,59 +0,0 @@ -# Maximum number of time steps: command-line argument -# number of grid points: command-line argument - -# Maximum allowable size of each subdomain in the problem domain; -# this is used to decompose the domain for parallel calculations. -amr.max_grid_size = 64 - -# Maximum level in hierarchy (for now must be 0, i.e., one level in total) -amr.max_level = 0 - -# Geometry -geometry.dims = 3 -geometry.prob_lo = -20.e-6 -20.e-6 -20.e-6 # physical domain -geometry.prob_hi = 20.e-6 20.e-6 20.e-6 - -# Boundaries -boundary.field_lo = pec pec periodic -boundary.field_hi = pec pec periodic -boundary.particle_lo = absorbing absorbing periodic -boundary.particle_hi = absorbing absorbing periodic - -# Verbosity -warpx.verbose = 1 - -# Algorithms -algo.particle_shape = 3 - -# CFL -warpx.cfl = 1.0 - -particles.species_names = electrons ions - -electrons.charge = -q_e -electrons.mass = m_e -electrons.injection_style = "NUniformPerCell" -electrons.num_particles_per_cell_each_dim = 2 2 4 -electrons.profile = constant -electrons.density = 1.e20 # number of electrons per m^3 -electrons.momentum_distribution_type = "gaussian" -electrons.ux_th = 0.01 -electrons.uy_th = 0.01 -electrons.uz_th = 0.01 -electrons.ux_m = 0. -electrons.uy_m = 0. -electrons.uz_m = 100. - -ions.charge = q_e -ions.mass = m_p -ions.injection_style = "NUniformPerCell" -ions.num_particles_per_cell_each_dim = 2 2 4 -ions.profile = constant -ions.density = 1.e20 # number of electrons per m^3 -ions.momentum_distribution_type = "gaussian" -ions.ux_th = 0.01 -ions.uy_th = 0.01 -ions.uz_th = 0.01 -ions.ux_m = 0. -ions.uy_m = 0. -ions.uz_m = 100. diff --git a/Tools/PerformanceTests/automated_test_4_labdiags_2ppc b/Tools/PerformanceTests/automated_test_4_labdiags_2ppc deleted file mode 100644 index f49d92acf26..00000000000 --- a/Tools/PerformanceTests/automated_test_4_labdiags_2ppc +++ /dev/null @@ -1,79 +0,0 @@ -# Maximum number of time steps: command-line argument -# number of grid points: command-line argument - -amr.max_grid_size = 64 - -# Maximum level in hierarchy (for now must be 0, i.e., one level in total) -amr.max_level = 0 - -# Geometry -geometry.dims = 3 -geometry.prob_lo = -150.e-6 -150.e-6 -80.e-6 # physical domain -geometry.prob_hi = 150.e-6 150.e-6 0. - -# Boundaries -boundary.field_lo = pec pec pec -boundary.field_hi = pec pec pec -boundary.particle_lo = absorbing absorbing absorbing -boundary.particle_hi = absorbing absorbing absorbing - -# Verbosity -warpx.verbose = 1 - -# Numerics -algo.particle_shape = 3 -warpx.use_filter = 1 -warpx.cfl = 1.0 - -# Moving window -warpx.do_moving_window = 1 -warpx.moving_window_dir = z -warpx.moving_window_v = 1.0 # in units of the speed of light - -# Boosted frame -warpx.gamma_boost = 15. -warpx.boost_direction = z - -# Species -particles.species_names = electrons ions - -electrons.charge = -q_e -electrons.mass = m_e -electrons.injection_style = "NUniformPerCell" -electrons.xmin = -150.e-6 -electrons.xmax = 150.e-6 -electrons.ymin = -150.e-6 -electrons.ymax = 150.e-6 -electrons.zmin = 0.e-6 -electrons.num_particles_per_cell_each_dim = 1 1 1 -electrons.profile = constant -electrons.density = 1. -electrons.momentum_distribution_type = "at_rest" -electrons.do_continuous_injection = 1 - -ions.charge = q_e -ions.mass = m_p -ions.injection_style = "NUniformPerCell" -ions.xmin = -150.e-6 -ions.xmax = 150.e-6 -ions.ymin = -150.e-6 -ions.ymax = 150.e-6 -ions.zmin = 0.e-6 -ions.num_particles_per_cell_each_dim = 1 1 1 -ions.profile = constant -ions.density = 1. -ions.momentum_distribution_type = "at_rest" -ions.do_continuous_injection = 1 - -# Laser -lasers.names = laser -laser.profile = Gaussian -laser.position = 0. 0. -1.e-6 # This point is on the laser plane -laser.direction = 0. 0. 1. # The plane normal direction -laser.polarization = 1. 0. 0. # The main polarization vector -laser.e_max = 8.e12 # Maximum amplitude of the laser field (in V/m) -laser.profile_waist = 5.e-5 # The waist of the laser (in meters) -laser.profile_duration = 16.7e-15 # The duration of the laser (in seconds) -laser.profile_t_peak = 33.4e-15 # The time at which the laser reaches its peak (in seconds) -laser.profile_focal_distance = 0.e-6 # Focal distance from the antenna (in meters) -laser.wavelength = 0.8e-6 # The wavelength of the laser (in meters) diff --git a/Tools/PerformanceTests/automated_test_5_loadimbalance b/Tools/PerformanceTests/automated_test_5_loadimbalance deleted file mode 100644 index 76b1a53efdb..00000000000 --- a/Tools/PerformanceTests/automated_test_5_loadimbalance +++ /dev/null @@ -1,59 +0,0 @@ -# Maximum number of time steps: command-line argument -# number of grid points: command-line argument - -# Maximum allowable size of each subdomain in the problem domain; -# this is used to decompose the domain for parallel calculations. -amr.max_grid_size = 32 - -# Maximum level in hierarchy (for now must be 0, i.e., one level in total) -amr.max_level = 0 - -# Geometry -geometry.dims = 3 -geometry.prob_lo = -20.e-6 -20.e-6 -20.e-6 # physical domain -geometry.prob_hi = 20.e-6 20.e-6 20.e-6 - -# Boundaries -boundary.field_lo = pec pec periodic -boundary.field_hi = pec pec periodic -boundary.particle_lo = absorbing absorbing periodic -boundary.particle_hi = absorbing absorbing periodic - -warpx.verbose = 1 -algo.load_balance_intervals = -5 -algo.particle_shape = 3 - -# CFL -warpx.cfl = 1.0 - -particles.species_names = electrons ions - -electrons.charge = -q_e -electrons.mass = m_e -electrons.injection_style = "NUniformPerCell" -electrons.num_particles_per_cell_each_dim = 2 2 4 -electrons.profile = constant -electrons.density = 1.e20 # number of electrons per m^3 -electrons.momentum_distribution_type = "gaussian" -electrons.zmax = 0. -electrons.ux_th = 0.01 -electrons.uy_th = 0.01 -electrons.uz_th = 0.01 -electrons.ux_m = 0. -electrons.uy_m = 0. -electrons.uz_m = 0. - -ions.charge = q_e -ions.mass = m_p -ions.injection_style = "NUniformPerCell" -ions.num_particles_per_cell_each_dim = 2 2 4 -ions.profile = constant -ions.density = 1.e20 # number of electrons per m^3 -ions.momentum_distribution_type = "gaussian" -ions.zmax = 0. -ions.ux_th = 0.01 -ions.uy_th = 0.01 -ions.uz_th = 0.01 -ions.ux_m = 0. -ions.uy_m = 0. -ions.uz_m = 0. diff --git a/Tools/PerformanceTests/automated_test_6_output_2ppc b/Tools/PerformanceTests/automated_test_6_output_2ppc deleted file mode 100644 index afd4a6df336..00000000000 --- a/Tools/PerformanceTests/automated_test_6_output_2ppc +++ /dev/null @@ -1,64 +0,0 @@ -# Maximum number of time steps: command-line argument -# number of grid points: command-line argument - -# Maximum allowable size of each subdomain in the problem domain; -# this is used to decompose the domain for parallel calculations. -amr.max_grid_size = 64 - -# Maximum level in hierarchy (for now must be 0, i.e., one level in total) -amr.max_level = 0 - -# Geometry -geometry.dims = 3 -geometry.prob_lo = -20.e-6 -20.e-6 -20.e-6 # physical domain -geometry.prob_hi = 20.e-6 20.e-6 20.e-6 - -# Boundaries -boundary.field_lo = pec pec pec -boundary.field_hi = pec pec pec -boundary.particle_lo = absorbing absorbing absorbing -boundary.particle_hi = absorbing absorbing absorbing - -# Verbosity -warpx.verbose = 1 - -algo.particle_shape = 3 - -# CFL -warpx.cfl = 1.0 - -particles.species_names = electrons ions - -electrons.charge = -q_e -electrons.mass = m_e -electrons.injection_style = "NUniformPerCell" -electrons.num_particles_per_cell_each_dim = 1 1 1 -electrons.profile = constant -electrons.density = 1.e20 # number of electrons per m^3 -electrons.momentum_distribution_type = "gaussian" -electrons.ux_th = 0.01 -electrons.uy_th = 0.01 -electrons.uz_th = 0.01 -electrons.ux_m = 0. -electrons.uy_m = 0. -electrons.uz_m = 0. - -ions.charge = q_e -ions.mass = m_p -ions.injection_style = "NUniformPerCell" -ions.num_particles_per_cell_each_dim = 1 1 1 -ions.profile = constant -ions.density = 1.e20 # number of electrons per m^3 -ions.momentum_distribution_type = "gaussian" -ions.ux_th = 0.01 -ions.uy_th = 0.01 -ions.uz_th = 0.01 -ions.ux_m = 0. -ions.uy_m = 0. -ions.uz_m = 0. - -# Diagnostics -diagnostics.diags_names = diag1 -diag1.intervals = 1 -diag1.file_prefix = "./diags/plt" -diag1.diag_type = Full diff --git a/Tools/PerformanceTests/cori.py b/Tools/PerformanceTests/cori.py deleted file mode 100644 index 046767713f0..00000000000 --- a/Tools/PerformanceTests/cori.py +++ /dev/null @@ -1,171 +0,0 @@ -# Copyright 2019 Axel Huebl, Luca Fedeli, Maxence Thevenet -# -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import copy -import os - -from functions_perftest import test_element - -module_name = {'cpu': 'haswell.', 'knl': 'mic-knl.', 'gpu':'.'} - -def executable_name(compiler, architecture): - return 'perf_tests3d.' + compiler + \ - '.' + module_name[architecture] + 'TPROF.MTMPI.OMP.QED.ex' - -def get_config_command(compiler, architecture): - config_command = '' - config_command += 'module unload darshan;' - if architecture == 'knl': - if compiler == 'intel': - config_command += 'module unload PrgEnv-gnu;' - config_command += 'module load PrgEnv-intel;' - elif compiler == 'gnu': - config_command += 'module unload PrgEnv-intel;' - config_command += 'module load PrgEnv-gnu;' - config_command += 'module unload craype-haswell;' - config_command += 'module load craype-mic-knl;' - elif architecture == 'cpu': - if compiler == 'intel': - config_command += 'module unload PrgEnv-gnu;' - config_command += 'module load PrgEnv-intel;' - elif compiler == 'gnu': - config_command += 'module unload PrgEnv-intel;' - config_command += 'module load PrgEnv-gnu;' - config_command += 'module unload craype-mic-knl;' - config_command += 'module load craype-haswell;' - return config_command - -# This function runs a batch script with -# dependencies to perform the analysis -# after all performance tests are done. -def process_analysis(automated, cwd, compiler, architecture, n_node_list, start_date, path_source, path_results): - dependencies = '' - f_log = open(cwd + 'log_jobids_tmp.txt' ,'r') - for line in f_log.readlines(): - dependencies += line.split()[3] + ':' - - batch_string = '''#!/bin/bash -#SBATCH --job-name=warpx_1node_read -#SBATCH --time=00:07:00 -#SBATCH -C knl -#SBATCH -N 1 -#SBATCH -S 4 -#SBATCH -q regular -#SBATCH -e read_error.txt -#SBATCH -o read_output.txt -#SBATCH --mail-type=end -#SBATCH --account=m2852 -module load h5py-parallel -''' - batch_string += 'python run_automated.py --compiler=' + \ - compiler + ' --architecture=' + architecture + \ - ' --mode=read' + \ - ' --n_node_list=' + '"' + n_node_list + '"' + \ - ' --start_date=' + start_date + \ - ' --path_source=' + path_source + \ - ' --path_results=' + path_results - if automated == True: - batch_string += ' --automated' - batch_string += '\n' - batch_file = 'slurm_perfread' - f_exe = open(batch_file,'w') - f_exe.write(batch_string) - f_exe.close() - os.system('chmod 700 ' + batch_file) - print( 'process_analysis line: ' + 'sbatch --dependency afterok:' + dependencies[0:-1] + ' ' + batch_file) - os.system('sbatch --dependency afterok:' + dependencies[0:-1] + ' ' + batch_file) - -# Calculate simulation time. Take 5 min + 5 min / simulation -def time_min(nb_simulations): - return 5. + nb_simulations*5. - -def get_submit_job_command(): - return ' sbatch ' - -def get_batch_string(test_list, job_time_min, Cname, n_node): - - job_time_str = str(int(job_time_min/60)) + ':' + str(int(job_time_min%60)) + ':00' - - batch_string = '' - batch_string += '#!/bin/bash\n' - batch_string += '#SBATCH --job-name=' + test_list[0].input_file + '\n' - batch_string += '#SBATCH --time=' + job_time_str + '\n' - batch_string += '#SBATCH -C ' + Cname + '\n' - batch_string += '#SBATCH -N ' + str(n_node) + '\n' - batch_string += '#SBATCH -q regular\n' - batch_string += '#SBATCH -e error.txt\n' - batch_string += '#SBATCH --account=m2852\n' - batch_string += 'module unload PrgEnv-gnu\n' - batch_string += 'module load PrgEnv-intel\n' - return batch_string - -def get_run_string(current_test, architecture, n_node, count, bin_name, runtime_param_string): - srun_string = '' - srun_string += 'export OMP_NUM_THREADS=' + str(current_test.n_omp) + '\n' - # number of logical cores per MPI process - if architecture == 'cpu': - cflag_value = max(1, int(32/current_test.n_mpi_per_node) * 2) # Follow NERSC directives - elif architecture == 'knl': - cflag_value = max(1, int(64/current_test.n_mpi_per_node) * 4) # Follow NERSC directives - output_filename = 'out_' + '_'.join([current_test.input_file, str(n_node), str(current_test.n_mpi_per_node), str(current_test.n_omp), str(count)]) + '.txt' - srun_string += 'srun --cpu_bind=cores '+ \ - ' -n ' + str(n_node*current_test.n_mpi_per_node) + \ - ' -c ' + str(cflag_value) + \ - ' ./' + bin_name + \ - ' ' + current_test.input_file + \ - runtime_param_string + \ - ' > ' + output_filename + '\n' - return srun_string - -def get_test_list(n_repeat): - test_list_unq = [] - # n_node is kept to None and passed in functions as an external argument - # That way, several test_element_instance run with the same n_node on the same batch job - test_list_unq.append( test_element(input_file='automated_test_1_uniform_rest_32ppc', - n_mpi_per_node=8, - n_omp=8, - n_cell=[128, 128, 128], - max_grid_size=64, - blocking_factor=32, - n_step=10) ) - test_list_unq.append( test_element(input_file='automated_test_2_uniform_rest_1ppc', - n_mpi_per_node=8, - n_omp=8, - n_cell=[256, 256, 512], - max_grid_size=64, - blocking_factor=32, - n_step=10) ) - test_list_unq.append( test_element(input_file='automated_test_3_uniform_drift_4ppc', - n_mpi_per_node=8, - n_omp=8, - n_cell=[128, 128, 128], - max_grid_size=64, - blocking_factor=32, - n_step=10) ) - test_list_unq.append( test_element(input_file='automated_test_4_labdiags_2ppc', - n_mpi_per_node=8, - n_omp=8, - n_cell=[64, 64, 128], - max_grid_size=64, - blocking_factor=32, - n_step=50) ) - test_list_unq.append( test_element(input_file='automated_test_5_loadimbalance', - n_mpi_per_node=8, - n_omp=8, - n_cell=[128, 128, 128], - max_grid_size=64, - blocking_factor=32, - n_step=10) ) - test_list_unq.append( test_element(input_file='automated_test_6_output_2ppc', - n_mpi_per_node=8, - n_omp=8, - n_cell=[128, 256, 256], - max_grid_size=64, - blocking_factor=32, - n_step=1) ) - test_list = [copy.deepcopy(item) for item in test_list_unq for _ in range(n_repeat) ] - return test_list diff --git a/Tools/PerformanceTests/functions_perftest.py b/Tools/PerformanceTests/functions_perftest.py deleted file mode 100644 index 8d7f4e29246..00000000000 --- a/Tools/PerformanceTests/functions_perftest.py +++ /dev/null @@ -1,255 +0,0 @@ -# Copyright 2018-2019 Axel Huebl, Luca Fedeli, Maxence Thevenet -# Remi Lehe -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import copy -import os -import re -import shutil - -import git -import numpy as np -import pandas as pd - -# import cori -# import summit - -# Each instance of this class contains information for a single test. -class test_element(): - def __init__(self, input_file=None, n_node=None, n_mpi_per_node=None, - n_omp=None, n_cell=None, n_step=None, max_grid_size=None, - blocking_factor=None): - self.input_file = input_file - self.n_node = n_node - self.n_mpi_per_node = n_mpi_per_node - self.n_omp = n_omp - self.n_cell = n_cell - self.n_step = n_step - self.max_grid_size = max_grid_size - self.blocking_factor = blocking_factor - - def scale_n_cell(self, n_node=0): - n_cell_scaled = copy.deepcopy(self.n_cell) - index_dim = 0 - while n_node > 1: - n_cell_scaled[index_dim] *= 2 - n_node /= 2 - index_dim = (index_dim+1) % 3 - self.n_cell = n_cell_scaled - -def scale_n_cell(ncell, n_node): - ncell_scaled = ncell[:] - index_dim = 0 - while n_node > 1: - ncell_scaled[index_dim] *= 2 - n_node /= 2 - index_dim = (index_dim+1) % 3 - return ncell_scaled - -def store_git_hash(repo_path=None, filename=None, name=None): - repo = git.Repo(path=repo_path) - sha = repo.head.object.hexsha - file_handler = open( filename, 'a+' ) - file_handler.write( name + ':' + sha + ' ') - file_handler.close() - -def get_file_content(filename=None): - file_handler = open( filename, 'r' ) - file_content = file_handler.read() - file_handler.close() - return file_content - -def run_batch(run_name, res_dir, bin_name, config_command, architecture='knl',\ - Cname='knl', n_node=1, n_mpi=1, n_omp=1): - # Clean res_dir - if os.path.exists(res_dir): - shutil.rmtree(res_dir) - os.makedirs(res_dir) - # Copy files to res_dir - cwd = os.environ['WARPX'] + '/Tools/PerformanceTests/' - bin_dir = cwd + 'Bin/' - shutil.copy(bin_dir + bin_name, res_dir) - shutil.copyfile(cwd + run_name, res_dir + 'inputs') - os.chdir(res_dir) - batch_string = '' - batch_string += '#!/bin/bash\n' - batch_string += '#SBATCH --job-name=' + run_name + str(n_node) + str(n_mpi) + str(n_omp) + '\n' - batch_string += '#SBATCH --time=00:23:00\n' - batch_string += '#SBATCH -C ' + Cname + '\n' - batch_string += '#SBATCH -N ' + str(n_node) + '\n' - batch_string += '#SBATCH -q regular\n' - batch_string += '#SBATCH -e error.txt\n' - batch_string += '#SBATCH --account=m2852\n' - batch_string += 'export OMP_NUM_THREADS=' + str(n_omp) + '\n' - if architecture == 'cpu': - cflag_value = max(1, int(32/n_mpi) * 2) # Follow NERSC directives - batch_string += 'srun --cpu_bind=cores '+ \ - ' -n ' + str(n_node*n_mpi) + \ - ' -c ' + str(cflag_value) + \ - ' ./' + bin_name + ' inputs > perf_output.txt' - elif architecture == 'knl': - # number of logical cores per MPI process - cflag_value = max(1, int(64/n_mpi) * 4) # Follow NERSC directives - batch_string += 'srun --cpu_bind=cores ' + \ - ' -n ' + str(n_node*n_mpi) + \ - ' -c ' + str(cflag_value) + \ - ' ./' + bin_name + ' inputs > perf_output.txt\n' - batch_file = 'slurm' - f_exe = open(batch_file,'w') - f_exe.write(batch_string) - f_exe.close() - os.system('chmod 700 ' + bin_name) - os.system(config_command + 'sbatch ' + batch_file + ' >> ' + cwd + 'log_jobids_tmp.txt') - return 0 - -def run_batch_nnode(test_list, res_dir, cwd, bin_name, config_command, batch_string, submit_job_command): - # Clean res_dir - if os.path.exists(res_dir): - shutil.rmtree(res_dir, ignore_errors=True) - os.makedirs(res_dir) - # Copy files to res_dir - bin_dir = cwd + 'Bin/' - shutil.copy(bin_dir + bin_name, res_dir) - os.chdir(res_dir) - - for count, current_test in enumerate(test_list): - shutil.copy(cwd + current_test.input_file, res_dir) - batch_file = 'batch_script.sh' - f_exe = open(batch_file,'w') - f_exe.write(batch_string) - f_exe.close() - os.system('chmod 700 ' + bin_name) - os.system(config_command + submit_job_command + batch_file +\ - ' >> ' + cwd + 'log_jobids_tmp.txt') - -# Read output file and return init time and 1-step time -def read_run_perf(filename, n_steps): - timing_list = [] - # Search inclusive time to get simulation step time - partition_limit = 'NCalls Incl. Min Incl. Avg Incl. Max Max %' - with open(filename) as file_handler: - output_text = file_handler.read() - # Get total simulation time - line_match_totaltime = re.search('TinyProfiler total time across processes.*', output_text) - total_time = float(line_match_totaltime.group(0).split()[8]) - search_area = output_text.partition(partition_limit)[2] - line_match_looptime = re.search('\nWarpX::Evolve().*', search_area) - time_wo_initialization = float(line_match_looptime.group(0).split()[3]) - timing_list += [str(total_time - time_wo_initialization)] - timing_list += [str(time_wo_initialization/n_steps)] - partition_limit1 = 'NCalls Excl. Min Excl. Avg Excl. Max Max %' - partition_limit2 = 'NCalls Incl. Min Incl. Avg Incl. Max Max %' - file_handler.close() - with open(filename) as file_handler: - output_text = file_handler.read() - # Search EXCLISUSIVE routine timings - search_area = output_text.partition(partition_limit1)[2].partition(partition_limit2)[0] - pattern_list = ['\nParticleContainer::Redistribute().*',\ - '\nFabArray::FillBoundary().*',\ - '\nFabArray::ParallelCopy().*',\ - '\nPPC::CurrentDeposition.*',\ - '\nPPC::FieldGather.*',\ - '\nPPC::ParticlePush.*',\ - '\nPPC::Evolve::Copy.*',\ - '\nWarpX::Evolve().*',\ - 'Checkpoint().*',\ - 'WriteParticles().*',\ - '\nVisMF::Write(FabArray).*',\ - '\nWriteMultiLevelPlotfile().*',\ - '\nParticleContainer::RedistributeMPI().*'] - for pattern in pattern_list: - timing = '0' - line_match = re.search(pattern, search_area) - if line_match is not None: - timing = [str(float(line_match.group(0).split()[3])/n_steps)] - timing_list += timing - return timing_list - -# Write time into logfile -def write_perf_logfile(log_file, log_line): - f_log = open(log_file, 'a') - f_log.write(log_line) - f_log.close() - return 0 - -def get_nsteps(run_name): - with open(run_name) as file_handler: - run_name_text = file_handler.read() - line_match_nsteps = re.search('\nmax_step.*', run_name_text) - nsteps = float(line_match_nsteps.group(0).split()[2]) - return nsteps - -def extract_dataframe(filename, n_steps): - # Get init time and total time through Inclusive time - partition_limit_start = 'NCalls Incl. Min Incl. Avg Incl. Max Max %' - print(filename) - with open(filename) as file_handler: - output_text = file_handler.read() - # get total simulation time - line_match_totaltime = re.search('TinyProfiler total time across processes.*', output_text) - total_time = float(line_match_totaltime.group(0).split()[8]) - # get time performing steps as Inclusive WarpX::Evolve() time - search_area = output_text.partition(partition_limit_start)[2] - line_match_looptime = re.search('\nWarpX::Evolve().*', search_area) - time_wo_initialization = float(line_match_looptime.group(0).split()[3]) - # New, might break something - line_match_WritePlotFile = re.search('\nDiagnostics::FilterComputePackFlush().*', search_area) - if line_match_WritePlotFile is not None: - time_WritePlotFile = float(line_match_WritePlotFile.group(0).split()[3]) - else: - time_WritePlotFile = 0. - # Get timers for all routines - # Where to start and stop in the output_file - partition_limit_start = 'NCalls Excl. Min Excl. Avg Excl. Max Max %' - partition_limit_end = 'NCalls Incl. Min Incl. Avg Incl. Max Max %' - # Put file content in a string - with open(filename) as file_handler: - output_text = file_handler.read() - # Keep only profiling data - search_area = output_text.partition(partition_limit_start)[2]\ - .partition(partition_limit_end)[0] - list_string = search_area.split('\n')[2:-4] - time_array = np.zeros(len(list_string)) - column_list= [] - for i in np.arange(len(list_string)): - column_list.append(list_string[i].split()[0]) - time_array[i] = float(list_string[i].split()[3]) - df = pd.DataFrame(columns=column_list) - df.loc[0] = time_array - df['time_initialization'] = total_time - time_wo_initialization - df['time_running'] = time_wo_initialization - df['time_WritePlotFile'] = time_WritePlotFile - # df['string_output'] = partition_limit_start + '\n' + search_area - return df - -# Run a performance test in an interactive allocation -# def run_interactive(run_name, res_dir, n_node=1, n_mpi=1, n_omp=1): -# # Clean res_dir # -# if os.path.exists(res_dir): -# shutil.rmtree(res_dir) -# os.makedirs(res_dir) -# # Copy files to res_dir # -# shutil.copyfile(bin_dir + bin_name, res_dir + bin_name) -# shutil.copyfile(cwd + run_name, res_dir + 'inputs') -# os.chdir(res_dir) -# if args.architecture == 'cpu': -# cflag_value = max(1, int(32/n_mpi) * 2) # Follow NERSC directives # -# exec_command = 'export OMP_NUM_THREADS=' + str(n_omp) + ';' +\ -# 'srun --cpu_bind=cores ' + \ -# ' -n ' + str(n_node*n_mpi) + \ -# ' -c ' + str(cflag_value) + \ -# ' ./' + bin_name + ' inputs > perf_output.txt' -# elif args.architecture == 'knl': -# # number of logical cores per MPI process # -# cflag_value = max(1,int(68/n_mpi) * 4) # Follow NERSC directives # -# exec_command = 'export OMP_NUM_THREADS=' + str(n_omp) + ';' +\ -# 'srun --cpu_bind=cores ' + \ -# ' -n ' + str(n_node*n_mpi) + \ -# ' -c ' + str(cflag_value) + \ -# ' ./' + bin_name + ' inputs > perf_output.txt' -# os.system('chmod 700 ' + bin_name) -# os.system(config_command + exec_command) -# return 0 diff --git a/Tools/PerformanceTests/performance_log.txt b/Tools/PerformanceTests/performance_log.txt deleted file mode 100644 index 72fece34939..00000000000 --- a/Tools/PerformanceTests/performance_log.txt +++ /dev/null @@ -1,81 +0,0 @@ -## year month day run_name compiler architecture n_node n_mpi n_omp time_initialization time_one_iteration Redistribute FillBoundary ParallelCopy CurrentDeposition FieldGather ParthiclePush Copy Evolve Checkpoint WriteParticles Write_FabArray WriteMultiLevelPlotfile(unit: second) RedistributeMPI -2018 01 31 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.14 0.3986 0.1713 0.01719 0.01615 0.06987 0.03636 0.01901 0.01999 0.003602 0 0 0 0 0.007262 -2018 01 31 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.39 0.4009 0.1712 0.01676 0.01583 0.07061 0.03684 0.01926 0.02011 0.003687 0 0 0 0 0.007841 -2018 01 31 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 2.91 0.4024 0.1716 0.01826 0.01918 0.0703 0.0363 0.01912 0.01989 0.003017 0 0 0 0 0.007256 -2018 01 31 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.21 0.3997 0.1717 0.01706 0.0162 0.07026 0.03655 0.01928 0.01999 0.003687 0 0 0 0 0.006799 -2018 01 31 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 0.89 0.4779 0.04441 0.1143 0.09117 0.1072 0.01254 0.003702 0.004217 0.01247 0 0 0 0 0.003441 -2018 01 31 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.58 0.4626 0.04424 0.1048 0.0851 0.1073 0.01259 0.003767 0.004282 0.01311 0 0 0 0 0.002798 -2018 01 31 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.63 0.4616 0.04441 0.1033 0.08398 0.1079 0.01312 0.003802 0.004224 0.01278 0 0 0 0 0.003188 -2018 01 31 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.72 0.461 0.04419 0.1038 0.08424 0.1074 0.01257 0.003799 0.0043 0.01318 0 0 0 0 0.002816 -2018 01 31 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.32 0.3986 0.1712 0.01804 0.01697 0.06999 0.03615 0.01842 0.01896 0.003445 0 0 0 0 0.00738 -2018 01 31 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.17 0.3974 0.1711 0.01722 0.01587 0.07016 0.03642 0.01844 0.01902 0.003431 0 0 0 0 0.007332 -2018 01 31 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 2.88 0.3946 0.1709 0.01686 0.01562 0.06972 0.03595 0.01848 0.01916 0.003269 0 0 0 0 0.006887 -2018 01 31 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 2.95 0.4094 0.1708 0.01761 0.01632 0.07001 0.03651 0.01863 0.01906 0.003314 0 0 0 0 0.01898 -2018 01 31 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.3 0.4787 0.04447 0.1139 0.09124 0.108 0.01287 0.003811 0.004205 0.01249 0 0 0 0 0.003045 -2018 01 31 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 3.16 0.4578 0.04412 0.1015 0.08339 0.1078 0.01301 0.003919 0.004182 0.0125 0 0 0 0 0.002701 -2018 01 31 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 2.78 0.4679 0.04418 0.1035 0.08456 0.1079 0.01303 0.003902 0.004214 0.0127 0 0 0 0 0.009118 -2018 01 31 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.12 0.4613 0.04425 0.1043 0.08517 0.1073 0.01242 0.003797 0.004221 0.01239 0 0 0 0 0.003665 -2018 01 31 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.48 0.1237 0.03056 0.01622 0.01468 0.02039 0.005016 0.003737 0.002632 0.00326 0 0 0 0 0.006871 -2018 01 31 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.79 0.1287 0.0308 0.01706 0.01715 0.02042 0.005452 0.003636 0.002797 0.003143 0 0 0 0 0.007324 -2018 01 31 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.9 0.1296 0.03084 0.01711 0.01731 0.02053 0.005379 0.003641 0.002843 0.003137 0 0 0 0 0.008151 -2018 01 31 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.9 0.1323 0.03081 0.01703 0.01736 0.02065 0.005339 0.003638 0.002751 0.004008 0 0 0 0 0.01015 -2018 01 31 automated_test_4_labdiags_2ppc intel knl 1 16 8 0.85 0.2896 0.03832 0.06449 0.07493 0.003507 0.002987 0.0001515 0.0001762 0.007921 0.0371 0.001537 0 0.0004387 0.03832 -2018 01 31 automated_test_4_labdiags_2ppc intel knl 1 16 8 1.12 0.2895 0.03845 0.06423 0.07481 0.003489 0.002994 0.000152 0.0001779 0.00834 0.0357 0.001545 0 0.0005249 0.03845 -2018 01 31 automated_test_4_labdiags_2ppc intel knl 1 16 8 0.76 0.3243 0.03804 0.0646 0.07462 0.003483 0.002991 0.0001508 0.0001769 0.008051 0.05983 0.001565 0 0.005392 0.03804 -2018 01 31 automated_test_4_labdiags_2ppc intel knl 1 16 8 0.74 0.3143 0.03941 0.06478 0.07547 0.003486 0.003007 0.0001518 0.0001808 0.007845 0.05079 0.001543 0 0.0007033 0.03941 -2018 01 31 automated_test_5_loadimbalance intel knl 1 16 8 9.2 0.3845 0.08558 0.1042 0.1332 0 0 0 0 0.01226 0 0 0 0 0.08558 -2018 01 31 automated_test_5_loadimbalance intel knl 1 16 8 9.19 0.3864 0.085 0.1051 0.134 0 0 0 0 0.01202 0 0 0 0 0.085 -2018 01 31 automated_test_5_loadimbalance intel knl 1 16 8 8.98 0.3912 0.08665 0.1061 0.1356 0 0 0 0 0.01193 0 0 0 0 0.08665 -2018 01 31 automated_test_5_loadimbalance intel knl 1 16 8 9.03 0.3826 0.08484 0.1031 0.1329 0 0 0 0 0.01205 0 0 0 0 0.08484 -2018 01 31 automated_test_6_output_2ppc intel knl 1 16 8 3.6 1.086 0.0898 0.1311 0.09441 0.1345 0.027 0.008783 0.009792 0.02151 0.08454 0.04962 0 0.0008218 0.005303 -2018 01 31 automated_test_6_output_2ppc intel knl 1 16 8 4.7 1.136 0.09059 0.1437 0.09535 0.1358 0.02915 0.009238 0.01002 0.02315 0.09088 0.05006 0 0.01081 0.005381 -2018 01 31 automated_test_6_output_2ppc intel knl 1 16 8 4.0 1.132 0.09145 0.1377 0.09592 0.1365 0.02817 0.009353 0.0103 0.02447 0.066 0.05309 0 0.02047 0.009196 -2018 01 31 automated_test_6_output_2ppc intel knl 1 16 8 3.8 1.135 0.09088 0.1308 0.09623 0.135 0.02762 0.008839 0.009758 0.02561 0.1144 0.04874 0 0.0008693 0.008112 -2018 02 13 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.87 0.4053 0.1754 0.01914 0.01871 0.0691 0.03648 0.01879 0.0193 0.003268 0 0 0 0 0.007445 -2018 02 13 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 4.38 0.405 0.1741 0.01901 0.01839 0.07034 0.03718 0.01894 0.0195 0.003845 0 0 0 0 0.007187 -2018 02 13 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.79 0.3999 0.1739 0.01859 0.01631 0.06918 0.0367 0.01906 0.01952 0.003278 0 0 0 0 0.006658 -2018 02 13 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.93 0.4044 0.1746 0.01854 0.01695 0.06975 0.03721 0.0191 0.01941 0.003979 0 0 0 0 0.007381 -2018 02 13 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.83 0.4773 0.04582 0.1089 0.08772 0.1072 0.01304 0.003335 0.004231 0.01385 0 0 0 0 0.002991 -2018 02 13 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.51 0.4654 0.04556 0.1027 0.08351 0.1068 0.01292 0.003114 0.004249 0.01356 0 0 0 0 0.002748 -2018 02 13 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.62 0.4755 0.0457 0.1082 0.08761 0.1069 0.0131 0.003205 0.00431 0.01388 0 0 0 0 0.002738 -2018 02 13 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.44 0.4798 0.04561 0.1133 0.08962 0.1064 0.01246 0.003076 0.004241 0.01318 0 0 0 0 0.003164 -2018 02 13 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.92 0.1282 0.03185 0.01747 0.01557 0.01956 0.005103 0.003455 0.00274 0.00346 0 0 0 0 0.007196 -2018 02 13 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.97 0.1301 0.03157 0.01788 0.01732 0.01957 0.00508 0.003335 0.002803 0.003454 0 0 0 0 0.007446 -2018 02 13 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.91 0.1289 0.03137 0.01765 0.0155 0.02026 0.005636 0.003513 0.002716 0.003381 0 0 0 0 0.007087 -2018 02 13 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.64 0.1308 0.03142 0.0181 0.01777 0.01953 0.005204 0.003371 0.002782 0.003057 0 0 0 0 0.007769 -2018 02 13 automated_test_4_labdiags_2ppc intel knl 1 16 8 3.19 0.3005 0.0383 0.06396 0.07274 0.003502 0.003005 0.0001628 0.0001839 0.008869 0.04427 0.001522 0 0.0005522 0.0383 -2018 02 13 automated_test_4_labdiags_2ppc intel knl 1 16 8 1.41 0.2945 0.0389 0.06251 0.0723 0.003508 0.003009 0.000164 0.0001825 0.009131 0.04042 0.001538 0 0.0005936 0.0389 -2018 02 13 automated_test_4_labdiags_2ppc intel knl 1 16 8 1.32 0.3066 0.0387 0.06558 0.07547 0.003463 0.003017 0.0001631 0.0001837 0.008431 0.04955 0.001555 0 0.000454 0.0387 -2018 02 13 automated_test_4_labdiags_2ppc intel knl 1 16 8 0.71 0.3391 0.03987 0.06534 0.07626 0.003475 0.003004 0.0001643 0.0001821 0.008152 0.06677 0.001534 0 0.01029 0.03987 -2018 02 13 automated_test_5_loadimbalance intel knl 1 16 8 9.68 0.3956 0.08701 0.1051 0.1352 0 0 0 0 0.01387 0 0 0 0 0.08701 -2018 02 13 automated_test_5_loadimbalance intel knl 1 16 8 10.65 0.3987 0.0866 0.1051 0.1332 0 0 0 0 0.0191 0 0 0 0 0.0866 -2018 02 13 automated_test_5_loadimbalance intel knl 1 16 8 10.11 0.4013 0.08782 0.1087 0.1359 0 0 0 0 0.01379 0 0 0 0 0.08782 -2018 02 13 automated_test_5_loadimbalance intel knl 1 16 8 9.94 0.39 0.08702 0.1028 0.132 0 0 0 0 0.0142 0 0 0 0 0.08702 -2018 02 13 automated_test_6_output_2ppc intel knl 1 16 8 1.292 0.2639 0.01424 0.03424 0.01742 0.01893 0.003449 0.001364 0.001712 0.009362 0.04053 0.01765 0 0.002558 0.001185 -2018 02 13 automated_test_6_output_2ppc intel knl 1 16 8 0.779 0.3155 0.01125 0.03605 0.01628 0.02431 0.009672 0.002843 0.001334 0.008876 0.05925 0.02047 0 0.001897 0.0006917 -2018 02 13 automated_test_6_output_2ppc intel knl 1 16 8 0.635 0.2568 0.01083 0.03443 0.01592 0.01963 0.003027 0.001439 0.001286 0.009288 0.03879 0.01815 0 0.001509 0.0007743 -2018 02 13 automated_test_6_output_2ppc intel knl 1 16 8 1.371 0.2648 0.01401 0.03376 0.01593 0.01936 0.003443 0.001351 0.00169 0.01161 0.03936 0.01785 0 0.002107 0.001171 -2018 02 20 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.7 0.4573 0.01159 0.02139 0.02206 0.06934 0.03845 0.0192 0.02062 0.003496 0 0 0 0 0.01159 -2018 02 20 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.45 0.4603 0.01356 0.02085 0.02488 0.06946 0.03777 0.01908 0.02031 0.003356 0 0 0 0 0.01356 -2018 02 20 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 3.72 0.4552 0.01245 0.02003 0.02013 0.06874 0.03766 0.01907 0.0203 0.003667 0 0 0 0 0.01245 -2018 02 20 automated_test_1_uniform_rest_32ppc intel knl 1 16 8 2.94 0.4557 0.01381 0.01979 0.02053 0.0687 0.03694 0.01886 0.02012 0.006396 0 0 0 0 0.01381 -2018 02 20 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.33 0.4937 0.005316 0.1103 0.09802 0.1071 0.01258 0.00326 0.004435 0.01347 0 0 0 0 0.005316 -2018 02 20 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.27 0.5063 0.004948 0.1213 0.1019 0.1067 0.01183 0.003056 0.004479 0.01327 0 0 0 0 0.004948 -2018 02 20 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 2.2 0.4983 0.005787 0.1141 0.1002 0.1067 0.0121 0.00307 0.00445 0.01343 0 0 0 0 0.005787 -2018 02 20 automated_test_2_uniform_rest_1ppc intel knl 1 16 8 1.39 0.5018 0.005339 0.1152 0.1007 0.1073 0.01249 0.003196 0.004484 0.01348 0 0 0 0 0.005339 -2018 02 20 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.98 0.1342 0.007843 0.01855 0.01798 0.01936 0.005198 0.003471 0.002626 0.003161 0 0 0 0 0.007843 -2018 02 20 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.63 0.1367 0.008055 0.01917 0.01818 0.01992 0.006097 0.003388 0.002639 0.003079 0 0 0 0 0.008055 -2018 02 20 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.66 0.1365 0.008017 0.0196 0.01819 0.01979 0.005769 0.00331 0.002668 0.003111 0 0 0 0 0.008017 -2018 02 20 automated_test_3_uniform_drift_4ppc intel knl 1 16 8 0.89 0.1367 0.008249 0.01947 0.01818 0.01956 0.005585 0.003341 0.002697 0.003217 0 0 0 0 0.008249 -2018 02 20 automated_test_4_labdiags_2ppc intel knl 1 16 8 1.14 0.3087 0.04174 0.0637 0.0734 0.00345 0.002967 0.0001664 0.0001849 0.008714 0.05156 0.001539 0 0.0004984 0.04174 -2018 02 20 automated_test_4_labdiags_2ppc intel knl 1 16 8 1.21 0.3407 0.07513 0.07261 0.0713 0.003428 0.002994 0.0001638 0.0001848 0.009408 0.003442 0.00173 0 0.0005256 0.07513 -2018 02 20 automated_test_4_labdiags_2ppc intel knl 1 16 8 1.73 0.347 0.04077 0.06476 0.07148 0.00345 0.002998 0.0001637 0.0001829 0.009379 0.03947 0.001574 0 0.04989 0.04077 -2018 02 20 automated_test_4_labdiags_2ppc intel knl 1 16 8 1.52 0.3469 0.04088 0.06365 0.07183 0.003493 0.002957 0.0001659 0.0001827 0.009064 0.04694 0.001959 0 0.04099 0.04088 -2018 02 20 automated_test_5_loadimbalance intel knl 1 16 8 9.92 0.4206 0.08811 0.1186 0.1402 0 0 0 0 0.01443 0 0 0 0 0.08811 -2018 02 20 automated_test_5_loadimbalance intel knl 1 16 8 9.12 0.3884 0.08626 0.1027 0.1305 0 0 0 0 0.01368 0 0 0 0 0.08626 -2018 02 20 automated_test_5_loadimbalance intel knl 1 16 8 9.91 0.4097 0.08598 0.1119 0.1381 0 0 0 0 0.01414 0 0 0 0 0.08598 -2018 02 20 automated_test_5_loadimbalance intel knl 1 16 8 9.63 0.4257 0.0876 0.1213 0.1441 0 0 0 0 0.01422 0 0 0 0 0.0876 -2018 02 20 automated_test_6_output_2ppc intel knl 1 16 8 1.23 0.274 0.003227 0.03782 0.01724 0.01945 0.003219 0.001468 0.0014 0.01094 0.03943 0.0175 0 0.00509 0.001122 -2018 02 20 automated_test_6_output_2ppc intel knl 1 16 8 2.076 0.3023 0.002995 0.035 0.01619 0.02462 0.01126 0.006984 0.001548 0.01009 0.04604 0.01734 0 0.08398 0.001151 -2018 02 20 automated_test_6_output_2ppc intel knl 1 16 8 1.378 0.273 0.004545 0.03721 0.01754 0.02039 0.003415 0.00145 0.001561 0.01058 0.04009 0.01763 0 0.002519 0.001187 -2018 02 20 automated_test_6_output_2ppc intel knl 1 16 8 1.61 0.2911 0.004065 0.03726 0.01782 0.02439 0.01289 0.003463 0.001689 0.008778 0.03975 0.01723 0 0.00247 0.00129 diff --git a/Tools/PerformanceTests/run_alltests.py b/Tools/PerformanceTests/run_alltests.py deleted file mode 100644 index b1083fc6f45..00000000000 --- a/Tools/PerformanceTests/run_alltests.py +++ /dev/null @@ -1,353 +0,0 @@ -# Copyright 2017-2020 Luca Fedeli, Maxence Thevenet, Remi Lehe -# -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import argparse -import datetime -import os -import re -import shutil -import time - -from functions_perftest import * - -# This script runs automated performance tests for WarpX. -# It runs tests in list test_list defined below, and write -# results in file performance_log.txt in warpx/Tools/PerformanceTests/ - -# ---- User's manual ---- -# Before running performance tests, make sure you have the latest version -# of performance_log.txt -# A typical execution reads: -# > python run_alltests.py --no-recompile --compiler=gnu --architecture=cpu --mode=run --log_file='my_performance_log.txt' -# These are default values, and will give the same result as -# > python run_alltests.py -# To add a new test item, extent the test_list with a line like -# test_list.extend([['my_input_file', n_node, n_mpi, n_omp]]*3) -# - my_input_file must be in warpx/Tools/PerformanceTests -# - the test will run 3 times, to have some statistics -# - the test must take <1h or it will timeout - -# ---- Developer's manual ---- -# This script can run in two modes: -# - 'run' mode: for each test item, a batch job is executed. -# create folder '$SCRATCH/performance_warpx/' -# recompile the code if option --recompile is used -# loop over test_list and submit one batch script per item -# Submit a batch job that executes the script in read mode -# This last job runs once all others are completed -# - 'read' mode: Get performance data from all test items -# create performance log file if does not exist -# loop over test_file -# read initialization time and step time -# write data into the performance log file -# push file performance_log.txt on the repo - -# Define the list of tests to run -# ------------------------------- -# each element of test_list contains -# [str runname, int n_node, int n_mpi PER NODE, int n_omp] -test_list = [] -n_repeat = 3 - -test_list.extend([['ompscaling_32ppc' , 1, 1, 1]]*n_repeat) -test_list.extend([['ompscaling_32ppc' , 1, 1, 2]]*n_repeat) -test_list.extend([['ompscaling_32ppc' , 1, 1, 4]]*n_repeat) -test_list.extend([['ompscaling_32ppc' , 1, 1, 8]]*n_repeat) -test_list.extend([['ompscaling_32ppc' , 1, 1, 16]]*n_repeat) -test_list.extend([['ompscaling_32ppc' , 1, 1, 32]]*n_repeat) -test_list.extend([['ompscaling_32ppc' , 1, 1, 64]]*n_repeat) -test_list.extend([['ompscaling_32ppc' , 1, 1,128]]*n_repeat) -test_list.extend([['ompscaling_32ppc' , 1, 1,256]]*n_repeat) - -#test_list.extend([['mil_weak1_0ppc_1' , 1, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_0ppc_8' , 8, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_0ppc_64' , 64, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_0ppc_512' , 512, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_0ppc_1024' , 1024, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_0ppc_2048' , 2048, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_0ppc_4096' , 4096, 8, 8]]*n_repeat) - -#test_list.extend([['mil_weak1_32ppc_1' , 1, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_32ppc_8' , 8, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_32ppc_64' , 64, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_32ppc_512' , 512, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_32ppc_1024' , 1024, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_32ppc_2048' , 2048, 8, 8]]*n_repeat) -#test_list.extend([['mil_weak1_32ppc_4096' , 4096, 8, 8]]*n_repeat) - -#test_list.extend([['strong_32ppc1' , 1, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc1' , 8, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc1' , 64, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc1' , 128, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc128' , 128, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc128' , 256, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc128' , 512, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc128' , 1024, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc128' , 2048, 8, 8]]*n_repeat) -#test_list.extend([['strong_32ppc128' , 4096, 8, 8]]*n_repeat) - -#test_list.extend([['strong1_0ppc_1' , 1, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_1' , 8, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_1' , 64, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_1' , 128, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_1' , 256, 8, 8]]*n_repeat) - -#test_list.extend([['strong1_0ppc_128' , 128, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_128' , 256, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_128' , 512, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_128' , 1024, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_128' , 2048, 8, 8]]*n_repeat) -#test_list.extend([['strong1_0ppc_128' , 4096, 8, 8]]*n_repeat) - -n_tests = len(test_list) - -# Read command-line arguments -# --------------------------- -# Create parser and read arguments -parser = argparse.ArgumentParser( - description='Run performance tests and write results in files') -parser.add_argument('--recompile', dest='recompile', action='store_true', default=False) -parser.add_argument('--no-recompile', dest='recompile', action='store_false', default=False) -parser.add_argument('--commit', dest='commit', action='store_true', default=False) -parser.add_argument( '--compiler', choices=['gnu', 'intel'], default='gnu', - help='which compiler to use') -parser.add_argument( '--architecture', choices=['cpu', 'knl'], default='cpu', - help='which architecture to cross-compile for NERSC machines') -parser.add_argument( '--mode', choices=['run', 'read'], default='run', - help='whether to run perftests or read their perf output. run calls read') -parser.add_argument( '--log_file', dest = 'log_file', default='my_performance_log.txt', - help='name of log file where data will be written. ignored if option --commit is used') -parser.add_argument( '--n_steps', dest = 'n_steps', default=None, - help='Number of time steps in the simulation. Should be read automatically from the input file') - -args = parser.parse_args() - -log_file = args.log_file -if args.commit == True: - log_file = 'performance_log.txt' - -# Dictionaries -# compiler names. Used for WarpX executable name -compiler_name = {'intel': 'intel', 'gnu': 'gcc'} -# architecture. Used for WarpX executable name -module_name = {'cpu': 'haswell', 'knl': 'mic-knl'} -# architecture. Used in batch scripts -module_Cname = {'cpu': 'haswell', 'knl': 'knl,quad,cache'} -# Define environment variables -cwd = os.getcwd() + '/' -res_dir_base = os.environ['SCRATCH'] + '/performance_warpx/' -bin_dir = cwd + 'Bin/' -bin_name = 'perf_tests3d.' + args.compiler + '.' + module_name[args.architecture] + '.TPROF.MTMPI.OMP.QED.ex' -log_dir = cwd - -perf_database_file = cwd + 'perf_database_warpx.h5' -do_rename = False -store_test = False - -day = time.strftime('%d') -month = time.strftime('%m') -year = time.strftime('%Y') - -# Initialize tests -# ---------------- -if args.mode == 'run': -# Set default options for compilation and execution - config_command = '' - config_command += 'module unload darshan;' - config_command += 'module load craype-hugepages4M;' - if args.architecture == 'knl': - if args.compiler == 'intel': - config_command += 'module unload PrgEnv-gnu;' - config_command += 'module load PrgEnv-intel;' - elif args.compiler == 'gnu': - config_command += 'module unload PrgEnv-intel;' - config_command += 'module load PrgEnv-gnu;' - config_command += 'module unload craype-haswell;' - config_command += 'module load craype-mic-knl;' - elif args.architecture == 'cpu': - if args.compiler == 'intel': - config_command += 'module unload PrgEnv-gnu;' - config_command += 'module load PrgEnv-intel;' - elif args.compiler == 'gnu': - config_command += 'module unload PrgEnv-intel;' - config_command += 'module load PrgEnv-gnu;' - config_command += 'module unload craype-mic-knl;' - config_command += 'module load craype-haswell;' - # Create main result directory if does not exist - if not os.path.exists(res_dir_base): - os.mkdir(res_dir_base) - -# Recompile if requested -if args.recompile == True: - with open(cwd + 'GNUmakefile_perftest') as makefile_handler: - makefile_text = makefile_handler.read() - makefile_text = re.sub('\nCOMP.*', '\nCOMP=%s' %compiler_name[args.compiler], makefile_text) - with open(cwd + 'GNUmakefile_perftest', 'w') as makefile_handler: - makefile_handler.write( makefile_text ) - os.system(config_command + " make -f GNUmakefile_perftest realclean ; " + " rm -r tmp_build_dir *.mod; make -j 8 -f GNUmakefile_perftest") - -# Define functions to run a test and analyse results -# -------------------------------------------------- -def process_analysis(): - dependencies = '' - f_log = open(cwd + 'log_jobids_tmp.txt','r') - for count, current_run in enumerate(test_list): - line = f_log.readline() - print(line) - dependencies += line.split()[3] + ':' - batch_string = '' - batch_string += '#!/bin/bash\n' - batch_string += '#SBATCH --job-name=warpx_read\n' - batch_string += '#SBATCH --time=00:05:00\n' - batch_string += '#SBATCH -C ' + module_Cname[args.architecture] + '\n' - batch_string += '#SBATCH -N 1\n' - batch_string += '#SBATCH -S 4\n' - batch_string += '#SBATCH -q regular\n' - batch_string += '#SBATCH -e read_error.txt\n' - batch_string += '#SBATCH -o read_output.txt\n' - batch_string += '#SBATCH --mail-type=end\n' - batch_string += '#SBATCH --account=m2852\n' - batch_string += 'python ' + __file__ + ' --no-recompile --compiler=' + \ - args.compiler + ' --architecture=' + args.architecture + \ - ' --mode=read' + ' --log_file=' + log_file - if args.commit == True: - batch_string += ' --commit' - batch_string += '\n' - batch_file = 'slurm_perfread' - f_exe = open(batch_file,'w') - f_exe.write(batch_string) - f_exe.close() - os.system('chmod 700 ' + batch_file) - os.system('sbatch --dependency afterok:' + dependencies[0:-1] + ' ' + batch_file) - return 0 - -# Loop over the tests and return run time + details -# ------------------------------------------------- -if args.mode == 'run': - # Remove file log_jobids_tmp.txt if exists. - # This file contains the jobid of every perf test - # It is used to manage the analysis script dependencies - if os.path.isfile(cwd + 'log_jobids_tmp.txt'): - os.remove(cwd + 'log_jobids_tmp.txt') - for count, current_run in enumerate(test_list): - # Results folder - print('run ' + str(current_run)) - run_name = current_run[0] - n_node = current_run[1] - n_mpi = current_run[2] - n_omp = current_run[3] - n_steps = get_nsteps(cwd + run_name) - res_dir = res_dir_base - res_dir += '_'.join([run_name, args.compiler,\ - args.architecture, str(n_node), str(n_mpi),\ - str(n_omp), str(count)]) + '/' - # Run the simulation. - # If you are currently in an interactive session and want to run interactive, - # just replace run_batch with run_interactive - run_batch(run_name, res_dir, bin_name, config_command, architecture=args.architecture, \ - Cname=module_Cname[args.architecture], n_node=n_node, n_mpi=n_mpi, n_omp=n_omp) - os.chdir(cwd) - process_analysis() - -if args.mode == 'read': - # Create log_file for performance tests if does not exist - if not os.path.isfile(log_dir + log_file): - log_line = '## year month day run_name compiler architecture n_node n_mpi ' +\ - 'n_omp time_initialization time_one_iteration Redistribute '+\ - 'FillBoundary ParallelCopy CurrentDeposition FieldGather '+\ - 'ParticlePush Copy Evolve Checkpoint '+\ - 'WriteParticles Write_FabArray '+\ - 'WriteMultiLevelPlotfile '+\ - 'RedistributeMPI(unit: second)\n' - f_log = open(log_dir + log_file, 'a') - f_log.write(log_line) - f_log.close() - for count, current_run in enumerate(test_list): - # Results folder - print('read ' + str(current_run)) - run_name = current_run[0] - n_node = current_run[1] - n_mpi = current_run[2] - n_omp = current_run[3] - if args.n_steps is None: - n_steps = get_nsteps(cwd + run_name) - else: - n_steps = int(args.n_steps) - res_dir = res_dir_base - res_dir += '_'.join([run_name, args.compiler,\ - args.architecture, str(n_node), str(n_mpi),\ - str(n_omp), str(count)]) + '/' - # Read to store in text file - # -------------------------- - output_filename = 'perf_output.txt' - timing_list = read_run_perf(res_dir + output_filename, n_steps) - # Write performance data to the performance log file - log_line = ' '.join([year, month, day, run_name, args.compiler,\ - args.architecture, str(n_node), str(n_mpi),\ - str(n_omp)] + timing_list + ['\n']) - write_perf_logfile(log_dir + log_file, log_line) - - # Read data for all test to put in hdf5 a database - # ------------------------------------------------ - # This is an hdf5 file containing ALL the simulation parameters and results. Might be too large for a repo - df_newline = extract_dataframe(res_dir + 'perf_output.txt', n_steps) - # Add all simulation parameters to the dataframe - df_newline['run_name'] = run_name - df_newline['n_node'] = n_node - df_newline['n_mpi'] = n_mpi - df_newline['n_omp'] = n_omp - df_newline['n_steps'] = n_steps - df_newline['rep'] = count - df_newline['date'] = datetime.datetime.now() - input_file = open(cwd + run_name, 'r') - input_file_content = input_file.read() - input_file.close() - df_newline['inputs_content'] = input_file_content - if os.path.exists(perf_database_file): - df_base = pd.read_hdf(perf_database_file, 'all_data') - updated_df = df_base.append(df_newline, ignore_index=True) - else: - updated_df = df_newline - updated_df.to_hdf(perf_database_file, key='all_data', mode='w') - - # Store test parameters for record if requested - if store_test == True: - dir_record_base = './perf_warpx_record/' - if not os.path.exists(dir_record_base): - os.mkdir(dir_record_base) - count = 0 - dir_record = dir_record_base + '_'.join([year, month, day]) + '_0' - while os.path.exists(dir_record): - dir_record = dir_record[:-1] + str(count) - os.mkdir(dir_record) - shutil.copy(__file__, dir_record) - shutil.copy(log_dir + log_file, dir_record) - for count, current_run in enumerate(test_list): - shutil.copy(current_run[0], dir_record) - - if do_rename == True: - # Rename files if requested - for count, current_run in enumerate(test_list): - run_name = current_run[0] - n_node = current_run[1] - n_mpi = current_run[2] - n_omp = current_run[3] - res_dir = res_dir_base - res_dir += '_'.join([run_name, args.compiler,\ - args.architecture, str(n_node), str(n_mpi),\ - str(n_omp), str(count)]) + '/' - res_dir_arch = res_dir_base - res_dir_arch += '_'.join([year, month, day, run_name, args.compiler,\ - args.architecture, str(n_node), str(n_mpi), \ - str(n_omp), str(count)]) + '/' - os.rename(res_dir, res_dir_arch) - - # Commit results to the Repo - if args.commit == True: - os.system('git add ' + log_dir + log_file + ';'\ - 'git commit -m "performance tests";'\ - 'git push -u origin development') diff --git a/Tools/PerformanceTests/run_alltests_1node.py b/Tools/PerformanceTests/run_alltests_1node.py deleted file mode 100644 index f112552b36e..00000000000 --- a/Tools/PerformanceTests/run_alltests_1node.py +++ /dev/null @@ -1,362 +0,0 @@ -# Copyright 2018-2020 Luca Fedeli, Maxence Thevenet -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import argparse -import datetime -import os -import re -import shutil -import time - -from functions_perftest import * - -# This script runs automated performance tests for WarpX. -# It runs tests in list test_list defined below, and write -# results in file performance_log.txt in warpx/Tools/PerformanceTests/ - -# ---- User's manual ---- -# Before running performance tests, make sure you have the latest version -# of performance_log.txt - -# ---- Running a custom set of performance tests ---- -# > python run_alltests_1node.py --no-recompile --compiler=intel -# > --architecture=knl --mode=run --input_file=uniform_plasma -# > --n_node=1 --log_file='my_performance_log.txt' - -# ---- Running the pre-defined automated tests ---- -# Compile and run: -# > python run_alltests_1node.py --automated --recompile -# Just run: -# > python run_alltests_1node.py --automated - -# To add a new test item, extent the test_list with a line like -# test_list.extend([['my_input_file', n_node, n_mpi, n_omp]]*n_repeat) -# - my_input_file must be in warpx/Tools/PerformanceTests - -# ---- Developer's manual ---- -# This script can run in two modes: -# - 'run' mode: for each test item, a batch job is executed. -# create folder '$SCRATCH/performance_warpx/' -# recompile the code if option --recompile is used -# loop over test_list and submit one batch script per item -# Submit a batch job that executes the script in read mode -# This last job runs once all others are completed -# - 'read' mode: Get performance data from all test items -# create performance log file if does not exist -# loop over test_file -# read initialization time and step time -# write data into the performance log file -# push file performance_log.txt on the repo - -# Read command-line arguments -# --------------------------- -# Create parser and read arguments -parser = argparse.ArgumentParser( - description='Run performance tests and write results in files') -parser.add_argument('--recompile', dest='recompile', action='store_true', default=False) -parser.add_argument('--no-recompile', dest='recompile', action='store_false', default=False) -parser.add_argument('--commit', dest='commit', action='store_true', default=False) -parser.add_argument( '--compiler', choices=['gnu', 'intel'], default='intel', - help='which compiler to use') -parser.add_argument( '--architecture', choices=['cpu', 'knl'], default='knl', - help='which architecture to cross-compile for NERSC machines') -parser.add_argument( '--mode', choices=['run', 'read'], default='run', - help='whether to run perftests or read their perf output. run calls read') -parser.add_argument( '--log_file', dest = 'log_file', default='my_performance_log.txt', - help='name of log file where data will be written. ignored if option --commit is used') -parser.add_argument('--n_node', dest='n_node', default=1, help='nomber of nodes for the runs') -parser.add_argument('--input_file', dest='input_file', default='input_file.pixr', - type=str, help='input file to run') -parser.add_argument('--automated', dest='automated', action='store_true', default=False, - help='Use to run the automated test list') - -args = parser.parse_args() -log_file = args.log_file -do_commit = args.commit -run_name = args.input_file - -# list of tests to run and analyse. -# Note: This is overwritten if option --automated is used -# each element of test_list contains -# [str input_file, int n_node, int n_mpi PER NODE, int n_omp] -test_list = [] -n_repeat = 2 -filename1 = args.input_file -test_list.extend([[filename1, 1, 128, 1]]*n_repeat) -test_list.extend([[filename1, 1, 64, 2]]*n_repeat) - -# Nothing should be changed after this line -# if flag --automated is used, test_list and do_commit are -# overwritten - -if args.automated == True: - test_list = [] - n_repeat = 2 - test_list.extend([['automated_test_1_uniform_rest_32ppc', 1, 16, 8]]*n_repeat) - test_list.extend([['automated_test_2_uniform_rest_1ppc', 1, 16, 8]]*n_repeat) - test_list.extend([['automated_test_3_uniform_drift_4ppc', 1, 16, 8]]*n_repeat) - test_list.extend([['automated_test_4_labdiags_2ppc', 1, 16, 8]]*n_repeat) - test_list.extend([['automated_test_5_loadimbalance', 1, 16, 8]]*n_repeat) - test_list.extend([['automated_test_6_output_2ppc', 1, 16, 8]]*n_repeat) - do_commit = False - run_name = 'automated_tests' - -n_tests = len(test_list) -if do_commit == True: - log_file = 'performance_log.txt' - -# Dictionaries -# compiler names. Used for WarpX executable name -compiler_name = {'intel': 'intel', 'gnu': 'gcc'} -# architecture. Used for WarpX executable name -module_name = {'cpu': 'haswell', 'knl': 'mic-knl'} -# architecture. Used in batch scripts -module_Cname = {'cpu': 'haswell', 'knl': 'knl,quad,cache'} -# Define environment variables -cwd = os.getcwd() + '/' -res_dir_base = os.environ['SCRATCH'] + '/performance_warpx/' -bin_dir = cwd + 'Bin/' -bin_name = 'perf_tests3d.' + args.compiler + '.' + module_name[args.architecture] + '.TPROF.MTMPI.OMP.QED.ex' -log_dir = cwd - -day = time.strftime('%d') -month = time.strftime('%m') -year = time.strftime('%Y') -n_node = int(args.n_node) - -perf_database_file = cwd + 'perf_database_warpx.h5' - -# Initialize tests -# ---------------- -if args.mode == 'run': -# Set default options for compilation and execution - config_command = '' - config_command += 'module unload darshan;' - config_command += 'module load craype-hugepages4M;' - if args.architecture == 'knl': - if args.compiler == 'intel': - config_command += 'module unload PrgEnv-gnu;' - config_command += 'module load PrgEnv-intel;' - elif args.compiler == 'gnu': - config_command += 'module unload PrgEnv-intel;' - config_command += 'module load PrgEnv-gnu;' - config_command += 'module unload craype-haswell;' - config_command += 'module load craype-mic-knl;' - elif args.architecture == 'cpu': - if args.compiler == 'intel': - config_command += 'module unload PrgEnv-gnu;' - config_command += 'module load PrgEnv-intel;' - elif args.compiler == 'gnu': - config_command += 'module unload PrgEnv-intel;' - config_command += 'module load PrgEnv-gnu;' - config_command += 'module unload craype-mic-knl;' - config_command += 'module load craype-haswell;' - # Create main result directory if does not exist - if not os.path.exists(res_dir_base): - os.mkdir(res_dir_base) - -# Recompile if requested -if args.recompile == True: - with open(cwd + 'GNUmakefile_perftest') as makefile_handler: - makefile_text = makefile_handler.read() - makefile_text = re.sub('\nCOMP.*', '\nCOMP=%s' %compiler_name[args.compiler], makefile_text) - with open(cwd + 'GNUmakefile_perftest', 'w') as makefile_handler: - makefile_handler.write( makefile_text ) - os.system(config_command + " make -f GNUmakefile_perftest realclean ; " + " rm -r tmp_build_dir *.mod; make -j 8 -f GNUmakefile_perftest") - -# This function runs a batch script with dependencies to perform the analysis -# when performance runs are done. -def process_analysis(): - dependencies = '' - f_log = open(cwd + 'log_jobids_tmp.txt','r') - line = f_log.readline() - print(line) - dependencies += line.split()[3] + ':' - batch_string = '' - batch_string += '#!/bin/bash\n' - batch_string += '#SBATCH --job-name=warpx_1node_read\n' - batch_string += '#SBATCH --time=00:05:00\n' - batch_string += '#SBATCH -C haswell\n' - batch_string += '#SBATCH -N 1\n' - batch_string += '#SBATCH -S 4\n' - batch_string += '#SBATCH -q regular\n' - batch_string += '#SBATCH -e read_error.txt\n' - batch_string += '#SBATCH -o read_output.txt\n' - batch_string += '#SBATCH --mail-type=end\n' - batch_string += '#SBATCH --account=m2852\n' - batch_string += 'python ' + __file__ + ' --no-recompile --compiler=' + \ - args.compiler + ' --architecture=' + args.architecture + \ - ' --mode=read' + ' --log_file=' + log_file + \ - ' --input_file=' + args.input_file - if do_commit == True: - batch_string += ' --commit' - if args.automated == True: - batch_string += ' --automated' - batch_string += '\n' - batch_file = 'slurm_perfread' - f_exe = open(batch_file,'w') - f_exe.write(batch_string) - f_exe.close() - os.system('chmod 700 ' + batch_file) - os.system('sbatch --dependency afterok:' + dependencies[0:-1] + ' ' + batch_file) - return 0 - -# Loop over the tests and return run time + details -# ------------------------------------------------- -if args.mode == 'run': - # Remove file log_jobids_tmp.txt if exists. - # This file contains the jobid of every perf test - # It is used to manage the analysis script dependencies - if os.path.isfile(cwd + 'log_jobids_tmp.txt'): - os.remove(cwd + 'log_jobids_tmp.txt') - res_dir = res_dir_base - res_dir += '_'.join([run_name, args.compiler,\ - args.architecture, str(n_node)]) + '/' - # Run the simulation. - run_batch_nnode(test_list, res_dir, bin_name, config_command,\ - architecture=args.architecture, Cname=module_Cname[args.architecture], \ - n_node=n_node) - os.chdir(cwd) - process_analysis() - -if args.mode == 'read': - # Create log_file for performance tests if does not exist - if not os.path.isfile(log_dir + log_file): - log_line = '## year month day input_file compiler architecture n_node n_mpi ' +\ - 'n_omp time_initialization time_one_iteration Redistribute '+\ - 'FillBoundary ParallelCopy CurrentDeposition FieldGather '+\ - 'ParthiclePush Copy Evolve Checkpoint '+\ - 'WriteParticles Write_FabArray '+\ - 'WriteMultiLevelPlotfile(unit: second) '+\ - 'RedistributeMPI\n' - f_log = open(log_dir + log_file, 'a') - f_log.write(log_line) - f_log.close() - for count, current_run in enumerate(test_list): - # Results folder - print('read ' + str(current_run)) - input_file = current_run[0] - # Do not read n_node = current_run[1], it is an external parameter - n_mpi = current_run[2] - n_omp = current_run[3] - n_steps = get_nsteps(cwd + input_file) - print('n_steps = ' + str(n_steps)) - res_dir = res_dir_base - res_dir += '_'.join([run_name, args.compiler,\ - args.architecture, str(n_node)]) + '/' - # Read performance data from the output file - output_filename = 'out_' + '_'.join([input_file, str(n_node), str(n_mpi), str(n_omp), str(count)]) + '.txt' - timing_list = read_run_perf(res_dir + output_filename, n_steps) - # Write performance data to the performance log file - log_line = ' '.join([year, month, day, input_file, args.compiler,\ - args.architecture, str(n_node), str(n_mpi),\ - str(n_omp)] + timing_list + ['\n']) - write_perf_logfile(log_dir + log_file, log_line) - # Read data for all test to put in hdf5 a database - # ------------------------------------------------ - # This is an hdf5 file containing ALL the simulation parameters and results. Might be too large for a repo - df_newline = extract_dataframe(res_dir + output_filename, n_steps) - # Add all simulation parameters to the dataframe - df_newline['run_name'] = run_name - df_newline['n_node'] = n_node - df_newline['n_mpi'] = n_mpi - df_newline['n_omp'] = n_omp - df_newline['n_steps'] = n_steps - df_newline['rep'] = count - df_newline['date'] = datetime.datetime.now() - input_file_open = open(cwd + input_file, 'r') - input_file_content = input_file_open.read() - input_file_open.close() - df_newline['inputs_content'] = input_file_content - if os.path.exists(perf_database_file): - df_base = pd.read_hdf(perf_database_file, 'all_data') - updated_df = df_base.append(df_newline, ignore_index=True) - else: - updated_df = df_newline - updated_df.to_hdf(perf_database_file, key='all_data', mode='w') - - # Store test parameters fot record - dir_record_base = './perf_warpx_record/' - if not os.path.exists(dir_record_base): - os.mkdir(dir_record_base) - count = 0 - dir_record = dir_record_base + '_'.join([year, month, day]) + '_0' - while os.path.exists(dir_record): - count += 1 - dir_record = dir_record[:-1] + str(count) - os.mkdir(dir_record) - shutil.copy(__file__, dir_record) - shutil.copy(log_dir + log_file, dir_record) - for count, current_run in enumerate(test_list): - shutil.copy(current_run[0], dir_record) - - # Rename directory with precise date for archive purpose - res_dir_arch = res_dir_base - res_dir_arch += '_'.join([year, month, day, run_name, args.compiler,\ - args.architecture, str(n_node)]) + '/' - os.rename(res_dir, res_dir_arch) - - # Commit results to the Repo - if do_commit == True: - os.system('git add ' + log_dir + log_file + ';'\ - 'git commit -m "performance tests";'\ - 'git push -u origin development') - - # Plot file - import matplotlib - import numpy as np - matplotlib.use('Agg') - import matplotlib.pyplot as plt - filename0 = 'my_performance_log' - filename = filename0 + '.txt' - fontsize = 14 - matplotlib.rcParams.update({'font.size': fontsize}) - nsteps = 100. - nrepeat = 4 - legends = [ 'n_node', 'n_mpi', 'n_omp', 'time_initialization', 'time_one_iteration', \ - 'Redistribute', 'FillBoundary', 'ParallelCopy', 'CurrentDeposition', \ - 'FieldGather', 'ParthiclePush', 'Copy', 'Evolve', 'Checkpoint', \ - 'WriteParticles', 'Write_FabArray', 'WriteMultiLevelPlotfile', \ - 'RedistributeMPI'] - date = np.loadtxt( filename, usecols = np.arange(0, 3 )) - data = np.loadtxt( filename, usecols = np.arange(6, 6+len(legends)) ) - # Read run name - with open(filename) as f: - namelist_tmp = zip(*[line.split() for line in f])[3] - # Remove first line = comments - namelist = list(namelist_tmp[1:]) - selector_list = ['automated_test_1_uniform_rest_32ppc',\ - 'automated_test_2_uniform_rest_1ppc',\ - 'automated_test_3_uniform_drift_4ppc',\ - 'automated_test_4_labdiags_2ppc',\ - 'automated_test_5_loadimbalance',\ - 'automated_test_6_output_2ppc'] - selector_string = selector_list[0] - selector = [idx for idx in range(len(namelist)) if selector_string in namelist[idx]] - lin_date = date[:,0]+date[:,1]/12.+date[:,2]/366. - unique_lin_date = np.unique(lin_date) - my_xticks = unique_lin_date -# cmap = plt.get_cmap("tab20") - cycle = plt.rcParams['axes.prop_cycle'].by_key()['color'] - for selector_string in selector_list: - selector = [idx for idx in range(len(namelist)) if selector_string in namelist[idx]] - plt.figure(num=0, figsize=(8,4)) - plt.clf() - plt.title('warpx ' + selector_string) - for i in np.arange(data.shape[1]): - icolors = i-3 - if i>3 and (data[selector,i] > 5./100*data[selector,4]).any(): - plt.plot(lin_date[selector], data[selector,i],'+', ms=6, \ - mew=2, label=legends[i] ) - # plt.plot(lin_date[selector], data[selector,i],'+', ms=6, \ - # mew=2, label=legends[i], color=cmap(i) ) - plt.xlabel('date') - plt.ylabel('time/step (s)') - plt.grid() - plt.legend(loc='best') - plt.legend(bbox_to_anchor=(1.1, 1.05)) - plt.savefig( selector_string + '.pdf', bbox_inches='tight') - plt.savefig( selector_string + '.png', bbox_inches='tight') diff --git a/Tools/PerformanceTests/run_automated.py b/Tools/PerformanceTests/run_automated.py deleted file mode 100644 index f03ead05376..00000000000 --- a/Tools/PerformanceTests/run_automated.py +++ /dev/null @@ -1,350 +0,0 @@ -# Copyright 2018-2019 Axel Huebl, Luca Fedeli, Maxence Thevenet -# -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -import argparse -import copy -import datetime -import os -import shutil -import sys -import time - -import git -import pandas as pd -from functions_perftest import ( - extract_dataframe, - get_file_content, - run_batch_nnode, - store_git_hash, -) - -# Get name of supercomputer and import configuration functions from -# machine-specific file -if os.getenv("LMOD_SYSTEM_NAME") == 'summit': - machine = 'summit' - from summit import ( - executable_name, - get_batch_string, - get_config_command, - get_run_string, - get_submit_job_command, - get_test_list, - process_analysis, - time_min, - ) -if os.getenv("NERSC_HOST") == 'cori': - machine = 'cori' - from cori import ( - executable_name, - get_batch_string, - get_config_command, - get_run_string, - get_submit_job_command, - get_test_list, - process_analysis, - time_min, - ) - -# typical use: python run_automated.py --n_node_list='1,8,16,32' --automated -# Assume warpx, picsar, amrex and perf_logs repos ar in the same directory and -# environment variable AUTOMATED_PERF_TESTS contains the path to this directory - -# requirements: -# - python packages: gitpython and pandas -# - AUTOMATED_PERF_TESTS: environment variables where warpx, -# amrex and picsar are installed ($AUTOMATED_PERF_TESTS/warpx etc.) -# - SCRATCH: environment variable where performance results are written. -# This script will create folder $SCRATCH/performance_warpx/ - -if "AUTOMATED_PERF_TESTS" not in os.environ: - raise ValueError("environment variable AUTOMATED_PERF_TESTS is not defined.\n" - "It should contain the path to the directory where WarpX, " - "AMReX and PICSAR repos are.") -if "SCRATCH" not in os.environ: - raise ValueError("environment variable SCRATCH is not defined.\n" - "This script will create $SCRATCH/performance_warpx/ " - "to store performance results.") -# Handle parser -############### -parser = argparse.ArgumentParser( description='Run performance tests and write results in files' ) -parser.add_argument('--recompile', - dest='recompile', - action='store_true', - default=False) -parser.add_argument('--commit', - dest='commit', - action='store_true', - default=False) -parser.add_argument('--automated', - dest='automated', - action='store_true', - default=False, - help='Use to run the automated test list') -parser.add_argument('--n_node_list', - dest='n_node_list', - default=[], - help='list of number of nodes for the runs', type=str) -parser.add_argument('--start_date', - dest='start_date' ) -parser.add_argument('--compiler', - choices=['gnu', 'intel', 'pgi'], - default='intel', - help='which compiler to use') -parser.add_argument('--architecture', - choices=['cpu', 'knl', 'gpu'], - default='knl', - help='which architecture to cross-compile for NERSC machines') -parser.add_argument('--mode', - choices=['run', 'read', 'browse_output_files'], - default='run', - help='whether to run perftests or read their perf output. run calls read') -parser.add_argument('--path_source', - default=None, - help='path to parent folder containing amrex, picsar and warpx folders') -parser.add_argument('--path_results', - default=None, - help='path to result directory, where simulations run') - -args = parser.parse_args() -n_node_list_string = args.n_node_list.split(',') -n_node_list = [int(i) for i in n_node_list_string] -start_date = args.start_date - -# Set behavior variables -######################## -run_name = 'custom_perftest' -perf_database_file = 'my_tests_database.h5' -rename_archive = False -store_full_input = False -update_perf_log_repo = False -push_on_perf_log_repo = False -recompile = args.recompile -pull_3_repos = False -recompile = True -compiler = args.compiler -architecture = args.architecture -source_dir_base = args.path_source -res_dir_base = args.path_results - -browse_output_files = False -if args.mode == 'browse_output_files': - browse_output_file = True -if args.mode == 'read': - browse_output_files = True - -if args.automated == True: - run_name = 'automated_tests' - perf_database_file = machine + '_results.h5' - rename_archive = True - store_full_input = False - update_perf_log_repo = True - push_on_perf_log_repo = False - pull_3_repos = True - recompile = True - source_dir_base = os.environ['AUTOMATED_PERF_TESTS'] - res_dir_base = os.environ['SCRATCH'] + '/performance_warpx/' - if machine == 'summit': - compiler = 'gnu' - architecture = 'gpu' - -# List of tests to perform -# ------------------------ -# Each test runs n_repeat times -n_repeat = 2 -# test_list is machine-specific -test_list = get_test_list(n_repeat) - -# Define directories -# ------------------ -warpx_dir = source_dir_base + '/warpx/' -picsar_dir = source_dir_base + '/picsar/' -amrex_dir = source_dir_base + '/amrex/' -perf_logs_repo = source_dir_base + 'perf_logs/' - -# Define dictionaries -# ------------------- -compiler_name = {'intel': 'intel', 'gnu': 'gcc', 'pgi':'pgi'} -module_Cname = {'cpu': 'haswell', 'knl': 'knl,quad,cache', 'gpu':''} -csv_file = {'cori':'cori_knl.csv', 'summit':'summit.csv'} -# cwd = os.getcwd() + '/' -cwd = warpx_dir + 'Tools/PerformanceTests/' - -path_hdf5 = cwd -if args.automated: - path_hdf5 = perf_logs_repo + '/logs_hdf5/' - -bin_dir = cwd + 'Bin/' -bin_name = executable_name(compiler, architecture) - -log_dir = cwd -day = time.strftime('%d') -month = time.strftime('%m') -year = time.strftime('%Y') - -# Initialize tests -# ---------------- -if args.mode == 'run': - start_date = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") - # Set default options for compilation and execution - config_command = get_config_command(compiler, architecture) - # Create main result directory if does not exist - if not os.path.exists(res_dir_base): - os.mkdir(res_dir_base) - - # Recompile if requested - # ---------------------- - if recompile == True: - if pull_3_repos == True: - git_repo = git.cmd.Git( picsar_dir ) - git_repo.pull() - git_repo = git.cmd.Git( amrex_dir ) - git_repo.pull() - git_repo = git.cmd.Git( warpx_dir ) - git_repo.pull() - - # Copy WarpX/GNUmakefile to current directory and recompile - # with specific options for automated performance tests. - # This way, performance test compilation does not mess with user's - # compilation - shutil.copyfile("../../GNUmakefile","./GNUmakefile") - make_realclean_command = " make realclean WARPX_HOME=../.. " \ - "AMREX_HOME=../../../amrex/ PICSAR_HOME=../../../picsar/ " \ - "EBASE=perf_tests COMP=%s" %compiler_name[compiler] + ";" - make_command = "make -j 16 WARPX_HOME=../.. " \ - "AMREX_HOME=../../../amrex/ PICSAR_HOME=../../../picsar/ " \ - "EBASE=perf_tests COMP=%s" %compiler_name[compiler] - if machine == 'summit': - make_command += ' USE_GPU=TRUE ' - os.system(config_command + make_realclean_command + \ - "rm -r tmp_build_dir *.mod; " + make_command ) - - # Store git hashes for WarpX, AMReX and PICSAR into file, so that - # they can be read when running the analysis. - if os.path.exists( cwd + 'store_git_hashes.txt' ): - os.remove( cwd + 'store_git_hashes.txt' ) - store_git_hash(repo_path=picsar_dir, filename=cwd + 'store_git_hashes.txt', name='picsar') - store_git_hash(repo_path=amrex_dir , filename=cwd + 'store_git_hashes.txt', name='amrex' ) - store_git_hash(repo_path=warpx_dir , filename=cwd + 'store_git_hashes.txt', name='warpx' ) - -# Loop over the tests and run all simulations: -# One batch job submitted per n_node. Several -# tests run within the same batch job. -# -------------------------------------------- -if args.mode == 'run': - if os.path.exists( 'log_jobids_tmp.txt' ): - os.remove( 'log_jobids_tmp.txt' ) - # loop on n_node. One batch script per n_node - for n_node in n_node_list: - res_dir = res_dir_base - res_dir += '_'.join([run_name, compiler, architecture, str(n_node)]) + '/' - runtime_param_list = [] - # Deep copy as we change the attribute n_cell of - # each instance of class test_element - test_list_n_node = copy.deepcopy(test_list) - job_time_min = time_min(len(test_list)) - batch_string = get_batch_string(test_list_n_node, job_time_min, module_Cname[architecture], n_node) - # Loop on tests - for count, current_run in enumerate(test_list_n_node): - current_run.scale_n_cell(n_node) - runtime_param_string = ' amr.n_cell=' + ' '.join(str(i) for i in current_run.n_cell) - runtime_param_string += ' amr.max_grid_size=' + str(current_run.max_grid_size) - runtime_param_string += ' amr.blocking_factor=' + str(current_run.blocking_factor) - runtime_param_string += ' max_step=' + str( current_run.n_step ) - # runtime_param_list.append( runtime_param_string ) - run_string = get_run_string(current_run, architecture, n_node, count, bin_name, runtime_param_string) - batch_string += run_string - batch_string += 'rm -rf plotfiles lab_frame_data diags\n' - - submit_job_command = get_submit_job_command() - # Run the simulations. - run_batch_nnode(test_list_n_node, res_dir, cwd, bin_name, config_command, batch_string, submit_job_command) - os.chdir(cwd) - # submit batch for analysis - if os.path.exists( 'read_error.txt' ): - os.remove( 'read_error.txt' ) - if os.path.exists( 'read_output.txt' ): - os.remove( 'read_output.txt' ) - process_analysis(args.automated, cwd, compiler, architecture, - args.n_node_list, start_date, source_dir_base, res_dir_base) - -# read the output file from each test and store timers in -# hdf5 file with pandas format -# ------------------------------------------------------- -for n_node in n_node_list: - print(n_node) - if browse_output_files: - res_dir = res_dir_base - res_dir += '_'.join([run_name, compiler,\ - architecture, str(n_node)]) + '/' - for count, current_run in enumerate(test_list): - # Read performance data from the output file - output_filename = 'out_' + '_'.join([current_run.input_file, str(n_node), str(current_run.n_mpi_per_node), str(current_run.n_omp), str(count)]) + '.txt' - # Read data for all test to put in hdf5 a database - # This is an hdf5 file containing ALL the simulation - # parameters and results. Might be too large for a repo - df_newline = extract_dataframe(res_dir + output_filename, current_run.n_step) - # Add all simulation parameters to the dataframe - df_newline['git_hashes'] = get_file_content(filename=cwd+'store_git_hashes.txt') - df_newline['start_date'] = start_date - df_newline['run_name'] = run_name - df_newline['input_file'] = current_run.input_file - df_newline['n_node'] = n_node - df_newline['n_mpi_per_node'] = current_run.n_mpi_per_node - df_newline['n_omp'] = current_run.n_omp - df_newline['n_steps'] = current_run.n_step - df_newline['rep'] = count%n_repeat - df_newline['date'] = datetime.datetime.now() - if store_full_input: - df_newline['inputs_content'] = get_file_content( filename=cwd+current_run.input_file ) - # Load file perf_database_file if exists, and - # append with results from this scan - if os.path.exists(path_hdf5 + perf_database_file): - df_base = pd.read_hdf(path_hdf5 + perf_database_file, 'all_data') - updated_df = df_base.append(df_newline, ignore_index=True) - else: - updated_df = df_newline - # Write dataframe to file perf_database_file - # (overwrite if file exists) - updated_df.to_hdf(path_hdf5 + perf_database_file, key='all_data', mode='w', format='table') - -# Extract sub-set of pandas data frame, write it to -# csv file and copy this file to perf_logs repo -# ------------------------------------------------- -if args.mode=='read' and update_perf_log_repo: - # get perf_logs repo - git_repo = git.Repo( perf_logs_repo ) - if push_on_perf_log_repo: - git_repo.git.stash('save') - git_repo.git.pull() - os.chdir( perf_logs_repo ) - sys.path.append('./') - import write_csv - git_repo.git.add('./logs_csv/' + csv_file[machine]) - git_repo.git.add('./logs_hdf5/' + perf_database_file) - index = git_repo.index - index.commit("automated tests") - -# Rename all result directories for archiving purposes: -# include date in the name, and a counter to avoid over-writing -for n_node in n_node_list: - if browse_output_files: - res_dir = res_dir_base - res_dir += '_'.join([run_name, compiler,\ - architecture, str(n_node)]) + '/' - # Rename directory with precise date+hour for archive purpose - if rename_archive == True: - loc_counter = 0 - res_dir_arch = res_dir_base - res_dir_arch += '_'.join([year, month, day, run_name, compiler,\ - architecture, str(n_node), str(loc_counter)]) + '/' - while os.path.exists( res_dir_arch ): - loc_counter += 1 - res_dir_arch = res_dir_base - res_dir_arch += '_'.join([year, month, day, run_name, compiler,\ - architecture, str(n_node), str(loc_counter)]) + '/' - print("renaming " + res_dir + " -> " + res_dir_arch) - os.rename( res_dir, res_dir_arch ) diff --git a/Tools/PerformanceTests/summit.py b/Tools/PerformanceTests/summit.py deleted file mode 100644 index c2ba6c70a2e..00000000000 --- a/Tools/PerformanceTests/summit.py +++ /dev/null @@ -1,146 +0,0 @@ -# Copyright 2019 Axel Huebl, Luca Fedeli, Maxence Thevenet -# -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -# requirements: -# - module load python/3.7.0-anaconda3-5.3.0 - -import copy -import os - -from functions_perftest import test_element - - -def executable_name(compiler,architecture): - return 'perf_tests3d.' + compiler + '.TPROF.MTMPI.CUDA.QED.ex' - -def get_config_command(compiler, architecture): - config_command = '' - config_command += 'module load gcc;' - config_command += 'module load cuda;' - return config_command - -# This function runs a batch script with -# dependencies to perform the analysis -# after all performance tests are done. -def process_analysis(automated, cwd, compiler, architecture, n_node_list, start_date, path_source, path_results): - - batch_string = '''#!/bin/bash -#BSUB -P APH114 -#BSUB -W 00:10 -#BSUB -nnodes 1 -#BSUB -J perf_test -#BSUB -o read_output.txt -#BSUB -e read_error.txt -''' - f_log = open(cwd + 'log_jobids_tmp.txt' ,'r') - for line in f_log.readlines(): - dependency = line.split()[1][1:-1] - batch_string += '#BSUB -w ended(' + dependency + ')\n' - - batch_string += 'python run_automated.py --compiler=' + \ - compiler + ' --architecture=' + architecture + \ - ' --mode=read' + \ - ' --n_node_list=' + '"' + n_node_list + '"' + \ - ' --start_date=' + start_date + \ - ' --path_source=' + path_source + \ - ' --path_results=' + path_results - if automated == True: - batch_string += ' --automated' - batch_string += '\n' - batch_file = 'bsub_perfread' - f_exe = open(batch_file,'w') - f_exe.write(batch_string) - f_exe.close() - os.system('chmod 700 ' + batch_file) - print( 'process_analysis line: ' + 'bsub ' + batch_file) - os.system('bsub ' + batch_file) - -# Calculate simulation time. Take 2 min + 2 min / simulation -def time_min(nb_simulations): - return 2. + nb_simulations*2. - -def get_submit_job_command(): - return ' bsub ' - -def get_batch_string(test_list, job_time_min, Cname, n_node): - - job_time_str = str(int(job_time_min/60)) + ':' + str(int(job_time_min%60)) - - batch_string = '' - batch_string += '#!/bin/bash\n' - batch_string += '#BSUB -P APH114\n' - batch_string += '#BSUB -W ' + job_time_str + '\n' - batch_string += '#BSUB -nnodes ' + str(n_node) + '\n' - batch_string += '#BSUB -J ' + test_list[0].input_file + '\n' - batch_string += '#BSUB -e error.txt\n' - batch_string += 'module load gcc\n' - batch_string += 'module load cuda\n' - return batch_string - -def get_run_string(current_test, architecture, n_node, count, bin_name, runtime_param_string): - - output_filename = 'out_' + '_'.join([current_test.input_file, str(n_node), str(current_test.n_mpi_per_node), str(current_test.n_omp), str(count)]) + '.txt' - - ngpu = str(current_test.n_mpi_per_node) - srun_string = '' - srun_string += 'jsrun ' - srun_string += ' -n ' + str(n_node) - srun_string += ' -a ' + ngpu + ' -g ' + ngpu + ' -c ' + ngpu + ' --bind=packed:1 ' - srun_string += ' ./' + bin_name + ' ' - srun_string += current_test.input_file + ' ' - srun_string += runtime_param_string - srun_string += ' > ' + output_filename + '\n' - return srun_string - -def get_test_list(n_repeat): - test_list_unq = [] - # n_node is kept to None and passed in functions as an external argument - # That way, several test_element_instance run with the same n_node on the same batch job - test_list_unq.append( test_element(input_file='automated_test_1_uniform_rest_32ppc', - n_mpi_per_node=6, - n_omp=1, - n_cell=[128, 128, 192], - max_grid_size=256, - blocking_factor=32, - n_step=10) ) - test_list_unq.append( test_element(input_file='automated_test_2_uniform_rest_1ppc', - n_mpi_per_node=6, - n_omp=1, - n_cell=[256, 512, 768], - max_grid_size=512, - blocking_factor=256, - n_step=10) ) - test_list_unq.append( test_element(input_file='automated_test_3_uniform_drift_4ppc', - n_mpi_per_node=6, - n_omp=1, - n_cell=[128, 128, 384], - max_grid_size=256, - blocking_factor=64, - n_step=10) ) - test_list_unq.append( test_element(input_file='automated_test_4_labdiags_2ppc', - n_mpi_per_node=6, - n_omp=1, - n_cell=[384, 256, 512], - max_grid_size=256, - blocking_factor=128, - n_step=50) ) - test_list_unq.append( test_element(input_file='automated_test_5_loadimbalance', - n_mpi_per_node=6, - n_omp=1, - n_cell=[64, 64, 192], - max_grid_size=64, - blocking_factor=32, - n_step=10) ) - test_list_unq.append( test_element(input_file='automated_test_6_output_2ppc', - n_mpi_per_node=6, - n_omp=1, - n_cell=[384, 256, 512], - max_grid_size=256, - blocking_factor=64, - n_step=1) ) - test_list = [copy.deepcopy(item) for item in test_list_unq for _ in range(n_repeat) ] - return test_list diff --git a/Tools/PostProcessing/Visualization.ipynb b/Tools/PostProcessing/Visualization.ipynb index ef05b69c2c0..848beb57256 100644 --- a/Tools/PostProcessing/Visualization.ipynb +++ b/Tools/PostProcessing/Visualization.ipynb @@ -16,10 +16,11 @@ "outputs": [], "source": [ "# Import statements\n", - "import yt ; yt.funcs.mylog.setLevel(50)\n", - "import numpy as np\n", - "import scipy.constants as scc\n", + "import yt\n", + "\n", + "yt.funcs.mylog.setLevel(50)\n", "import matplotlib.pyplot as plt\n", + "\n", "%matplotlib notebook" ] }, @@ -45,12 +46,12 @@ "metadata": {}, "outputs": [], "source": [ - "diag_name = 'diag' # E.g., diagnostics.diags_names = diag\n", + "diag_name = \"diag\" # E.g., diagnostics.diags_names = diag\n", "iteration = 0\n", - "plotfile = './diags/{}{:05d}'.format(diag_name, iteration)\n", - "field = 'Ex'\n", - "species = 'electron'\n", - "ds = yt.load( plotfile ) # Load the plotfile\n", + "plotfile = \"./diags/{}{:05d}\".format(diag_name, iteration)\n", + "field = \"Ex\"\n", + "species = \"electron\"\n", + "ds = yt.load(plotfile) # Load the plotfile\n", "# ds.field_list # Print all available quantities" ] }, @@ -67,10 +68,10 @@ "metadata": {}, "outputs": [], "source": [ - "sl = yt.SlicePlot(ds, 2, field, aspect=.2) # Create a sliceplot object\n", - "sl.annotate_particles(width=(10.e-6, 'm'), p_size=2, ptype=species, col='black')\n", - "sl.annotate_grids() # Show grids\n", - "sl.show() # Show the plot" + "sl = yt.SlicePlot(ds, 2, field, aspect=0.2) # Create a sliceplot object\n", + "sl.annotate_particles(width=(10.0e-6, \"m\"), p_size=2, ptype=species, col=\"black\")\n", + "sl.annotate_grids() # Show grids\n", + "sl.show() # Show the plot" ] }, { @@ -87,21 +88,27 @@ "outputs": [], "source": [ "# Get field quantities\n", - "all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions)\n", - "Bx = all_data_level_0['boxlib', field].v.squeeze()\n", - "Dx = ds.domain_width/ds.domain_dimensions\n", - "extent = [ds.domain_left_edge[ds.dimensionality-1], ds.domain_right_edge[ds.dimensionality-1],\n", - " ds.domain_left_edge[0], ds.domain_right_edge[0] ]\n", + "all_data_level_0 = ds.covering_grid(\n", + " level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions\n", + ")\n", + "Bx = all_data_level_0[\"boxlib\", field].v.squeeze()\n", + "Dx = ds.domain_width / ds.domain_dimensions\n", + "extent = [\n", + " ds.domain_left_edge[ds.dimensionality - 1],\n", + " ds.domain_right_edge[ds.dimensionality - 1],\n", + " ds.domain_left_edge[0],\n", + " ds.domain_right_edge[0],\n", + "]\n", "\n", "# Get particle quantities\n", "ad = ds.all_data()\n", - "x = ad[species, 'particle_position_x'].v\n", - "z = ad[species, 'particle_position_z'].v\n", + "x = ad[species, \"particle_position_x\"].v\n", + "z = ad[species, \"particle_position_z\"].v\n", "\n", "# Plot image\n", "plt.figure()\n", - "plt.imshow(Bx[:,Bx.shape[1]//2,:], extent=extent, aspect='auto')\n", - "plt.scatter(z,x,s=.1,c='k')" + "plt.imshow(Bx[:, Bx.shape[1] // 2, :], extent=extent, aspect=\"auto\")\n", + "plt.scatter(z, x, s=0.1, c=\"k\")" ] } ], diff --git a/Tools/PostProcessing/plot_distribution_mapping.py b/Tools/PostProcessing/plot_distribution_mapping.py index 4b0cdfd532b..899ea4678c4 100644 --- a/Tools/PostProcessing/plot_distribution_mapping.py +++ b/Tools/PostProcessing/plot_distribution_mapping.py @@ -11,6 +11,7 @@ class SimData: """ Structure for easy access to load costs reduced diagnostics """ + def __init__(self, directory, prange, is_3D): """ Set data-containing dir, data range; load data @@ -26,7 +27,7 @@ def __call__(self, i): print("No data_fields!") return - if not i in self.keys: + if i not in self.keys: print("Index is out of range!") print("Valid keys are ", self.keys) return @@ -40,7 +41,6 @@ def __call__(self, i): # Data_fields index currently set self.idx = i - def _get_costs_reduced_diagnostics(self, directory, prange): """ Read costs reduced diagnostics @@ -58,20 +58,21 @@ def _get_costs_reduced_diagnostics(self, directory, prange): if len(data.shape) == 1: data = data.reshape(-1, data.shape[0]) - steps = data[:,0].astype(int) + steps = data[:, 0].astype(int) - times = data[:,1] - data = data[:,2:] + times = data[:, 1] + data = data[:, 2:] # Compute the number of datafields saved per box n_data_fields = 0 with open(directory) as f: h = f.readlines()[0] - unique_headers=[''.join([l for l in w if not l.isdigit()]) - for w in h.split()][2::] + unique_headers = [ + "".join([ln for ln in w if not ln.isdigit()]) for w in h.split() + ][2::] # Either 9 or 10 depending if GPU - n_data_fields = 9 if len(set(unique_headers))%9 == 0 else 10 + n_data_fields = 9 if len(set(unique_headers)) % 9 == 0 else 10 f.close() # From data header, data layout is: @@ -86,9 +87,11 @@ def _get_costs_reduced_diagnostics(self, directory, prange): # cost_box_n, proc_box_n, lev_box_n, i_low_box_n, j_low_box_n, # k_low_box_n, num_cells_n, num_macro_particles_n, # (, gpu_ID_box_n if GPU run), hostname_box_n - i, j, k = (data[0,3::n_data_fields], - data[0,4::n_data_fields], - data[0,5::n_data_fields]) + i, j, k = ( + data[0, 3::n_data_fields], + data[0, 4::n_data_fields], + data[0, 5::n_data_fields], + ) i_blocks = np.diff(np.array(sorted(i.astype(int)))) j_blocks = np.diff(np.array(sorted(j.astype(int)))) @@ -103,21 +106,23 @@ def _get_costs_reduced_diagnostics(self, directory, prange): j_blocking_factor = 1 if len(j_non_zero) == 0 else j_non_zero.min() k_blocking_factor = 1 if len(k_non_zero) == 0 else k_non_zero.min() - imax = i.astype(int).max()//i_blocking_factor - jmax = j.astype(int).max()//j_blocking_factor - kmax = k.astype(int).max()//k_blocking_factor + imax = i.astype(int).max() // i_blocking_factor + jmax = j.astype(int).max() // j_blocking_factor + kmax = k.astype(int).max() // k_blocking_factor for key in self.keys: row = np.where(key == steps)[0][0] costs = data[row, 0::n_data_fields].astype(float) ranks = data[row, 1::n_data_fields].astype(int) - icoords = i.astype(int)//i_blocking_factor - jcoords = j.astype(int)//j_blocking_factor - kcoords = k.astype(int)//k_blocking_factor + icoords = i.astype(int) // i_blocking_factor + jcoords = j.astype(int) // j_blocking_factor + kcoords = k.astype(int) // k_blocking_factor # Fill in cost array - shape = (kmax+1, jmax+1, imax+1)[:2+self.is_3D] - coords = [coord[:2+self.is_3D] for coord in zip(kcoords, jcoords, icoords)] + shape = (kmax + 1, jmax + 1, imax + 1)[: 2 + self.is_3D] + coords = [ + coord[: 2 + self.is_3D] for coord in zip(kcoords, jcoords, icoords) + ] cost_arr = np.full(shape, 0.0) rank_arr = np.full(shape, -1) @@ -127,43 +132,56 @@ def _get_costs_reduced_diagnostics(self, directory, prange): rank_arr[coord] = ranks[nc] # For non-uniform blocks: fill with the corresponding cost/rank - visited = np.full(shape, False) + visited = np.full(shape, False) + def dfs(corner, pos, prev): # Exit conditions - if any([pos[i]>=shape[i] for i in range(len(shape))]): return - edges = list(rank_arr[corner[0]:pos[0]+1, pos[1], pos[2]]) \ - + list(rank_arr[pos[0], corner[1]:pos[1]+1, pos[2]]) \ - + list(rank_arr[pos[0], pos[1], corner[2]:pos[2]+1]) \ - if self.is_3D else \ - list(rank_arr[corner[0]:pos[0]+1, pos[1]]) \ - + list(rank_arr[pos[0], corner[1]:pos[1]+1]) - if visited[pos] or not set(edges).issubset(set([prev, -1])): return + if any([pos[i] >= shape[i] for i in range(len(shape))]): + return + edges = ( + list(rank_arr[corner[0] : pos[0] + 1, pos[1], pos[2]]) + + list(rank_arr[pos[0], corner[1] : pos[1] + 1, pos[2]]) + + list(rank_arr[pos[0], pos[1], corner[2] : pos[2] + 1]) + if self.is_3D + else list(rank_arr[corner[0] : pos[0] + 1, pos[1]]) + + list(rank_arr[pos[0], corner[1] : pos[1] + 1]) + ) + if visited[pos] or not set(edges).issubset(set([prev, -1])): + return visited[pos] = True - if rank_arr[pos] not in [-1, prev]: prev, corner = rank_arr[pos], pos - else: rank_arr[pos] = prev + if rank_arr[pos] not in [-1, prev]: + prev, corner = rank_arr[pos], pos + else: + rank_arr[pos] = prev args = [[0, 1] for _ in range(len(shape))] - neighbors = [tuple(np.array(pos) + np.array(p)) for p in product(*args) - if not p == (0,)*len(shape)] - for n in neighbors: dfs(corner, n, prev) + neighbors = [ + tuple(np.array(pos) + np.array(p)) + for p in product(*args) + if not p == (0,) * len(shape) + ] + for n in neighbors: + dfs(corner, n, prev) - for corner in coords: dfs(corner, corner, rank_arr[corner]) + for corner in coords: + dfs(corner, corner, rank_arr[corner]) - self.data_fields[key]['cost_arr'] = cost_arr - self.data_fields[key]['rank_arr'] = rank_arr + self.data_fields[key]["cost_arr"] = cost_arr + self.data_fields[key]["rank_arr"] = rank_arr # Compute load balance efficiency - rank_to_cost_map = {r:0. for r in set(ranks)} - for c, r in zip(costs, ranks): rank_to_cost_map[r] += c + rank_to_cost_map = {r: 0.0 for r in set(ranks)} + for c, r in zip(costs, ranks): + rank_to_cost_map[r] += c efficiencies = np.array(list(rank_to_cost_map.values())) efficiencies /= efficiencies.max() - self.data_fields[key]['ranks'] = np.array(list(rank_to_cost_map.keys())) - self.data_fields[key]['lb_efficiencies'] = efficiencies - self.data_fields[key]['lb_efficiency'] = efficiencies.mean() - self.data_fields[key]['lb_efficiency_max'] = efficiencies.max() - self.data_fields[key]['lb_efficiency_min'] = efficiencies.min() - self.data_fields[key]['t'] = times[row] - self.data_fields[key]['step'] = steps[row] + self.data_fields[key]["ranks"] = np.array(list(rank_to_cost_map.keys())) + self.data_fields[key]["lb_efficiencies"] = efficiencies + self.data_fields[key]["lb_efficiency"] = efficiencies.mean() + self.data_fields[key]["lb_efficiency_max"] = efficiencies.max() + self.data_fields[key]["lb_efficiency_min"] = efficiencies.min() + self.data_fields[key]["t"] = times[row] + self.data_fields[key]["step"] = steps[row] # ... diff --git a/Tools/PostProcessing/plot_nci_growth_rate.ipynb b/Tools/PostProcessing/plot_nci_growth_rate.ipynb index 559d5250237..5413d909229 100644 --- a/Tools/PostProcessing/plot_nci_growth_rate.ipynb +++ b/Tools/PostProcessing/plot_nci_growth_rate.ipynb @@ -21,11 +21,14 @@ "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", - "from scipy.constants import c\n", "import numpy as np\n", "import scipy.constants as scc\n", - "import yt ; yt.funcs.mylog.setLevel(50)\n", + "import yt\n", + "from scipy.constants import c\n", + "\n", + "yt.funcs.mylog.setLevel(50)\n", "import glob\n", + "\n", "%matplotlib inline" ] }, @@ -44,7 +47,7 @@ }, "outputs": [], "source": [ - "path_wx = 'path to diags folder'" + "path_wx = \"path to diags folder\"" ] }, { @@ -55,8 +58,10 @@ }, "outputs": [], "source": [ - "file_list_warpx = glob.glob(path_wx + 'diag1?????')\n", - "iterations_warpx = [ int(file_name[len(file_name)-5:]) for file_name in file_list_warpx ]" + "file_list_warpx = glob.glob(path_wx + \"diag1?????\")\n", + "iterations_warpx = [\n", + " int(file_name[len(file_name) - 5 :]) for file_name in file_list_warpx\n", + "]" ] }, { @@ -68,25 +73,24 @@ "outputs": [], "source": [ "def calculate_parameters(path):\n", - " iteration=200\n", - " dsx = yt.load( path + 'diag1%05d/' %iteration )\n", - " dxx = dsx.domain_width/dsx.domain_dimensions\n", - " dx=dxx[0];\n", - " dx = 1.*dx.ndarray_view()\n", - "\n", - " dz=dxx[1];\n", - " \n", - " dz = 1.*dz.ndarray_view()\n", - " cell_volume_x = np.prod(dxx)\n", - "\n", - " ds1 = yt.load(path+'/diag100100/')\n", - " ds2 = yt.load(path+'/diag100200/')\n", - " \n", + " iteration = 200\n", + " dsx = yt.load(path + \"diag1%05d/\" % iteration)\n", + " dxx = dsx.domain_width / dsx.domain_dimensions\n", + " dx = dxx[0]\n", + " dx = 1.0 * dx.ndarray_view()\n", + "\n", + " dz = dxx[1]\n", + "\n", + " dz = 1.0 * dz.ndarray_view()\n", + "\n", + " ds1 = yt.load(path + \"/diag100100/\")\n", + " ds2 = yt.load(path + \"/diag100200/\")\n", + "\n", " cur_t1 = ds1.current_time\n", - " cur_t2 = ds2.current_time \n", + " cur_t2 = ds2.current_time\n", " cur_t2.to_ndarray\n", - " dt = (cur_t2-cur_t1)/100\n", - " dt = 1.*dt.ndarray_view();\n", + " dt = (cur_t2 - cur_t1) / 100\n", + " dt = 1.0 * dt.ndarray_view()\n", " return dx, dz, dt" ] }, @@ -97,7 +101,7 @@ "outputs": [], "source": [ "dx, dz, dt = calculate_parameters(path_wx)\n", - "print(dx,dz,dt)" + "print(dx, dz, dt)" ] }, { @@ -108,35 +112,32 @@ }, "outputs": [], "source": [ - "def get_fourier_transform_wx( path, fieldcomp, \n", - " iteration, plot=False, remove_last=True ):\n", + "def get_fourier_transform_wx(path, fieldcomp, iteration, plot=False, remove_last=True):\n", " \"\"\"\n", " Calculate the Fourier transform of the field at a given iteration\n", " \"\"\"\n", - " \n", - " ds = yt.load(path + '/diag1%05d/' %iteration )\n", + "\n", + " ds = yt.load(path + \"/diag1%05d/\" % iteration)\n", "\n", " grid = ds.index.grids[0]\n", " F = grid[fieldcomp]\n", " F = F.ndarray_view()\n", "\n", - " \n", " if remove_last:\n", - " F = F[:-1,:-1]\n", - " F = F[:,:,0]\n", + " F = F[:-1, :-1]\n", + " F = F[:, :, 0]\n", "\n", - " kxmax = np.pi/dx\n", - " kzmax = np.pi/dz\n", + " kxmax = np.pi / dx\n", + " kzmax = np.pi / dz\n", " Nx = F.shape[0]\n", " Nz = F.shape[1]\n", - " spectralF = np.fft.fftshift( np.fft.fft2(F) )[int(Nx/2):, int(Nz/2):]\n", + " spectralF = np.fft.fftshift(np.fft.fft2(F))[int(Nx / 2) :, int(Nz / 2) :]\n", "\n", " if plot:\n", - " plt.imshow( np.log(abs(spectralF)), origin='lower',\n", - " extent=[0, kxmax, 0, kzmax] )\n", + " plt.imshow(np.log(abs(spectralF)), origin=\"lower\", extent=[0, kxmax, 0, kzmax])\n", " plt.colorbar()\n", - " \n", - " return( spectralF, kxmax, kzmax )" + "\n", + " return (spectralF, kxmax, kzmax)" ] }, { @@ -147,28 +148,30 @@ }, "outputs": [], "source": [ - "def growth_rate_between_wx( path, iteration1, iteration2, \n", - " remove_last=False, threshold=-13 ):\n", + "def growth_rate_between_wx(\n", + " path, iteration1, iteration2, remove_last=False, threshold=-13\n", + "):\n", " \"\"\"\n", - " Calculate the difference in spectral amplitude between two iterations, \n", + " Calculate the difference in spectral amplitude between two iterations,\n", " return the growth rate\n", - " \n", + "\n", " \"\"\"\n", - " spec1, kxmax, kzmax = \\\n", - " get_fourier_transform_wx( path, 'Ez', iteration=iteration1, remove_last=remove_last )\n", - " spec1 = np.where( abs(spec1) > np.exp(threshold), spec1, np.exp(threshold) )\n", - " \n", + " spec1, kxmax, kzmax = get_fourier_transform_wx(\n", + " path, \"Ez\", iteration=iteration1, remove_last=remove_last\n", + " )\n", + " spec1 = np.where(abs(spec1) > np.exp(threshold), spec1, np.exp(threshold))\n", "\n", - " spec2, kxmax, kzmax = \\\n", - " get_fourier_transform_wx( path, 'Ez', iteration=iteration2, remove_last=remove_last )\n", - " \n", - " spec2 = np.where( abs(spec2) > np.exp(threshold), spec2, np.exp(threshold) )\n", - " diff_growth = np.log( abs(spec2) ) - np.log( abs(spec1) )\n", + " spec2, kxmax, kzmax = get_fourier_transform_wx(\n", + " path, \"Ez\", iteration=iteration2, remove_last=remove_last\n", + " )\n", "\n", - " diff_time = (iteration2-iteration1)*dt;\n", - " growth_rate = diff_growth/diff_time/c;\n", + " spec2 = np.where(abs(spec2) > np.exp(threshold), spec2, np.exp(threshold))\n", + " diff_growth = np.log(abs(spec2)) - np.log(abs(spec1))\n", "\n", - " return( growth_rate, [0, kxmax, 0, kzmax] )" + " diff_time = (iteration2 - iteration1) * dt\n", + " growth_rate = diff_growth / diff_time / c\n", + "\n", + " return (growth_rate, [0, kxmax, 0, kzmax])" ] }, { @@ -179,18 +182,18 @@ }, "outputs": [], "source": [ - "def energy( ts ):\n", - " Ex= ts.index.grids[0]['boxlib', 'Ex'].squeeze().v\n", - " Ey= ts.index.grids[0]['boxlib', 'Ey'].squeeze().v\n", - " Ez= ts.index.grids[0]['boxlib', 'Ez'].squeeze().v\n", - " \n", - " Bx= ts.index.grids[0]['boxlib', 'Ex'].squeeze().v\n", - " By= ts.index.grids[0]['boxlib', 'Ey'].squeeze().v\n", - " Bz= ts.index.grids[0]['boxlib', 'Ez'].squeeze().v\n", - "\n", - " energyE = scc.epsilon_0*np.sum(Ex**2+Ey**2+Ez**2)\n", - " energyB= np.sum(Bx**2+By**2+Bz**2)/scc.mu_0 \n", - " energy = energyE + energyB\n", + "def energy(ts):\n", + " Ex = ts.index.grids[0][\"boxlib\", \"Ex\"].squeeze().v\n", + " Ey = ts.index.grids[0][\"boxlib\", \"Ey\"].squeeze().v\n", + " Ez = ts.index.grids[0][\"boxlib\", \"Ez\"].squeeze().v\n", + "\n", + " Bx = ts.index.grids[0][\"boxlib\", \"Ex\"].squeeze().v\n", + " By = ts.index.grids[0][\"boxlib\", \"Ey\"].squeeze().v\n", + " Bz = ts.index.grids[0][\"boxlib\", \"Ez\"].squeeze().v\n", + "\n", + " energyE = scc.epsilon_0 * np.sum(Ex**2 + Ey**2 + Ez**2)\n", + " energyB = np.sum(Bx**2 + By**2 + Bz**2) / scc.mu_0\n", + " energy = energyE + energyB\n", " return energy" ] }, @@ -202,9 +205,9 @@ "source": [ "energy_list = []\n", "for iter in iterations_warpx:\n", - " path = path_wx + '/diag1%05d/' %iter\n", - " ds = yt.load( path) \n", - " energy_list.append( energy(ds) )" + " path = path_wx + \"/diag1%05d/\" % iter\n", + " ds = yt.load(path)\n", + " energy_list.append(energy(ds))" ] }, { @@ -214,23 +217,23 @@ "outputs": [], "source": [ "iteration_start = 1700\n", - "iteration_end= 1900\n", + "iteration_end = 1900\n", "iter_delta = iterations_warpx[2] - iterations_warpx[1]\n", "\n", "\n", - "ds_start = yt.load(path_wx + 'diag1%05d/' %iteration_start)\n", - "Ez_start= ds.index.grids[0]['boxlib', 'Ez'].squeeze().v\n", + "ds_start = yt.load(path_wx + \"diag1%05d/\" % iteration_start)\n", + "Ez_start = ds.index.grids[0][\"boxlib\", \"Ez\"].squeeze().v\n", "\n", - "ds_end = yt.load(path_wx + 'diag1%05d/' %iteration_end)\n", - "Ez_end= ds_end.index.grids[0]['boxlib', 'Ez'].squeeze().v\n", + "ds_end = yt.load(path_wx + \"diag1%05d/\" % iteration_end)\n", + "Ez_end = ds_end.index.grids[0][\"boxlib\", \"Ez\"].squeeze().v\n", "\n", - "gr_wx, extent = growth_rate_between_wx(path_wx, iteration_start, iteration_end )\n", + "gr_wx, extent = growth_rate_between_wx(path_wx, iteration_start, iteration_end)\n", "\n", "\n", "fs = 13\n", "vmax = 0.05\n", - "vmin=-vmax\n", - "cmap_special = 'bwr'" + "vmin = -vmax\n", + "cmap_special = \"bwr\"" ] }, { @@ -239,23 +242,23 @@ "metadata": {}, "outputs": [], "source": [ - "fig, (ax1, ax2) = plt.subplots( ncols=2, figsize=(10,4.) )\n", + "fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(10, 4.0))\n", "\n", - "fs=14\n", + "fs = 14\n", "cmap = \"viridis\"\n", - "aspect='auto'\n", - "\n", - "img1 = ax1.imshow(Ez_start,aspect=aspect, cmap=cmap, extent=extent)\n", - "ax1.set_title('$t_{step}=$%i' % iteration_start, size=fs)\n", - "ax1.set_xlabel(' $k_{p,r} z$ ',size=fs)\n", - "ax1.set_ylabel(' $k_{p,r} x $ ',size=fs)\n", - "fig.colorbar(img1, ax=ax1, label = '$E_z, [V/m]$')\n", - "\n", - "img2 = ax2.imshow(Ez_end,aspect=aspect, cmap=cmap, extent=extent)\n", - "ax2.set_title('$t_{step}=$%i' % iteration_end,size=fs)\n", - "ax2.set_xlabel(' $k_{p,r} z$ ',size=fs)\n", - "ax2.set_ylabel(' $k_{p,r} x $ ',size=fs)\n", - "fig.colorbar(img2, ax=ax2, label = '$E_z, [V/m]$')\n", + "aspect = \"auto\"\n", + "\n", + "img1 = ax1.imshow(Ez_start, aspect=aspect, cmap=cmap, extent=extent)\n", + "ax1.set_title(\"$t_{step}=$%i\" % iteration_start, size=fs)\n", + "ax1.set_xlabel(\" $k_{p,r} z$ \", size=fs)\n", + "ax1.set_ylabel(\" $k_{p,r} x $ \", size=fs)\n", + "fig.colorbar(img1, ax=ax1, label=\"$E_z, [V/m]$\")\n", + "\n", + "img2 = ax2.imshow(Ez_end, aspect=aspect, cmap=cmap, extent=extent)\n", + "ax2.set_title(\"$t_{step}=$%i\" % iteration_end, size=fs)\n", + "ax2.set_xlabel(\" $k_{p,r} z$ \", size=fs)\n", + "ax2.set_ylabel(\" $k_{p,r} x $ \", size=fs)\n", + "fig.colorbar(img2, ax=ax2, label=\"$E_z, [V/m]$\")\n", "plt.tight_layout()" ] }, @@ -265,23 +268,31 @@ "metadata": {}, "outputs": [], "source": [ - "fig, (ax1, ax2) = plt.subplots( ncols=2,nrows=1, figsize=(13,5.) )\n", + "fig, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(13, 5.0))\n", "\n", - "fs=14\n", + "fs = 14\n", "\n", - "img1 = ax1.semilogy(iterations_warpx,energy_list)\n", - "ax1.semilogy(iteration_start,energy_list[iteration_start/iter_delta],'ro')\n", - "ax1.semilogy(iteration_end,energy_list[iteration_end/iter_delta],'ro')\n", + "img1 = ax1.semilogy(iterations_warpx, energy_list)\n", + "ax1.semilogy(iteration_start, energy_list[iteration_start / iter_delta], \"ro\")\n", + "ax1.semilogy(iteration_end, energy_list[iteration_end / iter_delta], \"ro\")\n", "ax1.grid()\n", "ax1.legend()\n", - "ax1.set_xlabel('time step',size=fs)\n", - "ax1.set_ylabel('Total EM energy',size=fs)\n", - "\n", - "img2 = ax2.imshow( gr_wx, origin='lower' ,cmap='bwr', vmax=0.05, vmin=-vmax, interpolation='nearest', extent=[0, 1, 0, 1] )\n", - "ax2.set_title('NCI growth rate',size=fs)\n", - "ax2.set_xlabel('$k_{p,r} z$ ',size=fs)\n", - "ax2.set_ylabel('$k_{p,r} x $ ',size=fs)\n", - "fig.colorbar(img2, ax=ax2, label = '$Im(\\omega)/\\omega_{p,r}$')" + "ax1.set_xlabel(\"time step\", size=fs)\n", + "ax1.set_ylabel(\"Total EM energy\", size=fs)\n", + "\n", + "img2 = ax2.imshow(\n", + " gr_wx,\n", + " origin=\"lower\",\n", + " cmap=\"bwr\",\n", + " vmax=0.05,\n", + " vmin=-vmax,\n", + " interpolation=\"nearest\",\n", + " extent=[0, 1, 0, 1],\n", + ")\n", + "ax2.set_title(\"NCI growth rate\", size=fs)\n", + "ax2.set_xlabel(\"$k_{p,r} z$ \", size=fs)\n", + "ax2.set_ylabel(\"$k_{p,r} x $ \", size=fs)\n", + "fig.colorbar(img2, ax=ax2, label=\"$Im(\\omega)/\\omega_{p,r}$\")" ] } ], diff --git a/Tools/PostProcessing/plot_parallel.py b/Tools/PostProcessing/plot_parallel.py index a4309b3896e..2bdac5d0177 100644 --- a/Tools/PostProcessing/plot_parallel.py +++ b/Tools/PostProcessing/plot_parallel.py @@ -16,7 +16,7 @@ import matplotlib.pyplot as plt import numpy as np -''' +""" This script loops over all WarpX plotfiles in a directory and, for each plotfile, saves an image showing the field and particles. @@ -41,33 +41,71 @@ To get help, run > python plot_parallel --help -''' +""" # Parse command line for options. parser = argparse.ArgumentParser() -parser.add_argument('--path', default=None, - help='path to plotfiles, defaults to diags/plotfiles. Plotfiles names must be plt?????') -parser.add_argument('--image_dir', default=None, - help='path where images are placed, defaults to diags/plotfiles or path if specified.') -parser.add_argument('--plotlib', default='yt', - choices=['yt','matplotlib'], - help='Plotting library to use') -parser.add_argument('--field', default='Ez', - help='Which field to plot, e.g., Ez, By, jx or rho. The central slice in y is plotted') -parser.add_argument('--pjump', default=20, - help='When plotlib=matplotlib, we plot every pjump particle') -parser.add_argument('--vmax', type=float, default=None, - help='If specified, the colormap will have bounds [-vmax, vmax]') -parser.add_argument('--slicewidth', default=10.e-6, - help='Only particles with -slicewidth/2 1: @@ -232,21 +310,23 @@ def reduce_evolved_quantity(z, q): else: return z, q + ### Analysis ### # Get list of plotfiles -file_list = glob.glob(os.path.join(path, 'plt?????')) +file_list = glob.glob(os.path.join(path, "plt?????")) file_list.sort() nfiles = len(file_list) # Get list of particle species to plot -pslist = get_species(file_list); +pslist = get_species(file_list) rank = 0 size = 1 if not args.serial: try: from mpi4py import MPI + comm_world = MPI.COMM_WORLD rank = comm_world.Get_rank() size = comm_world.Get_size() @@ -254,9 +334,9 @@ def reduce_evolved_quantity(z, q): pass if rank == 0: - print('number of MPI ranks: %d'%size) - print('Number of plotfiles: %s'%nfiles) - print('list of species: ', pslist) + print("number of MPI ranks: %d" % size) + print("Number of plotfiles: %s" % nfiles) + print("list of species: ", pslist) if plot_evolution is not None: # Fill with a value less than any possible value @@ -271,14 +351,16 @@ def reduce_evolved_quantity(z, q): # - plot field snapshot # - store window position and field max in arrays for count, filename in enumerate(file_list): - if count%size != rank: + if count % size != rank: continue - plot_snapshot( filename ) + plot_snapshot(filename) if plot_evolution is not None: - zwin[count], quantity[count] = get_evolution_quantity( filename, plot_evolution ) + zwin[count], quantity[count] = get_evolution_quantity(filename, plot_evolution) if plot_particle_evolution is not None: - zbar[count], xstd[count] = get_particle_evolution_quantity(filename, plot_particle_evolution) + zbar[count], xstd[count] = get_particle_evolution_quantity( + filename, plot_particle_evolution + ) if plot_evolution is not None: zwin, quantity = reduce_evolved_quantity(zwin, quantity) diff --git a/Tools/PostProcessing/plot_particle_path.py b/Tools/PostProcessing/plot_particle_path.py index 9bf7f896c10..af29dfc0e11 100644 --- a/Tools/PostProcessing/plot_particle_path.py +++ b/Tools/PostProcessing/plot_particle_path.py @@ -9,7 +9,7 @@ class AMReXParticleHeader(object): - ''' + """ This class is designed to parse and store the information contained in an AMReX particle header file. @@ -22,19 +22,18 @@ class AMReXParticleHeader(object): etc... - ''' + """ def __init__(self, header_filename): - self.real_component_names = [] self.int_component_names = [] with open(header_filename, "r") as f: self.version_string = f.readline().strip() - particle_real_type = self.version_string.split('_')[-1] - if particle_real_type == 'double': + particle_real_type = self.version_string.split("_")[-1] + if particle_real_type == "double": self.real_type = np.float64 - elif particle_real_type == 'single': + elif particle_real_type == "single": self.real_type = np.float32 else: raise RuntimeError("Did not recognize particle real type.") @@ -62,7 +61,7 @@ def __init__(self, header_filename): self.num_int_extra = 0 self.num_int = 0 - self.grids_per_level = np.zeros(self.num_levels, dtype='int64') + self.grids_per_level = np.zeros(self.num_levels, dtype="int64") self.grids = [] for level_num in range(self.num_levels): self.grids_per_level[level_num] = int(f.readline().strip()) @@ -75,7 +74,7 @@ def __init__(self, header_filename): def read_particle_data(fn, ptype="particle0"): - ''' + """ This function returns the particle data stored in a particular plot file and particle type. It returns two numpy arrays, the @@ -89,7 +88,7 @@ def read_particle_data(fn, ptype="particle0"): idata, rdata = read_particle_data("plt00000", "particle0") - ''' + """ base_fn = fn + "/" + ptype header = AMReXParticleHeader(base_fn + "/Header") @@ -99,22 +98,23 @@ def read_particle_data(fn, ptype="particle0"): elif header.real_type == np.float32: fdtype = "(%d,)f4" % header.num_real - idata = np.empty((header.num_particles, header.num_int )) + idata = np.empty((header.num_particles, header.num_int)) rdata = np.empty((header.num_particles, header.num_real)) ip = 0 for lvl, level_grids in enumerate(header.grids): - for (which, count, where) in level_grids: - if count == 0: continue + for which, count, where in level_grids: + if count == 0: + continue fn = base_fn + "/Level_%d/DATA_%04d" % (lvl, which) - with open(fn, 'rb') as f: + with open(fn, "rb") as f: f.seek(where) - ints = np.fromfile(f, dtype = idtype, count=count) - floats = np.fromfile(f, dtype = fdtype, count=count) + ints = np.fromfile(f, dtype=idtype, count=count) + floats = np.fromfile(f, dtype=fdtype, count=count) - idata[ip:ip+count] = ints - rdata[ip:ip+count] = floats + idata[ip : ip + count] = ints + rdata[ip : ip + count] = floats ip += count return idata, rdata @@ -143,10 +143,10 @@ def read_particle_data(fn, ptype="particle0"): fig = plt.gcf() fig.set_size_inches(8, 8) - plt.plot(x0, y0, 'r.') - plt.plot(x1, y1, 'b.') - plt.axis((-2., 2., -2., 2.)) + plt.plot(x0, y0, "r.") + plt.plot(x1, y1, "b.") + plt.axis((-2.0, 2.0, -2.0, 2.0)) ax = plt.gca() - ax.set_xlabel(r'$x$') - ax.set_ylabel(r'$y$') - plt.savefig('particles.png') + ax.set_xlabel(r"$x$") + ax.set_ylabel(r"$y$") + plt.savefig("particles.png") diff --git a/Tools/PostProcessing/plot_timestep_duration.py b/Tools/PostProcessing/plot_timestep_duration.py index 9858eb6a422..7b893f1ad1e 100755 --- a/Tools/PostProcessing/plot_timestep_duration.py +++ b/Tools/PostProcessing/plot_timestep_duration.py @@ -8,25 +8,24 @@ def extract_data(filename): - regex_step = re.compile( - r"STEP [0-9]* ends.*\n.* Avg\. per step = ([0-9]*[.])?[0-9]+ s", re.MULTILINE) + r"STEP [0-9]* ends.*\n.* Avg\. per step = ([0-9]*[.])?[0-9]+ s", re.MULTILINE + ) string_data = [] - print("Processing " + filename + " ...", end='') + print("Processing " + filename + " ...", end="") with open(filename) as f: text = f.read() string_data = [s.group(0) for s in regex_step.finditer(text)] - regex_real = re.compile( - r" -?[\d.]+(?:e-?\d+)?", re.MULTILINE) + regex_real = re.compile(r" -?[\d.]+(?:e-?\d+)?", re.MULTILINE) time_data = np.zeros([len(string_data), 6]) for i, ss in enumerate(string_data): numbers = regex_real.findall(ss) - time_data[i,:] = np.array(numbers) + time_data[i, :] = np.array(numbers) print("...done!") return time_data @@ -34,22 +33,22 @@ def extract_data(filename): def plot_timestep_duration(time_data, name): fig_name = name + "_ts_duration.png" - print("Generating " + fig_name + "...", end='') + print("Generating " + fig_name + "...", end="") - plt.rcParams.update({'font.size': 20}) - plt.rcParams['axes.linewidth'] = 3 + plt.rcParams.update({"font.size": 20}) + plt.rcParams["axes.linewidth"] = 3 - f, ax = plt.subplots(figsize=(12,6)) + f, ax = plt.subplots(figsize=(12, 6)) ax.set_ylabel("timestep duration [s]") ax.set_xlabel("step [#]") - ax.semilogy(time_data[:,0], time_data[:,4]) + ax.semilogy(time_data[:, 0], time_data[:, 4]) - ax.spines['bottom'].set_color('gray') - ax.spines['top'].set_visible(False) - ax.spines['left'].set_color('gray') - ax.spines['right'].set_visible(False) + ax.spines["bottom"].set_color("gray") + ax.spines["top"].set_visible(False) + ax.spines["left"].set_color("gray") + ax.spines["right"].set_visible(False) plt.tight_layout() @@ -59,22 +58,22 @@ def plot_timestep_duration(time_data, name): def plot_cumulative_duration(time_data, name): fig_name = name + "_cumulative_duration.png" - print("Generating " + fig_name + "...", end='') + print("Generating " + fig_name + "...", end="") - plt.rcParams.update({'font.size': 20}) - plt.rcParams['axes.linewidth'] = 3 + plt.rcParams.update({"font.size": 20}) + plt.rcParams["axes.linewidth"] = 3 - f, ax = plt.subplots(figsize=(12,6)) + f, ax = plt.subplots(figsize=(12, 6)) ax.set_ylabel("cumulative duration [s]") ax.set_xlabel("step [#]") - ax.plot(time_data[:,0], np.cumsum(time_data[:,4])) + ax.plot(time_data[:, 0], np.cumsum(time_data[:, 4])) - ax.spines['bottom'].set_color('gray') - ax.spines['top'].set_visible(False) - ax.spines['left'].set_color('gray') - ax.spines['right'].set_visible(False) + ax.spines["bottom"].set_color("gray") + ax.spines["top"].set_visible(False) + ax.spines["left"].set_color("gray") + ax.spines["right"].set_visible(False) plt.tight_layout() @@ -83,9 +82,16 @@ def plot_cumulative_duration(time_data, name): def do_plot_timestep_duration(): - parser = argparse.ArgumentParser(description='Generates plots of timestep duration from WarpX standard output logs') - parser.add_argument('file_name', metavar='file_name', type=str, nargs=1, - help='the name of the WarpX output log to process') + parser = argparse.ArgumentParser( + description="Generates plots of timestep duration from WarpX standard output logs" + ) + parser.add_argument( + "file_name", + metavar="file_name", + type=str, + nargs=1, + help="the name of the WarpX output log to process", + ) args = parser.parse_args() log_file_name = args.file_name[0] @@ -95,5 +101,6 @@ def do_plot_timestep_duration(): plot_timestep_duration(time_data, log_file_name) plot_cumulative_duration(time_data, log_file_name) + if __name__ == "__main__": do_plot_timestep_duration() diff --git a/Tools/PostProcessing/read_raw_data.py b/Tools/PostProcessing/read_raw_data.py index c34ea11d301..a180cad18e0 100644 --- a/Tools/PostProcessing/read_raw_data.py +++ b/Tools/PostProcessing/read_raw_data.py @@ -10,10 +10,11 @@ import numpy as np -HeaderInfo = namedtuple('HeaderInfo', ['version', 'how', 'ncomp', 'nghost']) +HeaderInfo = namedtuple("HeaderInfo", ["version", "how", "ncomp", "nghost"]) + def read_data(plt_file): - ''' + """ This function reads the raw (i.e. not averaged to cell centers) data from a WarpX plt file. The plt file must have been written with the @@ -33,9 +34,9 @@ def read_data(plt_file): >>> data = read_data("plt00016") >>> print(data.keys()) - >>> print(data['Ex'].shape) + >>> print(data["Ex"].shape) - ''' + """ all_data = [] raw_files = sorted(glob(plt_file + "/raw_fields/Level_*/")) for raw_file in raw_files: @@ -69,33 +70,35 @@ def _line_to_numpy_arrays(line): def _read_local_Header(header_file, dim): with open(header_file, "r") as f: t_snapshot = float(f.readline()) - if dim==2: + if dim == 2: nx, nz = [int(x) for x in f.readline().split()] ny = 1 xmin, zmin = [float(x) for x in f.readline().split()] ymin = 0 xmax, zmax = [float(x) for x in f.readline().split()] ymax = 0 - if dim==3: + if dim == 3: nx, ny, nz = [int(x) for x in f.readline().split()] xmin, ymin, zmin = [float(x) for x in f.readline().split()] xmax, ymax, zmax = [float(x) for x in f.readline().split()] field_names = f.readline().split() local_info = { - 't_snapshot' : t_snapshot, - 'field_names' : field_names, - 'xmin' : xmin, - 'ymin' : ymin, - 'zmin' : zmin, - 'xmax' : xmax, - 'ymax' : ymax, - 'zmax' : zmax, - 'nx' : nx, - 'ny' : ny, - 'nz' : nz - } + "t_snapshot": t_snapshot, + "field_names": field_names, + "xmin": xmin, + "ymin": ymin, + "zmin": zmin, + "xmax": xmax, + "ymax": ymax, + "zmax": zmax, + "nx": nx, + "ny": ny, + "nz": nz, + } return local_info + + ## ------------------------------------------------------------ ## USE THIS INSTEAD OF THE PREVIOUS FUNCTION IF Header contains ## (x,y,z) min and max vectors instead of zmin and zmax @@ -115,25 +118,23 @@ def _read_local_Header(header_file, dim): def _read_global_Header(header_file): with open(header_file, "r") as f: - nshapshots = int(f.readline()) dt_between_snapshots = float(f.readline()) gamma_boost = float(f.readline()) beta_boost = float(f.readline()) global_info = { - 'nshapshots' : nshapshots, - 'dt_between_snapshots' : dt_between_snapshots, - 'gamma_boost' : gamma_boost, - 'beta_boost' : beta_boost - } + "nshapshots": nshapshots, + "dt_between_snapshots": dt_between_snapshots, + "gamma_boost": gamma_boost, + "beta_boost": beta_boost, + } return global_info def _read_header(header_file): with open(header_file, "r") as f: - version = int(f.readline()) how = int(f.readline()) ncomp = int(f.readline()) @@ -142,9 +143,11 @@ def _read_header(header_file): # If the number of ghost cells varies depending on the direction, # s is a string of the form '(9,8)\n' in 2D or '(9,8,9)\n' in 3D. s = f.readline() - s = s.replace('(', '') # remove left parenthesis '(', if any - s = s.replace(')', '') # remove right parenthesis ')', if any - nghost = np.fromstring(s, dtype = int, sep = ',') # convert from string to numpy array + s = s.replace("(", "") # remove left parenthesis '(', if any + s = s.replace(")", "") # remove right parenthesis ')', if any + nghost = np.fromstring( + s, dtype=int, sep="," + ) # convert from string to numpy array header = HeaderInfo(version, how, ncomp, nghost) @@ -155,12 +158,10 @@ def _read_header(header_file): boxes = [] for line in f: clean_line = line.strip().split() - if clean_line == [')']: + if clean_line == [")"]: break lo_corner, hi_corner, node_type = _line_to_numpy_arrays(clean_line) - boxes.append((lo_corner - nghost, - hi_corner + nghost, - node_type)) + boxes.append((lo_corner - nghost, hi_corner + nghost, node_type)) # read the file and offset position for the corresponding box file_names = [] @@ -182,7 +183,6 @@ def _combine_boxes(boxes): def _read_field(raw_file, field_name): - header_file = raw_file + field_name + "_H" boxes, file_names, offsets, header = _read_header(header_file) @@ -200,11 +200,11 @@ def _read_field(raw_file, field_name): shape = np.append(shape, header.ncomp) with open(raw_file + fn, "rb") as f: f.seek(offset) - if (header.version == 1): + if header.version == 1: f.readline() # skip the first line - arr = np.fromfile(f, 'float64', np.product(shape)) - arr = arr.reshape(shape, order='F') - box_shape = [slice(l,h+1) for l, h in zip(lo, hi)] + arr = np.fromfile(f, "float64", np.product(shape)) + arr = arr.reshape(shape, order="F") + box_shape = [slice(low, hig + 1) for low, hig in zip(lo, hi)] if header.ncomp > 1: box_shape += [slice(None)] data[tuple(box_shape)] = arr @@ -212,9 +212,7 @@ def _read_field(raw_file, field_name): return data - def _read_buffer(snapshot, header_fn, _component_names): - boxes, file_names, offsets, header = _read_header(header_fn) dom_lo, dom_hi = _combine_boxes(boxes) @@ -230,18 +228,21 @@ def _read_buffer(snapshot, header_fn, _component_names): size = np.product(shape) with open(snapshot + "/Level_0/" + fn, "rb") as f: f.seek(offset) - if (header.version == 1): + if header.version == 1: f.readline() # skip the first line - arr = np.fromfile(f, 'float64', header.ncomp*size) + arr = np.fromfile(f, "float64", header.ncomp * size) for i in range(header.ncomp): - comp_data = arr[i*size:(i+1)*size].reshape(shape, order='F') + comp_data = arr[i * size : (i + 1) * size].reshape(shape, order="F") data = all_data[_component_names[i]] - data[tuple([slice(l,h+1) for l, h in zip(lo, hi)])] = comp_data + data[tuple([slice(low, hig + 1) for low, hig in zip(lo, hi)])] = ( + comp_data + ) all_data[_component_names[i]] = data return all_data -def read_reduced_diags(filename, delimiter=' '): - ''' + +def read_reduced_diags(filename, delimiter=" "): + """ Read data written by WarpX Reduced Diagnostics, and return them into Python objects input: - filename name of file to open @@ -249,54 +250,67 @@ def read_reduced_diags(filename, delimiter=' '): output: - metadata_dict dictionary where first key is the type of metadata, second is the field - data dictionary with data - ''' + """ # Read header line - unformatted_header = list( np.genfromtxt( filename, comments="@", max_rows=1, dtype="str", delimiter=delimiter) ) + unformatted_header = list( + np.genfromtxt( + filename, comments="@", max_rows=1, dtype="str", delimiter=delimiter + ) + ) # From header line, get field name, units and column number - field_names = [s[s.find("]")+1:s.find("(")] for s in unformatted_header] - field_units = [s[s.find("(")+1:s.find(")")] for s in unformatted_header] - field_column = [s[s.find("[")+1:s.find("]")] for s in unformatted_header] + field_names = [s[s.find("]") + 1 : s.find("(")] for s in unformatted_header] + field_units = [s[s.find("(") + 1 : s.find(")")] for s in unformatted_header] + field_column = [s[s.find("[") + 1 : s.find("]")] for s in unformatted_header] # Load data and re-format to a dictionary - data = np.loadtxt( filename, delimiter=delimiter ) + data = np.loadtxt(filename, delimiter=delimiter) if data.ndim == 1: data_dict = {key: np.atleast_1d(data[i]) for i, key in enumerate(field_names)} else: - data_dict = {key: data[:,i] for i, key in enumerate(field_names)} + data_dict = {key: data[:, i] for i, key in enumerate(field_names)} # Put header data into a dictionary metadata_dict = {} - metadata_dict['units'] = {key: field_units[i] for i, key in enumerate(field_names)} - metadata_dict['column'] = {key: field_column[i] for i, key in enumerate(field_names)} + metadata_dict["units"] = {key: field_units[i] for i, key in enumerate(field_names)} + metadata_dict["column"] = { + key: field_column[i] for i, key in enumerate(field_names) + } return metadata_dict, data_dict -def read_reduced_diags_histogram(filename, delimiter=' '): - ''' + +def read_reduced_diags_histogram(filename, delimiter=" "): + """ Modified based on read_reduced_diags Two extra return objects: - bin_value: the values of bins - bin_data: the histogram data values of bins - ''' + """ # Read header line - unformatted_header = list( np.genfromtxt( filename, comments="@", max_rows=1, dtype="str", delimiter=delimiter) ) + unformatted_header = list( + np.genfromtxt( + filename, comments="@", max_rows=1, dtype="str", delimiter=delimiter + ) + ) # From header line, get field name, units and column number - field_names = [s[s.find("]")+1:s.find("(")] for s in unformatted_header] - field_names[2:] = [s[s.find("b"):s.find("=")] for s in field_names[2:]] - field_units = [s[s.find("(")+1:s.find(")")] for s in unformatted_header] - field_column = [s[s.find("[")+1:s.find("]")] for s in unformatted_header] - field_bin = [s[s.find("=")+1:s.find("(")] for s in unformatted_header] + field_names = [s[s.find("]") + 1 : s.find("(")] for s in unformatted_header] + field_names[2:] = [s[s.find("b") : s.find("=")] for s in field_names[2:]] + field_units = [s[s.find("(") + 1 : s.find(")")] for s in unformatted_header] + field_column = [s[s.find("[") + 1 : s.find("]")] for s in unformatted_header] + field_bin = [s[s.find("=") + 1 : s.find("(")] for s in unformatted_header] # Load data and re-format to a dictionary - data = np.loadtxt( filename, delimiter=delimiter ) + data = np.loadtxt(filename, delimiter=delimiter) if data.ndim == 1: data_dict = {key: data[i] for i, key in enumerate(field_names)} else: - data_dict = {key: data[:,i] for i, key in enumerate(field_names)} + data_dict = {key: data[:, i] for i, key in enumerate(field_names)} # Put header data into a dictionary metadata_dict = {} - metadata_dict['units'] = {key: field_units[i] for i, key in enumerate(field_names)} - metadata_dict['column'] = {key: field_column[i] for i, key in enumerate(field_names)} + metadata_dict["units"] = {key: field_units[i] for i, key in enumerate(field_names)} + metadata_dict["column"] = { + key: field_column[i] for i, key in enumerate(field_names) + } # Save bin values - bin_value = np.asarray(field_bin[2:], dtype=np.float64, order='C') + bin_value = np.asarray(field_bin[2:], dtype=np.float64, order="C") if data.ndim == 1: - bin_data = data[2:] + bin_data = data[2:] else: - bin_data = data[:,2:] + bin_data = data[:, 2:] return metadata_dict, data_dict, bin_value, bin_data diff --git a/Tools/PostProcessing/video_yt.py b/Tools/PostProcessing/video_yt.py index 61046b3c074..90aad9f8d17 100644 --- a/Tools/PostProcessing/video_yt.py +++ b/Tools/PostProcessing/video_yt.py @@ -5,7 +5,7 @@ # # License: BSD-3-Clause-LBNL -''' +""" This script loops over 3D plotfiles plt*****, generates a 3D rendering of the data with fields and particles, and saves one image per plotfile to plt_****_img.png. It was written for a laser-wakefield acceleration @@ -18,7 +18,7 @@ > mpirun -np 4 python video_yt.py to generate the images. It can be quite slow for even moderately large plotfiles. -''' +""" import glob @@ -28,37 +28,43 @@ yt.enable_parallelism() import numpy as np -field = 'Ez' -my_max = int(5.e9) # Field maximum amplitude +field = "Ez" +my_max = int(5.0e9) # Field maximum amplitude do_particles = True -species0 = 'beam' -species1 = 'electrons' -do_patch = False # if want to plot an MR patch +species0 = "beam" +species1 = "electrons" +do_patch = False # if want to plot an MR patch resolution = (512, 512) -camera_position = np.array([15., 20., -5.])*yt.units.micrometer -file_list = glob.glob('./diags/plotfiles/plt?????') +camera_position = np.array([15.0, 20.0, -5.0]) * yt.units.micrometer +file_list = glob.glob("./diags/plotfiles/plt?????") + +clight = 299792458.0 # must be the same value as in WarpX -clight = 299792458.0 # must be the same value as in WarpX def plot_species(species, ad, radii, transparency, abs_xmax): # Color for each of these particles - colors_vect = [1., 1., 1., .05] # the last value is overwritten later - x = ad[species,'particle_position_x'].v - y = ad[species,'particle_position_y'].v - z = ad[species,'particle_position_z'].v + colors_vect = [1.0, 1.0, 1.0, 0.05] # the last value is overwritten later + x = ad[species, "particle_position_x"].v + y = ad[species, "particle_position_y"].v + z = ad[species, "particle_position_z"].v selector = np.abs(x) < abs_xmax - x = x[selector] ; y = y[selector] ; z = z[selector] - vertices = np.column_stack((x,y,z)) - colors = np.tile(colors_vect,(vertices.shape[0], 1)) - colors[:,3] = transparency - point = yt.visualization.volume_rendering.render_source.PointSource(vertices, colors=colors, radii=radii) + x = x[selector] + y = y[selector] + z = z[selector] + vertices = np.column_stack((x, y, z)) + colors = np.tile(colors_vect, (vertices.shape[0], 1)) + colors[:, 3] = transparency + point = yt.visualization.volume_rendering.render_source.PointSource( + vertices, colors=colors, radii=radii + ) return point + # Create the 3d image for 1 timestep # filename is the name of the folder (e.g. plt00000) def img_onestep(filename): # Load the data - ds = yt.load( filename ) + ds = yt.load(filename) ad = ds.all_data() # Calculate the z position of the box. @@ -66,30 +72,48 @@ def img_onestep(filename): # was used in the simulation, the rendering shows some jitter. # This is because a cell is added in z at some iterations but not all. # These lines calculate this jitter z_shift and remove it from the camera position and focus - iteration=int(filename[-5:]) - dt = 1./clight * 1./np.sqrt((1./ad['dx'][-1]**2 + 1./ad['dy'][-1]**2 + 1./ad['dz'][-1]**2)) + iteration = int(filename[-5:]) + dt = ( + 1.0 + / clight + * 1.0 + / np.sqrt( + ( + 1.0 / ad["dx"][-1] ** 2 + + 1.0 / ad["dy"][-1] ** 2 + + 1.0 / ad["dz"][-1] ** 2 + ) + ) + ) z_front = dt * float(iteration) * clight - z_shift = z_front-ds.domain_right_edge[2] + z_shift = z_front - ds.domain_right_edge[2] # Create a yt source object for the level1 patch if do_patch: box_patch = yt.visualization.volume_rendering.render_source.BoxSource( - left_edge=ds.index.grids[1].LeftEdge+np.array([0., 0., z_shift])*yt.units.meter, - right_edge=ds.index.grids[1].RightEdge+np.array([0., 0., z_shift])*yt.units.meter, - color=[1.,0.1,0.1,.01]) + left_edge=ds.index.grids[1].LeftEdge + + np.array([0.0, 0.0, z_shift]) * yt.units.meter, + right_edge=ds.index.grids[1].RightEdge + + np.array([0.0, 0.0, z_shift]) * yt.units.meter, + color=[1.0, 0.1, 0.1, 0.01], + ) # Handle 2 populations of particles: beam and plasma electrons if do_particles: - point0 = plot_species(species0, ad, 2, .01, 1.) - point1 = plot_species(species1, ad, 1, .002, 20.e-6) + point0 = plot_species(species0, ad, 2, 0.01, 1.0) + point1 = plot_species(species1, ad, 1, 0.002, 20.0e-6) sc = yt.create_scene(ds, field=field) # Set camera properties cam = sc.camera dom_length = ds.domain_width[2].v cam.set_width(ds.quan(dom_length, yt.units.meter)) - cam.position = ds.domain_center + camera_position + np.array([0., 0., z_shift])*yt.units.meter - cam.focus = ds.domain_center + np.array([0., 0., z_shift])*yt.units.meter + cam.position = ( + ds.domain_center + + camera_position + + np.array([0.0, 0.0, z_shift]) * yt.units.meter + ) + cam.focus = ds.domain_center + np.array([0.0, 0.0, z_shift]) * yt.units.meter cam.resolution = resolution # Field rendering properties source = sc[0] @@ -98,17 +122,17 @@ def img_onestep(filename): source.use_ghost_zones = True bounds = (-my_max, my_max) tf = yt.ColorTransferFunction(bounds) - w = (.01*my_max)**2 + w = (0.01 * my_max) ** 2 # Define the transfer function for 3d rendering # 3 isocontours for negative field values # The sharpness of the contour is controlled by argument width - tf.add_gaussian(-.04 *my_max, width=8*w, height=[0.1, 0.1, 1.0, 0.02]) - tf.add_gaussian(-.2 *my_max, width=5*w, height=[0.1, 0.1, 1.0, 0.05]) - tf.add_gaussian(-.6 *my_max, width=w, height=[0.0, 0.0, 1.0, 0.3]) + tf.add_gaussian(-0.04 * my_max, width=8 * w, height=[0.1, 0.1, 1.0, 0.02]) + tf.add_gaussian(-0.2 * my_max, width=5 * w, height=[0.1, 0.1, 1.0, 0.05]) + tf.add_gaussian(-0.6 * my_max, width=w, height=[0.0, 0.0, 1.0, 0.3]) # 3 isocontours for positive field values - tf.add_gaussian(.04 *my_max, width=8*w, height=[1.0, 1.0, 0.2, 0.02]) - tf.add_gaussian(.2 *my_max, width=5*w, height=[1.0, 1.0, 0.2, 0.05]) - tf.add_gaussian(.6 *my_max, width=w, height=[1.0, 1.0, 0.0, 0.3]) + tf.add_gaussian(0.04 * my_max, width=8 * w, height=[1.0, 1.0, 0.2, 0.02]) + tf.add_gaussian(0.2 * my_max, width=5 * w, height=[1.0, 1.0, 0.2, 0.05]) + tf.add_gaussian(0.6 * my_max, width=w, height=[1.0, 1.0, 0.0, 0.3]) source.tfh.tf = tf source.tfh.bounds = bounds source.tfh.set_log(False) @@ -118,7 +142,8 @@ def img_onestep(filename): sc.add_source(point1) if do_patch: sc.add_source(box_patch) - sc.save('./img_' + filename[-8:] + '.png', sigma_clip=1.) + sc.save("./img_" + filename[-8:] + ".png", sigma_clip=1.0) + # Get plt folders in current folder and loop over them. file_list.sort() diff --git a/Tools/PostProcessing/yt3d_mpi.py b/Tools/PostProcessing/yt3d_mpi.py index 655327aff3d..10734494280 100644 --- a/Tools/PostProcessing/yt3d_mpi.py +++ b/Tools/PostProcessing/yt3d_mpi.py @@ -4,7 +4,7 @@ # # License: BSD-3-Clause-LBNL -''' +""" This script loops over 3D plotfiles plt*****, generates a 3D rendering of the data with fields and particles, and saves one image per plotfile to img_*****.png. It was written for a beam-driven wakefield acceleration @@ -15,7 +15,7 @@ > mpirun -np 12 python yt3d_mpi.py to generate the images. It can be quite slow for even moderately large plotfiles. -''' +""" import glob @@ -27,60 +27,79 @@ yt.funcs.mylog.setLevel(50) # my_max = 1.e11 # for smooth rendering -my_max = 5.e10 # for layered rendering -species_to_plot = ['plasma_e', 'beam', 'driver'] +my_max = 5.0e10 # for layered rendering +species_to_plot = ["plasma_e", "beam", "driver"] # For each species, provide [red, green, blue, alpha] between 0. and 1. -species_colors = { 'plasma_e': [1., 1., 1., .15], - 'beam' : [1., 1., 1., .2 ], - 'driver' : [1., 1., 1., .2 ] } +species_colors = { + "plasma_e": [1.0, 1.0, 1.0, 0.15], + "beam": [1.0, 1.0, 1.0, 0.2], + "driver": [1.0, 1.0, 1.0, 0.2], +} # provide these to avoid jitter when using a moving window use_moving_window = True plot_mr_patch = False -rendering_type = 'layers' # 'layers' or 'smooth' -maxwell_solver = 'ckc' # 'ckc' or 'yee' +rendering_type = "layers" # 'layers' or 'smooth' +maxwell_solver = "ckc" # 'ckc' or 'yee' cfl = 0.99 -file_list = glob.glob('plotfiles/plt?????') +file_list = glob.glob("plotfiles/plt?????") + +bounds = (-my_max, my_max) +z_shift = 0.0 +w = (0.01 * my_max) ** 2 -bounds = ( -my_max, my_max ) -z_shift = 0. -w = (.01*my_max)**2 def jitter_shift(ds, ad, cfl, iteration): - if maxwell_solver == 'yee': - dt = 1./scc.c * 1./np.sqrt((1./ad['dx'][-1]**2 + 1./ad['dy'][-1]**2 + 1./ad['dz'][-1]**2)) - elif maxwell_solver == 'ckc': - dt = cfl * min( [ ad['dx'][-1], ad['dy'][-1], ad['dz'][-1] ] ) / scc.c - z_front = dt * float(iteration) * scc.c + 7.5e-6*yt.units.meter - z_shift = z_front-ds.domain_right_edge[2] + if maxwell_solver == "yee": + dt = ( + 1.0 + / scc.c + * 1.0 + / np.sqrt( + ( + 1.0 / ad["dx"][-1] ** 2 + + 1.0 / ad["dy"][-1] ** 2 + + 1.0 / ad["dz"][-1] ** 2 + ) + ) + ) + elif maxwell_solver == "ckc": + dt = cfl * min([ad["dx"][-1], ad["dy"][-1], ad["dz"][-1]]) / scc.c + z_front = dt * float(iteration) * scc.c + 7.5e-6 * yt.units.meter + z_shift = z_front - ds.domain_right_edge[2] return z_shift + def get_species_ytpoints(ad, species, color_vec): - xp = ad[species,'particle_position_x'].v - yp = ad[species,'particle_position_y'].v - zp = ad[species,'particle_position_z'].v - if species == 'plasma_e': - selection = np.abs(xp)<2.e-6 + xp = ad[species, "particle_position_x"].v + yp = ad[species, "particle_position_y"].v + zp = ad[species, "particle_position_z"].v + if species == "plasma_e": + selection = np.abs(xp) < 2.0e-6 zp = zp[selection] yp = yp[selection] xp = xp[selection] - vertices = np.column_stack((xp,yp,zp)) - colors = np.tile(color_vec,(vertices.shape[0], 1)) - points = yt.visualization.volume_rendering.render_source.PointSource(vertices, colors=colors, radii=1) + vertices = np.column_stack((xp, yp, zp)) + colors = np.tile(color_vec, (vertices.shape[0], 1)) + points = yt.visualization.volume_rendering.render_source.PointSource( + vertices, colors=colors, radii=1 + ) return points + def img_onestep(filename): - ds = yt.load( filename ) + ds = yt.load(filename) ad = ds.all_data() - iteration=int(filename[-5:]) - sc = yt.create_scene(ds, field='Ez') + iteration = int(filename[-5:]) + sc = yt.create_scene(ds, field="Ez") if use_moving_window: - z_shift = jitter_shift( ds, ad, cfl, iteration ) - array_shift = z_shift * np.array([0., 0., 1.]) + z_shift = jitter_shift(ds, ad, cfl, iteration) + array_shift = z_shift * np.array([0.0, 0.0, 1.0]) if plot_mr_patch: box_patch = yt.visualization.volume_rendering.render_source.BoxSource( - left_edge =ds.index.grids[1].LeftEdge +array_shift, - right_edge=ds.index.grids[1].RightEdge+array_shift, - color=[1.,0.1,0.1,.01] ) + left_edge=ds.index.grids[1].LeftEdge + array_shift, + right_edge=ds.index.grids[1].RightEdge + array_shift, + color=[1.0, 0.1, 0.1, 0.01], + ) sc.add_source(box_patch) ######################## ### volume rendering ### @@ -90,27 +109,28 @@ def img_onestep(filename): source.grey_opacity = True source.set_log(False) tf = yt.ColorTransferFunction(bounds) - if rendering_type == 'smooth': - tf.add_gaussian(-my_max/4, width=15**2*w, height=[0.0, 0.0, 1.0, 1]) - tf.add_gaussian( my_max/4, width=15**2*w, height=[1.0, 0.0, 0.0, 1]) - if rendering_type == 'layers': + if rendering_type == "smooth": + tf.add_gaussian(-my_max / 4, width=15**2 * w, height=[0.0, 0.0, 1.0, 1]) + tf.add_gaussian(my_max / 4, width=15**2 * w, height=[1.0, 0.0, 0.0, 1]) + if rendering_type == "layers": # NEGATIVE - tf.add_gaussian(-.04 *my_max, width=8*w, height=[0.1, 0.1, 1.0, 0.2]) - tf.add_gaussian(-.2 *my_max, width=5*w, height=[0.1, 0.1, 1.0, 0.5]) - tf.add_gaussian(-.6 *my_max, width=w, height=[0.0, 0.0, 1.0, 1.]) + tf.add_gaussian(-0.04 * my_max, width=8 * w, height=[0.1, 0.1, 1.0, 0.2]) + tf.add_gaussian(-0.2 * my_max, width=5 * w, height=[0.1, 0.1, 1.0, 0.5]) + tf.add_gaussian(-0.6 * my_max, width=w, height=[0.0, 0.0, 1.0, 1.0]) # POSITIVE - tf.add_gaussian(.04 *my_max, width=8*w, height=[1.0, 1.0, 0.2, 0.2]) - tf.add_gaussian(.2 *my_max, width=5*w, height=[1.0, 1.0, 0.2, 0.5]) - tf.add_gaussian(.6 *my_max, width=w, height=[1.0, 1.0, 0.0, 1.]) + tf.add_gaussian(0.04 * my_max, width=8 * w, height=[1.0, 1.0, 0.2, 0.2]) + tf.add_gaussian(0.2 * my_max, width=5 * w, height=[1.0, 1.0, 0.2, 0.5]) + tf.add_gaussian(0.6 * my_max, width=w, height=[1.0, 1.0, 0.0, 1.0]) ###################### ### plot particles ### ###################### species_points = {} for species in species_to_plot: - species_points[ species ] = get_species_ytpoints(ad, - species, species_colors[species]) - sc.add_source( species_points[ species ] ) + species_points[species] = get_species_ytpoints( + ad, species, species_colors[species] + ) + sc.add_source(species_points[species]) source.tfh.tf = tf source.tfh.bounds = bounds ######################### @@ -118,20 +138,23 @@ def img_onestep(filename): ######################### cam = sc.camera cam.resolution = (2048, 2048) - cam.width = .00018*yt.units.meter - cam.focus = ds.domain_center + \ - np.array([0., 0., 10.e-6 ])*yt.units.meter + \ - array_shift - cam.position = ds.domain_center + \ - np.array([15., 15., -5. ])*yt.units.micrometer + \ - array_shift - cam.normal_vector = [-0.3, -0.3, -.2] + cam.width = 0.00018 * yt.units.meter + cam.focus = ( + ds.domain_center + np.array([0.0, 0.0, 10.0e-6]) * yt.units.meter + array_shift + ) + cam.position = ( + ds.domain_center + + np.array([15.0, 15.0, -5.0]) * yt.units.micrometer + + array_shift + ) + cam.normal_vector = [-0.3, -0.3, -0.2] cam.switch_orientation() # save image - if rendering_type == 'smooth': - sc.save('img_' + str(my_number_list[count]).zfill(5), sigma_clip=5.) - if rendering_type == 'layers': - sc.save('img_' + str(my_number_list[count]).zfill(5), sigma_clip=2.) + if rendering_type == "smooth": + sc.save("img_" + str(my_number_list[count]).zfill(5), sigma_clip=5.0) + if rendering_type == "layers": + sc.save("img_" + str(my_number_list[count]).zfill(5), sigma_clip=2.0) + file_list.sort() # Total number of files @@ -142,9 +165,9 @@ def img_onestep(filename): me = comm_world.Get_rank() nrank = comm_world.Get_size() # List of files to process for current proc -my_list = file_list[ (me*nfiles)/nrank : ((me+1)*nfiles)/nrank ] +my_list = file_list[(me * nfiles) / nrank : ((me + 1) * nfiles) / nrank] # List if file numbers for current proc -my_number_list = number_list[ (me*nfiles)/nrank : ((me+1)*nfiles)/nrank ] +my_number_list = number_list[(me * nfiles) / nrank : ((me + 1) * nfiles) / nrank] for count, filename in enumerate(my_list): - print('processing ' + filename) + print("processing " + filename) img_onestep(filename) diff --git a/Tools/QedTablesUtils/Source/ArgParser/QedTablesArgParser.cpp b/Tools/QedTablesUtils/Source/ArgParser/QedTablesArgParser.cpp index 41d27477dcf..a92f191037d 100644 --- a/Tools/QedTablesUtils/Source/ArgParser/QedTablesArgParser.cpp +++ b/Tools/QedTablesUtils/Source/ArgParser/QedTablesArgParser.cpp @@ -85,7 +85,7 @@ ArgParser::ParseArgs (const std::vector& keys, const int argc, char const* void ArgParser::PrintHelp (const vector& cmd_list) { - cout << "Command line options: " << endl; + cout << "Command line options:\n"; for (const auto& el : cmd_list){ const auto type = get<1>(el); @@ -102,7 +102,7 @@ ArgParser::PrintHelp (const vector& cmd_list) cout << get<0>(el) << " " << stype << " " << get<2>(el) - << endl; + << "\n"; } } diff --git a/Tools/QedTablesUtils/Source/QedTableCommons.H b/Tools/QedTablesUtils/Source/QedTableCommons.H index 40551b9e13c..2233513bc97 100644 --- a/Tools/QedTablesUtils/Source/QedTableCommons.H +++ b/Tools/QedTablesUtils/Source/QedTableCommons.H @@ -19,7 +19,7 @@ void AbortWithMessage(const std::string& msg) void SuccessExit() { - std::cout << "___________________________" << std::endl; + std::cout << "___________________________\n"; exit(0); } diff --git a/Tools/QedTablesUtils/Source/QedTableGenerator.cpp b/Tools/QedTablesUtils/Source/QedTableGenerator.cpp index 1ea62b5c6ed..7bfa5787ec8 100644 --- a/Tools/QedTablesUtils/Source/QedTableGenerator.cpp +++ b/Tools/QedTablesUtils/Source/QedTableGenerator.cpp @@ -49,7 +49,7 @@ void GenerateTableQS (const ParsedArgs& args, const string& outfile_name); int main (int argc, char** argv) { - cout << "### QED Table Generator ###" << endl; + cout << "### QED Table Generator ###\n"; const auto args_map = ParseArgs(line_commands, argc, argv); if (args_map.empty() || Contains(args_map, "-h")){ diff --git a/Tools/QedTablesUtils/Source/QedTableReader.cpp b/Tools/QedTablesUtils/Source/QedTableReader.cpp index ba9d58775f2..27b284f34c2 100644 --- a/Tools/QedTablesUtils/Source/QedTableReader.cpp +++ b/Tools/QedTablesUtils/Source/QedTableReader.cpp @@ -57,7 +57,7 @@ class qs_photon_emission_table_wrapper : int main (int argc, char** argv) { - cout << "### QED Table Reader ###" << endl; + cout << "### QED Table Reader ###\n"; const auto args_map = ParseArgs(line_commands, argc, argv); if (args_map.empty() || Contains(args_map, "-h")){ diff --git a/Tools/Release/updateAMReX.py b/Tools/Release/updateAMReX.py index 9dfa7fbeb41..beeb12e85ff 100755 --- a/Tools/Release/updateAMReX.py +++ b/Tools/Release/updateAMReX.py @@ -15,15 +15,6 @@ import requests -try: - from configupdater import ConfigUpdater -except ImportError: - print("Warning: Cannot update .ini files without 'configupdater'") - print("Consider running 'python -m pip install configupdater'") - ConfigUpdater = None - sys.exit(1) - - # Maintainer Inputs ########################################################### print("""Hi there, this is a WarpX maintainer tool to update the source @@ -38,7 +29,7 @@ REPLY = input("Are you sure you want to continue? [y/N] ") print() -if not REPLY in ["Y", "y"]: +if REPLY not in ["Y", "y"]: print("You did not confirm with 'y', aborting.") sys.exit(1) @@ -46,7 +37,9 @@ # Current Versions ############################################################ # AMReX development HEAD -amrex_gh = requests.get('https://api.github.com/repos/AMReX-Codes/amrex/commits/development') +amrex_gh = requests.get( + "https://api.github.com/repos/AMReX-Codes/amrex/commits/development" +) amrex_HEAD = amrex_gh.json()["sha"] # WarpX references to AMReX: cmake/dependencies/AMReX.cmake @@ -54,18 +47,20 @@ # branch/commit/tag (git fetcher) version # set(WarpX_amrex_branch "development" ... amrex_branch = f"unknown (format issue in {amrex_cmake_path})" -with open(amrex_cmake_path, encoding='utf-8') as f: - r_minimal = re.findall(r'.*set\(WarpX_amrex_branch\s+"(.+)"\s+.*', - f.read(), re.MULTILINE) +with open(amrex_cmake_path, encoding="utf-8") as f: + r_minimal = re.findall( + r'.*set\(WarpX_amrex_branch\s+"(.+)"\s+.*', f.read(), re.MULTILINE + ) if len(r_minimal) >= 1: amrex_branch = r_minimal[0] # minimal (external) version # find_package(AMReX YY.MM CONFIG ... amrex_minimal = f"unknown (format issue in {amrex_cmake_path})" -with open(amrex_cmake_path, encoding='utf-8') as f: - r_minimal = re.findall(r'.*find_package\(AMReX\s+(.+)\s+CONFIG\s+.*', - f.read(), re.MULTILINE) +with open(amrex_cmake_path, encoding="utf-8") as f: + r_minimal = re.findall( + r".*find_package\(AMReX\s+(.+)\s+CONFIG\s+.*", f.read(), re.MULTILINE + ) if len(r_minimal) >= 1: amrex_minimal = r_minimal[0] @@ -78,13 +73,15 @@ print(f"Currently, WarpX builds against this AMReX commit/branch/sha: {amrex_branch}") print(f"AMReX HEAD commit (development branch): {amrex_HEAD}") -amrex_new_branch = input(f"Update AMReX commit/branch/sha: ").strip() +amrex_new_branch = input("Update AMReX commit/branch/sha: ").strip() if not amrex_new_branch: amrex_new_branch = amrex_branch print(f"--> Nothing entered, will keep: {amrex_branch}") print() -print(f"Currently, a pre-installed AMReX is required at least at version: {amrex_minimal}") +print( + f"Currently, a pre-installed AMReX is required at least at version: {amrex_minimal}" +) today = datetime.date.today().strftime("%y.%m") amrex_new_minimal = input(f"New minimal AMReX version (e.g. {today})? ").strip() if not amrex_new_minimal: @@ -97,77 +94,52 @@ REPLY = input("Is this information correct? Will now start updating! [y/N] ") print() -if not REPLY in ["Y", "y"]: +if REPLY not in ["Y", "y"]: print("You did not confirm with 'y', aborting.") sys.exit(1) # Updates ##################################################################### -# run_test.sh (used also for Azure Pipelines) -run_test_path = str(REPO_DIR.joinpath("run_test.sh")) -with open(run_test_path, encoding='utf-8') as f: - run_test_content = f.read() - # branch/commit/tag (git fetcher) version - # cd amrex && git checkout COMMIT_TAG_OR_BRANCH && cd - - run_test_content = re.sub( - r'(.*cd\s+amrex.+git checkout\s+--detach\s+)(.+)(\s+&&\s.*)', - r'\g<1>{}\g<3>'.format(amrex_new_branch), - run_test_content, flags = re.MULTILINE) - -with open(run_test_path, "w", encoding='utf-8') as f: - f.write(run_test_content) - # CI: legacy build check in .github/workflows/cuda.yml ci_gnumake_path = str(REPO_DIR.joinpath(".github/workflows/cuda.yml")) -with open(ci_gnumake_path, encoding='utf-8') as f: +with open(ci_gnumake_path, encoding="utf-8") as f: ci_gnumake_content = f.read() # branch/commit/tag (git fetcher) version # cd ../amrex && git checkout COMMIT_TAG_OR_BRANCH && cd - ci_gnumake_content = re.sub( - r'(.*cd\s+\.\./amrex.+git checkout\s+--detach\s+)(.+)(\s+&&\s.*)', - r'\g<1>{}\g<3>'.format(amrex_new_branch), - ci_gnumake_content, flags = re.MULTILINE) + r"(.*cd\s+\.\./amrex.+git checkout\s+--detach\s+)(.+)(\s+&&\s.*)", + r"\g<1>{}\g<3>".format(amrex_new_branch), + ci_gnumake_content, + flags=re.MULTILINE, + ) -with open(ci_gnumake_path, "w", encoding='utf-8') as f: +with open(ci_gnumake_path, "w", encoding="utf-8") as f: f.write(ci_gnumake_content) -if ConfigUpdater is not None: - # WarpX-tests.ini - tests_ini_path = str(REPO_DIR.joinpath("Regression/WarpX-tests.ini")) - cp = ConfigUpdater() - cp.optionxform = str - cp.read(tests_ini_path) - cp['AMReX']['branch'].value = amrex_new_branch - cp.update_file() - - # WarpX-GPU-tests.ini - tests_gpu_ini_path = str(REPO_DIR.joinpath("Regression/WarpX-GPU-tests.ini")) - cp = ConfigUpdater() - cp.optionxform = str - cp.read(tests_gpu_ini_path) - cp['AMReX']['branch'].value = amrex_new_branch - cp.update_file() - # WarpX references to AMReX: cmake/dependencies/AMReX.cmake -with open(amrex_cmake_path, encoding='utf-8') as f: +with open(amrex_cmake_path, encoding="utf-8") as f: amrex_cmake_content = f.read() # branch/commit/tag (git fetcher) version # set(WarpX_amrex_branch "development" ... amrex_cmake_content = re.sub( r'(.*set\(WarpX_amrex_branch\s+")(.+)("\s+.*)', - r'\g<1>{}\g<3>'.format(amrex_new_branch), - amrex_cmake_content, flags = re.MULTILINE) + r"\g<1>{}\g<3>".format(amrex_new_branch), + amrex_cmake_content, + flags=re.MULTILINE, + ) # minimal (external) version # find_package(AMReX YY.MM CONFIG ... amrex_cmake_content = re.sub( - r'(.*find_package\(AMReX\s+)(.+)(\s+CONFIG\s+.*)', - r'\g<1>{}\g<3>'.format(amrex_new_minimal), - amrex_cmake_content, flags = re.MULTILINE) + r"(.*find_package\(AMReX\s+)(.+)(\s+CONFIG\s+.*)", + r"\g<1>{}\g<3>".format(amrex_new_minimal), + amrex_cmake_content, + flags=re.MULTILINE, + ) -with open(amrex_cmake_path, "w", encoding='utf-8') as f: +with open(amrex_cmake_path, "w", encoding="utf-8") as f: f.write(amrex_cmake_content) diff --git a/Tools/Release/updatePICSAR.py b/Tools/Release/updatePICSAR.py index 7e61679d371..5148c16727e 100755 --- a/Tools/Release/updatePICSAR.py +++ b/Tools/Release/updatePICSAR.py @@ -29,7 +29,7 @@ REPLY = input("Are you sure you want to continue? [y/N] ") print() -if not REPLY in ["Y", "y"]: +if REPLY not in ["Y", "y"]: print("You did not confirm with 'y', aborting.") sys.exit(1) @@ -37,7 +37,9 @@ # Current Versions ############################################################ # PICSAR development HEAD -PICSAR_gh = requests.get('https://api.github.com/repos/ECP-WarpX/picsar/commits/development') +PICSAR_gh = requests.get( + "https://api.github.com/repos/ECP-WarpX/picsar/commits/development" +) PICSAR_HEAD = PICSAR_gh.json()["sha"] # WarpX references to PICSAR: cmake/dependencies/PICSAR.cmake @@ -45,18 +47,20 @@ # branch/commit/tag (git fetcher) version # set(WarpX_picsar_branch "development" ... PICSAR_branch = f"unknown (format issue in {PICSAR_cmake_path})" -with open(PICSAR_cmake_path, encoding='utf-8') as f: - r_minimal = re.findall(r'.*set\(WarpX_picsar_branch\s+"(.+)"\s+.*', - f.read(), re.MULTILINE) +with open(PICSAR_cmake_path, encoding="utf-8") as f: + r_minimal = re.findall( + r'.*set\(WarpX_picsar_branch\s+"(.+)"\s+.*', f.read(), re.MULTILINE + ) if len(r_minimal) >= 1: PICSAR_branch = r_minimal[0] # minimal (external) version # find_package(PICSAR YY.MM CONFIG ... PICSAR_minimal = f"unknown (format issue in {PICSAR_cmake_path})" -with open(PICSAR_cmake_path, encoding='utf-8') as f: - r_minimal = re.findall(r'.*find_package\(PICSAR\s+(.+)\s+CONFIG\s+.*', - f.read(), re.MULTILINE) +with open(PICSAR_cmake_path, encoding="utf-8") as f: + r_minimal = re.findall( + r".*find_package\(PICSAR\s+(.+)\s+CONFIG\s+.*", f.read(), re.MULTILINE + ) if len(r_minimal) >= 1: PICSAR_minimal = r_minimal[0] @@ -69,13 +73,15 @@ print(f"Currently, WarpX builds against this PICSAR commit/branch/sha: {PICSAR_branch}") print(f"PICSAR HEAD commit (development branch): {PICSAR_HEAD}") -PICSAR_new_branch = input(f"Update PICSAR commit/branch/sha: ").strip() +PICSAR_new_branch = input("Update PICSAR commit/branch/sha: ").strip() if not PICSAR_new_branch: PICSAR_new_branch = PICSAR_branch print(f"--> Nothing entered, will keep: {PICSAR_branch}") print() -print(f"Currently, a pre-installed PICSAR is required at least at version: {PICSAR_minimal}") +print( + f"Currently, a pre-installed PICSAR is required at least at version: {PICSAR_minimal}" +) today = datetime.date.today().strftime("%y.%m") PICSAR_new_minimal = input(f"New minimal PICSAR version (e.g. {today})? ").strip() if not PICSAR_new_minimal: @@ -88,7 +94,7 @@ REPLY = input("Is this information correct? Will now start updating! [y/N] ") print() -if not REPLY in ["Y", "y"]: +if REPLY not in ["Y", "y"]: print("You did not confirm with 'y', aborting.") sys.exit(1) @@ -96,24 +102,28 @@ # Updates ##################################################################### # WarpX references to PICSAR: cmake/dependencies/PICSAR.cmake -with open(PICSAR_cmake_path, encoding='utf-8') as f: +with open(PICSAR_cmake_path, encoding="utf-8") as f: PICSAR_cmake_content = f.read() # branch/commit/tag (git fetcher) version # set(WarpX_picsar_branch "development" ... PICSAR_cmake_content = re.sub( r'(.*set\(WarpX_picsar_branch\s+")(.+)("\s+.*)', - r'\g<1>{}\g<3>'.format(PICSAR_new_branch), - PICSAR_cmake_content, flags = re.MULTILINE) + r"\g<1>{}\g<3>".format(PICSAR_new_branch), + PICSAR_cmake_content, + flags=re.MULTILINE, + ) # minimal (external) version # find_package(PICSAR YY.MM CONFIG ... PICSAR_cmake_content = re.sub( - r'(.*find_package\(PICSAR\s+)(.+)(\s+CONFIG\s+.*)', - r'\g<1>{}\g<3>'.format(PICSAR_new_minimal), - PICSAR_cmake_content, flags = re.MULTILINE) + r"(.*find_package\(PICSAR\s+)(.+)(\s+CONFIG\s+.*)", + r"\g<1>{}\g<3>".format(PICSAR_new_minimal), + PICSAR_cmake_content, + flags=re.MULTILINE, + ) -with open(PICSAR_cmake_path, "w", encoding='utf-8') as f: +with open(PICSAR_cmake_path, "w", encoding="utf-8") as f: f.write(PICSAR_cmake_content) diff --git a/Tools/Release/updatepyAMReX.py b/Tools/Release/updatepyAMReX.py index 500781e0880..68001222241 100755 --- a/Tools/Release/updatepyAMReX.py +++ b/Tools/Release/updatepyAMReX.py @@ -29,7 +29,7 @@ REPLY = input("Are you sure you want to continue? [y/N] ") print() -if not REPLY in ["Y", "y"]: +if REPLY not in ["Y", "y"]: print("You did not confirm with 'y', aborting.") sys.exit(1) @@ -37,7 +37,9 @@ # Current Versions ############################################################ # pyAMReX development HEAD -pyamrex_gh = requests.get('https://api.github.com/repos/AMReX-Codes/pyamrex/commits/development') +pyamrex_gh = requests.get( + "https://api.github.com/repos/AMReX-Codes/pyamrex/commits/development" +) pyamrex_HEAD = pyamrex_gh.json()["sha"] # WarpX references to pyAMReX: cmake/dependencies/pyAMReX.cmake @@ -45,18 +47,20 @@ # branch/commit/tag (git fetcher) version # set(WarpX_pyamrex_branch "development" ... pyamrex_branch = f"unknown (format issue in {pyamrex_cmake_path})" -with open(pyamrex_cmake_path, encoding='utf-8') as f: - r_minimal = re.findall(r'.*set\(WarpX_pyamrex_branch\s+"(.+)"\s+.*', - f.read(), re.MULTILINE) +with open(pyamrex_cmake_path, encoding="utf-8") as f: + r_minimal = re.findall( + r'.*set\(WarpX_pyamrex_branch\s+"(.+)"\s+.*', f.read(), re.MULTILINE + ) if len(r_minimal) >= 1: pyamrex_branch = r_minimal[0] # minimal (external) version # find_package(AMReX YY.MM CONFIG ... pyamrex_minimal = f"unknown (format issue in {pyamrex_cmake_path})" -with open(pyamrex_cmake_path, encoding='utf-8') as f: - r_minimal = re.findall(r'.*find_package\(pyAMReX\s+(.+)\s+CONFIG\s+.*', - f.read(), re.MULTILINE) +with open(pyamrex_cmake_path, encoding="utf-8") as f: + r_minimal = re.findall( + r".*find_package\(pyAMReX\s+(.+)\s+CONFIG\s+.*", f.read(), re.MULTILINE + ) if len(r_minimal) >= 1: pyamrex_minimal = r_minimal[0] @@ -67,15 +71,19 @@ Please answer the following questions about the version number you want to require from pyAMReX:\n""") -print(f"Currently, WarpX builds against this pyAMReX commit/branch/sha: {pyamrex_branch}") +print( + f"Currently, WarpX builds against this pyAMReX commit/branch/sha: {pyamrex_branch}" +) print(f"pyAMReX HEAD commit (development branch): {pyamrex_HEAD}") -pyamrex_new_branch = input(f"Update pyAMReX commit/branch/sha: ").strip() +pyamrex_new_branch = input("Update pyAMReX commit/branch/sha: ").strip() if not pyamrex_new_branch: pyamrex_new_branch = pyamrex_branch print(f"--> Nothing entered, will keep: {pyamrex_branch}") print() -print(f"Currently, a pre-installed pyAMReX is required at least at version: {pyamrex_minimal}") +print( + f"Currently, a pre-installed pyAMReX is required at least at version: {pyamrex_minimal}" +) today = datetime.date.today().strftime("%y.%m") pyamrex_new_minimal = input(f"New minimal pyAMReX version (e.g. {today})? ").strip() if not pyamrex_new_minimal: @@ -88,7 +96,7 @@ REPLY = input("Is this information correct? Will now start updating! [y/N] ") print() -if not REPLY in ["Y", "y"]: +if REPLY not in ["Y", "y"]: print("You did not confirm with 'y', aborting.") sys.exit(1) @@ -96,24 +104,28 @@ # Updates ##################################################################### # WarpX references to pyAMReX: cmake/dependencies/pyAMReX.cmake -with open(pyamrex_cmake_path, encoding='utf-8') as f: +with open(pyamrex_cmake_path, encoding="utf-8") as f: pyAMReX_cmake_content = f.read() # branch/commit/tag (git fetcher) version # set(WarpX_pyamrex_branch "development" ... pyAMReX_cmake_content = re.sub( r'(.*set\(WarpX_pyamrex_branch\s+")(.+)("\s+.*)', - r'\g<1>{}\g<3>'.format(pyamrex_new_branch), - pyAMReX_cmake_content, flags = re.MULTILINE) + r"\g<1>{}\g<3>".format(pyamrex_new_branch), + pyAMReX_cmake_content, + flags=re.MULTILINE, + ) # minimal (external) version # find_package(AMReX YY.MM CONFIG ... pyAMReX_cmake_content = re.sub( - r'(.*find_package\(pyAMReX\s+)(.+)(\s+CONFIG\s+.*)', - r'\g<1>{}\g<3>'.format(pyamrex_new_minimal), - pyAMReX_cmake_content, flags = re.MULTILINE) + r"(.*find_package\(pyAMReX\s+)(.+)(\s+CONFIG\s+.*)", + r"\g<1>{}\g<3>".format(pyamrex_new_minimal), + pyAMReX_cmake_content, + flags=re.MULTILINE, + ) -with open(pyamrex_cmake_path, "w", encoding='utf-8') as f: +with open(pyamrex_cmake_path, "w", encoding="utf-8") as f: f.write(pyAMReX_cmake_content) diff --git a/Tools/machines/cori-nersc/cori_gpu.sbatch b/Tools/machines/cori-nersc/cori_gpu.sbatch deleted file mode 100644 index 7ccfcbf277f..00000000000 --- a/Tools/machines/cori-nersc/cori_gpu.sbatch +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -l - -# Copyright 2021 Axel Huebl -# This file is part of WarpX. -# License: BSD-3-Clause-LBNL -# -# Ref: -# - https://docs-dev.nersc.gov/cgpu/hardware/ -# - https://docs-dev.nersc.gov/cgpu/access/ -# - https://docs-dev.nersc.gov/cgpu/usage/#controlling-task-and-gpu-binding - -# Just increase this number of you need more nodes. -#SBATCH -N 2 -#SBATCH -t 03:00:00 -#SBATCH -J -#SBATCH -A m1759 -#SBATCH -q regular -#SBATCH -C gpu -# 8 V100 GPUs (16 GB) per node -#SBATCH --gres=gpu:8 -#SBATCH --exclusive -# one MPI rank per GPU (a quarter-socket) -#SBATCH --tasks-per-node=8 -# request all logical (virtual) cores per quarter-socket -#SBATCH --cpus-per-task=10 -#SBATCH -e WarpX.e%j -#SBATCH -o WarpX.o%j - - -# each Cori GPU node has 2 sockets of Intel Xeon Gold 6148 ('Skylake') @ 2.40 GHz -export WARPX_NMPI_PER_NODE=8 - -# each MPI rank per half-socket has 10 physical cores -# or 20 logical (virtual) cores -# we split half-sockets again by 2 to have one MPI rank per GPU -# over-subscribing each physical core with 2x -# hyperthreading leads to often to slight speedup on Intel -# the settings below make sure threads are close to the -# controlling MPI rank (process) per half socket and -# distribute equally over close-by physical cores and, -# for N>20, also equally over close-by logical cores -export OMP_PROC_BIND=spread -export OMP_PLACES=threads -export OMP_NUM_THREADS=10 - -# for async_io support: (optional) -export MPICH_MAX_THREAD_SAFETY=multiple - -EXE="" - -srun --cpu_bind=cores --gpus-per-task=1 --gpu-bind=map_gpu:0,1,2,3,4,5,6,7 \ - -n $(( ${SLURM_JOB_NUM_NODES} * ${WARPX_NMPI_PER_NODE} )) \ - ${EXE} \ - > output.txt diff --git a/Tools/machines/cori-nersc/cori_haswell.sbatch b/Tools/machines/cori-nersc/cori_haswell.sbatch deleted file mode 100644 index bce5bfcaa3a..00000000000 --- a/Tools/machines/cori-nersc/cori_haswell.sbatch +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -l - -# Just increase this number of you need more nodes. -#SBATCH -N 1 -#SBATCH -t 03:00:00 -#SBATCH -q regular -#SBATCH -C haswell -#SBATCH -J -#SBATCH -A -#SBATCH -e error.txt -#SBATCH -o output.txt -# one MPI rank per half-socket (see below) -#SBATCH --tasks-per-node=4 -# request all logical (virtual) cores per half-socket -#SBATCH --cpus-per-task=16 - - -# each Cori Haswell node has 2 sockets of Intel Xeon E5-2698 v3 -# each Xeon CPU is divided into 2 bus rings that each have direct L3 access -export WARPX_NMPI_PER_NODE=4 - -# each MPI rank per half-socket has 8 physical cores -# or 16 logical (virtual) cores -# over-subscribing each physical core with 2x -# hyperthreading leads to a slight (3.5%) speedup -# the settings below make sure threads are close to the -# controlling MPI rank (process) per half socket and -# distribute equally over close-by physical cores and, -# for N>8, also equally over close-by logical cores -export OMP_PROC_BIND=spread -export OMP_PLACES=threads -export OMP_NUM_THREADS=16 - -# for async_io support: (optional) -export MPICH_MAX_THREAD_SAFETY=multiple - -EXE="" - -srun --cpu_bind=cores -n $(( ${SLURM_JOB_NUM_NODES} * ${WARPX_NMPI_PER_NODE} )) \ - ${EXE} \ - > output.txt diff --git a/Tools/machines/cori-nersc/cori_knl.sbatch b/Tools/machines/cori-nersc/cori_knl.sbatch deleted file mode 100644 index 3c969827599..00000000000 --- a/Tools/machines/cori-nersc/cori_knl.sbatch +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -l - -# Copyright 2019 Maxence Thevenet -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - - -#SBATCH -N 2 -#SBATCH -t 01:00:00 -#SBATCH -q regular -#SBATCH -C knl -#SBATCH -S 4 -#SBATCH -J -#SBATCH -A -#SBATCH -e WarpX.e%j -#SBATCH -o WarpX.o%j - -export OMP_PLACES=threads -export OMP_PROC_BIND=spread - -# KNLs have 4 hyperthreads max -export CORI_MAX_HYPETHREAD_LEVEL=4 -# We use 64 cores out of the 68 available on Cori KNL, -# and leave 4 to the system (see "#SBATCH -S 4" above). -export CORI_NCORES_PER_NODE=64 - -# Typically use 8 MPI ranks per node without hyperthreading, -# i.e., OMP_NUM_THREADS=8 -export WARPX_NMPI_PER_NODE=8 -export WARPX_HYPERTHREAD_LEVEL=1 - -# Compute OMP_NUM_THREADS and the thread count (-c option) -export CORI_NHYPERTHREADS_MAX=$(( ${CORI_MAX_HYPETHREAD_LEVEL} * ${CORI_NCORES_PER_NODE} )) -export WARPX_NTHREADS_PER_NODE=$(( ${WARPX_HYPERTHREAD_LEVEL} * ${CORI_NCORES_PER_NODE} )) -export OMP_NUM_THREADS=$(( ${WARPX_NTHREADS_PER_NODE} / ${WARPX_NMPI_PER_NODE} )) -export WARPX_THREAD_COUNT=$(( ${CORI_NHYPERTHREADS_MAX} / ${WARPX_NMPI_PER_NODE} )) - -# for async_io support: (optional) -export MPICH_MAX_THREAD_SAFETY=multiple - -srun --cpu_bind=cores -n $(( ${SLURM_JOB_NUM_NODES} * ${WARPX_NMPI_PER_NODE} )) -c ${WARPX_THREAD_COUNT} \ - \ - > output.txt diff --git a/Tools/machines/cori-nersc/gpu_warpx.profile.example b/Tools/machines/cori-nersc/gpu_warpx.profile.example deleted file mode 100644 index 0d9d364cb1c..00000000000 --- a/Tools/machines/cori-nersc/gpu_warpx.profile.example +++ /dev/null @@ -1,32 +0,0 @@ -export proj="m1759" - -module purge -module load modules -module load cgpu -module load esslurm -module load gcc/8.3.0 cuda/11.4.0 cmake/3.22.1 -module load openmpi - -export CMAKE_PREFIX_PATH=$HOME/sw/cori_gpu/c-blosc-1.12.1-install:$CMAKE_PREFIX_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/cori_gpu/adios2-2.7.1-install:$CMAKE_PREFIX_PATH - -if [ -d "$HOME/sw/cori_gpu/venvs/cori_gpu_warpx" ] -then - source $HOME/sw/cori_gpu/venvs/cori_gpu_warpx/bin/activate -fi - -# compiler environment hints -export CC=$(which gcc) -export CXX=$(which g++) -export FC=$(which gfortran) -export CUDACXX=$(which nvcc) -export CUDAHOSTCXX=$(which g++) - -# optimize CUDA compilation for V100 -export AMREX_CUDA_ARCH=7.0 - -# allocate a GPU, e.g. to compile on -# 10 logical cores (5 physical), 1 GPU -function getNode() { - salloc -C gpu -N 1 -t 30 -c 10 --gres=gpu:1 -A $proj -} diff --git a/Tools/machines/cori-nersc/haswell_warpx.profile.example b/Tools/machines/cori-nersc/haswell_warpx.profile.example deleted file mode 100644 index f636b1ab555..00000000000 --- a/Tools/machines/cori-nersc/haswell_warpx.profile.example +++ /dev/null @@ -1,17 +0,0 @@ -module swap PrgEnv-intel PrgEnv-gnu -module load cmake/3.22.1 -module switch cray-libsci cray-libsci/20.09.1 -module load cray-hdf5-parallel/1.10.5.2 -module load cray-fftw/3.3.8.10 -module load cray-python/3.9.7.1 - -export PKG_CONFIG_PATH=$FFTW_DIR/pkgconfig:$PKG_CONFIG_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/haswell/c-blosc-1.12.1-install:$CMAKE_PREFIX_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/haswell/adios2-2.7.1-install:$CMAKE_PREFIX_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/haswell/blaspp-2024.05.31-install:$CMAKE_PREFIX_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/haswell/lapackpp-2024.05.31-install:$CMAKE_PREFIX_PATH - -if [ -d "$HOME/sw/haswell/venvs/haswell_warpx" ] -then - source $HOME/sw/haswell/venvs/haswell_warpx/bin/activate -fi diff --git a/Tools/machines/cori-nersc/knl_warpx.profile.example b/Tools/machines/cori-nersc/knl_warpx.profile.example deleted file mode 100644 index fdd7e14d594..00000000000 --- a/Tools/machines/cori-nersc/knl_warpx.profile.example +++ /dev/null @@ -1,21 +0,0 @@ -module swap craype-haswell craype-mic-knl -module swap PrgEnv-intel PrgEnv-gnu -module load cmake/3.22.1 -module switch cray-libsci cray-libsci/20.09.1 -module load cray-hdf5-parallel/1.10.5.2 -module load cray-fftw/3.3.8.10 -module load cray-python/3.9.7.1 - -export PKG_CONFIG_PATH=$FFTW_DIR/pkgconfig:$PKG_CONFIG_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/knl/c-blosc-1.12.1-install:$CMAKE_PREFIX_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/knl/adios2-2.7.1-install:$CMAKE_PREFIX_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/knl/blaspp-2024.05.31-install:$CMAKE_PREFIX_PATH -export CMAKE_PREFIX_PATH=$HOME/sw/knl/lapackpp-2024.05.31-install:$CMAKE_PREFIX_PATH - -if [ -d "$HOME/sw/knl/venvs/knl_warpx" ] -then - source $HOME/sw/knl/venvs/knl_warpx/bin/activate -fi - -export CXXFLAGS="-march=knl" -export CFLAGS="-march=knl" diff --git a/Tools/machines/frontier-olcf/frontier_warpx.profile.example b/Tools/machines/frontier-olcf/frontier_warpx.profile.example index f59f2d3d058..5ca6e1e1622 100644 --- a/Tools/machines/frontier-olcf/frontier_warpx.profile.example +++ b/Tools/machines/frontier-olcf/frontier_warpx.profile.example @@ -6,7 +6,8 @@ export MY_PROFILE=$(cd $(dirname $BASH_SOURCE) && pwd)"/"$(basename $BASH_SOURCE if [ -z ${proj-} ]; then echo "WARNING: The 'proj' variable is not yet set in your $MY_PROFILE file! Please edit its line 2 to continue!"; return; fi # required dependencies -module load cmake/3.23.2 +module switch Core Core/24.07 +module load cmake/3.27.9 module load craype-accel-amd-gfx90a module load rocm/5.7.1 module load cray-mpich/8.1.28 diff --git a/Tools/machines/hpc3-uci/hpc3_gpu_warpx.profile.example b/Tools/machines/hpc3-uci/hpc3_gpu_warpx.profile.example index 017613f9d60..27b6a59592e 100644 --- a/Tools/machines/hpc3-uci/hpc3_gpu_warpx.profile.example +++ b/Tools/machines/hpc3-uci/hpc3_gpu_warpx.profile.example @@ -6,7 +6,7 @@ export MY_PROFILE=$(cd $(dirname $BASH_SOURCE) && pwd)"/"$(basename $BASH_SOURCE if [ -z ${proj-} ]; then echo "WARNING: The 'proj' variable is not yet set in your $MY_PROFILE file! Please edit its line 2 to continue!"; return; fi # required dependencies -module load cmake/3.22.1 +module load cmake/3.22.1 # we need 3.24+ - installing via pipx until module is available module load gcc/11.2.0 module load cuda/11.7.1 module load openmpi/4.1.2/gcc.11.2.0 diff --git a/Tools/machines/hpc3-uci/install_gpu_dependencies.sh b/Tools/machines/hpc3-uci/install_gpu_dependencies.sh index b585c2702b6..56f2bff4025 100755 --- a/Tools/machines/hpc3-uci/install_gpu_dependencies.sh +++ b/Tools/machines/hpc3-uci/install_gpu_dependencies.sh @@ -118,6 +118,8 @@ python3 -m pip install --upgrade build python3 -m pip install --upgrade packaging python3 -m pip install --upgrade wheel python3 -m pip install --upgrade setuptools +python3 -m pip install --upgrade pipx +python3 -m pipx install --upgrade cmake python3 -m pip install --upgrade cython python3 -m pip install --upgrade numpy python3 -m pip install --upgrade pandas diff --git a/Tools/machines/karolina-it4i/install_dependencies.sh b/Tools/machines/karolina-it4i/install_dependencies.sh index cba455f3d29..c1b6e93ab00 100755 --- a/Tools/machines/karolina-it4i/install_dependencies.sh +++ b/Tools/machines/karolina-it4i/install_dependencies.sh @@ -53,7 +53,7 @@ python -m pip install --user --upgrade matplotlib #python -m pip install --user --upgrade yt # install or update WarpX dependencies -python -m pip install --user --upgrade picmistandard==0.29.0 +python -m pip install --user --upgrade picmistandard==0.30.0 python -m pip install --user --upgrade lasy # optional: for optimas (based on libEnsemble & ax->botorch->gpytorch->pytorch) diff --git a/Tools/machines/lassen-llnl/lassen_v100_warpx_toss3.profile.example b/Tools/machines/lassen-llnl/lassen_v100_warpx_toss3.profile.example index 98e8d6410b3..99e61a2fbf6 100644 --- a/Tools/machines/lassen-llnl/lassen_v100_warpx_toss3.profile.example +++ b/Tools/machines/lassen-llnl/lassen_v100_warpx_toss3.profile.example @@ -2,7 +2,7 @@ #export proj="" # edit this and comment in # required dependencies -module load cmake/3.23.1 +module load cmake/3.29.2 module load gcc/11.2.1 module load cuda/12.0.0 diff --git a/Tools/machines/lxplus-cern/lxplus_warpx.profile.example b/Tools/machines/lxplus-cern/lxplus_warpx.profile.example index 3f3770fac3f..e461e4503f0 100644 --- a/Tools/machines/lxplus-cern/lxplus_warpx.profile.example +++ b/Tools/machines/lxplus-cern/lxplus_warpx.profile.example @@ -22,7 +22,7 @@ then # create and activate the spack environment export SPACK_STACK_USE_PYTHON=1 export SPACK_STACK_USE_CUDA=1 - spack env create warpx-lxplus-cuda-py $WORK/WarpX/Tools/machines/lxplus-cern/spack.yaml + spack env create warpx-lxplus-cuda-py $WORK/warpx/Tools/machines/lxplus-cern/spack.yaml spack env activate warpx-lxplus-cuda-py spack install else diff --git a/Tools/machines/ookami-sbu/ookami_warpx.profile.example b/Tools/machines/ookami-sbu/ookami_warpx.profile.example index 321e3ce1d59..dc8c7ac6639 100644 --- a/Tools/machines/ookami-sbu/ookami_warpx.profile.example +++ b/Tools/machines/ookami-sbu/ookami_warpx.profile.example @@ -2,7 +2,7 @@ #export proj= # required dependencies -module load cmake/3.19.0 +module load cmake/3.19.0 # please check for a 3.24+ module and report back module load gcc/10.3.0 module load openmpi/gcc10/4.1.0 diff --git a/Tools/machines/perlmutter-nersc/install_gpu_dependencies.sh b/Tools/machines/perlmutter-nersc/install_gpu_dependencies.sh index ac95ad9f3a0..da48d9543a0 100755 --- a/Tools/machines/perlmutter-nersc/install_gpu_dependencies.sh +++ b/Tools/machines/perlmutter-nersc/install_gpu_dependencies.sh @@ -145,6 +145,10 @@ cmake \ cmake --build ${build_dir}/heffte-pm-gpu-build --target install --parallel 16 rm -rf ${build_dir}/heffte-pm-gpu-build +# work-around for heFFTe 2.4.0 bug with NVCC +# https://github.com/icl-utk-edu/heffte/pull/54 +sed -i 's/__AVX__/NOTDEFINED_DONOTUSE/g' ${SW_DIR}/heffte-2.4.0/include/stock_fft/heffte_stock_vec_types.h + # Python ###################################################################### # diff --git a/Tools/machines/pitzer-osc/install_cpu_dependencies.sh b/Tools/machines/pitzer-osc/install_cpu_dependencies.sh new file mode 100644 index 00000000000..f0b6ce4b950 --- /dev/null +++ b/Tools/machines/pitzer-osc/install_cpu_dependencies.sh @@ -0,0 +1,156 @@ +#!/bin/bash +# +# Copyright 2024 The WarpX Community +# +# This file is part of WarpX. +# +# Author: Zhongwei Wang +# License: BSD-3-Clause-LBNL + +# Exit on first error encountered ############################################# +# +set -eu -o pipefail + +# Check: ###################################################################### +# +# Was pitzer_cpu_warpx.profile sourced and configured correctly? +if [ -z ${proj-} ]; then + echo "WARNING: The 'proj' variable is not yet set in your pitzer_cpu_warpx.profile file! Please edit its line 2 to continue!" + exit 1 +fi + +# Remove old dependencies ##################################################### +# +rm -rf ${SW_DIR} +mkdir -p ${SW_DIR} + +# remove common user mistakes in python, located in .local instead of a venv +python3 -m pip uninstall -qq -y pywarpx +python3 -m pip uninstall -qq -y warpx +python3 -m pip uninstall -qqq -y mpi4py 2>/dev/null || true + +# General extra dependencies ################################################## +# +SRC_DIR="${HOME}/src" +build_dir=$(mktemp -d) + +# boost (for QED table generation support) +cd ${SRC_DIR} +wget https://archives.boost.io/release/1.82.0/source/boost_1_82_0.tar.gz +tar -xzvf boost_1_82_0.tar.gz +rm -rf boost_1_82_0.tar.gz +cd - + +cd ${SRC_DIR}/boost_1_82_0 +./bootstrap.sh --prefix=$SW_DIR/boost-1.82.0 +./b2 install +cd - + +# BLAS++ (for PSATD+RZ) +if [ -d ${SRC_DIR}/blaspp ]; then + cd ${SRC_DIR}/blaspp + git fetch --prune + git checkout v2024.05.31 + cd - +else + git clone -b v2024.05.31 https://github.com/icl-utk-edu/blaspp.git ${SRC_DIR}/blaspp +fi +rm -rf ${build_dir}/blaspp-pitzer-cpu-build +CXX=$(which CC) cmake -S ${SRC_DIR}/blaspp \ + -B ${build_dir}/blaspp-pitzer-cpu-build \ + -Duse_openmp=ON \ + -Dgpu_backend=OFF \ + -DCMAKE_CXX_STANDARD=17 \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/blaspp-2024.05.31 +cmake --build ${build_dir}/blaspp-pitzer-cpu-build --target install --parallel 16 +rm -rf ${build_dir}/blaspp-pitzer-cpu-build + +# LAPACK++ (for PSATD+RZ) +if [ -d ${SRC_DIR}/lapackpp ]; then + cd ${SRC_DIR}/lapackpp + git fetch --prune + git checkout v2024.05.31 + cd - +else + git clone -b v2024.05.31 https://github.com/icl-utk-edu/lapackpp.git ${SRC_DIR}/lapackpp +fi +rm -rf ${build_dir}/lapackpp-pitzer-cpu-build +CXX=$(which CC) CXXFLAGS="-DLAPACK_FORTRAN_ADD_" cmake -S ${SRC_DIR}/lapackpp \ + -B ${build_dir}/lapackpp-pitzer-cpu-build \ + -DCMAKE_CXX_STANDARD=17 \ + -Dbuild_tests=OFF \ + -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/lapackpp-2024.05.31 +cmake --build ${build_dir}/lapackpp-pitzer-cpu-build --target install --parallel 16 +rm -rf ${build_dir}/lapackpp-pitzer-cpu-build + +# c-blosc (I/O compression, for openPMD) +if [ -d ${SRC_DIR}/c-blosc ]; then + cd ${SRC_DIR}/c-blosc + git fetch --prune + git checkout v1.21.6 + cd - +else + git clone -b v1.21.6 https://github.com/Blosc/c-blosc.git ${SRC_DIR}/c-blosc +fi +rm -rf ${build_dir}/c-blosc-pitzer-build +cmake -S ${SRC_DIR}/c-blosc \ + -B ${build_dir}/c-blosc-pitzer-build \ + -DBUILD_TESTS=OFF \ + -DBUILD_BENCHMARKS=OFF \ + -DDEACTIVATE_AVX2=OFF \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/c-blosc-1.21.6 +cmake --build ${build_dir}/c-blosc-pitzer-build --target install --parallel 16 +rm -rf ${build_dir}/c-blosc-pitzer-build + +# ADIOS2 (for openPMD) +if [ -d ${SRC_DIR}/adios2 ]; then + cd ${SRC_DIR}/adios2 + git fetch --prune + git checkout v2.10.1 + cd - +else + git clone -b v2.10.1 https://github.com/ornladios/ADIOS2.git ${SRC_DIR}/adios2 +fi +rm -rf ${build_dir}/adios2-pitzer-build +cmake -S ${SRC_DIR}/adios2 \ + -B ${build_dir}/adios2-pitzer-build \ + -DBUILD_TESTING=OFF \ + -DADIOS2_BUILD_EXAMPLES=OFF \ + -DADIOS2_USE_Blosc=ON \ + -DADIOS2_USE_Fortran=OFF \ + -DADIOS2_USE_Python=OFF \ + -DADIOS2_USE_SST=OFF \ + -DADIOS2_USE_ZeroMQ=OFF \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/adios2-2.10.1 +cmake --build ${build_dir}/adios2-pitzer-build --target install -j 16 +rm -rf ${build_dir}/adios2-pitzer-build + +rm -rf ${build_dir} + +# Python ###################################################################### +# +python3 -m pip install --upgrade --user virtualenv +rm -rf ${SW_DIR}/venvs/${VENV_NAME} +python3 -m venv ${SW_DIR}/venvs/${VENV_NAME} +source ${SW_DIR}/venvs/${VENV_NAME}/bin/activate +python3 -m pip install --upgrade pip +python3 -m pip cache purge +python3 -m pip install --upgrade build +python3 -m pip install --upgrade packaging +python3 -m pip install --upgrade wheel +python3 -m pip install --upgrade setuptools +python3 -m pip install --upgrade cython +python3 -m pip install --upgrade numpy +python3 -m pip install --upgrade pandas +python3 -m pip install --upgrade scipy +python3 -m pip install --upgrade mpi4py --no-cache-dir --no-build-isolation --no-binary mpi4py +python3 -m pip install --upgrade openpmd-api +python3 -m pip install --upgrade matplotlib +python3 -m pip install --upgrade yt + +# install or update WarpX dependencies such as picmistandard +python3 -m pip install --upgrade -r ${SRC_DIR}/warpx/requirements.txt + +# ML dependencies +python3 -m pip install --upgrade torch diff --git a/Tools/machines/pitzer-osc/install_v100_dependencies.sh b/Tools/machines/pitzer-osc/install_v100_dependencies.sh new file mode 100644 index 00000000000..5601b4d76c9 --- /dev/null +++ b/Tools/machines/pitzer-osc/install_v100_dependencies.sh @@ -0,0 +1,156 @@ +#!/bin/bash +# +# Copyright 2024 The WarpX Community +# +# This file is part of WarpX. +# +# Author: Zhongwei Wang +# License: BSD-3-Clause-LBNL + +# Exit on first error encountered ############################################# +# +set -eu -o pipefail + +# Check: ###################################################################### +# +# Was pitzer_v100_warpx.profile sourced and configured correctly? +if [ -z ${proj-} ]; then + echo "WARNING: The 'proj' variable is not yet set in your pitzer_v100_warpx.profile file! Please edit its line 2 to continue!" + exit 1 +fi + +# Remove old dependencies ##################################################### +# +rm -rf ${SW_DIR} +mkdir -p ${SW_DIR} + +# remove common user mistakes in python, located in .local instead of a venv +python3 -m pip uninstall -qq -y pywarpx +python3 -m pip uninstall -qq -y warpx +python3 -m pip uninstall -qqq -y mpi4py 2>/dev/null || true + +# General extra dependencies ################################################## +# +SRC_DIR="${HOME}/src" +build_dir=$(mktemp -d) + +# boost (for QED table generation support) +cd ${SRC_DIR} +wget https://archives.boost.io/release/1.82.0/source/boost_1_82_0.tar.gz +tar -xzvf boost_1_82_0.tar.gz +rm -rf boost_1_82_0.tar.gz +cd - + +cd ${SRC_DIR}/boost_1_82_0 +./bootstrap.sh --prefix=${SW_DIR}/boost-1.82.0 +./b2 install +cd - + +# BLAS++ (for PSATD+RZ) +if [ -d ${SRC_DIR}/blaspp ]; then + cd ${SRC_DIR}/blaspp + git fetch + git checkout v2024.05.31 + cd - +else + git clone -b v2024.05.31 https://github.com/icl-utk-edu/blaspp.git ${SRC_DIR}/blaspp +fi +rm -rf ${build_dir}/blaspp-pitzer-v100-build +CXX=$(which CC) cmake -S ${SRC_DIR}/blaspp \ + -B ${build_dir}/blaspp-pitzer-v100-build \ + -Duse_openmp=ON \ + -Dgpu_backend=cuda \ + -DCMAKE_CXX_STANDARD=17 \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/blaspp-2024.05.31 +cmake --build ${build_dir}/blaspp-pitzer-v100-build --target install --parallel 16 +rm -rf ${build_dir}/blaspp-pitzer-v100-build + +# LAPACK++ (for PSATD+RZ) +if [ -d ${SRC_DIR}/lapackpp ]; then + cd ${SRC_DIR}/lapackpp + git fetch + git checkout v2024.05.31 + cd - +else + git clone -b v2024.05.31 https://github.com/icl-utk-edu/lapackpp.git ${SRC_DIR}/lapackpp +fi +rm -rf ${build_dir}/lapackpp-pitzer-v100-build +CXX=$(which CC) CXXFLAGS="-DLAPACK_FORTRAN_ADD_" cmake -S ${SRC_DIR}/lapackpp \ + -B ${build_dir}/lapackpp-pitzer-v100-build \ + -DCMAKE_CXX_STANDARD=17 \ + -Dbuild_tests=OFF \ + -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/lapackpp-2024.05.31 +cmake --build ${build_dir}/lapackpp-pitzer-v100-build --target install --parallel 16 +rm -rf ${build_dir}/lapackpp-pitzer-v100-build + +# c-blosc (I/O compression, for openPMD) +if [ -d ${SRC_DIR}/c-blosc ]; then + cd ${SRC_DIR}/c-blosc + git fetch --prune + git checkout v1.21.6 + cd - +else + git clone -b v1.21.6 https://github.com/Blosc/c-blosc.git ${SRC_DIR}/c-blosc +fi +rm -rf ${build_dir}/c-blosc-pitzer-build +cmake -S ${SRC_DIR}/c-blosc \ + -B ${build_dir}/c-blosc-pitzer-build \ + -DBUILD_TESTS=OFF \ + -DBUILD_BENCHMARKS=OFF \ + -DDEACTIVATE_AVX2=OFF \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/c-blosc-1.21.6 +cmake --build ${build_dir}/c-blosc-pitzer-build --target install --parallel 16 +rm -rf ${build_dir}/c-blosc-pitzer-build + +# ADIOS2 (for openPMD) +if [ -d ${SRC_DIR}/adios2 ]; then + cd ${SRC_DIR}/adios2 + git fetch --prune + git checkout v2.10.1 + cd - +else + git clone -b v2.10.1 https://github.com/ornladios/ADIOS2.git ${SRC_DIR}/adios2 +fi +rm -rf ${build_dir}/adios2-pitzer-build +cmake -S ${SRC_DIR}/adios2 \ + -B ${build_dir}/adios2-pitzer-build \ + -DBUILD_TESTING=OFF \ + -DADIOS2_BUILD_EXAMPLES=OFF \ + -DADIOS2_USE_Blosc=ON \ + -DADIOS2_USE_Fortran=OFF \ + -DADIOS2_USE_Python=OFF \ + -DADIOS2_USE_SST=OFF \ + -DADIOS2_USE_ZeroMQ=OFF \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/adios2-2.10.1 +cmake --build ${build_dir}/adios2-pitzer-build --target install -j 16 +rm -rf ${build_dir}/adios2-pitzer-build + +rm -rf ${build_dir} + +# Python ###################################################################### +# +python3 -m pip install --upgrade --user virtualenv +rm -rf ${SW_DIR}/venvs/${VENV_NAME} +python3 -m venv ${SW_DIR}/venvs/${VENV_NAME} +source ${SW_DIR}/venvs/${VENV_NAME}/bin/activate +python3 -m pip install --upgrade pip +python3 -m pip cache purge +python3 -m pip install --upgrade build +python3 -m pip install --upgrade packaging +python3 -m pip install --upgrade wheel +python3 -m pip install --upgrade setuptools +python3 -m pip install --upgrade cython +python3 -m pip install --upgrade numpy +python3 -m pip install --upgrade pandas +python3 -m pip install --upgrade scipy +python3 -m pip install --upgrade mpi4py --no-cache-dir --no-build-isolation --no-binary mpi4py +python3 -m pip install --upgrade openpmd-api +python3 -m pip install --upgrade matplotlib +python3 -m pip install --upgrade yt + +# install or update WarpX dependencies such as picmistandard +python3 -m pip install --upgrade -r ${SRC_DIR}/warpx/requirements.txt + +# ML dependencies +python3 -m pip install --upgrade torch diff --git a/Tools/machines/pitzer-osc/pitzer_cpu.sbatch b/Tools/machines/pitzer-osc/pitzer_cpu.sbatch new file mode 100644 index 00000000000..8097b3842f9 --- /dev/null +++ b/Tools/machines/pitzer-osc/pitzer_cpu.sbatch @@ -0,0 +1,19 @@ +#!/bin/bash +#SBATCH --time=0:20:00 +#SBATCH --nodes=1 --ntasks-per-node=6 +#SBATCH --cpus-per-task=8 +#SBATCH --job-name= +#SBATCH --account= +#SBATCH --output=./logs/%x_%j.out +#SBATCH --error=./logs/%x_%j.err + +# Pitzer cluster has 224 CPU nodes equipped with dual Intel Xeon 6148 (40 cores per node) and 340 CPU nodes with dual Intel Xeon 8268 (48 cores per node). https://www.osc.edu/resources/technical_support/supercomputers/pitzer + +source ${HOME}/pitzer_cpu_warpx.profile +export OMP_NUM_THREADS=${SLURM_CPUS_PER_TASK} + +# executable & inputs file or python interpreter & PICMI script here +EXE=${HOME}/src/warpx/build/bin/warpx.2d +INPUTS=inputs + +srun --cpu-bind=cores ${EXE} ${INPUTS} >./logs/${SLURM_JOB_NAME}_${SLURM_JOBID}.log 2>&1 diff --git a/Tools/machines/pitzer-osc/pitzer_cpu_warpx.profile.example b/Tools/machines/pitzer-osc/pitzer_cpu_warpx.profile.example new file mode 100644 index 00000000000..d99c16b6cb6 --- /dev/null +++ b/Tools/machines/pitzer-osc/pitzer_cpu_warpx.profile.example @@ -0,0 +1,54 @@ +# please set your project account +export proj="" # change me! + +# remembers the location of this script +export MY_CPU_PROFILE=$(cd $(dirname $BASH_SOURCE) && pwd)"/"$(basename $BASH_SOURCE) +if [ -z ${proj-} ]; then + echo "WARNING: The 'proj' variable is not yet set in your $MY_CPU_PROFILE file! Please edit its line 2 to continue!" + return +fi + +export SW_DIR="${HOME}/sw/osc/pitzer/cpu" + +module purge +module load cmake/3.25.2 +module load gnu/12.3.0 +module load openmpi/4.1.5-hpcx + +# optional: for python binding support +module load miniconda3/24.1.2-py310 +export VENV_NAME="warpx-pitzer-cpu" +if [ -d "${SW_DIR}/venvs/${VENV_NAME}" ]; then + source ${SW_DIR}/venvs/${VENV_NAME}/bin/activate +fi + +# an alias to request an interactive batch node for one hour +# for parallel execution, start on the batch node: srun +alias getNode="salloc -N 1 --ntasks-per-node=2 --cpus-per-task=20 -t 1:00:00 -A $proj" +# an alias to run a command on a batch node for up to 30min +# usage: runNode +alias runNode="srun -N 1 --ntasks-per-node=2 --cpus-per-task=20 -t 1:00:00 -A $proj" + +# optional: for PSATD in RZ geometry support +export CMAKE_PREFIX_PATH=${SW_DIR}/blaspp-2024.05.31:$CMAKE_PREFIX_PATH +export CMAKE_PREFIX_PATH=${SW_DIR}/lapackpp-2024.05.31:$CMAKE_PREFIX_PATH +export LD_LIBRARY_PATH=${SW_DIR}/blaspp-2024.05.31/lib64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${SW_DIR}/lapackpp-2024.05.31/lib64:$LD_LIBRARY_PATH + +# optional: for QED lookup table generation support +# use self-installed boost +export CMAKE_PREFIX_PATH=${SW_DIR}/boost-1.82.0:$CMAKE_PREFIX_PATH +export LD_LIBRARY_PATH=${SW_DIR}/boost-1.82.0/lib:$LD_LIBRARY_PATH + +# optional: for openPMD support (hdf5 and adios2) +module load hdf5/1.12.2 +export CMAKE_PREFIX_PATH=${SW_DIR}/c-blosc-1.21.6:$CMAKE_PREFIX_PATH +export CMAKE_PREFIX_PATH=${SW_DIR}/adios2-2.10.1:$CMAKE_PREFIX_PATH +export LD_LIBRARY_PATH=${SW_DIR}/c-blosc-1.21.6/lib64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${SW_DIR}/adios2-2.10.1/lib64:$LD_LIBRARY_PATH +export PATH=${SW_DIR}/adios2-2.10.1/bin:${PATH} + +# compiler environment hints +export CC=$(which gcc) +export CXX=$(which g++) +export FC=$(which gfortran) diff --git a/Tools/machines/pitzer-osc/pitzer_v100.sbatch b/Tools/machines/pitzer-osc/pitzer_v100.sbatch new file mode 100644 index 00000000000..d34868da16c --- /dev/null +++ b/Tools/machines/pitzer-osc/pitzer_v100.sbatch @@ -0,0 +1,26 @@ +#!/bin/bash +#SBATCH --time=0:20:00 +#SBATCH --nodes=1 --ntasks-per-node=2 +#SBATCH --cpus-per-task=24 +#SBATCH --gpus-per-task=1 +#SBATCH --gpu-bind=closest +#SBATCH --job-name= +#SBATCH --account= +#SBATCH --output=./logs/%x_%j.out +#SBATCH --error=./logs/%x_%j.err + +# Pitzer cluster has 32 GPU nodes with dual Intel Xeon 6148 and dual V100 (16GB) GPUs and 42 nodes with dual Intel Xeon 8268 and dual V100 (32GB) GPUs. https://www.osc.edu/resources/technical_support/supercomputers/pitzer + +source ${HOME}/pitzer_v100_warpx.profile +export OMP_NUM_THREADS=${SLURM_CPUS_PER_TASK} + +echo "GPU Information:" +nvidia-smi + +GPU_AWARE_MPI="amrex.use_gpu_aware_mpi=1" + +# executable & inputs file or python interpreter & PICMI script here +EXE=${HOME}/src/warpx/build_v100/bin/warpx.2d +INPUTS=inputs + +srun --cpu-bind=cores ${EXE} ${INPUTS} ${GPU_AWARE_MPI} >./logs/${SLURM_JOB_NAME}_${SLURM_JOBID}.log 2>&1 diff --git a/Tools/machines/pitzer-osc/pitzer_v100_warpx.profile.example b/Tools/machines/pitzer-osc/pitzer_v100_warpx.profile.example new file mode 100644 index 00000000000..061794f5f68 --- /dev/null +++ b/Tools/machines/pitzer-osc/pitzer_v100_warpx.profile.example @@ -0,0 +1,64 @@ +# please set your project account +export proj="" # change me! + +# remembers the location of this script +export MY_V100_PROFILE=$(cd $(dirname $BASH_SOURCE) && pwd)"/"$(basename $BASH_SOURCE) +if [ -z ${proj-} ]; then + echo "WARNING: The 'proj' variable is not yet set in your $MY_V100_PROFILE file! Please edit its line 2 to continue!" + return +fi + +export SW_DIR="${HOME}/sw/osc/pitzer/v100" + +module purge +module load cmake/3.25.2 +module load intel/19.0.5 +module load cuda/11.8.0 +module load openmpi-cuda/4.1.5-hpcx +module load gcc-compatibility/11.2.0 + +# optional: for python binding support +module load miniconda3/24.1.2-py310 +export VENV_NAME="warpx-pitzer-v100" +if [ -d "${SW_DIR}/venvs/${VENV_NAME}" ]; then + source ${SW_DIR}/venvs/${VENV_NAME}/bin/activate +fi + +# an alias to request an interactive batch node for one hour +# for parallel execution, start on the batch node: srun +alias getNode="salloc -N 1 --ntasks-per-node=2 --cpus-per-task=20 --gpus-per-task=v100:1 -t 1:00:00 -A $proj" +# an alias to run a command on a batch node for up to 30min +# usage: runNode +alias runNode="srun -N 1 --ntasks-per-node=2 --cpus-per-task=20 --gpus-per-task=v100:1 -t 1:00:00 -A $proj" + +# optional: for PSATD in RZ geometry support +export CMAKE_PREFIX_PATH=${SW_DIR}/blaspp-2024.05.31:$CMAKE_PREFIX_PATH +export CMAKE_PREFIX_PATH=${SW_DIR}/lapackpp-2024.05.31:$CMAKE_PREFIX_PATH +export LD_LIBRARY_PATH=${SW_DIR}/blaspp-2024.05.31/lib64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${SW_DIR}/lapackpp-2024.05.31/lib64:$LD_LIBRARY_PATH + +# optional: for QED lookup table generation support +# use self-installed boost +export CMAKE_PREFIX_PATH=${SW_DIR}/boost-1.82.0:$CMAKE_PREFIX_PATH +export LD_LIBRARY_PATH=${SW_DIR}/boost-1.82.0/lib:$LD_LIBRARY_PATH + +# optional: for openPMD support (hdf5 and adios2) +# use self-installed hdf5 +module load hdf5/1.12.0 + +export CMAKE_PREFIX_PATH=${SW_DIR}/c-blosc-1.21.6:$CMAKE_PREFIX_PATH +export CMAKE_PREFIX_PATH=${SW_DIR}/adios2-2.10.1:$CMAKE_PREFIX_PATH +export LD_LIBRARY_PATH=${SW_DIR}/c-blosc-1.21.6/lib64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${SW_DIR}/adios2-2.10.1/lib64:$LD_LIBRARY_PATH +export PATH=${SW_DIR}/adios2-2.10.1/bin:${PATH} + +# avoid relocation truncation error which result from large executable size +export CUDAFLAGS="--host-linker-script=use-lcs" # https://github.com/ECP-WarpX/WarpX/pull/3673 +export AMREX_CUDA_ARCH=7.0 # 7.0: V100, 8.0: V100, 9.0: H100 https://github.com/ECP-WarpX/WarpX/issues/3214 + +# compiler environment hints +export CC=$(which gcc) +export CXX=$(which g++) +export FC=$(which gfortran) +export CUDACXX=$(which nvcc) +export CUDAHOSTCXX=${CXX} diff --git a/Tools/machines/polaris-alcf/polaris_gpu_warpx.profile.example b/Tools/machines/polaris-alcf/polaris_gpu_warpx.profile.example index 333434c1b97..d5cb1ec7a07 100644 --- a/Tools/machines/polaris-alcf/polaris_gpu_warpx.profile.example +++ b/Tools/machines/polaris-alcf/polaris_gpu_warpx.profile.example @@ -3,20 +3,24 @@ export proj="" # change me! # swap to GNU programming environment (with gcc 11.2) module swap PrgEnv-nvhpc PrgEnv-gnu -module swap gcc/12.2.0 gcc/11.2.0 -module load nvhpc-mixed/22.11 +module load gcc-native/12.3 +module load nvhpc-mixed/23.9 # swap to the Milan cray package -module swap craype-x86-rome craype-x86-milan +module load craype-x86-milan + +# extra modules +module use /soft/modulefiles +module load spack-pe-gnu # required dependencies -module load cmake/3.23.2 +module load cmake/3.27.7 # optional: for QED support with detailed tables -# module load boost/1.81.0 +module load boost # optional: for openPMD and PSATD+RZ support -module load cray-hdf5-parallel/1.12.2.3 +module load cray-hdf5-parallel/1.12.2.9 export CMAKE_PREFIX_PATH=/home/${USER}/sw/polaris/gpu/c-blosc-1.21.1:$CMAKE_PREFIX_PATH export CMAKE_PREFIX_PATH=/home/${USER}/sw/polaris/gpu/adios2-2.8.3:$CMAKE_PREFIX_PATH export CMAKE_PREFIX_PATH=/home/${USER}/sw/polaris/gpu/blaspp-2024.05.31:$CMAKE_PREFIX_PATH @@ -30,7 +34,7 @@ export LD_LIBRARY_PATH=/home/${USER}/sw/polaris/gpu/lapackpp-2024.05.31/lib64:$L export PATH=/home/${USER}/sw/polaris/gpu/adios2-2.8.3/bin:${PATH} # optional: for Python bindings or libEnsemble -module load cray-python/3.9.13.1 +module load python/3.10.9 if [ -d "/home/${USER}/sw/polaris/gpu/venvs/warpx" ] then diff --git a/Tools/machines/spock-olcf/spock_mi100.sbatch b/Tools/machines/spock-olcf/spock_mi100.sbatch deleted file mode 100644 index 4ee09201b3f..00000000000 --- a/Tools/machines/spock-olcf/spock_mi100.sbatch +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -#SBATCH -A -#SBATCH -J warpx -#SBATCH -o %x-%j.out -#SBATCH -t 00:10:00 -#SBATCH -p ecp -#SBATCH -N 1 - -export OMP_NUM_THREADS=1 -srun -n 4 -c 2 --ntasks-per-node=4 ./warpx inputs > output.txt diff --git a/Tools/machines/spock-olcf/spock_warpx.profile.example b/Tools/machines/spock-olcf/spock_warpx.profile.example deleted file mode 100644 index 6b10656c3bf..00000000000 --- a/Tools/machines/spock-olcf/spock_warpx.profile.example +++ /dev/null @@ -1,29 +0,0 @@ -# please set your project account -#export proj= - -# required dependencies -module load cmake/3.20.2 -module load craype-accel-amd-gfx908 -module load rocm/4.3.0 - -# optional: faster builds -module load ccache -module load ninja - -# optional: just an additional text editor -module load nano - -# optional: an alias to request an interactive node for one hour -alias getNode="salloc -A $proj -J warpx -t 01:00:00 -p ecp -N 1" - -# fix system defaults: do not escape $ with a \ on tab completion -shopt -s direxpand - -# optimize CUDA compilation for MI100 -export AMREX_AMD_ARCH=gfx908 - -# compiler environment hints -export CC=$ROCM_PATH/llvm/bin/clang -export CXX=$(which hipcc) -export LDFLAGS="-L${CRAYLIBS_X86_64} $(CC --cray-print-opts=libs) -lmpi" -# GPU aware MPI: ${PE_MPICH_GTL_DIR_gfx908} -lmpi_gtl_hsa diff --git a/Tools/machines/taurus-zih/taurus_warpx.profile.example b/Tools/machines/taurus-zih/taurus_warpx.profile.example index f564f696c4a..434d773067b 100644 --- a/Tools/machines/taurus-zih/taurus_warpx.profile.example +++ b/Tools/machines/taurus-zih/taurus_warpx.profile.example @@ -5,7 +5,7 @@ module load modenv/hiera module load foss/2021b module load CUDA/11.8.0 -module load CMake/3.22.1 +module load CMake/3.27.6 # optional: for QED support with detailed tables #module load Boost # TODO diff --git a/Tools/machines/tioga-llnl/install_mi300a_dependencies.sh b/Tools/machines/tioga-llnl/install_mi300a_dependencies.sh new file mode 100644 index 00000000000..7e002838e4a --- /dev/null +++ b/Tools/machines/tioga-llnl/install_mi300a_dependencies.sh @@ -0,0 +1,234 @@ +#!/bin/bash +# +# Copyright 2024 The WarpX Community +# +# This file is part of WarpX. +# +# Author: Axel Huebl +# License: BSD-3-Clause-LBNL + +# Exit on first error encountered ############################################# +# +set -eu -o pipefail + + +# Check: ###################################################################### +# +# Was tioga_mi300a_warpx.profile sourced and configured correctly? +# early access: not yet used! +#if [ -z ${proj-} ]; then echo "WARNING: The 'proj' variable is not yet set in your tioga_mi300a_warpx.profile file! Please edit its line 2 to continue!"; exit 1; fi + + +# Remove old dependencies ##################################################### +# +SRC_DIR="/p/lustre1/${USER}/tioga/src" +SW_DIR="/p/lustre1/${USER}/tioga/warpx/mi300a" +rm -rf ${SW_DIR} +mkdir -p ${SW_DIR} + +# remove common user mistakes in python, located in .local instead of a venv +python3 -m pip uninstall -qq -y pywarpx +python3 -m pip uninstall -qq -y warpx +python3 -m pip uninstall -qqq -y mpi4py 2>/dev/null || true + + +# General extra dependencies ################################################## +# + +# tmpfs build directory: avoids issues often seen with $HOME and is faster +build_dir=$(mktemp -d) +build_procs=24 + +# C-Blosc2 (I/O compression) +if [ -d ${SRC_DIR}/c-blosc2 ] +then + cd ${SRC_DIR}/c-blosc2 + git fetch --prune + git checkout v2.15.1 + cd - +else + git clone -b v2.15.1 https://github.com/Blosc/c-blosc2.git ${SRC_DIR}/c-blosc2 +fi +cmake \ + --fresh \ + -S ${SRC_DIR}/c-blosc2 \ + -B ${build_dir}/c-blosc2-build \ + -DBUILD_TESTS=OFF \ + -DBUILD_BENCHMARKS=OFF \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_FUZZERS=OFF \ + -DBUILD_STATIC=OFF \ + -DDEACTIVATE_AVX2=OFF \ + -DDEACTIVATE_AVX512=OFF \ + -DWITH_SANITIZER=OFF \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/c-blosc-2.15.1 +cmake \ + --build ${build_dir}/c-blosc2-build \ + --target install \ + --parallel ${build_procs} +rm -rf ${build_dir}/c-blosc2-build + +# ADIOS2 +if [ -d ${SRC_DIR}/adios2 ] +then + cd ${SRC_DIR}/adios2 + git fetch --prune + git checkout v2.10.1 + cd - +else + git clone -b v2.10.1 https://github.com/ornladios/ADIOS2.git ${SRC_DIR}/adios2 +fi +cmake \ + --fresh \ + -S ${SRC_DIR}/adios2 \ + -B ${build_dir}/adios2-build \ + -DADIOS2_USE_Blosc2=ON \ + -DADIOS2_USE_Campaign=OFF \ + -DADIOS2_USE_Fortran=OFF \ + -DADIOS2_USE_Python=OFF \ + -DADIOS2_USE_ZeroMQ=OFF \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/adios2-2.10.1 +cmake \ + --build ${build_dir}/adios2-build \ + --target install \ + --parallel ${build_procs} +rm -rf ${build_dir}/adios2-build + +# BLAS++ (for PSATD+RZ) +if [ -d ${SRC_DIR}/blaspp ] +then + cd ${SRC_DIR}/blaspp + git fetch --prune + git checkout v2024.05.31 + cd - +else + git clone -b v2024.05.31 https://github.com/icl-utk-edu/blaspp.git ${SRC_DIR}/blaspp +fi +cmake \ + --fresh \ + -S ${SRC_DIR}/blaspp \ + -B ${build_dir}/blaspp-tioga-mi300a-build \ + -Duse_openmp=OFF \ + -Dgpu_backend=hip \ + -DCMAKE_CXX_STANDARD=17 \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/blaspp-2024.05.31 +cmake \ + --build ${build_dir}/blaspp-tioga-mi300a-build \ + --target install \ + --parallel ${build_procs} +rm -rf ${build_dir}/blaspp-tioga-mi300a-build + +# LAPACK++ (for PSATD+RZ) +if [ -d ${SRC_DIR}/lapackpp ] +then + cd ${SRC_DIR}/lapackpp + git fetch --prune + git checkout v2024.05.31 + cd - +else + git clone -b v2024.05.31 https://github.com/icl-utk-edu/lapackpp.git ${SRC_DIR}/lapackpp +fi +cmake \ + --fresh \ + -S ${SRC_DIR}/lapackpp \ + -B ${build_dir}/lapackpp-tioga-mi300a-build \ + -DCMAKE_CXX_STANDARD=17 \ + -Dgpu_backend=hip \ + -Dbuild_tests=OFF \ + -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/lapackpp-2024.05.31 +cmake \ + --build ${build_dir}/lapackpp-tioga-mi300a-build \ + --target install \ + --parallel ${build_procs} +rm -rf ${build_dir}/lapackpp-tioga-mi300a-build + +# heFFTe +if [ -d ${SRC_DIR}/heffte ] +then + cd ${SRC_DIR}/heffte + git fetch --prune + git checkout v2.4.0 + cd - +else + git clone -b v2.4.0 https://github.com/icl-utk-edu/heffte.git ${SRC_DIR}/heffte +fi +cmake \ + --fresh \ + -S ${SRC_DIR}/heffte \ + -B ${build_dir}/heffte-build \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_CXX_STANDARD=17 \ + -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \ + -DCMAKE_INSTALL_PREFIX=${SW_DIR}/heffte-2.4.0 \ + -DHeffte_DISABLE_GPU_AWARE_MPI=OFF \ + -DHeffte_ENABLE_AVX=OFF \ + -DHeffte_ENABLE_AVX512=OFF \ + -DHeffte_ENABLE_FFTW=OFF \ + -DHeffte_ENABLE_CUDA=OFF \ + -DHeffte_ENABLE_ROCM=ON \ + -DHeffte_ENABLE_ONEAPI=OFF \ + -DHeffte_ENABLE_MKL=OFF \ + -DHeffte_ENABLE_DOXYGEN=OFF \ + -DHeffte_SEQUENTIAL_TESTING=OFF \ + -DHeffte_ENABLE_TESTING=OFF \ + -DHeffte_ENABLE_TRACING=OFF \ + -DHeffte_ENABLE_PYTHON=OFF \ + -DHeffte_ENABLE_FORTRAN=OFF \ + -DHeffte_ENABLE_SWIG=OFF \ + -DHeffte_ENABLE_MAGMA=OFF +cmake \ + --build ${build_dir}/heffte-build \ + --target install \ + --parallel ${build_procs} +rm -rf ${build_dir}/heffte-build + + +# Python ###################################################################### +# +# sometimes, the Lassen PIP Index is down +export PIP_EXTRA_INDEX_URL="https://pypi.org/simple" + +python3 -m pip install --upgrade pip +python3 -m pip install --upgrade virtualenv +# python3 -m pip cache purge || true # Cache disabled on system +rm -rf ${SW_DIR}/venvs/warpx-trioga-mi300a +python3 -m venv ${SW_DIR}/venvs/warpx-trioga-mi300a +source ${SW_DIR}/venvs/warpx-trioga-mi300a/bin/activate +python3 -m pip install --upgrade pip +python3 -m pip install --upgrade build +python3 -m pip install --upgrade packaging +python3 -m pip install --upgrade wheel +python3 -m pip install --upgrade setuptools +python3 -m pip install --upgrade cython +python3 -m pip install --upgrade numpy +python3 -m pip install --upgrade pandas +python3 -m pip install --upgrade scipy +python3 -m pip install --upgrade mpi4py --no-cache-dir --no-build-isolation --no-binary mpi4py +python3 -m pip install --upgrade openpmd-api +python3 -m pip install --upgrade openpmd-viewer +python3 -m pip install --upgrade matplotlib +python3 -m pip install --upgrade yt +# install or update WarpX dependencies such as picmistandard +python3 -m pip install --upgrade -r ${SRC_DIR}/warpx/requirements.txt +# cupy for ROCm +# https://docs.cupy.dev/en/stable/install.html#building-cupy-for-rocm-from-source +# https://docs.cupy.dev/en/stable/install.html#using-cupy-on-amd-gpu-experimental +# https://github.com/cupy/cupy/issues/7830 +# https://github.com/cupy/cupy/pull/8457 +# https://github.com/cupy/cupy/pull/8319 +#python3 -m pip install --upgrade "cython<3" +#HIPCC=${CXX} \ +#CXXFLAGS="-I${ROCM_PATH}/include/hipblas -I${ROCM_PATH}/include/hipsparse -I${ROCM_PATH}/include/hipfft -I${ROCM_PATH}/include/rocsolver -I${ROCM_PATH}/include/rccl" \ +#CUPY_INSTALL_USE_HIP=1 \ +#ROCM_HOME=${ROCM_PATH} \ +#HCC_AMDGPU_TARGET=${AMREX_AMD_ARCH} \ +# python3 -m pip install -v cupy +#python3 -m pip install --upgrade "cython>=3" + + +# for ML dependencies, see install_mi300a_ml.sh + +# remove build temporary directory +rm -rf ${build_dir} diff --git a/Tools/machines/tioga-llnl/install_mi300a_ml.sh b/Tools/machines/tioga-llnl/install_mi300a_ml.sh new file mode 100644 index 00000000000..178deed9975 --- /dev/null +++ b/Tools/machines/tioga-llnl/install_mi300a_ml.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Copyright 2024 The WarpX Community +# +# This file is part of WarpX. +# +# Author: Axel Huebl +# License: BSD-3-Clause-LBNL + +# Exit on first error encountered ############################################# +# +set -eu -o pipefail + + +# Check: ###################################################################### +# +# Was tioga_mi300a_warpx.profile sourced and configured correctly? +# early access: not yet used! +#if [ -z ${proj-} ]; then echo "WARNING: The 'proj' variable is not yet set in your tioga_mi300a_warpx.profile file! Please edit its line 2 to continue!"; exit 1; fi + + +# Remove old dependencies ##################################################### +# +SRC_DIR="/p/lustre1/${USER}/tioga/src" +SW_DIR="/p/lustre1/${USER}/tioga/warpx/mi300a" + +# remove common user mistakes in python, located in .local instead of a venv +python3 -m pip uninstall -qqq -y torch 2>/dev/null || true + + +# Python ML ################################################################### +# +# for basic python dependencies, see install_mi300a_dependencies.sh + +# sometimes, the Lassen PIP Index is down +export PIP_EXTRA_INDEX_URL="https://pypi.org/simple" + +source ${SW_DIR}/venvs/warpx-trioga-mi300a/bin/activate + +python3 -m pip install --upgrade torch torchvision --index-url https://download.pytorch.org/whl/rocm6.1 +python3 -m pip install --upgrade scikit-learn +python3 -m pip install --upgrade "optimas[all]" diff --git a/Tools/machines/tioga-llnl/tioga_mi300a.sbatch b/Tools/machines/tioga-llnl/tioga_mi300a.sbatch new file mode 100644 index 00000000000..0e29e24adcb --- /dev/null +++ b/Tools/machines/tioga-llnl/tioga_mi300a.sbatch @@ -0,0 +1,44 @@ +#!/bin/bash -l + +# Copyright 2024 The WarpX Community +# +# This file is part of WarpX. +# +# Authors: Axel Huebl, Joshua David Ludwig +# License: BSD-3-Clause-LBNL + +#SBATCH -t 00:30:00 +#SBATCH -N 1 +#SBATCH -J WarpX +#S BATCH -A # project name not needed yet +#SBATCH -p mi300a +#SBATCH --gpu-bind=none +#SBATCH --ntasks-per-node=4 +#SBATCH --gpus-per-node=4 +#SBATCH -o WarpX.o%j +#SBATCH -e WarpX.e%j + +# executable & inputs file or python interpreter & PICMI script here +EXE=./warpx +INPUTS=inputs + +# pin to closest NIC to GPU +export MPICH_OFI_NIC_POLICY=GPU + +# threads for OpenMP and threaded compressors per MPI rank +# note: 16 avoids hyperthreading (32 virtual cores, 16 physical) +export SRUN_CPUS_PER_TASK=16 +export OMP_NUM_THREADS=${SRUN_CPUS_PER_TASK} + +# GPU-aware MPI optimizations +GPU_AWARE_MPI="amrex.use_gpu_aware_mpi=1" + +# APUs share memory with the host: +# Do NOT pre-allocate a large heap in AMReX +APU_SHARED_MEMORY="amrex.the_arena_init_size=1" + +# MPI parallel processes +srun \ + ${EXE} ${INPUTS} \ + ${GPU_AWARE_MPI} ${APU_SHARED_MEMORY} \ + > output.txt diff --git a/Tools/machines/tioga-llnl/tioga_mi300a_warpx.profile.example b/Tools/machines/tioga-llnl/tioga_mi300a_warpx.profile.example new file mode 100644 index 00000000000..e3da37c5522 --- /dev/null +++ b/Tools/machines/tioga-llnl/tioga_mi300a_warpx.profile.example @@ -0,0 +1,69 @@ +# please set your project account +export proj="" # change me! + +# remembers the location of this script +export MY_PROFILE=$(cd $(dirname $BASH_SOURCE) && pwd)"/"$(basename $BASH_SOURCE) +# early access: not yet used +# if [ -z ${proj-} ]; then echo "WARNING: The 'proj' variable is not yet set in your $MY_PROFILE file! Please edit its line 2 to continue!"; return; fi + +# required dependencies +module purge +module load PrgEnv-cray-amd/8.5.0 +# module load rocmcc/6.1.2-cce-18.0.0-magic +module load craype-x86-genoa # CPU +module load craype-accel-amd-gfx942 # GPU +module load cmake/3.29.2 +module load cray-mpich +module load cray-libsci +module load rocm/6.1.2 + +# optional: faster builds +# ccache is system provided +module load ninja/1.10.2 + +# optional: for QED support with detailed tables +# TODO: no Boost module found + +# optional: for openPMD and PSATD+RZ support +SW_DIR="/p/lustre1/${USER}/tioga/warpx/mi300a" +module load cray-hdf5-parallel/1.12.2.11 +export CMAKE_PREFIX_PATH=${SW_DIR}/c-blosc-2.15.1:$CMAKE_PREFIX_PATH +export CMAKE_PREFIX_PATH=${SW_DIR}/adios2-2.10.1:$CMAKE_PREFIX_PATH +export CMAKE_PREFIX_PATH=${SW_DIR}/blaspp-2024.05.31:$CMAKE_PREFIX_PATH +export CMAKE_PREFIX_PATH=${SW_DIR}/lapackpp-2024.05.31:$CMAKE_PREFIX_PATH +export CMAKE_PREFIX_PATH=${SW_DIR}/heffte-2.4.0:$CMAKE_PREFIX_PATH + +export LD_LIBRARY_PATH=${SW_DIR}/c-blosc-2.15.1/lib64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${SW_DIR}/adios2-2.10.1/lib64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${SW_DIR}/blaspp-2024.05.31/lib64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${SW_DIR}/lapackpp-2024.05.31/lib64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${SW_DIR}/heffte-2.4.0/lib64:$LD_LIBRARY_PATH + +export PATH=${SW_DIR}/adios2-2.10.1/bin:${PATH} + +# python +module load cray-python/3.11.7 + +if [ -d "${SW_DIR}/venvs/warpx-trioga-mi300a" ] +then + source ${SW_DIR}/venvs/warpx-trioga-mi300a/bin/activate +fi + +# an alias to request an interactive batch node for one hour +# for parallel execution, start on the batch node: srun +alias getNode="salloc -N 1 -p mi300a -t 1:00:00" +# an alias to run a command on a batch node for up to 30min +# usage: runNode +alias runNode="srun -N 1 --ntasks-per-node=4 -t 0:30:00 -p mi300a" + +# GPU-aware MPI +export MPICH_GPU_SUPPORT_ENABLED=1 + +# optimize ROCm/HIP compilation for MI300A +export AMREX_AMD_ARCH=gfx942 + +# compiler environment hints +export CC=$(which cc) +export CXX=$(which CC) +export FC=$(which ftn) +export HIPCXX=${CXX} diff --git a/WarpXConfig.cmake b/WarpXConfig.cmake index 8536d08f67a..df00423e823 100644 --- a/WarpXConfig.cmake +++ b/WarpXConfig.cmake @@ -37,6 +37,7 @@ set(WarpX_OPENPMD_FOUND ${WarpX_OPENPMD}) # TODO #WarpX_ASCENT "Ascent in situ diagnostics" OFF) +#WarpX_CATALYST "Catalyst in situ diagnostics" OFF) #WarpX_FFT "FFT-based solvers" OFF) #WarpX_SENSEI "SENSEI in situ diagnostics" OFF) #WarpX_QED "QED support (requires PICSAR)" ON) diff --git a/cmake/WarpXFunctions.cmake b/cmake/WarpXFunctions.cmake index e05b4c3afc4..43efd89efc5 100644 --- a/cmake/WarpXFunctions.cmake +++ b/cmake/WarpXFunctions.cmake @@ -301,12 +301,20 @@ function(set_warpx_binary_name D) set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".ASCENT") endif() + if(WarpX_CATALYST) + set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".CATALYST") + endif() + if(WarpX_OPENPMD) set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".OPMD") endif() if(WarpX_FFT) - set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".PSATD") + set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".FFT") + endif() + + if(WarpX_HEFFTE) + set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".HEFFTE") endif() if(WarpX_EB) @@ -441,6 +449,7 @@ function(warpx_print_summary) message(" Build options:") message(" APP: ${WarpX_APP}") message(" ASCENT: ${WarpX_ASCENT}") + message(" CATALYST: ${WarpX_CATALYST}") message(" COMPUTE: ${WarpX_COMPUTE}") message(" DIMS: ${WarpX_DIMS}") message(" Embedded Boundary: ${WarpX_EB}") diff --git a/cmake/dependencies/AMReX.cmake b/cmake/dependencies/AMReX.cmake index 025b4d3b6e0..e3682b69ff5 100644 --- a/cmake/dependencies/AMReX.cmake +++ b/cmake/dependencies/AMReX.cmake @@ -26,6 +26,11 @@ macro(find_amrex) set(AMReX_CONDUIT ON CACHE INTERNAL "") endif() + if(WarpX_CATALYST) + set(AMReX_CATALYST ON CACHE INTERNAL "") + set(AMReX_CONDUIT ON CACHE INTERNAL "") + endif() + if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") set(AMReX_ASSERTIONS ON CACHE BOOL "") # note: floating-point exceptions can slow down debug runs a lot @@ -140,22 +145,17 @@ macro(find_amrex) endif() add_subdirectory(${WarpX_amrex_src} _deps/localamrex-build/) else() + if(WarpX_COMPUTE STREQUAL CUDA) + enable_language(CUDA) + # AMReX 21.06+ supports CUDA_ARCHITECTURES + endif() FetchContent_Declare(fetchedamrex GIT_REPOSITORY ${WarpX_amrex_repo} GIT_TAG ${WarpX_amrex_branch} BUILD_IN_SOURCE 0 ) - FetchContent_GetProperties(fetchedamrex) - - if(NOT fetchedamrex_POPULATED) - FetchContent_Populate(fetchedamrex) - list(APPEND CMAKE_MODULE_PATH "${fetchedamrex_SOURCE_DIR}/Tools/CMake") - if(WarpX_COMPUTE STREQUAL CUDA) - enable_language(CUDA) - # AMReX 21.06+ supports CUDA_ARCHITECTURES - endif() - add_subdirectory(${fetchedamrex_SOURCE_DIR} ${fetchedamrex_BINARY_DIR}) - endif() + FetchContent_MakeAvailable(fetchedamrex) + list(APPEND CMAKE_MODULE_PATH "${fetchedamrex_SOURCE_DIR}/Tools/CMake") # advanced fetch options mark_as_advanced(FETCHCONTENT_BASE_DIR) @@ -226,6 +226,12 @@ macro(find_amrex) set(COMPONENT_ASCENT) endif() + if(WarpX_CATALYST) + set(COMPONENT_CATALYST CATALYST CONDUIT) + else() + set(COMPONENT_CATALYST) + endif() + set(WarpX_amrex_dim ${WarpX_DIMS}) # RZ is AMReX 2D list(TRANSFORM WarpX_amrex_dim REPLACE RZ 2) list(REMOVE_DUPLICATES WarpX_amrex_dim) @@ -250,7 +256,7 @@ macro(find_amrex) endif() set(COMPONENT_PRECISION ${WarpX_PRECISION} P${WarpX_PARTICLE_PRECISION}) - find_package(AMReX 24.07 CONFIG REQUIRED COMPONENTS ${COMPONENT_ASCENT} ${COMPONENT_DIMS} ${COMPONENT_EB} PARTICLES ${COMPONENT_PIC} ${COMPONENT_PRECISION} ${COMPONENT_SENSEI} LSOLVERS) + find_package(AMReX 24.09 CONFIG REQUIRED COMPONENTS ${COMPONENT_ASCENT} ${COMPONENT_CATALYST} ${COMPONENT_DIMS} ${COMPONENT_EB} PARTICLES ${COMPONENT_PIC} ${COMPONENT_PRECISION} ${COMPONENT_SENSEI} LSOLVERS) # note: TINYP skipped because user-configured and optional # AMReX CMake helper scripts @@ -273,7 +279,7 @@ set(WarpX_amrex_src "" set(WarpX_amrex_repo "https://github.com/AMReX-Codes/amrex.git" CACHE STRING "Repository URI to pull and build AMReX from if(WarpX_amrex_internal)") -set(WarpX_amrex_branch "0c3273f5e591815909180f8ffaf5b793cabbf9bc" +set(WarpX_amrex_branch "028638564f7be0694b9898f8d4088cdbf9a6f9f5" CACHE STRING "Repository branch for WarpX_amrex_repo if(WarpX_amrex_internal)") diff --git a/cmake/dependencies/PICSAR.cmake b/cmake/dependencies/PICSAR.cmake index 9086421356f..9eb9162238a 100644 --- a/cmake/dependencies/PICSAR.cmake +++ b/cmake/dependencies/PICSAR.cmake @@ -53,19 +53,13 @@ function(find_picsar) get_source_version(PXRMP_QED ${WarpX_picsar_src}) else() FetchContent_Declare(fetchedpicsar - GIT_REPOSITORY ${WarpX_picsar_repo} - GIT_TAG ${WarpX_picsar_branch} + GIT_REPOSITORY ${WarpX_picsar_repo} + GIT_TAG ${WarpX_picsar_branch} BUILD_IN_SOURCE 0 + SOURCE_SUBDIR multi_physics/QED ) - FetchContent_GetProperties(fetchedpicsar) + FetchContent_MakeAvailable(fetchedpicsar) - if(NOT fetchedpicsar_POPULATED) - FetchContent_Populate(fetchedpicsar) - add_subdirectory( - ${fetchedpicsar_SOURCE_DIR}/multi_physics/QED - ${fetchedpicsar_BINARY_DIR} - ) - endif() get_source_version(PXRMP_QED ${fetchedpicsar_SOURCE_DIR}) if(NOT PXRMP_QED_GIT_VERSION) set(PXRMP_QED_GIT_VERSION "${WarpX_picsar_branch}" CACHE INTERNAL "") @@ -94,7 +88,7 @@ function(find_picsar) #message(STATUS "PICSAR: Using version '${PICSAR_VERSION}'") else() # not supported by PICSAR (yet) - #find_package(PICSAR 23.11 CONFIG REQUIRED QED) + #find_package(PICSAR 24.09 CONFIG REQUIRED QED) #message(STATUS "PICSAR: Found version '${PICSAR_VERSION}'") message(FATAL_ERROR "PICSAR: Cannot be used as externally installed " "library yet. " @@ -115,7 +109,7 @@ if(WarpX_QED) set(WarpX_picsar_repo "https://github.com/ECP-WarpX/picsar.git" CACHE STRING "Repository URI to pull and build PICSAR from if(WarpX_picsar_internal)") - set(WarpX_picsar_branch "aa54e985398c1d575abc7e6737cdbc660a13765f" + set(WarpX_picsar_branch "24.09" CACHE STRING "Repository branch for WarpX_picsar_repo if(WarpX_picsar_internal)") diff --git a/cmake/dependencies/openPMD.cmake b/cmake/dependencies/openPMD.cmake index f58d37ee92e..ce6ec4d0967 100644 --- a/cmake/dependencies/openPMD.cmake +++ b/cmake/dependencies/openPMD.cmake @@ -32,12 +32,7 @@ function(find_openpmd) GIT_TAG ${WarpX_openpmd_branch} BUILD_IN_SOURCE 0 ) - FetchContent_GetProperties(fetchedopenpmd) - - if(NOT fetchedopenpmd_POPULATED) - FetchContent_Populate(fetchedopenpmd) - add_subdirectory(${fetchedopenpmd_SOURCE_DIR} ${fetchedopenpmd_BINARY_DIR}) - endif() + FetchContent_MakeAvailable(fetchedopenpmd) # advanced fetch options mark_as_advanced(FETCHCONTENT_BASE_DIR) diff --git a/cmake/dependencies/pyAMReX.cmake b/cmake/dependencies/pyAMReX.cmake index a4598953432..e93851443c0 100644 --- a/cmake/dependencies/pyAMReX.cmake +++ b/cmake/dependencies/pyAMReX.cmake @@ -47,12 +47,7 @@ function(find_pyamrex) GIT_TAG ${WarpX_pyamrex_branch} BUILD_IN_SOURCE 0 ) - FetchContent_GetProperties(fetchedpyamrex) - - if(NOT fetchedpyamrex_POPULATED) - FetchContent_Populate(fetchedpyamrex) - add_subdirectory(${fetchedpyamrex_SOURCE_DIR} ${fetchedpyamrex_BINARY_DIR}) - endif() + FetchContent_MakeAvailable(fetchedpyamrex) # advanced fetch options mark_as_advanced(FETCHCONTENT_BASE_DIR) @@ -64,7 +59,7 @@ function(find_pyamrex) endif() elseif(NOT WarpX_pyamrex_internal) # TODO: MPI control - find_package(pyAMReX 24.07 CONFIG REQUIRED) + find_package(pyAMReX 24.09 CONFIG REQUIRED) message(STATUS "pyAMReX: Found version '${pyAMReX_VERSION}'") endif() endfunction() @@ -79,7 +74,7 @@ option(WarpX_pyamrex_internal "Download & build pyAMReX" ON) set(WarpX_pyamrex_repo "https://github.com/AMReX-Codes/pyamrex.git" CACHE STRING "Repository URI to pull and build pyamrex from if(WarpX_pyamrex_internal)") -set(WarpX_pyamrex_branch "ff4643869c63d4ee40a87054b901f61eefcb97a3" +set(WarpX_pyamrex_branch "41c856b8a588c3c8b04bb35d2d05b56f6ce0dd7f" CACHE STRING "Repository branch for WarpX_pyamrex_repo if(WarpX_pyamrex_internal)") diff --git a/cmake/dependencies/pybind11.cmake b/cmake/dependencies/pybind11.cmake index 0a7ec260493..94d38e69112 100644 --- a/cmake/dependencies/pybind11.cmake +++ b/cmake/dependencies/pybind11.cmake @@ -21,12 +21,7 @@ function(find_pybind11) GIT_TAG ${WarpX_pybind11_branch} BUILD_IN_SOURCE 0 ) - FetchContent_GetProperties(fetchedpybind11) - - if(NOT fetchedpybind11_POPULATED) - FetchContent_Populate(fetchedpybind11) - add_subdirectory(${fetchedpybind11_SOURCE_DIR} ${fetchedpybind11_BINARY_DIR}) - endif() + FetchContent_MakeAvailable(fetchedpybind11) # advanced fetch options mark_as_advanced(FETCHCONTENT_BASE_DIR) diff --git a/pyproject.toml b/pyproject.toml index f9e615f9b83..6210388f6e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,11 +2,21 @@ requires = [ "setuptools>=42", "wheel", - "cmake>=3.20.0,<4.0.0", + "cmake>=3.24.0,<4.0.0", "packaging>=23", ] build-backend = "setuptools.build_meta" +[tool.ruff.format] +docstring-code-format = true + +[tool.ruff.lint] +select = ["E", "F", "I"] +ignore = ["E402", "E501", "F405"] + +[tool.ruff.lint.isort] +known-first-party = ["amrex", "picmistandard", "pywarpx", "warpx"] + [tool.isort] known_first_party = ["amrex", "picmistandard", "pywarpx", "warpx"] profile = "black" diff --git a/requirements.txt b/requirements.txt index 8e664ae3096..272c4903e94 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ periodictable~=1.5 # PICMI # note: don't forget to update the version in Docs/requirements.txt, too -picmistandard==0.29.0 +picmistandard==0.30.0 # for development against an unreleased PICMI version, use: #picmistandard @ git+https://github.com/picmi-standard/picmi.git#subdirectory=PICMI_Python diff --git a/run_test.sh b/run_test.sh deleted file mode 100755 index 1692f66263c..00000000000 --- a/run_test.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash - -# Copyright 2018-2020 Axel Huebl, David Grote, Edoardo Zoni -# Luca Fedeli, Maxence Thevenet, Remi Lehe -# -# -# This file is part of WarpX. -# -# License: BSD-3-Clause-LBNL - -# This script runs some of WarpX's standard regression tests, but -# without comparing the output to previously run simulations. -# This checks that: -# - The code compiles and runs without error -# - For some of the tests, a Python script checks that the results are -# physically correct. - -# The tests can be influenced by environment variables: -# Use `export WARPX_CI_DIM=3` or `export WARPX_CI_DIM=2` in order to -# select only the tests that correspond to this dimension -# Use `export WARPX_TEST_ARCH=CPU` or `export WARPX_TEST_ARCH=GPU` in order -# to run the tests on CPU or GPU respectively. - -set -eu -o pipefail - -# Parse command line arguments: if test names are given as command line arguments, -# store them in variable tests_arg and define new command line argument to call -# regtest.py with option --tests (works also for single test) -tests_arg=$* -tests_run=${tests_arg:+--tests=${tests_arg}} - -# environment options -WARPX_CI_TMP=${WARPX_CI_TMP:-""} - -# Remove contents and link to a previous test directory (intentionally two arguments) -rm -rf test_dir/* test_dir -# Create a temporary test directory -if [ -z "${WARPX_CI_TMP}" ]; then - tmp_dir=$(mktemp --help >/dev/null 2>&1 && mktemp -d -t ci-XXXXXXXXXX || mktemp -d "${TMPDIR:-/tmp}"/ci-XXXXXXXXXX) - if [ $? -ne 0 ]; then - echo "Cannot create temporary directory" - exit 1 - fi -else - tmp_dir=${WARPX_CI_TMP} -fi - -# Copy WarpX into current test directory -rm -rf ${tmp_dir}/warpx -mkdir -p ${tmp_dir}/warpx -cp -r ./* ${tmp_dir}/warpx - -# Link the test directory -ln -s ${tmp_dir} test_dir - -# Switch to the test directory -cd test_dir -echo "cd $PWD" - -# Prepare a virtual environment -rm -rf py-venv -python3 -m venv py-venv -source py-venv/bin/activate -python3 -m pip install --upgrade pip -python3 -m pip install --upgrade build packaging setuptools wheel -python3 -m pip install --upgrade cmake -python3 -m pip install --upgrade -r warpx/Regression/requirements.txt - -# Clone AMReX and warpx-data -git clone https://github.com/AMReX-Codes/amrex.git -cd amrex && git checkout --detach 0c3273f5e591815909180f8ffaf5b793cabbf9bc && cd - -# warpx-data contains various required data sets -git clone --depth 1 https://github.com/ECP-WarpX/warpx-data.git -# openPMD-example-datasets contains various required data sets -mkdir -p openPMD-example-datasets -cd openPMD-example-datasets -curl -sOL https://github.com/openPMD/openPMD-example-datasets/raw/4ba1d257c5b4897c0a3cd57742bb0987343a902e/example-femm-thetaMode.h5 -curl -sOL https://github.com/openPMD/openPMD-example-datasets/raw/4ba1d257c5b4897c0a3cd57742bb0987343a902e/example-femm-3d.h5 -cd - - -# Clone the AMReX regression test utility -git clone https://github.com/AMReX-Codes/regression_testing.git - -# Prepare regression tests -mkdir -p rt-WarpX/WarpX-benchmarks -cd warpx/Regression -echo "cd $PWD" -python3 prepare_file_ci.py -cp ci-tests.ini ../../rt-WarpX -cp -r Checksum ../../regression_testing/ - -# Run tests -cd ../../regression_testing/ -echo "cd $PWD" -# run only tests specified in variable tests_arg (single test or multiple tests) -if [[ ! -z "${tests_arg}" ]]; then - python3 regtest.py ../rt-WarpX/ci-tests.ini --skip_comparison --no_update all "${tests_run}" -# run all tests (variables tests_arg and tests_run are empty) -else - python3 regtest.py ../rt-WarpX/ci-tests.ini --skip_comparison --no_update all -fi - -# clean up python virtual environment -cd ../ -echo "cd $PWD" -deactivate diff --git a/setup.py b/setup.py index f05d5a71899..efc18d900cf 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ def initialize_options(self): # clashes with directories many developers have in their source trees; # this can create confusing results with "pip install .", which clones # the whole source tree by default - self.build_base = '_tmppythonbuild' + self.build_base = os.path.join("_tmppythonbuild", "warpx") def run(self): # remove existing build directory @@ -38,8 +38,10 @@ def run(self): lib_path = os.path.join(PYWARPX_LIB_DIR, lib_name) libs_found.append(lib_path) if len(libs_found) == 0: - raise RuntimeError("Error: no pre-build WarpX modules found in " - "PYWARPX_LIB_DIR='{}'".format(PYWARPX_LIB_DIR)) + raise RuntimeError( + "Error: no pre-build WarpX modules found in " + "PYWARPX_LIB_DIR='{}'".format(PYWARPX_LIB_DIR) + ) # copy external libs into collection of files in a temporary build dir dst_path = os.path.join(self.build_lib, "pywarpx") @@ -48,7 +50,7 @@ def run(self): class CMakeExtension(Extension): - def __init__(self, name, sourcedir=''): + def __init__(self, name, sourcedir=""): Extension.__init__(self, name, sources=[]) self.sourcedir = os.path.abspath(sourcedir) @@ -58,140 +60,131 @@ def run(self): from packaging.version import parse try: - out = subprocess.check_output(['cmake', '--version']) + out = subprocess.check_output(["cmake", "--version"]) except OSError: raise RuntimeError( - "CMake 3.20.0+ must be installed to build the following " + - "extensions: " + - ", ".join(e.name for e in self.extensions)) + "CMake 3.24.0+ must be installed to build the following " + + "extensions: " + + ", ".join(e.name for e in self.extensions) + ) cmake_version = parse(re.search(r"version\s*([\d.]+)", out.decode()).group(1)) - if cmake_version < parse("3.20.0"): - raise RuntimeError("CMake >= 3.20.0 is required") + if cmake_version < parse("3.24.0"): + raise RuntimeError("CMake >= 3.24.0 is required") for ext in self.extensions: self.build_extension(ext) def build_extension(self, ext): - extdir = os.path.abspath(os.path.dirname( - self.get_ext_fullpath(ext.name) - )) + extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) # required for auto-detection of auxiliary "native" libs if not extdir.endswith(os.path.sep): extdir += os.path.sep - r_dim = re.search(r'warpx_(1|2|rz|3)(?:d*)', ext.name) + r_dim = re.search(r"warpx_(1|2|rz|3)(?:d*)", ext.name) dims = r_dim.group(1).upper() cmake_args = [ - '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + - os.path.join(extdir, "pywarpx"), - '-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=' + extdir, - '-DWarpX_DIMS=' + dims, - '-DWarpX_APP:BOOL=OFF', + "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + os.path.join(extdir, "pywarpx"), + "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=" + extdir, + "-DWarpX_DIMS=" + dims, + "-DWarpX_APP:BOOL=OFF", ## variants - '-DWarpX_COMPUTE=' + WARPX_COMPUTE, - '-DWarpX_MPI:BOOL=' + WARPX_MPI, - '-DWarpX_EB:BOOL=' + WARPX_EB, - '-DWarpX_OPENPMD:BOOL=' + WARPX_OPENPMD, - '-DWarpX_PRECISION=' + WARPX_PRECISION, - '-DWarpX_PARTICLE_PRECISION=' + WARPX_PARTICLE_PRECISION, - '-DWarpX_FFT:BOOL=' + WARPX_FFT, - '-DWarpX_HEFFTE:BOOL=' + WARPX_HEFFTE, - '-DWarpX_PYTHON:BOOL=ON', - '-DWarpX_PYTHON_IPO:BOOL=' + WARPX_PYTHON_IPO, - '-DWarpX_QED:BOOL=' + WARPX_QED, - '-DWarpX_QED_TABLE_GEN:BOOL=' + WARPX_QED_TABLE_GEN, + "-DWarpX_COMPUTE=" + WARPX_COMPUTE, + "-DWarpX_MPI:BOOL=" + WARPX_MPI, + "-DWarpX_EB:BOOL=" + WARPX_EB, + "-DWarpX_OPENPMD:BOOL=" + WARPX_OPENPMD, + "-DWarpX_PRECISION=" + WARPX_PRECISION, + "-DWarpX_PARTICLE_PRECISION=" + WARPX_PARTICLE_PRECISION, + "-DWarpX_FFT:BOOL=" + WARPX_FFT, + "-DWarpX_HEFFTE:BOOL=" + WARPX_HEFFTE, + "-DWarpX_PYTHON:BOOL=ON", + "-DWarpX_PYTHON_IPO:BOOL=" + WARPX_PYTHON_IPO, + "-DWarpX_QED:BOOL=" + WARPX_QED, + "-DWarpX_QED_TABLE_GEN:BOOL=" + WARPX_QED_TABLE_GEN, ## dependency control (developers & package managers) - '-DWarpX_amrex_internal=' + WARPX_AMREX_INTERNAL, + "-DWarpX_amrex_internal=" + WARPX_AMREX_INTERNAL, # PEP-440 conformant version from package "-DpyWarpX_VERSION_INFO=" + self.distribution.get_version(), # see PICSAR and openPMD below ## static/shared libs - '-DBUILD_SHARED_LIBS:BOOL=' + BUILD_SHARED_LIBS, + "-DBUILD_SHARED_LIBS:BOOL=" + BUILD_SHARED_LIBS, ## Unix: rpath to current dir when packaged ## needed for shared (here non-default) builds and ADIOS1 ## wrapper libraries - '-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON', - '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=OFF', + "-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON", + "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=OFF", # Windows: has no RPath concept, all `.dll`s must be in %PATH% # or same dir as calling executable ] - if WARPX_QED.upper() in ['1', 'ON', 'TRUE', 'YES']: - cmake_args.append('-DWarpX_picsar_internal=' + WARPX_PICSAR_INTERNAL) - if WARPX_OPENPMD.upper() in ['1', 'ON', 'TRUE', 'YES']: + if WARPX_QED.upper() in ["1", "ON", "TRUE", "YES"]: + cmake_args.append("-DWarpX_picsar_internal=" + WARPX_PICSAR_INTERNAL) + if WARPX_OPENPMD.upper() in ["1", "ON", "TRUE", "YES"]: cmake_args += [ - '-DHDF5_USE_STATIC_LIBRARIES:BOOL=' + HDF5_USE_STATIC_LIBRARIES, - '-DADIOS_USE_STATIC_LIBS:BOOL=' + ADIOS_USE_STATIC_LIBS, - '-DWarpX_openpmd_internal=' + WARPX_OPENPMD_INTERNAL, + "-DHDF5_USE_STATIC_LIBRARIES:BOOL=" + HDF5_USE_STATIC_LIBRARIES, + "-DADIOS_USE_STATIC_LIBS:BOOL=" + ADIOS_USE_STATIC_LIBS, + "-DWarpX_openpmd_internal=" + WARPX_OPENPMD_INTERNAL, ] # further dependency control (developers & package managers) if WARPX_AMREX_SRC: - cmake_args.append('-DWarpX_amrex_src=' + WARPX_AMREX_SRC) + cmake_args.append("-DWarpX_amrex_src=" + WARPX_AMREX_SRC) if WARPX_AMREX_REPO: - cmake_args.append('-DWarpX_amrex_repo=' + WARPX_AMREX_REPO) + cmake_args.append("-DWarpX_amrex_repo=" + WARPX_AMREX_REPO) if WARPX_AMREX_BRANCH: - cmake_args.append('-DWarpX_amrex_branch=' + WARPX_AMREX_BRANCH) + cmake_args.append("-DWarpX_amrex_branch=" + WARPX_AMREX_BRANCH) if WARPX_OPENPMD_SRC: - cmake_args.append('-DWarpX_openpmd_src=' + WARPX_OPENPMD_SRC) + cmake_args.append("-DWarpX_openpmd_src=" + WARPX_OPENPMD_SRC) if WARPX_PICSAR_SRC: - cmake_args.append('-DWarpX_picsar_src=' + WARPX_PICSAR_SRC) + cmake_args.append("-DWarpX_picsar_src=" + WARPX_PICSAR_SRC) if WARPX_PYAMREX_SRC: - cmake_args.append('-DWarpX_pyamrex_src=' + WARPX_PYAMREX_SRC) + cmake_args.append("-DWarpX_pyamrex_src=" + WARPX_PYAMREX_SRC) if WARPX_PYAMREX_INTERNAL: - cmake_args.append('-DWarpX_pyamrex_internal=' + WARPX_PYAMREX_INTERNAL) + cmake_args.append("-DWarpX_pyamrex_internal=" + WARPX_PYAMREX_INTERNAL) if WARPX_PYBIND11_SRC: - cmake_args.append('-DWarpX_pybind11_src=' + WARPX_PYBIND11_SRC) + cmake_args.append("-DWarpX_pybind11_src=" + WARPX_PYBIND11_SRC) if WARPX_PYBIND11_INTERNAL: - cmake_args.append('-DWarpX_pybind11_internal=' + WARPX_PYBIND11_INTERNAL) + cmake_args.append("-DWarpX_pybind11_internal=" + WARPX_PYBIND11_INTERNAL) if WARPX_CCACHE_PROGRAM is not None: - cmake_args.append('-DCCACHE_PROGRAM=' + WARPX_CCACHE_PROGRAM) + cmake_args.append("-DCCACHE_PROGRAM=" + WARPX_CCACHE_PROGRAM) if sys.platform == "darwin": - cmake_args.append('-DCMAKE_INSTALL_RPATH=@loader_path') + cmake_args.append("-DCMAKE_INSTALL_RPATH=@loader_path") else: # values: linux*, aix, freebsd, ... # just as well win32 & cygwin (although Windows has no RPaths) - cmake_args.append('-DCMAKE_INSTALL_RPATH=$ORIGIN') + cmake_args.append("-DCMAKE_INSTALL_RPATH=$ORIGIN") - cfg = 'Debug' if self.debug else 'Release' - build_args = ['--config', cfg] + cfg = "Debug" if self.debug else "Release" + build_args = ["--config", cfg] if platform.system() == "Windows": cmake_args += [ - '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( - cfg.upper(), - os.path.join(extdir, "pywarpx") + "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format( + cfg.upper(), os.path.join(extdir, "pywarpx") ) ] if sys.maxsize > 2**32: - cmake_args += ['-A', 'x64'] + cmake_args += ["-A", "x64"] else: - cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] + cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] - build_args += ['--parallel', BUILD_PARALLEL] + build_args += ["--parallel", BUILD_PARALLEL] build_dir = os.path.join(self.build_temp, dims) os.makedirs(build_dir, exist_ok=True) - subprocess.check_call( - ['cmake', ext.sourcedir] + cmake_args, - cwd=build_dir - ) - subprocess.check_call( - ['cmake', '--build', '.'] + build_args, - cwd=build_dir - ) + subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=build_dir) + subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_dir) # note that this does not call install; # we pick up artifacts directly from the build output dirs -with open('./README.md', encoding='utf-8') as f: +with open("./README.md", encoding="utf-8") as f: long_description = f.read() # Allow to control options via environment vars. # Work-around for https://github.com/pypa/setuptools/issues/1712 # Pick up existing WarpX libraries or... -PYWARPX_LIB_DIR = os.environ.get('PYWARPX_LIB_DIR') +PYWARPX_LIB_DIR = os.environ.get("PYWARPX_LIB_DIR") WARPX_PYTHON_IPO = os.environ.get("WARPX_PYTHON_IPO", "ON") @@ -200,143 +193,152 @@ def build_extension(self, ext): # note: changed default for SHARED, MPI, TESTING and EXAMPLES # note: we use all-uppercase variable names for environment control to be # consistent across platforms (especially Windows) -WARPX_COMPUTE = env.pop('WARPX_COMPUTE', 'OMP') -WARPX_MPI = env.pop('WARPX_MPI', 'OFF') -WARPX_EB = env.pop('WARPX_EB', 'OFF') -WARPX_OPENPMD = env.pop('WARPX_OPENPMD', 'ON') -WARPX_PRECISION = env.pop('WARPX_PRECISION', 'DOUBLE') -WARPX_PARTICLE_PRECISION = env.pop('WARPX_PARTICLE_PRECISION', WARPX_PRECISION) -WARPX_FFT = env.pop('WARPX_FFT', 'OFF') -WARPX_HEFFTE = env.pop('WARPX_HEFFTE', 'OFF') -WARPX_QED = env.pop('WARPX_QED', 'ON') -WARPX_QED_TABLE_GEN = env.pop('WARPX_QED_TABLE_GEN', 'OFF') -WARPX_DIMS = env.pop('WARPX_DIMS', '1;2;RZ;3') -BUILD_PARALLEL = env.pop('BUILD_PARALLEL', '2') -BUILD_SHARED_LIBS = env.pop('WARPX_BUILD_SHARED_LIBS', - 'OFF') -#BUILD_TESTING = env.pop('WARPX_BUILD_TESTING', +WARPX_COMPUTE = env.pop("WARPX_COMPUTE", "OMP") +WARPX_MPI = env.pop("WARPX_MPI", "OFF") +WARPX_EB = env.pop("WARPX_EB", "ON") +WARPX_OPENPMD = env.pop("WARPX_OPENPMD", "ON") +WARPX_PRECISION = env.pop("WARPX_PRECISION", "DOUBLE") +WARPX_PARTICLE_PRECISION = env.pop("WARPX_PARTICLE_PRECISION", WARPX_PRECISION) +WARPX_FFT = env.pop("WARPX_FFT", "OFF") +WARPX_HEFFTE = env.pop("WARPX_HEFFTE", "OFF") +WARPX_QED = env.pop("WARPX_QED", "ON") +WARPX_QED_TABLE_GEN = env.pop("WARPX_QED_TABLE_GEN", "OFF") +WARPX_DIMS = env.pop("WARPX_DIMS", "1;2;RZ;3") +BUILD_PARALLEL = env.pop("BUILD_PARALLEL", "2") +BUILD_SHARED_LIBS = env.pop("WARPX_BUILD_SHARED_LIBS", "OFF") +# BUILD_TESTING = env.pop('WARPX_BUILD_TESTING', # 'OFF') -#BUILD_EXAMPLES = env.pop('WARPX_BUILD_EXAMPLES', +# BUILD_EXAMPLES = env.pop('WARPX_BUILD_EXAMPLES', # 'OFF') # openPMD-api sub-control -HDF5_USE_STATIC_LIBRARIES = env.pop('HDF5_USE_STATIC_LIBRARIES', 'OFF') -ADIOS_USE_STATIC_LIBS = env.pop('ADIOS_USE_STATIC_LIBS', 'OFF') +HDF5_USE_STATIC_LIBRARIES = env.pop("HDF5_USE_STATIC_LIBRARIES", "OFF") +ADIOS_USE_STATIC_LIBS = env.pop("ADIOS_USE_STATIC_LIBS", "OFF") # CMake dependency control (developers & package managers) -WARPX_AMREX_SRC = env.pop('WARPX_AMREX_SRC', '') -WARPX_AMREX_REPO = env.pop('WARPX_AMREX_REPO', '') -WARPX_AMREX_BRANCH = env.pop('WARPX_AMREX_BRANCH', '') -WARPX_AMREX_INTERNAL = env.pop('WARPX_AMREX_INTERNAL', 'ON') -WARPX_OPENPMD_SRC = env.pop('WARPX_OPENPMD_SRC', '') -WARPX_OPENPMD_INTERNAL = env.pop('WARPX_OPENPMD_INTERNAL', 'ON') -WARPX_PICSAR_SRC = env.pop('WARPX_PICSAR_SRC', '') -WARPX_PICSAR_INTERNAL = env.pop('WARPX_PICSAR_INTERNAL', 'ON') -WARPX_PYAMREX_SRC = env.pop('WARPX_PYAMREX_SRC', '') -WARPX_PYAMREX_INTERNAL = env.pop('WARPX_PYAMREX_INTERNAL', 'ON') -WARPX_PYBIND11_SRC = env.pop('WARPX_PYBIND11_SRC', '') -WARPX_PYBIND11_INTERNAL = env.pop('WARPX_PYBIND11_INTERNAL', 'ON') -WARPX_CCACHE_PROGRAM = env.pop('WARPX_CCACHE_PROGRAM', None) +WARPX_AMREX_SRC = env.pop("WARPX_AMREX_SRC", "") +WARPX_AMREX_REPO = env.pop("WARPX_AMREX_REPO", "") +WARPX_AMREX_BRANCH = env.pop("WARPX_AMREX_BRANCH", "") +WARPX_AMREX_INTERNAL = env.pop("WARPX_AMREX_INTERNAL", "ON") +WARPX_OPENPMD_SRC = env.pop("WARPX_OPENPMD_SRC", "") +WARPX_OPENPMD_INTERNAL = env.pop("WARPX_OPENPMD_INTERNAL", "ON") +WARPX_PICSAR_SRC = env.pop("WARPX_PICSAR_SRC", "") +WARPX_PICSAR_INTERNAL = env.pop("WARPX_PICSAR_INTERNAL", "ON") +WARPX_PYAMREX_SRC = env.pop("WARPX_PYAMREX_SRC", "") +WARPX_PYAMREX_INTERNAL = env.pop("WARPX_PYAMREX_INTERNAL", "ON") +WARPX_PYBIND11_SRC = env.pop("WARPX_PYBIND11_SRC", "") +WARPX_PYBIND11_INTERNAL = env.pop("WARPX_PYBIND11_INTERNAL", "ON") +WARPX_CCACHE_PROGRAM = env.pop("WARPX_CCACHE_PROGRAM", None) for key in env.keys(): - if key.lower().startswith('warpx'): - print(f"\nWARNING: Found environment variable '{key}', which is not a recognized WarpX option\n") + if key.lower().startswith("warpx"): + print( + f"\nWARNING: Found environment variable '{key}', which is not a recognized WarpX option\n" + ) # https://cmake.org/cmake/help/v3.0/command/if.html -if WARPX_MPI.upper() in ['1', 'ON', 'TRUE', 'YES']: +if WARPX_MPI.upper() in ["1", "ON", "TRUE", "YES"]: WARPX_MPI = "ON" else: WARPX_MPI = "OFF" # Include embedded boundary functionality -if WARPX_EB.upper() in ['1', 'ON', 'TRUE', 'YES']: +if WARPX_EB.upper() in ["1", "ON", "TRUE", "YES"]: WARPX_EB = "ON" else: WARPX_EB = "OFF" # for CMake -cxx_modules = [] # values: warpx_1d, warpx_2d, warpx_rz, warpx_3d -cmdclass = {} # build extensions +cxx_modules = [] # values: warpx_1d, warpx_2d, warpx_rz, warpx_3d +cmdclass = {} # build extensions # externally pre-built: pick up pre-built WarpX libraries if PYWARPX_LIB_DIR: - cmdclass=dict(build=CopyPreBuild) + cmdclass = dict(build=CopyPreBuild) # CMake: build WarpX libraries ourselves else: cmdclass = dict(build_ext=CMakeBuild) - for dim in [x.lower() for x in WARPX_DIMS.split(';')]: + for dim in [x.lower() for x in WARPX_DIMS.split(";")]: name = dim if dim == "rz" else dim + "d" cxx_modules.append(CMakeExtension("warpx_" + name)) # Get the package requirements from the requirements.txt file install_requires = [] -with open('./requirements.txt') as f: - install_requires = [line.strip('\n') for line in f.readlines()] +with open("./requirements.txt") as f: + install_requires = [line.strip("\n") for line in f.readlines()] if WARPX_MPI == "ON": - install_requires.append('mpi4py>=2.1.0') + install_requires.append("mpi4py>=2.1.0") # keyword reference: # https://packaging.python.org/guides/distributing-packages-using-setuptools setup( - name='pywarpx', + name="pywarpx", # note PEP-440 syntax: x.y.zaN but x.y.z.devN - version = '24.07', - packages = ['pywarpx'], - package_dir = {'pywarpx': 'Python/pywarpx'}, - author='Jean-Luc Vay, David P. Grote, Maxence Thévenet, Rémi Lehe, Andrew Myers, Weiqun Zhang, Axel Huebl, et al.', - author_email='jlvay@lbl.gov, grote1@llnl.gov, maxence.thevenet@desy.de, rlehe@lbl.gov, atmyers@lbl.gov, WeiqunZhang@lbl.gov, axelhuebl@lbl.gov', - maintainer='Axel Huebl, David P. Grote, Rémi Lehe', # wheel/pypi packages - maintainer_email='axelhuebl@lbl.gov, grote1@llnl.gov, rlehe@lbl.gov', - description='WarpX is an advanced electromagnetic Particle-In-Cell code.', + version="24.08", + packages=["pywarpx"], + package_dir={"pywarpx": "Python/pywarpx"}, + author="Jean-Luc Vay, David P. Grote, Maxence Thévenet, Rémi Lehe, Andrew Myers, Weiqun Zhang, Axel Huebl, et al.", + author_email="jlvay@lbl.gov, grote1@llnl.gov, maxence.thevenet@desy.de, rlehe@lbl.gov, atmyers@lbl.gov, WeiqunZhang@lbl.gov, axelhuebl@lbl.gov", + maintainer="Axel Huebl, David P. Grote, Rémi Lehe", # wheel/pypi packages + maintainer_email="axelhuebl@lbl.gov, grote1@llnl.gov, rlehe@lbl.gov", + description="WarpX is an advanced electromagnetic Particle-In-Cell code.", long_description=long_description, - long_description_content_type='text/markdown', - keywords=('WarpX openscience mpi hpc research pic particle-in-cell ' - 'plasma laser-plasma accelerator modeling simulation'), - url='https://ecp-warpx.github.io', + long_description_content_type="text/markdown", + keywords=( + "WarpX openscience mpi hpc research pic particle-in-cell " + "plasma laser-plasma accelerator modeling simulation" + ), + url="https://ecp-warpx.github.io", project_urls={ - 'Documentation': 'https://warpx.readthedocs.io', - 'Doxygen': 'https://warpx.readthedocs.io/en/latest/_static/doxyhtml/index.html', + "Documentation": "https://warpx.readthedocs.io", + "Doxygen": "https://warpx.readthedocs.io/en/latest/_static/doxyhtml/index.html", #'Reference': 'https://doi.org/...', (Paper and/or Zenodo) - 'Source': 'https://github.com/ECP-WarpX/WarpX', - 'Tracker': 'https://github.com/ECP-WarpX/WarpX/issues', + "Source": "https://github.com/ECP-WarpX/WarpX", + "Tracker": "https://github.com/ECP-WarpX/WarpX/issues", }, # CMake: self-built as extension module ext_modules=cxx_modules, cmdclass=cmdclass, # scripts=['warpx_1d', 'warpx_2d', 'warpx_rz', 'warpx_3d'], zip_safe=False, - python_requires='>=3.8', + python_requires=">=3.8", # tests_require=['pytest'], install_requires=install_requires, # see: src/bindings/python/cli - #entry_points={ + # entry_points={ # 'console_scripts': [ # 'warpx_3d = warpx.3d.__main__:main' # ] - #}, + # }, extras_require={ - 'all': ['openPMD-api~=0.15.1', 'openPMD-viewer~=1.1', 'yt>=4.1.0', 'matplotlib'], + "all": [ + "openPMD-api~=0.15.1", + "openPMD-viewer~=1.1", + "yt>=4.1.0", + "matplotlib", + ], }, # cmdclass={'test': PyTest}, # platforms='any', classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Natural Language :: English', - 'Environment :: Console', - 'Intended Audience :: Science/Research', - 'Operating System :: OS Independent', - 'Topic :: Scientific/Engineering', - 'Topic :: Scientific/Engineering :: Physics', - 'Programming Language :: C++', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - ('License :: OSI Approved :: ' - 'BSD License'), # TODO: use real SPDX: BSD-3-Clause-LBNL + "Development Status :: 5 - Production/Stable", + "Natural Language :: English", + "Environment :: Console", + "Intended Audience :: Science/Research", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Physics", + "Programming Language :: C++", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + ( + "License :: OSI Approved :: " "BSD License" + ), # TODO: use real SPDX: BSD-3-Clause-LBNL ], # new PEP 639 format - license='BSD-3-Clause-LBNL', - license_files = ['LICENSE.txt', 'LEGAL.txt'], + license="BSD-3-Clause-LBNL", + license_files=["LICENSE.txt", "LEGAL.txt"], )