-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
301a9b2
commit a483bbf
Showing
4 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# srcext [in]: File extension of the source files | ||
# trgext [in]: File extension of the target files | ||
# srcfiles [in]: List of the source files | ||
# trgfiles [out]: Contains the list of the preprocessed files on exit | ||
# | ||
function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles) | ||
|
||
set(_trgfiles) | ||
foreach(srcfile IN LISTS srcfiles) | ||
string(REGEX REPLACE "\\.${srcext}$" ".${trgext}" trgfile ${srcfile}) | ||
add_custom_command( | ||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trgfile} | ||
COMMAND ${preproc} ${preprocopts} ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/${trgfile} | ||
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile}) | ||
list(APPEND _trgfiles ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}) | ||
endforeach() | ||
set(${trgfiles} ${_trgfiles} PARENT_SCOPE) | ||
|
||
endfunction() | ||
|
||
# Preprocesses fortran files with fypp. | ||
# | ||
# It assumes that source files have the ".fypp" extension. Target files will be | ||
# created with the extension ".f90". The FYPP variable must contain the path to | ||
# the fypp-preprocessor. | ||
# | ||
# Args: | ||
# fyppopts [in]: Options to pass to fypp. | ||
# fyppfiles [in]: Files to be processed by fypp | ||
# f90files [out]: List of created f90 files on exit | ||
# | ||
function (fypp_f90 fyppopts fyppfiles f90files) | ||
preprocess("${FYPP}" "${fyppopts}" "fypp" "f90" "${fyppfiles}" _f90files) | ||
set(${f90files} ${_f90files} PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#:set TYPES = ['real(wp)', 'type(dual)'] | ||
#:set NAMES = ['real', 'dual'] | ||
#:set TYPES_NAMES = list(zip(TYPES, NAMES)) | ||
|
||
program example | ||
use forwarddiff, only: wp, jacobian | ||
implicit none | ||
interface rhs_robber | ||
procedure :: rhs_rober_real | ||
procedure :: rhs_rober_dual | ||
end interface | ||
|
||
call main() | ||
|
||
contains | ||
|
||
subroutine main() | ||
real(wp) :: u(3), f(3), dfdu(3,3) | ||
character(:), allocatable :: err | ||
|
||
! Compute the jacobian | ||
call jacobian(rhs_rober_dual, u, f, dfdu, err=err) | ||
if (allocated(err)) then | ||
print*,'err' | ||
stop 1 | ||
endif | ||
|
||
end subroutine | ||
|
||
#:for TYPE1, NAME in TYPES_NAMES | ||
subroutine rhs_rober_${NAME}$(u, du) | ||
#:if NAME == 'dual' | ||
use forwarddiff | ||
#:endif | ||
${TYPE1}$, intent(in) :: u(:) | ||
${TYPE1}$, intent(out) :: du(:) | ||
|
||
${TYPE1}$ :: tmp1, tmp2 | ||
|
||
real(wp), parameter :: k1 = 0.04_wp, & | ||
k2 = 3.0e7_wp, & | ||
k3 = 1.0e4_wp | ||
|
||
! An intermediate result | ||
tmp1 = -k1*u(1) | ||
|
||
! An intermediate dual needs to be initialized if | ||
! first assignment is just a number | ||
#:if NAME == 'dual' | ||
tmp2 = dual(size(u(1)%der)) | ||
#:endif | ||
tmp2 = 0.0_wp | ||
|
||
du(1) = tmp1 + k3*u(2)*u(3) | ||
du(2) = k1*u(1) - k2*u(2)**2.0_wp - k3*u(2)*u(3) | ||
du(3) = k2*u(2)**2.0_wp + tmp2 | ||
|
||
end subroutine | ||
|
||
#:endfor | ||
end program |