Add an absorbing layer
An absorbing layer (a perfectly matched layer's auxiliary fields, a sponge) carries a field decay=lambda: the stepper integrates the decay exactly, and
The recipe on a 1-D pulse,
allocate(u(0:NC+1), psi(0:NC+1), lam(0:NC+1), sig(0:NC+1)) ! a scalar field, one ghost cell each side
bx = box_interior(lb=[0], ub=[NC+1], ngc=1, components=.false.)
lo = bx%lo(box_dim(bx, 1_I4P)) ; hi = bx%hi(box_dim(bx, 1_I4P)) ! the interior of the field's dimension 1
lam = 0._R_P ; sig = 0._R_P ! outside the layer: no decay, no source
do i=3*NC/4+1, NC ! the layer, x in (3/4, 1)
lam(i) = LAMBDA_DT / DT ! lambda dt = 50
sig(i) = KAPPA * ((i - 0.5_R_P - 3*NC/4) / (NC/4))**2 * lam(i) ! psi relaxes to kappa(x) u: a graded damping
enddo
call st%initialize(SCHEME_SSP_33, FORM_BUTCHER, lb=[0], ub=[NC+1], components=.false.)
call sp%initialize_companion(st, lb=[0], ub=[NC+1], components=.false.)
print '(A,F7.4,A,F5.1)', 'ssp-33: real-axis bound', st%real_axis_bound(), ', lambda dt in the layer', LAMBDA_DT
print '(A,ES9.2,A,ES9.2)', 'explicit stages of the decay need dt <= ', st%real_axis_bound() / maxval(lam), &
'; dt = ', DTcall st%begin_step(bx, u) ; call sp%begin_step(bx, psi)
do k=1, st%stages()
call st%begin_stage(k, bx, DT, u) ; call sp%begin_stage(k, bx, DT, psi, decay=lam) ! psi's decay: exact
call st%stage_state_view(us) ; call sp%stage_state_view(ps)
call st%rhs_register_view(ru) ; call sp%rhs_register_view(rp)
us(lo-1) = us(hi) ; us(hi+1) = us(lo) ! periodic ghost cells of the stage state
do i=lo, hi
call gideon_fd_d1_c2([us(i-1), us(i), us(i+1)], DX, d)
ru(i) = -d - ps(i) ! central advection, damped by psi
rp(i) = sig(i) * us(i) ! psi's source alone: no -lambda psi
enddo
call st%end_stage(k, bx, DT, u) ; call sp%end_stage(k, bx, DT, psi)
enddo
call st%finish_step(bx, DT, u) ; call sp%finish_step(bx, DT, psi, decay=lam)$ cookbook_absorbing_layer
ssp-33: real-axis bound 2.5127, lambda dt in the layer 50.0
explicit stages of the decay need dt <= 1.96E-04; dt = 3.91E-03
t energy / energy(0)
0.125 9.998E-01
0.250 9.996E-01
0.375 9.944E-01
0.500 6.004E-01
0.625 5.182E-02
0.750 7.987E-03
0.875 3.012E-03
1.000 1.931E-03
absorbed, less than 1 % of the energy left at t = 1: T
[exit status 0]The pulse keeps its energy until it reaches the layer (its centre at
- A companion.
sp%initialize_companion(st, ...)givesthe field's scheme and form; drive it through the same calls in the same stage window. decay=needs the Butcher form. - The rate.
lamhas's shape: in the layer, 0 elsewhere, where the step is bitwise the explicit one. decay=lamat everybegin_stageofand at its finish_step(end_stagetakes none).- The source alone.
's residual is ; the stepper applies .
The explicit stages of the decay would need dt below real_axis_bound() / maxval(lam), the second line of the output: twenty times smaller here. The step is still the coupled system's: the source dt from the coupled limit (Stepper).
box_dim(bx, 1) is the dimension of the box's rank-5 view that holds the field's dimension 1 (2 for a scalar field): bx%lo and bx%hi of it are the interior's range, the loop of the residual.