Skip to content

Commit 17eb3de

Browse files
authored
Upstream CheMFC infrastructure (#544)
1 parent b9e6875 commit 17eb3de

39 files changed

+1039
-211
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/tests/**/* linguist-generated=true
2+
/toolchain/mechanisms/* linguist-generated=true

.github/workflows/docs.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
name: Documentation
22

3-
on:
4-
push:
5-
branches:
6-
- master
7-
8-
workflow_dispatch:
3+
on: [push, pull_request, workflow_dispatch]
94

105
jobs:
116
docs:
127
name: Build & Publish
138
runs-on: ubuntu-latest
149

15-
if: github.repository == 'MFlowCode/MFC'
1610
concurrency:
1711
group: docs-publish
1812
cancel-in-progress: true
@@ -53,6 +47,7 @@ jobs:
5347
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
5448
5549
- name: Publish Documentation
50+
if: github.repository == 'MFlowCode/MFC' && github.ref == 'refs/heads/master' && github.event_name == 'push'
5651
run: |
5752
set +e
5853
git ls-remote "${{ secrets.DOC_PUSH_URL }}" -q

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ jobs:
4949
- name: Setup MacOS
5050
if: matrix.os == 'macos'
5151
run: |
52-
brew install coreutils python cmake fftw hdf5 gcc@14 open-mpi
52+
brew install coreutils python cmake fftw hdf5 gcc@14 boost open-mpi
5353
echo "FC=gfortran-14" >> $GITHUB_ENV
54+
echo "BOOST_INCLUDE=/opt/homebrew/include/" >> $GITHUB_ENV
5455
5556
- name: Setup Ubuntu
5657
if: matrix.os == 'ubuntu' && matrix.intel == false
@@ -138,4 +139,3 @@ jobs:
138139
with:
139140
name: logs
140141
path: test-${{ matrix.device }}.out
141-

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ macro(HANDLE_SOURCES target useCommon)
340340
-D MFC_${${target}_UPPER}
341341
-D MFC_COMPILER="${CMAKE_Fortran_COMPILER_ID}"
342342
-D MFC_CASE_OPTIMIZATION=False
343+
-D chemistry=False
343344
--line-numbering
344345
--no-folding
345346
"${fpp}" "${f90}"

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,20 @@ It's rather straightforward.
5858
We'll give a brief intro. here for MacOS.
5959
Using [brew](https://brew.sh), install MFC's dependencies:
6060
```shell
61-
brew install coreutils python cmake fftw hdf5 gcc open-mpi
61+
brew install coreutils python cmake fftw hdf5 gcc boost open-mpi
6262
```
6363
You're now ready to build and test MFC!
6464
Put it to a convenient directory via
6565
```shell
6666
git clone https://github.com/MFlowCode/MFC
6767
cd MFC
6868
```
69+
and be sure MFC knows where to find Boost by appending to your dotfiles and sourcing them again
70+
```shell
71+
echo -e 'export BOOST_INCLUDE=/opt/homebrew/' | tee -a ~/.bash_profile ~/.zshrc
72+
. ~/.bash_profile 2>/dev/null || . ~/.zshrc 2>/dev/null
73+
! [ -z "${BOOST_INCLUDE+x}" ] && echo 'Environment is ready!' || echo 'Error: $BOOST_INCLUDE is unset. Please adjust the previous commands to fit with your environment.'
74+
```
6975
then you can build MFC and run the test suite!
7076
```shell
7177
./mfc.sh build -j $(nproc)

docs/documentation/getting-started.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ You will also have access to the `.sln` Microsoft Visual Studio solution files f
101101
<details>
102102
<summary><h3>MacOS</h3></summary>
103103

104-
Using [Homebrew](https://brew.sh/) you can install the necessary dependencies:
104+
Using [Homebrew](https://brew.sh/) you can install the necessary dependencies
105+
before configuring your environment:
105106

106107
```shell
107-
brew install coreutils python cmake fftw hdf5 gcc open-mpi
108+
brew install coreutils python cmake fftw hdf5 gcc boost open-mpi
109+
echo -e 'export BOOST_INCLUDE=/opt/homebrew/' | tee -a ~/.bash_profile ~/.zshrc
110+
. ~/.bash_profile 2>/dev/null || . ~/.zshrc 2>/dev/null
111+
! [ -z "${BOOST_INCLUDE+x}" ] && echo 'Environment is ready!' || echo 'Error: $BOOST_INCLUDE is unset. Please adjust the previous commands to fit with your environment.'
108112
```
109113

110114
They will download the dependencies MFC requires to build itself.

misc/fpp_to_fypp.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
for file in $(find src -type f | grep -Ev 'autogen' | grep -E '\.fpp$'); do
4+
echo "$file"
5+
mv "$file" "$(echo "$file" | sed s/\.fpp/\.fypp/)"
6+
done

src/common/include/macros.fpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,19 @@
140140
#endif
141141
#:enddef
142142

143-
#:def PROHIBIT(*args)
144-
#:set condition = args[0]
145-
#:if len(args) == 1
146-
#:set message = '""'
147-
#:else
148-
#:set message = args[1]
149-
#:endif
143+
#:def PROHIBIT(condition, message = None)
150144
if (${condition}$) then
151-
call s_prohibit_abort("${condition}$", ${message}$)
145+
call s_prohibit_abort("${condition}$", ${message or '""'}$)
152146
end if
153147
#:enddef
154148

155149
#define t_vec3 real(kind(0d0)), dimension(1:3)
156150
#define t_mat4x4 real(kind(0d0)), dimension(1:4,1:4)
151+
152+
#:def ASSERT(predicate, message = None)
153+
if (.not. (${predicate}$)) then
154+
call s_mpi_abort("${_FILE_.split('/')[-1]}$:${_LINE_}$: "// &
155+
"Assertion failed: ${predicate}$. " &
156+
//${message or '"No error description."'}$)
157+
end if
158+
#:enddef

src/common/m_derived_types.fpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
!! types used in the pre-process code.
99
module m_derived_types
1010

11-
use m_constants !< Constants
11+
use m_constants !< Constants
12+
use m_thermochem !< Thermodynamic properties
1213

1314
implicit none
1415

@@ -192,6 +193,7 @@ module m_derived_types
192193
!! id for hard coded initial condition
193194

194195
real(kind(0d0)) :: cf_val !! color function value
196+
real(kind(0d0)) :: Y(1:num_species)
195197

196198
end type ic_patch_parameters
197199

@@ -300,4 +302,18 @@ module m_derived_types
300302
301303
end type ghost_point
302304
305+
!> Species parameters
306+
type species_parameters
307+
character(LEN=name_len) :: name !< Name of species
308+
end type species_parameters
309+
310+
!> Chemistry parameters
311+
type chemistry_parameters
312+
character(LEN=name_len) :: cantera_file !< Path to Cantera file
313+
314+
logical :: advection
315+
logical :: diffusion
316+
logical :: reactions
317+
end type chemistry_parameters
318+
303319
end module m_derived_types
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
module m_finite_differences
2+
3+
use m_global_parameters
4+
5+
implicit none
6+
7+
contains
8+
9+
subroutine s_compute_fd_divergence(div, fields, ix_s, iy_s, iz_s)
10+
11+
type(scalar_field), intent(INOUT) :: div
12+
type(scalar_field), intent(IN) :: fields(1:3)
13+
type(int_bounds_info), intent(IN) :: ix_s, iy_s, iz_s
14+
15+
integer :: x, y, z !< Generic loop iterators
16+
17+
real(kind(0d0)) :: divergence
18+
19+
!$acc parallel loop collapse(3) private(divergence)
20+
do x = ix_s%beg, ix_s%end
21+
do y = iy_s%beg, iy_s%end
22+
do z = iz_s%beg, iz_s%end
23+
24+
if (x == ix_s%beg) then
25+
divergence = (-3d0*fields(1)%sf(x, y, z) + 4d0*fields(1)%sf(x + 1, y, z) - fields(1)%sf(x + 2, y, z))/(x_cc(x + 2) - x_cc(x))
26+
else if (x == ix_s%end) then
27+
divergence = (+3d0*fields(1)%sf(x, y, z) - 4d0*fields(1)%sf(x - 1, y, z) + fields(1)%sf(x - 2, y, z))/(x_cc(x) - x_cc(x - 2))
28+
else
29+
divergence = (fields(1)%sf(x + 1, y, z) - fields(1)%sf(x - 1, y, z))/(x_cc(x + 1) - x_cc(x - 1))
30+
end if
31+
32+
if (n > 0) then
33+
if (y == iy_s%beg) then
34+
divergence = divergence + (-3d0*fields(2)%sf(x, y, z) + 4d0*fields(2)%sf(x, y + 1, z) - fields(2)%sf(x, y + 2, z))/(y_cc(y + 2) - y_cc(y))
35+
else if (y == iy_s%end) then
36+
divergence = divergence + (+3d0*fields(2)%sf(x, y, z) - 4d0*fields(2)%sf(x, y - 1, z) + fields(2)%sf(x, y - 2, z))/(y_cc(y) - y_cc(y - 2))
37+
else
38+
divergence = divergence + (fields(2)%sf(x, y + 1, z) - fields(2)%sf(x, y - 1, z))/(y_cc(y + 1) - y_cc(y - 1))
39+
end if
40+
end if
41+
42+
if (p > 0) then
43+
if (z == iz_s%beg) then
44+
divergence = divergence + (-3d0*fields(3)%sf(x, y, z) + 4d0*fields(3)%sf(x, y, z + 1) - fields(3)%sf(x, y, z + 2))/(z_cc(z + 2) - z_cc(z))
45+
else if (z == iz_s%end) then
46+
divergence = divergence + (+3d0*fields(3)%sf(x, y, z) - 4d0*fields(3)%sf(x, y, z - 1) + fields(2)%sf(x, y, z - 2))/(z_cc(z) - z_cc(z - 2))
47+
else
48+
divergence = divergence + (fields(3)%sf(x, y, z + 1) - fields(3)%sf(x, y, z - 1))/(z_cc(z + 1) - z_cc(z - 1))
49+
end if
50+
end if
51+
52+
div%sf(x, y, z) = div%sf(x, y, z) + divergence
53+
54+
end do
55+
end do
56+
end do
57+
58+
end subroutine s_compute_fd_divergence
59+
60+
!> The purpose of this subroutine is to compute the finite-
61+
!! difference coefficients for the centered schemes utilized
62+
!! in computations of first order spatial derivatives in the
63+
!! s-coordinate direction. The s-coordinate direction refers
64+
!! to the x-, y- or z-coordinate direction, depending on the
65+
!! subroutine's inputs. Note that coefficients of up to 4th
66+
!! order accuracy are available.
67+
!! @param q Number of cells in the s-coordinate direction
68+
!! @param s_cc Locations of the cell-centers in the s-coordinate direction
69+
!! @param fd_coeff_s Finite-diff. coefficients in the s-coordinate direction
70+
subroutine s_compute_finite_difference_coefficients(q, s_cc, fd_coeff_s, buff_size, &
71+
fd_number_in, fd_order_in, offset_s)
72+
73+
integer :: lB, lE !< loop bounds
74+
integer, intent(IN) :: q
75+
integer, intent(IN) :: buff_size, fd_number_in, fd_order_in
76+
type(int_bounds_info), optional, intent(IN) :: offset_s
77+
real(kind(0d0)), allocatable, dimension(:, :), intent(INOUT) :: fd_coeff_s
78+
79+
real(kind(0d0)), &
80+
dimension(-buff_size:q + buff_size), &
81+
intent(IN) :: s_cc
82+
83+
integer :: i !< Generic loop iterator
84+
85+
if (present(offset_s)) then
86+
lB = -offset_s%beg
87+
lE = q + offset_s%end
88+
else
89+
lB = 0
90+
lE = q
91+
end if
92+
93+
if (allocated(fd_coeff_s)) deallocate (fd_coeff_s)
94+
allocate (fd_coeff_s(-fd_number_in:fd_number_in, lb:lE))
95+
96+
! Computing the 1st order finite-difference coefficients
97+
if (fd_order_in == 1) then
98+
do i = lB, lE
99+
fd_coeff_s(-1, i) = 0d0
100+
fd_coeff_s(0, i) = -1d0/(s_cc(i + 1) - s_cc(i))
101+
fd_coeff_s(1, i) = -fd_coeff_s(0, i)
102+
end do
103+
104+
! Computing the 2nd order finite-difference coefficients
105+
elseif (fd_order_in == 2) then
106+
do i = lB, lE
107+
fd_coeff_s(-1, i) = -1d0/(s_cc(i + 1) - s_cc(i - 1))
108+
fd_coeff_s(0, i) = 0d0
109+
fd_coeff_s(1, i) = -fd_coeff_s(-1, i)
110+
end do
111+
112+
! Computing the 4th order finite-difference coefficients
113+
else
114+
do i = lB, lE
115+
fd_coeff_s(-2, i) = 1d0/(s_cc(i - 2) - 8d0*s_cc(i - 1) - s_cc(i + 2) + 8d0*s_cc(i + 1))
116+
fd_coeff_s(-1, i) = -8d0*fd_coeff_s(-2, i)
117+
fd_coeff_s(0, i) = 0d0
118+
fd_coeff_s(1, i) = -fd_coeff_s(-1, i)
119+
fd_coeff_s(2, i) = -fd_coeff_s(-2, i)
120+
end do
121+
122+
end if
123+
124+
end subroutine s_compute_finite_difference_coefficients ! --------------
125+
126+
end module m_finite_differences
127+

0 commit comments

Comments
 (0)