forked from certik/numpy-fortran
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
3 changed files
with
26 additions
and
9 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 |
---|---|---|
@@ -1,46 +1,53 @@ | ||
module compute | ||
|
||
use types, only: dp | ||
implicit none | ||
private | ||
public init, register_func, run | ||
public init, register_func, run, dp | ||
|
||
abstract interface | ||
function derivs(x) result(y) | ||
use types, only: dp | ||
real(dp), intent(in) :: x(2) | ||
real(dp) :: y(2) | ||
end function | ||
end interface | ||
|
||
type eq | ||
integer :: i | ||
procedure(derivs) :: func | ||
procedure(derivs), nopass, pointer :: func | ||
end type | ||
|
||
contains | ||
|
||
subroutine init(d) | ||
type(eq), intent(inout) :: d | ||
d%func = NULL; | ||
d%func => NULL() | ||
end subroutine | ||
|
||
subroutine register_func(d, func) | ||
type(eq), intent(inout) :: d | ||
procedure(derivs), intent(in) :: func | ||
d%func => func; | ||
procedure(derivs), pointer, intent(in) :: func | ||
d%func => func | ||
end subroutine | ||
|
||
subroutine (d, x0, dt, n_steps) | ||
subroutine run(d, x0, dt, n_steps) | ||
type(eq), intent(in) :: d | ||
real(dp), intent(in) :: x0(2), dt | ||
integer, intent(in) :: n_steps | ||
|
||
real(dp) :: x(2), dx(2), t | ||
integer :: i | ||
if (.not. associated(d%func)) then | ||
print *, "d%func is not associated" | ||
end if | ||
x = x0 | ||
t = 0 | ||
do i = 1, n_steps | ||
dx = d%func(x) | ||
print *, x | ||
x += dx * dt | ||
t += dt | ||
x = x + dx * dt | ||
t = t + dt | ||
end do | ||
end subroutine | ||
|
||
end module |
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,9 @@ | ||
module types | ||
|
||
implicit none | ||
private | ||
public dp | ||
|
||
integer, parameter :: dp=kind(0.d0) | ||
|
||
end module |