This repository was archived by the owner on Aug 28, 2024. It is now read-only.
-
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.
Added new lambda function class to enable passing of complex functions into the BFGS minimizer
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,50 @@ | ||
| module lambda_function | ||
| !! Defines a class that can enable objects that behave like lambda functions. | ||
| use swiftest_globals | ||
| implicit none | ||
|
|
||
| type, public :: lambda_obj | ||
| private | ||
| procedure(lambda0), pointer, nopass :: lambdaptr => null() | ||
| contains | ||
| generic :: init => lambda_init_0 | ||
| procedure :: eval => lambda_eval_0 | ||
| procedure :: lambda_init_0 | ||
| end type | ||
|
|
||
| abstract interface | ||
| function lambda0(x) | ||
| ! Template for a 0 argument function | ||
| import DP | ||
| real(DP), intent(in) :: x | ||
| real(DP) :: lambda | ||
| end function | ||
| end interface | ||
|
|
||
| contains | ||
| subroutine lambda_init_0(self, lambda) | ||
| implicit none | ||
| ! Arguments | ||
| class(lambda_obj), intent(out) :: self | ||
| procedure(lambda0) :: lambda | ||
|
|
||
| self%lambdaptr => lambda | ||
| end subroutine lambda_init_0 | ||
|
|
||
| function lambda_eval_0(self, x) result(y) | ||
| implicit none | ||
| ! Arguments | ||
| class(lambda_obj), intent(in) :: self | ||
| real(DP), intent(in) :: x | ||
| ! Result | ||
| real(DP) :: y | ||
|
|
||
| if (associated(self%lambdaptr)) then | ||
| y = self%lambdaptr(x) | ||
| else | ||
| error stop "Initialize the object (call init) before computing values (call exec)!" | ||
| end if | ||
| end function lambda_eval_0 | ||
|
|
||
| end module lambda_function | ||
|
|
This file contains hidden or 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