Octopus
maxwell_boundary_op.F90
Go to the documentation of this file.
1!! Copyright (C) 2019 R. Jestaedt, H. Appel, F. Bonafe, M. Oliveira, N. Tancogne-Dejean
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17
18#include "global.h"
19
21 use accel_oct_m
25 use debug_oct_m
28 use global_oct_m
29 use grid_oct_m
30 use index_oct_m
31 use io_oct_m
33 use math_oct_m
35 use math_oct_m
38 use mesh_oct_m
40 use mpi_oct_m
42 use parser_oct_m
45 use types_oct_m
46 use unit_oct_m
49 use space_oct_m
51
52 implicit none
53
54 private
55 public :: &
58 bc_mxll_t, &
63
64 type pml_t
65 real(real64) :: width
66 integer :: points_number
67 integer, allocatable :: points_map(:)
68 integer, allocatable :: points_map_inv(:)
69 real(real64) :: power
70 real(real64) :: refl_error
71 real(real64), allocatable :: kappa(:,:)
72 real(real64), allocatable :: sigma_e(:,:)
73 real(real64), allocatable :: sigma_m(:,:)
74 real(real64), allocatable :: a(:,:)
75 real(real64), allocatable :: b(:,:)
76 real(real64), allocatable :: c(:,:)
77 real(real64), allocatable :: mask(:)
78 complex(real64), allocatable :: aux_ep(:,:,:)
79 complex(real64), allocatable :: aux_mu(:,:,:)
80 complex(real64), allocatable :: conv_plus(:,:,:)
81 complex(real64), allocatable :: conv_minus(:,:,:)
82 complex(real64), allocatable :: conv_plus_old(:,:,:)
83 complex(real64), allocatable :: conv_minus_old(:,:,:)
84 logical :: parameters_initialized = .false.
85 ! GPU buffers
86 type(accel_mem_t) :: buff_a, buff_b, buff_c, buff_conv_plus, buff_conv_minus, buff_map, buff_conv_plus_old
87 end type pml_t
88
89 type bc_mxll_t
90 integer :: bc_type(3)
91 integer :: bc_ab_type(3)
92 real(real64) :: bc_bounds(2, 3)
93 logical :: ab_user_def
94 real(real64), allocatable :: ab_ufn(:)
95
96 real(real64) :: ab_width
97 real(real64) :: mask_width
98 integer :: mask_points_number(3)
99 integer, allocatable :: mask_points_map(:,:)
100 real(real64), allocatable :: mask(:,:)
101
102 type(pml_t) :: pml
103 type(single_medium_box_t) :: medium(3)
104
105 integer :: constant_points_number
106 integer, allocatable :: constant_points_map(:)
107 complex(real64), allocatable :: constant_rs_state(:,:)
108 type(accel_mem_t) :: buff_constant_points_map
109
110 integer :: mirror_points_number(3) = 0
111 integer, allocatable :: mirror_points_map(:,:)
112
113 logical :: do_plane_waves = .false. !! look here afterwards
114 type(external_waves_t) :: plane_wave
115 logical :: plane_waves_dims(1:3) = .false.
116
117 real(real64) :: zero_width
118 integer :: zero_points_number(3)
119 integer, allocatable :: zero_points_map(:,:)
120 real(real64), allocatable :: zero(:,:)
121 end type bc_mxll_t
122
123 integer, public, parameter :: &
124 MXLL_BC_ZERO = 0, &
125 mxll_bc_constant = 1, &
126 mxll_bc_mirror_pec = 2, &
127 mxll_bc_mirror_pmc = 3, &
130
131 integer, parameter :: &
132 MXLL_PLANE_WAVES_NEGATIVE_SIDE = -1, &
134
135 integer, public, parameter :: &
136 MXLL_AB_NOT_ABSORBING = 0, &
141contains
143 ! ---------------------------------------------------------
144 subroutine bc_mxll_init(bc, namespace, space, gr, st)
145 type(bc_mxll_t), intent(inout) :: bc
146 type(namespace_t), intent(in) :: namespace
147 class(space_t), intent(in) :: space
148 type(grid_t), intent(in) :: gr
149 type(states_mxll_t), intent(inout) :: st
151 integer :: idim, nlines, icol, ncols, ab_shape_dim
152 real(real64) :: bounds(2, space%dim), ab_bounds(2, space%dim)
153 type(block_t) :: blk
154 character(len=1024) :: string
155 character(len=50) :: ab_type_str
156 character(len=1), dimension(3), parameter :: dims = ["x", "y", "z"]
157 logical :: plane_waves_check, ab_mask_check, ab_pml_check, plane_waves_set
158 logical :: constant_check, zero_check
159 real(real64) :: ep_factor, mu_factor, sigma_e_factor, sigma_m_factor
160
161 push_sub(bc_mxll_init)
163 call profiling_in('BC_MXLL_INIT')
165 plane_waves_set = .false.
166 bc%bc_type(:) = mxll_bc_zero ! default boundary condition is zero
167 bc%medium(:)%points_number = 0
168 bc%medium(:)%bdry_number = 0
170 !%Variable MaxwellBoundaryConditions
171 !%Type block
172 !%Section Maxwell
173 !%Description
174 !% Defines boundary conditions for the electromagnetic field propagation.
175 !%
176 !% Example:
177 !%
178 !% <tt>%MaxwellBoundaryConditions
179 !% <br>&nbsp;&nbsp; zero | mirror_pec | constant
180 !% <br>%</tt>
181 !%
182 !%
183 !%Option zero 0
184 !% Boundaries are not touched by the Maxwell code - they are set by the normal boundary conditions.
185 !% This is zero boundary conditions for non-periodic systems and periodic boundary conditions if
186 !% PeriodicDimensions is set.
187 !%Option constant 1
188 !% Boundaries are set to a constant.
189 !%Option mirror_pec 2
190 !% Perfect electric conductor.
191 !%Option mirror_pmc 3
192 !% Perfect magnetic conductor.
193 !%Option plane_waves 4
194 !% Boundaries feed in plane waves.
195 !%Option medium 6
196 !% Boundaries as linear medium (not yet implemented).
197 !%End
198 if (parse_block(namespace, 'MaxwellBoundaryConditions', blk) == 0) then
199
200 call messages_print_with_emphasis(msg='Maxwell Boundary Conditions:', namespace=namespace)
201 ! find out how many lines (i.e. states) the block has
202 nlines = parse_block_n(blk)
203 if (nlines /= 1) then
204 call messages_input_error(namespace, 'MaxwellBoundaryConditions', 'should consist of one line')
205 end if
206 ncols = parse_block_cols(blk, 0)
207 if (ncols /= 3) then
208 call messages_input_error(namespace, 'MaxwellBoundaryConditions', 'should consist of three columns')
209 end if
210 do icol = 1, ncols
211 call parse_block_integer(blk, 0, icol-1, bc%bc_type(icol))
212 end do
213 call parse_block_end(blk)
214 end if
215
216 do icol = 1, 3
217 select case (bc%bc_type(icol))
218 case (mxll_bc_zero)
219 string = 'Zero'
220 case (mxll_bc_constant)
221 string = 'Constant'
222 case (mxll_bc_mirror_pec)
223 string = 'PEC Mirror'
224 case (mxll_bc_mirror_pmc)
225 string = 'PMC Mirror'
227 string = 'Plane waves'
228 case (mxll_bc_medium)
229 string = 'Medium boundary'
230 case default
231 write(message(1),'(a)') 'Unknown Maxwell boundary condition'
232 call messages_fatal(1, namespace=namespace)
233 end select
234 write(message(1),'(a,I1,a,a)') 'Maxwell boundary condition in direction ', icol, ': ', trim(string)
235 call messages_info(1, namespace=namespace)
236 if (plane_waves_set .and. .not. (parse_is_defined(namespace, 'MaxwellIncidentWaves'))) then
237 write(message(1),'(a)') 'Input: Maxwell boundary condition option is set to "plane_waves".'
238 write(message(2),'(a)') 'Input: User defined Maxwell plane waves have to be defined!'
239 call messages_fatal(2, namespace=namespace)
240 end if
241 end do
242
243 plane_waves_check = .false.
244 ab_mask_check = .false.
245 ab_pml_check = .false.
246 constant_check = .false.
247 zero_check = .false.
248
249 bc%ab_user_def = .false.
250 bc%bc_ab_type(:) = mxll_ab_not_absorbing ! default option
251
252 !%Variable MaxwellAbsorbingBoundaries
253 !%Type block
254 !%Section Maxwell
255 !%Description
256 !% Type of absorbing boundaries used for Maxwell propagation in each direction.
257 !%
258 !% Example:
259 !%
260 !% <tt>%MaxwellAbsorbingBoundaries
261 !% <br>&nbsp;&nbsp; cpml | cpml | cpml
262 !% <br>%</tt>
263 !%
264 !%Option not_absorbing 0
265 !% No absorbing boundaries.
266 !%Option mask 1
267 !% A mask equal to the wavefunctions mask is applied to the Maxwell states at the boundaries
268 !%Option cpml 2
269 !% Perfectly matched layer absorbing boundary
270 !%Option mask_zero 7
271 !% Absorbing boundary region is set to zero
272 !%End
273
274 if (parse_block(namespace, 'MaxwellAbsorbingBoundaries', blk) == 0) then
275 ! find out how many lines (i.e. states) the block has
276 nlines = parse_block_n(blk)
277 if (nlines /= 1) then
278 message(1) = 'MaxwellAbsorbingBounaries has to consist of one line!'
279 call messages_fatal(1, namespace=namespace)
280 end if
281
282 ncols = parse_block_cols(blk, 0)
283 if (ncols /= 3) then
284 message(1) = 'MaxwellAbsorbingBoundaries has to consist of three columns!'
285 call messages_fatal(1, namespace=namespace)
286 end if
287
288 do icol = 1, ncols
289 call parse_block_integer(blk, 0, icol-1, bc%bc_ab_type(icol))
290 end do
291
292 call parse_block_end(blk)
293 end if
294
295 do idim = 1, 3
296 if (bc%bc_ab_type(idim) == mxll_ab_mask) ab_mask_check = .true.
297 if (bc%bc_ab_type(idim) == mxll_ab_cpml) ab_pml_check = .true.
298 if (bc%bc_type(idim) == mxll_bc_constant) constant_check = .true.
299 if (bc%bc_type(idim) == mxll_bc_zero) zero_check = .true.
300 end do
301
302 if (ab_mask_check .or. ab_pml_check) then
303
304 call messages_print_with_emphasis(msg='Maxwell Absorbing Boundaries', namespace=namespace)
305 write(message(1),'(a)') "Please keep in mind that"
306 write(message(2),'(a)') "with larger ABWidth, comes great responsibility."
307 write(message(3),'(a)') "AbsorbingBoundaries occupy space in the simulation box,"
308 write(message(4),'(a)') "hence choose your Lsize wisely."
309 call messages_info(4, namespace=namespace)
310
311 end if
312
313 bounds(1, :) = (gr%idx%nr(2, :) - gr%idx%enlarge(:))*gr%spacing(:)
314 bounds(2, :) = gr%idx%nr(2, :) * gr%spacing(:)
315 do idim = 1, st%dim
316 select case (bc%bc_type(idim))
317
318 case (mxll_bc_zero, mxll_bc_mirror_pec, mxll_bc_mirror_pmc)
319
320 bounds(1, idim) = (gr%idx%nr(2, idim) - gr%idx%enlarge(idim))*gr%spacing(idim)
321 bounds(2, idim) = (gr%idx%nr(2, idim)) * gr%spacing(idim)
322
323 case (mxll_bc_constant)
324
325 bounds(1, idim) = (gr%idx%nr(2, idim) - 2*gr%idx%enlarge(idim))*gr%spacing(idim)
326 bounds(2, idim) = (gr%idx%nr(2, idim)) * gr%spacing(idim)
327
329
330 bounds(1, idim) = (gr%idx%nr(2, idim) - 2*gr%idx%enlarge(idim))*gr%spacing(idim)
331 bounds(2, idim) = (gr%idx%nr(2, idim)) * gr%spacing(idim)
332 plane_waves_check = .true.
333 bc%do_plane_waves = .true.
334
335 case (mxll_bc_medium)
336 call bc_mxll_medium_init(gr, namespace, bounds, idim, ep_factor, mu_factor, sigma_e_factor, sigma_m_factor)
337 call maxwell_medium_points_mapping(bc, gr, bounds)
338 call bc_mxll_generate_medium(bc, space, gr, bounds, ep_factor, mu_factor, sigma_e_factor, sigma_m_factor)
339
340 end select
341
342 select type (box => gr%box)
343 type is (box_sphere_t)
344 ab_shape_dim = 1
345 if (space%is_periodic()) then
346 message(1) = "Sphere box shape can only work for non-periodic systems"
347 call messages_fatal(1, namespace=namespace)
348 end if
349 ab_bounds(1, idim) = bounds(1, idim)
350 ab_bounds(2, idim) = bounds(1, idim)
351 type is (box_parallelepiped_t)
352 if (.not. box%axes%orthogonal) then
353 message(1) = "Maxwell propagation does not work for non-orthogonal grids."
354 call messages_fatal(1, namespace=namespace)
355 end if
356
357 ab_shape_dim = space%dim
358 ab_bounds(1, idim) = bounds(1, idim)
359 ab_bounds(2, idim) = bounds(1, idim)
360 class default
361 message(1) = "Box shape for Maxwell propagation not supported yet"
362 call messages_fatal(1, namespace=namespace)
363 end select
364
365 if (bc%bc_ab_type(idim) /= mxll_ab_not_absorbing) then
366
367 call messages_print_var_option("MaxwellAbsorbingBoundaries", bc%bc_ab_type(idim), namespace=namespace)
368
369 select case (bc%bc_ab_type(idim))
370 case (mxll_ab_mask_zero)
371 call bc_mxll_ab_bounds_init(bc, gr, namespace, ab_bounds, idim)
372 bc%zero_width = bc%ab_width
373
374 case (mxll_ab_mask)
375 call bc_mxll_ab_bounds_init(bc, gr, namespace, ab_bounds, idim)
376 bc%mask_width = bc%ab_width
377
378 case (mxll_ab_cpml)
379 call bc_mxll_pml_init(bc, gr, namespace, ab_bounds, idim)
380
381 case default
382 message(1) = "Absorbing boundary type not implemented for Maxwell propagation"
383 call messages_fatal(1, namespace=namespace)
384 end select
385
386 end if
387
388 select case (bc%bc_ab_type(idim))
390 bounds(1, idim) = ab_bounds(1, idim)
391 bounds(2, idim) = bounds(2, idim)
392 bc%bc_bounds(:, idim) = bounds(:, idim)
393 case default
394 bc%bc_bounds(:, idim) = bounds(:, idim)
395 end select
396
397 select type (box => gr%box)
398 type is (box_parallelepiped_t)
399 select case (bc%bc_ab_type(idim))
400 case (mxll_ab_cpml)
401 ab_type_str = "PML"
402 case (mxll_ab_mask)
403 ab_type_str = "Mask"
404 case (mxll_ab_mask_zero)
405 ab_type_str = "Zero"
406 case default
407 ab_type_str = ""
408 end select
409
410 if (bc%bc_ab_type(idim) == mxll_ab_cpml .or. bc%bc_ab_type(idim) == mxll_ab_mask .or. &
411 bc%bc_ab_type(idim) == mxll_ab_mask_zero) then
412 string = trim(ab_type_str)//" Absorbing Boundary"
413 write(string,'(2a, f10.3,3a)') trim(string), " in "//dims(idim)//' direction spans from: ', &
414 units_from_atomic(units_inp%length, ab_bounds(1, idim) ), ' [', &
415 trim(units_abbrev(units_inp%length)), ']'
416 write(message(1),'(a)') trim(string)
417
418 string = "to "
419 write(string,'(a,f10.3,3a)') trim(string),&
420 units_from_atomic(units_inp%length, ab_bounds(2, idim) ), ' [', &
421 trim(units_abbrev(units_inp%length)), ']'
422
423 write(message(2),'(a)') trim(string)
424 call messages_info(2, namespace=namespace)
425 end if
426
427 class default
428
429 write(message(1),'(a,es10.3,3a)') &
430 " Lower bound = ", units_from_atomic(units_inp%length, ab_bounds(1, idim) ),&
431 ' [', trim(units_abbrev(units_inp%length)), ']'
432 write(message(2),'(a,es10.3,3a)') &
433 " Upper bound = ", units_from_atomic(units_inp%length, ab_bounds(2, idim) ),&
434 ' [', trim(units_abbrev(units_inp%length)), ']'
435 call messages_info(2, namespace=namespace)
436
437 end select
438
439 end do
440
441 ! initialization of surfaces
442 call maxwell_surfaces_init(gr, st, bounds)
443
444 ! mapping of mask boundary points
445 if (ab_mask_check) then
446 call maxwell_mask_points_mapping(bc, gr, ab_bounds)
447 end if
448
449 ! mapping of pml boundary points
450 if (ab_pml_check) then
451 call maxwell_pml_points_mapping(bc, gr, ab_bounds)
452 end if
453
454 ! mapping of constant boundary points
455 if (constant_check) then
456 bounds(1, :) = gr%idx%nr(2, :) * gr%spacing(:)
457 bounds(2, :) = gr%idx%nr(2, :) * gr%spacing(:)
458 do idim = 1, st%dim
459 if (bc%bc_type(idim) == mxll_bc_constant) then
460 bounds(1, idim) = (gr%idx%nr(2, idim) - 2*gr%idx%enlarge(idim))*gr%spacing(idim)
461 bounds(2, idim) = (gr%idx%nr(2, idim)) * gr%spacing(idim)
462 end if
463 end do
464 call maxwell_constant_points_mapping(bc, gr, bounds)
465 end if
466
467 ! mapping of plane waves boundary points
468 if (plane_waves_check) then
469 bounds(1, :) = gr%idx%nr(2, :) * gr%spacing(:)
470 bounds(2, :) = gr%idx%nr(2, :) * gr%spacing(:)
471 do idim = 1, st%dim
472 if (bc%bc_type(idim) == mxll_bc_plane_waves) then
473 bounds(1, idim) = (gr%idx%nr(2, idim) - 2*gr%idx%enlarge(idim))*gr%spacing(idim)
474 bounds(2, idim) = (gr%idx%nr(2, idim)) * gr%spacing(idim)
475 end if
476 end do
477 call maxwell_plane_waves_points_mapping(bc, gr, bounds)
478 call external_waves_init(bc%plane_wave, namespace)
479 end if
480
481 ! mapping of zero points
482 if (zero_check) then
483 bounds(1, :) = gr%idx%nr(2, :) * gr%spacing(:)
484 bounds(2, :) = gr%idx%nr(2, :) * gr%spacing(:)
485 do idim = 1, st%dim
486 if (bc%bc_type(idim) == mxll_bc_zero) then
487 bounds(1, idim) = (gr%idx%nr(2, idim) - gr%idx%enlarge(idim))*gr%spacing(idim)
488 bounds(2, idim) = (gr%idx%nr(2, idim)) * gr%spacing(idim)
489 end if
490 end do
491 call maxwell_zero_points_mapping(bc, gr, bounds)
492 end if
493
494 if (ab_mask_check) then
495 call bc_mxll_generate_mask(bc, gr, ab_bounds)
496 end if
497
498 if (ab_pml_check) then
499 call bc_mxll_generate_pml(bc, space)
500 end if
501
502 !call bc_generate_zero(bc, gr, ab_bounds)
503
504 if (debug%info) call bc_mxll_write_info(bc, gr, namespace, space)
505
506 if (ab_mask_check .or. ab_pml_check) then
507 call messages_print_with_emphasis(namespace=namespace)
508 end if
509
510 call profiling_out('BC_MXLL_INIT')
511
512 pop_sub(bc_mxll_init)
513 end subroutine bc_mxll_init
514
515 ! ---------------------------------------------------------
516 subroutine bc_mxll_end(bc)
517 type(bc_mxll_t), intent(inout) :: bc
518
519 integer :: idim
520
521 push_sub(bc_mxll_end)
522
523 safe_deallocate_a(bc%ab_ufn)
524
525 safe_deallocate_a(bc%mask_points_map)
526 safe_deallocate_a(bc%mask)
527
528 call pml_end(bc%pml)
529 do idim = 1, 3
530 call single_medium_box_end(bc%medium(idim))
531 end do
532
533 safe_deallocate_a(bc%constant_points_map)
534 safe_deallocate_a(bc%constant_rs_state)
535 if (accel_is_enabled()) then
536 call accel_free_buffer(bc%buff_constant_points_map)
537 end if
538
539 safe_deallocate_a(bc%mirror_points_map)
540
541 call external_waves_end(bc%plane_wave)
542
543 safe_deallocate_a(bc%zero_points_map)
544 safe_deallocate_a(bc%zero)
545
546 pop_sub(bc_mxll_end)
547 end subroutine bc_mxll_end
548
549 ! ---------------------------------------------------------
550 subroutine pml_end(pml)
551 type(pml_t), intent(inout) :: pml
552
553 push_sub(pml_end)
554
555 safe_deallocate_a(pml%points_map)
556 safe_deallocate_a(pml%points_map_inv)
557 safe_deallocate_a(pml%kappa)
558 safe_deallocate_a(pml%sigma_e)
559 safe_deallocate_a(pml%sigma_m)
560 safe_deallocate_a(pml%a)
561 safe_deallocate_a(pml%b)
562 safe_deallocate_a(pml%c)
563 safe_deallocate_a(pml%mask)
564 safe_deallocate_a(pml%aux_ep)
565 safe_deallocate_a(pml%aux_mu)
566 safe_deallocate_a(pml%conv_plus)
567 safe_deallocate_a(pml%conv_minus)
568 safe_deallocate_a(pml%conv_plus_old)
569 safe_deallocate_a(pml%conv_minus_old)
570 if (accel_is_enabled()) then
571 call accel_free_buffer(pml%buff_map)
572 call accel_free_buffer(pml%buff_a)
573 call accel_free_buffer(pml%buff_b)
574 call accel_free_buffer(pml%buff_c)
575 call accel_free_buffer(pml%buff_conv_plus)
576 call accel_free_buffer(pml%buff_conv_minus)
577 call accel_free_buffer(pml%buff_conv_plus_old)
578 end if
579
580
581 pop_sub(pml_end)
582 end subroutine pml_end
583
584
585
586 ! ---------------------------------------------------------
587 subroutine bc_mxll_medium_init(gr, namespace, bounds, idim, ep_factor, mu_factor, sigma_e_factor, sigma_m_factor)
588 type(grid_t), intent(in) :: gr
589 type(namespace_t), intent(in) :: namespace
590 real(real64), contiguous, intent(inout) :: bounds(:,:)
591 integer, intent(in) :: idim
592 real(real64), intent(out) :: ep_factor
593 real(real64), intent(out) :: mu_factor
594 real(real64), intent(out) :: sigma_e_factor
595 real(real64), intent(out) :: sigma_m_factor
596
597 real(real64) :: width
598
599 push_sub(bc_mxll_medium_init)
600
601 call profiling_in('BC_MXLL_MEDIUM_INIT')
602
603 !%Variable MediumWidth
604 !%Type float
605 !%Default 0.0 a.u.
606 !%Section Maxwell::Boundaries
607 !%Description
608 !% Width of the boundary region with medium
609 !%End
610 call parse_variable(namespace, 'MediumWidth', m_zero, width, units_inp%length)
611 bounds(1,idim) = ( gr%idx%nr(2, idim) - gr%idx%enlarge(idim) ) * gr%spacing(idim)
612 bounds(1,idim) = bounds(1,idim) - width
613 bounds(2,idim) = ( gr%idx%nr(2, idim) ) * gr%spacing(idim)
614
615 !%Variable MediumEpsilonFactor
616 !%Type float
617 !%Default 1.0.
618 !%Section Maxwell::Boundaries
619 !%Description
620 !% Linear medium electric susceptibility.
621 !%End
622 call parse_variable(namespace, 'MediumEpsilonFactor', m_one, ep_factor, unit_one)
623
624 !%Variable MediumMuFactor
625 !%Type float
626 !%Default 1.0
627 !%Section Maxwell::Boundaries
628 !%Description
629 !% Linear medium magnetic susceptibility.
630 !%End
631 call parse_variable(namespace, 'MediumMuFactor', m_one, mu_factor, unit_one)
632
633 !%Variable MediumElectricSigma
634 !%Type float
635 !%Default 0.
636 !%Section Maxwell::Boundaries
637 !%Description
638 !% Electric conductivity of the linear medium.
639 !%End
640
641 call parse_variable(namespace, 'MediumElectricSigma', m_zero, sigma_e_factor, unit_one)
642 !%Variable MediumMagneticSigma
643 !%Type float
644 !%Default 0.
645 !%Section Maxwell::Boundaries
646 !%Description
647 !% Magnetic conductivity of the linear medium.
648 !%End
649 call parse_variable(namespace, 'MediumMagneticSigma', m_zero, sigma_m_factor, unit_one)
650
651 call profiling_out('BC_MXLL_MEDIUM_INIT')
652
653 pop_sub(bc_mxll_medium_init)
654 end subroutine bc_mxll_medium_init
655
656 ! ---------------------------------------------------------
657 subroutine bc_mxll_ab_bounds_init(bc, gr, namespace, ab_bounds, idim)
658 type(bc_mxll_t), intent(inout) :: bc
659 type(grid_t), intent(in) :: gr
660 type(namespace_t), intent(in) :: namespace
661 real(real64), contiguous, intent(inout) :: ab_bounds(:,:)
662 integer, intent(in) :: idim
663
664 real(real64) :: default_width
665
666 push_sub(bc_mxll_ab_bounds_init)
667
668 !%Variable MaxwellABWidth
669 !%Type float
670 !%Section Maxwell::Boundaries
671 !%Description
672 !% Width of the region used to apply the absorbing boundaries. The default value is twice
673 !% the derivative order.
674 !%End
675
676 default_width = m_two * gr%der%order * maxval(gr%spacing(1:3))
677 call parse_variable(namespace, 'MaxwellABWidth', default_width, bc%ab_width, units_inp%length)
678
679 if (bc%ab_width < default_width) then
680 bc%ab_width = default_width
681 write(message(1),'(a)') 'Absorbing boundary width has to be larger or equal than twice the derivatives order times spacing!'
682 write(message(2),'(a,es10.3)') 'Absorbing boundary width is set to: ', default_width
683 call messages_info(2, namespace=namespace)
684 end if
685
686 ab_bounds(1, idim) = ab_bounds(2, idim) - bc%ab_width
687
689 end subroutine bc_mxll_ab_bounds_init
690
691 ! ---------------------------------------------------------
692 subroutine bc_mxll_pml_init(bc, gr, namespace, ab_bounds, idim)
693 type(bc_mxll_t), intent(inout) :: bc
694 type(grid_t), intent(in) :: gr
695 type(namespace_t), intent(in) :: namespace
696 real(real64), contiguous, intent(inout) :: ab_bounds(:,:)
697 integer, intent(in) :: idim
698
699 push_sub(bc_mxll_pml_init)
700
701 call bc_mxll_ab_bounds_init(bc, gr, namespace, ab_bounds, idim)
702 bc%pml%width = bc%ab_width
703
704 !%Variable MaxwellABPMLPower
705 !%Type float
706 !%Default 3.5
707 !%Section Maxwell::Boundaries
708 !%Description
709 !% Exponential of the polynomial profile for the non-physical conductivity of the PML.
710 !% Should be between 2 and 4
711 !%End
712 call parse_variable(namespace, 'MaxwellABPMLPower', 3.5_real64, bc%pml%power, unit_one)
713
714 !%Variable MaxwellABPMLReflectionError
715 !%Type float
716 !%Default 1.0e-16
717 !%Section Maxwell::Boundaries
718 !%Description
719 !% Tolerated reflection error for the PML
720 !%End
721 call parse_variable(namespace, 'MaxwellABPMLReflectionError', 1.0e-16_real64, bc%pml%refl_error, unit_one)
722
723 pop_sub(bc_mxll_pml_init)
724 end subroutine bc_mxll_pml_init
725
726 ! ---------------------------------------------------------
727 subroutine bc_mxll_write_info(bc, mesh, namespace, space)
728 type(bc_mxll_t), intent(in) :: bc
729 class(mesh_t), intent(in) :: mesh
730 type(namespace_t), intent(in) :: namespace
731 class(space_t), intent(in) :: space
732
733 integer :: err, idim, idim2
734 real(real64), allocatable :: tmp(:)
735 logical :: mask_check, pml_check, medium_check
736 character(1) :: dim_label(3)
737
738 push_sub(bc_mxll_write_info)
739
740 call profiling_in('BC_MXLL_WRITE_INFO')
741
742 mask_check = .false.
743 pml_check = .false.
744 medium_check = .false.
745
746 dim_label = (/'x', 'y', 'z'/)
747
748 do idim = 1, 3
749 if (bc%bc_ab_type(idim) == mxll_ab_mask) then
750 mask_check = .true.
751 end if
752 if (bc%bc_ab_type(idim) == mxll_ab_cpml) then
753 pml_check = .true.
754 end if
755 if (bc%bc_type(idim) == mxll_bc_medium) then
756 medium_check = .true.
757 end if
758 end do
759
760 if (mask_check) then
761 safe_allocate(tmp(1:mesh%np))
762 do idim = 1, 3
763 tmp(:) = m_zero
764 call get_mask_io_function(bc%mask, bc, tmp, idim)
765 call write_files("maxwell_mask", tmp)
766 end do
767 safe_deallocate_a(tmp)
768 else if (pml_check) then
769 safe_allocate(tmp(1:mesh%np))
770 do idim = 1, 3
771 ! sigma for electric field dim = idim
772 tmp(:) = m_one
773 call get_pml_io_function(bc%pml%sigma_e(:, idim), bc, tmp)
774 call write_files("maxwell_sigma_e-"//dim_label(idim), tmp)
775
776 ! sigma for magnetic dim = idim
777 tmp(:) = m_zero
778 call get_pml_io_function(bc%pml%sigma_m(:, 1), bc, tmp)
779 call write_files("maxwell_sigma_m-"//dim_label(idim), tmp)
780
781 ! pml_a for electric field dim = idim
782 tmp(:) = m_zero
783 call get_pml_io_function(real(bc%pml%a(:, idim), real64), bc, tmp)
784 call write_files("maxwell_sigma_pml_a_e-"//dim_label(idim), tmp)
785 end do
786 safe_deallocate_a(tmp)
787 end if
788
789 if (medium_check) then
790 safe_allocate(tmp(1:mesh%np))
791 do idim = 1, 3
792 ! medium epsilon
793 tmp(:) = p_ep
794 call get_medium_io_function(bc%medium(idim)%ep, bc, tmp, idim)
795 call write_files("maxwell_ep"//dim_label(idim), tmp)
796 ! medium mu
797 tmp(:) = p_mu
798 call get_medium_io_function(bc%medium(idim)%mu, bc, tmp, idim)
799 call write_files("maxwell_mu"//dim_label(idim), tmp)
800 ! medium epsilon
801 tmp(:) = p_c
802 call get_medium_io_function(bc%medium(idim)%c, bc, tmp, idim)
803 call write_files("maxwell_c"//dim_label(idim), tmp)
804 do idim2 = 1, 3
805 ! medium epsilon aux field dim = idim
806 tmp(:) = m_zero
807 call get_medium_io_function(bc%medium(idim)%aux_ep(:, idim2), bc, tmp, idim)
808 call write_files("maxwell_aux_ep-"//dim_label(idim)//"-"//dim_label(idim2), tmp)
809
810 ! medium mu aux field dim = idim
811 tmp(:) = m_zero
812 call get_medium_io_function(bc%medium(idim)%aux_mu(:, idim2), bc, tmp, idim)
813 call write_files("maxwell_aux_mu-"//dim_label(idim)//"-"//dim_label(idim2), tmp)
814 end do
815 end do
816
817 safe_deallocate_a(tmp)
818 end if
819
820 call profiling_out('BC_MXLL_WRITE_INFO')
821
822 pop_sub(bc_mxll_write_info)
823 contains
824
825 subroutine get_pml_io_function(pml_func, bc, io_func)
826 real(real64), intent(in) :: pml_func(:)
827 type(bc_mxll_t), intent(in) :: bc
828 real(real64), contiguous, intent(inout) :: io_func(:)
829
830 integer :: ip, ip_in
831
832 do ip_in = 1, bc%pml%points_number
833 ip = bc%pml%points_map(ip_in)
834 io_func(ip) = pml_func(ip_in)
835 end do
836
837 end subroutine get_pml_io_function
838
839 subroutine get_mask_io_function(mask_func, bc, io_func, idim)
840 real(real64), contiguous, intent(in) :: mask_func(:,:)
841 type(bc_mxll_t), intent(in) :: bc
842 real(real64), contiguous, intent(inout) :: io_func(:)
843 integer, intent(in) :: idim
844
845 integer :: ip, ip_in
846
847 do ip_in = 1, bc%mask_points_number(idim)
848 ip = bc%mask_points_map(ip_in, idim)
849 io_func(ip) = mask_func(ip_in, idim)
850 end do
851
852 end subroutine get_mask_io_function
853
854 subroutine get_medium_io_function(medium_func, bc, io_func, idim)
855 real(real64), contiguous, intent(in) :: medium_func(:)
856 type(bc_mxll_t), intent(in) :: bc
857 real(real64), contiguous, intent(inout) :: io_func(:)
858 integer, intent(in) :: idim
859
860 integer :: ip, ip_in
861
862 do ip_in = 1, bc%medium(idim)%points_number
863 ip = bc%medium(idim)%points_map(ip_in)
864 io_func(ip) = medium_func(ip_in)
865 end do
866
867 end subroutine get_medium_io_function
868
869 subroutine write_files(filename, tmp)
870 character(len=*), intent(in) :: filename
871 real(real64), contiguous, intent(in) :: tmp(:)
872
873 call dio_function_output(io_function_fill_how("VTK"), "./td.general", trim(filename), namespace, space, mesh, tmp, &
874 unit_one, err)
875 call dio_function_output(io_function_fill_how("AxisX"), "./td.general", trim(filename), namespace, space, mesh, tmp, &
876 unit_one, err)
877 call dio_function_output(io_function_fill_how("AxisY"), "./td.general", trim(filename), namespace, space, mesh, tmp, &
878 unit_one, err)
879 call dio_function_output(io_function_fill_how("AxisZ"), "./td.general", trim(filename), namespace, space, mesh, tmp, &
880 unit_one, err)
881 call dio_function_output(io_function_fill_how("PlaneX"), "./td.general", trim(filename), namespace, space, mesh, tmp, &
882 unit_one, err)
883 call dio_function_output(io_function_fill_how("PlaneY"), "./td.general", trim(filename), namespace, space, mesh, tmp, &
884 unit_one, err)
885 call dio_function_output(io_function_fill_how("PlaneZ"), "./td.general", trim(filename), namespace, space, mesh, tmp, &
886 unit_one, err)
887 end subroutine write_files
888
889 end subroutine bc_mxll_write_info
890
891 ! ---------------------------------------------------------
892 subroutine maxwell_mask_points_mapping(bc, mesh, bounds)
893 type(bc_mxll_t), intent(inout) :: bc
894 class(mesh_t), intent(in) :: mesh
895 real(real64), contiguous, intent(in) :: bounds(:,:)
896
897 integer :: ip, ip_in, ip_in_max, point_info, idim
898
900
901 call profiling_in('MAXWELL_MASK_POINTS_MAPPING')
902 ip_in_max = 1
903 do idim = 1, 3
904 if (bc%bc_ab_type(idim) == mxll_ab_mask) then
905 ! allocate mask points map
906 ip_in = 0
907 do ip = 1, mesh%np
908 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
909 if ((point_info == 1) .and. (abs(mesh%x_t(ip, idim)) >= bounds(1, idim))) then
910 ip_in = ip_in + 1
911 end if
912 end do
913 if (ip_in > ip_in_max) ip_in_max = ip_in
914 bc%mask_points_number(idim) = ip_in
915 end if
916 end do
917 safe_allocate(bc%mask(1:ip_in_max, 1:idim))
918 safe_allocate(bc%mask_points_map(1:ip_in_max, 1:idim))
919
920 do idim = 1, 3
921 if (bc%bc_ab_type(idim) == mxll_ab_mask) then
922 ! mask points mapping
923 ip_in = 0
924 do ip = 1, mesh%np
925 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
926 if ((point_info == 1) .and. (abs(mesh%x_t(ip, idim)) >= bounds(1, idim))) then
927 ip_in = ip_in + 1
928 bc%mask_points_map(ip_in, idim) = ip
929 end if
930 end do
931 end if
932 end do
933
934 call profiling_out('MAXWELL_MASK_POINTS_MAPPING')
936 end subroutine maxwell_mask_points_mapping
937
938 ! ---------------------------------------------------------
939 subroutine maxwell_pml_points_mapping(bc, mesh, bounds)
940 type(bc_mxll_t), intent(inout) :: bc
941 class(mesh_t), intent(in) :: mesh
942 real(real64), contiguous, intent(in) :: bounds(:,:)
943
944 integer :: ip, ip_in, point_info
945
947
948 call profiling_in('MXWL_PML_POINTS_MAPPING')
949
950 ! allocate pml points map
951 ip_in = 0
952 do ip = 1, mesh%np
953 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
954 if (point_info == 1) then
955 ip_in = ip_in + 1
956 end if
957 end do
958 bc%pml%points_number = ip_in
959 safe_allocate(bc%pml%points_map(1:ip_in))
960 safe_allocate(bc%pml%points_map_inv(1:mesh%np))
961 bc%pml%points_map_inv = 0
962 ip_in = 0
963 do ip = 1, mesh%np
964 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
965 if (point_info == 1) then
966 ip_in = ip_in + 1
967 bc%pml%points_map(ip_in) = ip
968 bc%pml%points_map_inv(ip) = ip_in
969 end if
970 end do
971
972 call profiling_out('MXWL_PML_POINTS_MAPPING')
973
975 end subroutine maxwell_pml_points_mapping
976
977 ! ---------------------------------------------------------
978 subroutine maxwell_constant_points_mapping(bc, mesh, bounds)
979 type(bc_mxll_t), intent(inout) :: bc
980 class(mesh_t), intent(in) :: mesh
981 real(real64), contiguous, intent(in) :: bounds(:,:)
982
983 integer :: ip, ip_in, point_info
984
986
987 call profiling_in('MAXWELL_CONSTANT_POINTS_MAP')
988
989 ! allocate constant points map
990 ip_in = 0
991 do ip = 1, mesh%np
992 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
993 if (point_info == 1) then
994 ip_in = ip_in + 1
995 end if
996 end do
997 bc%constant_points_number = ip_in
998 safe_allocate(bc%constant_points_map(1:ip_in))
999 safe_allocate(bc%constant_rs_state(1:ip_in, 1:3))
1000
1001 ! zero constant mapping
1002 ip_in = 0
1003 do ip = 1, mesh%np
1004 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
1005 if (point_info == 1) then
1006 ip_in = ip_in + 1
1007 bc%constant_points_map(ip_in) = ip
1008 end if
1009 end do
1010
1012 call accel_create_buffer(bc%buff_constant_points_map, accel_mem_read_only, type_integer, bc%constant_points_number)
1013 call accel_write_buffer(bc%buff_constant_points_map, bc%constant_points_number, bc%constant_points_map)
1014 end if
1015
1016 call profiling_out('MAXWELL_CONSTANT_POINTS_MAP')
1017
1019 end subroutine maxwell_constant_points_mapping
1020
1021 ! ---------------------------------------------------------
1022 subroutine maxwell_plane_waves_points_mapping(bc, mesh, bounds)
1023 type(bc_mxll_t), intent(inout) :: bc
1024 class(mesh_t), intent(in) :: mesh
1025 real(real64), contiguous, intent(in) :: bounds(:,:)
1026
1027 integer :: ip, ip_in, point_info
1028
1030
1031 call profiling_in('MXLL_PW_POINTS_MAP')
1032
1033 bc%plane_waves_dims = (bc%bc_type(1:3) == mxll_bc_plane_waves)
1034
1035 ! allocate map
1036 ip_in = 0
1037 do ip = 1, mesh%np
1038 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
1039 if (point_info == 1) then
1040 ip_in = ip_in + 1
1041 end if
1042 end do
1043 bc%plane_wave%points_number = ip_in
1044 safe_allocate(bc%plane_wave%points_map(1:ip_in))
1045
1046 ! mapping
1047 ip_in = 0
1048 do ip = 1, mesh%np
1049 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
1050 if (point_info == 1) then
1051 ip_in = ip_in + 1
1052 bc%plane_wave%points_map(ip_in) = ip
1053 end if
1054 end do
1055
1056 if (accel_is_enabled()) then
1057 call accel_create_buffer(bc%plane_wave%buff_map, accel_mem_read_only, type_integer, bc%plane_wave%points_number)
1058 call accel_write_buffer(bc%plane_wave%buff_map, bc%plane_wave%points_number, bc%plane_wave%points_map)
1059 end if
1060
1061 call profiling_out('MXLL_PW_POINTS_MAP')
1062
1065
1066 ! ---------------------------------------------------------
1067 subroutine maxwell_zero_points_mapping(bc, mesh, bounds)
1068 type(bc_mxll_t), intent(inout) :: bc
1069 class(mesh_t), intent(in) :: mesh
1070 real(real64), contiguous, intent(in) :: bounds(:,:)
1071
1072 integer :: ip, ip_in, ip_in_max, point_info, idim
1073
1075
1076 call profiling_in('MXLL_ZERO_POINTS_MAPPING')
1077
1078 ip_in_max = 0
1079 do idim = 1, 3
1080 if (bc%bc_type(idim) == mxll_bc_zero) then
1081 ! allocate zero points map
1082 ip_in = 0
1083 do ip = 1, mesh%np
1084 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
1085 if ((point_info == 1) .and. (abs(mesh%x(idim, ip)) >= bounds(1, idim))) then
1086 ip_in = ip_in + 1
1087 end if
1088 end do
1089 if (ip_in > ip_in_max) ip_in_max = ip_in
1090 end if
1091 end do
1092 bc%zero_points_number = ip_in
1093 safe_allocate(bc%zero(1:ip_in_max,3))
1094 safe_allocate(bc%zero_points_map(1:ip_in_max, 1:3))
1095
1096 do idim = 1, 3
1097 if (bc%bc_type(idim) == mxll_bc_zero) then
1098 ! zero points mapping
1099 ip_in = 0
1100 do ip = 1, mesh%np
1101 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
1102 if ((point_info == 1) .and. (abs(mesh%x_t(ip, idim)) >= bounds(1, idim))) then
1103 ip_in = ip_in + 1
1104 bc%zero_points_map(ip_in, idim) = ip
1105 end if
1106 end do
1107 end if
1108 end do
1109
1110 call profiling_out('MXLL_ZERO_POINTS_MAPPING')
1111
1113 end subroutine maxwell_zero_points_mapping
1114
1115 ! ---------------------------------------------------------
1116 subroutine maxwell_medium_points_mapping(bc, mesh, bounds)
1117 type(bc_mxll_t), intent(inout) :: bc
1118 class(mesh_t), intent(in) :: mesh
1119 real(real64), contiguous, intent(in) :: bounds(:,:)
1120
1121 integer :: ip, ip_in, ip_in_max, ip_bd, ip_bd_max, point_info, boundary_info, idim
1122
1124
1125 call profiling_in('MXLL_MEDIUM_POINTS_MAPPING')
1126
1127 bc%medium(:)%points_number = 0
1128 bc%medium(:)%bdry_number = 0
1129
1130 ip_in_max = 0
1131 ip_bd_max = 0
1132 do idim = 1, 3
1133 if (bc%bc_type(idim) == mxll_bc_medium) then
1134 ! allocate pml points map
1135 ip_in = 0
1136 ip_bd = 0
1137 do ip = 1, mesh%np
1138 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
1139 call maxwell_boundary_point_info(mesh, ip, bounds, boundary_info)
1140 if ((point_info == 1) .and. (abs(mesh%x_t(ip, idim)) >= bounds(1, idim))) then
1141 ip_in = ip_in + 1
1142 end if
1143 if ((boundary_info == 1) .and. (abs(mesh%x_t(ip, idim)) >= bounds(1, idim))) then
1144 ip_bd = ip_bd + 1
1145 end if
1146 end do
1147 bc%medium(idim)%points_number = ip_in
1148 bc%medium(idim)%bdry_number = ip_bd
1149 ip_in_max = max(ip_in_max, ip_in)
1150 ip_bd_max = max(ip_bd_max, ip_bd)
1151 end if
1152 end do
1153 do idim = 1, 3
1154 safe_allocate(bc%medium(idim)%points_map(1:ip_in_max))
1155 safe_allocate(bc%medium(idim)%bdry_map(1:ip_bd_max))
1156 end do
1157
1158 do idim = 1, 3
1159 if (bc%bc_type(idim) == mxll_bc_medium) then
1160 ip_in = 0
1161 ip_bd = 0
1162 do ip = 1, mesh%np
1163 call maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
1164 call maxwell_boundary_point_info(mesh, ip, bounds, boundary_info)
1165 if ((point_info == 1) .and. (abs(mesh%x_t(ip, idim)) >= bounds(1, idim))) then
1166 ip_in = ip_in + 1
1167 bc%medium(idim)%points_map(ip_in) = ip
1168 end if
1169 if ((boundary_info == 1) .and. (abs(mesh%x_t(ip, idim)) >= bounds(1, idim))) then
1170 ip_bd = ip_bd + 1
1171 bc%medium(idim)%bdry_map(ip_bd) = ip
1172 end if
1173 end do
1174 end if
1175 end do
1176
1177 call profiling_out('MXLL_MEDIUM_POINTS_MAPPING')
1178
1180 end subroutine maxwell_medium_points_mapping
1181
1182 ! ---------------------------------------------------------
1183 subroutine bc_mxll_generate_pml(bc, space)
1184 type(bc_mxll_t), intent(inout) :: bc
1185 class(space_t), intent(in) :: space
1186
1187
1189
1190 call profiling_in('BC_MXLL_GENERATE_PML')
1191
1192 safe_allocate(bc%pml%kappa(1:bc%pml%points_number, 1:space%dim))
1193 safe_allocate(bc%pml%sigma_e(1:bc%pml%points_number, 1:space%dim))
1194 safe_allocate(bc%pml%sigma_m(1:bc%pml%points_number, 1:space%dim))
1195 safe_allocate(bc%pml%a(1:bc%pml%points_number, 1:space%dim))
1196 safe_allocate(bc%pml%b(1:bc%pml%points_number, 1:space%dim))
1197 safe_allocate(bc%pml%c(1:bc%pml%points_number, 1:3))
1198 safe_allocate(bc%pml%mask(1:bc%pml%points_number))
1199 safe_allocate(bc%pml%conv_plus(1:bc%pml%points_number, 1:3, 1:3))
1200 safe_allocate(bc%pml%conv_minus(1:bc%pml%points_number, 1:3, 1:3))
1201 safe_allocate(bc%pml%conv_plus_old(1:bc%pml%points_number, 1:3, 1:3))
1202 safe_allocate(bc%pml%conv_minus_old(1:bc%pml%points_number, 1:3, 1:3))
1203 safe_allocate(bc%pml%aux_ep(1:bc%pml%points_number, 1:3, 1:3))
1204 safe_allocate(bc%pml%aux_mu(1:bc%pml%points_number, 1:3, 1:3))
1205
1206 bc%pml%kappa = m_one
1207 bc%pml%sigma_e = m_zero
1208 bc%pml%sigma_m = m_zero
1209 bc%pml%a = m_zero
1210 bc%pml%b = m_zero
1211 bc%pml%c = m_zero
1212 bc%pml%mask = m_one
1213 bc%pml%conv_plus = m_z0
1214 bc%pml%conv_minus = m_z0
1215 bc%pml%conv_plus_old = m_z0
1216 bc%pml%conv_minus_old = m_z0
1217
1218 if (accel_is_enabled()) then
1219 call accel_create_buffer(bc%pml%buff_map, accel_mem_read_only, type_integer, bc%pml%points_number)
1220 call accel_create_buffer(bc%pml%buff_a, accel_mem_read_only, type_float, int(bc%pml%points_number, int64)*space%dim)
1221 call accel_create_buffer(bc%pml%buff_b, accel_mem_read_only, type_float, int(bc%pml%points_number, int64)*space%dim)
1222 call accel_create_buffer(bc%pml%buff_c, accel_mem_read_only, type_float, int(bc%pml%points_number, int64)*space%dim)
1223 call accel_create_buffer(bc%pml%buff_conv_plus, accel_mem_read_write, type_cmplx, &
1224 int(bc%pml%points_number, int64)*space%dim*space%dim)
1225 call accel_create_buffer(bc%pml%buff_conv_minus, accel_mem_read_write, type_cmplx, &
1226 int(bc%pml%points_number, int64)*space%dim*space%dim)
1227 call accel_create_buffer(bc%pml%buff_conv_plus_old, accel_mem_read_write, type_cmplx, &
1228 int(bc%pml%points_number, int64)*space%dim*space%dim)
1229
1230 call accel_write_buffer(bc%pml%buff_a, bc%pml%points_number, space%dim, bc%pml%a)
1231 call accel_write_buffer(bc%pml%buff_b, bc%pml%points_number, space%dim, bc%pml%b)
1232 call accel_write_buffer(bc%pml%buff_c, bc%pml%points_number, space%dim, bc%pml%c)
1233 call accel_write_buffer(bc%pml%buff_conv_plus, bc%pml%points_number, space%dim, space%dim, bc%pml%conv_plus)
1234 call accel_write_buffer(bc%pml%buff_conv_minus, bc%pml%points_number, space%dim, space%dim, bc%pml%conv_minus)
1235 call accel_write_buffer(bc%pml%buff_conv_plus_old, bc%pml%points_number, space%dim, space%dim, bc%pml%conv_plus_old)
1236 end if
1237
1238 call profiling_out('BC_MXLL_GENERATE_PML')
1239
1240 pop_sub(bc_mxll_generate_pml)
1241 end subroutine bc_mxll_generate_pml
1242
1243
1244 ! ---------------------------------------------------------
1245 subroutine bc_mxll_generate_pml_parameters(bc, space, gr, c_factor, dt)
1246 type(bc_mxll_t), intent(inout) :: bc
1247 class(space_t), intent(in) :: space
1248 type(grid_t), intent(in) :: gr
1249 real(real64), intent(in) :: c_factor
1250 real(real64), optional, intent(in) :: dt
1251
1252 integer :: ip, ip_in, idim
1253 real(real64) :: width(3)
1254 real(real64) :: ddv(3), ss_e, ss_m, ss_max, aa_e, aa_m, bb_e, bb_m, gg, hh, kk, ll_e, ll_m
1255 real(real64), allocatable :: tmp(:), tmp_grad(:,:)
1256
1257
1259 safe_allocate(tmp(gr%np_part))
1260 safe_allocate(tmp_grad(gr%np, 1:space%dim))
1261 ! here bounds are ab_bounds, for which ab_bounds(1,:) = bc%bounds(1,:)
1262 ! width is stored in bc%pml%width
1263 ! assuming that the width is the same in the 3 dimensions (only case implemented now), we can change the following line:
1264 ! width(1:3) = bounds(2, 1:3) - bounds(1, 1:3) !! original line
1265 ! by
1266 width(1:3) = (/ bc%pml%width, bc%pml%width, bc%pml%width /)
1267
1268 ! PML variables for all boundary points
1269 do ip_in = 1, bc%pml%points_number
1270 ip = bc%pml%points_map(ip_in)
1271 ddv(1:3) = abs(gr%x(1:3, ip)) - bc%bc_bounds(1, 1:3)
1272 do idim = 1, space%dim
1273 if (ddv(idim) >= m_zero) then
1274 gg = (ddv(idim)/bc%pml%width)**bc%pml%power
1275 hh = (m_one-ddv(idim)/bc%pml%width)**bc%pml%power
1276 kk = m_one
1277 ss_max = -(bc%pml%power + m_one)*p_c*c_factor*p_ep*log(bc%pml%refl_error)/(m_two * bc%pml%width)
1278 ss_e = gg * ss_max
1279 ss_m = gg * ss_max
1280 ll_e = ss_e*kk
1281 ll_m = ss_m*kk
1282 aa_e = expm1(-(ss_e/(p_ep))*dt)
1283 aa_m = expm1(-(ss_m/(p_ep))*dt)
1284 if (abs(ll_e) < m_epsilon) aa_e = m_zero
1285 if (abs(ll_m) < m_epsilon) aa_m = m_zero
1286 bb_e = m_one + aa_e
1287 bb_m = m_one + aa_m
1288 bc%pml%sigma_e(ip_in, idim) = ss_e
1289 bc%pml%sigma_m(ip_in, idim) = ss_m
1290 bc%pml%a(ip_in, idim) = aa_e
1291 bc%pml%b(ip_in, idim) = bb_e
1292 bc%pml%kappa(ip_in, idim) = kk
1293 bc%pml%mask(ip_in) = bc%pml%mask(ip_in) * (m_one - sin(ddv(idim)*m_pi/(m_two*(width(idim))))**2)
1294 else
1295 bc%pml%kappa(ip_in, idim) = m_one
1296 bc%pml%sigma_e(ip_in, idim) = m_zero
1297 bc%pml%sigma_m(ip_in, idim) = m_zero
1298 bc%pml%a(ip_in, idim) = m_zero
1299 bc%pml%b(ip_in, idim) = m_zero
1300 bc%pml%mask(ip_in) = m_one
1301 end if
1302 end do
1303 end do
1304
1305 ! PML auxiliary epsilon for all boundary points
1306 do idim = 1, space%dim
1307 tmp = p_ep
1308 do ip_in = 1, bc%pml%points_number
1309 ip = bc%pml%points_map(ip_in)
1310 tmp(ip) = p_ep / bc%pml%kappa(ip_in, idim)
1311 end do
1312 call dderivatives_grad(gr%der, tmp, tmp_grad, set_bc = .false.)
1313 do ip_in = 1, bc%pml%points_number
1314 ip = bc%pml%points_map(ip_in)
1315 bc%pml%aux_ep(ip_in, :, idim) = tmp_grad(ip, :)/(m_four*p_ep*bc%pml%kappa(ip_in, idim))
1316 end do
1317 end do
1318
1319 ! PML auxiliary mu
1320 do idim = 1, space%dim
1321 ! P_mu is proportional to 1/P_c**2, so we need to devide by c_factor
1322 tmp = p_mu/c_factor**2
1323 do ip_in = 1, bc%pml%points_number
1324 ip = bc%pml%points_map(ip_in)
1325 tmp(ip) = p_mu/c_factor**2 / bc%pml%kappa(ip_in, idim)
1326 end do
1327 call dderivatives_grad(gr%der, tmp, tmp_grad, set_bc = .false.)
1328 do ip_in = 1, bc%pml%points_number
1329 ip = bc%pml%points_map(ip_in)
1330 bc%pml%aux_mu(ip_in, :, idim) = tmp_grad(ip, :)/(m_four*p_mu/c_factor**2 * bc%pml%kappa(ip_in, idim))
1331 end do
1332 end do
1333
1334 ! PML auxiliary c for all boundary points
1335 do idim = 1, space%dim
1336 do ip_in = 1, bc%pml%points_number
1337 bc%pml%c(ip_in, idim) = p_c*c_factor/bc%pml%kappa(ip_in, idim)
1338 end do
1339 end do
1340 safe_deallocate_a(tmp)
1341 safe_deallocate_a(tmp_grad)
1342
1343 if (accel_is_enabled()) then
1344 call accel_write_buffer(bc%pml%buff_map, bc%pml%points_number, bc%pml%points_map)
1345 call accel_write_buffer(bc%pml%buff_a, bc%pml%points_number, space%dim, bc%pml%a)
1346 call accel_write_buffer(bc%pml%buff_b, bc%pml%points_number, space%dim, bc%pml%b)
1347 call accel_write_buffer(bc%pml%buff_c, bc%pml%points_number, space%dim, bc%pml%c)
1348 call accel_write_buffer(bc%pml%buff_conv_plus, bc%pml%points_number, space%dim, space%dim, bc%pml%conv_plus)
1349 call accel_write_buffer(bc%pml%buff_conv_minus, bc%pml%points_number, space%dim, space%dim, bc%pml%conv_minus)
1350 end if
1351
1352 bc%pml%parameters_initialized = .true.
1353
1355
1356 end subroutine bc_mxll_generate_pml_parameters
1357
1358 ! ---------------------------------------------------------
1359 subroutine bc_mxll_initialize_pml_simple(bc, space, gr, c_factor, dt)
1360 type(bc_mxll_t), intent(inout) :: bc
1361 class(space_t), intent(in) :: space
1362 type(grid_t), intent(in) :: gr
1363 real(real64), intent(in) :: c_factor
1364 real(real64), intent(in) :: dt
1365
1366 integer :: ip_in, ip, idir
1367 real(real64) :: ddv(1:space%dim), kappa, sigma, alpha
1369
1370 ! PML variables for all boundary points
1371 do ip_in = 1, bc%pml%points_number
1372 ip = bc%pml%points_map(ip_in)
1373 ddv(1:3) = abs(gr%x(1:3, ip)) - bc%bc_bounds(1, 1:3)
1374 do idir = 1, space%dim
1375 if (ddv(idir) >= m_zero) then
1376 sigma = (ddv(idir)/bc%pml%width)**bc%pml%power * &
1377 (-(bc%pml%power + m_one)*p_c*c_factor*p_ep*log(bc%pml%refl_error)/(m_two * bc%pml%width))
1378 ! kappa and alpha could be set to different values, but these seem to be fine
1379 kappa = m_one
1380 ! non-zero values for alpha can be used to modify the low-frequency behavior
1381 alpha = m_zero
1382 bc%pml%b(ip_in, idir) = exp(-(alpha + sigma/kappa)/p_ep*dt)
1383 if (abs(sigma) < m_epsilon) then
1384 bc%pml%c(ip_in, idir) = m_zero
1385 else
1386 bc%pml%c(ip_in, idir) = m_one/(kappa + kappa**2*alpha/sigma) * &
1387 (bc%pml%b(ip_in, idir) - 1)
1388 end if
1389 else
1390 bc%pml%b(ip_in, idir) = m_zero
1391 bc%pml%c(ip_in, idir) = m_zero
1392 end if
1393 end do
1394 end do
1395 if (accel_is_enabled()) then
1396 call accel_write_buffer(bc%pml%buff_map, bc%pml%points_number, bc%pml%points_map)
1397 call accel_write_buffer(bc%pml%buff_b, bc%pml%points_number, space%dim, bc%pml%b)
1398 call accel_write_buffer(bc%pml%buff_c, bc%pml%points_number, space%dim, bc%pml%c)
1399 end if
1401 end subroutine bc_mxll_initialize_pml_simple
1402
1403 ! ---------------------------------------------------------
1404 subroutine bc_mxll_generate_mask(bc, mesh, bounds)
1405 type(bc_mxll_t), intent(inout) :: bc
1406 class(mesh_t), intent(in) :: mesh
1407 real(real64), contiguous, intent(in) :: bounds(:,:)
1408
1409 integer :: ip, ip_in, idim, ip_in_max
1410 real(real64) :: ddv(3), tmp(3), width(3)
1411 real(real64), allocatable :: mask(:)
1412
1413 push_sub(bc_mxll_generate_mask)
1414
1415 call profiling_in('BC_MXLL_GENERATE_MASK')
1416
1417 ip_in_max = maxval(bc%mask_points_number(:))
1418
1419 safe_allocate(mask(1:mesh%np))
1420
1421 mask(:) = m_one
1422
1423 width(1:3) = bounds(2, 1:3) - bounds(1, 1:3)
1424 tmp(:) = m_zero
1425
1426 do ip = 1, mesh%np
1427 tmp = m_one
1428 mask(ip) = m_one
1429 ddv(1:3) = abs(mesh%x(1:3, ip)) - bounds(1, 1:3)
1430 do idim = 1, mesh%box%dim
1431 if (ddv(idim) >= m_zero) then
1432 if (ddv(idim) <= width(idim)) then
1433 tmp(idim) = m_one - sin(ddv(idim) * m_pi / (m_two * (width(idim))))**2
1434 else
1435 tmp(idim) = m_one
1436 end if
1437 end if
1438 mask(ip) = mask(ip) * tmp(idim)
1439 end do
1440 end do
1441
1442 do idim = 1, mesh%box%dim
1443 do ip_in = 1, bc%mask_points_number(idim)
1444 ip = bc%mask_points_map(ip_in, idim)
1445 bc%mask(ip_in,idim) = mask(ip)
1446 end do
1447 end do
1448
1449 safe_deallocate_a(mask)
1450
1451 call profiling_out('BC_MXLL_GENERATE_MASK')
1452
1453 pop_sub(bc_mxll_generate_mask)
1454 end subroutine bc_mxll_generate_mask
1455
1456 ! ---------------------------------------------------------
1457 subroutine bc_mxll_generate_medium(bc, space, gr, bounds, ep_factor, mu_factor, sigma_e_factor, sigma_m_factor)
1458 type(bc_mxll_t), intent(inout) :: bc
1459 class(space_t), intent(in) :: space
1460 type(grid_t), intent(in) :: gr
1461 real(real64), contiguous, intent(in) :: bounds(:,:)
1462 real(real64), intent(in) :: ep_factor
1463 real(real64), intent(in) :: mu_factor
1464 real(real64), intent(in) :: sigma_e_factor
1465 real(real64), intent(in) :: sigma_m_factor
1466
1467 integer :: ip, ipp, ip_in, ip_in_max, ip_bd, idim, point_info
1468 integer :: medium_points_number(3)
1469 real(real64) :: dd, dd_min, dd_max, xx(3), xxp(3)
1470 real(real64), allocatable :: tmp(:), tmp_grad(:,:)
1471
1472 push_sub(bc_mxll_generate_medium)
1473
1474 call profiling_in('BC_MXLL_GENERATE_MEDIUM')
1475
1476 ip_in_max = max(bc%medium(1)%points_number, bc%medium(2)%points_number, bc%medium(3)%points_number)
1477 medium_points_number(:) = [bc%medium(1)%points_number, bc%medium(2)%points_number, bc%medium(3)%points_number]
1478 dd_max = max(2*gr%spacing(1), 2*gr%spacing(2), 2*gr%spacing(3))
1479 safe_allocate(tmp(gr%np_part))
1480 safe_allocate(tmp_grad(1:gr%np_part,1:space%dim))
1481
1482 do idim = 1, 3
1483 call single_medium_box_allocate(bc%medium(idim), ip_in_max)
1484 bc%medium(idim)%points_number = medium_points_number(idim)
1485 bc%medium(idim)%aux_ep = m_zero
1486 bc%medium(idim)%aux_mu = m_zero
1487 bc%medium(idim)%c = p_c
1488 if (bc%bc_type(idim) /= mxll_bc_medium) cycle
1489
1490 tmp = p_ep
1491 do ip = 1, gr%np_part
1492 call maxwell_box_point_info(bc, gr, ip, bounds, point_info)
1493 if ((point_info /= 0) .and. (abs(gr%x_t(ip, idim)) <= bounds(1, idim))) then
1494 xx(:) = gr%x(:, ip)
1495 dd_min = m_huge
1496 do ip_bd = 1, bc%medium(idim)%bdry_number
1497 ipp = bc%medium(idim)%bdry_map(ip_bd)
1498 xxp(:) = gr%x(:, ipp)
1499 dd = norm2(xx(1:3) - xxp(1:3))
1500 if (dd < dd_min) dd_min = dd
1501 end do
1502 tmp(ip) = p_ep * (m_one + ep_factor * m_one/(m_one + exp(-m_five/dd_max * (dd_min-m_two*dd_max))))
1503 end if
1504 end do
1505 call dderivatives_grad(gr%der, tmp, tmp_grad, set_bc = .false.)
1506 do ip_in = 1, bc%medium(idim)%points_number
1507 ip = bc%medium(idim)%points_map(ip_in)
1508 bc%medium(idim)%aux_ep(ip_in, :) = &
1509 tmp_grad(ip, :)/(m_four*p_ep*ep_factor * m_one/(m_one + exp(-m_five/dd_max-dd)))
1510 end do
1511 end do
1512
1513 do idim = 1, 3
1514 if (bc%bc_type(idim) /= mxll_bc_medium) cycle
1515 tmp = p_mu
1516 do ip = 1, gr%np_part
1517 call maxwell_box_point_info(bc, gr, ip, bounds, point_info)
1518 if ((point_info == 1) .and. (abs(gr%x_t(ip, idim)) <= bounds(1, idim))) then
1519 xx(:) = gr%x(:, ip)
1520 dd_min = m_huge
1521 do ip_bd = 1, bc%medium(idim)%bdry_number
1522 ipp = bc%medium(idim)%bdry_map(ip_bd)
1523 xxp(:) = gr%x(:, ipp)
1524 dd = norm2(xx(1:3) - xxp(1:3))
1525 if (dd < dd_min) dd_min = dd
1526 end do
1527 tmp(ip) = p_mu * (m_one + mu_factor * m_one/(m_one + exp(-m_five/dd_max * (dd_min - m_two*dd_max))))
1528 end if
1529 end do
1530 call dderivatives_grad(gr%der, tmp, tmp_grad, set_bc = .false.)
1531 do ip_in = 1, bc%medium(idim)%points_number
1532 ip = bc%medium(idim)%points_map(ip_in)
1533 bc%medium(idim)%aux_mu(ip_in, :) = &
1534 tmp_grad(ip, :)/(m_four * p_mu * mu_factor * m_one/(m_one + exp(-m_five/dd_max-dd)))
1535 end do
1536 end do
1537
1538 do idim = 1, 3
1539 if (bc%bc_type(idim) /= mxll_bc_medium) cycle
1540 do ip_in = 1, bc%medium(idim)%points_number
1541 ip = bc%medium(idim)%points_map(ip_in)
1542 xx(:) = gr%x(:, ip)
1543 dd_min = m_huge
1544 do ip_bd = 1, bc%medium(idim)%bdry_number
1545 ipp = bc%medium(idim)%bdry_map(ip_bd)
1546 xxp(:) = gr%x(:, ipp)
1547 dd = norm2(xx(1:3) - xxp(1:3))
1548 if (dd < dd_min) dd_min = dd
1549 end do
1550 bc%medium(idim)%ep(ip_in) = p_ep * (m_one + ep_factor &
1551 * m_one/(m_one + exp(-m_five / dd_max * (dd_min - m_two * dd_max))))
1552 bc%medium(idim)%mu(ip_in) = p_mu * (m_one + mu_factor &
1553 * m_one/(m_one + exp(-m_five / dd_max * (dd_min - m_two * dd_max))))
1554 bc%medium(idim)%sigma_e(ip_in) = (m_one + sigma_e_factor &
1555 * m_one/(m_one + exp(-m_five / dd_max * (dd_min - m_two * dd_max))))
1556 bc%medium(idim)%sigma_m(ip_in) = (m_one + sigma_m_factor &
1557 * m_one/(m_one + exp(-m_five / dd_max * (dd_min - m_two * dd_max))))
1558 bc%medium(idim)%c(ip_in) = m_one / sqrt(bc%medium(idim)%ep(ip_in) * bc%medium(idim)%mu(ip_in))
1559 end do
1560 end do
1561
1562 safe_deallocate_a(tmp)
1563 safe_deallocate_a(tmp_grad)
1564
1565 call profiling_out('BC_MXLL_GENERATE_MEDIUM')
1566
1568 end subroutine bc_mxll_generate_medium
1569
1570 ! ---------------------------------------------------------
1571 subroutine maxwell_surfaces_init(mesh, st, bounds)
1572 class(mesh_t), intent(in) :: mesh
1573 type(states_mxll_t), intent(inout) :: st
1574 real(real64), contiguous, intent(in) :: bounds(:,:)
1575
1576
1577 push_sub(maxwell_surfaces_init)
1578
1579 call profiling_in('MAXWELL_SURFACES_INIT')
1580
1581 ! y-z surface at -x boundary
1582 st%surface(1, 1)%spacing = m_half*(mesh%spacing(2) + mesh%spacing(3))
1583 st%surface(1, 1)%origin(:) = m_zero
1584 st%surface(1, 1)%origin(1) = -bounds(1, 1)
1585 st%surface(1, 1)%n(:) = m_zero
1586 st%surface(1, 1)%n(1) = -m_one
1587 st%surface(1, 1)%u(:) = m_zero
1588 st%surface(1, 1)%u(2) = -m_one
1589 st%surface(1, 1)%v(:) = m_zero
1590 st%surface(1, 1)%v(3) = m_one
1591 st%surface(1, 1)%nu = -int(bounds(1, 2)/mesh%spacing(2))
1592 st%surface(1, 1)%mu = int(bounds(1, 2)/mesh%spacing(2))
1593 st%surface(1, 1)%nv = -int(bounds(1, 3)/mesh%spacing(3))
1594 st%surface(1, 1)%mv = int(bounds(1, 3)/mesh%spacing(3))
1595
1596 ! y-z surface at +x boundary
1597 st%surface(2, 1)%spacing = m_half*(mesh%spacing(2) + mesh%spacing(3))
1598 st%surface(2, 1)%origin(:) = m_zero
1599 st%surface(2, 1)%origin(1) = bounds(1, 1)
1600 st%surface(2, 1)%n(:) = m_zero
1601 st%surface(2, 1)%n(1) = m_one
1602 st%surface(2, 1)%u(:) = m_zero
1603 st%surface(2, 1)%u(2) = m_one
1604 st%surface(2, 1)%v(:) = m_zero
1605 st%surface(2, 1)%v(3) = m_one
1606 st%surface(2, 1)%nu = -int(bounds(1, 2)/mesh%spacing(2))
1607 st%surface(2, 1)%mu = int(bounds(1, 2)/mesh%spacing(2))
1608 st%surface(2, 1)%nv = -int(bounds(1, 3)/mesh%spacing(3))
1609 st%surface(2, 1)%mv = int(bounds(1, 3)/mesh%spacing(3))
1610
1611 ! x-z surface at -y boundary
1612 st%surface(1, 2)%spacing = m_half*(mesh%spacing(1) + mesh%spacing(3))
1613 st%surface(1, 2)%origin(:) = m_zero
1614 st%surface(1, 2)%origin(2) = -bounds(1, 2)
1615 st%surface(1, 2)%n(:) = m_zero
1616 st%surface(1, 2)%n(2) = -m_one
1617 st%surface(1, 2)%u(:) = m_zero
1618 st%surface(1, 2)%u(1) = m_one
1619 st%surface(1, 2)%v(:) = m_zero
1620 st%surface(1, 2)%v(3) = m_one
1621 st%surface(1, 2)%nu = -int(bounds(1, 1)/mesh%spacing(1))
1622 st%surface(1, 2)%mu = int(bounds(1, 1)/mesh%spacing(1))
1623 st%surface(1, 2)%nv = -int(bounds(1, 3)/mesh%spacing(3))
1624 st%surface(1, 2)%mv = int(bounds(1, 3)/mesh%spacing(3))
1625
1626 ! x-z surface at +y boundary
1627 st%surface(2, 2)%spacing = m_half*(mesh%spacing(1) + mesh%spacing(3))
1628 st%surface(2, 2)%origin(:) = m_zero
1629 st%surface(2, 2)%origin(2) = bounds(1, 2)
1630 st%surface(2, 2)%n(:) = m_zero
1631 st%surface(2, 2)%n(2) = m_one
1632 st%surface(2, 2)%u(:) = m_zero
1633 st%surface(2, 2)%u(1) = m_one
1634 st%surface(2, 2)%v(:) = m_zero
1635 st%surface(2, 2)%v(3) = -m_one
1636 st%surface(2, 2)%nu = -int(bounds(1, 1)/mesh%spacing(1))
1637 st%surface(2, 2)%mu = int(bounds(1, 1)/mesh%spacing(1))
1638 st%surface(2, 2)%nv = -int(bounds(1, 3)/mesh%spacing(3))
1639 st%surface(2, 2)%mv = int(bounds(1, 3)/mesh%spacing(3))
1640
1641 ! x-y surface at -z boundary
1642 st%surface(1, 3)%spacing = m_half*(mesh%spacing(1) + mesh%spacing(2))
1643 st%surface(1, 3)%origin(:) = m_zero
1644 st%surface(1, 3)%origin(3) = -bounds(1, 3)
1645 st%surface(1, 3)%n(:) = m_zero
1646 st%surface(1, 3)%n(3) = -m_one
1647 st%surface(1, 3)%u(:) = m_zero
1648 st%surface(1, 3)%u(1) = m_one
1649 st%surface(1, 3)%v(:) = m_zero
1650 st%surface(1, 3)%v(2) = -m_one
1651 st%surface(1, 3)%nu = -int(bounds(1, 1)/mesh%spacing(1))
1652 st%surface(1, 3)%mu = int(bounds(1, 1)/mesh%spacing(1))
1653 st%surface(1, 3)%nv = -int(bounds(1, 2)/mesh%spacing(2))
1654 st%surface(1, 3)%mv = int(bounds(1, 2)/mesh%spacing(2))
1655
1656 ! x-y surface at +z boundary
1657 st%surface(2, 3)%spacing = m_half*(mesh%spacing(1) + mesh%spacing(2))
1658 st%surface(2, 3)%origin(:) = m_zero
1659 st%surface(2, 3)%origin(3) = bounds(1, 3)
1660 st%surface(2, 3)%n(:) = m_zero
1661 st%surface(2, 3)%n(3) = m_one
1662 st%surface(2, 3)%u(:) = m_zero
1663 st%surface(2, 3)%u(1) = m_one
1664 st%surface(2, 3)%v(:) = m_zero
1665 st%surface(2, 3)%v(2) = m_one
1666 st%surface(2, 3)%nu = -int(bounds(1, 1)/mesh%spacing(1))
1667 st%surface(2, 3)%mu = int(bounds(1, 1)/mesh%spacing(1))
1668 st%surface(2, 3)%nv = -int(bounds(1, 2)/mesh%spacing(2))
1669 st%surface(2, 3)%mv = int(bounds(1, 2)/mesh%spacing(2))
1670
1671 call profiling_out('MAXWELL_SURFACES_INIT')
1672
1673 pop_sub(maxwell_surfaces_init)
1674 end subroutine maxwell_surfaces_init
1675
1676 ! ---------------------------------------------------------
1677 subroutine maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
1678 type(bc_mxll_t), intent(inout) :: bc
1679 class(mesh_t), intent(in) :: mesh
1680 integer, intent(in) :: ip
1681 real(real64), contiguous, intent(in) :: bounds(:,:)
1682 integer, intent(out) :: point_info
1683
1684 real(real64) :: rr, dd, xx(3), width(3)
1685
1686 point_info = 0
1687
1688 width(1:3) = bounds(2, 1:3) - bounds(1, 1:3)
1689 xx = m_zero
1690 xx(1:mesh%box%dim) = mesh%x(1:mesh%box%dim, ip)
1691
1692 if (bc%ab_user_def) then
1693
1694 dd = bc%ab_ufn(ip) - bounds(1, 1)
1695 if (dd > m_zero) then
1696 if (bc%ab_ufn(ip) < bounds(2, 1)) then
1697 point_info = 1
1698 end if
1699 end if
1700
1701 else ! bc%ab_user_def == .false.
1702
1703 select type (box => mesh%box)
1704 type is (box_sphere_t)
1705 rr = norm2(xx - box%center)
1706 dd = rr - bounds(1, 1)
1707 if (dd > m_zero) then
1708 if (dd < width(1)) then
1709 point_info = 1
1710 end if
1711 end if
1712
1713 type is (box_parallelepiped_t)
1714 ! Limits of boundary region
1715 if (all(abs(xx(1:3) - box%center) <= bounds(2, 1:3))) then
1716 if (any(abs(xx(1:3) - box%center) > bounds(1, 1:3))) then
1717 point_info = 1
1718 else
1719 point_info = 0
1720 end if
1721 else
1722 point_info = -1
1723 end if
1724
1725 class default
1726 ! Other box shapes are not supported.
1727 assert(.false.)
1728 end select
1729 end if
1730
1731 end subroutine maxwell_box_point_info
1732
1733 ! ---------------------------------------------------------
1734 subroutine maxwell_boundary_point_info(mesh, ip, bounds, boundary_info)
1735 class(mesh_t), intent(in) :: mesh
1736 integer, intent(in) :: ip
1737 real(real64), contiguous, intent(in) :: bounds(:,:)
1738 integer, intent(out) :: boundary_info
1739
1740 real(real64) :: xx(3)
1741
1742 boundary_info = 0
1743
1744 xx = m_zero
1745 xx(1:mesh%box%dim) = mesh%x(1:mesh%box%dim, ip)
1746 if (is_close(abs(xx(1)), bounds(1, 1)) .and. (all(abs(xx(2:3)) <= bounds(1, 2:3))) .or. &
1747 is_close(abs(xx(2)), bounds(1, 2)) .and. (all(abs(xx(1:3:2)) <= bounds(1, 1:3:2))) .or. &
1748 is_close(abs(xx(3)), bounds(1, 3)) .and. (all(abs(xx(1:2)) <= bounds(1, 1:2)))) then
1749 boundary_info = 1
1750 else
1751 boundary_info = 0
1752 end if
1753
1754 end subroutine maxwell_boundary_point_info
1755
1756 ! ---------------------------------------------------------
1760 subroutine inner_and_outer_points_mapping(mesh, st, bounds, periodic_dim)
1761 class(mesh_t), intent(in) :: mesh
1762 type(states_mxll_t), intent(inout) :: st
1763 real(real64), contiguous, intent(in) :: bounds(:,:)
1764 integer, intent(in) :: periodic_dim
1765
1766 integer :: ip, ip_in, ip_bd, point_info, ndim
1767 real(real64) :: xx(mesh%box%dim)
1768
1770
1771 call profiling_in('IN_OUT_POINTS_MAP')
1772
1773 ndim = mesh%box%dim
1774
1775 ! allocate inner and boundary points points map
1776 ip_in = 0
1777 ip_bd = 0
1778 do ip = 1, mesh%np
1779 xx = mesh%x(:, ip)
1780 if (all(abs(xx(periodic_dim+1:ndim)) <= bounds(2, periodic_dim+1:ndim))) then
1781 if (any(abs(xx(periodic_dim+1:ndim)) > bounds(1, periodic_dim+1:ndim))) then
1782 point_info = 1
1783 else
1784 point_info = 0
1785 end if
1786 else
1787 point_info = -1
1788 end if
1789 if (point_info == 0) then
1790 ip_in = ip_in + 1
1791 else
1792 ip_bd = ip_bd + 1
1793 end if
1794 end do
1795 st%inner_points_number = ip_in
1796 safe_allocate(st%inner_points_map(1:ip_in))
1797 safe_allocate(st%inner_points_mask(1:mesh%np))
1798 st%boundary_points_number = ip_bd
1799 safe_allocate(st%boundary_points_map(1:ip_bd))
1800 safe_allocate(st%boundary_points_mask(1:mesh%np))
1801 st%inner_points_mask = .false.
1802 st%boundary_points_mask = .false.
1803
1804 ! inner and boundary points mapping
1805 ip_in = 0
1806 ip_bd = 0
1807 do ip = 1, mesh%np
1808 xx = mesh%x(:, ip)
1809 if (all(abs(xx(periodic_dim+1:ndim)) <= bounds(2, periodic_dim+1:ndim))) then
1810 if (any(abs(xx(periodic_dim+1:ndim)) > bounds(1, periodic_dim+1:ndim))) then
1811 point_info = 1
1812 else
1813 point_info = 0
1814 end if
1815 else
1816 point_info = -1
1817 end if
1818 if (point_info == 0) then
1819 ip_in = ip_in + 1
1820 st%inner_points_map(ip_in) = ip
1821 st%inner_points_mask(ip) = .true.
1822 else
1823 ip_bd = ip_bd + 1
1824 st%boundary_points_map(ip_bd) = ip
1825 st%boundary_points_mask(ip) = .true.
1826 end if
1827 end do
1828
1829 if (accel_is_enabled()) then
1830 call accel_create_buffer(st%buff_inner_points_map, accel_mem_read_only, type_integer, st%inner_points_number)
1831 call accel_write_buffer(st%buff_inner_points_map, st%inner_points_number, st%inner_points_map)
1832 call accel_create_buffer(st%buff_boundary_points_map, accel_mem_read_only, type_integer, st%boundary_points_number)
1833 call accel_write_buffer(st%buff_boundary_points_map, st%boundary_points_number, st%boundary_points_map)
1834 end if
1835
1836 call profiling_out('IN_OUT_POINTS_MAP')
1837
1839 end subroutine inner_and_outer_points_mapping
1840
1841 ! ---------------------------------------------------------
1842 subroutine surface_grid_points_mapping(mesh, st, bounds)
1843 class(mesh_t), intent(in) :: mesh
1844 type(states_mxll_t), intent(inout) :: st
1845 real(real64), contiguous, intent(in) :: bounds(:,:)
1846
1847 integer :: ix, ix_max, iix, iy, iy_max, iiy, iz, iz_max, iiz, idx1, idx2, nn_max
1848 integer(int64) :: ip_global
1849 integer, allocatable :: nn(:,:,:,:)
1850 real(real64) :: rr(3), delta(3), vec(2), min_1(3), max_1(3), min_2(3), max_2(3)
1851
1853
1854 call profiling_in('SURF_GRID_POINTS_MAPPING')
1855
1856 st%surface_grid_rows_number(1) = 3
1857 ix_max = st%surface_grid_rows_number(1)
1858 st%surface_grid_rows_number(2) = 3
1859 iy_max = st%surface_grid_rows_number(2)
1860 st%surface_grid_rows_number(3) = 3
1861 iz_max = st%surface_grid_rows_number(3)
1862
1863 delta(1) = m_two * abs(bounds(1,1)) / real(ix_max, real64)
1864 delta(2) = m_two * abs(bounds(1,2)) / real(iy_max, real64)
1865 delta(3) = m_two * abs(bounds(1,3)) / real(iz_max, real64)
1866
1867 st%surface_grid_element(1) = delta(2) * delta(3)
1868 st%surface_grid_element(2) = delta(1) * delta(3)
1869 st%surface_grid_element(3) = delta(1) * delta(2)
1870
1871 safe_allocate(nn(1:2, 1:3, 1:3, 1:3))
1872
1873 st%surface_grid_center(1, 1, :, :) = -int(bounds(1,1))
1874 do iy = 1, iy_max
1875 do iz = 1, iz_max
1876 rr(2) = -bounds(1,2) + delta(2)/m_two + (iy-1) * delta(2)
1877 rr(3) = -bounds(1,3) + delta(3)/m_two + (iz-1) * delta(3)
1878 st%surface_grid_center(1, 2, iy, iz) = int(rr(2))
1879 st%surface_grid_center(1, 3, iy, iz) = int(rr(3))
1880 end do
1881 end do
1882 st%surface_grid_center(2, 1, :, :) = int(bounds(1,1))
1883 do iy = 1, iy_max
1884 do iz = 1, iz_max
1885 rr(2) = -bounds(1,2) + delta(2)/m_two + (iy-1) * delta(2)
1886 rr(3) = -bounds(1,3) + delta(3)/m_two + (iz-1) * delta(3)
1887 st%surface_grid_center(2, 2, iy, iz) = int(rr(2))
1888 st%surface_grid_center(2, 3, iy, iz) = int(rr(3))
1889 end do
1890 end do
1891
1892 st%surface_grid_center(1, 2, :, :) = -int(bounds(1,2))
1893 do ix = 1, ix_max
1894 do iz = 1, iz_max
1895 rr(1) = -bounds(1,1) + delta(1)/m_two + (ix-1) * delta(1)
1896 rr(3) = -bounds(1,3) + delta(3)/m_two + (iz-1) * delta(3)
1897 st%surface_grid_center(1, 1, ix, iz) = int(rr(1))
1898 st%surface_grid_center(1, 3, ix, iz) = int(rr(3))
1899 end do
1900 end do
1901 st%surface_grid_center(2, 2, :, :) = int(bounds(1,2))
1902 do ix = 1, ix_max
1903 do iz = 1, iz_max
1904 rr(1) = -bounds(1,2) + delta(1)/m_two + (ix-1) * delta(1)
1905 rr(3) = -bounds(1,3) + delta(3)/m_two + (iz-1) * delta(3)
1906 st%surface_grid_center(2, 1, ix, iz) = int(rr(1))
1907 st%surface_grid_center(2, 3, ix, iz) = int(rr(3))
1908 end do
1909 end do
1910
1911 st%surface_grid_center(1, 3, :, :) = -int(bounds(1,3))
1912 do ix = 1, ix_max
1913 do iy = 1, iy_max
1914 rr(1) = -bounds(1,1) + delta(1)/m_two + (ix-1) * delta(1)
1915 rr(2) = -bounds(1,2) + delta(2)/m_two + (iy-1) * delta(2)
1916 st%surface_grid_center(1, 1, ix, iy) = int(rr(1))
1917 st%surface_grid_center(1, 2, ix, iy) = int(rr(2))
1918 end do
1919 end do
1920 st%surface_grid_center(2, 3, :, :) = int(bounds(1,3))
1921 do ix = 1, ix_max
1922 do iy = 1, iy_max
1923 rr(1) = -bounds(1,2) + delta(1)/m_two + (ix-1) * delta(1)
1924 rr(2) = -bounds(1,2) + delta(2)/m_two + (iy-1) * delta(2)
1925 st%surface_grid_center(2, 1, ix, iy) = int(rr(1))
1926 st%surface_grid_center(2, 2, ix, iy) = int(rr(2))
1927 end do
1928 end do
1929
1930 st%surface_grid_points_number(:,:,:) = 0
1931
1932 nn_max = 0
1933
1934 do iy = 1, iy_max
1935 do iz = 1, iz_max
1936 min_1(iy) = -bounds(1,2) + (iy-1) * delta(2)
1937 max_1(iy) = -bounds(1,2) + iy * delta(2)
1938 min_2(iz) = -bounds(1,3) + (iz-1) * delta(3)
1939 max_2(iz) = -bounds(1,3) + iz * delta(3)
1940 end do
1941 end do
1942 do iiy = mesh%idx%nr(1,2), mesh%idx%nr(2,2)
1943 do iiz = mesh%idx%nr(1,3), mesh%idx%nr(2,3)
1944 vec(1) = iiy * mesh%spacing(2)
1945 vec(2) = iiz * mesh%spacing(3)
1946 call get_surface_indices(vec, min_1, max_1, min_2, max_2, idx1, idx2)
1947 if (idx1 /= 0 .and. idx2 /= 0) then
1948 st%surface_grid_points_number(1, idx1, idx2) = st%surface_grid_points_number(1, idx1, idx2) + 1
1949 if (nn_max < st%surface_grid_points_number(1, idx1, idx2)) then
1950 nn_max = st%surface_grid_points_number(1, idx1, idx2)
1951 end if
1952 end if
1953 end do
1954 end do
1955
1956 do ix = 1, ix_max
1957 do iz = 1, iz_max
1958 min_1(ix) = -bounds(1,1) + (ix-1) * delta(1)
1959 max_1(ix) = -bounds(1,1) + ix * delta(1)
1960 min_2(iz) = -bounds(1,3) + (iz-1) * delta(3)
1961 max_2(iz) = -bounds(1,3) + iz * delta(3)
1962 end do
1963 end do
1964 do iix = mesh%idx%nr(1, 1), mesh%idx%nr(2, 1)
1965 do iiz = mesh%idx%nr(1, 3), mesh%idx%nr(2, 3)
1966 vec(1) = iix * mesh%spacing(1)
1967 vec(2) = iiz * mesh%spacing(3)
1968 call get_surface_indices(vec, min_1, max_1, min_2, max_2, idx1, idx2)
1969 if (idx1 /= 0 .and. idx2 /= 0) then
1970 st%surface_grid_points_number(2,idx1,idx2) = st%surface_grid_points_number(2,idx1,idx2)+1
1971 if (nn_max < st%surface_grid_points_number(2, idx1, idx2)) then
1972 nn_max = st%surface_grid_points_number(2, idx1, idx2)
1973 end if
1974 end if
1975 end do
1976 end do
1977
1978 do ix = 1, ix_max
1979 do iy = 1, iy_max
1980 min_1(ix) = -bounds(1,1) + (ix-1) * delta(1)
1981 max_1(ix) = -bounds(1,1) + ix * delta(1)
1982 min_2(iy) = -bounds(1,2) + (iy-1) * delta(2)
1983 max_2(iy) = -bounds(1,2) + iy * delta(2)
1984 end do
1985 end do
1986 do iix = mesh%idx%nr(1,1), mesh%idx%nr(2,1)
1987 do iiy = mesh%idx%nr(1,2), mesh%idx%nr(2,2)
1988 vec(1) = iix * mesh%spacing(1)
1989 vec(2) = iiy * mesh%spacing(2)
1990 call get_surface_indices(vec, min_1, max_1, min_2, max_2, idx1, idx2)
1991 if (idx1 /= 0 .and. idx2 /= 0) then
1992 st%surface_grid_points_number(3, idx1, idx2) = st%surface_grid_points_number(3, idx1, idx2) + 1
1993 if (nn_max < st%surface_grid_points_number(3, idx1, idx2)) then
1994 nn_max = st%surface_grid_points_number(3, idx1, idx2)
1995 end if
1996 end if
1997 end do
1998 end do
1999
2000 ! originally there were three allocated of the same pointer here
2001 safe_allocate(st%surface_grid_points_map(1:2, 1:st%dim, 1:ix_max, 1:iy_max, 1:nn_max))
2002
2003 nn(:,:,:,:) = 0
2004
2005 do iy = 1, iy_max
2006 do iz = 1, iz_max
2007 min_1(iy) = -bounds(1,2) + (iy-1) * delta(2)
2008 max_1(iy) = -bounds(1,2) + iy * delta(2)
2009 min_2(iz) = -bounds(1,3) + (iz-1) * delta(3)
2010 max_2(iz) = -bounds(1,3) + iz * delta(3)
2011 end do
2012 end do
2013 do iiy = mesh%idx%nr(1,2), mesh%idx%nr(2,2)
2014 do iiz = mesh%idx%nr(1,3), mesh%idx%nr(2,3)
2015 vec(1) = iiy * mesh%spacing(2)
2016 vec(2) = iiz * mesh%spacing(3)
2017 call get_surface_indices(vec, min_1, max_1, min_2, max_2, idx1, idx2)
2018 if (idx1 /= 0 .and. idx2 /= 0) then
2019 nn(1, 1, idx1, idx2) = nn(1, 1, idx1, idx2) + 1
2020 rr(1) = -bounds(1, 1)
2021 rr(2) = iiy * mesh%spacing(2)
2022 rr(3) = iiz * mesh%spacing(3)
2023 iix = int(-bounds(1,1)/mesh%spacing(1))
2024 ip_global = mesh_global_index_from_coords(mesh, [iix, iiy, iiz])
2025 st%surface_grid_points_map(1, 1, idx1, idx2, nn(1, 1, idx1, idx2)) = ip_global
2026 nn(2, 1, idx1, idx2) = nn(2, 1, idx1, idx2) + 1
2027 rr(1) = bounds(1,1)
2028 rr(2) = iiy * mesh%spacing(2)
2029 rr(3) = iiz * mesh%spacing(3)
2030 iix = int(bounds(1,1)/mesh%spacing(1))
2031 ip_global = mesh_global_index_from_coords(mesh, [iix, iiy, iiz])
2032 st%surface_grid_points_map(2, 1, idx1, idx2, nn(2, 1, idx1, idx2)) = ip_global
2033 end if
2034 end do
2035 end do
2036
2037 do ix = 1, ix_max
2038 do iz = 1, iz_max
2039 min_1(ix) = -bounds(1,1) + (ix-1) * delta(1)
2040 max_1(ix) = -bounds(1,1) + ix * delta(1)
2041 min_2(iz) = -bounds(1,3) + (iz-1) * delta(3)
2042 max_2(iz) = -bounds(1,3) + iz * delta(3)
2043 end do
2044 end do
2045 do iix = mesh%idx%nr(1,1), mesh%idx%nr(2,1)
2046 do iiz = mesh%idx%nr(1,3), mesh%idx%nr(2,3)
2047 vec(1) = iix * mesh%spacing(1)
2048 vec(2) = iiz * mesh%spacing(3)
2049 call get_surface_indices(vec, min_1, max_1, min_2, max_2, idx1, idx2)
2050 if (idx1 /= 0 .and. idx2 /= 0) then
2051 nn(1, 2, idx1, idx2) = nn(1, 2, idx1, idx2) + 1
2052 rr(1) = iix * mesh%spacing(1)
2053 rr(2) = -bounds(1, 2)
2054 rr(3) = iiz * mesh%spacing(3)
2055 iiy = int(-bounds(1,2)/mesh%spacing(2))
2056 ip_global = mesh_global_index_from_coords(mesh, [iix, iiy, iiz])
2057 st%surface_grid_points_map(1, 2, idx1, idx2, nn(1, 2, idx1, idx2)) = ip_global
2058 nn(2, 2, idx1, idx2) = nn(2, 2, idx1, idx2) + 1
2059 rr(1) = iix * mesh%spacing(1)
2060 rr(2) = bounds(1,2)
2061 rr(3) = iiz * mesh%spacing(3)
2062 iiy = int(bounds(1,2)/mesh%spacing(2))
2063 ip_global = mesh_global_index_from_coords(mesh, [iix, iiy, iiz])
2064 st%surface_grid_points_map(2, 2, idx1, idx2, nn(2, 2, idx1, idx2)) = ip_global
2065 end if
2066 end do
2067 end do
2068
2069 do ix = 1, ix_max
2070 do iy = 1, iy_max
2071 min_1(ix) = -bounds(1,1) + (ix-1) * delta(1)
2072 max_1(ix) = -bounds(1,1) + ix * delta(1)
2073 min_2(iy) = -bounds(1,2) + (iy-1) * delta(2)
2074 max_2(iy) = -bounds(1,2) + iy * delta(2)
2075 end do
2076 end do
2077 do iix = mesh%idx%nr(1,1), mesh%idx%nr(2,1)
2078 do iiy = mesh%idx%nr(1,2), mesh%idx%nr(2,2)
2079 vec(1) = iix * mesh%spacing(1)
2080 vec(2) = iiy * mesh%spacing(2)
2081 call get_surface_indices(vec, min_1, max_1, min_2, max_2, idx1, idx2)
2082 if (idx1 /= 0 .and. idx2 /= 0) then
2083 nn(1, 3, idx1, idx2) = nn(1, 3, idx1, idx2) + 1
2084 rr(1) = iix * mesh%spacing(1)
2085 rr(2) = iiy * mesh%spacing(2)
2086 rr(3) = -bounds(1,3)
2087 iiz = int(-bounds(1,3)/mesh%spacing(3))
2088 ip_global = mesh_global_index_from_coords(mesh, [iix, iiy, iiz])
2089 st%surface_grid_points_map(1, 3, idx1, idx2, nn(1, 3, idx1, idx2)) = ip_global
2090 nn(2, 3, idx1, idx2) = nn(2, 3, idx1, idx2) + 1
2091 rr(1) = iix * mesh%spacing(1)
2092 rr(2) = iiy * mesh%spacing(2)
2093 rr(3) = bounds(1,3)
2094 iiz = int(bounds(1,3)/mesh%spacing(3))
2095 ip_global = mesh_global_index_from_coords(mesh, [iix, iiy, iiz])
2096 st%surface_grid_points_map(2, 3, idx1, idx2, nn(2, 3, idx1, idx2)) = ip_global
2097 end if
2098 end do
2099 end do
2100
2101 safe_deallocate_a(nn)
2102
2103 call profiling_out('SURF_GRID_POINTS_MAPPING')
2104
2106 contains
2107
2108 subroutine get_surface_indices(vec, min_1, max_1, min_2, max_2, index_1, index_2)
2109 real(real64), contiguous, intent(in) :: vec(:)
2110 real(real64), contiguous, intent(in) :: min_1(:)
2111 real(real64), contiguous, intent(in) :: max_1(:)
2112 real(real64), contiguous, intent(in) :: min_2(:)
2113 real(real64), contiguous, intent(in) :: max_2(:)
2114 integer, intent(out) :: index_1
2115 integer, intent(out) :: index_2
2116
2117 if (vec(1) >= min_1(1) .and. vec(1) <= max_1(1) .and. vec(2) >= min_2(1) .and. vec(2) <= max_2(1)) then
2118 index_1 = 1
2119 index_2 = 1
2120 else if (vec(1) >= min_1(2) .and. vec(1) <= max_1(2) .and. vec(2) >= min_2(1) .and. vec(2) <= max_2(1)) then
2121 index_1 = 2
2122 index_2 = 1
2123 else if (vec(1) >= min_1(3) .and. vec(1) <= max_1(3) .and. vec(2) >= min_2(1) .and. vec(2) <= max_2(1)) then
2124 index_1 = 3
2125 index_2 = 1
2126 else if (vec(1) >= min_1(1) .and. vec(1) <= max_1(1) .and. vec(2) >= min_2(2) .and. vec(2) <= max_2(2)) then
2127 index_1 = 1
2128 index_2 = 2
2129 else if (vec(1) >= min_1(2) .and. vec(1) <= max_1(2) .and. vec(2) >= min_2(2) .and. vec(2) <= max_2(2)) then
2130 index_1 = 2
2131 index_2 = 2
2132 else if (vec(1) >= min_1(3) .and. vec(1) <= max_1(3) .and. vec(2) >= min_2(2) .and. vec(2) <= max_2(2)) then
2133 index_1 = 3
2134 index_2 = 2
2135 else if (vec(1) >= min_1(1) .and. vec(1) <= max_1(1) .and. vec(2) >= min_2(3) .and. vec(2) <= max_2(3)) then
2136 index_1 = 1
2137 index_2 = 3
2138 else if (vec(1) >= min_1(2) .and. vec(1) <= max_1(2) .and. vec(2) >= min_2(3) .and. vec(2) <= max_2(3)) then
2139 index_1 = 2
2140 index_2 = 3
2141 else if (vec(1) >= min_1(3) .and. vec(1) <= max_1(3) .and. vec(2) >= min_2(3) .and. vec(2) <= max_2(3)) then
2142 index_1 = 3
2143 index_2 = 3
2144 else
2145 index_1 = 0
2146 index_2 = 0
2147 end if
2148
2149 end subroutine get_surface_indices
2150
2151 end subroutine surface_grid_points_mapping
2152
2154
2155!! Local Variables:
2156!! mode: f90
2157!! coding: utf-8
2158!! End:
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
subroutine get_surface_indices(vec, min_1, max_1, min_2, max_2, index_1, index_2)
subroutine get_medium_io_function(medium_func, bc, io_func, idim)
subroutine get_mask_io_function(mask_func, bc, io_func, idim)
subroutine write_files(filename, tmp)
subroutine get_pml_io_function(pml_func, bc, io_func)
subroutine, public accel_free_buffer(this, async)
Definition: accel.F90:967
integer, parameter, public accel_mem_read_write
Definition: accel.F90:162
pure logical function, public accel_is_enabled()
Definition: accel.F90:391
integer, parameter, public accel_mem_read_only
Definition: accel.F90:162
type(debug_t), save, public debug
Definition: debug.F90:133
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dderivatives_grad(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the gradient to a mesh function
subroutine, public external_waves_end(external_waves)
subroutine, public external_waves_init(external_waves, namespace)
Here, plane wave is evaluated from analytical formulae on grid.
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_huge
Definition: global.F90:191
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_four
Definition: global.F90:177
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:171
real(real64), parameter, public p_mu
Definition: global.F90:220
real(real64), parameter, public p_ep
Definition: global.F90:219
complex(real64), parameter, public m_z0
Definition: global.F90:183
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_half
Definition: global.F90:179
real(real64), parameter, public p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
Definition: global.F90:215
real(real64), parameter, public m_one
Definition: global.F90:174
real(real64), parameter, public m_five
Definition: global.F90:178
This module implements the underlying real-space grid.
Definition: grid.F90:96
This module implements the index, used for the mesh points.
Definition: index.F90:101
subroutine, public dio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
integer(int64) function, public io_function_fill_how(where)
Use this function to quickly plot functions for debugging purposes: call dio_function_output(io_funct...
Definition: io.F90:93
subroutine, public single_medium_box_allocate(medium_box, n_points)
Allocation of medium_box components.
subroutine, public single_medium_box_end(medium_box)
Deallocation of medium_box components.
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
integer, parameter, public mxll_ab_mask_zero
subroutine maxwell_zero_points_mapping(bc, mesh, bounds)
integer, parameter, public mxll_bc_mirror_pmc
integer, parameter mxll_plane_waves_positive_side
subroutine maxwell_boundary_point_info(mesh, ip, bounds, boundary_info)
subroutine, public bc_mxll_init(bc, namespace, space, gr, st)
subroutine bc_mxll_generate_medium(bc, space, gr, bounds, ep_factor, mu_factor, sigma_e_factor, sigma_m_factor)
subroutine maxwell_surfaces_init(mesh, st, bounds)
subroutine maxwell_box_point_info(bc, mesh, ip, bounds, point_info)
integer, parameter, public mxll_bc_mirror_pec
integer, parameter, public mxll_ab_mask
subroutine, public inner_and_outer_points_mapping(mesh, st, bounds, periodic_dim)
Inner points (inside bounds(1, :)) and boundary points of the Maxwell grid. Periodic axes have no bou...
subroutine bc_mxll_medium_init(gr, namespace, bounds, idim, ep_factor, mu_factor, sigma_e_factor, sigma_m_factor)
subroutine, public surface_grid_points_mapping(mesh, st, bounds)
integer, parameter, public mxll_bc_plane_waves
subroutine, public bc_mxll_initialize_pml_simple(bc, space, gr, c_factor, dt)
integer, parameter, public mxll_bc_medium
subroutine maxwell_constant_points_mapping(bc, mesh, bounds)
subroutine bc_mxll_generate_pml(bc, space)
subroutine bc_mxll_write_info(bc, mesh, namespace, space)
subroutine, public bc_mxll_generate_pml_parameters(bc, space, gr, c_factor, dt)
subroutine bc_mxll_generate_mask(bc, mesh, bounds)
subroutine maxwell_plane_waves_points_mapping(bc, mesh, bounds)
integer, parameter, public mxll_bc_constant
subroutine bc_mxll_pml_init(bc, gr, namespace, ab_bounds, idim)
subroutine maxwell_medium_points_mapping(bc, mesh, bounds)
subroutine bc_mxll_ab_bounds_init(bc, gr, namespace, ab_bounds, idim)
subroutine, public bc_mxll_end(bc)
integer, parameter, public mxll_ab_cpml
subroutine maxwell_pml_points_mapping(bc, mesh, bounds)
subroutine maxwell_mask_points_mapping(bc, mesh, bounds)
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
integer(int64) function, public mesh_global_index_from_coords(mesh, ix)
This function returns the true global index of the point for a given vector of integer coordinates.
Definition: mesh.F90:905
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:878
character(len=512), private msg
Definition: messages.F90:143
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
Some general things and nomenclature:
Definition: par_vec.F90:150
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:440
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:600
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:672
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:604
type(type_t), parameter, public type_cmplx
Definition: types.F90:114
type(type_t), parameter, public type_integer
Definition: types.F90:115
type(type_t), parameter, public type_float
Definition: types.F90:113
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:111
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:202
This module defines the unit system, used for input and output.
type(unit_system_t), public units_inp
the units systems for reading and writing
type(unit_t), public unit_one
some special units required for particular quantities
Class implementing a parallelepiped box. Currently this is restricted to a rectangular cuboid (all th...
Class implementing a spherical box.
Definition: box_sphere.F90:111
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:148
Describes mesh distribution to nodes.
Definition: mesh.F90:165
int true(void)