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 .unit. operator for computing unit vectors
- Loading branch information
Showing
6 changed files
with
191 additions
and
18 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
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
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,129 @@ | ||
| !! Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh | ||
| !! This file is part of Swiftest. | ||
| !! Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License | ||
| !! as published by the Free Software Foundation, either version NDIM of the License, or (at your option) any later version. | ||
| !! Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
| !! of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| !! You should have received a copy of the GNU General Public License along with Swiftest. | ||
| !! If not, see: https://www.gnu.org/licenses. | ||
|
|
||
| submodule(swiftest_operators) s_operator_unit | ||
| !! author: David A. Minton | ||
| !! | ||
| !! Contains implementations for the .unit. operator for all defined real types | ||
| !! Returns a unit vector or array of unit vectors from an input vector or array of vectors | ||
| !! Single vector implementations: B = .unit. A(1:NDIM) | ||
| !! Vector list implementations: B(:) = .unit. A(1:NDIM, :) | ||
| contains | ||
|
|
||
| pure module function operator_unit_sp(A) result(B) | ||
| implicit none | ||
| ! Arguments | ||
| real(SP), dimension(:), intent(in) :: A | ||
| real(SP), dimension(NDIM) :: B | ||
| ! Internals | ||
| real(SP) :: Amag | ||
|
|
||
| Amag = norm2(A(:)) | ||
| B(:) = A(:) / Amag | ||
|
|
||
| return | ||
| end function operator_unit_sp | ||
|
|
||
|
|
||
| pure module function operator_unit_dp(A) result(B) | ||
| implicit none | ||
| ! Arguments | ||
| real(DP), dimension(:), intent(in) :: A | ||
| real(DP), dimension(NDIM) :: B | ||
| ! Internals | ||
| real(DP) :: Amag | ||
|
|
||
| Amag = norm2(A(:)) | ||
| B(:) = A(:) / Amag | ||
|
|
||
| return | ||
| end function operator_unit_dp | ||
|
|
||
|
|
||
| pure module function operator_unit_qp(A) result(B) | ||
| implicit none | ||
| ! Arguments | ||
| real(QP), dimension(:), intent(in) :: A | ||
| real(QP), dimension(NDIM) :: B | ||
| ! Internals | ||
| real(QP) :: Amag | ||
|
|
||
| Amag = norm2(A(:)) | ||
| B(:) = A(:) / Amag | ||
|
|
||
| return | ||
| end function operator_unit_qp | ||
|
|
||
|
|
||
| pure module function operator_unit_el_sp(A) result(B) | ||
| implicit none | ||
| ! Arguments | ||
| real(SP), dimension(:,:), intent(in) :: A | ||
| real(SP), dimension(:,:), allocatable :: B | ||
| ! Internals | ||
| real(SP) :: Amag | ||
| integer(I4B) :: i,n | ||
|
|
||
| n = size(A, 2) | ||
| if (allocated(B)) deallocate(B) | ||
| allocate(B(NDIM,n)) | ||
|
|
||
| do concurrent (i=1:n) | ||
| Amag = norm2(A(:, i)) | ||
| B(:,i) = A(:,i) / Amag | ||
| end do | ||
|
|
||
| return | ||
| end function operator_unit_el_sp | ||
|
|
||
|
|
||
| pure module function operator_unit_el_dp(A) result(B) | ||
| implicit none | ||
| ! Arguments | ||
| real(DP), dimension(:,:), intent(in) :: A | ||
| real(DP), dimension(:,:), allocatable :: B | ||
| ! Internals | ||
| real(DP) :: Amag | ||
| integer(I4B) :: i,n | ||
|
|
||
| n = size(A, 2) | ||
| if (allocated(B)) deallocate(B) | ||
| allocate(B(NDIM,n)) | ||
|
|
||
| do concurrent (i=1:n) | ||
| Amag = norm2(A(:, i)) | ||
| B(:,i) = A(:,i) / Amag | ||
| end do | ||
|
|
||
| return | ||
| end function operator_unit_el_dp | ||
|
|
||
| pure module function operator_unit_el_qp(A) result(B) | ||
| implicit none | ||
| ! Arguments | ||
| real(QP), dimension(:,:), intent(in) :: A | ||
| real(QP), dimension(:,:), allocatable :: B | ||
| ! Internals | ||
| real(QP) :: Amag | ||
| integer(I4B) :: i,n | ||
|
|
||
| n = size(A, 2) | ||
| if (allocated(B)) deallocate(B) | ||
| allocate(B(NDIM,n)) | ||
|
|
||
| do concurrent (i=1:n) | ||
| Amag = norm2(A(:, i)) | ||
| B(:,i) = A(:,i) / Amag | ||
| end do | ||
|
|
||
| return | ||
| end function operator_unit_el_qp | ||
|
|
||
| end submodule s_operator_unit | ||
|
|