Skip to content

Commit

Permalink
Upstream fixes and tools from Chemfc (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleberre authored Mar 18, 2024
1 parent 1573fdc commit e521a8a
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
cancel-in-progress: true

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# We build doxygen from source because of
# https://github.com/doxygen/doxygen/issues/9016
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Lint the toolchain
run: ./mfc.sh lint
4 changes: 2 additions & 2 deletions .github/workflows/pretty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Check formatting
run: |
./mfc.sh format
./mfc.sh format -j $(nproc)
git diff --exit-code
2 changes: 1 addition & 1 deletion .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Spell Check
uses: crate-ci/typos@master
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
runs-on: ${{ matrix.os }}-latest
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup MacOS
if: matrix.os == 'macos'
Expand All @@ -46,10 +46,7 @@ jobs:
- name: (MacOS) Build OpenMPI
if: matrix.os == 'macos' && matrix.mpi == 'mpi'
run: |
echo "OMPI_FC=gfortran-13" >> $GITHUB_ENV
echo "OMPI_CXX=g++-13" >> $GITHUB_ENV
echo "OMPI_MPICC=gcc-13" >> $GITHUB_ENV
HOMEBREW_MAKE_JOBS=$(nproc) brew install --cc=gcc-13 --verbose --build-from-source open-mpi
brew install mpich
- name: Setup Ubuntu
if: matrix.os == 'ubuntu' && matrix.intel == false
Expand Down Expand Up @@ -96,7 +93,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Test
run: sudo ./mfc.sh docker ./mfc.sh test -j $(nproc) -a
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ examples/*/viz/
examples/*.jpg
examples/*.png
*.mod

# Video Files
*.mp4
*.mov
*.mkv
*.avi
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

"cmake.configureOnOpen": false,

"python.defaultInterpreterPath": "${workspaceFolder}/build/venv/bin/python3",

"fortran.preferredCase": "lowercase",
"fortran.linter.includePaths": [ "${workspacefolder}/src/**" ],
"fortran.linter.fypp.enabled": true
}
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
-fcheck=all,no-array-temps
-fbacktrace
-fimplicit-none
)
#-ffpe-trap=invalid,zero,denormal,overflow
)
endif()

if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 10)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ It's rather straightforward.
We'll give a brief intro. here for MacOS.
Using [brew](https://brew.sh), install MFC's modest set of dependencies:
```console
brew install wget make python make cmake coreutils gcc openmpi
brew install wget make python make cmake coreutils gcc mpich
```
You're now ready to build and test MFC!
Clone it to a convenient directory via
Expand Down
1 change: 1 addition & 0 deletions docs/documentation/case.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Definition of the parameters is described in the following subsections.
| `t_step_start` | Integer | Simulation starting time step |
| `t_step_stop` | Integer | Simulation stopping time step |
| `t_step_save` | Integer | Frequency to output data |
| `t_step_print` | Integer | Frequency to print the current step number to standard output (default 1) |

The parameters define the boundaries of the spatial and temporal domains, and their discretization that are used in simulation.

Expand Down
11 changes: 2 additions & 9 deletions docs/documentation/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,19 @@ Further reading on `open-mpi` incompatibility with `clang`-based `gcc` on macOS:
We do *not* support `clang` due to conflicts with the Silo dependency.

```console
# === MFC MPI Installation ===
export MFC_GCC_VER=13
export OMPI_MPICC=gcc-$MFC_GCC_VER
export OMPI_CXX=g++-$MFC_GCC_VER
export OMPI_FC=gfortran-$MFC_GCC_VER
export CC=gcc-$MFC_GCC_VER
export CXX=g++-$MFC_GCC_VER
export FC=gfortran-$MFC_GCC_VER
# === MFC MPI Installation ===
```

**Close the open editor and terminal window**. Open a **new terminal** window before executing the commands below.

```console
brew install wget make python make cmake coreutils gcc@$MFC_GCC_VER
HOMEBREW_MAKE_JOBS=$(nproc) brew install --cc=gcc-$MFC_GCC_VER --verbose --build-from-source open-mpi
brew install wget make python make cmake coreutils gcc@$MFC_GCC_VER mpich
```

They will download the dependencies MFC requires to build itself. `open-mpi` will be compiled from source, using the version of GCC we specified above with the environment variables `HOMEBREW_CC` and `HOMEBREW_CXX`.
Building this package might take a while.
They will download the dependencies MFC requires to build itself.

</details>

Expand Down
2 changes: 2 additions & 0 deletions mfc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ elif [ "$1" == "format" ]; then
shift; . "$(pwd)/toolchain/bootstrap/format.sh" $@; exit 0
elif [ "$1" == "docker" ]; then
shift; . "$(pwd)/toolchain/bootstrap/docker.sh" $@; exit 0
elif [ "$1" == "venv" ]; then
shift; . "$(pwd)/toolchain/bootstrap/python.sh" $@; return
fi

mkdir -p "$(pwd)/build"
Expand Down
2 changes: 1 addition & 1 deletion src/post_process/m_start_up.f90
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ subroutine s_read_input_file() ! ---------------------------------------
backspace (1)
read (1, fmt='(A)') line
print *, 'Invalid line in namelist: '//trim(line)
call s_mpi_abort('Invalid line in pre_process.inp. It is '// &
call s_mpi_abort('Invalid line in post_process.inp. It is '// &
'likely due to a datatype mismatch. Exiting ...')
end if

Expand Down
12 changes: 12 additions & 0 deletions src/pre_process/m_data_output.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,18 @@ contains

end if

open (1, FILE='equations.dat', STATUS='unknown')

write (1, '(A)') "Equations: "
if (momxb /= 0) write (1, '(A,I3,I3)') " * Momentum: ", momxb, momxe
if (advxb /= 0) write (1, '(A,I3,I3)') " * Advection: ", advxb, advxe
if (contxb /= 0) write (1, '(A,I3,I3)') " * Continuity: ", contxb, contxe
if (bubxb /= 0) write (1, '(A,I3,I3)') " * Bubbles: ", bubxb, bubxe
if (strxb /= 0) write (1, '(A,I3,I3)') " * Stress: ", strxb, strxe
if (intxb /= 0) write (1, '(A,I3,I3)') " * Internal Energies: ", intxb, intxe

close (1)

end subroutine s_initialize_data_output_module ! --------------------------

!> Resets s_write_data_files pointer
Expand Down
3 changes: 3 additions & 0 deletions src/simulation/m_global_parameters.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ module m_global_parameters
integer :: t_step_start, t_step_stop, t_step_save
!> @}

integer :: t_step_print !< Number of time-steps between printouts

! ==========================================================================

! Simulation Algorithm Parameters ==========================================
Expand Down Expand Up @@ -378,6 +380,7 @@ contains
t_step_start = dflt_int
t_step_stop = dflt_int
t_step_save = dflt_int
t_step_print = 1

! Simulation algorithm parameters
model_eqns = dflt_int
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/m_mpi_proxy.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ contains
call MPI_BCAST(case_dir, len(case_dir), MPI_CHARACTER, 0, MPI_COMM_WORLD, ierr)
#:for VAR in ['t_step_old', 'm', 'n', 'p', 'm_glb', 'n_glb', 'p_glb', &
& 't_step_start','t_step_stop','t_step_save','model_eqns', &
& 'num_fluids','time_stepper', 'riemann_solver', &
& 't_step_start','t_step_stop','t_step_save','t_step_print', &
& 'model_eqns','num_fluids','time_stepper', 'riemann_solver', &
& 'wave_speeds', 'avg_state', 'precision', 'bc_x%beg', 'bc_x%end', &
& 'bc_y%beg', 'bc_y%end', 'bc_z%beg', 'bc_z%end', 'fd_order', &
& 'num_probes', 'num_integrals', 'bubble_model', 'thermal', &
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/m_rhs.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ contains
@:DEALLOCATE(qL_rsz_vf, qR_rsz_vf)
end if

if (weno_Re_flux) then
if (any(Re_size > 0) .and. weno_Re_flux) then
@:DEALLOCATE(dqL_rsx_vf, dqR_rsx_vf)

if (n > 0) then
Expand Down
56 changes: 20 additions & 36 deletions src/simulation/m_start_up.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ contains

! Namelist of the global parameters which may be specified by user
namelist /user_inputs/ case_dir, run_time_info, m, n, p, dt, &
t_step_start, t_step_stop, t_step_save, &
t_step_start, t_step_stop, t_step_save, t_step_print, &
model_eqns, num_fluids, adv_alphan, &
mpp_lim, time_stepper, weno_eps, weno_flat, &
riemann_flat, cu_mpi, cu_tensor, &
Expand Down Expand Up @@ -166,7 +166,7 @@ contains
backspace (1)
read (1, fmt='(A)') line
print *, 'Invalid line in namelist: '//trim(line)
call s_mpi_abort('Invalid line in pre_process.inp. It is '// &
call s_mpi_abort('Invalid line in simulation.inp. It is '// &
'likely due to a datatype mismatch. Exiting ...')
end if

Expand Down Expand Up @@ -317,39 +317,23 @@ contains
end if
! ==================================================================

! Cell-average Conservative Variables ==============================
if ((bubbles .neqv. .true.) .and. (hypoelasticity .neqv. .true.)) then
do i = 1, adv_idx%end
write (file_path, '(A,I0,A)') &
trim(t_step_dir)//'/q_cons_vf', i, '.dat'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), &
FORM='unformatted', &
ACTION='read', &
STATUS='old')
read (2) q_cons_vf(i)%sf(0:m, 0:n, 0:p); close (2)
else
call s_mpi_abort(trim(file_path)//' is missing. Exiting ...')
end if
end do
else
!make sure to read bubble variables
do i = 1, sys_size
write (file_path, '(A,I0,A)') &
trim(t_step_dir)//'/q_cons_vf', i, '.dat'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), &
FORM='unformatted', &
ACTION='read', &
STATUS='old')
read (2) q_cons_vf(i)%sf(0:m, 0:n, 0:p); close (2)
else
call s_mpi_abort(trim(file_path)//' is missing. Exiting ...')
end if
end do
!Read pb and mv for non-polytropic qbmm
do i = 1, sys_size
write (file_path, '(A,I0,A)') &
trim(t_step_dir)//'/q_cons_vf', i, '.dat'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), &
FORM='unformatted', &
ACTION='read', &
STATUS='old')
read (2) q_cons_vf(i)%sf(0:m, 0:n, 0:p); close (2)
else
call s_mpi_abort(trim(file_path)//' is missing. Exiting ...')
end if
end do

if ((bubbles .eqv. .true.) .or. (hypoelasticity .eqv. .true.)) then
! Read pb and mv for non-polytropic qbmm
if (qbmm .and. .not. polytropic) then
do i = 1, nb
do r = 1, nnode
Expand Down Expand Up @@ -1068,7 +1052,7 @@ contains

integer :: i, j, k, l

if (proc_rank == 0) then
if (proc_rank == 0 .and. mod(t_step - t_step_start, t_step_print) == 0) then
print '(" ["I3"%] Time step "I8" of "I0" @ t_step = "I0"")', &
int(ceiling(100d0*(real(t_step - t_step_start)/(t_step_stop - t_step_start + 1)))), &
t_step - t_step_start + 1, &
Expand Down
58 changes: 26 additions & 32 deletions toolchain/bootstrap/format.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
#!/bin/bash

log "Formatting MFC:"

fortran_files=$(find ${@:-src} -type f | grep -Ev 'src/.+/autogen/')

longest=0
for filepath in $fortran_files; do
if [ "${#filepath}" -gt "$longest" ]; then
longest="${#filepath}"
fi
while [[ $# -gt 0 ]]; do
case "$1" in
-j|--jobs)
JOBS="$2"
shift
;;
*)
echo "Format, unknown argument: $1."
exit 1
;;
esac

shift
done

for filepath in $fortran_files; do
echo -n " > $filepath $(printf '%*s' "$((longest - ${#filepath}))" '')"

before=$(sha256sum "$filepath" | cut -d' ' -f1)

python3 toolchain/indenter.py "$filepath"

if ! fprettify "$filepath" \
--silent --indent 4 --c-relations --enable-replacements --enable-decl \
--whitespace-comma 1 --whitespace-multdiv 0 --whitespace-plusminus 1 \
--case 1 1 1 1 --strict-indent --line-length 1000; then
error "failed to execute fprettify."
error "MFC has not been fprettify'ied."
exit 1
fi
log "Formatting MFC:"

after=$(sha256sum "$filepath" | cut -d' ' -f1)

if [ "$before" != "$after" ]; then
echo -e "$YELLOW[formatted]$COLOR_RESET"
else
echo -e "$GREEN[unchanged]$COLOR_RESET"
fi
done
if ! find ${@:-src} -type f | grep -Ev 'autogen' | grep -E '\.(f90|fpp)$' | \
parallel --jobs ${JOBS:-1} -- \
echo "\> {}" \&\& \
python3 toolchain/indenter.py "{}" \&\& \
fprettify "{}" --silent --indent 4 --c-relations --enable-replacements \
--enable-decl --whitespace-comma 1 --whitespace-multdiv 0 \
--whitespace-plusminus 1 --case 1 1 1 1 --strict-indent \
--line-length 1000\;; then
error "Formatting MFC failed."
exit 1
fi

ok "Done. MFC has been formatted."

2 changes: 1 addition & 1 deletion toolchain/mfc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_slug(self) -> str:
m = hashlib.sha256()
m.update(self.name.encode())
m.update(CFG().make_slug().encode())
m.update(input.load({}).get_fpp(self).encode())
m.update(input.load({}).get_fpp(self, False).encode())

return m.hexdigest()[:10]

Expand Down
Loading

0 comments on commit e521a8a

Please sign in to comment.