diff --git a/.github/problem-matchers/gcc.json b/.github/problem-matchers/gcc.json new file mode 100644 index 000000000..9ab06796a --- /dev/null +++ b/.github/problem-matchers/gcc.json @@ -0,0 +1,18 @@ +{ + "__comment": "Taken from vscode-cpptools's Extension/package.json gcc rule", + "problemMatcher": [ + { + "owner": "gcc-problem-matcher", + "pattern": [ + { + "regexp": "^(.*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + ] + } + ] +} diff --git a/.github/workflows/EOS.yml b/.github/workflows/EOS.yml deleted file mode 100644 index 0cdb3dc5b..000000000 --- a/.github/workflows/EOS.yml +++ /dev/null @@ -1,132 +0,0 @@ -name: CI_EOS -on: - workflow_dispatch: - push: - branches: [ development ] - pull_request: - branches: [ development ] - -jobs: - # Fuego EOS GNU7.5 - Fuego: - name: GNU@7.5 [Fuego] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/EosEval - run: | - make -j 2 COMP=gnu Eos_Model=Fuego Chemistry_Model=LiDryer - - name: Run - working-directory: ./Testing/Exec/EosEval - run: | - ./Pele2d.gnu.ex inputs.2d - - # Gamma Law EOS GNU7.5 - GammaLaw: - name: GNU@7.5 [GammaLaw] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/EosEval - run: | - make -j 2 COMP=gnu Eos_Model=GammaLaw Chemistry_Model=Null - - name: Run - working-directory: ./Testing/Exec/EosEval - run: | - ./Pele2d.gnu.ex inputs.2d - - # Fuego EOS CUDA support - Fuego_CUDA: - name: CUDA@11.0.1 [Fuego] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/EosEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make -j 2 COMP=gnu USE_CUDA=TRUE Eos_Model=Fuego Chemistry_Model=LiDryer - - # Gamma Law EOS CUDA support - GammaLaw_CUDA: - name: CUDA@11.0.1 [GammaLaw] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/EosEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make -j 2 COMP=gnu USE_CUDA=TRUE Eos_Model=GammaLaw Chemistry_Model=Null - - # Fuego EOS HIP support - #Fuego_HIP: - # name: HIPROCm@3.8 GFortran@9.3 [Fuego] - # runs-on: ubuntu-20.04 - # env: - # {CXXFLAGS: "-fno-operator-names"} - # steps: - # - uses: actions/checkout@v2 - # - name: System Dependencies - # run: .github/workflows/dependencies/dependencies_hip.sh - # - name: AMReX - # run: | - # mkdir build - # git clone https://github.com/AMReX-Codes/amrex.git build/amrex - # - name: Build - # env: - # AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - # PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - # working-directory: ./Testing/Exec/EosEval - # run: | - # source /etc/profile.d/rocm.sh - # hipcc --version - # make -j 2 COMP=gnu USE_HIP=TRUE Eos_Model=Fuego Chemistry_Model=LiDryer diff --git a/.github/workflows/Pythia.yml b/.github/workflows/Pythia.yml deleted file mode 100644 index d0730b7bc..000000000 --- a/.github/workflows/Pythia.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: CI_PYTHIA -on: - workflow_dispatch: - push: - branches: [ development ] - pull_request: - branches: [ development ] - -jobs: - Pythia: - strategy: - fail-fast: false - matrix: - python-version: [3.8] - poetry-version: [1.1.7] - os: [ubuntu-18.04] - runs-on: ${{ matrix.os }} - defaults: - run: - working-directory: ./Support/Fuego/Pythia - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Run image - uses: abatilo/actions-poetry@v2.0.0 - with: - poetry-version: ${{ matrix.poetry-version }} - - name: Install Dependencies using Poetry - run: poetry install - - name: Formatting with black - run: poetry run black --check . - - name: Sort imports with isort - run: poetry run isort --check-only --diff . - - name: Run tests - run: poetry run bash -c "cd ../Mechanism/Models/air && ./make-mechanism.sh" diff --git a/.github/workflows/Reaction.yml b/.github/workflows/Reaction.yml deleted file mode 100644 index 3983b136b..000000000 --- a/.github/workflows/Reaction.yml +++ /dev/null @@ -1,406 +0,0 @@ -name: CI_Reaction -on: - workflow_dispatch: - push: - branches: [ development ] - pull_request: - branches: [ development ] - -jobs: - # Cvode DRM GNU7.5 - cvodeDRM: - name: GNU@7.5 [cvode-DRM] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - make TPL COMP=gnu Eos_Model=Fuego Reactions_dir=cvode Chemistry_Model=drm19 - make -j 2 COMP=gnu Eos_Model=Fuego Reactions_dir=cvode Chemistry_Model=drm19 - - name: Run_Array4 - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_Array4 - - name: Run_1dArray - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_1dArray - - # Cvode LiDryer GNU7.5 - cvodeLiDryer: - name: GNU@7.5 [cvode-LiDryer] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - make TPL COMP=gnu Eos_Model=Fuego Reactions_dir=cvode Chemistry_Model=LiDryer - make -j 2 COMP=gnu Eos_Model=Fuego Reactions_dir=cvode Chemistry_Model=LiDryer - - name: Run_Array4 - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_Array4 fuel_name=H2 - - name: Run_1dArray - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_1dArray fuel_name=H2 - - # ARKode DRM GNU7.5 - arkodeDRM: - name: GNU@7.5 [arkode-DRM] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - make TPL COMP=gnu Eos_Model=Fuego Reactions_dir=arkode USE_ARKODE_PP=TRUE Chemistry_Model=drm19 - make -j 2 COMP=gnu Eos_Model=Fuego Reactions_dir=arkode USE_ARKODE_PP=TRUE Chemistry_Model=drm19 - - name: Run_Array4 - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_Array4 ode.dt=1.e-05 ode.ndt=100 - - name: Run_1dArray - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_1dArray ode.dt=1.e-05 ode.ndt=100 - - # ARKode LiDryer GNU7.5 - arkodeLiDryer: - name: GNU@7.5 [arkode-LiDryer] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - make TPL COMP=gnu Eos_Model=Fuego Reactions_dir=arkode USE_ARKODE_PP=TRUE Chemistry_Model=LiDryer - make -j 2 COMP=gnu Eos_Model=Fuego Reactions_dir=arkode USE_ARKODE_PP=TRUE Chemistry_Model=LiDryer - - name: Run_Array4 - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_Array4 ode.dt=1.e-05 ode.ndt=100 fuel_name=H2 - - name: Run_1dArray - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_1dArray ode.dt=1.e-05 ode.ndt=100 fuel_name=H2 - - # RK64 DRM GNU7.5 - rk64DRM: - name: GNU@7.5 [rk64-DRM] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - make TPL COMP=gnu Eos_dir=Fuego Reactions_dir=rk64 USE_SUNDIALS_PP=FALSE USE_RK64_PP=TRUE Chemistry_Model=drm19 - make -j 2 COMP=gnu Eos_dir=Fuego Reactions_dir=rk64 USE_SUNDIALS_PP=FALSE USE_RK64_PP=TRUE Chemistry_Model=drm19 - - name: Run_Array4 - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_Array4 ode.dt=1.e-05 ode.ndt=100 - - name: Run_1dArray - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_1dArray ode.dt=1.e-05 ode.ndt=100 - - # RK64 LiDryer GNU7.5 - rk64LiDryer: - name: GNU@7.5 [rk64-LiDryer] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - make TPL COMP=gnu Eos_dir=Fuego Reactions_dir=rk64 USE_SUNDIALS_PP=FALSE USE_RK64_PP=TRUE Chemistry_Model=LiDryer - make -j 2 COMP=gnu Eos_dir=Fuego Reactions_dir=rk64 USE_SUNDIALS_PP=FALSE USE_RK64_PP=TRUE Chemistry_Model=LiDryer - - name: Run_Array4 - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_Array4 ode.dt=1.e-05 ode.ndt=100 fuel_name=H2 - - name: Run_1dArray - working-directory: ./Testing/Exec/ReactEval - run: | - ./Pele3d.gnu.ex inputs.3d_1dArray ode.dt=1.e-05 ode.ndt=100 fuel_name=H2 - - # Cvode DRM CUDA support - cvodeDRM_CUDA: - name: CUDA@11.0.1 [cvode-DRM] - runs-on: ubuntu-18.04 - steps: - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{github.token}} - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make TPL COMP=gnu USE_CUDA=TRUE Reactions_dir=cvode Chemistry_Model=drm19 - make -j 2 COMP=gnu USE_CUDA=TRUE Reactions_dir=cvode Chemistry_Model=drm19 - - # Cvode LiDryer CUDA support - cvodeLiDryer_CUDA: - name: CUDA@11.0.1 [cvode-LiDryer] - runs-on: ubuntu-18.04 - steps: - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{github.token}} - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make TPL COMP=gnu USE_CUDA=TRUE Reactions_dir=cvode Chemistry_Model=LiDryer - make -j 2 COMP=gnu USE_CUDA=TRUE Reactions_dir=cvode Chemistry_Model=LiDryer - - # ARKode DRM CUDA support - arkodeDRM_CUDA: - name: CUDA@11.0.1 [arkode-DRM] - runs-on: ubuntu-18.04 - steps: - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{github.token}} - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make TPL COMP=gnu USE_CUDA=TRUE Reactions_dir=arkode USE_ARKODE_PP=TRUE Chemistry_Model=drm19 - make -j 2 COMP=gnu USE_CUDA=TRUE Reactions_dir=arkode USE_ARKODE_PP=TRUE Chemistry_Model=drm19 - - # ARKode LiDryer CUDA support - arkodeLiDryer_CUDA: - name: CUDA@11.0.1 [arkode-LiDryer] - runs-on: ubuntu-18.04 - steps: - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{github.token}} - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make TPL COMP=gnu USE_CUDA=TRUE Reactions_dir=arkode USE_ARKODE_PP=TRUE Chemistry_Model=LiDryer - make -j 2 COMP=gnu USE_CUDA=TRUE Reactions_dir=arkode USE_ARKODE_PP=TRUE Chemistry_Model=LiDryer - - # RK64 DRM CUDA support - rk64DRM_CUDA: - name: CUDA@11.0.1 [rk64-DRM] - runs-on: ubuntu-18.04 - steps: - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{github.token}} - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make TPL COMP=gnu USE_CUDA=TRUE Reactions_dir=rk64 USE_SUNDIALS_PP=FALSE USE_RK64_PP=TRUE Chemistry_Model=drm19 - make -j 2 COMP=gnu USE_CUDA=TRUE Reactions_dir=rk64 USE_SUNDIALS_PP=FALSE USE_RK64_PP=TRUE Chemistry_Model=drm19 - - # RK64 LiDryer CUDA support - rk64LiDryer_CUDA: - name: CUDA@11.0.1 [rk64-LiDryer] - runs-on: ubuntu-18.04 - steps: - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{github.token}} - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/ReactEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make TPL COMP=gnu USE_CUDA=TRUE Reactions_dir=rk64 USE_SUNDIALS_PP=FALSE USE_RK64_PP=TRUE Chemistry_Model=LiDryer - make -j 2 COMP=gnu USE_CUDA=TRUE Reactions_dir=rk64 USE_SUNDIALS_PP=FALSE USE_RK64_PP=TRUE Chemistry_Model=LiDryer - -# # Fuego DRM HIP support -# FuegoDRM_HIP: -# name: HIPROCm@3.8 GFortran@9.3 [FuegoDRM] -# runs-on: ubuntu-20.04 -# env: -# {CXXFLAGS: "-fno-operator-names"} -# steps: -# - uses: actions/checkout@v2 -# - name: System Dependencies -# run: .github/workflows/dependencies/dependencies_hip.sh -# - name: AMReX -# run: | -# mkdir build -# git clone https://github.com/AMReX-Codes/amrex.git build/amrex -# - name: Build -# env: -# AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex -# PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} -# working-directory: ./Testing/Exec/ReactEval_C -# run: | -# source /etc/profile.d/rocm.sh -# hipcc --version -# make TPL COMP=gnu USE_HIP=TRUE Eos_Model=Fuego Chemistry_Model=drm19 -# make -j 2 COMP=gnu USE_HIP=TRUE Eos_Model=Fuego Chemistry_Model=drm19 -# -# # Fuego LiDryer HIP support -# FuegoLiDryer_HIP: -# name: HIPROCm@3.8 GFortran@9.3 [FuegoLiDryer] -# runs-on: ubuntu-20.04 -# env: -# {CXXFLAGS: "-fno-operator-names"} -# steps: -# - uses: actions/checkout@v2 -# - name: System Dependencies -# run: .github/workflows/dependencies/dependencies_hip.sh -# - name: AMReX -# run: | -# mkdir build -# git clone https://github.com/AMReX-Codes/amrex.git build/amrex -# - name: Build -# env: -# AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex -# PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} -# working-directory: ./Testing/Exec/ReactEval_C -# run: | -# source /etc/profile.d/rocm.sh -# hipcc --version -# make TPL COMP=gnu USE_HIP=TRUE Eos_Model=Fuego Chemistry_Model=LiDryer -# make -j 2 COMP=gnu USE_HIP=TRUE Eos_Model=Fuego Chemistry_Model=LiDryer diff --git a/.github/workflows/Transport.yml b/.github/workflows/Transport.yml deleted file mode 100644 index c8ddff52b..000000000 --- a/.github/workflows/Transport.yml +++ /dev/null @@ -1,230 +0,0 @@ -name: CI_Transport -on: - workflow_dispatch: - push: - branches: [ development ] - pull_request: - branches: [ development ] - -jobs: - # Constant Transport GNU7.5 and MPI support - Constant_MPI: - name: GNU@7.5 MPI [Constant] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/TranEval - run: | - make -j 2 COMP=gnu Transport_Model=Constant - - name: Run - working-directory: ./Testing/Exec/TranEval - run: | - ./Pele2d.gnu.MPI.ex inputs.2d_Constant - - # Sutherland Transport GNU7.5 and MPI support - Sutherland_MPI: - name: GNU@7.5 MPI [Sutherland] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/TranEval - run: | - make -j 2 COMP=gnu Transport_Model=Sutherland - - name: Run - working-directory: ./Testing/Exec/TranEval - run: | - ./Pele2d.gnu.MPI.ex inputs.2d_Sutherland - - # Simple Transport GNU7.5 and MPI support - Simple_MPI: - name: GNU@7.5 MPI [Simple] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/TranEval - run: | - make -j 2 COMP=gnu Transport_Model=Simple - - name: Run - working-directory: ./Testing/Exec/TranEval - run: | - ./Pele2d.gnu.MPI.ex inputs.2d_Simple - - # Constant Transport CUDA and MPI support - Constant_CUDA: - name: CUDA@11.0.1 MPI [Constant] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/TranEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make -j 2 COMP=gnu USE_CUDA=TRUE Transport_Model=Constant - - # Sutherland Transport CUDA and MPI support - Sutherland_CUDA: - name: CUDA@11.0.1 MPI [Sutherland] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/TranEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make -j 2 COMP=gnu USE_CUDA=TRUE Transport_Model=Sutherland - - # Simple Transport CUDA and MPI support - Simple_CUDA: - name: CUDA@11.0.1 MPI [Simple] - runs-on: ubuntu-latest - env: - {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code"} - steps: - - uses: actions/checkout@v2 - - name: System Dependencies - run: .github/workflows/dependencies/dependencies_nvcc.sh - - name: AMReX - run: | - mkdir build - git clone https://github.com/AMReX-Codes/amrex.git build/amrex - - name: Build - env: - AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - working-directory: ./Testing/Exec/TranEval - run: | - export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} - export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} - make -j 2 COMP=gnu USE_CUDA=TRUE Transport_Model=Simple - - # Constant Transport HIP support - #Constant_HIP: - # name: HIPROCm@3.8 GFortran@9.3 [Constant] - # runs-on: ubuntu-20.04 - # env: - # {CXXFLAGS: "-fno-operator-names"} - # steps: - # - uses: actions/checkout@v2 - # - name: System Dependencies - # run: .github/workflows/dependencies/dependencies_hip.sh - # - name: AMReX - # run: | - # mkdir build - # git clone https://github.com/AMReX-Codes/amrex.git build/amrex - # - name: Build - # env: - # AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - # PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - # working-directory: ./Testing/Exec/TranEval - # run: | - # source /etc/profile.d/rocm.sh - # hipcc --version - # make -j 2 COMP=gnu USE_MPI=FALSE USE_HIP=TRUE Transport_Model=Constant - - # Sutherland Transport HIP support - #Sutherland_HIP: - # name: HIPROCm@3.8 GFortran@9.3 [Sutherland] - # runs-on: ubuntu-20.04 - # env: - # {CXXFLAGS: "-fno-operator-names"} - # steps: - # - uses: actions/checkout@v2 - # - name: System Dependencies - # run: .github/workflows/dependencies/dependencies_hip.sh - # - name: AMReX - # run: | - # mkdir build - # git clone https://github.com/AMReX-Codes/amrex.git build/amrex - # - name: Build - # env: - # AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - # PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - # working-directory: ./Testing/Exec/TranEval - # run: | - # source /etc/profile.d/rocm.sh - # hipcc --version - # make -j 2 COMP=gnu USE_MPI=FALSE USE_HIP=TRUE Transport_Model=Sutherland - - # Simple Transport HIP support - #Simple_HIP: - # name: HIPROCm@3.8 GFortran@9.3 [Simple] - # runs-on: ubuntu-20.04 - # env: - # {CXXFLAGS: "-fno-operator-names"} - # steps: - # - uses: actions/checkout@v2 - # - name: System Dependencies - # run: .github/workflows/dependencies/dependencies_hip.sh - # - name: AMReX - # run: | - # mkdir build - # git clone https://github.com/AMReX-Codes/amrex.git build/amrex - # - name: Build - # env: - # AMREX_HOME: ${GITHUB_WORKSPACE}/build/amrex - # PELE_PHYSICS_HOME: ${GITHUB_WORKSPACE} - # working-directory: ./Testing/Exec/TranEval - # run: | - # source /etc/profile.d/rocm.sh - # hipcc --version - # make -j 2 COMP=gnu USE_MPI=FALSE USE_HIP=TRUE Transport_Model=Simple diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..6d2772f52 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,149 @@ +name: PelePhysics +on: + push: + branches: [development] + pull_request: + branches: [development] + +jobs: + Formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.11 + with: + source: './Eos ./Transport ./Reactions' + exclude: '.' + extensions: 'H,h,cpp' + clangFormatVersion: 11 + + Pythia: + needs: Formatting + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: [3.8] + poetry-version: [1.1.7] + defaults: + run: + working-directory: ${{github.workspace}}/Support/Fuego/Pythia + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{matrix.python-version}} + - name: Run image + uses: abatilo/actions-poetry@v2.0.0 + with: + poetry-version: ${{matrix.poetry-version}} + - name: Install Dependencies using Poetry + run: poetry install + - name: Formatting with black + run: poetry run black --check . + - name: Sort imports with isort + run: poetry run isort --check-only --diff . + - name: Run tests + run: poetry run bash -c "cd ../Mechanism/Models/air && ./make-mechanism.sh" + + Transport-EOS-Reactions: + needs: Formatting + runs-on: ubuntu-latest + strategy: + matrix: + comp: [gnu, llvm, nvcc] + include: + - comp: gnu + amrex_build_args: 'COMP=gnu' + dependency_cmds: + - comp: llvm + amrex_build_args: 'COMP=llvm' + dependency_cmds: + - comp: nvcc + amrex_build_args: 'COMP=gnu USE_CUDA=TRUE' + dependency_cmds: '.github/workflows/dependencies/dependencies_nvcc.sh' + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{github.token}} + - name: Checkout PelePhysics + uses: actions/checkout@v2 + with: + path: PelePhysics-${{matrix.comp}} + - name: Checkout AMReX + uses: actions/checkout@v2 + with: + repository: AMReX-Codes/amrex + path: AMReX-${{matrix.comp}} + - name: Set Environment Variables + run: | + echo "AMREX_HOME=${{github.workspace}}/AMReX-${{matrix.comp}}" >> $GITHUB_ENV + echo "PELE_PHYSICS_HOME=${{github.workspace}}/PelePhysics-${{matrix.comp}}" >> $GITHUB_ENV + echo "TRANSPORT_WORKING_DIRECTORY=${{github.workspace}}/PelePhysics-${{matrix.comp}}/Testing/Exec/TranEval" >> $GITHUB_ENV + echo "EOS_WORKING_DIRECTORY=${{github.workspace}}/PelePhysics-${{matrix.comp}}/Testing/Exec/EosEval" >> $GITHUB_ENV + echo "REACT_WORKING_DIRECTORY=${{github.workspace}}/PelePhysics-${{matrix.comp}}/Testing/Exec/ReactEval" >> $GITHUB_ENV + echo "NPROCS=$(nproc)" >> $GITHUB_ENV + if [ "${{matrix.comp}}" == 'nvcc' ]; then \ + echo "CUDA_HOME=/usr/local/cuda-11.2" >> $GITHUB_ENV; \ + echo "LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64:${LD_LIBRARY_PATH}" >> $GITHUB_ENV; \ + echo "/usr/local/cuda-11.2/bin" >> $GITHUB_PATH; \ + fi + - name: Dependencies + working-directory: ${{env.TRANSPORT_WORKING_DIRECTORY}} + run: | + if [ "${{matrix.comp}}" == 'nvcc' ]; then \ + ${{github.workspace}}/PelePhysics-${{matrix.comp}}/${{matrix.dependency_cmds}}; \ + echo "CUDA_HOME=${CUDA_HOME}"; \ + ls ${CUDA_HOME} > /dev/null; \ + which nvcc || echo "nvcc not in PATH!"; \ + fi + cmake --version + make TPL ${{matrix.amrex_build_args}}; + - name: Test Transport + working-directory: ${{env.TRANSPORT_WORKING_DIRECTORY}} + run: | + echo "::add-matcher::${{github.workspace}}/PelePhysics-${{matrix.comp}}/.github/problem-matchers/gcc.json" + for TYPE in Constant Simple Sutherland; do \ + printf "\n-------- ${TYPE} --------\n"; \ + make -j ${{env.NPROCS}} Transport_Model=${TYPE} TINY_PROFILE=TRUE ${{matrix.amrex_build_args}}; \ + if [ "${{matrix.comp}}" != 'nvcc' ]; then ./Pele2d.${{matrix.comp}}.TPROF.ex inputs.2d_${TYPE}; fi; \ + make realclean; \ + if [ $? -ne 0 ]; then exit 1; fi; \ + done + - name: Test EOS + working-directory: ${{env.EOS_WORKING_DIRECTORY}} + run: | + echo "::add-matcher::${{github.workspace}}/PelePhysics-${{matrix.comp}}/.github/problem-matchers/gcc.json" + for TYPE in Fuego GammaLaw; do \ + if [ "${TYPE}" == 'Fuego' ]; then CHEMISTRY=LiDryer; else CHEMISTRY=Null; fi; \ + printf "\n-------- ${TYPE} --------\n"; \ + make -j ${{env.NPROCS}} Eos_Model=${TYPE} Chemistry_Model=${CHEMISTRY} TINY_PROFILE=TRUE ${{matrix.amrex_build_args}}; \ + if [ "${{matrix.comp}}" != 'nvcc' ]; then ./Pele2d.${{matrix.comp}}.TPROF.ex inputs.2d; fi; \ + make realclean; \ + if [ $? -ne 0 ]; then exit 1; fi; \ + done + - name: Test Reactions + working-directory: ${{env.REACT_WORKING_DIRECTORY}} + run: | + echo "::add-matcher::${{github.workspace}}/PelePhysics-${{matrix.comp}}/.github/problem-matchers/gcc.json" + make -j ${{env.NPROCS}} Eos_Model=Fuego Chemistry_Model=drm19 TINY_PROFILE=TRUE ${{matrix.amrex_build_args}} + if [ "${{matrix.comp}}" != 'nvcc' ]; then \ + for TYPE in Cvode Arkode RK64; do \ + printf "\n-------- ${TYPE} --------\n"; \ + ./Pele3d.${{matrix.comp}}.TPROF.ex inputs.3d_Array4 ode.dt=1.e-05 ode.ndt=100 chem_integrator="Reactor${TYPE}"; \ + ./Pele3d.${{matrix.comp}}.TPROF.ex inputs.3d_1dArray ode.dt=1.e-05 ode.ndt=100 chem_integrator="Reactor${TYPE}"; \ + if [ $? -ne 0 ]; then exit 1; fi; \ + done \ + fi; + make realclean + make -j ${{env.NPROCS}} Eos_Model=Fuego Chemistry_Model=LiDryer TINY_PROFILE=TRUE ${{matrix.amrex_build_args}} + if [ "${{matrix.comp}}" != 'nvcc' ]; then \ + for TYPE in Cvode Arkode RK64; do \ + printf "\n-------- ${TYPE} --------\n"; \ + ./Pele3d.${{matrix.comp}}.TPROF.ex inputs.3d_Array4 ode.dt=1.e-05 ode.ndt=100 chem_integrator="Reactor${TYPE}"; \ + ./Pele3d.${{matrix.comp}}.TPROF.ex inputs.3d_1dArray ode.dt=1.e-05 ode.ndt=100 chem_integrator="Reactor${TYPE}"; \ + if [ $? -ne 0 ]; then exit 1; fi; \ + done \ + fi + make realclean diff --git a/.github/workflows/dependencies/dependencies_nvcc.sh b/.github/workflows/dependencies/dependencies_nvcc.sh index 2e5b7c2ae..933c17d88 100755 --- a/.github/workflows/dependencies/dependencies_nvcc.sh +++ b/.github/workflows/dependencies/dependencies_nvcc.sh @@ -11,20 +11,27 @@ set -eu -o pipefail -sudo apt-get update - -sudo apt-get install -y --no-install-recommends\ +sudo apt-get -qqq update +sudo apt-get install -y \ build-essential \ ca-certificates \ gnupg \ - libopenmpi-dev \ - openmpi-bin \ pkg-config \ wget sudo wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub sudo apt-key add 7fa2af80.pub -echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list +echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" \ + | sudo tee /etc/apt/sources.list.d/cuda.list sudo apt-get update -sudo apt-get install -y cuda-command-line-tools-11-0 cuda-compiler-11-0 cuda-cupti-dev-11-0 cuda-minimal-build-11-0 cuda-nvml-dev-11-0 cuda-nvtx-11-0 libcurand-dev-11-0 libcusparse-dev-11-0 libcusolver-dev-11-0 libcublas-dev-11-0 -sudo ln -s cuda-11.0 /usr/local/cuda +sudo apt-get install -y \ + cuda-command-line-tools-11-2 \ + cuda-compiler-11-2 \ + cuda-cupti-dev-11-2 \ + cuda-minimal-build-11-2 \ + cuda-nvml-dev-11-2 \ + cuda-nvtx-11-2 \ + libcurand-dev-11-2 \ + libcusolver-dev-11-2 \ + libcusparse-dev-11-2 \ + libcublas-dev-11-2 diff --git a/Docs/cvode/source/CvodeInPP.rst b/Docs/cvode/source/CvodeInPP.rst index b5a13d750..5daeaee3f 100644 --- a/Docs/cvode/source/CvodeInPP.rst +++ b/Docs/cvode/source/CvodeInPP.rst @@ -164,7 +164,7 @@ Note that this is a `PelePhysics` flag, so it will automatically be recognized i By default, if Sundials is used then the implicit ODE solver CVODE is selected. The user then has to choose between a number of different methods to integrate the linear system arising during the implicit solve. Add the following line if sparsity features are required: :: - USE_KLU_PP = TRUE + PELE_USE_KLU = TRUE Likewise, if `SuiteSparse` has not been installed as prescribed in :ref:`sec:GetCVODE`, then a line specifying its location should be added: :: @@ -281,18 +281,12 @@ Additionally, the ``FUEGO_GAS`` flag should be set to true and the chemistry mod ifeq ($(USE_SUNDIALS_PP), TRUE) # provide location of sundials lib if needed SUNDIALS_LIB_DIR=$(PELE_PHYSICS_HOME)/ThirdParty/sundials/instdir/lib/ - # use ARKODE: if FALSE then CVODE is used - USE_ARKODE_PP = FALSE # use KLU sparse features -- only useful if CVODE is used - USE_KLU_PP = FALSE - ifeq ($(USE_KLU_PP), TRUE) + PELE_USE_KLU = FALSE + ifeq ($(PELE_USE_KLU), TRUE) # provide location of KLU lib if needed SUITESPARSE_DIR=$(PELE_PHYSICS_HOME)/ThirdParty/SuiteSparse/ endif - else - # Activates use of Hari explicit RK - # will only work if USE_SUNDIALS_PP = FALSE - USE_RK64_PP = FALSE endif ####################### @@ -386,7 +380,7 @@ Only the middle part of the ``GNUmakefile`` needs to be modified compared to the ifeq ($(USE_SUNDIALS_PP), TRUE) ... # use KLU sparse features -- only useful if CVODE is used - USE_KLU_PP = TRUE + PELE_USE_KLU = TRUE ... else ... diff --git a/Eos/EOS.H b/Eos/EOS.H index 05a083ab0..c6caf63d1 100644 --- a/Eos/EOS.H +++ b/Eos/EOS.H @@ -27,16 +27,13 @@ static_assert(true, "Invalid EOS specified"); namespace eos { template -void -atomic_weightsCHON(amrex::Real atwCHON[]); +void atomic_weightsCHON(amrex::Real atwCHON[]); template -void -element_compositionCHON(int ecompCHON[]); +void element_compositionCHON(int ecompCHON[]); template -void -speciesNames(amrex::Vector& spn); +void speciesNames(amrex::Vector& spn); } // namespace eos } // namespace physics diff --git a/Eos/Fuego.H b/Eos/Fuego.H index 2d1a08cf8..552fd1530 100644 --- a/Eos/Fuego.H +++ b/Eos/Fuego.H @@ -126,7 +126,7 @@ struct Fuego { HY2T(H, Y, T); } - + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void RYET2P( @@ -173,17 +173,19 @@ struct Fuego WDOT[n] *= mw[n]; } -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void RTY2JAC( - amrex::Real R, amrex::Real T, amrex::Real Y[], amrex::Real JAC[], int HP) + amrex::Real R, + amrex::Real T, + amrex::Real Y[], + amrex::Real JAC[], + const int HP) { amrex::Real C[NUM_SPECIES]; CKYTCR(&R, &T, Y, C); DWDOT(JAC, C, &T, &HP); } -#endif AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE @@ -198,7 +200,9 @@ struct Fuego AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - void RTY2Ei(amrex::Real /*R*/, amrex::Real T, amrex::Real* /*Y[]*/, amrex::Real Ei[]) { + void RTY2Ei( + amrex::Real /*R*/, amrex::Real T, amrex::Real* /*Y[]*/, amrex::Real Ei[]) + { T2Ei(T, Ei); } diff --git a/Eos/GammaLaw.H b/Eos/GammaLaw.H index c2276391a..0b081110d 100644 --- a/Eos/GammaLaw.H +++ b/Eos/GammaLaw.H @@ -55,7 +55,9 @@ struct GammaLaw AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - void RTY2Ei(amrex::Real /*R*/, amrex::Real T, amrex::Real* /*Y[]*/, amrex::Real Ei[]) { + void RTY2Ei( + amrex::Real /*R*/, amrex::Real T, amrex::Real* /*Y[]*/, amrex::Real Ei[]) + { T2Ei(T, Ei); } @@ -157,14 +159,14 @@ struct GammaLaw const amrex::Real Cv = Constants::RU / (wbar * (gamma - 1.0)); T = H / (Cv * gamma); } - + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void RHY2T(amrex::Real /*R*/, amrex::Real H, amrex::Real Y[], amrex::Real& T) { HY2T(H, Y, T); } - + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void RTY2P(amrex::Real R, amrex::Real T, amrex::Real Y[], amrex::Real& P) @@ -184,6 +186,40 @@ struct GammaLaw T = P * wbar / (R * Constants::RU); } + AMREX_GPU_HOST_DEVICE + AMREX_FORCE_INLINE + void RTY2WDOT( + amrex::Real /*R*/, + amrex::Real /*T*/, + amrex::Real* /*Y[]*/, + amrex::Real* /*WDOT[]*/) + { + amrex::Error("RTY2WDOT not physically possible for GammaLaw EoS"); + } + + AMREX_GPU_HOST_DEVICE + AMREX_FORCE_INLINE + void RTY2JAC( + amrex::Real /*R*/, + amrex::Real /*T*/, + amrex::Real* /*Y[]*/, + amrex::Real* /*JAC[]*/, + const int /*HP*/) + { + amrex::Error("RTY2JAC not supported with GammaLaw EoS"); + } + + AMREX_GPU_HOST_DEVICE + AMREX_FORCE_INLINE + void RTY2C( + amrex::Real /*R*/, + amrex::Real /*T*/, + amrex::Real* /*Y[]*/, + amrex::Real* /*acti[]*/) + { + amrex::Error("RTY2C not supported with GammaLaw EoS"); + } + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void Y2X(amrex::Real Y[], amrex::Real X[]) diff --git a/Eos/SRK.H b/Eos/SRK.H index 63afb38e5..c2b96bf98 100644 --- a/Eos/SRK.H +++ b/Eos/SRK.H @@ -436,12 +436,16 @@ struct SRK AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - void RHY2T(amrex::Real /*R*/, amrex::Real /*H*/, amrex::Real* /*Y[]*/, amrex::Real& /*T*/) + void RHY2T( + amrex::Real /*R*/, + amrex::Real /*H*/, + amrex::Real* /*Y[]*/, + amrex::Real& /*T*/) { // RHY2T is possible but is not yet supported amrex::Error("RHY2T not yet supported for this EoS"); } - + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void RTY2P(amrex::Real R, amrex::Real T, amrex::Real Y[], amrex::Real& P) @@ -512,18 +516,6 @@ struct SRK } } - AMREX_GPU_HOST_DEVICE - AMREX_FORCE_INLINE - void RTY2JAC( - amrex::Real /*R*/, - amrex::Real /*T*/, - amrex::Real* /*Y[]*/, - amrex::Real* /*JAC[]*/, - int /*HP*/) - { - amrex::Error("RTY2JAC not supported with SRK EoS"); - } - AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void RTY2C(amrex::Real R, amrex::Real T, amrex::Real Y[], amrex::Real acti[]) @@ -571,6 +563,18 @@ struct SRK WDOT[n] *= mw[n]; } + AMREX_GPU_HOST_DEVICE + AMREX_FORCE_INLINE + void RTY2JAC( + amrex::Real /*R*/, + amrex::Real /*T*/, + amrex::Real* /*Y[]*/, + amrex::Real* /*JAC[]*/, + const int /*HP*/) + { + amrex::Error("RTY2JAC not supported with SRK EoS"); + } + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void T2Ei(amrex::Real /*T*/, amrex::Real* /*Ei[]*/) diff --git a/Reactions/Make.package b/Reactions/Make.package index 18d59d235..86b4f422a 100644 --- a/Reactions/Make.package +++ b/Reactions/Make.package @@ -1,8 +1,6 @@ -CEXE_headers += reactor.H -CEXE_sources += reactor.cpp -ifeq ($(USE_SUNDIALS_PP),TRUE) - ifneq (, $(filter TRUE, $(USE_CUDA) $(USE_HIP))) - CEXE_headers += AMReX_SUNMemory.H - CEXE_sources += AMReX_SUNMemory.cpp - endif +CEXE_headers += ReactorUtils.H ReactorTypes.H ReactorBase.H ReactorRK64.H ReactorArkode.H ReactorNull.H ReactorCvode.H ReactorCvodeUtils.H ReactorCvodePreconditioner.H ReactorCvodeJacobian.H ReactorCvodeCustomLinSolver.H +CEXE_sources += ReactorUtils.cpp ReactorBase.cpp ReactorRK64.cpp ReactorArkode.cpp ReactorNull.cpp ReactorCvode.cpp ReactorCvodeUtils.cpp ReactorCvodePreconditioner.cpp ReactorCvodeJacobian.cpp ReactorCvodeCustomLinSolver.cpp +ifneq (, $(filter TRUE, $(USE_CUDA) $(USE_HIP))) + CEXE_headers += AMReX_SUNMemory.H + CEXE_sources += AMReX_SUNMemory.cpp endif diff --git a/Reactions/ReactorArkode.H b/Reactions/ReactorArkode.H new file mode 100644 index 000000000..b8aae6d3c --- /dev/null +++ b/Reactions/ReactorArkode.H @@ -0,0 +1,145 @@ +#ifndef _REACTORARKODE_H_ +#define _REACTORARKODE_H_ + +#include "ReactorBase.H" +#include +#include +#include +#ifdef AMREX_USE_GPU +#include "AMReX_SUNMemory.H" +#endif + +#ifdef AMREX_USE_HIP +#include +#endif + +#ifdef AMREX_USE_CUDA +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +namespace pele { +namespace physics { +namespace reactions { + +struct ARKODEUserData +{ + int ncells_d; + int neqs_per_cell; + int iverbose; + int ireactor_type; + amrex::Real dt_save; + amrex::Real* rhoe_init_d = NULL; + amrex::Real* rhoesrc_ext_d = NULL; + amrex::Real* rYsrc_d = NULL; +#ifdef AMREX_USE_GPU + amrex::gpuStream_t stream; +#endif + int nbBlocks; + int nbThreads; +}; + +class ReactorArkode : public ReactorBase::Register +{ +public: + static std::string identifier() { return "ReactorArkode"; } + + using Ordering = utils::CYOrder; + + int init(int reactor_type, int Ncells) override; + + void close() override {} + + int react( + const amrex::Box& box, + amrex::Array4 const& rY_in, + amrex::Array4 const& rY_src_in, + amrex::Array4 const& T_in, + amrex::Array4 const& rEner_in, + amrex::Array4 const& rEner_src_in, + amrex::Array4 const& FC_in, + amrex::Array4 const& mask, + amrex::Real& dt_react, + amrex::Real& time +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) override; + + int react( + amrex::Real* rY_in, + amrex::Real* rY_src_in, + amrex::Real* rX_in, + amrex::Real* rX_src_in, + amrex::Real& dt_react, + amrex::Real& time, + int Ncells +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) override; + + static int + cF_RHS(amrex::Real t, N_Vector y_in, N_Vector ydot, void* user_data); + + void flatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& frcExt, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Real* y_vect, + amrex::Real* src_vect, + amrex::Real* vect_energy, + amrex::Real* src_vect_energy) override + { + flatten_ops.flatten( + box, ncells, m_reactor_type, rhoY, frcExt, temperature, rhoE, frcEExt, + y_vect, src_vect, vect_energy, src_vect_energy); + } + + void unflatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Array4 const& FC_in, + amrex::Real* y_vect, + amrex::Real* vect_energy, + long int* FCunt, + amrex::Real dt) override + { + flatten_ops.unflatten( + box, ncells, m_reactor_type, rhoY, temperature, rhoE, frcEExt, FC_in, + y_vect, vect_energy, FCunt, dt); + } + + void SetTypValsODE(const std::vector& ExtTypVals) override; + +private: + amrex::Real relTol{1e-6}; + amrex::Real absTol{1e-10}; + int use_erkstep{0}; + int rk_method{40}; + int rk_controller{0}; + utils::FlattenOps flatten_ops; + int m_reactor_type{0}; +}; + +} // namespace reactions +} // namespace physics +} // namespace pele + +#endif diff --git a/Reactions/arkode/reactor_arkode.cpp b/Reactions/ReactorArkode.cpp similarity index 76% rename from Reactions/arkode/reactor_arkode.cpp rename to Reactions/ReactorArkode.cpp index f51f92e05..caed93e8a 100644 --- a/Reactions/arkode/reactor_arkode.cpp +++ b/Reactions/ReactorArkode.cpp @@ -1,8 +1,15 @@ -#include "reactor.H" +#include "ReactorArkode.H" -int reactor_init(int reactor_type, int Ncells) +namespace pele { +namespace physics { +namespace reactions { + +int +ReactorArkode::init(int reactor_type, int /*Ncells*/) { - BL_PROFILE("Pele::reactor_init()"); + BL_PROFILE("Pele::ReactorArkode::init()"); + m_reactor_type = reactor_type; + ReactorTypes::check_reactor_type(m_reactor_type); amrex::ParmParse pp("ode"); pp.query("use_erkstep", use_erkstep); pp.query("rtol", relTol); @@ -106,9 +113,8 @@ int reactor_init(int reactor_type, int Ncells) return (0); } -// React with array4 int -react( +ReactorArkode::react( const amrex::Box& box, amrex::Array4 const& rY_in, amrex::Array4 const& rY_src_in, @@ -116,46 +122,43 @@ react( amrex::Array4 const& rEner_in, amrex::Array4 const& rEner_src_in, amrex::Array4 const& FC_in, - amrex::Array4 const& mask, + amrex::Array4 const& /*mask*/, amrex::Real& dt_react, - amrex::Real& time, - const int& reactor_type + amrex::Real& time #ifdef AMREX_USE_GPU , amrex::gpuStream_t stream #endif ) { - BL_PROFILE("Pele::react()"); - int NCELLS, NEQ, neq_tot; - realtype time_init, time_out; + BL_PROFILE("Pele::ReactorArkode::react()"); - void* arkode_mem = NULL; - N_Vector y = NULL; + void* arkode_mem = nullptr; + N_Vector y = nullptr; - NEQ = NUM_SPECIES + 1; - NCELLS = box.numPts(); - neq_tot = NEQ * NCELLS; + int NEQ = NUM_SPECIES + 1; + int NCELLS = box.numPts(); + int neq_tot = NEQ * NCELLS; AMREX_ASSERT(NCELLS < std::numeric_limits::max()); - ARKODEUserData *user_data; + ARKODEUserData* user_data; user_data = (ARKODEUserData*)amrex::The_Arena()->alloc(sizeof(struct ARKODEUserData)); user_data->ncells_d = NCELLS; user_data->neqs_per_cell = NEQ; - user_data->ireactor_type = reactor_type; + user_data->ireactor_type = m_reactor_type; user_data->iverbose = 1; -//#ifdef AMREX_USE_GPU -// user_data->stream = stream; -//#endif -// user_data->nbThreads = 32; -// user_data->nbBlocks = std::max(1, NCELLS / user_data->nbThreads); + //#ifdef AMREX_USE_GPU + // user_data->stream = stream; + //#endif + // user_data->nbThreads = 32; + // user_data->nbBlocks = std::max(1, NCELLS / user_data->nbThreads); #if defined(AMREX_USE_CUDA) y = N_VNewWithMemHelp_Cuda( neq_tot, /*use_managed_mem=*/true, *amrex::sundials::The_SUNMemory_Helper()); - if (check_flag((void*)y, "N_VNewWithMemHelp_Cuda", 0)) + if (utils::check_flag((void*)y, "N_VNewWithMemHelp_Cuda", 0)) return (1); SUNCudaExecPolicy* stream_exec_policy = new SUNCudaThreadDirectExecPolicy(256, stream); @@ -166,7 +169,7 @@ react( y = N_VNewWithMemHelp_Hip( neq_tot, /*use_managed_mem=*/true, *amrex::sundials::The_SUNMemory_Helper()); - if (check_flag((void*)y, "N_VNewWithMemHelp_Hip", 0)) + if (utils::check_flag((void*)y, "N_VNewWithMemHelp_Hip", 0)) return (1); SUNHipExecPolicy* stream_exec_policy = new SUNHipThreadDirectExecPolicy(512, stream); @@ -175,8 +178,9 @@ react( N_VSetKernelExecPolicy_Hip(y, stream_exec_policy, reduce_exec_policy); #else y = N_VNew_Serial(neq_tot); - if (check_flag((void*)y, "N_VNew_Serial", 0)) + if (utils::check_flag((void*)y, "N_VNew_Serial", 0)) { return (1); + } #endif user_data->rhoe_init_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( @@ -194,33 +198,27 @@ react( realtype* yvec_d = N_VGetArrayPointer(y); #endif - const auto len = amrex::length(box); - const auto lo = amrex::lbound(box); - amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); - box_flatten( - icell, NCELLS, i, j, k, user_data->ireactor_type, rY_in, rY_src_in, T_in, - rEner_in, rEner_src_in, yvec_d, user_data->rYsrc_d, - user_data->rhoe_init_d, user_data->rhoesrc_ext_d); - }); + flatten( + box, NCELLS, rY_in, rY_src_in, T_in, rEner_in, rEner_src_in, yvec_d, + user_data->rYsrc_d, user_data->rhoe_init_d, user_data->rhoesrc_ext_d); - time_init = time; - time_out = time + dt_react; + realtype time_init = time; + realtype time_out = time + dt_react; if (use_erkstep == 0) { - arkode_mem = ARKStepCreate(cF_RHS, NULL, time, y); + arkode_mem = ARKStepCreate(cF_RHS, nullptr, time, y); ARKStepSetUserData(arkode_mem, static_cast(user_data)); ARKStepSStolerances(arkode_mem, relTol, absTol); ARKStepResStolerance(arkode_mem, absTol); ARKStepSetTableNum(arkode_mem, -1, rk_method); - ARKStepSetAdaptivityMethod(arkode_mem, rk_controller, 1, 0, NULL); + ARKStepSetAdaptivityMethod(arkode_mem, rk_controller, 1, 0, nullptr); ARKStepEvolve(arkode_mem, time_out, y, &time_init, ARK_NORMAL); } else { arkode_mem = ERKStepCreate(cF_RHS, time, y); ERKStepSetUserData(arkode_mem, static_cast(user_data)); ERKStepSStolerances(arkode_mem, relTol, absTol); ERKStepSetTableNum(arkode_mem, rk_method); - ERKStepSetAdaptivityMethod(arkode_mem, rk_controller, 1, 0, NULL); + ERKStepSetAdaptivityMethod(arkode_mem, rk_controller, 1, 0, nullptr); ERKStepEvolve(arkode_mem, time_out, y, &time_init, ARK_NORMAL); } @@ -236,12 +234,11 @@ react( ERKStepGetNumRhsEvals(arkode_mem, &nfe); } - amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); - box_unflatten( - icell, NCELLS, i, j, k, user_data->ireactor_type, rY_in, T_in, rEner_in, - rEner_src_in, FC_in, yvec_d, user_data->rhoe_init_d, nfe, dt_react); - }); + amrex::Gpu::DeviceVector v_nfe(NCELLS, nfe); + long int* d_nfe = v_nfe.data(); + unflatten( + box, NCELLS, rY_in, T_in, rEner_in, rEner_src_in, FC_in, yvec_d, + user_data->rhoe_init_d, d_nfe, dt_react); N_VDestroy(y); if (use_erkstep == 0) { @@ -261,14 +258,13 @@ react( // React for 1d array int -react( +ReactorArkode::react( realtype* rY_in, realtype* rY_src_in, realtype* rX_in, realtype* rX_src_in, realtype& dt_react, realtype& time, - int reactor_type, int Ncells #ifdef AMREX_USE_GPU , @@ -276,20 +272,18 @@ react( #endif ) { - BL_PROFILE("Pele::react()"); - int NCELLS, NEQ, neq_tot; - realtype time_init, time_out; - void* arkode_mem = NULL; - N_Vector y = NULL; - NEQ = NUM_SPECIES + 1; - NCELLS = Ncells; - neq_tot = NEQ * NCELLS; - ARKODEUserData *user_data; + BL_PROFILE("Pele::ReactorArkode::react()"); + void* arkode_mem = nullptr; + N_Vector y = nullptr; + int NEQ = NUM_SPECIES + 1; + int NCELLS = Ncells; + int neq_tot = NEQ * NCELLS; + ARKODEUserData* user_data; user_data = (ARKODEUserData*)amrex::The_Arena()->alloc(sizeof(struct ARKODEUserData)); user_data->ncells_d = NCELLS; user_data->neqs_per_cell = NEQ; - user_data->ireactor_type = reactor_type; + user_data->ireactor_type = m_reactor_type; user_data->iverbose = 1; #ifdef AMREX_USE_GPU user_data->stream = stream; @@ -301,7 +295,7 @@ react( y = N_VNewWithMemHelp_Cuda( neq_tot, /*use_managed_mem=*/true, *amrex::sundials::The_SUNMemory_Helper()); - if (check_flag((void*)y, "N_VNewWithMemHelp_Cuda", 0)) + if (utils::check_flag((void*)y, "N_VNewWithMemHelp_Cuda", 0)) return (1); SUNCudaExecPolicy* stream_exec_policy = new SUNCudaThreadDirectExecPolicy(256, stream); @@ -312,7 +306,7 @@ react( y = N_VNewWithMemHelp_Hip( neq_tot, /*use_managed_mem=*/true, *amrex::sundials::The_SUNMemory_Helper()); - if (check_flag((void*)y, "N_VNewWithMemHelp_Hip", 0)) + if (utils::check_flag((void*)y, "N_VNewWithMemHelp_Hip", 0)) return (1); SUNHipExecPolicy* stream_exec_policy = new SUNHipThreadDirectExecPolicy(256, stream); @@ -321,8 +315,9 @@ react( N_VSetKernelExecPolicy_Hip(y, stream_exec_policy, reduce_exec_policy); #else y = N_VNew_Serial(neq_tot); - if (check_flag((void*)y, "N_VNew_Serial", 0)) + if (utils::check_flag((void*)y, "N_VNew_Serial", 0)) { return (1); + } #endif user_data->rhoe_init_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( @@ -357,11 +352,11 @@ react( std::memcpy(user_data->rhoesrc_ext_d, rX_src_in, sizeof(realtype) * NCELLS); #endif - time_init = time; - time_out = time + dt_react; + realtype time_init = time; + realtype time_out = time + dt_react; if (use_erkstep == 0) { - arkode_mem = ARKStepCreate(cF_RHS, NULL, time, y); + arkode_mem = ARKStepCreate(cF_RHS, nullptr, time, y); ARKStepSetUserData(arkode_mem, static_cast(user_data)); ARKStepSStolerances(arkode_mem, relTol, absTol); ARKStepResStolerance(arkode_mem, absTol); @@ -410,9 +405,11 @@ react( return nfe; } -int cF_RHS(realtype t, N_Vector y_in, N_Vector ydot_in, void* user_data) +int +ReactorArkode::cF_RHS( + realtype t, N_Vector y_in, N_Vector ydot_in, void* user_data) { - BL_PROFILE("Pele::cF_RHS()"); + BL_PROFILE("Pele::ReactorArkode::cF_RHS()"); #if defined(AMREX_USE_CUDA) realtype* yvec_d = N_VGetDeviceArrayPointer_Cuda(y_in); realtype* ydot_d = N_VGetDeviceArrayPointer_Cuda(ydot_in); @@ -424,32 +421,19 @@ int cF_RHS(realtype t, N_Vector y_in, N_Vector ydot_in, void* user_data) realtype* ydot_d = N_VGetArrayPointer(ydot_in); #endif - ARKODEUserData *udata = static_cast(user_data); + auto* udata = static_cast(user_data); udata->dt_save = t; -// Manual launch for fKernelSpec -// const auto ec = amrex::Gpu::ExecutionConfig(udata->ncells_d); -// amrex::launch_global<<< -// udata->nbBlocks, udata->nbThreads, ec.sharedMem, udata->stream>>>( -// [=] AMREX_GPU_DEVICE() noexcept { -// for (int icell = blockDim.x * blockIdx.x + threadIdx.x, -// stride = blockDim.x * gridDim.x; -// icell < udata->ncells_d; icell += stride) { -// fKernelSpec( -// icell, udata->dt_save, udata->ireactor_type, yvec_d, ydot_d, -// udata->rhoe_init_d, udata->rhoesrc_ext_d, udata->rYsrc_d); -// } -// }); auto ncells = udata->ncells_d; auto dt_save = udata->dt_save; auto reactor_type = udata->ireactor_type; - auto rhoe_init = udata->rhoe_init_d; - auto rhoesrc_ext = udata->rhoesrc_ext_d; - auto rYsrc = udata->rYsrc_d; + auto* rhoe_init = udata->rhoe_init_d; + auto* rhoesrc_ext = udata->rhoesrc_ext_d; + auto* rYsrc = udata->rYsrc_d; amrex::ParallelFor(udata->ncells_d, [=] AMREX_GPU_DEVICE(int icell) noexcept { - fKernelSpec( - icell, ncells, dt_save, reactor_type, yvec_d, ydot_d, - rhoe_init, rhoesrc_ext, rYsrc); + utils::fKernelSpec( + icell, ncells, dt_save, reactor_type, yvec_d, ydot_d, rhoe_init, + rhoesrc_ext, rYsrc); }); amrex::Gpu::Device::streamSynchronize(); @@ -457,3 +441,11 @@ int cF_RHS(realtype t, N_Vector y_in, N_Vector ydot_in, void* user_data) return (0); } +void +ReactorArkode::SetTypValsODE(const std::vector& /*ExtTypVals*/) +{ + amrex::Print() << "WARNING: ignoring TypVals for this reactor." << std::endl; +} +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorBase.H b/Reactions/ReactorBase.H new file mode 100644 index 000000000..a5ab7f90a --- /dev/null +++ b/Reactions/ReactorBase.H @@ -0,0 +1,88 @@ +#ifndef _REACTORBASE_H_ +#define _REACTORBASE_H_ + +#include + +#include "Factory.H" +#include "PelePhysics.H" +#include "mechanism.H" +#include "ReactorUtils.H" + +namespace pele { +namespace physics { +namespace reactions { + +class ReactorBase : public Factory +{ +public: + static const std::string base_identifier() { return "ReactorBase"; } + + virtual int init(int reactor_type, int Ncells) = 0; + + virtual void close() = 0; + + virtual int react( + const amrex::Box& box, + amrex::Array4 const& rY_in, + amrex::Array4 const& rY_src_in, + amrex::Array4 const& T_in, + amrex::Array4 const& rEner_in, + amrex::Array4 const& rEner_src_in, + amrex::Array4 const& FC_in, + amrex::Array4 const& mask, + amrex::Real& dt_react, + amrex::Real& time +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) = 0; + + virtual int react( + amrex::Real* rY_in, + amrex::Real* rY_src_in, + amrex::Real* rX_in, + amrex::Real* rX_src_in, + amrex::Real& dt_react, + amrex::Real& time, + int Ncells +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) = 0; + + virtual void flatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& frcExt, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Real* y_vect, + amrex::Real* src_vect, + amrex::Real* vect_energy, + amrex::Real* src_vect_energy) = 0; + + virtual void unflatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Array4 const& FC_in, + amrex::Real* y_vect, + amrex::Real* vect_energy, + long int* FCunt, + amrex::Real dt) = 0; + + virtual void SetTypValsODE(const std::vector& ExtTypVals) = 0; + + virtual ~ReactorBase() = default; +}; +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorBase.cpp b/Reactions/ReactorBase.cpp new file mode 100644 index 000000000..7698fecc7 --- /dev/null +++ b/Reactions/ReactorBase.cpp @@ -0,0 +1,9 @@ +#include "ReactorBase.H" + +namespace pele { +namespace physics { +namespace reactions { + +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorCvode.H b/Reactions/ReactorCvode.H new file mode 100644 index 000000000..44b6b5473 --- /dev/null +++ b/Reactions/ReactorCvode.H @@ -0,0 +1,167 @@ +#ifndef _REACTORCVODE_H_ +#define _REACTORCVODE_H_ + +#include "ReactorBase.H" +#include "ReactorCvodeUtils.H" +#include "ReactorCvodePreconditioner.H" +#include "ReactorCvodeJacobian.H" +#include "ReactorCvodeCustomLinSolver.H" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef AMREX_USE_GPU +#include "AMReX_SUNMemory.H" +#endif + +#ifdef AMREX_USE_HIP +#include +#endif + +#ifdef PELE_USE_KLU +#include "klu.h" +#include +#endif + +#ifdef PELE_USE_MAGMA +#include +#include +#endif + +#ifdef AMREX_USE_CUDA +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +namespace pele { +namespace physics { +namespace reactions { + +class ReactorCvode : public ReactorBase::Register +{ +public: + static std::string identifier() { return "ReactorCvode"; } + + using Ordering = utils::YCOrder; + + int init(int reactor_type, int Ncells) override; + + void close() override; + + int react( + const amrex::Box& box, + amrex::Array4 const& rY_in, + amrex::Array4 const& rY_src_in, + amrex::Array4 const& T_in, + amrex::Array4 const& rEner_in, + amrex::Array4 const& rEner_src_in, + amrex::Array4 const& FC_in, + amrex::Array4 const& mask, + amrex::Real& dt_react, + amrex::Real& time +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) override; + + int react( + amrex::Real* rY_in, + amrex::Real* rY_src_in, + amrex::Real* rX_in, + amrex::Real* rX_src_in, + amrex::Real& dt_react, + amrex::Real& time, + int Ncells +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) override; + + static int + cF_RHS(amrex::Real t, N_Vector y_in, N_Vector ydot, void* user_data); + + void flatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& frcExt, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Real* y_vect, + amrex::Real* src_vect, + amrex::Real* vect_energy, + amrex::Real* src_vect_energy) override + { + flatten_ops.flatten( + box, ncells, m_reactor_type, rhoY, frcExt, temperature, rhoE, frcEExt, + y_vect, src_vect, vect_energy, src_vect_energy); + } + + void unflatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Array4 const& FC_in, + amrex::Real* y_vect, + amrex::Real* vect_energy, + long int* FCunt, + amrex::Real dt) override + { + flatten_ops.unflatten( + box, ncells, m_reactor_type, rhoY, temperature, rhoE, frcEExt, FC_in, + y_vect, vect_energy, FCunt, dt); + } + + void SetTypValsODE(const std::vector& ExtTypVals) override; + +private: + void checkCvodeOptions() const; + void allocUserData( + CVODEUserData* udata, + int a_ncells +#ifdef AMREX_USE_GPU + , + SUNMatrix& a_A, + amrex::gpuStream_t stream +#endif + ) const; + void setCvodeTols(void* a_cvode_mem, CVODEUserData* a_udata); + void freeUserData(CVODEUserData* data_wk); + + amrex::Real relTol{1e-6}; + amrex::Real absTol{1e-10}; + amrex::Array typVals; + utils::FlattenOps flatten_ops; + int m_reactor_type{0}; + +#ifndef AMREX_USE_GPU + N_Vector y = NULL; + SUNLinearSolver LS = NULL; + SUNMatrix A = NULL; + void* cvode_mem = NULL; + CVODEUserData* udata_g = NULL; +#endif +}; +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorCvode.cpp b/Reactions/ReactorCvode.cpp new file mode 100644 index 000000000..6104550cd --- /dev/null +++ b/Reactions/ReactorCvode.cpp @@ -0,0 +1,1954 @@ +#include "ReactorCvode.H" + +namespace pele { +namespace physics { +namespace reactions { +int +ReactorCvode::init(int reactor_type, int Ncells) +{ + BL_PROFILE("Pele::ReactorCvode::init()"); + m_reactor_type = reactor_type; + ReactorTypes::check_reactor_type(m_reactor_type); + amrex::ParmParse pp("ode"); + pp.query("rtol", relTol); + pp.query("atol", absTol); + checkCvodeOptions(); + +#ifndef AMREX_USE_GPU + // ---------------------------------------------------------- + // On CPU, initialize cvode_mem/userData + // ---------------------------------------------------------- + + // ---------------------------------------------------------- + // Solution vector + int neq_tot = (NUM_SPECIES + 1) * Ncells; + y = N_VNew_Serial(neq_tot); + if (utils::check_flag((void*)y, "N_VNew_Serial", 0)) { + return (1); + } + + // ---------------------------------------------------------- + // Call CVodeCreate to create the solver memory and specify the Backward + // Differentiation Formula and the use of a Newton iteration + cvode_mem = CVodeCreate(CV_BDF); + if (utils::check_flag((void*)cvode_mem, "CVodeCreate", 0)) { + return (1); + } + + udata_g = + (CVODEUserData*)amrex::The_Arena()->alloc(sizeof(struct CVODEUserData)); + allocUserData(udata_g, Ncells); + if (utils::check_flag((void*)udata_g, "allocUserData", 2)) { + return (1); + } + + // Set the pointer to user-defined data + int flag = CVodeSetUserData(cvode_mem, udata_g); + if (utils::check_flag(&flag, "CVodeSetUserData", 1)) { + return (1); + } + + // Call CVodeInit to initialize the integrator memory and specify the user's + // right hand side function, the inital time, and initial dependent variable + // vector y. + amrex::Real time = 0.0; + flag = CVodeInit(cvode_mem, cF_RHS, time, y); + if (utils::check_flag(&flag, "CVodeInit", 1)) { + return (1); + } + + // ---------------------------------------------------------- + // Setup tolerances + setCvodeTols(cvode_mem, udata_g); + + // ---------------------------------------------------------- + // Linear solver data + if ( + udata_g->isolve_type == cvode::denseFDDirect || + udata_g->isolve_type == cvode::denseDirect) { + // Create dense SUNMatrix for use in linear solves + A = SUNDenseMatrix(neq_tot, neq_tot); + if (utils::check_flag((void*)A, "SUNDenseMatrix", 0)) { + return (1); + } + + // Create dense SUNLinearSolver object for use by CVode + LS = SUNDenseLinearSolver(y, A); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) { + return (1); + } + + // Call CVDlsSetLinearSolver to attach the matrix and linear solver to CVode + flag = CVDlsSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVDlsSetLinearSolver", 1)) { + return (1); + } + + } else if (udata_g->isolve_type == cvode::sparseDirect) { +#ifdef PELE_USE_KLU + // Create sparse SUNMatrix for use in linear solves + A = SUNSparseMatrix( + neq_tot, neq_tot, (udata_g->NNZ) * udata_g->ncells_d, CSC_MAT); + if (utils::check_flag((void*)A, "SUNSparseMatrix", 0)) + return (1); + + // Create KLU solver object for use by CVode + LS = SUNLinSol_KLU(y, A); + if (utils::check_flag((void*)LS, "SUNLinSol_KLU", 0)) + return (1); + + // Call CVodeSetLinearSolver to attach the matrix and linear solver to CVode + flag = CVodeSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); +#else + amrex::Abort("sparseDirect solver_type not valid without KLU library."); +#endif + + } else if (udata_g->isolve_type == cvode::customDirect) { + // Create dense SUNMatrix for use in linear solves + A = SUNSparseMatrix( + neq_tot, neq_tot, (udata_g->NNZ) * udata_g->ncells_d, CSR_MAT); + if (utils::check_flag((void*)A, "SUNDenseMatrix", 0)) { + return (1); + } + + // Create dense SUNLinearSolver object for use by CVode + LS = cvode::SUNLinSol_sparse_custom( + y, A, reactor_type, udata_g->ncells_d, (NUM_SPECIES + 1), udata_g->NNZ); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) { + return (1); + } + + // Call CVDlsSetLinearSolver to attach the matrix and linear solver to CVode + flag = CVDlsSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVDlsSetLinearSolver", 1)) { + return (1); + } + + } else if (udata_g->isolve_type == cvode::GMRES) { + // Create the GMRES linear solver object + LS = SUNLinSol_SPGMR(y, PREC_NONE, 0); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) { + return (1); + } + + // Set CVSpils linear solver to LS + flag = CVSpilsSetLinearSolver(cvode_mem, LS); + if (utils::check_flag(&flag, "CVSpilsSetLinearSolver", 1)) { + return (1); + } + + } else if (udata_g->isolve_type == cvode::precGMRES) { + // Create the GMRES linear solver object + LS = SUNLinSol_SPGMR(y, PREC_LEFT, 0); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) { + return (1); + } + + // Set CVSpils linear solver to LS + flag = CVSpilsSetLinearSolver(cvode_mem, LS); + if (utils::check_flag(&flag, "CVSpilsSetLinearSolver", 1)) { + return (1); + } + + } else { + amrex::Abort("Wrong choice of linear solver..."); + } + + // ---------------------------------------------------------- + // Analytical Jac. data for direct solver + if (udata_g->ianalytical_jacobian == 1) { + if (udata_g->isolve_type == cvode::denseDirect) { + // Set the user-supplied Jacobian routine Jac + flag = CVodeSetJacFn(cvode_mem, cvode::cJac); + if (utils::check_flag(&flag, "CVodeSetJacFn", 1)) { + return (1); + } + } else if (udata_g->isolve_type == cvode::sparseDirect) { +#ifdef PELE_USE_KLU + // Set the user-supplied KLU Jacobian routine Jac + flag = CVodeSetJacFn(cvode_mem, cvode::cJac_KLU); + if (utils::check_flag(&flag, "CVodeSetJacFn", 1)) + return (1); +#else + amrex::Abort( + "Shouldn't be there: sparseDirect solver_type not valid without " + "KLU library."); +#endif + } else if (udata_g->isolve_type == cvode::customDirect) { + // Set the user-supplied Jacobian routine Jac + flag = CVodeSetJacFn(cvode_mem, cvode::cJac_sps); + if (utils::check_flag(&flag, "CVodeSetJacFn", 1)) { + return (1); + } + } + } + + // ---------------------------------------------------------- + // Analytical Jac. data for iterative solver preconditioner + if (udata_g->iprecond_type == cvode::denseSimpleAJac) { + // Set the JAcobian-times-vector function + flag = CVSpilsSetJacTimes(cvode_mem, nullptr, nullptr); + if (utils::check_flag(&flag, "CVSpilsSetJacTimes", 1)) { + return (1); + } + // Set the preconditioner plain dense solve and setup functions + flag = CVSpilsSetPreconditioner(cvode_mem, cvode::Precond, cvode::PSolve); + if (utils::check_flag(&flag, "CVSpilsSetPreconditioner", 1)) { + return (1); + } + } else if (udata_g->iprecond_type == cvode::sparseSimpleAJac) { +#ifdef PELE_USE_KLU + // Set the JAcobian-times-vector function + flag = CVSpilsSetJacTimes(cvode_mem, nullptr, nullptr); + if (utils::check_flag(&flag, "CVSpilsSetJacTimes", 1)) + return (1); + // Set the preconditioner KLU sparse solve and setup functions + flag = CVSpilsSetPreconditioner( + cvode_mem, cvode::Precond_sparse, cvode::PSolve_sparse); + if (utils::check_flag(&flag, "CVSpilsSetPreconditioner", 1)) + return (1); +#else + amrex::Abort( + "sparseSimpleAJac precond_type not valid without KLU library."); +#endif + } else if (udata_g->iprecond_type == cvode::customSimpleAJac) { + // Set the JAcobian-times-vector function + flag = CVSpilsSetJacTimes(cvode_mem, nullptr, nullptr); + if (utils::check_flag(&flag, "CVSpilsSetJacTimes", 1)) { + return (1); + } + // Set the preconditioner to custom solve and setup functions + flag = CVSpilsSetPreconditioner( + cvode_mem, cvode::Precond_custom, cvode::PSolve_custom); + if (utils::check_flag(&flag, "CVSpilsSetPreconditioner", 1)) { + return (1); + } + } + + // ---------------------------------------------------------- + // CVODE runtime options + flag = CVodeSetMaxNonlinIters(cvode_mem, 50); // Max newton iter. + if (utils::check_flag(&flag, "CVodeSetMaxNonlinIters", 1)) { + return (1); + } + flag = CVodeSetMaxErrTestFails(cvode_mem, 100); // Max Err.test failure + if (utils::check_flag(&flag, "CVodeSetMaxErrTestFails", 1)) { + return (1); + } + flag = CVodeSetErrHandlerFn( + cvode_mem, cvode::cvodeErrHandler, nullptr); // Err. handler funct. + if (utils::check_flag(&flag, "CVodeSetErrHandlerFn", 1)) { + return (1); + } + flag = CVodeSetMaxNumSteps(cvode_mem, 10000); // Max substeps + if (utils::check_flag(&flag, "CVodeSetMaxNumSteps", 1)) { + return (1); + } + flag = CVodeSetMaxOrd(cvode_mem, udata_g->maxOrder); // Max order + if (utils::check_flag(&flag, "CVodeSetMaxOrd", 1)) { + return (1); + } + flag = CVodeSetJacEvalFrequency(cvode_mem, 100); // Max Jac age + if (utils::check_flag(&flag, "CVodeSetJacEvalFrequency", 1)) { + return (1); + } + + // End of CPU section +#endif + + return (0); +} + +void +ReactorCvode::checkCvodeOptions() const +{ + + // Query options + amrex::ParmParse pp("ode"); + int iverbose = 0; + pp.query("verbose", iverbose); + + if (iverbose > 0) { + amrex::Print() << "Number of species in mech is " << NUM_SPECIES << "\n"; + } + + std::string solve_type_str = "none"; + amrex::ParmParse ppcv("cvode"); + ppcv.query("solve_type", solve_type_str); + int isolve_type = -1; + int ianalytical_jacobian = 0; + int iprecond_type = -1; + +#ifdef AMREX_USE_GPU + if (solve_type_str == "sparse_direct") { + isolve_type = cvode::sparseDirect; + ianalytical_jacobian = 1; +#ifdef AMREX_USE_CUDA + if (iverbose > 0) + amrex::Print() + << " Using a cuSparse direct linear solve with analytical Jacobian\n"; +#else + amrex::Abort("solve_type 'sparse_direct' only available with CUDA"); +#endif + } else if (solve_type_str == "custom_direct") { + isolve_type = cvode::customDirect; + ianalytical_jacobian = 1; +#ifdef AMREX_USE_CUDA + if (iverbose > 0) + amrex::Print() + << " Using a custom direct linear solve with analytical Jacobian\n"; +#else + amrex::Abort("solve_type 'custom_direct' only available with CUDA"); +#endif + } else if (solve_type_str == "magma_direct") { + isolve_type = cvode::magmaDirect; + ianalytical_jacobian = 1; +#ifdef PELE_USE_MAGMA + if (iverbose > 0) + amrex::Print() << " Using MAGMA direct linear solve\n"; +#else + amrex::Abort( + "solve_type 'magma_direct' only available with if PELE_USE_MAGMA true"); +#endif + } else if (solve_type_str == "GMRES") { + isolve_type = cvode::GMRES; + if (iverbose > 0) + amrex::Print() << " Using a JFNK GMRES linear solve\n"; + } else if (solve_type_str == "precGMRES") { + isolve_type = cvode::precGMRES; + if (iverbose > 0) + amrex::Print() << " Using a JFNK GMRES linear solve"; + std::string prec_type_str = "cuSparse_simplified_AJacobian"; + ppcv.query("precond_type", prec_type_str); + if (prec_type_str == "cuSparse_simplified_AJacobian") { + iprecond_type = cvode::sparseSimpleAJac; +#ifdef AMREX_USE_CUDA + amrex::Print() << " with a cuSparse simplified AJ-based preconditioner"; +#else + amrex::Abort( + "precond_type 'cuSparse_simplified_AJacobian' only available with " + "CUDA"); +#endif + } else { + amrex::Abort( + "Wrong precond_type. Only option is: 'cuSparse_simplified_AJacobian'"); + } + amrex::Print() << "\n"; + } else { + amrex::Abort( + "Wrong solve_type. Options are: 'sparse_direct', 'custom_direct', " + "'GMRES', 'precGMRES'"); + } + +#else + if (solve_type_str == "dense_direct") { + isolve_type = cvode::denseFDDirect; + if (iverbose > 0) { + amrex::Print() + << " Using a dense direct linear solve with Finite Difference " + "Jacobian\n"; + } + } else if (solve_type_str == "denseAJ_direct") { + isolve_type = cvode::denseDirect; + ianalytical_jacobian = 1; + if (iverbose > 0) { + amrex::Print() + << " Using a dense direct linear solve with Analytical Jacobian\n"; + } + } else if (solve_type_str == "sparse_direct") { + isolve_type = cvode::sparseDirect; + ianalytical_jacobian = 1; +#ifndef PELE_USE_KLU + amrex::Abort("solver_type sparse_direct requires the KLU library"); +#endif + if (iverbose > 0) { + amrex::Print() + << " Using a sparse direct linear solve with KLU Analytical Jacobian\n"; + } + } else if (solve_type_str == "custom_direct") { + isolve_type = cvode::customDirect; + ianalytical_jacobian = 1; + if (iverbose > 0) { + amrex::Print() + << " Using a sparse custom direct linear solve with Analytical " + "Jacobian\n"; + } + } else if (solve_type_str == "GMRES") { + isolve_type = cvode::GMRES; + if (iverbose > 0) { + amrex::Print() << " Using a JFNK GMRES linear solve\n"; + } + } else if (solve_type_str == "precGMRES") { + isolve_type = cvode::precGMRES; + if (iverbose > 0) { + amrex::Print() << " Using a JFNK GMRES linear solve"; + } + std::string prec_type_str = "none"; + ppcv.query("precond_type", prec_type_str); + if (prec_type_str == "dense_simplified_AJacobian") { + iprecond_type = cvode::denseSimpleAJac; + amrex::Print() << " with a dense simplified AJ-based preconditioner"; + } else if (prec_type_str == "sparse_simplified_AJacobian") { + iprecond_type = cvode::sparseSimpleAJac; +#ifndef PELE_USE_KLU + amrex::Abort( + "precond_type sparse_simplified_AJacobian requires the KLU library"); +#endif + amrex::Print() << " with a sparse simplified AJ-based preconditioner"; + } else if (prec_type_str == "custom_simplified_AJacobian") { + iprecond_type = cvode::customSimpleAJac; + amrex::Print() << " with a custom simplified AJ-based preconditioner"; + } else { + amrex::Abort( + "Wrong precond_type. Options are: 'dense_simplified_AJacobian', " + "'sparse_simplified_AJacobian', 'custom_simplified_AJacobian'"); + } + amrex::Print() << "\n"; + } else if (solve_type_str == "diagnostic") { + isolve_type = cvode::hackDumpSparsePattern; + } else { + amrex::Abort( + "Wrong solve_type. Options are: 'dense_direct', denseAJ_direct', " + "'sparse_direct', 'custom_direct', 'GMRES', 'precGMRES'"); + } +#endif + + // Print additionnal information + if (iprecond_type == cvode::sparseSimpleAJac) { + int nJdata; + const int HP = m_reactor_type == ReactorTypes::h_reactor_type; + // Simplified AJ precond data +#ifdef AMREX_USE_GPU +#if defined(AMREX_USE_CUDA) + SPARSITY_INFO_SYST_SIMPLIFIED(&nJdata, &HP); + if (iverbose > 0) { + amrex::Print() + << "--> cuSparse AJ based matrix Preconditioner -- non zero entries: " + << nJdata << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * 100.0 + << " % fill-in pattern\n"; + } +#elif defined(AMREX_USE_HIP) + amrex::Abort( + "\n--> precond_type sparse simplified_AJacobian not available with " + "HIP \n"); +#endif + +#else + SPARSITY_INFO_SYST_SIMPLIFIED(&nJdata, &HP); + if (iverbose > 0) { + amrex::Print() + << "--> KLU sparse AJ based matrix Preconditioner -- non zero entries: " + << nJdata << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * 100.0 + << " % fill-in pattern\n"; + } +#endif +#ifndef AMREX_USE_GPU + } else if (iprecond_type == cvode::customSimpleAJac) { + int nJdata; + const int HP = m_reactor_type == ReactorTypes::h_reactor_type; + // Simplified AJ precond data + SPARSITY_INFO_SYST_SIMPLIFIED(&nJdata, &HP); + if (iverbose > 0) { + amrex::Print() + << "--> custom sparse AJ based matrix Preconditioner -- non zero " + "entries: " + << nJdata << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * 100.0 + << " % fill-in pattern\n"; + } +#endif + } + + if (ianalytical_jacobian == 1) { + int nJdata; + const int HP = m_reactor_type == ReactorTypes::h_reactor_type; + int Ncells = 1; // Print the pattern of the diagonal block. Ncells will + // actually vary on GPU. +#ifdef AMREX_USE_GPU + if (isolve_type == cvode::sparseDirect) { +#if defined(AMREX_USE_CUDA) + SPARSITY_INFO_SYST(&nJdata, &HP, Ncells); + if (iverbose > 0) { + amrex::Print() + << "--> cuSparse based matrix Solver -- non zero entries: " << nJdata + << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * 100.0 + << " % fill-in pattern\n"; + } +#elif defined(AMREX_USE_HIP) + amrex::Abort("\n--> Analytical Jacobian not available with HIP. Change " + "solve_type.\n"); +#endif + } + +#else + if (isolve_type == cvode::customDirect) { + SPARSITY_INFO_SYST(&nJdata, &HP, Ncells); + if (iverbose > 0) { + amrex::Print() + << "--> sparse AJ-based matrix custom Solver -- non zero entries: " + << nJdata << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * 100.0 + << " % fill-in pattern\n"; + } + } else if (isolve_type == cvode::sparseDirect) { +#ifdef PELE_USE_KLU + SPARSITY_INFO(&nJdata, &HP, Ncells); + if (iverbose > 0) { + amrex::Print() + << "--> KLU sparse AJ-based matrix Solver -- non zero entries: " + << nJdata << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * 100.0 + << " % fill-in pattern\n"; + } +#else + amrex::Abort( + "solver_type 'sparseDirect' uses a sparse KLU matrix and requires " + "the KLU library"); +#endif + } +#endif + } + +#ifndef AMREX_USE_GPU + if (isolve_type == cvode::hackDumpSparsePattern) { + // This is a diagnostic option -> dump sparsity pattern and abort. + // Reactor type + const int HP = m_reactor_type == ReactorTypes::h_reactor_type; + + // CHEMISTRY JAC + int nJdata = 0; + SPARSITY_INFO(&nJdata, &HP, 1); + amrex::Print() << "--> Chem. Jac -- non zero entries: " << nJdata + << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * + 100.0 + << " % fill-in pattern\n"; + SUNMatrix PS; + PS = SUNSparseMatrix((NUM_SPECIES + 1), (NUM_SPECIES + 1), nJdata, CSR_MAT); + int* rowCount = (int*)SUNSparseMatrix_IndexPointers(PS); + int* colIdx = (int*)SUNSparseMatrix_IndexValues(PS); + SPARSITY_PREPROC_CSR(colIdx, rowCount, &HP, 1, 0); + amrex::Print() + << "\n\n *** Treating CHEM Jac (CSR symbolic analysis)*** \n\n"; + int counter = 0; + for (int i = 0; i < NUM_SPECIES + 1; i++) { + int nbVals = rowCount[i + 1] - rowCount[i]; + int* idx_arr = new int[nbVals]; + std::fill_n(idx_arr, nbVals, -1); + std::memcpy(idx_arr, colIdx + rowCount[i], nbVals * sizeof(int)); + int idx = 0; + for (int j = 0; j < NUM_SPECIES + 1; j++) { + if ((j == idx_arr[idx]) && (nbVals > 0)) { + std::cout << 1 << " "; + idx = idx + 1; + counter = counter + 1; + } else { + std::cout << 0 << " "; + } + } + delete[] idx_arr; + std::cout << std::endl; + } + amrex::Print() << " There was " << counter + << " non zero elems (compared to the " << nJdata + << " we need) \n"; + + // SYST JAC + SPARSITY_INFO_SYST(&nJdata, &HP, 1); + amrex::Print() << "--> Syst. Jac -- non zero entries: " << nJdata + << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * + 100.0 + << " % fill-in pattern\n"; + PS = SUNSparseMatrix((NUM_SPECIES + 1), (NUM_SPECIES + 1), nJdata, CSR_MAT); + rowCount = (int*)SUNSparseMatrix_IndexPointers(PS); + colIdx = (int*)SUNSparseMatrix_IndexValues(PS); + SPARSITY_PREPROC_SYST_CSR(colIdx, rowCount, &HP, 1, 1); + amrex::Print() + << "\n\n *** Treating SYST Jac (CSR symbolic analysis)*** \n\n"; + counter = 0; + for (int i = 0; i < NUM_SPECIES + 1; i++) { + int nbVals = rowCount[i + 1] - rowCount[i]; + int* idx_arr = new int[nbVals]; + std::fill_n(idx_arr, nbVals, -1); + std::memcpy(idx_arr, colIdx + (rowCount[i] - 1), nbVals * sizeof(int)); + int idx = 0; + for (int j = 0; j < NUM_SPECIES + 1; j++) { + if ((j == idx_arr[idx] - 1) && ((nbVals - idx) > 0)) { + std::cout << 1 << " "; + idx = idx + 1; + counter = counter + 1; + } else { + std::cout << 0 << " "; + } + } + delete[] idx_arr; + std::cout << std::endl; + } + amrex::Print() << " There was " << counter + << " non zero elems (compared to the " << nJdata + << " we need) \n"; + + // SYST JAC SIMPLIFIED + SPARSITY_INFO_SYST_SIMPLIFIED(&nJdata, &HP); + amrex::Print() + << "--> Simplified Syst Jac (for Precond) -- non zero entries: " << nJdata + << ", which represents " + << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * 100.0 + << " % fill-in pattern\n"; + PS = SUNSparseMatrix((NUM_SPECIES + 1), (NUM_SPECIES + 1), nJdata, CSR_MAT); + rowCount = (int*)SUNSparseMatrix_IndexPointers(PS); + colIdx = (int*)SUNSparseMatrix_IndexValues(PS); + SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(colIdx, rowCount, &HP, 1); + amrex::Print() << "\n\n *** Treating simplified SYST Jac (CSR symbolic " + "analysis)*** \n\n"; + counter = 0; + for (int i = 0; i < NUM_SPECIES + 1; i++) { + int nbVals = rowCount[i + 1] - rowCount[i]; + int* idx_arr = new int[nbVals]; + std::fill_n(idx_arr, nbVals, -1); + std::memcpy(idx_arr, colIdx + (rowCount[i] - 1), nbVals * sizeof(int)); + int idx = 0; + for (int j = 0; j < NUM_SPECIES + 1; j++) { + if ((j == idx_arr[idx] - 1) && ((nbVals - idx) > 0)) { + std::cout << 1 << " "; + idx = idx + 1; + counter = counter + 1; + } else { + std::cout << 0 << " "; + } + } + delete[] idx_arr; + std::cout << std::endl; + } + amrex::Print() << " There was " << counter + << " non zero elems (compared to the " << nJdata + << " we need) \n"; + + amrex::Abort("Chemistry sparsity pattern dumped -> exiting now !"); + } +#endif +} + +void +ReactorCvode::allocUserData( + CVODEUserData* udata, + int a_ncells +#ifdef AMREX_USE_GPU + , + SUNMatrix& a_A, + amrex::gpuStream_t stream +#endif +) const +{ + //---------------------------------------------------------- + // Query options + amrex::ParmParse pp("ode"); + int iverbose = 0; + pp.query("verbose", iverbose); + + std::string solve_type_str = "none"; + amrex::ParmParse ppcv("cvode"); + udata->maxOrder = 2; + ppcv.query("max_order", udata->maxOrder); + ppcv.query("solve_type", solve_type_str); + // Defaults + udata->isolve_type = -1; + udata->ianalytical_jacobian = 0; + udata->iprecond_type = -1; + +#ifdef AMREX_USE_GPU + if (solve_type_str == "sparse_direct") { + udata->isolve_type = cvode::sparseDirect; + udata->ianalytical_jacobian = 1; + } else if (solve_type_str == "custom_direct") { + udata->isolve_type = cvode::customDirect; + udata->ianalytical_jacobian = 1; + } else if (solve_type_str == "magma_direct") { + udata->isolve_type = cvode::magmaDirect; + udata->ianalytical_jacobian = 1; + } else if (solve_type_str == "GMRES") { + udata->isolve_type = cvode::GMRES; + } else if (solve_type_str == "precGMRES") { + udata->isolve_type = cvode::precGMRES; + std::string prec_type_str = "cuSparse_simplified_AJacobian"; + ppcv.query("precond_type", prec_type_str); + if (prec_type_str == "cuSparse_simplified_AJacobian") { + udata->iprecond_type = cvode::sparseSimpleAJac; + } else { + amrex::Abort( + "Wrong precond_type. Only option is: 'cuSparse_simplified_AJacobian'"); + } + amrex::Print() << "\n"; + } else { + amrex::Abort( + "Wrong solve_type. Options are: 'sparse_direct', 'custom_direct', " + "'GMRES', 'precGMRES'"); + } + +#else + if (solve_type_str == "dense_direct") { + udata->isolve_type = cvode::denseFDDirect; + } else if (solve_type_str == "denseAJ_direct") { + udata->isolve_type = cvode::denseDirect; + udata->ianalytical_jacobian = 1; + } else if (solve_type_str == "sparse_direct") { + udata->isolve_type = cvode::sparseDirect; + udata->ianalytical_jacobian = 1; +#ifndef PELE_USE_KLU + amrex::Abort("solver_type sparse_direct requires the KLU library"); +#endif + } else if (solve_type_str == "custom_direct") { + udata->isolve_type = cvode::customDirect; + udata->ianalytical_jacobian = 1; + } else if (solve_type_str == "GMRES") { + udata->isolve_type = cvode::GMRES; + } else if (solve_type_str == "precGMRES") { + udata->isolve_type = cvode::precGMRES; + std::string prec_type_str = "sparse_simplified_AJacobian"; + ppcv.query("precond_type", prec_type_str); + if (prec_type_str == "dense_simplified_AJacobian") { + udata->iprecond_type = cvode::denseSimpleAJac; + } else if (prec_type_str == "sparse_simplified_AJacobian") { + udata->iprecond_type = cvode::sparseSimpleAJac; +#ifndef PELE_USE_KLU + amrex::Abort( + "precond_type sparse_simplified_AJacobian requires the KLU library"); +#endif + } else if (prec_type_str == "custom_simplified_AJacobian") { + udata->iprecond_type = cvode::customSimpleAJac; + } else { + amrex::Abort( + "Wrong precond_type. Options are: 'dense_simplified_AJacobian', " + "'sparse_simplified_AJacobian', 'custom_simplified_AJacobian'"); + } + amrex::Print() << "\n"; + } else { + amrex::Abort( + "Wrong solve_type. Options are: 'dense_direct', denseAJ_direct', " + "'sparse_direct', 'custom_direct', 'GMRES', 'precGMRES'"); + } +#endif + + //---------------------------------------------------------- + // Pass options to udata + const int HP = m_reactor_type == ReactorTypes::h_reactor_type; + int nspec_tot = (NUM_SPECIES)*a_ncells; + udata->ireactor_type = m_reactor_type; + udata->ncells_d = a_ncells; + udata->iverbose = iverbose; +#ifdef AMREX_USE_GPU + udata->nbThreads = 32; + udata->nbBlocks = std::max(1, a_ncells / udata->nbThreads); + udata->stream = stream; +#endif + + //---------------------------------------------------------- + // Alloc internal udata solution/forcing containers + udata->species_ext_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( + nspec_tot * sizeof(amrex::Real)); + udata->energy_init_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( + a_ncells * sizeof(amrex::Real)); + udata->energy_ext_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( + a_ncells * sizeof(amrex::Real)); + udata->mask = (int*)amrex::The_Device_Arena()->alloc(a_ncells * sizeof(int)); + +#ifndef AMREX_USE_GPU + udata->FCunt = (int*)amrex::The_Device_Arena()->alloc(a_ncells * sizeof(int)); + udata->FirstTimePrecond = true; +#endif + + //---------------------------------------------------------- + // Alloc internal udata Analytical Jacobian containers +#ifdef AMREX_USE_GPU + if (udata->isolve_type == cvode::sparseDirect) { +#ifdef AMREX_USE_CUDA + SPARSITY_INFO_SYST(&(udata->NNZ), &HP, 1); + udata->csr_row_count_h = + (int*)amrex::The_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); + udata->csr_col_index_h = + (int*)amrex::The_Arena()->alloc(udata->NNZ * sizeof(int)); + udata->csr_row_count_d = + (int*)amrex::The_Device_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); + udata->csr_col_index_d = + (int*)amrex::The_Device_Arena()->alloc(udata->NNZ * sizeof(int)); + + cusolverStatus_t cusolver_status = CUSOLVER_STATUS_SUCCESS; + cusolver_status = cusolverSpCreate(&(udata->cusolverHandle)); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + cusolver_status = cusolverSpSetStream(udata->cusolverHandle, stream); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + + cusparseStatus_t cusparse_status = CUSPARSE_STATUS_SUCCESS; + cusparse_status = cusparseCreate(&(udata->cuSPHandle)); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); + cusparse_status = cusparseSetStream(udata->cuSPHandle, stream); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); + + a_A = SUNMatrix_cuSparse_NewBlockCSR( + a_ncells, (NUM_SPECIES + 1), (NUM_SPECIES + 1), udata->NNZ, + udata->cuSPHandle); + if (utils::check_flag((void*)a_A, "SUNMatrix_cuSparse_NewBlockCSR", 0)) { + amrex::Abort("Something went wrong while creating cuSparse_NewBlockCSR"); + } + + int retval = SUNMatrix_cuSparse_SetFixedPattern(a_A, 1); + // if (utils::check_flag(&retval, "SUNMatrix_cuSparse_SetFixedPattern", 1)) + // return(1); + + SPARSITY_PREPROC_SYST_CSR( + udata->csr_col_index_h, udata->csr_row_count_h, &HP, 1, 0); + amrex::Gpu::htod_memcpy( + &udata->csr_col_index_d, &udata->csr_col_index_h, + sizeof(udata->csr_col_index_h)); + amrex::Gpu::htod_memcpy( + &udata->csr_row_count_d, &udata->csr_row_count_h, + sizeof(udata->csr_row_count_h)); + SUNMatrix_cuSparse_CopyToDevice( + a_A, NULL, udata->csr_row_count_h, udata->csr_col_index_h); +#else + amrex::Abort( + "Solver_type sparse_direct is only available with CUDA on GPU"); +#endif + } else if (udata->isolve_type == cvode::customDirect) { +#ifdef AMREX_USE_CUDA + SPARSITY_INFO_SYST(&(udata->NNZ), &HP, 1); + udata->csr_row_count_h = + (int*)amrex::The_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); + udata->csr_col_index_h = + (int*)amrex::The_Arena()->alloc(udata->NNZ * sizeof(int)); + udata->csr_row_count_d = + (int*)amrex::The_Device_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); + udata->csr_col_index_d = + (int*)amrex::The_Device_Arena()->alloc(udata->NNZ * sizeof(int)); + + cusparseStatus_t cusparse_status = CUSPARSE_STATUS_SUCCESS; + cusparse_status = cusparseCreate(&(udata->cuSPHandle)); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); + cusparse_status = cusparseSetStream(udata->cuSPHandle, stream); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); + + a_A = SUNMatrix_cuSparse_NewBlockCSR( + a_ncells, (NUM_SPECIES + 1), (NUM_SPECIES + 1), udata->NNZ, + udata->cuSPHandle); + // if (utils::check_flag((void *)a_A, "SUNMatrix_cuSparse_NewBlockCSR", 0)) + // return(1); + + int retval = SUNMatrix_cuSparse_SetFixedPattern(a_A, 1); + // if(utils::check_flag(&retval, "SUNMatrix_cuSparse_SetFixedPattern", 1)) + // return(1); + + SPARSITY_PREPROC_SYST_CSR( + udata->csr_col_index_h, udata->csr_row_count_h, &HP, 1, 0); + amrex::Gpu::htod_memcpy( + &udata->csr_col_index_d, &udata->csr_col_index_h, + sizeof(udata->csr_col_index_h)); + amrex::Gpu::htod_memcpy( + &udata->csr_row_count_d, &udata->csr_row_count_h, + sizeof(udata->csr_row_count_h)); + SUNMatrix_cuSparse_CopyToDevice( + a_A, NULL, udata->csr_row_count_h, udata->csr_col_index_h); +#else + amrex::Abort( + "Solver_type custom_direct is only available with CUDA on GPU"); +#endif + } else if (udata->isolve_type == cvode::magmaDirect) { +#ifdef PELE_USE_MAGMA + a_A = SUNMatrix_MagmaDenseBlock( + a_ncells, (NUM_SPECIES + 1), (NUM_SPECIES + 1), SUNMEMTYPE_DEVICE, + *amrex::sundials::The_SUNMemory_Helper(), NULL); +#else + amrex::Abort("Solver_type magma_direct reauires PELE_USE_MAGMA = TRUE"); +#endif + } + +#else + if (udata->isolve_type == cvode::sparseDirect) { +#ifdef PELE_USE_KLU + // CSC matrices data -> one big matrix used for the direct solve + udata->colPtrs = new int*[1]; + udata->rowVals = new int*[1]; + udata->Jdata = new amrex::Real*[1]; + + // Number of non zero elements in ODE system + SPARSITY_INFO(&(udata->NNZ), &HP, udata->ncells_d); + // Build Sparse Matrix for direct sparse KLU solver + (udata->PS) = new SUNMatrix[1]; + (udata->PS)[0] = SUNSparseMatrix( + (NUM_SPECIES + 1) * udata->ncells_d, (NUM_SPECIES + 1) * udata->ncells_d, + udata->NNZ * udata->ncells_d, CSC_MAT); + udata->colPtrs[0] = (int*)SUNSparseMatrix_IndexPointers((udata->PS)[0]); + udata->rowVals[0] = (int*)SUNSparseMatrix_IndexValues((udata->PS)[0]); + udata->Jdata[0] = SUNSparseMatrix_Data((udata->PS)[0]); + SPARSITY_PREPROC_CSC( + udata->rowVals[0], udata->colPtrs[0], &HP, udata->ncells_d); +#endif + } else if (udata->isolve_type == cvode::customDirect) { + // Number of non zero elements in ODE system + SPARSITY_INFO_SYST(&(udata->NNZ), &HP, udata->ncells_d); + // Build the SUNmatrix as CSR sparse and fill ptrs to row/Vals + udata->PSc = SUNSparseMatrix( + (NUM_SPECIES + 1) * udata->ncells_d, (NUM_SPECIES + 1) * udata->ncells_d, + udata->NNZ * udata->ncells_d, CSR_MAT); + udata->rowPtrs_c = (int*)SUNSparseMatrix_IndexPointers(udata->PSc); + udata->colVals_c = (int*)SUNSparseMatrix_IndexValues(udata->PSc); + SPARSITY_PREPROC_SYST_CSR( + udata->colVals_c, udata->rowPtrs_c, &HP, udata->ncells_d, 0); + } +#endif + + //---------------------------------------------------------- + // Alloc internal udata Preconditioner containers +#ifdef AMREX_USE_GPU + if (udata->iprecond_type == cvode::sparseSimpleAJac) { +#ifdef AMREX_USE_CUDA + SPARSITY_INFO_SYST_SIMPLIFIED(&(udata->NNZ), &HP); + udata->csr_row_count_h = + (int*)amrex::The_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); + udata->csr_col_index_h = + (int*)amrex::The_Arena()->alloc(udata->NNZ * sizeof(int)); + + udata->csr_row_count_d = + (int*)amrex::The_Device_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); + udata->csr_col_index_d = + (int*)amrex::The_Device_Arena()->alloc(udata->NNZ * sizeof(int)); + udata->csr_jac_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( + udata->NNZ * a_ncells * sizeof(amrex::Real)); + udata->csr_val_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( + udata->NNZ * a_ncells * sizeof(amrex::Real)); + + SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR( + udata->csr_col_index_h, udata->csr_row_count_h, &HP, 1); + + amrex::Gpu::htod_memcpy( + &udata->csr_col_index_d, &udata->csr_col_index_h, + sizeof(udata->NNZ * sizeof(int))); + amrex::Gpu::htod_memcpy( + &udata->csr_row_count_d, &udata->csr_row_count_h, + sizeof((NUM_SPECIES + 2) * sizeof(int))); + + size_t workspaceInBytes = 0; + size_t internalDataInBytes = 0; + + cusolverStatus_t cusolver_status = CUSOLVER_STATUS_SUCCESS; + cusolver_status = cusolverSpCreate(&(udata->cusolverHandle)); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + cusolver_status = cusolverSpSetStream(udata->cusolverHandle, stream); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + + cusparseStatus_t cusparse_status = CUSPARSE_STATUS_SUCCESS; + cusparse_status = cusparseCreateMatDescr(&(udata->descrA)); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); + cusparse_status = + cusparseSetMatType(udata->descrA, CUSPARSE_MATRIX_TYPE_GENERAL); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); + cusparse_status = + cusparseSetMatIndexBase(udata->descrA, CUSPARSE_INDEX_BASE_ONE); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); + cusolver_status = cusolverSpCreateCsrqrInfo(&(udata->info)); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + + // symbolic analysis + cusolver_status = cusolverSpXcsrqrAnalysisBatched( + udata->cusolverHandle, + NUM_SPECIES + 1, // size per subsystem + NUM_SPECIES + 1, // size per subsystem + udata->NNZ, udata->descrA, udata->csr_row_count_h, udata->csr_col_index_h, + udata->info); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + + /* + size_t free_mem = 0; + size_t total_mem = 0; + cudaStat1 = cudaMemGetInfo( &free_mem, &total_mem ); + AMREX_ASSERT( cudaSuccess == cudaStat1 ); + std::cout<<"(AFTER SA) Free: "<< free_mem<< " Tot: "<cusolverHandle, + NUM_SPECIES + 1, // size per subsystem + NUM_SPECIES + 1, // size per subsystem + udata->NNZ, udata->descrA, udata->csr_val_d, udata->csr_row_count_h, + udata->csr_col_index_h, a_ncells, udata->info, &internalDataInBytes, + &workspaceInBytes); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + // amrex::Print() << " BufferInfo workspaceInBytes " << workspaceInBytes << + // "\n"; + + cudaError_t cudaStat1 = cudaSuccess; + cudaStat1 = cudaMalloc((void**)&(udata->buffer_qr), workspaceInBytes); + AMREX_ASSERT(cudaStat1 == cudaSuccess); +#else + amrex::Abort( + "cuSparse_simplified_AJacobian is only available with CUDA on GPU"); +#endif + } + +#else + if (udata->iprecond_type == cvode::denseSimpleAJac) { + // Matrix data : big bunch of dimensions, not sure why. Generally ncells == + // 1 so not too bad Simply create the space. + (udata->P) = new amrex::Real***[udata->ncells_d]; + (udata->Jbd) = new amrex::Real***[udata->ncells_d]; + (udata->pivot) = new sunindextype**[udata->ncells_d]; + for (int i = 0; i < udata->ncells_d; ++i) { + (udata->P)[i] = new amrex::Real**[udata->ncells_d]; + (udata->Jbd)[i] = new amrex::Real**[udata->ncells_d]; + (udata->pivot)[i] = new sunindextype*[udata->ncells_d]; + } + for (int i = 0; i < udata->ncells_d; ++i) { + (udata->P)[i][i] = newDenseMat(NUM_SPECIES + 1, NUM_SPECIES + 1); + (udata->Jbd)[i][i] = newDenseMat(NUM_SPECIES + 1, NUM_SPECIES + 1); + (udata->pivot)[i][i] = newIndexArray(NUM_SPECIES + 1); + } + } else if (udata->iprecond_type == cvode::sparseSimpleAJac) { +#ifdef PELE_USE_KLU + // CSC matrices data for each submatrix (cells) + udata->colPtrs = new int*[udata->ncells_d]; + udata->rowVals = new int*[udata->ncells_d]; + udata->Jdata = new amrex::Real*[udata->ncells_d]; + + // KLU internal storage + udata->Common = new klu_common[udata->ncells_d]; + udata->Symbolic = new klu_symbolic*[udata->ncells_d]; + udata->Numeric = new klu_numeric*[udata->ncells_d]; + // Sparse Matrices for It Sparse KLU block-solve + udata->PS = new SUNMatrix[udata->ncells_d]; + // Number of non zero elements + SPARSITY_INFO_SYST_SIMPLIFIED(&(udata->NNZ), &HP); + // Not used yet. TODO use to fetch sparse Mat + udata->indx = new int[udata->NNZ]; + udata->JSPSmat = new amrex::Real*[udata->ncells_d]; + for (int i = 0; i < udata->ncells_d; ++i) { + (udata->PS)[i] = + SUNSparseMatrix(NUM_SPECIES + 1, NUM_SPECIES + 1, udata->NNZ, CSC_MAT); + udata->colPtrs[i] = (int*)SUNSparseMatrix_IndexPointers((udata->PS)[i]); + udata->rowVals[i] = (int*)SUNSparseMatrix_IndexValues((udata->PS)[i]); + udata->Jdata[i] = SUNSparseMatrix_Data((udata->PS)[i]); + // indx not used YET + SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC( + udata->rowVals[i], udata->colPtrs[i], udata->indx, &HP); + udata->JSPSmat[i] = + new amrex::Real[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)]; + klu_defaults(&(udata->Common[i])); + // udata->Common.btf = 0; + //(udata->Common[i]).maxwork = 15; + // udata->Common.ordering = 1; + udata->Symbolic[i] = klu_analyze( + NUM_SPECIES + 1, udata->colPtrs[i], udata->rowVals[i], + &(udata->Common[i])); + } +#endif + } else if (udata->iprecond_type == cvode::customSimpleAJac) { + // CSR matrices data for each submatrix (cells) + udata->colVals = new int*[udata->ncells_d]; + udata->rowPtrs = new int*[udata->ncells_d]; + // Matrices for each sparse custom block-solve + udata->PS = new SUNMatrix[udata->ncells_d]; + udata->JSPSmat = new amrex::Real*[udata->ncells_d]; + // Number of non zero elements + SPARSITY_INFO_SYST_SIMPLIFIED(&(udata->NNZ), &HP); + for (int i = 0; i < udata->ncells_d; ++i) { + (udata->PS)[i] = + SUNSparseMatrix(NUM_SPECIES + 1, NUM_SPECIES + 1, udata->NNZ, CSR_MAT); + udata->rowPtrs[i] = (int*)SUNSparseMatrix_IndexPointers((udata->PS)[i]); + udata->colVals[i] = (int*)SUNSparseMatrix_IndexValues((udata->PS)[i]); + udata->Jdata[i] = SUNSparseMatrix_Data((udata->PS)[i]); + SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR( + udata->colVals[i], udata->rowPtrs[i], &HP, 0); + udata->JSPSmat[i] = + new amrex::Real[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)]; + } + } +#endif +} + +void +ReactorCvode::setCvodeTols(void* a_cvode_mem, CVODEUserData* a_udata) +{ + int omp_thread = 0; +#ifdef AMREX_USE_OMP + omp_thread = omp_get_thread_num(); +#endif + + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + a_udata != nullptr, "Reactor object is not initialized !!"); + + int ncells = a_udata->ncells_d; + int iverbose = a_udata->iverbose; + int neq_tot = (NUM_SPECIES + 1) * ncells; + +#if defined(AMREX_USE_CUDA) + N_Vector atol = N_VNewWithMemHelp_Cuda( + neq_tot, /*use_managed_mem=*/true, + *amrex::sundials::The_SUNMemory_Helper()); + amrex::Real* ratol = N_VGetHostArrayPointer_Cuda(atol); +#elif defined(AMREX_USE_HIP) + N_Vector atol = N_VNewWithMemHelp_Hip( + neq_tot, /*use_managed_mem=*/true, + *amrex::sundials::The_SUNMemory_Helper()); + amrex::Real* ratol = N_VGetHostArrayPointer_Hip(atol); +#else + N_Vector atol = N_VNew_Serial(neq_tot); + amrex::Real* ratol = N_VGetArrayPointer(atol); +#endif + + if (typVals[0] > 0.0) { + if ((iverbose > 0) && (omp_thread == 0)) { + amrex::Print() << " Setting CVODE tolerances with TypVals rtol = " + << relTol << " atolfact = " << absTol + << " in PelePhysics \n"; + } + for (int i = 0; i < ncells; i++) { + int offset = i * (NUM_SPECIES + 1); + for (int k = 0; k < NUM_SPECIES + 1; k++) { + ratol[offset + k] = typVals[k] * absTol; + } + } + } else { + if ((iverbose > 0) && (omp_thread == 0)) { + amrex::Print() << " Setting CVODE tolerances rtol = " << relTol + << " atol = " << absTol << " in PelePhysics \n"; + } + for (int i = 0; i < neq_tot; i++) { + ratol[i] = absTol; + } + } + +#if defined(AMREX_USE_CUDA) + N_VCopyToDevice_Cuda(atol); +#elif defined(AMREX_USE_HIP) + N_VCopyToDevice_Hip(atol); +#endif + + // Call CVodeSVtolerances to specify the scalar relative tolerance + // and vector absolute tolerances + int flag = CVodeSVtolerances(a_cvode_mem, relTol, atol); + if (utils::check_flag(&flag, "CVodeSVtolerances", 1)) { + amrex::Abort("Problem in setCvodeTols"); + } + + N_VDestroy(atol); +} + +int +ReactorCvode::react( + const amrex::Box& box, + amrex::Array4 const& rY_in, + amrex::Array4 const& rY_src_in, + amrex::Array4 const& T_in, + amrex::Array4 const& rEner_in, + amrex::Array4 const& rEner_src_in, + amrex::Array4 const& FC_in, + amrex::Array4 const& mask, + amrex::Real& dt_react, + amrex::Real& time +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif +) +{ + BL_PROFILE("Pele::ReactorCvode::react()"); + // CPU and GPU version are very different such that the entire file + // is split between a GPU region and a CPU region + + amrex::Real time_start = time; + amrex::Real time_final = time + dt_react; + amrex::Real CvodeActual_time_final = 0.0; + + //---------------------------------------------------------- + // GPU Region + //---------------------------------------------------------- +#ifdef AMREX_USE_GPU + int ncells = box.numPts(); + // Total number of eqs. in solve + int neq_tot = (NUM_SPECIES + 1) * ncells; + //---------------------------------------------------------- + // On CPU these lives as class variable and where initialized in + // init() + N_Vector y = NULL; + SUNLinearSolver LS = NULL; + SUNMatrix A = NULL; + void* cvode_mem = NULL; + CVODEUserData* user_data; + + // Fill user_data + amrex::Gpu::streamSynchronize(); + user_data = + (CVODEUserData*)amrex::The_Arena()->alloc(sizeof(struct CVODEUserData)); + allocUserData(user_data, ncells, A, stream); + + //---------------------------------------------------------- + // Solution vector and execution policy +#if defined(AMREX_USE_CUDA) + y = N_VNewWithMemHelp_Cuda( + neq_tot, /*use_managed_mem=*/true, + *amrex::sundials::The_SUNMemory_Helper()); + if (utils::check_flag((void*)y, "N_VNewWithMemHelp_Cuda", 0)) + return (1); + SUNCudaExecPolicy* stream_exec_policy = + new SUNCudaThreadDirectExecPolicy(256, stream); + SUNCudaExecPolicy* reduce_exec_policy = + new SUNCudaBlockReduceExecPolicy(256, 0, stream); + N_VSetKernelExecPolicy_Cuda(y, stream_exec_policy, reduce_exec_policy); + amrex::Real* yvec_d = N_VGetDeviceArrayPointer_Cuda(y); + +#elif defined(AMREX_USE_HIP) + y = N_VNewWithMemHelp_Hip( + neq_tot, /*use_managed_mem=*/true, + *amrex::sundials::The_SUNMemory_Helper()); + if (utils::check_flag((void*)y, "N_VNewWithMemHelp_Hip", 0)) + return (1); + SUNHipExecPolicy* stream_exec_policy = + new SUNHipThreadDirectExecPolicy(256, stream); + SUNHipExecPolicy* reduce_exec_policy = + new SUNHipBlockReduceExecPolicy(256, 0, stream); + N_VSetKernelExecPolicy_Hip(y, stream_exec_policy, reduce_exec_policy); + amrex::Real* yvec_d = N_VGetDeviceArrayPointer_Hip(y); +#endif + + // Fill data + flatten( + box, ncells, rY_in, rY_src_in, T_in, rEner_in, rEner_src_in, yvec_d, + user_data->species_ext_d, user_data->energy_init_d, + user_data->energy_ext_d); + +#ifdef AMREX_USE_OMP + Gpu::Device::streamSynchronize(); +#endif + + //---------------------------------------------------------- + // Setup Cvode object + cvode_mem = CVodeCreate(CV_BDF); + if (utils::check_flag((void*)cvode_mem, "CVodeCreate", 0)) + return (1); + int flag = CVodeSetUserData(cvode_mem, static_cast(user_data)); + + // Call CVodeInit to initialize the integrator memory and specify the + // user's right hand side function, the inital time, and + // initial dependent variable vector y. + flag = CVodeInit(cvode_mem, cF_RHS, time_start, y); + if (utils::check_flag(&flag, "CVodeInit", 1)) + return (1); + + //---------------------------------------------------------- + // Setup tolerances with typical values + setCvodeTols(cvode_mem, user_data); + + // ---------------------------------------------------------- + // Linear solver data + if (user_data->isolve_type == cvode::sparseDirect) { +#if defined(AMREX_USE_CUDA) + LS = SUNLinSol_cuSolverSp_batchQR(y, A, user_data->cusolverHandle); + if (utils::check_flag((void*)LS, "SUNLinSol_cuSolverSp_batchQR", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); + +#else + amrex::Abort( + "Shoudn't be there. solve_type sparse_direct only available with CUDA"); +#endif + } else if (user_data->isolve_type == cvode::customDirect) { +#if defined(AMREX_USE_CUDA) + LS = cvode::SUNLinSol_dense_custom(y, A, stream); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); + + flag = CVodeSetJacFn(cvode_mem, cvode::cJac); + if (utils::check_flag(&flag, "CVodeSetJacFn", 1)) + return (1); +#else + amrex::Abort( + "Shoudn't be there. solve_type custom_direct only available with CUDA"); +#endif + } else if (user_data->isolve_type == cvode::magmaDirect) { +#ifdef PELE_USE_MAGMA + LS = SUNLinSol_MagmaDense(y, A); + if (utils::check_flag((void*)LS, "SUNLinSol_MagmaDense", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); +#else + amrex::Abort( + "Shoudn't be there. solve_type magma_direct only available with " + "PELE_USE_MAGMA = TRUE"); +#endif + } else if (user_data->isolve_type == cvode::GMRES) { + LS = SUNLinSol_SPGMR(y, PREC_NONE, 0); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, NULL); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); + flag = CVodeSetJacTimes(cvode_mem, NULL, NULL); + if (utils::check_flag(&flag, "CVodeSetJacTimes", 1)) + return (1); + } else if (user_data->isolve_type == cvode::precGMRES) { + LS = SUNLinSol_SPGMR(y, PREC_LEFT, 0); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, NULL); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); + flag = CVodeSetJacTimes(cvode_mem, NULL, NULL); + if (utils::check_flag(&flag, "CVodeSetJacTimes", 1)) + return (1); + } + + // ---------------------------------------------------------- + // Analytical Jac. data for direct solver + // Sparse/custom/magma direct uses the same Jacobian functions + if (user_data->ianalytical_jacobian == 1) { + flag = CVodeSetJacFn(cvode_mem, cvode::cJac); + if (utils::check_flag(&flag, "CVodeSetJacFn", 1)) + return (1); + } + + // ---------------------------------------------------------- + // Analytical Jac. data for iterative solver preconditioner + if (user_data->iprecond_type == cvode::sparseSimpleAJac) { + flag = CVodeSetPreconditioner(cvode_mem, cvode::Precond, cvode::PSolve); + if (utils::check_flag(&flag, "CVodeSetPreconditioner", 1)) + return (1); + } + + // ---------------------------------------------------------- + // CVODE runtime options + flag = CVodeSetMaxNumSteps(cvode_mem, 100000); + if (utils::check_flag(&flag, "CVodeSetMaxNumSteps", 1)) + return (1); + flag = CVodeSetMaxOrd(cvode_mem, user_data->maxOrder); + if (utils::check_flag(&flag, "CVodeSetMaxOrd", 1)) + return (1); + + // ---------------------------------------------------------- + // Actual CVODE solve + BL_PROFILE_VAR("Pele::ReactorCvode::react():CVode", AroundCVODE); + flag = CVode(cvode_mem, time_final, y, &CvodeActual_time_final, CV_NORMAL); + if (utils::check_flag(&flag, "CVode", 1)) + return (1); + BL_PROFILE_VAR_STOP(AroundCVODE); + +#ifdef MOD_REACTOR + dt_react = + time_start - CvodeActual_time_final; // Actual dt_react performed by Cvode + time += dt_react; // Increment time in reactor mode +#endif + +#ifdef AMREX_USE_OMP + Gpu::Device::streamSynchronize(); +#endif + + // Get workload estimate + long int nfe; + flag = CVodeGetNumRhsEvals(cvode_mem, &nfe); + + amrex::Gpu::DeviceVector v_nfe(ncells, nfe); + long int* d_nfe = v_nfe.data(); + unflatten( + box, ncells, rY_in, T_in, rEner_in, rEner_src_in, FC_in, yvec_d, + user_data->energy_init_d, d_nfe, dt_react); + + if (user_data->iverbose > 1) { + cvode::printFinalStats(cvode_mem); + } + + //---------------------------------------------------------- + // Clean up + N_VDestroy(y); + CVodeFree(&cvode_mem); + + SUNLinSolFree(LS); + if (A != nullptr) { + SUNMatDestroy(A); + } + freeUserData(user_data); + + //---------------------------------------------------------- + // CPU Region + //---------------------------------------------------------- +#else + + int omp_thread = 0; +#ifdef AMREX_USE_OMP + omp_thread = omp_get_thread_num(); +#endif + + // Update TypicalValues + setCvodeTols(cvode_mem, udata_g); + + // Perform integration one cell at a time + const int icell = 0; + const int ncells = 1; + const auto captured_reactor_type = m_reactor_type; + ParallelFor( + box, [=, &CvodeActual_time_final] AMREX_GPU_DEVICE( + int i, int j, int k) noexcept { + if (mask(i, j, k) != -1) { + + amrex::Real* yvec_d = N_VGetArrayPointer(y); + utils::box_flatten( + icell, i, j, k, ncells, captured_reactor_type, rY_in, rY_src_in, T_in, + rEner_in, rEner_src_in, yvec_d, udata_g->species_ext_d, + udata_g->energy_init_d, udata_g->energy_ext_d); + + // ReInit CVODE is faster + CVodeReInit(cvode_mem, time_start, y); + + BL_PROFILE_VAR("Pele::ReactorCvode::react():CVode", AroundCVODE); + CVode(cvode_mem, time_final, y, &CvodeActual_time_final, CV_NORMAL); + BL_PROFILE_VAR_STOP(AroundCVODE); + + if ((udata_g->iverbose > 1) && (omp_thread == 0)) { + amrex::Print() << "Additional verbose info --\n"; + cvode::printFinalStats(cvode_mem); + amrex::Print() << "\n -------------------------------------\n"; + } + + amrex::Real actual_dt = CvodeActual_time_final - time_start; + + // Get estimate of how hard the integration process was + long int nfe = 0; + long int nfeLS = 0; + CVodeGetNumRhsEvals(cvode_mem, &nfe); + CVodeGetNumLinRhsEvals(cvode_mem, &nfeLS); + const long int nfe_tot = nfe + nfeLS; + + utils::box_unflatten( + icell, i, j, k, ncells, captured_reactor_type, rY_in, T_in, rEner_in, + rEner_src_in, FC_in, yvec_d, udata_g->energy_init_d, nfe_tot, + dt_react); + + if ((udata_g->iverbose > 3) && (omp_thread == 0)) { + amrex::Print() << "END : time curr is " << CvodeActual_time_final + << " and actual dt_react is " << actual_dt << "\n"; + } + } else { + FC_in(i, j, k, 0) = 0.0; + } + }); + +#ifdef MOD_REACTOR + dt_react = + time_start - + time_final; // In this case, assumes all individual CVODE calls nailed it. + time += dt_react; // Increment time in reactor mode +#endif + + long int nfe = + 20; // Dummy, the return value is no longer used for this function. +#endif + + return nfe; +} + +int +ReactorCvode::react( + realtype* rY_in, + realtype* rY_src_in, + realtype* rX_in, + realtype* rX_src_in, + realtype& dt_react, + realtype& time, + int Ncells +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif +) +{ + BL_PROFILE("Pele::ReactorCvode::react()"); + + // CPU and GPU version are very different such that the entire file + // is split between a GPU region and a CPU region + + amrex::Real time_start = time; + amrex::Real time_final = time + dt_react; + amrex::Real CvodeActual_time_final = 0.0; + + //---------------------------------------------------------- + // GPU Region + //---------------------------------------------------------- +#ifdef AMREX_USE_GPU + int neq_tot = (NUM_SPECIES + 1) * Ncells; + N_Vector y = NULL; + SUNLinearSolver LS = NULL; + SUNMatrix A = NULL; + void* cvode_mem = NULL; + CVODEUserData* user_data; + + // Fill user_data + amrex::Gpu::streamSynchronize(); + user_data = + (CVODEUserData*)amrex::The_Arena()->alloc(sizeof(struct CVODEUserData)); + allocUserData(user_data, Ncells, A, stream); + + //---------------------------------------------------------- + // Solution vector and execution policy +#if defined(AMREX_USE_CUDA) + y = N_VNewWithMemHelp_Cuda( + neq_tot, /*use_managed_mem=*/true, + *amrex::sundials::The_SUNMemory_Helper()); + if (utils::check_flag((void*)y, "N_VNewWithMemHelp_Cuda", 0)) + return (1); + SUNCudaExecPolicy* stream_exec_policy = + new SUNCudaThreadDirectExecPolicy(256, stream); + SUNCudaExecPolicy* reduce_exec_policy = + new SUNCudaBlockReduceExecPolicy(256, 0, stream); + N_VSetKernelExecPolicy_Cuda(y, stream_exec_policy, reduce_exec_policy); + amrex::Real* yvec_d = N_VGetDeviceArrayPointer_Cuda(y); + +#elif defined(AMREX_USE_HIP) + y = N_VNewWithMemHelp_Hip( + neq_tot, /*use_managed_mem=*/true, + *amrex::sundials::The_SUNMemory_Helper()); + if (utils::check_flag((void*)y, "N_VNewWithMemHelp_Hip", 0)) + return (1); + SUNHipExecPolicy* stream_exec_policy = + new SUNHipThreadDirectExecPolicy(256, stream); + SUNHipExecPolicy* reduce_exec_policy = + new SUNHipBlockReduceExecPolicy(256, 0, stream); + N_VSetKernelExecPolicy_Hip(y, stream_exec_policy, reduce_exec_policy); + amrex::Real* yvec_d = N_VGetDeviceArrayPointer_Hip(y); +#endif + + // Fill data + BL_PROFILE_VAR("Pele::ReactorCvode::react():ASyncCopy", AsyncCopy); + amrex::Gpu::htod_memcpy_async(yvec_d, rY_in, sizeof(amrex::Real) * (neq_tot)); + amrex::Gpu::htod_memcpy_async( + user_data->species_ext_d, rY_src_in, + sizeof(amrex::Real) * NUM_SPECIES * Ncells); + amrex::Gpu::htod_memcpy_async( + user_data->energy_init_d, rX_in, sizeof(amrex::Real) * Ncells); + amrex::Gpu::htod_memcpy_async( + user_data->energy_ext_d, rX_src_in, sizeof(amrex::Real) * Ncells); + BL_PROFILE_VAR_STOP(AsyncCopy); + +#ifdef AMREX_USE_OMP + Gpu::Device::streamSynchronize(); +#endif + + // ------------------------------------------------------------- + // Initialize integrator + cvode_mem = CVodeCreate(CV_BDF); + if (utils::check_flag((void*)cvode_mem, "CVodeCreate", 0)) + return (1); + int flag = CVodeSetUserData(cvode_mem, static_cast(user_data)); + + // Call CVodeInit to initialize the integrator memory and specify the + // user's right hand side function, the inital time, and + // initial dependent variable vector y. + flag = CVodeInit(cvode_mem, cF_RHS, time_start, y); + if (utils::check_flag(&flag, "CVodeInit", 1)) + return (1); + + //---------------------------------------------------------- + // Setup tolerances with typical values + setCvodeTols(cvode_mem, user_data); + + // ---------------------------------------------------------- + // Linear solver data + if (user_data->isolve_type == cvode::sparseDirect) { +#if defined(AMREX_USE_CUDA) + LS = SUNLinSol_cuSolverSp_batchQR(y, A, user_data->cusolverHandle); + if (utils::check_flag((void*)LS, "SUNLinSol_cuSolverSp_batchQR", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); + +#else + amrex::Abort( + "Shoudn't be there. solve_type sparse_direct only available with CUDA"); +#endif + } else if (user_data->isolve_type == cvode::customDirect) { +#if defined(AMREX_USE_CUDA) + LS = cvode::SUNLinSol_dense_custom(y, A, stream); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); + + flag = CVodeSetJacFn(cvode_mem, cvode::cJac); + if (utils::check_flag(&flag, "CVodeSetJacFn", 1)) + return (1); +#else + amrex::Abort( + "Shoudn't be there. solve_type custom_direct only available with CUDA"); +#endif + } else if (user_data->isolve_type == cvode::magmaDirect) { +#ifdef PELE_USE_MAGMA + LS = SUNLinSol_MagmaDense(y, A); + if (utils::check_flag((void*)LS, "SUNLinSol_MagmaDense", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, A); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); +#else + amrex::Abort( + "Shoudn't be there. solve_type magma_direct only available with " + "PELE_USE_MAGMA = TRUE"); +#endif + } else if (user_data->isolve_type == cvode::GMRES) { + LS = SUNLinSol_SPGMR(y, PREC_NONE, 0); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, NULL); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); + flag = CVodeSetJacTimes(cvode_mem, NULL, NULL); + if (utils::check_flag(&flag, "CVodeSetJacTimes", 1)) + return (1); + } else if (user_data->isolve_type == cvode::precGMRES) { + LS = SUNLinSol_SPGMR(y, PREC_LEFT, 0); + if (utils::check_flag((void*)LS, "SUNDenseLinearSolver", 0)) + return (1); + flag = CVodeSetLinearSolver(cvode_mem, LS, NULL); + if (utils::check_flag(&flag, "CVodeSetLinearSolver", 1)) + return (1); + flag = CVodeSetJacTimes(cvode_mem, NULL, NULL); + if (utils::check_flag(&flag, "CVodeSetJacTimes", 1)) + return (1); + } + + // ---------------------------------------------------------- + // Analytical Jac. data for direct solver + // Both sparse/custom direct uses the same Jacobian functions + if (user_data->ianalytical_jacobian == 1) { + flag = CVodeSetJacFn(cvode_mem, cvode::cJac); + if (utils::check_flag(&flag, "CVodeSetJacFn", 1)) + return (1); + } + + // ---------------------------------------------------------- + // Analytical Jac. data for iterative solver preconditioner + if (user_data->iprecond_type == cvode::sparseSimpleAJac) { + flag = CVodeSetPreconditioner(cvode_mem, cvode::Precond, cvode::PSolve); + if (utils::check_flag(&flag, "CVodeSetPreconditioner", 1)) + return (1); + } + + // ---------------------------------------------------------- + // CVODE runtime options + flag = CVodeSetMaxNumSteps(cvode_mem, 100000); + if (utils::check_flag(&flag, "CVodeSetMaxNumSteps", 1)) + return (1); + flag = CVodeSetMaxOrd(cvode_mem, user_data->maxOrder); + if (utils::check_flag(&flag, "CVodeSetMaxOrd", 1)) + return (1); + + // ---------------------------------------------------------- + // Actual CVODE solve + BL_PROFILE_VAR("Pele::ReactorCvode::react():CVode", AroundCVODE); + flag = CVode(cvode_mem, time_final, y, &CvodeActual_time_final, CV_NORMAL); + if (utils::check_flag(&flag, "CVode", 1)) + return (1); + BL_PROFILE_VAR_STOP(AroundCVODE); + +#ifdef MOD_REACTOR + dt_react = + time_start - CvodeActual_time_final; // Actual dt_react performed by Cvode + time += dt_react; // Increment time in reactor mode +#endif + +#ifdef AMREX_USE_OMP + Gpu::Device::streamSynchronize(); +#endif + + // ------------------------------------------------------------- + // Get the result back + BL_PROFILE_VAR_START(AsyncCopy); + amrex::Gpu::dtoh_memcpy_async(rY_in, yvec_d, sizeof(amrex::Real) * neq_tot); + for (int i = 0; i < Ncells; i++) { + rX_in[i] = rX_in[i] + dt_react * rX_src_in[i]; + } + BL_PROFILE_VAR_STOP(AsyncCopy); + + // ------------------------------------------------------------- + // Get the number of RHS evaluations + long int nfe; + flag = CVodeGetNumRhsEvals(cvode_mem, &nfe); + if (user_data->iverbose > 1) { + cvode::printFinalStats(cvode_mem); + } + + //---------------------------------------------------------- + // Clean up + N_VDestroy(y); + CVodeFree(&cvode_mem); + + SUNLinSolFree(LS); + if (A != nullptr) { + SUNMatDestroy(A); + } + freeUserData(user_data); + + //---------------------------------------------------------- + // CPU Region + //---------------------------------------------------------- +#else + int omp_thread = 0; +#ifdef AMREX_USE_OMP + omp_thread = omp_get_thread_num(); +#endif + + // Pointer of solution vector + amrex::Real* yvec_d = N_VGetArrayPointer(y); + std::memcpy( + yvec_d, rY_in, sizeof(amrex::Real) * ((NUM_SPECIES + 1) * Ncells)); + std::memcpy( + udata_g->species_ext_d, rY_src_in, + sizeof(amrex::Real) * (NUM_SPECIES * Ncells)); + std::memcpy(udata_g->energy_init_d, rX_in, sizeof(amrex::Real) * Ncells); + std::memcpy(udata_g->energy_ext_d, rX_src_in, sizeof(amrex::Real) * Ncells); + + // ReInit CVODE is faster + CVodeReInit(cvode_mem, time_start, y); + + BL_PROFILE_VAR("Pele::react():CVode", AroundCVODE); + int flag = + CVode(cvode_mem, time_final, y, &CvodeActual_time_final, CV_NORMAL); + // ONE STEP MODE FOR DEBUGGING + // flag = CVode(cvode_mem, time_final, y, &CvodeActual_time_final, + // CV_ONE_STEP); + if (utils::check_flag(&flag, "CVode", 1)) { + return (1); + } + BL_PROFILE_VAR_STOP(AroundCVODE); + + // Update TypicalValues + setCvodeTols(cvode_mem, udata_g); + +#ifdef MOD_REACTOR + dt_react = + time_start - CvodeActual_time_final; // Actual dt_react performed by Cvode + time += dt_react; // Increment time in reactor mode +#endif + + // Pack data to return in main routine external + std::memcpy( + rY_in, yvec_d, sizeof(amrex::Real) * ((NUM_SPECIES + 1) * Ncells)); + for (int i = 0; i < Ncells; i++) { + rX_in[i] = rX_in[i] + dt_react * rX_src_in[i]; + } + + if ((udata_g->iverbose > 1) && (omp_thread == 0)) { + amrex::Print() << "Additional verbose info --\n"; + cvode::printFinalStats(cvode_mem); + amrex::Print() << "\n -------------------------------------\n"; + } + + // Get estimate of how hard the integration process was + long int nfe, nfeLS; + flag = CVodeGetNumRhsEvals(cvode_mem, &nfe); + flag = CVodeGetNumLinRhsEvals(cvode_mem, &nfeLS); + nfe += nfeLS; +#endif + + return nfe; +} + +int +ReactorCvode::cF_RHS( + realtype t, N_Vector y_in, N_Vector ydot_in, void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::cF_RHS()"); +#if defined(AMREX_USE_CUDA) + amrex::Real* yvec_d = N_VGetDeviceArrayPointer_Cuda(y_in); + amrex::Real* ydot_d = N_VGetDeviceArrayPointer_Cuda(ydot_in); +#elif defined(AMREX_USE_HIP) + amrex::Real* yvec_d = N_VGetDeviceArrayPointer_Hip(y_in); + amrex::Real* ydot_d = N_VGetDeviceArrayPointer_Hip(ydot_in); +#else + amrex::Real* yvec_d = N_VGetArrayPointer(y_in); + amrex::Real* ydot_d = N_VGetArrayPointer(ydot_in); +#endif + + auto* udata = static_cast(user_data); + udata->dt_save = t; + + auto ncells = udata->ncells_d; + auto dt_save = udata->dt_save; + auto reactor_type = udata->ireactor_type; + auto* energy_init = udata->energy_init_d; + auto* energy_ext = udata->energy_ext_d; + auto* species_ext = udata->species_ext_d; + amrex::ParallelFor(ncells, [=] AMREX_GPU_DEVICE(int icell) noexcept { + utils::fKernelSpec( + icell, ncells, dt_save, reactor_type, yvec_d, ydot_d, energy_init, + energy_ext, species_ext); + }); + amrex::Gpu::Device::streamSynchronize(); + return 0; +} + +void +ReactorCvode::SetTypValsODE(const std::vector& ExtTypVals) +{ + int size_ETV = ExtTypVals.size(); + amrex::Vector kname; + pele::physics::eos::speciesNames(kname); + int omp_thread = 0; + +#ifdef _OPENMP + omp_thread = omp_get_thread_num(); +#endif + + for (int i = 0; i < size_ETV - 1; i++) { + typVals[i] = ExtTypVals[i]; + } + typVals[size_ETV - 1] = ExtTypVals[size_ETV - 1]; + + if (omp_thread == 0) { + amrex::Print() << "Set the typVals in PelePhysics: \n "; + for (int i = 0; i < size_ETV - 1; i++) { + amrex::Print() << kname[i] << ":" << typVals[i] << " "; + } + amrex::Print() << "Temp:" << typVals[size_ETV - 1] << " \n"; + } +} + +void +ReactorCvode::freeUserData(CVODEUserData* data_wk) +{ + amrex::The_Device_Arena()->free(data_wk->species_ext_d); + amrex::The_Device_Arena()->free(data_wk->energy_init_d); + amrex::The_Device_Arena()->free(data_wk->energy_ext_d); + amrex::The_Device_Arena()->free(data_wk->mask); + +#ifdef AMREX_USE_GPU + + if (data_wk->isolve_type == cvode::sparseDirect) { +#ifdef AMREX_USE_CUDA + amrex::The_Arena()->free(data_wk->csr_row_count_h); + amrex::The_Arena()->free(data_wk->csr_col_index_h); + cusolverStatus_t cusolver_status = + cusolverSpDestroy(data_wk->cusolverHandle); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + cusparseStatus_t cusparse_status = cusparseDestroy(data_wk->cuSPHandle); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); +#endif + } else if (data_wk->isolve_type == cvode::customDirect) { +#ifdef AMREX_USE_CUDA + amrex::The_Arena()->free(data_wk->csr_row_count_h); + amrex::The_Arena()->free(data_wk->csr_col_index_h); + cusparseStatus_t cusparse_status = cusparseDestroy(data_wk->cuSPHandle); + AMREX_ASSERT(cusparse_status == CUSPARSE_STATUS_SUCCESS); +#endif + } + // Preconditioner analytical Jacobian data + if (data_wk->iprecond_type == cvode::sparseSimpleAJac) { +#ifdef AMREX_USE_CUDA + amrex::The_Arena()->free(data_wk->csr_row_count_h); + amrex::The_Arena()->free(data_wk->csr_col_index_h); + amrex::The_Device_Arena()->free(data_wk->csr_val_d); + amrex::The_Device_Arena()->free(data_wk->csr_jac_d); + cusolverStatus_t cusolver_status = + cusolverSpDestroy(data_wk->cusolverHandle); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + cusolver_status = cusolverSpDestroyCsrqrInfo(data_wk->info); + AMREX_ASSERT(cusolver_status == CUSOLVER_STATUS_SUCCESS); + cudaFree(data_wk->buffer_qr); +#endif + } + amrex::The_Device_Arena()->free(data_wk); + +#else + amrex::The_Device_Arena()->free(data_wk->FCunt); + + // Direct solver Jac. data + if (data_wk->isolve_type == cvode::sparseDirect) { +#ifdef PELE_USE_KLU + delete[] data_wk->colPtrs; + delete[] data_wk->rowVals; + delete[] data_wk->Jdata; + SUNMatDestroy(A); + SUNMatDestroy((data_wk->PS)[0]); + delete[](data_wk->PS); +#endif + } else if (data_wk->isolve_type == cvode::customDirect) { + SUNMatDestroy(A); + SUNMatDestroy(data_wk->PSc); + } + + // Preconditionner Jac. data + if (data_wk->iprecond_type == cvode::denseSimpleAJac) { + for (int i = 0; i < data_wk->ncells_d; ++i) { + destroyMat((data_wk->P)[i][i]); + destroyMat((data_wk->Jbd)[i][i]); + destroyArray((data_wk->pivot)[i][i]); + } + for (int i = 0; i < data_wk->ncells_d; ++i) { + delete[](data_wk->P)[i]; + delete[](data_wk->Jbd)[i]; + delete[](data_wk->pivot)[i]; + } + delete[](data_wk->P); + delete[](data_wk->Jbd); + delete[](data_wk->pivot); + } else if (data_wk->iprecond_type == cvode::sparseSimpleAJac) { +#ifdef PELE_USE_KLU + delete[] data_wk->colPtrs; + delete[] data_wk->rowVals; + delete[] data_wk->Jdata; + for (int i = 0; i < data_wk->ncells_d; ++i) { + klu_free_symbolic(&(data_wk->Symbolic[i]), &(data_wk->Common[i])); + klu_free_numeric(&(data_wk->Numeric[i]), &(data_wk->Common[i])); + delete[] data_wk->JSPSmat[i]; + SUNMatDestroy((data_wk->PS)[i]); + } + delete[] data_wk->JSPSmat; + delete[] data_wk->Common; + delete[] data_wk->Symbolic; + delete[] data_wk->Numeric; + delete[] data_wk->PS; +#endif + } else if (data_wk->iprecond_type == cvode::customSimpleAJac) { + for (int i = 0; i < data_wk->ncells_d; ++i) { + delete[] data_wk->JSPSmat[i]; + SUNMatDestroy((data_wk->PS)[i]); + } + delete[] data_wk->colVals; + delete[] data_wk->rowPtrs; + delete[] data_wk->PS; + delete[] data_wk->JSPSmat; + } + + free(data_wk); +#endif +} + +void +ReactorCvode::close() +{ +#ifndef AMREX_USE_GPU + CVodeFree(&cvode_mem); + SUNLinSolFree(LS); + + if (udata_g->isolve_type == cvode::denseDirect) { + SUNMatDestroy(A); + } + + N_VDestroy(y); + freeUserData(udata_g); +#endif +} + +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorCvodeCustomLinSolver.H b/Reactions/ReactorCvodeCustomLinSolver.H new file mode 100644 index 000000000..12c0cf69c --- /dev/null +++ b/Reactions/ReactorCvodeCustomLinSolver.H @@ -0,0 +1,79 @@ +#ifndef _REACTORCVODECUSTOMLINSOLVER_H_ +#define _REACTORCVODECUSTOMLINSOLVER_H_ + +#include +#include +#include +#include +#include +#include +#include +#ifdef AMREX_USE_CUDA +#include +#include +#include +#endif +#include "mechanism.H" + +namespace pele { +namespace physics { +namespace reactions { +namespace cvode { +#ifdef AMREX_USE_GPU +struct _SUNLinearSolverContent_Dense_custom +{ + sunindextype last_flag; + int nsubsys; + int subsys_size; + int subsys_nnz; + int nbBlocks; + int nbThreads; + amrex::gpuStream_t stream; +}; + +typedef struct _SUNLinearSolverContent_Dense_custom* + SUNLinearSolverContent_Dense_custom; + +SUNLinearSolver +SUNLinSol_dense_custom(N_Vector y, SUNMatrix A, amrex::gpuStream_t stream); + +SUNLinearSolver_Type SUNLinSolGetType_Dense_custom(SUNLinearSolver S); + +int SUNLinSolSolve_Dense_custom( + SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, amrex::Real tol); + +int SUNLinSolSetup_Dense_custom(SUNLinearSolver S, SUNMatrix A); + +int SUNLinSolFree_Dense_custom(SUNLinearSolver S); + +#else +struct _SUNLinearSolverContent_Sparse_custom +{ + sunindextype last_flag; + int reactor_type; + int nsubsys; // number of subsystems + int subsys_size; // size of each subsystem + int subsys_nnz; +}; + +typedef struct _SUNLinearSolverContent_Sparse_custom* + SUNLinearSolverContent_Sparse_custom; + +SUNLinearSolver SUNLinSol_sparse_custom( + N_Vector y, + SUNMatrix A, + int reactor_type, + int nsubsys, + int subsys_size, + int subsys_nnz); + +SUNLinearSolver_Type SUNLinSolGetType_Sparse_custom(SUNLinearSolver S); + +int SUNLinSolSolve_Sparse_custom( + SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, amrex::Real tol); +#endif +} // namespace cvode +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorCvodeCustomLinSolver.cpp b/Reactions/ReactorCvodeCustomLinSolver.cpp new file mode 100644 index 000000000..7089dfb7f --- /dev/null +++ b/Reactions/ReactorCvodeCustomLinSolver.cpp @@ -0,0 +1,257 @@ +#include "ReactorCvodeCustomLinSolver.H" + +namespace pele { +namespace physics { +namespace reactions { +namespace cvode { + +#ifdef AMREX_USE_GPU + +#define SUN_CUSP_CONTENT(S) ((SUNLinearSolverContent_Dense_custom)(S->content)) +#define SUN_CUSP_SUBSYS_SIZE(S) (SUN_CUSP_CONTENT(S)->subsys_size) +#define SUN_CUSP_NUM_SUBSYS(S) (SUN_CUSP_CONTENT(S)->nsubsys) +#define SUN_CUSP_SUBSYS_NNZ(S) (SUN_CUSP_CONTENT(S)->subsys_nnz) + +#define SUN_CUSP_LASTFLAG(S) (SUN_CUSP_CONTENT(S)->last_flag) +#define SUN_CUSP_STREAM(S) (SUN_CUSP_CONTENT(S)->stream) +#define SUN_CUSP_NBLOCK(S) (SUN_CUSP_CONTENT(S)->nbBlocks) +#define SUN_CUSP_NTHREAD(S) (SUN_CUSP_CONTENT(S)->nbThreads) + +// The following are only available with Cuda +#ifdef AMREX_USE_CUDA +SUNLinearSolver +SUNLinSol_dense_custom(N_Vector y, SUNMatrix A, cudaStream_t stream) +{ + if (y == NULL || A == NULL) + return (NULL); + + if (N_VGetVectorID(y) != SUNDIALS_NVEC_CUDA) + return (NULL); + if (SUNMatGetID(A) != SUNMATRIX_CUSPARSE) + return (NULL); + + if (N_VGetLength(y) != SUNMatrix_cuSparse_Columns(A)) + return (NULL); + + if (!N_VIsManagedMemory_Cuda(y)) + return (NULL); + + SUNLinearSolver S; + S = NULL; + S = SUNLinSolNewEmpty(); + if (S == NULL) { + return (NULL); + } + + S->ops->gettype = SUNLinSolGetType_Dense_custom; + S->ops->setup = SUNLinSolSetup_Dense_custom; + S->ops->solve = SUNLinSolSolve_Dense_custom; + S->ops->free = SUNLinSolFree_Dense_custom; + + SUNLinearSolverContent_Dense_custom content; + content = NULL; + content = (SUNLinearSolverContent_Dense_custom)malloc(sizeof *content); + if (content == NULL) { + SUNLinSolFree(S); + return (NULL); + } + + S->content = content; + + content->last_flag = 0; + content->nsubsys = SUNMatrix_cuSparse_NumBlocks(A); + content->subsys_size = SUNMatrix_cuSparse_BlockRows(A); + content->subsys_nnz = SUNMatrix_cuSparse_BlockNNZ(A); + content->nbBlocks = std::max(1, content->nsubsys / 32); + content->nbThreads = 32; + content->stream = stream; + + return (S); +} + +SUNLinearSolver_Type +SUNLinSolGetType_Dense_custom(SUNLinearSolver S) +{ + return (SUNLINEARSOLVER_DIRECT); +} + +int +SUNLinSolSetup_Dense_custom(SUNLinearSolver S, SUNMatrix A) +{ + return (SUNLS_SUCCESS); +} + +int +SUNLinSolSolve_Dense_custom( + SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, amrex::Real tol) +{ + cudaError_t cuda_status = cudaSuccess; + + amrex::Real* x_d = N_VGetDeviceArrayPointer_Cuda(x); + amrex::Real* b_d = N_VGetDeviceArrayPointer_Cuda(b); + + amrex::Real* d_data = SUNMatrix_cuSparse_Data(A); + + BL_PROFILE_VAR("fKernelDenseSolve()", fKernelDenseSolve); + const auto ec = amrex::Gpu::ExecutionConfig(SUN_CUSP_NUM_SUBSYS(S)); + // TODO: why is this AMREX version NOT working ? + // launch_global<<>>( + // [=] AMREX_GPU_DEVICE () noexcept { + // for (int icell = blockDim.x*blockIdx.x+threadIdx.x, stride = + // blockDim.x*gridDim.x; + // icell < SUN_CUSP_NUM_SUBSYS(S); icell += stride) { + // fKernelDenseSolve(icell, x_d, b_d, + // SUN_CUSP_SUBSYS_SIZE(S), SUN_CUSP_SUBSYS_NNZ(S), data_d); + // } + // }); + // fKernelDenseSolve<<>>( + // SUN_CUSP_NUM_SUBSYS(S), x_d, b_d, SUN_CUSP_SUBSYS_SIZE(S), + // SUN_CUSP_SUBSYS_NNZ(S), d_data); + + cuda_status = cudaStreamSynchronize(SUN_CUSP_STREAM(S)); + AMREX_ASSERT(cuda_status == cudaSuccess); + + BL_PROFILE_VAR_STOP(fKernelDenseSolve); + + return (SUNLS_SUCCESS); +} + +int +SUNLinSolFree_Dense_custom(SUNLinearSolver S) +{ + if (S == NULL) + return (SUNLS_SUCCESS); + + if (S->content) { + free(S->content); + S->content = NULL; + } + + if (S->ops) { + free(S->ops); + S->ops = NULL; + } + + free(S); + S = NULL; + + return (SUNLS_SUCCESS); +} +#endif + +#else + +#define SUN_CUSP_CONTENT(S) ((SUNLinearSolverContent_Sparse_custom)(S->content)) +#define SUN_CUSP_REACTYPE(S) (SUN_CUSP_CONTENT(S)->reactor_type) +#define SUN_CUSP_NUM_SUBSYS(S) (SUN_CUSP_CONTENT(S)->nsubsys) +#define SUN_CUSP_SUBSYS_NNZ(S) (SUN_CUSP_CONTENT(S)->subsys_nnz) +#define SUN_CUSP_SUBSYS_SIZE(S) (SUN_CUSP_CONTENT(S)->subsys_size) + +SUNLinearSolver +SUNLinSol_sparse_custom( + N_Vector a_y, + SUNMatrix a_A, + int reactor_type, + int nsubsys, + int subsys_size, + int subsys_nnz) +{ + SUNLinearSolver S; + SUNLinearSolverContent_Sparse_custom content; + + // Check that required arguments are not NULL + if (a_y == nullptr || a_A == nullptr) { + return (nullptr); + } + if (SUNMatGetID(a_A) != SUNMATRIX_SPARSE) { + return (nullptr); + } + + // Matrix should be square + if (SUNSparseMatrix_Columns(a_A) != SUNSparseMatrix_Rows(a_A)) { + return (nullptr); + } + + // Check that it is a CSR matrix + if (SUNSparseMatrix_SparseType(a_A) != CSR_MAT) { + return (nullptr); + } + + // Matrix and vector dimensions must agree + if (N_VGetLength(a_y) != SUNSparseMatrix_Columns(a_A)) { + return (nullptr); + } + + // All subsystems must be the same size + if (SUNSparseMatrix_Columns(a_A) != (subsys_size * nsubsys)) { + return (nullptr); + } + + // Number of nonzeros per subsys must be the same + if (SUNSparseMatrix_NNZ(a_A) != (subsys_nnz * nsubsys)) { + return (nullptr); + } + + // Create an empty linear solver + S = SUNLinSolNewEmpty(); + if (S == nullptr) { + return (nullptr); + } + + // Attach operations + S->ops->gettype = SUNLinSolGetType_Sparse_custom; + S->ops->solve = SUNLinSolSolve_Sparse_custom; + + // Create content + content = (SUNLinearSolverContent_Sparse_custom)malloc(sizeof *content); + if (content == nullptr) { + SUNLinSolFree(S); + return (nullptr); + } + + // Attach content + S->content = content; + + // Fill content + content->last_flag = 0; + content->reactor_type = reactor_type; + content->nsubsys = nsubsys; + content->subsys_size = subsys_size; + content->subsys_nnz = subsys_nnz; + + return (S); +} + +SUNLinearSolver_Type SUNLinSolGetType_Sparse_custom(SUNLinearSolver /* S */) +{ + return (SUNLINEARSOLVER_DIRECT); +} + +int +SUNLinSolSolve_Sparse_custom( + SUNLinearSolver S, SUNMatrix a_A, N_Vector x, N_Vector b, amrex::Real /*tol*/) +{ + BL_PROFILE("Pele::GaussSolver()"); + amrex::Real* x_d = N_VGetArrayPointer(x); + amrex::Real* b_d = N_VGetArrayPointer(b); + + auto* Data = (amrex::Real*)SUNSparseMatrix_Data(a_A); + + for (int tid = 0; tid < SUN_CUSP_NUM_SUBSYS(S); tid++) { + int offset = tid * SUN_CUSP_SUBSYS_NNZ(S); + int offset_RHS = tid * SUN_CUSP_SUBSYS_SIZE(S); + amrex::Real* Data_offset = Data + offset; + amrex::Real* x_d_offset = x_d + offset_RHS; + amrex::Real* b_d_offset = b_d + offset_RHS; + sgjsolve(Data_offset, x_d_offset, b_d_offset); + } + + return (SUNLS_SUCCESS); +} +#endif +} // namespace cvode +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorCvodeJacobian.H b/Reactions/ReactorCvodeJacobian.H new file mode 100644 index 000000000..482055ccc --- /dev/null +++ b/Reactions/ReactorCvodeJacobian.H @@ -0,0 +1,64 @@ +#ifndef _REACTORCVODEJACOBIAN_H_ +#define _REACTORCVODEJACOBIAN_H_ + +#include +#include +#include +#include +#include "PelePhysics.H" +#include "mechanism.H" +#include "ReactorTypes.H" +#include "ReactorCvodeUtils.H" + +#ifdef AMREX_USE_HIP +#include +#endif + +#ifdef AMREX_USE_CUDA +#include +#include +#include +#endif + +namespace pele { +namespace physics { +namespace reactions { +namespace cvode { +int cJac( + amrex::Real tn, + N_Vector u, + N_Vector fy, + SUNMatrix J, + void* user_data, + N_Vector tmp1, + N_Vector tmp2, + N_Vector tmp3); + +#ifndef AMREX_USE_GPU +int cJac_sps( + amrex::Real tn, + N_Vector u, + N_Vector fy, + SUNMatrix J, + void* user_data, + N_Vector tmp1, + N_Vector tmp2, + N_Vector tmp3); + +#ifdef PELE_USE_KLU +int cJac_KLU( + amrex::Real tn, + N_Vector y, + N_Vector fy, + SUNMatrix J, + void* user_data, + N_Vector tmp1, + N_Vector tmp2, + N_Vector tmp3); +#endif +#endif +} // namespace cvode +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorCvodeJacobian.cpp b/Reactions/ReactorCvodeJacobian.cpp new file mode 100644 index 000000000..57129125e --- /dev/null +++ b/Reactions/ReactorCvodeJacobian.cpp @@ -0,0 +1,343 @@ +#include "ReactorCvodeJacobian.H" + +namespace pele { +namespace physics { +namespace reactions { +namespace cvode { +#ifdef AMREX_USE_GPU +int +cJac( + amrex::Real /*t*/, + N_Vector y_in, + N_Vector /*fy*/, + SUNMatrix J, + void* user_data, + N_Vector /*tmp1*/, + N_Vector /*tmp2*/, + N_Vector /*tmp3*/) +{ + BL_PROFILE("Pele::ReactorCvode::cJac()"); + CVODEUserData* udata = static_cast(user_data); + auto solveType = udata->isolve_type; + auto ncells = udata->ncells_d; + auto NNZ = udata->NNZ; + auto stream = udata->stream; + auto nbThreads = udata->nbThreads; + auto nbBlocks = udata->nbBlocks; + + if (solveType == sparseDirect) { +#ifdef AMREX_USE_CUDA + amrex::Real* yvec_d = N_VGetDeviceArrayPointer_Cuda(y_in); + amrex::Real* Jdata = SUNMatrix_cuSparse_Data(J); + + // Checks + if ( + (SUNMatrix_cuSparse_Rows(J) != (NUM_SPECIES + 1) * ncells) || + (SUNMatrix_cuSparse_Columns(J) != (NUM_SPECIES + 1) * ncells) || + (SUNMatrix_cuSparse_NNZ(J) != ncells * NNZ)) { + amrex::Print() << "Jac error: matrix is wrong size!\n"; + return 1; + } + + const auto ec = amrex::Gpu::ExecutionConfig(ncells); + amrex::launch_global<<>>( + [=] AMREX_GPU_DEVICE() noexcept { + for (int icell = blockDim.x * blockIdx.x + threadIdx.x, + stride = blockDim.x * gridDim.x; + icell < ncells; icell += stride) { + fKernelComputeAJchem(icell, user_data, yvec_d, Jdata); + } + }); + cudaError_t cuda_status = cudaStreamSynchronize(stream); + AMREX_ASSERT(cuda_status == cudaSuccess); +#else + amrex::Abort( + "Calling cJac with solve_type = sparse_direct only works with CUDA !"); +#endif + } else if (solveType == magmaDirect) { +#ifdef PELE_USE_MAGMA + amrex::Real* yvec_d = N_VGetDeviceArrayPointer(y_in); + amrex::Real* Jdata = SUNMatrix_MagmaDense_Data(J); + const auto ec = Gpu::ExecutionConfig(ncells); + launch_global<<>>( + [=] AMREX_GPU_DEVICE() noexcept { + for (int icell = blockDim.x * blockIdx.x + threadIdx.x, + stride = blockDim.x * gridDim.x; + icell < ncells; icell += stride) { + fKernelDenseAJchem(icell, user_data, yvec_d, Jdata); + } + }); + amrex::Gpu::Device::streamSynchronize(); +#else + amrex::Abort( + "Calling cJac with solve_type = magma_direct reauires PELE_USE_MAGMA = " + "TRUE !"); +#endif + } + + return (0); +} + +#else + +int +cJac( + amrex::Real /* tn */, + N_Vector u, + N_Vector /* fu */, + SUNMatrix J, + void* user_data, + N_Vector /* tmp1 */, + N_Vector /* tmp2 */, + N_Vector /* tmp3 */) +{ + BL_PROFILE("Pele::ReactorCvode::cJacDense()"); + + // Make local copies of pointers to input data + amrex::Real* ydata = N_VGetArrayPointer(u); + + // Make local copies of pointers in user_data + auto* udata = static_cast(user_data); + auto ncells = udata->ncells_d; + auto reactor_type = udata->ireactor_type; + + for (int tid = 0; tid < ncells; tid++) { + // Offset in case several cells + int offset = tid * (NUM_SPECIES + 1); + + // MW CGS + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + // rho MKS + amrex::Real rho = 0.0; + for (int i = 0; i < NUM_SPECIES; i++) { + rho = rho + ydata[offset + i]; + } + + amrex::Real temp = ydata[offset + NUM_SPECIES]; + + amrex::Real massfrac[NUM_SPECIES] = {0.0}; + // Yks + for (int i = 0; i < NUM_SPECIES; i++) { + massfrac[i] = ydata[offset + i] / rho; + } + + // Jac + amrex::Real Jmat_tmp[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)] = {0.0}; + const int consP = reactor_type == ReactorTypes::h_reactor_type; + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2JAC(rho, temp, massfrac, Jmat_tmp, consP); + + // fill the sunMat and scale + for (int i = 0; i < NUM_SPECIES; i++) { + amrex::Real* J_col = SM_COLUMN_D(J, offset + i); + for (int k = 0; k < NUM_SPECIES; k++) { + J_col[offset + k] = Jmat_tmp[i * (NUM_SPECIES + 1) + k] * mw[k] / mw[i]; + } + J_col[offset + NUM_SPECIES] = + Jmat_tmp[i * (NUM_SPECIES + 1) + NUM_SPECIES] / mw[i]; + } + amrex::Real* J_col = SM_COLUMN_D(J, offset + NUM_SPECIES); + for (int i = 0; i < NUM_SPECIES; i++) { + J_col[offset + i] = Jmat_tmp[NUM_SPECIES * (NUM_SPECIES + 1) + i] * mw[i]; + } + J_col = SM_COLUMN_D(J, offset); + } + + return (0); +} + +// Analytical SPARSE CSR Jacobian evaluation +int +cJac_sps( + amrex::Real /* tn */, + N_Vector u, + N_Vector /* fu */, + SUNMatrix J, + void* user_data, + N_Vector /* tmp1 */, + N_Vector /* tmp2 */, + N_Vector /* tmp3 */) +{ + BL_PROFILE("Pele::ReactorCvode::cJacSparse()"); + // Make local copies of pointers to input data + amrex::Real* ydata = N_VGetArrayPointer(u); + + // Make local copies of pointers in user_data (cell M)*/ + auto* udata = static_cast(user_data); + auto NNZ = udata->NNZ; + auto reactor_type = udata->ireactor_type; + auto ncells = udata->ncells_d; + auto* colVals_c = udata->colVals_c; + auto* rowPtrs_c = udata->rowPtrs_c; + + // MW CGS + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + sunindextype* rowPtrs_tmp = SUNSparseMatrix_IndexPointers(J); + sunindextype* colIndx_tmp = SUNSparseMatrix_IndexValues(J); + amrex::Real* Jdata = SUNSparseMatrix_Data(J); + // Fixed colVal + for (int i = 0; i < NNZ * ncells; i++) { + colIndx_tmp[i] = (sunindextype)colVals_c[i]; + } + rowPtrs_tmp[0] = (sunindextype)rowPtrs_c[0]; + // Fixed rowPtrs + for (int i = 0; i < ncells * (NUM_SPECIES + 1); i++) { + rowPtrs_tmp[i + 1] = (sunindextype)rowPtrs_c[i + 1]; + } + + // Temp vectors + // Save Jac from cell to cell if more than one + amrex::Real temp_save_lcl = 0.0; + for (int tid = 0; tid < ncells; tid++) { + // Offset in case several cells + int offset = tid * (NUM_SPECIES + 1); + int offset_J = tid * NNZ; + // rho MKS + amrex::Real rho = 0.0; + for (int i = 0; i < NUM_SPECIES; i++) { + rho = rho + ydata[offset + i]; + } + // Yks + amrex::Real massfrac[NUM_SPECIES] = {0.0}; + amrex::Real rhoinv = 1.0 / rho; + for (int i = 0; i < NUM_SPECIES; i++) { + massfrac[i] = ydata[offset + i] * rhoinv; + } + amrex::Real temp = ydata[offset + NUM_SPECIES]; + + // Do we recompute Jac ? + amrex::Real Jmat_tmp[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)] = {0.0}; + if (fabs(temp - temp_save_lcl) > 1.0) { + const int consP = reactor_type == ReactorTypes::h_reactor_type; + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2JAC(rho, temp, massfrac, Jmat_tmp, consP); + temp_save_lcl = temp; + // rescale + for (int i = 0; i < NUM_SPECIES; i++) { + for (int k = 0; k < NUM_SPECIES; k++) { + Jmat_tmp[k * (NUM_SPECIES + 1) + i] *= mw[i] / mw[k]; + } + Jmat_tmp[i * (NUM_SPECIES + 1) + NUM_SPECIES] /= mw[i]; + } + for (int i = 0; i < NUM_SPECIES; i++) { + Jmat_tmp[NUM_SPECIES * (NUM_SPECIES + 1) + i] *= mw[i]; + } + } + // Go from Dense to Sparse + for (int i = 1; i < NUM_SPECIES + 2; i++) { + int nbVals = rowPtrs_c[i] - rowPtrs_c[i - 1]; + for (int j = 0; j < nbVals; j++) { + int idx = colVals_c[rowPtrs_c[i - 1] + j]; + Jdata[offset_J + rowPtrs_c[i - 1] + j] = + Jmat_tmp[(i - 1) + (NUM_SPECIES + 1) * idx]; + } + } + } + + return (0); +} + +#ifdef PELE_USE_KLU +// Analytical SPARSE KLU CSC Jacobian evaluation +int +cJac_KLU( + amrex::Real /* tn */, + N_Vector u, + N_Vector /* fu */, + SUNMatrix J, + void* user_data, + N_Vector /* tmp1 */, + N_Vector /* tmp2 */, + N_Vector /* tmp3 */) +{ + BL_PROFILE("Pele::ReactorCvode::cJacSparseKLU()"); + + // Make local copies of pointers to input data + amrex::Real* ydata = N_VGetArrayPointer(u); + + // Make local copies of pointers in user_data (cell M) + CVODEUserData* udata = static_cast(user_data); + auto NNZ = udata->NNZ; + auto reactor_type = udata->ireactor_type; + auto ncells = udata->ncells_d; + auto colPtrs = udata->colPtrs; + auto rowVals = udata->rowVals; + + // MW CGS + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + // Fixed RowVals + sunindextype* colptrs_tmp = SUNSparseMatrix_IndexPointers(J); + sunindextype* rowvals_tmp = SUNSparseMatrix_IndexValues(J); + amrex::Real* Jdata = SUNSparseMatrix_Data(J); + for (int i = 0; i < NNZ; i++) { + rowvals_tmp[i] = rowVals[0][i]; + } + // Fixed colPtrs + colptrs_tmp[0] = colPtrs[0][0]; + for (int i = 0; i < ncells * (NUM_SPECIES + 1); i++) { + colptrs_tmp[i + 1] = colPtrs[0][i + 1]; + } + + // Save Jac from cell to cell if more than one + amrex::Real temp_save_lcl = 0.0; + for (int tid = 0; tid < ncells; tid++) { + // Offset in case several cells + int offset = tid * (NUM_SPECIES + 1); + // rho + amrex::Real rho = 0.0; + for (int i = 0; i < NUM_SPECIES; i++) { + rho = rho + ydata[offset + i]; + } + // Yks + amrex::Real massfrac[NUM_SPECIES] = {0.0}; + amrex::Real rhoinv = 1.0 / rho; + for (int i = 0; i < NUM_SPECIES; i++) { + massfrac[i] = ydata[offset + i] * rhoinv; + } + amrex::Real temp = ydata[offset + NUM_SPECIES]; + + // Do we recompute Jac ? + amrex::Real Jmat_tmp[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)] = {0.0}; + if (fabs(temp - temp_save_lcl) > 1.0) { + const int consP = reactor_type == ReactorTypes::h_reactor_type; + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2JAC(rho, temp, massfrac, Jmat_tmp, consP); + temp_save_lcl = temp; + // rescale + for (int i = 0; i < NUM_SPECIES; i++) { + for (int k = 0; k < NUM_SPECIES; k++) { + Jmat_tmp[k * (NUM_SPECIES + 1) + i] *= mw[i] / mw[k]; + } + Jmat_tmp[i * (NUM_SPECIES + 1) + NUM_SPECIES] /= mw[i]; + } + for (int i = 0; i < NUM_SPECIES; i++) { + Jmat_tmp[NUM_SPECIES * (NUM_SPECIES + 1) + i] *= mw[i]; + } + } + // Go from Dense to Sparse + BL_PROFILE_VAR("DensetoSps", DtoS); + for (int i = 1; i < NUM_SPECIES + 2; i++) { + int nbVals = colPtrs[0][i] - colPtrs[0][i - 1]; + for (int j = 0; j < nbVals; j++) { + int idx = rowVals[0][colPtrs[0][i - 1] + j]; + Jdata[colPtrs[0][offset + i - 1] + j] = + Jmat_tmp[(i - 1) * (NUM_SPECIES + 1) + idx]; + } + } + BL_PROFILE_VAR_STOP(DtoS); + } + + return (0); +} +#endif +#endif +} // namespace cvode +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorCvodePreconditioner.H b/Reactions/ReactorCvodePreconditioner.H new file mode 100644 index 000000000..1235401b9 --- /dev/null +++ b/Reactions/ReactorCvodePreconditioner.H @@ -0,0 +1,93 @@ +#ifndef _REACTORCVODEPRECONDITIONER_H_ +#define _REACTORCVODEPRECONDITIONER_H_ + +#include +#include +#include +#include "PelePhysics.H" +#include "mechanism.H" +#include "ReactorCvodeUtils.H" + +#ifdef AMREX_USE_HIP +#include +#endif + +#ifdef AMREX_USE_CUDA +#include +#endif + +namespace pele { +namespace physics { +namespace reactions { +namespace cvode { +// Basic preconditioner functions +int Precond( + amrex::Real tn, + N_Vector u, + N_Vector fu, + booleantype jok, + booleantype* jcurPtr, + amrex::Real gamma, + void* user_data); + +int PSolve( + amrex::Real tn, + N_Vector u, + N_Vector fu, + N_Vector r, + N_Vector z, + amrex::Real gamma, + amrex::Real delta, + int lr, + void* user_data); + +#ifndef AMREX_USE_GPU +// Custom SGS preconditioner functions +int PSolve_custom( + amrex::Real tn, + N_Vector u, + N_Vector fu, + N_Vector r, + N_Vector z, + amrex::Real gamma, + amrex::Real delta, + int lr, + void* user_data); + +int Precond_custom( + amrex::Real tn, + N_Vector u, + N_Vector fu, + booleantype jok, + booleantype* jcurPtr, + amrex::Real gamma, + void* user_data); + +#ifdef PELE_USE_KLU +// KLU preconditioner functions +int PSolve_sparse( + amrex::Real tn, + N_Vector u, + N_Vector fu, + N_Vector r, + N_Vector z, + amrex::Real gamma, + amrex::Real delta, + int lr, + void* user_data); + +int Precond_sparse( + amrex::Real tn, + N_Vector u, + N_Vector fu, + booleantype jok, + booleantype* jcurPtr, + amrex::Real gamma, + void* user_data); +#endif +#endif +} // namespace cvode +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorCvodePreconditioner.cpp b/Reactions/ReactorCvodePreconditioner.cpp new file mode 100644 index 000000000..e2e944725 --- /dev/null +++ b/Reactions/ReactorCvodePreconditioner.cpp @@ -0,0 +1,639 @@ +#include "ReactorCvodePreconditioner.H" + +namespace pele { +namespace physics { +namespace reactions { +namespace cvode { +#ifdef AMREX_USE_GPU +#ifdef AMREX_USE_CUDA +int +Precond( + amrex::Real /*tn*/, + N_Vector u, + N_Vector /*fu*/, + booleantype jok, + booleantype* jcurPtr, + amrex::Real gamma, + void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::Precond()"); + + amrex::Real* u_d = N_VGetDeviceArrayPointer_Cuda(u); + + CVODEUserData* udata = static_cast(user_data); + udata->gamma = gamma; + + // Get data out of udata to minimize global memory access + auto ncells = udata->ncells_d; + auto stream = udata->stream; + auto nbThreads = udata->nbThreads; + auto nbBlocks = udata->nbBlocks; + auto csr_val_d = udata->csr_val_d; + auto csr_row_count_d = udata->csr_row_count_d; + auto csr_col_index_d = udata->csr_col_index_d; + auto NNZ = udata->NNZ; + + BL_PROFILE_VAR("Pele::ReactorCvode::fKernelComputeAJ()", fKernelComputeAJ); + if (jok) { + const auto ec = amrex::Gpu::ExecutionConfig(ncells); + amrex::launch_global<<>>( + [=] AMREX_GPU_DEVICE() noexcept { + for (int icell = blockDim.x * blockIdx.x + threadIdx.x, + stride = blockDim.x * gridDim.x; + icell < ncells; icell += stride) { + fKernelComputeAJsys(icell, user_data, u_d, csr_val_d); + } + }); + *jcurPtr = SUNFALSE; + } else { + const auto ec = amrex::Gpu::ExecutionConfig(ncells); + amrex::launch_global<<>>( + [=] AMREX_GPU_DEVICE() noexcept { + for (int icell = blockDim.x * blockIdx.x + threadIdx.x, + stride = blockDim.x * gridDim.x; + icell < ncells; icell += stride) { + fKernelComputeallAJ(icell, user_data, u_d, csr_val_d); + } + }); + *jcurPtr = SUNTRUE; + } + cudaError_t cuda_status = cudaStreamSynchronize(stream); + AMREX_ASSERT(cuda_status == cudaSuccess); + BL_PROFILE_VAR_STOP(fKernelComputeAJ); + + /* + Somehow this function crash when called again after Psolve + but is it really necessary ? The code solver behaves well ... + BL_PROFILE_VAR("InfoBatched(inPrecond)", InfoBatched); + size_t workspaceInBytes = 0; + size_t internalDataInBytes = 0; + cusolverStatus_t cuS_st = CUSOLVER_STATUS_SUCCESS; + cuS_st = cusolverSpDcsrqrBufferInfoBatched(udata->cusolverHandle, + NUM_SPECIES + 1, NUM_SPECIES + 1, + NNZ, udata->descrA, csr_val_d, + csr_row_count_d, csr_col_index_d, + ncells, udata->info, + &internalDataInBytes, + &workspaceInBytes); + Print() << " BufferInfo workspaceInBytes " << workspaceInBytes << "\n"; + AMREX_ASSERT(cuS_st == CUSOLVER_STATUS_SUCCESS); + */ + + cuda_status = cudaDeviceSynchronize(); + AMREX_ASSERT(cuda_status == cudaSuccess); + return (0); +} + +int +PSolve( + amrex::Real /*tn*/, + N_Vector /*u*/, + N_Vector /*fu*/, + N_Vector r, + N_Vector z, + amrex::Real /*gamma*/, + amrex::Real /*delta*/, + int /*lr*/, + void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::PSolve()"); + + // Get data out of udata to minimize global memory access + CVODEUserData* udata = static_cast(user_data); + auto ncells = udata->ncells_d; + auto csr_val_d = udata->csr_val_d; + auto csr_row_count_d = udata->csr_row_count_d; + auto csr_col_index_d = udata->csr_col_index_d; + auto NNZ = udata->NNZ; + + amrex::Real* z_d = N_VGetDeviceArrayPointer_Cuda(z); + amrex::Real* r_d = N_VGetDeviceArrayPointer_Cuda(r); + + cusolverStatus_t cuS_st = CUSOLVER_STATUS_SUCCESS; + cuS_st = cusolverSpDcsrqrsvBatched( + udata->cusolverHandle, NUM_SPECIES + 1, NUM_SPECIES + 1, NNZ, udata->descrA, + csr_val_d, csr_row_count_d, csr_col_index_d, r_d, z_d, ncells, udata->info, + udata->buffer_qr); + AMREX_ASSERT(cuS_st == CUSOLVER_STATUS_SUCCESS); + + cudaError_t cuda_status = cudaDeviceSynchronize(); + AMREX_ASSERT(cuda_status == cudaSuccess); + + N_VCopyFromDevice_Cuda(z); + N_VCopyFromDevice_Cuda(r); + + /* + // Checks + // if (udata->iverbose > 4) { + for(int batchId = 0 ; batchId < ncells; batchId++){ + // measure |bj - Aj*xj| + realtype *csrValAj = (udata->csr_val_d) + batchId * (udata->NNZ); + double *xj = N_VGetHostArrayPointer_Cuda(z) + batchId * + (NUM_SPECIES+1); double *bj = + N_VGetHostArrayPointer_Cuda(r) + batchId * (NUM_SPECIES+1); + // sup| bj - Aj*xj| + double sup_res = 0; + for(int row = 0 ; row < (NUM_SPECIES+1) ; row++){ + printf("\n row %d: ", row); + const int start = udata->csr_row_count_d[row] - 1; + const int end = udata->csr_row_count_d[row +1] - 1; + double Ax = 0.0; // Aj(row,:)*xj + for(int colidx = start ; colidx < end ; colidx++){ + const int col = udata->csr_col_index_d[colidx] - 1; + const double Areg = csrValAj[colidx]; + const double xreg = xj[col]; + printf(" (%d, %14.8e, %14.8e, %14.8e) ", + col,Areg,xreg,bj[row] ); Ax = Ax + Areg * xreg; + } + double rresidi = bj[row] - Ax; + sup_res = (sup_res > fabs(rresidi))? sup_res : fabs(rresidi); + } + printf("batchId %d: sup|bj - Aj*xj| = %E \n", batchId, sup_res); + } + //} + */ + + return (0); +} + +#else + +int +Precond( + amrex::Real /* tn */, + N_Vector /* u */, + N_Vector /* fu */, + booleantype /* jok */, + booleantype* /* jcurPtr */, + amrex::Real /* gamma */, + void* /* user_data */) +{ + amrex::Abort("Only implemented for CUDA."); + return 1; +} + +int +PSolve( + amrex::Real /* tn */, + N_Vector /* u */, + N_Vector /* fu */, + N_Vector /* r */, + N_Vector /* z */, + amrex::Real /* gamma */, + amrex::Real /* delta */, + int /* lr */, + void* /* user_data */) +{ + amrex::Abort("Only implemented for CUDA."); + return 1; +} + +#endif + +#else + +// Preconditioner setup routine for GMRES solver when no sparse mode is +// activated Generate and preprocess P +int +Precond( + amrex::Real /* tn */, + N_Vector u, + N_Vector /* fu */, + booleantype jok, + booleantype* jcurPtr, + amrex::Real gamma, + void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::Precond()"); + // Make local copies of pointers to input data + amrex::Real* u_d = N_VGetArrayPointer(u); + + // Make local copies of pointers in user_data + auto* udata = static_cast(user_data); + auto reactor_type = udata->ireactor_type; + auto* P = udata->P; + auto* Jbd = udata->Jbd; + auto* pivot = udata->pivot; + + // MW CGS + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + if (jok) { + // jok = SUNTRUE: Copy Jbd to P + denseCopy(Jbd[0][0], P[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1); + *jcurPtr = SUNFALSE; + } else { + // rho MKS + amrex::Real rho = 0.0; + for (int i = 0; i < NUM_SPECIES; i++) { + rho = rho + u_d[i]; + } + // Yks + amrex::Real massfrac[NUM_SPECIES] = {0.0}; + amrex::Real rhoinv = 1.0 / rho; + for (int i = 0; i < NUM_SPECIES; i++) { + massfrac[i] = u_d[i] * rhoinv; + } + amrex::Real temp = u_d[NUM_SPECIES]; + // Activities + amrex::Real activity[NUM_SPECIES] = {0.0}; + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2C(rho, temp, massfrac, activity); + int consP = reactor_type == ReactorTypes::h_reactor_type; + amrex::Real Jmat[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)] = {0.0}; + DWDOT_SIMPLIFIED(Jmat, activity, &temp, &consP); + + // Scale Jacobian. Load into P. + denseScale(0.0, Jbd[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1); + for (int i = 0; i < NUM_SPECIES; i++) { + for (int k = 0; k < NUM_SPECIES; k++) { + (Jbd[0][0])[k][i] = Jmat[k * (NUM_SPECIES + 1) + i] * mw[i] / mw[k]; + } + (Jbd[0][0])[i][NUM_SPECIES] = + Jmat[i * (NUM_SPECIES + 1) + NUM_SPECIES] / mw[i]; + } + for (int i = 0; i < NUM_SPECIES; i++) { + (Jbd[0][0])[NUM_SPECIES][i] = + Jmat[NUM_SPECIES * (NUM_SPECIES + 1) + i] * mw[i]; + } + (Jbd[0][0])[NUM_SPECIES][NUM_SPECIES] = + Jmat[(NUM_SPECIES + 1) * (NUM_SPECIES + 1) - 1]; + + denseCopy(Jbd[0][0], P[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1); + + *jcurPtr = SUNTRUE; + } + + // Scale by -gamma + denseScale(-gamma, P[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1); + + // Add identity matrix and do LU decompositions on blocks in place. + denseAddIdentity(P[0][0], NUM_SPECIES + 1); + sunindextype ierr = + denseGETRF(P[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1, pivot[0][0]); + if (ierr != 0) { + return (1); + } + + return (0); +} + +int +PSolve( + amrex::Real /* tn */, + N_Vector /* u */, + N_Vector /* fu */, + N_Vector r, + N_Vector z, + amrex::Real /* gamma */, + amrex::Real /* delta */, + int /* lr */, + void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::PSolve()"); + // Make local copies of pointers to input data + amrex::Real* zdata = N_VGetArrayPointer(z); + + // Extract the P and pivot arrays from user_data. + auto* udata = static_cast(user_data); + auto* P = udata->P; + auto* pivot = udata->pivot; + + N_VScale(1.0, r, z); + + // Solve the block-diagonal system Pz = r using LU factors stored + // in P and pivot data in pivot, and return the solution in z. + amrex::Real* v = zdata; + denseGETRS(P[0][0], NUM_SPECIES + 1, pivot[0][0], v); + + return (0); +} + +#ifdef PELE_USE_KLU +// Preconditioner setup routine for GMRES solver when KLU sparse mode is +// activated Generate and preprocess P +int +Precond_sparse( + amrex::Real /* tn */, + N_Vector u, + N_Vector /* fu */, + booleantype jok, + booleantype* jcurPtr, + amrex::Real gamma, + void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::Precond_sparse()"); + // Make local copies of pointers to input data (big M) + amrex::Real* u_d = N_VGetArrayPointer(u); + + // Make local copies of pointers in user_data + CVODEUserData* udata = static_cast(user_data); + auto ncells = udata->ncells_d; + auto reactor_type = udata->ireactor_type; + auto JSPSmat = udata->JSPSmat; + auto colPtrs = udata->colPtrs; + auto rowVals = udata->rowVals; + auto Jdata = udata->Jdata; + auto Symbolic = udata->Symbolic; + auto Numeric = udata->Numeric; + auto Common = udata->Common; + auto FirstTimePrecond = udata->FirstTimePrecond; + + // MW CGS + // MW CGS + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + // Check if Jac is stale + if (jok) { + // jok = SUNTRUE: Copy Jbd to P + *jcurPtr = SUNFALSE; + } else { + // Save Jac from cell to cell if more than one + amrex::Real temp_save_lcl = 0.0; + for (int tid = 0; tid < ncells; tid++) { + // Offset in case several cells + int offset = tid * (NUM_SPECIES + 1); + // rho MKS + amrex::Real rho = 0.0; + for (int i = 0; i < NUM_SPECIES; i++) { + rho = rho + u_d[offset + i]; + } + // Yks + amrex::Real rhoinv = 1.0 / rho; + amrex::Real massfrac[NUM_SPECIES] = {0.0}; + for (int i = 0; i < NUM_SPECIES; i++) { + massfrac[i] = u_d[offset + i] * rhoinv; + } + amrex::Real temp = u_d[offset + NUM_SPECIES]; + // Activities + amrex::Real activity[NUM_SPECIES] = {0.0}; + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2C(rho, temp, massfrac, activity); + + // Do we recompute Jac ? + if (fabs(temp - temp_save_lcl) > 1.0) { + // Formalism + int consP = reactor_type == ReactorTypes::h_reactor_type; + DWDOT_SIMPLIFIED(JSPSmat[tid], activity, &temp, &consP); + + for (int i = 0; i < NUM_SPECIES; i++) { + for (int k = 0; k < NUM_SPECIES; k++) { + (JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] *= mw[i] / mw[k]; + } + (JSPSmat[tid])[i * (NUM_SPECIES + 1) + NUM_SPECIES] /= mw[i]; + } + for (int i = 0; i < NUM_SPECIES; i++) { + (JSPSmat[tid])[NUM_SPECIES * (NUM_SPECIES + 1) + i] *= mw[i]; + } + temp_save_lcl = temp; + } else { + // if not: copy the one from prev cell + for (int i = 0; i < NUM_SPECIES + 1; i++) { + for (int k = 0; k < NUM_SPECIES + 1; k++) { + (JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] = + (JSPSmat[tid - 1])[k * (NUM_SPECIES + 1) + i]; + } + } + } + } + + *jcurPtr = SUNTRUE; + } + + for (int i = 1; i < NUM_SPECIES + 2; i++) { + // nb non zeros elem should be the same for all cells + int nbVals = colPtrs[0][i] - colPtrs[0][i - 1]; + for (int j = 0; j < nbVals; j++) { + // row of non zero elem should be the same for all cells + int idx = rowVals[0][colPtrs[0][i - 1] + j]; + // Scale by -gamma + // Add identity matrix + for (int tid = 0; tid < ncells; tid++) { + if (idx == (i - 1)) { + Jdata[tid][colPtrs[tid][i - 1] + j] = + 1.0 - gamma * (JSPSmat[tid])[idx * (NUM_SPECIES + 1) + idx]; + } else { + Jdata[tid][colPtrs[tid][i - 1] + j] = + -gamma * (JSPSmat[tid])[(i - 1) * (NUM_SPECIES + 1) + idx]; + } + } + } + } + + BL_PROFILE_VAR("Pele::ReactorCvode::KLU_factorization", KLU_factor); + if (!(FirstTimePrecond)) { + for (int tid = 0; tid < ncells; tid++) { + klu_refactor( + colPtrs[tid], rowVals[tid], Jdata[tid], Symbolic[tid], Numeric[tid], + &(Common[tid])); + } + } else { + for (int tid = 0; tid < ncells; tid++) { + Numeric[tid] = klu_factor( + colPtrs[tid], rowVals[tid], Jdata[tid], Symbolic[tid], &(Common[tid])); + } + FirstTimePrecond = false; + } + BL_PROFILE_VAR_STOP(KLU_factor); + + return (0); +} + +int +PSolve_sparse( + amrex::Real /* tn */, + N_Vector /* u */, + N_Vector /* fu */, + N_Vector r, + N_Vector z, + amrex::Real /* gamma */, + amrex::Real /* delta */, + int /* lr */, + void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::PSolve_sparse()"); + // Make local copies of pointers in user_data + CVODEUserData* udata = static_cast(user_data); + auto ncells = udata->ncells_d; + auto Symbolic = udata->Symbolic; + auto Numeric = udata->Numeric; + auto Common = udata->Common; + + // Make local copies of pointers to input data (big M) + amrex::Real* zdata = N_VGetArrayPointer(z); + + BL_PROFILE_VAR("Pele::ReactorCvode::KLU_inversion", PSolve_sparse); + N_VScale(1.0, r, z); + + // Solve the block-diagonal system Pz = r using LU factors stored + // in P and pivot data in pivot, and return the solution in z. + amrex::Real zdata_cell[NUM_SPECIES + 1]; + for (int tid = 0; tid < ncells; tid++) { + int offset_beg = tid * (NUM_SPECIES + 1); + std::memcpy( + zdata_cell, zdata + offset_beg, (NUM_SPECIES + 1) * sizeof(amrex::Real)); + klu_solve( + Symbolic[tid], Numeric[tid], NUM_SPECIES + 1, 1, zdata_cell, + &(Common[tid])); + std::memcpy( + zdata + offset_beg, zdata_cell, (NUM_SPECIES + 1) * sizeof(amrex::Real)); + } + BL_PROFILE_VAR_STOP(PSolve_sparse); + + return (0); +} +#endif + +// Preconditioner setup routine for GMRES solver when custom sparse mode is +// activated Generate and preprocess P +int +Precond_custom( + amrex::Real /* tn */, + N_Vector u, + N_Vector /* fu */, + booleantype jok, + booleantype* jcurPtr, + amrex::Real gamma, + void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::Precond_custom()"); + // Make local copies of pointers to input data + amrex::Real* u_d = N_VGetArrayPointer(u); + + // Make local copies of pointers in user_data + auto* udata = static_cast(user_data); + auto ncells = udata->ncells_d; + auto reactor_type = udata->ireactor_type; + auto* JSPSmat = udata->JSPSmat; + auto* rowPtrs = udata->rowPtrs; + auto* colVals = udata->colVals; + auto* Jdata = udata->Jdata; + + // MW CGS + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + // Check if Jac is stale + if (jok) { + // jok = SUNTRUE: Copy Jbd to P + *jcurPtr = SUNFALSE; + } else { + // Save Jac from cell to cell if more than one + amrex::Real temp_save_lcl = 0.0; + for (int tid = 0; tid < ncells; tid++) { + // Offset in case several cells + int offset = tid * (NUM_SPECIES + 1); + // rho MKS + amrex::Real rho = 0.0; + for (int i = 0; i < NUM_SPECIES; i++) { + rho = rho + u_d[offset + i]; + } + // Yks + amrex::Real massfrac[NUM_SPECIES] = {0.0}; + amrex::Real rhoinv = 1.0 / rho; + for (int i = 0; i < NUM_SPECIES; i++) { + massfrac[i] = u_d[offset + i] * rhoinv; + } + amrex::Real temp = u_d[offset + NUM_SPECIES]; + // Activities + amrex::Real activity[NUM_SPECIES] = {0.0}; + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2C(rho, temp, massfrac, activity); + + // Do we recompute Jac ? + if (fabs(temp - temp_save_lcl) > 1.0) { + // Formalism + int consP = reactor_type == ReactorTypes::h_reactor_type; + DWDOT_SIMPLIFIED(JSPSmat[tid], activity, &temp, &consP); + + for (int i = 0; i < NUM_SPECIES; i++) { + for (int k = 0; k < NUM_SPECIES; k++) { + (JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] *= mw[i] / mw[k]; + } + (JSPSmat[tid])[i * (NUM_SPECIES + 1) + NUM_SPECIES] /= mw[i]; + } + for (int i = 0; i < NUM_SPECIES; i++) { + (JSPSmat[tid])[NUM_SPECIES * (NUM_SPECIES + 1) + i] *= mw[i]; + } + temp_save_lcl = temp; + } else { + // if not: copy the one from prev cell + for (int i = 0; i < NUM_SPECIES + 1; i++) { + for (int k = 0; k < NUM_SPECIES + 1; k++) { + (JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] = + (JSPSmat[tid - 1])[k * (NUM_SPECIES + 1) + i]; + } + } + } + } + *jcurPtr = SUNTRUE; + } + + for (int i = 1; i < NUM_SPECIES + 2; i++) { + // nb non zeros elem should be the same for all cells + int nbVals = rowPtrs[0][i] - rowPtrs[0][i - 1]; + for (int j = 0; j < nbVals; j++) { + // row of non zero elem should be the same for all cells + int idx = colVals[0][rowPtrs[0][i - 1] + j]; + // Scale by -gamma + // Add identity matrix + for (int tid = 0; tid < ncells; tid++) { + if (idx == (i - 1)) { + Jdata[tid][rowPtrs[tid][i - 1] + j] = + 1.0 - gamma * (JSPSmat[tid])[idx * (NUM_SPECIES + 1) + idx]; + } else { + Jdata[tid][rowPtrs[tid][i - 1] + j] = + -gamma * (JSPSmat[tid])[(i - 1) + (NUM_SPECIES + 1) * idx]; + } + } + } + } + + return (0); +} + +int +PSolve_custom( + amrex::Real /* tn */, + N_Vector /* u */, + N_Vector /* fu */, + N_Vector r, + N_Vector z, + amrex::Real /* gamma */, + amrex::Real /* delta */, + int /* lr */, + void* user_data) +{ + BL_PROFILE("Pele::ReactorCvode::PSolve_custom()"); + // Make local copies of pointers in user_data + auto* udata = static_cast(user_data); + auto ncells = udata->ncells_d; + auto* Jdata = udata->Jdata; + + // Make local copies of pointers to input data + amrex::Real* zdata = N_VGetArrayPointer(z); + amrex::Real* rdata = N_VGetArrayPointer(r); + + N_VScale(1.0, r, z); + + // Solve the block-diagonal system Pz = r using LU factors stored + // in P and pivot data in pivot, and return the solution in z. + BL_PROFILE_VAR("Pele::ReactorCvode::GaussSolver", GaussSolver); + for (int tid = 0; tid < ncells; tid++) { + int offset = tid * (NUM_SPECIES + 1); + double* z_d_offset = zdata + offset; + double* r_d_offset = rdata + offset; + sgjsolve_simplified(Jdata[tid], z_d_offset, r_d_offset); + } + BL_PROFILE_VAR_STOP(GaussSolver); + + return (0); +} + +#endif +} // namespace cvode +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorCvodeUtils.H b/Reactions/ReactorCvodeUtils.H new file mode 100644 index 000000000..48c457bd1 --- /dev/null +++ b/Reactions/ReactorCvodeUtils.H @@ -0,0 +1,360 @@ +#ifndef _REACTORUTILSCVODE_H_ +#define _REACTORUTILSCVODE_H_ +#include "ReactorTypes.H" + +#include +#include +#include +#include +#include +#include +#include "ReactorUtils.H" + +#ifdef AMREX_USE_CUDA +#include +#endif + +#ifdef PELE_USE_KLU +#include "klu.h" +#include +#endif + +namespace pele { +namespace physics { +namespace reactions { + +struct CVODEUserData +{ + amrex::Real dt_save; // Internal cvode dt holder + int ncells_d; // Number of cells in solve + int iverbose; // Verbose + int maxOrder; // CVODE max order + int ireactor_type; // Either HP (LM) or UV (C) + int ianalytical_jacobian; // Analytical Jacobian 'On' flag + int isolve_type; // Type of linear solve for Newton direction + int iprecond_type; // Type of preconditioner (if iterative solve) + int NNZ; // Number of non-zero entry for sparse representations + amrex::Real* energy_init_d = NULL; // Initial energy (rhoE for C, rhoH for LM) + amrex::Real* energy_ext_d = NULL; // External energy forcing + amrex::Real* species_ext_d = NULL; // External species forcing + int* mask = + NULL; // Masking tagging cells where integration should not be perfomed + int* FCunt = NULL; // Number of RHS evaluations (not used on GPU) + amrex::Real gamma; // System Chem. jacobian coefficient + int nbBlocks; // GPU kernel launch parameter + int nbThreads; // GPU kernel launch parameter + +#ifdef AMREX_USE_GPU + // Matrix data + int* csr_row_count_h; // Host CSR sparse mat + int* csr_col_index_h; // Host CSR sparse mat + int* csr_row_count_d; // Device CSR sparse mat + int* csr_col_index_d; // Device CSR sparse mat + amrex::Real* csr_val_d; // Syst. Jac. CSR sparse mat values + amrex::Real* csr_jac_d; // Chem. Jac. CSR sparse mat values + +#ifdef AMREX_USE_CUDA + // Batched QR preconditioner data + void* buffer_qr = NULL; // cuSolver internal work arrays + csrqrInfo_t info; // QR solve info + cusparseMatDescr_t descrA; // Sparse mat. descriptor + cusolverSpHandle_t cusolverHandle; + cusparseHandle_t cuSPHandle; +#endif + amrex::gpuStream_t stream; + +#else + bool FirstTimePrecond; + amrex::Real** Jdata = NULL; + // Sparse direct solve data + // Ptrs to CSR/CSC matrix for each submatrices (cells) + SUNMatrix* PS; + int** rowVals = NULL; + int** rowPtrs = NULL; + int** colPtrs = NULL; + int** colVals = NULL; + int* indx = NULL; + amrex::Real** JSPSmat = NULL; +#ifdef PELE_USE_KLU + klu_common* Common; + klu_symbolic** Symbolic; + klu_numeric** Numeric; +#endif + // Matrix data for denseSimpleAjac preconditioner + amrex::Real**** Jbd; + amrex::Real**** P; + sunindextype*** pivot; + // Custom direct linear solve: a CSR SUNMatrix and ptrs + SUNMatrix PSc; + int* colVals_c; + int* rowPtrs_c; +#endif +}; + +namespace cvode { + +#ifdef AMREX_USE_GPU +enum linSolveType { sparseDirect, customDirect, magmaDirect, GMRES, precGMRES }; +enum precondType { sparseSimpleAJac }; +#else +enum linSolveType { + denseFDDirect, + denseDirect, + sparseDirect, + customDirect, + GMRES, + precGMRES, + hackDumpSparsePattern +}; +enum precondType { denseSimpleAJac, sparseSimpleAJac, customSimpleAJac }; +#endif + +// Error function for CVODE +void cvodeErrHandler( + int error_code, + const char* /*module*/, + const char* /*function*/, + char* msg, + void* /*eh_data*/); + +void printFinalStats(void* cvodeMem); + +#ifdef AMREX_USE_GPU +AMREX_GPU_DEVICE +AMREX_FORCE_INLINE +void +fKernelComputeallAJ( + int ncell, void* user_data, amrex::Real* u_d, amrex::Real* csr_val_arg) +{ + CVODEUserData* udata = static_cast(user_data); + int neqs = NUM_SPECIES + 1; + auto NNZ = udata->NNZ; + auto reactor_type = udata->ireactor_type; + auto csr_jac_d = udata->csr_jac_d; + auto csr_row_count_d = udata->csr_row_count_d; + auto csr_col_index_d = udata->csr_col_index_d; + auto gamma = udata->gamma; + + amrex::GpuArray activity{0.0}; + amrex::GpuArray Jmat_pt{ + 0.0}; + + int u_offset = ncell * neqs; + amrex::Real* u_curr = u_d + u_offset; + + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + amrex::Real rho_pt = 0.0; + for (int n = 0; n < NUM_SPECIES; n++) { + rho_pt = rho_pt + u_curr[n]; + } + + amrex::GpuArray massfrac{0.0}; + for (int i = 0; i < NUM_SPECIES; i++) { + massfrac[i] = u_curr[i] / rho_pt; + } + + amrex::Real temp_pt = u_curr[NUM_SPECIES]; + + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2C(rho_pt, temp_pt, massfrac.arr, activity.arr); + + int consP = reactor_type == ReactorTypes::h_reactor_type; + DWDOT_SIMPLIFIED(Jmat_pt.arr, activity.arr, &temp_pt, &consP); + + int jac_offset = ncell * NNZ; + amrex::Real* csr_jac_cell = csr_jac_d + jac_offset; + amrex::Real* csr_val_cell = csr_val_arg + jac_offset; + for (int i = 0; i < NUM_SPECIES; i++) { + for (int k = 0; k < NUM_SPECIES; k++) { + Jmat_pt[k * neqs + i] *= mw[i] / mw[k]; + } + Jmat_pt[i * neqs + NUM_SPECIES] /= mw[i]; + Jmat_pt[NUM_SPECIES * neqs + i] *= mw[i]; + } + for (int i = 1; i < NUM_SPECIES + 2; i++) { + int nbVals = csr_row_count_d[i] - csr_row_count_d[i - 1]; + for (int j = 0; j < nbVals; j++) { + int idx = csr_col_index_d[csr_row_count_d[i - 1] + j - 1] - 1; + if (idx == (i - 1)) { + csr_val_cell[csr_row_count_d[i - 1] + j - 1] = + 1.0 - gamma * Jmat_pt[idx * neqs + idx]; + csr_jac_cell[csr_row_count_d[i - 1] + j - 1] = + Jmat_pt[idx * neqs + idx]; + } else { + csr_val_cell[csr_row_count_d[i - 1] + j - 1] = + -gamma * Jmat_pt[idx * neqs + i - 1]; + csr_jac_cell[csr_row_count_d[i - 1] + j - 1] = + Jmat_pt[idx * neqs + i - 1]; + } + } + } +} + +AMREX_GPU_DEVICE +AMREX_FORCE_INLINE +void +fKernelComputeAJsys( + int ncell, void* user_data, amrex::Real* u_d, amrex::Real* csr_val_arg) +{ + CVODEUserData* udata = static_cast(user_data); + auto NNZ = udata->NNZ; + auto csr_jac_d = udata->csr_jac_d; + auto csr_row_count_d = udata->csr_row_count_d; + auto csr_col_index_d = udata->csr_col_index_d; + auto gamma = udata->gamma; + + int jac_offset = ncell * NNZ; + amrex::Real* csr_jac_cell = csr_jac_d + jac_offset; + amrex::Real* csr_val_cell = csr_val_arg + jac_offset; + + for (int i = 1; i < NUM_SPECIES + 2; i++) { + int nbVals = csr_row_count_d[i] - csr_row_count_d[i - 1]; + for (int j = 0; j < nbVals; j++) { + int idx = csr_col_index_d[csr_row_count_d[i - 1] + j - 1] - 1; + if (idx == (i - 1)) { + csr_val_cell[csr_row_count_d[i - 1] + j - 1] = + 1.0 - gamma * csr_jac_cell[csr_row_count_d[i - 1] + j - 1]; + } else { + csr_val_cell[csr_row_count_d[i - 1] + j - 1] = + -gamma * csr_jac_cell[csr_row_count_d[i - 1] + j - 1]; + } + } + } +} + +AMREX_GPU_DEVICE +AMREX_FORCE_INLINE +void +fKernelComputeAJchem( + int ncell, void* user_data, amrex::Real* u_d, amrex::Real* Jdata) +{ + CVODEUserData* udata = static_cast(user_data); + const int neqs = NUM_SPECIES + 1; + auto NNZ = udata->NNZ; + auto reactor_type = udata->ireactor_type; + auto csr_row_count_d = udata->csr_row_count_d; + auto csr_col_index_d = udata->csr_col_index_d; + + int u_offset = ncell * neqs; + amrex::Real* u_curr = u_d + u_offset; + + amrex::Real rho_pt = 0.0; + for (int n = 0; n < NUM_SPECIES; n++) { + rho_pt = rho_pt + u_curr[n]; + } + + amrex::GpuArray massfrac = {0.0}; + for (int n = 0; n < NUM_SPECIES; n++) { + massfrac[n] = u_curr[n] / rho_pt; + } + amrex::Real temp_pt = u_curr[NUM_SPECIES]; + + const int consP = reactor_type == ReactorTypes::h_reactor_type; + amrex::GpuArray Jmat_pt = {0.0}; + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2JAC(rho_pt, temp_pt, massfrac.arr, Jmat_pt.arr, consP); + + // Scale Jacobian and pass into outgoing data ptr. + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + int jac_offset = ncell * NNZ; + amrex::Real* csr_jac_cell = Jdata + jac_offset; + + for (int i = 0; i < NUM_SPECIES; i++) { + for (int k = 0; k < NUM_SPECIES; k++) { + Jmat_pt[k * neqs + i] *= mw[i] / mw[k]; + } + Jmat_pt[i * neqs + NUM_SPECIES] /= mw[i]; + Jmat_pt[NUM_SPECIES * neqs + i] *= mw[i]; + } + for (int i = 1; i < NUM_SPECIES + 2; i++) { + int nbVals = csr_row_count_d[i] - csr_row_count_d[i - 1]; + for (int j = 0; j < nbVals; j++) { + int idx_cell = csr_col_index_d[csr_row_count_d[i - 1] + j]; + csr_jac_cell[csr_row_count_d[i - 1] + j] = + Jmat_pt[idx_cell * neqs + i - 1]; + } + } +} + +AMREX_GPU_DEVICE +AMREX_FORCE_INLINE +void +fKernelDenseAJchem( + int icell, void* user_data, amrex::Real* u_d, amrex::Real* Jdata) +{ + CVODEUserData* udata = static_cast(user_data); + const int neqs = NUM_SPECIES + 1; + auto reactor_type = udata->ireactor_type; + + int u_offset = icell * neqs; + amrex::Real* u_curr = u_d + u_offset; + + amrex::Real rho_pt = 0.0; + for (int n = 0; n < NUM_SPECIES; n++) { + rho_pt = rho_pt + u_curr[n]; + } + + amrex::GpuArray massfrac = {0.0}; + for (int n = 0; n < NUM_SPECIES; n++) { + massfrac[n] = u_curr[n] / rho_pt; + } + amrex::Real temp_pt = u_curr[NUM_SPECIES]; + + const int consP = reactor_type == ReactorTypes::h_reactor_type; + amrex::GpuArray Jmat_pt = {0.0}; + auto eos = pele::physics::PhysicsType::eos(); + eos.RTY2JAC(rho_pt, temp_pt, massfrac.arr, Jmat_pt.arr, consP); + + // Scale Jacobian and pass into outgoing data ptr. + amrex::Real mw[NUM_SPECIES] = {0.0}; + get_mw(mw); + + int jac_offset = icell * (neqs * neqs); + amrex::Real* Jcurr = Jdata + jac_offset; + + for (int i = 0; i < NUM_SPECIES; i++) { + for (int k = 0; k < NUM_SPECIES; k++) { + Jcurr[k * neqs + i] = Jmat_pt[k * neqs + i] * mw[i] / mw[k]; + } + Jcurr[i * neqs + NUM_SPECIES] = Jmat_pt[i * neqs + NUM_SPECIES] / mw[i]; + Jcurr[NUM_SPECIES * neqs + i] = Jmat_pt[NUM_SPECIES * neqs + i] * mw[i]; + } +} + +#ifdef AMREX_USE_CUDA +/* +__global__ void +fKernelDenseSolve( int ncell, + amrex::Real* x_d, + amrex::Real* b_d, + int subsys_size, + int subsys_nnz, + amrex::Real* csr_val) +{ + int stride = blockDim.x * gridDim.x; + + for (int icell = blockDim.x * blockIdx.x + threadIdx.x; icell < ncell; + icell += stride) { + int offset = icell * subsys_size; + int offset_A = icell * subsys_nnz; + + amrex::Real* csr_val_cell = csr_val + offset_A; + amrex::Real* x_cell = x_d + offset; + amrex::Real* b_cell = b_d + offset; + + sgjsolve(csr_val_cell, x_cell, b_cell); + } +} +*/ +#endif + +#endif +} // namespace cvode +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorCvodeUtils.cpp b/Reactions/ReactorCvodeUtils.cpp new file mode 100644 index 000000000..7c8c5d733 --- /dev/null +++ b/Reactions/ReactorCvodeUtils.cpp @@ -0,0 +1,90 @@ +#include "ReactorCvodeUtils.H" + +namespace pele { +namespace physics { +namespace reactions { +namespace cvode { + +// Error function for CVODE +void +cvodeErrHandler( + int error_code, + const char* /*module*/, + const char* /*function*/, + char* msg, + void* /*eh_data*/) +{ + if (error_code != CV_WARNING) { + std::cout << "From CVODE: " << msg << std::endl; + amrex::Abort("Aborting from CVODE"); + } +} + +void +printFinalStats(void* cvodeMem) +{ + long lenrw, leniw; + long lenrwLS, leniwLS; + long int nst, nfe, nsetups, nni, ncfn, netf; + long int nli, npe, nps, ncfl, nfeLS; + int flag; + + flag = CVodeGetWorkSpace(cvodeMem, &lenrw, &leniw); + utils::check_flag(&flag, "CVodeGetWorkSpace", 1); + flag = CVodeGetNumSteps(cvodeMem, &nst); + utils::check_flag(&flag, "CVodeGetNumSteps", 1); + flag = CVodeGetNumRhsEvals(cvodeMem, &nfe); + utils::check_flag(&flag, "CVodeGetNumRhsEvals", 1); + flag = CVodeGetNumLinSolvSetups(cvodeMem, &nsetups); + utils::check_flag(&flag, "CVodeGetNumLinSolvSetups", 1); + flag = CVodeGetNumErrTestFails(cvodeMem, &netf); + utils::check_flag(&flag, "CVodeGetNumErrTestFails", 1); + flag = CVodeGetNumNonlinSolvIters(cvodeMem, &nni); + utils::check_flag(&flag, "CVodeGetNumNonlinSolvIters", 1); + flag = CVodeGetNumNonlinSolvConvFails(cvodeMem, &ncfn); + utils::check_flag(&flag, "CVodeGetNumNonlinSolvConvFails", 1); + + flag = CVodeGetLinWorkSpace(cvodeMem, &lenrwLS, &leniwLS); + utils::check_flag(&flag, "CVodeGetLinWorkSpace", 1); + flag = CVodeGetNumLinIters(cvodeMem, &nli); + utils::check_flag(&flag, "CVodeGetNumLinIters", 1); + // flag = CVodeGetNumJacEvals(cvodeMem, &nje); + // utils::check_flag(&flag, "CVodeGetNumJacEvals", 1); + flag = CVodeGetNumLinRhsEvals(cvodeMem, &nfeLS); + utils::check_flag(&flag, "CVodeGetNumLinRhsEvals", 1); + + flag = CVodeGetNumPrecEvals(cvodeMem, &npe); + utils::check_flag(&flag, "CVodeGetNumPrecEvals", 1); + flag = CVodeGetNumPrecSolves(cvodeMem, &nps); + utils::check_flag(&flag, "CVodeGetNumPrecSolves", 1); + + flag = CVodeGetNumLinConvFails(cvodeMem, &ncfl); + utils::check_flag(&flag, "CVodeGetNumLinConvFails", 1); + +#ifdef AMREX_USE_OMP + amrex::Print() << "\nFinal Statistics: " + << "(thread:" << omp_get_thread_num() << ", "; + amrex::Print() << "cvodeMem:" << cvodeMem << ")\n"; +#else + amrex::Print() << "\nFinal Statistics:\n"; +#endif + amrex::Print() << "lenrw = " << lenrw << " leniw = " << leniw + << "\n"; + amrex::Print() << "lenrwLS = " << lenrwLS + << " leniwLS = " << leniwLS << "\n"; + amrex::Print() << "nSteps = " << nst << "\n"; + amrex::Print() << "nRHSeval = " << nfe << " nLinRHSeval = " << nfeLS + << "\n"; + amrex::Print() << "nnLinIt = " << nni << " nLinIt = " << nli + << "\n"; + amrex::Print() << "nLinsetups = " << nsetups << " nErrtf = " << netf + << "\n"; + amrex::Print() << "nPreceval = " << npe << " nPrecsolve = " << nps + << "\n"; + amrex::Print() << "nConvfail = " << ncfn << " nLinConvfail = " << ncfl + << "\n\n"; +} +} // namespace cvode +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorNull.H b/Reactions/ReactorNull.H new file mode 100644 index 000000000..9fd677783 --- /dev/null +++ b/Reactions/ReactorNull.H @@ -0,0 +1,97 @@ +#ifndef _REACTORNULL_H_ +#define _REACTORNULL_H_ + +#include "ReactorBase.H" + +namespace pele { +namespace physics { +namespace reactions { + +class ReactorNull : public ReactorBase::Register +{ +public: + static std::string identifier() { return "ReactorNull"; } + + using Ordering = utils::YCOrder; + + int init(int reactor_type, int Ncells) override; + + void close() override {} + + int react( + const amrex::Box& box, + amrex::Array4 const& rY_in, + amrex::Array4 const& rY_src_in, + amrex::Array4 const& T_in, + amrex::Array4 const& rEner_in, + amrex::Array4 const& rEner_src_in, + amrex::Array4 const& FC_in, + amrex::Array4 const& mask, + amrex::Real& dt_react, + amrex::Real& time +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) override; + + int react( + amrex::Real* rY_in, + amrex::Real* rY_src_in, + amrex::Real* rX_in, + amrex::Real* rX_src_in, + amrex::Real& dt_react, + amrex::Real& time, + int Ncells +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) override; + + void flatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& frcExt, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Real* y_vect, + amrex::Real* src_vect, + amrex::Real* vect_energy, + amrex::Real* src_vect_energy) override + { + flatten_ops.flatten( + box, ncells, m_reactor_type, rhoY, frcExt, temperature, rhoE, frcEExt, + y_vect, src_vect, vect_energy, src_vect_energy); + } + + void unflatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Array4 const& FC_in, + amrex::Real* y_vect, + amrex::Real* vect_energy, + long int* FCunt, + amrex::Real dt) override + { + flatten_ops.unflatten( + box, ncells, m_reactor_type, rhoY, temperature, rhoE, frcEExt, FC_in, + y_vect, vect_energy, FCunt, dt); + } + + void SetTypValsODE(const std::vector& ExtTypVals) override; + +private: + utils::FlattenOps flatten_ops; + int m_reactor_type{0}; +}; +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorNull.cpp b/Reactions/ReactorNull.cpp new file mode 100644 index 000000000..b05b905c6 --- /dev/null +++ b/Reactions/ReactorNull.cpp @@ -0,0 +1,107 @@ +#include "ReactorNull.H" + +namespace pele { +namespace physics { +namespace reactions { + +int +ReactorNull::init(int reactor_type, int /*Ncells*/) +{ + BL_PROFILE("Pele::ReactorNull::init()"); + m_reactor_type = reactor_type; + ReactorTypes::check_reactor_type(m_reactor_type); + return (0); +} + +// Array4 version +int +ReactorNull::react( + const amrex::Box& box, + amrex::Array4 const& rY_in, + amrex::Array4 const& rY_src_in, + amrex::Array4 const& T_in, + amrex::Array4 const& rEner_in, + amrex::Array4 const& rEner_src_in, + amrex::Array4 const& FC_in, + amrex::Array4 const& /*mask*/, + amrex::Real& dt_react, + amrex::Real& time +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t /*stream*/ +#endif +) +{ + + amrex::Real time_init = time; + + int captured_reactor_type = m_reactor_type; + + ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real renergy_loc = + rEner_in(i, j, k, 0) + rEner_src_in(i, j, k, 0) * dt_react; + rEner_in(i, j, k, 0) = renergy_loc; + amrex::Real rY_loc[NUM_SPECIES]; + for (int n = 0; n < NUM_SPECIES; n++) { + rY_loc[n] = rY_in(i, j, k, n) + rY_src_in(i, j, k, n) * dt_react; + rY_in(i, j, k, n) = rY_loc[n]; + } + amrex::Real rho_loc = 0.0; + for (double n : rY_loc) { + rho_loc += n; + } + amrex::Real Y_loc[NUM_SPECIES]; + for (int n = 0; n < NUM_SPECIES; n++) { + Y_loc[n] = rY_loc[n] / rho_loc; + } + amrex::Real energy_loc = renergy_loc / rho_loc; + amrex::Real T_loc = T_in(i, j, k, 0); + auto eos = pele::physics::PhysicsType::eos(); + if (captured_reactor_type == ReactorTypes::e_reactor_type) { + eos.REY2T(rho_loc, energy_loc, Y_loc, T_loc); + } else if (captured_reactor_type == ReactorTypes::h_reactor_type) { + eos.RHY2T(rho_loc, energy_loc, Y_loc, T_loc); + } else { + amrex::Abort("Wrong reactor type. Choose between 1 (e) or 2 (h)."); + } + T_in(i, j, k, 0) = T_loc; + FC_in(i, j, k, 0) = 0.0; + }); + +#ifdef MOD_REACTOR + time = time_init + dt_react; +#endif + return 0; +} + +// 1D version +int +ReactorNull::react( + amrex::Real* /*rY_in*/, + amrex::Real* /*rY_src_in*/, + amrex::Real* /*rX_in*/, + amrex::Real* /*rX_src_in*/, + amrex::Real& dt_react, + amrex::Real& time, + int /*Ncells*/ +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t /*stream*/ +#endif +) +{ + amrex::Real time_init = time; +#ifdef MOD_REACTOR + time = time_init + dt_react; +#endif + return 0; +} + +void +ReactorNull::SetTypValsODE(const std::vector& /*ExtTypVals*/) +{ + amrex::Print() << "WARNING: ignoring TypVals for this reactor." << std::endl; +} +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorRK64.H b/Reactions/ReactorRK64.H new file mode 100644 index 000000000..d52e76684 --- /dev/null +++ b/Reactions/ReactorRK64.H @@ -0,0 +1,135 @@ +#ifndef _REACTORRK64_H_ +#define _REACTORRK64_H_ + +#include "ReactorBase.H" + +namespace pele { +namespace physics { +namespace reactions { + +// stages and coefficients for rk64 +struct RK64Params +{ + const int nstages_rk64 = 6; + const amrex::Real alpha_rk64[6] = { + 0.218150805229859, // 3296351145737.0/15110423921029.0, + 0.256702469801519, // 1879360555526.0/ 7321162733569.0, + 0.527402592007520, // 10797097731880.0/20472212111779.0, + 0.0484864267224467, // 754636544611.0/15563872110659.0, + 1.24517071533530, // 3260218886217.0/ 2618290685819.0, + 0.412366034843237, // 5069185909380.0/12292927838509.0 + }; + + const amrex::Real beta_rk64[6] = { + -0.113554138044166, //-1204558336989.0/10607789004752.0, + -0.215118587818400, //-3028468927040.0/14078136890693.0, + -0.0510152146250577, //-455570672869.0/ 8930094212428.0, + -1.07992686223881, //-17275898420483.0/15997285579755.0, + -0.248664241213447, //-2453906524165.0/ 9868353053862.0, + 0.0}; + + const amrex::Real err_rk64[6] = { + -0.0554699315064507, //-530312978447.0/ 9560368366154.0, + 0.158481845574980, // 473021958881.0/ 2984707536468.0, + -0.0905918835751907, //-947229622805.0/10456009803779.0, + -0.219084567203338, //-2921473878215.0/13334914072261.0, + 0.164022338959433, // 1519535112975.0/ 9264196100452.0, + 0.0426421977505659 // 167623581683.0/ 3930932046784.0 + }; + const amrex::Real exp1_rk64 = 0.25; + const amrex::Real exp2_rk64 = 0.2; + const amrex::Real betaerr_rk64 = 1.0; +}; + +class ReactorRK64 : public ReactorBase::Register +{ +public: + static std::string identifier() { return "ReactorRK64"; } + + using Ordering = utils::YCOrder; + + int init(int reactor_type, int Ncells) override; + + void close() override {} + + int react( + const amrex::Box& box, + amrex::Array4 const& rY_in, + amrex::Array4 const& rY_src_in, + amrex::Array4 const& T_in, + amrex::Array4 const& rEner_in, + amrex::Array4 const& rEner_src_in, + amrex::Array4 const& FC_in, + amrex::Array4 const& mask, + amrex::Real& dt_react, + amrex::Real& time +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) override; + + int react( + amrex::Real* rY_in, + amrex::Real* rY_src_in, + amrex::Real* rX_in, + amrex::Real* rX_src_in, + amrex::Real& dt_react, + amrex::Real& time, + int Ncells +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t stream +#endif + ) override; + + void flatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& frcExt, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Real* y_vect, + amrex::Real* src_vect, + amrex::Real* vect_energy, + amrex::Real* src_vect_energy) override + { + flatten_ops.flatten( + box, ncells, m_reactor_type, rhoY, frcExt, temperature, rhoE, frcEExt, + y_vect, src_vect, vect_energy, src_vect_energy); + } + + void unflatten( + const amrex::Box box, + const int ncells, + amrex::Array4 const& rhoY, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Array4 const& FC_in, + amrex::Real* y_vect, + amrex::Real* vect_energy, + long int* FCunt, + amrex::Real dt) override + { + flatten_ops.unflatten( + box, ncells, m_reactor_type, rhoY, temperature, rhoE, frcEExt, FC_in, + y_vect, vect_energy, FCunt, dt); + } + + void SetTypValsODE(const std::vector& ExtTypVals) override; + +private: + amrex::Real absTol{1e-10}; + int rk64_nsubsteps_guess{10}; + int rk64_nsubsteps_min{5}; + int rk64_nsubsteps_max{500}; + utils::FlattenOps flatten_ops; + int m_reactor_type{0}; +}; +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorRK64.cpp b/Reactions/ReactorRK64.cpp new file mode 100644 index 000000000..de598e06b --- /dev/null +++ b/Reactions/ReactorRK64.cpp @@ -0,0 +1,330 @@ +#include "AMReX_Reduce.H" +#include "ReactorRK64.H" + +namespace pele { +namespace physics { +namespace reactions { + +int +ReactorRK64::init(int reactor_type, int /*Ncells*/) +{ + BL_PROFILE("Pele::ReactorRK64::init()"); + m_reactor_type = reactor_type; + ReactorTypes::check_reactor_type(m_reactor_type); + amrex::ParmParse pp("ode"); + pp.query("atol", absTol); + pp.query("rk64_nsubsteps_guess", rk64_nsubsteps_guess); + pp.query("rk64_nsubsteps_min", rk64_nsubsteps_min); + pp.query("rk64_nsubsteps_max", rk64_nsubsteps_max); + return (0); +} + +int +ReactorRK64::react( + amrex::Real* rY_in, + amrex::Real* rY_src_in, + amrex::Real* rX_in, + amrex::Real* rX_src_in, + amrex::Real& dt_react, + amrex::Real& time, + int Ncells +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t /*stream*/ +#endif +) +{ + BL_PROFILE("Pele::ReactorRK64::react()"); + + amrex::Real time_init = time; + amrex::Real time_out = time + dt_react; + const amrex::Real tinyval = 1e-50; + + // Copy to device + amrex::Gpu::DeviceVector rY(Ncells * (NUM_SPECIES + 1), 0); + amrex::Gpu::DeviceVector rY_src(Ncells * NUM_SPECIES, 0); + amrex::Gpu::DeviceVector rX(Ncells, 0); + amrex::Gpu::DeviceVector rX_src(Ncells, 0); + amrex::Real* d_rY = rY.data(); + amrex::Real* d_rY_src = rY_src.data(); + amrex::Real* d_rX = rX.data(); + amrex::Real* d_rX_src = rX_src.data(); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, rY_in, rY_in + Ncells * (NUM_SPECIES + 1), d_rY); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, rY_src_in, rY_src_in + Ncells * NUM_SPECIES, + d_rY_src); + amrex::Gpu::copy(amrex::Gpu::hostToDevice, rX_in, rX_in + Ncells, d_rX); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, rX_src_in, rX_src_in + Ncells, d_rX_src); + + // capture reactor type + const int captured_reactor_type = m_reactor_type; + const int captured_nsubsteps_guess = rk64_nsubsteps_guess; + const int captured_nsubsteps_min = rk64_nsubsteps_min; + const int captured_nsubsteps_max = rk64_nsubsteps_max; + const amrex::Real captured_abstol = absTol; + RK64Params rkp; + + amrex::Gpu::DeviceVector v_nsteps(Ncells, 0); + int* d_nsteps = v_nsteps.data(); + + amrex::ParallelFor(Ncells, [=] AMREX_GPU_DEVICE(int icell) noexcept { + amrex::Real soln_reg[NUM_SPECIES + 1] = {0.0}; + amrex::Real carryover_reg[NUM_SPECIES + 1] = {0.0}; + amrex::Real error_reg[NUM_SPECIES + 1] = {0.0}; + amrex::Real rhs[NUM_SPECIES + 1] = {0.0}; + amrex::Real rYsrc[NUM_SPECIES] = {0.0}; + amrex::Real current_time = time_init; + const int neq = (NUM_SPECIES + 1); + + for (int sp = 0; sp < neq; sp++) { + soln_reg[sp] = d_rY[icell * neq + sp]; + carryover_reg[sp] = soln_reg[sp]; + } + + amrex::Real dt_rk = dt_react / amrex::Real(captured_nsubsteps_guess); + amrex::Real dt_rk_min = dt_react / amrex::Real(captured_nsubsteps_max); + amrex::Real dt_rk_max = dt_react / amrex::Real(captured_nsubsteps_min); + + amrex::Real rhoe_init[] = {d_rX[icell]}; + amrex::Real rhoesrc_ext[] = {d_rX_src[icell]}; + + for (int sp = 0; sp < NUM_SPECIES; sp++) { + rYsrc[sp] = d_rY_src[icell * NUM_SPECIES + sp]; + } + + int nsteps = 0; + amrex::Real change_factor; + while (current_time < time_out) { + for (double& sp : error_reg) { + sp = 0.0; + } + for (int stage = 0; stage < rkp.nstages_rk64; stage++) { + utils::fKernelSpec( + 0, 1, current_time - time_init, captured_reactor_type, soln_reg, rhs, + rhoe_init, rhoesrc_ext, rYsrc); + + for (int sp = 0; sp < neq; sp++) { + error_reg[sp] += rkp.err_rk64[stage] * dt_rk * rhs[sp]; + soln_reg[sp] = + carryover_reg[sp] + rkp.alpha_rk64[stage] * dt_rk * rhs[sp]; + carryover_reg[sp] = + soln_reg[sp] + rkp.beta_rk64[stage] * dt_rk * rhs[sp]; + } + } + + current_time += dt_rk; + nsteps++; + + amrex::Real max_err = tinyval; + for (double sp : error_reg) { + max_err = fabs(sp) > max_err ? fabs(sp) : max_err; + } + + if (max_err < captured_abstol) { + change_factor = + rkp.betaerr_rk64 * pow((captured_abstol / max_err), rkp.exp1_rk64); + dt_rk = amrex::min(dt_rk_max, dt_rk * change_factor); + } else { + change_factor = + rkp.betaerr_rk64 * pow((captured_abstol / max_err), rkp.exp2_rk64); + dt_rk = amrex::max(dt_rk_min, dt_rk * change_factor); + } + } + d_nsteps[icell] = nsteps; + // copy data back + for (int sp = 0; sp < neq; sp++) { + d_rY[icell * neq + sp] = soln_reg[sp]; + } + d_rX[icell] = rhoe_init[0] + dt_react * rhoesrc_ext[0]; + }); + +#ifdef MOD_REACTOR + time = time_out; +#endif + + const int avgsteps = amrex::Reduce::Sum( + Ncells, [=] AMREX_GPU_DEVICE(int i) noexcept -> int { return d_nsteps[i]; }, + 0); + + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, d_rY, d_rY + Ncells * (NUM_SPECIES + 1), rY_in); + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, d_rY_src, d_rY_src + Ncells * NUM_SPECIES, + rY_src_in); + amrex::Gpu::copy(amrex::Gpu::deviceToHost, d_rX, d_rX + Ncells, rX_in); + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, d_rX_src, d_rX_src + Ncells, rX_src_in); + + return (int(avgsteps / amrex::Real(Ncells))); +} + +int +ReactorRK64::react( + const amrex::Box& box, + amrex::Array4 const& rY_in, + amrex::Array4 const& rY_src_in, + amrex::Array4 const& T_in, + amrex::Array4 const& rEner_in, + amrex::Array4 const& rEner_src_in, + amrex::Array4 const& FC_in, + amrex::Array4 const& /*mask*/, + amrex::Real& dt_react, + amrex::Real& time +#ifdef AMREX_USE_GPU + , + amrex::gpuStream_t /*stream*/ +#endif +) +{ + BL_PROFILE("Pele::ReactorRK64::react()"); + + amrex::Real time_init = time; + amrex::Real time_out = time + dt_react; + const amrex::Real tinyval = 1e-50; + + // capture reactor type + const int captured_reactor_type = m_reactor_type; + const int captured_nsubsteps_guess = rk64_nsubsteps_guess; + const int captured_nsubsteps_min = rk64_nsubsteps_min; + const int captured_nsubsteps_max = rk64_nsubsteps_max; + const amrex::Real captured_abstol = absTol; + RK64Params rkp; + + int Ncells = box.numPts(); + const auto len = amrex::length(box); + const auto lo = amrex::lbound(box); + + amrex::Gpu::DeviceVector v_nsteps(Ncells, 0); + int* d_nsteps = v_nsteps.data(); + + amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real soln_reg[NUM_SPECIES + 1] = {0.0}; + amrex::Real carryover_reg[NUM_SPECIES + 1] = {0.0}; + amrex::Real error_reg[NUM_SPECIES + 1] = {0.0}; + amrex::Real rhs[NUM_SPECIES + 1] = {0.0}; + amrex::Real rYsrc[NUM_SPECIES] = {0.0}; + amrex::Real current_time = time_init; + const int neq = (NUM_SPECIES + 1); + + amrex::Real rho = 0.0; + for (int sp = 0; sp < NUM_SPECIES; sp++) { + soln_reg[sp] = rY_in(i, j, k, sp); + carryover_reg[sp] = soln_reg[sp]; + rho += rY_in(i, j, k, sp); + } + amrex::Real rho_inv = 1.0 / rho; + amrex::Real mass_frac[NUM_SPECIES] = {0.0}; + for (int sp = 0; sp < NUM_SPECIES; sp++) { + mass_frac[sp] = rY_in(i, j, k, sp) * rho_inv; + } + amrex::Real temp = T_in(i, j, k, 0); + + amrex::Real Enrg_loc = rEner_in(i, j, k, 0) * rho_inv; + auto eos = pele::physics::PhysicsType::eos(); + if (captured_reactor_type == ReactorTypes::e_reactor_type) { + eos.REY2T(rho, Enrg_loc, mass_frac, temp); + } else if (captured_reactor_type == ReactorTypes::h_reactor_type) { + eos.RHY2T(rho, Enrg_loc, mass_frac, temp); + } else { + amrex::Abort("Wrong reactor type. Choose between 1 (e) or 2 (h)."); + } + soln_reg[NUM_SPECIES] = temp; + carryover_reg[NUM_SPECIES] = soln_reg[NUM_SPECIES]; + + amrex::Real dt_rk = dt_react / amrex::Real(captured_nsubsteps_guess); + amrex::Real dt_rk_min = dt_react / amrex::Real(captured_nsubsteps_max); + amrex::Real dt_rk_max = dt_react / amrex::Real(captured_nsubsteps_min); + + amrex::Real rhoe_init[] = {rEner_in(i, j, k, 0)}; + amrex::Real rhoesrc_ext[] = {rEner_src_in(i, j, k, 0)}; + + for (int sp = 0; sp < NUM_SPECIES; sp++) { + rYsrc[sp] = rY_src_in(i, j, k, sp); + } + + int nsteps = 0; + amrex::Real change_factor; + while (current_time < time_out) { + for (double& sp : error_reg) { + sp = 0.0; + } + for (int stage = 0; stage < rkp.nstages_rk64; stage++) { + utils::fKernelSpec( + 0, 1, current_time - time_init, captured_reactor_type, soln_reg, rhs, + rhoe_init, rhoesrc_ext, rYsrc); + + for (int sp = 0; sp < neq; sp++) { + error_reg[sp] += rkp.err_rk64[stage] * dt_rk * rhs[sp]; + soln_reg[sp] = + carryover_reg[sp] + rkp.alpha_rk64[stage] * dt_rk * rhs[sp]; + carryover_reg[sp] = + soln_reg[sp] + rkp.beta_rk64[stage] * dt_rk * rhs[sp]; + } + } + + current_time += dt_rk; + nsteps++; + + amrex::Real max_err = tinyval; + for (double sp : error_reg) { + max_err = fabs(sp) > max_err ? fabs(sp) : max_err; + } + + if (max_err < captured_abstol) { + change_factor = + rkp.betaerr_rk64 * pow((captured_abstol / max_err), rkp.exp1_rk64); + dt_rk = amrex::min(dt_rk_max, dt_rk * change_factor); + } else { + change_factor = + rkp.betaerr_rk64 * pow((captured_abstol / max_err), rkp.exp2_rk64); + dt_rk = amrex::max(dt_rk_min, dt_rk * change_factor); + } + } + + // copy data back + int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); + d_nsteps[icell] = nsteps; + rho = 0.0; + for (int sp = 0; sp < NUM_SPECIES; sp++) { + rY_in(i, j, k, sp) = soln_reg[sp]; + rho += rY_in(i, j, k, sp); + } + rho_inv = 1.0 / rho; + for (int sp = 0; sp < NUM_SPECIES; sp++) { + mass_frac[sp] = rY_in(i, j, k, sp) * rho_inv; + } + temp = soln_reg[NUM_SPECIES]; + rEner_in(i, j, k, 0) = rhoe_init[0] + dt_react * rhoesrc_ext[0]; + Enrg_loc = rEner_in(i, j, k, 0) * rho_inv; + + if (captured_reactor_type == ReactorTypes::e_reactor_type) { + eos.REY2T(rho, Enrg_loc, mass_frac, temp); + } else if (captured_reactor_type == ReactorTypes::h_reactor_type) { + eos.RHY2T(rho, Enrg_loc, mass_frac, temp); + } else { + amrex::Abort("Wrong reactor type. Choose between 1 (e) or 2 (h)."); + } + T_in(i, j, k, 0) = temp; + FC_in(i, j, k, 0) = nsteps; + }); + +#ifdef MOD_REACTOR + time = time_out; +#endif + + const int avgsteps = amrex::Reduce::Sum( + Ncells, [=] AMREX_GPU_DEVICE(int i) noexcept -> int { return d_nsteps[i]; }, + 0); + return (int(avgsteps / amrex::Real(Ncells))); +} + +void +ReactorRK64::SetTypValsODE(const std::vector& /*ExtTypVals*/) +{ + amrex::Print() << "WARNING: ignoring TypVals for this reactor." << std::endl; +} +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/ReactorTypes.H b/Reactions/ReactorTypes.H new file mode 100644 index 000000000..11fc18911 --- /dev/null +++ b/Reactions/ReactorTypes.H @@ -0,0 +1,25 @@ +#ifndef _REACTORTYPES_H_ +#define _REACTORTYPES_H_ + +#include + +namespace pele { +namespace physics { +namespace reactions { + +struct ReactorTypes +{ + static constexpr int e_reactor_type = 1; + static constexpr int h_reactor_type = 2; + static void check_reactor_type(const int reactor_type) + { + if (!((reactor_type == ReactorTypes::e_reactor_type) || + (reactor_type == ReactorTypes::h_reactor_type))) { + amrex::Abort("Wrong reactor type. Choose between 1 (e) or 2 (h)."); + } + } +}; +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorUtils.H b/Reactions/ReactorUtils.H new file mode 100644 index 000000000..09c87fba3 --- /dev/null +++ b/Reactions/ReactorUtils.H @@ -0,0 +1,286 @@ +#ifndef _REACTORUTILS_H_ +#define _REACTORUTILS_H_ + +#include +#include +#include "mechanism.H" +#include "PelePhysics.H" +#include "ReactorTypes.H" + +namespace pele { +namespace physics { +namespace reactions { +namespace utils { +int check_flag(void* flagvalue, const char* funcname, int opt); + +struct YCOrder +{ + // default: [ [Y_0,...Y_n]_{cell 0}, ..., [Y_0,...Y_n]_{cell m}] + using ordering_type = YCOrder; +}; + +struct CYOrder +{ + // [ [Y_{cell 0},...Y_m]_{species 0}, ..., [Y_{cell 0},...Y_m]_{species n}] + using ordering_type = CYOrder; +}; + +template +struct is_ordering_type +{ + static constexpr bool value = + std::is_base_of::value; +}; + +template +AMREX_GPU_DEVICE AMREX_FORCE_INLINE int +vec_index(const int specie_idx, const int icell, const int /*ncells*/) +{ + return icell * (NUM_SPECIES + 1) + specie_idx; +} + +template +AMREX_GPU_DEVICE AMREX_FORCE_INLINE int +spec_index(const int specie_idx, const int icell, const int /*ncells*/) +{ + return icell * NUM_SPECIES + specie_idx; +} + +template <> +AMREX_GPU_DEVICE AMREX_FORCE_INLINE int +vec_index(const int specie_idx, const int icell, const int ncells) +{ + return specie_idx * ncells + icell; +} + +template <> +AMREX_GPU_DEVICE AMREX_FORCE_INLINE int +spec_index(const int specie_idx, const int icell, const int ncells) +{ + return vec_index(specie_idx, icell, ncells); +} + +template +AMREX_GPU_DEVICE AMREX_FORCE_INLINE void +box_flatten( + const int icell, + const int i, + const int j, + const int k, + const int ncells, + const int reactor_type, + amrex::Array4 const& rhoY, + amrex::Array4 const& frcExt, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Real* y_vect, + amrex::Real* src_vect, + amrex::Real* vect_energy, + amrex::Real* src_vect_energy) +{ + amrex::Real mass_frac[NUM_SPECIES]; + amrex::Real rho = 0.0; + for (int n = 0; n < NUM_SPECIES; n++) { + const int idx = vec_index(n, icell, ncells); + const int idx2 = spec_index(n, icell, ncells); + const amrex::Real rhoYn = rhoY(i, j, k, n); + y_vect[idx] = rhoYn; + src_vect[idx2] = frcExt(i, j, k, n); + rho += rhoYn; + mass_frac[n] = rhoYn; + } + const amrex::Real rho_inv = 1.0 / rho; + for (int n = 0; n < NUM_SPECIES; n++) { + mass_frac[n] *= rho_inv; + } + + amrex::Real temp = temperature(i, j, k, 0); + vect_energy[icell] = rhoE(i, j, k, 0); + src_vect_energy[icell] = frcEExt(i, j, k, 0); + + amrex::Real Enrg_loc = vect_energy[icell] * rho_inv; + auto eos = pele::physics::PhysicsType::eos(); + if (reactor_type == ReactorTypes::e_reactor_type) { + eos.REY2T(rho, Enrg_loc, mass_frac, temp); + } else if (reactor_type == ReactorTypes::h_reactor_type) { + eos.RHY2T(rho, Enrg_loc, mass_frac, temp); + } else { + amrex::Abort("Wrong reactor type. Choose between 1 (e) or 2 (h)."); + } + y_vect[vec_index(NUM_SPECIES, icell, ncells)] = temp; +} + +template +AMREX_GPU_DEVICE AMREX_FORCE_INLINE void +box_unflatten( + const int icell, + const int i, + const int j, + const int k, + const int ncells, + const int reactor_type, + amrex::Array4 const& rhoY, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Array4 const& FC_in, + amrex::Real* y_vect, + amrex::Real* vect_energy, + long int const& FCunt, + amrex::Real dt) +{ + amrex::Real mass_frac[NUM_SPECIES]; + amrex::Real rho = 0.0; + for (int n = 0; n < NUM_SPECIES; n++) { + const amrex::Real rhoYn = y_vect[vec_index(n, icell, ncells)]; + rhoY(i, j, k, n) = rhoYn; + rho += rhoYn; + mass_frac[n] = rhoYn; + } + const amrex::Real rho_inv = 1.0 / rho; + for (int n = 0; n < NUM_SPECIES; n++) { + mass_frac[n] *= rho_inv; + } + + amrex::Real temp = y_vect[vec_index(NUM_SPECIES, icell, ncells)]; + rhoE(i, j, k, 0) = vect_energy[icell] + dt * frcEExt(i, j, k, 0); + + amrex::Real Enrg_loc = rhoE(i, j, k, 0) * rho_inv; + auto eos = pele::physics::PhysicsType::eos(); + if (reactor_type == ReactorTypes::e_reactor_type) { + eos.REY2T(rho, Enrg_loc, mass_frac, temp); + } else if (reactor_type == ReactorTypes::h_reactor_type) { + eos.RHY2T(rho, Enrg_loc, mass_frac, temp); + } else { + amrex::Abort("Wrong reactor type. Choose between 1 (e) or 2 (h)."); + } + temperature(i, j, k, 0) = temp; + FC_in(i, j, k, 0) = FCunt; +} + +template +class FlattenOps +{ +public: + static_assert( + is_ordering_type::value, + "FlattenOps must have ordering type as its template argument"); + + void flatten( + const amrex::Box box, + const int ncells, + const int reactor_type, + amrex::Array4 const& rhoY, + amrex::Array4 const& frcExt, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Real* y_vect, + amrex::Real* src_vect, + amrex::Real* vect_energy, + amrex::Real* src_vect_energy) + { + BL_PROFILE("Pele::flatten()"); + const auto len = amrex::length(box); + const auto lo = amrex::lbound(box); + amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + const int icell = + (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); + box_flatten( + icell, i, j, k, ncells, reactor_type, rhoY, frcExt, temperature, rhoE, + frcEExt, y_vect, src_vect, vect_energy, src_vect_energy); + }); + } + + void unflatten( + const amrex::Box box, + const int ncells, + const int reactor_type, + amrex::Array4 const& rhoY, + amrex::Array4 const& temperature, + amrex::Array4 const& rhoE, + amrex::Array4 const& frcEExt, + amrex::Array4 const& FC_in, + amrex::Real* y_vect, + amrex::Real* vect_energy, + long int* FCunt, + amrex::Real dt) + { + BL_PROFILE("Pele::unflatten()"); + const auto len = amrex::length(box); + const auto lo = amrex::lbound(box); + amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + const int icell = + (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); + box_unflatten( + icell, i, j, k, ncells, reactor_type, rhoY, temperature, rhoE, frcEExt, + FC_in, y_vect, vect_energy, FCunt[icell], dt); + }); + } +}; + +template +AMREX_GPU_DEVICE AMREX_FORCE_INLINE void +fKernelSpec( + const int icell, + const int ncells, + const double dt_save, + const int reactor_type, + amrex::Real* yvec_d, + amrex::Real* ydot_d, + amrex::Real* rhoe_init, + amrex::Real* rhoesrc_ext, + amrex::Real* rYs) +{ + amrex::Real rho_pt = 0.0; + amrex::GpuArray massfrac = {0.0}; + for (int n = 0; n < NUM_SPECIES; n++) { + massfrac[n] = yvec_d[vec_index(n, icell, ncells)]; + rho_pt += massfrac[n]; + } + const amrex::Real rho_pt_inv = 1.0 / rho_pt; + + for (int n = 0; n < NUM_SPECIES; n++) { + massfrac[n] *= rho_pt_inv; + } + + const amrex::Real nrg_pt = + (rhoe_init[icell] + rhoesrc_ext[icell] * dt_save) * rho_pt_inv; + + amrex::Real temp_pt = + yvec_d[vec_index(NUM_SPECIES, icell, ncells)]; + + amrex::Real Cv_pt = 0.0; + amrex::GpuArray ei_pt = {0.0}; + auto eos = pele::physics::PhysicsType::eos(); + if (reactor_type == ReactorTypes::e_reactor_type) { + eos.REY2T(rho_pt, nrg_pt, massfrac.arr, temp_pt); + eos.RTY2Ei(rho_pt, temp_pt, massfrac.arr, ei_pt.arr); + eos.RTY2Cv(rho_pt, temp_pt, massfrac.arr, Cv_pt); + } else if (reactor_type == ReactorTypes::h_reactor_type) { + eos.RHY2T(rho_pt, nrg_pt, massfrac.arr, temp_pt); + eos.RTY2Hi(rho_pt, temp_pt, massfrac.arr, ei_pt.arr); + eos.RTY2Cp(rho_pt, temp_pt, massfrac.arr, Cv_pt); + } else { + amrex::Abort("Wrong reactor type. Choose between 1 (e) or 2 (h)."); + } + + amrex::GpuArray cdots_pt = {0.0}; + eos.RTY2WDOT(rho_pt, temp_pt, massfrac.arr, cdots_pt.arr); + + amrex::Real rhoesrc = rhoesrc_ext[icell]; + for (int n = 0; n < NUM_SPECIES; n++) { + const amrex::Real cdot_rYs = + cdots_pt[n] + rYs[spec_index(n, icell, ncells)]; + ydot_d[vec_index(n, icell, ncells)] = cdot_rYs; + rhoesrc -= cdot_rYs * ei_pt[n]; + } + ydot_d[vec_index(NUM_SPECIES, icell, ncells)] = + rhoesrc * (rho_pt_inv / Cv_pt); +} +} // namespace utils +} // namespace reactions +} // namespace physics +} // namespace pele +#endif diff --git a/Reactions/ReactorUtils.cpp b/Reactions/ReactorUtils.cpp new file mode 100644 index 000000000..f62db3fa5 --- /dev/null +++ b/Reactions/ReactorUtils.cpp @@ -0,0 +1,55 @@ +#include "ReactorUtils.H" + +namespace pele { +namespace physics { +namespace reactions { +namespace utils { + +// Check function return value... +// opt == 0 means SUNDIALS function allocates memory so check if +// returned NULL pointer +// opt == 1 means SUNDIALS function returns a flag so check if +// flag >= 0 +// opt == 2 means function allocates memory so check if returned +// NULL pointer +int +check_flag(void* flagvalue, const char* funcname, int opt) +{ + int* errflag; + + if (opt == 0 && flagvalue == nullptr) { + if (amrex::ParallelDescriptor::IOProcessor()) { + fprintf( + stderr, "\nSUNDIALS_ERROR: %s() failed - returned NULL pointer\n\n", + funcname); + amrex::Abort("abort"); + } + return (1); + } + if (opt == 1) { + errflag = (int*)flagvalue; + if (*errflag < 0) { + if (amrex::ParallelDescriptor::IOProcessor()) { + fprintf( + stderr, "\nSUNDIALS_ERROR: %s() failed with flag = %d\n\n", funcname, + *errflag); + amrex::Abort("abort"); + } + return (1); + } + } else if (opt == 2 && flagvalue == nullptr) { + if (amrex::ParallelDescriptor::IOProcessor()) { + fprintf( + stderr, "\nMEMORY_ERROR: %s() failed - returned NULL pointer\n\n", + funcname); + amrex::Abort("abort"); + } + return (1); + } + + return (0); +} +} // namespace utils +} // namespace reactions +} // namespace physics +} // namespace pele diff --git a/Reactions/arkode/Make.package b/Reactions/arkode/Make.package deleted file mode 100644 index 85fd13b82..000000000 --- a/Reactions/arkode/Make.package +++ /dev/null @@ -1,2 +0,0 @@ -CEXE_headers += reactor_utils.H -CEXE_sources += reactor_arkode.cpp diff --git a/Reactions/arkode/reactor_utils.H b/Reactions/arkode/reactor_utils.H deleted file mode 100644 index 0714e64dc..000000000 --- a/Reactions/arkode/reactor_utils.H +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _REACTOR_UTILS_H_ -#define _REACTOR_UTILS_H_ - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE int -sunvec_index(const int specie_idx, const int icell, const int ncells) -{ - return specie_idx * ncells + icell; -} - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE int -sunspec_index(const int specie_idx, const int icell, const int ncells) -{ - return sunvec_index(specie_idx, icell, ncells); -} -#endif diff --git a/Reactions/cvode/Make.package b/Reactions/cvode/Make.package deleted file mode 100644 index 640e0ea07..000000000 --- a/Reactions/cvode/Make.package +++ /dev/null @@ -1,6 +0,0 @@ -CEXE_headers += reactor_utils.H -ifneq (, $(filter TRUE, $(USE_CUDA) $(USE_HIP))) - CEXE_sources += reactor_cvode_GPU.cpp -else - CEXE_sources += reactor_cvode_CPU.cpp -endif diff --git a/Reactions/cvode/reactor_cvode_CPU.cpp b/Reactions/cvode/reactor_cvode_CPU.cpp deleted file mode 100644 index c63bcf0a1..000000000 --- a/Reactions/cvode/reactor_cvode_CPU.cpp +++ /dev/null @@ -1,2287 +0,0 @@ -#include "reactor.H" - -using namespace amrex; - -#define SUN_CUSP_CONTENT(S) ((SUNLinearSolverContent_Sparse_custom)(S->content)) -#define SUN_CUSP_REACTYPE(S) (SUN_CUSP_CONTENT(S)->reactor_type) -#define SUN_CUSP_NUM_SUBSYS(S) (SUN_CUSP_CONTENT(S)->nsubsys) -#define SUN_CUSP_SUBSYS_NNZ(S) (SUN_CUSP_CONTENT(S)->subsys_nnz) -#define SUN_CUSP_SUBSYS_SIZE(S) (SUN_CUSP_CONTENT(S)->subsys_size) - -N_Vector y = NULL; -SUNLinearSolver LS = NULL; -SUNMatrix A = NULL; -void* cvode_mem = NULL; -CVODEUserData *data = NULL; - -#ifdef AMREX_USE_OMP -#pragma omp threadprivate(y, LS, A) -#pragma omp threadprivate(cvode_mem, data) -#endif - -void ReSetTolODE() -{ - int omp_thread = 0; -#ifdef AMREX_USE_OMP - omp_thread = omp_get_thread_num(); -#endif - - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - data != NULL, "Reactor object is not initialized !!"); - - int neq_tot = (NUM_SPECIES + 1) * data->ncells; - N_Vector atol = N_VNew_Serial(neq_tot); - realtype* ratol = N_VGetArrayPointer(atol); - - if (typVals[0] > 0) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "Setting CVODE tolerances rtol = " << relTol - << " atolfact = " << absTol << " in PelePhysics \n"; - } - for (int i = 0; i < data->ncells; i++) { - int offset = i * (NUM_SPECIES + 1); - for (int k = 0; k < NUM_SPECIES + 1; k++) { - ratol[offset + k] = typVals[k] * absTol; - } - } - } else { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "Setting CVODE tolerances rtol = " << relTol - << " atol = " << absTol << " in PelePhysics \n"; - } - for (int i = 0; i < neq_tot; i++) { - ratol[i] = absTol; - } - } - // Call CVodeSVtolerances to specify the scalar relative tolerance and vector - // absolute tolerances - int flag = CVodeSVtolerances(cvode_mem, relTol, atol); - if (check_flag(&flag, "CVodeSVtolerances", 1)) { - Abort("Problem in ReSetTolODE"); - } - - N_VDestroy(atol); -} - -void cvodeErrHandler( - int error_code, - const char* module, - const char* function, - char* msg, - void* eh_data) -{ - if (error_code != CV_WARNING) - { - std::cout << "From CVODE: " << msg << std::endl; - Abort("Bad CVODE"); - } -} - -// Initialization routine, called once at the begining of the problem -int reactor_init(int reactor_type, int ode_ncells) -{ - - BL_PROFILE_VAR("reactInit", reactInit); - - int omp_thread = 0; -#ifdef AMREX_USE_OMP - omp_thread = omp_get_thread_num(); -#endif - // Total number of eq to integrate - int neq_tot = (NUM_SPECIES + 1) * ode_ncells; - - y = N_VNew_Serial(neq_tot); - if (check_flag((void*)y, "N_VNew_Serial", 0)) - return (1); - - // Call CVodeCreate to create the solver memory and specify the Backward - // Differentiation Formula and the use of a Newton iteration - cvode_mem = CVodeCreate(CV_BDF); - if (check_flag((void*)cvode_mem, "CVodeCreate", 0)) - return (1); - - // Does not work for more than 1 cell right now - data = AllocUserData(reactor_type, ode_ncells); - if (check_flag((void*)data, "AllocUserData", 2)) - return (1); - - // Number of species and cells in mechanism - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "Number of species in mech is " << NUM_SPECIES << "\n"; - Print() << "Number of cells in one solve is " << data->ncells << "\n"; - } - - // Set the pointer to user-defined data - int flag = CVodeSetUserData(cvode_mem, data); - if (check_flag(&flag, "CVodeSetUserData", 1)) - return (1); - - realtype time = 0.0e+0; - // Call CVodeInit to initialize the integrator memory and specify the user's - // right hand side function, the inital time, and initial dependent variable - // vector y. - flag = CVodeInit(cvode_mem, cF_RHS, time, y); - if (check_flag(&flag, "CVodeInit", 1)) - return (1); - - // Definition of tolerances: one for each species - N_Vector atol = N_VNew_Serial(neq_tot); - realtype* ratol = N_VGetArrayPointer(atol); - if (typVals[0] > 0) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "Setting CVODE tolerances rtol = " << relTol - << " atolfact = " << absTol << " in PelePhysics \n"; - } - for (int i = 0; i < data->ncells; i++) { - int offset = i * (NUM_SPECIES + 1); - for (int k = 0; k < NUM_SPECIES + 1; k++) { - // ratol[offset + k] = std::max(typVals[k]*absTol,relTol); - ratol[offset + k] = typVals[k] * absTol; - } - } - } else { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "Setting CVODE tolerances rtol = " << relTol - << " atol = " << absTol << " in PelePhysics \n"; - } - for (int i = 0; i < neq_tot; i++) { - ratol[i] = absTol; - } - } - // Call CVodeSVtolerances to specify the scalar relative tolerance and vector - // absolute tolerances - flag = CVodeSVtolerances(cvode_mem, relTol, atol); - if (check_flag(&flag, "CVodeSVtolerances", 1)) - return (1); - - // flag = CVodeSetNonlinConvCoef(cvode_mem, 1.0e-1); - // if (check_flag(&flag, "CVodeSetNonlinConvCoef", 1)) return(1); - - flag = CVodeSetMaxNonlinIters(cvode_mem, 50); - if (check_flag(&flag, "CVodeSetMaxNonlinIters", 1)) - return (1); - - flag = CVodeSetMaxErrTestFails(cvode_mem, 100); - if (check_flag(&flag, "CVodeSetMaxErrTestFails", 1)) - return (1); - - flag = CVodeSetErrHandlerFn(cvode_mem, cvodeErrHandler, 0); - if (check_flag(&flag, "CVodeSetErrHandlerFn", 1)) - return (1); - - if (data->isolve_type == dense_solve) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "\n--> Using a Direct Dense Solver\n"; - } - // Create dense SUNMatrix for use in linear solves - A = SUNDenseMatrix(neq_tot, neq_tot); - if (check_flag((void*)A, "SUNDenseMatrix", 0)) - return (1); - - // Create dense SUNLinearSolver object for use by CVode - LS = SUNDenseLinearSolver(y, A); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - - // Call CVDlsSetLinearSolver to attach the matrix and linear solver to CVode - flag = CVDlsSetLinearSolver(cvode_mem, LS, A); - if (check_flag(&flag, "CVDlsSetLinearSolver", 1)) - return (1); - - } else if (data->isolve_type == sparse_custom_solve) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "\n--> Using a custom Direct Sparse Solver\n"; - } - // Create dense SUNMatrix for use in linear solves - A = SUNSparseMatrix(neq_tot, neq_tot, (data->NNZ) * data->ncells, CSR_MAT); - if (check_flag((void*)A, "SUNDenseMatrix", 0)) - return (1); - - // Create dense SUNLinearSolver object for use by CVode - LS = SUNLinSol_sparse_custom( - y, A, reactor_type, data->ncells, (NUM_SPECIES + 1), data->NNZ); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - - // Call CVDlsSetLinearSolver to attach the matrix and linear solver to CVode - flag = CVDlsSetLinearSolver(cvode_mem, LS, A); - if (check_flag(&flag, "CVDlsSetLinearSolver", 1)) - return (1); - - } else if (data->isolve_type == sparse_solve) { -#ifdef USE_KLU_PP - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "\n--> Using a Direct Sparse Solver\n"; - } - // Create sparse SUNMatrix for use in linear solves - A = SUNSparseMatrix(neq_tot, neq_tot, (data->NNZ) * data->ncells, CSC_MAT); - if (check_flag((void*)A, "SUNSparseMatrix", 0)) - return (1); - - // Create KLU solver object for use by CVode - LS = SUNLinSol_KLU(y, A); - if (check_flag((void*)LS, "SUNLinSol_KLU", 0)) - return (1); - - // Call CVodeSetLinearSolver to attach the matrix and linear solver to CVode - flag = CVodeSetLinearSolver(cvode_mem, LS, A); - if (check_flag(&flag, "CVodeSetLinearSolver", 1)) - return (1); -#else - Abort("Sparse solver not valid without KLU solver."); -#endif - - } else if ( - (data->isolve_type == iterative_gmres_solve) || - (data->isolve_type == iterative_gmres_solve_custom)) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << "\n--> Using an Iterative Solver (" << data->isolve_type - << ")\n"; - } - - // Create the linear solver object - if (data->ianalytical_jacobian == 0) { - LS = SUNLinSol_SPGMR(y, PREC_NONE, 0); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - } else { - LS = SUNLinSol_SPGMR(y, PREC_LEFT, 0); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - } - - // Set CVSpils linear solver to LS - flag = CVSpilsSetLinearSolver(cvode_mem, LS); - if (check_flag(&flag, "CVSpilsSetLinearSolver", 1)) - return (1); - } else { - Abort("Wrong choice of linear solver..."); - } - - if (data->ianalytical_jacobian == 0) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << " Without Analytical J/Preconditioner\n"; - } -#ifdef USE_KLU_PP - if (data->isolve_type == sparse_solve) { - Abort("Sparse Solver requires an Analytical J"); - } -#endif - if (data->isolve_type == sparse_custom_solve) { - Abort("Custom sparse solver requires an Analytical J"); - } - } else { - if (data->isolve_type == iterative_gmres_solve_custom) { - // Set the JAcobian-times-vector function - flag = CVSpilsSetJacTimes(cvode_mem, NULL, NULL); - if (check_flag(&flag, "CVSpilsSetJacTimes", 1)) - return (1); - - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << " With a custom Sparse Preconditioner\n"; - } - // Set the preconditioner solve and setup functions - flag = CVSpilsSetPreconditioner(cvode_mem, Precond_custom, PSolve_custom); - if (check_flag(&flag, "CVSpilsSetPreconditioner", 1)) - return (1); - - } else if (data->isolve_type == iterative_gmres_solve) { - // Set the JAcobian-times-vector function - flag = CVSpilsSetJacTimes(cvode_mem, NULL, NULL); - if (check_flag(&flag, "CVSpilsSetJacTimes", 1)) - return (1); -#ifdef USE_KLU_PP - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << " With a Sparse Preconditioner\n"; - } - // Set the preconditioner solve and setup functions - flag = CVSpilsSetPreconditioner(cvode_mem, Precond_sparse, PSolve_sparse); - if (check_flag(&flag, "CVSpilsSetPreconditioner", 1)) - return (1); -#else - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << " With a Preconditioner\n"; - } - // Set the preconditioner solve and setup functions - flag = CVSpilsSetPreconditioner(cvode_mem, Precond, PSolve); - if (check_flag(&flag, "CVSpilsSetPreconditioner", 1)) - return (1); -#endif -#ifdef USE_KLU_PP - } else if (data->isolve_type == sparse_solve) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << " With a Sparse Analytical J\n"; - } - // Set the user-supplied Jacobian routine Jac - flag = CVodeSetJacFn(cvode_mem, cJac_KLU); - if (check_flag(&flag, "CVodeSetJacFn", 1)) - return (1); -#endif - } else if (data->isolve_type == dense_solve) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << " With Analytical J\n"; - } - // Set the user-supplied Jacobian routine Jac - flag = CVodeSetJacFn(cvode_mem, cJac); - if (check_flag(&flag, "CVodeSetJacFn", 1)) - return (1); - - } else if (data->isolve_type == sparse_custom_solve) { - if ((data->iverbose > 0) && (omp_thread == 0)) { - Print() << " With a Sparse Analytical J\n"; - } - // Set the user-supplied Jacobian routine Jac - flag = CVodeSetJacFn(cvode_mem, cJac_sps); - if (check_flag(&flag, "CVodeSetJacFn", 1)) - return (1); - } - } - - // Set the max number of time steps - flag = CVodeSetMaxNumSteps(cvode_mem, 10000); - if (check_flag(&flag, "CVodeSetMaxNumSteps", 1)) - return (1); - - // Set the max order - flag = CVodeSetMaxOrd(cvode_mem, 2); - if (check_flag(&flag, "CVodeSetMaxOrd", 1)) - return (1); - - // Set the num of steps to wait inbetween Jac evals - flag = CVodeSetJacEvalFrequency(cvode_mem, 100); - if (check_flag(&flag, "CVodeSetJacEvalFrequency", 1)) - return (1); - - N_VDestroy(atol); - - if ((data->iverbose > 1) && (omp_thread == 0)) { - Print() << "\n--> DONE WITH INITIALIZATION (CPU)" << data->ireactor_type - << "\n"; - } - - data->reactor_cvode_initialized = true; - - BL_PROFILE_VAR_STOP(reactInit); - - return (0); -} - -// Main routine for CVode integration: integrate a Box version -int -react( - const Box& box, - Array4 const& rY_in, - Array4 const& rY_src_in, - Array4 const& T_in, - Array4 const& rEner_in, - Array4 const& rEner_src_in, - Array4 const& FC_in, - Array4 const& mask, - Real& dt_react, - Real& time, - const int& reactor_type) -{ - - int omp_thread = 0; -#ifdef AMREX_USE_OMP - omp_thread = omp_get_thread_num(); -#endif - - if ((data->iverbose > 1) && (omp_thread == 0)) { - Print() << "\n -------------------------------------\n"; - } - - // Initial time and time to reach after integration - time_init = time; - - if ((data->iverbose > 3) && (omp_thread == 0)) { - Print() << "BEG : time curr is " << time_init << " and dt_react is " - << dt_react << " and final time should be " << time_init + dt_react - << "\n"; - } - - if (data->ncells != 1) { - Abort("CVODE react can only integrate one cell at a time"); - } - int box_ncells = box.numPts(); - data->boxcell = 0; - - if ((data->iverbose > 2) && (omp_thread == 0)) { - Print() << "Ncells in the box = " << box_ncells << "\n"; - } - - // Perform integration one cell at a time - ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (mask(i, j, k) != -1) { - Real mass_frac[NUM_SPECIES]; - Real rho = 0.0; - Real rho_inv; - Real Enrg_loc; - Real temp; - - realtype* yvec_d = N_VGetArrayPointer(y); - - BL_PROFILE_VAR("reactor::FlatStuff", FlatStuff); - for (int n = 0; n < NUM_SPECIES; n++) { - yvec_d[n] = rY_in(i, j, k, n); - data->rYsrc[n] = rY_src_in(i, j, k, n); - rho += yvec_d[n]; - } - rho_inv = 1.0 / rho; - temp = T_in(i, j, k, 0); - data->rhoX_init[0] = rEner_in(i, j, k, 0); - data->rhoXsrc_ext[0] = rEner_src_in(i, j, k, 0); - - // T update with energy and Y - for (int n = 0; n < NUM_SPECIES; n++) { - mass_frac[n] = yvec_d[n] * rho_inv; - } - Enrg_loc = data->rhoX_init[0] * rho_inv; - auto eos = pele::physics::PhysicsType::eos(); - if (data->ireactor_type == 1) { - eos.REY2T(rho, Enrg_loc, mass_frac, temp); - } else { - eos.RHY2T(rho, Enrg_loc, mass_frac, temp); - } - yvec_d[NUM_SPECIES] = temp; - BL_PROFILE_VAR_STOP(FlatStuff); - - // ReInit CVODE is faster - CVodeReInit(cvode_mem, time_init, y); - - // Time to reach after integration - Real time_out_lcl = time_init + dt_react; - - // Integration - Real dummy_time; - BL_PROFILE_VAR("reactor::AroundCVODE", AroundCVODE); - CVode(cvode_mem, time_out_lcl, y, &dummy_time, CV_NORMAL); - BL_PROFILE_VAR_STOP(AroundCVODE); - - if ((data->iverbose > 1) && (omp_thread == 0)) { - Print() << "Additional verbose info --\n"; - PrintFinalStats(cvode_mem, yvec_d[NUM_SPECIES]); - Print() << "\n -------------------------------------\n"; - } - - // Get estimate of how hard the integration process was - long int nfe, nfeLS; - CVodeGetNumRhsEvals(cvode_mem, &nfe); - CVodeGetNumLinRhsEvals(cvode_mem, &nfeLS); - FC_in(i, j, k, 0) = nfe + nfeLS; - - BL_PROFILE_VAR_START(FlatStuff); - rho = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { - rY_in(i, j, k, n) = yvec_d[n]; - rho += yvec_d[n]; - } - rho_inv = 1.0 / rho; - temp = yvec_d[NUM_SPECIES]; - - // T update with energy and Y - for (int n = 0; n < NUM_SPECIES; n++) { - mass_frac[n] = yvec_d[n] * rho_inv; - } - rEner_in(i, j, k, 0) = - data->rhoX_init[0] + (dummy_time - time_init) * data->rhoXsrc_ext[0]; - Enrg_loc = rEner_in(i, j, k, 0) * rho_inv; - if (data->ireactor_type == 1) { - eos.REY2T(rho, Enrg_loc, mass_frac, temp); - } else { - eos.RHY2T(rho, Enrg_loc, mass_frac, temp); - } - T_in(i, j, k, 0) = temp; - BL_PROFILE_VAR_STOP(FlatStuff); - - if ((data->iverbose > 3) && (omp_thread == 0)) { - Print() << "END : time curr is " << dummy_time - << " and actual dt_react is " << (dummy_time - time_init) - << "\n"; - } - } else { - FC_in(i, j, k, 0) = 0.0; - } - }); - - // Update dt_react with real time step taken ... - // should be very similar to input dt_react - // dt_react = dummy_time - time_init; -#ifdef MOD_REACTOR - // If reactor mode is activated, update time to perform subcycling - time = time_init + dt_react; -#endif - - // Get estimate of how hard the integration process was - return 20; -} - -// Main routine for CVode integration: integrate a Box version 2 -int -react_2( - const Box& box, - Array4 const& rY_in, - Array4 const& rY_src_in, - Array4 const& T_in, - Array4 const& rEner_in, - Array4 const& rEner_src_in, - Array4 const& FC_in, - Array4 const& mask_in, - Real& dt_react, - Real& time) -{ - - realtype dummy_time; - int flag; - int omp_thread = 0; -#ifdef AMREX_USE_OMP - omp_thread = omp_get_thread_num(); -#endif - - if ((data->iverbose > 1) && (omp_thread == 0)) { - Print() << "\n -------------------------------------\n"; - } - - // Initial time and time to reach after integration - time_init = time; - realtype time_out = time + dt_react; - - if ((data->iverbose > 3) && (omp_thread == 0)) { - Print() << "BEG : time curr is " << time_init << " and dt_react is " - << dt_react << " and final time should be " << time_out << "\n"; - } - - // Define full box_ncells length vectors to be integrated piece by piece by - // CVode - int box_ncells = box.numPts(); - if ((data->iverbose > 2) && (omp_thread == 0)) { - Print() << "Ncells in the box = " << box_ncells << "\n"; - } - BL_PROFILE_VAR("reactor::ExtForcingAlloc", ExtForcingAlloc); - (data->Yvect_full) = new amrex::Real[box_ncells * (NUM_SPECIES + 1)]; - (data->rYsrc) = new amrex::Real[box_ncells * (NUM_SPECIES)]; - (data->rhoX_init) = new amrex::Real[box_ncells]; - (data->rhoXsrc_ext) = new amrex::Real[box_ncells]; - (data->FCunt) = new int[box_ncells]; - (data->mask) = new int[box_ncells]; - BL_PROFILE_VAR_STOP(ExtForcingAlloc); - - BL_PROFILE_VAR("reactor::FlatStuff", FlatStuff); - // Fill the full box_ncells length vectors from input Array4 - const auto len = length(box); - const auto lo = lbound(box); - ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); - box_flatten( - icell, box_ncells, i, j, k, data->ireactor_type, rY_in, rY_src_in, T_in, rEner_in, - rEner_src_in, data->Yvect_full, data->rYsrc, data->rhoX_init, - data->rhoXsrc_ext); - }); - BL_PROFILE_VAR_STOP(FlatStuff); - - BL_PROFILE_VAR("reactor::AroundCVODE", AroundCVODE); - BL_PROFILE_VAR_STOP(AroundCVODE); - - // We may need extra cells to fill the fixed data->ncells in this case since - // we do not Init each time - int extra_cells = box_ncells - box_ncells / (data->ncells) * (data->ncells); - if ((data->iverbose > 2) && (omp_thread == 0)) { - Print() << " Extra cells = " << extra_cells << "\n"; - } - - // Integrate data->ncells at a time with CVode The extra cell machinery is not - // ope yet and most likely produce out of bound errors - realtype* yvec_d = N_VGetArrayPointer(y); - long int nfe, nfeLS; - for (int i = 0; i < box_ncells + extra_cells; i += data->ncells) { - if (data->mask[i] != -1) // TODO: this doesn't really work, but we are not - // using react_2, let alone react_2 + EB. - { - // Print() <<" dealing with cell " << i << "\n"; - int offset = i * (NUM_SPECIES + 1); - data->boxcell = i; - for (int k = 0; k < data->ncells * (NUM_SPECIES + 1); k++) { - yvec_d[k] = data->Yvect_full[offset + k]; - } - - // ReInit CVODE is faster - CVodeReInit(cvode_mem, time_init, y); - - BL_PROFILE_VAR_START(AroundCVODE); - // Integration - flag = CVode(cvode_mem, time_out, y, &dummy_time, CV_NORMAL); - if (check_flag(&flag, "CVode", 1)) - return (1); - BL_PROFILE_VAR_STOP(AroundCVODE); - - // Update full box length vector - for (int k = 0; k < data->ncells * (NUM_SPECIES + 1); k++) { - data->Yvect_full[offset + k] = yvec_d[k]; - } - - // Get estimate of how hard the integration process was - flag = CVodeGetNumRhsEvals(cvode_mem, &nfe); - flag = CVodeGetNumLinRhsEvals(cvode_mem, &nfeLS); - for (int k = 0; k < data->ncells; k++) { - data->FCunt[i + k] = nfe + nfeLS; - } - - if ((data->iverbose > 3) && (omp_thread == 0)) { - Print() << "END : time curr is " << dummy_time - << " and actual dt_react is " << (dummy_time - time_init) - << "\n"; - } - } else { - for (int k = 0; k < data->ncells; k++) { - data->FCunt[i + k] = 0.0; - } - } - } - -#ifdef MOD_REACTOR - // If reactor mode is activated, update time to perform subcycling - time = time_init + dt_react; -#endif - - BL_PROFILE_VAR_START(FlatStuff); - // Update the input/output Array4 rY_in and rEner_in - ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); - box_unflatten( - icell, box_ncells, i, j, k, data->ireactor_type, rY_in, T_in, rEner_in, rEner_src_in, - FC_in, data->Yvect_full, data->rhoX_init, nfe, dt_react); - }); - BL_PROFILE_VAR_STOP(FlatStuff); - - BL_PROFILE_VAR_START(ExtForcingAlloc); - delete[](data->Yvect_full); - delete[](data->rYsrc); - delete[](data->rhoX_init); - delete[](data->rhoXsrc_ext); - delete[](data->FCunt); - delete[](data->mask); - BL_PROFILE_VAR_STOP(ExtForcingAlloc); - - if ((data->iverbose > 1) && (omp_thread == 0)) { - Print() << "Additional verbose info --\n"; - PrintFinalStats(cvode_mem, yvec_d[NUM_SPECIES]); - Print() << "\n -------------------------------------\n"; - } - - // Get estimate of how hard the integration process was - //long int nfe, nfeLS; - flag = CVodeGetNumRhsEvals(cvode_mem, &nfe); - flag = CVodeGetNumLinRhsEvals(cvode_mem, &nfeLS); - return nfe + nfeLS; -} - -// Main routine for CVode integration: classic version -int -react( - realtype* rY_in, - realtype* rY_src_in, - realtype* rX_in, - realtype* rX_src_in, - realtype& dt_react, - realtype& time, - int reactor_type, - int Ncells) -{ - - realtype dummy_time; - int flag; - int omp_thread = 0; -#ifdef AMREX_USE_OMP - omp_thread = omp_get_thread_num(); -#endif - - if ((data->iverbose > 1) && (omp_thread == 0)) { - Print() << "\n -------------------------------------\n"; - } - - // Initial time and time to reach after integration - time_init = time; - realtype time_out = time + dt_react; - - if ((data->iverbose > 3) && (omp_thread == 0)) { - Print() << "BEG : time curr is " << time_init << " and dt_react is " - << dt_react << " and final time should be " << time_out << "\n"; - } - - // Define full box_ncells length vectors to be integrated piece by piece by - // CVode - if ((data->iverbose > 2) && (omp_thread == 0)) { - Print() << "Ncells in the box = " << Ncells << "\n"; - } - - BL_PROFILE_VAR("reactor::FlatStuff", FlatStuff); - // Get Device MemCpy of in arrays - // Get Device pointer of solution vector - realtype* yvec_d = N_VGetArrayPointer(y); - // rhoY,T - std::memcpy(yvec_d, rY_in, sizeof(Real) * ((NUM_SPECIES + 1) * Ncells)); - // rhoY_src_ext - std::memcpy( - data->rYsrc, rY_src_in, sizeof(Real) * (NUM_SPECIES * Ncells)); - // rhoE/rhoH - std::memcpy(data->rhoX_init, rX_in, sizeof(Real) * Ncells); - std::memcpy(data->rhoXsrc_ext, rX_src_in, sizeof(Real) * Ncells); - BL_PROFILE_VAR_STOP(FlatStuff); - - // Check if y is within physical bounds we may remove that eventually - check_state(y); - if (!(data->actual_ok_to_react)) { -#ifdef MOD_REACTOR - // If reactor mode is activated, update time - time = time_out; -#endif - return 0; - } - - BL_PROFILE_VAR_START(FlatStuff); - // T update with energy and Y - int offset; - realtype rho, rho_inv, nrg_loc, temp; - for (int i = 0; i < Ncells; i++) { - offset = i * (NUM_SPECIES + 1); - realtype* mass_frac = rY_in + offset; - // get rho - rho = 0; - for (int kk = 0; kk < NUM_SPECIES; kk++) { - rho += mass_frac[kk]; - } - rho_inv = 1 / rho; - // get Yks - for (int kk = 0; kk < NUM_SPECIES; kk++) { - mass_frac[kk] = mass_frac[kk] * rho_inv; - } - // get energy - nrg_loc = rX_in[i] * rho_inv; - // recompute T - temp = rY_in[offset + NUM_SPECIES]; - auto eos = pele::physics::PhysicsType::eos(); - if (reactor_type == eint_rho) { - eos.REY2T(rho, nrg_loc, mass_frac, temp); - } else { - eos.RHY2T(rho, nrg_loc, mass_frac, temp); - } - // store T in y - yvec_d[offset + NUM_SPECIES] = temp; - } - BL_PROFILE_VAR_STOP(FlatStuff); - - // ReInit CVODE is faster - CVodeReInit(cvode_mem, time_init, y); - - // There should be no internal looping of CVOde - data->boxcell = 0; - - BL_PROFILE_VAR("reactor::AroundCVODE", AroundCVODE); - flag = CVode(cvode_mem, time_out, y, &dummy_time, CV_NORMAL); - // ONE STEP MODE FOR DEBUGGING - // flag = CVode(cvode_mem, time_out, y, &dummy_time, CV_ONE_STEP); - if (check_flag(&flag, "CVode", 1)) - return (1); - BL_PROFILE_VAR_STOP(AroundCVODE); - - // Update dt_react with real time step taken ... should be very similar to - // input dt_react - dt_react = dummy_time - time_init; -#ifdef MOD_REACTOR - // If reactor mode is activated, update time - time = time_init + dt_react; -#endif - - if ((data->iverbose > 3) && (omp_thread == 0)) { - Print() << "END : time curr is " << dummy_time << " and actual dt_react is " - << dt_react << "\n"; - } - - BL_PROFILE_VAR_START(FlatStuff); - // Pack data to return in main routine external - std::memcpy( - rY_in, yvec_d, ((NUM_SPECIES + 1) * Ncells) * sizeof(realtype)); - for (int i = 0; i < Ncells; i++) { - rX_in[i] = rX_in[i] + dt_react * rX_src_in[i]; - } - - // T update with energy and Y - for (int i = 0; i < Ncells; i++) { - offset = i * (NUM_SPECIES + 1); - realtype* mass_frac = yvec_d + offset; - // get rho - rho = 0; - for (int kk = 0; kk < NUM_SPECIES; kk++) { - rho += mass_frac[kk]; - } - rho_inv = 1 / rho; - // get Yks - for (int kk = 0; kk < NUM_SPECIES; kk++) { - mass_frac[kk] = mass_frac[kk] * rho_inv; - } - // get energy - nrg_loc = rX_in[i] * rho_inv; - // recompute T - auto eos = pele::physics::PhysicsType::eos(); - if (reactor_type == eint_rho) { - eos.REY2T(rho, nrg_loc, mass_frac, temp); - } else { - eos.RHY2T(rho, nrg_loc, mass_frac, temp); - } - // store T in rY_in - rY_in[offset + NUM_SPECIES] = temp; - } - BL_PROFILE_VAR_STOP(FlatStuff); - - if ((data->iverbose > 1) && (omp_thread == 0)) { - Print() << "Additional verbose info --\n"; - PrintFinalStats(cvode_mem, rY_in[NUM_SPECIES]); - Print() << "\n -------------------------------------\n"; - } - - // Get estimate of how hard the integration process was - long int nfe, nfeLS; - flag = CVodeGetNumRhsEvals(cvode_mem, &nfe); - flag = CVodeGetNumLinRhsEvals(cvode_mem, &nfeLS); - return nfe + nfeLS; -} - -// RHS routine -int -cF_RHS(realtype t, N_Vector y_in, N_Vector ydot_in, void* user_data) -{ - - realtype* y_d = N_VGetArrayPointer(y_in); - realtype* ydot_d = N_VGetArrayPointer(ydot_in); - - CVODEUserData* udata = static_cast(user_data); - int icell=0; - - udata->dt_save = t; - - BL_PROFILE_VAR("fKernelSpec()", fKernelSpec); - fKernelSpec(icell,udata->ncells, udata->dt_save, udata->ireactor_type, - y_d, ydot_d, udata->rhoX_init, - udata->rhoXsrc_ext, udata->rYsrc); - BL_PROFILE_VAR_STOP(fKernelSpec); - - return (0); -} - -// RHS source terms evaluation -void -fKernelSpec(realtype* t, realtype* yvec_d, realtype* ydot_d, void* user_data) -{ - // Make local copies of pointers in user_data (cell M) - CVODEUserData *data_wk = (CVODEUserData *)user_data; - - // Loop on packed cells - for (int tid = 0; tid < data_wk->ncells; tid++) { - // Tmp vars - realtype massfrac[NUM_SPECIES]; - realtype Xi[NUM_SPECIES]; - realtype cdot[NUM_SPECIES], molecular_weight[NUM_SPECIES]; - realtype cX; - realtype temp, energy; - realtype dt; - - // dt is curr time - time init - dt = *t - time_init; - - // Offset in case several cells - int offset = tid * (NUM_SPECIES + 1); - - // MW CGS - CKWT(molecular_weight); - - // rho MKS - realtype rho = 0.0; - for (int i = 0; i < NUM_SPECIES; i++) { - rho = rho + yvec_d[offset + i]; - } - - temp = yvec_d[offset + NUM_SPECIES]; - - // Yks - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = yvec_d[offset + i] / rho; - } - - // NRG CGS - energy = (data_wk->rhoX_init[data->boxcell + tid] + - data_wk->rhoXsrc_ext[data_wk->boxcell + tid] * dt) / - rho; - - auto eos = pele::physics::PhysicsType::eos(); - if (data_wk->ireactor_type == eint_rho) { - // UV REACTOR - eos.REY2T(rho, energy, massfrac, temp); - eos.RTY2Cv(rho, temp, massfrac, cX); - eos.RTY2Ei(rho, temp, massfrac, Xi); - } else if (data_wk->ireactor_type == enth_rho) { - // HP REACTOR - eos.RHY2T(rho, energy, massfrac, temp); - eos.RTY2Cp(rho, temp, massfrac, cX); - eos.RTY2Hi(rho, temp, massfrac, Xi); - } - eos.RTY2WDOT(rho, temp, massfrac, cdot); - - // Fill ydot vect - ydot_d[offset + NUM_SPECIES] = data_wk->rhoXsrc_ext[data_wk->boxcell + tid]; - for (int i = 0; i < NUM_SPECIES; i++) { - ydot_d[offset + i] = - cdot[i] + data_wk->rYsrc[(data_wk->boxcell + tid) * (NUM_SPECIES) + i]; - ydot_d[offset + NUM_SPECIES] = - ydot_d[offset + NUM_SPECIES] - ydot_d[offset + i] * Xi[i]; - } - ydot_d[offset + NUM_SPECIES] = ydot_d[offset + NUM_SPECIES] / (rho * cX); - } -} - -// Analytical Jacobian evaluation -int -cJac( - realtype /* tn */, - N_Vector u, - N_Vector /* fu */, - SUNMatrix J, - void* user_data, - N_Vector /* tmp1 */, - N_Vector /* tmp2 */, - N_Vector /* tmp3 */) -{ - - // Make local copies of pointers to input data (big M) - realtype* ydata = N_VGetArrayPointer(u); - - // Make local copies of pointers in user_data (cell M) - CVODEUserData *data_wk = (CVODEUserData *)user_data; - - BL_PROFILE_VAR("DenseJac", DenseJac); - for (int tid = 0; tid < data_wk->ncells; tid++) { - // Tmp vars - realtype* J_col_k; - realtype massfrac[NUM_SPECIES], molecular_weight[NUM_SPECIES]; - realtype temp; - realtype Jmat_tmp[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)]; - - // Offset in case several cells - int offset = tid * (NUM_SPECIES + 1); - - // MW CGS - CKWT(molecular_weight); - - // rho MKS - realtype rho = 0.0; - for (int i = 0; i < NUM_SPECIES; i++) { - rho = rho + ydata[offset + i]; - } - - temp = ydata[offset + NUM_SPECIES]; - - // Yks - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = ydata[offset + i] / rho; - } - - // Jac - int consP; - if (data_wk->ireactor_type == eint_rho) { - consP = 0; - } else { - consP = 1; - } - auto eos = pele::physics::PhysicsType::eos(); - eos.RTY2JAC(rho, temp, massfrac, Jmat_tmp, consP); - // fill the sunMat - for (int k = 0; k < NUM_SPECIES; k++) { - J_col_k = SM_COLUMN_D(J, offset + k); - for (int i = 0; i < NUM_SPECIES; i++) { - J_col_k[offset + i] = Jmat_tmp[k * (NUM_SPECIES + 1) + i] * - molecular_weight[i] / molecular_weight[k]; - } - J_col_k[offset + NUM_SPECIES] = - Jmat_tmp[k * (NUM_SPECIES + 1) + NUM_SPECIES] / molecular_weight[k]; - } - J_col_k = SM_COLUMN_D(J, offset + NUM_SPECIES); - for (int i = 0; i < NUM_SPECIES; i++) { - J_col_k[offset + i] = - Jmat_tmp[NUM_SPECIES * (NUM_SPECIES + 1) + i] * molecular_weight[i]; - } - J_col_k = SM_COLUMN_D(J, offset); - } - BL_PROFILE_VAR_STOP(DenseJac); - - return (0); -} - -// Analytical SPARSE Jacobian evaluation -int -cJac_sps( - realtype /* tn */, - N_Vector u, - N_Vector /* fu */, - SUNMatrix J, - void* user_data, - N_Vector /* tmp1 */, - N_Vector /* tmp2 */, - N_Vector /* tmp3 */) -{ - // Make local copies of pointers to input data (big M) - realtype* ydata = N_VGetArrayPointer(u); - sunindextype* rowPtrs_tmp = SUNSparseMatrix_IndexPointers(J); - sunindextype* colIndx_tmp = SUNSparseMatrix_IndexValues(J); - realtype* Jdata = SUNSparseMatrix_Data(J); - - // Make local copies of pointers in user_data (cell M)*/ - CVODEUserData *data_wk = (CVODEUserData *)user_data; - - // MW CGS - realtype molecular_weight[NUM_SPECIES]; - CKWT(molecular_weight); - - BL_PROFILE_VAR("FillSparseData", FillSpsData); - // Fixed colVal - for (int i = 0; i < data_wk->NNZ * data_wk->ncells; i++) { - colIndx_tmp[i] = (sunindextype)data_wk->colVals_c[i]; - } - rowPtrs_tmp[0] = (sunindextype)data_wk->rowPtrs_c[0]; - // Fixed rowPtrs - for (int i = 0; i < data_wk->ncells * (NUM_SPECIES + 1); i++) { - rowPtrs_tmp[i + 1] = (sunindextype)data_wk->rowPtrs_c[i + 1]; - } - BL_PROFILE_VAR_STOP(FillSpsData); - - BL_PROFILE_VAR("SparseJac", SpsJac); - // Temp vectors - realtype temp_save_lcl, temp; - realtype massfrac[NUM_SPECIES]; - realtype Jmat_tmp[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)]; - // Save Jac from cell to cell if more than one - temp_save_lcl = 0.0; - for (int tid = 0; tid < data_wk->ncells; tid++) { - // Offset in case several cells - int offset = tid * (NUM_SPECIES + 1); - int offset_J = tid * data_wk->NNZ; - // rho MKS - realtype rho = 0.0; - for (int i = 0; i < NUM_SPECIES; i++) { - rho = rho + ydata[offset + i]; - } - // Yks - realtype rhoinv = 1.0 / rho; - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = ydata[offset + i] * rhoinv; - } - temp = ydata[offset + NUM_SPECIES]; - // Do we recompute Jac ? - if (fabs(temp - temp_save_lcl) > 1.0) { - int consP = data_wk->ireactor_type == eint_rho ? 0 : 1; - auto eos = pele::physics::PhysicsType::eos(); - eos.RTY2JAC(rho, temp, massfrac, Jmat_tmp, consP); - temp_save_lcl = temp; - // rescale - for (int i = 0; i < NUM_SPECIES; i++) { - for (int k = 0; k < NUM_SPECIES; k++) { - Jmat_tmp[k * (NUM_SPECIES + 1) + i] = - Jmat_tmp[k * (NUM_SPECIES + 1) + i] * molecular_weight[i] / - molecular_weight[k]; - } - Jmat_tmp[i * (NUM_SPECIES + 1) + NUM_SPECIES] = - Jmat_tmp[i * (NUM_SPECIES + 1) + NUM_SPECIES] / molecular_weight[i]; - } - for (int i = 0; i < NUM_SPECIES; i++) { - Jmat_tmp[NUM_SPECIES * (NUM_SPECIES + 1) + i] = - Jmat_tmp[NUM_SPECIES * (NUM_SPECIES + 1) + i] * molecular_weight[i]; - } - } - // Go from Dense to Sparse - for (int i = 1; i < NUM_SPECIES + 2; i++) { - int nbVals = data_wk->rowPtrs_c[i] - data_wk->rowPtrs_c[i - 1]; - for (int j = 0; j < nbVals; j++) { - int idx = data_wk->colVals_c[data_wk->rowPtrs_c[i - 1] + j]; - Jdata[offset_J + data_wk->rowPtrs_c[i - 1] + j] = - Jmat_tmp[(i - 1) + (NUM_SPECIES + 1) * idx]; - } - } - } - BL_PROFILE_VAR_STOP(SpsJac); - - return (0); -} - -#ifdef USE_KLU_PP -// Analytical SPARSE Jacobian evaluation -int -cJac_KLU( - realtype /* tn */, - N_Vector u, - N_Vector /* fu */, - SUNMatrix J, - void* user_data, - N_Vector /* tmp1 */, - N_Vector /* tmp2 */, - N_Vector /* tmp3 */) -{ - - BL_PROFILE_VAR("SparseKLUJac", SpsKLUJac); - // Make local copies of pointers to input data (big M) - realtype* ydata = N_VGetArrayPointer(u); - sunindextype* colptrs_tmp = SUNSparseMatrix_IndexPointers(J); - sunindextype* rowvals_tmp = SUNSparseMatrix_IndexValues(J); - realtype* Jdata = SUNSparseMatrix_Data(J); - - // Make local copies of pointers in user_data (cell M) - CVODEUserData *data_wk = (CVODEUserData *)user_data; - - // MW CGS - realtype molecular_weight[NUM_SPECIES]; - CKWT(molecular_weight); - - // Fixed RowVals - for (int i = 0; i < data_wk->NNZ; i++) { - rowvals_tmp[i] = data_wk->rowVals[0][i]; - } - // Fixed colPtrs - colptrs_tmp[0] = data_wk->colPtrs[0][0]; - for (int i = 0; i < data_wk->ncells * (NUM_SPECIES + 1); i++) { - colptrs_tmp[i + 1] = data_wk->colPtrs[0][i + 1]; - } - - // Temp vectors - realtype temp_save_lcl, temp; - realtype massfrac[NUM_SPECIES]; - realtype Jmat_tmp[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)]; - // Save Jac from cell to cell if more than one - temp_save_lcl = 0.0; - for (int tid = 0; tid < data_wk->ncells; tid++) { - // Offset in case several cells - int offset = tid * (NUM_SPECIES + 1); - // rho MKS - realtype rho = 0.0; - for (int i = 0; i < NUM_SPECIES; i++) { - rho = rho + ydata[offset + i]; - } - // Yks - realtype rhoinv = 1.0 / rho; - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = ydata[offset + i] * rhoinv; - } - temp = ydata[offset + NUM_SPECIES]; - // Do we recompute Jac ? - if (fabs(temp - temp_save_lcl) > 1.0) { - // NRG CGS - int consP = data_wk->ireactor_type == eint_rho ? 0 : 1; - auto eos = pele::physics::PhysicsType::eos(); - eos.RTY2JAC(rho, temp, massfrac, Jmat_tmp, consP); - temp_save_lcl = temp; - // rescale - for (int i = 0; i < NUM_SPECIES; i++) { - for (int k = 0; k < NUM_SPECIES; k++) { - Jmat_tmp[k * (NUM_SPECIES + 1) + i] = - Jmat_tmp[k * (NUM_SPECIES + 1) + i] * molecular_weight[i] / - molecular_weight[k]; - } - Jmat_tmp[i * (NUM_SPECIES + 1) + NUM_SPECIES] = - Jmat_tmp[i * (NUM_SPECIES + 1) + NUM_SPECIES] / molecular_weight[i]; - } - for (int i = 0; i < NUM_SPECIES; i++) { - Jmat_tmp[NUM_SPECIES * (NUM_SPECIES + 1) + i] = - Jmat_tmp[NUM_SPECIES * (NUM_SPECIES + 1) + i] * molecular_weight[i]; - } - } - // Go from Dense to Sparse - BL_PROFILE_VAR("DensetoSps", DtoS); - for (int i = 1; i < NUM_SPECIES + 2; i++) { - int nbVals = data_wk->colPtrs[0][i] - data_wk->colPtrs[0][i - 1]; - for (int j = 0; j < nbVals; j++) { - int idx = data_wk->rowVals[0][data_wk->colPtrs[0][i - 1] + j]; - Jdata[data_wk->colPtrs[0][offset + i - 1] + j] = - Jmat_tmp[(i - 1) * (NUM_SPECIES + 1) + idx]; - } - } - BL_PROFILE_VAR_STOP(DtoS); - } - - BL_PROFILE_VAR_STOP(SpsKLUJac); - - return (0); -} -#endif - -// Preconditioner setup routine for GMRES solver when custom sparse mode is -// activated Generate and preprocess P -int -Precond_custom( - realtype /* tn */, - N_Vector u, - N_Vector /* fu */, - booleantype jok, - booleantype* jcurPtr, - realtype gamma, - void* user_data) -{ - // Make local copies of pointers to input data (big M) - realtype* udata = N_VGetArrayPointer(u); - // Make local copies of pointers in user_data (cell M) - CVODEUserData *data_wk = (CVODEUserData *)user_data; - - // MW CGS - realtype molecular_weight[NUM_SPECIES]; - CKWT(molecular_weight); - - // Check if Jac is stale - if (jok) { - // jok = SUNTRUE: Copy Jbd to P - *jcurPtr = SUNFALSE; - } else { - // Temp vectors - realtype temp, temp_save_lcl; - realtype activity[NUM_SPECIES], massfrac[NUM_SPECIES]; - // Save Jac from cell to cell if more than one - temp_save_lcl = 0.0; - for (int tid = 0; tid < data_wk->ncells; tid++) { - // Offset in case several cells - int offset = tid * (NUM_SPECIES + 1); - // rho MKS - realtype rho = 0.0; - for (int i = 0; i < NUM_SPECIES; i++) { - rho = rho + udata[offset + i]; - } - // Yks - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = udata[offset + i] / rho; - } - temp = udata[offset + NUM_SPECIES]; - // Activities - auto eos = pele::physics::PhysicsType::eos(); - eos.RTY2C(rho, temp, massfrac, activity); - // Do we recompute Jac ? - if (fabs(temp - temp_save_lcl) > 1.0) { - // Formalism - int consP; - if (data_wk->ireactor_type == eint_rho) { - consP = 0; - } else { - consP = 1; - } - DWDOT_SIMPLIFIED(data_wk->JSPSmat[tid], activity, &temp, &consP); - - for (int i = 0; i < NUM_SPECIES; i++) { - for (int k = 0; k < NUM_SPECIES; k++) { - (data_wk->JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] = - (data_wk->JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] * - molecular_weight[i] / molecular_weight[k]; - } - (data_wk->JSPSmat[tid])[i * (NUM_SPECIES + 1) + NUM_SPECIES] = - (data_wk->JSPSmat[tid])[i * (NUM_SPECIES + 1) + NUM_SPECIES] / - molecular_weight[i]; - } - for (int i = 0; i < NUM_SPECIES; i++) { - (data_wk->JSPSmat[tid])[NUM_SPECIES * (NUM_SPECIES + 1) + i] = - (data_wk->JSPSmat[tid])[NUM_SPECIES * (NUM_SPECIES + 1) + i] * - molecular_weight[i]; - } - temp_save_lcl = temp; - } else { - // if not: copy the one from prev cell - for (int i = 0; i < NUM_SPECIES + 1; i++) { - for (int k = 0; k < NUM_SPECIES + 1; k++) { - (data_wk->JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] = - (data_wk->JSPSmat[tid - 1])[k * (NUM_SPECIES + 1) + i]; - } - } - } - } - - *jcurPtr = SUNTRUE; - } - - int nbVals; - for (int i = 1; i < NUM_SPECIES + 2; i++) { - // nb non zeros elem should be the same for all cells - nbVals = data_wk->rowPtrs[0][i] - data_wk->rowPtrs[0][i - 1]; - for (int j = 0; j < nbVals; j++) { - // row of non zero elem should be the same for all cells - int idx = data_wk->colVals[0][data_wk->rowPtrs[0][i - 1] + j]; - // Scale by -gamma - // Add identity matrix - for (int tid = 0; tid < data_wk->ncells; tid++) { - if (idx == (i - 1)) { - data_wk->Jdata[tid][data_wk->rowPtrs[tid][i - 1] + j] = - 1.0 - - gamma * (data_wk->JSPSmat[tid])[idx * (NUM_SPECIES + 1) + idx]; - } else { - data_wk->Jdata[tid][data_wk->rowPtrs[tid][i - 1] + j] = - -gamma * (data_wk->JSPSmat[tid])[(i - 1) + (NUM_SPECIES + 1) * idx]; - } - } - } - } - - return (0); -} - -#ifdef USE_KLU_PP -// Preconditioner setup routine for GMRES solver when KLU sparse mode is -// activated Generate and preprocess P -int -Precond_sparse( - realtype /* tn */, - N_Vector u, - N_Vector /* fu */, - booleantype jok, - booleantype* jcurPtr, - realtype gamma, - void* user_data) -{ - // Make local copies of pointers to input data (big M) - realtype* udata = N_VGetArrayPointer(u); - // Make local copies of pointers in user_data (cell M) - CVODEUserData *data_wk = (CVODEUserData *)user_data; - - // MW CGS - realtype molecular_weight[NUM_SPECIES]; - CKWT(molecular_weight); - - // Check if Jac is stale - if (jok) { - // jok = SUNTRUE: Copy Jbd to P - *jcurPtr = SUNFALSE; - } else { - // Temp vectors - realtype activity[NUM_SPECIES], massfrac[NUM_SPECIES]; - // Save Jac from cell to cell if more than one - realtype temp_save_lcl = 0.0; - for (int tid = 0; tid < data_wk->ncells; tid++) { - // Offset in case several cells - int offset = tid * (NUM_SPECIES + 1); - // rho MKS - realtype rho = 0.0; - for (int i = 0; i < NUM_SPECIES; i++) { - rho = rho + udata[offset + i]; - } - // Yks - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = udata[offset + i] / rho; - } - realtype temp = udata[offset + NUM_SPECIES]; - // Activities - auto eos = pele::physics::PhysicsType::eos(); - eos.RTY2C(rho, temp, massfrac, activity); - // Do we recompute Jac ? - if (fabs(temp - temp_save_lcl) > 1.0) { - // Formalism - int consP = data_wk->ireactor_type == eint_rho ? 0 : 1; - DWDOT_SIMPLIFIED(data_wk->JSPSmat[tid], activity, &temp, &consP); - - for (int i = 0; i < NUM_SPECIES; i++) { - for (int k = 0; k < NUM_SPECIES; k++) { - (data_wk->JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] = - (data_wk->JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] * - molecular_weight[i] / molecular_weight[k]; - } - (data_wk->JSPSmat[tid])[i * (NUM_SPECIES + 1) + NUM_SPECIES] = - (data_wk->JSPSmat[tid])[i * (NUM_SPECIES + 1) + NUM_SPECIES] / - molecular_weight[i]; - } - for (int i = 0; i < NUM_SPECIES; i++) { - (data_wk->JSPSmat[tid])[NUM_SPECIES * (NUM_SPECIES + 1) + i] = - (data_wk->JSPSmat[tid])[NUM_SPECIES * (NUM_SPECIES + 1) + i] * - molecular_weight[i]; - } - temp_save_lcl = temp; - } else { - // if not: copy the one from prev cell - for (int i = 0; i < NUM_SPECIES + 1; i++) { - for (int k = 0; k < NUM_SPECIES + 1; k++) { - (data_wk->JSPSmat[tid])[k * (NUM_SPECIES + 1) + i] = - (data_wk->JSPSmat[tid - 1])[k * (NUM_SPECIES + 1) + i]; - } - } - } - } - - *jcurPtr = SUNTRUE; - } - - for (int i = 1; i < NUM_SPECIES + 2; i++) { - // nb non zeros elem should be the same for all cells - int nbVals = data_wk->colPtrs[0][i] - data_wk->colPtrs[0][i - 1]; - for (int j = 0; j < nbVals; j++) { - // row of non zero elem should be the same for all cells - int idx = data_wk->rowVals[0][data_wk->colPtrs[0][i - 1] + j]; - // Scale by -gamma - // Add identity matrix - for (int tid = 0; tid < data_wk->ncells; tid++) { - if (idx == (i - 1)) { - data_wk->Jdata[tid][data_wk->colPtrs[tid][i - 1] + j] = - 1.0 - - gamma * (data_wk->JSPSmat[tid])[idx * (NUM_SPECIES + 1) + idx]; - } else { - data_wk->Jdata[tid][data_wk->colPtrs[tid][i - 1] + j] = - -gamma * (data_wk->JSPSmat[tid])[(i - 1) * (NUM_SPECIES + 1) + idx]; - } - } - } - } - - BL_PROFILE_VAR("KLU_factorization", KLU_factor); - if (!(data_wk->FirstTimePrecond)) { - for (int tid = 0; tid < data_wk->ncells; tid++) { - klu_refactor( - data_wk->colPtrs[tid], data_wk->rowVals[tid], data_wk->Jdata[tid], - data_wk->Symbolic[tid], data_wk->Numeric[tid], &(data_wk->Common[tid])); - } - } else { - for (int tid = 0; tid < data_wk->ncells; tid++) { - data_wk->Numeric[tid] = klu_factor( - data_wk->colPtrs[tid], data_wk->rowVals[tid], data_wk->Jdata[tid], - data_wk->Symbolic[tid], &(data_wk->Common[tid])); - } - data_wk->FirstTimePrecond = false; - } - BL_PROFILE_VAR_STOP(KLU_factor); - - return (0); -} - -#else -// Preconditioner setup routine for GMRES solver when no sparse mode is -// activated Generate and preprocess P -int -Precond( - realtype /* tn */, - N_Vector u, - N_Vector /* fu */, - booleantype jok, - booleantype* jcurPtr, - realtype gamma, - void* user_data) -{ - // Make local copies of pointers to input data (big M) - realtype* udata = N_VGetArrayPointer(u); - - // Make local copies of pointers in user_data - CVODEUserData *data_wk = (CVODEUserData *)user_data; - realtype**(**P), **(**Jbd); - sunindextype*(**pivot); - P = (data_wk->P); - Jbd = (data_wk->Jbd); - pivot = (data_wk->pivot); - - // Tmp arrays - realtype molecular_weight[NUM_SPECIES]; - realtype Jmat[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)]; - realtype massfrac[NUM_SPECIES], activity[NUM_SPECIES]; - realtype temp; - sunindextype ierr; - - // MW CGS - CKWT(molecular_weight); - - if (jok) { - // jok = SUNTRUE: Copy Jbd to P - denseCopy(Jbd[0][0], P[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1); - *jcurPtr = SUNFALSE; - } else { - // rho MKS - realtype rho = 0.0; - for (int i = 0; i < NUM_SPECIES; i++) { - rho = rho + udata[i]; - } - // Yks - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = udata[i] / rho; - } - temp = udata[NUM_SPECIES]; - // Activities - auto eos = pele::physics::PhysicsType::eos(); - eos.RTY2C(rho, temp, massfrac, activity); - // jok = SUNFALSE: Generate Jbd from scratch and copy to P - // Make local copies of problem variables, for efficiency. - int consP; - if (data_wk->ireactor_type == eint_rho) { - consP = 0; - } else { - consP = 1; - } - DWDOT_SIMPLIFIED(Jmat, activity, &temp, &consP); - - // Compute Jacobian. Load into P. - denseScale(0.0, Jbd[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1); - for (int i = 0; i < NUM_SPECIES; i++) { - for (int k = 0; k < NUM_SPECIES; k++) { - (Jbd[0][0])[k][i] = Jmat[k * (NUM_SPECIES + 1) + i] * - molecular_weight[i] / molecular_weight[k]; - } - (Jbd[0][0])[i][NUM_SPECIES] = - Jmat[i * (NUM_SPECIES + 1) + NUM_SPECIES] / molecular_weight[i]; - } - for (int i = 0; i < NUM_SPECIES; i++) { - (Jbd[0][0])[NUM_SPECIES][i] = - Jmat[NUM_SPECIES * (NUM_SPECIES + 1) + i] * molecular_weight[i]; - } - (Jbd[0][0])[NUM_SPECIES][NUM_SPECIES] = - Jmat[(NUM_SPECIES + 1) * (NUM_SPECIES + 1) - 1]; - - denseCopy(Jbd[0][0], P[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1); - - *jcurPtr = SUNTRUE; - } - - // Scale by -gamma - denseScale(-gamma, P[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1); - // denseScale(0.0, P[0][0], NUM_SPECIES+1, NUM_SPECIES+1); - - // Add identity matrix and do LU decompositions on blocks in place. - denseAddIdentity(P[0][0], NUM_SPECIES + 1); - ierr = denseGETRF(P[0][0], NUM_SPECIES + 1, NUM_SPECIES + 1, pivot[0][0]); - if (ierr != 0) - return (1); - - return (0); -} -#endif - -// PSolve for GMRES solver when custom sparse mode is activated -int -PSolve_custom( - realtype /* tn */, - N_Vector /* u */, - N_Vector /* fu */, - N_Vector r, - N_Vector z, - realtype /* gamma */, - realtype /* delta */, - int /* lr */, - void* user_data) -{ - // Make local copies of pointers in user_data - CVODEUserData *data_wk = (CVODEUserData *)user_data; - - // Make local copies of pointers to input data (big M) - realtype* zdata = N_VGetArrayPointer(z); - realtype* rdata = N_VGetArrayPointer(r); - - N_VScale(1.0, r, z); - - // Solve the block-diagonal system Pz = r using LU factors stored - // in P and pivot data in pivot, and return the solution in z. - BL_PROFILE_VAR("GaussSolver", GaussSolver); - for (int tid = 0; tid < data_wk->ncells; tid++) { - int offset = tid * (NUM_SPECIES + 1); - double* z_d_offset = zdata + offset; - double* r_d_offset = rdata + offset; - sgjsolve_simplified(data_wk->Jdata[tid], z_d_offset, r_d_offset); - } - BL_PROFILE_VAR_STOP(GaussSolver); - - return (0); -} - -#ifdef USE_KLU_PP -// PSolve for GMRES solver when KLU sparse mode is activated -int -PSolve_sparse( - realtype /* tn */, - N_Vector /* u */, - N_Vector /* fu */, - N_Vector r, - N_Vector z, - realtype /* gamma */, - realtype /* delta */, - int /* lr */, - void* user_data) -{ - // Make local copies of pointers in user_data - CVODEUserData *data_wk = (CVODEUserData *)user_data; - - // Make local copies of pointers to input data (big M) - realtype* zdata = N_VGetArrayPointer(z); - - BL_PROFILE_VAR("KLU_inversion", PSolve_sparse); - N_VScale(1.0, r, z); - - // Solve the block-diagonal system Pz = r using LU factors stored - // in P and pivot data in pivot, and return the solution in z. - realtype zdata_cell[NUM_SPECIES + 1]; - for (int tid = 0; tid < data_wk->ncells; tid++) { - int offset_beg = tid * (NUM_SPECIES + 1); - std::memcpy( - zdata_cell, zdata + offset_beg, (NUM_SPECIES + 1) * sizeof(realtype)); - klu_solve( - data_wk->Symbolic[tid], data_wk->Numeric[tid], NUM_SPECIES + 1, 1, - zdata_cell, &(data_wk->Common[tid])); - std::memcpy( - zdata + offset_beg, zdata_cell, (NUM_SPECIES + 1) * sizeof(realtype)); - } - BL_PROFILE_VAR_STOP(PSolve_sparse); - - return (0); -} - -#else -// PSolve for GMRES solver when no sparse mode is activated -int -PSolve( - realtype /* tn */, - N_Vector /* u */, - N_Vector /* fu */, - N_Vector r, - N_Vector z, - realtype /* gamma */, - realtype /* delta */, - int /* lr */, - void* user_data) -{ - // Make local copies of pointers to input data (big M) - realtype* zdata = N_VGetArrayPointer(z); - - // Extract the P and pivot arrays from user_data. - CVODEUserData *data_wk = (CVODEUserData *)user_data; - realtype**(**P); - sunindextype*(**pivot); - P = data_wk->P; - pivot = data_wk->pivot; - - N_VScale(1.0, r, z); - - // Solve the block-diagonal system Pz = r using LU factors stored - // in P and pivot data in pivot, and return the solution in z. - realtype* v = zdata; - denseGETRS(P[0][0], NUM_SPECIES + 1, pivot[0][0], v); - - return (0); -} -#endif - -SUNLinearSolver -SUNLinSol_sparse_custom( - N_Vector a_y, - SUNMatrix a_A, - int reactor_type, - int nsubsys, - int subsys_size, - int subsys_nnz) -{ - SUNLinearSolver S; - SUNLinearSolverContent_Sparse_custom content; - - // Check that required arguments are not NULL - if (a_y == NULL || a_A == NULL) - return (NULL); - if (SUNMatGetID(a_A) != SUNMATRIX_SPARSE) - return (NULL); - - // Matrix should be square - if (SUNSparseMatrix_Columns(a_A) != SUNSparseMatrix_Rows(a_A)) - return (NULL); - - // Check that it is a CSR matrix - if (SUNSparseMatrix_SparseType(a_A) != CSR_MAT) - return (NULL); - - // Matrix and vector dimensions must agree - if (N_VGetLength(a_y) != SUNSparseMatrix_Columns(a_A)) - return (NULL); - - // All subsystems must be the same size - if (SUNSparseMatrix_Columns(a_A) != (subsys_size * nsubsys)) - return (NULL); - - // Number of nonzeros per subsys must be the same - if (SUNSparseMatrix_NNZ(a_A) != (subsys_nnz * nsubsys)) - return (NULL); - - // Create an empty linear solver - S = SUNLinSolNewEmpty(); - if (S == NULL) - return (NULL); - - // Attach operations - S->ops->gettype = SUNLinSolGetType_Sparse_custom; - S->ops->solve = SUNLinSolSolve_Sparse_custom; - - // Create content - content = (SUNLinearSolverContent_Sparse_custom)malloc(sizeof *content); - if (content == NULL) { - SUNLinSolFree(S); - return (NULL); - } - - // Attach content - S->content = content; - - // Fill content - content->last_flag = 0; - content->reactor_type = reactor_type; - content->nsubsys = nsubsys; - content->subsys_size = subsys_size; - content->subsys_nnz = subsys_nnz; - - return (S); -} - -SUNLinearSolver_Type SUNLinSolGetType_Sparse_custom(SUNLinearSolver /* S */) -{ - return (SUNLINEARSOLVER_DIRECT); -} - -int -SUNLinSolSolve_Sparse_custom( - SUNLinearSolver S, SUNMatrix a_A, N_Vector x, N_Vector b, realtype /* tol */) -{ - realtype* x_d = N_VGetArrayPointer(x); - realtype* b_d = N_VGetArrayPointer(b); - - double* Data = (double*)SUNSparseMatrix_Data(a_A); - - BL_PROFILE_VAR("GaussSolver", GaussSolver); - for (int tid = 0; tid < SUN_CUSP_NUM_SUBSYS(S); tid++) { - int offset = tid * SUN_CUSP_SUBSYS_NNZ(S); - int offset_RHS = tid * SUN_CUSP_SUBSYS_SIZE(S); - double* Data_offset = Data + offset; - double* x_d_offset = x_d + offset_RHS; - double* b_d_offset = b_d + offset_RHS; - sgjsolve(Data_offset, x_d_offset, b_d_offset); - } - BL_PROFILE_VAR_STOP(GaussSolver); - - return (SUNLS_SUCCESS); -} - -void -check_state(N_Vector yvec) -{ - realtype* ydata = N_VGetArrayPointer(yvec); - - data->actual_ok_to_react = true; - - for (int tid = 0; tid < data->ncells; tid++) { - // Offset in case several cells - int offset = tid * (NUM_SPECIES + 1); - // rho MKS - realtype rho = 0.0; - for (int k = 0; k < NUM_SPECIES; k++) { - rho = rho + ydata[offset + k]; - } - realtype Temp = ydata[offset + NUM_SPECIES]; - if ((rho < 1.0e-10) || (rho > 1.e10)) { - data->actual_ok_to_react = false; - Print() << "rho " << rho << "\n"; - } - if ((Temp < 200.0) || (Temp > 5000.0)) { - data->actual_ok_to_react = false; - Print() << "Temp " << Temp << "\n"; - } - } -} - -void -PrintFinalStats(void* cvodeMem, realtype Temp) -{ - long int nst, nfe, nsetups, nje, nfeLS, nni, ncfn; - long int nli, npe, nps, ncfl, netfails; - int flag; - realtype hlast, hinused, hcur; - - flag = CVodeGetNumSteps(cvodeMem, &nst); - check_flag(&flag, "CVodeGetNumSteps", 1); - flag = CVodeGetNumRhsEvals(cvodeMem, &nfe); - check_flag(&flag, "CVodeGetNumRhsEvals", 1); - flag = CVodeGetNumNonlinSolvIters(cvodeMem, &nni); - check_flag(&flag, "CVodeGetNumNonlinSolvIters", 1); - flag = CVodeGetNumLinSolvSetups(cvodeMem, &nsetups); - check_flag(&flag, "CVodeGetNumLinSolvSetups", 1); - flag = CVodeGetNumNonlinSolvConvFails(cvodeMem, &ncfn); - check_flag(&flag, "CVodeGetNumNonlinSolvConvFails", 1); - flag = CVodeGetNumErrTestFails(cvodeMem, &netfails); - check_flag(&flag, "CVodeGetNumErrTestFails", 1); - flag = CVodeGetLastStep(cvodeMem, &hlast); - check_flag(&flag, "CVodeGetLastStep", 1); - flag = CVodeGetActualInitStep(cvodeMem, &hinused); - check_flag(&flag, "CVodeGetActualInitStep", 1); - flag = CVodeGetCurrentTime(cvodeMem, &hcur); - check_flag(&flag, "CVodeGetCurrentTime", 1); - - if (data->isolve_type == dense_solve) { - flag = CVDlsGetNumRhsEvals(cvodeMem, &nfeLS); - check_flag(&flag, "CVDlsGetNumRhsEvals", 1); - flag = CVDlsGetNumJacEvals(cvodeMem, &nje); - check_flag(&flag, "CVDlsGetNumJacEvals", 1); - } else if (data->isolve_type == iterative_gmres_solve) { - flag = CVSpilsGetNumRhsEvals(cvode_mem, &nfeLS); - check_flag(&flag, "CVSpilsGetNumRhsEvals", 1); - flag = CVSpilsGetNumJtimesEvals(cvodeMem, &nje); - // flag = CVSpilsGetNumJTSetupEvals(cvodeMem, &nje); - check_flag(&flag, "CVSpilsGetNumJtimesEvals", 1); - flag = CVSpilsGetNumPrecEvals(cvodeMem, &npe); - check_flag(&flag, "CVSpilsGetNumPrecEvals", 1); - flag = CVSpilsGetNumPrecSolves(cvodeMem, &nps); - check_flag(&flag, "CVSpilsGetNumPrecSolves", 1); - flag = CVSpilsGetNumLinIters(cvodeMem, &nli); - check_flag(&flag, "CVSpilsGetNumLinIters", 1); - flag = CVSpilsGetNumConvFails(cvodeMem, &ncfl); - check_flag(&flag, "CVSpilsGetNumConvFails", 1); - } - - Print() << "-- Final Statistics --\n"; - Print() << "NonLinear (Newton) related --\n"; - Print() << Temp << " |DT(dt, dtcur) = " << nst << "(" << hlast << "," << hcur - << "), RHS = " << nfe << ", Iterations = " << nni - << ", ErrTestFails = " << netfails << ", LinSolvSetups = " << nsetups - << "\n"; - if (data->isolve_type == dense_solve) { - Print() << "Linear (Dense Direct Solve) related --\n"; - Print() << Temp << " |FD RHS = " << nfeLS << ", NumJacEvals = " << nje - << " \n"; - } else if (data->isolve_type == iterative_gmres_solve) { - // LinSolvSetups actually reflects the number of time the LinSolver has been - // called. NonLinIterations can be taken without the need for LinItes - Print() << "Linear (Krylov GMRES Solve) related --\n"; - Print() << Temp << " |RHSeval = " << nfeLS << ", jtvEval = " << nje - << ", NumPrecEvals = " << npe << ", NumPrecSolves = " << nps - << "\n"; - Print() << Temp << " |Iterations = " << nli << ", ConvFails = " << ncfl - << "\n"; - } -} - -/* Check function return value... - opt == 0 means SUNDIALS function allocates memory so check if - returned NULL pointer - opt == 1 means SUNDIALS function returns a flag so check if - flag >= 0 - opt == 2 means function allocates memory so check if returned - NULL pointer */ - -CVODEUserData* AllocUserData(int reactor_type, int num_cells) -{ - // Make local copies of pointers in user_data - CVODEUserData *data_wk = (CVODEUserData *)malloc(sizeof *data_wk); - int omp_thread = 0; -#ifdef AMREX_USE_OMP - omp_thread = omp_get_thread_num(); -#endif - - // ParmParse from the inputs file: only done once - ParmParse pp("ode"); - pp.query("analytical_jacobian", data_wk->ianalytical_jacobian); - data_wk->iverbose = 1; - pp.query("verbose", data_wk->iverbose); - - std::string solve_type_str = "none"; - ParmParse ppcv("cvode"); - ppcv.query("solve_type", solve_type_str); - /* options are: - dense_solve = 1; - sparse_solve = 5; - iterative_gmres_solve = 99; - sparse_custom_solve = 101; - iterative_gmres_solve_custom = 199; - hack_dump_sparsity_pattern = -5; - */ - if (solve_type_str == "dense") { - data_wk->isolve_type = dense_solve; - } else if (solve_type_str == "sparse") { - data_wk->isolve_type = sparse_solve; - } else if (solve_type_str == "GMRES") { - data_wk->isolve_type = iterative_gmres_solve; - } else if (solve_type_str == "sparse_custom") { - data_wk->isolve_type = sparse_custom_solve; - } else if (solve_type_str == "GMRES_custom") { - data_wk->isolve_type = iterative_gmres_solve_custom; - } else if (solve_type_str == "diag") { - data_wk->isolve_type = hack_dump_sparsity_pattern; - } else { - Abort("Wrong solve_type. Options are: dense, sparse, GMRES, sparse_custom, " - "GMRES_custom"); - } - - (data_wk->ireactor_type) = reactor_type; - - (data_wk->ncells) = num_cells; - - // Not sure of the interest of doing that the following: - // N_Vector Data = NULL; - // Data = N_VNew_Serial(data_wk->ncells*(NUM_SPECIES+1)); - //(data_wk->Yvect_full) = N_VGetArrayPointer_Serial(Data); - // Data = N_VNew_Serial(data_wk->ncells*(NUM_SPECIES)); - //(data_wk->rYsrc) = N_VGetArrayPointer_Serial(Data); - // Data = N_VNew_Serial(data_wk->ncells); - //(data_wk->rhoX_init) = N_VGetArrayPointer_Serial(Data); - // Data = N_VNew_Serial(data_wk->ncells); - //(data_wk->rhoXsrc_ext) = N_VGetArrayPointer_Serial(Data); - - (data_wk->Yvect_full) = new amrex::Real[data_wk->ncells * (NUM_SPECIES + 1)]; - (data_wk->rYsrc) = new amrex::Real[data_wk->ncells * (NUM_SPECIES)]; - (data_wk->rhoX_init) = new amrex::Real[data_wk->ncells]; - (data_wk->rhoXsrc_ext) = new amrex::Real[data_wk->ncells]; - (data_wk->FCunt) = new int[data_wk->ncells]; - (data_wk->mask) = new int[data_wk->ncells]; - - (data_wk->FirstTimePrecond) = true; - (data_wk->reactor_cvode_initialized) = false; - (data_wk->actual_ok_to_react) = true; - - int HP; - if (data_wk->ireactor_type == eint_rho) { - HP = 0; - } else { - HP = 1; - } - - // Sparse Direct and Sparse (It) Precond data - data_wk->colPtrs = new int*[data_wk->ncells]; - data_wk->rowVals = new int*[data_wk->ncells]; - data_wk->Jdata = new realtype*[data_wk->ncells]; - -#ifndef USE_KLU_PP - if (data_wk->isolve_type == iterative_gmres_solve) { - // Precond data - (data_wk->P) = new realtype***[data_wk->ncells]; - (data_wk->Jbd) = new realtype***[data_wk->ncells]; - (data_wk->pivot) = new sunindextype**[data_wk->ncells]; - for (int i = 0; i < data_wk->ncells; ++i) { - (data_wk->P)[i] = new realtype**[data_wk->ncells]; - (data_wk->Jbd)[i] = new realtype**[data_wk->ncells]; - (data_wk->pivot)[i] = new sunindextype*[data_wk->ncells]; - } - - for (int i = 0; i < data_wk->ncells; ++i) { - (data_wk->P)[i][i] = newDenseMat(NUM_SPECIES + 1, NUM_SPECIES + 1); - (data_wk->Jbd)[i][i] = newDenseMat(NUM_SPECIES + 1, NUM_SPECIES + 1); - (data_wk->pivot)[i][i] = newIndexArray(NUM_SPECIES + 1); - } - //} - -#else - if (data_wk->isolve_type == sparse_solve) { - // Sparse Matrix for Direct Sparse KLU solver - (data_wk->PS) = new SUNMatrix[1]; - SPARSITY_INFO(&(data_wk->NNZ), &HP, data_wk->ncells); - if ((data_wk->iverbose > 0) && (omp_thread == 0)) { - Print() << "--> SPARSE solver -- non zero entries: " << data_wk->NNZ - << ", which represents " - << data_wk->NNZ / - float( - (NUM_SPECIES + 1) * (NUM_SPECIES + 1) * (data_wk->ncells) * - (data_wk->ncells)) * - 100.0 - << " % fill-in pattern\n"; - } - (data_wk->PS)[0] = SUNSparseMatrix( - (NUM_SPECIES + 1) * data_wk->ncells, (NUM_SPECIES + 1) * data_wk->ncells, - data_wk->NNZ, CSC_MAT); - data_wk->colPtrs[0] = (int*)SUNSparseMatrix_IndexPointers((data_wk->PS)[0]); - data_wk->rowVals[0] = (int*)SUNSparseMatrix_IndexValues((data_wk->PS)[0]); - data_wk->Jdata[0] = SUNSparseMatrix_Data((data_wk->PS)[0]); - SPARSITY_PREPROC_CSC( - data_wk->rowVals[0], data_wk->colPtrs[0], &HP, data_wk->ncells); - - } else if (data_wk->isolve_type == iterative_gmres_solve) { - // KLU internal storage - data_wk->Common = new klu_common[data_wk->ncells]; - data_wk->Symbolic = new klu_symbolic*[data_wk->ncells]; - data_wk->Numeric = new klu_numeric*[data_wk->ncells]; - // Sparse Matrices for It Sparse KLU block-solve - data_wk->PS = new SUNMatrix[data_wk->ncells]; - // Number of non zero elements - SPARSITY_INFO_SYST_SIMPLIFIED(&(data_wk->NNZ), &HP); - if ( - (data_wk->iverbose > 0) && (omp_thread == 0) && - (data_wk->ianalytical_jacobian != 0)) { - Print() << "--> SPARSE Preconditioner -- non zero entries: " - << data_wk->NNZ << ", which represents " - << data_wk->NNZ / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * - 100.0 - << " % fill-in pattern\n"; - } - // Not used yet. TODO use to fetch sparse Mat - data_wk->indx = new int[data_wk->NNZ]; - data_wk->JSPSmat = new realtype*[data_wk->ncells]; - for (int i = 0; i < data_wk->ncells; ++i) { - (data_wk->PS)[i] = SUNSparseMatrix( - NUM_SPECIES + 1, NUM_SPECIES + 1, data_wk->NNZ, CSC_MAT); - data_wk->colPtrs[i] = - (int*)SUNSparseMatrix_IndexPointers((data_wk->PS)[i]); - data_wk->rowVals[i] = (int*)SUNSparseMatrix_IndexValues((data_wk->PS)[i]); - data_wk->Jdata[i] = SUNSparseMatrix_Data((data_wk->PS)[i]); - // indx not used YET - SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC( - data_wk->rowVals[i], data_wk->colPtrs[i], data_wk->indx, &HP); - data_wk->JSPSmat[i] = new realtype[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)]; - klu_defaults(&(data_wk->Common[i])); - // data_wk->Common.btf = 0; - //(data_wk->Common[i]).maxwork = 15; - // data_wk->Common.ordering = 1; - data_wk->Symbolic[i] = klu_analyze( - NUM_SPECIES + 1, data_wk->colPtrs[i], data_wk->rowVals[i], - &(data_wk->Common[i])); - } - //} -#endif - - } else if (data_wk->isolve_type == iterative_gmres_solve_custom) { - // Sparse Direct and Sparse (It) Precond data - data_wk->colVals = new int*[data_wk->ncells]; - data_wk->rowPtrs = new int*[data_wk->ncells]; - // Matrices for It Sparse custom block-solve - data_wk->PS = new SUNMatrix[data_wk->ncells]; - data_wk->JSPSmat = new realtype*[data_wk->ncells]; - // Number of non zero elements - SPARSITY_INFO_SYST_SIMPLIFIED(&(data_wk->NNZ), &HP); - for (int i = 0; i < data_wk->ncells; ++i) { - (data_wk->PS)[i] = SUNSparseMatrix( - NUM_SPECIES + 1, NUM_SPECIES + 1, data_wk->NNZ, CSR_MAT); - data_wk->rowPtrs[i] = - (int*)SUNSparseMatrix_IndexPointers((data_wk->PS)[i]); - data_wk->colVals[i] = (int*)SUNSparseMatrix_IndexValues((data_wk->PS)[i]); - data_wk->Jdata[i] = SUNSparseMatrix_Data((data_wk->PS)[i]); - SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR( - data_wk->colVals[i], data_wk->rowPtrs[i], &HP, 0); - data_wk->JSPSmat[i] = new realtype[(NUM_SPECIES + 1) * (NUM_SPECIES + 1)]; - } - if ((data_wk->iverbose > 0) && (omp_thread == 0)) { - Print() << "--> SPARSE Preconditioner -- non zero entries: " - << data_wk->NNZ * data_wk->ncells << ", which represents " - << data_wk->NNZ / - float( - (NUM_SPECIES + 1) * (NUM_SPECIES + 1) * data_wk->ncells) * - 100.0 - << " % fill-in pattern\n"; - } - } else if (data_wk->isolve_type == sparse_custom_solve) { - // Number of non zero elements - SPARSITY_INFO_SYST(&(data_wk->NNZ), &HP, 1); - data_wk->PSc = SUNSparseMatrix( - (NUM_SPECIES + 1) * data_wk->ncells, (NUM_SPECIES + 1) * data_wk->ncells, - data_wk->NNZ * data_wk->ncells, CSR_MAT); - data_wk->rowPtrs_c = (int*)SUNSparseMatrix_IndexPointers(data_wk->PSc); - data_wk->colVals_c = (int*)SUNSparseMatrix_IndexValues(data_wk->PSc); - SPARSITY_PREPROC_SYST_CSR( - data_wk->colVals_c, data_wk->rowPtrs_c, &HP, data_wk->ncells, 0); - if ((data_wk->iverbose > 0) && (omp_thread == 0)) { - Print() << "--> SPARSE solver -- non zero entries: " - << data_wk->NNZ * data_wk->ncells << ", which represents " - << data_wk->NNZ / - float( - (NUM_SPECIES + 1) * (NUM_SPECIES + 1) * data_wk->ncells) * - 100.0 - << " % fill-in pattern\n"; - } - } else if (data_wk->isolve_type == hack_dump_sparsity_pattern) { - // Debug mode, makes no sense to call with OMP/MPI activated - int counter; - - // CHEMISTRY JAC - SPARSITY_INFO(&(data_wk->NNZ), &HP, 1); - Print() << "--> Chem Jac -- non zero entries: " << data_wk->NNZ - << ", which represents " - << data_wk->NNZ / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * - 100.0 - << " % fill-in pattern\n"; - SUNMatrix PS; - PS = SUNSparseMatrix( - (NUM_SPECIES + 1), (NUM_SPECIES + 1), data_wk->NNZ, CSR_MAT); - int *colIdx, *rowCount; - rowCount = (int*)SUNSparseMatrix_IndexPointers(PS); - colIdx = (int*)SUNSparseMatrix_IndexValues(PS); - SPARSITY_PREPROC_CSR(colIdx, rowCount, &HP, 1, 0); - std::cout << " " << std::endl; - std::cout << "*** Treating CHEM Jac (CSR symbolic analysis)***" - << std::endl; - std::cout << " " << std::endl; - int nbVals; - counter = 0; - for (int i = 0; i < NUM_SPECIES + 1; i++) { - nbVals = rowCount[i + 1] - rowCount[i]; - int* idx_arr = new int[nbVals]; - std::fill_n(idx_arr, nbVals, -1); - std::memcpy(idx_arr, colIdx + rowCount[i], nbVals * sizeof(int)); - int idx = 0; - for (int j = 0; j < NUM_SPECIES + 1; j++) { - if ((j == idx_arr[idx]) && (nbVals > 0)) { - std::cout << 1 << " "; - idx = idx + 1; - counter = counter + 1; - } else { - std::cout << 0 << " "; - } - } - delete[] idx_arr; - std::cout << std::endl; - } - std::cout << " There was " << counter << " non zero elems (compare to the " - << data_wk->NNZ << " we need)" << std::endl; - - // SYST JAC - SPARSITY_INFO_SYST(&(data_wk->NNZ), &HP, 1); - Print() << "--> Syst Jac -- non zero entries: " << data_wk->NNZ - << ", which represents " - << data_wk->NNZ / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * - 100.0 - << " % fill-in pattern\n"; - PS = SUNSparseMatrix( - (NUM_SPECIES + 1), (NUM_SPECIES + 1), data_wk->NNZ, CSR_MAT); - rowCount = (int*)SUNSparseMatrix_IndexPointers(PS); - colIdx = (int*)SUNSparseMatrix_IndexValues(PS); - SPARSITY_PREPROC_SYST_CSR(colIdx, rowCount, &HP, 1, 1); - // CHEMISTRY JAC - std::cout << " " << std::endl; - std::cout << "*** Treating SYST Jac (CSR symbolic analysis)***" - << std::endl; - std::cout << " " << std::endl; - counter = 0; - for (int i = 0; i < NUM_SPECIES + 1; i++) { - nbVals = rowCount[i + 1] - rowCount[i]; - int* idx_arr = new int[nbVals]; - std::fill_n(idx_arr, nbVals, -1); - std::memcpy(idx_arr, colIdx + (rowCount[i] - 1), nbVals * sizeof(int)); - int idx = 0; - for (int j = 0; j < NUM_SPECIES + 1; j++) { - if ((j == idx_arr[idx] - 1) && ((nbVals - idx) > 0)) { - std::cout << 1 << " "; - idx = idx + 1; - counter = counter + 1; - } else { - std::cout << 0 << " "; - } - } - delete[] idx_arr; - std::cout << std::endl; - } - std::cout << " There was " << counter << " non zero elems (compare to the " - << data_wk->NNZ << " we need)" << std::endl; - - // SYST JAC SIMPLIFIED - SPARSITY_INFO_SYST_SIMPLIFIED(&(data_wk->NNZ), &HP); - Print() << "--> Simplified Syst Jac (for Precond) -- non zero entries: " - << data_wk->NNZ << ", which represents " - << data_wk->NNZ / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * - 100.0 - << " % fill-in pattern\n"; - PS = SUNSparseMatrix( - (NUM_SPECIES + 1), (NUM_SPECIES + 1), data_wk->NNZ, CSR_MAT); - rowCount = (int*)SUNSparseMatrix_IndexPointers(PS); - colIdx = (int*)SUNSparseMatrix_IndexValues(PS); - SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(colIdx, rowCount, &HP, 1); - // CHEMISTRY JAC - std::cout << " " << std::endl; - std::cout << "*** Treating simplified SYST Jac (CSR symbolic analysis)***" - << std::endl; - std::cout << " " << std::endl; - counter = 0; - for (int i = 0; i < NUM_SPECIES + 1; i++) { - nbVals = rowCount[i + 1] - rowCount[i]; - int* idx_arr = new int[nbVals]; - std::fill_n(idx_arr, nbVals, -1); - std::memcpy(idx_arr, colIdx + (rowCount[i] - 1), nbVals * sizeof(int)); - int idx = 0; - for (int j = 0; j < NUM_SPECIES + 1; j++) { - if ((j == idx_arr[idx] - 1) && ((nbVals - idx) > 0)) { - std::cout << 1 << " "; - idx = idx + 1; - counter = counter + 1; - } else { - std::cout << 0 << " "; - } - } - delete[] idx_arr; - std::cout << std::endl; - } - std::cout << " There was " << counter << " non zero elems (compare to the " - << data_wk->NNZ << " we need)" << std::endl; - - Abort("Dump Sparsity Patern of different Jacobians in CSR format."); - } - - return (data_wk); -} - -void -reactor_close() -{ - - CVodeFree(&cvode_mem); - SUNLinSolFree(LS); - - if (data->isolve_type == dense_solve) { - SUNMatDestroy(A); - } - - N_VDestroy(y); - FreeUserData(data); -} - -// Free data memory -// Probably not complete, how about the stuff allocated in KLU mode ? -void -FreeUserData(CVODEUserData *data_wk) -{ - delete[](data_wk->Yvect_full); - delete[](data_wk->rYsrc); - delete[](data_wk->rhoX_init); - delete[](data_wk->rhoXsrc_ext); - delete[](data_wk->FCunt); - delete[](data_wk->mask); - - delete[] data_wk->colPtrs; - delete[] data_wk->rowVals; - delete[] data_wk->Jdata; -#ifndef USE_KLU_PP - if (data_wk->isolve_type == iterative_gmres_solve) { - for (int i = 0; i < data_wk->ncells; ++i) { - destroyMat((data_wk->P)[i][i]); - destroyMat((data_wk->Jbd)[i][i]); - destroyArray((data_wk->pivot)[i][i]); - } - for (int i = 0; i < data_wk->ncells; ++i) { - delete[](data_wk->P)[i]; - delete[](data_wk->Jbd)[i]; - delete[](data_wk->pivot)[i]; - } - delete[](data_wk->P); - delete[](data_wk->Jbd); - delete[](data_wk->pivot); - //} - -#else - if (data_wk->isolve_type == sparse_solve) { - SUNMatDestroy(A); - SUNMatDestroy((data_wk->PS)[0]); - delete[](data_wk->PS); - } else if (data_wk->isolve_type == iterative_gmres_solve) { - delete[] data_wk->indx; - for (int i = 0; i < data_wk->ncells; ++i) { - klu_free_symbolic(&(data_wk->Symbolic[i]), &(data_wk->Common[i])); - klu_free_numeric(&(data_wk->Numeric[i]), &(data_wk->Common[i])); - delete[] data_wk->JSPSmat[i]; - SUNMatDestroy((data_wk->PS)[i]); - } - delete[] data_wk->JSPSmat; - delete[] data_wk->Common; - delete[] data_wk->Symbolic; - delete[] data_wk->Numeric; - delete[] data_wk->PS; - //} -#endif - - } else if (data_wk->isolve_type == iterative_gmres_solve_custom) { - for (int i = 0; i < data_wk->ncells; ++i) { - delete[] data_wk->JSPSmat[i]; - SUNMatDestroy((data_wk->PS)[i]); - } - delete[] data_wk->colVals; - delete[] data_wk->rowPtrs; - delete[] data_wk->PS; - delete[] data_wk->JSPSmat; - } else if (data_wk->isolve_type == sparse_custom_solve) { - SUNMatDestroy(A); - SUNMatDestroy(data_wk->PSc); - } else if (data_wk->isolve_type == hack_dump_sparsity_pattern) { - } - - free(data_wk); -} diff --git a/Reactions/cvode/reactor_cvode_GPU.cpp b/Reactions/cvode/reactor_cvode_GPU.cpp deleted file mode 100644 index 779bd1948..000000000 --- a/Reactions/cvode/reactor_cvode_GPU.cpp +++ /dev/null @@ -1,1696 +0,0 @@ -#include "reactor.H" - -using namespace amrex; - -#define SUN_CUSP_CONTENT(S) ((SUNLinearSolverContent_Dense_custom)(S->content)) -#define SUN_CUSP_SUBSYS_SIZE(S) (SUN_CUSP_CONTENT(S)->subsys_size) -#define SUN_CUSP_NUM_SUBSYS(S) (SUN_CUSP_CONTENT(S)->nsubsys) -#define SUN_CUSP_SUBSYS_NNZ(S) (SUN_CUSP_CONTENT(S)->subsys_nnz) - -#define SUN_CUSP_LASTFLAG(S) (SUN_CUSP_CONTENT(S)->last_flag) -#define SUN_CUSP_STREAM(S) (SUN_CUSP_CONTENT(S)->stream) -#define SUN_CUSP_NBLOCK(S) (SUN_CUSP_CONTENT(S)->nbBlocks) -#define SUN_CUSP_NTHREAD(S) (SUN_CUSP_CONTENT(S)->nbThreads) - -int reactor_init(int reactor_type, int Ncells) -{ - ParmParse pp("ode"); - int ianalytical_jacobian = 0; - pp.query("analytical_jacobian", ianalytical_jacobian); - int iverbose = 1; - pp.query("verbose", iverbose); - - if (iverbose > 0) { - Print() << "Number of species in mech is " << NUM_SPECIES << "\n"; - Print() << "Number of cells in one solve is " << Ncells << "\n"; - } - - std::string solve_type_str = "none"; - ParmParse ppcv("cvode"); - ppcv.query("solve_type", solve_type_str); - /* - sparse_custom_solve = 1; - sparse_solve = 5; - iterative_gmres_solve = 99; - */ - int isolve_type = -1; - if (solve_type_str == "sparse_custom") { - isolve_type = sparse_custom_solve; - } else if (solve_type_str == "sparse") { - isolve_type = sparse_solve; - } else if (solve_type_str == "GMRES") { - isolve_type = iterative_gmres_solve; - } else { - Abort("Wrong solve_type. Options are: sparse, sparse_custom, GMRES"); - } - - if (isolve_type == iterative_gmres_solve) { - if (ianalytical_jacobian == 1) { -#if defined(AMREX_USE_CUDA) - if (iverbose > 0) { - Print() << "Using an Iterative GMRES Solver with sparse simplified " - "preconditioning \n"; - } - int nJdata; - int HP; - if (reactor_type == eint_rho) { - HP = 0; - } else { - HP = 1; - } - // Precond data - SPARSITY_INFO_SYST_SIMPLIFIED(&nJdata, &HP); - if (iverbose > 0) { - Print() << "--> SPARSE Preconditioner -- non zero entries: " << nJdata - << ", which represents " - << nJdata / float((NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * 100.0 - << " % fill-in pattern\n"; - } -#elif defined(AMREX_USE_HIP) - Abort("\n--> With HIP the only option is NP GMRES \n"); -#else - Abort("\n--> Not sure what do with analytic Jacobian in this case \n"); -#endif - } else { - if (iverbose > 0) { - Print() - << "Using an Iterative GMRES Solver without preconditionning \n"; - } - } - - } else if (isolve_type == sparse_custom_solve) { -#if defined(AMREX_USE_CUDA) - if (ianalytical_jacobian == 1) { - if (iverbose > 0) { - Print() << "Using a custom sparse direct solver (with an analytical " - "Jacobian) \n"; - } - int nJdata; - int HP; - if (reactor_type == eint_rho) { - HP = 0; - } else { - HP = 1; - } - SPARSITY_INFO_SYST(&nJdata, &HP, Ncells); - if (iverbose > 0) { - Print() << "--> SPARSE Solver -- non zero entries: " << nJdata - << ", which represents " - << nJdata / - float(Ncells * (NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * - 100.0 - << " % fill-in pattern\n"; - } - } else { - Abort( - "\n--> Custom direct sparse solver requires an analytic Jacobian \n"); - } -#elif defined(AMREX_USE_HIP) - Abort("\n--> With HIP the only option is NP GMRES \n"); -#else - Abort("\n--> No sparse solve for this case\n"); -#endif - - } else if (isolve_type == sparse_solve) { -#if defined(AMREX_USE_CUDA) - if (ianalytical_jacobian == 1) { - Print() << "Using a Sparse Direct Solver based on cuSolver \n"; - int nJdata; - int HP; - if (reactor_type == eint_rho) { - HP = 0; - } else { - HP = 1; - } - SPARSITY_INFO_SYST(&nJdata, &HP, Ncells); - if (iverbose > 0) { - Print() << "--> SPARSE Solver -- non zero entries: " << nJdata - << ", which represents " - << nJdata / - float(Ncells * (NUM_SPECIES + 1) * (NUM_SPECIES + 1)) * - 100.0 - << " % fill-in pattern\n"; - } - } else { - Abort("\n--> Sparse direct solvers requires an analytic Jacobian \n"); - } -#elif defined(AMREX_USE_HIP) - Abort("\n--> No HIP equivalent to cuSolver implemented yet \n"); -#else - Abort("\n--> No batch solver for this case\n"); -#endif - - } else { - Abort("\n--> Bad linear solver choice for CVODE \n"); - } - - Print() << "\n--> DONE WITH INITIALIZATION (GPU)" << reactor_type << "\n"; - - return (0); -} - -int -react( - const amrex::Box& box, - amrex::Array4 const& rY_in, - amrex::Array4 const& rY_src_in, - amrex::Array4 const& T_in, - amrex::Array4 const& rEner_in, - amrex::Array4 const& rEner_src_in, - amrex::Array4 const& FC_in, - amrex::Array4 const& mask, - amrex::Real& dt_react, - amrex::Real& time, - const int& reactor_type -#ifdef AMREX_USE_GPU - , - amrex::gpuStream_t stream -#endif -) -{ - N_Vector y = NULL; - SUNLinearSolver LS = NULL; - SUNMatrix A = NULL; - void* cvode_mem = NULL; - int flag; - int NCELLS, neq_tot; - N_Vector atol; - realtype* ratol; - - ParmParse pp("ode"); - int ianalytical_jacobian = 0; - pp.query("analytical_jacobian", ianalytical_jacobian); - int iverbose = 1; - pp.query("verbose", iverbose); - - std::string solve_type_str = "none"; - ParmParse ppcv("cvode"); - ppcv.query("solve_type", solve_type_str); - /* - sparse_custom_solve = 1; - sparse_solve = 5; - iterative_gmres_solve = 99; - */ - int isolve_type = -1; - if (solve_type_str == "sparse_custom") { - isolve_type = sparse_custom_solve; - } else if (solve_type_str == "sparse") { - isolve_type = sparse_solve; - } else if (solve_type_str == "GMRES") { - isolve_type = iterative_gmres_solve; - } - - NCELLS = box.numPts(); - neq_tot = (NUM_SPECIES + 1) * NCELLS; - -#ifdef AMREX_USE_OMP - Gpu::streamSynchronize(); -#endif - - CVODEUserData * user_data; - - BL_PROFILE_VAR("AllocsInCVODE", AllocsCVODE); - user_data = (CVODEUserData*)The_Arena()->alloc(sizeof(struct CVODEUserData)); - BL_PROFILE_VAR_STOP(AllocsCVODE); - - user_data->ncells = NCELLS; - user_data->neqs_per_cell = NUM_SPECIES; - user_data->ireactor_type = reactor_type; - user_data->ianalytical_jacobian = ianalytical_jacobian; - user_data->isolve_type = isolve_type; - user_data->iverbose = iverbose; - user_data->nbBlocks = std::max(1, NCELLS / 32); -#ifdef AMREX_USE_GPU - user_data->stream = stream; -#endif - user_data->nbThreads = 32; - -#ifdef AMREX_USE_CUDA - if (user_data->ianalytical_jacobian == 1) { - int HP; - if (user_data->ireactor_type == 1) { - HP = 0; - } else { - HP = 1; - } - - BL_PROFILE_VAR("SparsityFuegoStuff", SparsityStuff); - BL_PROFILE_VAR_STOP(SparsityStuff); - if (user_data->isolve_type == iterative_gmres_solve) { - BL_PROFILE_VAR_START(SparsityStuff); - SPARSITY_INFO_SYST_SIMPLIFIED(&(user_data->NNZ), &HP); - BL_PROFILE_VAR_STOP(SparsityStuff); - - BL_PROFILE_VAR_START(AllocsCVODE); - user_data->csr_row_count_h = - (int*)The_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); - user_data->csr_col_index_h = - (int*)The_Arena()->alloc(user_data->NNZ * sizeof(int)); - user_data->csr_jac_h = - (double*)The_Arena()->alloc(user_data->NNZ * NCELLS * sizeof(double)); - user_data->csr_val_h = - (double*)The_Arena()->alloc(user_data->NNZ * NCELLS * sizeof(double)); - - user_data->csr_row_count_d = - (int*)The_Device_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); - user_data->csr_col_index_d = - (int*)The_Device_Arena()->alloc(user_data->NNZ * sizeof(int)); - user_data->csr_jac_d = (double*)The_Device_Arena()->alloc( - user_data->NNZ * NCELLS * sizeof(double)); - user_data->csr_val_d = (double*)The_Device_Arena()->alloc( - user_data->NNZ * NCELLS * sizeof(double)); - BL_PROFILE_VAR_STOP(AllocsCVODE); - - BL_PROFILE_VAR_START(SparsityStuff); - SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR( - user_data->csr_col_index_h, user_data->csr_row_count_h, &HP, 1); - BL_PROFILE_VAR_STOP(SparsityStuff); - - amrex::Gpu::htod_memcpy( - &user_data->csr_col_index_d, &user_data->csr_col_index_h, - sizeof(user_data->NNZ * sizeof(int))); - amrex::Gpu::htod_memcpy( - &user_data->csr_row_count_d, &user_data->csr_row_count_h, - sizeof((NUM_SPECIES + 2) * sizeof(int))); - - BL_PROFILE_VAR("CuSolverInit", CuSolverInit); - size_t workspaceInBytes, internalDataInBytes; - cusolverStatus_t cusolver_status = CUSOLVER_STATUS_SUCCESS; - cusparseStatus_t cusparse_status = CUSPARSE_STATUS_SUCCESS; - - workspaceInBytes = 0; - internalDataInBytes = 0; - - cusolver_status = cusolverSpCreate(&(user_data->cusolverHandle)); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cusolver_status = cusolverSpSetStream(user_data->cusolverHandle, stream); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cusparse_status = cusparseCreateMatDescr(&(user_data->descrA)); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - - cusparse_status = - cusparseSetMatType(user_data->descrA, CUSPARSE_MATRIX_TYPE_GENERAL); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - - cusparse_status = - cusparseSetMatIndexBase(user_data->descrA, CUSPARSE_INDEX_BASE_ONE); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - - cusolver_status = cusolverSpCreateCsrqrInfo(&(user_data->info)); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cusolver_status = cusolverSpXcsrqrAnalysisBatched( - user_data->cusolverHandle, NUM_SPECIES + 1, NUM_SPECIES + 1, - user_data->NNZ, user_data->descrA, user_data->csr_row_count_h, - user_data->csr_col_index_h, user_data->info); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - /* - size_t free_mem = 0; - size_t total_mem = 0; - cudaStat1 = cudaMemGetInfo( &free_mem, &total_mem ); - assert( cudaSuccess == cudaStat1 ); - std::cout<<"(AFTER SA) Free: "<< free_mem<< " Tot: - "<cusolverHandle, NUM_SPECIES + 1, NUM_SPECIES + 1, - user_data->NNZ, user_data->descrA, user_data->csr_val_h, - user_data->csr_row_count_h, user_data->csr_col_index_h, NCELLS, - user_data->info, &internalDataInBytes, &workspaceInBytes); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cudaError_t cudaStat1 = cudaSuccess; - cudaStat1 = cudaMalloc((void**)&(user_data->buffer_qr), workspaceInBytes); - assert(cudaStat1 == cudaSuccess); - BL_PROFILE_VAR_STOP(CuSolverInit); - - } else if (isolve_type == sparse_solve) { - BL_PROFILE_VAR_START(SparsityStuff); - SPARSITY_INFO_SYST(&(user_data->NNZ), &HP, 1); - BL_PROFILE_VAR_STOP(SparsityStuff); - - BL_PROFILE_VAR_START(AllocsCVODE); - user_data->csr_row_count_h = - (int*)The_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); - user_data->csr_col_index_h = - (int*)The_Arena()->alloc(user_data->NNZ * sizeof(int)); - - BL_PROFILE_VAR_STOP(AllocsCVODE); - - cusolverStatus_t cusolver_status = CUSOLVER_STATUS_SUCCESS; - cusparseStatus_t cusparse_status = CUSPARSE_STATUS_SUCCESS; - cudaError_t cuda_status = cudaSuccess; - - cusolver_status = cusolverSpCreate(&(user_data->cusolverHandle)); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cusolver_status = cusolverSpSetStream(user_data->cusolverHandle, stream); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cusparse_status = cusparseCreate(&(user_data->cuSPHandle)); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - - cusparse_status = cusparseSetStream(user_data->cuSPHandle, stream); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - - A = SUNMatrix_cuSparse_NewBlockCSR( - NCELLS, (NUM_SPECIES + 1), (NUM_SPECIES + 1), user_data->NNZ, - user_data->cuSPHandle); - if (check_flag((void*)A, "SUNMatrix_cuSparse_NewBlockCSR", 0)) - return (1); - - int retval = SUNMatrix_cuSparse_SetFixedPattern(A, 1); - if (check_flag(&retval, "SUNMatrix_cuSparse_SetFixedPattern", 1)) - return (1); - - BL_PROFILE_VAR_START(SparsityStuff); - SPARSITY_PREPROC_SYST_CSR( - user_data->csr_col_index_h, user_data->csr_row_count_h, &HP, 1, 0); - amrex::Gpu::htod_memcpy( - &user_data->csr_col_index_d, &user_data->csr_col_index_h, - sizeof(user_data->csr_col_index_h)); - amrex::Gpu::htod_memcpy( - &user_data->csr_row_count_d, &user_data->csr_row_count_h, - sizeof(user_data->csr_row_count_h)); - SUNMatrix_cuSparse_CopyToDevice( - A, NULL, user_data->csr_row_count_h, user_data->csr_col_index_h); - BL_PROFILE_VAR_STOP(SparsityStuff); - } else { - BL_PROFILE_VAR_START(SparsityStuff); - SPARSITY_INFO_SYST(&(user_data->NNZ), &HP, 1); - BL_PROFILE_VAR_STOP(SparsityStuff); - - BL_PROFILE_VAR_START(AllocsCVODE); - user_data->csr_row_count_h = - (int*)The_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); - user_data->csr_col_index_h = - (int*)The_Arena()->alloc(user_data->NNZ * sizeof(int)); - - user_data->csr_row_count_d = - (int*)The_Device_Arena()->alloc((NUM_SPECIES + 2) * sizeof(int)); - user_data->csr_col_index_d = - (int*)The_Device_Arena()->alloc(user_data->NNZ * sizeof(int)); - BL_PROFILE_VAR_STOP(AllocsCVODE); - - cusparseStatus_t cusparse_status = CUSPARSE_STATUS_SUCCESS; - - cusparse_status = cusparseCreate(&(user_data->cuSPHandle)); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - - cusparse_status = cusparseSetStream(user_data->cuSPHandle, stream); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - - A = SUNMatrix_cuSparse_NewBlockCSR( - NCELLS, (NUM_SPECIES + 1), (NUM_SPECIES + 1), user_data->NNZ, - user_data->cuSPHandle); - if (check_flag((void*)A, "SUNMatrix_cuSparse_NewBlockCSR", 0)) - return (1); - - int retval = SUNMatrix_cuSparse_SetFixedPattern(A, 1); - if (check_flag(&retval, "SUNMatrix_cuSparse_SetFixedPattern", 1)) - return (1); - - BL_PROFILE_VAR_START(SparsityStuff); - SPARSITY_PREPROC_SYST_CSR( - user_data->csr_col_index_h, user_data->csr_row_count_h, &HP, 1, 0); - amrex::Gpu::htod_memcpy( - &user_data->csr_col_index_d, &user_data->csr_col_index_h, - sizeof(user_data->csr_col_index_h)); - amrex::Gpu::htod_memcpy( - &user_data->csr_row_count_d, &user_data->csr_row_count_h, - sizeof(user_data->csr_row_count_h)); - SUNMatrix_cuSparse_CopyToDevice( - A, NULL, user_data->csr_row_count_h, user_data->csr_col_index_h); - BL_PROFILE_VAR_STOP(SparsityStuff); - } - } -#endif - -#if defined(AMREX_USE_CUDA) - y = N_VNewWithMemHelp_Cuda( - neq_tot, /*use_managed_mem=*/true, - *amrex::sundials::The_SUNMemory_Helper()); - if (check_flag((void*)y, "N_VNewWithMemHelp_Cuda", 0)) - return (1); -#elif defined(AMREX_USE_HIP) - y = N_VNewWithMemHelp_Hip( - neq_tot, /*use_managed_mem=*/true, - *amrex::sundials::The_SUNMemory_Helper()); - if (check_flag((void*)y, "N_VNewWithMemHelp_Hip", 0)) - return (1); -#else - y = N_VNew_Serial(neq_tot); - if (check_flag((void*)y, "N_VNew_Serial", 0)) - return (1); -#endif - -#if defined(AMREX_USE_CUDA) - SUNCudaExecPolicy* stream_exec_policy = - new SUNCudaThreadDirectExecPolicy(256, stream); - SUNCudaExecPolicy* reduce_exec_policy = - new SUNCudaBlockReduceExecPolicy(256, 0, stream); - N_VSetKernelExecPolicy_Cuda(y, stream_exec_policy, reduce_exec_policy); -#elif defined(AMREX_USE_HIP) - SUNHipExecPolicy* stream_exec_policy = - new SUNHipThreadDirectExecPolicy(256, stream); - SUNHipExecPolicy* reduce_exec_policy = - new SUNHipBlockReduceExecPolicy(256, 0, stream); - N_VSetKernelExecPolicy_Hip(y, stream_exec_policy, reduce_exec_policy); -#endif - - cvode_mem = CVodeCreate(CV_BDF); - if (check_flag((void*)cvode_mem, "CVodeCreate", 0)) - return (1); - - flag = CVodeSetUserData(cvode_mem, static_cast(user_data)); - - BL_PROFILE_VAR_START(AllocsCVODE); - user_data->rhoe_init_d = - (double*)The_Device_Arena()->alloc(NCELLS * sizeof(double)); - user_data->rhoesrc_ext_d = - (double*)The_Device_Arena()->alloc(NCELLS * sizeof(double)); - user_data->rYsrc_d = - (double*)The_Device_Arena()->alloc(NCELLS * NUM_SPECIES * sizeof(double)); - BL_PROFILE_VAR_STOP(AllocsCVODE); - -#if defined(AMREX_USE_CUDA) - realtype* yvec_d = N_VGetDeviceArrayPointer_Cuda(y); -#elif defined(AMREX_USE_HIP) - realtype* yvec_d = N_VGetDeviceArrayPointer_Hip(y); -#else - realtype* yvec_d = N_VGetArrayPointer(y); -#endif - - BL_PROFILE_VAR("reactor::FlatStuff", FlatStuff); - const auto len = amrex::length(box); - const auto lo = amrex::lbound(box); - amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); - - box_flatten( - icell, NCELLS, i, j, k, user_data->ireactor_type, rY_in, rY_src_in, T_in, - rEner_in, rEner_src_in, yvec_d, user_data->rYsrc_d, - user_data->rhoe_init_d, user_data->rhoesrc_ext_d); - }); - BL_PROFILE_VAR_STOP(FlatStuff); - -#ifdef AMREX_USE_OMP - Gpu::Device::streamSynchronize(); -#endif - - amrex::Real time_init = time; - amrex::Real time_out = time + dt_react; - - // Call CVodeInit to initialize the integrator memory and specify the - // user's right hand side function, the inital time, and - // initial dependent variable vector y. - flag = CVodeInit(cvode_mem, cF_RHS, time_init, y); - if (check_flag(&flag, "CVodeInit", 1)) - return (1); - - atol = N_VClone(y); -#if defined(AMREX_USE_CUDA) - ratol = N_VGetHostArrayPointer_Cuda(atol); -#elif defined(AMREX_USE_HIP) - ratol = N_VGetHostArrayPointer_Hip(atol); -#else - ratol = N_VGetArrayPointer(atol); -#endif - if (typVals[0] > 0) { - printf( - "Setting CVODE tolerances rtol = %14.8e atolfact = %14.8e in PelePhysics " - "\n", - relTol, absTol); - for (int i = 0; i < NCELLS; i++) { - int offset = i * (NUM_SPECIES + 1); - for (int k = 0; k < NUM_SPECIES + 1; k++) { - ratol[offset + k] = typVals[k] * absTol; - } - } - } else { - for (int i = 0; i < neq_tot; i++) { - ratol[i] = absTol; - } - } -#if defined(AMREX_USE_CUDA) - N_VCopyToDevice_Cuda(atol); -#elif defined(AMREX_USE_HIP) - N_VCopyToDevice_Hip(atol); -#endif - // Call CVodeSVtolerances to specify the scalar relative tolerance - // and vector absolute tolerances - flag = CVodeSVtolerances(cvode_mem, relTol, atol); - if (check_flag(&flag, "CVodeSVtolerances", 1)) - return (1); - - if (user_data->isolve_type == iterative_gmres_solve) { - if (user_data->ianalytical_jacobian == 0) { - LS = SUNLinSol_SPGMR(y, PREC_NONE, 0); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - } else { - LS = SUNLinSol_SPGMR(y, PREC_LEFT, 0); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - } - - flag = CVodeSetLinearSolver(cvode_mem, LS, NULL); - if (check_flag(&flag, "CVodeSetLinearSolver", 1)) - return (1); - - flag = CVodeSetJacTimes(cvode_mem, NULL, NULL); - if (check_flag(&flag, "CVodeSetJacTimes", 1)) - return (1); - - if (user_data->ianalytical_jacobian == 1) { -#if defined(AMREX_USE_CUDA) - flag = CVodeSetPreconditioner(cvode_mem, Precond, PSolve); - if (check_flag(&flag, "CVodeSetPreconditioner", 1)) - return (1); -#else - Abort("No options for preconditioning on non-CUDA GPUs"); -#endif - } - -#if defined(AMREX_USE_CUDA) - } else if (user_data->isolve_type == sparse_solve) { - LS = SUNLinSol_cuSolverSp_batchQR(y, A, user_data->cusolverHandle); - if (check_flag((void*)LS, "SUNLinSol_cuSolverSp_batchQR", 0)) - return (1); - - flag = CVodeSetLinearSolver(cvode_mem, LS, A); - if (check_flag(&flag, "CVodeSetLinearSolver", 1)) - return (1); - - flag = CVodeSetJacFn(cvode_mem, cJac); - if (check_flag(&flag, "CVodeSetJacFn", 1)) - return (1); - - } else { - LS = SUNLinSol_dense_custom(y, A, stream); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - - flag = CVodeSetLinearSolver(cvode_mem, LS, A); - if (check_flag(&flag, "CVodeSetLinearSolver", 1)) - return (1); - - flag = CVodeSetJacFn(cvode_mem, cJac); - if (check_flag(&flag, "CVodeSetJacFn", 1)) - return (1); -#endif - } - - flag = CVodeSetMaxNumSteps(cvode_mem, 100000); - if (check_flag(&flag, "CVodeSetMaxNumSteps", 1)) - return (1); - - flag = CVodeSetMaxOrd(cvode_mem, 2); - if (check_flag(&flag, "CVodeSetMaxOrd", 1)) - return (1); - - BL_PROFILE_VAR("AroundCVODE", AroundCVODE); - flag = CVode(cvode_mem, time_out, y, &time_init, CV_NORMAL); - if (check_flag(&flag, "CVode", 1)) - return (1); - BL_PROFILE_VAR_STOP(AroundCVODE); - -#ifdef MOD_REACTOR - dt_react = time_init - time; - time = time_init; -#endif - -#ifdef AMREX_USE_OMP - Gpu::Device::streamSynchronize(); -#endif - - long int nfe; - flag = CVodeGetNumRhsEvals(cvode_mem, &nfe); - - BL_PROFILE_VAR_START(FlatStuff); - amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); - - box_unflatten( - icell, NCELLS, i, j, k, user_data->ireactor_type, rY_in, T_in, rEner_in, - rEner_src_in, FC_in, yvec_d, user_data->rhoe_init_d, nfe, dt_react); - }); - BL_PROFILE_VAR_STOP(FlatStuff); - - if (user_data->iverbose > 1) { - PrintFinalStats(cvode_mem); - } - - N_VDestroy(y); - CVodeFree(&cvode_mem); - - SUNLinSolFree(LS); - - if (user_data->isolve_type != iterative_gmres_solve) { - SUNMatDestroy(A); - } - - The_Device_Arena()->free(user_data->rhoe_init_d); - The_Device_Arena()->free(user_data->rhoesrc_ext_d); - The_Device_Arena()->free(user_data->rYsrc_d); - - if (user_data->ianalytical_jacobian == 1) { -#ifdef AMREX_USE_CUDA - The_Arena()->free(user_data->csr_row_count_h); - The_Arena()->free(user_data->csr_col_index_h); - if (user_data->isolve_type == iterative_gmres_solve) { - The_Arena()->free(user_data->csr_val_h); - The_Arena()->free(user_data->csr_jac_h); - The_Device_Arena()->free(user_data->csr_val_d); - The_Device_Arena()->free(user_data->csr_jac_d); - - cusolverStatus_t cusolver_status = - cusolverSpDestroy(user_data->cusolverHandle); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cusolver_status = cusolverSpDestroyCsrqrInfo(user_data->info); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cudaFree(user_data->buffer_qr); - } else if (user_data->isolve_type == sparse_solve) { - cusolverStatus_t cusolver_status = - cusolverSpDestroy(user_data->cusolverHandle); - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cusparseStatus_t cusparse_status = cusparseDestroy(user_data->cuSPHandle); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - } else { - cusparseStatus_t cusparse_status = cusparseDestroy(user_data->cuSPHandle); - assert(cusparse_status == CUSPARSE_STATUS_SUCCESS); - } -#else - Abort("Shoudn't be there. Analytical Jacobian only available with CUDA !"); -#endif - } - - The_Arena()->free(user_data); - - N_VDestroy(atol); - - return nfe; -} - -static int -cF_RHS(realtype t, N_Vector y_in, N_Vector ydot_in, void* user_data) -{ - BL_PROFILE_VAR("fKernelSpec()", fKernelSpec); - -#if defined(AMREX_USE_CUDA) - realtype* yvec_d = N_VGetDeviceArrayPointer_Cuda(y_in); - realtype* ydot_d = N_VGetDeviceArrayPointer_Cuda(ydot_in); -#elif defined(AMREX_USE_HIP) - realtype* yvec_d = N_VGetDeviceArrayPointer_Hip(y_in); - realtype* ydot_d = N_VGetDeviceArrayPointer_Hip(ydot_in); -#else - realtype* yvec_d = N_VGetArrayPointer(y_in); - realtype* ydot_d = N_VGetArrayPointer(ydot_in); -#endif - - CVODEUserData * udata = static_cast(user_data); - udata->dt_save = t; - - auto ncells = udata->ncells; - auto dt_save = udata->dt_save; - auto reactor_type = udata->ireactor_type; - auto rhoe_init = udata->rhoe_init_d; - auto rhoesrc_ext = udata->rhoesrc_ext_d; - auto rYsrc = udata->rYsrc_d; -#ifdef AMREX_USE_GPU - const auto ec = Gpu::ExecutionConfig(udata->ncells); - // launch_global<<stream>>>( - launch_global<<< - udata->nbBlocks, udata->nbThreads, ec.sharedMem, udata->stream>>>( - [=] AMREX_GPU_DEVICE() noexcept { - for (int icell = blockDim.x * blockIdx.x + threadIdx.x, - stride = blockDim.x * gridDim.x; - icell < udata->ncells; icell += stride) { - fKernelSpec( - icell, ncells, dt_save, reactor_type, yvec_d, ydot_d, - rhoe_init, rhoesrc_ext, rYsrc); - } - }); - Gpu::Device::streamSynchronize(); -#else - for (int icell = 0; icell < udata->ncells; icell++) { - fKernelSpec( - icell, ncells, dt_save, reactor_type, yvec_d, ydot_d, - rhoe_init, rhoesrc_ext, rYsrc); - } -#endif - - BL_PROFILE_VAR_STOP(fKernelSpec); - - return (0); -} - -// React for 1d arrays -int -react( - realtype *rY_in, - realtype *rY_src_in, - realtype *rX_in, - realtype *rX_src_in, - realtype &dt_react, - realtype &time, - int reactor_type, - int Ncells -#ifdef AMREX_USE_GPU - , - amrex::gpuStream_t stream -#endif -) -{ - // ------------------------------------------------------------- - // CVODE structs - N_Vector y = NULL; // Solution vector - SUNLinearSolver LS = NULL; // Linear solver used in Newton solve - SUNMatrix A = NULL; // Chem. jacobian, if provided - void* cvode_mem = NULL; // CVODE internal memory pointer - N_Vector atol; // Component-wise abs. tolerance - realtype* ratol; // Rel. tolerance - - // temporary to catch CVODE exceptions - int flag; - - // ------------------------------------------------------------- - // ParmParse integrator options - ParmParse pp("ode"); - int ianalytical_jacobian = 0; - pp.query("analytical_jacobian", ianalytical_jacobian); - int iverbose = 1; - pp.query("verbose", iverbose); - - std::string solve_type_str = "none"; - ParmParse ppcv("cvode"); - ppcv.query("solve_type", solve_type_str); - /* - sparse_custom_solve = 1; - sparse_solve = 5; - iterative_gmres_solve = 99; - */ - int isolve_type = -1; - if (solve_type_str == "sparse_custom") { // Direct solve using custom GaussJordan routine - isolve_type = sparse_custom_solve; - } else if (solve_type_str == "sparse") { // Direct sparse solve using cuSolver (CUDA only !) - isolve_type = sparse_solve; - } else if (solve_type_str == "GMRES") { // Iter. solve using JFNK - isolve_type = iterative_gmres_solve; - } - - // ------------------------------------------------------------- - // Build CVODE data - - // System sizes - int NCELLS = Ncells; - int NEQ = NUM_SPECIES+1; // rhoYs + rhoH - int NEQSTOT = NEQ * NCELLS; - -#ifdef AMREX_USE_GPU - Gpu::streamSynchronize(); -#endif - - // Allocate CVODE data - BL_PROFILE_VAR("AllocsInCVODE", AllocsCVODE); - CVODEUserData * user_data; - user_data = (CVODEUserData*)The_Arena()->alloc(sizeof(struct CVODEUserData)); - user_data->rhoe_init_d = - (double*)The_Device_Arena()->alloc(NCELLS * sizeof(double)); - user_data->rhoesrc_ext_d = - (double*)The_Device_Arena()->alloc(NCELLS * sizeof(double)); - user_data->rYsrc_d = - (double*)The_Device_Arena()->alloc(NCELLS * NUM_SPECIES * sizeof(double)); - BL_PROFILE_VAR_STOP(AllocsCVODE); - - // Initialize CVODE options - user_data->ncells = NCELLS; - user_data->neqs_per_cell = NUM_SPECIES; - user_data->ireactor_type = reactor_type; - user_data->ianalytical_jacobian = ianalytical_jacobian; - user_data->isolve_type = isolve_type; - user_data->iverbose = iverbose; - user_data->nbBlocks = std::max(1, NCELLS / 32); -#ifdef AMREX_USE_GPU - user_data->stream = stream; -#endif - user_data->nbThreads = 32; - -#ifdef AMREX_USE_GPU - // For now, Abort() is analytical_jac required on GPU. - if (user_data->ianalytical_jacobian == 1) { - amrex::Abort("ode.analytical_jacobian = 1 currently unavailable on GPU"); - } -#endif - - // create solution Nvector -#if defined(AMREX_USE_CUDA) - y = N_VNewWithMemHelp_Cuda( - NEQSTOT, /*use_managed_mem=*/true, *amrex::sundials::The_SUNMemory_Helper()); - if (check_flag((void*)y, "N_VNewWithMemHelp_Cuda", 0)) - return (1); -#elif defined(AMREX_USE_HIP) - y = N_VNewWithMemHelp_Hip( - NEQSTOT, /*use_managed_mem=*/true, *amrex::sundials::The_SUNMemory_Helper()); - if (check_flag((void*)y, "N_VNewWithMemHelp_Hip", 0)) - return (1); -#else - y = N_VNew_Serial(NEQSTOT); - if (check_flag((void*)y, "N_VNew_Serial", 0)) - return (1); -#endif - - // On GPU, define execution policy -#if defined(AMREX_USE_CUDA) - SUNCudaExecPolicy* stream_exec_policy = - new SUNCudaThreadDirectExecPolicy(256, stream); - SUNCudaExecPolicy* reduce_exec_policy = - new SUNCudaBlockReduceExecPolicy(256, 0, stream); - N_VSetKernelExecPolicy_Cuda(y, stream_exec_policy, reduce_exec_policy); -#elif defined(AMREX_USE_HIP) - SUNHipExecPolicy* stream_exec_policy = - new SUNHipThreadDirectExecPolicy(256, stream); - SUNHipExecPolicy* reduce_exec_policy = - new SUNHipBlockReduceExecPolicy(256, 0, stream); - N_VSetKernelExecPolicy_Hip(y, stream_exec_policy, reduce_exec_policy); -#endif - - // Create CVODE object, specifying a Backward-Difference Formula method - cvode_mem = CVodeCreate(CV_BDF); - if (check_flag((void*)cvode_mem, "CVodeCreate", 0)) - return (1); - flag = CVodeSetUserData(cvode_mem, static_cast(user_data)); - - // ------------------------------------------------------------- - // Initialize solution vector -#if defined(AMREX_USE_CUDA) - realtype* yvec_d = N_VGetDeviceArrayPointer_Cuda(y); -#elif defined(AMREX_USE_HIP) - realtype* yvec_d = N_VGetDeviceArrayPointer_Hip(y); -#else - realtype* yvec_d = N_VGetArrayPointer(y); -#endif - - BL_PROFILE_VAR("AsyncCpy", AsyncCpy); -#ifdef AMREX_USE_GPU - amrex::Gpu::htod_memcpy_async( - yvec_d, rY_in, sizeof(realtype) * (NEQSTOT)); - amrex::Gpu::htod_memcpy_async( - user_data->rYsrc_d, rY_src_in, (NUM_SPECIES * NCELLS) * sizeof(realtype)); - amrex::Gpu::htod_memcpy_async( - user_data->rhoe_init_d, rX_in, sizeof(realtype) * NCELLS); - amrex::Gpu::htod_memcpy_async( - user_data->rhoesrc_ext_d, rX_src_in, sizeof(realtype) * NCELLS); -#else - std::memcpy(yvec_d, rY_in, sizeof(realtype) * (NEQSTOT)); - std::memcpy( - user_data->rYsrc_d, rY_src_in, (NUM_SPECIES * NCELLS) * sizeof(realtype)); - std::memcpy(user_data->rhoe_init_d, rX_in, sizeof(realtype) * NCELLS); - std::memcpy(user_data->rhoesrc_ext_d, rX_src_in, sizeof(realtype) * NCELLS); -#endif - BL_PROFILE_VAR_STOP(AsyncCpy); - - // ------------------------------------------------------------- - // Initialize integrator - amrex::Real time_init = time; - amrex::Real time_out = time + dt_react; - - /* Call CVodeInit to initialize the integrator memory and specify the - * user's right hand side function, the inital time, and - * initial dependent variable vector y. */ - flag = CVodeInit(cvode_mem, cF_RHS, time_init, y); - if (check_flag(&flag, "CVodeInit", 1)) { - return(1); - } - - // ------------------------------------------------------------- - // Define CVODE tolerances - atol = N_VClone(y); -#if defined(AMREX_USE_CUDA) - ratol = N_VGetHostArrayPointer_Cuda(atol); -#elif defined(AMREX_USE_HIP) - ratol = N_VGetHostArrayPointer_Hip(atol); -#else - ratol = N_VGetArrayPointer(atol); -#endif - if (typVals[0] > 0) { - printf( - "Setting CVODE tolerances rtol = %14.8e atolfact = %14.8e in PelePhysics " - "\n", - relTol, absTol); - for (int i = 0; i < NCELLS; i++) { - int offset = i * (NUM_SPECIES + 1); - for (int k = 0; k < NUM_SPECIES + 1; k++) { - ratol[offset + k] = typVals[k] * absTol; - } - } - } else { - for (int i = 0; i < NEQSTOT; i++) { - ratol[i] = absTol; - } - } -#if defined(AMREX_USE_CUDA) - N_VCopyToDevice_Cuda(atol); -#elif defined(AMREX_USE_HIP) - N_VCopyToDevice_Hip(atol); -#endif - // Call CVodeSVtolerances to specify the scalar relative tolerance - // and vector absolute tolerances - flag = CVodeSVtolerances(cvode_mem, relTol, atol); - if (check_flag(&flag, "CVodeSVtolerances", 1)) { - return (1); - } - - // ------------------------------------------------------------- - // Define and set CVODE linear solver - if (user_data->isolve_type == iterative_gmres_solve) { - if (user_data->ianalytical_jacobian == 0) { - LS = SUNLinSol_SPGMR(y, PREC_NONE, 0); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - } else { -#ifdef AMREX_USE_GPU - amrex::Abort("ode.analytical_jacobian = 1 currently unavailable on GPU"), -#endif - LS = SUNLinSol_SPGMR(y, PREC_LEFT, 0); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - } - - flag = CVodeSetLinearSolver(cvode_mem, LS, NULL); - if (check_flag(&flag, "CVodeSetLinearSolver", 1)) - return (1); - - flag = CVodeSetJacTimes(cvode_mem, NULL, NULL); - if (check_flag(&flag, "CVodeSetJacTimes", 1)) - return (1); - - if (user_data->ianalytical_jacobian == 1) { -#if defined(AMREX_USE_CUDA) - flag = CVodeSetPreconditioner(cvode_mem, Precond, PSolve); - if (check_flag(&flag, "CVodeSetPreconditioner", 1)) - return (1); -#else - Abort("No options for preconditioning on non-CUDA GPUs"); -#endif - } - -#if defined(AMREX_USE_CUDA) - } else if (user_data->isolve_type == sparse_solve) { - LS = SUNLinSol_cuSolverSp_batchQR(y, A, user_data->cusolverHandle); - if (check_flag((void*)LS, "SUNLinSol_cuSolverSp_batchQR", 0)) - return (1); - - flag = CVodeSetLinearSolver(cvode_mem, LS, A); - if (check_flag(&flag, "CVodeSetLinearSolver", 1)) - return (1); - - flag = CVodeSetJacFn(cvode_mem, cJac); - if (check_flag(&flag, "CVodeSetJacFn", 1)) - return (1); - - } else { - LS = SUNLinSol_dense_custom(y, A, stream); - if (check_flag((void*)LS, "SUNDenseLinearSolver", 0)) - return (1); - - flag = CVodeSetLinearSolver(cvode_mem, LS, A); - if (check_flag(&flag, "CVodeSetLinearSolver", 1)) - return (1); - - flag = CVodeSetJacFn(cvode_mem, cJac); - if (check_flag(&flag, "CVodeSetJacFn", 1)) - return (1); -#endif - } - - // ------------------------------------------------------------- - // Other CVODE options - flag = CVodeSetMaxNumSteps(cvode_mem, 100000); - if (check_flag(&flag, "CVodeSetMaxNumSteps", 1)) - return (1); - - flag = CVodeSetMaxOrd(cvode_mem, 2); - if (check_flag(&flag, "CVodeSetMaxOrd", 1)) - return (1); - - // ------------------------------------------------------------- - // Actual CVODE solve - BL_PROFILE_VAR("AroundCVODE", AroundCVODE); - flag = CVode(cvode_mem, time_out, y, &time_init, CV_NORMAL); - if (check_flag(&flag, "CVode", 1)) - return (1); - BL_PROFILE_VAR_STOP(AroundCVODE); - -#ifdef MOD_REACTOR - dt_react = time_init - time; - time = time_init; -#endif - - // ------------------------------------------------------------- - // Get the result back - BL_PROFILE_VAR_START(AsyncCpy); -#ifdef AMREX_USE_GPU - amrex::Gpu::dtoh_memcpy_async( -#else - std::memcpy( -#endif - rY_in, yvec_d, (NEQ * NCELLS) * sizeof(realtype)); - for (int i = 0; i < NCELLS; i++) { - rX_in[i] = rX_in[i] + dt_react * rX_src_in[i]; - } - BL_PROFILE_VAR_STOP(AsyncCpy); - - // ------------------------------------------------------------- - // Get the number of RHS evaluations - long int nfe; - flag = CVodeGetNumRhsEvals(cvode_mem, &nfe); - if (user_data->iverbose > 1) { - PrintFinalStats(cvode_mem); - } - - // ------------------------------------------------------------- - // Clean up memory - N_VDestroy(y); - CVodeFree(&cvode_mem); - - SUNLinSolFree(LS); - - if (user_data->isolve_type != iterative_gmres_solve) { - SUNMatDestroy(A); - } - - The_Device_Arena()->free(user_data->rhoe_init_d); - The_Device_Arena()->free(user_data->rhoesrc_ext_d); - The_Device_Arena()->free(user_data->rYsrc_d); - - The_Arena()->free(user_data); - - N_VDestroy(atol); - - return nfe; -} - -#ifdef AMREX_USE_CUDA -static int -Precond( - realtype tn, - N_Vector u, - N_Vector fu, - booleantype jok, - booleantype* jcurPtr, - realtype gamma, - void* user_data) -{ - - BL_PROFILE_VAR("Precond()", Precond); - - cudaError_t cuda_status = cudaSuccess; - size_t workspaceInBytes, internalDataInBytes; - cusolverStatus_t cusolver_status = CUSOLVER_STATUS_SUCCESS; - - workspaceInBytes = 0; - internalDataInBytes = 0; - - realtype* u_d = N_VGetDeviceArrayPointer_Cuda(u); - realtype* udot_d = N_VGetDeviceArrayPointer_Cuda(fu); - - CVODEUserData * udata = static_cast(user_data); - udata->gamma = gamma; - - BL_PROFILE_VAR("fKernelComputeAJ()", fKernelComputeAJ); - if (jok) { - const auto ec = Gpu::ExecutionConfig(udata->ncells); - launch_global<<< - udata->nbBlocks, udata->nbThreads, ec.sharedMem, udata->stream>>>( - [=] AMREX_GPU_DEVICE() noexcept { - for (int icell = blockDim.x * blockIdx.x + threadIdx.x, - stride = blockDim.x * gridDim.x; - icell < udata->ncells; icell += stride) { - fKernelComputeAJsys(icell, user_data, u_d, udata->csr_val_d); - } - }); - *jcurPtr = SUNFALSE; - } else { - const auto ec = Gpu::ExecutionConfig(udata->ncells); - launch_global<<< - udata->nbBlocks, udata->nbThreads, ec.sharedMem, udata->stream>>>( - [=] AMREX_GPU_DEVICE() noexcept { - for (int icell = blockDim.x * blockIdx.x + threadIdx.x, - stride = blockDim.x * gridDim.x; - icell < udata->ncells; icell += stride) { - fKernelComputeallAJ(icell, user_data, u_d, udata->csr_val_d); - } - }); - *jcurPtr = SUNTRUE; - } - - cuda_status = cudaStreamSynchronize(udata->stream); - assert(cuda_status == cudaSuccess); - BL_PROFILE_VAR_STOP(fKernelComputeAJ); - - BL_PROFILE_VAR("InfoBatched(inPrecond)", InfoBatched); - cusolver_status = cusolverSpDcsrqrBufferInfoBatched( - udata->cusolverHandle, udata->neqs_per_cell + 1, udata->neqs_per_cell + 1, - (udata->NNZ), udata->descrA, udata->csr_val_d, udata->csr_row_count_d, - udata->csr_col_index_d, udata->ncells, udata->info, &internalDataInBytes, - &workspaceInBytes); - - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cuda_status = cudaDeviceSynchronize(); - assert(cuda_status == cudaSuccess); - - BL_PROFILE_VAR_STOP(InfoBatched); - - BL_PROFILE_VAR_STOP(Precond); - - return (0); -} -#endif - -#ifdef AMREX_USE_CUDA -static int -PSolve( - realtype tn, - N_Vector u, - N_Vector fu, - N_Vector r, - N_Vector z, - realtype gamma, - realtype delta, - int lr, - void* user_data) -{ - BL_PROFILE_VAR("Psolve()", cusolverPsolve); - - cudaError_t cuda_status = cudaSuccess; - cusolverStatus_t cusolver_status = CUSOLVER_STATUS_SUCCESS; - - CVODEUserData * udata = static_cast(user_data); - - realtype* z_d = N_VGetDeviceArrayPointer_Cuda(z); - realtype* r_d = N_VGetDeviceArrayPointer_Cuda(r); - - cusolver_status = cusolverSpDcsrqrsvBatched( - udata->cusolverHandle, udata->neqs_per_cell + 1, udata->neqs_per_cell + 1, - (udata->NNZ), udata->descrA, udata->csr_val_d, udata->csr_row_count_d, - udata->csr_col_index_d, r_d, z_d, udata->ncells, udata->info, - udata->buffer_qr); - - assert(cusolver_status == CUSOLVER_STATUS_SUCCESS); - - cuda_status = cudaDeviceSynchronize(); - assert(cuda_status == cudaSuccess); - - N_VCopyFromDevice_Cuda(z); - N_VCopyFromDevice_Cuda(r); - - BL_PROFILE_VAR_STOP(cusolverPsolve); - - // Checks - // if (udata->iverbose > 4) { - // for(int batchId = 0 ; batchId < udata->ncells; batchId++){ - // // measure |bj - Aj*xj| - // realtype *csrValAj = (udata->csr_val_d) + batchId * (udata->NNZ); - // double *xj = N_VGetHostArrayPointer_Cuda(z) + batchId * - // (udata->neqs_per_cell+1); double *bj = - // N_VGetHostArrayPointer_Cuda(r) + batchId * (udata->neqs_per_cell+1); - // // sup| bj - Aj*xj| - // double sup_res = 0; - // for(int row = 0 ; row < (udata->neqs_per_cell+1) ; row++){ - // printf("\n row %d: ", row); - // const int start = udata->csr_row_count_d[row] - 1; - // const int end = udata->csr_row_count_d[row +1] - 1; - // double Ax = 0.0; // Aj(row,:)*xj - // for(int colidx = start ; colidx < end ; colidx++){ - // const int col = udata->csr_col_index_d[colidx] - 1; - // const double Areg = csrValAj[colidx]; - // const double xreg = xj[col]; - // printf(" (%d, %14.8e, %14.8e, %14.8e) ", - // col,Areg,xreg,bj[row] ); Ax = Ax + Areg * xreg; - // } - // double rresidi = bj[row] - Ax; - // sup_res = (sup_res > fabs(rresidi))? sup_res : fabs(rresidi); - // } - // printf("batchId %d: sup|bj - Aj*xj| = %E \n", batchId, sup_res); - // } - //} - - return (0); -} -#endif - -#ifdef AMREX_USE_CUDA -// Will not work for cuSolver_sparse_solve right now -static int -cJac( - realtype t, - N_Vector y_in, - N_Vector fy, - SUNMatrix J, - void* user_data, - N_Vector tmp1, - N_Vector tmp2, - N_Vector tmp3) -{ - cudaError_t cuda_status = cudaSuccess; - - CVODEUserData * udata = static_cast(user_data); - - realtype* yvec_d = N_VGetDeviceArrayPointer_Cuda(y_in); - realtype* ydot_d = N_VGetDeviceArrayPointer_Cuda(fy); - - realtype* Jdata; - - BL_PROFILE_VAR("cJac::SparsityStuff", cJacSparsityStuff); - Jdata = SUNMatrix_cuSparse_Data(J); - if ( - (SUNMatrix_cuSparse_Rows(J) != - (udata->neqs_per_cell + 1) * (udata->ncells)) || - (SUNMatrix_cuSparse_Columns(J) != - (udata->neqs_per_cell + 1) * (udata->ncells)) || - (SUNMatrix_cuSparse_NNZ(J) != udata->ncells * udata->NNZ)) { - Print() << "Jac error: matrix is wrong size!\n"; - return 1; - } - BL_PROFILE_VAR_STOP(cJacSparsityStuff); - - BL_PROFILE_VAR("Jacobian()", fKernelJac); - const auto ec = Gpu::ExecutionConfig(udata->ncells); - launch_global<<< - udata->nbBlocks, udata->nbThreads, ec.sharedMem, udata->stream>>>( - [=] AMREX_GPU_DEVICE() noexcept { - for (int icell = blockDim.x * blockIdx.x + threadIdx.x, - stride = blockDim.x * gridDim.x; - icell < udata->ncells; icell += stride) { - fKernelComputeAJchem(icell, user_data, yvec_d, Jdata); - } - }); - cuda_status = cudaStreamSynchronize(udata->stream); - assert(cuda_status == cudaSuccess); - BL_PROFILE_VAR_STOP(fKernelJac); - - return (0); -} -#endif - -#ifdef AMREX_USE_CUDA -AMREX_GPU_DEVICE -AMREX_FORCE_INLINE -void -fKernelComputeAJchem(int ncell, void* user_data, realtype* u_d, realtype* Jdata) -{ - CVODEUserData * udata = static_cast(user_data); - - int u_offset = ncell * (NUM_SPECIES + 1); - int jac_offset = ncell * (udata->NNZ); - - realtype* u_curr = u_d + u_offset; - realtype* csr_jac_cell = Jdata + jac_offset; - - Real mw[NUM_SPECIES] = {0.0}; - get_mw(mw); - - Real rho_pt = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { - rho_pt = rho_pt + u_curr[n]; - } - - GpuArray massfrac; - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = u_curr[i] / rho_pt; - } - - Real temp_pt = u_curr[NUM_SPECIES]; - - int consP; - if (udata->ireactor_type == 1) { - consP = 0; - } else { - consP = 1; - } - GpuArray Jmat_pt; - auto eos = pele::physics::PhysicsType::eos(); - eos.RTY2JAC(rho_pt, temp_pt, massfrac.arr, Jmat_pt.arr, consP); - - for (int i = 0; i < udata->neqs_per_cell; i++) { - for (int k = 0; k < udata->neqs_per_cell; k++) { - Jmat_pt[k * (udata->neqs_per_cell + 1) + i] = - Jmat_pt[k * (udata->neqs_per_cell + 1) + i] * mw[i] / mw[k]; - } - Jmat_pt[i * (udata->neqs_per_cell + 1) + udata->neqs_per_cell] = - Jmat_pt[i * (udata->neqs_per_cell + 1) + udata->neqs_per_cell] / mw[i]; - Jmat_pt[udata->neqs_per_cell * (udata->neqs_per_cell + 1) + i] = - Jmat_pt[udata->neqs_per_cell * (udata->neqs_per_cell + 1) + i] * mw[i]; - } - int nbVals; - for (int i = 1; i < udata->neqs_per_cell + 2; i++) { - nbVals = udata->csr_row_count_d[i] - udata->csr_row_count_d[i - 1]; - for (int j = 0; j < nbVals; j++) { - int idx_cell = udata->csr_col_index_d[udata->csr_row_count_d[i - 1] + j]; - csr_jac_cell[udata->csr_row_count_d[i - 1] + j] = - Jmat_pt[idx_cell * (udata->neqs_per_cell + 1) + i - 1]; - } - } -} -#endif - -#ifdef AMREX_USE_CUDA -AMREX_GPU_DEVICE -AMREX_FORCE_INLINE -void -fKernelComputeallAJ( - int ncell, void* user_data, realtype* u_d, double* csr_val_arg) -{ - CVODEUserData * udata = static_cast(user_data); - - Real mw[NUM_SPECIES]; - GpuArray massfrac, activity; - GpuArray Jmat_pt; - Real rho_pt, temp_pt; - - int u_offset = ncell * (NUM_SPECIES + 1); - int jac_offset = ncell * (udata->NNZ); - - realtype* u_curr = u_d + u_offset; - realtype* csr_jac_cell = udata->csr_jac_d + jac_offset; - realtype* csr_val_cell = csr_val_arg + jac_offset; - - get_mw(mw); - - rho_pt = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { - rho_pt = rho_pt + u_curr[n]; - } - - for (int i = 0; i < NUM_SPECIES; i++) { - massfrac[i] = u_curr[i] / rho_pt; - } - - temp_pt = u_curr[NUM_SPECIES]; - - auto eos = pele::physics::PhysicsType::eos(); - eos.RTY2C(rho_pt, temp_pt, massfrac.arr, activity.arr); - - int consP; - if (udata->ireactor_type == 1) { - consP = 0; - } else { - consP = 1; - } - DWDOT_SIMPLIFIED(Jmat_pt.arr, activity.arr, &temp_pt, &consP); - - for (int i = 0; i < udata->neqs_per_cell; i++) { - for (int k = 0; k < udata->neqs_per_cell; k++) { - Jmat_pt[k * (udata->neqs_per_cell + 1) + i] = - Jmat_pt[k * (udata->neqs_per_cell + 1) + i] * mw[i] / mw[k]; - } - Jmat_pt[i * (udata->neqs_per_cell + 1) + udata->neqs_per_cell] = - Jmat_pt[i * (udata->neqs_per_cell + 1) + udata->neqs_per_cell] / mw[i]; - Jmat_pt[udata->neqs_per_cell * (udata->neqs_per_cell + 1) + i] = - Jmat_pt[udata->neqs_per_cell * (udata->neqs_per_cell + 1) + i] * mw[i]; - } - int nbVals; - for (int i = 1; i < udata->neqs_per_cell + 2; i++) { - nbVals = udata->csr_row_count_d[i] - udata->csr_row_count_d[i - 1]; - for (int j = 0; j < nbVals; j++) { - int idx = - udata->csr_col_index_d[udata->csr_row_count_d[i - 1] + j - 1] - 1; - if (idx == (i - 1)) { - csr_val_cell[udata->csr_row_count_d[i - 1] + j - 1] = - 1.0 - - (udata->gamma) * Jmat_pt[idx * (udata->neqs_per_cell + 1) + idx]; - csr_jac_cell[udata->csr_row_count_d[i - 1] + j - 1] = - Jmat_pt[idx * (udata->neqs_per_cell + 1) + idx]; - } else { - csr_val_cell[udata->csr_row_count_d[i - 1] + j - 1] = - -(udata->gamma) * Jmat_pt[idx * (udata->neqs_per_cell + 1) + i - 1]; - csr_jac_cell[udata->csr_row_count_d[i - 1] + j - 1] = - Jmat_pt[idx * (udata->neqs_per_cell + 1) + i - 1]; - } - } - } -} -#endif - -#ifdef AMREX_USE_CUDA -AMREX_GPU_DEVICE -AMREX_FORCE_INLINE -void -fKernelComputeAJsys( - int ncell, void* user_data, realtype* u_d, double* csr_val_arg) -{ - CVODEUserData * udata = static_cast(user_data); - - int jac_offset = ncell * (udata->NNZ); - - realtype* csr_jac_cell = udata->csr_jac_d + jac_offset; - realtype* csr_val_cell = csr_val_arg + jac_offset; - - int nbVals; - for (int i = 1; i < udata->neqs_per_cell + 2; i++) { - nbVals = udata->csr_row_count_d[i] - udata->csr_row_count_d[i - 1]; - for (int j = 0; j < nbVals; j++) { - int idx = - udata->csr_col_index_d[udata->csr_row_count_d[i - 1] + j - 1] - 1; - if (idx == (i - 1)) { - csr_val_cell[udata->csr_row_count_d[i - 1] + j - 1] = - 1.0 - - (udata->gamma) * csr_jac_cell[udata->csr_row_count_d[i - 1] + j - 1]; - } else { - csr_val_cell[udata->csr_row_count_d[i - 1] + j - 1] = - -(udata->gamma) * csr_jac_cell[udata->csr_row_count_d[i - 1] + j - 1]; - } - } - } -} -#endif - -#ifdef AMREX_USE_CUDA -__global__ void -fKernelDenseSolve( - int ncell, - realtype* x_d, - realtype* b_d, - int subsys_size, - int subsys_nnz, - realtype* csr_val) -{ - int stride = blockDim.x * gridDim.x; - - for (int icell = blockDim.x * blockIdx.x + threadIdx.x; icell < ncell; - icell += stride) { - int offset = icell * subsys_size; - int offset_A = icell * subsys_nnz; - - realtype* csr_val_cell = csr_val + offset_A; - realtype* x_cell = x_d + offset; - realtype* b_cell = b_d + offset; - - sgjsolve(csr_val_cell, x_cell, b_cell); - } -} -#endif - -#ifdef AMREX_USE_CUDA -SUNLinearSolver -SUNLinSol_dense_custom(N_Vector y, SUNMatrix A, cudaStream_t stream) -{ - if (y == NULL || A == NULL) - return (NULL); - - if (N_VGetVectorID(y) != SUNDIALS_NVEC_CUDA) - return (NULL); - if (SUNMatGetID(A) != SUNMATRIX_CUSPARSE) - return (NULL); - - if (N_VGetLength(y) != SUNMatrix_cuSparse_Columns(A)) - return (NULL); - - if (!N_VIsManagedMemory_Cuda(y)) - return (NULL); - - SUNLinearSolver S; - S = NULL; - S = SUNLinSolNewEmpty(); - if (S == NULL) { - return (NULL); - } - - S->ops->gettype = SUNLinSolGetType_Dense_custom; - S->ops->setup = SUNLinSolSetup_Dense_custom; - S->ops->solve = SUNLinSolSolve_Dense_custom; - S->ops->free = SUNLinSolFree_Dense_custom; - - SUNLinearSolverContent_Dense_custom content; - content = NULL; - content = (SUNLinearSolverContent_Dense_custom)malloc(sizeof *content); - if (content == NULL) { - SUNLinSolFree(S); - return (NULL); - } - - S->content = content; - - content->last_flag = 0; - content->nsubsys = SUNMatrix_cuSparse_NumBlocks(A); - content->subsys_size = SUNMatrix_cuSparse_BlockRows(A); - content->subsys_nnz = SUNMatrix_cuSparse_BlockNNZ(A); - content->nbBlocks = std::max(1, content->nsubsys / 32); - content->nbThreads = 32; - content->stream = stream; - - return (S); -} -#endif - -#ifdef AMREX_USE_CUDA -SUNLinearSolver_Type -SUNLinSolGetType_Dense_custom(SUNLinearSolver S) -{ - return (SUNLINEARSOLVER_DIRECT); -} -#endif - -#ifdef AMREX_USE_CUDA -int -SUNLinSolSetup_Dense_custom(SUNLinearSolver S, SUNMatrix A) -{ - return (SUNLS_SUCCESS); -} -#endif - -#ifdef AMREX_USE_CUDA -int -SUNLinSolSolve_Dense_custom( - SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, realtype tol) -{ - cudaError_t cuda_status = cudaSuccess; - - realtype* x_d = N_VGetDeviceArrayPointer_Cuda(x); - realtype* b_d = N_VGetDeviceArrayPointer_Cuda(b); - - realtype* d_data = SUNMatrix_cuSparse_Data(A); - - BL_PROFILE_VAR("fKernelDenseSolve()", fKernelDenseSolve); - const auto ec = Gpu::ExecutionConfig(SUN_CUSP_NUM_SUBSYS(S)); - // TODO: why is this AMREX version NOT working ? - // launch_global<<>>( - // [=] AMREX_GPU_DEVICE () noexcept { - // for (int icell = blockDim.x*blockIdx.x+threadIdx.x, stride = - // blockDim.x*gridDim.x; - // icell < SUN_CUSP_NUM_SUBSYS(S); icell += stride) { - // fKernelDenseSolve(icell, x_d, b_d, - // SUN_CUSP_SUBSYS_SIZE(S), SUN_CUSP_SUBSYS_NNZ(S), data_d); - // } - // }); - fKernelDenseSolve<<< - SUN_CUSP_NBLOCK(S), SUN_CUSP_NTHREAD(S), ec.sharedMem, - SUN_CUSP_STREAM(S)>>>( - SUN_CUSP_NUM_SUBSYS(S), x_d, b_d, SUN_CUSP_SUBSYS_SIZE(S), - SUN_CUSP_SUBSYS_NNZ(S), d_data); - - cuda_status = cudaStreamSynchronize(SUN_CUSP_STREAM(S)); - assert(cuda_status == cudaSuccess); - - BL_PROFILE_VAR_STOP(fKernelDenseSolve); - - return (SUNLS_SUCCESS); -} -#endif - -#ifdef AMREX_USE_CUDA -int -SUNLinSolFree_Dense_custom(SUNLinearSolver S) -{ - if (S == NULL) - return (SUNLS_SUCCESS); - - if (S->content) { - free(S->content); - S->content = NULL; - } - - if (S->ops) { - free(S->ops); - S->ops = NULL; - } - - free(S); - S = NULL; - - return (SUNLS_SUCCESS); -} -#endif - -static void -PrintFinalStats(void* cvodeMem) -{ - long lenrw, leniw; - long lenrwLS, leniwLS; - long int nst, nfe, nsetups, nni, ncfn, netf; - long int nli, npe, nps, ncfl, nfeLS; - int flag; - - flag = CVodeGetWorkSpace(cvodeMem, &lenrw, &leniw); - check_flag(&flag, "CVodeGetWorkSpace", 1); - flag = CVodeGetNumSteps(cvodeMem, &nst); - check_flag(&flag, "CVodeGetNumSteps", 1); - flag = CVodeGetNumRhsEvals(cvodeMem, &nfe); - check_flag(&flag, "CVodeGetNumRhsEvals", 1); - flag = CVodeGetNumLinSolvSetups(cvodeMem, &nsetups); - check_flag(&flag, "CVodeGetNumLinSolvSetups", 1); - flag = CVodeGetNumErrTestFails(cvodeMem, &netf); - check_flag(&flag, "CVodeGetNumErrTestFails", 1); - flag = CVodeGetNumNonlinSolvIters(cvodeMem, &nni); - check_flag(&flag, "CVodeGetNumNonlinSolvIters", 1); - flag = CVodeGetNumNonlinSolvConvFails(cvodeMem, &ncfn); - check_flag(&flag, "CVodeGetNumNonlinSolvConvFails", 1); - - flag = CVodeGetLinWorkSpace(cvodeMem, &lenrwLS, &leniwLS); - check_flag(&flag, "CVodeGetLinWorkSpace", 1); - flag = CVodeGetNumLinIters(cvodeMem, &nli); - check_flag(&flag, "CVodeGetNumLinIters", 1); - // flag = CVodeGetNumJacEvals(cvodeMem, &nje); - // check_flag(&flag, "CVodeGetNumJacEvals", 1); - flag = CVodeGetNumLinRhsEvals(cvodeMem, &nfeLS); - check_flag(&flag, "CVodeGetNumLinRhsEvals", 1); - - flag = CVodeGetNumPrecEvals(cvodeMem, &npe); - check_flag(&flag, "CVodeGetNumPrecEvals", 1); - flag = CVodeGetNumPrecSolves(cvodeMem, &nps); - check_flag(&flag, "CVodeGetNumPrecSolves", 1); - - flag = CVodeGetNumLinConvFails(cvodeMem, &ncfl); - check_flag(&flag, "CVodeGetNumLinConvFails", 1); - -#ifdef _OPENMP - Print() << "\nFinal Statistics: " - << "(thread:" << omp_get_thread_num() << ", "; - Print() << "cvodeMem:" << cvodeMem << ")\n"; -#else - Print() << "\nFinal Statistics:\n"; -#endif - Print() << "lenrw = " << lenrw << " leniw = " << leniw - << "\n"; - Print() << "lenrwLS = " << lenrwLS << " leniwLS = " << leniwLS - << "\n"; - Print() << "nSteps = " << nst << "\n"; - Print() << "nRHSeval = " << nfe << " nLinRHSeval = " << nfeLS << "\n"; - Print() << "nnLinIt = " << nni << " nLinIt = " << nli << "\n"; - Print() << "nLinsetups = " << nsetups << " nErrtf = " << netf - << "\n"; - Print() << "nPreceval = " << npe << " nPrecsolve = " << nps << "\n"; - Print() << "nConvfail = " << ncfn << " nLinConvfail = " << ncfl - << "\n\n"; -} diff --git a/Reactions/cvode/reactor_utils.H b/Reactions/cvode/reactor_utils.H deleted file mode 100644 index 8be4467da..000000000 --- a/Reactions/cvode/reactor_utils.H +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _REACTOR_UTILS_H_ -#define _REACTOR_UTILS_H_ - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE int -sunvec_index(const int specie_idx, const int icell, const int /*ncells*/) -{ - return icell * (NUM_SPECIES + 1) + specie_idx; -} - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE int -sunspec_index(const int specie_idx, const int icell, const int /*ncells*/) -{ - return icell * NUM_SPECIES + specie_idx; -} -#endif diff --git a/Reactions/null/Make.package b/Reactions/null/Make.package deleted file mode 100644 index b128b61e9..000000000 --- a/Reactions/null/Make.package +++ /dev/null @@ -1,2 +0,0 @@ -CEXE_headers += reactor.H -CEXE_sources += reactor.cpp diff --git a/Reactions/null/reactor.H b/Reactions/null/reactor.H deleted file mode 100644 index 88ea793a2..000000000 --- a/Reactions/null/reactor.H +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _REACTOR_H_ -#define _REACTOR_H_ - -#include -#include -#include - -#include "PelePhysics.H" - -#ifdef AMREX_USE_GPU - -int reactor_info(int cvode_iE, int Ncells); - -int react( - const amrex::Box& box, - amrex::Array4 const& rY_in, - amrex::Array4 const& rY_src_in, - amrex::Array4 const& T_in, - amrex::Array4 const& rEner_in, - amrex::Array4 const& rEner_src_in, - amrex::Array4 const& FC_in, - amrex::Array4 const& mask, - amrex::Real& dt_react, - amrex::Real& time, - const int& reactor_type, - amrex::gpuStream_t stream); - -int react( - amrex::Real* rY_in, - amrex::Real* rY_src_in, - amrex::Real* rX_in, - amrex::Real* rX_src_in, - amrex::Real& dt_react, - amrex::Real& time, - int cvode_iE, - int Ncells, - amrex::gpuStream_t stream); - -void reactor_close(); - -void SetTypValsODE(const std::vector& ExtTypVals); - -void SetTolFactODE(amrex::Real relative_tol, amrex::Real absolute_tol); - -#else - -int reactor_init(int cvode_iE, int Ncells); - -int react( - const amrex::Box& box, - amrex::Array4 const& rY_in, - amrex::Array4 const& rY_src_in, - amrex::Array4 const& T_in, - amrex::Array4 const& rEner_in, - amrex::Array4 const& rEner_src_in, - amrex::Array4 const& FC_in, - amrex::Array4 const& mask, - amrex::Real& dt_react, - amrex::Real& time, - const int& reactor_type); - -int react( - amrex::Real* rY_in, - amrex::Real* rY_src_in, - amrex::Real* rX_in, - amrex::Real* rX_src_in, - amrex::Real& dt_react, - amrex::Real& time); - -void reactor_close(); - -void SetTypValsODE(const std::vector& ExtTypVals); - -void SetTolFactODE(amrex::Real relative_tol, amrex::Real absolute_tol); - -void ReSetTolODE(); - -#endif -#endif diff --git a/Reactions/null/reactor.cpp b/Reactions/null/reactor.cpp deleted file mode 100644 index 8b03f442e..000000000 --- a/Reactions/null/reactor.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include "reactor.H" - -#ifdef AMREX_USE_GPU - -void -SetTypValsODE(const std::vector& ExtTypVals) -{ -} - -void -SetTolFactODE(amrex::Real relative_tol, amrex::Real absolute_tol) -{ -} - -int -reactor_info(int /*reactor_type*/, int /*ode_ncells*/) -{ - return (0); -} - -// Array4 version -int -react( - const amrex::Box& box, - amrex::Array4 const& rY_in, - amrex::Array4 const& rY_src_in, - amrex::Array4 const& T_in, - amrex::Array4 const& rEner_in, - amrex::Array4 const& rEner_src_in, - amrex::Array4 const& FC_in, - amrex::Array4 const& mask, - amrex::Real& dt_react, - amrex::Real& time, - const int& reactor_type, - amrex::gpuStream_t stream) -{ - - int omp_thread = 0; -#ifdef _OPENMP - omp_thread = omp_get_thread_num(); -#endif - - constexpr int eint_rho = 1; - constexpr int enth_rho = 2; - - amrex::Real time_init = time; - - ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real renergy_loc = - rEner_in(i, j, k, 0) + rEner_src_in(i, j, k, 0) * dt_react; - rEner_in(i, j, k, 0) = renergy_loc; - amrex::Real rY_loc[NUM_SPECIES]; - for (int n = 0; n < NUM_SPECIES; n++) { - rY_loc[n] = rY_in(i, j, k, n) + rY_src_in(i, j, k, n) * dt_react; - rY_in(i, j, k, n) = rY_loc[n]; - } - amrex::Real rho_loc = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { - rho_loc += rY_loc[n]; - } - amrex::Real Y_loc[NUM_SPECIES]; - for (int n = 0; n < NUM_SPECIES; n++) { - Y_loc[n] = rY_loc[n] / rho_loc; - } - amrex::Real energy_loc = renergy_loc / rho_loc; - amrex::Real T_loc = T_in(i, j, k, 0); - auto eos = pele::physics::PhysicsType::eos(); - if (reactor_type == eint_rho) { - eos.REY2T(rho_loc, energy_loc, Y_loc, T_loc); - } else { - eos.RHY2T(rho_loc, energy_loc, Y_loc, T_loc); - } - T_in(i, j, k, 0) = T_loc; - FC_in(i, j, k, 0) = 0.0; - }); - -#ifdef MOD_REACTOR - time = time_init + dt_react; -#endif - return 0; -} - -// 1D version -int -react( - amrex::Real* rY_in, - amrex::Real* rY_src_in, - amrex::Real* rX_in, - amrex::Real* rX_src_in, - amrex::Real& dt_react, - amrex::Real& time, - int cvode_iE, - int Ncells, - amrex::gpuStream_t stream) -{ - amrex::Real time_init = time; -#ifdef MOD_REACTOR - time = time_init + dt_react; -#endif - return 0; -} - -void -reactor_close() -{ -} - -#else - -int ireactor_type; - -void -SetTypValsODE(const std::vector& ExtTypVals) -{ -} - -void -SetTolFactODE(amrex::Real relative_tol, amrex::Real absolute_tol) -{ -} - -void -ReSetTolODE() -{ -} - -int -reactor_init(int reactor_type, int /*ode_ncells*/) -{ - ireactor_type = reactor_type; - return (0); -} - -int -react( - const amrex::Box& box, - amrex::Array4 const& rY_in, - amrex::Array4 const& rY_src_in, - amrex::Array4 const& T_in, - amrex::Array4 const& rEner_in, - amrex::Array4 const& rEner_src_in, - amrex::Array4 const& FC_in, - amrex::Array4 const& mask, - amrex::Real& dt_react, - amrex::Real& time, - const int& reactor_type) -{ - int omp_thread = 0; -#ifdef _OPENMP - omp_thread = omp_get_thread_num(); -#endif - - constexpr int eint_rho = 1; - constexpr int enth_rho = 2; - - amrex::Real time_init = time; - - ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real renergy_loc = - rEner_in(i, j, k, 0) + rEner_src_in(i, j, k, 0) * dt_react; - rEner_in(i, j, k, 0) = renergy_loc; - amrex::Real rY_loc[NUM_SPECIES]; - for (int n = 0; n < NUM_SPECIES; n++) { - rY_loc[n] = rY_in(i, j, k, n) + rY_src_in(i, j, k, n) * dt_react; - rY_in(i, j, k, n) = rY_loc[n]; - } - amrex::Real rho_loc = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { - rho_loc += rY_loc[n]; - } - amrex::Real Y_loc[NUM_SPECIES]; - for (int n = 0; n < NUM_SPECIES; n++) { - Y_loc[n] = rY_loc[n] / rho_loc; - } - amrex::Real energy_loc = renergy_loc / rho_loc; - amrex::Real T_loc = T_in(i, j, k, 0); - auto eos = pele::physics::PhysicsType::eos(); - if (reactor_type == eint_rho) { - eos.REY2T(rho_loc, energy_loc, Y_loc, T_loc); - } else { - eos.RHY2T(rho_loc, energy_loc, Y_loc, T_loc); - } - T_in(i, j, k, 0) = T_loc; - FC_in(i, j, k, 0) = 0.0; - }); - -#ifdef MOD_REACTOR - time = time_init + dt_react; -#endif - return 0; -} - -int -react( - amrex::Real* rY_in, - amrex::Real* rY_src_in, - amrex::Real* rX_in, - amrex::Real* rX_src_in, - amrex::Real& dt_react, - amrex::Real& time) -{ - amrex::Real time_init = time; -#ifdef MOD_REACTOR - time = time_init + dt_react; -#endif - return 0; -} - -void -reactor_close() -{ -} - -#endif diff --git a/Reactions/reactor.H b/Reactions/reactor.H deleted file mode 100644 index 5bab15d93..000000000 --- a/Reactions/reactor.H +++ /dev/null @@ -1,655 +0,0 @@ -#ifndef _REACTOR_H_ -#define _REACTOR_H_ - -//#include - -#include -#include -#include -#include -#include -#include -#include "PelePhysics.H" -#include "mechanism.H" -#include "reactor_utils.H" - -#ifdef USE_SUNDIALS_PP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef USE_KLU_PP -#include "klu.h" -#include -#endif - -#ifdef AMREX_USE_CUDA -#include -#include -#include -#include -#include -#include -#include -#include -#endif - -#ifdef AMREX_USE_GPU -#include "AMReX_SUNMemory.H" -#endif - -#ifdef AMREX_USE_HIP -#include -#endif - -#endif - -extern amrex::Array typVals; -extern int eint_rho; // in/out = rhoE/rhoY -extern int enth_rho; // in/out = rhoH/rhoY -extern amrex::Real relTol; -extern amrex::Real absTol; -extern amrex::Real time_init; -extern int dense_solve; -extern int sparse_solve; -extern int iterative_gmres_solve; -extern int sparse_solve_custom; -extern int iterative_gmres_solve_custom; -extern int hack_dump_sparsity_pattern; -extern int sparse_cusolver_solve; -extern int sparse_custom_solve; -extern int use_erkstep; -extern int rk_method; -extern int rk_controller; - -extern int rk64_nsubsteps_guess; -extern int rk64_nsubsteps_min; -extern int rk64_nsubsteps_max; - -#ifdef AMREX_USE_OMP -#pragma omp threadprivate(time_init) -#pragma omp threadprivate(typVals) -#pragma omp threadprivate(relTol, absTol) -#pragma omp threadprivate(rk64_nsubsteps_guess, rk64_nsubsteps_min, rk64_nsubsteps_max) -#endif - -//=================================================================== -// initialize and close reactor functions -//=================================================================== -int reactor_init(int reactor_type, int Ncells); -void reactor_close(); -//=================================================================== - -//=================================================================== -// User data to feed into CPU/GPU sundials handle -//=================================================================== -#ifdef USE_SUNDIALS_PP - -#ifdef AMREX_USE_GPU -struct CVODEUserData -{ - amrex::Real gamma; - amrex::Real dt_save; - int ncells; - int neqs_per_cell; - int ireactor_type; - int ianalytical_jacobian; - int isolve_type; - amrex::Real* rhoe_init_d = NULL; - amrex::Real* rhoesrc_ext_d = NULL; - amrex::Real* rYsrc_d = NULL; - int iverbose; - int NNZ; - int* csr_row_count_h; - int* csr_col_index_h; - int* csr_row_count_d; - int* csr_col_index_d; - amrex::Real* csr_val_h; - amrex::Real* csr_jac_h; - amrex::Real* csr_val_d; - amrex::Real* csr_jac_d; - SUNMatrix R = NULL; -#ifdef AMREX_USE_CUDA - void* buffer_qr = NULL; - csrqrInfo_t info; - cusparseMatDescr_t descrA; - cusolverSpHandle_t cusolverHandle; - cusparseHandle_t cuSPHandle; -#endif - amrex::gpuStream_t stream; - int nbBlocks; - int nbThreads; -}; -#else -struct CVODEUserData -{ - amrex::Real dt_save; - bool FirstTimePrecond; - bool reactor_cvode_initialized; - bool actual_ok_to_react; - int ncells; - int iverbose; - int isolve_type; - int ianalytical_jacobian; - int ireactor_type; - int boxcell; - amrex::Real* Yvect_full = NULL; - amrex::Real* rhoX_init = NULL; - amrex::Real* rhoXsrc_ext = NULL; - amrex::Real* rYsrc = NULL; - int* FCunt = NULL; - int* mask = NULL; - - int NNZ; - SUNMatrix* PS; - amrex::Real** Jdata = NULL; - int** rowVals = NULL; - int** rowPtrs = NULL; - int** colPtrs = NULL; - int** colVals = NULL; - int* indx = NULL; - amrex::Real** JSPSmat = NULL; -#ifdef USE_KLU_PP - klu_common* Common; - klu_symbolic** Symbolic; - klu_numeric** Numeric; -#else - amrex::Real**** Jbd; - amrex::Real**** P; - sunindextype*** pivot; -#endif - SUNMatrix PSc; - int* colVals_c; - int* rowPtrs_c; -}; -#endif - -struct ARKODEUserData -{ - bool reactor_arkode_initialized; - int ncells_d; - int neqs_per_cell; - int iverbose; - int ireactor_type; - amrex::Real dt_save; - amrex::Real* rhoe_init_d = NULL; - amrex::Real* rhoesrc_ext_d = NULL; - amrex::Real* rYsrc_d = NULL; -#ifdef AMREX_USE_GPU - amrex::gpuStream_t stream; -#endif - int nbBlocks; - int nbThreads; -}; -#endif - -//=================================================================== -// Box flattening functions -//=================================================================== -AMREX_GPU_DEVICE AMREX_FORCE_INLINE void -box_flatten( - int icell, - int ncells, - int i, - int j, - int k, - int ireactor_type, - amrex::Array4 const& rhoY, - amrex::Array4 const& frcExt, - amrex::Array4 const& temperature, - amrex::Array4 const& rhoE, - amrex::Array4 const& frcEExt, - amrex::Real* tmp_vect, - amrex::Real* tmp_src_vect, - amrex::Real* tmp_vect_energy, - amrex::Real* tmp_src_vect_energy) -{ - amrex::Real mass_frac[NUM_SPECIES]; - amrex::Real rho = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { - const int idx = sunvec_index(n, icell, ncells); - const int idx2 = sunspec_index(n, icell, ncells); - const amrex::Real rhoYn = rhoY(i, j, k, n); - tmp_vect[idx] = rhoYn; - tmp_src_vect[idx2] = frcExt(i, j, k, n); - rho += rhoYn; - mass_frac[n] = rhoYn; - } - const amrex::Real rho_inv = 1.0 / rho; - for (int n = 0; n < NUM_SPECIES; n++) { - mass_frac[n] *= rho_inv; - } - - amrex::Real temp = temperature(i, j, k, 0); - tmp_vect_energy[icell] = rhoE(i, j, k, 0); - tmp_src_vect_energy[icell] = frcEExt(i, j, k, 0); - - amrex::Real Enrg_loc = tmp_vect_energy[icell] * rho_inv; - auto eos = pele::physics::PhysicsType::eos(); - if (ireactor_type == 1) { - eos.REY2T(rho, Enrg_loc, mass_frac, temp); - } else { - eos.RHY2T(rho, Enrg_loc, mass_frac, temp); - } - tmp_vect[sunvec_index(NUM_SPECIES, icell, ncells)] = temp; -} -//=================================================================== -AMREX_GPU_DEVICE AMREX_FORCE_INLINE void -box_unflatten( - int icell, - int ncells, - int i, - int j, - int k, - int ireactor_type, - amrex::Array4 const& rhoY, - amrex::Array4 const& T_in, - amrex::Array4 const& rhoE, - amrex::Array4 const& frcEExt, - amrex::Array4 const& FC_in, - amrex::Real* tmp_vect, - amrex::Real* tmp_vect_energy, - long int const& tmp_FCunt, - amrex::Real dt) -{ - amrex::Real mass_frac[NUM_SPECIES]; - amrex::Real rho = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { - const amrex::Real rhoYn = tmp_vect[sunvec_index(n, icell, ncells)]; - rhoY(i, j, k, n) = rhoYn; - rho += rhoYn; - mass_frac[n] = rhoYn; - } - const amrex::Real rho_inv = 1.0 / rho; - for (int n = 0; n < NUM_SPECIES; n++) { - mass_frac[n] *= rho_inv; - } - - amrex::Real temp = tmp_vect[sunvec_index(NUM_SPECIES, icell, ncells)]; - rhoE(i, j, k, 0) = tmp_vect_energy[icell] + dt * frcEExt(i, j, k, 0); - - amrex::Real Enrg_loc = rhoE(i, j, k, 0) * rho_inv; - auto eos = pele::physics::PhysicsType::eos(); - if (ireactor_type == 1) { - eos.REY2T(rho, Enrg_loc, mass_frac, temp); - } else { - eos.RHY2T(rho, Enrg_loc, mass_frac, temp); - } - T_in(i, j, k, 0) = temp; - FC_in(i, j, k, 0) = tmp_FCunt; -} -//=================================================================== - -//=================================================================== -// Tolerance setting with typical values -//=================================================================== -void SetTypValsODE(const std::vector& ExtTypVals); -void SetTolFactODE(amrex::Real relative_tol, amrex::Real absolute_tol); - -//=================================================================== -// RHS computation functions -//=================================================================== -#ifdef USE_SUNDIALS_PP -static int cF_RHS(amrex::Real t, N_Vector y_in, N_Vector ydot, void* user_data); -#endif - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE void -fKernelSpec( - int icell, - int ncells, - double dt_save, - int reactor_type, - amrex::Real* yvec_d, - amrex::Real* ydot_d, - amrex::Real* rhoe_init, - amrex::Real* rhoesrc_ext, - amrex::Real* rYs) -{ - amrex::Real rho_pt = 0.0; - amrex::GpuArray massfrac = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { - massfrac[n] = yvec_d[sunvec_index(n, icell, ncells)]; - rho_pt += massfrac[n]; - } - const amrex::Real rho_pt_inv = 1.0 / rho_pt; - - for (int n = 0; n < NUM_SPECIES; n++) { - massfrac[n] *= rho_pt_inv; - } - - const amrex::Real nrg_pt = - (rhoe_init[icell] + rhoesrc_ext[icell] * dt_save) * rho_pt_inv; - - amrex::Real temp_pt = yvec_d[sunvec_index(NUM_SPECIES, icell, ncells)]; - - amrex::Real Cv_pt = 0.0; - amrex::GpuArray ei_pt = {0.0}; - auto eos = pele::physics::PhysicsType::eos(); - if (reactor_type == 1) { - eos.REY2T(rho_pt, nrg_pt, massfrac.arr, temp_pt); - eos.RTY2Ei(rho_pt, temp_pt, massfrac.arr, ei_pt.arr); - eos.RTY2Cv(rho_pt, temp_pt, massfrac.arr, Cv_pt); - } else { - eos.RHY2T(rho_pt, nrg_pt, massfrac.arr, temp_pt); - eos.RTY2Hi(rho_pt, temp_pt, massfrac.arr, ei_pt.arr); - eos.RTY2Cp(rho_pt, temp_pt, massfrac.arr, Cv_pt); - } - - amrex::GpuArray cdots_pt = {0.0}; - eos.RTY2WDOT(rho_pt, temp_pt, massfrac.arr, cdots_pt.arr); - - amrex::Real rhoesrc = rhoesrc_ext[icell]; - for (int n = 0; n < NUM_SPECIES; n++) { - const amrex::Real cdot_rYs = - cdots_pt[n] + rYs[sunspec_index(n, icell, ncells)]; - ydot_d[sunvec_index(n, icell, ncells)] = cdot_rYs; - rhoesrc -= cdot_rYs * ei_pt[n]; - } - ydot_d[sunvec_index(NUM_SPECIES, icell, ncells)] = - rhoesrc * (rho_pt_inv / Cv_pt); -} -//=================================================================== - -//=================================================================== -// Different variants of react calls -//=================================================================== -int react( - const amrex::Box& box, - amrex::Array4 const& rY_in, - amrex::Array4 const& rY_src_in, - amrex::Array4 const& T_in, - amrex::Array4 const& rEner_in, - amrex::Array4 const& rEner_src_in, - amrex::Array4 const& FC_in, - amrex::Array4 const& mask, - amrex::Real& dt_react, - amrex::Real& time, - const int& reactor_type -#ifdef AMREX_USE_GPU - , - amrex::gpuStream_t stream -#endif -); - -int react( - amrex::Real* rY_in, - amrex::Real* rY_src_in, - amrex::Real* rX_in, - amrex::Real* rX_src_in, - amrex::Real& dt_react, - amrex::Real& time, - int reactor_type, - int Ncells -#ifdef AMREX_USE_GPU - , - amrex::gpuStream_t stream -#endif -); -//=================================================================== - -//=================================================================== -// CUDA specific things for cvode -//=================================================================== -#ifdef USE_SUNDIALS_PP - -#ifdef AMREX_USE_CUDA -static int Precond( - amrex::Real tn, - N_Vector u, - N_Vector fu, - booleantype jok, - booleantype* jcurPtr, - amrex::Real gamma, - void* user_data); - -static int PSolve( - amrex::Real tn, - N_Vector u, - N_Vector fu, - N_Vector r, - N_Vector z, - amrex::Real gamma, - amrex::Real delta, - int lr, - void* user_data); - -static int cJac( - amrex::Real t, - N_Vector y, - N_Vector fy, - SUNMatrix J, - void* user_data, - N_Vector tmp1, - N_Vector tmp2, - N_Vector tmp3); - -AMREX_GPU_DEVICE -AMREX_FORCE_INLINE -void fKernelComputeallAJ( - int ncells, void* user_data, amrex::Real* u_d, amrex::Real* csr_val); - -AMREX_GPU_DEVICE -AMREX_FORCE_INLINE -void fKernelComputeAJsys( - int ncells, void* user_data, amrex::Real* u_d, amrex::Real* csr_val); - -AMREX_GPU_DEVICE -AMREX_FORCE_INLINE -void fKernelComputeAJchem( - int ncells, void* user_data, amrex::Real* u_d, amrex::Real* Jdata); - -// CUSTOM -__global__ void fKernelDenseSolve( - int ncells, - amrex::Real* x_d, - amrex::Real* b_d, - int subsys_size, - int subsys_nnz, - amrex::Real* csr_val); - -struct _SUNLinearSolverContent_Dense_custom -{ - sunindextype last_flag; - int nsubsys; - int subsys_size; - int subsys_nnz; - int nbBlocks; - int nbThreads; - amrex::gpuStream_t stream; -}; - -typedef struct _SUNLinearSolverContent_Dense_custom* - SUNLinearSolverContent_Dense_custom; - -SUNLinearSolver -SUNLinSol_dense_custom(N_Vector y, SUNMatrix A, amrex::gpuStream_t stream); - -SUNLinearSolver_Type SUNLinSolGetType_Dense_custom(SUNLinearSolver S); - -int SUNLinSolSolve_Dense_custom( - SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, amrex::Real tol); - -int SUNLinSolSetup_Dense_custom(SUNLinearSolver S, SUNMatrix A); - -int SUNLinSolFree_Dense_custom(SUNLinearSolver S); -#endif - -#endif -//=================================================================== - -//=================================================================== -// Stats and checks -//=================================================================== -int check_flag(void* flagvalue, const char* funcname, int opt); - -#ifdef USE_SUNDIALS_PP - -// FIXME: make them the same -#ifdef AMREX_USE_GPU -static void PrintFinalStats(void* cvode_mem); -#else -static void PrintFinalStats(void* cvode_mem, amrex::Real Temp); -#endif - -#endif -//=================================================================== - -//=================================================================== -// CPU specific cvode functions -//=================================================================== -#ifdef USE_SUNDIALS_PP - -#ifndef AMREX_USE_GPU -CVODEUserData* AllocUserData(int reactor_type, int num_cells); - -int cJac( - amrex::Real tn, - N_Vector y, - N_Vector fy, - SUNMatrix J, - void* user_data, - N_Vector tmp1, - N_Vector tmp2, - N_Vector tmp3); - -int cJac_sps( - amrex::Real tn, - N_Vector y, - N_Vector fy, - SUNMatrix J, - void* user_data, - N_Vector tmp1, - N_Vector tmp2, - N_Vector tmp3); - -int PSolve_custom( - amrex::Real tn, - N_Vector u, - N_Vector fu, - N_Vector r, - N_Vector z, - amrex::Real gamma, - amrex::Real delta, - int lr, - void* user_data); - -int Precond_custom( - amrex::Real tn, - N_Vector u, - N_Vector fu, - booleantype jok, - booleantype* jcurPtr, - amrex::Real gamma, - void* user_data); - -#ifdef USE_KLU_PP -int cJac_KLU( - amrex::Real tn, - N_Vector y, - N_Vector fy, - SUNMatrix J, - void* user_data, - N_Vector tmp1, - N_Vector tmp2, - N_Vector tmp3); - -int PSolve_sparse( - amrex::Real tn, - N_Vector u, - N_Vector fu, - N_Vector r, - N_Vector z, - amrex::Real gamma, - amrex::Real delta, - int lr, - void* user_data); -int Precond_sparse( - amrex::Real tn, - N_Vector u, - N_Vector fu, - booleantype jok, - booleantype* jcurPtr, - amrex::Real gamma, - void* user_data); -#else -int PSolve( - amrex::Real tn, - N_Vector u, - N_Vector fu, - N_Vector r, - N_Vector z, - amrex::Real gamma, - amrex::Real delta, - int lr, - void* user_data); - -int Precond( - amrex::Real tn, - N_Vector u, - N_Vector fu, - booleantype jok, - booleantype* jcurPtr, - amrex::Real gamma, - void* user_data); -#endif - -int react_2( - const amrex::Box& box, - amrex::Array4 const& rY_in, - amrex::Array4 const& rY_src_in, - amrex::Array4 const& T_in, - amrex::Array4 const& rEner_in, - amrex::Array4 const& rEner_src_in, - amrex::Array4 const& FC_in, - amrex::Array4 const& mask, - amrex::Real& dt_react, - amrex::Real& time); - -void FreeUserData(CVODEUserData* data); - -void check_state(N_Vector yvec); - -void SetTypValsODE(const std::vector& ExtTypVals); - -void ReSetTolODE(); - -struct _SUNLinearSolverContent_Sparse_custom -{ - sunindextype last_flag; - int reactor_type; - int nsubsys; // number of subsystems - int subsys_size; // size of each subsystem - int subsys_nnz; -}; - -typedef struct _SUNLinearSolverContent_Sparse_custom* - SUNLinearSolverContent_Sparse_custom; - -SUNLinearSolver SUNLinSol_sparse_custom( - N_Vector y, - SUNMatrix A, - int reactor_type, - int nsubsys, - int subsys_size, - int subsys_nnz); - -SUNLinearSolver_Type SUNLinSolGetType_Sparse_custom(SUNLinearSolver S); - -int SUNLinSolSolve_Sparse_custom( - SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, amrex::Real tol); -#endif - -#endif -//=================================================================== - -#endif diff --git a/Reactions/reactor.cpp b/Reactions/reactor.cpp deleted file mode 100644 index 7b1fc2d02..000000000 --- a/Reactions/reactor.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "reactor.H" - -amrex::Array typVals = {-1}; -int eint_rho = 1; // in/out = rhoE/rhoY -int enth_rho = 2; // in/out = rhoH/rhoY -amrex::Real relTol = 1e-6; -amrex::Real absTol = 1e-10; -amrex::Real time_init = 0.0; -int dense_solve = 1; -int sparse_solve = 5; -int iterative_gmres_solve = 99; -int sparse_solve_custom = 101; -int iterative_gmres_solve_custom = 199; -int hack_dump_sparsity_pattern = -5; -int sparse_custom_solve = 2; -int use_erkstep = 0; -int rk_method = 40; -int rk_controller = 0; -int rk64_nsubsteps_guess = 10; -int rk64_nsubsteps_min = 5; -int rk64_nsubsteps_max = 500; - -//=================================================================== -void -SetTypValsODE(const std::vector& ExtTypVals) -{ - int size_ETV = ExtTypVals.size(); - amrex::Vector kname; - pele::physics::eos::speciesNames(kname); - int omp_thread = 0; - -#ifdef _OPENMP - omp_thread = omp_get_thread_num(); -#endif - - for (int i = 0; i < size_ETV - 1; i++) { - typVals[i] = ExtTypVals[i]; - } - typVals[size_ETV - 1] = ExtTypVals[size_ETV - 1]; - - if (omp_thread == 0) { - amrex::Print() << "Set the typVals in PelePhysics: \n "; - for (int i = 0; i < size_ETV - 1; i++) { - amrex::Print() << kname[i] << ":" << typVals[i] << " "; - } - amrex::Print() << "Temp:" << typVals[size_ETV - 1] << " \n"; - } -} -//=================================================================== -void -SetTolFactODE(amrex::Real relative_tol, amrex::Real absolute_tol) -{ - int omp_thread = 0; -#ifdef _OPENMP - omp_thread = omp_get_thread_num(); -#endif - relTol = relative_tol; - absTol = absolute_tol; - if (omp_thread == 0) { - amrex::Print() << "Set RTOL, ATOL = " << relTol << " " << absTol - << " in PelePhysics\n"; - } -} -//=================================================================== -// Check function return value... -// opt == 0 means SUNDIALS function allocates memory so check if -// returned NULL pointer -// opt == 1 means SUNDIALS function returns a flag so check if -// flag >= 0 -// opt == 2 means function allocates memory so check if returned -// NULL pointer -int -check_flag(void* flagvalue, const char* funcname, int opt) -{ - int* errflag; - - if (opt == 0 && flagvalue == NULL) { - if (amrex::ParallelDescriptor::IOProcessor()) { - fprintf( - stderr, "\nSUNDIALS_ERROR: %s() failed - returned NULL pointer\n\n", - funcname); - amrex::Abort("abort"); - } - return (1); - } else if (opt == 1) { - errflag = (int*)flagvalue; - if (*errflag < 0) { - if (amrex::ParallelDescriptor::IOProcessor()) { - fprintf( - stderr, "\nSUNDIALS_ERROR: %s() failed with flag = %d\n\n", funcname, - *errflag); - amrex::Abort("abort"); - } - return (1); - } - } else if (opt == 2 && flagvalue == NULL) { - if (amrex::ParallelDescriptor::IOProcessor()) { - fprintf( - stderr, "\nMEMORY_ERROR: %s() failed - returned NULL pointer\n\n", - funcname); - amrex::Abort("abort"); - } - return (1); - } - - return (0); -} -//=================================================================== diff --git a/Reactions/rk64/Make.package b/Reactions/rk64/Make.package deleted file mode 100644 index 34d3c631f..000000000 --- a/Reactions/rk64/Make.package +++ /dev/null @@ -1,3 +0,0 @@ -CEXE_headers += rkparams.H -CEXE_sources += reactor_rk64.cpp -CEXE_headers += reactor_utils.H diff --git a/Reactions/rk64/reactor_rk64.cpp b/Reactions/rk64/reactor_rk64.cpp deleted file mode 100644 index 63619070e..000000000 --- a/Reactions/rk64/reactor_rk64.cpp +++ /dev/null @@ -1,296 +0,0 @@ -#include "reactor.H" - -int -reactor_init(int reactor_type, int Ncells) -{ - amrex::ParmParse pp("ode"); - pp.query("atol", absTol); - pp.query("rtol", relTol); - pp.query("rk64_nsubsteps_guess", rk64_nsubsteps_guess); - pp.query("rk64_nsubsteps_min", rk64_nsubsteps_min); - pp.query("rk64_nsubsteps_max", rk64_nsubsteps_max); - return (0); -} - -int -react( - amrex::Real* rY_in, - amrex::Real* rY_src_in, - amrex::Real* rX_in, - amrex::Real* rX_src_in, - amrex::Real& dt_react, - amrex::Real& time, - int reactor_type, - int Ncells -#ifdef AMREX_USE_GPU - , - amrex::gpuStream_t stream -#endif -) -{ - - amrex::Real time_init = time; - amrex::Real time_out = time + dt_react; - const amrex::Real tinyval = 1e-50; - - // capture reactor type - int captured_reactor_type = reactor_type; - int captured_nsubsteps_guess = rk64_nsubsteps_guess; - int captured_nsubsteps_min = rk64_nsubsteps_min; - int captured_nsubsteps_max = rk64_nsubsteps_max; - amrex::Real captured_abstol = absTol; - - int* nstepsvec; - nstepsvec = new int[Ncells](); - - amrex::ParallelFor(Ncells, [=] AMREX_GPU_DEVICE(int icell) noexcept { - amrex::Real soln_reg[NUM_SPECIES + 1]; - amrex::Real carryover_reg[NUM_SPECIES + 1]; - amrex::Real error_reg[NUM_SPECIES + 1]; - amrex::Real rhs[NUM_SPECIES + 1]; - amrex::Real rYsrc[NUM_SPECIES]; - amrex::Real dt_rk, dt_rk_min, dt_rk_max, change_factor; - amrex::Real current_time = time_init; - int neq = (NUM_SPECIES + 1); - -#include "rkparams.H" - - for (int sp = 0; sp < neq; sp++) { - soln_reg[sp] = rY_in[icell * neq + sp]; - carryover_reg[sp] = soln_reg[sp]; - error_reg[sp] = 0.0; - rhs[sp] = 0.0; - } - - dt_rk = dt_react / amrex::Real(captured_nsubsteps_guess); - dt_rk_min = dt_react / amrex::Real(captured_nsubsteps_max); - dt_rk_max = dt_react / amrex::Real(captured_nsubsteps_min); - - current_time = time_init; - amrex::Real rhoe_init[] = {rX_in[icell]}; - amrex::Real rhoesrc_ext[] = {rX_src_in[icell]}; - - for (int sp = 0; sp < NUM_SPECIES; sp++) { - rYsrc[sp] = rY_src_in[icell * NUM_SPECIES + sp]; - } - - int nsteps = 0; - while (current_time < time_out) { - for (int sp = 0; sp < neq; sp++) { - error_reg[sp] = 0.0; - } - for (int stage = 0; stage < nstages_rk64; stage++) { - fKernelSpec( - 0, 1, current_time - time_init, captured_reactor_type, soln_reg, rhs, - rhoe_init, rhoesrc_ext, rYsrc); - - for (int i = 0; i < neq; i++) { - error_reg[i] += err_rk64[stage] * dt_rk * rhs[i]; - soln_reg[i] = carryover_reg[i] + alpha_rk64[stage] * dt_rk * rhs[i]; - carryover_reg[i] = soln_reg[i] + beta_rk64[stage] * dt_rk * rhs[i]; - } - } - - current_time += dt_rk; - nsteps++; - - amrex::Real max_err = tinyval; - for (int i = 0; i < neq; i++) { - if (fabs(error_reg[i]) > max_err) { - max_err = fabs(error_reg[i]); - } - } - - if (max_err < captured_abstol) { - change_factor = - betaerr_rk64 * pow((captured_abstol / max_err), exp1_rk64); - dt_rk = amrex::min(dt_rk_max, dt_rk * change_factor); - } else { - change_factor = - betaerr_rk64 * pow((captured_abstol / max_err), exp2_rk64); - dt_rk = amrex::max(dt_rk_min, dt_rk * change_factor); - } - } - nstepsvec[icell] = nsteps; - // copy data back - for (int sp = 0; sp < neq; sp++) { - rY_in[icell * neq + sp] = soln_reg[sp]; - } - rX_in[icell] = rhoe_init[0] + dt_react * rhoesrc_ext[0]; - }); - -#ifdef MOD_REACTOR - time = time_out; -#endif - - amrex::Real avgsteps = 0.0; - for (int i = 0; i < Ncells; i++) { - avgsteps += nstepsvec[i]; - } - - return (int(avgsteps / amrex::Real(Ncells))); -} - -int -react( - const amrex::Box& box, - amrex::Array4 const& rY_in, - amrex::Array4 const& rY_src_in, - amrex::Array4 const& T_in, - amrex::Array4 const& rEner_in, - amrex::Array4 const& rEner_src_in, - amrex::Array4 const& FC_in, - amrex::Array4 const& mask, - amrex::Real& dt_react, - amrex::Real& time, - const int& reactor_type -#ifdef AMREX_USE_GPU - , - amrex::gpuStream_t stream -#endif -) -{ - - amrex::Real time_init = time; - amrex::Real time_out = time + dt_react; - const amrex::Real tinyval = 1e-50; - - // capture reactor type - int captured_reactor_type = reactor_type; - int captured_nsubsteps_guess = rk64_nsubsteps_guess; - int captured_nsubsteps_min = rk64_nsubsteps_min; - int captured_nsubsteps_max = rk64_nsubsteps_max; - amrex::Real captured_abstol = absTol; - - int* nstepsvec; - int Ncells = box.numPts(); - const auto len = amrex::length(box); - const auto lo = amrex::lbound(box); - nstepsvec = new int[Ncells](); - - amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real soln_reg[NUM_SPECIES + 1]; - amrex::Real carryover_reg[NUM_SPECIES + 1]; - amrex::Real error_reg[NUM_SPECIES + 1]; - amrex::Real rhs[NUM_SPECIES + 1]; - - amrex::Real rYsrc[NUM_SPECIES]; - amrex::Real mass_frac[NUM_SPECIES]; - int neq = (NUM_SPECIES + 1); - -#include "rkparams.H" - - amrex::Real dt_rk, dt_rk_min, dt_rk_max, change_factor; - amrex::Real rho; - - for (int sp = 0; sp < NUM_SPECIES; sp++) { - soln_reg[sp] = rY_in(i, j, k, sp); - carryover_reg[sp] = soln_reg[sp]; - rho += rY_in(i, j, k, sp); - error_reg[sp] = 0.0; - rhs[sp] = 0.0; - } - amrex::Real rho_inv = 1.0 / rho; - for (int sp = 0; sp < NUM_SPECIES; sp++) { - mass_frac[sp] = rY_in(i, j, k, sp) * rho_inv; - } - rhs[NUM_SPECIES] = 0.0; - error_reg[NUM_SPECIES] = 0.0; - amrex::Real temp = T_in(i, j, k, 0); - - amrex::Real Enrg_loc = rEner_in(i, j, k, 0) * rho_inv; - auto eos = pele::physics::PhysicsType::eos(); - if (captured_reactor_type == 1) { - eos.REY2T(rho, Enrg_loc, mass_frac, temp); - } else { - eos.RHY2T(rho, Enrg_loc, mass_frac, temp); - } - soln_reg[NUM_SPECIES] = temp; - carryover_reg[NUM_SPECIES] = soln_reg[NUM_SPECIES]; - - dt_rk = dt_react / amrex::Real(captured_nsubsteps_guess); - dt_rk_min = dt_react / amrex::Real(captured_nsubsteps_max); - dt_rk_max = dt_react / amrex::Real(captured_nsubsteps_min); - - amrex::Real current_time = time_init; - amrex::Real rhoe_init[] = {rEner_in(i, j, k, 0)}; - amrex::Real rhoesrc_ext[] = {rEner_src_in(i, j, k, 0)}; - - for (int sp = 0; sp < NUM_SPECIES; sp++) { - rYsrc[sp] = rY_src_in(i, j, k, sp); - } - - int nsteps = 0; - while (current_time < time_out) { - for (int sp = 0; sp < neq; sp++) { - error_reg[sp] = 0.0; - } - for (int stage = 0; stage < nstages_rk64; stage++) { - fKernelSpec( - 0, 1,current_time - time_init, captured_reactor_type, soln_reg, rhs, - rhoe_init, rhoesrc_ext, rYsrc); - - for (int i = 0; i < neq; i++) { - error_reg[i] += err_rk64[stage] * dt_rk * rhs[i]; - soln_reg[i] = carryover_reg[i] + alpha_rk64[stage] * dt_rk * rhs[i]; - carryover_reg[i] = soln_reg[i] + beta_rk64[stage] * dt_rk * rhs[i]; - } - } - - current_time += dt_rk; - nsteps++; - - amrex::Real max_err = tinyval; - for (int i = 0; i < neq; i++) { - if (fabs(error_reg[i]) > max_err) { - max_err = fabs(error_reg[i]); - } - } - - if (max_err < captured_abstol) { - change_factor = - betaerr_rk64 * pow((captured_abstol / max_err), exp1_rk64); - dt_rk = amrex::min(dt_rk_max, dt_rk * change_factor); - } else { - change_factor = - betaerr_rk64 * pow((captured_abstol / max_err), exp2_rk64); - dt_rk = amrex::max(dt_rk_min, dt_rk * change_factor); - } - } - - // copy data back - int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x); - nstepsvec[icell] = nsteps; - for (int sp = 0; sp < NUM_SPECIES; sp++) { - rY_in(i, j, k, sp) = soln_reg[sp]; - rho += rY_in(i, j, k, sp); - } - rho_inv = 1.0 / rho; - for (int sp = 0; sp < NUM_SPECIES; sp++) { - mass_frac[sp] = rY_in(i, j, k, sp) * rho_inv; - } - temp = soln_reg[NUM_SPECIES]; - rEner_in(i, j, k, 0) = rhoe_init[0] + dt_react * rhoesrc_ext[0]; - Enrg_loc = rEner_in(i, j, k, 0) * rho_inv; - - if (captured_reactor_type == 1) { - eos.REY2T(rho, Enrg_loc, mass_frac, temp); - } else { - eos.RHY2T(rho, Enrg_loc, mass_frac, temp); - } - T_in(i, j, k, 0) = temp; - FC_in(i, j, k, 0) = nsteps; - }); - -#ifdef MOD_REACTOR - time = time_out; -#endif - - amrex::Real avgsteps = 0.0; - for (int i = 0; i < Ncells; i++) { - avgsteps += nstepsvec[i]; - } - avgsteps = int(avgsteps / amrex::Real(Ncells)); - - return (int(avgsteps / amrex::Real(Ncells))); -} diff --git a/Reactions/rk64/reactor_utils.H b/Reactions/rk64/reactor_utils.H deleted file mode 100644 index 8be4467da..000000000 --- a/Reactions/rk64/reactor_utils.H +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _REACTOR_UTILS_H_ -#define _REACTOR_UTILS_H_ - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE int -sunvec_index(const int specie_idx, const int icell, const int /*ncells*/) -{ - return icell * (NUM_SPECIES + 1) + specie_idx; -} - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE int -sunspec_index(const int specie_idx, const int icell, const int /*ncells*/) -{ - return icell * NUM_SPECIES + specie_idx; -} -#endif diff --git a/Reactions/rk64/rkparams.H b/Reactions/rk64/rkparams.H deleted file mode 100644 index ed4006eef..000000000 --- a/Reactions/rk64/rkparams.H +++ /dev/null @@ -1,33 +0,0 @@ -//=================================================================== -//stages and coefficients for rk64 -//=================================================================== -const int nstages_rk64 = 6; -const amrex::Real alpha_rk64[6] = { - 0.218150805229859, // 3296351145737.0/15110423921029.0, - 0.256702469801519, // 1879360555526.0/ 7321162733569.0, - 0.527402592007520, // 10797097731880.0/20472212111779.0, - 0.0484864267224467, // 754636544611.0/15563872110659.0, - 1.24517071533530, // 3260218886217.0/ 2618290685819.0, - 0.412366034843237, // 5069185909380.0/12292927838509.0 -}; - -const amrex::Real beta_rk64[6] = { - -0.113554138044166, //-1204558336989.0/10607789004752.0, - -0.215118587818400, //-3028468927040.0/14078136890693.0, - -0.0510152146250577, //-455570672869.0/ 8930094212428.0, - -1.07992686223881, //-17275898420483.0/15997285579755.0, - -0.248664241213447, //-2453906524165.0/ 9868353053862.0, - 0.0}; - -const amrex::Real err_rk64[6] = { - -0.0554699315064507, //-530312978447.0/ 9560368366154.0, - 0.158481845574980, // 473021958881.0/ 2984707536468.0, - -0.0905918835751907, //-947229622805.0/10456009803779.0, - -0.219084567203338, //-2921473878215.0/13334914072261.0, - 0.164022338959433, // 1519535112975.0/ 9264196100452.0, - 0.0426421977505659 // 167623581683.0/ 3930932046784.0 -}; -const amrex::Real exp1_rk64 = 0.25; -const amrex::Real exp2_rk64 = 0.2; -const amrex::Real betaerr_rk64 = 1.0; -//=================================================================== diff --git a/Source/Factory.H b/Source/Factory.H new file mode 100644 index 000000000..b755ec884 --- /dev/null +++ b/Source/Factory.H @@ -0,0 +1,164 @@ +#ifndef FACTORY_H +#define FACTORY_H + +#include +#include +#include + +#include "AMReX_Print.H" +#include "AMReX.H" + +namespace pele { +namespace physics { + +/** Runtime selection of options based on string keyword lookup + * + * This is lifted straight from AMR-wind, + * + * Factory provides an automated way to register subclasses that can be + * instantiated during runtime using string based lookups. The facility mimics + * the runTimeSelectionTable in OpenFOAM and the current structure is adapted + * from http://www.nirfriedman.com/2018/04/29/unforgettable-factory/ + * + * The usage is described using the following example from code. We would like + * to support creation of a turbulence model based on user inputs that are read + * from a file. We will create a base class TurbulenceModel that defines the + * API for the turbulence model and how it interacts with the rest of the code. + * Then new models, e.g., Smagorinsky, k-Omega SST/SAS, etc., are added as + * subclasses to this instance. + * + * ``` + * // Create a base class that can be used to register and create instances + * // + * // The template arguments are the classname for CRTP and types of additional + * // arguments to be passed to the constructor of the object + * class TurbulenceModel : public Factory + * { + * // Define a base identifier string for debugging purposes + * static const std::string base_identifier() { return "TurbulenceModel"; + * } + * + * // Define API as appropriate here + * }; + * + * // Define a subclass + * // Instead of using the base class we use Base::Register to allow + * registration class Smagorinsky : public + * TurbulenceModel::Register + * { + * // This is the keyword that is used to lookup and create this instance + * static const std::string identifier() { return "Smagorinsky"; } + * + * // Model implementation here + * }; + * + * // To create a turbulence model instance + * auto sim = CFDSim(mesh); + * // tmodel is a std::unique_ptr instance + * auto tmodel = TurbulenceModel::create("Smagorinsky", sim); + * ``` + * + * \tparam Base base class (e.g., Physics) + * \tparam Args Arguments types to be passed to the constructor during + * instantiation + */ +template +struct Factory +{ + /** Create an instance of the concrete subclass based on the runtime keyword + * + * \param key Unique identifier used to lookup subclass instance + * \param args Arguments to the constructor of the subclass + */ + static std::unique_ptr create(const std::string& key, Args... args) + { + key_exists_or_error(key); + auto ptr = table().at(key)(std::forward(args)...); + amrex::Print() << "Creating " << Base::base_identifier() + << " instance: " << key << std::endl; + return ptr; + } + + /** Print a list of the valid subclasses registered to this base instance + * + * \param os Valid output stream + */ + static void print(std::ostream& os) + { + const auto& tbl = table(); + os << Base::base_identifier() << " " << tbl.size() << std::endl; + for (const auto& it : tbl) { + os << " - " << it.first << std::endl; + } + } + + //! Class to handle registration of subclass for runtime selection + template + struct Register : public Base + { + friend T; + static bool registered; + + static bool add_sub_type() + { + // TODO: Add checks against multiple registration + Factory::table()[T::identifier()] = + [](Args... args) -> std::unique_ptr { + return std::unique_ptr(new T(std::forward(args)...)); + }; + return true; + } + + virtual ~Register() + { + if (registered) { + auto& tbl = Factory::table(); + const auto& it = tbl.find(T::identifier()); + registered = (it != tbl.end()); + } + } + + private: + Register() { (void)registered; } + }; + + virtual ~Factory() = default; + friend Base; + +private: + using CreatorFunc = std::unique_ptr (*)(Args...); + using LookupTable = std::unordered_map; + + //! Check if the keyword exists in table or print diagnostic message and + //! abort + static void key_exists_or_error(const std::string& key) + { + const auto& tbl = table(); + if (tbl.find(key) == tbl.end()) { + // Print valid options + if (amrex::ParallelDescriptor::IOProcessor()) + print(std::cout); + // Quit with error + amrex::Abort( + "In " + Base::base_identifier() + " cannot find instance: " + key); + } + } + + //! Lookup table containing all registered instances + static LookupTable& table() + { + static LookupTable tbl; + return tbl; + } + + Factory() = default; +}; + +template +template +bool Factory::Register::registered = + Factory::Register::add_sub_type(); + +} // namespace physics +} // namespace pele +#endif /* FACTORY_H */ diff --git a/Support/Fuego/Mechanism/Models/BurkeDryer/mechanism.H b/Support/Fuego/Mechanism/Models/BurkeDryer/mechanism.H index 1782732b1..019a80c5c 100644 --- a/Support/Fuego/Mechanism/Models/BurkeDryer/mechanism.H +++ b/Support/Fuego/Mechanism/Models/BurkeDryer/mechanism.H @@ -45,14 +45,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -3800,7 +3800,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<196; i++) { @@ -5179,11 +5178,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[195] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[13]; @@ -5202,12 +5199,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<196; i++) { @@ -6840,12 +6835,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[13]; @@ -6864,7 +6857,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/BurkeDryer/mechanism.cpp b/Support/Fuego/Mechanism/Models/BurkeDryer/mechanism.cpp index ed86ec6b6..b03a7c31e 100644 --- a/Support/Fuego/Mechanism/Models/BurkeDryer/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/BurkeDryer/mechanism.cpp @@ -14,8 +14,6 @@ void atomicWeight(amrex::Real * awt) awt[3] = 39.948000; /*AR */ awt[4] = 4.002600; /*HE */ awt[5] = 12.011150; /*C */ - - return; } @@ -120,8 +118,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(196); amrex::Gpu::DeviceVector c_v(13); @@ -155,16 +152,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(196); amrex::Gpu::DeviceVector c_v(13); @@ -202,16 +195,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(196); amrex::Gpu::DeviceVector c_v(13); @@ -249,15 +238,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -299,14 +284,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(196); @@ -362,15 +343,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(196); @@ -435,15 +412,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(196); amrex::Gpu::DeviceVector c_v(13); @@ -485,15 +458,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(196); amrex::Gpu::DeviceVector c_v(13); @@ -552,9 +521,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/Davis/mechanism.H b/Support/Fuego/Mechanism/Models/Davis/mechanism.H index 7cbdb314d..3b22a7d3a 100644 --- a/Support/Fuego/Mechanism/Models/Davis/mechanism.H +++ b/Support/Fuego/Mechanism/Models/Davis/mechanism.H @@ -46,14 +46,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -4200,7 +4200,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<225; i++) { @@ -6175,11 +6174,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[224] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[14]; @@ -6198,12 +6195,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<225; i++) { @@ -8493,12 +8488,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[14]; @@ -8517,7 +8510,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/Davis/mechanism.cpp b/Support/Fuego/Mechanism/Models/Davis/mechanism.cpp index 0fc76f1e3..299fd12bc 100644 --- a/Support/Fuego/Mechanism/Models/Davis/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/Davis/mechanism.cpp @@ -14,8 +14,6 @@ void atomicWeight(amrex::Real * awt) awt[3] = 14.006700; /*N */ awt[4] = 39.948000; /*AR */ awt[5] = 4.002600; /*HE */ - - return; } @@ -126,8 +124,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(225); amrex::Gpu::DeviceVector c_v(14); @@ -161,16 +158,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(225); amrex::Gpu::DeviceVector c_v(14); @@ -208,16 +201,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(225); amrex::Gpu::DeviceVector c_v(14); @@ -255,15 +244,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -305,14 +290,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(225); @@ -368,15 +349,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(225); @@ -441,15 +418,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(225); amrex::Gpu::DeviceVector c_v(14); @@ -491,15 +464,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(225); amrex::Gpu::DeviceVector c_v(14); @@ -558,9 +527,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/FFCM1_Red/mechanism.H b/Support/Fuego/Mechanism/Models/FFCM1_Red/mechanism.H index bbc00f396..2f5367465 100644 --- a/Support/Fuego/Mechanism/Models/FFCM1_Red/mechanism.H +++ b/Support/Fuego/Mechanism/Models/FFCM1_Red/mechanism.H @@ -52,14 +52,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -7411,7 +7411,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<484; i++) { @@ -14029,11 +14028,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[483] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[21]; @@ -14052,12 +14049,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<484; i++) { @@ -21608,12 +21603,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[21]; @@ -21632,7 +21625,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/FFCM1_Red/mechanism.cpp b/Support/Fuego/Mechanism/Models/FFCM1_Red/mechanism.cpp index 653c3343f..e5a77ea95 100644 --- a/Support/Fuego/Mechanism/Models/FFCM1_Red/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/FFCM1_Red/mechanism.cpp @@ -13,8 +13,6 @@ void atomicWeight(amrex::Real * awt) awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ awt[4] = 4.002600; /*HE */ - - return; } @@ -164,8 +162,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -199,16 +196,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -246,16 +239,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -293,15 +282,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -343,14 +328,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(484); @@ -406,15 +387,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(484); @@ -479,15 +456,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -529,15 +502,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -596,9 +565,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/JL4/mechanism.H b/Support/Fuego/Mechanism/Models/JL4/mechanism.H index 0754afddc..0219c11c0 100644 --- a/Support/Fuego/Mechanism/Models/JL4/mechanism.H +++ b/Support/Fuego/Mechanism/Models/JL4/mechanism.H @@ -37,14 +37,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -2321,7 +2321,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<64; i++) { @@ -2567,11 +2566,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[63] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[7]; @@ -2590,12 +2587,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<64; i++) { @@ -2844,12 +2839,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[7]; @@ -2868,7 +2861,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/JL4/mechanism.cpp b/Support/Fuego/Mechanism/Models/JL4/mechanism.cpp index 615e52fe6..a6bb5a9cd 100644 --- a/Support/Fuego/Mechanism/Models/JL4/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/JL4/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 15.999400; /*O */ awt[2] = 1.007970; /*H */ awt[3] = 14.006700; /*N */ - - return; } @@ -90,8 +88,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(64); amrex::Gpu::DeviceVector c_v(7); @@ -125,16 +122,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(64); amrex::Gpu::DeviceVector c_v(7); @@ -172,16 +165,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(64); amrex::Gpu::DeviceVector c_v(7); @@ -219,15 +208,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -269,14 +254,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(64); @@ -332,15 +313,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(64); @@ -405,15 +382,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(64); amrex::Gpu::DeviceVector c_v(7); @@ -455,15 +428,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(64); amrex::Gpu::DeviceVector c_v(7); @@ -522,9 +491,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/Kolla/mechanism.H b/Support/Fuego/Mechanism/Models/Kolla/mechanism.H index 34c1f25b6..d1a468f83 100644 --- a/Support/Fuego/Mechanism/Models/Kolla/mechanism.H +++ b/Support/Fuego/Mechanism/Models/Kolla/mechanism.H @@ -42,14 +42,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -3694,7 +3694,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<169; i++) { @@ -5251,11 +5250,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[168] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[12]; @@ -5274,12 +5271,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<169; i++) { @@ -7094,12 +7089,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[12]; @@ -7118,7 +7111,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/Kolla/mechanism.cpp b/Support/Fuego/Mechanism/Models/Kolla/mechanism.cpp index fb5dc879f..e19a04b7e 100644 --- a/Support/Fuego/Mechanism/Models/Kolla/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/Kolla/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 15.999400; /*O */ awt[3] = 14.006700; /*N */ - - return; } @@ -114,8 +112,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(169); amrex::Gpu::DeviceVector c_v(12); @@ -149,16 +146,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(169); amrex::Gpu::DeviceVector c_v(12); @@ -196,16 +189,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(169); amrex::Gpu::DeviceVector c_v(12); @@ -243,15 +232,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -293,14 +278,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(169); @@ -356,15 +337,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(169); @@ -429,15 +406,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(169); amrex::Gpu::DeviceVector c_v(12); @@ -479,15 +452,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(169); amrex::Gpu::DeviceVector c_v(12); @@ -546,9 +515,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/LiDryer/mechanism.H b/Support/Fuego/Mechanism/Models/LiDryer/mechanism.H index 438dac574..ae234c517 100644 --- a/Support/Fuego/Mechanism/Models/LiDryer/mechanism.H +++ b/Support/Fuego/Mechanism/Models/LiDryer/mechanism.H @@ -38,14 +38,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -3056,7 +3056,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<100; i++) { @@ -4180,11 +4179,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[99] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[9]; @@ -4203,12 +4200,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<100; i++) { @@ -5473,12 +5468,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[9]; @@ -5497,7 +5490,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/LiDryer/mechanism.cpp b/Support/Fuego/Mechanism/Models/LiDryer/mechanism.cpp index 12557dfde..9613b021f 100644 --- a/Support/Fuego/Mechanism/Models/LiDryer/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/LiDryer/mechanism.cpp @@ -11,8 +11,6 @@ void atomicWeight(amrex::Real * awt) awt[0] = 1.007970; /*H */ awt[1] = 15.999400; /*O */ awt[2] = 14.006700; /*N */ - - return; } @@ -96,8 +94,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -131,16 +128,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -178,16 +171,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -225,15 +214,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -275,14 +260,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(100); @@ -338,15 +319,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(100); @@ -411,15 +388,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -461,15 +434,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -528,9 +497,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/LuDME/mechanism.H b/Support/Fuego/Mechanism/Models/LuDME/mechanism.H index 23d0d458d..40a2705e5 100644 --- a/Support/Fuego/Mechanism/Models/LuDME/mechanism.H +++ b/Support/Fuego/Mechanism/Models/LuDME/mechanism.H @@ -69,14 +69,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -11797,7 +11797,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<1600; i++) { @@ -21307,11 +21306,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[1599] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[39]; @@ -21330,12 +21327,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<1600; i++) { @@ -31620,12 +31615,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[39]; @@ -31644,7 +31637,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/LuDME/mechanism.cpp b/Support/Fuego/Mechanism/Models/LuDME/mechanism.cpp index a4cdb2369..1bb36bbb6 100644 --- a/Support/Fuego/Mechanism/Models/LuDME/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/LuDME/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 15.999400; /*O */ awt[3] = 14.006700; /*N */ - - return; } @@ -267,8 +265,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1600); amrex::Gpu::DeviceVector c_v(39); @@ -302,16 +299,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1600); amrex::Gpu::DeviceVector c_v(39); @@ -349,16 +342,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(1600); amrex::Gpu::DeviceVector c_v(39); @@ -396,15 +385,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -446,14 +431,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1600); @@ -509,15 +490,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1600); @@ -582,15 +559,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(1600); amrex::Gpu::DeviceVector c_v(39); @@ -632,15 +605,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(1600); amrex::Gpu::DeviceVector c_v(39); @@ -699,9 +668,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/LuEthylene/mechanism.H b/Support/Fuego/Mechanism/Models/LuEthylene/mechanism.H index 4a7fb2e0a..276d230f8 100644 --- a/Support/Fuego/Mechanism/Models/LuEthylene/mechanism.H +++ b/Support/Fuego/Mechanism/Models/LuEthylene/mechanism.H @@ -63,14 +63,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -11109,7 +11109,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<1089; i++) { @@ -22643,11 +22642,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[1088] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[32]; @@ -22666,12 +22663,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<1089; i++) { @@ -35689,12 +35684,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[32]; @@ -35713,7 +35706,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/LuEthylene/mechanism.cpp b/Support/Fuego/Mechanism/Models/LuEthylene/mechanism.cpp index 180317d85..5ee8ed68a 100644 --- a/Support/Fuego/Mechanism/Models/LuEthylene/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/LuEthylene/mechanism.cpp @@ -13,8 +13,6 @@ void atomicWeight(amrex::Real * awt) awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ awt[4] = 39.948000; /*AR */ - - return; } @@ -222,8 +220,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -257,16 +254,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -304,16 +297,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -351,15 +340,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -401,14 +386,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1089); @@ -464,15 +445,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1089); @@ -537,15 +514,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -587,15 +560,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -654,9 +623,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/Make.package b/Support/Fuego/Mechanism/Models/Make.package index 76ca595fa..95fce2885 100644 --- a/Support/Fuego/Mechanism/Models/Make.package +++ b/Support/Fuego/Mechanism/Models/Make.package @@ -1,4 +1 @@ -ifeq ($(USE_F90_PP),TRUE) - F90EXE_sources += mod_fuego.F90 -endif CEXE_headers += PPHYS_CONSTANTS.H diff --git a/Support/Fuego/Mechanism/Models/NUIGalway/mechanism.H b/Support/Fuego/Mechanism/Models/NUIGalway/mechanism.H index fd9539582..67a055104 100644 --- a/Support/Fuego/Mechanism/Models/NUIGalway/mechanism.H +++ b/Support/Fuego/Mechanism/Models/NUIGalway/mechanism.H @@ -150,14 +150,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -38615,7 +38615,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<14161; i++) { @@ -76132,11 +76131,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[14160] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[118]; @@ -76155,12 +76152,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<14161; i++) { @@ -115217,12 +115212,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[118]; @@ -115241,7 +115234,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/NUIGalway/mechanism.cpp b/Support/Fuego/Mechanism/Models/NUIGalway/mechanism.cpp index eb0bb19c7..bf0b05436 100644 --- a/Support/Fuego/Mechanism/Models/NUIGalway/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/NUIGalway/mechanism.cpp @@ -14,8 +14,6 @@ void atomicWeight(amrex::Real * awt) awt[3] = 15.999400; /*O */ awt[4] = 39.948000; /*AR */ awt[5] = 4.002600; /*HE */ - - return; } @@ -726,8 +724,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(14161); amrex::Gpu::DeviceVector c_v(118); @@ -761,16 +758,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(14161); amrex::Gpu::DeviceVector c_v(118); @@ -808,16 +801,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(14161); amrex::Gpu::DeviceVector c_v(118); @@ -855,15 +844,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -905,14 +890,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(14161); @@ -968,15 +949,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(14161); @@ -1041,15 +1018,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(14161); amrex::Gpu::DeviceVector c_v(118); @@ -1091,15 +1064,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(14161); amrex::Gpu::DeviceVector c_v(118); @@ -1158,9 +1127,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/Null/mechanism.H b/Support/Fuego/Mechanism/Models/Null/mechanism.H index d3f1fcf3f..94f1def51 100644 --- a/Support/Fuego/Mechanism/Models/Null/mechanism.H +++ b/Support/Fuego/Mechanism/Models/Null/mechanism.H @@ -24,6 +24,15 @@ void CKAWT(amrex::Real * awt); void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); +/* SPARSE INFORMATION */ +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); /* inverse molecular weights */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE @@ -95,11 +104,17 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void CKYTCR(amrex::Real * /*rho*/, amr } /*compute the reaction Jacobian */ -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * /*J*/, amrex::Real * /*sc*/, amrex::Real * /*Tp*/, int * /*consP*/) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * /*J*/, amrex::Real * /*sc*/, amrex::Real * /*Tp*/, const int * /*consP*/) { amrex::Abort("DWDOT not implemented for Null chemistry."); } +/*compute an approx to the reaction Jacobian (for preconditioning) */ +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * /*J*/, amrex::Real * /*sc*/, amrex::Real * /*Tp*/, const int * /*consP*/) +{ + amrex::Abort("DWDOT_SIMPLIFIED not implemented for Null chemistry."); +} + /*Returns internal energy in mass units (Eq 30.) */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void CKUMS(amrex::Real * /*T*/, amrex::Real * /*ums*/) { @@ -209,6 +224,24 @@ void egtransetCOFD(amrex::Real* /*COFD*/) { amrex::Abort("egtransetCOFD not implemented for Null chemistry."); } +/* gauss-jordan solver external routine */ +/* Replace this routine with the one generated by the Gauss Jordan solver of DW */ +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void sgjsolve(amrex::Real* /*A*/, amrex::Real* /*x*/, amrex::Real* /*b*/) { + amrex::Abort("sgjsolve not implemented, choose a different solver "); +} + +/* Replace this routine with the one generated by the Gauss Jordan solver of DW */ +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void sgjsolve_simplified(amrex::Real* /*A*/, amrex::Real* /*x*/, amrex::Real* /*b*/) { + amrex::Abort("sgjsolve_simplified not implemented, choose a different solver "); +} + +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void CKINDX(int * mm, int * kk, int * ii, int * nfit) +{ + *mm = 1; + *kk = 1; + *ii = 0; + *nfit = -1; /*Why do you need this anyway ? */ +} #endif diff --git a/Support/Fuego/Mechanism/Models/Null/mechanism.cpp b/Support/Fuego/Mechanism/Models/Null/mechanism.cpp index 33b6fd77c..2abffbb41 100644 --- a/Support/Fuego/Mechanism/Models/Null/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/Null/mechanism.cpp @@ -22,4 +22,76 @@ CKSYMS_STR(amrex::Vector& /*kname*/) { } +// compute sparsity pattern of the chemistry Jacobian +void +SPARSITY_INFO(int* /*nJdata*/, const int* /*consP*/, int /*NCELLS*/) +{ +} + +// compute sparsity pattern of the system Jacobian +void +SPARSITY_INFO_SYST(int* /*nJdata*/, const int* /*consP*/, int /*NCELLS*/) +{ +} + +// compute sparsity pattern of the simplified (for preconditioning) system +// Jacobian +void +SPARSITY_INFO_SYST_SIMPLIFIED(int* /*nJdata*/, const int* /*consP*/) +{ +} + +// compute sparsity pattern of the chemistry Jacobian in CSC format -- base 0 +void +SPARSITY_PREPROC_CSC( + int* /*rowVals*/ + , + int* /*colPtrs*/, + const int* /*consP*/, + int /*NCELLS*/) +{ +} + +// compute sparsity pattern of the chemistry Jacobian in CSR format -- base 0 +void +SPARSITY_PREPROC_CSR( + int* /*colVals*/, + int* /*rowPtrs*/, + const int* /*consP*/, + int /*NCELLS*/, + int /*base*/) +{ +} + +// compute sparsity pattern of the system Jacobian +// CSR format BASE is user choice +void +SPARSITY_PREPROC_SYST_CSR( + int* /*colVals*/, + int* /*rowPtr*/, + const int* /*consP*/, + int /*NCELLS*/, + int /*base*/) +{ +} + +// compute sparsity pattern of the simplified (for precond) system Jacobian on +// CPU BASE 0 +void +SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC( + int* /*rowVals*/, int* /*colPtrs*/, int* /*indx*/, const int* /*consP*/) +{ +} + +// compute sparsity pattern of the simplified (for precond) system Jacobian +// CSR format BASE is under choice +void +SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR( + int* /*colVals*/ + , + int* /*rowPtr*/, + const int* /*consP*/, + int /*base*/) +{ +} #endif diff --git a/Support/Fuego/Mechanism/Models/air/mechanism.H b/Support/Fuego/Mechanism/Models/air/mechanism.H index bb0c17142..234faf4fa 100644 --- a/Support/Fuego/Mechanism/Models/air/mechanism.H +++ b/Support/Fuego/Mechanism/Models/air/mechanism.H @@ -30,14 +30,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -1446,7 +1446,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<9; i++) { @@ -1528,11 +1527,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[8] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[2]; @@ -1551,12 +1548,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<9; i++) { @@ -1641,12 +1636,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[2]; @@ -1665,7 +1658,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/air/mechanism.cpp b/Support/Fuego/Mechanism/Models/air/mechanism.cpp index 94ea65e7c..e04026dd9 100644 --- a/Support/Fuego/Mechanism/Models/air/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/air/mechanism.cpp @@ -10,8 +10,6 @@ void atomicWeight(amrex::Real * awt) { awt[0] = 15.999400; /*O */ awt[1] = 14.006700; /*N */ - - return; } @@ -62,8 +60,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -97,16 +94,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -144,16 +137,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -191,15 +180,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -241,14 +226,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(9); @@ -304,15 +285,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(9); @@ -377,15 +354,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -427,15 +400,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -494,9 +463,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/alzeta/mechanism.H b/Support/Fuego/Mechanism/Models/alzeta/mechanism.H index df40712f0..f005e4a06 100644 --- a/Support/Fuego/Mechanism/Models/alzeta/mechanism.H +++ b/Support/Fuego/Mechanism/Models/alzeta/mechanism.H @@ -104,14 +104,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -17519,8 +17519,8 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void productionRate(amrex::Real * wdot const amrex::Real qr = k_f * exp(-(g_RT[1] + 2.000000*g_RT[3] - g_RT[3] - g_RT[6])) * (refC) * (sc[3]*sc[6]); const amrex::Real qdot = qf - qr; wdot[1] -= qdot; - wdot[3] -= 2.000000 * qdot; wdot[3] += qdot; + wdot[3] -= 2.000000 * qdot; wdot[6] += qdot; } @@ -24547,7 +24547,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<5329; i++) { @@ -54038,11 +54037,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[5328] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[72]; @@ -54061,12 +54058,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<5329; i++) { @@ -86087,12 +86082,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[72]; @@ -86111,7 +86104,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/alzeta/mechanism.cpp b/Support/Fuego/Mechanism/Models/alzeta/mechanism.cpp index 30253504c..9233b65df 100644 --- a/Support/Fuego/Mechanism/Models/alzeta/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/alzeta/mechanism.cpp @@ -14,8 +14,6 @@ void atomicWeight(amrex::Real * awt) awt[3] = 14.006700; /*N */ awt[4] = 39.948000; /*AR */ awt[5] = 18.998400; /*F */ - - return; } @@ -444,8 +442,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(5329); amrex::Gpu::DeviceVector c_v(72); @@ -479,16 +476,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(5329); amrex::Gpu::DeviceVector c_v(72); @@ -526,16 +519,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(5329); amrex::Gpu::DeviceVector c_v(72); @@ -573,15 +562,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -623,14 +608,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(5329); @@ -686,15 +667,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(5329); @@ -759,15 +736,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(5329); amrex::Gpu::DeviceVector c_v(72); @@ -809,15 +782,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(5329); amrex::Gpu::DeviceVector c_v(72); @@ -876,9 +845,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/chem-CH4-2step/mechanism.H b/Support/Fuego/Mechanism/Models/chem-CH4-2step/mechanism.H index fe7b1e87b..971e450a7 100644 --- a/Support/Fuego/Mechanism/Models/chem-CH4-2step/mechanism.H +++ b/Support/Fuego/Mechanism/Models/chem-CH4-2step/mechanism.H @@ -36,14 +36,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -2147,7 +2147,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<49; i++) { @@ -2315,11 +2314,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[48] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[6]; @@ -2338,12 +2335,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<49; i++) { @@ -2514,12 +2509,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[6]; @@ -2538,7 +2531,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/chem-CH4-2step/mechanism.cpp b/Support/Fuego/Mechanism/Models/chem-CH4-2step/mechanism.cpp index 092d813bc..8b0ce741e 100644 --- a/Support/Fuego/Mechanism/Models/chem-CH4-2step/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/chem-CH4-2step/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ - - return; } @@ -86,8 +84,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(49); amrex::Gpu::DeviceVector c_v(6); @@ -121,16 +118,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(49); amrex::Gpu::DeviceVector c_v(6); @@ -168,16 +161,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(49); amrex::Gpu::DeviceVector c_v(6); @@ -215,15 +204,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -265,14 +250,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(49); @@ -328,15 +309,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(49); @@ -401,15 +378,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(49); amrex::Gpu::DeviceVector c_v(6); @@ -451,15 +424,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(49); amrex::Gpu::DeviceVector c_v(6); @@ -518,9 +487,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/chem-H/mechanism.H b/Support/Fuego/Mechanism/Models/chem-H/mechanism.H index 6a1a31d2d..fa4da4db3 100644 --- a/Support/Fuego/Mechanism/Models/chem-H/mechanism.H +++ b/Support/Fuego/Mechanism/Models/chem-H/mechanism.H @@ -38,14 +38,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -2645,8 +2645,8 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void productionRate(amrex::Real * wdot const amrex::Real qr = k_f * exp(-(g_RT[1] + 2.000000*g_RT[3] - g_RT[3] - g_RT[6])) * (refC) * (sc[3]*sc[6]); const amrex::Real qdot = qf - qr; wdot[1] -= qdot; - wdot[3] -= 2.000000 * qdot; wdot[3] += qdot; + wdot[3] -= 2.000000 * qdot; wdot[6] += qdot; } @@ -3156,7 +3156,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<100; i++) { @@ -4495,11 +4494,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[99] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[9]; @@ -4518,12 +4515,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<100; i++) { @@ -6000,12 +5995,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[9]; @@ -6024,7 +6017,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/chem-H/mechanism.cpp b/Support/Fuego/Mechanism/Models/chem-H/mechanism.cpp index fa0e9af9e..08fc053b3 100644 --- a/Support/Fuego/Mechanism/Models/chem-H/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/chem-H/mechanism.cpp @@ -11,8 +11,6 @@ void atomicWeight(amrex::Real * awt) awt[0] = 15.999400; /*O */ awt[1] = 1.007970; /*H */ awt[2] = 14.006700; /*N */ - - return; } @@ -96,8 +94,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -131,16 +128,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -178,16 +171,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -225,15 +214,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -275,14 +260,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(100); @@ -338,15 +319,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(100); @@ -411,15 +388,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -461,15 +434,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(100); amrex::Gpu::DeviceVector c_v(9); @@ -528,9 +497,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/decane_3sp/mechanism.H b/Support/Fuego/Mechanism/Models/decane_3sp/mechanism.H index f1337733d..c2280f38f 100644 --- a/Support/Fuego/Mechanism/Models/decane_3sp/mechanism.H +++ b/Support/Fuego/Mechanism/Models/decane_3sp/mechanism.H @@ -33,14 +33,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -1639,7 +1639,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<16; i++) { @@ -1721,11 +1720,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[15] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[3]; @@ -1744,12 +1741,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<16; i++) { @@ -1834,12 +1829,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[3]; @@ -1858,7 +1851,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/decane_3sp/mechanism.cpp b/Support/Fuego/Mechanism/Models/decane_3sp/mechanism.cpp index ec0b0dc51..127b583e8 100644 --- a/Support/Fuego/Mechanism/Models/decane_3sp/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/decane_3sp/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 15.999400; /*O */ awt[3] = 14.006700; /*N */ - - return; } @@ -71,8 +69,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -106,16 +103,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -153,16 +146,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -200,15 +189,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -250,14 +235,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(16); @@ -313,15 +294,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(16); @@ -386,15 +363,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -436,15 +409,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -503,9 +472,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/dodecane_lu/mechanism.H b/Support/Fuego/Mechanism/Models/dodecane_lu/mechanism.H index f58dc618e..0fffa8559 100644 --- a/Support/Fuego/Mechanism/Models/dodecane_lu/mechanism.H +++ b/Support/Fuego/Mechanism/Models/dodecane_lu/mechanism.H @@ -83,14 +83,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -15890,7 +15890,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<2916; i++) { @@ -30758,11 +30757,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[2915] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[53]; @@ -30781,12 +30778,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<2916; i++) { @@ -47010,12 +47005,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[53]; @@ -47034,7 +47027,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/dodecane_lu/mechanism.cpp b/Support/Fuego/Mechanism/Models/dodecane_lu/mechanism.cpp index 0356b00df..89e909f20 100644 --- a/Support/Fuego/Mechanism/Models/dodecane_lu/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/dodecane_lu/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ - - return; } @@ -327,8 +325,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -362,16 +359,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -409,16 +402,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -456,15 +445,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -506,14 +491,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(2916); @@ -569,15 +550,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(2916); @@ -642,15 +619,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -692,15 +665,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -759,9 +728,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/dodecane_wang/mechanism.H b/Support/Fuego/Mechanism/Models/dodecane_wang/mechanism.H index cd8b2b4e6..c5bec6a3c 100644 --- a/Support/Fuego/Mechanism/Models/dodecane_wang/mechanism.H +++ b/Support/Fuego/Mechanism/Models/dodecane_wang/mechanism.H @@ -86,14 +86,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -16821,7 +16821,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<3249; i++) { @@ -33277,11 +33276,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[3248] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[56]; @@ -33300,12 +33297,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<3249; i++) { @@ -51132,12 +51127,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[56]; @@ -51156,7 +51149,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/dodecane_wang/mechanism.cpp b/Support/Fuego/Mechanism/Models/dodecane_wang/mechanism.cpp index a488403a8..b713c2a57 100644 --- a/Support/Fuego/Mechanism/Models/dodecane_wang/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/dodecane_wang/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ - - return; } @@ -344,8 +342,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(3249); amrex::Gpu::DeviceVector c_v(56); @@ -379,16 +376,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(3249); amrex::Gpu::DeviceVector c_v(56); @@ -426,16 +419,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(3249); amrex::Gpu::DeviceVector c_v(56); @@ -473,15 +462,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -523,14 +508,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(3249); @@ -586,15 +567,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(3249); @@ -659,15 +636,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(3249); amrex::Gpu::DeviceVector c_v(56); @@ -709,15 +682,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(3249); amrex::Gpu::DeviceVector c_v(56); @@ -776,9 +745,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/drm19/mechanism.H b/Support/Fuego/Mechanism/Models/drm19/mechanism.H index 6d3080bfc..0ee4a095d 100644 --- a/Support/Fuego/Mechanism/Models/drm19/mechanism.H +++ b/Support/Fuego/Mechanism/Models/drm19/mechanism.H @@ -52,14 +52,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -5218,8 +5218,8 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void productionRate(amrex::Real * wdot const amrex::Real qr = k_f * exp(-(g_RT[1] + 2.000000*g_RT[3] - g_RT[3] - g_RT[6])) * (refC) * (sc[3]*sc[6]); const amrex::Real qdot = qf - qr; wdot[1] -= qdot; - wdot[3] += qdot; wdot[3] -= 2.000000 * qdot; + wdot[3] += qdot; wdot[6] += qdot; } @@ -6417,7 +6417,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<484; i++) { @@ -10910,11 +10909,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[483] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[21]; @@ -10933,12 +10930,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<484; i++) { @@ -16084,12 +16079,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[21]; @@ -16108,7 +16101,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/drm19/mechanism.cpp b/Support/Fuego/Mechanism/Models/drm19/mechanism.cpp index f39ec1814..4977465e0 100644 --- a/Support/Fuego/Mechanism/Models/drm19/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/drm19/mechanism.cpp @@ -13,8 +13,6 @@ void atomicWeight(amrex::Real * awt) awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ awt[4] = 39.948000; /*AR */ - - return; } @@ -162,8 +160,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -197,16 +194,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -244,16 +237,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -291,15 +280,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -341,14 +326,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(484); @@ -404,15 +385,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(484); @@ -477,15 +454,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -527,15 +500,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(484); amrex::Gpu::DeviceVector c_v(21); @@ -594,9 +563,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/ethylene_af/mechanism.H b/Support/Fuego/Mechanism/Models/ethylene_af/mechanism.H index 077dace71..5028b5103 100644 --- a/Support/Fuego/Mechanism/Models/ethylene_af/mechanism.H +++ b/Support/Fuego/Mechanism/Models/ethylene_af/mechanism.H @@ -59,14 +59,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -7170,8 +7170,8 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void productionRate(amrex::Real * wdot const amrex::Real qr = k_f * exp(-(2.000000*g_RT[1] + g_RT[2] - 2.000000*g_RT[2])) * (refC) * ((sc[2] * sc[2])); const amrex::Real qdot = qf - qr; wdot[1] -= 2.000000 * qdot; - wdot[2] += 2.000000 * qdot; wdot[2] -= qdot; + wdot[2] += 2.000000 * qdot; } { @@ -9744,7 +9744,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<900; i++) { @@ -18881,11 +18880,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[899] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[29]; @@ -18904,12 +18901,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<900; i++) { @@ -29689,12 +29684,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[29]; @@ -29713,7 +29706,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/ethylene_af/mechanism.cpp b/Support/Fuego/Mechanism/Models/ethylene_af/mechanism.cpp index 0e3e55b9f..f45d5032c 100644 --- a/Support/Fuego/Mechanism/Models/ethylene_af/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/ethylene_af/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 15.999400; /*O */ awt[3] = 12.011150; /*C */ - - return; } @@ -204,8 +202,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(900); amrex::Gpu::DeviceVector c_v(29); @@ -239,16 +236,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(900); amrex::Gpu::DeviceVector c_v(29); @@ -286,16 +279,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(900); amrex::Gpu::DeviceVector c_v(29); @@ -333,15 +322,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -383,14 +368,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(900); @@ -446,15 +427,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(900); @@ -519,15 +496,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(900); amrex::Gpu::DeviceVector c_v(29); @@ -569,15 +542,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(900); amrex::Gpu::DeviceVector c_v(29); @@ -636,9 +605,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/grimech12/mechanism.H b/Support/Fuego/Mechanism/Models/grimech12/mechanism.H index 39d073cff..f4cc27193 100644 --- a/Support/Fuego/Mechanism/Models/grimech12/mechanism.H +++ b/Support/Fuego/Mechanism/Models/grimech12/mechanism.H @@ -63,14 +63,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -8227,8 +8227,8 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void productionRate(amrex::Real * wdot const amrex::Real qr = k_f * exp(-(g_RT[1] + 2.000000*g_RT[3] - g_RT[3] - g_RT[6])) * (refC) * (sc[3]*sc[6]); const amrex::Real qdot = qf - qr; wdot[1] -= qdot; - wdot[3] += qdot; wdot[3] -= 2.000000 * qdot; + wdot[3] += qdot; wdot[6] += qdot; } @@ -10443,7 +10443,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<1089; i++) { @@ -20367,11 +20366,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[1088] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[32]; @@ -20390,12 +20387,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<1089; i++) { @@ -31601,12 +31596,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[32]; @@ -31625,7 +31618,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/grimech12/mechanism.cpp b/Support/Fuego/Mechanism/Models/grimech12/mechanism.cpp index ff9ce706c..c2c4ed038 100644 --- a/Support/Fuego/Mechanism/Models/grimech12/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/grimech12/mechanism.cpp @@ -13,8 +13,6 @@ void atomicWeight(amrex::Real * awt) awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ awt[4] = 39.948000; /*AR */ - - return; } @@ -221,8 +219,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -256,16 +253,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -303,16 +296,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -350,15 +339,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -400,14 +385,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1089); @@ -463,15 +444,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1089); @@ -536,15 +513,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -586,15 +559,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(1089); amrex::Gpu::DeviceVector c_v(32); @@ -653,9 +622,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/grimech30-noArN/mechanism.H b/Support/Fuego/Mechanism/Models/grimech30-noArN/mechanism.H index 0a3415840..f5d003144 100644 --- a/Support/Fuego/Mechanism/Models/grimech30-noArN/mechanism.H +++ b/Support/Fuego/Mechanism/Models/grimech30-noArN/mechanism.H @@ -65,14 +65,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -9197,8 +9197,8 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void productionRate(amrex::Real * wdot const amrex::Real qr = k_f * exp(-(g_RT[1] + 2.000000*g_RT[3] - g_RT[3] - g_RT[6])) * (refC) * (sc[3]*sc[6]); const amrex::Real qdot = qf - qr; wdot[1] -= qdot; - wdot[3] -= 2.000000 * qdot; wdot[3] += qdot; + wdot[3] -= 2.000000 * qdot; wdot[6] += qdot; } @@ -11925,7 +11925,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<1296; i++) { @@ -24000,11 +23999,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[1295] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[35]; @@ -24023,12 +24020,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<1296; i++) { @@ -37530,12 +37525,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[35]; @@ -37554,7 +37547,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/grimech30-noArN/mechanism.cpp b/Support/Fuego/Mechanism/Models/grimech30-noArN/mechanism.cpp index 21a9b3876..72c0c3349 100644 --- a/Support/Fuego/Mechanism/Models/grimech30-noArN/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/grimech30-noArN/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ - - return; } @@ -237,8 +235,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1296); amrex::Gpu::DeviceVector c_v(35); @@ -272,16 +269,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1296); amrex::Gpu::DeviceVector c_v(35); @@ -319,16 +312,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(1296); amrex::Gpu::DeviceVector c_v(35); @@ -366,15 +355,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -416,14 +401,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1296); @@ -479,15 +460,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1296); @@ -552,15 +529,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(1296); amrex::Gpu::DeviceVector c_v(35); @@ -602,15 +575,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(1296); amrex::Gpu::DeviceVector c_v(35); @@ -669,9 +638,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/grimech30/mechanism.H b/Support/Fuego/Mechanism/Models/grimech30/mechanism.H index 6936e80ad..200370e6a 100644 --- a/Support/Fuego/Mechanism/Models/grimech30/mechanism.H +++ b/Support/Fuego/Mechanism/Models/grimech30/mechanism.H @@ -84,14 +84,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -12936,8 +12936,8 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void productionRate(amrex::Real * wdot const amrex::Real qf = k_f * (sc[0]*(sc[1] * sc[1])); const amrex::Real qr = k_f * exp(-(g_RT[0] - 2.000000*g_RT[0] + 2.000000*g_RT[1])) * (refC) * ((sc[0] * sc[0])); const amrex::Real qdot = qf - qr; - wdot[0] += 2.000000 * qdot; wdot[0] -= qdot; + wdot[0] += 2.000000 * qdot; wdot[1] -= 2.000000 * qdot; } @@ -17190,7 +17190,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<2916; i++) { @@ -35722,11 +35721,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[2915] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[53]; @@ -35745,12 +35742,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<2916; i++) { @@ -56305,12 +56300,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[53]; @@ -56329,7 +56322,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/grimech30/mechanism.cpp b/Support/Fuego/Mechanism/Models/grimech30/mechanism.cpp index 79f7d8a48..a993f3096 100644 --- a/Support/Fuego/Mechanism/Models/grimech30/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/grimech30/mechanism.cpp @@ -13,8 +13,6 @@ void atomicWeight(amrex::Real * awt) awt[2] = 12.011150; /*C */ awt[3] = 14.006700; /*N */ awt[4] = 39.948000; /*AR */ - - return; } @@ -338,8 +336,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -373,16 +370,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -420,16 +413,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -467,15 +456,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -517,14 +502,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(2916); @@ -580,15 +561,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(2916); @@ -653,15 +630,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -703,15 +676,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(2916); amrex::Gpu::DeviceVector c_v(53); @@ -770,9 +739,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/heptane_3sp/mechanism.H b/Support/Fuego/Mechanism/Models/heptane_3sp/mechanism.H index 445fe646e..e9b33123c 100644 --- a/Support/Fuego/Mechanism/Models/heptane_3sp/mechanism.H +++ b/Support/Fuego/Mechanism/Models/heptane_3sp/mechanism.H @@ -33,14 +33,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -1639,7 +1639,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<16; i++) { @@ -1721,11 +1720,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[15] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[3]; @@ -1744,12 +1741,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<16; i++) { @@ -1834,12 +1829,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[3]; @@ -1858,7 +1851,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/heptane_3sp/mechanism.cpp b/Support/Fuego/Mechanism/Models/heptane_3sp/mechanism.cpp index dcdc08ad1..adc4e09c8 100644 --- a/Support/Fuego/Mechanism/Models/heptane_3sp/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/heptane_3sp/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 1.007970; /*H */ awt[2] = 15.999400; /*O */ awt[3] = 14.006700; /*N */ - - return; } @@ -71,8 +69,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -106,16 +103,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -153,16 +146,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -200,15 +189,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -250,14 +235,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(16); @@ -313,15 +294,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(16); @@ -386,15 +363,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -436,15 +409,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(16); amrex::Gpu::DeviceVector c_v(3); @@ -503,9 +472,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/heptane_fc/mechanism.H b/Support/Fuego/Mechanism/Models/heptane_fc/mechanism.H index f34ce8552..007e1e8f2 100644 --- a/Support/Fuego/Mechanism/Models/heptane_fc/mechanism.H +++ b/Support/Fuego/Mechanism/Models/heptane_fc/mechanism.H @@ -82,14 +82,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -14629,7 +14629,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<2809; i++) { @@ -22744,11 +22743,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[2808] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[52]; @@ -22767,12 +22764,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<2809; i++) { @@ -32007,12 +32002,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[52]; @@ -32031,7 +32024,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/heptane_fc/mechanism.cpp b/Support/Fuego/Mechanism/Models/heptane_fc/mechanism.cpp index 024293d3f..39b916345 100644 --- a/Support/Fuego/Mechanism/Models/heptane_fc/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/heptane_fc/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 15.999400; /*O */ awt[2] = 1.007970; /*H */ awt[3] = 12.011150; /*C */ - - return; } @@ -328,8 +326,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(2809); amrex::Gpu::DeviceVector c_v(52); @@ -363,16 +360,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(2809); amrex::Gpu::DeviceVector c_v(52); @@ -410,16 +403,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(2809); amrex::Gpu::DeviceVector c_v(52); @@ -457,15 +446,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -507,14 +492,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(2809); @@ -570,15 +551,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(2809); @@ -643,15 +620,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(2809); amrex::Gpu::DeviceVector c_v(52); @@ -693,15 +666,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(2809); amrex::Gpu::DeviceVector c_v(52); @@ -760,9 +729,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/heptane_lu_88sk/mechanism.H b/Support/Fuego/Mechanism/Models/heptane_lu_88sk/mechanism.H index 93ba20899..26bc2ad9e 100644 --- a/Support/Fuego/Mechanism/Models/heptane_lu_88sk/mechanism.H +++ b/Support/Fuego/Mechanism/Models/heptane_lu_88sk/mechanism.H @@ -118,14 +118,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -25590,7 +25590,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<7921; i++) { @@ -46181,11 +46180,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[7920] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[88]; @@ -46204,12 +46201,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<7921; i++) { @@ -67393,12 +67388,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[88]; @@ -67417,7 +67410,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/heptane_lu_88sk/mechanism.cpp b/Support/Fuego/Mechanism/Models/heptane_lu_88sk/mechanism.cpp index 08110a962..4ab75d390 100644 --- a/Support/Fuego/Mechanism/Models/heptane_lu_88sk/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/heptane_lu_88sk/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 12.011150; /*C */ awt[2] = 15.999400; /*O */ awt[3] = 14.006700; /*N */ - - return; } @@ -543,8 +541,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(7921); amrex::Gpu::DeviceVector c_v(88); @@ -578,16 +575,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(7921); amrex::Gpu::DeviceVector c_v(88); @@ -625,16 +618,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(7921); amrex::Gpu::DeviceVector c_v(88); @@ -672,15 +661,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -722,14 +707,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(7921); @@ -785,15 +766,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(7921); @@ -858,15 +835,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(7921); amrex::Gpu::DeviceVector c_v(88); @@ -908,15 +881,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(7921); amrex::Gpu::DeviceVector c_v(88); @@ -975,9 +944,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/nitrogens/mechanism.H b/Support/Fuego/Mechanism/Models/nitrogens/mechanism.H index 1da7801e0..9e51cff94 100644 --- a/Support/Fuego/Mechanism/Models/nitrogens/mechanism.H +++ b/Support/Fuego/Mechanism/Models/nitrogens/mechanism.H @@ -29,14 +29,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -1445,7 +1445,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<9; i++) { @@ -1527,11 +1526,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[8] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[2]; @@ -1550,12 +1547,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<9; i++) { @@ -1640,12 +1635,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[2]; @@ -1664,7 +1657,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/nitrogens/mechanism.cpp b/Support/Fuego/Mechanism/Models/nitrogens/mechanism.cpp index eb95e36d8..ba9f37876 100644 --- a/Support/Fuego/Mechanism/Models/nitrogens/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/nitrogens/mechanism.cpp @@ -9,8 +9,6 @@ void atomicWeight(amrex::Real * awt) { awt[0] = 14.006700; /*N */ - - return; } @@ -60,8 +58,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -95,16 +92,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -142,16 +135,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -189,15 +178,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -239,14 +224,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(9); @@ -302,15 +283,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(9); @@ -375,15 +352,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -425,15 +398,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(9); amrex::Gpu::DeviceVector c_v(2); @@ -492,9 +461,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Mechanism/Models/propane_fc/mechanism.H b/Support/Fuego/Mechanism/Models/propane_fc/mechanism.H index 52545e61d..456683489 100644 --- a/Support/Fuego/Mechanism/Models/propane_fc/mechanism.H +++ b/Support/Fuego/Mechanism/Models/propane_fc/mechanism.H @@ -64,14 +64,14 @@ void CKNCF(int * ncf); void CKSYME_STR(amrex::Vector& ename); void CKSYMS_STR(amrex::Vector& kname); /* SPARSE INFORMATION */ -void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS); -void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP); -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS); -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP); -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base); +void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS); +void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP); +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS); +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP); +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base); @@ -10484,7 +10484,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void dcvpRdT(amrex::Real * species, con } /*compute an approx to the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP) { for (int i=0; i<1225; i++) { @@ -16735,11 +16734,9 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J /* dTdot/dT */ J[1224] = -tmp1 + tmp2*dcmixdT - tmp3*dehmixdT; } -#endif /*compute an approx to the reaction Jacobian (for preconditioning) */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP) { amrex::Real c[34]; @@ -16758,12 +16755,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, return; } -#endif /*compute the reaction Jacobian on GPU */ -#ifdef COMPILE_JACOBIAN AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) +void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP) { for (int i=0; i<1225; i++) { @@ -23414,12 +23409,10 @@ void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP) return; } -#endif /*compute the reaction Jacobian */ -#ifdef COMPILE_JACOBIAN -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP) +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP) { amrex::Real c[34]; @@ -23438,7 +23431,6 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Rea return; } -#endif /* Transport function declarations */ diff --git a/Support/Fuego/Mechanism/Models/propane_fc/mechanism.cpp b/Support/Fuego/Mechanism/Models/propane_fc/mechanism.cpp index da8d4c681..33f584258 100644 --- a/Support/Fuego/Mechanism/Models/propane_fc/mechanism.cpp +++ b/Support/Fuego/Mechanism/Models/propane_fc/mechanism.cpp @@ -12,8 +12,6 @@ void atomicWeight(amrex::Real * awt) awt[1] = 15.999400; /*O */ awt[2] = 1.007970; /*H */ awt[3] = 12.011150; /*C */ - - return; } @@ -233,8 +231,7 @@ void CKSYMS_STR(amrex::Vector& kname) } /*compute the sparsity pattern of the chemistry Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1225); amrex::Gpu::DeviceVector c_v(34); @@ -268,16 +265,12 @@ void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) +void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS) { amrex::Gpu::DeviceVector J_v(1225); amrex::Gpu::DeviceVector c_v(34); @@ -315,16 +308,12 @@ void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS) } *nJdata = NCELLS * nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the simplified (for preconditioning) system Jacobian */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) +void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP) { amrex::Gpu::DeviceVector J_v(1225); amrex::Gpu::DeviceVector c_v(34); @@ -362,15 +351,11 @@ void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP) } nJdata[0] = nJdata_tmp; - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS) +void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS) { int offset_row; int offset_col; @@ -412,14 +397,10 @@ void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELL colPtrs[offset_col + (k + 1)] = nJdata_tmp; } } - - return; } -#endif /*compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1225); @@ -475,15 +456,11 @@ void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, } } } - - return; } -#endif /*compute the sparsity pattern of the system Jacobian */ /*CSR format BASE is user choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base) +void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base) { int offset; amrex::Gpu::DeviceVector J_v(1225); @@ -548,15 +525,11 @@ void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCE } } } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian on CPU */ /*BASE 0 */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP) { amrex::Gpu::DeviceVector J_v(1225); amrex::Gpu::DeviceVector c_v(34); @@ -598,15 +571,11 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * in } colPtrs[k+1] = nJdata_tmp; } - - return; } -#endif /*compute the sparsity pattern of the simplified (for precond) system Jacobian */ /*CSR format BASE is under choice */ -#ifdef COMPILE_JACOBIAN -void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base) +void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base) { amrex::Gpu::DeviceVector J_v(1225); amrex::Gpu::DeviceVector c_v(34); @@ -665,9 +634,6 @@ void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * con rowPtr[l+1] = nJdata_tmp; } } - - return; } -#endif #endif diff --git a/Support/Fuego/Pythia/pythia-0.5/packages/fuego/fuego/serialization/c/CPickler.py b/Support/Fuego/Pythia/pythia-0.5/packages/fuego/fuego/serialization/c/CPickler.py index 7781fe3f8..9d1bb1923 100644 --- a/Support/Fuego/Pythia/pythia-0.5/packages/fuego/fuego/serialization/c/CPickler.py +++ b/Support/Fuego/Pythia/pythia-0.5/packages/fuego/fuego/serialization/c/CPickler.py @@ -588,28 +588,28 @@ def _chem_file_decl(self, mechanism): self._write("void CKSYMS_STR(amrex::Vector& kname);") self._write(self.line(" SPARSE INFORMATION ")) self._write( - "void SPARSITY_INFO(int * nJdata, int * consP, int NCELLS);" + "void SPARSITY_INFO(int * nJdata, const int * consP, int NCELLS);" ) self._write( - "void SPARSITY_INFO_SYST(int * nJdata, int * consP, int NCELLS);" + "void SPARSITY_INFO_SYST(int * nJdata, const int * consP, int NCELLS);" ) self._write( - "void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, int * consP);" + "void SPARSITY_INFO_SYST_SIMPLIFIED(int * nJdata, const int * consP);" ) self._write( - "void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS);" + "void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS);" ) self._write( - "void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base);" + "void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base);" ) self._write( - "void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base);" + "void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base);" ) self._write( - "void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP);" + "void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP);" ) self._write( - "void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base);" + "void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base);" ) self._write() return @@ -5525,7 +5525,7 @@ def _ajacPrecond(self, mechanism): self._write() self._write(self.line("compute an approx to the reaction Jacobian")) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( "AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void aJacobian_precond(amrex::Real * J, amrex::Real * sc, amrex::Real T, int HP)" ) @@ -5713,7 +5713,7 @@ def _ajacPrecond(self, mechanism): self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") return def _ajac_reaction_precond(self, mechanism, reaction, rcase): @@ -6302,9 +6302,9 @@ def _DproductionRatePrecond(self, mechanism): "compute an approx to the reaction Jacobian (for preconditioning)" ) ) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * HP)" + "AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT_SIMPLIFIED(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * HP)" ) self._write("{") self._indent() @@ -6336,7 +6336,7 @@ def _DproductionRatePrecond(self, mechanism): self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") return def _ajac_GPU(self, mechanism): @@ -6344,10 +6344,10 @@ def _ajac_GPU(self, mechanism): self._write() self._write(self.line("compute the reaction Jacobian on GPU")) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write("AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE") self._write( - "void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP)" + "void aJacobian(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP)" ) self._write("{") self._indent() @@ -6550,7 +6550,7 @@ def _ajac_GPU(self, mechanism): self._write() self._write("return;") self._write("}") - self._write("#endif") + # self._write("#endif") self._write() return @@ -7045,9 +7045,9 @@ def _DproductionRate(self, mechanism): self._write() self._write(self.line("compute the reaction Jacobian")) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, int * consP)" + "AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void DWDOT(amrex::Real * J, amrex::Real * sc, amrex::Real * Tp, const int * consP)" ) self._write("{") self._indent() @@ -7077,7 +7077,7 @@ def _DproductionRate(self, mechanism): self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() return @@ -9203,7 +9203,7 @@ def _ajac(self, mechanism): self._write() self._write(self.line("compute the reaction Jacobian on CPU")) self._write( - "void aJacobian_cpu(amrex::Real * J, amrex::Real * sc, amrex::Real T, int consP)" + "void aJacobian_cpu(amrex::Real * J, amrex::Real * sc, amrex::Real T, const int consP)" ) self._write("{") self._indent() @@ -12748,8 +12748,6 @@ def _atomicWeight(self, mechanism): + self.line("%s" % element.symbol) ) - self._write() - self._write("return;") self._outdent() self._write("}") @@ -12945,9 +12943,9 @@ def _sparsity(self, mechanism): self._write( self.line("compute the sparsity pattern of the chemistry Jacobian") ) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "void SPARSITY_INFO( int * nJdata, int * consP, int NCELLS)" + "void SPARSITY_INFO( int * nJdata, const int * consP, int NCELLS)" ) self._write("{") self._indent() @@ -13005,12 +13003,10 @@ def _sparsity(self, mechanism): self._write() self._write("*nJdata = NCELLS * nJdata_tmp;") - self._write() - self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() self._write() @@ -13019,9 +13015,9 @@ def _sparsity(self, mechanism): self._write( self.line("compute the sparsity pattern of the system Jacobian") ) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "void SPARSITY_INFO_SYST( int * nJdata, int * consP, int NCELLS)" + "void SPARSITY_INFO_SYST( int * nJdata, const int * consP, int NCELLS)" ) self._write("{") self._indent() @@ -13087,12 +13083,10 @@ def _sparsity(self, mechanism): self._write() self._write("*nJdata = NCELLS * nJdata_tmp;") - self._write() - self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() self._write() @@ -13103,9 +13097,9 @@ def _sparsity(self, mechanism): "compute the sparsity pattern of the simplified (for preconditioning) system Jacobian" ) ) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, int * consP)" + "void SPARSITY_INFO_SYST_SIMPLIFIED( int * nJdata, const int * consP)" ) self._write("{") self._indent() @@ -13171,12 +13165,10 @@ def _sparsity(self, mechanism): self._write() self._write("nJdata[0] = nJdata_tmp;") - self._write() - self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() self._write() @@ -13186,9 +13178,9 @@ def _sparsity(self, mechanism): "compute the sparsity pattern of the chemistry Jacobian in CSC format -- base 0" ) ) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, int * consP, int NCELLS)" + "void SPARSITY_PREPROC_CSC(int * rowVals, int * colPtrs, const int * consP, int NCELLS)" ) self._write("{") self._indent() @@ -13255,12 +13247,10 @@ def _sparsity(self, mechanism): self._outdent() self._write("}") - self._write() - self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() #### @@ -13269,9 +13259,9 @@ def _sparsity(self, mechanism): "compute the sparsity pattern of the chemistry Jacobian in CSR format -- base 0" ) ) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, int * consP, int NCELLS, int base)" + "void SPARSITY_PREPROC_CSR(int * colVals, int * rowPtrs, const int * consP, int NCELLS, int base)" ) self._write("{") self._indent() @@ -13365,11 +13355,9 @@ def _sparsity(self, mechanism): self._outdent() self._write("}") - self._write() - self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() #### @@ -13377,9 +13365,9 @@ def _sparsity(self, mechanism): self.line("compute the sparsity pattern of the system Jacobian") ) self._write(self.line("CSR format BASE is user choice")) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, int * consP, int NCELLS, int base)" + "void SPARSITY_PREPROC_SYST_CSR(int * colVals, int * rowPtr, const int * consP, int NCELLS, int base)" ) self._write("{") self._indent() @@ -13489,11 +13477,9 @@ def _sparsity(self, mechanism): self._outdent() self._write("}") - self._write() - self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() #### @@ -13503,9 +13489,9 @@ def _sparsity(self, mechanism): ) ) self._write(self.line("BASE 0")) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, int * consP)" + "void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSC(int * rowVals, int * colPtrs, int * indx, const int * consP)" ) self._write("{") self._indent() @@ -13574,11 +13560,9 @@ def _sparsity(self, mechanism): self._outdent() self._write("}") - self._write() - self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() #### @@ -13588,9 +13572,9 @@ def _sparsity(self, mechanism): ) ) self._write(self.line("CSR format BASE is under choice")) - self._write("#ifdef COMPILE_JACOBIAN") + # self._write("#ifdef COMPILE_JACOBIAN") self._write( - "void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, int * consP, int base)" + "void SPARSITY_PREPROC_SYST_SIMPLIFIED_CSR(int * colVals, int * rowPtr, const int * consP, int base)" ) self._write("{") self._indent() @@ -13690,11 +13674,9 @@ def _sparsity(self, mechanism): self._outdent() self._write("}") - self._write() - self._write("return;") self._outdent() self._write("}") - self._write("#endif") + # self._write("#endif") self._write() return diff --git a/Testing/Exec/EosEval/GNUmakefile b/Testing/Exec/EosEval/GNUmakefile index e6d0490b0..19c6b4a76 100644 --- a/Testing/Exec/EosEval/GNUmakefile +++ b/Testing/Exec/EosEval/GNUmakefile @@ -6,8 +6,8 @@ VERBOSE = FALSE DEBUG = FALSE # Compiler -COMP = gnu -FCOMP = gfortran +COMP = gnu +FCOMP = gfortran USE_MPI = FALSE USE_OMP = FALSE USE_CUDA = FALSE @@ -15,21 +15,32 @@ USE_HIP = FALSE # PelePhysics FUEGO_GAS = TRUE -USE_SUNDIALS_PP = FALSE -USE_RK64_PP = FALSE +TINY_PROFILE = FALSE # define the location of the PELE_PHYSICS top directory -PELE_PHYSICS_HOME := ../../.. +PELE_PHYSICS_HOME ?= ../../.. + +# this flag activates the subcycling mode in the D/Cvode routines +DEFINES += -DMOD_REACTOR + +# Activates use of SUNDIALS +ifeq ($(USE_CUDA), TRUE) + PELE_USE_KLU = FALSE +else + ifeq ($(USE_HIP), TRUE) + PELE_USE_KLU = FALSE + else + PELE_USE_KLU = FALSE + endif +endif ifeq ($(FUEGO_GAS), TRUE) Eos_Model = Fuego Chemistry_Model = LiDryer - Reactions_dir = null Transport_Model = Constant else Eos_Model = GammaLaw Chemistry_Model = Null - Reactions_dir = null Transport_Model = Constant endif diff --git a/Testing/Exec/EosEval/main.cpp b/Testing/Exec/EosEval/main.cpp index cd44dd8e7..aec924f8d 100644 --- a/Testing/Exec/EosEval/main.cpp +++ b/Testing/Exec/EosEval/main.cpp @@ -4,154 +4,151 @@ #include #include #include +#include -#include #include "mechanism.H" #include #include -using namespace amrex; - int -main (int argc, - char* argv[]) +main(int argc, char* argv[]) { - Initialize(argc,argv); - { + amrex::Initialize(argc, argv); + { + + amrex::ParmParse pp; + + // Define geometry + amrex::Array npts{AMREX_D_DECL(1, 1, 1)}; + + for (int i = 0; i < AMREX_SPACEDIM; ++i) { + npts[i] = 128; + } - ParmParse pp; + amrex::Box domain( + amrex::IntVect(AMREX_D_DECL(0, 0, 0)), + amrex::IntVect(AMREX_D_DECL(npts[0] - 1, npts[1] - 1, npts[2] - 1))); - // Define geometry - Array npts {AMREX_D_DECL(1,1,1)};; - for (int i = 0; i < AMREX_SPACEDIM; ++i) { - npts[i] = 128; - } - - Box domain(IntVect(AMREX_D_DECL(0,0,0)), - IntVect(AMREX_D_DECL(npts[0]-1,npts[1]-1,npts[2]-1))); + amrex::RealBox real_box( + {AMREX_D_DECL(-1.0, -1.0, -1.0)}, {AMREX_D_DECL(1.0, 1.0, 1.0)}); - RealBox real_box({AMREX_D_DECL(-1.0,-1.0,-1.0)}, - {AMREX_D_DECL( 1.0, 1.0, 1.0)}); + int coord = 0; - int coord = 0; + amrex::Array is_periodic{AMREX_D_DECL(1, 1, 1)}; - Array is_periodic {AMREX_D_DECL(1,1,1)}; + amrex::Geometry geom(domain, real_box, coord, is_periodic); - Geometry geom(domain, real_box, coord, is_periodic); - - // Define BoxArray - int max_size = 32; - pp.query("max_size",max_size); - BoxArray ba(domain); - ba.maxSize(max_size); + // Define BoxArray + int max_size = 32; + pp.query("max_size", max_size); + amrex::BoxArray ba(domain); + ba.maxSize(max_size); - ParmParse ppa("amr"); - std::string pltfile("plt"); - ppa.query("plot_file",pltfile); + amrex::ParmParse ppa("amr"); + std::string pltfile("plt"); + ppa.query("plot_file", pltfile); - DistributionMapping dm{ba}; - int num_grow = 0; + amrex::DistributionMapping dm{ba}; + int num_grow = 0; - // Data MFs - MultiFab mass_frac(ba,dm,NUM_SPECIES,num_grow); - MultiFab temperature(ba,dm,1,num_grow); - MultiFab density(ba,dm,1,num_grow); - MultiFab energy(ba,dm,1,num_grow); + // Data MFs + amrex::MultiFab mass_frac(ba, dm, NUM_SPECIES, num_grow); + amrex::MultiFab temperature(ba, dm, 1, num_grow); + amrex::MultiFab density(ba, dm, 1, num_grow); + amrex::MultiFab energy(ba, dm, 1, num_grow); - IntVect tilesize(D_DECL(10240,8,32)); - - const auto geomdata = geom.data(); + const auto geomdata = geom.data(); #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mass_frac,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { - - const Box& bx = mfi.tilebox(); - auto const& Y_a = mass_frac.array(mfi); - auto const& T_a = temperature.array(mfi); - auto const& rho_a = density.array(mfi); - auto const& e_a = energy.array(mfi); - amrex::ParallelFor(bx, [Y_a, T_a, rho_a, e_a, geomdata] - AMREX_GPU_DEVICE (int i, int j, int k) noexcept { - initialize_data(i, j, k, Y_a, T_a, rho_a, e_a, geomdata); - }); - } - - // Plot init state for debug purposes - //MultiFab VarPltInit(ba,dm,NUM_SPECIES+3,num_grow); - //MultiFab::Copy(VarPltInit,mass_frac,0,0,NUM_SPECIES,num_grow); - //MultiFab::Copy(VarPltInit,temperature,0,NUM_SPECIES,1,num_grow); - //MultiFab::Copy(VarPltInit,density,0,NUM_SPECIES+1,1,num_grow); - //MultiFab::Copy(VarPltInit,energy,0,NUM_SPECIES+2,1,num_grow); - //std::string initfile = amrex::Concatenate(pltfile,99); // Need a number other than zero for reg test to pass - //PlotFileFromMF(VarPltInit,initfile); - - MultiFab VarPlt(ba,dm,4,num_grow); - MultiFab cp(ba,dm,1,num_grow); - MultiFab cv(ba,dm,1,num_grow); + for (amrex::MFIter mfi(mass_frac, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + + const amrex::Box& bx = mfi.tilebox(); + auto const& Y_a = mass_frac.array(mfi); + auto const& T_a = temperature.array(mfi); + auto const& rho_a = density.array(mfi); + auto const& e_a = energy.array(mfi); + amrex::ParallelFor( + bx, [Y_a, T_a, rho_a, e_a, + geomdata] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + initialize_data(i, j, k, Y_a, T_a, rho_a, e_a, geomdata); + }); + } + + amrex::MultiFab VarPlt(ba, dm, 4, num_grow); + amrex::MultiFab cp(ba, dm, 1, num_grow); + amrex::MultiFab cv(ba, dm, 1, num_grow); #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mass_frac,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { - - const Box& box = mfi.tilebox(); - - auto const& Y_a = mass_frac.const_array(mfi); - auto const& T_a = temperature.const_array(mfi); - auto const& cp_a = cp.array(mfi); - amrex::ParallelFor(box, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { - get_cp(i, j, k, Y_a, T_a, cp_a); - }); - } - MultiFab::Copy(VarPlt,cp,0,0,1,num_grow); - + for (amrex::MFIter mfi(mass_frac, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + + const amrex::Box& box = mfi.tilebox(); + + auto const& Y_a = mass_frac.const_array(mfi); + auto const& T_a = temperature.const_array(mfi); + auto const& cp_a = cp.array(mfi); + amrex::ParallelFor( + box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + get_cp(i, j, k, Y_a, T_a, cp_a); + }); + } + amrex::MultiFab::Copy(VarPlt, cp, 0, 0, 1, num_grow); #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mass_frac,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { - - const Box& box = mfi.tilebox(); - - auto const& Y_a = mass_frac.const_array(mfi); - auto const& T_a = temperature.const_array(mfi); - auto const& cv_a = cv.array(mfi); - amrex::ParallelFor(box, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { - get_cv(i, j, k, Y_a, T_a, cv_a); - }); - } - MultiFab::Copy(VarPlt,cv,0,1,1,num_grow); + for (amrex::MFIter mfi(mass_frac, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + + const amrex::Box& box = mfi.tilebox(); + + auto const& Y_a = mass_frac.const_array(mfi); + auto const& T_a = temperature.const_array(mfi); + auto const& cv_a = cv.array(mfi); + amrex::ParallelFor( + box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + get_cv(i, j, k, Y_a, T_a, cv_a); + }); + } + amrex::MultiFab::Copy(VarPlt, cv, 0, 1, 1, num_grow); - #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mass_frac,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { - - const Box& box = mfi.tilebox(); - - auto const& Y_a = mass_frac.const_array(mfi); - auto const& e_a = energy.const_array(mfi); - auto const& T_a = temperature.array(mfi); - amrex::ParallelFor(box, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { - get_T_from_EY(i, j, k, Y_a, T_a, e_a); - }); - } - MultiFab::Copy(VarPlt,temperature,0,2,1,num_grow); - MultiFab::Copy(VarPlt,energy,0,3,1,num_grow); - - std::string outfile = amrex::Concatenate(pltfile,1); // Need a number other than zero for reg test to pass - PlotFileFromMF(VarPlt,outfile); - + for (amrex::MFIter mfi(mass_frac, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + + const amrex::Box& box = mfi.tilebox(); + + auto const& Y_a = mass_frac.const_array(mfi); + auto const& e_a = energy.const_array(mfi); + auto const& T_a = temperature.array(mfi); + amrex::ParallelFor( + box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + get_T_from_EY(i, j, k, Y_a, T_a, e_a); + }); } - - amrex::Finalize(); - - return 0; + amrex::MultiFab::Copy(VarPlt, temperature, 0, 2, 1, num_grow); + amrex::MultiFab::Copy(VarPlt, energy, 0, 3, 1, num_grow); + + std::string outfile = amrex::Concatenate(pltfile, 1); + // TODO: add fct count to this output + amrex::Vector plt_VarsName; + plt_VarsName.push_back("cp"); + plt_VarsName.push_back("cv"); + plt_VarsName.push_back("temperature"); + plt_VarsName.push_back("energy"); + amrex::WriteSingleLevelPlotfile( + outfile, VarPlt, plt_VarsName, geom, 0.0, 0); + } + + amrex::Finalize(); + + return 0; } diff --git a/Testing/Exec/Make.PelePhysics b/Testing/Exec/Make.PelePhysics index 18e298f42..e54e3d1fd 100644 --- a/Testing/Exec/Make.PelePhysics +++ b/Testing/Exec/Make.PelePhysics @@ -9,27 +9,19 @@ REACTIONS_HOME ?= $(PELE_PHYSICS_HOME)/Reactions TRAN_HOME ?= $(PELE_PHYSICS_HOME)/Transport EBASE = Pele +BL_NO_FORT = TRUE # EXTERN_CORE is simply a list of the directories we use in Eos, Reactions, Transport and Util # this list will be searched for runtime parameters EXTERN_CORE ?= -ifeq ($(USE_SUNDIALS_PP),TRUE) - include $(PELE_PHYSICS_HOME)/ThirdParty/Make.ThirdParty -else ifeq ($(USE_RK64_PP),TRUE) - DEFINES += -DUSE_RK64_PP -endif - include $(AMREX_HOME)/Tools/GNUMake/Make.defs +include $(PELE_PHYSICS_HOME)/ThirdParty/Make.ThirdParty + # PeleC uses a coarse grained OMP approach DEFINES += -DCRSEGRNDOMP -# Need this for DataServices to compile -DEFINES += -DBL_NOLINEVALUES - -DEFINES += -DCOMPILE_JACOBIAN - ifeq ($(USE_ACC), TRUE) DEFINES += -DACC endif @@ -53,8 +45,8 @@ endif ifeq ($(Eos_Model),$(filter $(Eos_Model),Soave-Redlich-Kwong)) DEFINES += -DUSE_SRK_EOS endif -INCLUDE_LOCATIONS += $(EOS_HOME) -VPATH_LOCATIONS += $(EOS_HOME) +INCLUDE_LOCATIONS += $(EOS_HOME) +VPATH_LOCATIONS += $(EOS_HOME) ifeq ($(Eos_Model), Fuego) TRANSPORT_TYPE := IDEAL_GAS else @@ -68,27 +60,9 @@ Bpack += $(EOS_HOME)/Make.package Blocs += $(EOS_HOME) # Reactions -ifeq ($(USE_SUNDIALS_PP),TRUE) - REACTIONS_PATH := $(REACTIONS_HOME)/$(strip $(Reactions_dir)) - include $(REACTIONS_HOME)/Make.package - include $(REACTIONS_PATH)/Make.package - INCLUDE_LOCATIONS += $(REACTIONS_HOME) $(REACTIONS_PATH) - VPATH_LOCATIONS += $(REACTIONS_HOME) $(REACTIONS_PATH) -endif -ifeq ($(USE_RK64_PP),TRUE) - REACTIONS_PATH := $(REACTIONS_HOME)/$(strip $(Reactions_dir)) - include $(REACTIONS_HOME)/Make.package - include $(REACTIONS_PATH)/Make.package - INCLUDE_LOCATIONS += $(REACTIONS_HOME) $(REACTIONS_PATH) - VPATH_LOCATIONS += $(REACTIONS_HOME) $(REACTIONS_PATH) -endif -ifeq ($(USE_F90_PP),TRUE) - REACTIONS_HOME_F90 := $(REACTIONS_HOME)/F90 - REACTIONS_PATH_F90 := $(REACTIONS_PATH)/F90 - EXTERN_CORE += $(REACTIONS_HOME_F90) $(REACTIONS_PATH_F90) - INCLUDE_LOCATIONS += $(REACTIONS_HOME_F90) $(REACTIONS_PATH_F90) - VPATH_LOCATIONS += $(REACTIONS_HOME_F90) $(REACTIONS_PATH_F90) -endif +include $(REACTIONS_HOME)/Make.package +INCLUDE_LOCATIONS += $(REACTIONS_HOME) +VPATH_LOCATIONS += $(REACTIONS_HOME) ifeq ($(Eos_Model), GammaLaw) ifneq ($(Chemistry_Model), Null) $(error Chemistry_Model definition not compatible with Eos_Model=GammaLaw) @@ -124,25 +98,16 @@ ifeq ($(Transport_Model), Sutherland) DEFINES += -DUSE_SUTHERLAND_TRANSPORT endif -Pdirs := Base Boundary AmrCore Extern/amrdata -Bdirs := Source +Pdirs := Base Boundary AmrCore Bpack += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)/Make.package) Blocs += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)) -Bpack += $(foreach dir, $(Bdirs), $(TOP)/Testing/$(dir)/Make.package) -Blocs += $(foreach dir, $(Bdirs), $(TOP)/Testing/$(dir)) - include $(Bpack) INCLUDE_LOCATIONS += $(Blocs) VPATH_LOCATIONS += $(Blocs) -# runtime parameter support for extern/ routines -f90EXE_sources += extern.f90 - -EXTERN_TEMPLATE := $(PELE_PHYSICS_HOME)/Testing/Source/extern_probin.template - EXTERN_PARAMETERS := $(shell $(AMREX_HOME)/Tools/F_scripts/findparams.py $(EXTERN_CORE)) # job_info support @@ -150,13 +115,10 @@ CEXE_sources += AMReX_buildInfo.cpp CEXE_headers += $(AMREX_HOME)/Tools/C_scripts/buildInfo.H INCLUDE_LOCATIONS += $(AMREX_HOME)/Tools/C_scripts - MNAMES := EOS=$(EOS_PATH) REACTIONS=$(REACTIONS_PATH) MNAMES += TRANSPORT=$(TRAN_HOME) MNAMES += CHEMISTRY=$(Chemistry_Model) -include $(PELE_PHYSICS_HOME)/ThirdParty/Make.ThirdParty - ifeq ($(shell uname),Darwin) all: $(executable) install_name_tool -add_rpath $(PELE_PHYSICS_HOME)/ThirdParty/INSTALL/$(configSpecificTPSuffix)/lib $(executable) @@ -170,12 +132,14 @@ endif include $(AMREX_HOME)/Tools/GNUMake/Make.rules +$(objForExecs): TPL + ifeq ($(USE_CUDA),TRUE) CXXFLAGS+=-Xptxas --disable-optimizer-constants endif clean:: - $(SILENT) $(RM) extern.f90 extern_parameters.cpp extern_parameters_F.H extern_parameters.H extern.f90 + $(SILENT) $(RM) extern_parameters.cpp extern_parameters.H $(SILENT) $(RM) AMReX_buildInfo.cpp AMReX_buildInfo.cpp: @@ -186,25 +150,17 @@ AMReX_buildInfo.cpp: --MODULES "$(MNAMES)" \ --GIT "$(TOP) $(AMREX_HOME) $(PELE_PHYSICS_HOME)" -extern.f90: $(EXTERN_PARAMETERS) $(EXTERN_TEMPLATE) - $(AMREX_HOME)/Tools/F_scripts/write_probin.py \ - -t $(EXTERN_TEMPLATE) -o extern.f90 -n extern \ - --pa "$(EXTERN_PARAMETERS)" - -ifeq ($(USE_SUNDIALS_PP),TRUE) - TPL: - cd $(PELE_PHYSICS_HOME)/ThirdParty; make AMREX_HOME=$(AMREX_HOME) USE_HIP=$(USE_HIP) USE_CUDA=$(USE_CUDA) USE_KLU_PP=$(USE_KLU_PP) DEBUG=$(DEBUG) COMP=$(HOSTCC) NVCC=$(COMP) CUDA_ARCH=$(CUDA_ARCH) +TPL: + @echo "==> Building SUNDIALS library" + @cd $(PELE_PHYSICS_HOME)/ThirdParty; make sundials AMREX_HOME=$(AMREX_HOME) USE_HIP=$(USE_HIP) USE_CUDA=$(USE_CUDA) PELE_USE_KLU=$(PELE_USE_KLU) DEBUG=$(DEBUG) COMP=$(HOSTCC) NVCC=$(COMP) CUDA_ARCH=$(CUDA_ARCH) - TPLclean: - cd $(PELE_PHYSICS_HOME)/ThirdParty; make AMREX_HOME=$(AMREX_HOME) USE_HIP=$(USE_HIP) USE_CUDA=$(USE_CUDA) USE_KLU_PP=$(USE_KLU_PP) DEBUG=$(DEBUG) COMP=$(HOSTCC) NVCC=$(COMP) CUDA_ARCH=$(CUDA_ARCH) clean +TPLclean: + @echo "==> Removing SUNDIALS library" + @cd $(PELE_PHYSICS_HOME)/ThirdParty; make AMREX_HOME=$(AMREX_HOME) USE_HIP=$(USE_HIP) USE_CUDA=$(USE_CUDA) PELE_USE_KLU=$(PELE_USE_KLU) DEBUG=$(DEBUG) COMP=$(HOSTCC) NVCC=$(COMP) CUDA_ARCH=$(CUDA_ARCH) clean - TPLrealclean: - cd $(PELE_PHYSICS_HOME)/ThirdParty; make AMREX_HOME=$(AMREX_HOME) USE_HIP=$(USE_HIP) USE_CUDA=$(USE_CUDA) USE_KLU_PP=$(USE_KLU_PP) DEBUG=$(DEBUG) COMP=$(HOSTCC) NVCC=$(COMP) CUDA_ARCH=$(CUDA_ARCH) realclean -else - TPL: - TPLclean: - TPLrealclean: -endif +TPLrealclean: + @echo "==> Removing SUNDIALS library" + @cd $(PELE_PHYSICS_HOME)/ThirdParty; make AMREX_HOME=$(AMREX_HOME) USE_HIP=$(USE_HIP) USE_CUDA=$(USE_CUDA) PELE_USE_KLU=$(PELE_USE_KLU) DEBUG=$(DEBUG) COMP=$(HOSTCC) NVCC=$(COMP) CUDA_ARCH=$(CUDA_ARCH) realclean #----------------------------------------------------------------------------- diff --git a/Testing/Exec/ProductionRateEval/GNUmakefile b/Testing/Exec/ProductionRateEval/GNUmakefile index c8b5c84f1..745d7f049 100644 --- a/Testing/Exec/ProductionRateEval/GNUmakefile +++ b/Testing/Exec/ProductionRateEval/GNUmakefile @@ -14,25 +14,22 @@ FCOMP = gfortran USE_MPI = TRUE USE_OMP = FALSE -USE_CUDA = FALSE USE_CUDA = TRUE +USE_CUDA = FALSE TINY_PROFILE = FALSE -USE_SUNDIALS_PP = TRUE ifeq ($(USE_CUDA), TRUE) - USE_KLU_PP = FALSE + PELE_USE_KLU = FALSE else - USE_F90_PP = FALSE - USE_KLU_PP = FALSE + PELE_USE_KLU = FALSE endif -USE_KLU = $(USE_KLU_PP) # sort out keywords later... +USE_KLU = $(PELE_USE_KLU) # sort out keywords later... Eos_Model = Fuego #Chemistry_Model = LiDryer Chemistry_Model = drm19 #Chemistry_Model = grimech12 -Reactions_dir = Fuego Transport_Model = Simple CEXE_sources += main.cpp diff --git a/Testing/Exec/ProductionRateEval/main.cpp b/Testing/Exec/ProductionRateEval/main.cpp index 04478d04e..bdcd94ff2 100644 --- a/Testing/Exec/ProductionRateEval/main.cpp +++ b/Testing/Exec/ProductionRateEval/main.cpp @@ -5,40 +5,36 @@ #include #include #include +#include #include #include #include -#include -#ifdef USE_SUNDIALS_PP -#include -#else -#include -#endif - -using namespace amrex; +#include AMREX_GPU_DEVICE -inline -void -initialize_data(int i, int j, int k, - Array4 const& mf, - Array4 const& temp, - Array4 const& rho, - const GpuArray& dx, - const GpuArray& plo, - const GpuArray& phi ) noexcept +inline void +initialize_data( + int i, + int j, + int k, + amrex::Array4 const& mf, + amrex::Array4 const& temp, + amrex::Array4 const& rho, + const amrex::GpuArray& dx, + const amrex::GpuArray& plo, + const amrex::GpuArray& phi) noexcept { - Real dTemp = 5.0; - Real dRho = 0.005; - Real y = plo[1] + (j+0.5)*dx[1]; - Real x = plo[0] + (i+0.5)*dx[0]; - Real pi = 3.1415926535897932; - Real L[3]; - Real P[3]; - Real Y_lo[NUM_SPECIES]; - Real Y_hi[NUM_SPECIES]; + amrex::Real dTemp = 5.0; + amrex::Real dRho = 0.005; + amrex::Real y = plo[1] + (j + 0.5) * dx[1]; + amrex::Real x = plo[0] + (i + 0.5) * dx[0]; + amrex::Real pi = 3.1415926535897932; + amrex::Real L[3]; + amrex::Real P[3]; + amrex::Real Y_lo[NUM_SPECIES]; + amrex::Real Y_hi[NUM_SPECIES]; for (int n = 0; n < 3; n++) { L[n] = phi[n] - plo[n]; @@ -46,122 +42,136 @@ initialize_data(int i, int j, int k, } for (int n = 0; n < NUM_SPECIES; n++) { Y_lo[n] = 0.0; - Y_hi[n] = 1.0 / NUM_SPECIES ; + Y_hi[n] = 1.0 / NUM_SPECIES; } Y_lo[0] = 1.0; // T, Yk, rho - Real Tavg = 500; - Real Ravg = 0.01; -#if ( AMREX_SPACEDIM == 1 ) - temp(i,j,k) = Tavg; - rho(i,j,k) = Ravg; + amrex::Real Tavg = 500; + amrex::Real Ravg = 0.01; +#if (AMREX_SPACEDIM == 1) + temp(i, j, k) = Tavg; + rho(i, j, k) = Ravg; #else - temp(i,j,k) = Tavg + dTemp * std::sin(2.0*pi*y/P[1]); - rho(i,j,k) = Ravg + dRho * std::sin(2.0*pi*y/P[1]); + temp(i, j, k) = Tavg + dTemp * std::sin(2.0 * pi * y / P[1]); + rho(i, j, k) = Ravg + dRho * std::sin(2.0 * pi * y / P[1]); #endif for (int n = 0; n < NUM_SPECIES; n++) { - mf(i,j,k,n) = Y_lo[n] + (Y_hi[n]-Y_lo[n]) * x / L[0]; + mf(i, j, k, n) = Y_lo[n] + (Y_hi[n] - Y_lo[n]) * x / L[0]; } // corr Yk - Real dummy = 0.0; - for (int n = 0; n < NUM_SPECIES-1; n++) { - dummy = dummy + mf(i,j,k,n); + amrex::Real dummy = 0.0; + for (int n = 0; n < NUM_SPECIES - 1; n++) { + dummy = dummy + mf(i, j, k, n); } - mf(i,j,k,NUM_SPECIES-1) = 1.0 - dummy; + mf(i, j, k, NUM_SPECIES - 1) = 1.0 - dummy; } int -main (int argc, - char* argv[]) +main(int argc, char* argv[]) { - Initialize(argc,argv); + amrex::Initialize(argc, argv); { amrex::Print() << " Initialization of EOS (CPP)... \n"; - - ParmParse pp; + + amrex::ParmParse pp; int nc = 512; - pp.query("nc",nc); - std::vector npts(3,nc); + pp.query("nc", nc); + std::vector npts(3, nc); - Box domain(IntVect(D_DECL(0,0,0)), - IntVect(D_DECL(npts[0]-1,npts[1]-1,npts[2]-1))); + amrex::Box domain( + amrex::IntVect(D_DECL(0, 0, 0)), + amrex::IntVect(D_DECL(npts[0] - 1, npts[1] - 1, npts[2] - 1))); - GpuArray plo, phi, dx; - for (int i=0; i plo, phi, dx; + for (int i = 0; i < BL_SPACEDIM; ++i) { phi[i] = domain.length(i); - dx[i] = (phi[i] - plo[i])/domain.length(i); + dx[i] = (phi[i] - plo[i]) / domain.length(i); } + + amrex::RealBox real_box( + {AMREX_D_DECL(plo[0], plo[1], plo[2])}, + {AMREX_D_DECL(phi[0], phi[1], phi[2])}); + + int coord = 0; + + amrex::Array is_periodic{AMREX_D_DECL(1, 1, 1)}; + + amrex::Geometry geom(domain, real_box, coord, is_periodic); + int max_size = 128; - pp.query("max_size",max_size); - BoxArray ba(domain); + pp.query("max_size", max_size); + amrex::BoxArray ba(domain); ba.maxSize(max_size); - int num_spec; - num_spec = NUM_SPECIES; + const int num_spec = NUM_SPECIES; - DistributionMapping dm{ba}; + amrex::DistributionMapping dm{ba}; int num_grow = 0; - MultiFab mass_frac(ba,dm,num_spec,num_grow); - MultiFab temperature(ba,dm,1,num_grow); - MultiFab density(ba,dm,1,num_grow); + amrex::MultiFab mass_frac(ba, dm, num_spec, num_grow); + amrex::MultiFab temperature(ba, dm, 1, num_grow); + amrex::MultiFab density(ba, dm, 1, num_grow); #ifdef _OPENMP #pragma omp parallel #endif - for (MFIter mfi(mass_frac,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& gbox = mfi.tilebox(); - - Array4 const& Y_a = mass_frac.array(mfi); - Array4 const& T_a = temperature.array(mfi); - Array4 const& rho_a = density.array(mfi); - - amrex::ParallelFor(gbox, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - initialize_data(i, j, k, Y_a, T_a, rho_a, dx, plo, phi); - }); + for (amrex::MFIter mfi(mass_frac, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& gbox = mfi.tilebox(); + + amrex::Array4 const& Y_a = mass_frac.array(mfi); + amrex::Array4 const& T_a = temperature.array(mfi); + amrex::Array4 const& rho_a = density.array(mfi); + + amrex::ParallelFor( + gbox, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + initialize_data(i, j, k, Y_a, T_a, rho_a, dx, plo, phi); + }); } - bool write_output = pp.countval("plot_file") > 0; - MultiFab wdots(ba,dm,num_spec,num_grow); - + amrex::MultiFab wdots(ba, dm, num_spec, num_grow); + #ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mass_frac,TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - const Box& box = mfi.tilebox(); - - const auto mf = mass_frac.array(mfi); - const auto temp = temperature.array(mfi); - const auto rho = density.array(mfi); - const auto wdot = wdots.array(mfi); - - ParallelFor(box, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - Real Yl[NUM_SPECIES]; - Real Wl[NUM_SPECIES]; - for (int n=0; n plt_VarsName; + for (int k = 0; k < NUM_SPECIES; ++k) { + plt_VarsName.push_back("wdot_" + std::to_string(k)); + } + amrex::WriteSingleLevelPlotfile( + outfile, wdots, plt_VarsName, geom, 0.0, 0); } } - Finalize(); + amrex::Finalize(); return 0; } diff --git a/Testing/Exec/ReactEval/GNUmakefile b/Testing/Exec/ReactEval/GNUmakefile index 141b41e41..a097e68a2 100644 --- a/Testing/Exec/ReactEval/GNUmakefile +++ b/Testing/Exec/ReactEval/GNUmakefile @@ -19,46 +19,26 @@ TINY_PROFILE = FALSE # define the location of the PELE_PHYSICS top directory PELE_PHYSICS_HOME ?= ../../.. -####################### # this flag activates the subcycling mode in the D/Cvode routines DEFINES += -DMOD_REACTOR -####################### -# ODE solver OPTIONS: DVODE (default) / SUNDIALS / RK explicit -####################### -# Activates use of SUNDIALS: CVODE (default) / ARKODE -USE_SUNDIALS_PP = TRUE -USE_RK64_PP = FALSE -ifeq ($(USE_SUNDIALS_PP), TRUE) - USE_ARKODE_PP = FALSE - ifeq ($(USE_CUDA), TRUE) - USE_KLU_PP = FALSE - else - ifeq ($(USE_HIP), TRUE) - USE_KLU_PP = FALSE - else - USE_KLU_PP = FALSE - endif - endif +ifeq ($(USE_CUDA), TRUE) + PELE_USE_KLU = FALSE else - USE_RK64_PP = TRUE - ifeq ($(USE_RK64_PP), TRUE) - # Activates use of Hari explicit RK - # will only work if USE_SUNDIALS_PP = FALSE - TRANSPORT_CPP = TRUE + ifeq ($(USE_HIP), TRUE) + PELE_USE_KLU = FALSE + else + PELE_USE_KLU = FALSE endif endif -####################### ifeq ($(FUEGO_GAS), TRUE) Eos_Model = Fuego Chemistry_Model = drm19 - Reactions_dir = cvode Transport_Model = Simple else Eos_Model = GammaLaw Chemistry_Model = Null - Reactions_dir = null Transport_Model = Constant endif diff --git a/Testing/Exec/ReactEval/GPU_misc.H b/Testing/Exec/ReactEval/GPU_misc.H index 3a257ea1e..76b0f86e7 100644 --- a/Testing/Exec/ReactEval/GPU_misc.H +++ b/Testing/Exec/ReactEval/GPU_misc.H @@ -33,7 +33,7 @@ initialize_data(int i, int j, int k, amrex::GpuArray Y; amrex::Real y = plo[1] + (j+0.5)*dx[1]; - amrex::Real x = plo[0] + (i+0.5)*dx[0]; + //amrex::Real x = plo[0] + (i+0.5)*dx[0]; amrex::Real pi = 3.1415926535897932; amrex::GpuArray L; amrex::GpuArray P; diff --git a/Testing/Exec/ReactEval/inputs.3d-regt_GPU b/Testing/Exec/ReactEval/inputs.3d-regt_GPU index 0461a5552..77f14495a 100644 --- a/Testing/Exec/ReactEval/inputs.3d-regt_GPU +++ b/Testing/Exec/ReactEval/inputs.3d-regt_GPU @@ -2,6 +2,7 @@ ncells = 2 256 2 max_grid_size = 16 plotfile = plt fuel_name = CH4 +chem_integrator = "ReactorRK64" ode.dt = 1.e-09 ode.ndt = 1 diff --git a/Testing/Exec/ReactEval/inputs.3d_1dArray b/Testing/Exec/ReactEval/inputs.3d_1dArray index eb95f35de..89a18527a 100644 --- a/Testing/Exec/ReactEval/inputs.3d_1dArray +++ b/Testing/Exec/ReactEval/inputs.3d_1dArray @@ -3,7 +3,7 @@ max_grid_size = 16 plotfile = plt fuel_name = CH4 reactFormat = 1dArray - +chem_integrator = "ReactorRK64" ode.dt = 1.e-05 ode.ndt = 1 diff --git a/Testing/Exec/ReactEval/inputs.3d_Array4 b/Testing/Exec/ReactEval/inputs.3d_Array4 index 4d71df238..1bd13cfa2 100644 --- a/Testing/Exec/ReactEval/inputs.3d_Array4 +++ b/Testing/Exec/ReactEval/inputs.3d_Array4 @@ -3,7 +3,7 @@ max_grid_size = 16 plotfile = plt fuel_name = CH4 reactFormat = Array4 - +chem_integrator = "ReactorRK64" ode.dt = 1.e-05 ode.ndt = 1 diff --git a/Testing/Exec/ReactEval/inputs.3d_ChkFile b/Testing/Exec/ReactEval/inputs.3d_ChkFile index dac2ebb46..342fc4928 100644 --- a/Testing/Exec/ReactEval/inputs.3d_ChkFile +++ b/Testing/Exec/ReactEval/inputs.3d_ChkFile @@ -3,6 +3,7 @@ max_grid_size = 16 plotfile = plt fuel_name = CH4 reactFormat = Array4 +chem_integrator = "ReactorRK64" initFromFile = 1 # At the current time, the following file must have been # generated with PeleLM. diff --git a/Testing/Exec/ReactEval/main.cpp b/Testing/Exec/ReactEval/main.cpp index f3a199ae6..34fa8093b 100644 --- a/Testing/Exec/ReactEval/main.cpp +++ b/Testing/Exec/ReactEval/main.cpp @@ -8,66 +8,54 @@ #include #include -#ifdef USE_SUNDIALS_PP #ifdef AMREX_USE_GPU #include #endif -#endif #include "mechanism.H" #include -#include #include -#include - -#ifndef USE_RK64_PP -#ifdef USE_ARKODE_PP -static std::string ODE_SOLVER = "ARKODE"; -#else -static std::string ODE_SOLVER = "CVODE"; -#endif -#else -static std::string ODE_SOLVER = "RK64"; -#endif - -using namespace amrex; +#include -namespace { const std::string level_prefix{"Level_"}; } +namespace { +const std::string level_prefix{"Level_"}; +} -void GotoNextLine(std::istream& is) +void +GotoNextLine(std::istream& is) { - constexpr std::streamsize bl_ignore_max{100000}; - is.ignore(bl_ignore_max, '\n'); + constexpr std::streamsize bl_ignore_max{100000}; + is.ignore(bl_ignore_max, '\n'); } int -main (int argc, - char* argv[]) +main(int argc, char* argv[]) { - Initialize(argc,argv); - -#ifdef USE_SUNDIALS_PP + amrex::Initialize(argc, argv); #ifdef AMREX_USE_GPU - amrex::sundials::MemoryHelper::Initialize(); /* TODO: this ideally (I think) will go in the amrex::Initialize */ -#endif - + amrex::sundials::MemoryHelper::Initialize(); /* TODO: this ideally (I think) + will go in the + amrex::Initialize */ #endif { - Real strt_time = ParallelDescriptor::second(); + amrex::Real strt_time = amrex::ParallelDescriptor::second(); BL_PROFILE_VAR("main::main()", pmain); - ParmParse pp; + amrex::ParmParse pp; std::string fuel_name; pp.get("fuel_name", fuel_name); + std::string chem_integrator = ""; + pp.get("chem_integrator", chem_integrator); + std::string pltfile; bool do_plt = false; - if (pp.countval("plotfile")>0) { - pp.get("plotfile",pltfile); + if (pp.countval("plotfile") > 0) { + pp.get("plotfile", pltfile); do_plt = true; } @@ -75,10 +63,10 @@ main (int argc, // Can either generate single level data // or read in data from a checkpoint like file int initFromChk = 0; - pp.query("initFromFile",initFromChk); + pp.query("initFromFile", initFromChk); std::string chkfile = ""; if (initFromChk) { - pp.query("initFile",chkfile); + pp.query("initFile", chkfile); } /* react() function version */ @@ -87,233 +75,242 @@ main (int argc, std::string reactFormat = "Array4"; int reactFunc; pp.query("reactFormat", reactFormat); - if ( reactFormat == "Array4") { - reactFunc = 1; - } else if ( reactFormat == "1dArray" ) { - reactFunc = 2; + if (reactFormat == "Array4") { + reactFunc = 1; + } else if (reactFormat == "1dArray") { + reactFunc = 2; } else { - Abort(" --> reactFormat can only be 'Array4' or '1dArray' !"); + amrex::Abort(" --> reactFormat can only be 'Array4' or '1dArray' !"); } /* ODE inputs */ - ParmParse ppode("ode"); + amrex::ParmParse ppode("ode"); int ode_ncells = 1; - ppode.query("ode_ncells",ode_ncells); // number of cells to integrate per call, used only if reactFunc = 2 + ppode.query("ode_ncells", ode_ncells); // number of cells to integrate per + // call, used only if reactFunc = 2 + + amrex::Real dt = 1.e-5; + ppode.query("dt", dt); - Real dt = 1.e-5; - ppode.query("dt",dt); - int ndt = 1; - ppode.query("ndt",ndt); // number of solver calls per dt - + ppode.query("ndt", ndt); // number of solver calls per dt + int ode_iE = -1; - ppode.query("reactor_type",ode_iE); // RHS type, 1: e (PeleC), !1: h (PeleLM) <------ FIXME! - - Real rtol = 1e-10; - ppode.query("rtol",rtol); - - Real atol = 1e-10; - ppode.query("atol",atol); + ppode.query( + "reactor_type", + ode_iE); // RHS type, 1: e (PeleC), !1: h (PeleLM) <------ FIXME! + + amrex::Real rtol = 1e-10; + ppode.query("rtol", rtol); + + amrex::Real atol = 1e-10; + ppode.query("atol", atol); int use_typ_vals = 0; - ppode.query("use_typ_vals",use_typ_vals); + ppode.query("use_typ_vals", use_typ_vals); - Print() << "ODE solver: " << ODE_SOLVER << std::endl; - Print() << "Type of reactor: " << (ode_iE == 1 ? "e (PeleC)" : "h (PeleLM)") << std::endl; // <---- FIXME - Print() << "Fuel: " << fuel_name << ", Oxy: O2" << std::endl; + amrex::Print() << "ODE solver: " << chem_integrator << std::endl; + amrex::Print() << "Type of reactor: " + << (ode_iE == 1 ? "e (PeleC)" : "h (PeleLM)") + << std::endl; // <---- FIXME + amrex::Print() << "Fuel: " << fuel_name << ", Oxy: O2" << std::endl; /* Mixture info */ - int fuel_idx = -1; + int fuel_idx = -1; if (fuel_name == "H2") { - fuel_idx = H2_ID; + fuel_idx = H2_ID; #ifdef CH4_ID } else if (fuel_name == "CH4") { - fuel_idx = CH4_ID; + fuel_idx = CH4_ID; #endif #ifdef NC12H26_ID } else if (fuel_name == "NC12H26") { - fuel_idx = NC12H26_ID; + fuel_idx = NC12H26_ID; #endif #ifdef IC8H18_ID } else if (fuel_name == "IC8H18") { - fuel_idx = IC8H18_ID; + fuel_idx = IC8H18_ID; #endif } - pele::physics::transport::TransportParams trans_parms; + pele::physics::transport::TransportParams< + pele::physics::PhysicsType::transport_type> + trans_parms; trans_parms.allocate(); /* Initialize reactor object inside OMP region, including tolerances */ BL_PROFILE_VAR("main::reactor_info()", reactInfo); + std::unique_ptr reactor = + pele::physics::reactions::ReactorBase::create(chem_integrator); #ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif { - // Set ODE tolerances -#ifndef USE_ARKODE_PP - SetTolFactODE(rtol,atol); -#endif - reactor_init(ode_iE, ode_ncells); + reactor->init(ode_iE, ode_ncells); } BL_PROFILE_VAR_STOP(reactInfo); // ----------------------------------------------------------------------------- // Initialize geom/data - // When initFromChk = 0, default is single level data provided by initialize_data - // with a -1:1 unit length realbox in each dir and cell count provided by the user - // otherwise number of levels, geom and all are read in from the chkfile + // When initFromChk = 0, default is single level data provided by + // initialize_data with a -1:1 unit length realbox in each dir and cell + // count provided by the user otherwise number of levels, geom and all are + // read in from the chkfile // ----------------------------------------------------------------------------- int finest_level = 0; - Vector geoms; - Vector grids; - Vector dmaps; + amrex::Vector geoms; + amrex::Vector grids; + amrex::Vector dmaps; BL_PROFILE_VAR("main::geometry_setup", GeomSetup); - if ( initFromChk == 0 ) { - // ----------------------------------------------------------------------------- - // Resize vectors - // ----------------------------------------------------------------------------- - geoms.resize(finest_level+1); - grids.resize(finest_level+1); - dmaps.resize(finest_level+1); - - // ----------------------------------------------------------------------------- - // Define the geometry - // ----------------------------------------------------------------------------- - std::array ncells = {AMREX_D_DECL(1,1,1)}; - if (pp.countval("ncells") == 1) { - pp.get("ncells",ncells[0]); - ncells = {AMREX_D_DECL(ncells[0],1,1)}; - } - else if (pp.countval("ncells") >= AMREX_SPACEDIM) { - Vector nc(AMREX_SPACEDIM); - pp.getarr("ncells",nc,0,AMREX_SPACEDIM); - ncells = {AMREX_D_DECL(nc[0],nc[1],nc[2])}; - } - else { - Abort("ncells has to have length 1 or spacedim"); - } - - Box domain(IntVect(AMREX_D_DECL(0,0,0)), - IntVect(AMREX_D_DECL(ncells[0]-1,ncells[1]-1,ncells[2]-1))); + if (initFromChk == 0) { + // ----------------------------------------------------------------------------- + // Resize vectors + // ----------------------------------------------------------------------------- + geoms.resize(finest_level + 1); + grids.resize(finest_level + 1); + dmaps.resize(finest_level + 1); + + // ----------------------------------------------------------------------------- + // Define the geometry + // ----------------------------------------------------------------------------- + std::array ncells = {AMREX_D_DECL(1, 1, 1)}; + if (pp.countval("ncells") == 1) { + pp.get("ncells", ncells[0]); + ncells = {AMREX_D_DECL(ncells[0], 1, 1)}; + } else if (pp.countval("ncells") >= AMREX_SPACEDIM) { + amrex::Vector nc(AMREX_SPACEDIM); + pp.getarr("ncells", nc, 0, AMREX_SPACEDIM); + ncells = {AMREX_D_DECL(nc[0], nc[1], nc[2])}; + } else { + amrex::Abort("ncells has to have length 1 or spacedim"); + } + amrex::Box domain( + amrex::IntVect(AMREX_D_DECL(0, 0, 0)), + amrex::IntVect( + AMREX_D_DECL(ncells[0] - 1, ncells[1] - 1, ncells[2] - 1))); - RealBox real_box({AMREX_D_DECL(-1.0,-1.0,-1.0)}, - {AMREX_D_DECL( 1.0, 1.0, 1.0)}); + amrex::RealBox real_box( + {AMREX_D_DECL(-1.0, -1.0, -1.0)}, {AMREX_D_DECL(1.0, 1.0, 1.0)}); - int coord = 0; + int coord = 0; - Array is_periodic {AMREX_D_DECL(1,1,1)}; + amrex::Array is_periodic{AMREX_D_DECL(1, 1, 1)}; - geoms[0] = Geometry(domain, real_box, coord, is_periodic); + geoms[0] = amrex::Geometry(domain, real_box, coord, is_periodic); - Print() << "Integrating "<< domain.numPts() << " cells for: " << dt << " seconds with " << ndt << " substeps \n"; + amrex::Print() << "Integrating " << domain.numPts() + << " cells for: " << dt << " seconds with " << ndt + << " substeps \n"; - // ----------------------------------------------------------------------------- - // Define BoxArray / Dmap - // ----------------------------------------------------------------------------- - int max_grid_size = 16; - pp.query("max_grid_size",max_grid_size); - grids[0] = BoxArray(domain); - grids[0].maxSize(max_grid_size); - dmaps[0] = DistributionMapping(grids[0], ParallelDescriptor::NProcs()); + // ----------------------------------------------------------------------------- + // Define amrex::BoxArray / Dmap + // ----------------------------------------------------------------------------- + int max_grid_size = 16; + pp.query("max_grid_size", max_grid_size); + grids[0] = amrex::BoxArray(domain); + grids[0].maxSize(max_grid_size); + dmaps[0] = amrex::DistributionMapping( + grids[0], amrex::ParallelDescriptor::NProcs()); } else { - // Read chkfile header to get the geometry/BAs info - // - - if (ode_iE==1) { - Abort("The option to read in chemical data is currently only available with PeleLM data and requires ode_iE=2"); - } - - std::string File(chkfile + "/Header"); - VisMF::IO_Buffer io_buffer(VisMF::GetIOBufferSize()); - Vector fileCharPtr; - ParallelDescriptor::ReadAndBcastFile(File, fileCharPtr); - std::string fileCharPtrString(fileCharPtr.dataPtr()); - std::istringstream is(fileCharPtrString, std::istringstream::in); - std::string line, word; - - //-------------------------------------------- - // General info - //-------------------------------------------- - Real crse_dt = 0.0; - std::getline(is, line); // Dummy title - is >> finest_level; // Finest level - GotoNextLine(is); - is >> crse_dt; // Coarse level dt - GotoNextLine(is); + // Read chkfile header to get the geometry/BAs info + // - Print() << " Warning: dt and ndt are overwritten when using data from a checkfile ! \n"; - ndt = 1; - dt = crse_dt; - - //-------------------------------------------- - // Geometry - //-------------------------------------------- - Real prob_lo[AMREX_SPACEDIM]; - Real prob_hi[AMREX_SPACEDIM]; - // Low coordinates of domain bounding box - std::getline(is, line); - { - std::istringstream lis(line); - int i = 0; - while(lis >> word) - { - prob_lo[i++] = std::stod(word); - } - } + if (ode_iE == 1) { + amrex::Abort( + "The option to read in chemical data is currently only available " + "with PeleLM data and requires ode_iE=2"); + } - // High coordinates of domain bounding box - std::getline(is, line); - { - std::istringstream lis(line); - int i = 0; - while(lis >> word) - { - prob_hi[i++] = std::stod(word); - } + std::string File(chkfile + "/Header"); + amrex::VisMF::IO_Buffer io_buffer(amrex::VisMF::GetIOBufferSize()); + amrex::Vector fileCharPtr; + amrex::ParallelDescriptor::ReadAndBcastFile(File, fileCharPtr); + std::string fileCharPtrString(fileCharPtr.dataPtr()); + std::istringstream is(fileCharPtrString, std::istringstream::in); + std::string line, word; + + //-------------------------------------------- + // General info + //-------------------------------------------- + amrex::Real crse_dt = 0.0; + std::getline(is, line); // Dummy title + is >> finest_level; // Finest level + GotoNextLine(is); + is >> crse_dt; // Coarse level dt + GotoNextLine(is); + + amrex::Print() + << " Warning: dt and ndt are overwritten when using data from a " + "checkfile ! \n"; + ndt = 1; + dt = crse_dt; + + //-------------------------------------------- + // Geometry + //-------------------------------------------- + amrex::Real prob_lo[AMREX_SPACEDIM]; + amrex::Real prob_hi[AMREX_SPACEDIM]; + // Low coordinates of domain bounding box + std::getline(is, line); + { + std::istringstream lis(line); + int i = 0; + while (lis >> word) { + prob_lo[i++] = std::stod(word); } - int coord = 0; - Array is_periodic {AMREX_D_DECL(1,1,1)}; - RealBox domainSize(prob_lo, prob_hi); - Box domain; // Read domain Box - is >> domain; - GotoNextLine(is); + } - // ----------------------------------------------------------------------------- - // Resize vectors - // ----------------------------------------------------------------------------- - geoms.resize(finest_level+1); - grids.resize(finest_level+1); - dmaps.resize(finest_level+1); - - // ----------------------------------------------------------------------------- - // Define geoms, read BoxArray and define dmap - // ----------------------------------------------------------------------------- - geoms[0] = Geometry(domain, domainSize, coord, is_periodic); - for(int lev = 1; lev <= finest_level; ++lev) { - geoms[lev] = amrex::refine(geoms[lev-1], 2); // Assumes ref_ratio = 2 + // High coordinates of domain bounding box + std::getline(is, line); + { + std::istringstream lis(line); + int i = 0; + while (lis >> word) { + prob_hi[i++] = std::stod(word); } + } + int coord = 0; + amrex::Array is_periodic{AMREX_D_DECL(1, 1, 1)}; + amrex::RealBox domainSize(prob_lo, prob_hi); + amrex::Box domain; // Read domain amrex::Box + is >> domain; + GotoNextLine(is); + + // ----------------------------------------------------------------------------- + // Resize vectors + // ----------------------------------------------------------------------------- + geoms.resize(finest_level + 1); + grids.resize(finest_level + 1); + dmaps.resize(finest_level + 1); + + // ----------------------------------------------------------------------------- + // Define geoms, read amrex::BoxArray and define dmap + // ----------------------------------------------------------------------------- + geoms[0] = amrex::Geometry(domain, domainSize, coord, is_periodic); + for (int lev = 1; lev <= finest_level; ++lev) { + geoms[lev] = amrex::refine(geoms[lev - 1], 2); // Assumes ref_ratio = 2 + } - for(int lev = 0; lev <= finest_level; ++lev) - { - // read in level 'lev' BoxArray from Header - BoxArray ba; - ba.readFrom(is); - GotoNextLine(is); + for (int lev = 0; lev <= finest_level; ++lev) { + // read in level 'lev' amrex::BoxArray from Header + amrex::BoxArray ba; + ba.readFrom(is); + GotoNextLine(is); - // Set vector entries - grids[lev] = ba; - dmaps[lev] = DistributionMapping(ba, ParallelDescriptor::NProcs()); - } + // Set vector entries + grids[lev] = ba; + dmaps[lev] = + amrex::DistributionMapping(ba, amrex::ParallelDescriptor::NProcs()); + } - for(int lev = 0; lev <= finest_level; ++lev) - { - Print() << " Level " << lev - << " integrating " << grids[lev].numPts() - << " cells on " << grids[lev].size() - << " boxes for " << dt/std::pow(2,lev) << " seconds \n"; - } + for (int lev = 0; lev <= finest_level; ++lev) { + amrex::Print() << " Level " << lev << " integrating " + << grids[lev].numPts() << " cells on " + << grids[lev].size() << " boxes for " + << dt / std::pow(2, lev) << " seconds \n"; + } } BL_PROFILE_VAR_STOP(GeomSetup); @@ -322,421 +319,439 @@ main (int argc, // ----------------------------------------------------------------------------- BL_PROFILE_VAR("main::initialize_data()", InitData); int num_grow = 0; - Vector mf(finest_level+1); - Vector rY_source_ext(finest_level+1); - Vector mfE(finest_level+1); - Vector rY_source_energy_ext(finest_level+1); - Vector fctCount(finest_level+1); - Vector dummyMask(finest_level+1); - for(int lev = 0; lev <= finest_level; ++lev) - { - mf[lev].define(grids[lev],dmaps[lev],NUM_SPECIES+1,num_grow); - rY_source_ext[lev].define(grids[lev],dmaps[lev],NUM_SPECIES,num_grow); - mfE[lev].define(grids[lev],dmaps[lev],1,num_grow); - rY_source_energy_ext[lev].define(grids[lev],dmaps[lev],1,num_grow); - fctCount[lev].define(grids[lev],dmaps[lev],1,num_grow); - dummyMask[lev].define(grids[lev],dmaps[lev],1,num_grow); - dummyMask[lev].setVal(1); + amrex::Vector mf(finest_level + 1); + amrex::Vector rY_source_ext(finest_level + 1); + amrex::Vector mfE(finest_level + 1); + amrex::Vector rY_source_energy_ext(finest_level + 1); + amrex::Vector fctCount(finest_level + 1); + amrex::Vector dummyMask(finest_level + 1); + for (int lev = 0; lev <= finest_level; ++lev) { + mf[lev].define(grids[lev], dmaps[lev], NUM_SPECIES + 1, num_grow); + rY_source_ext[lev].define(grids[lev], dmaps[lev], NUM_SPECIES, num_grow); + mfE[lev].define(grids[lev], dmaps[lev], 1, num_grow); + rY_source_energy_ext[lev].define(grids[lev], dmaps[lev], 1, num_grow); + fctCount[lev].define(grids[lev], dmaps[lev], 1, num_grow); + dummyMask[lev].define(grids[lev], dmaps[lev], 1, num_grow); + dummyMask[lev].setVal(1); } - FabArrayBase::mfiter_tile_size = IntVect(AMREX_D_DECL(1024,1024,1024)); + amrex::FabArrayBase::mfiter_tile_size = + amrex::IntVect(AMREX_D_DECL(1024, 1024, 1024)); // ----------------------------------------------------------------------------- // Initialize data // ----------------------------------------------------------------------------- - if ( initFromChk == 0 ) { - for(int lev = 0; lev <= finest_level; ++lev) - { - const auto geomdata = geoms[lev].data(); + if (initFromChk == 0) { + for (int lev = 0; lev <= finest_level; ++lev) { + const auto geomdata = geoms[lev].data(); #ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi) { - - const Box& box = mfi.tilebox(); - - Array4 const& rY_a = mf[lev].array(mfi); - Array4 const& rYs_a = rY_source_ext[lev].array(mfi); - Array4 const& E_a = mfE[lev].array(mfi); - Array4 const& rE_a = rY_source_energy_ext[lev].array(mfi); - - ParallelFor(box, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - initialize_data(i, j, k, fuel_idx, ode_iE, - rY_a, rYs_a, E_a, rE_a, - geomdata); + for (amrex::MFIter mfi(mf[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + + const amrex::Box& box = mfi.tilebox(); + + amrex::Array4 const& rY_a = mf[lev].array(mfi); + amrex::Array4 const& rYs_a = + rY_source_ext[lev].array(mfi); + amrex::Array4 const& E_a = mfE[lev].array(mfi); + amrex::Array4 const& rE_a = + rY_source_energy_ext[lev].array(mfi); + + amrex::ParallelFor( + box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + initialize_data( + i, j, k, fuel_idx, ode_iE, rY_a, rYs_a, E_a, rE_a, geomdata); }); - } - } + } + } } else { - // Load the data from chkfile - for(int lev = 0; lev <= finest_level; ++lev) - { - // Assuming here a PeleLM state: vel + rho + species + rhoh + T + rhoRT - MultiFab stateIn(grids[lev],dmaps[lev],NUM_SPECIES+AMREX_SPACEDIM+4,0); - MultiFab forcingIn(grids[lev],dmaps[lev],NUM_SPECIES+1,0); - VisMF::Read(stateIn, - amrex::MultiFabFileFullPrefix(lev, chkfile, level_prefix, "OldState")); - VisMF::Read(forcingIn, - amrex::MultiFabFileFullPrefix(lev, chkfile, level_prefix, "ChemForcing")); - // Copy into our local data holders - // and convert from MKS -> CGS since we have PeleLM data + // Load the data from chkfile + for (int lev = 0; lev <= finest_level; ++lev) { + // Assuming here a PeleLM state: vel + rho + species + rhoh + T + rhoRT + amrex::MultiFab stateIn( + grids[lev], dmaps[lev], NUM_SPECIES + AMREX_SPACEDIM + 4, 0); + amrex::MultiFab forcingIn(grids[lev], dmaps[lev], NUM_SPECIES + 1, 0); + amrex::VisMF::Read( + stateIn, amrex::MultiFabFileFullPrefix( + lev, chkfile, level_prefix, "OldState")); + amrex::VisMF::Read( + forcingIn, amrex::MultiFabFileFullPrefix( + lev, chkfile, level_prefix, "ChemForcing")); + // Copy into our local data holders + // and convert from MKS -> CGS since we have PeleLM data #ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& box = mfi.tilebox(); - - auto const& rhoYs = mf[lev].array(mfi); - auto const& temp = mf[lev].array(mfi,NUM_SPECIES); - auto const& rhoH = mfE[lev].array(mfi); - auto const& force_Y = rY_source_ext[lev].array(mfi); - auto const& force_E = rY_source_energy_ext[lev].array(mfi); - auto const& rhoYs_in = stateIn.const_array(mfi,AMREX_SPACEDIM+1); - auto const& temp_in = stateIn.const_array(mfi,AMREX_SPACEDIM+NUM_SPECIES+2); - auto const& rhoh_in = stateIn.const_array(mfi,AMREX_SPACEDIM+NUM_SPECIES+1); - auto const& force_a = forcingIn.const_array(mfi); - ParallelFor(box, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - for (int n = 0; n < NUM_SPECIES; n++) { - rhoYs(i,j,k,n) = rhoYs_in(i,j,k,n) * 1.0e-3; // with MKS -> CGS conversion - force_Y(i,j,k,n) = force_a(i,j,k,n) * 1.0e-3; - } - temp(i,j,k) = temp_in(i,j,k); - rhoH(i,j,k) = rhoh_in(i,j,k) * 10.0; // with MKS -> CGS conversion - force_E(i,j,k) = force_a(i,j,k,NUM_SPECIES) * 10.0; - }); - } - } + for (amrex::MFIter mfi(mf[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& box = mfi.tilebox(); + + auto const& rhoYs = mf[lev].array(mfi); + auto const& temp = mf[lev].array(mfi, NUM_SPECIES); + auto const& rhoH = mfE[lev].array(mfi); + auto const& force_Y = rY_source_ext[lev].array(mfi); + auto const& force_E = rY_source_energy_ext[lev].array(mfi); + auto const& rhoYs_in = stateIn.const_array(mfi, AMREX_SPACEDIM + 1); + auto const& temp_in = + stateIn.const_array(mfi, AMREX_SPACEDIM + NUM_SPECIES + 2); + auto const& rhoh_in = + stateIn.const_array(mfi, AMREX_SPACEDIM + NUM_SPECIES + 1); + auto const& force_a = forcingIn.const_array(mfi); + amrex::ParallelFor( + box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + for (int n = 0; n < NUM_SPECIES; n++) { + rhoYs(i, j, k, n) = + rhoYs_in(i, j, k, n) * 1.0e-3; // with MKS -> CGS conversion + force_Y(i, j, k, n) = force_a(i, j, k, n) * 1.0e-3; + } + temp(i, j, k) = temp_in(i, j, k); + rhoH(i, j, k) = + rhoh_in(i, j, k) * 10.0; // with MKS -> CGS conversion + force_E(i, j, k) = force_a(i, j, k, NUM_SPECIES) * 10.0; + }); + } + } } BL_PROFILE_VAR_STOP(InitData); // Print initial data if needed - BL_PROFILE_VAR_NS("PlotFile",PlotFile); + BL_PROFILE_VAR_NS("PlotFile", PlotFile); if (do_plt) { BL_PROFILE_VAR_START(PlotFile); - std::string outfile = Concatenate(pltfile,0); - Vector isteps(finest_level + 1, 0); - Vector refRatios(finest_level, {AMREX_D_DECL(2,2,2)}); - Vector plt_VarsName; + std::string outfile = amrex::Concatenate(pltfile, 0); + amrex::Vector isteps(finest_level + 1, 0); + amrex::Vector refRatios( + finest_level, {AMREX_D_DECL(2, 2, 2)}); + amrex::Vector plt_VarsName; for (int k = 0; k < NUM_SPECIES; ++k) { - plt_VarsName.push_back("SPEC"+std::to_string(k)); + plt_VarsName.push_back("SPEC" + std::to_string(k)); } plt_VarsName.push_back("TEMP"); - amrex::WriteMultiLevelPlotfile(outfile, finest_level + 1, GetVecOfConstPtrs(mf), - plt_VarsName, geoms, 0.0, isteps, refRatios); + amrex::WriteMultiLevelPlotfile( + outfile, finest_level + 1, GetVecOfConstPtrs(mf), plt_VarsName, geoms, + 0.0, isteps, refRatios); BL_PROFILE_VAR_STOP(PlotFile); } // ----------------------------------------------------------------------------- // Set typical values // ----------------------------------------------------------------------------- -#ifndef USE_ARKODE_PP + if (chem_integrator == "ReactorCvode") { #ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - { - if (use_typ_vals) { - Vector typ_vals(NUM_SPECIES+1,1.0e-10); - if (ppode.contains("typ_vals")) { - Print() << "Using user-defined typical values for the absolute tolerances of the ode solver.\n"; - ppode.getarr("typ_vals", typ_vals,0,NUM_SPECIES+1); - for (int i = 0; i < NUM_SPECIES; ++i) { - typ_vals[i] = std::max(typ_vals[i],1.e-10); - } - } else { - Print() << "Using typical values from the initial data for the absolute tolerances of the ode solver.\n"; - for (int lev = 0; lev <= finest_level; ++lev) { - /* - Pretty sure TypVal should be rhoYs in CGS, but keep that around just in case. - MultiFab massFrac(grids[lev],dmaps[lev],NUM_SPECIES,0); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& box = mfi.tilebox(); - auto const& rhoYs = mf[lev].const_array(mfi); - auto const& Ys = massFrac.array(mfi); - ParallelFor(box, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - amrex::Real rho = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { - rho += rhoYs(i,j,k,n); - } - amrex::Real rhoinv = 1.0/rho; - for (int n = 0; n < NUM_SPECIES; n++) { - Ys(i,j,k,n) = rhoYs(i,j,k,n) * rhoinv; - } - }); - } - */ - for (int i = 0; i < NUM_SPECIES; ++i) { - typ_vals[i] = std::max(typ_vals[i],mf[lev].max(i)); - } - typ_vals[NUM_SPECIES] = std::max(typ_vals[NUM_SPECIES],mf[lev].max(NUM_SPECIES)); - } + { + if (use_typ_vals) { + amrex::Vector typ_vals(NUM_SPECIES + 1, 1.0e-10); + if (ppode.contains("typ_vals")) { + amrex::Print() + << "Using user-defined typical values for the absolute " + "tolerances of the ode solver.\n"; + ppode.getarr("typ_vals", typ_vals, 0, NUM_SPECIES + 1); + for (int i = 0; i < NUM_SPECIES; ++i) { + typ_vals[i] = std::max(typ_vals[i], 1.e-10); + } + } else { + amrex::Print() + << "Using typical values from the initial data for the " + "absolute tolerances of the ode solver.\n"; + for (int lev = 0; lev <= finest_level; ++lev) { + /* + Pretty sure TypVal should be rhoYs in CGS, but keep that around + just in case. amrex::MultiFab + massFrac(grids[lev],dmaps[lev],NUM_SPECIES,0); #ifdef + AMREX_USE_OMP #pragma omp parallel if + (amrex::Gpu::notInLaunchRegion()) #endif for (amrex::MFIter + mfi(mf[lev],amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { const amrex::Box& box = mfi.tilebox(); auto const& + rhoYs = mf[lev].const_array(mfi); auto const& Ys = + massFrac.array(mfi); amrex::ParallelFor(box, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + amrex::Real rho = 0.0; + for (int n = 0; n < NUM_SPECIES; n++) { + rho += rhoYs(i,j,k,n); + } + amrex::Real rhoinv = 1.0/rho; + for (int n = 0; n < NUM_SPECIES; n++) { + Ys(i,j,k,n) = rhoYs(i,j,k,n) * rhoinv; + } + }); + } + */ + for (int i = 0; i < NUM_SPECIES; ++i) { + typ_vals[i] = std::max(typ_vals[i], mf[lev].max(i)); + } + typ_vals[NUM_SPECIES] = + std::max(typ_vals[NUM_SPECIES], mf[lev].max(NUM_SPECIES)); + } + } + reactor->SetTypValsODE(typ_vals); } - SetTypValsODE(typ_vals); } } -#endif - - Print() << " \n STARTING THE ADVANCE \n"; + amrex::Print() << " \n STARTING THE ADVANCE \n"; /* REACT */ - BL_PROFILE_VAR_NS("React",ReactInLoop); - BL_PROFILE_VAR_NS("Allocs",Allocs); - BL_PROFILE_VAR_NS("Flatten",mainflatten); + BL_PROFILE_VAR_NS("React", ReactInLoop); + BL_PROFILE_VAR_NS("Allocs", Allocs); + BL_PROFILE_VAR_NS("Flatten", mainflatten); - for(int lev = 0; lev <= finest_level; ++lev) - { - Real lvl_strt = ParallelDescriptor::second(); - BL_PROFILE_VAR("Advance_Level"+std::to_string(lev),Advance); + for (int lev = 0; lev <= finest_level; ++lev) { + amrex::Real lvl_strt = amrex::ParallelDescriptor::second(); + BL_PROFILE_VAR("Advance_Level" + std::to_string(lev), Advance); #ifdef AMREX_USE_OMP - const auto tiling = MFItInfo().SetDynamic(true); + const auto tiling = MFItInfo().SetDynamic(true); #pragma omp parallel #else - const bool tiling = TilingIfNotGPU(); + const bool tiling = amrex::TilingIfNotGPU(); #endif - for ( MFIter mfi(mf[lev],tiling); mfi.isValid(); ++mfi) { - - const Box& box = mfi.tilebox(); - int nc = box.numPts(); - int extra_cells = 0; - - const auto len = length(box); - const auto lo = lbound(box); + for (amrex::MFIter mfi(mf[lev], tiling); mfi.isValid(); ++mfi) { - auto const& rhoY = mf[lev].array(mfi); - auto const& T = mf[lev].array(mfi, NUM_SPECIES); - auto const& rhoE = mfE[lev].array(mfi); - auto const& frcExt = rY_source_ext[lev].array(mfi); - auto const& frcEExt = rY_source_energy_ext[lev].array(mfi); - auto const& fc = fctCount[lev].array(mfi); - auto const& mask = dummyMask[lev].array(mfi); - - // ------------------------------------------------------------- - // Integration with Array4 react function - if (reactFunc == 1) { - Real time = 0.0; - Real dt_lev = dt/std::pow(2,lev); - Real dt_incr = dt_lev/ndt; - int tmp_fc; - - Print() << " [" << lev << "]" << " integrating " << nc << " cells \n"; - /* Solve */ - BL_PROFILE_VAR_START(ReactInLoop); - for (int ii = 0; ii < ndt; ++ii) - { - tmp_fc=react(box, rhoY, frcExt, T, - rhoE, frcEExt, fc, mask, - dt_incr, time, ode_iE + int omp_thread = 0; +#ifdef AMREX_USE_OMP + omp_thread = omp_get_thread_num(); +#endif + const amrex::Box& box = mfi.tilebox(); + const int nc = box.numPts(); + int extra_cells = 0; + + auto const& rhoY = mf[lev].array(mfi); + auto const& T = mf[lev].array(mfi, NUM_SPECIES); + auto const& rhoE = mfE[lev].array(mfi); + auto const& frcExt = rY_source_ext[lev].array(mfi); + auto const& frcEExt = rY_source_energy_ext[lev].array(mfi); + auto const& fc = fctCount[lev].array(mfi); + auto const& mask = dummyMask[lev].array(mfi); + + // ------------------------------------------------------------- + // Integration with Array4 react function + if (reactFunc == 1) { + amrex::Real time = 0.0; + amrex::Real dt_lev = dt / std::pow(2, lev); + amrex::Real dt_incr = dt_lev / ndt; + int tmp_fc; + if (omp_thread == 0) { + amrex::Print() << " [" << lev << "]" + << " integrating " << nc << " cells \n"; + } + /* Solve */ + BL_PROFILE_VAR_START(ReactInLoop); + for (int ii = 0; ii < ndt; ++ii) { + tmp_fc = reactor->react( + box, rhoY, frcExt, T, rhoE, frcEExt, fc, mask, dt_incr, time #ifdef AMREX_USE_GPU - , amrex::Gpu::gpuStream() + , + amrex::Gpu::gpuStream() #endif - ); - dt_incr = dt_lev/ndt; - Gpu::Device::streamSynchronize(); - } - BL_PROFILE_VAR_STOP(ReactInLoop); + ); + dt_incr = dt_lev / ndt; + amrex::Gpu::Device::streamSynchronize(); + } + BL_PROFILE_VAR_STOP(ReactInLoop); // ------------------------------------------------------------- // Integration with 1dArray raw pointer react function - } - else if (reactFunc == 2) { + } else if (reactFunc == 2) { - // On GPU, integrate the entirely box at once - // othewise use the user-input ode_ncells + // On GPU, integrate the entirely box at once + // othewise use the user-input ode_ncells #ifdef AMREX_USE_GPU - ode_ncells = nc; + ode_ncells = nc; #endif - extra_cells = nc - (nc / ode_ncells) * ode_ncells; - Print() << " Integrating " << nc << " cells with a "<< ode_ncells << " ode cell buffer "; - Print() << "("<< extra_cells<<" extra cells) \n"; + extra_cells = nc - (nc / ode_ncells) * ode_ncells; + if (omp_thread == 0) { + amrex::Print() << " Integrating " << nc << " cells with a " + << ode_ncells << " ode cell buffer "; + amrex::Print() << "(" << extra_cells << " extra cells) \n"; + } - BL_PROFILE_VAR_START(Allocs); - int nCells = nc+extra_cells; + BL_PROFILE_VAR_START(Allocs); + int nCells = nc + extra_cells; #ifdef AMREX_USE_GPU - auto tmp_vect_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( - nCells * (NUM_SPECIES+1) * sizeof(amrex::Real)); - auto tmp_src_vect_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( - nCells * NUM_SPECIES * sizeof(amrex::Real)); - auto tmp_vect_energy_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( - nCells * sizeof(amrex::Real)); - auto tmp_src_vect_energy_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( - nCells * sizeof(amrex::Real)); - auto tmp_fc_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( - nCells * sizeof(amrex::Real)); - auto tmp_mask_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( - nCells * sizeof(amrex::Real)); + auto tmp_vect_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( + nCells * (NUM_SPECIES + 1) * sizeof(amrex::Real)); + auto tmp_src_vect_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( + nCells * NUM_SPECIES * sizeof(amrex::Real)); + auto tmp_vect_energy_d = + (amrex::Real*)amrex::The_Device_Arena()->alloc( + nCells * sizeof(amrex::Real)); + auto tmp_src_vect_energy_d = + (amrex::Real*)amrex::The_Device_Arena()->alloc( + nCells * sizeof(amrex::Real)); + auto tmp_fc_d = (long int*)amrex::The_Device_Arena()->alloc( + nCells * sizeof(amrex::Real)); + auto tmp_mask_d = (amrex::Real*)amrex::The_Device_Arena()->alloc( + nCells * sizeof(amrex::Real)); #endif - auto tmp_vect = new Real[nCells * (NUM_SPECIES+1)]; - auto tmp_src_vect = new Real[nCells * NUM_SPECIES]; - auto tmp_vect_energy = new Real[nCells]; - auto tmp_src_vect_energy = new Real[nCells]; - auto tmp_fc = new int[nCells]; - auto tmp_mask = new int[nCells]; - - BL_PROFILE_VAR_STOP(Allocs); + auto tmp_vect = new amrex::Real[nCells * (NUM_SPECIES + 1)]; + auto tmp_src_vect = new amrex::Real[nCells * NUM_SPECIES]; + auto tmp_vect_energy = new amrex::Real[nCells]; + auto tmp_src_vect_energy = new amrex::Real[nCells]; + auto tmp_fc = new long int[nCells]; + auto tmp_mask = new int[nCells]; - BL_PROFILE_VAR_START(mainflatten); -#ifndef AMREX_USE_GPU - ParallelFor(box, - [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept - { - int icell = (k-lo.z)*len.x*len.y + (j-lo.y)*len.x + (i-lo.x); - - box_flatten(icell, nCells, i, j, k, ode_iE, - rhoY, frcExt, T, rhoE, frcEExt, - tmp_vect, tmp_src_vect, tmp_vect_energy, tmp_src_vect_energy); - }); + BL_PROFILE_VAR_STOP(Allocs); - for (int icell=nc; icellflatten( + box, nCells, rhoY, frcExt, T, rhoE, frcEExt, tmp_vect, tmp_src_vect, + tmp_vect_energy, tmp_src_vect_energy); + + for (int icell = nc; icell < nc + extra_cells; icell++) { + for (int sp = 0; sp < NUM_SPECIES; sp++) { + tmp_vect[icell * (NUM_SPECIES + 1) + sp] = rhoY(0, 0, 0, sp); + tmp_src_vect[icell * NUM_SPECIES + sp] = frcExt(0, 0, 0, sp); } + tmp_vect[icell * (NUM_SPECIES + 1) + NUM_SPECIES] = T(0, 0, 0); + tmp_vect_energy[icell] = rhoE(0, 0, 0); + tmp_src_vect_energy[icell] = frcEExt(0, 0, 0); + tmp_mask[icell] = mask(0, 0, 0); + } #else - ParallelFor(box, - [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept - { - int icell = (k-lo.z)*len.x*len.y + (j-lo.y)*len.x + (i-lo.x); - - box_flatten(icell, nCells, i, j, k, ode_iE, - rhoY, frcExt, T, rhoE, frcEExt, - tmp_vect_d, tmp_src_vect_d, tmp_vect_energy_d, tmp_src_vect_energy_d); - }); - - Gpu::copy(Gpu::deviceToHost, tmp_vect_d, tmp_vect_d+nCells*(NUM_SPECIES+1), tmp_vect); - Gpu::copy(Gpu::deviceToHost, tmp_src_vect_d, tmp_src_vect_d+nCells*NUM_SPECIES, tmp_src_vect); - Gpu::copy(Gpu::deviceToHost, tmp_vect_energy_d, tmp_vect_energy_d+nCells, tmp_vect_energy); - Gpu::copy(Gpu::deviceToHost, tmp_src_vect_energy_d, tmp_src_vect_energy_d+nCells, tmp_src_vect_energy); + reactor->flatten( + box, nCells, rhoY, frcExt, T, rhoE, frcEExt, tmp_vect_d, + tmp_src_vect_d, tmp_vect_energy_d, tmp_src_vect_energy_d); + + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, tmp_vect_d, + tmp_vect_d + nCells * (NUM_SPECIES + 1), tmp_vect); + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, tmp_src_vect_d, + tmp_src_vect_d + nCells * NUM_SPECIES, tmp_src_vect); + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, tmp_vect_energy_d, + tmp_vect_energy_d + nCells, tmp_vect_energy); + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, tmp_src_vect_energy_d, + tmp_src_vect_energy_d + nCells, tmp_src_vect_energy); #endif - BL_PROFILE_VAR_STOP(mainflatten); - - /* Solve */ - BL_PROFILE_VAR_START(ReactInLoop); - for(int i = 0; i < nCells; i+=ode_ncells) { - tmp_fc[i] = 0; - Real time = 0.0; - Real dt_lev = dt/std::pow(2,lev); - Real dt_incr = dt_lev/ndt; - for (int ii = 0; ii < ndt; ++ii) { - tmp_fc[i] += react(&tmp_vect[i*(NUM_SPECIES+1)], &tmp_src_vect[i*NUM_SPECIES], - &tmp_vect_energy[i], &tmp_src_vect_energy[i], - dt_incr,time,ode_iE, ode_ncells + BL_PROFILE_VAR_STOP(mainflatten); + + /* Solve */ + BL_PROFILE_VAR_START(ReactInLoop); + for (int i = 0; i < nCells; i += ode_ncells) { + tmp_fc[i] = 0; + amrex::Real time = 0.0; + amrex::Real dt_lev = dt / std::pow(2, lev); + amrex::Real dt_incr = dt_lev / ndt; + for (int ii = 0; ii < ndt; ++ii) { + tmp_fc[i] += reactor->react( + &tmp_vect[i * (NUM_SPECIES + 1)], + &tmp_src_vect[i * NUM_SPECIES], &tmp_vect_energy[i], + &tmp_src_vect_energy[i], dt_incr, time, ode_ncells #ifdef AMREX_USE_GPU - , amrex::Gpu::gpuStream() + , + amrex::Gpu::gpuStream() #endif - ); - - dt_incr = dt_lev/ndt; - for (int ic = i+1; ic < i+ode_ncells ; ++ic) { - tmp_fc[ic] = tmp_fc[i]; - } - Gpu::Device::streamSynchronize(); - } + ); + + dt_incr = dt_lev / ndt; + for (int ic = i + 1; ic < i + ode_ncells; ++ic) { + tmp_fc[ic] = tmp_fc[i]; + } + amrex::Gpu::Device::streamSynchronize(); } - BL_PROFILE_VAR_STOP(ReactInLoop); + } + BL_PROFILE_VAR_STOP(ReactInLoop); - BL_PROFILE_VAR_START(mainflatten); + BL_PROFILE_VAR_START(mainflatten); #ifndef AMREX_USE_GPU - ParallelFor(box, - [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept - { - int icell = (k-lo.z)*len.x*len.y + (j-lo.y)*len.x + (i-lo.x); - box_unflatten(icell, nCells, i, j, k, ode_iE, - rhoY, T, rhoE, frcEExt, fc, - tmp_vect, tmp_vect_energy, tmp_fc[icell], dt); - }); + reactor->unflatten( + box, nCells, rhoY, T, rhoE, frcEExt, fc, tmp_vect, tmp_vect_energy, + tmp_fc, dt); #else - Gpu::copy(Gpu::hostToDevice, tmp_vect, tmp_vect+nCells*(NUM_SPECIES+1), tmp_vect_d); - Gpu::copy(Gpu::hostToDevice, tmp_src_vect, tmp_src_vect+nCells*NUM_SPECIES, tmp_src_vect_d); - Gpu::copy(Gpu::hostToDevice, tmp_vect_energy, tmp_vect_energy+nCells, tmp_vect_energy_d); - Gpu::copy(Gpu::hostToDevice, tmp_src_vect_energy, tmp_src_vect_energy+nCells, tmp_src_vect_energy_d); - Gpu::copy(Gpu::hostToDevice, tmp_fc, tmp_fc+nCells, tmp_fc_d); - - ParallelFor(box, - [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept - { - int icell = (k-lo.z)*len.x*len.y + (j-lo.y)*len.x + (i-lo.x); - box_unflatten(icell, nCells, i, j, k, ode_iE, - rhoY, T, rhoE, frcEExt, fc, - tmp_vect_d, tmp_vect_energy_d, tmp_fc_d[icell], dt); - }); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, tmp_vect, + tmp_vect + nCells * (NUM_SPECIES + 1), tmp_vect_d); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, tmp_src_vect, + tmp_src_vect + nCells * NUM_SPECIES, tmp_src_vect_d); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, tmp_vect_energy, tmp_vect_energy + nCells, + tmp_vect_energy_d); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, tmp_src_vect_energy, + tmp_src_vect_energy + nCells, tmp_src_vect_energy_d); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, tmp_fc, tmp_fc + nCells, tmp_fc_d); + + reactor->unflatten( + box, nCells, rhoY, T, rhoE, frcEExt, fc, tmp_vect_d, + tmp_vect_energy_d, tmp_fc_d, dt); #endif - BL_PROFILE_VAR_STOP(mainflatten); - - delete[] tmp_vect; - delete[] tmp_src_vect; - delete[] tmp_vect_energy; - delete[] tmp_src_vect_energy; - delete[] tmp_fc; - delete[] tmp_mask; + BL_PROFILE_VAR_STOP(mainflatten); + + delete[] tmp_vect; + delete[] tmp_src_vect; + delete[] tmp_vect_energy; + delete[] tmp_src_vect_energy; + delete[] tmp_fc; + delete[] tmp_mask; #ifdef AMREX_USE_GPU - amrex::The_Device_Arena()->free(tmp_vect_d); - amrex::The_Device_Arena()->free(tmp_src_vect_d); - amrex::The_Device_Arena()->free(tmp_vect_energy_d); - amrex::The_Device_Arena()->free(tmp_src_vect_energy_d); - amrex::The_Device_Arena()->free(tmp_fc_d); - amrex::The_Device_Arena()->free(tmp_mask_d); + amrex::The_Device_Arena()->free(tmp_vect_d); + amrex::The_Device_Arena()->free(tmp_src_vect_d); + amrex::The_Device_Arena()->free(tmp_vect_energy_d); + amrex::The_Device_Arena()->free(tmp_src_vect_energy_d); + amrex::The_Device_Arena()->free(tmp_fc_d); + amrex::The_Device_Arena()->free(tmp_mask_d); #endif - } - } - BL_PROFILE_VAR_STOP(Advance); - Real lvl_run_time = ParallelDescriptor::second() - lvl_strt; - ParallelDescriptor::ReduceRealMax(lvl_run_time, ParallelDescriptor::IOProcessorNumber()); - amrex::Print() << " >> Level " << lev << " advance: " << lvl_run_time << "\n"; + } + } + BL_PROFILE_VAR_STOP(Advance); + amrex::Real lvl_run_time = amrex::ParallelDescriptor::second() - lvl_strt; + amrex::ParallelDescriptor::ReduceRealMax( + lvl_run_time, amrex::ParallelDescriptor::IOProcessorNumber()); + amrex::Print() << " >> Level " << lev << " advance: " << lvl_run_time + << "\n"; } // TODO multilevel max. { - Vector typ_vals(NUM_SPECIES+1); - Print() << "ode.typ_vals= "; - for (int i = 0; i < NUM_SPECIES+1; ++i) { - Print() << std::max(1.e-10,mf[0].max(i)) << " "; + amrex::Vector typ_vals(NUM_SPECIES + 1); + amrex::Print() << "ode.typ_vals= "; + for (int i = 0; i < NUM_SPECIES + 1; ++i) { + amrex::Print() << std::max(1.e-10, mf[0].max(i)) << " "; } - Print() << std::endl; + amrex::Print() << std::endl; } if (do_plt) { - BL_PROFILE_VAR_START(PlotFile); - std::string outfile = Concatenate(pltfile,1); - // TODO: add fct count to this output - Vector isteps(finest_level + 1, 0); - Vector refRatios(finest_level, {AMREX_D_DECL(2,2,2)}); - Vector plt_VarsName; - for (int k = 0; k < NUM_SPECIES; ++k) { - plt_VarsName.push_back("SPEC"+std::to_string(k)); - } - plt_VarsName.push_back("TEMP"); + BL_PROFILE_VAR_START(PlotFile); + std::string outfile = amrex::Concatenate(pltfile, 1); + // TODO: add fct count to this output + amrex::Vector isteps(finest_level + 1, 0); + amrex::Vector refRatios( + finest_level, {AMREX_D_DECL(2, 2, 2)}); + amrex::Vector plt_VarsName; + for (int k = 0; k < NUM_SPECIES; ++k) { + plt_VarsName.push_back("SPEC" + std::to_string(k)); + } + plt_VarsName.push_back("TEMP"); - amrex::WriteMultiLevelPlotfile(outfile, finest_level + 1, GetVecOfConstPtrs(mf), - plt_VarsName, geoms, 0.0, isteps, refRatios); - BL_PROFILE_VAR_STOP(PlotFile); + amrex::WriteMultiLevelPlotfile( + outfile, finest_level + 1, GetVecOfConstPtrs(mf), plt_VarsName, geoms, + 0.0, isteps, refRatios); + BL_PROFILE_VAR_STOP(PlotFile); } - + trans_parms.deallocate(); BL_PROFILE_VAR_STOP(pmain); - Real run_time = ParallelDescriptor::second() - strt_time; - ParallelDescriptor::ReduceRealMax(run_time, ParallelDescriptor::IOProcessorNumber()); + amrex::Real run_time = amrex::ParallelDescriptor::second() - strt_time; + amrex::ParallelDescriptor::ReduceRealMax( + run_time, amrex::ParallelDescriptor::IOProcessorNumber()); amrex::Print() << " \n >> React::main() " << run_time << "\n\n"; } - Finalize(); + amrex::Finalize(); return 0; } diff --git a/Testing/Exec/ReactEval_FORTRAN/GNUmakefile b/Testing/Exec/ReactEval_FORTRAN/GNUmakefile deleted file mode 100644 index d4657c352..000000000 --- a/Testing/Exec/ReactEval_FORTRAN/GNUmakefile +++ /dev/null @@ -1,39 +0,0 @@ -PRECISION = DOUBLE -PROFILE = FALSE - -DEBUG = TRUE - -DIM = 2 - -COMP = gcc -FCOMP = gfortran - -USE_MPI = TRUE -USE_OMP = FALSE - -FUEGO_GAS = TRUE - -TINY_PROFILE = FALSE - -# define the location of the PELE_PHYSICS top directory -PELE_PHYSICS_HOME := ../../.. - -#Testing F90 routines -USE_F90_PP = TRUE - -####################### -ifeq ($(FUEGO_GAS), TRUE) - Eos_Model = Fuego - Chemistry_Model = LiDryer - Reactions_dir = Fuego - Transport_Model = Simple -else - Eos_Model = GammaLaw - Reactions_dir = Null - Transport_Model = Constant -endif - -Bpack := ./Make.package -Blocs := . - -include $(PELE_PHYSICS_HOME)/Testing/Exec/Make.PelePhysics diff --git a/Testing/Exec/ReactEval_FORTRAN/Make.package b/Testing/Exec/ReactEval_FORTRAN/Make.package deleted file mode 100644 index 7f8f11be1..000000000 --- a/Testing/Exec/ReactEval_FORTRAN/Make.package +++ /dev/null @@ -1,4 +0,0 @@ -f90EXE_sources += probdata.f90 -F90EXE_sources += main_nd.F90 -CEXE_sources += main.cpp - diff --git a/Testing/Exec/ReactEval_FORTRAN/inputs.2d b/Testing/Exec/ReactEval_FORTRAN/inputs.2d deleted file mode 100644 index e69de29bb..000000000 diff --git a/Testing/Exec/ReactEval_FORTRAN/main.cpp b/Testing/Exec/ReactEval_FORTRAN/main.cpp deleted file mode 100644 index 69611cab9..000000000 --- a/Testing/Exec/ReactEval_FORTRAN/main.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include -#include - -#include -#include -#include -#include - -using namespace amrex; - -#include -#include -#include - -std::string inputs_name = ""; - -using namespace amrex; - -int -main (int argc, - char* argv[]) -{ - Initialize(argc,argv); - { - - ParmParse pp; - - std::string probin_file = "probin"; - pp.query("probin_file",probin_file); - int probin_file_length = probin_file.length(); - std::vector probin_file_name(probin_file_length); - - for (int i = 0; i < probin_file_length; i++) - probin_file_name[i] = probin_file[i]; - - extern_init(&(probin_file_name[0]),&probin_file_length); - -#ifdef _OPENMP -#pragma omp parallel -#endif - extern_init_reactor(); - - - std::vector npts(3,1); - for (int i = 0; i < BL_SPACEDIM; ++i) { - npts[i] = 128; - } - - Box domain(IntVect(D_DECL(0,0,0)), - IntVect(D_DECL(npts[0]-1,npts[1]-1,npts[2]-1))); - - std::vector plo(3,0), phi(3,0), dx(3,1); - for (int i=0; i - -extern "C" -{ - void extern_init - (const int* name, const int* namlen); - - void extern_init_reactor(); - - void extern_close(); - - void get_num_spec(int* nspecies); - - void initialize_data - (const int* lo, const int* hi, - const BL_FORT_FAB_ARG_3D(massfraction), - const BL_FORT_FAB_ARG_3D(temperature), - const BL_FORT_FAB_ARG_3D(eint), - const Real* dx, const Real* plo, const Real* phi); - - void react_state - (const int* lo, const int* hi, - const BL_FORT_FAB_ARG_3D(rYo), - const BL_FORT_FAB_ARG_3D(eo), - const BL_FORT_FAB_ARG_3D(To), - const BL_FORT_FAB_ARG_3D(rYn), - const BL_FORT_FAB_ARG_3D(en), - const BL_FORT_FAB_ARG_3D(Tn), - const BL_FORT_FAB_ARG_3D(rY_src_ext), - const BL_FORT_FAB_ARG_3D(re_src_ext), - const BL_FORT_IFAB_ARG_3D(mask), - const BL_FORT_FAB_ARG_3D(cost), - const Real* time, const Real* dt); -} - -#endif // _main_F_H_ diff --git a/Testing/Exec/ReactEval_FORTRAN/main_nd.F90 b/Testing/Exec/ReactEval_FORTRAN/main_nd.F90 deleted file mode 100644 index 7e280f496..000000000 --- a/Testing/Exec/ReactEval_FORTRAN/main_nd.F90 +++ /dev/null @@ -1,264 +0,0 @@ -module main_module - - use amrex_fort_module, only : amrex_real - - implicit none - -contains - - subroutine extern_init(name,namlen) bind(C, name="extern_init") - - use fuego_chemistry - use eos_module - use transport_module - - implicit none - integer :: namlen - integer :: name(namlen) - - real (kind=amrex_real) :: small_temp = 1.d-200 - real (kind=amrex_real) :: small_dens = 1.d-200 - - ! initialize the external runtime parameters in - ! extern_probin_module - call runtime_init(name,namlen) - - call network_init() - - call eos_init(small_temp, small_dens) - - call transport_init_F() - - end subroutine extern_init - - subroutine extern_init_reactor() bind(C, name="extern_init_reactor") - -#ifdef USE_SUNDIALS_PP - use cvode_module , only : reactor_init - - implicit none - - integer :: ncells(1), iiE(1) - - iiE(1) = 1 - ncells(1) = 1 - - call reactor_init(iiE(1),ncells(1)) -#else - use reactor_module - - implicit none - - call reactor_init(1) -#endif - - - end subroutine extern_init_reactor - - - subroutine extern_close() bind(C, name="extern_close") - - use transport_module - implicit none - - call transport_close_F() - - end subroutine extern_close - - - subroutine get_num_spec(nspecies_out) bind(C, name="get_num_spec") - - use fuego_chemistry, only : nspecies - - implicit none - - integer, intent(out) :: nspecies_out - - nspecies_out = nspecies - - end subroutine get_num_spec - - subroutine initialize_data( & - lo,hi, & - rhoY, rY_lo, rY_hi, & - temperature, t_lo, t_hi, & - eint, e_lo, e_hi, & - dx, plo, phi) & - bind(C, name="initialize_data") - - use amrex_constants_module, only: M_PI, HALF, ONE, TWO, ZERO - use fuego_chemistry, only: nspecies - use eos_type_module - use eos_module - - implicit none - - integer , intent(in ) :: lo(3), hi(3) - integer , intent(in ) :: rY_lo(3), rY_hi(3) - integer , intent(in ) :: t_lo(3), t_hi(3) - integer , intent(in ) :: e_lo(3), e_hi(3) - real(amrex_real), intent(in ) :: dx(3) - real(amrex_real), intent(in ) :: plo(3), phi(3) - real(amrex_real), intent(inout) :: rhoY(rY_lo(1):rY_hi(1),rY_lo(2):rY_hi(2),rY_lo(3):rY_hi(3),nspecies) - real(amrex_real), intent(inout) :: temperature( t_lo(1): t_hi(1), t_lo(2): t_hi(2), t_lo(3): t_hi(3)) - real(amrex_real), intent(inout) :: eint( e_lo(1): e_hi(1), e_lo(2): e_hi(2), e_lo(3): e_hi(3)) - - ! local variables - integer :: i, j, k - real(amrex_real) :: Temp_lo, Temp_hi, dTemp, P(3), L(3), x, y, z, pressure - type(eos_t) :: eos_state - - call build(eos_state) - - Temp_lo = 1500.d0 - Temp_hi = 2000.d0 - dTemp = 5.d0 - - if (nspecies.lt.3) then - stop 'This step assumes that there are at least 3 species' - endif - eos_state%molefrac = 0.d0 - eos_state%molefrac(1) = 0.2d0 - eos_state%molefrac(2) = 0.1d0 - eos_state%molefrac(nspecies) = 1.d0 - eos_state%molefrac(1) - eos_state%molefrac(2) - call eos_xty(eos_state) - - L(:) = phi(:) - plo(:) - P(:) = L(:) / 4 - - pressure = 1013250.d0 - - do k = lo(3),hi(3) - z = plo(3) + (k+HALF)*dx(3) - do j = lo(2),hi(2) - y = plo(2) + (j+HALF)*dx(2) - do i = lo(1),hi(1) - x = plo(1) + (i+HALF)*dx(1) - - eos_state % p = pressure - eos_state % T = Temp_lo + (Temp_hi-Temp_lo)*y/L(2) + dTemp*SIN(TWO*M_PI*y/P(2)) - - eos_state % massfrac(nspecies) = ONE - sum(eos_state % massfrac(1:nspecies-1)) - - call eos_tp(eos_state) - -#ifdef USE_SUNDIALS_PP - eint(i,j,k) = eos_state % e * eos_state % rho -#else - eint(i,j,k) = eos_state % e -#endif - rhoY(i,j,k,1:nspecies) = eos_state % massfrac * eos_state % rho - temperature(i,j,k) = eos_state % T - - end do - end do - end do - - call destroy(eos_state) - - end subroutine initialize_data - - - subroutine react_state(lo,hi, & - mold,mo_lo,mo_hi, & - eold,eo_lo,eo_hi, & - Told,To_lo,To_hi, & - mnew,mn_lo,mn_hi, & - enew,en_lo,en_hi, & - Tnew,Tn_lo,Tn_hi, & - ysrc,ys_lo,ys_hi, & - esrc,es_lo,es_hi, & - mask,m_lo,m_hi, & - cost,c_lo,c_hi, & - time,dt_react) bind(C, name="react_state") - - use fuego_chemistry , only : nspecies -#ifdef USE_SUNDIALS_PP - use cvode_module , only : react -#else - use reactor_module , only : react -#endif - - implicit none - - integer :: lo(3), hi(3) - integer :: mo_lo(3), mo_hi(3) - integer :: eo_lo(3), eo_hi(3) - integer :: To_lo(3), To_hi(3) - integer :: mn_lo(3), mn_hi(3) - integer :: en_lo(3), en_hi(3) - integer :: Tn_lo(3), Tn_hi(3) - integer :: ys_lo(3), ys_hi(3) - integer :: es_lo(3), es_hi(3) - integer :: m_lo(3), m_hi(3) - integer :: c_lo(3), c_hi(3) - real(amrex_real) :: mold(mo_lo(1):mo_hi(1),mo_lo(2):mo_hi(2),mo_lo(3):mo_hi(3),nspecies) - real(amrex_real) :: eold(eo_lo(1):eo_hi(1),eo_lo(2):eo_hi(2),eo_lo(3):eo_hi(3)) - real(amrex_real) :: Told(To_lo(1):To_hi(1),To_lo(2):To_hi(2),To_lo(3):To_hi(3)) - real(amrex_real) :: mnew(mn_lo(1):mn_hi(1),mn_lo(2):mn_hi(2),mn_lo(3):mn_hi(3),nspecies) - real(amrex_real) :: enew(en_lo(1):en_hi(1),en_lo(2):en_hi(2),en_lo(3):en_hi(3)) - real(amrex_real) :: Tnew(Tn_lo(1):Tn_hi(1),Tn_lo(2):Tn_hi(2),Tn_lo(3):Tn_hi(3)) - real(amrex_real) :: ysrc(ys_lo(1):ys_hi(1),ys_lo(2):ys_hi(2),ys_lo(3):ys_hi(3),nspecies) - real(amrex_real) :: esrc(es_lo(1):es_hi(1),es_lo(2):es_hi(2),es_lo(3):es_hi(3)) - integer :: mask(m_lo(1):m_hi(1),m_lo(2):m_hi(2),m_lo(3):m_hi(3)) - real(amrex_real) :: cost(c_lo(1):c_hi(1),c_lo(2):c_hi(2),c_lo(3):c_hi(3)) -#ifdef USE_SUNDIALS_PP - real(amrex_real) :: time, dt_react -#else - real(amrex_real) :: time, dt_react, pressure -#endif - - integer :: i, j, k - - real(amrex_real) :: rY(nspecies+1), rY_src(nspecies) -#ifdef USE_SUNDIALS_PP - real(amrex_real) :: energy(1), energy_src(1) -#else - real(amrex_real) :: energy, energy_src -#endif - - - do k = lo(3), hi(3) - do j = lo(2), hi(2) - do i = lo(1), hi(1) - - if (mask(i,j,k) .eq. 1) then - rY(1:nspecies) = mold(i,j,k,1:nspecies) - rY_src(1:nspecies) = ysrc(i,j,k,1:nspecies) - rY(nspecies+1) = Told(i,j,k) -#ifdef USE_SUNDIALS_PP - energy(1) = eold(i,j,k) - energy_src(1) = esrc(i,j,k) -#else - energy = eold(i,j,k) - energy_src = esrc(i,j,k) - - pressure = 1013250.d0 -#endif - - cost(i,j,k) = react(rY, rY_src,& -#ifdef USE_SUNDIALS_PP - energy(1), energy_src(1),& - dt_react,time) -#else - energy, energy_src,& - pressure,& - dt_react,time) -#endif - -#ifdef USE_SUNDIALS_PP - enew(i,j,k) = energy(1) -#else - enew(i,j,k) = energy -#endif - Tnew(i,j,k) = rY(nspecies+1) - mnew(i,j,k,1:nspecies) = rY(1:nspecies) - end if - - end do - enddo - enddo - - end subroutine react_state - -end module main_module diff --git a/Testing/Exec/ReactEval_FORTRAN/probdata.f90 b/Testing/Exec/ReactEval_FORTRAN/probdata.f90 deleted file mode 100644 index e4f320a0a..000000000 --- a/Testing/Exec/ReactEval_FORTRAN/probdata.f90 +++ /dev/null @@ -1,10 +0,0 @@ -module probdata_module - - use amrex_fort_module, only : amrex_real - implicit none - - real(amrex_real), save :: thermal_conductivity, diff_coeff - real(amrex_real), save :: T1, T2, rho0 - real(amrex_real), save :: t_0 - -end module probdata_module diff --git a/Testing/Exec/ReactEval_FORTRAN/probin b/Testing/Exec/ReactEval_FORTRAN/probin deleted file mode 100644 index 0bd1fe516..000000000 --- a/Testing/Exec/ReactEval_FORTRAN/probin +++ /dev/null @@ -1,3 +0,0 @@ -&extern - new_Jacobian_each_cell = 1 -/ diff --git a/Testing/Exec/TranEval/GNUmakefile b/Testing/Exec/TranEval/GNUmakefile index 752bdd716..4a4f7bb53 100644 --- a/Testing/Exec/TranEval/GNUmakefile +++ b/Testing/Exec/TranEval/GNUmakefile @@ -6,28 +6,42 @@ VERBOSE = FALSE DEBUG = FALSE # Compiler -COMP = gnu -FCOMP = gfortran -USE_MPI = TRUE +COMP = gnu +FCOMP = gfortran +USE_MPI = FALSE USE_OMP = FALSE USE_CUDA = FALSE USE_HIP = FALSE # PelePhysics FUEGO_GAS = TRUE -USE_SUNDIALS_PP = FALSE -USE_RK64_PP = FALSE +TINY_PROFILE = FALSE + +# define the location of the PELE_PHYSICS top directory +PELE_PHYSICS_HOME ?= ../../.. + +# this flag activates the subcycling mode in the D/Cvode routines +DEFINES += -DMOD_REACTOR + +# Activates use of SUNDIALS +ifeq ($(USE_CUDA), TRUE) + PELE_USE_KLU = FALSE +else + ifeq ($(USE_HIP), TRUE) + PELE_USE_KLU = FALSE + else + PELE_USE_KLU = FALSE + endif +endif ifeq ($(FUEGO_GAS), TRUE) Eos_Model = Fuego Chemistry_Model = air - Reactions_dir = null Transport_Model = Simple else Eos_Model = GammaLaw Chemistry_Model = Null - Reactions_dir = null - Transport_Mode = Constant + Transport_Model = Constant endif Bpack := ./Make.package diff --git a/Testing/Exec/TranEval/main.cpp b/Testing/Exec/TranEval/main.cpp index cb86fece7..171cacda0 100644 --- a/Testing/Exec/TranEval/main.cpp +++ b/Testing/Exec/TranEval/main.cpp @@ -4,137 +4,135 @@ #include #include #include +#include -#include #include "mechanism.H" #include #include -using namespace amrex; - int -main (int argc, - char* argv[]) +main(int argc, char* argv[]) { - Initialize(argc,argv); - { + amrex::Initialize(argc, argv); + { + + amrex::ParmParse pp; - ParmParse pp; + pele::physics::transport::TransportParams< + pele::physics::PhysicsType::transport_type> + trans_parms; + trans_parms.allocate(); - pele::physics::transport::TransportParams trans_parms; - trans_parms.allocate(); - - // Define geometry - Array npts {AMREX_D_DECL(1,1,1)};; - for (int i = 0; i < AMREX_SPACEDIM; ++i) { - npts[i] = 128; - } - - Box domain(IntVect(AMREX_D_DECL(0,0,0)), - IntVect(AMREX_D_DECL(npts[0]-1,npts[1]-1,npts[2]-1))); + // Define geometry + amrex::Array npts{AMREX_D_DECL(1, 1, 1)}; + for (int i = 0; i < AMREX_SPACEDIM; ++i) { + npts[i] = 128; + } - RealBox real_box({AMREX_D_DECL(-1.0,-1.0,-1.0)}, - {AMREX_D_DECL( 1.0, 1.0, 1.0)}); + amrex::Box domain( + amrex::IntVect(AMREX_D_DECL(0, 0, 0)), + amrex::IntVect(AMREX_D_DECL(npts[0] - 1, npts[1] - 1, npts[2] - 1))); - int coord = 0; + amrex::RealBox real_box( + {AMREX_D_DECL(-1.0, -1.0, -1.0)}, {AMREX_D_DECL(1.0, 1.0, 1.0)}); - Array is_periodic {AMREX_D_DECL(1,1,1)}; + int coord = 0; - Geometry geom(domain, real_box, coord, is_periodic); + amrex::Array is_periodic{AMREX_D_DECL(1, 1, 1)}; - // Define BoxArray - int max_size = 32; - pp.query("max_size",max_size); - BoxArray ba(domain); - ba.maxSize(max_size); + amrex::Geometry geom(domain, real_box, coord, is_periodic); - ParmParse ppa("amr"); - std::string pltfile("plt"); - ppa.query("plot_file",pltfile); + // Define BoxArray + int max_size = 32; + pp.query("max_size", max_size); + amrex::BoxArray ba(domain); + ba.maxSize(max_size); - DistributionMapping dm{ba}; - int num_grow = 0; + amrex::ParmParse ppa("amr"); + std::string pltfile("plt"); + ppa.query("plot_file", pltfile); - // Data MFs - MultiFab mass_frac(ba,dm,NUM_SPECIES,num_grow); - MultiFab temperature(ba,dm,1,num_grow); - MultiFab density(ba,dm,1,num_grow); + amrex::DistributionMapping dm{ba}; + int num_grow = 0; - IntVect tilesize(AMREX_D_DECL(10240,8,32)); + // Data MFs + amrex::MultiFab mass_frac(ba, dm, NUM_SPECIES, num_grow); + amrex::MultiFab temperature(ba, dm, 1, num_grow); + amrex::MultiFab density(ba, dm, 1, num_grow); + + const auto geomdata = geom.data(); - const auto geomdata = geom.data(); - #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mass_frac,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { - - const Box& bx = mfi.tilebox(); + for (amrex::MFIter mfi(mass_frac, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { - auto const& Y_a = mass_frac.array(mfi); - auto const& T_a = temperature.array(mfi); - auto const& rho_a = density.array(mfi); + const amrex::Box& bx = mfi.tilebox(); - amrex::ParallelFor(bx, [Y_a, T_a, rho_a, geomdata] - AMREX_GPU_DEVICE (int i, int j, int k) noexcept { - initialize_data(i, j, k, Y_a, T_a, rho_a, geomdata); - }); + auto const& Y_a = mass_frac.array(mfi); + auto const& T_a = temperature.array(mfi); + auto const& rho_a = density.array(mfi); - } - - // Plot init state for debug purposes - //MultiFab VarPltInit(ba,dm,NUM_SPECIES+2,num_grow); - //MultiFab::Copy(VarPltInit,mass_frac,0,0,NUM_SPECIES,num_grow); - //MultiFab::Copy(VarPltInit,temperature,0,NUM_SPECIES,1,num_grow); - //MultiFab::Copy(VarPltInit,density,0,NUM_SPECIES+1,1,num_grow); - //std::string initfile = amrex::Concatenate(pltfile,99); // Need a number other than zero for reg test to pass - //PlotFileFromMF(VarPltInit,initfile); + amrex::ParallelFor( + bx, [Y_a, T_a, rho_a, + geomdata] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + initialize_data(i, j, k, Y_a, T_a, rho_a, geomdata); + }); + } - MultiFab D(ba,dm,NUM_SPECIES,num_grow); - MultiFab mu(ba,dm,1,num_grow); - MultiFab xi(ba,dm,1,num_grow); - MultiFab lam(ba,dm,1,num_grow); + amrex::MultiFab D(ba, dm, NUM_SPECIES, num_grow); + amrex::MultiFab mu(ba, dm, 1, num_grow); + amrex::MultiFab xi(ba, dm, 1, num_grow); + amrex::MultiFab lam(ba, dm, 1, num_grow); - // Get the transport data pointer - auto const* ltransparm = trans_parms.device_trans_parm(); + // Get the transport data pointer + auto const* ltransparm = trans_parms.device_trans_parm(); #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif - for (MFIter mfi(mass_frac,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { - - const Box& gbox = mfi.tilebox(); - - Array4 const& Y_a = mass_frac.array(mfi); - Array4 const& T_a = temperature.array(mfi); - Array4 const& rho_a = density.array(mfi); - Array4 const& D_a = D.array(mfi); - Array4 const& mu_a = mu.array(mfi); - Array4 const& xi_a = xi.array(mfi); - Array4 const& lam_a = lam.array(mfi); - - amrex::launch(gbox, [=] AMREX_GPU_DEVICE(amrex::Box const& tbx) { - auto trans = pele::physics::PhysicsType::transport(); - trans.get_transport_coeffs(tbx, - Y_a, T_a, rho_a, - D_a, mu_a, xi_a, lam_a, ltransparm); - }); - } - - trans_parms.deallocate(); - - MultiFab VarPlt(ba,dm,NUM_SPECIES+3,num_grow); - MultiFab::Copy(VarPlt,D,0,0,NUM_SPECIES,num_grow); - MultiFab::Copy(VarPlt,mu,0,NUM_SPECIES,1,num_grow); - MultiFab::Copy(VarPlt,xi,0,NUM_SPECIES+1,1,num_grow); - MultiFab::Copy(VarPlt,lam,0,NUM_SPECIES+2,1,num_grow); - - std::string outfile = amrex::Concatenate(pltfile,1); // Need a number other than zero for reg test to pass - PlotFileFromMF(VarPlt,outfile); + for (amrex::MFIter mfi(mass_frac, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + + const amrex::Box& gbox = mfi.tilebox(); + + amrex::Array4 const& Y_a = mass_frac.array(mfi); + amrex::Array4 const& T_a = temperature.array(mfi); + amrex::Array4 const& rho_a = density.array(mfi); + amrex::Array4 const& D_a = D.array(mfi); + amrex::Array4 const& mu_a = mu.array(mfi); + amrex::Array4 const& xi_a = xi.array(mfi); + amrex::Array4 const& lam_a = lam.array(mfi); + + amrex::launch(gbox, [=] AMREX_GPU_DEVICE(amrex::Box const& tbx) { + auto trans = pele::physics::PhysicsType::transport(); + trans.get_transport_coeffs( + tbx, Y_a, T_a, rho_a, D_a, mu_a, xi_a, lam_a, ltransparm); + }); + } + + trans_parms.deallocate(); + + amrex::MultiFab VarPlt(ba, dm, NUM_SPECIES + 3, num_grow); + amrex::MultiFab::Copy(VarPlt, D, 0, 0, NUM_SPECIES, num_grow); + amrex::MultiFab::Copy(VarPlt, mu, 0, NUM_SPECIES, 1, num_grow); + amrex::MultiFab::Copy(VarPlt, xi, 0, NUM_SPECIES + 1, 1, num_grow); + amrex::MultiFab::Copy(VarPlt, lam, 0, NUM_SPECIES + 2, 1, num_grow); + std::string outfile = amrex::Concatenate(pltfile, 1); + amrex::Vector plt_VarsName; + for (int k = 0; k < NUM_SPECIES; ++k) { + plt_VarsName.push_back("D" + std::to_string(k)); } + plt_VarsName.push_back("mu"); + plt_VarsName.push_back("xi"); + plt_VarsName.push_back("lam"); + amrex::WriteSingleLevelPlotfile( + outfile, VarPlt, plt_VarsName, geom, 0.0, 0); + } - amrex::Finalize(); + amrex::Finalize(); - return 0; + return 0; } diff --git a/Testing/Regression/PelePhysics-tests.ini b/Testing/Regression/PelePhysics-tests.ini index 23fc19fce..c7e989c19 100644 --- a/Testing/Regression/PelePhysics-tests.ini +++ b/Testing/Regression/PelePhysics-tests.ini @@ -118,7 +118,7 @@ numprocs = 2 useOMP = 0 compileTest = 0 doVis = 0 -addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=Simple USE_SUNDIALS_PP=FALSE +addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=Simple runtime_params = probin_file=probin [ReactEval-3d-Simple-DRM-OMP-F] @@ -133,7 +133,7 @@ useOMP = 1 numthreads = 4 compileTest = 0 doVis = 0 -addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=Simple USE_SUNDIALS_PP=FALSE +addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=Simple runtime_params = probin_file=probin [ReactEval-3d-EGLib-DRM-F] @@ -147,7 +147,7 @@ numprocs = 2 useOMP = 0 compileTest = 0 doVis = 0 -addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=EGLib USE_SUNDIALS_PP=FALSE +addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=EGLib runtime_params = probin_file=probin #CPP @@ -161,7 +161,7 @@ numprocs = 2 useOMP = 0 compileTest = 0 doVis = 0 -addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=Simple USE_SUNDIALS_PP=TRUE USE_KLU_PP=FALSE +addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=Simple PELE_USE_KLU=FALSE [ReactEval-3d-Simple-DRM-OMP] buildDir = Testing/Exec/ReactEval_C/ @@ -174,4 +174,4 @@ useOMP = 1 numthreads = 4 compileTest = 0 doVis = 0 -addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=Simple USE_SUNDIALS_PP=TRUE USE_KLU_PP=FALSE +addToCompileString = Chemistry_Model=drm19 Eos_Model=Fuego Reactions_dir=Fuego Transport_Model=Simple PELE_USE_KLU=FALSE diff --git a/Testing/Source/Make.package b/Testing/Source/Make.package deleted file mode 100644 index 2cf39636f..000000000 --- a/Testing/Source/Make.package +++ /dev/null @@ -1,5 +0,0 @@ -CEXE_sources += WritePlotFile.cpp -CEXE_sources += PlotFileFromMF.cpp - -CEXE_headers += WritePlotFile.H -CEXE_headers += PlotFileFromMF.H diff --git a/Testing/Source/PlotFileFromMF.H b/Testing/Source/PlotFileFromMF.H deleted file mode 100644 index c6c77f12e..000000000 --- a/Testing/Source/PlotFileFromMF.H +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _PlotFileFromMF_ -#define _PlotFileFromMF_ -#include -#include - -void PlotFileFromMF(const amrex::MultiFab& mf, - const std::string& oFile); - -#endif // _PlotFileFromMF_ diff --git a/Testing/Source/PlotFileFromMF.cpp b/Testing/Source/PlotFileFromMF.cpp deleted file mode 100644 index 6e75fed7f..000000000 --- a/Testing/Source/PlotFileFromMF.cpp +++ /dev/null @@ -1,29 +0,0 @@ - -#include -#include - -using namespace amrex; - -void PlotFileFromMF(const amrex::MultiFab& mf, - const std::string& oFile) -{ - const std::string pfversion = "HyperCLaw-V1.1"; - Vector data(1); - data[0] = &mf; - Real time = 0; - const Box dbox = mf.boxArray().minimalBox(); - Vector probDomain(1,dbox); - Vector probLo(BL_SPACEDIM,0), probHi(BL_SPACEDIM,0); - for (int d=0; d refRatio(0); - Vector > dxLevel(1, Vector(BL_SPACEDIM, 1)); - int coordSys = 0; - Vector names(mf.nComp()); - for (int i=0; i -#include -#include -#include -#include -#include - - -void WritePlotfile(const std::string &pfversion, - const amrex::Vector &data, - const amrex::Real time, - const amrex::Vector &probLo, - const amrex::Vector &probHi, - const amrex::Vector &refRatio, - const amrex::Vector &probDomain, - const amrex::Vector > &dxLevel, - const int coordSys, - const std::string &oFile, - const amrex::Vector &names, - const bool verbose, - const bool isCartGrid = false, - const amrex::Real *vfeps = 0, - const int *levelSteps = 0); - - -#endif -// -------------------------------------------------------------------- diff --git a/Testing/Source/WritePlotFile.cpp b/Testing/Source/WritePlotFile.cpp deleted file mode 100644 index e0c222f2b..000000000 --- a/Testing/Source/WritePlotFile.cpp +++ /dev/null @@ -1,325 +0,0 @@ -// -------------------------------------------------------------------- -// WritePlotFile.cpp -// -------------------------------------------------------------------- -#include -#include -#include -#include -#include -#include - -#include - -using namespace amrex; - -// -------------------------------------------------------------------- -void WritePlotfile(const std::string &pfversion, - const amrex::Vector &data, - const amrex::Real time, - const amrex::Vector &probLo, - const amrex::Vector &probHi, - const amrex::Vector &refRatio, - const amrex::Vector &probDomain, - const amrex::Vector > &dxLevel, - const int coordSys, - const std::string &oFile, - const amrex::Vector &names, - const bool verbose, - const bool isCartGrid, - const amrex::Real *vfeps, - const int *levelSteps) -{ - if(ParallelDescriptor::IOProcessor()) { - if( ! UtilCreateDirectory(oFile,0755)) { - CreateDirectoryFailed(oFile); - } - } - // - // Force other processors to wait till directory is built. - // - ParallelDescriptor::Barrier(); - - std::string oFileHeader(oFile); - oFileHeader += "/Header"; - - VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size); - - std::ofstream os; - - //os.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size()); - - if(verbose && ParallelDescriptor::IOProcessor()) { - std::cout << "Opening file = " << oFileHeader << '\n'; - } - - os.open(oFileHeader.c_str(), std::ios::out|std::ios::binary); - - if(os.fail()) { - amrex::FileOpenFailed(oFileHeader); - } - // - // Start writing plotfile. - // - os << pfversion << '\n'; - int n_var = data[0]->nComp(); - os << n_var << '\n'; - for (int n = 0; n < n_var; n++) os << names[n] << '\n'; - os << BL_SPACEDIM << '\n'; - os << std::setprecision(30) << time << '\n'; - const int finestLevel = data.size() - 1; - os << finestLevel << '\n'; - for (int i = 0; i < BL_SPACEDIM; i++) os << probLo[i] << ' '; - os << '\n'; - for (int i = 0; i < BL_SPACEDIM; i++) os << probHi[i] << ' '; - os << '\n'; - for (int i = 0; i < finestLevel; i++) os << refRatio[i] << ' '; - os << '\n'; - for (int i = 0; i <= finestLevel; i++) os << probDomain[i] << ' '; - os << '\n'; - if(levelSteps != 0) { - for (int i = 0; i <= finestLevel; i++) os << levelSteps[i] << ' '; - } else { - for (int i = 0; i <= finestLevel; i++) os << 0 << ' '; - } - os << '\n'; - for(int i = 0; i <= finestLevel; i++) { - for(int k = 0; k < BL_SPACEDIM; k++) { - os << dxLevel[i][k] << ' '; - } - os << '\n'; - } - if(isCartGrid) { - for(int i(0); i <= finestLevel; i++) { - os << vfeps[i] << ' '; - } - os << '\n'; - } - os << coordSys << '\n'; - os << 0 << '\n'; // --------------- The bndry data width. - // - // Write out level by level. - // - for(int iLevel(0); iLevel <= finestLevel; ++iLevel) { - // - // Write state data. - // - const BoxArray &ba = data[iLevel]->boxArray(); - int nGrids = ba.size(); - char buf[64]; - sprintf(buf, "Level_%d", iLevel); - - if(ParallelDescriptor::IOProcessor()) { - os << iLevel << ' ' << nGrids << ' ' << time << '\n'; - if(levelSteps != 0) { - os << levelSteps[iLevel] << '\n'; - } else { - os << 0 << '\n'; - } - - for(int i(0); i < nGrids; ++i) { - const Box &b = ba[i]; - for(int n(0); n < BL_SPACEDIM; ++n) { - Real glo = b.smallEnd()[n] * dxLevel[iLevel][n]; - Real ghi = (b.bigEnd()[n]+1) * dxLevel[iLevel][n]; - os << glo << ' ' << ghi << '\n'; - } - } - // - // Build the directory to hold the MultiFabs at this level. - // - std::string Level(oFile); - Level += '/'; - Level += buf; - - if( ! amrex::UtilCreateDirectory(Level, 0755)) { - amrex::CreateDirectoryFailed(Level); - } - } - // - // Force other processors to wait till directory is built. - // - ParallelDescriptor::Barrier(); - // - // Now build the full relative pathname of the MultiFab. - // - static const std::string MultiFabBaseName("MultiFab"); - - std::string PathName(oFile); - PathName += '/'; - PathName += buf; - PathName += '/'; - PathName += MultiFabBaseName; - - if(ParallelDescriptor::IOProcessor()) { - // - // The full name relative to the Header file. - // - std::string RelativePathName(buf); - RelativePathName += '/'; - RelativePathName += MultiFabBaseName; - os << RelativePathName << '\n'; - } - VisMF::Write(*data[iLevel], PathName); - } - - os.close(); -} - - - -// -------------------------------------------------------------------- -std::string VisMFBaseName(const std::string& filename) { - BL_ASSERT(filename[filename.length() - 1] != '/'); - if(const char *slash = strrchr(filename.c_str(), '/')) { - return std::string(slash + 1); - } else { - return filename; - } -} - - -// -------------------------------------------------------------------- -void Write2DBoxFrom3D(const Box &box, std::ostream &os, int whichPlane) { - os << '('; - switch(whichPlane) { - case 0: - os << '(' << box.smallEnd(1) << ',' << box.smallEnd(2) << ')' << ' ' - << '(' << box.bigEnd(1) << ',' << box.bigEnd(2) << ')' << ' ' - << '(' << box.type(1) << ',' << box.type(2) << ')'; - break; - - case 1: - os << '(' << box.smallEnd(0) << ',' << box.smallEnd(2) << ')' << ' ' - << '(' << box.bigEnd(0) << ',' << box.bigEnd(2) << ')' << ' ' - << '(' << box.type(0) << ',' << box.type(2) << ')'; - break; - - case 2: - os << '(' << box.smallEnd(0) << ',' << box.smallEnd(1) << ')' << ' ' - << '(' << box.bigEnd(0) << ',' << box.bigEnd(1) << ')' << ' ' - << '(' << box.type(0) << ',' << box.type(1) << ')'; - break; - - case 3: // for testing - os << '(' << box.smallEnd(0) << ',' << box.smallEnd(1) << ',' << box.smallEnd(2) << ')' << ' ' - << '(' << box.bigEnd(0) << ',' << box.bigEnd(1) << ',' << box.bigEnd(2) << ')' << ' ' - << '(' << box.type(0) << ',' << box.type(1) << ',' << box.type(2) << ')'; - break; - } - os << ')'; - -} - - -#include -#include -// -------------------------------------------------------------------- -VisMF::FabOnDisk VisMFWrite(const FArrayBox &fabIn, const std::string &filename, - std::ostream &os, long &bytes, int whichPlane) -{ - FArrayBox fab; - if(fabIn.box().length(whichPlane) > 1) { - Box b(fabIn.box()); - b.setBig(whichPlane, b.smallEnd(whichPlane)); - fab.resize(b, fabIn.nComp()); - } else { - fab.resize(fabIn.box(), fabIn.nComp()); - } - fab.copy(fabIn); - - - VisMF::FabOnDisk fab_on_disk(filename, VisMF::FileOffset(os)); -// ==================== - //fab.writeOn(os); - // ==================== - //fabio->write_header(os, *this, num_comp); - //os << "FAB " << *rd; - //os << fab.box() << ' ' << fab.nComp() << '\n'; - // ==================== - - // ==================== - //fabio->write(os, *this, 0, fab.nComp()); - const long base_siz = fab.box().numPts(); - const Real *comp_ptr = fab.dataPtr(0); - const long siz = base_siz*fab.nComp(); - const int *ord = FPC::reverse_double_order; - RealDescriptor *rd = new RealDescriptor(FPC::ieee_double, ord, 8); - os << "FAB " << *rd; - //os << fab.box(); - Write2DBoxFrom3D(fab.box(), os, whichPlane); - os << ' ' << fab.nComp() << '\n'; - RealDescriptor::convertFromNativeFormat(os, siz, comp_ptr, *rd); - //os.write((char *) comp_ptr, siz*sizeof(double)); - // ==================== -// ==================== - bytes += (VisMF::FileOffset(os) - fab_on_disk.m_head); - return fab_on_disk; -} - - -// -------------------------------------------------------------------- -static std::ostream &operator<<(std::ostream &os, - const Vector< Vector > &ar) -{ - long i = 0, N = ar.size(), M = (N == 0) ? 0 : ar[0].size(); - os << N << ',' << M << '\n'; - for( ; i < N; i++) { - BL_ASSERT(ar[i].size() == M); - for(long j = 0; j < M; j++) { - os << ar[i][j] << ','; - } - os << '\n'; - } - if( ! os.good()) { - amrex::Error("Write of Vector> failed"); - } - return os; -} - - -// -------------------------------------------------------------------- -long VisMFWriteHeader(const std::string &mf_name, VisMF::Header &hdr, - int whichPlane) -{ - long bytes(0); - std::string MFHdrFileName(mf_name); - MFHdrFileName += "_H"; - VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size); - std::ofstream MFHdrFile; - MFHdrFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size()); - MFHdrFile.open(MFHdrFileName.c_str(), std::ios::out|std::ios::trunc); - if( ! MFHdrFile.good()) { - amrex::FileOpenFailed(MFHdrFileName); - } - // =============================== - //MFHdrFile << hdr; - std::ios::fmtflags oflags = MFHdrFile.flags(); - MFHdrFile.setf(std::ios::floatfield, std::ios::scientific); - int old_prec = MFHdrFile.precision(15); - - MFHdrFile << hdr.m_vers << '\n'; - MFHdrFile << int(hdr.m_how) << '\n'; - MFHdrFile << hdr.m_ncomp << '\n'; - MFHdrFile << hdr.m_ngrow << '\n'; ; - - //hdr.m_ba.writeOn(MFHdrFile); MFHdrFile << '\n'; - MFHdrFile << '(' << hdr.m_ba.size() << ' ' << 0 << '\n'; - - for(int i(0); i < hdr.m_ba.size(); ++i) { - Write2DBoxFrom3D(hdr.m_ba[i], MFHdrFile, whichPlane); - MFHdrFile << '\n'; - } - - MFHdrFile << ')' << '\n'; - - - MFHdrFile << hdr.m_fod << '\n'; - MFHdrFile << hdr.m_min << '\n'; - MFHdrFile << hdr.m_max << '\n'; - - // =============================== - bytes += VisMF::FileOffset(MFHdrFile); - MFHdrFile.close(); - return bytes; -} - diff --git a/Testing/Source/extern_probin.template b/Testing/Source/extern_probin.template deleted file mode 100644 index bf2a2f1ab..000000000 --- a/Testing/Source/extern_probin.template +++ /dev/null @@ -1,67 +0,0 @@ -! This module stores the runtime parameters. The probin_init() routine is -! used to initialize the runtime parameters - -module extern_probin_module - - use amrex_fort_module, only : rt=>amrex_real, dim=>amrex_spacedim - - implicit none - - private - - @@declarationsA@@ - -end module extern_probin_module - -subroutine runtime_init(name,namlen) - - use extern_probin_module - - implicit none - - integer :: namlen - integer :: name(namlen) - - integer :: un, i, status - - integer, parameter :: maxlen = 256 - character (len=maxlen) :: probin - - - @@namelist@@ - - @@defaults@@ - - - ! create the filename - if (namlen > maxlen) then - print *, 'probin file name too long' - stop - endif - - do i = 1, namlen - probin(i:i) = char(name(i)) - end do - - - ! read in the namelist - un = 9 - open (unit=un, file=probin(1:namlen), form='formatted', status='old') - read (unit=un, nml=extern, iostat=status) - - if (status < 0) then - ! the namelist does not exist, so we just go with the defaults - continue - - else if (status > 0) then - ! some problem in the namelist - print *, 'ERROR: problem in the extern namelist' - stop - endif - - close (unit=un) - - @@acc@@ - -end subroutine runtime_init - diff --git a/ThirdParty/GNUmakefile b/ThirdParty/GNUmakefile index ed4bc1913..76fdf86f7 100644 --- a/ThirdParty/GNUmakefile +++ b/ThirdParty/GNUmakefile @@ -1,14 +1,9 @@ -# -# Build configuration -# - COMP ?= gcc DEBUG ?= FALSE USE_CUDA ?= FALSE -USE_KLU_PP ?= FALSE +PELE_USE_KLU ?= FALSE CUDA_ARCH ?= 70 -#SS_VERSION=5.7.2 SS_VERSION=5.4.0 include $(AMREX_HOME)/Tools/GNUMake/Make.defs @@ -17,21 +12,27 @@ lowercase_hcomp = $(shell echo $(COMP) | tr A-Z a-z) ifeq ($(lowercase_hcomp),$(filter $(lowercase_hcomp),gcc gnu g++ mpicc mpicxx)) ifeq ($(lowercase_hcomp),$(filter $(lowercase_hcomp),mpi)) CCOMPILER = $(shell $(COMP) --show | awk '{print $$1}') + CXXCOMPILER = $(shell $(COMP) --show | awk '{print $$1}') else CCOMPILER = gcc + CXXCOMPILER = g++ endif else ifeq ($(lowercase_hcomp),$(filter $(lowercase_hcomp),intel)) CCOMPILER = icc + CXXCOMPILER = icpc else ifeq ($(lowercase_hcomp),$(filter $(lowercase_hcomp),pgi)) CCOMPILER = pgicc + CXXCOMPILER = pgiCC else ifeq ($(lowercase_hcomp),$(filter $(lowercase_hcomp),llvm)) CCOMPILER = clang + CXXCOMPILER = clang++ else ifeq ($(lowercase_hcomp),$(filter $(lowercase_hcomp),hip)) CCOMPILER = hipcc + CXXCOMPILER = hipcc else $(error Unknown COMP setting) endif @@ -40,26 +41,10 @@ else endif endif -ifeq ($(USE_MPI),TRUE) - ifeq ($(CCOMPILER),$(filter $(CCOMPILER),mpi)) - HOST_COMPILER = $(shell $(CCOMPILER) --show | awk '{print $$1}') - else - HOST_COMPILER = $(CCOMPILER) - endif -else - HOST_COMPILER = $(CCOMPILER) -endif - -ifeq ($(USE_CUDA),TRUE) - DEV_COMPILER = nvcc -else - DEV_COMPILER = $(HOST_COMPILER) -endif - -tp_suffix=$(COMP)$(DebugSuffix)$(CUDASuffix)$(KLUSuffix) +tp_suffix=$(COMP)$(DebugSuffix)$(CUDASuffix)$(HIPSuffix)$(KLUSuffix) INSTALL_PREFIX=$(PWD)/INSTALL/$(tp_suffix) -ifeq ($(USE_KLU_PP),TRUE) +ifeq ($(PELE_USE_KLU),TRUE) KLUSuffix := .KLU KLU_DEFINES=-DENABLE_KLU:BOOL=ON -DKLU_INCLUDE_DIR=${INSTALL_PREFIX}/include -DKLU_LIBRARY_DIR=${INSTALL_PREFIX}/lib SS_BUILD_PREFIX=$(PWD)/BUILD/SUITESPARSE @@ -80,7 +65,6 @@ endif ifeq ($(DEBUG),FALSE) BUILD_TYPE=Release - COMP_FLAGS="-O3 -DNDEBUG" DebugSuffix= else BUILD_TYPE=Debug @@ -88,7 +72,7 @@ else endif ifeq ($(USE_CUDA),TRUE) - CUDA_DEFINES=-DENABLE_CUDA:BOOL=ON -DCUDA_HOST_COMPILER=$(HOST_COMPILER) -DCMAKE_CUDA_ARCHITECTURES:STRING=$(CUDA_ARCH) + CUDA_DEFINES=-DENABLE_CUDA:BOOL=ON -DCMAKE_CUDA_ARCHITECTURES:STRING=$(CUDA_ARCH) -DCMAKE_CUDA_COMPILER:STRING=nvcc -DCMAKE_CUDA_HOST_COMPILER:STRING=$(CXXCOMPILER) CUDASuffix=.CUDA else CUDA_DEFINES=-DENABLE_CUDA:BOOL=OFF @@ -108,7 +92,7 @@ SUNDIALS_BUILD_DIR=$(SUNDIALS_BUILD_PREFIX)/build/$(tp_suffix) ONE_SUNDIALS_SRC_FILE=$(SUNDIALS_SOURCE_DIR)/include/sundials/sundials_config.in ONE_SUNDIALS_LIB_FILE=$(INSTALL_PREFIX)/lib/libsundials_cvode.a -all: $(ONE_SUNDIALS_LIB_FILE) +sundials: $(ONE_SUNDIALS_LIB_FILE) tp_suffix: @echo $(tp_suffix) @@ -118,10 +102,10 @@ $(ONE_SUNDIALS_LIB_FILE): $(ONE_SUNDIALS_SRC_FILE) $(ONE_SS_LIB_FILE) @mkdir -p $(SUNDIALS_BUILD_DIR) cd $(SUNDIALS_BUILD_DIR); cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON -DCMAKE_INSTALL_PREFIX:STRING=$(INSTALL_PREFIX) \ -DCMAKE_INSTALL_LIBDIR:STRING=$(INSTALL_PREFIX)/lib -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ - -DCMAKE_C_COMPILER:STRING=$(HOST_COMPILER) -DCMAKE_CXX_COMPILER:STRING=$(HOST_COMPILER) \ - $(CUDA_HOST_COMP_DEFINE) -DEXAMPLES_INSTALL_PATH:STRING=$(INSTALL_PREFIX)/examples \ - -DCMAKE_BUILD_TYPE:STRING=$(BUILD_TYPE) -DCMAKE_C_FLAGS_RELEASE:STRING=$(COMP_FLAGS) \ - $(CUDA_DEFINES) $(HIP_DEFINES) -DENABLE_MPI:BOOL=OFF -DENABLE_OPENMP:BOOL=OFF $(KLU_DEFINES) \ + -DCMAKE_C_COMPILER:STRING=$(CCOMPILER) -DCMAKE_CXX_COMPILER:STRING=$(CXXCOMPILER) \ + -DEXAMPLES_INSTALL_PATH:STRING=$(INSTALL_PREFIX)/examples \ + -DCMAKE_BUILD_TYPE:STRING=$(BUILD_TYPE) $(CUDA_DEFINES) $(HIP_DEFINES) \ + -DENABLE_MPI:BOOL=OFF -DENABLE_OPENMP:BOOL=OFF $(KLU_DEFINES) \ -DEXAMPLES_ENABLE_C:BOOL=OFF -DEXAMPLES_ENABLE_CXX:BOOL=OFF -DEXAMPLES_ENABLE_CUDA:BOOL=OFF \ -DBUILD_CVODES:BOOL=OFF -DBUILD_IDA:BOOL=OFF -DBUILD_IDAS:BOOL=OFF -DBUILD_KINSOL:BOOL=OFF \ -DSUNDIALS_INDEX_SIZE:INT=32 -DSUNDIALS_RAJA_BACKENDS:STRING=CUDA $(SUNDIALS_SOURCE_DIR); \ @@ -152,7 +136,7 @@ $(SS_DIST_DIR)/$(SS_DIST_FILE): @mkdir -p $(SS_DIST_DIR) @cd $(SS_DIST_DIR); wget https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/$(SS_DIST_FILE) -ifeq ($(USE_KLU_PP),TRUE) +ifeq ($(PELE_USE_KLU),TRUE) clean_SS: @echo rm -rf $(SS_BUILD_PREFIX) else diff --git a/ThirdParty/Make.ThirdParty b/ThirdParty/Make.ThirdParty index 13d327174..25ad9b0c7 100644 --- a/ThirdParty/Make.ThirdParty +++ b/ThirdParty/Make.ThirdParty @@ -1,46 +1,37 @@ -ifeq ($(USE_SUNDIALS_PP),TRUE) - DEFINES += -DUSE_SUNDIALS_PP - ifeq ($(USE_CUDA),TRUE) - ifeq ($(lowercase_nvcc_host_comp),$(filter $(lowercase_nvcc_host_comp),gcc gnu g++)) - HOSTCC = gcc - else - HOSTCC = pgi - endif +ifeq ($(USE_CUDA),TRUE) + ifeq ($(lowercase_nvcc_host_comp),$(filter $(lowercase_nvcc_host_comp),gcc gnu g++)) + HOSTCC = gcc else - HOSTCC = $(COMP) + HOSTCC = pgi endif - configSpecificTPSuffix=$(shell cd $(PELE_PHYSICS_HOME)/ThirdParty; make tp_suffix AMREX_HOME=$(AMREX_HOME) USE_CUDA=$(USE_CUDA) USE_HIP=$(USE_HIP) USE_KLU_PP=$(USE_KLU_PP) DEBUG=$(DEBUG) COMP=$(HOSTCC) NVCC=$(COMP) | tail -1) - SUNDIALS_LIB_DIR ?= $(PELE_PHYSICS_HOME)/ThirdParty/INSTALL/$(configSpecificTPSuffix)/lib - INCLUDE_LOCATIONS += $(SUNDIALS_LIB_DIR)/../include - ifeq ($(USE_ARKODE_PP),TRUE) - DEFINES += -DUSE_ARKODE_PP - endif - LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_cvode -lsundials_arkode - LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_nvecserial - ifeq ($(USE_CUDA),TRUE) - LIBRARY_LOCATIONS += $(SUNDIALS_LIB_DIR) - LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_nveccuda - ifneq ($(USE_ARKODE_PP),TRUE) - LIBRARIES += -lsundials_sunlinsolcusolversp -lsundials_sunmatrixcusparse -lcusolver -lcusparse - endif - else - ifeq ($(USE_HIP),TRUE) - LIBRARY_LOCATIONS += $(SUNDIALS_LIB_DIR) - LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_nvechip - endif +else + HOSTCC = $(COMP) +endif +configSpecificTPSuffix=$(shell cd $(PELE_PHYSICS_HOME)/ThirdParty; make tp_suffix AMREX_HOME=$(AMREX_HOME) USE_CUDA=$(USE_CUDA) USE_HIP=$(USE_HIP) PELE_USE_KLU=$(PELE_USE_KLU) DEBUG=$(DEBUG) COMP=$(HOSTCC) NVCC=$(COMP) | tail -1) +SUNDIALS_LIB_DIR := $(PELE_PHYSICS_HOME)/ThirdParty/INSTALL/$(configSpecificTPSuffix)/lib +INCLUDE_LOCATIONS += $(SUNDIALS_LIB_DIR)/../include +LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_cvode -lsundials_arkode +LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_nvecserial +ifeq ($(USE_CUDA),TRUE) + LIBRARY_LOCATIONS += $(SUNDIALS_LIB_DIR) + LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_nveccuda + LIBRARIES += -lsundials_sunlinsolcusolversp -lsundials_sunmatrixcusparse -lcusolver -lcusparse +else + ifeq ($(USE_HIP),TRUE) + LIBRARY_LOCATIONS += $(SUNDIALS_LIB_DIR) + LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_nvechip endif +endif +ifneq ($(shell uname),Darwin) + LIBRARIES += -Wl,-rpath=${SUNDIALS_LIB_DIR} +endif +ifeq ($(PELE_USE_KLU), TRUE) + SUITESPARSE_DIR := $(PELE_PHYSICS_HOME)/ThirdParty/INSTALL/$(configSpecificTPSuffix) + DEFINES += -DPELE_USE_KLU + LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_sunmatrixsparse -lsundials_sunlinsolklu + LIBRARIES += -L$(SUITESPARSE_DIR)/lib -lklu -lamd -lcolamd -lbtf -lsuitesparseconfig + INCLUDE_LOCATIONS+=${SUITESPARSE_DIR}/include ifneq ($(shell uname),Darwin) - LIBRARIES += -Wl,-rpath=${SUNDIALS_LIB_DIR} - endif - ifeq ($(USE_KLU_PP), TRUE) - SUITESPARSE_DIR ?= $(PELE_PHYSICS_HOME)/ThirdParty/INSTALL/$(configSpecificTPSuffix) - DEFINES += -DUSE_KLU_PP - LIBRARIES += -L$(SUNDIALS_LIB_DIR) -lsundials_sunmatrixsparse -lsundials_sunlinsolklu - LIBRARIES += -L$(SUITESPARSE_DIR)/lib -lklu -lamd -lcolamd -lbtf -lsuitesparseconfig - INCLUDE_LOCATIONS+=${SUITESPARSE_DIR}/include - ifneq ($(shell uname),Darwin) - LIBRARIES += -Wl,-rpath=${SUITESPARSE_DIR}/lib - endif + LIBRARIES += -Wl,-rpath=${SUITESPARSE_DIR}/lib endif endif - diff --git a/Transport/Simple.H b/Transport/Simple.H index 470f5625e..3e7614ed0 100644 --- a/Transport/Simple.H +++ b/Transport/Simple.H @@ -44,11 +44,11 @@ struct NonIdealChungCorrections for (int i = 0; i < NUM_SPECIES; ++i) { for (int j = 0; j < NUM_SPECIES; ++j) { - const amrex::Real Xij = Xloc[i] * Xloc[j]; - const int idx = i * NUM_SPECIES + j; - - const amrex::Real sqrtT2 = trans_parm->sqrtT2ij[idx]; - const amrex::Real T2 = sqrtT2 * sqrtT2; + const amrex::Real Xij = Xloc[i] * Xloc[j]; + const int idx = i * NUM_SPECIES + j; + + const amrex::Real sqrtT2 = trans_parm->sqrtT2ij[idx]; + const amrex::Real T2 = sqrtT2 * sqrtT2; const amrex::Real T3 = T2 * sqrtT2; sigma_M_3 += Xij * T3; @@ -61,9 +61,9 @@ struct NonIdealChungCorrections MW_m += Xij * Epsilon_ij * T2 * trans_parm->sqrtMWij[idx]; - DP_m_4 += Xij* trans_parm->trans_dip[i] * - trans_parm->trans_dip[i] * trans_parm->trans_dip[j] * - trans_parm->trans_dip[j] / (T3 * Epsilon_ij); + DP_m_4 += Xij * trans_parm->trans_dip[i] * trans_parm->trans_dip[i] * + trans_parm->trans_dip[j] * trans_parm->trans_dip[j] / + (T3 * Epsilon_ij); KappaM += Xij * trans_parm->sqrtKappaij[idx]; } @@ -191,10 +191,10 @@ struct BinaryDiff amrex::Real Upsilonij = 0.0; for (int k = 0; k < NUM_SPECIES; ++k) { - Upsilonij += tparm->Upsilonijk[idx_ij*NUM_SPECIES + k] * Yloc[k]; + Upsilonij += tparm->Upsilonijk[idx_ij * NUM_SPECIES + k] * Yloc[k]; } Upsilonij = Upsilonij * rholoc * Constants::Avna * M_PI / 12.0 + 1.0; - dbintemp *= (Constants::RU * Tloc * Upsilonij) / Constants::PATM ; + dbintemp *= (Constants::RU * Tloc * Upsilonij) / Constants::PATM; term1 += Yloc[j]; term2 += Xloc[j] * dbintemp; } diff --git a/Transport/TransportParams.H b/Transport/TransportParams.H index 6dd8aee67..adc530108 100644 --- a/Transport/TransportParams.H +++ b/Transport/TransportParams.H @@ -333,36 +333,39 @@ struct TransParm } for (int i = 0; i < NUM_SPECIES; ++i) { for (int j = 0; j < NUM_SPECIES; ++j) { - const int idx = i * NUM_SPECIES + j; + const int idx = i * NUM_SPECIES + j; sqrtT2ij[idx] = std::sqrt(trans_sig[i] * trans_sig[j]); - sqrtEpsilonij[idx] = std::sqrt(trans_eps[i] * trans_eps[j]); - sqrtMWij[idx] = std::sqrt(2.0 / (trans_iwt[i] + trans_iwt[j])); - sqrtKappaij[idx] = std::sqrt(Kappai[i] * Kappai[j]); + sqrtEpsilonij[idx] = std::sqrt(trans_eps[i] * trans_eps[j]); + sqrtMWij[idx] = std::sqrt(2.0 / (trans_iwt[i] + trans_iwt[j])); + sqrtKappaij[idx] = std::sqrt(Kappai[i] * Kappai[j]); } } for (int i = 0; i < NUM_SPECIES; ++i) { for (int j = 0; j < NUM_SPECIES; ++j) { - if (i != j) { - const int idx_ij = i + NUM_SPECIES * j; - const amrex::Real S_ij = 0.5 * (trans_sig[i] + trans_sig[j]) * 1e-8; // converted to cm - const amrex::Real S_ij_inv = 1.0 / S_ij; - for (int k = 0; k < NUM_SPECIES; ++k) { - const amrex::Real S_ik = 0.5 * (trans_sig[i] + trans_sig[k]) * 1e-8; // converted to cm - const amrex::Real S_jk = 0.5 * (trans_sig[j] + trans_sig[k]) * 1e-8; // converted to cm - Upsilonijk[idx_ij*NUM_SPECIES + k] = - trans_iwt[k] * - (8.0 * (S_ik * S_ik * S_ik + S_jk * S_jk * S_jk) - - 6.0 * (S_ik * S_ik + S_jk * S_jk) * S_ij - - 3.0 * - ((S_ik * S_ik - S_jk * S_jk) * (S_ik * S_ik - S_jk * S_jk)) * - S_ij_inv + - S_ij * S_ij * S_ij); - } - } - } + if (i != j) { + const int idx_ij = i + NUM_SPECIES * j; + const amrex::Real S_ij = + 0.5 * (trans_sig[i] + trans_sig[j]) * 1e-8; // converted to cm + const amrex::Real S_ij_inv = 1.0 / S_ij; + for (int k = 0; k < NUM_SPECIES; ++k) { + const amrex::Real S_ik = + 0.5 * (trans_sig[i] + trans_sig[k]) * 1e-8; // converted to cm + const amrex::Real S_jk = + 0.5 * (trans_sig[j] + trans_sig[k]) * 1e-8; // converted to cm + Upsilonijk[idx_ij * NUM_SPECIES + k] = + trans_iwt[k] * + (8.0 * (S_ik * S_ik * S_ik + S_jk * S_jk * S_jk) - + 6.0 * (S_ik * S_ik + S_jk * S_jk) * S_ij - + 3.0 * + ((S_ik * S_ik - S_jk * S_jk) * (S_ik * S_ik - S_jk * S_jk)) * + S_ij_inv + + S_ij * S_ij * S_ij); + } + } + } } - + m_allocated = true; } }