|
1 | 1 | module MethodSubcellTernaryModule |
2 | 2 | use KindModule, only: DP, I4B, LGP |
3 | | - use ConstantsModule, only: DZERO, DSAME, DHALF, DONE, DTWO |
| 3 | + use ConstantsModule, only: DZERO, DSAME, DHALF, DONE, DTWO, DONETHIRD |
4 | 4 | use ErrorUtilModule, only: pstop |
5 | 5 | use GeomUtilModule, only: skew |
6 | 6 | use MethodModule, only: MethodType |
@@ -61,91 +61,104 @@ subroutine apply_mst(this, particle, tmax) |
61 | 61 | end select |
62 | 62 | end subroutine apply_mst |
63 | 63 |
|
64 | | - !> @brief Nudge barycentric coordinates such that none is less |
65 | | - !! than distance DSAME from any edge of the canonical subcell. |
| 64 | + !> @brief Nudge barycentric coordinates into the interior of |
| 65 | + !! the canonical subcell such that the point is at least the |
| 66 | + !! minimal distance tol from any face. |
66 | 67 | !! |
67 | 68 | !! Assumes 1 = alpha + beta + gamma, and 0 <= alpha <= 1 (and |
68 | 69 | !! likewise for beta and gamma). The latter is not strictly |
69 | 70 | !! required but it should be established that a particle is |
70 | | - !! _roughly_ in a given subcell before calling this routine. |
| 71 | + !! roughly in a given subcell before calling this routine. |
71 | 72 | !< |
72 | | - subroutine nudge(alpi, beti, gami) |
| 73 | + subroutine nudge(alpha, beta, gamma, tol) |
73 | 74 | ! dummy |
74 | | - real(DP), intent(inout) :: alpi |
75 | | - real(DP), intent(inout) :: beti |
76 | | - real(DP), intent(out) :: gami |
| 75 | + real(DP), intent(inout) :: alpha |
| 76 | + real(DP), intent(inout) :: beta |
| 77 | + real(DP), intent(out) :: gamma |
| 78 | + real(DP), intent(in), optional :: tol |
77 | 79 | ! local |
78 | 80 | real(DP) :: lolimit |
79 | 81 | real(DP) :: hilimit |
80 | 82 | real(DP) :: delta |
| 83 | + real(DP) :: ltol |
81 | 84 |
|
82 | | - gami = DONE - alpi - beti |
83 | | - lolimit = DSAME |
84 | | - hilimit = DONE - DTWO * DSAME |
| 85 | + if (present(tol)) then |
| 86 | + ltol = tol |
| 87 | + if (tol < DZERO .or. tol > DONETHIRD) then |
| 88 | + print *, "error -- tolerance must be between 0 and 1/3, inclusive" |
| 89 | + call pstop(1) |
| 90 | + end if |
| 91 | + else |
| 92 | + ltol = DSAME |
| 93 | + end if |
| 94 | + |
| 95 | + gamma = DONE - alpha - beta |
| 96 | + lolimit = ltol |
| 97 | + hilimit = DONE - DTWO * ltol |
85 | 98 | ! Check alpha coordinate against lower limit |
86 | | - if (alpi < lolimit) then |
| 99 | + if (alpha < lolimit) then |
87 | 100 | ! Alpha is too low, so nudge alpha to lower limit; this is a move |
88 | 101 | ! parallel to the "alpha axis," which also changes gamma |
89 | | - alpi = lolimit |
90 | | - gami = DONE - alpi - beti |
| 102 | + alpha = lolimit |
| 103 | + gamma = DONE - alpha - beta |
91 | 104 | ! Check beta coordinate against lower limit (which in this |
92 | 105 | ! case is equivalent to checking gamma coordinate against |
93 | 106 | ! upper limit) |
94 | | - if (beti < lolimit) then |
| 107 | + if (beta < lolimit) then |
95 | 108 | ! Beta is too low (gamma is too high), so nudge beta to lower limit; |
96 | 109 | ! this is a move parallel to the "beta axis," which also changes gamma |
97 | | - beti = lolimit |
98 | | - gami = hilimit |
| 110 | + beta = lolimit |
| 111 | + gamma = hilimit |
99 | 112 | ! Check beta coordinate against upper limit (which in this |
100 | 113 | ! case is equivalent to checking gamma coordinate against |
101 | 114 | ! lower limit) |
102 | | - else if (beti > hilimit) then |
| 115 | + else if (beta > hilimit) then |
103 | 116 | ! Beta is too high (gamma is too low), so nudge beta to lower limit; |
104 | 117 | ! this is a move parallel to the "beta axis," which also changes gamma |
105 | | - beti = hilimit |
106 | | - gami = lolimit |
| 118 | + beta = hilimit |
| 119 | + gamma = lolimit |
107 | 120 | end if |
108 | 121 | end if |
109 | 122 | ! Check beta coordinate against lower limit. (If alpha coordinate |
110 | 123 | ! was nudged to lower limit, beta and gamma coordinates have also |
111 | 124 | ! been adjusted as necessary to place particle within subcell, and |
112 | 125 | ! subsequent checks on beta and gamma will evaluate to false, and |
113 | 126 | ! no further adjustments will be made.) |
114 | | - if (beti < lolimit) then |
| 127 | + if (beta < lolimit) then |
115 | 128 | ! Beta is too low, so nudge beta to lower limit; this is a move |
116 | 129 | ! parallel to the "beta axis," which also changes gamma |
117 | | - beti = lolimit |
118 | | - gami = DONE - alpi - beti |
| 130 | + beta = lolimit |
| 131 | + gamma = DONE - alpha - beta |
119 | 132 | ! Check alpha coordinate against lower limit (which in this |
120 | 133 | ! case is equivalent to checking gamma coordinate against |
121 | 134 | ! upper limit) |
122 | | - if (alpi < lolimit) then |
| 135 | + if (alpha < lolimit) then |
123 | 136 | ! Alpha is too low (gamma is too high), so nudge alpha to lower limit; |
124 | 137 | ! this is a move parallel to the "alpha axis," which also changes gamma |
125 | | - alpi = lolimit |
126 | | - gami = hilimit |
| 138 | + alpha = lolimit |
| 139 | + gamma = hilimit |
127 | 140 | ! Check alpha coordinate against upper limit (which in this |
128 | 141 | ! case is equivalent to checking gamma coordinate against |
129 | 142 | ! lower limit) |
130 | | - else if (alpi > hilimit) then |
| 143 | + else if (alpha > hilimit) then |
131 | 144 | ! Alpha is too high (gamma is too low), so nudge alpha to lower limit; |
132 | 145 | ! this is a move parallel to the "alpha axis," which also changes gamma |
133 | | - alpi = hilimit |
134 | | - gami = lolimit |
| 146 | + alpha = hilimit |
| 147 | + gamma = lolimit |
135 | 148 | end if |
136 | 149 | end if |
137 | 150 | ! Check gamma coordinate against lower limit.(If alpha and/or beta |
138 | 151 | ! coordinate was nudged to lower limit, gamma coordinate has also |
139 | 152 | ! been adjusted as necessary to place particle within subcell, and |
140 | 153 | ! subsequent check on gamma will evaluate to false, and no further |
141 | 154 | ! adjustment will be made.) |
142 | | - if (gami < lolimit) then |
| 155 | + if (gamma < lolimit) then |
143 | 156 | ! Gamma is too low, so nudge gamma to lower limit; this is a move |
144 | 157 | ! parallel to the "gamma axis," which also changes alpha and beta |
145 | | - delta = DHALF * (lolimit - gami) |
146 | | - gami = DSAME |
147 | | - alpi = alpi - delta |
148 | | - beti = beti - delta |
| 158 | + delta = DHALF * (lolimit - gamma) |
| 159 | + gamma = ltol |
| 160 | + alpha = alpha - delta |
| 161 | + beta = beta - delta |
149 | 162 | end if |
150 | 163 | end subroutine nudge |
151 | 164 |
|
|
0 commit comments