3 #include "sll_memory.h"
4 #include "sll_working_precision.h"
35 sll_real64,
dimension(:, :),
intent(out):: matrix_poisson
37 sll_int32,
intent(in)::
type
39 sll_int32 :: num_cells
43 sll_int32 :: index_tab, index_tabij
44 sll_int32 :: index_tabi_1j, index_tabij_1
45 sll_int32 :: index_tabij1, index_tabi1j
46 sll_int32 :: index_tabi1j1, index_tabi_1j_1
47 sll_int32 :: k1, k2, n
49 num_cells = mesh%num_cells
51 matrix_poisson = 0._f64
61 elseif (
type == 2) then
62 n = mesh%num_triangles
63 elseif (
type == 3) then
69 k1 = mesh%hex_coord(1, global)
70 k2 = mesh%hex_coord(2, global)
72 call mesh%index_hex_to_global(k1, k2, index_tab)
74 call mesh%index_hex_to_global(k1 - 1, k2 - 1, index_tabi_1j_1)
75 call mesh%index_hex_to_global(k1 - 1, k2, index_tabi_1j)
76 call mesh%index_hex_to_global(k1, k2 - 1, index_tabij_1)
77 call mesh%index_hex_to_global(k1, k2 + 1, index_tabij1)
78 call mesh%index_hex_to_global(k1 + 1, k2, index_tabi1j)
79 call mesh%index_hex_to_global(k1 + 1, k2 + 1, index_tabi1j1)
81 index_tabij = index_tab
83 index_tabi_1j_1 = index_tabi_1j_1 - index_tab + 2*num_cells + 2
84 index_tabi_1j = index_tabi_1j - index_tab + 2*num_cells + 2
85 index_tabij_1 = index_tabij_1 - index_tab + 2*num_cells + 2
86 index_tabij = index_tabij - index_tab + 2*num_cells + 2
87 index_tabij1 = index_tabij1 - index_tab + 2*num_cells + 2
88 index_tabi1j = index_tabi1j - index_tab + 2*num_cells + 2
89 index_tabi1j1 = index_tabi1j1 - index_tab + 2*num_cells + 2
91 if (abs(k1) == num_cells .and. abs(k2) == num_cells .or. &
92 abs(k1) == num_cells .and. k2 == 0 .or. &
93 abs(k2) == num_cells .and. k1 == 0 &
96 if (k1 == num_cells .and. k2 == 0) then
97 matrix_poisson(index_tab, index_tabij) = 1._f64
98 elseif (k1 == num_cells .and. k2 == num_cells) then
99 matrix_poisson(index_tab, index_tabij) = 1._f64
100 else if (k2 == num_cells .and. k1 == 0) then
101 matrix_poisson(index_tab, index_tabij) = 1._f64
102 else if (k1 == -num_cells .and. k2 == 0) then
103 matrix_poisson(index_tab, index_tabij) = 1._f64
104 else if (-k1 == num_cells .and. k2 == -num_cells) then
105 matrix_poisson(index_tab, index_tabij) = 1._f64
106 else if (k2 == -num_cells .and. k1 == 0) then
107 matrix_poisson(index_tab, index_tabij) = 1._f64
110 else if (k1*k2 < 0 .and. abs(k1) + abs(k2) == num_cells .or. &
111 abs(k1) == num_cells .or. abs(k2) == num_cells &
114 if (k1 == num_cells) then
115 matrix_poisson(index_tab, index_tabij) = 1._f64
116 elseif (k2 == num_cells) then
117 matrix_poisson(index_tab, index_tabij) = 1._f64
118 else if (k1*k2 < 0 .and. -k1 + k2 == num_cells) then
119 matrix_poisson(index_tab, index_tabij) = 1._f64
120 else if (k1 == -num_cells) then
121 matrix_poisson(index_tab, index_tabij) = 1._f64
122 else if (k2 == -num_cells) then
123 matrix_poisson(index_tab, index_tabij) = 1._f64
124 else if (k1*k2 < 0 .and. k1 - k2 == num_cells) then
125 matrix_poisson(index_tab, index_tabij) = 1._f64
128 elseif (abs(k1) == num_cells - 1 .and. abs(k2) == num_cells - 1 .or. &
129 abs(k1) == num_cells - 1 .and. k2 == 0 .or. &
130 abs(k2) == num_cells - 1 .and. k1 == 0 &
133 if (k1 == num_cells - 1 .and. k2 == 0) then
134 matrix_poisson(index_tab, index_tabi_1j_1) = -1._f64
135 matrix_poisson(index_tab, index_tabi_1j) = -1._f64
136 matrix_poisson(index_tab, index_tabij) = 6._f64
137 matrix_poisson(index_tab, index_tabij1) = -1._f64
138 elseif (k1 == num_cells - 1 .and. k2 == num_cells - 1) then
139 matrix_poisson(index_tab, index_tabi_1j_1) = -1._f64
140 matrix_poisson(index_tab, index_tabi_1j) = -1._f64
141 matrix_poisson(index_tab, index_tabij_1) = -1._f64
142 matrix_poisson(index_tab, index_tabij) = 6._f64
143 else if (k2 == num_cells - 1 .and. k1 == 0) then
144 matrix_poisson(index_tab, index_tabi_1j_1) = -1._f64
145 matrix_poisson(index_tab, index_tabij_1) = -1._f64
146 matrix_poisson(index_tab, index_tabij) = 6._f64
147 matrix_poisson(index_tab, index_tabi1j) = -1._f64
148 else if (k1 == -num_cells + 1 .and. k2 == 0) then
149 matrix_poisson(index_tab, index_tabij_1) = -1._f64
150 matrix_poisson(index_tab, index_tabij) = 6._f64
151 matrix_poisson(index_tab, index_tabi1j) = -1._f64
152 matrix_poisson(index_tab, index_tabi1j1) = -1._f64
153 else if (-k1 == num_cells - 1 .and. k2 == -num_cells + 1) then
154 matrix_poisson(index_tab, index_tabij) = 6._f64
155 matrix_poisson(index_tab, index_tabij1) = -1._f64
156 matrix_poisson(index_tab, index_tabi1j) = -1._f64
157 matrix_poisson(index_tab, index_tabi1j1) = -1._f64
158 else if (k2 == -num_cells + 1 .and. k1 == 0) then
159 matrix_poisson(index_tab, index_tabi_1j) = -1._f64
160 matrix_poisson(index_tab, index_tabij) = 6._f64
161 matrix_poisson(index_tab, index_tabij1) = -1._f64
162 matrix_poisson(index_tab, index_tabi1j1) = -1._f64
165 else if (k1*k2 < 0 .and. abs(k1) + abs(k2) == num_cells - 1 .or. &
166 abs(k1) == num_cells - 1 .or. abs(k2) == num_cells - 1 &
169 if (k1 == num_cells - 1) then
170 matrix_poisson(index_tab, index_tabi_1j_1) = -1._f64
171 matrix_poisson(index_tab, index_tabi_1j) = -1._f64
172 matrix_poisson(index_tab, index_tabij_1) = -1._f64
173 matrix_poisson(index_tab, index_tabij) = 6._f64
174 matrix_poisson(index_tab, index_tabij1) = -1._f64
175 elseif (k2 == num_cells - 1) then
176 matrix_poisson(index_tab, index_tabi_1j_1) = -1._f64
177 matrix_poisson(index_tab, index_tabi_1j) = -1._f64
178 matrix_poisson(index_tab, index_tabij_1) = -1._f64
179 matrix_poisson(index_tab, index_tabij) = 6._f64
180 matrix_poisson(index_tab, index_tabi1j) = -1._f64
181 else if (k1*k2 < 0 .and. -k1 + k2 == num_cells - 1) then
182 matrix_poisson(index_tab, index_tabi_1j_1) = -1._f64
183 matrix_poisson(index_tab, index_tabij_1) = -1._f64
184 matrix_poisson(index_tab, index_tabij) = 6._f64
185 matrix_poisson(index_tab, index_tabi1j) = -1._f64
186 matrix_poisson(index_tab, index_tabi1j1) = -1._f64
187 else if (k1 == -num_cells + 1) then
188 matrix_poisson(index_tab, index_tabij_1) = -1._f64
189 matrix_poisson(index_tab, index_tabij) = 6._f64
190 matrix_poisson(index_tab, index_tabij1) = -1._f64
191 matrix_poisson(index_tab, index_tabi1j) = -1._f64
192 matrix_poisson(index_tab, index_tabi1j1) = -1._f64
193 else if (k2 == -num_cells + 1) then
194 matrix_poisson(index_tab, index_tabi_1j) = -1._f64
195 matrix_poisson(index_tab, index_tabij) = 6._f64
196 matrix_poisson(index_tab, index_tabij1) = -1._f64
197 matrix_poisson(index_tab, index_tabi1j) = -1._f64
198 matrix_poisson(index_tab, index_tabi1j1) = -1._f64
199 else if (k1*k2 < 0 .and. k1 - k2 == num_cells - 1) then
200 matrix_poisson(index_tab, index_tabi_1j_1) = -1._f64
201 matrix_poisson(index_tab, index_tabi_1j) = -1._f64
202 matrix_poisson(index_tab, index_tabij) = 6._f64
203 matrix_poisson(index_tab, index_tabij1) = -1._f64
204 matrix_poisson(index_tab, index_tabi1j1) = -1._f64
209 matrix_poisson(index_tab, index_tabi_1j_1) = -1._f64
210 matrix_poisson(index_tab, index_tabi_1j) = -1._f64
211 matrix_poisson(index_tab, index_tabij_1) = -1._f64
212 matrix_poisson(index_tab, index_tabij) = 6._f64
213 matrix_poisson(index_tab, index_tabij1) = -1._f64
214 matrix_poisson(index_tab, index_tabi1j) = -1._f64
215 matrix_poisson(index_tab, index_tabi1j1) = -1._f64
224 sll_real64,
dimension(:),
intent(out) :: second_terme
225 sll_real64,
dimension(:),
intent(in) :: rho
226 sll_int32 :: num_cells, i, index_tab, k1, k2
228 sll_real64 :: f1, f2, f3, f4, f5, f6
231 num_cells = mesh%num_cells
232 step = mesh%delta**2*1.5_f64
238 do global = 1, mesh%num_pts_tot
240 k1 = mesh%hex_coord(1, global)
241 k2 = mesh%hex_coord(2, global)
243 call mesh%index_hex_to_global(k1, k2, index_tab)
252 second_terme(index_tab) = (0.75_f64*rho(global) + &
253 (f1 + f2 + f3 + f4 + f5 + f6)/24._f64)*step
265 call mesh%index_hex_to_global(num_cells, 0, index_tab)
266 second_terme(index_tab) = 0._f64
267 call mesh%index_hex_to_global(num_cells, num_cells, index_tab)
268 second_terme(index_tab) = 0._f64
269 call mesh%index_hex_to_global(0, num_cells, index_tab)
270 second_terme(index_tab) = 0._f64
271 call mesh%index_hex_to_global(-num_cells, 0, index_tab)
272 second_terme(index_tab) = 0._f64
273 call mesh%index_hex_to_global(-num_cells, -num_cells, index_tab)
274 second_terme(index_tab) = 0._f64
275 call mesh%index_hex_to_global(0, -num_cells, index_tab)
276 second_terme(index_tab) = 0._f64
280 do i = 1, num_cells - 1
283 call mesh%index_hex_to_global(num_cells, i, index_tab)
284 second_terme(index_tab) = 0._f64
286 call mesh%index_hex_to_global(num_cells - i, num_cells, index_tab)
287 second_terme(index_tab) = 0._f64
289 call mesh%index_hex_to_global(-i, num_cells - i, index_tab)
290 second_terme(index_tab) = 0._f64
292 call mesh%index_hex_to_global(-num_cells, -i, index_tab)
293 second_terme(index_tab) = 0._f64
295 call mesh%index_hex_to_global(-i, -num_cells, index_tab)
296 second_terme(index_tab) = 0._f64
298 call mesh%index_hex_to_global(num_cells - i, -i, index_tab)
299 second_terme(index_tab) = 0._f64
309 call mesh%index_hex_to_global(num_cells - 1, 1, index_tab)
310 second_terme(index_tab) = second_terme(index_tab) + 0._f64
311 call mesh%index_hex_to_global(num_cells - 1, num_cells - 1, index_tab)
312 second_terme(index_tab) = second_terme(index_tab) + 0._f64
313 call mesh%index_hex_to_global(1, num_cells - 1, index_tab)
314 second_terme(index_tab) = second_terme(index_tab) + 0._f64
315 call mesh%index_hex_to_global(-num_cells + 1, 1, index_tab)
316 second_terme(index_tab) = second_terme(index_tab) + 0._f64
317 call mesh%index_hex_to_global(-num_cells + 1, -num_cells + 1, index_tab)
318 second_terme(index_tab) = second_terme(index_tab) + 0._f64
319 call mesh%index_hex_to_global(1, -num_cells + 1, index_tab)
320 second_terme(index_tab) = second_terme(index_tab) + 0._f64
324 do i = 2, num_cells - 2
327 call mesh%index_hex_to_global(num_cells - 1, i, index_tab)
328 second_terme(index_tab) = second_terme(index_tab) + 0._f64
330 call mesh%index_hex_to_global(num_cells - 1 - i, num_cells - 1, index_tab)
331 second_terme(index_tab) = second_terme(index_tab) + 0._f64
333 call mesh%index_hex_to_global(-i, num_cells - 1 - i, index_tab)
334 second_terme(index_tab) = second_terme(index_tab) + 0._f64
336 call mesh%index_hex_to_global(-num_cells + 1, -i, index_tab)
337 second_terme(index_tab) = second_terme(index_tab) + 0._f64
339 call mesh%index_hex_to_global(-i, -num_cells + 1, index_tab)
340 second_terme(index_tab) = second_terme(index_tab) + 0._f64
342 call mesh%index_hex_to_global(num_cells - 1 - i, -i, index_tab)
343 second_terme(index_tab) = second_terme(index_tab) + 0._f64
352 sll_real64,
dimension(:) :: rho
353 sll_int32 :: k1, k2, n
356 if (abs(k1) > mesh%num_cells .or. abs(k2) > mesh%num_cells .or. &
357 (k1)*(k2) < 0 .and. (abs(k1) + abs(k2) > mesh%num_cells))
then
360 n = mesh%hex_to_global(k1, k2)
371 sll_real64,
dimension(:) :: uxn, uyn, phi, dxuxn, dyuxn, dxuyn, dyuyn
372 sll_int32,
intent(in) ::
type
373 sll_int32 :: i, h1, h2
374 sll_real64 :: r11, r12, r21, r22, det
375 sll_real64 :: phi2j1, phi1j2, phi_2j1, phi_2j_1, phi_1j_2, phi1j_2, phi2j_1, phi_1j2
376 sll_real64 :: phi_2j_2, phi2j_2, phi2j2, phi_2j2
377 sll_real64 :: phi_3j, phij_3, phij, phi1j1, phi_1j_1, phi1j_1, phi_1j1
378 sll_real64 :: phi_2j, phi_1j, phi1j, phi2j, phij_2, phij_1, phij1, phij2
379 sll_real64 :: uh1, uh2, uh1h1, uh2h2, uh1h2
381 det = (mesh%r1_x1*mesh%r2_x2 - mesh%r1_x2*mesh%r2_x1)/mesh%delta
383 r11 = +mesh%r2_x2/det
384 r12 = -mesh%r2_x1/det
385 r21 = -mesh%r1_x2/det
386 r22 = +mesh%r1_x1/det
390 do i = 1, mesh%num_pts_tot
392 h1 = mesh%hex_coord(1, i)
393 h2 = mesh%hex_coord(2, i)
437 uh1 = (phi_2j + 8._f64*(phi1j - phi_1j) - phi2j)/(12._f64*mesh%delta)
438 uh2 = (phij_2 + 8._f64*(phij1 - phij_1) - phij2)/(12._f64*mesh%delta)
454 uxn(i) = -(uh1*r12 + uh2*r22)
455 uyn(i) = +(uh1*r11 + uh2*r21)
469 uh1h1 = (-phi_2j + 16._f64*(phi_1j + phi1j) - 30._f64*phij - phi2j)/(12._f64*mesh%delta**2)
470 uh2h2 = (-phij_2 + 16._f64*(phij_1 + phij1) - 30._f64*phij - phij2)/(12._f64*mesh%delta**2)
471 uh1h2 = (64._f64*(phi1j1 - phi1j_1 - phi_1j1 + phi_1j_1) + &
472 8._f64*(-phi2j1 - phi1j2 - phi_2j_1 - phi_1j_2 + phi_1j2 + phi_2j1 + phi1j_2 + phi2j_1) + &
473 phi2j2 - phi2j_2 - phi_2j2 + phi_2j_2)/(144._f64*mesh%delta**2)
475 dxuxn(i) = -(uh1h1*r11*r12 + uh1h2*(r11*r22 + r12*r21) + uh2h2*r21*r22)
477 dyuyn(i) = +(uh1h1*r11*r12 + uh1h2*(r11*r22 + r12*r21) + uh2h2*r21*r22)
478 dxuyn(i) = +(uh1h1*r11*r11 + 2._f64*uh1h2*r11*r21 + uh2h2*r21*r21)
481 dyuxn(i) = -(-phi_2j_2 + 16._f64*(phi_1j_1 + phi1j1) - 30._f64*phij - phi2j2)/ &
482 (12._f64*mesh%delta**2)
506 sll_real64,
dimension(:) :: phi
507 sll_int32 :: k1, k2, n
510 if (abs(k1) > mesh%num_cells .or. abs(k2) > mesh%num_cells .or. &
511 (k1)*(k2) < 0 .and. (abs(k1) + abs(k2) > mesh%num_cells))
then
514 n = mesh%hex_to_global(k1, k2)
subroutine, public sll_s_hex_second_terme_poisson(second_terme, mesh, rho)
real(kind=f64) function value_if_inside_phi(k1, k2, mesh, phi)
subroutine, public sll_s_hex_matrix_poisson(matrix_poisson, mesh, type)
real(kind=f64) function value_if_inside_rho(k1, k2, mesh, rho)
subroutine, public sll_s_compute_hex_fields(mesh, uxn, uyn, dxuxn, dyuxn, dxuyn, dyuyn, phi, type)
type(sll_t_hex_mesh_2d) function, pointer, public sll_f_new_hex_mesh_2d(num_cells, center_x1, center_x2, r11, r12, r21, r22, r31, r32, radius, EXTRA_TABLES)
Creates and initializes a new hexagonal mesh.