Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0a3c601
Start implementing first coefficient of non-uniform FD scheme
pbartholomew08 Feb 25, 2023
29aaf14
Describe paramters of verify coefficients test.
pbartholomew08 Feb 25, 2023
784ff19
Merge branch 'main' into 1-implement-non-uniform-compact-finite-diffe…
pbartholomew08 Feb 26, 2023
243183d
Fleshing out the first coefficient implementation
pbartholomew08 Feb 26, 2023
1041ea9
Merge branch 'main' into 1-implement-non-uniform-compact-finite-diffe…
pbartholomew08 Feb 26, 2023
9d4e9c1
Add debugging flags for Debug builds
pbartholomew08 Feb 26, 2023
edc4a6e
gfortran doesn't support parameterised types
pbartholomew08 Feb 26, 2023
94e09ef
Implement B coefficient
pbartholomew08 Feb 26, 2023
cac6613
Implement coefficient C
pbartholomew08 Feb 26, 2023
8034c7d
Implement coefficient D
pbartholomew08 Feb 26, 2023
9852f7e
Implement coefficient E
pbartholomew08 Feb 26, 2023
48e17ae
Merge branch 'main' into 1-implement-non-uniform-compact-finite-diffe…
pbartholomew08 Feb 26, 2023
3a12b0f
Update comments to improve FORD documentation
pbartholomew08 Feb 26, 2023
bec3ac8
Add index stencil type
pbartholomew08 Feb 26, 2023
3b2e1e9
Initial implementation of RHS derivative function
pbartholomew08 Feb 26, 2023
9e6ce2f
Move to f2018 standard
pbartholomew08 Feb 26, 2023
4d1b2ab
Merge branch 'main' into 1-implement-non-uniform-compact-finite-diffe…
pbartholomew08 Feb 26, 2023
bfe44c0
Need to disable FP optimisation in Cray compiler
pbartholomew08 Feb 26, 2023
db9a91a
WIP Implement coeff_a_alt
pbartholomew08 Feb 27, 2023
01f9e1e
WIP coeff_a_alt adding additional terms
pbartholomew08 Feb 27, 2023
d9e7c6b
WIP coeff_a_alt add additional terms
pbartholomew08 Feb 27, 2023
f5a16d6
WIP coeff_a_alt add additional coefficients
pbartholomew08 Feb 27, 2023
36b1d1a
WIP coeff_a_alt add additional terms
pbartholomew08 Feb 27, 2023
0a2ce4c
WIP coeff_a_alt add additional terms
pbartholomew08 Feb 27, 2023
fe2ffe0
Remove colour codes
pbartholomew08 Feb 27, 2023
5848e59
Add the test for coeff_a_alt
pbartholomew08 Feb 27, 2023
37530bf
Replace coeff_a with coeff_a_alt
pbartholomew08 Feb 27, 2023
be787e7
Initial alternative implementation of coeff_b
pbartholomew08 Feb 28, 2023
34c39c6
WIP add additional terms to coeff_b_alt
pbartholomew08 Feb 28, 2023
4d5f63f
Adding additional terms to coeff_b_alt
pbartholomew08 Feb 28, 2023
052935b
Adding additional terms to coeff_b_alt
pbartholomew08 Feb 28, 2023
6df5f75
Adding additional terms to coeff_b_alt
pbartholomew08 Feb 28, 2023
75eae92
Spotted error in coeff_A calculation
pbartholomew08 Feb 28, 2023
eeb0477
Implement last term in coeff_b_alt
pbartholomew08 Feb 28, 2023
bfc178b
Remove colour codes
pbartholomew08 Feb 28, 2023
7fea668
Replace coeff_b with coeff_b_alt implementation
pbartholomew08 Feb 28, 2023
0d70de2
Move coeffs module to subdirectory
pbartholomew08 Feb 28, 2023
155cd1b
Move coefficient evaluations to submodules
pbartholomew08 Feb 28, 2023
2652a2c
Split coeff_a into PURE subfunctions
pbartholomew08 Feb 28, 2023
e53685b
Tidy up coeff_a submodule
pbartholomew08 Feb 28, 2023
a06ba88
Split coeff_b evaluation into smaller PURE subfunctions
pbartholomew08 Feb 28, 2023
46fdf9f
Split coeff_c evaluation into smaller PURE functions
pbartholomew08 Feb 28, 2023
7e5f51f
Split coeff_d computation into smaller PURE functions
pbartholomew08 Feb 28, 2023
5e67702
Enable testing coefficient A by component
pbartholomew08 Feb 28, 2023
b3a4cf1
Enable testing coefficient B by component
pbartholomew08 Feb 28, 2023
e8c4aba
Fortran submodules require use of CMake v3.25.2
pbartholomew08 Feb 28, 2023
2da2353
Update derivative rules to test range of properties + functions
pbartholomew08 Feb 28, 2023
c97b138
Delta stencils were wider than necessary
pbartholomew08 Feb 28, 2023
fc47ba8
Need to actually set the grid in the test...
pbartholomew08 Feb 28, 2023
6c8b1c5
Compute finite difference in floating-point robust way
pbartholomew08 Feb 28, 2023
1832cb5
Document the coeff_e module
pbartholomew08 Mar 3, 2023
296abaf
Correct copy-paste error
pbartholomew08 Mar 3, 2023
cdfb9fc
Fix code blocks in README
pbartholomew08 Mar 4, 2023
30a26a6
Ensuring each source file has a documentation header
pbartholomew08 Mar 4, 2023
b89a55f
Documenting procedures
pbartholomew08 Mar 4, 2023
8ab75b8
Merge branch '8-tests-fail-under-floating-point-optimisations' of git…
pbartholomew08 Mar 4, 2023
ccc60d3
Merge pull request #9 from 3decomp/8-tests-fail-under-floating-point-…
pbartholomew08 Mar 4, 2023
f99e95a
Tidy up CMakeLists.txt
pbartholomew08 Mar 4, 2023
7001531
Add option to build shared libraries
pbartholomew08 Mar 5, 2023
ae10398
Split FD schemes test suite for separate function types
pbartholomew08 Mar 5, 2023
25fd403
Split FD schemes coefficient test suite
pbartholomew08 Mar 5, 2023
4a217ac
Fix error in setting Debug flags
pbartholomew08 Mar 5, 2023
1c01908
Fix typo
pbartholomew08 Mar 18, 2023
ab2b409
Merge branch 'main' into 1-implement-non-uniform-compact-finite-diffe…
pbartholomew08 Mar 20, 2023
22f6264
Merge branch 'main' into 1-implement-non-uniform-compact-finite-diffe…
pbartholomew08 Mar 20, 2023
9352fc5
Update CHANGELOG
pbartholomew08 Mar 20, 2023
3aa981f
Merge branch 'main' into 1-implement-non-uniform-compact-finite-diffe…
pbartholomew08 Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ This is the change log for `NuCFD`, it is based on the format suggested by [Keep

### Added

- Added Cray compiler support [42b7070].
- Added Intel compiler support [2d3ce07].
- Added `FORD` documentation system [c780fe1].
- Added tridiagonal solver with support for periodic problems [f5d254f].
- Added simple library to support writing tests [a5814c8].
- Added build and test system based on `cmake` [8d56f30].
- Added Cray compiler support [42b7070].
- Added Intel compiler support [2d3ce07].
- Set minimum `cmake` version `v3.25.2` to support Fortran submodules [e8c4aba].

### Changed
### Deprecated
Expand Down
57 changes: 16 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
#
## Description
#
# Main CMakeLists file for the NuCFD project.
#
## LICENSE
#
# SPDX-License-Identifier: BSD-3-Clause
#

## Basic configuration
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.25.2)
project(NuCFD)
enable_language(Fortran)

option(BUILD_SHARED_LIBS "Enable building as a shared library" OFF)
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE true)
endif()

include(GNUInstallDirs)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
Expand All @@ -23,9 +30,9 @@ set(icc_like_fc "$<COMPILE_LANG_AND_ID:Fortran,Intel>")
set(cray_like_fc "$<COMPILE_LANG_AND_ID:Fortran,Cray>")
add_library(nucfd_compiler_flags INTERFACE)
target_compile_options(nucfd_compiler_flags INTERFACE
"$<${gcc_like_fc}:-std=f2008;-Wall;-Wextra;-Wpedantic;-Warray-bounds;-Wimplicit-interface;-Wimplicit-procedure;-fimplicit-none>"
"$<${icc_like_fc}:-std08;-warn;all>"
"$<${cray_like_fc}:-en;-emf;-eI>")
"$<${gcc_like_fc}:-cpp;-std=f2018;-Wall;-Wextra;-Wpedantic;-Warray-bounds;-Wimplicit-interface;-Wimplicit-procedure;-fimplicit-none>"
"$<${icc_like_fc}:-fpp;-std18;-warn;all>"
"$<${cray_like_fc}:-cpp;-hfp0;-en;-emf;-eI>") # Anything greater than fp0 fails tests!
add_library(nucfd_debug_flags INTERFACE)
target_compile_options(nucfd_debug_flags INTERFACE
"$<${gcc_like_fc}:-g;-Og;-ffpe-trap=invalid,zero;-fcheck=bounds;-fbacktrace>"
Expand All @@ -35,48 +42,16 @@ add_library(nucfd_strict_flags INTERFACE)
target_compile_options(nucfd_strict_flags INTERFACE
"$<${gcc_like_fc}:-Werror;-Wno-error=integer-division>"
"$<${cray_like_fc}:-eN>")
if (CMAKE_BUILD_TYPE MATCHES "Debug")
target_link_libraries(nucfd_compiler_flags INTERFACE nucfd_debug_flags)
endif()

## Build nucfd library
add_library(nucfd
src/nucfd_trid_solver_mod.f90
src/nucfd_coeffs_mod.f90)
target_link_libraries(nucfd nucfd_compiler_flags)
add_subdirectory(src)

## Testing
enable_testing()

add_library(nucfd_test_flags INTERFACE)
target_link_libraries(nucfd_test_flags INTERFACE
nucfd_compiler_flags
nucfd_debug_flags
nucfd_strict_flags)

add_library(nucfd_test_framework tests/nucfd_tests_mod.f90)
target_link_libraries(nucfd_test_framework nucfd_test_flags)

function(define_test suite test_name)
add_executable(${test_name} tests/${suite}/${test_name}.f90)
target_link_libraries(${test_name} nucfd)
target_link_libraries(${test_name} nucfd_test_framework)
target_link_libraries(${test_name} nucfd_test_flags)
add_test(NAME ${suite}:${test_name} COMMAND ${test_name})
endfunction()

function(add_test_libs suite test_name lib)
target_link_libraries(${test_name} ${lib})
endfunction()

# Tidiagonal solver test suite
add_library(trid_test_utils tests/tridsolver/tridsol_test_utils_mod.f90)
target_link_libraries(trid_test_utils nucfd_test_flags)
define_test(tridsolver system_11_symm nucfd_test_framework)
define_test(tridsolver system_11_anti-symm)
add_test_libs(tridsolver system_11_symm trid_test_utils)
add_test_libs(tridsolver system_11_anti-symm trid_test_utils)
define_test(tridsolver system_00_symm nucfd_test_framework)
define_test(tridsolver system_00_anti-symm)
add_test_libs(tridsolver system_00_symm trid_test_utils)
add_test_libs(tridsolver system_00_anti-symm trid_test_utils)
add_subdirectory(tests)

## Documentation
add_custom_target(doc ford
Expand Down
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,49 @@ difference schemes on non-uniform grids.
## Building

The `NuCFD` build system is generated by `cmake`, a default configuration can be created by running
``
```
cmake -B build
``
```
from the root directory.
Once the build system has been generated running
``
```
make -C build
``
```
will build the library.
The build can be configured using the `ccmake` tool, however currently only `gfortran` is supported.

Note that this project uses Fortran2008 submodules, support for these in CMake requires CMake v3.25.2
or above.
If you already have an older CMake it can be relatively easily updated for the local user by cloning
the repository and checking out tag `v3.25.2` (or later), CMake iteslf can then be built using a
fairly standard process:
```
cmake -B build -DCMAKE_INSTALL_PREFIX=/path/to/install
# Any configuration required
make -C build && make -C build install
export PATH=/path/to/install/bin:${PATH}
```
you should then be able to use your new CMake to configure the `NuCFD` build.

## Testing

After building the library it can be tested using `ctest`.
From the root directory run
``
```
make -C build test
``
```
to launch the tests.
If any test fail more detailed output can be shown by running `ctest` verbosely
``
```
cd build
ctest --verbose
``
```
which will print any output from the tests, add `--rerun-failed` to only repeat failing tests.

## Documentation

Documentation can be generated using the FORD tool by running
``
```
make -C build/ doc
``
```
the generated documentation can be viewed in a web browser by opening `./manual/index.html`.
24 changes: 24 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## src/CMakeLists.txt
#
## Description
#
# CMakeLists file for building the NuCFD library.
#
## LICENSE
#
# SPDX-License-Identifier: BSD-3-Clause
#

add_library(nucfd_types OBJECT
nucfd_types_mod.f90
)
target_link_libraries(nucfd_types PRIVATE nucfd_compiler_flags)

add_subdirectory(coeffs)

add_library(nucfd
nucfd_trid_solver_mod.f90
nucfd_deriv_mod.f90)
target_link_libraries(nucfd PRIVATE $<TARGET_OBJECTS:nucfd_types>)
target_link_libraries(nucfd PRIVATE $<TARGET_OBJECTS:nucfd_coeffs>)
target_link_libraries(nucfd PUBLIC nucfd_compiler_flags)
21 changes: 21 additions & 0 deletions src/coeffs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## src/coeffs/CMakeLists.txt
#
## Description
#
# CMakeLists file for building the coefficients module of NuCFD.
#
## LICENSE
#
# SPDX-License-Identifier: BSD-3-Clause
#

add_library(nucfd_coeffs OBJECT
nucfd_coeffs_mod.f90
nucfd_coeffs_a.f90
nucfd_coeffs_b.f90
nucfd_coeffs_c.f90
nucfd_coeffs_d.f90
nucfd_coeffs_e.f90
)
target_link_libraries(nucfd_coeffs PRIVATE $<TARGET_OBJECTS:nucfd_types>)
target_link_libraries(nucfd_coeffs PRIVATE nucfd_compiler_flags)
173 changes: 173 additions & 0 deletions src/coeffs/nucfd_coeffs_a.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
! src/coeffs/nucfd_coeff_a.f90
!
!! Implements coefficient A of the nucfd_coeffs module.
!
! SPDX-License-Identifier: BSD-3-Clause

submodule (nucfd_coeffs) nucfd_coeffs_a
!! Submodule defining the coefficient acting on f_{i+1} for compact finite difference schemes on
!! non-uniform grids.

implicit none

contains

module real function coeff_a_points(x)
!! Compute the coefficient acting on f_{i+1} of the finite diference given a stencil of points.

type(nucfd_stencil_points), intent(in) :: x !! Stencil of points for the finite
!! difference.

type(nucfd_stencil_deltas) :: h ! Stencil of grid spacings for the finite difference.

#ifndef NDEBUG
if (size(x%stencil) /= 5) then
print *, "Error@coeff_a_points: expecting width 5 stencil, received width = ", &
size(x%stencil)
error stop
end if
if (1 - lbound(x%stencil, 1) /= 3) then
print *, "Error@coeff_a_points: expecting centre 3 stencil, received centre = ", &
1 - lbound(x%stencil, 1)
print *, size(x%stencil), lbound(x%stencil), ubound(x%stencil)
error stop
end if
#endif

h = points_to_deltas(x)
coeff_a_points = coeff_a(h)

end function coeff_a_points

module real function coeff_a_deltas(h)
!! Compute the coefficient acting on f_{i+1} of the finite diference given a stencil of grid
!! spacings.

type(nucfd_stencil_deltas), intent(in) :: h !! Stencil of grid spacings for the finite difference.

real :: numerator, numerator_corr, denominator, divisor

#ifndef NDEBUG
if (size(h%stencil) /= 4) then
print *, "Error@coeff_a_deltas: expecting width 4 stencil, received width = ", &
size(h%stencil)
error stop
end if
if (1 - lbound(h%stencil, 1) /= 2) then
print *, "Error@coeff_a_deltas: expecting centre 2 stencil, received centre = ", &
1 - lbound(h%stencil, 1)
print *, size(h%stencil), lbound(h%stencil), ubound(h%stencil)
error stop
end if
#endif

call coeff_a_components(h, numerator, numerator_corr, denominator, divisor)
coeff_a_deltas = ((numerator + numerator_corr) / denominator) / divisor

end function coeff_a_deltas

module subroutine coeff_a_components(h, numerator, numerator_corr, denominator, divisor)

type(nucfd_stencil_deltas), intent(in) :: h !! Stencil of grid spacings for the finite difference.

real, intent(out) :: numerator
real, intent(out) :: numerator_corr
real, intent(out) :: denominator
real, intent(out) :: divisor

real :: hm1, h0, hp1, hp2 ! Grid deltas at i -2, -1, 0, +1, +2

#ifndef NDEBUG
if (size(h%stencil) /= 4) then
print *, "Error@coeff_a_components: expecting width 4 stencil, received width = ", &
size(h%stencil)
error stop
end if
if (1 - lbound(h%stencil, 1) /= 2) then
print *, "Error@coeff_a_components: expecting centre 2 stencil, received centre = ", &
1 - lbound(h%stencil, 1)
print *, size(h%stencil), lbound(h%stencil), ubound(h%stencil)
error stop
end if
#endif

select type(deltas => h%stencil)
type is(real)
hm1 = deltas(-1)
h0 = deltas(0)
hp1 = deltas(1)
hp2 = deltas(2)
class default
error stop
end select

associate(beta => alpha) ! To match Gamet et al. (1999)
numerator = coeff_numerator(hm1, h0, hp2, hp2, beta)
numerator_corr = coeff_numerator_corr(hm1, h0, hp1, hp2, alpha, beta)
denominator = coeff_denominator(h0, hp1, hp2)
divisor = coeff_divisor(hm1, h0, hp1)
end associate

end subroutine coeff_a_components

pure real function coeff_numerator(hm1, h0, hp1, hp2, beta)
!! Computes the numerator of the coefficient acting on f_{i+1}.
!!
!! Reduces to (14/3) h^3 when h=const and beta=1/3.

real, intent(in) :: hm1
real, intent(in) :: h0
real, intent(in) :: hp1
real, intent(in) :: hp2
real, intent(in) :: beta

coeff_numerator = h0 * ((hm1 + h0) * (hp1 + hp2) + 2.0 * hp1 * hp2 * beta) ! = (14/3) h^3
end function coeff_numerator

pure real function coeff_numerator_corr(hm1, h0, hp1, hp2, alpha, beta)
!! Computes the non-uniform correction to the numerator acting on f_{i+1}.
!!
!! Reduces to zero when h=const and alpha=beta.

real, intent(in) :: hm1
real, intent(in) :: h0
real, intent(in) :: hp1
real, intent(in) :: hp2
real, intent(in) :: alpha
real, intent(in) :: beta

coeff_numerator_corr = hm1 * h0 * hp2 * (beta - alpha) & ! Should cancel for case alpha = beta
+ (h0**2) * (hp2 - hp1) * beta & ! Should cancel for constant h
+ hm1 * hp1 * (2.0 * hp2 - h0 - hp1) * beta & ! Should cancel for constant h
+ (hp1**2) * (3.0 * hp2 - 2.0 * h0 - hp1) * beta & ! Should cancel for constant h
+ h0 * (2.0 * hp1 * hp2 * beta - hm1 * (h0 + hp1) * alpha) ! Should cancel for constant h,
! alpha=beta
end function coeff_numerator_corr

pure real function coeff_denominator(h0, hp1, hp2)
!! Computes the denominator of the coefficient acting on f_{i+1}.
!!
!! Reduces to 3 h^3 when h=const. Dividing the numerator by this term yields the coefficient
!! 14/9 when h=const, alpha=beta=1/3.

real, intent(in) :: h0
real, intent(in) :: hp1
real, intent(in) :: hp2

coeff_denominator = (3.0 * hp1 * ((h0 + hp1) / 2.0) * hp2)
end function coeff_denominator

pure real function coeff_divisor(hm1, h0, hp1)
!! Computes the non-uniform equivalent to 2h divisor of the coefficient acting on f_{i+1}.
!!
!! Dividing the coefficient by this term should reduce to (14/9)/(2h) when h=const,
!! alpha=beta=1/3.

real, intent(in) :: hm1
real, intent(in) :: h0
real, intent(in) :: hp1

coeff_divisor = (2.0 * ((hm1 + h0 + hp1) / 3.0))
end function coeff_divisor

end submodule nucfd_coeffs_a
Loading