Skip to content

Commit

Permalink
copied dnad
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Mar 28, 2024
1 parent ed3422f commit 7918b34
Show file tree
Hide file tree
Showing 8 changed files with 1,034 additions and 204 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION "3.14")

project(FORWARDDIF LANGUAGES Fortran)
set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/modules")

add_subdirectory(src)
add_subdirectory(test)

7 changes: 6 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
add_library(forwarddif forwarddif_dual.f90)
add_library(forwarddif
forwarddif_const.f90
forwarddif_dual.f90
forwarddif_derivative.f90
forwarddif.f90
)

# add_executable(test_forwarddif test_forwarddif.f90)
# target_link_libraries(test_forwarddif forwarddif)
Expand Down
7 changes: 7 additions & 0 deletions src/forwarddif.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module forwarddif
use forwarddif_const
use forwarddif_dual
use forwarddif_derivative
implicit none
public
end module
3 changes: 3 additions & 0 deletions src/forwarddif_const.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module forwarddif_const
use iso_fortran_env, only: wp => real32
end module
30 changes: 30 additions & 0 deletions src/forwarddif_derivative.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module forwarddif_derivative
use forwarddif_const, only: wp
use forwarddif_dual, only: dual
implicit none
private

public :: derivative, derivative_sig

abstract interface
function derivative_sig(x) result(res)
import :: dual
type(dual), intent(in) :: x
type(dual) :: res
end function
end interface

contains

subroutine derivative(fcn, x, fcn_x, dfcn_x)
procedure(derivative_sig) :: fcn
real(wp), intent(in) :: x
real(wp), intent(out) :: fcn_x
real(wp), intent(out) :: dfcn_x
type(dual) :: f
f = fcn(dual(x, [1.0_wp]))
fcn_x = f%val
dfcn_x = f%der(1)
end subroutine

end module
Loading

0 comments on commit 7918b34

Please sign in to comment.