Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fast3d.f90
Go to the documentation of this file.
1! Copyright (c) 2008-2020, UCHICAGO ARGONNE, LLC.
2!
3! The UChicago Argonne, LLC as Operator of Argonne National
4! Laboratory holds copyright in the Software. The copyright holder
5! reserves all rights except those expressly granted to licensees,
6! and U.S. Government license rights.
7!
8! Redistribution and use in source and binary forms, with or without
9! modification, are permitted provided that the following conditions
10! are met:
11!
12! 1. Redistributions of source code must retain the above copyright
13! notice, this list of conditions and the disclaimer below.
14!
15! 2. Redistributions in binary form must reproduce the above copyright
16! notice, this list of conditions and the disclaimer (as noted below)
17! in the documentation and/or other materials provided with the
18! distribution.
19!
20! 3. Neither the name of ANL nor the names of its contributors
21! may be used to endorse or promote products derived from this software
22! without specific prior written permission.
23!
24! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28! UCHICAGO ARGONNE, LLC, THE U.S. DEPARTMENT OF
29! ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
31! TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36!
37! Additional BSD Notice
38! ---------------------
39! 1. This notice is required to be provided under our contract with
40! the U.S. Department of Energy (DOE). This work was produced at
41! Argonne National Laboratory under Contract
42! No. DE-AC02-06CH11357 with the DOE.
43!
44! 2. Neither the United States Government nor UCHICAGO ARGONNE,
45! LLC nor any of their employees, makes any warranty,
46! express or implied, or assumes any liability or responsibility for the
47! accuracy, completeness, or usefulness of any information, apparatus,
48! product, or process disclosed, or represents that its use would not
49! infringe privately-owned rights.
50!
51! 3. Also, reference herein to any specific commercial products, process,
52! or services by trade name, trademark, manufacturer or otherwise does
53! not necessarily constitute or imply its endorsement, recommendation,
54! or favoring by the United States Government or UCHICAGO ARGONNE LLC.
55! The views and opinions of authors expressed
56! herein do not necessarily state or reflect those of the United States
57! Government or UCHICAGO ARGONNE, LLC, and shall
58! not be used for advertising or product endorsement purposes.
59!
60!> Fast diagonalization methods from NEKTON
61module fast3d
62 use num_types, only : rp, xp
63 use speclib, only : zwgll, zwgl
64 use math, only : rzero
65 implicit none
66 private
67
69
70contains
71
72 !> Compute finite-difference stencil weights for evaluating derivatives up to
73 !! order \f$m\f$ at a point.
74 !! @details
75 !! This routine comes from the Appendix C of
76 !! "A Practical Guide to Pseudospectral Methods" by B. Fornberg,
77 !! Cambridge University Press, 1996.
78 !!
79 !! Given gridpoints \f$ x_0, x_1, \dots x_n \f$ and some point \f$\xi\f$
80 !! (not necessarily a grid point!) find weights \f$ c_{j, k} \f$, such that
81 !! the expansions
82 !! \f$ \frac{d^k f}{d x^k}|_{x=\xi} \approx \sum_{j=0}^n c_{j,k} f(x_j)\f$,
83 !! \f$k=0, \dots m\f$ are optimal.
84 !! Note that finite-difference stencils are exactly such type of expansions.
85 !! For the derivation of the algorithm, refer to 3.1 in the reference above.
86 !!
87 !! @note - Setting \f$m=0\f$ makes this a polynomial interpolation routine.
88 !! It is the fastest such routine possible for a single interpolation point,
89 !! according to the above reference.
90 !! @note - The name `_full` refers to the fact that we use the
91 !! values \f$f(x_j)\f$
92 !! at all available nodes \f$x\f$ to construct the expansion. So we always
93 !! get the finite difference stencil of maximum order possible.
94 !!
95 !! @warning The calculation of the wieghts is numerically stable.
96 !! But applying the weights to a function can be ill-conditioned in the case
97 !! of high-order derivatives.
98 !!
99 !! @param xi Point at which the approximations are to be accurate
100 !! @param x The coordinates for the grid points
101 !! @param[in] n The size of `x` is `n + 1`
102 !! @param[in] m Highest order of derivative to be approximated
103 !! @param c The stencil weights. Row j corresponds to weight of \f$f(x_j)\f$
104 !! and column k to the kth derivative
105 subroutine fd_weights_full(xi, x, n, m, c)
106 integer, intent(in) :: n
107 integer, intent(in) :: m
108 real(kind=rp), intent(in) :: x(0:n)
109 real(kind=rp), intent(out) :: c(0:n,0:m)
110 real(kind=rp), intent(in) :: xi
111 real(kind=xp) :: cx(0:n,0:m)
112 real(kind=xp) :: c1, c2, c3, c4, c5
113 integer :: i, j, k, mn
114
115 c1 = 1d0
116 c4 = x(0) - xi
117
118 do k = 0, m
119 do j = 0, n
120 cx(j,k) = 0.0_xp
121 end do
122 end do
123
124 cx(0,0) = 1d0
125
126 do i = 1, n
127 mn = min(i,m)
128 c2 = 1d0
129 c5 = c4
130 c4 = x(i) - xi
131 do j = 0, i - 1
132 c3 = x(i) - x(j)
133 c2 = c2 * c3
134 do k = mn, 1, -1
135 cx(i,k) = c1 * (k * cx(i-1,k-1) - c5 * cx(i-1,k)) / c2
136 end do
137 cx(i,0) = -c1 * c5 * cx(i-1,0) / c2
138 do k = mn, 1, -1
139 cx(j,k) = (c4 * cx(j,k) - k * cx(j,k-1)) / c3
140 end do
141 cx(j,0) = c4 * cx(j,0) / c3
142 end do
143 c1 = c2
144 end do
145 c = real(cx, kind=rp)
146 end subroutine fd_weights_full
147
148
149 !> Generate matrices for single element, 1D operators:
150 !! a = Laplacian
151 !! b = diagonal mass matrix
152 !! c = convection operator b*d
153 !! d = derivative matrix
154 !! dgll = derivative matrix, mapping from pressure nodes to velocity
155 !! jgll = interpolation matrix, mapping from pressure nodes to velocity
156 !! z = GLL points
157 !!
158 !! zgl = GL points
159 !! bgl = diagonal mass matrix on GL
160 !! dgl = derivative matrix, mapping from velocity nodes to pressure
161 !! jgl = interpolation matrix, mapping from velocity nodes to pressure
162 !!
163 !! n = polynomial degree (velocity space)
164 !! w = work array of size 2*n+2
165 !!
166 !! Currently, this is set up for pressure nodes on the interior GLL pts.
167 !!
168 !!
169 subroutine semhat(a, b, c, d, z, dgll, jgll, bgl, zgl, dgl, jgl, n, w)
170 integer, intent(in) :: n
171 real(kind=rp), intent(inout) :: a(0:n,0:n)
172 real(kind=rp), intent(inout) :: b(0:n)
173 real(kind=rp), intent(inout) :: c(0:n,0:n)
174 real(kind=rp), intent(inout) :: d(0:n,0:n)
175 real(kind=rp), intent(inout) :: z(0:n)
176 real(kind=rp), intent(inout) :: dgll(0:n,1:n-1), jgll(0:n,1:n-1)
177 real(kind=rp), intent(inout) :: bgl(1:n-1)
178 real(kind=rp), intent(inout) :: zgl(1:n-1)
179 real(kind=rp), intent(inout) :: dgl(1:n-1,0:n)
180 real(kind=rp), intent(inout) :: jgl(1:n-1,0:n)
181 real(kind=rp), intent(inout) :: w(0:2*n+1)
182 integer :: np, nm, n2, i, j, k
183 np = n+1
184 nm = n-1
185 n2 = n-2
186 call zwgll(z, b, np)
187 do i = 0,n
188 call fd_weights_full(z(i), z, n, 1, w)
189 do j = 0,n
190 d(i,j) = w(j+np) ! Derivative matrix
191 end do
192 end do
193
194 if (n .eq. 1) return ! No interpolation for n = 1
195
196 do i = 0,n
197 call fd_weights_full(z(i), z(1), n2, 1, w(1))
198 do j = 1, nm
199 jgll(i,j) = w(j) ! Interpolation matrix
200 dgll(i,j) = w(j + nm) ! Derivative matrix
201 end do
202 end do
203 call rzero(a, np*np)
204 do j = 0,n
205 do i = 0,n
206 do k = 0,n
207 a(i,j) = a(i,j) + d(k,i)*b(k)*d(k,j)
208 end do
209 c(i,j) = b(i)*d(i,j)
210 end do
211 end do
212 call zwgl(zgl, bgl, nm)
213 do i = 1,n-1
214 call fd_weights_full(zgl(i), z, n, 1, w)
215 do j = 0,n
216 jgl(i,j) = w(j ) ! Interpolation matrix
217 dgl(i,j) = w(j+np) ! Derivative matrix
218 end do
219 end do
220 end subroutine semhat
221
222 !> Compute interpolation weights for points `z_to` using values at points
223 !! `z_from`.
224 !! @details
225 !! This is essentially a wrapper for calling fd_weights_full() for several
226 !! points. For each point in `z_to`, we get a set of interpolation weights of
227 !! size `n_from`.
228 !! The result is thus a matrix of weights, each row corresponding to a point
229 !! in `z_to` and each column the weight of a point in `z_from`.
230 !!
231 !! This routine is used for interpolating between elements of different
232 !! polynomial order. In other words, belonging to different
233 !! \ref space::space_t . The points are then GL, GLL, etc., depending on the
234 !! space.
235 !!
236 !! @param jh Matrix of the interpolation weights.
237 !! @param jht Same as `jh` but transposed.
238 !! @param z_to Target points for interpolation.
239 !! @param z_from Quadrature points.
240 !! @param n_to Number of points in `z_to`.
241 !! @param n_from Number of points in `z_from`.
242 !! @param derivative Specifies if we want the derivative
243 !! interpolation instead, e.g.
244 !! `derivative = 1` refers to the first derivative etc.
245 subroutine setup_intp(jh, jht, z_to, z_from, n_to, n_from, derivative)
246 implicit none
247 integer, intent(in) :: n_to, n_from, derivative
248 real(kind=rp), intent(inout) :: jh(n_to, n_from), jht(n_from, n_to)
249 real(kind=rp), intent(in) :: z_to(n_to), z_from(n_from)
250 real(kind=rp) :: w(n_from, 0:derivative)
251 integer :: i, j
252 do i = 1, n_to
253 ! This will assign w the weights for interpolating to point
254 ! zf(i) values at points zc
255 call fd_weights_full(z_to(i), z_from, n_from-1, derivative, w)
256
257 ! store each of the weights in the corresponding row/column
258 do j = 1, n_from
259 jh(i,j) = w(j, derivative)
260 jht(j,i) = w(j, derivative)
261 end do
262 end do
263 end subroutine setup_intp
264end module fast3d
double real
Fast diagonalization methods from NEKTON.
Definition fast3d.f90:61
subroutine, public semhat(a, b, c, d, z, dgll, jgll, bgl, zgl, dgl, jgl, n, w)
Generate matrices for single element, 1D operators: a = Laplacian b = diagonal mass matrix c = convec...
Definition fast3d.f90:170
subroutine, public fd_weights_full(xi, x, n, m, c)
Compute finite-difference stencil weights for evaluating derivatives up to order at a point.
Definition fast3d.f90:106
subroutine, public setup_intp(jh, jht, z_to, z_from, n_to, n_from, derivative)
Compute interpolation weights for points z_to using values at points z_from.
Definition fast3d.f90:246
Definition math.F90:60
subroutine, public rzero(a, n)
Zero a real vector.
Definition math.F90:249
integer, parameter, public xp
Definition num_types.f90:16
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
LIBRARY ROUTINES FOR SPECTRAL METHODS.
Definition speclib.f90:149
subroutine dgll(d, dt, z, nz, nzd)
Compute the derivative matrix D and its transpose DT associated with the Nth order Lagrangian interpo...
Definition speclib.f90:881
subroutine zwgll(z, w, np)
Generate NP Gauss-Lobatto Legendre points (Z) and weights (W) associated with Jacobi polynomial P(N)(...
Definition speclib.f90:180
subroutine zwgl(z, w, np)
Generate NP Gauss Legendre points Z and weights W associated with Jacobi polynomial ....
Definition speclib.f90:165