@@ -156,6 +156,29 @@ def get_external_sources(t, dt, U, ivars, rp, myg, *, U_old=None, problem_source
156156 return S
157157
158158
159+ def get_sponge_factor (U , ivars , rp , myg ):
160+ """compute the sponge factor, f / tau, that goes into a
161+ sponge damping term of the form S = - (f / tau) (rho U)"""
162+
163+ rho = U [:, :, ivars .idens ]
164+ rho_begin = rp .get_param ("sponge.sponge_rho_begin" )
165+ rho_full = rp .get_param ("sponge.sponge_rho_full" )
166+
167+ assert rho_begin > rho_full
168+
169+ f = myg .scratch_array ()
170+
171+ f [:, :] = np .where (rho > rho_begin ,
172+ 0.0 ,
173+ np .where (rho < rho_full ,
174+ 1.0 ,
175+ 0.5 * (1.0 - np .cos (np .pi * (rho - rho_begin ) /
176+ (rho_full - rho_begin )))))
177+
178+ tau = rp .get_param ("sponge.sponge_timescale" )
179+ return f / tau
180+
181+
159182class Simulation (NullSimulation ):
160183 """The main simulation class for the corner transport upwind
161184 compressible hydrodynamics solver
@@ -392,6 +415,14 @@ def evolve(self):
392415 var = self .cc_data .get_var_by_index (n )
393416 var .v ()[:, :] += 0.5 * self .dt * (S_new .v (n = n ) - S_old .v (n = n ))
394417
418+ # finally, do the sponge, if desired -- this is formulated as an
419+ # implicit update to the velocity
420+ if self .rp .get_param ("sponge.do_sponge" ):
421+ kappa_f = get_sponge_factor (self .cc_data .data , self .ivars , self .rp , myg )
422+
423+ self .cc_data .data [:, :, self .ivars .ixmom ] /= (1.0 + self .dt * kappa_f )
424+ self .cc_data .data [:, :, self .ivars .iymom ] /= (1.0 + self .dt * kappa_f )
425+
395426 if self .particles is not None :
396427 self .particles .update_particles (self .dt )
397428
0 commit comments